Skip to contentSkip to conversation

ASoC: mediatek: Add basic PCM driver for MT8516

PATCH In review Fabien Parent 3 participants 9 messages May 2, 2019 – May 14, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover ASoC: mediatek: Add basic PCM driver for MT8516

This patch series add a basic PCM driver for MediaTek MT8516 with only support for ADDA Playback & Recording for now.

Fabien Parent (5):
ASoC: mediatek: make agent_disable, msb & hd fields optional
dt-bindings: sound: Add MT8516 AFE PCM bindings
ASoC: mediatek: Add MT8516 PCM driver
ASoC: mediatek: mt8516: Add ADDA DAI driver
ASoC: mediatek: mt8516: register ADDA DAI

 .../bindings/sound/mt8516-afe-pcm.txt         |  28 +
 sound/soc/mediatek/Kconfig                    |  10 +
 sound/soc/mediatek/Makefile                   |   1 +
 sound/soc/mediatek/common/mtk-afe-fe-dai.c    |  23 +-
 sound/soc/mediatek/mt8516/Makefile            |   7 +
 sound/soc/mediatek/mt8516/mt8516-afe-common.h |  18 +
 sound/soc/mediatek/mt8516/mt8516-afe-pcm.c    | 794 ++++++++++++++++++
 sound/soc/mediatek/mt8516/mt8516-afe-regs.h   | 218 +++++
 sound/soc/mediatek/mt8516/mt8516-dai-adda.c   | 316 +++++++
 9 files changed, 1406 insertions(+), 9 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/mt8516-afe-pcm.txt
 create mode 100644 sound/soc/mediatek/mt8516/Makefile
 create mode 100644 sound/soc/mediatek/mt8516/mt8516-afe-common.h
 create mode 100644 sound/soc/mediatek/mt8516/mt8516-afe-pcm.c
 create mode 100644 sound/soc/mediatek/mt8516/mt8516-afe-regs.h
 create mode 100644 sound/soc/mediatek/mt8516/mt8516-dai-adda.c
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/5 ASoC: mediatek: make agent_disable, msb & hd fields optional

Not every SoC have the following registers: agent_disable_reg, msg_reg, and hd_reg. Make them optional in order to allow more SoC to use the common DAI FE code.

---
 sound/soc/mediatek/common/mtk-afe-fe-dai.c | 23 +++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
