aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/serial/mpc52xx_uart.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/serial/mpc52xx_uart.c')
-rw-r--r--drivers/serial/mpc52xx_uart.c284
1 files changed, 236 insertions, 48 deletions
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 7ce9e9f567a3..02469c31bf0b 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -29,39 +29,6 @@
29 * kind, whether express or implied. 29 * kind, whether express or implied.
30 */ 30 */
31 31
32/* Platform device Usage :
33 *
34 * Since PSCs can have multiple function, the correct driver for each one
35 * is selected by calling mpc52xx_match_psc_function(...). The function
36 * handled by this driver is "uart".
37 *
38 * The driver init all necessary registers to place the PSC in uart mode without
39 * DCD. However, the pin multiplexing aren't changed and should be set either
40 * by the bootloader or in the platform init code.
41 *
42 * The idx field must be equal to the PSC index (e.g. 0 for PSC1, 1 for PSC2,
43 * and so on). So the PSC1 is mapped to /dev/ttyPSC0, PSC2 to /dev/ttyPSC1 and
44 * so on. But be warned, it's an ABSOLUTE REQUIREMENT ! This is needed mainly
45 * fpr the console code : without this 1:1 mapping, at early boot time, when we
46 * are parsing the kernel args console=ttyPSC?, we wouldn't know which PSC it
47 * will be mapped to.
48 */
49
50/* OF Platform device Usage :
51 *
52 * This driver is only used for PSCs configured in uart mode. The device
53 * tree will have a node for each PSC with "mpc52xx-psc-uart" in the compatible
54 * list.
55 *
56 * By default, PSC devices are enumerated in the order they are found. However
57 * a particular PSC number can be forces by adding 'device_no = <port#>'
58 * to the device node.
59 *
60 * The driver init all necessary registers to place the PSC in uart mode without
61 * DCD. However, the pin multiplexing aren't changed and should be set either
62 * by the bootloader or in the platform init code.
63 */
64
65#undef DEBUG 32#undef DEBUG
66 33
67#include <linux/device.h> 34#include <linux/device.h>
@@ -74,6 +41,7 @@
74#include <linux/io.h> 41#include <linux/io.h>
75#include <linux/of.h> 42#include <linux/of.h>
76#include <linux/of_platform.h> 43#include <linux/of_platform.h>
44#include <linux/clk.h>
77 45
78#include <asm/mpc52xx.h> 46#include <asm/mpc52xx.h>
79#include <asm/mpc52xx_psc.h> 47#include <asm/mpc52xx_psc.h>
@@ -113,6 +81,7 @@ static void mpc52xx_uart_of_enumerate(void);
113 81
114/* Forward declaration of the interruption handling routine */ 82/* Forward declaration of the interruption handling routine */
115static irqreturn_t mpc52xx_uart_int(int irq, void *dev_id); 83static irqreturn_t mpc52xx_uart_int(int irq, void *dev_id);
84static irqreturn_t mpc5xxx_uart_process_int(struct uart_port *port);
116 85
117 86
118/* Simple macro to test if a port is console or not. This one is taken 87/* Simple macro to test if a port is console or not. This one is taken
@@ -145,6 +114,11 @@ struct psc_ops {
145 void (*cw_disable_ints)(struct uart_port *port); 114 void (*cw_disable_ints)(struct uart_port *port);
146 void (*cw_restore_ints)(struct uart_port *port); 115 void (*cw_restore_ints)(struct uart_port *port);
147 unsigned long (*getuartclk)(void *p); 116 unsigned long (*getuartclk)(void *p);
117 int (*clock)(struct uart_port *port, int enable);
118 int (*fifoc_init)(void);
119 void (*fifoc_uninit)(void);
120 void (*get_irq)(struct uart_port *, struct device_node *);
121 irqreturn_t (*handle_irq)(struct uart_port *port);
148}; 122};
149 123
150#ifdef CONFIG_PPC_MPC52xx 124#ifdef CONFIG_PPC_MPC52xx
@@ -256,6 +230,18 @@ static unsigned long mpc52xx_getuartclk(void *p)
256 return mpc5xxx_get_bus_frequency(p) / 2; 230 return mpc5xxx_get_bus_frequency(p) / 2;
257} 231}
258 232
233static void mpc52xx_psc_get_irq(struct uart_port *port, struct device_node *np)
234{
235 port->irqflags = IRQF_DISABLED;
236 port->irq = irq_of_parse_and_map(np, 0);
237}
238
239/* 52xx specific interrupt handler. The caller holds the port lock */
240static irqreturn_t mpc52xx_psc_handle_irq(struct uart_port *port)
241{
242 return mpc5xxx_uart_process_int(port);
243}
244
259static struct psc_ops mpc52xx_psc_ops = { 245static struct psc_ops mpc52xx_psc_ops = {
260 .fifo_init = mpc52xx_psc_fifo_init, 246 .fifo_init = mpc52xx_psc_fifo_init,
261 .raw_rx_rdy = mpc52xx_psc_raw_rx_rdy, 247 .raw_rx_rdy = mpc52xx_psc_raw_rx_rdy,
@@ -273,14 +259,32 @@ static struct psc_ops mpc52xx_psc_ops = {
273 .cw_disable_ints = mpc52xx_psc_cw_disable_ints, 259 .cw_disable_ints = mpc52xx_psc_cw_disable_ints,
274 .cw_restore_ints = mpc52xx_psc_cw_restore_ints, 260 .cw_restore_ints = mpc52xx_psc_cw_restore_ints,
275 .getuartclk = mpc52xx_getuartclk, 261 .getuartclk = mpc52xx_getuartclk,
262 .get_irq = mpc52xx_psc_get_irq,
263 .handle_irq = mpc52xx_psc_handle_irq,
276}; 264};
277 265
278#endif /* CONFIG_MPC52xx */ 266#endif /* CONFIG_MPC52xx */
279 267
280#ifdef CONFIG_PPC_MPC512x 268#ifdef CONFIG_PPC_MPC512x
281#define FIFO_512x(port) ((struct mpc512x_psc_fifo __iomem *)(PSC(port)+1)) 269#define FIFO_512x(port) ((struct mpc512x_psc_fifo __iomem *)(PSC(port)+1))
270
271/* PSC FIFO Controller for mpc512x */
272struct psc_fifoc {
273 u32 fifoc_cmd;
274 u32 fifoc_int;
275 u32 fifoc_dma;
276 u32 fifoc_axe;
277 u32 fifoc_debug;
278};
279
280static struct psc_fifoc __iomem *psc_fifoc;
281static unsigned int psc_fifoc_irq;
282
282static void mpc512x_psc_fifo_init(struct uart_port *port) 283static void mpc512x_psc_fifo_init(struct uart_port *port)
283{ 284{
285 /* /32 prescaler */
286 out_be16(&PSC(port)->mpc52xx_psc_clock_select, 0xdd00);
287
284 out_be32(&FIFO_512x(port)->txcmd, MPC512x_PSC_FIFO_RESET_SLICE); 288 out_be32(&FIFO_512x(port)->txcmd, MPC512x_PSC_FIFO_RESET_SLICE);
285 out_be32(&FIFO_512x(port)->txcmd, MPC512x_PSC_FIFO_ENABLE_SLICE); 289 out_be32(&FIFO_512x(port)->txcmd, MPC512x_PSC_FIFO_ENABLE_SLICE);
286 out_be32(&FIFO_512x(port)->txalarm, 1); 290 out_be32(&FIFO_512x(port)->txalarm, 1);
@@ -393,6 +397,160 @@ static unsigned long mpc512x_getuartclk(void *p)
393 return mpc5xxx_get_bus_frequency(p); 397 return mpc5xxx_get_bus_frequency(p);
394} 398}
395 399
400#define DEFAULT_FIFO_SIZE 16
401
402static unsigned int __init get_fifo_size(struct device_node *np,
403 char *fifo_name)
404{
405 const unsigned int *fp;
406
407 fp = of_get_property(np, fifo_name, NULL);
408 if (fp)
409 return *fp;
410
411 pr_warning("no %s property in %s node, defaulting to %d\n",
412 fifo_name, np->full_name, DEFAULT_FIFO_SIZE);
413
414 return DEFAULT_FIFO_SIZE;
415}
416
417#define FIFOC(_base) ((struct mpc512x_psc_fifo __iomem *) \
418 ((u32)(_base) + sizeof(struct mpc52xx_psc)))
419
420/* Init PSC FIFO Controller */
421static int __init mpc512x_psc_fifoc_init(void)
422{
423 struct device_node *np;
424 void __iomem *psc;
425 unsigned int tx_fifo_size;
426 unsigned int rx_fifo_size;
427 int fifobase = 0; /* current fifo address in 32 bit words */
428
429 np = of_find_compatible_node(NULL, NULL,
430 "fsl,mpc5121-psc-fifo");
431 if (!np) {
432 pr_err("%s: Can't find FIFOC node\n", __func__);
433 return -ENODEV;
434 }
435
436 psc_fifoc = of_iomap(np, 0);
437 if (!psc_fifoc) {
438 pr_err("%s: Can't map FIFOC\n", __func__);
439 return -ENODEV;
440 }
441
442 psc_fifoc_irq = irq_of_parse_and_map(np, 0);
443 of_node_put(np);
444 if (psc_fifoc_irq == NO_IRQ) {
445 pr_err("%s: Can't get FIFOC irq\n", __func__);
446 iounmap(psc_fifoc);
447 return -ENODEV;
448 }
449
450 for_each_compatible_node(np, NULL, "fsl,mpc5121-psc-uart") {
451 tx_fifo_size = get_fifo_size(np, "fsl,tx-fifo-size");
452 rx_fifo_size = get_fifo_size(np, "fsl,rx-fifo-size");
453
454 /* size in register is in 4 byte units */
455 tx_fifo_size /= 4;
456 rx_fifo_size /= 4;
457 if (!tx_fifo_size)
458 tx_fifo_size = 1;
459 if (!rx_fifo_size)
460 rx_fifo_size = 1;
461
462 psc = of_iomap(np, 0);
463 if (!psc) {
464 pr_err("%s: Can't map %s device\n",
465 __func__, np->full_name);
466 continue;
467 }
468
469 /* FIFO space is 4KiB, check if requested size is available */
470 if ((fifobase + tx_fifo_size + rx_fifo_size) > 0x1000) {
471 pr_err("%s: no fifo space available for %s\n",
472 __func__, np->full_name);
473 iounmap(psc);
474 /*
475 * chances are that another device requests less
476 * fifo space, so we continue.
477 */
478 continue;
479 }
480 /* set tx and rx fifo size registers */
481 out_be32(&FIFOC(psc)->txsz, (fifobase << 16) | tx_fifo_size);
482 fifobase += tx_fifo_size;
483 out_be32(&FIFOC(psc)->rxsz, (fifobase << 16) | rx_fifo_size);
484 fifobase += rx_fifo_size;
485
486 /* reset and enable the slices */
487 out_be32(&FIFOC(psc)->txcmd, 0x80);
488 out_be32(&FIFOC(psc)->txcmd, 0x01);
489 out_be32(&FIFOC(psc)->rxcmd, 0x80);
490 out_be32(&FIFOC(psc)->rxcmd, 0x01);
491
492 iounmap(psc);
493 }
494
495 return 0;
496}
497
498static void __exit mpc512x_psc_fifoc_uninit(void)
499{
500 iounmap(psc_fifoc);
501}
502
503/* 512x specific interrupt handler. The caller holds the port lock */
504static irqreturn_t mpc512x_psc_handle_irq(struct uart_port *port)
505{
506 unsigned long fifoc_int;
507 int psc_num;
508
509 /* Read pending PSC FIFOC interrupts */
510 fifoc_int = in_be32(&psc_fifoc->fifoc_int);
511
512 /* Check if it is an interrupt for this port */
513 psc_num = (port->mapbase & 0xf00) >> 8;
514 if (test_bit(psc_num, &fifoc_int) ||
515 test_bit(psc_num + 16, &fifoc_int))
516 return mpc5xxx_uart_process_int(port);
517
518 return IRQ_NONE;
519}
520
521static int mpc512x_psc_clock(struct uart_port *port, int enable)
522{
523 struct clk *psc_clk;
524 int psc_num;
525 char clk_name[10];
526
527 if (uart_console(port))
528 return 0;
529
530 psc_num = (port->mapbase & 0xf00) >> 8;
531 snprintf(clk_name, sizeof(clk_name), "psc%d_clk", psc_num);
532 psc_clk = clk_get(port->dev, clk_name);
533 if (IS_ERR(psc_clk)) {
534 dev_err(port->dev, "Failed to get PSC clock entry!\n");
535 return -ENODEV;
536 }
537
538 dev_dbg(port->dev, "%s %sable\n", clk_name, enable ? "en" : "dis");
539
540 if (enable)
541 clk_enable(psc_clk);
542 else
543 clk_disable(psc_clk);
544
545 return 0;
546}
547
548static void mpc512x_psc_get_irq(struct uart_port *port, struct device_node *np)
549{
550 port->irqflags = IRQF_SHARED;
551 port->irq = psc_fifoc_irq;
552}
553
396static struct psc_ops mpc512x_psc_ops = { 554static struct psc_ops mpc512x_psc_ops = {
397 .fifo_init = mpc512x_psc_fifo_init, 555 .fifo_init = mpc512x_psc_fifo_init,
398 .raw_rx_rdy = mpc512x_psc_raw_rx_rdy, 556 .raw_rx_rdy = mpc512x_psc_raw_rx_rdy,
@@ -410,6 +568,11 @@ static struct psc_ops mpc512x_psc_ops = {
410 .cw_disable_ints = mpc512x_psc_cw_disable_ints, 568 .cw_disable_ints = mpc512x_psc_cw_disable_ints,
411 .cw_restore_ints = mpc512x_psc_cw_restore_ints, 569 .cw_restore_ints = mpc512x_psc_cw_restore_ints,
412 .getuartclk = mpc512x_getuartclk, 570 .getuartclk = mpc512x_getuartclk,
571 .clock = mpc512x_psc_clock,
572 .fifoc_init = mpc512x_psc_fifoc_init,
573 .fifoc_uninit = mpc512x_psc_fifoc_uninit,
574 .get_irq = mpc512x_psc_get_irq,
575 .handle_irq = mpc512x_psc_handle_irq,
413}; 576};
414#endif 577#endif
415 578
@@ -519,10 +682,15 @@ mpc52xx_uart_startup(struct uart_port *port)
519 struct mpc52xx_psc __iomem *psc = PSC(port); 682 struct mpc52xx_psc __iomem *psc = PSC(port);
520 int ret; 683 int ret;
521 684
685 if (psc_ops->clock) {
686 ret = psc_ops->clock(port, 1);
687 if (ret)
688 return ret;
689 }
690
522 /* Request IRQ */ 691 /* Request IRQ */
523 ret = request_irq(port->irq, mpc52xx_uart_int, 692 ret = request_irq(port->irq, mpc52xx_uart_int,
524 IRQF_DISABLED | IRQF_SAMPLE_RANDOM, 693 port->irqflags, "mpc52xx_psc_uart", port);
525 "mpc52xx_psc_uart", port);
526 if (ret) 694 if (ret)
527 return ret; 695 return ret;
528 696
@@ -553,6 +721,9 @@ mpc52xx_uart_shutdown(struct uart_port *port)
553 port->read_status_mask = 0; 721 port->read_status_mask = 0;
554 out_be16(&psc->mpc52xx_psc_imr, port->read_status_mask); 722 out_be16(&psc->mpc52xx_psc_imr, port->read_status_mask);
555 723
724 if (psc_ops->clock)
725 psc_ops->clock(port, 0);
726
556 /* Release interrupt */ 727 /* Release interrupt */
557 free_irq(port->irq, port); 728 free_irq(port->irq, port);
558} 729}
@@ -851,15 +1022,12 @@ mpc52xx_uart_int_tx_chars(struct uart_port *port)
851} 1022}
852 1023
853static irqreturn_t 1024static irqreturn_t
854mpc52xx_uart_int(int irq, void *dev_id) 1025mpc5xxx_uart_process_int(struct uart_port *port)
855{ 1026{
856 struct uart_port *port = dev_id;
857 unsigned long pass = ISR_PASS_LIMIT; 1027 unsigned long pass = ISR_PASS_LIMIT;
858 unsigned int keepgoing; 1028 unsigned int keepgoing;
859 u8 status; 1029 u8 status;
860 1030
861 spin_lock(&port->lock);
862
863 /* While we have stuff to do, we continue */ 1031 /* While we have stuff to do, we continue */
864 do { 1032 do {
865 /* If we don't find anything to do, we stop */ 1033 /* If we don't find anything to do, we stop */
@@ -886,11 +1054,23 @@ mpc52xx_uart_int(int irq, void *dev_id)
886 1054
887 } while (keepgoing); 1055 } while (keepgoing);
888 1056
889 spin_unlock(&port->lock);
890
891 return IRQ_HANDLED; 1057 return IRQ_HANDLED;
892} 1058}
893 1059
1060static irqreturn_t
1061mpc52xx_uart_int(int irq, void *dev_id)
1062{
1063 struct uart_port *port = dev_id;
1064 irqreturn_t ret;
1065
1066 spin_lock(&port->lock);
1067
1068 ret = psc_ops->handle_irq(port);
1069
1070 spin_unlock(&port->lock);
1071
1072 return ret;
1073}
894 1074
895/* ======================================================================== */ 1075/* ======================================================================== */
896/* Console ( if applicable ) */ 1076/* Console ( if applicable ) */
@@ -1152,7 +1332,7 @@ mpc52xx_uart_of_probe(struct of_device *op, const struct of_device_id *match)
1152 return -EINVAL; 1332 return -EINVAL;
1153 } 1333 }
1154 1334
1155 port->irq = irq_of_parse_and_map(op->node, 0); 1335 psc_ops->get_irq(port, op->node);
1156 if (port->irq == NO_IRQ) { 1336 if (port->irq == NO_IRQ) {
1157 dev_dbg(&op->dev, "Could not get irq\n"); 1337 dev_dbg(&op->dev, "Could not get irq\n");
1158 return -EINVAL; 1338 return -EINVAL;
@@ -1163,10 +1343,8 @@ mpc52xx_uart_of_probe(struct of_device *op, const struct of_device_id *match)
1163 1343
1164 /* Add the port to the uart sub-system */ 1344 /* Add the port to the uart sub-system */
1165 ret = uart_add_one_port(&mpc52xx_uart_driver, port); 1345 ret = uart_add_one_port(&mpc52xx_uart_driver, port);
1166 if (ret) { 1346 if (ret)
1167 irq_dispose_mapping(port->irq);
1168 return ret; 1347 return ret;
1169 }
1170 1348
1171 dev_set_drvdata(&op->dev, (void *)port); 1349 dev_set_drvdata(&op->dev, (void *)port);
1172 return 0; 1350 return 0;
@@ -1178,10 +1356,8 @@ mpc52xx_uart_of_remove(struct of_device *op)
1178 struct uart_port *port = dev_get_drvdata(&op->dev); 1356 struct uart_port *port = dev_get_drvdata(&op->dev);
1179 dev_set_drvdata(&op->dev, NULL); 1357 dev_set_drvdata(&op->dev, NULL);
1180 1358
1181 if (port) { 1359 if (port)
1182 uart_remove_one_port(&mpc52xx_uart_driver, port); 1360 uart_remove_one_port(&mpc52xx_uart_driver, port);
1183 irq_dispose_mapping(port->irq);
1184 }
1185 1361
1186 return 0; 1362 return 0;
1187} 1363}
@@ -1288,6 +1464,15 @@ mpc52xx_uart_init(void)
1288 1464
1289 mpc52xx_uart_of_enumerate(); 1465 mpc52xx_uart_of_enumerate();
1290 1466
1467 /*
1468 * Map the PSC FIFO Controller and init if on MPC512x.
1469 */
1470 if (psc_ops && psc_ops->fifoc_init) {
1471 ret = psc_ops->fifoc_init();
1472 if (ret)
1473 return ret;
1474 }
1475
1291 ret = of_register_platform_driver(&mpc52xx_uart_of_driver); 1476 ret = of_register_platform_driver(&mpc52xx_uart_of_driver);
1292 if (ret) { 1477 if (ret) {
1293 printk(KERN_ERR "%s: of_register_platform_driver failed (%i)\n", 1478 printk(KERN_ERR "%s: of_register_platform_driver failed (%i)\n",
@@ -1302,6 +1487,9 @@ mpc52xx_uart_init(void)
1302static void __exit 1487static void __exit
1303mpc52xx_uart_exit(void) 1488mpc52xx_uart_exit(void)
1304{ 1489{
1490 if (psc_ops->fifoc_uninit)
1491 psc_ops->fifoc_uninit();
1492
1305 of_unregister_platform_driver(&mpc52xx_uart_of_driver); 1493 of_unregister_platform_driver(&mpc52xx_uart_of_driver);
1306 uart_unregister_driver(&mpc52xx_uart_driver); 1494 uart_unregister_driver(&mpc52xx_uart_driver);
1307} 1495}