Skip to contentSkip to conversation

Add support for Tempo Semiconductor's TSCS42xx audio CODEC

PATCH Superseded Steven Eckhoff 2 participants 2 messages Nov 14, 2017 – Nov 15, 2017

Subsystems (4)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Steven Eckhoff

author maintainer
#0 lore raw

PATCH v2 1/1 Add support for Tempo Semiconductor's TSCS42xx audio CODEC

Currently there is no support for the TSCS42xx audio CODEC.

Add support for it.

Cc Steven Eckhoff <[email protected]>
Cc Liam Girdwood <[email protected]>
Cc Mark Brown <[email protected]>
Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>
---
 .../ABI/testing/sysfs-bus-i2c-devices-tscs42xx.txt |  185 ++
 .../devicetree/bindings/sound/tscs42xx.txt         |   24 +
 .../devicetree/bindings/vendor-prefixes.txt        |    1 +
 MAINTAINERS                                        |    5 +
 sound/soc/codecs/Kconfig                           |    8 +
 sound/soc/codecs/Makefile                          |    2 +
 sound/soc/codecs/tscs42xx.c                        | 2006 +++++++++++++++
 sound/soc/codecs/tscs42xx.h                        | 2693 ++++++++++++++++++++
 8 files changed, 4924 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-i2c-devices-tscs42xx.txt
 create mode 100644 Documentation/devicetree/bindings/sound/tscs42xx.txt
 create mode 100644 sound/soc/codecs/tscs42xx.c
 create mode 100644 sound/soc/codecs/tscs42xx.h
Documentation/ABI/testing/sysfs-bus-i2c-devices-tscs42xx.txt new file +185 -0
new file mode 100644
index 000000000000..ed409a97e812
@@ -0,0 +1,185 @@
+What:		/sys/bus/i2c/devices/.../dsp/eq[n]_ch[n]_[ab][n]
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Sets the equalizer biquad coefficient
+
+What:		/sys/bus/i2c/devices/.../dsp/eq[n]_ch[n]_prescale
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Sets the prescaler attenuation of the equalizer
+		biquad cascade
+
+What:		/sys/bus/i2c/devices/.../dsp/bass_ext[n]_[ab][n]
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Sets the bass extraction biquad coefficient
+
+What:		/sys/bus/i2c/devices/.../dsp/bass_lmt_[ab][n]
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Sets the bass non linear function coefficient
+
+What:		/sys/bus/i2c/devices/.../dsp/bass_cto_[ab][n]
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Sets the bass cut-off biquad coefficient
+
+What:		/sys/bus/i2c/devices/.../dsp/treb_ext[n]_[ab][n]
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Sets the treb extraction biquad coefficient
+
+What:		/sys/bus/i2c/devices/.../dsp/treb_lmt_[ab][n]
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Sets the treb non linear function coefficient
+
+What:		/sys/bus/i2c/devices/.../dsp/treb_cto_[ab][n]
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Sets the treb cut-off biquad coefficient
+
+What:		/sys/bus/i2c/devices/.../dsp/3d_coef
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Sets the 3d coefficient
+
+What:		/sys/bus/i2c/devices/.../dsp/3d_mix
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Sets 3d mix coefficient
+
+What:		/sys/bus/i2c/devices/.../dsp/bass_mix
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Sets bass mix coefficient
+
+What:		/sys/bus/i2c/devices/.../dsp/treb_mix
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Sets treb mix coefficient
+
+What:		/sys/bus/i2c/devices/.../controls/eq1_en
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Enables equalizer one
+
+What:		/sys/bus/i2c/devices/.../controls/eq1_bands_en
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Enables equalizer one bands:
+			0h = Pre-scale only
+			1h = Pre-scale + EQ band 0
+			2h = Pre-scale + EQ bands 0 to 1
+			...
+			6h = Pre-scale + EQ bands 0 to 5
+
+What:		/sys/bus/i2c/devices/.../controls/eq2_en
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Enables equalizer one
+
+What:		/sys/bus/i2c/devices/.../controls/eq2_bands_en
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Enables equalizer one bands:
+			0h = Pre-scale only
+			1h = Pre-scale + EQ band 0
+			2h = Pre-scale + EQ bands 0 to 1
+			...
+			6h = Pre-scale + EQ bands 0 to 5
+
+What:		/sys/bus/i2c/devices/.../controls/cle_level_mode
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Sets the compressor, limiter and expander level detection mode:
+			0h = Average
+			1h = Peak
+
+What:		/sys/bus/i2c/devices/.../controls/cle_level_detect_window
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Sets the compressor, limiter and expander level detection mode
+		window:
+			0h = Equivalent of 512 samples
+				at the selected Base Rate (~10-16ms)
+			1h = Equivalent of 64 samples
+				at the selected Base Rate (~1.3-2ms)
+
+What:		/sys/bus/i2c/devices/.../controls/exp_en
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Enables the expander
+
+What:		/sys/bus/i2c/devices/.../controls/limit_en
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Enables the limiter
+
+What:		/sys/bus/i2c/devices/.../controls/comp_en
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Enables the compressor
+
+What:		/sys/bus/i2c/devices/.../controls/3d_en
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Enables the 3D enhancer
+
+What:		/sys/bus/i2c/devices/.../controls/treb_en
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Enables the treble enhancer
+
+What:		/sys/bus/i2c/devices/.../controls/treb_nlf_bypass
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Enables the treble non-linear function bypass
+
+What:		/sys/bus/i2c/devices/.../controls/bass_en
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Enables the bass enhancer
+
+What:		/sys/bus/i2c/devices/.../controls/bass_nlf_bypass
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Enables the bass non-linear function bypass
+
+What:		/sys/bus/i2c/devices/.../control_regs/export
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Adds the specified control register to the sysfs interface
+
+What:		/sys/bus/i2c/devices/.../control_regs/unexport
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Removes the specified control register to the sysfs interface
Documentation/devicetree/bindings/sound/tscs42xx.txt new file +24 -0
new file mode 100644
index 000000000000..2f9c8affde48
@@ -0,0 +1,24 @@
+TSCS42XX Audio CODEC
+
+Required Properties:
+
+  - compatible : "tscs:tscs42xx"
+
+  - reg : The I2C address of the device
+
+  - mclk-src : The source of the master clock. This can be "mclk" or "xtal".
+
+  - mclk-src-freq : The frequency of the master clock
+
+  - clocks : The phandle of the master clock
+
+Example:
+
+codec: tscs42xx@69 {
+	compatible = "tscs,tscs42xx";
+	reg = <0x69>;
+	mclk-src = "mclk";
+	mclk-src-freq = <25000000>;
+	clocks = <&cprman BCM2835_CLOCK_GP1>;
+	status = "okay";
+};
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
index b1eeca851d6f..24036f503aa0 100644
@@ -349,6 +349,7 @@ tpo	TPO
 tronfy	Tronfy
 tronsmart	Tronsmart
 truly	Truly Semiconductors Limited
