Skip to contentSkip to conversation

ASoC: mediatek: Add support for MT7986 SoC

PATCH Superseded Maso Huang 5 participants 26 messages Jun 26, 2023 – Jul 24, 2023

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Maso Huang

author
#0 lore raw

v2 cover ASoC: mediatek: Add support for MT7986 SoC

Changes in v2:
- v1 title: [PATCH 0/7] ASoC: mediatek: Add support for MT79xx SoC
- add missing maintainers
- rename mt79xx to mt7986 in all files
- use clk bulk api in mt7986-afe-clk.c [2/7]
- refine mt7986-afe-pcm.c based on reviewer's suggestions [4/7]
- refine dt-binding files based on reviewer's suggestions [6/7] [7/7]
- transpose [3/7] and [4/7] in v1 to fix test build errors

This series of patches adds support for MediaTek AFE of MT7986 SoC. Patches are based on broonie tree "for-next" branch.

Maso Huang (7):
ASoC: mediatek: mt7986: add common header
ASoC: mediatek: mt7986: support audio clock control
ASoC: mediatek: mt7986: support etdm in platform driver
ASoC: mediatek: mt7986: add platform driver
ASoC: mediatek: mt7986: add machine driver with wm8960
ASoC: dt-bindings: mediatek,mt7986-wm8960: add mt7986-wm8960 document
ASoC: dt-bindings: mediatek,mt7986-afe: add audio afe document

 .../bindings/sound/mediatek,mt7986-afe.yaml   |  89 +++
 .../sound/mediatek,mt7986-wm8960.yaml         |  53 ++
 sound/soc/mediatek/Kconfig                    |  20 +
 sound/soc/mediatek/Makefile                   |   1 +
 sound/soc/mediatek/mt7986/Makefile            |  10 +
 sound/soc/mediatek/mt7986/mt7986-afe-clk.c    |  75 +++
 sound/soc/mediatek/mt7986/mt7986-afe-clk.h    |  18 +
 sound/soc/mediatek/mt7986/mt7986-afe-common.h |  51 ++
 sound/soc/mediatek/mt7986/mt7986-afe-pcm.c    | 598 ++++++++++++++++++
 sound/soc/mediatek/mt7986/mt7986-dai-etdm.c   | 421 ++++++++++++
 sound/soc/mediatek/mt7986/mt7986-reg.h        | 206 ++++++
 sound/soc/mediatek/mt7986/mt7986-wm8960.c     | 184 ++++++
 12 files changed, 1726 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mediatek,mt7986-afe.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/mediatek,mt7986-wm8960.yaml
 create mode 100644 sound/soc/mediatek/mt7986/Makefile
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-clk.c
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-clk.h
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-common.h
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-pcm.c
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-dai-etdm.c
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-reg.h
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-wm8960.c
Signature · 1 line
2.18.0
author
#1 lore raw

PATCH v2 1/7 ASoC: mediatek: mt7986: add common header

Add header files for register definition and structure.

---
 sound/soc/mediatek/mt7986/mt7986-afe-common.h |  51 +++++
 sound/soc/mediatek/mt7986/mt7986-reg.h        | 206 ++++++++++++++++++
 2 files changed, 257 insertions(+)
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-common.h
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-reg.h
sound/soc/mediatek/mt7986/mt7986-afe-common.h new file +51 -0
new file mode 100644
index 000000000000..646e1be4fdce
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * mt7986-afe-common.h  --  MediaTek 7986 audio driver definitions
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#ifndef _MT_7986_AFE_COMMON_H_
+#define _MT_7986_AFE_COMMON_H_
+
+#include <sound/soc.h>
+#include <linux/clk.h>
+#include <linux/list.h>
+#include <linux/regmap.h>
+#include "../common/mtk-base-afe.h"
+
+enum {
+	MT7986_MEMIF_DL1,
+	MT7986_MEMIF_VUL12,
+	MT7986_MEMIF_NUM,
+	MT7986_DAI_ETDM = MT7986_MEMIF_NUM,
+	MT7986_DAI_NUM,
+};
+
+enum {
+	MT7986_IRQ_0,
+	MT7986_IRQ_1,
+	MT7986_IRQ_2,
+	MT7986_IRQ_NUM,
+};
+
+struct clk;
+
+struct mt7986_afe_private {
+	struct clk_bulk_data *clks;
+	int num_clks;
+
+	int pm_runtime_bypass_reg_ctl;
+
+	/* dai */
+	void *dai_priv[MT7986_DAI_NUM];
+};
+
+unsigned int mt7986_afe_rate_transform(struct device *dev,
+				       unsigned int rate);
+
+/* dai register */
+int mt7986_dai_etdm_register(struct mtk_base_afe *afe);
+#endif
sound/soc/mediatek/mt7986/mt7986-reg.h new file +206 -0

206 lines not on this page · raw message

Signature · 1 line
2.18.0
maintainer Reviewed-by on v2 1/7
#2 lore raw

Re: [PATCH v2 1/7] ASoC: mediatek: mt7986: add common header

Il 26/06/23 04:34, Maso Huang ha scritto:

Quoted 84 lines

Add header files for register definition and structure.

---
  sound/soc/mediatek/mt7986/mt7986-afe-common.h |  51 +++++
  sound/soc/mediatek/mt7986/mt7986-reg.h        | 206 ++++++++++++++++++
  2 files changed, 257 insertions(+)

create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-common.h create mode 100644 sound/soc/mediatek/mt7986/mt7986-reg.h

sound/soc/mediatek/mt7986/mt7986-afe-common.h new file +51 -0
new file mode 100644
index 000000000000..646e1be4fdce
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * mt7986-afe-common.h  --  MediaTek 7986 audio driver definitions
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#ifndef _MT_7986_AFE_COMMON_H_
+#define _MT_7986_AFE_COMMON_H_
+
+#include <sound/soc.h>
+#include <linux/clk.h>
+#include <linux/list.h>
+#include <linux/regmap.h>
+#include "../common/mtk-base-afe.h"
+
+enum {
+	MT7986_MEMIF_DL1,
+	MT7986_MEMIF_VUL12,
+	MT7986_MEMIF_NUM,
+	MT7986_DAI_ETDM = MT7986_MEMIF_NUM,
+	MT7986_DAI_NUM,
+};
+
+enum {
+	MT7986_IRQ_0,
+	MT7986_IRQ_1,
+	MT7986_IRQ_2,
+	MT7986_IRQ_NUM,
+};
+
+struct clk;
+
+struct mt7986_afe_private {
+	struct clk_bulk_data *clks;
+	int num_clks;
+
+	int pm_runtime_bypass_reg_ctl;
+
+	/* dai */
+	void *dai_priv[MT7986_DAI_NUM];
+};
+
+unsigned int mt7986_afe_rate_transform(struct device *dev,
+				       unsigned int rate);
+
+/* dai register */
+int mt7986_dai_etdm_register(struct mtk_base_afe *afe);
+#endif
sound/soc/mediatek/mt7986/mt7986-reg.h new file +11 -0
new file mode 100644
index 000000000000..6433cdf3da92
@@ -0,0 +1,206 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * mt7986-reg.h  --  MediaTek 7986 audio driver reg definition
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#ifndef _MT7986_REG_H_
+#define _MT7986_REG_H_

..snip..

sound/soc/mediatek/mt7986/mt7986-reg.h line 192

Quoted 8 lines
sound/soc/mediatek/mt7986/mt7986-reg.h new file +8 -0
+/* ETDM_OUT5_CON4 */
+#define OUT_RELATCH(x)                  ((x) << 24)
+#define OUT_RELATCH_SFT                 24
+#define OUT_RELATCH_MASK                GENMASK(28, 24)
+#define OUT_CLK_SRC(x)                  ((x) << 6)
+#define OUT_CLK_SRC_SFT                 6
+#define OUT_CLK_SRC_MASK                GENMASK(8, 6)
+#define OUT_SEL_FS(x)                   ((x) << 0)

A number shifted by zero bits is equal to itself, so, this statement doesn't make sense. I understand why you want a OUT_SEL_FS(x) definition though, so you could do it like:

#define OUT_SEL_FS(x) (x)

After which,

Regards,
Angelo

#3 lore raw

Re: [PATCH v2 1/7] ASoC: mediatek: mt7986: add common header

Quoted 109 lines · AngeloGioacchino Del Regno

External email : Please do not click links or open attachments until you have verified the sender or the content.
Il 26/06/23 04:34, Maso Huang ha scritto:

Quoted 6 lines

Add header files for register definition and structure.

---
  sound/soc/mediatek/mt7986/mt7986-afe-common.h |  51 +++++
  sound/soc/mediatek/mt7986/mt7986-reg.h        | 206

++++++++++++++++++

Review

Quoted 5 lines
  2 files changed, 257 insertions(+)

create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-common.h create mode 100644 sound/soc/mediatek/mt7986/mt7986-reg.h

(quoted diff) +0 -0

b/sound/soc/mediatek/mt7986/mt7986-afe-common.h

Review

Quoted 57 lines

new file mode 100644
index 000000000000..646e1be4fdce

sound/soc/mediatek/mt7986/mt7986-afe-common.h new file +51 -0
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * mt7986-afe-common.h  --  MediaTek 7986 audio driver definitions
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#ifndef _MT_7986_AFE_COMMON_H_
+#define _MT_7986_AFE_COMMON_H_
+
+#include <sound/soc.h>
+#include <linux/clk.h>
+#include <linux/list.h>
+#include <linux/regmap.h>
+#include "../common/mtk-base-afe.h"
+
+enum {
+MT7986_MEMIF_DL1,
+MT7986_MEMIF_VUL12,
+MT7986_MEMIF_NUM,
+MT7986_DAI_ETDM = MT7986_MEMIF_NUM,
+MT7986_DAI_NUM,
+};
+
+enum {
+MT7986_IRQ_0,
+MT7986_IRQ_1,
+MT7986_IRQ_2,
+MT7986_IRQ_NUM,
+};
+
+struct clk;
+
+struct mt7986_afe_private {
+struct clk_bulk_data *clks;
+int num_clks;
+
+int pm_runtime_bypass_reg_ctl;
+
+/* dai */
+void *dai_priv[MT7986_DAI_NUM];
+};
+
+unsigned int mt7986_afe_rate_transform(struct device *dev,
+       unsigned int rate);
+
+/* dai register */
+int mt7986_dai_etdm_register(struct mtk_base_afe *afe);
+#endif
(quoted diff) +0 -0

b/sound/soc/mediatek/mt7986/mt7986-reg.h

Quoted 16 lines

new file mode 100644
index 000000000000..6433cdf3da92

sound/soc/mediatek/mt7986/mt7986-reg.h new file +11 -0
@@ -0,0 +1,206 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * mt7986-reg.h  --  MediaTek 7986 audio driver reg definition
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#ifndef _MT7986_REG_H_
+#define _MT7986_REG_H_

..snip..

sound/soc/mediatek/mt7986/mt7986-reg.h line 192

Quoted 8 lines
sound/soc/mediatek/mt7986/mt7986-reg.h new file +8 -0
+/* ETDM_OUT5_CON4 */
+#define OUT_RELATCH(x)                  ((x) << 24)
+#define OUT_RELATCH_SFT                 24
+#define OUT_RELATCH_MASK                GENMASK(28, 24)
+#define OUT_CLK_SRC(x)                  ((x) << 6)
+#define OUT_CLK_SRC_SFT                 6
+#define OUT_CLK_SRC_MASK                GENMASK(8, 6)
+#define OUT_SEL_FS(x)                   ((x) << 0)

A number shifted by zero bits is equal to itself, so, this statement doesn't
make sense. I understand why you want a OUT_SEL_FS(x) definition though, so
you could do it like:

Quoted 8 lines

#define OUT_SEL_FS(x)(x)

After which,
Reviewed-by: AngeloGioacchino Del Regno <
[email protected]>

Regards,
Angelo

Hi Angelo,

Thanks for your review.
I'll fix this in v3 patch.

Best regards,
Maso

author
#4 lore raw

PATCH v2 2/7 ASoC: mediatek: mt7986: support audio clock control

In reply to Maso Huang

Add audio clock wrapper and audio tuner control.

