2 * Blackfin On-Chip Sport Emulated UART Driver
4 * Copyright 2006-2009 Analog Devices Inc.
6 * Enter bugs at http://blackfin.uclinux.org/
8 * Licensed under the GPL-2 or later.
12 * This driver and the hardware supported are in term of EE-191 of ADI.
13 * http://www.analog.com/UploadedFiles/Application_Notes/399447663EE191.pdf
14 * This application note describe how to implement a UART on a Sharc DSP,
15 * but this driver is implemented on Blackfin Processor.
16 * Transmit Frame Sync is not used by this driver to transfer data out.
21 #define DRV_NAME "bfin-sport-uart"
22 #define DEVICE_NAME "ttySS"
23 #define pr_fmt(fmt) DRV_NAME ": " fmt
25 #include <linux/module.h>
26 #include <linux/ioport.h>
28 #include <linux/init.h>
29 #include <linux/console.h>
30 #include <linux/sysrq.h>
31 #include <linux/platform_device.h>
32 #include <linux/tty.h>
33 #include <linux/tty_flip.h>
34 #include <linux/serial_core.h>
36 #include <asm/delay.h>
37 #include <asm/portmux.h>
39 #include "bfin_sport_uart.h"
41 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
42 unsigned short bfin_uart_pin_req_sport0
[] =
43 {P_SPORT0_TFS
, P_SPORT0_DTPRI
, P_SPORT0_TSCLK
, P_SPORT0_RFS
, \
44 P_SPORT0_DRPRI
, P_SPORT0_RSCLK
, P_SPORT0_DRSEC
, P_SPORT0_DTSEC
, 0};
46 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
47 unsigned short bfin_uart_pin_req_sport1
[] =
48 {P_SPORT1_TFS
, P_SPORT1_DTPRI
, P_SPORT1_TSCLK
, P_SPORT1_RFS
, \
49 P_SPORT1_DRPRI
, P_SPORT1_RSCLK
, P_SPORT1_DRSEC
, P_SPORT1_DTSEC
, 0};
51 #ifdef CONFIG_SERIAL_BFIN_SPORT2_UART
52 unsigned short bfin_uart_pin_req_sport2
[] =
53 {P_SPORT2_TFS
, P_SPORT2_DTPRI
, P_SPORT2_TSCLK
, P_SPORT2_RFS
, \
54 P_SPORT2_DRPRI
, P_SPORT2_RSCLK
, P_SPORT2_DRSEC
, P_SPORT2_DTSEC
, 0};
56 #ifdef CONFIG_SERIAL_BFIN_SPORT3_UART
57 unsigned short bfin_uart_pin_req_sport3
[] =
58 {P_SPORT3_TFS
, P_SPORT3_DTPRI
, P_SPORT3_TSCLK
, P_SPORT3_RFS
, \
59 P_SPORT3_DRPRI
, P_SPORT3_RSCLK
, P_SPORT3_DRSEC
, P_SPORT3_DTSEC
, 0};
62 struct sport_uart_port
{
63 struct uart_port port
;
66 unsigned short rxmask
;
67 unsigned short txmask1
;
68 unsigned short txmask2
;
70 /* unsigned char parib; */
73 static void sport_uart_tx_chars(struct sport_uart_port
*up
);
74 static void sport_stop_tx(struct uart_port
*port
);
76 static inline void tx_one_byte(struct sport_uart_port
*up
, unsigned int value
)
78 pr_debug("%s value:%x, mask1=0x%x, mask2=0x%x\n", __func__
, value
,
79 up
->txmask1
, up
->txmask2
);
81 /* Place Start and Stop bits */
82 __asm__
__volatile__ (
84 "%[val] = %[val] & %[mask1];"
85 "%[val] = %[val] | %[mask2];"
87 : [mask1
]"d"(up
->txmask1
), [mask2
]"d"(up
->txmask2
)
90 pr_debug("%s value:%x\n", __func__
, value
);
92 SPORT_PUT_TX(up
, value
);
95 static inline unsigned char rx_one_byte(struct sport_uart_port
*up
)
98 unsigned char extract
;
99 u32 tmp_mask1
, tmp_mask2
, tmp_shift
, tmp
;
101 if ((up
->csize
+ up
->stopb
) > 7)
102 value
= SPORT_GET_RX32(up
);
104 value
= SPORT_GET_RX(up
);
106 pr_debug("%s value:%x, cs=%d, mask=0x%x\n", __func__
, value
,
107 up
->csize
, up
->rxmask
);
110 __asm__
__volatile__ (
112 "%[mask1] = %[rxmask];"
113 "%[mask2] = 0x0200(Z);"
115 "LSETUP(.Lloop_s, .Lloop_e) LC0 = %[lc];"
117 "%[tmp] = extract(%[val], %[mask1].L)(Z);"
118 "%[tmp] <<= %[shift];"
119 "%[extr] = %[extr] | %[tmp];"
120 "%[mask1] = %[mask1] - %[mask2];"
123 : [extr
]"=&d"(extract
), [shift
]"=&d"(tmp_shift
), [tmp
]"=&d"(tmp
),
124 [mask1
]"=&d"(tmp_mask1
), [mask2
]"=&d"(tmp_mask2
)
125 : [val
]"d"(value
), [rxmask
]"d"(up
->rxmask
), [lc
]"a"(up
->csize
)
126 : "ASTAT", "LB0", "LC0", "LT0"
129 pr_debug(" extract:%x\n", extract
);
133 static int sport_uart_setup(struct sport_uart_port
*up
, int size
, int baud_rate
)
135 int tclkdiv
, rclkdiv
;
136 unsigned int sclk
= get_sclk();
138 /* Set TCR1 and TCR2, TFSR is not enabled for uart */
139 SPORT_PUT_TCR1(up
, (ITFS
| TLSBIT
| ITCLK
));
140 SPORT_PUT_TCR2(up
, size
+ 1);
141 pr_debug("%s TCR1:%x, TCR2:%x\n", __func__
, SPORT_GET_TCR1(up
), SPORT_GET_TCR2(up
));
143 /* Set RCR1 and RCR2 */
144 SPORT_PUT_RCR1(up
, (RCKFE
| LARFS
| LRFS
| RFSR
| IRCLK
));
145 SPORT_PUT_RCR2(up
, (size
+ 1) * 2 - 1);
146 pr_debug("%s RCR1:%x, RCR2:%x\n", __func__
, SPORT_GET_RCR1(up
), SPORT_GET_RCR2(up
));
148 tclkdiv
= sclk
/ (2 * baud_rate
) - 1;
149 rclkdiv
= sclk
/ (2 * baud_rate
* 2) - 1;
150 SPORT_PUT_TCLKDIV(up
, tclkdiv
);
151 SPORT_PUT_RCLKDIV(up
, rclkdiv
);
153 pr_debug("%s sclk:%d, baud_rate:%d, tclkdiv:%d, rclkdiv:%d\n",
154 __func__
, sclk
, baud_rate
, tclkdiv
, rclkdiv
);
159 static irqreturn_t
sport_uart_rx_irq(int irq
, void *dev_id
)
161 struct sport_uart_port
*up
= dev_id
;
162 struct tty_struct
*tty
= up
->port
.state
->port
.tty
;
165 spin_lock(&up
->port
.lock
);
167 while (SPORT_GET_STAT(up
) & RXNE
) {
168 ch
= rx_one_byte(up
);
169 up
->port
.icount
.rx
++;
171 if (!uart_handle_sysrq_char(&up
->port
, ch
))
172 tty_insert_flip_char(tty
, ch
, TTY_NORMAL
);
174 tty_flip_buffer_push(tty
);
176 spin_unlock(&up
->port
.lock
);
181 static irqreturn_t
sport_uart_tx_irq(int irq
, void *dev_id
)
183 struct sport_uart_port
*up
= dev_id
;
185 spin_lock(&up
->port
.lock
);
186 sport_uart_tx_chars(up
);
187 spin_unlock(&up
->port
.lock
);
192 static irqreturn_t
sport_uart_err_irq(int irq
, void *dev_id
)
194 struct sport_uart_port
*up
= dev_id
;
195 struct tty_struct
*tty
= up
->port
.state
->port
.tty
;
196 unsigned int stat
= SPORT_GET_STAT(up
);
198 spin_lock(&up
->port
.lock
);
200 /* Overflow in RX FIFO */
202 up
->port
.icount
.overrun
++;
203 tty_insert_flip_char(tty
, 0, TTY_OVERRUN
);
204 SPORT_PUT_STAT(up
, ROVF
); /* Clear ROVF bit */
206 /* These should not happen */
207 if (stat
& (TOVF
| TUVF
| RUVF
)) {
208 pr_err("SPORT Error:%s %s %s\n",
209 (stat
& TOVF
) ? "TX overflow" : "",
210 (stat
& TUVF
) ? "TX underflow" : "",
211 (stat
& RUVF
) ? "RX underflow" : "");
212 SPORT_PUT_TCR1(up
, SPORT_GET_TCR1(up
) & ~TSPEN
);
213 SPORT_PUT_RCR1(up
, SPORT_GET_RCR1(up
) & ~RSPEN
);
217 spin_unlock(&up
->port
.lock
);
221 /* Reqeust IRQ, Setup clock */
222 static int sport_startup(struct uart_port
*port
)
224 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
227 pr_debug("%s enter\n", __func__
);
228 ret
= request_irq(up
->port
.irq
, sport_uart_rx_irq
, 0,
229 "SPORT_UART_RX", up
);
231 dev_err(port
->dev
, "unable to request SPORT RX interrupt\n");
235 ret
= request_irq(up
->port
.irq
+1, sport_uart_tx_irq
, 0,
236 "SPORT_UART_TX", up
);
238 dev_err(port
->dev
, "unable to request SPORT TX interrupt\n");
242 ret
= request_irq(up
->err_irq
, sport_uart_err_irq
, 0,
243 "SPORT_UART_STATUS", up
);
245 dev_err(port
->dev
, "unable to request SPORT status interrupt\n");
251 free_irq(up
->port
.irq
+1, up
);
253 free_irq(up
->port
.irq
, up
);
258 static void sport_uart_tx_chars(struct sport_uart_port
*up
)
260 struct circ_buf
*xmit
= &up
->port
.state
->xmit
;
262 if (SPORT_GET_STAT(up
) & TXF
)
265 if (up
->port
.x_char
) {
266 tx_one_byte(up
, up
->port
.x_char
);
267 up
->port
.icount
.tx
++;
272 if (uart_circ_empty(xmit
) || uart_tx_stopped(&up
->port
)) {
273 sport_stop_tx(&up
->port
);
277 while(!(SPORT_GET_STAT(up
) & TXF
) && !uart_circ_empty(xmit
)) {
278 tx_one_byte(up
, xmit
->buf
[xmit
->tail
]);
279 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
-1);
280 up
->port
.icount
.tx
++;
283 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
284 uart_write_wakeup(&up
->port
);
287 static unsigned int sport_tx_empty(struct uart_port
*port
)
289 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
292 stat
= SPORT_GET_STAT(up
);
293 pr_debug("%s stat:%04x\n", __func__
, stat
);
300 static unsigned int sport_get_mctrl(struct uart_port
*port
)
302 pr_debug("%s enter\n", __func__
);
303 return (TIOCM_CTS
| TIOCM_CD
| TIOCM_DSR
);
306 static void sport_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
308 pr_debug("%s enter\n", __func__
);
311 static void sport_stop_tx(struct uart_port
*port
)
313 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
315 pr_debug("%s enter\n", __func__
);
317 /* Although the hold register is empty, last byte is still in shift
318 * register and not sent out yet. So, put a dummy data into TX FIFO.
319 * Then, sport tx stops when last byte is shift out and the dummy
320 * data is moved into the shift register.
322 SPORT_PUT_TX(up
, 0xffff);
323 while (!(SPORT_GET_STAT(up
) & TXHRE
))
326 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) & ~TSPEN
));
332 static void sport_start_tx(struct uart_port
*port
)
334 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
336 pr_debug("%s enter\n", __func__
);
338 /* Write data into SPORT FIFO before enable SPROT to transmit */
339 sport_uart_tx_chars(up
);
341 /* Enable transmit, then an interrupt will generated */
342 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) | TSPEN
));
344 pr_debug("%s exit\n", __func__
);
347 static void sport_stop_rx(struct uart_port
*port
)
349 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
351 pr_debug("%s enter\n", __func__
);
352 /* Disable sport to stop rx */
353 SPORT_PUT_RCR1(up
, (SPORT_GET_RCR1(up
) & ~RSPEN
));
357 static void sport_enable_ms(struct uart_port
*port
)
359 pr_debug("%s enter\n", __func__
);
362 static void sport_break_ctl(struct uart_port
*port
, int break_state
)
364 pr_debug("%s enter\n", __func__
);
367 static void sport_shutdown(struct uart_port
*port
)
369 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
371 dev_dbg(port
->dev
, "%s enter\n", __func__
);
374 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) & ~TSPEN
));
375 SPORT_PUT_RCR1(up
, (SPORT_GET_RCR1(up
) & ~RSPEN
));
378 free_irq(up
->port
.irq
, up
);
379 free_irq(up
->port
.irq
+1, up
);
380 free_irq(up
->err_irq
, up
);
383 static const char *sport_type(struct uart_port
*port
)
385 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
387 pr_debug("%s enter\n", __func__
);
388 return up
->port
.type
== PORT_BFIN_SPORT
? "BFIN-SPORT-UART" : NULL
;
391 static void sport_release_port(struct uart_port
*port
)
393 pr_debug("%s enter\n", __func__
);
396 static int sport_request_port(struct uart_port
*port
)
398 pr_debug("%s enter\n", __func__
);
402 static void sport_config_port(struct uart_port
*port
, int flags
)
404 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
406 pr_debug("%s enter\n", __func__
);
407 up
->port
.type
= PORT_BFIN_SPORT
;
410 static int sport_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
412 pr_debug("%s enter\n", __func__
);
416 static void sport_set_termios(struct uart_port
*port
,
417 struct ktermios
*termios
, struct ktermios
*old
)
419 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
423 pr_debug("%s enter, c_cflag:%08x\n", __func__
, termios
->c_cflag
);
425 switch (termios
->c_cflag
& CSIZE
) {
439 pr_warning("requested word length not supported\n");
442 if (termios
->c_cflag
& CSTOPB
) {
445 if (termios
->c_cflag
& PARENB
) {
446 pr_warning("PAREN bits is not supported yet\n");
450 port
->read_status_mask
= OE
;
451 if (termios
->c_iflag
& INPCK
)
452 port
->read_status_mask
|= (FE
| PE
);
453 if (termios
->c_iflag
& (BRKINT
| PARMRK
))
454 port
->read_status_mask
|= BI
;
457 * Characters to ignore
459 port
->ignore_status_mask
= 0;
460 if (termios
->c_iflag
& IGNPAR
)
461 port
->ignore_status_mask
|= FE
| PE
;
462 if (termios
->c_iflag
& IGNBRK
) {
463 port
->ignore_status_mask
|= BI
;
465 * If we're ignoring parity and break indicators,
466 * ignore overruns too (for real raw support).
468 if (termios
->c_iflag
& IGNPAR
)
469 port
->ignore_status_mask
|= OE
;
472 /* RX extract mask */
473 up
->rxmask
= 0x01 | (((up
->csize
+ up
->stopb
) * 2 - 1) << 0x8);
474 /* TX masks, 8 bit data and 1 bit stop for example:
475 * mask1 = b#0111111110
476 * mask2 = b#1000000000
478 for (i
= 0, up
->txmask1
= 0; i
< up
->csize
; i
++)
479 up
->txmask1
|= (1<<i
);
480 up
->txmask2
= (1<<i
);
483 up
->txmask2
|= (1<<i
);
488 port
->uartclk
= uart_get_baud_rate(port
, termios
, old
, 0, get_sclk()/16);
490 spin_lock_irqsave(&up
->port
.lock
, flags
);
493 SPORT_PUT_TCR1(up
, SPORT_GET_TCR1(up
) & ~TSPEN
);
494 SPORT_PUT_RCR1(up
, SPORT_GET_RCR1(up
) & ~RSPEN
);
496 sport_uart_setup(up
, up
->csize
+ up
->stopb
, port
->uartclk
);
498 /* driver TX line high after config, one dummy data is
499 * necessary to stop sport after shift one byte
501 SPORT_PUT_TX(up
, 0xffff);
502 SPORT_PUT_TX(up
, 0xffff);
503 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) | TSPEN
));
505 while (!(SPORT_GET_STAT(up
) & TXHRE
))
507 SPORT_PUT_TCR1(up
, SPORT_GET_TCR1(up
) & ~TSPEN
);
510 /* Port speed changed, update the per-port timeout. */
511 uart_update_timeout(port
, termios
->c_cflag
, port
->uartclk
);
513 /* Enable sport rx */
514 SPORT_PUT_RCR1(up
, SPORT_GET_RCR1(up
) | RSPEN
);
517 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
520 struct uart_ops sport_uart_ops
= {
521 .tx_empty
= sport_tx_empty
,
522 .set_mctrl
= sport_set_mctrl
,
523 .get_mctrl
= sport_get_mctrl
,
524 .stop_tx
= sport_stop_tx
,
525 .start_tx
= sport_start_tx
,
526 .stop_rx
= sport_stop_rx
,
527 .enable_ms
= sport_enable_ms
,
528 .break_ctl
= sport_break_ctl
,
529 .startup
= sport_startup
,
530 .shutdown
= sport_shutdown
,
531 .set_termios
= sport_set_termios
,
533 .release_port
= sport_release_port
,
534 .request_port
= sport_request_port
,
535 .config_port
= sport_config_port
,
536 .verify_port
= sport_verify_port
,
539 #define BFIN_SPORT_UART_MAX_PORTS 4
541 static struct sport_uart_port
*bfin_sport_uart_ports
[BFIN_SPORT_UART_MAX_PORTS
];
543 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
545 sport_uart_console_setup(struct console
*co
, char *options
)
547 struct sport_uart_port
*up
;
553 /* Check whether an invalid uart number has been specified */
554 if (co
->index
< 0 || co
->index
>= BFIN_SPORT_UART_MAX_PORTS
)
557 up
= bfin_sport_uart_ports
[co
->index
];
562 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
564 return uart_set_options(&up
->port
, co
, baud
, parity
, bits
, flow
);
567 static void sport_uart_console_putchar(struct uart_port
*port
, int ch
)
569 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
571 while (SPORT_GET_STAT(up
) & TXF
)
578 * Interrupts are disabled on entering
581 sport_uart_console_write(struct console
*co
, const char *s
, unsigned int count
)
583 struct sport_uart_port
*up
= bfin_sport_uart_ports
[co
->index
];
586 spin_lock_irqsave(&up
->port
.lock
, flags
);
588 if (SPORT_GET_TCR1(up
) & TSPEN
)
589 uart_console_write(&up
->port
, s
, count
, sport_uart_console_putchar
);
591 /* dummy data to start sport */
592 while (SPORT_GET_STAT(up
) & TXF
)
594 SPORT_PUT_TX(up
, 0xffff);
595 /* Enable transmit, then an interrupt will generated */
596 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) | TSPEN
));
599 uart_console_write(&up
->port
, s
, count
, sport_uart_console_putchar
);
601 /* Although the hold register is empty, last byte is still in shift
602 * register and not sent out yet. So, put a dummy data into TX FIFO.
603 * Then, sport tx stops when last byte is shift out and the dummy
604 * data is moved into the shift register.
606 while (SPORT_GET_STAT(up
) & TXF
)
608 SPORT_PUT_TX(up
, 0xffff);
609 while (!(SPORT_GET_STAT(up
) & TXHRE
))
612 /* Stop sport tx transfer */
613 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) & ~TSPEN
));
617 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
620 static struct uart_driver sport_uart_reg
;
622 static struct console sport_uart_console
= {
624 .write
= sport_uart_console_write
,
625 .device
= uart_console_device
,
626 .setup
= sport_uart_console_setup
,
627 .flags
= CON_PRINTBUFFER
,
629 .data
= &sport_uart_reg
,
632 #define SPORT_UART_CONSOLE (&sport_uart_console)
634 #define SPORT_UART_CONSOLE NULL
635 #endif /* CONFIG_SERIAL_BFIN_SPORT_CONSOLE */
638 static struct uart_driver sport_uart_reg
= {
639 .owner
= THIS_MODULE
,
640 .driver_name
= DRV_NAME
,
641 .dev_name
= DEVICE_NAME
,
644 .nr
= BFIN_SPORT_UART_MAX_PORTS
,
645 .cons
= SPORT_UART_CONSOLE
,
649 static int sport_uart_suspend(struct device
*dev
)
651 struct sport_uart_port
*sport
= dev_get_drvdata(dev
);
653 dev_dbg(dev
, "%s enter\n", __func__
);
655 uart_suspend_port(&sport_uart_reg
, &sport
->port
);
660 static int sport_uart_resume(struct device
*dev
)
662 struct sport_uart_port
*sport
= dev_get_drvdata(dev
);
664 dev_dbg(dev
, "%s enter\n", __func__
);
666 uart_resume_port(&sport_uart_reg
, &sport
->port
);
671 static struct dev_pm_ops bfin_sport_uart_dev_pm_ops
= {
672 .suspend
= sport_uart_suspend
,
673 .resume
= sport_uart_resume
,
677 static int __devinit
sport_uart_probe(struct platform_device
*pdev
)
679 struct resource
*res
;
680 struct sport_uart_port
*sport
;
683 dev_dbg(&pdev
->dev
, "%s enter\n", __func__
);
685 if (pdev
->id
< 0 || pdev
->id
>= BFIN_SPORT_UART_MAX_PORTS
) {
686 dev_err(&pdev
->dev
, "Wrong sport uart platform device id.\n");
690 if (bfin_sport_uart_ports
[pdev
->id
] == NULL
) {
691 bfin_sport_uart_ports
[pdev
->id
] =
692 kmalloc(sizeof(struct sport_uart_port
), GFP_KERNEL
);
693 sport
= bfin_sport_uart_ports
[pdev
->id
];
696 "Fail to kmalloc sport_uart_port\n");
700 ret
= peripheral_request_list(
701 (unsigned short *)pdev
->dev
.platform_data
, DRV_NAME
);
704 "Fail to request SPORT peripherals\n");
705 goto out_error_free_mem
;
708 spin_lock_init(&sport
->port
.lock
);
709 sport
->port
.fifosize
= SPORT_TX_FIFO_SIZE
,
710 sport
->port
.ops
= &sport_uart_ops
;
711 sport
->port
.line
= pdev
->id
;
712 sport
->port
.iotype
= UPIO_MEM
;
713 sport
->port
.flags
= UPF_BOOT_AUTOCONF
;
715 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
717 dev_err(&pdev
->dev
, "Cannot get IORESOURCE_MEM\n");
719 goto out_error_free_peripherals
;
722 sport
->port
.membase
= ioremap(res
->start
,
723 res
->end
- res
->start
);
724 if (!sport
->port
.membase
) {
725 dev_err(&pdev
->dev
, "Cannot map sport IO\n");
727 goto out_error_free_peripherals
;
730 sport
->port
.irq
= platform_get_irq(pdev
, 0);
731 if (sport
->port
.irq
< 0) {
732 dev_err(&pdev
->dev
, "No sport RX/TX IRQ specified\n");
734 goto out_error_unmap
;
737 sport
->err_irq
= platform_get_irq(pdev
, 1);
738 if (sport
->err_irq
< 0) {
739 dev_err(&pdev
->dev
, "No sport status IRQ specified\n");
741 goto out_error_unmap
;
745 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
746 if (!is_early_platform_device(pdev
)) {
748 sport
= bfin_sport_uart_ports
[pdev
->id
];
749 sport
->port
.dev
= &pdev
->dev
;
750 dev_set_drvdata(&pdev
->dev
, sport
);
751 ret
= uart_add_one_port(&sport_uart_reg
, &sport
->port
);
752 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
760 iounmap(sport
->port
.membase
);
761 out_error_free_peripherals
:
762 peripheral_free_list(
763 (unsigned short *)pdev
->dev
.platform_data
);
766 bfin_sport_uart_ports
[pdev
->id
] = NULL
;
772 static int __devexit
sport_uart_remove(struct platform_device
*pdev
)
774 struct sport_uart_port
*sport
= platform_get_drvdata(pdev
);
776 dev_dbg(&pdev
->dev
, "%s enter\n", __func__
);
777 dev_set_drvdata(&pdev
->dev
, NULL
);
780 uart_remove_one_port(&sport_uart_reg
, &sport
->port
);
781 iounmap(sport
->port
.membase
);
782 peripheral_free_list(
783 (unsigned short *)pdev
->dev
.platform_data
);
785 bfin_sport_uart_ports
[pdev
->id
] = NULL
;
791 static struct platform_driver sport_uart_driver
= {
792 .probe
= sport_uart_probe
,
793 .remove
= __devexit_p(sport_uart_remove
),
797 .pm
= &bfin_sport_uart_dev_pm_ops
,
802 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
803 static __initdata
struct early_platform_driver early_sport_uart_driver
= {
804 .class_str
= DRV_NAME
,
805 .pdrv
= &sport_uart_driver
,
806 .requested_id
= EARLY_PLATFORM_ID_UNSET
,
809 static int __init
sport_uart_rs_console_init(void)
811 early_platform_driver_register(&early_sport_uart_driver
, DRV_NAME
);
813 early_platform_driver_probe(DRV_NAME
, BFIN_SPORT_UART_MAX_PORTS
, 0);
815 register_console(&sport_uart_console
);
819 console_initcall(sport_uart_rs_console_init
);
822 static int __init
sport_uart_init(void)
826 pr_info("Serial: Blackfin uart over sport driver\n");
828 ret
= uart_register_driver(&sport_uart_reg
);
830 pr_err("failed to register %s:%d\n",
831 sport_uart_reg
.driver_name
, ret
);
835 ret
= platform_driver_register(&sport_uart_driver
);
837 pr_err("failed to register sport uart driver:%d\n", ret
);
838 uart_unregister_driver(&sport_uart_reg
);
843 module_init(sport_uart_init
);
845 static void __exit
sport_uart_exit(void)
847 platform_driver_unregister(&sport_uart_driver
);
848 uart_unregister_driver(&sport_uart_reg
);
850 module_exit(sport_uart_exit
);
852 MODULE_AUTHOR("Sonic Zhang, Roy Huang");
853 MODULE_DESCRIPTION("Blackfin serial over SPORT driver");
854 MODULE_LICENSE("GPL");