Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM: pxa: eseries: use gpio lookup for audio

The three eseries machines have very similar drivers for audio, all
using the mach/eseries-gpio.h header for finding the gpio numbers.

Change these to use gpio descriptors to avoid the header file
dependency.

I convert the _OFF gpio numbers into GPIO_ACTIVE_LOW ones for
consistency here.

Acked-by: Mark Brown <broonie@kernel.org>
Acked-by: Robert Jarzmik <robert.jarzmik@free.fr>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Cc: alsa-devel@alsa-project.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

+78 -51
+32
arch/arm/mach-pxa/eseries.c
··· 24 24 #include <linux/mtd/rawnand.h> 25 25 #include <linux/mtd/partitions.h> 26 26 #include <linux/memblock.h> 27 + #include <linux/gpio/machine.h> 27 28 28 29 #include <video/w100fb.h> 29 30 ··· 521 520 .id = -1, 522 521 }; 523 522 523 + static struct gpiod_lookup_table e740_audio_gpio_table = { 524 + .dev_id = "e740-audio", 525 + .table = { 526 + GPIO_LOOKUP("gpio-pxa", GPIO_E740_WM9705_nAVDD2, "Audio power", GPIO_ACTIVE_HIGH), 527 + GPIO_LOOKUP("gpio-pxa", GPIO_E740_AMP_ON, "Output amp", GPIO_ACTIVE_HIGH), 528 + GPIO_LOOKUP("gpio-pxa", GPIO_E740_MIC_ON, "Mic amp", GPIO_ACTIVE_HIGH), 529 + { }, 530 + }, 531 + }; 532 + 524 533 /* ----------------------------------------------------------------------- */ 525 534 526 535 static struct platform_device *e740_devices[] __initdata = { ··· 551 540 "UDCCLK", &pxa25x_device_udc.dev), 552 541 eseries_get_tmio_gpios(); 553 542 gpiod_add_lookup_table(&e7xx_gpio_vbus_gpiod_table); 543 + gpiod_add_lookup_table(&e740_audio_gpio_table); 554 544 platform_add_devices(ARRAY_AND_SIZE(e740_devices)); 555 545 pxa_set_ac97_info(NULL); 556 546 pxa_set_ficp_info(&e7xx_ficp_platform_data); ··· 727 715 .resource = eseries_tmio_resources, 728 716 }; 729 717 718 + static struct gpiod_lookup_table e750_audio_gpio_table = { 719 + .dev_id = "e750-audio", 720 + .table = { 721 + GPIO_LOOKUP("gpio-pxa", GPIO_E750_HP_AMP_OFF, "Output amp", GPIO_ACTIVE_LOW), 722 + GPIO_LOOKUP("gpio-pxa", GPIO_E750_SPK_AMP_OFF, "Mic amp", GPIO_ACTIVE_LOW), 723 + { }, 724 + }, 725 + }; 726 + 730 727 static struct platform_device e750_audio_device = { 731 728 .name = "e750-audio", 732 729 .id = -1, ··· 760 739 "GPIO11_CLK", NULL), 761 740 eseries_get_tmio_gpios(); 762 741 gpiod_add_lookup_table(&e7xx_gpio_vbus_gpiod_table); 742 + gpiod_add_lookup_table(&e750_audio_gpio_table); 763 743 platform_add_devices(ARRAY_AND_SIZE(e750_devices)); 764 744 pxa_set_ac97_info(NULL); 765 745 pxa_set_ficp_info(&e7xx_ficp_platform_data); ··· 955 933 .resource = eseries_tmio_resources, 956 934 }; 957 935 936 + static struct gpiod_lookup_table e800_audio_gpio_table = { 937 + .dev_id = "e800-audio", 938 + .table = { 939 + GPIO_LOOKUP("gpio-pxa", GPIO_E800_HP_AMP_OFF, "Output amp", GPIO_ACTIVE_LOW), 940 + GPIO_LOOKUP("gpio-pxa", GPIO_E800_SPK_AMP_ON, "Mic amp", GPIO_ACTIVE_HIGH), 941 + { }, 942 + }, 943 + }; 944 + 958 945 static struct platform_device e800_audio_device = { 959 946 .name = "e800-audio", 960 947 .id = -1, ··· 988 957 "GPIO11_CLK", NULL), 989 958 eseries_get_tmio_gpios(); 990 959 gpiod_add_lookup_table(&e800_gpio_vbus_gpiod_table); 960 + gpiod_add_lookup_table(&e800_audio_gpio_table); 991 961 platform_add_devices(ARRAY_AND_SIZE(e800_devices)); 992 962 pxa_set_ac97_info(NULL); 993 963 }
+18 -17
sound/soc/pxa/e740_wm9705.c
··· 7 7 8 8 #include <linux/module.h> 9 9 #include <linux/moduleparam.h> 10 - #include <linux/gpio.h> 10 + #include <linux/gpio/consumer.h> 11 11 12 12 #include <sound/core.h> 13 13 #include <sound/pcm.h> 14 14 #include <sound/soc.h> 15 15 16 16 #include <linux/platform_data/asoc-pxa.h> 17 - #include <mach/eseries-gpio.h> 18 17 19 18 #include <asm/mach-types.h> 19 + 20 + static struct gpio_desc *gpiod_output_amp, *gpiod_input_amp; 21 + static struct gpio_desc *gpiod_audio_power; 20 22 21 23 #define E740_AUDIO_OUT 1 22 24 #define E740_AUDIO_IN 2 ··· 27 25 28 26 static void e740_sync_audio_power(int status) 29 27 { 30 - gpio_set_value(GPIO_E740_WM9705_nAVDD2, !status); 31 - gpio_set_value(GPIO_E740_AMP_ON, (status & E740_AUDIO_OUT) ? 1 : 0); 32 - gpio_set_value(GPIO_E740_MIC_ON, (status & E740_AUDIO_IN) ? 1 : 0); 28 + gpiod_set_value(gpiod_audio_power, !status); 29 + gpiod_set_value(gpiod_output_amp, (status & E740_AUDIO_OUT) ? 1 : 0); 30 + gpiod_set_value(gpiod_input_amp, (status & E740_AUDIO_IN) ? 1 : 0); 33 31 } 34 32 35 33 static int e740_mic_amp_event(struct snd_soc_dapm_widget *w, ··· 118 116 .fully_routed = true, 119 117 }; 120 118 121 - static struct gpio e740_audio_gpios[] = { 122 - { GPIO_E740_MIC_ON, GPIOF_OUT_INIT_LOW, "Mic amp" }, 123 - { GPIO_E740_AMP_ON, GPIOF_OUT_INIT_LOW, "Output amp" }, 124 - { GPIO_E740_WM9705_nAVDD2, GPIOF_OUT_INIT_HIGH, "Audio power" }, 125 - }; 126 - 127 119 static int e740_probe(struct platform_device *pdev) 128 120 { 129 121 struct snd_soc_card *card = &e740; 130 122 int ret; 131 123 132 - ret = gpio_request_array(e740_audio_gpios, 133 - ARRAY_SIZE(e740_audio_gpios)); 124 + gpiod_input_amp = devm_gpiod_get(&pdev->dev, "Mic amp", GPIOD_OUT_LOW); 125 + ret = PTR_ERR_OR_ZERO(gpiod_input_amp); 126 + if (ret) 127 + return ret; 128 + gpiod_output_amp = devm_gpiod_get(&pdev->dev, "Output amp", GPIOD_OUT_LOW); 129 + ret = PTR_ERR_OR_ZERO(gpiod_output_amp); 130 + if (ret) 131 + return ret; 132 + gpiod_audio_power = devm_gpiod_get(&pdev->dev, "Audio power", GPIOD_OUT_HIGH); 133 + ret = PTR_ERR_OR_ZERO(gpiod_audio_power); 134 134 if (ret) 135 135 return ret; 136 136 137 137 card->dev = &pdev->dev; 138 138 139 139 ret = devm_snd_soc_register_card(&pdev->dev, card); 140 - if (ret) { 140 + if (ret) 141 141 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 142 142 ret); 143 - gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios)); 144 - } 145 143 return ret; 146 144 } 147 145 148 146 static int e740_remove(struct platform_device *pdev) 149 147 { 150 - gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios)); 151 148 return 0; 152 149 } 153 150
+14 -17
sound/soc/pxa/e750_wm9705.c
··· 7 7 8 8 #include <linux/module.h> 9 9 #include <linux/moduleparam.h> 10 - #include <linux/gpio.h> 10 + #include <linux/gpio/consumer.h> 11 11 12 12 #include <sound/core.h> 13 13 #include <sound/pcm.h> 14 14 #include <sound/soc.h> 15 15 16 16 #include <linux/platform_data/asoc-pxa.h> 17 - #include <mach/eseries-gpio.h> 18 17 19 18 #include <asm/mach-types.h> 19 + 20 + static struct gpio_desc *gpiod_spk_amp, *gpiod_hp_amp; 20 21 21 22 static int e750_spk_amp_event(struct snd_soc_dapm_widget *w, 22 23 struct snd_kcontrol *kcontrol, int event) 23 24 { 24 25 if (event & SND_SOC_DAPM_PRE_PMU) 25 - gpio_set_value(GPIO_E750_SPK_AMP_OFF, 0); 26 + gpiod_set_value(gpiod_spk_amp, 1); 26 27 else if (event & SND_SOC_DAPM_POST_PMD) 27 - gpio_set_value(GPIO_E750_SPK_AMP_OFF, 1); 28 + gpiod_set_value(gpiod_spk_amp, 0); 28 29 29 30 return 0; 30 31 } ··· 34 33 struct snd_kcontrol *kcontrol, int event) 35 34 { 36 35 if (event & SND_SOC_DAPM_PRE_PMU) 37 - gpio_set_value(GPIO_E750_HP_AMP_OFF, 0); 36 + gpiod_set_value(gpiod_hp_amp, 1); 38 37 else if (event & SND_SOC_DAPM_POST_PMD) 39 - gpio_set_value(GPIO_E750_HP_AMP_OFF, 1); 38 + gpiod_set_value(gpiod_hp_amp, 0); 40 39 41 40 return 0; 42 41 } ··· 101 100 .fully_routed = true, 102 101 }; 103 102 104 - static struct gpio e750_audio_gpios[] = { 105 - { GPIO_E750_HP_AMP_OFF, GPIOF_OUT_INIT_HIGH, "Headphone amp" }, 106 - { GPIO_E750_SPK_AMP_OFF, GPIOF_OUT_INIT_HIGH, "Speaker amp" }, 107 - }; 108 - 109 103 static int e750_probe(struct platform_device *pdev) 110 104 { 111 105 struct snd_soc_card *card = &e750; 112 106 int ret; 113 107 114 - ret = gpio_request_array(e750_audio_gpios, 115 - ARRAY_SIZE(e750_audio_gpios)); 108 + gpiod_hp_amp = devm_gpiod_get(&pdev->dev, "Headphone amp", GPIOD_OUT_LOW); 109 + ret = PTR_ERR_OR_ZERO(gpiod_hp_amp); 110 + if (ret) 111 + return ret; 112 + gpiod_spk_amp = devm_gpiod_get(&pdev->dev, "Speaker amp", GPIOD_OUT_LOW); 113 + ret = PTR_ERR_OR_ZERO(gpiod_spk_amp); 116 114 if (ret) 117 115 return ret; 118 116 119 117 card->dev = &pdev->dev; 120 118 121 119 ret = devm_snd_soc_register_card(&pdev->dev, card); 122 - if (ret) { 120 + if (ret) 123 121 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 124 122 ret); 125 - gpio_free_array(e750_audio_gpios, ARRAY_SIZE(e750_audio_gpios)); 126 - } 127 123 return ret; 128 124 } 129 125 130 126 static int e750_remove(struct platform_device *pdev) 131 127 { 132 - gpio_free_array(e750_audio_gpios, ARRAY_SIZE(e750_audio_gpios)); 133 128 return 0; 134 129 } 135 130
+14 -17
sound/soc/pxa/e800_wm9712.c
··· 7 7 8 8 #include <linux/module.h> 9 9 #include <linux/moduleparam.h> 10 - #include <linux/gpio.h> 10 + #include <linux/gpio/consumer.h> 11 11 12 12 #include <sound/core.h> 13 13 #include <sound/pcm.h> ··· 15 15 16 16 #include <asm/mach-types.h> 17 17 #include <linux/platform_data/asoc-pxa.h> 18 - #include <mach/eseries-gpio.h> 18 + 19 + static struct gpio_desc *gpiod_spk_amp, *gpiod_hp_amp; 19 20 20 21 static int e800_spk_amp_event(struct snd_soc_dapm_widget *w, 21 22 struct snd_kcontrol *kcontrol, int event) 22 23 { 23 24 if (event & SND_SOC_DAPM_PRE_PMU) 24 - gpio_set_value(GPIO_E800_SPK_AMP_ON, 1); 25 + gpiod_set_value(gpiod_spk_amp, 1); 25 26 else if (event & SND_SOC_DAPM_POST_PMD) 26 - gpio_set_value(GPIO_E800_SPK_AMP_ON, 0); 27 + gpiod_set_value(gpiod_spk_amp, 0); 27 28 28 29 return 0; 29 30 } ··· 33 32 struct snd_kcontrol *kcontrol, int event) 34 33 { 35 34 if (event & SND_SOC_DAPM_PRE_PMU) 36 - gpio_set_value(GPIO_E800_HP_AMP_OFF, 0); 35 + gpiod_set_value(gpiod_hp_amp, 1); 37 36 else if (event & SND_SOC_DAPM_POST_PMD) 38 - gpio_set_value(GPIO_E800_HP_AMP_OFF, 1); 37 + gpiod_set_value(gpiod_hp_amp, 0); 39 38 40 39 return 0; 41 40 } ··· 101 100 .num_dapm_routes = ARRAY_SIZE(audio_map), 102 101 }; 103 102 104 - static struct gpio e800_audio_gpios[] = { 105 - { GPIO_E800_SPK_AMP_ON, GPIOF_OUT_INIT_HIGH, "Headphone amp" }, 106 - { GPIO_E800_HP_AMP_OFF, GPIOF_OUT_INIT_HIGH, "Speaker amp" }, 107 - }; 108 - 109 103 static int e800_probe(struct platform_device *pdev) 110 104 { 111 105 struct snd_soc_card *card = &e800; 112 106 int ret; 113 107 114 - ret = gpio_request_array(e800_audio_gpios, 115 - ARRAY_SIZE(e800_audio_gpios)); 108 + gpiod_hp_amp = devm_gpiod_get(&pdev->dev, "Headphone amp", GPIOD_OUT_LOW); 109 + ret = PTR_ERR_OR_ZERO(gpiod_hp_amp); 110 + if (ret) 111 + return ret; 112 + gpiod_spk_amp = devm_gpiod_get(&pdev->dev, "Speaker amp", GPIOD_OUT_LOW); 113 + ret = PTR_ERR_OR_ZERO(gpiod_spk_amp); 116 114 if (ret) 117 115 return ret; 118 116 119 117 card->dev = &pdev->dev; 120 118 121 119 ret = devm_snd_soc_register_card(&pdev->dev, card); 122 - if (ret) { 120 + if (ret) 123 121 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 124 122 ret); 125 - gpio_free_array(e800_audio_gpios, ARRAY_SIZE(e800_audio_gpios)); 126 - } 127 123 return ret; 128 124 } 129 125 130 126 static int e800_remove(struct platform_device *pdev) 131 127 { 132 - gpio_free_array(e800_audio_gpios, ARRAY_SIZE(e800_audio_gpios)); 133 128 return 0; 134 129 } 135 130