1 From 53b1d94ccca6a06e86460344f7c38949d53374b6 Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Sat, 24 Apr 2010 12:36:15 +0200
4 Subject: [PATCH] Add qi_lb60 SoC sound board driver
7 sound/soc/jz4740/Kconfig | 8 ++
8 sound/soc/jz4740/Makefile | 4 +
9 sound/soc/jz4740/qi_lb60.c | 182 ++++++++++++++++++++++++++++++++++++++++++++
10 3 files changed, 194 insertions(+), 0 deletions(-)
11 create mode 100644 sound/soc/jz4740/qi_lb60.c
13 diff --git a/sound/soc/jz4740/Kconfig b/sound/soc/jz4740/Kconfig
14 index 39df949..e546c30 100644
15 --- a/sound/soc/jz4740/Kconfig
16 +++ b/sound/soc/jz4740/Kconfig
17 @@ -11,3 +11,11 @@ config SND_JZ4740_SOC_I2S
18 tristate "SoC Audio (I2S protocol) for Ingenic jz4740 chip"
20 Say Y if you want to use I2S protocol and I2S codec on Ingenic Jz4740 QI_LB60 board.
22 +config SND_JZ4740_SOC_QI_LB60
23 + tristate "SoC Audio support for Qi Hardware Ben Nanonote"
24 + depends on SND_JZ4740_SOC && JZ4740_QI_LB60
25 + select SND_JZ4740_SOC_I2S
26 + select SND_SOC_JZCODEC
28 + Say Y if you want to add support for SoC audio of internal codec on Ingenic Jz4740 QI_LB60 board.
29 diff --git a/sound/soc/jz4740/Makefile b/sound/soc/jz4740/Makefile
30 index 1be8d19..be873c1 100644
31 --- a/sound/soc/jz4740/Makefile
32 +++ b/sound/soc/jz4740/Makefile
33 @@ -7,3 +7,7 @@ snd-soc-jz4740-i2s-objs := jz4740-i2s.o
34 obj-$(CONFIG_SND_JZ4740_SOC) += snd-soc-jz4740.o
35 obj-$(CONFIG_SND_JZ4740_SOC_I2S) += snd-soc-jz4740-i2s.o
37 +# Jz4740 Machine Support
38 +snd-soc-qi-lb60-objs := qi_lb60.o
40 +obj-$(CONFIG_SND_JZ4740_SOC_QI_LB60) += snd-soc-qi-lb60.o
41 diff --git a/sound/soc/jz4740/qi_lb60.c b/sound/soc/jz4740/qi_lb60.c
43 index 0000000..a2ce3cf
45 +++ b/sound/soc/jz4740/qi_lb60.c
48 + * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
50 + * This program is free software; you can redistribute it and/or modify
51 + * it under the terms of the GNU General Public License version 2 as
52 + * published by the Free Software Foundation.
54 + * You should have received a copy of the GNU General Public License along
55 + * with this program; if not, write to the Free Software Foundation, Inc.,
56 + * 675 Mass Ave, Cambridge, MA 02139, USA.
60 +#include <linux/module.h>
61 +#include <linux/moduleparam.h>
62 +#include <linux/timer.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 <linux/gpio.h>
71 +#include "../codecs/jzcodec.h"
72 +#include "jz4740-pcm.h"
73 +#include "jz4740-i2s.h"
76 +#define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29)
77 +#define QI_LB60_AMP_GPIO JZ_GPIO_PORTD(4)
79 +static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget,
80 + struct snd_kcontrol *ctrl, int event)
83 + if (event & SND_SOC_DAPM_POST_PMU)
85 + else if (event & SND_SOC_DAPM_PRE_PMD)
88 + gpio_set_value(QI_LB60_SND_GPIO, on);
89 + gpio_set_value(QI_LB60_AMP_GPIO, on);
94 +static const struct snd_soc_dapm_widget qi_lb60_widgets[] = {
95 + SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event),
96 + SND_SOC_DAPM_MIC("Mic", NULL),
99 +static const struct snd_soc_dapm_route qi_lb60_routes[] = {
100 + {"Mic", NULL, "MIC"},
101 + {"Speaker", NULL, "LOUT"},
102 + {"Speaker", NULL, "ROUT"},
105 +#define QI_LB60_DAIFMT (SND_SOC_DAIFMT_I2S | \
106 + SND_SOC_DAIFMT_NB_NF | \
107 + SND_SOC_DAIFMT_CBM_CFM)
109 +static int qi_lb60_codec_init(struct snd_soc_codec *codec)
112 + struct snd_soc_dai *cpu_dai = codec->socdev->card->dai_link->cpu_dai;
113 + struct snd_soc_dai *codec_dai = codec->socdev->card->dai_link->codec_dai;
115 + snd_soc_dapm_nc_pin(codec, "LIN");
116 + snd_soc_dapm_nc_pin(codec, "RIN");
118 + ret = snd_soc_dai_set_fmt(codec_dai, QI_LB60_DAIFMT);
120 + dev_err(codec->dev, "Failed to set codec dai format: %d\n", ret);
124 + ret = snd_soc_dai_set_fmt(cpu_dai, QI_LB60_DAIFMT);
126 + dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
130 + ret = snd_soc_dai_set_sysclk(codec_dai, JZCODEC_SYSCLK, 111,
133 + dev_err(codec->dev, "Failed to set codec dai sysclk: %d\n", ret);
137 + snd_soc_dapm_new_controls(codec, qi_lb60_widgets, ARRAY_SIZE(qi_lb60_widgets));
139 + snd_soc_dapm_add_routes(codec, qi_lb60_routes, ARRAY_SIZE(qi_lb60_routes));
141 + snd_soc_dapm_sync(codec);
146 +static struct snd_soc_dai_link qi_lb60_dai = {
147 + .name = "jz-codec",
148 + .stream_name = "JZCODEC",
149 + .cpu_dai = &jz4740_i2s_dai,
150 + .codec_dai = &jz_codec_dai,
151 + .init = qi_lb60_codec_init,
154 +static struct snd_soc_card qi_lb60 = {
156 + .dai_link = &qi_lb60_dai,
158 + .platform = &jz4740_soc_platform,
161 +static struct snd_soc_device qi_lb60_snd_devdata = {
163 + .codec_dev = &soc_codec_dev_jzcodec,
166 +static struct platform_device *qi_lb60_snd_device;
168 +static int __init qi_lb60_init(void)
172 + qi_lb60_snd_device = platform_device_alloc("soc-audio", -1);
174 + if (!qi_lb60_snd_device)
178 + ret = gpio_request(QI_LB60_SND_GPIO, "SND");
180 + pr_err("qi_lb60 snd: Failed to request SND GPIO(%d): %d\n",
181 + QI_LB60_SND_GPIO, ret);
182 + goto err_device_put;
185 + ret = gpio_request(QI_LB60_AMP_GPIO, "AMP");
187 + pr_err("qi_lb60 snd: Failed to request AMP GPIO(%d): %d\n",
188 + QI_LB60_AMP_GPIO, ret);
189 + goto err_gpio_free_snd;
192 + gpio_direction_output(JZ_GPIO_PORTB(29), 0);
193 + gpio_direction_output(JZ_GPIO_PORTD(4), 0);
195 + platform_set_drvdata(qi_lb60_snd_device, &qi_lb60_snd_devdata);
196 + qi_lb60_snd_devdata.dev = &qi_lb60_snd_device->dev;
197 + ret = platform_device_add(qi_lb60_snd_device);
199 + pr_err("qi_lb60 snd: Failed to add snd soc device: %d\n", ret);
200 + goto err_unset_pdata;
206 + platform_set_drvdata(qi_lb60_snd_device, NULL);
207 +/*err_gpio_free_amp:*/
208 + gpio_free(QI_LB60_AMP_GPIO);
210 + gpio_free(QI_LB60_SND_GPIO);
212 + platform_device_put(qi_lb60_snd_device);
216 +module_init(qi_lb60_init);
218 +static void __exit qi_lb60_exit(void)
220 + gpio_free(QI_LB60_AMP_GPIO);
221 + gpio_free(QI_LB60_SND_GPIO);
222 + platform_device_unregister(qi_lb60_snd_device);
224 +module_exit(qi_lb60_exit);
226 +MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
227 +MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
228 +MODULE_LICENSE("GPL v2");