2 * drivers/serial/ubi32_mailbox.c
3 * Ubicom32 On-Chip Mailbox 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/>.
23 * Ubicom32 implementation derived from (with many thanks):
28 #include <linux/module.h>
29 #include <linux/ioport.h>
30 #include <linux/init.h>
31 #include <linux/console.h>
32 #include <linux/sysrq.h>
33 #include <linux/platform_device.h>
34 #include <linux/tty.h>
35 #include <linux/tty_flip.h>
36 #include <linux/serial_core.h>
37 #include <linux/version.h>
39 #include <asm/ip5000.h>
41 #define SERIAL_UBICOM_BAUDRATE 115200
42 #define SERIAL_UBICOM_DATA_BIT 8 /* Fixed parameter - do not change */
43 #define SERIAL_UBICOM_PAR_BIT 0 /* Fixed parameter - do not change */
44 #define SERIAL_UBICOM_STOP_BIT 1 /* Fixed parameter - do not change */
46 /* UART name and device definitions */
47 #define UBI32_MAILBOX_NAME "ttyUM" // XXX
48 #define UBI32_MAILBOX_MAJOR 207 // XXX
49 #define UBI32_MAILBOX_MINOR 64
51 #define PORT_UBI32_MAILBOX 1235
56 struct ubi32_mailbox_port {
57 struct uart_port port;
60 * the uart port is wrapped in another structure in case we need to hold more state than
61 * what we can hold in the uart_port.
62 * Not sure if we need this, I took over the concept from the blackfin driver.
64 } ubi32_mailbox_ports[NR_PORTS];
66 struct ubi32_mailbox_resource {
69 } ubi32_mailbox_resource[NR_PORTS] = {
71 * uart_base_addr has to be non-NULL because it is put in the uart_port membase.
72 * If membase if null the kernel skips the configuration and our port_type never gets set.
74 {ISD_MAILBOX_BASE, ISD_MAILBOX_INT}
77 static volatile struct ubicom32_isd_mailbox {
80 volatile u32_t status;
81 } *ubi32_mailbox = (struct ubicom32_isd_mailbox *)ISD_MAILBOX_BASE;
83 static void ubi32_mailbox_tx_chars(struct ubi32_mailbox_port *uart);
85 static void ubi32_mailbox_mctrl_check(struct ubi32_mailbox_port *uart);
90 static int mailbox_console_flg = TRUE;
91 static int num_timeouts = 0;
94 * dummy functions and defined to be able to compile the Blackfin code
96 #define UART_GET_LSR(port) (1)
97 #define UART_PUT_LSR(port, bits)
98 #define UART_CLEAR_LSR(port) (1)
107 #define UART_GET_LCR(port) (1)
108 #define UART_PUT_LCR(port, bits)
115 #define UART_GET_IER(port) (1)
116 #define UART_SET_IER(port, bits)
117 #define UART_CLEAR_IER(port, bits)
120 #define UART_GET_CHAR(port) ubi32_mailbox_get_char()
121 #define UART_PUT_CHAR(port, ch) ubi32_mailbox_put_char(ch)
123 #define UART_GET_DLL(port) 0
124 #define UART_PUT_DLL(port, ch)
125 #define UART_GET_DLH(port) 0
126 #define UART_PUT_DLH(port, ch)
127 #define UART_GET_GCTL(port) (0)
128 #define UART_PUT_GCTL(port, ch)
132 * ubi32_mailbox_get_char_avail()
134 static int ubi32_mailbox_get_char_avail(void)
136 return !(ubi32_mailbox->status & ISD_MAILBOX_STATUS_IN_EMPTY);
140 * ubi32_mailbox_get_char()
142 static u32_t ubi32_mailbox_get_char(void)
144 if (mailbox_console_flg == TRUE) {
146 * Mailbox console is connected.
148 while (ubi32_mailbox->status & ISD_MAILBOX_STATUS_IN_EMPTY);
149 return ubi32_mailbox->in & 0xff;
153 * Mailbox console was not connected.
155 if (ubi32_mailbox->status & ISD_MAILBOX_STATUS_IN_EMPTY) {
160 * Mailbox console is connecting.
162 mailbox_console_flg = TRUE;
164 return ubi32_mailbox->in & 0xff;
167 #define MAILBOX_MAX_ATTEMPTS 1000000
168 #define MAILBOX_MAX_TIMEOUTS 5
170 * ubi32_mailbox_put_char()
172 static void ubi32_mailbox_put_char(u32_t v)
175 * Wait to be able to output.
177 u32_t num_attempts = 0;
179 if(mailbox_console_flg == TRUE) {
180 while(num_attempts++ < MAILBOX_MAX_ATTEMPTS) {
181 if(ubi32_mailbox->status & ISD_MAILBOX_STATUS_OUT_EMPTY) {
187 * If timed out more than 5 times on send, mailbox console is disconnected now.
189 if (num_attempts > MAILBOX_MAX_ATTEMPTS) {
190 if (num_timeouts++ > MAILBOX_MAX_TIMEOUTS) {
191 mailbox_console_flg = FALSE;
206 ubi32_mailbox->out = v & 0xff;
209 static void ubi32_mailbox_hw_init(struct ubi32_mailbox_port *uart)
211 // NOTE: It does not do any good to do these here because we are running on the linux hardware thread,
212 // and these have to be called on the ldsr thread.
213 // ubicom32_clear_interrupt(ISD_MAILBOX_INT);
214 // ubicom32_enable_interrupt(ISD_MAILBOX_INT);
218 * interrupts are disabled on entry
220 static void ubi32_mailbox_stop_tx(struct uart_port *port)
222 // struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
223 // struct circ_buf *xmit = &uart->port.info->xmit;
225 while (!(UART_GET_LSR(uart) & TEMT))
229 UART_PUT_LSR(uart, TFI);
230 UART_CLEAR_IER(uart, ETBEI);
234 * port is locked and interrupts are disabled
236 static void ubi32_mailbox_start_tx(struct uart_port *port)
238 struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
240 UART_SET_IER(uart, ETBEI);
242 ubi32_mailbox_tx_chars(uart);
246 * Interrupts are enabled
248 static void ubi32_mailbox_stop_rx(struct uart_port *port)
250 // struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
251 UART_CLEAR_IER(uart, ERBFI);
255 * Set the modem control timer to fire immediately.
257 static void ubi32_mailbox_enable_ms(struct uart_port *port)
261 static void ubi32_mailbox_rx_chars(struct ubi32_mailbox_port *uart)
263 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)
264 struct uart_state *state = uart->port.state;
265 struct tty_struct *tty = state->port.tty;
267 struct uart_info *info = uart->port.info;
268 struct tty_struct *tty = info->port.tty;
270 unsigned int status, ch, flg;
272 status = 0; // XXX? UART_GET_LSR(uart);
273 UART_CLEAR_LSR(uart);
275 ch = UART_GET_CHAR(uart);
280 uart->port.icount.rx++;
283 uart->port.icount.brk++;
284 if (uart_handle_break(&uart->port))
286 status &= ~(PE | FE);
289 uart->port.icount.parity++;
291 uart->port.icount.overrun++;
293 uart->port.icount.frame++;
295 status &= uart->port.read_status_mask;
299 else if (status & PE)
301 else if (status & FE)
306 if (uart_handle_sysrq_char(&uart->port, ch))
309 uart_insert_char(&uart->port, status, OE, ch, flg);
312 tty_flip_buffer_push(tty);
315 static void ubi32_mailbox_tx_chars(struct ubi32_mailbox_port *uart)
317 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)
318 struct circ_buf *xmit = &uart->port.state->xmit;
320 struct circ_buf *xmit = &uart->port.info->xmit;
323 if (uart->port.x_char) {
324 UART_PUT_CHAR(uart, uart->port.x_char);
325 uart->port.icount.tx++;
326 uart->port.x_char = 0;
329 * Check the modem control lines before
330 * transmitting anything.
332 ubi32_mailbox_mctrl_check(uart);
334 if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) {
335 ubi32_mailbox_stop_tx(&uart->port);
339 while ((UART_GET_LSR(uart) & THRE) && xmit->tail != xmit->head) {
340 UART_PUT_CHAR(uart, xmit->buf[xmit->tail]);
341 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
342 uart->port.icount.tx++;
346 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
347 uart_write_wakeup(&uart->port);
349 if (uart_circ_empty(xmit))
350 ubi32_mailbox_stop_tx(&uart->port);
353 static irqreturn_t ubi32_mailbox_isr(int irq, void *dev_id)
355 struct ubi32_mailbox_port *uart = dev_id;
357 spin_lock(&uart->port.lock);
359 //XXX?while (UART_GET_LSR(uart) & DR)
364 while (ubi32_mailbox_get_char_avail()) {
365 ubi32_mailbox_rx_chars(uart);
372 if (this_uart.tx_in == this_uart.tx_out) {
373 UBICOM32_IO_PORT(SERIAL_UBICOM_PORT)->int_mask &= ~IO_PORTX_INT_SERDES_TXBE;
374 } else if (UBICOM32_IO_PORT(SERIAL_UBICOM_PORT)->int_status & IO_PORTX_INT_SERDES_TXBE) {
375 uart_ubicom32_send(this_uart.tx_buf[this_uart.tx_out & (SERIAL_UBICOM_BUF_SIZE - 1)]);
377 UBICOM32_IO_PORT(SERIAL_UBICOM_PORT)->int_mask |= IO_PORTX_INT_SERDES_TXBE;
381 spin_unlock(&uart->port.lock);
386 static irqreturn_t ubi32_mailbox_tx_int(int irq, void *dev_id)
388 struct ubi32_mailbox_port *uart = dev_id;
390 spin_lock(&uart->port.lock);
391 if (UART_GET_LSR(uart) & THRE)
392 ubi32_mailbox_tx_chars(uart);
393 spin_unlock(&uart->port.lock);
400 * Return TIOCSER_TEMT when transmitter is not busy.
402 static unsigned int ubi32_mailbox_tx_empty(struct uart_port *port)
404 // struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
407 lsr = UART_GET_LSR(uart);
414 static unsigned int ubi32_mailbox_get_mctrl(struct uart_port *port)
416 return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
419 static void ubi32_mailbox_set_mctrl(struct uart_port *port, unsigned int mctrl)
424 * Handle any change of modem status signal since we were last called.
426 static void ubi32_mailbox_mctrl_check(struct ubi32_mailbox_port *uart)
431 * Interrupts are always disabled.
433 static void ubi32_mailbox_break_ctl(struct uart_port *port, int break_state)
435 // struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
436 u16 lcr = UART_GET_LCR(uart);
441 UART_PUT_LCR(uart, lcr);
445 static int ubi32_mailbox_startup(struct uart_port *port)
447 struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
449 if (request_irq(uart->port.irq, ubi32_mailbox_isr, IRQF_DISABLED,
450 "UBI32_MAILBOX", uart)) {
451 printk(KERN_NOTICE "Unable to attach Ubicom32 SERDES interrupt\n");
455 UART_SET_IER(uart, ERBFI);
459 static void ubi32_mailbox_shutdown(struct uart_port *port)
461 struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
463 free_irq(uart->port.irq, uart);
467 ubi32_mailbox_set_termios(struct uart_port *port, struct ktermios *termios,
468 struct ktermios *old)
470 struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
472 unsigned int baud, quot;
473 unsigned short val, ier, lsr, lcr = 0;
475 switch (termios->c_cflag & CSIZE) {
489 printk(KERN_ERR "%s: word lengh not supported\n",
493 if (termios->c_cflag & CSTOPB)
495 if (termios->c_cflag & PARENB)
497 if (!(termios->c_cflag & PARODD))
499 if (termios->c_cflag & CMSPAR)
502 port->read_status_mask = OE;
503 if (termios->c_iflag & INPCK)
504 port->read_status_mask |= (FE | PE);
505 if (termios->c_iflag & (BRKINT | PARMRK))
506 port->read_status_mask |= BI;
509 * Characters to ignore
511 port->ignore_status_mask = 0;
512 if (termios->c_iflag & IGNPAR)
513 port->ignore_status_mask |= FE | PE;
514 if (termios->c_iflag & IGNBRK) {
515 port->ignore_status_mask |= BI;
517 * If we're ignoring parity and break indicators,
518 * ignore overruns too (for real raw support).
520 if (termios->c_iflag & IGNPAR)
521 port->ignore_status_mask |= OE;
524 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
525 quot = uart_get_divisor(port, baud);
526 spin_lock_irqsave(&uart->port.lock, flags);
529 lsr = UART_GET_LSR(uart);
530 } while (!(lsr & TEMT));
533 ier = UART_GET_IER(uart);
534 UART_CLEAR_IER(uart, 0xF);
536 UART_PUT_DLL(uart, quot & 0xFF);
538 UART_PUT_DLH(uart, (quot >> 8) & 0xFF);
541 UART_PUT_LCR(uart, lcr);
544 UART_SET_IER(uart, ier);
546 val = UART_GET_GCTL(uart);
548 UART_PUT_GCTL(uart, val);
550 spin_unlock_irqrestore(&uart->port.lock, flags);
553 static const char *ubi32_mailbox_type(struct uart_port *port)
555 struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
557 return uart->port.type == PORT_UBI32_MAILBOX ? "UBI32_MAILBOX" : NULL;
561 * Release the memory region(s) being used by 'port'.
563 static void ubi32_mailbox_release_port(struct uart_port *port)
568 * Request the memory region(s) being used by 'port'.
570 static int ubi32_mailbox_request_port(struct uart_port *port)
576 * Configure/autoconfigure the port.
578 static void ubi32_mailbox_config_port(struct uart_port *port, int flags)
580 struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
582 if (flags & UART_CONFIG_TYPE && ubi32_mailbox_request_port(&uart->port) == 0)
583 uart->port.type = PORT_UBI32_MAILBOX;
587 * Verify the new serial_struct (for TIOCSSERIAL).
588 * The only change we allow are to the flags and type, and
589 * even then only between PORT_UBI32_MAILBOX and PORT_UNKNOWN
592 ubi32_mailbox_verify_port(struct uart_port *port, struct serial_struct *ser)
597 static struct uart_ops ubi32_mailbox_pops = {
598 .tx_empty = ubi32_mailbox_tx_empty,
599 .set_mctrl = ubi32_mailbox_set_mctrl,
600 .get_mctrl = ubi32_mailbox_get_mctrl,
601 .stop_tx = ubi32_mailbox_stop_tx,
602 .start_tx = ubi32_mailbox_start_tx,
603 .stop_rx = ubi32_mailbox_stop_rx,
604 .enable_ms = ubi32_mailbox_enable_ms,
605 .break_ctl = ubi32_mailbox_break_ctl,
606 .startup = ubi32_mailbox_startup,
607 .shutdown = ubi32_mailbox_shutdown,
608 .set_termios = ubi32_mailbox_set_termios,
609 .type = ubi32_mailbox_type,
610 .release_port = ubi32_mailbox_release_port,
611 .request_port = ubi32_mailbox_request_port,
612 .config_port = ubi32_mailbox_config_port,
613 .verify_port = ubi32_mailbox_verify_port,
616 static void __init ubi32_mailbox_init_ports(void)
618 static int first = 1;
625 for (i = 0; i < NR_PORTS; i++) {
626 ubi32_mailbox_ports[i].port.uartclk = get_sclk();
627 ubi32_mailbox_ports[i].port.ops = &ubi32_mailbox_pops;
628 ubi32_mailbox_ports[i].port.line = i;
629 ubi32_mailbox_ports[i].port.iotype = UPIO_MEM;
630 ubi32_mailbox_ports[i].port.membase =
631 (void __iomem *)ubi32_mailbox_resource[i].uart_base_addr;
632 ubi32_mailbox_ports[i].port.mapbase =
633 ubi32_mailbox_resource[i].uart_base_addr;
634 ubi32_mailbox_ports[i].port.irq =
635 ubi32_mailbox_resource[i].uart_irq;
636 ubi32_mailbox_ports[i].port.flags = UPF_BOOT_AUTOCONF;
637 spin_lock_init(&ubi32_mailbox_ports[i].port.lock);
639 ubi32_mailbox_hw_init(&ubi32_mailbox_ports[i]);
644 #ifdef CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE
646 * If the port was already initialised (eg, by a boot loader),
647 * try to determine the current setup.
650 ubi32_mailbox_console_get_options(struct ubi32_mailbox_port *uart, int *baud,
651 int *parity, int *bits)
653 unsigned short status;
655 status = UART_GET_IER(uart) & (ERBFI | ETBEI);
656 if (status == (ERBFI | ETBEI)) {
657 /* ok, the port was enabled */
659 unsigned short dlh, dll;
661 lcr = UART_GET_LCR(uart);
670 switch (lcr & 0x03) {
671 case 0: *bits = 5; break;
672 case 1: *bits = 6; break;
673 case 2: *bits = 7; break;
674 case 3: *bits = 8; break;
677 dll = UART_GET_DLL(uart);
678 dlh = UART_GET_DLH(uart);
680 *baud = get_sclk() / (16*(dll | dlh << 8));
682 pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __FUNCTION__, *baud, *parity, *bits);
686 #if defined(CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
687 static struct uart_driver ubi32_mailbox_reg;
690 ubi32_mailbox_console_setup(struct console *co, char *options)
692 struct ubi32_mailbox_port *uart;
693 # ifdef CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE
694 int baud = SERIAL_UBICOM_BAUDRATE;
701 * Check whether an invalid uart number has been specified, and
702 * if so, search for the first available port that does have
705 if (co->index == -1 || co->index >= NR_PORTS)
707 uart = &ubi32_mailbox_ports[co->index];
709 # ifdef CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE
711 uart_parse_options(options, &baud, &parity, &bits, &flow);
713 ubi32_mailbox_console_get_options(uart, &baud, &parity, &bits);
715 //JB return uart_set_options(&uart->port, co, baud, parity, bits, flow);
721 #endif /* defined (CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE) ||
722 defined (CONFIG_EARLY_PRINTK) */
724 #ifdef CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE
725 static void ubi32_mailbox_console_putchar(struct uart_port *port, int ch)
727 // struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
728 while (!(UART_GET_LSR(uart) & THRE))
730 UART_PUT_CHAR(uart, ch);
735 * Interrupts are disabled on entering
738 ubi32_mailbox_console_write(struct console *co, const char *s, unsigned int count)
740 struct ubi32_mailbox_port *uart = &ubi32_mailbox_ports[co->index];
741 unsigned long flags = 0;
743 spin_lock_irqsave(&uart->port.lock, flags);
744 uart_console_write(&uart->port, s, count, ubi32_mailbox_console_putchar);
745 spin_unlock_irqrestore(&uart->port.lock, flags);
749 static struct console ubi32_mailbox_console = {
750 .name = UBI32_MAILBOX_NAME,
751 .write = ubi32_mailbox_console_write,
752 .device = uart_console_device,
753 .setup = ubi32_mailbox_console_setup,
754 .flags = CON_PRINTBUFFER,
756 .data = &ubi32_mailbox_reg,
759 static int __init ubi32_mailbox_console_init(void)
761 ubi32_mailbox_init_ports();
762 register_console(&ubi32_mailbox_console);
765 console_initcall(ubi32_mailbox_console_init);
767 #define UBI32_MAILBOX_CONSOLE &ubi32_mailbox_console
769 #define UBI32_MAILBOX_CONSOLE NULL
770 #endif /* CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE */
773 #ifdef CONFIG_EARLY_PRINTK
774 static __init void ubi32_mailbox_early_putc(struct uart_port *port, int ch)
776 UART_PUT_CHAR(uart, ch);
779 static __init void ubi32_mailbox_early_write(struct console *con, const char *s,
782 struct ubi32_mailbox_port *uart = &ubi32_mailbox_ports[con->index];
785 for (i = 0; i < n; i++, s++) {
787 ubi32_mailbox_early_putc(&uart->port, '\r');
788 ubi32_mailbox_early_putc(&uart->port, *s);
792 static struct __init console ubi32_mailbox_early_console = {
794 .write = ubi32_mailbox_early_write,
795 .device = uart_console_device,
796 .flags = CON_PRINTBUFFER,
797 .setup = ubi32_mailbox_console_setup,
799 .data = &ubi32_mailbox_reg,
803 * XXX Unused in our driver. Need to find out what the termios initialization is good/needed for.
805 struct console __init *ubi32_mailbox_early_init(unsigned int port,
808 struct ubi32_mailbox_port *uart;
811 if (port == -1 || port >= NR_PORTS)
813 ubi32_mailbox_init_ports();
814 ubi32_mailbox_early_console.index = port;
815 uart = &ubi32_mailbox_ports[port];
821 ubi32_mailbox_set_termios(&uart->port, &t, &t);
822 return &ubi32_mailbox_early_console;
825 #endif /* CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE */
827 static struct uart_driver ubi32_mailbox_reg = {
828 .owner = THIS_MODULE,
829 .driver_name = "ubi32_mailbox",
830 .dev_name = UBI32_MAILBOX_NAME,
831 .major = UBI32_MAILBOX_MAJOR,
832 .minor = UBI32_MAILBOX_MINOR,
834 .cons = UBI32_MAILBOX_CONSOLE,
837 static int ubi32_mailbox_suspend(struct platform_device *dev, pm_message_t state)
839 struct ubi32_mailbox_port *uart = platform_get_drvdata(dev);
842 uart_suspend_port(&ubi32_mailbox_reg, &uart->port);
847 static int ubi32_mailbox_resume(struct platform_device *dev)
849 struct ubi32_mailbox_port *uart = platform_get_drvdata(dev);
852 uart_resume_port(&ubi32_mailbox_reg, &uart->port);
857 static int ubi32_mailbox_probe(struct platform_device *dev)
859 struct resource *res = dev->resource;
862 for (i = 0; i < dev->num_resources; i++, res++)
863 if (res->flags & IORESOURCE_MEM)
866 if (i < dev->num_resources) {
867 for (i = 0; i < NR_PORTS; i++, res++) {
868 if (ubi32_mailbox_ports[i].port.mapbase != res->start)
870 ubi32_mailbox_ports[i].port.dev = &dev->dev;
871 uart_add_one_port(&ubi32_mailbox_reg, &ubi32_mailbox_ports[i].port);
872 platform_set_drvdata(dev, &ubi32_mailbox_ports[i]);
879 static int ubi32_mailbox_remove(struct platform_device *pdev)
881 struct ubi32_mailbox_port *uart = platform_get_drvdata(pdev);
883 platform_set_drvdata(pdev, NULL);
886 uart_remove_one_port(&ubi32_mailbox_reg, &uart->port);
891 static struct platform_driver ubi32_mailbox_driver = {
892 .probe = ubi32_mailbox_probe,
893 .remove = ubi32_mailbox_remove,
894 .suspend = ubi32_mailbox_suspend,
895 .resume = ubi32_mailbox_resume,
897 .name = "ubi32-mbox",
898 .owner = THIS_MODULE,
902 static int __init ubi32_mailbox_init(void)
906 pr_info("Serial: Ubicom32 mailbox serial driver.\n");
908 mailbox_console_flg = TRUE;
910 ubi32_mailbox_init_ports();
912 ret = uart_register_driver(&ubi32_mailbox_reg);
914 ret = platform_driver_register(&ubi32_mailbox_driver);
916 pr_debug("uart register failed\n");
917 uart_unregister_driver(&ubi32_mailbox_reg);
922 * XXX HACK: currently probe does not get called, but the port needs to be added to work.
924 uart_add_one_port(&ubi32_mailbox_reg, &ubi32_mailbox_ports[0].port);
928 static void __exit ubi32_mailbox_exit(void)
930 platform_driver_unregister(&ubi32_mailbox_driver);
931 uart_unregister_driver(&ubi32_mailbox_reg);
934 module_init(ubi32_mailbox_init);
935 module_exit(ubi32_mailbox_exit);
937 MODULE_ALIAS_CHARDEV_MAJOR(UBI32_MAILBOX_MAJOR);
938 MODULE_ALIAS("platform:ubi32_mailbox");