[kernel] rename 014-samsung_flash patch to a better name, thanks maddes
[openwrt.git] / target / linux / xburst / patches-2.6.34 / 066-n516-sound.patch
1 From 34b6a12e70e8260cf273dab7e618602df0c1bebe Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Sat, 24 Apr 2010 12:37:47 +0200
4 Subject: [PATCH] Add N516 sound SoC board driver
5
6 ---
7 sound/soc/jz4740/Kconfig | 8 ++
8 sound/soc/jz4740/Makefile | 2 +
9 sound/soc/jz4740/n516.c | 303 +++++++++++++++++++++++++++++++++++++++++++++
10 3 files changed, 313 insertions(+), 0 deletions(-)
11 create mode 100644 sound/soc/jz4740/n516.c
12
13 diff --git a/sound/soc/jz4740/Kconfig b/sound/soc/jz4740/Kconfig
14 index e546c30..fea440d 100644
15 --- a/sound/soc/jz4740/Kconfig
16 +++ b/sound/soc/jz4740/Kconfig
17 @@ -19,3 +19,11 @@ config SND_JZ4740_SOC_QI_LB60
18 select SND_SOC_JZCODEC
19 help
20 Say Y if you want to add support for SoC audio of internal codec on Ingenic Jz4740 QI_LB60 board.
21 +
22 +config SND_JZ4740_SOC_N516
23 + tristate "SoC Audio support for Hanvon N516 eBook reader"
24 + depends on SND_JZ4740_SOC && JZ4740_N516
25 + select SND_JZ4740_SOC_I2S
26 + select SND_SOC_JZCODEC
27 + help
28 + Say Y if you want to enable support for SoC audio on the Hanvon N516.
29 diff --git a/sound/soc/jz4740/Makefile b/sound/soc/jz4740/Makefile
30 index be873c1..b64d912 100644
31 --- a/sound/soc/jz4740/Makefile
32 +++ b/sound/soc/jz4740/Makefile
33 @@ -9,5 +9,7 @@ obj-$(CONFIG_SND_JZ4740_SOC_I2S) += snd-soc-jz4740-i2s.o
34
35 # Jz4740 Machine Support
36 snd-soc-qi-lb60-objs := qi_lb60.o
37 +snd-soc-n516-objs := n516.o
38
39 obj-$(CONFIG_SND_JZ4740_SOC_QI_LB60) += snd-soc-qi-lb60.o
40 +obj-$(CONFIG_SND_JZ4740_SOC_N516) += snd-soc-n516.o
41 diff --git a/sound/soc/jz4740/n516.c b/sound/soc/jz4740/n516.c
42 new file mode 100644
43 index 0000000..9cb51c2
44 --- /dev/null
45 +++ b/sound/soc/jz4740/n516.c
46 @@ -0,0 +1,303 @@
47 +/*
48 + * Copyright (C) 2009, Yauhen Kharuzhy <jekhor@gmail.com>
49 + * OpenInkpot project
50 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
51 + *
52 + * This program is free software; you can redistribute it and/or modify
53 + * it under the terms of the GNU General Public License version 2 as
54 + * published by the Free Software Foundation.
55 + *
56 + * You should have received a copy of the GNU General Public License along
57 + * with this program; if not, write to the Free Software Foundation, Inc.,
58 + * 675 Mass Ave, Cambridge, MA 02139, USA.
59 + *
60 + */
61 +
62 +#include <linux/module.h>
63 +#include <linux/interrupt.h>
64 +#include <linux/platform_device.h>
65 +#include <sound/core.h>
66 +#include <sound/pcm.h>
67 +#include <sound/soc.h>
68 +#include <sound/soc-dapm.h>
69 +#include <sound/jack.h>
70 +#include <linux/gpio.h>
71 +#include <linux/workqueue.h>
72 +
73 +#include "../codecs/jzcodec.h"
74 +#include "jz4740-pcm.h"
75 +#include "jz4740-i2s.h"
76 +
77 +#include <asm/mach-jz4740/board-n516.h>
78 +
79 +enum {
80 + N516_SPEAKER_AUTO = 0,
81 + N516_SPEAKER_OFF = 1,
82 + N516_SPEAKER_ON = 2,
83 +};
84 +
85 +static int n516_speaker_mode;
86 +static struct snd_soc_codec *n516_codec;
87 +static struct work_struct n516_headphone_work;
88 +
89 +static void n516_ext_control(void)
90 +{
91 + if (!n516_codec)
92 + return;
93 +
94 + switch (n516_speaker_mode) {
95 + case N516_SPEAKER_ON:
96 + snd_soc_dapm_enable_pin(n516_codec, "Speaker");
97 + break;
98 + case N516_SPEAKER_OFF:
99 + snd_soc_dapm_disable_pin(n516_codec, "Speaker");
100 + break;
101 + case N516_SPEAKER_AUTO:
102 + if (snd_soc_dapm_get_pin_status(n516_codec, "Headphone"))
103 + snd_soc_dapm_disable_pin(n516_codec, "Speaker");
104 + else
105 + snd_soc_dapm_enable_pin(n516_codec, "Speaker");
106 + break;
107 + default:
108 + break;
109 + }
110 +
111 + /* signal a DAPM event */
112 + snd_soc_dapm_sync(n516_codec);
113 +}
114 +
115 +static int n516_speaker_event(struct snd_soc_dapm_widget *widget,
116 + struct snd_kcontrol *ctrl, int event)
117 +{
118 + int on = !SND_SOC_DAPM_EVENT_OFF(event);
119 +
120 + gpio_set_value(GPIO_SPEAKER_ENABLE, on);
121 +
122 + return 0;
123 +}
124 +
125 +static void n516_headphone_event_work(struct work_struct *work)
126 +{
127 + n516_ext_control();
128 +}
129 +
130 +static int n516_headphone_event(struct snd_soc_dapm_widget *widget,
131 + struct snd_kcontrol *ctrl, int event)
132 +{
133 + /* We can't call soc_dapm_sync from a event handler */
134 + if (event & (SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD))
135 + schedule_work(&n516_headphone_work);
136 + return 0;
137 +}
138 +
139 +static const struct snd_soc_dapm_widget n516_widgets[] = {
140 + SND_SOC_DAPM_SPK("Speaker", n516_speaker_event),
141 + SND_SOC_DAPM_HP("Headphone", n516_headphone_event),
142 + SND_SOC_DAPM_MIC("Mic", NULL),
143 +};
144 +
145 +static const struct snd_soc_dapm_route n516_routes[] = {
146 + {"Mic", NULL, "MIC"},
147 + {"Speaker", NULL, "LOUT"},
148 + {"Speaker", NULL, "ROUT"},
149 + {"Headphone", NULL, "LOUT"},
150 + {"Headphone", NULL, "ROUT"},
151 +};
152 +
153 +static const char *n516_speaker_modes[] = {"Auto", "Off", "On"};
154 +static const struct soc_enum n516_speaker_mode_enum =
155 + SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(n516_speaker_modes), n516_speaker_modes);
156 +
157 +static int n516_get_speaker_mode(struct snd_kcontrol *kcontrol,
158 + struct snd_ctl_elem_value *ucontrol)
159 +{
160 + ucontrol->value.integer.value[0] = n516_speaker_mode;
161 + return 0;
162 +}
163 +
164 +static int n516_set_speaker_mode(struct snd_kcontrol *kcontrol,
165 + struct snd_ctl_elem_value *ucontrol)
166 +{
167 + if (n516_speaker_mode == ucontrol->value.integer.value[0])
168 + return 0;
169 +
170 + n516_speaker_mode = ucontrol->value.integer.value[0];
171 + n516_ext_control();
172 + return 1;
173 +}
174 +
175 +static const struct snd_kcontrol_new n516_controls[] = {
176 + SOC_ENUM_EXT("Speaker Function", n516_speaker_mode_enum,
177 + n516_get_speaker_mode, n516_set_speaker_mode),
178 +};
179 +
180 +#define N516_DAIFMT (SND_SOC_DAIFMT_I2S | \
181 + SND_SOC_DAIFMT_NB_NF | \
182 + SND_SOC_DAIFMT_CBM_CFM)
183 +
184 +static int n516_codec_init(struct snd_soc_codec *codec)
185 +{
186 + int ret;
187 + struct snd_soc_dai *cpu_dai = codec->socdev->card->dai_link->cpu_dai;
188 + struct snd_soc_dai *codec_dai = codec->socdev->card->dai_link->codec_dai;
189 +
190 + n516_codec = codec;
191 +
192 + snd_soc_dapm_nc_pin(codec, "LIN");
193 + snd_soc_dapm_nc_pin(codec, "RIN");
194 +
195 + ret = snd_soc_dai_set_fmt(codec_dai, N516_DAIFMT);
196 + if (ret < 0) {
197 + dev_err(codec->dev, "Failed to set codec dai format: %d\n", ret);
198 + return ret;
199 + }
200 +
201 + ret = snd_soc_dai_set_fmt(cpu_dai, N516_DAIFMT);
202 + if (ret < 0) {
203 + dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
204 + return ret;
205 + }
206 +
207 + ret = snd_soc_dai_set_sysclk(codec_dai, JZCODEC_SYSCLK, 111,
208 + SND_SOC_CLOCK_IN);
209 + if (ret < 0) {
210 + dev_err(codec->dev, "Failed to set codec dai sysclk: %d\n", ret);
211 + return ret;
212 + }
213 +
214 + ret = snd_soc_add_controls(codec, n516_controls,
215 + ARRAY_SIZE(n516_controls));
216 + if (ret) {
217 + dev_err(codec->dev, "Failed to add controls: %d\n", ret);
218 + return ret;
219 + }
220 +
221 +
222 + ret = snd_soc_dapm_new_controls(codec, n516_widgets,
223 + ARRAY_SIZE(n516_widgets));
224 + if (ret) {
225 + dev_err(codec->dev, "Failed to add dapm controls: %d\n", ret);
226 + return ret;
227 + }
228 +
229 + ret = snd_soc_dapm_add_routes(codec, n516_routes, ARRAY_SIZE(n516_routes));
230 + if (ret) {
231 + dev_err(codec->dev, "Failed to add dapm routes: %d\n", ret);
232 + return ret;
233 + }
234 +
235 + snd_soc_dapm_sync(codec);
236 +
237 + return 0;
238 +}
239 +
240 +static struct snd_soc_dai_link n516_dai = {
241 + .name = "jz-codec",
242 + .stream_name = "JZCODEC",
243 + .cpu_dai = &jz4740_i2s_dai,
244 + .codec_dai = &jz_codec_dai,
245 + .init = n516_codec_init,
246 +};
247 +
248 +static struct snd_soc_card n516_card = {
249 + .name = "N516",
250 + .dai_link = &n516_dai,
251 + .num_links = 1,
252 + .platform = &jz4740_soc_platform,
253 +};
254 +
255 +static struct snd_soc_device n516_snd_devdata = {
256 + .card = &n516_card,
257 + .codec_dev = &soc_codec_dev_jzcodec,
258 +};
259 +
260 +static struct platform_device *n516_snd_device;
261 +
262 +static struct snd_soc_jack n516_hp_jack;
263 +
264 +static struct snd_soc_jack_pin n516_hp_pin = {
265 + .pin = "Headphone",
266 + .mask = SND_JACK_HEADPHONE,
267 +};
268 +
269 +static struct snd_soc_jack_gpio n516_hp_gpio = {
270 + .gpio = GPIO_HPHONE_DETECT,
271 + .name = "Headphone detect",
272 + .report = SND_JACK_HEADPHONE,
273 + .debounce_time = 100,
274 +};
275 +
276 +static int __init n516_add_headphone_jack(void)
277 +{
278 + int ret;
279 +
280 + ret = snd_soc_jack_new(&n516_card, "Headphone jack",
281 + SND_JACK_HEADPHONE, &n516_hp_jack);
282 + if (ret)
283 + return ret;
284 +
285 + ret = snd_soc_jack_add_pins(&n516_hp_jack, 1, &n516_hp_pin);
286 + if (ret)
287 + return ret;
288 +
289 + ret = snd_soc_jack_add_gpios(&n516_hp_jack, 1, &n516_hp_gpio);
290 +
291 + return ret;
292 +}
293 +
294 +static int __init n516_init(void)
295 +{
296 + int ret;
297 +
298 + n516_snd_device = platform_device_alloc("soc-audio", -1);
299 +
300 + if (!n516_snd_device)
301 + return -ENOMEM;
302 +
303 + ret = gpio_request(GPIO_SPEAKER_ENABLE, "Speaker enable");
304 + if (ret) {
305 + pr_err("n516 snd: Failed to request SPEAKER_ENABLE GPIO(%d): %d\n",
306 + GPIO_SPEAKER_ENABLE, ret);
307 + goto err_device_put;
308 + }
309 +
310 + gpio_direction_output(GPIO_SPEAKER_ENABLE, 0);
311 + INIT_WORK(&n516_headphone_work, n516_headphone_event_work);
312 +
313 + platform_set_drvdata(n516_snd_device, &n516_snd_devdata);
314 + n516_snd_devdata.dev = &n516_snd_device->dev;
315 + ret = platform_device_add(n516_snd_device);
316 + if (ret) {
317 + pr_err("n516 snd: Failed to add snd soc device: %d\n", ret);
318 + goto err_unset_pdata;
319 + }
320 +
321 + ret = n516_add_headphone_jack();
322 + /* We can live without it, so just print a warning */
323 + if (ret)
324 + pr_warning("n516 snd: Failed to initalise headphone jack: %d\n", ret);
325 +
326 + return 0;
327 +
328 +err_unset_pdata:
329 + platform_set_drvdata(n516_snd_device, NULL);
330 +/*err_gpio_free_speaker:*/
331 + gpio_free(GPIO_SPEAKER_ENABLE);
332 +err_device_put:
333 + platform_device_put(n516_snd_device);
334 +
335 + return ret;
336 +}
337 +module_init(n516_init);
338 +
339 +static void __exit n516_exit(void)
340 +{
341 + snd_soc_jack_free_gpios(&n516_hp_jack, 1, &n516_hp_gpio);
342 + gpio_free(GPIO_SPEAKER_ENABLE);
343 + platform_device_unregister(n516_snd_device);
344 +}
345 +module_exit(n516_exit);
346 +
347 +MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
348 +MODULE_DESCRIPTION("ALSA SoC N516 Audio support");
349 +MODULE_LICENSE("GPL v2");
350 --
351 1.5.6.5
352
This page took 0.062677 seconds and 5 git commands to generate.