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>
31 #include <linux/slab.h>
33 #include <linux/tty.h>
35 #include <linux/serial_core.h>
38 #include <asm/delay.h>
52 #ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
63 pr_debug(
"%s value:%x, mask1=0x%x, mask2=0x%x\n", __func__, value,
69 "%[val] = %[val] & %[mask1];"
70 "%[val] = %[val] | %[mask2];"
75 pr_debug(
"%s value:%x\n", __func__, value);
83 unsigned char extract;
84 u32 tmp_mask1, tmp_mask2, tmp_shift,
tmp;
91 pr_debug(
"%s value:%x, cs=%d, mask=0x%x\n", __func__, value,
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)
111 :
"ASTAT",
"LB0",
"LC0",
"LT0"
120 int tclkdiv, rclkdiv;
133 tclkdiv = sclk / (2 * baud_rate) - 1;
139 rclkdiv = sclk / (2 * baud_rate * 2 * 97 / 100) - 1;
143 pr_debug(
"%s sclk:%d, baud_rate:%d, tclkdiv:%d, rclkdiv:%d\n",
144 __func__, sclk, baud_rate, tclkdiv, rclkdiv);
155 spin_lock(&up->
port.lock);
158 ch = rx_one_byte(up);
159 up->
port.icount.rx++;
166 spin_unlock(&up->
port.lock);
171 static irqreturn_t sport_uart_tx_irq(
int irq,
void *dev_id)
175 spin_lock(&up->
port.lock);
176 sport_uart_tx_chars(up);
177 spin_unlock(&up->
port.lock);
182 static irqreturn_t sport_uart_err_irq(
int irq,
void *dev_id)
188 spin_lock(&up->
port.lock);
192 up->
port.icount.overrun++;
198 pr_err(
"SPORT Error:%s %s %s\n",
199 (stat &
TOVF) ?
"TX overflow" :
"",
200 (stat &
TUVF) ?
"TX underflow" :
"",
201 (stat &
RUVF) ?
"RX underflow" :
"");
207 spin_unlock(&up->
port.lock);
211 #ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
225 static void sport_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
241 static irqreturn_t sport_mctrl_cts_int(
int irq,
void *dev_id)
246 status = sport_get_mctrl(&up->
port);
252 static unsigned int sport_get_mctrl(
struct uart_port *port)
258 static void sport_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
265 static int sport_startup(
struct uart_port *port)
272 "SPORT_UART_RX", up);
274 dev_err(port->
dev,
"unable to request SPORT RX interrupt\n");
279 "SPORT_UART_TX", up);
281 dev_err(port->
dev,
"unable to request SPORT TX interrupt\n");
286 "SPORT_UART_STATUS", up);
288 dev_err(port->
dev,
"unable to request SPORT status interrupt\n");
292 #ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
293 if (up->cts_pin >= 0) {
297 0,
"BFIN_SPORT_UART_CTS", up)) {
299 dev_info(port->
dev,
"Unable to attach BlackFin UART over SPORT CTS interrupt. So, disable it.\n");
302 if (up->rts_pin >= 0) {
304 dev_info(port->
dev,
"fail to request RTS PIN at GPIO_%d\n", up->rts_pin);
333 if (up->
port.x_char) {
334 tx_one_byte(up, up->
port.x_char);
335 up->
port.icount.tx++;
347 sport_stop_tx(&up->
port);
352 tx_one_byte(up, xmit->
buf[xmit->
tail]);
354 up->
port.icount.tx++;
363 static unsigned int sport_tx_empty(
struct uart_port *port)
369 pr_debug(
"%s stat:%04x\n", __func__, stat);
376 static void sport_stop_tx(
struct uart_port *port)
400 static void sport_start_tx(
struct uart_port *port)
407 if (sport_uart_tx_chars(up)) {
416 static void sport_stop_rx(
struct uart_port *port)
426 static void sport_enable_ms(
struct uart_port *port)
431 static void sport_break_ctl(
struct uart_port *port,
int break_state)
436 static void sport_shutdown(
struct uart_port *port)
450 #ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
451 if (up->cts_pin >= 0)
453 if (up->rts_pin >= 0)
458 static const char *sport_type(
struct uart_port *port)
466 static void sport_release_port(
struct uart_port *port)
471 static int sport_request_port(
struct uart_port *port)
491 static void sport_set_termios(
struct uart_port *port,
514 pr_warning(
"requested word length not supported\n");
521 pr_warning(
"PAREN bits is not supported yet\n");
577 spin_unlock_irqrestore(&up->
port.lock, flags);
581 .tx_empty = sport_tx_empty,
582 .set_mctrl = sport_set_mctrl,
583 .get_mctrl = sport_get_mctrl,
584 .stop_tx = sport_stop_tx,
585 .start_tx = sport_start_tx,
586 .stop_rx = sport_stop_rx,
587 .enable_ms = sport_enable_ms,
588 .break_ctl = sport_break_ctl,
589 .startup = sport_startup,
590 .shutdown = sport_shutdown,
591 .set_termios = sport_set_termios,
593 .release_port = sport_release_port,
594 .request_port = sport_request_port,
595 .config_port = sport_config_port,
596 .verify_port = sport_verify_port,
599 #define BFIN_SPORT_UART_MAX_PORTS 4
603 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
604 #define CLASS_BFIN_SPORT_CONSOLE "bfin-sport-console"
613 # ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
623 up = bfin_sport_uart_ports[co->
index];
633 static void sport_uart_console_putchar(
struct uart_port *port,
int ch)
647 sport_uart_console_write(
struct console *co,
const char *
s,
unsigned int count)
683 spin_unlock_irqrestore(&up->
port.lock, flags);
688 static struct console sport_uart_console = {
690 .write = sport_uart_console_write,
692 .setup = sport_uart_console_setup,
695 .data = &sport_uart_reg,
698 #define SPORT_UART_CONSOLE (&sport_uart_console)
700 #define SPORT_UART_CONSOLE NULL
715 static int sport_uart_suspend(
struct device *
dev)
719 dev_dbg(dev,
"%s enter\n", __func__);
726 static int sport_uart_resume(
struct device *dev)
730 dev_dbg(dev,
"%s enter\n", __func__);
737 static struct dev_pm_ops bfin_sport_uart_dev_pm_ops = {
739 .resume = sport_uart_resume,
752 dev_err(&pdev->
dev,
"Wrong sport uart platform device id.\n");
756 if (bfin_sport_uart_ports[pdev->
id] ==
NULL) {
757 bfin_sport_uart_ports[pdev->
id] =
759 sport = bfin_sport_uart_ports[pdev->
id];
762 "Fail to malloc sport_uart_port\n");
767 (
unsigned short *)pdev->
dev.platform_data,
DRV_NAME);
770 "Fail to request SPORT peripherals\n");
771 goto out_error_free_mem;
777 sport->
port.line = pdev->
id;
783 dev_err(&pdev->
dev,
"Cannot get IORESOURCE_MEM\n");
785 goto out_error_free_peripherals;
789 if (!sport->
port.membase) {
792 goto out_error_free_peripherals;
797 if ((
int)sport->
port.irq < 0) {
798 dev_err(&pdev->
dev,
"No sport RX/TX IRQ specified\n");
800 goto out_error_unmap;
805 dev_err(&pdev->
dev,
"No sport status IRQ specified\n");
807 goto out_error_unmap;
809 #ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
814 sport->cts_pin = res->
start;
822 sport->rts_pin = res->
start;
826 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
827 if (!is_early_platform_device(pdev)) {
829 sport = bfin_sport_uart_ports[pdev->
id];
833 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
842 out_error_free_peripherals:
844 (
unsigned short *)pdev->
dev.platform_data);
847 bfin_sport_uart_ports[pdev->
id] =
NULL;
864 (
unsigned short *)pdev->
dev.platform_data);
866 bfin_sport_uart_ports[pdev->
id] =
NULL;
873 .probe = sport_uart_probe,
878 .pm = &bfin_sport_uart_dev_pm_ops,
883 #ifdef CONFIG_SERIAL_BFIN_SPORT_CONSOLE
886 .pdrv = &sport_uart_driver,
890 static int __init sport_uart_rs_console_init(
void)
904 static int __init sport_uart_init(
void)
908 pr_info(
"Blackfin uart over sport driver\n");
912 pr_err(
"failed to register %s:%d\n",
919 pr_err(
"failed to register sport uart driver:%d\n", ret);
927 static void __exit sport_uart_exit(
void)