From: Shawn Guo <shawn.guo@linaro.org>
To: alsa-devel@alsa-project.org
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>,
linux-arm-kernel@lists.infradead.org,
Dong Aisheng <dong.aisheng@linaro.org>,
Shawn Guo <shawn.guo@linaro.org>
Subject: [PATCH 4/6] ASoC: mxs: add device tree support for mxs-saif
Date: Thu, 10 May 2012 16:42:11 +0800 [thread overview]
Message-ID: <1336639333-11561-5-git-send-email-shawn.guo@linaro.org> (raw)
In-Reply-To: <1336639333-11561-1-git-send-email-shawn.guo@linaro.org>
Add device tree probe for mxs-saif driver.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
---
.../devicetree/bindings/sound/mxs-saif.txt | 36 ++++++++++
sound/soc/mxs/mxs-saif.c | 74 +++++++++++++++-----
2 files changed, 93 insertions(+), 17 deletions(-)
create mode 100644 Documentation/devicetree/bindings/sound/mxs-saif.txt
diff --git a/Documentation/devicetree/bindings/sound/mxs-saif.txt b/Documentation/devicetree/bindings/sound/mxs-saif.txt
new file mode 100644
index 0000000..c37ba61
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/mxs-saif.txt
@@ -0,0 +1,36 @@
+* Freescale MXS Serial Audio Interface (SAIF)
+
+Required properties:
+- compatible: Should be "fsl,<chip>-saif"
+- reg: Should contain registers location and length
+- interrupts: Should contain ERROR and DMA interrupts
+- fsl,saif-dma-channel: APBX DMA channel for the SAIF
+
+Optional properties:
+- fsl,saif-master: phandle to the master SAIF. It's only required for
+ the slave SAIF.
+
+Note: Each SAIF controller should have an alias correctly numbered
+in "aliases" node.
+
+Example:
+
+aliases {
+ saif0 = &saif0;
+ saif1 = &saif1;
+};
+
+saif0: saif@80042000 {
+ compatible = "fsl,imx28-saif";
+ reg = <0x80042000 2000>;
+ interrupts = <59 80>;
+ fsl,saif-dma-channel = <4>;
+};
+
+saif1: saif@80046000 {
+ compatible = "fsl,imx28-saif";
+ reg = <0x80046000 2000>;
+ interrupts = <58 81>;
+ fsl,saif-dma-channel = <5>;
+ fsl,saif-master = <&saif0>;
+};
diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c
index fa80ee6..ca1e77c 100644
--- a/sound/soc/mxs/mxs-saif.c
+++ b/sound/soc/mxs/mxs-saif.c
@@ -18,6 +18,8 @@
#include <linux/module.h>
#include <linux/init.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/dma-mapping.h>
@@ -623,35 +625,58 @@ static irqreturn_t mxs_saif_irq(int irq, void *dev_id)
static int __devinit mxs_saif_probe(struct platform_device *pdev)
{
+ struct device_node *np = pdev->dev.of_node;
struct resource *iores, *dmares;
struct mxs_saif *saif;
struct mxs_saif_platform_data *pdata;
struct pinctrl *pinctrl;
int ret = 0;
- if (pdev->id >= ARRAY_SIZE(mxs_saif))
+
+ if (!np && pdev->id >= ARRAY_SIZE(mxs_saif))
return -EINVAL;
saif = devm_kzalloc(&pdev->dev, sizeof(*saif), GFP_KERNEL);
if (!saif)
return -ENOMEM;
- mxs_saif[pdev->id] = saif;
- saif->id = pdev->id;
-
- pdata = pdev->dev.platform_data;
- if (pdata && !pdata->master_mode) {
- saif->master_id = pdata->master_id;
- if (saif->master_id < 0 ||
- saif->master_id >= ARRAY_SIZE(mxs_saif) ||
- saif->master_id == saif->id) {
- dev_err(&pdev->dev, "get wrong master id\n");
- return -EINVAL;
+ if (np) {
+ struct device_node *master;
+ saif->id = of_alias_get_id(np, "saif");
+ if (saif->id < 0)
+ return saif->id;
+ /*
+ * If there is no "fsl,saif-master" phandle, it's a saif
+ * master. Otherwise, it's a slave and its phandle points
+ * to the master.
+ */
+ master = of_parse_phandle(np, "fsl,saif-master", 0);
+ if (!master) {
+ saif->master_id = saif->id;
+ } else {
+ saif->master_id = of_alias_get_id(master, "saif");
+ if (saif->master_id < 0)
+ return saif->master_id;
}
} else {
- saif->master_id = saif->id;
+ saif->id = pdev->id;
+
+ pdata = pdev->dev.platform_data;
+ if (pdata && !pdata->master_mode) {
+ saif->master_id = pdata->master_id;
+ if (saif->master_id < 0 ||
+ saif->master_id >= ARRAY_SIZE(mxs_saif) ||
+ saif->master_id == saif->id) {
+ dev_err(&pdev->dev, "get wrong master id\n");
+ return -EINVAL;
+ }
+ } else {
+ saif->master_id = saif->id;
+ }
}
+ mxs_saif[saif->id] = saif;
+
pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
if (IS_ERR(pinctrl)) {
ret = PTR_ERR(pinctrl);
@@ -676,11 +701,19 @@ static int __devinit mxs_saif_probe(struct platform_device *pdev)
dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
if (!dmares) {
- dev_err(&pdev->dev, "failed to get dma resource: %d\n",
- ret);
- return -ENODEV;
+ /*
+ * TODO: This is a temporary solution and should be changed
+ * to use generic DMA binding later when the helplers get in.
+ */
+ ret = of_property_read_u32(np, "fsl,saif-dma-channel",
+ &saif->dma_param.chan_num);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to get dma channel\n");
+ return ret;
+ }
+ } else {
+ saif->dma_param.chan_num = dmares->start;
}
- saif->dma_param.chan_num = dmares->start;
saif->irq = platform_get_irq(pdev, 0);
if (saif->irq < 0) {
@@ -730,6 +763,12 @@ static int __devexit mxs_saif_remove(struct platform_device *pdev)
return 0;
}
+static const struct of_device_id mxs_saif_dt_ids[] = {
+ { .compatible = "fsl,imx28-saif", },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, mxs_saif_dt_ids);
+
static struct platform_driver mxs_saif_driver = {
.probe = mxs_saif_probe,
.remove = __devexit_p(mxs_saif_remove),
@@ -737,6 +776,7 @@ static struct platform_driver mxs_saif_driver = {
.driver = {
.name = "mxs-saif",
.owner = THIS_MODULE,
+ .of_match_table = mxs_saif_dt_ids,
},
};
--
1.7.5.4
next prev parent reply other threads:[~2012-05-10 8:42 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-10 8:42 [PATCH 0/6] Add device tree support for mxs audio Shawn Guo
2012-05-10 8:42 ` [PATCH 1/6] ASoC: mxs: add __devinit for mxs_saif_probe Shawn Guo
2012-05-10 8:58 ` Dong Aisheng
2012-05-10 9:32 ` Mark Brown
2012-05-10 8:42 ` [PATCH 2/6] ASoC: mxs: use devm_clk_get " Shawn Guo
2012-05-10 9:12 ` Dong Aisheng
2012-05-10 9:11 ` Shawn Guo
2012-05-10 9:13 ` Mark Brown
2012-05-10 9:17 ` Shawn Guo
2012-05-10 9:30 ` Mark Brown
2012-05-10 12:01 ` Shawn Guo
2012-05-10 8:42 ` [PATCH 3/6] ASoC: mxs: mxs-pcm does not need to be a plaform_driver Shawn Guo
2012-05-10 9:25 ` Dong Aisheng
2012-05-10 12:13 ` Shawn Guo
2012-05-10 8:42 ` Shawn Guo [this message]
2012-05-10 9:45 ` [PATCH 4/6] ASoC: mxs: add device tree support for mxs-saif Dong Aisheng
2012-05-10 12:14 ` Shawn Guo
2012-05-10 8:42 ` [PATCH 5/6] ASoC: mxs: add device tree support for mxs-sgtl5000 Shawn Guo
2012-05-10 11:16 ` Dong Aisheng
2012-05-10 12:20 ` Shawn Guo
2012-05-11 2:33 ` Dong Aisheng
2012-05-11 2:49 ` Shawn Guo
2012-05-11 14:14 ` Shawn Guo
2012-05-10 8:42 ` [PATCH 6/6] ARM: dts: enable audio support for imx28-evk Shawn Guo
2012-05-10 11:22 ` Dong Aisheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1336639333-11561-5-git-send-email-shawn.guo@linaro.org \
--to=shawn.guo@linaro.org \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=dong.aisheng@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).