Date:2010-04-24 12:36:15 (13 years 7 months ago)
Author:Lars C.
Commit:46503c75486bfd00511e0c25c98481652d87ec17
Message:Add qi_lb60 SoC sound board driver

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

Change Details

sound/soc/jz4740/Kconfig
1111    tristate "SoC Audio (I2S protocol) for Ingenic jz4740 chip"
1212    help
1313      Say Y if you want to use I2S protocol and I2S codec on Ingenic Jz4740 QI_LB60 board.
14
15config SND_JZ4740_SOC_QI_LB60
16    tristate "SoC Audio support for Qi Hardware Ben Nanonote"
17    depends on SND_JZ4740_SOC && JZ4740_QI_LB60
18    select SND_JZ4740_SOC_I2S
19    select SND_SOC_JZCODEC
20    help
21      Say Y if you want to add support for SoC audio of internal codec on Ingenic Jz4740 QI_LB60 board.
sound/soc/jz4740/Makefile
77obj-$(CONFIG_SND_JZ4740_SOC) += snd-soc-jz4740.o
88obj-$(CONFIG_SND_JZ4740_SOC_I2S) += snd-soc-jz4740-i2s.o
99
10# Jz4740 Machine Support
11snd-soc-qi-lb60-objs := qi_lb60.o
12
13obj-$(CONFIG_SND_JZ4740_SOC_QI_LB60) += snd-soc-qi-lb60.o
sound/soc/jz4740/qi_lb60.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
30#define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29)
31#define QI_LB60_AMP_GPIO JZ_GPIO_PORTD(4)
32
33static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget,
34                 struct snd_kcontrol *ctrl, int event)
35{
36    int on = 0;
37    if (event & SND_SOC_DAPM_POST_PMU)
38        on = 1;
39    else if (event & SND_SOC_DAPM_PRE_PMD)
40        on = 0;
41
42    gpio_set_value(QI_LB60_SND_GPIO, on);
43    gpio_set_value(QI_LB60_AMP_GPIO, on);
44
45    return 0;
46}
47
48static const struct snd_soc_dapm_widget qi_lb60_widgets[] = {
49    SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event),
50    SND_SOC_DAPM_MIC("Mic", NULL),
51};
52
53static const struct snd_soc_dapm_route qi_lb60_routes[] = {
54    {"Mic", NULL, "MIC"},
55    {"Speaker", NULL, "LOUT"},
56    {"Speaker", NULL, "ROUT"},
57};
58
59#define QI_LB60_DAIFMT (SND_SOC_DAIFMT_I2S | \
60            SND_SOC_DAIFMT_NB_NF | \
61            SND_SOC_DAIFMT_CBM_CFM)
62
63static int qi_lb60_codec_init(struct snd_soc_codec *codec)
64{
65    int ret;
66    struct snd_soc_dai *cpu_dai = codec->socdev->card->dai_link->cpu_dai;
67    struct snd_soc_dai *codec_dai = codec->socdev->card->dai_link->codec_dai;
68
69    snd_soc_dapm_nc_pin(codec, "LIN");
70    snd_soc_dapm_nc_pin(codec, "RIN");
71
72    ret = snd_soc_dai_set_fmt(codec_dai, QI_LB60_DAIFMT);
73    if (ret < 0) {
74        dev_err(codec->dev, "Failed to set codec dai format: %d\n", ret);
75        return ret;
76    }
77
78    ret = snd_soc_dai_set_fmt(cpu_dai, QI_LB60_DAIFMT);
79    if (ret < 0) {
80        dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
81        return ret;
82    }
83
84    ret = snd_soc_dai_set_sysclk(codec_dai, JZCODEC_SYSCLK, 111,
85        SND_SOC_CLOCK_IN);
86    if (ret < 0) {
87        dev_err(codec->dev, "Failed to set codec dai sysclk: %d\n", ret);
88        return ret;
89    }
90
91    snd_soc_dapm_new_controls(codec, qi_lb60_widgets, ARRAY_SIZE(qi_lb60_widgets));
92
93    snd_soc_dapm_add_routes(codec, qi_lb60_routes, ARRAY_SIZE(qi_lb60_routes));
94
95    snd_soc_dapm_sync(codec);
96
97    return 0;
98}
99
100static struct snd_soc_dai_link qi_lb60_dai = {
101    .name = "jz-codec",
102    .stream_name = "JZCODEC",
103    .cpu_dai = &jz4740_i2s_dai,
104    .codec_dai = &jz_codec_dai,
105    .init = qi_lb60_codec_init,
106};
107
108static struct snd_soc_card qi_lb60 = {
109    .name = "QI LB60",
110    .dai_link = &qi_lb60_dai,
111    .num_links = 1,
112    .platform = &jz4740_soc_platform,
113};
114
115static struct snd_soc_device qi_lb60_snd_devdata = {
116    .card = &qi_lb60,
117    .codec_dev = &soc_codec_dev_jzcodec,
118};
119
120static struct platform_device *qi_lb60_snd_device;
121
122static int __init qi_lb60_init(void)
123{
124    int ret;
125
126    qi_lb60_snd_device = platform_device_alloc("soc-audio", -1);
127
128    if (!qi_lb60_snd_device)
129        return -ENOMEM;
130
131
132    ret = gpio_request(QI_LB60_SND_GPIO, "SND");
133    if (ret) {
134        pr_err("qi_lb60 snd: Failed to request SND GPIO(%d): %d\n",
135                QI_LB60_SND_GPIO, ret);
136        goto err_device_put;
137    }
138
139    ret = gpio_request(QI_LB60_AMP_GPIO, "AMP");
140    if (ret) {
141        pr_err("qi_lb60 snd: Failed to request AMP GPIO(%d): %d\n",
142                QI_LB60_AMP_GPIO, ret);
143        goto err_gpio_free_snd;
144    }
145
146    gpio_direction_output(JZ_GPIO_PORTB(29), 0);
147    gpio_direction_output(JZ_GPIO_PORTD(4), 0);
148
149    platform_set_drvdata(qi_lb60_snd_device, &qi_lb60_snd_devdata);
150    qi_lb60_snd_devdata.dev = &qi_lb60_snd_device->dev;
151    ret = platform_device_add(qi_lb60_snd_device);
152    if (ret) {
153        pr_err("qi_lb60 snd: Failed to add snd soc device: %d\n", ret);
154        goto err_unset_pdata;
155    }
156
157     return 0;
158
159err_unset_pdata:
160    platform_set_drvdata(qi_lb60_snd_device, NULL);
161/*err_gpio_free_amp:*/
162    gpio_free(QI_LB60_AMP_GPIO);
163err_gpio_free_snd:
164    gpio_free(QI_LB60_SND_GPIO);
165err_device_put:
166    platform_device_put(qi_lb60_snd_device);
167
168    return ret;
169}
170module_init(qi_lb60_init);
171
172static void __exit qi_lb60_exit(void)
173{
174    gpio_free(QI_LB60_AMP_GPIO);
175    gpio_free(QI_LB60_SND_GPIO);
176    platform_device_unregister(qi_lb60_snd_device);
177}
178module_exit(qi_lb60_exit);
179
180MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
181MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
182MODULE_LICENSE("GPL v2");

Archive Download the corresponding diff file



interactive