Commit f81ad942 authored by Mark Brown's avatar Mark Brown
Browse files

ASoC: wm8770: Remove regulator allocation to SPI probe



This is more idiomatic and ensures we don't try to do the ASoC card setup
until we've got all the required resources.

Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent c16a7428
Loading
Loading
Loading
Loading
+35 −46
Original line number Diff line number Diff line
@@ -576,7 +576,6 @@ static int wm8770_probe(struct snd_soc_codec *codec)
{
	struct wm8770_priv *wm8770;
	int ret;
	int i;

	wm8770 = snd_soc_codec_get_drvdata(codec);
	wm8770->codec = codec;
@@ -587,36 +586,11 @@ static int wm8770_probe(struct snd_soc_codec *codec)
		return ret;
	}

	for (i = 0; i < ARRAY_SIZE(wm8770->supplies); i++)
		wm8770->supplies[i].supply = wm8770_supply_names[i];

	ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8770->supplies),
				 wm8770->supplies);
	if (ret) {
		dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
		return ret;
	}

	wm8770->disable_nb[0].notifier_call = wm8770_regulator_event_0;
	wm8770->disable_nb[1].notifier_call = wm8770_regulator_event_1;
	wm8770->disable_nb[2].notifier_call = wm8770_regulator_event_2;

	/* This should really be moved into the regulator core */
	for (i = 0; i < ARRAY_SIZE(wm8770->supplies); i++) {
		ret = regulator_register_notifier(wm8770->supplies[i].consumer,
						  &wm8770->disable_nb[i]);
		if (ret) {
			dev_err(codec->dev,
				"Failed to register regulator notifier: %d\n",
				ret);
		}
	}

	ret = regulator_bulk_enable(ARRAY_SIZE(wm8770->supplies),
				    wm8770->supplies);
	if (ret) {
		dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
		goto err_reg_get;
		return ret;
	}

	ret = wm8770_reset(codec);
@@ -646,32 +620,14 @@ static int wm8770_probe(struct snd_soc_codec *codec)
				  ARRAY_SIZE(wm8770_dapm_widgets));
	snd_soc_dapm_add_routes(&codec->dapm, wm8770_intercon,
				ARRAY_SIZE(wm8770_intercon));
	return 0;

err_reg_enable:
	regulator_bulk_disable(ARRAY_SIZE(wm8770->supplies), wm8770->supplies);
err_reg_get:
	regulator_bulk_free(ARRAY_SIZE(wm8770->supplies), wm8770->supplies);
	return ret;
}

static int wm8770_remove(struct snd_soc_codec *codec)
{
	struct wm8770_priv *wm8770;
	int i;

	wm8770 = snd_soc_codec_get_drvdata(codec);

	for (i = 0; i < ARRAY_SIZE(wm8770->supplies); ++i)
		regulator_unregister_notifier(wm8770->supplies[i].consumer,
					      &wm8770->disable_nb[i]);
	regulator_bulk_free(ARRAY_SIZE(wm8770->supplies), wm8770->supplies);
	return 0;
}

static struct snd_soc_codec_driver soc_codec_dev_wm8770 = {
	.probe = wm8770_probe,
	.remove = wm8770_remove,
	.set_bias_level = wm8770_set_bias_level,
	.idle_bias_off = true,
};
@@ -697,13 +653,38 @@ static const struct regmap_config wm8770_regmap = {
static int __devinit wm8770_spi_probe(struct spi_device *spi)
{
	struct wm8770_priv *wm8770;
	int ret;
	int ret, i;

	wm8770 = devm_kzalloc(&spi->dev, sizeof(struct wm8770_priv),
			      GFP_KERNEL);
	if (!wm8770)
		return -ENOMEM;

	for (i = 0; i < ARRAY_SIZE(wm8770->supplies); i++)
		wm8770->supplies[i].supply = wm8770_supply_names[i];

	ret = devm_regulator_bulk_get(&spi->dev, ARRAY_SIZE(wm8770->supplies),
				      wm8770->supplies);
	if (ret) {
		dev_err(&spi->dev, "Failed to request supplies: %d\n", ret);
		return ret;
	}

	wm8770->disable_nb[0].notifier_call = wm8770_regulator_event_0;
	wm8770->disable_nb[1].notifier_call = wm8770_regulator_event_1;
	wm8770->disable_nb[2].notifier_call = wm8770_regulator_event_2;

	/* This should really be moved into the regulator core */
	for (i = 0; i < ARRAY_SIZE(wm8770->supplies); i++) {
		ret = regulator_register_notifier(wm8770->supplies[i].consumer,
						  &wm8770->disable_nb[i]);
		if (ret) {
			dev_err(&spi->dev,
				"Failed to register regulator notifier: %d\n",
				ret);
		}
	}

	wm8770->regmap = devm_regmap_init_spi(spi, &wm8770_regmap);
	if (IS_ERR(wm8770->regmap))
		return PTR_ERR(wm8770->regmap);
@@ -718,7 +699,15 @@ static int __devinit wm8770_spi_probe(struct spi_device *spi)

static int __devexit wm8770_spi_remove(struct spi_device *spi)
{
	struct wm8770_priv *wm8770 = spi_get_drvdata(spi);
	int i;

	for (i = 0; i < ARRAY_SIZE(wm8770->supplies); ++i)
		regulator_unregister_notifier(wm8770->supplies[i].consumer,
					      &wm8770->disable_nb[i]);

	snd_soc_unregister_codec(&spi->dev);

	return 0;
}