---
 sound/soc/mediatek/mt7986/mt7986-afe-clk.c | 75 ++++++++++++++++++++++
 sound/soc/mediatek/mt7986/mt7986-afe-clk.h | 18 ++++++
 2 files changed, 93 insertions(+)
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-clk.c
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-clk.h
sound/soc/mediatek/mt7986/mt7986-afe-clk.c new file +75 -0
new file mode 100644
index 000000000000..a8b5fae05673
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * mt7986-afe-clk.c  --  MediaTek 7986 afe clock ctrl
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#include <linux/clk.h>
+
+#include "mt7986-afe-common.h"
+#include "mt7986-afe-clk.h"
+#include "mt7986-reg.h"
+
+enum {
+	CK_INFRA_AUD_BUS_CK = 0,
+	CK_INFRA_AUD_26M_CK,
+	CK_INFRA_AUD_L_CK,
+	CK_INFRA_AUD_AUD_CK,
+	CK_INFRA_AUD_EG2_CK,
+	CLK_NUM
+};
+
+static const char *aud_clks[CLK_NUM] = {
+	[CK_INFRA_AUD_BUS_CK] = "aud_bus_ck",
+	[CK_INFRA_AUD_26M_CK] = "aud_26m_ck",
+	[CK_INFRA_AUD_L_CK] = "aud_l_ck",
+	[CK_INFRA_AUD_AUD_CK] = "aud_aud_ck",
+	[CK_INFRA_AUD_EG2_CK] = "aud_eg2_ck",
+};
+
+int mt7986_init_clock(struct mtk_base_afe *afe)
+{
+	struct mt7986_afe_private *afe_priv = afe->platform_priv;
+	int ret, i;
+
+	afe_priv->clks = devm_kcalloc(afe->dev, CLK_NUM,
+				sizeof(*afe_priv->clks), GFP_KERNEL);
+	if (!afe_priv->clks)
+		return -ENOMEM;
+	afe_priv->num_clks = CLK_NUM;
+
+	for (i = 0; i < afe_priv->num_clks; i++)
+		afe_priv->clks[i].id = aud_clks[i];
+
+	ret = devm_clk_bulk_get(afe->dev, afe_priv->num_clks, afe_priv->clks);
+	if (ret)
+		return dev_err_probe(afe->dev, ret, "Failed to get clocks\n");
+
+	return 0;
+}
+
+int mt7986_afe_enable_clock(struct mtk_base_afe *afe)
+{
+	struct mt7986_afe_private *afe_priv = afe->platform_priv;
+	int ret;
+
+	ret = clk_bulk_prepare_enable(afe_priv->num_clks, afe_priv->clks);
+	if (ret)
+		return dev_err_probe(afe->dev, ret, "Failed to enable clocks\n");
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(mt7986_afe_enable_clock);
+
+int mt7986_afe_disable_clock(struct mtk_base_afe *afe)
+{
+	struct mt7986_afe_private *afe_priv = afe->platform_priv;
+
+	clk_bulk_disable_unprepare(afe_priv->num_clks, afe_priv->clks);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(mt7986_afe_disable_clock);
sound/soc/mediatek/mt7986/mt7986-afe-clk.h new file +18 -0
new file mode 100644
index 000000000000..2f15b7a54bdc
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * mt7986-afe-clk.h  --  MediaTek 7986 afe clock ctrl definition
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#ifndef _MT7986_AFE_CLK_H_
+#define _MT7986_AFE_CLK_H_
+
+struct mtk_base_afe;
+
+int mt7986_init_clock(struct mtk_base_afe *afe);
+int mt7986_afe_enable_clock(struct mtk_base_afe *afe);
+int mt7986_afe_disable_clock(struct mtk_base_afe *afe);
+#endif
Signature · 7 lines
2.18.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v2 2/7
#5 lore raw

Re: [PATCH v2 2/7] ASoC: mediatek: mt7986: support audio clock control

Quoted 5 lines · Maso Huang

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Add audio clock wrapper and audio tuner control.

Quoted 116 lines
---
 sound/soc/mediatek/mt7986/mt7986-afe-clk.c | 75 ++++++++++++++++++++++
 sound/soc/mediatek/mt7986/mt7986-afe-clk.h | 18 ++++++
 2 files changed, 93 insertions(+)
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-clk.c
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-clk.h
sound/soc/mediatek/mt7986/mt7986-afe-clk.c new file +75 -0
new file mode 100644
index 000000000000..a8b5fae05673
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * mt7986-afe-clk.c  --  MediaTek 7986 afe clock ctrl
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#include <linux/clk.h>
+
+#include "mt7986-afe-common.h"
+#include "mt7986-afe-clk.h"
+#include "mt7986-reg.h"
+
+enum {
+       CK_INFRA_AUD_BUS_CK = 0,
+       CK_INFRA_AUD_26M_CK,
+       CK_INFRA_AUD_L_CK,
+       CK_INFRA_AUD_AUD_CK,
+       CK_INFRA_AUD_EG2_CK,
+       CLK_NUM
+};
+
+static const char *aud_clks[CLK_NUM] = {
+       [CK_INFRA_AUD_BUS_CK] = "aud_bus_ck",
+       [CK_INFRA_AUD_26M_CK] = "aud_26m_ck",
+       [CK_INFRA_AUD_L_CK] = "aud_l_ck",
+       [CK_INFRA_AUD_AUD_CK] = "aud_aud_ck",
+       [CK_INFRA_AUD_EG2_CK] = "aud_eg2_ck",
+};
+
+int mt7986_init_clock(struct mtk_base_afe *afe)
+{
+       struct mt7986_afe_private *afe_priv = afe->platform_priv;
+       int ret, i;
+
+       afe_priv->clks = devm_kcalloc(afe->dev, CLK_NUM,
+                               sizeof(*afe_priv->clks), GFP_KERNEL);
+       if (!afe_priv->clks)
+               return -ENOMEM;
+       afe_priv->num_clks = CLK_NUM;
+
+       for (i = 0; i < afe_priv->num_clks; i++)
+               afe_priv->clks[i].id = aud_clks[i];
+
+       ret = devm_clk_bulk_get(afe->dev, afe_priv->num_clks, afe_priv->clks);
+       if (ret)
+               return dev_err_probe(afe->dev, ret, "Failed to get clocks\n");
+
+       return 0;
+}
+
+int mt7986_afe_enable_clock(struct mtk_base_afe *afe)
+{
+       struct mt7986_afe_private *afe_priv = afe->platform_priv;
+       int ret;
+
+       ret = clk_bulk_prepare_enable(afe_priv->num_clks, afe_priv->clks);
+       if (ret)
+               return dev_err_probe(afe->dev, ret, "Failed to enable clocks\n");
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(mt7986_afe_enable_clock);
+
+int mt7986_afe_disable_clock(struct mtk_base_afe *afe)
+{
+       struct mt7986_afe_private *afe_priv = afe->platform_priv;
+
+       clk_bulk_disable_unprepare(afe_priv->num_clks, afe_priv->clks);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(mt7986_afe_disable_clock);
sound/soc/mediatek/mt7986/mt7986-afe-clk.h new file +18 -1
new file mode 100644
index 000000000000..2f15b7a54bdc
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * mt7986-afe-clk.h  --  MediaTek 7986 afe clock ctrl definition
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#ifndef _MT7986_AFE_CLK_H_
+#define _MT7986_AFE_CLK_H_
+
+struct mtk_base_afe;
+
+int mt7986_init_clock(struct mtk_base_afe *afe);
+int mt7986_afe_enable_clock(struct mtk_base_afe *afe);
+int mt7986_afe_disable_clock(struct mtk_base_afe *afe);
+#endif
--

2.18.0

Quoted 4 lines

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#6 lore raw

Re: [PATCH v2 2/7] ASoC: mediatek: mt7986: support audio clock control

In reply to Maso Huang

Il 26/06/23 04:34, Maso Huang ha scritto:

Quoted 65 lines

Add audio clock wrapper and audio tuner control.

---
  sound/soc/mediatek/mt7986/mt7986-afe-clk.c | 75 ++++++++++++++++++++++
  sound/soc/mediatek/mt7986/mt7986-afe-clk.h | 18 ++++++
  2 files changed, 93 insertions(+)

create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-clk.c create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-clk.h

sound/soc/mediatek/mt7986/mt7986-afe-clk.c new file +49 -0
new file mode 100644
index 000000000000..a8b5fae05673
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * mt7986-afe-clk.c  --  MediaTek 7986 afe clock ctrl
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#include <linux/clk.h>
+
+#include "mt7986-afe-common.h"
+#include "mt7986-afe-clk.h"
+#include "mt7986-reg.h"
+
+enum {
+	CK_INFRA_AUD_BUS_CK = 0,
+	CK_INFRA_AUD_26M_CK,
+	CK_INFRA_AUD_L_CK,
+	CK_INFRA_AUD_AUD_CK,
+	CK_INFRA_AUD_EG2_CK,
+	CLK_NUM
+};
+
+static const char *aud_clks[CLK_NUM] = {
+	[CK_INFRA_AUD_BUS_CK] = "aud_bus_ck",
+	[CK_INFRA_AUD_26M_CK] = "aud_26m_ck",
+	[CK_INFRA_AUD_L_CK] = "aud_l_ck",
+	[CK_INFRA_AUD_AUD_CK] = "aud_aud_ck",
+	[CK_INFRA_AUD_EG2_CK] = "aud_eg2_ck",
+};
+
+int mt7986_init_clock(struct mtk_base_afe *afe)
+{
+	struct mt7986_afe_private *afe_priv = afe->platform_priv;
+	int ret, i;
+
+	afe_priv->clks = devm_kcalloc(afe->dev, CLK_NUM,
+				sizeof(*afe_priv->clks), GFP_KERNEL);
+	if (!afe_priv->clks)
+		return -ENOMEM;
+	afe_priv->num_clks = CLK_NUM;
+
+	for (i = 0; i < afe_priv->num_clks; i++)
+		afe_priv->clks[i].id = aud_clks[i];
+
+	ret = devm_clk_bulk_get(afe->dev, afe_priv->num_clks, afe_priv->clks);
+	if (ret)
+		return dev_err_probe(afe->dev, ret, "Failed to get clocks\n");

sound/soc/mediatek/mt7986/mt7986-afe-clk.c line 59

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-afe-clk.c new file +10 -0
+
+	return 0;
+}
+
+int mt7986_afe_enable_clock(struct mtk_base_afe *afe)
+{
+	struct mt7986_afe_private *afe_priv = afe->platform_priv;
+	int ret;
+
+	ret = clk_bulk_prepare_enable(afe_priv->num_clks, afe_priv->clks);

You don't need a wrapper function for just a single clk_bulk_prepare_enable() call.

sound/soc/mediatek/mt7986/mt7986-afe-clk.c line 71

Quoted 12 lines
sound/soc/mediatek/mt7986/mt7986-afe-clk.c new file +12 -0
+	if (ret)
+		return dev_err_probe(afe->dev, ret, "Failed to enable clocks\n");
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(mt7986_afe_enable_clock);
+
+int mt7986_afe_disable_clock(struct mtk_base_afe *afe)
+{
+	struct mt7986_afe_private *afe_priv = afe->platform_priv;
+
+	clk_bulk_disable_unprepare(afe_priv->num_clks, afe_priv->clks);

Same for this one....

... which means that this file will have only mt7986_init_clock() so, ultimately, you don't need a mt7986-afe-clk.c file at all.
Please merge this logic into mt7986-afe-pcm.c, which is also the only user of it.

Thanks,
Angelo

#7 lore raw

Re: [PATCH v2 2/7] ASoC: mediatek: mt7986: support audio clock control

Quoted 77 lines · AngeloGioacchino Del Regno

External email : Please do not click links or open attachments until you have verified the sender or the content.
Il 26/06/23 04:34, Maso Huang ha scritto:

Quoted 5 lines

Add audio clock wrapper and audio tuner control.

---
  sound/soc/mediatek/mt7986/mt7986-afe-clk.c | 75

++++++++++++++++++++++

Review

Quoted 6 lines
  sound/soc/mediatek/mt7986/mt7986-afe-clk.h | 18 ++++++
  2 files changed, 93 insertions(+)

create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-clk.c create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-clk.h

(quoted diff) +0 -0

b/sound/soc/mediatek/mt7986/mt7986-afe-clk.c

Quoted 60 lines

new file mode 100644
index 000000000000..a8b5fae05673

sound/soc/mediatek/mt7986/mt7986-afe-clk.c new file +47 -0
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * mt7986-afe-clk.c  --  MediaTek 7986 afe clock ctrl
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#include <linux/clk.h>
+
+#include "mt7986-afe-common.h"
+#include "mt7986-afe-clk.h"
+#include "mt7986-reg.h"
+
+enum {
+CK_INFRA_AUD_BUS_CK = 0,
+CK_INFRA_AUD_26M_CK,
+CK_INFRA_AUD_L_CK,
+CK_INFRA_AUD_AUD_CK,
+CK_INFRA_AUD_EG2_CK,
+CLK_NUM
+};
+
+static const char *aud_clks[CLK_NUM] = {
+[CK_INFRA_AUD_BUS_CK] = "aud_bus_ck",
+[CK_INFRA_AUD_26M_CK] = "aud_26m_ck",
+[CK_INFRA_AUD_L_CK] = "aud_l_ck",
+[CK_INFRA_AUD_AUD_CK] = "aud_aud_ck",
+[CK_INFRA_AUD_EG2_CK] = "aud_eg2_ck",
+};
+
+int mt7986_init_clock(struct mtk_base_afe *afe)
+{
+struct mt7986_afe_private *afe_priv = afe->platform_priv;
+int ret, i;
+
+afe_priv->clks = devm_kcalloc(afe->dev, CLK_NUM,
+sizeof(*afe_priv->clks), GFP_KERNEL);
+if (!afe_priv->clks)
+return -ENOMEM;
+afe_priv->num_clks = CLK_NUM;
+
+for (i = 0; i < afe_priv->num_clks; i++)
+afe_priv->clks[i].id = aud_clks[i];
+
+ret = devm_clk_bulk_get(afe->dev, afe_priv->num_clks, afe_priv-

clks);

sound/soc/mediatek/mt7986/mt7986-afe-clk.c new file +7 -0
+if (ret)
+return dev_err_probe(afe->dev, ret, "Failed to get clocks\n");
+
+return 0;
+}
+
+int mt7986_afe_enable_clock(struct mtk_base_afe *afe)
Quoted 9 lines

sound/soc/mediatek/mt7986/mt7986-afe-clk.c line 59

Quoted 5 lines
sound/soc/mediatek/mt7986/mt7986-afe-clk.c new file +5 -0
+{
+struct mt7986_afe_private *afe_priv = afe->platform_priv;
+int ret;
+
+ret = clk_bulk_prepare_enable(afe_priv->num_clks, afe_priv->clks);

You don't need a wrapper function for just a single clk_bulk_prepare_enable() call.

OK, I'll use clk_bulk_prepare_enable directly.

Quoted 6 lines
Quoted 6 lines
sound/soc/mediatek/mt7986/mt7986-afe-clk.c new file +6 -0
+if (ret)
+return dev_err_probe(afe->dev, ret, "Failed to enable clocks\n");
+
+return 0;
+}
+EXPORT_SYMBOL_GPL(mt7986_afe_enable_clock);
Quoted 9 lines

sound/soc/mediatek/mt7986/mt7986-afe-clk.c line 71

Quoted 6 lines
sound/soc/mediatek/mt7986/mt7986-afe-clk.c new file +6 -0
+
+int mt7986_afe_disable_clock(struct mtk_base_afe *afe)
+{
+struct mt7986_afe_private *afe_priv = afe->platform_priv;
+
+clk_bulk_disable_unprepare(afe_priv->num_clks, afe_priv->clks);

Same for this one....

OK.

Quoted 9 lines

... which means that this file will have only mt7986_init_clock() so, ultimately,
you don't need a mt7986-afe-clk.c file at all.
Please merge this logic into mt7986-afe-pcm.c, which is also the only user of it.

Thanks,
Angelo

Hi Angelo,

Thanks for your review.
I'll remove mt7986-afe-clk.c and merge related clock api to mt7986-afe- pcm.c in v3 patch.

Best regards,
Maso

author
#8 lore raw

PATCH v2 3/7 ASoC: mediatek: mt7986: support etdm in platform driver

In reply to Maso Huang

Add mt7986 etdm dai driver support.

---
 sound/soc/mediatek/mt7986/mt7986-dai-etdm.c | 421 ++++++++++++++++++++
 1 file changed, 421 insertions(+)
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-dai-etdm.c
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +421 -0
new file mode 100644
index 000000000000..672deb59ea46
@@ -0,0 +1,421 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * MediaTek ALSA SoC Audio DAI eTDM Control
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#include <linux/bitops.h>
+#include <linux/regmap.h>
+#include <sound/pcm_params.h>
+#include "mt7986-afe-clk.h"
+#include "mt7986-afe-common.h"
+#include "mt7986-reg.h"
+
+enum {
+	HOPPING_CLK = 0,
+	APLL_CLK = 1,
+};
+
+enum {
+	MTK_DAI_ETDM_FORMAT_I2S = 0,
+	MTK_DAI_ETDM_FORMAT_DSPA = 4,
+	MTK_DAI_ETDM_FORMAT_DSPB = 5,
+};
+
+enum {
+	ETDM_IN5 = 2,
+	ETDM_OUT5 = 10,
+};
+
+enum {
+	MTK_ETDM_RATE_8K = 0,
+	MTK_ETDM_RATE_12K = 1,
+	MTK_ETDM_RATE_16K = 2,
+	MTK_ETDM_RATE_24K = 3,
+	MTK_ETDM_RATE_32K = 4,
+	MTK_ETDM_RATE_48K = 5,
+	MTK_ETDM_RATE_96K = 7,
+	MTK_ETDM_RATE_192K = 9,
+	MTK_ETDM_RATE_11K = 16,
+	MTK_ETDM_RATE_22K = 17,
+	MTK_ETDM_RATE_44K = 18,
+	MTK_ETDM_RATE_88K = 19,
+	MTK_ETDM_RATE_176K = 20,
+};
+
+struct mtk_dai_etdm_priv {
+	bool bck_inv;
+	bool lrck_inv;
+	bool slave_mode;
+	unsigned int format;
+};
+
+static unsigned int mt7986_etdm_rate_transform(struct device *dev,
+					unsigned int rate)
+{
+	switch (rate) {
+	case 8000:
+		return MTK_ETDM_RATE_8K;
+	case 11025:
+		return MTK_ETDM_RATE_11K;
+	case 12000:
+		return MTK_ETDM_RATE_12K;
+	case 16000:
+		return MTK_ETDM_RATE_16K;
+	case 22050:
+		return MTK_ETDM_RATE_22K;
+	case 24000:
+		return MTK_ETDM_RATE_24K;
+	case 32000:
+		return MTK_ETDM_RATE_32K;
+	case 44100:
+		return MTK_ETDM_RATE_44K;
+	case 48000:
+		return MTK_ETDM_RATE_48K;
+	case 88200:
+		return MTK_ETDM_RATE_88K;
+	case 96000:
+		return MTK_ETDM_RATE_96K;
+	case 176400:
+		return MTK_ETDM_RATE_176K;
+	case 192000:
+		return MTK_ETDM_RATE_192K;
+	default:
+		dev_warn(dev, "%s(), rate %u invalid, use %d!!!\n",
+			 __func__, rate, MTK_ETDM_RATE_48K);
+		return MTK_ETDM_RATE_48K;
+	}
+}
+
+static int get_etdm_wlen(unsigned int bitwidth)
+{
+	return bitwidth <= 16 ? 16 : 32;
+}
+
+/* dai component */
+/* interconnection */
+
+static const struct snd_kcontrol_new o124_mix[] = {
+	SOC_DAPM_SINGLE_AUTODISABLE("I032_Switch", AFE_CONN124_1, 0, 1, 0),
+};
+
+static const struct snd_kcontrol_new o125_mix[] = {
+	SOC_DAPM_SINGLE_AUTODISABLE("I033_Switch", AFE_CONN125_1, 1, 1, 0),
+};
+
+static const struct snd_soc_dapm_widget mtk_dai_etdm_widgets[] = {
+
+	/* DL */
+	SND_SOC_DAPM_MIXER("I150", SND_SOC_NOPM, 0, 0, NULL, 0),
+	SND_SOC_DAPM_MIXER("I151", SND_SOC_NOPM, 0, 0, NULL, 0),
+	/* UL */
+	SND_SOC_DAPM_MIXER("O124", SND_SOC_NOPM, 0, 0,
+			   o124_mix, ARRAY_SIZE(o124_mix)),
+	SND_SOC_DAPM_MIXER("O125", SND_SOC_NOPM, 0, 0,
+			   o125_mix, ARRAY_SIZE(o125_mix)),
+};
+
+static const struct snd_soc_dapm_route mtk_dai_etdm_routes[] = {
+	{"I150", NULL, "ETDM Capture"},
+	{"I151", NULL, "ETDM Capture"},
+	{"ETDM Playback", NULL, "O124"},
+	{"ETDM Playback", NULL, "O125"},
+	{"O124", "I032_Switch", "I032"},
+	{"O125", "I033_Switch", "I033"},
+};
+
+/* dai ops */
+static int mtk_dai_etdm_startup(struct snd_pcm_substream *substream,
+				struct snd_soc_dai *dai)
+{
+	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
+
+	mt7986_afe_enable_clock(afe);
+
+	regmap_update_bits(afe->regmap, AUDIO_TOP_CON2, CLK_OUT5_PDN_MASK,
+			   0);
+	regmap_update_bits(afe->regmap, AUDIO_TOP_CON2, CLK_IN5_PDN_MASK,
+			   0);
+
+	return 0;
+}
+
+static void mtk_dai_etdm_shutdown(struct snd_pcm_substream *substream,
+				  struct snd_soc_dai *dai)
+{
+	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
+
+	regmap_update_bits(afe->regmap, AUDIO_TOP_CON2, CLK_OUT5_PDN_MASK,
+			   CLK_OUT5_PDN);
+	regmap_update_bits(afe->regmap, AUDIO_TOP_CON2, CLK_IN5_PDN_MASK,
+			   CLK_IN5_PDN);
+
+	mt7986_afe_disable_clock(afe);
+}
+
+static unsigned int get_etdm_ch_fixup(unsigned int channels)
+{
+	if (channels > 16)
+		return 24;
+	else if (channels > 8)
+		return 16;
+	else if (channels > 4)
+		return 8;
+	else if (channels > 2)
+		return 4;
+	else
+		return 2;
+}
+
+static int mtk_dai_etdm_config(struct mtk_base_afe *afe,
+			       struct snd_pcm_hw_params *params,
+			       struct snd_soc_dai *dai,
+			       int stream)
+{
+	struct mt7986_afe_private *afe_priv = afe->platform_priv;
+	struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai->id];
+	unsigned int rate = params_rate(params);
+	unsigned int etdm_rate = mt7986_etdm_rate_transform(afe->dev, rate);
+	unsigned int afe_rate = mt7986_afe_rate_transform(afe->dev, rate);
+	unsigned int channels = params_channels(params);
+	unsigned int bit_width = params_width(params);
+	unsigned int wlen = get_etdm_wlen(bit_width);
+	unsigned int val = 0;
+	unsigned int mask = 0;
+
+	dev_dbg(afe->dev, "%s(), stream %d, rate %u, bitwidth %u\n",
+		 __func__, stream, rate, bit_width);
+
+	/* CON0 */
+	mask |= ETDM_BIT_LEN_MASK;
+	val |= ETDM_BIT_LEN(bit_width);
+	mask |= ETDM_WRD_LEN_MASK;
+	val |= ETDM_WRD_LEN(wlen);
+	mask |= ETDM_FMT_MASK;
+	val |= ETDM_FMT(etdm_data->format);
+	mask |= ETDM_CH_NUM_MASK;
+	val |= ETDM_CH_NUM(get_etdm_ch_fixup(channels));
+	mask |= RELATCH_SRC_MASK;
+	val |= RELATCH_SRC(APLL_CLK);
+
+	switch (stream) {
+	case SNDRV_PCM_STREAM_PLAYBACK:
+		/* set ETDM_OUT5_CON0 */
+		regmap_update_bits(afe->regmap, ETDM_OUT5_CON0, mask, val);
+
+		/* set ETDM_OUT5_CON4 */
+		regmap_update_bits(afe->regmap, ETDM_OUT5_CON4,
+				   OUT_RELATCH_MASK, OUT_RELATCH(afe_rate));
+		regmap_update_bits(afe->regmap, ETDM_OUT5_CON4,
+				   OUT_CLK_SRC_MASK, OUT_CLK_SRC(APLL_CLK));
+		regmap_update_bits(afe->regmap, ETDM_OUT5_CON4,
+				   OUT_SEL_FS_MASK, OUT_SEL_FS(etdm_rate));
+
+		/* set ETDM_OUT5_CON5 */
+		regmap_update_bits(afe->regmap, ETDM_OUT5_CON5,
+				   ETDM_CLK_DIV_MASK, ETDM_CLK_DIV);
+		break;
+	case SNDRV_PCM_STREAM_CAPTURE:
+		/* set ETDM_IN5_CON0 */
+		regmap_update_bits(afe->regmap, ETDM_IN5_CON0, mask, val);
+		regmap_update_bits(afe->regmap, ETDM_IN5_CON0,
+				   ETDM_SYNC_MASK, ETDM_SYNC);
+
+		/* set ETDM_IN5_CON2 */
+		regmap_update_bits(afe->regmap, ETDM_IN5_CON2,
+				   IN_CLK_SRC_MASK, IN_CLK_SRC(APLL_CLK));
+
+		/* set ETDM_IN5_CON3 */
+		regmap_update_bits(afe->regmap, ETDM_IN5_CON3,
+				   IN_SEL_FS_MASK, IN_SEL_FS(etdm_rate));
+
+		/* set ETDM_IN5_CON4 */
+		regmap_update_bits(afe->regmap, ETDM_IN5_CON4,
+				   IN_RELATCH_MASK, IN_RELATCH(afe_rate));
+		break;
+	default:
+		break;
+	}
+
+	return 0;
+}
+
+static int mtk_dai_etdm_hw_params(struct snd_pcm_substream *substream,
+				  struct snd_pcm_hw_params *params,
+				  struct snd_soc_dai *dai)
+{
+	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
+
+	mtk_dai_etdm_config(afe, params, dai, SNDRV_PCM_STREAM_PLAYBACK);
+	mtk_dai_etdm_config(afe, params, dai, SNDRV_PCM_STREAM_CAPTURE);
+
+	return 0;
+}
+
+static int mtk_dai_etdm_trigger(struct snd_pcm_substream *substream, int cmd,
+				struct snd_soc_dai *dai)
+{
+	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
+
+	dev_dbg(afe->dev, "%s(), cmd %d, dai id %d\n", __func__, cmd, dai->id);
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+	case SNDRV_PCM_TRIGGER_RESUME:
+		regmap_update_bits(afe->regmap, ETDM_IN5_CON0, ETDM_EN_MASK,
+				   ETDM_EN);
+		regmap_update_bits(afe->regmap, ETDM_OUT5_CON0, ETDM_EN_MASK,
+				   ETDM_EN);
+		break;
+	case SNDRV_PCM_TRIGGER_STOP:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+		regmap_update_bits(afe->regmap, ETDM_IN5_CON0, ETDM_EN_MASK,
+				   0);
+		regmap_update_bits(afe->regmap, ETDM_OUT5_CON0, ETDM_EN_MASK,
+				   0);
+		break;
+	default:
+		break;
+	}
+
+	return 0;
+}
+
+static int mtk_dai_etdm_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
+{
+	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
+	struct mt7986_afe_private *afe_priv = afe->platform_priv;
+	struct mtk_dai_etdm_priv *etdm_data;
+	void *priv_data;
+
+	switch (dai->id) {
+	case MT7986_DAI_ETDM:
+		break;
+	default:
+		dev_warn(afe->dev, "%s(), id %d not support\n",
+			 __func__, dai->id);
+		return -EINVAL;
+	}
+
+	priv_data = devm_kzalloc(afe->dev, sizeof(struct mtk_dai_etdm_priv),
+				 GFP_KERNEL);
+	if (!priv_data)
+		return -ENOMEM;
+
+	afe_priv->dai_priv[dai->id] = priv_data;
+	etdm_data = afe_priv->dai_priv[dai->id];
+
+	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+	case SND_SOC_DAIFMT_I2S:
+		etdm_data->format = MTK_DAI_ETDM_FORMAT_I2S;
+		break;
+	case SND_SOC_DAIFMT_DSP_A:
+		etdm_data->format = MTK_DAI_ETDM_FORMAT_DSPA;
+		break;
+	case SND_SOC_DAIFMT_DSP_B:
+		etdm_data->format = MTK_DAI_ETDM_FORMAT_DSPB;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+	case SND_SOC_DAIFMT_NB_NF:
+		etdm_data->bck_inv = false;
+		etdm_data->lrck_inv = false;
+		break;
+	case SND_SOC_DAIFMT_NB_IF:
+		etdm_data->bck_inv = false;
+		etdm_data->lrck_inv = true;
+		break;
+	case SND_SOC_DAIFMT_IB_NF:
+		etdm_data->bck_inv = true;
+		etdm_data->lrck_inv = false;
+		break;
+	case SND_SOC_DAIFMT_IB_IF:
+		etdm_data->bck_inv = true;
+		etdm_data->lrck_inv = true;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+	case SND_SOC_DAIFMT_CBM_CFM:
+		etdm_data->slave_mode = true;
+		break;
+	case SND_SOC_DAIFMT_CBS_CFS:
+		etdm_data->slave_mode = false;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static const struct snd_soc_dai_ops mtk_dai_etdm_ops = {
+	.startup = mtk_dai_etdm_startup,
+	.shutdown = mtk_dai_etdm_shutdown,
+	.hw_params = mtk_dai_etdm_hw_params,
+	.trigger = mtk_dai_etdm_trigger,
+	.set_fmt = mtk_dai_etdm_set_fmt,
+};
+
+/* dai driver */
+#define MTK_ETDM_RATES (SNDRV_PCM_RATE_8000_48000 |\
+			SNDRV_PCM_RATE_88200 |\
+			SNDRV_PCM_RATE_96000 |\
+			SNDRV_PCM_RATE_176400 |\
+			SNDRV_PCM_RATE_192000)
+
+#define MTK_ETDM_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
+			  SNDRV_PCM_FMTBIT_S24_LE |\
+			  SNDRV_PCM_FMTBIT_S32_LE)
+
+static struct snd_soc_dai_driver mtk_dai_etdm_driver[] = {
+	{
+		.name = "ETDM",
+		.id = MT7986_DAI_ETDM,
+		.capture = {
+			.stream_name = "ETDM Capture",
+			.channels_min = 1,
+			.channels_max = 2,
+			.rates = MTK_ETDM_RATES,
+			.formats = MTK_ETDM_FORMATS,
+		},
+		.playback = {
+			.stream_name = "ETDM Playback",
+			.channels_min = 1,
+			.channels_max = 2,
+			.rates = MTK_ETDM_RATES,
+			.formats = MTK_ETDM_FORMATS,
+		},
+		.ops = &mtk_dai_etdm_ops,
+		.symmetric_rate = 1,
+		.symmetric_sample_bits = 1,
+	},
+};
+
+int mt7986_dai_etdm_register(struct mtk_base_afe *afe)
+{
+	struct mtk_base_afe_dai *dai;
+
+	dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL);
+	if (!dai)
+		return -ENOMEM;
+
+	list_add(&dai->list, &afe->sub_dais);
+
+	dai->dai_drivers = mtk_dai_etdm_driver;
+	dai->num_dai_drivers = ARRAY_SIZE(mtk_dai_etdm_driver);
+
+	dai->dapm_widgets = mtk_dai_etdm_widgets;
+	dai->num_dapm_widgets = ARRAY_SIZE(mtk_dai_etdm_widgets);
+	dai->dapm_routes = mtk_dai_etdm_routes;
+	dai->num_dapm_routes = ARRAY_SIZE(mtk_dai_etdm_routes);
+
+	return 0;
+}
Signature · 1 line
2.18.0
maintainer Reviewed-by on v2 3/7
#9 lore raw

Re: [PATCH v2 3/7] ASoC: mediatek: mt7986: support etdm in platform driver

Il 26/06/23 04:34, Maso Huang ha scritto:

Quoted 61 lines

Add mt7986 etdm dai driver support.

---
  sound/soc/mediatek/mt7986/mt7986-dai-etdm.c | 421 ++++++++++++++++++++
  1 file changed, 421 insertions(+)

create mode 100644 sound/soc/mediatek/mt7986/mt7986-dai-etdm.c

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +47 -0
new file mode 100644
index 000000000000..672deb59ea46
@@ -0,0 +1,421 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * MediaTek ALSA SoC Audio DAI eTDM Control
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#include <linux/bitops.h>
+#include <linux/regmap.h>
+#include <sound/pcm_params.h>
+#include "mt7986-afe-clk.h"
+#include "mt7986-afe-common.h"
+#include "mt7986-reg.h"
+
+enum {
+	HOPPING_CLK = 0,
+	APLL_CLK = 1,
+};
+
+enum {
+	MTK_DAI_ETDM_FORMAT_I2S = 0,
+	MTK_DAI_ETDM_FORMAT_DSPA = 4,
+	MTK_DAI_ETDM_FORMAT_DSPB = 5,
+};
+
+enum {
+	ETDM_IN5 = 2,
+	ETDM_OUT5 = 10,
+};
+
+enum {
+	MTK_ETDM_RATE_8K = 0,
+	MTK_ETDM_RATE_12K = 1,
+	MTK_ETDM_RATE_16K = 2,
+	MTK_ETDM_RATE_24K = 3,
+	MTK_ETDM_RATE_32K = 4,
+	MTK_ETDM_RATE_48K = 5,
+	MTK_ETDM_RATE_96K = 7,
+	MTK_ETDM_RATE_192K = 9,
+	MTK_ETDM_RATE_11K = 16,
+	MTK_ETDM_RATE_22K = 17,
+	MTK_ETDM_RATE_44K = 18,
+	MTK_ETDM_RATE_88K = 19,
+	MTK_ETDM_RATE_176K = 20,
+};

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c line 57

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +10 -0
+
+struct mtk_dai_etdm_priv {
+	bool bck_inv;
+	bool lrck_inv;
+	bool slave_mode;
+	unsigned int format;
+};
+
+static unsigned int mt7986_etdm_rate_transform(struct device *dev,
+					unsigned int rate)

Please either fix indentation or just do it in one line, 86 columns are ok.

Quoted 20 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +20 -0
+{
+	switch (rate) {
+	case 8000:
+		return MTK_ETDM_RATE_8K;
+	case 11025:
+		return MTK_ETDM_RATE_11K;
+	case 12000:
+		return MTK_ETDM_RATE_12K;
+	case 16000:
+		return MTK_ETDM_RATE_16K;
+	case 22050:
+		return MTK_ETDM_RATE_22K;
+	case 24000:
+		return MTK_ETDM_RATE_24K;
+	case 32000:
+		return MTK_ETDM_RATE_32K;
+	case 44100:
+		return MTK_ETDM_RATE_44K;
+	case 48000:
+		return MTK_ETDM_RATE_48K;

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c line 87

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +10 -0
+	case 88200:
+		return MTK_ETDM_RATE_88K;
+	case 96000:
+		return MTK_ETDM_RATE_96K;
+	case 176400:
+		return MTK_ETDM_RATE_176K;
+	case 192000:
+		return MTK_ETDM_RATE_192K;
+	default:
+		dev_warn(dev, "%s(), rate %u invalid, use %d!!!\n",

s/use/using/g

Quoted 19 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +19 -0
+			 __func__, rate, MTK_ETDM_RATE_48K);
+		return MTK_ETDM_RATE_48K;
+	}
+}
+
+static int get_etdm_wlen(unsigned int bitwidth)
+{
+	return bitwidth <= 16 ? 16 : 32;
+}
+
+/* dai component */
+/* interconnection */
+
+static const struct snd_kcontrol_new o124_mix[] = {
+	SOC_DAPM_SINGLE_AUTODISABLE("I032_Switch", AFE_CONN124_1, 0, 1, 0),
+};
+
+static const struct snd_kcontrol_new o125_mix[] = {
+	SOC_DAPM_SINGLE_AUTODISABLE("I033_Switch", AFE_CONN125_1, 1, 1, 0),

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c line 116

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +10 -0
+};
+
+static const struct snd_soc_dapm_widget mtk_dai_etdm_widgets[] = {
+
+	/* DL */
+	SND_SOC_DAPM_MIXER("I150", SND_SOC_NOPM, 0, 0, NULL, 0),
+	SND_SOC_DAPM_MIXER("I151", SND_SOC_NOPM, 0, 0, NULL, 0),
+	/* UL */
+	SND_SOC_DAPM_MIXER("O124", SND_SOC_NOPM, 0, 0,
+			   o124_mix, ARRAY_SIZE(o124_mix)),

Fits in one line.

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c line 118

Quoted 2 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +2 -0
+	SND_SOC_DAPM_MIXER("O125", SND_SOC_NOPM, 0, 0,
+			   o125_mix, ARRAY_SIZE(o125_mix)),

This one too.

Quoted 13 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +13 -0
+};
+
+static const struct snd_soc_dapm_route mtk_dai_etdm_routes[] = {
+	{"I150", NULL, "ETDM Capture"},
+	{"I151", NULL, "ETDM Capture"},
+	{"ETDM Playback", NULL, "O124"},
+	{"ETDM Playback", NULL, "O125"},
+	{"O124", "I032_Switch", "I032"},
+	{"O125", "I033_Switch", "I033"},
+};
+
+/* dai ops */
+static int mtk_dai_etdm_startup(struct snd_pcm_substream *substream,

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c line 141

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +10 -0
+				struct snd_soc_dai *dai)
+{
+	struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
+
+	mt7986_afe_enable_clock(afe);
+
+	regmap_update_bits(afe->regmap, AUDIO_TOP_CON2, CLK_OUT5_PDN_MASK,
+			   0);
+	regmap_update_bits(afe->regmap, AUDIO_TOP_CON2, CLK_IN5_PDN_MASK,
+			   0);

Both do fit in one line (and others in this file).

After fixing that,

#10 lore raw

Re: [PATCH v2 3/7] ASoC: mediatek: mt7986: support etdm in platform driver

Quoted 72 lines · AngeloGioacchino Del Regno

External email : Please do not click links or open attachments until you have verified the sender or the content.
Il 26/06/23 04:34, Maso Huang ha scritto:

Quoted 5 lines

Add mt7986 etdm dai driver support.

---
  sound/soc/mediatek/mt7986/mt7986-dai-etdm.c | 421

++++++++++++++++++++

Review

Quoted 4 lines
  1 file changed, 421 insertions(+)

create mode 100644 sound/soc/mediatek/mt7986/mt7986-dai-etdm.c

(quoted diff) +0 -0

b/sound/soc/mediatek/mt7986/mt7986-dai-etdm.c

Quoted 57 lines

new file mode 100644
index 000000000000..672deb59ea46

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +52 -0
@@ -0,0 +1,421 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * MediaTek ALSA SoC Audio DAI eTDM Control
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#include <linux/bitops.h>
+#include <linux/regmap.h>
+#include <sound/pcm_params.h>
+#include "mt7986-afe-clk.h"
+#include "mt7986-afe-common.h"
+#include "mt7986-reg.h"
+
+enum {
+HOPPING_CLK = 0,
+APLL_CLK = 1,
+};
+
+enum {
+MTK_DAI_ETDM_FORMAT_I2S = 0,
+MTK_DAI_ETDM_FORMAT_DSPA = 4,
+MTK_DAI_ETDM_FORMAT_DSPB = 5,
+};
+
+enum {
+ETDM_IN5 = 2,
+ETDM_OUT5 = 10,
+};
+
+enum {
+MTK_ETDM_RATE_8K = 0,
+MTK_ETDM_RATE_12K = 1,
+MTK_ETDM_RATE_16K = 2,
+MTK_ETDM_RATE_24K = 3,
+MTK_ETDM_RATE_32K = 4,
+MTK_ETDM_RATE_48K = 5,
+MTK_ETDM_RATE_96K = 7,
+MTK_ETDM_RATE_192K = 9,
+MTK_ETDM_RATE_11K = 16,
+MTK_ETDM_RATE_22K = 17,
+MTK_ETDM_RATE_44K = 18,
+MTK_ETDM_RATE_88K = 19,
+MTK_ETDM_RATE_176K = 20,
+};
+
+struct mtk_dai_etdm_priv {
+bool bck_inv;
+bool lrck_inv;
+bool slave_mode;
Quoted 9 lines

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c line 57

Quoted 5 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +5 -0
+unsigned int format;
+};
+
+static unsigned int mt7986_etdm_rate_transform(struct device *dev,
+unsigned int rate)

Please either fix indentation or just do it in one line, 86 columns are ok.

OK.

Quoted 24 lines
Quoted 24 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +24 -0
+{
+switch (rate) {
+case 8000:
+return MTK_ETDM_RATE_8K;
+case 11025:
+return MTK_ETDM_RATE_11K;
+case 12000:
+return MTK_ETDM_RATE_12K;
+case 16000:
+return MTK_ETDM_RATE_16K;
+case 22050:
+return MTK_ETDM_RATE_22K;
+case 24000:
+return MTK_ETDM_RATE_24K;
+case 32000:
+return MTK_ETDM_RATE_32K;
+case 44100:
+return MTK_ETDM_RATE_44K;
+case 48000:
+return MTK_ETDM_RATE_48K;
+case 88200:
+return MTK_ETDM_RATE_88K;
+case 96000:
+return MTK_ETDM_RATE_96K;
Quoted 9 lines

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c line 87

Quoted 6 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +6 -0
+case 176400:
+return MTK_ETDM_RATE_176K;
+case 192000:
+return MTK_ETDM_RATE_192K;
+default:
+dev_warn(dev, "%s(), rate %u invalid, use %d!!!\n",

s/use/using/g

OK.

Quoted 21 lines
Quoted 5 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +5 -0
+ __func__, rate, MTK_ETDM_RATE_48K);
+return MTK_ETDM_RATE_48K;
+}
+}
+

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +10 -0
+static int get_etdm_wlen(unsigned int bitwidth)
+{
+return bitwidth <= 16 ? 16 : 32;
+}
+
+/* dai component */
+/* interconnection */
+
+static const struct snd_kcontrol_new o124_mix[] = {
+SOC_DAPM_SINGLE_AUTODISABLE("I032_Switch", AFE_CONN124_1, 0, 1,

0),

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c

Quoted 4 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +4 -0
+};
+
+static const struct snd_kcontrol_new o125_mix[] = {
+SOC_DAPM_SINGLE_AUTODISABLE("I033_Switch", AFE_CONN125_1, 1, 1,

0),

Quoted 13 lines

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c line 116

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +10 -0
+};
+
+static const struct snd_soc_dapm_widget mtk_dai_etdm_widgets[] = {
+
+/* DL */
+SND_SOC_DAPM_MIXER("I150", SND_SOC_NOPM, 0, 0, NULL, 0),
+SND_SOC_DAPM_MIXER("I151", SND_SOC_NOPM, 0, 0, NULL, 0),
+/* UL */
+SND_SOC_DAPM_MIXER("O124", SND_SOC_NOPM, 0, 0,
+   o124_mix, ARRAY_SIZE(o124_mix)),

Fits in one line.

OK.

Quoted 5 lines

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c line 118

Quoted 2 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +2 -0
+SND_SOC_DAPM_MIXER("O125", SND_SOC_NOPM, 0, 0,
+   o125_mix, ARRAY_SIZE(o125_mix)),

This one too.

OK.

Quoted 14 lines

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c

Quoted 13 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +13 -0
+};
+
+static const struct snd_soc_dapm_route mtk_dai_etdm_routes[] = {
+{"I150", NULL, "ETDM Capture"},
+{"I151", NULL, "ETDM Capture"},
+{"ETDM Playback", NULL, "O124"},
+{"ETDM Playback", NULL, "O125"},
+{"O124", "I032_Switch", "I032"},
+{"O125", "I033_Switch", "I033"},
+};
+
+/* dai ops */
+static int mtk_dai_etdm_startup(struct snd_pcm_substream

*substream,

Quoted 13 lines

sound/soc/mediatek/mt7986/mt7986-dai-etdm.c line 141

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-dai-etdm.c new file +10 -0
+struct snd_soc_dai *dai)
+{
+struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
+
+mt7986_afe_enable_clock(afe);
+
+regmap_update_bits(afe->regmap, AUDIO_TOP_CON2, CLK_OUT5_PDN_MASK,
+   0);
+regmap_update_bits(afe->regmap, AUDIO_TOP_CON2, CLK_IN5_PDN_MASK,
+   0);

Both do fit in one line (and others in this file).

OK.

Quoted 4 lines

After fixing that,

Reviewed-by: AngeloGioacchino Del Regno <
[email protected]>

Hi Angelo,

Thanks for your review.
I'll fix them in v3 patch.

Best regards,
Maso

author
#11 lore raw

PATCH v2 4/7 ASoC: mediatek: mt7986: add platform driver

In reply to Maso Huang

Add mt7986 platform driver.

---
 sound/soc/mediatek/Kconfig                 |  10 +
 sound/soc/mediatek/Makefile                |   1 +
 sound/soc/mediatek/mt7986/Makefile         |   9 +
 sound/soc/mediatek/mt7986/mt7986-afe-pcm.c | 598 +++++++++++++++++++++
 4 files changed, 618 insertions(+)
 create mode 100644 sound/soc/mediatek/mt7986/Makefile
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-pcm.c
sound/soc/mediatek/Kconfig +10 -0
index 90db67e0ce4f..558827755a8d 100644
@@ -54,6 +54,16 @@ config SND_SOC_MT6797_MT6351
 	  Select Y if you have such device.
 	  If unsure select "N".
 
+config SND_SOC_MT7986
+	tristate "ASoC support for Mediatek MT7986 chip"
+	depends on ARCH_MEDIATEK
+	select SND_SOC_MEDIATEK
+	help
+	  This adds ASoC platform driver support for MediaTek MT7986 chip
+	  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
sound/soc/mediatek/Makefile +1 -0
index 3de38cfc69e5..3938e7f75c2e 100644
@@ -2,6 +2,7 @@
 obj-$(CONFIG_SND_SOC_MEDIATEK) += common/
 obj-$(CONFIG_SND_SOC_MT2701) += mt2701/
 obj-$(CONFIG_SND_SOC_MT6797) += mt6797/
+obj-$(CONFIG_SND_SOC_MT7986) += mt7986/
 obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
 obj-$(CONFIG_SND_SOC_MT8183) += mt8183/
 obj-$(CONFIG_SND_SOC_MT8186) += mt8186/
sound/soc/mediatek/mt7986/Makefile new file +9 -0
new file mode 100644
index 000000000000..7c0ece616198
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+
+# platform driver
+snd-soc-mt7986-afe-objs := \
+	mt7986-afe-pcm.o \
+	mt7986-afe-clk.o \
+	mt7986-dai-etdm.o
+
+obj-$(CONFIG_SND_SOC_MT7986) += snd-soc-mt7986-afe.o
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +598 -0

598 lines not on this page · raw message

Signature · 1 line
2.18.0
#12 lore raw

Re: [PATCH v2 4/7] ASoC: mediatek: mt7986: add platform driver

Quoted 36 lines · Maso Huang
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +36 -0
+static int mt7986_afe_pcm_dev_probe(struct platform_device *pdev)
+{
+       struct mtk_base_afe *afe;
+       struct mt7986_afe_private *afe_priv;
+       struct device *dev;
+       int i, irq_id, ret;
+
+       afe = devm_kzalloc(&pdev->dev, sizeof(*afe), GFP_KERNEL);
+       if (!afe)
+               return -ENOMEM;
+       platform_set_drvdata(pdev, afe);
+
+       afe->platform_priv = devm_kzalloc(&pdev->dev, sizeof(*afe_priv),
+                                         GFP_KERNEL);
+       if (!afe->platform_priv)
+               return -ENOMEM;
+
+       afe_priv = afe->platform_priv;
+       afe->dev = &pdev->dev;
+       dev = afe->dev;
+
+       afe->base_addr = devm_platform_ioremap_resource(pdev, 0);
+       if (IS_ERR(afe->base_addr))
+               return PTR_ERR(afe->base_addr);
+
+       /* initial audio related clock */
+       ret = mt7986_init_clock(afe);
+       if (ret)
+               return dev_err_probe(dev, ret, "Cannot initialize clocks\n");
+
+       ret = devm_pm_runtime_enable(dev);
+       if (ret)
+               return ret;
+
+       /* enable clock for regcache get default value from hw */
+       afe_priv->pm_runtime_bypass_reg_ctl = true;

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 473

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +10 -0
+       pm_runtime_get_sync(&pdev->dev);
+
+       afe->regmap = devm_regmap_init_mmio(&pdev->dev, afe->base_addr,
+                     &mt7986_afe_regmap_config);
+       if (IS_ERR(afe->regmap)) {
+               ret = PTR_ERR(afe->regmap);
+               goto err_pm_disable;
+       }
+
+       pm_runtime_put_sync(&pdev->dev);

You already did here a put thus (see below)

Quoted 79 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +79 -0
+       afe_priv->pm_runtime_bypass_reg_ctl = false;
+
+       /* init memif */
+       afe->memif_size = MT7986_MEMIF_NUM;
+       afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe->memif),
+                                 GFP_KERNEL);
+       if (!afe->memif)
+               goto err_pm_disable;
+
+       for (i = 0; i < afe->memif_size; i++) {
+               afe->memif[i].data = &memif_data[i];
+               afe->memif[i].irq_usage = -1;
+       }
+
+       mutex_init(&afe->irq_alloc_lock);
+
+       /* irq initialize */
+       afe->irqs_size = MT7986_IRQ_NUM;
+       afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs),
+                                GFP_KERNEL);
+       if (!afe->irqs)
+               goto err_pm_disable;
+
+       for (i = 0; i < afe->irqs_size; i++)
+               afe->irqs[i].irq_data = &irq_data[i];
+
+       /* request irq */
+       irq_id = platform_get_irq(pdev, 0);
+       if (irq_id < 0) {
+               dev_err(dev, "%pOFn no irq found\n", dev->of_node);
+               ret = irq_id;
+               goto err_pm_disable;
+       }
+       ret = devm_request_irq(dev, irq_id, mt7986_afe_irq_handler,
+                              IRQF_TRIGGER_NONE, "asys-isr", (void *)afe);
+       if (ret) {
+               dev_err(dev, "could not request_irq for asys-isr\n");
+               goto err_pm_disable;
+       }
+
+       /* init sub_dais */
+       INIT_LIST_HEAD(&afe->sub_dais);
+
+       for (i = 0; i < ARRAY_SIZE(dai_register_cbs); i++) {
+               ret = dai_register_cbs[i](afe);
+               if (ret) {
+                       dev_err(afe->dev, "dai register i %d fail, ret %d\n",
+                                i, ret);
+                       goto err_pm_disable;
+               }
+       }
+
+       /* init dai_driver and component_driver */
+       ret = mtk_afe_combine_sub_dai(afe);
+       if (ret) {
+               dev_err(afe->dev, "mtk_afe_combine_sub_dai fail, ret %d\n",
+                        ret);
+               goto err_pm_disable;
+       }
+
+       afe->mtk_afe_hardware = &mt7986_afe_hardware;
+       afe->memif_fs = mt7986_memif_fs;
+       afe->irq_fs = mt7986_irq_fs;
+
+       afe->runtime_resume = mt7986_afe_runtime_resume;
+       afe->runtime_suspend = mt7986_afe_runtime_suspend;
+
+       /* register component */
+       ret = devm_snd_soc_register_component(&pdev->dev,
+                                             &mt7986_afe_component,
+                                             NULL, 0);
+       if (ret) {
+               dev_warn(dev, "err_platform\n");
+               goto err_pm_disable;
+       }
+
+       ret = devm_snd_soc_register_component(afe->dev,
+                                             &mt7986_afe_pcm_dai_component,
+                                             afe->dai_drivers,

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 562

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +10 -0
+                                             afe->num_dai_drivers);
+       if (ret) {
+               dev_warn(dev, "err_dai_component\n");
+               goto err_pm_disable;
+       }
+
+       return ret;
+
+err_pm_disable:
+       pm_runtime_put_sync(&pdev->dev);

these should be no need for this one here.

Quoted 1 line

+ pm_runtime_disable(&pdev->dev);

This is also covered by devm_pm_runtime_enable().

Review

Quoted 2 lines
(quoted diff) +2 -0
+       return ret;
+}

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#13 lore raw

Re: [PATCH v2 4/7] ASoC: mediatek: mt7986: add platform driver

Quoted 143 lines · On Tue, 2023-06-27 at 04:43 +0000, [email protected] wrote:

External email : Please do not click links or open attachments until you have verified the sender or the content.

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

Quoted 13 lines · Maso Huang
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +13 -0
+static int mt7986_afe_pcm_dev_probe(struct platform_device *pdev)
+{
+       struct mtk_base_afe *afe;
+       struct mt7986_afe_private *afe_priv;
+       struct device *dev;
+       int i, irq_id, ret;
+
+       afe = devm_kzalloc(&pdev->dev, sizeof(*afe), GFP_KERNEL);
+       if (!afe)
+               return -ENOMEM;
+       platform_set_drvdata(pdev, afe);
+
+       afe->platform_priv = devm_kzalloc(&pdev->dev,

sizeof(*afe_priv),

Quoted 6 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +6 -0
+                                         GFP_KERNEL);
+       if (!afe->platform_priv)
+               return -ENOMEM;
+
+       afe_priv = afe->platform_priv;
+       afe->dev = &pdev->dev;

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +10 -0
+       dev = afe->dev;
+
+       afe->base_addr = devm_platform_ioremap_resource(pdev, 0);
+       if (IS_ERR(afe->base_addr))
+               return PTR_ERR(afe->base_addr);
+
+       /* initial audio related clock */
+       ret = mt7986_init_clock(afe);
+       if (ret)
+               return dev_err_probe(dev, ret, "Cannot initialize

clocks\n");

Quoted 11 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +10 -0
+
+       ret = devm_pm_runtime_enable(dev);
+       if (ret)
+               return ret;
+
+       /* enable clock for regcache get default value from hw */
+       afe_priv->pm_runtime_bypass_reg_ctl = true;
+       pm_runtime_get_sync(&pdev->dev);
+
+       afe->regmap = devm_regmap_init_mmio(&pdev->dev, afe-

base_addr,

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 473

Quoted 7 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +7 -0
+                     &mt7986_afe_regmap_config);
+       if (IS_ERR(afe->regmap)) {
+               ret = PTR_ERR(afe->regmap);
+               goto err_pm_disable;
+       }
+
+       pm_runtime_put_sync(&pdev->dev);

You already did here a put thus (see below)

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

Quoted 5 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +5 -0
+       afe_priv->pm_runtime_bypass_reg_ctl = false;
+
+       /* init memif */
+       afe->memif_size = MT7986_MEMIF_NUM;
+       afe->memif = devm_kcalloc(dev, afe->memif_size,

sizeof(*afe->memif),

Quoted 21 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +14 -0
+                                 GFP_KERNEL);
+       if (!afe->memif)
+               goto err_pm_disable;
+
+       for (i = 0; i < afe->memif_size; i++) {
+               afe->memif[i].data = &memif_data[i];
+               afe->memif[i].irq_usage = -1;
+       }
+
+       mutex_init(&afe->irq_alloc_lock);
+
+       /* irq initialize */
+       afe->irqs_size = MT7986_IRQ_NUM;
+       afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe-

irqs),

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +6 -0
+                                GFP_KERNEL);
+       if (!afe->irqs)
+               goto err_pm_disable;
+
+       for (i = 0; i < afe->irqs_size; i++)
+               afe->irqs[i].irq_data = &irq_data[i];

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +10 -0
+
+       /* request irq */
+       irq_id = platform_get_irq(pdev, 0);
+       if (irq_id < 0) {
+               dev_err(dev, "%pOFn no irq found\n", dev->of_node);
+               ret = irq_id;
+               goto err_pm_disable;
+       }
+       ret = devm_request_irq(dev, irq_id, mt7986_afe_irq_handler,
+                              IRQF_TRIGGER_NONE, "asys-isr", (void

*)afe);

Review

Quoted 2 lines
(quoted diff) +2 -0
+       if (ret) {
+               dev_err(dev, "could not request_irq for asys-

isr\n");

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +10 -0
+               goto err_pm_disable;
+       }
+
+       /* init sub_dais */
+       INIT_LIST_HEAD(&afe->sub_dais);
+
+       for (i = 0; i < ARRAY_SIZE(dai_register_cbs); i++) {
+               ret = dai_register_cbs[i](afe);
+               if (ret) {
+                       dev_err(afe->dev, "dai register i %d fail,

ret %d\n",

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

Quoted 9 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +9 -0
+                                i, ret);
+                       goto err_pm_disable;
+               }
+       }
+
+       /* init dai_driver and component_driver */
+       ret = mtk_afe_combine_sub_dai(afe);
+       if (ret) {
+               dev_err(afe->dev, "mtk_afe_combine_sub_dai fail,

ret %d\n",

Quoted 4 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +3 -0
+                        ret);
+               goto err_pm_disable;
+       }

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 542

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +10 -0
+
+       afe->mtk_afe_hardware = &mt7986_afe_hardware;
+       afe->memif_fs = mt7986_memif_fs;
+       afe->irq_fs = mt7986_irq_fs;
+
+       afe->runtime_resume = mt7986_afe_runtime_resume;
+       afe->runtime_suspend = mt7986_afe_runtime_suspend;
+
+       /* register component */
+       ret = devm_snd_soc_register_component(&pdev->dev,

+ &mt7986_afe_component,

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 550

Quoted 8 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +7 -0
+                                             NULL, 0);
+       if (ret) {
+               dev_warn(dev, "err_platform\n");
+               goto err_pm_disable;
+       }
+
+       ret = devm_snd_soc_register_component(afe->dev,

+ &mt7986_afe_pcm_dai_com
ponent,

Quoted 15 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 562

Quoted 12 lines
(quoted diff) +2 -0
+                                             afe->dai_drivers,
+                                             afe-

num_dai_drivers);

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +9 -0
+       if (ret) {
+               dev_warn(dev, "err_dai_component\n");
+               goto err_pm_disable;
+       }
+
+       return ret;
+
+err_pm_disable:
+       pm_runtime_put_sync(&pdev->dev);

these should be no need for this one here.

Hi Claudiu,
Thanks for your review.
This is for (IS_ERR(afe->regmap)) error handling. May I just remove this one? or any other suggestion?

Thanks,
Maso

Quoted 8 lines
Quoted 1 line

+ pm_runtime_disable(&pdev->dev);

This is also covered by devm_pm_runtime_enable().

Quoted 2 lines
(quoted diff) +2 -0
+       return ret;
+}
#14 lore raw

Re: [PATCH v2 4/7] ASoC: mediatek: mt7986: add platform driver

In reply to Maso Huang

Il 26/06/23 04:34, Maso Huang ha scritto:

Quoted 12 lines

Add mt7986 platform driver.

---
  sound/soc/mediatek/Kconfig                 |  10 +
  sound/soc/mediatek/Makefile                |   1 +
  sound/soc/mediatek/mt7986/Makefile         |   9 +
  sound/soc/mediatek/mt7986/mt7986-afe-pcm.c | 598 +++++++++++++++++++++
  4 files changed, 618 insertions(+)

create mode 100644 sound/soc/mediatek/mt7986/Makefile create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

..snip..

Quoted 35 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +29 -0
new file mode 100644
index 000000000000..9eef21762e93
@@ -0,0 +1,598 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * MediaTek ALSA SoC AFE platform driver for MT7986
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/pm_runtime.h>
+
+#include "mt7986-afe-common.h"
+#include "mt7986-afe-clk.h"
+#include "mt7986-reg.h"
+#include "../common/mtk-afe-platform-driver.h"
+#include "../common/mtk-afe-fe-dai.h"
+
+enum {
+	MTK_AFE_RATE_8K = 0,
+	MTK_AFE_RATE_11K = 1,
+	MTK_AFE_RATE_12K = 2,
+	MTK_AFE_RATE_16K = 4,
+	MTK_AFE_RATE_22K = 5,
+	MTK_AFE_RATE_24K = 6,
+	MTK_AFE_RATE_32K = 8,

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 39

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +10 -0
+	MTK_AFE_RATE_44K = 9,
+	MTK_AFE_RATE_48K = 10,
+	MTK_AFE_RATE_88K = 13,
+	MTK_AFE_RATE_96K = 14,
+	MTK_AFE_RATE_176K = 17,
+	MTK_AFE_RATE_192K = 18,
+};
+
+unsigned int mt7986_afe_rate_transform(struct device *dev,
+				       unsigned int rate)

Fits in one line.

Quoted 20 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +20 -0
+{
+	switch (rate) {
+	case 8000:
+		return MTK_AFE_RATE_8K;
+	case 11025:
+		return MTK_AFE_RATE_11K;
+	case 12000:
+		return MTK_AFE_RATE_12K;
+	case 16000:
+		return MTK_AFE_RATE_16K;
+	case 22050:
+		return MTK_AFE_RATE_22K;
+	case 24000:
+		return MTK_AFE_RATE_24K;
+	case 32000:
+		return MTK_AFE_RATE_32K;
+	case 44100:
+		return MTK_AFE_RATE_44K;
+	case 48000:
+		return MTK_AFE_RATE_48K;

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 69

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +10 -0
+	case 88200:
+		return MTK_AFE_RATE_88K;
+	case 96000:
+		return MTK_AFE_RATE_96K;
+	case 176400:
+		return MTK_AFE_RATE_176K;
+	case 192000:
+		return MTK_AFE_RATE_192K;
+	default:
+		dev_warn(dev, "%s(), rate %u invalid, use %d!!!\n",

s/use/using/g

Quoted 5 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +5 -0
+			 __func__, rate, MTK_AFE_RATE_48K);
+		return MTK_AFE_RATE_48K;
+	}
+}
+

..snip..

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 275

Quoted 5 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +5 -0
+
+static bool mt7986_is_volatile_reg(struct device *dev, unsigned int reg)
+{
+	/* these auto-gen reg has read-only bit, so put it as volatile */
+	/* volatile reg cannot be cached, so cannot be set when power off */

Fix the comment format please; for multi-line comments, you want:

/*
* Those auto-gen regs are read-only, so put it a volatile because
* volatile registers cannot be cached, which means that they cannot
* be set when power is off
*/

Quoted 16 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +16 -0
+	switch (reg) {
+	case AFE_DL0_CUR_MSB:
+	case AFE_DL0_CUR:
+	case AFE_DL0_RCH_MON:
+	case AFE_DL0_LCH_MON:
+	case AFE_VUL0_CUR_MSB:
+	case AFE_VUL0_CUR:
+	case AFE_IRQ_MCU_STATUS:
+	case AFE_MEMIF_RD_MON:
+	case AFE_MEMIF_WR_MON:
+		return true;
+	default:
+		return false;
+	};
+}
+

..snip..

Quoted 18 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +18 -0
+
+static int mt7986_afe_pcm_dev_probe(struct platform_device *pdev)
+{
+	struct mtk_base_afe *afe;
+	struct mt7986_afe_private *afe_priv;
+	struct device *dev;
+	int i, irq_id, ret;
+
+	afe = devm_kzalloc(&pdev->dev, sizeof(*afe), GFP_KERNEL);
+	if (!afe)
+		return -ENOMEM;
+	platform_set_drvdata(pdev, afe);
+
+	afe->platform_priv = devm_kzalloc(&pdev->dev, sizeof(*afe_priv),
+					  GFP_KERNEL);
+	if (!afe->platform_priv)
+		return -ENOMEM;
+

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 454

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +10 -0
+	afe_priv = afe->platform_priv;
+	afe->dev = &pdev->dev;
+	dev = afe->dev;
+
+	afe->base_addr = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(afe->base_addr))
+		return PTR_ERR(afe->base_addr);
+
+	/* initial audio related clock */
+	ret = mt7986_init_clock(afe);

As said in the review for patch [2/7], function mt7986_init_clock() must be moved in this file instead.

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 467

Quoted 13 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +13 -0
+	if (ret)
+		return dev_err_probe(dev, ret, "Cannot initialize clocks\n");
+
+	ret = devm_pm_runtime_enable(dev);
+	if (ret)
+		return ret;
+
+	/* enable clock for regcache get default value from hw */
+	afe_priv->pm_runtime_bypass_reg_ctl = true;
+	pm_runtime_get_sync(&pdev->dev);
+
+	afe->regmap = devm_regmap_init_mmio(&pdev->dev, afe->base_addr,
+		      &mt7986_afe_regmap_config);
	pm_runtime_put_sync(&pdev->dev);
	if (IS_ERR(afe->regmap))
		return PTR_ERR(afe->regmap);

	afe_prov->pm_runtime_bypass_reg_ctl = false;

that's better :-)

Quoted 28 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +28 -0
+	if (IS_ERR(afe->regmap)) {
+		ret = PTR_ERR(afe->regmap);
+		goto err_pm_disable;
+	}
+
+	pm_runtime_put_sync(&pdev->dev);
+	afe_priv->pm_runtime_bypass_reg_ctl = false;
+
+	/* init memif */
+	afe->memif_size = MT7986_MEMIF_NUM;
+	afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe->memif),
+				  GFP_KERNEL);
+	if (!afe->memif)
+		goto err_pm_disable;
+
+	for (i = 0; i < afe->memif_size; i++) {
+		afe->memif[i].data = &memif_data[i];
+		afe->memif[i].irq_usage = -1;
+	}
+
+	mutex_init(&afe->irq_alloc_lock);
+
+	/* irq initialize */
+	afe->irqs_size = MT7986_IRQ_NUM;
+	afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs),
+				 GFP_KERNEL);
+	if (!afe->irqs)
+		goto err_pm_disable;

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 505

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +10 -0
+
+	for (i = 0; i < afe->irqs_size; i++)
+		afe->irqs[i].irq_data = &irq_data[i];
+
+	/* request irq */
+	irq_id = platform_get_irq(pdev, 0);
+	if (irq_id < 0) {
+		dev_err(dev, "%pOFn no irq found\n", dev->of_node);
+		ret = irq_id;
+		goto err_pm_disable;

You can just return... and please use dev_err_probe().

Quoted 31 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +31 -0
+	}
+	ret = devm_request_irq(dev, irq_id, mt7986_afe_irq_handler,
+			       IRQF_TRIGGER_NONE, "asys-isr", (void *)afe);
+	if (ret) {
+		dev_err(dev, "could not request_irq for asys-isr\n");
+		goto err_pm_disable;
+	}
+
+	/* init sub_dais */
+	INIT_LIST_HEAD(&afe->sub_dais);
+
+	for (i = 0; i < ARRAY_SIZE(dai_register_cbs); i++) {
+		ret = dai_register_cbs[i](afe);
+		if (ret) {
+			dev_err(afe->dev, "dai register i %d fail, ret %d\n",
+				 i, ret);
+			goto err_pm_disable;
+		}
+	}
+
+	/* init dai_driver and component_driver */
+	ret = mtk_afe_combine_sub_dai(afe);
+	if (ret) {
+		dev_err(afe->dev, "mtk_afe_combine_sub_dai fail, ret %d\n",
+			 ret);
+		goto err_pm_disable;
+	}
+
+	afe->mtk_afe_hardware = &mt7986_afe_hardware;
+	afe->memif_fs = mt7986_memif_fs;
+	afe->irq_fs = mt7986_irq_fs;

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 546

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +10 -0
+
+	afe->runtime_resume = mt7986_afe_runtime_resume;
+	afe->runtime_suspend = mt7986_afe_runtime_suspend;
+
+	/* register component */
+	ret = devm_snd_soc_register_component(&pdev->dev,
+					      &mt7986_afe_component,
+					      NULL, 0);
+	if (ret) {
+		dev_warn(dev, "err_platform\n");

That shall not be a dev_warn, but a dev_err() instead, but then, being this a probe function and not needing that jump, it's dev_err_probe().

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 555

Quoted 9 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +9 -0
+		goto err_pm_disable;
+	}
+
+	ret = devm_snd_soc_register_component(afe->dev,
+					      &mt7986_afe_pcm_dai_component,
+					      afe->dai_drivers,
+					      afe->num_dai_drivers);
+	if (ret) {
+		dev_warn(dev, "err_dai_component\n");

Same here.

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 561

Quoted 6 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +6 -0
+		goto err_pm_disable;
+	}
+
+	return ret;
+
+err_pm_disable:

