ASoC: mchp-pdmc: add support for suspend to RAM
authorClaudiu Beznea <claudiu.beznea@microchip.com>
Tue, 13 Dec 2022 11:28:50 +0000 (13:28 +0200)
committerMark Brown <broonie@kernel.org>
Sun, 25 Dec 2022 23:33:17 +0000 (23:33 +0000)
Add support for suspend to RAM by re-aranging the lines in switch..case
from mchp_pdmc_trigger() and saving/restoring the enabled interrupts. These
are necessary as AT91 devices has a special power saving mode (called
backup and self-refresh) where most of the SoC parts are powered off
and thus we need to reconfigure the PDMC on resume.

Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Link: https://lore.kernel.org/r/20221213112851.89212-4-claudiu.beznea@microchip.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/atmel/mchp-pdmc.c

index f184404..cf4084d 100644 (file)
@@ -113,6 +113,7 @@ struct mchp_pdmc {
        struct clk *pclk;
        struct clk *gclk;
        u32 pdmcen;
+       u32 suspend_irq;
        int mic_no;
        int sinc_order;
        bool audio_filter_en;
@@ -641,22 +642,27 @@ static int mchp_pdmc_trigger(struct snd_pcm_substream *substream,
 #endif
 
        switch (cmd) {
-       case SNDRV_PCM_TRIGGER_START:
        case SNDRV_PCM_TRIGGER_RESUME:
-       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+       case SNDRV_PCM_TRIGGER_START:
                /* Enable overrun and underrun error interrupts */
-               regmap_write(dd->regmap, MCHP_PDMC_IER,
+               regmap_write(dd->regmap, MCHP_PDMC_IER, dd->suspend_irq |
                             MCHP_PDMC_IR_RXOVR | MCHP_PDMC_IR_RXUDR);
+               dd->suspend_irq = 0;
+               fallthrough;
+       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
                snd_soc_component_update_bits(cpu, MCHP_PDMC_MR,
                                              MCHP_PDMC_MR_PDMCEN_MASK,
                                              dd->pdmcen);
                break;
-       case SNDRV_PCM_TRIGGER_STOP:
        case SNDRV_PCM_TRIGGER_SUSPEND:
-       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+               regmap_read(dd->regmap, MCHP_PDMC_IMR, &dd->suspend_irq);
+               fallthrough;
+       case SNDRV_PCM_TRIGGER_STOP:
                /* Disable overrun and underrun error interrupts */
-               regmap_write(dd->regmap, MCHP_PDMC_IDR,
+               regmap_write(dd->regmap, MCHP_PDMC_IDR, dd->suspend_irq |
                             MCHP_PDMC_IR_RXOVR | MCHP_PDMC_IR_RXUDR);
+               fallthrough;
+       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
                snd_soc_component_update_bits(cpu, MCHP_PDMC_MR,
                                              MCHP_PDMC_MR_PDMCEN_MASK, 0);
                break;
@@ -1107,6 +1113,7 @@ static const struct of_device_id mchp_pdmc_of_match[] = {
 MODULE_DEVICE_TABLE(of, mchp_pdmc_of_match);
 
 static const struct dev_pm_ops mchp_pdmc_pm_ops = {
+       SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
        RUNTIME_PM_OPS(mchp_pdmc_runtime_suspend, mchp_pdmc_runtime_resume,
                       NULL)
 };