Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/mmc/card/sdio_uart.c - SDIO UART/GPS driver |
| 3 | * |
| 4 | * Based on drivers/serial/8250.c and drivers/serial/serial_core.c |
| 5 | * by Russell King. |
| 6 | * |
| 7 | * Author: Nicolas Pitre |
| 8 | * Created: June 15, 2007 |
| 9 | * Copyright: MontaVista Software, Inc. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or (at |
| 14 | * your option) any later version. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * Note: Although this driver assumes a 16550A-like UART implementation, |
| 19 | * it is not possible to leverage the common 8250/16550 driver, nor the |
| 20 | * core UART infrastructure, as they assumes direct access to the hardware |
| 21 | * registers, often under a spinlock. This is not possible in the SDIO |
| 22 | * context as SDIO access functions must be able to sleep. |
| 23 | * |
| 24 | * Because we need to lock the SDIO host to ensure an exclusive access to |
| 25 | * the card, we simply rely on that lock to also prevent and serialize |
| 26 | * concurrent access to the same port. |
| 27 | */ |
| 28 | |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/kernel.h> |
Alan Cox | 4b3b49b | 2009-11-30 13:16:36 +0000 | [diff] [blame^] | 32 | #include <linux/sched.h> |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 33 | #include <linux/mutex.h> |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 34 | #include <linux/seq_file.h> |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 35 | #include <linux/serial_reg.h> |
| 36 | #include <linux/circ_buf.h> |
| 37 | #include <linux/gfp.h> |
| 38 | #include <linux/tty.h> |
| 39 | #include <linux/tty_flip.h> |
| 40 | |
| 41 | #include <linux/mmc/core.h> |
| 42 | #include <linux/mmc/card.h> |
| 43 | #include <linux/mmc/sdio_func.h> |
| 44 | #include <linux/mmc/sdio_ids.h> |
| 45 | |
| 46 | |
| 47 | #define UART_NR 8 /* Number of UARTs this driver can handle */ |
| 48 | |
| 49 | |
| 50 | #define UART_XMIT_SIZE PAGE_SIZE |
| 51 | #define WAKEUP_CHARS 256 |
| 52 | |
| 53 | #define circ_empty(circ) ((circ)->head == (circ)->tail) |
| 54 | #define circ_clear(circ) ((circ)->head = (circ)->tail = 0) |
| 55 | |
| 56 | #define circ_chars_pending(circ) \ |
| 57 | (CIRC_CNT((circ)->head, (circ)->tail, UART_XMIT_SIZE)) |
| 58 | |
| 59 | #define circ_chars_free(circ) \ |
| 60 | (CIRC_SPACE((circ)->head, (circ)->tail, UART_XMIT_SIZE)) |
| 61 | |
| 62 | |
| 63 | struct uart_icount { |
| 64 | __u32 cts; |
| 65 | __u32 dsr; |
| 66 | __u32 rng; |
| 67 | __u32 dcd; |
| 68 | __u32 rx; |
| 69 | __u32 tx; |
| 70 | __u32 frame; |
| 71 | __u32 overrun; |
| 72 | __u32 parity; |
| 73 | __u32 brk; |
| 74 | }; |
| 75 | |
| 76 | struct sdio_uart_port { |
Alan Cox | b5849b1 | 2009-11-05 13:28:06 +0000 | [diff] [blame] | 77 | struct tty_port port; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 78 | struct kref kref; |
| 79 | struct tty_struct *tty; |
| 80 | unsigned int index; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 81 | struct sdio_func *func; |
| 82 | struct mutex func_lock; |
Nicolas Pitre | 15b82b4 | 2007-08-20 17:17:37 -0400 | [diff] [blame] | 83 | struct task_struct *in_sdio_uart_irq; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 84 | unsigned int regs_offset; |
| 85 | struct circ_buf xmit; |
| 86 | spinlock_t write_lock; |
| 87 | struct uart_icount icount; |
| 88 | unsigned int uartclk; |
| 89 | unsigned int mctrl; |
Alan Cox | 4b3b49b | 2009-11-30 13:16:36 +0000 | [diff] [blame^] | 90 | unsigned int rx_mctrl; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 91 | unsigned int read_status_mask; |
| 92 | unsigned int ignore_status_mask; |
| 93 | unsigned char x_char; |
| 94 | unsigned char ier; |
| 95 | unsigned char lcr; |
| 96 | }; |
| 97 | |
| 98 | static struct sdio_uart_port *sdio_uart_table[UART_NR]; |
| 99 | static DEFINE_SPINLOCK(sdio_uart_table_lock); |
| 100 | |
| 101 | static int sdio_uart_add_port(struct sdio_uart_port *port) |
| 102 | { |
| 103 | int index, ret = -EBUSY; |
| 104 | |
| 105 | kref_init(&port->kref); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 106 | mutex_init(&port->func_lock); |
| 107 | spin_lock_init(&port->write_lock); |
| 108 | |
| 109 | spin_lock(&sdio_uart_table_lock); |
| 110 | for (index = 0; index < UART_NR; index++) { |
| 111 | if (!sdio_uart_table[index]) { |
| 112 | port->index = index; |
| 113 | sdio_uart_table[index] = port; |
| 114 | ret = 0; |
| 115 | break; |
| 116 | } |
| 117 | } |
| 118 | spin_unlock(&sdio_uart_table_lock); |
| 119 | |
| 120 | return ret; |
| 121 | } |
| 122 | |
| 123 | static struct sdio_uart_port *sdio_uart_port_get(unsigned index) |
| 124 | { |
| 125 | struct sdio_uart_port *port; |
| 126 | |
| 127 | if (index >= UART_NR) |
| 128 | return NULL; |
| 129 | |
| 130 | spin_lock(&sdio_uart_table_lock); |
| 131 | port = sdio_uart_table[index]; |
| 132 | if (port) |
| 133 | kref_get(&port->kref); |
| 134 | spin_unlock(&sdio_uart_table_lock); |
| 135 | |
| 136 | return port; |
| 137 | } |
| 138 | |
| 139 | static void sdio_uart_port_destroy(struct kref *kref) |
| 140 | { |
| 141 | struct sdio_uart_port *port = |
| 142 | container_of(kref, struct sdio_uart_port, kref); |
| 143 | kfree(port); |
| 144 | } |
| 145 | |
| 146 | static void sdio_uart_port_put(struct sdio_uart_port *port) |
| 147 | { |
| 148 | kref_put(&port->kref, sdio_uart_port_destroy); |
| 149 | } |
| 150 | |
| 151 | static void sdio_uart_port_remove(struct sdio_uart_port *port) |
| 152 | { |
| 153 | struct sdio_func *func; |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 154 | struct tty_struct *tty; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 155 | |
| 156 | BUG_ON(sdio_uart_table[port->index] != port); |
| 157 | |
| 158 | spin_lock(&sdio_uart_table_lock); |
| 159 | sdio_uart_table[port->index] = NULL; |
| 160 | spin_unlock(&sdio_uart_table_lock); |
| 161 | |
| 162 | /* |
| 163 | * We're killing a port that potentially still is in use by |
| 164 | * the tty layer. Be careful to prevent any further access |
| 165 | * to the SDIO function and arrange for the tty layer to |
| 166 | * give up on that port ASAP. |
| 167 | * Beware: the lock ordering is critical. |
| 168 | */ |
Alan Cox | 0a68f64 | 2009-11-05 13:28:38 +0000 | [diff] [blame] | 169 | mutex_lock(&port->port.mutex); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 170 | mutex_lock(&port->func_lock); |
| 171 | func = port->func; |
| 172 | sdio_claim_host(func); |
| 173 | port->func = NULL; |
| 174 | mutex_unlock(&port->func_lock); |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 175 | tty = tty_port_tty_get(&port->port); |
| 176 | /* tty_hangup is async so is this safe as is ?? */ |
| 177 | if (tty) { |
| 178 | tty_hangup(tty); |
Alan Cox | 530646f | 2009-11-05 13:28:29 +0000 | [diff] [blame] | 179 | tty_kref_put(tty); |
| 180 | } |
Alan Cox | 0a68f64 | 2009-11-05 13:28:38 +0000 | [diff] [blame] | 181 | mutex_unlock(&port->port.mutex); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 182 | sdio_release_irq(func); |
| 183 | sdio_disable_func(func); |
| 184 | sdio_release_host(func); |
| 185 | |
| 186 | sdio_uart_port_put(port); |
| 187 | } |
| 188 | |
| 189 | static int sdio_uart_claim_func(struct sdio_uart_port *port) |
| 190 | { |
| 191 | mutex_lock(&port->func_lock); |
| 192 | if (unlikely(!port->func)) { |
| 193 | mutex_unlock(&port->func_lock); |
| 194 | return -ENODEV; |
| 195 | } |
Nicolas Pitre | 15b82b4 | 2007-08-20 17:17:37 -0400 | [diff] [blame] | 196 | if (likely(port->in_sdio_uart_irq != current)) |
| 197 | sdio_claim_host(port->func); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 198 | mutex_unlock(&port->func_lock); |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | static inline void sdio_uart_release_func(struct sdio_uart_port *port) |
| 203 | { |
Nicolas Pitre | 15b82b4 | 2007-08-20 17:17:37 -0400 | [diff] [blame] | 204 | if (likely(port->in_sdio_uart_irq != current)) |
| 205 | sdio_release_host(port->func); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static inline unsigned int sdio_in(struct sdio_uart_port *port, int offset) |
| 209 | { |
| 210 | unsigned char c; |
| 211 | c = sdio_readb(port->func, port->regs_offset + offset, NULL); |
| 212 | return c; |
| 213 | } |
| 214 | |
| 215 | static inline void sdio_out(struct sdio_uart_port *port, int offset, int value) |
| 216 | { |
| 217 | sdio_writeb(port->func, value, port->regs_offset + offset, NULL); |
| 218 | } |
| 219 | |
| 220 | static unsigned int sdio_uart_get_mctrl(struct sdio_uart_port *port) |
| 221 | { |
| 222 | unsigned char status; |
| 223 | unsigned int ret; |
| 224 | |
Alan Cox | 4b3b49b | 2009-11-30 13:16:36 +0000 | [diff] [blame^] | 225 | /* FIXME: What stops this losing the delta bits and breaking |
| 226 | sdio_uart_check_modem_status ? */ |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 227 | status = sdio_in(port, UART_MSR); |
| 228 | |
| 229 | ret = 0; |
| 230 | if (status & UART_MSR_DCD) |
| 231 | ret |= TIOCM_CAR; |
| 232 | if (status & UART_MSR_RI) |
| 233 | ret |= TIOCM_RNG; |
| 234 | if (status & UART_MSR_DSR) |
| 235 | ret |= TIOCM_DSR; |
| 236 | if (status & UART_MSR_CTS) |
| 237 | ret |= TIOCM_CTS; |
| 238 | return ret; |
| 239 | } |
| 240 | |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 241 | static void sdio_uart_write_mctrl(struct sdio_uart_port *port, |
| 242 | unsigned int mctrl) |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 243 | { |
| 244 | unsigned char mcr = 0; |
| 245 | |
| 246 | if (mctrl & TIOCM_RTS) |
| 247 | mcr |= UART_MCR_RTS; |
| 248 | if (mctrl & TIOCM_DTR) |
| 249 | mcr |= UART_MCR_DTR; |
| 250 | if (mctrl & TIOCM_OUT1) |
| 251 | mcr |= UART_MCR_OUT1; |
| 252 | if (mctrl & TIOCM_OUT2) |
| 253 | mcr |= UART_MCR_OUT2; |
| 254 | if (mctrl & TIOCM_LOOP) |
| 255 | mcr |= UART_MCR_LOOP; |
| 256 | |
| 257 | sdio_out(port, UART_MCR, mcr); |
| 258 | } |
| 259 | |
| 260 | static inline void sdio_uart_update_mctrl(struct sdio_uart_port *port, |
| 261 | unsigned int set, unsigned int clear) |
| 262 | { |
| 263 | unsigned int old; |
| 264 | |
| 265 | old = port->mctrl; |
| 266 | port->mctrl = (old & ~clear) | set; |
| 267 | if (old != port->mctrl) |
| 268 | sdio_uart_write_mctrl(port, port->mctrl); |
| 269 | } |
| 270 | |
| 271 | #define sdio_uart_set_mctrl(port, x) sdio_uart_update_mctrl(port, x, 0) |
| 272 | #define sdio_uart_clear_mctrl(port, x) sdio_uart_update_mctrl(port, 0, x) |
| 273 | |
| 274 | static void sdio_uart_change_speed(struct sdio_uart_port *port, |
| 275 | struct ktermios *termios, |
| 276 | struct ktermios *old) |
| 277 | { |
| 278 | unsigned char cval, fcr = 0; |
| 279 | unsigned int baud, quot; |
| 280 | |
| 281 | switch (termios->c_cflag & CSIZE) { |
| 282 | case CS5: |
| 283 | cval = UART_LCR_WLEN5; |
| 284 | break; |
| 285 | case CS6: |
| 286 | cval = UART_LCR_WLEN6; |
| 287 | break; |
| 288 | case CS7: |
| 289 | cval = UART_LCR_WLEN7; |
| 290 | break; |
| 291 | default: |
| 292 | case CS8: |
| 293 | cval = UART_LCR_WLEN8; |
| 294 | break; |
| 295 | } |
| 296 | |
| 297 | if (termios->c_cflag & CSTOPB) |
| 298 | cval |= UART_LCR_STOP; |
| 299 | if (termios->c_cflag & PARENB) |
| 300 | cval |= UART_LCR_PARITY; |
| 301 | if (!(termios->c_cflag & PARODD)) |
| 302 | cval |= UART_LCR_EPAR; |
| 303 | |
| 304 | for (;;) { |
| 305 | baud = tty_termios_baud_rate(termios); |
| 306 | if (baud == 0) |
| 307 | baud = 9600; /* Special case: B0 rate. */ |
| 308 | if (baud <= port->uartclk) |
| 309 | break; |
| 310 | /* |
| 311 | * Oops, the quotient was zero. Try again with the old |
| 312 | * baud rate if possible, otherwise default to 9600. |
| 313 | */ |
| 314 | termios->c_cflag &= ~CBAUD; |
| 315 | if (old) { |
| 316 | termios->c_cflag |= old->c_cflag & CBAUD; |
| 317 | old = NULL; |
| 318 | } else |
| 319 | termios->c_cflag |= B9600; |
| 320 | } |
| 321 | quot = (2 * port->uartclk + baud) / (2 * baud); |
| 322 | |
| 323 | if (baud < 2400) |
| 324 | fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1; |
| 325 | else |
| 326 | fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10; |
| 327 | |
| 328 | port->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; |
| 329 | if (termios->c_iflag & INPCK) |
| 330 | port->read_status_mask |= UART_LSR_FE | UART_LSR_PE; |
| 331 | if (termios->c_iflag & (BRKINT | PARMRK)) |
| 332 | port->read_status_mask |= UART_LSR_BI; |
| 333 | |
| 334 | /* |
| 335 | * Characters to ignore |
| 336 | */ |
| 337 | port->ignore_status_mask = 0; |
| 338 | if (termios->c_iflag & IGNPAR) |
| 339 | port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; |
| 340 | if (termios->c_iflag & IGNBRK) { |
| 341 | port->ignore_status_mask |= UART_LSR_BI; |
| 342 | /* |
| 343 | * If we're ignoring parity and break indicators, |
| 344 | * ignore overruns too (for real raw support). |
| 345 | */ |
| 346 | if (termios->c_iflag & IGNPAR) |
| 347 | port->ignore_status_mask |= UART_LSR_OE; |
| 348 | } |
| 349 | |
| 350 | /* |
| 351 | * ignore all characters if CREAD is not set |
| 352 | */ |
| 353 | if ((termios->c_cflag & CREAD) == 0) |
| 354 | port->ignore_status_mask |= UART_LSR_DR; |
| 355 | |
| 356 | /* |
| 357 | * CTS flow control flag and modem status interrupts |
| 358 | */ |
| 359 | port->ier &= ~UART_IER_MSI; |
| 360 | if ((termios->c_cflag & CRTSCTS) || !(termios->c_cflag & CLOCAL)) |
| 361 | port->ier |= UART_IER_MSI; |
| 362 | |
| 363 | port->lcr = cval; |
| 364 | |
| 365 | sdio_out(port, UART_IER, port->ier); |
| 366 | sdio_out(port, UART_LCR, cval | UART_LCR_DLAB); |
| 367 | sdio_out(port, UART_DLL, quot & 0xff); |
| 368 | sdio_out(port, UART_DLM, quot >> 8); |
| 369 | sdio_out(port, UART_LCR, cval); |
| 370 | sdio_out(port, UART_FCR, fcr); |
| 371 | |
| 372 | sdio_uart_write_mctrl(port, port->mctrl); |
| 373 | } |
| 374 | |
| 375 | static void sdio_uart_start_tx(struct sdio_uart_port *port) |
| 376 | { |
| 377 | if (!(port->ier & UART_IER_THRI)) { |
| 378 | port->ier |= UART_IER_THRI; |
| 379 | sdio_out(port, UART_IER, port->ier); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | static void sdio_uart_stop_tx(struct sdio_uart_port *port) |
| 384 | { |
| 385 | if (port->ier & UART_IER_THRI) { |
| 386 | port->ier &= ~UART_IER_THRI; |
| 387 | sdio_out(port, UART_IER, port->ier); |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | static void sdio_uart_stop_rx(struct sdio_uart_port *port) |
| 392 | { |
| 393 | port->ier &= ~UART_IER_RLSI; |
| 394 | port->read_status_mask &= ~UART_LSR_DR; |
| 395 | sdio_out(port, UART_IER, port->ier); |
| 396 | } |
| 397 | |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 398 | static void sdio_uart_receive_chars(struct sdio_uart_port *port, |
| 399 | unsigned int *status) |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 400 | { |
Alan Cox | 530646f | 2009-11-05 13:28:29 +0000 | [diff] [blame] | 401 | struct tty_struct *tty = tty_port_tty_get(&port->port); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 402 | unsigned int ch, flag; |
| 403 | int max_count = 256; |
| 404 | |
| 405 | do { |
| 406 | ch = sdio_in(port, UART_RX); |
| 407 | flag = TTY_NORMAL; |
| 408 | port->icount.rx++; |
| 409 | |
| 410 | if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE | |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 411 | UART_LSR_FE | UART_LSR_OE))) { |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 412 | /* |
| 413 | * For statistics only |
| 414 | */ |
| 415 | if (*status & UART_LSR_BI) { |
| 416 | *status &= ~(UART_LSR_FE | UART_LSR_PE); |
| 417 | port->icount.brk++; |
| 418 | } else if (*status & UART_LSR_PE) |
| 419 | port->icount.parity++; |
| 420 | else if (*status & UART_LSR_FE) |
| 421 | port->icount.frame++; |
| 422 | if (*status & UART_LSR_OE) |
| 423 | port->icount.overrun++; |
| 424 | |
| 425 | /* |
| 426 | * Mask off conditions which should be ignored. |
| 427 | */ |
| 428 | *status &= port->read_status_mask; |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 429 | if (*status & UART_LSR_BI) |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 430 | flag = TTY_BREAK; |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 431 | else if (*status & UART_LSR_PE) |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 432 | flag = TTY_PARITY; |
| 433 | else if (*status & UART_LSR_FE) |
| 434 | flag = TTY_FRAME; |
| 435 | } |
| 436 | |
| 437 | if ((*status & port->ignore_status_mask & ~UART_LSR_OE) == 0) |
Alan Cox | 530646f | 2009-11-05 13:28:29 +0000 | [diff] [blame] | 438 | if (tty) |
| 439 | tty_insert_flip_char(tty, ch, flag); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 440 | |
| 441 | /* |
| 442 | * Overrun is special. Since it's reported immediately, |
| 443 | * it doesn't affect the current character. |
| 444 | */ |
| 445 | if (*status & ~port->ignore_status_mask & UART_LSR_OE) |
Alan Cox | 530646f | 2009-11-05 13:28:29 +0000 | [diff] [blame] | 446 | if (tty) |
| 447 | tty_insert_flip_char(tty, 0, TTY_OVERRUN); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 448 | |
| 449 | *status = sdio_in(port, UART_LSR); |
| 450 | } while ((*status & UART_LSR_DR) && (max_count-- > 0)); |
Alan Cox | 530646f | 2009-11-05 13:28:29 +0000 | [diff] [blame] | 451 | if (tty) { |
| 452 | tty_flip_buffer_push(tty); |
| 453 | tty_kref_put(tty); |
| 454 | } |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | static void sdio_uart_transmit_chars(struct sdio_uart_port *port) |
| 458 | { |
| 459 | struct circ_buf *xmit = &port->xmit; |
| 460 | int count; |
Alan Cox | 530646f | 2009-11-05 13:28:29 +0000 | [diff] [blame] | 461 | struct tty_struct *tty; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 462 | |
| 463 | if (port->x_char) { |
| 464 | sdio_out(port, UART_TX, port->x_char); |
| 465 | port->icount.tx++; |
| 466 | port->x_char = 0; |
| 467 | return; |
| 468 | } |
Alan Cox | 530646f | 2009-11-05 13:28:29 +0000 | [diff] [blame] | 469 | |
| 470 | tty = tty_port_tty_get(&port->port); |
| 471 | |
Alan Cox | c271cf3 | 2009-11-30 13:16:25 +0000 | [diff] [blame] | 472 | if (tty == NULL || circ_empty(xmit) || |
| 473 | tty->stopped || tty->hw_stopped) { |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 474 | sdio_uart_stop_tx(port); |
Alan Cox | 530646f | 2009-11-05 13:28:29 +0000 | [diff] [blame] | 475 | tty_kref_put(tty); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 476 | return; |
| 477 | } |
| 478 | |
| 479 | count = 16; |
| 480 | do { |
| 481 | sdio_out(port, UART_TX, xmit->buf[xmit->tail]); |
| 482 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
| 483 | port->icount.tx++; |
| 484 | if (circ_empty(xmit)) |
| 485 | break; |
| 486 | } while (--count > 0); |
| 487 | |
| 488 | if (circ_chars_pending(xmit) < WAKEUP_CHARS) |
Alan Cox | b5849b1 | 2009-11-05 13:28:06 +0000 | [diff] [blame] | 489 | tty_wakeup(tty); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 490 | |
| 491 | if (circ_empty(xmit)) |
| 492 | sdio_uart_stop_tx(port); |
Alan Cox | 530646f | 2009-11-05 13:28:29 +0000 | [diff] [blame] | 493 | tty_kref_put(tty); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | static void sdio_uart_check_modem_status(struct sdio_uart_port *port) |
| 497 | { |
| 498 | int status; |
Alan Cox | 530646f | 2009-11-05 13:28:29 +0000 | [diff] [blame] | 499 | struct tty_struct *tty; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 500 | |
| 501 | status = sdio_in(port, UART_MSR); |
| 502 | |
| 503 | if ((status & UART_MSR_ANY_DELTA) == 0) |
| 504 | return; |
| 505 | |
| 506 | if (status & UART_MSR_TERI) |
| 507 | port->icount.rng++; |
| 508 | if (status & UART_MSR_DDSR) |
| 509 | port->icount.dsr++; |
Alan Cox | 4b3b49b | 2009-11-30 13:16:36 +0000 | [diff] [blame^] | 510 | if (status & UART_MSR_DDCD) { |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 511 | port->icount.dcd++; |
Alan Cox | 4b3b49b | 2009-11-30 13:16:36 +0000 | [diff] [blame^] | 512 | /* DCD raise - wake for open */ |
| 513 | if (status & UART_MSR_DCD) |
| 514 | wake_up_interruptible(&port->port.open_wait); |
| 515 | else { |
| 516 | /* DCD drop - hang up if tty attached */ |
| 517 | tty = tty_port_tty_get(&port->port); |
| 518 | if (tty) { |
| 519 | tty_hangup(tty); |
| 520 | tty_kref_put(tty); |
| 521 | } |
| 522 | } |
| 523 | } |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 524 | if (status & UART_MSR_DCTS) { |
| 525 | port->icount.cts++; |
Alan Cox | 530646f | 2009-11-05 13:28:29 +0000 | [diff] [blame] | 526 | tty = tty_port_tty_get(&port->port); |
| 527 | if (tty && (tty->termios->c_cflag & CRTSCTS)) { |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 528 | int cts = (status & UART_MSR_CTS); |
Alan Cox | b5849b1 | 2009-11-05 13:28:06 +0000 | [diff] [blame] | 529 | if (tty->hw_stopped) { |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 530 | if (cts) { |
Alan Cox | b5849b1 | 2009-11-05 13:28:06 +0000 | [diff] [blame] | 531 | tty->hw_stopped = 0; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 532 | sdio_uart_start_tx(port); |
Alan Cox | b5849b1 | 2009-11-05 13:28:06 +0000 | [diff] [blame] | 533 | tty_wakeup(tty); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 534 | } |
| 535 | } else { |
| 536 | if (!cts) { |
Alan Cox | b5849b1 | 2009-11-05 13:28:06 +0000 | [diff] [blame] | 537 | tty->hw_stopped = 1; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 538 | sdio_uart_stop_tx(port); |
| 539 | } |
| 540 | } |
| 541 | } |
Alan Cox | 530646f | 2009-11-05 13:28:29 +0000 | [diff] [blame] | 542 | tty_kref_put(tty); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 543 | } |
| 544 | } |
| 545 | |
| 546 | /* |
| 547 | * This handles the interrupt from one port. |
| 548 | */ |
| 549 | static void sdio_uart_irq(struct sdio_func *func) |
| 550 | { |
| 551 | struct sdio_uart_port *port = sdio_get_drvdata(func); |
| 552 | unsigned int iir, lsr; |
| 553 | |
Nicolas Pitre | 15b82b4 | 2007-08-20 17:17:37 -0400 | [diff] [blame] | 554 | /* |
| 555 | * In a few places sdio_uart_irq() is called directly instead of |
| 556 | * waiting for the actual interrupt to be raised and the SDIO IRQ |
| 557 | * thread scheduled in order to reduce latency. However, some |
| 558 | * interaction with the tty core may end up calling us back |
| 559 | * (serial echo, flow control, etc.) through those same places |
| 560 | * causing undesirable effects. Let's stop the recursion here. |
| 561 | */ |
| 562 | if (unlikely(port->in_sdio_uart_irq == current)) |
| 563 | return; |
| 564 | |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 565 | iir = sdio_in(port, UART_IIR); |
| 566 | if (iir & UART_IIR_NO_INT) |
| 567 | return; |
Nicolas Pitre | 15b82b4 | 2007-08-20 17:17:37 -0400 | [diff] [blame] | 568 | |
| 569 | port->in_sdio_uart_irq = current; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 570 | lsr = sdio_in(port, UART_LSR); |
| 571 | if (lsr & UART_LSR_DR) |
| 572 | sdio_uart_receive_chars(port, &lsr); |
| 573 | sdio_uart_check_modem_status(port); |
| 574 | if (lsr & UART_LSR_THRE) |
| 575 | sdio_uart_transmit_chars(port); |
Nicolas Pitre | 15b82b4 | 2007-08-20 17:17:37 -0400 | [diff] [blame] | 576 | port->in_sdio_uart_irq = NULL; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 577 | } |
| 578 | |
Alan Cox | 4b3b49b | 2009-11-30 13:16:36 +0000 | [diff] [blame^] | 579 | static int uart_carrier_raised(struct tty_port *tport) |
| 580 | { |
| 581 | struct sdio_uart_port *port = |
| 582 | container_of(tport, struct sdio_uart_port, port); |
| 583 | unsigned int ret = sdio_uart_claim_func(port); |
| 584 | if (ret) /* Missing hardware shoudn't block for carrier */ |
| 585 | return 1; |
| 586 | ret = sdio_uart_get_mctrl(port); |
| 587 | sdio_uart_release_func(port); |
| 588 | if (ret & TIOCM_CAR) |
| 589 | return 1; |
| 590 | return 0; |
| 591 | } |
| 592 | |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 593 | /** |
| 594 | * uart_dtr_rts - port helper to set uart signals |
| 595 | * @tport: tty port to be updated |
| 596 | * @onoff: set to turn on DTR/RTS |
| 597 | * |
| 598 | * Called by the tty port helpers when the modem signals need to be |
| 599 | * adjusted during an open, close and hangup. |
| 600 | */ |
Alan Cox | 530646f | 2009-11-05 13:28:29 +0000 | [diff] [blame] | 601 | |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 602 | static void uart_dtr_rts(struct tty_port *tport, int onoff) |
| 603 | { |
| 604 | struct sdio_uart_port *port = |
| 605 | container_of(tport, struct sdio_uart_port, port); |
| 606 | if (onoff == 0) |
| 607 | sdio_uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); |
| 608 | else |
| 609 | sdio_uart_set_mctrl(port, TIOCM_DTR | TIOCM_RTS); |
| 610 | } |
| 611 | |
| 612 | /** |
| 613 | * sdio_uart_activate - start up hardware |
| 614 | * @tport: tty port to activate |
| 615 | * @tty: tty bound to this port |
| 616 | * |
| 617 | * Activate a tty port. The port locking guarantees us this will be |
| 618 | * run exactly once per set of opens, and if successful will see the |
| 619 | * shutdown method run exactly once to match. Start up and shutdown are |
| 620 | * protected from each other by the internal locking and will not run |
| 621 | * at the same time even during a hangup event. |
| 622 | * |
| 623 | * If we successfully start up the port we take an extra kref as we |
| 624 | * will keep it around until shutdown when the kref is dropped. |
| 625 | */ |
| 626 | |
| 627 | static int sdio_uart_activate(struct tty_port *tport, struct tty_struct *tty) |
| 628 | { |
| 629 | struct sdio_uart_port *port = |
| 630 | container_of(tport, struct sdio_uart_port, port); |
| 631 | unsigned long page; |
| 632 | int ret; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 633 | |
| 634 | /* |
| 635 | * Set the TTY IO error marker - we will only clear this |
| 636 | * once we have successfully opened the port. |
| 637 | */ |
Alan Cox | b5849b1 | 2009-11-05 13:28:06 +0000 | [diff] [blame] | 638 | set_bit(TTY_IO_ERROR, &tty->flags); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 639 | |
| 640 | /* Initialise and allocate the transmit buffer. */ |
| 641 | page = __get_free_page(GFP_KERNEL); |
| 642 | if (!page) |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 643 | return -ENOMEM; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 644 | port->xmit.buf = (unsigned char *)page; |
| 645 | circ_clear(&port->xmit); |
| 646 | |
| 647 | ret = sdio_uart_claim_func(port); |
| 648 | if (ret) |
| 649 | goto err1; |
| 650 | ret = sdio_enable_func(port->func); |
| 651 | if (ret) |
| 652 | goto err2; |
| 653 | ret = sdio_claim_irq(port->func, sdio_uart_irq); |
| 654 | if (ret) |
| 655 | goto err3; |
| 656 | |
| 657 | /* |
| 658 | * Clear the FIFO buffers and disable them. |
| 659 | * (they will be reenabled in sdio_change_speed()) |
| 660 | */ |
| 661 | sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO); |
| 662 | sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO | |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 663 | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 664 | sdio_out(port, UART_FCR, 0); |
| 665 | |
| 666 | /* |
| 667 | * Clear the interrupt registers. |
| 668 | */ |
| 669 | (void) sdio_in(port, UART_LSR); |
| 670 | (void) sdio_in(port, UART_RX); |
| 671 | (void) sdio_in(port, UART_IIR); |
| 672 | (void) sdio_in(port, UART_MSR); |
| 673 | |
| 674 | /* |
| 675 | * Now, initialize the UART |
| 676 | */ |
| 677 | sdio_out(port, UART_LCR, UART_LCR_WLEN8); |
| 678 | |
Alan Cox | c271cf3 | 2009-11-30 13:16:25 +0000 | [diff] [blame] | 679 | port->ier = UART_IER_RLSI|UART_IER_RDI|UART_IER_RTOIE|UART_IER_UUE; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 680 | port->mctrl = TIOCM_OUT2; |
| 681 | |
Alan Cox | b5849b1 | 2009-11-05 13:28:06 +0000 | [diff] [blame] | 682 | sdio_uart_change_speed(port, tty->termios, NULL); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 683 | |
Alan Cox | b5849b1 | 2009-11-05 13:28:06 +0000 | [diff] [blame] | 684 | if (tty->termios->c_cflag & CBAUD) |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 685 | sdio_uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR); |
| 686 | |
Alan Cox | b5849b1 | 2009-11-05 13:28:06 +0000 | [diff] [blame] | 687 | if (tty->termios->c_cflag & CRTSCTS) |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 688 | if (!(sdio_uart_get_mctrl(port) & TIOCM_CTS)) |
Alan Cox | b5849b1 | 2009-11-05 13:28:06 +0000 | [diff] [blame] | 689 | tty->hw_stopped = 1; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 690 | |
Nicolas Pitre | 0395b48 | 2009-11-05 13:28:17 +0000 | [diff] [blame] | 691 | clear_bit(TTY_IO_ERROR, &tty->flags); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 692 | |
| 693 | /* Kick the IRQ handler once while we're still holding the host lock */ |
| 694 | sdio_uart_irq(port->func); |
| 695 | |
| 696 | sdio_uart_release_func(port); |
| 697 | return 0; |
| 698 | |
| 699 | err3: |
| 700 | sdio_disable_func(port->func); |
| 701 | err2: |
| 702 | sdio_uart_release_func(port); |
| 703 | err1: |
| 704 | free_page((unsigned long)port->xmit.buf); |
| 705 | return ret; |
| 706 | } |
| 707 | |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 708 | /** |
| 709 | * sdio_uart_shutdown - stop hardware |
| 710 | * @tport: tty port to shut down |
| 711 | * |
| 712 | * Deactivate a tty port. The port locking guarantees us this will be |
| 713 | * run only if a successful matching activate already ran. The two are |
| 714 | * protected from each other by the internal locking and will not run |
| 715 | * at the same time even during a hangup event. |
| 716 | */ |
| 717 | |
| 718 | static void sdio_uart_shutdown(struct tty_port *tport) |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 719 | { |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 720 | struct sdio_uart_port *port = |
| 721 | container_of(tport, struct sdio_uart_port, port); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 722 | int ret; |
| 723 | |
| 724 | ret = sdio_uart_claim_func(port); |
| 725 | if (ret) |
| 726 | goto skip; |
| 727 | |
| 728 | sdio_uart_stop_rx(port); |
| 729 | |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 730 | /* Disable interrupts from this port */ |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 731 | sdio_release_irq(port->func); |
| 732 | port->ier = 0; |
| 733 | sdio_out(port, UART_IER, 0); |
| 734 | |
| 735 | sdio_uart_clear_mctrl(port, TIOCM_OUT2); |
| 736 | |
| 737 | /* Disable break condition and FIFOs. */ |
| 738 | port->lcr &= ~UART_LCR_SBC; |
| 739 | sdio_out(port, UART_LCR, port->lcr); |
| 740 | sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO | |
| 741 | UART_FCR_CLEAR_RCVR | |
| 742 | UART_FCR_CLEAR_XMIT); |
| 743 | sdio_out(port, UART_FCR, 0); |
| 744 | |
| 745 | sdio_disable_func(port->func); |
| 746 | |
| 747 | sdio_uart_release_func(port); |
| 748 | |
| 749 | skip: |
| 750 | /* Free the transmit buffer page. */ |
| 751 | free_page((unsigned long)port->xmit.buf); |
| 752 | } |
| 753 | |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 754 | /** |
| 755 | * sdio_uart_install - install method |
| 756 | * @driver: the driver in use (sdio_uart in our case) |
| 757 | * @tty: the tty being bound |
| 758 | * |
| 759 | * Look up and bind the tty and the driver together. Initialize |
| 760 | * any needed private data (in our case the termios) |
| 761 | */ |
| 762 | |
| 763 | static int sdio_uart_install(struct tty_driver *driver, struct tty_struct *tty) |
| 764 | { |
| 765 | int idx = tty->index; |
| 766 | struct sdio_uart_port *port = sdio_uart_port_get(idx); |
| 767 | int ret = tty_init_termios(tty); |
| 768 | |
| 769 | if (ret == 0) { |
| 770 | tty_driver_kref_get(driver); |
| 771 | tty->count++; |
| 772 | /* This is the ref sdio_uart_port get provided */ |
| 773 | tty->driver_data = port; |
| 774 | driver->ttys[idx] = tty; |
| 775 | } else |
| 776 | sdio_uart_port_put(port); |
| 777 | return ret; |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | /** |
| 781 | * sdio_uart_cleanup - called on the last tty kref drop |
| 782 | * @tty: the tty being destroyed |
| 783 | * |
| 784 | * Called asynchronously when the last reference to the tty is dropped. |
| 785 | * We cannot destroy the tty->driver_data port kref until this point |
| 786 | */ |
| 787 | |
| 788 | static void sdio_uart_cleanup(struct tty_struct *tty) |
| 789 | { |
| 790 | struct sdio_uart_port *port = tty->driver_data; |
| 791 | tty->driver_data = NULL; /* Bug trap */ |
| 792 | sdio_uart_port_put(port); |
| 793 | } |
| 794 | |
| 795 | /* |
| 796 | * Open/close/hangup is now entirely boilerplate |
| 797 | */ |
| 798 | |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 799 | static int sdio_uart_open(struct tty_struct *tty, struct file *filp) |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 800 | { |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 801 | struct sdio_uart_port *port = tty->driver_data; |
| 802 | return tty_port_open(&port->port, tty, filp); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | static void sdio_uart_close(struct tty_struct *tty, struct file * filp) |
| 806 | { |
| 807 | struct sdio_uart_port *port = tty->driver_data; |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 808 | tty_port_close(&port->port, tty, filp); |
| 809 | } |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 810 | |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 811 | static void sdio_uart_hangup(struct tty_struct *tty) |
| 812 | { |
| 813 | struct sdio_uart_port *port = tty->driver_data; |
| 814 | tty_port_hangup(&port->port); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 815 | } |
| 816 | |
Alan Cox | c271cf3 | 2009-11-30 13:16:25 +0000 | [diff] [blame] | 817 | static int sdio_uart_write(struct tty_struct *tty, const unsigned char *buf, |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 818 | int count) |
| 819 | { |
| 820 | struct sdio_uart_port *port = tty->driver_data; |
| 821 | struct circ_buf *circ = &port->xmit; |
| 822 | int c, ret = 0; |
| 823 | |
| 824 | if (!port->func) |
| 825 | return -ENODEV; |
| 826 | |
| 827 | spin_lock(&port->write_lock); |
| 828 | while (1) { |
| 829 | c = CIRC_SPACE_TO_END(circ->head, circ->tail, UART_XMIT_SIZE); |
| 830 | if (count < c) |
| 831 | c = count; |
| 832 | if (c <= 0) |
| 833 | break; |
| 834 | memcpy(circ->buf + circ->head, buf, c); |
| 835 | circ->head = (circ->head + c) & (UART_XMIT_SIZE - 1); |
| 836 | buf += c; |
| 837 | count -= c; |
| 838 | ret += c; |
| 839 | } |
| 840 | spin_unlock(&port->write_lock); |
| 841 | |
Alan Cox | c271cf3 | 2009-11-30 13:16:25 +0000 | [diff] [blame] | 842 | if (!(port->ier & UART_IER_THRI)) { |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 843 | int err = sdio_uart_claim_func(port); |
| 844 | if (!err) { |
| 845 | sdio_uart_start_tx(port); |
| 846 | sdio_uart_irq(port->func); |
| 847 | sdio_uart_release_func(port); |
| 848 | } else |
| 849 | ret = err; |
| 850 | } |
| 851 | |
| 852 | return ret; |
| 853 | } |
| 854 | |
| 855 | static int sdio_uart_write_room(struct tty_struct *tty) |
| 856 | { |
| 857 | struct sdio_uart_port *port = tty->driver_data; |
| 858 | return port ? circ_chars_free(&port->xmit) : 0; |
| 859 | } |
| 860 | |
| 861 | static int sdio_uart_chars_in_buffer(struct tty_struct *tty) |
| 862 | { |
| 863 | struct sdio_uart_port *port = tty->driver_data; |
| 864 | return port ? circ_chars_pending(&port->xmit) : 0; |
| 865 | } |
| 866 | |
| 867 | static void sdio_uart_send_xchar(struct tty_struct *tty, char ch) |
| 868 | { |
| 869 | struct sdio_uart_port *port = tty->driver_data; |
| 870 | |
| 871 | port->x_char = ch; |
| 872 | if (ch && !(port->ier & UART_IER_THRI)) { |
| 873 | if (sdio_uart_claim_func(port) != 0) |
| 874 | return; |
| 875 | sdio_uart_start_tx(port); |
| 876 | sdio_uart_irq(port->func); |
| 877 | sdio_uart_release_func(port); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | static void sdio_uart_throttle(struct tty_struct *tty) |
| 882 | { |
| 883 | struct sdio_uart_port *port = tty->driver_data; |
| 884 | |
| 885 | if (!I_IXOFF(tty) && !(tty->termios->c_cflag & CRTSCTS)) |
| 886 | return; |
| 887 | |
| 888 | if (sdio_uart_claim_func(port) != 0) |
| 889 | return; |
| 890 | |
| 891 | if (I_IXOFF(tty)) { |
| 892 | port->x_char = STOP_CHAR(tty); |
| 893 | sdio_uart_start_tx(port); |
| 894 | } |
| 895 | |
| 896 | if (tty->termios->c_cflag & CRTSCTS) |
| 897 | sdio_uart_clear_mctrl(port, TIOCM_RTS); |
| 898 | |
| 899 | sdio_uart_irq(port->func); |
| 900 | sdio_uart_release_func(port); |
| 901 | } |
| 902 | |
| 903 | static void sdio_uart_unthrottle(struct tty_struct *tty) |
| 904 | { |
| 905 | struct sdio_uart_port *port = tty->driver_data; |
| 906 | |
| 907 | if (!I_IXOFF(tty) && !(tty->termios->c_cflag & CRTSCTS)) |
| 908 | return; |
| 909 | |
| 910 | if (sdio_uart_claim_func(port) != 0) |
| 911 | return; |
| 912 | |
| 913 | if (I_IXOFF(tty)) { |
| 914 | if (port->x_char) { |
| 915 | port->x_char = 0; |
| 916 | } else { |
| 917 | port->x_char = START_CHAR(tty); |
| 918 | sdio_uart_start_tx(port); |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | if (tty->termios->c_cflag & CRTSCTS) |
| 923 | sdio_uart_set_mctrl(port, TIOCM_RTS); |
| 924 | |
| 925 | sdio_uart_irq(port->func); |
| 926 | sdio_uart_release_func(port); |
| 927 | } |
| 928 | |
Alan Cox | c271cf3 | 2009-11-30 13:16:25 +0000 | [diff] [blame] | 929 | static void sdio_uart_set_termios(struct tty_struct *tty, |
| 930 | struct ktermios *old_termios) |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 931 | { |
| 932 | struct sdio_uart_port *port = tty->driver_data; |
| 933 | unsigned int cflag = tty->termios->c_cflag; |
| 934 | |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 935 | if (sdio_uart_claim_func(port) != 0) |
| 936 | return; |
| 937 | |
| 938 | sdio_uart_change_speed(port, tty->termios, old_termios); |
| 939 | |
| 940 | /* Handle transition to B0 status */ |
| 941 | if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD)) |
| 942 | sdio_uart_clear_mctrl(port, TIOCM_RTS | TIOCM_DTR); |
| 943 | |
| 944 | /* Handle transition away from B0 status */ |
| 945 | if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) { |
| 946 | unsigned int mask = TIOCM_DTR; |
| 947 | if (!(cflag & CRTSCTS) || !test_bit(TTY_THROTTLED, &tty->flags)) |
| 948 | mask |= TIOCM_RTS; |
| 949 | sdio_uart_set_mctrl(port, mask); |
| 950 | } |
| 951 | |
| 952 | /* Handle turning off CRTSCTS */ |
| 953 | if ((old_termios->c_cflag & CRTSCTS) && !(cflag & CRTSCTS)) { |
| 954 | tty->hw_stopped = 0; |
| 955 | sdio_uart_start_tx(port); |
| 956 | } |
| 957 | |
| 958 | /* Handle turning on CRTSCTS */ |
| 959 | if (!(old_termios->c_cflag & CRTSCTS) && (cflag & CRTSCTS)) { |
| 960 | if (!(sdio_uart_get_mctrl(port) & TIOCM_CTS)) { |
| 961 | tty->hw_stopped = 1; |
| 962 | sdio_uart_stop_tx(port); |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | sdio_uart_release_func(port); |
| 967 | } |
| 968 | |
David Howells | c43d8636 | 2008-07-10 12:28:48 +0100 | [diff] [blame] | 969 | static int sdio_uart_break_ctl(struct tty_struct *tty, int break_state) |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 970 | { |
| 971 | struct sdio_uart_port *port = tty->driver_data; |
David Howells | c43d8636 | 2008-07-10 12:28:48 +0100 | [diff] [blame] | 972 | int result; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 973 | |
David Howells | c43d8636 | 2008-07-10 12:28:48 +0100 | [diff] [blame] | 974 | result = sdio_uart_claim_func(port); |
| 975 | if (result != 0) |
| 976 | return result; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 977 | |
| 978 | if (break_state == -1) |
| 979 | port->lcr |= UART_LCR_SBC; |
| 980 | else |
| 981 | port->lcr &= ~UART_LCR_SBC; |
| 982 | sdio_out(port, UART_LCR, port->lcr); |
| 983 | |
| 984 | sdio_uart_release_func(port); |
David Howells | c43d8636 | 2008-07-10 12:28:48 +0100 | [diff] [blame] | 985 | return 0; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | static int sdio_uart_tiocmget(struct tty_struct *tty, struct file *file) |
| 989 | { |
| 990 | struct sdio_uart_port *port = tty->driver_data; |
| 991 | int result; |
| 992 | |
| 993 | result = sdio_uart_claim_func(port); |
| 994 | if (!result) { |
| 995 | result = port->mctrl | sdio_uart_get_mctrl(port); |
| 996 | sdio_uart_release_func(port); |
| 997 | } |
| 998 | |
| 999 | return result; |
| 1000 | } |
| 1001 | |
| 1002 | static int sdio_uart_tiocmset(struct tty_struct *tty, struct file *file, |
| 1003 | unsigned int set, unsigned int clear) |
| 1004 | { |
| 1005 | struct sdio_uart_port *port = tty->driver_data; |
| 1006 | int result; |
| 1007 | |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 1008 | result = sdio_uart_claim_func(port); |
Alan Cox | c271cf3 | 2009-11-30 13:16:25 +0000 | [diff] [blame] | 1009 | if (!result) { |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 1010 | sdio_uart_update_mctrl(port, set, clear); |
| 1011 | sdio_uart_release_func(port); |
| 1012 | } |
| 1013 | |
| 1014 | return result; |
| 1015 | } |
| 1016 | |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1017 | static int sdio_uart_proc_show(struct seq_file *m, void *v) |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1018 | { |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1019 | int i; |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1020 | |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1021 | seq_printf(m, "serinfo:1.0 driver%s%s revision:%s\n", |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1022 | "", "", ""); |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1023 | for (i = 0; i < UART_NR; i++) { |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1024 | struct sdio_uart_port *port = sdio_uart_port_get(i); |
| 1025 | if (port) { |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1026 | seq_printf(m, "%d: uart:SDIO", i); |
Alan Cox | c271cf3 | 2009-11-30 13:16:25 +0000 | [diff] [blame] | 1027 | if (capable(CAP_SYS_ADMIN)) { |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1028 | seq_printf(m, " tx:%d rx:%d", |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 1029 | port->icount.tx, port->icount.rx); |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1030 | if (port->icount.frame) |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1031 | seq_printf(m, " fe:%d", |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 1032 | port->icount.frame); |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1033 | if (port->icount.parity) |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1034 | seq_printf(m, " pe:%d", |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 1035 | port->icount.parity); |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1036 | if (port->icount.brk) |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1037 | seq_printf(m, " brk:%d", |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 1038 | port->icount.brk); |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1039 | if (port->icount.overrun) |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1040 | seq_printf(m, " oe:%d", |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 1041 | port->icount.overrun); |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1042 | if (port->icount.cts) |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1043 | seq_printf(m, " cts:%d", |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 1044 | port->icount.cts); |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1045 | if (port->icount.dsr) |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1046 | seq_printf(m, " dsr:%d", |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 1047 | port->icount.dsr); |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1048 | if (port->icount.rng) |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1049 | seq_printf(m, " rng:%d", |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 1050 | port->icount.rng); |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1051 | if (port->icount.dcd) |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1052 | seq_printf(m, " dcd:%d", |
Thadeu Lima de Souza Cascardo | 1e04b7a | 2009-10-15 16:44:00 -0300 | [diff] [blame] | 1053 | port->icount.dcd); |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1054 | } |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1055 | sdio_uart_port_put(port); |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1056 | seq_putc(m, '\n'); |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1057 | } |
| 1058 | } |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1059 | return 0; |
Nicolas Pitre | 5ed334a | 2007-07-04 23:40:34 -0400 | [diff] [blame] | 1060 | } |
| 1061 | |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1062 | static int sdio_uart_proc_open(struct inode *inode, struct file *file) |
| 1063 | { |
| 1064 | return single_open(file, sdio_uart_proc_show, NULL); |
| 1065 | } |
| 1066 | |
| 1067 | static const struct file_operations sdio_uart_proc_fops = { |
| 1068 | .owner = THIS_MODULE, |
| 1069 | .open = sdio_uart_proc_open, |
| 1070 | .read = seq_read, |
| 1071 | .llseek = seq_lseek, |
| 1072 | .release = single_release, |
| 1073 | }; |
| 1074 | |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 1075 | static const struct tty_port_operations sdio_uart_port_ops = { |
| 1076 | .dtr_rts = uart_dtr_rts, |
Alan Cox | 4b3b49b | 2009-11-30 13:16:36 +0000 | [diff] [blame^] | 1077 | .carrier_raised = uart_carrier_raised, |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 1078 | .shutdown = sdio_uart_shutdown, |
| 1079 | .activate = sdio_uart_activate, |
| 1080 | }; |
| 1081 | |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 1082 | static const struct tty_operations sdio_uart_ops = { |
| 1083 | .open = sdio_uart_open, |
| 1084 | .close = sdio_uart_close, |
| 1085 | .write = sdio_uart_write, |
| 1086 | .write_room = sdio_uart_write_room, |
| 1087 | .chars_in_buffer = sdio_uart_chars_in_buffer, |
| 1088 | .send_xchar = sdio_uart_send_xchar, |
| 1089 | .throttle = sdio_uart_throttle, |
| 1090 | .unthrottle = sdio_uart_unthrottle, |
| 1091 | .set_termios = sdio_uart_set_termios, |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 1092 | .hangup = sdio_uart_hangup, |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 1093 | .break_ctl = sdio_uart_break_ctl, |
| 1094 | .tiocmget = sdio_uart_tiocmget, |
| 1095 | .tiocmset = sdio_uart_tiocmset, |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 1096 | .install = sdio_uart_install, |
| 1097 | .cleanup = sdio_uart_cleanup, |
Alexey Dobriyan | 201a50b | 2009-03-31 15:19:20 -0700 | [diff] [blame] | 1098 | .proc_fops = &sdio_uart_proc_fops, |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 1099 | }; |
| 1100 | |
| 1101 | static struct tty_driver *sdio_uart_tty_driver; |
| 1102 | |
| 1103 | static int sdio_uart_probe(struct sdio_func *func, |
| 1104 | const struct sdio_device_id *id) |
| 1105 | { |
| 1106 | struct sdio_uart_port *port; |
| 1107 | int ret; |
| 1108 | |
| 1109 | port = kzalloc(sizeof(struct sdio_uart_port), GFP_KERNEL); |
| 1110 | if (!port) |
| 1111 | return -ENOMEM; |
| 1112 | |
| 1113 | if (func->class == SDIO_CLASS_UART) { |
| 1114 | printk(KERN_WARNING "%s: need info on UART class basic setup\n", |
| 1115 | sdio_func_id(func)); |
| 1116 | kfree(port); |
| 1117 | return -ENOSYS; |
| 1118 | } else if (func->class == SDIO_CLASS_GPS) { |
| 1119 | /* |
| 1120 | * We need tuple 0x91. It contains SUBTPL_SIOREG |
| 1121 | * and SUBTPL_RCVCAPS. |
| 1122 | */ |
| 1123 | struct sdio_func_tuple *tpl; |
| 1124 | for (tpl = func->tuples; tpl; tpl = tpl->next) { |
| 1125 | if (tpl->code != 0x91) |
| 1126 | continue; |
| 1127 | if (tpl->size < 10) |
| 1128 | continue; |
| 1129 | if (tpl->data[1] == 0) /* SUBTPL_SIOREG */ |
| 1130 | break; |
| 1131 | } |
| 1132 | if (!tpl) { |
| 1133 | printk(KERN_WARNING |
Alan Cox | c271cf3 | 2009-11-30 13:16:25 +0000 | [diff] [blame] | 1134 | "%s: can't find tuple 0x91 subtuple 0 (SUBTPL_SIOREG) for GPS class\n", |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 1135 | sdio_func_id(func)); |
| 1136 | kfree(port); |
| 1137 | return -EINVAL; |
| 1138 | } |
| 1139 | printk(KERN_DEBUG "%s: Register ID = 0x%02x, Exp ID = 0x%02x\n", |
| 1140 | sdio_func_id(func), tpl->data[2], tpl->data[3]); |
| 1141 | port->regs_offset = (tpl->data[4] << 0) | |
| 1142 | (tpl->data[5] << 8) | |
| 1143 | (tpl->data[6] << 16); |
| 1144 | printk(KERN_DEBUG "%s: regs offset = 0x%x\n", |
| 1145 | sdio_func_id(func), port->regs_offset); |
| 1146 | port->uartclk = tpl->data[7] * 115200; |
| 1147 | if (port->uartclk == 0) |
| 1148 | port->uartclk = 115200; |
| 1149 | printk(KERN_DEBUG "%s: clk %d baudcode %u 4800-div %u\n", |
| 1150 | sdio_func_id(func), port->uartclk, |
| 1151 | tpl->data[7], tpl->data[8] | (tpl->data[9] << 8)); |
| 1152 | } else { |
| 1153 | kfree(port); |
| 1154 | return -EINVAL; |
| 1155 | } |
| 1156 | |
| 1157 | port->func = func; |
| 1158 | sdio_set_drvdata(func, port); |
Alan Cox | b5849b1 | 2009-11-05 13:28:06 +0000 | [diff] [blame] | 1159 | tty_port_init(&port->port); |
Alan Cox | 584abc3 | 2009-11-30 13:16:09 +0000 | [diff] [blame] | 1160 | port->port.ops = &sdio_uart_port_ops; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 1161 | |
| 1162 | ret = sdio_uart_add_port(port); |
| 1163 | if (ret) { |
| 1164 | kfree(port); |
| 1165 | } else { |
| 1166 | struct device *dev; |
Alan Cox | c271cf3 | 2009-11-30 13:16:25 +0000 | [diff] [blame] | 1167 | dev = tty_register_device(sdio_uart_tty_driver, |
| 1168 | port->index, &func->dev); |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 1169 | if (IS_ERR(dev)) { |
| 1170 | sdio_uart_port_remove(port); |
| 1171 | ret = PTR_ERR(dev); |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | return ret; |
| 1176 | } |
| 1177 | |
| 1178 | static void sdio_uart_remove(struct sdio_func *func) |
| 1179 | { |
| 1180 | struct sdio_uart_port *port = sdio_get_drvdata(func); |
| 1181 | |
| 1182 | tty_unregister_device(sdio_uart_tty_driver, port->index); |
| 1183 | sdio_uart_port_remove(port); |
| 1184 | } |
| 1185 | |
| 1186 | static const struct sdio_device_id sdio_uart_ids[] = { |
| 1187 | { SDIO_DEVICE_CLASS(SDIO_CLASS_UART) }, |
| 1188 | { SDIO_DEVICE_CLASS(SDIO_CLASS_GPS) }, |
| 1189 | { /* end: all zeroes */ }, |
| 1190 | }; |
| 1191 | |
| 1192 | MODULE_DEVICE_TABLE(sdio, sdio_uart_ids); |
| 1193 | |
| 1194 | static struct sdio_driver sdio_uart_driver = { |
| 1195 | .probe = sdio_uart_probe, |
| 1196 | .remove = sdio_uart_remove, |
| 1197 | .name = "sdio_uart", |
| 1198 | .id_table = sdio_uart_ids, |
| 1199 | }; |
| 1200 | |
| 1201 | static int __init sdio_uart_init(void) |
| 1202 | { |
| 1203 | int ret; |
| 1204 | struct tty_driver *tty_drv; |
| 1205 | |
| 1206 | sdio_uart_tty_driver = tty_drv = alloc_tty_driver(UART_NR); |
| 1207 | if (!tty_drv) |
| 1208 | return -ENOMEM; |
| 1209 | |
| 1210 | tty_drv->owner = THIS_MODULE; |
| 1211 | tty_drv->driver_name = "sdio_uart"; |
| 1212 | tty_drv->name = "ttySDIO"; |
| 1213 | tty_drv->major = 0; /* dynamically allocated */ |
| 1214 | tty_drv->minor_start = 0; |
| 1215 | tty_drv->type = TTY_DRIVER_TYPE_SERIAL; |
| 1216 | tty_drv->subtype = SERIAL_TYPE_NORMAL; |
| 1217 | tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
| 1218 | tty_drv->init_termios = tty_std_termios; |
| 1219 | tty_drv->init_termios.c_cflag = B4800 | CS8 | CREAD | HUPCL | CLOCAL; |
Nicolas Pitre | 2ba30ee | 2007-08-15 13:27:29 -0400 | [diff] [blame] | 1220 | tty_drv->init_termios.c_ispeed = 4800; |
| 1221 | tty_drv->init_termios.c_ospeed = 4800; |
Nicolas Pitre | 6e418a9 | 2007-06-30 02:04:21 -0400 | [diff] [blame] | 1222 | tty_set_operations(tty_drv, &sdio_uart_ops); |
| 1223 | |
| 1224 | ret = tty_register_driver(tty_drv); |
| 1225 | if (ret) |
| 1226 | goto err1; |
| 1227 | |
| 1228 | ret = sdio_register_driver(&sdio_uart_driver); |
| 1229 | if (ret) |
| 1230 | goto err2; |
| 1231 | |
| 1232 | return 0; |
| 1233 | |
| 1234 | err2: |
| 1235 | tty_unregister_driver(tty_drv); |
| 1236 | err1: |
| 1237 | put_tty_driver(tty_drv); |
| 1238 | return ret; |
| 1239 | } |
| 1240 | |
| 1241 | static void __exit sdio_uart_exit(void) |
| 1242 | { |
| 1243 | sdio_unregister_driver(&sdio_uart_driver); |
| 1244 | tty_unregister_driver(sdio_uart_tty_driver); |
| 1245 | put_tty_driver(sdio_uart_tty_driver); |
| 1246 | } |
| 1247 | |
| 1248 | module_init(sdio_uart_init); |
| 1249 | module_exit(sdio_uart_exit); |
| 1250 | |
| 1251 | MODULE_AUTHOR("Nicolas Pitre"); |
| 1252 | MODULE_LICENSE("GPL"); |