audio: add enable count for PDM module [1/1]
authorShuai Li <shuai.li@amlogic.com>
Thu, 8 Aug 2019 08:17:32 +0000 (16:17 +0800)
committerTao Zeng <tao.zeng@amlogic.com>
Fri, 9 Aug 2019 08:48:25 +0000 (01:48 -0700)
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 <shuai.li@amlogic.com>
sound/soc/amlogic/auge/pdm_hw.c

index 4a861ac..fd5116b 100644 (file)
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/string.h>
-/*#include <linux/delay.h>*/
+#include <linux/spinlock.h>
 
 #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)
 {
+       unsigned long flags;
+
+       spin_lock_irqsave(&pdm_lock, flags);
        if (is_enable) {
-               aml_pdm_update_bits(
-                       PDM_CTRL,
-                       0x1 << 31,
-                       is_enable << 31);
+               if (pdm_enable_cnt == 0)
+                       aml_pdm_update_bits(
+                               PDM_CTRL,
+                               0x1 << 31,
+                               is_enable << 31);
+               pdm_enable_cnt++;
        } else {
-               aml_pdm_update_bits(
-                       PDM_CTRL,
-                       0x1 << 31 | 0x1 << 16,
-                       0 << 31 | 0 << 16);
-
-               /*udelay(1000);*/
+               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)