aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/tegra
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2012-05-22 18:08:54 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-06-03 08:06:36 -0400
commitf51022f1aedc4d1a02d0dfa8fde47f6a8291f618 (patch)
tree50dc2009ab531f7689e97063a5bf352abab8c072 /sound/soc/tegra
parent0bf79ef2c303cc70d036c9fb355aeb468e8efb62 (diff)
ASoC: tegra+wm8903: move all GPIO setup into probe
Now that deferred probe exists, we can parse device tree and request GPIOs from probe(), rather than deferring this to the DAI link's init(). Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/tegra')
-rw-r--r--sound/soc/tegra/tegra_wm8903.c162
1 files changed, 83 insertions, 79 deletions
diff --git a/sound/soc/tegra/tegra_wm8903.c b/sound/soc/tegra/tegra_wm8903.c
index 0b0df49d9d33..a8a3103ab4cb 100644
--- a/sound/soc/tegra/tegra_wm8903.c
+++ b/sound/soc/tegra/tegra_wm8903.c
@@ -245,80 +245,6 @@ static int tegra_wm8903_init(struct snd_soc_pcm_runtime *rtd)
245 struct snd_soc_card *card = codec->card; 245 struct snd_soc_card *card = codec->card;
246 struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); 246 struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
247 struct tegra_wm8903_platform_data *pdata = &machine->pdata; 247 struct tegra_wm8903_platform_data *pdata = &machine->pdata;
248 struct device_node *np = card->dev->of_node;
249 int ret;
250
251 if (card->dev->platform_data) {
252 memcpy(pdata, card->dev->platform_data, sizeof(*pdata));
253 } else if (np) {
254 /*
255 * This part must be in init() rather than probe() in order to
256 * guarantee that the WM8903 has been probed, and hence its
257 * GPIO controller registered, which is a pre-condition for
258 * of_get_named_gpio() to be able to map the phandles in the
259 * properties to the controller node. Given this, all
260 * pdata handling is in init() for consistency.
261 */
262 pdata->gpio_spkr_en = of_get_named_gpio(np,
263 "nvidia,spkr-en-gpios", 0);
264 pdata->gpio_hp_mute = of_get_named_gpio(np,
265 "nvidia,hp-mute-gpios", 0);
266 pdata->gpio_hp_det = of_get_named_gpio(np,
267 "nvidia,hp-det-gpios", 0);
268 pdata->gpio_int_mic_en = of_get_named_gpio(np,
269 "nvidia,int-mic-en-gpios", 0);
270 pdata->gpio_ext_mic_en = of_get_named_gpio(np,
271 "nvidia,ext-mic-en-gpios", 0);
272 } else {
273 dev_err(card->dev, "No platform data supplied\n");
274 return -EINVAL;
275 }
276
277 if (gpio_is_valid(pdata->gpio_spkr_en)) {
278 ret = gpio_request(pdata->gpio_spkr_en, "spkr_en");
279 if (ret) {
280 dev_err(card->dev, "cannot get spkr_en gpio\n");
281 return ret;
282 }
283 machine->gpio_requested |= GPIO_SPKR_EN;
284
285 gpio_direction_output(pdata->gpio_spkr_en, 0);
286 }
287
288 if (gpio_is_valid(pdata->gpio_hp_mute)) {
289 ret = gpio_request(pdata->gpio_hp_mute, "hp_mute");
290 if (ret) {
291 dev_err(card->dev, "cannot get hp_mute gpio\n");
292 return ret;
293 }
294 machine->gpio_requested |= GPIO_HP_MUTE;
295
296 gpio_direction_output(pdata->gpio_hp_mute, 1);
297 }
298
299 if (gpio_is_valid(pdata->gpio_int_mic_en)) {
300 ret = gpio_request(pdata->gpio_int_mic_en, "int_mic_en");
301 if (ret) {
302 dev_err(card->dev, "cannot get int_mic_en gpio\n");
303 return ret;
304 }
305 machine->gpio_requested |= GPIO_INT_MIC_EN;
306
307 /* Disable int mic; enable signal is active-high */
308 gpio_direction_output(pdata->gpio_int_mic_en, 0);
309 }
310
311 if (gpio_is_valid(pdata->gpio_ext_mic_en)) {
312 ret = gpio_request(pdata->gpio_ext_mic_en, "ext_mic_en");
313 if (ret) {
314 dev_err(card->dev, "cannot get ext_mic_en gpio\n");
315 return ret;
316 }
317 machine->gpio_requested |= GPIO_EXT_MIC_EN;
318
319 /* Enable ext mic; enable signal is active-low */
320 gpio_direction_output(pdata->gpio_ext_mic_en, 0);
321 }
322 248
323 if (gpio_is_valid(pdata->gpio_hp_det)) { 249 if (gpio_is_valid(pdata->gpio_hp_det)) {
324 tegra_wm8903_hp_jack_gpio.gpio = pdata->gpio_hp_det; 250 tegra_wm8903_hp_jack_gpio.gpio = pdata->gpio_hp_det;
@@ -372,8 +298,10 @@ static struct snd_soc_card snd_soc_tegra_wm8903 = {
372 298
373static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev) 299static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev)
374{ 300{
301 struct device_node *np = pdev->dev.of_node;
375 struct snd_soc_card *card = &snd_soc_tegra_wm8903; 302 struct snd_soc_card *card = &snd_soc_tegra_wm8903;
376 struct tegra_wm8903 *machine; 303 struct tegra_wm8903 *machine;
304 struct tegra_wm8903_platform_data *pdata;
377 int ret; 305 int ret;
378 306
379 if (!pdev->dev.platform_data && !pdev->dev.of_node) { 307 if (!pdev->dev.platform_data && !pdev->dev.of_node) {
@@ -388,12 +316,42 @@ static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev)
388 ret = -ENOMEM; 316 ret = -ENOMEM;
389 goto err; 317 goto err;
390 } 318 }
319 pdata = &machine->pdata;
391 320
392 card->dev = &pdev->dev; 321 card->dev = &pdev->dev;
393 platform_set_drvdata(pdev, card); 322 platform_set_drvdata(pdev, card);
394 snd_soc_card_set_drvdata(card, machine); 323 snd_soc_card_set_drvdata(card, machine);
395 324
396 if (pdev->dev.of_node) { 325 if (pdev->dev.platform_data) {
326 memcpy(pdata, card->dev->platform_data, sizeof(*pdata));
327 } else if (np) {
328 pdata->gpio_spkr_en = of_get_named_gpio(np,
329 "nvidia,spkr-en-gpios", 0);
330 if (pdata->gpio_spkr_en == -ENODEV)
331 return -EPROBE_DEFER;
332
333 pdata->gpio_hp_mute = of_get_named_gpio(np,
334 "nvidia,hp-mute-gpios", 0);
335 if (pdata->gpio_hp_mute == -ENODEV)
336 return -EPROBE_DEFER;
337
338 pdata->gpio_hp_det = of_get_named_gpio(np,
339 "nvidia,hp-det-gpios", 0);
340 if (pdata->gpio_hp_det == -ENODEV)
341 return -EPROBE_DEFER;
342
343 pdata->gpio_int_mic_en = of_get_named_gpio(np,
344 "nvidia,int-mic-en-gpios", 0);
345 if (pdata->gpio_int_mic_en == -ENODEV)
346 return -EPROBE_DEFER;
347
348 pdata->gpio_ext_mic_en = of_get_named_gpio(np,
349 "nvidia,ext-mic-en-gpios", 0);
350 if (pdata->gpio_ext_mic_en == -ENODEV)
351 return -EPROBE_DEFER;
352 }
353
354 if (np) {
397 ret = snd_soc_of_parse_card_name(card, "nvidia,model"); 355 ret = snd_soc_of_parse_card_name(card, "nvidia,model");
398 if (ret) 356 if (ret)
399 goto err; 357 goto err;
@@ -404,8 +362,8 @@ static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev)
404 goto err; 362 goto err;
405 363
406 tegra_wm8903_dai.codec_name = NULL; 364 tegra_wm8903_dai.codec_name = NULL;
407 tegra_wm8903_dai.codec_of_node = of_parse_phandle( 365 tegra_wm8903_dai.codec_of_node = of_parse_phandle(np,
408 pdev->dev.of_node, "nvidia,audio-codec", 0); 366 "nvidia,audio-codec", 0);
409 if (!tegra_wm8903_dai.codec_of_node) { 367 if (!tegra_wm8903_dai.codec_of_node) {
410 dev_err(&pdev->dev, 368 dev_err(&pdev->dev,
411 "Property 'nvidia,audio-codec' missing or invalid\n"); 369 "Property 'nvidia,audio-codec' missing or invalid\n");
@@ -414,8 +372,8 @@ static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev)
414 } 372 }
415 373
416 tegra_wm8903_dai.cpu_dai_name = NULL; 374 tegra_wm8903_dai.cpu_dai_name = NULL;
417 tegra_wm8903_dai.cpu_dai_of_node = of_parse_phandle( 375 tegra_wm8903_dai.cpu_dai_of_node = of_parse_phandle(np,
418 pdev->dev.of_node, "nvidia,i2s-controller", 0); 376 "nvidia,i2s-controller", 0);
419 if (!tegra_wm8903_dai.cpu_dai_of_node) { 377 if (!tegra_wm8903_dai.cpu_dai_of_node) {
420 dev_err(&pdev->dev, 378 dev_err(&pdev->dev,
421 "Property 'nvidia,i2s-controller' missing or invalid\n"); 379 "Property 'nvidia,i2s-controller' missing or invalid\n");
@@ -442,6 +400,52 @@ static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev)
442 } 400 }
443 } 401 }
444 402
403 if (gpio_is_valid(pdata->gpio_spkr_en)) {
404 ret = gpio_request(pdata->gpio_spkr_en, "spkr_en");
405 if (ret) {
406 dev_err(card->dev, "cannot get spkr_en gpio\n");
407 return ret;
408 }
409 machine->gpio_requested |= GPIO_SPKR_EN;
410
411 gpio_direction_output(pdata->gpio_spkr_en, 0);
412 }
413
414 if (gpio_is_valid(pdata->gpio_hp_mute)) {
415 ret = gpio_request(pdata->gpio_hp_mute, "hp_mute");
416 if (ret) {
417 dev_err(card->dev, "cannot get hp_mute gpio\n");
418 return ret;
419 }
420 machine->gpio_requested |= GPIO_HP_MUTE;
421
422 gpio_direction_output(pdata->gpio_hp_mute, 1);
423 }
424
425 if (gpio_is_valid(pdata->gpio_int_mic_en)) {
426 ret = gpio_request(pdata->gpio_int_mic_en, "int_mic_en");
427 if (ret) {
428 dev_err(card->dev, "cannot get int_mic_en gpio\n");
429 return ret;
430 }
431 machine->gpio_requested |= GPIO_INT_MIC_EN;
432
433 /* Disable int mic; enable signal is active-high */
434 gpio_direction_output(pdata->gpio_int_mic_en, 0);
435 }
436
437 if (gpio_is_valid(pdata->gpio_ext_mic_en)) {
438 ret = gpio_request(pdata->gpio_ext_mic_en, "ext_mic_en");
439 if (ret) {
440 dev_err(card->dev, "cannot get ext_mic_en gpio\n");
441 return ret;
442 }
443 machine->gpio_requested |= GPIO_EXT_MIC_EN;
444
445 /* Enable ext mic; enable signal is active-low */
446 gpio_direction_output(pdata->gpio_ext_mic_en, 0);
447 }
448
445 ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev); 449 ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
446 if (ret) 450 if (ret)
447 goto err; 451 goto err;