Root/sound/soc/jz4740/a320.c

Source at commit 032d0e3323c0f8c69ab1e1aed6c82ebabe1e381f created 8 years 7 months ago.
By Maarten ter Huurne, ASoC: jz4740: A320: Add .owner to struct snd_soc_card
1/*
2 * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
3 * Copyright (C) 2010-2011, Maarten ter Huurne <maarten@treewalker.org>
4 * Copyright (C) 2011, Paul Cercueil <paul@crapouillou.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * You should have received a copy of the GNU General Public License along
11 * with this program; if not, write to the Free Software Foundation, Inc.,
12 * 675 Mass Ave, Cambridge, MA 02139, USA.
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/moduleparam.h>
18#include <linux/timer.h>
19#include <linux/interrupt.h>
20#include <linux/platform_device.h>
21#include <sound/core.h>
22#include <sound/pcm.h>
23#include <sound/soc.h>
24#include <linux/gpio.h>
25
26#define A320_SPK_GPIO JZ_GPIO_PORTC(27)
27#define A320_HPTV_GPIO JZ_GPIO_PORTD(7)
28
29static int a320_spk_event(struct snd_soc_dapm_widget *widget,
30              struct snd_kcontrol *ctrl, int event)
31{
32    gpio_set_value(A320_SPK_GPIO, SND_SOC_DAPM_EVENT_ON(event));
33    return 0;
34}
35
36static int a320_hptv_event(
37            struct snd_soc_dapm_widget *widget,
38            struct snd_kcontrol *ctrl, int event)
39{
40    gpio_set_value(A320_HPTV_GPIO, SND_SOC_DAPM_EVENT_ON(event));
41    return 0;
42}
43
44static const struct snd_kcontrol_new a320_controls[] = {
45    SOC_DAPM_PIN_SWITCH("Speaker"),
46    SOC_DAPM_PIN_SWITCH("Headphones + TV-out"),
47};
48
49static const struct snd_soc_dapm_widget a320_widgets[] = {
50    SND_SOC_DAPM_MIC("Mic", NULL),
51    SND_SOC_DAPM_SPK("Speaker", a320_spk_event),
52    SND_SOC_DAPM_LINE("Headphones + TV-out", a320_hptv_event),
53};
54
55static const struct snd_soc_dapm_route a320_routes[] = {
56    {"Mic", NULL, "MIC"},
57    {"Speaker", NULL, "LOUT"},
58    {"Speaker", NULL, "ROUT"},
59    {"Headphones + TV-out", NULL, "LOUT"},
60    {"Headphones + TV-out", NULL, "ROUT"},
61};
62
63#define A320_DAIFMT (SND_SOC_DAIFMT_I2S | \
64             SND_SOC_DAIFMT_NB_NF | \
65             SND_SOC_DAIFMT_CBM_CFM)
66
67static int a320_codec_init(struct snd_soc_pcm_runtime *rtd)
68{
69    struct snd_soc_codec *codec = rtd->codec;
70    struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
71    struct snd_soc_dapm_context *dapm = &codec->dapm;
72    int ret;
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_add_controls(codec, a320_controls, ARRAY_SIZE(a320_controls));
81
82    snd_soc_dapm_new_controls(dapm, a320_widgets, ARRAY_SIZE(a320_widgets));
83    snd_soc_dapm_add_routes(dapm, a320_routes, ARRAY_SIZE(a320_routes));
84    snd_soc_dapm_sync(dapm);
85
86    return 0;
87}
88
89static struct snd_soc_dai_link a320_dai = {
90    .name = "jz4740",
91    .stream_name = "jz4740",
92    .cpu_dai_name = "jz4740-i2s",
93    .platform_name = "jz4740-pcm-audio",
94    .codec_dai_name = "jz4740-hifi",
95    .codec_name = "jz4740-codec",
96    .init = a320_codec_init,
97};
98
99static struct snd_soc_card a320 = {
100    .name = "Dingoo A320",
101    .owner = THIS_MODULE,
102    .dai_link = &a320_dai,
103    .num_links = 1,
104};
105
106static struct platform_device *a320_snd_device;
107
108static int __init a320_init(void)
109{
110    int ret;
111
112    a320_snd_device = platform_device_alloc("soc-audio", -1);
113
114    if (!a320_snd_device)
115        return -ENOMEM;
116
117    ret = gpio_request(A320_SPK_GPIO, "SPK");
118    if (ret) {
119        pr_err("a320 snd: Failed to request SPK GPIO(%d): %d\n",
120                A320_SPK_GPIO, ret);
121        goto err_device_put;
122    }
123
124    ret = gpio_request(A320_HPTV_GPIO, "HPTV");
125    if (ret) {
126        pr_err("a320 snd: Failed to request HPTV GPIO(%d): %d\n",
127                A320_HPTV_GPIO, ret);
128        goto err_gpio_free_spk;
129    }
130
131    gpio_direction_output(A320_SPK_GPIO, 0);
132    gpio_direction_output(A320_HPTV_GPIO, 0);
133
134    platform_set_drvdata(a320_snd_device, &a320);
135
136    ret = platform_device_add(a320_snd_device);
137    if (ret) {
138        pr_err("a320 snd: Failed to add snd soc device: %d\n", ret);
139        goto err_unset_pdata;
140    }
141
142     return 0;
143
144err_unset_pdata:
145    platform_set_drvdata(a320_snd_device, NULL);
146/*err_gpio_free_hptv:*/
147    gpio_free(A320_HPTV_GPIO);
148err_gpio_free_spk:
149    gpio_free(A320_SPK_GPIO);
150err_device_put:
151    platform_device_put(a320_snd_device);
152
153    return ret;
154}
155module_init(a320_init);
156
157static void __exit a320_exit(void)
158{
159    gpio_free(A320_HPTV_GPIO);
160    gpio_free(A320_SPK_GPIO);
161    platform_device_unregister(a320_snd_device);
162}
163module_exit(a320_exit);
164
165MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>, Maarten ter Huurne <maarten@treewalker.org>, Paul Cercueil <paul@crapouillou.net>");
166MODULE_DESCRIPTION("ALSA SoC Dingoo A320 Audio support");
167MODULE_LICENSE("GPL v2");
168

Archive Download this file



interactive