[alsa-devel] [PATCH 2/2] ASoC: mediatek: add power-domains for mt2701-afe-pcm.txt

2017-02-15 Thread Garlic Tseng
This add power-domains for mt2701-afe-pcm

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt 
b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
index 3e623a7..9800a56 100644
--- a/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
+++ b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
@@ -4,6 +4,7 @@ Required properties:
 - compatible = "mediatek,mt2701-audio";
 - reg: register location and size
 - interrupts: Should contain AFE interrupt
+- power-domains: should define the power domain
 - clock-names: should have these clock names:
"infra_sys_audio_clk",
"top_audio_mux1_sel",
@@ -58,6 +59,7 @@ Example:
  <0 0x112A 0 0x2>;
interrupts = ,
 ;
+   power-domains = < MT2701_POWER_DOMAIN_IFR_MSC>;
clocks = < CLK_INFRA_AUDIO>,
 < CLK_TOP_AUD_MUX1_SEL>,
 < CLK_TOP_AUD_MUX2_SEL>,
-- 
1.9.1



[alsa-devel] [PATCH 0/2] ASoC: mediatek: add power-domain ctrl for 2701

2017-02-15 Thread Garlic Tseng
add power-domain get/put ctrl for 2701 and add relative node description
in binding doc.

Garlic Tseng (2):
  ASoC: mediatek: add power-domain get/put ctrl for mt2701
  ASoC: mediatek: add power-domains for mt2701-afe-pcm.txt

 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt | 2 ++
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 2 ++
 2 files changed, 4 insertions(+)

-- 
1.9.1



[alsa-devel] [PATCH 2/2] ASoC: mediatek: add power-domains for mt2701-afe-pcm.txt

2017-02-15 Thread Garlic Tseng
This add power-domains for mt2701-afe-pcm

Signed-off-by: Garlic Tseng 
---
 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt 
b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
index 3e623a7..9800a56 100644
--- a/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
+++ b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
@@ -4,6 +4,7 @@ Required properties:
 - compatible = "mediatek,mt2701-audio";
 - reg: register location and size
 - interrupts: Should contain AFE interrupt
+- power-domains: should define the power domain
 - clock-names: should have these clock names:
"infra_sys_audio_clk",
"top_audio_mux1_sel",
@@ -58,6 +59,7 @@ Example:
  <0 0x112A 0 0x2>;
interrupts = ,
 ;
+   power-domains = < MT2701_POWER_DOMAIN_IFR_MSC>;
clocks = < CLK_INFRA_AUDIO>,
 < CLK_TOP_AUD_MUX1_SEL>,
 < CLK_TOP_AUD_MUX2_SEL>,
-- 
1.9.1



[alsa-devel] [PATCH 0/2] ASoC: mediatek: add power-domain ctrl for 2701

2017-02-15 Thread Garlic Tseng
add power-domain get/put ctrl for 2701 and add relative node description
in binding doc.

Garlic Tseng (2):
  ASoC: mediatek: add power-domain get/put ctrl for mt2701
  ASoC: mediatek: add power-domains for mt2701-afe-pcm.txt

 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt | 2 ++
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 2 ++
 2 files changed, 4 insertions(+)

-- 
1.9.1



[alsa-devel] [PATCH 1/2] ASoC: mediatek: add power-domain get/put ctrl for mt2701

2017-02-15 Thread Garlic Tseng
add power-domain ctrl for audio driver

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
index 34a6123..c7fa3e6 100644
--- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -1578,6 +1578,7 @@ static int mt2701_afe_pcm_dev_probe(struct 
platform_device *pdev)
pm_runtime_enable(>dev);
if (!pm_runtime_enabled(>dev))
goto err_pm_disable;
+   pm_runtime_get_sync(>dev);
 