You don't need this label because you're now using devm_pm_runtime_enable() and, following my advice from some lines up, pm_runtime_put_sync() is called at the right time already.

This means that you can simplify this function a lot with directly returning the error in error paths (including instances of dev_err_probe() ).

Quoted 4 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +4 -0
+	pm_runtime_put_sync(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+	return ret;
+}

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 575

Quoted 10 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +10 -0
+
+static void mt7986_afe_pcm_dev_remove(struct platform_device *pdev)
+{
+	pm_runtime_disable(&pdev->dev);
+	if (!pm_runtime_status_suspended(&pdev->dev))
+		mt7986_afe_runtime_suspend(&pdev->dev);
+}
+
+static const struct of_device_id mt7986_afe_pcm_dt_match[] = {
+	{ .compatible = "mediatek,mt7986-afe", },

You don't need the comma here ^^
so this is just

	{ .compatible = "mediatek,mt7986-afe" },

Everything else looks fine.

Regards,
Angelo

#15 lore raw

Re: [PATCH v2 4/7] ASoC: mediatek: mt7986: add platform driver

Quoted 60 lines · AngeloGioacchino Del Regno

External email : Please do not click links or open attachments until you have verified the sender or the content.
Il 26/06/23 04:34, Maso Huang ha scritto:

Quoted 8 lines

Add mt7986 platform driver.

---
  sound/soc/mediatek/Kconfig                 |  10 +
  sound/soc/mediatek/Makefile                |   1 +
  sound/soc/mediatek/mt7986/Makefile         |   9 +
  sound/soc/mediatek/mt7986/mt7986-afe-pcm.c | 598

+++++++++++++++++++++

Quoted 4 lines
  4 files changed, 618 insertions(+)

create mode 100644 sound/soc/mediatek/mt7986/Makefile create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

..snip..

Review

Quoted 1 line
(quoted diff) +0 -0

b/sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

Quoted 38 lines

new file mode 100644
index 000000000000..9eef21762e93

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +33 -0
@@ -0,0 +1,598 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * MediaTek ALSA SoC AFE platform driver for MT7986
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/pm_runtime.h>
+
+#include "mt7986-afe-common.h"
+#include "mt7986-afe-clk.h"
+#include "mt7986-reg.h"
+#include "../common/mtk-afe-platform-driver.h"
+#include "../common/mtk-afe-fe-dai.h"
+
+enum {
+MTK_AFE_RATE_8K = 0,
+MTK_AFE_RATE_11K = 1,
+MTK_AFE_RATE_12K = 2,
+MTK_AFE_RATE_16K = 4,
+MTK_AFE_RATE_22K = 5,
+MTK_AFE_RATE_24K = 6,
+MTK_AFE_RATE_32K = 8,
+MTK_AFE_RATE_44K = 9,
+MTK_AFE_RATE_48K = 10,
+MTK_AFE_RATE_88K = 13,
+MTK_AFE_RATE_96K = 14,
Quoted 9 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 39

Quoted 6 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +6 -0
+MTK_AFE_RATE_176K = 17,
+MTK_AFE_RATE_192K = 18,
+};
+
+unsigned int mt7986_afe_rate_transform(struct device *dev,
+       unsigned int rate)

Fits in one line.

OK.

Quoted 24 lines
Quoted 24 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +24 -0
+{
+switch (rate) {
+case 8000:
+return MTK_AFE_RATE_8K;
+case 11025:
+return MTK_AFE_RATE_11K;
+case 12000:
+return MTK_AFE_RATE_12K;
+case 16000:
+return MTK_AFE_RATE_16K;
+case 22050:
+return MTK_AFE_RATE_22K;
+case 24000:
+return MTK_AFE_RATE_24K;
+case 32000:
+return MTK_AFE_RATE_32K;
+case 44100:
+return MTK_AFE_RATE_44K;
+case 48000:
+return MTK_AFE_RATE_48K;
+case 88200:
+return MTK_AFE_RATE_88K;
+case 96000:
+return MTK_AFE_RATE_96K;
Quoted 9 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 69

Quoted 6 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +6 -0
+case 176400:
+return MTK_AFE_RATE_176K;
+case 192000:
+return MTK_AFE_RATE_192K;
+default:
+dev_warn(dev, "%s(), rate %u invalid, use %d!!!\n",

s/use/using/g

OK.

Quoted 16 lines
Quoted 5 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +5 -0
+ __func__, rate, MTK_AFE_RATE_48K);
+return MTK_AFE_RATE_48K;
+}
+}
+

..snip..

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

Quoted 2 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +2 -0
+
+static bool mt7986_is_volatile_reg(struct device *dev, unsigned

int reg)

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

Quoted 3 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +3 -0
+{
+/* these auto-gen reg has read-only bit, so put it as volatile */
+/* volatile reg cannot be cached, so cannot be set when power off

*/

Quoted 8 lines

Fix the comment format please; for multi-line comments, you want:

/*
* Those auto-gen regs are read-only, so put it a volatile because
* volatile registers cannot be cached, which means that they cannot
* be set when power is off
*/

OK.

Quoted 44 lines
Quoted 17 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +16 -0
+switch (reg) {
+case AFE_DL0_CUR_MSB:
+case AFE_DL0_CUR:
+case AFE_DL0_RCH_MON:
+case AFE_DL0_LCH_MON:
+case AFE_VUL0_CUR_MSB:
+case AFE_VUL0_CUR:
+case AFE_IRQ_MCU_STATUS:
+case AFE_MEMIF_RD_MON:
+case AFE_MEMIF_WR_MON:
+return true;
+default:
+return false;
+};
+}
+

..snip..

Quoted 24 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +24 -0
+
+static int mt7986_afe_pcm_dev_probe(struct platform_device *pdev)
+{
+struct mtk_base_afe *afe;
+struct mt7986_afe_private *afe_priv;
+struct device *dev;
+int i, irq_id, ret;
+
+afe = devm_kzalloc(&pdev->dev, sizeof(*afe), GFP_KERNEL);
+if (!afe)
+return -ENOMEM;
+platform_set_drvdata(pdev, afe);
+
+afe->platform_priv = devm_kzalloc(&pdev->dev, sizeof(*afe_priv),
+  GFP_KERNEL);
+if (!afe->platform_priv)
+return -ENOMEM;
+
+afe_priv = afe->platform_priv;
+afe->dev = &pdev->dev;
+dev = afe->dev;
+
+afe->base_addr = devm_platform_ioremap_resource(pdev, 0);
+if (IS_ERR(afe->base_addr))
Quoted 9 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 454

Quoted 4 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +4 -0
+return PTR_ERR(afe->base_addr);
+
+/* initial audio related clock */
+ret = mt7986_init_clock(afe);

As said in the review for patch [2/7], function mt7986_init_clock() must be moved
in this file instead.

OK.

Quoted 18 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 467

Quoted 13 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +13 -0
+if (ret)
+return dev_err_probe(dev, ret, "Cannot initialize clocks\n");
+
+ret = devm_pm_runtime_enable(dev);
+if (ret)
+return ret;
+
+/* enable clock for regcache get default value from hw */
+afe_priv->pm_runtime_bypass_reg_ctl = true;
+pm_runtime_get_sync(&pdev->dev);
+
+afe->regmap = devm_regmap_init_mmio(&pdev->dev, afe->base_addr,
+      &mt7986_afe_regmap_config);

pm_runtime_put_sync(&pdev->dev);
if (IS_ERR(afe->regmap))
return PTR_ERR(afe->regmap);

Quoted 4 lines

afe_prov->pm_runtime_bypass_reg_ctl = false;

that's better :-)

OK.

Quoted 33 lines
Quoted 33 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +11 -0
+if (IS_ERR(afe->regmap)) {
+ret = PTR_ERR(afe->regmap);
+goto err_pm_disable;
+}
+
+pm_runtime_put_sync(&pdev->dev);
+afe_priv->pm_runtime_bypass_reg_ctl = false;
+
+/* init memif */
+afe->memif_size = MT7986_MEMIF_NUM;
+afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe-

memif),

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +21 -0
+  GFP_KERNEL);
+if (!afe->memif)
+goto err_pm_disable;
+
+for (i = 0; i < afe->memif_size; i++) {
+afe->memif[i].data = &memif_data[i];
+afe->memif[i].irq_usage = -1;
+}
+
+mutex_init(&afe->irq_alloc_lock);
+
+/* irq initialize */
+afe->irqs_size = MT7986_IRQ_NUM;
+afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs),
+ GFP_KERNEL);
+if (!afe->irqs)
+goto err_pm_disable;
+
+for (i = 0; i < afe->irqs_size; i++)
+afe->irqs[i].irq_data = &irq_data[i];
+
Quoted 9 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 505

