2 * ASoC Driver for AudioSense add on soundcard
4 * Bhargav A K <anur.bhargav@gmail.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
17 #include <linux/module.h>
18 #include <linux/platform_device.h>
19 #include <linux/clk.h>
20 #include <linux/i2c.h>
21 #include <sound/core.h>
22 #include <sound/pcm.h>
23 #include <sound/pcm_params.h>
24 #include <sound/soc.h>
25 #include <sound/jack.h>
26 #include <sound/control.h>
28 #include <sound/tlv320aic32x4.h>
29 #include "../codecs/tlv320aic32x4.h"
31 #define AIC32X4_SYSCLK_XTAL 0x00
34 * Setup Codec Sample Rates and Channels
36 * 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, 96000,
38 static const unsigned int audiosense_pi_rate[] = {
42 static struct snd_pcm_hw_constraint_list audiosense_constraints_rates = {
43 .list = audiosense_pi_rate,
44 .count = ARRAY_SIZE(audiosense_pi_rate),
47 static const unsigned int audiosense_pi_channels[] = {
51 static struct snd_pcm_hw_constraint_list audiosense_constraints_ch = {
52 .count = ARRAY_SIZE(audiosense_pi_channels),
53 .list = audiosense_pi_channels,
57 /* Setup DAPM widgets and paths */
58 static const struct snd_soc_dapm_widget audiosense_pi_dapm_widgets[] = {
59 SND_SOC_DAPM_HP("Headphone Jack", NULL),
60 SND_SOC_DAPM_LINE("Line Out", NULL),
61 SND_SOC_DAPM_LINE("Line In", NULL),
62 SND_SOC_DAPM_INPUT("CM_L"),
63 SND_SOC_DAPM_INPUT("CM_R"),
66 static const struct snd_soc_dapm_route audiosense_pi_audio_map[] = {
67 /* Line Inputs are connected to
72 {"IN1_L", NULL, "Line In"},
73 {"IN1_R", NULL, "Line In"},
74 {"IN2_L", NULL, "Line In"},
75 {"IN2_R", NULL, "Line In"},
76 {"IN3_L", NULL, "Line In"},
77 {"IN3_R", NULL, "Line In"},
79 /* Mic is connected to IN2_L and IN2_R */
80 {"Left ADC", NULL, "Mic Bias"},
81 {"Right ADC", NULL, "Mic Bias"},
83 /* Headphone connected to HPL, HPR */
84 {"Headphone Jack", NULL, "HPL"},
85 {"Headphone Jack", NULL, "HPR"},
87 /* Speakers connected to LOL and LOR */
88 {"Line Out", NULL, "LOL"},
89 {"Line Out", NULL, "LOR"},
92 static int audiosense_pi_card_init(struct snd_soc_pcm_runtime *rtd)
94 /* TODO: init of the codec specific dapm data, ignore suspend/resume */
95 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
97 snd_soc_component_update_bits(component, AIC32X4_MICBIAS, 0x78,
98 AIC32X4_MICBIAS_LDOIN |
99 AIC32X4_MICBIAS_2075V);
100 snd_soc_component_update_bits(component, AIC32X4_PWRCFG, 0x08,
101 AIC32X4_AVDDWEAKDISABLE);
102 snd_soc_component_update_bits(component, AIC32X4_LDOCTL, 0x01,
108 static int audiosense_pi_card_hw_params(
109 struct snd_pcm_substream *substream,
110 struct snd_pcm_hw_params *params)
113 struct snd_soc_pcm_runtime *rtd = substream->private_data;
114 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
116 /* Set the codec system clock, there is a 12 MHz XTAL on the board */
117 ret = snd_soc_dai_set_sysclk(codec_dai, AIC32X4_SYSCLK_XTAL,
118 12000000, SND_SOC_CLOCK_IN);
120 dev_err(rtd->card->dev,
121 "could not set codec driver clock params\n");
127 static int audiosense_pi_card_startup(struct snd_pcm_substream *substream)
129 struct snd_pcm_runtime *runtime = substream->runtime;
132 * Set codec to 48Khz Sampling, Stereo I/O and 16 bit audio
134 runtime->hw.channels_max = 2;
135 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
136 &audiosense_constraints_ch);
138 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
139 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
142 snd_pcm_hw_constraint_list(substream->runtime, 0,
143 SNDRV_PCM_HW_PARAM_RATE,
144 &audiosense_constraints_rates);
148 static struct snd_soc_ops audiosense_pi_card_ops = {
149 .startup = audiosense_pi_card_startup,
150 .hw_params = audiosense_pi_card_hw_params,
153 SND_SOC_DAILINK_DEFS(audiosense_pi,
154 DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
155 DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic32x4.1-0018", "tlv320aic32x4-hifi")),
156 DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
158 static struct snd_soc_dai_link audiosense_pi_card_dai[] = {
160 .name = "TLV320AIC3204 Audio",
161 .stream_name = "TLV320AIC3204 Hifi Audio",
162 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
163 SND_SOC_DAIFMT_CBM_CFM,
164 .ops = &audiosense_pi_card_ops,
165 .init = audiosense_pi_card_init,
166 SND_SOC_DAILINK_REG(audiosense_pi),
170 static struct snd_soc_card audiosense_pi_card = {
171 .name = "audiosense-pi",
172 .driver_name = "audiosense-pi",
173 .dai_link = audiosense_pi_card_dai,
174 .owner = THIS_MODULE,
175 .num_links = ARRAY_SIZE(audiosense_pi_card_dai),
176 .dapm_widgets = audiosense_pi_dapm_widgets,
177 .num_dapm_widgets = ARRAY_SIZE(audiosense_pi_dapm_widgets),
178 .dapm_routes = audiosense_pi_audio_map,
179 .num_dapm_routes = ARRAY_SIZE(audiosense_pi_audio_map),
182 static int audiosense_pi_card_probe(struct platform_device *pdev)
185 struct snd_soc_card *card = &audiosense_pi_card;
186 struct snd_soc_dai_link *dai = &audiosense_pi_card_dai[0];
187 struct device_node *i2s_node = pdev->dev.of_node;
189 card->dev = &pdev->dev;
192 dev_err(&pdev->dev, "DAI not found. Missing or Invalid\n");
196 i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
199 "Property 'i2s-controller' missing or invalid\n");
203 dai->cpus->dai_name = NULL;
204 dai->cpus->of_node = i2s_node;
205 dai->platforms->name = NULL;
206 dai->platforms->of_node = i2s_node;
208 of_node_put(i2s_node);
210 ret = snd_soc_register_card(card);
211 if (ret && ret != -EPROBE_DEFER)
213 "snd_soc_register_card() failed: %d\n", ret);
218 static int audiosense_pi_card_remove(struct platform_device *pdev)
220 struct snd_soc_card *card = platform_get_drvdata(pdev);
222 snd_soc_unregister_card(card);
226 static const struct of_device_id audiosense_pi_card_of_match[] = {
227 { .compatible = "as,audiosense-pi", },
230 MODULE_DEVICE_TABLE(of, audiosense_pi_card_of_match);
232 static struct platform_driver audiosense_pi_card_driver = {
234 .name = "audiosense-snd-card",
235 .owner = THIS_MODULE,
236 .of_match_table = audiosense_pi_card_of_match,
238 .probe = audiosense_pi_card_probe,
239 .remove = audiosense_pi_card_remove,
242 module_platform_driver(audiosense_pi_card_driver);
244 MODULE_AUTHOR("Bhargav AK <anur.bhargav@gmail.com>");
245 MODULE_DESCRIPTION("ASoC Driver for TLV320AIC3204 Audio");
246 MODULE_LICENSE("GPL v2");
247 MODULE_ALIAS("platform:audiosense-pi");