1 From d2e198ed9ade74e2cb042ade405071ab58b11e33 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 --- 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_JZCODEC
18 Say Y if you want to enable support for SoC audio on the Hanvon N516.
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_JZCODEC
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
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
39 +++ b/sound/soc/jz4740/n526.c
42 + * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
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.
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.
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>
65 +#include "../codecs/jzcodec.h"
66 +#include "jz4740-pcm.h"
67 +#include "jz4740-i2s.h"
69 +#define N526_AMP_EN_GPIO JZ_GPIO_PORTD(4)
71 +static int n526_spk_event(struct snd_soc_dapm_widget *widget,
72 + struct snd_kcontrol *ctrl, int event)
74 + gpio_set_value(N526_AMP_EN_GPIO, !SND_SOC_DAPM_EVENT_OFF(event));
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),
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"},
92 +static const struct snd_kcontrol_new n526_controls[] = {
93 + SOC_DAPM_PIN_SWITCH("Speaker"),
96 +#define N526_DAIFMT (SND_SOC_DAIFMT_I2S | \
97 + SND_SOC_DAIFMT_NB_NF | \
98 + SND_SOC_DAIFMT_CBM_CFM)
100 +static int n526_codec_init(struct snd_soc_codec *codec)
103 + struct snd_soc_dai *cpu_dai = codec->socdev->card->dai_link->cpu_dai;
104 + struct snd_soc_dai *codec_dai = codec->socdev->card->dai_link->codec_dai;
106 + snd_soc_dapm_nc_pin(codec, "LIN");
107 + snd_soc_dapm_nc_pin(codec, "RIN");
109 + ret = snd_soc_dai_set_fmt(codec_dai, N526_DAIFMT);
111 + dev_err(codec->dev, "Failed to set codec dai format: %d\n", ret);
115 + ret = snd_soc_dai_set_fmt(cpu_dai, N526_DAIFMT);
117 + dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
121 + ret = snd_soc_dai_set_sysclk(codec_dai, JZCODEC_SYSCLK, 111,
124 + dev_err(codec->dev, "Failed to set codec dai sysclk: %d\n", ret);
128 + snd_soc_dapm_new_controls(codec, n526_widgets, ARRAY_SIZE(n526_widgets));
130 + snd_soc_add_controls(codec, n526_controls,
131 + ARRAY_SIZE(n526_controls));
133 + snd_soc_dapm_add_routes(codec, n526_routes, ARRAY_SIZE(n526_routes));
135 + snd_soc_dapm_sync(codec);
140 +static struct snd_soc_dai_link n526_dai = {
141 + .name = "jz-codec",
142 + .stream_name = "JZCODEC",
143 + .cpu_dai = &jz4740_i2s_dai,
144 + .codec_dai = &jz_codec_dai,
145 + .init = n526_codec_init,
148 +static struct snd_soc_card n526 = {
150 + .dai_link = &n526_dai,
152 + .platform = &jz4740_soc_platform,
155 +static struct snd_soc_device n526_snd_devdata = {
157 + .codec_dev = &soc_codec_dev_jzcodec,
160 +static struct platform_device *n526_snd_device;
162 +static int __init n526_init(void)
166 + n526_snd_device = platform_device_alloc("soc-audio", -1);
168 + if (!n526_snd_device)
171 + ret = gpio_request(N526_AMP_EN_GPIO, "AMP");
173 + pr_err("n526 snd: Failed to request AMP GPIO(%d): %d\n",
174 + N526_AMP_EN_GPIO, ret);
175 + goto err_device_put;
178 + gpio_direction_output(JZ_GPIO_PORTD(4), 0);
180 + platform_set_drvdata(n526_snd_device, &n526_snd_devdata);
181 + n526_snd_devdata.dev = &n526_snd_device->dev;
182 + ret = platform_device_add(n526_snd_device);
184 + pr_err("n526 snd: Failed to add snd soc device: %d\n", ret);
185 + goto err_unset_pdata;
191 + platform_set_drvdata(n526_snd_device, NULL);
192 + gpio_free(N526_AMP_EN_GPIO);
194 + platform_device_put(n526_snd_device);
198 +module_init(n526_init);
200 +static void __exit n526_exit(void)
202 + gpio_free(N526_AMP_EN_GPIO);
203 + platform_device_unregister(n526_snd_device);
205 +module_exit(n526_exit);
207 +MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
208 +MODULE_DESCRIPTION("ALSA SoC N526 audio support");
209 +MODULE_LICENSE("GPL v2");