blob: 5815430e8521d6d0ad4a2763cb5c8949578aacf5 [file] [log] [blame]
Mike Rapoport13073942011-04-26 11:52:42 +03001/*
2 * trimslice.c - TrimSlice machine ASoC driver
3 *
4 * Copyright (C) 2011 - CompuLab, Ltd.
5 * Author: Mike Rapoport <mike@compulab.co.il>
6 *
7 * Based on code copyright/by:
8 * Author: Stephen Warren <swarren@nvidia.com>
9 * Copyright (C) 2010-2011 - NVIDIA, Inc.
10 *
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.
14 *
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.
19 *
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
23 * 02110-1301 USA
24 *
25 */
26
27#include <asm/mach-types.h>
28
29#include <linux/module.h>
Stephen Warren6264f662012-04-27 13:34:19 -060030#include <linux/of.h>
Mike Rapoport13073942011-04-26 11:52:42 +030031#include <linux/platform_device.h>
32#include <linux/slab.h>
33
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>
39
40#include "../codecs/tlv320aic23.h"
41
Mike Rapoport13073942011-04-26 11:52:42 +030042#include "tegra_asoc_utils.h"
43
44#define DRV_NAME "tegra-snd-trimslice"
45
46struct tegra_trimslice {
47 struct tegra_asoc_utils_data util_data;
48};
49
50static int trimslice_asoc_hw_params(struct snd_pcm_substream *substream,
51 struct snd_pcm_hw_params *params)
52{
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);
59 int srate, mclk;
60 int err;
61
62 srate = params_rate(params);
63 mclk = 128 * srate;
64
65 err = tegra_asoc_utils_set_rate(&trimslice->util_data, srate, mclk);
66 if (err < 0) {
67 dev_err(card->dev, "Can't configure clocks\n");
68 return err;
69 }
70
71 err = snd_soc_dai_set_fmt(codec_dai,
72 SND_SOC_DAIFMT_I2S |
73 SND_SOC_DAIFMT_NB_NF |
74 SND_SOC_DAIFMT_CBS_CFS);
75 if (err < 0) {
76 dev_err(card->dev, "codec_dai fmt not set\n");
77 return err;
78 }
79
80 err = snd_soc_dai_set_fmt(cpu_dai,
81 SND_SOC_DAIFMT_I2S |
82 SND_SOC_DAIFMT_NB_NF |
83 SND_SOC_DAIFMT_CBS_CFS);
84 if (err < 0) {
85 dev_err(card->dev, "cpu_dai fmt not set\n");
86 return err;
87 }
88
89 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
90 SND_SOC_CLOCK_IN);
91 if (err < 0) {
92 dev_err(card->dev, "codec_dai clock not set\n");
93 return err;
94 }
95
96 return 0;
97}
98
99static struct snd_soc_ops trimslice_asoc_ops = {
100 .hw_params = trimslice_asoc_hw_params,
101};
102
103static 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),
106};
107
108static const struct snd_soc_dapm_route trimslice_audio_map[] = {
109 {"Line Out", NULL, "LOUT"},
110 {"Line Out", NULL, "ROUT"},
111
112 {"LLINEIN", NULL, "Line In"},
113 {"RLINEIN", NULL, "Line In"},
114};
115
Mike Rapoport13073942011-04-26 11:52:42 +0300116static struct snd_soc_dai_link trimslice_tlv320aic23_dai = {
117 .name = "TLV320AIC23",
118 .stream_name = "AIC23",
119 .codec_name = "tlv320aic23-codec.2-001a",
Stephen Warren896637a2012-04-06 10:30:52 -0600120 .platform_name = "tegra20-i2s.0",
121 .cpu_dai_name = "tegra20-i2s.0",
Mike Rapoport13073942011-04-26 11:52:42 +0300122 .codec_dai_name = "tlv320aic23-hifi",
Mike Rapoport13073942011-04-26 11:52:42 +0300123 .ops = &trimslice_asoc_ops,
124};
125
126static struct snd_soc_card snd_soc_trimslice = {
127 .name = "tegra-trimslice",
Axel Linb16eaf92011-12-22 21:23:01 +0800128 .owner = THIS_MODULE,
Mike Rapoport13073942011-04-26 11:52:42 +0300129 .dai_link = &trimslice_tlv320aic23_dai,
130 .num_links = 1,
131
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),
Stephen Warren504855d2011-11-23 12:42:06 -0700136 .fully_routed = true,
Mike Rapoport13073942011-04-26 11:52:42 +0300137};
138
139static __devinit int tegra_snd_trimslice_probe(struct platform_device *pdev)
140{
141 struct snd_soc_card *card = &snd_soc_trimslice;
142 struct tegra_trimslice *trimslice;
143 int ret;
144
Stephen Warren45c26092011-11-22 18:21:21 -0700145 trimslice = devm_kzalloc(&pdev->dev, sizeof(struct tegra_trimslice),
146 GFP_KERNEL);
Mike Rapoport13073942011-04-26 11:52:42 +0300147 if (!trimslice) {
148 dev_err(&pdev->dev, "Can't allocate tegra_trimslice\n");
Stephen Warren45c26092011-11-22 18:21:21 -0700149 ret = -ENOMEM;
150 goto err;
Mike Rapoport13073942011-04-26 11:52:42 +0300151 }
152
Stephen Warren6264f662012-04-27 13:34:19 -0600153 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) {
158 dev_err(&pdev->dev,
159 "Property 'nvidia,audio-codec' missing or invalid\n");
160 ret = -EINVAL;
161 goto err;
162 }
163
164 trimslice_tlv320aic23_dai.cpu_dai_name = NULL;
Stephen Warrenbc926572012-05-25 18:22:11 -0600165 trimslice_tlv320aic23_dai.cpu_of_node = of_parse_phandle(
Stephen Warren6264f662012-04-27 13:34:19 -0600166 pdev->dev.of_node, "nvidia,i2s-controller", 0);
Stephen Warrenbc926572012-05-25 18:22:11 -0600167 if (!trimslice_tlv320aic23_dai.cpu_of_node) {
Stephen Warren6264f662012-04-27 13:34:19 -0600168 dev_err(&pdev->dev,
169 "Property 'nvidia,i2s-controller' missing or invalid\n");
170 ret = -EINVAL;
171 goto err;
172 }
173
174 trimslice_tlv320aic23_dai.platform_name = NULL;
175 trimslice_tlv320aic23_dai.platform_of_node =
Stephen Warrenbc926572012-05-25 18:22:11 -0600176 trimslice_tlv320aic23_dai.cpu_of_node;
Stephen Warren6264f662012-04-27 13:34:19 -0600177 }
178
Mike Rapoport13073942011-04-26 11:52:42 +0300179 ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev);
180 if (ret)
Stephen Warren45c26092011-11-22 18:21:21 -0700181 goto err;
Mike Rapoport13073942011-04-26 11:52:42 +0300182
183 card->dev = &pdev->dev;
184 platform_set_drvdata(pdev, card);
185 snd_soc_card_set_drvdata(card, trimslice);
186
187 ret = snd_soc_register_card(card);
188 if (ret) {
189 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
190 ret);
191 goto err_fini_utils;
192 }
193
194 return 0;
195
196err_fini_utils:
197 tegra_asoc_utils_fini(&trimslice->util_data);
Stephen Warren45c26092011-11-22 18:21:21 -0700198err:
Mike Rapoport13073942011-04-26 11:52:42 +0300199 return ret;
200}
201
202static int __devexit tegra_snd_trimslice_remove(struct platform_device *pdev)
203{
204 struct snd_soc_card *card = platform_get_drvdata(pdev);
205 struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
206
207 snd_soc_unregister_card(card);
208
209 tegra_asoc_utils_fini(&trimslice->util_data);
210
Mike Rapoport13073942011-04-26 11:52:42 +0300211 return 0;
212}
213
Stephen Warren6264f662012-04-27 13:34:19 -0600214static const struct of_device_id trimslice_of_match[] __devinitconst = {
215 { .compatible = "nvidia,tegra-audio-trimslice", },
216 {},
217};
218MODULE_DEVICE_TABLE(of, trimslice_of_match);
219
Mike Rapoport13073942011-04-26 11:52:42 +0300220static struct platform_driver tegra_snd_trimslice_driver = {
221 .driver = {
222 .name = DRV_NAME,
223 .owner = THIS_MODULE,
Stephen Warren6264f662012-04-27 13:34:19 -0600224 .of_match_table = trimslice_of_match,
Mike Rapoport13073942011-04-26 11:52:42 +0300225 },
226 .probe = tegra_snd_trimslice_probe,
227 .remove = __devexit_p(tegra_snd_trimslice_remove),
228};
Stephen Warren45c26092011-11-22 18:21:21 -0700229module_platform_driver(tegra_snd_trimslice_driver);
Mike Rapoport13073942011-04-26 11:52:42 +0300230
231MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
232MODULE_DESCRIPTION("Trimslice machine ASoC driver");
233MODULE_LICENSE("GPL");
234MODULE_ALIAS("platform:" DRV_NAME);