]>
Commit | Line | Data |
---|---|---|
58783faf | 1 | /* |
aef9a37c | 2 | * tegra_alc5632.c -- Toshiba AC100(PAZ00) machine ASoC driver |
1ae93b9d SW |
3 | * |
4 | * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net> | |
518de86b | 5 | * Copyright (C) 2012 - NVIDIA, Inc. |
1ae93b9d SW |
6 | * |
7 | * Authors: Leon Romanovsky <leon@leon.nu> | |
8 | * Andrey Danin <danindrey@mail.ru> | |
9 | * Marc Dietrich <marvin24@gmx.de> | |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License version 2 as | |
13 | * published by the Free Software Foundation. | |
14 | */ | |
58783faf LR |
15 | |
16 | #include <asm/mach-types.h> | |
17 | ||
18 | #include <linux/module.h> | |
19 | #include <linux/platform_device.h> | |
20 | #include <linux/slab.h> | |
21 | #include <linux/gpio.h> | |
d559f1e5 | 22 | #include <linux/of_gpio.h> |
58783faf LR |
23 | |
24 | #include <sound/core.h> | |
25 | #include <sound/jack.h> | |
26 | #include <sound/pcm.h> | |
27 | #include <sound/pcm_params.h> | |
28 | #include <sound/soc.h> | |
29 | ||
30 | #include "../codecs/alc5632.h" | |
31 | ||
58783faf LR |
32 | #include "tegra_asoc_utils.h" |
33 | ||
34 | #define DRV_NAME "tegra-alc5632" | |
35 | ||
36 | struct tegra_alc5632 { | |
37 | struct tegra_asoc_utils_data util_data; | |
d559f1e5 | 38 | int gpio_hp_det; |
58783faf LR |
39 | }; |
40 | ||
41 | static int tegra_alc5632_asoc_hw_params(struct snd_pcm_substream *substream, | |
42 | struct snd_pcm_hw_params *params) | |
43 | { | |
44 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
45 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | |
40db77a0 | 46 | struct snd_soc_codec *codec = codec_dai->codec; |
58783faf LR |
47 | struct snd_soc_card *card = codec->card; |
48 | struct tegra_alc5632 *alc5632 = snd_soc_card_get_drvdata(card); | |
49 | int srate, mclk; | |
50 | int err; | |
51 | ||
52 | srate = params_rate(params); | |
53 | mclk = 512 * srate; | |
54 | ||
55 | err = tegra_asoc_utils_set_rate(&alc5632->util_data, srate, mclk); | |
56 | if (err < 0) { | |
57 | dev_err(card->dev, "Can't configure clocks\n"); | |
58 | return err; | |
59 | } | |
60 | ||
61 | err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, | |
62 | SND_SOC_CLOCK_IN); | |
63 | if (err < 0) { | |
64 | dev_err(card->dev, "codec_dai clock not set\n"); | |
65 | return err; | |
66 | } | |
67 | ||
68 | return 0; | |
69 | } | |
70 | ||
71 | static struct snd_soc_ops tegra_alc5632_asoc_ops = { | |
72 | .hw_params = tegra_alc5632_asoc_hw_params, | |
73 | }; | |
74 | ||
75 | static struct snd_soc_jack tegra_alc5632_hs_jack; | |
76 | ||
77 | static struct snd_soc_jack_pin tegra_alc5632_hs_jack_pins[] = { | |
78 | { | |
79 | .pin = "Headset Mic", | |
80 | .mask = SND_JACK_MICROPHONE, | |
81 | }, | |
82 | { | |
83 | .pin = "Headset Stereophone", | |
84 | .mask = SND_JACK_HEADPHONE, | |
85 | }, | |
86 | }; | |
87 | ||
d559f1e5 LR |
88 | static struct snd_soc_jack_gpio tegra_alc5632_hp_jack_gpio = { |
89 | .name = "Headset detection", | |
90 | .report = SND_JACK_HEADSET, | |
91 | .debounce_time = 150, | |
92 | .invert = 1, | |
93 | }; | |
94 | ||
58783faf LR |
95 | static const struct snd_soc_dapm_widget tegra_alc5632_dapm_widgets[] = { |
96 | SND_SOC_DAPM_SPK("Int Spk", NULL), | |
97 | SND_SOC_DAPM_HP("Headset Stereophone", NULL), | |
98 | SND_SOC_DAPM_MIC("Headset Mic", NULL), | |
dd7d3a24 | 99 | SND_SOC_DAPM_MIC("Digital Mic", NULL), |
58783faf LR |
100 | }; |
101 | ||
58783faf LR |
102 | static const struct snd_kcontrol_new tegra_alc5632_controls[] = { |
103 | SOC_DAPM_PIN_SWITCH("Int Spk"), | |
104 | }; | |
105 | ||
106 | static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime *rtd) | |
107 | { | |
40db77a0 SW |
108 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
109 | struct snd_soc_codec *codec = codec_dai->codec; | |
58783faf | 110 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
d559f1e5 | 111 | struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(codec->card); |
58783faf LR |
112 | |
113 | snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET, | |
114 | &tegra_alc5632_hs_jack); | |
115 | snd_soc_jack_add_pins(&tegra_alc5632_hs_jack, | |
116 | ARRAY_SIZE(tegra_alc5632_hs_jack_pins), | |
117 | tegra_alc5632_hs_jack_pins); | |
118 | ||
d559f1e5 LR |
119 | if (gpio_is_valid(machine->gpio_hp_det)) { |
120 | tegra_alc5632_hp_jack_gpio.gpio = machine->gpio_hp_det; | |
121 | snd_soc_jack_add_gpios(&tegra_alc5632_hs_jack, | |
122 | 1, | |
123 | &tegra_alc5632_hp_jack_gpio); | |
d559f1e5 LR |
124 | } |
125 | ||
58783faf LR |
126 | snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1"); |
127 | ||
128 | return 0; | |
129 | } | |
130 | ||
131 | static struct snd_soc_dai_link tegra_alc5632_dai = { | |
132 | .name = "ALC5632", | |
133 | .stream_name = "ALC5632 PCM", | |
58783faf LR |
134 | .codec_dai_name = "alc5632-hifi", |
135 | .init = tegra_alc5632_asoc_init, | |
136 | .ops = &tegra_alc5632_asoc_ops, | |
137 | .dai_fmt = SND_SOC_DAIFMT_I2S | |
138 | | SND_SOC_DAIFMT_NB_NF | |
139 | | SND_SOC_DAIFMT_CBS_CFS, | |
140 | }; | |
141 | ||
142 | static struct snd_soc_card snd_soc_tegra_alc5632 = { | |
143 | .name = "tegra-alc5632", | |
b16eaf9f | 144 | .owner = THIS_MODULE, |
58783faf LR |
145 | .dai_link = &tegra_alc5632_dai, |
146 | .num_links = 1, | |
147 | .controls = tegra_alc5632_controls, | |
148 | .num_controls = ARRAY_SIZE(tegra_alc5632_controls), | |
149 | .dapm_widgets = tegra_alc5632_dapm_widgets, | |
150 | .num_dapm_widgets = ARRAY_SIZE(tegra_alc5632_dapm_widgets), | |
58783faf LR |
151 | .fully_routed = true, |
152 | }; | |
153 | ||
154 | static __devinit int tegra_alc5632_probe(struct platform_device *pdev) | |
155 | { | |
aef9a37c | 156 | struct device_node *np = pdev->dev.of_node; |
58783faf LR |
157 | struct snd_soc_card *card = &snd_soc_tegra_alc5632; |
158 | struct tegra_alc5632 *alc5632; | |
159 | int ret; | |
160 | ||
161 | alc5632 = devm_kzalloc(&pdev->dev, | |
162 | sizeof(struct tegra_alc5632), GFP_KERNEL); | |
163 | if (!alc5632) { | |
164 | dev_err(&pdev->dev, "Can't allocate tegra_alc5632\n"); | |
b4dc0a75 LR |
165 | ret = -ENOMEM; |
166 | goto err; | |
58783faf LR |
167 | } |
168 | ||
58783faf LR |
169 | card->dev = &pdev->dev; |
170 | platform_set_drvdata(pdev, card); | |
171 | snd_soc_card_set_drvdata(card, alc5632); | |
172 | ||
b4dc0a75 LR |
173 | if (!(pdev->dev.of_node)) { |
174 | dev_err(&pdev->dev, "Must be instantiated using device tree\n"); | |
175 | ret = -EINVAL; | |
176 | goto err; | |
177 | } | |
178 | ||
aef9a37c | 179 | alc5632->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0); |
bbfc3280 | 180 | if (alc5632->gpio_hp_det == -EPROBE_DEFER) |
aef9a37c SW |
181 | return -EPROBE_DEFER; |
182 | ||
b4dc0a75 LR |
183 | ret = snd_soc_of_parse_card_name(card, "nvidia,model"); |
184 | if (ret) | |
185 | goto err; | |
186 | ||
187 | ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing"); | |
188 | if (ret) | |
189 | goto err; | |
190 | ||
191 | tegra_alc5632_dai.codec_of_node = of_parse_phandle( | |
192 | pdev->dev.of_node, "nvidia,audio-codec", 0); | |
193 | ||
194 | if (!tegra_alc5632_dai.codec_of_node) { | |
195 | dev_err(&pdev->dev, | |
196 | "Property 'nvidia,audio-codec' missing or invalid\n"); | |
197 | ret = -EINVAL; | |
198 | goto err; | |
199 | } | |
200 | ||
bc92657a | 201 | tegra_alc5632_dai.cpu_of_node = of_parse_phandle( |
b4dc0a75 | 202 | pdev->dev.of_node, "nvidia,i2s-controller", 0); |
bc92657a | 203 | if (!tegra_alc5632_dai.cpu_of_node) { |
b4dc0a75 LR |
204 | dev_err(&pdev->dev, |
205 | "Property 'nvidia,i2s-controller' missing or invalid\n"); | |
206 | ret = -EINVAL; | |
207 | goto err; | |
208 | } | |
209 | ||
bc92657a | 210 | tegra_alc5632_dai.platform_of_node = tegra_alc5632_dai.cpu_of_node; |
b4dc0a75 LR |
211 | |
212 | ret = tegra_asoc_utils_init(&alc5632->util_data, &pdev->dev); | |
213 | if (ret) | |
518de86b | 214 | goto err; |
b4dc0a75 | 215 | |
58783faf LR |
216 | ret = snd_soc_register_card(card); |
217 | if (ret) { | |
218 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", | |
219 | ret); | |
b4dc0a75 | 220 | goto err_fini_utils; |
58783faf LR |
221 | } |
222 | ||
223 | return 0; | |
b4dc0a75 LR |
224 | |
225 | err_fini_utils: | |
226 | tegra_asoc_utils_fini(&alc5632->util_data); | |
b4dc0a75 LR |
227 | err: |
228 | return ret; | |
58783faf LR |
229 | } |
230 | ||
231 | static int __devexit tegra_alc5632_remove(struct platform_device *pdev) | |
232 | { | |
233 | struct snd_soc_card *card = platform_get_drvdata(pdev); | |
d559f1e5 LR |
234 | struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(card); |
235 | ||
9f6328d9 SW |
236 | snd_soc_jack_free_gpios(&tegra_alc5632_hs_jack, 1, |
237 | &tegra_alc5632_hp_jack_gpio); | |
58783faf LR |
238 | |
239 | snd_soc_unregister_card(card); | |
240 | ||
d559f1e5 | 241 | tegra_asoc_utils_fini(&machine->util_data); |
58783faf LR |
242 | |
243 | return 0; | |
244 | } | |
245 | ||
b4dc0a75 LR |
246 | static const struct of_device_id tegra_alc5632_of_match[] __devinitconst = { |
247 | { .compatible = "nvidia,tegra-audio-alc5632", }, | |
248 | {}, | |
249 | }; | |
250 | ||
58783faf LR |
251 | static struct platform_driver tegra_alc5632_driver = { |
252 | .driver = { | |
253 | .name = DRV_NAME, | |
254 | .owner = THIS_MODULE, | |
255 | .pm = &snd_soc_pm_ops, | |
b4dc0a75 | 256 | .of_match_table = tegra_alc5632_of_match, |
58783faf LR |
257 | }, |
258 | .probe = tegra_alc5632_probe, | |
259 | .remove = __devexit_p(tegra_alc5632_remove), | |
260 | }; | |
261 | module_platform_driver(tegra_alc5632_driver); | |
262 | ||
263 | MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>"); | |
264 | MODULE_DESCRIPTION("Tegra+ALC5632 machine ASoC driver"); | |
265 | MODULE_LICENSE("GPL"); | |
266 | MODULE_ALIAS("platform:" DRV_NAME); | |
b4dc0a75 | 267 | MODULE_DEVICE_TABLE(of, tegra_alc5632_of_match); |