aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/mxs
diff options
context:
space:
mode:
authorShawn Guo <shawn.guo@linaro.org>2012-05-11 10:24:17 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-05-12 06:04:59 -0400
commit08641c7c74dddfcd726512edfaa3b4cbe42e523e (patch)
treea90c3c70a2dc4a57d3f227d9b93c8f953eed9f34 /sound/soc/mxs
parent4da3fe7851f9288c2479186d390b0de28d51bdb0 (diff)
ASoC: mxs: add device tree support for mxs-saif
Add device tree probe for mxs-saif driver. Signed-off-by: Shawn Guo <shawn.guo@linaro.org> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/mxs')
-rw-r--r--sound/soc/mxs/mxs-saif.c72
1 files changed, 54 insertions, 18 deletions
diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c
index 356aad83c1fe..064274880673 100644
--- a/sound/soc/mxs/mxs-saif.c
+++ b/sound/soc/mxs/mxs-saif.c
@@ -18,6 +18,8 @@
18 18
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/of.h>
22#include <linux/of_device.h>
21#include <linux/platform_device.h> 23#include <linux/platform_device.h>
22#include <linux/slab.h> 24#include <linux/slab.h>
23#include <linux/dma-mapping.h> 25#include <linux/dma-mapping.h>
@@ -622,34 +624,54 @@ static irqreturn_t mxs_saif_irq(int irq, void *dev_id)
622 624
623static int __devinit mxs_saif_probe(struct platform_device *pdev) 625static int __devinit mxs_saif_probe(struct platform_device *pdev)
624{ 626{
627 struct device_node *np = pdev->dev.of_node;
625 struct resource *iores, *dmares; 628 struct resource *iores, *dmares;
626 struct mxs_saif *saif; 629 struct mxs_saif *saif;
627 struct mxs_saif_platform_data *pdata; 630 struct mxs_saif_platform_data *pdata;
628 int ret = 0; 631 int ret = 0;
629 632
630 if (pdev->id >= ARRAY_SIZE(mxs_saif)) 633
634 if (!np && pdev->id >= ARRAY_SIZE(mxs_saif))
631 return -EINVAL; 635 return -EINVAL;
632 636
633 saif = devm_kzalloc(&pdev->dev, sizeof(*saif), GFP_KERNEL); 637 saif = devm_kzalloc(&pdev->dev, sizeof(*saif), GFP_KERNEL);
634 if (!saif) 638 if (!saif)
635 return -ENOMEM; 639 return -ENOMEM;
636 640
637 mxs_saif[pdev->id] = saif; 641 if (np) {
638 saif->id = pdev->id; 642 struct device_node *master;
639 643 saif->id = of_alias_get_id(np, "saif");
640 pdata = pdev->dev.platform_data; 644 if (saif->id < 0)
641 if (pdata && !pdata->master_mode) { 645 return saif->id;
642 saif->master_id = pdata->master_id; 646 /*
643 if (saif->master_id < 0 || 647 * If there is no "fsl,saif-master" phandle, it's a saif
644 saif->master_id >= ARRAY_SIZE(mxs_saif) || 648 * master. Otherwise, it's a slave and its phandle points
645 saif->master_id == saif->id) { 649 * to the master.
646 dev_err(&pdev->dev, "get wrong master id\n"); 650 */
647 return -EINVAL; 651 master = of_parse_phandle(np, "fsl,saif-master", 0);
652 if (!master) {
653 saif->master_id = saif->id;
654 } else {
655 saif->master_id = of_alias_get_id(master, "saif");
656 if (saif->master_id < 0)
657 return saif->master_id;
648 } 658 }
649 } else { 659 } else {
650 saif->master_id = saif->id; 660 saif->id = pdev->id;
661 pdata = pdev->dev.platform_data;
662 if (pdata && !pdata->master_mode)
663 saif->master_id = pdata->master_id;
664 else
665 saif->master_id = saif->id;
666 }
667
668 if (saif->master_id < 0 || saif->master_id >= ARRAY_SIZE(mxs_saif)) {
669 dev_err(&pdev->dev, "get wrong master id\n");
670 return -EINVAL;
651 } 671 }
652 672
673 mxs_saif[saif->id] = saif;
674
653 saif->clk = clk_get(&pdev->dev, NULL); 675 saif->clk = clk_get(&pdev->dev, NULL);
654 if (IS_ERR(saif->clk)) { 676 if (IS_ERR(saif->clk)) {
655 ret = PTR_ERR(saif->clk); 677 ret = PTR_ERR(saif->clk);
@@ -669,12 +691,19 @@ static int __devinit mxs_saif_probe(struct platform_device *pdev)
669 691
670 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0); 692 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
671 if (!dmares) { 693 if (!dmares) {
672 ret = -ENODEV; 694 /*
673 dev_err(&pdev->dev, "failed to get dma resource: %d\n", 695 * TODO: This is a temporary solution and should be changed
674 ret); 696 * to use generic DMA binding later when the helplers get in.
675 goto failed_get_resource; 697 */
698 ret = of_property_read_u32(np, "fsl,saif-dma-channel",
699 &saif->dma_param.chan_num);
700 if (ret) {
701 dev_err(&pdev->dev, "failed to get dma channel\n");
702 goto failed_get_resource;
703 }
704 } else {
705 saif->dma_param.chan_num = dmares->start;
676 } 706 }
677 saif->dma_param.chan_num = dmares->start;
678 707
679 saif->irq = platform_get_irq(pdev, 0); 708 saif->irq = platform_get_irq(pdev, 0);
680 if (saif->irq < 0) { 709 if (saif->irq < 0) {
@@ -735,6 +764,12 @@ static int __devexit mxs_saif_remove(struct platform_device *pdev)
735 return 0; 764 return 0;
736} 765}
737 766
767static const struct of_device_id mxs_saif_dt_ids[] = {
768 { .compatible = "fsl,imx28-saif", },
769 { /* sentinel */ }
770};
771MODULE_DEVICE_TABLE(of, mxs_saif_dt_ids);
772
738static struct platform_driver mxs_saif_driver = { 773static struct platform_driver mxs_saif_driver = {
739 .probe = mxs_saif_probe, 774 .probe = mxs_saif_probe,
740 .remove = __devexit_p(mxs_saif_remove), 775 .remove = __devexit_p(mxs_saif_remove),
@@ -742,6 +777,7 @@ static struct platform_driver mxs_saif_driver = {
742 .driver = { 777 .driver = {
743 .name = "mxs-saif", 778 .name = "mxs-saif",
744 .owner = THIS_MODULE, 779 .owner = THIS_MODULE,
780 .of_match_table = mxs_saif_dt_ids,
745 }, 781 },
746}; 782};
747 783