blob: 05c68aab5cf0a9a8e06a7fb93f27cd2b0d3cf3e0 [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",
Mike Rapoport13073942011-04-26 11:52:42 +0300100 .codec_dai_name = "tlv320aic23-hifi",
Mike Rapoport13073942011-04-26 11:52:42 +0300101 .ops = &trimslice_asoc_ops,
Stephen Warren408dafc2012-06-06 17:15:48 -0600102 .dai_fmt = SND_SOC_DAIFMT_I2S |
103 SND_SOC_DAIFMT_NB_NF |
104 SND_SOC_DAIFMT_CBS_CFS,
Mike Rapoport13073942011-04-26 11:52:42 +0300105};
106
107static struct snd_soc_card snd_soc_trimslice = {
108 .name = "tegra-trimslice",
Axel Linb16eaf92011-12-22 21:23:01 +0800109 .owner = THIS_MODULE,
Mike Rapoport13073942011-04-26 11:52:42 +0300110 .dai_link = &trimslice_tlv320aic23_dai,
111 .num_links = 1,
112
113 .dapm_widgets = trimslice_dapm_widgets,
114 .num_dapm_widgets = ARRAY_SIZE(trimslice_dapm_widgets),
115 .dapm_routes = trimslice_audio_map,
116 .num_dapm_routes = ARRAY_SIZE(trimslice_audio_map),
Stephen Warren504855d2011-11-23 12:42:06 -0700117 .fully_routed = true,
Mike Rapoport13073942011-04-26 11:52:42 +0300118};
119
Bill Pemberton4652a0d2012-12-07 09:26:33 -0500120static int tegra_snd_trimslice_probe(struct platform_device *pdev)
Mike Rapoport13073942011-04-26 11:52:42 +0300121{
Stephen Warrenbd85a062013-02-15 17:07:34 -0700122 struct device_node *np = pdev->dev.of_node;
Mike Rapoport13073942011-04-26 11:52:42 +0300123 struct snd_soc_card *card = &snd_soc_trimslice;
124 struct tegra_trimslice *trimslice;
125 int ret;
126
Stephen Warren45c26092011-11-22 18:21:21 -0700127 trimslice = devm_kzalloc(&pdev->dev, sizeof(struct tegra_trimslice),
128 GFP_KERNEL);
Mike Rapoport13073942011-04-26 11:52:42 +0300129 if (!trimslice) {
130 dev_err(&pdev->dev, "Can't allocate tegra_trimslice\n");
Stephen Warrenbd85a062013-02-15 17:07:34 -0700131 return -ENOMEM;
Mike Rapoport13073942011-04-26 11:52:42 +0300132 }
133
Mike Rapoport13073942011-04-26 11:52:42 +0300134 card->dev = &pdev->dev;
135 platform_set_drvdata(pdev, card);
136 snd_soc_card_set_drvdata(card, trimslice);
137
Stephen Warrenbd85a062013-02-15 17:07:34 -0700138 trimslice_tlv320aic23_dai.codec_of_node = of_parse_phandle(np,
139 "nvidia,audio-codec", 0);
140 if (!trimslice_tlv320aic23_dai.codec_of_node) {
141 dev_err(&pdev->dev,
142 "Property 'nvidia,audio-codec' missing or invalid\n");
143 ret = -EINVAL;
144 goto err;
145 }
146
147 trimslice_tlv320aic23_dai.cpu_of_node = of_parse_phandle(np,
148 "nvidia,i2s-controller", 0);
149 if (!trimslice_tlv320aic23_dai.cpu_of_node) {
150 dev_err(&pdev->dev,
151 "Property 'nvidia,i2s-controller' missing or invalid\n");
152 ret = -EINVAL;
153 goto err;
154 }
155
156 trimslice_tlv320aic23_dai.platform_of_node =
157 trimslice_tlv320aic23_dai.cpu_of_node;
158
159 ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev);
160 if (ret)
161 goto err;
162
Mike Rapoport13073942011-04-26 11:52:42 +0300163 ret = snd_soc_register_card(card);
164 if (ret) {
165 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
166 ret);
167 goto err_fini_utils;
168 }
169
170 return 0;
171
172err_fini_utils:
173 tegra_asoc_utils_fini(&trimslice->util_data);
Stephen Warren45c26092011-11-22 18:21:21 -0700174err:
Mike Rapoport13073942011-04-26 11:52:42 +0300175 return ret;
176}
177
Bill Pemberton4652a0d2012-12-07 09:26:33 -0500178static int tegra_snd_trimslice_remove(struct platform_device *pdev)
Mike Rapoport13073942011-04-26 11:52:42 +0300179{
180 struct snd_soc_card *card = platform_get_drvdata(pdev);
181 struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
182
183 snd_soc_unregister_card(card);
184
185 tegra_asoc_utils_fini(&trimslice->util_data);
186
Mike Rapoport13073942011-04-26 11:52:42 +0300187 return 0;
188}
189
Bill Pembertonf6e65742012-11-19 13:25:33 -0500190static const struct of_device_id trimslice_of_match[] = {
Stephen Warren6264f662012-04-27 13:34:19 -0600191 { .compatible = "nvidia,tegra-audio-trimslice", },
192 {},
193};
194MODULE_DEVICE_TABLE(of, trimslice_of_match);
195
Mike Rapoport13073942011-04-26 11:52:42 +0300196static struct platform_driver tegra_snd_trimslice_driver = {
197 .driver = {
198 .name = DRV_NAME,
199 .owner = THIS_MODULE,
Stephen Warren6264f662012-04-27 13:34:19 -0600200 .of_match_table = trimslice_of_match,
Mike Rapoport13073942011-04-26 11:52:42 +0300201 },
202 .probe = tegra_snd_trimslice_probe,
Bill Pemberton4652a0d2012-12-07 09:26:33 -0500203 .remove = tegra_snd_trimslice_remove,
Mike Rapoport13073942011-04-26 11:52:42 +0300204};
Stephen Warren45c26092011-11-22 18:21:21 -0700205module_platform_driver(tegra_snd_trimslice_driver);
Mike Rapoport13073942011-04-26 11:52:42 +0300206
207MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
208MODULE_DESCRIPTION("Trimslice machine ASoC driver");
209MODULE_LICENSE("GPL");
210MODULE_ALIAS("platform:" DRV_NAME);