MLK-15070-2: ASoC: fsl: Add machine driver for AK4497
authorDaniel Baluta <daniel.baluta@nxp.com>
Mon, 31 Jul 2017 10:57:43 +0000 (13:57 +0300)
committerNitin Garg <nitin.garg@nxp.com>
Tue, 20 Mar 2018 19:53:04 +0000 (14:53 -0500)
This glues SAI interface with AK4497 DAC codec on i.MX boards.

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Documentation/devicetree/bindings/sound/imx-audio-ak4497.txt [new file with mode: 0644]
sound/soc/fsl/Kconfig
sound/soc/fsl/Makefile
sound/soc/fsl/imx-ak4497.c [new file with mode: 0644]

diff --git a/Documentation/devicetree/bindings/sound/imx-audio-ak4497.txt b/Documentation/devicetree/bindings/sound/imx-audio-ak4497.txt
new file mode 100644 (file)
index 0000000..f93a03a
--- /dev/null
@@ -0,0 +1,27 @@
+Freescale i.MX audio complex with AK4497 DAC
+
+Required properties:
+
+- compatible   : "fsl,imx-audio-ak4497"
+- model        : The user-visible name of this sound complex
+- audio-cpu    : The phandle of CPU DAI
+- audio-codec  : The phandle of the ak4497 audio DAC
+- 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, ak4497 pins,
+  and the jacks on the board.
+
+Example:
+
+sound {
+       compatible = "fsl,imx-audio-ak4497";
+       model = "ak4497-audio";
+       audio-cpu = <&sai3>;
+       audio-codec = <&codec>;
+       audio-routing =
+               "AOUTLN", "Playback",
+               "AOUTLP", "Playback",
+               "AOUTRN", "Playback",
+               "AOUTRP", "Playback",
+};
+
index 0dad21d..745139f 100644 (file)
@@ -301,6 +301,18 @@ config SND_SOC_IMX_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_AK4497
+       tristate "SoC Audio support for i.MX boards with AK4497"
+       depends on OF && I2C
+       select SND_SOC_AK4497
+       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 AK4497
+         Say Y if you want to add support for SoC audio on an i.MX board with
+         an AK4497 DAC.
+
 config SND_SOC_IMX_WM8960
        tristate "SoC Audio support for i.MX boards with wm8960"
        depends on OF && I2C
index 61004c7..ea77ae4 100644 (file)
@@ -85,6 +85,7 @@ 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
+snd-soc-imx-ak4497-objs := imx-ak4497.o
 
 obj-$(CONFIG_SND_SOC_EUKREA_TLV320) += snd-soc-eukrea-tlv320.o
 obj-$(CONFIG_SND_SOC_PHYCORE_AC97) += snd-soc-phycore-ac97.o
@@ -110,5 +111,6 @@ 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
+obj-$(CONFIG_SND_SOC_IMX_AK4497) += snd-soc-imx-ak4497.o
 
 AFLAGS_hdmi_pcm.o := -march=armv7-a -mtune=cortex-a9 -mfpu=neon -mfloat-abi=softfp
diff --git a/sound/soc/fsl/imx-ak4497.c b/sound/soc/fsl/imx-ak4497.c
new file mode 100644 (file)
index 0000000..627f057
--- /dev/null
@@ -0,0 +1,168 @@
+/* i.MX AK4458 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/ak4497.h"
+
+
+struct imx_ak4497_data {
+       struct snd_soc_card card;
+};
+
+static struct snd_soc_dapm_widget imx_ak4497_dapm_widgets[] = {
+       SND_SOC_DAPM_LINE("Line Out", 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_ak4497_dai = {
+       .name = "ak4497",
+       .stream_name = "Audio",
+       .codec_dai_name = "ak4497-aif",
+       .ops = &imx_aif_ops,
+       .playback_only = 1,
+};
+
+static int imx_ak4497_probe(struct platform_device *pdev)
+{
+       struct imx_ak4497_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_ak4497_dai.codec_of_node = codec_np;
+       imx_ak4497_dai.cpu_dai_name = dev_name(&cpu_pdev->dev);
+       imx_ak4497_dai.platform_of_node = cpu_np;
+       imx_ak4497_dai.playback_only = 1;
+
+       priv->card.dai_link = &imx_ak4497_dai;
+       priv->card.num_links = 1;
+       priv->card.dev = &pdev->dev;
+       priv->card.owner = THIS_MODULE;
+       priv->card.dapm_widgets = imx_ak4497_dapm_widgets;
+       priv->card.num_dapm_widgets = ARRAY_SIZE(imx_ak4497_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_ak4497_dt_ids[] = {
+       { .compatible = "fsl,imx-audio-ak4497", },
+       { },
+};
+MODULE_DEVICE_TABLE(of, imx_ak4497_dt_ids);
+
+static struct platform_driver imx_ak4497_driver = {
+       .driver = {
+               .name = "imx-ak4497",
+               .pm = &snd_soc_pm_ops,
+               .of_match_table = imx_ak4497_dt_ids,
+       },
+       .probe = imx_ak4497_probe,
+};
+module_platform_driver(imx_ak4497_driver);
+
+MODULE_AUTHOR("Daniel Baluta <daniel.baluta@nxp.com>");
+MODULE_DESCRIPTION("Freescale i.MX AK4497 ASoC machine driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:imx-ak4497");