ret = snd_soc_register_platform(>dev, _afe_pcm_platform);
if (ret) {
@@ -1617,6 +1618,7 @@ static int mt2701_afe_pcm_dev_remove(struct 
platform_device *pdev)
pm_runtime_disable(>dev);
if (!pm_runtime_status_suspended(>dev))
mt2701_afe_runtime_suspend(>dev);
+   pm_runtime_put_sync(>dev);
 
snd_soc_unregister_component(>dev);
snd_soc_unregister_platform(>dev);
-- 
1.9.1



[alsa-devel] [PATCH 1/2] ASoC: mediatek: add power-domain get/put ctrl for mt2701

2017-02-15 Thread Garlic Tseng
add power-domain ctrl for audio driver

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
index 34a6123..c7fa3e6 100644
--- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -1578,6 +1578,7 @@ static int mt2701_afe_pcm_dev_probe(struct 
platform_device *pdev)
pm_runtime_enable(>dev);
if (!pm_runtime_enabled(>dev))
goto err_pm_disable;
+   pm_runtime_get_sync(>dev);
 
ret = snd_soc_register_platform(>dev, _afe_pcm_platform);
if (ret) {
@@ -1617,6 +1618,7 @@ static int mt2701_afe_pcm_dev_remove(struct 
platform_device *pdev)
pm_runtime_disable(>dev);
if (!pm_runtime_status_suspended(>dev))
mt2701_afe_runtime_suspend(>dev);
+   pm_runtime_put_sync(>dev);
 
snd_soc_unregister_component(>dev);
snd_soc_unregister_platform(>dev);
-- 
1.9.1



Re: [alsa-devel] [PATCH -next v2] ASoC: mediatek: mt2701: fix non static symbol warning

2016-07-10 Thread Garlic Tseng
On Fri, 2016-07-08 at 13:47 +, weiyj...@163.com wrote:
> From: Wei Yongjun <yongjun_...@trendmicro.com.cn>
> 
> Fixes the following sparse warning:
> 
> sound/soc/mediatek/mt2701/mt2701-afe-pcm.c:72:5: warning:
>  symbol 'mt2701_dai_num_to_i2s' was not declared. Should it be static?
> 
> Signed-off-by: Wei Yongjun <yongjun_...@trendmicro.com.cn>

Acked-by: Garlic Tseng <garlic.ts...@mediatek.com>

> ---
>  sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
> b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
> index 15522c0..34a6123 100644
> --- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
> +++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
> @@ -69,7 +69,7 @@ static const struct mt2701_afe_rate mt2701_afe_i2s_rates[] 
> = {
>   { .rate = 352800, .regvalue = 24 },
>  };
>  
> -int mt2701_dai_num_to_i2s(struct mtk_base_afe *afe, int num)
> +static int mt2701_dai_num_to_i2s(struct mtk_base_afe *afe, int num)
>  {
>   int val = num - MT2701_IO_I2S;
> 
> 
> ___
> Alsa-devel mailing list
> alsa-de...@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel




Re: [alsa-devel] [PATCH -next v2] ASoC: mediatek: mt2701: fix non static symbol warning

2016-07-10 Thread Garlic Tseng
On Fri, 2016-07-08 at 13:47 +, weiyj...@163.com wrote:
> From: Wei Yongjun 
> 
> Fixes the following sparse warning:
> 
> sound/soc/mediatek/mt2701/mt2701-afe-pcm.c:72:5: warning:
>  symbol 'mt2701_dai_num_to_i2s' was not declared. Should it be static?
> 
> Signed-off-by: Wei Yongjun 

Acked-by: Garlic Tseng 

> ---
>  sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
> b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
> index 15522c0..34a6123 100644
> --- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
> +++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
> @@ -69,7 +69,7 @@ static const struct mt2701_afe_rate mt2701_afe_i2s_rates[] 
> = {
>   { .rate = 352800, .regvalue = 24 },
>  };
>  
> -int mt2701_dai_num_to_i2s(struct mtk_base_afe *afe, int num)
> +static int mt2701_dai_num_to_i2s(struct mtk_base_afe *afe, int num)
>  {
>   int val = num - MT2701_IO_I2S;
> 
> 
> ___
> Alsa-devel mailing list
> alsa-de...@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel




Re: [alsa-devel] [PATCH 3/4] ASoC: mediatek: add BT implementation

2016-07-05 Thread Garlic Tseng
On Tue, 2016-07-05 at 10:12 +0200, Mark Brown wrote:
> On Tue, Jul 05, 2016 at 09:52:13AM +0800, Garlic Tseng wrote:
> > On Mon, 2016-07-04 at 16:44 +0200, Mark Brown wrote:
> 
> > > We really shouldn't be writing the registers or other internal data of
> > > the device.  Instead we should be getting the driver for the relevant
> > > hardware component to do it.  If we just write to registers that makes
> > > the interoperation with the real driver for the device more fragile than
> > > it should be, people might update the main driver without noticing the
> > > external driver.
> 
> > The AUDIO_TOP_CON4 is a reg of the ASoC hw module. All the registers
> > which are set in the btmrg operator belong to ASoC hardware. The reg
> > writing you mention above is to power up the MRG interface in the ASoC
> > module.
> 
> The problem is that this is the machine driver, not a driver for the
> chip that's being controlled.

The patch is for platform driver "mt2701-afe-pcm.c", which contorls the
ASoC module, not for machine driver. Maybe the patch sequence is
confusing and I'm sorry about that. Or did I misunderstand your comment?





Re: [alsa-devel] [PATCH 3/4] ASoC: mediatek: add BT implementation

2016-07-05 Thread Garlic Tseng
On Tue, 2016-07-05 at 10:12 +0200, Mark Brown wrote:
> On Tue, Jul 05, 2016 at 09:52:13AM +0800, Garlic Tseng wrote:
> > On Mon, 2016-07-04 at 16:44 +0200, Mark Brown wrote:
> 
> > > We really shouldn't be writing the registers or other internal data of
> > > the device.  Instead we should be getting the driver for the relevant
> > > hardware component to do it.  If we just write to registers that makes
> > > the interoperation with the real driver for the device more fragile than
> > > it should be, people might update the main driver without noticing the
> > > external driver.
> 
> > The AUDIO_TOP_CON4 is a reg of the ASoC hw module. All the registers
> > which are set in the btmrg operator belong to ASoC hardware. The reg
> > writing you mention above is to power up the MRG interface in the ASoC
> > module.
> 
> The problem is that this is the machine driver, not a driver for the
> chip that's being controlled.

The patch is for platform driver "mt2701-afe-pcm.c", which contorls the
ASoC module, not for machine driver. Maybe the patch sequence is
confusing and I'm sorry about that. Or did I misunderstand your comment?





Re: [alsa-devel] [PATCH 3/4] ASoC: mediatek: add BT implementation

2016-07-04 Thread Garlic Tseng
On Mon, 2016-07-04 at 16:44 +0200, Mark Brown wrote:
> On Mon, Jul 04, 2016 at 06:56:27PM +0800, Garlic Tseng wrote:
> 
> > +static int mt2701_btmrg_startup(struct snd_pcm_substream *substream,
> > +   struct snd_soc_dai *dai)
> > +{
> > +   struct snd_soc_pcm_runtime *rtd = substream->private_data;
> > +   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
> > +   struct mt2701_afe_private *afe_priv = afe->platform_priv;
> > +
> > +   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
> > +  AUDIO_TOP_CON4_PDN_MRGIF, 0);
> 
> We really shouldn't be writing the registers or other internal data of
> the device.  Instead we should be getting the driver for the relevant
> hardware component to do it.  If we just write to registers that makes
> the interoperation with the real driver for the device more fragile than
> it should be, people might update the main driver without noticing the
> external driver.

The AUDIO_TOP_CON4 is a reg of the ASoC hw module. All the registers
which are set in the btmrg operator belong to ASoC hardware. The reg
writing you mention above is to power up the MRG interface in the ASoC
module.

When we start BT link, we need to start some hardware component belongs
to ASoC module. Of course we also need to start up the BT module
(including start up the MRG interface hw in BT chip), but it is not in
the ASoC driver.



Re: [alsa-devel] [PATCH 3/4] ASoC: mediatek: add BT implementation

2016-07-04 Thread Garlic Tseng
On Mon, 2016-07-04 at 16:44 +0200, Mark Brown wrote:
> On Mon, Jul 04, 2016 at 06:56:27PM +0800, Garlic Tseng wrote:
> 
> > +static int mt2701_btmrg_startup(struct snd_pcm_substream *substream,
> > +   struct snd_soc_dai *dai)
> > +{
> > +   struct snd_soc_pcm_runtime *rtd = substream->private_data;
> > +   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
> > +   struct mt2701_afe_private *afe_priv = afe->platform_priv;
> > +
> > +   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
> > +  AUDIO_TOP_CON4_PDN_MRGIF, 0);
> 
> We really shouldn't be writing the registers or other internal data of
> the device.  Instead we should be getting the driver for the relevant
> hardware component to do it.  If we just write to registers that makes
> the interoperation with the real driver for the device more fragile than
> it should be, people might update the main driver without noticing the
> external driver.

The AUDIO_TOP_CON4 is a reg of the ASoC hw module. All the registers
which are set in the btmrg operator belong to ASoC hardware. The reg
writing you mention above is to power up the MRG interface in the ASoC
module.

When we start BT link, we need to start some hardware component belongs
to ASoC module. Of course we also need to start up the BT module
(including start up the MRG interface hw in BT chip), but it is not in
the ASoC driver.



[alsa-devel] [PATCH 3/4] ASoC: mediatek: add BT implementation

2016-07-04 Thread Garlic Tseng
Add BT implementation for mt2701 platform driver.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 139 +
 1 file changed, 139 insertions(+)

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
index c865ba1..6c14d68 100644
--- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -333,6 +333,86 @@ static int mt2701_afe_i2s_set_sysclk(struct snd_soc_dai 
*dai, int clk_id,
return 0;
 }
 
+static int mt2701_btmrg_startup(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF, 0);
+
+   afe_priv->mrg_enable[substream->stream] = 1;
+   return 0;
+}
+
+static int mt2701_btmrg_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   int stream_fs;
+   u32 val, msk;
+
+   stream_fs = params_rate(params);
+
+   if ((stream_fs != 8000) && (stream_fs != 16000)) {
+   dev_err(afe->dev, "%s() btmgr not supprt this stream_fs %d\n",
+   __func__, stream_fs);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_I2S_MODE_MASK,
+  AFE_MRGIF_CON_I2S_MODE_32K);
+
+   val = AFE_DAIBT_CON0_BT_FUNC_EN | AFE_DAIBT_CON0_BT_FUNC_RDY
+ | AFE_DAIBT_CON0_MRG_USE;
+   msk = val;
+
+   if (stream_fs == 16000)
+   val |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   msk |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0, msk, val);
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN,
+  AFE_DAIBT_CON0_DAIBT_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN,
+  AFE_MRGIF_CON_MRG_I2S_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN,
+  AFE_MRGIF_CON_MRG_EN);
+   return 0;
+}
+
+static void mt2701_btmrg_shutdown(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   /* if the other direction stream is not occupied */
+   if (!afe_priv->mrg_enable[!substream->stream]) {
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN, 0);
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF,
+  AUDIO_TOP_CON4_PDN_MRGIF);
+   }
+   afe_priv->mrg_enable[substream->stream] = 0;
+}
+
 static int mt2701_simple_fe_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
 {
@@ -514,6 +594,13 @@ static const struct snd_soc_dai_ops mt2701_afe_i2s_ops = {
.set_sysclk = mt2701_afe_i2s_set_sysclk,
 };
 
+/* MRG BE DAIs */
+static struct snd_soc_dai_ops mt2701_btmrg_ops = {
+   .startup = mt2701_btmrg_startup,
+   .shutdown = mt2701_btmrg_shutdown,
+   .hw_params = mt2701_btmrg_hw_params,
+};
+
 static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
/* FE DAIs: memory intefaces to CPU */
{
@@ -566,6 +653,36 @@ static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
},
.ops = _single_memif_dai_ops,
},
+   {
+   .name = "PCM_BT_DL",
+   .id = MT2701_MEMIF_DLBT,
+   .suspend = mtk_afe_dai_suspend,
+   .resume = mtk_afe_dai_resume,
+   .playback = {
+ 

[alsa-devel] [PATCH 2/4] ASoC: bt-sco: extend rate and add a general compatible string

2016-07-04 Thread Garlic Tseng
Add supports for 16k (wideband BT) and add a general compatible
string "linux,bt-sco"

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 Documentation/devicetree/bindings/sound/bt-sco.txt |  2 +-
 sound/soc/codecs/bt-sco.c  | 52 +++---
 2 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/Documentation/devicetree/bindings/sound/bt-sco.txt 
b/Documentation/devicetree/bindings/sound/bt-sco.txt
index 29b8e5d..641edf7 100644
--- a/Documentation/devicetree/bindings/sound/bt-sco.txt
+++ b/Documentation/devicetree/bindings/sound/bt-sco.txt
@@ -4,7 +4,7 @@ This device support generic Bluetooth SCO link.
 
 Required properties:
 
-  - compatible : "delta,dfbmcs320"
+  - compatible : "delta,dfbmcs320" or "linux,bt-sco"
 
 Example:
 
diff --git a/sound/soc/codecs/bt-sco.c b/sound/soc/codecs/bt-sco.c
index b084ad1..2a8d0ee 100644
--- a/sound/soc/codecs/bt-sco.c
+++ b/sound/soc/codecs/bt-sco.c
@@ -25,22 +25,41 @@ static const struct snd_soc_dapm_route bt_sco_routes[] = {
{ "TX", NULL, "Playback" },
 };
 
-static struct snd_soc_dai_driver bt_sco_dai = {
-   .name = "bt-sco-pcm",
-   .playback = {
-   .stream_name = "Playback",
-   .channels_min = 1,
-   .channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
-   .formats = SNDRV_PCM_FMTBIT_S16_LE,
-   },
-   .capture = {
-.stream_name = "Capture",
-   .channels_min = 1,
-   .channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
-   .formats = SNDRV_PCM_FMTBIT_S16_LE,
+static struct snd_soc_dai_driver bt_sco_dai[] = {
+   {
+   .name = "bt-sco-pcm",
+   .playback = {
+   .stream_name = "Playback",
+   .channels_min = 1,
+   .channels_max = 1,
+   .rates = SNDRV_PCM_RATE_8000,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE,
+   },
+   .capture = {
+.stream_name = "Capture",
+   .channels_min = 1,
+   .channels_max = 1,
+   .rates = SNDRV_PCM_RATE_8000,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE,
+   },
},
+   {
+   .name = "bt-sco-pcm-wb",
+   .playback = {
+   .stream_name = "Playback",
+   .channels_min = 1,
+   .channels_max = 1,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE,
+   },
+   .capture = {
+.stream_name = "Capture",
+   .channels_min = 1,
+   .channels_max = 1,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE,
+   },
+   }
 };
 
 static struct snd_soc_codec_driver soc_codec_dev_bt_sco = {
@@ -53,7 +72,7 @@ static struct snd_soc_codec_driver soc_codec_dev_bt_sco = {
 static int bt_sco_probe(struct platform_device *pdev)
 {
return snd_soc_register_codec(>dev, _codec_dev_bt_sco,
-   _sco_dai, 1);
+ bt_sco_dai, ARRAY_SIZE(bt_sco_dai));
 }
 
 static int bt_sco_remove(struct platform_device *pdev)
@@ -77,6 +96,7 @@ MODULE_DEVICE_TABLE(platform, bt_sco_driver_ids);
 #if defined(CONFIG_OF)
 static const struct of_device_id bt_sco_codec_of_match[] = {
{ .compatible = "delta,dfbmcs320", },
+   { .compatible = "linux,bt-sco", },
{},
 };
 MODULE_DEVICE_TABLE(of, bt_sco_codec_of_match);
-- 
1.9.1



[alsa-devel] [PATCH 3/4] ASoC: mediatek: add BT implementation

2016-07-04 Thread Garlic Tseng
Add BT implementation for mt2701 platform driver.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 139 +
 1 file changed, 139 insertions(+)

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
index c865ba1..6c14d68 100644
--- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -333,6 +333,86 @@ static int mt2701_afe_i2s_set_sysclk(struct snd_soc_dai 
*dai, int clk_id,
return 0;
 }
 
+static int mt2701_btmrg_startup(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF, 0);
+
+   afe_priv->mrg_enable[substream->stream] = 1;
+   return 0;
+}
+
+static int mt2701_btmrg_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   int stream_fs;
+   u32 val, msk;
+
+   stream_fs = params_rate(params);
+
+   if ((stream_fs != 8000) && (stream_fs != 16000)) {
+   dev_err(afe->dev, "%s() btmgr not supprt this stream_fs %d\n",
+   __func__, stream_fs);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_I2S_MODE_MASK,
+  AFE_MRGIF_CON_I2S_MODE_32K);
+
+   val = AFE_DAIBT_CON0_BT_FUNC_EN | AFE_DAIBT_CON0_BT_FUNC_RDY
+ | AFE_DAIBT_CON0_MRG_USE;
+   msk = val;
+
+   if (stream_fs == 16000)
+   val |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   msk |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0, msk, val);
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN,
+  AFE_DAIBT_CON0_DAIBT_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN,
+  AFE_MRGIF_CON_MRG_I2S_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN,
+  AFE_MRGIF_CON_MRG_EN);
+   return 0;
+}
+
+static void mt2701_btmrg_shutdown(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   /* if the other direction stream is not occupied */
+   if (!afe_priv->mrg_enable[!substream->stream]) {
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN, 0);
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF,
+  AUDIO_TOP_CON4_PDN_MRGIF);
+   }
+   afe_priv->mrg_enable[substream->stream] = 0;
+}
+
 static int mt2701_simple_fe_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
 {
@@ -514,6 +594,13 @@ static const struct snd_soc_dai_ops mt2701_afe_i2s_ops = {
.set_sysclk = mt2701_afe_i2s_set_sysclk,
 };
 
+/* MRG BE DAIs */
+static struct snd_soc_dai_ops mt2701_btmrg_ops = {
+   .startup = mt2701_btmrg_startup,
+   .shutdown = mt2701_btmrg_shutdown,
+   .hw_params = mt2701_btmrg_hw_params,
+};
+
 static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
/* FE DAIs: memory intefaces to CPU */
{
@@ -566,6 +653,36 @@ static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
},
.ops = _single_memif_dai_ops,
},
+   {
+   .name = "PCM_BT_DL",
+   .id = MT2701_MEMIF_DLBT,
+   .suspend = mtk_afe_dai_suspend,
+   .resume = mtk_afe_dai_resume,
+   .playback = {
+   .stream_name = "DLBT",
+  

[alsa-devel] [PATCH 2/4] ASoC: bt-sco: extend rate and add a general compatible string

2016-07-04 Thread Garlic Tseng
Add supports for 16k (wideband BT) and add a general compatible
string "linux,bt-sco"

Signed-off-by: Garlic Tseng 
---
 Documentation/devicetree/bindings/sound/bt-sco.txt |  2 +-
 sound/soc/codecs/bt-sco.c  | 52 +++---
 2 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/Documentation/devicetree/bindings/sound/bt-sco.txt 
b/Documentation/devicetree/bindings/sound/bt-sco.txt
index 29b8e5d..641edf7 100644
--- a/Documentation/devicetree/bindings/sound/bt-sco.txt
+++ b/Documentation/devicetree/bindings/sound/bt-sco.txt
@@ -4,7 +4,7 @@ This device support generic Bluetooth SCO link.
 
 Required properties:
 
-  - compatible : "delta,dfbmcs320"
+  - compatible : "delta,dfbmcs320" or "linux,bt-sco"
 
 Example:
 
diff --git a/sound/soc/codecs/bt-sco.c b/sound/soc/codecs/bt-sco.c
index b084ad1..2a8d0ee 100644
--- a/sound/soc/codecs/bt-sco.c
+++ b/sound/soc/codecs/bt-sco.c
@@ -25,22 +25,41 @@ static const struct snd_soc_dapm_route bt_sco_routes[] = {
{ "TX", NULL, "Playback" },
 };
 
-static struct snd_soc_dai_driver bt_sco_dai = {
-   .name = "bt-sco-pcm",
-   .playback = {
-   .stream_name = "Playback",
-   .channels_min = 1,
-   .channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
-   .formats = SNDRV_PCM_FMTBIT_S16_LE,
-   },
-   .capture = {
-.stream_name = "Capture",
-   .channels_min = 1,
-   .channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
-   .formats = SNDRV_PCM_FMTBIT_S16_LE,
+static struct snd_soc_dai_driver bt_sco_dai[] = {
+   {
+   .name = "bt-sco-pcm",
+   .playback = {
+   .stream_name = "Playback",
+   .channels_min = 1,
+   .channels_max = 1,
+   .rates = SNDRV_PCM_RATE_8000,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE,
+   },
+   .capture = {
+.stream_name = "Capture",
+   .channels_min = 1,
+   .channels_max = 1,
+   .rates = SNDRV_PCM_RATE_8000,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE,
+   },
},
+   {
+   .name = "bt-sco-pcm-wb",
+   .playback = {
+   .stream_name = "Playback",
+   .channels_min = 1,
+   .channels_max = 1,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE,
+   },
+   .capture = {
+.stream_name = "Capture",
+   .channels_min = 1,
+   .channels_max = 1,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE,
+   },
+   }
 };
 
 static struct snd_soc_codec_driver soc_codec_dev_bt_sco = {
@@ -53,7 +72,7 @@ static struct snd_soc_codec_driver soc_codec_dev_bt_sco = {
 static int bt_sco_probe(struct platform_device *pdev)
 {
return snd_soc_register_codec(>dev, _codec_dev_bt_sco,
-   _sco_dai, 1);
+ bt_sco_dai, ARRAY_SIZE(bt_sco_dai));
 }
 
 static int bt_sco_remove(struct platform_device *pdev)
@@ -77,6 +96,7 @@ MODULE_DEVICE_TABLE(platform, bt_sco_driver_ids);
 #if defined(CONFIG_OF)
 static const struct of_device_id bt_sco_codec_of_match[] = {
{ .compatible = "delta,dfbmcs320", },
+   { .compatible = "linux,bt-sco", },
{},
 };
 MODULE_DEVICE_TABLE(of, bt_sco_codec_of_match);
-- 
1.9.1



[alsa-devel] [PATCH 4/4] ASoC: mediatek: Add mt2701-cs42448 driver and config option.

2016-07-04 Thread Garlic Tseng
Add machine driver and config option for MT2701.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/Kconfig |  21 ++
 sound/soc/mediatek/Makefile|   1 +
 sound/soc/mediatek/mt2701/Makefile |  19 ++
 sound/soc/mediatek/mt2701/mt2701-cs42448.c | 412 +
 4 files changed, 453 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index 705904b..2fbe543 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,6 +1,27 @@
 config SND_SOC_MEDIATEK
tristate
 
+config SND_SOC_MT2701
+   tristate "ASoC support for Mediatek MT2701 chip"
+   depends on ARCH_MEDIATEK
+   select SND_SOC_MEDIATEK
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ that can be used with other codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
+config SND_SOC_MT2701_CS42448
+   tristate "ASoc Audio driver for MT2701 with CS42448 codec"
+   depends on SND_SOC_MT2701
+   select SND_SOC_CS42XX8_I2C
+   select SND_SOC_BT_SCO
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ with the CS42448 codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
 config SND_SOC_MT8173
tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index 4fe8068..6bcab35 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,2 +1,3 @@
 obj-$(CONFIG_SND_SOC_MEDIATEK) += common/
+obj-$(CONFIG_SND_SOC_MT2701) += mt2701/
 obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
diff --git a/sound/soc/mediatek/mt2701/Makefile 
b/sound/soc/mediatek/mt2701/Makefile
new file mode 100644
index 000..31c3d04
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/Makefile
@@ -0,0 +1,19 @@
+#
+# 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-mt2701-afe-objs := mt2701-afe-pcm.o mt2701-afe-clock-ctrl.o
+obj-$(CONFIG_SND_SOC_MT2701) += snd-soc-mt2701-afe.o
+
+# machine driver
+obj-$(CONFIG_SND_SOC_MT2701_CS42448) += mt2701-cs42448.o
diff --git a/sound/soc/mediatek/mt2701/mt2701-cs42448.c 
b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
new file mode 100644
index 000..1e7e8d4
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
@@ -0,0 +1,412 @@
+/*
+ * mt2701-cs42448.c  --  MT2701 CS42448 ALSA SoC machine driver
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Ir Lian <ir.l...@mediatek.com>
+ *  Garlic Tseng <garlic.ts...@mediatek.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+struct mt2701_cs42448_private {
+   int i2s1_in_mux;
+   int i2s1_in_mux_gpio_sel_1;
+   int i2s1_in_mux_gpio_sel_2;
+};
+
+static const char * const i2sin_mux_switch_text[] = {
+   "ADC_SDOUT2",
+   "ADC_SDOUT3",
+   "I2S_IN_1",
+   "I2S_IN_2",
+};
+
+static const struct soc_enum i2sin_mux_enum =
+   SOC_ENUM_SINGLE_EXT(4, i2sin_mux_switch_text);
+
+static int mt2701_cs42448_i2sin1_mux_get(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card);
+
+   ucontrol->value.integer.value[0] = priv->i2s1_in_mux;
+   return 0;
+}
+
+static int mt2701_cs42448_i2sin1_mux_set(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card

[alsa-devel] [PATCH 4/4] ASoC: mediatek: Add mt2701-cs42448 driver and config option.

2016-07-04 Thread Garlic Tseng
Add machine driver and config option for MT2701.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/Kconfig |  21 ++
 sound/soc/mediatek/Makefile|   1 +
 sound/soc/mediatek/mt2701/Makefile |  19 ++
 sound/soc/mediatek/mt2701/mt2701-cs42448.c | 412 +
 4 files changed, 453 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index 705904b..2fbe543 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,6 +1,27 @@
 config SND_SOC_MEDIATEK
tristate
 
+config SND_SOC_MT2701
+   tristate "ASoC support for Mediatek MT2701 chip"
+   depends on ARCH_MEDIATEK
+   select SND_SOC_MEDIATEK
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ that can be used with other codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
+config SND_SOC_MT2701_CS42448
+   tristate "ASoc Audio driver for MT2701 with CS42448 codec"
+   depends on SND_SOC_MT2701
+   select SND_SOC_CS42XX8_I2C
+   select SND_SOC_BT_SCO
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ with the CS42448 codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
 config SND_SOC_MT8173
tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index 4fe8068..6bcab35 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,2 +1,3 @@
 obj-$(CONFIG_SND_SOC_MEDIATEK) += common/
+obj-$(CONFIG_SND_SOC_MT2701) += mt2701/
 obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
diff --git a/sound/soc/mediatek/mt2701/Makefile 
b/sound/soc/mediatek/mt2701/Makefile
new file mode 100644
index 000..31c3d04
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/Makefile
@@ -0,0 +1,19 @@
+#
+# 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-mt2701-afe-objs := mt2701-afe-pcm.o mt2701-afe-clock-ctrl.o
+obj-$(CONFIG_SND_SOC_MT2701) += snd-soc-mt2701-afe.o
+
+# machine driver
+obj-$(CONFIG_SND_SOC_MT2701_CS42448) += mt2701-cs42448.o
diff --git a/sound/soc/mediatek/mt2701/mt2701-cs42448.c 
b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
new file mode 100644
index 000..1e7e8d4
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
@@ -0,0 +1,412 @@
+/*
+ * mt2701-cs42448.c  --  MT2701 CS42448 ALSA SoC machine driver
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Ir Lian 
+ *  Garlic Tseng 
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+struct mt2701_cs42448_private {
+   int i2s1_in_mux;
+   int i2s1_in_mux_gpio_sel_1;
+   int i2s1_in_mux_gpio_sel_2;
+};
+
+static const char * const i2sin_mux_switch_text[] = {
+   "ADC_SDOUT2",
+   "ADC_SDOUT3",
+   "I2S_IN_1",
+   "I2S_IN_2",
+};
+
+static const struct soc_enum i2sin_mux_enum =
+   SOC_ENUM_SINGLE_EXT(4, i2sin_mux_switch_text);
+
+static int mt2701_cs42448_i2sin1_mux_get(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card);
+
+   ucontrol->value.integer.value[0] = priv->i2s1_in_mux;
+   return 0;
+}
+
+static int mt2701_cs42448_i2sin1_mux_set(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card);
+
+   if (ucontrol->value.integer.value[0] == priv->i2s1_in_mux)
+   ret

[alsa-devel] [PATCH 0/4] ASoC: Mediatek: add MT2701 platform and machine driver

2016-07-04 Thread Garlic Tseng
Some patches of the patchset "ASoC: Mediatek: Add support for MT2701 SOC"
have been applied to the broonie tree, so I send a new patchset for the 
remaining patches.

The patchset adds mt2701 support based on Mediatek AFE common structure.

Change since the previous patchset:
* remove unnecessary set_clkdiv and set_fmt ops in mt2701 platform driver
* add another snd_soc_dai_driver for bt-sco codec to support 8k and 16k



Garlic Tseng (4):
  ASoC: mediatek: add mt2701 platform driver implementation.
  ASoC: bt-sco: extend rate and add a general compatible string
  ASoC: mediatek: add BT implementation
  ASoC: mediatek: Add mt2701-cs42448 driver and config option.

 Documentation/devicetree/bindings/sound/bt-sco.txt |2 +-
 sound/soc/codecs/bt-sco.c  |   52 +-
 sound/soc/mediatek/Kconfig |   21 +
 sound/soc/mediatek/Makefile|1 +
 sound/soc/mediatek/mt2701/Makefile |   19 +
 sound/soc/mediatek/mt2701/mt2701-afe-common.h  |9 -
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 1654 
 sound/soc/mediatek/mt2701/mt2701-cs42448.c |  412 +
 8 files changed, 2144 insertions(+), 26 deletions(-)
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c

-- 
1.9.1



[alsa-devel] [PATCH 1/4] ASoC: mediatek: add mt2701 platform driver implementation.

2016-07-04 Thread Garlic Tseng
Add mt2701 platform driver implementation for playback and capture.
The implement follow DAPM structure (memory interface as FE and I2S
as BE).
Because of the hardware design, i2s out required to be enabled when
we need to enable i2s in. This patch includes the implementation.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/mt2701/mt2701-afe-common.h |9 -
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c| 1515 +
 2 files changed, 1515 insertions(+), 9 deletions(-)
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-common.h 
b/sound/soc/mediatek/mt2701/mt2701-afe-common.h
index c77166e..c19430e 100644
--- a/sound/soc/mediatek/mt2701/mt2701-afe-common.h
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-common.h
@@ -69,11 +69,6 @@ enum {
MT2701_IRQ_ASYS_END,
 };
 
-enum {
-   DIV_ID_MCLK_TO_BCK,
-   DIV_ID_BCK_TO_LRCK,
-};
-
 /* 2701 clock def */
 enum audio_system_clock_type {
MT2701_AUD_INFRA_SYS_AUDIO,
@@ -163,10 +158,6 @@ enum mt2701_i2s_dir {
 struct mt2701_i2s_path {
int dai_id;
int mclk_rate;
-   int div_mclk_to_bck;
-   int div_bck_to_lrck;
-   int format;
-   snd_pcm_format_t stream_fmt;
int on[I2S_DIR_NUM];
int occupied[I2S_DIR_NUM];
const struct mt2701_i2s_data *i2s_data[2];
diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
new file mode 100644
index 000..c865ba1
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -0,0 +1,1515 @@
+/*
+ * Mediatek ALSA SoC AFE platform driver for 2701
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng <garlic.ts...@mediatek.com>
+ * Ir Lian <ir.l...@mediatek.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+#include "mt2701-afe-clock-ctrl.h"
+#include "../common/mtk-afe-platform-driver.h"
+#include "../common/mtk-afe-fe-dai.h"
+
+#define AFE_IRQ_STATUS_BITS0xff
+
+static const struct snd_pcm_hardware mt2701_afe_hardware = {
+   .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED
+   | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE
+  | SNDRV_PCM_FMTBIT_S32_LE,
+   .period_bytes_min = 1024,
+   .period_bytes_max = 1024 * 256,
+   .periods_min = 4,
+   .periods_max = 1024,
+   .buffer_bytes_max = 1024 * 1024 * 16,
+   .fifo_size = 0,
+};
+
+struct mt2701_afe_rate {
+   unsigned int rate;
+   unsigned int regvalue;
+};
+
+static const struct mt2701_afe_rate mt2701_afe_i2s_rates[] = {
+   { .rate = 8000, .regvalue = 0 },
+   { .rate = 12000, .regvalue = 1 },
+   { .rate = 16000, .regvalue = 2 },
+   { .rate = 24000, .regvalue = 3 },
+   { .rate = 32000, .regvalue = 4 },
+   { .rate = 48000, .regvalue = 5 },
+   { .rate = 96000, .regvalue = 6 },
+   { .rate = 192000, .regvalue = 7 },
+   { .rate = 384000, .regvalue = 8 },
+   { .rate = 7350, .regvalue = 16 },
+   { .rate = 11025, .regvalue = 17 },
+   { .rate = 14700, .regvalue = 18 },
+   { .rate = 22050, .regvalue = 19 },
+   { .rate = 29400, .regvalue = 20 },
+   { .rate = 44100, .regvalue = 21 },
+   { .rate = 88200, .regvalue = 22 },
+   { .rate = 176400, .regvalue = 23 },
+   { .rate = 352800, .regvalue = 24 },
+};
+
+int mt2701_dai_num_to_i2s(struct mtk_base_afe *afe, int num)
+{
+   int val = num - MT2701_IO_I2S;
+
+   if (val < 0 || val >= MT2701_I2S_NUM) {
+   dev_err(afe->dev, "%s, num not available, num %d, val %d\n",
+   __func__, num, val);
+   return -EINVAL;
+   }
+   return val;
+}
+
+static int mt2701_afe_i2s_fs(unsigned int sample_rate)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(mt2701_afe_i2s_rates); i++)
+   if (mt2701_afe_i2s_rates[i].rate == sample_rate)
+   return mt2701_afe_i2s_rates[i].regvalue;
+
+   return -EINVAL;
+}
+
+static int mt2701_afe_i2s_startup(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvda

[alsa-devel] [PATCH 0/4] ASoC: Mediatek: add MT2701 platform and machine driver

2016-07-04 Thread Garlic Tseng
Some patches of the patchset "ASoC: Mediatek: Add support for MT2701 SOC"
have been applied to the broonie tree, so I send a new patchset for the 
remaining patches.

The patchset adds mt2701 support based on Mediatek AFE common structure.

Change since the previous patchset:
* remove unnecessary set_clkdiv and set_fmt ops in mt2701 platform driver
* add another snd_soc_dai_driver for bt-sco codec to support 8k and 16k



Garlic Tseng (4):
  ASoC: mediatek: add mt2701 platform driver implementation.
  ASoC: bt-sco: extend rate and add a general compatible string
  ASoC: mediatek: add BT implementation
  ASoC: mediatek: Add mt2701-cs42448 driver and config option.

 Documentation/devicetree/bindings/sound/bt-sco.txt |2 +-
 sound/soc/codecs/bt-sco.c  |   52 +-
 sound/soc/mediatek/Kconfig |   21 +
 sound/soc/mediatek/Makefile|1 +
 sound/soc/mediatek/mt2701/Makefile |   19 +
 sound/soc/mediatek/mt2701/mt2701-afe-common.h  |9 -
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 1654 
 sound/soc/mediatek/mt2701/mt2701-cs42448.c |  412 +
 8 files changed, 2144 insertions(+), 26 deletions(-)
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c

-- 
1.9.1



[alsa-devel] [PATCH 1/4] ASoC: mediatek: add mt2701 platform driver implementation.

2016-07-04 Thread Garlic Tseng
Add mt2701 platform driver implementation for playback and capture.
The implement follow DAPM structure (memory interface as FE and I2S
as BE).
Because of the hardware design, i2s out required to be enabled when
we need to enable i2s in. This patch includes the implementation.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/mt2701/mt2701-afe-common.h |9 -
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c| 1515 +
 2 files changed, 1515 insertions(+), 9 deletions(-)
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-common.h 
b/sound/soc/mediatek/mt2701/mt2701-afe-common.h
index c77166e..c19430e 100644
--- a/sound/soc/mediatek/mt2701/mt2701-afe-common.h
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-common.h
@@ -69,11 +69,6 @@ enum {
MT2701_IRQ_ASYS_END,
 };
 
-enum {
-   DIV_ID_MCLK_TO_BCK,
-   DIV_ID_BCK_TO_LRCK,
-};
-
 /* 2701 clock def */
 enum audio_system_clock_type {
MT2701_AUD_INFRA_SYS_AUDIO,
@@ -163,10 +158,6 @@ enum mt2701_i2s_dir {
 struct mt2701_i2s_path {
int dai_id;
int mclk_rate;
-   int div_mclk_to_bck;
-   int div_bck_to_lrck;
-   int format;
-   snd_pcm_format_t stream_fmt;
int on[I2S_DIR_NUM];
int occupied[I2S_DIR_NUM];
const struct mt2701_i2s_data *i2s_data[2];
diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
new file mode 100644
index 000..c865ba1
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -0,0 +1,1515 @@
+/*
+ * Mediatek ALSA SoC AFE platform driver for 2701
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng 
+ * Ir Lian 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+#include "mt2701-afe-clock-ctrl.h"
+#include "../common/mtk-afe-platform-driver.h"
+#include "../common/mtk-afe-fe-dai.h"
+
+#define AFE_IRQ_STATUS_BITS0xff
+
+static const struct snd_pcm_hardware mt2701_afe_hardware = {
+   .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED
+   | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE
+  | SNDRV_PCM_FMTBIT_S32_LE,
+   .period_bytes_min = 1024,
+   .period_bytes_max = 1024 * 256,
+   .periods_min = 4,
+   .periods_max = 1024,
+   .buffer_bytes_max = 1024 * 1024 * 16,
+   .fifo_size = 0,
+};
+
+struct mt2701_afe_rate {
+   unsigned int rate;
+   unsigned int regvalue;
+};
+
+static const struct mt2701_afe_rate mt2701_afe_i2s_rates[] = {
+   { .rate = 8000, .regvalue = 0 },
+   { .rate = 12000, .regvalue = 1 },
+   { .rate = 16000, .regvalue = 2 },
+   { .rate = 24000, .regvalue = 3 },
+   { .rate = 32000, .regvalue = 4 },
+   { .rate = 48000, .regvalue = 5 },
+   { .rate = 96000, .regvalue = 6 },
+   { .rate = 192000, .regvalue = 7 },
+   { .rate = 384000, .regvalue = 8 },
+   { .rate = 7350, .regvalue = 16 },
+   { .rate = 11025, .regvalue = 17 },
+   { .rate = 14700, .regvalue = 18 },
+   { .rate = 22050, .regvalue = 19 },
+   { .rate = 29400, .regvalue = 20 },
+   { .rate = 44100, .regvalue = 21 },
+   { .rate = 88200, .regvalue = 22 },
+   { .rate = 176400, .regvalue = 23 },
+   { .rate = 352800, .regvalue = 24 },
+};
+
+int mt2701_dai_num_to_i2s(struct mtk_base_afe *afe, int num)
+{
+   int val = num - MT2701_IO_I2S;
+
+   if (val < 0 || val >= MT2701_I2S_NUM) {
+   dev_err(afe->dev, "%s, num not available, num %d, val %d\n",
+   __func__, num, val);
+   return -EINVAL;
+   }
+   return val;
+}
+
+static int mt2701_afe_i2s_fs(unsigned int sample_rate)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(mt2701_afe_i2s_rates); i++)
+   if (mt2701_afe_i2s_rates[i].rate == sample_rate)
+   return mt2701_afe_i2s_rates[i].regvalue;
+
+   return -EINVAL;
+}
+
+static int mt2701_afe_i2s_startup(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+  

[alsa-devel] [PATCH] ASoC: bt-sco: add config prompt

2016-07-04 Thread Garlic Tseng
Add config prompt for bt-sco codec driver

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/codecs/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index f2f8603..1cd6ab3 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -383,7 +383,7 @@ config SND_SOC_ALC5632
tristate
 
 config SND_SOC_BT_SCO
-   tristate
+   tristate "Dummy BT SCO codec driver"
 
 config SND_SOC_CQ0093VC
tristate
-- 
1.9.1



[alsa-devel] [PATCH] ASoC: bt-sco: add config prompt

2016-07-04 Thread Garlic Tseng
Add config prompt for bt-sco codec driver

Signed-off-by: Garlic Tseng 
---
 sound/soc/codecs/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index f2f8603..1cd6ab3 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -383,7 +383,7 @@ config SND_SOC_ALC5632
tristate
 
 config SND_SOC_BT_SCO
-   tristate
+   tristate "Dummy BT SCO codec driver"
 
 config SND_SOC_CQ0093VC
tristate
-- 
1.9.1



Re: [alsa-devel] [PATCH v5 6/9] ASoC: mediatek: add mt2701 platform driver implementation.

2016-07-03 Thread Garlic Tseng
On Thu, 2016-06-30 at 21:39 +0800, Garlic Tseng wrote:
> On Wed, 2016-06-29 at 20:13 +0100, Mark Brown wrote:
> > On Fri, Jun 17, 2016 at 03:43:57PM +0800, Garlic Tseng wrote:
> > 
> > > +static int mt2701_afe_i2s_set_clkdiv(struct snd_soc_dai *dai, int div_id,
> > > +  int div)
> > > +{
> > 
> > Why are we adding a set_clkdiv() operation?  I would expect the driver
> > to be able to figure things out automatically.
> > 
> > > + case DIV_ID_MCLK_TO_BCK:
> > > + afe_priv->i2s_path[i2s_num].div_mclk_to_bck = div;
> > > + break;
> > > + case DIV_ID_BCK_TO_LRCK:
> > > + afe_priv->i2s_path[i2s_num].div_bck_to_lrck = div;
> > > + break;
> > 
> > Especially in the case where we're configuring LRCLK, that's trivial
> > when we know the sample rate which we have to know anyway.
> 
> Oh... actually I want to say 'div_mclk_over_bck' and 'div_bck_over_lrck'
> I'll fix the naming if we decide to reserve the set_clkdiv() operation.
> (omit some comment)

Hi Mark, I recognize that we can set mclk by set_sysclk, fix bck to 64fs
and let lrck be the same as sample rate so yes we don't need set_clkdiv.

Thanks for comment, I'll fix that in the next patch.

Garlic





Re: [alsa-devel] [PATCH v5 6/9] ASoC: mediatek: add mt2701 platform driver implementation.

2016-07-03 Thread Garlic Tseng
On Thu, 2016-06-30 at 21:39 +0800, Garlic Tseng wrote:
> On Wed, 2016-06-29 at 20:13 +0100, Mark Brown wrote:
> > On Fri, Jun 17, 2016 at 03:43:57PM +0800, Garlic Tseng wrote:
> > 
> > > +static int mt2701_afe_i2s_set_clkdiv(struct snd_soc_dai *dai, int div_id,
> > > +  int div)
> > > +{
> > 
> > Why are we adding a set_clkdiv() operation?  I would expect the driver
> > to be able to figure things out automatically.
> > 
> > > + case DIV_ID_MCLK_TO_BCK:
> > > + afe_priv->i2s_path[i2s_num].div_mclk_to_bck = div;
> > > + break;
> > > + case DIV_ID_BCK_TO_LRCK:
> > > + afe_priv->i2s_path[i2s_num].div_bck_to_lrck = div;
> > > + break;
> > 
> > Especially in the case where we're configuring LRCLK, that's trivial
> > when we know the sample rate which we have to know anyway.
> 
> Oh... actually I want to say 'div_mclk_over_bck' and 'div_bck_over_lrck'
> I'll fix the naming if we decide to reserve the set_clkdiv() operation.
> (omit some comment)

Hi Mark, I recognize that we can set mclk by set_sysclk, fix bck to 64fs
and let lrck be the same as sample rate so yes we don't need set_clkdiv.

Thanks for comment, I'll fix that in the next patch.

Garlic





Re: [alsa-devel] [PATCH v5 7/9] ASoC: bt-sco: extend rate and add a general compatible string

2016-07-03 Thread Garlic Tseng
On Sat, 2016-07-02 at 17:05 +0800, Chen-Yu Tsai wrote:

Hi,

> Could we also make this driver directly configurable from Kconfig,
> and not just selected by platforms (currently Samsung) or by building
> all coddecs?
> 
> Thanks
> ChenYu

I'll add configure prompt for SND_SOC_BT_SCO in next patchset.
Thanks for comment.

Garlic




Re: [alsa-devel] [PATCH v5 7/9] ASoC: bt-sco: extend rate and add a general compatible string

2016-07-03 Thread Garlic Tseng
On Sat, 2016-07-02 at 17:05 +0800, Chen-Yu Tsai wrote:

Hi,

> Could we also make this driver directly configurable from Kconfig,
> and not just selected by platforms (currently Samsung) or by building
> all coddecs?
> 
> Thanks
> ChenYu

I'll add configure prompt for SND_SOC_BT_SCO in next patchset.
Thanks for comment.

Garlic




Re: [alsa-devel] [PATCH v5 7/9] ASoC: bt-sco: extend rate and add a general compatible string

2016-06-30 Thread Garlic Tseng
On Thu, 2016-06-30 at 20:55 +0800, Garlic Tseng wrote:
> On Wed, 2016-06-29 at 20:15 +0100, Mark Brown wrote:
> > On Fri, Jun 17, 2016 at 03:43:58PM +0800, Garlic Tseng wrote:
> > > Add supports for 16k (wideband BT) and add a general compatible
> > > string "linux,bt-sco"
> > 
> > This will claim that we support 16k on existing systems which we clearly
> > don't.  It also seems unwise to advertise multiple rates when we've no
> > way to configure the rates...  how does the BT controller figure out
> > what the sample rate is?
> 
> The codec driver is a dummy driver for bt device and actually do
> nothing. The user-space will control both bt part and alsa part (at
> least in mt2701 platform). Yes the sound/soc/codecs/bt-sco.c was only
> support 8k and was already there before the patch, but I think it might
> be ok to extend it to 16k without any side effect.
> 
> If you worry about some potential risk (I don't see any) maybe we have
> to develop another dummy bt-sco codec driver which support both 8k and
> 16k?

Ah! If someone whose bluetooth modules only support 8k use the driver,
they might be broken, right? Maybe we can add another snd_soc_dai_driver
which can support both 8k and 16k.
(Actually I found the issue is discussed before
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-November/084687.html )



Re: [alsa-devel] [PATCH v5 7/9] ASoC: bt-sco: extend rate and add a general compatible string

2016-06-30 Thread Garlic Tseng
On Thu, 2016-06-30 at 20:55 +0800, Garlic Tseng wrote:
> On Wed, 2016-06-29 at 20:15 +0100, Mark Brown wrote:
> > On Fri, Jun 17, 2016 at 03:43:58PM +0800, Garlic Tseng wrote:
> > > Add supports for 16k (wideband BT) and add a general compatible
> > > string "linux,bt-sco"
> > 
> > This will claim that we support 16k on existing systems which we clearly
> > don't.  It also seems unwise to advertise multiple rates when we've no
> > way to configure the rates...  how does the BT controller figure out
> > what the sample rate is?
> 
> The codec driver is a dummy driver for bt device and actually do
> nothing. The user-space will control both bt part and alsa part (at
> least in mt2701 platform). Yes the sound/soc/codecs/bt-sco.c was only
> support 8k and was already there before the patch, but I think it might
> be ok to extend it to 16k without any side effect.
> 
> If you worry about some potential risk (I don't see any) maybe we have
> to develop another dummy bt-sco codec driver which support both 8k and
> 16k?

Ah! If someone whose bluetooth modules only support 8k use the driver,
they might be broken, right? Maybe we can add another snd_soc_dai_driver
which can support both 8k and 16k.
(Actually I found the issue is discussed before
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-November/084687.html )



Re: [alsa-devel] [PATCH v5 6/9] ASoC: mediatek: add mt2701 platform driver implementation.

2016-06-30 Thread Garlic Tseng
On Wed, 2016-06-29 at 20:13 +0100, Mark Brown wrote:
> On Fri, Jun 17, 2016 at 03:43:57PM +0800, Garlic Tseng wrote:
> 
> > +static int mt2701_afe_i2s_set_clkdiv(struct snd_soc_dai *dai, int div_id,
> > +int div)
> > +{
> 
> Why are we adding a set_clkdiv() operation?  I would expect the driver
> to be able to figure things out automatically.
> 
> > +   case DIV_ID_MCLK_TO_BCK:
> > +   afe_priv->i2s_path[i2s_num].div_mclk_to_bck = div;
> > +   break;
> > +   case DIV_ID_BCK_TO_LRCK:
> > +   afe_priv->i2s_path[i2s_num].div_bck_to_lrck = div;
> > +   break;
> 
> Especially in the case where we're configuring LRCLK, that's trivial
> when we know the sample rate which we have to know anyway.

Oh... actually I want to say 'div_mclk_over_bck' and 'div_bck_over_lrck'
I'll fix the naming if we decide to reserve the set_clkdiv() operation.

For div_bck_over_lrck, yes we only support bck = 64fs now so I'll remove
it. Maybe in the future we'll allow bck = 32fs for some board and I'll
send patch on that time.

For div_mclk_over_bck, mt2635 can offer 128fs and 256fs mclk to codec,
and it depends on the board so I tend to let machine driver configure
it. However, maybe changing it to div_mclk_over_lrck will be better.
I'll do the change.

BTW, some patch is applied for the patchset so I need not to send the
new version but send another patchset, right?


> ___
> Alsa-devel mailing list
> alsa-de...@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel




Re: [alsa-devel] [PATCH v5 6/9] ASoC: mediatek: add mt2701 platform driver implementation.

2016-06-30 Thread Garlic Tseng
On Wed, 2016-06-29 at 20:13 +0100, Mark Brown wrote:
> On Fri, Jun 17, 2016 at 03:43:57PM +0800, Garlic Tseng wrote:
> 
> > +static int mt2701_afe_i2s_set_clkdiv(struct snd_soc_dai *dai, int div_id,
> > +int div)
> > +{
> 
> Why are we adding a set_clkdiv() operation?  I would expect the driver
> to be able to figure things out automatically.
> 
> > +   case DIV_ID_MCLK_TO_BCK:
> > +   afe_priv->i2s_path[i2s_num].div_mclk_to_bck = div;
> > +   break;
> > +   case DIV_ID_BCK_TO_LRCK:
> > +   afe_priv->i2s_path[i2s_num].div_bck_to_lrck = div;
> > +   break;
> 
> Especially in the case where we're configuring LRCLK, that's trivial
> when we know the sample rate which we have to know anyway.

Oh... actually I want to say 'div_mclk_over_bck' and 'div_bck_over_lrck'
I'll fix the naming if we decide to reserve the set_clkdiv() operation.

For div_bck_over_lrck, yes we only support bck = 64fs now so I'll remove
it. Maybe in the future we'll allow bck = 32fs for some board and I'll
send patch on that time.

For div_mclk_over_bck, mt2635 can offer 128fs and 256fs mclk to codec,
and it depends on the board so I tend to let machine driver configure
it. However, maybe changing it to div_mclk_over_lrck will be better.
I'll do the change.

BTW, some patch is applied for the patchset so I need not to send the
new version but send another patchset, right?


> ___
> Alsa-devel mailing list
> alsa-de...@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel




Re: [alsa-devel] [PATCH v5 7/9] ASoC: bt-sco: extend rate and add a general compatible string

2016-06-30 Thread Garlic Tseng
On Wed, 2016-06-29 at 20:15 +0100, Mark Brown wrote:
> On Fri, Jun 17, 2016 at 03:43:58PM +0800, Garlic Tseng wrote:
> > Add supports for 16k (wideband BT) and add a general compatible
> > string "linux,bt-sco"
> 
> This will claim that we support 16k on existing systems which we clearly
> don't.  It also seems unwise to advertise multiple rates when we've no
> way to configure the rates...  how does the BT controller figure out
> what the sample rate is?

The codec driver is a dummy driver for bt device and actually do
nothing. The user-space will control both bt part and alsa part (at
least in mt2701 platform). Yes the sound/soc/codecs/bt-sco.c was only
support 8k and was already there before the patch, but I think it might
be ok to extend it to 16k without any side effect.

If you worry about some potential risk (I don't see any) maybe we have
to develop another dummy bt-sco codec driver which support both 8k and
16k?



Re: [alsa-devel] [PATCH v5 7/9] ASoC: bt-sco: extend rate and add a general compatible string

2016-06-30 Thread Garlic Tseng
On Wed, 2016-06-29 at 20:15 +0100, Mark Brown wrote:
> On Fri, Jun 17, 2016 at 03:43:58PM +0800, Garlic Tseng wrote:
> > Add supports for 16k (wideband BT) and add a general compatible
> > string "linux,bt-sco"
> 
> This will claim that we support 16k on existing systems which we clearly
> don't.  It also seems unwise to advertise multiple rates when we've no
> way to configure the rates...  how does the BT controller figure out
> what the sample rate is?

The codec driver is a dummy driver for bt device and actually do
nothing. The user-space will control both bt part and alsa part (at
least in mt2701 platform). Yes the sound/soc/codecs/bt-sco.c was only
support 8k and was already there before the patch, but I think it might
be ok to extend it to 16k without any side effect.

If you worry about some potential risk (I don't see any) maybe we have
to develop another dummy bt-sco codec driver which support both 8k and
16k?



[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 <garlic.ts...@mediatek.com>
---
 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 = {
@

[alsa-devel] [PATCH v5 2/9] ASoC: mediatek: implement mediatek common structure

2016-06-17 Thread Garlic Tseng
implement mediatek basic structure, include common private data,
afe fe dai operator and afe platform driver.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/common/mtk-afe-fe-dai.c | 379 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.h |  45 +++
 .../soc/mediatek/common/mtk-afe-platform-driver.c  |  90 +
 .../soc/mediatek/common/mtk-afe-platform-driver.h  |  23 ++
 sound/soc/mediatek/common/mtk-base-afe.h   | 104 ++
 5 files changed, 641 insertions(+)
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.h
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.h
 create mode 100644 sound/soc/mediatek/common/mtk-base-afe.h

diff --git a/sound/soc/mediatek/common/mtk-afe-fe-dai.c 
b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
new file mode 100644
index 000..b788791b
--- /dev/null
+++ b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
@@ -0,0 +1,379 @@
+/*
+ * mtk-afe-fe-dais.c  --  Mediatek afe fe dai operator
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng <garlic.ts...@mediatek.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "mtk-afe-fe-dai.h"
+#include "mtk-base-afe.h"
+
+#define AFE_BASE_END_OFFSET 8
+
+int mtk_regmap_update_bits(struct regmap *map, int reg, unsigned int mask,
+  unsigned int val)
+{
+   if (reg < 0)
+   return 0;
+   return regmap_update_bits(map, reg, mask, val);
+}
+
+int mtk_regmap_write(struct regmap *map, int reg, unsigned int val)
+{
+   if (reg < 0)
+   return 0;
+   return regmap_write(map, reg, val);
+}
+
+int mtk_afe_fe_startup(struct snd_pcm_substream *substream,
+  struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   int memif_num = rtd->cpu_dai->id;
+   struct mtk_base_afe_memif *memif = >memif[memif_num];
+   const struct snd_pcm_hardware *mtk_afe_hardware = afe->mtk_afe_hardware;
+   int ret;
+
+   memif->substream = substream;
+
+   snd_pcm_hw_constraint_step(substream->runtime, 0,
+  SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 16);
+   /* enable agent */
+   mtk_regmap_update_bits(afe->regmap, memif->data->agent_disable_reg,
+  1 << memif->data->agent_disable_shift,
+  0 << memif->data->agent_disable_shift);
+
+   snd_soc_set_runtime_hwparams(substream, mtk_afe_hardware);
+
+   /*
+* Capture cannot use ping-pong buffer since hw_ptr at IRQ may be
+* smaller than period_size due to AFE's internal buffer.
+* This easily leads to overrun when avail_min is period_size.
+* One more period can hold the possible unread buffer.
+*/
+   if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+   int periods_max = mtk_afe_hardware->periods_max;
+
+   ret = snd_pcm_hw_constraint_minmax(runtime,
+  SNDRV_PCM_HW_PARAM_PERIODS,
+  3, periods_max);
+   if (ret < 0) {
+   dev_err(afe->dev, "hw_constraint_minmax failed\n");
+   return ret;
+   }
+   }
+
+   ret = snd_pcm_hw_constraint_integer(runtime,
+   SNDRV_PCM_HW_PARAM_PERIODS);
+   if (ret < 0)
+   dev_err(afe->dev, "snd_pcm_hw_constraint_integer failed\n");
+
+   /* dynamic allocate irq to memif */
+   if (memif->irq_usage < 0) {
+   int irq_id = mtk_dynamic_irq_acquire(afe);
+
+   if (irq_id != afe->irqs_size) {
+   /* link */
+   memif->irq_usage = irq_id;
+   } else {
+   dev_err(afe->dev, "%s() error: no more asys irq\n",
+   __func__);
+   ret = -EBUSY;
+   }
+   }
+   return ret;
+}
+EXPORT_SYM

[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

[alsa-devel] [PATCH v5 2/9] ASoC: mediatek: implement mediatek common structure

2016-06-17 Thread Garlic Tseng
implement mediatek basic structure, include common private data,
afe fe dai operator and afe platform driver.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/common/mtk-afe-fe-dai.c | 379 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.h |  45 +++
 .../soc/mediatek/common/mtk-afe-platform-driver.c  |  90 +
 .../soc/mediatek/common/mtk-afe-platform-driver.h  |  23 ++
 sound/soc/mediatek/common/mtk-base-afe.h   | 104 ++
 5 files changed, 641 insertions(+)
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.h
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.h
 create mode 100644 sound/soc/mediatek/common/mtk-base-afe.h

diff --git a/sound/soc/mediatek/common/mtk-afe-fe-dai.c 
b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
new file mode 100644
index 000..b788791b
--- /dev/null
+++ b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
@@ -0,0 +1,379 @@
+/*
+ * mtk-afe-fe-dais.c  --  Mediatek afe fe dai operator
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "mtk-afe-fe-dai.h"
+#include "mtk-base-afe.h"
+
+#define AFE_BASE_END_OFFSET 8
+
+int mtk_regmap_update_bits(struct regmap *map, int reg, unsigned int mask,
+  unsigned int val)
+{
+   if (reg < 0)
+   return 0;
+   return regmap_update_bits(map, reg, mask, val);
+}
+
+int mtk_regmap_write(struct regmap *map, int reg, unsigned int val)
+{
+   if (reg < 0)
+   return 0;
+   return regmap_write(map, reg, val);
+}
+
+int mtk_afe_fe_startup(struct snd_pcm_substream *substream,
+  struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   int memif_num = rtd->cpu_dai->id;
+   struct mtk_base_afe_memif *memif = >memif[memif_num];
+   const struct snd_pcm_hardware *mtk_afe_hardware = afe->mtk_afe_hardware;
+   int ret;
+
+   memif->substream = substream;
+
+   snd_pcm_hw_constraint_step(substream->runtime, 0,
+  SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 16);
+   /* enable agent */
+   mtk_regmap_update_bits(afe->regmap, memif->data->agent_disable_reg,
+  1 << memif->data->agent_disable_shift,
+  0 << memif->data->agent_disable_shift);
+
+   snd_soc_set_runtime_hwparams(substream, mtk_afe_hardware);
+
+   /*
+* Capture cannot use ping-pong buffer since hw_ptr at IRQ may be
+* smaller than period_size due to AFE's internal buffer.
+* This easily leads to overrun when avail_min is period_size.
+* One more period can hold the possible unread buffer.
+*/
+   if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+   int periods_max = mtk_afe_hardware->periods_max;
+
+   ret = snd_pcm_hw_constraint_minmax(runtime,
+  SNDRV_PCM_HW_PARAM_PERIODS,
+  3, periods_max);
+   if (ret < 0) {
+   dev_err(afe->dev, "hw_constraint_minmax failed\n");
+   return ret;
+   }
+   }
+
+   ret = snd_pcm_hw_constraint_integer(runtime,
+   SNDRV_PCM_HW_PARAM_PERIODS);
+   if (ret < 0)
+   dev_err(afe->dev, "snd_pcm_hw_constraint_integer failed\n");
+
+   /* dynamic allocate irq to memif */
+   if (memif->irq_usage < 0) {
+   int irq_id = mtk_dynamic_irq_acquire(afe);
+
+   if (irq_id != afe->irqs_size) {
+   /* link */
+   memif->irq_usage = irq_id;
+   } else {
+   dev_err(afe->dev, "%s() error: no more asys irq\n",
+   __func__);
+   ret = -EBUSY;
+   }
+   }
+   return ret;
+}
+EXPORT_SYMBOL_GPL(mtk_afe_fe_startup);
+
+void mtk_afe_fe_shutdown(struct snd_pcm_substre

[alsa-devel] [PATCH v5 6/9] ASoC: mediatek: add mt2701 platform driver implementation.

2016-06-17 Thread Garlic Tseng
Add mt2701 platform driver implementation for playback and capture.
The implement follow DAPM structure (memory interface as FE and I2S
as BE).
Because of the hardware design, i2s out required to be enabled when
we need to enable i2s in. This patch includes the implementation.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 1559 
 1 file changed, 1559 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
new file mode 100644
index 000..deb5f82
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -0,0 +1,1559 @@
+/*
+ * Mediatek ALSA SoC AFE platform driver for 2701
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng <garlic.ts...@mediatek.com>
+ * Ir Lian <ir.l...@mediatek.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+#include "mt2701-afe-clock-ctrl.h"
+#include "../common/mtk-afe-platform-driver.h"
+#include "../common/mtk-afe-fe-dai.h"
+
+#define AFE_IRQ_STATUS_BITS0xff
+
+static const struct snd_pcm_hardware mt2701_afe_hardware = {
+   .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED
+   | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE
+  | SNDRV_PCM_FMTBIT_S32_LE,
+   .period_bytes_min = 1024,
+   .period_bytes_max = 1024 * 256,
+   .periods_min = 4,
+   .periods_max = 1024,
+   .buffer_bytes_max = 1024 * 1024 * 16,
+   .fifo_size = 0,
+};
+
+struct mt2701_afe_rate {
+   unsigned int rate;
+   unsigned int regvalue;
+};
+
+static const struct mt2701_afe_rate mt2701_afe_i2s_rates[] = {
+   { .rate = 8000, .regvalue = 0 },
+   { .rate = 12000, .regvalue = 1 },
+   { .rate = 16000, .regvalue = 2 },
+   { .rate = 24000, .regvalue = 3 },
+   { .rate = 32000, .regvalue = 4 },
+   { .rate = 48000, .regvalue = 5 },
+   { .rate = 96000, .regvalue = 6 },
+   { .rate = 192000, .regvalue = 7 },
+   { .rate = 384000, .regvalue = 8 },
+   { .rate = 7350, .regvalue = 16 },
+   { .rate = 11025, .regvalue = 17 },
+   { .rate = 14700, .regvalue = 18 },
+   { .rate = 22050, .regvalue = 19 },
+   { .rate = 29400, .regvalue = 20 },
+   { .rate = 44100, .regvalue = 21 },
+   { .rate = 88200, .regvalue = 22 },
+   { .rate = 176400, .regvalue = 23 },
+   { .rate = 352800, .regvalue = 24 },
+};
+
+int mt2701_dai_num_to_i2s(struct mtk_base_afe *afe, int num)
+{
+   int val = num - MT2701_IO_I2S;
+
+   if (val < 0 || val >= MT2701_I2S_NUM) {
+   dev_err(afe->dev, "%s, num not available, num %d, val %d\n",
+   __func__, num, val);
+   return -EINVAL;
+   }
+   return val;
+}
+
+static int mt2701_afe_i2s_fs(unsigned int sample_rate)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(mt2701_afe_i2s_rates); i++)
+   if (mt2701_afe_i2s_rates[i].rate == sample_rate)
+   return mt2701_afe_i2s_rates[i].regvalue;
+
+   return -EINVAL;
+}
+
+static int mt2701_afe_i2s_startup(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+   int i2s_num = mt2701_dai_num_to_i2s(afe, dai->id);
+   int clk_num = MT2701_AUD_AUD_I2S1_MCLK + i2s_num;
+   int ret = 0;
+
+   if (i2s_num < 0)
+   return i2s_num;
+
+   /* enable mclk */
+   ret = clk_prepare_enable(afe_priv->clocks[clk_num]);
+   if (ret)
+   dev_err(afe->dev, "Failed to enable mclk for I2S: %d\n",
+   i2s_num);
+
+   return ret;
+}
+
+static int mt2701_afe_i2s_path_shutdown(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai,
+   int dir_invert)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform

[alsa-devel] [PATCH v5 7/9] ASoC: bt-sco: extend rate and add a general compatible string

2016-06-17 Thread Garlic Tseng
Add supports for 16k (wideband BT) and add a general compatible
string "linux,bt-sco"

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 Documentation/devicetree/bindings/sound/bt-sco.txt | 2 +-
 sound/soc/codecs/bt-sco.c  | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/sound/bt-sco.txt 
b/Documentation/devicetree/bindings/sound/bt-sco.txt
index 29b8e5d..641edf7 100644
--- a/Documentation/devicetree/bindings/sound/bt-sco.txt
+++ b/Documentation/devicetree/bindings/sound/bt-sco.txt
@@ -4,7 +4,7 @@ This device support generic Bluetooth SCO link.
 
 Required properties:
 
-  - compatible : "delta,dfbmcs320"
+  - compatible : "delta,dfbmcs320" or "linux,bt-sco"
 
 Example:
 
diff --git a/sound/soc/codecs/bt-sco.c b/sound/soc/codecs/bt-sco.c
index b084ad1..101b384 100644
--- a/sound/soc/codecs/bt-sco.c
+++ b/sound/soc/codecs/bt-sco.c
@@ -31,14 +31,14 @@ static struct snd_soc_dai_driver bt_sco_dai = {
.stream_name = "Playback",
.channels_min = 1,
.channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
.capture = {
 .stream_name = "Capture",
.channels_min = 1,
.channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
 };
@@ -77,6 +77,7 @@ MODULE_DEVICE_TABLE(platform, bt_sco_driver_ids);
 #if defined(CONFIG_OF)
 static const struct of_device_id bt_sco_codec_of_match[] = {
{ .compatible = "delta,dfbmcs320", },
+   { .compatible = "linux,bt-sco", },
{},
 };
 MODULE_DEVICE_TABLE(of, bt_sco_codec_of_match);
-- 
1.9.1



[alsa-devel] [PATCH v5 9/9] ASoC: mediatek: Add mt2701-cs42448 driver and config option.

2016-06-17 Thread Garlic Tseng
Add machine driver and config option for MT2701.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/Kconfig |  21 ++
 sound/soc/mediatek/Makefile|   1 +
 sound/soc/mediatek/mt2701/Makefile |  19 ++
 sound/soc/mediatek/mt2701/mt2701-cs42448.c | 422 +
 4 files changed, 463 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index 705904b..2fbe543 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,6 +1,27 @@
 config SND_SOC_MEDIATEK
tristate
 
+config SND_SOC_MT2701
+   tristate "ASoC support for Mediatek MT2701 chip"
+   depends on ARCH_MEDIATEK
+   select SND_SOC_MEDIATEK
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ that can be used with other codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
+config SND_SOC_MT2701_CS42448
+   tristate "ASoc Audio driver for MT2701 with CS42448 codec"
+   depends on SND_SOC_MT2701
+   select SND_SOC_CS42XX8_I2C
+   select SND_SOC_BT_SCO
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ with the CS42448 codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
 config SND_SOC_MT8173
tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index 4fe8068..6bcab35 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,2 +1,3 @@
 obj-$(CONFIG_SND_SOC_MEDIATEK) += common/
+obj-$(CONFIG_SND_SOC_MT2701) += mt2701/
 obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
diff --git a/sound/soc/mediatek/mt2701/Makefile 
b/sound/soc/mediatek/mt2701/Makefile
new file mode 100644
index 000..31c3d04
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/Makefile
@@ -0,0 +1,19 @@
+#
+# 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-mt2701-afe-objs := mt2701-afe-pcm.o mt2701-afe-clock-ctrl.o
+obj-$(CONFIG_SND_SOC_MT2701) += snd-soc-mt2701-afe.o
+
+# machine driver
+obj-$(CONFIG_SND_SOC_MT2701_CS42448) += mt2701-cs42448.o
diff --git a/sound/soc/mediatek/mt2701/mt2701-cs42448.c 
b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
new file mode 100644
index 000..0e48cb9
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
@@ -0,0 +1,422 @@
+/*
+ * mt2701-cs42448.c  --  MT2701 CS42448 ALSA SoC machine driver
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Ir Lian <ir.l...@mediatek.com>
+ *  Garlic Tseng <garlic.ts...@mediatek.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+struct mt2701_cs42448_private {
+   int i2s1_in_mux;
+   int i2s1_in_mux_gpio_sel_1;
+   int i2s1_in_mux_gpio_sel_2;
+};
+
+static const char * const i2sin_mux_switch_text[] = {
+   "ADC_SDOUT2",
+   "ADC_SDOUT3",
+   "I2S_IN_1",
+   "I2S_IN_2",
+};
+
+static const struct soc_enum i2sin_mux_enum =
+   SOC_ENUM_SINGLE_EXT(4, i2sin_mux_switch_text);
+
+static int mt2701_cs42448_i2sin1_mux_get(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card);
+
+   ucontrol->value.integer.value[0] = priv->i2s1_in_mux;
+   return 0;
+}
+
+static int mt2701_cs42448_i2sin1_mux_set(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card

[alsa-devel] [PATCH v5 6/9] ASoC: mediatek: add mt2701 platform driver implementation.

2016-06-17 Thread Garlic Tseng
Add mt2701 platform driver implementation for playback and capture.
The implement follow DAPM structure (memory interface as FE and I2S
as BE).
Because of the hardware design, i2s out required to be enabled when
we need to enable i2s in. This patch includes the implementation.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 1559 
 1 file changed, 1559 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
new file mode 100644
index 000..deb5f82
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -0,0 +1,1559 @@
+/*
+ * Mediatek ALSA SoC AFE platform driver for 2701
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng 
+ * Ir Lian 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+#include "mt2701-afe-clock-ctrl.h"
+#include "../common/mtk-afe-platform-driver.h"
+#include "../common/mtk-afe-fe-dai.h"
+
+#define AFE_IRQ_STATUS_BITS0xff
+
+static const struct snd_pcm_hardware mt2701_afe_hardware = {
+   .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED
+   | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE
+  | SNDRV_PCM_FMTBIT_S32_LE,
+   .period_bytes_min = 1024,
+   .period_bytes_max = 1024 * 256,
+   .periods_min = 4,
+   .periods_max = 1024,
+   .buffer_bytes_max = 1024 * 1024 * 16,
+   .fifo_size = 0,
+};
+
+struct mt2701_afe_rate {
+   unsigned int rate;
+   unsigned int regvalue;
+};
+
+static const struct mt2701_afe_rate mt2701_afe_i2s_rates[] = {
+   { .rate = 8000, .regvalue = 0 },
+   { .rate = 12000, .regvalue = 1 },
+   { .rate = 16000, .regvalue = 2 },
+   { .rate = 24000, .regvalue = 3 },
+   { .rate = 32000, .regvalue = 4 },
+   { .rate = 48000, .regvalue = 5 },
+   { .rate = 96000, .regvalue = 6 },
+   { .rate = 192000, .regvalue = 7 },
+   { .rate = 384000, .regvalue = 8 },
+   { .rate = 7350, .regvalue = 16 },
+   { .rate = 11025, .regvalue = 17 },
+   { .rate = 14700, .regvalue = 18 },
+   { .rate = 22050, .regvalue = 19 },
+   { .rate = 29400, .regvalue = 20 },
+   { .rate = 44100, .regvalue = 21 },
+   { .rate = 88200, .regvalue = 22 },
+   { .rate = 176400, .regvalue = 23 },
+   { .rate = 352800, .regvalue = 24 },
+};
+
+int mt2701_dai_num_to_i2s(struct mtk_base_afe *afe, int num)
+{
+   int val = num - MT2701_IO_I2S;
+
+   if (val < 0 || val >= MT2701_I2S_NUM) {
+   dev_err(afe->dev, "%s, num not available, num %d, val %d\n",
+   __func__, num, val);
+   return -EINVAL;
+   }
+   return val;
+}
+
+static int mt2701_afe_i2s_fs(unsigned int sample_rate)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(mt2701_afe_i2s_rates); i++)
+   if (mt2701_afe_i2s_rates[i].rate == sample_rate)
+   return mt2701_afe_i2s_rates[i].regvalue;
+
+   return -EINVAL;
+}
+
+static int mt2701_afe_i2s_startup(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+   int i2s_num = mt2701_dai_num_to_i2s(afe, dai->id);
+   int clk_num = MT2701_AUD_AUD_I2S1_MCLK + i2s_num;
+   int ret = 0;
+
+   if (i2s_num < 0)
+   return i2s_num;
+
+   /* enable mclk */
+   ret = clk_prepare_enable(afe_priv->clocks[clk_num]);
+   if (ret)
+   dev_err(afe->dev, "Failed to enable mclk for I2S: %d\n",
+   i2s_num);
+
+   return ret;
+}
+
+static int mt2701_afe_i2s_path_shutdown(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai,
+   int dir_invert)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_pri

[alsa-devel] [PATCH v5 7/9] ASoC: bt-sco: extend rate and add a general compatible string

2016-06-17 Thread Garlic Tseng
Add supports for 16k (wideband BT) and add a general compatible
string "linux,bt-sco"

Signed-off-by: Garlic Tseng 
---
 Documentation/devicetree/bindings/sound/bt-sco.txt | 2 +-
 sound/soc/codecs/bt-sco.c  | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/sound/bt-sco.txt 
b/Documentation/devicetree/bindings/sound/bt-sco.txt
index 29b8e5d..641edf7 100644
--- a/Documentation/devicetree/bindings/sound/bt-sco.txt
+++ b/Documentation/devicetree/bindings/sound/bt-sco.txt
@@ -4,7 +4,7 @@ This device support generic Bluetooth SCO link.
 
 Required properties:
 
-  - compatible : "delta,dfbmcs320"
+  - compatible : "delta,dfbmcs320" or "linux,bt-sco"
 
 Example:
 
diff --git a/sound/soc/codecs/bt-sco.c b/sound/soc/codecs/bt-sco.c
index b084ad1..101b384 100644
--- a/sound/soc/codecs/bt-sco.c
+++ b/sound/soc/codecs/bt-sco.c
@@ -31,14 +31,14 @@ static struct snd_soc_dai_driver bt_sco_dai = {
.stream_name = "Playback",
.channels_min = 1,
.channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
.capture = {
 .stream_name = "Capture",
.channels_min = 1,
.channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
 };
@@ -77,6 +77,7 @@ MODULE_DEVICE_TABLE(platform, bt_sco_driver_ids);
 #if defined(CONFIG_OF)
 static const struct of_device_id bt_sco_codec_of_match[] = {
{ .compatible = "delta,dfbmcs320", },
+   { .compatible = "linux,bt-sco", },
{},
 };
 MODULE_DEVICE_TABLE(of, bt_sco_codec_of_match);
-- 
1.9.1



[alsa-devel] [PATCH v5 9/9] ASoC: mediatek: Add mt2701-cs42448 driver and config option.

2016-06-17 Thread Garlic Tseng
Add machine driver and config option for MT2701.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/Kconfig |  21 ++
 sound/soc/mediatek/Makefile|   1 +
 sound/soc/mediatek/mt2701/Makefile |  19 ++
 sound/soc/mediatek/mt2701/mt2701-cs42448.c | 422 +
 4 files changed, 463 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index 705904b..2fbe543 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,6 +1,27 @@
 config SND_SOC_MEDIATEK
tristate
 
+config SND_SOC_MT2701
+   tristate "ASoC support for Mediatek MT2701 chip"
+   depends on ARCH_MEDIATEK
+   select SND_SOC_MEDIATEK
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ that can be used with other codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
+config SND_SOC_MT2701_CS42448
+   tristate "ASoc Audio driver for MT2701 with CS42448 codec"
+   depends on SND_SOC_MT2701
+   select SND_SOC_CS42XX8_I2C
+   select SND_SOC_BT_SCO
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ with the CS42448 codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
 config SND_SOC_MT8173
tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index 4fe8068..6bcab35 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,2 +1,3 @@
 obj-$(CONFIG_SND_SOC_MEDIATEK) += common/
+obj-$(CONFIG_SND_SOC_MT2701) += mt2701/
 obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
diff --git a/sound/soc/mediatek/mt2701/Makefile 
b/sound/soc/mediatek/mt2701/Makefile
new file mode 100644
index 000..31c3d04
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/Makefile
@@ -0,0 +1,19 @@
+#
+# 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-mt2701-afe-objs := mt2701-afe-pcm.o mt2701-afe-clock-ctrl.o
+obj-$(CONFIG_SND_SOC_MT2701) += snd-soc-mt2701-afe.o
+
+# machine driver
+obj-$(CONFIG_SND_SOC_MT2701_CS42448) += mt2701-cs42448.o
diff --git a/sound/soc/mediatek/mt2701/mt2701-cs42448.c 
b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
new file mode 100644
index 000..0e48cb9
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
@@ -0,0 +1,422 @@
+/*
+ * mt2701-cs42448.c  --  MT2701 CS42448 ALSA SoC machine driver
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Ir Lian 
+ *  Garlic Tseng 
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+struct mt2701_cs42448_private {
+   int i2s1_in_mux;
+   int i2s1_in_mux_gpio_sel_1;
+   int i2s1_in_mux_gpio_sel_2;
+};
+
+static const char * const i2sin_mux_switch_text[] = {
+   "ADC_SDOUT2",
+   "ADC_SDOUT3",
+   "I2S_IN_1",
+   "I2S_IN_2",
+};
+
+static const struct soc_enum i2sin_mux_enum =
+   SOC_ENUM_SINGLE_EXT(4, i2sin_mux_switch_text);
+
+static int mt2701_cs42448_i2sin1_mux_get(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card);
+
+   ucontrol->value.integer.value[0] = priv->i2s1_in_mux;
+   return 0;
+}
+
+static int mt2701_cs42448_i2sin1_mux_set(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card);
+
+   if (ucontrol->value.integer.value[0] == priv->i2s1_in_mux)
+   ret

[alsa-devel] [PATCH v5 4/9] ASoC: mediatek: add documents for mt2701

2016-06-17 Thread Garlic Tseng
add mt2701-afe-pcm.txt and mt2701-cs42448.txt for mt2701

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 .../devicetree/bindings/sound/mt2701-afe-pcm.txt   | 150 +
 .../devicetree/bindings/sound/mt2701-cs42448.txt   |  43 ++
 2 files changed, 193 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-cs42448.txt

diff --git a/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt 
b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
new file mode 100644
index 000..3e623a7
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
@@ -0,0 +1,150 @@
+Mediatek AFE PCM controller for mt2701
+
+Required properties:
+- compatible = "mediatek,mt2701-audio";
+- reg: register location and size
+- interrupts: Should contain AFE interrupt
+- clock-names: should have these clock names:
+   "infra_sys_audio_clk",
+   "top_audio_mux1_sel",
+   "top_audio_mux2_sel",
+   "top_audio_mux1_div",
+   "top_audio_mux2_div",
+   "top_audio_48k_timing",
+   "top_audio_44k_timing",
+   "top_audpll_mux_sel",
+   "top_apll_sel",
+   "top_aud1_pll_98M",
+   "top_aud2_pll_90M",
+   "top_hadds2_pll_98M",
+   "top_hadds2_pll_294M",
+   "top_audpll",
+   "top_audpll_d4",
+   "top_audpll_d8",
+   "top_audpll_d16",
+   "top_audpll_d24",
+   "top_audintbus_sel",
+   "clk_26m",
+   "top_syspll1_d4",
+   "top_aud_k1_src_sel",
+   "top_aud_k2_src_sel",
+   "top_aud_k3_src_sel",
+   "top_aud_k4_src_sel",
+   "top_aud_k5_src_sel",
+   "top_aud_k6_src_sel",
+   "top_aud_k1_src_div",
+   "top_aud_k2_src_div",
+   "top_aud_k3_src_div",
+   "top_aud_k4_src_div",
+   "top_aud_k5_src_div",
+   "top_aud_k6_src_div",
+   "top_aud_i2s1_mclk",
+   "top_aud_i2s2_mclk",
+   "top_aud_i2s3_mclk",
+   "top_aud_i2s4_mclk",
+   "top_aud_i2s5_mclk",
+   "top_aud_i2s6_mclk",
+   "top_asm_m_sel",
+   "top_asm_h_sel",
+   "top_univpll2_d4",
+   "top_univpll2_d2",
+   "top_syspll_d5";
+
+Example:
+
+   afe: mt2701-afe-pcm@1122 {
+   compatible = "mediatek,mt2701-audio";
+   reg = <0 0x1122 0 0x2000>,
+ <0 0x112A 0 0x2>;
+   interrupts = ,
+;
+   clocks = < CLK_INFRA_AUDIO>,
+< CLK_TOP_AUD_MUX1_SEL>,
+< CLK_TOP_AUD_MUX2_SEL>,
+< CLK_TOP_AUD_MUX1_DIV>,
+< CLK_TOP_AUD_MUX2_DIV>,
+< CLK_TOP_AUD_48K_TIMING>,
+< CLK_TOP_AUD_44K_TIMING>,
+< CLK_TOP_AUDPLL_MUX_SEL>,
+< CLK_TOP_APLL_SEL>,
+< CLK_TOP_AUD1PLL_98M>,
+< CLK_TOP_AUD2PLL_90M>,
+< CLK_TOP_HADDS2PLL_98M>,
+< CLK_TOP_HADDS2PLL_294M>,
+< CLK_TOP_AUDPLL>,
+< CLK_TOP_AUDPLL_D4>,
+< CLK_TOP_AUDPLL_D8>,
+< CLK_TOP_AUDPLL_D16>,
+< CLK_TOP_AUDPLL_D24>,
+< CLK_TOP_AUDINTBUS_SEL>,
+<>,
+< CLK_TOP_SYSPLL1_D4>,
+< CLK_TOP_AUD_K1_SRC_SEL>,
+< CLK_TOP_AUD_K2_SRC_SEL>,
+< CLK_TOP_AUD_K3_SRC_SEL>,
+< CLK_TOP_AUD_K4_SRC_SEL>,
+< CLK_TOP_AUD_K5_SRC_SEL>,
+< CLK_TOP_AUD_K6_SRC_SEL>,
+< CLK_TOP_AUD_K1_SRC_DIV>,
+< CLK_TOP_AUD_K2_SRC_DIV>,
+< CLK_TOP_AUD_K3_SRC_DI

[alsa-devel] [PATCH v5 5/9] ASoC: mediatek: add structure define and clock control for 2701

2016-06-17 Thread Garlic Tseng
add structure define and clock control function for 2701.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c | 464 ++
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h |  38 ++
 sound/soc/mediatek/mt2701/mt2701-afe-common.h | 181 +
 sound/soc/mediatek/mt2701/mt2701-reg.h| 186 +
 4 files changed, 869 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-common.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-reg.h

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
new file mode 100644
index 000..b815ecc
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
@@ -0,0 +1,464 @@
+/*
+ * mt2701-afe-clock-ctrl.c  --  Mediatek 2701 afe clock ctrl
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng <garlic.ts...@mediatek.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+#include "mt2701-afe-clock-ctrl.h"
+
+static const char *aud_clks[MT2701_CLOCK_NUM] = {
+   [MT2701_AUD_INFRA_SYS_AUDIO] = "infra_sys_audio_clk",
+   [MT2701_AUD_AUD_MUX1_SEL] = "top_audio_mux1_sel",
+   [MT2701_AUD_AUD_MUX2_SEL] = "top_audio_mux2_sel",
+   [MT2701_AUD_AUD_MUX1_DIV] = "top_audio_mux1_div",
+   [MT2701_AUD_AUD_MUX2_DIV] = "top_audio_mux2_div",
+   [MT2701_AUD_AUD_48K_TIMING] = "top_audio_48k_timing",
+   [MT2701_AUD_AUD_44K_TIMING] = "top_audio_44k_timing",
+   [MT2701_AUD_AUDPLL_MUX_SEL] = "top_audpll_mux_sel",
+   [MT2701_AUD_APLL_SEL] = "top_apll_sel",
+   [MT2701_AUD_AUD1PLL_98M] = "top_aud1_pll_98M",
+   [MT2701_AUD_AUD2PLL_90M] = "top_aud2_pll_90M",
+   [MT2701_AUD_HADDS2PLL_98M] = "top_hadds2_pll_98M",
+   [MT2701_AUD_HADDS2PLL_294M] = "top_hadds2_pll_294M",
+   [MT2701_AUD_AUDPLL] = "top_audpll",
+   [MT2701_AUD_AUDPLL_D4] = "top_audpll_d4",
+   [MT2701_AUD_AUDPLL_D8] = "top_audpll_d8",
+   [MT2701_AUD_AUDPLL_D16] = "top_audpll_d16",
+   [MT2701_AUD_AUDPLL_D24] = "top_audpll_d24",
+   [MT2701_AUD_AUDINTBUS] = "top_audintbus_sel",
+   [MT2701_AUD_CLK_26M] = "clk_26m",
+   [MT2701_AUD_SYSPLL1_D4] = "top_syspll1_d4",
+   [MT2701_AUD_AUD_K1_SRC_SEL] = "top_aud_k1_src_sel",
+   [MT2701_AUD_AUD_K2_SRC_SEL] = "top_aud_k2_src_sel",
+   [MT2701_AUD_AUD_K3_SRC_SEL] = "top_aud_k3_src_sel",
+   [MT2701_AUD_AUD_K4_SRC_SEL] = "top_aud_k4_src_sel",
+   [MT2701_AUD_AUD_K5_SRC_SEL] = "top_aud_k5_src_sel",
+   [MT2701_AUD_AUD_K6_SRC_SEL] = "top_aud_k6_src_sel",
+   [MT2701_AUD_AUD_K1_SRC_DIV] = "top_aud_k1_src_div",
+   [MT2701_AUD_AUD_K2_SRC_DIV] = "top_aud_k2_src_div",
+   [MT2701_AUD_AUD_K3_SRC_DIV] = "top_aud_k3_src_div",
+   [MT2701_AUD_AUD_K4_SRC_DIV] = "top_aud_k4_src_div",
+   [MT2701_AUD_AUD_K5_SRC_DIV] = "top_aud_k5_src_div",
+   [MT2701_AUD_AUD_K6_SRC_DIV] = "top_aud_k6_src_div",
+   [MT2701_AUD_AUD_I2S1_MCLK] = "top_aud_i2s1_mclk",
+   [MT2701_AUD_AUD_I2S2_MCLK] = "top_aud_i2s2_mclk",
+   [MT2701_AUD_AUD_I2S3_MCLK] = "top_aud_i2s3_mclk",
+   [MT2701_AUD_AUD_I2S4_MCLK] = "top_aud_i2s4_mclk",
+   [MT2701_AUD_AUD_I2S5_MCLK] = "top_aud_i2s5_mclk",
+   [MT2701_AUD_AUD_I2S6_MCLK] = "top_aud_i2s6_mclk",
+   [MT2701_AUD_ASM_M_SEL] = "top_asm_m_sel",
+   [MT2701_AUD_ASM_H_SEL] = "top_asm_h_sel",
+   [MT2701_AUD_UNIVPLL2_D4] = "top_univpll2_d4",
+   [MT2701_AUD_UNIVPLL2_D2] = "top_univpll2_d2",
+   [MT2701_AUD_SYSPLL_D5] = "top_syspll_d5",
+};
+
+int mt2701_init_clock(struct mtk_base_afe *afe)
+{
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+   int i = 0;
+
+   for (i = 0; i < MT2701_CLOCK_NUM; i++) {
+   afe_priv->clocks[i] = devm_clk_get(afe->dev, aud_clks[i]);
+   

[alsa-devel] [PATCH v5 4/9] ASoC: mediatek: add documents for mt2701

2016-06-17 Thread Garlic Tseng
add mt2701-afe-pcm.txt and mt2701-cs42448.txt for mt2701

Signed-off-by: Garlic Tseng 
---
 .../devicetree/bindings/sound/mt2701-afe-pcm.txt   | 150 +
 .../devicetree/bindings/sound/mt2701-cs42448.txt   |  43 ++
 2 files changed, 193 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-cs42448.txt

diff --git a/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt 
b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
new file mode 100644
index 000..3e623a7
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
@@ -0,0 +1,150 @@
+Mediatek AFE PCM controller for mt2701
+
+Required properties:
+- compatible = "mediatek,mt2701-audio";
+- reg: register location and size
+- interrupts: Should contain AFE interrupt
+- clock-names: should have these clock names:
+   "infra_sys_audio_clk",
+   "top_audio_mux1_sel",
+   "top_audio_mux2_sel",
+   "top_audio_mux1_div",
+   "top_audio_mux2_div",
+   "top_audio_48k_timing",
+   "top_audio_44k_timing",
+   "top_audpll_mux_sel",
+   "top_apll_sel",
+   "top_aud1_pll_98M",
+   "top_aud2_pll_90M",
+   "top_hadds2_pll_98M",
+   "top_hadds2_pll_294M",
+   "top_audpll",
+   "top_audpll_d4",
+   "top_audpll_d8",
+   "top_audpll_d16",
+   "top_audpll_d24",
+   "top_audintbus_sel",
+   "clk_26m",
+   "top_syspll1_d4",
+   "top_aud_k1_src_sel",
+   "top_aud_k2_src_sel",
+   "top_aud_k3_src_sel",
+   "top_aud_k4_src_sel",
+   "top_aud_k5_src_sel",
+   "top_aud_k6_src_sel",
+   "top_aud_k1_src_div",
+   "top_aud_k2_src_div",
+   "top_aud_k3_src_div",
+   "top_aud_k4_src_div",
+   "top_aud_k5_src_div",
+   "top_aud_k6_src_div",
+   "top_aud_i2s1_mclk",
+   "top_aud_i2s2_mclk",
+   "top_aud_i2s3_mclk",
+   "top_aud_i2s4_mclk",
+   "top_aud_i2s5_mclk",
+   "top_aud_i2s6_mclk",
+   "top_asm_m_sel",
+   "top_asm_h_sel",
+   "top_univpll2_d4",
+   "top_univpll2_d2",
+   "top_syspll_d5";
+
+Example:
+
+   afe: mt2701-afe-pcm@1122 {
+   compatible = "mediatek,mt2701-audio";
+   reg = <0 0x1122 0 0x2000>,
+ <0 0x112A 0 0x2>;
+   interrupts = ,
+;
+   clocks = < CLK_INFRA_AUDIO>,
+< CLK_TOP_AUD_MUX1_SEL>,
+< CLK_TOP_AUD_MUX2_SEL>,
+< CLK_TOP_AUD_MUX1_DIV>,
+< CLK_TOP_AUD_MUX2_DIV>,
+< CLK_TOP_AUD_48K_TIMING>,
+< CLK_TOP_AUD_44K_TIMING>,
+< CLK_TOP_AUDPLL_MUX_SEL>,
+< CLK_TOP_APLL_SEL>,
+< CLK_TOP_AUD1PLL_98M>,
+< CLK_TOP_AUD2PLL_90M>,
+< CLK_TOP_HADDS2PLL_98M>,
+< CLK_TOP_HADDS2PLL_294M>,
+< CLK_TOP_AUDPLL>,
+< CLK_TOP_AUDPLL_D4>,
+< CLK_TOP_AUDPLL_D8>,
+< CLK_TOP_AUDPLL_D16>,
+< CLK_TOP_AUDPLL_D24>,
+< CLK_TOP_AUDINTBUS_SEL>,
+<>,
+< CLK_TOP_SYSPLL1_D4>,
+< CLK_TOP_AUD_K1_SRC_SEL>,
+< CLK_TOP_AUD_K2_SRC_SEL>,
+< CLK_TOP_AUD_K3_SRC_SEL>,
+< CLK_TOP_AUD_K4_SRC_SEL>,
+< CLK_TOP_AUD_K5_SRC_SEL>,
+< CLK_TOP_AUD_K6_SRC_SEL>,
+< CLK_TOP_AUD_K1_SRC_DIV>,
+< CLK_TOP_AUD_K2_SRC_DIV>,
+< CLK_TOP_AUD_K3_SRC_DIV>,
+< CLK_TOP_AUD_K4_S

[alsa-devel] [PATCH v5 5/9] ASoC: mediatek: add structure define and clock control for 2701

2016-06-17 Thread Garlic Tseng
add structure define and clock control function for 2701.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c | 464 ++
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h |  38 ++
 sound/soc/mediatek/mt2701/mt2701-afe-common.h | 181 +
 sound/soc/mediatek/mt2701/mt2701-reg.h| 186 +
 4 files changed, 869 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-common.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-reg.h

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
new file mode 100644
index 000..b815ecc
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
@@ -0,0 +1,464 @@
+/*
+ * mt2701-afe-clock-ctrl.c  --  Mediatek 2701 afe clock ctrl
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+#include "mt2701-afe-clock-ctrl.h"
+
+static const char *aud_clks[MT2701_CLOCK_NUM] = {
+   [MT2701_AUD_INFRA_SYS_AUDIO] = "infra_sys_audio_clk",
+   [MT2701_AUD_AUD_MUX1_SEL] = "top_audio_mux1_sel",
+   [MT2701_AUD_AUD_MUX2_SEL] = "top_audio_mux2_sel",
+   [MT2701_AUD_AUD_MUX1_DIV] = "top_audio_mux1_div",
+   [MT2701_AUD_AUD_MUX2_DIV] = "top_audio_mux2_div",
+   [MT2701_AUD_AUD_48K_TIMING] = "top_audio_48k_timing",
+   [MT2701_AUD_AUD_44K_TIMING] = "top_audio_44k_timing",
+   [MT2701_AUD_AUDPLL_MUX_SEL] = "top_audpll_mux_sel",
+   [MT2701_AUD_APLL_SEL] = "top_apll_sel",
+   [MT2701_AUD_AUD1PLL_98M] = "top_aud1_pll_98M",
+   [MT2701_AUD_AUD2PLL_90M] = "top_aud2_pll_90M",
+   [MT2701_AUD_HADDS2PLL_98M] = "top_hadds2_pll_98M",
+   [MT2701_AUD_HADDS2PLL_294M] = "top_hadds2_pll_294M",
+   [MT2701_AUD_AUDPLL] = "top_audpll",
+   [MT2701_AUD_AUDPLL_D4] = "top_audpll_d4",
+   [MT2701_AUD_AUDPLL_D8] = "top_audpll_d8",
+   [MT2701_AUD_AUDPLL_D16] = "top_audpll_d16",
+   [MT2701_AUD_AUDPLL_D24] = "top_audpll_d24",
+   [MT2701_AUD_AUDINTBUS] = "top_audintbus_sel",
+   [MT2701_AUD_CLK_26M] = "clk_26m",
+   [MT2701_AUD_SYSPLL1_D4] = "top_syspll1_d4",
+   [MT2701_AUD_AUD_K1_SRC_SEL] = "top_aud_k1_src_sel",
+   [MT2701_AUD_AUD_K2_SRC_SEL] = "top_aud_k2_src_sel",
+   [MT2701_AUD_AUD_K3_SRC_SEL] = "top_aud_k3_src_sel",
+   [MT2701_AUD_AUD_K4_SRC_SEL] = "top_aud_k4_src_sel",
+   [MT2701_AUD_AUD_K5_SRC_SEL] = "top_aud_k5_src_sel",
+   [MT2701_AUD_AUD_K6_SRC_SEL] = "top_aud_k6_src_sel",
+   [MT2701_AUD_AUD_K1_SRC_DIV] = "top_aud_k1_src_div",
+   [MT2701_AUD_AUD_K2_SRC_DIV] = "top_aud_k2_src_div",
+   [MT2701_AUD_AUD_K3_SRC_DIV] = "top_aud_k3_src_div",
+   [MT2701_AUD_AUD_K4_SRC_DIV] = "top_aud_k4_src_div",
+   [MT2701_AUD_AUD_K5_SRC_DIV] = "top_aud_k5_src_div",
+   [MT2701_AUD_AUD_K6_SRC_DIV] = "top_aud_k6_src_div",
+   [MT2701_AUD_AUD_I2S1_MCLK] = "top_aud_i2s1_mclk",
+   [MT2701_AUD_AUD_I2S2_MCLK] = "top_aud_i2s2_mclk",
+   [MT2701_AUD_AUD_I2S3_MCLK] = "top_aud_i2s3_mclk",
+   [MT2701_AUD_AUD_I2S4_MCLK] = "top_aud_i2s4_mclk",
+   [MT2701_AUD_AUD_I2S5_MCLK] = "top_aud_i2s5_mclk",
+   [MT2701_AUD_AUD_I2S6_MCLK] = "top_aud_i2s6_mclk",
+   [MT2701_AUD_ASM_M_SEL] = "top_asm_m_sel",
+   [MT2701_AUD_ASM_H_SEL] = "top_asm_h_sel",
+   [MT2701_AUD_UNIVPLL2_D4] = "top_univpll2_d4",
+   [MT2701_AUD_UNIVPLL2_D2] = "top_univpll2_d2",
+   [MT2701_AUD_SYSPLL_D5] = "top_syspll_d5",
+};
+
+int mt2701_init_clock(struct mtk_base_afe *afe)
+{
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+   int i = 0;
+
+   for (i = 0; i < MT2701_CLOCK_NUM; i++) {
+   afe_priv->clocks[i] = devm_clk_get(afe->dev, aud_clks[i]);
+   if (IS_ERR(aud_clks[i])) {
+   dev_warn(afe->dev, 

[alsa-devel] [PATCH v5 0/9] ASoC: Mediatek: Add support for MT2701 SOC

2016-06-17 Thread Garlic Tseng
This patch adds basic support for Mediatek AFE for MT2701 SoC.
The patch is based on broonie tree "for-next" branch.

Change since v4:

* remove SND_SOC_MEDIATEK config prompt
* fix config prompt to meaningful one for SND_SOC_MT2701_CS42448
* remove some unnecessary random space change

Change since v3:

* fix comments style.

Change since v2:

* fix comments style.
* replace EXPORT_SYMBOL with EXPORT_SYMBOL_GPL
* reduce debug message
* move mutex lock for irq-allocated to AFE struct
* remove func mtk_simple_isr and call snd_pcm_period_elapsed directly
* mt2701 driver probe will fail if clock initial error
* fix dapm on/off switch control naming

Change since v1:

implement common private structure, fe dai and platform driver.
let mt8173 and mt2701 use the common structure.


Garlic Tseng (9):
  ASoC: mediatek: Refine mt8173 driver and change config option
  ASoC: mediatek: implement mediatek common structure
  ASoC: mediatek: let mt8173 use mediatek common structure
  ASoC: mediatek: add documents for mt2701
  ASoC: mediatek: add structure define and clock control for 2701
  ASoC: mediatek: add mt2701 platform driver implementation.
  ASoC: bt-sco: extend rate and add a general compatible string
  ASoC: mediatek: add BT implementation
  ASoC: mediatek: Add mt2701-cs42448 driver and config option.

 Documentation/devicetree/bindings/sound/bt-sco.txt |2 +-
 .../devicetree/bindings/sound/mt2701-afe-pcm.txt   |  150 ++
 .../devicetree/bindings/sound/mt2701-cs42448.txt   |   43 +
 sound/soc/codecs/bt-sco.c  |5 +-
 sound/soc/mediatek/Kconfig |   37 +-
 sound/soc/mediatek/Makefile|   10 +-
 sound/soc/mediatek/common/Makefile |   16 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.c |  379 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.h |   45 +
 .../soc/mediatek/common/mtk-afe-platform-driver.c  |   90 ++
 .../soc/mediatek/common/mtk-afe-platform-driver.h  |   23 +
 sound/soc/mediatek/common/mtk-base-afe.h   |  104 ++
 sound/soc/mediatek/mt2701/Makefile |   19 +
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c  |  464 ++
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h  |   38 +
 sound/soc/mediatek/mt2701/mt2701-afe-common.h  |  181 +++
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 1698 
 sound/soc/mediatek/mt2701/mt2701-cs42448.c |  422 +
 sound/soc/mediatek/mt2701/mt2701-reg.h |  186 +++
 sound/soc/mediatek/mt8173/Makefile |7 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h  |   73 +
 .../{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} |  921 +--
 sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c  |2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c   |2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c   |4 +-
 sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c|2 +-
 sound/soc/mediatek/mtk-afe-common.h|  101 --
 27 files changed, 4390 insertions(+), 634 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-cs42448.txt
 create mode 100644 sound/soc/mediatek/common/Makefile
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.h
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.h
 create mode 100644 sound/soc/mediatek/common/mtk-base-afe.h
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-common.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-reg.h
 create mode 100644 sound/soc/mediatek/mt8173/Makefile
 create mode 100644 sound/soc/mediatek/mt8173/mt8173-afe-common.h
 rename sound/soc/mediatek/{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} (51%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c (99%)
 delete mode 100644 sound/soc/mediatek/mtk-afe-common.h

-- 
1.9.1



[alsa-devel] [PATCH v5 8/9] ASoC: mediatek: add BT implementation

2016-06-17 Thread Garlic Tseng
Add BT implementation for mt2701 platform driver.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 139 +
 1 file changed, 139 insertions(+)

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
index deb5f82..5fd2caa 100644
--- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -377,6 +377,86 @@ static int mt2701_afe_i2s_set_fmt(struct snd_soc_dai *dai, 
unsigned int fmt)
return 0;
 }
 
+static int mt2701_btmrg_startup(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF, 0);
+
+   afe_priv->mrg_enable[substream->stream] = 1;
+   return 0;
+}
+
+static int mt2701_btmrg_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   int stream_fs;
+   u32 val, msk;
+
+   stream_fs = params_rate(params);
+
+   if ((stream_fs != 8000) && (stream_fs != 16000)) {
+   dev_err(afe->dev, "%s() btmgr not supprt this stream_fs %d\n",
+   __func__, stream_fs);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_I2S_MODE_MASK,
+  AFE_MRGIF_CON_I2S_MODE_32K);
+
+   val = AFE_DAIBT_CON0_BT_FUNC_EN | AFE_DAIBT_CON0_BT_FUNC_RDY
+ | AFE_DAIBT_CON0_MRG_USE;
+   msk = val;
+
+   if (stream_fs == 16000)
+   val |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   msk |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0, msk, val);
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN,
+  AFE_DAIBT_CON0_DAIBT_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN,
+  AFE_MRGIF_CON_MRG_I2S_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN,
+  AFE_MRGIF_CON_MRG_EN);
+   return 0;
+}
+
+static void mt2701_btmrg_shutdown(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   /* if the other direction stream is not occupied */
+   if (!afe_priv->mrg_enable[!substream->stream]) {
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN, 0);
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF,
+  AUDIO_TOP_CON4_PDN_MRGIF);
+   }
+   afe_priv->mrg_enable[substream->stream] = 0;
+}
+
 static int mt2701_simple_fe_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
 {
@@ -560,6 +640,13 @@ static const struct snd_soc_dai_ops mt2701_afe_i2s_ops = {
.set_fmt= mt2701_afe_i2s_set_fmt,
 };
 
+/* MRG BE DAIs */
+static struct snd_soc_dai_ops mt2701_btmrg_ops = {
+   .startup = mt2701_btmrg_startup,
+   .shutdown = mt2701_btmrg_shutdown,
+   .hw_params = mt2701_btmrg_hw_params,
+};
+
 static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
/* FE DAIs: memory intefaces to CPU */
{
@@ -610,6 +697,36 @@ static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
},
.ops = _single_memif_dai_ops,
},
+   {
+   .name = "PCM_BT_DL",
+   .id = MT2701_MEMIF_DLBT,
+   .suspend = mtk_afe_dai_suspend,
+   .resume = mtk_afe_dai_resume,
+   .playback = {
+ 

[alsa-devel] [PATCH v5 1/9] ASoC: mediatek: Refine mt8173 driver and change config option

2016-06-17 Thread Garlic Tseng
move mt8173 driver to another folder and add prefix.
add config option SND_SOC_MT8173

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/Kconfig |  14 +-
 sound/soc/mediatek/Makefile|   9 +-
 sound/soc/mediatek/mt8173/Makefile |   7 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h  | 101 +
 .../{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} | 494 ++---
 sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c  |   2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c   |   2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c   |   4 +-
 sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c|   2 +-
 sound/soc/mediatek/mtk-afe-common.h| 101 -
 10 files changed, 367 insertions(+), 369 deletions(-)
 create mode 100644 sound/soc/mediatek/mt8173/Makefile
 create mode 100644 sound/soc/mediatek/mt8173/mt8173-afe-common.h
 rename sound/soc/mediatek/{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} (66%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c (99%)
 delete mode 100644 sound/soc/mediatek/mtk-afe-common.h

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index 3abf51c..ae9f664 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,15 +1,15 @@
-config SND_SOC_MEDIATEK
-   tristate "ASoC support for Mediatek chip"
+config SND_SOC_MT8173
+   tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
help
- This adds ASoC platform driver support for Mediatek chip
+ This adds ASoC platform driver support for Mediatek MT8173 chip
  that can be used with other codecs.
  Select Y if you have such device.
  Ex: MT8173
 
 config SND_SOC_MT8173_MAX98090
tristate "ASoC Audio driver for MT8173 with MAX98090 codec"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_MAX98090
help
  This adds ASoC driver for Mediatek MT8173 boards
@@ -19,7 +19,7 @@ config SND_SOC_MT8173_MAX98090
 
 config SND_SOC_MT8173_RT5650
tristate "ASoC Audio driver for MT8173 with RT5650 codec"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
help
  This adds ASoC driver for Mediatek MT8173 boards
@@ -29,7 +29,7 @@ config SND_SOC_MT8173_RT5650
 
 config SND_SOC_MT8173_RT5650_RT5514
tristate "ASoC Audio driver for MT8173 with RT5650 RT5514 codecs"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
select SND_SOC_RT5514
help
@@ -40,7 +40,7 @@ config SND_SOC_MT8173_RT5650_RT5514
 
 config SND_SOC_MT8173_RT5650_RT5676
tristate "ASoC Audio driver for MT8173 with RT5650 RT5676 codecs"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
select SND_SOC_RT5677
select SND_SOC_HDMI_CODEC
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index d486860..240dfc70 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,7 +1,2 @@
-# MTK Platform Support
-obj-$(CONFIG_SND_SOC_MEDIATEK) += mtk-afe-pcm.o
-# Machine support
-obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650) += mt8173-rt5650.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5514) += mt8173-rt5650-rt5514.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5676) += mt8173-rt5650-rt5676.o
+# 8173 Machine support
+obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
diff --git a/sound/soc/mediatek/mt8173/Makefile 
b/sound/soc/mediatek/mt8173/Makefile
new file mode 100644
index 000..0357b27
--- /dev/null
+++ b/sound/soc/mediatek/mt8173/Makefile
@@ -0,0 +1,7 @@
+# MTK Platform Support
+obj-$(CONFIG_SND_SOC_MT8173) += mt8173-afe-pcm.o
+# Machine support
+obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650) += mt8173-rt5650.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5514) += mt8173-rt5650-rt5514.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5676) += mt8173-rt5650-rt5676.o
diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-common.h 
b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
new file mode 100644
index 000..8f2936d
--- /dev/null
+++ b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
@@ -0,0 +1,101 @@
+/*
+ * mt8173_afe_common.h  --  Mediatek 8173 audio driver common definitions
+ *
+ * Copyright (c) 2015 MediaTek Inc.
+ * Author: Koro Chen <koro.c...@mediatek.

[alsa-devel] [PATCH v5 0/9] ASoC: Mediatek: Add support for MT2701 SOC

2016-06-17 Thread Garlic Tseng
This patch adds basic support for Mediatek AFE for MT2701 SoC.
The patch is based on broonie tree "for-next" branch.

Change since v4:

* remove SND_SOC_MEDIATEK config prompt
* fix config prompt to meaningful one for SND_SOC_MT2701_CS42448
* remove some unnecessary random space change

Change since v3:

* fix comments style.

Change since v2:

* fix comments style.
* replace EXPORT_SYMBOL with EXPORT_SYMBOL_GPL
* reduce debug message
* move mutex lock for irq-allocated to AFE struct
* remove func mtk_simple_isr and call snd_pcm_period_elapsed directly
* mt2701 driver probe will fail if clock initial error
* fix dapm on/off switch control naming

Change since v1:

implement common private structure, fe dai and platform driver.
let mt8173 and mt2701 use the common structure.


Garlic Tseng (9):
  ASoC: mediatek: Refine mt8173 driver and change config option
  ASoC: mediatek: implement mediatek common structure
  ASoC: mediatek: let mt8173 use mediatek common structure
  ASoC: mediatek: add documents for mt2701
  ASoC: mediatek: add structure define and clock control for 2701
  ASoC: mediatek: add mt2701 platform driver implementation.
  ASoC: bt-sco: extend rate and add a general compatible string
  ASoC: mediatek: add BT implementation
  ASoC: mediatek: Add mt2701-cs42448 driver and config option.

 Documentation/devicetree/bindings/sound/bt-sco.txt |2 +-
 .../devicetree/bindings/sound/mt2701-afe-pcm.txt   |  150 ++
 .../devicetree/bindings/sound/mt2701-cs42448.txt   |   43 +
 sound/soc/codecs/bt-sco.c  |5 +-
 sound/soc/mediatek/Kconfig |   37 +-
 sound/soc/mediatek/Makefile|   10 +-
 sound/soc/mediatek/common/Makefile |   16 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.c |  379 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.h |   45 +
 .../soc/mediatek/common/mtk-afe-platform-driver.c  |   90 ++
 .../soc/mediatek/common/mtk-afe-platform-driver.h  |   23 +
 sound/soc/mediatek/common/mtk-base-afe.h   |  104 ++
 sound/soc/mediatek/mt2701/Makefile |   19 +
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c  |  464 ++
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h  |   38 +
 sound/soc/mediatek/mt2701/mt2701-afe-common.h  |  181 +++
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 1698 
 sound/soc/mediatek/mt2701/mt2701-cs42448.c |  422 +
 sound/soc/mediatek/mt2701/mt2701-reg.h |  186 +++
 sound/soc/mediatek/mt8173/Makefile |7 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h  |   73 +
 .../{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} |  921 +--
 sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c  |2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c   |2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c   |4 +-
 sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c|2 +-
 sound/soc/mediatek/mtk-afe-common.h|  101 --
 27 files changed, 4390 insertions(+), 634 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-cs42448.txt
 create mode 100644 sound/soc/mediatek/common/Makefile
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.h
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.h
 create mode 100644 sound/soc/mediatek/common/mtk-base-afe.h
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-common.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-reg.h
 create mode 100644 sound/soc/mediatek/mt8173/Makefile
 create mode 100644 sound/soc/mediatek/mt8173/mt8173-afe-common.h
 rename sound/soc/mediatek/{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} (51%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c (99%)
 delete mode 100644 sound/soc/mediatek/mtk-afe-common.h

-- 
1.9.1



[alsa-devel] [PATCH v5 8/9] ASoC: mediatek: add BT implementation

2016-06-17 Thread Garlic Tseng
Add BT implementation for mt2701 platform driver.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 139 +
 1 file changed, 139 insertions(+)

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
index deb5f82..5fd2caa 100644
--- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -377,6 +377,86 @@ static int mt2701_afe_i2s_set_fmt(struct snd_soc_dai *dai, 
unsigned int fmt)
return 0;
 }
 
+static int mt2701_btmrg_startup(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF, 0);
+
+   afe_priv->mrg_enable[substream->stream] = 1;
+   return 0;
+}
+
+static int mt2701_btmrg_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   int stream_fs;
+   u32 val, msk;
+
+   stream_fs = params_rate(params);
+
+   if ((stream_fs != 8000) && (stream_fs != 16000)) {
+   dev_err(afe->dev, "%s() btmgr not supprt this stream_fs %d\n",
+   __func__, stream_fs);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_I2S_MODE_MASK,
+  AFE_MRGIF_CON_I2S_MODE_32K);
+
+   val = AFE_DAIBT_CON0_BT_FUNC_EN | AFE_DAIBT_CON0_BT_FUNC_RDY
+ | AFE_DAIBT_CON0_MRG_USE;
+   msk = val;
+
+   if (stream_fs == 16000)
+   val |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   msk |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0, msk, val);
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN,
+  AFE_DAIBT_CON0_DAIBT_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN,
+  AFE_MRGIF_CON_MRG_I2S_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN,
+  AFE_MRGIF_CON_MRG_EN);
+   return 0;
+}
+
+static void mt2701_btmrg_shutdown(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   /* if the other direction stream is not occupied */
+   if (!afe_priv->mrg_enable[!substream->stream]) {
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN, 0);
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF,
+  AUDIO_TOP_CON4_PDN_MRGIF);
+   }
+   afe_priv->mrg_enable[substream->stream] = 0;
+}
+
 static int mt2701_simple_fe_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
 {
@@ -560,6 +640,13 @@ static const struct snd_soc_dai_ops mt2701_afe_i2s_ops = {
.set_fmt= mt2701_afe_i2s_set_fmt,
 };
 
+/* MRG BE DAIs */
+static struct snd_soc_dai_ops mt2701_btmrg_ops = {
+   .startup = mt2701_btmrg_startup,
+   .shutdown = mt2701_btmrg_shutdown,
+   .hw_params = mt2701_btmrg_hw_params,
+};
+
 static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
/* FE DAIs: memory intefaces to CPU */
{
@@ -610,6 +697,36 @@ static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
},
.ops = _single_memif_dai_ops,
},
+   {
+   .name = "PCM_BT_DL",
+   .id = MT2701_MEMIF_DLBT,
+   .suspend = mtk_afe_dai_suspend,
+   .resume = mtk_afe_dai_resume,
+   .playback = {
+   .stream_name = "DLBT",
+  

[alsa-devel] [PATCH v5 1/9] ASoC: mediatek: Refine mt8173 driver and change config option

2016-06-17 Thread Garlic Tseng
move mt8173 driver to another folder and add prefix.
add config option SND_SOC_MT8173

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/Kconfig |  14 +-
 sound/soc/mediatek/Makefile|   9 +-
 sound/soc/mediatek/mt8173/Makefile |   7 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h  | 101 +
 .../{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} | 494 ++---
 sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c  |   2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c   |   2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c   |   4 +-
 sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c|   2 +-
 sound/soc/mediatek/mtk-afe-common.h| 101 -
 10 files changed, 367 insertions(+), 369 deletions(-)
 create mode 100644 sound/soc/mediatek/mt8173/Makefile
 create mode 100644 sound/soc/mediatek/mt8173/mt8173-afe-common.h
 rename sound/soc/mediatek/{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} (66%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c (99%)
 delete mode 100644 sound/soc/mediatek/mtk-afe-common.h

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index 3abf51c..ae9f664 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,15 +1,15 @@
-config SND_SOC_MEDIATEK
-   tristate "ASoC support for Mediatek chip"
+config SND_SOC_MT8173
+   tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
help
- This adds ASoC platform driver support for Mediatek chip
+ This adds ASoC platform driver support for Mediatek MT8173 chip
  that can be used with other codecs.
  Select Y if you have such device.
  Ex: MT8173
 
 config SND_SOC_MT8173_MAX98090
tristate "ASoC Audio driver for MT8173 with MAX98090 codec"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_MAX98090
help
  This adds ASoC driver for Mediatek MT8173 boards
@@ -19,7 +19,7 @@ config SND_SOC_MT8173_MAX98090
 
 config SND_SOC_MT8173_RT5650
tristate "ASoC Audio driver for MT8173 with RT5650 codec"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
help
  This adds ASoC driver for Mediatek MT8173 boards
@@ -29,7 +29,7 @@ config SND_SOC_MT8173_RT5650
 
 config SND_SOC_MT8173_RT5650_RT5514
tristate "ASoC Audio driver for MT8173 with RT5650 RT5514 codecs"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
select SND_SOC_RT5514
help
@@ -40,7 +40,7 @@ config SND_SOC_MT8173_RT5650_RT5514
 
 config SND_SOC_MT8173_RT5650_RT5676
tristate "ASoC Audio driver for MT8173 with RT5650 RT5676 codecs"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
select SND_SOC_RT5677
select SND_SOC_HDMI_CODEC
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index d486860..240dfc70 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,7 +1,2 @@
-# MTK Platform Support
-obj-$(CONFIG_SND_SOC_MEDIATEK) += mtk-afe-pcm.o
-# Machine support
-obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650) += mt8173-rt5650.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5514) += mt8173-rt5650-rt5514.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5676) += mt8173-rt5650-rt5676.o
+# 8173 Machine support
+obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
diff --git a/sound/soc/mediatek/mt8173/Makefile 
b/sound/soc/mediatek/mt8173/Makefile
new file mode 100644
index 000..0357b27
--- /dev/null
+++ b/sound/soc/mediatek/mt8173/Makefile
@@ -0,0 +1,7 @@
+# MTK Platform Support
+obj-$(CONFIG_SND_SOC_MT8173) += mt8173-afe-pcm.o
+# Machine support
+obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650) += mt8173-rt5650.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5514) += mt8173-rt5650-rt5514.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5676) += mt8173-rt5650-rt5676.o
diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-common.h 
b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
new file mode 100644
index 000..8f2936d
--- /dev/null
+++ b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
@@ -0,0 +1,101 @@
+/*
+ * mt8173_afe_common.h  --  Mediatek 8173 audio driver common definitions
+ *
+ * Copyright (c) 2015 MediaTek Inc.
+ * Author: Koro Chen 
+ * Sascha Hauer 
+ * Hidalgo Huang 
+ * 

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

2016-06-15 Thread Garlic Tseng
Hi Yingjoe, thanks for comments.

> > +config SND_SOC_MEDIATEK
> > +   tristate "SND_SOC_MEDIATEK"
> > +   depends on ARCH_MEDIATEK
> > +   help
> > + This adds ASoC driver for Mediatek boards
> > + that can be used with other codecs.
> > + Select Y if you have such device.
> > + If unsure select "N".
> > +
> >  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.
> 
> It seems both SND_SOC_MT8173 and SND_SOC_MT2701 select SND_SOC_MEDIATEK,
> and enabling only SND_SOC_MEDIATEK itself is not really useful. Do we
> need to make SND_SOC_MEDIATEK user configurable option?

I'll make the config not user configurable, something like:

+config SND_SOC_MEDIATEK
+   tristate

> 
> If it is, we should at least have a proper config prompt instead of just
> "SND_SOC_MEDIATEK".
> 
> 
> > @@ -49,3 +59,4 @@ config SND_SOC_MT8173_RT5650_RT5676
> >   with the RT5650 and RT5676 codecs.
> >   Select Y if you have such device.
> >   If unsure select "N".
> > +
> 
> nit: This change is not necessary.

I'll fix it, thanks.

> 
> Joe.C
> 
> 




Re: [alsa-devel] [PATCH v4 9/9] ASoC: mediatek: Add mt2701-cs42448 driver and config option.

2016-06-15 Thread Garlic Tseng
On Wed, 2016-06-15 at 18:58 +0800, Yingjoe Chen wrote:
> On Mon, 2016-06-13 at 15:26 +0800, Garlic Tseng wrote:
> > +config SND_SOC_MT2701_CS42448
> > +   tristate "SND_SOC_MT2701_CS42448"
> 
> Please provide proper config prompt here.

OK I'll fix it. Thanks.

> Joe.C
> 
> 




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

2016-06-15 Thread Garlic Tseng
Hi Yingjoe, thanks for comments.

> > +config SND_SOC_MEDIATEK
> > +   tristate "SND_SOC_MEDIATEK"
> > +   depends on ARCH_MEDIATEK
> > +   help
> > + This adds ASoC driver for Mediatek boards
> > + that can be used with other codecs.
> > + Select Y if you have such device.
> > + If unsure select "N".
> > +
> >  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.
> 
> It seems both SND_SOC_MT8173 and SND_SOC_MT2701 select SND_SOC_MEDIATEK,
> and enabling only SND_SOC_MEDIATEK itself is not really useful. Do we
> need to make SND_SOC_MEDIATEK user configurable option?

I'll make the config not user configurable, something like:

+config SND_SOC_MEDIATEK
+   tristate

> 
> If it is, we should at least have a proper config prompt instead of just
> "SND_SOC_MEDIATEK".
> 
> 
> > @@ -49,3 +59,4 @@ config SND_SOC_MT8173_RT5650_RT5676
> >   with the RT5650 and RT5676 codecs.
> >   Select Y if you have such device.
> >   If unsure select "N".
> > +
> 
> nit: This change is not necessary.

I'll fix it, thanks.

> 
> Joe.C
> 
> 




Re: [alsa-devel] [PATCH v4 9/9] ASoC: mediatek: Add mt2701-cs42448 driver and config option.

2016-06-15 Thread Garlic Tseng
On Wed, 2016-06-15 at 18:58 +0800, Yingjoe Chen wrote:
> On Mon, 2016-06-13 at 15:26 +0800, Garlic Tseng wrote:
> > +config SND_SOC_MT2701_CS42448
> > +   tristate "SND_SOC_MT2701_CS42448"
> 
> Please provide proper config prompt here.

OK I'll fix it. Thanks.

> Joe.C
> 
> 




[alsa-devel] [PATCH v4 0/9] ASoC: Mediatek: Add support for MT2701 SOC

2016-06-13 Thread Garlic Tseng
Sorry for submitting new version in a short time.
I find some comment style error and fix it.
please ignore v3 and directly review v4.

This patch adds basic support for Mediatek AFE for MT2701 SoC.
The patch is based on broonie tree "for-next" branch.

Change since v3:

* fix comments style.

Change since v2:

* fix comments style.
* replace EXPORT_SYMBOL with EXPORT_SYMBOL_GPL
* reduce debug message
* move mutex lock for irq-allocated to AFE struct
* remove func mtk_simple_isr and call snd_pcm_period_elapsed directly
* mt2701 driver probe will fail if clock initial error
* fix dapm on/off switch control naming

Change since v1:

implement common private structure, fe dai and platform driver.
let mt8173 and mt2701 use the common structure.


Garlic Tseng (9):
  ASoC: mediatek: Refine mt8173 driver and change config option
  ASoC: mediatek: implement mediatek common structure
  ASoC: mediatek: let mt8173 use mediatek common structure
  ASoC: mediatek: add documents for mt2701
  ASoC: mediatek: add structure define and clock control for 2701
  ASoC: mediatek: add mt2701 platform driver implementation.
  ASoC: bt-sco: extend rate and add a general compatible string
  ASoC: mediatek: add BT implementation
  ASoC: mediatek: Add mt2701-cs42448 driver and config option.

 Documentation/devicetree/bindings/sound/bt-sco.txt |2 +-
 .../devicetree/bindings/sound/mt2701-afe-pcm.txt   |  150 ++
 .../devicetree/bindings/sound/mt2701-cs42448.txt   |   43 +
 sound/soc/codecs/bt-sco.c  |5 +-
 sound/soc/mediatek/Kconfig |   44 +-
 sound/soc/mediatek/Makefile|   11 +-
 sound/soc/mediatek/common/Makefile |   17 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.c |  379 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.h |   45 +
 .../soc/mediatek/common/mtk-afe-platform-driver.c  |   90 ++
 .../soc/mediatek/common/mtk-afe-platform-driver.h  |   23 +
 sound/soc/mediatek/common/mtk-base-afe.h   |  104 ++
 sound/soc/mediatek/mt2701/Makefile |   19 +
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c  |  464 ++
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h  |   38 +
 sound/soc/mediatek/mt2701/mt2701-afe-common.h  |  181 +++
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 1698 
 sound/soc/mediatek/mt2701/mt2701-cs42448.c |  422 +
 sound/soc/mediatek/mt2701/mt2701-reg.h |  186 +++
 sound/soc/mediatek/mt8173/Makefile |7 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h  |   73 +
 .../{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} |  921 +--
 sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c  |2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c   |2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c   |4 +-
 sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c|2 +-
 sound/soc/mediatek/mtk-afe-common.h|  101 --
 27 files changed, 4399 insertions(+), 634 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-cs42448.txt
 create mode 100644 sound/soc/mediatek/common/Makefile
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.h
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.h
 create mode 100644 sound/soc/mediatek/common/mtk-base-afe.h
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-common.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-reg.h
 create mode 100644 sound/soc/mediatek/mt8173/Makefile
 create mode 100644 sound/soc/mediatek/mt8173/mt8173-afe-common.h
 rename sound/soc/mediatek/{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} (51%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c (99%)
 delete mode 100644 sound/soc/mediatek/mtk-afe-common.h

-- 
1.9.1



[alsa-devel] [PATCH v4 0/9] ASoC: Mediatek: Add support for MT2701 SOC

2016-06-13 Thread Garlic Tseng
Sorry for submitting new version in a short time.
I find some comment style error and fix it.
please ignore v3 and directly review v4.

This patch adds basic support for Mediatek AFE for MT2701 SoC.
The patch is based on broonie tree "for-next" branch.

Change since v3:

* fix comments style.

Change since v2:

* fix comments style.
* replace EXPORT_SYMBOL with EXPORT_SYMBOL_GPL
* reduce debug message
* move mutex lock for irq-allocated to AFE struct
* remove func mtk_simple_isr and call snd_pcm_period_elapsed directly
* mt2701 driver probe will fail if clock initial error
* fix dapm on/off switch control naming

Change since v1:

implement common private structure, fe dai and platform driver.
let mt8173 and mt2701 use the common structure.


Garlic Tseng (9):
  ASoC: mediatek: Refine mt8173 driver and change config option
  ASoC: mediatek: implement mediatek common structure
  ASoC: mediatek: let mt8173 use mediatek common structure
  ASoC: mediatek: add documents for mt2701
  ASoC: mediatek: add structure define and clock control for 2701
  ASoC: mediatek: add mt2701 platform driver implementation.
  ASoC: bt-sco: extend rate and add a general compatible string
  ASoC: mediatek: add BT implementation
  ASoC: mediatek: Add mt2701-cs42448 driver and config option.

 Documentation/devicetree/bindings/sound/bt-sco.txt |2 +-
 .../devicetree/bindings/sound/mt2701-afe-pcm.txt   |  150 ++
 .../devicetree/bindings/sound/mt2701-cs42448.txt   |   43 +
 sound/soc/codecs/bt-sco.c  |5 +-
 sound/soc/mediatek/Kconfig |   44 +-
 sound/soc/mediatek/Makefile|   11 +-
 sound/soc/mediatek/common/Makefile |   17 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.c |  379 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.h |   45 +
 .../soc/mediatek/common/mtk-afe-platform-driver.c  |   90 ++
 .../soc/mediatek/common/mtk-afe-platform-driver.h  |   23 +
 sound/soc/mediatek/common/mtk-base-afe.h   |  104 ++
 sound/soc/mediatek/mt2701/Makefile |   19 +
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c  |  464 ++
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h  |   38 +
 sound/soc/mediatek/mt2701/mt2701-afe-common.h  |  181 +++
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 1698 
 sound/soc/mediatek/mt2701/mt2701-cs42448.c |  422 +
 sound/soc/mediatek/mt2701/mt2701-reg.h |  186 +++
 sound/soc/mediatek/mt8173/Makefile |7 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h  |   73 +
 .../{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} |  921 +--
 sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c  |2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c   |2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c   |4 +-
 sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c|2 +-
 sound/soc/mediatek/mtk-afe-common.h|  101 --
 27 files changed, 4399 insertions(+), 634 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-cs42448.txt
 create mode 100644 sound/soc/mediatek/common/Makefile
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.h
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.h
 create mode 100644 sound/soc/mediatek/common/mtk-base-afe.h
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-common.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-reg.h
 create mode 100644 sound/soc/mediatek/mt8173/Makefile
 create mode 100644 sound/soc/mediatek/mt8173/mt8173-afe-common.h
 rename sound/soc/mediatek/{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} (51%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c (99%)
 delete mode 100644 sound/soc/mediatek/mtk-afe-common.h

-- 
1.9.1



[alsa-devel] [PATCH v4 9/9] ASoC: mediatek: Add mt2701-cs42448 driver and config option.

2016-06-13 Thread Garlic Tseng
Add machine driver and config option for MT2701.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/Kconfig |  21 ++
 sound/soc/mediatek/Makefile|   1 +
 sound/soc/mediatek/mt2701/Makefile |  19 ++
 sound/soc/mediatek/mt2701/mt2701-cs42448.c | 422 +
 4 files changed, 463 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index ff1a419..0ecb785 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -7,6 +7,27 @@ config SND_SOC_MEDIATEK
  Select Y if you have such device.
  If unsure select "N".
 
+config SND_SOC_MT2701
+   tristate "ASoC support for Mediatek MT2701 chip"
+   depends on ARCH_MEDIATEK
+   select SND_SOC_MEDIATEK
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ that can be used with other codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
+config SND_SOC_MT2701_CS42448
+   tristate "SND_SOC_MT2701_CS42448"
+   depends on SND_SOC_MT2701
+   select SND_SOC_CS42XX8_I2C
+   select SND_SOC_BT_SCO
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ with the CS42448 codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
 config SND_SOC_MT8173
tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index 3d893be..5133215 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,3 +1,4 @@
 obj-$(CONFIG_SND_SOC_MEDIATEK) += common/
+obj-$(CONFIG_SND_SOC_MT2701) += mt2701/
 obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
 
diff --git a/sound/soc/mediatek/mt2701/Makefile 
b/sound/soc/mediatek/mt2701/Makefile
new file mode 100644
index 000..31c3d04
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/Makefile
@@ -0,0 +1,19 @@
+#
+# 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-mt2701-afe-objs := mt2701-afe-pcm.o mt2701-afe-clock-ctrl.o
+obj-$(CONFIG_SND_SOC_MT2701) += snd-soc-mt2701-afe.o
+
+# machine driver
+obj-$(CONFIG_SND_SOC_MT2701_CS42448) += mt2701-cs42448.o
diff --git a/sound/soc/mediatek/mt2701/mt2701-cs42448.c 
b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
new file mode 100644
index 000..0e48cb9
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
@@ -0,0 +1,422 @@
+/*
+ * mt2701-cs42448.c  --  MT2701 CS42448 ALSA SoC machine driver
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Ir Lian <ir.l...@mediatek.com>
+ *  Garlic Tseng <garlic.ts...@mediatek.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+struct mt2701_cs42448_private {
+   int i2s1_in_mux;
+   int i2s1_in_mux_gpio_sel_1;
+   int i2s1_in_mux_gpio_sel_2;
+};
+
+static const char * const i2sin_mux_switch_text[] = {
+   "ADC_SDOUT2",
+   "ADC_SDOUT3",
+   "I2S_IN_1",
+   "I2S_IN_2",
+};
+
+static const struct soc_enum i2sin_mux_enum =
+   SOC_ENUM_SINGLE_EXT(4, i2sin_mux_switch_text);
+
+static int mt2701_cs42448_i2sin1_mux_get(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card);
+
+   ucontrol->value.integer.value[0] = priv->i2s1_in_mux;
+   return 0;
+}
+
+static int mt2701_cs42448_i2sin1_mux_set(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private

[alsa-devel] [PATCH v4 9/9] ASoC: mediatek: Add mt2701-cs42448 driver and config option.

2016-06-13 Thread Garlic Tseng
Add machine driver and config option for MT2701.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/Kconfig |  21 ++
 sound/soc/mediatek/Makefile|   1 +
 sound/soc/mediatek/mt2701/Makefile |  19 ++
 sound/soc/mediatek/mt2701/mt2701-cs42448.c | 422 +
 4 files changed, 463 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index ff1a419..0ecb785 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -7,6 +7,27 @@ config SND_SOC_MEDIATEK
  Select Y if you have such device.
  If unsure select "N".
 
+config SND_SOC_MT2701
+   tristate "ASoC support for Mediatek MT2701 chip"
+   depends on ARCH_MEDIATEK
+   select SND_SOC_MEDIATEK
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ that can be used with other codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
+config SND_SOC_MT2701_CS42448
+   tristate "SND_SOC_MT2701_CS42448"
+   depends on SND_SOC_MT2701
+   select SND_SOC_CS42XX8_I2C
+   select SND_SOC_BT_SCO
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ with the CS42448 codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
 config SND_SOC_MT8173
tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index 3d893be..5133215 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,3 +1,4 @@
 obj-$(CONFIG_SND_SOC_MEDIATEK) += common/
+obj-$(CONFIG_SND_SOC_MT2701) += mt2701/
 obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
 
diff --git a/sound/soc/mediatek/mt2701/Makefile 
b/sound/soc/mediatek/mt2701/Makefile
new file mode 100644
index 000..31c3d04
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/Makefile
@@ -0,0 +1,19 @@
+#
+# 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-mt2701-afe-objs := mt2701-afe-pcm.o mt2701-afe-clock-ctrl.o
+obj-$(CONFIG_SND_SOC_MT2701) += snd-soc-mt2701-afe.o
+
+# machine driver
+obj-$(CONFIG_SND_SOC_MT2701_CS42448) += mt2701-cs42448.o
diff --git a/sound/soc/mediatek/mt2701/mt2701-cs42448.c 
b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
new file mode 100644
index 000..0e48cb9
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
@@ -0,0 +1,422 @@
+/*
+ * mt2701-cs42448.c  --  MT2701 CS42448 ALSA SoC machine driver
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Ir Lian 
+ *  Garlic Tseng 
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+struct mt2701_cs42448_private {
+   int i2s1_in_mux;
+   int i2s1_in_mux_gpio_sel_1;
+   int i2s1_in_mux_gpio_sel_2;
+};
+
+static const char * const i2sin_mux_switch_text[] = {
+   "ADC_SDOUT2",
+   "ADC_SDOUT3",
+   "I2S_IN_1",
+   "I2S_IN_2",
+};
+
+static const struct soc_enum i2sin_mux_enum =
+   SOC_ENUM_SINGLE_EXT(4, i2sin_mux_switch_text);
+
+static int mt2701_cs42448_i2sin1_mux_get(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card);
+
+   ucontrol->value.integer.value[0] = priv->i2s1_in_mux;
+   return 0;
+}
+
+static int mt2701_cs42448_i2sin1_mux_set(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card);
+
+   if (ucontrol->value.integer.value[

[alsa-devel] [PATCH v4 5/9] ASoC: mediatek: add structure define and clock control for 2701

2016-06-13 Thread Garlic Tseng
add structure define and clock control function for 2701.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c | 464 ++
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h |  38 ++
 sound/soc/mediatek/mt2701/mt2701-afe-common.h | 181 +
 sound/soc/mediatek/mt2701/mt2701-reg.h| 186 +
 4 files changed, 869 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-common.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-reg.h

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
new file mode 100644
index 000..b815ecc
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
@@ -0,0 +1,464 @@
+/*
+ * mt2701-afe-clock-ctrl.c  --  Mediatek 2701 afe clock ctrl
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng <garlic.ts...@mediatek.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+#include "mt2701-afe-clock-ctrl.h"
+
+static const char *aud_clks[MT2701_CLOCK_NUM] = {
+   [MT2701_AUD_INFRA_SYS_AUDIO] = "infra_sys_audio_clk",
+   [MT2701_AUD_AUD_MUX1_SEL] = "top_audio_mux1_sel",
+   [MT2701_AUD_AUD_MUX2_SEL] = "top_audio_mux2_sel",
+   [MT2701_AUD_AUD_MUX1_DIV] = "top_audio_mux1_div",
+   [MT2701_AUD_AUD_MUX2_DIV] = "top_audio_mux2_div",
+   [MT2701_AUD_AUD_48K_TIMING] = "top_audio_48k_timing",
+   [MT2701_AUD_AUD_44K_TIMING] = "top_audio_44k_timing",
+   [MT2701_AUD_AUDPLL_MUX_SEL] = "top_audpll_mux_sel",
+   [MT2701_AUD_APLL_SEL] = "top_apll_sel",
+   [MT2701_AUD_AUD1PLL_98M] = "top_aud1_pll_98M",
+   [MT2701_AUD_AUD2PLL_90M] = "top_aud2_pll_90M",
+   [MT2701_AUD_HADDS2PLL_98M] = "top_hadds2_pll_98M",
+   [MT2701_AUD_HADDS2PLL_294M] = "top_hadds2_pll_294M",
+   [MT2701_AUD_AUDPLL] = "top_audpll",
+   [MT2701_AUD_AUDPLL_D4] = "top_audpll_d4",
+   [MT2701_AUD_AUDPLL_D8] = "top_audpll_d8",
+   [MT2701_AUD_AUDPLL_D16] = "top_audpll_d16",
+   [MT2701_AUD_AUDPLL_D24] = "top_audpll_d24",
+   [MT2701_AUD_AUDINTBUS] = "top_audintbus_sel",
+   [MT2701_AUD_CLK_26M] = "clk_26m",
+   [MT2701_AUD_SYSPLL1_D4] = "top_syspll1_d4",
+   [MT2701_AUD_AUD_K1_SRC_SEL] = "top_aud_k1_src_sel",
+   [MT2701_AUD_AUD_K2_SRC_SEL] = "top_aud_k2_src_sel",
+   [MT2701_AUD_AUD_K3_SRC_SEL] = "top_aud_k3_src_sel",
+   [MT2701_AUD_AUD_K4_SRC_SEL] = "top_aud_k4_src_sel",
+   [MT2701_AUD_AUD_K5_SRC_SEL] = "top_aud_k5_src_sel",
+   [MT2701_AUD_AUD_K6_SRC_SEL] = "top_aud_k6_src_sel",
+   [MT2701_AUD_AUD_K1_SRC_DIV] = "top_aud_k1_src_div",
+   [MT2701_AUD_AUD_K2_SRC_DIV] = "top_aud_k2_src_div",
+   [MT2701_AUD_AUD_K3_SRC_DIV] = "top_aud_k3_src_div",
+   [MT2701_AUD_AUD_K4_SRC_DIV] = "top_aud_k4_src_div",
+   [MT2701_AUD_AUD_K5_SRC_DIV] = "top_aud_k5_src_div",
+   [MT2701_AUD_AUD_K6_SRC_DIV] = "top_aud_k6_src_div",
+   [MT2701_AUD_AUD_I2S1_MCLK] = "top_aud_i2s1_mclk",
+   [MT2701_AUD_AUD_I2S2_MCLK] = "top_aud_i2s2_mclk",
+   [MT2701_AUD_AUD_I2S3_MCLK] = "top_aud_i2s3_mclk",
+   [MT2701_AUD_AUD_I2S4_MCLK] = "top_aud_i2s4_mclk",
+   [MT2701_AUD_AUD_I2S5_MCLK] = "top_aud_i2s5_mclk",
+   [MT2701_AUD_AUD_I2S6_MCLK] = "top_aud_i2s6_mclk",
+   [MT2701_AUD_ASM_M_SEL] = "top_asm_m_sel",
+   [MT2701_AUD_ASM_H_SEL] = "top_asm_h_sel",
+   [MT2701_AUD_UNIVPLL2_D4] = "top_univpll2_d4",
+   [MT2701_AUD_UNIVPLL2_D2] = "top_univpll2_d2",
+   [MT2701_AUD_SYSPLL_D5] = "top_syspll_d5",
+};
+
+int mt2701_init_clock(struct mtk_base_afe *afe)
+{
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+   int i = 0;
+
+   for (i = 0; i < MT2701_CLOCK_NUM; i++) {
+   afe_priv->clocks[i] = devm_clk_get(afe->dev, aud_clks[i]);
+   

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

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

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/Kconfig|  11 +
 sound/soc/mediatek/Makefile   |   3 +-
 sound/soc/mediatek/common/Makefile|  17 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h |  42 +-
 sound/soc/mediatek/mt8173/mt8173-afe-pcm.c| 679 +++---
 5 files changed, 327 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..ff1a419 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,6 +1,16 @@
+config SND_SOC_MEDIATEK
+   tristate "SND_SOC_MEDIATEK"
+   depends on ARCH_MEDIATEK
+   help
+ This adds ASoC driver for Mediatek boards
+ that can be used with other codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
 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.
@@ -49,3 +59,4 @@ config SND_SOC_MT8173_RT5650_RT5676
  with the RT5650 and RT5676 codecs.
  Select Y if you have such device.
  If unsure select "N".
+
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index 240dfc70..3d893be 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,2 +1,3 @@
-# 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..0fcd921
--- /dev/null
+++ b/sound/soc/mediatek/common/Makefile
@@ -0,0 +1,17 @@
+#
+# 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 mt817

[alsa-devel] [PATCH v4 2/9] ASoC: mediatek: implement mediatek common structure

2016-06-13 Thread Garlic Tseng
implement mediatek basic structure, include common private data,
afe fe dai operator and afe platform driver.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/common/mtk-afe-fe-dai.c | 379 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.h |  45 +++
 .../soc/mediatek/common/mtk-afe-platform-driver.c  |  90 +
 .../soc/mediatek/common/mtk-afe-platform-driver.h  |  23 ++
 sound/soc/mediatek/common/mtk-base-afe.h   | 104 ++
 5 files changed, 641 insertions(+)
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.h
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.h
 create mode 100644 sound/soc/mediatek/common/mtk-base-afe.h

diff --git a/sound/soc/mediatek/common/mtk-afe-fe-dai.c 
b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
new file mode 100644
index 000..b788791b
--- /dev/null
+++ b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
@@ -0,0 +1,379 @@
+/*
+ * mtk-afe-fe-dais.c  --  Mediatek afe fe dai operator
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng <garlic.ts...@mediatek.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "mtk-afe-fe-dai.h"
+#include "mtk-base-afe.h"
+
+#define AFE_BASE_END_OFFSET 8
+
+int mtk_regmap_update_bits(struct regmap *map, int reg, unsigned int mask,
+  unsigned int val)
+{
+   if (reg < 0)
+   return 0;
+   return regmap_update_bits(map, reg, mask, val);
+}
+
+int mtk_regmap_write(struct regmap *map, int reg, unsigned int val)
+{
+   if (reg < 0)
+   return 0;
+   return regmap_write(map, reg, val);
+}
+
+int mtk_afe_fe_startup(struct snd_pcm_substream *substream,
+  struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   int memif_num = rtd->cpu_dai->id;
+   struct mtk_base_afe_memif *memif = >memif[memif_num];
+   const struct snd_pcm_hardware *mtk_afe_hardware = afe->mtk_afe_hardware;
+   int ret;
+
+   memif->substream = substream;
+
+   snd_pcm_hw_constraint_step(substream->runtime, 0,
+  SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 16);
+   /* enable agent */
+   mtk_regmap_update_bits(afe->regmap, memif->data->agent_disable_reg,
+  1 << memif->data->agent_disable_shift,
+  0 << memif->data->agent_disable_shift);
+
+   snd_soc_set_runtime_hwparams(substream, mtk_afe_hardware);
+
+   /*
+* Capture cannot use ping-pong buffer since hw_ptr at IRQ may be
+* smaller than period_size due to AFE's internal buffer.
+* This easily leads to overrun when avail_min is period_size.
+* One more period can hold the possible unread buffer.
+*/
+   if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+   int periods_max = mtk_afe_hardware->periods_max;
+
+   ret = snd_pcm_hw_constraint_minmax(runtime,
+  SNDRV_PCM_HW_PARAM_PERIODS,
+  3, periods_max);
+   if (ret < 0) {
+   dev_err(afe->dev, "hw_constraint_minmax failed\n");
+   return ret;
+   }
+   }
+
+   ret = snd_pcm_hw_constraint_integer(runtime,
+   SNDRV_PCM_HW_PARAM_PERIODS);
+   if (ret < 0)
+   dev_err(afe->dev, "snd_pcm_hw_constraint_integer failed\n");
+
+   /* dynamic allocate irq to memif */
+   if (memif->irq_usage < 0) {
+   int irq_id = mtk_dynamic_irq_acquire(afe);
+
+   if (irq_id != afe->irqs_size) {
+   /* link */
+   memif->irq_usage = irq_id;
+   } else {
+   dev_err(afe->dev, "%s() error: no more asys irq\n",
+   __func__);
+   ret = -EBUSY;
+   }
+   }
+   return ret;
+}
+EXPORT_SYM

