1 From b1c42b78b7bd779288f340e202820aa2c2cf6629 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_JZ4740_CODEC
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_JZ4740_CODEC
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/jz4740.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;
105 + snd_soc_dapm_nc_pin(codec, "LIN");
106 + snd_soc_dapm_nc_pin(codec, "RIN");
108 + ret = snd_soc_dai_set_fmt(cpu_dai, N526_DAIFMT);
110 + dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
114 + snd_soc_dapm_new_controls(codec, n526_widgets, ARRAY_SIZE(n526_widgets));
116 + snd_soc_add_controls(codec, n526_controls,
117 + ARRAY_SIZE(n526_controls));
119 + snd_soc_dapm_add_routes(codec, n526_routes, ARRAY_SIZE(n526_routes));
121 + snd_soc_dapm_sync(codec);
126 +static struct snd_soc_dai_link n526_dai = {
127 + .name = "jz-codec",
128 + .stream_name = "jz4740",
129 + .cpu_dai = &jz4740_i2s_dai,
130 + .codec_dai = &jz4740_codec_dai,
131 + .init = n526_codec_init,
134 +static struct snd_soc_card n526 = {
136 + .dai_link = &n526_dai,
138 + .platform = &jz4740_soc_platform,
141 +static struct snd_soc_device n526_snd_devdata = {
143 + .codec_dev = &soc_codec_dev_jz4740_codec,
146 +static struct platform_device *n526_snd_device;
148 +static int __init n526_init(void)
152 + n526_snd_device = platform_device_alloc("soc-audio", -1);
154 + if (!n526_snd_device)
157 + ret = gpio_request(N526_AMP_EN_GPIO, "AMP");
159 + pr_err("n526 snd: Failed to request AMP GPIO(%d): %d\n",
160 + N526_AMP_EN_GPIO, ret);
161 + goto err_device_put;
164 + gpio_direction_output(JZ_GPIO_PORTD(4), 0);
166 + platform_set_drvdata(n526_snd_device, &n526_snd_devdata);
167 + n526_snd_devdata.dev = &n526_snd_device->dev;
168 + ret = platform_device_add(n526_snd_device);
170 + pr_err("n526 snd: Failed to add snd soc device: %d\n", ret);
171 + goto err_unset_pdata;
177 + platform_set_drvdata(n526_snd_device, NULL);
178 + gpio_free(N526_AMP_EN_GPIO);
180 + platform_device_put(n526_snd_device);
184 +module_init(n526_init);
186 +static void __exit n526_exit(void)
188 + gpio_free(N526_AMP_EN_GPIO);
189 + platform_device_unregister(n526_snd_device);
191 +module_exit(n526_exit);
193 +MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
194 +MODULE_DESCRIPTION("ALSA SoC N526 audio support");
195 +MODULE_LICENSE("GPL v2");