Skip to content

Commit

Permalink
ASoC: uda1380: Request GPIOs at bus probe time
Browse files Browse the repository at this point in the history
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 <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Lars-Peter Clausen authored and Mark Brown committed Nov 23, 2016
1 parent 4185d4b commit 222e728
Showing 1 changed file with 20 additions and 35 deletions.
55 changes: 20 additions & 35 deletions sound/soc/codecs/uda1380.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,25 +698,10 @@ static int uda1380_probe(struct snd_soc_codec *codec)
codec->hw_write = (hw_write_t)i2c_master_send;
codec->control_data = uda1380->control_data;

if (!pdata)
return -EINVAL;

if (gpio_is_valid(pdata->gpio_reset)) {
ret = gpio_request_one(pdata->gpio_reset, GPIOF_OUT_INIT_LOW,
"uda1380 reset");
if (ret)
goto err_out;
}

if (gpio_is_valid(pdata->gpio_power)) {
ret = gpio_request_one(pdata->gpio_power, GPIOF_OUT_INIT_LOW,
"uda1380 power");
if (ret)
goto err_free_gpio;
} else {
if (!gpio_is_valid(pdata->gpio_power)) {
ret = uda1380_reset(codec);
if (ret)
goto err_free_gpio;
return ret;
}

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

return 0;

err_free_gpio:
if (gpio_is_valid(pdata->gpio_reset))
gpio_free(pdata->gpio_reset);
err_out:
return ret;
}

/* power down chip */
static int uda1380_remove(struct snd_soc_codec *codec)
{
struct uda1380_platform_data *pdata =codec->dev->platform_data;

gpio_free(pdata->gpio_reset);
gpio_free(pdata->gpio_power);

return 0;
}

static struct snd_soc_codec_driver soc_codec_dev_uda1380 = {
.probe = uda1380_probe,
.remove = uda1380_remove,
.read = uda1380_read_reg_cache,
.write = uda1380_write,
.set_bias_level = uda1380_set_bias_level,
Expand All @@ -778,14 +745,32 @@ static struct snd_soc_codec_driver soc_codec_dev_uda1380 = {
static int uda1380_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
struct uda1380_platform_data *pdata = i2c->dev.platform_data;
struct uda1380_priv *uda1380;
int ret;

if (!pdata)
return -EINVAL;

uda1380 = devm_kzalloc(&i2c->dev, sizeof(struct uda1380_priv),
GFP_KERNEL);
if (uda1380 == NULL)
return -ENOMEM;

if (gpio_is_valid(pdata->gpio_reset)) {
ret = devm_gpio_request_one(&i2c->dev, pdata->gpio_reset,
GPIOF_OUT_INIT_LOW, "uda1380 reset");
if (ret)
return ret;
}

if (gpio_is_valid(pdata->gpio_power)) {
ret = devm_gpio_request_one(&i2c->dev, pdata->gpio_power,
GPIOF_OUT_INIT_LOW, "uda1380 power");
if (ret)
return ret;
}

i2c_set_clientdata(i2c, uda1380);
uda1380->control_data = i2c;

Expand Down

0 comments on commit 222e728

Please sign in to comment.