[alsa-devel] [PATCH v4 5/9] ASoC: mediatek: add structure define and clock control for 2701

2016-06-13 Thread Garlic Tseng
add structure define and clock control function for 2701.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c | 464 ++
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h |  38 ++
 sound/soc/mediatek/mt2701/mt2701-afe-common.h | 181 +
 sound/soc/mediatek/mt2701/mt2701-reg.h| 186 +
 4 files changed, 869 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-common.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-reg.h

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
new file mode 100644
index 000..b815ecc
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
@@ -0,0 +1,464 @@
+/*
+ * mt2701-afe-clock-ctrl.c  --  Mediatek 2701 afe clock ctrl
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+#include "mt2701-afe-clock-ctrl.h"
+
+static const char *aud_clks[MT2701_CLOCK_NUM] = {
+   [MT2701_AUD_INFRA_SYS_AUDIO] = "infra_sys_audio_clk",
+   [MT2701_AUD_AUD_MUX1_SEL] = "top_audio_mux1_sel",
+   [MT2701_AUD_AUD_MUX2_SEL] = "top_audio_mux2_sel",
+   [MT2701_AUD_AUD_MUX1_DIV] = "top_audio_mux1_div",
+   [MT2701_AUD_AUD_MUX2_DIV] = "top_audio_mux2_div",
+   [MT2701_AUD_AUD_48K_TIMING] = "top_audio_48k_timing",
+   [MT2701_AUD_AUD_44K_TIMING] = "top_audio_44k_timing",
+   [MT2701_AUD_AUDPLL_MUX_SEL] = "top_audpll_mux_sel",
+   [MT2701_AUD_APLL_SEL] = "top_apll_sel",
+   [MT2701_AUD_AUD1PLL_98M] = "top_aud1_pll_98M",
+   [MT2701_AUD_AUD2PLL_90M] = "top_aud2_pll_90M",
+   [MT2701_AUD_HADDS2PLL_98M] = "top_hadds2_pll_98M",
+   [MT2701_AUD_HADDS2PLL_294M] = "top_hadds2_pll_294M",
+   [MT2701_AUD_AUDPLL] = "top_audpll",
+   [MT2701_AUD_AUDPLL_D4] = "top_audpll_d4",
+   [MT2701_AUD_AUDPLL_D8] = "top_audpll_d8",
+   [MT2701_AUD_AUDPLL_D16] = "top_audpll_d16",
+   [MT2701_AUD_AUDPLL_D24] = "top_audpll_d24",
+   [MT2701_AUD_AUDINTBUS] = "top_audintbus_sel",
+   [MT2701_AUD_CLK_26M] = "clk_26m",
+   [MT2701_AUD_SYSPLL1_D4] = "top_syspll1_d4",
+   [MT2701_AUD_AUD_K1_SRC_SEL] = "top_aud_k1_src_sel",
+   [MT2701_AUD_AUD_K2_SRC_SEL] = "top_aud_k2_src_sel",
+   [MT2701_AUD_AUD_K3_SRC_SEL] = "top_aud_k3_src_sel",
+   [MT2701_AUD_AUD_K4_SRC_SEL] = "top_aud_k4_src_sel",
+   [MT2701_AUD_AUD_K5_SRC_SEL] = "top_aud_k5_src_sel",
+   [MT2701_AUD_AUD_K6_SRC_SEL] = "top_aud_k6_src_sel",
+   [MT2701_AUD_AUD_K1_SRC_DIV] = "top_aud_k1_src_div",
+   [MT2701_AUD_AUD_K2_SRC_DIV] = "top_aud_k2_src_div",
+   [MT2701_AUD_AUD_K3_SRC_DIV] = "top_aud_k3_src_div",
+   [MT2701_AUD_AUD_K4_SRC_DIV] = "top_aud_k4_src_div",
+   [MT2701_AUD_AUD_K5_SRC_DIV] = "top_aud_k5_src_div",
+   [MT2701_AUD_AUD_K6_SRC_DIV] = "top_aud_k6_src_div",
+   [MT2701_AUD_AUD_I2S1_MCLK] = "top_aud_i2s1_mclk",
+   [MT2701_AUD_AUD_I2S2_MCLK] = "top_aud_i2s2_mclk",
+   [MT2701_AUD_AUD_I2S3_MCLK] = "top_aud_i2s3_mclk",
+   [MT2701_AUD_AUD_I2S4_MCLK] = "top_aud_i2s4_mclk",
+   [MT2701_AUD_AUD_I2S5_MCLK] = "top_aud_i2s5_mclk",
+   [MT2701_AUD_AUD_I2S6_MCLK] = "top_aud_i2s6_mclk",
+   [MT2701_AUD_ASM_M_SEL] = "top_asm_m_sel",
+   [MT2701_AUD_ASM_H_SEL] = "top_asm_h_sel",
+   [MT2701_AUD_UNIVPLL2_D4] = "top_univpll2_d4",
+   [MT2701_AUD_UNIVPLL2_D2] = "top_univpll2_d2",
+   [MT2701_AUD_SYSPLL_D5] = "top_syspll_d5",
+};
+
+int mt2701_init_clock(struct mtk_base_afe *afe)
+{
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+   int i = 0;
+
+   for (i = 0; i < MT2701_CLOCK_NUM; i++) {
+   afe_priv->clocks[i] = devm_clk_get(afe->dev, aud_clks[i]);
+   if (IS_ERR(aud_clks[i])) {
+   dev_warn(afe->dev, 

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

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

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/Kconfig|  11 +
 sound/soc/mediatek/Makefile   |   3 +-
 sound/soc/mediatek/common/Makefile|  17 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h |  42 +-
 sound/soc/mediatek/mt8173/mt8173-afe-pcm.c| 679 +++---
 5 files changed, 327 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..ff1a419 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,6 +1,16 @@
+config SND_SOC_MEDIATEK
+   tristate "SND_SOC_MEDIATEK"
+   depends on ARCH_MEDIATEK
+   help
+ This adds ASoC driver for Mediatek boards
+ that can be used with other codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
 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.
@@ -49,3 +59,4 @@ config SND_SOC_MT8173_RT5650_RT5676
  with the RT5650 and RT5676 codecs.
  Select Y if you have such device.
  If unsure select "N".
+
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index 240dfc70..3d893be 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,2 +1,3 @@
-# 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..0fcd921
--- /dev/null
+++ b/sound/soc/mediatek/common/Makefile
@@ -0,0 +1,17 @@
+#
+# 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 io

[alsa-devel] [PATCH v4 2/9] ASoC: mediatek: implement mediatek common structure

2016-06-13 Thread Garlic Tseng
implement mediatek basic structure, include common private data,
afe fe dai operator and afe platform driver.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/common/mtk-afe-fe-dai.c | 379 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.h |  45 +++
 .../soc/mediatek/common/mtk-afe-platform-driver.c  |  90 +
 .../soc/mediatek/common/mtk-afe-platform-driver.h  |  23 ++
 sound/soc/mediatek/common/mtk-base-afe.h   | 104 ++
 5 files changed, 641 insertions(+)
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.h
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.h
 create mode 100644 sound/soc/mediatek/common/mtk-base-afe.h

diff --git a/sound/soc/mediatek/common/mtk-afe-fe-dai.c 
b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
new file mode 100644
index 000..b788791b
--- /dev/null
+++ b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
@@ -0,0 +1,379 @@
+/*
+ * mtk-afe-fe-dais.c  --  Mediatek afe fe dai operator
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "mtk-afe-fe-dai.h"
+#include "mtk-base-afe.h"
+
+#define AFE_BASE_END_OFFSET 8
+
+int mtk_regmap_update_bits(struct regmap *map, int reg, unsigned int mask,
+  unsigned int val)
+{
+   if (reg < 0)
+   return 0;
+   return regmap_update_bits(map, reg, mask, val);
+}
+
+int mtk_regmap_write(struct regmap *map, int reg, unsigned int val)
+{
+   if (reg < 0)
+   return 0;
+   return regmap_write(map, reg, val);
+}
+
+int mtk_afe_fe_startup(struct snd_pcm_substream *substream,
+  struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   int memif_num = rtd->cpu_dai->id;
+   struct mtk_base_afe_memif *memif = >memif[memif_num];
+   const struct snd_pcm_hardware *mtk_afe_hardware = afe->mtk_afe_hardware;
+   int ret;
+
+   memif->substream = substream;
+
+   snd_pcm_hw_constraint_step(substream->runtime, 0,
+  SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 16);
+   /* enable agent */
+   mtk_regmap_update_bits(afe->regmap, memif->data->agent_disable_reg,
+  1 << memif->data->agent_disable_shift,
+  0 << memif->data->agent_disable_shift);
+
+   snd_soc_set_runtime_hwparams(substream, mtk_afe_hardware);
+
+   /*
+* Capture cannot use ping-pong buffer since hw_ptr at IRQ may be
+* smaller than period_size due to AFE's internal buffer.
+* This easily leads to overrun when avail_min is period_size.
+* One more period can hold the possible unread buffer.
+*/
+   if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+   int periods_max = mtk_afe_hardware->periods_max;
+
+   ret = snd_pcm_hw_constraint_minmax(runtime,
+  SNDRV_PCM_HW_PARAM_PERIODS,
+  3, periods_max);
+   if (ret < 0) {
+   dev_err(afe->dev, "hw_constraint_minmax failed\n");
+   return ret;
+   }
+   }
+
+   ret = snd_pcm_hw_constraint_integer(runtime,
+   SNDRV_PCM_HW_PARAM_PERIODS);
+   if (ret < 0)
+   dev_err(afe->dev, "snd_pcm_hw_constraint_integer failed\n");
+
+   /* dynamic allocate irq to memif */
+   if (memif->irq_usage < 0) {
+   int irq_id = mtk_dynamic_irq_acquire(afe);
+
+   if (irq_id != afe->irqs_size) {
+   /* link */
+   memif->irq_usage = irq_id;
+   } else {
+   dev_err(afe->dev, "%s() error: no more asys irq\n",
+   __func__);
+   ret = -EBUSY;
+   }
+   }
+   return ret;
+}
+EXPORT_SYMBOL_GPL(mtk_afe_fe_startup);
+
+void mtk_afe_fe_shutdown(struct snd_pcm_substre

[alsa-devel] [PATCH v4 7/9] ASoC: bt-sco: extend rate and add a general compatible string

2016-06-13 Thread Garlic Tseng
Add supports for 16k (wideband BT) and add a general compatible
string "linux,bt-sco"

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 Documentation/devicetree/bindings/sound/bt-sco.txt | 2 +-
 sound/soc/codecs/bt-sco.c  | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/sound/bt-sco.txt 
b/Documentation/devicetree/bindings/sound/bt-sco.txt
index 29b8e5d..641edf7 100644
--- a/Documentation/devicetree/bindings/sound/bt-sco.txt
+++ b/Documentation/devicetree/bindings/sound/bt-sco.txt
@@ -4,7 +4,7 @@ This device support generic Bluetooth SCO link.
 
 Required properties:
 
-  - compatible : "delta,dfbmcs320"
+  - compatible : "delta,dfbmcs320" or "linux,bt-sco"
 
 Example:
 
diff --git a/sound/soc/codecs/bt-sco.c b/sound/soc/codecs/bt-sco.c
index b084ad1..101b384 100644
--- a/sound/soc/codecs/bt-sco.c
+++ b/sound/soc/codecs/bt-sco.c
@@ -31,14 +31,14 @@ static struct snd_soc_dai_driver bt_sco_dai = {
.stream_name = "Playback",
.channels_min = 1,
.channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
.capture = {
 .stream_name = "Capture",
.channels_min = 1,
.channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
 };
@@ -77,6 +77,7 @@ MODULE_DEVICE_TABLE(platform, bt_sco_driver_ids);
 #if defined(CONFIG_OF)
 static const struct of_device_id bt_sco_codec_of_match[] = {
{ .compatible = "delta,dfbmcs320", },
+   { .compatible = "linux,bt-sco", },
{},
 };
 MODULE_DEVICE_TABLE(of, bt_sco_codec_of_match);
-- 
1.9.1



[alsa-devel] [PATCH v4 8/9] ASoC: mediatek: add BT implementation

2016-06-13 Thread Garlic Tseng
Add BT implementation for mt2701 platform driver.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 139 +
 1 file changed, 139 insertions(+)

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
index deb5f82..5fd2caa 100644
--- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -377,6 +377,86 @@ static int mt2701_afe_i2s_set_fmt(struct snd_soc_dai *dai, 
unsigned int fmt)
return 0;
 }
 
+static int mt2701_btmrg_startup(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF, 0);
+
+   afe_priv->mrg_enable[substream->stream] = 1;
+   return 0;
+}
+
+static int mt2701_btmrg_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   int stream_fs;
+   u32 val, msk;
+
+   stream_fs = params_rate(params);
+
+   if ((stream_fs != 8000) && (stream_fs != 16000)) {
+   dev_err(afe->dev, "%s() btmgr not supprt this stream_fs %d\n",
+   __func__, stream_fs);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_I2S_MODE_MASK,
+  AFE_MRGIF_CON_I2S_MODE_32K);
+
+   val = AFE_DAIBT_CON0_BT_FUNC_EN | AFE_DAIBT_CON0_BT_FUNC_RDY
+ | AFE_DAIBT_CON0_MRG_USE;
+   msk = val;
+
+   if (stream_fs == 16000)
+   val |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   msk |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0, msk, val);
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN,
+  AFE_DAIBT_CON0_DAIBT_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN,
+  AFE_MRGIF_CON_MRG_I2S_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN,
+  AFE_MRGIF_CON_MRG_EN);
+   return 0;
+}
+
+static void mt2701_btmrg_shutdown(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   /* if the other direction stream is not occupied */
+   if (!afe_priv->mrg_enable[!substream->stream]) {
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN, 0);
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF,
+  AUDIO_TOP_CON4_PDN_MRGIF);
+   }
+   afe_priv->mrg_enable[substream->stream] = 0;
+}
+
 static int mt2701_simple_fe_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
 {
@@ -560,6 +640,13 @@ static const struct snd_soc_dai_ops mt2701_afe_i2s_ops = {
.set_fmt= mt2701_afe_i2s_set_fmt,
 };
 
+/* MRG BE DAIs */
+static struct snd_soc_dai_ops mt2701_btmrg_ops = {
+   .startup = mt2701_btmrg_startup,
+   .shutdown = mt2701_btmrg_shutdown,
+   .hw_params = mt2701_btmrg_hw_params,
+};
+
 static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
/* FE DAIs: memory intefaces to CPU */
{
@@ -610,6 +697,36 @@ static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
},
.ops = _single_memif_dai_ops,
},
+   {
+   .name = "PCM_BT_DL",
+   .id = MT2701_MEMIF_DLBT,
+   .suspend = mtk_afe_dai_suspend,
+   .resume = mtk_afe_dai_resume,
+   .playback = {
+ 

[alsa-devel] [PATCH v4 1/9] ASoC: mediatek: Refine mt8173 driver and change config option

2016-06-13 Thread Garlic Tseng
move mt8173 driver to another folder and add prefix.
add config option SND_SOC_MT8173

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/Kconfig |  14 +-
 sound/soc/mediatek/Makefile|   9 +-
 sound/soc/mediatek/mt8173/Makefile |   7 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h  | 101 +
 .../{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} | 494 ++---
 sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c  |   2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c   |   2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c   |   4 +-
 sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c|   2 +-
 sound/soc/mediatek/mtk-afe-common.h| 101 -
 10 files changed, 367 insertions(+), 369 deletions(-)
 create mode 100644 sound/soc/mediatek/mt8173/Makefile
 create mode 100644 sound/soc/mediatek/mt8173/mt8173-afe-common.h
 rename sound/soc/mediatek/{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} (66%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c (99%)
 delete mode 100644 sound/soc/mediatek/mtk-afe-common.h

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index 3abf51c..ae9f664 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,15 +1,15 @@
-config SND_SOC_MEDIATEK
-   tristate "ASoC support for Mediatek chip"
+config SND_SOC_MT8173
+   tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
help
- This adds ASoC platform driver support for Mediatek chip
+ This adds ASoC platform driver support for Mediatek MT8173 chip
  that can be used with other codecs.
  Select Y if you have such device.
  Ex: MT8173
 
 config SND_SOC_MT8173_MAX98090
tristate "ASoC Audio driver for MT8173 with MAX98090 codec"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_MAX98090
help
  This adds ASoC driver for Mediatek MT8173 boards
@@ -19,7 +19,7 @@ config SND_SOC_MT8173_MAX98090
 
 config SND_SOC_MT8173_RT5650
tristate "ASoC Audio driver for MT8173 with RT5650 codec"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
help
  This adds ASoC driver for Mediatek MT8173 boards
@@ -29,7 +29,7 @@ config SND_SOC_MT8173_RT5650
 
 config SND_SOC_MT8173_RT5650_RT5514
tristate "ASoC Audio driver for MT8173 with RT5650 RT5514 codecs"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
select SND_SOC_RT5514
help
@@ -40,7 +40,7 @@ config SND_SOC_MT8173_RT5650_RT5514
 
 config SND_SOC_MT8173_RT5650_RT5676
tristate "ASoC Audio driver for MT8173 with RT5650 RT5676 codecs"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
select SND_SOC_RT5677
select SND_SOC_HDMI_CODEC
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index d486860..240dfc70 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,7 +1,2 @@
-# MTK Platform Support
-obj-$(CONFIG_SND_SOC_MEDIATEK) += mtk-afe-pcm.o
-# Machine support
-obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650) += mt8173-rt5650.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5514) += mt8173-rt5650-rt5514.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5676) += mt8173-rt5650-rt5676.o
+# 8173 Machine support
+obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
diff --git a/sound/soc/mediatek/mt8173/Makefile 
b/sound/soc/mediatek/mt8173/Makefile
new file mode 100644
index 000..0357b27
--- /dev/null
+++ b/sound/soc/mediatek/mt8173/Makefile
@@ -0,0 +1,7 @@
+# MTK Platform Support
+obj-$(CONFIG_SND_SOC_MT8173) += mt8173-afe-pcm.o
+# Machine support
+obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650) += mt8173-rt5650.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5514) += mt8173-rt5650-rt5514.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5676) += mt8173-rt5650-rt5676.o
diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-common.h 
b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
new file mode 100644
index 000..8f2936d
--- /dev/null
+++ b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
@@ -0,0 +1,101 @@
+/*
+ * mt8173_afe_common.h  --  Mediatek 8173 audio driver common definitions
+ *
+ * Copyright (c) 2015 MediaTek Inc.
+ * Author: Koro Chen <koro.c...@mediatek.

[alsa-devel] [PATCH v4 7/9] ASoC: bt-sco: extend rate and add a general compatible string

2016-06-13 Thread Garlic Tseng
Add supports for 16k (wideband BT) and add a general compatible
string "linux,bt-sco"

Signed-off-by: Garlic Tseng 
---
 Documentation/devicetree/bindings/sound/bt-sco.txt | 2 +-
 sound/soc/codecs/bt-sco.c  | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/sound/bt-sco.txt 
b/Documentation/devicetree/bindings/sound/bt-sco.txt
index 29b8e5d..641edf7 100644
--- a/Documentation/devicetree/bindings/sound/bt-sco.txt
+++ b/Documentation/devicetree/bindings/sound/bt-sco.txt
@@ -4,7 +4,7 @@ This device support generic Bluetooth SCO link.
 
 Required properties:
 
-  - compatible : "delta,dfbmcs320"
+  - compatible : "delta,dfbmcs320" or "linux,bt-sco"
 
 Example:
 
diff --git a/sound/soc/codecs/bt-sco.c b/sound/soc/codecs/bt-sco.c
index b084ad1..101b384 100644
--- a/sound/soc/codecs/bt-sco.c
+++ b/sound/soc/codecs/bt-sco.c
@@ -31,14 +31,14 @@ static struct snd_soc_dai_driver bt_sco_dai = {
.stream_name = "Playback",
.channels_min = 1,
.channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
.capture = {
 .stream_name = "Capture",
.channels_min = 1,
.channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
 };
@@ -77,6 +77,7 @@ MODULE_DEVICE_TABLE(platform, bt_sco_driver_ids);
 #if defined(CONFIG_OF)
 static const struct of_device_id bt_sco_codec_of_match[] = {
{ .compatible = "delta,dfbmcs320", },
+   { .compatible = "linux,bt-sco", },
{},
 };
 MODULE_DEVICE_TABLE(of, bt_sco_codec_of_match);
-- 
1.9.1



[alsa-devel] [PATCH v4 8/9] ASoC: mediatek: add BT implementation

2016-06-13 Thread Garlic Tseng
Add BT implementation for mt2701 platform driver.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 139 +
 1 file changed, 139 insertions(+)

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
index deb5f82..5fd2caa 100644
--- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -377,6 +377,86 @@ static int mt2701_afe_i2s_set_fmt(struct snd_soc_dai *dai, 
unsigned int fmt)
return 0;
 }
 
+static int mt2701_btmrg_startup(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF, 0);
+
+   afe_priv->mrg_enable[substream->stream] = 1;
+   return 0;
+}
+
+static int mt2701_btmrg_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   int stream_fs;
+   u32 val, msk;
+
+   stream_fs = params_rate(params);
+
+   if ((stream_fs != 8000) && (stream_fs != 16000)) {
+   dev_err(afe->dev, "%s() btmgr not supprt this stream_fs %d\n",
+   __func__, stream_fs);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_I2S_MODE_MASK,
+  AFE_MRGIF_CON_I2S_MODE_32K);
+
+   val = AFE_DAIBT_CON0_BT_FUNC_EN | AFE_DAIBT_CON0_BT_FUNC_RDY
+ | AFE_DAIBT_CON0_MRG_USE;
+   msk = val;
+
+   if (stream_fs == 16000)
+   val |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   msk |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0, msk, val);
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN,
+  AFE_DAIBT_CON0_DAIBT_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN,
+  AFE_MRGIF_CON_MRG_I2S_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN,
+  AFE_MRGIF_CON_MRG_EN);
+   return 0;
+}
+
+static void mt2701_btmrg_shutdown(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   /* if the other direction stream is not occupied */
+   if (!afe_priv->mrg_enable[!substream->stream]) {
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN, 0);
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF,
+  AUDIO_TOP_CON4_PDN_MRGIF);
+   }
+   afe_priv->mrg_enable[substream->stream] = 0;
+}
+
 static int mt2701_simple_fe_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
 {
@@ -560,6 +640,13 @@ static const struct snd_soc_dai_ops mt2701_afe_i2s_ops = {
.set_fmt= mt2701_afe_i2s_set_fmt,
 };
 
+/* MRG BE DAIs */
+static struct snd_soc_dai_ops mt2701_btmrg_ops = {
+   .startup = mt2701_btmrg_startup,
+   .shutdown = mt2701_btmrg_shutdown,
+   .hw_params = mt2701_btmrg_hw_params,
+};
+
 static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
/* FE DAIs: memory intefaces to CPU */
{
@@ -610,6 +697,36 @@ static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
},
.ops = _single_memif_dai_ops,
},
+   {
+   .name = "PCM_BT_DL",
+   .id = MT2701_MEMIF_DLBT,
+   .suspend = mtk_afe_dai_suspend,
+   .resume = mtk_afe_dai_resume,
+   .playback = {
+   .stream_name = "DLBT",
+  

[alsa-devel] [PATCH v4 1/9] ASoC: mediatek: Refine mt8173 driver and change config option

2016-06-13 Thread Garlic Tseng
move mt8173 driver to another folder and add prefix.
add config option SND_SOC_MT8173

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/Kconfig |  14 +-
 sound/soc/mediatek/Makefile|   9 +-
 sound/soc/mediatek/mt8173/Makefile |   7 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h  | 101 +
 .../{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} | 494 ++---
 sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c  |   2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c   |   2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c   |   4 +-
 sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c|   2 +-
 sound/soc/mediatek/mtk-afe-common.h| 101 -
 10 files changed, 367 insertions(+), 369 deletions(-)
 create mode 100644 sound/soc/mediatek/mt8173/Makefile
 create mode 100644 sound/soc/mediatek/mt8173/mt8173-afe-common.h
 rename sound/soc/mediatek/{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} (66%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c (99%)
 delete mode 100644 sound/soc/mediatek/mtk-afe-common.h

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index 3abf51c..ae9f664 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,15 +1,15 @@
-config SND_SOC_MEDIATEK
-   tristate "ASoC support for Mediatek chip"
+config SND_SOC_MT8173
+   tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
help
- This adds ASoC platform driver support for Mediatek chip
+ This adds ASoC platform driver support for Mediatek MT8173 chip
  that can be used with other codecs.
  Select Y if you have such device.
  Ex: MT8173
 
 config SND_SOC_MT8173_MAX98090
tristate "ASoC Audio driver for MT8173 with MAX98090 codec"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_MAX98090
help
  This adds ASoC driver for Mediatek MT8173 boards
@@ -19,7 +19,7 @@ config SND_SOC_MT8173_MAX98090
 
 config SND_SOC_MT8173_RT5650
tristate "ASoC Audio driver for MT8173 with RT5650 codec"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
help
  This adds ASoC driver for Mediatek MT8173 boards
@@ -29,7 +29,7 @@ config SND_SOC_MT8173_RT5650
 
 config SND_SOC_MT8173_RT5650_RT5514
tristate "ASoC Audio driver for MT8173 with RT5650 RT5514 codecs"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
select SND_SOC_RT5514
help
@@ -40,7 +40,7 @@ config SND_SOC_MT8173_RT5650_RT5514
 
 config SND_SOC_MT8173_RT5650_RT5676
tristate "ASoC Audio driver for MT8173 with RT5650 RT5676 codecs"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
select SND_SOC_RT5677
select SND_SOC_HDMI_CODEC
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index d486860..240dfc70 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,7 +1,2 @@
-# MTK Platform Support
-obj-$(CONFIG_SND_SOC_MEDIATEK) += mtk-afe-pcm.o
-# Machine support
-obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650) += mt8173-rt5650.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5514) += mt8173-rt5650-rt5514.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5676) += mt8173-rt5650-rt5676.o
+# 8173 Machine support
+obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
diff --git a/sound/soc/mediatek/mt8173/Makefile 
b/sound/soc/mediatek/mt8173/Makefile
new file mode 100644
index 000..0357b27
--- /dev/null
+++ b/sound/soc/mediatek/mt8173/Makefile
@@ -0,0 +1,7 @@
+# MTK Platform Support
+obj-$(CONFIG_SND_SOC_MT8173) += mt8173-afe-pcm.o
+# Machine support
+obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650) += mt8173-rt5650.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5514) += mt8173-rt5650-rt5514.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5676) += mt8173-rt5650-rt5676.o
diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-common.h 
b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
new file mode 100644
index 000..8f2936d
--- /dev/null
+++ b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
@@ -0,0 +1,101 @@
+/*
+ * mt8173_afe_common.h  --  Mediatek 8173 audio driver common definitions
+ *
+ * Copyright (c) 2015 MediaTek Inc.
+ * Author: Koro Chen 
+ * Sascha Hauer 
+ * Hidalgo Huang 
+ * 

[alsa-devel] [PATCH v4 6/9] ASoC: mediatek: add mt2701 platform driver implementation.

2016-06-13 Thread Garlic Tseng
Add mt2701 platform driver implementation for playback and capture.
The implement follow DAPM structure (memory interface as FE and I2S
as BE).
Because of the hardware design, i2s out required to be enabled when
we need to enable i2s in. This patch includes the implementation.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 1559 
 1 file changed, 1559 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
new file mode 100644
index 000..deb5f82
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -0,0 +1,1559 @@
+/*
+ * Mediatek ALSA SoC AFE platform driver for 2701
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng <garlic.ts...@mediatek.com>
+ * Ir Lian <ir.l...@mediatek.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+#include "mt2701-afe-clock-ctrl.h"
+#include "../common/mtk-afe-platform-driver.h"
+#include "../common/mtk-afe-fe-dai.h"
+
+#define AFE_IRQ_STATUS_BITS0xff
+
+static const struct snd_pcm_hardware mt2701_afe_hardware = {
+   .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED
+   | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE
+  | SNDRV_PCM_FMTBIT_S32_LE,
+   .period_bytes_min = 1024,
+   .period_bytes_max = 1024 * 256,
+   .periods_min = 4,
+   .periods_max = 1024,
+   .buffer_bytes_max = 1024 * 1024 * 16,
+   .fifo_size = 0,
+};
+
+struct mt2701_afe_rate {
+   unsigned int rate;
+   unsigned int regvalue;
+};
+
+static const struct mt2701_afe_rate mt2701_afe_i2s_rates[] = {
+   { .rate = 8000, .regvalue = 0 },
+   { .rate = 12000, .regvalue = 1 },
+   { .rate = 16000, .regvalue = 2 },
+   { .rate = 24000, .regvalue = 3 },
+   { .rate = 32000, .regvalue = 4 },
+   { .rate = 48000, .regvalue = 5 },
+   { .rate = 96000, .regvalue = 6 },
+   { .rate = 192000, .regvalue = 7 },
+   { .rate = 384000, .regvalue = 8 },
+   { .rate = 7350, .regvalue = 16 },
+   { .rate = 11025, .regvalue = 17 },
+   { .rate = 14700, .regvalue = 18 },
+   { .rate = 22050, .regvalue = 19 },
+   { .rate = 29400, .regvalue = 20 },
+   { .rate = 44100, .regvalue = 21 },
+   { .rate = 88200, .regvalue = 22 },
+   { .rate = 176400, .regvalue = 23 },
+   { .rate = 352800, .regvalue = 24 },
+};
+
+int mt2701_dai_num_to_i2s(struct mtk_base_afe *afe, int num)
+{
+   int val = num - MT2701_IO_I2S;
+
+   if (val < 0 || val >= MT2701_I2S_NUM) {
+   dev_err(afe->dev, "%s, num not available, num %d, val %d\n",
+   __func__, num, val);
+   return -EINVAL;
+   }
+   return val;
+}
+
+static int mt2701_afe_i2s_fs(unsigned int sample_rate)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(mt2701_afe_i2s_rates); i++)
+   if (mt2701_afe_i2s_rates[i].rate == sample_rate)
+   return mt2701_afe_i2s_rates[i].regvalue;
+
+   return -EINVAL;
+}
+
+static int mt2701_afe_i2s_startup(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+   int i2s_num = mt2701_dai_num_to_i2s(afe, dai->id);
+   int clk_num = MT2701_AUD_AUD_I2S1_MCLK + i2s_num;
+   int ret = 0;
+
+   if (i2s_num < 0)
+   return i2s_num;
+
+   /* enable mclk */
+   ret = clk_prepare_enable(afe_priv->clocks[clk_num]);
+   if (ret)
+   dev_err(afe->dev, "Failed to enable mclk for I2S: %d\n",
+   i2s_num);
+
+   return ret;
+}
+
+static int mt2701_afe_i2s_path_shutdown(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai,
+   int dir_invert)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform

