[alsa-devel] [PATCH v5 3/9] ASoC: mediatek: let mt8173 use mediatek common structure

2016-06-17 Thread Garlic Tseng
Modify mt8173 driver implementation to use common structure.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/Kconfig|   4 +
 sound/soc/mediatek/Makefile   |   2 +-
 sound/soc/mediatek/common/Makefile|  16 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h |  42 +-
 sound/soc/mediatek/mt8173/mt8173-afe-pcm.c| 679 +++---
 5 files changed, 318 insertions(+), 425 deletions(-)
 create mode 100644 sound/soc/mediatek/common/Makefile

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index ae9f664..705904b 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,6 +1,10 @@
+config SND_SOC_MEDIATEK
+   tristate
+
 config SND_SOC_MT8173
tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
+   select SND_SOC_MEDIATEK
help
  This adds ASoC platform driver support for Mediatek MT8173 chip
  that can be used with other codecs.
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index 240dfc70..4fe8068 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,2 +1,2 @@
-# 8173 Machine support
+obj-$(CONFIG_SND_SOC_MEDIATEK) += common/
 obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
diff --git a/sound/soc/mediatek/common/Makefile 
b/sound/soc/mediatek/common/Makefile
new file mode 100644
index 000..a55d33b
--- /dev/null
+++ b/sound/soc/mediatek/common/Makefile
@@ -0,0 +1,16 @@
+#
+# Copyright (C) 2015 MediaTek Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+# platform driver
+snd-soc-mtk-common-objs := mtk-afe-platform-driver.o mtk-afe-fe-dai.o
+obj-$(CONFIG_SND_SOC_MEDIATEK) += snd-soc-mtk-common.o
diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-common.h 
b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
index 8f2936d..9a4837c 100644
--- a/sound/soc/mediatek/mt8173/mt8173-afe-common.h
+++ b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
@@ -46,14 +46,13 @@ enum {
 };
 
 enum {
-   MT8173_AFE_IRQ_1,
-   MT8173_AFE_IRQ_2,
-   MT8173_AFE_IRQ_3,
-   MT8173_AFE_IRQ_4,
-   MT8173_AFE_IRQ_5,
-   MT8173_AFE_IRQ_6,
-   MT8173_AFE_IRQ_7,
-   MT8173_AFE_IRQ_8,
+   MT8173_AFE_IRQ_DL1,
+   MT8173_AFE_IRQ_DL2,
+   MT8173_AFE_IRQ_VUL,
+   MT8173_AFE_IRQ_DAI,
+   MT8173_AFE_IRQ_AWB,
+   MT8173_AFE_IRQ_MOD_DAI,
+   MT8173_AFE_IRQ_HDMI,
MT8173_AFE_IRQ_NUM,
 };
 
@@ -71,31 +70,4 @@ enum {
MT8173_CLK_NUM
 };
 
-struct mt8173_afe;
-struct snd_pcm_substream;
-
-struct mt8173_afe_memif_data {
-   int id;
-   const char *name;
-   int reg_ofs_base;
-   int reg_ofs_cur;
-   int fs_shift;
-   int mono_shift;
-   int enable_shift;
-   int irq_reg_cnt;
-   int irq_cnt_shift;
-   int irq_en_shift;
-   int irq_fs_shift;
-   int irq_clr_shift;
-   int msb_shift;
-};
-
-struct mt8173_afe_memif {
-   unsigned int phys_buf_addr;
-   int buffer_size;
-   struct snd_pcm_substream *substream;
-   const struct mt8173_afe_memif_data *data;
-   const struct mt8173_afe_irq_data *irqdata;
-};
-
 #endif
diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c 
b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
index 4fc52bc..8a643a3 100644
--- a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
+++ b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
@@ -25,6 +25,9 @@
 #include 
 #include 
 #include "mt8173-afe-common.h"
+#include "../common/mtk-base-afe.h"
+#include "../common/mtk-afe-platform-driver.h"
+#include "../common/mtk-afe-fe-dai.h"
 
 /*
  *  R E G I S T E R   D E F I N I T I O N
@@ -81,7 +84,6 @@
 #define AFE_TDM_CON1   0x0548
 #define AFE_TDM_CON2   0x054c
 
-#define AFE_BASE_END_OFFSET8
 #define AFE_IRQ_STATUS_BITS0xff
 
 /* AUDIO_TOP_CON0 (0x) */
@@ -152,15 +154,8 @@ static const unsigned int mt8173_afe_backup_list[] = {
AFE_DAC_CON0,
 };
 
