blob: 0fd115e69a8a729715fb21aed03931457d9eedc4 [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>
30#include <linux/platform_device.h>
31#include <linux/slab.h>
32
33#include <sound/core.h>
34#include <sound/jack.h>
35#include <sound/pcm.h>
36#include <sound/pcm_params.h>
37#include <sound/soc.h>
38
39#include "../codecs/tlv320aic23.h"
40
Mike Rapoport13073942011-04-26 11:52:42 +030041#include "tegra_asoc_utils.h"
42
43#define DRV_NAME "tegra-snd-trimslice"
44
45struct tegra_trimslice {
46 struct tegra_asoc_utils_data util_data;
47};
48
49static int trimslice_asoc_hw_params(struct snd_pcm_substream *substream,
50 struct snd_pcm_hw_params *params)
51{
52 struct snd_soc_pcm_runtime *rtd = substream->private_data;
53 struct snd_soc_dai *codec_dai = rtd->codec_dai;
54 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
55 struct snd_soc_codec *codec = rtd->codec;
56 struct snd_soc_card *card = codec->card;
57 struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
58 int srate, mclk;
59 int err;
60
61 srate = params_rate(params);
62 mclk = 128 * srate;
63
64 err = tegra_asoc_utils_set_rate(&trimslice->util_data, srate, mclk);
65 if (err < 0) {
66 dev_err(card->dev, "Can't configure clocks\n");
67 return err;
68 }
69
70 err = snd_soc_dai_set_fmt(codec_dai,
71 SND_SOC_DAIFMT_I2S |
72 SND_SOC_DAIFMT_NB_NF |
73 SND_SOC_DAIFMT_CBS_CFS);
74 if (err < 0) {
75 dev_err(card->dev, "codec_dai fmt not set\n");
76 return err;
77 }
78
79 err = snd_soc_dai_set_fmt(cpu_dai,
80 SND_SOC_DAIFMT_I2S |
81 SND_SOC_DAIFMT_NB_NF |
82 SND_SOC_DAIFMT_CBS_CFS);
83 if (err < 0) {
84 dev_err(card->dev, "cpu_dai fmt not set\n");
85 return err;
86 }
87
88 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
89 SND_SOC_CLOCK_IN);
90 if (err < 0) {
91 dev_err(card->dev, "codec_dai clock not set\n");
92 return err;
93 }
94
95 return 0;
96}
97
98static struct snd_soc_ops trimslice_asoc_ops = {
99 .hw_params = trimslice_asoc_hw_params,
100};
101
102static const struct snd_soc_dapm_widget trimslice_dapm_widgets[] = {
103 SND_SOC_DAPM_HP("Line Out", NULL),
104 SND_SOC_DAPM_LINE("Line In", NULL),
105};
106
107static const struct snd_soc_dapm_route trimslice_audio_map[] = {
108 {"Line Out", NULL, "LOUT"},
109 {"Line Out", NULL, "ROUT"},
110
111 {"LLINEIN", NULL, "Line In"},
112 {"RLINEIN", NULL, "Line In"},
113};
114
Mike Rapoport13073942011-04-26 11:52:42 +0300115static struct snd_soc_dai_link trimslice_tlv320aic23_dai = {
116 .name = "TLV320AIC23",
117 .stream_name = "AIC23",
118 .codec_name = "tlv320aic23-codec.2-001a",
Stephen Warren896637a2012-04-06 10:30:52 -0600119 .platform_name = "tegra20-i2s.0",
120 .cpu_dai_name = "tegra20-i2s.0",
Mike Rapoport13073942011-04-26 11:52:42 +0300121 .codec_dai_name = "tlv320aic23-hifi",
Mike Rapoport13073942011-04-26 11:52:42 +0300122 .ops = &trimslice_asoc_ops,
123};
124
125static struct snd_soc_card snd_soc_trimslice = {
126 .name = "tegra-trimslice",
Axel Linb16eaf92011-12-22 21:23:01 +0800127 .owner = THIS_MODULE,
Mike Rapoport13073942011-04-26 11:52:42 +0300128 .dai_link = &trimslice_tlv320aic23_dai,
129 .num_links = 1,
130
131 .dapm_widgets = trimslice_dapm_widgets,
132 .num_dapm_widgets = ARRAY_SIZE(trimslice_dapm_widgets),
133 .dapm_routes = trimslice_audio_map,
134 .num_dapm_routes = ARRAY_SIZE(trimslice_audio_map),
Stephen Warren504855d2011-11-23 12:42:06 -0700135 .fully_routed = true,
Mike Rapoport13073942011-04-26 11:52:42 +0300136};
137
138static __devinit int tegra_snd_trimslice_probe(struct platform_device *pdev)
139{
140 struct snd_soc_card *card = &snd_soc_trimslice;
141 struct tegra_trimslice *trimslice;
142 int ret;
143
Stephen Warren45c26092011-11-22 18:21:21 -0700144 trimslice = devm_kzalloc(&pdev->dev, sizeof(struct tegra_trimslice),
145 GFP_KERNEL);
Mike Rapoport13073942011-04-26 11:52:42 +0300146 if (!trimslice) {
147 dev_err(&pdev->dev, "Can't allocate tegra_trimslice\n");
Stephen Warren45c26092011-11-22 18:21:21 -0700148 ret = -ENOMEM;
149 goto err;
Mike Rapoport13073942011-04-26 11:52:42 +0300150 }
151
152 ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev);
153 if (ret)
Stephen Warren45c26092011-11-22 18:21:21 -0700154 goto err;
Mike Rapoport13073942011-04-26 11:52:42 +0300155
156 card->dev = &pdev->dev;
157 platform_set_drvdata(pdev, card);
158 snd_soc_card_set_drvdata(card, trimslice);
159
160 ret = snd_soc_register_card(card);
161 if (ret) {
162 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
163 ret);
164 goto err_fini_utils;
165 }
166
167 return 0;
168
169err_fini_utils:
170 tegra_asoc_utils_fini(&trimslice->util_data);
Stephen Warren45c26092011-11-22 18:21:21 -0700171err:
Mike Rapoport13073942011-04-26 11:52:42 +0300172 return ret;
173}
174
175static int __devexit tegra_snd_trimslice_remove(struct platform_device *pdev)
176{
177 struct snd_soc_card *card = platform_get_drvdata(pdev);
178 struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
179
180 snd_soc_unregister_card(card);
181
182 tegra_asoc_utils_fini(&trimslice->util_data);
183
Mike Rapoport13073942011-04-26 11:52:42 +0300184 return 0;
185}
186
187static struct platform_driver tegra_snd_trimslice_driver = {
188 .driver = {
189 .name = DRV_NAME,
190 .owner = THIS_MODULE,
191 },
192 .probe = tegra_snd_trimslice_probe,
193 .remove = __devexit_p(tegra_snd_trimslice_remove),
194};
Stephen Warren45c26092011-11-22 18:21:21 -0700195module_platform_driver(tegra_snd_trimslice_driver);
Mike Rapoport13073942011-04-26 11:52:42 +0300196
197MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
198MODULE_DESCRIPTION("Trimslice machine ASoC driver");
199MODULE_LICENSE("GPL");
200MODULE_ALIAS("platform:" DRV_NAME);