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/slab.h>
32 #include <linux/platform_device.h>
33 #include <linux/tty.h>
34 #include <linux/tty_flip.h>
35 #include <linux/serial_core.h>
37 #include <asm/delay.h>
38 #include <asm/portmux.h>
40 #include "bfin_sport_uart.h"
42 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
43 unsigned short bfin_uart_pin_req_sport0
[] =
44 {P_SPORT0_TFS
, P_SPORT0_DTPRI
, P_SPORT0_TSCLK
, P_SPORT0_RFS
, \
45 P_SPORT0_DRPRI
, P_SPORT0_RSCLK
, P_SPORT0_DRSEC
, P_SPORT0_DTSEC
, 0};
47 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
48 unsigned short bfin_uart_pin_req_sport1
[] =
49 {P_SPORT1_TFS
, P_SPORT1_DTPRI
, P_SPORT1_TSCLK
, P_SPORT1_RFS
, \
50 P_SPORT1_DRPRI
, P_SPORT1_RSCLK
, P_SPORT1_DRSEC
, P_SPORT1_DTSEC
, 0};
52 #ifdef CONFIG_SERIAL_BFIN_SPORT2_UART
53 unsigned short bfin_uart_pin_req_sport2
[] =
54 {P_SPORT2_TFS
, P_SPORT2_DTPRI
, P_SPORT2_TSCLK
, P_SPORT2_RFS
, \
55 P_SPORT2_DRPRI
, P_SPORT2_RSCLK
, P_SPORT2_DRSEC
, P_SPORT2_DTSEC
, 0};
57 #ifdef CONFIG_SERIAL_BFIN_SPORT3_UART
58 unsigned short bfin_uart_pin_req_sport3
[] =
59 {P_SPORT3_TFS
, P_SPORT3_DTPRI
, P_SPORT3_TSCLK
, P_SPORT3_RFS
, \
60 P_SPORT3_DRPRI
, P_SPORT3_RSCLK
, P_SPORT3_DRSEC
, P_SPORT3_DTSEC
, 0};
63 struct sport_uart_port
{
64 struct uart_port port
;
67 unsigned short rxmask
;
68 unsigned short txmask1
;
69 unsigned short txmask2
;
71 /* unsigned char parib; */
74 static void sport_uart_tx_chars(struct sport_uart_port
*up
);
75 static void sport_stop_tx(struct uart_port
*port
);
77 static inline void tx_one_byte(struct sport_uart_port
*up
, unsigned int value
)
79 pr_debug("%s value:%x, mask1=0x%x, mask2=0x%x\n", __func__
, value
,
80 up
->txmask1
, up
->txmask2
);
82 /* Place Start and Stop bits */
83 __asm__
__volatile__ (
85 "%[val] = %[val] & %[mask1];"
86 "%[val] = %[val] | %[mask2];"
88 : [mask1
]"d"(up
->txmask1
), [mask2
]"d"(up
->txmask2
)
91 pr_debug("%s value:%x\n", __func__
, value
);
93 SPORT_PUT_TX(up
, value
);
96 static inline unsigned char rx_one_byte(struct sport_uart_port
*up
)
99 unsigned char extract
;
100 u32 tmp_mask1
, tmp_mask2
, tmp_shift
, tmp
;
102 if ((up
->csize
+ up
->stopb
) > 7)
103 value
= SPORT_GET_RX32(up
);
105 value
= SPORT_GET_RX(up
);
107 pr_debug("%s value:%x, cs=%d, mask=0x%x\n", __func__
, value
,
108 up
->csize
, up
->rxmask
);
111 __asm__
__volatile__ (
113 "%[mask1] = %[rxmask];"
114 "%[mask2] = 0x0200(Z);"
116 "LSETUP(.Lloop_s, .Lloop_e) LC0 = %[lc];"
118 "%[tmp] = extract(%[val], %[mask1].L)(Z);"
119 "%[tmp] <<= %[shift];"
120 "%[extr] = %[extr] | %[tmp];"
121 "%[mask1] = %[mask1] - %[mask2];"
124 : [extr
]"=&d"(extract
), [shift
]"=&d"(tmp_shift
), [tmp
]"=&d"(tmp
),
125 [mask1
]"=&d"(tmp_mask1
), [mask2
]"=&d"(tmp_mask2
)
126 : [val
]"d"(value
), [rxmask
]"d"(up
->rxmask
), [lc
]"a"(up
->csize
)
127 : "ASTAT", "LB0", "LC0", "LT0"
130 pr_debug(" extract:%x\n", extract
);
134 static int sport_uart_setup(struct sport_uart_port
*up
, int size
, int baud_rate
)
136 int tclkdiv
, rclkdiv
;
137 unsigned int sclk
= get_sclk();
139 /* Set TCR1 and TCR2, TFSR is not enabled for uart */
140 SPORT_PUT_TCR1(up
, (ITFS
| TLSBIT
| ITCLK
));
141 SPORT_PUT_TCR2(up
, size
+ 1);
142 pr_debug("%s TCR1:%x, TCR2:%x\n", __func__
, SPORT_GET_TCR1(up
), SPORT_GET_TCR2(up
));
144 /* Set RCR1 and RCR2 */
145 SPORT_PUT_RCR1(up
, (RCKFE
| LARFS
| LRFS
| RFSR
| IRCLK
));
146 SPORT_PUT_RCR2(up
, (size
+ 1) * 2 - 1);
147 pr_debug("%s RCR1:%x, RCR2:%x\n", __func__
, SPORT_GET_RCR1(up
), SPORT_GET_RCR2(up
));
149 tclkdiv
= sclk
/ (2 * baud_rate
) - 1;
150 rclkdiv
= sclk
/ (2 * baud_rate
* 2) - 1;
151 SPORT_PUT_TCLKDIV(up
, tclkdiv
);
152 SPORT_PUT_RCLKDIV(up
, rclkdiv
);
154 pr_debug("%s sclk:%d, baud_rate:%d, tclkdiv:%d, rclkdiv:%d\n",
155 __func__
, sclk
, baud_rate
, tclkdiv
, rclkdiv
);
160 static irqreturn_t
sport_uart_rx_irq(int irq
, void *dev_id
)
162 struct sport_uart_port
*up
= dev_id
;
163 struct tty_struct
*tty
= up
->port
.state
->port
.tty
;
166 spin_lock(&up
->port
.lock
);
168 while (SPORT_GET_STAT(up
) & RXNE
) {
169 ch
= rx_one_byte(up
);
170 up
->port
.icount
.rx
++;
172 if (!uart_handle_sysrq_char(&up
->port
, ch
))
173 tty_insert_flip_char(tty
, ch
, TTY_NORMAL
);
175 tty_flip_buffer_push(tty
);
177 spin_unlock(&up
->port
.lock
);
182 static irqreturn_t
sport_uart_tx_irq(int irq
, void *dev_id
)
184 struct sport_uart_port
*up
= dev_id
;
186 spin_lock(&up
->port
.lock
);
187 sport_uart_tx_chars(up
);
188 spin_unlock(&up
->port
.lock
);
193 static irqreturn_t
sport_uart_err_irq(int irq
, void *dev_id
)
195 struct sport_uart_port
*up
= dev_id
;
196 struct tty_struct
*tty
= up
->port
.state
->port
.tty
;
197 unsigned int stat
= SPORT_GET_STAT(up
);
199 spin_lock(&up
->port
.lock
);
201 /* Overflow in RX FIFO */
203 up
->port
.icount
.overrun
++;
204 tty_insert_flip_char(tty
, 0, TTY_OVERRUN
);
205 SPORT_PUT_STAT(up
, ROVF
); /* Clear ROVF bit */
207 /* These should not happen */
208 if (stat
& (TOVF
| TUVF
| RUVF
)) {
209 pr_err("SPORT Error:%s %s %s\n",
210 (stat
& TOVF
) ? "TX overflow" : "",
211 (stat
& TUVF
) ? "TX underflow" : "",
212 (stat
& RUVF
) ? "RX underflow" : "");
213 SPORT_PUT_TCR1(up
, SPORT_GET_TCR1(up
) & ~TSPEN
);
214 SPORT_PUT_RCR1(up
, SPORT_GET_RCR1(up
) & ~RSPEN
);
218 spin_unlock(&up
->port
.lock
);
222 /* Reqeust IRQ, Setup clock */
223 static int sport_startup(struct uart_port
*port
)
225 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
228 pr_debug("%s enter\n", __func__
);
229 ret
= request_irq(up
->port
.irq
, sport_uart_rx_irq
, 0,
230 "SPORT_UART_RX", up
);
232 dev_err(port
->dev
, "unable to request SPORT RX interrupt\n");
236 ret
= request_irq(up
->port
.irq
+1, sport_uart_tx_irq
, 0,
237 "SPORT_UART_TX", up
);
239 dev_err(port
->dev
, "unable to request SPORT TX interrupt\n");
243 ret
= request_irq(up
->err_irq
, sport_uart_err_irq
, 0,
244 "SPORT_UART_STATUS", up
);
246 dev_err(port
->dev
, "unable to request SPORT status interrupt\n");
252 free_irq(up
->port
.irq
+1, up
);
254 free_irq(up
->port
.irq
, up
);
259 static void sport_uart_tx_chars(struct sport_uart_port
*up
)
261 struct circ_buf
*xmit
= &up
->port
.state
->xmit
;
263 if (SPORT_GET_STAT(up
) & TXF
)
266 if (up
->port
.x_char
) {
267 tx_one_byte(up
, up
->port
.x_char
);
268 up
->port
.icount
.tx
++;
273 if (uart_circ_empty(xmit
) || uart_tx_stopped(&up
->port
)) {
274 sport_stop_tx(&up
->port
);
278 while(!(SPORT_GET_STAT(up
) & TXF
) && !uart_circ_empty(xmit
)) {
279 tx_one_byte(up
, xmit
->buf
[xmit
->tail
]);
280 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
-1);
281 up
->port
.icount
.tx
++;
284 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
285 uart_write_wakeup(&up
->port
);
288 static unsigned int sport_tx_empty(struct uart_port
*port
)
290 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
293 stat
= SPORT_GET_STAT(up
);
294 pr_debug("%s stat:%04x\n", __func__
, stat
);
301 static unsigned int sport_get_mctrl(struct uart_port
*port
)
303 pr_debug("%s enter\n", __func__
);
304 return (TIOCM_CTS
| TIOCM_CD
| TIOCM_DSR
);
307 static void sport_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
309 pr_debug("%s enter\n", __func__
);
312 static void sport_stop_tx(struct uart_port
*port
)
314 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
316 pr_debug("%s enter\n", __func__
);
318 /* Although the hold register is empty, last byte is still in shift
319 * register and not sent out yet. So, put a dummy data into TX FIFO.
320 * Then, sport tx stops when last byte is shift out and the dummy
321 * data is moved into the shift register.
323 SPORT_PUT_TX(up
, 0xffff);
324 while (!(SPORT_GET_STAT(up
) & TXHRE
))
327 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) & ~TSPEN
));
333 static void sport_start_tx(struct uart_port
*port
)
335 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
337 pr_debug("%s enter\n", __func__
);
339 /* Write data into SPORT FIFO before enable SPROT to transmit */
340 sport_uart_tx_chars(up
);
342 /* Enable transmit, then an interrupt will generated */
343 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) | TSPEN
));
345 pr_debug("%s exit\n", __func__
);
348 static void sport_stop_rx(struct uart_port
*port
)
350 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
352 pr_debug("%s enter\n", __func__
);
353 /* Disable sport to stop rx */
354 SPORT_PUT_RCR1(up
, (SPORT_GET_RCR1(up
) & ~RSPEN
));
358 static void sport_enable_ms(struct uart_port
*port
)
360 pr_debug("%s enter\n", __func__
);
363 static void sport_break_ctl(struct uart_port
*port
, int break_state
)
365 pr_debug("%s enter\n", __func__
);
368 static void sport_shutdown(struct uart_port
*port
)
370 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
372 dev_dbg(port
->dev
, "%s enter\n", __func__
);
375 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) & ~TSPEN
));
376 SPORT_PUT_RCR1(up
, (SPORT_GET_RCR1(up
) & ~RSPEN
));
379 free_irq(up
->port
.irq
, up
);
380 free_irq(up
->port
.irq
+1, up
);
381 free_irq(up
->err_irq
, up
);
384 static const char *sport_type(struct uart_port
*port
)
386 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
388 pr_debug("%s enter\n", __func__
);
389 return up
->port
.type
== PORT_BFIN_SPORT
? "BFIN-SPORT-UART" : NULL
;
392 static void sport_release_port(struct uart_port
*port
)
394 pr_debug("%s enter\n", __func__
);
397 static int sport_request_port(struct uart_port
*port
)
399 pr_debug("%s enter\n", __func__
);
403 static void sport_config_port(struct uart_port
*port
, int flags
)
405 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
407 pr_debug("%s enter\n", __func__
);
408 up
->port
.type
= PORT_BFIN_SPORT
;
411 static int sport_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
413 pr_debug("%s enter\n", __func__
);
417 static void sport_set_termios(struct uart_port
*port
,
418 struct ktermios
*termios
, struct ktermios
*old
)
420 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
424 pr_debug("%s enter, c_cflag:%08x\n", __func__
, termios
->c_cflag
);
426 switch (termios
->c_cflag
& CSIZE
) {
440 pr_warning("requested word length not supported\n");
443 if (termios
->c_cflag
& CSTOPB
) {
446 if (termios
->c_cflag
& PARENB
) {
447 pr_warning("PAREN bits is not supported yet\n");
451 port
->read_status_mask
= OE
;
452 if (termios
->c_iflag
& INPCK
)
453 port
->read_status_mask
|= (FE
| PE
);
454 if (termios
->c_iflag
& (BRKINT
| PARMRK
))
455 port
->read_status_mask
|= BI
;
458 * Characters to ignore
460 port
->ignore_status_mask
= 0;
461 if (termios
->c_iflag
& IGNPAR
)
462 port
->ignore_status_mask
|= FE
| PE
;
463 if (termios
->c_iflag
& IGNBRK
) {
464 port
->ignore_status_mask
|= BI
;
466 * If we're ignoring parity and break indicators,
467 * ignore overruns too (for real raw support).
469 if (termios
->c_iflag
& IGNPAR
)
470 port
->ignore_status_mask
|= OE
;
473 /* RX extract mask */
474 up
->rxmask
= 0x01 | (((up
->csize
+ up
->stopb
) * 2 - 1) << 0x8);
475 /* TX masks, 8 bit data and 1 bit stop for example:
476 * mask1 = b#0111111110
477 * mask2 = b#1000000000
479 for (i
= 0, up
->txmask1
= 0; i
< up
->csize
; i
++)
480 up
->txmask1
|= (1<<i
);
481 up
->txmask2
= (1<<i
);
484 up
->txmask2
|= (1<<i
);
489 port
->uartclk
= uart_get_baud_rate(port
, termios
, old
, 0, get_sclk()/16);
491 spin_lock_irqsave(&up
->port
.lock
, flags
);
494 SPORT_PUT_TCR1(up
, SPORT_GET_TCR1(up
) & ~TSPEN
);
495 SPORT_PUT_RCR1(up
, SPORT_GET_RCR1(up
) & ~RSPEN
);
497 sport_uart_setup(up
, up
->csize
+ up
->stopb
, port
->uartclk
);
499 /* driver TX line high after config, one dummy data is
500 * necessary to stop sport after shift one byte
502 SPORT_PUT_TX(up
, 0xffff);
503 SPORT_PUT_TX(up
, 0xffff);
504 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) | TSPEN
));
506 while (!(SPORT_GET_STAT(up
) & TXHRE
))
508 SPORT_PUT_TCR1(up
, SPORT_GET_TCR1(up
) & ~TSPEN
);
511 /* Port speed changed, update the per-port timeout. */
512 uart_update_timeout(port
, termios
->c_cflag
, port
->uartclk
);
514 /* Enable sport rx */
515 SPORT_PUT_RCR1(up
, SPORT_GET_RCR1(up
) | RSPEN
);
518 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
521 struct uart_ops sport_uart_ops
= {
522 .tx_empty
= sport_tx_empty
,
523 .set_mctrl
= sport_set_mctrl
,
524 .get_mctrl
= sport_get_mctrl
,
525 .stop_tx
= sport_stop_tx
,
526 .start_tx
= sport_start_tx
,
527 .stop_rx
= sport_stop_rx
,
528 .enable_ms
= sport_enable_ms
,
529 .break_ctl
= sport_break_ctl
,
530 .startup
= sport_startup
,
531 .shutdown
= sport_shutdown
,
532 .set_termios
= sport_set_termios
,
534 .release_port
= sport_release_port
,
535 .request_port
= sport_request_port
,
536 .config_port
= sport_config_port
,
537 .verify_port
= sport_verify_port
,
540 #define BFIN_SPORT_UART_MAX_PORTS 4
542 static struct sport_uart_port
*bfin_sport_uart_ports
[BFIN_SPORT_UART_MAX_PORTS
];
544 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
546 sport_uart_console_setup(struct console
*co
, char *options
)
548 struct sport_uart_port
*up
;
554 /* Check whether an invalid uart number has been specified */
555 if (co
->index
< 0 || co
->index
>= BFIN_SPORT_UART_MAX_PORTS
)
558 up
= bfin_sport_uart_ports
[co
->index
];
563 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
565 return uart_set_options(&up
->port
, co
, baud
, parity
, bits
, flow
);
568 static void sport_uart_console_putchar(struct uart_port
*port
, int ch
)
570 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
572 while (SPORT_GET_STAT(up
) & TXF
)
579 * Interrupts are disabled on entering
582 sport_uart_console_write(struct console
*co
, const char *s
, unsigned int count
)
584 struct sport_uart_port
*up
= bfin_sport_uart_ports
[co
->index
];
587 spin_lock_irqsave(&up
->port
.lock
, flags
);
589 if (SPORT_GET_TCR1(up
) & TSPEN
)
590 uart_console_write(&up
->port
, s
, count
, sport_uart_console_putchar
);
592 /* dummy data to start sport */
593 while (SPORT_GET_STAT(up
) & TXF
)
595 SPORT_PUT_TX(up
, 0xffff);
596 /* Enable transmit, then an interrupt will generated */
597 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) | TSPEN
));
600 uart_console_write(&up
->port
, s
, count
, sport_uart_console_putchar
);
602 /* Although the hold register is empty, last byte is still in shift
603 * register and not sent out yet. So, put a dummy data into TX FIFO.
604 * Then, sport tx stops when last byte is shift out and the dummy
605 * data is moved into the shift register.
607 while (SPORT_GET_STAT(up
) & TXF
)
609 SPORT_PUT_TX(up
, 0xffff);
610 while (!(SPORT_GET_STAT(up
) & TXHRE
))
613 /* Stop sport tx transfer */
614 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) & ~TSPEN
));
618 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
621 static struct uart_driver sport_uart_reg
;
623 static struct console sport_uart_console
= {
625 .write
= sport_uart_console_write
,
626 .device
= uart_console_device
,
627 .setup
= sport_uart_console_setup
,
628 .flags
= CON_PRINTBUFFER
,
630 .data
= &sport_uart_reg
,
633 #define SPORT_UART_CONSOLE (&sport_uart_console)
635 #define SPORT_UART_CONSOLE NULL
636 #endif /* CONFIG_SERIAL_BFIN_SPORT_CONSOLE */
639 static struct uart_driver sport_uart_reg
= {
640 .owner
= THIS_MODULE
,
641 .driver_name
= DRV_NAME
,
642 .dev_name
= DEVICE_NAME
,
645 .nr
= BFIN_SPORT_UART_MAX_PORTS
,
646 .cons
= SPORT_UART_CONSOLE
,
650 static int sport_uart_suspend(struct device
*dev
)
652 struct sport_uart_port
*sport
= dev_get_drvdata(dev
);
654 dev_dbg(dev
, "%s enter\n", __func__
);
656 uart_suspend_port(&sport_uart_reg
, &sport
->port
);
661 static int sport_uart_resume(struct device
*dev
)
663 struct sport_uart_port
*sport
= dev_get_drvdata(dev
);
665 dev_dbg(dev
, "%s enter\n", __func__
);
667 uart_resume_port(&sport_uart_reg
, &sport
->port
);
672 static struct dev_pm_ops bfin_sport_uart_dev_pm_ops
= {
673 .suspend
= sport_uart_suspend
,
674 .resume
= sport_uart_resume
,
678 static int __devinit
sport_uart_probe(struct platform_device
*pdev
)
680 struct resource
*res
;
681 struct sport_uart_port
*sport
;
684 dev_dbg(&pdev
->dev
, "%s enter\n", __func__
);
686 if (pdev
->id
< 0 || pdev
->id
>= BFIN_SPORT_UART_MAX_PORTS
) {
687 dev_err(&pdev
->dev
, "Wrong sport uart platform device id.\n");
691 if (bfin_sport_uart_ports
[pdev
->id
] == NULL
) {
692 bfin_sport_uart_ports
[pdev
->id
] =
693 kmalloc(sizeof(struct sport_uart_port
), GFP_KERNEL
);
694 sport
= bfin_sport_uart_ports
[pdev
->id
];
697 "Fail to kmalloc sport_uart_port\n");
701 ret
= peripheral_request_list(
702 (unsigned short *)pdev
->dev
.platform_data
, DRV_NAME
);
705 "Fail to request SPORT peripherals\n");
706 goto out_error_free_mem
;
709 spin_lock_init(&sport
->port
.lock
);
710 sport
->port
.fifosize
= SPORT_TX_FIFO_SIZE
,
711 sport
->port
.ops
= &sport_uart_ops
;
712 sport
->port
.line
= pdev
->id
;
713 sport
->port
.iotype
= UPIO_MEM
;
714 sport
->port
.flags
= UPF_BOOT_AUTOCONF
;
716 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
718 dev_err(&pdev
->dev
, "Cannot get IORESOURCE_MEM\n");
720 goto out_error_free_peripherals
;
723 sport
->port
.membase
= ioremap(res
->start
,
724 res
->end
- res
->start
);
725 if (!sport
->port
.membase
) {
726 dev_err(&pdev
->dev
, "Cannot map sport IO\n");
728 goto out_error_free_peripherals
;
731 sport
->port
.irq
= platform_get_irq(pdev
, 0);
732 if (sport
->port
.irq
< 0) {
733 dev_err(&pdev
->dev
, "No sport RX/TX IRQ specified\n");
735 goto out_error_unmap
;
738 sport
->err_irq
= platform_get_irq(pdev
, 1);
739 if (sport
->err_irq
< 0) {
740 dev_err(&pdev
->dev
, "No sport status IRQ specified\n");
742 goto out_error_unmap
;
746 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
747 if (!is_early_platform_device(pdev
)) {
749 sport
= bfin_sport_uart_ports
[pdev
->id
];
750 sport
->port
.dev
= &pdev
->dev
;
751 dev_set_drvdata(&pdev
->dev
, sport
);
752 ret
= uart_add_one_port(&sport_uart_reg
, &sport
->port
);
753 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
761 iounmap(sport
->port
.membase
);
762 out_error_free_peripherals
:
763 peripheral_free_list(
764 (unsigned short *)pdev
->dev
.platform_data
);
767 bfin_sport_uart_ports
[pdev
->id
] = NULL
;
773 static int __devexit
sport_uart_remove(struct platform_device
*pdev
)
775 struct sport_uart_port
*sport
= platform_get_drvdata(pdev
);
777 dev_dbg(&pdev
->dev
, "%s enter\n", __func__
);
778 dev_set_drvdata(&pdev
->dev
, NULL
);
781 uart_remove_one_port(&sport_uart_reg
, &sport
->port
);
782 iounmap(sport
->port
.membase
);
783 peripheral_free_list(
784 (unsigned short *)pdev
->dev
.platform_data
);
786 bfin_sport_uart_ports
[pdev
->id
] = NULL
;
792 static struct platform_driver sport_uart_driver
= {
793 .probe
= sport_uart_probe
,
794 .remove
= __devexit_p(sport_uart_remove
),
798 .pm
= &bfin_sport_uart_dev_pm_ops
,
803 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
804 static __initdata
struct early_platform_driver early_sport_uart_driver
= {
805 .class_str
= DRV_NAME
,
806 .pdrv
= &sport_uart_driver
,
807 .requested_id
= EARLY_PLATFORM_ID_UNSET
,
810 static int __init
sport_uart_rs_console_init(void)
812 early_platform_driver_register(&early_sport_uart_driver
, DRV_NAME
);
814 early_platform_driver_probe(DRV_NAME
, BFIN_SPORT_UART_MAX_PORTS
, 0);
816 register_console(&sport_uart_console
);
820 console_initcall(sport_uart_rs_console_init
);
823 static int __init
sport_uart_init(void)
827 pr_info("Serial: Blackfin uart over sport driver\n");
829 ret
= uart_register_driver(&sport_uart_reg
);
831 pr_err("failed to register %s:%d\n",
832 sport_uart_reg
.driver_name
, ret
);
836 ret
= platform_driver_register(&sport_uart_driver
);
838 pr_err("failed to register sport uart driver:%d\n", ret
);
839 uart_unregister_driver(&sport_uart_reg
);
844 module_init(sport_uart_init
);
846 static void __exit
sport_uart_exit(void)
848 platform_driver_unregister(&sport_uart_driver
);
849 uart_unregister_driver(&sport_uart_reg
);
851 module_exit(sport_uart_exit
);
853 MODULE_AUTHOR("Sonic Zhang, Roy Huang");
854 MODULE_DESCRIPTION("Blackfin serial over SPORT driver");
855 MODULE_LICENSE("GPL");