]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ARM: pxa: spitz: use gpio descriptors for audio
authorArnd Bergmann <arnd@arndb.de>
Wed, 11 Sep 2019 14:43:59 +0000 (16:43 +0200)
committerArnd Bergmann <arnd@arndb.de>
Sat, 7 May 2022 20:55:47 +0000 (22:55 +0200)
The audio driver should not use a hardwired gpio number
from the header. Change it to use a lookup table.

Acked-by: Mark Brown <broonie@kernel.org>
Cc: alsa-devel@alsa-project.org
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
arch/arm/mach-pxa/spitz.c
arch/arm/mach-pxa/spitz.h [moved from arch/arm/mach-pxa/include/mach/spitz.h with 99% similarity]
arch/arm/mach-pxa/spitz_pm.c
sound/soc/pxa/spitz.c

index a648e7094e84e5ab44a41d7a078f90e584f1206c..cd8f009453732ff48766794a8ceb9b226990aa5a 100644 (file)
@@ -44,7 +44,7 @@
 #include <linux/platform_data/mmc-pxamci.h>
 #include <linux/platform_data/usb-ohci-pxa27x.h>
 #include <linux/platform_data/video-pxafb.h>
-#include <mach/spitz.h>
+#include "spitz.h"
 #include "sharpsl_pm.h"
 #include <mach/smemc.h>
 
@@ -962,11 +962,42 @@ static void __init spitz_i2c_init(void)
 static inline void spitz_i2c_init(void) {}
 #endif
 
+static struct gpiod_lookup_table spitz_audio_gpio_table = {
+       .dev_id = "spitz-audio",
+       .table = {
+               GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_L - SPITZ_SCP_GPIO_BASE,
+                           "mute-l", GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_R - SPITZ_SCP_GPIO_BASE,
+                           "mute-r", GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP("sharp-scoop.1", SPITZ_GPIO_MIC_BIAS - SPITZ_SCP2_GPIO_BASE,
+                           "mic", GPIO_ACTIVE_HIGH),
+               { },
+       },
+};
+
+static struct gpiod_lookup_table akita_audio_gpio_table = {
+       .dev_id = "spitz-audio",
+       .table = {
+               GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_L - SPITZ_SCP_GPIO_BASE,
+                           "mute-l", GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_R - SPITZ_SCP_GPIO_BASE,
+                           "mute-r", GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP("i2c-max7310", AKITA_GPIO_MIC_BIAS - AKITA_IOEXP_GPIO_BASE,
+                           "mic", GPIO_ACTIVE_HIGH),
+               { },
+       },
+};
+
 /******************************************************************************
  * Audio devices
  ******************************************************************************/
 static inline void spitz_audio_init(void)
 {
+       if (machine_is_akita())
+               gpiod_add_lookup_table(&akita_audio_gpio_table);
+       else
+               gpiod_add_lookup_table(&spitz_audio_gpio_table);
+
        platform_device_register_simple("spitz-audio", -1, NULL, 0);
 }
 
similarity index 99%
rename from arch/arm/mach-pxa/include/mach/spitz.h
rename to arch/arm/mach-pxa/spitz.h
index 04828d8918aa3f45455ae835f39ed0adf92a47e6..f97e3ebd762d5189a9a506ed6d6fb835146b806c 100644 (file)
@@ -11,7 +11,7 @@
 #define __ASM_ARCH_SPITZ_H  1
 #endif
 
-#include "irqs.h" /* PXA_NR_BUILTIN_GPIO, PXA_GPIO_TO_IRQ */
+#include <mach/irqs.h> /* PXA_NR_BUILTIN_GPIO, PXA_GPIO_TO_IRQ */
 #include <linux/fb.h>
 
 /* Spitz/Akita GPIOs */
index 201dabe883b68185662efe3e4e50108170b881c5..6689b67f9ce5ad400a66f1f6f3cfca9acb408ac9 100644 (file)
@@ -19,7 +19,7 @@
 #include <asm/irq.h>
 #include <asm/mach-types.h>
 
-#include <mach/spitz.h>
+#include "spitz.h"
 #include "pxa27x.h"
 #include "sharpsl_pm.h"
 
index 7c1384a869ca482f9cac29925510cb80f6ac6aa8..44303b6eb228bf67f987c188a4d88823a7d1ae1a 100644 (file)
 #include <linux/timer.h>
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/soc.h>
 
 #include <asm/mach-types.h>
-#include <mach/spitz.h>
 #include "../codecs/wm8750.h"
 #include "pxa2xx-i2s.h"
 
@@ -37,7 +36,7 @@
 
 static int spitz_jack_func;
 static int spitz_spk_func;
