Date:2010-08-29 06:47:27 (12 years 1 month ago)
Author:Maarten ter Huurne
Commit:c4d3c9e867996f17639c7633b04c10745d81e1e3
Message:a320 snd: Add SoC sound support for Dingoo A320.

Squashed commit based on the jz-2.6.35 branch.
Files: sound/soc/jz4740/Kconfig (1 diff)
sound/soc/jz4740/Makefile (1 diff)
sound/soc/jz4740/a320.c (1 diff)

Change Details

sound/soc/jz4740/Kconfig
3737    select SND_SOC_JZCODEC
3838    help
3939      Say Y if you want to enable support for SoC audio on the Hanvon N526.
40
41config SND_JZ4740_SOC_A320
42    bool "SoC Audio support for Dingoo A320"
43    depends on SND_JZ4740_SOC && JZ4740_A320
44    select SND_JZ4740_SOC_I2S
45    select SND_SOC_JZ4740_CODEC
46    help
47      Say Y if you want to add support for SoC audio on the Dingoo A320
48      game and media player.
sound/soc/jz4740/Makefile
1111snd-soc-qi-lb60-objs := qi_lb60.o
1212snd-soc-n516-objs := n516.o
1313snd-soc-n526-objs := n526.o
14snd-soc-a320-objs := a320.o
1415
1516obj-$(CONFIG_SND_JZ4740_SOC_QI_LB60) += snd-soc-qi-lb60.o
1617obj-$(CONFIG_SND_JZ4740_SOC_N516) += snd-soc-n516.o
1718obj-$(CONFIG_SND_JZ4740_SOC_N526) += snd-soc-n526.o
19obj-$(CONFIG_SND_JZ4740_SOC_A320) += snd-soc-a320.o
sound/soc/jz4740/a320.c
1/*
2 * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
3 * Copyright (C) 2010, Maarten ter Huurne <maarten@treewalker.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * You should have received a copy of the GNU General Public License along
10 * with this program; if not, write to the Free Software Foundation, Inc.,
11 * 675 Mass Ave, Cambridge, MA 02139, USA.
12 *
13 */
14
15#include <linux/module.h>
16#include <linux/moduleparam.h>
17#include <linux/timer.h>
18#include <linux/interrupt.h>
19#include <linux/platform_device.h>
20#include <sound/core.h>
21#include <sound/pcm.h>
22#include <sound/soc.h>
23#include <sound/soc-dapm.h>
24#include <linux/gpio.h>
25
26#include "../codecs/jz4740.h"
27#include "jz4740-pcm.h"
28#include "jz4740-i2s.h"
29
30
31// TODO(MtH): These GPIOs are related to audio according to booboo's notes,
32// but what they do exactly is not clear at the moment.
33#define A320_SND_GPIO JZ_GPIO_PORTC(27)
34#define A320_AMP_GPIO JZ_GPIO_PORTD(7)
35
36static int a320_spk_event(struct snd_soc_dapm_widget *widget,
37              struct snd_kcontrol *ctrl, int event)
38{
39    int on = 0;
40    if (event & SND_SOC_DAPM_POST_PMU)
41        on = 1;
42    else if (event & SND_SOC_DAPM_PRE_PMD)
43        on = 0;
44
45    gpio_set_value(A320_SND_GPIO, on);
46    gpio_set_value(A320_AMP_GPIO, on);
47
48    return 0;
49}
50
51static const struct snd_soc_dapm_widget a320_widgets[] = {
52    SND_SOC_DAPM_SPK("Speaker", a320_spk_event),
53    SND_SOC_DAPM_MIC("Mic", NULL),
54};
55
56static const struct snd_soc_dapm_route a320_routes[] = {
57    {"Mic", NULL, "MIC"},
58    {"Speaker", NULL, "LOUT"},
59    {"Speaker", NULL, "ROUT"},
60};
61
62#define A320_DAIFMT (SND_SOC_DAIFMT_I2S | \
63             SND_SOC_DAIFMT_NB_NF | \
64             SND_SOC_DAIFMT_CBM_CFM)
65
66static int a320_codec_init(struct snd_soc_codec *codec)
67{
68    int ret;
69    struct snd_soc_dai *cpu_dai = codec->socdev->card->dai_link->cpu_dai;
70
71    snd_soc_dapm_nc_pin(codec, "LIN");
72    snd_soc_dapm_nc_pin(codec, "RIN");
73
74    ret = snd_soc_dai_set_fmt(cpu_dai, A320_DAIFMT);
75    if (ret < 0) {
76        dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
77        return ret;
78    }
79
80    snd_soc_dapm_new_controls(codec, a320_widgets, ARRAY_SIZE(a320_widgets));
81    snd_soc_dapm_add_routes(codec, a320_routes, ARRAY_SIZE(a320_routes));
82    snd_soc_dapm_sync(codec);
83
84    return 0;
85}
86
87static struct snd_soc_dai_link a320_dai = {
88    .name = "jz4740",
89    .stream_name = "jz4740",
90    .cpu_dai = &jz4740_i2s_dai,
91    .codec_dai = &jz4740_codec_dai,
92    .init = a320_codec_init,
93};
94
95static struct snd_soc_card a320 = {
96    .name = "Dingoo A320",
97    .dai_link = &a320_dai,
98    .num_links = 1,
99    .platform = &jz4740_soc_platform,
100};
101
102static struct snd_soc_device a320_snd_devdata = {
103    .card = &a320,
104    .codec_dev = &soc_codec_dev_jz4740_codec,
105};
106
107static struct platform_device *a320_snd_device;
108
109static int __init a320_init(void)
110{
111    int ret;
112
113    a320_snd_device = platform_device_alloc("soc-audio", -1);
114
115    if (!a320_snd_device)
116        return -ENOMEM;
117
118    ret = gpio_request(A320_SND_GPIO, "SND");
119    if (ret) {
120        pr_err("a320 snd: Failed to request SND GPIO(%d): %d\n",
121                A320_SND_GPIO, ret);
122        goto err_device_put;
123    }
124
125    ret = gpio_request(A320_AMP_GPIO, "AMP");
126    if (ret) {
127        pr_err("a320 snd: Failed to request AMP GPIO(%d): %d\n",
128                A320_AMP_GPIO, ret);
129        goto err_gpio_free_snd;
130    }
131
132    gpio_direction_output(A320_SND_GPIO, 0);
133    gpio_direction_output(A320_AMP_GPIO, 0);
134
135    platform_set_drvdata(a320_snd_device, &a320_snd_devdata);
136    a320_snd_devdata.dev = &a320_snd_device->dev;
137    ret = platform_device_add(a320_snd_device);
138    if (ret) {
139        pr_err("a320 snd: Failed to add snd soc device: %d\n", ret);
140        goto err_unset_pdata;
141    }
142
143     return 0;
144
145err_unset_pdata:
146    platform_set_drvdata(a320_snd_device, NULL);
147/*err_gpio_free_amp:*/
148    gpio_free(A320_AMP_GPIO);
149err_gpio_free_snd:
150    gpio_free(A320_SND_GPIO);
151err_device_put:
152    platform_device_put(a320_snd_device);
153
154    return ret;
155}
156module_init(a320_init);
157
158static void __exit a320_exit(void)
159{
160    gpio_free(A320_AMP_GPIO);
161    gpio_free(A320_SND_GPIO);
162    platform_device_unregister(a320_snd_device);
163}
164module_exit(a320_exit);
165
166MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>, Maarten ter Huurne <maarten@treewalker.org>");
167MODULE_DESCRIPTION("ALSA SoC Dingoo A320 Audio support");
168MODULE_LICENSE("GPL v2");

Archive Download the corresponding diff file



interactive