ar71xx: rewrite SPI drivers for the RB4xx boards
[openwrt.git] / target / linux / xburst / patches-2.6.35 / 065-qi_lb60-sound.patch
1 From 498365d473a863fdfceff28315ce8561752bc356 Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Sat, 19 Jun 2010 16:52:51 +0200
4 Subject: [PATCH] ASoC: JZ4740: Add qi_lb60 board driver
5
6 This patch adds ASoC support for the qi_lb60 board.
7
8 Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
9 Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
10 Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
11 ---
12 sound/soc/jz4740/Kconfig | 9 +++
13 sound/soc/jz4740/Makefile | 4 +
14 sound/soc/jz4740/qi_lb60.c | 166 ++++++++++++++++++++++++++++++++++++++++++++
15 3 files changed, 179 insertions(+), 0 deletions(-)
16 create mode 100644 sound/soc/jz4740/qi_lb60.c
17
18 --- a/sound/soc/jz4740/Kconfig
19 +++ b/sound/soc/jz4740/Kconfig
20 @@ -12,3 +12,12 @@ config SND_JZ4740_SOC_I2S
21 help
22 Say Y if you want to use I2S protocol and I2S codec on Ingenic JZ4740
23 based boards.
24 +
25 +config SND_JZ4740_SOC_QI_LB60
26 + tristate "SoC Audio support for Qi LB60"
27 + depends on SND_JZ4740_SOC && JZ4740_QI_LB60
28 + select SND_JZ4740_SOC_I2S
29 + select SND_SOC_JZ4740_CODEC
30 + help
31 + Say Y if you want to add support for ASoC audio on the Qi LB60 board
32 + a.k.a Qi Ben NanoNote.
33 --- a/sound/soc/jz4740/Makefile
34 +++ b/sound/soc/jz4740/Makefile
35 @@ -7,3 +7,7 @@ snd-soc-jz4740-i2s-objs := jz4740-i2s.o
36 obj-$(CONFIG_SND_JZ4740_SOC) += snd-soc-jz4740.o
37 obj-$(CONFIG_SND_JZ4740_SOC_I2S) += snd-soc-jz4740-i2s.o
38
39 +# Jz4740 Machine Support
40 +snd-soc-qi-lb60-objs := qi_lb60.o
41 +
42 +obj-$(CONFIG_SND_JZ4740_SOC_QI_LB60) += snd-soc-qi-lb60.o
43 --- /dev/null
44 +++ b/sound/soc/jz4740/qi_lb60.c
45 @@ -0,0 +1,166 @@
46 +/*
47 + * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
48 + *
49 + * This program is free software; you can redistribute it and/or modify
50 + * it under the terms of the GNU General Public License version 2 as
51 + * published by the Free Software Foundation.
52 + *
53 + * You should have received a copy of the GNU General Public License along
54 + * with this program; if not, write to the Free Software Foundation, Inc.,
55 + * 675 Mass Ave, Cambridge, MA 02139, USA.
56 + *
57 + */
58 +
59 +#include <linux/module.h>
60 +#include <linux/moduleparam.h>
61 +#include <linux/timer.h>
62 +#include <linux/interrupt.h>
63 +#include <linux/platform_device.h>
64 +#include <sound/core.h>
65 +#include <sound/pcm.h>
66 +#include <sound/soc.h>
67 +#include <sound/soc-dapm.h>
68 +#include <linux/gpio.h>
69 +
70 +#include "../codecs/jz4740.h"
71 +#include "jz4740-pcm.h"
72 +#include "jz4740-i2s.h"
73 +
74 +
75 +#define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29)
76 +#define QI_LB60_AMP_GPIO JZ_GPIO_PORTD(4)
77 +
78 +static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget,
79 + struct snd_kcontrol *ctrl, int event)
80 +{
81 + int on = 0;
82 + if (event & SND_SOC_DAPM_POST_PMU)
83 + on = 1;
84 + else if (event & SND_SOC_DAPM_PRE_PMD)
85 + on = 0;
86 +
87 + gpio_set_value(QI_LB60_SND_GPIO, on);
88 + gpio_set_value(QI_LB60_AMP_GPIO, on);
89 +
90 + return 0;
91 +}
92 +
93 +static const struct snd_soc_dapm_widget qi_lb60_widgets[] = {
94 + SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event),
95 + SND_SOC_DAPM_MIC("Mic", NULL),
96 +};
97 +
98 +static const struct snd_soc_dapm_route qi_lb60_routes[] = {
99 + {"Mic", NULL, "MIC"},
100 + {"Speaker", NULL, "LOUT"},
101 + {"Speaker", NULL, "ROUT"},
102 +};
103 +
104 +#define QI_LB60_DAIFMT (SND_SOC_DAIFMT_I2S | \
105 + SND_SOC_DAIFMT_NB_NF | \
106 + SND_SOC_DAIFMT_CBM_CFM)
107 +
108 +static int qi_lb60_codec_init(struct snd_soc_codec *codec)
109 +{
110 + int ret;
111 + struct snd_soc_dai *cpu_dai = codec->socdev->card->dai_link->cpu_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(cpu_dai, QI_LB60_DAIFMT);
117 + if (ret < 0) {
118 + dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
119 + return ret;
120 + }
121 +
122 + snd_soc_dapm_new_controls(codec, qi_lb60_widgets, ARRAY_SIZE(qi_lb60_widgets));
123 + snd_soc_dapm_add_routes(codec, qi_lb60_routes, ARRAY_SIZE(qi_lb60_routes));
124 + snd_soc_dapm_sync(codec);
125 +
126 + return 0;
127 +}
128 +
129 +static struct snd_soc_dai_link qi_lb60_dai = {
130 + .name = "jz4740",
131 + .stream_name = "jz4740",
132 + .cpu_dai = &jz4740_i2s_dai,
133 + .codec_dai = &jz4740_codec_dai,
134 + .init = qi_lb60_codec_init,
135 +};
136 +
137 +static struct snd_soc_card qi_lb60 = {
138 + .name = "QI LB60",
139 + .dai_link = &qi_lb60_dai,
140 + .num_links = 1,
141 + .platform = &jz4740_soc_platform,
142 +};
143 +
144 +static struct snd_soc_device qi_lb60_snd_devdata = {
145 + .card = &qi_lb60,
146 + .codec_dev = &soc_codec_dev_jz4740_codec,
147 +};
148 +
149 +static struct platform_device *qi_lb60_snd_device;
150 +
151 +static int __init qi_lb60_init(void)
152 +{
153 + int ret;
154 +
155 + qi_lb60_snd_device = platform_device_alloc("soc-audio", -1);
156 +
157 + if (!qi_lb60_snd_device)
158 + return -ENOMEM;
159 +
160 + ret = gpio_request(QI_LB60_SND_GPIO, "SND");
161 + if (ret) {
162 + pr_err("qi_lb60 snd: Failed to request SND GPIO(%d): %d\n",
163 + QI_LB60_SND_GPIO, ret);
164 + goto err_device_put;
165 + }
166 +
167 + ret = gpio_request(QI_LB60_AMP_GPIO, "AMP");
168 + if (ret) {
169 + pr_err("qi_lb60 snd: Failed to request AMP GPIO(%d): %d\n",
170 + QI_LB60_AMP_GPIO, ret);
171 + goto err_gpio_free_snd;
172 + }
173 +
174 + gpio_direction_output(QI_LB60_SND_GPIO, 0);
175 + gpio_direction_output(QI_LB60_AMP_GPIO, 0);
176 +
177 + platform_set_drvdata(qi_lb60_snd_device, &qi_lb60_snd_devdata);
178 + qi_lb60_snd_devdata.dev = &qi_lb60_snd_device->dev;
179 +
180 + ret = platform_device_add(qi_lb60_snd_device);
181 + if (ret) {
182 + pr_err("qi_lb60 snd: Failed to add snd soc device: %d\n", ret);
183 + goto err_unset_pdata;
184 + }
185 +
186 + return 0;
187 +
188 +err_unset_pdata:
189 + platform_set_drvdata(qi_lb60_snd_device, NULL);
190 +/*err_gpio_free_amp:*/
191 + gpio_free(QI_LB60_AMP_GPIO);
192 +err_gpio_free_snd:
193 + gpio_free(QI_LB60_SND_GPIO);
194 +err_device_put:
195 + platform_device_put(qi_lb60_snd_device);
196 +
197 + return ret;
198 +}
199 +module_init(qi_lb60_init);
200 +
201 +static void __exit qi_lb60_exit(void)
202 +{
203 + gpio_free(QI_LB60_AMP_GPIO);
204 + gpio_free(QI_LB60_SND_GPIO);
205 + platform_device_unregister(qi_lb60_snd_device);
206 +}
207 +module_exit(qi_lb60_exit);
208 +
209 +MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
210 +MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
211 +MODULE_LICENSE("GPL v2");
This page took 0.060752 seconds and 5 git commands to generate.