MLK-15071-2: ASoC: fsl: Add machine driver for AK5558
authorShengjiu Wang <shengjiu.wang@nxp.com>
Wed, 27 Dec 2017 06:54:52 +0000 (14:54 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Tue, 20 Mar 2018 19:53:03 +0000 (14:53 -0500)
Add machine driver for i.MX boards that have AK5558 ADC attached to SAI.

Signed-off-by: Mihai Serban <mihai.serban@nxp.com>
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Documentation/devicetree/bindings/sound/imx-audio-ak5558.txt [new file with mode: 0644]
sound/soc/fsl/Kconfig
sound/soc/fsl/Makefile
sound/soc/fsl/imx-ak5558.c [new file with mode: 0644]

diff --git a/Documentation/devicetree/bindings/sound/imx-audio-ak5558.txt b/Documentation/devicetree/bindings/sound/imx-audio-ak5558.txt
new file mode 100644 (file)
index 0000000..3da9587
--- /dev/null
@@ -0,0 +1,30 @@
+Freescale i.MX audio complex with AK5558 ADC
+
+Required properties:
+
+- compatible   : "fsl,imx-audio-ak5558"
+- model                : The user-visible name of this sound complex
+- audio-cpu    : The phandle of CPU DAI
+- audio-codec  : The phandle of the AK5558 audio ADC
+- audio-routing : A list of the connections between audio components. Each entry
+  is a pair of strings, the first being the connection's sink, the second being
+  the connection's source. Valid names could be power supplies, AK5558 pins,
+  and the jacks on the board.
+
+Example:
+
+sound {
+       compatible = "fsl,imx-audio-ak5558";
+       model = "ak5558-audio";
+       audio-cpu = <&sai1>;
+       audio-codec = <&codec>;
+       audio-routing =
+               "AIN1", "Capture",
+               "AIN2", "Capture",
+               "AIN3", "Capture",
+               "AIN4", "Capture",
+               "AIN5", "Capture",
+               "AIN6", "Capture",
+               "AIN7", "Capture",
+               "AIN8", "Capture";
+};
index 6d8031e..0dad21d 100644 (file)
@@ -289,6 +289,18 @@ config SND_SOC_IMX_AK4458
          Say Y if you want to add support for SoC audio on an i.MX board with
          an AK4458 DAC.
 
+config SND_SOC_IMX_AK5558
+       tristate "SoC Audio support for i.MX boards with AK5558"
+       depends on OF && I2C
+       select SND_SOC_AK5558
+       select SND_SOC_IMX_PCM_DMA
+       select SND_SOC_FSL_SAI
+       select SND_SOC_FSL_UTILS
+       help
+         SoC Audio support for i.MX boards with AK5558
+         Say Y if you want to add support for SoC audio on an i.MX board with
+         an AK5558 ADC.
+
 config SND_SOC_IMX_WM8960
        tristate "SoC Audio support for i.MX boards with wm8960"
        depends on OF && I2C
index 6a6062e..61004c7 100644 (file)
@@ -84,6 +84,7 @@ snd-soc-imx-rpmsg-objs := imx-rpmsg.o
 snd-soc-imx-amix-objs := imx-amix.o
 snd-soc-imx-pdm-objs := imx-pdm.o
 snd-soc-imx-ak4458-objs := imx-ak4458.o
+snd-soc-imx-ak5558-objs := imx-ak5558.o
 
 obj-$(CONFIG_SND_SOC_EUKREA_TLV320) += snd-soc-eukrea-tlv320.o
 obj-$(CONFIG_SND_SOC_PHYCORE_AC97) += snd-soc-phycore-ac97.o
@@ -108,5 +109,6 @@ obj-$(CONFIG_SND_SOC_IMX_AMIX) += snd-soc-imx-amix.o
 obj-$(CONFIG_SND_SOC_IMX_CDNHDMI) += snd-soc-imx-cdnhdmi.o
 obj-$(CONFIG_SND_SOC_IMX_PDM_MIC) += snd-soc-imx-pdm.o
 obj-$(CONFIG_SND_SOC_IMX_AK4458) += snd-soc-imx-ak4458.o
+obj-$(CONFIG_SND_SOC_IMX_AK5558) += snd-soc-imx-ak5558.o
 
 AFLAGS_hdmi_pcm.o := -march=armv7-a -mtune=cortex-a9 -mfpu=neon -mfloat-abi=softfp
diff --git a/sound/soc/fsl/imx-ak5558.c b/sound/soc/fsl/imx-ak5558.c
new file mode 100644 (file)
index 0000000..59dc901
--- /dev/null
@@ -0,0 +1,169 @@
+/* i.MX AK5558 audio support
+ *
+ * Copyright 2017 NXP
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/gpio/consumer.h>
+#include <linux/of_device.h>
+#include <sound/soc.h>
+#include <sound/pcm_params.h>
+#include <sound/soc-dapm.h>
+
+#include "../codecs/ak5558.h"
+
+
+struct imx_ak5558_data {
+       struct snd_soc_card card;
+};
+
+static struct snd_soc_dapm_widget imx_ak5558_dapm_widgets[] = {
+       SND_SOC_DAPM_LINE("Line In", NULL),
+};
+
+static int imx_aif_hw_params(struct snd_pcm_substream *substream,
+                               struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+       struct snd_soc_dai *codec_dai = rtd->codec_dai;
+       struct snd_soc_card *card = rtd->card;
+       struct device *dev = card->dev;
+       unsigned int channels = params_channels(params);
+       unsigned int fmt;
+       int ret;
+
+       fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+               SND_SOC_DAIFMT_CBS_CFS;
+
+       ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
+       if (ret) {
+               dev_err(dev, "failed to set cpu dai fmt: %d\n", ret);
+               return ret;
+       }
+
+       ret = snd_soc_dai_set_fmt(codec_dai, fmt);
+       if (ret) {
+               dev_err(dev, "failed to set codec dai fmt: %d\n", ret);
+               return ret;
+       }
+
+       ret = snd_soc_dai_set_tdm_slot(cpu_dai,
+                                      BIT(channels) - 1, BIT(channels) - 1,
+                                      2, 32);
+       if (ret) {
+               dev_err(dev, "failed to set cpu dai tdm slot: %d\n", ret);
+               return ret;
+       }
+
+       return ret;
+}
+
+static struct snd_soc_ops imx_aif_ops = {
+       .hw_params = imx_aif_hw_params,
+};
+
+static struct snd_soc_dai_link imx_ak5558_dai = {
+       .name = "ak5558",
+       .stream_name = "Audio",
+       .codec_dai_name = "ak5558-aif",
+       .ops = &imx_aif_ops,
+       .capture_only = 1,
+};
+
+static int imx_ak5558_probe(struct platform_device *pdev)
+{
+       struct imx_ak5558_data *priv;
+       struct device_node *cpu_np, *codec_np = NULL;
+       struct platform_device *cpu_pdev;
+       int ret;
+
+
+       priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;
+
+       cpu_np = of_parse_phandle(pdev->dev.of_node, "audio-cpu", 0);
+       if (!cpu_np) {
+               dev_err(&pdev->dev, "audio dai phandle missing or invalid\n");
+               ret = -EINVAL;
+               goto fail;
+       }
+
+       codec_np = of_parse_phandle(pdev->dev.of_node, "audio-codec", 0);
+       if (!codec_np) {
+               dev_err(&pdev->dev, "audio codec phandle missing or invalid\n");
+               ret = -EINVAL;
+               goto fail;
+       }
+
+       cpu_pdev = of_find_device_by_node(cpu_np);
+       if (!cpu_pdev) {
+               dev_err(&pdev->dev, "failed to find SAI platform device\n");
+               ret = -EINVAL;
+               goto fail;
+       }
+
+       imx_ak5558_dai.codec_of_node = codec_np;
+       imx_ak5558_dai.cpu_dai_name = dev_name(&cpu_pdev->dev);
+       imx_ak5558_dai.platform_of_node = cpu_np;
+       imx_ak5558_dai.capture_only = 1;
+
+       priv->card.dai_link = &imx_ak5558_dai;
+       priv->card.num_links = 1;
+       priv->card.dev = &pdev->dev;
+       priv->card.owner = THIS_MODULE;
+       priv->card.dapm_widgets = imx_ak5558_dapm_widgets;
+       priv->card.num_dapm_widgets = ARRAY_SIZE(imx_ak5558_dapm_widgets);
+
+       ret = snd_soc_of_parse_card_name(&priv->card, "model");
+       if (ret)
+               goto fail;
+
+       snd_soc_card_set_drvdata(&priv->card, priv);
+
+       ret = devm_snd_soc_register_card(&pdev->dev, &priv->card);
+       if (ret) {
+               dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
+               goto fail;
+       }
+
+       ret = 0;
+fail:
+       if (cpu_np)
+               of_node_put(cpu_np);
+       if (codec_np)
+               of_node_put(codec_np);
+
+       return ret;
+}
+
+static const struct of_device_id imx_ak5558_dt_ids[] = {
+       { .compatible = "fsl,imx-audio-ak5558", },
+       { },
+};
+MODULE_DEVICE_TABLE(of, imx_ak5558_dt_ids);
+
+static struct platform_driver imx_ak5558_driver = {
+       .driver = {
+               .name = "imx-ak5558",
+               .pm = &snd_soc_pm_ops,
+               .of_match_table = imx_ak5558_dt_ids,
+       },
+       .probe = imx_ak5558_probe,
+};
+module_platform_driver(imx_ak5558_driver);
+
+MODULE_AUTHOR("Mihai Serban <mihai.serban@nxp.com>");
+MODULE_DESCRIPTION("Freescale i.MX AK5558 ASoC machine driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:imx-ak5558");