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

ASoC: ti: Convert N810 ASoC to GPIO descriptors

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>

authored by

Linus Walleij and committed by
Mark Brown
22041ed1 5b12dd84

+27 -14
+10
arch/arm/mach-omap2/board-n8x0.c
··· 498 498 .late_init = n8x0_menelaus_late_init, 499 499 }; 500 500 501 + static struct gpiod_lookup_table nokia810_asoc_gpio_table = { 502 + .dev_id = "soc-audio", 503 + .table = { 504 + GPIO_LOOKUP("gpio-0-15", 10, "headset", GPIO_ACTIVE_HIGH), 505 + GPIO_LOOKUP("gpio-80-111", 21, "speaker", GPIO_ACTIVE_HIGH), 506 + { } 507 + }, 508 + }; 509 + 501 510 static int __init n8x0_late_initcall(void) 502 511 { 503 512 if (!board_caps) ··· 514 505 515 506 n8x0_mmc_init(); 516 507 n8x0_usb_init(); 508 + gpiod_add_lookup_table(&nokia810_asoc_gpio_table); 517 509 518 510 return 0; 519 511 }
+17 -14
sound/soc/ti/n810.c
··· 15 15 #include <sound/soc.h> 16 16 17 17 #include <asm/mach-types.h> 18 - #include <linux/gpio.h> 18 + #include <linux/gpio/consumer.h> 19 19 #include <linux/module.h> 20 20 #include <linux/platform_data/asoc-ti-mcbsp.h> 21 21 22 22 #include "omap-mcbsp.h" 23 23 24 - #define N810_HEADSET_AMP_GPIO 10 25 - #define N810_SPEAKER_AMP_GPIO 101 24 + static struct gpio_desc *n810_headset_amp; 25 + static struct gpio_desc *n810_speaker_amp; 26 26 27 27 enum { 28 28 N810_JACK_DISABLED, ··· 187 187 struct snd_kcontrol *k, int event) 188 188 { 189 189 if (SND_SOC_DAPM_EVENT_ON(event)) 190 - gpio_set_value(N810_SPEAKER_AMP_GPIO, 1); 190 + gpiod_set_value(n810_speaker_amp, 1); 191 191 else 192 - gpio_set_value(N810_SPEAKER_AMP_GPIO, 0); 192 + gpiod_set_value(n810_speaker_amp, 0); 193 193 194 194 return 0; 195 195 } ··· 198 198 struct snd_kcontrol *k, int event) 199 199 { 200 200 if (SND_SOC_DAPM_EVENT_ON(event)) 201 - gpio_set_value(N810_HEADSET_AMP_GPIO, 1); 201 + gpiod_set_value(n810_headset_amp, 1); 202 202 else 203 - gpio_set_value(N810_HEADSET_AMP_GPIO, 0); 203 + gpiod_set_value(n810_headset_amp, 0); 204 204 205 205 return 0; 206 206 } ··· 327 327 clk_set_parent(sys_clkout2_src, func96m_clk); 328 328 clk_set_rate(sys_clkout2, 12000000); 329 329 330 - if (WARN_ON((gpio_request(N810_HEADSET_AMP_GPIO, "hs_amp") < 0) || 331 - (gpio_request(N810_SPEAKER_AMP_GPIO, "spk_amp") < 0))) { 332 - err = -EINVAL; 330 + n810_headset_amp = devm_gpiod_get(&n810_snd_device->dev, 331 + "headphone", GPIOD_OUT_LOW); 332 + if (IS_ERR(n810_headset_amp)) { 333 + err = PTR_ERR(n810_headset_amp); 333 334 goto err4; 334 335 } 335 336 336 - gpio_direction_output(N810_HEADSET_AMP_GPIO, 0); 337 - gpio_direction_output(N810_SPEAKER_AMP_GPIO, 0); 337 + n810_speaker_amp = devm_gpiod_get(&n810_snd_device->dev, 338 + "speaker", GPIOD_OUT_LOW); 339 + if (IS_ERR(n810_speaker_amp)) { 340 + err = PTR_ERR(n810_speaker_amp); 341 + goto err4; 342 + } 338 343 339 344 return 0; 340 345 err4: ··· 356 351 357 352 static void __exit n810_soc_exit(void) 358 353 { 359 - gpio_free(N810_SPEAKER_AMP_GPIO); 360 - gpio_free(N810_HEADSET_AMP_GPIO); 361 354 clk_put(sys_clkout2_src); 362 355 clk_put(sys_clkout2); 363 356 clk_put(func96m_clk);