blob: 4a255a4d0c47556b667b05099bfc33c998257d5f [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;
Stephen Warren40db77a2012-06-06 17:15:49 -060055 struct snd_soc_codec *codec = codec_dai->codec;
Mike Rapoport13073942011-04-26 11:52:42 +030056 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
Mike Rapoport13073942011-04-26 11:52:42 +030070 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
71 SND_SOC_CLOCK_IN);
72 if (err < 0) {
73 dev_err(card->dev, "codec_dai clock not set\n");
74 return err;
75 }
76
77 return 0;
78}
79
80static struct snd_soc_ops trimslice_asoc_ops = {
81 .hw_params = trimslice_asoc_hw_params,
82};
83
84static const struct snd_soc_dapm_widget trimslice_dapm_widgets[] = {
85 SND_SOC_DAPM_HP("Line Out", NULL),
86 SND_SOC_DAPM_LINE("Line In", NULL),
87};
88
89static const struct snd_soc_dapm_route trimslice_audio_map[] = {
90 {"Line Out", NULL, "LOUT"},
91 {"Line Out", NULL, "ROUT"},
92
93 {"LLINEIN", NULL, "Line In"},
94 {"RLINEIN", NULL, "Line In"},
95};
96
Mike Rapoport13073942011-04-26 11:52:42 +030097static struct snd_soc_dai_link trimslice_tlv320aic23_dai = {
98 .name = "TLV320AIC23",
99 .stream_name = "AIC23",
100 .codec_name = "tlv320aic23-codec.2-001a",
Stephen Warren896637a2012-04-06 10:30:52 -0600101 .platform_name = "tegra20-i2s.0",
102 .cpu_dai_name = "tegra20-i2s.0",
Mike Rapoport13073942011-04-26 11:52:42 +0300103 .codec_dai_name = "tlv320aic23-hifi",
Mike Rapoport13073942011-04-26 11:52:42 +0300104 .ops = &trimslice_asoc_ops,
Stephen Warren408dafc2012-06-06 17:15:48 -0600105 .dai_fmt = SND_SOC_DAIFMT_I2S |
106 SND_SOC_DAIFMT_NB_NF |
107 SND_SOC_DAIFMT_CBS_CFS,
Mike Rapoport13073942011-04-26 11:52:42 +0300108};
109
110static struct snd_soc_card snd_soc_trimslice = {
111 .name = "tegra-trimslice",
Axel Linb16eaf92011-12-22 21:23:01 +0800112 .owner = THIS_MODULE,
Mike Rapoport13073942011-04-26 11:52:42 +0300113 .dai_link = &trimslice_tlv320aic23_dai,
114 .num_links = 1,
115
116 .dapm_widgets = trimslice_dapm_widgets,
117 .num_dapm_widgets = ARRAY_SIZE(trimslice_dapm_widgets),
118 .dapm_routes = trimslice_audio_map,
119 .num_dapm_routes = ARRAY_SIZE(trimslice_audio_map),
Stephen Warren504855d2011-11-23 12:42:06 -0700120 .fully_routed = true,
Mike Rapoport13073942011-04-26 11:52:42 +0300121};
122
123static __devinit int tegra_snd_trimslice_probe(struct platform_device *pdev)
124{
125 struct snd_soc_card *card = &snd_soc_trimslice;
126 struct tegra_trimslice *trimslice;
127 int ret;
128
Stephen Warren45c26092011-11-22 18:21:21 -0700129 trimslice = devm_kzalloc(&pdev->dev, sizeof(struct tegra_trimslice),
130 GFP_KERNEL);
Mike Rapoport13073942011-04-26 11:52:42 +0300131 if (!trimslice) {
132 dev_err(&pdev->dev, "Can't allocate tegra_trimslice\n");
Stephen Warren45c26092011-11-22 18:21:21 -0700133 ret = -ENOMEM;
134 goto err;
Mike Rapoport13073942011-04-26 11:52:42 +0300135 }
136
Stephen Warren6264f662012-04-27 13:34:19 -0600137 if (pdev->dev.of_node) {
138 trimslice_tlv320aic23_dai.codec_name = NULL;
139 trimslice_tlv320aic23_dai.codec_of_node = of_parse_phandle(
140 pdev->dev.of_node, "nvidia,audio-codec", 0);
141 if (!trimslice_tlv320aic23_dai.codec_of_node) {
142 dev_err(&pdev->dev,
143 "Property 'nvidia,audio-codec' missing or invalid\n");
144 ret = -EINVAL;
145 goto err;
146 }
147
148 trimslice_tlv320aic23_dai.cpu_dai_name = NULL;
Stephen Warrenbc926572012-05-25 18:22:11 -0600149 trimslice_tlv320aic23_dai.cpu_of_node = of_parse_phandle(
Stephen Warren6264f662012-04-27 13:34:19 -0600150 pdev->dev.of_node, "nvidia,i2s-controller", 0);
Stephen Warrenbc926572012-05-25 18:22:11 -0600151 if (!trimslice_tlv320aic23_dai.cpu_of_node) {
Stephen Warren6264f662012-04-27 13:34:19 -0600152 dev_err(&pdev->dev,
153 "Property 'nvidia,i2s-controller' missing or invalid\n");
154 ret = -EINVAL;
155 goto err;
156 }
157
158 trimslice_tlv320aic23_dai.platform_name = NULL;
159 trimslice_tlv320aic23_dai.platform_of_node =
Stephen Warrenbc926572012-05-25 18:22:11 -0600160 trimslice_tlv320aic23_dai.cpu_of_node;
Stephen Warren6264f662012-04-27 13:34:19 -0600161 }
162
Mike Rapoport13073942011-04-26 11:52:42 +0300163 ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev);
164 if (ret)
Stephen Warren45c26092011-11-22 18:21:21 -0700165 goto err;
Mike Rapoport13073942011-04-26 11:52:42 +0300166
167 card->dev = &pdev->dev;
168 platform_set_drvdata(pdev, card);
169 snd_soc_card_set_drvdata(card, trimslice);
170
171 ret = snd_soc_register_card(card);
172 if (ret) {
173 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
174 ret);
175 goto err_fini_utils;
176 }
177
178 return 0;
179
180err_fini_utils:
181 tegra_asoc_utils_fini(&trimslice->util_data);
Stephen Warren45c26092011-11-22 18:21:21 -0700182err:
Mike Rapoport13073942011-04-26 11:52:42 +0300183 return ret;
184}
185
186static int __devexit tegra_snd_trimslice_remove(struct platform_device *pdev)
187{
188 struct snd_soc_card *card = platform_get_drvdata(pdev);
189 struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
190
191 snd_soc_unregister_card(card);
192
193 tegra_asoc_utils_fini(&trimslice->util_data);
194
Mike Rapoport13073942011-04-26 11:52:42 +0300195 return 0;
196}
197
Bill Pembertonf6e65742012-11-19 13:25:33 -0500198static const struct of_device_id trimslice_of_match[] = {
Stephen Warren6264f662012-04-27 13:34:19 -0600199 { .compatible = "nvidia,tegra-audio-trimslice", },
200 {},
201};
202MODULE_DEVICE_TABLE(of, trimslice_of_match);
203
Mike Rapoport13073942011-04-26 11:52:42 +0300204static struct platform_driver tegra_snd_trimslice_driver = {
205 .driver = {
206 .name = DRV_NAME,
207 .owner = THIS_MODULE,
Stephen Warren6264f662012-04-27 13:34:19 -0600208 .of_match_table = trimslice_of_match,
Mike Rapoport13073942011-04-26 11:52:42 +0300209 },
210 .probe = tegra_snd_trimslice_probe,
211 .remove = __devexit_p(tegra_snd_trimslice_remove),
212};
Stephen Warren45c26092011-11-22 18:21:21 -0700213module_platform_driver(tegra_snd_trimslice_driver);
Mike Rapoport13073942011-04-26 11:52:42 +0300214
215MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
216MODULE_DESCRIPTION("Trimslice machine ASoC driver");
217MODULE_LICENSE("GPL");
218MODULE_ALIAS("platform:" DRV_NAME);