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>
38 #include <asm/ip5000.h>
40 #define SERIAL_UBICOM_BAUDRATE 115200
41 #define SERIAL_UBICOM_DATA_BIT 8 /* Fixed parameter - do not change */
42 #define SERIAL_UBICOM_PAR_BIT 0 /* Fixed parameter - do not change */
43 #define SERIAL_UBICOM_STOP_BIT 1 /* Fixed parameter - do not change */
45 /* UART name and device definitions */
46 #define UBI32_MAILBOX_NAME "ttyUM" // XXX
47 #define UBI32_MAILBOX_MAJOR 207 // XXX
48 #define UBI32_MAILBOX_MINOR 64
50 #define PORT_UBI32_MAILBOX 1235
55 struct ubi32_mailbox_port
{
56 struct uart_port port
;
59 * the uart port is wrapped in another structure in case we need to hold more state than
60 * what we can hold in the uart_port.
61 * Not sure if we need this, I took over the concept from the blackfin driver.
63 } ubi32_mailbox_ports
[NR_PORTS
];
65 struct ubi32_mailbox_resource
{
68 } ubi32_mailbox_resource
[NR_PORTS
] = {
70 * uart_base_addr has to be non-NULL because it is put in the uart_port membase.
71 * If membase if null the kernel skips the configuration and our port_type never gets set.
73 {ISD_MAILBOX_BASE
, ISD_MAILBOX_INT
}
76 static volatile struct ubicom32_isd_mailbox
{
79 volatile u32_t status
;
80 } *ubi32_mailbox
= (struct ubicom32_isd_mailbox
*)ISD_MAILBOX_BASE
;
82 static void ubi32_mailbox_tx_chars(struct ubi32_mailbox_port
*uart
);
84 static void ubi32_mailbox_mctrl_check(struct ubi32_mailbox_port
*uart
);
89 static int mailbox_console_flg
= TRUE
;
90 static int num_timeouts
= 0;
93 * dummy functions and defined to be able to compile the Blackfin code
95 #define UART_GET_LSR(port) (1)
96 #define UART_PUT_LSR(port, bits)
97 #define UART_CLEAR_LSR(port) (1)
106 #define UART_GET_LCR(port) (1)
107 #define UART_PUT_LCR(port, bits)
114 #define UART_GET_IER(port) (1)
115 #define UART_SET_IER(port, bits)
116 #define UART_CLEAR_IER(port, bits)
119 #define UART_GET_CHAR(port) ubi32_mailbox_get_char()
120 #define UART_PUT_CHAR(port, ch) ubi32_mailbox_put_char(ch)
122 #define UART_GET_DLL(port) 0
123 #define UART_PUT_DLL(port, ch)
124 #define UART_GET_DLH(port) 0
125 #define UART_PUT_DLH(port, ch)
126 #define UART_GET_GCTL(port) (0)
127 #define UART_PUT_GCTL(port, ch)
131 * ubi32_mailbox_get_char_avail()
133 static int ubi32_mailbox_get_char_avail(void)
135 return !(ubi32_mailbox
->status
& ISD_MAILBOX_STATUS_IN_EMPTY
);
139 * ubi32_mailbox_get_char()
141 static u32_t
ubi32_mailbox_get_char(void)
143 if (mailbox_console_flg
== TRUE
) {
145 * Mailbox console is connected.
147 while (ubi32_mailbox
->status
& ISD_MAILBOX_STATUS_IN_EMPTY
);
148 return ubi32_mailbox
->in
& 0xff;
152 * Mailbox console was not connected.
154 if (ubi32_mailbox
->status
& ISD_MAILBOX_STATUS_IN_EMPTY
) {
159 * Mailbox console is connecting.
161 mailbox_console_flg
= TRUE
;
163 return ubi32_mailbox
->in
& 0xff;
166 #define MAILBOX_MAX_ATTEMPTS 1000000
167 #define MAILBOX_MAX_TIMEOUTS 5
169 * ubi32_mailbox_put_char()
171 static void ubi32_mailbox_put_char(u32_t v
)
174 * Wait to be able to output.
176 u32_t num_attempts
= 0;
178 if(mailbox_console_flg
== TRUE
) {
179 while(num_attempts
++ < MAILBOX_MAX_ATTEMPTS
) {
180 if(ubi32_mailbox
->status
& ISD_MAILBOX_STATUS_OUT_EMPTY
) {
186 * If timed out more than 5 times on send, mailbox console is disconnected now.
188 if (num_attempts
> MAILBOX_MAX_ATTEMPTS
) {
189 if (num_timeouts
++ > MAILBOX_MAX_TIMEOUTS
) {
190 mailbox_console_flg
= FALSE
;
205 ubi32_mailbox
->out
= v
& 0xff;
208 static void ubi32_mailbox_hw_init(struct ubi32_mailbox_port
*uart
)
210 // NOTE: It does not do any good to do these here because we are running on the linux hardware thread,
211 // and these have to be called on the ldsr thread.
212 // ubicom32_clear_interrupt(ISD_MAILBOX_INT);
213 // ubicom32_enable_interrupt(ISD_MAILBOX_INT);
217 * interrupts are disabled on entry
219 static void ubi32_mailbox_stop_tx(struct uart_port
*port
)
221 // struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
222 // struct circ_buf *xmit = &uart->port.info->xmit;
224 while (!(UART_GET_LSR(uart
) & TEMT
))
228 UART_PUT_LSR(uart
, TFI
);
229 UART_CLEAR_IER(uart
, ETBEI
);
233 * port is locked and interrupts are disabled
235 static void ubi32_mailbox_start_tx(struct uart_port
*port
)
237 struct ubi32_mailbox_port
*uart
= (struct ubi32_mailbox_port
*)port
;
239 UART_SET_IER(uart
, ETBEI
);
241 ubi32_mailbox_tx_chars(uart
);
245 * Interrupts are enabled
247 static void ubi32_mailbox_stop_rx(struct uart_port
*port
)
249 // struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
250 UART_CLEAR_IER(uart
, ERBFI
);
254 * Set the modem control timer to fire immediately.
256 static void ubi32_mailbox_enable_ms(struct uart_port
*port
)
260 static void ubi32_mailbox_rx_chars(struct ubi32_mailbox_port
*uart
)
262 struct uart_info
*info
= uart
->port
.info
;
263 struct tty_struct
*tty
= info
->port
.tty
;
264 unsigned int status
, ch
, flg
;
266 status
= 0; // XXX? UART_GET_LSR(uart);
267 UART_CLEAR_LSR(uart
);
269 ch
= UART_GET_CHAR(uart
);
274 uart
->port
.icount
.rx
++;
277 uart
->port
.icount
.brk
++;
278 if (uart_handle_break(&uart
->port
))
280 status
&= ~(PE
| FE
);
283 uart
->port
.icount
.parity
++;
285 uart
->port
.icount
.overrun
++;
287 uart
->port
.icount
.frame
++;
289 status
&= uart
->port
.read_status_mask
;
293 else if (status
& PE
)
295 else if (status
& FE
)
300 if (uart_handle_sysrq_char(&uart
->port
, ch
))
303 uart_insert_char(&uart
->port
, status
, OE
, ch
, flg
);
306 tty_flip_buffer_push(tty
);
309 static void ubi32_mailbox_tx_chars(struct ubi32_mailbox_port
*uart
)
311 struct circ_buf
*xmit
= &uart
->port
.info
->xmit
;
313 if (uart
->port
.x_char
) {
314 UART_PUT_CHAR(uart
, uart
->port
.x_char
);
315 uart
->port
.icount
.tx
++;
316 uart
->port
.x_char
= 0;
319 * Check the modem control lines before
320 * transmitting anything.
322 ubi32_mailbox_mctrl_check(uart
);
324 if (uart_circ_empty(xmit
) || uart_tx_stopped(&uart
->port
)) {
325 ubi32_mailbox_stop_tx(&uart
->port
);
329 while ((UART_GET_LSR(uart
) & THRE
) && xmit
->tail
!= xmit
->head
) {
330 UART_PUT_CHAR(uart
, xmit
->buf
[xmit
->tail
]);
331 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
332 uart
->port
.icount
.tx
++;
336 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
337 uart_write_wakeup(&uart
->port
);
339 if (uart_circ_empty(xmit
))
340 ubi32_mailbox_stop_tx(&uart
->port
);
343 static irqreturn_t
ubi32_mailbox_isr(int irq
, void *dev_id
)
345 struct ubi32_mailbox_port
*uart
= dev_id
;
347 spin_lock(&uart
->port
.lock
);
349 //XXX?while (UART_GET_LSR(uart) & DR)
354 while (ubi32_mailbox_get_char_avail()) {
355 ubi32_mailbox_rx_chars(uart
);
362 if (this_uart
.tx_in
== this_uart
.tx_out
) {
363 UBICOM32_IO_PORT(SERIAL_UBICOM_PORT
)->int_mask
&= ~IO_PORTX_INT_SERDES_TXBE
;
364 } else if (UBICOM32_IO_PORT(SERIAL_UBICOM_PORT
)->int_status
& IO_PORTX_INT_SERDES_TXBE
) {
365 uart_ubicom32_send(this_uart
.tx_buf
[this_uart
.tx_out
& (SERIAL_UBICOM_BUF_SIZE
- 1)]);
367 UBICOM32_IO_PORT(SERIAL_UBICOM_PORT
)->int_mask
|= IO_PORTX_INT_SERDES_TXBE
;
371 spin_unlock(&uart
->port
.lock
);
376 static irqreturn_t
ubi32_mailbox_tx_int(int irq
, void *dev_id
)
378 struct ubi32_mailbox_port
*uart
= dev_id
;
380 spin_lock(&uart
->port
.lock
);
381 if (UART_GET_LSR(uart
) & THRE
)
382 ubi32_mailbox_tx_chars(uart
);
383 spin_unlock(&uart
->port
.lock
);
390 * Return TIOCSER_TEMT when transmitter is not busy.
392 static unsigned int ubi32_mailbox_tx_empty(struct uart_port
*port
)
394 // struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
397 lsr
= UART_GET_LSR(uart
);
404 static unsigned int ubi32_mailbox_get_mctrl(struct uart_port
*port
)
406 return TIOCM_CTS
| TIOCM_DSR
| TIOCM_CAR
;
409 static void ubi32_mailbox_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
414 * Handle any change of modem status signal since we were last called.
416 static void ubi32_mailbox_mctrl_check(struct ubi32_mailbox_port
*uart
)
421 * Interrupts are always disabled.
423 static void ubi32_mailbox_break_ctl(struct uart_port
*port
, int break_state
)
425 // struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
426 u16 lcr
= UART_GET_LCR(uart
);
431 UART_PUT_LCR(uart
, lcr
);
435 static int ubi32_mailbox_startup(struct uart_port
*port
)
437 struct ubi32_mailbox_port
*uart
= (struct ubi32_mailbox_port
*)port
;
439 if (request_irq(uart
->port
.irq
, ubi32_mailbox_isr
, IRQF_DISABLED
,
440 "UBI32_MAILBOX", uart
)) {
441 printk(KERN_NOTICE
"Unable to attach Ubicom32 SERDES interrupt\n");
445 UART_SET_IER(uart
, ERBFI
);
449 static void ubi32_mailbox_shutdown(struct uart_port
*port
)
451 struct ubi32_mailbox_port
*uart
= (struct ubi32_mailbox_port
*)port
;
453 free_irq(uart
->port
.irq
, uart
);
457 ubi32_mailbox_set_termios(struct uart_port
*port
, struct ktermios
*termios
,
458 struct ktermios
*old
)
460 struct ubi32_mailbox_port
*uart
= (struct ubi32_mailbox_port
*)port
;
462 unsigned int baud
, quot
;
463 unsigned short val
, ier
, lsr
, lcr
= 0;
465 switch (termios
->c_cflag
& CSIZE
) {
479 printk(KERN_ERR
"%s: word lengh not supported\n",
483 if (termios
->c_cflag
& CSTOPB
)
485 if (termios
->c_cflag
& PARENB
)
487 if (!(termios
->c_cflag
& PARODD
))
489 if (termios
->c_cflag
& CMSPAR
)
492 port
->read_status_mask
= OE
;
493 if (termios
->c_iflag
& INPCK
)
494 port
->read_status_mask
|= (FE
| PE
);
495 if (termios
->c_iflag
& (BRKINT
| PARMRK
))
496 port
->read_status_mask
|= BI
;
499 * Characters to ignore
501 port
->ignore_status_mask
= 0;
502 if (termios
->c_iflag
& IGNPAR
)
503 port
->ignore_status_mask
|= FE
| PE
;
504 if (termios
->c_iflag
& IGNBRK
) {
505 port
->ignore_status_mask
|= BI
;
507 * If we're ignoring parity and break indicators,
508 * ignore overruns too (for real raw support).
510 if (termios
->c_iflag
& IGNPAR
)
511 port
->ignore_status_mask
|= OE
;
514 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/16);
515 quot
= uart_get_divisor(port
, baud
);
516 spin_lock_irqsave(&uart
->port
.lock
, flags
);
519 lsr
= UART_GET_LSR(uart
);
520 } while (!(lsr
& TEMT
));
523 ier
= UART_GET_IER(uart
);
524 UART_CLEAR_IER(uart
, 0xF);
526 UART_PUT_DLL(uart
, quot
& 0xFF);
528 UART_PUT_DLH(uart
, (quot
>> 8) & 0xFF);
531 UART_PUT_LCR(uart
, lcr
);
534 UART_SET_IER(uart
, ier
);
536 val
= UART_GET_GCTL(uart
);
538 UART_PUT_GCTL(uart
, val
);
540 spin_unlock_irqrestore(&uart
->port
.lock
, flags
);
543 static const char *ubi32_mailbox_type(struct uart_port
*port
)
545 struct ubi32_mailbox_port
*uart
= (struct ubi32_mailbox_port
*)port
;
547 return uart
->port
.type
== PORT_UBI32_MAILBOX
? "UBI32_MAILBOX" : NULL
;
551 * Release the memory region(s) being used by 'port'.
553 static void ubi32_mailbox_release_port(struct uart_port
*port
)
558 * Request the memory region(s) being used by 'port'.
560 static int ubi32_mailbox_request_port(struct uart_port
*port
)
566 * Configure/autoconfigure the port.
568 static void ubi32_mailbox_config_port(struct uart_port
*port
, int flags
)
570 struct ubi32_mailbox_port
*uart
= (struct ubi32_mailbox_port
*)port
;
572 if (flags
& UART_CONFIG_TYPE
&& ubi32_mailbox_request_port(&uart
->port
) == 0)
573 uart
->port
.type
= PORT_UBI32_MAILBOX
;
577 * Verify the new serial_struct (for TIOCSSERIAL).
578 * The only change we allow are to the flags and type, and
579 * even then only between PORT_UBI32_MAILBOX and PORT_UNKNOWN
582 ubi32_mailbox_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
587 static struct uart_ops ubi32_mailbox_pops
= {
588 .tx_empty
= ubi32_mailbox_tx_empty
,
589 .set_mctrl
= ubi32_mailbox_set_mctrl
,
590 .get_mctrl
= ubi32_mailbox_get_mctrl
,
591 .stop_tx
= ubi32_mailbox_stop_tx
,
592 .start_tx
= ubi32_mailbox_start_tx
,
593 .stop_rx
= ubi32_mailbox_stop_rx
,
594 .enable_ms
= ubi32_mailbox_enable_ms
,
595 .break_ctl
= ubi32_mailbox_break_ctl
,
596 .startup
= ubi32_mailbox_startup
,
597 .shutdown
= ubi32_mailbox_shutdown
,
598 .set_termios
= ubi32_mailbox_set_termios
,
599 .type
= ubi32_mailbox_type
,
600 .release_port
= ubi32_mailbox_release_port
,
601 .request_port
= ubi32_mailbox_request_port
,
602 .config_port
= ubi32_mailbox_config_port
,
603 .verify_port
= ubi32_mailbox_verify_port
,
606 static void __init
ubi32_mailbox_init_ports(void)
608 static int first
= 1;
615 for (i
= 0; i
< NR_PORTS
; i
++) {
616 ubi32_mailbox_ports
[i
].port
.uartclk
= get_sclk();
617 ubi32_mailbox_ports
[i
].port
.ops
= &ubi32_mailbox_pops
;
618 ubi32_mailbox_ports
[i
].port
.line
= i
;
619 ubi32_mailbox_ports
[i
].port
.iotype
= UPIO_MEM
;
620 ubi32_mailbox_ports
[i
].port
.membase
=
621 (void __iomem
*)ubi32_mailbox_resource
[i
].uart_base_addr
;
622 ubi32_mailbox_ports
[i
].port
.mapbase
=
623 ubi32_mailbox_resource
[i
].uart_base_addr
;
624 ubi32_mailbox_ports
[i
].port
.irq
=
625 ubi32_mailbox_resource
[i
].uart_irq
;
626 ubi32_mailbox_ports
[i
].port
.flags
= UPF_BOOT_AUTOCONF
;
627 spin_lock_init(&ubi32_mailbox_ports
[i
].port
.lock
);
629 ubi32_mailbox_hw_init(&ubi32_mailbox_ports
[i
]);
634 #ifdef CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE
636 * If the port was already initialised (eg, by a boot loader),
637 * try to determine the current setup.
640 ubi32_mailbox_console_get_options(struct ubi32_mailbox_port
*uart
, int *baud
,
641 int *parity
, int *bits
)
643 unsigned short status
;
645 status
= UART_GET_IER(uart
) & (ERBFI
| ETBEI
);
646 if (status
== (ERBFI
| ETBEI
)) {
647 /* ok, the port was enabled */
649 unsigned short dlh
, dll
;
651 lcr
= UART_GET_LCR(uart
);
660 switch (lcr
& 0x03) {
661 case 0: *bits
= 5; break;
662 case 1: *bits
= 6; break;
663 case 2: *bits
= 7; break;
664 case 3: *bits
= 8; break;
667 dll
= UART_GET_DLL(uart
);
668 dlh
= UART_GET_DLH(uart
);
670 *baud
= get_sclk() / (16*(dll
| dlh
<< 8));
672 pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __FUNCTION__
, *baud
, *parity
, *bits
);
676 #if defined(CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
677 static struct uart_driver ubi32_mailbox_reg
;
680 ubi32_mailbox_console_setup(struct console
*co
, char *options
)
682 struct ubi32_mailbox_port
*uart
;
683 # ifdef CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE
684 int baud
= SERIAL_UBICOM_BAUDRATE
;
691 * Check whether an invalid uart number has been specified, and
692 * if so, search for the first available port that does have
695 if (co
->index
== -1 || co
->index
>= NR_PORTS
)
697 uart
= &ubi32_mailbox_ports
[co
->index
];
699 # ifdef CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE
701 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
703 ubi32_mailbox_console_get_options(uart
, &baud
, &parity
, &bits
);
705 //JB return uart_set_options(&uart->port, co, baud, parity, bits, flow);
711 #endif /* defined (CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE) ||
712 defined (CONFIG_EARLY_PRINTK) */
714 #ifdef CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE
715 static void ubi32_mailbox_console_putchar(struct uart_port
*port
, int ch
)
717 // struct ubi32_mailbox_port *uart = (struct ubi32_mailbox_port *)port;
718 while (!(UART_GET_LSR(uart
) & THRE
))
720 UART_PUT_CHAR(uart
, ch
);
725 * Interrupts are disabled on entering
728 ubi32_mailbox_console_write(struct console
*co
, const char *s
, unsigned int count
)
730 struct ubi32_mailbox_port
*uart
= &ubi32_mailbox_ports
[co
->index
];
731 unsigned long flags
= 0;
733 spin_lock_irqsave(&uart
->port
.lock
, flags
);
734 uart_console_write(&uart
->port
, s
, count
, ubi32_mailbox_console_putchar
);
735 spin_unlock_irqrestore(&uart
->port
.lock
, flags
);
739 static struct console ubi32_mailbox_console
= {
740 .name
= UBI32_MAILBOX_NAME
,
741 .write
= ubi32_mailbox_console_write
,
742 .device
= uart_console_device
,
743 .setup
= ubi32_mailbox_console_setup
,
744 .flags
= CON_PRINTBUFFER
,
746 .data
= &ubi32_mailbox_reg
,
749 static int __init
ubi32_mailbox_console_init(void)
751 ubi32_mailbox_init_ports();
752 register_console(&ubi32_mailbox_console
);
755 console_initcall(ubi32_mailbox_console_init
);
757 #define UBI32_MAILBOX_CONSOLE &ubi32_mailbox_console
759 #define UBI32_MAILBOX_CONSOLE NULL
760 #endif /* CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE */
763 #ifdef CONFIG_EARLY_PRINTK
764 static __init
void ubi32_mailbox_early_putc(struct uart_port
*port
, int ch
)
766 UART_PUT_CHAR(uart
, ch
);
769 static __init
void ubi32_mailbox_early_write(struct console
*con
, const char *s
,
772 struct ubi32_mailbox_port
*uart
= &ubi32_mailbox_ports
[con
->index
];
775 for (i
= 0; i
< n
; i
++, s
++) {
777 ubi32_mailbox_early_putc(&uart
->port
, '\r');
778 ubi32_mailbox_early_putc(&uart
->port
, *s
);
782 static struct __init console ubi32_mailbox_early_console
= {
784 .write
= ubi32_mailbox_early_write
,
785 .device
= uart_console_device
,
786 .flags
= CON_PRINTBUFFER
,
787 .setup
= ubi32_mailbox_console_setup
,
789 .data
= &ubi32_mailbox_reg
,
793 * XXX Unused in our driver. Need to find out what the termios initialization is good/needed for.
795 struct console __init
*ubi32_mailbox_early_init(unsigned int port
,
798 struct ubi32_mailbox_port
*uart
;
801 if (port
== -1 || port
>= NR_PORTS
)
803 ubi32_mailbox_init_ports();
804 ubi32_mailbox_early_console
.index
= port
;
805 uart
= &ubi32_mailbox_ports
[port
];
811 ubi32_mailbox_set_termios(&uart
->port
, &t
, &t
);
812 return &ubi32_mailbox_early_console
;
815 #endif /* CONFIG_SERIAL_UBI32_MAILBOX_CONSOLE */
817 static struct uart_driver ubi32_mailbox_reg
= {
818 .owner
= THIS_MODULE
,
819 .driver_name
= "ubi32_mailbox",
820 .dev_name
= UBI32_MAILBOX_NAME
,
821 .major
= UBI32_MAILBOX_MAJOR
,
822 .minor
= UBI32_MAILBOX_MINOR
,
824 .cons
= UBI32_MAILBOX_CONSOLE
,
827 static int ubi32_mailbox_suspend(struct platform_device
*dev
, pm_message_t state
)
829 struct ubi32_mailbox_port
*uart
= platform_get_drvdata(dev
);
832 uart_suspend_port(&ubi32_mailbox_reg
, &uart
->port
);
837 static int ubi32_mailbox_resume(struct platform_device
*dev
)
839 struct ubi32_mailbox_port
*uart
= platform_get_drvdata(dev
);
842 uart_resume_port(&ubi32_mailbox_reg
, &uart
->port
);
847 static int ubi32_mailbox_probe(struct platform_device
*dev
)
849 struct resource
*res
= dev
->resource
;
852 for (i
= 0; i
< dev
->num_resources
; i
++, res
++)
853 if (res
->flags
& IORESOURCE_MEM
)
856 if (i
< dev
->num_resources
) {
857 for (i
= 0; i
< NR_PORTS
; i
++, res
++) {
858 if (ubi32_mailbox_ports
[i
].port
.mapbase
!= res
->start
)
860 ubi32_mailbox_ports
[i
].port
.dev
= &dev
->dev
;
861 uart_add_one_port(&ubi32_mailbox_reg
, &ubi32_mailbox_ports
[i
].port
);
862 platform_set_drvdata(dev
, &ubi32_mailbox_ports
[i
]);
869 static int ubi32_mailbox_remove(struct platform_device
*pdev
)
871 struct ubi32_mailbox_port
*uart
= platform_get_drvdata(pdev
);
873 platform_set_drvdata(pdev
, NULL
);
876 uart_remove_one_port(&ubi32_mailbox_reg
, &uart
->port
);
881 static struct platform_driver ubi32_mailbox_driver
= {
882 .probe
= ubi32_mailbox_probe
,
883 .remove
= ubi32_mailbox_remove
,
884 .suspend
= ubi32_mailbox_suspend
,
885 .resume
= ubi32_mailbox_resume
,
887 .name
= "ubi32-mbox",
888 .owner
= THIS_MODULE
,
892 static int __init
ubi32_mailbox_init(void)
896 pr_info("Serial: Ubicom32 mailbox serial driver.\n");
898 mailbox_console_flg
= TRUE
;
900 ubi32_mailbox_init_ports();
902 ret
= uart_register_driver(&ubi32_mailbox_reg
);
904 ret
= platform_driver_register(&ubi32_mailbox_driver
);
906 pr_debug("uart register failed\n");
907 uart_unregister_driver(&ubi32_mailbox_reg
);
912 * XXX HACK: currently probe does not get called, but the port needs to be added to work.
914 uart_add_one_port(&ubi32_mailbox_reg
, &ubi32_mailbox_ports
[0].port
);
918 static void __exit
ubi32_mailbox_exit(void)
920 platform_driver_unregister(&ubi32_mailbox_driver
);
921 uart_unregister_driver(&ubi32_mailbox_reg
);
924 module_init(ubi32_mailbox_init
);
925 module_exit(ubi32_mailbox_exit
);
927 MODULE_ALIAS_CHARDEV_MAJOR(UBI32_MAILBOX_MAJOR
);
928 MODULE_ALIAS("platform:ubi32_mailbox");