From cf8817733d10c0147a01c97219dd0551bcf25e08 Mon Sep 17 00:00:00 2001 From: Olivier Moysan Date: Thu, 21 Mar 2019 16:34:56 +0100 Subject: ASoC: stm32: sai: add power management Add support of low power modes to STM32 SAI driver. Signed-off-by: Olivier Moysan Signed-off-by: Mark Brown --- sound/soc/stm/stm32_sai_sub.c | 45 +++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'sound/soc/stm/stm32_sai_sub.c') diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c index 55d802f51c15..2a90641cf164 100644 --- a/sound/soc/stm/stm32_sai_sub.c +++ b/sound/soc/stm/stm32_sai_sub.c @@ -168,6 +168,7 @@ static bool stm32_sai_sub_volatile_reg(struct device *dev, unsigned int reg) { switch (reg) { case STM_SAI_DR_REGX: + case STM_SAI_SR_REGX: return true; default: return false; @@ -182,7 +183,6 @@ static bool stm32_sai_sub_writeable_reg(struct device *dev, unsigned int reg) case STM_SAI_FRCR_REGX: case STM_SAI_SLOTR_REGX: case STM_SAI_IMR_REGX: - case STM_SAI_SR_REGX: case STM_SAI_CLRFR_REGX: case STM_SAI_DR_REGX: case STM_SAI_PDMCR_REGX: @@ -202,6 +202,7 @@ static const struct regmap_config stm32_sai_sub_regmap_config_f4 = { .volatile_reg = stm32_sai_sub_volatile_reg, .writeable_reg = stm32_sai_sub_writeable_reg, .fast_io = true, + .cache_type = REGCACHE_FLAT, }; static const struct regmap_config stm32_sai_sub_regmap_config_h7 = { @@ -213,6 +214,7 @@ static const struct regmap_config stm32_sai_sub_regmap_config_h7 = { .volatile_reg = stm32_sai_sub_volatile_reg, .writeable_reg = stm32_sai_sub_writeable_reg, .fast_io = true, + .cache_type = REGCACHE_FLAT, }; static int snd_pcm_iec958_info(struct snd_kcontrol *kcontrol, @@ -441,8 +443,8 @@ static irqreturn_t stm32_sai_isr(int irq, void *devid) if (!flags) return IRQ_NONE; - regmap_update_bits(sai->regmap, STM_SAI_CLRFR_REGX, SAI_XCLRFR_MASK, - SAI_XCLRFR_MASK); + regmap_write_bits(sai->regmap, STM_SAI_CLRFR_REGX, SAI_XCLRFR_MASK, + SAI_XCLRFR_MASK); if (!sai->substream) { dev_err(&pdev->dev, "Device stopped. Spurious IRQ 0x%x\n", sr); @@ -704,9 +706,8 @@ static int stm32_sai_startup(struct snd_pcm_substream *substream, } /* Enable ITs */ - - regmap_update_bits(sai->regmap, STM_SAI_CLRFR_REGX, - SAI_XCLRFR_MASK, SAI_XCLRFR_MASK); + regmap_write_bits(sai->regmap, STM_SAI_CLRFR_REGX, + SAI_XCLRFR_MASK, SAI_XCLRFR_MASK); imr = SAI_XIMR_OVRUDRIE; if (STM_SAI_IS_CAPTURE(sai)) { @@ -738,10 +739,10 @@ static int stm32_sai_set_config(struct snd_soc_dai *cpu_dai, * SAI fifo threshold is set to half fifo, to keep enough space * for DMA incoming bursts. */ - regmap_update_bits(sai->regmap, STM_SAI_CR2_REGX, - SAI_XCR2_FFLUSH | SAI_XCR2_FTH_MASK, - SAI_XCR2_FFLUSH | - SAI_XCR2_FTH_SET(STM_SAI_FIFO_TH_HALF)); + regmap_write_bits(sai->regmap, STM_SAI_CR2_REGX, + SAI_XCR2_FFLUSH | SAI_XCR2_FTH_MASK, + SAI_XCR2_FFLUSH | + SAI_XCR2_FTH_SET(STM_SAI_FIFO_TH_HALF)); /* DS bits in CR1 not set for SPDIF (size forced to 24 bits).*/ if (STM_SAI_PROTOCOL_IS_SPDIF(sai)) { @@ -1492,10 +1493,34 @@ static int stm32_sai_sub_probe(struct platform_device *pdev) return 0; } +#ifdef CONFIG_PM_SLEEP +static int stm32_sai_sub_suspend(struct device *dev) +{ + struct stm32_sai_sub_data *sai = dev_get_drvdata(dev); + + regcache_cache_only(sai->regmap, true); + regcache_mark_dirty(sai->regmap); + return 0; +} + +static int stm32_sai_sub_resume(struct device *dev) +{ + struct stm32_sai_sub_data *sai = dev_get_drvdata(dev); + + regcache_cache_only(sai->regmap, false); + return regcache_sync(sai->regmap); +} +#endif /* CONFIG_PM_SLEEP */ + +static const struct dev_pm_ops stm32_sai_sub_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(stm32_sai_sub_suspend, stm32_sai_sub_resume) +}; + static struct platform_driver stm32_sai_sub_driver = { .driver = { .name = "st,stm32-sai-sub", .of_match_table = stm32_sai_sub_ids, + .pm = &stm32_sai_sub_pm_ops, }, .probe = stm32_sai_sub_probe, }; -- cgit v1.2.3 From 8f8a54884dfd3d756693b7f174a06397bf19d8a5 Mon Sep 17 00:00:00 2001 From: Arnaud Pouliquen Date: Tue, 23 Apr 2019 17:58:08 +0200 Subject: ASoC: stm32: sai: simplify dai driver initialisation Suppress the useless dynamic allocation of the dai driver structure. Signed-off-by: Arnaud Pouliquen Signed-off-by: Mark Brown --- sound/soc/stm/stm32_sai_sub.c | 43 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) (limited to 'sound/soc/stm/stm32_sai_sub.c') diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c index 3dd54bc54fa1..e3b021c9e8d0 100644 --- a/sound/soc/stm/stm32_sai_sub.c +++ b/sound/soc/stm/stm32_sai_sub.c @@ -109,7 +109,7 @@ struct stm32_sai_sub_data { struct regmap *regmap; const struct regmap_config *regmap_config; struct snd_dmaengine_dai_dma_data dma_params; - struct snd_soc_dai_driver *cpu_dai_drv; + struct snd_soc_dai_driver cpu_dai_drv; struct snd_soc_dai *cpu_dai; struct snd_pcm_substream *substream; struct stm32_sai_data *pdata; @@ -1204,8 +1204,7 @@ static const struct snd_pcm_hardware stm32_sai_pcm_hw = { .periods_max = 8, }; -static struct snd_soc_dai_driver stm32_sai_playback_dai[] = { -{ +static struct snd_soc_dai_driver stm32_sai_playback_dai = { .probe = stm32_sai_dai_probe, .pcm_new = stm32_sai_pcm_new, .id = 1, /* avoid call to fmt_single_name() */ @@ -1222,11 +1221,9 @@ static struct snd_soc_dai_driver stm32_sai_playback_dai[] = { SNDRV_PCM_FMTBIT_S32_LE, }, .ops = &stm32_sai_pcm_dai_ops, - } }; -static struct snd_soc_dai_driver stm32_sai_capture_dai[] = { -{ +static struct snd_soc_dai_driver stm32_sai_capture_dai = { .probe = stm32_sai_dai_probe, .id = 1, /* avoid call to fmt_single_name() */ .capture = { @@ -1242,7 +1239,6 @@ static struct snd_soc_dai_driver stm32_sai_capture_dai[] = { SNDRV_PCM_FMTBIT_S32_LE, }, .ops = &stm32_sai_pcm_dai_ops, - } }; static const struct snd_dmaengine_pcm_config stm32_sai_pcm_config = { @@ -1411,29 +1407,6 @@ static int stm32_sai_sub_parse_of(struct platform_device *pdev, return 0; } -static int stm32_sai_sub_dais_init(struct platform_device *pdev, - struct stm32_sai_sub_data *sai) -{ - sai->cpu_dai_drv = devm_kzalloc(&pdev->dev, - sizeof(struct snd_soc_dai_driver), - GFP_KERNEL); - if (!sai->cpu_dai_drv) - return -ENOMEM; - - if (STM_SAI_IS_PLAYBACK(sai)) { - memcpy(sai->cpu_dai_drv, &stm32_sai_playback_dai, - sizeof(stm32_sai_playback_dai)); - sai->cpu_dai_drv->playback.stream_name = sai->cpu_dai_drv->name; - } else { - memcpy(sai->cpu_dai_drv, &stm32_sai_capture_dai, - sizeof(stm32_sai_capture_dai)); - sai->cpu_dai_drv->capture.stream_name = sai->cpu_dai_drv->name; - } - sai->cpu_dai_drv->name = dev_name(&pdev->dev); - - return 0; -} - static int stm32_sai_sub_probe(struct platform_device *pdev) { struct stm32_sai_sub_data *sai; @@ -1465,9 +1438,11 @@ static int stm32_sai_sub_probe(struct platform_device *pdev) if (ret) return ret; - ret = stm32_sai_sub_dais_init(pdev, sai); - if (ret) - return ret; + if (STM_SAI_IS_PLAYBACK(sai)) + sai->cpu_dai_drv = stm32_sai_playback_dai; + else + sai->cpu_dai_drv = stm32_sai_capture_dai; + sai->cpu_dai_drv.name = dev_name(&pdev->dev); ret = devm_request_irq(&pdev->dev, sai->pdata->irq, stm32_sai_isr, IRQF_SHARED, dev_name(&pdev->dev), sai); @@ -1477,7 +1452,7 @@ static int stm32_sai_sub_probe(struct platform_device *pdev) } ret = devm_snd_soc_register_component(&pdev->dev, &stm32_component, - sai->cpu_dai_drv, 1); + &sai->cpu_dai_drv, 1); if (ret) return ret; -- cgit v1.2.3