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

ARM: pxa: hx4700: use gpio descriptors for audio

The audio driver should not use a hardwired gpio number
from the header. Change it to use a lookup table.

Cc: Philipp Zabel <philipp.zabel@gmail.com>
Cc: Paul Parsons <lost.distance@yahoo.com>
Acked-by: Mark Brown <broonie@kernel.org>
Acked-by: Robert Jarzmik <robert.jarzmik@free.fr>
Cc: alsa-devel@alsa-project.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

+32 -25
+1 -1
arch/arm/mach-pxa/hx4700-pcmcia.c
··· 10 10 #include <linux/irq.h> 11 11 12 12 #include <asm/mach-types.h> 13 - #include <mach/hx4700.h> 13 + #include "hx4700.h" 14 14 15 15 #include <pcmcia/soc_common.h> 16 16
+15 -1
arch/arm/mach-pxa/hx4700.c
··· 41 41 42 42 #include "pxa27x.h" 43 43 #include "addr-map.h" 44 - #include <mach/hx4700.h> 44 + #include "hx4700.h" 45 45 #include <linux/platform_data/irda-pxaficp.h> 46 46 47 47 #include <sound/ak4641.h> ··· 834 834 }, 835 835 }; 836 836 837 + static struct gpiod_lookup_table hx4700_audio_gpio_table = { 838 + .dev_id = "hx4700-audio", 839 + .table = { 840 + GPIO_LOOKUP("gpio-pxa", GPIO75_HX4700_EARPHONE_nDET, 841 + "earphone-det", GPIO_ACTIVE_LOW), 842 + GPIO_LOOKUP("gpio-pxa", GPIO92_HX4700_HP_DRIVER, 843 + "hp-driver", GPIO_ACTIVE_HIGH), 844 + GPIO_LOOKUP("gpio-pxa", GPIO107_HX4700_SPK_nSD, 845 + "spk-sd", GPIO_ACTIVE_LOW), 846 + { }, 847 + }, 848 + }; 849 + 837 850 static struct platform_device audio = { 838 851 .name = "hx4700-audio", 839 852 .id = -1, ··· 908 895 909 896 gpiod_add_lookup_table(&bq24022_gpiod_table); 910 897 gpiod_add_lookup_table(&gpio_vbus_gpiod_table); 898 + gpiod_add_lookup_table(&hx4700_audio_gpio_table); 911 899 platform_add_devices(devices, ARRAY_SIZE(devices)); 912 900 pwm_add_table(hx4700_pwm_lookup, ARRAY_SIZE(hx4700_pwm_lookup)); 913 901
+1 -1
arch/arm/mach-pxa/include/mach/hx4700.h arch/arm/mach-pxa/hx4700.h
··· 10 10 11 11 #include <linux/gpio.h> 12 12 #include <linux/mfd/asic3.h> 13 - #include "irqs.h" /* PXA_NR_BUILTIN_GPIO */ 13 + #include <mach/irqs.h> /* PXA_NR_BUILTIN_GPIO */ 14 14 15 15 #define HX4700_ASIC3_GPIO_BASE PXA_NR_BUILTIN_GPIO 16 16 #define HX4700_EGPIO_BASE (HX4700_ASIC3_GPIO_BASE + ASIC3_NUM_GPIOS)
+15 -22
sound/soc/pxa/hx4700.c
··· 10 10 #include <linux/interrupt.h> 11 11 #include <linux/platform_device.h> 12 12 #include <linux/delay.h> 13 - #include <linux/gpio.h> 13 + #include <linux/gpio/consumer.h> 14 14 15 15 #include <sound/core.h> 16 16 #include <sound/jack.h> ··· 18 18 #include <sound/pcm_params.h> 19 19 #include <sound/soc.h> 20 20 21 - #include <mach/hx4700.h> 22 21 #include <asm/mach-types.h> 23 22 #include "pxa2xx-i2s.h" 24 23 24 + static struct gpio_desc *gpiod_hp_driver, *gpiod_spk_sd; 25 25 static struct snd_soc_jack hs_jack; 26 26 27 27 /* Headphones jack detection DAPM pin */ ··· 29 29 { 30 30 .pin = "Headphone Jack", 31 31 .mask = SND_JACK_HEADPHONE, 32 + .invert = 1, 32 33 }, 33 34 { 34 35 .pin = "Speaker", 35 36 /* disable speaker when hp jack is inserted */ 36 37 .mask = SND_JACK_HEADPHONE, 37 - .invert = 1, 38 38 }, 39 39 }; 40 40 41 41 /* Headphones jack detection GPIO */ 42 42 static struct snd_soc_jack_gpio hs_jack_gpio = { 43 - .gpio = GPIO75_HX4700_EARPHONE_nDET, 44 - .invert = true, 45 - .name = "hp-gpio", 43 + .name = "earphone-det", 46 44 .report = SND_JACK_HEADPHONE, 47 45 .debounce_time = 200, 48 46 }; ··· 79 81 static int hx4700_spk_power(struct snd_soc_dapm_widget *w, 80 82 struct snd_kcontrol *k, int event) 81 83 { 82 - gpio_set_value(GPIO107_HX4700_SPK_nSD, !!SND_SOC_DAPM_EVENT_ON(event)); 84 + gpiod_set_value(gpiod_spk_sd, !SND_SOC_DAPM_EVENT_ON(event)); 83 85 return 0; 84 86 } 85 87 86 88 static int hx4700_hp_power(struct snd_soc_dapm_widget *w, 87 89 struct snd_kcontrol *k, int event) 88 90 { 89 - gpio_set_value(GPIO92_HX4700_HP_DRIVER, !!SND_SOC_DAPM_EVENT_ON(event)); 91 + gpiod_set_value(gpiod_hp_driver, !!SND_SOC_DAPM_EVENT_ON(event)); 90 92 return 0; 91 93 } 92 94 ··· 160 162 .fully_routed = true, 161 163 }; 162 164 163 - static struct gpio hx4700_audio_gpios[] = { 164 - { GPIO107_HX4700_SPK_nSD, GPIOF_OUT_INIT_HIGH, "SPK_POWER" }, 165 - { GPIO92_HX4700_HP_DRIVER, GPIOF_OUT_INIT_LOW, "EP_POWER" }, 166 - }; 167 - 168 165 static int hx4700_audio_probe(struct platform_device *pdev) 169 166 { 170 167 int ret; ··· 167 174 if (!machine_is_h4700()) 168 175 return -ENODEV; 169 176 170 - ret = gpio_request_array(hx4700_audio_gpios, 171 - ARRAY_SIZE(hx4700_audio_gpios)); 177 + gpiod_hp_driver = devm_gpiod_get(&pdev->dev, "hp-driver", GPIOD_ASIS); 178 + ret = PTR_ERR_OR_ZERO(gpiod_hp_driver); 179 + if (ret) 180 + return ret; 181 + gpiod_spk_sd = devm_gpiod_get(&pdev->dev, "spk-sd", GPIOD_ASIS); 182 + ret = PTR_ERR_OR_ZERO(gpiod_spk_sd); 172 183 if (ret) 173 184 return ret; 174 185 186 + hs_jack_gpio.gpiod_dev = &pdev->dev; 175 187 snd_soc_card_hx4700.dev = &pdev->dev; 176 188 ret = devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_hx4700); 177 - if (ret) 178 - gpio_free_array(hx4700_audio_gpios, 179 - ARRAY_SIZE(hx4700_audio_gpios)); 180 189 181 190 return ret; 182 191 } 183 192 184 193 static int hx4700_audio_remove(struct platform_device *pdev) 185 194 { 186 - gpio_set_value(GPIO92_HX4700_HP_DRIVER, 0); 187 - gpio_set_value(GPIO107_HX4700_SPK_nSD, 0); 188 - 189 - gpio_free_array(hx4700_audio_gpios, ARRAY_SIZE(hx4700_audio_gpios)); 195 + gpiod_set_value(gpiod_hp_driver, 0); 196 + gpiod_set_value(gpiod_spk_sd, 0); 190 197 return 0; 191 198 } 192 199