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/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 rclkdiv
= sclk
/ (2 * baud_rate
* 2) - 1;
135 SPORT_PUT_TCLKDIV(up
, tclkdiv
);
136 SPORT_PUT_RCLKDIV(up
, rclkdiv
);
138 pr_debug("%s sclk:%d, baud_rate:%d, tclkdiv:%d, rclkdiv:%d\n",
139 __func__
, sclk
, baud_rate
, tclkdiv
, rclkdiv
);
144 static irqreturn_t
sport_uart_rx_irq(int irq
, void *dev_id
)
146 struct sport_uart_port
*up
= dev_id
;
147 struct tty_struct
*tty
= up
->port
.state
->port
.tty
;
150 spin_lock(&up
->port
.lock
);
152 while (SPORT_GET_STAT(up
) & RXNE
) {
153 ch
= rx_one_byte(up
);
154 up
->port
.icount
.rx
++;
156 if (!uart_handle_sysrq_char(&up
->port
, ch
))
157 tty_insert_flip_char(tty
, ch
, TTY_NORMAL
);
159 tty_flip_buffer_push(tty
);
161 spin_unlock(&up
->port
.lock
);
166 static irqreturn_t
sport_uart_tx_irq(int irq
, void *dev_id
)
168 struct sport_uart_port
*up
= dev_id
;
170 spin_lock(&up
->port
.lock
);
171 sport_uart_tx_chars(up
);
172 spin_unlock(&up
->port
.lock
);
177 static irqreturn_t
sport_uart_err_irq(int irq
, void *dev_id
)
179 struct sport_uart_port
*up
= dev_id
;
180 struct tty_struct
*tty
= up
->port
.state
->port
.tty
;
181 unsigned int stat
= SPORT_GET_STAT(up
);
183 spin_lock(&up
->port
.lock
);
185 /* Overflow in RX FIFO */
187 up
->port
.icount
.overrun
++;
188 tty_insert_flip_char(tty
, 0, TTY_OVERRUN
);
189 SPORT_PUT_STAT(up
, ROVF
); /* Clear ROVF bit */
191 /* These should not happen */
192 if (stat
& (TOVF
| TUVF
| RUVF
)) {
193 pr_err("SPORT Error:%s %s %s\n",
194 (stat
& TOVF
) ? "TX overflow" : "",
195 (stat
& TUVF
) ? "TX underflow" : "",
196 (stat
& RUVF
) ? "RX underflow" : "");
197 SPORT_PUT_TCR1(up
, SPORT_GET_TCR1(up
) & ~TSPEN
);
198 SPORT_PUT_RCR1(up
, SPORT_GET_RCR1(up
) & ~RSPEN
);
202 spin_unlock(&up
->port
.lock
);
206 #ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
207 static unsigned int sport_get_mctrl(struct uart_port
*port
)
209 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
211 return TIOCM_CTS
| TIOCM_DSR
| TIOCM_CAR
;
213 /* CTS PIN is negative assertive. */
214 if (SPORT_UART_GET_CTS(up
))
215 return TIOCM_CTS
| TIOCM_DSR
| TIOCM_CAR
;
217 return TIOCM_DSR
| TIOCM_CAR
;
220 static void sport_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
222 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
226 /* RTS PIN is negative assertive. */
227 if (mctrl
& TIOCM_RTS
)
228 SPORT_UART_ENABLE_RTS(up
);
230 SPORT_UART_DISABLE_RTS(up
);
234 * Handle any change of modem status signal.
236 static irqreturn_t
sport_mctrl_cts_int(int irq
, void *dev_id
)
238 struct sport_uart_port
*up
= (struct sport_uart_port
*)dev_id
;
241 status
= sport_get_mctrl(&up
->port
);
242 uart_handle_cts_change(&up
->port
, status
& TIOCM_CTS
);
247 static unsigned int sport_get_mctrl(struct uart_port
*port
)
249 pr_debug("%s enter\n", __func__
);
250 return TIOCM_CTS
| TIOCM_CD
| TIOCM_DSR
;
253 static void sport_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
255 pr_debug("%s enter\n", __func__
);
259 /* Reqeust IRQ, Setup clock */
260 static int sport_startup(struct uart_port
*port
)
262 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
265 pr_debug("%s enter\n", __func__
);
266 ret
= request_irq(up
->port
.irq
, sport_uart_rx_irq
, 0,
267 "SPORT_UART_RX", up
);
269 dev_err(port
->dev
, "unable to request SPORT RX interrupt\n");
273 ret
= request_irq(up
->port
.irq
+1, sport_uart_tx_irq
, 0,
274 "SPORT_UART_TX", up
);
276 dev_err(port
->dev
, "unable to request SPORT TX interrupt\n");
280 ret
= request_irq(up
->err_irq
, sport_uart_err_irq
, 0,
281 "SPORT_UART_STATUS", up
);
283 dev_err(port
->dev
, "unable to request SPORT status interrupt\n");
287 #ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
288 if (up
->cts_pin
>= 0) {
289 if (request_irq(gpio_to_irq(up
->cts_pin
),
291 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
|
292 IRQF_DISABLED
, "BFIN_SPORT_UART_CTS", up
)) {
294 dev_info(port
->dev
, "Unable to attach BlackFin UART \
295 over SPORT CTS interrupt. So, disable it.\n");
298 if (up
->rts_pin
>= 0)
299 gpio_direction_output(up
->rts_pin
, 0);
304 free_irq(up
->port
.irq
+1, up
);
306 free_irq(up
->port
.irq
, up
);
312 * sport_uart_tx_chars
314 * ret 1 means need to enable sport.
315 * ret 0 means do nothing.
317 static int sport_uart_tx_chars(struct sport_uart_port
*up
)
319 struct circ_buf
*xmit
= &up
->port
.state
->xmit
;
321 if (SPORT_GET_STAT(up
) & TXF
)
324 if (up
->port
.x_char
) {
325 tx_one_byte(up
, up
->port
.x_char
);
326 up
->port
.icount
.tx
++;
331 if (uart_circ_empty(xmit
) || uart_tx_stopped(&up
->port
)) {
332 /* The waiting loop to stop SPORT TX from TX interrupt is
333 * too long. This may block SPORT RX interrupts and cause
334 * RX FIFO overflow. So, do stop sport TX only after the last
335 * char in TX FIFO is moved into the shift register.
337 if (SPORT_GET_STAT(up
) & TXHRE
)
338 sport_stop_tx(&up
->port
);
342 while(!(SPORT_GET_STAT(up
) & TXF
) && !uart_circ_empty(xmit
)) {
343 tx_one_byte(up
, xmit
->buf
[xmit
->tail
]);
344 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
-1);
345 up
->port
.icount
.tx
++;
348 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
349 uart_write_wakeup(&up
->port
);
354 static unsigned int sport_tx_empty(struct uart_port
*port
)
356 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
359 stat
= SPORT_GET_STAT(up
);
360 pr_debug("%s stat:%04x\n", __func__
, stat
);
367 static void sport_stop_tx(struct uart_port
*port
)
369 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
371 pr_debug("%s enter\n", __func__
);
373 if (!(SPORT_GET_TCR1(up
) & TSPEN
))
376 /* Although the hold register is empty, last byte is still in shift
377 * register and not sent out yet. So, put a dummy data into TX FIFO.
378 * Then, sport tx stops when last byte is shift out and the dummy
379 * data is moved into the shift register.
381 SPORT_PUT_TX(up
, 0xffff);
382 while (!(SPORT_GET_STAT(up
) & TXHRE
))
385 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) & ~TSPEN
));
391 static void sport_start_tx(struct uart_port
*port
)
393 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
395 pr_debug("%s enter\n", __func__
);
397 /* Write data into SPORT FIFO before enable SPROT to transmit */
398 if (sport_uart_tx_chars(up
)) {
399 /* Enable transmit, then an interrupt will generated */
400 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) | TSPEN
));
404 pr_debug("%s exit\n", __func__
);
407 static void sport_stop_rx(struct uart_port
*port
)
409 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
411 pr_debug("%s enter\n", __func__
);
412 /* Disable sport to stop rx */
413 SPORT_PUT_RCR1(up
, (SPORT_GET_RCR1(up
) & ~RSPEN
));
417 static void sport_enable_ms(struct uart_port
*port
)
419 pr_debug("%s enter\n", __func__
);
422 static void sport_break_ctl(struct uart_port
*port
, int break_state
)
424 pr_debug("%s enter\n", __func__
);
427 static void sport_shutdown(struct uart_port
*port
)
429 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
431 dev_dbg(port
->dev
, "%s enter\n", __func__
);
434 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) & ~TSPEN
));
435 SPORT_PUT_RCR1(up
, (SPORT_GET_RCR1(up
) & ~RSPEN
));
438 free_irq(up
->port
.irq
, up
);
439 free_irq(up
->port
.irq
+1, up
);
440 free_irq(up
->err_irq
, up
);
441 #ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
442 if (up
->cts_pin
>= 0)
443 free_irq(gpio_to_irq(up
->cts_pin
), up
);
447 static const char *sport_type(struct uart_port
*port
)
449 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
451 pr_debug("%s enter\n", __func__
);
452 return up
->port
.type
== PORT_BFIN_SPORT
? "BFIN-SPORT-UART" : NULL
;
455 static void sport_release_port(struct uart_port
*port
)
457 pr_debug("%s enter\n", __func__
);
460 static int sport_request_port(struct uart_port
*port
)
462 pr_debug("%s enter\n", __func__
);
466 static void sport_config_port(struct uart_port
*port
, int flags
)
468 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
470 pr_debug("%s enter\n", __func__
);
471 up
->port
.type
= PORT_BFIN_SPORT
;
474 static int sport_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
476 pr_debug("%s enter\n", __func__
);
480 static void sport_set_termios(struct uart_port
*port
,
481 struct ktermios
*termios
, struct ktermios
*old
)
483 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
487 pr_debug("%s enter, c_cflag:%08x\n", __func__
, termios
->c_cflag
);
489 switch (termios
->c_cflag
& CSIZE
) {
503 pr_warning("requested word length not supported\n");
506 if (termios
->c_cflag
& CSTOPB
) {
509 if (termios
->c_cflag
& PARENB
) {
510 pr_warning("PAREN bits is not supported yet\n");
514 spin_lock_irqsave(&up
->port
.lock
, flags
);
516 port
->read_status_mask
= 0;
519 * Characters to ignore
521 port
->ignore_status_mask
= 0;
523 /* RX extract mask */
524 up
->rxmask
= 0x01 | (((up
->csize
+ up
->stopb
) * 2 - 1) << 0x8);
525 /* TX masks, 8 bit data and 1 bit stop for example:
526 * mask1 = b#0111111110
527 * mask2 = b#1000000000
529 for (i
= 0, up
->txmask1
= 0; i
< up
->csize
; i
++)
530 up
->txmask1
|= (1<<i
);
531 up
->txmask2
= (1<<i
);
534 up
->txmask2
|= (1<<i
);
539 port
->uartclk
= uart_get_baud_rate(port
, termios
, old
, 0, get_sclk()/16);
542 SPORT_PUT_TCR1(up
, SPORT_GET_TCR1(up
) & ~TSPEN
);
543 SPORT_PUT_RCR1(up
, SPORT_GET_RCR1(up
) & ~RSPEN
);
545 sport_uart_setup(up
, up
->csize
+ up
->stopb
, port
->uartclk
);
547 /* driver TX line high after config, one dummy data is
548 * necessary to stop sport after shift one byte
550 SPORT_PUT_TX(up
, 0xffff);
551 SPORT_PUT_TX(up
, 0xffff);
552 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) | TSPEN
));
554 while (!(SPORT_GET_STAT(up
) & TXHRE
))
556 SPORT_PUT_TCR1(up
, SPORT_GET_TCR1(up
) & ~TSPEN
);
559 /* Port speed changed, update the per-port timeout. */
560 uart_update_timeout(port
, termios
->c_cflag
, port
->uartclk
);
562 /* Enable sport rx */
563 SPORT_PUT_RCR1(up
, SPORT_GET_RCR1(up
) | RSPEN
);
566 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
569 struct uart_ops sport_uart_ops
= {
570 .tx_empty
= sport_tx_empty
,
571 .set_mctrl
= sport_set_mctrl
,
572 .get_mctrl
= sport_get_mctrl
,
573 .stop_tx
= sport_stop_tx
,
574 .start_tx
= sport_start_tx
,
575 .stop_rx
= sport_stop_rx
,
576 .enable_ms
= sport_enable_ms
,
577 .break_ctl
= sport_break_ctl
,
578 .startup
= sport_startup
,
579 .shutdown
= sport_shutdown
,
580 .set_termios
= sport_set_termios
,
582 .release_port
= sport_release_port
,
583 .request_port
= sport_request_port
,
584 .config_port
= sport_config_port
,
585 .verify_port
= sport_verify_port
,
588 #define BFIN_SPORT_UART_MAX_PORTS 4
590 static struct sport_uart_port
*bfin_sport_uart_ports
[BFIN_SPORT_UART_MAX_PORTS
];
592 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
593 #define CLASS_BFIN_SPORT_CONSOLE "bfin-sport-console"
596 sport_uart_console_setup(struct console
*co
, char *options
)
598 struct sport_uart_port
*up
;
602 # ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
608 /* Check whether an invalid uart number has been specified */
609 if (co
->index
< 0 || co
->index
>= BFIN_SPORT_UART_MAX_PORTS
)
612 up
= bfin_sport_uart_ports
[co
->index
];
617 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
619 return uart_set_options(&up
->port
, co
, baud
, parity
, bits
, flow
);
622 static void sport_uart_console_putchar(struct uart_port
*port
, int ch
)
624 struct sport_uart_port
*up
= (struct sport_uart_port
*)port
;
626 while (SPORT_GET_STAT(up
) & TXF
)
633 * Interrupts are disabled on entering
636 sport_uart_console_write(struct console
*co
, const char *s
, unsigned int count
)
638 struct sport_uart_port
*up
= bfin_sport_uart_ports
[co
->index
];
641 spin_lock_irqsave(&up
->port
.lock
, flags
);
643 if (SPORT_GET_TCR1(up
) & TSPEN
)
644 uart_console_write(&up
->port
, s
, count
, sport_uart_console_putchar
);
646 /* dummy data to start sport */
647 while (SPORT_GET_STAT(up
) & TXF
)
649 SPORT_PUT_TX(up
, 0xffff);
650 /* Enable transmit, then an interrupt will generated */
651 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) | TSPEN
));
654 uart_console_write(&up
->port
, s
, count
, sport_uart_console_putchar
);
656 /* Although the hold register is empty, last byte is still in shift
657 * register and not sent out yet. So, put a dummy data into TX FIFO.
658 * Then, sport tx stops when last byte is shift out and the dummy
659 * data is moved into the shift register.
661 while (SPORT_GET_STAT(up
) & TXF
)
663 SPORT_PUT_TX(up
, 0xffff);
664 while (!(SPORT_GET_STAT(up
) & TXHRE
))
667 /* Stop sport tx transfer */
668 SPORT_PUT_TCR1(up
, (SPORT_GET_TCR1(up
) & ~TSPEN
));
672 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
675 static struct uart_driver sport_uart_reg
;
677 static struct console sport_uart_console
= {
679 .write
= sport_uart_console_write
,
680 .device
= uart_console_device
,
681 .setup
= sport_uart_console_setup
,
682 .flags
= CON_PRINTBUFFER
,
684 .data
= &sport_uart_reg
,
687 #define SPORT_UART_CONSOLE (&sport_uart_console)
689 #define SPORT_UART_CONSOLE NULL
690 #endif /* CONFIG_SERIAL_BFIN_SPORT_CONSOLE */
693 static struct uart_driver sport_uart_reg
= {
694 .owner
= THIS_MODULE
,
695 .driver_name
= DRV_NAME
,
696 .dev_name
= DEVICE_NAME
,
699 .nr
= BFIN_SPORT_UART_MAX_PORTS
,
700 .cons
= SPORT_UART_CONSOLE
,
704 static int sport_uart_suspend(struct device
*dev
)
706 struct sport_uart_port
*sport
= dev_get_drvdata(dev
);
708 dev_dbg(dev
, "%s enter\n", __func__
);
710 uart_suspend_port(&sport_uart_reg
, &sport
->port
);
715 static int sport_uart_resume(struct device
*dev
)
717 struct sport_uart_port
*sport
= dev_get_drvdata(dev
);
719 dev_dbg(dev
, "%s enter\n", __func__
);
721 uart_resume_port(&sport_uart_reg
, &sport
->port
);
726 static struct dev_pm_ops bfin_sport_uart_dev_pm_ops
= {
727 .suspend
= sport_uart_suspend
,
728 .resume
= sport_uart_resume
,
732 static int __devinit
sport_uart_probe(struct platform_device
*pdev
)
734 struct resource
*res
;
735 struct sport_uart_port
*sport
;
738 dev_dbg(&pdev
->dev
, "%s enter\n", __func__
);
740 if (pdev
->id
< 0 || pdev
->id
>= BFIN_SPORT_UART_MAX_PORTS
) {
741 dev_err(&pdev
->dev
, "Wrong sport uart platform device id.\n");
745 if (bfin_sport_uart_ports
[pdev
->id
] == NULL
) {
746 bfin_sport_uart_ports
[pdev
->id
] =
747 kzalloc(sizeof(struct sport_uart_port
), GFP_KERNEL
);
748 sport
= bfin_sport_uart_ports
[pdev
->id
];
751 "Fail to malloc sport_uart_port\n");
755 ret
= peripheral_request_list(
756 (unsigned short *)pdev
->dev
.platform_data
, DRV_NAME
);
759 "Fail to request SPORT peripherals\n");
760 goto out_error_free_mem
;
763 spin_lock_init(&sport
->port
.lock
);
764 sport
->port
.fifosize
= SPORT_TX_FIFO_SIZE
,
765 sport
->port
.ops
= &sport_uart_ops
;
766 sport
->port
.line
= pdev
->id
;
767 sport
->port
.iotype
= UPIO_MEM
;
768 sport
->port
.flags
= UPF_BOOT_AUTOCONF
;
770 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
772 dev_err(&pdev
->dev
, "Cannot get IORESOURCE_MEM\n");
774 goto out_error_free_peripherals
;
777 sport
->port
.membase
= ioremap(res
->start
, resource_size(res
));
778 if (!sport
->port
.membase
) {
779 dev_err(&pdev
->dev
, "Cannot map sport IO\n");
781 goto out_error_free_peripherals
;
783 sport
->port
.mapbase
= res
->start
;
785 sport
->port
.irq
= platform_get_irq(pdev
, 0);
786 if (sport
->port
.irq
< 0) {
787 dev_err(&pdev
->dev
, "No sport RX/TX IRQ specified\n");
789 goto out_error_unmap
;
792 sport
->err_irq
= platform_get_irq(pdev
, 1);
793 if (sport
->err_irq
< 0) {
794 dev_err(&pdev
->dev
, "No sport status IRQ specified\n");
796 goto out_error_unmap
;
798 #ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
799 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
803 sport
->cts_pin
= res
->start
;
805 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 1);
809 sport
->rts_pin
= res
->start
;
811 if (sport
->rts_pin
>= 0)
812 gpio_request(sport
->rts_pin
, DRV_NAME
);
816 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
817 if (!is_early_platform_device(pdev
)) {
819 sport
= bfin_sport_uart_ports
[pdev
->id
];
820 sport
->port
.dev
= &pdev
->dev
;
821 dev_set_drvdata(&pdev
->dev
, sport
);
822 ret
= uart_add_one_port(&sport_uart_reg
, &sport
->port
);
823 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
831 iounmap(sport
->port
.membase
);
832 out_error_free_peripherals
:
833 peripheral_free_list(
834 (unsigned short *)pdev
->dev
.platform_data
);
837 bfin_sport_uart_ports
[pdev
->id
] = NULL
;
843 static int __devexit
sport_uart_remove(struct platform_device
*pdev
)
845 struct sport_uart_port
*sport
= platform_get_drvdata(pdev
);
847 dev_dbg(&pdev
->dev
, "%s enter\n", __func__
);
848 dev_set_drvdata(&pdev
->dev
, NULL
);
851 uart_remove_one_port(&sport_uart_reg
, &sport
->port
);
852 #ifdef CONFIG_SERIAL_BFIN_CTSRTS
853 if (sport
->rts_pin
>= 0)
854 gpio_free(sport
->rts_pin
);
856 iounmap(sport
->port
.membase
);
857 peripheral_free_list(
858 (unsigned short *)pdev
->dev
.platform_data
);
860 bfin_sport_uart_ports
[pdev
->id
] = NULL
;
866 static struct platform_driver sport_uart_driver
= {
867 .probe
= sport_uart_probe
,
868 .remove
= __devexit_p(sport_uart_remove
),
872 .pm
= &bfin_sport_uart_dev_pm_ops
,
877 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
878 static __initdata
struct early_platform_driver early_sport_uart_driver
= {
879 .class_str
= CLASS_BFIN_SPORT_CONSOLE
,
880 .pdrv
= &sport_uart_driver
,
881 .requested_id
= EARLY_PLATFORM_ID_UNSET
,
884 static int __init
sport_uart_rs_console_init(void)
886 early_platform_driver_register(&early_sport_uart_driver
, DRV_NAME
);
888 early_platform_driver_probe(CLASS_BFIN_SPORT_CONSOLE
,
889 BFIN_SPORT_UART_MAX_PORTS
, 0);
891 register_console(&sport_uart_console
);
895 console_initcall(sport_uart_rs_console_init
);
898 static int __init
sport_uart_init(void)
902 pr_info("Blackfin uart over sport driver\n");
904 ret
= uart_register_driver(&sport_uart_reg
);
906 pr_err("failed to register %s:%d\n",
907 sport_uart_reg
.driver_name
, ret
);
911 ret
= platform_driver_register(&sport_uart_driver
);
913 pr_err("failed to register sport uart driver:%d\n", ret
);
914 uart_unregister_driver(&sport_uart_reg
);
919 module_init(sport_uart_init
);
921 static void __exit
sport_uart_exit(void)
923 platform_driver_unregister(&sport_uart_driver
);
924 uart_unregister_driver(&sport_uart_reg
);
926 module_exit(sport_uart_exit
);
928 MODULE_AUTHOR("Sonic Zhang, Roy Huang");
929 MODULE_DESCRIPTION("Blackfin serial over SPORT driver");
930 MODULE_LICENSE("GPL");