-static int spitz_mic_gpio;
+static struct gpio_desc *gpiod_mic, *gpiod_mute_l, *gpiod_mute_r;
 
 static void spitz_ext_control(struct snd_soc_dapm_context *dapm)
 {
@@ -56,8 +55,8 @@ static void spitz_ext_control(struct snd_soc_dapm_context *dapm)
                snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Jack");
                snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack");
                snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack");
-               gpio_set_value(SPITZ_GPIO_MUTE_L, 1);
-               gpio_set_value(SPITZ_GPIO_MUTE_R, 1);
+               gpiod_set_value(gpiod_mute_l, 1);
+               gpiod_set_value(gpiod_mute_r, 1);
                break;
        case SPITZ_MIC:
                /* enable mic jack and bias, mute hp */
@@ -65,8 +64,8 @@ static void spitz_ext_control(struct snd_soc_dapm_context *dapm)
                snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
                snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack");
                snd_soc_dapm_enable_pin_unlocked(dapm, "Mic Jack");
-               gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
-               gpio_set_value(SPITZ_GPIO_MUTE_R, 0);
+               gpiod_set_value(gpiod_mute_l, 0);
+               gpiod_set_value(gpiod_mute_r, 0);
                break;
        case SPITZ_LINE:
                /* enable line jack, disable mic bias and mute hp */
@@ -74,8 +73,8 @@ static void spitz_ext_control(struct snd_soc_dapm_context *dapm)
                snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
                snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Jack");
                snd_soc_dapm_enable_pin_unlocked(dapm, "Line Jack");
-               gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
-               gpio_set_value(SPITZ_GPIO_MUTE_R, 0);
+               gpiod_set_value(gpiod_mute_l, 0);
+               gpiod_set_value(gpiod_mute_r, 0);
                break;
        case SPITZ_HEADSET:
                /* enable and unmute headset jack enable mic bias, mute L hp */
@@ -83,8 +82,8 @@ static void spitz_ext_control(struct snd_soc_dapm_context *dapm)
                snd_soc_dapm_enable_pin_unlocked(dapm, "Mic Jack");
                snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack");
                snd_soc_dapm_enable_pin_unlocked(dapm, "Headset Jack");
-               gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
-               gpio_set_value(SPITZ_GPIO_MUTE_R, 1);
+               gpiod_set_value(gpiod_mute_l, 0);
+               gpiod_set_value(gpiod_mute_r, 1);
                break;
        case SPITZ_HP_OFF:
 
@@ -93,8 +92,8 @@ static void spitz_ext_control(struct snd_soc_dapm_context *dapm)
                snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
                snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Jack");
                snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack");
-               gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
-               gpio_set_value(SPITZ_GPIO_MUTE_R, 0);
+               gpiod_set_value(gpiod_mute_l, 0);
+               gpiod_set_value(gpiod_mute_r, 0);
                break;
        }
 
@@ -199,7 +198,7 @@ static int spitz_set_spk(struct snd_kcontrol *kcontrol,
 static int spitz_mic_bias(struct snd_soc_dapm_widget *w,
        struct snd_kcontrol *k, int event)
 {
-       gpio_set_value_cansleep(spitz_mic_gpio, SND_SOC_DAPM_EVENT_ON(event));
+       gpiod_set_value_cansleep(gpiod_mic, SND_SOC_DAPM_EVENT_ON(event));
        return 0;
 }
 
@@ -287,39 +286,28 @@ static int spitz_probe(struct platform_device *pdev)
        struct snd_soc_card *card = &snd_soc_spitz;
        int ret;
 
-       if (machine_is_akita())
-               spitz_mic_gpio = AKITA_GPIO_MIC_BIAS;
-       else
-               spitz_mic_gpio = SPITZ_GPIO_MIC_BIAS;
-
-       ret = gpio_request(spitz_mic_gpio, "MIC GPIO");
-       if (ret)
-               goto err1;
-
-       ret = gpio_direction_output(spitz_mic_gpio, 0);
-       if (ret)
-               goto err2;
+       gpiod_mic = devm_gpiod_get(&pdev->dev, "mic", GPIOD_OUT_LOW);
+       if (IS_ERR(gpiod_mic))
+               return PTR_ERR(gpiod_mic);
+       gpiod_mute_l = devm_gpiod_get(&pdev->dev, "mute-l", GPIOD_OUT_LOW);
+       if (IS_ERR(gpiod_mute_l))
+               return PTR_ERR(gpiod_mute_l);
+       gpiod_mute_r = devm_gpiod_get(&pdev->dev, "mute-r", GPIOD_OUT_LOW);
+       if (IS_ERR(gpiod_mute_r))
+               return PTR_ERR(gpiod_mute_r);
 
        card->dev = &pdev->dev;
 
        ret = devm_snd_soc_register_card(&pdev->dev, card);
-       if (ret) {
+       if (ret)
                dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
                        ret);
-               goto err2;
-       }
-
-       return 0;
 
-err2:
-       gpio_free(spitz_mic_gpio);
-err1:
        return ret;
 }
 
 static int spitz_remove(struct platform_device *pdev)
 {
-       gpio_free(spitz_mic_gpio);
        return 0;
 }