2 * trimslice.c - TrimSlice machine ASoC driver
4 * Copyright (C) 2011 - CompuLab, Ltd.
5 * Author: Mike Rapoport <mike@compulab.co.il>
7 * Based on code copyright/by:
8 * Author: Stephen Warren <swarren@nvidia.com>
9 * Copyright (C) 2010-2011 - NVIDIA, Inc.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * version 2 as published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 #include <asm/mach-types.h>
29 #include <linux/module.h>
31 #include <linux/platform_device.h>
32 #include <linux/slab.h>
34 #include <sound/core.h>
35 #include <sound/jack.h>
36 #include <sound/pcm.h>
37 #include <sound/pcm_params.h>
38 #include <sound/soc.h>
40 #include "../codecs/tlv320aic23.h"
42 #include "tegra_asoc_utils.h"
44 #define DRV_NAME "tegra-snd-trimslice"
46 struct tegra_trimslice {
47 struct tegra_asoc_utils_data util_data;
50 static int trimslice_asoc_hw_params(struct snd_pcm_substream *substream,
51 struct snd_pcm_hw_params *params)
53 struct snd_soc_pcm_runtime *rtd = substream->private_data;
54 struct snd_soc_dai *codec_dai = rtd->codec_dai;
55 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
56 struct snd_soc_codec *codec = rtd->codec;
57 struct snd_soc_card *card = codec->card;
58 struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
62 srate = params_rate(params);
65 err = tegra_asoc_utils_set_rate(&trimslice->util_data, srate, mclk);
67 dev_err(card->dev, "Can't configure clocks\n");
71 err = snd_soc_dai_set_fmt(codec_dai,
73 SND_SOC_DAIFMT_NB_NF |
74 SND_SOC_DAIFMT_CBS_CFS);
76 dev_err(card->dev, "codec_dai fmt not set\n");
80 err = snd_soc_dai_set_fmt(cpu_dai,
82 SND_SOC_DAIFMT_NB_NF |
83 SND_SOC_DAIFMT_CBS_CFS);
85 dev_err(card->dev, "cpu_dai fmt not set\n");
89 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
92 dev_err(card->dev, "codec_dai clock not set\n");
99 static struct snd_soc_ops trimslice_asoc_ops = {
100 .hw_params = trimslice_asoc_hw_params,
103 static const struct snd_soc_dapm_widget trimslice_dapm_widgets[] = {
104 SND_SOC_DAPM_HP("Line Out", NULL),
105 SND_SOC_DAPM_LINE("Line In", NULL),
108 static const struct snd_soc_dapm_route trimslice_audio_map[] = {
109 {"Line Out", NULL, "LOUT"},
110 {"Line Out", NULL, "ROUT"},
112 {"LLINEIN", NULL, "Line In"},
113 {"RLINEIN", NULL, "Line In"},
116 static struct snd_soc_dai_link trimslice_tlv320aic23_dai = {
117 .name = "TLV320AIC23",
118 .stream_name = "AIC23",
119 .codec_name = "tlv320aic23-codec.2-001a",
120 .platform_name = "tegra20-i2s.0",
121 .cpu_dai_name = "tegra20-i2s.0",
122 .codec_dai_name = "tlv320aic23-hifi",
123 .ops = &trimslice_asoc_ops,
126 static struct snd_soc_card snd_soc_trimslice = {
127 .name = "tegra-trimslice",
128 .owner = THIS_MODULE,
129 .dai_link = &trimslice_tlv320aic23_dai,
132 .dapm_widgets = trimslice_dapm_widgets,
133 .num_dapm_widgets = ARRAY_SIZE(trimslice_dapm_widgets),
134 .dapm_routes = trimslice_audio_map,
135 .num_dapm_routes = ARRAY_SIZE(trimslice_audio_map),
136 .fully_routed = true,
139 static __devinit int tegra_snd_trimslice_probe(struct platform_device *pdev)
141 struct snd_soc_card *card = &snd_soc_trimslice;
142 struct tegra_trimslice *trimslice;
145 trimslice = devm_kzalloc(&pdev->dev, sizeof(struct tegra_trimslice),
148 dev_err(&pdev->dev, "Can't allocate tegra_trimslice\n");
153 if (pdev->dev.of_node) {
154 trimslice_tlv320aic23_dai.codec_name = NULL;
155 trimslice_tlv320aic23_dai.codec_of_node = of_parse_phandle(
156 pdev->dev.of_node, "nvidia,audio-codec", 0);
157 if (!trimslice_tlv320aic23_dai.codec_of_node) {
159 "Property 'nvidia,audio-codec' missing or invalid\n");
164 trimslice_tlv320aic23_dai.cpu_dai_name = NULL;
165 trimslice_tlv320aic23_dai.cpu_dai_of_node = of_parse_phandle(
166 pdev->dev.of_node, "nvidia,i2s-controller", 0);
167 if (!trimslice_tlv320aic23_dai.cpu_dai_of_node) {
169 "Property 'nvidia,i2s-controller' missing or invalid\n");
174 trimslice_tlv320aic23_dai.platform_name = NULL;
175 trimslice_tlv320aic23_dai.platform_of_node =
176 trimslice_tlv320aic23_dai.cpu_dai_of_node;
179 ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev);
183 card->dev = &pdev->dev;
184 platform_set_drvdata(pdev, card);
185 snd_soc_card_set_drvdata(card, trimslice);
187 ret = snd_soc_register_card(card);
189 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
197 tegra_asoc_utils_fini(&trimslice->util_data);
202 static int __devexit tegra_snd_trimslice_remove(struct platform_device *pdev)
204 struct snd_soc_card *card = platform_get_drvdata(pdev);
205 struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
207 snd_soc_unregister_card(card);
209 tegra_asoc_utils_fini(&trimslice->util_data);
214 static const struct of_device_id trimslice_of_match[] __devinitconst = {
215 { .compatible = "nvidia,tegra-audio-trimslice", },
218 MODULE_DEVICE_TABLE(of, trimslice_of_match);
220 static struct platform_driver tegra_snd_trimslice_driver = {
223 .owner = THIS_MODULE,
224 .of_match_table = trimslice_of_match,
226 .probe = tegra_snd_trimslice_probe,
227 .remove = __devexit_p(tegra_snd_trimslice_remove),
229 module_platform_driver(tegra_snd_trimslice_driver);
231 MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
232 MODULE_DESCRIPTION("Trimslice machine ASoC driver");
233 MODULE_LICENSE("GPL");
234 MODULE_ALIAS("platform:" DRV_NAME);