aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2014-04-22 16:46:35 -0400
committerMark Brown <broonie@linaro.org>2014-04-23 07:18:36 -0400
commit218e18a3728507ee82ed2eb10c789671a00e34bd (patch)
tree5b2079e52248bee0fe8951bc6dcc390c9538fe67
parent050f62e4de52901cc0f7aebbd64876d2639a8657 (diff)
ASoC: qi_lb60: Use GPIO descriptor API
The new GPIO descriptor API is now the preferred way for handling GPIOs. It also allows us to separate the platform depended code from the platform independent code (Which will make it possible to increase build test coverage of the platform independent code). Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Ralf Baechle <ralf@linux-mips.org> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--arch/mips/jz4740/board-qi_lb60.c11
-rw-r--r--sound/soc/jz4740/qi_lb60.c54
2 files changed, 39 insertions, 26 deletions
diff --git a/arch/mips/jz4740/board-qi_lb60.c b/arch/mips/jz4740/board-qi_lb60.c
index c01900e5d078..088e92a79ae6 100644
--- a/arch/mips/jz4740/board-qi_lb60.c
+++ b/arch/mips/jz4740/board-qi_lb60.c
@@ -425,6 +425,15 @@ static struct platform_device qi_lb60_audio_device = {
425 .id = -1, 425 .id = -1,
426}; 426};
427 427
428static struct gpiod_lookup_table qi_lb60_audio_gpio_table = {
429 .dev_id = "qi-lb60-audio",
430 .table = {
431 GPIO_LOOKUP("Bank B", 29, "snd", 0),
432 GPIO_LOOKUP("Bank D", 4, "amp", 0),
433 { },
434 },
435};
436
428static struct platform_device *jz_platform_devices[] __initdata = { 437static struct platform_device *jz_platform_devices[] __initdata = {
429 &jz4740_udc_device, 438 &jz4740_udc_device,
430 &jz4740_udc_xceiv_device, 439 &jz4740_udc_xceiv_device,
@@ -461,6 +470,8 @@ static int __init qi_lb60_init_platform_devices(void)
461 jz4740_adc_device.dev.platform_data = &qi_lb60_battery_pdata; 470 jz4740_adc_device.dev.platform_data = &qi_lb60_battery_pdata;
462 jz4740_mmc_device.dev.platform_data = &qi_lb60_mmc_pdata; 471 jz4740_mmc_device.dev.platform_data = &qi_lb60_mmc_pdata;
463 472
473 gpiod_add_lookup_table(&qi_lb60_audio_gpio_table);
474
464 jz4740_serial_device_register(); 475 jz4740_serial_device_register();
465 476
466 spi_register_board_info(qi_lb60_spi_board_info, 477 spi_register_board_info(qi_lb60_spi_board_info,
diff --git a/sound/soc/jz4740/qi_lb60.c b/sound/soc/jz4740/qi_lb60.c
index be0a437f0888..5cb91f9e8626 100644
--- a/sound/soc/jz4740/qi_lb60.c
+++ b/sound/soc/jz4740/qi_lb60.c
@@ -19,18 +19,21 @@
19#include <sound/core.h> 19#include <sound/core.h>
20#include <sound/pcm.h> 20#include <sound/pcm.h>
21#include <sound/soc.h> 21#include <sound/soc.h>
22#include <linux/gpio.h> 22#include <linux/gpio/consumer.h>
23 23
24#define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29) 24struct qi_lb60 {
25#define QI_LB60_AMP_GPIO JZ_GPIO_PORTD(4) 25 struct gpio_desc *snd_gpio;
26 struct gpio_desc *amp_gpio;
27};
26 28
27static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget, 29static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget,
28 struct snd_kcontrol *ctrl, int event) 30 struct snd_kcontrol *ctrl, int event)
29{ 31{
32 struct qi_lb60 *qi_lb60 = snd_soc_card_get_drvdata(widget->dapm->card);
30 int on = !SND_SOC_DAPM_EVENT_OFF(event); 33 int on = !SND_SOC_DAPM_EVENT_OFF(event);
31 34
32 gpio_set_value(QI_LB60_SND_GPIO, on); 35 gpiod_set_value_cansleep(qi_lb60->snd_gpio, on);
33 gpio_set_value(QI_LB60_AMP_GPIO, on); 36 gpiod_set_value_cansleep(qi_lb60->amp_gpio, on);
34 37
35 return 0; 38 return 0;
36} 39}
@@ -57,7 +60,7 @@ static struct snd_soc_dai_link qi_lb60_dai = {
57 SND_SOC_DAIFMT_CBM_CFM, 60 SND_SOC_DAIFMT_CBM_CFM,
58}; 61};
59 62
60static struct snd_soc_card qi_lb60 = { 63static struct snd_soc_card qi_lb60_card = {
61 .name = "QI LB60", 64 .name = "QI LB60",
62 .owner = THIS_MODULE, 65 .owner = THIS_MODULE,
63 .dai_link = &qi_lb60_dai, 66 .dai_link = &qi_lb60_dai,
@@ -70,35 +73,35 @@ static struct snd_soc_card qi_lb60 = {
70 .fully_routed = true, 73 .fully_routed = true,
71}; 74};
72 75
73static const struct gpio qi_lb60_gpios[] = {
74 { QI_LB60_SND_GPIO, GPIOF_OUT_INIT_LOW, "SND" },
75 { QI_LB60_AMP_GPIO, GPIOF_OUT_INIT_LOW, "AMP" },
76};
77
78static int qi_lb60_probe(struct platform_device *pdev) 76static int qi_lb60_probe(struct platform_device *pdev)
79{ 77{
80 struct snd_soc_card *card = &qi_lb60; 78 struct qi_lb60 *qi_lb60;
79 struct snd_soc_card *card = &qi_lb60_card;
81 int ret; 80 int ret;
82 81
83 ret = gpio_request_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios)); 82 qi_lb60 = devm_kzalloc(&pdev->dev, sizeof(*qi_lb60), GFP_KERNEL);
83 if (!qi_lb60)
84 return -ENOMEM;
85
86 qi_lb60->snd_gpio = devm_gpiod_get(&pdev->dev, "snd");
87 if (IS_ERR(qi_lb60->snd_gpio))
88 return PTR_ERR(qi_lb60->snd_gpio);
89 ret = gpiod_direction_output(qi_lb60->snd_gpio, 0);
90 if (ret)
91 return ret;
92
93 qi_lb60->amp_gpio = devm_gpiod_get(&pdev->dev, "amp");
94 if (IS_ERR(qi_lb60->amp_gpio))
95 return PTR_ERR(qi_lb60->amp_gpio);
96 ret = gpiod_direction_output(qi_lb60->amp_gpio, 0);
84 if (ret) 97 if (ret)
85 return ret; 98 return ret;
86 99
87 card->dev = &pdev->dev; 100 card->dev = &pdev->dev;
88 101
89 ret = devm_snd_soc_register_card(&pdev->dev, card); 102 snd_soc_card_set_drvdata(card, qi_lb60);
90 if (ret) {
91 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
92 ret);
93 gpio_free_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios));
94 }
95 return ret;
96}
97 103
98static int qi_lb60_remove(struct platform_device *pdev) 104 return devm_snd_soc_register_card(&pdev->dev, card);
99{
100 gpio_free_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios));
101 return 0;
102} 105}
103 106
104static struct platform_driver qi_lb60_driver = { 107static struct platform_driver qi_lb60_driver = {
@@ -107,7 +110,6 @@ static struct platform_driver qi_lb60_driver = {
107 .owner = THIS_MODULE, 110 .owner = THIS_MODULE,
108 }, 111 },
109 .probe = qi_lb60_probe, 112 .probe = qi_lb60_probe,
110 .remove = qi_lb60_remove,
111}; 113};
112 114
113module_platform_driver(qi_lb60_driver); 115module_platform_driver(qi_lb60_driver);