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
6 This patch adds ASoC support for the qi_lb60 board.
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>
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
18 --- a/sound/soc/jz4740/Kconfig
19 +++ b/sound/soc/jz4740/Kconfig
20 @@ -12,3 +12,12 @@ config SND_JZ4740_SOC_I2S
22 Say Y if you want to use I2S protocol and I2S codec on Ingenic JZ4740
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
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
39 +# Jz4740 Machine Support
40 +snd-soc-qi-lb60-objs := qi_lb60.o
42 +obj-$(CONFIG_SND_JZ4740_SOC_QI_LB60) += snd-soc-qi-lb60.o
44 +++ b/sound/soc/jz4740/qi_lb60.c
47 + * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
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.
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.
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>
70 +#include "../codecs/jz4740.h"
71 +#include "jz4740-pcm.h"
72 +#include "jz4740-i2s.h"
75 +#define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29)
76 +#define QI_LB60_AMP_GPIO JZ_GPIO_PORTD(4)
78 +static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget,
79 + struct snd_kcontrol *ctrl, int event)
82 + if (event & SND_SOC_DAPM_POST_PMU)
84 + else if (event & SND_SOC_DAPM_PRE_PMD)
87 + gpio_set_value(QI_LB60_SND_GPIO, on);
88 + gpio_set_value(QI_LB60_AMP_GPIO, on);
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),
98 +static const struct snd_soc_dapm_route qi_lb60_routes[] = {
99 + {"Mic", NULL, "MIC"},
100 + {"Speaker", NULL, "LOUT"},
101 + {"Speaker", NULL, "ROUT"},
104 +#define QI_LB60_DAIFMT (SND_SOC_DAIFMT_I2S | \
105 + SND_SOC_DAIFMT_NB_NF | \
106 + SND_SOC_DAIFMT_CBM_CFM)
108 +static int qi_lb60_codec_init(struct snd_soc_codec *codec)
111 + struct snd_soc_dai *cpu_dai = codec->socdev->card->dai_link->cpu_dai;
113 + snd_soc_dapm_nc_pin(codec, "LIN");
114 + snd_soc_dapm_nc_pin(codec, "RIN");
116 + ret = snd_soc_dai_set_fmt(cpu_dai, QI_LB60_DAIFMT);
118 + dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
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);
129 +static struct snd_soc_dai_link qi_lb60_dai = {
131 + .stream_name = "jz4740",
132 + .cpu_dai = &jz4740_i2s_dai,
133 + .codec_dai = &jz4740_codec_dai,
134 + .init = qi_lb60_codec_init,
137 +static struct snd_soc_card qi_lb60 = {
139 + .dai_link = &qi_lb60_dai,
141 + .platform = &jz4740_soc_platform,
144 +static struct snd_soc_device qi_lb60_snd_devdata = {
146 + .codec_dev = &soc_codec_dev_jz4740_codec,
149 +static struct platform_device *qi_lb60_snd_device;
151 +static int __init qi_lb60_init(void)
155 + qi_lb60_snd_device = platform_device_alloc("soc-audio", -1);
157 + if (!qi_lb60_snd_device)
160 + ret = gpio_request(QI_LB60_SND_GPIO, "SND");
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;
167 + ret = gpio_request(QI_LB60_AMP_GPIO, "AMP");
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;
174 + gpio_direction_output(QI_LB60_SND_GPIO, 0);
175 + gpio_direction_output(QI_LB60_AMP_GPIO, 0);
177 + platform_set_drvdata(qi_lb60_snd_device, &qi_lb60_snd_devdata);
178 + qi_lb60_snd_devdata.dev = &qi_lb60_snd_device->dev;
180 + ret = platform_device_add(qi_lb60_snd_device);
182 + pr_err("qi_lb60 snd: Failed to add snd soc device: %d\n", ret);
183 + goto err_unset_pdata;
189 + platform_set_drvdata(qi_lb60_snd_device, NULL);
190 +/*err_gpio_free_amp:*/
191 + gpio_free(QI_LB60_AMP_GPIO);
193 + gpio_free(QI_LB60_SND_GPIO);
195 + platform_device_put(qi_lb60_snd_device);
199 +module_init(qi_lb60_init);
201 +static void __exit qi_lb60_exit(void)
203 + gpio_free(QI_LB60_AMP_GPIO);
204 + gpio_free(QI_LB60_SND_GPIO);
205 + platform_device_unregister(qi_lb60_snd_device);
207 +module_exit(qi_lb60_exit);
209 +MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
210 +MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
211 +MODULE_LICENSE("GPL v2");