ASoC: pandora: add a regulator for dac
authorGrazvydas Ignotas <notasas@gmail.com>
Sun, 22 May 2016 22:19:46 +0000 (01:19 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Sun, 3 Jul 2016 00:23:25 +0000 (03:23 +0300)
Comes from regen-controlled 5V supply.

sound/soc/omap/omap3pandora.c

index 796484d..4099227 100644 (file)
@@ -43,6 +43,7 @@
 #define PREFIX "ASoC omap3pandora: "
 
 static struct regulator *omap3pandora_dac_reg;
+static struct regulator *omap3pandora_amp_reg;
 
 static int omap3pandora_hw_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
@@ -113,8 +114,7 @@ static int omap3pandora_dac_event(struct snd_soc_dapm_widget *w,
                gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO, 1);
        } else {
                gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO, 0);
-               mdelay(1);
-               regulator_disable(omap3pandora_dac_reg);
+               regulator_disable_deferred(omap3pandora_dac_reg, 1);
        }
 
        return 0;
@@ -123,10 +123,16 @@ static int omap3pandora_dac_event(struct snd_soc_dapm_widget *w,
 static int omap3pandora_hp_event(struct snd_soc_dapm_widget *w,
        struct snd_kcontrol *k, int event)
 {
-       if (SND_SOC_DAPM_EVENT_ON(event))
+       if (SND_SOC_DAPM_EVENT_ON(event)) {
+               regulator_enable(omap3pandora_amp_reg);
                gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO, 1);
-       else
+       }
+       else {
                gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO, 0);
+               /* wait for the large caps to discharge, otherwise the
+                * "turn off noise" heard through the speakers takes longer */
+               regulator_disable_deferred(omap3pandora_amp_reg, 1000);
+       }
 
        return 0;
 }
@@ -320,8 +326,19 @@ static int __init omap3pandora_soc_init(void)
                goto fail3;
        }
 
+       omap3pandora_amp_reg = regulator_get(&omap3pandora_snd_device->dev, "vdd_amp");
+       if (IS_ERR(omap3pandora_amp_reg)) {
+               pr_err(PREFIX "Failed to get amp regulator from %s: %ld\n",
+                       dev_name(&omap3pandora_snd_device->dev),
+                       PTR_ERR(omap3pandora_amp_reg));
+               ret = PTR_ERR(omap3pandora_amp_reg);
+               goto fail4;
+       }
+
        return 0;
 
+fail4:
+       regulator_put(omap3pandora_dac_reg);
 fail3:
        platform_device_del(omap3pandora_snd_device);
 fail2:
@@ -337,6 +354,7 @@ module_init(omap3pandora_soc_init);
 static void __exit omap3pandora_soc_exit(void)
 {
        regulator_put(omap3pandora_dac_reg);
+       regulator_put(omap3pandora_amp_reg);
        platform_device_unregister(omap3pandora_snd_device);
        gpio_free(OMAP3_PANDORA_AMP_POWER_GPIO);
        gpio_free(OMAP3_PANDORA_DAC_POWER_GPIO);