Quoted 6 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +6 -0
+/* request irq */
+irq_id = platform_get_irq(pdev, 0);
+if (irq_id < 0) {
+dev_err(dev, "%pOFn no irq found\n", dev->of_node);
+ret = irq_id;
+goto err_pm_disable;

You can just return... and please use dev_err_probe().

OK.

Quoted 37 lines
Quoted 37 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +37 -0
+}
+ret = devm_request_irq(dev, irq_id, mt7986_afe_irq_handler,
+       IRQF_TRIGGER_NONE, "asys-isr", (void *)afe);
+if (ret) {
+dev_err(dev, "could not request_irq for asys-isr\n");
+goto err_pm_disable;
+}
+
+/* init sub_dais */
+INIT_LIST_HEAD(&afe->sub_dais);
+
+for (i = 0; i < ARRAY_SIZE(dai_register_cbs); i++) {
+ret = dai_register_cbs[i](afe);
+if (ret) {
+dev_err(afe->dev, "dai register i %d fail, ret %d\n",
+ i, ret);
+goto err_pm_disable;
+}
+}
+
+/* init dai_driver and component_driver */
+ret = mtk_afe_combine_sub_dai(afe);
+if (ret) {
+dev_err(afe->dev, "mtk_afe_combine_sub_dai fail, ret %d\n",
+ ret);
+goto err_pm_disable;
+}
+
+afe->mtk_afe_hardware = &mt7986_afe_hardware;
+afe->memif_fs = mt7986_memif_fs;
+afe->irq_fs = mt7986_irq_fs;
+
+afe->runtime_resume = mt7986_afe_runtime_resume;
+afe->runtime_suspend = mt7986_afe_runtime_suspend;
+
+/* register component */
+ret = devm_snd_soc_register_component(&pdev->dev,
Quoted 9 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 546

Quoted 4 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +4 -0
+      &mt7986_afe_component,
+      NULL, 0);
+if (ret) {
+dev_warn(dev, "err_platform\n");

That shall not be a dev_warn, but a dev_err() instead, but then, being this
a probe function and not needing that jump, it's dev_err_probe().

OK.

Quoted 12 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 555

Quoted 9 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +9 -0
+goto err_pm_disable;
+}
+
+ret = devm_snd_soc_register_component(afe->dev,
+      &mt7986_afe_pcm_dai_component,
+      afe->dai_drivers,
+      afe->num_dai_drivers);
+if (ret) {
+dev_warn(dev, "err_dai_component\n");

Same here.

OK.

Quoted 13 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 561

Quoted 6 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +6 -0
+goto err_pm_disable;
+}
+
+return ret;
+
+err_pm_disable:

