Commit 8e23fcc89c8091790903927449f8efb9b4e23960
Committed by
Linus Torvalds
1 parent
7d6a07d123
Exists in
master
and in
4 other branches
Serial: Allow port type to be specified when calling serial8250_register_port.
Add flag value UPF_FIXED_TYPE which specifies that the UART type is known and should not be probed. For this case the UARTs properties are just copied out of the uart_config entry. This allows us to keep SOC specific 8250 probe code out of 8250.c. In this case we know the serial hardware will not be changing as it is on the same silicon as the CPU, and we can specify it with certainty in the board/cpu setup code. The alternative is to load up 8250.c with a bunch of OCTEON specific special cases in the probing code. Signed-off-by: David Daney <ddaney@caviumnetworks.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 4 changed files with 17 additions and 2 deletions Inline Diff
drivers/serial/8250.c
1 | /* | 1 | /* |
2 | * linux/drivers/char/8250.c | 2 | * linux/drivers/char/8250.c |
3 | * | 3 | * |
4 | * Driver for 8250/16550-type serial ports | 4 | * Driver for 8250/16550-type serial ports |
5 | * | 5 | * |
6 | * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o. | 6 | * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o. |
7 | * | 7 | * |
8 | * Copyright (C) 2001 Russell King. | 8 | * Copyright (C) 2001 Russell King. |
9 | * | 9 | * |
10 | * This program is free software; you can redistribute it and/or modify | 10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License as published by | 11 | * it under the terms of the GNU General Public License as published by |
12 | * the Free Software Foundation; either version 2 of the License, or | 12 | * the Free Software Foundation; either version 2 of the License, or |
13 | * (at your option) any later version. | 13 | * (at your option) any later version. |
14 | * | 14 | * |
15 | * A note about mapbase / membase | 15 | * A note about mapbase / membase |
16 | * | 16 | * |
17 | * mapbase is the physical address of the IO port. | 17 | * mapbase is the physical address of the IO port. |
18 | * membase is an 'ioremapped' cookie. | 18 | * membase is an 'ioremapped' cookie. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) | 21 | #if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
22 | #define SUPPORT_SYSRQ | 22 | #define SUPPORT_SYSRQ |
23 | #endif | 23 | #endif |
24 | 24 | ||
25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
26 | #include <linux/moduleparam.h> | 26 | #include <linux/moduleparam.h> |
27 | #include <linux/ioport.h> | 27 | #include <linux/ioport.h> |
28 | #include <linux/init.h> | 28 | #include <linux/init.h> |
29 | #include <linux/console.h> | 29 | #include <linux/console.h> |
30 | #include <linux/sysrq.h> | 30 | #include <linux/sysrq.h> |
31 | #include <linux/delay.h> | 31 | #include <linux/delay.h> |
32 | #include <linux/platform_device.h> | 32 | #include <linux/platform_device.h> |
33 | #include <linux/tty.h> | 33 | #include <linux/tty.h> |
34 | #include <linux/tty_flip.h> | 34 | #include <linux/tty_flip.h> |
35 | #include <linux/serial_reg.h> | 35 | #include <linux/serial_reg.h> |
36 | #include <linux/serial_core.h> | 36 | #include <linux/serial_core.h> |
37 | #include <linux/serial.h> | 37 | #include <linux/serial.h> |
38 | #include <linux/serial_8250.h> | 38 | #include <linux/serial_8250.h> |
39 | #include <linux/nmi.h> | 39 | #include <linux/nmi.h> |
40 | #include <linux/mutex.h> | 40 | #include <linux/mutex.h> |
41 | 41 | ||
42 | #include <asm/io.h> | 42 | #include <asm/io.h> |
43 | #include <asm/irq.h> | 43 | #include <asm/irq.h> |
44 | 44 | ||
45 | #include "8250.h" | 45 | #include "8250.h" |
46 | 46 | ||
47 | #ifdef CONFIG_SPARC | 47 | #ifdef CONFIG_SPARC |
48 | #include "suncore.h" | 48 | #include "suncore.h" |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | /* | 51 | /* |
52 | * Configuration: | 52 | * Configuration: |
53 | * share_irqs - whether we pass IRQF_SHARED to request_irq(). This option | 53 | * share_irqs - whether we pass IRQF_SHARED to request_irq(). This option |
54 | * is unsafe when used on edge-triggered interrupts. | 54 | * is unsafe when used on edge-triggered interrupts. |
55 | */ | 55 | */ |
56 | static unsigned int share_irqs = SERIAL8250_SHARE_IRQS; | 56 | static unsigned int share_irqs = SERIAL8250_SHARE_IRQS; |
57 | 57 | ||
58 | static unsigned int nr_uarts = CONFIG_SERIAL_8250_RUNTIME_UARTS; | 58 | static unsigned int nr_uarts = CONFIG_SERIAL_8250_RUNTIME_UARTS; |
59 | 59 | ||
60 | static struct uart_driver serial8250_reg; | 60 | static struct uart_driver serial8250_reg; |
61 | 61 | ||
62 | static int serial_index(struct uart_port *port) | 62 | static int serial_index(struct uart_port *port) |
63 | { | 63 | { |
64 | return (serial8250_reg.minor - 64) + port->line; | 64 | return (serial8250_reg.minor - 64) + port->line; |
65 | } | 65 | } |
66 | 66 | ||
67 | /* | 67 | /* |
68 | * Debugging. | 68 | * Debugging. |
69 | */ | 69 | */ |
70 | #if 0 | 70 | #if 0 |
71 | #define DEBUG_AUTOCONF(fmt...) printk(fmt) | 71 | #define DEBUG_AUTOCONF(fmt...) printk(fmt) |
72 | #else | 72 | #else |
73 | #define DEBUG_AUTOCONF(fmt...) do { } while (0) | 73 | #define DEBUG_AUTOCONF(fmt...) do { } while (0) |
74 | #endif | 74 | #endif |
75 | 75 | ||
76 | #if 0 | 76 | #if 0 |
77 | #define DEBUG_INTR(fmt...) printk(fmt) | 77 | #define DEBUG_INTR(fmt...) printk(fmt) |
78 | #else | 78 | #else |
79 | #define DEBUG_INTR(fmt...) do { } while (0) | 79 | #define DEBUG_INTR(fmt...) do { } while (0) |
80 | #endif | 80 | #endif |
81 | 81 | ||
82 | #define PASS_LIMIT 256 | 82 | #define PASS_LIMIT 256 |
83 | 83 | ||
84 | /* | 84 | /* |
85 | * We default to IRQ0 for the "no irq" hack. Some | 85 | * We default to IRQ0 for the "no irq" hack. Some |
86 | * machine types want others as well - they're free | 86 | * machine types want others as well - they're free |
87 | * to redefine this in their header file. | 87 | * to redefine this in their header file. |
88 | */ | 88 | */ |
89 | #define is_real_interrupt(irq) ((irq) != 0) | 89 | #define is_real_interrupt(irq) ((irq) != 0) |
90 | 90 | ||
91 | #ifdef CONFIG_SERIAL_8250_DETECT_IRQ | 91 | #ifdef CONFIG_SERIAL_8250_DETECT_IRQ |
92 | #define CONFIG_SERIAL_DETECT_IRQ 1 | 92 | #define CONFIG_SERIAL_DETECT_IRQ 1 |
93 | #endif | 93 | #endif |
94 | #ifdef CONFIG_SERIAL_8250_MANY_PORTS | 94 | #ifdef CONFIG_SERIAL_8250_MANY_PORTS |
95 | #define CONFIG_SERIAL_MANY_PORTS 1 | 95 | #define CONFIG_SERIAL_MANY_PORTS 1 |
96 | #endif | 96 | #endif |
97 | 97 | ||
98 | /* | 98 | /* |
99 | * HUB6 is always on. This will be removed once the header | 99 | * HUB6 is always on. This will be removed once the header |
100 | * files have been cleaned. | 100 | * files have been cleaned. |
101 | */ | 101 | */ |
102 | #define CONFIG_HUB6 1 | 102 | #define CONFIG_HUB6 1 |
103 | 103 | ||
104 | #include <asm/serial.h> | 104 | #include <asm/serial.h> |
105 | /* | 105 | /* |
106 | * SERIAL_PORT_DFNS tells us about built-in ports that have no | 106 | * SERIAL_PORT_DFNS tells us about built-in ports that have no |
107 | * standard enumeration mechanism. Platforms that can find all | 107 | * standard enumeration mechanism. Platforms that can find all |
108 | * serial ports via mechanisms like ACPI or PCI need not supply it. | 108 | * serial ports via mechanisms like ACPI or PCI need not supply it. |
109 | */ | 109 | */ |
110 | #ifndef SERIAL_PORT_DFNS | 110 | #ifndef SERIAL_PORT_DFNS |
111 | #define SERIAL_PORT_DFNS | 111 | #define SERIAL_PORT_DFNS |
112 | #endif | 112 | #endif |
113 | 113 | ||
114 | static const struct old_serial_port old_serial_port[] = { | 114 | static const struct old_serial_port old_serial_port[] = { |
115 | SERIAL_PORT_DFNS /* defined in asm/serial.h */ | 115 | SERIAL_PORT_DFNS /* defined in asm/serial.h */ |
116 | }; | 116 | }; |
117 | 117 | ||
118 | #define UART_NR CONFIG_SERIAL_8250_NR_UARTS | 118 | #define UART_NR CONFIG_SERIAL_8250_NR_UARTS |
119 | 119 | ||
120 | #ifdef CONFIG_SERIAL_8250_RSA | 120 | #ifdef CONFIG_SERIAL_8250_RSA |
121 | 121 | ||
122 | #define PORT_RSA_MAX 4 | 122 | #define PORT_RSA_MAX 4 |
123 | static unsigned long probe_rsa[PORT_RSA_MAX]; | 123 | static unsigned long probe_rsa[PORT_RSA_MAX]; |
124 | static unsigned int probe_rsa_count; | 124 | static unsigned int probe_rsa_count; |
125 | #endif /* CONFIG_SERIAL_8250_RSA */ | 125 | #endif /* CONFIG_SERIAL_8250_RSA */ |
126 | 126 | ||
127 | struct uart_8250_port { | 127 | struct uart_8250_port { |
128 | struct uart_port port; | 128 | struct uart_port port; |
129 | struct timer_list timer; /* "no irq" timer */ | 129 | struct timer_list timer; /* "no irq" timer */ |
130 | struct list_head list; /* ports on this IRQ */ | 130 | struct list_head list; /* ports on this IRQ */ |
131 | unsigned short capabilities; /* port capabilities */ | 131 | unsigned short capabilities; /* port capabilities */ |
132 | unsigned short bugs; /* port bugs */ | 132 | unsigned short bugs; /* port bugs */ |
133 | unsigned int tx_loadsz; /* transmit fifo load size */ | 133 | unsigned int tx_loadsz; /* transmit fifo load size */ |
134 | unsigned char acr; | 134 | unsigned char acr; |
135 | unsigned char ier; | 135 | unsigned char ier; |
136 | unsigned char lcr; | 136 | unsigned char lcr; |
137 | unsigned char mcr; | 137 | unsigned char mcr; |
138 | unsigned char mcr_mask; /* mask of user bits */ | 138 | unsigned char mcr_mask; /* mask of user bits */ |
139 | unsigned char mcr_force; /* mask of forced bits */ | 139 | unsigned char mcr_force; /* mask of forced bits */ |
140 | 140 | ||
141 | /* | 141 | /* |
142 | * Some bits in registers are cleared on a read, so they must | 142 | * Some bits in registers are cleared on a read, so they must |
143 | * be saved whenever the register is read but the bits will not | 143 | * be saved whenever the register is read but the bits will not |
144 | * be immediately processed. | 144 | * be immediately processed. |
145 | */ | 145 | */ |
146 | #define LSR_SAVE_FLAGS UART_LSR_BRK_ERROR_BITS | 146 | #define LSR_SAVE_FLAGS UART_LSR_BRK_ERROR_BITS |
147 | unsigned char lsr_saved_flags; | 147 | unsigned char lsr_saved_flags; |
148 | #define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA | 148 | #define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA |
149 | unsigned char msr_saved_flags; | 149 | unsigned char msr_saved_flags; |
150 | 150 | ||
151 | /* | 151 | /* |
152 | * We provide a per-port pm hook. | 152 | * We provide a per-port pm hook. |
153 | */ | 153 | */ |
154 | void (*pm)(struct uart_port *port, | 154 | void (*pm)(struct uart_port *port, |
155 | unsigned int state, unsigned int old); | 155 | unsigned int state, unsigned int old); |
156 | }; | 156 | }; |
157 | 157 | ||
158 | struct irq_info { | 158 | struct irq_info { |
159 | struct hlist_node node; | 159 | struct hlist_node node; |
160 | int irq; | 160 | int irq; |
161 | spinlock_t lock; /* Protects list not the hash */ | 161 | spinlock_t lock; /* Protects list not the hash */ |
162 | struct list_head *head; | 162 | struct list_head *head; |
163 | }; | 163 | }; |
164 | 164 | ||
165 | #define NR_IRQ_HASH 32 /* Can be adjusted later */ | 165 | #define NR_IRQ_HASH 32 /* Can be adjusted later */ |
166 | static struct hlist_head irq_lists[NR_IRQ_HASH]; | 166 | static struct hlist_head irq_lists[NR_IRQ_HASH]; |
167 | static DEFINE_MUTEX(hash_mutex); /* Used to walk the hash */ | 167 | static DEFINE_MUTEX(hash_mutex); /* Used to walk the hash */ |
168 | 168 | ||
169 | /* | 169 | /* |
170 | * Here we define the default xmit fifo size used for each type of UART. | 170 | * Here we define the default xmit fifo size used for each type of UART. |
171 | */ | 171 | */ |
172 | static const struct serial8250_config uart_config[] = { | 172 | static const struct serial8250_config uart_config[] = { |
173 | [PORT_UNKNOWN] = { | 173 | [PORT_UNKNOWN] = { |
174 | .name = "unknown", | 174 | .name = "unknown", |
175 | .fifo_size = 1, | 175 | .fifo_size = 1, |
176 | .tx_loadsz = 1, | 176 | .tx_loadsz = 1, |
177 | }, | 177 | }, |
178 | [PORT_8250] = { | 178 | [PORT_8250] = { |
179 | .name = "8250", | 179 | .name = "8250", |
180 | .fifo_size = 1, | 180 | .fifo_size = 1, |
181 | .tx_loadsz = 1, | 181 | .tx_loadsz = 1, |
182 | }, | 182 | }, |
183 | [PORT_16450] = { | 183 | [PORT_16450] = { |
184 | .name = "16450", | 184 | .name = "16450", |
185 | .fifo_size = 1, | 185 | .fifo_size = 1, |
186 | .tx_loadsz = 1, | 186 | .tx_loadsz = 1, |
187 | }, | 187 | }, |
188 | [PORT_16550] = { | 188 | [PORT_16550] = { |
189 | .name = "16550", | 189 | .name = "16550", |
190 | .fifo_size = 1, | 190 | .fifo_size = 1, |
191 | .tx_loadsz = 1, | 191 | .tx_loadsz = 1, |
192 | }, | 192 | }, |
193 | [PORT_16550A] = { | 193 | [PORT_16550A] = { |
194 | .name = "16550A", | 194 | .name = "16550A", |
195 | .fifo_size = 16, | 195 | .fifo_size = 16, |
196 | .tx_loadsz = 16, | 196 | .tx_loadsz = 16, |
197 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, | 197 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
198 | .flags = UART_CAP_FIFO, | 198 | .flags = UART_CAP_FIFO, |
199 | }, | 199 | }, |
200 | [PORT_CIRRUS] = { | 200 | [PORT_CIRRUS] = { |
201 | .name = "Cirrus", | 201 | .name = "Cirrus", |
202 | .fifo_size = 1, | 202 | .fifo_size = 1, |
203 | .tx_loadsz = 1, | 203 | .tx_loadsz = 1, |
204 | }, | 204 | }, |
205 | [PORT_16650] = { | 205 | [PORT_16650] = { |
206 | .name = "ST16650", | 206 | .name = "ST16650", |
207 | .fifo_size = 1, | 207 | .fifo_size = 1, |
208 | .tx_loadsz = 1, | 208 | .tx_loadsz = 1, |
209 | .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, | 209 | .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, |
210 | }, | 210 | }, |
211 | [PORT_16650V2] = { | 211 | [PORT_16650V2] = { |
212 | .name = "ST16650V2", | 212 | .name = "ST16650V2", |
213 | .fifo_size = 32, | 213 | .fifo_size = 32, |
214 | .tx_loadsz = 16, | 214 | .tx_loadsz = 16, |
215 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 | | 215 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 | |
216 | UART_FCR_T_TRIG_00, | 216 | UART_FCR_T_TRIG_00, |
217 | .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, | 217 | .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, |
218 | }, | 218 | }, |
219 | [PORT_16750] = { | 219 | [PORT_16750] = { |
220 | .name = "TI16750", | 220 | .name = "TI16750", |
221 | .fifo_size = 64, | 221 | .fifo_size = 64, |
222 | .tx_loadsz = 64, | 222 | .tx_loadsz = 64, |
223 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 | | 223 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 | |
224 | UART_FCR7_64BYTE, | 224 | UART_FCR7_64BYTE, |
225 | .flags = UART_CAP_FIFO | UART_CAP_SLEEP | UART_CAP_AFE, | 225 | .flags = UART_CAP_FIFO | UART_CAP_SLEEP | UART_CAP_AFE, |
226 | }, | 226 | }, |
227 | [PORT_STARTECH] = { | 227 | [PORT_STARTECH] = { |
228 | .name = "Startech", | 228 | .name = "Startech", |
229 | .fifo_size = 1, | 229 | .fifo_size = 1, |
230 | .tx_loadsz = 1, | 230 | .tx_loadsz = 1, |
231 | }, | 231 | }, |
232 | [PORT_16C950] = { | 232 | [PORT_16C950] = { |
233 | .name = "16C950/954", | 233 | .name = "16C950/954", |
234 | .fifo_size = 128, | 234 | .fifo_size = 128, |
235 | .tx_loadsz = 128, | 235 | .tx_loadsz = 128, |
236 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, | 236 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
237 | .flags = UART_CAP_FIFO, | 237 | .flags = UART_CAP_FIFO, |
238 | }, | 238 | }, |
239 | [PORT_16654] = { | 239 | [PORT_16654] = { |
240 | .name = "ST16654", | 240 | .name = "ST16654", |
241 | .fifo_size = 64, | 241 | .fifo_size = 64, |
242 | .tx_loadsz = 32, | 242 | .tx_loadsz = 32, |
243 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 | | 243 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 | |
244 | UART_FCR_T_TRIG_10, | 244 | UART_FCR_T_TRIG_10, |
245 | .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, | 245 | .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, |
246 | }, | 246 | }, |
247 | [PORT_16850] = { | 247 | [PORT_16850] = { |
248 | .name = "XR16850", | 248 | .name = "XR16850", |
249 | .fifo_size = 128, | 249 | .fifo_size = 128, |
250 | .tx_loadsz = 128, | 250 | .tx_loadsz = 128, |
251 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, | 251 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
252 | .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, | 252 | .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, |
253 | }, | 253 | }, |
254 | [PORT_RSA] = { | 254 | [PORT_RSA] = { |
255 | .name = "RSA", | 255 | .name = "RSA", |
256 | .fifo_size = 2048, | 256 | .fifo_size = 2048, |
257 | .tx_loadsz = 2048, | 257 | .tx_loadsz = 2048, |
258 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_11, | 258 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_11, |
259 | .flags = UART_CAP_FIFO, | 259 | .flags = UART_CAP_FIFO, |
260 | }, | 260 | }, |
261 | [PORT_NS16550A] = { | 261 | [PORT_NS16550A] = { |
262 | .name = "NS16550A", | 262 | .name = "NS16550A", |
263 | .fifo_size = 16, | 263 | .fifo_size = 16, |
264 | .tx_loadsz = 16, | 264 | .tx_loadsz = 16, |
265 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, | 265 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
266 | .flags = UART_CAP_FIFO | UART_NATSEMI, | 266 | .flags = UART_CAP_FIFO | UART_NATSEMI, |
267 | }, | 267 | }, |
268 | [PORT_XSCALE] = { | 268 | [PORT_XSCALE] = { |
269 | .name = "XScale", | 269 | .name = "XScale", |
270 | .fifo_size = 32, | 270 | .fifo_size = 32, |
271 | .tx_loadsz = 32, | 271 | .tx_loadsz = 32, |
272 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, | 272 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
273 | .flags = UART_CAP_FIFO | UART_CAP_UUE, | 273 | .flags = UART_CAP_FIFO | UART_CAP_UUE, |
274 | }, | 274 | }, |
275 | [PORT_RM9000] = { | 275 | [PORT_RM9000] = { |
276 | .name = "RM9000", | 276 | .name = "RM9000", |
277 | .fifo_size = 16, | 277 | .fifo_size = 16, |
278 | .tx_loadsz = 16, | 278 | .tx_loadsz = 16, |
279 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, | 279 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
280 | .flags = UART_CAP_FIFO, | 280 | .flags = UART_CAP_FIFO, |
281 | }, | 281 | }, |
282 | }; | 282 | }; |
283 | 283 | ||
284 | #if defined (CONFIG_SERIAL_8250_AU1X00) | 284 | #if defined (CONFIG_SERIAL_8250_AU1X00) |
285 | 285 | ||
286 | /* Au1x00 UART hardware has a weird register layout */ | 286 | /* Au1x00 UART hardware has a weird register layout */ |
287 | static const u8 au_io_in_map[] = { | 287 | static const u8 au_io_in_map[] = { |
288 | [UART_RX] = 0, | 288 | [UART_RX] = 0, |
289 | [UART_IER] = 2, | 289 | [UART_IER] = 2, |
290 | [UART_IIR] = 3, | 290 | [UART_IIR] = 3, |
291 | [UART_LCR] = 5, | 291 | [UART_LCR] = 5, |
292 | [UART_MCR] = 6, | 292 | [UART_MCR] = 6, |
293 | [UART_LSR] = 7, | 293 | [UART_LSR] = 7, |
294 | [UART_MSR] = 8, | 294 | [UART_MSR] = 8, |
295 | }; | 295 | }; |
296 | 296 | ||
297 | static const u8 au_io_out_map[] = { | 297 | static const u8 au_io_out_map[] = { |
298 | [UART_TX] = 1, | 298 | [UART_TX] = 1, |
299 | [UART_IER] = 2, | 299 | [UART_IER] = 2, |
300 | [UART_FCR] = 4, | 300 | [UART_FCR] = 4, |
301 | [UART_LCR] = 5, | 301 | [UART_LCR] = 5, |
302 | [UART_MCR] = 6, | 302 | [UART_MCR] = 6, |
303 | }; | 303 | }; |
304 | 304 | ||
305 | /* sane hardware needs no mapping */ | 305 | /* sane hardware needs no mapping */ |
306 | static inline int map_8250_in_reg(struct uart_port *p, int offset) | 306 | static inline int map_8250_in_reg(struct uart_port *p, int offset) |
307 | { | 307 | { |
308 | if (p->iotype != UPIO_AU) | 308 | if (p->iotype != UPIO_AU) |
309 | return offset; | 309 | return offset; |
310 | return au_io_in_map[offset]; | 310 | return au_io_in_map[offset]; |
311 | } | 311 | } |
312 | 312 | ||
313 | static inline int map_8250_out_reg(struct uart_port *p, int offset) | 313 | static inline int map_8250_out_reg(struct uart_port *p, int offset) |
314 | { | 314 | { |
315 | if (p->iotype != UPIO_AU) | 315 | if (p->iotype != UPIO_AU) |
316 | return offset; | 316 | return offset; |
317 | return au_io_out_map[offset]; | 317 | return au_io_out_map[offset]; |
318 | } | 318 | } |
319 | 319 | ||
320 | #elif defined(CONFIG_SERIAL_8250_RM9K) | 320 | #elif defined(CONFIG_SERIAL_8250_RM9K) |
321 | 321 | ||
322 | static const u8 | 322 | static const u8 |
323 | regmap_in[8] = { | 323 | regmap_in[8] = { |
324 | [UART_RX] = 0x00, | 324 | [UART_RX] = 0x00, |
325 | [UART_IER] = 0x0c, | 325 | [UART_IER] = 0x0c, |
326 | [UART_IIR] = 0x14, | 326 | [UART_IIR] = 0x14, |
327 | [UART_LCR] = 0x1c, | 327 | [UART_LCR] = 0x1c, |
328 | [UART_MCR] = 0x20, | 328 | [UART_MCR] = 0x20, |
329 | [UART_LSR] = 0x24, | 329 | [UART_LSR] = 0x24, |
330 | [UART_MSR] = 0x28, | 330 | [UART_MSR] = 0x28, |
331 | [UART_SCR] = 0x2c | 331 | [UART_SCR] = 0x2c |
332 | }, | 332 | }, |
333 | regmap_out[8] = { | 333 | regmap_out[8] = { |
334 | [UART_TX] = 0x04, | 334 | [UART_TX] = 0x04, |
335 | [UART_IER] = 0x0c, | 335 | [UART_IER] = 0x0c, |
336 | [UART_FCR] = 0x18, | 336 | [UART_FCR] = 0x18, |
337 | [UART_LCR] = 0x1c, | 337 | [UART_LCR] = 0x1c, |
338 | [UART_MCR] = 0x20, | 338 | [UART_MCR] = 0x20, |
339 | [UART_LSR] = 0x24, | 339 | [UART_LSR] = 0x24, |
340 | [UART_MSR] = 0x28, | 340 | [UART_MSR] = 0x28, |
341 | [UART_SCR] = 0x2c | 341 | [UART_SCR] = 0x2c |
342 | }; | 342 | }; |
343 | 343 | ||
344 | static inline int map_8250_in_reg(struct uart_port *p, int offset) | 344 | static inline int map_8250_in_reg(struct uart_port *p, int offset) |
345 | { | 345 | { |
346 | if (p->iotype != UPIO_RM9000) | 346 | if (p->iotype != UPIO_RM9000) |
347 | return offset; | 347 | return offset; |
348 | return regmap_in[offset]; | 348 | return regmap_in[offset]; |
349 | } | 349 | } |
350 | 350 | ||
351 | static inline int map_8250_out_reg(struct uart_port *p, int offset) | 351 | static inline int map_8250_out_reg(struct uart_port *p, int offset) |
352 | { | 352 | { |
353 | if (p->iotype != UPIO_RM9000) | 353 | if (p->iotype != UPIO_RM9000) |
354 | return offset; | 354 | return offset; |
355 | return regmap_out[offset]; | 355 | return regmap_out[offset]; |
356 | } | 356 | } |
357 | 357 | ||
358 | #else | 358 | #else |
359 | 359 | ||
360 | /* sane hardware needs no mapping */ | 360 | /* sane hardware needs no mapping */ |
361 | #define map_8250_in_reg(up, offset) (offset) | 361 | #define map_8250_in_reg(up, offset) (offset) |
362 | #define map_8250_out_reg(up, offset) (offset) | 362 | #define map_8250_out_reg(up, offset) (offset) |
363 | 363 | ||
364 | #endif | 364 | #endif |
365 | 365 | ||
366 | static unsigned int hub6_serial_in(struct uart_port *p, int offset) | 366 | static unsigned int hub6_serial_in(struct uart_port *p, int offset) |
367 | { | 367 | { |
368 | offset = map_8250_in_reg(p, offset) << p->regshift; | 368 | offset = map_8250_in_reg(p, offset) << p->regshift; |
369 | outb(p->hub6 - 1 + offset, p->iobase); | 369 | outb(p->hub6 - 1 + offset, p->iobase); |
370 | return inb(p->iobase + 1); | 370 | return inb(p->iobase + 1); |
371 | } | 371 | } |
372 | 372 | ||
373 | static void hub6_serial_out(struct uart_port *p, int offset, int value) | 373 | static void hub6_serial_out(struct uart_port *p, int offset, int value) |
374 | { | 374 | { |
375 | offset = map_8250_out_reg(p, offset) << p->regshift; | 375 | offset = map_8250_out_reg(p, offset) << p->regshift; |
376 | outb(p->hub6 - 1 + offset, p->iobase); | 376 | outb(p->hub6 - 1 + offset, p->iobase); |
377 | outb(value, p->iobase + 1); | 377 | outb(value, p->iobase + 1); |
378 | } | 378 | } |
379 | 379 | ||
380 | static unsigned int mem_serial_in(struct uart_port *p, int offset) | 380 | static unsigned int mem_serial_in(struct uart_port *p, int offset) |
381 | { | 381 | { |
382 | offset = map_8250_in_reg(p, offset) << p->regshift; | 382 | offset = map_8250_in_reg(p, offset) << p->regshift; |
383 | return readb(p->membase + offset); | 383 | return readb(p->membase + offset); |
384 | } | 384 | } |
385 | 385 | ||
386 | static void mem_serial_out(struct uart_port *p, int offset, int value) | 386 | static void mem_serial_out(struct uart_port *p, int offset, int value) |
387 | { | 387 | { |
388 | offset = map_8250_out_reg(p, offset) << p->regshift; | 388 | offset = map_8250_out_reg(p, offset) << p->regshift; |
389 | writeb(value, p->membase + offset); | 389 | writeb(value, p->membase + offset); |
390 | } | 390 | } |
391 | 391 | ||
392 | static void mem32_serial_out(struct uart_port *p, int offset, int value) | 392 | static void mem32_serial_out(struct uart_port *p, int offset, int value) |
393 | { | 393 | { |
394 | offset = map_8250_out_reg(p, offset) << p->regshift; | 394 | offset = map_8250_out_reg(p, offset) << p->regshift; |
395 | writel(value, p->membase + offset); | 395 | writel(value, p->membase + offset); |
396 | } | 396 | } |
397 | 397 | ||
398 | static unsigned int mem32_serial_in(struct uart_port *p, int offset) | 398 | static unsigned int mem32_serial_in(struct uart_port *p, int offset) |
399 | { | 399 | { |
400 | offset = map_8250_in_reg(p, offset) << p->regshift; | 400 | offset = map_8250_in_reg(p, offset) << p->regshift; |
401 | return readl(p->membase + offset); | 401 | return readl(p->membase + offset); |
402 | } | 402 | } |
403 | 403 | ||
404 | #ifdef CONFIG_SERIAL_8250_AU1X00 | 404 | #ifdef CONFIG_SERIAL_8250_AU1X00 |
405 | static unsigned int au_serial_in(struct uart_port *p, int offset) | 405 | static unsigned int au_serial_in(struct uart_port *p, int offset) |
406 | { | 406 | { |
407 | offset = map_8250_in_reg(p, offset) << p->regshift; | 407 | offset = map_8250_in_reg(p, offset) << p->regshift; |
408 | return __raw_readl(p->membase + offset); | 408 | return __raw_readl(p->membase + offset); |
409 | } | 409 | } |
410 | 410 | ||
411 | static void au_serial_out(struct uart_port *p, int offset, int value) | 411 | static void au_serial_out(struct uart_port *p, int offset, int value) |
412 | { | 412 | { |
413 | offset = map_8250_out_reg(p, offset) << p->regshift; | 413 | offset = map_8250_out_reg(p, offset) << p->regshift; |
414 | __raw_writel(value, p->membase + offset); | 414 | __raw_writel(value, p->membase + offset); |
415 | } | 415 | } |
416 | #endif | 416 | #endif |
417 | 417 | ||
418 | static unsigned int tsi_serial_in(struct uart_port *p, int offset) | 418 | static unsigned int tsi_serial_in(struct uart_port *p, int offset) |
419 | { | 419 | { |
420 | unsigned int tmp; | 420 | unsigned int tmp; |
421 | offset = map_8250_in_reg(p, offset) << p->regshift; | 421 | offset = map_8250_in_reg(p, offset) << p->regshift; |
422 | if (offset == UART_IIR) { | 422 | if (offset == UART_IIR) { |
423 | tmp = readl(p->membase + (UART_IIR & ~3)); | 423 | tmp = readl(p->membase + (UART_IIR & ~3)); |
424 | return (tmp >> 16) & 0xff; /* UART_IIR % 4 == 2 */ | 424 | return (tmp >> 16) & 0xff; /* UART_IIR % 4 == 2 */ |
425 | } else | 425 | } else |
426 | return readb(p->membase + offset); | 426 | return readb(p->membase + offset); |
427 | } | 427 | } |
428 | 428 | ||
429 | static void tsi_serial_out(struct uart_port *p, int offset, int value) | 429 | static void tsi_serial_out(struct uart_port *p, int offset, int value) |
430 | { | 430 | { |
431 | offset = map_8250_out_reg(p, offset) << p->regshift; | 431 | offset = map_8250_out_reg(p, offset) << p->regshift; |
432 | if (!((offset == UART_IER) && (value & UART_IER_UUE))) | 432 | if (!((offset == UART_IER) && (value & UART_IER_UUE))) |
433 | writeb(value, p->membase + offset); | 433 | writeb(value, p->membase + offset); |
434 | } | 434 | } |
435 | 435 | ||
436 | static void dwapb_serial_out(struct uart_port *p, int offset, int value) | 436 | static void dwapb_serial_out(struct uart_port *p, int offset, int value) |
437 | { | 437 | { |
438 | int save_offset = offset; | 438 | int save_offset = offset; |
439 | offset = map_8250_out_reg(p, offset) << p->regshift; | 439 | offset = map_8250_out_reg(p, offset) << p->regshift; |
440 | /* Save the LCR value so it can be re-written when a | 440 | /* Save the LCR value so it can be re-written when a |
441 | * Busy Detect interrupt occurs. */ | 441 | * Busy Detect interrupt occurs. */ |
442 | if (save_offset == UART_LCR) { | 442 | if (save_offset == UART_LCR) { |
443 | struct uart_8250_port *up = (struct uart_8250_port *)p; | 443 | struct uart_8250_port *up = (struct uart_8250_port *)p; |
444 | up->lcr = value; | 444 | up->lcr = value; |
445 | } | 445 | } |
446 | writeb(value, p->membase + offset); | 446 | writeb(value, p->membase + offset); |
447 | /* Read the IER to ensure any interrupt is cleared before | 447 | /* Read the IER to ensure any interrupt is cleared before |
448 | * returning from ISR. */ | 448 | * returning from ISR. */ |
449 | if (save_offset == UART_TX || save_offset == UART_IER) | 449 | if (save_offset == UART_TX || save_offset == UART_IER) |
450 | value = p->serial_in(p, UART_IER); | 450 | value = p->serial_in(p, UART_IER); |
451 | } | 451 | } |
452 | 452 | ||
453 | static unsigned int io_serial_in(struct uart_port *p, int offset) | 453 | static unsigned int io_serial_in(struct uart_port *p, int offset) |
454 | { | 454 | { |
455 | offset = map_8250_in_reg(p, offset) << p->regshift; | 455 | offset = map_8250_in_reg(p, offset) << p->regshift; |
456 | return inb(p->iobase + offset); | 456 | return inb(p->iobase + offset); |
457 | } | 457 | } |
458 | 458 | ||
459 | static void io_serial_out(struct uart_port *p, int offset, int value) | 459 | static void io_serial_out(struct uart_port *p, int offset, int value) |
460 | { | 460 | { |
461 | offset = map_8250_out_reg(p, offset) << p->regshift; | 461 | offset = map_8250_out_reg(p, offset) << p->regshift; |
462 | outb(value, p->iobase + offset); | 462 | outb(value, p->iobase + offset); |
463 | } | 463 | } |
464 | 464 | ||
465 | static void set_io_from_upio(struct uart_port *p) | 465 | static void set_io_from_upio(struct uart_port *p) |
466 | { | 466 | { |
467 | switch (p->iotype) { | 467 | switch (p->iotype) { |
468 | case UPIO_HUB6: | 468 | case UPIO_HUB6: |
469 | p->serial_in = hub6_serial_in; | 469 | p->serial_in = hub6_serial_in; |
470 | p->serial_out = hub6_serial_out; | 470 | p->serial_out = hub6_serial_out; |
471 | break; | 471 | break; |
472 | 472 | ||
473 | case UPIO_MEM: | 473 | case UPIO_MEM: |
474 | p->serial_in = mem_serial_in; | 474 | p->serial_in = mem_serial_in; |
475 | p->serial_out = mem_serial_out; | 475 | p->serial_out = mem_serial_out; |
476 | break; | 476 | break; |
477 | 477 | ||
478 | case UPIO_RM9000: | 478 | case UPIO_RM9000: |
479 | case UPIO_MEM32: | 479 | case UPIO_MEM32: |
480 | p->serial_in = mem32_serial_in; | 480 | p->serial_in = mem32_serial_in; |
481 | p->serial_out = mem32_serial_out; | 481 | p->serial_out = mem32_serial_out; |
482 | break; | 482 | break; |
483 | 483 | ||
484 | #ifdef CONFIG_SERIAL_8250_AU1X00 | 484 | #ifdef CONFIG_SERIAL_8250_AU1X00 |
485 | case UPIO_AU: | 485 | case UPIO_AU: |
486 | p->serial_in = au_serial_in; | 486 | p->serial_in = au_serial_in; |
487 | p->serial_out = au_serial_out; | 487 | p->serial_out = au_serial_out; |
488 | break; | 488 | break; |
489 | #endif | 489 | #endif |
490 | case UPIO_TSI: | 490 | case UPIO_TSI: |
491 | p->serial_in = tsi_serial_in; | 491 | p->serial_in = tsi_serial_in; |
492 | p->serial_out = tsi_serial_out; | 492 | p->serial_out = tsi_serial_out; |
493 | break; | 493 | break; |
494 | 494 | ||
495 | case UPIO_DWAPB: | 495 | case UPIO_DWAPB: |
496 | p->serial_in = mem_serial_in; | 496 | p->serial_in = mem_serial_in; |
497 | p->serial_out = dwapb_serial_out; | 497 | p->serial_out = dwapb_serial_out; |
498 | break; | 498 | break; |
499 | 499 | ||
500 | default: | 500 | default: |
501 | p->serial_in = io_serial_in; | 501 | p->serial_in = io_serial_in; |
502 | p->serial_out = io_serial_out; | 502 | p->serial_out = io_serial_out; |
503 | break; | 503 | break; |
504 | } | 504 | } |
505 | } | 505 | } |
506 | 506 | ||
507 | static void | 507 | static void |
508 | serial_out_sync(struct uart_8250_port *up, int offset, int value) | 508 | serial_out_sync(struct uart_8250_port *up, int offset, int value) |
509 | { | 509 | { |
510 | struct uart_port *p = &up->port; | 510 | struct uart_port *p = &up->port; |
511 | switch (p->iotype) { | 511 | switch (p->iotype) { |
512 | case UPIO_MEM: | 512 | case UPIO_MEM: |
513 | case UPIO_MEM32: | 513 | case UPIO_MEM32: |
514 | #ifdef CONFIG_SERIAL_8250_AU1X00 | 514 | #ifdef CONFIG_SERIAL_8250_AU1X00 |
515 | case UPIO_AU: | 515 | case UPIO_AU: |
516 | #endif | 516 | #endif |
517 | case UPIO_DWAPB: | 517 | case UPIO_DWAPB: |
518 | p->serial_out(p, offset, value); | 518 | p->serial_out(p, offset, value); |
519 | p->serial_in(p, UART_LCR); /* safe, no side-effects */ | 519 | p->serial_in(p, UART_LCR); /* safe, no side-effects */ |
520 | break; | 520 | break; |
521 | default: | 521 | default: |
522 | p->serial_out(p, offset, value); | 522 | p->serial_out(p, offset, value); |
523 | } | 523 | } |
524 | } | 524 | } |
525 | 525 | ||
526 | #define serial_in(up, offset) \ | 526 | #define serial_in(up, offset) \ |
527 | (up->port.serial_in(&(up)->port, (offset))) | 527 | (up->port.serial_in(&(up)->port, (offset))) |
528 | #define serial_out(up, offset, value) \ | 528 | #define serial_out(up, offset, value) \ |
529 | (up->port.serial_out(&(up)->port, (offset), (value))) | 529 | (up->port.serial_out(&(up)->port, (offset), (value))) |
530 | /* | 530 | /* |
531 | * We used to support using pause I/O for certain machines. We | 531 | * We used to support using pause I/O for certain machines. We |
532 | * haven't supported this for a while, but just in case it's badly | 532 | * haven't supported this for a while, but just in case it's badly |
533 | * needed for certain old 386 machines, I've left these #define's | 533 | * needed for certain old 386 machines, I've left these #define's |
534 | * in.... | 534 | * in.... |
535 | */ | 535 | */ |
536 | #define serial_inp(up, offset) serial_in(up, offset) | 536 | #define serial_inp(up, offset) serial_in(up, offset) |
537 | #define serial_outp(up, offset, value) serial_out(up, offset, value) | 537 | #define serial_outp(up, offset, value) serial_out(up, offset, value) |
538 | 538 | ||
539 | /* Uart divisor latch read */ | 539 | /* Uart divisor latch read */ |
540 | static inline int _serial_dl_read(struct uart_8250_port *up) | 540 | static inline int _serial_dl_read(struct uart_8250_port *up) |
541 | { | 541 | { |
542 | return serial_inp(up, UART_DLL) | serial_inp(up, UART_DLM) << 8; | 542 | return serial_inp(up, UART_DLL) | serial_inp(up, UART_DLM) << 8; |
543 | } | 543 | } |
544 | 544 | ||
545 | /* Uart divisor latch write */ | 545 | /* Uart divisor latch write */ |
546 | static inline void _serial_dl_write(struct uart_8250_port *up, int value) | 546 | static inline void _serial_dl_write(struct uart_8250_port *up, int value) |
547 | { | 547 | { |
548 | serial_outp(up, UART_DLL, value & 0xff); | 548 | serial_outp(up, UART_DLL, value & 0xff); |
549 | serial_outp(up, UART_DLM, value >> 8 & 0xff); | 549 | serial_outp(up, UART_DLM, value >> 8 & 0xff); |
550 | } | 550 | } |
551 | 551 | ||
552 | #if defined(CONFIG_SERIAL_8250_AU1X00) | 552 | #if defined(CONFIG_SERIAL_8250_AU1X00) |
553 | /* Au1x00 haven't got a standard divisor latch */ | 553 | /* Au1x00 haven't got a standard divisor latch */ |
554 | static int serial_dl_read(struct uart_8250_port *up) | 554 | static int serial_dl_read(struct uart_8250_port *up) |
555 | { | 555 | { |
556 | if (up->port.iotype == UPIO_AU) | 556 | if (up->port.iotype == UPIO_AU) |
557 | return __raw_readl(up->port.membase + 0x28); | 557 | return __raw_readl(up->port.membase + 0x28); |
558 | else | 558 | else |
559 | return _serial_dl_read(up); | 559 | return _serial_dl_read(up); |
560 | } | 560 | } |
561 | 561 | ||
562 | static void serial_dl_write(struct uart_8250_port *up, int value) | 562 | static void serial_dl_write(struct uart_8250_port *up, int value) |
563 | { | 563 | { |
564 | if (up->port.iotype == UPIO_AU) | 564 | if (up->port.iotype == UPIO_AU) |
565 | __raw_writel(value, up->port.membase + 0x28); | 565 | __raw_writel(value, up->port.membase + 0x28); |
566 | else | 566 | else |
567 | _serial_dl_write(up, value); | 567 | _serial_dl_write(up, value); |
568 | } | 568 | } |
569 | #elif defined(CONFIG_SERIAL_8250_RM9K) | 569 | #elif defined(CONFIG_SERIAL_8250_RM9K) |
570 | static int serial_dl_read(struct uart_8250_port *up) | 570 | static int serial_dl_read(struct uart_8250_port *up) |
571 | { | 571 | { |
572 | return (up->port.iotype == UPIO_RM9000) ? | 572 | return (up->port.iotype == UPIO_RM9000) ? |
573 | (((__raw_readl(up->port.membase + 0x10) << 8) | | 573 | (((__raw_readl(up->port.membase + 0x10) << 8) | |
574 | (__raw_readl(up->port.membase + 0x08) & 0xff)) & 0xffff) : | 574 | (__raw_readl(up->port.membase + 0x08) & 0xff)) & 0xffff) : |
575 | _serial_dl_read(up); | 575 | _serial_dl_read(up); |
576 | } | 576 | } |
577 | 577 | ||
578 | static void serial_dl_write(struct uart_8250_port *up, int value) | 578 | static void serial_dl_write(struct uart_8250_port *up, int value) |
579 | { | 579 | { |
580 | if (up->port.iotype == UPIO_RM9000) { | 580 | if (up->port.iotype == UPIO_RM9000) { |
581 | __raw_writel(value, up->port.membase + 0x08); | 581 | __raw_writel(value, up->port.membase + 0x08); |
582 | __raw_writel(value >> 8, up->port.membase + 0x10); | 582 | __raw_writel(value >> 8, up->port.membase + 0x10); |
583 | } else { | 583 | } else { |
584 | _serial_dl_write(up, value); | 584 | _serial_dl_write(up, value); |
585 | } | 585 | } |
586 | } | 586 | } |
587 | #else | 587 | #else |
588 | #define serial_dl_read(up) _serial_dl_read(up) | 588 | #define serial_dl_read(up) _serial_dl_read(up) |
589 | #define serial_dl_write(up, value) _serial_dl_write(up, value) | 589 | #define serial_dl_write(up, value) _serial_dl_write(up, value) |
590 | #endif | 590 | #endif |
591 | 591 | ||
592 | /* | 592 | /* |
593 | * For the 16C950 | 593 | * For the 16C950 |
594 | */ | 594 | */ |
595 | static void serial_icr_write(struct uart_8250_port *up, int offset, int value) | 595 | static void serial_icr_write(struct uart_8250_port *up, int offset, int value) |
596 | { | 596 | { |
597 | serial_out(up, UART_SCR, offset); | 597 | serial_out(up, UART_SCR, offset); |
598 | serial_out(up, UART_ICR, value); | 598 | serial_out(up, UART_ICR, value); |
599 | } | 599 | } |
600 | 600 | ||
601 | static unsigned int serial_icr_read(struct uart_8250_port *up, int offset) | 601 | static unsigned int serial_icr_read(struct uart_8250_port *up, int offset) |
602 | { | 602 | { |
603 | unsigned int value; | 603 | unsigned int value; |
604 | 604 | ||
605 | serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD); | 605 | serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD); |
606 | serial_out(up, UART_SCR, offset); | 606 | serial_out(up, UART_SCR, offset); |
607 | value = serial_in(up, UART_ICR); | 607 | value = serial_in(up, UART_ICR); |
608 | serial_icr_write(up, UART_ACR, up->acr); | 608 | serial_icr_write(up, UART_ACR, up->acr); |
609 | 609 | ||
610 | return value; | 610 | return value; |
611 | } | 611 | } |
612 | 612 | ||
613 | /* | 613 | /* |
614 | * FIFO support. | 614 | * FIFO support. |
615 | */ | 615 | */ |
616 | static void serial8250_clear_fifos(struct uart_8250_port *p) | 616 | static void serial8250_clear_fifos(struct uart_8250_port *p) |
617 | { | 617 | { |
618 | if (p->capabilities & UART_CAP_FIFO) { | 618 | if (p->capabilities & UART_CAP_FIFO) { |
619 | serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO); | 619 | serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO); |
620 | serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO | | 620 | serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO | |
621 | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); | 621 | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); |
622 | serial_outp(p, UART_FCR, 0); | 622 | serial_outp(p, UART_FCR, 0); |
623 | } | 623 | } |
624 | } | 624 | } |
625 | 625 | ||
626 | /* | 626 | /* |
627 | * IER sleep support. UARTs which have EFRs need the "extended | 627 | * IER sleep support. UARTs which have EFRs need the "extended |
628 | * capability" bit enabled. Note that on XR16C850s, we need to | 628 | * capability" bit enabled. Note that on XR16C850s, we need to |
629 | * reset LCR to write to IER. | 629 | * reset LCR to write to IER. |
630 | */ | 630 | */ |
631 | static void serial8250_set_sleep(struct uart_8250_port *p, int sleep) | 631 | static void serial8250_set_sleep(struct uart_8250_port *p, int sleep) |
632 | { | 632 | { |
633 | if (p->capabilities & UART_CAP_SLEEP) { | 633 | if (p->capabilities & UART_CAP_SLEEP) { |
634 | if (p->capabilities & UART_CAP_EFR) { | 634 | if (p->capabilities & UART_CAP_EFR) { |
635 | serial_outp(p, UART_LCR, 0xBF); | 635 | serial_outp(p, UART_LCR, 0xBF); |
636 | serial_outp(p, UART_EFR, UART_EFR_ECB); | 636 | serial_outp(p, UART_EFR, UART_EFR_ECB); |
637 | serial_outp(p, UART_LCR, 0); | 637 | serial_outp(p, UART_LCR, 0); |
638 | } | 638 | } |
639 | serial_outp(p, UART_IER, sleep ? UART_IERX_SLEEP : 0); | 639 | serial_outp(p, UART_IER, sleep ? UART_IERX_SLEEP : 0); |
640 | if (p->capabilities & UART_CAP_EFR) { | 640 | if (p->capabilities & UART_CAP_EFR) { |
641 | serial_outp(p, UART_LCR, 0xBF); | 641 | serial_outp(p, UART_LCR, 0xBF); |
642 | serial_outp(p, UART_EFR, 0); | 642 | serial_outp(p, UART_EFR, 0); |
643 | serial_outp(p, UART_LCR, 0); | 643 | serial_outp(p, UART_LCR, 0); |
644 | } | 644 | } |
645 | } | 645 | } |
646 | } | 646 | } |
647 | 647 | ||
648 | #ifdef CONFIG_SERIAL_8250_RSA | 648 | #ifdef CONFIG_SERIAL_8250_RSA |
649 | /* | 649 | /* |
650 | * Attempts to turn on the RSA FIFO. Returns zero on failure. | 650 | * Attempts to turn on the RSA FIFO. Returns zero on failure. |
651 | * We set the port uart clock rate if we succeed. | 651 | * We set the port uart clock rate if we succeed. |
652 | */ | 652 | */ |
653 | static int __enable_rsa(struct uart_8250_port *up) | 653 | static int __enable_rsa(struct uart_8250_port *up) |
654 | { | 654 | { |
655 | unsigned char mode; | 655 | unsigned char mode; |
656 | int result; | 656 | int result; |
657 | 657 | ||
658 | mode = serial_inp(up, UART_RSA_MSR); | 658 | mode = serial_inp(up, UART_RSA_MSR); |
659 | result = mode & UART_RSA_MSR_FIFO; | 659 | result = mode & UART_RSA_MSR_FIFO; |
660 | 660 | ||
661 | if (!result) { | 661 | if (!result) { |
662 | serial_outp(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO); | 662 | serial_outp(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO); |
663 | mode = serial_inp(up, UART_RSA_MSR); | 663 | mode = serial_inp(up, UART_RSA_MSR); |
664 | result = mode & UART_RSA_MSR_FIFO; | 664 | result = mode & UART_RSA_MSR_FIFO; |
665 | } | 665 | } |
666 | 666 | ||
667 | if (result) | 667 | if (result) |
668 | up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16; | 668 | up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16; |
669 | 669 | ||
670 | return result; | 670 | return result; |
671 | } | 671 | } |
672 | 672 | ||
673 | static void enable_rsa(struct uart_8250_port *up) | 673 | static void enable_rsa(struct uart_8250_port *up) |
674 | { | 674 | { |
675 | if (up->port.type == PORT_RSA) { | 675 | if (up->port.type == PORT_RSA) { |
676 | if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) { | 676 | if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) { |
677 | spin_lock_irq(&up->port.lock); | 677 | spin_lock_irq(&up->port.lock); |
678 | __enable_rsa(up); | 678 | __enable_rsa(up); |
679 | spin_unlock_irq(&up->port.lock); | 679 | spin_unlock_irq(&up->port.lock); |
680 | } | 680 | } |
681 | if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) | 681 | if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) |
682 | serial_outp(up, UART_RSA_FRR, 0); | 682 | serial_outp(up, UART_RSA_FRR, 0); |
683 | } | 683 | } |
684 | } | 684 | } |
685 | 685 | ||
686 | /* | 686 | /* |
687 | * Attempts to turn off the RSA FIFO. Returns zero on failure. | 687 | * Attempts to turn off the RSA FIFO. Returns zero on failure. |
688 | * It is unknown why interrupts were disabled in here. However, | 688 | * It is unknown why interrupts were disabled in here. However, |
689 | * the caller is expected to preserve this behaviour by grabbing | 689 | * the caller is expected to preserve this behaviour by grabbing |
690 | * the spinlock before calling this function. | 690 | * the spinlock before calling this function. |
691 | */ | 691 | */ |
692 | static void disable_rsa(struct uart_8250_port *up) | 692 | static void disable_rsa(struct uart_8250_port *up) |
693 | { | 693 | { |
694 | unsigned char mode; | 694 | unsigned char mode; |
695 | int result; | 695 | int result; |
696 | 696 | ||
697 | if (up->port.type == PORT_RSA && | 697 | if (up->port.type == PORT_RSA && |
698 | up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) { | 698 | up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) { |
699 | spin_lock_irq(&up->port.lock); | 699 | spin_lock_irq(&up->port.lock); |
700 | 700 | ||
701 | mode = serial_inp(up, UART_RSA_MSR); | 701 | mode = serial_inp(up, UART_RSA_MSR); |
702 | result = !(mode & UART_RSA_MSR_FIFO); | 702 | result = !(mode & UART_RSA_MSR_FIFO); |
703 | 703 | ||
704 | if (!result) { | 704 | if (!result) { |
705 | serial_outp(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO); | 705 | serial_outp(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO); |
706 | mode = serial_inp(up, UART_RSA_MSR); | 706 | mode = serial_inp(up, UART_RSA_MSR); |
707 | result = !(mode & UART_RSA_MSR_FIFO); | 707 | result = !(mode & UART_RSA_MSR_FIFO); |
708 | } | 708 | } |
709 | 709 | ||
710 | if (result) | 710 | if (result) |
711 | up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16; | 711 | up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16; |
712 | spin_unlock_irq(&up->port.lock); | 712 | spin_unlock_irq(&up->port.lock); |
713 | } | 713 | } |
714 | } | 714 | } |
715 | #endif /* CONFIG_SERIAL_8250_RSA */ | 715 | #endif /* CONFIG_SERIAL_8250_RSA */ |
716 | 716 | ||
717 | /* | 717 | /* |
718 | * This is a quickie test to see how big the FIFO is. | 718 | * This is a quickie test to see how big the FIFO is. |
719 | * It doesn't work at all the time, more's the pity. | 719 | * It doesn't work at all the time, more's the pity. |
720 | */ | 720 | */ |
721 | static int size_fifo(struct uart_8250_port *up) | 721 | static int size_fifo(struct uart_8250_port *up) |
722 | { | 722 | { |
723 | unsigned char old_fcr, old_mcr, old_lcr; | 723 | unsigned char old_fcr, old_mcr, old_lcr; |
724 | unsigned short old_dl; | 724 | unsigned short old_dl; |
725 | int count; | 725 | int count; |
726 | 726 | ||
727 | old_lcr = serial_inp(up, UART_LCR); | 727 | old_lcr = serial_inp(up, UART_LCR); |
728 | serial_outp(up, UART_LCR, 0); | 728 | serial_outp(up, UART_LCR, 0); |
729 | old_fcr = serial_inp(up, UART_FCR); | 729 | old_fcr = serial_inp(up, UART_FCR); |
730 | old_mcr = serial_inp(up, UART_MCR); | 730 | old_mcr = serial_inp(up, UART_MCR); |
731 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | | 731 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | |
732 | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); | 732 | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); |
733 | serial_outp(up, UART_MCR, UART_MCR_LOOP); | 733 | serial_outp(up, UART_MCR, UART_MCR_LOOP); |
734 | serial_outp(up, UART_LCR, UART_LCR_DLAB); | 734 | serial_outp(up, UART_LCR, UART_LCR_DLAB); |
735 | old_dl = serial_dl_read(up); | 735 | old_dl = serial_dl_read(up); |
736 | serial_dl_write(up, 0x0001); | 736 | serial_dl_write(up, 0x0001); |
737 | serial_outp(up, UART_LCR, 0x03); | 737 | serial_outp(up, UART_LCR, 0x03); |
738 | for (count = 0; count < 256; count++) | 738 | for (count = 0; count < 256; count++) |
739 | serial_outp(up, UART_TX, count); | 739 | serial_outp(up, UART_TX, count); |
740 | mdelay(20);/* FIXME - schedule_timeout */ | 740 | mdelay(20);/* FIXME - schedule_timeout */ |
741 | for (count = 0; (serial_inp(up, UART_LSR) & UART_LSR_DR) && | 741 | for (count = 0; (serial_inp(up, UART_LSR) & UART_LSR_DR) && |
742 | (count < 256); count++) | 742 | (count < 256); count++) |
743 | serial_inp(up, UART_RX); | 743 | serial_inp(up, UART_RX); |
744 | serial_outp(up, UART_FCR, old_fcr); | 744 | serial_outp(up, UART_FCR, old_fcr); |
745 | serial_outp(up, UART_MCR, old_mcr); | 745 | serial_outp(up, UART_MCR, old_mcr); |
746 | serial_outp(up, UART_LCR, UART_LCR_DLAB); | 746 | serial_outp(up, UART_LCR, UART_LCR_DLAB); |
747 | serial_dl_write(up, old_dl); | 747 | serial_dl_write(up, old_dl); |
748 | serial_outp(up, UART_LCR, old_lcr); | 748 | serial_outp(up, UART_LCR, old_lcr); |
749 | 749 | ||
750 | return count; | 750 | return count; |
751 | } | 751 | } |
752 | 752 | ||
753 | /* | 753 | /* |
754 | * Read UART ID using the divisor method - set DLL and DLM to zero | 754 | * Read UART ID using the divisor method - set DLL and DLM to zero |
755 | * and the revision will be in DLL and device type in DLM. We | 755 | * and the revision will be in DLL and device type in DLM. We |
756 | * preserve the device state across this. | 756 | * preserve the device state across this. |
757 | */ | 757 | */ |
758 | static unsigned int autoconfig_read_divisor_id(struct uart_8250_port *p) | 758 | static unsigned int autoconfig_read_divisor_id(struct uart_8250_port *p) |
759 | { | 759 | { |
760 | unsigned char old_dll, old_dlm, old_lcr; | 760 | unsigned char old_dll, old_dlm, old_lcr; |
761 | unsigned int id; | 761 | unsigned int id; |
762 | 762 | ||
763 | old_lcr = serial_inp(p, UART_LCR); | 763 | old_lcr = serial_inp(p, UART_LCR); |
764 | serial_outp(p, UART_LCR, UART_LCR_DLAB); | 764 | serial_outp(p, UART_LCR, UART_LCR_DLAB); |
765 | 765 | ||
766 | old_dll = serial_inp(p, UART_DLL); | 766 | old_dll = serial_inp(p, UART_DLL); |
767 | old_dlm = serial_inp(p, UART_DLM); | 767 | old_dlm = serial_inp(p, UART_DLM); |
768 | 768 | ||
769 | serial_outp(p, UART_DLL, 0); | 769 | serial_outp(p, UART_DLL, 0); |
770 | serial_outp(p, UART_DLM, 0); | 770 | serial_outp(p, UART_DLM, 0); |
771 | 771 | ||
772 | id = serial_inp(p, UART_DLL) | serial_inp(p, UART_DLM) << 8; | 772 | id = serial_inp(p, UART_DLL) | serial_inp(p, UART_DLM) << 8; |
773 | 773 | ||
774 | serial_outp(p, UART_DLL, old_dll); | 774 | serial_outp(p, UART_DLL, old_dll); |
775 | serial_outp(p, UART_DLM, old_dlm); | 775 | serial_outp(p, UART_DLM, old_dlm); |
776 | serial_outp(p, UART_LCR, old_lcr); | 776 | serial_outp(p, UART_LCR, old_lcr); |
777 | 777 | ||
778 | return id; | 778 | return id; |
779 | } | 779 | } |
780 | 780 | ||
781 | /* | 781 | /* |
782 | * This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's. | 782 | * This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's. |
783 | * When this function is called we know it is at least a StarTech | 783 | * When this function is called we know it is at least a StarTech |
784 | * 16650 V2, but it might be one of several StarTech UARTs, or one of | 784 | * 16650 V2, but it might be one of several StarTech UARTs, or one of |
785 | * its clones. (We treat the broken original StarTech 16650 V1 as a | 785 | * its clones. (We treat the broken original StarTech 16650 V1 as a |
786 | * 16550, and why not? Startech doesn't seem to even acknowledge its | 786 | * 16550, and why not? Startech doesn't seem to even acknowledge its |
787 | * existence.) | 787 | * existence.) |
788 | * | 788 | * |
789 | * What evil have men's minds wrought... | 789 | * What evil have men's minds wrought... |
790 | */ | 790 | */ |
791 | static void autoconfig_has_efr(struct uart_8250_port *up) | 791 | static void autoconfig_has_efr(struct uart_8250_port *up) |
792 | { | 792 | { |
793 | unsigned int id1, id2, id3, rev; | 793 | unsigned int id1, id2, id3, rev; |
794 | 794 | ||
795 | /* | 795 | /* |
796 | * Everything with an EFR has SLEEP | 796 | * Everything with an EFR has SLEEP |
797 | */ | 797 | */ |
798 | up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP; | 798 | up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP; |
799 | 799 | ||
800 | /* | 800 | /* |
801 | * First we check to see if it's an Oxford Semiconductor UART. | 801 | * First we check to see if it's an Oxford Semiconductor UART. |
802 | * | 802 | * |
803 | * If we have to do this here because some non-National | 803 | * If we have to do this here because some non-National |
804 | * Semiconductor clone chips lock up if you try writing to the | 804 | * Semiconductor clone chips lock up if you try writing to the |
805 | * LSR register (which serial_icr_read does) | 805 | * LSR register (which serial_icr_read does) |
806 | */ | 806 | */ |
807 | 807 | ||
808 | /* | 808 | /* |
809 | * Check for Oxford Semiconductor 16C950. | 809 | * Check for Oxford Semiconductor 16C950. |
810 | * | 810 | * |
811 | * EFR [4] must be set else this test fails. | 811 | * EFR [4] must be set else this test fails. |
812 | * | 812 | * |
813 | * This shouldn't be necessary, but Mike Hudson (Exoray@isys.ca) | 813 | * This shouldn't be necessary, but Mike Hudson (Exoray@isys.ca) |
814 | * claims that it's needed for 952 dual UART's (which are not | 814 | * claims that it's needed for 952 dual UART's (which are not |
815 | * recommended for new designs). | 815 | * recommended for new designs). |
816 | */ | 816 | */ |
817 | up->acr = 0; | 817 | up->acr = 0; |
818 | serial_out(up, UART_LCR, 0xBF); | 818 | serial_out(up, UART_LCR, 0xBF); |
819 | serial_out(up, UART_EFR, UART_EFR_ECB); | 819 | serial_out(up, UART_EFR, UART_EFR_ECB); |
820 | serial_out(up, UART_LCR, 0x00); | 820 | serial_out(up, UART_LCR, 0x00); |
821 | id1 = serial_icr_read(up, UART_ID1); | 821 | id1 = serial_icr_read(up, UART_ID1); |
822 | id2 = serial_icr_read(up, UART_ID2); | 822 | id2 = serial_icr_read(up, UART_ID2); |
823 | id3 = serial_icr_read(up, UART_ID3); | 823 | id3 = serial_icr_read(up, UART_ID3); |
824 | rev = serial_icr_read(up, UART_REV); | 824 | rev = serial_icr_read(up, UART_REV); |
825 | 825 | ||
826 | DEBUG_AUTOCONF("950id=%02x:%02x:%02x:%02x ", id1, id2, id3, rev); | 826 | DEBUG_AUTOCONF("950id=%02x:%02x:%02x:%02x ", id1, id2, id3, rev); |
827 | 827 | ||
828 | if (id1 == 0x16 && id2 == 0xC9 && | 828 | if (id1 == 0x16 && id2 == 0xC9 && |
829 | (id3 == 0x50 || id3 == 0x52 || id3 == 0x54)) { | 829 | (id3 == 0x50 || id3 == 0x52 || id3 == 0x54)) { |
830 | up->port.type = PORT_16C950; | 830 | up->port.type = PORT_16C950; |
831 | 831 | ||
832 | /* | 832 | /* |
833 | * Enable work around for the Oxford Semiconductor 952 rev B | 833 | * Enable work around for the Oxford Semiconductor 952 rev B |
834 | * chip which causes it to seriously miscalculate baud rates | 834 | * chip which causes it to seriously miscalculate baud rates |
835 | * when DLL is 0. | 835 | * when DLL is 0. |
836 | */ | 836 | */ |
837 | if (id3 == 0x52 && rev == 0x01) | 837 | if (id3 == 0x52 && rev == 0x01) |
838 | up->bugs |= UART_BUG_QUOT; | 838 | up->bugs |= UART_BUG_QUOT; |
839 | return; | 839 | return; |
840 | } | 840 | } |
841 | 841 | ||
842 | /* | 842 | /* |
843 | * We check for a XR16C850 by setting DLL and DLM to 0, and then | 843 | * We check for a XR16C850 by setting DLL and DLM to 0, and then |
844 | * reading back DLL and DLM. The chip type depends on the DLM | 844 | * reading back DLL and DLM. The chip type depends on the DLM |
845 | * value read back: | 845 | * value read back: |
846 | * 0x10 - XR16C850 and the DLL contains the chip revision. | 846 | * 0x10 - XR16C850 and the DLL contains the chip revision. |
847 | * 0x12 - XR16C2850. | 847 | * 0x12 - XR16C2850. |
848 | * 0x14 - XR16C854. | 848 | * 0x14 - XR16C854. |
849 | */ | 849 | */ |
850 | id1 = autoconfig_read_divisor_id(up); | 850 | id1 = autoconfig_read_divisor_id(up); |
851 | DEBUG_AUTOCONF("850id=%04x ", id1); | 851 | DEBUG_AUTOCONF("850id=%04x ", id1); |
852 | 852 | ||
853 | id2 = id1 >> 8; | 853 | id2 = id1 >> 8; |
854 | if (id2 == 0x10 || id2 == 0x12 || id2 == 0x14) { | 854 | if (id2 == 0x10 || id2 == 0x12 || id2 == 0x14) { |
855 | up->port.type = PORT_16850; | 855 | up->port.type = PORT_16850; |
856 | return; | 856 | return; |
857 | } | 857 | } |
858 | 858 | ||
859 | /* | 859 | /* |
860 | * It wasn't an XR16C850. | 860 | * It wasn't an XR16C850. |
861 | * | 861 | * |
862 | * We distinguish between the '654 and the '650 by counting | 862 | * We distinguish between the '654 and the '650 by counting |
863 | * how many bytes are in the FIFO. I'm using this for now, | 863 | * how many bytes are in the FIFO. I'm using this for now, |
864 | * since that's the technique that was sent to me in the | 864 | * since that's the technique that was sent to me in the |
865 | * serial driver update, but I'm not convinced this works. | 865 | * serial driver update, but I'm not convinced this works. |
866 | * I've had problems doing this in the past. -TYT | 866 | * I've had problems doing this in the past. -TYT |
867 | */ | 867 | */ |
868 | if (size_fifo(up) == 64) | 868 | if (size_fifo(up) == 64) |
869 | up->port.type = PORT_16654; | 869 | up->port.type = PORT_16654; |
870 | else | 870 | else |
871 | up->port.type = PORT_16650V2; | 871 | up->port.type = PORT_16650V2; |
872 | } | 872 | } |
873 | 873 | ||
874 | /* | 874 | /* |
875 | * We detected a chip without a FIFO. Only two fall into | 875 | * We detected a chip without a FIFO. Only two fall into |
876 | * this category - the original 8250 and the 16450. The | 876 | * this category - the original 8250 and the 16450. The |
877 | * 16450 has a scratch register (accessible with LCR=0) | 877 | * 16450 has a scratch register (accessible with LCR=0) |
878 | */ | 878 | */ |
879 | static void autoconfig_8250(struct uart_8250_port *up) | 879 | static void autoconfig_8250(struct uart_8250_port *up) |
880 | { | 880 | { |
881 | unsigned char scratch, status1, status2; | 881 | unsigned char scratch, status1, status2; |
882 | 882 | ||
883 | up->port.type = PORT_8250; | 883 | up->port.type = PORT_8250; |
884 | 884 | ||
885 | scratch = serial_in(up, UART_SCR); | 885 | scratch = serial_in(up, UART_SCR); |
886 | serial_outp(up, UART_SCR, 0xa5); | 886 | serial_outp(up, UART_SCR, 0xa5); |
887 | status1 = serial_in(up, UART_SCR); | 887 | status1 = serial_in(up, UART_SCR); |
888 | serial_outp(up, UART_SCR, 0x5a); | 888 | serial_outp(up, UART_SCR, 0x5a); |
889 | status2 = serial_in(up, UART_SCR); | 889 | status2 = serial_in(up, UART_SCR); |
890 | serial_outp(up, UART_SCR, scratch); | 890 | serial_outp(up, UART_SCR, scratch); |
891 | 891 | ||
892 | if (status1 == 0xa5 && status2 == 0x5a) | 892 | if (status1 == 0xa5 && status2 == 0x5a) |
893 | up->port.type = PORT_16450; | 893 | up->port.type = PORT_16450; |
894 | } | 894 | } |
895 | 895 | ||
896 | static int broken_efr(struct uart_8250_port *up) | 896 | static int broken_efr(struct uart_8250_port *up) |
897 | { | 897 | { |
898 | /* | 898 | /* |
899 | * Exar ST16C2550 "A2" devices incorrectly detect as | 899 | * Exar ST16C2550 "A2" devices incorrectly detect as |
900 | * having an EFR, and report an ID of 0x0201. See | 900 | * having an EFR, and report an ID of 0x0201. See |
901 | * http://www.exar.com/info.php?pdf=dan180_oct2004.pdf | 901 | * http://www.exar.com/info.php?pdf=dan180_oct2004.pdf |
902 | */ | 902 | */ |
903 | if (autoconfig_read_divisor_id(up) == 0x0201 && size_fifo(up) == 16) | 903 | if (autoconfig_read_divisor_id(up) == 0x0201 && size_fifo(up) == 16) |
904 | return 1; | 904 | return 1; |
905 | 905 | ||
906 | return 0; | 906 | return 0; |
907 | } | 907 | } |
908 | 908 | ||
909 | /* | 909 | /* |
910 | * We know that the chip has FIFOs. Does it have an EFR? The | 910 | * We know that the chip has FIFOs. Does it have an EFR? The |
911 | * EFR is located in the same register position as the IIR and | 911 | * EFR is located in the same register position as the IIR and |
912 | * we know the top two bits of the IIR are currently set. The | 912 | * we know the top two bits of the IIR are currently set. The |
913 | * EFR should contain zero. Try to read the EFR. | 913 | * EFR should contain zero. Try to read the EFR. |
914 | */ | 914 | */ |
915 | static void autoconfig_16550a(struct uart_8250_port *up) | 915 | static void autoconfig_16550a(struct uart_8250_port *up) |
916 | { | 916 | { |
917 | unsigned char status1, status2; | 917 | unsigned char status1, status2; |
918 | unsigned int iersave; | 918 | unsigned int iersave; |
919 | 919 | ||
920 | up->port.type = PORT_16550A; | 920 | up->port.type = PORT_16550A; |
921 | up->capabilities |= UART_CAP_FIFO; | 921 | up->capabilities |= UART_CAP_FIFO; |
922 | 922 | ||
923 | /* | 923 | /* |
924 | * Check for presence of the EFR when DLAB is set. | 924 | * Check for presence of the EFR when DLAB is set. |
925 | * Only ST16C650V1 UARTs pass this test. | 925 | * Only ST16C650V1 UARTs pass this test. |
926 | */ | 926 | */ |
927 | serial_outp(up, UART_LCR, UART_LCR_DLAB); | 927 | serial_outp(up, UART_LCR, UART_LCR_DLAB); |
928 | if (serial_in(up, UART_EFR) == 0) { | 928 | if (serial_in(up, UART_EFR) == 0) { |
929 | serial_outp(up, UART_EFR, 0xA8); | 929 | serial_outp(up, UART_EFR, 0xA8); |
930 | if (serial_in(up, UART_EFR) != 0) { | 930 | if (serial_in(up, UART_EFR) != 0) { |
931 | DEBUG_AUTOCONF("EFRv1 "); | 931 | DEBUG_AUTOCONF("EFRv1 "); |
932 | up->port.type = PORT_16650; | 932 | up->port.type = PORT_16650; |
933 | up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP; | 933 | up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP; |
934 | } else { | 934 | } else { |
935 | DEBUG_AUTOCONF("Motorola 8xxx DUART "); | 935 | DEBUG_AUTOCONF("Motorola 8xxx DUART "); |
936 | } | 936 | } |
937 | serial_outp(up, UART_EFR, 0); | 937 | serial_outp(up, UART_EFR, 0); |
938 | return; | 938 | return; |
939 | } | 939 | } |
940 | 940 | ||
941 | /* | 941 | /* |
942 | * Maybe it requires 0xbf to be written to the LCR. | 942 | * Maybe it requires 0xbf to be written to the LCR. |
943 | * (other ST16C650V2 UARTs, TI16C752A, etc) | 943 | * (other ST16C650V2 UARTs, TI16C752A, etc) |
944 | */ | 944 | */ |
945 | serial_outp(up, UART_LCR, 0xBF); | 945 | serial_outp(up, UART_LCR, 0xBF); |
946 | if (serial_in(up, UART_EFR) == 0 && !broken_efr(up)) { | 946 | if (serial_in(up, UART_EFR) == 0 && !broken_efr(up)) { |
947 | DEBUG_AUTOCONF("EFRv2 "); | 947 | DEBUG_AUTOCONF("EFRv2 "); |
948 | autoconfig_has_efr(up); | 948 | autoconfig_has_efr(up); |
949 | return; | 949 | return; |
950 | } | 950 | } |
951 | 951 | ||
952 | /* | 952 | /* |
953 | * Check for a National Semiconductor SuperIO chip. | 953 | * Check for a National Semiconductor SuperIO chip. |
954 | * Attempt to switch to bank 2, read the value of the LOOP bit | 954 | * Attempt to switch to bank 2, read the value of the LOOP bit |
955 | * from EXCR1. Switch back to bank 0, change it in MCR. Then | 955 | * from EXCR1. Switch back to bank 0, change it in MCR. Then |
956 | * switch back to bank 2, read it from EXCR1 again and check | 956 | * switch back to bank 2, read it from EXCR1 again and check |
957 | * it's changed. If so, set baud_base in EXCR2 to 921600. -- dwmw2 | 957 | * it's changed. If so, set baud_base in EXCR2 to 921600. -- dwmw2 |
958 | */ | 958 | */ |
959 | serial_outp(up, UART_LCR, 0); | 959 | serial_outp(up, UART_LCR, 0); |
960 | status1 = serial_in(up, UART_MCR); | 960 | status1 = serial_in(up, UART_MCR); |
961 | serial_outp(up, UART_LCR, 0xE0); | 961 | serial_outp(up, UART_LCR, 0xE0); |
962 | status2 = serial_in(up, 0x02); /* EXCR1 */ | 962 | status2 = serial_in(up, 0x02); /* EXCR1 */ |
963 | 963 | ||
964 | if (!((status2 ^ status1) & UART_MCR_LOOP)) { | 964 | if (!((status2 ^ status1) & UART_MCR_LOOP)) { |
965 | serial_outp(up, UART_LCR, 0); | 965 | serial_outp(up, UART_LCR, 0); |
966 | serial_outp(up, UART_MCR, status1 ^ UART_MCR_LOOP); | 966 | serial_outp(up, UART_MCR, status1 ^ UART_MCR_LOOP); |
967 | serial_outp(up, UART_LCR, 0xE0); | 967 | serial_outp(up, UART_LCR, 0xE0); |
968 | status2 = serial_in(up, 0x02); /* EXCR1 */ | 968 | status2 = serial_in(up, 0x02); /* EXCR1 */ |
969 | serial_outp(up, UART_LCR, 0); | 969 | serial_outp(up, UART_LCR, 0); |
970 | serial_outp(up, UART_MCR, status1); | 970 | serial_outp(up, UART_MCR, status1); |
971 | 971 | ||
972 | if ((status2 ^ status1) & UART_MCR_LOOP) { | 972 | if ((status2 ^ status1) & UART_MCR_LOOP) { |
973 | unsigned short quot; | 973 | unsigned short quot; |
974 | 974 | ||
975 | serial_outp(up, UART_LCR, 0xE0); | 975 | serial_outp(up, UART_LCR, 0xE0); |
976 | 976 | ||
977 | quot = serial_dl_read(up); | 977 | quot = serial_dl_read(up); |
978 | quot <<= 3; | 978 | quot <<= 3; |
979 | 979 | ||
980 | status1 = serial_in(up, 0x04); /* EXCR2 */ | 980 | status1 = serial_in(up, 0x04); /* EXCR2 */ |
981 | status1 &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */ | 981 | status1 &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */ |
982 | status1 |= 0x10; /* 1.625 divisor for baud_base --> 921600 */ | 982 | status1 |= 0x10; /* 1.625 divisor for baud_base --> 921600 */ |
983 | serial_outp(up, 0x04, status1); | 983 | serial_outp(up, 0x04, status1); |
984 | 984 | ||
985 | serial_dl_write(up, quot); | 985 | serial_dl_write(up, quot); |
986 | 986 | ||
987 | serial_outp(up, UART_LCR, 0); | 987 | serial_outp(up, UART_LCR, 0); |
988 | 988 | ||
989 | up->port.uartclk = 921600*16; | 989 | up->port.uartclk = 921600*16; |
990 | up->port.type = PORT_NS16550A; | 990 | up->port.type = PORT_NS16550A; |
991 | up->capabilities |= UART_NATSEMI; | 991 | up->capabilities |= UART_NATSEMI; |
992 | return; | 992 | return; |
993 | } | 993 | } |
994 | } | 994 | } |
995 | 995 | ||
996 | /* | 996 | /* |
997 | * No EFR. Try to detect a TI16750, which only sets bit 5 of | 997 | * No EFR. Try to detect a TI16750, which only sets bit 5 of |
998 | * the IIR when 64 byte FIFO mode is enabled when DLAB is set. | 998 | * the IIR when 64 byte FIFO mode is enabled when DLAB is set. |
999 | * Try setting it with and without DLAB set. Cheap clones | 999 | * Try setting it with and without DLAB set. Cheap clones |
1000 | * set bit 5 without DLAB set. | 1000 | * set bit 5 without DLAB set. |
1001 | */ | 1001 | */ |
1002 | serial_outp(up, UART_LCR, 0); | 1002 | serial_outp(up, UART_LCR, 0); |
1003 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); | 1003 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); |
1004 | status1 = serial_in(up, UART_IIR) >> 5; | 1004 | status1 = serial_in(up, UART_IIR) >> 5; |
1005 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); | 1005 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); |
1006 | serial_outp(up, UART_LCR, UART_LCR_DLAB); | 1006 | serial_outp(up, UART_LCR, UART_LCR_DLAB); |
1007 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); | 1007 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); |
1008 | status2 = serial_in(up, UART_IIR) >> 5; | 1008 | status2 = serial_in(up, UART_IIR) >> 5; |
1009 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); | 1009 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); |
1010 | serial_outp(up, UART_LCR, 0); | 1010 | serial_outp(up, UART_LCR, 0); |
1011 | 1011 | ||
1012 | DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1, status2); | 1012 | DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1, status2); |
1013 | 1013 | ||
1014 | if (status1 == 6 && status2 == 7) { | 1014 | if (status1 == 6 && status2 == 7) { |
1015 | up->port.type = PORT_16750; | 1015 | up->port.type = PORT_16750; |
1016 | up->capabilities |= UART_CAP_AFE | UART_CAP_SLEEP; | 1016 | up->capabilities |= UART_CAP_AFE | UART_CAP_SLEEP; |
1017 | return; | 1017 | return; |
1018 | } | 1018 | } |
1019 | 1019 | ||
1020 | /* | 1020 | /* |
1021 | * Try writing and reading the UART_IER_UUE bit (b6). | 1021 | * Try writing and reading the UART_IER_UUE bit (b6). |
1022 | * If it works, this is probably one of the Xscale platform's | 1022 | * If it works, this is probably one of the Xscale platform's |
1023 | * internal UARTs. | 1023 | * internal UARTs. |
1024 | * We're going to explicitly set the UUE bit to 0 before | 1024 | * We're going to explicitly set the UUE bit to 0 before |
1025 | * trying to write and read a 1 just to make sure it's not | 1025 | * trying to write and read a 1 just to make sure it's not |
1026 | * already a 1 and maybe locked there before we even start start. | 1026 | * already a 1 and maybe locked there before we even start start. |
1027 | */ | 1027 | */ |
1028 | iersave = serial_in(up, UART_IER); | 1028 | iersave = serial_in(up, UART_IER); |
1029 | serial_outp(up, UART_IER, iersave & ~UART_IER_UUE); | 1029 | serial_outp(up, UART_IER, iersave & ~UART_IER_UUE); |
1030 | if (!(serial_in(up, UART_IER) & UART_IER_UUE)) { | 1030 | if (!(serial_in(up, UART_IER) & UART_IER_UUE)) { |
1031 | /* | 1031 | /* |
1032 | * OK it's in a known zero state, try writing and reading | 1032 | * OK it's in a known zero state, try writing and reading |
1033 | * without disturbing the current state of the other bits. | 1033 | * without disturbing the current state of the other bits. |
1034 | */ | 1034 | */ |
1035 | serial_outp(up, UART_IER, iersave | UART_IER_UUE); | 1035 | serial_outp(up, UART_IER, iersave | UART_IER_UUE); |
1036 | if (serial_in(up, UART_IER) & UART_IER_UUE) { | 1036 | if (serial_in(up, UART_IER) & UART_IER_UUE) { |
1037 | /* | 1037 | /* |
1038 | * It's an Xscale. | 1038 | * It's an Xscale. |
1039 | * We'll leave the UART_IER_UUE bit set to 1 (enabled). | 1039 | * We'll leave the UART_IER_UUE bit set to 1 (enabled). |
1040 | */ | 1040 | */ |
1041 | DEBUG_AUTOCONF("Xscale "); | 1041 | DEBUG_AUTOCONF("Xscale "); |
1042 | up->port.type = PORT_XSCALE; | 1042 | up->port.type = PORT_XSCALE; |
1043 | up->capabilities |= UART_CAP_UUE; | 1043 | up->capabilities |= UART_CAP_UUE; |
1044 | return; | 1044 | return; |
1045 | } | 1045 | } |
1046 | } else { | 1046 | } else { |
1047 | /* | 1047 | /* |
1048 | * If we got here we couldn't force the IER_UUE bit to 0. | 1048 | * If we got here we couldn't force the IER_UUE bit to 0. |
1049 | * Log it and continue. | 1049 | * Log it and continue. |
1050 | */ | 1050 | */ |
1051 | DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 "); | 1051 | DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 "); |
1052 | } | 1052 | } |
1053 | serial_outp(up, UART_IER, iersave); | 1053 | serial_outp(up, UART_IER, iersave); |
1054 | } | 1054 | } |
1055 | 1055 | ||
1056 | /* | 1056 | /* |
1057 | * This routine is called by rs_init() to initialize a specific serial | 1057 | * This routine is called by rs_init() to initialize a specific serial |
1058 | * port. It determines what type of UART chip this serial port is | 1058 | * port. It determines what type of UART chip this serial port is |
1059 | * using: 8250, 16450, 16550, 16550A. The important question is | 1059 | * using: 8250, 16450, 16550, 16550A. The important question is |
1060 | * whether or not this UART is a 16550A or not, since this will | 1060 | * whether or not this UART is a 16550A or not, since this will |
1061 | * determine whether or not we can use its FIFO features or not. | 1061 | * determine whether or not we can use its FIFO features or not. |
1062 | */ | 1062 | */ |
1063 | static void autoconfig(struct uart_8250_port *up, unsigned int probeflags) | 1063 | static void autoconfig(struct uart_8250_port *up, unsigned int probeflags) |
1064 | { | 1064 | { |
1065 | unsigned char status1, scratch, scratch2, scratch3; | 1065 | unsigned char status1, scratch, scratch2, scratch3; |
1066 | unsigned char save_lcr, save_mcr; | 1066 | unsigned char save_lcr, save_mcr; |
1067 | unsigned long flags; | 1067 | unsigned long flags; |
1068 | 1068 | ||
1069 | if (!up->port.iobase && !up->port.mapbase && !up->port.membase) | 1069 | if (!up->port.iobase && !up->port.mapbase && !up->port.membase) |
1070 | return; | 1070 | return; |
1071 | 1071 | ||
1072 | DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04x, 0x%p): ", | 1072 | DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04x, 0x%p): ", |
1073 | serial_index(&up->port), up->port.iobase, up->port.membase); | 1073 | serial_index(&up->port), up->port.iobase, up->port.membase); |
1074 | 1074 | ||
1075 | /* | 1075 | /* |
1076 | * We really do need global IRQs disabled here - we're going to | 1076 | * We really do need global IRQs disabled here - we're going to |
1077 | * be frobbing the chips IRQ enable register to see if it exists. | 1077 | * be frobbing the chips IRQ enable register to see if it exists. |
1078 | */ | 1078 | */ |
1079 | spin_lock_irqsave(&up->port.lock, flags); | 1079 | spin_lock_irqsave(&up->port.lock, flags); |
1080 | 1080 | ||
1081 | up->capabilities = 0; | 1081 | up->capabilities = 0; |
1082 | up->bugs = 0; | 1082 | up->bugs = 0; |
1083 | 1083 | ||
1084 | if (!(up->port.flags & UPF_BUGGY_UART)) { | 1084 | if (!(up->port.flags & UPF_BUGGY_UART)) { |
1085 | /* | 1085 | /* |
1086 | * Do a simple existence test first; if we fail this, | 1086 | * Do a simple existence test first; if we fail this, |
1087 | * there's no point trying anything else. | 1087 | * there's no point trying anything else. |
1088 | * | 1088 | * |
1089 | * 0x80 is used as a nonsense port to prevent against | 1089 | * 0x80 is used as a nonsense port to prevent against |
1090 | * false positives due to ISA bus float. The | 1090 | * false positives due to ISA bus float. The |
1091 | * assumption is that 0x80 is a non-existent port; | 1091 | * assumption is that 0x80 is a non-existent port; |
1092 | * which should be safe since include/asm/io.h also | 1092 | * which should be safe since include/asm/io.h also |
1093 | * makes this assumption. | 1093 | * makes this assumption. |
1094 | * | 1094 | * |
1095 | * Note: this is safe as long as MCR bit 4 is clear | 1095 | * Note: this is safe as long as MCR bit 4 is clear |
1096 | * and the device is in "PC" mode. | 1096 | * and the device is in "PC" mode. |
1097 | */ | 1097 | */ |
1098 | scratch = serial_inp(up, UART_IER); | 1098 | scratch = serial_inp(up, UART_IER); |
1099 | serial_outp(up, UART_IER, 0); | 1099 | serial_outp(up, UART_IER, 0); |
1100 | #ifdef __i386__ | 1100 | #ifdef __i386__ |
1101 | outb(0xff, 0x080); | 1101 | outb(0xff, 0x080); |
1102 | #endif | 1102 | #endif |
1103 | /* | 1103 | /* |
1104 | * Mask out IER[7:4] bits for test as some UARTs (e.g. TL | 1104 | * Mask out IER[7:4] bits for test as some UARTs (e.g. TL |
1105 | * 16C754B) allow only to modify them if an EFR bit is set. | 1105 | * 16C754B) allow only to modify them if an EFR bit is set. |
1106 | */ | 1106 | */ |
1107 | scratch2 = serial_inp(up, UART_IER) & 0x0f; | 1107 | scratch2 = serial_inp(up, UART_IER) & 0x0f; |
1108 | serial_outp(up, UART_IER, 0x0F); | 1108 | serial_outp(up, UART_IER, 0x0F); |
1109 | #ifdef __i386__ | 1109 | #ifdef __i386__ |
1110 | outb(0, 0x080); | 1110 | outb(0, 0x080); |
1111 | #endif | 1111 | #endif |
1112 | scratch3 = serial_inp(up, UART_IER) & 0x0f; | 1112 | scratch3 = serial_inp(up, UART_IER) & 0x0f; |
1113 | serial_outp(up, UART_IER, scratch); | 1113 | serial_outp(up, UART_IER, scratch); |
1114 | if (scratch2 != 0 || scratch3 != 0x0F) { | 1114 | if (scratch2 != 0 || scratch3 != 0x0F) { |
1115 | /* | 1115 | /* |
1116 | * We failed; there's nothing here | 1116 | * We failed; there's nothing here |
1117 | */ | 1117 | */ |
1118 | DEBUG_AUTOCONF("IER test failed (%02x, %02x) ", | 1118 | DEBUG_AUTOCONF("IER test failed (%02x, %02x) ", |
1119 | scratch2, scratch3); | 1119 | scratch2, scratch3); |
1120 | goto out; | 1120 | goto out; |
1121 | } | 1121 | } |
1122 | } | 1122 | } |
1123 | 1123 | ||
1124 | save_mcr = serial_in(up, UART_MCR); | 1124 | save_mcr = serial_in(up, UART_MCR); |
1125 | save_lcr = serial_in(up, UART_LCR); | 1125 | save_lcr = serial_in(up, UART_LCR); |
1126 | 1126 | ||
1127 | /* | 1127 | /* |
1128 | * Check to see if a UART is really there. Certain broken | 1128 | * Check to see if a UART is really there. Certain broken |
1129 | * internal modems based on the Rockwell chipset fail this | 1129 | * internal modems based on the Rockwell chipset fail this |
1130 | * test, because they apparently don't implement the loopback | 1130 | * test, because they apparently don't implement the loopback |
1131 | * test mode. So this test is skipped on the COM 1 through | 1131 | * test mode. So this test is skipped on the COM 1 through |
1132 | * COM 4 ports. This *should* be safe, since no board | 1132 | * COM 4 ports. This *should* be safe, since no board |
1133 | * manufacturer would be stupid enough to design a board | 1133 | * manufacturer would be stupid enough to design a board |
1134 | * that conflicts with COM 1-4 --- we hope! | 1134 | * that conflicts with COM 1-4 --- we hope! |
1135 | */ | 1135 | */ |
1136 | if (!(up->port.flags & UPF_SKIP_TEST)) { | 1136 | if (!(up->port.flags & UPF_SKIP_TEST)) { |
1137 | serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A); | 1137 | serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A); |
1138 | status1 = serial_inp(up, UART_MSR) & 0xF0; | 1138 | status1 = serial_inp(up, UART_MSR) & 0xF0; |
1139 | serial_outp(up, UART_MCR, save_mcr); | 1139 | serial_outp(up, UART_MCR, save_mcr); |
1140 | if (status1 != 0x90) { | 1140 | if (status1 != 0x90) { |
1141 | DEBUG_AUTOCONF("LOOP test failed (%02x) ", | 1141 | DEBUG_AUTOCONF("LOOP test failed (%02x) ", |
1142 | status1); | 1142 | status1); |
1143 | goto out; | 1143 | goto out; |
1144 | } | 1144 | } |
1145 | } | 1145 | } |
1146 | 1146 | ||
1147 | /* | 1147 | /* |
1148 | * We're pretty sure there's a port here. Lets find out what | 1148 | * We're pretty sure there's a port here. Lets find out what |
1149 | * type of port it is. The IIR top two bits allows us to find | 1149 | * type of port it is. The IIR top two bits allows us to find |
1150 | * out if it's 8250 or 16450, 16550, 16550A or later. This | 1150 | * out if it's 8250 or 16450, 16550, 16550A or later. This |
1151 | * determines what we test for next. | 1151 | * determines what we test for next. |
1152 | * | 1152 | * |
1153 | * We also initialise the EFR (if any) to zero for later. The | 1153 | * We also initialise the EFR (if any) to zero for later. The |
1154 | * EFR occupies the same register location as the FCR and IIR. | 1154 | * EFR occupies the same register location as the FCR and IIR. |
1155 | */ | 1155 | */ |
1156 | serial_outp(up, UART_LCR, 0xBF); | 1156 | serial_outp(up, UART_LCR, 0xBF); |
1157 | serial_outp(up, UART_EFR, 0); | 1157 | serial_outp(up, UART_EFR, 0); |
1158 | serial_outp(up, UART_LCR, 0); | 1158 | serial_outp(up, UART_LCR, 0); |
1159 | 1159 | ||
1160 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); | 1160 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); |
1161 | scratch = serial_in(up, UART_IIR) >> 6; | 1161 | scratch = serial_in(up, UART_IIR) >> 6; |
1162 | 1162 | ||
1163 | DEBUG_AUTOCONF("iir=%d ", scratch); | 1163 | DEBUG_AUTOCONF("iir=%d ", scratch); |
1164 | 1164 | ||
1165 | switch (scratch) { | 1165 | switch (scratch) { |
1166 | case 0: | 1166 | case 0: |
1167 | autoconfig_8250(up); | 1167 | autoconfig_8250(up); |
1168 | break; | 1168 | break; |
1169 | case 1: | 1169 | case 1: |
1170 | up->port.type = PORT_UNKNOWN; | 1170 | up->port.type = PORT_UNKNOWN; |
1171 | break; | 1171 | break; |
1172 | case 2: | 1172 | case 2: |
1173 | up->port.type = PORT_16550; | 1173 | up->port.type = PORT_16550; |
1174 | break; | 1174 | break; |
1175 | case 3: | 1175 | case 3: |
1176 | autoconfig_16550a(up); | 1176 | autoconfig_16550a(up); |
1177 | break; | 1177 | break; |
1178 | } | 1178 | } |
1179 | 1179 | ||
1180 | #ifdef CONFIG_SERIAL_8250_RSA | 1180 | #ifdef CONFIG_SERIAL_8250_RSA |
1181 | /* | 1181 | /* |
1182 | * Only probe for RSA ports if we got the region. | 1182 | * Only probe for RSA ports if we got the region. |
1183 | */ | 1183 | */ |
1184 | if (up->port.type == PORT_16550A && probeflags & PROBE_RSA) { | 1184 | if (up->port.type == PORT_16550A && probeflags & PROBE_RSA) { |
1185 | int i; | 1185 | int i; |
1186 | 1186 | ||
1187 | for (i = 0 ; i < probe_rsa_count; ++i) { | 1187 | for (i = 0 ; i < probe_rsa_count; ++i) { |
1188 | if (probe_rsa[i] == up->port.iobase && | 1188 | if (probe_rsa[i] == up->port.iobase && |
1189 | __enable_rsa(up)) { | 1189 | __enable_rsa(up)) { |
1190 | up->port.type = PORT_RSA; | 1190 | up->port.type = PORT_RSA; |
1191 | break; | 1191 | break; |
1192 | } | 1192 | } |
1193 | } | 1193 | } |
1194 | } | 1194 | } |
1195 | #endif | 1195 | #endif |
1196 | 1196 | ||
1197 | #ifdef CONFIG_SERIAL_8250_AU1X00 | 1197 | #ifdef CONFIG_SERIAL_8250_AU1X00 |
1198 | /* if access method is AU, it is a 16550 with a quirk */ | 1198 | /* if access method is AU, it is a 16550 with a quirk */ |
1199 | if (up->port.type == PORT_16550A && up->port.iotype == UPIO_AU) | 1199 | if (up->port.type == PORT_16550A && up->port.iotype == UPIO_AU) |
1200 | up->bugs |= UART_BUG_NOMSR; | 1200 | up->bugs |= UART_BUG_NOMSR; |
1201 | #endif | 1201 | #endif |
1202 | 1202 | ||
1203 | serial_outp(up, UART_LCR, save_lcr); | 1203 | serial_outp(up, UART_LCR, save_lcr); |
1204 | 1204 | ||
1205 | if (up->capabilities != uart_config[up->port.type].flags) { | 1205 | if (up->capabilities != uart_config[up->port.type].flags) { |
1206 | printk(KERN_WARNING | 1206 | printk(KERN_WARNING |
1207 | "ttyS%d: detected caps %08x should be %08x\n", | 1207 | "ttyS%d: detected caps %08x should be %08x\n", |
1208 | serial_index(&up->port), up->capabilities, | 1208 | serial_index(&up->port), up->capabilities, |
1209 | uart_config[up->port.type].flags); | 1209 | uart_config[up->port.type].flags); |
1210 | } | 1210 | } |
1211 | 1211 | ||
1212 | up->port.fifosize = uart_config[up->port.type].fifo_size; | 1212 | up->port.fifosize = uart_config[up->port.type].fifo_size; |
1213 | up->capabilities = uart_config[up->port.type].flags; | 1213 | up->capabilities = uart_config[up->port.type].flags; |
1214 | up->tx_loadsz = uart_config[up->port.type].tx_loadsz; | 1214 | up->tx_loadsz = uart_config[up->port.type].tx_loadsz; |
1215 | 1215 | ||
1216 | if (up->port.type == PORT_UNKNOWN) | 1216 | if (up->port.type == PORT_UNKNOWN) |
1217 | goto out; | 1217 | goto out; |
1218 | 1218 | ||
1219 | /* | 1219 | /* |
1220 | * Reset the UART. | 1220 | * Reset the UART. |
1221 | */ | 1221 | */ |
1222 | #ifdef CONFIG_SERIAL_8250_RSA | 1222 | #ifdef CONFIG_SERIAL_8250_RSA |
1223 | if (up->port.type == PORT_RSA) | 1223 | if (up->port.type == PORT_RSA) |
1224 | serial_outp(up, UART_RSA_FRR, 0); | 1224 | serial_outp(up, UART_RSA_FRR, 0); |
1225 | #endif | 1225 | #endif |
1226 | serial_outp(up, UART_MCR, save_mcr); | 1226 | serial_outp(up, UART_MCR, save_mcr); |
1227 | serial8250_clear_fifos(up); | 1227 | serial8250_clear_fifos(up); |
1228 | serial_in(up, UART_RX); | 1228 | serial_in(up, UART_RX); |
1229 | if (up->capabilities & UART_CAP_UUE) | 1229 | if (up->capabilities & UART_CAP_UUE) |
1230 | serial_outp(up, UART_IER, UART_IER_UUE); | 1230 | serial_outp(up, UART_IER, UART_IER_UUE); |
1231 | else | 1231 | else |
1232 | serial_outp(up, UART_IER, 0); | 1232 | serial_outp(up, UART_IER, 0); |
1233 | 1233 | ||
1234 | out: | 1234 | out: |
1235 | spin_unlock_irqrestore(&up->port.lock, flags); | 1235 | spin_unlock_irqrestore(&up->port.lock, flags); |
1236 | DEBUG_AUTOCONF("type=%s\n", uart_config[up->port.type].name); | 1236 | DEBUG_AUTOCONF("type=%s\n", uart_config[up->port.type].name); |
1237 | } | 1237 | } |
1238 | 1238 | ||
1239 | static void autoconfig_irq(struct uart_8250_port *up) | 1239 | static void autoconfig_irq(struct uart_8250_port *up) |
1240 | { | 1240 | { |
1241 | unsigned char save_mcr, save_ier; | 1241 | unsigned char save_mcr, save_ier; |
1242 | unsigned char save_ICP = 0; | 1242 | unsigned char save_ICP = 0; |
1243 | unsigned int ICP = 0; | 1243 | unsigned int ICP = 0; |
1244 | unsigned long irqs; | 1244 | unsigned long irqs; |
1245 | int irq; | 1245 | int irq; |
1246 | 1246 | ||
1247 | if (up->port.flags & UPF_FOURPORT) { | 1247 | if (up->port.flags & UPF_FOURPORT) { |
1248 | ICP = (up->port.iobase & 0xfe0) | 0x1f; | 1248 | ICP = (up->port.iobase & 0xfe0) | 0x1f; |
1249 | save_ICP = inb_p(ICP); | 1249 | save_ICP = inb_p(ICP); |
1250 | outb_p(0x80, ICP); | 1250 | outb_p(0x80, ICP); |
1251 | (void) inb_p(ICP); | 1251 | (void) inb_p(ICP); |
1252 | } | 1252 | } |
1253 | 1253 | ||
1254 | /* forget possible initially masked and pending IRQ */ | 1254 | /* forget possible initially masked and pending IRQ */ |
1255 | probe_irq_off(probe_irq_on()); | 1255 | probe_irq_off(probe_irq_on()); |
1256 | save_mcr = serial_inp(up, UART_MCR); | 1256 | save_mcr = serial_inp(up, UART_MCR); |
1257 | save_ier = serial_inp(up, UART_IER); | 1257 | save_ier = serial_inp(up, UART_IER); |
1258 | serial_outp(up, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2); | 1258 | serial_outp(up, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2); |
1259 | 1259 | ||
1260 | irqs = probe_irq_on(); | 1260 | irqs = probe_irq_on(); |
1261 | serial_outp(up, UART_MCR, 0); | 1261 | serial_outp(up, UART_MCR, 0); |
1262 | udelay(10); | 1262 | udelay(10); |
1263 | if (up->port.flags & UPF_FOURPORT) { | 1263 | if (up->port.flags & UPF_FOURPORT) { |
1264 | serial_outp(up, UART_MCR, | 1264 | serial_outp(up, UART_MCR, |
1265 | UART_MCR_DTR | UART_MCR_RTS); | 1265 | UART_MCR_DTR | UART_MCR_RTS); |
1266 | } else { | 1266 | } else { |
1267 | serial_outp(up, UART_MCR, | 1267 | serial_outp(up, UART_MCR, |
1268 | UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2); | 1268 | UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2); |
1269 | } | 1269 | } |
1270 | serial_outp(up, UART_IER, 0x0f); /* enable all intrs */ | 1270 | serial_outp(up, UART_IER, 0x0f); /* enable all intrs */ |
1271 | (void)serial_inp(up, UART_LSR); | 1271 | (void)serial_inp(up, UART_LSR); |
1272 | (void)serial_inp(up, UART_RX); | 1272 | (void)serial_inp(up, UART_RX); |
1273 | (void)serial_inp(up, UART_IIR); | 1273 | (void)serial_inp(up, UART_IIR); |
1274 | (void)serial_inp(up, UART_MSR); | 1274 | (void)serial_inp(up, UART_MSR); |
1275 | serial_outp(up, UART_TX, 0xFF); | 1275 | serial_outp(up, UART_TX, 0xFF); |
1276 | udelay(20); | 1276 | udelay(20); |
1277 | irq = probe_irq_off(irqs); | 1277 | irq = probe_irq_off(irqs); |
1278 | 1278 | ||
1279 | serial_outp(up, UART_MCR, save_mcr); | 1279 | serial_outp(up, UART_MCR, save_mcr); |
1280 | serial_outp(up, UART_IER, save_ier); | 1280 | serial_outp(up, UART_IER, save_ier); |
1281 | 1281 | ||
1282 | if (up->port.flags & UPF_FOURPORT) | 1282 | if (up->port.flags & UPF_FOURPORT) |
1283 | outb_p(save_ICP, ICP); | 1283 | outb_p(save_ICP, ICP); |
1284 | 1284 | ||
1285 | up->port.irq = (irq > 0) ? irq : 0; | 1285 | up->port.irq = (irq > 0) ? irq : 0; |
1286 | } | 1286 | } |
1287 | 1287 | ||
1288 | static inline void __stop_tx(struct uart_8250_port *p) | 1288 | static inline void __stop_tx(struct uart_8250_port *p) |
1289 | { | 1289 | { |
1290 | if (p->ier & UART_IER_THRI) { | 1290 | if (p->ier & UART_IER_THRI) { |
1291 | p->ier &= ~UART_IER_THRI; | 1291 | p->ier &= ~UART_IER_THRI; |
1292 | serial_out(p, UART_IER, p->ier); | 1292 | serial_out(p, UART_IER, p->ier); |
1293 | } | 1293 | } |
1294 | } | 1294 | } |
1295 | 1295 | ||
1296 | static void serial8250_stop_tx(struct uart_port *port) | 1296 | static void serial8250_stop_tx(struct uart_port *port) |
1297 | { | 1297 | { |
1298 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1298 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
1299 | 1299 | ||
1300 | __stop_tx(up); | 1300 | __stop_tx(up); |
1301 | 1301 | ||
1302 | /* | 1302 | /* |
1303 | * We really want to stop the transmitter from sending. | 1303 | * We really want to stop the transmitter from sending. |
1304 | */ | 1304 | */ |
1305 | if (up->port.type == PORT_16C950) { | 1305 | if (up->port.type == PORT_16C950) { |
1306 | up->acr |= UART_ACR_TXDIS; | 1306 | up->acr |= UART_ACR_TXDIS; |
1307 | serial_icr_write(up, UART_ACR, up->acr); | 1307 | serial_icr_write(up, UART_ACR, up->acr); |
1308 | } | 1308 | } |
1309 | } | 1309 | } |
1310 | 1310 | ||
1311 | static void transmit_chars(struct uart_8250_port *up); | 1311 | static void transmit_chars(struct uart_8250_port *up); |
1312 | 1312 | ||
1313 | static void serial8250_start_tx(struct uart_port *port) | 1313 | static void serial8250_start_tx(struct uart_port *port) |
1314 | { | 1314 | { |
1315 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1315 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
1316 | 1316 | ||
1317 | if (!(up->ier & UART_IER_THRI)) { | 1317 | if (!(up->ier & UART_IER_THRI)) { |
1318 | up->ier |= UART_IER_THRI; | 1318 | up->ier |= UART_IER_THRI; |
1319 | serial_out(up, UART_IER, up->ier); | 1319 | serial_out(up, UART_IER, up->ier); |
1320 | 1320 | ||
1321 | if (up->bugs & UART_BUG_TXEN) { | 1321 | if (up->bugs & UART_BUG_TXEN) { |
1322 | unsigned char lsr, iir; | 1322 | unsigned char lsr, iir; |
1323 | lsr = serial_in(up, UART_LSR); | 1323 | lsr = serial_in(up, UART_LSR); |
1324 | up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; | 1324 | up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; |
1325 | iir = serial_in(up, UART_IIR) & 0x0f; | 1325 | iir = serial_in(up, UART_IIR) & 0x0f; |
1326 | if ((up->port.type == PORT_RM9000) ? | 1326 | if ((up->port.type == PORT_RM9000) ? |
1327 | (lsr & UART_LSR_THRE && | 1327 | (lsr & UART_LSR_THRE && |
1328 | (iir == UART_IIR_NO_INT || iir == UART_IIR_THRI)) : | 1328 | (iir == UART_IIR_NO_INT || iir == UART_IIR_THRI)) : |
1329 | (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT)) | 1329 | (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT)) |
1330 | transmit_chars(up); | 1330 | transmit_chars(up); |
1331 | } | 1331 | } |
1332 | } | 1332 | } |
1333 | 1333 | ||
1334 | /* | 1334 | /* |
1335 | * Re-enable the transmitter if we disabled it. | 1335 | * Re-enable the transmitter if we disabled it. |
1336 | */ | 1336 | */ |
1337 | if (up->port.type == PORT_16C950 && up->acr & UART_ACR_TXDIS) { | 1337 | if (up->port.type == PORT_16C950 && up->acr & UART_ACR_TXDIS) { |
1338 | up->acr &= ~UART_ACR_TXDIS; | 1338 | up->acr &= ~UART_ACR_TXDIS; |
1339 | serial_icr_write(up, UART_ACR, up->acr); | 1339 | serial_icr_write(up, UART_ACR, up->acr); |
1340 | } | 1340 | } |
1341 | } | 1341 | } |
1342 | 1342 | ||
1343 | static void serial8250_stop_rx(struct uart_port *port) | 1343 | static void serial8250_stop_rx(struct uart_port *port) |
1344 | { | 1344 | { |
1345 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1345 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
1346 | 1346 | ||
1347 | up->ier &= ~UART_IER_RLSI; | 1347 | up->ier &= ~UART_IER_RLSI; |
1348 | up->port.read_status_mask &= ~UART_LSR_DR; | 1348 | up->port.read_status_mask &= ~UART_LSR_DR; |
1349 | serial_out(up, UART_IER, up->ier); | 1349 | serial_out(up, UART_IER, up->ier); |
1350 | } | 1350 | } |
1351 | 1351 | ||
1352 | static void serial8250_enable_ms(struct uart_port *port) | 1352 | static void serial8250_enable_ms(struct uart_port *port) |
1353 | { | 1353 | { |
1354 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1354 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
1355 | 1355 | ||
1356 | /* no MSR capabilities */ | 1356 | /* no MSR capabilities */ |
1357 | if (up->bugs & UART_BUG_NOMSR) | 1357 | if (up->bugs & UART_BUG_NOMSR) |
1358 | return; | 1358 | return; |
1359 | 1359 | ||
1360 | up->ier |= UART_IER_MSI; | 1360 | up->ier |= UART_IER_MSI; |
1361 | serial_out(up, UART_IER, up->ier); | 1361 | serial_out(up, UART_IER, up->ier); |
1362 | } | 1362 | } |
1363 | 1363 | ||
1364 | static void | 1364 | static void |
1365 | receive_chars(struct uart_8250_port *up, unsigned int *status) | 1365 | receive_chars(struct uart_8250_port *up, unsigned int *status) |
1366 | { | 1366 | { |
1367 | struct tty_struct *tty = up->port.info->port.tty; | 1367 | struct tty_struct *tty = up->port.info->port.tty; |
1368 | unsigned char ch, lsr = *status; | 1368 | unsigned char ch, lsr = *status; |
1369 | int max_count = 256; | 1369 | int max_count = 256; |
1370 | char flag; | 1370 | char flag; |
1371 | 1371 | ||
1372 | do { | 1372 | do { |
1373 | if (likely(lsr & UART_LSR_DR)) | 1373 | if (likely(lsr & UART_LSR_DR)) |
1374 | ch = serial_inp(up, UART_RX); | 1374 | ch = serial_inp(up, UART_RX); |
1375 | else | 1375 | else |
1376 | /* | 1376 | /* |
1377 | * Intel 82571 has a Serial Over Lan device that will | 1377 | * Intel 82571 has a Serial Over Lan device that will |
1378 | * set UART_LSR_BI without setting UART_LSR_DR when | 1378 | * set UART_LSR_BI without setting UART_LSR_DR when |
1379 | * it receives a break. To avoid reading from the | 1379 | * it receives a break. To avoid reading from the |
1380 | * receive buffer without UART_LSR_DR bit set, we | 1380 | * receive buffer without UART_LSR_DR bit set, we |
1381 | * just force the read character to be 0 | 1381 | * just force the read character to be 0 |
1382 | */ | 1382 | */ |
1383 | ch = 0; | 1383 | ch = 0; |
1384 | 1384 | ||
1385 | flag = TTY_NORMAL; | 1385 | flag = TTY_NORMAL; |
1386 | up->port.icount.rx++; | 1386 | up->port.icount.rx++; |
1387 | 1387 | ||
1388 | lsr |= up->lsr_saved_flags; | 1388 | lsr |= up->lsr_saved_flags; |
1389 | up->lsr_saved_flags = 0; | 1389 | up->lsr_saved_flags = 0; |
1390 | 1390 | ||
1391 | if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) { | 1391 | if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) { |
1392 | /* | 1392 | /* |
1393 | * For statistics only | 1393 | * For statistics only |
1394 | */ | 1394 | */ |
1395 | if (lsr & UART_LSR_BI) { | 1395 | if (lsr & UART_LSR_BI) { |
1396 | lsr &= ~(UART_LSR_FE | UART_LSR_PE); | 1396 | lsr &= ~(UART_LSR_FE | UART_LSR_PE); |
1397 | up->port.icount.brk++; | 1397 | up->port.icount.brk++; |
1398 | /* | 1398 | /* |
1399 | * We do the SysRQ and SAK checking | 1399 | * We do the SysRQ and SAK checking |
1400 | * here because otherwise the break | 1400 | * here because otherwise the break |
1401 | * may get masked by ignore_status_mask | 1401 | * may get masked by ignore_status_mask |
1402 | * or read_status_mask. | 1402 | * or read_status_mask. |
1403 | */ | 1403 | */ |
1404 | if (uart_handle_break(&up->port)) | 1404 | if (uart_handle_break(&up->port)) |
1405 | goto ignore_char; | 1405 | goto ignore_char; |
1406 | } else if (lsr & UART_LSR_PE) | 1406 | } else if (lsr & UART_LSR_PE) |
1407 | up->port.icount.parity++; | 1407 | up->port.icount.parity++; |
1408 | else if (lsr & UART_LSR_FE) | 1408 | else if (lsr & UART_LSR_FE) |
1409 | up->port.icount.frame++; | 1409 | up->port.icount.frame++; |
1410 | if (lsr & UART_LSR_OE) | 1410 | if (lsr & UART_LSR_OE) |
1411 | up->port.icount.overrun++; | 1411 | up->port.icount.overrun++; |
1412 | 1412 | ||
1413 | /* | 1413 | /* |
1414 | * Mask off conditions which should be ignored. | 1414 | * Mask off conditions which should be ignored. |
1415 | */ | 1415 | */ |
1416 | lsr &= up->port.read_status_mask; | 1416 | lsr &= up->port.read_status_mask; |
1417 | 1417 | ||
1418 | if (lsr & UART_LSR_BI) { | 1418 | if (lsr & UART_LSR_BI) { |
1419 | DEBUG_INTR("handling break...."); | 1419 | DEBUG_INTR("handling break...."); |
1420 | flag = TTY_BREAK; | 1420 | flag = TTY_BREAK; |
1421 | } else if (lsr & UART_LSR_PE) | 1421 | } else if (lsr & UART_LSR_PE) |
1422 | flag = TTY_PARITY; | 1422 | flag = TTY_PARITY; |
1423 | else if (lsr & UART_LSR_FE) | 1423 | else if (lsr & UART_LSR_FE) |
1424 | flag = TTY_FRAME; | 1424 | flag = TTY_FRAME; |
1425 | } | 1425 | } |
1426 | if (uart_handle_sysrq_char(&up->port, ch)) | 1426 | if (uart_handle_sysrq_char(&up->port, ch)) |
1427 | goto ignore_char; | 1427 | goto ignore_char; |
1428 | 1428 | ||
1429 | uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag); | 1429 | uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag); |
1430 | 1430 | ||
1431 | ignore_char: | 1431 | ignore_char: |
1432 | lsr = serial_inp(up, UART_LSR); | 1432 | lsr = serial_inp(up, UART_LSR); |
1433 | } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0)); | 1433 | } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0)); |
1434 | spin_unlock(&up->port.lock); | 1434 | spin_unlock(&up->port.lock); |
1435 | tty_flip_buffer_push(tty); | 1435 | tty_flip_buffer_push(tty); |
1436 | spin_lock(&up->port.lock); | 1436 | spin_lock(&up->port.lock); |
1437 | *status = lsr; | 1437 | *status = lsr; |
1438 | } | 1438 | } |
1439 | 1439 | ||
1440 | static void transmit_chars(struct uart_8250_port *up) | 1440 | static void transmit_chars(struct uart_8250_port *up) |
1441 | { | 1441 | { |
1442 | struct circ_buf *xmit = &up->port.info->xmit; | 1442 | struct circ_buf *xmit = &up->port.info->xmit; |
1443 | int count; | 1443 | int count; |
1444 | 1444 | ||
1445 | if (up->port.x_char) { | 1445 | if (up->port.x_char) { |
1446 | serial_outp(up, UART_TX, up->port.x_char); | 1446 | serial_outp(up, UART_TX, up->port.x_char); |
1447 | up->port.icount.tx++; | 1447 | up->port.icount.tx++; |
1448 | up->port.x_char = 0; | 1448 | up->port.x_char = 0; |
1449 | return; | 1449 | return; |
1450 | } | 1450 | } |
1451 | if (uart_tx_stopped(&up->port)) { | 1451 | if (uart_tx_stopped(&up->port)) { |
1452 | serial8250_stop_tx(&up->port); | 1452 | serial8250_stop_tx(&up->port); |
1453 | return; | 1453 | return; |
1454 | } | 1454 | } |
1455 | if (uart_circ_empty(xmit)) { | 1455 | if (uart_circ_empty(xmit)) { |
1456 | __stop_tx(up); | 1456 | __stop_tx(up); |
1457 | return; | 1457 | return; |
1458 | } | 1458 | } |
1459 | 1459 | ||
1460 | count = up->tx_loadsz; | 1460 | count = up->tx_loadsz; |
1461 | do { | 1461 | do { |
1462 | serial_out(up, UART_TX, xmit->buf[xmit->tail]); | 1462 | serial_out(up, UART_TX, xmit->buf[xmit->tail]); |
1463 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); | 1463 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
1464 | up->port.icount.tx++; | 1464 | up->port.icount.tx++; |
1465 | if (uart_circ_empty(xmit)) | 1465 | if (uart_circ_empty(xmit)) |
1466 | break; | 1466 | break; |
1467 | } while (--count > 0); | 1467 | } while (--count > 0); |
1468 | 1468 | ||
1469 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) | 1469 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
1470 | uart_write_wakeup(&up->port); | 1470 | uart_write_wakeup(&up->port); |
1471 | 1471 | ||
1472 | DEBUG_INTR("THRE..."); | 1472 | DEBUG_INTR("THRE..."); |
1473 | 1473 | ||
1474 | if (uart_circ_empty(xmit)) | 1474 | if (uart_circ_empty(xmit)) |
1475 | __stop_tx(up); | 1475 | __stop_tx(up); |
1476 | } | 1476 | } |
1477 | 1477 | ||
1478 | static unsigned int check_modem_status(struct uart_8250_port *up) | 1478 | static unsigned int check_modem_status(struct uart_8250_port *up) |
1479 | { | 1479 | { |
1480 | unsigned int status = serial_in(up, UART_MSR); | 1480 | unsigned int status = serial_in(up, UART_MSR); |
1481 | 1481 | ||
1482 | status |= up->msr_saved_flags; | 1482 | status |= up->msr_saved_flags; |
1483 | up->msr_saved_flags = 0; | 1483 | up->msr_saved_flags = 0; |
1484 | if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI && | 1484 | if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI && |
1485 | up->port.info != NULL) { | 1485 | up->port.info != NULL) { |
1486 | if (status & UART_MSR_TERI) | 1486 | if (status & UART_MSR_TERI) |
1487 | up->port.icount.rng++; | 1487 | up->port.icount.rng++; |
1488 | if (status & UART_MSR_DDSR) | 1488 | if (status & UART_MSR_DDSR) |
1489 | up->port.icount.dsr++; | 1489 | up->port.icount.dsr++; |
1490 | if (status & UART_MSR_DDCD) | 1490 | if (status & UART_MSR_DDCD) |
1491 | uart_handle_dcd_change(&up->port, status & UART_MSR_DCD); | 1491 | uart_handle_dcd_change(&up->port, status & UART_MSR_DCD); |
1492 | if (status & UART_MSR_DCTS) | 1492 | if (status & UART_MSR_DCTS) |
1493 | uart_handle_cts_change(&up->port, status & UART_MSR_CTS); | 1493 | uart_handle_cts_change(&up->port, status & UART_MSR_CTS); |
1494 | 1494 | ||
1495 | wake_up_interruptible(&up->port.info->delta_msr_wait); | 1495 | wake_up_interruptible(&up->port.info->delta_msr_wait); |
1496 | } | 1496 | } |
1497 | 1497 | ||
1498 | return status; | 1498 | return status; |
1499 | } | 1499 | } |
1500 | 1500 | ||
1501 | /* | 1501 | /* |
1502 | * This handles the interrupt from one port. | 1502 | * This handles the interrupt from one port. |
1503 | */ | 1503 | */ |
1504 | static void serial8250_handle_port(struct uart_8250_port *up) | 1504 | static void serial8250_handle_port(struct uart_8250_port *up) |
1505 | { | 1505 | { |
1506 | unsigned int status; | 1506 | unsigned int status; |
1507 | unsigned long flags; | 1507 | unsigned long flags; |
1508 | 1508 | ||
1509 | spin_lock_irqsave(&up->port.lock, flags); | 1509 | spin_lock_irqsave(&up->port.lock, flags); |
1510 | 1510 | ||
1511 | status = serial_inp(up, UART_LSR); | 1511 | status = serial_inp(up, UART_LSR); |
1512 | 1512 | ||
1513 | DEBUG_INTR("status = %x...", status); | 1513 | DEBUG_INTR("status = %x...", status); |
1514 | 1514 | ||
1515 | if (status & (UART_LSR_DR | UART_LSR_BI)) | 1515 | if (status & (UART_LSR_DR | UART_LSR_BI)) |
1516 | receive_chars(up, &status); | 1516 | receive_chars(up, &status); |
1517 | check_modem_status(up); | 1517 | check_modem_status(up); |
1518 | if (status & UART_LSR_THRE) | 1518 | if (status & UART_LSR_THRE) |
1519 | transmit_chars(up); | 1519 | transmit_chars(up); |
1520 | 1520 | ||
1521 | spin_unlock_irqrestore(&up->port.lock, flags); | 1521 | spin_unlock_irqrestore(&up->port.lock, flags); |
1522 | } | 1522 | } |
1523 | 1523 | ||
1524 | /* | 1524 | /* |
1525 | * This is the serial driver's interrupt routine. | 1525 | * This is the serial driver's interrupt routine. |
1526 | * | 1526 | * |
1527 | * Arjan thinks the old way was overly complex, so it got simplified. | 1527 | * Arjan thinks the old way was overly complex, so it got simplified. |
1528 | * Alan disagrees, saying that need the complexity to handle the weird | 1528 | * Alan disagrees, saying that need the complexity to handle the weird |
1529 | * nature of ISA shared interrupts. (This is a special exception.) | 1529 | * nature of ISA shared interrupts. (This is a special exception.) |
1530 | * | 1530 | * |
1531 | * In order to handle ISA shared interrupts properly, we need to check | 1531 | * In order to handle ISA shared interrupts properly, we need to check |
1532 | * that all ports have been serviced, and therefore the ISA interrupt | 1532 | * that all ports have been serviced, and therefore the ISA interrupt |
1533 | * line has been de-asserted. | 1533 | * line has been de-asserted. |
1534 | * | 1534 | * |
1535 | * This means we need to loop through all ports. checking that they | 1535 | * This means we need to loop through all ports. checking that they |
1536 | * don't have an interrupt pending. | 1536 | * don't have an interrupt pending. |
1537 | */ | 1537 | */ |
1538 | static irqreturn_t serial8250_interrupt(int irq, void *dev_id) | 1538 | static irqreturn_t serial8250_interrupt(int irq, void *dev_id) |
1539 | { | 1539 | { |
1540 | struct irq_info *i = dev_id; | 1540 | struct irq_info *i = dev_id; |
1541 | struct list_head *l, *end = NULL; | 1541 | struct list_head *l, *end = NULL; |
1542 | int pass_counter = 0, handled = 0; | 1542 | int pass_counter = 0, handled = 0; |
1543 | 1543 | ||
1544 | DEBUG_INTR("serial8250_interrupt(%d)...", irq); | 1544 | DEBUG_INTR("serial8250_interrupt(%d)...", irq); |
1545 | 1545 | ||
1546 | spin_lock(&i->lock); | 1546 | spin_lock(&i->lock); |
1547 | 1547 | ||
1548 | l = i->head; | 1548 | l = i->head; |
1549 | do { | 1549 | do { |
1550 | struct uart_8250_port *up; | 1550 | struct uart_8250_port *up; |
1551 | unsigned int iir; | 1551 | unsigned int iir; |
1552 | 1552 | ||
1553 | up = list_entry(l, struct uart_8250_port, list); | 1553 | up = list_entry(l, struct uart_8250_port, list); |
1554 | 1554 | ||
1555 | iir = serial_in(up, UART_IIR); | 1555 | iir = serial_in(up, UART_IIR); |
1556 | if (!(iir & UART_IIR_NO_INT)) { | 1556 | if (!(iir & UART_IIR_NO_INT)) { |
1557 | serial8250_handle_port(up); | 1557 | serial8250_handle_port(up); |
1558 | 1558 | ||
1559 | handled = 1; | 1559 | handled = 1; |
1560 | 1560 | ||
1561 | end = NULL; | 1561 | end = NULL; |
1562 | } else if (up->port.iotype == UPIO_DWAPB && | 1562 | } else if (up->port.iotype == UPIO_DWAPB && |
1563 | (iir & UART_IIR_BUSY) == UART_IIR_BUSY) { | 1563 | (iir & UART_IIR_BUSY) == UART_IIR_BUSY) { |
1564 | /* The DesignWare APB UART has an Busy Detect (0x07) | 1564 | /* The DesignWare APB UART has an Busy Detect (0x07) |
1565 | * interrupt meaning an LCR write attempt occured while the | 1565 | * interrupt meaning an LCR write attempt occured while the |
1566 | * UART was busy. The interrupt must be cleared by reading | 1566 | * UART was busy. The interrupt must be cleared by reading |
1567 | * the UART status register (USR) and the LCR re-written. */ | 1567 | * the UART status register (USR) and the LCR re-written. */ |
1568 | unsigned int status; | 1568 | unsigned int status; |
1569 | status = *(volatile u32 *)up->port.private_data; | 1569 | status = *(volatile u32 *)up->port.private_data; |
1570 | serial_out(up, UART_LCR, up->lcr); | 1570 | serial_out(up, UART_LCR, up->lcr); |
1571 | 1571 | ||
1572 | handled = 1; | 1572 | handled = 1; |
1573 | 1573 | ||
1574 | end = NULL; | 1574 | end = NULL; |
1575 | } else if (end == NULL) | 1575 | } else if (end == NULL) |
1576 | end = l; | 1576 | end = l; |
1577 | 1577 | ||
1578 | l = l->next; | 1578 | l = l->next; |
1579 | 1579 | ||
1580 | if (l == i->head && pass_counter++ > PASS_LIMIT) { | 1580 | if (l == i->head && pass_counter++ > PASS_LIMIT) { |
1581 | /* If we hit this, we're dead. */ | 1581 | /* If we hit this, we're dead. */ |
1582 | printk(KERN_ERR "serial8250: too much work for " | 1582 | printk(KERN_ERR "serial8250: too much work for " |
1583 | "irq%d\n", irq); | 1583 | "irq%d\n", irq); |
1584 | break; | 1584 | break; |
1585 | } | 1585 | } |
1586 | } while (l != end); | 1586 | } while (l != end); |
1587 | 1587 | ||
1588 | spin_unlock(&i->lock); | 1588 | spin_unlock(&i->lock); |
1589 | 1589 | ||
1590 | DEBUG_INTR("end.\n"); | 1590 | DEBUG_INTR("end.\n"); |
1591 | 1591 | ||
1592 | return IRQ_RETVAL(handled); | 1592 | return IRQ_RETVAL(handled); |
1593 | } | 1593 | } |
1594 | 1594 | ||
1595 | /* | 1595 | /* |
1596 | * To support ISA shared interrupts, we need to have one interrupt | 1596 | * To support ISA shared interrupts, we need to have one interrupt |
1597 | * handler that ensures that the IRQ line has been deasserted | 1597 | * handler that ensures that the IRQ line has been deasserted |
1598 | * before returning. Failing to do this will result in the IRQ | 1598 | * before returning. Failing to do this will result in the IRQ |
1599 | * line being stuck active, and, since ISA irqs are edge triggered, | 1599 | * line being stuck active, and, since ISA irqs are edge triggered, |
1600 | * no more IRQs will be seen. | 1600 | * no more IRQs will be seen. |
1601 | */ | 1601 | */ |
1602 | static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up) | 1602 | static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up) |
1603 | { | 1603 | { |
1604 | spin_lock_irq(&i->lock); | 1604 | spin_lock_irq(&i->lock); |
1605 | 1605 | ||
1606 | if (!list_empty(i->head)) { | 1606 | if (!list_empty(i->head)) { |
1607 | if (i->head == &up->list) | 1607 | if (i->head == &up->list) |
1608 | i->head = i->head->next; | 1608 | i->head = i->head->next; |
1609 | list_del(&up->list); | 1609 | list_del(&up->list); |
1610 | } else { | 1610 | } else { |
1611 | BUG_ON(i->head != &up->list); | 1611 | BUG_ON(i->head != &up->list); |
1612 | i->head = NULL; | 1612 | i->head = NULL; |
1613 | } | 1613 | } |
1614 | spin_unlock_irq(&i->lock); | 1614 | spin_unlock_irq(&i->lock); |
1615 | /* List empty so throw away the hash node */ | 1615 | /* List empty so throw away the hash node */ |
1616 | if (i->head == NULL) { | 1616 | if (i->head == NULL) { |
1617 | hlist_del(&i->node); | 1617 | hlist_del(&i->node); |
1618 | kfree(i); | 1618 | kfree(i); |
1619 | } | 1619 | } |
1620 | } | 1620 | } |
1621 | 1621 | ||
1622 | static int serial_link_irq_chain(struct uart_8250_port *up) | 1622 | static int serial_link_irq_chain(struct uart_8250_port *up) |
1623 | { | 1623 | { |
1624 | struct hlist_head *h; | 1624 | struct hlist_head *h; |
1625 | struct hlist_node *n; | 1625 | struct hlist_node *n; |
1626 | struct irq_info *i; | 1626 | struct irq_info *i; |
1627 | int ret, irq_flags = up->port.flags & UPF_SHARE_IRQ ? IRQF_SHARED : 0; | 1627 | int ret, irq_flags = up->port.flags & UPF_SHARE_IRQ ? IRQF_SHARED : 0; |
1628 | 1628 | ||
1629 | mutex_lock(&hash_mutex); | 1629 | mutex_lock(&hash_mutex); |
1630 | 1630 | ||
1631 | h = &irq_lists[up->port.irq % NR_IRQ_HASH]; | 1631 | h = &irq_lists[up->port.irq % NR_IRQ_HASH]; |
1632 | 1632 | ||
1633 | hlist_for_each(n, h) { | 1633 | hlist_for_each(n, h) { |
1634 | i = hlist_entry(n, struct irq_info, node); | 1634 | i = hlist_entry(n, struct irq_info, node); |
1635 | if (i->irq == up->port.irq) | 1635 | if (i->irq == up->port.irq) |
1636 | break; | 1636 | break; |
1637 | } | 1637 | } |
1638 | 1638 | ||
1639 | if (n == NULL) { | 1639 | if (n == NULL) { |
1640 | i = kzalloc(sizeof(struct irq_info), GFP_KERNEL); | 1640 | i = kzalloc(sizeof(struct irq_info), GFP_KERNEL); |
1641 | if (i == NULL) { | 1641 | if (i == NULL) { |
1642 | mutex_unlock(&hash_mutex); | 1642 | mutex_unlock(&hash_mutex); |
1643 | return -ENOMEM; | 1643 | return -ENOMEM; |
1644 | } | 1644 | } |
1645 | spin_lock_init(&i->lock); | 1645 | spin_lock_init(&i->lock); |
1646 | i->irq = up->port.irq; | 1646 | i->irq = up->port.irq; |
1647 | hlist_add_head(&i->node, h); | 1647 | hlist_add_head(&i->node, h); |
1648 | } | 1648 | } |
1649 | mutex_unlock(&hash_mutex); | 1649 | mutex_unlock(&hash_mutex); |
1650 | 1650 | ||
1651 | spin_lock_irq(&i->lock); | 1651 | spin_lock_irq(&i->lock); |
1652 | 1652 | ||
1653 | if (i->head) { | 1653 | if (i->head) { |
1654 | list_add(&up->list, i->head); | 1654 | list_add(&up->list, i->head); |
1655 | spin_unlock_irq(&i->lock); | 1655 | spin_unlock_irq(&i->lock); |
1656 | 1656 | ||
1657 | ret = 0; | 1657 | ret = 0; |
1658 | } else { | 1658 | } else { |
1659 | INIT_LIST_HEAD(&up->list); | 1659 | INIT_LIST_HEAD(&up->list); |
1660 | i->head = &up->list; | 1660 | i->head = &up->list; |
1661 | spin_unlock_irq(&i->lock); | 1661 | spin_unlock_irq(&i->lock); |
1662 | 1662 | ||
1663 | ret = request_irq(up->port.irq, serial8250_interrupt, | 1663 | ret = request_irq(up->port.irq, serial8250_interrupt, |
1664 | irq_flags, "serial", i); | 1664 | irq_flags, "serial", i); |
1665 | if (ret < 0) | 1665 | if (ret < 0) |
1666 | serial_do_unlink(i, up); | 1666 | serial_do_unlink(i, up); |
1667 | } | 1667 | } |
1668 | 1668 | ||
1669 | return ret; | 1669 | return ret; |
1670 | } | 1670 | } |
1671 | 1671 | ||
1672 | static void serial_unlink_irq_chain(struct uart_8250_port *up) | 1672 | static void serial_unlink_irq_chain(struct uart_8250_port *up) |
1673 | { | 1673 | { |
1674 | struct irq_info *i; | 1674 | struct irq_info *i; |
1675 | struct hlist_node *n; | 1675 | struct hlist_node *n; |
1676 | struct hlist_head *h; | 1676 | struct hlist_head *h; |
1677 | 1677 | ||
1678 | mutex_lock(&hash_mutex); | 1678 | mutex_lock(&hash_mutex); |
1679 | 1679 | ||
1680 | h = &irq_lists[up->port.irq % NR_IRQ_HASH]; | 1680 | h = &irq_lists[up->port.irq % NR_IRQ_HASH]; |
1681 | 1681 | ||
1682 | hlist_for_each(n, h) { | 1682 | hlist_for_each(n, h) { |
1683 | i = hlist_entry(n, struct irq_info, node); | 1683 | i = hlist_entry(n, struct irq_info, node); |
1684 | if (i->irq == up->port.irq) | 1684 | if (i->irq == up->port.irq) |
1685 | break; | 1685 | break; |
1686 | } | 1686 | } |
1687 | 1687 | ||
1688 | BUG_ON(n == NULL); | 1688 | BUG_ON(n == NULL); |
1689 | BUG_ON(i->head == NULL); | 1689 | BUG_ON(i->head == NULL); |
1690 | 1690 | ||
1691 | if (list_empty(i->head)) | 1691 | if (list_empty(i->head)) |
1692 | free_irq(up->port.irq, i); | 1692 | free_irq(up->port.irq, i); |
1693 | 1693 | ||
1694 | serial_do_unlink(i, up); | 1694 | serial_do_unlink(i, up); |
1695 | mutex_unlock(&hash_mutex); | 1695 | mutex_unlock(&hash_mutex); |
1696 | } | 1696 | } |
1697 | 1697 | ||
1698 | /* Base timer interval for polling */ | 1698 | /* Base timer interval for polling */ |
1699 | static inline int poll_timeout(int timeout) | 1699 | static inline int poll_timeout(int timeout) |
1700 | { | 1700 | { |
1701 | return timeout > 6 ? (timeout / 2 - 2) : 1; | 1701 | return timeout > 6 ? (timeout / 2 - 2) : 1; |
1702 | } | 1702 | } |
1703 | 1703 | ||
1704 | /* | 1704 | /* |
1705 | * This function is used to handle ports that do not have an | 1705 | * This function is used to handle ports that do not have an |
1706 | * interrupt. This doesn't work very well for 16450's, but gives | 1706 | * interrupt. This doesn't work very well for 16450's, but gives |
1707 | * barely passable results for a 16550A. (Although at the expense | 1707 | * barely passable results for a 16550A. (Although at the expense |
1708 | * of much CPU overhead). | 1708 | * of much CPU overhead). |
1709 | */ | 1709 | */ |
1710 | static void serial8250_timeout(unsigned long data) | 1710 | static void serial8250_timeout(unsigned long data) |
1711 | { | 1711 | { |
1712 | struct uart_8250_port *up = (struct uart_8250_port *)data; | 1712 | struct uart_8250_port *up = (struct uart_8250_port *)data; |
1713 | unsigned int iir; | 1713 | unsigned int iir; |
1714 | 1714 | ||
1715 | iir = serial_in(up, UART_IIR); | 1715 | iir = serial_in(up, UART_IIR); |
1716 | if (!(iir & UART_IIR_NO_INT)) | 1716 | if (!(iir & UART_IIR_NO_INT)) |
1717 | serial8250_handle_port(up); | 1717 | serial8250_handle_port(up); |
1718 | mod_timer(&up->timer, jiffies + poll_timeout(up->port.timeout)); | 1718 | mod_timer(&up->timer, jiffies + poll_timeout(up->port.timeout)); |
1719 | } | 1719 | } |
1720 | 1720 | ||
1721 | static void serial8250_backup_timeout(unsigned long data) | 1721 | static void serial8250_backup_timeout(unsigned long data) |
1722 | { | 1722 | { |
1723 | struct uart_8250_port *up = (struct uart_8250_port *)data; | 1723 | struct uart_8250_port *up = (struct uart_8250_port *)data; |
1724 | unsigned int iir, ier = 0, lsr; | 1724 | unsigned int iir, ier = 0, lsr; |
1725 | unsigned long flags; | 1725 | unsigned long flags; |
1726 | 1726 | ||
1727 | /* | 1727 | /* |
1728 | * Must disable interrupts or else we risk racing with the interrupt | 1728 | * Must disable interrupts or else we risk racing with the interrupt |
1729 | * based handler. | 1729 | * based handler. |
1730 | */ | 1730 | */ |
1731 | if (is_real_interrupt(up->port.irq)) { | 1731 | if (is_real_interrupt(up->port.irq)) { |
1732 | ier = serial_in(up, UART_IER); | 1732 | ier = serial_in(up, UART_IER); |
1733 | serial_out(up, UART_IER, 0); | 1733 | serial_out(up, UART_IER, 0); |
1734 | } | 1734 | } |
1735 | 1735 | ||
1736 | iir = serial_in(up, UART_IIR); | 1736 | iir = serial_in(up, UART_IIR); |
1737 | 1737 | ||
1738 | /* | 1738 | /* |
1739 | * This should be a safe test for anyone who doesn't trust the | 1739 | * This should be a safe test for anyone who doesn't trust the |
1740 | * IIR bits on their UART, but it's specifically designed for | 1740 | * IIR bits on their UART, but it's specifically designed for |
1741 | * the "Diva" UART used on the management processor on many HP | 1741 | * the "Diva" UART used on the management processor on many HP |
1742 | * ia64 and parisc boxes. | 1742 | * ia64 and parisc boxes. |
1743 | */ | 1743 | */ |
1744 | spin_lock_irqsave(&up->port.lock, flags); | 1744 | spin_lock_irqsave(&up->port.lock, flags); |
1745 | lsr = serial_in(up, UART_LSR); | 1745 | lsr = serial_in(up, UART_LSR); |
1746 | up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; | 1746 | up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; |
1747 | spin_unlock_irqrestore(&up->port.lock, flags); | 1747 | spin_unlock_irqrestore(&up->port.lock, flags); |
1748 | if ((iir & UART_IIR_NO_INT) && (up->ier & UART_IER_THRI) && | 1748 | if ((iir & UART_IIR_NO_INT) && (up->ier & UART_IER_THRI) && |
1749 | (!uart_circ_empty(&up->port.info->xmit) || up->port.x_char) && | 1749 | (!uart_circ_empty(&up->port.info->xmit) || up->port.x_char) && |
1750 | (lsr & UART_LSR_THRE)) { | 1750 | (lsr & UART_LSR_THRE)) { |
1751 | iir &= ~(UART_IIR_ID | UART_IIR_NO_INT); | 1751 | iir &= ~(UART_IIR_ID | UART_IIR_NO_INT); |
1752 | iir |= UART_IIR_THRI; | 1752 | iir |= UART_IIR_THRI; |
1753 | } | 1753 | } |
1754 | 1754 | ||
1755 | if (!(iir & UART_IIR_NO_INT)) | 1755 | if (!(iir & UART_IIR_NO_INT)) |
1756 | serial8250_handle_port(up); | 1756 | serial8250_handle_port(up); |
1757 | 1757 | ||
1758 | if (is_real_interrupt(up->port.irq)) | 1758 | if (is_real_interrupt(up->port.irq)) |
1759 | serial_out(up, UART_IER, ier); | 1759 | serial_out(up, UART_IER, ier); |
1760 | 1760 | ||
1761 | /* Standard timer interval plus 0.2s to keep the port running */ | 1761 | /* Standard timer interval plus 0.2s to keep the port running */ |
1762 | mod_timer(&up->timer, | 1762 | mod_timer(&up->timer, |
1763 | jiffies + poll_timeout(up->port.timeout) + HZ / 5); | 1763 | jiffies + poll_timeout(up->port.timeout) + HZ / 5); |
1764 | } | 1764 | } |
1765 | 1765 | ||
1766 | static unsigned int serial8250_tx_empty(struct uart_port *port) | 1766 | static unsigned int serial8250_tx_empty(struct uart_port *port) |
1767 | { | 1767 | { |
1768 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1768 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
1769 | unsigned long flags; | 1769 | unsigned long flags; |
1770 | unsigned int lsr; | 1770 | unsigned int lsr; |
1771 | 1771 | ||
1772 | spin_lock_irqsave(&up->port.lock, flags); | 1772 | spin_lock_irqsave(&up->port.lock, flags); |
1773 | lsr = serial_in(up, UART_LSR); | 1773 | lsr = serial_in(up, UART_LSR); |
1774 | up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; | 1774 | up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; |
1775 | spin_unlock_irqrestore(&up->port.lock, flags); | 1775 | spin_unlock_irqrestore(&up->port.lock, flags); |
1776 | 1776 | ||
1777 | return lsr & UART_LSR_TEMT ? TIOCSER_TEMT : 0; | 1777 | return lsr & UART_LSR_TEMT ? TIOCSER_TEMT : 0; |
1778 | } | 1778 | } |
1779 | 1779 | ||
1780 | static unsigned int serial8250_get_mctrl(struct uart_port *port) | 1780 | static unsigned int serial8250_get_mctrl(struct uart_port *port) |
1781 | { | 1781 | { |
1782 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1782 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
1783 | unsigned int status; | 1783 | unsigned int status; |
1784 | unsigned int ret; | 1784 | unsigned int ret; |
1785 | 1785 | ||
1786 | status = check_modem_status(up); | 1786 | status = check_modem_status(up); |
1787 | 1787 | ||
1788 | ret = 0; | 1788 | ret = 0; |
1789 | if (status & UART_MSR_DCD) | 1789 | if (status & UART_MSR_DCD) |
1790 | ret |= TIOCM_CAR; | 1790 | ret |= TIOCM_CAR; |
1791 | if (status & UART_MSR_RI) | 1791 | if (status & UART_MSR_RI) |
1792 | ret |= TIOCM_RNG; | 1792 | ret |= TIOCM_RNG; |
1793 | if (status & UART_MSR_DSR) | 1793 | if (status & UART_MSR_DSR) |
1794 | ret |= TIOCM_DSR; | 1794 | ret |= TIOCM_DSR; |
1795 | if (status & UART_MSR_CTS) | 1795 | if (status & UART_MSR_CTS) |
1796 | ret |= TIOCM_CTS; | 1796 | ret |= TIOCM_CTS; |
1797 | return ret; | 1797 | return ret; |
1798 | } | 1798 | } |
1799 | 1799 | ||
1800 | static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl) | 1800 | static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl) |
1801 | { | 1801 | { |
1802 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1802 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
1803 | unsigned char mcr = 0; | 1803 | unsigned char mcr = 0; |
1804 | 1804 | ||
1805 | if (mctrl & TIOCM_RTS) | 1805 | if (mctrl & TIOCM_RTS) |
1806 | mcr |= UART_MCR_RTS; | 1806 | mcr |= UART_MCR_RTS; |
1807 | if (mctrl & TIOCM_DTR) | 1807 | if (mctrl & TIOCM_DTR) |
1808 | mcr |= UART_MCR_DTR; | 1808 | mcr |= UART_MCR_DTR; |
1809 | if (mctrl & TIOCM_OUT1) | 1809 | if (mctrl & TIOCM_OUT1) |
1810 | mcr |= UART_MCR_OUT1; | 1810 | mcr |= UART_MCR_OUT1; |
1811 | if (mctrl & TIOCM_OUT2) | 1811 | if (mctrl & TIOCM_OUT2) |
1812 | mcr |= UART_MCR_OUT2; | 1812 | mcr |= UART_MCR_OUT2; |
1813 | if (mctrl & TIOCM_LOOP) | 1813 | if (mctrl & TIOCM_LOOP) |
1814 | mcr |= UART_MCR_LOOP; | 1814 | mcr |= UART_MCR_LOOP; |
1815 | 1815 | ||
1816 | mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr; | 1816 | mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr; |
1817 | 1817 | ||
1818 | serial_out(up, UART_MCR, mcr); | 1818 | serial_out(up, UART_MCR, mcr); |
1819 | } | 1819 | } |
1820 | 1820 | ||
1821 | static void serial8250_break_ctl(struct uart_port *port, int break_state) | 1821 | static void serial8250_break_ctl(struct uart_port *port, int break_state) |
1822 | { | 1822 | { |
1823 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1823 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
1824 | unsigned long flags; | 1824 | unsigned long flags; |
1825 | 1825 | ||
1826 | spin_lock_irqsave(&up->port.lock, flags); | 1826 | spin_lock_irqsave(&up->port.lock, flags); |
1827 | if (break_state == -1) | 1827 | if (break_state == -1) |
1828 | up->lcr |= UART_LCR_SBC; | 1828 | up->lcr |= UART_LCR_SBC; |
1829 | else | 1829 | else |
1830 | up->lcr &= ~UART_LCR_SBC; | 1830 | up->lcr &= ~UART_LCR_SBC; |
1831 | serial_out(up, UART_LCR, up->lcr); | 1831 | serial_out(up, UART_LCR, up->lcr); |
1832 | spin_unlock_irqrestore(&up->port.lock, flags); | 1832 | spin_unlock_irqrestore(&up->port.lock, flags); |
1833 | } | 1833 | } |
1834 | 1834 | ||
1835 | #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) | 1835 | #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) |
1836 | 1836 | ||
1837 | /* | 1837 | /* |
1838 | * Wait for transmitter & holding register to empty | 1838 | * Wait for transmitter & holding register to empty |
1839 | */ | 1839 | */ |
1840 | static void wait_for_xmitr(struct uart_8250_port *up, int bits) | 1840 | static void wait_for_xmitr(struct uart_8250_port *up, int bits) |
1841 | { | 1841 | { |
1842 | unsigned int status, tmout = 10000; | 1842 | unsigned int status, tmout = 10000; |
1843 | 1843 | ||
1844 | /* Wait up to 10ms for the character(s) to be sent. */ | 1844 | /* Wait up to 10ms for the character(s) to be sent. */ |
1845 | do { | 1845 | do { |
1846 | status = serial_in(up, UART_LSR); | 1846 | status = serial_in(up, UART_LSR); |
1847 | 1847 | ||
1848 | up->lsr_saved_flags |= status & LSR_SAVE_FLAGS; | 1848 | up->lsr_saved_flags |= status & LSR_SAVE_FLAGS; |
1849 | 1849 | ||
1850 | if (--tmout == 0) | 1850 | if (--tmout == 0) |
1851 | break; | 1851 | break; |
1852 | udelay(1); | 1852 | udelay(1); |
1853 | } while ((status & bits) != bits); | 1853 | } while ((status & bits) != bits); |
1854 | 1854 | ||
1855 | /* Wait up to 1s for flow control if necessary */ | 1855 | /* Wait up to 1s for flow control if necessary */ |
1856 | if (up->port.flags & UPF_CONS_FLOW) { | 1856 | if (up->port.flags & UPF_CONS_FLOW) { |
1857 | unsigned int tmout; | 1857 | unsigned int tmout; |
1858 | for (tmout = 1000000; tmout; tmout--) { | 1858 | for (tmout = 1000000; tmout; tmout--) { |
1859 | unsigned int msr = serial_in(up, UART_MSR); | 1859 | unsigned int msr = serial_in(up, UART_MSR); |
1860 | up->msr_saved_flags |= msr & MSR_SAVE_FLAGS; | 1860 | up->msr_saved_flags |= msr & MSR_SAVE_FLAGS; |
1861 | if (msr & UART_MSR_CTS) | 1861 | if (msr & UART_MSR_CTS) |
1862 | break; | 1862 | break; |
1863 | udelay(1); | 1863 | udelay(1); |
1864 | touch_nmi_watchdog(); | 1864 | touch_nmi_watchdog(); |
1865 | } | 1865 | } |
1866 | } | 1866 | } |
1867 | } | 1867 | } |
1868 | 1868 | ||
1869 | #ifdef CONFIG_CONSOLE_POLL | 1869 | #ifdef CONFIG_CONSOLE_POLL |
1870 | /* | 1870 | /* |
1871 | * Console polling routines for writing and reading from the uart while | 1871 | * Console polling routines for writing and reading from the uart while |
1872 | * in an interrupt or debug context. | 1872 | * in an interrupt or debug context. |
1873 | */ | 1873 | */ |
1874 | 1874 | ||
1875 | static int serial8250_get_poll_char(struct uart_port *port) | 1875 | static int serial8250_get_poll_char(struct uart_port *port) |
1876 | { | 1876 | { |
1877 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1877 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
1878 | unsigned char lsr = serial_inp(up, UART_LSR); | 1878 | unsigned char lsr = serial_inp(up, UART_LSR); |
1879 | 1879 | ||
1880 | while (!(lsr & UART_LSR_DR)) | 1880 | while (!(lsr & UART_LSR_DR)) |
1881 | lsr = serial_inp(up, UART_LSR); | 1881 | lsr = serial_inp(up, UART_LSR); |
1882 | 1882 | ||
1883 | return serial_inp(up, UART_RX); | 1883 | return serial_inp(up, UART_RX); |
1884 | } | 1884 | } |
1885 | 1885 | ||
1886 | 1886 | ||
1887 | static void serial8250_put_poll_char(struct uart_port *port, | 1887 | static void serial8250_put_poll_char(struct uart_port *port, |
1888 | unsigned char c) | 1888 | unsigned char c) |
1889 | { | 1889 | { |
1890 | unsigned int ier; | 1890 | unsigned int ier; |
1891 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1891 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
1892 | 1892 | ||
1893 | /* | 1893 | /* |
1894 | * First save the IER then disable the interrupts | 1894 | * First save the IER then disable the interrupts |
1895 | */ | 1895 | */ |
1896 | ier = serial_in(up, UART_IER); | 1896 | ier = serial_in(up, UART_IER); |
1897 | if (up->capabilities & UART_CAP_UUE) | 1897 | if (up->capabilities & UART_CAP_UUE) |
1898 | serial_out(up, UART_IER, UART_IER_UUE); | 1898 | serial_out(up, UART_IER, UART_IER_UUE); |
1899 | else | 1899 | else |
1900 | serial_out(up, UART_IER, 0); | 1900 | serial_out(up, UART_IER, 0); |
1901 | 1901 | ||
1902 | wait_for_xmitr(up, BOTH_EMPTY); | 1902 | wait_for_xmitr(up, BOTH_EMPTY); |
1903 | /* | 1903 | /* |
1904 | * Send the character out. | 1904 | * Send the character out. |
1905 | * If a LF, also do CR... | 1905 | * If a LF, also do CR... |
1906 | */ | 1906 | */ |
1907 | serial_out(up, UART_TX, c); | 1907 | serial_out(up, UART_TX, c); |
1908 | if (c == 10) { | 1908 | if (c == 10) { |
1909 | wait_for_xmitr(up, BOTH_EMPTY); | 1909 | wait_for_xmitr(up, BOTH_EMPTY); |
1910 | serial_out(up, UART_TX, 13); | 1910 | serial_out(up, UART_TX, 13); |
1911 | } | 1911 | } |
1912 | 1912 | ||
1913 | /* | 1913 | /* |
1914 | * Finally, wait for transmitter to become empty | 1914 | * Finally, wait for transmitter to become empty |
1915 | * and restore the IER | 1915 | * and restore the IER |
1916 | */ | 1916 | */ |
1917 | wait_for_xmitr(up, BOTH_EMPTY); | 1917 | wait_for_xmitr(up, BOTH_EMPTY); |
1918 | serial_out(up, UART_IER, ier); | 1918 | serial_out(up, UART_IER, ier); |
1919 | } | 1919 | } |
1920 | 1920 | ||
1921 | #endif /* CONFIG_CONSOLE_POLL */ | 1921 | #endif /* CONFIG_CONSOLE_POLL */ |
1922 | 1922 | ||
1923 | static int serial8250_startup(struct uart_port *port) | 1923 | static int serial8250_startup(struct uart_port *port) |
1924 | { | 1924 | { |
1925 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1925 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
1926 | unsigned long flags; | 1926 | unsigned long flags; |
1927 | unsigned char lsr, iir; | 1927 | unsigned char lsr, iir; |
1928 | int retval; | 1928 | int retval; |
1929 | 1929 | ||
1930 | up->capabilities = uart_config[up->port.type].flags; | 1930 | up->capabilities = uart_config[up->port.type].flags; |
1931 | up->mcr = 0; | 1931 | up->mcr = 0; |
1932 | 1932 | ||
1933 | if (up->port.type == PORT_16C950) { | 1933 | if (up->port.type == PORT_16C950) { |
1934 | /* Wake up and initialize UART */ | 1934 | /* Wake up and initialize UART */ |
1935 | up->acr = 0; | 1935 | up->acr = 0; |
1936 | serial_outp(up, UART_LCR, 0xBF); | 1936 | serial_outp(up, UART_LCR, 0xBF); |
1937 | serial_outp(up, UART_EFR, UART_EFR_ECB); | 1937 | serial_outp(up, UART_EFR, UART_EFR_ECB); |
1938 | serial_outp(up, UART_IER, 0); | 1938 | serial_outp(up, UART_IER, 0); |
1939 | serial_outp(up, UART_LCR, 0); | 1939 | serial_outp(up, UART_LCR, 0); |
1940 | serial_icr_write(up, UART_CSR, 0); /* Reset the UART */ | 1940 | serial_icr_write(up, UART_CSR, 0); /* Reset the UART */ |
1941 | serial_outp(up, UART_LCR, 0xBF); | 1941 | serial_outp(up, UART_LCR, 0xBF); |
1942 | serial_outp(up, UART_EFR, UART_EFR_ECB); | 1942 | serial_outp(up, UART_EFR, UART_EFR_ECB); |
1943 | serial_outp(up, UART_LCR, 0); | 1943 | serial_outp(up, UART_LCR, 0); |
1944 | } | 1944 | } |
1945 | 1945 | ||
1946 | #ifdef CONFIG_SERIAL_8250_RSA | 1946 | #ifdef CONFIG_SERIAL_8250_RSA |
1947 | /* | 1947 | /* |
1948 | * If this is an RSA port, see if we can kick it up to the | 1948 | * If this is an RSA port, see if we can kick it up to the |
1949 | * higher speed clock. | 1949 | * higher speed clock. |
1950 | */ | 1950 | */ |
1951 | enable_rsa(up); | 1951 | enable_rsa(up); |
1952 | #endif | 1952 | #endif |
1953 | 1953 | ||
1954 | /* | 1954 | /* |
1955 | * Clear the FIFO buffers and disable them. | 1955 | * Clear the FIFO buffers and disable them. |
1956 | * (they will be reenabled in set_termios()) | 1956 | * (they will be reenabled in set_termios()) |
1957 | */ | 1957 | */ |
1958 | serial8250_clear_fifos(up); | 1958 | serial8250_clear_fifos(up); |
1959 | 1959 | ||
1960 | /* | 1960 | /* |
1961 | * Clear the interrupt registers. | 1961 | * Clear the interrupt registers. |
1962 | */ | 1962 | */ |
1963 | (void) serial_inp(up, UART_LSR); | 1963 | (void) serial_inp(up, UART_LSR); |
1964 | (void) serial_inp(up, UART_RX); | 1964 | (void) serial_inp(up, UART_RX); |
1965 | (void) serial_inp(up, UART_IIR); | 1965 | (void) serial_inp(up, UART_IIR); |
1966 | (void) serial_inp(up, UART_MSR); | 1966 | (void) serial_inp(up, UART_MSR); |
1967 | 1967 | ||
1968 | /* | 1968 | /* |
1969 | * At this point, there's no way the LSR could still be 0xff; | 1969 | * At this point, there's no way the LSR could still be 0xff; |
1970 | * if it is, then bail out, because there's likely no UART | 1970 | * if it is, then bail out, because there's likely no UART |
1971 | * here. | 1971 | * here. |
1972 | */ | 1972 | */ |
1973 | if (!(up->port.flags & UPF_BUGGY_UART) && | 1973 | if (!(up->port.flags & UPF_BUGGY_UART) && |
1974 | (serial_inp(up, UART_LSR) == 0xff)) { | 1974 | (serial_inp(up, UART_LSR) == 0xff)) { |
1975 | printk(KERN_INFO "ttyS%d: LSR safety check engaged!\n", | 1975 | printk(KERN_INFO "ttyS%d: LSR safety check engaged!\n", |
1976 | serial_index(&up->port)); | 1976 | serial_index(&up->port)); |
1977 | return -ENODEV; | 1977 | return -ENODEV; |
1978 | } | 1978 | } |
1979 | 1979 | ||
1980 | /* | 1980 | /* |
1981 | * For a XR16C850, we need to set the trigger levels | 1981 | * For a XR16C850, we need to set the trigger levels |
1982 | */ | 1982 | */ |
1983 | if (up->port.type == PORT_16850) { | 1983 | if (up->port.type == PORT_16850) { |
1984 | unsigned char fctr; | 1984 | unsigned char fctr; |
1985 | 1985 | ||
1986 | serial_outp(up, UART_LCR, 0xbf); | 1986 | serial_outp(up, UART_LCR, 0xbf); |
1987 | 1987 | ||
1988 | fctr = serial_inp(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX); | 1988 | fctr = serial_inp(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX); |
1989 | serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_RX); | 1989 | serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_RX); |
1990 | serial_outp(up, UART_TRG, UART_TRG_96); | 1990 | serial_outp(up, UART_TRG, UART_TRG_96); |
1991 | serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_TX); | 1991 | serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_TX); |
1992 | serial_outp(up, UART_TRG, UART_TRG_96); | 1992 | serial_outp(up, UART_TRG, UART_TRG_96); |
1993 | 1993 | ||
1994 | serial_outp(up, UART_LCR, 0); | 1994 | serial_outp(up, UART_LCR, 0); |
1995 | } | 1995 | } |
1996 | 1996 | ||
1997 | if (is_real_interrupt(up->port.irq)) { | 1997 | if (is_real_interrupt(up->port.irq)) { |
1998 | unsigned char iir1; | 1998 | unsigned char iir1; |
1999 | /* | 1999 | /* |
2000 | * Test for UARTs that do not reassert THRE when the | 2000 | * Test for UARTs that do not reassert THRE when the |
2001 | * transmitter is idle and the interrupt has already | 2001 | * transmitter is idle and the interrupt has already |
2002 | * been cleared. Real 16550s should always reassert | 2002 | * been cleared. Real 16550s should always reassert |
2003 | * this interrupt whenever the transmitter is idle and | 2003 | * this interrupt whenever the transmitter is idle and |
2004 | * the interrupt is enabled. Delays are necessary to | 2004 | * the interrupt is enabled. Delays are necessary to |
2005 | * allow register changes to become visible. | 2005 | * allow register changes to become visible. |
2006 | */ | 2006 | */ |
2007 | spin_lock_irqsave(&up->port.lock, flags); | 2007 | spin_lock_irqsave(&up->port.lock, flags); |
2008 | if (up->port.flags & UPF_SHARE_IRQ) | 2008 | if (up->port.flags & UPF_SHARE_IRQ) |
2009 | disable_irq_nosync(up->port.irq); | 2009 | disable_irq_nosync(up->port.irq); |
2010 | 2010 | ||
2011 | wait_for_xmitr(up, UART_LSR_THRE); | 2011 | wait_for_xmitr(up, UART_LSR_THRE); |
2012 | serial_out_sync(up, UART_IER, UART_IER_THRI); | 2012 | serial_out_sync(up, UART_IER, UART_IER_THRI); |
2013 | udelay(1); /* allow THRE to set */ | 2013 | udelay(1); /* allow THRE to set */ |
2014 | iir1 = serial_in(up, UART_IIR); | 2014 | iir1 = serial_in(up, UART_IIR); |
2015 | serial_out(up, UART_IER, 0); | 2015 | serial_out(up, UART_IER, 0); |
2016 | serial_out_sync(up, UART_IER, UART_IER_THRI); | 2016 | serial_out_sync(up, UART_IER, UART_IER_THRI); |
2017 | udelay(1); /* allow a working UART time to re-assert THRE */ | 2017 | udelay(1); /* allow a working UART time to re-assert THRE */ |
2018 | iir = serial_in(up, UART_IIR); | 2018 | iir = serial_in(up, UART_IIR); |
2019 | serial_out(up, UART_IER, 0); | 2019 | serial_out(up, UART_IER, 0); |
2020 | 2020 | ||
2021 | if (up->port.flags & UPF_SHARE_IRQ) | 2021 | if (up->port.flags & UPF_SHARE_IRQ) |
2022 | enable_irq(up->port.irq); | 2022 | enable_irq(up->port.irq); |
2023 | spin_unlock_irqrestore(&up->port.lock, flags); | 2023 | spin_unlock_irqrestore(&up->port.lock, flags); |
2024 | 2024 | ||
2025 | /* | 2025 | /* |
2026 | * If the interrupt is not reasserted, setup a timer to | 2026 | * If the interrupt is not reasserted, setup a timer to |
2027 | * kick the UART on a regular basis. | 2027 | * kick the UART on a regular basis. |
2028 | */ | 2028 | */ |
2029 | if (!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) { | 2029 | if (!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) { |
2030 | up->bugs |= UART_BUG_THRE; | 2030 | up->bugs |= UART_BUG_THRE; |
2031 | pr_debug("ttyS%d - using backup timer\n", | 2031 | pr_debug("ttyS%d - using backup timer\n", |
2032 | serial_index(port)); | 2032 | serial_index(port)); |
2033 | } | 2033 | } |
2034 | } | 2034 | } |
2035 | 2035 | ||
2036 | /* | 2036 | /* |
2037 | * The above check will only give an accurate result the first time | 2037 | * The above check will only give an accurate result the first time |
2038 | * the port is opened so this value needs to be preserved. | 2038 | * the port is opened so this value needs to be preserved. |
2039 | */ | 2039 | */ |
2040 | if (up->bugs & UART_BUG_THRE) { | 2040 | if (up->bugs & UART_BUG_THRE) { |
2041 | up->timer.function = serial8250_backup_timeout; | 2041 | up->timer.function = serial8250_backup_timeout; |
2042 | up->timer.data = (unsigned long)up; | 2042 | up->timer.data = (unsigned long)up; |
2043 | mod_timer(&up->timer, jiffies + | 2043 | mod_timer(&up->timer, jiffies + |
2044 | poll_timeout(up->port.timeout) + HZ / 5); | 2044 | poll_timeout(up->port.timeout) + HZ / 5); |
2045 | } | 2045 | } |
2046 | 2046 | ||
2047 | /* | 2047 | /* |
2048 | * If the "interrupt" for this port doesn't correspond with any | 2048 | * If the "interrupt" for this port doesn't correspond with any |
2049 | * hardware interrupt, we use a timer-based system. The original | 2049 | * hardware interrupt, we use a timer-based system. The original |
2050 | * driver used to do this with IRQ0. | 2050 | * driver used to do this with IRQ0. |
2051 | */ | 2051 | */ |
2052 | if (!is_real_interrupt(up->port.irq)) { | 2052 | if (!is_real_interrupt(up->port.irq)) { |
2053 | up->timer.data = (unsigned long)up; | 2053 | up->timer.data = (unsigned long)up; |
2054 | mod_timer(&up->timer, jiffies + poll_timeout(up->port.timeout)); | 2054 | mod_timer(&up->timer, jiffies + poll_timeout(up->port.timeout)); |
2055 | } else { | 2055 | } else { |
2056 | retval = serial_link_irq_chain(up); | 2056 | retval = serial_link_irq_chain(up); |
2057 | if (retval) | 2057 | if (retval) |
2058 | return retval; | 2058 | return retval; |
2059 | } | 2059 | } |
2060 | 2060 | ||
2061 | /* | 2061 | /* |
2062 | * Now, initialize the UART | 2062 | * Now, initialize the UART |
2063 | */ | 2063 | */ |
2064 | serial_outp(up, UART_LCR, UART_LCR_WLEN8); | 2064 | serial_outp(up, UART_LCR, UART_LCR_WLEN8); |
2065 | 2065 | ||
2066 | spin_lock_irqsave(&up->port.lock, flags); | 2066 | spin_lock_irqsave(&up->port.lock, flags); |
2067 | if (up->port.flags & UPF_FOURPORT) { | 2067 | if (up->port.flags & UPF_FOURPORT) { |
2068 | if (!is_real_interrupt(up->port.irq)) | 2068 | if (!is_real_interrupt(up->port.irq)) |
2069 | up->port.mctrl |= TIOCM_OUT1; | 2069 | up->port.mctrl |= TIOCM_OUT1; |
2070 | } else | 2070 | } else |
2071 | /* | 2071 | /* |
2072 | * Most PC uarts need OUT2 raised to enable interrupts. | 2072 | * Most PC uarts need OUT2 raised to enable interrupts. |
2073 | */ | 2073 | */ |
2074 | if (is_real_interrupt(up->port.irq)) | 2074 | if (is_real_interrupt(up->port.irq)) |
2075 | up->port.mctrl |= TIOCM_OUT2; | 2075 | up->port.mctrl |= TIOCM_OUT2; |
2076 | 2076 | ||
2077 | serial8250_set_mctrl(&up->port, up->port.mctrl); | 2077 | serial8250_set_mctrl(&up->port, up->port.mctrl); |
2078 | 2078 | ||
2079 | /* | 2079 | /* |
2080 | * Do a quick test to see if we receive an | 2080 | * Do a quick test to see if we receive an |
2081 | * interrupt when we enable the TX irq. | 2081 | * interrupt when we enable the TX irq. |
2082 | */ | 2082 | */ |
2083 | serial_outp(up, UART_IER, UART_IER_THRI); | 2083 | serial_outp(up, UART_IER, UART_IER_THRI); |
2084 | lsr = serial_in(up, UART_LSR); | 2084 | lsr = serial_in(up, UART_LSR); |
2085 | iir = serial_in(up, UART_IIR); | 2085 | iir = serial_in(up, UART_IIR); |
2086 | serial_outp(up, UART_IER, 0); | 2086 | serial_outp(up, UART_IER, 0); |
2087 | 2087 | ||
2088 | if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) { | 2088 | if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) { |
2089 | if (!(up->bugs & UART_BUG_TXEN)) { | 2089 | if (!(up->bugs & UART_BUG_TXEN)) { |
2090 | up->bugs |= UART_BUG_TXEN; | 2090 | up->bugs |= UART_BUG_TXEN; |
2091 | pr_debug("ttyS%d - enabling bad tx status workarounds\n", | 2091 | pr_debug("ttyS%d - enabling bad tx status workarounds\n", |
2092 | serial_index(port)); | 2092 | serial_index(port)); |
2093 | } | 2093 | } |
2094 | } else { | 2094 | } else { |
2095 | up->bugs &= ~UART_BUG_TXEN; | 2095 | up->bugs &= ~UART_BUG_TXEN; |
2096 | } | 2096 | } |
2097 | 2097 | ||
2098 | spin_unlock_irqrestore(&up->port.lock, flags); | 2098 | spin_unlock_irqrestore(&up->port.lock, flags); |
2099 | 2099 | ||
2100 | /* | 2100 | /* |
2101 | * Clear the interrupt registers again for luck, and clear the | 2101 | * Clear the interrupt registers again for luck, and clear the |
2102 | * saved flags to avoid getting false values from polling | 2102 | * saved flags to avoid getting false values from polling |
2103 | * routines or the previous session. | 2103 | * routines or the previous session. |
2104 | */ | 2104 | */ |
2105 | serial_inp(up, UART_LSR); | 2105 | serial_inp(up, UART_LSR); |
2106 | serial_inp(up, UART_RX); | 2106 | serial_inp(up, UART_RX); |
2107 | serial_inp(up, UART_IIR); | 2107 | serial_inp(up, UART_IIR); |
2108 | serial_inp(up, UART_MSR); | 2108 | serial_inp(up, UART_MSR); |
2109 | up->lsr_saved_flags = 0; | 2109 | up->lsr_saved_flags = 0; |
2110 | up->msr_saved_flags = 0; | 2110 | up->msr_saved_flags = 0; |
2111 | 2111 | ||
2112 | /* | 2112 | /* |
2113 | * Finally, enable interrupts. Note: Modem status interrupts | 2113 | * Finally, enable interrupts. Note: Modem status interrupts |
2114 | * are set via set_termios(), which will be occurring imminently | 2114 | * are set via set_termios(), which will be occurring imminently |
2115 | * anyway, so we don't enable them here. | 2115 | * anyway, so we don't enable them here. |
2116 | */ | 2116 | */ |
2117 | up->ier = UART_IER_RLSI | UART_IER_RDI; | 2117 | up->ier = UART_IER_RLSI | UART_IER_RDI; |
2118 | serial_outp(up, UART_IER, up->ier); | 2118 | serial_outp(up, UART_IER, up->ier); |
2119 | 2119 | ||
2120 | if (up->port.flags & UPF_FOURPORT) { | 2120 | if (up->port.flags & UPF_FOURPORT) { |
2121 | unsigned int icp; | 2121 | unsigned int icp; |
2122 | /* | 2122 | /* |
2123 | * Enable interrupts on the AST Fourport board | 2123 | * Enable interrupts on the AST Fourport board |
2124 | */ | 2124 | */ |
2125 | icp = (up->port.iobase & 0xfe0) | 0x01f; | 2125 | icp = (up->port.iobase & 0xfe0) | 0x01f; |
2126 | outb_p(0x80, icp); | 2126 | outb_p(0x80, icp); |
2127 | (void) inb_p(icp); | 2127 | (void) inb_p(icp); |
2128 | } | 2128 | } |
2129 | 2129 | ||
2130 | return 0; | 2130 | return 0; |
2131 | } | 2131 | } |
2132 | 2132 | ||
2133 | static void serial8250_shutdown(struct uart_port *port) | 2133 | static void serial8250_shutdown(struct uart_port *port) |
2134 | { | 2134 | { |
2135 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 2135 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
2136 | unsigned long flags; | 2136 | unsigned long flags; |
2137 | 2137 | ||
2138 | /* | 2138 | /* |
2139 | * Disable interrupts from this port | 2139 | * Disable interrupts from this port |
2140 | */ | 2140 | */ |
2141 | up->ier = 0; | 2141 | up->ier = 0; |
2142 | serial_outp(up, UART_IER, 0); | 2142 | serial_outp(up, UART_IER, 0); |
2143 | 2143 | ||
2144 | spin_lock_irqsave(&up->port.lock, flags); | 2144 | spin_lock_irqsave(&up->port.lock, flags); |
2145 | if (up->port.flags & UPF_FOURPORT) { | 2145 | if (up->port.flags & UPF_FOURPORT) { |
2146 | /* reset interrupts on the AST Fourport board */ | 2146 | /* reset interrupts on the AST Fourport board */ |
2147 | inb((up->port.iobase & 0xfe0) | 0x1f); | 2147 | inb((up->port.iobase & 0xfe0) | 0x1f); |
2148 | up->port.mctrl |= TIOCM_OUT1; | 2148 | up->port.mctrl |= TIOCM_OUT1; |
2149 | } else | 2149 | } else |
2150 | up->port.mctrl &= ~TIOCM_OUT2; | 2150 | up->port.mctrl &= ~TIOCM_OUT2; |
2151 | 2151 | ||
2152 | serial8250_set_mctrl(&up->port, up->port.mctrl); | 2152 | serial8250_set_mctrl(&up->port, up->port.mctrl); |
2153 | spin_unlock_irqrestore(&up->port.lock, flags); | 2153 | spin_unlock_irqrestore(&up->port.lock, flags); |
2154 | 2154 | ||
2155 | /* | 2155 | /* |
2156 | * Disable break condition and FIFOs | 2156 | * Disable break condition and FIFOs |
2157 | */ | 2157 | */ |
2158 | serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC); | 2158 | serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC); |
2159 | serial8250_clear_fifos(up); | 2159 | serial8250_clear_fifos(up); |
2160 | 2160 | ||
2161 | #ifdef CONFIG_SERIAL_8250_RSA | 2161 | #ifdef CONFIG_SERIAL_8250_RSA |
2162 | /* | 2162 | /* |
2163 | * Reset the RSA board back to 115kbps compat mode. | 2163 | * Reset the RSA board back to 115kbps compat mode. |
2164 | */ | 2164 | */ |
2165 | disable_rsa(up); | 2165 | disable_rsa(up); |
2166 | #endif | 2166 | #endif |
2167 | 2167 | ||
2168 | /* | 2168 | /* |
2169 | * Read data port to reset things, and then unlink from | 2169 | * Read data port to reset things, and then unlink from |
2170 | * the IRQ chain. | 2170 | * the IRQ chain. |
2171 | */ | 2171 | */ |
2172 | (void) serial_in(up, UART_RX); | 2172 | (void) serial_in(up, UART_RX); |
2173 | 2173 | ||
2174 | del_timer_sync(&up->timer); | 2174 | del_timer_sync(&up->timer); |
2175 | up->timer.function = serial8250_timeout; | 2175 | up->timer.function = serial8250_timeout; |
2176 | if (is_real_interrupt(up->port.irq)) | 2176 | if (is_real_interrupt(up->port.irq)) |
2177 | serial_unlink_irq_chain(up); | 2177 | serial_unlink_irq_chain(up); |
2178 | } | 2178 | } |
2179 | 2179 | ||
2180 | static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int baud) | 2180 | static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int baud) |
2181 | { | 2181 | { |
2182 | unsigned int quot; | 2182 | unsigned int quot; |
2183 | 2183 | ||
2184 | /* | 2184 | /* |
2185 | * Handle magic divisors for baud rates above baud_base on | 2185 | * Handle magic divisors for baud rates above baud_base on |
2186 | * SMSC SuperIO chips. | 2186 | * SMSC SuperIO chips. |
2187 | */ | 2187 | */ |
2188 | if ((port->flags & UPF_MAGIC_MULTIPLIER) && | 2188 | if ((port->flags & UPF_MAGIC_MULTIPLIER) && |
2189 | baud == (port->uartclk/4)) | 2189 | baud == (port->uartclk/4)) |
2190 | quot = 0x8001; | 2190 | quot = 0x8001; |
2191 | else if ((port->flags & UPF_MAGIC_MULTIPLIER) && | 2191 | else if ((port->flags & UPF_MAGIC_MULTIPLIER) && |
2192 | baud == (port->uartclk/8)) | 2192 | baud == (port->uartclk/8)) |
2193 | quot = 0x8002; | 2193 | quot = 0x8002; |
2194 | else | 2194 | else |
2195 | quot = uart_get_divisor(port, baud); | 2195 | quot = uart_get_divisor(port, baud); |
2196 | 2196 | ||
2197 | return quot; | 2197 | return quot; |
2198 | } | 2198 | } |
2199 | 2199 | ||
2200 | static void | 2200 | static void |
2201 | serial8250_set_termios(struct uart_port *port, struct ktermios *termios, | 2201 | serial8250_set_termios(struct uart_port *port, struct ktermios *termios, |
2202 | struct ktermios *old) | 2202 | struct ktermios *old) |
2203 | { | 2203 | { |
2204 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 2204 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
2205 | unsigned char cval, fcr = 0; | 2205 | unsigned char cval, fcr = 0; |
2206 | unsigned long flags; | 2206 | unsigned long flags; |
2207 | unsigned int baud, quot; | 2207 | unsigned int baud, quot; |
2208 | 2208 | ||
2209 | switch (termios->c_cflag & CSIZE) { | 2209 | switch (termios->c_cflag & CSIZE) { |
2210 | case CS5: | 2210 | case CS5: |
2211 | cval = UART_LCR_WLEN5; | 2211 | cval = UART_LCR_WLEN5; |
2212 | break; | 2212 | break; |
2213 | case CS6: | 2213 | case CS6: |
2214 | cval = UART_LCR_WLEN6; | 2214 | cval = UART_LCR_WLEN6; |
2215 | break; | 2215 | break; |
2216 | case CS7: | 2216 | case CS7: |
2217 | cval = UART_LCR_WLEN7; | 2217 | cval = UART_LCR_WLEN7; |
2218 | break; | 2218 | break; |
2219 | default: | 2219 | default: |
2220 | case CS8: | 2220 | case CS8: |
2221 | cval = UART_LCR_WLEN8; | 2221 | cval = UART_LCR_WLEN8; |
2222 | break; | 2222 | break; |
2223 | } | 2223 | } |
2224 | 2224 | ||
2225 | if (termios->c_cflag & CSTOPB) | 2225 | if (termios->c_cflag & CSTOPB) |
2226 | cval |= UART_LCR_STOP; | 2226 | cval |= UART_LCR_STOP; |
2227 | if (termios->c_cflag & PARENB) | 2227 | if (termios->c_cflag & PARENB) |
2228 | cval |= UART_LCR_PARITY; | 2228 | cval |= UART_LCR_PARITY; |
2229 | if (!(termios->c_cflag & PARODD)) | 2229 | if (!(termios->c_cflag & PARODD)) |
2230 | cval |= UART_LCR_EPAR; | 2230 | cval |= UART_LCR_EPAR; |
2231 | #ifdef CMSPAR | 2231 | #ifdef CMSPAR |
2232 | if (termios->c_cflag & CMSPAR) | 2232 | if (termios->c_cflag & CMSPAR) |
2233 | cval |= UART_LCR_SPAR; | 2233 | cval |= UART_LCR_SPAR; |
2234 | #endif | 2234 | #endif |
2235 | 2235 | ||
2236 | /* | 2236 | /* |
2237 | * Ask the core to calculate the divisor for us. | 2237 | * Ask the core to calculate the divisor for us. |
2238 | */ | 2238 | */ |
2239 | baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); | 2239 | baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); |
2240 | quot = serial8250_get_divisor(port, baud); | 2240 | quot = serial8250_get_divisor(port, baud); |
2241 | 2241 | ||
2242 | /* | 2242 | /* |
2243 | * Oxford Semi 952 rev B workaround | 2243 | * Oxford Semi 952 rev B workaround |
2244 | */ | 2244 | */ |
2245 | if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0) | 2245 | if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0) |
2246 | quot++; | 2246 | quot++; |
2247 | 2247 | ||
2248 | if (up->capabilities & UART_CAP_FIFO && up->port.fifosize > 1) { | 2248 | if (up->capabilities & UART_CAP_FIFO && up->port.fifosize > 1) { |
2249 | if (baud < 2400) | 2249 | if (baud < 2400) |
2250 | fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1; | 2250 | fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1; |
2251 | else | 2251 | else |
2252 | fcr = uart_config[up->port.type].fcr; | 2252 | fcr = uart_config[up->port.type].fcr; |
2253 | } | 2253 | } |
2254 | 2254 | ||
2255 | /* | 2255 | /* |
2256 | * MCR-based auto flow control. When AFE is enabled, RTS will be | 2256 | * MCR-based auto flow control. When AFE is enabled, RTS will be |
2257 | * deasserted when the receive FIFO contains more characters than | 2257 | * deasserted when the receive FIFO contains more characters than |
2258 | * the trigger, or the MCR RTS bit is cleared. In the case where | 2258 | * the trigger, or the MCR RTS bit is cleared. In the case where |
2259 | * the remote UART is not using CTS auto flow control, we must | 2259 | * the remote UART is not using CTS auto flow control, we must |
2260 | * have sufficient FIFO entries for the latency of the remote | 2260 | * have sufficient FIFO entries for the latency of the remote |
2261 | * UART to respond. IOW, at least 32 bytes of FIFO. | 2261 | * UART to respond. IOW, at least 32 bytes of FIFO. |
2262 | */ | 2262 | */ |
2263 | if (up->capabilities & UART_CAP_AFE && up->port.fifosize >= 32) { | 2263 | if (up->capabilities & UART_CAP_AFE && up->port.fifosize >= 32) { |
2264 | up->mcr &= ~UART_MCR_AFE; | 2264 | up->mcr &= ~UART_MCR_AFE; |
2265 | if (termios->c_cflag & CRTSCTS) | 2265 | if (termios->c_cflag & CRTSCTS) |
2266 | up->mcr |= UART_MCR_AFE; | 2266 | up->mcr |= UART_MCR_AFE; |
2267 | } | 2267 | } |
2268 | 2268 | ||
2269 | /* | 2269 | /* |
2270 | * Ok, we're now changing the port state. Do it with | 2270 | * Ok, we're now changing the port state. Do it with |
2271 | * interrupts disabled. | 2271 | * interrupts disabled. |
2272 | */ | 2272 | */ |
2273 | spin_lock_irqsave(&up->port.lock, flags); | 2273 | spin_lock_irqsave(&up->port.lock, flags); |
2274 | 2274 | ||
2275 | /* | 2275 | /* |
2276 | * Update the per-port timeout. | 2276 | * Update the per-port timeout. |
2277 | */ | 2277 | */ |
2278 | uart_update_timeout(port, termios->c_cflag, baud); | 2278 | uart_update_timeout(port, termios->c_cflag, baud); |
2279 | 2279 | ||
2280 | up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; | 2280 | up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; |
2281 | if (termios->c_iflag & INPCK) | 2281 | if (termios->c_iflag & INPCK) |
2282 | up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE; | 2282 | up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE; |
2283 | if (termios->c_iflag & (BRKINT | PARMRK)) | 2283 | if (termios->c_iflag & (BRKINT | PARMRK)) |
2284 | up->port.read_status_mask |= UART_LSR_BI; | 2284 | up->port.read_status_mask |= UART_LSR_BI; |
2285 | 2285 | ||
2286 | /* | 2286 | /* |
2287 | * Characteres to ignore | 2287 | * Characteres to ignore |
2288 | */ | 2288 | */ |
2289 | up->port.ignore_status_mask = 0; | 2289 | up->port.ignore_status_mask = 0; |
2290 | if (termios->c_iflag & IGNPAR) | 2290 | if (termios->c_iflag & IGNPAR) |
2291 | up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; | 2291 | up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; |
2292 | if (termios->c_iflag & IGNBRK) { | 2292 | if (termios->c_iflag & IGNBRK) { |
2293 | up->port.ignore_status_mask |= UART_LSR_BI; | 2293 | up->port.ignore_status_mask |= UART_LSR_BI; |
2294 | /* | 2294 | /* |
2295 | * If we're ignoring parity and break indicators, | 2295 | * If we're ignoring parity and break indicators, |
2296 | * ignore overruns too (for real raw support). | 2296 | * ignore overruns too (for real raw support). |
2297 | */ | 2297 | */ |
2298 | if (termios->c_iflag & IGNPAR) | 2298 | if (termios->c_iflag & IGNPAR) |
2299 | up->port.ignore_status_mask |= UART_LSR_OE; | 2299 | up->port.ignore_status_mask |= UART_LSR_OE; |
2300 | } | 2300 | } |
2301 | 2301 | ||
2302 | /* | 2302 | /* |
2303 | * ignore all characters if CREAD is not set | 2303 | * ignore all characters if CREAD is not set |
2304 | */ | 2304 | */ |
2305 | if ((termios->c_cflag & CREAD) == 0) | 2305 | if ((termios->c_cflag & CREAD) == 0) |
2306 | up->port.ignore_status_mask |= UART_LSR_DR; | 2306 | up->port.ignore_status_mask |= UART_LSR_DR; |
2307 | 2307 | ||
2308 | /* | 2308 | /* |
2309 | * CTS flow control flag and modem status interrupts | 2309 | * CTS flow control flag and modem status interrupts |
2310 | */ | 2310 | */ |
2311 | up->ier &= ~UART_IER_MSI; | 2311 | up->ier &= ~UART_IER_MSI; |
2312 | if (!(up->bugs & UART_BUG_NOMSR) && | 2312 | if (!(up->bugs & UART_BUG_NOMSR) && |
2313 | UART_ENABLE_MS(&up->port, termios->c_cflag)) | 2313 | UART_ENABLE_MS(&up->port, termios->c_cflag)) |
2314 | up->ier |= UART_IER_MSI; | 2314 | up->ier |= UART_IER_MSI; |
2315 | if (up->capabilities & UART_CAP_UUE) | 2315 | if (up->capabilities & UART_CAP_UUE) |
2316 | up->ier |= UART_IER_UUE | UART_IER_RTOIE; | 2316 | up->ier |= UART_IER_UUE | UART_IER_RTOIE; |
2317 | 2317 | ||
2318 | serial_out(up, UART_IER, up->ier); | 2318 | serial_out(up, UART_IER, up->ier); |
2319 | 2319 | ||
2320 | if (up->capabilities & UART_CAP_EFR) { | 2320 | if (up->capabilities & UART_CAP_EFR) { |
2321 | unsigned char efr = 0; | 2321 | unsigned char efr = 0; |
2322 | /* | 2322 | /* |
2323 | * TI16C752/Startech hardware flow control. FIXME: | 2323 | * TI16C752/Startech hardware flow control. FIXME: |
2324 | * - TI16C752 requires control thresholds to be set. | 2324 | * - TI16C752 requires control thresholds to be set. |
2325 | * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled. | 2325 | * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled. |
2326 | */ | 2326 | */ |
2327 | if (termios->c_cflag & CRTSCTS) | 2327 | if (termios->c_cflag & CRTSCTS) |
2328 | efr |= UART_EFR_CTS; | 2328 | efr |= UART_EFR_CTS; |
2329 | 2329 | ||
2330 | serial_outp(up, UART_LCR, 0xBF); | 2330 | serial_outp(up, UART_LCR, 0xBF); |
2331 | serial_outp(up, UART_EFR, efr); | 2331 | serial_outp(up, UART_EFR, efr); |
2332 | } | 2332 | } |
2333 | 2333 | ||
2334 | #ifdef CONFIG_ARCH_OMAP | 2334 | #ifdef CONFIG_ARCH_OMAP |
2335 | /* Workaround to enable 115200 baud on OMAP1510 internal ports */ | 2335 | /* Workaround to enable 115200 baud on OMAP1510 internal ports */ |
2336 | if (cpu_is_omap1510() && is_omap_port(up)) { | 2336 | if (cpu_is_omap1510() && is_omap_port(up)) { |
2337 | if (baud == 115200) { | 2337 | if (baud == 115200) { |
2338 | quot = 1; | 2338 | quot = 1; |
2339 | serial_out(up, UART_OMAP_OSC_12M_SEL, 1); | 2339 | serial_out(up, UART_OMAP_OSC_12M_SEL, 1); |
2340 | } else | 2340 | } else |
2341 | serial_out(up, UART_OMAP_OSC_12M_SEL, 0); | 2341 | serial_out(up, UART_OMAP_OSC_12M_SEL, 0); |
2342 | } | 2342 | } |
2343 | #endif | 2343 | #endif |
2344 | 2344 | ||
2345 | if (up->capabilities & UART_NATSEMI) { | 2345 | if (up->capabilities & UART_NATSEMI) { |
2346 | /* Switch to bank 2 not bank 1, to avoid resetting EXCR2 */ | 2346 | /* Switch to bank 2 not bank 1, to avoid resetting EXCR2 */ |
2347 | serial_outp(up, UART_LCR, 0xe0); | 2347 | serial_outp(up, UART_LCR, 0xe0); |
2348 | } else { | 2348 | } else { |
2349 | serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */ | 2349 | serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */ |
2350 | } | 2350 | } |
2351 | 2351 | ||
2352 | serial_dl_write(up, quot); | 2352 | serial_dl_write(up, quot); |
2353 | 2353 | ||
2354 | /* | 2354 | /* |
2355 | * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR | 2355 | * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR |
2356 | * is written without DLAB set, this mode will be disabled. | 2356 | * is written without DLAB set, this mode will be disabled. |
2357 | */ | 2357 | */ |
2358 | if (up->port.type == PORT_16750) | 2358 | if (up->port.type == PORT_16750) |
2359 | serial_outp(up, UART_FCR, fcr); | 2359 | serial_outp(up, UART_FCR, fcr); |
2360 | 2360 | ||
2361 | serial_outp(up, UART_LCR, cval); /* reset DLAB */ | 2361 | serial_outp(up, UART_LCR, cval); /* reset DLAB */ |
2362 | up->lcr = cval; /* Save LCR */ | 2362 | up->lcr = cval; /* Save LCR */ |
2363 | if (up->port.type != PORT_16750) { | 2363 | if (up->port.type != PORT_16750) { |
2364 | if (fcr & UART_FCR_ENABLE_FIFO) { | 2364 | if (fcr & UART_FCR_ENABLE_FIFO) { |
2365 | /* emulated UARTs (Lucent Venus 167x) need two steps */ | 2365 | /* emulated UARTs (Lucent Venus 167x) need two steps */ |
2366 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); | 2366 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); |
2367 | } | 2367 | } |
2368 | serial_outp(up, UART_FCR, fcr); /* set fcr */ | 2368 | serial_outp(up, UART_FCR, fcr); /* set fcr */ |
2369 | } | 2369 | } |
2370 | serial8250_set_mctrl(&up->port, up->port.mctrl); | 2370 | serial8250_set_mctrl(&up->port, up->port.mctrl); |
2371 | spin_unlock_irqrestore(&up->port.lock, flags); | 2371 | spin_unlock_irqrestore(&up->port.lock, flags); |
2372 | /* Don't rewrite B0 */ | 2372 | /* Don't rewrite B0 */ |
2373 | if (tty_termios_baud_rate(termios)) | 2373 | if (tty_termios_baud_rate(termios)) |
2374 | tty_termios_encode_baud_rate(termios, baud, baud); | 2374 | tty_termios_encode_baud_rate(termios, baud, baud); |
2375 | } | 2375 | } |
2376 | 2376 | ||
2377 | static void | 2377 | static void |
2378 | serial8250_pm(struct uart_port *port, unsigned int state, | 2378 | serial8250_pm(struct uart_port *port, unsigned int state, |
2379 | unsigned int oldstate) | 2379 | unsigned int oldstate) |
2380 | { | 2380 | { |
2381 | struct uart_8250_port *p = (struct uart_8250_port *)port; | 2381 | struct uart_8250_port *p = (struct uart_8250_port *)port; |
2382 | 2382 | ||
2383 | serial8250_set_sleep(p, state != 0); | 2383 | serial8250_set_sleep(p, state != 0); |
2384 | 2384 | ||
2385 | if (p->pm) | 2385 | if (p->pm) |
2386 | p->pm(port, state, oldstate); | 2386 | p->pm(port, state, oldstate); |
2387 | } | 2387 | } |
2388 | 2388 | ||
2389 | static unsigned int serial8250_port_size(struct uart_8250_port *pt) | 2389 | static unsigned int serial8250_port_size(struct uart_8250_port *pt) |
2390 | { | 2390 | { |
2391 | if (pt->port.iotype == UPIO_AU) | 2391 | if (pt->port.iotype == UPIO_AU) |
2392 | return 0x100000; | 2392 | return 0x100000; |
2393 | #ifdef CONFIG_ARCH_OMAP | 2393 | #ifdef CONFIG_ARCH_OMAP |
2394 | if (is_omap_port(pt)) | 2394 | if (is_omap_port(pt)) |
2395 | return 0x16 << pt->port.regshift; | 2395 | return 0x16 << pt->port.regshift; |
2396 | #endif | 2396 | #endif |
2397 | return 8 << pt->port.regshift; | 2397 | return 8 << pt->port.regshift; |
2398 | } | 2398 | } |
2399 | 2399 | ||
2400 | /* | 2400 | /* |
2401 | * Resource handling. | 2401 | * Resource handling. |
2402 | */ | 2402 | */ |
2403 | static int serial8250_request_std_resource(struct uart_8250_port *up) | 2403 | static int serial8250_request_std_resource(struct uart_8250_port *up) |
2404 | { | 2404 | { |
2405 | unsigned int size = serial8250_port_size(up); | 2405 | unsigned int size = serial8250_port_size(up); |
2406 | int ret = 0; | 2406 | int ret = 0; |
2407 | 2407 | ||
2408 | switch (up->port.iotype) { | 2408 | switch (up->port.iotype) { |
2409 | case UPIO_AU: | 2409 | case UPIO_AU: |
2410 | case UPIO_TSI: | 2410 | case UPIO_TSI: |
2411 | case UPIO_MEM32: | 2411 | case UPIO_MEM32: |
2412 | case UPIO_MEM: | 2412 | case UPIO_MEM: |
2413 | case UPIO_DWAPB: | 2413 | case UPIO_DWAPB: |
2414 | if (!up->port.mapbase) | 2414 | if (!up->port.mapbase) |
2415 | break; | 2415 | break; |
2416 | 2416 | ||
2417 | if (!request_mem_region(up->port.mapbase, size, "serial")) { | 2417 | if (!request_mem_region(up->port.mapbase, size, "serial")) { |
2418 | ret = -EBUSY; | 2418 | ret = -EBUSY; |
2419 | break; | 2419 | break; |
2420 | } | 2420 | } |
2421 | 2421 | ||
2422 | if (up->port.flags & UPF_IOREMAP) { | 2422 | if (up->port.flags & UPF_IOREMAP) { |
2423 | up->port.membase = ioremap_nocache(up->port.mapbase, | 2423 | up->port.membase = ioremap_nocache(up->port.mapbase, |
2424 | size); | 2424 | size); |
2425 | if (!up->port.membase) { | 2425 | if (!up->port.membase) { |
2426 | release_mem_region(up->port.mapbase, size); | 2426 | release_mem_region(up->port.mapbase, size); |
2427 | ret = -ENOMEM; | 2427 | ret = -ENOMEM; |
2428 | } | 2428 | } |
2429 | } | 2429 | } |
2430 | break; | 2430 | break; |
2431 | 2431 | ||
2432 | case UPIO_HUB6: | 2432 | case UPIO_HUB6: |
2433 | case UPIO_PORT: | 2433 | case UPIO_PORT: |
2434 | if (!request_region(up->port.iobase, size, "serial")) | 2434 | if (!request_region(up->port.iobase, size, "serial")) |
2435 | ret = -EBUSY; | 2435 | ret = -EBUSY; |
2436 | break; | 2436 | break; |
2437 | } | 2437 | } |
2438 | return ret; | 2438 | return ret; |
2439 | } | 2439 | } |
2440 | 2440 | ||
2441 | static void serial8250_release_std_resource(struct uart_8250_port *up) | 2441 | static void serial8250_release_std_resource(struct uart_8250_port *up) |
2442 | { | 2442 | { |
2443 | unsigned int size = serial8250_port_size(up); | 2443 | unsigned int size = serial8250_port_size(up); |
2444 | 2444 | ||
2445 | switch (up->port.iotype) { | 2445 | switch (up->port.iotype) { |
2446 | case UPIO_AU: | 2446 | case UPIO_AU: |
2447 | case UPIO_TSI: | 2447 | case UPIO_TSI: |
2448 | case UPIO_MEM32: | 2448 | case UPIO_MEM32: |
2449 | case UPIO_MEM: | 2449 | case UPIO_MEM: |
2450 | case UPIO_DWAPB: | 2450 | case UPIO_DWAPB: |
2451 | if (!up->port.mapbase) | 2451 | if (!up->port.mapbase) |
2452 | break; | 2452 | break; |
2453 | 2453 | ||
2454 | if (up->port.flags & UPF_IOREMAP) { | 2454 | if (up->port.flags & UPF_IOREMAP) { |
2455 | iounmap(up->port.membase); | 2455 | iounmap(up->port.membase); |
2456 | up->port.membase = NULL; | 2456 | up->port.membase = NULL; |
2457 | } | 2457 | } |
2458 | 2458 | ||
2459 | release_mem_region(up->port.mapbase, size); | 2459 | release_mem_region(up->port.mapbase, size); |
2460 | break; | 2460 | break; |
2461 | 2461 | ||
2462 | case UPIO_HUB6: | 2462 | case UPIO_HUB6: |
2463 | case UPIO_PORT: | 2463 | case UPIO_PORT: |
2464 | release_region(up->port.iobase, size); | 2464 | release_region(up->port.iobase, size); |
2465 | break; | 2465 | break; |
2466 | } | 2466 | } |
2467 | } | 2467 | } |
2468 | 2468 | ||
2469 | static int serial8250_request_rsa_resource(struct uart_8250_port *up) | 2469 | static int serial8250_request_rsa_resource(struct uart_8250_port *up) |
2470 | { | 2470 | { |
2471 | unsigned long start = UART_RSA_BASE << up->port.regshift; | 2471 | unsigned long start = UART_RSA_BASE << up->port.regshift; |
2472 | unsigned int size = 8 << up->port.regshift; | 2472 | unsigned int size = 8 << up->port.regshift; |
2473 | int ret = -EINVAL; | 2473 | int ret = -EINVAL; |
2474 | 2474 | ||
2475 | switch (up->port.iotype) { | 2475 | switch (up->port.iotype) { |
2476 | case UPIO_HUB6: | 2476 | case UPIO_HUB6: |
2477 | case UPIO_PORT: | 2477 | case UPIO_PORT: |
2478 | start += up->port.iobase; | 2478 | start += up->port.iobase; |
2479 | if (request_region(start, size, "serial-rsa")) | 2479 | if (request_region(start, size, "serial-rsa")) |
2480 | ret = 0; | 2480 | ret = 0; |
2481 | else | 2481 | else |
2482 | ret = -EBUSY; | 2482 | ret = -EBUSY; |
2483 | break; | 2483 | break; |
2484 | } | 2484 | } |
2485 | 2485 | ||
2486 | return ret; | 2486 | return ret; |
2487 | } | 2487 | } |
2488 | 2488 | ||
2489 | static void serial8250_release_rsa_resource(struct uart_8250_port *up) | 2489 | static void serial8250_release_rsa_resource(struct uart_8250_port *up) |
2490 | { | 2490 | { |
2491 | unsigned long offset = UART_RSA_BASE << up->port.regshift; | 2491 | unsigned long offset = UART_RSA_BASE << up->port.regshift; |
2492 | unsigned int size = 8 << up->port.regshift; | 2492 | unsigned int size = 8 << up->port.regshift; |
2493 | 2493 | ||
2494 | switch (up->port.iotype) { | 2494 | switch (up->port.iotype) { |
2495 | case UPIO_HUB6: | 2495 | case UPIO_HUB6: |
2496 | case UPIO_PORT: | 2496 | case UPIO_PORT: |
2497 | release_region(up->port.iobase + offset, size); | 2497 | release_region(up->port.iobase + offset, size); |
2498 | break; | 2498 | break; |
2499 | } | 2499 | } |
2500 | } | 2500 | } |
2501 | 2501 | ||
2502 | static void serial8250_release_port(struct uart_port *port) | 2502 | static void serial8250_release_port(struct uart_port *port) |
2503 | { | 2503 | { |
2504 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 2504 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
2505 | 2505 | ||
2506 | serial8250_release_std_resource(up); | 2506 | serial8250_release_std_resource(up); |
2507 | if (up->port.type == PORT_RSA) | 2507 | if (up->port.type == PORT_RSA) |
2508 | serial8250_release_rsa_resource(up); | 2508 | serial8250_release_rsa_resource(up); |
2509 | } | 2509 | } |
2510 | 2510 | ||
2511 | static int serial8250_request_port(struct uart_port *port) | 2511 | static int serial8250_request_port(struct uart_port *port) |
2512 | { | 2512 | { |
2513 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 2513 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
2514 | int ret = 0; | 2514 | int ret = 0; |
2515 | 2515 | ||
2516 | ret = serial8250_request_std_resource(up); | 2516 | ret = serial8250_request_std_resource(up); |
2517 | if (ret == 0 && up->port.type == PORT_RSA) { | 2517 | if (ret == 0 && up->port.type == PORT_RSA) { |
2518 | ret = serial8250_request_rsa_resource(up); | 2518 | ret = serial8250_request_rsa_resource(up); |
2519 | if (ret < 0) | 2519 | if (ret < 0) |
2520 | serial8250_release_std_resource(up); | 2520 | serial8250_release_std_resource(up); |
2521 | } | 2521 | } |
2522 | 2522 | ||
2523 | return ret; | 2523 | return ret; |
2524 | } | 2524 | } |
2525 | 2525 | ||
2526 | static void serial8250_config_port(struct uart_port *port, int flags) | 2526 | static void serial8250_config_port(struct uart_port *port, int flags) |
2527 | { | 2527 | { |
2528 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 2528 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
2529 | int probeflags = PROBE_ANY; | 2529 | int probeflags = PROBE_ANY; |
2530 | int ret; | 2530 | int ret; |
2531 | 2531 | ||
2532 | /* | 2532 | /* |
2533 | * Find the region that we can probe for. This in turn | 2533 | * Find the region that we can probe for. This in turn |
2534 | * tells us whether we can probe for the type of port. | 2534 | * tells us whether we can probe for the type of port. |
2535 | */ | 2535 | */ |
2536 | ret = serial8250_request_std_resource(up); | 2536 | ret = serial8250_request_std_resource(up); |
2537 | if (ret < 0) | 2537 | if (ret < 0) |
2538 | return; | 2538 | return; |
2539 | 2539 | ||
2540 | ret = serial8250_request_rsa_resource(up); | 2540 | ret = serial8250_request_rsa_resource(up); |
2541 | if (ret < 0) | 2541 | if (ret < 0) |
2542 | probeflags &= ~PROBE_RSA; | 2542 | probeflags &= ~PROBE_RSA; |
2543 | 2543 | ||
2544 | if (flags & UART_CONFIG_TYPE) | 2544 | if (flags & UART_CONFIG_TYPE) |
2545 | autoconfig(up, probeflags); | 2545 | autoconfig(up, probeflags); |
2546 | if (up->port.type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ) | 2546 | if (up->port.type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ) |
2547 | autoconfig_irq(up); | 2547 | autoconfig_irq(up); |
2548 | 2548 | ||
2549 | if (up->port.type != PORT_RSA && probeflags & PROBE_RSA) | 2549 | if (up->port.type != PORT_RSA && probeflags & PROBE_RSA) |
2550 | serial8250_release_rsa_resource(up); | 2550 | serial8250_release_rsa_resource(up); |
2551 | if (up->port.type == PORT_UNKNOWN) | 2551 | if (up->port.type == PORT_UNKNOWN) |
2552 | serial8250_release_std_resource(up); | 2552 | serial8250_release_std_resource(up); |
2553 | } | 2553 | } |
2554 | 2554 | ||
2555 | static int | 2555 | static int |
2556 | serial8250_verify_port(struct uart_port *port, struct serial_struct *ser) | 2556 | serial8250_verify_port(struct uart_port *port, struct serial_struct *ser) |
2557 | { | 2557 | { |
2558 | if (ser->irq >= nr_irqs || ser->irq < 0 || | 2558 | if (ser->irq >= nr_irqs || ser->irq < 0 || |
2559 | ser->baud_base < 9600 || ser->type < PORT_UNKNOWN || | 2559 | ser->baud_base < 9600 || ser->type < PORT_UNKNOWN || |
2560 | ser->type >= ARRAY_SIZE(uart_config) || ser->type == PORT_CIRRUS || | 2560 | ser->type >= ARRAY_SIZE(uart_config) || ser->type == PORT_CIRRUS || |
2561 | ser->type == PORT_STARTECH) | 2561 | ser->type == PORT_STARTECH) |
2562 | return -EINVAL; | 2562 | return -EINVAL; |
2563 | return 0; | 2563 | return 0; |
2564 | } | 2564 | } |
2565 | 2565 | ||
2566 | static const char * | 2566 | static const char * |
2567 | serial8250_type(struct uart_port *port) | 2567 | serial8250_type(struct uart_port *port) |
2568 | { | 2568 | { |
2569 | int type = port->type; | 2569 | int type = port->type; |
2570 | 2570 | ||
2571 | if (type >= ARRAY_SIZE(uart_config)) | 2571 | if (type >= ARRAY_SIZE(uart_config)) |
2572 | type = 0; | 2572 | type = 0; |
2573 | return uart_config[type].name; | 2573 | return uart_config[type].name; |
2574 | } | 2574 | } |
2575 | 2575 | ||
2576 | static struct uart_ops serial8250_pops = { | 2576 | static struct uart_ops serial8250_pops = { |
2577 | .tx_empty = serial8250_tx_empty, | 2577 | .tx_empty = serial8250_tx_empty, |
2578 | .set_mctrl = serial8250_set_mctrl, | 2578 | .set_mctrl = serial8250_set_mctrl, |
2579 | .get_mctrl = serial8250_get_mctrl, | 2579 | .get_mctrl = serial8250_get_mctrl, |
2580 | .stop_tx = serial8250_stop_tx, | 2580 | .stop_tx = serial8250_stop_tx, |
2581 | .start_tx = serial8250_start_tx, | 2581 | .start_tx = serial8250_start_tx, |
2582 | .stop_rx = serial8250_stop_rx, | 2582 | .stop_rx = serial8250_stop_rx, |
2583 | .enable_ms = serial8250_enable_ms, | 2583 | .enable_ms = serial8250_enable_ms, |
2584 | .break_ctl = serial8250_break_ctl, | 2584 | .break_ctl = serial8250_break_ctl, |
2585 | .startup = serial8250_startup, | 2585 | .startup = serial8250_startup, |
2586 | .shutdown = serial8250_shutdown, | 2586 | .shutdown = serial8250_shutdown, |
2587 | .set_termios = serial8250_set_termios, | 2587 | .set_termios = serial8250_set_termios, |
2588 | .pm = serial8250_pm, | 2588 | .pm = serial8250_pm, |
2589 | .type = serial8250_type, | 2589 | .type = serial8250_type, |
2590 | .release_port = serial8250_release_port, | 2590 | .release_port = serial8250_release_port, |
2591 | .request_port = serial8250_request_port, | 2591 | .request_port = serial8250_request_port, |
2592 | .config_port = serial8250_config_port, | 2592 | .config_port = serial8250_config_port, |
2593 | .verify_port = serial8250_verify_port, | 2593 | .verify_port = serial8250_verify_port, |
2594 | #ifdef CONFIG_CONSOLE_POLL | 2594 | #ifdef CONFIG_CONSOLE_POLL |
2595 | .poll_get_char = serial8250_get_poll_char, | 2595 | .poll_get_char = serial8250_get_poll_char, |
2596 | .poll_put_char = serial8250_put_poll_char, | 2596 | .poll_put_char = serial8250_put_poll_char, |
2597 | #endif | 2597 | #endif |
2598 | }; | 2598 | }; |
2599 | 2599 | ||
2600 | static struct uart_8250_port serial8250_ports[UART_NR]; | 2600 | static struct uart_8250_port serial8250_ports[UART_NR]; |
2601 | 2601 | ||
2602 | static void __init serial8250_isa_init_ports(void) | 2602 | static void __init serial8250_isa_init_ports(void) |
2603 | { | 2603 | { |
2604 | struct uart_8250_port *up; | 2604 | struct uart_8250_port *up; |
2605 | static int first = 1; | 2605 | static int first = 1; |
2606 | int i; | 2606 | int i; |
2607 | 2607 | ||
2608 | if (!first) | 2608 | if (!first) |
2609 | return; | 2609 | return; |
2610 | first = 0; | 2610 | first = 0; |
2611 | 2611 | ||
2612 | for (i = 0; i < nr_uarts; i++) { | 2612 | for (i = 0; i < nr_uarts; i++) { |
2613 | struct uart_8250_port *up = &serial8250_ports[i]; | 2613 | struct uart_8250_port *up = &serial8250_ports[i]; |
2614 | 2614 | ||
2615 | up->port.line = i; | 2615 | up->port.line = i; |
2616 | spin_lock_init(&up->port.lock); | 2616 | spin_lock_init(&up->port.lock); |
2617 | 2617 | ||
2618 | init_timer(&up->timer); | 2618 | init_timer(&up->timer); |
2619 | up->timer.function = serial8250_timeout; | 2619 | up->timer.function = serial8250_timeout; |
2620 | 2620 | ||
2621 | /* | 2621 | /* |
2622 | * ALPHA_KLUDGE_MCR needs to be killed. | 2622 | * ALPHA_KLUDGE_MCR needs to be killed. |
2623 | */ | 2623 | */ |
2624 | up->mcr_mask = ~ALPHA_KLUDGE_MCR; | 2624 | up->mcr_mask = ~ALPHA_KLUDGE_MCR; |
2625 | up->mcr_force = ALPHA_KLUDGE_MCR; | 2625 | up->mcr_force = ALPHA_KLUDGE_MCR; |
2626 | 2626 | ||
2627 | up->port.ops = &serial8250_pops; | 2627 | up->port.ops = &serial8250_pops; |
2628 | } | 2628 | } |
2629 | 2629 | ||
2630 | for (i = 0, up = serial8250_ports; | 2630 | for (i = 0, up = serial8250_ports; |
2631 | i < ARRAY_SIZE(old_serial_port) && i < nr_uarts; | 2631 | i < ARRAY_SIZE(old_serial_port) && i < nr_uarts; |
2632 | i++, up++) { | 2632 | i++, up++) { |
2633 | up->port.iobase = old_serial_port[i].port; | 2633 | up->port.iobase = old_serial_port[i].port; |
2634 | up->port.irq = irq_canonicalize(old_serial_port[i].irq); | 2634 | up->port.irq = irq_canonicalize(old_serial_port[i].irq); |
2635 | up->port.uartclk = old_serial_port[i].baud_base * 16; | 2635 | up->port.uartclk = old_serial_port[i].baud_base * 16; |
2636 | up->port.flags = old_serial_port[i].flags; | 2636 | up->port.flags = old_serial_port[i].flags; |
2637 | up->port.hub6 = old_serial_port[i].hub6; | 2637 | up->port.hub6 = old_serial_port[i].hub6; |
2638 | up->port.membase = old_serial_port[i].iomem_base; | 2638 | up->port.membase = old_serial_port[i].iomem_base; |
2639 | up->port.iotype = old_serial_port[i].io_type; | 2639 | up->port.iotype = old_serial_port[i].io_type; |
2640 | up->port.regshift = old_serial_port[i].iomem_reg_shift; | 2640 | up->port.regshift = old_serial_port[i].iomem_reg_shift; |
2641 | set_io_from_upio(&up->port); | 2641 | set_io_from_upio(&up->port); |
2642 | if (share_irqs) | 2642 | if (share_irqs) |
2643 | up->port.flags |= UPF_SHARE_IRQ; | 2643 | up->port.flags |= UPF_SHARE_IRQ; |
2644 | } | 2644 | } |
2645 | } | 2645 | } |
2646 | 2646 | ||
2647 | static void __init | 2647 | static void __init |
2648 | serial8250_register_ports(struct uart_driver *drv, struct device *dev) | 2648 | serial8250_register_ports(struct uart_driver *drv, struct device *dev) |
2649 | { | 2649 | { |
2650 | int i; | 2650 | int i; |
2651 | 2651 | ||
2652 | serial8250_isa_init_ports(); | 2652 | serial8250_isa_init_ports(); |
2653 | 2653 | ||
2654 | for (i = 0; i < nr_uarts; i++) { | 2654 | for (i = 0; i < nr_uarts; i++) { |
2655 | struct uart_8250_port *up = &serial8250_ports[i]; | 2655 | struct uart_8250_port *up = &serial8250_ports[i]; |
2656 | 2656 | ||
2657 | up->port.dev = dev; | 2657 | up->port.dev = dev; |
2658 | uart_add_one_port(drv, &up->port); | 2658 | uart_add_one_port(drv, &up->port); |
2659 | } | 2659 | } |
2660 | } | 2660 | } |
2661 | 2661 | ||
2662 | #ifdef CONFIG_SERIAL_8250_CONSOLE | 2662 | #ifdef CONFIG_SERIAL_8250_CONSOLE |
2663 | 2663 | ||
2664 | static void serial8250_console_putchar(struct uart_port *port, int ch) | 2664 | static void serial8250_console_putchar(struct uart_port *port, int ch) |
2665 | { | 2665 | { |
2666 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 2666 | struct uart_8250_port *up = (struct uart_8250_port *)port; |
2667 | 2667 | ||
2668 | wait_for_xmitr(up, UART_LSR_THRE); | 2668 | wait_for_xmitr(up, UART_LSR_THRE); |
2669 | serial_out(up, UART_TX, ch); | 2669 | serial_out(up, UART_TX, ch); |
2670 | } | 2670 | } |
2671 | 2671 | ||
2672 | /* | 2672 | /* |
2673 | * Print a string to the serial port trying not to disturb | 2673 | * Print a string to the serial port trying not to disturb |
2674 | * any possible real use of the port... | 2674 | * any possible real use of the port... |
2675 | * | 2675 | * |
2676 | * The console_lock must be held when we get here. | 2676 | * The console_lock must be held when we get here. |
2677 | */ | 2677 | */ |
2678 | static void | 2678 | static void |
2679 | serial8250_console_write(struct console *co, const char *s, unsigned int count) | 2679 | serial8250_console_write(struct console *co, const char *s, unsigned int count) |
2680 | { | 2680 | { |
2681 | struct uart_8250_port *up = &serial8250_ports[co->index]; | 2681 | struct uart_8250_port *up = &serial8250_ports[co->index]; |
2682 | unsigned long flags; | 2682 | unsigned long flags; |
2683 | unsigned int ier; | 2683 | unsigned int ier; |
2684 | int locked = 1; | 2684 | int locked = 1; |
2685 | 2685 | ||
2686 | touch_nmi_watchdog(); | 2686 | touch_nmi_watchdog(); |
2687 | 2687 | ||
2688 | local_irq_save(flags); | 2688 | local_irq_save(flags); |
2689 | if (up->port.sysrq) { | 2689 | if (up->port.sysrq) { |
2690 | /* serial8250_handle_port() already took the lock */ | 2690 | /* serial8250_handle_port() already took the lock */ |
2691 | locked = 0; | 2691 | locked = 0; |
2692 | } else if (oops_in_progress) { | 2692 | } else if (oops_in_progress) { |
2693 | locked = spin_trylock(&up->port.lock); | 2693 | locked = spin_trylock(&up->port.lock); |
2694 | } else | 2694 | } else |
2695 | spin_lock(&up->port.lock); | 2695 | spin_lock(&up->port.lock); |
2696 | 2696 | ||
2697 | /* | 2697 | /* |
2698 | * First save the IER then disable the interrupts | 2698 | * First save the IER then disable the interrupts |
2699 | */ | 2699 | */ |
2700 | ier = serial_in(up, UART_IER); | 2700 | ier = serial_in(up, UART_IER); |
2701 | 2701 | ||
2702 | if (up->capabilities & UART_CAP_UUE) | 2702 | if (up->capabilities & UART_CAP_UUE) |
2703 | serial_out(up, UART_IER, UART_IER_UUE); | 2703 | serial_out(up, UART_IER, UART_IER_UUE); |
2704 | else | 2704 | else |
2705 | serial_out(up, UART_IER, 0); | 2705 | serial_out(up, UART_IER, 0); |
2706 | 2706 | ||
2707 | uart_console_write(&up->port, s, count, serial8250_console_putchar); | 2707 | uart_console_write(&up->port, s, count, serial8250_console_putchar); |
2708 | 2708 | ||
2709 | /* | 2709 | /* |
2710 | * Finally, wait for transmitter to become empty | 2710 | * Finally, wait for transmitter to become empty |
2711 | * and restore the IER | 2711 | * and restore the IER |
2712 | */ | 2712 | */ |
2713 | wait_for_xmitr(up, BOTH_EMPTY); | 2713 | wait_for_xmitr(up, BOTH_EMPTY); |
2714 | serial_out(up, UART_IER, ier); | 2714 | serial_out(up, UART_IER, ier); |
2715 | 2715 | ||
2716 | /* | 2716 | /* |
2717 | * The receive handling will happen properly because the | 2717 | * The receive handling will happen properly because the |
2718 | * receive ready bit will still be set; it is not cleared | 2718 | * receive ready bit will still be set; it is not cleared |
2719 | * on read. However, modem control will not, we must | 2719 | * on read. However, modem control will not, we must |
2720 | * call it if we have saved something in the saved flags | 2720 | * call it if we have saved something in the saved flags |
2721 | * while processing with interrupts off. | 2721 | * while processing with interrupts off. |
2722 | */ | 2722 | */ |
2723 | if (up->msr_saved_flags) | 2723 | if (up->msr_saved_flags) |
2724 | check_modem_status(up); | 2724 | check_modem_status(up); |
2725 | 2725 | ||
2726 | if (locked) | 2726 | if (locked) |
2727 | spin_unlock(&up->port.lock); | 2727 | spin_unlock(&up->port.lock); |
2728 | local_irq_restore(flags); | 2728 | local_irq_restore(flags); |
2729 | } | 2729 | } |
2730 | 2730 | ||
2731 | static int __init serial8250_console_setup(struct console *co, char *options) | 2731 | static int __init serial8250_console_setup(struct console *co, char *options) |
2732 | { | 2732 | { |
2733 | struct uart_port *port; | 2733 | struct uart_port *port; |
2734 | int baud = 9600; | 2734 | int baud = 9600; |
2735 | int bits = 8; | 2735 | int bits = 8; |
2736 | int parity = 'n'; | 2736 | int parity = 'n'; |
2737 | int flow = 'n'; | 2737 | int flow = 'n'; |
2738 | 2738 | ||
2739 | /* | 2739 | /* |
2740 | * Check whether an invalid uart number has been specified, and | 2740 | * Check whether an invalid uart number has been specified, and |
2741 | * if so, search for the first available port that does have | 2741 | * if so, search for the first available port that does have |
2742 | * console support. | 2742 | * console support. |
2743 | */ | 2743 | */ |
2744 | if (co->index >= nr_uarts) | 2744 | if (co->index >= nr_uarts) |
2745 | co->index = 0; | 2745 | co->index = 0; |
2746 | port = &serial8250_ports[co->index].port; | 2746 | port = &serial8250_ports[co->index].port; |
2747 | if (!port->iobase && !port->membase) | 2747 | if (!port->iobase && !port->membase) |
2748 | return -ENODEV; | 2748 | return -ENODEV; |
2749 | 2749 | ||
2750 | if (options) | 2750 | if (options) |
2751 | uart_parse_options(options, &baud, &parity, &bits, &flow); | 2751 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
2752 | 2752 | ||
2753 | return uart_set_options(port, co, baud, parity, bits, flow); | 2753 | return uart_set_options(port, co, baud, parity, bits, flow); |
2754 | } | 2754 | } |
2755 | 2755 | ||
2756 | static int serial8250_console_early_setup(void) | 2756 | static int serial8250_console_early_setup(void) |
2757 | { | 2757 | { |
2758 | return serial8250_find_port_for_earlycon(); | 2758 | return serial8250_find_port_for_earlycon(); |
2759 | } | 2759 | } |
2760 | 2760 | ||
2761 | static struct console serial8250_console = { | 2761 | static struct console serial8250_console = { |
2762 | .name = "ttyS", | 2762 | .name = "ttyS", |
2763 | .write = serial8250_console_write, | 2763 | .write = serial8250_console_write, |
2764 | .device = uart_console_device, | 2764 | .device = uart_console_device, |
2765 | .setup = serial8250_console_setup, | 2765 | .setup = serial8250_console_setup, |
2766 | .early_setup = serial8250_console_early_setup, | 2766 | .early_setup = serial8250_console_early_setup, |
2767 | .flags = CON_PRINTBUFFER, | 2767 | .flags = CON_PRINTBUFFER, |
2768 | .index = -1, | 2768 | .index = -1, |
2769 | .data = &serial8250_reg, | 2769 | .data = &serial8250_reg, |
2770 | }; | 2770 | }; |
2771 | 2771 | ||
2772 | static int __init serial8250_console_init(void) | 2772 | static int __init serial8250_console_init(void) |
2773 | { | 2773 | { |
2774 | if (nr_uarts > UART_NR) | 2774 | if (nr_uarts > UART_NR) |
2775 | nr_uarts = UART_NR; | 2775 | nr_uarts = UART_NR; |
2776 | 2776 | ||
2777 | serial8250_isa_init_ports(); | 2777 | serial8250_isa_init_ports(); |
2778 | register_console(&serial8250_console); | 2778 | register_console(&serial8250_console); |
2779 | return 0; | 2779 | return 0; |
2780 | } | 2780 | } |
2781 | console_initcall(serial8250_console_init); | 2781 | console_initcall(serial8250_console_init); |
2782 | 2782 | ||
2783 | int serial8250_find_port(struct uart_port *p) | 2783 | int serial8250_find_port(struct uart_port *p) |
2784 | { | 2784 | { |
2785 | int line; | 2785 | int line; |
2786 | struct uart_port *port; | 2786 | struct uart_port *port; |
2787 | 2787 | ||
2788 | for (line = 0; line < nr_uarts; line++) { | 2788 | for (line = 0; line < nr_uarts; line++) { |
2789 | port = &serial8250_ports[line].port; | 2789 | port = &serial8250_ports[line].port; |
2790 | if (uart_match_port(p, port)) | 2790 | if (uart_match_port(p, port)) |
2791 | return line; | 2791 | return line; |
2792 | } | 2792 | } |
2793 | return -ENODEV; | 2793 | return -ENODEV; |
2794 | } | 2794 | } |
2795 | 2795 | ||
2796 | #define SERIAL8250_CONSOLE &serial8250_console | 2796 | #define SERIAL8250_CONSOLE &serial8250_console |
2797 | #else | 2797 | #else |
2798 | #define SERIAL8250_CONSOLE NULL | 2798 | #define SERIAL8250_CONSOLE NULL |
2799 | #endif | 2799 | #endif |
2800 | 2800 | ||
2801 | static struct uart_driver serial8250_reg = { | 2801 | static struct uart_driver serial8250_reg = { |
2802 | .owner = THIS_MODULE, | 2802 | .owner = THIS_MODULE, |
2803 | .driver_name = "serial", | 2803 | .driver_name = "serial", |
2804 | .dev_name = "ttyS", | 2804 | .dev_name = "ttyS", |
2805 | .major = TTY_MAJOR, | 2805 | .major = TTY_MAJOR, |
2806 | .minor = 64, | 2806 | .minor = 64, |
2807 | .cons = SERIAL8250_CONSOLE, | 2807 | .cons = SERIAL8250_CONSOLE, |
2808 | }; | 2808 | }; |
2809 | 2809 | ||
2810 | /* | 2810 | /* |
2811 | * early_serial_setup - early registration for 8250 ports | 2811 | * early_serial_setup - early registration for 8250 ports |
2812 | * | 2812 | * |
2813 | * Setup an 8250 port structure prior to console initialisation. Use | 2813 | * Setup an 8250 port structure prior to console initialisation. Use |
2814 | * after console initialisation will cause undefined behaviour. | 2814 | * after console initialisation will cause undefined behaviour. |
2815 | */ | 2815 | */ |
2816 | int __init early_serial_setup(struct uart_port *port) | 2816 | int __init early_serial_setup(struct uart_port *port) |
2817 | { | 2817 | { |
2818 | struct uart_port *p; | 2818 | struct uart_port *p; |
2819 | 2819 | ||
2820 | if (port->line >= ARRAY_SIZE(serial8250_ports)) | 2820 | if (port->line >= ARRAY_SIZE(serial8250_ports)) |
2821 | return -ENODEV; | 2821 | return -ENODEV; |
2822 | 2822 | ||
2823 | serial8250_isa_init_ports(); | 2823 | serial8250_isa_init_ports(); |
2824 | p = &serial8250_ports[port->line].port; | 2824 | p = &serial8250_ports[port->line].port; |
2825 | p->iobase = port->iobase; | 2825 | p->iobase = port->iobase; |
2826 | p->membase = port->membase; | 2826 | p->membase = port->membase; |
2827 | p->irq = port->irq; | 2827 | p->irq = port->irq; |
2828 | p->uartclk = port->uartclk; | 2828 | p->uartclk = port->uartclk; |
2829 | p->fifosize = port->fifosize; | 2829 | p->fifosize = port->fifosize; |
2830 | p->regshift = port->regshift; | 2830 | p->regshift = port->regshift; |
2831 | p->iotype = port->iotype; | 2831 | p->iotype = port->iotype; |
2832 | p->flags = port->flags; | 2832 | p->flags = port->flags; |
2833 | p->mapbase = port->mapbase; | 2833 | p->mapbase = port->mapbase; |
2834 | p->private_data = port->private_data; | 2834 | p->private_data = port->private_data; |
2835 | 2835 | ||
2836 | set_io_from_upio(p); | 2836 | set_io_from_upio(p); |
2837 | if (port->serial_in) | 2837 | if (port->serial_in) |
2838 | p->serial_in = port->serial_in; | 2838 | p->serial_in = port->serial_in; |
2839 | if (port->serial_out) | 2839 | if (port->serial_out) |
2840 | p->serial_out = port->serial_out; | 2840 | p->serial_out = port->serial_out; |
2841 | 2841 | ||
2842 | return 0; | 2842 | return 0; |
2843 | } | 2843 | } |
2844 | 2844 | ||
2845 | /** | 2845 | /** |
2846 | * serial8250_suspend_port - suspend one serial port | 2846 | * serial8250_suspend_port - suspend one serial port |
2847 | * @line: serial line number | 2847 | * @line: serial line number |
2848 | * | 2848 | * |
2849 | * Suspend one serial port. | 2849 | * Suspend one serial port. |
2850 | */ | 2850 | */ |
2851 | void serial8250_suspend_port(int line) | 2851 | void serial8250_suspend_port(int line) |
2852 | { | 2852 | { |
2853 | uart_suspend_port(&serial8250_reg, &serial8250_ports[line].port); | 2853 | uart_suspend_port(&serial8250_reg, &serial8250_ports[line].port); |
2854 | } | 2854 | } |
2855 | 2855 | ||
2856 | /** | 2856 | /** |
2857 | * serial8250_resume_port - resume one serial port | 2857 | * serial8250_resume_port - resume one serial port |
2858 | * @line: serial line number | 2858 | * @line: serial line number |
2859 | * | 2859 | * |
2860 | * Resume one serial port. | 2860 | * Resume one serial port. |
2861 | */ | 2861 | */ |
2862 | void serial8250_resume_port(int line) | 2862 | void serial8250_resume_port(int line) |
2863 | { | 2863 | { |
2864 | struct uart_8250_port *up = &serial8250_ports[line]; | 2864 | struct uart_8250_port *up = &serial8250_ports[line]; |
2865 | 2865 | ||
2866 | if (up->capabilities & UART_NATSEMI) { | 2866 | if (up->capabilities & UART_NATSEMI) { |
2867 | unsigned char tmp; | 2867 | unsigned char tmp; |
2868 | 2868 | ||
2869 | /* Ensure it's still in high speed mode */ | 2869 | /* Ensure it's still in high speed mode */ |
2870 | serial_outp(up, UART_LCR, 0xE0); | 2870 | serial_outp(up, UART_LCR, 0xE0); |
2871 | 2871 | ||
2872 | tmp = serial_in(up, 0x04); /* EXCR2 */ | 2872 | tmp = serial_in(up, 0x04); /* EXCR2 */ |
2873 | tmp &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */ | 2873 | tmp &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */ |
2874 | tmp |= 0x10; /* 1.625 divisor for baud_base --> 921600 */ | 2874 | tmp |= 0x10; /* 1.625 divisor for baud_base --> 921600 */ |
2875 | serial_outp(up, 0x04, tmp); | 2875 | serial_outp(up, 0x04, tmp); |
2876 | 2876 | ||
2877 | serial_outp(up, UART_LCR, 0); | 2877 | serial_outp(up, UART_LCR, 0); |
2878 | } | 2878 | } |
2879 | uart_resume_port(&serial8250_reg, &up->port); | 2879 | uart_resume_port(&serial8250_reg, &up->port); |
2880 | } | 2880 | } |
2881 | 2881 | ||
2882 | /* | 2882 | /* |
2883 | * Register a set of serial devices attached to a platform device. The | 2883 | * Register a set of serial devices attached to a platform device. The |
2884 | * list is terminated with a zero flags entry, which means we expect | 2884 | * list is terminated with a zero flags entry, which means we expect |
2885 | * all entries to have at least UPF_BOOT_AUTOCONF set. | 2885 | * all entries to have at least UPF_BOOT_AUTOCONF set. |
2886 | */ | 2886 | */ |
2887 | static int __devinit serial8250_probe(struct platform_device *dev) | 2887 | static int __devinit serial8250_probe(struct platform_device *dev) |
2888 | { | 2888 | { |
2889 | struct plat_serial8250_port *p = dev->dev.platform_data; | 2889 | struct plat_serial8250_port *p = dev->dev.platform_data; |
2890 | struct uart_port port; | 2890 | struct uart_port port; |
2891 | int ret, i; | 2891 | int ret, i; |
2892 | 2892 | ||
2893 | memset(&port, 0, sizeof(struct uart_port)); | 2893 | memset(&port, 0, sizeof(struct uart_port)); |
2894 | 2894 | ||
2895 | for (i = 0; p && p->flags != 0; p++, i++) { | 2895 | for (i = 0; p && p->flags != 0; p++, i++) { |
2896 | port.iobase = p->iobase; | 2896 | port.iobase = p->iobase; |
2897 | port.membase = p->membase; | 2897 | port.membase = p->membase; |
2898 | port.irq = p->irq; | 2898 | port.irq = p->irq; |
2899 | port.uartclk = p->uartclk; | 2899 | port.uartclk = p->uartclk; |
2900 | port.regshift = p->regshift; | 2900 | port.regshift = p->regshift; |
2901 | port.iotype = p->iotype; | 2901 | port.iotype = p->iotype; |
2902 | port.flags = p->flags; | 2902 | port.flags = p->flags; |
2903 | port.mapbase = p->mapbase; | 2903 | port.mapbase = p->mapbase; |
2904 | port.hub6 = p->hub6; | 2904 | port.hub6 = p->hub6; |
2905 | port.private_data = p->private_data; | 2905 | port.private_data = p->private_data; |
2906 | port.type = p->type; | ||
2906 | port.serial_in = p->serial_in; | 2907 | port.serial_in = p->serial_in; |
2907 | port.serial_out = p->serial_out; | 2908 | port.serial_out = p->serial_out; |
2908 | port.dev = &dev->dev; | 2909 | port.dev = &dev->dev; |
2909 | if (share_irqs) | 2910 | if (share_irqs) |
2910 | port.flags |= UPF_SHARE_IRQ; | 2911 | port.flags |= UPF_SHARE_IRQ; |
2911 | ret = serial8250_register_port(&port); | 2912 | ret = serial8250_register_port(&port); |
2912 | if (ret < 0) { | 2913 | if (ret < 0) { |
2913 | dev_err(&dev->dev, "unable to register port at index %d " | 2914 | dev_err(&dev->dev, "unable to register port at index %d " |
2914 | "(IO%lx MEM%llx IRQ%d): %d\n", i, | 2915 | "(IO%lx MEM%llx IRQ%d): %d\n", i, |
2915 | p->iobase, (unsigned long long)p->mapbase, | 2916 | p->iobase, (unsigned long long)p->mapbase, |
2916 | p->irq, ret); | 2917 | p->irq, ret); |
2917 | } | 2918 | } |
2918 | } | 2919 | } |
2919 | return 0; | 2920 | return 0; |
2920 | } | 2921 | } |
2921 | 2922 | ||
2922 | /* | 2923 | /* |
2923 | * Remove serial ports registered against a platform device. | 2924 | * Remove serial ports registered against a platform device. |
2924 | */ | 2925 | */ |
2925 | static int __devexit serial8250_remove(struct platform_device *dev) | 2926 | static int __devexit serial8250_remove(struct platform_device *dev) |
2926 | { | 2927 | { |
2927 | int i; | 2928 | int i; |
2928 | 2929 | ||
2929 | for (i = 0; i < nr_uarts; i++) { | 2930 | for (i = 0; i < nr_uarts; i++) { |
2930 | struct uart_8250_port *up = &serial8250_ports[i]; | 2931 | struct uart_8250_port *up = &serial8250_ports[i]; |
2931 | 2932 | ||
2932 | if (up->port.dev == &dev->dev) | 2933 | if (up->port.dev == &dev->dev) |
2933 | serial8250_unregister_port(i); | 2934 | serial8250_unregister_port(i); |
2934 | } | 2935 | } |
2935 | return 0; | 2936 | return 0; |
2936 | } | 2937 | } |
2937 | 2938 | ||
2938 | static int serial8250_suspend(struct platform_device *dev, pm_message_t state) | 2939 | static int serial8250_suspend(struct platform_device *dev, pm_message_t state) |
2939 | { | 2940 | { |
2940 | int i; | 2941 | int i; |
2941 | 2942 | ||
2942 | for (i = 0; i < UART_NR; i++) { | 2943 | for (i = 0; i < UART_NR; i++) { |
2943 | struct uart_8250_port *up = &serial8250_ports[i]; | 2944 | struct uart_8250_port *up = &serial8250_ports[i]; |
2944 | 2945 | ||
2945 | if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev) | 2946 | if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev) |
2946 | uart_suspend_port(&serial8250_reg, &up->port); | 2947 | uart_suspend_port(&serial8250_reg, &up->port); |
2947 | } | 2948 | } |
2948 | 2949 | ||
2949 | return 0; | 2950 | return 0; |
2950 | } | 2951 | } |
2951 | 2952 | ||
2952 | static int serial8250_resume(struct platform_device *dev) | 2953 | static int serial8250_resume(struct platform_device *dev) |
2953 | { | 2954 | { |
2954 | int i; | 2955 | int i; |
2955 | 2956 | ||
2956 | for (i = 0; i < UART_NR; i++) { | 2957 | for (i = 0; i < UART_NR; i++) { |
2957 | struct uart_8250_port *up = &serial8250_ports[i]; | 2958 | struct uart_8250_port *up = &serial8250_ports[i]; |
2958 | 2959 | ||
2959 | if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev) | 2960 | if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev) |
2960 | serial8250_resume_port(i); | 2961 | serial8250_resume_port(i); |
2961 | } | 2962 | } |
2962 | 2963 | ||
2963 | return 0; | 2964 | return 0; |
2964 | } | 2965 | } |
2965 | 2966 | ||
2966 | static struct platform_driver serial8250_isa_driver = { | 2967 | static struct platform_driver serial8250_isa_driver = { |
2967 | .probe = serial8250_probe, | 2968 | .probe = serial8250_probe, |
2968 | .remove = __devexit_p(serial8250_remove), | 2969 | .remove = __devexit_p(serial8250_remove), |
2969 | .suspend = serial8250_suspend, | 2970 | .suspend = serial8250_suspend, |
2970 | .resume = serial8250_resume, | 2971 | .resume = serial8250_resume, |
2971 | .driver = { | 2972 | .driver = { |
2972 | .name = "serial8250", | 2973 | .name = "serial8250", |
2973 | .owner = THIS_MODULE, | 2974 | .owner = THIS_MODULE, |
2974 | }, | 2975 | }, |
2975 | }; | 2976 | }; |
2976 | 2977 | ||
2977 | /* | 2978 | /* |
2978 | * This "device" covers _all_ ISA 8250-compatible serial devices listed | 2979 | * This "device" covers _all_ ISA 8250-compatible serial devices listed |
2979 | * in the table in include/asm/serial.h | 2980 | * in the table in include/asm/serial.h |
2980 | */ | 2981 | */ |
2981 | static struct platform_device *serial8250_isa_devs; | 2982 | static struct platform_device *serial8250_isa_devs; |
2982 | 2983 | ||
2983 | /* | 2984 | /* |
2984 | * serial8250_register_port and serial8250_unregister_port allows for | 2985 | * serial8250_register_port and serial8250_unregister_port allows for |
2985 | * 16x50 serial ports to be configured at run-time, to support PCMCIA | 2986 | * 16x50 serial ports to be configured at run-time, to support PCMCIA |
2986 | * modems and PCI multiport cards. | 2987 | * modems and PCI multiport cards. |
2987 | */ | 2988 | */ |
2988 | static DEFINE_MUTEX(serial_mutex); | 2989 | static DEFINE_MUTEX(serial_mutex); |
2989 | 2990 | ||
2990 | static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port *port) | 2991 | static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port *port) |
2991 | { | 2992 | { |
2992 | int i; | 2993 | int i; |
2993 | 2994 | ||
2994 | /* | 2995 | /* |
2995 | * First, find a port entry which matches. | 2996 | * First, find a port entry which matches. |
2996 | */ | 2997 | */ |
2997 | for (i = 0; i < nr_uarts; i++) | 2998 | for (i = 0; i < nr_uarts; i++) |
2998 | if (uart_match_port(&serial8250_ports[i].port, port)) | 2999 | if (uart_match_port(&serial8250_ports[i].port, port)) |
2999 | return &serial8250_ports[i]; | 3000 | return &serial8250_ports[i]; |
3000 | 3001 | ||
3001 | /* | 3002 | /* |
3002 | * We didn't find a matching entry, so look for the first | 3003 | * We didn't find a matching entry, so look for the first |
3003 | * free entry. We look for one which hasn't been previously | 3004 | * free entry. We look for one which hasn't been previously |
3004 | * used (indicated by zero iobase). | 3005 | * used (indicated by zero iobase). |
3005 | */ | 3006 | */ |
3006 | for (i = 0; i < nr_uarts; i++) | 3007 | for (i = 0; i < nr_uarts; i++) |
3007 | if (serial8250_ports[i].port.type == PORT_UNKNOWN && | 3008 | if (serial8250_ports[i].port.type == PORT_UNKNOWN && |
3008 | serial8250_ports[i].port.iobase == 0) | 3009 | serial8250_ports[i].port.iobase == 0) |
3009 | return &serial8250_ports[i]; | 3010 | return &serial8250_ports[i]; |
3010 | 3011 | ||
3011 | /* | 3012 | /* |
3012 | * That also failed. Last resort is to find any entry which | 3013 | * That also failed. Last resort is to find any entry which |
3013 | * doesn't have a real port associated with it. | 3014 | * doesn't have a real port associated with it. |
3014 | */ | 3015 | */ |
3015 | for (i = 0; i < nr_uarts; i++) | 3016 | for (i = 0; i < nr_uarts; i++) |
3016 | if (serial8250_ports[i].port.type == PORT_UNKNOWN) | 3017 | if (serial8250_ports[i].port.type == PORT_UNKNOWN) |
3017 | return &serial8250_ports[i]; | 3018 | return &serial8250_ports[i]; |
3018 | 3019 | ||
3019 | return NULL; | 3020 | return NULL; |
3020 | } | 3021 | } |
3021 | 3022 | ||
3022 | /** | 3023 | /** |
3023 | * serial8250_register_port - register a serial port | 3024 | * serial8250_register_port - register a serial port |
3024 | * @port: serial port template | 3025 | * @port: serial port template |
3025 | * | 3026 | * |
3026 | * Configure the serial port specified by the request. If the | 3027 | * Configure the serial port specified by the request. If the |
3027 | * port exists and is in use, it is hung up and unregistered | 3028 | * port exists and is in use, it is hung up and unregistered |
3028 | * first. | 3029 | * first. |
3029 | * | 3030 | * |
3030 | * The port is then probed and if necessary the IRQ is autodetected | 3031 | * The port is then probed and if necessary the IRQ is autodetected |
3031 | * If this fails an error is returned. | 3032 | * If this fails an error is returned. |
3032 | * | 3033 | * |
3033 | * On success the port is ready to use and the line number is returned. | 3034 | * On success the port is ready to use and the line number is returned. |
3034 | */ | 3035 | */ |
3035 | int serial8250_register_port(struct uart_port *port) | 3036 | int serial8250_register_port(struct uart_port *port) |
3036 | { | 3037 | { |
3037 | struct uart_8250_port *uart; | 3038 | struct uart_8250_port *uart; |
3038 | int ret = -ENOSPC; | 3039 | int ret = -ENOSPC; |
3039 | 3040 | ||
3040 | if (port->uartclk == 0) | 3041 | if (port->uartclk == 0) |
3041 | return -EINVAL; | 3042 | return -EINVAL; |
3042 | 3043 | ||
3043 | mutex_lock(&serial_mutex); | 3044 | mutex_lock(&serial_mutex); |
3044 | 3045 | ||
3045 | uart = serial8250_find_match_or_unused(port); | 3046 | uart = serial8250_find_match_or_unused(port); |
3046 | if (uart) { | 3047 | if (uart) { |
3047 | uart_remove_one_port(&serial8250_reg, &uart->port); | 3048 | uart_remove_one_port(&serial8250_reg, &uart->port); |
3048 | 3049 | ||
3049 | uart->port.iobase = port->iobase; | 3050 | uart->port.iobase = port->iobase; |
3050 | uart->port.membase = port->membase; | 3051 | uart->port.membase = port->membase; |
3051 | uart->port.irq = port->irq; | 3052 | uart->port.irq = port->irq; |
3052 | uart->port.uartclk = port->uartclk; | 3053 | uart->port.uartclk = port->uartclk; |
3053 | uart->port.fifosize = port->fifosize; | 3054 | uart->port.fifosize = port->fifosize; |
3054 | uart->port.regshift = port->regshift; | 3055 | uart->port.regshift = port->regshift; |
3055 | uart->port.iotype = port->iotype; | 3056 | uart->port.iotype = port->iotype; |
3056 | uart->port.flags = port->flags | UPF_BOOT_AUTOCONF; | 3057 | uart->port.flags = port->flags | UPF_BOOT_AUTOCONF; |
3057 | uart->port.mapbase = port->mapbase; | 3058 | uart->port.mapbase = port->mapbase; |
3058 | uart->port.private_data = port->private_data; | 3059 | uart->port.private_data = port->private_data; |
3059 | if (port->dev) | 3060 | if (port->dev) |
3060 | uart->port.dev = port->dev; | 3061 | uart->port.dev = port->dev; |
3062 | |||
3063 | if (port->flags & UPF_FIXED_TYPE) { | ||
3064 | uart->port.type = port->type; | ||
3065 | uart->port.fifosize = uart_config[port->type].fifo_size; | ||
3066 | uart->capabilities = uart_config[port->type].flags; | ||
3067 | uart->tx_loadsz = uart_config[port->type].tx_loadsz; | ||
3068 | } | ||
3069 | |||
3061 | set_io_from_upio(&uart->port); | 3070 | set_io_from_upio(&uart->port); |
3062 | /* Possibly override default I/O functions. */ | 3071 | /* Possibly override default I/O functions. */ |
3063 | if (port->serial_in) | 3072 | if (port->serial_in) |
3064 | uart->port.serial_in = port->serial_in; | 3073 | uart->port.serial_in = port->serial_in; |
3065 | if (port->serial_out) | 3074 | if (port->serial_out) |
3066 | uart->port.serial_out = port->serial_out; | 3075 | uart->port.serial_out = port->serial_out; |
3067 | 3076 | ||
3068 | ret = uart_add_one_port(&serial8250_reg, &uart->port); | 3077 | ret = uart_add_one_port(&serial8250_reg, &uart->port); |
3069 | if (ret == 0) | 3078 | if (ret == 0) |
3070 | ret = uart->port.line; | 3079 | ret = uart->port.line; |
3071 | } | 3080 | } |
3072 | mutex_unlock(&serial_mutex); | 3081 | mutex_unlock(&serial_mutex); |
3073 | 3082 | ||
3074 | return ret; | 3083 | return ret; |
3075 | } | 3084 | } |
3076 | EXPORT_SYMBOL(serial8250_register_port); | 3085 | EXPORT_SYMBOL(serial8250_register_port); |
3077 | 3086 | ||
3078 | /** | 3087 | /** |
3079 | * serial8250_unregister_port - remove a 16x50 serial port at runtime | 3088 | * serial8250_unregister_port - remove a 16x50 serial port at runtime |
3080 | * @line: serial line number | 3089 | * @line: serial line number |
3081 | * | 3090 | * |
3082 | * Remove one serial port. This may not be called from interrupt | 3091 | * Remove one serial port. This may not be called from interrupt |
3083 | * context. We hand the port back to the our control. | 3092 | * context. We hand the port back to the our control. |
3084 | */ | 3093 | */ |
3085 | void serial8250_unregister_port(int line) | 3094 | void serial8250_unregister_port(int line) |
3086 | { | 3095 | { |
3087 | struct uart_8250_port *uart = &serial8250_ports[line]; | 3096 | struct uart_8250_port *uart = &serial8250_ports[line]; |
3088 | 3097 | ||
3089 | mutex_lock(&serial_mutex); | 3098 | mutex_lock(&serial_mutex); |
3090 | uart_remove_one_port(&serial8250_reg, &uart->port); | 3099 | uart_remove_one_port(&serial8250_reg, &uart->port); |
3091 | if (serial8250_isa_devs) { | 3100 | if (serial8250_isa_devs) { |
3092 | uart->port.flags &= ~UPF_BOOT_AUTOCONF; | 3101 | uart->port.flags &= ~UPF_BOOT_AUTOCONF; |
3093 | uart->port.type = PORT_UNKNOWN; | 3102 | uart->port.type = PORT_UNKNOWN; |
3094 | uart->port.dev = &serial8250_isa_devs->dev; | 3103 | uart->port.dev = &serial8250_isa_devs->dev; |
3095 | uart_add_one_port(&serial8250_reg, &uart->port); | 3104 | uart_add_one_port(&serial8250_reg, &uart->port); |
3096 | } else { | 3105 | } else { |
3097 | uart->port.dev = NULL; | 3106 | uart->port.dev = NULL; |
3098 | } | 3107 | } |
3099 | mutex_unlock(&serial_mutex); | 3108 | mutex_unlock(&serial_mutex); |
3100 | } | 3109 | } |
3101 | EXPORT_SYMBOL(serial8250_unregister_port); | 3110 | EXPORT_SYMBOL(serial8250_unregister_port); |
3102 | 3111 | ||
3103 | static int __init serial8250_init(void) | 3112 | static int __init serial8250_init(void) |
3104 | { | 3113 | { |
3105 | int ret; | 3114 | int ret; |
3106 | 3115 | ||
3107 | if (nr_uarts > UART_NR) | 3116 | if (nr_uarts > UART_NR) |
3108 | nr_uarts = UART_NR; | 3117 | nr_uarts = UART_NR; |
3109 | 3118 | ||
3110 | printk(KERN_INFO "Serial: 8250/16550 driver" | 3119 | printk(KERN_INFO "Serial: 8250/16550 driver" |
3111 | "%d ports, IRQ sharing %sabled\n", nr_uarts, | 3120 | "%d ports, IRQ sharing %sabled\n", nr_uarts, |
3112 | share_irqs ? "en" : "dis"); | 3121 | share_irqs ? "en" : "dis"); |
3113 | 3122 | ||
3114 | #ifdef CONFIG_SPARC | 3123 | #ifdef CONFIG_SPARC |
3115 | ret = sunserial_register_minors(&serial8250_reg, UART_NR); | 3124 | ret = sunserial_register_minors(&serial8250_reg, UART_NR); |
3116 | #else | 3125 | #else |
3117 | serial8250_reg.nr = UART_NR; | 3126 | serial8250_reg.nr = UART_NR; |
3118 | ret = uart_register_driver(&serial8250_reg); | 3127 | ret = uart_register_driver(&serial8250_reg); |
3119 | #endif | 3128 | #endif |
3120 | if (ret) | 3129 | if (ret) |
3121 | goto out; | 3130 | goto out; |
3122 | 3131 | ||
3123 | serial8250_isa_devs = platform_device_alloc("serial8250", | 3132 | serial8250_isa_devs = platform_device_alloc("serial8250", |
3124 | PLAT8250_DEV_LEGACY); | 3133 | PLAT8250_DEV_LEGACY); |
3125 | if (!serial8250_isa_devs) { | 3134 | if (!serial8250_isa_devs) { |
3126 | ret = -ENOMEM; | 3135 | ret = -ENOMEM; |
3127 | goto unreg_uart_drv; | 3136 | goto unreg_uart_drv; |
3128 | } | 3137 | } |
3129 | 3138 | ||
3130 | ret = platform_device_add(serial8250_isa_devs); | 3139 | ret = platform_device_add(serial8250_isa_devs); |
3131 | if (ret) | 3140 | if (ret) |
3132 | goto put_dev; | 3141 | goto put_dev; |
3133 | 3142 | ||
3134 | serial8250_register_ports(&serial8250_reg, &serial8250_isa_devs->dev); | 3143 | serial8250_register_ports(&serial8250_reg, &serial8250_isa_devs->dev); |
3135 | 3144 | ||
3136 | ret = platform_driver_register(&serial8250_isa_driver); | 3145 | ret = platform_driver_register(&serial8250_isa_driver); |
3137 | if (ret == 0) | 3146 | if (ret == 0) |
3138 | goto out; | 3147 | goto out; |
3139 | 3148 | ||
3140 | platform_device_del(serial8250_isa_devs); | 3149 | platform_device_del(serial8250_isa_devs); |
3141 | put_dev: | 3150 | put_dev: |
3142 | platform_device_put(serial8250_isa_devs); | 3151 | platform_device_put(serial8250_isa_devs); |
3143 | unreg_uart_drv: | 3152 | unreg_uart_drv: |
3144 | #ifdef CONFIG_SPARC | 3153 | #ifdef CONFIG_SPARC |
3145 | sunserial_unregister_minors(&serial8250_reg, UART_NR); | 3154 | sunserial_unregister_minors(&serial8250_reg, UART_NR); |
3146 | #else | 3155 | #else |
3147 | uart_unregister_driver(&serial8250_reg); | 3156 | uart_unregister_driver(&serial8250_reg); |
3148 | #endif | 3157 | #endif |
3149 | out: | 3158 | out: |
3150 | return ret; | 3159 | return ret; |
3151 | } | 3160 | } |
3152 | 3161 | ||
3153 | static void __exit serial8250_exit(void) | 3162 | static void __exit serial8250_exit(void) |
3154 | { | 3163 | { |
3155 | struct platform_device *isa_dev = serial8250_isa_devs; | 3164 | struct platform_device *isa_dev = serial8250_isa_devs; |
3156 | 3165 | ||
3157 | /* | 3166 | /* |
3158 | * This tells serial8250_unregister_port() not to re-register | 3167 | * This tells serial8250_unregister_port() not to re-register |
3159 | * the ports (thereby making serial8250_isa_driver permanently | 3168 | * the ports (thereby making serial8250_isa_driver permanently |
3160 | * in use.) | 3169 | * in use.) |
3161 | */ | 3170 | */ |
3162 | serial8250_isa_devs = NULL; | 3171 | serial8250_isa_devs = NULL; |
3163 | 3172 | ||
3164 | platform_driver_unregister(&serial8250_isa_driver); | 3173 | platform_driver_unregister(&serial8250_isa_driver); |
3165 | platform_device_unregister(isa_dev); | 3174 | platform_device_unregister(isa_dev); |
3166 | 3175 | ||
3167 | #ifdef CONFIG_SPARC | 3176 | #ifdef CONFIG_SPARC |
3168 | sunserial_unregister_minors(&serial8250_reg, UART_NR); | 3177 | sunserial_unregister_minors(&serial8250_reg, UART_NR); |
3169 | #else | 3178 | #else |
3170 | uart_unregister_driver(&serial8250_reg); | 3179 | uart_unregister_driver(&serial8250_reg); |
3171 | #endif | 3180 | #endif |
3172 | } | 3181 | } |
3173 | 3182 | ||
3174 | module_init(serial8250_init); | 3183 | module_init(serial8250_init); |
3175 | module_exit(serial8250_exit); | 3184 | module_exit(serial8250_exit); |
3176 | 3185 | ||
3177 | EXPORT_SYMBOL(serial8250_suspend_port); | 3186 | EXPORT_SYMBOL(serial8250_suspend_port); |
3178 | EXPORT_SYMBOL(serial8250_resume_port); | 3187 | EXPORT_SYMBOL(serial8250_resume_port); |
3179 | 3188 | ||
3180 | MODULE_LICENSE("GPL"); | 3189 | MODULE_LICENSE("GPL"); |
3181 | MODULE_DESCRIPTION("Generic 8250/16x50 serial driver"); | 3190 | MODULE_DESCRIPTION("Generic 8250/16x50 serial driver"); |
3182 | 3191 | ||
3183 | module_param(share_irqs, uint, 0644); | 3192 | module_param(share_irqs, uint, 0644); |
3184 | MODULE_PARM_DESC(share_irqs, "Share IRQs with other non-8250/16x50 devices" | 3193 | MODULE_PARM_DESC(share_irqs, "Share IRQs with other non-8250/16x50 devices" |
3185 | " (unsafe)"); | 3194 | " (unsafe)"); |
3186 | 3195 | ||
3187 | module_param(nr_uarts, uint, 0644); | 3196 | module_param(nr_uarts, uint, 0644); |
3188 | MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")"); | 3197 | MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")"); |
3189 | 3198 | ||
3190 | #ifdef CONFIG_SERIAL_8250_RSA | 3199 | #ifdef CONFIG_SERIAL_8250_RSA |
3191 | module_param_array(probe_rsa, ulong, &probe_rsa_count, 0444); | 3200 | module_param_array(probe_rsa, ulong, &probe_rsa_count, 0444); |
3192 | MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA"); | 3201 | MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA"); |
3193 | #endif | 3202 | #endif |
3194 | MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR); | 3203 | MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR); |
3195 | 3204 |
drivers/serial/serial_core.c
1 | /* | 1 | /* |
2 | * linux/drivers/char/core.c | 2 | * linux/drivers/char/core.c |
3 | * | 3 | * |
4 | * Driver core for serial ports | 4 | * Driver core for serial ports |
5 | * | 5 | * |
6 | * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o. | 6 | * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o. |
7 | * | 7 | * |
8 | * Copyright 1999 ARM Limited | 8 | * Copyright 1999 ARM Limited |
9 | * Copyright (C) 2000-2001 Deep Blue Solutions Ltd. | 9 | * Copyright (C) 2000-2001 Deep Blue Solutions Ltd. |
10 | * | 10 | * |
11 | * This program is free software; you can redistribute it and/or modify | 11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License as published by | 12 | * it under the terms of the GNU General Public License as published by |
13 | * the Free Software Foundation; either version 2 of the License, or | 13 | * the Free Software Foundation; either version 2 of the License, or |
14 | * (at your option) any later version. | 14 | * (at your option) any later version. |
15 | * | 15 | * |
16 | * This program is distributed in the hope that it will be useful, | 16 | * This program is distributed in the hope that it will be useful, |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | * GNU General Public License for more details. | 19 | * GNU General Public License for more details. |
20 | * | 20 | * |
21 | * You should have received a copy of the GNU General Public License | 21 | * You should have received a copy of the GNU General Public License |
22 | * along with this program; if not, write to the Free Software | 22 | * along with this program; if not, write to the Free Software |
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
24 | */ | 24 | */ |
25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
26 | #include <linux/tty.h> | 26 | #include <linux/tty.h> |
27 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
28 | #include <linux/init.h> | 28 | #include <linux/init.h> |
29 | #include <linux/console.h> | 29 | #include <linux/console.h> |
30 | #include <linux/serial_core.h> | 30 | #include <linux/serial_core.h> |
31 | #include <linux/smp_lock.h> | 31 | #include <linux/smp_lock.h> |
32 | #include <linux/device.h> | 32 | #include <linux/device.h> |
33 | #include <linux/serial.h> /* for serial_state and serial_icounter_struct */ | 33 | #include <linux/serial.h> /* for serial_state and serial_icounter_struct */ |
34 | #include <linux/delay.h> | 34 | #include <linux/delay.h> |
35 | #include <linux/mutex.h> | 35 | #include <linux/mutex.h> |
36 | 36 | ||
37 | #include <asm/irq.h> | 37 | #include <asm/irq.h> |
38 | #include <asm/uaccess.h> | 38 | #include <asm/uaccess.h> |
39 | 39 | ||
40 | /* | 40 | /* |
41 | * This is used to lock changes in serial line configuration. | 41 | * This is used to lock changes in serial line configuration. |
42 | */ | 42 | */ |
43 | static DEFINE_MUTEX(port_mutex); | 43 | static DEFINE_MUTEX(port_mutex); |
44 | 44 | ||
45 | /* | 45 | /* |
46 | * lockdep: port->lock is initialized in two places, but we | 46 | * lockdep: port->lock is initialized in two places, but we |
47 | * want only one lock-class: | 47 | * want only one lock-class: |
48 | */ | 48 | */ |
49 | static struct lock_class_key port_lock_key; | 49 | static struct lock_class_key port_lock_key; |
50 | 50 | ||
51 | #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8) | 51 | #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8) |
52 | 52 | ||
53 | #define uart_users(state) ((state)->count + (state)->info.port.blocked_open) | 53 | #define uart_users(state) ((state)->count + (state)->info.port.blocked_open) |
54 | 54 | ||
55 | #ifdef CONFIG_SERIAL_CORE_CONSOLE | 55 | #ifdef CONFIG_SERIAL_CORE_CONSOLE |
56 | #define uart_console(port) ((port)->cons && (port)->cons->index == (port)->line) | 56 | #define uart_console(port) ((port)->cons && (port)->cons->index == (port)->line) |
57 | #else | 57 | #else |
58 | #define uart_console(port) (0) | 58 | #define uart_console(port) (0) |
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | static void uart_change_speed(struct uart_state *state, | 61 | static void uart_change_speed(struct uart_state *state, |
62 | struct ktermios *old_termios); | 62 | struct ktermios *old_termios); |
63 | static void uart_wait_until_sent(struct tty_struct *tty, int timeout); | 63 | static void uart_wait_until_sent(struct tty_struct *tty, int timeout); |
64 | static void uart_change_pm(struct uart_state *state, int pm_state); | 64 | static void uart_change_pm(struct uart_state *state, int pm_state); |
65 | 65 | ||
66 | /* | 66 | /* |
67 | * This routine is used by the interrupt handler to schedule processing in | 67 | * This routine is used by the interrupt handler to schedule processing in |
68 | * the software interrupt portion of the driver. | 68 | * the software interrupt portion of the driver. |
69 | */ | 69 | */ |
70 | void uart_write_wakeup(struct uart_port *port) | 70 | void uart_write_wakeup(struct uart_port *port) |
71 | { | 71 | { |
72 | struct uart_info *info = port->info; | 72 | struct uart_info *info = port->info; |
73 | /* | 73 | /* |
74 | * This means you called this function _after_ the port was | 74 | * This means you called this function _after_ the port was |
75 | * closed. No cookie for you. | 75 | * closed. No cookie for you. |
76 | */ | 76 | */ |
77 | BUG_ON(!info); | 77 | BUG_ON(!info); |
78 | tasklet_schedule(&info->tlet); | 78 | tasklet_schedule(&info->tlet); |
79 | } | 79 | } |
80 | 80 | ||
81 | static void uart_stop(struct tty_struct *tty) | 81 | static void uart_stop(struct tty_struct *tty) |
82 | { | 82 | { |
83 | struct uart_state *state = tty->driver_data; | 83 | struct uart_state *state = tty->driver_data; |
84 | struct uart_port *port = state->port; | 84 | struct uart_port *port = state->port; |
85 | unsigned long flags; | 85 | unsigned long flags; |
86 | 86 | ||
87 | spin_lock_irqsave(&port->lock, flags); | 87 | spin_lock_irqsave(&port->lock, flags); |
88 | port->ops->stop_tx(port); | 88 | port->ops->stop_tx(port); |
89 | spin_unlock_irqrestore(&port->lock, flags); | 89 | spin_unlock_irqrestore(&port->lock, flags); |
90 | } | 90 | } |
91 | 91 | ||
92 | static void __uart_start(struct tty_struct *tty) | 92 | static void __uart_start(struct tty_struct *tty) |
93 | { | 93 | { |
94 | struct uart_state *state = tty->driver_data; | 94 | struct uart_state *state = tty->driver_data; |
95 | struct uart_port *port = state->port; | 95 | struct uart_port *port = state->port; |
96 | 96 | ||
97 | if (!uart_circ_empty(&state->info.xmit) && state->info.xmit.buf && | 97 | if (!uart_circ_empty(&state->info.xmit) && state->info.xmit.buf && |
98 | !tty->stopped && !tty->hw_stopped) | 98 | !tty->stopped && !tty->hw_stopped) |
99 | port->ops->start_tx(port); | 99 | port->ops->start_tx(port); |
100 | } | 100 | } |
101 | 101 | ||
102 | static void uart_start(struct tty_struct *tty) | 102 | static void uart_start(struct tty_struct *tty) |
103 | { | 103 | { |
104 | struct uart_state *state = tty->driver_data; | 104 | struct uart_state *state = tty->driver_data; |
105 | struct uart_port *port = state->port; | 105 | struct uart_port *port = state->port; |
106 | unsigned long flags; | 106 | unsigned long flags; |
107 | 107 | ||
108 | spin_lock_irqsave(&port->lock, flags); | 108 | spin_lock_irqsave(&port->lock, flags); |
109 | __uart_start(tty); | 109 | __uart_start(tty); |
110 | spin_unlock_irqrestore(&port->lock, flags); | 110 | spin_unlock_irqrestore(&port->lock, flags); |
111 | } | 111 | } |
112 | 112 | ||
113 | static void uart_tasklet_action(unsigned long data) | 113 | static void uart_tasklet_action(unsigned long data) |
114 | { | 114 | { |
115 | struct uart_state *state = (struct uart_state *)data; | 115 | struct uart_state *state = (struct uart_state *)data; |
116 | tty_wakeup(state->info.port.tty); | 116 | tty_wakeup(state->info.port.tty); |
117 | } | 117 | } |
118 | 118 | ||
119 | static inline void | 119 | static inline void |
120 | uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear) | 120 | uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear) |
121 | { | 121 | { |
122 | unsigned long flags; | 122 | unsigned long flags; |
123 | unsigned int old; | 123 | unsigned int old; |
124 | 124 | ||
125 | spin_lock_irqsave(&port->lock, flags); | 125 | spin_lock_irqsave(&port->lock, flags); |
126 | old = port->mctrl; | 126 | old = port->mctrl; |
127 | port->mctrl = (old & ~clear) | set; | 127 | port->mctrl = (old & ~clear) | set; |
128 | if (old != port->mctrl) | 128 | if (old != port->mctrl) |
129 | port->ops->set_mctrl(port, port->mctrl); | 129 | port->ops->set_mctrl(port, port->mctrl); |
130 | spin_unlock_irqrestore(&port->lock, flags); | 130 | spin_unlock_irqrestore(&port->lock, flags); |
131 | } | 131 | } |
132 | 132 | ||
133 | #define uart_set_mctrl(port, set) uart_update_mctrl(port, set, 0) | 133 | #define uart_set_mctrl(port, set) uart_update_mctrl(port, set, 0) |
134 | #define uart_clear_mctrl(port, clear) uart_update_mctrl(port, 0, clear) | 134 | #define uart_clear_mctrl(port, clear) uart_update_mctrl(port, 0, clear) |
135 | 135 | ||
136 | /* | 136 | /* |
137 | * Startup the port. This will be called once per open. All calls | 137 | * Startup the port. This will be called once per open. All calls |
138 | * will be serialised by the per-port mutex. | 138 | * will be serialised by the per-port mutex. |
139 | */ | 139 | */ |
140 | static int uart_startup(struct uart_state *state, int init_hw) | 140 | static int uart_startup(struct uart_state *state, int init_hw) |
141 | { | 141 | { |
142 | struct uart_info *info = &state->info; | 142 | struct uart_info *info = &state->info; |
143 | struct uart_port *port = state->port; | 143 | struct uart_port *port = state->port; |
144 | unsigned long page; | 144 | unsigned long page; |
145 | int retval = 0; | 145 | int retval = 0; |
146 | 146 | ||
147 | if (info->flags & UIF_INITIALIZED) | 147 | if (info->flags & UIF_INITIALIZED) |
148 | return 0; | 148 | return 0; |
149 | 149 | ||
150 | /* | 150 | /* |
151 | * Set the TTY IO error marker - we will only clear this | 151 | * Set the TTY IO error marker - we will only clear this |
152 | * once we have successfully opened the port. Also set | 152 | * once we have successfully opened the port. Also set |
153 | * up the tty->alt_speed kludge | 153 | * up the tty->alt_speed kludge |
154 | */ | 154 | */ |
155 | set_bit(TTY_IO_ERROR, &info->port.tty->flags); | 155 | set_bit(TTY_IO_ERROR, &info->port.tty->flags); |
156 | 156 | ||
157 | if (port->type == PORT_UNKNOWN) | 157 | if (port->type == PORT_UNKNOWN) |
158 | return 0; | 158 | return 0; |
159 | 159 | ||
160 | /* | 160 | /* |
161 | * Initialise and allocate the transmit and temporary | 161 | * Initialise and allocate the transmit and temporary |
162 | * buffer. | 162 | * buffer. |
163 | */ | 163 | */ |
164 | if (!info->xmit.buf) { | 164 | if (!info->xmit.buf) { |
165 | /* This is protected by the per port mutex */ | 165 | /* This is protected by the per port mutex */ |
166 | page = get_zeroed_page(GFP_KERNEL); | 166 | page = get_zeroed_page(GFP_KERNEL); |
167 | if (!page) | 167 | if (!page) |
168 | return -ENOMEM; | 168 | return -ENOMEM; |
169 | 169 | ||
170 | info->xmit.buf = (unsigned char *) page; | 170 | info->xmit.buf = (unsigned char *) page; |
171 | uart_circ_clear(&info->xmit); | 171 | uart_circ_clear(&info->xmit); |
172 | } | 172 | } |
173 | 173 | ||
174 | retval = port->ops->startup(port); | 174 | retval = port->ops->startup(port); |
175 | if (retval == 0) { | 175 | if (retval == 0) { |
176 | if (init_hw) { | 176 | if (init_hw) { |
177 | /* | 177 | /* |
178 | * Initialise the hardware port settings. | 178 | * Initialise the hardware port settings. |
179 | */ | 179 | */ |
180 | uart_change_speed(state, NULL); | 180 | uart_change_speed(state, NULL); |
181 | 181 | ||
182 | /* | 182 | /* |
183 | * Setup the RTS and DTR signals once the | 183 | * Setup the RTS and DTR signals once the |
184 | * port is open and ready to respond. | 184 | * port is open and ready to respond. |
185 | */ | 185 | */ |
186 | if (info->port.tty->termios->c_cflag & CBAUD) | 186 | if (info->port.tty->termios->c_cflag & CBAUD) |
187 | uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR); | 187 | uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR); |
188 | } | 188 | } |
189 | 189 | ||
190 | if (info->flags & UIF_CTS_FLOW) { | 190 | if (info->flags & UIF_CTS_FLOW) { |
191 | spin_lock_irq(&port->lock); | 191 | spin_lock_irq(&port->lock); |
192 | if (!(port->ops->get_mctrl(port) & TIOCM_CTS)) | 192 | if (!(port->ops->get_mctrl(port) & TIOCM_CTS)) |
193 | info->port.tty->hw_stopped = 1; | 193 | info->port.tty->hw_stopped = 1; |
194 | spin_unlock_irq(&port->lock); | 194 | spin_unlock_irq(&port->lock); |
195 | } | 195 | } |
196 | 196 | ||
197 | info->flags |= UIF_INITIALIZED; | 197 | info->flags |= UIF_INITIALIZED; |
198 | 198 | ||
199 | clear_bit(TTY_IO_ERROR, &info->port.tty->flags); | 199 | clear_bit(TTY_IO_ERROR, &info->port.tty->flags); |
200 | } | 200 | } |
201 | 201 | ||
202 | if (retval && capable(CAP_SYS_ADMIN)) | 202 | if (retval && capable(CAP_SYS_ADMIN)) |
203 | retval = 0; | 203 | retval = 0; |
204 | 204 | ||
205 | return retval; | 205 | return retval; |
206 | } | 206 | } |
207 | 207 | ||
208 | /* | 208 | /* |
209 | * This routine will shutdown a serial port; interrupts are disabled, and | 209 | * This routine will shutdown a serial port; interrupts are disabled, and |
210 | * DTR is dropped if the hangup on close termio flag is on. Calls to | 210 | * DTR is dropped if the hangup on close termio flag is on. Calls to |
211 | * uart_shutdown are serialised by the per-port semaphore. | 211 | * uart_shutdown are serialised by the per-port semaphore. |
212 | */ | 212 | */ |
213 | static void uart_shutdown(struct uart_state *state) | 213 | static void uart_shutdown(struct uart_state *state) |
214 | { | 214 | { |
215 | struct uart_info *info = &state->info; | 215 | struct uart_info *info = &state->info; |
216 | struct uart_port *port = state->port; | 216 | struct uart_port *port = state->port; |
217 | struct tty_struct *tty = info->port.tty; | 217 | struct tty_struct *tty = info->port.tty; |
218 | 218 | ||
219 | /* | 219 | /* |
220 | * Set the TTY IO error marker | 220 | * Set the TTY IO error marker |
221 | */ | 221 | */ |
222 | if (tty) | 222 | if (tty) |
223 | set_bit(TTY_IO_ERROR, &tty->flags); | 223 | set_bit(TTY_IO_ERROR, &tty->flags); |
224 | 224 | ||
225 | if (info->flags & UIF_INITIALIZED) { | 225 | if (info->flags & UIF_INITIALIZED) { |
226 | info->flags &= ~UIF_INITIALIZED; | 226 | info->flags &= ~UIF_INITIALIZED; |
227 | 227 | ||
228 | /* | 228 | /* |
229 | * Turn off DTR and RTS early. | 229 | * Turn off DTR and RTS early. |
230 | */ | 230 | */ |
231 | if (!tty || (tty->termios->c_cflag & HUPCL)) | 231 | if (!tty || (tty->termios->c_cflag & HUPCL)) |
232 | uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); | 232 | uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); |
233 | 233 | ||
234 | /* | 234 | /* |
235 | * clear delta_msr_wait queue to avoid mem leaks: we may free | 235 | * clear delta_msr_wait queue to avoid mem leaks: we may free |
236 | * the irq here so the queue might never be woken up. Note | 236 | * the irq here so the queue might never be woken up. Note |
237 | * that we won't end up waiting on delta_msr_wait again since | 237 | * that we won't end up waiting on delta_msr_wait again since |
238 | * any outstanding file descriptors should be pointing at | 238 | * any outstanding file descriptors should be pointing at |
239 | * hung_up_tty_fops now. | 239 | * hung_up_tty_fops now. |
240 | */ | 240 | */ |
241 | wake_up_interruptible(&info->delta_msr_wait); | 241 | wake_up_interruptible(&info->delta_msr_wait); |
242 | 242 | ||
243 | /* | 243 | /* |
244 | * Free the IRQ and disable the port. | 244 | * Free the IRQ and disable the port. |
245 | */ | 245 | */ |
246 | port->ops->shutdown(port); | 246 | port->ops->shutdown(port); |
247 | 247 | ||
248 | /* | 248 | /* |
249 | * Ensure that the IRQ handler isn't running on another CPU. | 249 | * Ensure that the IRQ handler isn't running on another CPU. |
250 | */ | 250 | */ |
251 | synchronize_irq(port->irq); | 251 | synchronize_irq(port->irq); |
252 | } | 252 | } |
253 | 253 | ||
254 | /* | 254 | /* |
255 | * kill off our tasklet | 255 | * kill off our tasklet |
256 | */ | 256 | */ |
257 | tasklet_kill(&info->tlet); | 257 | tasklet_kill(&info->tlet); |
258 | 258 | ||
259 | /* | 259 | /* |
260 | * Free the transmit buffer page. | 260 | * Free the transmit buffer page. |
261 | */ | 261 | */ |
262 | if (info->xmit.buf) { | 262 | if (info->xmit.buf) { |
263 | free_page((unsigned long)info->xmit.buf); | 263 | free_page((unsigned long)info->xmit.buf); |
264 | info->xmit.buf = NULL; | 264 | info->xmit.buf = NULL; |
265 | } | 265 | } |
266 | } | 266 | } |
267 | 267 | ||
268 | /** | 268 | /** |
269 | * uart_update_timeout - update per-port FIFO timeout. | 269 | * uart_update_timeout - update per-port FIFO timeout. |
270 | * @port: uart_port structure describing the port | 270 | * @port: uart_port structure describing the port |
271 | * @cflag: termios cflag value | 271 | * @cflag: termios cflag value |
272 | * @baud: speed of the port | 272 | * @baud: speed of the port |
273 | * | 273 | * |
274 | * Set the port FIFO timeout value. The @cflag value should | 274 | * Set the port FIFO timeout value. The @cflag value should |
275 | * reflect the actual hardware settings. | 275 | * reflect the actual hardware settings. |
276 | */ | 276 | */ |
277 | void | 277 | void |
278 | uart_update_timeout(struct uart_port *port, unsigned int cflag, | 278 | uart_update_timeout(struct uart_port *port, unsigned int cflag, |
279 | unsigned int baud) | 279 | unsigned int baud) |
280 | { | 280 | { |
281 | unsigned int bits; | 281 | unsigned int bits; |
282 | 282 | ||
283 | /* byte size and parity */ | 283 | /* byte size and parity */ |
284 | switch (cflag & CSIZE) { | 284 | switch (cflag & CSIZE) { |
285 | case CS5: | 285 | case CS5: |
286 | bits = 7; | 286 | bits = 7; |
287 | break; | 287 | break; |
288 | case CS6: | 288 | case CS6: |
289 | bits = 8; | 289 | bits = 8; |
290 | break; | 290 | break; |
291 | case CS7: | 291 | case CS7: |
292 | bits = 9; | 292 | bits = 9; |
293 | break; | 293 | break; |
294 | default: | 294 | default: |
295 | bits = 10; | 295 | bits = 10; |
296 | break; /* CS8 */ | 296 | break; /* CS8 */ |
297 | } | 297 | } |
298 | 298 | ||
299 | if (cflag & CSTOPB) | 299 | if (cflag & CSTOPB) |
300 | bits++; | 300 | bits++; |
301 | if (cflag & PARENB) | 301 | if (cflag & PARENB) |
302 | bits++; | 302 | bits++; |
303 | 303 | ||
304 | /* | 304 | /* |
305 | * The total number of bits to be transmitted in the fifo. | 305 | * The total number of bits to be transmitted in the fifo. |
306 | */ | 306 | */ |
307 | bits = bits * port->fifosize; | 307 | bits = bits * port->fifosize; |
308 | 308 | ||
309 | /* | 309 | /* |
310 | * Figure the timeout to send the above number of bits. | 310 | * Figure the timeout to send the above number of bits. |
311 | * Add .02 seconds of slop | 311 | * Add .02 seconds of slop |
312 | */ | 312 | */ |
313 | port->timeout = (HZ * bits) / baud + HZ/50; | 313 | port->timeout = (HZ * bits) / baud + HZ/50; |
314 | } | 314 | } |
315 | 315 | ||
316 | EXPORT_SYMBOL(uart_update_timeout); | 316 | EXPORT_SYMBOL(uart_update_timeout); |
317 | 317 | ||
318 | /** | 318 | /** |
319 | * uart_get_baud_rate - return baud rate for a particular port | 319 | * uart_get_baud_rate - return baud rate for a particular port |
320 | * @port: uart_port structure describing the port in question. | 320 | * @port: uart_port structure describing the port in question. |
321 | * @termios: desired termios settings. | 321 | * @termios: desired termios settings. |
322 | * @old: old termios (or NULL) | 322 | * @old: old termios (or NULL) |
323 | * @min: minimum acceptable baud rate | 323 | * @min: minimum acceptable baud rate |
324 | * @max: maximum acceptable baud rate | 324 | * @max: maximum acceptable baud rate |
325 | * | 325 | * |
326 | * Decode the termios structure into a numeric baud rate, | 326 | * Decode the termios structure into a numeric baud rate, |
327 | * taking account of the magic 38400 baud rate (with spd_* | 327 | * taking account of the magic 38400 baud rate (with spd_* |
328 | * flags), and mapping the %B0 rate to 9600 baud. | 328 | * flags), and mapping the %B0 rate to 9600 baud. |
329 | * | 329 | * |
330 | * If the new baud rate is invalid, try the old termios setting. | 330 | * If the new baud rate is invalid, try the old termios setting. |
331 | * If it's still invalid, we try 9600 baud. | 331 | * If it's still invalid, we try 9600 baud. |
332 | * | 332 | * |
333 | * Update the @termios structure to reflect the baud rate | 333 | * Update the @termios structure to reflect the baud rate |
334 | * we're actually going to be using. Don't do this for the case | 334 | * we're actually going to be using. Don't do this for the case |
335 | * where B0 is requested ("hang up"). | 335 | * where B0 is requested ("hang up"). |
336 | */ | 336 | */ |
337 | unsigned int | 337 | unsigned int |
338 | uart_get_baud_rate(struct uart_port *port, struct ktermios *termios, | 338 | uart_get_baud_rate(struct uart_port *port, struct ktermios *termios, |
339 | struct ktermios *old, unsigned int min, unsigned int max) | 339 | struct ktermios *old, unsigned int min, unsigned int max) |
340 | { | 340 | { |
341 | unsigned int try, baud, altbaud = 38400; | 341 | unsigned int try, baud, altbaud = 38400; |
342 | int hung_up = 0; | 342 | int hung_up = 0; |
343 | upf_t flags = port->flags & UPF_SPD_MASK; | 343 | upf_t flags = port->flags & UPF_SPD_MASK; |
344 | 344 | ||
345 | if (flags == UPF_SPD_HI) | 345 | if (flags == UPF_SPD_HI) |
346 | altbaud = 57600; | 346 | altbaud = 57600; |
347 | if (flags == UPF_SPD_VHI) | 347 | if (flags == UPF_SPD_VHI) |
348 | altbaud = 115200; | 348 | altbaud = 115200; |
349 | if (flags == UPF_SPD_SHI) | 349 | if (flags == UPF_SPD_SHI) |
350 | altbaud = 230400; | 350 | altbaud = 230400; |
351 | if (flags == UPF_SPD_WARP) | 351 | if (flags == UPF_SPD_WARP) |
352 | altbaud = 460800; | 352 | altbaud = 460800; |
353 | 353 | ||
354 | for (try = 0; try < 2; try++) { | 354 | for (try = 0; try < 2; try++) { |
355 | baud = tty_termios_baud_rate(termios); | 355 | baud = tty_termios_baud_rate(termios); |
356 | 356 | ||
357 | /* | 357 | /* |
358 | * The spd_hi, spd_vhi, spd_shi, spd_warp kludge... | 358 | * The spd_hi, spd_vhi, spd_shi, spd_warp kludge... |
359 | * Die! Die! Die! | 359 | * Die! Die! Die! |
360 | */ | 360 | */ |
361 | if (baud == 38400) | 361 | if (baud == 38400) |
362 | baud = altbaud; | 362 | baud = altbaud; |
363 | 363 | ||
364 | /* | 364 | /* |
365 | * Special case: B0 rate. | 365 | * Special case: B0 rate. |
366 | */ | 366 | */ |
367 | if (baud == 0) { | 367 | if (baud == 0) { |
368 | hung_up = 1; | 368 | hung_up = 1; |
369 | baud = 9600; | 369 | baud = 9600; |
370 | } | 370 | } |
371 | 371 | ||
372 | if (baud >= min && baud <= max) | 372 | if (baud >= min && baud <= max) |
373 | return baud; | 373 | return baud; |
374 | 374 | ||
375 | /* | 375 | /* |
376 | * Oops, the quotient was zero. Try again with | 376 | * Oops, the quotient was zero. Try again with |
377 | * the old baud rate if possible. | 377 | * the old baud rate if possible. |
378 | */ | 378 | */ |
379 | termios->c_cflag &= ~CBAUD; | 379 | termios->c_cflag &= ~CBAUD; |
380 | if (old) { | 380 | if (old) { |
381 | baud = tty_termios_baud_rate(old); | 381 | baud = tty_termios_baud_rate(old); |
382 | if (!hung_up) | 382 | if (!hung_up) |
383 | tty_termios_encode_baud_rate(termios, | 383 | tty_termios_encode_baud_rate(termios, |
384 | baud, baud); | 384 | baud, baud); |
385 | old = NULL; | 385 | old = NULL; |
386 | continue; | 386 | continue; |
387 | } | 387 | } |
388 | 388 | ||
389 | /* | 389 | /* |
390 | * As a last resort, if the quotient is zero, | 390 | * As a last resort, if the quotient is zero, |
391 | * default to 9600 bps | 391 | * default to 9600 bps |
392 | */ | 392 | */ |
393 | if (!hung_up) | 393 | if (!hung_up) |
394 | tty_termios_encode_baud_rate(termios, 9600, 9600); | 394 | tty_termios_encode_baud_rate(termios, 9600, 9600); |
395 | } | 395 | } |
396 | 396 | ||
397 | return 0; | 397 | return 0; |
398 | } | 398 | } |
399 | 399 | ||
400 | EXPORT_SYMBOL(uart_get_baud_rate); | 400 | EXPORT_SYMBOL(uart_get_baud_rate); |
401 | 401 | ||
402 | /** | 402 | /** |
403 | * uart_get_divisor - return uart clock divisor | 403 | * uart_get_divisor - return uart clock divisor |
404 | * @port: uart_port structure describing the port. | 404 | * @port: uart_port structure describing the port. |
405 | * @baud: desired baud rate | 405 | * @baud: desired baud rate |
406 | * | 406 | * |
407 | * Calculate the uart clock divisor for the port. | 407 | * Calculate the uart clock divisor for the port. |
408 | */ | 408 | */ |
409 | unsigned int | 409 | unsigned int |
410 | uart_get_divisor(struct uart_port *port, unsigned int baud) | 410 | uart_get_divisor(struct uart_port *port, unsigned int baud) |
411 | { | 411 | { |
412 | unsigned int quot; | 412 | unsigned int quot; |
413 | 413 | ||
414 | /* | 414 | /* |
415 | * Old custom speed handling. | 415 | * Old custom speed handling. |
416 | */ | 416 | */ |
417 | if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST) | 417 | if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST) |
418 | quot = port->custom_divisor; | 418 | quot = port->custom_divisor; |
419 | else | 419 | else |
420 | quot = (port->uartclk + (8 * baud)) / (16 * baud); | 420 | quot = (port->uartclk + (8 * baud)) / (16 * baud); |
421 | 421 | ||
422 | return quot; | 422 | return quot; |
423 | } | 423 | } |
424 | 424 | ||
425 | EXPORT_SYMBOL(uart_get_divisor); | 425 | EXPORT_SYMBOL(uart_get_divisor); |
426 | 426 | ||
427 | /* FIXME: Consistent locking policy */ | 427 | /* FIXME: Consistent locking policy */ |
428 | static void | 428 | static void |
429 | uart_change_speed(struct uart_state *state, struct ktermios *old_termios) | 429 | uart_change_speed(struct uart_state *state, struct ktermios *old_termios) |
430 | { | 430 | { |
431 | struct tty_struct *tty = state->info.port.tty; | 431 | struct tty_struct *tty = state->info.port.tty; |
432 | struct uart_port *port = state->port; | 432 | struct uart_port *port = state->port; |
433 | struct ktermios *termios; | 433 | struct ktermios *termios; |
434 | 434 | ||
435 | /* | 435 | /* |
436 | * If we have no tty, termios, or the port does not exist, | 436 | * If we have no tty, termios, or the port does not exist, |
437 | * then we can't set the parameters for this port. | 437 | * then we can't set the parameters for this port. |
438 | */ | 438 | */ |
439 | if (!tty || !tty->termios || port->type == PORT_UNKNOWN) | 439 | if (!tty || !tty->termios || port->type == PORT_UNKNOWN) |
440 | return; | 440 | return; |
441 | 441 | ||
442 | termios = tty->termios; | 442 | termios = tty->termios; |
443 | 443 | ||
444 | /* | 444 | /* |
445 | * Set flags based on termios cflag | 445 | * Set flags based on termios cflag |
446 | */ | 446 | */ |
447 | if (termios->c_cflag & CRTSCTS) | 447 | if (termios->c_cflag & CRTSCTS) |
448 | state->info.flags |= UIF_CTS_FLOW; | 448 | state->info.flags |= UIF_CTS_FLOW; |
449 | else | 449 | else |
450 | state->info.flags &= ~UIF_CTS_FLOW; | 450 | state->info.flags &= ~UIF_CTS_FLOW; |
451 | 451 | ||
452 | if (termios->c_cflag & CLOCAL) | 452 | if (termios->c_cflag & CLOCAL) |
453 | state->info.flags &= ~UIF_CHECK_CD; | 453 | state->info.flags &= ~UIF_CHECK_CD; |
454 | else | 454 | else |
455 | state->info.flags |= UIF_CHECK_CD; | 455 | state->info.flags |= UIF_CHECK_CD; |
456 | 456 | ||
457 | port->ops->set_termios(port, termios, old_termios); | 457 | port->ops->set_termios(port, termios, old_termios); |
458 | } | 458 | } |
459 | 459 | ||
460 | static inline int | 460 | static inline int |
461 | __uart_put_char(struct uart_port *port, struct circ_buf *circ, unsigned char c) | 461 | __uart_put_char(struct uart_port *port, struct circ_buf *circ, unsigned char c) |
462 | { | 462 | { |
463 | unsigned long flags; | 463 | unsigned long flags; |
464 | int ret = 0; | 464 | int ret = 0; |
465 | 465 | ||
466 | if (!circ->buf) | 466 | if (!circ->buf) |
467 | return 0; | 467 | return 0; |
468 | 468 | ||
469 | spin_lock_irqsave(&port->lock, flags); | 469 | spin_lock_irqsave(&port->lock, flags); |
470 | if (uart_circ_chars_free(circ) != 0) { | 470 | if (uart_circ_chars_free(circ) != 0) { |
471 | circ->buf[circ->head] = c; | 471 | circ->buf[circ->head] = c; |
472 | circ->head = (circ->head + 1) & (UART_XMIT_SIZE - 1); | 472 | circ->head = (circ->head + 1) & (UART_XMIT_SIZE - 1); |
473 | ret = 1; | 473 | ret = 1; |
474 | } | 474 | } |
475 | spin_unlock_irqrestore(&port->lock, flags); | 475 | spin_unlock_irqrestore(&port->lock, flags); |
476 | return ret; | 476 | return ret; |
477 | } | 477 | } |
478 | 478 | ||
479 | static int uart_put_char(struct tty_struct *tty, unsigned char ch) | 479 | static int uart_put_char(struct tty_struct *tty, unsigned char ch) |
480 | { | 480 | { |
481 | struct uart_state *state = tty->driver_data; | 481 | struct uart_state *state = tty->driver_data; |
482 | 482 | ||
483 | return __uart_put_char(state->port, &state->info.xmit, ch); | 483 | return __uart_put_char(state->port, &state->info.xmit, ch); |
484 | } | 484 | } |
485 | 485 | ||
486 | static void uart_flush_chars(struct tty_struct *tty) | 486 | static void uart_flush_chars(struct tty_struct *tty) |
487 | { | 487 | { |
488 | uart_start(tty); | 488 | uart_start(tty); |
489 | } | 489 | } |
490 | 490 | ||
491 | static int | 491 | static int |
492 | uart_write(struct tty_struct *tty, const unsigned char *buf, int count) | 492 | uart_write(struct tty_struct *tty, const unsigned char *buf, int count) |
493 | { | 493 | { |
494 | struct uart_state *state = tty->driver_data; | 494 | struct uart_state *state = tty->driver_data; |
495 | struct uart_port *port; | 495 | struct uart_port *port; |
496 | struct circ_buf *circ; | 496 | struct circ_buf *circ; |
497 | unsigned long flags; | 497 | unsigned long flags; |
498 | int c, ret = 0; | 498 | int c, ret = 0; |
499 | 499 | ||
500 | /* | 500 | /* |
501 | * This means you called this function _after_ the port was | 501 | * This means you called this function _after_ the port was |
502 | * closed. No cookie for you. | 502 | * closed. No cookie for you. |
503 | */ | 503 | */ |
504 | if (!state) { | 504 | if (!state) { |
505 | WARN_ON(1); | 505 | WARN_ON(1); |
506 | return -EL3HLT; | 506 | return -EL3HLT; |
507 | } | 507 | } |
508 | 508 | ||
509 | port = state->port; | 509 | port = state->port; |
510 | circ = &state->info.xmit; | 510 | circ = &state->info.xmit; |
511 | 511 | ||
512 | if (!circ->buf) | 512 | if (!circ->buf) |
513 | return 0; | 513 | return 0; |
514 | 514 | ||
515 | spin_lock_irqsave(&port->lock, flags); | 515 | spin_lock_irqsave(&port->lock, flags); |
516 | while (1) { | 516 | while (1) { |
517 | c = CIRC_SPACE_TO_END(circ->head, circ->tail, UART_XMIT_SIZE); | 517 | c = CIRC_SPACE_TO_END(circ->head, circ->tail, UART_XMIT_SIZE); |
518 | if (count < c) | 518 | if (count < c) |
519 | c = count; | 519 | c = count; |
520 | if (c <= 0) | 520 | if (c <= 0) |
521 | break; | 521 | break; |
522 | memcpy(circ->buf + circ->head, buf, c); | 522 | memcpy(circ->buf + circ->head, buf, c); |
523 | circ->head = (circ->head + c) & (UART_XMIT_SIZE - 1); | 523 | circ->head = (circ->head + c) & (UART_XMIT_SIZE - 1); |
524 | buf += c; | 524 | buf += c; |
525 | count -= c; | 525 | count -= c; |
526 | ret += c; | 526 | ret += c; |
527 | } | 527 | } |
528 | spin_unlock_irqrestore(&port->lock, flags); | 528 | spin_unlock_irqrestore(&port->lock, flags); |
529 | 529 | ||
530 | uart_start(tty); | 530 | uart_start(tty); |
531 | return ret; | 531 | return ret; |
532 | } | 532 | } |
533 | 533 | ||
534 | static int uart_write_room(struct tty_struct *tty) | 534 | static int uart_write_room(struct tty_struct *tty) |
535 | { | 535 | { |
536 | struct uart_state *state = tty->driver_data; | 536 | struct uart_state *state = tty->driver_data; |
537 | unsigned long flags; | 537 | unsigned long flags; |
538 | int ret; | 538 | int ret; |
539 | 539 | ||
540 | spin_lock_irqsave(&state->port->lock, flags); | 540 | spin_lock_irqsave(&state->port->lock, flags); |
541 | ret = uart_circ_chars_free(&state->info.xmit); | 541 | ret = uart_circ_chars_free(&state->info.xmit); |
542 | spin_unlock_irqrestore(&state->port->lock, flags); | 542 | spin_unlock_irqrestore(&state->port->lock, flags); |
543 | return ret; | 543 | return ret; |
544 | } | 544 | } |
545 | 545 | ||
546 | static int uart_chars_in_buffer(struct tty_struct *tty) | 546 | static int uart_chars_in_buffer(struct tty_struct *tty) |
547 | { | 547 | { |
548 | struct uart_state *state = tty->driver_data; | 548 | struct uart_state *state = tty->driver_data; |
549 | unsigned long flags; | 549 | unsigned long flags; |
550 | int ret; | 550 | int ret; |
551 | 551 | ||
552 | spin_lock_irqsave(&state->port->lock, flags); | 552 | spin_lock_irqsave(&state->port->lock, flags); |
553 | ret = uart_circ_chars_pending(&state->info.xmit); | 553 | ret = uart_circ_chars_pending(&state->info.xmit); |
554 | spin_unlock_irqrestore(&state->port->lock, flags); | 554 | spin_unlock_irqrestore(&state->port->lock, flags); |
555 | return ret; | 555 | return ret; |
556 | } | 556 | } |
557 | 557 | ||
558 | static void uart_flush_buffer(struct tty_struct *tty) | 558 | static void uart_flush_buffer(struct tty_struct *tty) |
559 | { | 559 | { |
560 | struct uart_state *state = tty->driver_data; | 560 | struct uart_state *state = tty->driver_data; |
561 | struct uart_port *port; | 561 | struct uart_port *port; |
562 | unsigned long flags; | 562 | unsigned long flags; |
563 | 563 | ||
564 | /* | 564 | /* |
565 | * This means you called this function _after_ the port was | 565 | * This means you called this function _after_ the port was |
566 | * closed. No cookie for you. | 566 | * closed. No cookie for you. |
567 | */ | 567 | */ |
568 | if (!state) { | 568 | if (!state) { |
569 | WARN_ON(1); | 569 | WARN_ON(1); |
570 | return; | 570 | return; |
571 | } | 571 | } |
572 | 572 | ||
573 | port = state->port; | 573 | port = state->port; |
574 | pr_debug("uart_flush_buffer(%d) called\n", tty->index); | 574 | pr_debug("uart_flush_buffer(%d) called\n", tty->index); |
575 | 575 | ||
576 | spin_lock_irqsave(&port->lock, flags); | 576 | spin_lock_irqsave(&port->lock, flags); |
577 | uart_circ_clear(&state->info.xmit); | 577 | uart_circ_clear(&state->info.xmit); |
578 | if (port->ops->flush_buffer) | 578 | if (port->ops->flush_buffer) |
579 | port->ops->flush_buffer(port); | 579 | port->ops->flush_buffer(port); |
580 | spin_unlock_irqrestore(&port->lock, flags); | 580 | spin_unlock_irqrestore(&port->lock, flags); |
581 | tty_wakeup(tty); | 581 | tty_wakeup(tty); |
582 | } | 582 | } |
583 | 583 | ||
584 | /* | 584 | /* |
585 | * This function is used to send a high-priority XON/XOFF character to | 585 | * This function is used to send a high-priority XON/XOFF character to |
586 | * the device | 586 | * the device |
587 | */ | 587 | */ |
588 | static void uart_send_xchar(struct tty_struct *tty, char ch) | 588 | static void uart_send_xchar(struct tty_struct *tty, char ch) |
589 | { | 589 | { |
590 | struct uart_state *state = tty->driver_data; | 590 | struct uart_state *state = tty->driver_data; |
591 | struct uart_port *port = state->port; | 591 | struct uart_port *port = state->port; |
592 | unsigned long flags; | 592 | unsigned long flags; |
593 | 593 | ||
594 | if (port->ops->send_xchar) | 594 | if (port->ops->send_xchar) |
595 | port->ops->send_xchar(port, ch); | 595 | port->ops->send_xchar(port, ch); |
596 | else { | 596 | else { |
597 | port->x_char = ch; | 597 | port->x_char = ch; |
598 | if (ch) { | 598 | if (ch) { |
599 | spin_lock_irqsave(&port->lock, flags); | 599 | spin_lock_irqsave(&port->lock, flags); |
600 | port->ops->start_tx(port); | 600 | port->ops->start_tx(port); |
601 | spin_unlock_irqrestore(&port->lock, flags); | 601 | spin_unlock_irqrestore(&port->lock, flags); |
602 | } | 602 | } |
603 | } | 603 | } |
604 | } | 604 | } |
605 | 605 | ||
606 | static void uart_throttle(struct tty_struct *tty) | 606 | static void uart_throttle(struct tty_struct *tty) |
607 | { | 607 | { |
608 | struct uart_state *state = tty->driver_data; | 608 | struct uart_state *state = tty->driver_data; |
609 | 609 | ||
610 | if (I_IXOFF(tty)) | 610 | if (I_IXOFF(tty)) |
611 | uart_send_xchar(tty, STOP_CHAR(tty)); | 611 | uart_send_xchar(tty, STOP_CHAR(tty)); |
612 | 612 | ||
613 | if (tty->termios->c_cflag & CRTSCTS) | 613 | if (tty->termios->c_cflag & CRTSCTS) |
614 | uart_clear_mctrl(state->port, TIOCM_RTS); | 614 | uart_clear_mctrl(state->port, TIOCM_RTS); |
615 | } | 615 | } |
616 | 616 | ||
617 | static void uart_unthrottle(struct tty_struct *tty) | 617 | static void uart_unthrottle(struct tty_struct *tty) |
618 | { | 618 | { |
619 | struct uart_state *state = tty->driver_data; | 619 | struct uart_state *state = tty->driver_data; |
620 | struct uart_port *port = state->port; | 620 | struct uart_port *port = state->port; |
621 | 621 | ||
622 | if (I_IXOFF(tty)) { | 622 | if (I_IXOFF(tty)) { |
623 | if (port->x_char) | 623 | if (port->x_char) |
624 | port->x_char = 0; | 624 | port->x_char = 0; |
625 | else | 625 | else |
626 | uart_send_xchar(tty, START_CHAR(tty)); | 626 | uart_send_xchar(tty, START_CHAR(tty)); |
627 | } | 627 | } |
628 | 628 | ||
629 | if (tty->termios->c_cflag & CRTSCTS) | 629 | if (tty->termios->c_cflag & CRTSCTS) |
630 | uart_set_mctrl(port, TIOCM_RTS); | 630 | uart_set_mctrl(port, TIOCM_RTS); |
631 | } | 631 | } |
632 | 632 | ||
633 | static int uart_get_info(struct uart_state *state, | 633 | static int uart_get_info(struct uart_state *state, |
634 | struct serial_struct __user *retinfo) | 634 | struct serial_struct __user *retinfo) |
635 | { | 635 | { |
636 | struct uart_port *port = state->port; | 636 | struct uart_port *port = state->port; |
637 | struct serial_struct tmp; | 637 | struct serial_struct tmp; |
638 | 638 | ||
639 | memset(&tmp, 0, sizeof(tmp)); | 639 | memset(&tmp, 0, sizeof(tmp)); |
640 | 640 | ||
641 | /* Ensure the state we copy is consistent and no hardware changes | 641 | /* Ensure the state we copy is consistent and no hardware changes |
642 | occur as we go */ | 642 | occur as we go */ |
643 | mutex_lock(&state->mutex); | 643 | mutex_lock(&state->mutex); |
644 | 644 | ||
645 | tmp.type = port->type; | 645 | tmp.type = port->type; |
646 | tmp.line = port->line; | 646 | tmp.line = port->line; |
647 | tmp.port = port->iobase; | 647 | tmp.port = port->iobase; |
648 | if (HIGH_BITS_OFFSET) | 648 | if (HIGH_BITS_OFFSET) |
649 | tmp.port_high = (long) port->iobase >> HIGH_BITS_OFFSET; | 649 | tmp.port_high = (long) port->iobase >> HIGH_BITS_OFFSET; |
650 | tmp.irq = port->irq; | 650 | tmp.irq = port->irq; |
651 | tmp.flags = port->flags; | 651 | tmp.flags = port->flags; |
652 | tmp.xmit_fifo_size = port->fifosize; | 652 | tmp.xmit_fifo_size = port->fifosize; |
653 | tmp.baud_base = port->uartclk / 16; | 653 | tmp.baud_base = port->uartclk / 16; |
654 | tmp.close_delay = state->close_delay / 10; | 654 | tmp.close_delay = state->close_delay / 10; |
655 | tmp.closing_wait = state->closing_wait == USF_CLOSING_WAIT_NONE ? | 655 | tmp.closing_wait = state->closing_wait == USF_CLOSING_WAIT_NONE ? |
656 | ASYNC_CLOSING_WAIT_NONE : | 656 | ASYNC_CLOSING_WAIT_NONE : |
657 | state->closing_wait / 10; | 657 | state->closing_wait / 10; |
658 | tmp.custom_divisor = port->custom_divisor; | 658 | tmp.custom_divisor = port->custom_divisor; |
659 | tmp.hub6 = port->hub6; | 659 | tmp.hub6 = port->hub6; |
660 | tmp.io_type = port->iotype; | 660 | tmp.io_type = port->iotype; |
661 | tmp.iomem_reg_shift = port->regshift; | 661 | tmp.iomem_reg_shift = port->regshift; |
662 | tmp.iomem_base = (void *)(unsigned long)port->mapbase; | 662 | tmp.iomem_base = (void *)(unsigned long)port->mapbase; |
663 | 663 | ||
664 | mutex_unlock(&state->mutex); | 664 | mutex_unlock(&state->mutex); |
665 | 665 | ||
666 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) | 666 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
667 | return -EFAULT; | 667 | return -EFAULT; |
668 | return 0; | 668 | return 0; |
669 | } | 669 | } |
670 | 670 | ||
671 | static int uart_set_info(struct uart_state *state, | 671 | static int uart_set_info(struct uart_state *state, |
672 | struct serial_struct __user *newinfo) | 672 | struct serial_struct __user *newinfo) |
673 | { | 673 | { |
674 | struct serial_struct new_serial; | 674 | struct serial_struct new_serial; |
675 | struct uart_port *port = state->port; | 675 | struct uart_port *port = state->port; |
676 | unsigned long new_port; | 676 | unsigned long new_port; |
677 | unsigned int change_irq, change_port, closing_wait; | 677 | unsigned int change_irq, change_port, closing_wait; |
678 | unsigned int old_custom_divisor, close_delay; | 678 | unsigned int old_custom_divisor, close_delay; |
679 | upf_t old_flags, new_flags; | 679 | upf_t old_flags, new_flags; |
680 | int retval = 0; | 680 | int retval = 0; |
681 | 681 | ||
682 | if (copy_from_user(&new_serial, newinfo, sizeof(new_serial))) | 682 | if (copy_from_user(&new_serial, newinfo, sizeof(new_serial))) |
683 | return -EFAULT; | 683 | return -EFAULT; |
684 | 684 | ||
685 | new_port = new_serial.port; | 685 | new_port = new_serial.port; |
686 | if (HIGH_BITS_OFFSET) | 686 | if (HIGH_BITS_OFFSET) |
687 | new_port += (unsigned long) new_serial.port_high << HIGH_BITS_OFFSET; | 687 | new_port += (unsigned long) new_serial.port_high << HIGH_BITS_OFFSET; |
688 | 688 | ||
689 | new_serial.irq = irq_canonicalize(new_serial.irq); | 689 | new_serial.irq = irq_canonicalize(new_serial.irq); |
690 | close_delay = new_serial.close_delay * 10; | 690 | close_delay = new_serial.close_delay * 10; |
691 | closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ? | 691 | closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ? |
692 | USF_CLOSING_WAIT_NONE : new_serial.closing_wait * 10; | 692 | USF_CLOSING_WAIT_NONE : new_serial.closing_wait * 10; |
693 | 693 | ||
694 | /* | 694 | /* |
695 | * This semaphore protects state->count. It is also | 695 | * This semaphore protects state->count. It is also |
696 | * very useful to prevent opens. Also, take the | 696 | * very useful to prevent opens. Also, take the |
697 | * port configuration semaphore to make sure that a | 697 | * port configuration semaphore to make sure that a |
698 | * module insertion/removal doesn't change anything | 698 | * module insertion/removal doesn't change anything |
699 | * under us. | 699 | * under us. |
700 | */ | 700 | */ |
701 | mutex_lock(&state->mutex); | 701 | mutex_lock(&state->mutex); |
702 | 702 | ||
703 | change_irq = !(port->flags & UPF_FIXED_PORT) | 703 | change_irq = !(port->flags & UPF_FIXED_PORT) |
704 | && new_serial.irq != port->irq; | 704 | && new_serial.irq != port->irq; |
705 | 705 | ||
706 | /* | 706 | /* |
707 | * Since changing the 'type' of the port changes its resource | 707 | * Since changing the 'type' of the port changes its resource |
708 | * allocations, we should treat type changes the same as | 708 | * allocations, we should treat type changes the same as |
709 | * IO port changes. | 709 | * IO port changes. |
710 | */ | 710 | */ |
711 | change_port = !(port->flags & UPF_FIXED_PORT) | 711 | change_port = !(port->flags & UPF_FIXED_PORT) |
712 | && (new_port != port->iobase || | 712 | && (new_port != port->iobase || |
713 | (unsigned long)new_serial.iomem_base != port->mapbase || | 713 | (unsigned long)new_serial.iomem_base != port->mapbase || |
714 | new_serial.hub6 != port->hub6 || | 714 | new_serial.hub6 != port->hub6 || |
715 | new_serial.io_type != port->iotype || | 715 | new_serial.io_type != port->iotype || |
716 | new_serial.iomem_reg_shift != port->regshift || | 716 | new_serial.iomem_reg_shift != port->regshift || |
717 | new_serial.type != port->type); | 717 | new_serial.type != port->type); |
718 | 718 | ||
719 | old_flags = port->flags; | 719 | old_flags = port->flags; |
720 | new_flags = new_serial.flags; | 720 | new_flags = new_serial.flags; |
721 | old_custom_divisor = port->custom_divisor; | 721 | old_custom_divisor = port->custom_divisor; |
722 | 722 | ||
723 | if (!capable(CAP_SYS_ADMIN)) { | 723 | if (!capable(CAP_SYS_ADMIN)) { |
724 | retval = -EPERM; | 724 | retval = -EPERM; |
725 | if (change_irq || change_port || | 725 | if (change_irq || change_port || |
726 | (new_serial.baud_base != port->uartclk / 16) || | 726 | (new_serial.baud_base != port->uartclk / 16) || |
727 | (close_delay != state->close_delay) || | 727 | (close_delay != state->close_delay) || |
728 | (closing_wait != state->closing_wait) || | 728 | (closing_wait != state->closing_wait) || |
729 | (new_serial.xmit_fifo_size && | 729 | (new_serial.xmit_fifo_size && |
730 | new_serial.xmit_fifo_size != port->fifosize) || | 730 | new_serial.xmit_fifo_size != port->fifosize) || |
731 | (((new_flags ^ old_flags) & ~UPF_USR_MASK) != 0)) | 731 | (((new_flags ^ old_flags) & ~UPF_USR_MASK) != 0)) |
732 | goto exit; | 732 | goto exit; |
733 | port->flags = ((port->flags & ~UPF_USR_MASK) | | 733 | port->flags = ((port->flags & ~UPF_USR_MASK) | |
734 | (new_flags & UPF_USR_MASK)); | 734 | (new_flags & UPF_USR_MASK)); |
735 | port->custom_divisor = new_serial.custom_divisor; | 735 | port->custom_divisor = new_serial.custom_divisor; |
736 | goto check_and_exit; | 736 | goto check_and_exit; |
737 | } | 737 | } |
738 | 738 | ||
739 | /* | 739 | /* |
740 | * Ask the low level driver to verify the settings. | 740 | * Ask the low level driver to verify the settings. |
741 | */ | 741 | */ |
742 | if (port->ops->verify_port) | 742 | if (port->ops->verify_port) |
743 | retval = port->ops->verify_port(port, &new_serial); | 743 | retval = port->ops->verify_port(port, &new_serial); |
744 | 744 | ||
745 | if ((new_serial.irq >= nr_irqs) || (new_serial.irq < 0) || | 745 | if ((new_serial.irq >= nr_irqs) || (new_serial.irq < 0) || |
746 | (new_serial.baud_base < 9600)) | 746 | (new_serial.baud_base < 9600)) |
747 | retval = -EINVAL; | 747 | retval = -EINVAL; |
748 | 748 | ||
749 | if (retval) | 749 | if (retval) |
750 | goto exit; | 750 | goto exit; |
751 | 751 | ||
752 | if (change_port || change_irq) { | 752 | if (change_port || change_irq) { |
753 | retval = -EBUSY; | 753 | retval = -EBUSY; |
754 | 754 | ||
755 | /* | 755 | /* |
756 | * Make sure that we are the sole user of this port. | 756 | * Make sure that we are the sole user of this port. |
757 | */ | 757 | */ |
758 | if (uart_users(state) > 1) | 758 | if (uart_users(state) > 1) |
759 | goto exit; | 759 | goto exit; |
760 | 760 | ||
761 | /* | 761 | /* |
762 | * We need to shutdown the serial port at the old | 762 | * We need to shutdown the serial port at the old |
763 | * port/type/irq combination. | 763 | * port/type/irq combination. |
764 | */ | 764 | */ |
765 | uart_shutdown(state); | 765 | uart_shutdown(state); |
766 | } | 766 | } |
767 | 767 | ||
768 | if (change_port) { | 768 | if (change_port) { |
769 | unsigned long old_iobase, old_mapbase; | 769 | unsigned long old_iobase, old_mapbase; |
770 | unsigned int old_type, old_iotype, old_hub6, old_shift; | 770 | unsigned int old_type, old_iotype, old_hub6, old_shift; |
771 | 771 | ||
772 | old_iobase = port->iobase; | 772 | old_iobase = port->iobase; |
773 | old_mapbase = port->mapbase; | 773 | old_mapbase = port->mapbase; |
774 | old_type = port->type; | 774 | old_type = port->type; |
775 | old_hub6 = port->hub6; | 775 | old_hub6 = port->hub6; |
776 | old_iotype = port->iotype; | 776 | old_iotype = port->iotype; |
777 | old_shift = port->regshift; | 777 | old_shift = port->regshift; |
778 | 778 | ||
779 | /* | 779 | /* |
780 | * Free and release old regions | 780 | * Free and release old regions |
781 | */ | 781 | */ |
782 | if (old_type != PORT_UNKNOWN) | 782 | if (old_type != PORT_UNKNOWN) |
783 | port->ops->release_port(port); | 783 | port->ops->release_port(port); |
784 | 784 | ||
785 | port->iobase = new_port; | 785 | port->iobase = new_port; |
786 | port->type = new_serial.type; | 786 | port->type = new_serial.type; |
787 | port->hub6 = new_serial.hub6; | 787 | port->hub6 = new_serial.hub6; |
788 | port->iotype = new_serial.io_type; | 788 | port->iotype = new_serial.io_type; |
789 | port->regshift = new_serial.iomem_reg_shift; | 789 | port->regshift = new_serial.iomem_reg_shift; |
790 | port->mapbase = (unsigned long)new_serial.iomem_base; | 790 | port->mapbase = (unsigned long)new_serial.iomem_base; |
791 | 791 | ||
792 | /* | 792 | /* |
793 | * Claim and map the new regions | 793 | * Claim and map the new regions |
794 | */ | 794 | */ |
795 | if (port->type != PORT_UNKNOWN) { | 795 | if (port->type != PORT_UNKNOWN) { |
796 | retval = port->ops->request_port(port); | 796 | retval = port->ops->request_port(port); |
797 | } else { | 797 | } else { |
798 | /* Always success - Jean II */ | 798 | /* Always success - Jean II */ |
799 | retval = 0; | 799 | retval = 0; |
800 | } | 800 | } |
801 | 801 | ||
802 | /* | 802 | /* |
803 | * If we fail to request resources for the | 803 | * If we fail to request resources for the |
804 | * new port, try to restore the old settings. | 804 | * new port, try to restore the old settings. |
805 | */ | 805 | */ |
806 | if (retval && old_type != PORT_UNKNOWN) { | 806 | if (retval && old_type != PORT_UNKNOWN) { |
807 | port->iobase = old_iobase; | 807 | port->iobase = old_iobase; |
808 | port->type = old_type; | 808 | port->type = old_type; |
809 | port->hub6 = old_hub6; | 809 | port->hub6 = old_hub6; |
810 | port->iotype = old_iotype; | 810 | port->iotype = old_iotype; |
811 | port->regshift = old_shift; | 811 | port->regshift = old_shift; |
812 | port->mapbase = old_mapbase; | 812 | port->mapbase = old_mapbase; |
813 | retval = port->ops->request_port(port); | 813 | retval = port->ops->request_port(port); |
814 | /* | 814 | /* |
815 | * If we failed to restore the old settings, | 815 | * If we failed to restore the old settings, |
816 | * we fail like this. | 816 | * we fail like this. |
817 | */ | 817 | */ |
818 | if (retval) | 818 | if (retval) |
819 | port->type = PORT_UNKNOWN; | 819 | port->type = PORT_UNKNOWN; |
820 | 820 | ||
821 | /* | 821 | /* |
822 | * We failed anyway. | 822 | * We failed anyway. |
823 | */ | 823 | */ |
824 | retval = -EBUSY; | 824 | retval = -EBUSY; |
825 | /* Added to return the correct error -Ram Gupta */ | 825 | /* Added to return the correct error -Ram Gupta */ |
826 | goto exit; | 826 | goto exit; |
827 | } | 827 | } |
828 | } | 828 | } |
829 | 829 | ||
830 | if (change_irq) | 830 | if (change_irq) |
831 | port->irq = new_serial.irq; | 831 | port->irq = new_serial.irq; |
832 | if (!(port->flags & UPF_FIXED_PORT)) | 832 | if (!(port->flags & UPF_FIXED_PORT)) |
833 | port->uartclk = new_serial.baud_base * 16; | 833 | port->uartclk = new_serial.baud_base * 16; |
834 | port->flags = (port->flags & ~UPF_CHANGE_MASK) | | 834 | port->flags = (port->flags & ~UPF_CHANGE_MASK) | |
835 | (new_flags & UPF_CHANGE_MASK); | 835 | (new_flags & UPF_CHANGE_MASK); |
836 | port->custom_divisor = new_serial.custom_divisor; | 836 | port->custom_divisor = new_serial.custom_divisor; |
837 | state->close_delay = close_delay; | 837 | state->close_delay = close_delay; |
838 | state->closing_wait = closing_wait; | 838 | state->closing_wait = closing_wait; |
839 | if (new_serial.xmit_fifo_size) | 839 | if (new_serial.xmit_fifo_size) |
840 | port->fifosize = new_serial.xmit_fifo_size; | 840 | port->fifosize = new_serial.xmit_fifo_size; |
841 | if (state->info.port.tty) | 841 | if (state->info.port.tty) |
842 | state->info.port.tty->low_latency = | 842 | state->info.port.tty->low_latency = |
843 | (port->flags & UPF_LOW_LATENCY) ? 1 : 0; | 843 | (port->flags & UPF_LOW_LATENCY) ? 1 : 0; |
844 | 844 | ||
845 | check_and_exit: | 845 | check_and_exit: |
846 | retval = 0; | 846 | retval = 0; |
847 | if (port->type == PORT_UNKNOWN) | 847 | if (port->type == PORT_UNKNOWN) |
848 | goto exit; | 848 | goto exit; |
849 | if (state->info.flags & UIF_INITIALIZED) { | 849 | if (state->info.flags & UIF_INITIALIZED) { |
850 | if (((old_flags ^ port->flags) & UPF_SPD_MASK) || | 850 | if (((old_flags ^ port->flags) & UPF_SPD_MASK) || |
851 | old_custom_divisor != port->custom_divisor) { | 851 | old_custom_divisor != port->custom_divisor) { |
852 | /* | 852 | /* |
853 | * If they're setting up a custom divisor or speed, | 853 | * If they're setting up a custom divisor or speed, |
854 | * instead of clearing it, then bitch about it. No | 854 | * instead of clearing it, then bitch about it. No |
855 | * need to rate-limit; it's CAP_SYS_ADMIN only. | 855 | * need to rate-limit; it's CAP_SYS_ADMIN only. |
856 | */ | 856 | */ |
857 | if (port->flags & UPF_SPD_MASK) { | 857 | if (port->flags & UPF_SPD_MASK) { |
858 | char buf[64]; | 858 | char buf[64]; |
859 | printk(KERN_NOTICE | 859 | printk(KERN_NOTICE |
860 | "%s sets custom speed on %s. This " | 860 | "%s sets custom speed on %s. This " |
861 | "is deprecated.\n", current->comm, | 861 | "is deprecated.\n", current->comm, |
862 | tty_name(state->info.port.tty, buf)); | 862 | tty_name(state->info.port.tty, buf)); |
863 | } | 863 | } |
864 | uart_change_speed(state, NULL); | 864 | uart_change_speed(state, NULL); |
865 | } | 865 | } |
866 | } else | 866 | } else |
867 | retval = uart_startup(state, 1); | 867 | retval = uart_startup(state, 1); |
868 | exit: | 868 | exit: |
869 | mutex_unlock(&state->mutex); | 869 | mutex_unlock(&state->mutex); |
870 | return retval; | 870 | return retval; |
871 | } | 871 | } |
872 | 872 | ||
873 | 873 | ||
874 | /* | 874 | /* |
875 | * uart_get_lsr_info - get line status register info. | 875 | * uart_get_lsr_info - get line status register info. |
876 | * Note: uart_ioctl protects us against hangups. | 876 | * Note: uart_ioctl protects us against hangups. |
877 | */ | 877 | */ |
878 | static int uart_get_lsr_info(struct uart_state *state, | 878 | static int uart_get_lsr_info(struct uart_state *state, |
879 | unsigned int __user *value) | 879 | unsigned int __user *value) |
880 | { | 880 | { |
881 | struct uart_port *port = state->port; | 881 | struct uart_port *port = state->port; |
882 | unsigned int result; | 882 | unsigned int result; |
883 | 883 | ||
884 | result = port->ops->tx_empty(port); | 884 | result = port->ops->tx_empty(port); |
885 | 885 | ||
886 | /* | 886 | /* |
887 | * If we're about to load something into the transmit | 887 | * If we're about to load something into the transmit |
888 | * register, we'll pretend the transmitter isn't empty to | 888 | * register, we'll pretend the transmitter isn't empty to |
889 | * avoid a race condition (depending on when the transmit | 889 | * avoid a race condition (depending on when the transmit |
890 | * interrupt happens). | 890 | * interrupt happens). |
891 | */ | 891 | */ |
892 | if (port->x_char || | 892 | if (port->x_char || |
893 | ((uart_circ_chars_pending(&state->info.xmit) > 0) && | 893 | ((uart_circ_chars_pending(&state->info.xmit) > 0) && |
894 | !state->info.port.tty->stopped && !state->info.port.tty->hw_stopped)) | 894 | !state->info.port.tty->stopped && !state->info.port.tty->hw_stopped)) |
895 | result &= ~TIOCSER_TEMT; | 895 | result &= ~TIOCSER_TEMT; |
896 | 896 | ||
897 | return put_user(result, value); | 897 | return put_user(result, value); |
898 | } | 898 | } |
899 | 899 | ||
900 | static int uart_tiocmget(struct tty_struct *tty, struct file *file) | 900 | static int uart_tiocmget(struct tty_struct *tty, struct file *file) |
901 | { | 901 | { |
902 | struct uart_state *state = tty->driver_data; | 902 | struct uart_state *state = tty->driver_data; |
903 | struct uart_port *port = state->port; | 903 | struct uart_port *port = state->port; |
904 | int result = -EIO; | 904 | int result = -EIO; |
905 | 905 | ||
906 | mutex_lock(&state->mutex); | 906 | mutex_lock(&state->mutex); |
907 | if ((!file || !tty_hung_up_p(file)) && | 907 | if ((!file || !tty_hung_up_p(file)) && |
908 | !(tty->flags & (1 << TTY_IO_ERROR))) { | 908 | !(tty->flags & (1 << TTY_IO_ERROR))) { |
909 | result = port->mctrl; | 909 | result = port->mctrl; |
910 | 910 | ||
911 | spin_lock_irq(&port->lock); | 911 | spin_lock_irq(&port->lock); |
912 | result |= port->ops->get_mctrl(port); | 912 | result |= port->ops->get_mctrl(port); |
913 | spin_unlock_irq(&port->lock); | 913 | spin_unlock_irq(&port->lock); |
914 | } | 914 | } |
915 | mutex_unlock(&state->mutex); | 915 | mutex_unlock(&state->mutex); |
916 | 916 | ||
917 | return result; | 917 | return result; |
918 | } | 918 | } |
919 | 919 | ||
920 | static int | 920 | static int |
921 | uart_tiocmset(struct tty_struct *tty, struct file *file, | 921 | uart_tiocmset(struct tty_struct *tty, struct file *file, |
922 | unsigned int set, unsigned int clear) | 922 | unsigned int set, unsigned int clear) |
923 | { | 923 | { |
924 | struct uart_state *state = tty->driver_data; | 924 | struct uart_state *state = tty->driver_data; |
925 | struct uart_port *port = state->port; | 925 | struct uart_port *port = state->port; |
926 | int ret = -EIO; | 926 | int ret = -EIO; |
927 | 927 | ||
928 | mutex_lock(&state->mutex); | 928 | mutex_lock(&state->mutex); |
929 | if ((!file || !tty_hung_up_p(file)) && | 929 | if ((!file || !tty_hung_up_p(file)) && |
930 | !(tty->flags & (1 << TTY_IO_ERROR))) { | 930 | !(tty->flags & (1 << TTY_IO_ERROR))) { |
931 | uart_update_mctrl(port, set, clear); | 931 | uart_update_mctrl(port, set, clear); |
932 | ret = 0; | 932 | ret = 0; |
933 | } | 933 | } |
934 | mutex_unlock(&state->mutex); | 934 | mutex_unlock(&state->mutex); |
935 | return ret; | 935 | return ret; |
936 | } | 936 | } |
937 | 937 | ||
938 | static int uart_break_ctl(struct tty_struct *tty, int break_state) | 938 | static int uart_break_ctl(struct tty_struct *tty, int break_state) |
939 | { | 939 | { |
940 | struct uart_state *state = tty->driver_data; | 940 | struct uart_state *state = tty->driver_data; |
941 | struct uart_port *port = state->port; | 941 | struct uart_port *port = state->port; |
942 | 942 | ||
943 | mutex_lock(&state->mutex); | 943 | mutex_lock(&state->mutex); |
944 | 944 | ||
945 | if (port->type != PORT_UNKNOWN) | 945 | if (port->type != PORT_UNKNOWN) |
946 | port->ops->break_ctl(port, break_state); | 946 | port->ops->break_ctl(port, break_state); |
947 | 947 | ||
948 | mutex_unlock(&state->mutex); | 948 | mutex_unlock(&state->mutex); |
949 | return 0; | 949 | return 0; |
950 | } | 950 | } |
951 | 951 | ||
952 | static int uart_do_autoconfig(struct uart_state *state) | 952 | static int uart_do_autoconfig(struct uart_state *state) |
953 | { | 953 | { |
954 | struct uart_port *port = state->port; | 954 | struct uart_port *port = state->port; |
955 | int flags, ret; | 955 | int flags, ret; |
956 | 956 | ||
957 | if (!capable(CAP_SYS_ADMIN)) | 957 | if (!capable(CAP_SYS_ADMIN)) |
958 | return -EPERM; | 958 | return -EPERM; |
959 | 959 | ||
960 | /* | 960 | /* |
961 | * Take the per-port semaphore. This prevents count from | 961 | * Take the per-port semaphore. This prevents count from |
962 | * changing, and hence any extra opens of the port while | 962 | * changing, and hence any extra opens of the port while |
963 | * we're auto-configuring. | 963 | * we're auto-configuring. |
964 | */ | 964 | */ |
965 | if (mutex_lock_interruptible(&state->mutex)) | 965 | if (mutex_lock_interruptible(&state->mutex)) |
966 | return -ERESTARTSYS; | 966 | return -ERESTARTSYS; |
967 | 967 | ||
968 | ret = -EBUSY; | 968 | ret = -EBUSY; |
969 | if (uart_users(state) == 1) { | 969 | if (uart_users(state) == 1) { |
970 | uart_shutdown(state); | 970 | uart_shutdown(state); |
971 | 971 | ||
972 | /* | 972 | /* |
973 | * If we already have a port type configured, | 973 | * If we already have a port type configured, |
974 | * we must release its resources. | 974 | * we must release its resources. |
975 | */ | 975 | */ |
976 | if (port->type != PORT_UNKNOWN) | 976 | if (port->type != PORT_UNKNOWN) |
977 | port->ops->release_port(port); | 977 | port->ops->release_port(port); |
978 | 978 | ||
979 | flags = UART_CONFIG_TYPE; | 979 | flags = UART_CONFIG_TYPE; |
980 | if (port->flags & UPF_AUTO_IRQ) | 980 | if (port->flags & UPF_AUTO_IRQ) |
981 | flags |= UART_CONFIG_IRQ; | 981 | flags |= UART_CONFIG_IRQ; |
982 | 982 | ||
983 | /* | 983 | /* |
984 | * This will claim the ports resources if | 984 | * This will claim the ports resources if |
985 | * a port is found. | 985 | * a port is found. |
986 | */ | 986 | */ |
987 | port->ops->config_port(port, flags); | 987 | port->ops->config_port(port, flags); |
988 | 988 | ||
989 | ret = uart_startup(state, 1); | 989 | ret = uart_startup(state, 1); |
990 | } | 990 | } |
991 | mutex_unlock(&state->mutex); | 991 | mutex_unlock(&state->mutex); |
992 | return ret; | 992 | return ret; |
993 | } | 993 | } |
994 | 994 | ||
995 | /* | 995 | /* |
996 | * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change | 996 | * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change |
997 | * - mask passed in arg for lines of interest | 997 | * - mask passed in arg for lines of interest |
998 | * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking) | 998 | * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking) |
999 | * Caller should use TIOCGICOUNT to see which one it was | 999 | * Caller should use TIOCGICOUNT to see which one it was |
1000 | */ | 1000 | */ |
1001 | static int | 1001 | static int |
1002 | uart_wait_modem_status(struct uart_state *state, unsigned long arg) | 1002 | uart_wait_modem_status(struct uart_state *state, unsigned long arg) |
1003 | { | 1003 | { |
1004 | struct uart_port *port = state->port; | 1004 | struct uart_port *port = state->port; |
1005 | DECLARE_WAITQUEUE(wait, current); | 1005 | DECLARE_WAITQUEUE(wait, current); |
1006 | struct uart_icount cprev, cnow; | 1006 | struct uart_icount cprev, cnow; |
1007 | int ret; | 1007 | int ret; |
1008 | 1008 | ||
1009 | /* | 1009 | /* |
1010 | * note the counters on entry | 1010 | * note the counters on entry |
1011 | */ | 1011 | */ |
1012 | spin_lock_irq(&port->lock); | 1012 | spin_lock_irq(&port->lock); |
1013 | memcpy(&cprev, &port->icount, sizeof(struct uart_icount)); | 1013 | memcpy(&cprev, &port->icount, sizeof(struct uart_icount)); |
1014 | 1014 | ||
1015 | /* | 1015 | /* |
1016 | * Force modem status interrupts on | 1016 | * Force modem status interrupts on |
1017 | */ | 1017 | */ |
1018 | port->ops->enable_ms(port); | 1018 | port->ops->enable_ms(port); |
1019 | spin_unlock_irq(&port->lock); | 1019 | spin_unlock_irq(&port->lock); |
1020 | 1020 | ||
1021 | add_wait_queue(&state->info.delta_msr_wait, &wait); | 1021 | add_wait_queue(&state->info.delta_msr_wait, &wait); |
1022 | for (;;) { | 1022 | for (;;) { |
1023 | spin_lock_irq(&port->lock); | 1023 | spin_lock_irq(&port->lock); |
1024 | memcpy(&cnow, &port->icount, sizeof(struct uart_icount)); | 1024 | memcpy(&cnow, &port->icount, sizeof(struct uart_icount)); |
1025 | spin_unlock_irq(&port->lock); | 1025 | spin_unlock_irq(&port->lock); |
1026 | 1026 | ||
1027 | set_current_state(TASK_INTERRUPTIBLE); | 1027 | set_current_state(TASK_INTERRUPTIBLE); |
1028 | 1028 | ||
1029 | if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || | 1029 | if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || |
1030 | ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || | 1030 | ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || |
1031 | ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || | 1031 | ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || |
1032 | ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) { | 1032 | ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) { |
1033 | ret = 0; | 1033 | ret = 0; |
1034 | break; | 1034 | break; |
1035 | } | 1035 | } |
1036 | 1036 | ||
1037 | schedule(); | 1037 | schedule(); |
1038 | 1038 | ||
1039 | /* see if a signal did it */ | 1039 | /* see if a signal did it */ |
1040 | if (signal_pending(current)) { | 1040 | if (signal_pending(current)) { |
1041 | ret = -ERESTARTSYS; | 1041 | ret = -ERESTARTSYS; |
1042 | break; | 1042 | break; |
1043 | } | 1043 | } |
1044 | 1044 | ||
1045 | cprev = cnow; | 1045 | cprev = cnow; |
1046 | } | 1046 | } |
1047 | 1047 | ||
1048 | current->state = TASK_RUNNING; | 1048 | current->state = TASK_RUNNING; |
1049 | remove_wait_queue(&state->info.delta_msr_wait, &wait); | 1049 | remove_wait_queue(&state->info.delta_msr_wait, &wait); |
1050 | 1050 | ||
1051 | return ret; | 1051 | return ret; |
1052 | } | 1052 | } |
1053 | 1053 | ||
1054 | /* | 1054 | /* |
1055 | * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) | 1055 | * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) |
1056 | * Return: write counters to the user passed counter struct | 1056 | * Return: write counters to the user passed counter struct |
1057 | * NB: both 1->0 and 0->1 transitions are counted except for | 1057 | * NB: both 1->0 and 0->1 transitions are counted except for |
1058 | * RI where only 0->1 is counted. | 1058 | * RI where only 0->1 is counted. |
1059 | */ | 1059 | */ |
1060 | static int uart_get_count(struct uart_state *state, | 1060 | static int uart_get_count(struct uart_state *state, |
1061 | struct serial_icounter_struct __user *icnt) | 1061 | struct serial_icounter_struct __user *icnt) |
1062 | { | 1062 | { |
1063 | struct serial_icounter_struct icount; | 1063 | struct serial_icounter_struct icount; |
1064 | struct uart_icount cnow; | 1064 | struct uart_icount cnow; |
1065 | struct uart_port *port = state->port; | 1065 | struct uart_port *port = state->port; |
1066 | 1066 | ||
1067 | spin_lock_irq(&port->lock); | 1067 | spin_lock_irq(&port->lock); |
1068 | memcpy(&cnow, &port->icount, sizeof(struct uart_icount)); | 1068 | memcpy(&cnow, &port->icount, sizeof(struct uart_icount)); |
1069 | spin_unlock_irq(&port->lock); | 1069 | spin_unlock_irq(&port->lock); |
1070 | 1070 | ||
1071 | icount.cts = cnow.cts; | 1071 | icount.cts = cnow.cts; |
1072 | icount.dsr = cnow.dsr; | 1072 | icount.dsr = cnow.dsr; |
1073 | icount.rng = cnow.rng; | 1073 | icount.rng = cnow.rng; |
1074 | icount.dcd = cnow.dcd; | 1074 | icount.dcd = cnow.dcd; |
1075 | icount.rx = cnow.rx; | 1075 | icount.rx = cnow.rx; |
1076 | icount.tx = cnow.tx; | 1076 | icount.tx = cnow.tx; |
1077 | icount.frame = cnow.frame; | 1077 | icount.frame = cnow.frame; |
1078 | icount.overrun = cnow.overrun; | 1078 | icount.overrun = cnow.overrun; |
1079 | icount.parity = cnow.parity; | 1079 | icount.parity = cnow.parity; |
1080 | icount.brk = cnow.brk; | 1080 | icount.brk = cnow.brk; |
1081 | icount.buf_overrun = cnow.buf_overrun; | 1081 | icount.buf_overrun = cnow.buf_overrun; |
1082 | 1082 | ||
1083 | return copy_to_user(icnt, &icount, sizeof(icount)) ? -EFAULT : 0; | 1083 | return copy_to_user(icnt, &icount, sizeof(icount)) ? -EFAULT : 0; |
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | /* | 1086 | /* |
1087 | * Called via sys_ioctl. We can use spin_lock_irq() here. | 1087 | * Called via sys_ioctl. We can use spin_lock_irq() here. |
1088 | */ | 1088 | */ |
1089 | static int | 1089 | static int |
1090 | uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, | 1090 | uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, |
1091 | unsigned long arg) | 1091 | unsigned long arg) |
1092 | { | 1092 | { |
1093 | struct uart_state *state = tty->driver_data; | 1093 | struct uart_state *state = tty->driver_data; |
1094 | void __user *uarg = (void __user *)arg; | 1094 | void __user *uarg = (void __user *)arg; |
1095 | int ret = -ENOIOCTLCMD; | 1095 | int ret = -ENOIOCTLCMD; |
1096 | 1096 | ||
1097 | 1097 | ||
1098 | /* | 1098 | /* |
1099 | * These ioctls don't rely on the hardware to be present. | 1099 | * These ioctls don't rely on the hardware to be present. |
1100 | */ | 1100 | */ |
1101 | switch (cmd) { | 1101 | switch (cmd) { |
1102 | case TIOCGSERIAL: | 1102 | case TIOCGSERIAL: |
1103 | ret = uart_get_info(state, uarg); | 1103 | ret = uart_get_info(state, uarg); |
1104 | break; | 1104 | break; |
1105 | 1105 | ||
1106 | case TIOCSSERIAL: | 1106 | case TIOCSSERIAL: |
1107 | ret = uart_set_info(state, uarg); | 1107 | ret = uart_set_info(state, uarg); |
1108 | break; | 1108 | break; |
1109 | 1109 | ||
1110 | case TIOCSERCONFIG: | 1110 | case TIOCSERCONFIG: |
1111 | ret = uart_do_autoconfig(state); | 1111 | ret = uart_do_autoconfig(state); |
1112 | break; | 1112 | break; |
1113 | 1113 | ||
1114 | case TIOCSERGWILD: /* obsolete */ | 1114 | case TIOCSERGWILD: /* obsolete */ |
1115 | case TIOCSERSWILD: /* obsolete */ | 1115 | case TIOCSERSWILD: /* obsolete */ |
1116 | ret = 0; | 1116 | ret = 0; |
1117 | break; | 1117 | break; |
1118 | } | 1118 | } |
1119 | 1119 | ||
1120 | if (ret != -ENOIOCTLCMD) | 1120 | if (ret != -ENOIOCTLCMD) |
1121 | goto out; | 1121 | goto out; |
1122 | 1122 | ||
1123 | if (tty->flags & (1 << TTY_IO_ERROR)) { | 1123 | if (tty->flags & (1 << TTY_IO_ERROR)) { |
1124 | ret = -EIO; | 1124 | ret = -EIO; |
1125 | goto out; | 1125 | goto out; |
1126 | } | 1126 | } |
1127 | 1127 | ||
1128 | /* | 1128 | /* |
1129 | * The following should only be used when hardware is present. | 1129 | * The following should only be used when hardware is present. |
1130 | */ | 1130 | */ |
1131 | switch (cmd) { | 1131 | switch (cmd) { |
1132 | case TIOCMIWAIT: | 1132 | case TIOCMIWAIT: |
1133 | ret = uart_wait_modem_status(state, arg); | 1133 | ret = uart_wait_modem_status(state, arg); |
1134 | break; | 1134 | break; |
1135 | 1135 | ||
1136 | case TIOCGICOUNT: | 1136 | case TIOCGICOUNT: |
1137 | ret = uart_get_count(state, uarg); | 1137 | ret = uart_get_count(state, uarg); |
1138 | break; | 1138 | break; |
1139 | } | 1139 | } |
1140 | 1140 | ||
1141 | if (ret != -ENOIOCTLCMD) | 1141 | if (ret != -ENOIOCTLCMD) |
1142 | goto out; | 1142 | goto out; |
1143 | 1143 | ||
1144 | mutex_lock(&state->mutex); | 1144 | mutex_lock(&state->mutex); |
1145 | 1145 | ||
1146 | if (tty_hung_up_p(filp)) { | 1146 | if (tty_hung_up_p(filp)) { |
1147 | ret = -EIO; | 1147 | ret = -EIO; |
1148 | goto out_up; | 1148 | goto out_up; |
1149 | } | 1149 | } |
1150 | 1150 | ||
1151 | /* | 1151 | /* |
1152 | * All these rely on hardware being present and need to be | 1152 | * All these rely on hardware being present and need to be |
1153 | * protected against the tty being hung up. | 1153 | * protected against the tty being hung up. |
1154 | */ | 1154 | */ |
1155 | switch (cmd) { | 1155 | switch (cmd) { |
1156 | case TIOCSERGETLSR: /* Get line status register */ | 1156 | case TIOCSERGETLSR: /* Get line status register */ |
1157 | ret = uart_get_lsr_info(state, uarg); | 1157 | ret = uart_get_lsr_info(state, uarg); |
1158 | break; | 1158 | break; |
1159 | 1159 | ||
1160 | default: { | 1160 | default: { |
1161 | struct uart_port *port = state->port; | 1161 | struct uart_port *port = state->port; |
1162 | if (port->ops->ioctl) | 1162 | if (port->ops->ioctl) |
1163 | ret = port->ops->ioctl(port, cmd, arg); | 1163 | ret = port->ops->ioctl(port, cmd, arg); |
1164 | break; | 1164 | break; |
1165 | } | 1165 | } |
1166 | } | 1166 | } |
1167 | out_up: | 1167 | out_up: |
1168 | mutex_unlock(&state->mutex); | 1168 | mutex_unlock(&state->mutex); |
1169 | out: | 1169 | out: |
1170 | return ret; | 1170 | return ret; |
1171 | } | 1171 | } |
1172 | 1172 | ||
1173 | static void uart_set_ldisc(struct tty_struct *tty) | 1173 | static void uart_set_ldisc(struct tty_struct *tty) |
1174 | { | 1174 | { |
1175 | struct uart_state *state = tty->driver_data; | 1175 | struct uart_state *state = tty->driver_data; |
1176 | struct uart_port *port = state->port; | 1176 | struct uart_port *port = state->port; |
1177 | 1177 | ||
1178 | if (port->ops->set_ldisc) | 1178 | if (port->ops->set_ldisc) |
1179 | port->ops->set_ldisc(port); | 1179 | port->ops->set_ldisc(port); |
1180 | } | 1180 | } |
1181 | 1181 | ||
1182 | static void uart_set_termios(struct tty_struct *tty, | 1182 | static void uart_set_termios(struct tty_struct *tty, |
1183 | struct ktermios *old_termios) | 1183 | struct ktermios *old_termios) |
1184 | { | 1184 | { |
1185 | struct uart_state *state = tty->driver_data; | 1185 | struct uart_state *state = tty->driver_data; |
1186 | unsigned long flags; | 1186 | unsigned long flags; |
1187 | unsigned int cflag = tty->termios->c_cflag; | 1187 | unsigned int cflag = tty->termios->c_cflag; |
1188 | 1188 | ||
1189 | 1189 | ||
1190 | /* | 1190 | /* |
1191 | * These are the bits that are used to setup various | 1191 | * These are the bits that are used to setup various |
1192 | * flags in the low level driver. We can ignore the Bfoo | 1192 | * flags in the low level driver. We can ignore the Bfoo |
1193 | * bits in c_cflag; c_[io]speed will always be set | 1193 | * bits in c_cflag; c_[io]speed will always be set |
1194 | * appropriately by set_termios() in tty_ioctl.c | 1194 | * appropriately by set_termios() in tty_ioctl.c |
1195 | */ | 1195 | */ |
1196 | #define RELEVANT_IFLAG(iflag) ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) | 1196 | #define RELEVANT_IFLAG(iflag) ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) |
1197 | if ((cflag ^ old_termios->c_cflag) == 0 && | 1197 | if ((cflag ^ old_termios->c_cflag) == 0 && |
1198 | tty->termios->c_ospeed == old_termios->c_ospeed && | 1198 | tty->termios->c_ospeed == old_termios->c_ospeed && |
1199 | tty->termios->c_ispeed == old_termios->c_ispeed && | 1199 | tty->termios->c_ispeed == old_termios->c_ispeed && |
1200 | RELEVANT_IFLAG(tty->termios->c_iflag ^ old_termios->c_iflag) == 0) { | 1200 | RELEVANT_IFLAG(tty->termios->c_iflag ^ old_termios->c_iflag) == 0) { |
1201 | return; | 1201 | return; |
1202 | } | 1202 | } |
1203 | 1203 | ||
1204 | uart_change_speed(state, old_termios); | 1204 | uart_change_speed(state, old_termios); |
1205 | 1205 | ||
1206 | /* Handle transition to B0 status */ | 1206 | /* Handle transition to B0 status */ |
1207 | if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD)) | 1207 | if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD)) |
1208 | uart_clear_mctrl(state->port, TIOCM_RTS | TIOCM_DTR); | 1208 | uart_clear_mctrl(state->port, TIOCM_RTS | TIOCM_DTR); |
1209 | 1209 | ||
1210 | /* Handle transition away from B0 status */ | 1210 | /* Handle transition away from B0 status */ |
1211 | if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) { | 1211 | if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) { |
1212 | unsigned int mask = TIOCM_DTR; | 1212 | unsigned int mask = TIOCM_DTR; |
1213 | if (!(cflag & CRTSCTS) || | 1213 | if (!(cflag & CRTSCTS) || |
1214 | !test_bit(TTY_THROTTLED, &tty->flags)) | 1214 | !test_bit(TTY_THROTTLED, &tty->flags)) |
1215 | mask |= TIOCM_RTS; | 1215 | mask |= TIOCM_RTS; |
1216 | uart_set_mctrl(state->port, mask); | 1216 | uart_set_mctrl(state->port, mask); |
1217 | } | 1217 | } |
1218 | 1218 | ||
1219 | /* Handle turning off CRTSCTS */ | 1219 | /* Handle turning off CRTSCTS */ |
1220 | if ((old_termios->c_cflag & CRTSCTS) && !(cflag & CRTSCTS)) { | 1220 | if ((old_termios->c_cflag & CRTSCTS) && !(cflag & CRTSCTS)) { |
1221 | spin_lock_irqsave(&state->port->lock, flags); | 1221 | spin_lock_irqsave(&state->port->lock, flags); |
1222 | tty->hw_stopped = 0; | 1222 | tty->hw_stopped = 0; |
1223 | __uart_start(tty); | 1223 | __uart_start(tty); |
1224 | spin_unlock_irqrestore(&state->port->lock, flags); | 1224 | spin_unlock_irqrestore(&state->port->lock, flags); |
1225 | } | 1225 | } |
1226 | 1226 | ||
1227 | /* Handle turning on CRTSCTS */ | 1227 | /* Handle turning on CRTSCTS */ |
1228 | if (!(old_termios->c_cflag & CRTSCTS) && (cflag & CRTSCTS)) { | 1228 | if (!(old_termios->c_cflag & CRTSCTS) && (cflag & CRTSCTS)) { |
1229 | spin_lock_irqsave(&state->port->lock, flags); | 1229 | spin_lock_irqsave(&state->port->lock, flags); |
1230 | if (!(state->port->ops->get_mctrl(state->port) & TIOCM_CTS)) { | 1230 | if (!(state->port->ops->get_mctrl(state->port) & TIOCM_CTS)) { |
1231 | tty->hw_stopped = 1; | 1231 | tty->hw_stopped = 1; |
1232 | state->port->ops->stop_tx(state->port); | 1232 | state->port->ops->stop_tx(state->port); |
1233 | } | 1233 | } |
1234 | spin_unlock_irqrestore(&state->port->lock, flags); | 1234 | spin_unlock_irqrestore(&state->port->lock, flags); |
1235 | } | 1235 | } |
1236 | #if 0 | 1236 | #if 0 |
1237 | /* | 1237 | /* |
1238 | * No need to wake up processes in open wait, since they | 1238 | * No need to wake up processes in open wait, since they |
1239 | * sample the CLOCAL flag once, and don't recheck it. | 1239 | * sample the CLOCAL flag once, and don't recheck it. |
1240 | * XXX It's not clear whether the current behavior is correct | 1240 | * XXX It's not clear whether the current behavior is correct |
1241 | * or not. Hence, this may change..... | 1241 | * or not. Hence, this may change..... |
1242 | */ | 1242 | */ |
1243 | if (!(old_termios->c_cflag & CLOCAL) && | 1243 | if (!(old_termios->c_cflag & CLOCAL) && |
1244 | (tty->termios->c_cflag & CLOCAL)) | 1244 | (tty->termios->c_cflag & CLOCAL)) |
1245 | wake_up_interruptible(&info->port.open_wait); | 1245 | wake_up_interruptible(&info->port.open_wait); |
1246 | #endif | 1246 | #endif |
1247 | } | 1247 | } |
1248 | 1248 | ||
1249 | /* | 1249 | /* |
1250 | * In 2.4.5, calls to this will be serialized via the BKL in | 1250 | * In 2.4.5, calls to this will be serialized via the BKL in |
1251 | * linux/drivers/char/tty_io.c:tty_release() | 1251 | * linux/drivers/char/tty_io.c:tty_release() |
1252 | * linux/drivers/char/tty_io.c:do_tty_handup() | 1252 | * linux/drivers/char/tty_io.c:do_tty_handup() |
1253 | */ | 1253 | */ |
1254 | static void uart_close(struct tty_struct *tty, struct file *filp) | 1254 | static void uart_close(struct tty_struct *tty, struct file *filp) |
1255 | { | 1255 | { |
1256 | struct uart_state *state = tty->driver_data; | 1256 | struct uart_state *state = tty->driver_data; |
1257 | struct uart_port *port; | 1257 | struct uart_port *port; |
1258 | 1258 | ||
1259 | BUG_ON(!kernel_locked()); | 1259 | BUG_ON(!kernel_locked()); |
1260 | 1260 | ||
1261 | if (!state || !state->port) | 1261 | if (!state || !state->port) |
1262 | return; | 1262 | return; |
1263 | 1263 | ||
1264 | port = state->port; | 1264 | port = state->port; |
1265 | 1265 | ||
1266 | pr_debug("uart_close(%d) called\n", port->line); | 1266 | pr_debug("uart_close(%d) called\n", port->line); |
1267 | 1267 | ||
1268 | mutex_lock(&state->mutex); | 1268 | mutex_lock(&state->mutex); |
1269 | 1269 | ||
1270 | if (tty_hung_up_p(filp)) | 1270 | if (tty_hung_up_p(filp)) |
1271 | goto done; | 1271 | goto done; |
1272 | 1272 | ||
1273 | if ((tty->count == 1) && (state->count != 1)) { | 1273 | if ((tty->count == 1) && (state->count != 1)) { |
1274 | /* | 1274 | /* |
1275 | * Uh, oh. tty->count is 1, which means that the tty | 1275 | * Uh, oh. tty->count is 1, which means that the tty |
1276 | * structure will be freed. state->count should always | 1276 | * structure will be freed. state->count should always |
1277 | * be one in these conditions. If it's greater than | 1277 | * be one in these conditions. If it's greater than |
1278 | * one, we've got real problems, since it means the | 1278 | * one, we've got real problems, since it means the |
1279 | * serial port won't be shutdown. | 1279 | * serial port won't be shutdown. |
1280 | */ | 1280 | */ |
1281 | printk(KERN_ERR "uart_close: bad serial port count; tty->count is 1, " | 1281 | printk(KERN_ERR "uart_close: bad serial port count; tty->count is 1, " |
1282 | "state->count is %d\n", state->count); | 1282 | "state->count is %d\n", state->count); |
1283 | state->count = 1; | 1283 | state->count = 1; |
1284 | } | 1284 | } |
1285 | if (--state->count < 0) { | 1285 | if (--state->count < 0) { |
1286 | printk(KERN_ERR "uart_close: bad serial port count for %s: %d\n", | 1286 | printk(KERN_ERR "uart_close: bad serial port count for %s: %d\n", |
1287 | tty->name, state->count); | 1287 | tty->name, state->count); |
1288 | state->count = 0; | 1288 | state->count = 0; |
1289 | } | 1289 | } |
1290 | if (state->count) | 1290 | if (state->count) |
1291 | goto done; | 1291 | goto done; |
1292 | 1292 | ||
1293 | /* | 1293 | /* |
1294 | * Now we wait for the transmit buffer to clear; and we notify | 1294 | * Now we wait for the transmit buffer to clear; and we notify |
1295 | * the line discipline to only process XON/XOFF characters by | 1295 | * the line discipline to only process XON/XOFF characters by |
1296 | * setting tty->closing. | 1296 | * setting tty->closing. |
1297 | */ | 1297 | */ |
1298 | tty->closing = 1; | 1298 | tty->closing = 1; |
1299 | 1299 | ||
1300 | if (state->closing_wait != USF_CLOSING_WAIT_NONE) | 1300 | if (state->closing_wait != USF_CLOSING_WAIT_NONE) |
1301 | tty_wait_until_sent(tty, msecs_to_jiffies(state->closing_wait)); | 1301 | tty_wait_until_sent(tty, msecs_to_jiffies(state->closing_wait)); |
1302 | 1302 | ||
1303 | /* | 1303 | /* |
1304 | * At this point, we stop accepting input. To do this, we | 1304 | * At this point, we stop accepting input. To do this, we |
1305 | * disable the receive line status interrupts. | 1305 | * disable the receive line status interrupts. |
1306 | */ | 1306 | */ |
1307 | if (state->info.flags & UIF_INITIALIZED) { | 1307 | if (state->info.flags & UIF_INITIALIZED) { |
1308 | unsigned long flags; | 1308 | unsigned long flags; |
1309 | spin_lock_irqsave(&port->lock, flags); | 1309 | spin_lock_irqsave(&port->lock, flags); |
1310 | port->ops->stop_rx(port); | 1310 | port->ops->stop_rx(port); |
1311 | spin_unlock_irqrestore(&port->lock, flags); | 1311 | spin_unlock_irqrestore(&port->lock, flags); |
1312 | /* | 1312 | /* |
1313 | * Before we drop DTR, make sure the UART transmitter | 1313 | * Before we drop DTR, make sure the UART transmitter |
1314 | * has completely drained; this is especially | 1314 | * has completely drained; this is especially |
1315 | * important if there is a transmit FIFO! | 1315 | * important if there is a transmit FIFO! |
1316 | */ | 1316 | */ |
1317 | uart_wait_until_sent(tty, port->timeout); | 1317 | uart_wait_until_sent(tty, port->timeout); |
1318 | } | 1318 | } |
1319 | 1319 | ||
1320 | uart_shutdown(state); | 1320 | uart_shutdown(state); |
1321 | uart_flush_buffer(tty); | 1321 | uart_flush_buffer(tty); |
1322 | 1322 | ||
1323 | tty_ldisc_flush(tty); | 1323 | tty_ldisc_flush(tty); |
1324 | 1324 | ||
1325 | tty->closing = 0; | 1325 | tty->closing = 0; |
1326 | state->info.port.tty = NULL; | 1326 | state->info.port.tty = NULL; |
1327 | 1327 | ||
1328 | if (state->info.port.blocked_open) { | 1328 | if (state->info.port.blocked_open) { |
1329 | if (state->close_delay) | 1329 | if (state->close_delay) |
1330 | msleep_interruptible(state->close_delay); | 1330 | msleep_interruptible(state->close_delay); |
1331 | } else if (!uart_console(port)) { | 1331 | } else if (!uart_console(port)) { |
1332 | uart_change_pm(state, 3); | 1332 | uart_change_pm(state, 3); |
1333 | } | 1333 | } |
1334 | 1334 | ||
1335 | /* | 1335 | /* |
1336 | * Wake up anyone trying to open this port. | 1336 | * Wake up anyone trying to open this port. |
1337 | */ | 1337 | */ |
1338 | state->info.flags &= ~UIF_NORMAL_ACTIVE; | 1338 | state->info.flags &= ~UIF_NORMAL_ACTIVE; |
1339 | wake_up_interruptible(&state->info.port.open_wait); | 1339 | wake_up_interruptible(&state->info.port.open_wait); |
1340 | 1340 | ||
1341 | done: | 1341 | done: |
1342 | mutex_unlock(&state->mutex); | 1342 | mutex_unlock(&state->mutex); |
1343 | } | 1343 | } |
1344 | 1344 | ||
1345 | static void uart_wait_until_sent(struct tty_struct *tty, int timeout) | 1345 | static void uart_wait_until_sent(struct tty_struct *tty, int timeout) |
1346 | { | 1346 | { |
1347 | struct uart_state *state = tty->driver_data; | 1347 | struct uart_state *state = tty->driver_data; |
1348 | struct uart_port *port = state->port; | 1348 | struct uart_port *port = state->port; |
1349 | unsigned long char_time, expire; | 1349 | unsigned long char_time, expire; |
1350 | 1350 | ||
1351 | if (port->type == PORT_UNKNOWN || port->fifosize == 0) | 1351 | if (port->type == PORT_UNKNOWN || port->fifosize == 0) |
1352 | return; | 1352 | return; |
1353 | 1353 | ||
1354 | lock_kernel(); | 1354 | lock_kernel(); |
1355 | 1355 | ||
1356 | /* | 1356 | /* |
1357 | * Set the check interval to be 1/5 of the estimated time to | 1357 | * Set the check interval to be 1/5 of the estimated time to |
1358 | * send a single character, and make it at least 1. The check | 1358 | * send a single character, and make it at least 1. The check |
1359 | * interval should also be less than the timeout. | 1359 | * interval should also be less than the timeout. |
1360 | * | 1360 | * |
1361 | * Note: we have to use pretty tight timings here to satisfy | 1361 | * Note: we have to use pretty tight timings here to satisfy |
1362 | * the NIST-PCTS. | 1362 | * the NIST-PCTS. |
1363 | */ | 1363 | */ |
1364 | char_time = (port->timeout - HZ/50) / port->fifosize; | 1364 | char_time = (port->timeout - HZ/50) / port->fifosize; |
1365 | char_time = char_time / 5; | 1365 | char_time = char_time / 5; |
1366 | if (char_time == 0) | 1366 | if (char_time == 0) |
1367 | char_time = 1; | 1367 | char_time = 1; |
1368 | if (timeout && timeout < char_time) | 1368 | if (timeout && timeout < char_time) |
1369 | char_time = timeout; | 1369 | char_time = timeout; |
1370 | 1370 | ||
1371 | /* | 1371 | /* |
1372 | * If the transmitter hasn't cleared in twice the approximate | 1372 | * If the transmitter hasn't cleared in twice the approximate |
1373 | * amount of time to send the entire FIFO, it probably won't | 1373 | * amount of time to send the entire FIFO, it probably won't |
1374 | * ever clear. This assumes the UART isn't doing flow | 1374 | * ever clear. This assumes the UART isn't doing flow |
1375 | * control, which is currently the case. Hence, if it ever | 1375 | * control, which is currently the case. Hence, if it ever |
1376 | * takes longer than port->timeout, this is probably due to a | 1376 | * takes longer than port->timeout, this is probably due to a |
1377 | * UART bug of some kind. So, we clamp the timeout parameter at | 1377 | * UART bug of some kind. So, we clamp the timeout parameter at |
1378 | * 2*port->timeout. | 1378 | * 2*port->timeout. |
1379 | */ | 1379 | */ |
1380 | if (timeout == 0 || timeout > 2 * port->timeout) | 1380 | if (timeout == 0 || timeout > 2 * port->timeout) |
1381 | timeout = 2 * port->timeout; | 1381 | timeout = 2 * port->timeout; |
1382 | 1382 | ||
1383 | expire = jiffies + timeout; | 1383 | expire = jiffies + timeout; |
1384 | 1384 | ||
1385 | pr_debug("uart_wait_until_sent(%d), jiffies=%lu, expire=%lu...\n", | 1385 | pr_debug("uart_wait_until_sent(%d), jiffies=%lu, expire=%lu...\n", |
1386 | port->line, jiffies, expire); | 1386 | port->line, jiffies, expire); |
1387 | 1387 | ||
1388 | /* | 1388 | /* |
1389 | * Check whether the transmitter is empty every 'char_time'. | 1389 | * Check whether the transmitter is empty every 'char_time'. |
1390 | * 'timeout' / 'expire' give us the maximum amount of time | 1390 | * 'timeout' / 'expire' give us the maximum amount of time |
1391 | * we wait. | 1391 | * we wait. |
1392 | */ | 1392 | */ |
1393 | while (!port->ops->tx_empty(port)) { | 1393 | while (!port->ops->tx_empty(port)) { |
1394 | msleep_interruptible(jiffies_to_msecs(char_time)); | 1394 | msleep_interruptible(jiffies_to_msecs(char_time)); |
1395 | if (signal_pending(current)) | 1395 | if (signal_pending(current)) |
1396 | break; | 1396 | break; |
1397 | if (time_after(jiffies, expire)) | 1397 | if (time_after(jiffies, expire)) |
1398 | break; | 1398 | break; |
1399 | } | 1399 | } |
1400 | set_current_state(TASK_RUNNING); /* might not be needed */ | 1400 | set_current_state(TASK_RUNNING); /* might not be needed */ |
1401 | unlock_kernel(); | 1401 | unlock_kernel(); |
1402 | } | 1402 | } |
1403 | 1403 | ||
1404 | /* | 1404 | /* |
1405 | * This is called with the BKL held in | 1405 | * This is called with the BKL held in |
1406 | * linux/drivers/char/tty_io.c:do_tty_hangup() | 1406 | * linux/drivers/char/tty_io.c:do_tty_hangup() |
1407 | * We're called from the eventd thread, so we can sleep for | 1407 | * We're called from the eventd thread, so we can sleep for |
1408 | * a _short_ time only. | 1408 | * a _short_ time only. |
1409 | */ | 1409 | */ |
1410 | static void uart_hangup(struct tty_struct *tty) | 1410 | static void uart_hangup(struct tty_struct *tty) |
1411 | { | 1411 | { |
1412 | struct uart_state *state = tty->driver_data; | 1412 | struct uart_state *state = tty->driver_data; |
1413 | struct uart_info *info = &state->info; | 1413 | struct uart_info *info = &state->info; |
1414 | 1414 | ||
1415 | BUG_ON(!kernel_locked()); | 1415 | BUG_ON(!kernel_locked()); |
1416 | pr_debug("uart_hangup(%d)\n", state->port->line); | 1416 | pr_debug("uart_hangup(%d)\n", state->port->line); |
1417 | 1417 | ||
1418 | mutex_lock(&state->mutex); | 1418 | mutex_lock(&state->mutex); |
1419 | if (info->flags & UIF_NORMAL_ACTIVE) { | 1419 | if (info->flags & UIF_NORMAL_ACTIVE) { |
1420 | uart_flush_buffer(tty); | 1420 | uart_flush_buffer(tty); |
1421 | uart_shutdown(state); | 1421 | uart_shutdown(state); |
1422 | state->count = 0; | 1422 | state->count = 0; |
1423 | info->flags &= ~UIF_NORMAL_ACTIVE; | 1423 | info->flags &= ~UIF_NORMAL_ACTIVE; |
1424 | info->port.tty = NULL; | 1424 | info->port.tty = NULL; |
1425 | wake_up_interruptible(&info->port.open_wait); | 1425 | wake_up_interruptible(&info->port.open_wait); |
1426 | wake_up_interruptible(&info->delta_msr_wait); | 1426 | wake_up_interruptible(&info->delta_msr_wait); |
1427 | } | 1427 | } |
1428 | mutex_unlock(&state->mutex); | 1428 | mutex_unlock(&state->mutex); |
1429 | } | 1429 | } |
1430 | 1430 | ||
1431 | /* | 1431 | /* |
1432 | * Copy across the serial console cflag setting into the termios settings | 1432 | * Copy across the serial console cflag setting into the termios settings |
1433 | * for the initial open of the port. This allows continuity between the | 1433 | * for the initial open of the port. This allows continuity between the |
1434 | * kernel settings, and the settings init adopts when it opens the port | 1434 | * kernel settings, and the settings init adopts when it opens the port |
1435 | * for the first time. | 1435 | * for the first time. |
1436 | */ | 1436 | */ |
1437 | static void uart_update_termios(struct uart_state *state) | 1437 | static void uart_update_termios(struct uart_state *state) |
1438 | { | 1438 | { |
1439 | struct tty_struct *tty = state->info.port.tty; | 1439 | struct tty_struct *tty = state->info.port.tty; |
1440 | struct uart_port *port = state->port; | 1440 | struct uart_port *port = state->port; |
1441 | 1441 | ||
1442 | if (uart_console(port) && port->cons->cflag) { | 1442 | if (uart_console(port) && port->cons->cflag) { |
1443 | tty->termios->c_cflag = port->cons->cflag; | 1443 | tty->termios->c_cflag = port->cons->cflag; |
1444 | port->cons->cflag = 0; | 1444 | port->cons->cflag = 0; |
1445 | } | 1445 | } |
1446 | 1446 | ||
1447 | /* | 1447 | /* |
1448 | * If the device failed to grab its irq resources, | 1448 | * If the device failed to grab its irq resources, |
1449 | * or some other error occurred, don't try to talk | 1449 | * or some other error occurred, don't try to talk |
1450 | * to the port hardware. | 1450 | * to the port hardware. |
1451 | */ | 1451 | */ |
1452 | if (!(tty->flags & (1 << TTY_IO_ERROR))) { | 1452 | if (!(tty->flags & (1 << TTY_IO_ERROR))) { |
1453 | /* | 1453 | /* |
1454 | * Make termios settings take effect. | 1454 | * Make termios settings take effect. |
1455 | */ | 1455 | */ |
1456 | uart_change_speed(state, NULL); | 1456 | uart_change_speed(state, NULL); |
1457 | 1457 | ||
1458 | /* | 1458 | /* |
1459 | * And finally enable the RTS and DTR signals. | 1459 | * And finally enable the RTS and DTR signals. |
1460 | */ | 1460 | */ |
1461 | if (tty->termios->c_cflag & CBAUD) | 1461 | if (tty->termios->c_cflag & CBAUD) |
1462 | uart_set_mctrl(port, TIOCM_DTR | TIOCM_RTS); | 1462 | uart_set_mctrl(port, TIOCM_DTR | TIOCM_RTS); |
1463 | } | 1463 | } |
1464 | } | 1464 | } |
1465 | 1465 | ||
1466 | /* | 1466 | /* |
1467 | * Block the open until the port is ready. We must be called with | 1467 | * Block the open until the port is ready. We must be called with |
1468 | * the per-port semaphore held. | 1468 | * the per-port semaphore held. |
1469 | */ | 1469 | */ |
1470 | static int | 1470 | static int |
1471 | uart_block_til_ready(struct file *filp, struct uart_state *state) | 1471 | uart_block_til_ready(struct file *filp, struct uart_state *state) |
1472 | { | 1472 | { |
1473 | DECLARE_WAITQUEUE(wait, current); | 1473 | DECLARE_WAITQUEUE(wait, current); |
1474 | struct uart_info *info = &state->info; | 1474 | struct uart_info *info = &state->info; |
1475 | struct uart_port *port = state->port; | 1475 | struct uart_port *port = state->port; |
1476 | unsigned int mctrl; | 1476 | unsigned int mctrl; |
1477 | 1477 | ||
1478 | info->port.blocked_open++; | 1478 | info->port.blocked_open++; |
1479 | state->count--; | 1479 | state->count--; |
1480 | 1480 | ||
1481 | add_wait_queue(&info->port.open_wait, &wait); | 1481 | add_wait_queue(&info->port.open_wait, &wait); |
1482 | while (1) { | 1482 | while (1) { |
1483 | set_current_state(TASK_INTERRUPTIBLE); | 1483 | set_current_state(TASK_INTERRUPTIBLE); |
1484 | 1484 | ||
1485 | /* | 1485 | /* |
1486 | * If we have been hung up, tell userspace/restart open. | 1486 | * If we have been hung up, tell userspace/restart open. |
1487 | */ | 1487 | */ |
1488 | if (tty_hung_up_p(filp) || info->port.tty == NULL) | 1488 | if (tty_hung_up_p(filp) || info->port.tty == NULL) |
1489 | break; | 1489 | break; |
1490 | 1490 | ||
1491 | /* | 1491 | /* |
1492 | * If the port has been closed, tell userspace/restart open. | 1492 | * If the port has been closed, tell userspace/restart open. |
1493 | */ | 1493 | */ |
1494 | if (!(info->flags & UIF_INITIALIZED)) | 1494 | if (!(info->flags & UIF_INITIALIZED)) |
1495 | break; | 1495 | break; |
1496 | 1496 | ||
1497 | /* | 1497 | /* |
1498 | * If non-blocking mode is set, or CLOCAL mode is set, | 1498 | * If non-blocking mode is set, or CLOCAL mode is set, |
1499 | * we don't want to wait for the modem status lines to | 1499 | * we don't want to wait for the modem status lines to |
1500 | * indicate that the port is ready. | 1500 | * indicate that the port is ready. |
1501 | * | 1501 | * |
1502 | * Also, if the port is not enabled/configured, we want | 1502 | * Also, if the port is not enabled/configured, we want |
1503 | * to allow the open to succeed here. Note that we will | 1503 | * to allow the open to succeed here. Note that we will |
1504 | * have set TTY_IO_ERROR for a non-existant port. | 1504 | * have set TTY_IO_ERROR for a non-existant port. |
1505 | */ | 1505 | */ |
1506 | if ((filp->f_flags & O_NONBLOCK) || | 1506 | if ((filp->f_flags & O_NONBLOCK) || |
1507 | (info->port.tty->termios->c_cflag & CLOCAL) || | 1507 | (info->port.tty->termios->c_cflag & CLOCAL) || |
1508 | (info->port.tty->flags & (1 << TTY_IO_ERROR))) | 1508 | (info->port.tty->flags & (1 << TTY_IO_ERROR))) |
1509 | break; | 1509 | break; |
1510 | 1510 | ||
1511 | /* | 1511 | /* |
1512 | * Set DTR to allow modem to know we're waiting. Do | 1512 | * Set DTR to allow modem to know we're waiting. Do |
1513 | * not set RTS here - we want to make sure we catch | 1513 | * not set RTS here - we want to make sure we catch |
1514 | * the data from the modem. | 1514 | * the data from the modem. |
1515 | */ | 1515 | */ |
1516 | if (info->port.tty->termios->c_cflag & CBAUD) | 1516 | if (info->port.tty->termios->c_cflag & CBAUD) |
1517 | uart_set_mctrl(port, TIOCM_DTR); | 1517 | uart_set_mctrl(port, TIOCM_DTR); |
1518 | 1518 | ||
1519 | /* | 1519 | /* |
1520 | * and wait for the carrier to indicate that the | 1520 | * and wait for the carrier to indicate that the |
1521 | * modem is ready for us. | 1521 | * modem is ready for us. |
1522 | */ | 1522 | */ |
1523 | spin_lock_irq(&port->lock); | 1523 | spin_lock_irq(&port->lock); |
1524 | port->ops->enable_ms(port); | 1524 | port->ops->enable_ms(port); |
1525 | mctrl = port->ops->get_mctrl(port); | 1525 | mctrl = port->ops->get_mctrl(port); |
1526 | spin_unlock_irq(&port->lock); | 1526 | spin_unlock_irq(&port->lock); |
1527 | if (mctrl & TIOCM_CAR) | 1527 | if (mctrl & TIOCM_CAR) |
1528 | break; | 1528 | break; |
1529 | 1529 | ||
1530 | mutex_unlock(&state->mutex); | 1530 | mutex_unlock(&state->mutex); |
1531 | schedule(); | 1531 | schedule(); |
1532 | mutex_lock(&state->mutex); | 1532 | mutex_lock(&state->mutex); |
1533 | 1533 | ||
1534 | if (signal_pending(current)) | 1534 | if (signal_pending(current)) |
1535 | break; | 1535 | break; |
1536 | } | 1536 | } |
1537 | set_current_state(TASK_RUNNING); | 1537 | set_current_state(TASK_RUNNING); |
1538 | remove_wait_queue(&info->port.open_wait, &wait); | 1538 | remove_wait_queue(&info->port.open_wait, &wait); |
1539 | 1539 | ||
1540 | state->count++; | 1540 | state->count++; |
1541 | info->port.blocked_open--; | 1541 | info->port.blocked_open--; |
1542 | 1542 | ||
1543 | if (signal_pending(current)) | 1543 | if (signal_pending(current)) |
1544 | return -ERESTARTSYS; | 1544 | return -ERESTARTSYS; |
1545 | 1545 | ||
1546 | if (!info->port.tty || tty_hung_up_p(filp)) | 1546 | if (!info->port.tty || tty_hung_up_p(filp)) |
1547 | return -EAGAIN; | 1547 | return -EAGAIN; |
1548 | 1548 | ||
1549 | return 0; | 1549 | return 0; |
1550 | } | 1550 | } |
1551 | 1551 | ||
1552 | static struct uart_state *uart_get(struct uart_driver *drv, int line) | 1552 | static struct uart_state *uart_get(struct uart_driver *drv, int line) |
1553 | { | 1553 | { |
1554 | struct uart_state *state; | 1554 | struct uart_state *state; |
1555 | int ret = 0; | 1555 | int ret = 0; |
1556 | 1556 | ||
1557 | state = drv->state + line; | 1557 | state = drv->state + line; |
1558 | if (mutex_lock_interruptible(&state->mutex)) { | 1558 | if (mutex_lock_interruptible(&state->mutex)) { |
1559 | ret = -ERESTARTSYS; | 1559 | ret = -ERESTARTSYS; |
1560 | goto err; | 1560 | goto err; |
1561 | } | 1561 | } |
1562 | 1562 | ||
1563 | state->count++; | 1563 | state->count++; |
1564 | if (!state->port || state->port->flags & UPF_DEAD) { | 1564 | if (!state->port || state->port->flags & UPF_DEAD) { |
1565 | ret = -ENXIO; | 1565 | ret = -ENXIO; |
1566 | goto err_unlock; | 1566 | goto err_unlock; |
1567 | } | 1567 | } |
1568 | return state; | 1568 | return state; |
1569 | 1569 | ||
1570 | err_unlock: | 1570 | err_unlock: |
1571 | state->count--; | 1571 | state->count--; |
1572 | mutex_unlock(&state->mutex); | 1572 | mutex_unlock(&state->mutex); |
1573 | err: | 1573 | err: |
1574 | return ERR_PTR(ret); | 1574 | return ERR_PTR(ret); |
1575 | } | 1575 | } |
1576 | 1576 | ||
1577 | /* | 1577 | /* |
1578 | * calls to uart_open are serialised by the BKL in | 1578 | * calls to uart_open are serialised by the BKL in |
1579 | * fs/char_dev.c:chrdev_open() | 1579 | * fs/char_dev.c:chrdev_open() |
1580 | * Note that if this fails, then uart_close() _will_ be called. | 1580 | * Note that if this fails, then uart_close() _will_ be called. |
1581 | * | 1581 | * |
1582 | * In time, we want to scrap the "opening nonpresent ports" | 1582 | * In time, we want to scrap the "opening nonpresent ports" |
1583 | * behaviour and implement an alternative way for setserial | 1583 | * behaviour and implement an alternative way for setserial |
1584 | * to set base addresses/ports/types. This will allow us to | 1584 | * to set base addresses/ports/types. This will allow us to |
1585 | * get rid of a certain amount of extra tests. | 1585 | * get rid of a certain amount of extra tests. |
1586 | */ | 1586 | */ |
1587 | static int uart_open(struct tty_struct *tty, struct file *filp) | 1587 | static int uart_open(struct tty_struct *tty, struct file *filp) |
1588 | { | 1588 | { |
1589 | struct uart_driver *drv = (struct uart_driver *)tty->driver->driver_state; | 1589 | struct uart_driver *drv = (struct uart_driver *)tty->driver->driver_state; |
1590 | struct uart_state *state; | 1590 | struct uart_state *state; |
1591 | int retval, line = tty->index; | 1591 | int retval, line = tty->index; |
1592 | 1592 | ||
1593 | BUG_ON(!kernel_locked()); | 1593 | BUG_ON(!kernel_locked()); |
1594 | pr_debug("uart_open(%d) called\n", line); | 1594 | pr_debug("uart_open(%d) called\n", line); |
1595 | 1595 | ||
1596 | /* | 1596 | /* |
1597 | * tty->driver->num won't change, so we won't fail here with | 1597 | * tty->driver->num won't change, so we won't fail here with |
1598 | * tty->driver_data set to something non-NULL (and therefore | 1598 | * tty->driver_data set to something non-NULL (and therefore |
1599 | * we won't get caught by uart_close()). | 1599 | * we won't get caught by uart_close()). |
1600 | */ | 1600 | */ |
1601 | retval = -ENODEV; | 1601 | retval = -ENODEV; |
1602 | if (line >= tty->driver->num) | 1602 | if (line >= tty->driver->num) |
1603 | goto fail; | 1603 | goto fail; |
1604 | 1604 | ||
1605 | /* | 1605 | /* |
1606 | * We take the semaphore inside uart_get to guarantee that we won't | 1606 | * We take the semaphore inside uart_get to guarantee that we won't |
1607 | * be re-entered while allocating the info structure, or while we | 1607 | * be re-entered while allocating the info structure, or while we |
1608 | * request any IRQs that the driver may need. This also has the nice | 1608 | * request any IRQs that the driver may need. This also has the nice |
1609 | * side-effect that it delays the action of uart_hangup, so we can | 1609 | * side-effect that it delays the action of uart_hangup, so we can |
1610 | * guarantee that info->port.tty will always contain something reasonable. | 1610 | * guarantee that info->port.tty will always contain something reasonable. |
1611 | */ | 1611 | */ |
1612 | state = uart_get(drv, line); | 1612 | state = uart_get(drv, line); |
1613 | if (IS_ERR(state)) { | 1613 | if (IS_ERR(state)) { |
1614 | retval = PTR_ERR(state); | 1614 | retval = PTR_ERR(state); |
1615 | goto fail; | 1615 | goto fail; |
1616 | } | 1616 | } |
1617 | 1617 | ||
1618 | /* | 1618 | /* |
1619 | * Once we set tty->driver_data here, we are guaranteed that | 1619 | * Once we set tty->driver_data here, we are guaranteed that |
1620 | * uart_close() will decrement the driver module use count. | 1620 | * uart_close() will decrement the driver module use count. |
1621 | * Any failures from here onwards should not touch the count. | 1621 | * Any failures from here onwards should not touch the count. |
1622 | */ | 1622 | */ |
1623 | tty->driver_data = state; | 1623 | tty->driver_data = state; |
1624 | state->port->info = &state->info; | 1624 | state->port->info = &state->info; |
1625 | tty->low_latency = (state->port->flags & UPF_LOW_LATENCY) ? 1 : 0; | 1625 | tty->low_latency = (state->port->flags & UPF_LOW_LATENCY) ? 1 : 0; |
1626 | tty->alt_speed = 0; | 1626 | tty->alt_speed = 0; |
1627 | state->info.port.tty = tty; | 1627 | state->info.port.tty = tty; |
1628 | 1628 | ||
1629 | /* | 1629 | /* |
1630 | * If the port is in the middle of closing, bail out now. | 1630 | * If the port is in the middle of closing, bail out now. |
1631 | */ | 1631 | */ |
1632 | if (tty_hung_up_p(filp)) { | 1632 | if (tty_hung_up_p(filp)) { |
1633 | retval = -EAGAIN; | 1633 | retval = -EAGAIN; |
1634 | state->count--; | 1634 | state->count--; |
1635 | mutex_unlock(&state->mutex); | 1635 | mutex_unlock(&state->mutex); |
1636 | goto fail; | 1636 | goto fail; |
1637 | } | 1637 | } |
1638 | 1638 | ||
1639 | /* | 1639 | /* |
1640 | * Make sure the device is in D0 state. | 1640 | * Make sure the device is in D0 state. |
1641 | */ | 1641 | */ |
1642 | if (state->count == 1) | 1642 | if (state->count == 1) |
1643 | uart_change_pm(state, 0); | 1643 | uart_change_pm(state, 0); |
1644 | 1644 | ||
1645 | /* | 1645 | /* |
1646 | * Start up the serial port. | 1646 | * Start up the serial port. |
1647 | */ | 1647 | */ |
1648 | retval = uart_startup(state, 0); | 1648 | retval = uart_startup(state, 0); |
1649 | 1649 | ||
1650 | /* | 1650 | /* |
1651 | * If we succeeded, wait until the port is ready. | 1651 | * If we succeeded, wait until the port is ready. |
1652 | */ | 1652 | */ |
1653 | if (retval == 0) | 1653 | if (retval == 0) |
1654 | retval = uart_block_til_ready(filp, state); | 1654 | retval = uart_block_til_ready(filp, state); |
1655 | mutex_unlock(&state->mutex); | 1655 | mutex_unlock(&state->mutex); |
1656 | 1656 | ||
1657 | /* | 1657 | /* |
1658 | * If this is the first open to succeed, adjust things to suit. | 1658 | * If this is the first open to succeed, adjust things to suit. |
1659 | */ | 1659 | */ |
1660 | if (retval == 0 && !(state->info.flags & UIF_NORMAL_ACTIVE)) { | 1660 | if (retval == 0 && !(state->info.flags & UIF_NORMAL_ACTIVE)) { |
1661 | state->info.flags |= UIF_NORMAL_ACTIVE; | 1661 | state->info.flags |= UIF_NORMAL_ACTIVE; |
1662 | 1662 | ||
1663 | uart_update_termios(state); | 1663 | uart_update_termios(state); |
1664 | } | 1664 | } |
1665 | 1665 | ||
1666 | fail: | 1666 | fail: |
1667 | return retval; | 1667 | return retval; |
1668 | } | 1668 | } |
1669 | 1669 | ||
1670 | static const char *uart_type(struct uart_port *port) | 1670 | static const char *uart_type(struct uart_port *port) |
1671 | { | 1671 | { |
1672 | const char *str = NULL; | 1672 | const char *str = NULL; |
1673 | 1673 | ||
1674 | if (port->ops->type) | 1674 | if (port->ops->type) |
1675 | str = port->ops->type(port); | 1675 | str = port->ops->type(port); |
1676 | 1676 | ||
1677 | if (!str) | 1677 | if (!str) |
1678 | str = "unknown"; | 1678 | str = "unknown"; |
1679 | 1679 | ||
1680 | return str; | 1680 | return str; |
1681 | } | 1681 | } |
1682 | 1682 | ||
1683 | #ifdef CONFIG_PROC_FS | 1683 | #ifdef CONFIG_PROC_FS |
1684 | 1684 | ||
1685 | static int uart_line_info(char *buf, struct uart_driver *drv, int i) | 1685 | static int uart_line_info(char *buf, struct uart_driver *drv, int i) |
1686 | { | 1686 | { |
1687 | struct uart_state *state = drv->state + i; | 1687 | struct uart_state *state = drv->state + i; |
1688 | int pm_state; | 1688 | int pm_state; |
1689 | struct uart_port *port = state->port; | 1689 | struct uart_port *port = state->port; |
1690 | char stat_buf[32]; | 1690 | char stat_buf[32]; |
1691 | unsigned int status; | 1691 | unsigned int status; |
1692 | int mmio, ret; | 1692 | int mmio, ret; |
1693 | 1693 | ||
1694 | if (!port) | 1694 | if (!port) |
1695 | return 0; | 1695 | return 0; |
1696 | 1696 | ||
1697 | mmio = port->iotype >= UPIO_MEM; | 1697 | mmio = port->iotype >= UPIO_MEM; |
1698 | ret = sprintf(buf, "%d: uart:%s %s%08llX irq:%d", | 1698 | ret = sprintf(buf, "%d: uart:%s %s%08llX irq:%d", |
1699 | port->line, uart_type(port), | 1699 | port->line, uart_type(port), |
1700 | mmio ? "mmio:0x" : "port:", | 1700 | mmio ? "mmio:0x" : "port:", |
1701 | mmio ? (unsigned long long)port->mapbase | 1701 | mmio ? (unsigned long long)port->mapbase |
1702 | : (unsigned long long) port->iobase, | 1702 | : (unsigned long long) port->iobase, |
1703 | port->irq); | 1703 | port->irq); |
1704 | 1704 | ||
1705 | if (port->type == PORT_UNKNOWN) { | 1705 | if (port->type == PORT_UNKNOWN) { |
1706 | strcat(buf, "\n"); | 1706 | strcat(buf, "\n"); |
1707 | return ret + 1; | 1707 | return ret + 1; |
1708 | } | 1708 | } |
1709 | 1709 | ||
1710 | if (capable(CAP_SYS_ADMIN)) { | 1710 | if (capable(CAP_SYS_ADMIN)) { |
1711 | mutex_lock(&state->mutex); | 1711 | mutex_lock(&state->mutex); |
1712 | pm_state = state->pm_state; | 1712 | pm_state = state->pm_state; |
1713 | if (pm_state) | 1713 | if (pm_state) |
1714 | uart_change_pm(state, 0); | 1714 | uart_change_pm(state, 0); |
1715 | spin_lock_irq(&port->lock); | 1715 | spin_lock_irq(&port->lock); |
1716 | status = port->ops->get_mctrl(port); | 1716 | status = port->ops->get_mctrl(port); |
1717 | spin_unlock_irq(&port->lock); | 1717 | spin_unlock_irq(&port->lock); |
1718 | if (pm_state) | 1718 | if (pm_state) |
1719 | uart_change_pm(state, pm_state); | 1719 | uart_change_pm(state, pm_state); |
1720 | mutex_unlock(&state->mutex); | 1720 | mutex_unlock(&state->mutex); |
1721 | 1721 | ||
1722 | ret += sprintf(buf + ret, " tx:%d rx:%d", | 1722 | ret += sprintf(buf + ret, " tx:%d rx:%d", |
1723 | port->icount.tx, port->icount.rx); | 1723 | port->icount.tx, port->icount.rx); |
1724 | if (port->icount.frame) | 1724 | if (port->icount.frame) |
1725 | ret += sprintf(buf + ret, " fe:%d", | 1725 | ret += sprintf(buf + ret, " fe:%d", |
1726 | port->icount.frame); | 1726 | port->icount.frame); |
1727 | if (port->icount.parity) | 1727 | if (port->icount.parity) |
1728 | ret += sprintf(buf + ret, " pe:%d", | 1728 | ret += sprintf(buf + ret, " pe:%d", |
1729 | port->icount.parity); | 1729 | port->icount.parity); |
1730 | if (port->icount.brk) | 1730 | if (port->icount.brk) |
1731 | ret += sprintf(buf + ret, " brk:%d", | 1731 | ret += sprintf(buf + ret, " brk:%d", |
1732 | port->icount.brk); | 1732 | port->icount.brk); |
1733 | if (port->icount.overrun) | 1733 | if (port->icount.overrun) |
1734 | ret += sprintf(buf + ret, " oe:%d", | 1734 | ret += sprintf(buf + ret, " oe:%d", |
1735 | port->icount.overrun); | 1735 | port->icount.overrun); |
1736 | 1736 | ||
1737 | #define INFOBIT(bit, str) \ | 1737 | #define INFOBIT(bit, str) \ |
1738 | if (port->mctrl & (bit)) \ | 1738 | if (port->mctrl & (bit)) \ |
1739 | strncat(stat_buf, (str), sizeof(stat_buf) - \ | 1739 | strncat(stat_buf, (str), sizeof(stat_buf) - \ |
1740 | strlen(stat_buf) - 2) | 1740 | strlen(stat_buf) - 2) |
1741 | #define STATBIT(bit, str) \ | 1741 | #define STATBIT(bit, str) \ |
1742 | if (status & (bit)) \ | 1742 | if (status & (bit)) \ |
1743 | strncat(stat_buf, (str), sizeof(stat_buf) - \ | 1743 | strncat(stat_buf, (str), sizeof(stat_buf) - \ |
1744 | strlen(stat_buf) - 2) | 1744 | strlen(stat_buf) - 2) |
1745 | 1745 | ||
1746 | stat_buf[0] = '\0'; | 1746 | stat_buf[0] = '\0'; |
1747 | stat_buf[1] = '\0'; | 1747 | stat_buf[1] = '\0'; |
1748 | INFOBIT(TIOCM_RTS, "|RTS"); | 1748 | INFOBIT(TIOCM_RTS, "|RTS"); |
1749 | STATBIT(TIOCM_CTS, "|CTS"); | 1749 | STATBIT(TIOCM_CTS, "|CTS"); |
1750 | INFOBIT(TIOCM_DTR, "|DTR"); | 1750 | INFOBIT(TIOCM_DTR, "|DTR"); |
1751 | STATBIT(TIOCM_DSR, "|DSR"); | 1751 | STATBIT(TIOCM_DSR, "|DSR"); |
1752 | STATBIT(TIOCM_CAR, "|CD"); | 1752 | STATBIT(TIOCM_CAR, "|CD"); |
1753 | STATBIT(TIOCM_RNG, "|RI"); | 1753 | STATBIT(TIOCM_RNG, "|RI"); |
1754 | if (stat_buf[0]) | 1754 | if (stat_buf[0]) |
1755 | stat_buf[0] = ' '; | 1755 | stat_buf[0] = ' '; |
1756 | strcat(stat_buf, "\n"); | 1756 | strcat(stat_buf, "\n"); |
1757 | 1757 | ||
1758 | ret += sprintf(buf + ret, stat_buf); | 1758 | ret += sprintf(buf + ret, stat_buf); |
1759 | } else { | 1759 | } else { |
1760 | strcat(buf, "\n"); | 1760 | strcat(buf, "\n"); |
1761 | ret++; | 1761 | ret++; |
1762 | } | 1762 | } |
1763 | #undef STATBIT | 1763 | #undef STATBIT |
1764 | #undef INFOBIT | 1764 | #undef INFOBIT |
1765 | return ret; | 1765 | return ret; |
1766 | } | 1766 | } |
1767 | 1767 | ||
1768 | static int uart_read_proc(char *page, char **start, off_t off, | 1768 | static int uart_read_proc(char *page, char **start, off_t off, |
1769 | int count, int *eof, void *data) | 1769 | int count, int *eof, void *data) |
1770 | { | 1770 | { |
1771 | struct tty_driver *ttydrv = data; | 1771 | struct tty_driver *ttydrv = data; |
1772 | struct uart_driver *drv = ttydrv->driver_state; | 1772 | struct uart_driver *drv = ttydrv->driver_state; |
1773 | int i, len = 0, l; | 1773 | int i, len = 0, l; |
1774 | off_t begin = 0; | 1774 | off_t begin = 0; |
1775 | 1775 | ||
1776 | len += sprintf(page, "serinfo:1.0 driver%s%s revision:%s\n", | 1776 | len += sprintf(page, "serinfo:1.0 driver%s%s revision:%s\n", |
1777 | "", "", ""); | 1777 | "", "", ""); |
1778 | for (i = 0; i < drv->nr && len < PAGE_SIZE - 96; i++) { | 1778 | for (i = 0; i < drv->nr && len < PAGE_SIZE - 96; i++) { |
1779 | l = uart_line_info(page + len, drv, i); | 1779 | l = uart_line_info(page + len, drv, i); |
1780 | len += l; | 1780 | len += l; |
1781 | if (len + begin > off + count) | 1781 | if (len + begin > off + count) |
1782 | goto done; | 1782 | goto done; |
1783 | if (len + begin < off) { | 1783 | if (len + begin < off) { |
1784 | begin += len; | 1784 | begin += len; |
1785 | len = 0; | 1785 | len = 0; |
1786 | } | 1786 | } |
1787 | } | 1787 | } |
1788 | *eof = 1; | 1788 | *eof = 1; |
1789 | done: | 1789 | done: |
1790 | if (off >= len + begin) | 1790 | if (off >= len + begin) |
1791 | return 0; | 1791 | return 0; |
1792 | *start = page + (off - begin); | 1792 | *start = page + (off - begin); |
1793 | return (count < begin + len - off) ? count : (begin + len - off); | 1793 | return (count < begin + len - off) ? count : (begin + len - off); |
1794 | } | 1794 | } |
1795 | #endif | 1795 | #endif |
1796 | 1796 | ||
1797 | #if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL) | 1797 | #if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL) |
1798 | /* | 1798 | /* |
1799 | * uart_console_write - write a console message to a serial port | 1799 | * uart_console_write - write a console message to a serial port |
1800 | * @port: the port to write the message | 1800 | * @port: the port to write the message |
1801 | * @s: array of characters | 1801 | * @s: array of characters |
1802 | * @count: number of characters in string to write | 1802 | * @count: number of characters in string to write |
1803 | * @write: function to write character to port | 1803 | * @write: function to write character to port |
1804 | */ | 1804 | */ |
1805 | void uart_console_write(struct uart_port *port, const char *s, | 1805 | void uart_console_write(struct uart_port *port, const char *s, |
1806 | unsigned int count, | 1806 | unsigned int count, |
1807 | void (*putchar)(struct uart_port *, int)) | 1807 | void (*putchar)(struct uart_port *, int)) |
1808 | { | 1808 | { |
1809 | unsigned int i; | 1809 | unsigned int i; |
1810 | 1810 | ||
1811 | for (i = 0; i < count; i++, s++) { | 1811 | for (i = 0; i < count; i++, s++) { |
1812 | if (*s == '\n') | 1812 | if (*s == '\n') |
1813 | putchar(port, '\r'); | 1813 | putchar(port, '\r'); |
1814 | putchar(port, *s); | 1814 | putchar(port, *s); |
1815 | } | 1815 | } |
1816 | } | 1816 | } |
1817 | EXPORT_SYMBOL_GPL(uart_console_write); | 1817 | EXPORT_SYMBOL_GPL(uart_console_write); |
1818 | 1818 | ||
1819 | /* | 1819 | /* |
1820 | * Check whether an invalid uart number has been specified, and | 1820 | * Check whether an invalid uart number has been specified, and |
1821 | * if so, search for the first available port that does have | 1821 | * if so, search for the first available port that does have |
1822 | * console support. | 1822 | * console support. |
1823 | */ | 1823 | */ |
1824 | struct uart_port * __init | 1824 | struct uart_port * __init |
1825 | uart_get_console(struct uart_port *ports, int nr, struct console *co) | 1825 | uart_get_console(struct uart_port *ports, int nr, struct console *co) |
1826 | { | 1826 | { |
1827 | int idx = co->index; | 1827 | int idx = co->index; |
1828 | 1828 | ||
1829 | if (idx < 0 || idx >= nr || (ports[idx].iobase == 0 && | 1829 | if (idx < 0 || idx >= nr || (ports[idx].iobase == 0 && |
1830 | ports[idx].membase == NULL)) | 1830 | ports[idx].membase == NULL)) |
1831 | for (idx = 0; idx < nr; idx++) | 1831 | for (idx = 0; idx < nr; idx++) |
1832 | if (ports[idx].iobase != 0 || | 1832 | if (ports[idx].iobase != 0 || |
1833 | ports[idx].membase != NULL) | 1833 | ports[idx].membase != NULL) |
1834 | break; | 1834 | break; |
1835 | 1835 | ||
1836 | co->index = idx; | 1836 | co->index = idx; |
1837 | 1837 | ||
1838 | return ports + idx; | 1838 | return ports + idx; |
1839 | } | 1839 | } |
1840 | 1840 | ||
1841 | /** | 1841 | /** |
1842 | * uart_parse_options - Parse serial port baud/parity/bits/flow contro. | 1842 | * uart_parse_options - Parse serial port baud/parity/bits/flow contro. |
1843 | * @options: pointer to option string | 1843 | * @options: pointer to option string |
1844 | * @baud: pointer to an 'int' variable for the baud rate. | 1844 | * @baud: pointer to an 'int' variable for the baud rate. |
1845 | * @parity: pointer to an 'int' variable for the parity. | 1845 | * @parity: pointer to an 'int' variable for the parity. |
1846 | * @bits: pointer to an 'int' variable for the number of data bits. | 1846 | * @bits: pointer to an 'int' variable for the number of data bits. |
1847 | * @flow: pointer to an 'int' variable for the flow control character. | 1847 | * @flow: pointer to an 'int' variable for the flow control character. |
1848 | * | 1848 | * |
1849 | * uart_parse_options decodes a string containing the serial console | 1849 | * uart_parse_options decodes a string containing the serial console |
1850 | * options. The format of the string is <baud><parity><bits><flow>, | 1850 | * options. The format of the string is <baud><parity><bits><flow>, |
1851 | * eg: 115200n8r | 1851 | * eg: 115200n8r |
1852 | */ | 1852 | */ |
1853 | void | 1853 | void |
1854 | uart_parse_options(char *options, int *baud, int *parity, int *bits, int *flow) | 1854 | uart_parse_options(char *options, int *baud, int *parity, int *bits, int *flow) |
1855 | { | 1855 | { |
1856 | char *s = options; | 1856 | char *s = options; |
1857 | 1857 | ||
1858 | *baud = simple_strtoul(s, NULL, 10); | 1858 | *baud = simple_strtoul(s, NULL, 10); |
1859 | while (*s >= '0' && *s <= '9') | 1859 | while (*s >= '0' && *s <= '9') |
1860 | s++; | 1860 | s++; |
1861 | if (*s) | 1861 | if (*s) |
1862 | *parity = *s++; | 1862 | *parity = *s++; |
1863 | if (*s) | 1863 | if (*s) |
1864 | *bits = *s++ - '0'; | 1864 | *bits = *s++ - '0'; |
1865 | if (*s) | 1865 | if (*s) |
1866 | *flow = *s; | 1866 | *flow = *s; |
1867 | } | 1867 | } |
1868 | EXPORT_SYMBOL_GPL(uart_parse_options); | 1868 | EXPORT_SYMBOL_GPL(uart_parse_options); |
1869 | 1869 | ||
1870 | struct baud_rates { | 1870 | struct baud_rates { |
1871 | unsigned int rate; | 1871 | unsigned int rate; |
1872 | unsigned int cflag; | 1872 | unsigned int cflag; |
1873 | }; | 1873 | }; |
1874 | 1874 | ||
1875 | static const struct baud_rates baud_rates[] = { | 1875 | static const struct baud_rates baud_rates[] = { |
1876 | { 921600, B921600 }, | 1876 | { 921600, B921600 }, |
1877 | { 460800, B460800 }, | 1877 | { 460800, B460800 }, |
1878 | { 230400, B230400 }, | 1878 | { 230400, B230400 }, |
1879 | { 115200, B115200 }, | 1879 | { 115200, B115200 }, |
1880 | { 57600, B57600 }, | 1880 | { 57600, B57600 }, |
1881 | { 38400, B38400 }, | 1881 | { 38400, B38400 }, |
1882 | { 19200, B19200 }, | 1882 | { 19200, B19200 }, |
1883 | { 9600, B9600 }, | 1883 | { 9600, B9600 }, |
1884 | { 4800, B4800 }, | 1884 | { 4800, B4800 }, |
1885 | { 2400, B2400 }, | 1885 | { 2400, B2400 }, |
1886 | { 1200, B1200 }, | 1886 | { 1200, B1200 }, |
1887 | { 0, B38400 } | 1887 | { 0, B38400 } |
1888 | }; | 1888 | }; |
1889 | 1889 | ||
1890 | /** | 1890 | /** |
1891 | * uart_set_options - setup the serial console parameters | 1891 | * uart_set_options - setup the serial console parameters |
1892 | * @port: pointer to the serial ports uart_port structure | 1892 | * @port: pointer to the serial ports uart_port structure |
1893 | * @co: console pointer | 1893 | * @co: console pointer |
1894 | * @baud: baud rate | 1894 | * @baud: baud rate |
1895 | * @parity: parity character - 'n' (none), 'o' (odd), 'e' (even) | 1895 | * @parity: parity character - 'n' (none), 'o' (odd), 'e' (even) |
1896 | * @bits: number of data bits | 1896 | * @bits: number of data bits |
1897 | * @flow: flow control character - 'r' (rts) | 1897 | * @flow: flow control character - 'r' (rts) |
1898 | */ | 1898 | */ |
1899 | int | 1899 | int |
1900 | uart_set_options(struct uart_port *port, struct console *co, | 1900 | uart_set_options(struct uart_port *port, struct console *co, |
1901 | int baud, int parity, int bits, int flow) | 1901 | int baud, int parity, int bits, int flow) |
1902 | { | 1902 | { |
1903 | struct ktermios termios; | 1903 | struct ktermios termios; |
1904 | static struct ktermios dummy; | 1904 | static struct ktermios dummy; |
1905 | int i; | 1905 | int i; |
1906 | 1906 | ||
1907 | /* | 1907 | /* |
1908 | * Ensure that the serial console lock is initialised | 1908 | * Ensure that the serial console lock is initialised |
1909 | * early. | 1909 | * early. |
1910 | */ | 1910 | */ |
1911 | spin_lock_init(&port->lock); | 1911 | spin_lock_init(&port->lock); |
1912 | lockdep_set_class(&port->lock, &port_lock_key); | 1912 | lockdep_set_class(&port->lock, &port_lock_key); |
1913 | 1913 | ||
1914 | memset(&termios, 0, sizeof(struct ktermios)); | 1914 | memset(&termios, 0, sizeof(struct ktermios)); |
1915 | 1915 | ||
1916 | termios.c_cflag = CREAD | HUPCL | CLOCAL; | 1916 | termios.c_cflag = CREAD | HUPCL | CLOCAL; |
1917 | 1917 | ||
1918 | /* | 1918 | /* |
1919 | * Construct a cflag setting. | 1919 | * Construct a cflag setting. |
1920 | */ | 1920 | */ |
1921 | for (i = 0; baud_rates[i].rate; i++) | 1921 | for (i = 0; baud_rates[i].rate; i++) |
1922 | if (baud_rates[i].rate <= baud) | 1922 | if (baud_rates[i].rate <= baud) |
1923 | break; | 1923 | break; |
1924 | 1924 | ||
1925 | termios.c_cflag |= baud_rates[i].cflag; | 1925 | termios.c_cflag |= baud_rates[i].cflag; |
1926 | 1926 | ||
1927 | if (bits == 7) | 1927 | if (bits == 7) |
1928 | termios.c_cflag |= CS7; | 1928 | termios.c_cflag |= CS7; |
1929 | else | 1929 | else |
1930 | termios.c_cflag |= CS8; | 1930 | termios.c_cflag |= CS8; |
1931 | 1931 | ||
1932 | switch (parity) { | 1932 | switch (parity) { |
1933 | case 'o': case 'O': | 1933 | case 'o': case 'O': |
1934 | termios.c_cflag |= PARODD; | 1934 | termios.c_cflag |= PARODD; |
1935 | /*fall through*/ | 1935 | /*fall through*/ |
1936 | case 'e': case 'E': | 1936 | case 'e': case 'E': |
1937 | termios.c_cflag |= PARENB; | 1937 | termios.c_cflag |= PARENB; |
1938 | break; | 1938 | break; |
1939 | } | 1939 | } |
1940 | 1940 | ||
1941 | if (flow == 'r') | 1941 | if (flow == 'r') |
1942 | termios.c_cflag |= CRTSCTS; | 1942 | termios.c_cflag |= CRTSCTS; |
1943 | 1943 | ||
1944 | /* | 1944 | /* |
1945 | * some uarts on other side don't support no flow control. | 1945 | * some uarts on other side don't support no flow control. |
1946 | * So we set * DTR in host uart to make them happy | 1946 | * So we set * DTR in host uart to make them happy |
1947 | */ | 1947 | */ |
1948 | port->mctrl |= TIOCM_DTR; | 1948 | port->mctrl |= TIOCM_DTR; |
1949 | 1949 | ||
1950 | port->ops->set_termios(port, &termios, &dummy); | 1950 | port->ops->set_termios(port, &termios, &dummy); |
1951 | /* | 1951 | /* |
1952 | * Allow the setting of the UART parameters with a NULL console | 1952 | * Allow the setting of the UART parameters with a NULL console |
1953 | * too: | 1953 | * too: |
1954 | */ | 1954 | */ |
1955 | if (co) | 1955 | if (co) |
1956 | co->cflag = termios.c_cflag; | 1956 | co->cflag = termios.c_cflag; |
1957 | 1957 | ||
1958 | return 0; | 1958 | return 0; |
1959 | } | 1959 | } |
1960 | EXPORT_SYMBOL_GPL(uart_set_options); | 1960 | EXPORT_SYMBOL_GPL(uart_set_options); |
1961 | #endif /* CONFIG_SERIAL_CORE_CONSOLE */ | 1961 | #endif /* CONFIG_SERIAL_CORE_CONSOLE */ |
1962 | 1962 | ||
1963 | static void uart_change_pm(struct uart_state *state, int pm_state) | 1963 | static void uart_change_pm(struct uart_state *state, int pm_state) |
1964 | { | 1964 | { |
1965 | struct uart_port *port = state->port; | 1965 | struct uart_port *port = state->port; |
1966 | 1966 | ||
1967 | if (state->pm_state != pm_state) { | 1967 | if (state->pm_state != pm_state) { |
1968 | if (port->ops->pm) | 1968 | if (port->ops->pm) |
1969 | port->ops->pm(port, pm_state, state->pm_state); | 1969 | port->ops->pm(port, pm_state, state->pm_state); |
1970 | state->pm_state = pm_state; | 1970 | state->pm_state = pm_state; |
1971 | } | 1971 | } |
1972 | } | 1972 | } |
1973 | 1973 | ||
1974 | struct uart_match { | 1974 | struct uart_match { |
1975 | struct uart_port *port; | 1975 | struct uart_port *port; |
1976 | struct uart_driver *driver; | 1976 | struct uart_driver *driver; |
1977 | }; | 1977 | }; |
1978 | 1978 | ||
1979 | static int serial_match_port(struct device *dev, void *data) | 1979 | static int serial_match_port(struct device *dev, void *data) |
1980 | { | 1980 | { |
1981 | struct uart_match *match = data; | 1981 | struct uart_match *match = data; |
1982 | struct tty_driver *tty_drv = match->driver->tty_driver; | 1982 | struct tty_driver *tty_drv = match->driver->tty_driver; |
1983 | dev_t devt = MKDEV(tty_drv->major, tty_drv->minor_start) + | 1983 | dev_t devt = MKDEV(tty_drv->major, tty_drv->minor_start) + |
1984 | match->port->line; | 1984 | match->port->line; |
1985 | 1985 | ||
1986 | return dev->devt == devt; /* Actually, only one tty per port */ | 1986 | return dev->devt == devt; /* Actually, only one tty per port */ |
1987 | } | 1987 | } |
1988 | 1988 | ||
1989 | int uart_suspend_port(struct uart_driver *drv, struct uart_port *port) | 1989 | int uart_suspend_port(struct uart_driver *drv, struct uart_port *port) |
1990 | { | 1990 | { |
1991 | struct uart_state *state = drv->state + port->line; | 1991 | struct uart_state *state = drv->state + port->line; |
1992 | struct device *tty_dev; | 1992 | struct device *tty_dev; |
1993 | struct uart_match match = {port, drv}; | 1993 | struct uart_match match = {port, drv}; |
1994 | 1994 | ||
1995 | mutex_lock(&state->mutex); | 1995 | mutex_lock(&state->mutex); |
1996 | 1996 | ||
1997 | if (!console_suspend_enabled && uart_console(port)) { | 1997 | if (!console_suspend_enabled && uart_console(port)) { |
1998 | /* we're going to avoid suspending serial console */ | 1998 | /* we're going to avoid suspending serial console */ |
1999 | mutex_unlock(&state->mutex); | 1999 | mutex_unlock(&state->mutex); |
2000 | return 0; | 2000 | return 0; |
2001 | } | 2001 | } |
2002 | 2002 | ||
2003 | tty_dev = device_find_child(port->dev, &match, serial_match_port); | 2003 | tty_dev = device_find_child(port->dev, &match, serial_match_port); |
2004 | if (device_may_wakeup(tty_dev)) { | 2004 | if (device_may_wakeup(tty_dev)) { |
2005 | enable_irq_wake(port->irq); | 2005 | enable_irq_wake(port->irq); |
2006 | put_device(tty_dev); | 2006 | put_device(tty_dev); |
2007 | mutex_unlock(&state->mutex); | 2007 | mutex_unlock(&state->mutex); |
2008 | return 0; | 2008 | return 0; |
2009 | } | 2009 | } |
2010 | port->suspended = 1; | 2010 | port->suspended = 1; |
2011 | 2011 | ||
2012 | if (state->info.flags & UIF_INITIALIZED) { | 2012 | if (state->info.flags & UIF_INITIALIZED) { |
2013 | const struct uart_ops *ops = port->ops; | 2013 | const struct uart_ops *ops = port->ops; |
2014 | int tries; | 2014 | int tries; |
2015 | 2015 | ||
2016 | state->info.flags = (state->info.flags & ~UIF_INITIALIZED) | 2016 | state->info.flags = (state->info.flags & ~UIF_INITIALIZED) |
2017 | | UIF_SUSPENDED; | 2017 | | UIF_SUSPENDED; |
2018 | 2018 | ||
2019 | spin_lock_irq(&port->lock); | 2019 | spin_lock_irq(&port->lock); |
2020 | ops->stop_tx(port); | 2020 | ops->stop_tx(port); |
2021 | ops->set_mctrl(port, 0); | 2021 | ops->set_mctrl(port, 0); |
2022 | ops->stop_rx(port); | 2022 | ops->stop_rx(port); |
2023 | spin_unlock_irq(&port->lock); | 2023 | spin_unlock_irq(&port->lock); |
2024 | 2024 | ||
2025 | /* | 2025 | /* |
2026 | * Wait for the transmitter to empty. | 2026 | * Wait for the transmitter to empty. |
2027 | */ | 2027 | */ |
2028 | for (tries = 3; !ops->tx_empty(port) && tries; tries--) | 2028 | for (tries = 3; !ops->tx_empty(port) && tries; tries--) |
2029 | msleep(10); | 2029 | msleep(10); |
2030 | if (!tries) | 2030 | if (!tries) |
2031 | printk(KERN_ERR "%s%s%s%d: Unable to drain " | 2031 | printk(KERN_ERR "%s%s%s%d: Unable to drain " |
2032 | "transmitter\n", | 2032 | "transmitter\n", |
2033 | port->dev ? port->dev->bus_id : "", | 2033 | port->dev ? port->dev->bus_id : "", |
2034 | port->dev ? ": " : "", | 2034 | port->dev ? ": " : "", |
2035 | drv->dev_name, | 2035 | drv->dev_name, |
2036 | drv->tty_driver->name_base + port->line); | 2036 | drv->tty_driver->name_base + port->line); |
2037 | 2037 | ||
2038 | ops->shutdown(port); | 2038 | ops->shutdown(port); |
2039 | } | 2039 | } |
2040 | 2040 | ||
2041 | /* | 2041 | /* |
2042 | * Disable the console device before suspending. | 2042 | * Disable the console device before suspending. |
2043 | */ | 2043 | */ |
2044 | if (uart_console(port)) | 2044 | if (uart_console(port)) |
2045 | console_stop(port->cons); | 2045 | console_stop(port->cons); |
2046 | 2046 | ||
2047 | uart_change_pm(state, 3); | 2047 | uart_change_pm(state, 3); |
2048 | 2048 | ||
2049 | mutex_unlock(&state->mutex); | 2049 | mutex_unlock(&state->mutex); |
2050 | 2050 | ||
2051 | return 0; | 2051 | return 0; |
2052 | } | 2052 | } |
2053 | 2053 | ||
2054 | int uart_resume_port(struct uart_driver *drv, struct uart_port *port) | 2054 | int uart_resume_port(struct uart_driver *drv, struct uart_port *port) |
2055 | { | 2055 | { |
2056 | struct uart_state *state = drv->state + port->line; | 2056 | struct uart_state *state = drv->state + port->line; |
2057 | struct device *tty_dev; | 2057 | struct device *tty_dev; |
2058 | struct uart_match match = {port, drv}; | 2058 | struct uart_match match = {port, drv}; |
2059 | 2059 | ||
2060 | mutex_lock(&state->mutex); | 2060 | mutex_lock(&state->mutex); |
2061 | 2061 | ||
2062 | if (!console_suspend_enabled && uart_console(port)) { | 2062 | if (!console_suspend_enabled && uart_console(port)) { |
2063 | /* no need to resume serial console, it wasn't suspended */ | 2063 | /* no need to resume serial console, it wasn't suspended */ |
2064 | mutex_unlock(&state->mutex); | 2064 | mutex_unlock(&state->mutex); |
2065 | return 0; | 2065 | return 0; |
2066 | } | 2066 | } |
2067 | 2067 | ||
2068 | tty_dev = device_find_child(port->dev, &match, serial_match_port); | 2068 | tty_dev = device_find_child(port->dev, &match, serial_match_port); |
2069 | if (!port->suspended && device_may_wakeup(tty_dev)) { | 2069 | if (!port->suspended && device_may_wakeup(tty_dev)) { |
2070 | disable_irq_wake(port->irq); | 2070 | disable_irq_wake(port->irq); |
2071 | mutex_unlock(&state->mutex); | 2071 | mutex_unlock(&state->mutex); |
2072 | return 0; | 2072 | return 0; |
2073 | } | 2073 | } |
2074 | port->suspended = 0; | 2074 | port->suspended = 0; |
2075 | 2075 | ||
2076 | /* | 2076 | /* |
2077 | * Re-enable the console device after suspending. | 2077 | * Re-enable the console device after suspending. |
2078 | */ | 2078 | */ |
2079 | if (uart_console(port)) { | 2079 | if (uart_console(port)) { |
2080 | struct ktermios termios; | 2080 | struct ktermios termios; |
2081 | 2081 | ||
2082 | /* | 2082 | /* |
2083 | * First try to use the console cflag setting. | 2083 | * First try to use the console cflag setting. |
2084 | */ | 2084 | */ |
2085 | memset(&termios, 0, sizeof(struct ktermios)); | 2085 | memset(&termios, 0, sizeof(struct ktermios)); |
2086 | termios.c_cflag = port->cons->cflag; | 2086 | termios.c_cflag = port->cons->cflag; |
2087 | 2087 | ||
2088 | /* | 2088 | /* |
2089 | * If that's unset, use the tty termios setting. | 2089 | * If that's unset, use the tty termios setting. |
2090 | */ | 2090 | */ |
2091 | if (state->info.port.tty && termios.c_cflag == 0) | 2091 | if (state->info.port.tty && termios.c_cflag == 0) |
2092 | termios = *state->info.port.tty->termios; | 2092 | termios = *state->info.port.tty->termios; |
2093 | 2093 | ||
2094 | uart_change_pm(state, 0); | 2094 | uart_change_pm(state, 0); |
2095 | port->ops->set_termios(port, &termios, NULL); | 2095 | port->ops->set_termios(port, &termios, NULL); |
2096 | console_start(port->cons); | 2096 | console_start(port->cons); |
2097 | } | 2097 | } |
2098 | 2098 | ||
2099 | if (state->info.flags & UIF_SUSPENDED) { | 2099 | if (state->info.flags & UIF_SUSPENDED) { |
2100 | const struct uart_ops *ops = port->ops; | 2100 | const struct uart_ops *ops = port->ops; |
2101 | int ret; | 2101 | int ret; |
2102 | 2102 | ||
2103 | uart_change_pm(state, 0); | 2103 | uart_change_pm(state, 0); |
2104 | spin_lock_irq(&port->lock); | 2104 | spin_lock_irq(&port->lock); |
2105 | ops->set_mctrl(port, 0); | 2105 | ops->set_mctrl(port, 0); |
2106 | spin_unlock_irq(&port->lock); | 2106 | spin_unlock_irq(&port->lock); |
2107 | ret = ops->startup(port); | 2107 | ret = ops->startup(port); |
2108 | if (ret == 0) { | 2108 | if (ret == 0) { |
2109 | uart_change_speed(state, NULL); | 2109 | uart_change_speed(state, NULL); |
2110 | spin_lock_irq(&port->lock); | 2110 | spin_lock_irq(&port->lock); |
2111 | ops->set_mctrl(port, port->mctrl); | 2111 | ops->set_mctrl(port, port->mctrl); |
2112 | ops->start_tx(port); | 2112 | ops->start_tx(port); |
2113 | spin_unlock_irq(&port->lock); | 2113 | spin_unlock_irq(&port->lock); |
2114 | state->info.flags |= UIF_INITIALIZED; | 2114 | state->info.flags |= UIF_INITIALIZED; |
2115 | } else { | 2115 | } else { |
2116 | /* | 2116 | /* |
2117 | * Failed to resume - maybe hardware went away? | 2117 | * Failed to resume - maybe hardware went away? |
2118 | * Clear the "initialized" flag so we won't try | 2118 | * Clear the "initialized" flag so we won't try |
2119 | * to call the low level drivers shutdown method. | 2119 | * to call the low level drivers shutdown method. |
2120 | */ | 2120 | */ |
2121 | uart_shutdown(state); | 2121 | uart_shutdown(state); |
2122 | } | 2122 | } |
2123 | 2123 | ||
2124 | state->info.flags &= ~UIF_SUSPENDED; | 2124 | state->info.flags &= ~UIF_SUSPENDED; |
2125 | } | 2125 | } |
2126 | 2126 | ||
2127 | mutex_unlock(&state->mutex); | 2127 | mutex_unlock(&state->mutex); |
2128 | 2128 | ||
2129 | return 0; | 2129 | return 0; |
2130 | } | 2130 | } |
2131 | 2131 | ||
2132 | static inline void | 2132 | static inline void |
2133 | uart_report_port(struct uart_driver *drv, struct uart_port *port) | 2133 | uart_report_port(struct uart_driver *drv, struct uart_port *port) |
2134 | { | 2134 | { |
2135 | char address[64]; | 2135 | char address[64]; |
2136 | 2136 | ||
2137 | switch (port->iotype) { | 2137 | switch (port->iotype) { |
2138 | case UPIO_PORT: | 2138 | case UPIO_PORT: |
2139 | snprintf(address, sizeof(address), "I/O 0x%lx", port->iobase); | 2139 | snprintf(address, sizeof(address), "I/O 0x%lx", port->iobase); |
2140 | break; | 2140 | break; |
2141 | case UPIO_HUB6: | 2141 | case UPIO_HUB6: |
2142 | snprintf(address, sizeof(address), | 2142 | snprintf(address, sizeof(address), |
2143 | "I/O 0x%lx offset 0x%x", port->iobase, port->hub6); | 2143 | "I/O 0x%lx offset 0x%x", port->iobase, port->hub6); |
2144 | break; | 2144 | break; |
2145 | case UPIO_MEM: | 2145 | case UPIO_MEM: |
2146 | case UPIO_MEM32: | 2146 | case UPIO_MEM32: |
2147 | case UPIO_AU: | 2147 | case UPIO_AU: |
2148 | case UPIO_TSI: | 2148 | case UPIO_TSI: |
2149 | case UPIO_DWAPB: | 2149 | case UPIO_DWAPB: |
2150 | snprintf(address, sizeof(address), | 2150 | snprintf(address, sizeof(address), |
2151 | "MMIO 0x%llx", (unsigned long long)port->mapbase); | 2151 | "MMIO 0x%llx", (unsigned long long)port->mapbase); |
2152 | break; | 2152 | break; |
2153 | default: | 2153 | default: |
2154 | strlcpy(address, "*unknown*", sizeof(address)); | 2154 | strlcpy(address, "*unknown*", sizeof(address)); |
2155 | break; | 2155 | break; |
2156 | } | 2156 | } |
2157 | 2157 | ||
2158 | printk(KERN_INFO "%s%s%s%d at %s (irq = %d) is a %s\n", | 2158 | printk(KERN_INFO "%s%s%s%d at %s (irq = %d) is a %s\n", |
2159 | port->dev ? port->dev->bus_id : "", | 2159 | port->dev ? port->dev->bus_id : "", |
2160 | port->dev ? ": " : "", | 2160 | port->dev ? ": " : "", |
2161 | drv->dev_name, | 2161 | drv->dev_name, |
2162 | drv->tty_driver->name_base + port->line, | 2162 | drv->tty_driver->name_base + port->line, |
2163 | address, port->irq, uart_type(port)); | 2163 | address, port->irq, uart_type(port)); |
2164 | } | 2164 | } |
2165 | 2165 | ||
2166 | static void | 2166 | static void |
2167 | uart_configure_port(struct uart_driver *drv, struct uart_state *state, | 2167 | uart_configure_port(struct uart_driver *drv, struct uart_state *state, |
2168 | struct uart_port *port) | 2168 | struct uart_port *port) |
2169 | { | 2169 | { |
2170 | unsigned int flags; | 2170 | unsigned int flags; |
2171 | 2171 | ||
2172 | /* | 2172 | /* |
2173 | * If there isn't a port here, don't do anything further. | 2173 | * If there isn't a port here, don't do anything further. |
2174 | */ | 2174 | */ |
2175 | if (!port->iobase && !port->mapbase && !port->membase) | 2175 | if (!port->iobase && !port->mapbase && !port->membase) |
2176 | return; | 2176 | return; |
2177 | 2177 | ||
2178 | /* | 2178 | /* |
2179 | * Now do the auto configuration stuff. Note that config_port | 2179 | * Now do the auto configuration stuff. Note that config_port |
2180 | * is expected to claim the resources and map the port for us. | 2180 | * is expected to claim the resources and map the port for us. |
2181 | */ | 2181 | */ |
2182 | flags = UART_CONFIG_TYPE; | 2182 | flags = 0; |
2183 | if (port->flags & UPF_AUTO_IRQ) | 2183 | if (port->flags & UPF_AUTO_IRQ) |
2184 | flags |= UART_CONFIG_IRQ; | 2184 | flags |= UART_CONFIG_IRQ; |
2185 | if (port->flags & UPF_BOOT_AUTOCONF) { | 2185 | if (port->flags & UPF_BOOT_AUTOCONF) { |
2186 | port->type = PORT_UNKNOWN; | 2186 | if (!(port->flags & UPF_FIXED_TYPE)) { |
2187 | port->type = PORT_UNKNOWN; | ||
2188 | flags |= UART_CONFIG_TYPE; | ||
2189 | } | ||
2187 | port->ops->config_port(port, flags); | 2190 | port->ops->config_port(port, flags); |
2188 | } | 2191 | } |
2189 | 2192 | ||
2190 | if (port->type != PORT_UNKNOWN) { | 2193 | if (port->type != PORT_UNKNOWN) { |
2191 | unsigned long flags; | 2194 | unsigned long flags; |
2192 | 2195 | ||
2193 | uart_report_port(drv, port); | 2196 | uart_report_port(drv, port); |
2194 | 2197 | ||
2195 | /* Power up port for set_mctrl() */ | 2198 | /* Power up port for set_mctrl() */ |
2196 | uart_change_pm(state, 0); | 2199 | uart_change_pm(state, 0); |
2197 | 2200 | ||
2198 | /* | 2201 | /* |
2199 | * Ensure that the modem control lines are de-activated. | 2202 | * Ensure that the modem control lines are de-activated. |
2200 | * keep the DTR setting that is set in uart_set_options() | 2203 | * keep the DTR setting that is set in uart_set_options() |
2201 | * We probably don't need a spinlock around this, but | 2204 | * We probably don't need a spinlock around this, but |
2202 | */ | 2205 | */ |
2203 | spin_lock_irqsave(&port->lock, flags); | 2206 | spin_lock_irqsave(&port->lock, flags); |
2204 | port->ops->set_mctrl(port, port->mctrl & TIOCM_DTR); | 2207 | port->ops->set_mctrl(port, port->mctrl & TIOCM_DTR); |
2205 | spin_unlock_irqrestore(&port->lock, flags); | 2208 | spin_unlock_irqrestore(&port->lock, flags); |
2206 | 2209 | ||
2207 | /* | 2210 | /* |
2208 | * If this driver supports console, and it hasn't been | 2211 | * If this driver supports console, and it hasn't been |
2209 | * successfully registered yet, try to re-register it. | 2212 | * successfully registered yet, try to re-register it. |
2210 | * It may be that the port was not available. | 2213 | * It may be that the port was not available. |
2211 | */ | 2214 | */ |
2212 | if (port->cons && !(port->cons->flags & CON_ENABLED)) | 2215 | if (port->cons && !(port->cons->flags & CON_ENABLED)) |
2213 | register_console(port->cons); | 2216 | register_console(port->cons); |
2214 | 2217 | ||
2215 | /* | 2218 | /* |
2216 | * Power down all ports by default, except the | 2219 | * Power down all ports by default, except the |
2217 | * console if we have one. | 2220 | * console if we have one. |
2218 | */ | 2221 | */ |
2219 | if (!uart_console(port)) | 2222 | if (!uart_console(port)) |
2220 | uart_change_pm(state, 3); | 2223 | uart_change_pm(state, 3); |
2221 | } | 2224 | } |
2222 | } | 2225 | } |
2223 | 2226 | ||
2224 | #ifdef CONFIG_CONSOLE_POLL | 2227 | #ifdef CONFIG_CONSOLE_POLL |
2225 | 2228 | ||
2226 | static int uart_poll_init(struct tty_driver *driver, int line, char *options) | 2229 | static int uart_poll_init(struct tty_driver *driver, int line, char *options) |
2227 | { | 2230 | { |
2228 | struct uart_driver *drv = driver->driver_state; | 2231 | struct uart_driver *drv = driver->driver_state; |
2229 | struct uart_state *state = drv->state + line; | 2232 | struct uart_state *state = drv->state + line; |
2230 | struct uart_port *port; | 2233 | struct uart_port *port; |
2231 | int baud = 9600; | 2234 | int baud = 9600; |
2232 | int bits = 8; | 2235 | int bits = 8; |
2233 | int parity = 'n'; | 2236 | int parity = 'n'; |
2234 | int flow = 'n'; | 2237 | int flow = 'n'; |
2235 | 2238 | ||
2236 | if (!state || !state->port) | 2239 | if (!state || !state->port) |
2237 | return -1; | 2240 | return -1; |
2238 | 2241 | ||
2239 | port = state->port; | 2242 | port = state->port; |
2240 | if (!(port->ops->poll_get_char && port->ops->poll_put_char)) | 2243 | if (!(port->ops->poll_get_char && port->ops->poll_put_char)) |
2241 | return -1; | 2244 | return -1; |
2242 | 2245 | ||
2243 | if (options) { | 2246 | if (options) { |
2244 | uart_parse_options(options, &baud, &parity, &bits, &flow); | 2247 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
2245 | return uart_set_options(port, NULL, baud, parity, bits, flow); | 2248 | return uart_set_options(port, NULL, baud, parity, bits, flow); |
2246 | } | 2249 | } |
2247 | 2250 | ||
2248 | return 0; | 2251 | return 0; |
2249 | } | 2252 | } |
2250 | 2253 | ||
2251 | static int uart_poll_get_char(struct tty_driver *driver, int line) | 2254 | static int uart_poll_get_char(struct tty_driver *driver, int line) |
2252 | { | 2255 | { |
2253 | struct uart_driver *drv = driver->driver_state; | 2256 | struct uart_driver *drv = driver->driver_state; |
2254 | struct uart_state *state = drv->state + line; | 2257 | struct uart_state *state = drv->state + line; |
2255 | struct uart_port *port; | 2258 | struct uart_port *port; |
2256 | 2259 | ||
2257 | if (!state || !state->port) | 2260 | if (!state || !state->port) |
2258 | return -1; | 2261 | return -1; |
2259 | 2262 | ||
2260 | port = state->port; | 2263 | port = state->port; |
2261 | return port->ops->poll_get_char(port); | 2264 | return port->ops->poll_get_char(port); |
2262 | } | 2265 | } |
2263 | 2266 | ||
2264 | static void uart_poll_put_char(struct tty_driver *driver, int line, char ch) | 2267 | static void uart_poll_put_char(struct tty_driver *driver, int line, char ch) |
2265 | { | 2268 | { |
2266 | struct uart_driver *drv = driver->driver_state; | 2269 | struct uart_driver *drv = driver->driver_state; |
2267 | struct uart_state *state = drv->state + line; | 2270 | struct uart_state *state = drv->state + line; |
2268 | struct uart_port *port; | 2271 | struct uart_port *port; |
2269 | 2272 | ||
2270 | if (!state || !state->port) | 2273 | if (!state || !state->port) |
2271 | return; | 2274 | return; |
2272 | 2275 | ||
2273 | port = state->port; | 2276 | port = state->port; |
2274 | port->ops->poll_put_char(port, ch); | 2277 | port->ops->poll_put_char(port, ch); |
2275 | } | 2278 | } |
2276 | #endif | 2279 | #endif |
2277 | 2280 | ||
2278 | static const struct tty_operations uart_ops = { | 2281 | static const struct tty_operations uart_ops = { |
2279 | .open = uart_open, | 2282 | .open = uart_open, |
2280 | .close = uart_close, | 2283 | .close = uart_close, |
2281 | .write = uart_write, | 2284 | .write = uart_write, |
2282 | .put_char = uart_put_char, | 2285 | .put_char = uart_put_char, |
2283 | .flush_chars = uart_flush_chars, | 2286 | .flush_chars = uart_flush_chars, |
2284 | .write_room = uart_write_room, | 2287 | .write_room = uart_write_room, |
2285 | .chars_in_buffer= uart_chars_in_buffer, | 2288 | .chars_in_buffer= uart_chars_in_buffer, |
2286 | .flush_buffer = uart_flush_buffer, | 2289 | .flush_buffer = uart_flush_buffer, |
2287 | .ioctl = uart_ioctl, | 2290 | .ioctl = uart_ioctl, |
2288 | .throttle = uart_throttle, | 2291 | .throttle = uart_throttle, |
2289 | .unthrottle = uart_unthrottle, | 2292 | .unthrottle = uart_unthrottle, |
2290 | .send_xchar = uart_send_xchar, | 2293 | .send_xchar = uart_send_xchar, |
2291 | .set_termios = uart_set_termios, | 2294 | .set_termios = uart_set_termios, |
2292 | .set_ldisc = uart_set_ldisc, | 2295 | .set_ldisc = uart_set_ldisc, |
2293 | .stop = uart_stop, | 2296 | .stop = uart_stop, |
2294 | .start = uart_start, | 2297 | .start = uart_start, |
2295 | .hangup = uart_hangup, | 2298 | .hangup = uart_hangup, |
2296 | .break_ctl = uart_break_ctl, | 2299 | .break_ctl = uart_break_ctl, |
2297 | .wait_until_sent= uart_wait_until_sent, | 2300 | .wait_until_sent= uart_wait_until_sent, |
2298 | #ifdef CONFIG_PROC_FS | 2301 | #ifdef CONFIG_PROC_FS |
2299 | .read_proc = uart_read_proc, | 2302 | .read_proc = uart_read_proc, |
2300 | #endif | 2303 | #endif |
2301 | .tiocmget = uart_tiocmget, | 2304 | .tiocmget = uart_tiocmget, |
2302 | .tiocmset = uart_tiocmset, | 2305 | .tiocmset = uart_tiocmset, |
2303 | #ifdef CONFIG_CONSOLE_POLL | 2306 | #ifdef CONFIG_CONSOLE_POLL |
2304 | .poll_init = uart_poll_init, | 2307 | .poll_init = uart_poll_init, |
2305 | .poll_get_char = uart_poll_get_char, | 2308 | .poll_get_char = uart_poll_get_char, |
2306 | .poll_put_char = uart_poll_put_char, | 2309 | .poll_put_char = uart_poll_put_char, |
2307 | #endif | 2310 | #endif |
2308 | }; | 2311 | }; |
2309 | 2312 | ||
2310 | /** | 2313 | /** |
2311 | * uart_register_driver - register a driver with the uart core layer | 2314 | * uart_register_driver - register a driver with the uart core layer |
2312 | * @drv: low level driver structure | 2315 | * @drv: low level driver structure |
2313 | * | 2316 | * |
2314 | * Register a uart driver with the core driver. We in turn register | 2317 | * Register a uart driver with the core driver. We in turn register |
2315 | * with the tty layer, and initialise the core driver per-port state. | 2318 | * with the tty layer, and initialise the core driver per-port state. |
2316 | * | 2319 | * |
2317 | * We have a proc file in /proc/tty/driver which is named after the | 2320 | * We have a proc file in /proc/tty/driver which is named after the |
2318 | * normal driver. | 2321 | * normal driver. |
2319 | * | 2322 | * |
2320 | * drv->port should be NULL, and the per-port structures should be | 2323 | * drv->port should be NULL, and the per-port structures should be |
2321 | * registered using uart_add_one_port after this call has succeeded. | 2324 | * registered using uart_add_one_port after this call has succeeded. |
2322 | */ | 2325 | */ |
2323 | int uart_register_driver(struct uart_driver *drv) | 2326 | int uart_register_driver(struct uart_driver *drv) |
2324 | { | 2327 | { |
2325 | struct tty_driver *normal = NULL; | 2328 | struct tty_driver *normal = NULL; |
2326 | int i, retval; | 2329 | int i, retval; |
2327 | 2330 | ||
2328 | BUG_ON(drv->state); | 2331 | BUG_ON(drv->state); |
2329 | 2332 | ||
2330 | /* | 2333 | /* |
2331 | * Maybe we should be using a slab cache for this, especially if | 2334 | * Maybe we should be using a slab cache for this, especially if |
2332 | * we have a large number of ports to handle. | 2335 | * we have a large number of ports to handle. |
2333 | */ | 2336 | */ |
2334 | drv->state = kzalloc(sizeof(struct uart_state) * drv->nr, GFP_KERNEL); | 2337 | drv->state = kzalloc(sizeof(struct uart_state) * drv->nr, GFP_KERNEL); |
2335 | retval = -ENOMEM; | 2338 | retval = -ENOMEM; |
2336 | if (!drv->state) | 2339 | if (!drv->state) |
2337 | goto out; | 2340 | goto out; |
2338 | 2341 | ||
2339 | normal = alloc_tty_driver(drv->nr); | 2342 | normal = alloc_tty_driver(drv->nr); |
2340 | if (!normal) | 2343 | if (!normal) |
2341 | goto out; | 2344 | goto out; |
2342 | 2345 | ||
2343 | drv->tty_driver = normal; | 2346 | drv->tty_driver = normal; |
2344 | 2347 | ||
2345 | normal->owner = drv->owner; | 2348 | normal->owner = drv->owner; |
2346 | normal->driver_name = drv->driver_name; | 2349 | normal->driver_name = drv->driver_name; |
2347 | normal->name = drv->dev_name; | 2350 | normal->name = drv->dev_name; |
2348 | normal->major = drv->major; | 2351 | normal->major = drv->major; |
2349 | normal->minor_start = drv->minor; | 2352 | normal->minor_start = drv->minor; |
2350 | normal->type = TTY_DRIVER_TYPE_SERIAL; | 2353 | normal->type = TTY_DRIVER_TYPE_SERIAL; |
2351 | normal->subtype = SERIAL_TYPE_NORMAL; | 2354 | normal->subtype = SERIAL_TYPE_NORMAL; |
2352 | normal->init_termios = tty_std_termios; | 2355 | normal->init_termios = tty_std_termios; |
2353 | normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | 2356 | normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; |
2354 | normal->init_termios.c_ispeed = normal->init_termios.c_ospeed = 9600; | 2357 | normal->init_termios.c_ispeed = normal->init_termios.c_ospeed = 9600; |
2355 | normal->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; | 2358 | normal->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
2356 | normal->driver_state = drv; | 2359 | normal->driver_state = drv; |
2357 | tty_set_operations(normal, &uart_ops); | 2360 | tty_set_operations(normal, &uart_ops); |
2358 | 2361 | ||
2359 | /* | 2362 | /* |
2360 | * Initialise the UART state(s). | 2363 | * Initialise the UART state(s). |
2361 | */ | 2364 | */ |
2362 | for (i = 0; i < drv->nr; i++) { | 2365 | for (i = 0; i < drv->nr; i++) { |
2363 | struct uart_state *state = drv->state + i; | 2366 | struct uart_state *state = drv->state + i; |
2364 | 2367 | ||
2365 | state->close_delay = 500; /* .5 seconds */ | 2368 | state->close_delay = 500; /* .5 seconds */ |
2366 | state->closing_wait = 30000; /* 30 seconds */ | 2369 | state->closing_wait = 30000; /* 30 seconds */ |
2367 | mutex_init(&state->mutex); | 2370 | mutex_init(&state->mutex); |
2368 | 2371 | ||
2369 | tty_port_init(&state->info.port); | 2372 | tty_port_init(&state->info.port); |
2370 | init_waitqueue_head(&state->info.delta_msr_wait); | 2373 | init_waitqueue_head(&state->info.delta_msr_wait); |
2371 | tasklet_init(&state->info.tlet, uart_tasklet_action, | 2374 | tasklet_init(&state->info.tlet, uart_tasklet_action, |
2372 | (unsigned long)state); | 2375 | (unsigned long)state); |
2373 | } | 2376 | } |
2374 | 2377 | ||
2375 | retval = tty_register_driver(normal); | 2378 | retval = tty_register_driver(normal); |
2376 | out: | 2379 | out: |
2377 | if (retval < 0) { | 2380 | if (retval < 0) { |
2378 | put_tty_driver(normal); | 2381 | put_tty_driver(normal); |
2379 | kfree(drv->state); | 2382 | kfree(drv->state); |
2380 | } | 2383 | } |
2381 | return retval; | 2384 | return retval; |
2382 | } | 2385 | } |
2383 | 2386 | ||
2384 | /** | 2387 | /** |
2385 | * uart_unregister_driver - remove a driver from the uart core layer | 2388 | * uart_unregister_driver - remove a driver from the uart core layer |
2386 | * @drv: low level driver structure | 2389 | * @drv: low level driver structure |
2387 | * | 2390 | * |
2388 | * Remove all references to a driver from the core driver. The low | 2391 | * Remove all references to a driver from the core driver. The low |
2389 | * level driver must have removed all its ports via the | 2392 | * level driver must have removed all its ports via the |
2390 | * uart_remove_one_port() if it registered them with uart_add_one_port(). | 2393 | * uart_remove_one_port() if it registered them with uart_add_one_port(). |
2391 | * (ie, drv->port == NULL) | 2394 | * (ie, drv->port == NULL) |
2392 | */ | 2395 | */ |
2393 | void uart_unregister_driver(struct uart_driver *drv) | 2396 | void uart_unregister_driver(struct uart_driver *drv) |
2394 | { | 2397 | { |
2395 | struct tty_driver *p = drv->tty_driver; | 2398 | struct tty_driver *p = drv->tty_driver; |
2396 | tty_unregister_driver(p); | 2399 | tty_unregister_driver(p); |
2397 | put_tty_driver(p); | 2400 | put_tty_driver(p); |
2398 | kfree(drv->state); | 2401 | kfree(drv->state); |
2399 | drv->tty_driver = NULL; | 2402 | drv->tty_driver = NULL; |
2400 | } | 2403 | } |
2401 | 2404 | ||
2402 | struct tty_driver *uart_console_device(struct console *co, int *index) | 2405 | struct tty_driver *uart_console_device(struct console *co, int *index) |
2403 | { | 2406 | { |
2404 | struct uart_driver *p = co->data; | 2407 | struct uart_driver *p = co->data; |
2405 | *index = co->index; | 2408 | *index = co->index; |
2406 | return p->tty_driver; | 2409 | return p->tty_driver; |
2407 | } | 2410 | } |
2408 | 2411 | ||
2409 | /** | 2412 | /** |
2410 | * uart_add_one_port - attach a driver-defined port structure | 2413 | * uart_add_one_port - attach a driver-defined port structure |
2411 | * @drv: pointer to the uart low level driver structure for this port | 2414 | * @drv: pointer to the uart low level driver structure for this port |
2412 | * @port: uart port structure to use for this port. | 2415 | * @port: uart port structure to use for this port. |
2413 | * | 2416 | * |
2414 | * This allows the driver to register its own uart_port structure | 2417 | * This allows the driver to register its own uart_port structure |
2415 | * with the core driver. The main purpose is to allow the low | 2418 | * with the core driver. The main purpose is to allow the low |
2416 | * level uart drivers to expand uart_port, rather than having yet | 2419 | * level uart drivers to expand uart_port, rather than having yet |
2417 | * more levels of structures. | 2420 | * more levels of structures. |
2418 | */ | 2421 | */ |
2419 | int uart_add_one_port(struct uart_driver *drv, struct uart_port *port) | 2422 | int uart_add_one_port(struct uart_driver *drv, struct uart_port *port) |
2420 | { | 2423 | { |
2421 | struct uart_state *state; | 2424 | struct uart_state *state; |
2422 | int ret = 0; | 2425 | int ret = 0; |
2423 | struct device *tty_dev; | 2426 | struct device *tty_dev; |
2424 | 2427 | ||
2425 | BUG_ON(in_interrupt()); | 2428 | BUG_ON(in_interrupt()); |
2426 | 2429 | ||
2427 | if (port->line >= drv->nr) | 2430 | if (port->line >= drv->nr) |
2428 | return -EINVAL; | 2431 | return -EINVAL; |
2429 | 2432 | ||
2430 | state = drv->state + port->line; | 2433 | state = drv->state + port->line; |
2431 | 2434 | ||
2432 | mutex_lock(&port_mutex); | 2435 | mutex_lock(&port_mutex); |
2433 | mutex_lock(&state->mutex); | 2436 | mutex_lock(&state->mutex); |
2434 | if (state->port) { | 2437 | if (state->port) { |
2435 | ret = -EINVAL; | 2438 | ret = -EINVAL; |
2436 | goto out; | 2439 | goto out; |
2437 | } | 2440 | } |
2438 | 2441 | ||
2439 | state->port = port; | 2442 | state->port = port; |
2440 | state->pm_state = -1; | 2443 | state->pm_state = -1; |
2441 | 2444 | ||
2442 | port->cons = drv->cons; | 2445 | port->cons = drv->cons; |
2443 | port->info = &state->info; | 2446 | port->info = &state->info; |
2444 | 2447 | ||
2445 | /* | 2448 | /* |
2446 | * If this port is a console, then the spinlock is already | 2449 | * If this port is a console, then the spinlock is already |
2447 | * initialised. | 2450 | * initialised. |
2448 | */ | 2451 | */ |
2449 | if (!(uart_console(port) && (port->cons->flags & CON_ENABLED))) { | 2452 | if (!(uart_console(port) && (port->cons->flags & CON_ENABLED))) { |
2450 | spin_lock_init(&port->lock); | 2453 | spin_lock_init(&port->lock); |
2451 | lockdep_set_class(&port->lock, &port_lock_key); | 2454 | lockdep_set_class(&port->lock, &port_lock_key); |
2452 | } | 2455 | } |
2453 | 2456 | ||
2454 | uart_configure_port(drv, state, port); | 2457 | uart_configure_port(drv, state, port); |
2455 | 2458 | ||
2456 | /* | 2459 | /* |
2457 | * Register the port whether it's detected or not. This allows | 2460 | * Register the port whether it's detected or not. This allows |
2458 | * setserial to be used to alter this ports parameters. | 2461 | * setserial to be used to alter this ports parameters. |
2459 | */ | 2462 | */ |
2460 | tty_dev = tty_register_device(drv->tty_driver, port->line, port->dev); | 2463 | tty_dev = tty_register_device(drv->tty_driver, port->line, port->dev); |
2461 | if (likely(!IS_ERR(tty_dev))) { | 2464 | if (likely(!IS_ERR(tty_dev))) { |
2462 | device_init_wakeup(tty_dev, 1); | 2465 | device_init_wakeup(tty_dev, 1); |
2463 | device_set_wakeup_enable(tty_dev, 0); | 2466 | device_set_wakeup_enable(tty_dev, 0); |
2464 | } else | 2467 | } else |
2465 | printk(KERN_ERR "Cannot register tty device on line %d\n", | 2468 | printk(KERN_ERR "Cannot register tty device on line %d\n", |
2466 | port->line); | 2469 | port->line); |
2467 | 2470 | ||
2468 | /* | 2471 | /* |
2469 | * Ensure UPF_DEAD is not set. | 2472 | * Ensure UPF_DEAD is not set. |
2470 | */ | 2473 | */ |
2471 | port->flags &= ~UPF_DEAD; | 2474 | port->flags &= ~UPF_DEAD; |
2472 | 2475 | ||
2473 | out: | 2476 | out: |
2474 | mutex_unlock(&state->mutex); | 2477 | mutex_unlock(&state->mutex); |
2475 | mutex_unlock(&port_mutex); | 2478 | mutex_unlock(&port_mutex); |
2476 | 2479 | ||
2477 | return ret; | 2480 | return ret; |
2478 | } | 2481 | } |
2479 | 2482 | ||
2480 | /** | 2483 | /** |
2481 | * uart_remove_one_port - detach a driver defined port structure | 2484 | * uart_remove_one_port - detach a driver defined port structure |
2482 | * @drv: pointer to the uart low level driver structure for this port | 2485 | * @drv: pointer to the uart low level driver structure for this port |
2483 | * @port: uart port structure for this port | 2486 | * @port: uart port structure for this port |
2484 | * | 2487 | * |
2485 | * This unhooks (and hangs up) the specified port structure from the | 2488 | * This unhooks (and hangs up) the specified port structure from the |
2486 | * core driver. No further calls will be made to the low-level code | 2489 | * core driver. No further calls will be made to the low-level code |
2487 | * for this port. | 2490 | * for this port. |
2488 | */ | 2491 | */ |
2489 | int uart_remove_one_port(struct uart_driver *drv, struct uart_port *port) | 2492 | int uart_remove_one_port(struct uart_driver *drv, struct uart_port *port) |
2490 | { | 2493 | { |
2491 | struct uart_state *state = drv->state + port->line; | 2494 | struct uart_state *state = drv->state + port->line; |
2492 | struct uart_info *info; | 2495 | struct uart_info *info; |
2493 | 2496 | ||
2494 | BUG_ON(in_interrupt()); | 2497 | BUG_ON(in_interrupt()); |
2495 | 2498 | ||
2496 | if (state->port != port) | 2499 | if (state->port != port) |
2497 | printk(KERN_ALERT "Removing wrong port: %p != %p\n", | 2500 | printk(KERN_ALERT "Removing wrong port: %p != %p\n", |
2498 | state->port, port); | 2501 | state->port, port); |
2499 | 2502 | ||
2500 | mutex_lock(&port_mutex); | 2503 | mutex_lock(&port_mutex); |
2501 | 2504 | ||
2502 | /* | 2505 | /* |
2503 | * Mark the port "dead" - this prevents any opens from | 2506 | * Mark the port "dead" - this prevents any opens from |
2504 | * succeeding while we shut down the port. | 2507 | * succeeding while we shut down the port. |
2505 | */ | 2508 | */ |
2506 | mutex_lock(&state->mutex); | 2509 | mutex_lock(&state->mutex); |
2507 | port->flags |= UPF_DEAD; | 2510 | port->flags |= UPF_DEAD; |
2508 | mutex_unlock(&state->mutex); | 2511 | mutex_unlock(&state->mutex); |
2509 | 2512 | ||
2510 | /* | 2513 | /* |
2511 | * Remove the devices from the tty layer | 2514 | * Remove the devices from the tty layer |
2512 | */ | 2515 | */ |
2513 | tty_unregister_device(drv->tty_driver, port->line); | 2516 | tty_unregister_device(drv->tty_driver, port->line); |
2514 | 2517 | ||
2515 | info = &state->info; | 2518 | info = &state->info; |
2516 | if (info && info->port.tty) | 2519 | if (info && info->port.tty) |
2517 | tty_vhangup(info->port.tty); | 2520 | tty_vhangup(info->port.tty); |
2518 | 2521 | ||
2519 | /* | 2522 | /* |
2520 | * Free the port IO and memory resources, if any. | 2523 | * Free the port IO and memory resources, if any. |
2521 | */ | 2524 | */ |
2522 | if (port->type != PORT_UNKNOWN) | 2525 | if (port->type != PORT_UNKNOWN) |
2523 | port->ops->release_port(port); | 2526 | port->ops->release_port(port); |
2524 | 2527 | ||
2525 | /* | 2528 | /* |
2526 | * Indicate that there isn't a port here anymore. | 2529 | * Indicate that there isn't a port here anymore. |
2527 | */ | 2530 | */ |
2528 | port->type = PORT_UNKNOWN; | 2531 | port->type = PORT_UNKNOWN; |
2529 | 2532 | ||
2530 | /* | 2533 | /* |
2531 | * Kill the tasklet, and free resources. | 2534 | * Kill the tasklet, and free resources. |
2532 | */ | 2535 | */ |
2533 | if (info) | 2536 | if (info) |
2534 | tasklet_kill(&info->tlet); | 2537 | tasklet_kill(&info->tlet); |
2535 | 2538 | ||
2536 | state->port = NULL; | 2539 | state->port = NULL; |
2537 | mutex_unlock(&port_mutex); | 2540 | mutex_unlock(&port_mutex); |
2538 | 2541 | ||
2539 | return 0; | 2542 | return 0; |
2540 | } | 2543 | } |
2541 | 2544 | ||
2542 | /* | 2545 | /* |
2543 | * Are the two ports equivalent? | 2546 | * Are the two ports equivalent? |
2544 | */ | 2547 | */ |
2545 | int uart_match_port(struct uart_port *port1, struct uart_port *port2) | 2548 | int uart_match_port(struct uart_port *port1, struct uart_port *port2) |
2546 | { | 2549 | { |
2547 | if (port1->iotype != port2->iotype) | 2550 | if (port1->iotype != port2->iotype) |
2548 | return 0; | 2551 | return 0; |
2549 | 2552 | ||
2550 | switch (port1->iotype) { | 2553 | switch (port1->iotype) { |
2551 | case UPIO_PORT: | 2554 | case UPIO_PORT: |
2552 | return (port1->iobase == port2->iobase); | 2555 | return (port1->iobase == port2->iobase); |
2553 | case UPIO_HUB6: | 2556 | case UPIO_HUB6: |
2554 | return (port1->iobase == port2->iobase) && | 2557 | return (port1->iobase == port2->iobase) && |
2555 | (port1->hub6 == port2->hub6); | 2558 | (port1->hub6 == port2->hub6); |
2556 | case UPIO_MEM: | 2559 | case UPIO_MEM: |
2557 | case UPIO_MEM32: | 2560 | case UPIO_MEM32: |
2558 | case UPIO_AU: | 2561 | case UPIO_AU: |
2559 | case UPIO_TSI: | 2562 | case UPIO_TSI: |
2560 | case UPIO_DWAPB: | 2563 | case UPIO_DWAPB: |
2561 | return (port1->mapbase == port2->mapbase); | 2564 | return (port1->mapbase == port2->mapbase); |
2562 | } | 2565 | } |
2563 | return 0; | 2566 | return 0; |
2564 | } | 2567 | } |
2565 | EXPORT_SYMBOL(uart_match_port); | 2568 | EXPORT_SYMBOL(uart_match_port); |
2566 | 2569 | ||
2567 | EXPORT_SYMBOL(uart_write_wakeup); | 2570 | EXPORT_SYMBOL(uart_write_wakeup); |
2568 | EXPORT_SYMBOL(uart_register_driver); | 2571 | EXPORT_SYMBOL(uart_register_driver); |
2569 | EXPORT_SYMBOL(uart_unregister_driver); | 2572 | EXPORT_SYMBOL(uart_unregister_driver); |
2570 | EXPORT_SYMBOL(uart_suspend_port); | 2573 | EXPORT_SYMBOL(uart_suspend_port); |
2571 | EXPORT_SYMBOL(uart_resume_port); | 2574 | EXPORT_SYMBOL(uart_resume_port); |
2572 | EXPORT_SYMBOL(uart_add_one_port); | 2575 | EXPORT_SYMBOL(uart_add_one_port); |
2573 | EXPORT_SYMBOL(uart_remove_one_port); | 2576 | EXPORT_SYMBOL(uart_remove_one_port); |
2574 | 2577 | ||
2575 | MODULE_DESCRIPTION("Serial driver core"); | 2578 | MODULE_DESCRIPTION("Serial driver core"); |
2576 | MODULE_LICENSE("GPL"); | 2579 | MODULE_LICENSE("GPL"); |
2577 | 2580 |
include/linux/serial_8250.h
1 | /* | 1 | /* |
2 | * linux/include/linux/serial_8250.h | 2 | * linux/include/linux/serial_8250.h |
3 | * | 3 | * |
4 | * Copyright (C) 2004 Russell King | 4 | * Copyright (C) 2004 Russell King |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or | 8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
10 | */ | 10 | */ |
11 | #ifndef _LINUX_SERIAL_8250_H | 11 | #ifndef _LINUX_SERIAL_8250_H |
12 | #define _LINUX_SERIAL_8250_H | 12 | #define _LINUX_SERIAL_8250_H |
13 | 13 | ||
14 | #include <linux/serial_core.h> | 14 | #include <linux/serial_core.h> |
15 | #include <linux/platform_device.h> | 15 | #include <linux/platform_device.h> |
16 | 16 | ||
17 | /* | 17 | /* |
18 | * This is the platform device platform_data structure | 18 | * This is the platform device platform_data structure |
19 | */ | 19 | */ |
20 | struct plat_serial8250_port { | 20 | struct plat_serial8250_port { |
21 | unsigned long iobase; /* io base address */ | 21 | unsigned long iobase; /* io base address */ |
22 | void __iomem *membase; /* ioremap cookie or NULL */ | 22 | void __iomem *membase; /* ioremap cookie or NULL */ |
23 | resource_size_t mapbase; /* resource base */ | 23 | resource_size_t mapbase; /* resource base */ |
24 | unsigned int irq; /* interrupt number */ | 24 | unsigned int irq; /* interrupt number */ |
25 | unsigned int uartclk; /* UART clock rate */ | 25 | unsigned int uartclk; /* UART clock rate */ |
26 | void *private_data; | 26 | void *private_data; |
27 | unsigned char regshift; /* register shift */ | 27 | unsigned char regshift; /* register shift */ |
28 | unsigned char iotype; /* UPIO_* */ | 28 | unsigned char iotype; /* UPIO_* */ |
29 | unsigned char hub6; | 29 | unsigned char hub6; |
30 | upf_t flags; /* UPF_* flags */ | 30 | upf_t flags; /* UPF_* flags */ |
31 | unsigned int type; /* If UPF_FIXED_TYPE */ | ||
31 | unsigned int (*serial_in)(struct uart_port *, int); | 32 | unsigned int (*serial_in)(struct uart_port *, int); |
32 | void (*serial_out)(struct uart_port *, int, int); | 33 | void (*serial_out)(struct uart_port *, int, int); |
33 | }; | 34 | }; |
34 | 35 | ||
35 | /* | 36 | /* |
36 | * Allocate 8250 platform device IDs. Nothing is implied by | 37 | * Allocate 8250 platform device IDs. Nothing is implied by |
37 | * the numbering here, except for the legacy entry being -1. | 38 | * the numbering here, except for the legacy entry being -1. |
38 | */ | 39 | */ |
39 | enum { | 40 | enum { |
40 | PLAT8250_DEV_LEGACY = -1, | 41 | PLAT8250_DEV_LEGACY = -1, |
41 | PLAT8250_DEV_PLATFORM, | 42 | PLAT8250_DEV_PLATFORM, |
42 | PLAT8250_DEV_PLATFORM1, | 43 | PLAT8250_DEV_PLATFORM1, |
43 | PLAT8250_DEV_PLATFORM2, | 44 | PLAT8250_DEV_PLATFORM2, |
44 | PLAT8250_DEV_FOURPORT, | 45 | PLAT8250_DEV_FOURPORT, |
45 | PLAT8250_DEV_ACCENT, | 46 | PLAT8250_DEV_ACCENT, |
46 | PLAT8250_DEV_BOCA, | 47 | PLAT8250_DEV_BOCA, |
47 | PLAT8250_DEV_EXAR_ST16C554, | 48 | PLAT8250_DEV_EXAR_ST16C554, |
48 | PLAT8250_DEV_HUB6, | 49 | PLAT8250_DEV_HUB6, |
49 | PLAT8250_DEV_MCA, | 50 | PLAT8250_DEV_MCA, |
50 | PLAT8250_DEV_AU1X00, | 51 | PLAT8250_DEV_AU1X00, |
51 | PLAT8250_DEV_SM501, | 52 | PLAT8250_DEV_SM501, |
52 | }; | 53 | }; |
53 | 54 | ||
54 | /* | 55 | /* |
55 | * This should be used by drivers which want to register | 56 | * This should be used by drivers which want to register |
56 | * their own 8250 ports without registering their own | 57 | * their own 8250 ports without registering their own |
57 | * platform device. Using these will make your driver | 58 | * platform device. Using these will make your driver |
58 | * dependent on the 8250 driver. | 59 | * dependent on the 8250 driver. |
59 | */ | 60 | */ |
60 | struct uart_port; | 61 | struct uart_port; |
61 | 62 | ||
62 | int serial8250_register_port(struct uart_port *); | 63 | int serial8250_register_port(struct uart_port *); |
63 | void serial8250_unregister_port(int line); | 64 | void serial8250_unregister_port(int line); |
64 | void serial8250_suspend_port(int line); | 65 | void serial8250_suspend_port(int line); |
65 | void serial8250_resume_port(int line); | 66 | void serial8250_resume_port(int line); |
66 | 67 | ||
67 | extern int early_serial_setup(struct uart_port *port); | 68 | extern int early_serial_setup(struct uart_port *port); |
68 | 69 | ||
69 | extern int serial8250_find_port(struct uart_port *p); | 70 | extern int serial8250_find_port(struct uart_port *p); |
70 | extern int serial8250_find_port_for_earlycon(void); | 71 | extern int serial8250_find_port_for_earlycon(void); |
71 | extern int setup_early_serial8250_console(char *cmdline); | 72 | extern int setup_early_serial8250_console(char *cmdline); |
72 | 73 | ||
73 | #endif | 74 | #endif |
74 | 75 |
include/linux/serial_core.h
1 | /* | 1 | /* |
2 | * linux/drivers/char/serial_core.h | 2 | * linux/drivers/char/serial_core.h |
3 | * | 3 | * |
4 | * Copyright (C) 2000 Deep Blue Solutions Ltd. | 4 | * Copyright (C) 2000 Deep Blue Solutions Ltd. |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or | 8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
10 | * | 10 | * |
11 | * This program is distributed in the hope that it will be useful, | 11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. | 14 | * GNU General Public License for more details. |
15 | * | 15 | * |
16 | * You should have received a copy of the GNU General Public License | 16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software | 17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | */ | 19 | */ |
20 | #ifndef LINUX_SERIAL_CORE_H | 20 | #ifndef LINUX_SERIAL_CORE_H |
21 | #define LINUX_SERIAL_CORE_H | 21 | #define LINUX_SERIAL_CORE_H |
22 | 22 | ||
23 | /* | 23 | /* |
24 | * The type definitions. These are from Ted Ts'o's serial.h | 24 | * The type definitions. These are from Ted Ts'o's serial.h |
25 | */ | 25 | */ |
26 | #define PORT_UNKNOWN 0 | 26 | #define PORT_UNKNOWN 0 |
27 | #define PORT_8250 1 | 27 | #define PORT_8250 1 |
28 | #define PORT_16450 2 | 28 | #define PORT_16450 2 |
29 | #define PORT_16550 3 | 29 | #define PORT_16550 3 |
30 | #define PORT_16550A 4 | 30 | #define PORT_16550A 4 |
31 | #define PORT_CIRRUS 5 | 31 | #define PORT_CIRRUS 5 |
32 | #define PORT_16650 6 | 32 | #define PORT_16650 6 |
33 | #define PORT_16650V2 7 | 33 | #define PORT_16650V2 7 |
34 | #define PORT_16750 8 | 34 | #define PORT_16750 8 |
35 | #define PORT_STARTECH 9 | 35 | #define PORT_STARTECH 9 |
36 | #define PORT_16C950 10 | 36 | #define PORT_16C950 10 |
37 | #define PORT_16654 11 | 37 | #define PORT_16654 11 |
38 | #define PORT_16850 12 | 38 | #define PORT_16850 12 |
39 | #define PORT_RSA 13 | 39 | #define PORT_RSA 13 |
40 | #define PORT_NS16550A 14 | 40 | #define PORT_NS16550A 14 |
41 | #define PORT_XSCALE 15 | 41 | #define PORT_XSCALE 15 |
42 | #define PORT_RM9000 16 /* PMC-Sierra RM9xxx internal UART */ | 42 | #define PORT_RM9000 16 /* PMC-Sierra RM9xxx internal UART */ |
43 | #define PORT_MAX_8250 16 /* max port ID */ | 43 | #define PORT_MAX_8250 16 /* max port ID */ |
44 | 44 | ||
45 | /* | 45 | /* |
46 | * ARM specific type numbers. These are not currently guaranteed | 46 | * ARM specific type numbers. These are not currently guaranteed |
47 | * to be implemented, and will change in the future. These are | 47 | * to be implemented, and will change in the future. These are |
48 | * separate so any additions to the old serial.c that occur before | 48 | * separate so any additions to the old serial.c that occur before |
49 | * we are merged can be easily merged here. | 49 | * we are merged can be easily merged here. |
50 | */ | 50 | */ |
51 | #define PORT_PXA 31 | 51 | #define PORT_PXA 31 |
52 | #define PORT_AMBA 32 | 52 | #define PORT_AMBA 32 |
53 | #define PORT_CLPS711X 33 | 53 | #define PORT_CLPS711X 33 |
54 | #define PORT_SA1100 34 | 54 | #define PORT_SA1100 34 |
55 | #define PORT_UART00 35 | 55 | #define PORT_UART00 35 |
56 | #define PORT_21285 37 | 56 | #define PORT_21285 37 |
57 | 57 | ||
58 | /* Sparc type numbers. */ | 58 | /* Sparc type numbers. */ |
59 | #define PORT_SUNZILOG 38 | 59 | #define PORT_SUNZILOG 38 |
60 | #define PORT_SUNSAB 39 | 60 | #define PORT_SUNSAB 39 |
61 | 61 | ||
62 | /* DEC */ | 62 | /* DEC */ |
63 | #define PORT_DZ 46 | 63 | #define PORT_DZ 46 |
64 | #define PORT_ZS 47 | 64 | #define PORT_ZS 47 |
65 | 65 | ||
66 | /* Parisc type numbers. */ | 66 | /* Parisc type numbers. */ |
67 | #define PORT_MUX 48 | 67 | #define PORT_MUX 48 |
68 | 68 | ||
69 | /* Atmel AT91 / AT32 SoC */ | 69 | /* Atmel AT91 / AT32 SoC */ |
70 | #define PORT_ATMEL 49 | 70 | #define PORT_ATMEL 49 |
71 | 71 | ||
72 | /* Macintosh Zilog type numbers */ | 72 | /* Macintosh Zilog type numbers */ |
73 | #define PORT_MAC_ZILOG 50 /* m68k : not yet implemented */ | 73 | #define PORT_MAC_ZILOG 50 /* m68k : not yet implemented */ |
74 | #define PORT_PMAC_ZILOG 51 | 74 | #define PORT_PMAC_ZILOG 51 |
75 | 75 | ||
76 | /* SH-SCI */ | 76 | /* SH-SCI */ |
77 | #define PORT_SCI 52 | 77 | #define PORT_SCI 52 |
78 | #define PORT_SCIF 53 | 78 | #define PORT_SCIF 53 |
79 | #define PORT_IRDA 54 | 79 | #define PORT_IRDA 54 |
80 | 80 | ||
81 | /* Samsung S3C2410 SoC and derivatives thereof */ | 81 | /* Samsung S3C2410 SoC and derivatives thereof */ |
82 | #define PORT_S3C2410 55 | 82 | #define PORT_S3C2410 55 |
83 | 83 | ||
84 | /* SGI IP22 aka Indy / Challenge S / Indigo 2 */ | 84 | /* SGI IP22 aka Indy / Challenge S / Indigo 2 */ |
85 | #define PORT_IP22ZILOG 56 | 85 | #define PORT_IP22ZILOG 56 |
86 | 86 | ||
87 | /* Sharp LH7a40x -- an ARM9 SoC series */ | 87 | /* Sharp LH7a40x -- an ARM9 SoC series */ |
88 | #define PORT_LH7A40X 57 | 88 | #define PORT_LH7A40X 57 |
89 | 89 | ||
90 | /* PPC CPM type number */ | 90 | /* PPC CPM type number */ |
91 | #define PORT_CPM 58 | 91 | #define PORT_CPM 58 |
92 | 92 | ||
93 | /* MPC52xx type numbers */ | 93 | /* MPC52xx type numbers */ |
94 | #define PORT_MPC52xx 59 | 94 | #define PORT_MPC52xx 59 |
95 | 95 | ||
96 | /* IBM icom */ | 96 | /* IBM icom */ |
97 | #define PORT_ICOM 60 | 97 | #define PORT_ICOM 60 |
98 | 98 | ||
99 | /* Samsung S3C2440 SoC */ | 99 | /* Samsung S3C2440 SoC */ |
100 | #define PORT_S3C2440 61 | 100 | #define PORT_S3C2440 61 |
101 | 101 | ||
102 | /* Motorola i.MX SoC */ | 102 | /* Motorola i.MX SoC */ |
103 | #define PORT_IMX 62 | 103 | #define PORT_IMX 62 |
104 | 104 | ||
105 | /* Marvell MPSC */ | 105 | /* Marvell MPSC */ |
106 | #define PORT_MPSC 63 | 106 | #define PORT_MPSC 63 |
107 | 107 | ||
108 | /* TXX9 type number */ | 108 | /* TXX9 type number */ |
109 | #define PORT_TXX9 64 | 109 | #define PORT_TXX9 64 |
110 | 110 | ||
111 | /* NEC VR4100 series SIU/DSIU */ | 111 | /* NEC VR4100 series SIU/DSIU */ |
112 | #define PORT_VR41XX_SIU 65 | 112 | #define PORT_VR41XX_SIU 65 |
113 | #define PORT_VR41XX_DSIU 66 | 113 | #define PORT_VR41XX_DSIU 66 |
114 | 114 | ||
115 | /* Samsung S3C2400 SoC */ | 115 | /* Samsung S3C2400 SoC */ |
116 | #define PORT_S3C2400 67 | 116 | #define PORT_S3C2400 67 |
117 | 117 | ||
118 | /* M32R SIO */ | 118 | /* M32R SIO */ |
119 | #define PORT_M32R_SIO 68 | 119 | #define PORT_M32R_SIO 68 |
120 | 120 | ||
121 | /*Digi jsm */ | 121 | /*Digi jsm */ |
122 | #define PORT_JSM 69 | 122 | #define PORT_JSM 69 |
123 | 123 | ||
124 | #define PORT_PNX8XXX 70 | 124 | #define PORT_PNX8XXX 70 |
125 | 125 | ||
126 | /* Hilscher netx */ | 126 | /* Hilscher netx */ |
127 | #define PORT_NETX 71 | 127 | #define PORT_NETX 71 |
128 | 128 | ||
129 | /* SUN4V Hypervisor Console */ | 129 | /* SUN4V Hypervisor Console */ |
130 | #define PORT_SUNHV 72 | 130 | #define PORT_SUNHV 72 |
131 | 131 | ||
132 | #define PORT_S3C2412 73 | 132 | #define PORT_S3C2412 73 |
133 | 133 | ||
134 | /* Xilinx uartlite */ | 134 | /* Xilinx uartlite */ |
135 | #define PORT_UARTLITE 74 | 135 | #define PORT_UARTLITE 74 |
136 | 136 | ||
137 | /* Blackfin bf5xx */ | 137 | /* Blackfin bf5xx */ |
138 | #define PORT_BFIN 75 | 138 | #define PORT_BFIN 75 |
139 | 139 | ||
140 | /* Micrel KS8695 */ | 140 | /* Micrel KS8695 */ |
141 | #define PORT_KS8695 76 | 141 | #define PORT_KS8695 76 |
142 | 142 | ||
143 | /* Broadcom SB1250, etc. SOC */ | 143 | /* Broadcom SB1250, etc. SOC */ |
144 | #define PORT_SB1250_DUART 77 | 144 | #define PORT_SB1250_DUART 77 |
145 | 145 | ||
146 | /* Freescale ColdFire */ | 146 | /* Freescale ColdFire */ |
147 | #define PORT_MCF 78 | 147 | #define PORT_MCF 78 |
148 | 148 | ||
149 | /* Blackfin SPORT */ | 149 | /* Blackfin SPORT */ |
150 | #define PORT_BFIN_SPORT 79 | 150 | #define PORT_BFIN_SPORT 79 |
151 | 151 | ||
152 | /* MN10300 on-chip UART numbers */ | 152 | /* MN10300 on-chip UART numbers */ |
153 | #define PORT_MN10300 80 | 153 | #define PORT_MN10300 80 |
154 | #define PORT_MN10300_CTS 81 | 154 | #define PORT_MN10300_CTS 81 |
155 | 155 | ||
156 | #define PORT_SC26XX 82 | 156 | #define PORT_SC26XX 82 |
157 | 157 | ||
158 | /* SH-SCI */ | 158 | /* SH-SCI */ |
159 | #define PORT_SCIFA 83 | 159 | #define PORT_SCIFA 83 |
160 | 160 | ||
161 | #define PORT_S3C6400 84 | 161 | #define PORT_S3C6400 84 |
162 | 162 | ||
163 | #ifdef __KERNEL__ | 163 | #ifdef __KERNEL__ |
164 | 164 | ||
165 | #include <linux/compiler.h> | 165 | #include <linux/compiler.h> |
166 | #include <linux/interrupt.h> | 166 | #include <linux/interrupt.h> |
167 | #include <linux/circ_buf.h> | 167 | #include <linux/circ_buf.h> |
168 | #include <linux/spinlock.h> | 168 | #include <linux/spinlock.h> |
169 | #include <linux/sched.h> | 169 | #include <linux/sched.h> |
170 | #include <linux/tty.h> | 170 | #include <linux/tty.h> |
171 | #include <linux/mutex.h> | 171 | #include <linux/mutex.h> |
172 | #include <linux/sysrq.h> | 172 | #include <linux/sysrq.h> |
173 | 173 | ||
174 | struct uart_port; | 174 | struct uart_port; |
175 | struct uart_info; | 175 | struct uart_info; |
176 | struct serial_struct; | 176 | struct serial_struct; |
177 | struct device; | 177 | struct device; |
178 | 178 | ||
179 | /* | 179 | /* |
180 | * This structure describes all the operations that can be | 180 | * This structure describes all the operations that can be |
181 | * done on the physical hardware. | 181 | * done on the physical hardware. |
182 | */ | 182 | */ |
183 | struct uart_ops { | 183 | struct uart_ops { |
184 | unsigned int (*tx_empty)(struct uart_port *); | 184 | unsigned int (*tx_empty)(struct uart_port *); |
185 | void (*set_mctrl)(struct uart_port *, unsigned int mctrl); | 185 | void (*set_mctrl)(struct uart_port *, unsigned int mctrl); |
186 | unsigned int (*get_mctrl)(struct uart_port *); | 186 | unsigned int (*get_mctrl)(struct uart_port *); |
187 | void (*stop_tx)(struct uart_port *); | 187 | void (*stop_tx)(struct uart_port *); |
188 | void (*start_tx)(struct uart_port *); | 188 | void (*start_tx)(struct uart_port *); |
189 | void (*send_xchar)(struct uart_port *, char ch); | 189 | void (*send_xchar)(struct uart_port *, char ch); |
190 | void (*stop_rx)(struct uart_port *); | 190 | void (*stop_rx)(struct uart_port *); |
191 | void (*enable_ms)(struct uart_port *); | 191 | void (*enable_ms)(struct uart_port *); |
192 | void (*break_ctl)(struct uart_port *, int ctl); | 192 | void (*break_ctl)(struct uart_port *, int ctl); |
193 | int (*startup)(struct uart_port *); | 193 | int (*startup)(struct uart_port *); |
194 | void (*shutdown)(struct uart_port *); | 194 | void (*shutdown)(struct uart_port *); |
195 | void (*flush_buffer)(struct uart_port *); | 195 | void (*flush_buffer)(struct uart_port *); |
196 | void (*set_termios)(struct uart_port *, struct ktermios *new, | 196 | void (*set_termios)(struct uart_port *, struct ktermios *new, |
197 | struct ktermios *old); | 197 | struct ktermios *old); |
198 | void (*set_ldisc)(struct uart_port *); | 198 | void (*set_ldisc)(struct uart_port *); |
199 | void (*pm)(struct uart_port *, unsigned int state, | 199 | void (*pm)(struct uart_port *, unsigned int state, |
200 | unsigned int oldstate); | 200 | unsigned int oldstate); |
201 | int (*set_wake)(struct uart_port *, unsigned int state); | 201 | int (*set_wake)(struct uart_port *, unsigned int state); |
202 | 202 | ||
203 | /* | 203 | /* |
204 | * Return a string describing the type of the port | 204 | * Return a string describing the type of the port |
205 | */ | 205 | */ |
206 | const char *(*type)(struct uart_port *); | 206 | const char *(*type)(struct uart_port *); |
207 | 207 | ||
208 | /* | 208 | /* |
209 | * Release IO and memory resources used by the port. | 209 | * Release IO and memory resources used by the port. |
210 | * This includes iounmap if necessary. | 210 | * This includes iounmap if necessary. |
211 | */ | 211 | */ |
212 | void (*release_port)(struct uart_port *); | 212 | void (*release_port)(struct uart_port *); |
213 | 213 | ||
214 | /* | 214 | /* |
215 | * Request IO and memory resources used by the port. | 215 | * Request IO and memory resources used by the port. |
216 | * This includes iomapping the port if necessary. | 216 | * This includes iomapping the port if necessary. |
217 | */ | 217 | */ |
218 | int (*request_port)(struct uart_port *); | 218 | int (*request_port)(struct uart_port *); |
219 | void (*config_port)(struct uart_port *, int); | 219 | void (*config_port)(struct uart_port *, int); |
220 | int (*verify_port)(struct uart_port *, struct serial_struct *); | 220 | int (*verify_port)(struct uart_port *, struct serial_struct *); |
221 | int (*ioctl)(struct uart_port *, unsigned int, unsigned long); | 221 | int (*ioctl)(struct uart_port *, unsigned int, unsigned long); |
222 | #ifdef CONFIG_CONSOLE_POLL | 222 | #ifdef CONFIG_CONSOLE_POLL |
223 | void (*poll_put_char)(struct uart_port *, unsigned char); | 223 | void (*poll_put_char)(struct uart_port *, unsigned char); |
224 | int (*poll_get_char)(struct uart_port *); | 224 | int (*poll_get_char)(struct uart_port *); |
225 | #endif | 225 | #endif |
226 | }; | 226 | }; |
227 | 227 | ||
228 | #define UART_CONFIG_TYPE (1 << 0) | 228 | #define UART_CONFIG_TYPE (1 << 0) |
229 | #define UART_CONFIG_IRQ (1 << 1) | 229 | #define UART_CONFIG_IRQ (1 << 1) |
230 | 230 | ||
231 | struct uart_icount { | 231 | struct uart_icount { |
232 | __u32 cts; | 232 | __u32 cts; |
233 | __u32 dsr; | 233 | __u32 dsr; |
234 | __u32 rng; | 234 | __u32 rng; |
235 | __u32 dcd; | 235 | __u32 dcd; |
236 | __u32 rx; | 236 | __u32 rx; |
237 | __u32 tx; | 237 | __u32 tx; |
238 | __u32 frame; | 238 | __u32 frame; |
239 | __u32 overrun; | 239 | __u32 overrun; |
240 | __u32 parity; | 240 | __u32 parity; |
241 | __u32 brk; | 241 | __u32 brk; |
242 | __u32 buf_overrun; | 242 | __u32 buf_overrun; |
243 | }; | 243 | }; |
244 | 244 | ||
245 | typedef unsigned int __bitwise__ upf_t; | 245 | typedef unsigned int __bitwise__ upf_t; |
246 | 246 | ||
247 | struct uart_port { | 247 | struct uart_port { |
248 | spinlock_t lock; /* port lock */ | 248 | spinlock_t lock; /* port lock */ |
249 | unsigned long iobase; /* in/out[bwl] */ | 249 | unsigned long iobase; /* in/out[bwl] */ |
250 | unsigned char __iomem *membase; /* read/write[bwl] */ | 250 | unsigned char __iomem *membase; /* read/write[bwl] */ |
251 | unsigned int (*serial_in)(struct uart_port *, int); | 251 | unsigned int (*serial_in)(struct uart_port *, int); |
252 | void (*serial_out)(struct uart_port *, int, int); | 252 | void (*serial_out)(struct uart_port *, int, int); |
253 | unsigned int irq; /* irq number */ | 253 | unsigned int irq; /* irq number */ |
254 | unsigned int uartclk; /* base uart clock */ | 254 | unsigned int uartclk; /* base uart clock */ |
255 | unsigned int fifosize; /* tx fifo size */ | 255 | unsigned int fifosize; /* tx fifo size */ |
256 | unsigned char x_char; /* xon/xoff char */ | 256 | unsigned char x_char; /* xon/xoff char */ |
257 | unsigned char regshift; /* reg offset shift */ | 257 | unsigned char regshift; /* reg offset shift */ |
258 | unsigned char iotype; /* io access style */ | 258 | unsigned char iotype; /* io access style */ |
259 | unsigned char unused1; | 259 | unsigned char unused1; |
260 | 260 | ||
261 | #define UPIO_PORT (0) | 261 | #define UPIO_PORT (0) |
262 | #define UPIO_HUB6 (1) | 262 | #define UPIO_HUB6 (1) |
263 | #define UPIO_MEM (2) | 263 | #define UPIO_MEM (2) |
264 | #define UPIO_MEM32 (3) | 264 | #define UPIO_MEM32 (3) |
265 | #define UPIO_AU (4) /* Au1x00 type IO */ | 265 | #define UPIO_AU (4) /* Au1x00 type IO */ |
266 | #define UPIO_TSI (5) /* Tsi108/109 type IO */ | 266 | #define UPIO_TSI (5) /* Tsi108/109 type IO */ |
267 | #define UPIO_DWAPB (6) /* DesignWare APB UART */ | 267 | #define UPIO_DWAPB (6) /* DesignWare APB UART */ |
268 | #define UPIO_RM9000 (7) /* RM9000 type IO */ | 268 | #define UPIO_RM9000 (7) /* RM9000 type IO */ |
269 | 269 | ||
270 | unsigned int read_status_mask; /* driver specific */ | 270 | unsigned int read_status_mask; /* driver specific */ |
271 | unsigned int ignore_status_mask; /* driver specific */ | 271 | unsigned int ignore_status_mask; /* driver specific */ |
272 | struct uart_info *info; /* pointer to parent info */ | 272 | struct uart_info *info; /* pointer to parent info */ |
273 | struct uart_icount icount; /* statistics */ | 273 | struct uart_icount icount; /* statistics */ |
274 | 274 | ||
275 | struct console *cons; /* struct console, if any */ | 275 | struct console *cons; /* struct console, if any */ |
276 | #ifdef CONFIG_SERIAL_CORE_CONSOLE | 276 | #ifdef CONFIG_SERIAL_CORE_CONSOLE |
277 | unsigned long sysrq; /* sysrq timeout */ | 277 | unsigned long sysrq; /* sysrq timeout */ |
278 | #endif | 278 | #endif |
279 | 279 | ||
280 | upf_t flags; | 280 | upf_t flags; |
281 | 281 | ||
282 | #define UPF_FOURPORT ((__force upf_t) (1 << 1)) | 282 | #define UPF_FOURPORT ((__force upf_t) (1 << 1)) |
283 | #define UPF_SAK ((__force upf_t) (1 << 2)) | 283 | #define UPF_SAK ((__force upf_t) (1 << 2)) |
284 | #define UPF_SPD_MASK ((__force upf_t) (0x1030)) | 284 | #define UPF_SPD_MASK ((__force upf_t) (0x1030)) |
285 | #define UPF_SPD_HI ((__force upf_t) (0x0010)) | 285 | #define UPF_SPD_HI ((__force upf_t) (0x0010)) |
286 | #define UPF_SPD_VHI ((__force upf_t) (0x0020)) | 286 | #define UPF_SPD_VHI ((__force upf_t) (0x0020)) |
287 | #define UPF_SPD_CUST ((__force upf_t) (0x0030)) | 287 | #define UPF_SPD_CUST ((__force upf_t) (0x0030)) |
288 | #define UPF_SPD_SHI ((__force upf_t) (0x1000)) | 288 | #define UPF_SPD_SHI ((__force upf_t) (0x1000)) |
289 | #define UPF_SPD_WARP ((__force upf_t) (0x1010)) | 289 | #define UPF_SPD_WARP ((__force upf_t) (0x1010)) |
290 | #define UPF_SKIP_TEST ((__force upf_t) (1 << 6)) | 290 | #define UPF_SKIP_TEST ((__force upf_t) (1 << 6)) |
291 | #define UPF_AUTO_IRQ ((__force upf_t) (1 << 7)) | 291 | #define UPF_AUTO_IRQ ((__force upf_t) (1 << 7)) |
292 | #define UPF_HARDPPS_CD ((__force upf_t) (1 << 11)) | 292 | #define UPF_HARDPPS_CD ((__force upf_t) (1 << 11)) |
293 | #define UPF_LOW_LATENCY ((__force upf_t) (1 << 13)) | 293 | #define UPF_LOW_LATENCY ((__force upf_t) (1 << 13)) |
294 | #define UPF_BUGGY_UART ((__force upf_t) (1 << 14)) | 294 | #define UPF_BUGGY_UART ((__force upf_t) (1 << 14)) |
295 | #define UPF_MAGIC_MULTIPLIER ((__force upf_t) (1 << 16)) | 295 | #define UPF_MAGIC_MULTIPLIER ((__force upf_t) (1 << 16)) |
296 | #define UPF_CONS_FLOW ((__force upf_t) (1 << 23)) | 296 | #define UPF_CONS_FLOW ((__force upf_t) (1 << 23)) |
297 | #define UPF_SHARE_IRQ ((__force upf_t) (1 << 24)) | 297 | #define UPF_SHARE_IRQ ((__force upf_t) (1 << 24)) |
298 | /* The exact UART type is known and should not be probed. */ | ||
299 | #define UPF_FIXED_TYPE ((__force upf_t) (1 << 27)) | ||
298 | #define UPF_BOOT_AUTOCONF ((__force upf_t) (1 << 28)) | 300 | #define UPF_BOOT_AUTOCONF ((__force upf_t) (1 << 28)) |
299 | #define UPF_FIXED_PORT ((__force upf_t) (1 << 29)) | 301 | #define UPF_FIXED_PORT ((__force upf_t) (1 << 29)) |
300 | #define UPF_DEAD ((__force upf_t) (1 << 30)) | 302 | #define UPF_DEAD ((__force upf_t) (1 << 30)) |
301 | #define UPF_IOREMAP ((__force upf_t) (1 << 31)) | 303 | #define UPF_IOREMAP ((__force upf_t) (1 << 31)) |
302 | 304 | ||
303 | #define UPF_CHANGE_MASK ((__force upf_t) (0x17fff)) | 305 | #define UPF_CHANGE_MASK ((__force upf_t) (0x17fff)) |
304 | #define UPF_USR_MASK ((__force upf_t) (UPF_SPD_MASK|UPF_LOW_LATENCY)) | 306 | #define UPF_USR_MASK ((__force upf_t) (UPF_SPD_MASK|UPF_LOW_LATENCY)) |
305 | 307 | ||
306 | unsigned int mctrl; /* current modem ctrl settings */ | 308 | unsigned int mctrl; /* current modem ctrl settings */ |
307 | unsigned int timeout; /* character-based timeout */ | 309 | unsigned int timeout; /* character-based timeout */ |
308 | unsigned int type; /* port type */ | 310 | unsigned int type; /* port type */ |
309 | const struct uart_ops *ops; | 311 | const struct uart_ops *ops; |
310 | unsigned int custom_divisor; | 312 | unsigned int custom_divisor; |
311 | unsigned int line; /* port index */ | 313 | unsigned int line; /* port index */ |
312 | resource_size_t mapbase; /* for ioremap */ | 314 | resource_size_t mapbase; /* for ioremap */ |
313 | struct device *dev; /* parent device */ | 315 | struct device *dev; /* parent device */ |
314 | unsigned char hub6; /* this should be in the 8250 driver */ | 316 | unsigned char hub6; /* this should be in the 8250 driver */ |
315 | unsigned char suspended; | 317 | unsigned char suspended; |
316 | unsigned char unused[2]; | 318 | unsigned char unused[2]; |
317 | void *private_data; /* generic platform data pointer */ | 319 | void *private_data; /* generic platform data pointer */ |
318 | }; | 320 | }; |
319 | 321 | ||
320 | /* | 322 | /* |
321 | * This is the state information which is only valid when the port | 323 | * This is the state information which is only valid when the port |
322 | * is open; it may be cleared the core driver once the device has | 324 | * is open; it may be cleared the core driver once the device has |
323 | * been closed. Either the low level driver or the core can modify | 325 | * been closed. Either the low level driver or the core can modify |
324 | * stuff here. | 326 | * stuff here. |
325 | */ | 327 | */ |
326 | typedef unsigned int __bitwise__ uif_t; | 328 | typedef unsigned int __bitwise__ uif_t; |
327 | 329 | ||
328 | struct uart_info { | 330 | struct uart_info { |
329 | struct tty_port port; | 331 | struct tty_port port; |
330 | struct circ_buf xmit; | 332 | struct circ_buf xmit; |
331 | uif_t flags; | 333 | uif_t flags; |
332 | 334 | ||
333 | /* | 335 | /* |
334 | * Definitions for info->flags. These are _private_ to serial_core, and | 336 | * Definitions for info->flags. These are _private_ to serial_core, and |
335 | * are specific to this structure. They may be queried by low level drivers. | 337 | * are specific to this structure. They may be queried by low level drivers. |
336 | * | 338 | * |
337 | * FIXME: use the ASY_ definitions | 339 | * FIXME: use the ASY_ definitions |
338 | */ | 340 | */ |
339 | #define UIF_CHECK_CD ((__force uif_t) (1 << 25)) | 341 | #define UIF_CHECK_CD ((__force uif_t) (1 << 25)) |
340 | #define UIF_CTS_FLOW ((__force uif_t) (1 << 26)) | 342 | #define UIF_CTS_FLOW ((__force uif_t) (1 << 26)) |
341 | #define UIF_NORMAL_ACTIVE ((__force uif_t) (1 << 29)) | 343 | #define UIF_NORMAL_ACTIVE ((__force uif_t) (1 << 29)) |
342 | #define UIF_INITIALIZED ((__force uif_t) (1 << 31)) | 344 | #define UIF_INITIALIZED ((__force uif_t) (1 << 31)) |
343 | #define UIF_SUSPENDED ((__force uif_t) (1 << 30)) | 345 | #define UIF_SUSPENDED ((__force uif_t) (1 << 30)) |
344 | 346 | ||
345 | struct tasklet_struct tlet; | 347 | struct tasklet_struct tlet; |
346 | wait_queue_head_t delta_msr_wait; | 348 | wait_queue_head_t delta_msr_wait; |
347 | }; | 349 | }; |
348 | 350 | ||
349 | /* | 351 | /* |
350 | * This is the state information which is persistent across opens. | 352 | * This is the state information which is persistent across opens. |
351 | * The low level driver must not to touch any elements contained | 353 | * The low level driver must not to touch any elements contained |
352 | * within. | 354 | * within. |
353 | */ | 355 | */ |
354 | struct uart_state { | 356 | struct uart_state { |
355 | unsigned int close_delay; /* msec */ | 357 | unsigned int close_delay; /* msec */ |
356 | unsigned int closing_wait; /* msec */ | 358 | unsigned int closing_wait; /* msec */ |
357 | 359 | ||
358 | #define USF_CLOSING_WAIT_INF (0) | 360 | #define USF_CLOSING_WAIT_INF (0) |
359 | #define USF_CLOSING_WAIT_NONE (~0U) | 361 | #define USF_CLOSING_WAIT_NONE (~0U) |
360 | 362 | ||
361 | int count; | 363 | int count; |
362 | int pm_state; | 364 | int pm_state; |
363 | struct uart_info info; | 365 | struct uart_info info; |
364 | struct uart_port *port; | 366 | struct uart_port *port; |
365 | 367 | ||
366 | struct mutex mutex; | 368 | struct mutex mutex; |
367 | }; | 369 | }; |
368 | 370 | ||
369 | #define UART_XMIT_SIZE PAGE_SIZE | 371 | #define UART_XMIT_SIZE PAGE_SIZE |
370 | 372 | ||
371 | 373 | ||
372 | /* number of characters left in xmit buffer before we ask for more */ | 374 | /* number of characters left in xmit buffer before we ask for more */ |
373 | #define WAKEUP_CHARS 256 | 375 | #define WAKEUP_CHARS 256 |
374 | 376 | ||
375 | struct module; | 377 | struct module; |
376 | struct tty_driver; | 378 | struct tty_driver; |
377 | 379 | ||
378 | struct uart_driver { | 380 | struct uart_driver { |
379 | struct module *owner; | 381 | struct module *owner; |
380 | const char *driver_name; | 382 | const char *driver_name; |
381 | const char *dev_name; | 383 | const char *dev_name; |
382 | int major; | 384 | int major; |
383 | int minor; | 385 | int minor; |
384 | int nr; | 386 | int nr; |
385 | struct console *cons; | 387 | struct console *cons; |
386 | 388 | ||
387 | /* | 389 | /* |
388 | * these are private; the low level driver should not | 390 | * these are private; the low level driver should not |
389 | * touch these; they should be initialised to NULL | 391 | * touch these; they should be initialised to NULL |
390 | */ | 392 | */ |
391 | struct uart_state *state; | 393 | struct uart_state *state; |
392 | struct tty_driver *tty_driver; | 394 | struct tty_driver *tty_driver; |
393 | }; | 395 | }; |
394 | 396 | ||
395 | void uart_write_wakeup(struct uart_port *port); | 397 | void uart_write_wakeup(struct uart_port *port); |
396 | 398 | ||
397 | /* | 399 | /* |
398 | * Baud rate helpers. | 400 | * Baud rate helpers. |
399 | */ | 401 | */ |
400 | void uart_update_timeout(struct uart_port *port, unsigned int cflag, | 402 | void uart_update_timeout(struct uart_port *port, unsigned int cflag, |
401 | unsigned int baud); | 403 | unsigned int baud); |
402 | unsigned int uart_get_baud_rate(struct uart_port *port, struct ktermios *termios, | 404 | unsigned int uart_get_baud_rate(struct uart_port *port, struct ktermios *termios, |
403 | struct ktermios *old, unsigned int min, | 405 | struct ktermios *old, unsigned int min, |
404 | unsigned int max); | 406 | unsigned int max); |
405 | unsigned int uart_get_divisor(struct uart_port *port, unsigned int baud); | 407 | unsigned int uart_get_divisor(struct uart_port *port, unsigned int baud); |
406 | 408 | ||
407 | /* | 409 | /* |
408 | * Console helpers. | 410 | * Console helpers. |
409 | */ | 411 | */ |
410 | struct uart_port *uart_get_console(struct uart_port *ports, int nr, | 412 | struct uart_port *uart_get_console(struct uart_port *ports, int nr, |
411 | struct console *c); | 413 | struct console *c); |
412 | void uart_parse_options(char *options, int *baud, int *parity, int *bits, | 414 | void uart_parse_options(char *options, int *baud, int *parity, int *bits, |
413 | int *flow); | 415 | int *flow); |
414 | int uart_set_options(struct uart_port *port, struct console *co, int baud, | 416 | int uart_set_options(struct uart_port *port, struct console *co, int baud, |
415 | int parity, int bits, int flow); | 417 | int parity, int bits, int flow); |
416 | struct tty_driver *uart_console_device(struct console *co, int *index); | 418 | struct tty_driver *uart_console_device(struct console *co, int *index); |
417 | void uart_console_write(struct uart_port *port, const char *s, | 419 | void uart_console_write(struct uart_port *port, const char *s, |
418 | unsigned int count, | 420 | unsigned int count, |
419 | void (*putchar)(struct uart_port *, int)); | 421 | void (*putchar)(struct uart_port *, int)); |
420 | 422 | ||
421 | /* | 423 | /* |
422 | * Port/driver registration/removal | 424 | * Port/driver registration/removal |
423 | */ | 425 | */ |
424 | int uart_register_driver(struct uart_driver *uart); | 426 | int uart_register_driver(struct uart_driver *uart); |
425 | void uart_unregister_driver(struct uart_driver *uart); | 427 | void uart_unregister_driver(struct uart_driver *uart); |
426 | int uart_add_one_port(struct uart_driver *reg, struct uart_port *port); | 428 | int uart_add_one_port(struct uart_driver *reg, struct uart_port *port); |
427 | int uart_remove_one_port(struct uart_driver *reg, struct uart_port *port); | 429 | int uart_remove_one_port(struct uart_driver *reg, struct uart_port *port); |
428 | int uart_match_port(struct uart_port *port1, struct uart_port *port2); | 430 | int uart_match_port(struct uart_port *port1, struct uart_port *port2); |
429 | 431 | ||
430 | /* | 432 | /* |
431 | * Power Management | 433 | * Power Management |
432 | */ | 434 | */ |
433 | int uart_suspend_port(struct uart_driver *reg, struct uart_port *port); | 435 | int uart_suspend_port(struct uart_driver *reg, struct uart_port *port); |
434 | int uart_resume_port(struct uart_driver *reg, struct uart_port *port); | 436 | int uart_resume_port(struct uart_driver *reg, struct uart_port *port); |
435 | 437 | ||
436 | #define uart_circ_empty(circ) ((circ)->head == (circ)->tail) | 438 | #define uart_circ_empty(circ) ((circ)->head == (circ)->tail) |
437 | #define uart_circ_clear(circ) ((circ)->head = (circ)->tail = 0) | 439 | #define uart_circ_clear(circ) ((circ)->head = (circ)->tail = 0) |
438 | 440 | ||
439 | #define uart_circ_chars_pending(circ) \ | 441 | #define uart_circ_chars_pending(circ) \ |
440 | (CIRC_CNT((circ)->head, (circ)->tail, UART_XMIT_SIZE)) | 442 | (CIRC_CNT((circ)->head, (circ)->tail, UART_XMIT_SIZE)) |
441 | 443 | ||
442 | #define uart_circ_chars_free(circ) \ | 444 | #define uart_circ_chars_free(circ) \ |
443 | (CIRC_SPACE((circ)->head, (circ)->tail, UART_XMIT_SIZE)) | 445 | (CIRC_SPACE((circ)->head, (circ)->tail, UART_XMIT_SIZE)) |
444 | 446 | ||
445 | static inline int uart_tx_stopped(struct uart_port *port) | 447 | static inline int uart_tx_stopped(struct uart_port *port) |
446 | { | 448 | { |
447 | struct tty_struct *tty = port->info->port.tty; | 449 | struct tty_struct *tty = port->info->port.tty; |
448 | if(tty->stopped || tty->hw_stopped) | 450 | if(tty->stopped || tty->hw_stopped) |
449 | return 1; | 451 | return 1; |
450 | return 0; | 452 | return 0; |
451 | } | 453 | } |
452 | 454 | ||
453 | /* | 455 | /* |
454 | * The following are helper functions for the low level drivers. | 456 | * The following are helper functions for the low level drivers. |
455 | */ | 457 | */ |
456 | static inline int | 458 | static inline int |
457 | uart_handle_sysrq_char(struct uart_port *port, unsigned int ch) | 459 | uart_handle_sysrq_char(struct uart_port *port, unsigned int ch) |
458 | { | 460 | { |
459 | #ifdef SUPPORT_SYSRQ | 461 | #ifdef SUPPORT_SYSRQ |
460 | if (port->sysrq) { | 462 | if (port->sysrq) { |
461 | if (ch && time_before(jiffies, port->sysrq)) { | 463 | if (ch && time_before(jiffies, port->sysrq)) { |
462 | handle_sysrq(ch, port->info->port.tty); | 464 | handle_sysrq(ch, port->info->port.tty); |
463 | port->sysrq = 0; | 465 | port->sysrq = 0; |
464 | return 1; | 466 | return 1; |
465 | } | 467 | } |
466 | port->sysrq = 0; | 468 | port->sysrq = 0; |
467 | } | 469 | } |
468 | #endif | 470 | #endif |
469 | return 0; | 471 | return 0; |
470 | } | 472 | } |
471 | #ifndef SUPPORT_SYSRQ | 473 | #ifndef SUPPORT_SYSRQ |
472 | #define uart_handle_sysrq_char(port,ch) uart_handle_sysrq_char(port, 0) | 474 | #define uart_handle_sysrq_char(port,ch) uart_handle_sysrq_char(port, 0) |
473 | #endif | 475 | #endif |
474 | 476 | ||
475 | /* | 477 | /* |
476 | * We do the SysRQ and SAK checking like this... | 478 | * We do the SysRQ and SAK checking like this... |
477 | */ | 479 | */ |
478 | static inline int uart_handle_break(struct uart_port *port) | 480 | static inline int uart_handle_break(struct uart_port *port) |
479 | { | 481 | { |
480 | struct uart_info *info = port->info; | 482 | struct uart_info *info = port->info; |
481 | #ifdef SUPPORT_SYSRQ | 483 | #ifdef SUPPORT_SYSRQ |
482 | if (port->cons && port->cons->index == port->line) { | 484 | if (port->cons && port->cons->index == port->line) { |
483 | if (!port->sysrq) { | 485 | if (!port->sysrq) { |
484 | port->sysrq = jiffies + HZ*5; | 486 | port->sysrq = jiffies + HZ*5; |
485 | return 1; | 487 | return 1; |
486 | } | 488 | } |
487 | port->sysrq = 0; | 489 | port->sysrq = 0; |
488 | } | 490 | } |
489 | #endif | 491 | #endif |
490 | if (port->flags & UPF_SAK) | 492 | if (port->flags & UPF_SAK) |
491 | do_SAK(info->port.tty); | 493 | do_SAK(info->port.tty); |
492 | return 0; | 494 | return 0; |
493 | } | 495 | } |
494 | 496 | ||
495 | /** | 497 | /** |
496 | * uart_handle_dcd_change - handle a change of carrier detect state | 498 | * uart_handle_dcd_change - handle a change of carrier detect state |
497 | * @port: uart_port structure for the open port | 499 | * @port: uart_port structure for the open port |
498 | * @status: new carrier detect status, nonzero if active | 500 | * @status: new carrier detect status, nonzero if active |
499 | */ | 501 | */ |
500 | static inline void | 502 | static inline void |
501 | uart_handle_dcd_change(struct uart_port *port, unsigned int status) | 503 | uart_handle_dcd_change(struct uart_port *port, unsigned int status) |
502 | { | 504 | { |
503 | struct uart_info *info = port->info; | 505 | struct uart_info *info = port->info; |
504 | 506 | ||
505 | port->icount.dcd++; | 507 | port->icount.dcd++; |
506 | 508 | ||
507 | #ifdef CONFIG_HARD_PPS | 509 | #ifdef CONFIG_HARD_PPS |
508 | if ((port->flags & UPF_HARDPPS_CD) && status) | 510 | if ((port->flags & UPF_HARDPPS_CD) && status) |
509 | hardpps(); | 511 | hardpps(); |
510 | #endif | 512 | #endif |
511 | 513 | ||
512 | if (info->flags & UIF_CHECK_CD) { | 514 | if (info->flags & UIF_CHECK_CD) { |
513 | if (status) | 515 | if (status) |
514 | wake_up_interruptible(&info->port.open_wait); | 516 | wake_up_interruptible(&info->port.open_wait); |
515 | else if (info->port.tty) | 517 | else if (info->port.tty) |
516 | tty_hangup(info->port.tty); | 518 | tty_hangup(info->port.tty); |
517 | } | 519 | } |
518 | } | 520 | } |
519 | 521 | ||
520 | /** | 522 | /** |
521 | * uart_handle_cts_change - handle a change of clear-to-send state | 523 | * uart_handle_cts_change - handle a change of clear-to-send state |
522 | * @port: uart_port structure for the open port | 524 | * @port: uart_port structure for the open port |
523 | * @status: new clear to send status, nonzero if active | 525 | * @status: new clear to send status, nonzero if active |
524 | */ | 526 | */ |
525 | static inline void | 527 | static inline void |
526 | uart_handle_cts_change(struct uart_port *port, unsigned int status) | 528 | uart_handle_cts_change(struct uart_port *port, unsigned int status) |
527 | { | 529 | { |
528 | struct uart_info *info = port->info; | 530 | struct uart_info *info = port->info; |
529 | struct tty_struct *tty = info->port.tty; | 531 | struct tty_struct *tty = info->port.tty; |
530 | 532 | ||
531 | port->icount.cts++; | 533 | port->icount.cts++; |
532 | 534 | ||
533 | if (info->flags & UIF_CTS_FLOW) { | 535 | if (info->flags & UIF_CTS_FLOW) { |
534 | if (tty->hw_stopped) { | 536 | if (tty->hw_stopped) { |
535 | if (status) { | 537 | if (status) { |
536 | tty->hw_stopped = 0; | 538 | tty->hw_stopped = 0; |
537 | port->ops->start_tx(port); | 539 | port->ops->start_tx(port); |
538 | uart_write_wakeup(port); | 540 | uart_write_wakeup(port); |
539 | } | 541 | } |
540 | } else { | 542 | } else { |
541 | if (!status) { | 543 | if (!status) { |
542 | tty->hw_stopped = 1; | 544 | tty->hw_stopped = 1; |
543 | port->ops->stop_tx(port); | 545 | port->ops->stop_tx(port); |
544 | } | 546 | } |
545 | } | 547 | } |
546 | } | 548 | } |
547 | } | 549 | } |
548 | 550 | ||
549 | #include <linux/tty_flip.h> | 551 | #include <linux/tty_flip.h> |
550 | 552 | ||
551 | static inline void | 553 | static inline void |
552 | uart_insert_char(struct uart_port *port, unsigned int status, | 554 | uart_insert_char(struct uart_port *port, unsigned int status, |
553 | unsigned int overrun, unsigned int ch, unsigned int flag) | 555 | unsigned int overrun, unsigned int ch, unsigned int flag) |
554 | { | 556 | { |
555 | struct tty_struct *tty = port->info->port.tty; | 557 | struct tty_struct *tty = port->info->port.tty; |
556 | 558 | ||
557 | if ((status & port->ignore_status_mask & ~overrun) == 0) | 559 | if ((status & port->ignore_status_mask & ~overrun) == 0) |
558 | tty_insert_flip_char(tty, ch, flag); | 560 | tty_insert_flip_char(tty, ch, flag); |
559 | 561 | ||
560 | /* | 562 | /* |
561 | * Overrun is special. Since it's reported immediately, | 563 | * Overrun is special. Since it's reported immediately, |
562 | * it doesn't affect the current character. | 564 | * it doesn't affect the current character. |
563 | */ | 565 | */ |
564 | if (status & ~port->ignore_status_mask & overrun) | 566 | if (status & ~port->ignore_status_mask & overrun) |
565 | tty_insert_flip_char(tty, 0, TTY_OVERRUN); | 567 | tty_insert_flip_char(tty, 0, TTY_OVERRUN); |
566 | } | 568 | } |
567 | 569 | ||
568 | /* | 570 | /* |
569 | * UART_ENABLE_MS - determine if port should enable modem status irqs | 571 | * UART_ENABLE_MS - determine if port should enable modem status irqs |
570 | */ | 572 | */ |
571 | #define UART_ENABLE_MS(port,cflag) ((port)->flags & UPF_HARDPPS_CD || \ | 573 | #define UART_ENABLE_MS(port,cflag) ((port)->flags & UPF_HARDPPS_CD || \ |
572 | (cflag) & CRTSCTS || \ | 574 | (cflag) & CRTSCTS || \ |
573 | !((cflag) & CLOCAL)) | 575 | !((cflag) & CLOCAL)) |
574 | 576 | ||
575 | #endif | 577 | #endif |
576 | 578 | ||
577 | #endif /* LINUX_SERIAL_CORE_H */ | 579 | #endif /* LINUX_SERIAL_CORE_H */ |
578 | 580 |