]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ASoC: am335x-tx48: add support for Ka-Ro TX48 module
authorLothar Waßmann <LW@KARO-electronics.de>
Wed, 11 Dec 2013 15:06:45 +0000 (16:06 +0100)
committerLothar Waßmann <LW@KARO-electronics.de>
Wed, 27 Aug 2014 08:32:21 +0000 (10:32 +0200)
sound/soc/davinci/Kconfig
sound/soc/davinci/Makefile
sound/soc/davinci/am335x-tx48.c [new file with mode: 0644]

index 50a098749b9e2104d8451a16352b855938ae8366..ac3eaefa610c5cef4c1d61d42c5f1983913fded9 100644 (file)
@@ -26,6 +26,15 @@ config SND_AM33XX_SOC_EVM
          AM335X-EVMSK, and BeagelBone with AudioCape boards have this
          setup.
 
+config  SND_AM335X_SOC_TX48
+       tristate "SoC Audio support for Ka-Ro TX48"
+       depends on OF && SND_DAVINCI_SOC && SOC_AM33XX
+       select SND_SOC_SGTL5000
+       select SND_DAVINCI_SOC_MCASP
+       help
+         Say Y if you want to add support for SoC audio on
+         Ka-Ro electronics TX48
+
 config SND_DAVINCI_SOC_EVM
        tristate "SoC Audio support for DaVinci DM6446, DM355 or DM365 EVM"
        depends on SND_DAVINCI_SOC && I2C
index 744d4d9a018466c77709a0d18e40afdb26aac063..0f70ddaaf73f301811624ec7df0ee32d62499341 100644 (file)
@@ -11,5 +11,7 @@ obj-$(CONFIG_SND_DAVINCI_SOC_VCIF) += snd-soc-davinci-vcif.o
 
 # Generic DAVINCI/AM33xx Machine Support
 snd-soc-evm-objs := davinci-evm.o
+snd-soc-tx48-objs := am335x-tx48.o
 
 obj-$(CONFIG_SND_DAVINCI_SOC_GENERIC_EVM) += snd-soc-evm.o
