13 #include <linux/module.h>
20 #include <linux/tty.h>
22 #include <linux/serial_core.h>
23 #include <linux/serial.h>
24 #include <linux/slab.h>
31 #define DRIVER_NAME "ar933x-uart"
33 #define AR933X_DUMMY_STATUS_RD 0x01
61 t = ar933x_uart_read(up, offset);
64 ar933x_uart_write(up, offset, t);
71 ar933x_uart_rmw(up, offset, 0, val);
78 ar933x_uart_rmw(up, offset, val, 0);
102 static unsigned int ar933x_uart_tx_empty(
struct uart_port *
port)
110 spin_unlock_irqrestore(&up->
port.lock, flags);
115 static unsigned int ar933x_uart_get_mctrl(
struct uart_port *port)
120 static void ar933x_uart_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
124 static void ar933x_uart_start_tx(
struct uart_port *port)
128 ar933x_uart_start_tx_interrupt(up);
131 static void ar933x_uart_stop_tx(
struct uart_port *port)
135 ar933x_uart_stop_tx_interrupt(up);
138 static void ar933x_uart_stop_rx(
struct uart_port *port)
146 static void ar933x_uart_break_ctl(
struct uart_port *port,
int break_state)
152 if (break_state == -1)
158 spin_unlock_irqrestore(&up->
port.lock, flags);
161 static void ar933x_uart_enable_ms(
struct uart_port *port)
165 static void ar933x_uart_set_termios(
struct uart_port *port,
172 unsigned int baud, scale;
175 new->c_cflag &= ~
CSIZE;
182 if (new->c_cflag &
PARENB) {
183 if (!(new->c_cflag &
PARODD))
206 up->
port.ignore_status_mask = 0;
209 if ((new->c_cflag &
CREAD) == 0)
222 spin_unlock_irqrestore(&up->
port.lock, flags);
244 AR933X_UART_DATA_RX_CSR);
251 up->
port.icount.rx++;
259 }
while (max_count-- > 0);
272 if (uart_tx_stopped(&up->
port))
275 count = up->
port.fifosize;
283 if (up->
port.x_char) {
284 ar933x_uart_putc(up, up->
port.x_char);
285 up->
port.icount.tx++;
293 ar933x_uart_putc(up, xmit->
buf[xmit->
tail]);
296 up->
port.icount.tx++;
297 }
while (--count > 0);
303 ar933x_uart_start_tx_interrupt(up);
315 spin_lock(&up->
port.lock);
322 AR933X_UART_INT_RX_VALID);
323 ar933x_uart_rx_chars(up);
328 AR933X_UART_INT_TX_EMPTY);
329 ar933x_uart_stop_tx_interrupt(up);
330 ar933x_uart_tx_chars(up);
333 spin_unlock(&up->
port.lock);
338 static int ar933x_uart_startup(
struct uart_port *port)
345 up->
port.irqflags, dev_name(up->
port.dev), up);
359 spin_unlock_irqrestore(&up->
port.lock, flags);
364 static void ar933x_uart_shutdown(
struct uart_port *port)
379 static const char *ar933x_uart_type(
struct uart_port *port)
384 static void ar933x_uart_release_port(
struct uart_port *port)
389 static int ar933x_uart_request_port(
struct uart_port *port)
395 static void ar933x_uart_config_port(
struct uart_port *port,
int flags)
401 static int ar933x_uart_verify_port(
struct uart_port *port,
417 static struct uart_ops ar933x_uart_ops = {
418 .tx_empty = ar933x_uart_tx_empty,
419 .set_mctrl = ar933x_uart_set_mctrl,
420 .get_mctrl = ar933x_uart_get_mctrl,
421 .stop_tx = ar933x_uart_stop_tx,
422 .start_tx = ar933x_uart_start_tx,
423 .stop_rx = ar933x_uart_stop_rx,
424 .enable_ms = ar933x_uart_enable_ms,
425 .break_ctl = ar933x_uart_break_ctl,
426 .startup = ar933x_uart_startup,
427 .shutdown = ar933x_uart_shutdown,
428 .set_termios = ar933x_uart_set_termios,
429 .type = ar933x_uart_type,
430 .release_port = ar933x_uart_release_port,
431 .request_port = ar933x_uart_request_port,
432 .config_port = ar933x_uart_config_port,
433 .verify_port = ar933x_uart_verify_port,
436 #ifdef CONFIG_SERIAL_AR933X_CONSOLE
439 ar933x_console_ports[CONFIG_SERIAL_AR933X_NR_UARTS];
452 }
while ((status & AR933X_UART_DATA_TX_CSR) == 0);
455 static void ar933x_uart_console_putchar(
struct uart_port *port,
int ch)
459 ar933x_uart_wait_xmitr(up);
460 ar933x_uart_putc(up, ch);
463 static void ar933x_uart_console_write(
struct console *co,
const char *
s,
476 locked = spin_trylock(&up->
port.lock);
478 spin_lock(&up->
port.lock);
492 ar933x_uart_wait_xmitr(up);
498 spin_unlock(&up->
port.lock);
503 static int ar933x_uart_console_setup(
struct console *co,
char *
options)
511 if (co->
index < 0 || co->
index >= CONFIG_SERIAL_AR933X_NR_UARTS)
514 up = ar933x_console_ports[co->
index];
524 static struct console ar933x_uart_console = {
526 .write = ar933x_uart_console_write,
528 .setup = ar933x_uart_console_setup,
531 .data = &ar933x_uart_driver,
536 ar933x_console_ports[up->
port.line] =
up;
539 #define AR933X_SERIAL_CONSOLE (&ar933x_uart_console)
543 static inline void ar933x_uart_add_console_port(
struct ar933x_uart_port *up) {}
545 #define AR933X_SERIAL_CONSOLE NULL
552 .dev_name =
"ttyATH",
553 .nr = CONFIG_SERIAL_AR933X_NR_UARTS,
567 pdata = pdev->
dev.platform_data;
575 if (
id > CONFIG_SERIAL_AR933X_NR_UARTS)
612 port->
ops = &ar933x_uart_ops;
614 ar933x_uart_add_console_port(up);
620 platform_set_drvdata(pdev, up);
634 up = platform_get_drvdata(pdev);
635 platform_set_drvdata(pdev,
NULL);
647 .probe = ar933x_uart_probe,
655 static int __init ar933x_uart_init(
void)
659 ar933x_uart_driver.
nr = CONFIG_SERIAL_AR933X_NR_UARTS;
666 goto err_unregister_uart_driver;
670 err_unregister_uart_driver:
676 static void __exit ar933x_uart_exit(
void)