]>
Commit | Line | Data |
---|---|---|
49bdb044 | 1 | /* |
2 | * Rockchip machine ASoC driver for boards using a MAX90809 CODEC. | |
3 | * | |
4 | * Copyright (c) 2014, ROCKCHIP CORPORATION. All rights reserved. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms and conditions of the GNU General Public License, | |
8 | * version 2, as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | * | |
18 | */ | |
19 | ||
20 | #include <linux/module.h> | |
21 | #include <linux/platform_device.h> | |
22 | #include <linux/slab.h> | |
23 | #include <linux/gpio.h> | |
24 | #include <linux/of_gpio.h> | |
25 | #include <sound/core.h> | |
26 | #include <sound/jack.h> | |
27 | #include <sound/pcm.h> | |
28 | #include <sound/pcm_params.h> | |
29 | #include <sound/soc.h> | |
30 | ||
31 | #include "rockchip_i2s.h" | |
32 | #include "../codecs/ts3a227e.h" | |
33 | ||
34 | #define DRV_NAME "rockchip-snd-max98090" | |
35 | ||
36 | static struct snd_soc_jack headset_jack; | |
37 | static struct snd_soc_jack_pin headset_jack_pins[] = { | |
38 | { | |
39 | .pin = "Headset Jack", | |
40 | .mask = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE | | |
41 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | | |
42 | SND_JACK_BTN_2 | SND_JACK_BTN_3, | |
43 | }, | |
44 | }; | |
45 | ||
46 | static const struct snd_soc_dapm_widget rk_dapm_widgets[] = { | |
47 | SND_SOC_DAPM_HP("Headphone", NULL), | |
48 | SND_SOC_DAPM_MIC("Headset Mic", NULL), | |
49 | SND_SOC_DAPM_MIC("Int Mic", NULL), | |
50 | SND_SOC_DAPM_SPK("Speaker", NULL), | |
51 | }; | |
52 | ||
53 | static const struct snd_soc_dapm_route rk_audio_map[] = { | |
54 | {"IN34", NULL, "Headset Mic"}, | |
55 | {"IN34", NULL, "MICBIAS"}, | |
ec0d23b2 | 56 | {"Headset Mic", NULL, "MICBIAS"}, |
49bdb044 | 57 | {"DMICL", NULL, "Int Mic"}, |
58 | {"Headphone", NULL, "HPL"}, | |
59 | {"Headphone", NULL, "HPR"}, | |
60 | {"Speaker", NULL, "SPKL"}, | |
61 | {"Speaker", NULL, "SPKR"}, | |
62 | }; | |
63 | ||
64 | static const struct snd_kcontrol_new rk_mc_controls[] = { | |
65 | SOC_DAPM_PIN_SWITCH("Headphone"), | |
66 | SOC_DAPM_PIN_SWITCH("Headset Mic"), | |
67 | SOC_DAPM_PIN_SWITCH("Int Mic"), | |
68 | SOC_DAPM_PIN_SWITCH("Speaker"), | |
69 | }; | |
70 | ||
71 | static int rk_aif1_hw_params(struct snd_pcm_substream *substream, | |
72 | struct snd_pcm_hw_params *params) | |
73 | { | |
74 | int ret = 0; | |
75 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
76 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | |
77 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | |
78 | int mclk; | |
79 | ||
80 | switch (params_rate(params)) { | |
81 | case 8000: | |
82 | case 16000: | |
a4ebd380 CW |
83 | case 24000: |
84 | case 32000: | |
49bdb044 | 85 | case 48000: |
a4ebd380 | 86 | case 64000: |
49bdb044 | 87 | case 96000: |
88 | mclk = 12288000; | |
89 | break; | |
a4ebd380 CW |
90 | case 11025: |
91 | case 22050: | |
49bdb044 | 92 | case 44100: |
a4ebd380 | 93 | case 88200: |
49bdb044 | 94 | mclk = 11289600; |
95 | break; | |
96 | default: | |
97 | return -EINVAL; | |
98 | } | |
99 | ||
100 | ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, | |
101 | SND_SOC_CLOCK_OUT); | |
102 | if (ret < 0) { | |
103 | dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret); | |
104 | return ret; | |
105 | } | |
106 | ||
107 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, | |
108 | SND_SOC_CLOCK_IN); | |
109 | if (ret < 0) { | |
110 | dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret); | |
111 | return ret; | |
112 | } | |
113 | ||
114 | return ret; | |
115 | } | |
116 | ||
49bdb044 | 117 | static struct snd_soc_ops rk_aif1_ops = { |
118 | .hw_params = rk_aif1_hw_params, | |
119 | }; | |
120 | ||
49bdb044 | 121 | static struct snd_soc_dai_link rk_dailink = { |
122 | .name = "max98090", | |
123 | .stream_name = "Audio", | |
124 | .codec_dai_name = "HiFi", | |
49bdb044 | 125 | .ops = &rk_aif1_ops, |
126 | /* set max98090 as slave */ | |
127 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | | |
128 | SND_SOC_DAIFMT_CBS_CFS, | |
129 | }; | |
130 | ||
5f224493 EBS |
131 | static int rk_98090_headset_init(struct snd_soc_component *component); |
132 | ||
133 | static struct snd_soc_aux_dev rk_98090_headset_dev = { | |
134 | .name = "Headset Chip", | |
135 | .init = rk_98090_headset_init, | |
136 | }; | |
137 | ||
49bdb044 | 138 | static struct snd_soc_card snd_soc_card_rk = { |
139 | .name = "ROCKCHIP-I2S", | |
54d8697f | 140 | .owner = THIS_MODULE, |
49bdb044 | 141 | .dai_link = &rk_dailink, |
142 | .num_links = 1, | |
143 | .aux_dev = &rk_98090_headset_dev, | |
144 | .num_aux_devs = 1, | |
145 | .dapm_widgets = rk_dapm_widgets, | |
146 | .num_dapm_widgets = ARRAY_SIZE(rk_dapm_widgets), | |
147 | .dapm_routes = rk_audio_map, | |
148 | .num_dapm_routes = ARRAY_SIZE(rk_audio_map), | |
149 | .controls = rk_mc_controls, | |
150 | .num_controls = ARRAY_SIZE(rk_mc_controls), | |
151 | }; | |
152 | ||
5f224493 EBS |
153 | static int rk_98090_headset_init(struct snd_soc_component *component) |
154 | { | |
155 | int ret; | |
156 | ||
157 | /* Enable Headset and 4 Buttons Jack detection */ | |
158 | ret = snd_soc_card_jack_new(&snd_soc_card_rk, "Headset Jack", | |
159 | SND_JACK_HEADSET | | |
160 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | | |
161 | SND_JACK_BTN_2 | SND_JACK_BTN_3, | |
162 | &headset_jack, | |
163 | headset_jack_pins, | |
164 | ARRAY_SIZE(headset_jack_pins)); | |
165 | if (ret) | |
166 | return ret; | |
167 | ||
168 | ret = ts3a227e_enable_jack_detect(component, &headset_jack); | |
169 | ||
170 | return ret; | |
171 | } | |
172 | ||
49bdb044 | 173 | static int snd_rk_mc_probe(struct platform_device *pdev) |
174 | { | |
175 | int ret = 0; | |
176 | struct snd_soc_card *card = &snd_soc_card_rk; | |
177 | struct device_node *np = pdev->dev.of_node; | |
178 | ||
179 | /* register the soc card */ | |
180 | card->dev = &pdev->dev; | |
181 | ||
182 | rk_dailink.codec_of_node = of_parse_phandle(np, | |
183 | "rockchip,audio-codec", 0); | |
184 | if (!rk_dailink.codec_of_node) { | |
185 | dev_err(&pdev->dev, | |
186 | "Property 'rockchip,audio-codec' missing or invalid\n"); | |
187 | return -EINVAL; | |
188 | } | |
189 | ||
190 | rk_dailink.cpu_of_node = of_parse_phandle(np, | |
191 | "rockchip,i2s-controller", 0); | |
192 | if (!rk_dailink.cpu_of_node) { | |
193 | dev_err(&pdev->dev, | |
194 | "Property 'rockchip,i2s-controller' missing or invalid\n"); | |
195 | return -EINVAL; | |
196 | } | |
197 | ||
198 | rk_dailink.platform_of_node = rk_dailink.cpu_of_node; | |
199 | ||
200 | rk_98090_headset_dev.codec_of_node = of_parse_phandle(np, | |
201 | "rockchip,headset-codec", 0); | |
202 | if (!rk_98090_headset_dev.codec_of_node) { | |
203 | dev_err(&pdev->dev, | |
204 | "Property 'rockchip,headset-codec' missing/invalid\n"); | |
205 | return -EINVAL; | |
206 | } | |
207 | ||
208 | ret = snd_soc_of_parse_card_name(card, "rockchip,model"); | |
209 | if (ret) { | |
210 | dev_err(&pdev->dev, | |
211 | "Soc parse card name failed %d\n", ret); | |
212 | return ret; | |
213 | } | |
214 | ||
215 | ret = devm_snd_soc_register_card(&pdev->dev, card); | |
216 | if (ret) { | |
217 | dev_err(&pdev->dev, | |
218 | "Soc register card failed %d\n", ret); | |
219 | return ret; | |
220 | } | |
221 | ||
222 | return ret; | |
223 | } | |
224 | ||
225 | static const struct of_device_id rockchip_max98090_of_match[] = { | |
226 | { .compatible = "rockchip,rockchip-audio-max98090", }, | |
227 | {}, | |
228 | }; | |
229 | ||
230 | MODULE_DEVICE_TABLE(of, rockchip_max98090_of_match); | |
231 | ||
232 | static struct platform_driver snd_rk_mc_driver = { | |
233 | .probe = snd_rk_mc_probe, | |
234 | .driver = { | |
235 | .name = DRV_NAME, | |
49bdb044 | 236 | .pm = &snd_soc_pm_ops, |
237 | .of_match_table = rockchip_max98090_of_match, | |
238 | }, | |
239 | }; | |
240 | ||
241 | module_platform_driver(snd_rk_mc_driver); | |
242 | ||
243 | MODULE_AUTHOR("jianqun <jay.xu@rock-chips.com>"); | |
244 | MODULE_DESCRIPTION("Rockchip max98090 machine ASoC driver"); | |
245 | MODULE_LICENSE("GPL v2"); | |
246 | MODULE_ALIAS("platform:" DRV_NAME); |