Root/
Source at commit 032d0e3323c0f8c69ab1e1aed6c82ebabe1e381f created 11 years 11 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 | |
29 | static 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 | |
36 | static 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 | |
44 | static const struct snd_kcontrol_new a320_controls[] = { |
45 | SOC_DAPM_PIN_SWITCH("Speaker"), |
46 | SOC_DAPM_PIN_SWITCH("Headphones + TV-out"), |
47 | }; |
48 | |
49 | static 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 | |
55 | static 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 | |
67 | static 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 | |
89 | static 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 | |
99 | static struct snd_soc_card a320 = { |
100 | .name = "Dingoo A320", |
101 | .owner = THIS_MODULE, |
102 | .dai_link = &a320_dai, |
103 | .num_links = 1, |
104 | }; |
105 | |
106 | static struct platform_device *a320_snd_device; |
107 | |
108 | static 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 | |
144 | err_unset_pdata: |
145 | platform_set_drvdata(a320_snd_device, NULL); |
146 | /*err_gpio_free_hptv:*/ |
147 | gpio_free(A320_HPTV_GPIO); |
148 | err_gpio_free_spk: |
149 | gpio_free(A320_SPK_GPIO); |
150 | err_device_put: |
151 | platform_device_put(a320_snd_device); |
152 | |
153 | return ret; |
154 | } |
155 | module_init(a320_init); |
156 | |
157 | static 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 | } |
163 | module_exit(a320_exit); |
164 | |
165 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>, Maarten ter Huurne <maarten@treewalker.org>, Paul Cercueil <paul@crapouillou.net>"); |
166 | MODULE_DESCRIPTION("ALSA SoC Dingoo A320 Audio support"); |
167 | MODULE_LICENSE("GPL v2"); |
168 |
Branches:
ben-wpan
ben-wpan-stefan
javiroman/ks7010
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9