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/static/imported-files/application_notes/EE191.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/bfin_sport.h>
38 #include <asm/delay.h>
39 #include <asm/portmux.h>
41 #include "bfin_sport_uart.h"
43 struct sport_uart_port
{
44 struct uart_port port
;
47 unsigned short rxmask
;
48 unsigned short txmask1
;
49 unsigned short txmask2
;
51 /* unsigned char parib; */
52 #ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
58 static int sport_uart_tx_chars(struct sport_uart_port
*up
);
59 static void sport_stop_tx(struct uart_port
*port
);
61 static inline void tx_one_byte(struct sport_uart_port
*up
, unsigned int value
)
63 pr_debug("%s value:%x, mask1=0x%x, mask2=0x%x\n", __func__
, value
,
64 up
->txmask1
, up
->txmask2
);
66 /* Place Start and Stop bits */
67 __asm__
__volatile__ (
69 "%[val] = %[val] & %[mask1];"
70 "%[val] = %[val] | %[mask2];"
72 : [mask1
]"d"(up
->txmask1
), [mask2
]"d"(up
->txmask2
)
75 pr_debug("%s value:%x\n", __func__
, value
);
77 SPORT_PUT_TX(up
, value
);
80 static inline unsigned char rx_one_byte(struct sport_uart_port
*up
)
83 unsigned char extract
;
84 u32 tmp_mask1
, tmp_mask2
, tmp_shift
, tmp
;
86 if ((up
->csize
+ up
->stopb
) > 7)
87 value
= SPORT_GET_RX32(up
);
89 value
= SPORT_GET_RX(up
);
91 pr_debug("%s value:%x, cs=%d, mask=0x%x\n", __func__
, value
,
92 up
->csize
, up
->rxmask
);
95 __asm__
__volatile__ (
97 "%[mask1] = %[rxmask];"
98 "%[mask2] = 0x0200(Z);"
100 "LSETUP(.Lloop_s, .Lloop_e) LC0 = %[lc];"
102 "%[tmp] = extract(%[val], %[mask1].L)(Z);"
103 "%[tmp] <<= %[shift];"
104 "%[extr] = %[extr] | %[tmp];"
105 "%[mask1] = %[mask1] - %[mask2];"
108 : [extr
]"=&d"(extract
), [shift
]"=&d"(tmp_shift
), [tmp
]"=&d"(tmp
),
109 [mask1
]"=&d"(tmp_mask1
), [mask2
]"=&d"(tmp_mask2
)
110 : [val
]"d"(value
), [rxmask
]"d"(up
->rxmask
), [lc
]"a"(up
->csize
)
111 : "ASTAT", "LB0", "LC0", "LT0"
114 pr_debug(" extract:%x\n", extract
);
118 static int sport_uart_setup(struct sport_uart_port
*up
, int size
, int baud_rate
)
120 int tclkdiv
, rclkdiv
;
121 unsigned int sclk
= get_sclk();
123 /* Set TCR1 and TCR2, TFSR is not enabled for uart */
124 SPORT_PUT_TCR1(up
, (LATFS
| ITFS
| TFSR
| TLSBIT
| ITCLK
));
125 SPORT_PUT_TCR2(up
, size
+ 1);
126 pr_debug("%s TCR1:%x, TCR2:%x\n", __func__
, SPORT_GET_TCR1(up
), SPORT_GET_TCR2(up
));
128 /* Set RCR1 and RCR2 */
129 SPORT_PUT_RCR1(up
, (RCKFE
| LARFS
| LRFS
| RFSR
| IRCLK
));
130 SPORT_PUT_RCR2(up
, (size
+ 1) * 2 - 1);
131 pr_debug("%s RCR1:%x, RCR2:%x\n", __func__
, SPORT_GET_RCR1(up
), SPORT_GET_RCR2(up
));
133 tclkdiv
= sclk
/ (2 * baud_rate
) - 1;
134 /* The actual uart baud rate of devices vary between +/-2%. The sport
135 * RX sample rate should be faster than the double of the worst case,
136 * otherwise, wrong data are received. So, set sport RX clock to be
139 rclkdiv
= sclk
/ (2 * baud_rate
* 2 * 97 / 100) - 1;
140 SPORT_PUT_TCLKDIV(up
, tclkdiv
);
141 SPORT_PUT_RCLKDIV(up
, rclkdiv
);
143 pr_debug("%s sclk:%d, baud_rate:%d, tclkdiv:%d, rclkdiv:%d\n",
144 __func__
, sclk
, baud_rate
, tclkdiv
, rclkdiv
);
149 static irqreturn_t
sport_uart_rx_irq(int irq
, void *dev_id
)
151 struct sport_uart_port
*up
= dev_id
;
152 struct tty_port
*port
= &up
->port
.state
->port
;
155 spin_lock(&up
->port
.lock
);
157 while (SPORT_GET_STAT(up
) & RXNE
) {
158 ch
= rx_one_byte(up
);
159 up
->port
.icount
.rx
++;
161 if (!uart_handle_sysrq_char(&up
->port
, ch
))
162 tty_insert_flip_char(port
, ch
, TTY_NORMAL
);
165 spin_unlock(&up
->port
.lock
);
167 /* XXX this won't deadlock with lowlat? */
168 tty_flip_buffer_push(port
);
173 static irqreturn_t
sport_uart_tx_irq(int irq
, void *dev_id
)
175 struct sport_uart_port
*up
= dev_id
;
177 spin_lock(&up
->port
.lock
);
178 sport_uart_tx_chars(up
);
179 spin_unlock(&up
->port
.lock
);
184 static irqreturn_t
sport_uart_err_irq(int irq
, void *dev_id
)
186 struct sport_uart_port
*up
= dev_id
;
187 unsigned int stat
= SPORT_GET_STAT(up
);
189 spin_lock(&up
->port
.lock
);
191 /* Overflow in RX FIFO */
193 up
->port
.icount
.overrun
++;
194 tty_insert_flip_char(&up
->port
.state
->port
, 0, TTY_OVERRUN
);
195 SPORT_PUT_STAT(up
, ROVF
); /* Clear ROVF bit */
197 /* These should not happen */
198 if (stat
& (TOVF
| TUVF
| RUVF
)) {
199 pr_err("SPORT Error:%s %s %s\n",
200 (stat
& TOVF
) ? "TX overflow" : "",
201 (stat
& TUVF
) ? "TX underflow" : "",
202 (stat
& RUVF
) ? "RX underflow" : "");
203 SPORT_PUT_TCR1(up
, SPORT_GET_TCR1(up
) & ~TSPEN
);
204 SPORT_PUT_RCR1(up
, SPORT_GET_RCR1(up
) & ~RSPEN
);
208 spin_unlock(&up
->port
.lock
);
209 /* XXX we don't push the overrun bit to TTY? */
214 #ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
215 static unsigned int sport_get_mctrl(struct uart_port
*port
)
217 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
219 return TIOCM_CTS
| TIOCM_DSR
| TIOCM_CAR
;
221 /* CTS PIN is negative assertive. */
222 if (SPORT_UART_GET_CTS(up
))
223 return TIOCM_CTS
| TIOCM_DSR
| TIOCM_CAR
;
225 return TIOCM_DSR
| TIOCM_CAR
;
228 static void sport_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
230 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
234 /* RTS PIN is negative assertive. */
235 if (mctrl
& TIOCM_RTS
)
236 SPORT_UART_ENABLE_RTS(up
);
238 SPORT_UART_DISABLE_RTS(up
);
242 * Handle any change of modem status signal.
244 static irqreturn_t
sport_mctrl_cts_int(int irq
, void *dev_id
)
246 struct sport_uart_port
*up
= (struct sport_uart_port
*)dev_id
;
249 status
= sport_get_mctrl(&up
->port
);
250 uart_handle_cts_change(&up
->port
, status
& TIOCM_CTS
);
255 static unsigned int sport_get_mctrl(struct uart_port
*port
)
257 pr_debug("%s enter\n", __func__
);
258 return TIOCM_CTS
| TIOCM_CD
| TIOCM_DSR
;
261 static void sport_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
263 pr_debug("%s enter\n", __func__
);
267 /* Reqeust IRQ, Setup clock */
268 static int sport_startup(struct uart_port
*port
)
270 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
273 pr_debug("%s enter\n", __func__
);
274 ret
= request_irq(up
->port
.irq
, sport_uart_rx_irq
, 0,
275 "SPORT_UART_RX", up
);
277 dev_err(port
->dev
, "unable to request SPORT RX interrupt\n");
281 ret
= request_irq(up
->port
.irq
+1, sport_uart_tx_irq
, 0,
282 "SPORT_UART_TX", up
);
284 dev_err(port
->dev
, "unable to request SPORT TX interrupt\n");
288 ret
= request_irq(up
->err_irq
, sport_uart_err_irq
, 0,
289 "SPORT_UART_STATUS", up
);
291 dev_err(port
->dev
, "unable to request SPORT status interrupt\n");
295 #ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
296 if (up
->cts_pin
>= 0) {
297 if (request_irq(gpio_to_irq(up
->cts_pin
),
299 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
|
300 0, "BFIN_SPORT_UART_CTS", up
)) {
302 dev_info(port
->dev
, "Unable to attach BlackFin UART over SPORT CTS interrupt. So, disable it.\n");
305 if (up
->rts_pin
>= 0) {
306 if (gpio_request(up
->rts_pin
, DRV_NAME
)) {
307 dev_info(port
->dev
, "fail to request RTS PIN at GPIO_%d\n", up
->rts_pin
);
310 gpio_direction_output(up
->rts_pin
, 0);
316 free_irq(up
->port
.irq
+1, up
);
318 free_irq(up
->port
.irq
, up
);
324 * sport_uart_tx_chars
326 * ret 1 means need to enable sport.
327 * ret 0 means do nothing.
329 static int sport_uart_tx_chars(struct sport_uart_port
*up
)
331 struct circ_buf
*xmit
= &up
->port
.state
->xmit
;
333 if (SPORT_GET_STAT(up
) & TXF
)
336 if (up
->port
.x_char
) {
337 tx_one_byte(up
, up
->port
.x_char
);
338 up
->port
.icount
.tx
++;
343 if (uart_circ_empty(xmit
) || uart_tx_stopped(&up
->port
)) {
344 /* The waiting loop to stop SPORT TX from TX interrupt is
345 * too long. This may block SPORT RX interrupts and cause
346 * RX FIFO overflow. So, do stop sport TX only after the last
347 * char in TX FIFO is moved into the shift register.
349 if (SPORT_GET_STAT(up
) & TXHRE
)
350 sport_stop_tx(&up
->port
);
354 while(!(SPORT_GET_STAT(up
) & TXF
) && !uart_circ_empty(xmit
)) {
355 tx_one_byte(up
, xmit
->buf
[xmit
->tail
]);
356 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
-1);
357 up
->port
.icount
.tx
++;
360 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
361 uart_write_wakeup(&up
->port
);
366 static unsigned int sport_tx_empty(struct uart_port
*port
)
368 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
371 stat
= SPORT_GET_STAT(up
);
372 pr_debug("%s stat:%04x\n", __func__
, stat
);
379 static void sport_stop_tx(struct uart_port
*port
)
381 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
383 pr_debug("%s enter\n", __func__
);
385 if (!(SPORT_GET_TCR1(up
) & TSPEN
))
388 /* Although the hold register is empty, last byte is still in shift
389 * register and not sent out yet. So, put a dummy data into TX FIFO.
390 * Then, sport tx stops when last byte is shift out and the dummy
391 * data is moved into the shift register.
393 SPORT_PUT_TX(up
, 0xffff);
394 while (!(SPORT_GET_STAT(up
) & TXHRE
))
397 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) & ~TSPEN
));
403 static void sport_start_tx(struct uart_port
*port
)
405 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
407 pr_debug("%s enter\n", __func__
);
409 /* Write data into SPORT FIFO before enable SPROT to transmit */
410 if (sport_uart_tx_chars(up
)) {
411 /* Enable transmit, then an interrupt will generated */
412 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) | TSPEN
));
416 pr_debug("%s exit\n", __func__
);
419 static void sport_stop_rx(struct uart_port
*port
)
421 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
423 pr_debug("%s enter\n", __func__
);
424 /* Disable sport to stop rx */
425 SPORT_PUT_RCR1(up
, (SPORT_GET_RCR1(up
) & ~RSPEN
));
429 static void sport_enable_ms(struct uart_port
*port
)
431 pr_debug("%s enter\n", __func__
);
434 static void sport_break_ctl(struct uart_port
*port
, int break_state
)
436 pr_debug("%s enter\n", __func__
);
439 static void sport_shutdown(struct uart_port
*port
)
441 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
443 dev_dbg(port
->dev
, "%s enter\n", __func__
);
446 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) & ~TSPEN
));
447 SPORT_PUT_RCR1(up
, (SPORT_GET_RCR1(up
) & ~RSPEN
));
450 free_irq(up
->port
.irq
, up
);
451 free_irq(up
->port
.irq
+1, up
);
452 free_irq(up
->err_irq
, up
);
453 #ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
454 if (up
->cts_pin
>= 0)
455 free_irq(gpio_to_irq(up
->cts_pin
), up
);
456 if (up
->rts_pin
>= 0)
457 gpio_free(up
->rts_pin
);
461 static const char *sport_type(struct uart_port
*port
)
463 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
465 pr_debug("%s enter\n", __func__
);
466 return up
->port
.type
== PORT_BFIN_SPORT
? "BFIN-SPORT-UART" : NULL
;
469 static void sport_release_port(struct uart_port
*port
)
471 pr_debug("%s enter\n", __func__
);
474 static int sport_request_port(struct uart_port
*port
)
476 pr_debug("%s enter\n", __func__
);
480 static void sport_config_port(struct uart_port
*port
, int flags
)
482 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
484 pr_debug("%s enter\n", __func__
);
485 up
->port
.type
= PORT_BFIN_SPORT
;
488 static int sport_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
490 pr_debug("%s enter\n", __func__
);
494 static void sport_set_termios(struct uart_port
*port
,
495 struct ktermios
*termios
, struct ktermios
*old
)
497 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
501 pr_debug("%s enter, c_cflag:%08x\n", __func__
, termios
->c_cflag
);
503 switch (termios
->c_cflag
& CSIZE
) {
517 pr_warning("requested word length not supported\n");
520 if (termios
->c_cflag
& CSTOPB
) {
523 if (termios
->c_cflag
& PARENB
) {
524 pr_warning("PAREN bits is not supported yet\n");
528 spin_lock_irqsave(&up
->port
.lock
, flags
);
530 port
->read_status_mask
= 0;
533 * Characters to ignore
535 port
->ignore_status_mask
= 0;
537 /* RX extract mask */
538 up
->rxmask
= 0x01 | (((up
->csize
+ up
->stopb
) * 2 - 1) << 0x8);
539 /* TX masks, 8 bit data and 1 bit stop for example:
540 * mask1 = b#0111111110
541 * mask2 = b#1000000000
543 for (i
= 0, up
->txmask1
= 0; i
< up
->csize
; i
++)
544 up
->txmask1
|= (1<<i
);
545 up
->txmask2
= (1<<i
);
548 up
->txmask2
|= (1<<i
);
553 port
->uartclk
= uart_get_baud_rate(port
, termios
, old
, 0, get_sclk()/16);
556 SPORT_PUT_TCR1(up
, SPORT_GET_TCR1(up
) & ~TSPEN
);
557 SPORT_PUT_RCR1(up
, SPORT_GET_RCR1(up
) & ~RSPEN
);
559 sport_uart_setup(up
, up
->csize
+ up
->stopb
, port
->uartclk
);
561 /* driver TX line high after config, one dummy data is
562 * necessary to stop sport after shift one byte
564 SPORT_PUT_TX(up
, 0xffff);
565 SPORT_PUT_TX(up
, 0xffff);
566 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) | TSPEN
));
568 while (!(SPORT_GET_STAT(up
) & TXHRE
))
570 SPORT_PUT_TCR1(up
, SPORT_GET_TCR1(up
) & ~TSPEN
);
573 /* Port speed changed, update the per-port timeout. */
574 uart_update_timeout(port
, termios
->c_cflag
, port
->uartclk
);
576 /* Enable sport rx */
577 SPORT_PUT_RCR1(up
, SPORT_GET_RCR1(up
) | RSPEN
);
580 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
583 struct uart_ops sport_uart_ops
= {
584 .tx_empty
= sport_tx_empty
,
585 .set_mctrl
= sport_set_mctrl
,
586 .get_mctrl
= sport_get_mctrl
,
587 .stop_tx
= sport_stop_tx
,
588 .start_tx
= sport_start_tx
,
589 .stop_rx
= sport_stop_rx
,
590 .enable_ms
= sport_enable_ms
,
591 .break_ctl
= sport_break_ctl
,
592 .startup
= sport_startup
,
593 .shutdown
= sport_shutdown
,
594 .set_termios
= sport_set_termios
,
596 .release_port
= sport_release_port
,
597 .request_port
= sport_request_port
,
598 .config_port
= sport_config_port
,
599 .verify_port
= sport_verify_port
,
602 #define BFIN_SPORT_UART_MAX_PORTS 4
604 static struct sport_uart_port
*bfin_sport_uart_ports
[BFIN_SPORT_UART_MAX_PORTS
];
606 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
607 #define CLASS_BFIN_SPORT_CONSOLE "bfin-sport-console"
610 sport_uart_console_setup(struct console
*co
, char *options
)
612 struct sport_uart_port
*up
;
616 # ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
622 /* Check whether an invalid uart number has been specified */
623 if (co
->index
< 0 || co
->index
>= BFIN_SPORT_UART_MAX_PORTS
)
626 up
= bfin_sport_uart_ports
[co
->index
];
631 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
633 return uart_set_options(&up
->port
, co
, baud
, parity
, bits
, flow
);
636 static void sport_uart_console_putchar(struct uart_port
*port
, int ch
)
638 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
640 while (SPORT_GET_STAT(up
) & TXF
)
647 * Interrupts are disabled on entering
650 sport_uart_console_write(struct console
*co
, const char *s
, unsigned int count
)
652 struct sport_uart_port
*up
= bfin_sport_uart_ports
[co
->index
];
655 spin_lock_irqsave(&up
->port
.lock
, flags
);
657 if (SPORT_GET_TCR1(up
) & TSPEN
)
658 uart_console_write(&up
->port
, s
, count
, sport_uart_console_putchar
);
660 /* dummy data to start sport */
661 while (SPORT_GET_STAT(up
) & TXF
)
663 SPORT_PUT_TX(up
, 0xffff);
664 /* Enable transmit, then an interrupt will generated */
665 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) | TSPEN
));
668 uart_console_write(&up
->port
, s
, count
, sport_uart_console_putchar
);
670 /* Although the hold register is empty, last byte is still in shift
671 * register and not sent out yet. So, put a dummy data into TX FIFO.
672 * Then, sport tx stops when last byte is shift out and the dummy
673 * data is moved into the shift register.
675 while (SPORT_GET_STAT(up
) & TXF
)
677 SPORT_PUT_TX(up
, 0xffff);
678 while (!(SPORT_GET_STAT(up
) & TXHRE
))
681 /* Stop sport tx transfer */
682 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) & ~TSPEN
));
686 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
689 static struct uart_driver sport_uart_reg
;
691 static struct console sport_uart_console
= {
693 .write
= sport_uart_console_write
,
694 .device
= uart_console_device
,
695 .setup
= sport_uart_console_setup
,
696 .flags
= CON_PRINTBUFFER
,
698 .data
= &sport_uart_reg
,
701 #define SPORT_UART_CONSOLE (&sport_uart_console)
703 #define SPORT_UART_CONSOLE NULL
704 #endif /* CONFIG_SERIAL_BFIN_SPORT_CONSOLE */
707 static struct uart_driver sport_uart_reg
= {
708 .owner
= THIS_MODULE
,
709 .driver_name
= DRV_NAME
,
710 .dev_name
= DEVICE_NAME
,
713 .nr
= BFIN_SPORT_UART_MAX_PORTS
,
714 .cons
= SPORT_UART_CONSOLE
,
718 static int sport_uart_suspend(struct device
*dev
)
720 struct sport_uart_port
*sport
= dev_get_drvdata(dev
);
722 dev_dbg(dev
, "%s enter\n", __func__
);
724 uart_suspend_port(&sport_uart_reg
, &sport
->port
);
729 static int sport_uart_resume(struct device
*dev
)
731 struct sport_uart_port
*sport
= dev_get_drvdata(dev
);
733 dev_dbg(dev
, "%s enter\n", __func__
);
735 uart_resume_port(&sport_uart_reg
, &sport
->port
);
740 static struct dev_pm_ops bfin_sport_uart_dev_pm_ops
= {
741 .suspend
= sport_uart_suspend
,
742 .resume
= sport_uart_resume
,
746 static int sport_uart_probe(struct platform_device
*pdev
)
748 struct resource
*res
;
749 struct sport_uart_port
*sport
;
752 dev_dbg(&pdev
->dev
, "%s enter\n", __func__
);
754 if (pdev
->id
< 0 || pdev
->id
>= BFIN_SPORT_UART_MAX_PORTS
) {
755 dev_err(&pdev
->dev
, "Wrong sport uart platform device id.\n");
759 if (bfin_sport_uart_ports
[pdev
->id
] == NULL
) {
760 bfin_sport_uart_ports
[pdev
->id
] =
761 kzalloc(sizeof(struct sport_uart_port
), GFP_KERNEL
);
762 sport
= bfin_sport_uart_ports
[pdev
->id
];
765 "Fail to malloc sport_uart_port\n");
769 ret
= peripheral_request_list(
770 (unsigned short *)dev_get_platdata(&pdev
->dev
),
774 "Fail to request SPORT peripherals\n");
775 goto out_error_free_mem
;
778 spin_lock_init(&sport
->port
.lock
);
779 sport
->port
.fifosize
= SPORT_TX_FIFO_SIZE
,
780 sport
->port
.ops
= &sport_uart_ops
;
781 sport
->port
.line
= pdev
->id
;
782 sport
->port
.iotype
= UPIO_MEM
;
783 sport
->port
.flags
= UPF_BOOT_AUTOCONF
;
785 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
787 dev_err(&pdev
->dev
, "Cannot get IORESOURCE_MEM\n");
789 goto out_error_free_peripherals
;
792 sport
->port
.membase
= ioremap(res
->start
, resource_size(res
));
793 if (!sport
->port
.membase
) {
794 dev_err(&pdev
->dev
, "Cannot map sport IO\n");
796 goto out_error_free_peripherals
;
798 sport
->port
.mapbase
= res
->start
;
800 sport
->port
.irq
= platform_get_irq(pdev
, 0);
801 if ((int)sport
->port
.irq
< 0) {
802 dev_err(&pdev
->dev
, "No sport RX/TX IRQ specified\n");
804 goto out_error_unmap
;
807 sport
->err_irq
= platform_get_irq(pdev
, 1);
808 if (sport
->err_irq
< 0) {
809 dev_err(&pdev
->dev
, "No sport status IRQ specified\n");
811 goto out_error_unmap
;
813 #ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
814 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
818 sport
->cts_pin
= res
->start
;
819 sport
->port
.flags
|= ASYNC_CTS_FLOW
;
822 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 1);
826 sport
->rts_pin
= res
->start
;
830 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
831 if (!is_early_platform_device(pdev
)) {
833 sport
= bfin_sport_uart_ports
[pdev
->id
];
834 sport
->port
.dev
= &pdev
->dev
;
835 dev_set_drvdata(&pdev
->dev
, sport
);
836 ret
= uart_add_one_port(&sport_uart_reg
, &sport
->port
);
837 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
845 iounmap(sport
->port
.membase
);
846 out_error_free_peripherals
:
847 peripheral_free_list(
848 (unsigned short *)dev_get_platdata(&pdev
->dev
));
851 bfin_sport_uart_ports
[pdev
->id
] = NULL
;
857 static int sport_uart_remove(struct platform_device
*pdev
)
859 struct sport_uart_port
*sport
= platform_get_drvdata(pdev
);
861 dev_dbg(&pdev
->dev
, "%s enter\n", __func__
);
862 dev_set_drvdata(&pdev
->dev
, NULL
);
865 uart_remove_one_port(&sport_uart_reg
, &sport
->port
);
866 iounmap(sport
->port
.membase
);
867 peripheral_free_list(
868 (unsigned short *)dev_get_platdata(&pdev
->dev
));
870 bfin_sport_uart_ports
[pdev
->id
] = NULL
;
876 static struct platform_driver sport_uart_driver
= {
877 .probe
= sport_uart_probe
,
878 .remove
= sport_uart_remove
,
882 .pm
= &bfin_sport_uart_dev_pm_ops
,
887 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
888 static struct early_platform_driver early_sport_uart_driver __initdata
= {
889 .class_str
= CLASS_BFIN_SPORT_CONSOLE
,
890 .pdrv
= &sport_uart_driver
,
891 .requested_id
= EARLY_PLATFORM_ID_UNSET
,
894 static int __init
sport_uart_rs_console_init(void)
896 early_platform_driver_register(&early_sport_uart_driver
, DRV_NAME
);
898 early_platform_driver_probe(CLASS_BFIN_SPORT_CONSOLE
,
899 BFIN_SPORT_UART_MAX_PORTS
, 0);
901 register_console(&sport_uart_console
);
905 console_initcall(sport_uart_rs_console_init
);
908 static int __init
sport_uart_init(void)
912 pr_info("Blackfin uart over sport driver\n");
914 ret
= uart_register_driver(&sport_uart_reg
);
916 pr_err("failed to register %s:%d\n",
917 sport_uart_reg
.driver_name
, ret
);
921 ret
= platform_driver_register(&sport_uart_driver
);
923 pr_err("failed to register sport uart driver:%d\n", ret
);
924 uart_unregister_driver(&sport_uart_reg
);
929 module_init(sport_uart_init
);
931 static void __exit
sport_uart_exit(void)
933 platform_driver_unregister(&sport_uart_driver
);
934 uart_unregister_driver(&sport_uart_reg
);
936 module_exit(sport_uart_exit
);
938 MODULE_AUTHOR("Sonic Zhang, Roy Huang");
939 MODULE_DESCRIPTION("Blackfin serial over SPORT driver");
940 MODULE_LICENSE("GPL");