+tscs	Tempo Semiconductor
 tsd	Theobroma Systems Design und Consulting GmbH
 tyan	Tyan Computer Corporation
 ucrobotics	uCRobotics
MAINTAINERS +5 -0
index 650aa0e0e9d8..63d1d892842a 100644
@@ -13674,6 +13674,11 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial.git
 S:	Maintained
 K:	^Subject:.*(?i)trivial
 
+TEMPO SEMICONDUCTOR DRIVERS
+M:	Steven Eckhoff <[email protected]>
+S:	Maintained
+F:	sound/soc/codecs/tscs42xx.*
+
 TTY LAYER
 M:	Greg Kroah-Hartman <[email protected]>
 M:	Jiri Slaby <[email protected]>
sound/soc/codecs/Kconfig +8 -0
index c367d11079bc..34e911c1e082 100644
@@ -217,6 +217,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_WM9705 if SND_SOC_AC97_BUS
 	select SND_SOC_WM9712 if SND_SOC_AC97_BUS
 	select SND_SOC_WM9713 if SND_SOC_AC97_BUS
+	select SND_SOC_TSCS42XX if I2C
         help
           Normally ASoC codec drivers are only built if a machine driver which
           uses them is also built since they are only usable with a machine
@@ -1142,6 +1143,13 @@ config SND_SOC_ZX_AUD96P22
 	depends on I2C
 	select REGMAP_I2C
 
+config SND_SOC_TSCS42XX
+	tristate "Tempo Semiconductor TSCS42xx CODEC"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  Add support for Tempo Semiconductor's TSCS42xx audio CODEC.
+
 # Amp
 config SND_SOC_LM4857
 	tristate