+obj-$(CONFIG_SND_AM335X_SOC_TX48) += snd-soc-tx48.o
diff --git a/sound/soc/davinci/am335x-tx48.c b/sound/soc/davinci/am335x-tx48.c
new file mode 100644 (file)
index 0000000..381f545
--- /dev/null
@@ -0,0 +1,198 @@
+/*
+ * ASoC driver for Ka-Ro electronics TX48 module
+ * (C) Copyright 2013 Lothar Waßmann <LW@KARO-electronics.de>
+ *
+ * based on: davinci-evm.c
+ * Author:      Vladimir Barinov, <vbarinov@embeddedalley.com>
+ * Copyright:   (C) 2007 MontaVista Software, Inc., <source@mvista.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#define DEBUG
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/timer.h>
+#include <linux/interrupt.h>
+#include <linux/of_platform.h>
+#include <linux/i2c.h>
+#include <linux/edma.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+
+#include <asm/dma.h>
+#include <asm/mach-types.h>
+
+#include "../codecs/sgtl5000.h"
+
+#include "davinci-pcm.h"
+#include "davinci-i2s.h"
+#include "davinci-mcasp.h"
+
+struct am335x_tx48_drvdata {
+       unsigned sysclk;
+};
+
+static int sgtl5000_hw_params(struct snd_pcm_substream *substream,
+       struct snd_pcm_hw_params *params)
+{
+       int ret;
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *codec_dai = rtd->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+       struct snd_soc_card *soc_card = rtd->codec->card;
+       struct am335x_tx48_drvdata *drvdata = snd_soc_card_get_drvdata(soc_card);
+       unsigned sysclk = drvdata->sysclk;
+       u32 dai_format;
+
+       if (!codec_dai) {
+               dev_err(rtd->dev->parent, "No CODEC DAI\n");
+               return -ENODEV;
+       }
+       if (!codec_dai->driver) {
+               dev_err(rtd->dev->parent, "No CODEC DAI driver\n");
+               return -ENODEV;
+       }
+
+       if (!cpu_dai) {
+               dev_err(rtd->dev->parent, "No CPU DAI\n");
+               return -ENODEV;
+       }
+       if (!cpu_dai->driver) {
+               dev_err(rtd->dev->parent, "No CPU DAI driver\n");
+               return -ENODEV;
+       }
+
+       dev_info(rtd->dev->parent, "%s: setting codec clock to %u.%03uMHz\n", __func__,
+               sysclk / 1000000, sysclk / 1000 % 1000);
+       /* Set SGTL5000's SYSCLK */
+       ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, sysclk, 0);
+       if (ret)
+               return ret;
+
+       dev_info(rtd->dev->parent, "%s: setting mcasp clock to %u.%03uMHz\n", __func__,
+               sysclk / 1000000, sysclk / 1000 % 1000);
+
+       /* set codec to master mode */
+       dai_format = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+                       SND_SOC_DAIFMT_CBM_CFM;
+
+       /* set codec DAI configuration */
+       ret = snd_soc_dai_set_fmt(codec_dai, dai_format);
+       if (ret)
+               return ret;
+
+       /* set cpu DAI configuration */
+       ret = snd_soc_dai_set_fmt(cpu_dai, dai_format);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
+static struct snd_soc_ops am335x_tx48_ops = {
+       .hw_params = sgtl5000_hw_params,
+};
+
+/*
+ * The struct is used as place holder. It will be completely
+ * filled with data from dt node.
+ */
+static struct snd_soc_dai_link am335x_tx48_dai = {
+       .name = "SGTL5000",
+       .stream_name = "SGTL5000",
+       .codec_dai_name = "sgtl5000",
+       .ops = &am335x_tx48_ops,
+};
+
+static struct snd_soc_card am335x_tx48_soc_card = {
+       .owner = THIS_MODULE,
+       .dai_link = &am335x_tx48_dai,
+       .num_links = 1,
+};
+
+static const struct of_device_id am335x_tx48_dt_ids[] = {
+       { .compatible = "ti,am335x-tx48-audio", },
+       { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, am335x_tx48_dt_ids);
+
+static int am335x_tx48_probe(struct platform_device *pdev)
+{
+       int ret;
+       struct device_node *np = pdev->dev.of_node;
+       struct am335x_tx48_drvdata *drvdata;
+       struct device_node *of_node;
+
+       of_node = of_parse_phandle(np, "ti,audio-codec", 0);
+       if (!of_node) {
+               dev_err(&pdev->dev, "codec handle missing in DT\n");
+               return -EINVAL;
+       }
+
+       am335x_tx48_dai.codec_of_node = of_node;
+       of_node_put(of_node);
+
+       of_node = of_parse_phandle(np, "ti,mcasp-controller", 0);
+       if (!of_node) {
+               dev_err(&pdev->dev, "mcasp handle missing in DT\n");
+               return -EINVAL;
+       }
+
+       am335x_tx48_dai.cpu_of_node = of_node;
+       am335x_tx48_dai.platform_of_node = of_node;
+       of_node_put(of_node);
+
+       am335x_tx48_soc_card.dev = &pdev->dev;
+       ret = snd_soc_of_parse_card_name(&am335x_tx48_soc_card, "ti,model");
+       if (ret)
+               return ret;
+
+       drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
+       if (!drvdata)
+               return -ENOMEM;
+
+       ret = of_property_read_u32(np, "ti,codec-clock-rate", &drvdata->sysclk);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "codec clock rate not set in DT\n");
+               return -EINVAL;
+       }
+
+       snd_soc_card_set_drvdata(&am335x_tx48_soc_card, drvdata);
+       ret = devm_snd_soc_register_card(&pdev->dev, &am335x_tx48_soc_card);
+       if (ret) {
+               dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
+               return ret;
+       }
+       dev_dbg(&pdev->dev, "Soundcard %p registered\n", &am335x_tx48_soc_card);
+       return 0;
+}
+
+static int am335x_tx48_remove(struct platform_device *pdev)
+{
+       struct snd_soc_card *card = platform_get_drvdata(pdev);
+
+dev_dbg(&pdev->dev, "%s: Unregistering card %p\n", __func__, card);
+       snd_soc_unregister_card(card);
+
+       return 0;
+}
+
+static struct platform_driver am335x_tx48_driver = {
+       .probe          = am335x_tx48_probe,
+       .remove         = am335x_tx48_remove,
+       .driver         = {
+               .name   = "am335x_tx48",
+               .owner  = THIS_MODULE,
+               .of_match_table = am335x_tx48_dt_ids,
+       },
+};
+module_platform_driver(am335x_tx48_driver);
+
+MODULE_AUTHOR("Lothar Waßmann");
+MODULE_DESCRIPTION("Ka-Ro TX48 ASoC driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:am335x-tx48");