You don't need this label because you're now using devm_pm_runtime_enable() and,
following my advice from some lines up, pm_runtime_put_sync() is called at the
right time already.

Quoted 4 lines

This means that you can simplify this function a lot with directly returning the
error in error paths (including instances of dev_err_probe() ).

OK.

Quoted 19 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

Quoted 6 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +6 -0
+pm_runtime_put_sync(&pdev->dev);
+pm_runtime_disable(&pdev->dev);
+return ret;
+}
+
+static void mt7986_afe_pcm_dev_remove(struct platform_device

*pdev)

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 575

Quoted 8 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +8 -0
+{
+pm_runtime_disable(&pdev->dev);
+if (!pm_runtime_status_suspended(&pdev->dev))
+mt7986_afe_runtime_suspend(&pdev->dev);
+}
+
+static const struct of_device_id mt7986_afe_pcm_dt_match[] = {
+{ .compatible = "mediatek,mt7986-afe", },

You don't need the comma here ^^
so this is just

Quoted 2 lines

{ .compatible = "mediatek,mt7986-afe" },

OK.

Quoted 4 lines

Everything else looks fine.

Regards,
Angelo

Hi Angelo,

Thanks for your review.
I'll refine all of them in v3 patch.

Best regards,
Maso

#16 lore raw

Re: [PATCH v2 4/7] ASoC: mediatek: mt7986: add platform driver

Quoted 364 lines · Maso Huang
Quoted 63 lines · AngeloGioacchino Del Regno

External email : Please do not click links or open attachments until
you have verified the sender or the content.
Il 26/06/23 04:34, Maso Huang ha scritto:

Quoted 8 lines

Add mt7986 platform driver.

---
  sound/soc/mediatek/Kconfig                 |  10 +
  sound/soc/mediatek/Makefile                |   1 +
  sound/soc/mediatek/mt7986/Makefile         |   9 +
  sound/soc/mediatek/mt7986/mt7986-afe-pcm.c | 598

+++++++++++++++++++++

Quoted 4 lines
  4 files changed, 618 insertions(+)

create mode 100644 sound/soc/mediatek/mt7986/Makefile create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

..snip..

Review

Quoted 1 line
(quoted diff) +0 -0

b/sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

Quoted 38 lines

new file mode 100644
index 000000000000..9eef21762e93

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +33 -0
@@ -0,0 +1,598 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * MediaTek ALSA SoC AFE platform driver for MT7986
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Vic Wu <[email protected]>
+ *         Maso Huang <[email protected]>
+ */
+
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/pm_runtime.h>
+
+#include "mt7986-afe-common.h"
+#include "mt7986-afe-clk.h"
+#include "mt7986-reg.h"
+#include "../common/mtk-afe-platform-driver.h"
+#include "../common/mtk-afe-fe-dai.h"
+
+enum {
+MTK_AFE_RATE_8K = 0,
+MTK_AFE_RATE_11K = 1,
+MTK_AFE_RATE_12K = 2,
+MTK_AFE_RATE_16K = 4,
+MTK_AFE_RATE_22K = 5,
+MTK_AFE_RATE_24K = 6,
+MTK_AFE_RATE_32K = 8,
+MTK_AFE_RATE_44K = 9,
+MTK_AFE_RATE_48K = 10,
+MTK_AFE_RATE_88K = 13,
+MTK_AFE_RATE_96K = 14,
Quoted 9 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 39

Quoted 6 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +6 -0
+MTK_AFE_RATE_176K = 17,
+MTK_AFE_RATE_192K = 18,
+};
+
+unsigned int mt7986_afe_rate_transform(struct device *dev,
+       unsigned int rate)

Fits in one line.

OK.

Quoted 24 lines
Quoted 24 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +24 -0
+{
+switch (rate) {
+case 8000:
+return MTK_AFE_RATE_8K;
+case 11025:
+return MTK_AFE_RATE_11K;
+case 12000:
+return MTK_AFE_RATE_12K;
+case 16000:
+return MTK_AFE_RATE_16K;
+case 22050:
+return MTK_AFE_RATE_22K;
+case 24000:
+return MTK_AFE_RATE_24K;
+case 32000:
+return MTK_AFE_RATE_32K;
+case 44100:
+return MTK_AFE_RATE_44K;
+case 48000:
+return MTK_AFE_RATE_48K;
+case 88200:
+return MTK_AFE_RATE_88K;
+case 96000:
+return MTK_AFE_RATE_96K;
Quoted 9 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 69

Quoted 6 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +6 -0
+case 176400:
+return MTK_AFE_RATE_176K;
+case 192000:
+return MTK_AFE_RATE_192K;
+default:
+dev_warn(dev, "%s(), rate %u invalid, use %d!!!\n",

s/use/using/g

OK.

Quoted 20 lines
Quoted 5 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +5 -0
+ __func__, rate, MTK_AFE_RATE_48K);
+return MTK_AFE_RATE_48K;
+}
+}
+

..snip..

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

Quoted 2 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +2 -0
+
+static bool mt7986_is_volatile_reg(struct device *dev, unsigned

int reg)

Quoted 5 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +2 -0
+{
+/* these auto-gen reg has read-only bit, so put it as volatile

*/
+/* volatile reg cannot be cached, so cannot be set when power off

*/

Quoted 9 lines

Fix the comment format please; for multi-line comments, you want:

/*
* Those auto-gen regs are read-only, so put it a volatile because
* volatile registers cannot be cached, which means that they
cannot
* be set when power is off
*/

OK.

Quoted 45 lines
Quoted 17 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +16 -0
+switch (reg) {
+case AFE_DL0_CUR_MSB:
+case AFE_DL0_CUR:
+case AFE_DL0_RCH_MON:
+case AFE_DL0_LCH_MON:
+case AFE_VUL0_CUR_MSB:
+case AFE_VUL0_CUR:
+case AFE_IRQ_MCU_STATUS:
+case AFE_MEMIF_RD_MON:
+case AFE_MEMIF_WR_MON:
+return true;
+default:
+return false;
+};
+}
+

..snip..

Quoted 25 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +2 -0
+
+static int mt7986_afe_pcm_dev_probe(struct platform_device

*pdev)

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +22 -0
+{
+struct mtk_base_afe *afe;
+struct mt7986_afe_private *afe_priv;
+struct device *dev;
+int i, irq_id, ret;
+
+afe = devm_kzalloc(&pdev->dev, sizeof(*afe), GFP_KERNEL);
+if (!afe)
+return -ENOMEM;
+platform_set_drvdata(pdev, afe);
+
+afe->platform_priv = devm_kzalloc(&pdev->dev, sizeof(*afe_priv),
+  GFP_KERNEL);
+if (!afe->platform_priv)
+return -ENOMEM;
+
+afe_priv = afe->platform_priv;
+afe->dev = &pdev->dev;
+dev = afe->dev;
+
+afe->base_addr = devm_platform_ioremap_resource(pdev, 0);
+if (IS_ERR(afe->base_addr))
Quoted 9 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 454

Quoted 4 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +4 -0
+return PTR_ERR(afe->base_addr);
+
+/* initial audio related clock */
+ret = mt7986_init_clock(afe);

As said in the review for patch [2/7], function mt7986_init_clock() must be moved
in this file instead.

OK.

Quoted 18 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 467

Quoted 13 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +13 -0
+if (ret)
+return dev_err_probe(dev, ret, "Cannot initialize clocks\n");
+
+ret = devm_pm_runtime_enable(dev);
+if (ret)
+return ret;
+
+/* enable clock for regcache get default value from hw */
+afe_priv->pm_runtime_bypass_reg_ctl = true;
+pm_runtime_get_sync(&pdev->dev);
+
+afe->regmap = devm_regmap_init_mmio(&pdev->dev, afe->base_addr,
+      &mt7986_afe_regmap_config);

pm_runtime_put_sync(&pdev->dev);
if (IS_ERR(afe->regmap))
return PTR_ERR(afe->regmap);

Quoted 4 lines

afe_prov->pm_runtime_bypass_reg_ctl = false;

that's better :-)

OK.

Quoted 27 lines
Quoted 27 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +11 -0
+if (IS_ERR(afe->regmap)) {
+ret = PTR_ERR(afe->regmap);
+goto err_pm_disable;
+}
+
+pm_runtime_put_sync(&pdev->dev);
+afe_priv->pm_runtime_bypass_reg_ctl = false;
+
+/* init memif */
+afe->memif_size = MT7986_MEMIF_NUM;
+afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe-

memif),

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +14 -0
+  GFP_KERNEL);
+if (!afe->memif)
+goto err_pm_disable;
+
+for (i = 0; i < afe->memif_size; i++) {
+afe->memif[i].data = &memif_data[i];
+afe->memif[i].irq_usage = -1;
+}
+
+mutex_init(&afe->irq_alloc_lock);
+
+/* irq initialize */
+afe->irqs_size = MT7986_IRQ_NUM;
+afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe-
Quoted 1 line

