aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/serial
diff options
context:
space:
mode:
authorFabio Estevam <fabio.estevam@freescale.com>2012-06-18 09:06:09 -0400
committerShawn Guo <shawn.guo@linaro.org>2012-07-03 01:22:35 -0400
commit1ea6607d4cdc917987e7e6cfaafc4a630d97a297 (patch)
treebbb1bc41125fc8dfe071ee7e5fbd44204f33baec /drivers/tty/serial
parenta217c46c2ed65d4cde5c7c72290deebc2303116e (diff)
serial: mxs-auart: Allow device tree probing
Allow device tree probing. Cc: Grant Likely <grant.likely@secretlab.ca> Cc: Rob Herring <rob.herring@calxeda.com> Cc: Alan Cox <alan@linux.intel.com> Cc: <linux-serial@vger.kernel.org> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com> Signed-off-by: Subodh Nijsure <snijsure@grid-net.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Diffstat (limited to 'drivers/tty/serial')
-rw-r--r--drivers/tty/serial/mxs-auart.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index ec56d8397aae..2e341b81ff89 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -33,6 +33,7 @@
33#include <linux/delay.h> 33#include <linux/delay.h>
34#include <linux/io.h> 34#include <linux/io.h>
35#include <linux/pinctrl/consumer.h> 35#include <linux/pinctrl/consumer.h>
36#include <linux/of_device.h>
36 37
37#include <asm/cacheflush.h> 38#include <asm/cacheflush.h>
38 39
@@ -675,6 +676,30 @@ static struct uart_driver auart_driver = {
675#endif 676#endif
676}; 677};
677 678
679/*
680 * This function returns 1 if pdev isn't a device instatiated by dt, 0 if it
681 * could successfully get all information from dt or a negative errno.
682 */
683static int serial_mxs_probe_dt(struct mxs_auart_port *s,
684 struct platform_device *pdev)
685{
686 struct device_node *np = pdev->dev.of_node;
687 int ret;
688
689 if (!np)
690 /* no device tree device */
691 return 1;
692
693 ret = of_alias_get_id(np, "serial");
694 if (ret < 0) {
695 dev_err(&pdev->dev, "failed to get alias id: %d\n", ret);
696 return ret;
697 }
698 s->port.line = ret;
699
700 return 0;
701}
702
678static int __devinit mxs_auart_probe(struct platform_device *pdev) 703static int __devinit mxs_auart_probe(struct platform_device *pdev)
679{ 704{
680 struct mxs_auart_port *s; 705 struct mxs_auart_port *s;
@@ -689,6 +714,12 @@ static int __devinit mxs_auart_probe(struct platform_device *pdev)
689 goto out; 714 goto out;
690 } 715 }
691 716
717 ret = serial_mxs_probe_dt(s, pdev);
718 if (ret > 0)
719 s->port.line = pdev->id < 0 ? 0 : pdev->id;
720 else if (ret < 0)
721 goto out_free;
722
692 pinctrl = devm_pinctrl_get_select_default(&pdev->dev); 723 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
693 if (IS_ERR(pinctrl)) { 724 if (IS_ERR(pinctrl)) {
694 ret = PTR_ERR(pinctrl); 725 ret = PTR_ERR(pinctrl);
@@ -711,7 +742,6 @@ static int __devinit mxs_auart_probe(struct platform_device *pdev)
711 s->port.membase = ioremap(r->start, resource_size(r)); 742 s->port.membase = ioremap(r->start, resource_size(r));
712 s->port.ops = &mxs_auart_ops; 743 s->port.ops = &mxs_auart_ops;
713 s->port.iotype = UPIO_MEM; 744 s->port.iotype = UPIO_MEM;
714 s->port.line = pdev->id < 0 ? 0 : pdev->id;
715 s->port.fifosize = 16; 745 s->port.fifosize = 16;
716 s->port.uartclk = clk_get_rate(s->clk); 746 s->port.uartclk = clk_get_rate(s->clk);
717 s->port.type = PORT_IMX; 747 s->port.type = PORT_IMX;
@@ -728,7 +758,7 @@ static int __devinit mxs_auart_probe(struct platform_device *pdev)
728 758
729 platform_set_drvdata(pdev, s); 759 platform_set_drvdata(pdev, s);
730 760
731 auart_port[pdev->id] = s; 761 auart_port[s->port.line] = s;
732 762
733 mxs_auart_reset(&s->port); 763 mxs_auart_reset(&s->port);
734 764
@@ -769,12 +799,19 @@ static int __devexit mxs_auart_remove(struct platform_device *pdev)
769 return 0; 799 return 0;
770} 800}
771 801
802static struct of_device_id mxs_auart_dt_ids[] = {
803 { .compatible = "fsl,imx23-auart", },
804 { /* sentinel */ }
805};
806MODULE_DEVICE_TABLE(of, mxs_auart_dt_ids);
807
772static struct platform_driver mxs_auart_driver = { 808static struct platform_driver mxs_auart_driver = {
773 .probe = mxs_auart_probe, 809 .probe = mxs_auart_probe,
774 .remove = __devexit_p(mxs_auart_remove), 810 .remove = __devexit_p(mxs_auart_remove),
775 .driver = { 811 .driver = {
776 .name = "mxs-auart", 812 .name = "mxs-auart",
777 .owner = THIS_MODULE, 813 .owner = THIS_MODULE,
814 .of_match_table = mxs_auart_dt_ids,
778 }, 815 },
779}; 816};
780 817
@@ -807,3 +844,4 @@ module_init(mxs_auart_init);
807module_exit(mxs_auart_exit); 844module_exit(mxs_auart_exit);
808MODULE_LICENSE("GPL"); 845MODULE_LICENSE("GPL");
809MODULE_DESCRIPTION("Freescale MXS application uart driver"); 846MODULE_DESCRIPTION("Freescale MXS application uart driver");
847MODULE_ALIAS("platform:mxs-auart");