[RFT] ASoC: ak4642: Fix up max_register setting
diff mbox

Message ID 1435459611.15772.2.camel@ingics.com
State New
Headers show

Commit Message

Axel Lin June 28, 2015, 2:46 a.m. UTC
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.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
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(-)

Comments

Mark Brown June 30, 2015, 10:46 a.m. UTC | #1
On Sun, Jun 28, 2015 at 10:46:51AM +0800, Axel Lin wrote:

>  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,

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?
Axel Lin June 30, 2015, 11:25 a.m. UTC | #2
2015-06-30 18:46 GMT+08:00 Mark Brown <broonie@kernel.org>:
> On Sun, Jun 28, 2015 at 10:46:51AM +0800, Axel Lin wrote:
>
>>  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,
>
> 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.)
Mark Brown June 30, 2015, 3:18 p.m. UTC | #3
On Tue, Jun 30, 2015 at 07:25:57PM +0800, Axel Lin wrote:
> 2015-06-30 18:46 GMT+08:00 Mark Brown <broonie@kernel.org>:

> >>  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,

> > 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.

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().

> 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.

Patch
diff mbox

diff --git a/sound/soc/codecs/ak4642.c b/sound/soc/codecs/ak4642.c
index 7c0f6552..7f27345 100644
--- a/sound/soc/codecs/ak4642.c
+++ b/sound/soc/codecs/ak4642.c
@@ -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 = {