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