Skip to contentSkip to conversation

ASoC: Add max98371 codec driver

PATCH In review anish kumar 3 participants 6 messages Mar 22, 2016 – Apr 10, 2016

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

PATCH 1/1 ASoC: Add max98371 codec driver

---
Changes in this version:
1. Removed the probe callback as it was not used.
2. Replaced the control with tlv

 .../devicetree/bindings/sound/max98371.txt         |  17 +
 sound/soc/codecs/max98371.c                        | 427 +++++++++++++++++++++
 sound/soc/codecs/max98371.h                        |  64 +++
 3 files changed, 508 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/max98371.txt
 create mode 100644 sound/soc/codecs/max98371.c
 create mode 100644 sound/soc/codecs/max98371.h
Documentation/devicetree/bindings/sound/max98371.txt new file +17 -0
new file mode 100644
index 0000000..6c28523
@@ -0,0 +1,17 @@
+max98371 codec
+
+This device supports I2C mode only.
+
+Required properties:
+
+- compatible : "maxim,max98371"
+- reg : The chip select number on the I2C bus
+
+Example:
+
+&i2c {
+	max98371: max98371@0x31 {
+		compatible = "maxim,max98371";
+		reg = <0x31>;
+	};
+};
sound/soc/codecs/max98371.c new file +427 -0

427 lines not on this page · raw message

sound/soc/codecs/max98371.h new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
1.9.3
maintainer
#1 lore raw

sound/soc/codecs/max98371.c line 29

Quoted 5 lines · anish kumar
sound/soc/codecs/max98371.c new file +5 -0
+static const char *const voltage_level_text[] = {
+	"9.5dB", "10.5dB", "11.5dB", "11.5dB", "12.5dB",
+	"13.5dB", "14.5dB", "15.5dB", "16.5dB", "17.5dB",
+	"18.5dB", "19.5dB", "20.5dB"
+};

These look like this control is a gain and so I'd expect it to be a normal TLV control. What does this control do exactly?

#2 lore raw
Quoted 10 lines · Mark Brown

sound/soc/codecs/max98371.c line 29

Quoted 5 lines · anish kumar
sound/soc/codecs/max98371.c new file +5 -0
+static const char *const voltage_level_text[] = {
+     "9.5dB", "10.5dB", "11.5dB", "11.5dB", "12.5dB",
+     "13.5dB", "14.5dB", "15.5dB", "16.5dB", "17.5dB",
+     "18.5dB", "19.5dB", "20.5dB"
+};

These look like this control is a gain and so I'd expect it to be a normal TLV control. What does this control do exactly?

It is "Speaker No-Load Output Voltage Maximum". It is described here on page 50.
https://datasheets.maximintegrated.com/en/ds/MAX98371.pdf

#3 lore raw
In reply to anish kumar

[...]

Quoted 1 line

