2 * drivers/serial/ubi32_uarttio.c
3 * Ubicom32 Serial Virtual Peripherial Driver
5 * (C) Copyright 2009, Ubicom, Inc.
7 * This file is part of the Ubicom32 Linux Kernel Port.
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
24 #include <linux/module.h>
25 #include <linux/ioport.h>
26 #include <linux/init.h>
27 #include <linux/console.h>
28 #include <linux/sysrq.h>
29 #include <linux/platform_device.h>
30 #include <linux/tty.h>
31 #include <linux/tty_flip.h>
32 #include <linux/serial_core.h>
34 #include <asm/ip5000.h>
36 #include <asm/thread.h>
37 #include <asm/uart_tio.h>
39 #define DRIVER_NAME "ubi32_uarttio"
42 * For storing the module parameters.
44 #define UBI32_UARTTIO_MAX_PARAM_LEN 80
45 static char utio_ports_param[UBI32_UARTTIO_MAX_PARAM_LEN];
48 * UART name and device definitions
50 #define UBI32_UARTTIO_NAME "ttyUV" // XXX
51 #define UBI32_UARTTIO_MAJOR 206 // XXX
52 #define UBI32_UARTTIO_MINOR 64 // XXX
55 * The following structures are allocated statically because the
56 * memory allocation subsystem is not initialized this early on
62 struct ubi32_uarttio_port {
63 struct uarttio_uart *uart;
67 struct uart_port port;
72 * If this value is set, the port has had its direction set already
76 static struct ubi32_uarttio_port uarttio_ports[CONFIG_SERIAL_UBI32_UARTTIO_NR_UARTS];
79 * Number of ports currently initialized
81 static int uarttio_nports;
84 * Per device structure
86 struct ubi32_uarttio_instance {
87 struct uarttio_regs *regs;
88 struct ubi32_uarttio_port *ports;
91 u8_t driver_registered;
94 static struct ubi32_uarttio_instance uarttio_inst;
96 #ifdef CONFIG_SERIAL_UBI32_UARTTIO_CONSOLE
97 static struct console ubi32_uarttio_console;
98 #define UBI32_UARTTIO_CONSOLE &ubi32_uarttio_console
100 #define UBI32_UARTTIO_CONSOLE NULL
103 static struct uart_driver ubi32_uarttio_uart_driver = {
104 .owner = THIS_MODULE,
105 .driver_name = DRIVER_NAME,
106 .dev_name = UBI32_UARTTIO_NAME,
107 .major = UBI32_UARTTIO_MAJOR,
108 .minor = UBI32_UARTTIO_MINOR,
109 .cons = UBI32_UARTTIO_CONSOLE,
112 #ifdef UBI32_UARTTIO_UNUSED
114 * ubi32_uarttio_get_send_space
116 static int ubi32_uarttio_get_send_space(struct uarttio_uart *uart)
118 int count = uart->tx_fifo_head - uart->tx_fifo_tail;
120 count += uart->tx_fifo_size;
122 return uart->tx_fifo_size - count;
127 * ubi32_uarttio_get_recv_ready
129 static int ubi32_uarttio_get_recv_ready(struct uarttio_uart *uart)
131 int count = uart->rx_fifo_head - uart->rx_fifo_tail;
133 count += uart->rx_fifo_size;
139 * ubi32_uarttio_get_char()
141 static u8_t ubi32_uarttio_get_char(struct uarttio_uart *uart)
146 u32_t tail = uart->rx_fifo_tail;
147 u8_t data = uart->rx_fifo[tail];
149 if (++tail == uart->rx_fifo_size) {
152 uart->rx_fifo_tail = tail;
158 * ubi32_uarttio_put_char()
160 static int ubi32_uarttio_put_char(struct uarttio_uart *uart, u8_t c)
162 u32_t head = uart->tx_fifo_head;
168 if (++head == uart->tx_fifo_size) {
173 * If there isn't any space, return EBUSY
175 if (head == uart->tx_fifo_tail) {
180 * Put the character in the queue
182 uart->tx_fifo[prev] = c;
183 uart->tx_fifo_head = head;
189 * ubi32_uarttio_set_baud
191 static int ubi32_uarttio_set_baud(struct ubi32_uarttio_port *uup, unsigned int baud)
193 if (uup->uart->current_baud_rate == baud) {
197 uup->uart->baud_rate = baud;
198 uup->uart->flags |= UARTTIO_UART_FLAG_SET_RATE;
199 while (uup->uart->flags & UARTTIO_UART_FLAG_SET_RATE) {
203 if (uup->uart->current_baud_rate != baud) {
205 * Failed to set baud rate
207 printk(KERN_WARNING "Invalid baud rate %u, running at %u\n", baud, uup->uart->current_baud_rate);
215 * ubi32_uarttio_handle_receive
217 static void ubi32_uarttio_handle_receive(struct ubi32_uarttio_port *uup, int stat)
219 struct uarttio_uart *uart = uup->uart;
220 struct uart_port *port = &uup->port;
221 struct tty_struct *tty = port->info->port.tty;
222 unsigned char ch = 0;
223 char flag = TTY_NORMAL;
226 if ((stat & (UARTTIO_UART_INT_RX | UARTTIO_UART_INT_RXFRAME | UARTTIO_UART_INT_RXOVF)) == 0) {
230 if (stat & UARTTIO_UART_INT_RX) {
231 count = ubi32_uarttio_get_recv_ready(uart);
232 port->icount.rx += count;
235 if (stat & UARTTIO_UART_INT_RXOVF) {
236 port->icount.overrun++;
239 if (stat & UARTTIO_UART_INT_RXFRAME) {
240 port->icount.frame++;
243 stat &= ~port->ignore_status_mask;
245 if (stat & UARTTIO_UART_INT_RX) {
247 for (i = 0; i < count; i++) {
248 ch = ubi32_uarttio_get_char(uart);
249 tty_insert_flip_char(tty, ch, flag);
253 if (stat & UARTTIO_UART_INT_RXFRAME) {
254 tty_insert_flip_char(tty, 0, TTY_FRAME);
257 if (stat & UARTTIO_UART_INT_RXOVF) {
258 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
263 * ubi32_uarttio_stop_tx
264 * interrupts are disabled on entry
266 static void ubi32_uarttio_stop_tx(struct uart_port *port)
268 struct ubi32_uarttio_port *uup = port->private_data;
270 uup->uart->int_mask &= ~UARTTIO_UART_INT_TXBE;
274 * ubi32_uarttio_handle_transmit
276 static void ubi32_uarttio_handle_transmit(struct ubi32_uarttio_port *uup, int stat)
278 struct uarttio_uart *uart = uup->uart;
279 struct uart_port *port = &uup->port;
280 struct circ_buf *xmit = &port->info->xmit;
282 if (!(stat & UARTTIO_UART_INT_TXBE)) {
287 if (ubi32_uarttio_put_char(uart, port->x_char)) {
295 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
296 ubi32_uarttio_stop_tx(port);
301 * Send as many characters as we can
303 while (ubi32_uarttio_put_char(uart, xmit->buf[xmit->tail]) == 0) {
304 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
306 if (uart_circ_empty(xmit)) {
312 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) {
313 uart_write_wakeup(port);
316 if (uart_circ_empty(xmit)) {
317 ubi32_uarttio_stop_tx(port);
322 * ubi32_uarttio_start_tx
323 * port is locked and interrupts are disabled
325 static void ubi32_uarttio_start_tx(struct uart_port *port)
327 struct ubi32_uarttio_port *uup = port->private_data;
328 struct uarttio_uart *uart = uup->uart;
330 uart->int_mask |= UARTTIO_UART_INT_TXBE;
334 * ubi32_uarttio_stop_rx
335 * Interrupts are enabled
337 static void ubi32_uarttio_stop_rx(struct uart_port *port)
339 struct ubi32_uarttio_port *uup = port->private_data;
340 struct uarttio_uart *uart = uup->uart;
343 * don't forward any more data (like !CREAD)
345 uart->int_mask &= ~UARTTIO_UART_INT_RX;
346 port->ignore_status_mask = UARTTIO_UART_INT_RX;
350 * ubi32_uarttio_enable_ms
351 * Set the modem control timer to fire immediately.
353 static void ubi32_uarttio_enable_ms(struct uart_port *port)
361 static irqreturn_t ubi32_uarttio_isr(int irq, void *appdata)
363 struct ubi32_uarttio_port *uup = uarttio_ports;
367 * Service all of the ports
369 for (i = 0; i < uarttio_nports; i++) {
372 if (!(uup->uart->flags & UARTTIO_UART_FLAG_ENABLED)) {
377 spin_lock(&uup->port.lock);
379 flags = uup->uart->int_flags;
381 uup->uart->int_flags = 0;
383 ubi32_uarttio_handle_receive(uup, flags);
384 ubi32_uarttio_handle_transmit(uup, flags);
386 tty_flip_buffer_push(uup->port.info->port.tty);
388 spin_unlock(&uup->port.lock);
397 * ubi32_uarttio_tx_empty
398 * Return TIOCSER_TEMT when transmitter is not busy.
400 static unsigned int ubi32_uarttio_tx_empty(struct uart_port *port)
402 struct ubi32_uarttio_port *uup = port->private_data;
404 if (uup->uart->tx_fifo_head == uup->uart->tx_fifo_tail) {
412 * ubi32_uarttio_get_mctrl
414 static unsigned int ubi32_uarttio_get_mctrl(struct uart_port *port)
416 return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
420 * ubi32_uarttio_set_mctrl
422 static void ubi32_uarttio_set_mctrl(struct uart_port *port, unsigned int mctrl)
428 * ubi32_uarttio_break_ctl
430 static void ubi32_uarttio_break_ctl(struct uart_port *port, int break_state)
436 * ubi32_uarttio_startup
438 static int ubi32_uarttio_startup(struct uart_port *port)
440 struct ubi32_uarttio_port *uup = port->private_data;
441 struct uarttio_uart *uart = uup->uart;
443 uart->flags |= UARTTIO_UART_FLAG_ENABLED;
445 uart->int_mask |= UARTTIO_UART_INT_TXBE | UARTTIO_UART_INT_RX;
451 * ubi32_uarttio_shutdown
453 static void ubi32_uarttio_shutdown(struct uart_port *port)
455 struct ubi32_uarttio_port *uup = port->private_data;
456 struct uarttio_uart *uart = uup->uart;
459 uart->flags &= ~UARTTIO_UART_FLAG_ENABLED;
463 * ubi32_uarttio_set_termios
465 static void ubi32_uarttio_set_termios(struct uart_port *port, struct ktermios *termios, struct ktermios *old)
467 struct ubi32_uarttio_port *uup = port->private_data;
471 spin_lock_irqsave(&port->lock, flags);
474 port->read_status_mask = UBI32_UARTTIO_RX | UBI32_UARTTIO_RXOVF | UBI32_UARTTIO_TXOVF;
476 if (termios->c_iflag & INPCK) {
477 port->read_status_mask |= UBI32_UARTTIO_RXFRAME;
481 port->ignore_status_mask = 0;
482 if (termios->c_iflag & IGNPAR) {
483 port->ignore_status_mask |= UARTTIO_UART_INT_RXFRAME |
484 UARTTIO_UART_INT_RXOVF;
488 * ignore all characters if CREAD is not set
490 if ((termios->c_cflag & CREAD) == 0) {
491 port->ignore_status_mask |= UARTTIO_UART_INT_RX |
492 UARTTIO_UART_INT_RXFRAME |
493 UARTTIO_UART_INT_RXOVF;
497 baud = uart_get_baud_rate(port, termios, old, 0, 460800);
498 uart_update_timeout(port, termios->c_cflag, baud);
500 ubi32_uarttio_set_baud(uup, baud);
501 spin_unlock_irqrestore(&port->lock, flags);
507 static const char *ubi32_uarttio_type(struct uart_port *port)
509 return (port->type == PORT_UBI32_UARTTIO) ? "UBI32_UARTTIO" : NULL;
513 * ubi32_uarttio_release_port
514 * Release the memory region(s) being used by 'port'.
516 static void ubi32_uarttio_release_port(struct uart_port *port)
521 * ubi32_uarttio_request_port
522 * Request the memory region(s) being used by 'port'.
524 static int ubi32_uarttio_request_port(struct uart_port *port)
530 * ubi32_uarttio_config_port
531 * Configure/autoconfigure the port.
533 static void ubi32_uarttio_config_port(struct uart_port *port, int flags)
535 if ((flags & UART_CONFIG_TYPE) && (ubi32_uarttio_request_port(port) == 0)) {
536 port->type = PORT_UBI32_UARTTIO;
541 * ubi32_uarttio_verify_port
542 * Verify the new serial_struct (for TIOCSSERIAL).
544 * The only change we allow are to the flags and type, and
545 * even then only between PORT_UBI32_UARTTIO and PORT_UNKNOWN
547 static int ubi32_uarttio_verify_port(struct uart_port *port, struct serial_struct *ser)
552 static struct uart_ops ubi32_uarttio_pops = {
553 .tx_empty = ubi32_uarttio_tx_empty,
554 .set_mctrl = ubi32_uarttio_set_mctrl,
555 .get_mctrl = ubi32_uarttio_get_mctrl,
556 .stop_tx = ubi32_uarttio_stop_tx,
557 .start_tx = ubi32_uarttio_start_tx,
558 .stop_rx = ubi32_uarttio_stop_rx,
559 .enable_ms = ubi32_uarttio_enable_ms,
560 .break_ctl = ubi32_uarttio_break_ctl,
561 .startup = ubi32_uarttio_startup,
562 .shutdown = ubi32_uarttio_shutdown,
563 .set_termios = ubi32_uarttio_set_termios,
564 .type = ubi32_uarttio_type,
565 .release_port = ubi32_uarttio_release_port,
566 .request_port = ubi32_uarttio_request_port,
567 .config_port = ubi32_uarttio_config_port,
568 .verify_port = ubi32_uarttio_verify_port,
572 * ubi32_uarttio_add_ports
574 static int __init ubi32_uarttio_add_ports(void)
577 struct ubi32_uarttio_port *uup = uarttio_ports;
580 for (i = 0; i < uarttio_nports; i++) {
584 res = gpio_request(uup->tx_pin, "ubi32_uarttio_tx");
586 printk(KERN_WARNING "Failed to request GPIO %d\n", uup->tx_pin);
591 res = gpio_request(uup->rx_pin, "ubi32_uarttio_rx");
593 gpio_free(uup->tx_pin);
594 printk(KERN_WARNING "Failed to request GPIO %d\n", uup->rx_pin);
599 res = uart_add_one_port(&ubi32_uarttio_uart_driver, &uup->port);
601 gpio_free(uup->rx_pin);
602 gpio_free(uup->tx_pin);
604 printk(KERN_WARNING "Failed to add port %d,%d\n", uup->tx_pin, uup->rx_pin);
610 * Set the direction of the ports now, after we're sure that everything is ok
612 if (!uup->port_init) {
613 gpio_direction_output(uup->tx_pin, 1);
614 gpio_direction_input(uup->rx_pin);
624 * ubi32_uarttio_cleanup
626 static void ubi32_uarttio_cleanup(void)
628 struct ubi32_uarttio_port *uup;
632 * Stop the hardware thread
634 if (uarttio_inst.regs) {
635 thread_disable(uarttio_inst.regs->thread);
637 if (uarttio_inst.irq_requested) {
638 free_irq(uarttio_inst.irq, NULL);
642 * Get rid of the ports
644 uup = uarttio_inst.ports;
645 for (i = 0; i < uarttio_nports; i++) {
646 gpio_free(uup->tx_pin);
647 gpio_free(uup->rx_pin);
649 uart_remove_one_port(&ubi32_uarttio_uart_driver, &uup->port);
654 if (uarttio_inst.driver_registered) {
655 uart_unregister_driver(&ubi32_uarttio_uart_driver);
660 * ubi32_uarttio_setup_port
661 * Setup a port in the TIO registers
663 static int ubi32_uarttio_setup_port(int index,
664 struct uarttio_uart *uart,
665 unsigned int baud, unsigned int tx_pin,
668 struct ubi32_uarttio_port *uup = &uarttio_ports[index];
669 void *tx_port = ubi_gpio_get_port(tx_pin);
670 void *rx_port = ubi_gpio_get_port(rx_pin);
673 * Verify the ports are on chip
675 if (!tx_port || !rx_port) {
676 printk(KERN_WARNING "Invalid port(s) specified: %u or %u\n", tx_pin, rx_pin);
680 uup->tx_pin = tx_pin;
681 uup->rx_pin = rx_pin;
685 * Setup the port structure
687 uup->port.ops = &ubi32_uarttio_pops;
688 uup->port.line = index;
689 uup->port.iotype = UPIO_MEM;
690 uup->port.flags = UPF_BOOT_AUTOCONF;
691 uup->port.fifosize = uup->uart->tx_fifo_size;
692 uup->port.private_data = uup;
695 * We share this IRQ across all ports
697 uup->port.irq = uarttio_inst.irq;
700 * We really don't have a mem/map base but without these variables
701 * set, the serial_core won't startup.
703 uup->port.membase = (void __iomem *)uup;
704 uup->port.mapbase = (resource_size_t)uup;
705 spin_lock_init(&uup->port.lock);
708 * Set up the hardware
710 uart->flags = UARTTIO_UART_FLAG_SET_RATE | UARTTIO_UART_FLAG_RESET;
712 uart->tx_port = (unsigned int)tx_port;
713 uart->tx_pin = gpio_pin_index(tx_pin);
715 uart->tx_stop_bits = 1;
717 uart->rx_port = (unsigned int)rx_port;
718 uart->rx_pin = gpio_pin_index(rx_pin);
720 uart->rx_stop_bits = 1;
722 uart->baud_rate = baud;
727 enum ubi32_uarttio_parse_states {
728 UBI32_UARTTIO_PARSE_STATE_BAUD,
729 UBI32_UARTTIO_PARSE_STATE_TX_PIN,
730 UBI32_UARTTIO_PARSE_STATE_RX_PIN,
731 UBI32_UARTTIO_PARSE_STATE_HS,
732 UBI32_UARTTIO_PARSE_STATE_CTS_PIN,
733 UBI32_UARTTIO_PARSE_STATE_RTS_PIN,
737 * ubi32_uarttio_parse_param
739 static int ubi32_uarttio_parse_param(char *str)
750 enum ubi32_uarttio_parse_states state = UBI32_UARTTIO_PARSE_STATE_BAUD;
751 struct uarttio_uart *uart = uarttio_inst.regs->uarts;
754 * Run though the options and generate the proper structures
756 res = get_option(&str, &i);
757 while ((res == 2) || (res == 1)) {
759 case UBI32_UARTTIO_PARSE_STATE_BAUD:
761 * If we are here and nfound > 0 then create the port
762 * based on the previous input
768 if (ubi32_uarttio_setup_port(nfound - 1, uart, baud, tx_pin, rx_pin)) {
774 printk(KERN_INFO "Serial port %d: tx=%d:rx=%d @ %d\n", nfound, tx_pin, rx_pin, baud);
780 * Reset the variables and go to the next state
784 state = UBI32_UARTTIO_PARSE_STATE_TX_PIN;
787 case UBI32_UARTTIO_PARSE_STATE_TX_PIN:
789 state = UBI32_UARTTIO_PARSE_STATE_RX_PIN;
792 case UBI32_UARTTIO_PARSE_STATE_RX_PIN:
794 state = UBI32_UARTTIO_PARSE_STATE_HS;
797 case UBI32_UARTTIO_PARSE_STATE_HS:
800 state = UBI32_UARTTIO_PARSE_STATE_CTS_PIN;
804 if (nfound == uarttio_inst.regs->max_uarts) {
805 printk(KERN_WARNING "Maximum number of serial ports reached\n");
809 state = UBI32_UARTTIO_PARSE_STATE_BAUD;
812 case UBI32_UARTTIO_PARSE_STATE_CTS_PIN:
814 state = UBI32_UARTTIO_PARSE_STATE_RTS_PIN;
817 case UBI32_UARTTIO_PARSE_STATE_RTS_PIN:
820 if (nfound == uarttio_inst.regs->max_uarts) {
821 printk(KERN_WARNING "Maximum number of serial ports reached\n");
825 state = UBI32_UARTTIO_PARSE_STATE_BAUD;
828 res = get_option(&str, &i);
831 if ((res > 2) || state != UBI32_UARTTIO_PARSE_STATE_BAUD) {
832 printk(KERN_WARNING "Parameter syntax error.\n");
838 * Create the final port
840 if (ubi32_uarttio_setup_port(nfound - 1, uart, baud, tx_pin, rx_pin)) {
843 printk(KERN_INFO "Serial port %d: tx=%d:rx=%d @ %d\n", nfound, tx_pin, rx_pin, baud);
846 uarttio_nports = nfound;
848 return nfound ? 0 : -ENODEV;
854 uart = uarttio_inst.regs->uarts;
855 for (i = 0; i < uarttio_inst.regs->max_uarts; i++) {
864 * ubi32_uarttio_probe
866 static int ubi32_uarttio_probe(void)
869 struct uarttio_node *uart_node;
870 char *str = utio_ports_param;
872 static int probe_result;
875 * We only want to be probed once, we could be probed twice
876 * for example if we are used as a console
884 * Extract the TIO name from the setup string
895 probe_result = -EINVAL;
899 uart_node = (struct uarttio_node *)devtree_find_node(utio_ports_param);
901 probe_result = -ENODEV;
905 uarttio_inst.irq = uart_node->dn.recvirq;
906 uarttio_inst.regs = uart_node->regs;
909 * Parse module parameters.
911 ret = ubi32_uarttio_parse_param(str);
913 ubi32_uarttio_cleanup();
918 ubi32_uarttio_uart_driver.nr = uarttio_nports;
923 #if defined(CONFIG_SERIAL_UBI32_UARTTIO_CONSOLE)
925 * ubi32_uarttio_console_setup
927 static int __init ubi32_uarttio_console_setup(struct console *co, char *options)
933 struct ubi32_uarttio_port *uup;
936 * Check whether an invalid uart number has been specified, and
937 * if so, search for the first available port that does have
940 if (co->index == -1 || co->index >= uarttio_nports) {
943 uup = &uarttio_ports[co->index];
944 baud = uup->uart->baud_rate;
945 uup->uart->flags |= UARTTIO_UART_FLAG_ENABLED;
949 * We have to use the direct interface because the gpio
950 * subsystem is not available at this point.
953 UBICOM32_GPIO_SET_PIN_HIGH(uup->tx_pin);
954 UBICOM32_GPIO_SET_PIN_OUTPUT(uup->tx_pin);
955 UBICOM32_GPIO_SET_PIN_INPUT(uup->rx_pin);
960 thread_enable(uarttio_inst.regs->thread);
966 uart_parse_options(options, &baud, &parity, &bits, &flow);
967 if (ubi32_uarttio_set_baud(uup, baud)) {
968 baud = uup->uart->current_baud_rate;
972 return uart_set_options(&uup->port, co, baud, 'n', 8, 'n');
976 * ubi32_uarttio_console_putchar
978 static void ubi32_uarttio_console_putchar(struct uart_port *port, int ch)
980 struct ubi32_uarttio_port *uup = port->private_data;
982 while (ubi32_uarttio_put_char(uup->uart, ch)) {
988 * ubi32_uarttio_console_write
989 * Interrupts are disabled on entering
991 static void ubi32_uarttio_console_write(struct console *co, const char *s, unsigned int count)
993 struct uart_port *port = &(uarttio_ports[co->index].port);
994 unsigned long flags = 0;
996 spin_lock_irqsave(&port->lock, flags);
997 uart_console_write(port, s, count, ubi32_uarttio_console_putchar);
998 spin_unlock_irqrestore(&port->lock, flags);
1001 static struct console ubi32_uarttio_console = {
1002 .name = UBI32_UARTTIO_NAME,
1003 .write = ubi32_uarttio_console_write,
1004 .device = uart_console_device,
1005 .setup = ubi32_uarttio_console_setup,
1006 .flags = CON_PRINTBUFFER,
1008 .data = &ubi32_uarttio_uart_driver,
1011 static int __init ubi32_uarttio_console_init(void)
1015 res = ubi32_uarttio_probe();
1020 register_console(&ubi32_uarttio_console);
1023 console_initcall(ubi32_uarttio_console_init);
1024 #endif /* CONFIG_SERIAL_UBI32_UARTTIO_CONSOLE */
1027 * ubi32_serial_suspend
1029 static int ubi32_uarttio_suspend(struct platform_device *pdev, pm_message_t state)
1032 for (i = 0; i < uarttio_nports; i++) {
1033 uart_suspend_port(&ubi32_uarttio_uart_driver, &uarttio_ports[i].port);
1040 * ubi32_serial_resume
1042 static int ubi32_uarttio_resume(struct platform_device *pdev)
1045 for (i = 0; i < uarttio_nports; i++) {
1046 uart_resume_port(&ubi32_uarttio_uart_driver, &uarttio_ports[i].port);
1053 * ubi32_uarttio_remove
1055 static int __devexit ubi32_uarttio_remove(struct platform_device *pdev)
1057 ubi32_uarttio_cleanup();
1059 uart_unregister_driver(&ubi32_uarttio_uart_driver);
1064 static struct platform_driver ubi32_uarttio_platform_driver = {
1065 .remove = __devexit_p(ubi32_uarttio_remove),
1066 .suspend = ubi32_uarttio_suspend,
1067 .resume = ubi32_uarttio_resume,
1069 .name = DRIVER_NAME,
1070 .owner = THIS_MODULE,
1076 * Called at boot time.
1078 * uarttio=TIONAME,(baud,tx_pin,rx_pin,handshake[,cts_pin,rts_pin],...)
1079 * TIONAME is the name of the devtree node which describes the UARTTIO
1080 * pin is the index of the pin, i.e. PA4 is 5 [(port * 32) + pin]
1081 * handshake = 1 to enable handshaking, provide cts_pin, rts_pin (UNSUPPORTED)
1082 * handshake = 0 to disable handshaking, do not provide cts_pin, rts_pin
1083 * Ex: uarttio=UARTTIO,57600,7,6,0,9600,8,9,0
1085 static int __init ubi32_uarttio_setup(char *str)
1087 strncpy(utio_ports_param, str, UBI32_UARTTIO_MAX_PARAM_LEN);
1088 utio_ports_param[UBI32_UARTTIO_MAX_PARAM_LEN - 1] = 0;
1091 __setup("uarttio=", ubi32_uarttio_setup);
1095 * ubi32_uarttio_init
1097 static int __init ubi32_uarttio_init(void)
1102 ret = ubi32_uarttio_probe();
1108 * Request the IRQ (do it here since many ports share the same IRQ)
1110 ret = request_irq(uarttio_inst.irq, ubi32_uarttio_isr, IRQF_DISABLED, DRIVER_NAME, NULL);
1112 printk(KERN_WARNING "Could not request IRQ %d\n", uarttio_inst.irq);
1115 uarttio_inst.irq_requested = 1;
1118 * Register the UART driver and add the ports
1120 ret = uart_register_driver(&ubi32_uarttio_uart_driver);
1124 uarttio_inst.driver_registered = 1;
1126 ret = ubi32_uarttio_add_ports();
1128 ubi32_uarttio_cleanup();
1135 thread_enable(uarttio_inst.regs->thread);
1137 for (i = 0; i < uarttio_nports; i++) {
1138 pr_info("Serial: Ubicom32 uarttio #%d: tx:%d rx:%d baud:%d\n",
1139 i, uarttio_ports[i].tx_pin, uarttio_ports[i].rx_pin,
1140 uarttio_ports[i].uart->current_baud_rate);
1142 pr_info("Serial: Ubicom32 uarttio started on thread:%d irq:%d\n", uarttio_inst.regs->thread, uarttio_inst.irq);
1147 ubi32_uarttio_cleanup();
1150 module_init(ubi32_uarttio_init);
1153 * ubi32_uarttio_exit
1155 static void __exit ubi32_uarttio_exit(void)
1157 platform_driver_unregister(&ubi32_uarttio_platform_driver);
1159 module_exit(ubi32_uarttio_exit);
1161 module_param_string(ports, utio_ports_param, sizeof(utio_ports_param), 0444);
1162 MODULE_PARM_DESC(ports, "Sets the ports to allocate: ports=TIONAME,(baud,txpin,rxpin,handshake[,ctspin,rtspin],...)\n"
1163 " TIONAME is the name of the devtree node which describes the UARTTIO\n"
1164 " pin is the index of the pin, i.e. PA4 is 5 [(port * 32) + pin]\n"
1165 " handshake = 1 to enable handshaking, provide ctspin, rtspin (UNSUPPORTED)\n"
1166 " handshake = 0 to disable handshaking, do not provide ctspin, rtspin\n"
1167 " Ex: ports=UARTTIO,57600,7,6,0,9600,8,9,0\n");
1168 MODULE_AUTHOR("Patrick Tjin <pat.tjin@ubicom.com>");
1169 MODULE_DESCRIPTION("Ubicom serial virtual peripherial driver");
1170 MODULE_LICENSE("GPL");
1171 MODULE_ALIAS_CHARDEV_MAJOR(UBI32_UARTTIO_MAJOR);
1172 MODULE_ALIAS("platform:" DRIVER_NAME);