diff options
Diffstat (limited to 'sound/soc/codecs/wm8804.c')
-rw-r--r-- | sound/soc/codecs/wm8804.c | 109 |
1 files changed, 59 insertions, 50 deletions
diff --git a/sound/soc/codecs/wm8804.c b/sound/soc/codecs/wm8804.c index cff34be61f88..1e403f67cf16 100644 --- a/sound/soc/codecs/wm8804.c +++ b/sound/soc/codecs/wm8804.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/gpio/consumer.h> | 16 | #include <linux/gpio/consumer.h> |
17 | #include <linux/delay.h> | 17 | #include <linux/delay.h> |
18 | #include <linux/pm.h> | 18 | #include <linux/pm.h> |
19 | #include <linux/pm_runtime.h> | ||
19 | #include <linux/of_device.h> | 20 | #include <linux/of_device.h> |
20 | #include <linux/regulator/consumer.h> | 21 | #include <linux/regulator/consumer.h> |
21 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
@@ -59,6 +60,7 @@ static const struct reg_default wm8804_reg_defaults[] = { | |||
59 | }; | 60 | }; |
60 | 61 | ||
61 | struct wm8804_priv { | 62 | struct wm8804_priv { |
63 | struct device *dev; | ||
62 | struct regmap *regmap; | 64 | struct regmap *regmap; |
63 | struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES]; | 65 | struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES]; |
64 | struct notifier_block disable_nb[WM8804_NUM_SUPPLIES]; | 66 | struct notifier_block disable_nb[WM8804_NUM_SUPPLIES]; |
@@ -403,19 +405,19 @@ static int wm8804_set_pll(struct snd_soc_dai *dai, int pll_id, | |||
403 | int source, unsigned int freq_in, | 405 | int source, unsigned int freq_in, |
404 | unsigned int freq_out) | 406 | unsigned int freq_out) |
405 | { | 407 | { |
406 | struct snd_soc_codec *codec; | 408 | struct snd_soc_codec *codec = dai->codec; |
409 | struct wm8804_priv *wm8804 = snd_soc_codec_get_drvdata(codec); | ||
410 | bool change; | ||
407 | 411 | ||
408 | codec = dai->codec; | ||
409 | if (!freq_in || !freq_out) { | 412 | if (!freq_in || !freq_out) { |
410 | /* disable the PLL */ | 413 | /* disable the PLL */ |
411 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x1, 0x1); | 414 | regmap_update_bits_check(wm8804->regmap, WM8804_PWRDN, |
412 | return 0; | 415 | 0x1, 0x1, &change); |
416 | if (change) | ||
417 | pm_runtime_put(wm8804->dev); | ||
413 | } else { | 418 | } else { |
414 | int ret; | 419 | int ret; |
415 | struct pll_div pll_div; | 420 | struct pll_div pll_div; |
416 | struct wm8804_priv *wm8804; | ||
417 | |||
418 | wm8804 = snd_soc_codec_get_drvdata(codec); | ||
419 | 421 | ||
420 | ret = pll_factors(&pll_div, freq_out, freq_in, | 422 | ret = pll_factors(&pll_div, freq_out, freq_in, |
421 | wm8804->mclk_div); | 423 | wm8804->mclk_div); |
@@ -423,7 +425,10 @@ static int wm8804_set_pll(struct snd_soc_dai *dai, int pll_id, | |||
423 | return ret; | 425 | return ret; |
424 | 426 | ||
425 | /* power down the PLL before reprogramming it */ | 427 | /* power down the PLL before reprogramming it */ |
426 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x1, 0x1); | 428 | regmap_update_bits_check(wm8804->regmap, WM8804_PWRDN, |
429 | 0x1, 0x1, &change); | ||
430 | if (!change) | ||
431 | pm_runtime_get_sync(wm8804->dev); | ||
427 | 432 | ||
428 | /* set PLLN and PRESCALE */ | 433 | /* set PLLN and PRESCALE */ |
429 | snd_soc_update_bits(codec, WM8804_PLL4, 0xf | 0x10, | 434 | snd_soc_update_bits(codec, WM8804_PLL4, 0xf | 0x10, |
@@ -501,47 +506,6 @@ static int wm8804_set_clkdiv(struct snd_soc_dai *dai, | |||
501 | return 0; | 506 | return 0; |
502 | } | 507 | } |
503 | 508 | ||
504 | static int wm8804_set_bias_level(struct snd_soc_codec *codec, | ||
505 | enum snd_soc_bias_level level) | ||
506 | { | ||
507 | int ret; | ||
508 | struct wm8804_priv *wm8804; | ||
509 | |||
510 | wm8804 = snd_soc_codec_get_drvdata(codec); | ||
511 | switch (level) { | ||
512 | case SND_SOC_BIAS_ON: | ||
513 | break; | ||
514 | case SND_SOC_BIAS_PREPARE: | ||
515 | /* power up the OSC and the PLL */ | ||
516 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0); | ||
517 | break; | ||
518 | case SND_SOC_BIAS_STANDBY: | ||
519 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { | ||
520 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8804->supplies), | ||
521 | wm8804->supplies); | ||
522 | if (ret) { | ||
523 | dev_err(codec->dev, | ||
524 | "Failed to enable supplies: %d\n", | ||
525 | ret); | ||
526 | return ret; | ||
527 | } | ||
528 | regcache_sync(wm8804->regmap); | ||
529 | } | ||
530 | /* power down the OSC and the PLL */ | ||
531 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0x9); | ||
532 | break; | ||
533 | case SND_SOC_BIAS_OFF: | ||
534 | /* power down the OSC and the PLL */ | ||
535 | snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0x9); | ||
536 | regulator_bulk_disable(ARRAY_SIZE(wm8804->supplies), | ||
537 | wm8804->supplies); | ||
538 | break; | ||
539 | } | ||
540 | |||
541 | codec->dapm.bias_level = level; | ||
542 | return 0; | ||
543 | } | ||
544 | |||
545 | static const struct snd_soc_dai_ops wm8804_dai_ops = { | 509 | static const struct snd_soc_dai_ops wm8804_dai_ops = { |
546 | .hw_params = wm8804_hw_params, | 510 | .hw_params = wm8804_hw_params, |
547 | .set_fmt = wm8804_set_fmt, | 511 | .set_fmt = wm8804_set_fmt, |
@@ -579,7 +543,6 @@ static struct snd_soc_dai_driver wm8804_dai = { | |||
579 | }; | 543 | }; |
580 | 544 | ||
581 | static const struct snd_soc_codec_driver soc_codec_dev_wm8804 = { | 545 | static const struct snd_soc_codec_driver soc_codec_dev_wm8804 = { |
582 | .set_bias_level = wm8804_set_bias_level, | ||
583 | .idle_bias_off = true, | 546 | .idle_bias_off = true, |
584 | 547 | ||
585 | .dapm_widgets = wm8804_dapm_widgets, | 548 | .dapm_widgets = wm8804_dapm_widgets, |
@@ -613,6 +576,7 @@ int wm8804_probe(struct device *dev, struct regmap *regmap) | |||
613 | 576 | ||
614 | dev_set_drvdata(dev, wm8804); | 577 | dev_set_drvdata(dev, wm8804); |
615 | 578 | ||
579 | wm8804->dev = dev; | ||
616 | wm8804->regmap = regmap; | 580 | wm8804->regmap = regmap; |
617 | 581 | ||
618 | wm8804->reset = devm_gpiod_get_optional(dev, "wlf,reset", | 582 | wm8804->reset = devm_gpiod_get_optional(dev, "wlf,reset", |
@@ -703,6 +667,10 @@ int wm8804_probe(struct device *dev, struct regmap *regmap) | |||
703 | goto err_reg_enable; | 667 | goto err_reg_enable; |
704 | } | 668 | } |
705 | 669 | ||
670 | pm_runtime_set_active(dev); | ||
671 | pm_runtime_enable(dev); | ||
672 | pm_runtime_idle(dev); | ||
673 | |||
706 | return 0; | 674 | return 0; |
707 | 675 | ||
708 | err_reg_enable: | 676 | err_reg_enable: |
@@ -713,10 +681,51 @@ EXPORT_SYMBOL_GPL(wm8804_probe); | |||
713 | 681 | ||
714 | void wm8804_remove(struct device *dev) | 682 | void wm8804_remove(struct device *dev) |
715 | { | 683 | { |
684 | pm_runtime_disable(dev); | ||
716 | snd_soc_unregister_codec(dev); | 685 | snd_soc_unregister_codec(dev); |
717 | } | 686 | } |
718 | EXPORT_SYMBOL_GPL(wm8804_remove); | 687 | EXPORT_SYMBOL_GPL(wm8804_remove); |
719 | 688 | ||
689 | #if IS_ENABLED(CONFIG_PM) | ||
690 | static int wm8804_runtime_resume(struct device *dev) | ||
691 | { | ||
692 | struct wm8804_priv *wm8804 = dev_get_drvdata(dev); | ||
693 | int ret; | ||
694 | |||
695 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8804->supplies), | ||
696 | wm8804->supplies); | ||
697 | if (ret) { | ||
698 | dev_err(wm8804->dev, "Failed to enable supplies: %d\n", ret); | ||
699 | return ret; | ||
700 | } | ||
701 | |||
702 | regcache_sync(wm8804->regmap); | ||
703 | |||
704 | /* Power up OSCCLK */ | ||
705 | regmap_update_bits(wm8804->regmap, WM8804_PWRDN, 0x8, 0x0); | ||
706 | |||
707 | return 0; | ||
708 | } | ||
709 | |||
710 | static int wm8804_runtime_suspend(struct device *dev) | ||
711 | { | ||
712 | struct wm8804_priv *wm8804 = dev_get_drvdata(dev); | ||
713 | |||
714 | /* Power down OSCCLK */ | ||
715 | regmap_update_bits(wm8804->regmap, WM8804_PWRDN, 0x8, 0x8); | ||
716 | |||
717 | regulator_bulk_disable(ARRAY_SIZE(wm8804->supplies), | ||
718 | wm8804->supplies); | ||
719 | |||
720 | return 0; | ||
721 | } | ||
722 | #endif | ||
723 | |||
724 | const struct dev_pm_ops wm8804_pm = { | ||
725 | SET_RUNTIME_PM_OPS(wm8804_runtime_suspend, wm8804_runtime_resume, NULL) | ||
726 | }; | ||
727 | EXPORT_SYMBOL_GPL(wm8804_pm); | ||
728 | |||
720 | MODULE_DESCRIPTION("ASoC WM8804 driver"); | 729 | MODULE_DESCRIPTION("ASoC WM8804 driver"); |
721 | MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>"); | 730 | MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>"); |
722 | MODULE_LICENSE("GPL"); | 731 | MODULE_LICENSE("GPL"); |