sound/soc/mediatek/common/mtk-afe-fe-dai.c +14 -9
index cf4978be062f..f39f5d8c4244 100644
@@ -47,10 +47,13 @@ int mtk_afe_fe_startup(struct snd_pcm_substream *substream,
 
 	snd_pcm_hw_constraint_step(substream->runtime, 0,
 				   SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 16);
+
 	/* enable agent */
-	mtk_regmap_update_bits(afe->regmap, memif->data->agent_disable_reg,
-			       1 << memif->data->agent_disable_shift,
-			       0 << memif->data->agent_disable_shift);
+	if (memif->data->agent_disable_shift >= 0)
+		mtk_regmap_update_bits(afe->regmap,
+				       memif->data->agent_disable_reg,
+				       1 << memif->data->agent_disable_shift,
+				       0 << memif->data->agent_disable_shift);
 
 	snd_soc_set_runtime_hwparams(substream, mtk_afe_hardware);
 
@@ -143,9 +146,10 @@ int mtk_afe_fe_hw_params(struct snd_pcm_substream *substream,
 			 memif->phys_buf_addr + memif->buffer_size - 1);
 
 	/* set MSB to 33-bit */
-	mtk_regmap_update_bits(afe->regmap, memif->data->msb_reg,
-			       1 << memif->data->msb_shift,
-			       msb_at_bit33 << memif->data->msb_shift);
+	if (memif->data->msb_shift >= 0)
+		mtk_regmap_update_bits(afe->regmap, memif->data->msb_reg,
+				       1 << memif->data->msb_shift,
+				       msb_at_bit33 << memif->data->msb_shift);
 
 	/* set channel */
 	if (memif->data->mono_shift >= 0) {
@@ -269,9 +273,10 @@ int mtk_afe_fe_prepare(struct snd_pcm_substream *substream,
 		break;
 	}
 
-	mtk_regmap_update_bits(afe->regmap, memif->data->hd_reg,
-			       1 << memif->data->hd_shift,
-			       hd_audio << memif->data->hd_shift);
+	if (memif->data->hd_shift >= 0)
+		mtk_regmap_update_bits(afe->regmap, memif->data->hd_reg,
+				       1 << memif->data->hd_shift,
+				       hd_audio << memif->data->hd_shift);
 
 	return 0;
 }
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/5 dt-bindings: sound: Add MT8516 AFE PCM bindings

In reply to Fabien Parent

Add documentation for the bindings of the MT8516 AFE PCM driver.

---
 .../bindings/sound/mt8516-afe-pcm.txt         | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mt8516-afe-pcm.txt
Documentation/devicetree/bindings/sound/mt8516-afe-pcm.txt new file +28 -0
new file mode 100644
index 000000000000..c5fb3c55a7f4
@@ -0,0 +1,28 @@
+Mediatek AFE PCM controller for mt8516
+
+Required properties:
+- compatible:  "mediatek,mt8516-audio"
+- interrupts: should contain AFE interrupt
+- clocks: Must contain an entry for each entry in clock-names
+- clock-names: should have these clock names:
+		"top_pdn_audio",
+		"aud_dac_clk",
+		"aud_dac_predis_clk",
+		"aud_adc_clk";
+
+Example:
+
+
+	afe: mt8516-afe-pcm@11140000  {
+		compatible = "mediatek,mt8516-audio";
+		reg = <0 0x11140000 0 0x1000>;
+		interrupts = <GIC_SPI 120 IRQ_TYPE_LEVEL_LOW>;
+		clocks = <&topckgen CLK_TOP_AUDIO>,
+			 <&audiotop CLK_AUD_DAC>,
+			 <&audiotop CLK_AUD_DAC_PREDIS>,
+			 <&audiotop CLK_AUD_ADC>;
+		clock-names = "top_pdn_audio",
+			      "aud_dac_clk",
+			      "aud_dac_predis_clk",
+			      "aud_adc_clk";
+	};
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 2/5
#3 lore raw

Re: [PATCH 2/5] dt-bindings: sound: Add MT8516 AFE PCM bindings

Quoted 8 lines · Fabien Parent

Add documentation for the bindings of the MT8516 AFE PCM driver.

---
 .../bindings/sound/mt8516-afe-pcm.txt         | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mt8516-afe-pcm.txt
#4 lore raw

PATCH 3/5 ASoC: mediatek: Add MT8516 PCM driver

In reply to Fabien Parent

This commit adds the PCM driver for the MediaTek MT8516 SoC.

---
 sound/soc/mediatek/Kconfig                  |  10 +
 sound/soc/mediatek/Makefile                 |   1 +
 sound/soc/mediatek/mt8516/Makefile          |   6 +
 sound/soc/mediatek/mt8516/mt8516-afe-pcm.c  | 792 ++++++++++++++++++++
 sound/soc/mediatek/mt8516/mt8516-afe-regs.h | 218 ++++++
 5 files changed, 1027 insertions(+)
 create mode 100644 sound/soc/mediatek/mt8516/Makefile
 create mode 100644 sound/soc/mediatek/mt8516/mt8516-afe-pcm.c
 create mode 100644 sound/soc/mediatek/mt8516/mt8516-afe-regs.h
sound/soc/mediatek/Kconfig +10 -0
index b35410e4020e..f0bae957d475 100644
@@ -116,6 +116,16 @@ config SND_SOC_MT8183
 	  Select Y if you have such device.
 	  If unsure select "N".
 
+config SND_SOC_MT8516
+	tristate "ASoC support for Mediatek MT8516 chip"
+	depends on ARCH_MEDIATEK
+	select SND_SOC_MEDIATEK
+	help
+	  This adds ASoC platform driver support for Mediatek MT8516 chip
+	  that can be used with other codecs.
+	  Select Y if you have such device.
+	  If unsure select "N".
+
 config SND_SOC_MTK_BTCVSD
 	tristate "ALSA BT SCO CVSD/MSBC Driver"
 	help
sound/soc/mediatek/Makefile +1 -0
index 76032cae6d51..a48500d69a8b 100644
@@ -4,3 +4,4 @@ obj-$(CONFIG_SND_SOC_MT2701) += mt2701/
 obj-$(CONFIG_SND_SOC_MT6797) += mt6797/
 obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
 obj-$(CONFIG_SND_SOC_MT8183) += mt8183/
+obj-$(CONFIG_SND_SOC_MT8516) += mt8516/
sound/soc/mediatek/mt8516/Makefile new file +6 -0
new file mode 100644
index 000000000000..6e49b01d02c2
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+
+snd-soc-mt8516-afe-objs := \
+	mt8516-afe-pcm.o
+
+obj-$(CONFIG_SND_SOC_MT8516) += snd-soc-mt8516-afe.o
sound/soc/mediatek/mt8516/mt8516-afe-pcm.c new file +792 -0

792 lines not on this page · raw message

sound/soc/mediatek/mt8516/mt8516-afe-regs.h new file +218 -0

218 lines not on this page · raw message

Signature · 1 line
2.20.1
maintainer
#5 lore raw

Re: [PATCH 3/5] ASoC: mediatek: Add MT8516 PCM driver

Quoted 12 lines · Fabien Parent
sound/soc/mediatek/mt8516/mt8516-afe-pcm.c new file +12 -0
+static irqreturn_t mt8516_afe_irq_handler(int irq, void *dev_id)
+{
+	struct mtk_base_afe *afe = dev_id;
+	unsigned int reg_value;
+	unsigned int memif_status;
+	int i, ret;
+
+	ret = regmap_read(afe->regmap, AFE_IRQ_STATUS, &reg_value);
+	if (ret) {
+		reg_value = AFE_IRQ_STATUS_BITS;
+		goto exit_irq;
+	}

...

sound/soc/mediatek/mt8516/mt8516-afe-pcm.c line 531

Quoted 5 lines
sound/soc/mediatek/mt8516/mt8516-afe-pcm.c new file +5 -0
+exit_irq:
+	regmap_write(afe->regmap, AFE_IRQ_CLR, reg_value & AFE_IRQ_STATUS_BITS);
+
+	return IRQ_HANDLED;
+}

This unconditionally says it handled an interrupt regardless of what happened. This means that the interrupt line can't be shared and that the error handling code in the generic interrupt subsystem can't tell if something goes wrong and the interrupt gets stuck.

sound/soc/mediatek/mt8516/mt8516-afe-pcm.c line 714

Quoted 6 lines
sound/soc/mediatek/mt8516/mt8516-afe-pcm.c new file +6 -0
+	ret = devm_request_irq(afe->dev, irq_id, mt8516_afe_irq_handler,
+			       0, "Afe_ISR_Handle", (void *)afe);
+	if (ret) {
+		dev_err(afe->dev, "could not request_irq\n");
+		return ret;
+	}

Are you sure the interrupt handler can safely use managed resources, especially given...

sound/soc/mediatek/mt8516/mt8516-afe-pcm.c line 724

Quoted 9 lines
sound/soc/mediatek/mt8516/mt8516-afe-pcm.c new file +9 -0
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	afe->base_addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(afe->base_addr))
+		return PTR_ERR(afe->base_addr);
+
+	afe->regmap = devm_regmap_init_mmio(&pdev->dev, afe->base_addr,
+		&mt8516_afe_regmap_config);
+	if (IS_ERR(afe->regmap))
+		return PTR_ERR(afe->regmap);

