2 * n810.c -- SoC audio for Nokia N810
4 * Copyright (C) 2008 Nokia Corporation
6 * Contact: Jarkko Nikula <jarkko.nikula@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #include <linux/clk.h>
25 #include <linux/platform_device.h>
26 #include <sound/core.h>
27 #include <sound/pcm.h>
28 #include <sound/soc.h>
29 #include <sound/soc-dapm.h>
31 #include <asm/mach-types.h>
32 #include <asm/arch/hardware.h>
33 #include <asm/arch/gpio.h>
34 #include <asm/arch/mcbsp.h>
36 #include "omap-mcbsp.h"
38 #include "../codecs/tlv320aic3x.h"
40 #define RX44_HEADSET_AMP_GPIO 10
41 #define RX44_SPEAKER_AMP_GPIO 101
43 static struct clk
*sys_clkout2
;
44 static struct clk
*sys_clkout2_src
;
45 static struct clk
*func96m_clk
;
47 static int n810_spk_func
;
48 static int n810_jack_func
;
50 static void n810_ext_control(struct snd_soc_codec
*codec
)
52 snd_soc_dapm_set_endpoint(codec
, "Ext Spk", n810_spk_func
);
53 snd_soc_dapm_set_endpoint(codec
, "Headphone Jack", n810_jack_func
);
55 snd_soc_dapm_sync_endpoints(codec
);
58 static int n810_startup(struct snd_pcm_substream
*substream
)
60 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
61 struct snd_soc_codec
*codec
= rtd
->socdev
->codec
;
63 n810_ext_control(codec
);
64 return clk_enable(sys_clkout2
);
67 static void n810_shutdown(struct snd_pcm_substream
*substream
)
69 clk_disable(sys_clkout2
);
72 static int n810_hw_params(struct snd_pcm_substream
*substream
,
73 struct snd_pcm_hw_params
*params
)
75 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
76 struct snd_soc_codec_dai
*codec_dai
= rtd
->dai
->codec_dai
;
77 struct snd_soc_cpu_dai
*cpu_dai
= rtd
->dai
->cpu_dai
;
80 /* Set codec DAI configuration */
81 err
= codec_dai
->dai_ops
.set_fmt(codec_dai
,
83 SND_SOC_DAIFMT_NB_NF
|
84 SND_SOC_DAIFMT_CBM_CFM
);
88 /* Set cpu DAI configuration */
89 err
= cpu_dai
->dai_ops
.set_fmt(cpu_dai
,
91 SND_SOC_DAIFMT_NB_NF
|
92 SND_SOC_DAIFMT_CBM_CFM
);
96 /* Set the codec system clock for DAC and ADC */
97 err
= codec_dai
->dai_ops
.set_sysclk(codec_dai
, 0, 12000000,
103 static struct snd_soc_ops n810_ops
= {
104 .startup
= n810_startup
,
105 .hw_params
= n810_hw_params
,
106 .shutdown
= n810_shutdown
,
109 static int n810_get_spk(struct snd_kcontrol
*kcontrol
,
110 struct snd_ctl_elem_value
*ucontrol
)
112 ucontrol
->value
.integer
.value
[0] = n810_spk_func
;
117 static int n810_set_spk(struct snd_kcontrol
*kcontrol
,
118 struct snd_ctl_elem_value
*ucontrol
)
120 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
122 if (n810_spk_func
== ucontrol
->value
.integer
.value
[0])
125 n810_spk_func
= ucontrol
->value
.integer
.value
[0];
126 n810_ext_control(codec
);
131 static int n810_get_jack(struct snd_kcontrol
*kcontrol
,
132 struct snd_ctl_elem_value
*ucontrol
)
134 ucontrol
->value
.integer
.value
[0] = n810_jack_func
;
139 static int n810_set_jack(struct snd_kcontrol
*kcontrol
,
140 struct snd_ctl_elem_value
*ucontrol
)
142 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
144 if (n810_jack_func
== ucontrol
->value
.integer
.value
[0])
147 n810_jack_func
= ucontrol
->value
.integer
.value
[0];
148 n810_ext_control(codec
);
153 static int n810_spk_event(struct snd_soc_dapm_widget
*w
,
154 struct snd_kcontrol
*k
, int event
)
156 if (SND_SOC_DAPM_EVENT_ON(event
))
157 omap_set_gpio_dataout(RX44_SPEAKER_AMP_GPIO
, 1);
159 omap_set_gpio_dataout(RX44_SPEAKER_AMP_GPIO
, 0);
164 static int n810_jack_event(struct snd_soc_dapm_widget
*w
,
165 struct snd_kcontrol
*k
, int event
)
167 if (SND_SOC_DAPM_EVENT_ON(event
))
168 omap_set_gpio_dataout(RX44_HEADSET_AMP_GPIO
, 1);
170 omap_set_gpio_dataout(RX44_HEADSET_AMP_GPIO
, 0);
175 static const struct snd_soc_dapm_widget aic33_dapm_widgets
[] = {
176 SND_SOC_DAPM_SPK("Ext Spk", n810_spk_event
),
177 SND_SOC_DAPM_HP("Headphone Jack", n810_jack_event
),
180 static const char *audio_map
[][3] = {
181 {"Headphone Jack", NULL
, "HPLOUT"},
182 {"Headphone Jack", NULL
, "HPROUT"},
184 {"Ext Spk", NULL
, "LLOUT"},
185 {"Ext Spk", NULL
, "RLOUT"},
188 static const char *spk_function
[] = {"Off", "On"};
189 static const char *jack_function
[] = {"Off", "Headphone"};
190 static const struct soc_enum n810_enum
[] = {
191 SOC_ENUM_SINGLE_EXT(2, spk_function
),
192 SOC_ENUM_SINGLE_EXT(3, jack_function
),
195 static const struct snd_kcontrol_new aic33_n810_controls
[] = {
196 SOC_ENUM_EXT("Speaker Function", n810_enum
[0],
197 n810_get_spk
, n810_set_spk
),
198 SOC_ENUM_EXT("Jack Function", n810_enum
[1],
199 n810_get_jack
, n810_set_jack
),
202 static int n810_aic33_init(struct snd_soc_codec
*codec
)
207 snd_soc_dapm_set_endpoint(codec
, "MONO_LOUT", 0);
208 snd_soc_dapm_set_endpoint(codec
, "HPLCOM", 0);
209 snd_soc_dapm_set_endpoint(codec
, "HPRCOM", 0);
211 /* Add N810 specific controls */
212 for (i
= 0; i
< ARRAY_SIZE(aic33_n810_controls
); i
++) {
213 err
= snd_ctl_add(codec
->card
,
214 snd_soc_cnew(&aic33_n810_controls
[i
], codec
, NULL
));
219 /* Add N810 specific widgets */
220 for (i
= 0; i
< ARRAY_SIZE(aic33_dapm_widgets
); i
++)
221 snd_soc_dapm_new_control(codec
, &aic33_dapm_widgets
[i
]);
223 /* Set up N810 specific audio path audio_map */
224 for (i
= 0; i
< ARRAY_SIZE(audio_map
); i
++)
225 snd_soc_dapm_connect_input(codec
, audio_map
[i
][0],
226 audio_map
[i
][1], audio_map
[i
][2]);
228 snd_soc_dapm_sync_endpoints(codec
);
233 /* Digital audio interface glue - connects codec <--> CPU */
234 static struct snd_soc_dai_link n810_dai
= {
235 .name
= "TLV320AIC33",
236 .stream_name
= "AIC33",
237 .cpu_dai
= &omap_mcbsp_dai
[0],
238 .codec_dai
= &aic3x_dai
,
239 .init
= n810_aic33_init
,
243 /* Audio machine driver */
244 static struct snd_soc_machine snd_soc_machine_n810
= {
246 .dai_link
= &n810_dai
,
250 /* Audio private data */
251 static struct aic3x_setup_data n810_aic33_setup
= {
255 /* Audio subsystem */
256 static struct snd_soc_device n810_snd_devdata
= {
257 .machine
= &snd_soc_machine_n810
,
258 .platform
= &omap_soc_platform
,
259 .codec_dev
= &soc_codec_dev_aic3x
,
260 .codec_data
= &n810_aic33_setup
,
263 static struct platform_device
*n810_snd_device
;
265 static int __init
n810_soc_init(void)
270 if (!machine_is_nokia_n810())
273 n810_snd_device
= platform_device_alloc("soc-audio", -1);
274 if (!n810_snd_device
)
277 platform_set_drvdata(n810_snd_device
, &n810_snd_devdata
);
278 n810_snd_devdata
.dev
= &n810_snd_device
->dev
;
279 *(unsigned int *)n810_dai
.cpu_dai
->private_data
= 1; /* McBSP2 */
280 err
= platform_device_add(n810_snd_device
);
284 dev
= &n810_snd_device
->dev
;
286 sys_clkout2_src
= clk_get(dev
, "sys_clkout2_src");
287 if (IS_ERR(sys_clkout2_src
)) {
288 dev_err(dev
, "Could not get sys_clkout2_src clock\n");
291 sys_clkout2
= clk_get(dev
, "sys_clkout2");
292 if (IS_ERR(sys_clkout2
)) {
293 dev_err(dev
, "Could not get sys_clkout2\n");
297 * Configure 12 MHz output on SYS_CLKOUT2. Therefore we must use
298 * 96 MHz as its parent in order to get 12 MHz
300 func96m_clk
= clk_get(dev
, "func_96m_ck");
301 if (IS_ERR(func96m_clk
)) {
302 dev_err(dev
, "Could not get func 96M clock\n");
305 clk_set_parent(sys_clkout2_src
, func96m_clk
);
306 clk_set_rate(sys_clkout2
, 12000000);
308 if (omap_request_gpio(RX44_HEADSET_AMP_GPIO
) < 0)
310 if (omap_request_gpio(RX44_SPEAKER_AMP_GPIO
) < 0)
312 omap_set_gpio_direction(RX44_HEADSET_AMP_GPIO
, 0);
313 omap_set_gpio_direction(RX44_SPEAKER_AMP_GPIO
, 0);
317 clk_put(sys_clkout2
);
318 platform_device_del(n810_snd_device
);
320 platform_device_put(n810_snd_device
);
326 static void __exit
n810_soc_exit(void)
328 platform_device_unregister(n810_snd_device
);
331 module_init(n810_soc_init
);
332 module_exit(n810_soc_exit
);
334 MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@nokia.com>");
335 MODULE_DESCRIPTION("ALSA SoC Nokia N810");
336 MODULE_LICENSE("GPL");