irqs),

Quoted 16 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 505

Quoted 13 lines

+ GFP_KERNEL);

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +12 -0
+if (!afe->irqs)
+goto err_pm_disable;
+
+for (i = 0; i < afe->irqs_size; i++)
+afe->irqs[i].irq_data = &irq_data[i];
+
+/* request irq */
+irq_id = platform_get_irq(pdev, 0);
+if (irq_id < 0) {
+dev_err(dev, "%pOFn no irq found\n", dev->of_node);
+ret = irq_id;
+goto err_pm_disable;

You can just return... and please use dev_err_probe().

OK.

Quoted 37 lines
Quoted 37 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +37 -0
+}
+ret = devm_request_irq(dev, irq_id, mt7986_afe_irq_handler,
+       IRQF_TRIGGER_NONE, "asys-isr", (void *)afe);
+if (ret) {
+dev_err(dev, "could not request_irq for asys-isr\n");
+goto err_pm_disable;
+}
+
+/* init sub_dais */
+INIT_LIST_HEAD(&afe->sub_dais);
+
+for (i = 0; i < ARRAY_SIZE(dai_register_cbs); i++) {
+ret = dai_register_cbs[i](afe);
+if (ret) {
+dev_err(afe->dev, "dai register i %d fail, ret %d\n",
+ i, ret);
+goto err_pm_disable;
+}
+}
+
+/* init dai_driver and component_driver */
+ret = mtk_afe_combine_sub_dai(afe);
+if (ret) {
+dev_err(afe->dev, "mtk_afe_combine_sub_dai fail, ret %d\n",
+ ret);
+goto err_pm_disable;
+}
+
+afe->mtk_afe_hardware = &mt7986_afe_hardware;
+afe->memif_fs = mt7986_memif_fs;
+afe->irq_fs = mt7986_irq_fs;
+
+afe->runtime_resume = mt7986_afe_runtime_resume;
+afe->runtime_suspend = mt7986_afe_runtime_suspend;
+
+/* register component */
+ret = devm_snd_soc_register_component(&pdev->dev,
Quoted 9 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 546

Quoted 4 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +4 -0
+      &mt7986_afe_component,
+      NULL, 0);
+if (ret) {
+dev_warn(dev, "err_platform\n");

That shall not be a dev_warn, but a dev_err() instead, but then, being this
a probe function and not needing that jump, it's dev_err_probe().

OK.

Quoted 12 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 555

Quoted 9 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +9 -0
+goto err_pm_disable;
+}
+
+ret = devm_snd_soc_register_component(afe->dev,
+      &mt7986_afe_pcm_dai_component,
+      afe->dai_drivers,
+      afe->num_dai_drivers);
+if (ret) {
+dev_warn(dev, "err_dai_component\n");

Same here.

OK.

Quoted 13 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 561

Quoted 6 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +6 -0
+goto err_pm_disable;
+}
+
+return ret;
+
+err_pm_disable:

