ASoC: ti: Convert N810 ASoC to GPIO descriptors
authorLinus Walleij <linus.walleij@linaro.org>
Tue, 26 Sep 2023 13:25:29 +0000 (15:25 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 2 Oct 2023 13:06:19 +0000 (14:06 +0100)
The N810 uses GPIO descriptors pretty much exclusively, but not
for ASoC, so let's fix it. Register the pins in a descriptor table
in the machine since the ASoC device is not using device tree.

Use static locals for the GPIO descriptors because I'm not able
to experient with better state storage on any real hardware. Others
using the N810 can come afterwards and improve this.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
Link: https://lore.kernel.org/r/20230926-descriptors-asoc-ti-v1-1-60cf4f8adbc5@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
arch/arm/mach-omap2/board-n8x0.c
sound/soc/ti/n810.c

index 8e3b5068d4ab07cab11d73bf114b3c3a54f3dae9..31755a378c7364b5b5a055fa59b8796600a898a9 100644 (file)
@@ -498,6 +498,15 @@ struct menelaus_platform_data n8x0_menelaus_platform_data = {
        .late_init = n8x0_menelaus_late_init,
 };
 
+static struct gpiod_lookup_table nokia810_asoc_gpio_table = {
+       .dev_id = "soc-audio",
+       .table = {
+               GPIO_LOOKUP("gpio-0-15", 10, "headset", GPIO_ACTIVE_HIGH),
+               GPIO_LOOKUP("gpio-80-111", 21, "speaker", GPIO_ACTIVE_HIGH),
+               { }
+       },
+};
+
 static int __init n8x0_late_initcall(void)
 {
        if (!board_caps)
@@ -505,6 +514,7 @@ static int __init n8x0_late_initcall(void)
 
        n8x0_mmc_init();
        n8x0_usb_init();
+       gpiod_add_lookup_table(&nokia810_asoc_gpio_table);
 
        return 0;
 }
index ed217b34f846ad160355ae1b1040479e3ab3f1d1..71a2a90bad2b16bb23794297bcc5d81abecbbd79 100644 (file)
 #include <sound/soc.h>
 
 #include <asm/mach-types.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/module.h>
 #include <linux/platform_data/asoc-ti-mcbsp.h>
 
 #include "omap-mcbsp.h"
 
-#define N810_HEADSET_AMP_GPIO  10
-#define N810_SPEAKER_AMP_GPIO  101
+static struct gpio_desc *n810_headset_amp;
+static struct gpio_desc *n810_speaker_amp;
 
 enum {
        N810_JACK_DISABLED,
@@ -187,9 +187,9 @@ static int n810_spk_event(struct snd_soc_dapm_widget *w,
                          struct snd_kcontrol *k, int event)
 {
        if (SND_SOC_DAPM_EVENT_ON(event))
-               gpio_set_value(N810_SPEAKER_AMP_GPIO, 1);
+               gpiod_set_value(n810_speaker_amp, 1);
        else
-               gpio_set_value(N810_SPEAKER_AMP_GPIO, 0);
+               gpiod_set_value(n810_speaker_amp, 0);
 
        return 0;
 }
@@ -198,9 +198,9 @@ static int n810_jack_event(struct snd_soc_dapm_widget *w,
                           struct snd_kcontrol *k, int event)
 {
        if (SND_SOC_DAPM_EVENT_ON(event))
-               gpio_set_value(N810_HEADSET_AMP_GPIO, 1);
+               gpiod_set_value(n810_headset_amp, 1);
        else
-               gpio_set_value(N810_HEADSET_AMP_GPIO, 0);
+               gpiod_set_value(n810_headset_amp, 0);
 
        return 0;
 }
@@ -327,14 +327,19 @@ static int __init n810_soc_init(void)
        clk_set_parent(sys_clkout2_src, func96m_clk);
        clk_set_rate(sys_clkout2, 12000000);
 
-       if (WARN_ON((gpio_request(N810_HEADSET_AMP_GPIO, "hs_amp") < 0) ||
-                   (gpio_request(N810_SPEAKER_AMP_GPIO, "spk_amp") < 0))) {
-               err = -EINVAL;
+       n810_headset_amp = devm_gpiod_get(&n810_snd_device->dev,
+                                         "headphone", GPIOD_OUT_LOW);
+       if (IS_ERR(n810_headset_amp)) {
+               err = PTR_ERR(n810_headset_amp);
                goto err4;
        }
 
-       gpio_direction_output(N810_HEADSET_AMP_GPIO, 0);
-       gpio_direction_output(N810_SPEAKER_AMP_GPIO, 0);
+       n810_speaker_amp = devm_gpiod_get(&n810_snd_device->dev,
+                                         "speaker", GPIOD_OUT_LOW);
+       if (IS_ERR(n810_speaker_amp)) {
+               err = PTR_ERR(n810_speaker_amp);
+               goto err4;
+       }
 
        return 0;
 err4:
@@ -351,8 +356,6 @@ err1:
 
 static void __exit n810_soc_exit(void)
 {
-       gpio_free(N810_SPEAKER_AMP_GPIO);
-       gpio_free(N810_HEADSET_AMP_GPIO);
        clk_put(sys_clkout2_src);
        clk_put(sys_clkout2);
        clk_put(func96m_clk);