[alsa-devel] [PATCH v4 4/9] ASoC: mediatek: add documents for mt2701

2016-06-13 Thread Garlic Tseng
add mt2701-afe-pcm.txt and mt2701-cs42448.txt for mt2701

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 .../devicetree/bindings/sound/mt2701-afe-pcm.txt   | 150 +
 .../devicetree/bindings/sound/mt2701-cs42448.txt   |  43 ++
 2 files changed, 193 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-cs42448.txt

diff --git a/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt 
b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
new file mode 100644
index 000..3e623a7
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
@@ -0,0 +1,150 @@
+Mediatek AFE PCM controller for mt2701
+
+Required properties:
+- compatible = "mediatek,mt2701-audio";
+- reg: register location and size
+- interrupts: Should contain AFE interrupt
+- clock-names: should have these clock names:
+   "infra_sys_audio_clk",
+   "top_audio_mux1_sel",
+   "top_audio_mux2_sel",
+   "top_audio_mux1_div",
+   "top_audio_mux2_div",
+   "top_audio_48k_timing",
+   "top_audio_44k_timing",
+   "top_audpll_mux_sel",
+   "top_apll_sel",
+   "top_aud1_pll_98M",
+   "top_aud2_pll_90M",
+   "top_hadds2_pll_98M",
+   "top_hadds2_pll_294M",
+   "top_audpll",
+   "top_audpll_d4",
+   "top_audpll_d8",
+   "top_audpll_d16",
+   "top_audpll_d24",
+   "top_audintbus_sel",
+   "clk_26m",
+   "top_syspll1_d4",
+   "top_aud_k1_src_sel",
+   "top_aud_k2_src_sel",
+   "top_aud_k3_src_sel",
+   "top_aud_k4_src_sel",
+   "top_aud_k5_src_sel",
+   "top_aud_k6_src_sel",
+   "top_aud_k1_src_div",
+   "top_aud_k2_src_div",
+   "top_aud_k3_src_div",
+   "top_aud_k4_src_div",
+   "top_aud_k5_src_div",
+   "top_aud_k6_src_div",
+   "top_aud_i2s1_mclk",
+   "top_aud_i2s2_mclk",
+   "top_aud_i2s3_mclk",
+   "top_aud_i2s4_mclk",
+   "top_aud_i2s5_mclk",
+   "top_aud_i2s6_mclk",
+   "top_asm_m_sel",
+   "top_asm_h_sel",
+   "top_univpll2_d4",
+   "top_univpll2_d2",
+   "top_syspll_d5";
+
+Example:
+
+   afe: mt2701-afe-pcm@1122 {
+   compatible = "mediatek,mt2701-audio";
+   reg = <0 0x1122 0 0x2000>,
+ <0 0x112A 0 0x2>;
+   interrupts = ,
+;
+   clocks = < CLK_INFRA_AUDIO>,
+< CLK_TOP_AUD_MUX1_SEL>,
+< CLK_TOP_AUD_MUX2_SEL>,
+< CLK_TOP_AUD_MUX1_DIV>,
+< CLK_TOP_AUD_MUX2_DIV>,
+< CLK_TOP_AUD_48K_TIMING>,
+< CLK_TOP_AUD_44K_TIMING>,
+< CLK_TOP_AUDPLL_MUX_SEL>,
+< CLK_TOP_APLL_SEL>,
+< CLK_TOP_AUD1PLL_98M>,
+< CLK_TOP_AUD2PLL_90M>,
+< CLK_TOP_HADDS2PLL_98M>,
+< CLK_TOP_HADDS2PLL_294M>,
+< CLK_TOP_AUDPLL>,
+< CLK_TOP_AUDPLL_D4>,
+< CLK_TOP_AUDPLL_D8>,
+< CLK_TOP_AUDPLL_D16>,
+< CLK_TOP_AUDPLL_D24>,
+< CLK_TOP_AUDINTBUS_SEL>,
+<>,
+< CLK_TOP_SYSPLL1_D4>,
+< CLK_TOP_AUD_K1_SRC_SEL>,
+< CLK_TOP_AUD_K2_SRC_SEL>,
+< CLK_TOP_AUD_K3_SRC_SEL>,
+< CLK_TOP_AUD_K4_SRC_SEL>,
+< CLK_TOP_AUD_K5_SRC_SEL>,
+< CLK_TOP_AUD_K6_SRC_SEL>,
+< CLK_TOP_AUD_K1_SRC_DIV>,
+< CLK_TOP_AUD_K2_SRC_DIV>,
+< CLK_TOP_AUD_K3_SRC_DI

[alsa-devel] [PATCH v4 6/9] ASoC: mediatek: add mt2701 platform driver implementation.

2016-06-13 Thread Garlic Tseng
Add mt2701 platform driver implementation for playback and capture.
The implement follow DAPM structure (memory interface as FE and I2S
as BE).
Because of the hardware design, i2s out required to be enabled when
we need to enable i2s in. This patch includes the implementation.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 1559 
 1 file changed, 1559 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
new file mode 100644
index 000..deb5f82
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -0,0 +1,1559 @@
+/*
+ * Mediatek ALSA SoC AFE platform driver for 2701
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng 
+ * Ir Lian 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+#include "mt2701-afe-clock-ctrl.h"
+#include "../common/mtk-afe-platform-driver.h"
+#include "../common/mtk-afe-fe-dai.h"
+
+#define AFE_IRQ_STATUS_BITS0xff
+
+static const struct snd_pcm_hardware mt2701_afe_hardware = {
+   .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED
+   | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE
+  | SNDRV_PCM_FMTBIT_S32_LE,
+   .period_bytes_min = 1024,
+   .period_bytes_max = 1024 * 256,
+   .periods_min = 4,
+   .periods_max = 1024,
+   .buffer_bytes_max = 1024 * 1024 * 16,
+   .fifo_size = 0,
+};
+
+struct mt2701_afe_rate {
+   unsigned int rate;
+   unsigned int regvalue;
+};
+
+static const struct mt2701_afe_rate mt2701_afe_i2s_rates[] = {
+   { .rate = 8000, .regvalue = 0 },
+   { .rate = 12000, .regvalue = 1 },
+   { .rate = 16000, .regvalue = 2 },
+   { .rate = 24000, .regvalue = 3 },
+   { .rate = 32000, .regvalue = 4 },
+   { .rate = 48000, .regvalue = 5 },
+   { .rate = 96000, .regvalue = 6 },
+   { .rate = 192000, .regvalue = 7 },
+   { .rate = 384000, .regvalue = 8 },
+   { .rate = 7350, .regvalue = 16 },
+   { .rate = 11025, .regvalue = 17 },
+   { .rate = 14700, .regvalue = 18 },
+   { .rate = 22050, .regvalue = 19 },
+   { .rate = 29400, .regvalue = 20 },
+   { .rate = 44100, .regvalue = 21 },
+   { .rate = 88200, .regvalue = 22 },
+   { .rate = 176400, .regvalue = 23 },
+   { .rate = 352800, .regvalue = 24 },
+};
+
+int mt2701_dai_num_to_i2s(struct mtk_base_afe *afe, int num)
+{
+   int val = num - MT2701_IO_I2S;
+
+   if (val < 0 || val >= MT2701_I2S_NUM) {
+   dev_err(afe->dev, "%s, num not available, num %d, val %d\n",
+   __func__, num, val);
+   return -EINVAL;
+   }
+   return val;
+}
+
+static int mt2701_afe_i2s_fs(unsigned int sample_rate)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(mt2701_afe_i2s_rates); i++)
+   if (mt2701_afe_i2s_rates[i].rate == sample_rate)
+   return mt2701_afe_i2s_rates[i].regvalue;
+
+   return -EINVAL;
+}
+
+static int mt2701_afe_i2s_startup(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+   int i2s_num = mt2701_dai_num_to_i2s(afe, dai->id);
+   int clk_num = MT2701_AUD_AUD_I2S1_MCLK + i2s_num;
+   int ret = 0;
+
+   if (i2s_num < 0)
+   return i2s_num;
+
+   /* enable mclk */
+   ret = clk_prepare_enable(afe_priv->clocks[clk_num]);
+   if (ret)
+   dev_err(afe->dev, "Failed to enable mclk for I2S: %d\n",
+   i2s_num);
+
+   return ret;
+}
+
+static int mt2701_afe_i2s_path_shutdown(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai,
+   int dir_invert)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_pri

