Date:2010-04-24 12:38:41 (13 years 11 months ago)
Author:Lars C.
Commit:636d1593a14007696939759844aef2dcf99f68f8
Message:Add N526 sound SoC board driver

Files: sound/soc/jz4740/Kconfig (1 diff)
sound/soc/jz4740/Makefile (1 diff)
sound/soc/jz4740/n526.c (1 diff)

Change Details

sound/soc/jz4740/Kconfig
2929    select SND_SOC_JZCODEC
3030    help
3131      Say Y if you want to enable support for SoC audio on the Hanvon N516.
32
33config SND_JZ4740_SOC_N526
34    tristate "SoC Audio support for Hanvon N526 eBook reader"
35    depends on SND_JZ4740_SOC && JZ4740_N526
36    select SND_JZ4740_SOC_I2S
37    select SND_SOC_JZCODEC
38    help
39      Say Y if you want to enable support for SoC audio on the Hanvon N526.
sound/soc/jz4740/Makefile
1010# Jz4740 Machine Support
1111snd-soc-qi-lb60-objs := qi_lb60.o
1212snd-soc-n516-objs := n516.o
13snd-soc-n526-objs := n526.o
1314
1415obj-$(CONFIG_SND_JZ4740_SOC_QI_LB60) += snd-soc-qi-lb60.o
1516obj-$(CONFIG_SND_JZ4740_SOC_N516) += snd-soc-n516.o
17obj-$(CONFIG_SND_JZ4740_SOC_N526) += snd-soc-n526.o
sound/soc/jz4740/n526.c
1/*
2 * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * You should have received a copy of the GNU General Public License along
9 * with this program; if not, write to the Free Software Foundation, Inc.,
10 * 675 Mass Ave, Cambridge, MA 02139, USA.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/timer.h>
17#include <linux/interrupt.h>
18#include <linux/platform_device.h>
19#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/soc.h>
22#include <sound/soc-dapm.h>
23#include <linux/gpio.h>
24
25#include "../codecs/jzcodec.h"
26#include "jz4740-pcm.h"
27#include "jz4740-i2s.h"
28
29#define N526_AMP_EN_GPIO JZ_GPIO_PORTD(4)
30
31static int n526_spk_event(struct snd_soc_dapm_widget *widget,
32                 struct snd_kcontrol *ctrl, int event)
33{
34    gpio_set_value(N526_AMP_EN_GPIO, !SND_SOC_DAPM_EVENT_OFF(event));
35    return 0;
36}
37
38static const struct snd_soc_dapm_widget n526_widgets[] = {
39    SND_SOC_DAPM_SPK("Speaker", n526_spk_event),
40    SND_SOC_DAPM_HP("Headphone", NULL),
41    SND_SOC_DAPM_MIC("Mic", NULL),
42};
43
44static const struct snd_soc_dapm_route n526_routes[] = {
45    {"Mic", NULL, "MIC"},
46    {"Speaker", NULL, "LOUT"},
47    {"Speaker", NULL, "ROUT"},
48    {"Headphone", NULL, "LOUT"},
49    {"Headphone", NULL, "ROUT"},
50};
51
52static const struct snd_kcontrol_new n526_controls[] = {
53    SOC_DAPM_PIN_SWITCH("Speaker"),
54};
55
56#define N526_DAIFMT (SND_SOC_DAIFMT_I2S | \
57            SND_SOC_DAIFMT_NB_NF | \
58            SND_SOC_DAIFMT_CBM_CFM)
59
60static int n526_codec_init(struct snd_soc_codec *codec)
61{
62    int ret;
63    struct snd_soc_dai *cpu_dai = codec->socdev->card->dai_link->cpu_dai;
64    struct snd_soc_dai *codec_dai = codec->socdev->card->dai_link->codec_dai;
65
66    snd_soc_dapm_nc_pin(codec, "LIN");
67    snd_soc_dapm_nc_pin(codec, "RIN");
68
69    ret = snd_soc_dai_set_fmt(codec_dai, N526_DAIFMT);
70    if (ret < 0) {
71        dev_err(codec->dev, "Failed to set codec dai format: %d\n", ret);
72        return ret;
73    }
74
75    ret = snd_soc_dai_set_fmt(cpu_dai, N526_DAIFMT);
76    if (ret < 0) {
77        dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
78        return ret;
79    }
80
81    ret = snd_soc_dai_set_sysclk(codec_dai, JZCODEC_SYSCLK, 111,
82        SND_SOC_CLOCK_IN);
83    if (ret < 0) {
84        dev_err(codec->dev, "Failed to set codec dai sysclk: %d\n", ret);
85        return ret;
86    }
87
88    snd_soc_dapm_new_controls(codec, n526_widgets, ARRAY_SIZE(n526_widgets));
89
90    snd_soc_add_controls(codec, n526_controls,
91                ARRAY_SIZE(n526_controls));
92
93    snd_soc_dapm_add_routes(codec, n526_routes, ARRAY_SIZE(n526_routes));
94
95    snd_soc_dapm_sync(codec);
96
97    return 0;
98}
99
100static struct snd_soc_dai_link n526_dai = {
101    .name = "jz-codec",
102    .stream_name = "JZCODEC",
103    .cpu_dai = &jz4740_i2s_dai,
104    .codec_dai = &jz_codec_dai,
105    .init = n526_codec_init,
106};
107
108static struct snd_soc_card n526 = {
109    .name = "N526",
110    .dai_link = &n526_dai,
111    .num_links = 1,
112    .platform = &jz4740_soc_platform,
113};
114
115static struct snd_soc_device n526_snd_devdata = {
116    .card = &n526,
117    .codec_dev = &soc_codec_dev_jzcodec,
118};
119
120static struct platform_device *n526_snd_device;
121
122static int __init n526_init(void)
123{
124    int ret;
125
126    n526_snd_device = platform_device_alloc("soc-audio", -1);
127
128    if (!n526_snd_device)
129        return -ENOMEM;
130
131    ret = gpio_request(N526_AMP_EN_GPIO, "AMP");
132    if (ret) {
133        pr_err("n526 snd: Failed to request AMP GPIO(%d): %d\n",
134                N526_AMP_EN_GPIO, ret);
135        goto err_device_put;
136    }
137
138    gpio_direction_output(JZ_GPIO_PORTD(4), 0);
139
140    platform_set_drvdata(n526_snd_device, &n526_snd_devdata);
141    n526_snd_devdata.dev = &n526_snd_device->dev;
142    ret = platform_device_add(n526_snd_device);
143    if (ret) {
144        pr_err("n526 snd: Failed to add snd soc device: %d\n", ret);
145        goto err_unset_pdata;
146    }
147
148     return 0;
149
150err_unset_pdata:
151    platform_set_drvdata(n526_snd_device, NULL);
152    gpio_free(N526_AMP_EN_GPIO);
153err_device_put:
154    platform_device_put(n526_snd_device);
155
156    return ret;
157}
158module_init(n526_init);
159
160static void __exit n526_exit(void)
161{
162    gpio_free(N526_AMP_EN_GPIO);
163    platform_device_unregister(n526_snd_device);
164}
165module_exit(n526_exit);
166
167MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
168MODULE_DESCRIPTION("ALSA SoC N526 audio support");
169MODULE_LICENSE("GPL v2");

Archive Download the corresponding diff file



interactive