From 230e822ef5530322f20f591c1933e7be0d2f9954 Mon Sep 17 00:00:00 2001 From: Shuai Li Date: Thu, 8 Aug 2019 16:17:32 +0800 Subject: [PATCH] audio: add enable count for PDM module [1/1] PD#IPTV-3723 Problem: One use case is PDM module is sendig data to both PDM device and LOOPBACK device. Close one will make another useless. Solution: Add management of the PDM module by a enable count. Verify: SM1. Change-Id: Iceeb756c02671b16dbc3c49a9b793a50e6e559b5 Signed-off-by: Shuai Li --- sound/soc/amlogic/auge/pdm_hw.c | 35 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/sound/soc/amlogic/auge/pdm_hw.c b/sound/soc/amlogic/auge/pdm_hw.c index 4a861ac107fb..fd5116b9c194 100644 --- a/sound/soc/amlogic/auge/pdm_hw.c +++ b/sound/soc/amlogic/auge/pdm_hw.c @@ -19,28 +19,39 @@ #include #include #include -/*#include */ +#include #include "pdm_hw.h" #include "regs.h" #include "iomap.h" #include "pdm_hw_coeff.c" +static DEFINE_SPINLOCK(pdm_lock); +static unsigned long pdm_enable_cnt; void pdm_enable(int is_enable) { - if (is_enable) { - aml_pdm_update_bits( - PDM_CTRL, - 0x1 << 31, - is_enable << 31); - } else { - aml_pdm_update_bits( - PDM_CTRL, - 0x1 << 31 | 0x1 << 16, - 0 << 31 | 0 << 16); + unsigned long flags; - /*udelay(1000);*/ + spin_lock_irqsave(&pdm_lock, flags); + if (is_enable) { + if (pdm_enable_cnt == 0) + aml_pdm_update_bits( + PDM_CTRL, + 0x1 << 31, + is_enable << 31); + pdm_enable_cnt++; + } else { + if (WARN_ON(pdm_enable_cnt == 0)) + goto exit; + if (--pdm_enable_cnt == 0) + aml_pdm_update_bits( + PDM_CTRL, + 0x1 << 31 | 0x1 << 16, + 0 << 31 | 0 << 16); } + +exit: + spin_unlock_irqrestore(&pdm_lock, flags); } void pdm_fifo_reset(void)