[alsa-devel] [PATCH v4 4/9] ASoC: mediatek: add documents for mt2701

2016-06-13 Thread Garlic Tseng
add mt2701-afe-pcm.txt and mt2701-cs42448.txt for mt2701

Signed-off-by: Garlic Tseng 
---
 .../devicetree/bindings/sound/mt2701-afe-pcm.txt   | 150 +
 .../devicetree/bindings/sound/mt2701-cs42448.txt   |  43 ++
 2 files changed, 193 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-cs42448.txt

diff --git a/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt 
b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
new file mode 100644
index 000..3e623a7
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
@@ -0,0 +1,150 @@
+Mediatek AFE PCM controller for mt2701
+
+Required properties:
+- compatible = "mediatek,mt2701-audio";
+- reg: register location and size
+- interrupts: Should contain AFE interrupt
+- clock-names: should have these clock names:
+   "infra_sys_audio_clk",
+   "top_audio_mux1_sel",
+   "top_audio_mux2_sel",
+   "top_audio_mux1_div",
+   "top_audio_mux2_div",
+   "top_audio_48k_timing",
+   "top_audio_44k_timing",
+   "top_audpll_mux_sel",
+   "top_apll_sel",
+   "top_aud1_pll_98M",
+   "top_aud2_pll_90M",
+   "top_hadds2_pll_98M",
+   "top_hadds2_pll_294M",
+   "top_audpll",
+   "top_audpll_d4",
+   "top_audpll_d8",
+   "top_audpll_d16",
+   "top_audpll_d24",
+   "top_audintbus_sel",
+   "clk_26m",
+   "top_syspll1_d4",
+   "top_aud_k1_src_sel",
+   "top_aud_k2_src_sel",
+   "top_aud_k3_src_sel",
+   "top_aud_k4_src_sel",
+   "top_aud_k5_src_sel",
+   "top_aud_k6_src_sel",
+   "top_aud_k1_src_div",
+   "top_aud_k2_src_div",
+   "top_aud_k3_src_div",
+   "top_aud_k4_src_div",
+   "top_aud_k5_src_div",
+   "top_aud_k6_src_div",
+   "top_aud_i2s1_mclk",
+   "top_aud_i2s2_mclk",
+   "top_aud_i2s3_mclk",
+   "top_aud_i2s4_mclk",
+   "top_aud_i2s5_mclk",
+   "top_aud_i2s6_mclk",
+   "top_asm_m_sel",
+   "top_asm_h_sel",
+   "top_univpll2_d4",
+   "top_univpll2_d2",
+   "top_syspll_d5";
+
+Example:
+
+   afe: mt2701-afe-pcm@1122 {
+   compatible = "mediatek,mt2701-audio";
+   reg = <0 0x1122 0 0x2000>,
+ <0 0x112A 0 0x2>;
+   interrupts = ,
+;
+   clocks = < CLK_INFRA_AUDIO>,
+< CLK_TOP_AUD_MUX1_SEL>,
+< CLK_TOP_AUD_MUX2_SEL>,
+< CLK_TOP_AUD_MUX1_DIV>,
+< CLK_TOP_AUD_MUX2_DIV>,
+< CLK_TOP_AUD_48K_TIMING>,
+< CLK_TOP_AUD_44K_TIMING>,
+< CLK_TOP_AUDPLL_MUX_SEL>,
+< CLK_TOP_APLL_SEL>,
+< CLK_TOP_AUD1PLL_98M>,
+< CLK_TOP_AUD2PLL_90M>,
+< CLK_TOP_HADDS2PLL_98M>,
+< CLK_TOP_HADDS2PLL_294M>,
+< CLK_TOP_AUDPLL>,
+< CLK_TOP_AUDPLL_D4>,
+< CLK_TOP_AUDPLL_D8>,
+< CLK_TOP_AUDPLL_D16>,
+< CLK_TOP_AUDPLL_D24>,
+< CLK_TOP_AUDINTBUS_SEL>,
+<>,
+< CLK_TOP_SYSPLL1_D4>,
+< CLK_TOP_AUD_K1_SRC_SEL>,
+< CLK_TOP_AUD_K2_SRC_SEL>,
+< CLK_TOP_AUD_K3_SRC_SEL>,
+< CLK_TOP_AUD_K4_SRC_SEL>,
+< CLK_TOP_AUD_K5_SRC_SEL>,
+< CLK_TOP_AUD_K6_SRC_SEL>,
+< CLK_TOP_AUD_K1_SRC_DIV>,
+< CLK_TOP_AUD_K2_SRC_DIV>,
+< CLK_TOP_AUD_K3_SRC_DIV>,
+< CLK_TOP_AUD_K4_S

[alsa-devel] [PATCH v3 7/9] ASoC: bt-sco: extend rate and add a general compatible string

2016-06-13 Thread Garlic Tseng
Add supports for 16k (wideband BT) and add a general compatible
string "linux,bt-sco"

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 Documentation/devicetree/bindings/sound/bt-sco.txt | 2 +-
 sound/soc/codecs/bt-sco.c  | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/sound/bt-sco.txt 
b/Documentation/devicetree/bindings/sound/bt-sco.txt
index 29b8e5d..641edf7 100644
--- a/Documentation/devicetree/bindings/sound/bt-sco.txt
+++ b/Documentation/devicetree/bindings/sound/bt-sco.txt
@@ -4,7 +4,7 @@ This device support generic Bluetooth SCO link.
 
 Required properties:
 
-  - compatible : "delta,dfbmcs320"
+  - compatible : "delta,dfbmcs320" or "linux,bt-sco"
 
 Example:
 
diff --git a/sound/soc/codecs/bt-sco.c b/sound/soc/codecs/bt-sco.c
index b084ad1..101b384 100644
--- a/sound/soc/codecs/bt-sco.c
+++ b/sound/soc/codecs/bt-sco.c
@@ -31,14 +31,14 @@ static struct snd_soc_dai_driver bt_sco_dai = {
.stream_name = "Playback",
.channels_min = 1,
.channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
.capture = {
 .stream_name = "Capture",
.channels_min = 1,
.channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
 };
@@ -77,6 +77,7 @@ MODULE_DEVICE_TABLE(platform, bt_sco_driver_ids);
 #if defined(CONFIG_OF)
 static const struct of_device_id bt_sco_codec_of_match[] = {
{ .compatible = "delta,dfbmcs320", },
+   { .compatible = "linux,bt-sco", },
{},
 };
 MODULE_DEVICE_TABLE(of, bt_sco_codec_of_match);
-- 
1.9.1



[alsa-devel] [PATCH v3 7/9] ASoC: bt-sco: extend rate and add a general compatible string

2016-06-13 Thread Garlic Tseng
Add supports for 16k (wideband BT) and add a general compatible
string "linux,bt-sco"

Signed-off-by: Garlic Tseng 
---
 Documentation/devicetree/bindings/sound/bt-sco.txt | 2 +-
 sound/soc/codecs/bt-sco.c  | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/sound/bt-sco.txt 
b/Documentation/devicetree/bindings/sound/bt-sco.txt
index 29b8e5d..641edf7 100644
--- a/Documentation/devicetree/bindings/sound/bt-sco.txt
+++ b/Documentation/devicetree/bindings/sound/bt-sco.txt
@@ -4,7 +4,7 @@ This device support generic Bluetooth SCO link.
 
 Required properties:
 
-  - compatible : "delta,dfbmcs320"
+  - compatible : "delta,dfbmcs320" or "linux,bt-sco"
 
 Example:
 
diff --git a/sound/soc/codecs/bt-sco.c b/sound/soc/codecs/bt-sco.c
index b084ad1..101b384 100644
--- a/sound/soc/codecs/bt-sco.c
+++ b/sound/soc/codecs/bt-sco.c
@@ -31,14 +31,14 @@ static struct snd_soc_dai_driver bt_sco_dai = {
.stream_name = "Playback",
.channels_min = 1,
.channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
.capture = {
 .stream_name = "Capture",
.channels_min = 1,
.channels_max = 1,
-   .rates = SNDRV_PCM_RATE_8000,
+   .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
 };
@@ -77,6 +77,7 @@ MODULE_DEVICE_TABLE(platform, bt_sco_driver_ids);
 #if defined(CONFIG_OF)
 static const struct of_device_id bt_sco_codec_of_match[] = {
{ .compatible = "delta,dfbmcs320", },
+   { .compatible = "linux,bt-sco", },
{},
 };
 MODULE_DEVICE_TABLE(of, bt_sco_codec_of_match);
-- 
1.9.1



[alsa-devel] [PATCH v3 0/9] ASoC: Mediatek: Add support for MT2701 SOC

2016-06-13 Thread Garlic Tseng
This patch adds basic support for Mediatek AFE for MT2701 SoC.
The patch is based on broonie tree "for-next" branch.

Change since v2:

* fix comments style.
* replace EXPORT_SYMBOL with EXPORT_SYMBOL_GPL
* reduce debug message
* move mutex lock for irq-allocated to AFE struct
* remove func mtk_simple_isr and call snd_pcm_period_elapsed directly
* mt2701 driver probe will fail if clock initial error
* fix dapm on/off switch control naming

Change since v1:

implement common private structure, fe dai and platform driver.
let mt8173 and mt2701 use the common structure.


Garlic Tseng (9):
  ASoC: mediatek: Refine mt8173 driver and change config option
  ASoC: mediatek: implement mediatek common structure
  ASoC: mediatek: let mt8173 use mediatek common structure
  ASoC: mediatek: add documents for mt2701
  ASoC: mediatek: add structure define and clock control for 2701
  ASoC: mediatek: add mt2701 platform driver implementation.
  ASoC: bt-sco: extend rate and add a general compatible string
  ASoC: mediatek: add BT implementation
  ASoC: mediatek: Add mt2701-cs42448 driver and config option.

 Documentation/devicetree/bindings/sound/bt-sco.txt |2 +-
 .../devicetree/bindings/sound/mt2701-afe-pcm.txt   |  150 ++
 .../devicetree/bindings/sound/mt2701-cs42448.txt   |   43 +
 sound/soc/codecs/bt-sco.c  |5 +-
 sound/soc/mediatek/Kconfig |   44 +-
 sound/soc/mediatek/Makefile|   11 +-
 sound/soc/mediatek/common/Makefile |   17 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.c |  379 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.h |   45 +
 .../soc/mediatek/common/mtk-afe-platform-driver.c  |   90 ++
 .../soc/mediatek/common/mtk-afe-platform-driver.h  |   23 +
 sound/soc/mediatek/common/mtk-base-afe.h   |  104 ++
 sound/soc/mediatek/mt2701/Makefile |   19 +
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c  |  464 ++
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h  |   38 +
 sound/soc/mediatek/mt2701/mt2701-afe-common.h  |  181 +++
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 1698 
 sound/soc/mediatek/mt2701/mt2701-cs42448.c |  422 +
 sound/soc/mediatek/mt2701/mt2701-reg.h |  186 +++
 sound/soc/mediatek/mt8173/Makefile |7 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h  |   73 +
 .../{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} |  921 +--
 sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c  |2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c   |2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c   |4 +-
 sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c|2 +-
 sound/soc/mediatek/mtk-afe-common.h|  101 --
 27 files changed, 4399 insertions(+), 634 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-cs42448.txt
 create mode 100644 sound/soc/mediatek/common/Makefile
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.h
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.h
 create mode 100644 sound/soc/mediatek/common/mtk-base-afe.h
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-common.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-reg.h
 create mode 100644 sound/soc/mediatek/mt8173/Makefile
 create mode 100644 sound/soc/mediatek/mt8173/mt8173-afe-common.h
 rename sound/soc/mediatek/{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} (51%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c (99%)
 delete mode 100644 sound/soc/mediatek/mtk-afe-common.h

-- 
1.9.1



[alsa-devel] [PATCH v3 0/9] ASoC: Mediatek: Add support for MT2701 SOC

2016-06-13 Thread Garlic Tseng
This patch adds basic support for Mediatek AFE for MT2701 SoC.
The patch is based on broonie tree "for-next" branch.

Change since v2:

* fix comments style.
* replace EXPORT_SYMBOL with EXPORT_SYMBOL_GPL
* reduce debug message
* move mutex lock for irq-allocated to AFE struct
* remove func mtk_simple_isr and call snd_pcm_period_elapsed directly
* mt2701 driver probe will fail if clock initial error
* fix dapm on/off switch control naming

Change since v1:

implement common private structure, fe dai and platform driver.
let mt8173 and mt2701 use the common structure.


Garlic Tseng (9):
  ASoC: mediatek: Refine mt8173 driver and change config option
  ASoC: mediatek: implement mediatek common structure
  ASoC: mediatek: let mt8173 use mediatek common structure
  ASoC: mediatek: add documents for mt2701
  ASoC: mediatek: add structure define and clock control for 2701
  ASoC: mediatek: add mt2701 platform driver implementation.
  ASoC: bt-sco: extend rate and add a general compatible string
  ASoC: mediatek: add BT implementation
  ASoC: mediatek: Add mt2701-cs42448 driver and config option.

 Documentation/devicetree/bindings/sound/bt-sco.txt |2 +-
 .../devicetree/bindings/sound/mt2701-afe-pcm.txt   |  150 ++
 .../devicetree/bindings/sound/mt2701-cs42448.txt   |   43 +
 sound/soc/codecs/bt-sco.c  |5 +-
 sound/soc/mediatek/Kconfig |   44 +-
 sound/soc/mediatek/Makefile|   11 +-
 sound/soc/mediatek/common/Makefile |   17 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.c |  379 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.h |   45 +
 .../soc/mediatek/common/mtk-afe-platform-driver.c  |   90 ++
 .../soc/mediatek/common/mtk-afe-platform-driver.h  |   23 +
 sound/soc/mediatek/common/mtk-base-afe.h   |  104 ++
 sound/soc/mediatek/mt2701/Makefile |   19 +
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c  |  464 ++
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h  |   38 +
 sound/soc/mediatek/mt2701/mt2701-afe-common.h  |  181 +++
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 1698 
 sound/soc/mediatek/mt2701/mt2701-cs42448.c |  422 +
 sound/soc/mediatek/mt2701/mt2701-reg.h |  186 +++
 sound/soc/mediatek/mt8173/Makefile |7 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h  |   73 +
 .../{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} |  921 +--
 sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c  |2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c   |2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c   |4 +-
 sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c|2 +-
 sound/soc/mediatek/mtk-afe-common.h|  101 --
 27 files changed, 4399 insertions(+), 634 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-cs42448.txt
 create mode 100644 sound/soc/mediatek/common/Makefile
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.h
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.h
 create mode 100644 sound/soc/mediatek/common/mtk-base-afe.h
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-common.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-reg.h
 create mode 100644 sound/soc/mediatek/mt8173/Makefile
 create mode 100644 sound/soc/mediatek/mt8173/mt8173-afe-common.h
 rename sound/soc/mediatek/{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} (51%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c (99%)
 delete mode 100644 sound/soc/mediatek/mtk-afe-common.h

-- 
1.9.1



[alsa-devel] [PATCH v3 2/9] ASoC: mediatek: implement mediatek common structure

2016-06-13 Thread Garlic Tseng
implement mediatek basic structure, include common private data,
afe fe dai operator and afe platform driver.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/common/mtk-afe-fe-dai.c | 379 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.h |  45 +++
 .../soc/mediatek/common/mtk-afe-platform-driver.c  |  90 +
 .../soc/mediatek/common/mtk-afe-platform-driver.h  |  23 ++
 sound/soc/mediatek/common/mtk-base-afe.h   | 104 ++
 5 files changed, 641 insertions(+)
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.h
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.h
 create mode 100644 sound/soc/mediatek/common/mtk-base-afe.h

diff --git a/sound/soc/mediatek/common/mtk-afe-fe-dai.c 
b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
new file mode 100644
index 000..d6b99d2
--- /dev/null
+++ b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
@@ -0,0 +1,379 @@
+/*
+ * mtk-afe-fe-dais.c  --  Mediatek afe fe dai operator
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng <garlic.ts...@mediatek.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "mtk-afe-fe-dai.h"
+#include "mtk-base-afe.h"
+
+#define AFE_BASE_END_OFFSET 8
+
+int mtk_regmap_update_bits(struct regmap *map, int reg, unsigned int mask,
+  unsigned int val)
+{
+   if (reg < 0)
+   return 0;
+   return regmap_update_bits(map, reg, mask, val);
+}
+
+int mtk_regmap_write(struct regmap *map, int reg, unsigned int val)
+{
+   if (reg < 0)
+   return 0;
+   return regmap_write(map, reg, val);
+}
+
+int mtk_afe_fe_startup(struct snd_pcm_substream *substream,
+  struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   int memif_num = rtd->cpu_dai->id;
+   struct mtk_base_afe_memif *memif = >memif[memif_num];
+   const struct snd_pcm_hardware *mtk_afe_hardware = afe->mtk_afe_hardware;
+   int ret;
+
+   memif->substream = substream;
+
+   snd_pcm_hw_constraint_step(substream->runtime, 0,
+  SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 16);
+   /*enable agent*/
+   mtk_regmap_update_bits(afe->regmap, memif->data->agent_disable_reg,
+  1 << memif->data->agent_disable_shift,
+  0 << memif->data->agent_disable_shift);
+
+   snd_soc_set_runtime_hwparams(substream, mtk_afe_hardware);
+
+   /*
+* Capture cannot use ping-pong buffer since hw_ptr at IRQ may be
+* smaller than period_size due to AFE's internal buffer.
+* This easily leads to overrun when avail_min is period_size.
+* One more period can hold the possible unread buffer.
+*/
+   if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+   int periods_max = mtk_afe_hardware->periods_max;
+
+   ret = snd_pcm_hw_constraint_minmax(runtime,
+  SNDRV_PCM_HW_PARAM_PERIODS,
+  3, periods_max);
+   if (ret < 0) {
+   dev_err(afe->dev, "hw_constraint_minmax failed\n");
+   return ret;
+   }
+   }
+
+   ret = snd_pcm_hw_constraint_integer(runtime,
+   SNDRV_PCM_HW_PARAM_PERIODS);
+   if (ret < 0)
+   dev_err(afe->dev, "snd_pcm_hw_constraint_integer failed\n");
+
+   /*dynamic allocate irq to memif */
+   if (memif->irq_usage < 0) {
+   int irq_id = mtk_dynamic_irq_acquire(afe);
+
+   if (irq_id != afe->irqs_size) {
+   /* link */
+   memif->irq_usage = irq_id;
+   } else {
+   dev_err(afe->dev, "%s() error: no more asys irq\n",
+   __func__);
+   ret = -EBUSY;
+   }
+   }
+   return ret;
+}
+EXPORT_SYM

[alsa-devel] [PATCH v3 2/9] ASoC: mediatek: implement mediatek common structure

2016-06-13 Thread Garlic Tseng
implement mediatek basic structure, include common private data,
afe fe dai operator and afe platform driver.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/common/mtk-afe-fe-dai.c | 379 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.h |  45 +++
 .../soc/mediatek/common/mtk-afe-platform-driver.c  |  90 +
 .../soc/mediatek/common/mtk-afe-platform-driver.h  |  23 ++
 sound/soc/mediatek/common/mtk-base-afe.h   | 104 ++
 5 files changed, 641 insertions(+)
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-fe-dai.h
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.c
 create mode 100644 sound/soc/mediatek/common/mtk-afe-platform-driver.h
 create mode 100644 sound/soc/mediatek/common/mtk-base-afe.h

diff --git a/sound/soc/mediatek/common/mtk-afe-fe-dai.c 
b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
new file mode 100644
index 000..d6b99d2
--- /dev/null
+++ b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
@@ -0,0 +1,379 @@
+/*
+ * mtk-afe-fe-dais.c  --  Mediatek afe fe dai operator
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "mtk-afe-fe-dai.h"
+#include "mtk-base-afe.h"
+
+#define AFE_BASE_END_OFFSET 8
+
+int mtk_regmap_update_bits(struct regmap *map, int reg, unsigned int mask,
+  unsigned int val)
+{
+   if (reg < 0)
+   return 0;
+   return regmap_update_bits(map, reg, mask, val);
+}
+
+int mtk_regmap_write(struct regmap *map, int reg, unsigned int val)
+{
+   if (reg < 0)
+   return 0;
+   return regmap_write(map, reg, val);
+}
+
+int mtk_afe_fe_startup(struct snd_pcm_substream *substream,
+  struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   int memif_num = rtd->cpu_dai->id;
+   struct mtk_base_afe_memif *memif = >memif[memif_num];
+   const struct snd_pcm_hardware *mtk_afe_hardware = afe->mtk_afe_hardware;
+   int ret;
+
+   memif->substream = substream;
+
+   snd_pcm_hw_constraint_step(substream->runtime, 0,
+  SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 16);
+   /*enable agent*/
+   mtk_regmap_update_bits(afe->regmap, memif->data->agent_disable_reg,
+  1 << memif->data->agent_disable_shift,
+  0 << memif->data->agent_disable_shift);
+
+   snd_soc_set_runtime_hwparams(substream, mtk_afe_hardware);
+
+   /*
+* Capture cannot use ping-pong buffer since hw_ptr at IRQ may be
+* smaller than period_size due to AFE's internal buffer.
+* This easily leads to overrun when avail_min is period_size.
+* One more period can hold the possible unread buffer.
+*/
+   if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+   int periods_max = mtk_afe_hardware->periods_max;
+
+   ret = snd_pcm_hw_constraint_minmax(runtime,
+  SNDRV_PCM_HW_PARAM_PERIODS,
+  3, periods_max);
+   if (ret < 0) {
+   dev_err(afe->dev, "hw_constraint_minmax failed\n");
+   return ret;
+   }
+   }
+
+   ret = snd_pcm_hw_constraint_integer(runtime,
+   SNDRV_PCM_HW_PARAM_PERIODS);
+   if (ret < 0)
+   dev_err(afe->dev, "snd_pcm_hw_constraint_integer failed\n");
+
+   /*dynamic allocate irq to memif */
+   if (memif->irq_usage < 0) {
+   int irq_id = mtk_dynamic_irq_acquire(afe);
+
+   if (irq_id != afe->irqs_size) {
+   /* link */
+   memif->irq_usage = irq_id;
+   } else {
+   dev_err(afe->dev, "%s() error: no more asys irq\n",
+   __func__);
+   ret = -EBUSY;
+   }
+   }
+   return ret;
+}
+EXPORT_SYMBOL_GPL(mtk_afe_fe_startup);
+
+void mtk_afe_fe_shutdown(struct snd_pcm_substre

[alsa-devel] [PATCH v3 9/9] ASoC: mediatek: Add mt2701-cs42448 driver and config option.

2016-06-13 Thread Garlic Tseng
Add machine driver and config option for MT2701.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/Kconfig |  21 ++
 sound/soc/mediatek/Makefile|   1 +
 sound/soc/mediatek/mt2701/Makefile |  19 ++
 sound/soc/mediatek/mt2701/mt2701-cs42448.c | 422 +
 4 files changed, 463 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index ff1a419..0ecb785 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -7,6 +7,27 @@ config SND_SOC_MEDIATEK
  Select Y if you have such device.
  If unsure select "N".
 
+config SND_SOC_MT2701
+   tristate "ASoC support for Mediatek MT2701 chip"
+   depends on ARCH_MEDIATEK
+   select SND_SOC_MEDIATEK
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ that can be used with other codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
+config SND_SOC_MT2701_CS42448
+   tristate "SND_SOC_MT2701_CS42448"
+   depends on SND_SOC_MT2701
+   select SND_SOC_CS42XX8_I2C
+   select SND_SOC_BT_SCO
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ with the CS42448 codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
 config SND_SOC_MT8173
tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index 3d893be..5133215 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,3 +1,4 @@
 obj-$(CONFIG_SND_SOC_MEDIATEK) += common/
+obj-$(CONFIG_SND_SOC_MT2701) += mt2701/
 obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
 
diff --git a/sound/soc/mediatek/mt2701/Makefile 
b/sound/soc/mediatek/mt2701/Makefile
new file mode 100644
index 000..31c3d04
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/Makefile
@@ -0,0 +1,19 @@
+#
+# 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-mt2701-afe-objs := mt2701-afe-pcm.o mt2701-afe-clock-ctrl.o
+obj-$(CONFIG_SND_SOC_MT2701) += snd-soc-mt2701-afe.o
+
+# machine driver
+obj-$(CONFIG_SND_SOC_MT2701_CS42448) += mt2701-cs42448.o
diff --git a/sound/soc/mediatek/mt2701/mt2701-cs42448.c 
b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
new file mode 100644
index 000..0e48cb9
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
@@ -0,0 +1,422 @@
+/*
+ * mt2701-cs42448.c  --  MT2701 CS42448 ALSA SoC machine driver
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Ir Lian <ir.l...@mediatek.com>
+ *  Garlic Tseng <garlic.ts...@mediatek.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+struct mt2701_cs42448_private {
+   int i2s1_in_mux;
+   int i2s1_in_mux_gpio_sel_1;
+   int i2s1_in_mux_gpio_sel_2;
+};
+
+static const char * const i2sin_mux_switch_text[] = {
+   "ADC_SDOUT2",
+   "ADC_SDOUT3",
+   "I2S_IN_1",
+   "I2S_IN_2",
+};
+
+static const struct soc_enum i2sin_mux_enum =
+   SOC_ENUM_SINGLE_EXT(4, i2sin_mux_switch_text);
+
+static int mt2701_cs42448_i2sin1_mux_get(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card);
+
+   ucontrol->value.integer.value[0] = priv->i2s1_in_mux;
+   return 0;
+}
+
+static int mt2701_cs42448_i2sin1_mux_set(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private

[alsa-devel] [PATCH v3 8/9] ASoC: mediatek: add BT implementation

2016-06-13 Thread Garlic Tseng
Add BT implementation for mt2701 platform driver.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 139 +
 1 file changed, 139 insertions(+)

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
index deb5f82..5fd2caa 100644
--- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -377,6 +377,86 @@ static int mt2701_afe_i2s_set_fmt(struct snd_soc_dai *dai, 
unsigned int fmt)
return 0;
 }
 
+static int mt2701_btmrg_startup(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF, 0);
+
+   afe_priv->mrg_enable[substream->stream] = 1;
+   return 0;
+}
+
+static int mt2701_btmrg_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   int stream_fs;
+   u32 val, msk;
+
+   stream_fs = params_rate(params);
+
+   if ((stream_fs != 8000) && (stream_fs != 16000)) {
+   dev_err(afe->dev, "%s() btmgr not supprt this stream_fs %d\n",
+   __func__, stream_fs);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_I2S_MODE_MASK,
+  AFE_MRGIF_CON_I2S_MODE_32K);
+
+   val = AFE_DAIBT_CON0_BT_FUNC_EN | AFE_DAIBT_CON0_BT_FUNC_RDY
+ | AFE_DAIBT_CON0_MRG_USE;
+   msk = val;
+
+   if (stream_fs == 16000)
+   val |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   msk |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0, msk, val);
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN,
+  AFE_DAIBT_CON0_DAIBT_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN,
+  AFE_MRGIF_CON_MRG_I2S_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN,
+  AFE_MRGIF_CON_MRG_EN);
+   return 0;
+}
+
+static void mt2701_btmrg_shutdown(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   /* if the other direction stream is not occupied */
+   if (!afe_priv->mrg_enable[!substream->stream]) {
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN, 0);
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF,
+  AUDIO_TOP_CON4_PDN_MRGIF);
+   }
+   afe_priv->mrg_enable[substream->stream] = 0;
+}
+
 static int mt2701_simple_fe_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
 {
@@ -560,6 +640,13 @@ static const struct snd_soc_dai_ops mt2701_afe_i2s_ops = {
.set_fmt= mt2701_afe_i2s_set_fmt,
 };
 
+/* MRG BE DAIs */
+static struct snd_soc_dai_ops mt2701_btmrg_ops = {
+   .startup = mt2701_btmrg_startup,
+   .shutdown = mt2701_btmrg_shutdown,
+   .hw_params = mt2701_btmrg_hw_params,
+};
+
 static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
/* FE DAIs: memory intefaces to CPU */
{
@@ -610,6 +697,36 @@ static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
},
.ops = _single_memif_dai_ops,
},
+   {
+   .name = "PCM_BT_DL",
+   .id = MT2701_MEMIF_DLBT,
+   .suspend = mtk_afe_dai_suspend,
+   .resume = mtk_afe_dai_resume,
+   .playback = {
+ 

[alsa-devel] [PATCH v3 9/9] ASoC: mediatek: Add mt2701-cs42448 driver and config option.

2016-06-13 Thread Garlic Tseng
Add machine driver and config option for MT2701.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/Kconfig |  21 ++
 sound/soc/mediatek/Makefile|   1 +
 sound/soc/mediatek/mt2701/Makefile |  19 ++
 sound/soc/mediatek/mt2701/mt2701-cs42448.c | 422 +
 4 files changed, 463 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/Makefile
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-cs42448.c

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index ff1a419..0ecb785 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -7,6 +7,27 @@ config SND_SOC_MEDIATEK
  Select Y if you have such device.
  If unsure select "N".
 
+config SND_SOC_MT2701
+   tristate "ASoC support for Mediatek MT2701 chip"
+   depends on ARCH_MEDIATEK
+   select SND_SOC_MEDIATEK
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ that can be used with other codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
+config SND_SOC_MT2701_CS42448
+   tristate "SND_SOC_MT2701_CS42448"
+   depends on SND_SOC_MT2701
+   select SND_SOC_CS42XX8_I2C
+   select SND_SOC_BT_SCO
+   help
+ This adds ASoC driver for Mediatek MT2701 boards
+ with the CS42448 codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
 config SND_SOC_MT8173
tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index 3d893be..5133215 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,3 +1,4 @@
 obj-$(CONFIG_SND_SOC_MEDIATEK) += common/
+obj-$(CONFIG_SND_SOC_MT2701) += mt2701/
 obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
 
diff --git a/sound/soc/mediatek/mt2701/Makefile 
b/sound/soc/mediatek/mt2701/Makefile
new file mode 100644
index 000..31c3d04
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/Makefile
@@ -0,0 +1,19 @@
+#
+# 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-mt2701-afe-objs := mt2701-afe-pcm.o mt2701-afe-clock-ctrl.o
+obj-$(CONFIG_SND_SOC_MT2701) += snd-soc-mt2701-afe.o
+
+# machine driver
+obj-$(CONFIG_SND_SOC_MT2701_CS42448) += mt2701-cs42448.o
diff --git a/sound/soc/mediatek/mt2701/mt2701-cs42448.c 
b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
new file mode 100644
index 000..0e48cb9
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-cs42448.c
@@ -0,0 +1,422 @@
+/*
+ * mt2701-cs42448.c  --  MT2701 CS42448 ALSA SoC machine driver
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Ir Lian 
+ *  Garlic Tseng 
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+struct mt2701_cs42448_private {
+   int i2s1_in_mux;
+   int i2s1_in_mux_gpio_sel_1;
+   int i2s1_in_mux_gpio_sel_2;
+};
+
+static const char * const i2sin_mux_switch_text[] = {
+   "ADC_SDOUT2",
+   "ADC_SDOUT3",
+   "I2S_IN_1",
+   "I2S_IN_2",
+};
+
+static const struct soc_enum i2sin_mux_enum =
+   SOC_ENUM_SINGLE_EXT(4, i2sin_mux_switch_text);
+
+static int mt2701_cs42448_i2sin1_mux_get(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card);
+
+   ucontrol->value.integer.value[0] = priv->i2s1_in_mux;
+   return 0;
+}
+
+static int mt2701_cs42448_i2sin1_mux_set(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+   struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card);
+
+   if (ucontrol->value.integer.value[

[alsa-devel] [PATCH v3 8/9] ASoC: mediatek: add BT implementation

2016-06-13 Thread Garlic Tseng
Add BT implementation for mt2701 platform driver.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 139 +
 1 file changed, 139 insertions(+)

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
index deb5f82..5fd2caa 100644
--- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -377,6 +377,86 @@ static int mt2701_afe_i2s_set_fmt(struct snd_soc_dai *dai, 
unsigned int fmt)
return 0;
 }
 
+static int mt2701_btmrg_startup(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF, 0);
+
+   afe_priv->mrg_enable[substream->stream] = 1;
+   return 0;
+}
+
+static int mt2701_btmrg_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   int stream_fs;
+   u32 val, msk;
+
+   stream_fs = params_rate(params);
+
+   if ((stream_fs != 8000) && (stream_fs != 16000)) {
+   dev_err(afe->dev, "%s() btmgr not supprt this stream_fs %d\n",
+   __func__, stream_fs);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_I2S_MODE_MASK,
+  AFE_MRGIF_CON_I2S_MODE_32K);
+
+   val = AFE_DAIBT_CON0_BT_FUNC_EN | AFE_DAIBT_CON0_BT_FUNC_RDY
+ | AFE_DAIBT_CON0_MRG_USE;
+   msk = val;
+
+   if (stream_fs == 16000)
+   val |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   msk |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0, msk, val);
+
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN,
+  AFE_DAIBT_CON0_DAIBT_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN,
+  AFE_MRGIF_CON_MRG_I2S_EN);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN,
+  AFE_MRGIF_CON_MRG_EN);
+   return 0;
+}
+
+static void mt2701_btmrg_shutdown(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+
+   /* if the other direction stream is not occupied */
+   if (!afe_priv->mrg_enable[!substream->stream]) {
+   regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
+  AFE_DAIBT_CON0_DAIBT_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_EN, 0);
+   regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
+  AFE_MRGIF_CON_MRG_I2S_EN, 0);
+   regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
+  AUDIO_TOP_CON4_PDN_MRGIF,
+  AUDIO_TOP_CON4_PDN_MRGIF);
+   }
+   afe_priv->mrg_enable[substream->stream] = 0;
+}
+
 static int mt2701_simple_fe_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
 {
@@ -560,6 +640,13 @@ static const struct snd_soc_dai_ops mt2701_afe_i2s_ops = {
.set_fmt= mt2701_afe_i2s_set_fmt,
 };
 
+/* MRG BE DAIs */
+static struct snd_soc_dai_ops mt2701_btmrg_ops = {
+   .startup = mt2701_btmrg_startup,
+   .shutdown = mt2701_btmrg_shutdown,
+   .hw_params = mt2701_btmrg_hw_params,
+};
+
 static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
/* FE DAIs: memory intefaces to CPU */
{
@@ -610,6 +697,36 @@ static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
},
.ops = _single_memif_dai_ops,
},
+   {
+   .name = "PCM_BT_DL",
+   .id = MT2701_MEMIF_DLBT,
+   .suspend = mtk_afe_dai_suspend,
+   .resume = mtk_afe_dai_resume,
+   .playback = {
+   .stream_name = "DLBT",
+  

[alsa-devel] [PATCH v3 6/9] ASoC: mediatek: add mt2701 platform driver implementation.

2016-06-13 Thread Garlic Tseng
Add mt2701 platform driver implementation for playback and capture.
The implement follow DAPM structure (memory interface as FE and I2S
as BE).
Because of the hardware design, i2s out required to be enabled when
we need to enable i2s in. This patch includes the implementation.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 1559 
 1 file changed, 1559 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
new file mode 100644
index 000..deb5f82
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -0,0 +1,1559 @@
+/*
+ * Mediatek ALSA SoC AFE platform driver for 2701
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng <garlic.ts...@mediatek.com>
+ * Ir Lian <ir.l...@mediatek.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+#include "mt2701-afe-clock-ctrl.h"
+#include "../common/mtk-afe-platform-driver.h"
+#include "../common/mtk-afe-fe-dai.h"
+
+#define AFE_IRQ_STATUS_BITS0xff
+
+static const struct snd_pcm_hardware mt2701_afe_hardware = {
+   .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED
+   | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE
+  | SNDRV_PCM_FMTBIT_S32_LE,
+   .period_bytes_min = 1024,
+   .period_bytes_max = 1024 * 256,
+   .periods_min = 4,
+   .periods_max = 1024,
+   .buffer_bytes_max = 1024 * 1024 * 16,
+   .fifo_size = 0,
+};
+
+struct mt2701_afe_rate {
+   unsigned int rate;
+   unsigned int regvalue;
+};
+
+static const struct mt2701_afe_rate mt2701_afe_i2s_rates[] = {
+   { .rate = 8000, .regvalue = 0 },
+   { .rate = 12000, .regvalue = 1 },
+   { .rate = 16000, .regvalue = 2 },
+   { .rate = 24000, .regvalue = 3 },
+   { .rate = 32000, .regvalue = 4 },
+   { .rate = 48000, .regvalue = 5 },
+   { .rate = 96000, .regvalue = 6 },
+   { .rate = 192000, .regvalue = 7 },
+   { .rate = 384000, .regvalue = 8 },
+   { .rate = 7350, .regvalue = 16 },
+   { .rate = 11025, .regvalue = 17 },
+   { .rate = 14700, .regvalue = 18 },
+   { .rate = 22050, .regvalue = 19 },
+   { .rate = 29400, .regvalue = 20 },
+   { .rate = 44100, .regvalue = 21 },
+   { .rate = 88200, .regvalue = 22 },
+   { .rate = 176400, .regvalue = 23 },
+   { .rate = 352800, .regvalue = 24 },
+};
+
+int mt2701_dai_num_to_i2s(struct mtk_base_afe *afe, int num)
+{
+   int val = num - MT2701_IO_I2S;
+
+   if (val < 0 || val >= MT2701_I2S_NUM) {
+   dev_err(afe->dev, "%s, num not available, num %d, val %d\n",
+   __func__, num, val);
+   return -EINVAL;
+   }
+   return val;
+}
+
+static int mt2701_afe_i2s_fs(unsigned int sample_rate)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(mt2701_afe_i2s_rates); i++)
+   if (mt2701_afe_i2s_rates[i].rate == sample_rate)
+   return mt2701_afe_i2s_rates[i].regvalue;
+
+   return -EINVAL;
+}
+
+static int mt2701_afe_i2s_startup(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+   int i2s_num = mt2701_dai_num_to_i2s(afe, dai->id);
+   int clk_num = MT2701_AUD_AUD_I2S1_MCLK + i2s_num;
+   int ret = 0;
+
+   if (i2s_num < 0)
+   return i2s_num;
+
+   /* enable mclk */
+   ret = clk_prepare_enable(afe_priv->clocks[clk_num]);
+   if (ret)
+   dev_err(afe->dev, "Failed to enable mclk for I2S: %d\n",
+   i2s_num);
+
+   return ret;
+}
+
+static int mt2701_afe_i2s_path_shutdown(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai,
+   int dir_invert)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform

[alsa-devel] [PATCH v3 6/9] ASoC: mediatek: add mt2701 platform driver implementation.

2016-06-13 Thread Garlic Tseng
Add mt2701 platform driver implementation for playback and capture.
The implement follow DAPM structure (memory interface as FE and I2S
as BE).
Because of the hardware design, i2s out required to be enabled when
we need to enable i2s in. This patch includes the implementation.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 1559 
 1 file changed, 1559 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-pcm.c

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
new file mode 100644
index 000..deb5f82
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c
@@ -0,0 +1,1559 @@
+/*
+ * Mediatek ALSA SoC AFE platform driver for 2701
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng 
+ * Ir Lian 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+
+#include "mt2701-afe-clock-ctrl.h"
+#include "../common/mtk-afe-platform-driver.h"
+#include "../common/mtk-afe-fe-dai.h"
+
+#define AFE_IRQ_STATUS_BITS0xff
+
+static const struct snd_pcm_hardware mt2701_afe_hardware = {
+   .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED
+   | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID,
+   .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE
+  | SNDRV_PCM_FMTBIT_S32_LE,
+   .period_bytes_min = 1024,
+   .period_bytes_max = 1024 * 256,
+   .periods_min = 4,
+   .periods_max = 1024,
+   .buffer_bytes_max = 1024 * 1024 * 16,
+   .fifo_size = 0,
+};
+
+struct mt2701_afe_rate {
+   unsigned int rate;
+   unsigned int regvalue;
+};
+
+static const struct mt2701_afe_rate mt2701_afe_i2s_rates[] = {
+   { .rate = 8000, .regvalue = 0 },
+   { .rate = 12000, .regvalue = 1 },
+   { .rate = 16000, .regvalue = 2 },
+   { .rate = 24000, .regvalue = 3 },
+   { .rate = 32000, .regvalue = 4 },
+   { .rate = 48000, .regvalue = 5 },
+   { .rate = 96000, .regvalue = 6 },
+   { .rate = 192000, .regvalue = 7 },
+   { .rate = 384000, .regvalue = 8 },
+   { .rate = 7350, .regvalue = 16 },
+   { .rate = 11025, .regvalue = 17 },
+   { .rate = 14700, .regvalue = 18 },
+   { .rate = 22050, .regvalue = 19 },
+   { .rate = 29400, .regvalue = 20 },
+   { .rate = 44100, .regvalue = 21 },
+   { .rate = 88200, .regvalue = 22 },
+   { .rate = 176400, .regvalue = 23 },
+   { .rate = 352800, .regvalue = 24 },
+};
+
+int mt2701_dai_num_to_i2s(struct mtk_base_afe *afe, int num)
+{
+   int val = num - MT2701_IO_I2S;
+
+   if (val < 0 || val >= MT2701_I2S_NUM) {
+   dev_err(afe->dev, "%s, num not available, num %d, val %d\n",
+   __func__, num, val);
+   return -EINVAL;
+   }
+   return val;
+}
+
+static int mt2701_afe_i2s_fs(unsigned int sample_rate)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(mt2701_afe_i2s_rates); i++)
+   if (mt2701_afe_i2s_rates[i].rate == sample_rate)
+   return mt2701_afe_i2s_rates[i].regvalue;
+
+   return -EINVAL;
+}
+
+static int mt2701_afe_i2s_startup(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+   int i2s_num = mt2701_dai_num_to_i2s(afe, dai->id);
+   int clk_num = MT2701_AUD_AUD_I2S1_MCLK + i2s_num;
+   int ret = 0;
+
+   if (i2s_num < 0)
+   return i2s_num;
+
+   /* enable mclk */
+   ret = clk_prepare_enable(afe_priv->clocks[clk_num]);
+   if (ret)
+   dev_err(afe->dev, "Failed to enable mclk for I2S: %d\n",
+   i2s_num);
+
+   return ret;
+}
+
+static int mt2701_afe_i2s_path_shutdown(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai,
+   int dir_invert)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+   struct mt2701_afe_private *afe_priv = afe->platform_pri

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

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

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/Kconfig|  11 +
 sound/soc/mediatek/Makefile   |   3 +-
 sound/soc/mediatek/common/Makefile|  17 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h |  42 +-
 sound/soc/mediatek/mt8173/mt8173-afe-pcm.c| 679 +++---
 5 files changed, 327 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..ff1a419 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,6 +1,16 @@
