diff options
author | Sebastian Reichel <sre@kernel.org> | 2014-04-28 10:07:24 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-05-01 13:54:34 -0400 |
commit | 386e81ab3b4d6f50064d0ce0b3d82a4ea9a26296 (patch) | |
tree | 61c3730712a964cc0754cc92bdc3f46c9c718271 /sound/soc/omap | |
parent | 0a17a37046dbd55204b00fee6e270c8008ace56b (diff) |
ASoC: omap: rx51: get GPIO numbers via gpiod API
Update the driver to get GPIO numbers from the
devm gpiod API instead of requesting hardcoded
GPIO numbers.
Signed-off-by: Sebastian Reichel <sre@kernel.org>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'sound/soc/omap')
-rw-r--r-- | sound/soc/omap/rx51.c | 114 |
1 files changed, 79 insertions, 35 deletions
diff --git a/sound/soc/omap/rx51.c b/sound/soc/omap/rx51.c index e140b1b2bdf1..30cfac023138 100644 --- a/sound/soc/omap/rx51.c +++ b/sound/soc/omap/rx51.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/delay.h> | 26 | #include <linux/delay.h> |
27 | #include <linux/gpio.h> | 27 | #include <linux/gpio.h> |
28 | #include <linux/platform_device.h> | 28 | #include <linux/platform_device.h> |
29 | #include <linux/gpio/consumer.h> | ||
29 | #include <linux/module.h> | 30 | #include <linux/module.h> |
30 | #include <sound/core.h> | 31 | #include <sound/core.h> |
31 | #include <sound/jack.h> | 32 | #include <sound/jack.h> |
@@ -38,15 +39,6 @@ | |||
38 | 39 | ||
39 | #include "omap-mcbsp.h" | 40 | #include "omap-mcbsp.h" |
40 | 41 | ||
41 | #define RX51_TVOUT_SEL_GPIO 40 | ||
42 | #define RX51_JACK_DETECT_GPIO 177 | ||
43 | #define RX51_ECI_SW_GPIO 182 | ||
44 | /* | ||
45 | * REVISIT: TWL4030 GPIO base in RX-51. Now statically defined to 192. This | ||
46 | * gpio is reserved in arch/arm/mach-omap2/board-rx51-peripherals.c | ||
47 | */ | ||
48 | #define RX51_SPEAKER_AMP_TWL_GPIO (192 + 7) | ||
49 | |||
50 | enum { | 42 | enum { |
51 | RX51_JACK_DISABLED, | 43 | RX51_JACK_DISABLED, |
52 | RX51_JACK_TVOUT, /* tv-out with stereo output */ | 44 | RX51_JACK_TVOUT, /* tv-out with stereo output */ |
@@ -54,12 +46,21 @@ enum { | |||
54 | RX51_JACK_HS, /* headset: stereo output with mic */ | 46 | RX51_JACK_HS, /* headset: stereo output with mic */ |
55 | }; | 47 | }; |
56 | 48 | ||
49 | struct rx51_audio_pdata { | ||
50 | struct gpio_desc *tvout_selection_gpio; | ||
51 | struct gpio_desc *jack_detection_gpio; | ||
52 | struct gpio_desc *eci_sw_gpio; | ||
53 | struct gpio_desc *speaker_amp_gpio; | ||
54 | }; | ||
55 | |||
57 | static int rx51_spk_func; | 56 | static int rx51_spk_func; |
58 | static int rx51_dmic_func; | 57 | static int rx51_dmic_func; |
59 | static int rx51_jack_func; | 58 | static int rx51_jack_func; |
60 | 59 | ||
61 | static void rx51_ext_control(struct snd_soc_dapm_context *dapm) | 60 | static void rx51_ext_control(struct snd_soc_dapm_context *dapm) |
62 | { | 61 | { |
62 | struct snd_soc_card *card = dapm->card; | ||
63 | struct rx51_audio_pdata *pdata = snd_soc_card_get_drvdata(card); | ||
63 | int hp = 0, hs = 0, tvout = 0; | 64 | int hp = 0, hs = 0, tvout = 0; |
64 | 65 | ||
65 | switch (rx51_jack_func) { | 66 | switch (rx51_jack_func) { |
@@ -93,7 +94,7 @@ static void rx51_ext_control(struct snd_soc_dapm_context *dapm) | |||
93 | else | 94 | else |
94 | snd_soc_dapm_disable_pin_unlocked(dapm, "HS Mic"); | 95 | snd_soc_dapm_disable_pin_unlocked(dapm, "HS Mic"); |
95 | 96 | ||
96 | gpio_set_value(RX51_TVOUT_SEL_GPIO, tvout); | 97 | gpiod_set_value(pdata->tvout_selection_gpio, tvout); |
97 | 98 | ||
98 | snd_soc_dapm_sync_unlocked(dapm); | 99 | snd_soc_dapm_sync_unlocked(dapm); |
99 | 100 | ||
@@ -154,10 +155,12 @@ static int rx51_set_spk(struct snd_kcontrol *kcontrol, | |||
154 | static int rx51_spk_event(struct snd_soc_dapm_widget *w, | 155 | static int rx51_spk_event(struct snd_soc_dapm_widget *w, |
155 | struct snd_kcontrol *k, int event) | 156 | struct snd_kcontrol *k, int event) |
156 | { | 157 | { |
157 | if (SND_SOC_DAPM_EVENT_ON(event)) | 158 | struct snd_soc_dapm_context *dapm = w->dapm; |
158 | gpio_set_value_cansleep(RX51_SPEAKER_AMP_TWL_GPIO, 1); | 159 | struct snd_soc_card *card = dapm->card; |
159 | else | 160 | struct rx51_audio_pdata *pdata = snd_soc_card_get_drvdata(card); |
160 | gpio_set_value_cansleep(RX51_SPEAKER_AMP_TWL_GPIO, 0); | 161 | |
162 | gpiod_set_raw_value_cansleep(pdata->speaker_amp_gpio, | ||
163 | !!SND_SOC_DAPM_EVENT_ON(event)); | ||
161 | 164 | ||
162 | return 0; | 165 | return 0; |
163 | } | 166 | } |
@@ -223,7 +226,6 @@ static struct snd_soc_jack rx51_av_jack; | |||
223 | 226 | ||
224 | static struct snd_soc_jack_gpio rx51_av_jack_gpios[] = { | 227 | static struct snd_soc_jack_gpio rx51_av_jack_gpios[] = { |
225 | { | 228 | { |
226 | .gpio = RX51_JACK_DETECT_GPIO, | ||
227 | .name = "avdet-gpio", | 229 | .name = "avdet-gpio", |
228 | .report = SND_JACK_HEADSET, | 230 | .report = SND_JACK_HEADSET, |
229 | .invert = 1, | 231 | .invert = 1, |
@@ -284,6 +286,9 @@ static const struct snd_kcontrol_new aic34_rx51_controls[] = { | |||
284 | static int rx51_aic34_init(struct snd_soc_pcm_runtime *rtd) | 286 | static int rx51_aic34_init(struct snd_soc_pcm_runtime *rtd) |
285 | { | 287 | { |
286 | struct snd_soc_codec *codec = rtd->codec; | 288 | struct snd_soc_codec *codec = rtd->codec; |
289 | struct snd_soc_card *card = codec->card; | ||
290 | struct rx51_audio_pdata *pdata = snd_soc_card_get_drvdata(card); | ||
291 | |||
287 | struct snd_soc_dapm_context *dapm = &codec->dapm; | 292 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
288 | int err; | 293 | int err; |
289 | 294 | ||
@@ -307,6 +312,11 @@ static int rx51_aic34_init(struct snd_soc_pcm_runtime *rtd) | |||
307 | &rx51_av_jack); | 312 | &rx51_av_jack); |
308 | if (err) | 313 | if (err) |
309 | return err; | 314 | return err; |
315 | |||
316 | /* prepare gpio for snd_soc_jack_add_gpios */ | ||
317 | rx51_av_jack_gpios[0].gpio = desc_to_gpio(pdata->jack_detection_gpio); | ||
318 | devm_gpiod_put(card->dev, pdata->jack_detection_gpio); | ||
319 | |||
310 | err = snd_soc_jack_add_gpios(&rx51_av_jack, | 320 | err = snd_soc_jack_add_gpios(&rx51_av_jack, |
311 | ARRAY_SIZE(rx51_av_jack_gpios), | 321 | ARRAY_SIZE(rx51_av_jack_gpios), |
312 | rx51_av_jack_gpios); | 322 | rx51_av_jack_gpios); |
@@ -365,37 +375,74 @@ static struct snd_soc_card rx51_sound_card = { | |||
365 | 375 | ||
366 | static int rx51_soc_probe(struct platform_device *pdev) | 376 | static int rx51_soc_probe(struct platform_device *pdev) |
367 | { | 377 | { |
378 | struct rx51_audio_pdata *pdata; | ||
368 | struct snd_soc_card *card = &rx51_sound_card; | 379 | struct snd_soc_card *card = &rx51_sound_card; |
369 | int err; | 380 | int err; |
370 | 381 | ||
371 | if (!machine_is_nokia_rx51() && !of_machine_is_compatible("nokia,omap3-n900")) | 382 | if (!machine_is_nokia_rx51() && !of_machine_is_compatible("nokia,omap3-n900")) |
372 | return -ENODEV; | 383 | return -ENODEV; |
373 | 384 | ||
374 | err = gpio_request_one(RX51_TVOUT_SEL_GPIO, | ||
375 | GPIOF_DIR_OUT | GPIOF_INIT_LOW, "tvout_sel"); | ||
376 | if (err) | ||
377 | goto err_gpio_tvout_sel; | ||
378 | err = gpio_request_one(RX51_ECI_SW_GPIO, | ||
379 | GPIOF_DIR_OUT | GPIOF_INIT_HIGH, "eci_sw"); | ||
380 | if (err) | ||
381 | goto err_gpio_eci_sw; | ||
382 | |||
383 | card->dev = &pdev->dev; | 385 | card->dev = &pdev->dev; |
384 | 386 | ||
387 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); | ||
388 | if (pdata == NULL) { | ||
389 | dev_err(card->dev, "failed to create private data\n"); | ||
390 | return -ENOMEM; | ||
391 | } | ||
392 | snd_soc_card_set_drvdata(card, pdata); | ||
393 | |||
394 | pdata->tvout_selection_gpio = devm_gpiod_get(card->dev, | ||
395 | "tvout-selection"); | ||
396 | if (IS_ERR(pdata->tvout_selection_gpio)) { | ||
397 | dev_err(card->dev, "could not get tvout selection gpio\n"); | ||
398 | return PTR_ERR(pdata->tvout_selection_gpio); | ||
399 | } | ||
400 | |||
401 | err = gpiod_direction_output(pdata->tvout_selection_gpio, 0); | ||
402 | if (err) { | ||
403 | dev_err(card->dev, "could not setup tvout selection gpio\n"); | ||
404 | return err; | ||
405 | } | ||
406 | |||
407 | pdata->jack_detection_gpio = devm_gpiod_get(card->dev, | ||
408 | "jack-detection"); | ||
409 | if (IS_ERR(pdata->jack_detection_gpio)) { | ||
410 | dev_err(card->dev, "could not get jack detection gpio\n"); | ||
411 | return PTR_ERR(pdata->jack_detection_gpio); | ||
412 | } | ||
413 | |||
414 | pdata->eci_sw_gpio = devm_gpiod_get(card->dev, "eci-switch"); | ||
415 | if (IS_ERR(pdata->eci_sw_gpio)) { | ||
416 | dev_err(card->dev, "could not get eci switch gpio\n"); | ||
417 | return PTR_ERR(pdata->eci_sw_gpio); | ||
418 | } | ||
419 | |||
420 | err = gpiod_direction_output(pdata->eci_sw_gpio, 1); | ||
421 | if (err) { | ||
422 | dev_err(card->dev, "could not setup eci switch gpio\n"); | ||
423 | return err; | ||
424 | } | ||
425 | |||
426 | pdata->speaker_amp_gpio = devm_gpiod_get(card->dev, | ||
427 | "speaker-amplifier"); | ||
428 | if (IS_ERR(pdata->speaker_amp_gpio)) { | ||
429 | dev_err(card->dev, "could not get speaker enable gpio\n"); | ||
430 | return PTR_ERR(pdata->speaker_amp_gpio); | ||
431 | } | ||
432 | |||
433 | err = gpiod_direction_output(pdata->speaker_amp_gpio, 0); | ||
434 | if (err) { | ||
435 | dev_err(card->dev, "could not setup speaker enable gpio\n"); | ||
436 | return err; | ||
437 | } | ||
438 | |||
385 | err = devm_snd_soc_register_card(card->dev, card); | 439 | err = devm_snd_soc_register_card(card->dev, card); |
386 | if (err) { | 440 | if (err) { |
387 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", err); | 441 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", err); |
388 | goto err_snd; | 442 | return err; |
389 | } | 443 | } |
390 | 444 | ||
391 | return 0; | 445 | return 0; |
392 | err_snd: | ||
393 | gpio_free(RX51_ECI_SW_GPIO); | ||
394 | err_gpio_eci_sw: | ||
395 | gpio_free(RX51_TVOUT_SEL_GPIO); | ||
396 | err_gpio_tvout_sel: | ||
397 | |||
398 | return err; | ||
399 | } | 446 | } |
400 | 447 | ||
401 | static int rx51_soc_remove(struct platform_device *pdev) | 448 | static int rx51_soc_remove(struct platform_device *pdev) |
@@ -403,9 +450,6 @@ static int rx51_soc_remove(struct platform_device *pdev) | |||
403 | snd_soc_jack_free_gpios(&rx51_av_jack, ARRAY_SIZE(rx51_av_jack_gpios), | 450 | snd_soc_jack_free_gpios(&rx51_av_jack, ARRAY_SIZE(rx51_av_jack_gpios), |
404 | rx51_av_jack_gpios); | 451 | rx51_av_jack_gpios); |
405 | 452 | ||
406 | gpio_free(RX51_ECI_SW_GPIO); | ||
407 | gpio_free(RX51_TVOUT_SEL_GPIO); | ||
408 | |||
409 | return 0; | 453 | return 0; |
410 | } | 454 | } |
411 | 455 | ||