aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/serial/bfin_5xx.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/serial/bfin_5xx.c')
-rw-r--r--drivers/serial/bfin_5xx.c638
1 files changed, 384 insertions, 254 deletions
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
index 19cac9f610fd..e381b895b04d 100644
--- a/drivers/serial/bfin_5xx.c
+++ b/drivers/serial/bfin_5xx.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Blackfin On-Chip Serial Driver 2 * Blackfin On-Chip Serial Driver
3 * 3 *
4 * Copyright 2006-2008 Analog Devices Inc. 4 * Copyright 2006-2010 Analog Devices Inc.
5 * 5 *
6 * Enter bugs at http://blackfin.uclinux.org/ 6 * Enter bugs at http://blackfin.uclinux.org/
7 * 7 *
@@ -12,6 +12,9 @@
12#define SUPPORT_SYSRQ 12#define SUPPORT_SYSRQ
13#endif 13#endif
14 14
15#define DRIVER_NAME "bfin-uart"
16#define pr_fmt(fmt) DRIVER_NAME ": " fmt
17
15#include <linux/module.h> 18#include <linux/module.h>
16#include <linux/ioport.h> 19#include <linux/ioport.h>
17#include <linux/gfp.h> 20#include <linux/gfp.h>
@@ -23,21 +26,20 @@
23#include <linux/tty.h> 26#include <linux/tty.h>
24#include <linux/tty_flip.h> 27#include <linux/tty_flip.h>
25#include <linux/serial_core.h> 28#include <linux/serial_core.h>
26#include <linux/dma-mapping.h> 29#include <linux/gpio.h>
27 30#include <linux/irq.h>
28#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
29 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
30#include <linux/kgdb.h> 31#include <linux/kgdb.h>
31#include <asm/irq_regs.h> 32#include <linux/slab.h>
32#endif 33#include <linux/dma-mapping.h>
33
34#include <asm/gpio.h>
35#include <mach/bfin_serial_5xx.h>
36 34
37#include <asm/dma.h> 35#include <asm/portmux.h>
38#include <asm/io.h>
39#include <asm/irq.h>
40#include <asm/cacheflush.h> 36#include <asm/cacheflush.h>
37#include <asm/dma.h>
38
39#define port_membase(uart) (((struct bfin_serial_port *)(uart))->port.membase)
40#define get_lsr_cache(uart) (((struct bfin_serial_port *)(uart))->lsr)
41#define put_lsr_cache(uart, v) (((struct bfin_serial_port *)(uart))->lsr = (v))
42#include <asm/bfin_serial.h>
41 43
42#ifdef CONFIG_SERIAL_BFIN_MODULE 44#ifdef CONFIG_SERIAL_BFIN_MODULE
43# undef CONFIG_EARLY_PRINTK 45# undef CONFIG_EARLY_PRINTK
@@ -48,12 +50,11 @@
48#endif 50#endif
49 51
50/* UART name and device definitions */ 52/* UART name and device definitions */
51#define BFIN_SERIAL_NAME "ttyBF" 53#define BFIN_SERIAL_DEV_NAME "ttyBF"
52#define BFIN_SERIAL_MAJOR 204 54#define BFIN_SERIAL_MAJOR 204
53#define BFIN_SERIAL_MINOR 64 55#define BFIN_SERIAL_MINOR 64
54 56
55static struct bfin_serial_port bfin_serial_ports[BFIN_UART_NR_PORTS]; 57static struct bfin_serial_port *bfin_serial_ports[BFIN_UART_NR_PORTS];
56static int nr_active_ports = ARRAY_SIZE(bfin_serial_resource);
57 58
58#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \ 59#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
59 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE) 60 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
@@ -743,14 +744,14 @@ static int bfin_serial_startup(struct uart_port *port)
743 } 744 }
744 } 745 }
745 if (uart->rts_pin >= 0) { 746 if (uart->rts_pin >= 0) {
746 gpio_request(uart->rts_pin, DRIVER_NAME);
747 gpio_direction_output(uart->rts_pin, 0); 747 gpio_direction_output(uart->rts_pin, 0);
748 } 748 }
749#endif 749#endif
750#ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS 750#ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
751 if (request_irq(uart->status_irq, 751 if (uart->cts_pin >= 0 && request_irq(uart->status_irq,
752 bfin_serial_mctrl_cts_int, 752 bfin_serial_mctrl_cts_int,
753 IRQF_DISABLED, "BFIN_UART_MODEM_STATUS", uart)) { 753 IRQF_DISABLED, "BFIN_UART_MODEM_STATUS", uart)) {
754 uart->cts_pin = -1;
754 pr_info("Unable to attach BlackFin UART Modem Status interrupt.\n"); 755 pr_info("Unable to attach BlackFin UART Modem Status interrupt.\n");
755 } 756 }
756 757
@@ -796,11 +797,9 @@ static void bfin_serial_shutdown(struct uart_port *port)
796#ifdef CONFIG_SERIAL_BFIN_CTSRTS 797#ifdef CONFIG_SERIAL_BFIN_CTSRTS
797 if (uart->cts_pin >= 0) 798 if (uart->cts_pin >= 0)
798 free_irq(gpio_to_irq(uart->cts_pin), uart); 799 free_irq(gpio_to_irq(uart->cts_pin), uart);
799 if (uart->rts_pin >= 0)
800 gpio_free(uart->rts_pin);
801#endif 800#endif
802#ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS 801#ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
803 if (UART_GET_IER(uart) & EDSSI) 802 if (uart->cts_pin >= 0)
804 free_irq(uart->status_irq, uart); 803 free_irq(uart->status_irq, uart);
805#endif 804#endif
806} 805}
@@ -962,33 +961,33 @@ bfin_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
962 */ 961 */
963static void bfin_serial_set_ldisc(struct uart_port *port, int ld) 962static void bfin_serial_set_ldisc(struct uart_port *port, int ld)
964{ 963{
965 int line = port->line; 964 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
966 unsigned short val; 965 unsigned short val;
967 966
968 switch (ld) { 967 switch (ld) {
969 case N_IRDA: 968 case N_IRDA:
970 val = UART_GET_GCTL(&bfin_serial_ports[line]); 969 val = UART_GET_GCTL(uart);
971 val |= (IREN | RPOLC); 970 val |= (IREN | RPOLC);
972 UART_PUT_GCTL(&bfin_serial_ports[line], val); 971 UART_PUT_GCTL(uart, val);
973 break; 972 break;
974 default: 973 default:
975 val = UART_GET_GCTL(&bfin_serial_ports[line]); 974 val = UART_GET_GCTL(uart);
976 val &= ~(IREN | RPOLC); 975 val &= ~(IREN | RPOLC);
977 UART_PUT_GCTL(&bfin_serial_ports[line], val); 976 UART_PUT_GCTL(uart, val);
978 } 977 }
979} 978}
980 979
981static void bfin_serial_reset_irda(struct uart_port *port) 980static void bfin_serial_reset_irda(struct uart_port *port)
982{ 981{
983 int line = port->line; 982 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
984 unsigned short val; 983 unsigned short val;
985 984
986 val = UART_GET_GCTL(&bfin_serial_ports[line]); 985 val = UART_GET_GCTL(uart);
987 val &= ~(IREN | RPOLC); 986 val &= ~(IREN | RPOLC);
988 UART_PUT_GCTL(&bfin_serial_ports[line], val); 987 UART_PUT_GCTL(uart, val);
989 SSYNC(); 988 SSYNC();
990 val |= (IREN | RPOLC); 989 val |= (IREN | RPOLC);
991 UART_PUT_GCTL(&bfin_serial_ports[line], val); 990 UART_PUT_GCTL(uart, val);
992 SSYNC(); 991 SSYNC();
993} 992}
994 993
@@ -1070,85 +1069,6 @@ static struct uart_ops bfin_serial_pops = {
1070#endif 1069#endif
1071}; 1070};
1072 1071
1073static void __init bfin_serial_hw_init(void)
1074{
1075#ifdef CONFIG_SERIAL_BFIN_UART0
1076 peripheral_request(P_UART0_TX, DRIVER_NAME);
1077 peripheral_request(P_UART0_RX, DRIVER_NAME);
1078#endif
1079
1080#ifdef CONFIG_SERIAL_BFIN_UART1
1081 peripheral_request(P_UART1_TX, DRIVER_NAME);
1082 peripheral_request(P_UART1_RX, DRIVER_NAME);
1083
1084# if defined(CONFIG_BFIN_UART1_CTSRTS) && defined(CONFIG_BF54x)
1085 peripheral_request(P_UART1_RTS, DRIVER_NAME);
1086 peripheral_request(P_UART1_CTS, DRIVER_NAME);
1087# endif
1088#endif
1089
1090#ifdef CONFIG_SERIAL_BFIN_UART2
1091 peripheral_request(P_UART2_TX, DRIVER_NAME);
1092 peripheral_request(P_UART2_RX, DRIVER_NAME);
1093#endif
1094
1095#ifdef CONFIG_SERIAL_BFIN_UART3
1096 peripheral_request(P_UART3_TX, DRIVER_NAME);
1097 peripheral_request(P_UART3_RX, DRIVER_NAME);
1098
1099# if defined(CONFIG_BFIN_UART3_CTSRTS) && defined(CONFIG_BF54x)
1100 peripheral_request(P_UART3_RTS, DRIVER_NAME);
1101 peripheral_request(P_UART3_CTS, DRIVER_NAME);
1102# endif
1103#endif
1104}
1105
1106static void __init bfin_serial_init_ports(void)
1107{
1108 static int first = 1;
1109 int i;
1110
1111 if (!first)
1112 return;
1113 first = 0;
1114
1115 bfin_serial_hw_init();
1116
1117 for (i = 0; i < nr_active_ports; i++) {
1118 spin_lock_init(&bfin_serial_ports[i].port.lock);
1119 bfin_serial_ports[i].port.uartclk = get_sclk();
1120 bfin_serial_ports[i].port.fifosize = BFIN_UART_TX_FIFO_SIZE;
1121 bfin_serial_ports[i].port.ops = &bfin_serial_pops;
1122 bfin_serial_ports[i].port.line = i;
1123 bfin_serial_ports[i].port.iotype = UPIO_MEM;
1124 bfin_serial_ports[i].port.membase =
1125 (void __iomem *)bfin_serial_resource[i].uart_base_addr;
1126 bfin_serial_ports[i].port.mapbase =
1127 bfin_serial_resource[i].uart_base_addr;
1128 bfin_serial_ports[i].port.irq =
1129 bfin_serial_resource[i].uart_irq;
1130 bfin_serial_ports[i].status_irq =
1131 bfin_serial_resource[i].uart_status_irq;
1132 bfin_serial_ports[i].port.flags = UPF_BOOT_AUTOCONF;
1133#ifdef CONFIG_SERIAL_BFIN_DMA
1134 bfin_serial_ports[i].tx_done = 1;
1135 bfin_serial_ports[i].tx_count = 0;
1136 bfin_serial_ports[i].tx_dma_channel =
1137 bfin_serial_resource[i].uart_tx_dma_channel;
1138 bfin_serial_ports[i].rx_dma_channel =
1139 bfin_serial_resource[i].uart_rx_dma_channel;
1140 init_timer(&(bfin_serial_ports[i].rx_dma_timer));
1141#endif
1142#if defined(CONFIG_SERIAL_BFIN_CTSRTS) || \
1143 defined(CONFIG_SERIAL_BFIN_HARD_CTSRTS)
1144 bfin_serial_ports[i].cts_pin =
1145 bfin_serial_resource[i].uart_cts_pin;
1146 bfin_serial_ports[i].rts_pin =
1147 bfin_serial_resource[i].uart_rts_pin;
1148#endif
1149 }
1150}
1151
1152#if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK) 1072#if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
1153/* 1073/*
1154 * If the port was already initialised (eg, by a boot loader), 1074 * If the port was already initialised (eg, by a boot loader),
@@ -1196,6 +1116,34 @@ bfin_serial_console_get_options(struct bfin_serial_port *uart, int *baud,
1196 1116
1197static struct uart_driver bfin_serial_reg; 1117static struct uart_driver bfin_serial_reg;
1198 1118
1119static void bfin_serial_console_putchar(struct uart_port *port, int ch)
1120{
1121 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
1122 while (!(UART_GET_LSR(uart) & THRE))
1123 barrier();
1124 UART_PUT_CHAR(uart, ch);
1125}
1126
1127#endif /* defined (CONFIG_SERIAL_BFIN_CONSOLE) ||
1128 defined (CONFIG_EARLY_PRINTK) */
1129
1130#ifdef CONFIG_SERIAL_BFIN_CONSOLE
1131#define CLASS_BFIN_CONSOLE "bfin-console"
1132/*
1133 * Interrupts are disabled on entering
1134 */
1135static void
1136bfin_serial_console_write(struct console *co, const char *s, unsigned int count)
1137{
1138 struct bfin_serial_port *uart = bfin_serial_ports[co->index];
1139 unsigned long flags;
1140
1141 spin_lock_irqsave(&uart->port.lock, flags);
1142 uart_console_write(&uart->port, s, count, bfin_serial_console_putchar);
1143 spin_unlock_irqrestore(&uart->port.lock, flags);
1144
1145}
1146
1199static int __init 1147static int __init
1200bfin_serial_console_setup(struct console *co, char *options) 1148bfin_serial_console_setup(struct console *co, char *options)
1201{ 1149{
@@ -1215,9 +1163,12 @@ bfin_serial_console_setup(struct console *co, char *options)
1215 * if so, search for the first available port that does have 1163 * if so, search for the first available port that does have
1216 * console support. 1164 * console support.
1217 */ 1165 */
1218 if (co->index == -1 || co->index >= nr_active_ports) 1166 if (co->index < 0 || co->index >= BFIN_UART_NR_PORTS)
1219 co->index = 0; 1167 return -ENODEV;
1220 uart = &bfin_serial_ports[co->index]; 1168
1169 uart = bfin_serial_ports[co->index];
1170 if (!uart)
1171 return -ENODEV;
1221 1172
1222 if (options) 1173 if (options)
1223 uart_parse_options(options, &baud, &parity, &bits, &flow); 1174 uart_parse_options(options, &baud, &parity, &bits, &flow);
@@ -1226,36 +1177,9 @@ bfin_serial_console_setup(struct console *co, char *options)
1226 1177
1227 return uart_set_options(&uart->port, co, baud, parity, bits, flow); 1178 return uart_set_options(&uart->port, co, baud, parity, bits, flow);
1228} 1179}
1229#endif /* defined (CONFIG_SERIAL_BFIN_CONSOLE) ||
1230 defined (CONFIG_EARLY_PRINTK) */
1231
1232#ifdef CONFIG_SERIAL_BFIN_CONSOLE
1233static void bfin_serial_console_putchar(struct uart_port *port, int ch)
1234{
1235 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
1236 while (!(UART_GET_LSR(uart) & THRE))
1237 barrier();
1238 UART_PUT_CHAR(uart, ch);
1239 SSYNC();
1240}
1241
1242/*
1243 * Interrupts are disabled on entering
1244 */
1245static void
1246bfin_serial_console_write(struct console *co, const char *s, unsigned int count)
1247{
1248 struct bfin_serial_port *uart = &bfin_serial_ports[co->index];
1249 unsigned long flags;
1250
1251 spin_lock_irqsave(&uart->port.lock, flags);
1252 uart_console_write(&uart->port, s, count, bfin_serial_console_putchar);
1253 spin_unlock_irqrestore(&uart->port.lock, flags);
1254
1255}
1256 1180
1257static struct console bfin_serial_console = { 1181static struct console bfin_serial_console = {
1258 .name = BFIN_SERIAL_NAME, 1182 .name = BFIN_SERIAL_DEV_NAME,
1259 .write = bfin_serial_console_write, 1183 .write = bfin_serial_console_write,
1260 .device = uart_console_device, 1184 .device = uart_console_device,
1261 .setup = bfin_serial_console_setup, 1185 .setup = bfin_serial_console_setup,
@@ -1263,44 +1187,30 @@ static struct console bfin_serial_console = {
1263 .index = -1, 1187 .index = -1,
1264 .data = &bfin_serial_reg, 1188 .data = &bfin_serial_reg,
1265}; 1189};
1266
1267static int __init bfin_serial_rs_console_init(void)
1268{
1269 bfin_serial_init_ports();
1270 register_console(&bfin_serial_console);
1271
1272 return 0;
1273}
1274console_initcall(bfin_serial_rs_console_init);
1275
1276#define BFIN_SERIAL_CONSOLE &bfin_serial_console 1190#define BFIN_SERIAL_CONSOLE &bfin_serial_console
1277#else 1191#else
1278#define BFIN_SERIAL_CONSOLE NULL 1192#define BFIN_SERIAL_CONSOLE NULL
1279#endif /* CONFIG_SERIAL_BFIN_CONSOLE */ 1193#endif /* CONFIG_SERIAL_BFIN_CONSOLE */
1280 1194
1195#ifdef CONFIG_EARLY_PRINTK
1196static struct bfin_serial_port bfin_earlyprintk_port;
1197#define CLASS_BFIN_EARLYPRINTK "bfin-earlyprintk"
1281 1198
1282#ifdef CONFIG_EARLY_PRINTK 1199/*
1283static __init void early_serial_putc(struct uart_port *port, int ch) 1200 * Interrupts are disabled on entering
1201 */
1202static void
1203bfin_earlyprintk_console_write(struct console *co, const char *s, unsigned int count)
1284{ 1204{
1285 unsigned timeout = 0xffff; 1205 unsigned long flags;
1286 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
1287
1288 while ((!(UART_GET_LSR(uart) & THRE)) && --timeout)
1289 cpu_relax();
1290 UART_PUT_CHAR(uart, ch);
1291}
1292 1206
1293static __init void early_serial_write(struct console *con, const char *s, 1207 if (bfin_earlyprintk_port.port.line != co->index)
1294 unsigned int n) 1208 return;
1295{
1296 struct bfin_serial_port *uart = &bfin_serial_ports[con->index];
1297 unsigned int i;
1298 1209
1299 for (i = 0; i < n; i++, s++) { 1210 spin_lock_irqsave(&bfin_earlyprintk_port.port.lock, flags);
1300 if (*s == '\n') 1211 uart_console_write(&bfin_earlyprintk_port.port, s, count,
1301 early_serial_putc(&uart->port, '\r'); 1212 bfin_serial_console_putchar);
1302 early_serial_putc(&uart->port, *s); 1213 spin_unlock_irqrestore(&bfin_earlyprintk_port.port.lock, flags);
1303 }
1304} 1214}
1305 1215
1306/* 1216/*
@@ -1311,113 +1221,204 @@ static __init void early_serial_write(struct console *con, const char *s,
1311 */ 1221 */
1312static struct __initdata console bfin_early_serial_console = { 1222static struct __initdata console bfin_early_serial_console = {
1313 .name = "early_BFuart", 1223 .name = "early_BFuart",
1314 .write = early_serial_write, 1224 .write = bfin_earlyprintk_console_write,
1315 .device = uart_console_device, 1225 .device = uart_console_device,
1316 .flags = CON_PRINTBUFFER, 1226 .flags = CON_PRINTBUFFER,
1317 .index = -1, 1227 .index = -1,
1318 .data = &bfin_serial_reg, 1228 .data = &bfin_serial_reg,
1319}; 1229};
1320
1321struct console __init *bfin_earlyserial_init(unsigned int port,
1322 unsigned int cflag)
1323{
1324 struct bfin_serial_port *uart;
1325 struct ktermios t;
1326
1327#ifdef CONFIG_SERIAL_BFIN_CONSOLE
1328 /*
1329 * If we are using early serial, don't let the normal console rewind
1330 * log buffer, since that causes things to be printed multiple times
1331 */
1332 bfin_serial_console.flags &= ~CON_PRINTBUFFER;
1333#endif 1230#endif
1334 1231
1335 if (port == -1 || port >= nr_active_ports)
1336 port = 0;
1337 bfin_serial_init_ports();
1338 bfin_early_serial_console.index = port;
1339 uart = &bfin_serial_ports[port];
1340 t.c_cflag = cflag;
1341 t.c_iflag = 0;
1342 t.c_oflag = 0;
1343 t.c_lflag = ICANON;
1344 t.c_line = port;
1345 bfin_serial_set_termios(&uart->port, &t, &t);
1346 return &bfin_early_serial_console;
1347}
1348
1349#endif /* CONFIG_EARLY_PRINTK */
1350
1351static struct uart_driver bfin_serial_reg = { 1232static struct uart_driver bfin_serial_reg = {
1352 .owner = THIS_MODULE, 1233 .owner = THIS_MODULE,
1353 .driver_name = "bfin-uart", 1234 .driver_name = DRIVER_NAME,
1354 .dev_name = BFIN_SERIAL_NAME, 1235 .dev_name = BFIN_SERIAL_DEV_NAME,
1355 .major = BFIN_SERIAL_MAJOR, 1236 .major = BFIN_SERIAL_MAJOR,
1356 .minor = BFIN_SERIAL_MINOR, 1237 .minor = BFIN_SERIAL_MINOR,
1357 .nr = BFIN_UART_NR_PORTS, 1238 .nr = BFIN_UART_NR_PORTS,
1358 .cons = BFIN_SERIAL_CONSOLE, 1239 .cons = BFIN_SERIAL_CONSOLE,
1359}; 1240};
1360 1241
1361static int bfin_serial_suspend(struct platform_device *dev, pm_message_t state) 1242static int bfin_serial_suspend(struct platform_device *pdev, pm_message_t state)
1362{ 1243{
1363 int i; 1244 struct bfin_serial_port *uart = platform_get_drvdata(pdev);
1364 1245
1365 for (i = 0; i < nr_active_ports; i++) { 1246 return uart_suspend_port(&bfin_serial_reg, &uart->port);
1366 if (bfin_serial_ports[i].port.dev != &dev->dev) 1247}
1367 continue;
1368 uart_suspend_port(&bfin_serial_reg, &bfin_serial_ports[i].port);
1369 }
1370 1248
1371 return 0; 1249static int bfin_serial_resume(struct platform_device *pdev)
1250{
1251 struct bfin_serial_port *uart = platform_get_drvdata(pdev);
1252
1253 return uart_resume_port(&bfin_serial_reg, &uart->port);
1372} 1254}
1373 1255
1374static int bfin_serial_resume(struct platform_device *dev) 1256static int bfin_serial_probe(struct platform_device *pdev)
1375{ 1257{
1376 int i; 1258 struct resource *res;
1259 struct bfin_serial_port *uart = NULL;
1260 int ret = 0;
1377 1261
1378 for (i = 0; i < nr_active_ports; i++) { 1262 if (pdev->id < 0 || pdev->id >= BFIN_UART_NR_PORTS) {
1379 if (bfin_serial_ports[i].port.dev != &dev->dev) 1263 dev_err(&pdev->dev, "Wrong bfin uart platform device id.\n");
1380 continue; 1264 return -ENOENT;
1381 uart_resume_port(&bfin_serial_reg, &bfin_serial_ports[i].port);
1382 } 1265 }
1383 1266
1384 return 0; 1267 if (bfin_serial_ports[pdev->id] == NULL) {
1385}
1386 1268
1387static int bfin_serial_probe(struct platform_device *dev) 1269 uart = kzalloc(sizeof(*uart), GFP_KERNEL);
1388{ 1270 if (!uart) {
1389 struct resource *res = dev->resource; 1271 dev_err(&pdev->dev,
1390 int i; 1272 "fail to malloc bfin_serial_port\n");
1273 return -ENOMEM;
1274 }
1275 bfin_serial_ports[pdev->id] = uart;
1391 1276
1392 for (i = 0; i < dev->num_resources; i++, res++) 1277#ifdef CONFIG_EARLY_PRINTK
1393 if (res->flags & IORESOURCE_MEM) 1278 if (!(bfin_earlyprintk_port.port.membase
1394 break; 1279 && bfin_earlyprintk_port.port.line == pdev->id)) {
1280 /*
1281 * If the peripheral PINs of current port is allocated
1282 * in earlyprintk probe stage, don't do it again.
1283 */
1284#endif
1285 ret = peripheral_request_list(
1286 (unsigned short *)pdev->dev.platform_data, DRIVER_NAME);
1287 if (ret) {
1288 dev_err(&pdev->dev,
1289 "fail to request bfin serial peripherals\n");
1290 goto out_error_free_mem;
1291 }
1292#ifdef CONFIG_EARLY_PRINTK
1293 }
1294#endif
1295
1296 spin_lock_init(&uart->port.lock);
1297 uart->port.uartclk = get_sclk();
1298 uart->port.fifosize = BFIN_UART_TX_FIFO_SIZE;
1299 uart->port.ops = &bfin_serial_pops;
1300 uart->port.line = pdev->id;
1301 uart->port.iotype = UPIO_MEM;
1302 uart->port.flags = UPF_BOOT_AUTOCONF;
1303
1304 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1305 if (res == NULL) {
1306 dev_err(&pdev->dev, "Cannot get IORESOURCE_MEM\n");
1307 ret = -ENOENT;
1308 goto out_error_free_peripherals;
1309 }
1310
1311 uart->port.membase = ioremap(res->start,
1312 res->end - res->start);
1313 if (!uart->port.membase) {
1314 dev_err(&pdev->dev, "Cannot map uart IO\n");
1315 ret = -ENXIO;
1316 goto out_error_free_peripherals;
1317 }
1318 uart->port.mapbase = res->start;
1395 1319
1396 if (i < dev->num_resources) { 1320 uart->port.irq = platform_get_irq(pdev, 0);
1397 for (i = 0; i < nr_active_ports; i++, res++) { 1321 if (uart->port.irq < 0) {
1398 if (bfin_serial_ports[i].port.mapbase != res->start) 1322 dev_err(&pdev->dev, "No uart RX/TX IRQ specified\n");
1399 continue; 1323 ret = -ENOENT;
1400 bfin_serial_ports[i].port.dev = &dev->dev; 1324 goto out_error_unmap;
1401 uart_add_one_port(&bfin_serial_reg, &bfin_serial_ports[i].port);
1402 } 1325 }
1326
1327 uart->status_irq = platform_get_irq(pdev, 1);
1328 if (uart->status_irq < 0) {
1329 dev_err(&pdev->dev, "No uart status IRQ specified\n");
1330 ret = -ENOENT;
1331 goto out_error_unmap;
1332 }
1333
1334#ifdef CONFIG_SERIAL_BFIN_DMA
1335 uart->tx_done = 1;
1336 uart->tx_count = 0;
1337
1338 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1339 if (res == NULL) {
1340 dev_err(&pdev->dev, "No uart TX DMA channel specified\n");
1341 ret = -ENOENT;
1342 goto out_error_unmap;
1343 }
1344 uart->tx_dma_channel = res->start;
1345
1346 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
1347 if (res == NULL) {
1348 dev_err(&pdev->dev, "No uart RX DMA channel specified\n");
1349 ret = -ENOENT;
1350 goto out_error_unmap;
1351 }
1352 uart->rx_dma_channel = res->start;
1353
1354 init_timer(&(uart->rx_dma_timer));
1355#endif
1356
1357#if defined(CONFIG_SERIAL_BFIN_CTSRTS) || \
1358 defined(CONFIG_SERIAL_BFIN_HARD_CTSRTS)
1359 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1360 if (res == NULL)
1361 uart->cts_pin = -1;
1362 else
1363 uart->cts_pin = res->start;
1364
1365 res = platform_get_resource(pdev, IORESOURCE_IO, 1);
1366 if (res == NULL)
1367 uart->rts_pin = -1;
1368 else
1369 uart->rts_pin = res->start;
1370# if defined(CONFIG_SERIAL_BFIN_CTSRTS)
1371 if (uart->rts_pin >= 0)
1372 gpio_request(uart->rts_pin, DRIVER_NAME);
1373# endif
1374#endif
1403 } 1375 }
1404 1376
1405 return 0; 1377#ifdef CONFIG_SERIAL_BFIN_CONSOLE
1378 if (!is_early_platform_device(pdev)) {
1379#endif
1380 uart = bfin_serial_ports[pdev->id];
1381 uart->port.dev = &pdev->dev;
1382 dev_set_drvdata(&pdev->dev, uart);
1383 ret = uart_add_one_port(&bfin_serial_reg, &uart->port);
1384#ifdef CONFIG_SERIAL_BFIN_CONSOLE
1385 }
1386#endif
1387
1388 if (!ret)
1389 return 0;
1390
1391 if (uart) {
1392out_error_unmap:
1393 iounmap(uart->port.membase);
1394out_error_free_peripherals:
1395 peripheral_free_list(
1396 (unsigned short *)pdev->dev.platform_data);
1397out_error_free_mem:
1398 kfree(uart);
1399 bfin_serial_ports[pdev->id] = NULL;
1400 }
1401
1402 return ret;
1406} 1403}
1407 1404
1408static int bfin_serial_remove(struct platform_device *dev) 1405static int __devexit bfin_serial_remove(struct platform_device *pdev)
1409{ 1406{
1410 int i; 1407 struct bfin_serial_port *uart = platform_get_drvdata(pdev);
1411 1408
1412 for (i = 0; i < nr_active_ports; i++) { 1409 dev_set_drvdata(&pdev->dev, NULL);
1413 if (bfin_serial_ports[i].port.dev != &dev->dev) 1410
1414 continue; 1411 if (uart) {
1415 uart_remove_one_port(&bfin_serial_reg, &bfin_serial_ports[i].port); 1412 uart_remove_one_port(&bfin_serial_reg, &uart->port);
1416 bfin_serial_ports[i].port.dev = NULL; 1413#ifdef CONFIG_SERIAL_BFIN_CTSRTS
1417#if defined(CONFIG_SERIAL_BFIN_CTSRTS) 1414 if (uart->rts_pin >= 0)
1418 gpio_free(bfin_serial_ports[i].cts_pin); 1415 gpio_free(uart->rts_pin);
1419 gpio_free(bfin_serial_ports[i].rts_pin);
1420#endif 1416#endif
1417 iounmap(uart->port.membase);
1418 peripheral_free_list(
1419 (unsigned short *)pdev->dev.platform_data);
1420 kfree(uart);
1421 bfin_serial_ports[pdev->id] = NULL;
1421 } 1422 }
1422 1423
1423 return 0; 1424 return 0;
@@ -1425,31 +1426,160 @@ static int bfin_serial_remove(struct platform_device *dev)
1425 1426
1426static struct platform_driver bfin_serial_driver = { 1427static struct platform_driver bfin_serial_driver = {
1427 .probe = bfin_serial_probe, 1428 .probe = bfin_serial_probe,
1428 .remove = bfin_serial_remove, 1429 .remove = __devexit_p(bfin_serial_remove),
1429 .suspend = bfin_serial_suspend, 1430 .suspend = bfin_serial_suspend,
1430 .resume = bfin_serial_resume, 1431 .resume = bfin_serial_resume,
1431 .driver = { 1432 .driver = {
1432 .name = "bfin-uart", 1433 .name = DRIVER_NAME,
1433 .owner = THIS_MODULE, 1434 .owner = THIS_MODULE,
1434 }, 1435 },
1435}; 1436};
1436 1437
1437static int __init bfin_serial_init(void) 1438#if defined(CONFIG_SERIAL_BFIN_CONSOLE)
1439static __initdata struct early_platform_driver early_bfin_serial_driver = {
1440 .class_str = CLASS_BFIN_CONSOLE,
1441 .pdrv = &bfin_serial_driver,
1442 .requested_id = EARLY_PLATFORM_ID_UNSET,
1443};
1444
1445static int __init bfin_serial_rs_console_init(void)
1446{
1447 early_platform_driver_register(&early_bfin_serial_driver, DRIVER_NAME);
1448
1449 early_platform_driver_probe(CLASS_BFIN_CONSOLE, BFIN_UART_NR_PORTS, 0);
1450
1451 register_console(&bfin_serial_console);
1452
1453 return 0;
1454}
1455console_initcall(bfin_serial_rs_console_init);
1456#endif
1457
1458#ifdef CONFIG_EARLY_PRINTK
1459/*
1460 * Memory can't be allocated dynamically during earlyprink init stage.
1461 * So, do individual probe for earlyprink with a static uart port variable.
1462 */
1463static int bfin_earlyprintk_probe(struct platform_device *pdev)
1438{ 1464{
1465 struct resource *res;
1439 int ret; 1466 int ret;
1440 1467
1441 pr_info("Serial: Blackfin serial driver\n"); 1468 if (pdev->id < 0 || pdev->id >= BFIN_UART_NR_PORTS) {
1469 dev_err(&pdev->dev, "Wrong earlyprintk platform device id.\n");
1470 return -ENOENT;
1471 }
1472
1473 ret = peripheral_request_list(
1474 (unsigned short *)pdev->dev.platform_data, DRIVER_NAME);
1475 if (ret) {
1476 dev_err(&pdev->dev,
1477 "fail to request bfin serial peripherals\n");
1478 return ret;
1479 }
1480
1481 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1482 if (res == NULL) {
1483 dev_err(&pdev->dev, "Cannot get IORESOURCE_MEM\n");
1484 ret = -ENOENT;
1485 goto out_error_free_peripherals;
1486 }
1487
1488 bfin_earlyprintk_port.port.membase = ioremap(res->start,
1489 res->end - res->start);
1490 if (!bfin_earlyprintk_port.port.membase) {
1491 dev_err(&pdev->dev, "Cannot map uart IO\n");
1492 ret = -ENXIO;
1493 goto out_error_free_peripherals;
1494 }
1495 bfin_earlyprintk_port.port.mapbase = res->start;
1496 bfin_earlyprintk_port.port.line = pdev->id;
1497 bfin_earlyprintk_port.port.uartclk = get_sclk();
1498 bfin_earlyprintk_port.port.fifosize = BFIN_UART_TX_FIFO_SIZE;
1499 spin_lock_init(&bfin_earlyprintk_port.port.lock);
1500
1501 return 0;
1502
1503out_error_free_peripherals:
1504 peripheral_free_list(
1505 (unsigned short *)pdev->dev.platform_data);
1506
1507 return ret;
1508}
1509
1510static struct platform_driver bfin_earlyprintk_driver = {
1511 .probe = bfin_earlyprintk_probe,
1512 .driver = {
1513 .name = DRIVER_NAME,
1514 .owner = THIS_MODULE,
1515 },
1516};
1517
1518static __initdata struct early_platform_driver early_bfin_earlyprintk_driver = {
1519 .class_str = CLASS_BFIN_EARLYPRINTK,
1520 .pdrv = &bfin_earlyprintk_driver,
1521 .requested_id = EARLY_PLATFORM_ID_UNSET,
1522};
1523
1524struct console __init *bfin_earlyserial_init(unsigned int port,
1525 unsigned int cflag)
1526{
1527 struct ktermios t;
1528 char port_name[20];
1442 1529
1443 bfin_serial_init_ports(); 1530 if (port < 0 || port >= BFIN_UART_NR_PORTS)
1531 return NULL;
1532
1533 /*
1534 * Only probe resource of the given port in earlyprintk boot arg.
1535 * The expected port id should be indicated in port name string.
1536 */
1537 snprintf(port_name, 20, DRIVER_NAME ".%d", port);
1538 early_platform_driver_register(&early_bfin_earlyprintk_driver,
1539 port_name);
1540 early_platform_driver_probe(CLASS_BFIN_EARLYPRINTK, 1, 0);
1541
1542 if (!bfin_earlyprintk_port.port.membase)
1543 return NULL;
1544
1545#ifdef CONFIG_SERIAL_BFIN_CONSOLE
1546 /*
1547 * If we are using early serial, don't let the normal console rewind
1548 * log buffer, since that causes things to be printed multiple times
1549 */
1550 bfin_serial_console.flags &= ~CON_PRINTBUFFER;
1551#endif
1552
1553 bfin_early_serial_console.index = port;
1554 t.c_cflag = cflag;
1555 t.c_iflag = 0;
1556 t.c_oflag = 0;
1557 t.c_lflag = ICANON;
1558 t.c_line = port;
1559 bfin_serial_set_termios(&bfin_earlyprintk_port.port, &t, &t);
1560
1561 return &bfin_early_serial_console;
1562}
1563#endif /* CONFIG_EARLY_PRINTK */
1564
1565static int __init bfin_serial_init(void)
1566{
1567 int ret;
1568
1569 pr_info("Blackfin serial driver\n");
1444 1570
1445 ret = uart_register_driver(&bfin_serial_reg); 1571 ret = uart_register_driver(&bfin_serial_reg);
1446 if (ret == 0) { 1572 if (ret) {
1447 ret = platform_driver_register(&bfin_serial_driver); 1573 pr_err("failed to register %s:%d\n",
1448 if (ret) { 1574 bfin_serial_reg.driver_name, ret);
1449 pr_debug("uart register failed\n"); 1575 }
1450 uart_unregister_driver(&bfin_serial_reg); 1576
1451 } 1577 ret = platform_driver_register(&bfin_serial_driver);
1578 if (ret) {
1579 pr_err("fail to register bfin uart\n");
1580 uart_unregister_driver(&bfin_serial_reg);
1452 } 1581 }
1582
1453 return ret; 1583 return ret;
1454} 1584}
1455 1585
@@ -1463,7 +1593,7 @@ static void __exit bfin_serial_exit(void)
1463module_init(bfin_serial_init); 1593module_init(bfin_serial_init);
1464module_exit(bfin_serial_exit); 1594module_exit(bfin_serial_exit);
1465 1595
1466MODULE_AUTHOR("Aubrey.Li <aubrey.li@analog.com>"); 1596MODULE_AUTHOR("Sonic Zhang, Aubrey Li");
1467MODULE_DESCRIPTION("Blackfin generic serial port driver"); 1597MODULE_DESCRIPTION("Blackfin generic serial port driver");
1468MODULE_LICENSE("GPL"); 1598MODULE_LICENSE("GPL");
1469MODULE_ALIAS_CHARDEV_MAJOR(BFIN_SERIAL_MAJOR); 1599MODULE_ALIAS_CHARDEV_MAJOR(BFIN_SERIAL_MAJOR);