sound/soc/codecs/Makefile +2 -0
index 05018b7ca72b..a20e643b4067 100644
@@ -230,6 +230,7 @@ snd-soc-wm9712-objs := wm9712.o
 snd-soc-wm9713-objs := wm9713.o
 snd-soc-wm-hubs-objs := wm_hubs.o
 snd-soc-zx-aud96p22-objs := zx_aud96p22.o
+snd-soc-tscs42xx-objs := tscs42xx.o
 # Amp
 snd-soc-dio2125-objs := dio2125.o
 snd-soc-max9877-objs := max9877.o
@@ -468,6 +469,7 @@ obj-$(CONFIG_SND_SOC_WM9713)	+= snd-soc-wm9713.o
 obj-$(CONFIG_SND_SOC_WM_ADSP)	+= snd-soc-wm-adsp.o
 obj-$(CONFIG_SND_SOC_WM_HUBS)	+= snd-soc-wm-hubs.o
 obj-$(CONFIG_SND_SOC_ZX_AUD96P22) += snd-soc-zx-aud96p22.o
+obj-$(CONFIG_SND_SOC_TSCS42XX)	+= snd-soc-tscs42xx.o
 
 # Amp
 obj-$(CONFIG_SND_SOC_DIO2125)	+= snd-soc-dio2125.o
sound/soc/codecs/tscs42xx.c new file +2006 -0

2,006 lines not on this page · raw message

sound/soc/codecs/tscs42xx.h new file +2693 -0

733 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.11.0

Part of the diff is not shown here. View the raw message.

maintainer
#1 lore raw
Quoted 1 line · Steven Eckhoff

Currently there is no support for the TSCS42xx audio CODEC.

This driver is doing a lot of weird, non-standard stuff without any explanation - quite a bit of this needs to be refactored to use standard interfaces. The code is mostly clean but if it doesn't fit in well with the rest of the system that's an issue.

Please submit patches using subject lines reflecting the style for the subsystem. This makes it easier for people to identify relevant patches. Look at what existing commits in the area you're changing are doing and make sure your subject lines visually resemble what they're doing.

Documentation/ABI/testing/sysfs-bus-i2c-devices-tscs42xx.txt line 5

Quoted 5 lines
Documentation/ABI/testing/sysfs-bus-i2c-devices-tscs42xx.txt new file +5 -0
+What:		/sys/bus/i2c/devices/.../dsp/eq[n]_ch[n]_[ab][n]
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Sets the equalizer biquad coefficient

Don't add sysfs files for configuring DSP coefficients, use binary controls like other drivers do so that all the audio configuration can be done via one interface.

Documentation/ABI/testing/sysfs-bus-i2c-devices-tscs42xx.txt line 137

Quoted 5 lines
Documentation/ABI/testing/sysfs-bus-i2c-devices-tscs42xx.txt new file +5 -0
+What:		/sys/bus/i2c/devices/.../controls/limit_en
+Date:		November 2017
+KernelVersion:	4.14
+Contact:	Steven Eckhoff <[email protected]>
+Description:	Enables the limiter

This isn't even a DSP coefficeint, this is just a standard on/off enable control. Why are you adding all this stuff that makes no attempt to use standard interfaces?

sound/soc/codecs/Kconfig config SND_SOC_ALL_CODECS · line 221

Quoted 9 lines

index c367d11079bc..34e911c1e082 100644

sound/soc/codecs/Kconfig +1 -0
@@ -217,6 +217,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_WM9705 if SND_SOC_AC97_BUS
 	select SND_SOC_WM9712 if SND_SOC_AC97_BUS
 	select SND_SOC_WM9713 if SND_SOC_AC97_BUS
+	select SND_SOC_TSCS42XX if I2C
         help

Keep these lists sorted please.

sound/soc/codecs/Kconfig config SND_SOC_ALL_CODECS

