Root/
Source at commit 653678783eaceabb6bc7461a1411f2264b8219eb created 12 years 7 months ago. By Maarten ter Huurne, MIPS: A320: Add SoC sound support for Dingoo A320 | |
---|---|
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_card_controls(rtd->card, a320_controls, |
81 | ARRAY_SIZE(a320_controls)); |
82 | |
83 | snd_soc_dapm_new_controls(dapm, a320_widgets, ARRAY_SIZE(a320_widgets)); |
84 | snd_soc_dapm_add_routes(dapm, a320_routes, ARRAY_SIZE(a320_routes)); |
85 | snd_soc_dapm_sync(dapm); |
86 | |
87 | return 0; |
88 | } |
89 | |
90 | static struct snd_soc_dai_link a320_dai = { |
91 | .name = "jz4740", |
92 | .stream_name = "jz4740", |
93 | .cpu_dai_name = "jz4740-i2s", |
94 | .platform_name = "jz4740-pcm-audio", |
95 | .codec_dai_name = "jz4740-hifi", |
96 | .codec_name = "jz4740-codec", |
97 | .init = a320_codec_init, |
98 | }; |
99 | |
100 | static struct snd_soc_card a320 = { |
101 | .name = "Dingoo A320", |
102 | .owner = THIS_MODULE, |
103 | .dai_link = &a320_dai, |
104 | .num_links = 1, |
105 | }; |
106 | |
107 | static int __devinit a320_probe(struct platform_device *pdev) |
108 | { |
109 | struct snd_soc_card *card = &a320; |
110 | int ret; |
111 | |
112 | ret = gpio_request(A320_SPK_GPIO, "SPK"); |
113 | if (ret) { |
114 | dev_err(&pdev->dev, "Failed to request SPK GPIO(%d): %d\n", |
115 | A320_SPK_GPIO, ret); |
116 | return ret; |
117 | } |
118 | |
119 | ret = gpio_request(A320_HPTV_GPIO, "HPTV"); |
120 | if (ret) { |
121 | dev_err(&pdev->dev, "Failed to request HPTV GPIO(%d): %d\n", |
122 | A320_HPTV_GPIO, ret); |
123 | goto err_gpio_free_spk; |
124 | } |
125 | |
126 | gpio_direction_output(A320_SPK_GPIO, 0); |
127 | gpio_direction_output(A320_HPTV_GPIO, 0); |
128 | |
129 | card->dev = &pdev->dev; |
130 | |
131 | ret = snd_soc_register_card(card); |
132 | if (ret) { |
133 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", |
134 | ret); |
135 | goto err_gpio_free_hptv; |
136 | } |
137 | |
138 | return 0; |
139 | |
140 | err_gpio_free_hptv: |
141 | gpio_free(A320_HPTV_GPIO); |
142 | err_gpio_free_spk: |
143 | gpio_free(A320_SPK_GPIO); |
144 | |
145 | return ret; |
146 | } |
147 | |
148 | static int __devexit a320_remove(struct platform_device *pdev) |
149 | { |
150 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
151 | |
152 | snd_soc_unregister_card(card); |
153 | gpio_free(A320_HPTV_GPIO); |
154 | gpio_free(A320_SPK_GPIO); |
155 | return 0; |
156 | } |
157 | |
158 | static struct platform_driver a320_driver = { |
159 | .driver = { |
160 | .name = "a320-audio", |
161 | .owner = THIS_MODULE, |
162 | }, |
163 | .probe = a320_probe, |
164 | .remove = __devexit_p(a320_remove), |
165 | }; |
166 | |
167 | module_platform_driver(a320_driver); |
168 | |
169 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>, Maarten ter Huurne <maarten@treewalker.org>, Paul Cercueil <paul@crapouillou.net>"); |
170 | MODULE_DESCRIPTION("ALSA SoC Dingoo A320 Audio support"); |
171 | MODULE_LICENSE("GPL v2"); |
172 | MODULE_ALIAS("platform:a320-audio"); |
173 |
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