Skip to contentSkip to conversation

ASoC: ak4642: Fix up max_register setting

PATCH Superseded Axel Lin 2 participants 4 messages Jun 28, 2015 – Jun 30, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 ASoC: ak4642: Fix up max_register setting

The max_register setting for ak4642, ak4643 and ak4648 are wrong, fix it.

According to the datasheet:

        the maximum valid register for ak4642 is 0x1f
        the maximum valid register for ak4643 is 0x24
        the maximum valid register for ak4648 is 0x27

The default settings for ak4642 and ak4643 are the same for 0x0 ~ 0x1f registers, so it's fine to use the same reg_default table with different num_reg_defaults setting.

---
Hi,
I don't have this h/w to test.
I'd appreciate if someone can review and test this patch. Thanks,
Axel

 sound/soc/codecs/ak4642.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
sound/soc/codecs/ak4642.c +18 -7
index 7c0f6552..7f27345 100644
@@ -64,12 +64,15 @@
 #define FIL1_0		0x1c
 #define FIL1_1		0x1d
 #define FIL1_2		0x1e
-#define FIL1_3		0x1f
+#define FIL1_3		0x1f	/* The maximum valid register for ak4642 */
 #define PW_MGMT4	0x20
 #define MD_CTL5		0x21
 #define LO_MS		0x22
 #define HP_MS		0x23
-#define SPK_MS		0x24
+#define SPK_MS		0x24	/* The maximum valid register for ak4643 */
+#define EQ_FBEQAB	0x25
+#define EQ_FBEQCD	0x26
+#define EQ_FBEQE	0x27	/* The maximum valid register for ak4648 */
 
 /* PW_MGMT1*/
 #define PMVCM		(1 << 6) /* VCOM Power Management */
@@ -535,17 +538,25 @@ static struct snd_soc_codec_driver soc_codec_dev_ak4642 = {
 static const struct regmap_config ak4642_regmap = {
 	.reg_bits		= 8,
 	.val_bits		= 8,
-	.max_register		= ARRAY_SIZE(ak4642_reg) + 1,
+	.max_register		= FIL1_3,
 	.reg_defaults		= ak4642_reg,
-	.num_reg_defaults	= ARRAY_SIZE(ak4642_reg),
+	.num_reg_defaults	= FIL1_3 + 1,
+};
+
+static const struct regmap_config ak4643_regmap = {
+	.reg_bits		= 8,
+	.val_bits		= 8,
+	.max_register		= SPK_MS,
+	.reg_defaults		= ak4642_reg,
+	.num_reg_defaults	= SPK_MS + 1,
 };
 
 static const struct regmap_config ak4648_regmap = {
 	.reg_bits		= 8,
 	.val_bits		= 8,
-	.max_register		= ARRAY_SIZE(ak4648_reg) + 1,
+	.max_register		= EQ_FBEQE,
 	.reg_defaults		= ak4648_reg,
-	.num_reg_defaults	= ARRAY_SIZE(ak4648_reg),
+	.num_reg_defaults	= EQ_FBEQE + 1,
 };
 
 static const struct ak4642_drvdata ak4642_drvdata = {
@@ -553,7 +564,7 @@ static const struct ak4642_drvdata ak4642_drvdata = {
 };
 
 static const struct ak4642_drvdata ak4643_drvdata = {
-	.regmap_config = &ak4642_regmap,
+	.regmap_config = &ak4643_regmap,
 };
 
 static const struct ak4642_drvdata ak4648_drvdata = {
Signature · 1 line
2.1.0
maintainer
#1 lore raw

sound/soc/codecs/ak4642.c static struct snd_soc_codec_driver soc_codec_dev_ak4642 = { · line 543

Quoted 8 lines · Axel Lin

static const struct regmap_config ak4642_regmap = {

sound/soc/codecs/ak4642.c +2 -2
 	.reg_bits		= 8,
 	.val_bits		= 8,
-	.max_register		= ARRAY_SIZE(ak4642_reg) + 1,
+	.max_register		= FIL1_3,
 	.reg_defaults		= ak4642_reg,
-	.num_reg_defaults	= ARRAY_SIZE(ak4642_reg),
+	.num_reg_defaults	= FIL1_3 + 1,

This change is incorrect, the number of register defaults must match the size of the array of register defaults being passed in. Why are you changing this?

author
#2 lore raw

2015-06-30 18:46 GMT+08:00 Mark Brown <[email protected]>:

Quoted 11 lines · Axel Lin

sound/soc/codecs/ak4642.c static struct snd_soc_codec_driver soc_codec_dev_ak4642 = { · line 543

Quoted 9 lines

static const struct regmap_config ak4642_regmap = {
.reg_bits = 8,
.val_bits = 8,

sound/soc/codecs/ak4642.c +2 -2
-     .max_register           = ARRAY_SIZE(ak4642_reg) + 1,
+     .max_register           = FIL1_3,
      .reg_defaults           = ak4642_reg,
-     .num_reg_defaults       = ARRAY_SIZE(ak4642_reg),
+     .num_reg_defaults       = FIL1_3 + 1,
Quoted 3 lines

This change is incorrect, the number of register defaults must match the size of the array of register defaults being passed in. Why are you changing this?

Because I reuse the same reg_default for ak4642 and ak4643. According to the datasheet:
For ak4642, the valid registers are 0x0 ~ 0x1f (FIL1_3)
For ak4643, the valid registers are 0x0 ~ 0x24 (SPK_MS)
The default registers for 0x0 ~ 0x1f are the same for ak4642 and ak4643.

That is why this patch set .num_reg_defaults = FIL1_3 + 1 for ak4642.

Or do you prefer having separate reg_default for ak4642 and ak4643? (Then it can use ARRAY_SIZE() here.)

maintainer
#3 lore raw
Quoted 15 lines · Axel Lin

2015-06-30 18:46 GMT+08:00 Mark Brown <[email protected]>:

Quoted 9 lines

sound/soc/codecs/ak4642.c static struct snd_soc_codec_driver soc_codec_dev_ak4642 = { · line 543

Quoted 8 lines

static const struct regmap_config ak4642_regmap = {
.reg_bits = 8,
.val_bits = 8,

sound/soc/codecs/ak4642.c +2 -2
-     .max_register           = ARRAY_SIZE(ak4642_reg) + 1,
+     .max_register           = FIL1_3,
      .reg_defaults           = ak4642_reg,
-     .num_reg_defaults       = ARRAY_SIZE(ak4642_reg),
+     .num_reg_defaults       = FIL1_3 + 1,
Quoted 3 lines

This change is incorrect, the number of register defaults must match the size of the array of register defaults being passed in. Why are you changing this?

Quoted 5 lines

Because I reuse the same reg_default for ak4642 and ak4643. According to the datasheet:
For ak4642, the valid registers are 0x0 ~ 0x1f (FIL1_3)
For ak4643, the valid registers are 0x0 ~ 0x24 (SPK_MS)
The default registers for 0x0 ~ 0x1f are the same for ak4642 and ak4643.

Ah, I see. That definitely deserves a comment since it's very unusual - possibly also with a BUILD_BUG_ON() for the define being less than ARRAY_SIZE().

Quoted 2 lines

Or do you prefer having separate reg_default for ak4642 and ak4643? (Then it can use ARRAY_SIZE() here.)

No, what you're doing is OK but really ought to have comments so it's clearer.