+static struct reg_default max98371_reg[] = {

const
[...]

sound/soc/codecs/max98371.c line 142

Quoted 5 lines
sound/soc/codecs/max98371.c new file +5 -0
+static const unsigned int max98371_gain_tlv[] = {
+	0, 8, TLV_DB_SCALE_ITEM(0, 50, 0),
+	9, 10, TLV_DB_SCALE_ITEM(500, 100, 0),
+	11, 15, TLV_DB_SCALE_ITEM(0, 0, 0),
+};

I don't think this works, you need to define a container. This is best done using DECLARE_TLV_DB_RANGE().

sound/soc/codecs/max98371.c line 146

Quoted 4 lines
sound/soc/codecs/max98371.c new file +4 -0
+
+static const unsigned int max98371_noload_gain_tlv[] = {
+	0, 11, TLV_DB_SCALE_ITEM(0, 100, 0),
+};

Again, won't work I think, but since this is a single item, just just DECLARE_TLV_DB_SCALE.

[...]

sound/soc/codecs/max98371.c line 232

Quoted 2 lines
sound/soc/codecs/max98371.c new file +2 -0
+		pr_info("%s: format unsupported %d",
+				__func__, params_format(params));

Not pr_info(), maybe dev_err() or drop it altogether. Same for the other pr_info() calls.

sound/soc/codecs/max98371.c line 300

Quoted 3 lines
sound/soc/codecs/max98371.c new file +3 -0
+static const struct snd_soc_dapm_widget max98371_dapm_widgets[] = {
+	SND_SOC_DAPM_AIF_IN("DAI_OUT",
+		"HiFi Playback", 0, SND_SOC_NOPM, 0, 0),

This doesn't seem to do anything, just drop it.

sound/soc/codecs/max98371.c line 301

Quoted 1 line
sound/soc/codecs/max98371.c new file +1 -0
+	SND_SOC_DAPM_DAC("DAC Enable",

I'd just call this DAC.

sound/soc/codecs/max98371.c line 302

Quoted 1 line
sound/soc/codecs/max98371.c new file +1 -0
+		"HiFi Playback", MAX98371_SPK_ENABLE, 0, 0),

Drop the "HiFi Playback" here and connect the DAC in the routes to the "HiFi Playback" widget.

sound/soc/codecs/max98371.c line 318

Quoted 5 lines
sound/soc/codecs/max98371.c new file +5 -0
+	SND_SOC_DAPM_SUPPLY("Global Enable",
+		MAX98371_GLOBAL_ENABLE, 0, 0, NULL, 0),
+	SND_SOC_DAPM_OUTPUT("SPK_OUT"),
+};
+static struct snd_soc_dai_ops max98371_dai_ops = {

const

Quoted 4 lines
sound/soc/codecs/max98371.c new file +4 -0
+	.set_fmt = max98371_dai_set_fmt,
+	.hw_params = max98371_dai_hw_params,
+};
+

[...]

Quoted 1 line

+static struct snd_soc_codec_driver max98371_codec = {

const

Quoted 35 lines
sound/soc/codecs/max98371.c new file +35 -0
+	.controls = max98371_snd_controls,
+	.num_controls = ARRAY_SIZE(max98371_snd_controls),
+	.dapm_routes = max98371_audio_map,
+	.num_dapm_routes = ARRAY_SIZE(max98371_audio_map),
+	.dapm_widgets = max98371_dapm_widgets,
+	.num_dapm_widgets = ARRAY_SIZE(max98371_dapm_widgets),
+};
+
+static const struct regmap_config max98371_regmap = {
+	.reg_bits         = 8,
+	.val_bits         = 8,
+	.max_register     = MAX98371_VERSION,
+	.reg_defaults     = max98371_reg,
+	.num_reg_defaults = ARRAY_SIZE(max98371_reg),
+	.volatile_reg     = max98371_volatile_register,
+	.readable_reg     = max98371_readable_register,
+	.cache_type       = REGCACHE_RBTREE,
+};
+
+static int max98371_i2c_probe(struct i2c_client *i2c,
+		const struct i2c_device_id *id)
+{
+	struct max98371_priv *max98371;
+	int ret, reg;
+
+	max98371 = devm_kzalloc(&i2c->dev,
+			sizeof(*max98371), GFP_KERNEL);
+	if (!max98371)
+		return -ENOMEM;
+
+	i2c_set_clientdata(i2c, max98371);
+	max98371->regmap = devm_regmap_init_i2c(i2c, &max98371_regmap);
+	if (IS_ERR(max98371->regmap)) {
+		ret = PTR_ERR(max98371->regmap);
+		dev_err(&i2c->dev,

sound/soc/codecs/max98371.c line 382

Quoted 10 lines
sound/soc/codecs/max98371.c new file +10 -0
+				"Failed to allocate regmap: %d\n", ret);
+		return ret;
+	}
+
+	ret = regmap_read(max98371->regmap, MAX98371_VERSION, &reg);
+	if (ret < 0) {
+		dev_info(&i2c->dev, "device error %d\n", ret);
+		return ret;
+	}
+	dev_info(&i2c->dev, "device version %x\n", reg);

Drop this, it is just noise in the boot log.

Quoted 9 lines
sound/soc/codecs/max98371.c new file +9 -0
+
+	ret = snd_soc_register_codec(&i2c->dev, &max98371_codec,
+			max98371_dai, ARRAY_SIZE(max98371_dai));
+	if (ret < 0) {
+		dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
+		return ret;
+	}
+	return ret;
+}
#4 lore raw
Quoted 108 lines · Lars-Peter Clausen

[...]

Quoted 1 line

+static struct reg_default max98371_reg[] = {

const
[...]

sound/soc/codecs/max98371.c line 142

Quoted 5 lines
sound/soc/codecs/max98371.c new file +5 -0
+static const unsigned int max98371_gain_tlv[] = {
+     0, 8, TLV_DB_SCALE_ITEM(0, 50, 0),
+     9, 10, TLV_DB_SCALE_ITEM(500, 100, 0),
+     11, 15, TLV_DB_SCALE_ITEM(0, 0, 0),
+};

I don't think this works, you need to define a container. This is best done using DECLARE_TLV_DB_RANGE().

sound/soc/codecs/max98371.c line 146

Quoted 4 lines
sound/soc/codecs/max98371.c new file +4 -0
+
+static const unsigned int max98371_noload_gain_tlv[] = {
+     0, 11, TLV_DB_SCALE_ITEM(0, 100, 0),
+};

Again, won't work I think, but since this is a single item, just just DECLARE_TLV_DB_SCALE.

[...]

sound/soc/codecs/max98371.c line 232

Quoted 2 lines
sound/soc/codecs/max98371.c new file +2 -0
+             pr_info("%s: format unsupported %d",
+                             __func__, params_format(params));

Not pr_info(), maybe dev_err() or drop it altogether. Same for the other pr_info() calls.

sound/soc/codecs/max98371.c line 300

Quoted 3 lines
sound/soc/codecs/max98371.c new file +3 -0
+static const struct snd_soc_dapm_widget max98371_dapm_widgets[] = {
+     SND_SOC_DAPM_AIF_IN("DAI_OUT",
+             "HiFi Playback", 0, SND_SOC_NOPM, 0, 0),

This doesn't seem to do anything, just drop it.

Quoted 1 line

+ SND_SOC_DAPM_DAC("DAC Enable",

I'd just call this DAC.

Quoted 1 line

+ "HiFi Playback", MAX98371_SPK_ENABLE, 0, 0),

Drop the "HiFi Playback" here and connect the DAC in the routes to the "HiFi Playback" widget.

sound/soc/codecs/max98371.c line 318

Quoted 5 lines
sound/soc/codecs/max98371.c new file +5 -0
+     SND_SOC_DAPM_SUPPLY("Global Enable",
+             MAX98371_GLOBAL_ENABLE, 0, 0, NULL, 0),
+     SND_SOC_DAPM_OUTPUT("SPK_OUT"),
+};
+static struct snd_soc_dai_ops max98371_dai_ops = {

const

Quoted 4 lines
sound/soc/codecs/max98371.c new file +4 -0
+     .set_fmt = max98371_dai_set_fmt,
+     .hw_params = max98371_dai_hw_params,
+};
+

[...]

Quoted 1 line

+static struct snd_soc_codec_driver max98371_codec = {

const

Quoted 35 lines
sound/soc/codecs/max98371.c new file +35 -0
+     .controls = max98371_snd_controls,
+     .num_controls = ARRAY_SIZE(max98371_snd_controls),
+     .dapm_routes = max98371_audio_map,
+     .num_dapm_routes = ARRAY_SIZE(max98371_audio_map),
+     .dapm_widgets = max98371_dapm_widgets,
+     .num_dapm_widgets = ARRAY_SIZE(max98371_dapm_widgets),
+};
+
+static const struct regmap_config max98371_regmap = {
+     .reg_bits         = 8,
+     .val_bits         = 8,
+     .max_register     = MAX98371_VERSION,
+     .reg_defaults     = max98371_reg,
+     .num_reg_defaults = ARRAY_SIZE(max98371_reg),
+     .volatile_reg     = max98371_volatile_register,
+     .readable_reg     = max98371_readable_register,
+     .cache_type       = REGCACHE_RBTREE,
+};
+
+static int max98371_i2c_probe(struct i2c_client *i2c,
+             const struct i2c_device_id *id)
+{
+     struct max98371_priv *max98371;
+     int ret, reg;
+
+     max98371 = devm_kzalloc(&i2c->dev,
+                     sizeof(*max98371), GFP_KERNEL);
+     if (!max98371)
+             return -ENOMEM;
+
+     i2c_set_clientdata(i2c, max98371);
+     max98371->regmap = devm_regmap_init_i2c(i2c, &max98371_regmap);
+     if (IS_ERR(max98371->regmap)) {
+             ret = PTR_ERR(max98371->regmap);
+             dev_err(&i2c->dev,

sound/soc/codecs/max98371.c line 382

Quoted 10 lines
sound/soc/codecs/max98371.c new file +10 -0
+                             "Failed to allocate regmap: %d\n", ret);
+             return ret;
+     }
+
+     ret = regmap_read(max98371->regmap, MAX98371_VERSION, &reg);
+     if (ret < 0) {
+             dev_info(&i2c->dev, "device error %d\n", ret);
+             return ret;
+     }
+     dev_info(&i2c->dev, "device version %x\n", reg);

Drop this, it is just noise in the boot log.

Quoted 9 lines

sound/soc/codecs/max98371.c line 391

Quoted 9 lines
sound/soc/codecs/max98371.c new file +9 -0
+
+     ret = snd_soc_register_codec(&i2c->dev, &max98371_codec,
+                     max98371_dai, ARRAY_SIZE(max98371_dai));
+     if (ret < 0) {
+             dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
+             return ret;
+     }
+     return ret;
+}

Thanks. All comments will be addressed in the next patch.

maintainer
#5 lore raw
In reply to Lars-Peter Clausen
Quoted 8 lines · Lars-Peter Clausen

sound/soc/codecs/max98371.c line 382

Quoted 6 lines
sound/soc/codecs/max98371.c new file +6 -0
+	ret = regmap_read(max98371->regmap, MAX98371_VERSION, &reg);
+	if (ret < 0) {
+		dev_info(&i2c->dev, "device error %d\n", ret);
+		return ret;
+	}
+	dev_info(&i2c->dev, "device version %x\n", reg);

Drop this, it is just noise in the boot log.

It's generally OK to print information about the actual hardware found in the system, it can be a helpful diagnostic. Getting all this stuff into sysfs files would be even better but that doesn't seem to be how we do things at the minute.