+config SND_SOC_MEDIATEK
+   tristate "SND_SOC_MEDIATEK"
+   depends on ARCH_MEDIATEK
+   help
+ This adds ASoC driver for Mediatek boards
+ that can be used with other codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
 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.
@@ -49,3 +59,4 @@ config SND_SOC_MT8173_RT5650_RT5676
  with the RT5650 and RT5676 codecs.
  Select Y if you have such device.
  If unsure select "N".
+
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index 240dfc70..3d893be 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,2 +1,3 @@
-# 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..0fcd921
--- /dev/null
+++ b/sound/soc/mediatek/common/Makefile
@@ -0,0 +1,17 @@
+#
+# 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 mt817

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

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

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/Kconfig|  11 +
 sound/soc/mediatek/Makefile   |   3 +-
 sound/soc/mediatek/common/Makefile|  17 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h |  42 +-
 sound/soc/mediatek/mt8173/mt8173-afe-pcm.c| 679 +++---
 5 files changed, 327 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..ff1a419 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,6 +1,16 @@
+config SND_SOC_MEDIATEK
+   tristate "SND_SOC_MEDIATEK"
+   depends on ARCH_MEDIATEK
+   help
+ This adds ASoC driver for Mediatek boards
+ that can be used with other codecs.
+ Select Y if you have such device.
+ If unsure select "N".
+
 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.
