Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/char/8250.c |
| 3 | * |
| 4 | * Driver for 8250/16550-type serial ports |
| 5 | * |
| 6 | * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o. |
| 7 | * |
| 8 | * Copyright (C) 2001 Russell King. |
| 9 | * |
| 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 |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * A note about mapbase / membase |
| 16 | * |
| 17 | * mapbase is the physical address of the IO port. |
| 18 | * membase is an 'ioremapped' cookie. |
| 19 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | #if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
| 22 | #define SUPPORT_SYSRQ |
| 23 | #endif |
| 24 | |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/moduleparam.h> |
| 27 | #include <linux/ioport.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/console.h> |
| 30 | #include <linux/sysrq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/delay.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/tty.h> |
Daniel Drake | cd3ecad | 2010-10-20 16:00:48 -0700 | [diff] [blame] | 34 | #include <linux/ratelimit.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/tty_flip.h> |
| 36 | #include <linux/serial_reg.h> |
| 37 | #include <linux/serial_core.h> |
| 38 | #include <linux/serial.h> |
| 39 | #include <linux/serial_8250.h> |
Andrew Morton | 78512ec | 2005-11-07 00:59:13 -0800 | [diff] [blame] | 40 | #include <linux/nmi.h> |
Arjan van de Ven | f392ecf | 2006-01-12 18:44:32 +0000 | [diff] [blame] | 41 | #include <linux/mutex.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | #include <asm/io.h> |
| 45 | #include <asm/irq.h> |
| 46 | |
| 47 | #include "8250.h" |
| 48 | |
David Miller | b70ac77 | 2008-10-13 10:36:31 +0100 | [diff] [blame] | 49 | #ifdef CONFIG_SPARC |
| 50 | #include "suncore.h" |
| 51 | #endif |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /* |
| 54 | * Configuration: |
Thomas Gleixner | 40663cc | 2006-07-01 19:29:43 -0700 | [diff] [blame] | 55 | * share_irqs - whether we pass IRQF_SHARED to request_irq(). This option |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | * is unsafe when used on edge-triggered interrupts. |
| 57 | */ |
Adrian Bunk | 408b664 | 2005-05-01 08:59:29 -0700 | [diff] [blame] | 58 | static unsigned int share_irqs = SERIAL8250_SHARE_IRQS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Dave Jones | a61c2d7 | 2006-01-07 23:18:19 +0000 | [diff] [blame] | 60 | static unsigned int nr_uarts = CONFIG_SERIAL_8250_RUNTIME_UARTS; |
| 61 | |
David S. Miller | 8440838 | 2008-10-13 10:45:26 +0100 | [diff] [blame] | 62 | static struct uart_driver serial8250_reg; |
| 63 | |
| 64 | static int serial_index(struct uart_port *port) |
| 65 | { |
| 66 | return (serial8250_reg.minor - 64) + port->line; |
| 67 | } |
| 68 | |
Chuck Ebbert | d41a4b5 | 2009-10-01 15:44:26 -0700 | [diff] [blame] | 69 | static unsigned int skip_txen_test; /* force skip of txen test at init time */ |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | /* |
| 72 | * Debugging. |
| 73 | */ |
| 74 | #if 0 |
| 75 | #define DEBUG_AUTOCONF(fmt...) printk(fmt) |
| 76 | #else |
| 77 | #define DEBUG_AUTOCONF(fmt...) do { } while (0) |
| 78 | #endif |
| 79 | |
| 80 | #if 0 |
| 81 | #define DEBUG_INTR(fmt...) printk(fmt) |
| 82 | #else |
| 83 | #define DEBUG_INTR(fmt...) do { } while (0) |
| 84 | #endif |
| 85 | |
| 86 | #define PASS_LIMIT 256 |
| 87 | |
Dick Hollenbeck | bca4761 | 2009-12-09 12:31:34 -0800 | [diff] [blame] | 88 | #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) |
| 89 | |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* |
| 92 | * We default to IRQ0 for the "no irq" hack. Some |
| 93 | * machine types want others as well - they're free |
| 94 | * to redefine this in their header file. |
| 95 | */ |
| 96 | #define is_real_interrupt(irq) ((irq) != 0) |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | #ifdef CONFIG_SERIAL_8250_DETECT_IRQ |
| 99 | #define CONFIG_SERIAL_DETECT_IRQ 1 |
| 100 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | #ifdef CONFIG_SERIAL_8250_MANY_PORTS |
| 102 | #define CONFIG_SERIAL_MANY_PORTS 1 |
| 103 | #endif |
| 104 | |
| 105 | /* |
| 106 | * HUB6 is always on. This will be removed once the header |
| 107 | * files have been cleaned. |
| 108 | */ |
| 109 | #define CONFIG_HUB6 1 |
| 110 | |
Bryan Wu | a4ed1e4 | 2008-05-31 16:10:04 +0800 | [diff] [blame] | 111 | #include <asm/serial.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | /* |
| 113 | * SERIAL_PORT_DFNS tells us about built-in ports that have no |
| 114 | * standard enumeration mechanism. Platforms that can find all |
| 115 | * serial ports via mechanisms like ACPI or PCI need not supply it. |
| 116 | */ |
| 117 | #ifndef SERIAL_PORT_DFNS |
| 118 | #define SERIAL_PORT_DFNS |
| 119 | #endif |
| 120 | |
Arjan van de Ven | cb3592b | 2005-11-28 21:04:11 +0000 | [diff] [blame] | 121 | static const struct old_serial_port old_serial_port[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | SERIAL_PORT_DFNS /* defined in asm/serial.h */ |
| 123 | }; |
| 124 | |
Russell King | 026d02a | 2005-06-29 18:45:19 +0100 | [diff] [blame] | 125 | #define UART_NR CONFIG_SERIAL_8250_NR_UARTS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
| 127 | #ifdef CONFIG_SERIAL_8250_RSA |
| 128 | |
| 129 | #define PORT_RSA_MAX 4 |
| 130 | static unsigned long probe_rsa[PORT_RSA_MAX]; |
| 131 | static unsigned int probe_rsa_count; |
| 132 | #endif /* CONFIG_SERIAL_8250_RSA */ |
| 133 | |
| 134 | struct uart_8250_port { |
| 135 | struct uart_port port; |
| 136 | struct timer_list timer; /* "no irq" timer */ |
| 137 | struct list_head list; /* ports on this IRQ */ |
Russell King | 4ba5e35 | 2005-06-23 10:43:04 +0100 | [diff] [blame] | 138 | unsigned short capabilities; /* port capabilities */ |
| 139 | unsigned short bugs; /* port bugs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | unsigned int tx_loadsz; /* transmit fifo load size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | unsigned char acr; |
| 142 | unsigned char ier; |
| 143 | unsigned char lcr; |
| 144 | unsigned char mcr; |
| 145 | unsigned char mcr_mask; /* mask of user bits */ |
| 146 | unsigned char mcr_force; /* mask of forced bits */ |
Alan Cox | b8e7e40 | 2009-05-28 14:01:35 +0100 | [diff] [blame] | 147 | unsigned char cur_iotype; /* Running I/O type */ |
Corey Minyard | ad4c2aa | 2007-08-22 14:01:18 -0700 | [diff] [blame] | 148 | |
| 149 | /* |
| 150 | * Some bits in registers are cleared on a read, so they must |
| 151 | * be saved whenever the register is read but the bits will not |
| 152 | * be immediately processed. |
| 153 | */ |
| 154 | #define LSR_SAVE_FLAGS UART_LSR_BRK_ERROR_BITS |
| 155 | unsigned char lsr_saved_flags; |
| 156 | #define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA |
| 157 | unsigned char msr_saved_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | struct irq_info { |
Alan Cox | 25db8ad | 2008-08-19 20:49:40 -0700 | [diff] [blame] | 161 | struct hlist_node node; |
| 162 | int irq; |
| 163 | spinlock_t lock; /* Protects list not the hash */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | struct list_head *head; |
| 165 | }; |
| 166 | |
Alan Cox | 25db8ad | 2008-08-19 20:49:40 -0700 | [diff] [blame] | 167 | #define NR_IRQ_HASH 32 /* Can be adjusted later */ |
| 168 | static struct hlist_head irq_lists[NR_IRQ_HASH]; |
| 169 | static DEFINE_MUTEX(hash_mutex); /* Used to walk the hash */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | /* |
| 172 | * Here we define the default xmit fifo size used for each type of UART. |
| 173 | */ |
| 174 | static const struct serial8250_config uart_config[] = { |
| 175 | [PORT_UNKNOWN] = { |
| 176 | .name = "unknown", |
| 177 | .fifo_size = 1, |
| 178 | .tx_loadsz = 1, |
| 179 | }, |
| 180 | [PORT_8250] = { |
| 181 | .name = "8250", |
| 182 | .fifo_size = 1, |
| 183 | .tx_loadsz = 1, |
| 184 | }, |
| 185 | [PORT_16450] = { |
| 186 | .name = "16450", |
| 187 | .fifo_size = 1, |
| 188 | .tx_loadsz = 1, |
| 189 | }, |
| 190 | [PORT_16550] = { |
| 191 | .name = "16550", |
| 192 | .fifo_size = 1, |
| 193 | .tx_loadsz = 1, |
| 194 | }, |
| 195 | [PORT_16550A] = { |
| 196 | .name = "16550A", |
| 197 | .fifo_size = 16, |
| 198 | .tx_loadsz = 16, |
| 199 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
| 200 | .flags = UART_CAP_FIFO, |
| 201 | }, |
| 202 | [PORT_CIRRUS] = { |
| 203 | .name = "Cirrus", |
| 204 | .fifo_size = 1, |
| 205 | .tx_loadsz = 1, |
| 206 | }, |
| 207 | [PORT_16650] = { |
| 208 | .name = "ST16650", |
| 209 | .fifo_size = 1, |
| 210 | .tx_loadsz = 1, |
| 211 | .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, |
| 212 | }, |
| 213 | [PORT_16650V2] = { |
| 214 | .name = "ST16650V2", |
| 215 | .fifo_size = 32, |
| 216 | .tx_loadsz = 16, |
| 217 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 | |
| 218 | UART_FCR_T_TRIG_00, |
| 219 | .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, |
| 220 | }, |
| 221 | [PORT_16750] = { |
| 222 | .name = "TI16750", |
| 223 | .fifo_size = 64, |
| 224 | .tx_loadsz = 64, |
| 225 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 | |
| 226 | UART_FCR7_64BYTE, |
| 227 | .flags = UART_CAP_FIFO | UART_CAP_SLEEP | UART_CAP_AFE, |
| 228 | }, |
| 229 | [PORT_STARTECH] = { |
| 230 | .name = "Startech", |
| 231 | .fifo_size = 1, |
| 232 | .tx_loadsz = 1, |
| 233 | }, |
| 234 | [PORT_16C950] = { |
| 235 | .name = "16C950/954", |
| 236 | .fifo_size = 128, |
| 237 | .tx_loadsz = 128, |
| 238 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
Pavel Machek | d0694e2 | 2011-01-09 08:38:48 +0100 | [diff] [blame] | 239 | /* UART_CAP_EFR breaks billionon CF bluetooth card. */ |
| 240 | .flags = UART_CAP_FIFO | UART_CAP_SLEEP, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | }, |
| 242 | [PORT_16654] = { |
| 243 | .name = "ST16654", |
| 244 | .fifo_size = 64, |
| 245 | .tx_loadsz = 32, |
| 246 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 | |
| 247 | UART_FCR_T_TRIG_10, |
| 248 | .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, |
| 249 | }, |
| 250 | [PORT_16850] = { |
| 251 | .name = "XR16850", |
| 252 | .fifo_size = 128, |
| 253 | .tx_loadsz = 128, |
| 254 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
| 255 | .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP, |
| 256 | }, |
| 257 | [PORT_RSA] = { |
| 258 | .name = "RSA", |
| 259 | .fifo_size = 2048, |
| 260 | .tx_loadsz = 2048, |
| 261 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_11, |
| 262 | .flags = UART_CAP_FIFO, |
| 263 | }, |
| 264 | [PORT_NS16550A] = { |
| 265 | .name = "NS16550A", |
| 266 | .fifo_size = 16, |
| 267 | .tx_loadsz = 16, |
| 268 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
| 269 | .flags = UART_CAP_FIFO | UART_NATSEMI, |
| 270 | }, |
| 271 | [PORT_XSCALE] = { |
| 272 | .name = "XScale", |
| 273 | .fifo_size = 32, |
| 274 | .tx_loadsz = 32, |
| 275 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
| 276 | .flags = UART_CAP_FIFO | UART_CAP_UUE, |
| 277 | }, |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 278 | [PORT_RM9000] = { |
| 279 | .name = "RM9000", |
| 280 | .fifo_size = 16, |
| 281 | .tx_loadsz = 16, |
| 282 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
| 283 | .flags = UART_CAP_FIFO, |
| 284 | }, |
David Daney | 6b06f19 | 2009-01-02 13:50:00 +0000 | [diff] [blame] | 285 | [PORT_OCTEON] = { |
| 286 | .name = "OCTEON", |
| 287 | .fifo_size = 64, |
| 288 | .tx_loadsz = 64, |
| 289 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
| 290 | .flags = UART_CAP_FIFO, |
| 291 | }, |
Florian Fainelli | 08e0992 | 2009-06-11 13:21:24 +0100 | [diff] [blame] | 292 | [PORT_AR7] = { |
| 293 | .name = "AR7", |
| 294 | .fifo_size = 16, |
| 295 | .tx_loadsz = 16, |
| 296 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00, |
| 297 | .flags = UART_CAP_FIFO | UART_CAP_AFE, |
| 298 | }, |
Philippe Langlais | 235dae5 | 2010-07-29 17:13:57 +0200 | [diff] [blame] | 299 | [PORT_U6_16550A] = { |
| 300 | .name = "U6_16550A", |
| 301 | .fifo_size = 64, |
| 302 | .tx_loadsz = 64, |
| 303 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
| 304 | .flags = UART_CAP_FIFO | UART_CAP_AFE, |
| 305 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | }; |
| 307 | |
Manuel Lauss | 12bf3f2 | 2010-07-15 21:45:05 +0200 | [diff] [blame] | 308 | #if defined(CONFIG_MIPS_ALCHEMY) |
Pantelis Antoniou | 21c614a | 2005-11-06 09:07:03 +0000 | [diff] [blame] | 309 | |
| 310 | /* Au1x00 UART hardware has a weird register layout */ |
| 311 | static const u8 au_io_in_map[] = { |
| 312 | [UART_RX] = 0, |
| 313 | [UART_IER] = 2, |
| 314 | [UART_IIR] = 3, |
| 315 | [UART_LCR] = 5, |
| 316 | [UART_MCR] = 6, |
| 317 | [UART_LSR] = 7, |
| 318 | [UART_MSR] = 8, |
| 319 | }; |
| 320 | |
| 321 | static const u8 au_io_out_map[] = { |
| 322 | [UART_TX] = 1, |
| 323 | [UART_IER] = 2, |
| 324 | [UART_FCR] = 4, |
| 325 | [UART_LCR] = 5, |
| 326 | [UART_MCR] = 6, |
| 327 | }; |
| 328 | |
| 329 | /* sane hardware needs no mapping */ |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 330 | static inline int map_8250_in_reg(struct uart_port *p, int offset) |
Pantelis Antoniou | 21c614a | 2005-11-06 09:07:03 +0000 | [diff] [blame] | 331 | { |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 332 | if (p->iotype != UPIO_AU) |
Pantelis Antoniou | 21c614a | 2005-11-06 09:07:03 +0000 | [diff] [blame] | 333 | return offset; |
| 334 | return au_io_in_map[offset]; |
| 335 | } |
| 336 | |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 337 | static inline int map_8250_out_reg(struct uart_port *p, int offset) |
Pantelis Antoniou | 21c614a | 2005-11-06 09:07:03 +0000 | [diff] [blame] | 338 | { |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 339 | if (p->iotype != UPIO_AU) |
Pantelis Antoniou | 21c614a | 2005-11-06 09:07:03 +0000 | [diff] [blame] | 340 | return offset; |
| 341 | return au_io_out_map[offset]; |
| 342 | } |
| 343 | |
Alan Cox | 6f803cd | 2008-02-08 04:18:52 -0800 | [diff] [blame] | 344 | #elif defined(CONFIG_SERIAL_8250_RM9K) |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 345 | |
| 346 | static const u8 |
| 347 | regmap_in[8] = { |
| 348 | [UART_RX] = 0x00, |
| 349 | [UART_IER] = 0x0c, |
| 350 | [UART_IIR] = 0x14, |
| 351 | [UART_LCR] = 0x1c, |
| 352 | [UART_MCR] = 0x20, |
| 353 | [UART_LSR] = 0x24, |
| 354 | [UART_MSR] = 0x28, |
| 355 | [UART_SCR] = 0x2c |
| 356 | }, |
| 357 | regmap_out[8] = { |
| 358 | [UART_TX] = 0x04, |
| 359 | [UART_IER] = 0x0c, |
| 360 | [UART_FCR] = 0x18, |
| 361 | [UART_LCR] = 0x1c, |
| 362 | [UART_MCR] = 0x20, |
| 363 | [UART_LSR] = 0x24, |
| 364 | [UART_MSR] = 0x28, |
| 365 | [UART_SCR] = 0x2c |
| 366 | }; |
| 367 | |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 368 | static inline int map_8250_in_reg(struct uart_port *p, int offset) |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 369 | { |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 370 | if (p->iotype != UPIO_RM9000) |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 371 | return offset; |
| 372 | return regmap_in[offset]; |
| 373 | } |
| 374 | |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 375 | static inline int map_8250_out_reg(struct uart_port *p, int offset) |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 376 | { |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 377 | if (p->iotype != UPIO_RM9000) |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 378 | return offset; |
| 379 | return regmap_out[offset]; |
| 380 | } |
| 381 | |
Pantelis Antoniou | 21c614a | 2005-11-06 09:07:03 +0000 | [diff] [blame] | 382 | #else |
| 383 | |
| 384 | /* sane hardware needs no mapping */ |
| 385 | #define map_8250_in_reg(up, offset) (offset) |
| 386 | #define map_8250_out_reg(up, offset) (offset) |
| 387 | |
| 388 | #endif |
| 389 | |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 390 | static unsigned int hub6_serial_in(struct uart_port *p, int offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 392 | offset = map_8250_in_reg(p, offset) << p->regshift; |
| 393 | outb(p->hub6 - 1 + offset, p->iobase); |
| 394 | return inb(p->iobase + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
| 396 | |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 397 | static void hub6_serial_out(struct uart_port *p, int offset, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | { |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 399 | offset = map_8250_out_reg(p, offset) << p->regshift; |
| 400 | outb(p->hub6 - 1 + offset, p->iobase); |
| 401 | outb(value, p->iobase + 1); |
| 402 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 404 | static unsigned int mem_serial_in(struct uart_port *p, int offset) |
| 405 | { |
| 406 | offset = map_8250_in_reg(p, offset) << p->regshift; |
| 407 | return readb(p->membase + offset); |
| 408 | } |
| 409 | |
| 410 | static void mem_serial_out(struct uart_port *p, int offset, int value) |
| 411 | { |
| 412 | offset = map_8250_out_reg(p, offset) << p->regshift; |
| 413 | writeb(value, p->membase + offset); |
| 414 | } |
| 415 | |
| 416 | static void mem32_serial_out(struct uart_port *p, int offset, int value) |
| 417 | { |
| 418 | offset = map_8250_out_reg(p, offset) << p->regshift; |
| 419 | writel(value, p->membase + offset); |
| 420 | } |
| 421 | |
| 422 | static unsigned int mem32_serial_in(struct uart_port *p, int offset) |
| 423 | { |
| 424 | offset = map_8250_in_reg(p, offset) << p->regshift; |
| 425 | return readl(p->membase + offset); |
| 426 | } |
| 427 | |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 428 | static unsigned int au_serial_in(struct uart_port *p, int offset) |
| 429 | { |
| 430 | offset = map_8250_in_reg(p, offset) << p->regshift; |
| 431 | return __raw_readl(p->membase + offset); |
| 432 | } |
| 433 | |
| 434 | static void au_serial_out(struct uart_port *p, int offset, int value) |
| 435 | { |
| 436 | offset = map_8250_out_reg(p, offset) << p->regshift; |
| 437 | __raw_writel(value, p->membase + offset); |
| 438 | } |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 439 | |
| 440 | static unsigned int tsi_serial_in(struct uart_port *p, int offset) |
| 441 | { |
| 442 | unsigned int tmp; |
| 443 | offset = map_8250_in_reg(p, offset) << p->regshift; |
| 444 | if (offset == UART_IIR) { |
| 445 | tmp = readl(p->membase + (UART_IIR & ~3)); |
| 446 | return (tmp >> 16) & 0xff; /* UART_IIR % 4 == 2 */ |
| 447 | } else |
| 448 | return readb(p->membase + offset); |
| 449 | } |
| 450 | |
| 451 | static void tsi_serial_out(struct uart_port *p, int offset, int value) |
| 452 | { |
| 453 | offset = map_8250_out_reg(p, offset) << p->regshift; |
| 454 | if (!((offset == UART_IER) && (value & UART_IER_UUE))) |
| 455 | writeb(value, p->membase + offset); |
| 456 | } |
| 457 | |
Jamie Iles | a3ae0fc | 2010-12-01 23:39:36 +0000 | [diff] [blame] | 458 | /* Save the LCR value so it can be re-written when a Busy Detect IRQ occurs. */ |
| 459 | static inline void dwapb_save_out_value(struct uart_port *p, int offset, |
| 460 | int value) |
| 461 | { |
| 462 | struct uart_8250_port *up = |
| 463 | container_of(p, struct uart_8250_port, port); |
| 464 | |
| 465 | if (offset == UART_LCR) |
| 466 | up->lcr = value; |
| 467 | } |
| 468 | |
| 469 | /* Read the IER to ensure any interrupt is cleared before returning from ISR. */ |
| 470 | static inline void dwapb_check_clear_ier(struct uart_port *p, int offset) |
| 471 | { |
| 472 | if (offset == UART_TX || offset == UART_IER) |
| 473 | p->serial_in(p, UART_IER); |
| 474 | } |
| 475 | |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 476 | static void dwapb_serial_out(struct uart_port *p, int offset, int value) |
| 477 | { |
| 478 | int save_offset = offset; |
| 479 | offset = map_8250_out_reg(p, offset) << p->regshift; |
Jamie Iles | a3ae0fc | 2010-12-01 23:39:36 +0000 | [diff] [blame] | 480 | dwapb_save_out_value(p, save_offset, value); |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 481 | writeb(value, p->membase + offset); |
Jamie Iles | a3ae0fc | 2010-12-01 23:39:36 +0000 | [diff] [blame] | 482 | dwapb_check_clear_ier(p, save_offset); |
| 483 | } |
| 484 | |
| 485 | static void dwapb32_serial_out(struct uart_port *p, int offset, int value) |
| 486 | { |
| 487 | int save_offset = offset; |
| 488 | offset = map_8250_out_reg(p, offset) << p->regshift; |
| 489 | dwapb_save_out_value(p, save_offset, value); |
| 490 | writel(value, p->membase + offset); |
| 491 | dwapb_check_clear_ier(p, save_offset); |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | static unsigned int io_serial_in(struct uart_port *p, int offset) |
| 495 | { |
| 496 | offset = map_8250_in_reg(p, offset) << p->regshift; |
| 497 | return inb(p->iobase + offset); |
| 498 | } |
| 499 | |
| 500 | static void io_serial_out(struct uart_port *p, int offset, int value) |
| 501 | { |
| 502 | offset = map_8250_out_reg(p, offset) << p->regshift; |
| 503 | outb(value, p->iobase + offset); |
| 504 | } |
| 505 | |
| 506 | static void set_io_from_upio(struct uart_port *p) |
| 507 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 508 | struct uart_8250_port *up = |
| 509 | container_of(p, struct uart_8250_port, port); |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 510 | switch (p->iotype) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | case UPIO_HUB6: |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 512 | p->serial_in = hub6_serial_in; |
| 513 | p->serial_out = hub6_serial_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | break; |
| 515 | |
| 516 | case UPIO_MEM: |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 517 | p->serial_in = mem_serial_in; |
| 518 | p->serial_out = mem_serial_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | break; |
| 520 | |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 521 | case UPIO_RM9000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | case UPIO_MEM32: |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 523 | p->serial_in = mem32_serial_in; |
| 524 | p->serial_out = mem32_serial_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | break; |
| 526 | |
Pantelis Antoniou | 21c614a | 2005-11-06 09:07:03 +0000 | [diff] [blame] | 527 | case UPIO_AU: |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 528 | p->serial_in = au_serial_in; |
| 529 | p->serial_out = au_serial_out; |
Pantelis Antoniou | 21c614a | 2005-11-06 09:07:03 +0000 | [diff] [blame] | 530 | break; |
Manuel Lauss | 12bf3f2 | 2010-07-15 21:45:05 +0200 | [diff] [blame] | 531 | |
Zang Roy-r61911 | 3be91ec | 2006-06-30 02:29:58 -0700 | [diff] [blame] | 532 | case UPIO_TSI: |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 533 | p->serial_in = tsi_serial_in; |
| 534 | p->serial_out = tsi_serial_out; |
Zang Roy-r61911 | 3be91ec | 2006-06-30 02:29:58 -0700 | [diff] [blame] | 535 | break; |
Pantelis Antoniou | 21c614a | 2005-11-06 09:07:03 +0000 | [diff] [blame] | 536 | |
Marc St-Jean | beab697 | 2007-05-06 14:48:45 -0700 | [diff] [blame] | 537 | case UPIO_DWAPB: |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 538 | p->serial_in = mem_serial_in; |
| 539 | p->serial_out = dwapb_serial_out; |
Marc St-Jean | beab697 | 2007-05-06 14:48:45 -0700 | [diff] [blame] | 540 | break; |
| 541 | |
Jamie Iles | a3ae0fc | 2010-12-01 23:39:36 +0000 | [diff] [blame] | 542 | case UPIO_DWAPB32: |
| 543 | p->serial_in = mem32_serial_in; |
| 544 | p->serial_out = dwapb32_serial_out; |
| 545 | break; |
| 546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | default: |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 548 | p->serial_in = io_serial_in; |
| 549 | p->serial_out = io_serial_out; |
| 550 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | } |
Alan Cox | b8e7e40 | 2009-05-28 14:01:35 +0100 | [diff] [blame] | 552 | /* Remember loaded iotype */ |
| 553 | up->cur_iotype = p->iotype; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 556 | static void |
| 557 | serial_out_sync(struct uart_8250_port *up, int offset, int value) |
| 558 | { |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 559 | struct uart_port *p = &up->port; |
| 560 | switch (p->iotype) { |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 561 | case UPIO_MEM: |
| 562 | case UPIO_MEM32: |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 563 | case UPIO_AU: |
Marc St-Jean | beab697 | 2007-05-06 14:48:45 -0700 | [diff] [blame] | 564 | case UPIO_DWAPB: |
Jamie Iles | a3ae0fc | 2010-12-01 23:39:36 +0000 | [diff] [blame] | 565 | case UPIO_DWAPB32: |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 566 | p->serial_out(p, offset, value); |
| 567 | p->serial_in(p, UART_LCR); /* safe, no side-effects */ |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 568 | break; |
| 569 | default: |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 570 | p->serial_out(p, offset, value); |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 574 | #define serial_in(up, offset) \ |
| 575 | (up->port.serial_in(&(up)->port, (offset))) |
| 576 | #define serial_out(up, offset, value) \ |
| 577 | (up->port.serial_out(&(up)->port, (offset), (value))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | /* |
| 579 | * We used to support using pause I/O for certain machines. We |
| 580 | * haven't supported this for a while, but just in case it's badly |
| 581 | * needed for certain old 386 machines, I've left these #define's |
| 582 | * in.... |
| 583 | */ |
| 584 | #define serial_inp(up, offset) serial_in(up, offset) |
| 585 | #define serial_outp(up, offset, value) serial_out(up, offset, value) |
| 586 | |
Jon Anders Haugum | b32b19b | 2006-04-30 11:20:56 +0100 | [diff] [blame] | 587 | /* Uart divisor latch read */ |
| 588 | static inline int _serial_dl_read(struct uart_8250_port *up) |
| 589 | { |
| 590 | return serial_inp(up, UART_DLL) | serial_inp(up, UART_DLM) << 8; |
| 591 | } |
| 592 | |
| 593 | /* Uart divisor latch write */ |
| 594 | static inline void _serial_dl_write(struct uart_8250_port *up, int value) |
| 595 | { |
| 596 | serial_outp(up, UART_DLL, value & 0xff); |
| 597 | serial_outp(up, UART_DLM, value >> 8 & 0xff); |
| 598 | } |
| 599 | |
Manuel Lauss | 12bf3f2 | 2010-07-15 21:45:05 +0200 | [diff] [blame] | 600 | #if defined(CONFIG_MIPS_ALCHEMY) |
Jon Anders Haugum | b32b19b | 2006-04-30 11:20:56 +0100 | [diff] [blame] | 601 | /* Au1x00 haven't got a standard divisor latch */ |
| 602 | static int serial_dl_read(struct uart_8250_port *up) |
| 603 | { |
| 604 | if (up->port.iotype == UPIO_AU) |
| 605 | return __raw_readl(up->port.membase + 0x28); |
| 606 | else |
| 607 | return _serial_dl_read(up); |
| 608 | } |
| 609 | |
| 610 | static void serial_dl_write(struct uart_8250_port *up, int value) |
| 611 | { |
| 612 | if (up->port.iotype == UPIO_AU) |
| 613 | __raw_writel(value, up->port.membase + 0x28); |
| 614 | else |
| 615 | _serial_dl_write(up, value); |
| 616 | } |
Alan Cox | 6f803cd | 2008-02-08 04:18:52 -0800 | [diff] [blame] | 617 | #elif defined(CONFIG_SERIAL_8250_RM9K) |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 618 | static int serial_dl_read(struct uart_8250_port *up) |
| 619 | { |
| 620 | return (up->port.iotype == UPIO_RM9000) ? |
| 621 | (((__raw_readl(up->port.membase + 0x10) << 8) | |
| 622 | (__raw_readl(up->port.membase + 0x08) & 0xff)) & 0xffff) : |
| 623 | _serial_dl_read(up); |
| 624 | } |
| 625 | |
| 626 | static void serial_dl_write(struct uart_8250_port *up, int value) |
| 627 | { |
| 628 | if (up->port.iotype == UPIO_RM9000) { |
| 629 | __raw_writel(value, up->port.membase + 0x08); |
| 630 | __raw_writel(value >> 8, up->port.membase + 0x10); |
| 631 | } else { |
| 632 | _serial_dl_write(up, value); |
| 633 | } |
| 634 | } |
Jon Anders Haugum | b32b19b | 2006-04-30 11:20:56 +0100 | [diff] [blame] | 635 | #else |
| 636 | #define serial_dl_read(up) _serial_dl_read(up) |
| 637 | #define serial_dl_write(up, value) _serial_dl_write(up, value) |
| 638 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
| 640 | /* |
| 641 | * For the 16C950 |
| 642 | */ |
| 643 | static void serial_icr_write(struct uart_8250_port *up, int offset, int value) |
| 644 | { |
| 645 | serial_out(up, UART_SCR, offset); |
| 646 | serial_out(up, UART_ICR, value); |
| 647 | } |
| 648 | |
| 649 | static unsigned int serial_icr_read(struct uart_8250_port *up, int offset) |
| 650 | { |
| 651 | unsigned int value; |
| 652 | |
| 653 | serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD); |
| 654 | serial_out(up, UART_SCR, offset); |
| 655 | value = serial_in(up, UART_ICR); |
| 656 | serial_icr_write(up, UART_ACR, up->acr); |
| 657 | |
| 658 | return value; |
| 659 | } |
| 660 | |
| 661 | /* |
| 662 | * FIFO support. |
| 663 | */ |
Will Newton | b5d674a | 2008-10-13 10:36:21 +0100 | [diff] [blame] | 664 | static void serial8250_clear_fifos(struct uart_8250_port *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | { |
| 666 | if (p->capabilities & UART_CAP_FIFO) { |
| 667 | serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO); |
| 668 | serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO | |
| 669 | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); |
| 670 | serial_outp(p, UART_FCR, 0); |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | /* |
| 675 | * IER sleep support. UARTs which have EFRs need the "extended |
| 676 | * capability" bit enabled. Note that on XR16C850s, we need to |
| 677 | * reset LCR to write to IER. |
| 678 | */ |
Will Newton | b5d674a | 2008-10-13 10:36:21 +0100 | [diff] [blame] | 679 | static void serial8250_set_sleep(struct uart_8250_port *p, int sleep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | { |
| 681 | if (p->capabilities & UART_CAP_SLEEP) { |
| 682 | if (p->capabilities & UART_CAP_EFR) { |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 683 | serial_outp(p, UART_LCR, UART_LCR_CONF_MODE_B); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | serial_outp(p, UART_EFR, UART_EFR_ECB); |
| 685 | serial_outp(p, UART_LCR, 0); |
| 686 | } |
| 687 | serial_outp(p, UART_IER, sleep ? UART_IERX_SLEEP : 0); |
| 688 | if (p->capabilities & UART_CAP_EFR) { |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 689 | serial_outp(p, UART_LCR, UART_LCR_CONF_MODE_B); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | serial_outp(p, UART_EFR, 0); |
| 691 | serial_outp(p, UART_LCR, 0); |
| 692 | } |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | #ifdef CONFIG_SERIAL_8250_RSA |
| 697 | /* |
| 698 | * Attempts to turn on the RSA FIFO. Returns zero on failure. |
| 699 | * We set the port uart clock rate if we succeed. |
| 700 | */ |
| 701 | static int __enable_rsa(struct uart_8250_port *up) |
| 702 | { |
| 703 | unsigned char mode; |
| 704 | int result; |
| 705 | |
| 706 | mode = serial_inp(up, UART_RSA_MSR); |
| 707 | result = mode & UART_RSA_MSR_FIFO; |
| 708 | |
| 709 | if (!result) { |
| 710 | serial_outp(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO); |
| 711 | mode = serial_inp(up, UART_RSA_MSR); |
| 712 | result = mode & UART_RSA_MSR_FIFO; |
| 713 | } |
| 714 | |
| 715 | if (result) |
| 716 | up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16; |
| 717 | |
| 718 | return result; |
| 719 | } |
| 720 | |
| 721 | static void enable_rsa(struct uart_8250_port *up) |
| 722 | { |
| 723 | if (up->port.type == PORT_RSA) { |
| 724 | if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) { |
| 725 | spin_lock_irq(&up->port.lock); |
| 726 | __enable_rsa(up); |
| 727 | spin_unlock_irq(&up->port.lock); |
| 728 | } |
| 729 | if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) |
| 730 | serial_outp(up, UART_RSA_FRR, 0); |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | /* |
| 735 | * Attempts to turn off the RSA FIFO. Returns zero on failure. |
| 736 | * It is unknown why interrupts were disabled in here. However, |
| 737 | * the caller is expected to preserve this behaviour by grabbing |
| 738 | * the spinlock before calling this function. |
| 739 | */ |
| 740 | static void disable_rsa(struct uart_8250_port *up) |
| 741 | { |
| 742 | unsigned char mode; |
| 743 | int result; |
| 744 | |
| 745 | if (up->port.type == PORT_RSA && |
| 746 | up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) { |
| 747 | spin_lock_irq(&up->port.lock); |
| 748 | |
| 749 | mode = serial_inp(up, UART_RSA_MSR); |
| 750 | result = !(mode & UART_RSA_MSR_FIFO); |
| 751 | |
| 752 | if (!result) { |
| 753 | serial_outp(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO); |
| 754 | mode = serial_inp(up, UART_RSA_MSR); |
| 755 | result = !(mode & UART_RSA_MSR_FIFO); |
| 756 | } |
| 757 | |
| 758 | if (result) |
| 759 | up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16; |
| 760 | spin_unlock_irq(&up->port.lock); |
| 761 | } |
| 762 | } |
| 763 | #endif /* CONFIG_SERIAL_8250_RSA */ |
| 764 | |
| 765 | /* |
| 766 | * This is a quickie test to see how big the FIFO is. |
| 767 | * It doesn't work at all the time, more's the pity. |
| 768 | */ |
| 769 | static int size_fifo(struct uart_8250_port *up) |
| 770 | { |
Jon Anders Haugum | b32b19b | 2006-04-30 11:20:56 +0100 | [diff] [blame] | 771 | unsigned char old_fcr, old_mcr, old_lcr; |
| 772 | unsigned short old_dl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | int count; |
| 774 | |
| 775 | old_lcr = serial_inp(up, UART_LCR); |
| 776 | serial_outp(up, UART_LCR, 0); |
| 777 | old_fcr = serial_inp(up, UART_FCR); |
| 778 | old_mcr = serial_inp(up, UART_MCR); |
| 779 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | |
| 780 | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); |
| 781 | serial_outp(up, UART_MCR, UART_MCR_LOOP); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 782 | serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_A); |
Jon Anders Haugum | b32b19b | 2006-04-30 11:20:56 +0100 | [diff] [blame] | 783 | old_dl = serial_dl_read(up); |
| 784 | serial_dl_write(up, 0x0001); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | serial_outp(up, UART_LCR, 0x03); |
| 786 | for (count = 0; count < 256; count++) |
| 787 | serial_outp(up, UART_TX, count); |
| 788 | mdelay(20);/* FIXME - schedule_timeout */ |
| 789 | for (count = 0; (serial_inp(up, UART_LSR) & UART_LSR_DR) && |
| 790 | (count < 256); count++) |
| 791 | serial_inp(up, UART_RX); |
| 792 | serial_outp(up, UART_FCR, old_fcr); |
| 793 | serial_outp(up, UART_MCR, old_mcr); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 794 | serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_A); |
Jon Anders Haugum | b32b19b | 2006-04-30 11:20:56 +0100 | [diff] [blame] | 795 | serial_dl_write(up, old_dl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | serial_outp(up, UART_LCR, old_lcr); |
| 797 | |
| 798 | return count; |
| 799 | } |
| 800 | |
| 801 | /* |
| 802 | * Read UART ID using the divisor method - set DLL and DLM to zero |
| 803 | * and the revision will be in DLL and device type in DLM. We |
| 804 | * preserve the device state across this. |
| 805 | */ |
| 806 | static unsigned int autoconfig_read_divisor_id(struct uart_8250_port *p) |
| 807 | { |
| 808 | unsigned char old_dll, old_dlm, old_lcr; |
| 809 | unsigned int id; |
| 810 | |
| 811 | old_lcr = serial_inp(p, UART_LCR); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 812 | serial_outp(p, UART_LCR, UART_LCR_CONF_MODE_A); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | |
| 814 | old_dll = serial_inp(p, UART_DLL); |
| 815 | old_dlm = serial_inp(p, UART_DLM); |
| 816 | |
| 817 | serial_outp(p, UART_DLL, 0); |
| 818 | serial_outp(p, UART_DLM, 0); |
| 819 | |
| 820 | id = serial_inp(p, UART_DLL) | serial_inp(p, UART_DLM) << 8; |
| 821 | |
| 822 | serial_outp(p, UART_DLL, old_dll); |
| 823 | serial_outp(p, UART_DLM, old_dlm); |
| 824 | serial_outp(p, UART_LCR, old_lcr); |
| 825 | |
| 826 | return id; |
| 827 | } |
| 828 | |
| 829 | /* |
| 830 | * This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's. |
| 831 | * When this function is called we know it is at least a StarTech |
| 832 | * 16650 V2, but it might be one of several StarTech UARTs, or one of |
| 833 | * its clones. (We treat the broken original StarTech 16650 V1 as a |
| 834 | * 16550, and why not? Startech doesn't seem to even acknowledge its |
| 835 | * existence.) |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 836 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | * What evil have men's minds wrought... |
| 838 | */ |
| 839 | static void autoconfig_has_efr(struct uart_8250_port *up) |
| 840 | { |
| 841 | unsigned int id1, id2, id3, rev; |
| 842 | |
| 843 | /* |
| 844 | * Everything with an EFR has SLEEP |
| 845 | */ |
| 846 | up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP; |
| 847 | |
| 848 | /* |
| 849 | * First we check to see if it's an Oxford Semiconductor UART. |
| 850 | * |
| 851 | * If we have to do this here because some non-National |
| 852 | * Semiconductor clone chips lock up if you try writing to the |
| 853 | * LSR register (which serial_icr_read does) |
| 854 | */ |
| 855 | |
| 856 | /* |
| 857 | * Check for Oxford Semiconductor 16C950. |
| 858 | * |
| 859 | * EFR [4] must be set else this test fails. |
| 860 | * |
| 861 | * This shouldn't be necessary, but Mike Hudson (Exoray@isys.ca) |
| 862 | * claims that it's needed for 952 dual UART's (which are not |
| 863 | * recommended for new designs). |
| 864 | */ |
| 865 | up->acr = 0; |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 866 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | serial_out(up, UART_EFR, UART_EFR_ECB); |
| 868 | serial_out(up, UART_LCR, 0x00); |
| 869 | id1 = serial_icr_read(up, UART_ID1); |
| 870 | id2 = serial_icr_read(up, UART_ID2); |
| 871 | id3 = serial_icr_read(up, UART_ID3); |
| 872 | rev = serial_icr_read(up, UART_REV); |
| 873 | |
| 874 | DEBUG_AUTOCONF("950id=%02x:%02x:%02x:%02x ", id1, id2, id3, rev); |
| 875 | |
| 876 | if (id1 == 0x16 && id2 == 0xC9 && |
| 877 | (id3 == 0x50 || id3 == 0x52 || id3 == 0x54)) { |
| 878 | up->port.type = PORT_16C950; |
Russell King | 4ba5e35 | 2005-06-23 10:43:04 +0100 | [diff] [blame] | 879 | |
| 880 | /* |
| 881 | * Enable work around for the Oxford Semiconductor 952 rev B |
| 882 | * chip which causes it to seriously miscalculate baud rates |
| 883 | * when DLL is 0. |
| 884 | */ |
| 885 | if (id3 == 0x52 && rev == 0x01) |
| 886 | up->bugs |= UART_BUG_QUOT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | return; |
| 888 | } |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 889 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | /* |
| 891 | * We check for a XR16C850 by setting DLL and DLM to 0, and then |
| 892 | * reading back DLL and DLM. The chip type depends on the DLM |
| 893 | * value read back: |
| 894 | * 0x10 - XR16C850 and the DLL contains the chip revision. |
| 895 | * 0x12 - XR16C2850. |
| 896 | * 0x14 - XR16C854. |
| 897 | */ |
| 898 | id1 = autoconfig_read_divisor_id(up); |
| 899 | DEBUG_AUTOCONF("850id=%04x ", id1); |
| 900 | |
| 901 | id2 = id1 >> 8; |
| 902 | if (id2 == 0x10 || id2 == 0x12 || id2 == 0x14) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | up->port.type = PORT_16850; |
| 904 | return; |
| 905 | } |
| 906 | |
| 907 | /* |
| 908 | * It wasn't an XR16C850. |
| 909 | * |
| 910 | * We distinguish between the '654 and the '650 by counting |
| 911 | * how many bytes are in the FIFO. I'm using this for now, |
| 912 | * since that's the technique that was sent to me in the |
| 913 | * serial driver update, but I'm not convinced this works. |
| 914 | * I've had problems doing this in the past. -TYT |
| 915 | */ |
| 916 | if (size_fifo(up) == 64) |
| 917 | up->port.type = PORT_16654; |
| 918 | else |
| 919 | up->port.type = PORT_16650V2; |
| 920 | } |
| 921 | |
| 922 | /* |
| 923 | * We detected a chip without a FIFO. Only two fall into |
| 924 | * this category - the original 8250 and the 16450. The |
| 925 | * 16450 has a scratch register (accessible with LCR=0) |
| 926 | */ |
| 927 | static void autoconfig_8250(struct uart_8250_port *up) |
| 928 | { |
| 929 | unsigned char scratch, status1, status2; |
| 930 | |
| 931 | up->port.type = PORT_8250; |
| 932 | |
| 933 | scratch = serial_in(up, UART_SCR); |
| 934 | serial_outp(up, UART_SCR, 0xa5); |
| 935 | status1 = serial_in(up, UART_SCR); |
| 936 | serial_outp(up, UART_SCR, 0x5a); |
| 937 | status2 = serial_in(up, UART_SCR); |
| 938 | serial_outp(up, UART_SCR, scratch); |
| 939 | |
| 940 | if (status1 == 0xa5 && status2 == 0x5a) |
| 941 | up->port.type = PORT_16450; |
| 942 | } |
| 943 | |
| 944 | static int broken_efr(struct uart_8250_port *up) |
| 945 | { |
| 946 | /* |
| 947 | * Exar ST16C2550 "A2" devices incorrectly detect as |
| 948 | * having an EFR, and report an ID of 0x0201. See |
Justin P. Mattock | 631dd1a | 2010-10-18 11:03:14 +0200 | [diff] [blame] | 949 | * http://linux.derkeiler.com/Mailing-Lists/Kernel/2004-11/4812.html |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | */ |
| 951 | if (autoconfig_read_divisor_id(up) == 0x0201 && size_fifo(up) == 16) |
| 952 | return 1; |
| 953 | |
| 954 | return 0; |
| 955 | } |
| 956 | |
| 957 | /* |
| 958 | * We know that the chip has FIFOs. Does it have an EFR? The |
| 959 | * EFR is located in the same register position as the IIR and |
| 960 | * we know the top two bits of the IIR are currently set. The |
| 961 | * EFR should contain zero. Try to read the EFR. |
| 962 | */ |
| 963 | static void autoconfig_16550a(struct uart_8250_port *up) |
| 964 | { |
| 965 | unsigned char status1, status2; |
| 966 | unsigned int iersave; |
| 967 | |
| 968 | up->port.type = PORT_16550A; |
| 969 | up->capabilities |= UART_CAP_FIFO; |
| 970 | |
| 971 | /* |
| 972 | * Check for presence of the EFR when DLAB is set. |
| 973 | * Only ST16C650V1 UARTs pass this test. |
| 974 | */ |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 975 | serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_A); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | if (serial_in(up, UART_EFR) == 0) { |
| 977 | serial_outp(up, UART_EFR, 0xA8); |
| 978 | if (serial_in(up, UART_EFR) != 0) { |
| 979 | DEBUG_AUTOCONF("EFRv1 "); |
| 980 | up->port.type = PORT_16650; |
| 981 | up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP; |
| 982 | } else { |
| 983 | DEBUG_AUTOCONF("Motorola 8xxx DUART "); |
| 984 | } |
| 985 | serial_outp(up, UART_EFR, 0); |
| 986 | return; |
| 987 | } |
| 988 | |
| 989 | /* |
| 990 | * Maybe it requires 0xbf to be written to the LCR. |
| 991 | * (other ST16C650V2 UARTs, TI16C752A, etc) |
| 992 | */ |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 993 | serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | if (serial_in(up, UART_EFR) == 0 && !broken_efr(up)) { |
| 995 | DEBUG_AUTOCONF("EFRv2 "); |
| 996 | autoconfig_has_efr(up); |
| 997 | return; |
| 998 | } |
| 999 | |
| 1000 | /* |
| 1001 | * Check for a National Semiconductor SuperIO chip. |
| 1002 | * Attempt to switch to bank 2, read the value of the LOOP bit |
| 1003 | * from EXCR1. Switch back to bank 0, change it in MCR. Then |
| 1004 | * switch back to bank 2, read it from EXCR1 again and check |
| 1005 | * it's changed. If so, set baud_base in EXCR2 to 921600. -- dwmw2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | */ |
| 1007 | serial_outp(up, UART_LCR, 0); |
| 1008 | status1 = serial_in(up, UART_MCR); |
| 1009 | serial_outp(up, UART_LCR, 0xE0); |
| 1010 | status2 = serial_in(up, 0x02); /* EXCR1 */ |
| 1011 | |
| 1012 | if (!((status2 ^ status1) & UART_MCR_LOOP)) { |
| 1013 | serial_outp(up, UART_LCR, 0); |
| 1014 | serial_outp(up, UART_MCR, status1 ^ UART_MCR_LOOP); |
| 1015 | serial_outp(up, UART_LCR, 0xE0); |
| 1016 | status2 = serial_in(up, 0x02); /* EXCR1 */ |
| 1017 | serial_outp(up, UART_LCR, 0); |
| 1018 | serial_outp(up, UART_MCR, status1); |
| 1019 | |
| 1020 | if ((status2 ^ status1) & UART_MCR_LOOP) { |
David Woodhouse | 857dde2 | 2005-05-21 15:52:23 +0100 | [diff] [blame] | 1021 | unsigned short quot; |
| 1022 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | serial_outp(up, UART_LCR, 0xE0); |
David Woodhouse | 857dde2 | 2005-05-21 15:52:23 +0100 | [diff] [blame] | 1024 | |
Jon Anders Haugum | b32b19b | 2006-04-30 11:20:56 +0100 | [diff] [blame] | 1025 | quot = serial_dl_read(up); |
David Woodhouse | 857dde2 | 2005-05-21 15:52:23 +0100 | [diff] [blame] | 1026 | quot <<= 3; |
| 1027 | |
David Woodhouse | b5b82df | 2007-05-17 14:27:39 +0800 | [diff] [blame] | 1028 | status1 = serial_in(up, 0x04); /* EXCR2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | status1 &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */ |
| 1030 | status1 |= 0x10; /* 1.625 divisor for baud_base --> 921600 */ |
| 1031 | serial_outp(up, 0x04, status1); |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 1032 | |
Jon Anders Haugum | b32b19b | 2006-04-30 11:20:56 +0100 | [diff] [blame] | 1033 | serial_dl_write(up, quot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | |
David Woodhouse | 857dde2 | 2005-05-21 15:52:23 +0100 | [diff] [blame] | 1035 | serial_outp(up, UART_LCR, 0); |
| 1036 | |
| 1037 | up->port.uartclk = 921600*16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | up->port.type = PORT_NS16550A; |
| 1039 | up->capabilities |= UART_NATSEMI; |
| 1040 | return; |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | /* |
| 1045 | * No EFR. Try to detect a TI16750, which only sets bit 5 of |
| 1046 | * the IIR when 64 byte FIFO mode is enabled when DLAB is set. |
| 1047 | * Try setting it with and without DLAB set. Cheap clones |
| 1048 | * set bit 5 without DLAB set. |
| 1049 | */ |
| 1050 | serial_outp(up, UART_LCR, 0); |
| 1051 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); |
| 1052 | status1 = serial_in(up, UART_IIR) >> 5; |
| 1053 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 1054 | serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_A); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); |
| 1056 | status2 = serial_in(up, UART_IIR) >> 5; |
| 1057 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); |
| 1058 | serial_outp(up, UART_LCR, 0); |
| 1059 | |
| 1060 | DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1, status2); |
| 1061 | |
| 1062 | if (status1 == 6 && status2 == 7) { |
| 1063 | up->port.type = PORT_16750; |
| 1064 | up->capabilities |= UART_CAP_AFE | UART_CAP_SLEEP; |
| 1065 | return; |
| 1066 | } |
| 1067 | |
| 1068 | /* |
| 1069 | * Try writing and reading the UART_IER_UUE bit (b6). |
| 1070 | * If it works, this is probably one of the Xscale platform's |
| 1071 | * internal UARTs. |
| 1072 | * We're going to explicitly set the UUE bit to 0 before |
| 1073 | * trying to write and read a 1 just to make sure it's not |
| 1074 | * already a 1 and maybe locked there before we even start start. |
| 1075 | */ |
| 1076 | iersave = serial_in(up, UART_IER); |
| 1077 | serial_outp(up, UART_IER, iersave & ~UART_IER_UUE); |
| 1078 | if (!(serial_in(up, UART_IER) & UART_IER_UUE)) { |
| 1079 | /* |
| 1080 | * OK it's in a known zero state, try writing and reading |
| 1081 | * without disturbing the current state of the other bits. |
| 1082 | */ |
| 1083 | serial_outp(up, UART_IER, iersave | UART_IER_UUE); |
| 1084 | if (serial_in(up, UART_IER) & UART_IER_UUE) { |
| 1085 | /* |
| 1086 | * It's an Xscale. |
| 1087 | * We'll leave the UART_IER_UUE bit set to 1 (enabled). |
| 1088 | */ |
| 1089 | DEBUG_AUTOCONF("Xscale "); |
| 1090 | up->port.type = PORT_XSCALE; |
| 1091 | up->capabilities |= UART_CAP_UUE; |
| 1092 | return; |
| 1093 | } |
| 1094 | } else { |
| 1095 | /* |
| 1096 | * If we got here we couldn't force the IER_UUE bit to 0. |
| 1097 | * Log it and continue. |
| 1098 | */ |
| 1099 | DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 "); |
| 1100 | } |
| 1101 | serial_outp(up, UART_IER, iersave); |
Philippe Langlais | 235dae5 | 2010-07-29 17:13:57 +0200 | [diff] [blame] | 1102 | |
| 1103 | /* |
| 1104 | * We distinguish between 16550A and U6 16550A by counting |
| 1105 | * how many bytes are in the FIFO. |
| 1106 | */ |
| 1107 | if (up->port.type == PORT_16550A && size_fifo(up) == 64) { |
| 1108 | up->port.type = PORT_U6_16550A; |
| 1109 | up->capabilities |= UART_CAP_AFE; |
| 1110 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | /* |
| 1114 | * This routine is called by rs_init() to initialize a specific serial |
| 1115 | * port. It determines what type of UART chip this serial port is |
| 1116 | * using: 8250, 16450, 16550, 16550A. The important question is |
| 1117 | * whether or not this UART is a 16550A or not, since this will |
| 1118 | * determine whether or not we can use its FIFO features or not. |
| 1119 | */ |
| 1120 | static void autoconfig(struct uart_8250_port *up, unsigned int probeflags) |
| 1121 | { |
| 1122 | unsigned char status1, scratch, scratch2, scratch3; |
| 1123 | unsigned char save_lcr, save_mcr; |
| 1124 | unsigned long flags; |
| 1125 | |
| 1126 | if (!up->port.iobase && !up->port.mapbase && !up->port.membase) |
| 1127 | return; |
| 1128 | |
Lennert Buytenhek | 80647b9 | 2009-11-11 14:26:41 -0800 | [diff] [blame] | 1129 | DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04lx, 0x%p): ", |
David S. Miller | 8440838 | 2008-10-13 10:45:26 +0100 | [diff] [blame] | 1130 | serial_index(&up->port), up->port.iobase, up->port.membase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | |
| 1132 | /* |
| 1133 | * We really do need global IRQs disabled here - we're going to |
| 1134 | * be frobbing the chips IRQ enable register to see if it exists. |
| 1135 | */ |
| 1136 | spin_lock_irqsave(&up->port.lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | |
| 1138 | up->capabilities = 0; |
Russell King | 4ba5e35 | 2005-06-23 10:43:04 +0100 | [diff] [blame] | 1139 | up->bugs = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | |
| 1141 | if (!(up->port.flags & UPF_BUGGY_UART)) { |
| 1142 | /* |
| 1143 | * Do a simple existence test first; if we fail this, |
| 1144 | * there's no point trying anything else. |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 1145 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | * 0x80 is used as a nonsense port to prevent against |
| 1147 | * false positives due to ISA bus float. The |
| 1148 | * assumption is that 0x80 is a non-existent port; |
| 1149 | * which should be safe since include/asm/io.h also |
| 1150 | * makes this assumption. |
| 1151 | * |
| 1152 | * Note: this is safe as long as MCR bit 4 is clear |
| 1153 | * and the device is in "PC" mode. |
| 1154 | */ |
| 1155 | scratch = serial_inp(up, UART_IER); |
| 1156 | serial_outp(up, UART_IER, 0); |
| 1157 | #ifdef __i386__ |
| 1158 | outb(0xff, 0x080); |
| 1159 | #endif |
Thomas Hoehn | 4821200 | 2007-02-10 01:46:05 -0800 | [diff] [blame] | 1160 | /* |
| 1161 | * Mask out IER[7:4] bits for test as some UARTs (e.g. TL |
| 1162 | * 16C754B) allow only to modify them if an EFR bit is set. |
| 1163 | */ |
| 1164 | scratch2 = serial_inp(up, UART_IER) & 0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | serial_outp(up, UART_IER, 0x0F); |
| 1166 | #ifdef __i386__ |
| 1167 | outb(0, 0x080); |
| 1168 | #endif |
Thomas Hoehn | 4821200 | 2007-02-10 01:46:05 -0800 | [diff] [blame] | 1169 | scratch3 = serial_inp(up, UART_IER) & 0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | serial_outp(up, UART_IER, scratch); |
| 1171 | if (scratch2 != 0 || scratch3 != 0x0F) { |
| 1172 | /* |
| 1173 | * We failed; there's nothing here |
| 1174 | */ |
| 1175 | DEBUG_AUTOCONF("IER test failed (%02x, %02x) ", |
| 1176 | scratch2, scratch3); |
| 1177 | goto out; |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | save_mcr = serial_in(up, UART_MCR); |
| 1182 | save_lcr = serial_in(up, UART_LCR); |
| 1183 | |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 1184 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | * Check to see if a UART is really there. Certain broken |
| 1186 | * internal modems based on the Rockwell chipset fail this |
| 1187 | * test, because they apparently don't implement the loopback |
| 1188 | * test mode. So this test is skipped on the COM 1 through |
| 1189 | * COM 4 ports. This *should* be safe, since no board |
| 1190 | * manufacturer would be stupid enough to design a board |
| 1191 | * that conflicts with COM 1-4 --- we hope! |
| 1192 | */ |
| 1193 | if (!(up->port.flags & UPF_SKIP_TEST)) { |
| 1194 | serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A); |
| 1195 | status1 = serial_inp(up, UART_MSR) & 0xF0; |
| 1196 | serial_outp(up, UART_MCR, save_mcr); |
| 1197 | if (status1 != 0x90) { |
| 1198 | DEBUG_AUTOCONF("LOOP test failed (%02x) ", |
| 1199 | status1); |
| 1200 | goto out; |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | /* |
| 1205 | * We're pretty sure there's a port here. Lets find out what |
| 1206 | * type of port it is. The IIR top two bits allows us to find |
Russell King | 6f0d618 | 2005-09-09 16:17:58 +0100 | [diff] [blame] | 1207 | * out if it's 8250 or 16450, 16550, 16550A or later. This |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | * determines what we test for next. |
| 1209 | * |
| 1210 | * We also initialise the EFR (if any) to zero for later. The |
| 1211 | * EFR occupies the same register location as the FCR and IIR. |
| 1212 | */ |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 1213 | serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | serial_outp(up, UART_EFR, 0); |
| 1215 | serial_outp(up, UART_LCR, 0); |
| 1216 | |
| 1217 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); |
| 1218 | scratch = serial_in(up, UART_IIR) >> 6; |
| 1219 | |
| 1220 | DEBUG_AUTOCONF("iir=%d ", scratch); |
| 1221 | |
| 1222 | switch (scratch) { |
| 1223 | case 0: |
| 1224 | autoconfig_8250(up); |
| 1225 | break; |
| 1226 | case 1: |
| 1227 | up->port.type = PORT_UNKNOWN; |
| 1228 | break; |
| 1229 | case 2: |
| 1230 | up->port.type = PORT_16550; |
| 1231 | break; |
| 1232 | case 3: |
| 1233 | autoconfig_16550a(up); |
| 1234 | break; |
| 1235 | } |
| 1236 | |
| 1237 | #ifdef CONFIG_SERIAL_8250_RSA |
| 1238 | /* |
| 1239 | * Only probe for RSA ports if we got the region. |
| 1240 | */ |
| 1241 | if (up->port.type == PORT_16550A && probeflags & PROBE_RSA) { |
| 1242 | int i; |
| 1243 | |
| 1244 | for (i = 0 ; i < probe_rsa_count; ++i) { |
| 1245 | if (probe_rsa[i] == up->port.iobase && |
| 1246 | __enable_rsa(up)) { |
| 1247 | up->port.type = PORT_RSA; |
| 1248 | break; |
| 1249 | } |
| 1250 | } |
| 1251 | } |
| 1252 | #endif |
Pantelis Antoniou | 21c614a | 2005-11-06 09:07:03 +0000 | [diff] [blame] | 1253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | serial_outp(up, UART_LCR, save_lcr); |
| 1255 | |
| 1256 | if (up->capabilities != uart_config[up->port.type].flags) { |
| 1257 | printk(KERN_WARNING |
| 1258 | "ttyS%d: detected caps %08x should be %08x\n", |
David S. Miller | 8440838 | 2008-10-13 10:45:26 +0100 | [diff] [blame] | 1259 | serial_index(&up->port), up->capabilities, |
| 1260 | uart_config[up->port.type].flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | up->port.fifosize = uart_config[up->port.type].fifo_size; |
| 1264 | up->capabilities = uart_config[up->port.type].flags; |
| 1265 | up->tx_loadsz = uart_config[up->port.type].tx_loadsz; |
| 1266 | |
| 1267 | if (up->port.type == PORT_UNKNOWN) |
| 1268 | goto out; |
| 1269 | |
| 1270 | /* |
| 1271 | * Reset the UART. |
| 1272 | */ |
| 1273 | #ifdef CONFIG_SERIAL_8250_RSA |
| 1274 | if (up->port.type == PORT_RSA) |
| 1275 | serial_outp(up, UART_RSA_FRR, 0); |
| 1276 | #endif |
| 1277 | serial_outp(up, UART_MCR, save_mcr); |
| 1278 | serial8250_clear_fifos(up); |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 1279 | serial_in(up, UART_RX); |
Lennert Buytenhek | 5c8c755 | 2005-11-12 21:58:05 +0000 | [diff] [blame] | 1280 | if (up->capabilities & UART_CAP_UUE) |
| 1281 | serial_outp(up, UART_IER, UART_IER_UUE); |
| 1282 | else |
| 1283 | serial_outp(up, UART_IER, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 1285 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | spin_unlock_irqrestore(&up->port.lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | DEBUG_AUTOCONF("type=%s\n", uart_config[up->port.type].name); |
| 1288 | } |
| 1289 | |
| 1290 | static void autoconfig_irq(struct uart_8250_port *up) |
| 1291 | { |
| 1292 | unsigned char save_mcr, save_ier; |
| 1293 | unsigned char save_ICP = 0; |
| 1294 | unsigned int ICP = 0; |
| 1295 | unsigned long irqs; |
| 1296 | int irq; |
| 1297 | |
| 1298 | if (up->port.flags & UPF_FOURPORT) { |
| 1299 | ICP = (up->port.iobase & 0xfe0) | 0x1f; |
| 1300 | save_ICP = inb_p(ICP); |
| 1301 | outb_p(0x80, ICP); |
| 1302 | (void) inb_p(ICP); |
| 1303 | } |
| 1304 | |
| 1305 | /* forget possible initially masked and pending IRQ */ |
| 1306 | probe_irq_off(probe_irq_on()); |
| 1307 | save_mcr = serial_inp(up, UART_MCR); |
| 1308 | save_ier = serial_inp(up, UART_IER); |
| 1309 | serial_outp(up, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2); |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 1310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | irqs = probe_irq_on(); |
| 1312 | serial_outp(up, UART_MCR, 0); |
Alan Cox | 6f803cd | 2008-02-08 04:18:52 -0800 | [diff] [blame] | 1313 | udelay(10); |
| 1314 | if (up->port.flags & UPF_FOURPORT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | serial_outp(up, UART_MCR, |
| 1316 | UART_MCR_DTR | UART_MCR_RTS); |
| 1317 | } else { |
| 1318 | serial_outp(up, UART_MCR, |
| 1319 | UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2); |
| 1320 | } |
| 1321 | serial_outp(up, UART_IER, 0x0f); /* enable all intrs */ |
| 1322 | (void)serial_inp(up, UART_LSR); |
| 1323 | (void)serial_inp(up, UART_RX); |
| 1324 | (void)serial_inp(up, UART_IIR); |
| 1325 | (void)serial_inp(up, UART_MSR); |
| 1326 | serial_outp(up, UART_TX, 0xFF); |
Alan Cox | 6f803cd | 2008-02-08 04:18:52 -0800 | [diff] [blame] | 1327 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | irq = probe_irq_off(irqs); |
| 1329 | |
| 1330 | serial_outp(up, UART_MCR, save_mcr); |
| 1331 | serial_outp(up, UART_IER, save_ier); |
| 1332 | |
| 1333 | if (up->port.flags & UPF_FOURPORT) |
| 1334 | outb_p(save_ICP, ICP); |
| 1335 | |
| 1336 | up->port.irq = (irq > 0) ? irq : 0; |
| 1337 | } |
| 1338 | |
Russell King | e763b90 | 2005-06-29 18:41:51 +0100 | [diff] [blame] | 1339 | static inline void __stop_tx(struct uart_8250_port *p) |
| 1340 | { |
| 1341 | if (p->ier & UART_IER_THRI) { |
| 1342 | p->ier &= ~UART_IER_THRI; |
| 1343 | serial_out(p, UART_IER, p->ier); |
| 1344 | } |
| 1345 | } |
| 1346 | |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 1347 | static void serial8250_stop_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 1349 | struct uart_8250_port *up = |
| 1350 | container_of(port, struct uart_8250_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | |
Russell King | e763b90 | 2005-06-29 18:41:51 +0100 | [diff] [blame] | 1352 | __stop_tx(up); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | |
| 1354 | /* |
Russell King | e763b90 | 2005-06-29 18:41:51 +0100 | [diff] [blame] | 1355 | * We really want to stop the transmitter from sending. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | */ |
Russell King | e763b90 | 2005-06-29 18:41:51 +0100 | [diff] [blame] | 1357 | if (up->port.type == PORT_16C950) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | up->acr |= UART_ACR_TXDIS; |
| 1359 | serial_icr_write(up, UART_ACR, up->acr); |
| 1360 | } |
| 1361 | } |
| 1362 | |
Russell King | 55d3b28 | 2005-06-23 15:05:41 +0100 | [diff] [blame] | 1363 | static void transmit_chars(struct uart_8250_port *up); |
| 1364 | |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 1365 | static void serial8250_start_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 1367 | struct uart_8250_port *up = |
| 1368 | container_of(port, struct uart_8250_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | |
| 1370 | if (!(up->ier & UART_IER_THRI)) { |
| 1371 | up->ier |= UART_IER_THRI; |
| 1372 | serial_out(up, UART_IER, up->ier); |
Russell King | 55d3b28 | 2005-06-23 15:05:41 +0100 | [diff] [blame] | 1373 | |
Russell King | 67f7654 | 2005-06-23 22:26:43 +0100 | [diff] [blame] | 1374 | if (up->bugs & UART_BUG_TXEN) { |
Ian Jackson | 68cb4f8 | 2009-11-18 11:08:11 +0100 | [diff] [blame] | 1375 | unsigned char lsr; |
Russell King | 55d3b28 | 2005-06-23 15:05:41 +0100 | [diff] [blame] | 1376 | lsr = serial_in(up, UART_LSR); |
Corey Minyard | ad4c2aa | 2007-08-22 14:01:18 -0700 | [diff] [blame] | 1377 | up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; |
Thomas Koeller | bd71c18 | 2007-05-06 14:48:47 -0700 | [diff] [blame] | 1378 | if ((up->port.type == PORT_RM9000) ? |
Ian Jackson | 68cb4f8 | 2009-11-18 11:08:11 +0100 | [diff] [blame] | 1379 | (lsr & UART_LSR_THRE) : |
| 1380 | (lsr & UART_LSR_TEMT)) |
Russell King | 55d3b28 | 2005-06-23 15:05:41 +0100 | [diff] [blame] | 1381 | transmit_chars(up); |
| 1382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | } |
Russell King | e763b90 | 2005-06-29 18:41:51 +0100 | [diff] [blame] | 1384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | /* |
Russell King | e763b90 | 2005-06-29 18:41:51 +0100 | [diff] [blame] | 1386 | * Re-enable the transmitter if we disabled it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | */ |
Russell King | e763b90 | 2005-06-29 18:41:51 +0100 | [diff] [blame] | 1388 | if (up->port.type == PORT_16C950 && up->acr & UART_ACR_TXDIS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | up->acr &= ~UART_ACR_TXDIS; |
| 1390 | serial_icr_write(up, UART_ACR, up->acr); |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | static void serial8250_stop_rx(struct uart_port *port) |
| 1395 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 1396 | struct uart_8250_port *up = |
| 1397 | container_of(port, struct uart_8250_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | |
| 1399 | up->ier &= ~UART_IER_RLSI; |
| 1400 | up->port.read_status_mask &= ~UART_LSR_DR; |
| 1401 | serial_out(up, UART_IER, up->ier); |
| 1402 | } |
| 1403 | |
| 1404 | static void serial8250_enable_ms(struct uart_port *port) |
| 1405 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 1406 | struct uart_8250_port *up = |
| 1407 | container_of(port, struct uart_8250_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | |
Pantelis Antoniou | 21c614a | 2005-11-06 09:07:03 +0000 | [diff] [blame] | 1409 | /* no MSR capabilities */ |
| 1410 | if (up->bugs & UART_BUG_NOMSR) |
| 1411 | return; |
| 1412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | up->ier |= UART_IER_MSI; |
| 1414 | serial_out(up, UART_IER, up->ier); |
| 1415 | } |
| 1416 | |
Russell King | ea8874d | 2006-01-04 19:43:24 +0000 | [diff] [blame] | 1417 | static void |
Thomas Koeller | cc79aa9 | 2007-02-20 13:58:05 -0800 | [diff] [blame] | 1418 | receive_chars(struct uart_8250_port *up, unsigned int *status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | { |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 1420 | struct tty_struct *tty = up->port.state->port.tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | unsigned char ch, lsr = *status; |
| 1422 | int max_count = 256; |
| 1423 | char flag; |
| 1424 | |
| 1425 | do { |
Aristeu Rozanski | 7500b1f | 2008-07-23 21:29:45 -0700 | [diff] [blame] | 1426 | if (likely(lsr & UART_LSR_DR)) |
| 1427 | ch = serial_inp(up, UART_RX); |
| 1428 | else |
| 1429 | /* |
| 1430 | * Intel 82571 has a Serial Over Lan device that will |
| 1431 | * set UART_LSR_BI without setting UART_LSR_DR when |
| 1432 | * it receives a break. To avoid reading from the |
| 1433 | * receive buffer without UART_LSR_DR bit set, we |
| 1434 | * just force the read character to be 0 |
| 1435 | */ |
| 1436 | ch = 0; |
| 1437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | flag = TTY_NORMAL; |
| 1439 | up->port.icount.rx++; |
| 1440 | |
Corey Minyard | ad4c2aa | 2007-08-22 14:01:18 -0700 | [diff] [blame] | 1441 | lsr |= up->lsr_saved_flags; |
| 1442 | up->lsr_saved_flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | |
Corey Minyard | ad4c2aa | 2007-08-22 14:01:18 -0700 | [diff] [blame] | 1444 | if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | /* |
| 1446 | * For statistics only |
| 1447 | */ |
| 1448 | if (lsr & UART_LSR_BI) { |
| 1449 | lsr &= ~(UART_LSR_FE | UART_LSR_PE); |
| 1450 | up->port.icount.brk++; |
| 1451 | /* |
| 1452 | * We do the SysRQ and SAK checking |
| 1453 | * here because otherwise the break |
| 1454 | * may get masked by ignore_status_mask |
| 1455 | * or read_status_mask. |
| 1456 | */ |
| 1457 | if (uart_handle_break(&up->port)) |
| 1458 | goto ignore_char; |
| 1459 | } else if (lsr & UART_LSR_PE) |
| 1460 | up->port.icount.parity++; |
| 1461 | else if (lsr & UART_LSR_FE) |
| 1462 | up->port.icount.frame++; |
| 1463 | if (lsr & UART_LSR_OE) |
| 1464 | up->port.icount.overrun++; |
| 1465 | |
| 1466 | /* |
Russell King | 23907eb | 2005-04-16 15:26:39 -0700 | [diff] [blame] | 1467 | * Mask off conditions which should be ignored. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | */ |
| 1469 | lsr &= up->port.read_status_mask; |
| 1470 | |
| 1471 | if (lsr & UART_LSR_BI) { |
| 1472 | DEBUG_INTR("handling break...."); |
| 1473 | flag = TTY_BREAK; |
| 1474 | } else if (lsr & UART_LSR_PE) |
| 1475 | flag = TTY_PARITY; |
| 1476 | else if (lsr & UART_LSR_FE) |
| 1477 | flag = TTY_FRAME; |
| 1478 | } |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1479 | if (uart_handle_sysrq_char(&up->port, ch)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | goto ignore_char; |
Russell King | 05ab301 | 2005-05-09 23:21:59 +0100 | [diff] [blame] | 1481 | |
| 1482 | uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag); |
| 1483 | |
Alan Cox | 6f803cd | 2008-02-08 04:18:52 -0800 | [diff] [blame] | 1484 | ignore_char: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | lsr = serial_inp(up, UART_LSR); |
Aristeu Rozanski | 7500b1f | 2008-07-23 21:29:45 -0700 | [diff] [blame] | 1486 | } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | spin_unlock(&up->port.lock); |
| 1488 | tty_flip_buffer_push(tty); |
| 1489 | spin_lock(&up->port.lock); |
| 1490 | *status = lsr; |
| 1491 | } |
| 1492 | |
Russell King | ea8874d | 2006-01-04 19:43:24 +0000 | [diff] [blame] | 1493 | static void transmit_chars(struct uart_8250_port *up) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | { |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 1495 | struct circ_buf *xmit = &up->port.state->xmit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | int count; |
| 1497 | |
| 1498 | if (up->port.x_char) { |
| 1499 | serial_outp(up, UART_TX, up->port.x_char); |
| 1500 | up->port.icount.tx++; |
| 1501 | up->port.x_char = 0; |
| 1502 | return; |
| 1503 | } |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 1504 | if (uart_tx_stopped(&up->port)) { |
| 1505 | serial8250_stop_tx(&up->port); |
| 1506 | return; |
| 1507 | } |
| 1508 | if (uart_circ_empty(xmit)) { |
Russell King | e763b90 | 2005-06-29 18:41:51 +0100 | [diff] [blame] | 1509 | __stop_tx(up); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | return; |
| 1511 | } |
| 1512 | |
| 1513 | count = up->tx_loadsz; |
| 1514 | do { |
| 1515 | serial_out(up, UART_TX, xmit->buf[xmit->tail]); |
| 1516 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
| 1517 | up->port.icount.tx++; |
| 1518 | if (uart_circ_empty(xmit)) |
| 1519 | break; |
| 1520 | } while (--count > 0); |
| 1521 | |
| 1522 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 1523 | uart_write_wakeup(&up->port); |
| 1524 | |
| 1525 | DEBUG_INTR("THRE..."); |
| 1526 | |
| 1527 | if (uart_circ_empty(xmit)) |
Russell King | e763b90 | 2005-06-29 18:41:51 +0100 | [diff] [blame] | 1528 | __stop_tx(up); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
Russell King | 2af7cd6 | 2006-01-04 16:55:09 +0000 | [diff] [blame] | 1531 | static unsigned int check_modem_status(struct uart_8250_port *up) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | { |
Russell King | 2af7cd6 | 2006-01-04 16:55:09 +0000 | [diff] [blame] | 1533 | unsigned int status = serial_in(up, UART_MSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | |
Corey Minyard | ad4c2aa | 2007-08-22 14:01:18 -0700 | [diff] [blame] | 1535 | status |= up->msr_saved_flags; |
| 1536 | up->msr_saved_flags = 0; |
Taku Izumi | fdc30b3 | 2007-04-23 14:41:00 -0700 | [diff] [blame] | 1537 | if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI && |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 1538 | up->port.state != NULL) { |
Russell King | 2af7cd6 | 2006-01-04 16:55:09 +0000 | [diff] [blame] | 1539 | if (status & UART_MSR_TERI) |
| 1540 | up->port.icount.rng++; |
| 1541 | if (status & UART_MSR_DDSR) |
| 1542 | up->port.icount.dsr++; |
| 1543 | if (status & UART_MSR_DDCD) |
| 1544 | uart_handle_dcd_change(&up->port, status & UART_MSR_DCD); |
| 1545 | if (status & UART_MSR_DCTS) |
| 1546 | uart_handle_cts_change(&up->port, status & UART_MSR_CTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | |
Alan Cox | bdc04e3 | 2009-09-19 13:13:31 -0700 | [diff] [blame] | 1548 | wake_up_interruptible(&up->port.state->port.delta_msr_wait); |
Russell King | 2af7cd6 | 2006-01-04 16:55:09 +0000 | [diff] [blame] | 1549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | |
Russell King | 2af7cd6 | 2006-01-04 16:55:09 +0000 | [diff] [blame] | 1551 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | /* |
| 1555 | * This handles the interrupt from one port. |
| 1556 | */ |
Will Newton | b5d674a | 2008-10-13 10:36:21 +0100 | [diff] [blame] | 1557 | static void serial8250_handle_port(struct uart_8250_port *up) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | { |
Russell King | 45e2460 | 2006-01-04 19:19:06 +0000 | [diff] [blame] | 1559 | unsigned int status; |
Jiri Kosina | 4bf3631 | 2007-04-23 14:41:21 -0700 | [diff] [blame] | 1560 | unsigned long flags; |
Russell King | 45e2460 | 2006-01-04 19:19:06 +0000 | [diff] [blame] | 1561 | |
Jiri Kosina | 4bf3631 | 2007-04-23 14:41:21 -0700 | [diff] [blame] | 1562 | spin_lock_irqsave(&up->port.lock, flags); |
Russell King | 45e2460 | 2006-01-04 19:19:06 +0000 | [diff] [blame] | 1563 | |
| 1564 | status = serial_inp(up, UART_LSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | |
| 1566 | DEBUG_INTR("status = %x...", status); |
| 1567 | |
Aristeu Rozanski | 7500b1f | 2008-07-23 21:29:45 -0700 | [diff] [blame] | 1568 | if (status & (UART_LSR_DR | UART_LSR_BI)) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1569 | receive_chars(up, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | check_modem_status(up); |
| 1571 | if (status & UART_LSR_THRE) |
| 1572 | transmit_chars(up); |
Russell King | 45e2460 | 2006-01-04 19:19:06 +0000 | [diff] [blame] | 1573 | |
Jiri Kosina | 4bf3631 | 2007-04-23 14:41:21 -0700 | [diff] [blame] | 1574 | spin_unlock_irqrestore(&up->port.lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | /* |
| 1578 | * This is the serial driver's interrupt routine. |
| 1579 | * |
| 1580 | * Arjan thinks the old way was overly complex, so it got simplified. |
| 1581 | * Alan disagrees, saying that need the complexity to handle the weird |
| 1582 | * nature of ISA shared interrupts. (This is a special exception.) |
| 1583 | * |
| 1584 | * In order to handle ISA shared interrupts properly, we need to check |
| 1585 | * that all ports have been serviced, and therefore the ISA interrupt |
| 1586 | * line has been de-asserted. |
| 1587 | * |
| 1588 | * This means we need to loop through all ports. checking that they |
| 1589 | * don't have an interrupt pending. |
| 1590 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1591 | static irqreturn_t serial8250_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | { |
| 1593 | struct irq_info *i = dev_id; |
| 1594 | struct list_head *l, *end = NULL; |
| 1595 | int pass_counter = 0, handled = 0; |
| 1596 | |
| 1597 | DEBUG_INTR("serial8250_interrupt(%d)...", irq); |
| 1598 | |
| 1599 | spin_lock(&i->lock); |
| 1600 | |
| 1601 | l = i->head; |
| 1602 | do { |
| 1603 | struct uart_8250_port *up; |
| 1604 | unsigned int iir; |
| 1605 | |
| 1606 | up = list_entry(l, struct uart_8250_port, list); |
| 1607 | |
| 1608 | iir = serial_in(up, UART_IIR); |
| 1609 | if (!(iir & UART_IIR_NO_INT)) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1610 | serial8250_handle_port(up); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | |
| 1612 | handled = 1; |
| 1613 | |
| 1614 | end = NULL; |
Jamie Iles | a3ae0fc | 2010-12-01 23:39:36 +0000 | [diff] [blame] | 1615 | } else if ((up->port.iotype == UPIO_DWAPB || |
| 1616 | up->port.iotype == UPIO_DWAPB32) && |
Marc St-Jean | beab697 | 2007-05-06 14:48:45 -0700 | [diff] [blame] | 1617 | (iir & UART_IIR_BUSY) == UART_IIR_BUSY) { |
| 1618 | /* The DesignWare APB UART has an Busy Detect (0x07) |
| 1619 | * interrupt meaning an LCR write attempt occured while the |
| 1620 | * UART was busy. The interrupt must be cleared by reading |
| 1621 | * the UART status register (USR) and the LCR re-written. */ |
| 1622 | unsigned int status; |
| 1623 | status = *(volatile u32 *)up->port.private_data; |
| 1624 | serial_out(up, UART_LCR, up->lcr); |
| 1625 | |
| 1626 | handled = 1; |
| 1627 | |
| 1628 | end = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | } else if (end == NULL) |
| 1630 | end = l; |
| 1631 | |
| 1632 | l = l->next; |
| 1633 | |
| 1634 | if (l == i->head && pass_counter++ > PASS_LIMIT) { |
| 1635 | /* If we hit this, we're dead. */ |
Daniel Drake | cd3ecad | 2010-10-20 16:00:48 -0700 | [diff] [blame] | 1636 | printk_ratelimited(KERN_ERR |
| 1637 | "serial8250: too much work for irq%d\n", irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | break; |
| 1639 | } |
| 1640 | } while (l != end); |
| 1641 | |
| 1642 | spin_unlock(&i->lock); |
| 1643 | |
| 1644 | DEBUG_INTR("end.\n"); |
| 1645 | |
| 1646 | return IRQ_RETVAL(handled); |
| 1647 | } |
| 1648 | |
| 1649 | /* |
| 1650 | * To support ISA shared interrupts, we need to have one interrupt |
| 1651 | * handler that ensures that the IRQ line has been deasserted |
| 1652 | * before returning. Failing to do this will result in the IRQ |
| 1653 | * line being stuck active, and, since ISA irqs are edge triggered, |
| 1654 | * no more IRQs will be seen. |
| 1655 | */ |
| 1656 | static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up) |
| 1657 | { |
| 1658 | spin_lock_irq(&i->lock); |
| 1659 | |
| 1660 | if (!list_empty(i->head)) { |
| 1661 | if (i->head == &up->list) |
| 1662 | i->head = i->head->next; |
| 1663 | list_del(&up->list); |
| 1664 | } else { |
| 1665 | BUG_ON(i->head != &up->list); |
| 1666 | i->head = NULL; |
| 1667 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | spin_unlock_irq(&i->lock); |
Alan Cox | 25db8ad | 2008-08-19 20:49:40 -0700 | [diff] [blame] | 1669 | /* List empty so throw away the hash node */ |
| 1670 | if (i->head == NULL) { |
| 1671 | hlist_del(&i->node); |
| 1672 | kfree(i); |
| 1673 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | static int serial_link_irq_chain(struct uart_8250_port *up) |
| 1677 | { |
Alan Cox | 25db8ad | 2008-08-19 20:49:40 -0700 | [diff] [blame] | 1678 | struct hlist_head *h; |
| 1679 | struct hlist_node *n; |
| 1680 | struct irq_info *i; |
Thomas Gleixner | 40663cc | 2006-07-01 19:29:43 -0700 | [diff] [blame] | 1681 | int ret, irq_flags = up->port.flags & UPF_SHARE_IRQ ? IRQF_SHARED : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | |
Alan Cox | 25db8ad | 2008-08-19 20:49:40 -0700 | [diff] [blame] | 1683 | mutex_lock(&hash_mutex); |
| 1684 | |
| 1685 | h = &irq_lists[up->port.irq % NR_IRQ_HASH]; |
| 1686 | |
| 1687 | hlist_for_each(n, h) { |
| 1688 | i = hlist_entry(n, struct irq_info, node); |
| 1689 | if (i->irq == up->port.irq) |
| 1690 | break; |
| 1691 | } |
| 1692 | |
| 1693 | if (n == NULL) { |
| 1694 | i = kzalloc(sizeof(struct irq_info), GFP_KERNEL); |
| 1695 | if (i == NULL) { |
| 1696 | mutex_unlock(&hash_mutex); |
| 1697 | return -ENOMEM; |
| 1698 | } |
| 1699 | spin_lock_init(&i->lock); |
| 1700 | i->irq = up->port.irq; |
| 1701 | hlist_add_head(&i->node, h); |
| 1702 | } |
| 1703 | mutex_unlock(&hash_mutex); |
| 1704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | spin_lock_irq(&i->lock); |
| 1706 | |
| 1707 | if (i->head) { |
| 1708 | list_add(&up->list, i->head); |
| 1709 | spin_unlock_irq(&i->lock); |
| 1710 | |
| 1711 | ret = 0; |
| 1712 | } else { |
| 1713 | INIT_LIST_HEAD(&up->list); |
| 1714 | i->head = &up->list; |
| 1715 | spin_unlock_irq(&i->lock); |
Vikram Pandita | 1c2f049 | 2009-09-19 13:13:19 -0700 | [diff] [blame] | 1716 | irq_flags |= up->port.irqflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | ret = request_irq(up->port.irq, serial8250_interrupt, |
| 1718 | irq_flags, "serial", i); |
| 1719 | if (ret < 0) |
| 1720 | serial_do_unlink(i, up); |
| 1721 | } |
| 1722 | |
| 1723 | return ret; |
| 1724 | } |
| 1725 | |
| 1726 | static void serial_unlink_irq_chain(struct uart_8250_port *up) |
| 1727 | { |
Alan Cox | 25db8ad | 2008-08-19 20:49:40 -0700 | [diff] [blame] | 1728 | struct irq_info *i; |
| 1729 | struct hlist_node *n; |
| 1730 | struct hlist_head *h; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | |
Alan Cox | 25db8ad | 2008-08-19 20:49:40 -0700 | [diff] [blame] | 1732 | mutex_lock(&hash_mutex); |
| 1733 | |
| 1734 | h = &irq_lists[up->port.irq % NR_IRQ_HASH]; |
| 1735 | |
| 1736 | hlist_for_each(n, h) { |
| 1737 | i = hlist_entry(n, struct irq_info, node); |
| 1738 | if (i->irq == up->port.irq) |
| 1739 | break; |
| 1740 | } |
| 1741 | |
| 1742 | BUG_ON(n == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | BUG_ON(i->head == NULL); |
| 1744 | |
| 1745 | if (list_empty(i->head)) |
| 1746 | free_irq(up->port.irq, i); |
| 1747 | |
| 1748 | serial_do_unlink(i, up); |
Alan Cox | 25db8ad | 2008-08-19 20:49:40 -0700 | [diff] [blame] | 1749 | mutex_unlock(&hash_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | /* |
| 1753 | * This function is used to handle ports that do not have an |
| 1754 | * interrupt. This doesn't work very well for 16450's, but gives |
| 1755 | * barely passable results for a 16550A. (Although at the expense |
| 1756 | * of much CPU overhead). |
| 1757 | */ |
| 1758 | static void serial8250_timeout(unsigned long data) |
| 1759 | { |
| 1760 | struct uart_8250_port *up = (struct uart_8250_port *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | unsigned int iir; |
| 1762 | |
| 1763 | iir = serial_in(up, UART_IIR); |
Russell King | 45e2460 | 2006-01-04 19:19:06 +0000 | [diff] [blame] | 1764 | if (!(iir & UART_IIR_NO_INT)) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1765 | serial8250_handle_port(up); |
Anton Vorontsov | 5438106 | 2010-10-01 17:21:25 +0400 | [diff] [blame] | 1766 | mod_timer(&up->timer, jiffies + uart_poll_timeout(&up->port)); |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 1767 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 1769 | static void serial8250_backup_timeout(unsigned long data) |
| 1770 | { |
| 1771 | struct uart_8250_port *up = (struct uart_8250_port *)data; |
Corey Minyard | ad4c2aa | 2007-08-22 14:01:18 -0700 | [diff] [blame] | 1772 | unsigned int iir, ier = 0, lsr; |
| 1773 | unsigned long flags; |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 1774 | |
| 1775 | /* |
| 1776 | * Must disable interrupts or else we risk racing with the interrupt |
| 1777 | * based handler. |
| 1778 | */ |
| 1779 | if (is_real_interrupt(up->port.irq)) { |
| 1780 | ier = serial_in(up, UART_IER); |
| 1781 | serial_out(up, UART_IER, 0); |
| 1782 | } |
| 1783 | |
| 1784 | iir = serial_in(up, UART_IIR); |
| 1785 | |
| 1786 | /* |
| 1787 | * This should be a safe test for anyone who doesn't trust the |
| 1788 | * IIR bits on their UART, but it's specifically designed for |
| 1789 | * the "Diva" UART used on the management processor on many HP |
| 1790 | * ia64 and parisc boxes. |
| 1791 | */ |
Corey Minyard | ad4c2aa | 2007-08-22 14:01:18 -0700 | [diff] [blame] | 1792 | spin_lock_irqsave(&up->port.lock, flags); |
| 1793 | lsr = serial_in(up, UART_LSR); |
| 1794 | up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; |
| 1795 | spin_unlock_irqrestore(&up->port.lock, flags); |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 1796 | if ((iir & UART_IIR_NO_INT) && (up->ier & UART_IER_THRI) && |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 1797 | (!uart_circ_empty(&up->port.state->xmit) || up->port.x_char) && |
Corey Minyard | ad4c2aa | 2007-08-22 14:01:18 -0700 | [diff] [blame] | 1798 | (lsr & UART_LSR_THRE)) { |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 1799 | iir &= ~(UART_IIR_ID | UART_IIR_NO_INT); |
| 1800 | iir |= UART_IIR_THRI; |
| 1801 | } |
| 1802 | |
| 1803 | if (!(iir & UART_IIR_NO_INT)) |
| 1804 | serial8250_handle_port(up); |
| 1805 | |
| 1806 | if (is_real_interrupt(up->port.irq)) |
| 1807 | serial_out(up, UART_IER, ier); |
| 1808 | |
| 1809 | /* Standard timer interval plus 0.2s to keep the port running */ |
Alan Cox | 6f803cd | 2008-02-08 04:18:52 -0800 | [diff] [blame] | 1810 | mod_timer(&up->timer, |
Anton Vorontsov | 5438106 | 2010-10-01 17:21:25 +0400 | [diff] [blame] | 1811 | jiffies + uart_poll_timeout(&up->port) + HZ / 5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | static unsigned int serial8250_tx_empty(struct uart_port *port) |
| 1815 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 1816 | struct uart_8250_port *up = |
| 1817 | container_of(port, struct uart_8250_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | unsigned long flags; |
Corey Minyard | ad4c2aa | 2007-08-22 14:01:18 -0700 | [diff] [blame] | 1819 | unsigned int lsr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | |
| 1821 | spin_lock_irqsave(&up->port.lock, flags); |
Corey Minyard | ad4c2aa | 2007-08-22 14:01:18 -0700 | [diff] [blame] | 1822 | lsr = serial_in(up, UART_LSR); |
| 1823 | up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | spin_unlock_irqrestore(&up->port.lock, flags); |
| 1825 | |
Dick Hollenbeck | bca4761 | 2009-12-09 12:31:34 -0800 | [diff] [blame] | 1826 | return (lsr & BOTH_EMPTY) == BOTH_EMPTY ? TIOCSER_TEMT : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | static unsigned int serial8250_get_mctrl(struct uart_port *port) |
| 1830 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 1831 | struct uart_8250_port *up = |
| 1832 | container_of(port, struct uart_8250_port, port); |
Russell King | 2af7cd6 | 2006-01-04 16:55:09 +0000 | [diff] [blame] | 1833 | unsigned int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | unsigned int ret; |
| 1835 | |
Russell King | 2af7cd6 | 2006-01-04 16:55:09 +0000 | [diff] [blame] | 1836 | status = check_modem_status(up); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | |
| 1838 | ret = 0; |
| 1839 | if (status & UART_MSR_DCD) |
| 1840 | ret |= TIOCM_CAR; |
| 1841 | if (status & UART_MSR_RI) |
| 1842 | ret |= TIOCM_RNG; |
| 1843 | if (status & UART_MSR_DSR) |
| 1844 | ret |= TIOCM_DSR; |
| 1845 | if (status & UART_MSR_CTS) |
| 1846 | ret |= TIOCM_CTS; |
| 1847 | return ret; |
| 1848 | } |
| 1849 | |
| 1850 | static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl) |
| 1851 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 1852 | struct uart_8250_port *up = |
| 1853 | container_of(port, struct uart_8250_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | unsigned char mcr = 0; |
| 1855 | |
| 1856 | if (mctrl & TIOCM_RTS) |
| 1857 | mcr |= UART_MCR_RTS; |
| 1858 | if (mctrl & TIOCM_DTR) |
| 1859 | mcr |= UART_MCR_DTR; |
| 1860 | if (mctrl & TIOCM_OUT1) |
| 1861 | mcr |= UART_MCR_OUT1; |
| 1862 | if (mctrl & TIOCM_OUT2) |
| 1863 | mcr |= UART_MCR_OUT2; |
| 1864 | if (mctrl & TIOCM_LOOP) |
| 1865 | mcr |= UART_MCR_LOOP; |
| 1866 | |
| 1867 | mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr; |
| 1868 | |
| 1869 | serial_out(up, UART_MCR, mcr); |
| 1870 | } |
| 1871 | |
| 1872 | static void serial8250_break_ctl(struct uart_port *port, int break_state) |
| 1873 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 1874 | struct uart_8250_port *up = |
| 1875 | container_of(port, struct uart_8250_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | unsigned long flags; |
| 1877 | |
| 1878 | spin_lock_irqsave(&up->port.lock, flags); |
| 1879 | if (break_state == -1) |
| 1880 | up->lcr |= UART_LCR_SBC; |
| 1881 | else |
| 1882 | up->lcr &= ~UART_LCR_SBC; |
| 1883 | serial_out(up, UART_LCR, up->lcr); |
| 1884 | spin_unlock_irqrestore(&up->port.lock, flags); |
| 1885 | } |
| 1886 | |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 1887 | /* |
| 1888 | * Wait for transmitter & holding register to empty |
| 1889 | */ |
Will Newton | b5d674a | 2008-10-13 10:36:21 +0100 | [diff] [blame] | 1890 | static void wait_for_xmitr(struct uart_8250_port *up, int bits) |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 1891 | { |
| 1892 | unsigned int status, tmout = 10000; |
| 1893 | |
| 1894 | /* Wait up to 10ms for the character(s) to be sent. */ |
David Daney | 97d303b | 2010-10-05 11:40:07 -0700 | [diff] [blame] | 1895 | for (;;) { |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 1896 | status = serial_in(up, UART_LSR); |
| 1897 | |
Corey Minyard | ad4c2aa | 2007-08-22 14:01:18 -0700 | [diff] [blame] | 1898 | up->lsr_saved_flags |= status & LSR_SAVE_FLAGS; |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 1899 | |
David Daney | 97d303b | 2010-10-05 11:40:07 -0700 | [diff] [blame] | 1900 | if ((status & bits) == bits) |
| 1901 | break; |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 1902 | if (--tmout == 0) |
| 1903 | break; |
| 1904 | udelay(1); |
David Daney | 97d303b | 2010-10-05 11:40:07 -0700 | [diff] [blame] | 1905 | } |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 1906 | |
| 1907 | /* Wait up to 1s for flow control if necessary */ |
| 1908 | if (up->port.flags & UPF_CONS_FLOW) { |
Corey Minyard | ad4c2aa | 2007-08-22 14:01:18 -0700 | [diff] [blame] | 1909 | unsigned int tmout; |
| 1910 | for (tmout = 1000000; tmout; tmout--) { |
| 1911 | unsigned int msr = serial_in(up, UART_MSR); |
| 1912 | up->msr_saved_flags |= msr & MSR_SAVE_FLAGS; |
| 1913 | if (msr & UART_MSR_CTS) |
| 1914 | break; |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 1915 | udelay(1); |
| 1916 | touch_nmi_watchdog(); |
| 1917 | } |
| 1918 | } |
| 1919 | } |
| 1920 | |
Jason Wessel | f2d937f | 2008-04-17 20:05:37 +0200 | [diff] [blame] | 1921 | #ifdef CONFIG_CONSOLE_POLL |
| 1922 | /* |
| 1923 | * Console polling routines for writing and reading from the uart while |
| 1924 | * in an interrupt or debug context. |
| 1925 | */ |
| 1926 | |
| 1927 | static int serial8250_get_poll_char(struct uart_port *port) |
| 1928 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 1929 | struct uart_8250_port *up = |
| 1930 | container_of(port, struct uart_8250_port, port); |
Jason Wessel | f2d937f | 2008-04-17 20:05:37 +0200 | [diff] [blame] | 1931 | unsigned char lsr = serial_inp(up, UART_LSR); |
| 1932 | |
Jason Wessel | f5316b4 | 2010-05-20 21:04:22 -0500 | [diff] [blame] | 1933 | if (!(lsr & UART_LSR_DR)) |
| 1934 | return NO_POLL_CHAR; |
Jason Wessel | f2d937f | 2008-04-17 20:05:37 +0200 | [diff] [blame] | 1935 | |
| 1936 | return serial_inp(up, UART_RX); |
| 1937 | } |
| 1938 | |
| 1939 | |
| 1940 | static void serial8250_put_poll_char(struct uart_port *port, |
| 1941 | unsigned char c) |
| 1942 | { |
| 1943 | unsigned int ier; |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 1944 | struct uart_8250_port *up = |
| 1945 | container_of(port, struct uart_8250_port, port); |
Jason Wessel | f2d937f | 2008-04-17 20:05:37 +0200 | [diff] [blame] | 1946 | |
| 1947 | /* |
| 1948 | * First save the IER then disable the interrupts |
| 1949 | */ |
| 1950 | ier = serial_in(up, UART_IER); |
| 1951 | if (up->capabilities & UART_CAP_UUE) |
| 1952 | serial_out(up, UART_IER, UART_IER_UUE); |
| 1953 | else |
| 1954 | serial_out(up, UART_IER, 0); |
| 1955 | |
| 1956 | wait_for_xmitr(up, BOTH_EMPTY); |
| 1957 | /* |
| 1958 | * Send the character out. |
| 1959 | * If a LF, also do CR... |
| 1960 | */ |
| 1961 | serial_out(up, UART_TX, c); |
| 1962 | if (c == 10) { |
| 1963 | wait_for_xmitr(up, BOTH_EMPTY); |
| 1964 | serial_out(up, UART_TX, 13); |
| 1965 | } |
| 1966 | |
| 1967 | /* |
| 1968 | * Finally, wait for transmitter to become empty |
| 1969 | * and restore the IER |
| 1970 | */ |
| 1971 | wait_for_xmitr(up, BOTH_EMPTY); |
| 1972 | serial_out(up, UART_IER, ier); |
| 1973 | } |
| 1974 | |
| 1975 | #endif /* CONFIG_CONSOLE_POLL */ |
| 1976 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | static int serial8250_startup(struct uart_port *port) |
| 1978 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 1979 | struct uart_8250_port *up = |
| 1980 | container_of(port, struct uart_8250_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | unsigned long flags; |
Russell King | 55d3b28 | 2005-06-23 15:05:41 +0100 | [diff] [blame] | 1982 | unsigned char lsr, iir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | int retval; |
| 1984 | |
Ondrej Puzman | e4f05af | 2010-12-04 21:17:38 +0100 | [diff] [blame] | 1985 | up->port.fifosize = uart_config[up->port.type].fifo_size; |
| 1986 | up->tx_loadsz = uart_config[up->port.type].tx_loadsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | up->capabilities = uart_config[up->port.type].flags; |
| 1988 | up->mcr = 0; |
| 1989 | |
Alan Cox | b8e7e40 | 2009-05-28 14:01:35 +0100 | [diff] [blame] | 1990 | if (up->port.iotype != up->cur_iotype) |
| 1991 | set_io_from_upio(port); |
| 1992 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | if (up->port.type == PORT_16C950) { |
| 1994 | /* Wake up and initialize UART */ |
| 1995 | up->acr = 0; |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 1996 | serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | serial_outp(up, UART_EFR, UART_EFR_ECB); |
| 1998 | serial_outp(up, UART_IER, 0); |
| 1999 | serial_outp(up, UART_LCR, 0); |
| 2000 | serial_icr_write(up, UART_CSR, 0); /* Reset the UART */ |
| 2001 | serial_outp(up, UART_LCR, 0xBF); |
| 2002 | serial_outp(up, UART_EFR, UART_EFR_ECB); |
| 2003 | serial_outp(up, UART_LCR, 0); |
| 2004 | } |
| 2005 | |
| 2006 | #ifdef CONFIG_SERIAL_8250_RSA |
| 2007 | /* |
| 2008 | * If this is an RSA port, see if we can kick it up to the |
| 2009 | * higher speed clock. |
| 2010 | */ |
| 2011 | enable_rsa(up); |
| 2012 | #endif |
| 2013 | |
| 2014 | /* |
| 2015 | * Clear the FIFO buffers and disable them. |
Alexey Dobriyan | 7f927fc | 2006-03-28 01:56:53 -0800 | [diff] [blame] | 2016 | * (they will be reenabled in set_termios()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | */ |
| 2018 | serial8250_clear_fifos(up); |
| 2019 | |
| 2020 | /* |
| 2021 | * Clear the interrupt registers. |
| 2022 | */ |
| 2023 | (void) serial_inp(up, UART_LSR); |
| 2024 | (void) serial_inp(up, UART_RX); |
| 2025 | (void) serial_inp(up, UART_IIR); |
| 2026 | (void) serial_inp(up, UART_MSR); |
| 2027 | |
| 2028 | /* |
| 2029 | * At this point, there's no way the LSR could still be 0xff; |
| 2030 | * if it is, then bail out, because there's likely no UART |
| 2031 | * here. |
| 2032 | */ |
| 2033 | if (!(up->port.flags & UPF_BUGGY_UART) && |
| 2034 | (serial_inp(up, UART_LSR) == 0xff)) { |
David S. Miller | 8440838 | 2008-10-13 10:45:26 +0100 | [diff] [blame] | 2035 | printk(KERN_INFO "ttyS%d: LSR safety check engaged!\n", |
| 2036 | serial_index(&up->port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | return -ENODEV; |
| 2038 | } |
| 2039 | |
| 2040 | /* |
| 2041 | * For a XR16C850, we need to set the trigger levels |
| 2042 | */ |
| 2043 | if (up->port.type == PORT_16850) { |
| 2044 | unsigned char fctr; |
| 2045 | |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 2046 | serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | |
| 2048 | fctr = serial_inp(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX); |
| 2049 | serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_RX); |
| 2050 | serial_outp(up, UART_TRG, UART_TRG_96); |
| 2051 | serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_TX); |
| 2052 | serial_outp(up, UART_TRG, UART_TRG_96); |
| 2053 | |
| 2054 | serial_outp(up, UART_LCR, 0); |
| 2055 | } |
| 2056 | |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 2057 | if (is_real_interrupt(up->port.irq)) { |
Alex Williamson | 01c194d | 2008-04-28 02:14:09 -0700 | [diff] [blame] | 2058 | unsigned char iir1; |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 2059 | /* |
| 2060 | * Test for UARTs that do not reassert THRE when the |
| 2061 | * transmitter is idle and the interrupt has already |
| 2062 | * been cleared. Real 16550s should always reassert |
| 2063 | * this interrupt whenever the transmitter is idle and |
| 2064 | * the interrupt is enabled. Delays are necessary to |
| 2065 | * allow register changes to become visible. |
| 2066 | */ |
Borislav Petkov | c389d27 | 2008-07-29 22:33:32 -0700 | [diff] [blame] | 2067 | spin_lock_irqsave(&up->port.lock, flags); |
Vikram Pandita | 1c2f049 | 2009-09-19 13:13:19 -0700 | [diff] [blame] | 2068 | if (up->port.irqflags & IRQF_SHARED) |
Anton Vorontsov | 768aec0 | 2008-07-22 11:21:07 +0100 | [diff] [blame] | 2069 | disable_irq_nosync(up->port.irq); |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 2070 | |
| 2071 | wait_for_xmitr(up, UART_LSR_THRE); |
| 2072 | serial_out_sync(up, UART_IER, UART_IER_THRI); |
| 2073 | udelay(1); /* allow THRE to set */ |
Alex Williamson | 01c194d | 2008-04-28 02:14:09 -0700 | [diff] [blame] | 2074 | iir1 = serial_in(up, UART_IIR); |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 2075 | serial_out(up, UART_IER, 0); |
| 2076 | serial_out_sync(up, UART_IER, UART_IER_THRI); |
| 2077 | udelay(1); /* allow a working UART time to re-assert THRE */ |
| 2078 | iir = serial_in(up, UART_IIR); |
| 2079 | serial_out(up, UART_IER, 0); |
| 2080 | |
Vikram Pandita | 1c2f049 | 2009-09-19 13:13:19 -0700 | [diff] [blame] | 2081 | if (up->port.irqflags & IRQF_SHARED) |
Anton Vorontsov | 768aec0 | 2008-07-22 11:21:07 +0100 | [diff] [blame] | 2082 | enable_irq(up->port.irq); |
Borislav Petkov | c389d27 | 2008-07-29 22:33:32 -0700 | [diff] [blame] | 2083 | spin_unlock_irqrestore(&up->port.lock, flags); |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 2084 | |
| 2085 | /* |
| 2086 | * If the interrupt is not reasserted, setup a timer to |
| 2087 | * kick the UART on a regular basis. |
| 2088 | */ |
Alex Williamson | 01c194d | 2008-04-28 02:14:09 -0700 | [diff] [blame] | 2089 | if (!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) { |
Will Newton | 363f66f | 2008-09-02 14:35:44 -0700 | [diff] [blame] | 2090 | up->bugs |= UART_BUG_THRE; |
David S. Miller | 8440838 | 2008-10-13 10:45:26 +0100 | [diff] [blame] | 2091 | pr_debug("ttyS%d - using backup timer\n", |
| 2092 | serial_index(port)); |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 2093 | } |
| 2094 | } |
| 2095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | /* |
Will Newton | 363f66f | 2008-09-02 14:35:44 -0700 | [diff] [blame] | 2097 | * The above check will only give an accurate result the first time |
| 2098 | * the port is opened so this value needs to be preserved. |
| 2099 | */ |
| 2100 | if (up->bugs & UART_BUG_THRE) { |
| 2101 | up->timer.function = serial8250_backup_timeout; |
| 2102 | up->timer.data = (unsigned long)up; |
| 2103 | mod_timer(&up->timer, jiffies + |
Anton Vorontsov | 5438106 | 2010-10-01 17:21:25 +0400 | [diff] [blame] | 2104 | uart_poll_timeout(port) + HZ / 5); |
Will Newton | 363f66f | 2008-09-02 14:35:44 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | * If the "interrupt" for this port doesn't correspond with any |
| 2109 | * hardware interrupt, we use a timer-based system. The original |
| 2110 | * driver used to do this with IRQ0. |
| 2111 | */ |
| 2112 | if (!is_real_interrupt(up->port.irq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | up->timer.data = (unsigned long)up; |
Anton Vorontsov | 5438106 | 2010-10-01 17:21:25 +0400 | [diff] [blame] | 2114 | mod_timer(&up->timer, jiffies + uart_poll_timeout(port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | } else { |
| 2116 | retval = serial_link_irq_chain(up); |
| 2117 | if (retval) |
| 2118 | return retval; |
| 2119 | } |
| 2120 | |
| 2121 | /* |
| 2122 | * Now, initialize the UART |
| 2123 | */ |
| 2124 | serial_outp(up, UART_LCR, UART_LCR_WLEN8); |
| 2125 | |
| 2126 | spin_lock_irqsave(&up->port.lock, flags); |
| 2127 | if (up->port.flags & UPF_FOURPORT) { |
| 2128 | if (!is_real_interrupt(up->port.irq)) |
| 2129 | up->port.mctrl |= TIOCM_OUT1; |
| 2130 | } else |
| 2131 | /* |
| 2132 | * Most PC uarts need OUT2 raised to enable interrupts. |
| 2133 | */ |
| 2134 | if (is_real_interrupt(up->port.irq)) |
| 2135 | up->port.mctrl |= TIOCM_OUT2; |
| 2136 | |
| 2137 | serial8250_set_mctrl(&up->port, up->port.mctrl); |
Russell King | 55d3b28 | 2005-06-23 15:05:41 +0100 | [diff] [blame] | 2138 | |
Mauro Carvalho Chehab | b6adea3 | 2009-02-20 15:38:52 -0800 | [diff] [blame] | 2139 | /* Serial over Lan (SoL) hack: |
| 2140 | Intel 8257x Gigabit ethernet chips have a |
| 2141 | 16550 emulation, to be used for Serial Over Lan. |
| 2142 | Those chips take a longer time than a normal |
| 2143 | serial device to signalize that a transmission |
| 2144 | data was queued. Due to that, the above test generally |
| 2145 | fails. One solution would be to delay the reading of |
| 2146 | iir. However, this is not reliable, since the timeout |
| 2147 | is variable. So, let's just don't test if we receive |
| 2148 | TX irq. This way, we'll never enable UART_BUG_TXEN. |
| 2149 | */ |
Chuck Ebbert | d41a4b5 | 2009-10-01 15:44:26 -0700 | [diff] [blame] | 2150 | if (skip_txen_test || up->port.flags & UPF_NO_TXEN_TEST) |
Mauro Carvalho Chehab | b6adea3 | 2009-02-20 15:38:52 -0800 | [diff] [blame] | 2151 | goto dont_test_tx_en; |
| 2152 | |
Russell King | 55d3b28 | 2005-06-23 15:05:41 +0100 | [diff] [blame] | 2153 | /* |
| 2154 | * Do a quick test to see if we receive an |
| 2155 | * interrupt when we enable the TX irq. |
| 2156 | */ |
| 2157 | serial_outp(up, UART_IER, UART_IER_THRI); |
| 2158 | lsr = serial_in(up, UART_LSR); |
| 2159 | iir = serial_in(up, UART_IIR); |
| 2160 | serial_outp(up, UART_IER, 0); |
| 2161 | |
| 2162 | if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) { |
Russell King | 67f7654 | 2005-06-23 22:26:43 +0100 | [diff] [blame] | 2163 | if (!(up->bugs & UART_BUG_TXEN)) { |
| 2164 | up->bugs |= UART_BUG_TXEN; |
Russell King | 55d3b28 | 2005-06-23 15:05:41 +0100 | [diff] [blame] | 2165 | pr_debug("ttyS%d - enabling bad tx status workarounds\n", |
David S. Miller | 8440838 | 2008-10-13 10:45:26 +0100 | [diff] [blame] | 2166 | serial_index(port)); |
Russell King | 55d3b28 | 2005-06-23 15:05:41 +0100 | [diff] [blame] | 2167 | } |
| 2168 | } else { |
Russell King | 67f7654 | 2005-06-23 22:26:43 +0100 | [diff] [blame] | 2169 | up->bugs &= ~UART_BUG_TXEN; |
Russell King | 55d3b28 | 2005-06-23 15:05:41 +0100 | [diff] [blame] | 2170 | } |
| 2171 | |
Mauro Carvalho Chehab | b6adea3 | 2009-02-20 15:38:52 -0800 | [diff] [blame] | 2172 | dont_test_tx_en: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | spin_unlock_irqrestore(&up->port.lock, flags); |
| 2174 | |
| 2175 | /* |
Corey Minyard | ad4c2aa | 2007-08-22 14:01:18 -0700 | [diff] [blame] | 2176 | * Clear the interrupt registers again for luck, and clear the |
| 2177 | * saved flags to avoid getting false values from polling |
| 2178 | * routines or the previous session. |
| 2179 | */ |
| 2180 | serial_inp(up, UART_LSR); |
| 2181 | serial_inp(up, UART_RX); |
| 2182 | serial_inp(up, UART_IIR); |
| 2183 | serial_inp(up, UART_MSR); |
| 2184 | up->lsr_saved_flags = 0; |
| 2185 | up->msr_saved_flags = 0; |
| 2186 | |
| 2187 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | * Finally, enable interrupts. Note: Modem status interrupts |
| 2189 | * are set via set_termios(), which will be occurring imminently |
| 2190 | * anyway, so we don't enable them here. |
| 2191 | */ |
| 2192 | up->ier = UART_IER_RLSI | UART_IER_RDI; |
| 2193 | serial_outp(up, UART_IER, up->ier); |
| 2194 | |
| 2195 | if (up->port.flags & UPF_FOURPORT) { |
| 2196 | unsigned int icp; |
| 2197 | /* |
| 2198 | * Enable interrupts on the AST Fourport board |
| 2199 | */ |
| 2200 | icp = (up->port.iobase & 0xfe0) | 0x01f; |
| 2201 | outb_p(0x80, icp); |
| 2202 | (void) inb_p(icp); |
| 2203 | } |
| 2204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | return 0; |
| 2206 | } |
| 2207 | |
| 2208 | static void serial8250_shutdown(struct uart_port *port) |
| 2209 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 2210 | struct uart_8250_port *up = |
| 2211 | container_of(port, struct uart_8250_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | unsigned long flags; |
| 2213 | |
| 2214 | /* |
| 2215 | * Disable interrupts from this port |
| 2216 | */ |
| 2217 | up->ier = 0; |
| 2218 | serial_outp(up, UART_IER, 0); |
| 2219 | |
| 2220 | spin_lock_irqsave(&up->port.lock, flags); |
| 2221 | if (up->port.flags & UPF_FOURPORT) { |
| 2222 | /* reset interrupts on the AST Fourport board */ |
| 2223 | inb((up->port.iobase & 0xfe0) | 0x1f); |
| 2224 | up->port.mctrl |= TIOCM_OUT1; |
| 2225 | } else |
| 2226 | up->port.mctrl &= ~TIOCM_OUT2; |
| 2227 | |
| 2228 | serial8250_set_mctrl(&up->port, up->port.mctrl); |
| 2229 | spin_unlock_irqrestore(&up->port.lock, flags); |
| 2230 | |
| 2231 | /* |
| 2232 | * Disable break condition and FIFOs |
| 2233 | */ |
| 2234 | serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC); |
| 2235 | serial8250_clear_fifos(up); |
| 2236 | |
| 2237 | #ifdef CONFIG_SERIAL_8250_RSA |
| 2238 | /* |
| 2239 | * Reset the RSA board back to 115kbps compat mode. |
| 2240 | */ |
| 2241 | disable_rsa(up); |
| 2242 | #endif |
| 2243 | |
| 2244 | /* |
| 2245 | * Read data port to reset things, and then unlink from |
| 2246 | * the IRQ chain. |
| 2247 | */ |
| 2248 | (void) serial_in(up, UART_RX); |
| 2249 | |
Alex Williamson | 40b36da | 2007-02-14 00:33:04 -0800 | [diff] [blame] | 2250 | del_timer_sync(&up->timer); |
| 2251 | up->timer.function = serial8250_timeout; |
| 2252 | if (is_real_interrupt(up->port.irq)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | serial_unlink_irq_chain(up); |
| 2254 | } |
| 2255 | |
| 2256 | static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int baud) |
| 2257 | { |
| 2258 | unsigned int quot; |
| 2259 | |
| 2260 | /* |
| 2261 | * Handle magic divisors for baud rates above baud_base on |
| 2262 | * SMSC SuperIO chips. |
| 2263 | */ |
| 2264 | if ((port->flags & UPF_MAGIC_MULTIPLIER) && |
| 2265 | baud == (port->uartclk/4)) |
| 2266 | quot = 0x8001; |
| 2267 | else if ((port->flags & UPF_MAGIC_MULTIPLIER) && |
| 2268 | baud == (port->uartclk/8)) |
| 2269 | quot = 0x8002; |
| 2270 | else |
| 2271 | quot = uart_get_divisor(port, baud); |
| 2272 | |
| 2273 | return quot; |
| 2274 | } |
| 2275 | |
Philippe Langlais | 235dae5 | 2010-07-29 17:13:57 +0200 | [diff] [blame] | 2276 | void |
| 2277 | serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, |
| 2278 | struct ktermios *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 2280 | struct uart_8250_port *up = |
| 2281 | container_of(port, struct uart_8250_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | unsigned char cval, fcr = 0; |
| 2283 | unsigned long flags; |
| 2284 | unsigned int baud, quot; |
| 2285 | |
| 2286 | switch (termios->c_cflag & CSIZE) { |
| 2287 | case CS5: |
Russell King | 0a8b80c5 | 2005-06-24 19:48:22 +0100 | [diff] [blame] | 2288 | cval = UART_LCR_WLEN5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | break; |
| 2290 | case CS6: |
Russell King | 0a8b80c5 | 2005-06-24 19:48:22 +0100 | [diff] [blame] | 2291 | cval = UART_LCR_WLEN6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | break; |
| 2293 | case CS7: |
Russell King | 0a8b80c5 | 2005-06-24 19:48:22 +0100 | [diff] [blame] | 2294 | cval = UART_LCR_WLEN7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | break; |
| 2296 | default: |
| 2297 | case CS8: |
Russell King | 0a8b80c5 | 2005-06-24 19:48:22 +0100 | [diff] [blame] | 2298 | cval = UART_LCR_WLEN8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | break; |
| 2300 | } |
| 2301 | |
| 2302 | if (termios->c_cflag & CSTOPB) |
Russell King | 0a8b80c5 | 2005-06-24 19:48:22 +0100 | [diff] [blame] | 2303 | cval |= UART_LCR_STOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | if (termios->c_cflag & PARENB) |
| 2305 | cval |= UART_LCR_PARITY; |
| 2306 | if (!(termios->c_cflag & PARODD)) |
| 2307 | cval |= UART_LCR_EPAR; |
| 2308 | #ifdef CMSPAR |
| 2309 | if (termios->c_cflag & CMSPAR) |
| 2310 | cval |= UART_LCR_SPAR; |
| 2311 | #endif |
| 2312 | |
| 2313 | /* |
| 2314 | * Ask the core to calculate the divisor for us. |
| 2315 | */ |
Anton Vorontsov | 24d481e | 2009-09-19 13:13:20 -0700 | [diff] [blame] | 2316 | baud = uart_get_baud_rate(port, termios, old, |
| 2317 | port->uartclk / 16 / 0xffff, |
| 2318 | port->uartclk / 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | quot = serial8250_get_divisor(port, baud); |
| 2320 | |
| 2321 | /* |
Russell King | 4ba5e35 | 2005-06-23 10:43:04 +0100 | [diff] [blame] | 2322 | * Oxford Semi 952 rev B workaround |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | */ |
Russell King | 4ba5e35 | 2005-06-23 10:43:04 +0100 | [diff] [blame] | 2324 | if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0) |
Alan Cox | 3e8d4e2 | 2008-02-04 22:27:53 -0800 | [diff] [blame] | 2325 | quot++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | |
| 2327 | if (up->capabilities & UART_CAP_FIFO && up->port.fifosize > 1) { |
| 2328 | if (baud < 2400) |
| 2329 | fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1; |
| 2330 | else |
| 2331 | fcr = uart_config[up->port.type].fcr; |
| 2332 | } |
| 2333 | |
| 2334 | /* |
| 2335 | * MCR-based auto flow control. When AFE is enabled, RTS will be |
| 2336 | * deasserted when the receive FIFO contains more characters than |
| 2337 | * the trigger, or the MCR RTS bit is cleared. In the case where |
| 2338 | * the remote UART is not using CTS auto flow control, we must |
| 2339 | * have sufficient FIFO entries for the latency of the remote |
| 2340 | * UART to respond. IOW, at least 32 bytes of FIFO. |
| 2341 | */ |
| 2342 | if (up->capabilities & UART_CAP_AFE && up->port.fifosize >= 32) { |
| 2343 | up->mcr &= ~UART_MCR_AFE; |
| 2344 | if (termios->c_cflag & CRTSCTS) |
| 2345 | up->mcr |= UART_MCR_AFE; |
| 2346 | } |
| 2347 | |
| 2348 | /* |
| 2349 | * Ok, we're now changing the port state. Do it with |
| 2350 | * interrupts disabled. |
| 2351 | */ |
| 2352 | spin_lock_irqsave(&up->port.lock, flags); |
| 2353 | |
| 2354 | /* |
| 2355 | * Update the per-port timeout. |
| 2356 | */ |
| 2357 | uart_update_timeout(port, termios->c_cflag, baud); |
| 2358 | |
| 2359 | up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; |
| 2360 | if (termios->c_iflag & INPCK) |
| 2361 | up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE; |
| 2362 | if (termios->c_iflag & (BRKINT | PARMRK)) |
| 2363 | up->port.read_status_mask |= UART_LSR_BI; |
| 2364 | |
| 2365 | /* |
| 2366 | * Characteres to ignore |
| 2367 | */ |
| 2368 | up->port.ignore_status_mask = 0; |
| 2369 | if (termios->c_iflag & IGNPAR) |
| 2370 | up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; |
| 2371 | if (termios->c_iflag & IGNBRK) { |
| 2372 | up->port.ignore_status_mask |= UART_LSR_BI; |
| 2373 | /* |
| 2374 | * If we're ignoring parity and break indicators, |
| 2375 | * ignore overruns too (for real raw support). |
| 2376 | */ |
| 2377 | if (termios->c_iflag & IGNPAR) |
| 2378 | up->port.ignore_status_mask |= UART_LSR_OE; |
| 2379 | } |
| 2380 | |
| 2381 | /* |
| 2382 | * ignore all characters if CREAD is not set |
| 2383 | */ |
| 2384 | if ((termios->c_cflag & CREAD) == 0) |
| 2385 | up->port.ignore_status_mask |= UART_LSR_DR; |
| 2386 | |
| 2387 | /* |
| 2388 | * CTS flow control flag and modem status interrupts |
| 2389 | */ |
Ingo Molnar | f8b372a | 2010-11-13 16:21:58 +0100 | [diff] [blame] | 2390 | up->ier &= ~UART_IER_MSI; |
Pantelis Antoniou | 21c614a | 2005-11-06 09:07:03 +0000 | [diff] [blame] | 2391 | if (!(up->bugs & UART_BUG_NOMSR) && |
| 2392 | UART_ENABLE_MS(&up->port, termios->c_cflag)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | up->ier |= UART_IER_MSI; |
| 2394 | if (up->capabilities & UART_CAP_UUE) |
| 2395 | up->ier |= UART_IER_UUE | UART_IER_RTOIE; |
| 2396 | |
| 2397 | serial_out(up, UART_IER, up->ier); |
| 2398 | |
| 2399 | if (up->capabilities & UART_CAP_EFR) { |
| 2400 | unsigned char efr = 0; |
| 2401 | /* |
| 2402 | * TI16C752/Startech hardware flow control. FIXME: |
| 2403 | * - TI16C752 requires control thresholds to be set. |
| 2404 | * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled. |
| 2405 | */ |
| 2406 | if (termios->c_cflag & CRTSCTS) |
| 2407 | efr |= UART_EFR_CTS; |
| 2408 | |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 2409 | serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | serial_outp(up, UART_EFR, efr); |
| 2411 | } |
| 2412 | |
Russell King | f2eda27 | 2008-09-01 21:47:59 +0100 | [diff] [blame] | 2413 | #ifdef CONFIG_ARCH_OMAP |
Jonathan McDowell | 255341c | 2006-08-14 23:05:32 -0700 | [diff] [blame] | 2414 | /* Workaround to enable 115200 baud on OMAP1510 internal ports */ |
Russell King | 5668545 | 2008-09-01 21:25:33 +0100 | [diff] [blame] | 2415 | if (cpu_is_omap1510() && is_omap_port(up)) { |
Jonathan McDowell | 255341c | 2006-08-14 23:05:32 -0700 | [diff] [blame] | 2416 | if (baud == 115200) { |
| 2417 | quot = 1; |
| 2418 | serial_out(up, UART_OMAP_OSC_12M_SEL, 1); |
| 2419 | } else |
| 2420 | serial_out(up, UART_OMAP_OSC_12M_SEL, 0); |
| 2421 | } |
| 2422 | #endif |
| 2423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | if (up->capabilities & UART_NATSEMI) { |
| 2425 | /* Switch to bank 2 not bank 1, to avoid resetting EXCR2 */ |
| 2426 | serial_outp(up, UART_LCR, 0xe0); |
| 2427 | } else { |
| 2428 | serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */ |
| 2429 | } |
| 2430 | |
Jon Anders Haugum | b32b19b | 2006-04-30 11:20:56 +0100 | [diff] [blame] | 2431 | serial_dl_write(up, quot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | |
| 2433 | /* |
| 2434 | * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR |
| 2435 | * is written without DLAB set, this mode will be disabled. |
| 2436 | */ |
| 2437 | if (up->port.type == PORT_16750) |
| 2438 | serial_outp(up, UART_FCR, fcr); |
| 2439 | |
| 2440 | serial_outp(up, UART_LCR, cval); /* reset DLAB */ |
| 2441 | up->lcr = cval; /* Save LCR */ |
| 2442 | if (up->port.type != PORT_16750) { |
| 2443 | if (fcr & UART_FCR_ENABLE_FIFO) { |
| 2444 | /* emulated UARTs (Lucent Venus 167x) need two steps */ |
| 2445 | serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); |
| 2446 | } |
| 2447 | serial_outp(up, UART_FCR, fcr); /* set fcr */ |
| 2448 | } |
| 2449 | serial8250_set_mctrl(&up->port, up->port.mctrl); |
| 2450 | spin_unlock_irqrestore(&up->port.lock, flags); |
Alan Cox | e991a2b | 2008-04-28 02:14:06 -0700 | [diff] [blame] | 2451 | /* Don't rewrite B0 */ |
| 2452 | if (tty_termios_baud_rate(termios)) |
| 2453 | tty_termios_encode_baud_rate(termios, baud, baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | } |
Philippe Langlais | 235dae5 | 2010-07-29 17:13:57 +0200 | [diff] [blame] | 2455 | EXPORT_SYMBOL(serial8250_do_set_termios); |
| 2456 | |
| 2457 | static void |
| 2458 | serial8250_set_termios(struct uart_port *port, struct ktermios *termios, |
| 2459 | struct ktermios *old) |
| 2460 | { |
| 2461 | if (port->set_termios) |
| 2462 | port->set_termios(port, termios, old); |
| 2463 | else |
| 2464 | serial8250_do_set_termios(port, termios, old); |
| 2465 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | |
| 2467 | static void |
Arnd Bergmann | a0821df | 2010-06-01 22:53:11 +0200 | [diff] [blame] | 2468 | serial8250_set_ldisc(struct uart_port *port, int new) |
Rodolfo Giometti | dc77f16 | 2010-03-10 15:23:48 -0800 | [diff] [blame] | 2469 | { |
Arnd Bergmann | a0821df | 2010-06-01 22:53:11 +0200 | [diff] [blame] | 2470 | if (new == N_PPS) { |
Rodolfo Giometti | dc77f16 | 2010-03-10 15:23:48 -0800 | [diff] [blame] | 2471 | port->flags |= UPF_HARDPPS_CD; |
| 2472 | serial8250_enable_ms(port); |
| 2473 | } else |
| 2474 | port->flags &= ~UPF_HARDPPS_CD; |
| 2475 | } |
| 2476 | |
Manuel Lauss | c161afe | 2010-09-25 15:13:45 +0200 | [diff] [blame] | 2477 | |
| 2478 | void serial8250_do_pm(struct uart_port *port, unsigned int state, |
| 2479 | unsigned int oldstate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 2481 | struct uart_8250_port *p = |
| 2482 | container_of(port, struct uart_8250_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | |
| 2484 | serial8250_set_sleep(p, state != 0); |
Manuel Lauss | c161afe | 2010-09-25 15:13:45 +0200 | [diff] [blame] | 2485 | } |
| 2486 | EXPORT_SYMBOL(serial8250_do_pm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | |
Manuel Lauss | c161afe | 2010-09-25 15:13:45 +0200 | [diff] [blame] | 2488 | static void |
| 2489 | serial8250_pm(struct uart_port *port, unsigned int state, |
| 2490 | unsigned int oldstate) |
| 2491 | { |
| 2492 | if (port->pm) |
| 2493 | port->pm(port, state, oldstate); |
| 2494 | else |
| 2495 | serial8250_do_pm(port, state, oldstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | } |
| 2497 | |
Russell King | f2eda27 | 2008-09-01 21:47:59 +0100 | [diff] [blame] | 2498 | static unsigned int serial8250_port_size(struct uart_8250_port *pt) |
| 2499 | { |
| 2500 | if (pt->port.iotype == UPIO_AU) |
Manuel Lauss | b2b13cd | 2009-10-28 21:37:28 +0100 | [diff] [blame] | 2501 | return 0x1000; |
Russell King | f2eda27 | 2008-09-01 21:47:59 +0100 | [diff] [blame] | 2502 | #ifdef CONFIG_ARCH_OMAP |
| 2503 | if (is_omap_port(pt)) |
| 2504 | return 0x16 << pt->port.regshift; |
| 2505 | #endif |
| 2506 | return 8 << pt->port.regshift; |
| 2507 | } |
| 2508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | /* |
| 2510 | * Resource handling. |
| 2511 | */ |
| 2512 | static int serial8250_request_std_resource(struct uart_8250_port *up) |
| 2513 | { |
Russell King | f2eda27 | 2008-09-01 21:47:59 +0100 | [diff] [blame] | 2514 | unsigned int size = serial8250_port_size(up); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2515 | int ret = 0; |
| 2516 | |
| 2517 | switch (up->port.iotype) { |
Sergei Shtylyov | 85835f4 | 2006-04-30 11:15:58 +0100 | [diff] [blame] | 2518 | case UPIO_AU: |
Sergei Shtylyov | 0b30d66 | 2006-09-09 22:23:56 +0400 | [diff] [blame] | 2519 | case UPIO_TSI: |
| 2520 | case UPIO_MEM32: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | case UPIO_MEM: |
Marc St-Jean | beab697 | 2007-05-06 14:48:45 -0700 | [diff] [blame] | 2522 | case UPIO_DWAPB: |
Jamie Iles | a3ae0fc | 2010-12-01 23:39:36 +0000 | [diff] [blame] | 2523 | case UPIO_DWAPB32: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | if (!up->port.mapbase) |
| 2525 | break; |
| 2526 | |
| 2527 | if (!request_mem_region(up->port.mapbase, size, "serial")) { |
| 2528 | ret = -EBUSY; |
| 2529 | break; |
| 2530 | } |
| 2531 | |
| 2532 | if (up->port.flags & UPF_IOREMAP) { |
Alan Cox | 6f441fe | 2008-05-01 04:34:59 -0700 | [diff] [blame] | 2533 | up->port.membase = ioremap_nocache(up->port.mapbase, |
| 2534 | size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | if (!up->port.membase) { |
| 2536 | release_mem_region(up->port.mapbase, size); |
| 2537 | ret = -ENOMEM; |
| 2538 | } |
| 2539 | } |
| 2540 | break; |
| 2541 | |
| 2542 | case UPIO_HUB6: |
| 2543 | case UPIO_PORT: |
| 2544 | if (!request_region(up->port.iobase, size, "serial")) |
| 2545 | ret = -EBUSY; |
| 2546 | break; |
| 2547 | } |
| 2548 | return ret; |
| 2549 | } |
| 2550 | |
| 2551 | static void serial8250_release_std_resource(struct uart_8250_port *up) |
| 2552 | { |
Russell King | f2eda27 | 2008-09-01 21:47:59 +0100 | [diff] [blame] | 2553 | unsigned int size = serial8250_port_size(up); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | |
| 2555 | switch (up->port.iotype) { |
Sergei Shtylyov | 85835f4 | 2006-04-30 11:15:58 +0100 | [diff] [blame] | 2556 | case UPIO_AU: |
Sergei Shtylyov | 0b30d66 | 2006-09-09 22:23:56 +0400 | [diff] [blame] | 2557 | case UPIO_TSI: |
| 2558 | case UPIO_MEM32: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | case UPIO_MEM: |
Marc St-Jean | beab697 | 2007-05-06 14:48:45 -0700 | [diff] [blame] | 2560 | case UPIO_DWAPB: |
Jamie Iles | a3ae0fc | 2010-12-01 23:39:36 +0000 | [diff] [blame] | 2561 | case UPIO_DWAPB32: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | if (!up->port.mapbase) |
| 2563 | break; |
| 2564 | |
| 2565 | if (up->port.flags & UPF_IOREMAP) { |
| 2566 | iounmap(up->port.membase); |
| 2567 | up->port.membase = NULL; |
| 2568 | } |
| 2569 | |
| 2570 | release_mem_region(up->port.mapbase, size); |
| 2571 | break; |
| 2572 | |
| 2573 | case UPIO_HUB6: |
| 2574 | case UPIO_PORT: |
| 2575 | release_region(up->port.iobase, size); |
| 2576 | break; |
| 2577 | } |
| 2578 | } |
| 2579 | |
| 2580 | static int serial8250_request_rsa_resource(struct uart_8250_port *up) |
| 2581 | { |
| 2582 | unsigned long start = UART_RSA_BASE << up->port.regshift; |
| 2583 | unsigned int size = 8 << up->port.regshift; |
Sergei Shtylyov | 0b30d66 | 2006-09-09 22:23:56 +0400 | [diff] [blame] | 2584 | int ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | |
| 2586 | switch (up->port.iotype) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | case UPIO_HUB6: |
| 2588 | case UPIO_PORT: |
| 2589 | start += up->port.iobase; |
Sergei Shtylyov | 0b30d66 | 2006-09-09 22:23:56 +0400 | [diff] [blame] | 2590 | if (request_region(start, size, "serial-rsa")) |
| 2591 | ret = 0; |
| 2592 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | ret = -EBUSY; |
| 2594 | break; |
| 2595 | } |
| 2596 | |
| 2597 | return ret; |
| 2598 | } |
| 2599 | |
| 2600 | static void serial8250_release_rsa_resource(struct uart_8250_port *up) |
| 2601 | { |
| 2602 | unsigned long offset = UART_RSA_BASE << up->port.regshift; |
| 2603 | unsigned int size = 8 << up->port.regshift; |
| 2604 | |
| 2605 | switch (up->port.iotype) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | case UPIO_HUB6: |
| 2607 | case UPIO_PORT: |
| 2608 | release_region(up->port.iobase + offset, size); |
| 2609 | break; |
| 2610 | } |
| 2611 | } |
| 2612 | |
| 2613 | static void serial8250_release_port(struct uart_port *port) |
| 2614 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 2615 | struct uart_8250_port *up = |
| 2616 | container_of(port, struct uart_8250_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | |
| 2618 | serial8250_release_std_resource(up); |
| 2619 | if (up->port.type == PORT_RSA) |
| 2620 | serial8250_release_rsa_resource(up); |
| 2621 | } |
| 2622 | |
| 2623 | static int serial8250_request_port(struct uart_port *port) |
| 2624 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 2625 | struct uart_8250_port *up = |
| 2626 | container_of(port, struct uart_8250_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | int ret = 0; |
| 2628 | |
| 2629 | ret = serial8250_request_std_resource(up); |
| 2630 | if (ret == 0 && up->port.type == PORT_RSA) { |
| 2631 | ret = serial8250_request_rsa_resource(up); |
| 2632 | if (ret < 0) |
| 2633 | serial8250_release_std_resource(up); |
| 2634 | } |
| 2635 | |
| 2636 | return ret; |
| 2637 | } |
| 2638 | |
| 2639 | static void serial8250_config_port(struct uart_port *port, int flags) |
| 2640 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 2641 | struct uart_8250_port *up = |
| 2642 | container_of(port, struct uart_8250_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | int probeflags = PROBE_ANY; |
| 2644 | int ret; |
| 2645 | |
| 2646 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | * Find the region that we can probe for. This in turn |
| 2648 | * tells us whether we can probe for the type of port. |
| 2649 | */ |
| 2650 | ret = serial8250_request_std_resource(up); |
| 2651 | if (ret < 0) |
| 2652 | return; |
| 2653 | |
| 2654 | ret = serial8250_request_rsa_resource(up); |
| 2655 | if (ret < 0) |
| 2656 | probeflags &= ~PROBE_RSA; |
| 2657 | |
Alan Cox | b8e7e40 | 2009-05-28 14:01:35 +0100 | [diff] [blame] | 2658 | if (up->port.iotype != up->cur_iotype) |
| 2659 | set_io_from_upio(port); |
| 2660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | if (flags & UART_CONFIG_TYPE) |
| 2662 | autoconfig(up, probeflags); |
Manuel Lauss | b2b13cd | 2009-10-28 21:37:28 +0100 | [diff] [blame] | 2663 | |
Manuel Lauss | b2b13cd | 2009-10-28 21:37:28 +0100 | [diff] [blame] | 2664 | /* if access method is AU, it is a 16550 with a quirk */ |
| 2665 | if (up->port.type == PORT_16550A && up->port.iotype == UPIO_AU) |
| 2666 | up->bugs |= UART_BUG_NOMSR; |
Manuel Lauss | b2b13cd | 2009-10-28 21:37:28 +0100 | [diff] [blame] | 2667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | if (up->port.type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ) |
| 2669 | autoconfig_irq(up); |
| 2670 | |
| 2671 | if (up->port.type != PORT_RSA && probeflags & PROBE_RSA) |
| 2672 | serial8250_release_rsa_resource(up); |
| 2673 | if (up->port.type == PORT_UNKNOWN) |
| 2674 | serial8250_release_std_resource(up); |
| 2675 | } |
| 2676 | |
| 2677 | static int |
| 2678 | serial8250_verify_port(struct uart_port *port, struct serial_struct *ser) |
| 2679 | { |
Yinghai Lu | a62c413 | 2008-08-19 20:49:55 -0700 | [diff] [blame] | 2680 | if (ser->irq >= nr_irqs || ser->irq < 0 || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | ser->baud_base < 9600 || ser->type < PORT_UNKNOWN || |
| 2682 | ser->type >= ARRAY_SIZE(uart_config) || ser->type == PORT_CIRRUS || |
| 2683 | ser->type == PORT_STARTECH) |
| 2684 | return -EINVAL; |
| 2685 | return 0; |
| 2686 | } |
| 2687 | |
| 2688 | static const char * |
| 2689 | serial8250_type(struct uart_port *port) |
| 2690 | { |
| 2691 | int type = port->type; |
| 2692 | |
| 2693 | if (type >= ARRAY_SIZE(uart_config)) |
| 2694 | type = 0; |
| 2695 | return uart_config[type].name; |
| 2696 | } |
| 2697 | |
| 2698 | static struct uart_ops serial8250_pops = { |
| 2699 | .tx_empty = serial8250_tx_empty, |
| 2700 | .set_mctrl = serial8250_set_mctrl, |
| 2701 | .get_mctrl = serial8250_get_mctrl, |
| 2702 | .stop_tx = serial8250_stop_tx, |
| 2703 | .start_tx = serial8250_start_tx, |
| 2704 | .stop_rx = serial8250_stop_rx, |
| 2705 | .enable_ms = serial8250_enable_ms, |
| 2706 | .break_ctl = serial8250_break_ctl, |
| 2707 | .startup = serial8250_startup, |
| 2708 | .shutdown = serial8250_shutdown, |
| 2709 | .set_termios = serial8250_set_termios, |
Rodolfo Giometti | dc77f16 | 2010-03-10 15:23:48 -0800 | [diff] [blame] | 2710 | .set_ldisc = serial8250_set_ldisc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | .pm = serial8250_pm, |
| 2712 | .type = serial8250_type, |
| 2713 | .release_port = serial8250_release_port, |
| 2714 | .request_port = serial8250_request_port, |
| 2715 | .config_port = serial8250_config_port, |
| 2716 | .verify_port = serial8250_verify_port, |
Jason Wessel | f2d937f | 2008-04-17 20:05:37 +0200 | [diff] [blame] | 2717 | #ifdef CONFIG_CONSOLE_POLL |
| 2718 | .poll_get_char = serial8250_get_poll_char, |
| 2719 | .poll_put_char = serial8250_put_poll_char, |
| 2720 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | }; |
| 2722 | |
| 2723 | static struct uart_8250_port serial8250_ports[UART_NR]; |
| 2724 | |
Alan Cox | af7f374 | 2010-10-18 11:38:02 -0700 | [diff] [blame] | 2725 | static void (*serial8250_isa_config)(int port, struct uart_port *up, |
| 2726 | unsigned short *capabilities); |
| 2727 | |
| 2728 | void serial8250_set_isa_configurator( |
| 2729 | void (*v)(int port, struct uart_port *up, unsigned short *capabilities)) |
| 2730 | { |
| 2731 | serial8250_isa_config = v; |
| 2732 | } |
| 2733 | EXPORT_SYMBOL(serial8250_set_isa_configurator); |
| 2734 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | static void __init serial8250_isa_init_ports(void) |
| 2736 | { |
| 2737 | struct uart_8250_port *up; |
| 2738 | static int first = 1; |
André Goddard Rosa | 4c0ebb8 | 2009-10-25 12:01:34 -0200 | [diff] [blame] | 2739 | int i, irqflag = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | |
| 2741 | if (!first) |
| 2742 | return; |
| 2743 | first = 0; |
| 2744 | |
Dave Jones | a61c2d7 | 2006-01-07 23:18:19 +0000 | [diff] [blame] | 2745 | for (i = 0; i < nr_uarts; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | struct uart_8250_port *up = &serial8250_ports[i]; |
| 2747 | |
| 2748 | up->port.line = i; |
| 2749 | spin_lock_init(&up->port.lock); |
| 2750 | |
| 2751 | init_timer(&up->timer); |
| 2752 | up->timer.function = serial8250_timeout; |
| 2753 | |
| 2754 | /* |
| 2755 | * ALPHA_KLUDGE_MCR needs to be killed. |
| 2756 | */ |
| 2757 | up->mcr_mask = ~ALPHA_KLUDGE_MCR; |
| 2758 | up->mcr_force = ALPHA_KLUDGE_MCR; |
| 2759 | |
| 2760 | up->port.ops = &serial8250_pops; |
| 2761 | } |
| 2762 | |
André Goddard Rosa | 4c0ebb8 | 2009-10-25 12:01:34 -0200 | [diff] [blame] | 2763 | if (share_irqs) |
| 2764 | irqflag = IRQF_SHARED; |
| 2765 | |
Russell King | 44454bc | 2005-06-30 22:41:22 +0100 | [diff] [blame] | 2766 | for (i = 0, up = serial8250_ports; |
Dave Jones | a61c2d7 | 2006-01-07 23:18:19 +0000 | [diff] [blame] | 2767 | i < ARRAY_SIZE(old_serial_port) && i < nr_uarts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | i++, up++) { |
| 2769 | up->port.iobase = old_serial_port[i].port; |
| 2770 | up->port.irq = irq_canonicalize(old_serial_port[i].irq); |
Vikram Pandita | 1c2f049 | 2009-09-19 13:13:19 -0700 | [diff] [blame] | 2771 | up->port.irqflags = old_serial_port[i].irqflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | up->port.uartclk = old_serial_port[i].baud_base * 16; |
| 2773 | up->port.flags = old_serial_port[i].flags; |
| 2774 | up->port.hub6 = old_serial_port[i].hub6; |
| 2775 | up->port.membase = old_serial_port[i].iomem_base; |
| 2776 | up->port.iotype = old_serial_port[i].io_type; |
| 2777 | up->port.regshift = old_serial_port[i].iomem_reg_shift; |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 2778 | set_io_from_upio(&up->port); |
André Goddard Rosa | 4c0ebb8 | 2009-10-25 12:01:34 -0200 | [diff] [blame] | 2779 | up->port.irqflags |= irqflag; |
Alan Cox | af7f374 | 2010-10-18 11:38:02 -0700 | [diff] [blame] | 2780 | if (serial8250_isa_config != NULL) |
| 2781 | serial8250_isa_config(i, &up->port, &up->capabilities); |
| 2782 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | } |
| 2784 | } |
| 2785 | |
Shmulik Ladkani | b5d228c | 2009-12-09 12:31:29 -0800 | [diff] [blame] | 2786 | static void |
| 2787 | serial8250_init_fixed_type_port(struct uart_8250_port *up, unsigned int type) |
| 2788 | { |
| 2789 | up->port.type = type; |
| 2790 | up->port.fifosize = uart_config[type].fifo_size; |
| 2791 | up->capabilities = uart_config[type].flags; |
| 2792 | up->tx_loadsz = uart_config[type].tx_loadsz; |
| 2793 | } |
| 2794 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | static void __init |
| 2796 | serial8250_register_ports(struct uart_driver *drv, struct device *dev) |
| 2797 | { |
| 2798 | int i; |
| 2799 | |
Alan Cox | b8e7e40 | 2009-05-28 14:01:35 +0100 | [diff] [blame] | 2800 | for (i = 0; i < nr_uarts; i++) { |
| 2801 | struct uart_8250_port *up = &serial8250_ports[i]; |
| 2802 | up->cur_iotype = 0xFF; |
| 2803 | } |
| 2804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | serial8250_isa_init_ports(); |
| 2806 | |
Dave Jones | a61c2d7 | 2006-01-07 23:18:19 +0000 | [diff] [blame] | 2807 | for (i = 0; i < nr_uarts; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | struct uart_8250_port *up = &serial8250_ports[i]; |
| 2809 | |
| 2810 | up->port.dev = dev; |
Shmulik Ladkani | b5d228c | 2009-12-09 12:31:29 -0800 | [diff] [blame] | 2811 | |
| 2812 | if (up->port.flags & UPF_FIXED_TYPE) |
| 2813 | serial8250_init_fixed_type_port(up, up->port.type); |
| 2814 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | uart_add_one_port(drv, &up->port); |
| 2816 | } |
| 2817 | } |
| 2818 | |
| 2819 | #ifdef CONFIG_SERIAL_8250_CONSOLE |
| 2820 | |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 2821 | static void serial8250_console_putchar(struct uart_port *port, int ch) |
| 2822 | { |
Jamie Iles | 49d5741 | 2010-12-01 23:39:35 +0000 | [diff] [blame] | 2823 | struct uart_8250_port *up = |
| 2824 | container_of(port, struct uart_8250_port, port); |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 2825 | |
| 2826 | wait_for_xmitr(up, UART_LSR_THRE); |
| 2827 | serial_out(up, UART_TX, ch); |
| 2828 | } |
| 2829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | /* |
| 2831 | * Print a string to the serial port trying not to disturb |
| 2832 | * any possible real use of the port... |
| 2833 | * |
| 2834 | * The console_lock must be held when we get here. |
| 2835 | */ |
| 2836 | static void |
| 2837 | serial8250_console_write(struct console *co, const char *s, unsigned int count) |
| 2838 | { |
| 2839 | struct uart_8250_port *up = &serial8250_ports[co->index]; |
Russell King | d8a5a8d | 2006-05-02 16:04:29 +0100 | [diff] [blame] | 2840 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | unsigned int ier; |
Russell King | d8a5a8d | 2006-05-02 16:04:29 +0100 | [diff] [blame] | 2842 | int locked = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | |
Andrew Morton | 78512ec | 2005-11-07 00:59:13 -0800 | [diff] [blame] | 2844 | touch_nmi_watchdog(); |
| 2845 | |
Andrew Morton | 68aa2c0 | 2006-06-30 02:29:59 -0700 | [diff] [blame] | 2846 | local_irq_save(flags); |
| 2847 | if (up->port.sysrq) { |
| 2848 | /* serial8250_handle_port() already took the lock */ |
| 2849 | locked = 0; |
| 2850 | } else if (oops_in_progress) { |
| 2851 | locked = spin_trylock(&up->port.lock); |
Russell King | d8a5a8d | 2006-05-02 16:04:29 +0100 | [diff] [blame] | 2852 | } else |
Andrew Morton | 68aa2c0 | 2006-06-30 02:29:59 -0700 | [diff] [blame] | 2853 | spin_lock(&up->port.lock); |
Russell King | d8a5a8d | 2006-05-02 16:04:29 +0100 | [diff] [blame] | 2854 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | /* |
Ralf Baechle | dc7bf13 | 2006-02-15 09:59:47 +0000 | [diff] [blame] | 2856 | * First save the IER then disable the interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | */ |
| 2858 | ier = serial_in(up, UART_IER); |
| 2859 | |
| 2860 | if (up->capabilities & UART_CAP_UUE) |
| 2861 | serial_out(up, UART_IER, UART_IER_UUE); |
| 2862 | else |
| 2863 | serial_out(up, UART_IER, 0); |
| 2864 | |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 2865 | uart_console_write(&up->port, s, count, serial8250_console_putchar); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | |
| 2867 | /* |
| 2868 | * Finally, wait for transmitter to become empty |
| 2869 | * and restore the IER |
| 2870 | */ |
Alan Cox | f91a371 | 2006-01-21 14:59:12 +0000 | [diff] [blame] | 2871 | wait_for_xmitr(up, BOTH_EMPTY); |
Russell King | a88d75b | 2006-04-30 11:30:15 +0100 | [diff] [blame] | 2872 | serial_out(up, UART_IER, ier); |
Russell King | d8a5a8d | 2006-05-02 16:04:29 +0100 | [diff] [blame] | 2873 | |
Corey Minyard | ad4c2aa | 2007-08-22 14:01:18 -0700 | [diff] [blame] | 2874 | /* |
| 2875 | * The receive handling will happen properly because the |
| 2876 | * receive ready bit will still be set; it is not cleared |
| 2877 | * on read. However, modem control will not, we must |
| 2878 | * call it if we have saved something in the saved flags |
| 2879 | * while processing with interrupts off. |
| 2880 | */ |
| 2881 | if (up->msr_saved_flags) |
| 2882 | check_modem_status(up); |
| 2883 | |
Russell King | d8a5a8d | 2006-05-02 16:04:29 +0100 | [diff] [blame] | 2884 | if (locked) |
Andrew Morton | 68aa2c0 | 2006-06-30 02:29:59 -0700 | [diff] [blame] | 2885 | spin_unlock(&up->port.lock); |
| 2886 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | } |
| 2888 | |
Vivek Goyal | 118c0ac | 2007-01-11 01:52:44 +0100 | [diff] [blame] | 2889 | static int __init serial8250_console_setup(struct console *co, char *options) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | { |
| 2891 | struct uart_port *port; |
| 2892 | int baud = 9600; |
| 2893 | int bits = 8; |
| 2894 | int parity = 'n'; |
| 2895 | int flow = 'n'; |
| 2896 | |
| 2897 | /* |
| 2898 | * Check whether an invalid uart number has been specified, and |
| 2899 | * if so, search for the first available port that does have |
| 2900 | * console support. |
| 2901 | */ |
Dave Jones | a61c2d7 | 2006-01-07 23:18:19 +0000 | [diff] [blame] | 2902 | if (co->index >= nr_uarts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | co->index = 0; |
| 2904 | port = &serial8250_ports[co->index].port; |
| 2905 | if (!port->iobase && !port->membase) |
| 2906 | return -ENODEV; |
| 2907 | |
| 2908 | if (options) |
| 2909 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 2910 | |
| 2911 | return uart_set_options(port, co, baud, parity, bits, flow); |
| 2912 | } |
| 2913 | |
Daniel Ritz | b6b1d87 | 2007-08-03 16:07:43 +0200 | [diff] [blame] | 2914 | static int serial8250_console_early_setup(void) |
Yinghai Lu | 18a8bd9 | 2007-07-15 23:37:59 -0700 | [diff] [blame] | 2915 | { |
| 2916 | return serial8250_find_port_for_earlycon(); |
| 2917 | } |
| 2918 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | static struct console serial8250_console = { |
| 2920 | .name = "ttyS", |
| 2921 | .write = serial8250_console_write, |
| 2922 | .device = uart_console_device, |
| 2923 | .setup = serial8250_console_setup, |
Yinghai Lu | 18a8bd9 | 2007-07-15 23:37:59 -0700 | [diff] [blame] | 2924 | .early_setup = serial8250_console_early_setup, |
Peter Zijlstra | a80c49d | 2010-11-15 21:11:12 +0100 | [diff] [blame] | 2925 | .flags = CON_PRINTBUFFER | CON_ANYTIME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | .index = -1, |
| 2927 | .data = &serial8250_reg, |
| 2928 | }; |
| 2929 | |
| 2930 | static int __init serial8250_console_init(void) |
| 2931 | { |
Eric W. Biederman | 05d81d2 | 2008-07-12 13:47:53 -0700 | [diff] [blame] | 2932 | if (nr_uarts > UART_NR) |
| 2933 | nr_uarts = UART_NR; |
| 2934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | serial8250_isa_init_ports(); |
| 2936 | register_console(&serial8250_console); |
| 2937 | return 0; |
| 2938 | } |
| 2939 | console_initcall(serial8250_console_init); |
| 2940 | |
Yinghai Lu | 18a8bd9 | 2007-07-15 23:37:59 -0700 | [diff] [blame] | 2941 | int serial8250_find_port(struct uart_port *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | { |
| 2943 | int line; |
| 2944 | struct uart_port *port; |
| 2945 | |
Dave Jones | a61c2d7 | 2006-01-07 23:18:19 +0000 | [diff] [blame] | 2946 | for (line = 0; line < nr_uarts; line++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | port = &serial8250_ports[line].port; |
Russell King | 50aec3b5 | 2006-01-04 18:13:03 +0000 | [diff] [blame] | 2948 | if (uart_match_port(p, port)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | return line; |
| 2950 | } |
| 2951 | return -ENODEV; |
| 2952 | } |
| 2953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2954 | #define SERIAL8250_CONSOLE &serial8250_console |
| 2955 | #else |
| 2956 | #define SERIAL8250_CONSOLE NULL |
| 2957 | #endif |
| 2958 | |
| 2959 | static struct uart_driver serial8250_reg = { |
| 2960 | .owner = THIS_MODULE, |
| 2961 | .driver_name = "serial", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | .dev_name = "ttyS", |
| 2963 | .major = TTY_MAJOR, |
| 2964 | .minor = 64, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | .cons = SERIAL8250_CONSOLE, |
| 2966 | }; |
| 2967 | |
Russell King | d856c66 | 2006-02-23 10:22:13 +0000 | [diff] [blame] | 2968 | /* |
| 2969 | * early_serial_setup - early registration for 8250 ports |
| 2970 | * |
| 2971 | * Setup an 8250 port structure prior to console initialisation. Use |
| 2972 | * after console initialisation will cause undefined behaviour. |
| 2973 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | int __init early_serial_setup(struct uart_port *port) |
| 2975 | { |
David Daney | b430428 | 2009-01-02 13:49:41 +0000 | [diff] [blame] | 2976 | struct uart_port *p; |
| 2977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | if (port->line >= ARRAY_SIZE(serial8250_ports)) |
| 2979 | return -ENODEV; |
| 2980 | |
| 2981 | serial8250_isa_init_ports(); |
David Daney | b430428 | 2009-01-02 13:49:41 +0000 | [diff] [blame] | 2982 | p = &serial8250_ports[port->line].port; |
| 2983 | p->iobase = port->iobase; |
| 2984 | p->membase = port->membase; |
| 2985 | p->irq = port->irq; |
Vikram Pandita | 1c2f049 | 2009-09-19 13:13:19 -0700 | [diff] [blame] | 2986 | p->irqflags = port->irqflags; |
David Daney | b430428 | 2009-01-02 13:49:41 +0000 | [diff] [blame] | 2987 | p->uartclk = port->uartclk; |
| 2988 | p->fifosize = port->fifosize; |
| 2989 | p->regshift = port->regshift; |
| 2990 | p->iotype = port->iotype; |
| 2991 | p->flags = port->flags; |
| 2992 | p->mapbase = port->mapbase; |
| 2993 | p->private_data = port->private_data; |
Helge Deller | 125c97d | 2009-01-13 22:51:07 +0100 | [diff] [blame] | 2994 | p->type = port->type; |
| 2995 | p->line = port->line; |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 2996 | |
| 2997 | set_io_from_upio(p); |
| 2998 | if (port->serial_in) |
| 2999 | p->serial_in = port->serial_in; |
| 3000 | if (port->serial_out) |
| 3001 | p->serial_out = port->serial_out; |
| 3002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | return 0; |
| 3004 | } |
| 3005 | |
| 3006 | /** |
| 3007 | * serial8250_suspend_port - suspend one serial port |
| 3008 | * @line: serial line number |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | * |
| 3010 | * Suspend one serial port. |
| 3011 | */ |
| 3012 | void serial8250_suspend_port(int line) |
| 3013 | { |
| 3014 | uart_suspend_port(&serial8250_reg, &serial8250_ports[line].port); |
| 3015 | } |
| 3016 | |
| 3017 | /** |
| 3018 | * serial8250_resume_port - resume one serial port |
| 3019 | * @line: serial line number |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | * |
| 3021 | * Resume one serial port. |
| 3022 | */ |
| 3023 | void serial8250_resume_port(int line) |
| 3024 | { |
David Woodhouse | b5b82df | 2007-05-17 14:27:39 +0800 | [diff] [blame] | 3025 | struct uart_8250_port *up = &serial8250_ports[line]; |
| 3026 | |
| 3027 | if (up->capabilities & UART_NATSEMI) { |
| 3028 | unsigned char tmp; |
| 3029 | |
| 3030 | /* Ensure it's still in high speed mode */ |
| 3031 | serial_outp(up, UART_LCR, 0xE0); |
| 3032 | |
| 3033 | tmp = serial_in(up, 0x04); /* EXCR2 */ |
| 3034 | tmp &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */ |
| 3035 | tmp |= 0x10; /* 1.625 divisor for baud_base --> 921600 */ |
| 3036 | serial_outp(up, 0x04, tmp); |
| 3037 | |
| 3038 | serial_outp(up, UART_LCR, 0); |
Yin Kangkai | 95926d2 | 2011-02-09 11:34:20 +0800 | [diff] [blame^] | 3039 | up->port.uartclk = 921600*16; |
David Woodhouse | b5b82df | 2007-05-17 14:27:39 +0800 | [diff] [blame] | 3040 | } |
| 3041 | uart_resume_port(&serial8250_reg, &up->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | } |
| 3043 | |
| 3044 | /* |
| 3045 | * Register a set of serial devices attached to a platform device. The |
| 3046 | * list is terminated with a zero flags entry, which means we expect |
| 3047 | * all entries to have at least UPF_BOOT_AUTOCONF set. |
| 3048 | */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3049 | static int __devinit serial8250_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3051 | struct plat_serial8250_port *p = dev->dev.platform_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | struct uart_port port; |
André Goddard Rosa | 4c0ebb8 | 2009-10-25 12:01:34 -0200 | [diff] [blame] | 3053 | int ret, i, irqflag = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | |
| 3055 | memset(&port, 0, sizeof(struct uart_port)); |
| 3056 | |
André Goddard Rosa | 4c0ebb8 | 2009-10-25 12:01:34 -0200 | [diff] [blame] | 3057 | if (share_irqs) |
| 3058 | irqflag = IRQF_SHARED; |
| 3059 | |
Russell King | ec9f47c | 2005-06-27 11:12:54 +0100 | [diff] [blame] | 3060 | for (i = 0; p && p->flags != 0; p++, i++) { |
Will Newton | 74a19741 | 2008-02-04 22:27:50 -0800 | [diff] [blame] | 3061 | port.iobase = p->iobase; |
| 3062 | port.membase = p->membase; |
| 3063 | port.irq = p->irq; |
Vikram Pandita | 1c2f049 | 2009-09-19 13:13:19 -0700 | [diff] [blame] | 3064 | port.irqflags = p->irqflags; |
Will Newton | 74a19741 | 2008-02-04 22:27:50 -0800 | [diff] [blame] | 3065 | port.uartclk = p->uartclk; |
| 3066 | port.regshift = p->regshift; |
| 3067 | port.iotype = p->iotype; |
| 3068 | port.flags = p->flags; |
| 3069 | port.mapbase = p->mapbase; |
| 3070 | port.hub6 = p->hub6; |
| 3071 | port.private_data = p->private_data; |
David Daney | 8e23fcc | 2009-01-02 13:49:54 +0000 | [diff] [blame] | 3072 | port.type = p->type; |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 3073 | port.serial_in = p->serial_in; |
| 3074 | port.serial_out = p->serial_out; |
Philippe Langlais | 235dae5 | 2010-07-29 17:13:57 +0200 | [diff] [blame] | 3075 | port.set_termios = p->set_termios; |
Manuel Lauss | c161afe | 2010-09-25 15:13:45 +0200 | [diff] [blame] | 3076 | port.pm = p->pm; |
Will Newton | 74a19741 | 2008-02-04 22:27:50 -0800 | [diff] [blame] | 3077 | port.dev = &dev->dev; |
André Goddard Rosa | 4c0ebb8 | 2009-10-25 12:01:34 -0200 | [diff] [blame] | 3078 | port.irqflags |= irqflag; |
Russell King | ec9f47c | 2005-06-27 11:12:54 +0100 | [diff] [blame] | 3079 | ret = serial8250_register_port(&port); |
| 3080 | if (ret < 0) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3081 | dev_err(&dev->dev, "unable to register port at index %d " |
Josh Boyer | 4f640ef | 2007-07-23 18:43:44 -0700 | [diff] [blame] | 3082 | "(IO%lx MEM%llx IRQ%d): %d\n", i, |
| 3083 | p->iobase, (unsigned long long)p->mapbase, |
| 3084 | p->irq, ret); |
Russell King | ec9f47c | 2005-06-27 11:12:54 +0100 | [diff] [blame] | 3085 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | } |
| 3087 | return 0; |
| 3088 | } |
| 3089 | |
| 3090 | /* |
| 3091 | * Remove serial ports registered against a platform device. |
| 3092 | */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3093 | static int __devexit serial8250_remove(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | { |
| 3095 | int i; |
| 3096 | |
Dave Jones | a61c2d7 | 2006-01-07 23:18:19 +0000 | [diff] [blame] | 3097 | for (i = 0; i < nr_uarts; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | struct uart_8250_port *up = &serial8250_ports[i]; |
| 3099 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3100 | if (up->port.dev == &dev->dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | serial8250_unregister_port(i); |
| 3102 | } |
| 3103 | return 0; |
| 3104 | } |
| 3105 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3106 | static int serial8250_suspend(struct platform_device *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | { |
| 3108 | int i; |
| 3109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | for (i = 0; i < UART_NR; i++) { |
| 3111 | struct uart_8250_port *up = &serial8250_ports[i]; |
| 3112 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3113 | if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | uart_suspend_port(&serial8250_reg, &up->port); |
| 3115 | } |
| 3116 | |
| 3117 | return 0; |
| 3118 | } |
| 3119 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3120 | static int serial8250_resume(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | { |
| 3122 | int i; |
| 3123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | for (i = 0; i < UART_NR; i++) { |
| 3125 | struct uart_8250_port *up = &serial8250_ports[i]; |
| 3126 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3127 | if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev) |
David Woodhouse | b5b82df | 2007-05-17 14:27:39 +0800 | [diff] [blame] | 3128 | serial8250_resume_port(i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | } |
| 3130 | |
| 3131 | return 0; |
| 3132 | } |
| 3133 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3134 | static struct platform_driver serial8250_isa_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3135 | .probe = serial8250_probe, |
| 3136 | .remove = __devexit_p(serial8250_remove), |
| 3137 | .suspend = serial8250_suspend, |
| 3138 | .resume = serial8250_resume, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3139 | .driver = { |
| 3140 | .name = "serial8250", |
Dmitry Torokhov | 7493a31 | 2006-01-13 22:06:43 +0000 | [diff] [blame] | 3141 | .owner = THIS_MODULE, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3142 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | }; |
| 3144 | |
| 3145 | /* |
| 3146 | * This "device" covers _all_ ISA 8250-compatible serial devices listed |
| 3147 | * in the table in include/asm/serial.h |
| 3148 | */ |
| 3149 | static struct platform_device *serial8250_isa_devs; |
| 3150 | |
| 3151 | /* |
| 3152 | * serial8250_register_port and serial8250_unregister_port allows for |
| 3153 | * 16x50 serial ports to be configured at run-time, to support PCMCIA |
| 3154 | * modems and PCI multiport cards. |
| 3155 | */ |
Arjan van de Ven | f392ecf | 2006-01-12 18:44:32 +0000 | [diff] [blame] | 3156 | static DEFINE_MUTEX(serial_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | |
| 3158 | static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port *port) |
| 3159 | { |
| 3160 | int i; |
| 3161 | |
| 3162 | /* |
| 3163 | * First, find a port entry which matches. |
| 3164 | */ |
Dave Jones | a61c2d7 | 2006-01-07 23:18:19 +0000 | [diff] [blame] | 3165 | for (i = 0; i < nr_uarts; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | if (uart_match_port(&serial8250_ports[i].port, port)) |
| 3167 | return &serial8250_ports[i]; |
| 3168 | |
| 3169 | /* |
| 3170 | * We didn't find a matching entry, so look for the first |
| 3171 | * free entry. We look for one which hasn't been previously |
| 3172 | * used (indicated by zero iobase). |
| 3173 | */ |
Dave Jones | a61c2d7 | 2006-01-07 23:18:19 +0000 | [diff] [blame] | 3174 | for (i = 0; i < nr_uarts; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | if (serial8250_ports[i].port.type == PORT_UNKNOWN && |
| 3176 | serial8250_ports[i].port.iobase == 0) |
| 3177 | return &serial8250_ports[i]; |
| 3178 | |
| 3179 | /* |
| 3180 | * That also failed. Last resort is to find any entry which |
| 3181 | * doesn't have a real port associated with it. |
| 3182 | */ |
Dave Jones | a61c2d7 | 2006-01-07 23:18:19 +0000 | [diff] [blame] | 3183 | for (i = 0; i < nr_uarts; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | if (serial8250_ports[i].port.type == PORT_UNKNOWN) |
| 3185 | return &serial8250_ports[i]; |
| 3186 | |
| 3187 | return NULL; |
| 3188 | } |
| 3189 | |
| 3190 | /** |
| 3191 | * serial8250_register_port - register a serial port |
| 3192 | * @port: serial port template |
| 3193 | * |
| 3194 | * Configure the serial port specified by the request. If the |
| 3195 | * port exists and is in use, it is hung up and unregistered |
| 3196 | * first. |
| 3197 | * |
| 3198 | * The port is then probed and if necessary the IRQ is autodetected |
| 3199 | * If this fails an error is returned. |
| 3200 | * |
| 3201 | * On success the port is ready to use and the line number is returned. |
| 3202 | */ |
| 3203 | int serial8250_register_port(struct uart_port *port) |
| 3204 | { |
| 3205 | struct uart_8250_port *uart; |
| 3206 | int ret = -ENOSPC; |
| 3207 | |
| 3208 | if (port->uartclk == 0) |
| 3209 | return -EINVAL; |
| 3210 | |
Arjan van de Ven | f392ecf | 2006-01-12 18:44:32 +0000 | [diff] [blame] | 3211 | mutex_lock(&serial_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | |
| 3213 | uart = serial8250_find_match_or_unused(port); |
| 3214 | if (uart) { |
| 3215 | uart_remove_one_port(&serial8250_reg, &uart->port); |
| 3216 | |
Will Newton | 74a19741 | 2008-02-04 22:27:50 -0800 | [diff] [blame] | 3217 | uart->port.iobase = port->iobase; |
| 3218 | uart->port.membase = port->membase; |
| 3219 | uart->port.irq = port->irq; |
Vikram Pandita | 1c2f049 | 2009-09-19 13:13:19 -0700 | [diff] [blame] | 3220 | uart->port.irqflags = port->irqflags; |
Will Newton | 74a19741 | 2008-02-04 22:27:50 -0800 | [diff] [blame] | 3221 | uart->port.uartclk = port->uartclk; |
| 3222 | uart->port.fifosize = port->fifosize; |
| 3223 | uart->port.regshift = port->regshift; |
| 3224 | uart->port.iotype = port->iotype; |
| 3225 | uart->port.flags = port->flags | UPF_BOOT_AUTOCONF; |
| 3226 | uart->port.mapbase = port->mapbase; |
| 3227 | uart->port.private_data = port->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | if (port->dev) |
| 3229 | uart->port.dev = port->dev; |
David Daney | 8e23fcc | 2009-01-02 13:49:54 +0000 | [diff] [blame] | 3230 | |
Shmulik Ladkani | b5d228c | 2009-12-09 12:31:29 -0800 | [diff] [blame] | 3231 | if (port->flags & UPF_FIXED_TYPE) |
| 3232 | serial8250_init_fixed_type_port(uart, port->type); |
David Daney | 8e23fcc | 2009-01-02 13:49:54 +0000 | [diff] [blame] | 3233 | |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 3234 | set_io_from_upio(&uart->port); |
| 3235 | /* Possibly override default I/O functions. */ |
| 3236 | if (port->serial_in) |
| 3237 | uart->port.serial_in = port->serial_in; |
| 3238 | if (port->serial_out) |
| 3239 | uart->port.serial_out = port->serial_out; |
Philippe Langlais | 235dae5 | 2010-07-29 17:13:57 +0200 | [diff] [blame] | 3240 | /* Possibly override set_termios call */ |
| 3241 | if (port->set_termios) |
| 3242 | uart->port.set_termios = port->set_termios; |
Manuel Lauss | c161afe | 2010-09-25 15:13:45 +0200 | [diff] [blame] | 3243 | if (port->pm) |
| 3244 | uart->port.pm = port->pm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | |
Alan Cox | af7f374 | 2010-10-18 11:38:02 -0700 | [diff] [blame] | 3246 | if (serial8250_isa_config != NULL) |
| 3247 | serial8250_isa_config(0, &uart->port, |
| 3248 | &uart->capabilities); |
| 3249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | ret = uart_add_one_port(&serial8250_reg, &uart->port); |
| 3251 | if (ret == 0) |
| 3252 | ret = uart->port.line; |
| 3253 | } |
Arjan van de Ven | f392ecf | 2006-01-12 18:44:32 +0000 | [diff] [blame] | 3254 | mutex_unlock(&serial_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | |
| 3256 | return ret; |
| 3257 | } |
| 3258 | EXPORT_SYMBOL(serial8250_register_port); |
| 3259 | |
| 3260 | /** |
| 3261 | * serial8250_unregister_port - remove a 16x50 serial port at runtime |
| 3262 | * @line: serial line number |
| 3263 | * |
| 3264 | * Remove one serial port. This may not be called from interrupt |
| 3265 | * context. We hand the port back to the our control. |
| 3266 | */ |
| 3267 | void serial8250_unregister_port(int line) |
| 3268 | { |
| 3269 | struct uart_8250_port *uart = &serial8250_ports[line]; |
| 3270 | |
Arjan van de Ven | f392ecf | 2006-01-12 18:44:32 +0000 | [diff] [blame] | 3271 | mutex_lock(&serial_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | uart_remove_one_port(&serial8250_reg, &uart->port); |
| 3273 | if (serial8250_isa_devs) { |
| 3274 | uart->port.flags &= ~UPF_BOOT_AUTOCONF; |
| 3275 | uart->port.type = PORT_UNKNOWN; |
| 3276 | uart->port.dev = &serial8250_isa_devs->dev; |
| 3277 | uart_add_one_port(&serial8250_reg, &uart->port); |
| 3278 | } else { |
| 3279 | uart->port.dev = NULL; |
| 3280 | } |
Arjan van de Ven | f392ecf | 2006-01-12 18:44:32 +0000 | [diff] [blame] | 3281 | mutex_unlock(&serial_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | } |
| 3283 | EXPORT_SYMBOL(serial8250_unregister_port); |
| 3284 | |
| 3285 | static int __init serial8250_init(void) |
| 3286 | { |
Alan Cox | 25db8ad | 2008-08-19 20:49:40 -0700 | [diff] [blame] | 3287 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | |
Dave Jones | a61c2d7 | 2006-01-07 23:18:19 +0000 | [diff] [blame] | 3289 | if (nr_uarts > UART_NR) |
| 3290 | nr_uarts = UART_NR; |
| 3291 | |
Paul Bolle | f1fb9bb | 2008-12-30 14:06:43 +0100 | [diff] [blame] | 3292 | printk(KERN_INFO "Serial: 8250/16550 driver, " |
Dave Jones | a61c2d7 | 2006-01-07 23:18:19 +0000 | [diff] [blame] | 3293 | "%d ports, IRQ sharing %sabled\n", nr_uarts, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | share_irqs ? "en" : "dis"); |
| 3295 | |
David Miller | b70ac77 | 2008-10-13 10:36:31 +0100 | [diff] [blame] | 3296 | #ifdef CONFIG_SPARC |
| 3297 | ret = sunserial_register_minors(&serial8250_reg, UART_NR); |
| 3298 | #else |
| 3299 | serial8250_reg.nr = UART_NR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | ret = uart_register_driver(&serial8250_reg); |
David Miller | b70ac77 | 2008-10-13 10:36:31 +0100 | [diff] [blame] | 3301 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | if (ret) |
| 3303 | goto out; |
| 3304 | |
Dmitry Torokhov | 7493a31 | 2006-01-13 22:06:43 +0000 | [diff] [blame] | 3305 | serial8250_isa_devs = platform_device_alloc("serial8250", |
| 3306 | PLAT8250_DEV_LEGACY); |
| 3307 | if (!serial8250_isa_devs) { |
| 3308 | ret = -ENOMEM; |
Russell King | bc965a7 | 2006-01-18 09:54:29 +0000 | [diff] [blame] | 3309 | goto unreg_uart_drv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | } |
| 3311 | |
Dmitry Torokhov | 7493a31 | 2006-01-13 22:06:43 +0000 | [diff] [blame] | 3312 | ret = platform_device_add(serial8250_isa_devs); |
| 3313 | if (ret) |
| 3314 | goto put_dev; |
| 3315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | serial8250_register_ports(&serial8250_reg, &serial8250_isa_devs->dev); |
| 3317 | |
Russell King | bc965a7 | 2006-01-18 09:54:29 +0000 | [diff] [blame] | 3318 | ret = platform_driver_register(&serial8250_isa_driver); |
| 3319 | if (ret == 0) |
| 3320 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | |
Russell King | bc965a7 | 2006-01-18 09:54:29 +0000 | [diff] [blame] | 3322 | platform_device_del(serial8250_isa_devs); |
Alan Cox | 25db8ad | 2008-08-19 20:49:40 -0700 | [diff] [blame] | 3323 | put_dev: |
Dmitry Torokhov | 7493a31 | 2006-01-13 22:06:43 +0000 | [diff] [blame] | 3324 | platform_device_put(serial8250_isa_devs); |
Alan Cox | 25db8ad | 2008-08-19 20:49:40 -0700 | [diff] [blame] | 3325 | unreg_uart_drv: |
David Miller | b70ac77 | 2008-10-13 10:36:31 +0100 | [diff] [blame] | 3326 | #ifdef CONFIG_SPARC |
| 3327 | sunserial_unregister_minors(&serial8250_reg, UART_NR); |
| 3328 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3329 | uart_unregister_driver(&serial8250_reg); |
David Miller | b70ac77 | 2008-10-13 10:36:31 +0100 | [diff] [blame] | 3330 | #endif |
Alan Cox | 25db8ad | 2008-08-19 20:49:40 -0700 | [diff] [blame] | 3331 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | return ret; |
| 3333 | } |
| 3334 | |
| 3335 | static void __exit serial8250_exit(void) |
| 3336 | { |
| 3337 | struct platform_device *isa_dev = serial8250_isa_devs; |
| 3338 | |
| 3339 | /* |
| 3340 | * This tells serial8250_unregister_port() not to re-register |
| 3341 | * the ports (thereby making serial8250_isa_driver permanently |
| 3342 | * in use.) |
| 3343 | */ |
| 3344 | serial8250_isa_devs = NULL; |
| 3345 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3346 | platform_driver_unregister(&serial8250_isa_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | platform_device_unregister(isa_dev); |
| 3348 | |
David Miller | b70ac77 | 2008-10-13 10:36:31 +0100 | [diff] [blame] | 3349 | #ifdef CONFIG_SPARC |
| 3350 | sunserial_unregister_minors(&serial8250_reg, UART_NR); |
| 3351 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | uart_unregister_driver(&serial8250_reg); |
David Miller | b70ac77 | 2008-10-13 10:36:31 +0100 | [diff] [blame] | 3353 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | module_init(serial8250_init); |
| 3357 | module_exit(serial8250_exit); |
| 3358 | |
| 3359 | EXPORT_SYMBOL(serial8250_suspend_port); |
| 3360 | EXPORT_SYMBOL(serial8250_resume_port); |
| 3361 | |
| 3362 | MODULE_LICENSE("GPL"); |
Adrian Bunk | d87a6d9 | 2008-07-16 21:53:31 +0100 | [diff] [blame] | 3363 | MODULE_DESCRIPTION("Generic 8250/16x50 serial driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | |
| 3365 | module_param(share_irqs, uint, 0644); |
| 3366 | MODULE_PARM_DESC(share_irqs, "Share IRQs with other non-8250/16x50 devices" |
| 3367 | " (unsafe)"); |
| 3368 | |
Dave Jones | a61c2d7 | 2006-01-07 23:18:19 +0000 | [diff] [blame] | 3369 | module_param(nr_uarts, uint, 0644); |
| 3370 | MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")"); |
| 3371 | |
Chuck Ebbert | d41a4b5 | 2009-10-01 15:44:26 -0700 | [diff] [blame] | 3372 | module_param(skip_txen_test, uint, 0644); |
| 3373 | MODULE_PARM_DESC(skip_txen_test, "Skip checking for the TXEN bug at init time"); |
| 3374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | #ifdef CONFIG_SERIAL_8250_RSA |
| 3376 | module_param_array(probe_rsa, ulong, &probe_rsa_count, 0444); |
| 3377 | MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA"); |
| 3378 | #endif |
| 3379 | MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR); |