2 * ASoC driver for Ka-Ro electronics TX48 module
3 * (C) Copyright 2013 Lothar Waßmann <LW@KARO-electronics.de>
5 * based on: davinci-evm.c
6 * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
7 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
15 #include <linux/module.h>
16 #include <linux/moduleparam.h>
17 #include <linux/timer.h>
18 #include <linux/interrupt.h>
19 #include <linux/of_platform.h>
20 #include <linux/i2c.h>
21 #include <linux/edma.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/soc.h>
27 #include <asm/mach-types.h>
29 #include "../codecs/sgtl5000.h"
31 #include "davinci-pcm.h"
32 #include "davinci-i2s.h"
33 #include "davinci-mcasp.h"
35 struct am335x_tx48_drvdata {
39 static int sgtl5000_hw_params(struct snd_pcm_substream *substream,
40 struct snd_pcm_hw_params *params)
43 struct snd_soc_pcm_runtime *rtd = substream->private_data;
44 struct snd_soc_dai *codec_dai = rtd->codec_dai;
45 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
46 struct snd_soc_card *soc_card = rtd->codec->card;
47 struct am335x_tx48_drvdata *drvdata = snd_soc_card_get_drvdata(soc_card);
48 unsigned sysclk = drvdata->sysclk;
52 dev_err(rtd->dev->parent, "No CODEC DAI\n");
55 if (!codec_dai->driver) {
56 dev_err(rtd->dev->parent, "No CODEC DAI driver\n");
61 dev_err(rtd->dev->parent, "No CPU DAI\n");
64 if (!cpu_dai->driver) {
65 dev_err(rtd->dev->parent, "No CPU DAI driver\n");
69 dev_info(rtd->dev->parent, "%s: setting codec clock to %u.%03uMHz\n", __func__,
70 sysclk / 1000000, sysclk / 1000 % 1000);
71 /* Set SGTL5000's SYSCLK */
72 ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, sysclk, 0);
76 dev_info(rtd->dev->parent, "%s: setting mcasp clock to %u.%03uMHz\n", __func__,
77 sysclk / 1000000, sysclk / 1000 % 1000);
79 /* set codec to master mode */
80 dai_format = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
81 SND_SOC_DAIFMT_CBM_CFM;
83 /* set codec DAI configuration */
84 ret = snd_soc_dai_set_fmt(codec_dai, dai_format);
88 /* set cpu DAI configuration */
89 ret = snd_soc_dai_set_fmt(cpu_dai, dai_format);
96 static struct snd_soc_ops am335x_tx48_ops = {
97 .hw_params = sgtl5000_hw_params,
101 * The struct is used as place holder. It will be completely
102 * filled with data from dt node.
104 static struct snd_soc_dai_link am335x_tx48_dai = {
106 .stream_name = "SGTL5000",
107 .codec_dai_name = "sgtl5000",
108 .ops = &am335x_tx48_ops,
111 static struct snd_soc_card am335x_tx48_soc_card = {
112 .owner = THIS_MODULE,
113 .dai_link = &am335x_tx48_dai,
117 static const struct of_device_id am335x_tx48_dt_ids[] = {
118 { .compatible = "ti,am335x-tx48-audio", },
121 MODULE_DEVICE_TABLE(of, am335x_tx48_dt_ids);
123 static int am335x_tx48_probe(struct platform_device *pdev)
126 struct device_node *np = pdev->dev.of_node;
127 struct am335x_tx48_drvdata *drvdata;
128 struct device_node *of_node;
130 of_node = of_parse_phandle(np, "ti,audio-codec", 0);
132 dev_err(&pdev->dev, "codec handle missing in DT\n");
136 am335x_tx48_dai.codec_of_node = of_node;
137 of_node_put(of_node);
139 of_node = of_parse_phandle(np, "ti,mcasp-controller", 0);
141 dev_err(&pdev->dev, "mcasp handle missing in DT\n");
145 am335x_tx48_dai.cpu_of_node = of_node;
146 am335x_tx48_dai.platform_of_node = of_node;
147 of_node_put(of_node);
149 am335x_tx48_soc_card.dev = &pdev->dev;
150 ret = snd_soc_of_parse_card_name(&am335x_tx48_soc_card, "ti,model");
154 drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
158 ret = of_property_read_u32(np, "ti,codec-clock-rate", &drvdata->sysclk);
160 dev_err(&pdev->dev, "codec clock rate not set in DT\n");
164 snd_soc_card_set_drvdata(&am335x_tx48_soc_card, drvdata);
165 ret = devm_snd_soc_register_card(&pdev->dev, &am335x_tx48_soc_card);
167 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
170 dev_dbg(&pdev->dev, "Soundcard %p registered\n", &am335x_tx48_soc_card);
174 static int am335x_tx48_remove(struct platform_device *pdev)
176 struct snd_soc_card *card = platform_get_drvdata(pdev);
178 dev_dbg(&pdev->dev, "%s: Unregistering card %p\n", __func__, card);
179 snd_soc_unregister_card(card);
184 static struct platform_driver am335x_tx48_driver = {
185 .probe = am335x_tx48_probe,
186 .remove = am335x_tx48_remove,
188 .name = "am335x_tx48",
189 .owner = THIS_MODULE,
190 .of_match_table = am335x_tx48_dt_ids,
193 module_platform_driver(am335x_tx48_driver);
195 MODULE_AUTHOR("Lothar Waßmann");
196 MODULE_DESCRIPTION("Ka-Ro TX48 ASoC driver");
197 MODULE_LICENSE("GPL");
198 MODULE_ALIAS("platform:am335x-tx48");