@@ -49,3 +59,4 @@ config SND_SOC_MT8173_RT5650_RT5676
  with the RT5650 and RT5676 codecs.
  Select Y if you have such device.
  If unsure select "N".
+
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index 240dfc70..3d893be 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,2 +1,3 @@
-# 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..0fcd921
--- /dev/null
+++ b/sound/soc/mediatek/common/Makefile
@@ -0,0 +1,17 @@
+#
+# 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 io

[alsa-devel] [PATCH v3 5/9] ASoC: mediatek: add structure define and clock control for 2701

2016-06-13 Thread Garlic Tseng
add structure define and clock control function for 2701.

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c | 464 ++
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h |  38 ++
 sound/soc/mediatek/mt2701/mt2701-afe-common.h | 181 +
 sound/soc/mediatek/mt2701/mt2701-reg.h| 186 +
 4 files changed, 869 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-common.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-reg.h

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
new file mode 100644
index 000..b815ecc
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
@@ -0,0 +1,464 @@
+/*
+ * mt2701-afe-clock-ctrl.c  --  Mediatek 2701 afe clock ctrl
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng <garlic.ts...@mediatek.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+#include "mt2701-afe-clock-ctrl.h"
+
+static const char *aud_clks[MT2701_CLOCK_NUM] = {
+   [MT2701_AUD_INFRA_SYS_AUDIO] = "infra_sys_audio_clk",
+   [MT2701_AUD_AUD_MUX1_SEL] = "top_audio_mux1_sel",
+   [MT2701_AUD_AUD_MUX2_SEL] = "top_audio_mux2_sel",
+   [MT2701_AUD_AUD_MUX1_DIV] = "top_audio_mux1_div",
+   [MT2701_AUD_AUD_MUX2_DIV] = "top_audio_mux2_div",
+   [MT2701_AUD_AUD_48K_TIMING] = "top_audio_48k_timing",
+   [MT2701_AUD_AUD_44K_TIMING] = "top_audio_44k_timing",
+   [MT2701_AUD_AUDPLL_MUX_SEL] = "top_audpll_mux_sel",
+   [MT2701_AUD_APLL_SEL] = "top_apll_sel",
+   [MT2701_AUD_AUD1PLL_98M] = "top_aud1_pll_98M",
+   [MT2701_AUD_AUD2PLL_90M] = "top_aud2_pll_90M",
+   [MT2701_AUD_HADDS2PLL_98M] = "top_hadds2_pll_98M",
+   [MT2701_AUD_HADDS2PLL_294M] = "top_hadds2_pll_294M",
+   [MT2701_AUD_AUDPLL] = "top_audpll",
+   [MT2701_AUD_AUDPLL_D4] = "top_audpll_d4",
+   [MT2701_AUD_AUDPLL_D8] = "top_audpll_d8",
+   [MT2701_AUD_AUDPLL_D16] = "top_audpll_d16",
+   [MT2701_AUD_AUDPLL_D24] = "top_audpll_d24",
+   [MT2701_AUD_AUDINTBUS] = "top_audintbus_sel",
+   [MT2701_AUD_CLK_26M] = "clk_26m",
+   [MT2701_AUD_SYSPLL1_D4] = "top_syspll1_d4",
+   [MT2701_AUD_AUD_K1_SRC_SEL] = "top_aud_k1_src_sel",
+   [MT2701_AUD_AUD_K2_SRC_SEL] = "top_aud_k2_src_sel",
+   [MT2701_AUD_AUD_K3_SRC_SEL] = "top_aud_k3_src_sel",
+   [MT2701_AUD_AUD_K4_SRC_SEL] = "top_aud_k4_src_sel",
+   [MT2701_AUD_AUD_K5_SRC_SEL] = "top_aud_k5_src_sel",
+   [MT2701_AUD_AUD_K6_SRC_SEL] = "top_aud_k6_src_sel",
+   [MT2701_AUD_AUD_K1_SRC_DIV] = "top_aud_k1_src_div",
+   [MT2701_AUD_AUD_K2_SRC_DIV] = "top_aud_k2_src_div",
+   [MT2701_AUD_AUD_K3_SRC_DIV] = "top_aud_k3_src_div",
+   [MT2701_AUD_AUD_K4_SRC_DIV] = "top_aud_k4_src_div",
+   [MT2701_AUD_AUD_K5_SRC_DIV] = "top_aud_k5_src_div",
+   [MT2701_AUD_AUD_K6_SRC_DIV] = "top_aud_k6_src_div",
+   [MT2701_AUD_AUD_I2S1_MCLK] = "top_aud_i2s1_mclk",
+   [MT2701_AUD_AUD_I2S2_MCLK] = "top_aud_i2s2_mclk",
+   [MT2701_AUD_AUD_I2S3_MCLK] = "top_aud_i2s3_mclk",
+   [MT2701_AUD_AUD_I2S4_MCLK] = "top_aud_i2s4_mclk",
+   [MT2701_AUD_AUD_I2S5_MCLK] = "top_aud_i2s5_mclk",
+   [MT2701_AUD_AUD_I2S6_MCLK] = "top_aud_i2s6_mclk",
+   [MT2701_AUD_ASM_M_SEL] = "top_asm_m_sel",
+   [MT2701_AUD_ASM_H_SEL] = "top_asm_h_sel",
+   [MT2701_AUD_UNIVPLL2_D4] = "top_univpll2_d4",
+   [MT2701_AUD_UNIVPLL2_D2] = "top_univpll2_d2",
+   [MT2701_AUD_SYSPLL_D5] = "top_syspll_d5",
+};
+
+int mt2701_init_clock(struct mtk_base_afe *afe)
+{
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+   int i = 0;
+
+   for (i = 0; i < MT2701_CLOCK_NUM; i++) {
+   afe_priv->clocks[i] = devm_clk_get(afe->dev, aud_clks[i]);
+   

[alsa-devel] [PATCH v3 1/9] ASoC: mediatek: Refine mt8173 driver and change config option

2016-06-13 Thread Garlic Tseng
move mt8173 driver to another folder and add prefix.
add config option SND_SOC_MT8173

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 sound/soc/mediatek/Kconfig |  14 +-
 sound/soc/mediatek/Makefile|   9 +-
 sound/soc/mediatek/mt8173/Makefile |   7 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h  | 101 +
 .../{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} | 494 ++---
 sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c  |   2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c   |   2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c   |   4 +-
 sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c|   2 +-
 sound/soc/mediatek/mtk-afe-common.h| 101 -
 10 files changed, 367 insertions(+), 369 deletions(-)
 create mode 100644 sound/soc/mediatek/mt8173/Makefile
 create mode 100644 sound/soc/mediatek/mt8173/mt8173-afe-common.h
 rename sound/soc/mediatek/{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} (66%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c (99%)
 delete mode 100644 sound/soc/mediatek/mtk-afe-common.h

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index 3abf51c..ae9f664 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,15 +1,15 @@
-config SND_SOC_MEDIATEK
-   tristate "ASoC support for Mediatek chip"
+config SND_SOC_MT8173
+   tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
help
- This adds ASoC platform driver support for Mediatek chip
+ This adds ASoC platform driver support for Mediatek MT8173 chip
  that can be used with other codecs.
  Select Y if you have such device.
  Ex: MT8173
 
 config SND_SOC_MT8173_MAX98090
tristate "ASoC Audio driver for MT8173 with MAX98090 codec"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_MAX98090
help
  This adds ASoC driver for Mediatek MT8173 boards
@@ -19,7 +19,7 @@ config SND_SOC_MT8173_MAX98090
 
 config SND_SOC_MT8173_RT5650
tristate "ASoC Audio driver for MT8173 with RT5650 codec"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
help
  This adds ASoC driver for Mediatek MT8173 boards
@@ -29,7 +29,7 @@ config SND_SOC_MT8173_RT5650
 
 config SND_SOC_MT8173_RT5650_RT5514
tristate "ASoC Audio driver for MT8173 with RT5650 RT5514 codecs"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
select SND_SOC_RT5514
help
@@ -40,7 +40,7 @@ config SND_SOC_MT8173_RT5650_RT5514
 
 config SND_SOC_MT8173_RT5650_RT5676
tristate "ASoC Audio driver for MT8173 with RT5650 RT5676 codecs"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
select SND_SOC_RT5677
select SND_SOC_HDMI_CODEC
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index d486860..240dfc70 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,7 +1,2 @@
-# MTK Platform Support
-obj-$(CONFIG_SND_SOC_MEDIATEK) += mtk-afe-pcm.o
-# Machine support
-obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650) += mt8173-rt5650.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5514) += mt8173-rt5650-rt5514.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5676) += mt8173-rt5650-rt5676.o
+# 8173 Machine support
+obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
diff --git a/sound/soc/mediatek/mt8173/Makefile 
b/sound/soc/mediatek/mt8173/Makefile
new file mode 100644
index 000..0357b27
--- /dev/null
+++ b/sound/soc/mediatek/mt8173/Makefile
@@ -0,0 +1,7 @@
+# MTK Platform Support
+obj-$(CONFIG_SND_SOC_MT8173) += mt8173-afe-pcm.o
+# Machine support
+obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650) += mt8173-rt5650.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5514) += mt8173-rt5650-rt5514.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5676) += mt8173-rt5650-rt5676.o
diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-common.h 
b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
new file mode 100644
index 000..8f2936d
--- /dev/null
+++ b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
@@ -0,0 +1,101 @@
+/*
+ * mt8173_afe_common.h  --  Mediatek 8173 audio driver common definitions
+ *
+ * Copyright (c) 2015 MediaTek Inc.
+ * Author: Koro Chen <koro.c...@mediatek.

[alsa-devel] [PATCH v3 4/9] ASoC: mediatek: add documents for mt2701

2016-06-13 Thread Garlic Tseng
add mt2701-afe-pcm.txt and mt2701-cs42448.txt for mt2701

Signed-off-by: Garlic Tseng <garlic.ts...@mediatek.com>
---
 .../devicetree/bindings/sound/mt2701-afe-pcm.txt   | 150 +
 .../devicetree/bindings/sound/mt2701-cs42448.txt   |  43 ++
 2 files changed, 193 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-cs42448.txt

diff --git a/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt 
b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
new file mode 100644
index 000..3e623a7
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
@@ -0,0 +1,150 @@
+Mediatek AFE PCM controller for mt2701
+
+Required properties:
+- compatible = "mediatek,mt2701-audio";
+- reg: register location and size
+- interrupts: Should contain AFE interrupt
+- clock-names: should have these clock names:
+   "infra_sys_audio_clk",
+   "top_audio_mux1_sel",
+   "top_audio_mux2_sel",
+   "top_audio_mux1_div",
+   "top_audio_mux2_div",
+   "top_audio_48k_timing",
+   "top_audio_44k_timing",
+   "top_audpll_mux_sel",
+   "top_apll_sel",
+   "top_aud1_pll_98M",
+   "top_aud2_pll_90M",
+   "top_hadds2_pll_98M",
+   "top_hadds2_pll_294M",
+   "top_audpll",
+   "top_audpll_d4",
+   "top_audpll_d8",
+   "top_audpll_d16",
+   "top_audpll_d24",
+   "top_audintbus_sel",
+   "clk_26m",
+   "top_syspll1_d4",
+   "top_aud_k1_src_sel",
+   "top_aud_k2_src_sel",
+   "top_aud_k3_src_sel",
+   "top_aud_k4_src_sel",
+   "top_aud_k5_src_sel",
+   "top_aud_k6_src_sel",
+   "top_aud_k1_src_div",
+   "top_aud_k2_src_div",
+   "top_aud_k3_src_div",
+   "top_aud_k4_src_div",
+   "top_aud_k5_src_div",
+   "top_aud_k6_src_div",
+   "top_aud_i2s1_mclk",
+   "top_aud_i2s2_mclk",
+   "top_aud_i2s3_mclk",
+   "top_aud_i2s4_mclk",
+   "top_aud_i2s5_mclk",
+   "top_aud_i2s6_mclk",
+   "top_asm_m_sel",
+   "top_asm_h_sel",
+   "top_univpll2_d4",
+   "top_univpll2_d2",
+   "top_syspll_d5";
+
+Example:
+
+   afe: mt2701-afe-pcm@1122 {
+   compatible = "mediatek,mt2701-audio";
+   reg = <0 0x1122 0 0x2000>,
+ <0 0x112A 0 0x2>;
+   interrupts = ,
+;
+   clocks = < CLK_INFRA_AUDIO>,
+< CLK_TOP_AUD_MUX1_SEL>,
+< CLK_TOP_AUD_MUX2_SEL>,
+< CLK_TOP_AUD_MUX1_DIV>,
+< CLK_TOP_AUD_MUX2_DIV>,
+< CLK_TOP_AUD_48K_TIMING>,
+< CLK_TOP_AUD_44K_TIMING>,
+< CLK_TOP_AUDPLL_MUX_SEL>,
+< CLK_TOP_APLL_SEL>,
+< CLK_TOP_AUD1PLL_98M>,
+< CLK_TOP_AUD2PLL_90M>,
+< CLK_TOP_HADDS2PLL_98M>,
+< CLK_TOP_HADDS2PLL_294M>,
+< CLK_TOP_AUDPLL>,
+< CLK_TOP_AUDPLL_D4>,
+< CLK_TOP_AUDPLL_D8>,
+< CLK_TOP_AUDPLL_D16>,
+< CLK_TOP_AUDPLL_D24>,
+< CLK_TOP_AUDINTBUS_SEL>,
+<>,
+< CLK_TOP_SYSPLL1_D4>,
+< CLK_TOP_AUD_K1_SRC_SEL>,
+< CLK_TOP_AUD_K2_SRC_SEL>,
+< CLK_TOP_AUD_K3_SRC_SEL>,
+< CLK_TOP_AUD_K4_SRC_SEL>,
+< CLK_TOP_AUD_K5_SRC_SEL>,
+< CLK_TOP_AUD_K6_SRC_SEL>,
+< CLK_TOP_AUD_K1_SRC_DIV>,
+< CLK_TOP_AUD_K2_SRC_DIV>,
+< CLK_TOP_AUD_K3_SRC_DI

[alsa-devel] [PATCH v3 5/9] ASoC: mediatek: add structure define and clock control for 2701

2016-06-13 Thread Garlic Tseng
add structure define and clock control function for 2701.

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c | 464 ++
 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h |  38 ++
 sound/soc/mediatek/mt2701/mt2701-afe-common.h | 181 +
 sound/soc/mediatek/mt2701/mt2701-reg.h| 186 +
 4 files changed, 869 insertions(+)
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-afe-common.h
 create mode 100644 sound/soc/mediatek/mt2701/mt2701-reg.h

diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c 
b/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
new file mode 100644
index 000..b815ecc
--- /dev/null
+++ b/sound/soc/mediatek/mt2701/mt2701-afe-clock-ctrl.c
@@ -0,0 +1,464 @@
+/*
+ * mt2701-afe-clock-ctrl.c  --  Mediatek 2701 afe clock ctrl
+ *
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Garlic Tseng 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#include 
+#include 
+#include 
+
+#include "mt2701-afe-common.h"
+#include "mt2701-afe-clock-ctrl.h"
+
+static const char *aud_clks[MT2701_CLOCK_NUM] = {
+   [MT2701_AUD_INFRA_SYS_AUDIO] = "infra_sys_audio_clk",
+   [MT2701_AUD_AUD_MUX1_SEL] = "top_audio_mux1_sel",
+   [MT2701_AUD_AUD_MUX2_SEL] = "top_audio_mux2_sel",
+   [MT2701_AUD_AUD_MUX1_DIV] = "top_audio_mux1_div",
+   [MT2701_AUD_AUD_MUX2_DIV] = "top_audio_mux2_div",
+   [MT2701_AUD_AUD_48K_TIMING] = "top_audio_48k_timing",
+   [MT2701_AUD_AUD_44K_TIMING] = "top_audio_44k_timing",
+   [MT2701_AUD_AUDPLL_MUX_SEL] = "top_audpll_mux_sel",
+   [MT2701_AUD_APLL_SEL] = "top_apll_sel",
+   [MT2701_AUD_AUD1PLL_98M] = "top_aud1_pll_98M",
+   [MT2701_AUD_AUD2PLL_90M] = "top_aud2_pll_90M",
+   [MT2701_AUD_HADDS2PLL_98M] = "top_hadds2_pll_98M",
+   [MT2701_AUD_HADDS2PLL_294M] = "top_hadds2_pll_294M",
+   [MT2701_AUD_AUDPLL] = "top_audpll",
+   [MT2701_AUD_AUDPLL_D4] = "top_audpll_d4",
+   [MT2701_AUD_AUDPLL_D8] = "top_audpll_d8",
+   [MT2701_AUD_AUDPLL_D16] = "top_audpll_d16",
+   [MT2701_AUD_AUDPLL_D24] = "top_audpll_d24",
+   [MT2701_AUD_AUDINTBUS] = "top_audintbus_sel",
+   [MT2701_AUD_CLK_26M] = "clk_26m",
+   [MT2701_AUD_SYSPLL1_D4] = "top_syspll1_d4",
+   [MT2701_AUD_AUD_K1_SRC_SEL] = "top_aud_k1_src_sel",
+   [MT2701_AUD_AUD_K2_SRC_SEL] = "top_aud_k2_src_sel",
+   [MT2701_AUD_AUD_K3_SRC_SEL] = "top_aud_k3_src_sel",
+   [MT2701_AUD_AUD_K4_SRC_SEL] = "top_aud_k4_src_sel",
+   [MT2701_AUD_AUD_K5_SRC_SEL] = "top_aud_k5_src_sel",
+   [MT2701_AUD_AUD_K6_SRC_SEL] = "top_aud_k6_src_sel",
+   [MT2701_AUD_AUD_K1_SRC_DIV] = "top_aud_k1_src_div",
+   [MT2701_AUD_AUD_K2_SRC_DIV] = "top_aud_k2_src_div",
+   [MT2701_AUD_AUD_K3_SRC_DIV] = "top_aud_k3_src_div",
+   [MT2701_AUD_AUD_K4_SRC_DIV] = "top_aud_k4_src_div",
+   [MT2701_AUD_AUD_K5_SRC_DIV] = "top_aud_k5_src_div",
+   [MT2701_AUD_AUD_K6_SRC_DIV] = "top_aud_k6_src_div",
+   [MT2701_AUD_AUD_I2S1_MCLK] = "top_aud_i2s1_mclk",
+   [MT2701_AUD_AUD_I2S2_MCLK] = "top_aud_i2s2_mclk",
+   [MT2701_AUD_AUD_I2S3_MCLK] = "top_aud_i2s3_mclk",
+   [MT2701_AUD_AUD_I2S4_MCLK] = "top_aud_i2s4_mclk",
+   [MT2701_AUD_AUD_I2S5_MCLK] = "top_aud_i2s5_mclk",
+   [MT2701_AUD_AUD_I2S6_MCLK] = "top_aud_i2s6_mclk",
+   [MT2701_AUD_ASM_M_SEL] = "top_asm_m_sel",
+   [MT2701_AUD_ASM_H_SEL] = "top_asm_h_sel",
+   [MT2701_AUD_UNIVPLL2_D4] = "top_univpll2_d4",
+   [MT2701_AUD_UNIVPLL2_D2] = "top_univpll2_d2",
+   [MT2701_AUD_SYSPLL_D5] = "top_syspll_d5",
+};
+
+int mt2701_init_clock(struct mtk_base_afe *afe)
+{
+   struct mt2701_afe_private *afe_priv = afe->platform_priv;
+   int i = 0;
+
+   for (i = 0; i < MT2701_CLOCK_NUM; i++) {
+   afe_priv->clocks[i] = devm_clk_get(afe->dev, aud_clks[i]);
+   if (IS_ERR(aud_clks[i])) {
+   dev_warn(afe->dev, 

[alsa-devel] [PATCH v3 1/9] ASoC: mediatek: Refine mt8173 driver and change config option

2016-06-13 Thread Garlic Tseng
move mt8173 driver to another folder and add prefix.
add config option SND_SOC_MT8173

Signed-off-by: Garlic Tseng 
---
 sound/soc/mediatek/Kconfig |  14 +-
 sound/soc/mediatek/Makefile|   9 +-
 sound/soc/mediatek/mt8173/Makefile |   7 +
 sound/soc/mediatek/mt8173/mt8173-afe-common.h  | 101 +
 .../{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} | 494 ++---
 sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c  |   2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c   |   2 +-
 .../mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c   |   4 +-
 sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c|   2 +-
 sound/soc/mediatek/mtk-afe-common.h| 101 -
 10 files changed, 367 insertions(+), 369 deletions(-)
 create mode 100644 sound/soc/mediatek/mt8173/Makefile
 create mode 100644 sound/soc/mediatek/mt8173/mt8173-afe-common.h
 rename sound/soc/mediatek/{mtk-afe-pcm.c => mt8173/mt8173-afe-pcm.c} (66%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-max98090.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5514.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650-rt5676.c (99%)
 rename sound/soc/mediatek/{ => mt8173}/mt8173-rt5650.c (99%)
 delete mode 100644 sound/soc/mediatek/mtk-afe-common.h

diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index 3abf51c..ae9f664 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -1,15 +1,15 @@
-config SND_SOC_MEDIATEK
-   tristate "ASoC support for Mediatek chip"
+config SND_SOC_MT8173
+   tristate "ASoC support for Mediatek MT8173 chip"
depends on ARCH_MEDIATEK
help
- This adds ASoC platform driver support for Mediatek chip
+ This adds ASoC platform driver support for Mediatek MT8173 chip
  that can be used with other codecs.
  Select Y if you have such device.
  Ex: MT8173
 
 config SND_SOC_MT8173_MAX98090
tristate "ASoC Audio driver for MT8173 with MAX98090 codec"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_MAX98090
help
  This adds ASoC driver for Mediatek MT8173 boards
@@ -19,7 +19,7 @@ config SND_SOC_MT8173_MAX98090
 
 config SND_SOC_MT8173_RT5650
tristate "ASoC Audio driver for MT8173 with RT5650 codec"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
help
  This adds ASoC driver for Mediatek MT8173 boards
@@ -29,7 +29,7 @@ config SND_SOC_MT8173_RT5650
 
 config SND_SOC_MT8173_RT5650_RT5514
tristate "ASoC Audio driver for MT8173 with RT5650 RT5514 codecs"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
select SND_SOC_RT5514
help
@@ -40,7 +40,7 @@ config SND_SOC_MT8173_RT5650_RT5514
 
 config SND_SOC_MT8173_RT5650_RT5676
tristate "ASoC Audio driver for MT8173 with RT5650 RT5676 codecs"
-   depends on SND_SOC_MEDIATEK && I2C
+   depends on SND_SOC_MT8173 && I2C
select SND_SOC_RT5645
select SND_SOC_RT5677
select SND_SOC_HDMI_CODEC
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index d486860..240dfc70 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -1,7 +1,2 @@
-# MTK Platform Support
-obj-$(CONFIG_SND_SOC_MEDIATEK) += mtk-afe-pcm.o
-# Machine support
-obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650) += mt8173-rt5650.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5514) += mt8173-rt5650-rt5514.o
-obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5676) += mt8173-rt5650-rt5676.o
+# 8173 Machine support
+obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
diff --git a/sound/soc/mediatek/mt8173/Makefile 
b/sound/soc/mediatek/mt8173/Makefile
new file mode 100644
index 000..0357b27
--- /dev/null
+++ b/sound/soc/mediatek/mt8173/Makefile
@@ -0,0 +1,7 @@
+# MTK Platform Support
+obj-$(CONFIG_SND_SOC_MT8173) += mt8173-afe-pcm.o
+# Machine support
+obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650) += mt8173-rt5650.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5514) += mt8173-rt5650-rt5514.o
+obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5676) += mt8173-rt5650-rt5676.o
diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-common.h 
b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
new file mode 100644
index 000..8f2936d
--- /dev/null
+++ b/sound/soc/mediatek/mt8173/mt8173-afe-common.h
@@ -0,0 +1,101 @@
+/*
+ * mt8173_afe_common.h  --  Mediatek 8173 audio driver common definitions
+ *
+ * Copyright (c) 2015 MediaTek Inc.
+ * Author: Koro Chen 
+ * Sascha Hauer 
+ * Hidalgo Huang 
+ * 

[alsa-devel] [PATCH v3 4/9] ASoC: mediatek: add documents for mt2701

2016-06-13 Thread Garlic Tseng
add mt2701-afe-pcm.txt and mt2701-cs42448.txt for mt2701

Signed-off-by: Garlic Tseng 
---
 .../devicetree/bindings/sound/mt2701-afe-pcm.txt   | 150 +
 .../devicetree/bindings/sound/mt2701-cs42448.txt   |  43 ++
 2 files changed, 193 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
 create mode 100644 Documentation/devicetree/bindings/sound/mt2701-cs42448.txt

diff --git a/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt 
b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
new file mode 100644
index 000..3e623a7
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/mt2701-afe-pcm.txt
@@ -0,0 +1,150 @@
+Mediatek AFE PCM controller for mt2701
+
+Required properties:
+- compatible = "mediatek,mt2701-audio";
+- reg: register location and size
+- interrupts: Should contain AFE interrupt
+- clock-names: should have these clock names:
+   "infra_sys_audio_clk",
+   "top_audio_mux1_sel",
+   "top_audio_mux2_sel",
+   "top_audio_mux1_div",
+   "top_audio_mux2_div",
+   "top_audio_48k_timing",
+   "top_audio_44k_timing",
+   "top_audpll_mux_sel",
+   "top_apll_sel",
+   "top_aud1_pll_98M",
+   "top_aud2_pll_90M",
+   "top_hadds2_pll_98M",
+   "top_hadds2_pll_294M",
+   "top_audpll",
+   "top_audpll_d4",
+   "top_audpll_d8",
+   "top_audpll_d16",
+   "top_audpll_d24",
+   "top_audintbus_sel",
+   "clk_26m",
+   "top_syspll1_d4",
+   "top_aud_k1_src_sel",
+   "top_aud_k2_src_sel",
+   "top_aud_k3_src_sel",
+   "top_aud_k4_src_sel",
+   "top_aud_k5_src_sel",
+   "top_aud_k6_src_sel",
+   "top_aud_k1_src_div",
+   "top_aud_k2_src_div",
+   "top_aud_k3_src_div",
+   "top_aud_k4_src_div",
+   "top_aud_k5_src_div",
+   "top_aud_k6_src_div",
+   "top_aud_i2s1_mclk",
+   "top_aud_i2s2_mclk",
+   "top_aud_i2s3_mclk",
+   "top_aud_i2s4_mclk",
+   "top_aud_i2s5_mclk",
+   "top_aud_i2s6_mclk",
+   "top_asm_m_sel",
+   "top_asm_h_sel",
+   "top_univpll2_d4",
+   "top_univpll2_d2",
+   "top_syspll_d5";
+
+Example:
+
+   afe: mt2701-afe-pcm@1122 {
+   compatible = "mediatek,mt2701-audio";
+   reg = <0 0x1122 0 0x2000>,
+ <0 0x112A 0 0x2>;
+   interrupts = ,
+;
+   clocks = < CLK_INFRA_AUDIO>,
+< CLK_TOP_AUD_MUX1_SEL>,
+< CLK_TOP_AUD_MUX2_SEL>,
+< CLK_TOP_AUD_MUX1_DIV>,
+< CLK_TOP_AUD_MUX2_DIV>,
+< CLK_TOP_AUD_48K_TIMING>,
+< CLK_TOP_AUD_44K_TIMING>,
+< CLK_TOP_AUDPLL_MUX_SEL>,
+< CLK_TOP_APLL_SEL>,
+< CLK_TOP_AUD1PLL_98M>,
+< CLK_TOP_AUD2PLL_90M>,
+< CLK_TOP_HADDS2PLL_98M>,
+< CLK_TOP_HADDS2PLL_294M>,
+< CLK_TOP_AUDPLL>,
+< CLK_TOP_AUDPLL_D4>,
+< CLK_TOP_AUDPLL_D8>,
+< CLK_TOP_AUDPLL_D16>,
+< CLK_TOP_AUDPLL_D24>,
+< CLK_TOP_AUDINTBUS_SEL>,
+<>,
+< CLK_TOP_SYSPLL1_D4>,
+< CLK_TOP_AUD_K1_SRC_SEL>,
+< CLK_TOP_AUD_K2_SRC_SEL>,
+< CLK_TOP_AUD_K3_SRC_SEL>,
+< CLK_TOP_AUD_K4_SRC_SEL>,
+< CLK_TOP_AUD_K5_SRC_SEL>,
+< CLK_TOP_AUD_K6_SRC_SEL>,
+< CLK_TOP_AUD_K1_SRC_DIV>,
+< CLK_TOP_AUD_K2_SRC_DIV>,
+< CLK_TOP_AUD_K3_SRC_DIV>,
+< CLK_TOP_AUD_K4_S

Re: [alsa-devel] [PATCH v2 6/9] ASoC: mediatek: add mt2701 platform driver implementation.

2016-06-07 Thread Garlic Tseng
On Tue, 2016-06-07 at 17:31 +0100, Mark Brown wrote:
> On Fri, Jun 03, 2016 at 12:56:21PM +0800, Garlic Tseng wrote:
> 
> > +   if (val < 0 || val > MT2701_I2S_NUM) {
> > +   dev_err(afe->dev, "%s, num not available, num %d, val %d\n",
> > +   __func__, num, val);
> > +   return -1;
> 
> Real error codes please.

OK I'll fix it.

> 
> > +static const struct snd_kcontrol_new mt2701_afe_multi_ch_out_asrc3[] = {
> > +   SOC_DAPM_SINGLE_AUTODISABLE("Multi ch asrc out3", PWR2_TOP_CON, 7, 1,
> > +   1),
> > +};
> 
> On/off controls should end in Switch.

Do you means that the name should end in Switch? Something like "Multi
ch asrc out3 Switch" (or maybe a shorter one)

I'll fix it (if I don't misunderstand the comment)

Thanks!

> ___
> Alsa-devel mailing list
> alsa-de...@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel




Re: [alsa-devel] [PATCH v2 6/9] ASoC: mediatek: add mt2701 platform driver implementation.

2016-06-07 Thread Garlic Tseng
On Tue, 2016-06-07 at 17:31 +0100, Mark Brown wrote:
> On Fri, Jun 03, 2016 at 12:56:21PM +0800, Garlic Tseng wrote:
> 
> > +   if (val < 0 || val > MT2701_I2S_NUM) {
> > +   dev_err(afe->dev, "%s, num not available, num %d, val %d\n",
> > +   __func__, num, val);
> > +   return -1;
> 
> Real error codes please.

OK I'll fix it.

> 
> > +static const struct snd_kcontrol_new mt2701_afe_multi_ch_out_asrc3[] = {
> > +   SOC_DAPM_SINGLE_AUTODISABLE("Multi ch asrc out3", PWR2_TOP_CON, 7, 1,
> > +   1),
> > +};
> 
> On/off controls should end in Switch.

Do you means that the name should end in Switch? Something like "Multi
ch asrc out3 Switch" (or maybe a shorter one)

I'll fix it (if I don't misunderstand the comment)

Thanks!

> ___
> Alsa-devel mailing list
> alsa-de...@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel




  1   2   >