Quoted 4 lines
sound/soc/codecs/Kconfig +4 -0
+			/* Write LSB first due to auto increment on MSB */
+			ret = snd_soc_write(codec, R_DACCRWRL + j,
+					fw->data[i + NUM_DACCR_BYTES - 1 - j]);
+			if (ret < 0) {

Can't the device handle writing all three bytes at once (the regmap said it could)? If so that'd speed things up a lot.

sound/soc/codecs/Kconfig

Quoted 1 line
sound/soc/codecs/Kconfig +1 -0
+	dev_info(codec->dev, "Loaded tscs42xx_daccram.dfw\n");

dev_dbg() at most.

sound/soc/codecs/Kconfig

Quoted 13 lines
sound/soc/codecs/Kconfig +13 -0
+#define NUM_CONTROL_BYTES 2
+static int load_control_regs(struct snd_soc_codec *codec)
+{
+	const struct firmware *fw = NULL;
+	int ret;
+	int i;
+
+	ret = request_firmware_direct(&fw, "tscs42xx_controls.dfw", codec->dev);
+	if (ret) {
+		dev_info(codec->dev,
+			"No tscs42xx_controls.dfw file found (%d)\n", ret);
+		return 0;
+	}

What exactly are these controls?

sound/soc/codecs/Kconfig

Quoted 11 lines
sound/soc/codecs/Kconfig +11 -0
+	for (count = 0; count < PLL_LOCK_TIME_MAX; count++) {
+		reg = snd_soc_read(codec, R_PLLCTL0);
+		if (reg < 0) {
+			dev_err(codec->dev,
+				"Failed to read PLL lock status (%d)\n", ret);
+			break;
+		} else if (reg > 0) {
+			ret = true;
+			break;
+		}
+		mdelay(1);

A mdelay() is going to spin the CPU, is that really required or would an msleep() be fine?

sound/soc/codecs/Kconfig

Quoted 9 lines
sound/soc/codecs/Kconfig +9 -0
+static int tscs42xx_hw_params(struct snd_pcm_substream *substream,
+		struct snd_pcm_hw_params *params,
+		struct snd_soc_dai *codec_dai)
+{
+	struct snd_soc_codec *codec = codec_dai->codec;
+	struct tscs42xx_priv *tscs42xx = snd_soc_codec_get_drvdata(codec);
+	int ret;
+
+	mutex_lock(&tscs42xx->lock);

Why is there locking here? In general what is this lock for?

sound/soc/codecs/Kconfig

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+	case SND_SOC_DAIFMT_CBS_CFS:
+		ret = -EINVAL;
+		dev_err(codec->dev, "tscs42xx slave mode not supported (%d)\n",
+			ret);
+		break;
+	default:
+		ret = -EINVAL;
+		dev_err(codec->dev, "Unsupported format (%d)\n", ret);
+		break;
+	}

Just remove the _CBS_CFS case, it's redundant.

sound/soc/codecs/Kconfig

Quoted 5 lines
sound/soc/codecs/Kconfig +5 -0
+	switch (ratio) {
+	case 32:
+	value = RV_DACSR_DBCM_32;
+		break;
+	case 40:

Please follow the kernel coding style.

sound/soc/codecs/Kconfig

Quoted 9 lines
sound/soc/codecs/Kconfig +9 -0
+static int tscs42xx_i2c_read(struct i2c_client *i2c, u8 reg, u8 *val)
+{
+	int ret;
+
+	ret = i2c_smbus_write_byte(i2c, reg);
+	if (ret < 0) {
+		dev_err(&i2c->dev, "I2C write failed (%d)\n", ret);
+		return ret;
+	}

Why not just use the regmap?

sound/soc/codecs/Kconfig

Quoted 5 lines
sound/soc/codecs/Kconfig +5 -0
+	ret = of_property_read_string(np, "mclk-src", &mclk_src);
+	if (ret) {
+		dev_err(&i2c->dev, "mclk-src is needed (%d)\n", ret);
+		return ret;
+	}

If this needs to be in the DT rather than determined by the machine driver the mux should be a standard clock driver using the clock bindings.

sound/soc/codecs/Kconfig

Quoted 6 lines
sound/soc/codecs/Kconfig +6 -0
+	if (!strncmp(mclk_src, "mclk", 4)) {
+		tscs42xx->mclk = devm_clk_get(&i2c->dev, NULL);
+		if (IS_ERR(tscs42xx->mclk)) {
+			dev_info(&i2c->dev, "mclk not present trying again\n");
+			return -EPROBE_DEFER;
+		}

This is broken, it's just ignoring the error code and deferring even if there is a definitive error from the clock API.

sound/soc/codecs/Kconfig

Quoted 1 line
sound/soc/codecs/Kconfig +1 -0
+		tscs42xx->pll_src_clk = PLL_SRC_CLK_MCLK2;

What happened to MCLK1?

sound/soc/codecs/Kconfig

Quoted 3 lines
sound/soc/codecs/Kconfig +3 -0
+static int __init tscs42xx_modinit(void)
+{
+	int ret = 0;

module_i2c_driver().