diff options
Diffstat (limited to 'drivers/serial')
-rw-r--r-- | drivers/serial/8250.c | 58 | ||||
-rw-r--r-- | drivers/serial/Kconfig | 3 | ||||
-rw-r--r-- | drivers/serial/Makefile | 1 | ||||
-rw-r--r-- | drivers/serial/kgdboc.c | 163 | ||||
-rw-r--r-- | drivers/serial/serial_core.c | 72 |
5 files changed, 294 insertions, 3 deletions
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c index 77f7a7f0646e..96a585e1cee8 100644 --- a/drivers/serial/8250.c +++ b/drivers/serial/8250.c | |||
@@ -1740,6 +1740,60 @@ static inline void wait_for_xmitr(struct uart_8250_port *up, int bits) | |||
1740 | } | 1740 | } |
1741 | } | 1741 | } |
1742 | 1742 | ||
1743 | #ifdef CONFIG_CONSOLE_POLL | ||
1744 | /* | ||
1745 | * Console polling routines for writing and reading from the uart while | ||
1746 | * in an interrupt or debug context. | ||
1747 | */ | ||
1748 | |||
1749 | static int serial8250_get_poll_char(struct uart_port *port) | ||
1750 | { | ||
1751 | struct uart_8250_port *up = (struct uart_8250_port *)port; | ||
1752 | unsigned char lsr = serial_inp(up, UART_LSR); | ||
1753 | |||
1754 | while (!(lsr & UART_LSR_DR)) | ||
1755 | lsr = serial_inp(up, UART_LSR); | ||
1756 | |||
1757 | return serial_inp(up, UART_RX); | ||
1758 | } | ||
1759 | |||
1760 | |||
1761 | static void serial8250_put_poll_char(struct uart_port *port, | ||
1762 | unsigned char c) | ||
1763 | { | ||
1764 | unsigned int ier; | ||
1765 | struct uart_8250_port *up = (struct uart_8250_port *)port; | ||
1766 | |||
1767 | /* | ||
1768 | * First save the IER then disable the interrupts | ||
1769 | */ | ||
1770 | ier = serial_in(up, UART_IER); | ||
1771 | if (up->capabilities & UART_CAP_UUE) | ||
1772 | serial_out(up, UART_IER, UART_IER_UUE); | ||
1773 | else | ||
1774 | serial_out(up, UART_IER, 0); | ||
1775 | |||
1776 | wait_for_xmitr(up, BOTH_EMPTY); | ||
1777 | /* | ||
1778 | * Send the character out. | ||
1779 | * If a LF, also do CR... | ||
1780 | */ | ||
1781 | serial_out(up, UART_TX, c); | ||
1782 | if (c == 10) { | ||
1783 | wait_for_xmitr(up, BOTH_EMPTY); | ||
1784 | serial_out(up, UART_TX, 13); | ||
1785 | } | ||
1786 | |||
1787 | /* | ||
1788 | * Finally, wait for transmitter to become empty | ||
1789 | * and restore the IER | ||
1790 | */ | ||
1791 | wait_for_xmitr(up, BOTH_EMPTY); | ||
1792 | serial_out(up, UART_IER, ier); | ||
1793 | } | ||
1794 | |||
1795 | #endif /* CONFIG_CONSOLE_POLL */ | ||
1796 | |||
1743 | static int serial8250_startup(struct uart_port *port) | 1797 | static int serial8250_startup(struct uart_port *port) |
1744 | { | 1798 | { |
1745 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1799 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
@@ -2386,6 +2440,10 @@ static struct uart_ops serial8250_pops = { | |||
2386 | .request_port = serial8250_request_port, | 2440 | .request_port = serial8250_request_port, |
2387 | .config_port = serial8250_config_port, | 2441 | .config_port = serial8250_config_port, |
2388 | .verify_port = serial8250_verify_port, | 2442 | .verify_port = serial8250_verify_port, |
2443 | #ifdef CONFIG_CONSOLE_POLL | ||
2444 | .poll_get_char = serial8250_get_poll_char, | ||
2445 | .poll_put_char = serial8250_put_poll_char, | ||
2446 | #endif | ||
2389 | }; | 2447 | }; |
2390 | 2448 | ||
2391 | static struct uart_8250_port serial8250_ports[UART_NR]; | 2449 | static struct uart_8250_port serial8250_ports[UART_NR]; |
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index cf627cd1b4c8..f7cd9504d811 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig | |||
@@ -961,6 +961,9 @@ config SERIAL_CORE | |||
961 | config SERIAL_CORE_CONSOLE | 961 | config SERIAL_CORE_CONSOLE |
962 | bool | 962 | bool |
963 | 963 | ||
964 | config CONSOLE_POLL | ||
965 | bool | ||
966 | |||
964 | config SERIAL_68328 | 967 | config SERIAL_68328 |
965 | bool "68328 serial support" | 968 | bool "68328 serial support" |
966 | depends on M68328 || M68EZ328 || M68VZ328 | 969 | depends on M68328 || M68EZ328 || M68VZ328 |
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile index 640cfe44a56d..3cbea5494724 100644 --- a/drivers/serial/Makefile +++ b/drivers/serial/Makefile | |||
@@ -66,4 +66,5 @@ obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o | |||
66 | obj-$(CONFIG_SERIAL_NETX) += netx-serial.o | 66 | obj-$(CONFIG_SERIAL_NETX) += netx-serial.o |
67 | obj-$(CONFIG_SERIAL_OF_PLATFORM) += of_serial.o | 67 | obj-$(CONFIG_SERIAL_OF_PLATFORM) += of_serial.o |
68 | obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o | 68 | obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o |
69 | obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o | ||
69 | obj-$(CONFIG_SERIAL_QE) += ucc_uart.o | 70 | obj-$(CONFIG_SERIAL_QE) += ucc_uart.o |
diff --git a/drivers/serial/kgdboc.c b/drivers/serial/kgdboc.c new file mode 100644 index 000000000000..341830791608 --- /dev/null +++ b/drivers/serial/kgdboc.c | |||
@@ -0,0 +1,163 @@ | |||
1 | /* | ||
2 | * Based on the same principle as kgdboe using the NETPOLL api, this | ||
3 | * driver uses a console polling api to implement a gdb serial inteface | ||
4 | * which is multiplexed on a console port. | ||
5 | * | ||
6 | * Maintainer: Jason Wessel <jason.wessel@windriver.com> | ||
7 | * | ||
8 | * 2007-2008 (c) Jason Wessel - Wind River Systems, Inc. | ||
9 | * | ||
10 | * This file is licensed under the terms of the GNU General Public | ||
11 | * License version 2. This program is licensed "as is" without any | ||
12 | * warranty of any kind, whether express or implied. | ||
13 | */ | ||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/ctype.h> | ||
16 | #include <linux/kgdb.h> | ||
17 | #include <linux/tty.h> | ||
18 | |||
19 | #define MAX_CONFIG_LEN 40 | ||
20 | |||
21 | static struct kgdb_io kgdboc_io_ops; | ||
22 | |||
23 | /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */ | ||
24 | static int configured = -1; | ||
25 | |||
26 | static char config[MAX_CONFIG_LEN]; | ||
27 | static struct kparam_string kps = { | ||
28 | .string = config, | ||
29 | .maxlen = MAX_CONFIG_LEN, | ||
30 | }; | ||
31 | |||
32 | static struct tty_driver *kgdb_tty_driver; | ||
33 | static int kgdb_tty_line; | ||
34 | |||
35 | static int kgdboc_option_setup(char *opt) | ||
36 | { | ||
37 | if (strlen(opt) > MAX_CONFIG_LEN) { | ||
38 | printk(KERN_ERR "kgdboc: config string too long\n"); | ||
39 | return -ENOSPC; | ||
40 | } | ||
41 | strcpy(config, opt); | ||
42 | |||
43 | return 0; | ||
44 | } | ||
45 | |||
46 | __setup("kgdboc=", kgdboc_option_setup); | ||
47 | |||
48 | static int configure_kgdboc(void) | ||
49 | { | ||
50 | struct tty_driver *p; | ||
51 | int tty_line = 0; | ||
52 | int err; | ||
53 | |||
54 | err = kgdboc_option_setup(config); | ||
55 | if (err || !strlen(config) || isspace(config[0])) | ||
56 | goto noconfig; | ||
57 | |||
58 | err = -ENODEV; | ||
59 | |||
60 | p = tty_find_polling_driver(config, &tty_line); | ||
61 | if (!p) | ||
62 | goto noconfig; | ||
63 | |||
64 | kgdb_tty_driver = p; | ||
65 | kgdb_tty_line = tty_line; | ||
66 | |||
67 | err = kgdb_register_io_module(&kgdboc_io_ops); | ||
68 | if (err) | ||
69 | goto noconfig; | ||
70 | |||
71 | configured = 1; | ||
72 | |||
73 | return 0; | ||
74 | |||
75 | noconfig: | ||
76 | config[0] = 0; | ||
77 | configured = 0; | ||
78 | |||
79 | return err; | ||
80 | } | ||
81 | |||
82 | static int __init init_kgdboc(void) | ||
83 | { | ||
84 | /* Already configured? */ | ||
85 | if (configured == 1) | ||
86 | return 0; | ||
87 | |||
88 | return configure_kgdboc(); | ||
89 | } | ||
90 | |||
91 | static void cleanup_kgdboc(void) | ||
92 | { | ||
93 | if (configured == 1) | ||
94 | kgdb_unregister_io_module(&kgdboc_io_ops); | ||
95 | } | ||
96 | |||
97 | static int kgdboc_get_char(void) | ||
98 | { | ||
99 | return kgdb_tty_driver->poll_get_char(kgdb_tty_driver, kgdb_tty_line); | ||
100 | } | ||
101 | |||
102 | static void kgdboc_put_char(u8 chr) | ||
103 | { | ||
104 | kgdb_tty_driver->poll_put_char(kgdb_tty_driver, kgdb_tty_line, chr); | ||
105 | } | ||
106 | |||
107 | static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp) | ||
108 | { | ||
109 | if (strlen(kmessage) >= MAX_CONFIG_LEN) { | ||
110 | printk(KERN_ERR "kgdboc: config string too long\n"); | ||
111 | return -ENOSPC; | ||
112 | } | ||
113 | |||
114 | /* Only copy in the string if the init function has not run yet */ | ||
115 | if (configured < 0) { | ||
116 | strcpy(config, kmessage); | ||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | if (kgdb_connected) { | ||
121 | printk(KERN_ERR | ||
122 | "kgdboc: Cannot reconfigure while KGDB is connected.\n"); | ||
123 | |||
124 | return -EBUSY; | ||
125 | } | ||
126 | |||
127 | strcpy(config, kmessage); | ||
128 | |||
129 | if (configured == 1) | ||
130 | cleanup_kgdboc(); | ||
131 | |||
132 | /* Go and configure with the new params. */ | ||
133 | return configure_kgdboc(); | ||
134 | } | ||
135 | |||
136 | static void kgdboc_pre_exp_handler(void) | ||
137 | { | ||
138 | /* Increment the module count when the debugger is active */ | ||
139 | if (!kgdb_connected) | ||
140 | try_module_get(THIS_MODULE); | ||
141 | } | ||
142 | |||
143 | static void kgdboc_post_exp_handler(void) | ||
144 | { | ||
145 | /* decrement the module count when the debugger detaches */ | ||
146 | if (!kgdb_connected) | ||
147 | module_put(THIS_MODULE); | ||
148 | } | ||
149 | |||
150 | static struct kgdb_io kgdboc_io_ops = { | ||
151 | .name = "kgdboc", | ||
152 | .read_char = kgdboc_get_char, | ||
153 | .write_char = kgdboc_put_char, | ||
154 | .pre_exception = kgdboc_pre_exp_handler, | ||
155 | .post_exception = kgdboc_post_exp_handler, | ||
156 | }; | ||
157 | |||
158 | module_init(init_kgdboc); | ||
159 | module_exit(cleanup_kgdboc); | ||
160 | module_param_call(kgdboc, param_set_kgdboc_var, param_get_string, &kps, 0644); | ||
161 | MODULE_PARM_DESC(kgdboc, "<serial_device>[,baud]"); | ||
162 | MODULE_DESCRIPTION("KGDB Console TTY Driver"); | ||
163 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c index 0f5a17987cca..4d7eecbead9b 100644 --- a/drivers/serial/serial_core.c +++ b/drivers/serial/serial_core.c | |||
@@ -1827,7 +1827,7 @@ uart_get_console(struct uart_port *ports, int nr, struct console *co) | |||
1827 | * options. The format of the string is <baud><parity><bits><flow>, | 1827 | * options. The format of the string is <baud><parity><bits><flow>, |
1828 | * eg: 115200n8r | 1828 | * eg: 115200n8r |
1829 | */ | 1829 | */ |
1830 | void __init | 1830 | void |
1831 | uart_parse_options(char *options, int *baud, int *parity, int *bits, int *flow) | 1831 | uart_parse_options(char *options, int *baud, int *parity, int *bits, int *flow) |
1832 | { | 1832 | { |
1833 | char *s = options; | 1833 | char *s = options; |
@@ -1842,6 +1842,7 @@ uart_parse_options(char *options, int *baud, int *parity, int *bits, int *flow) | |||
1842 | if (*s) | 1842 | if (*s) |
1843 | *flow = *s; | 1843 | *flow = *s; |
1844 | } | 1844 | } |
1845 | EXPORT_SYMBOL_GPL(uart_parse_options); | ||
1845 | 1846 | ||
1846 | struct baud_rates { | 1847 | struct baud_rates { |
1847 | unsigned int rate; | 1848 | unsigned int rate; |
@@ -1872,7 +1873,7 @@ static const struct baud_rates baud_rates[] = { | |||
1872 | * @bits: number of data bits | 1873 | * @bits: number of data bits |
1873 | * @flow: flow control character - 'r' (rts) | 1874 | * @flow: flow control character - 'r' (rts) |
1874 | */ | 1875 | */ |
1875 | int __init | 1876 | int |
1876 | uart_set_options(struct uart_port *port, struct console *co, | 1877 | uart_set_options(struct uart_port *port, struct console *co, |
1877 | int baud, int parity, int bits, int flow) | 1878 | int baud, int parity, int bits, int flow) |
1878 | { | 1879 | { |
@@ -1924,10 +1925,16 @@ uart_set_options(struct uart_port *port, struct console *co, | |||
1924 | port->mctrl |= TIOCM_DTR; | 1925 | port->mctrl |= TIOCM_DTR; |
1925 | 1926 | ||
1926 | port->ops->set_termios(port, &termios, &dummy); | 1927 | port->ops->set_termios(port, &termios, &dummy); |
1927 | co->cflag = termios.c_cflag; | 1928 | /* |
1929 | * Allow the setting of the UART parameters with a NULL console | ||
1930 | * too: | ||
1931 | */ | ||
1932 | if (co) | ||
1933 | co->cflag = termios.c_cflag; | ||
1928 | 1934 | ||
1929 | return 0; | 1935 | return 0; |
1930 | } | 1936 | } |
1937 | EXPORT_SYMBOL_GPL(uart_set_options); | ||
1931 | #endif /* CONFIG_SERIAL_CORE_CONSOLE */ | 1938 | #endif /* CONFIG_SERIAL_CORE_CONSOLE */ |
1932 | 1939 | ||
1933 | static void uart_change_pm(struct uart_state *state, int pm_state) | 1940 | static void uart_change_pm(struct uart_state *state, int pm_state) |
@@ -2182,6 +2189,60 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state, | |||
2182 | } | 2189 | } |
2183 | } | 2190 | } |
2184 | 2191 | ||
2192 | #ifdef CONFIG_CONSOLE_POLL | ||
2193 | |||
2194 | static int uart_poll_init(struct tty_driver *driver, int line, char *options) | ||
2195 | { | ||
2196 | struct uart_driver *drv = driver->driver_state; | ||
2197 | struct uart_state *state = drv->state + line; | ||
2198 | struct uart_port *port; | ||
2199 | int baud = 9600; | ||
2200 | int bits = 8; | ||
2201 | int parity = 'n'; | ||
2202 | int flow = 'n'; | ||
2203 | |||
2204 | if (!state || !state->port) | ||
2205 | return -1; | ||
2206 | |||
2207 | port = state->port; | ||
2208 | if (!(port->ops->poll_get_char && port->ops->poll_put_char)) | ||
2209 | return -1; | ||
2210 | |||
2211 | if (options) { | ||
2212 | uart_parse_options(options, &baud, &parity, &bits, &flow); | ||
2213 | return uart_set_options(port, NULL, baud, parity, bits, flow); | ||
2214 | } | ||
2215 | |||
2216 | return 0; | ||
2217 | } | ||
2218 | |||
2219 | static int uart_poll_get_char(struct tty_driver *driver, int line) | ||
2220 | { | ||
2221 | struct uart_driver *drv = driver->driver_state; | ||
2222 | struct uart_state *state = drv->state + line; | ||
2223 | struct uart_port *port; | ||
2224 | |||
2225 | if (!state || !state->port) | ||
2226 | return -1; | ||
2227 | |||
2228 | port = state->port; | ||
2229 | return port->ops->poll_get_char(port); | ||
2230 | } | ||
2231 | |||
2232 | static void uart_poll_put_char(struct tty_driver *driver, int line, char ch) | ||
2233 | { | ||
2234 | struct uart_driver *drv = driver->driver_state; | ||
2235 | struct uart_state *state = drv->state + line; | ||
2236 | struct uart_port *port; | ||
2237 | |||
2238 | if (!state || !state->port) | ||
2239 | return; | ||
2240 | |||
2241 | port = state->port; | ||
2242 | port->ops->poll_put_char(port, ch); | ||
2243 | } | ||
2244 | #endif | ||
2245 | |||
2185 | static const struct tty_operations uart_ops = { | 2246 | static const struct tty_operations uart_ops = { |
2186 | .open = uart_open, | 2247 | .open = uart_open, |
2187 | .close = uart_close, | 2248 | .close = uart_close, |
@@ -2206,6 +2267,11 @@ static const struct tty_operations uart_ops = { | |||
2206 | #endif | 2267 | #endif |
2207 | .tiocmget = uart_tiocmget, | 2268 | .tiocmget = uart_tiocmget, |
2208 | .tiocmset = uart_tiocmset, | 2269 | .tiocmset = uart_tiocmset, |
2270 | #ifdef CONFIG_CONSOLE_POLL | ||
2271 | .poll_init = uart_poll_init, | ||
2272 | .poll_get_char = uart_poll_get_char, | ||
2273 | .poll_put_char = uart_poll_put_char, | ||
2274 | #endif | ||
2209 | }; | 2275 | }; |
2210 | 2276 | ||
2211 | /** | 2277 | /** |