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
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
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
20 Say Y if you want to enable support for SoC audio on the Hanvon N516.
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
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
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
44 index 0000000..2283904
46 +++ b/sound/soc/jz4740/n526.c
49 + * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
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.
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.
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>
72 +#include "../codecs/jzcodec.h"
73 +#include "jz4740-pcm.h"
74 +#include "jz4740-i2s.h"
76 +#define N526_AMP_EN_GPIO JZ_GPIO_PORTD(4)
78 +static int n526_spk_event(struct snd_soc_dapm_widget *widget,
79 + struct snd_kcontrol *ctrl, int event)
81 + gpio_set_value(N526_AMP_EN_GPIO, !SND_SOC_DAPM_EVENT_OFF(event));
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),
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"},
99 +static const struct snd_kcontrol_new n526_controls[] = {
100 + SOC_DAPM_PIN_SWITCH("Speaker"),
103 +#define N526_DAIFMT (SND_SOC_DAIFMT_I2S | \
104 + SND_SOC_DAIFMT_NB_NF | \
105 + SND_SOC_DAIFMT_CBM_CFM)
107 +static int n526_codec_init(struct snd_soc_codec *codec)
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;
113 + snd_soc_dapm_nc_pin(codec, "LIN");
114 + snd_soc_dapm_nc_pin(codec, "RIN");
116 + ret = snd_soc_dai_set_fmt(codec_dai, N526_DAIFMT);
118 + dev_err(codec->dev, "Failed to set codec dai format: %d\n", ret);
122 + ret = snd_soc_dai_set_fmt(cpu_dai, N526_DAIFMT);
124 + dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
128 + ret = snd_soc_dai_set_sysclk(codec_dai, JZCODEC_SYSCLK, 111,
131 + dev_err(codec->dev, "Failed to set codec dai sysclk: %d\n", ret);
135 + snd_soc_dapm_new_controls(codec, n526_widgets, ARRAY_SIZE(n526_widgets));
137 + snd_soc_add_controls(codec, n526_controls,
138 + ARRAY_SIZE(n526_controls));
140 + snd_soc_dapm_add_routes(codec, n526_routes, ARRAY_SIZE(n526_routes));
142 + snd_soc_dapm_sync(codec);
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,
155 +static struct snd_soc_card n526 = {
157 + .dai_link = &n526_dai,
159 + .platform = &jz4740_soc_platform,
162 +static struct snd_soc_device n526_snd_devdata = {
164 + .codec_dev = &soc_codec_dev_jzcodec,
167 +static struct platform_device *n526_snd_device;
169 +static int __init n526_init(void)
173 + n526_snd_device = platform_device_alloc("soc-audio", -1);
175 + if (!n526_snd_device)
178 + ret = gpio_request(N526_AMP_EN_GPIO, "AMP");
180 + pr_err("n526 snd: Failed to request AMP GPIO(%d): %d\n",
181 + N526_AMP_EN_GPIO, ret);
182 + goto err_device_put;
185 + gpio_direction_output(JZ_GPIO_PORTD(4), 0);
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);
191 + pr_err("n526 snd: Failed to add snd soc device: %d\n", ret);
192 + goto err_unset_pdata;
198 + platform_set_drvdata(n526_snd_device, NULL);
199 + gpio_free(N526_AMP_EN_GPIO);
201 + platform_device_put(n526_snd_device);
205 +module_init(n526_init);
207 +static void __exit n526_exit(void)
209 + gpio_free(N526_AMP_EN_GPIO);
210 + platform_device_unregister(n526_snd_device);
212 +module_exit(n526_exit);
214 +MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
215 +MODULE_DESCRIPTION("ALSA SoC N526 audio support");
216 +MODULE_LICENSE("GPL v2");