[xburst] Add 2.6.37 support
[openwrt.git] / target / linux / xburst / patches-2.6.34 / 067-n526-sound.patch
1 From c2ac996d78f5015d759375792ba390739c1acd00 Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Sat, 24 Apr 2010 12:38:41 +0200
4 Subject: [PATCH] Add N526 sound SoC board driver
5
6 ---
7  sound/soc/jz4740/Kconfig  |    8 ++
8  sound/soc/jz4740/Makefile |    2 +
9  sound/soc/jz4740/n526.c   |  169 +++++++++++++++++++++++++++++++++++++++++++++
10  3 files changed, 179 insertions(+), 0 deletions(-)
11  create mode 100644 sound/soc/jz4740/n526.c
12
13 diff --git a/sound/soc/jz4740/Kconfig b/sound/soc/jz4740/Kconfig
14 index fea440d..cd00c8c 100644
15 --- a/sound/soc/jz4740/Kconfig
16 +++ b/sound/soc/jz4740/Kconfig
17 @@ -27,3 +27,11 @@ config SND_JZ4740_SOC_N516
18      select SND_SOC_JZCODEC
19         help
20           Say Y if you want to enable support for SoC audio on the Hanvon N516.
21 +
22 +config SND_JZ4740_SOC_N526
23 +       tristate "SoC Audio support for Hanvon N526 eBook reader"
24 +       depends on SND_JZ4740_SOC && JZ4740_N526
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 N526.
29 diff --git a/sound/soc/jz4740/Makefile b/sound/soc/jz4740/Makefile
30 index b64d912..e7952d3 100644
31 --- a/sound/soc/jz4740/Makefile
32 +++ b/sound/soc/jz4740/Makefile
33 @@ -10,6 +10,8 @@ obj-$(CONFIG_SND_JZ4740_SOC_I2S) += snd-soc-jz4740-i2s.o
34  # Jz4740 Machine Support
35  snd-soc-qi-lb60-objs := qi_lb60.o
36  snd-soc-n516-objs := n516.o
37 +snd-soc-n526-objs := n526.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 +obj-$(CONFIG_SND_JZ4740_SOC_N526) += snd-soc-n526.o
42 diff --git a/sound/soc/jz4740/n526.c b/sound/soc/jz4740/n526.c
43 new file mode 100644
44 index 0000000..2283904
45 --- /dev/null
46 +++ b/sound/soc/jz4740/n526.c
47 @@ -0,0 +1,169 @@
48 +/*
49 + * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
50 + *
51 + * This program is free software; you can redistribute it and/or modify
52 + * it under the terms of the GNU General Public License version 2 as
53 + * published by the Free Software Foundation.
54 + *
55 + *  You should have received a copy of the  GNU General Public License along
56 + *  with this program; if not, write  to the Free Software Foundation, Inc.,
57 + *  675 Mass Ave, Cambridge, MA 02139, USA.
58 + *
59 + */
60 +
61 +#include <linux/module.h>
62 +#include <linux/moduleparam.h>
63 +#include <linux/timer.h>
64 +#include <linux/interrupt.h>
65 +#include <linux/platform_device.h>
66 +#include <sound/core.h>
67 +#include <sound/pcm.h>
68 +#include <sound/soc.h>
69 +#include <sound/soc-dapm.h>
70 +#include <linux/gpio.h>
71 +
72 +#include "../codecs/jzcodec.h"
73 +#include "jz4740-pcm.h"
74 +#include "jz4740-i2s.h"
75 +
76 +#define N526_AMP_EN_GPIO JZ_GPIO_PORTD(4)
77 +
78 +static int n526_spk_event(struct snd_soc_dapm_widget *widget,
79 +                            struct snd_kcontrol *ctrl, int event)
80 +{
81 +       gpio_set_value(N526_AMP_EN_GPIO, !SND_SOC_DAPM_EVENT_OFF(event));
82 +       return 0;
83 +}
84 +
85 +static const struct snd_soc_dapm_widget n526_widgets[] = {
86 +       SND_SOC_DAPM_SPK("Speaker", n526_spk_event),
87 +       SND_SOC_DAPM_HP("Headphone", NULL),
88 +       SND_SOC_DAPM_MIC("Mic", NULL),
89 +};
90 +
91 +static const struct snd_soc_dapm_route n526_routes[] = {
92 +       {"Mic", NULL, "MIC"},
93 +       {"Speaker", NULL, "LOUT"},
94 +       {"Speaker", NULL, "ROUT"},
95 +       {"Headphone", NULL, "LOUT"},
96 +       {"Headphone", NULL, "ROUT"},
97 +};
98 +
99 +static const struct snd_kcontrol_new n526_controls[] = {
100 +       SOC_DAPM_PIN_SWITCH("Speaker"),
101 +};
102 +
103 +#define N526_DAIFMT (SND_SOC_DAIFMT_I2S | \
104 +                       SND_SOC_DAIFMT_NB_NF | \
105 +                       SND_SOC_DAIFMT_CBM_CFM)
106 +
107 +static int n526_codec_init(struct snd_soc_codec *codec)
108 +{
109 +       int ret;
110 +       struct snd_soc_dai *cpu_dai = codec->socdev->card->dai_link->cpu_dai;
111 +       struct snd_soc_dai *codec_dai = codec->socdev->card->dai_link->codec_dai;
112 +
113 +       snd_soc_dapm_nc_pin(codec, "LIN");
114 +       snd_soc_dapm_nc_pin(codec, "RIN");
115 +
116 +       ret = snd_soc_dai_set_fmt(codec_dai, N526_DAIFMT);
117 +       if (ret < 0) {
118 +               dev_err(codec->dev, "Failed to set codec dai format: %d\n", ret);
119 +               return ret;
120 +       }
121 +
122 +       ret = snd_soc_dai_set_fmt(cpu_dai, N526_DAIFMT);
123 +       if (ret < 0) {
124 +               dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
125 +               return ret;
126 +       }
127 +
128 +       ret = snd_soc_dai_set_sysclk(codec_dai, JZCODEC_SYSCLK, 111,
129 +               SND_SOC_CLOCK_IN);
130 +       if (ret < 0) {
131 +               dev_err(codec->dev, "Failed to set codec dai sysclk: %d\n", ret);
132 +               return ret;
133 +       }
134 +
135 +       snd_soc_dapm_new_controls(codec, n526_widgets, ARRAY_SIZE(n526_widgets));
136 +
137 +       snd_soc_add_controls(codec, n526_controls,
138 +                               ARRAY_SIZE(n526_controls));
139 +
140 +       snd_soc_dapm_add_routes(codec, n526_routes, ARRAY_SIZE(n526_routes));
141 +
142 +       snd_soc_dapm_sync(codec);
143 +
144 +       return 0;
145 +}
146 +
147 +static struct snd_soc_dai_link n526_dai = {
148 +       .name = "jz-codec",
149 +       .stream_name = "JZCODEC",
150 +       .cpu_dai = &jz4740_i2s_dai,
151 +       .codec_dai = &jz_codec_dai,
152 +       .init = n526_codec_init,
153 +};
154 +
155 +static struct snd_soc_card n526 = {
156 +       .name = "N526",
157 +       .dai_link = &n526_dai,
158 +       .num_links = 1,
159 +       .platform = &jz4740_soc_platform,
160 +};
161 +
162 +static struct snd_soc_device n526_snd_devdata = {
163 +       .card = &n526,
164 +       .codec_dev = &soc_codec_dev_jzcodec,
165 +};
166 +
167 +static struct platform_device *n526_snd_device;
168 +
169 +static int __init n526_init(void)
170 +{
171 +       int ret;
172 +
173 +       n526_snd_device = platform_device_alloc("soc-audio", -1);
174 +
175 +       if (!n526_snd_device)
176 +               return -ENOMEM;
177 +
178 +       ret = gpio_request(N526_AMP_EN_GPIO, "AMP");
179 +       if (ret) {
180 +               pr_err("n526 snd: Failed to request AMP GPIO(%d): %d\n",
181 +                               N526_AMP_EN_GPIO, ret);
182 +               goto err_device_put;
183 +       }
184 +
185 +       gpio_direction_output(JZ_GPIO_PORTD(4), 0);
186 +
187 +       platform_set_drvdata(n526_snd_device, &n526_snd_devdata);
188 +       n526_snd_devdata.dev = &n526_snd_device->dev;
189 +       ret = platform_device_add(n526_snd_device);
190 +       if (ret) {
191 +               pr_err("n526 snd: Failed to add snd soc device: %d\n", ret);
192 +               goto err_unset_pdata;
193 +       }
194 +
195 +        return 0;
196 +
197 +err_unset_pdata:
198 +       platform_set_drvdata(n526_snd_device, NULL);
199 +       gpio_free(N526_AMP_EN_GPIO);
200 +err_device_put:
201 +       platform_device_put(n526_snd_device);
202 +
203 +       return ret;
204 +}
205 +module_init(n526_init);
206 +
207 +static void __exit n526_exit(void)
208 +{
209 +       gpio_free(N526_AMP_EN_GPIO);
210 +       platform_device_unregister(n526_snd_device);
211 +}
212 +module_exit(n526_exit);
213 +
214 +MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
215 +MODULE_DESCRIPTION("ALSA SoC N526 audio support");
216 +MODULE_LICENSE("GPL v2");
217 -- 
218 1.5.6.5
219