From 77a4525bc282b7072ebda5d6f6925ca6d604a16f Mon Sep 17 00:00:00 2001 From: Srinivas Kandagatla Date: Wed, 26 Jul 2017 02:35:07 +0200 Subject: ASoC: jack: fix snd_soc_codec_set_jack return error This patch changes the error code returned by snd_soc_codec_set_jack() from -EINVAL to -ENOTSUPP. The reason to do this is to make the caller aware that the underlying codec does not support this callback. This can make the caller write the code to handle this case properly. Other reason is that -EINVAL is not the correct error to return in this case anyway. Signed-off-by: Srinivas Kandagatla Signed-off-by: Mark Brown --- sound/soc/soc-jack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound/soc/soc-jack.c') diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c index 7daf21fee355..42ca9f19843b 100644 --- a/sound/soc/soc-jack.c +++ b/sound/soc/soc-jack.c @@ -36,7 +36,7 @@ int snd_soc_codec_set_jack(struct snd_soc_codec *codec, if (codec->driver->set_jack) return codec->driver->set_jack(codec, jack, data); else - return -EINVAL; + return -ENOTSUPP; } EXPORT_SYMBOL_GPL(snd_soc_codec_set_jack); -- cgit v1.2.3 From bd29ae969042c87413157c02d4f2a787d0212da3 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 22 Aug 2017 13:59:44 +0200 Subject: ASoC: jack: Manage gpios via devres Let's be lazy -- this patch adds the devres code to snd_soc_jack_add_gpios() for releasing the gpio resources at device removal automagically. After this patch, you don't have to call snd_soc_jack_free_gpios() manually as long as it's managed from the machine driver. What about the gpios assigned in other levels? Well, you might still need to free the resources manually, depending on how the component unbind works. Signed-off-by: Takashi Iwai Signed-off-by: Mark Brown --- sound/soc/soc-jack.c | 52 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 11 deletions(-) (limited to 'sound/soc/soc-jack.c') diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c index 42ca9f19843b..4c83734ae596 100644 --- a/sound/soc/soc-jack.c +++ b/sound/soc/soc-jack.c @@ -22,6 +22,12 @@ #include #include +struct jack_gpio_tbl { + int count; + struct snd_soc_jack *jack; + struct snd_soc_jack_gpio *gpios; +}; + /** * snd_soc_codec_set_jack - configure codec jack. * @codec: CODEC @@ -333,6 +339,28 @@ static int snd_soc_jack_pm_notifier(struct notifier_block *nb, return NOTIFY_DONE; } +static void jack_free_gpios(struct snd_soc_jack *jack, int count, + struct snd_soc_jack_gpio *gpios) +{ + int i; + + for (i = 0; i < count; i++) { + gpiod_unexport(gpios[i].desc); + unregister_pm_notifier(&gpios[i].pm_notifier); + free_irq(gpiod_to_irq(gpios[i].desc), &gpios[i]); + cancel_delayed_work_sync(&gpios[i].work); + gpiod_put(gpios[i].desc); + gpios[i].jack = NULL; + } +} + +static void jack_devres_free_gpios(struct device *dev, void *res) +{ + struct jack_gpio_tbl *tbl = res; + + jack_free_gpios(tbl->jack, tbl->count, tbl->gpios); +} + /** * snd_soc_jack_add_gpios - Associate GPIO pins with an ASoC jack * @@ -347,6 +375,14 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count, struct snd_soc_jack_gpio *gpios) { int i, ret; + struct jack_gpio_tbl *tbl; + + tbl = devres_alloc(jack_devres_free_gpios, sizeof(*tbl), GFP_KERNEL); + if (!tbl) + return -ENOMEM; + tbl->jack = jack; + tbl->count = count; + tbl->gpios = gpios; for (i = 0; i < count; i++) { if (!gpios[i].name) { @@ -424,12 +460,14 @@ got_gpio: msecs_to_jiffies(gpios[i].debounce_time)); } + devres_add(jack->card->dev, tbl); return 0; err: gpio_free(gpios[i].gpio); undo: - snd_soc_jack_free_gpios(jack, i, gpios); + jack_free_gpios(jack, i, gpios); + devres_free(tbl); return ret; } @@ -471,16 +509,8 @@ EXPORT_SYMBOL_GPL(snd_soc_jack_add_gpiods); void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count, struct snd_soc_jack_gpio *gpios) { - int i; - - for (i = 0; i < count; i++) { - gpiod_unexport(gpios[i].desc); - unregister_pm_notifier(&gpios[i].pm_notifier); - free_irq(gpiod_to_irq(gpios[i].desc), &gpios[i]); - cancel_delayed_work_sync(&gpios[i].work); - gpiod_put(gpios[i].desc); - gpios[i].jack = NULL; - } + jack_free_gpios(jack, count, gpios); + devres_destroy(jack->card->dev, jack_devres_free_gpios, NULL, NULL); } EXPORT_SYMBOL_GPL(snd_soc_jack_free_gpios); #endif /* CONFIG_GPIOLIB */ -- cgit v1.2.3