You don't need this label because you're now using devm_pm_runtime_enable() and,
following my advice from some lines up, pm_runtime_put_sync() is called at the
right time already.

Quoted 4 lines

This means that you can simplify this function a lot with directly returning the
error in error paths (including instances of dev_err_probe() ).

OK.

Quoted 8 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c

Quoted 6 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +6 -0
+pm_runtime_put_sync(&pdev->dev);
+pm_runtime_disable(&pdev->dev);
+return ret;
+}
+
+static void mt7986_afe_pcm_dev_remove(struct platform_device

*pdev)

Quoted 5 lines
Quoted 5 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 572

Quoted 5 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +5 -0
+{
+pm_runtime_disable(&pdev->dev);
+if (!pm_runtime_status_suspended(&pdev->dev))
+mt7986_afe_runtime_suspend(&pdev->dev);
+}

Hi Angelo,

Since I'm using devm_pm_runtime_enable right now, shoud I remove mt7986_afe_pcm_dev_remove as well?
It seems no more needed.

Best regards,
Maso

Quoted 25 lines
Quoted 9 lines

sound/soc/mediatek/mt7986/mt7986-afe-pcm.c line 575

Quoted 3 lines
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c new file +3 -0
+
+static const struct of_device_id mt7986_afe_pcm_dt_match[] = {
+{ .compatible = "mediatek,mt7986-afe", },

You don't need the comma here ^^
so this is just

{ .compatible = "mediatek,mt7986-afe" },

OK.

Quoted 4 lines

Everything else looks fine.

Regards,
Angelo

Hi Angelo,

Thanks for your review.
I'll refine all of them in v3 patch.

Best regards,
Maso

author
#17 lore raw

PATCH v2 5/7 ASoC: mediatek: mt7986: add machine driver with wm8960

In reply to Maso Huang

Add support for mt7986 board with wm8960.

---
 sound/soc/mediatek/Kconfig                |  10 ++
 sound/soc/mediatek/mt7986/Makefile        |   1 +
 sound/soc/mediatek/mt7986/mt7986-wm8960.c | 184 ++++++++++++++++++++++
 3 files changed, 195 insertions(+)
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-wm8960.c
sound/soc/mediatek/Kconfig +10 -0
index 558827755a8d..8d1bc8814486 100644
@@ -64,6 +64,16 @@ config SND_SOC_MT7986
 	  Select Y if you have such device.
 	  If unsure select "N".
 
+config SND_SOC_MT7986_WM8960
+	tristate "ASoc Audio driver for MT7986 with WM8960 codec"
+	depends on SND_SOC_MT7986 && I2C
+	select SND_SOC_WM8960
+	help
+	  This adds support for ASoC machine driver for MediaTek MT7986
+	  boards with the WM8960 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
sound/soc/mediatek/mt7986/Makefile +1 -0
index 7c0ece616198..4d75e116f246 100644
@@ -7,3 +7,4 @@ snd-soc-mt7986-afe-objs := \
 	mt7986-dai-etdm.o
 
 obj-$(CONFIG_SND_SOC_MT7986) += snd-soc-mt7986-afe.o
+obj-$(CONFIG_SND_SOC_MT7986_WM8960) += mt7986-wm8960.o
sound/soc/mediatek/mt7986/mt7986-wm8960.c new file +184 -0

184 lines not on this page · raw message

Signature · 1 line
2.18.0
author
#18 lore raw

PATCH v2 6/7 ASoC: dt-bindings: mediatek,mt7986-wm8960: add mt7986-wm8960 document

In reply to Maso Huang

Add document for mt7986 board with wm8960.

---
 .../sound/mediatek,mt7986-wm8960.yaml         | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mediatek,mt7986-wm8960.yaml
Documentation/devicetree/bindings/sound/mediatek,mt7986-wm8960.yaml new file +53 -0
new file mode 100644
index 000000000000..76394f7e5502
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/mediatek,mt7986-wm8960.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek MT7986 sound card with WM8960 codec
+
+maintainers:
+  - Maso Huang <[email protected]>
+
+properties:
+  compatible:
+    const: mediatek,mt7986-wm8960-machine
+
+  mediatek,platform:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: The phandle of MT7986 platform.
+
+  audio-routing:
+    $ref: /schemas/types.yaml#/definitions/non-unique-string-array
+    description:
+      A list of the connections between audio components. Each entry is a
+      sink/source pair of strings. Valid names could be the input or output
+      widgets of audio components, power supplies, MicBias of codec and the
+      software switch.
+
+  mediatek,audio-codec:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: The phandle of wm8960 codec.
+
+additionalProperties: false
+
+required:
+  - compatible
+  - mediatek,platform
+  - audio-routing
+  - mediatek,audio-codec
+
+examples:
+  - |
+    sound {
+        compatible = "mediatek,mt7986-wm8960-machine";
+        mediatek,platform = <&afe>;
+        audio-routing =
+            "Headphone", "HP_L",
+            "Headphone", "HP_R",
+            "LINPUT1", "AMIC",
+            "RINPUT1", "AMIC";
+        mediatek,audio-codec = <&wm8960>;
+    };
+
+...
Signature · 1 line
2.18.0
maintainer
#19 lore raw

Re: [PATCH v2 6/7] ASoC: dt-bindings: mediatek,mt7986-wm8960: add mt7986-wm8960 document

Quoted 34 lines · Maso Huang

Add document for mt7986 board with wm8960.

---
 .../sound/mediatek,mt7986-wm8960.yaml         | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mediatek,mt7986-wm8960.yaml
Documentation/devicetree/bindings/sound/mediatek,mt7986-wm8960.yaml new file +20 -0
new file mode 100644
index 000000000000..76394f7e5502
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/mediatek,mt7986-wm8960.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek MT7986 sound card with WM8960 codec
+
+maintainers:
+  - Maso Huang <[email protected]>
+
+properties:
+  compatible:
+    const: mediatek,mt7986-wm8960-machine
+
+  mediatek,platform:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: The phandle of MT7986 platform.
+
+  audio-routing:

Documentation/devicetree/bindings/sound/mediatek,mt7986-wm8960.yaml line 30

Quoted 10 lines
Documentation/devicetree/bindings/sound/mediatek,mt7986-wm8960.yaml new file +10 -0
+    $ref: /schemas/types.yaml#/definitions/non-unique-string-array
+    description:
+      A list of the connections between audio components. Each entry is a
+      sink/source pair of strings. Valid names could be the input or output
+      widgets of audio components, power supplies, MicBias of codec and the
+      software switch.
+
+  mediatek,audio-codec:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: The phandle of wm8960 codec.

Please define these properties in a common schema and reference them where already used and here. A given property shouldn't have multiple type definitions.

Rob

#20 lore raw

Re: [PATCH v2 6/7] ASoC: dt-bindings: mediatek,mt7986-wm8960: add mt7986-wm8960 document

Quoted 58 lines · Rob Herring

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 5 lines · Maso Huang

Add document for mt7986 board with wm8960.

---
 .../sound/mediatek,mt7986-wm8960.yaml         | 53

+++++++++++++++++++

Quoted 2 lines
 1 file changed, 53 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/sound/mediatek,mt7986-wm8960.yaml

Quoted 2 lines

diff --git

a/Documentation/devicetree/bindings/sound/mediatek,mt7986-wm8960.yaml b/Documentation/devicetree/bindings/sound/mediatek,mt7986-wm8960.yaml

Documentation/devicetree/bindings/sound/mediatek,mt7986-

Quoted 4 lines

new file mode 100644
index 000000000000..76394f7e5502

Documentation/devicetree/bindings/sound/mediatek,mt7986- new file +0 -0

wm8960.yaml

Documentation/devicetree/bindings/sound/mediatek,mt7986- line 4

Quoted 5 lines
Documentation/devicetree/bindings/sound/mediatek,mt7986- new file +4 -0
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: 

http://devicetree.org/schemas/sound/mediatek,mt7986-wm8960.yaml#

Quoted 9 lines
Documentation/devicetree/bindings/sound/mediatek,mt7986- new file +9 -0
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek MT7986 sound card with WM8960 codec
+
+maintainers:
+  - Maso Huang <[email protected]>
+
+properties:
+  compatible:

Documentation/devicetree/bindings/sound/mediatek,mt7986- line 23

Quoted 10 lines
Documentation/devicetree/bindings/sound/mediatek,mt7986- new file +10 -0
+    const: mediatek,mt7986-wm8960-machine
+
+  mediatek,platform:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: The phandle of MT7986 platform.
+
+  audio-routing:
+    $ref: /schemas/types.yaml#/definitions/non-unique-string-array
+    description:
+      A list of the connections between audio components. Each

entry is a

Documentation/devicetree/bindings/sound/mediatek,mt7986- line 24

Quoted 1 line
Documentation/devicetree/bindings/sound/mediatek,mt7986- new file +1 -0
+      sink/source pair of strings. Valid names could be the input

or output

Documentation/devicetree/bindings/sound/mediatek,mt7986- line 25

Quoted 1 line
Documentation/devicetree/bindings/sound/mediatek,mt7986- new file +1 -0
+      widgets of audio components, power supplies, MicBias of

codec and the

Documentation/devicetree/bindings/sound/mediatek,mt7986- line 30

Quoted 5 lines
Documentation/devicetree/bindings/sound/mediatek,mt7986- new file +5 -0
+      software switch.
+
+  mediatek,audio-codec:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: The phandle of wm8960 codec.
Quoted 6 lines

Please define these properties in a common schema and reference them where already used and here. A given property shouldn't have multiple
type definitions.

Rob

Hi Rob,

Thanks for your review.

Did you mean I need to create mediatek common part yaml and reference to it for these three properties?
Or is there any example for reference for this case?

Best regards,
Maso

author
#21 lore raw

PATCH v2 7/7 ASoC: dt-bindings: mediatek,mt7986-afe: add audio afe document

In reply to Maso Huang

Add mt7986 audio afe document.

---
 .../bindings/sound/mediatek,mt7986-afe.yaml   | 89 +++++++++++++++++++
 1 file changed, 89 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mediatek,mt7986-afe.yaml
Documentation/devicetree/bindings/sound/mediatek,mt7986-afe.yaml new file +89 -0
new file mode 100644
index 000000000000..257327a33ea1
@@ -0,0 +1,89 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/mediatek,mt7986-afe.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek AFE PCM controller for MT7986
+
+maintainers:
+  - Maso Huang <[email protected]>
+
+properties:
+  compatible:
+    oneOf:
+      - const: mediatek,mt7986-afe
+      - items:
+          - enum:
+              - mediatek,mt7981-afe
+              - mediatek,mt7988-afe
+          - const: mediatek,mt7986-afe
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    minItems: 5
+    items:
+      - description: audio bus clock
+      - description: audio 26M clock
+      - description: audio intbus clock
+      - description: audio hopping clock
+      - description: audio pll clock
+      - description: mux for pcm_mck
+      - description: audio i2s/pcm mck
+
+  clock-names:
+    minItems: 5
+    items:
+      - const: aud_bus_ck
+      - const: aud_26m_ck
+      - const: aud_l_ck
+      - const: aud_aud_ck
+      - const: aud_eg2_ck
+      - const: aud_sel
+      - const: aud_i2s_m
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - assigned-clocks
+  - assigned-clock-parents
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/clock/mt7986-clk.h>
+
+    afe@11210000 {
+        compatible = "mediatek,mt7986-afe";
+        reg = <0x11210000 0x9000>;
+        interrupts = <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&infracfg_ao CLK_INFRA_AUD_BUS_CK>,
+                 <&infracfg_ao CLK_INFRA_AUD_26M_CK>,
+                 <&infracfg_ao CLK_INFRA_AUD_L_CK>,
+                 <&infracfg_ao CLK_INFRA_AUD_AUD_CK>,
+                 <&infracfg_ao CLK_INFRA_AUD_EG2_CK>;
+        clock-names = "aud_bus_ck",
+                      "aud_26m_ck",
+                      "aud_l_ck",
+                      "aud_aud_ck",
+                      "aud_eg2_ck";
+        assigned-clocks = <&topckgen CLK_TOP_A1SYS_SEL>,
+                          <&topckgen CLK_TOP_AUD_L_SEL>,
+                          <&topckgen CLK_TOP_A_TUNER_SEL>;
+        assigned-clock-parents = <&topckgen CLK_TOP_APLL2_D4>,
+                                 <&apmixedsys CLK_APMIXED_APLL2>,
+                                 <&topckgen CLK_TOP_APLL2_D4>;
+    };
+
+...
Signature · 1 line
2.18.0
maintainer
#22 lore raw

Re: [PATCH v2 7/7] ASoC: dt-bindings: mediatek,mt7986-afe: add audio afe document

Quoted 52 lines · Maso Huang

Add mt7986 audio afe document.

---
 .../bindings/sound/mediatek,mt7986-afe.yaml   | 89 +++++++++++++++++++
 1 file changed, 89 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mediatek,mt7986-afe.yaml
Documentation/devicetree/bindings/sound/mediatek,mt7986-afe.yaml new file +38 -0
new file mode 100644
index 000000000000..257327a33ea1
@@ -0,0 +1,89 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/mediatek,mt7986-afe.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek AFE PCM controller for MT7986
+
+maintainers:
+  - Maso Huang <[email protected]>
+
+properties:
+  compatible:
+    oneOf:
+      - const: mediatek,mt7986-afe
+      - items:
+          - enum:
+              - mediatek,mt7981-afe
+              - mediatek,mt7988-afe
+          - const: mediatek,mt7986-afe
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    minItems: 5
+    items:
+      - description: audio bus clock
+      - description: audio 26M clock
+      - description: audio intbus clock
+      - description: audio hopping clock
+      - description: audio pll clock
+      - description: mux for pcm_mck
+      - description: audio i2s/pcm mck
+

Documentation/devicetree/bindings/sound/mediatek,mt7986-afe.yaml line 48

Quoted 10 lines
Documentation/devicetree/bindings/sound/mediatek,mt7986-afe.yaml new file +10 -0
+  clock-names:
+    minItems: 5
+    items:
+      - const: aud_bus_ck
+      - const: aud_26m_ck
+      - const: aud_l_ck
+      - const: aud_aud_ck
+      - const: aud_eg2_ck
+      - const: aud_sel
+      - const: aud_i2s_m

'aud_' is redundant.

Quoted 44 lines
Documentation/devicetree/bindings/sound/mediatek,mt7986-afe.yaml new file +41 -0
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - assigned-clocks
+  - assigned-clock-parents
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/clock/mt7986-clk.h>
+
+    afe@11210000 {
+        compatible = "mediatek,mt7986-afe";
+        reg = <0x11210000 0x9000>;
+        interrupts = <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&infracfg_ao CLK_INFRA_AUD_BUS_CK>,
+                 <&infracfg_ao CLK_INFRA_AUD_26M_CK>,
+                 <&infracfg_ao CLK_INFRA_AUD_L_CK>,
+                 <&infracfg_ao CLK_INFRA_AUD_AUD_CK>,
+                 <&infracfg_ao CLK_INFRA_AUD_EG2_CK>;
+        clock-names = "aud_bus_ck",
+                      "aud_26m_ck",
+                      "aud_l_ck",
+                      "aud_aud_ck",
+                      "aud_eg2_ck";
+        assigned-clocks = <&topckgen CLK_TOP_A1SYS_SEL>,
+                          <&topckgen CLK_TOP_AUD_L_SEL>,
+                          <&topckgen CLK_TOP_A_TUNER_SEL>;
+        assigned-clock-parents = <&topckgen CLK_TOP_APLL2_D4>,
+                                 <&apmixedsys CLK_APMIXED_APLL2>,
+                                 <&topckgen CLK_TOP_APLL2_D4>;
+    };
+
+...
Signature · 1 line
2.18.0
#23 lore raw

Re: [PATCH v2 7/7] ASoC: dt-bindings: mediatek,mt7986-afe: add audio afe document

Quoted 65 lines · Rob Herring

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 5 lines · Maso Huang

Add mt7986 audio afe document.

---
 .../bindings/sound/mediatek,mt7986-afe.yaml   | 89

+++++++++++++++++++

Quoted 2 lines
 1 file changed, 89 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/sound/mediatek,mt7986-afe.yaml

Quoted 2 lines

diff --git

a/Documentation/devicetree/bindings/sound/mediatek,mt7986-afe.yaml b/Documentation/devicetree/bindings/sound/mediatek,mt7986-afe.yaml

Documentation/devicetree/bindings/sound/mediatek,mt7986-

Quoted 4 lines

new file mode 100644
index 000000000000..257327a33ea1

Documentation/devicetree/bindings/sound/mediatek,mt7986- new file +0 -0

afe.yaml

Quoted 43 lines
Documentation/devicetree/bindings/sound/mediatek,mt7986- new file +42 -0
@@ -0,0 +1,89 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/mediatek,mt7986-afe.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek AFE PCM controller for MT7986
+
+maintainers:
+  - Maso Huang <[email protected]>
+
+properties:
+  compatible:
+    oneOf:
+      - const: mediatek,mt7986-afe
+      - items:
+          - enum:
+              - mediatek,mt7981-afe
+              - mediatek,mt7988-afe
+          - const: mediatek,mt7986-afe
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    minItems: 5
+    items:
+      - description: audio bus clock
+      - description: audio 26M clock
+      - description: audio intbus clock
+      - description: audio hopping clock
+      - description: audio pll clock
+      - description: mux for pcm_mck
+      - description: audio i2s/pcm mck
+
+  clock-names:
+    minItems: 5
+    items:
+      - const: aud_bus_ck
Quoted 9 lines

Documentation/devicetree/bindings/sound/mediatek,mt7986- line 48

Quoted 6 lines
Documentation/devicetree/bindings/sound/mediatek,mt7986- new file +6 -0
+      - const: aud_26m_ck
+      - const: aud_l_ck
+      - const: aud_aud_ck
+      - const: aud_eg2_ck
+      - const: aud_sel
+      - const: aud_i2s_m

'aud_' is redundant.

Hi Rob,

Thanks for your review.

I'll refine as below in v3 patch.
items:
- const: bus_ck
- const: 26m_ck
- const: l_ck
- const: aud_ck
- const: eg2_ck
- const: sel
- const: i2s_m

And modify example as well.

Best regards,
Maso

Quoted 44 lines
Quoted 44 lines
Documentation/devicetree/bindings/sound/mediatek,mt7986- new file +41 -0
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - assigned-clocks
+  - assigned-clock-parents
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/clock/mt7986-clk.h>
+
+    afe@11210000 {
+        compatible = "mediatek,mt7986-afe";
+        reg = <0x11210000 0x9000>;
+        interrupts = <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&infracfg_ao CLK_INFRA_AUD_BUS_CK>,
+                 <&infracfg_ao CLK_INFRA_AUD_26M_CK>,
+                 <&infracfg_ao CLK_INFRA_AUD_L_CK>,
+                 <&infracfg_ao CLK_INFRA_AUD_AUD_CK>,
+                 <&infracfg_ao CLK_INFRA_AUD_EG2_CK>;
+        clock-names = "aud_bus_ck",
+                      "aud_26m_ck",
+                      "aud_l_ck",
+                      "aud_aud_ck",
+                      "aud_eg2_ck";
+        assigned-clocks = <&topckgen CLK_TOP_A1SYS_SEL>,
+                          <&topckgen CLK_TOP_AUD_L_SEL>,
+                          <&topckgen CLK_TOP_A_TUNER_SEL>;
+        assigned-clock-parents = <&topckgen CLK_TOP_APLL2_D4>,
+                                 <&apmixedsys CLK_APMIXED_APLL2>,
+                                 <&topckgen CLK_TOP_APLL2_D4>;
+    };
+
+...
Signature · 1 line
2.18.0
#24 lore raw
In reply to Maso Huang

Gentle ping :)