-struct mt8173_afe {
-   /* address for ioremap audio hardware register */
-   void __iomem *base_addr;
-   struct device *dev;
-   struct regmap *regmap;
-   struct mt8173_afe_memif memif[MT8173_AFE_MEMIF_NUM];
+struct mt8173_afe_private {
struct clk *clocks[MT8173_CLK_NUM];
-   unsigned int backup_regs[ARRAY_SIZE(mt8173_afe_backup_list)];
-   bool suspended;
 };
 
 static const struct snd_pcm_hardware mt8173_afe_hardware = {
@@ -174,53 +169,6 @@ static const struct snd_pcm_hardware 

[alsa-devel] [PATCH v5 3/9] ASoC: mediatek: let mt8173 use mediatek common structure

2016-06-17 Thread Garlic Tseng
Modify mt8173 driver implementation to use common structure.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/Kconfig|   4 +
 sound/soc/mediatek/Makefile   |   2 +-
 sound/soc/mediatek/common/Makefile|  16 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h |  42 +-
 sound/soc/mediatek/mt8173/mt8173-afe-pcm.c| 679 +++---
 5 files changed, 318 insertions(+), 425 deletions(-)
 create mode 100644 sound/soc/mediatek/common/Makefile

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index ae9f664..705904b 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,6 +1,10 @@
+config SND_SOC_MEDIATEK
+   tristate
+
 config SND_SOC_MT8173
tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
+   select SND_SOC_MEDIATEK
help
  This adds ASoC platform driver support for Mediatek MT8173 chip
  that can be used with other codecs.
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index 240dfc70..4fe8068 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,2 +1,2 @@
-# 8173 Machine support
+obj-$(CONFIG_SND_SOC_MEDIATEK) += common/
 obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
diff --git a/sound/soc/mediatek/common/Makefile 
b/sound/soc/mediatek/common/Makefile
new file mode 100644
index 000..a55d33b
--- /dev/null
+++ b/sound/soc/mediatek/common/Makefile
@@ -0,0 +1,16 @@
+#
+# Copyright (C) 2015 MediaTek Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+# platform driver
+snd-soc-mtk-common-objs := mtk-afe-platform-driver.o mtk-afe-fe-dai.o
+obj-$(CONFIG_SND_SOC_MEDIATEK) += snd-soc-mtk-common.o
diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-common.h 
b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
index 8f2936d..9a4837c 100644
--- a/sound/soc/mediatek/mt8173/mt8173-afe-common.h
+++ b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
@@ -46,14 +46,13 @@ enum {
 };
 
 enum {
-   MT8173_AFE_IRQ_1,
-   MT8173_AFE_IRQ_2,
-   MT8173_AFE_IRQ_3,
-   MT8173_AFE_IRQ_4,
-   MT8173_AFE_IRQ_5,
-   MT8173_AFE_IRQ_6,
-   MT8173_AFE_IRQ_7,
-   MT8173_AFE_IRQ_8,
+   MT8173_AFE_IRQ_DL1,
+   MT8173_AFE_IRQ_DL2,
+   MT8173_AFE_IRQ_VUL,
+   MT8173_AFE_IRQ_DAI,
+   MT8173_AFE_IRQ_AWB,
+   MT8173_AFE_IRQ_MOD_DAI,
+   MT8173_AFE_IRQ_HDMI,
MT8173_AFE_IRQ_NUM,
 };
 
@@ -71,31 +70,4 @@ enum {
MT8173_CLK_NUM
 };
 
-struct mt8173_afe;
-struct snd_pcm_substream;
-
-struct mt8173_afe_memif_data {
-   int id;
-   const char *name;
-   int reg_ofs_base;
-   int reg_ofs_cur;
-   int fs_shift;
-   int mono_shift;
-   int enable_shift;
-   int irq_reg_cnt;
-   int irq_cnt_shift;
-   int irq_en_shift;
-   int irq_fs_shift;
-   int irq_clr_shift;
-   int msb_shift;
-};
-
-struct mt8173_afe_memif {
-   unsigned int phys_buf_addr;
-   int buffer_size;
-   struct snd_pcm_substream *substream;
-   const struct mt8173_afe_memif_data *data;
-   const struct mt8173_afe_irq_data *irqdata;
-};
-
 #endif
diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c 
b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
index 4fc52bc..8a643a3 100644
--- a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
+++ b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
@@ -25,6 +25,9 @@
 #include 
 #include 
 #include "mt8173-afe-common.h"
+#include "../common/mtk-base-afe.h"
+#include "../common/mtk-afe-platform-driver.h"
+#include "../common/mtk-afe-fe-dai.h"
 
 /*
  *  R E G I S T E R   D E F I N I T I O N
@@ -81,7 +84,6 @@
 #define AFE_TDM_CON1   0x0548
 #define AFE_TDM_CON2   0x054c
 
-#define AFE_BASE_END_OFFSET8
 #define AFE_IRQ_STATUS_BITS0xff
 
 /* AUDIO_TOP_CON0 (0x) */
@@ -152,15 +154,8 @@ static const unsigned int mt8173_afe_backup_list[] = {
AFE_DAC_CON0,
 };
 
-struct mt8173_afe {
-   /* address for ioremap audio hardware register */
-   void __iomem *base_addr;
-   struct device *dev;
-   struct regmap *regmap;
-   struct mt8173_afe_memif memif[MT8173_AFE_MEMIF_NUM];
+struct mt8173_afe_private {
struct clk *clocks[MT8173_CLK_NUM];
-   unsigned int backup_regs[ARRAY_SIZE(mt8173_afe_backup_list)];
-   bool suspended;
 };
 
 static const struct snd_pcm_hardware mt8173_afe_hardware = {
@@ -174,53 +169,6 @@ static const struct snd_pcm_hardware mt8173_afe_hardware = 
{