diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-10-10 07:32:03 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-10-14 22:49:41 -0400 |
commit | f81ad9421a49107a9d12f902af3373fbcd808288 (patch) | |
tree | c0cdb9e6262c80fe05c82caeeb82a50539a32979 /sound/soc/codecs | |
parent | c16a7428912350a28f51df48c5f738523b1ecd8b (diff) |
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: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs')
-rw-r--r-- | sound/soc/codecs/wm8770.c | 81 |
1 files changed, 35 insertions, 46 deletions
diff --git a/sound/soc/codecs/wm8770.c b/sound/soc/codecs/wm8770.c index 8eefe429e384..90920315f536 100644 --- a/sound/soc/codecs/wm8770.c +++ b/sound/soc/codecs/wm8770.c | |||
@@ -576,7 +576,6 @@ static int wm8770_probe(struct snd_soc_codec *codec) | |||
576 | { | 576 | { |
577 | struct wm8770_priv *wm8770; | 577 | struct wm8770_priv *wm8770; |
578 | int ret; | 578 | int ret; |
579 | int i; | ||
580 | 579 | ||
581 | wm8770 = snd_soc_codec_get_drvdata(codec); | 580 | wm8770 = snd_soc_codec_get_drvdata(codec); |
582 | wm8770->codec = codec; | 581 | wm8770->codec = codec; |
@@ -587,36 +586,11 @@ static int wm8770_probe(struct snd_soc_codec *codec) | |||
587 | return ret; | 586 | return ret; |
588 | } | 587 | } |
589 | 588 | ||
590 | for (i = 0; i < ARRAY_SIZE(wm8770->supplies); i++) | ||
591 | wm8770->supplies[i].supply = wm8770_supply_names[i]; | ||
592 | |||
593 | ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8770->supplies), | ||
594 | wm8770->supplies); | ||
595 | if (ret) { | ||
596 | dev_err(codec->dev, "Failed to request supplies: %d\n", ret); | ||
597 | return ret; | ||
598 | } | ||
599 | |||
600 | wm8770->disable_nb[0].notifier_call = wm8770_regulator_event_0; | ||
601 | wm8770->disable_nb[1].notifier_call = wm8770_regulator_event_1; | ||
602 | wm8770->disable_nb[2].notifier_call = wm8770_regulator_event_2; | ||
603 | |||
604 | /* This should really be moved into the regulator core */ | ||
605 | for (i = 0; i < ARRAY_SIZE(wm8770->supplies); i++) { | ||
606 | ret = regulator_register_notifier(wm8770->supplies[i].consumer, | ||
607 | &wm8770->disable_nb[i]); | ||
608 | if (ret) { | ||
609 | dev_err(codec->dev, | ||
610 | "Failed to register regulator notifier: %d\n", | ||
611 | ret); | ||
612 | } | ||
613 | } | ||
614 | |||
615 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8770->supplies), | 589 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8770->supplies), |
616 | wm8770->supplies); | 590 | wm8770->supplies); |
617 | if (ret) { | 591 | if (ret) { |
618 | dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); | 592 | dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); |
619 | goto err_reg_get; | 593 | return ret; |
620 | } | 594 | } |
621 | 595 | ||
622 | ret = wm8770_reset(codec); | 596 | ret = wm8770_reset(codec); |
@@ -646,32 +620,14 @@ static int wm8770_probe(struct snd_soc_codec *codec) | |||
646 | ARRAY_SIZE(wm8770_dapm_widgets)); | 620 | ARRAY_SIZE(wm8770_dapm_widgets)); |
647 | snd_soc_dapm_add_routes(&codec->dapm, wm8770_intercon, | 621 | snd_soc_dapm_add_routes(&codec->dapm, wm8770_intercon, |
648 | ARRAY_SIZE(wm8770_intercon)); | 622 | ARRAY_SIZE(wm8770_intercon)); |
649 | return 0; | ||
650 | 623 | ||
651 | err_reg_enable: | 624 | err_reg_enable: |
652 | regulator_bulk_disable(ARRAY_SIZE(wm8770->supplies), wm8770->supplies); | 625 | regulator_bulk_disable(ARRAY_SIZE(wm8770->supplies), wm8770->supplies); |
653 | err_reg_get: | ||
654 | regulator_bulk_free(ARRAY_SIZE(wm8770->supplies), wm8770->supplies); | ||
655 | return ret; | 626 | return ret; |
656 | } | 627 | } |
657 | 628 | ||
658 | static int wm8770_remove(struct snd_soc_codec *codec) | ||
659 | { | ||
660 | struct wm8770_priv *wm8770; | ||
661 | int i; | ||
662 | |||
663 | wm8770 = snd_soc_codec_get_drvdata(codec); | ||
664 | |||
665 | for (i = 0; i < ARRAY_SIZE(wm8770->supplies); ++i) | ||
666 | regulator_unregister_notifier(wm8770->supplies[i].consumer, | ||
667 | &wm8770->disable_nb[i]); | ||
668 | regulator_bulk_free(ARRAY_SIZE(wm8770->supplies), wm8770->supplies); | ||
669 | return 0; | ||
670 | } | ||
671 | |||
672 | static struct snd_soc_codec_driver soc_codec_dev_wm8770 = { | 629 | static struct snd_soc_codec_driver soc_codec_dev_wm8770 = { |
673 | .probe = wm8770_probe, | 630 | .probe = wm8770_probe, |
674 | .remove = wm8770_remove, | ||
675 | .set_bias_level = wm8770_set_bias_level, | 631 | .set_bias_level = wm8770_set_bias_level, |
676 | .idle_bias_off = true, | 632 | .idle_bias_off = true, |
677 | }; | 633 | }; |
@@ -697,13 +653,38 @@ static const struct regmap_config wm8770_regmap = { | |||
697 | static int __devinit wm8770_spi_probe(struct spi_device *spi) | 653 | static int __devinit wm8770_spi_probe(struct spi_device *spi) |
698 | { | 654 | { |
699 | struct wm8770_priv *wm8770; | 655 | struct wm8770_priv *wm8770; |
700 | int ret; | 656 | int ret, i; |
701 | 657 | ||
702 | wm8770 = devm_kzalloc(&spi->dev, sizeof(struct wm8770_priv), | 658 | wm8770 = devm_kzalloc(&spi->dev, sizeof(struct wm8770_priv), |
703 | GFP_KERNEL); | 659 | GFP_KERNEL); |
704 | if (!wm8770) | 660 | if (!wm8770) |
705 | return -ENOMEM; | 661 | return -ENOMEM; |
706 | 662 | ||
663 | for (i = 0; i < ARRAY_SIZE(wm8770->supplies); i++) | ||
664 | wm8770->supplies[i].supply = wm8770_supply_names[i]; | ||
665 | |||
666 | ret = devm_regulator_bulk_get(&spi->dev, ARRAY_SIZE(wm8770->supplies), | ||
667 | wm8770->supplies); | ||
668 | if (ret) { | ||
669 | dev_err(&spi->dev, "Failed to request supplies: %d\n", ret); | ||
670 | return ret; | ||
671 | } | ||
672 | |||
673 | wm8770->disable_nb[0].notifier_call = wm8770_regulator_event_0; | ||
674 | wm8770->disable_nb[1].notifier_call = wm8770_regulator_event_1; | ||
675 | wm8770->disable_nb[2].notifier_call = wm8770_regulator_event_2; | ||
676 | |||
677 | /* This should really be moved into the regulator core */ | ||
678 | for (i = 0; i < ARRAY_SIZE(wm8770->supplies); i++) { | ||
679 | ret = regulator_register_notifier(wm8770->supplies[i].consumer, | ||
680 | &wm8770->disable_nb[i]); | ||
681 | if (ret) { | ||
682 | dev_err(&spi->dev, | ||
683 | "Failed to register regulator notifier: %d\n", | ||
684 | ret); | ||
685 | } | ||
686 | } | ||
687 | |||
707 | wm8770->regmap = devm_regmap_init_spi(spi, &wm8770_regmap); | 688 | wm8770->regmap = devm_regmap_init_spi(spi, &wm8770_regmap); |
708 | if (IS_ERR(wm8770->regmap)) | 689 | if (IS_ERR(wm8770->regmap)) |
709 | return PTR_ERR(wm8770->regmap); | 690 | return PTR_ERR(wm8770->regmap); |
@@ -718,7 +699,15 @@ static int __devinit wm8770_spi_probe(struct spi_device *spi) | |||
718 | 699 | ||
719 | static int __devexit wm8770_spi_remove(struct spi_device *spi) | 700 | static int __devexit wm8770_spi_remove(struct spi_device *spi) |
720 | { | 701 | { |
702 | struct wm8770_priv *wm8770 = spi_get_drvdata(spi); | ||
703 | int i; | ||
704 | |||
705 | for (i = 0; i < ARRAY_SIZE(wm8770->supplies); ++i) | ||
706 | regulator_unregister_notifier(wm8770->supplies[i].consumer, | ||
707 | &wm8770->disable_nb[i]); | ||
708 | |||
721 | snd_soc_unregister_codec(&spi->dev); | 709 | snd_soc_unregister_codec(&spi->dev); |
710 | |||
722 | return 0; | 711 | return 0; |
723 | } | 712 | } |
724 | 713 | ||