...that things like the register map and the I/O resources for the chip are allocated after and therefore freed before before the interrupt is freed. Normally the interrupt should be one of the last things to be allocated.

sound/soc/mediatek/mt8516/mt8516-afe-pcm.c line 771

Quoted 4 lines
sound/soc/mediatek/mt8516/mt8516-afe-pcm.c new file +4 -0
+static int mt8516_afe_pcm_dev_remove(struct platform_device *pdev)
+{
+	return 0;
+}

In general if functions can legitimately be empty they should just be omitted, if they are required that usually means they have to do something.

#6 lore raw

PATCH 4/5 ASoC: mediatek: mt8516: Add ADDA DAI driver

In reply to Fabien Parent

Add the ADDA DAI driver for the MediaTek MT8516 SoC.

---
 sound/soc/mediatek/mt8516/Makefile            |   3 +-
 sound/soc/mediatek/mt8516/mt8516-afe-common.h |  18 +
 sound/soc/mediatek/mt8516/mt8516-dai-adda.c   | 316 ++++++++++++++++++
 3 files changed, 336 insertions(+), 1 deletion(-)
 create mode 100644 sound/soc/mediatek/mt8516/mt8516-afe-common.h
 create mode 100644 sound/soc/mediatek/mt8516/mt8516-dai-adda.c
