Commit 398575db authored by Mark Brown's avatar Mark Brown

ASoC: Refactor WM8741 regulator handling into CODEC generic code

No meaningful runtime impact but is more in line with other CODECs and
will support further work.
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: default avatarLiam Girdwood <lrg@ti.com>
parent 68817ee4
...@@ -422,17 +422,35 @@ static int wm8741_probe(struct snd_soc_codec *codec) ...@@ -422,17 +422,35 @@ static int wm8741_probe(struct snd_soc_codec *codec)
{ {
struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
int ret = 0; int ret = 0;
int i;
for (i = 0; i < ARRAY_SIZE(wm8741->supplies); i++)
wm8741->supplies[i].supply = wm8741_supply_names[i];
ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8741->supplies),
wm8741->supplies);
if (ret != 0) {
dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
goto err;
}
ret = regulator_bulk_enable(ARRAY_SIZE(wm8741->supplies),
wm8741->supplies);
if (ret != 0) {
dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
goto err_get;
}
ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8741->control_type); ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8741->control_type);
if (ret != 0) { if (ret != 0) {
dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
return ret; goto err_enable;
} }
ret = wm8741_reset(codec); ret = wm8741_reset(codec);
if (ret < 0) { if (ret < 0) {
dev_err(codec->dev, "Failed to issue reset\n"); dev_err(codec->dev, "Failed to issue reset\n");
return ret; goto err_enable;
} }
/* Change some default settings - latch VU */ /* Change some default settings - latch VU */
...@@ -451,10 +469,28 @@ static int wm8741_probe(struct snd_soc_codec *codec) ...@@ -451,10 +469,28 @@ static int wm8741_probe(struct snd_soc_codec *codec)
dev_dbg(codec->dev, "Successful registration\n"); dev_dbg(codec->dev, "Successful registration\n");
return ret; return ret;
err_enable:
regulator_bulk_disable(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
err_get:
regulator_bulk_free(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
err:
return ret;
}
static int wm8741_remove(struct snd_soc_codec *codec)
{
struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
regulator_bulk_disable(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
regulator_bulk_free(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
return 0;
} }
static struct snd_soc_codec_driver soc_codec_dev_wm8741 = { static struct snd_soc_codec_driver soc_codec_dev_wm8741 = {
.probe = wm8741_probe, .probe = wm8741_probe,
.remove = wm8741_remove,
.resume = wm8741_resume, .resume = wm8741_resume,
.reg_cache_size = ARRAY_SIZE(wm8741_reg_defaults), .reg_cache_size = ARRAY_SIZE(wm8741_reg_defaults),
.reg_word_size = sizeof(u16), .reg_word_size = sizeof(u16),
...@@ -466,43 +502,22 @@ static int wm8741_i2c_probe(struct i2c_client *i2c, ...@@ -466,43 +502,22 @@ static int wm8741_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct wm8741_priv *wm8741; struct wm8741_priv *wm8741;
int ret, i; int ret;
wm8741 = kzalloc(sizeof(struct wm8741_priv), GFP_KERNEL); wm8741 = kzalloc(sizeof(struct wm8741_priv), GFP_KERNEL);
if (wm8741 == NULL) if (wm8741 == NULL)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < ARRAY_SIZE(wm8741->supplies); i++)
wm8741->supplies[i].supply = wm8741_supply_names[i];
ret = regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8741->supplies),
wm8741->supplies);
if (ret != 0) {
dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
goto err;
}
ret = regulator_bulk_enable(ARRAY_SIZE(wm8741->supplies),
wm8741->supplies);
if (ret != 0) {
dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret);
goto err_get;
}
i2c_set_clientdata(i2c, wm8741); i2c_set_clientdata(i2c, wm8741);
wm8741->control_type = SND_SOC_I2C; wm8741->control_type = SND_SOC_I2C;
ret = snd_soc_register_codec(&i2c->dev, ret = snd_soc_register_codec(&i2c->dev,
&soc_codec_dev_wm8741, &wm8741_dai, 1); &soc_codec_dev_wm8741, &wm8741_dai, 1);
if (ret < 0) if (ret != 0)
goto err_enable; goto err;
return ret;
err_enable: return ret;
regulator_bulk_disable(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
err_get:
regulator_bulk_free(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
err: err:
kfree(wm8741); kfree(wm8741);
return ret; return ret;
...@@ -510,10 +525,7 @@ static int wm8741_i2c_probe(struct i2c_client *i2c, ...@@ -510,10 +525,7 @@ static int wm8741_i2c_probe(struct i2c_client *i2c,
static int wm8741_i2c_remove(struct i2c_client *client) static int wm8741_i2c_remove(struct i2c_client *client)
{ {
struct wm8741_priv *wm8741 = i2c_get_clientdata(client);
snd_soc_unregister_codec(&client->dev); snd_soc_unregister_codec(&client->dev);
regulator_bulk_free(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
kfree(i2c_get_clientdata(client)); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment