Skip to contentSkip to conversation

add tas2780

PATCH Superseded Raphael-Xu 3 participants 3 messages Jul 4, 2022

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Raphael-Xu

author
#0 lore raw

PATCH 1/1 add tas2780

1.update Kconfig and Makefile 2.add tas2780.c and tas2780.h

---
 sound/soc/codecs/Kconfig   |   8 +
 sound/soc/codecs/Makefile  |   2 +
 sound/soc/codecs/tas2780.c | 726 +++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/tas2780.h | 101 ++++++
 4 files changed, 837 insertions(+)
 create mode 100644 sound/soc/codecs/tas2780.c
 create mode 100644 sound/soc/codecs/tas2780.h
sound/soc/codecs/Kconfig +8 -0
index 6165db92a629..4cb767642219 100644
@@ -219,6 +219,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_TAS2562
 	imply SND_SOC_TAS2764
 	imply SND_SOC_TAS2770
+	imply SND_SOC_TAS2780
 	imply SND_SOC_TAS5086
 	imply SND_SOC_TAS571X
 	imply SND_SOC_TAS5720
@@ -1524,6 +1525,13 @@ config SND_SOC_TAS2770
 	tristate "Texas Instruments TAS2770 speaker amplifier"
 	depends on I2C
 
+config SND_SOC_TAS2780
+	tristate "Texas Instruments TAS2780 Mono Audio amplifier"
+	depends on I2C
+	help
+	  Enable support for Texas Instruments TAS2780 high-efficiency mono
+	  digital input Class-D audio power amplifiers.
+
 config SND_SOC_TAS5086
 	tristate "Texas Instruments TAS5086 speaker amplifier"
 	depends on I2C
sound/soc/codecs/Makefile +2 -0
index 28dc4edfd01f..14273b68a7ec 100644
@@ -346,6 +346,7 @@ snd-soc-tpa6130a2-objs := tpa6130a2.o
 snd-soc-tas2552-objs := tas2552.o
 snd-soc-tas2562-objs := tas2562.o
 snd-soc-tas2764-objs := tas2764.o
+snd-soc-tas2780-objs := tas2780.o
 # Mux
 snd-soc-simple-mux-objs := simple-mux.o
 
@@ -589,6 +590,7 @@ obj-$(CONFIG_SND_SOC_STI_SAS)	+= snd-soc-sti-sas.o
 obj-$(CONFIG_SND_SOC_TAS2552)	+= snd-soc-tas2552.o
 obj-$(CONFIG_SND_SOC_TAS2562)	+= snd-soc-tas2562.o
 obj-$(CONFIG_SND_SOC_TAS2764)	+= snd-soc-tas2764.o
+obj-$(CONFIG_SND_SOC_TAS2780)	+= snd-soc-tas2780.o
 obj-$(CONFIG_SND_SOC_TAS5086)	+= snd-soc-tas5086.o
 obj-$(CONFIG_SND_SOC_TAS571X)	+= snd-soc-tas571x.o
 obj-$(CONFIG_SND_SOC_TAS5720)	+= snd-soc-tas5720.o
sound/soc/codecs/tas2780.c new file +726 -0

726 lines not on this page · raw message

sound/soc/codecs/tas2780.h new file +101 -0

101 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#1 lore raw
Quoted 1 line · Raphael-Xu

1.update Kconfig and Makefile 2.add tas2780.c and tas2780.h

This looks pretty good, there's some mostly stylistic things below but they're all fairly minor and you also need to provide documentation for the DT binding.

Quoted 4 lines

snd-soc-tas2562-objs := tas2562.o
snd-soc-tas2764-objs := tas2764.o
+snd-soc-tas2780-objs := tas2780.o
# Mux

Please preserve these blank lines here.

sound/soc/codecs/tas2780.c line 62

Quoted 6 lines
sound/soc/codecs/tas2780.c new file +6 -0
+	ret = snd_soc_component_update_bits(component, TAS2780_PWR_CTRL,
+					    TAS2780_PWR_CTRL_MASK,
+					    TAS2780_PWR_CTRL_SHUTDOWN);
+	if (ret < 0) {
+		pr_err("%s:errCode:0x%0x:power down error\n",
+			__func__, ret);

dev_err(), and the style used in the log message doesn't really match the typical kernel style at all.

Review

Quoted 1 line
(quoted diff) +1 -0
+		goto EXIT;

Labels should generally be lower case.

Quoted 12 lines
sound/soc/codecs/tas2780.c new file +12 -0
+static int tas2780_dac_event(struct snd_soc_dapm_widget *w,
+			     struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_component *component =
+		snd_soc_dapm_to_component(w->dapm);
+	struct tas2780_priv *tas2780 =
+		snd_soc_component_get_drvdata(component);
+	int ret = 0;
+
+	switch (event) {
+	case SND_SOC_DAPM_POST_PMU:
+		ret = snd_soc_component_update_bits(component,

sound/soc/codecs/tas2780.c line 132

Quoted 10 lines
sound/soc/codecs/tas2780.c new file +10 -0
+						TAS2780_PWR_CTRL,
+						TAS2780_PWR_CTRL_MASK,
+						TAS2780_PWR_CTRL_MUTE);
+		break;
+	case SND_SOC_DAPM_PRE_PMD:
+		ret = snd_soc_component_update_bits(component,
+						TAS2780_PWR_CTRL,
+						TAS2780_PWR_CTRL_MASK,
+						TAS2780_PWR_CTRL_SHUTDOWN);
+		break;

This looks like it should perhaps be a mute_stream operation while...

Quoted 12 lines
sound/soc/codecs/tas2780.c new file +12 -0
+static int tas2780_mute(struct snd_soc_dai *dai, int mute, int direction)
+{
+	struct snd_soc_component *component = dai->component;
+	struct tas2780_priv *tas2780 =
+		snd_soc_component_get_drvdata(component);
+	int ret = 0;
+
+	if (!mute) {
+		ret = snd_soc_component_update_bits(component,
+			TAS2780_CLK_CFG, TAS2780_CLK_CFG_MASK,
+			TAS2780_CLK_CFG_ENABLE);
+

sound/soc/codecs/tas2780.c line 200

Quoted 10 lines
sound/soc/codecs/tas2780.c new file +10 -0
+		if (ret < 0) {
+			dev_err(tas2780->dev,
+				"%s: Failed to CLK_CFG_ENABLE\n",
+				__func__);
+			goto EXIT;
+		}
+	}
+	ret = snd_soc_component_update_bits(component, TAS2780_PWR_CTRL,
+		TAS2780_PWR_CTRL_MASK,
+		mute ? TAS2780_PWR_CTRL_MUTE : 0);

...this is managing clocks which doesn't look like what I'd expect for a mute operation, that should probably be part of the power management (either a DAPM supply or in the bias level handling)?

sound/soc/codecs/tas2780.c line 392

Quoted 12 lines
sound/soc/codecs/tas2780.c new file +12 -0
+
+	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+	case SND_SOC_DAIFMT_I2S:
+	case SND_SOC_DAIFMT_DSP_A:
+		iface = TAS2780_TDM_CFG2_SCFG_I2S;
+		tdm_rx_start_slot = 1;
+		break;
+	case SND_SOC_DAIFMT_DSP_B:
+	case SND_SOC_DAIFMT_LEFT_J:
+		iface = TAS2780_TDM_CFG2_SCFG_LEFT_J;
+		tdm_rx_start_slot = 0;
+		break;

This doesn't seem right - it's using exactly the same configuration for multiple DAI formats.

sound/soc/codecs/tas2780.c line 615

Quoted 5 lines
sound/soc/codecs/tas2780.c new file +5 -0
+static bool tas2780_volatile(struct device *dev,
+	unsigned int reg)
+{
+			return true;
+}

Just don't specify a cache.

sound/soc/codecs/tas2780.c line 640

Quoted 12 lines
sound/soc/codecs/tas2780.c new file +12 -0
+static int tas2780_parse_dt(struct device *dev, struct tas2780_priv *tas2780)
+{
+	int ret = 0;
+
+	tas2780->reset_gpio = devm_gpiod_get_optional(tas2780->dev, "reset",
+		GPIOD_OUT_HIGH);
+	if (IS_ERR(tas2780->reset_gpio)) {
+		if (PTR_ERR(tas2780->reset_gpio) == -EPROBE_DEFER) {
+			tas2780->reset_gpio = NULL;
+			return -EPROBE_DEFER;
+		}
+	}

This has a DT binding but there's no DT binding document, any new DT bindings need to be documented.

#2 lore raw
In reply to Raphael-Xu
Quoted 4 lines · Raphael-Xu

1.update Kconfig and Makefile 2.add tas2780.c and tas2780.h

---

...

Quoted 30 lines
sound/soc/codecs/tas2780.c new file +24 -0
new file mode 100644
index 000000000000..0e452c7464fb
@@ -0,0 +1,726 @@
+// SPDX-License-Identifier: GPL-2.0
+// Driver for the Texas Instruments TAS2780 Mono
+//		Audio amplifier
+// Copyright (C) 2022 Texas Instruments Inc.
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
+#include <linux/regmap.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+#include <sound/soc.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/initval.h>
+#include <sound/tlv.h>
+
+#include "tas2780.h"

sound/soc/codecs/tas2780.c line 34

Quoted 10 lines
sound/soc/codecs/tas2780.c new file +10 -0
+
+struct tas2780_priv {
+	struct snd_soc_component *component;
+	struct gpio_desc *reset_gpio;
+	struct gpio_desc *sdz_gpio;
+	struct regmap *regmap;
+	struct device *dev;
+	int v_sense_slot;
+	int i_sense_slot;
+

Unnecessary empty line?

Quoted 15 lines
sound/soc/codecs/tas2780.c new file +15 -0
+};
+
+static void tas2780_reset(struct tas2780_priv *tas2780)
+{
+	if (tas2780->reset_gpio) {
+		gpiod_set_value_cansleep(tas2780->reset_gpio, 0);
+		usleep_range(2000, 2050);
+		gpiod_set_value_cansleep(tas2780->reset_gpio, 1);
+		usleep_range(2000, 2050);
+	}
+
+	snd_soc_component_write(tas2780->component, TAS2780_SW_RST,
+				TAS2780_RST);
+}
+

...

Quoted 6 lines
sound/soc/codecs/tas2780.c new file +6 -0
+
+static const struct snd_soc_component_driver soc_component_driver_tas2780 = {
+	.probe			= tas2780_codec_probe,
+#ifdef CONFIG_PM
+	.suspend		= tas2780_codec_suspend,
+	.resume			= tas2780_codec_resume,

sound/soc/codecs/tas2780.c line 583

Quoted 10 lines
sound/soc/codecs/tas2780.c new file +10 -0
+#endif
+	.controls		= tas2780_snd_controls,
+	.num_controls		= ARRAY_SIZE(tas2780_snd_controls),
+	.dapm_widgets		= tas2780_dapm_widgets,
+	.num_dapm_widgets	= ARRAY_SIZE(tas2780_dapm_widgets),
+	.dapm_routes		= tas2780_audio_map,
+	.num_dapm_routes	= ARRAY_SIZE(tas2780_audio_map),
+	.idle_bias_on		= 1,
+	.endianness		= 1,
+	.non_legacy_dai_naming	= 1,

From what I see change removing non_legacy_dai_naming field is merged in for-next branch, so you can skip it, as it is default now.

Quoted 15 lines
sound/soc/codecs/tas2780.c new file +15 -0
+};
+
+static const struct reg_default tas2780_reg_defaults[] = {
+	{ TAS2780_PAGE, 0x00 },
+	{ TAS2780_SW_RST, 0x00 },
+	{ TAS2780_PWR_CTRL, 0x1a },
+	{ TAS2780_DVC, 0x00 },
+	{ TAS2780_CHNL_0, 0x00 },
+	{ TAS2780_TDM_CFG0, 0x09 },
+	{ TAS2780_TDM_CFG1, 0x02 },
+	{ TAS2780_TDM_CFG2, 0x0a },
+	{ TAS2780_TDM_CFG3, 0x10 },
+	{ TAS2780_TDM_CFG5, 0x42 },
+};
+