sound/soc/mediatek/mt8516/Makefile +2 -1
index 6e49b01d02c2..dc05ab45560d 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 snd-soc-mt8516-afe-objs := \
-	mt8516-afe-pcm.o
+	mt8516-afe-pcm.o \
+	mt8516-dai-adda.o
 
 obj-$(CONFIG_SND_SOC_MT8516) += snd-soc-mt8516-afe.o
sound/soc/mediatek/mt8516/mt8516-afe-common.h new file +18 -0
new file mode 100644
index 000000000000..e70877c044a4
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2019 BayLibre, SAS
+ * Author: Fabien Parent <[email protected]>
+ */
+
+#ifndef _MT8516_AFE_COMMON_H_
+#define _MT8516_AFE_COMMON_H_
+
+#include "../common/mtk-base-afe.h"
+
+enum {
+	MT8516_AFE_BE_ADDA,
+};
+
+int mt8516_dai_adda_register(struct mtk_base_afe *afe);
+
+#endif
sound/soc/mediatek/mt8516/mt8516-dai-adda.c new file +316 -0

316 lines not on this page · raw message

Signature · 1 line
2.20.1
maintainer
#7 lore raw

Re: [PATCH 4/5] ASoC: mediatek: mt8516: Add ADDA DAI driver

sound/soc/mediatek/mt8516/mt8516-dai-adda.c line 168

Quoted 7 lines · Fabien Parent
sound/soc/mediatek/mt8516/mt8516-dai-adda.c new file +7 -0
+static int mt8516_afe_adda_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);
+	unsigned int width_val = params_width(params) > 16 ?
+		(AFE_CONN_24BIT_O03 | AFE_CONN_24BIT_O04) : 0;

Please write normal conditional statements rather than burying things in the variable declarations usin the ternery operator, it makes things much more legible.

#8 lore raw

PATCH 5/5 ASoC: mediatek: mt8516: register ADDA DAI

In reply to Fabien Parent

Register the ADDA DAI driver into the MT8516 PCM driver.

---
 sound/soc/mediatek/mt8516/mt8516-afe-pcm.c | 2 ++
 1 file changed, 2 insertions(+)
sound/soc/mediatek/mt8516/mt8516-afe-pcm.c +2 -0
index 84fbb5dbbd14..e1fd9290dd8f 100644
@@ -10,6 +10,7 @@
 #include <linux/module.h>
 #include <linux/of.h>
 
+#include "mt8516-afe-common.h"
 #include "mt8516-afe-regs.h"
 
 #include "../common/mtk-afe-platform-driver.h"
@@ -670,6 +671,7 @@ static int mt8516_dai_memif_register(struct mtk_base_afe *afe)
 typedef int (*dai_register_cb)(struct mtk_base_afe *);
 static const dai_register_cb dai_register_cbs[] = {
 	mt8516_dai_memif_register,
+	mt8516_dai_adda_register,
 };
 
 static int mt8516_afe_component_probe(struct snd_soc_component *component)
Signature · 1 line
2.20.1