Hi Rob and Angelo,

Can you help to check this latest series and share your thoughts if any?

Best regards,
Maso

Quoted 50 lines · Maso Huang

Changes in v2:
- v1 title: [PATCH 0/7] ASoC: mediatek: Add support for MT79xx SoC
- add missing maintainers
- rename mt79xx to mt7986 in all files
- use clk bulk api in mt7986-afe-clk.c [2/7]
- refine mt7986-afe-pcm.c based on reviewer's suggestions [4/7]
- refine dt-binding files based on reviewer's suggestions [6/7]
[7/7]
- transpose [3/7] and [4/7] in v1 to fix test build errors

This series of patches adds support for MediaTek AFE of MT7986 SoC. Patches are based on broonie tree "for-next" branch.

Maso Huang (7):
ASoC: mediatek: mt7986: add common header
ASoC: mediatek: mt7986: support audio clock control
ASoC: mediatek: mt7986: support etdm in platform driver
ASoC: mediatek: mt7986: add platform driver
ASoC: mediatek: mt7986: add machine driver with wm8960
ASoC: dt-bindings: mediatek,mt7986-wm8960: add mt7986-wm8960
document
ASoC: dt-bindings: mediatek,mt7986-afe: add audio afe document

 .../bindings/sound/mediatek,mt7986-afe.yaml   |  89 +++
 .../sound/mediatek,mt7986-wm8960.yaml         |  53 ++
 sound/soc/mediatek/Kconfig                    |  20 +
 sound/soc/mediatek/Makefile                   |   1 +
 sound/soc/mediatek/mt7986/Makefile            |  10 +
 sound/soc/mediatek/mt7986/mt7986-afe-clk.c    |  75 +++
 sound/soc/mediatek/mt7986/mt7986-afe-clk.h    |  18 +
 sound/soc/mediatek/mt7986/mt7986-afe-common.h |  51 ++
 sound/soc/mediatek/mt7986/mt7986-afe-pcm.c    | 598
++++++++++++++++++
 sound/soc/mediatek/mt7986/mt7986-dai-etdm.c   | 421 ++++++++++++
 sound/soc/mediatek/mt7986/mt7986-reg.h        | 206 ++++++
 sound/soc/mediatek/mt7986/mt7986-wm8960.c     | 184 ++++++
 12 files changed, 1726 insertions(+)
 create mode 100644
Documentation/devicetree/bindings/sound/mediatek,mt7986-afe.yaml
 create mode 100644
Documentation/devicetree/bindings/sound/mediatek,mt7986-wm8960.yaml
 create mode 100644 sound/soc/mediatek/mt7986/Makefile
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-clk.c
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-clk.h
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-common.h
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-afe-pcm.c
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-dai-etdm.c
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-reg.h
 create mode 100644 sound/soc/mediatek/mt7986/mt7986-wm8960.c
#25 lore raw
Quoted 6 lines · Maso Huang (黃加竹)

Gentle ping :)

Hi Rob and Angelo,

Can you help to check this latest series and share your thoughts if any?

You got comments to fix! Implement what you were asked to do.

Best regards,
Krzysztof