Skip to content

Commit 222e728

Browse files
larsclausenbroonie
authored andcommitted
ASoC: uda1380: Request GPIOs at bus probe time
Resources should be requested when the device is probed on the control bus rather then when the CODEC is bound to the sound card. This allows things like probe deferring and device managed allocations to work. So move the GPIO request calls from the CODEC probe to the bus probe and also make them managed along the way. Signed-off-by: Lars-Peter Clausen <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 4185d4b commit 222e728

File tree

1 file changed

+20
-35
lines changed

1 file changed

+20
-35
lines changed

sound/soc/codecs/uda1380.c

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -698,25 +698,10 @@ static int uda1380_probe(struct snd_soc_codec *codec)
698698
codec->hw_write = (hw_write_t)i2c_master_send;
699699
codec->control_data = uda1380->control_data;
700700

701-
if (!pdata)
702-
return -EINVAL;
703-
704-
if (gpio_is_valid(pdata->gpio_reset)) {
705-
ret = gpio_request_one(pdata->gpio_reset, GPIOF_OUT_INIT_LOW,
706-
"uda1380 reset");
707-
if (ret)
708-
goto err_out;
709-
}
710-
711-
if (gpio_is_valid(pdata->gpio_power)) {
712-
ret = gpio_request_one(pdata->gpio_power, GPIOF_OUT_INIT_LOW,
713-
"uda1380 power");
714-
if (ret)
715-
goto err_free_gpio;
716-
} else {
701+
if (!gpio_is_valid(pdata->gpio_power)) {
717702
ret = uda1380_reset(codec);
718703
if (ret)
719-
goto err_free_gpio;
704+
return ret;
720705
}
721706

722707
INIT_WORK(&uda1380->work, uda1380_flush_work);
@@ -732,29 +717,11 @@ static int uda1380_probe(struct snd_soc_codec *codec)
732717
break;
733718
}
734719

735-
return 0;
736-
737-
err_free_gpio:
738-
if (gpio_is_valid(pdata->gpio_reset))
739-
gpio_free(pdata->gpio_reset);
740-
err_out:
741-
return ret;
742-
}
743-
744-
/* power down chip */
745-
static int uda1380_remove(struct snd_soc_codec *codec)
746-
{
747-
struct uda1380_platform_data *pdata =codec->dev->platform_data;
748-
749-
gpio_free(pdata->gpio_reset);
750-
gpio_free(pdata->gpio_power);
751-
752720
return 0;
753721
}
754722

755723
static struct snd_soc_codec_driver soc_codec_dev_uda1380 = {
756724
.probe = uda1380_probe,
757-
.remove = uda1380_remove,
758725
.read = uda1380_read_reg_cache,
759726
.write = uda1380_write,
760727
.set_bias_level = uda1380_set_bias_level,
@@ -778,14 +745,32 @@ static struct snd_soc_codec_driver soc_codec_dev_uda1380 = {
778745
static int uda1380_i2c_probe(struct i2c_client *i2c,
779746
const struct i2c_device_id *id)
780747
{
748+
struct uda1380_platform_data *pdata = i2c->dev.platform_data;
781749
struct uda1380_priv *uda1380;
782750
int ret;
783751

752+
if (!pdata)
753+
return -EINVAL;
754+
784755
uda1380 = devm_kzalloc(&i2c->dev, sizeof(struct uda1380_priv),
785756
GFP_KERNEL);
786757
if (uda1380 == NULL)
787758
return -ENOMEM;
788759

760+
if (gpio_is_valid(pdata->gpio_reset)) {
761+
ret = devm_gpio_request_one(&i2c->dev, pdata->gpio_reset,
762+
GPIOF_OUT_INIT_LOW, "uda1380 reset");
763+
if (ret)
764+
return ret;
765+
}
766+
767+
if (gpio_is_valid(pdata->gpio_power)) {
768+
ret = devm_gpio_request_one(&i2c->dev, pdata->gpio_power,
769+
GPIOF_OUT_INIT_LOW, "uda1380 power");
770+
if (ret)
771+
return ret;
772+
}
773+
789774
i2c_set_clientdata(i2c, uda1380);
790775
uda1380->control_data = i2c;
791776

0 commit comments

Comments
 (0)