ASoC: max98373: Added max98373_reset for stable amp reset
PATCH 1/1 ASoC: max98373: Added max98373_reset for stable amp reset
---
Changes : Created max98373_reset function to minimize code duplication.
Changed regmap_write to regmap_update_bits. Other bits except LSB need to be masked.
Added reset verification step to make sure software reset is completed well. Software reset is done in 10ms in normal case. Revision ID is available when the amp is in the idle state which means software reset is completed.
Software reset will be performed maximum 3 times to avoid amp reset failure. Generally it is done in the first trial. sleep time after software reset is increased + 30ms for every retrial. Maximum possible msleep time is 100 ms (initial 10 ms + 30 ms * 3 times).
sound/soc/codecs/max98373.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-)
sound/soc/codecs/max98373.c +35 -6
@@ -724,14 +724,45 @@ static struct snd_soc_dai_driver max98373_dai[] = { } }; +static void max98373_reset (struct max98373_priv *max98373,struct device *dev) +{ +int ret, reg, count, delay; + + count =0 ; +while (true) { +/* Software Reset */ + ret =regmap_update_bits (max98373->regmap, +MAX98373_R2000_SW_RESET , +MAX98373_SOFT_RESET , +MAX98373_SOFT_RESET ); +if (ret) +dev_err (dev,"Reset command failed. (ret:%d)\n" , ret); + + delay =10000 + (count *30000 ); +usleep_range (delay, delay +1000 ); + +/* Software Reset Verification */ + ret =regmap_read (max98373->regmap, +MAX98373_R21FF_REV_ID , ®); +if (!ret) { +dev_info (dev,"Reset completed (retry:%d)\n" , count); +break ; + } + +if (++count >3 ) { +dev_err (dev,"Reset failed. (ret:%d)\n" , ret); +break ; + } +usleep_range (10000 ,11000 ); + } +} +static int max98373_probe (struct snd_soc_component *component) {struct max98373_priv *max98373 =snd_soc_component_get_drvdata (component);/* Software Reset */ -regmap_write (max98373->regmap, -MAX98373_R2000_SW_RESET ,MAX98373_SOFT_RESET ); -usleep_range (10000 ,11000 ); +max98373_reset (max98373, component->dev);/* IV default slot configuration */ regmap_write(max98373->regmap,
@@ -818,9 +849,7 @@ static int max98373_resume(struct device *dev) {struct max98373_priv *max98373 =dev_get_drvdata (dev); -regmap_write (max98373->regmap, -MAX98373_R2000_SW_RESET ,MAX98373_SOFT_RESET ); -usleep_range (10000 ,11000 ); +max98373_reset (max98373, dev);regcache_cache_only (max98373->regmap, false);regcache_sync (max98373->regmap);return 0 ;
Signature · 1 line
2.7.4
Hi Ryan!
Just some questions inline - in general I like the reset function.
Quoted 9 lines · Ryan Lee
Signed-off-by Ryan Lee <[email protected]>---
Changes : Createdmax98373_resetfunction to minimize code duplication.
Changedregmap_writetoregmap_update_bits. Other bits except LSB need to be masked.
Added reset verification step to make sure software reset is completed well. Software reset is done in 10ms in normal case. Revision ID is available when the amp is in the idle state which means software reset is completed.
Software reset will be performed maximum 3 times to avoid amp reset failure. Generally it is done in the first trial. sleep time after software reset is increased + 30ms for every retrial. Maximum possible msleep time is 100 ms (initial 10 ms + 30 ms * 3 times).
Why is the sleep time increased after each SW reset?
What is the failure case that you've seen which would benefit from this?
Quoted 25 lines
sound/soc/codecs/max98373.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-)sound/soc/codecs/max98373.c +13
-0@@ -724,14 +724,45 @@ static struct snd_soc_dai_driver max98373_dai[] = { } }; +static void max98373_reset (struct max98373_priv *max98373,struct device *dev) +{ +int ret, reg, count, delay; + + count =0 ; +while (true) { +/* Software Reset */ + ret =regmap_update_bits (max98373->regmap, +MAX98373_R2000_SW_RESET , +MAX98373_SOFT_RESET , +MAX98373_SOFT_RESET ); +if (ret) +dev_err (dev,"Reset command failed. (ret:%d)\n" , ret);
sound/soc/codecs/max98373.c static struct snd_soc_dai_driver max98373_dai[] = { · line 749
Quoted 10 lines
sound/soc/codecs/max98373.c +10
-0+ + delay =10000 + (count *30000 ); +usleep_range (delay, delay +1000 ); + +/* Software Reset Verification */ + ret =regmap_read (max98373->regmap, +MAX98373_R21FF_REV_ID , ®); +if (!ret) { +dev_info (dev,"Reset completed (retry:%d)\n" , count); +break ;
Instead of break, can the code return here?
"break" implies something else will happen after the while loop exits
- there isn't.
sound/soc/codecs/max98373.c static struct snd_soc_dai_driver max98373_dai[] = { · line 756
Quoted 7 lines
sound/soc/codecs/max98373.c +7
-0+ } + +if (++count >3 ) { +dev_err (dev,"Reset failed. (ret:%d)\n" , ret); +break ; + } +usleep_range (10000 ,11000 );
Why is there a second delay after reading MAX98373_R21FF_REV_ID? Is this really necessary?
If the second usleep_range() isn't needed, it would be better/clearer
to make code loop on "while (count < 4)". And then outside the while
loop, use dev_err() to share what the failure was.
Quoted 27 lines
sound/soc/codecs/max98373.c +5
-7+ } +} +static int max98373_probe (struct snd_soc_component *component) {struct max98373_priv *max98373 =snd_soc_component_get_drvdata (component);/* Software Reset */ -regmap_write (max98373->regmap, -MAX98373_R2000_SW_RESET ,MAX98373_SOFT_RESET ); -usleep_range (10000 ,11000 ); +max98373_reset (max98373, component->dev);/* IV default slot configuration */ regmap_write(max98373->regmap,@@ -818,9 +849,7 @@ static int max98373_resume(struct device *dev) {struct max98373_priv *max98373 =dev_get_drvdata (dev); -regmap_write (max98373->regmap, -MAX98373_R2000_SW_RESET ,MAX98373_SOFT_RESET ); -usleep_range (10000 ,11000 ); +max98373_reset (max98373, dev);regcache_cache_only (max98373->regmap, false);regcache_sync (max98373->regmap);return 0 ; --
Quoted 2 lines
2.7.4
cheers,
grant
I just realized I had one more question...
Quoted 13 lines · Grant Grundler
Hi Ryan!
Just some questions inline - in general I like the reset function.
Quoted 7 lines · Ryan Lee
Signed-off-by Ryan Lee <[email protected]>---
Changes : Createdmax98373_resetfunction to minimize code duplication.
Changedregmap_writetoregmap_update_bits. Other bits except LSB need to be masked.
Added reset verification step to make sure software reset is completed well. Software reset is done in 10ms in normal case. Revision ID is available when the amp is in the idle state which means software reset is completed.
Why not poll the RevID register a few times until it gives a value?
Then structure the code to try reset twice (maybe three times). This would avoid the unusual "sleep time after reset is increased" code.
cheers,
grant
Quoted 93 lines
Quoted 2 lines
Software reset will be performed maximum 3 times to avoid amp reset failure. Generally it is done in the first trial. sleep time after software reset is increased + 30ms for every retrial. Maximum possible msleep time is 100 ms (initial 10 ms + 30 ms * 3 times).
Why is the sleep time increased after each SW reset?
What is the failure case that you've seen which would benefit from this?Quoted 25 lines
sound/soc/codecs/max98373.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-)sound/soc/codecs/max98373.c +13
-0@@ -724,14 +724,45 @@ static struct snd_soc_dai_driver max98373_dai[] = { } }; +static void max98373_reset (struct max98373_priv *max98373,struct device *dev) +{ +int ret, reg, count, delay; + + count =0 ; +while (true) { +/* Software Reset */ + ret =regmap_update_bits (max98373->regmap, +MAX98373_R2000_SW_RESET , +MAX98373_SOFT_RESET , +MAX98373_SOFT_RESET ); +if (ret) +dev_err (dev,"Reset command failed. (ret:%d)\n" , ret);sound/soc/codecs/max98373.c static struct snd_soc_dai_driver max98373_dai[] = { · line 749
Quoted 10 lines
sound/soc/codecs/max98373.c +10
-0+ + delay =10000 + (count *30000 ); +usleep_range (delay, delay +1000 ); + +/* Software Reset Verification */ + ret =regmap_read (max98373->regmap, +MAX98373_R21FF_REV_ID , ®); +if (!ret) { +dev_info (dev,"Reset completed (retry:%d)\n" , count); +break ;Instead of break, can the code return here?
"break" implies something else will happen after the while loop exits
- there isn't.sound/soc/codecs/max98373.c static struct snd_soc_dai_driver max98373_dai[] = { · line 756
Quoted 7 lines
sound/soc/codecs/max98373.c +7
-0+ } + +if (++count >3 ) { +dev_err (dev,"Reset failed. (ret:%d)\n" , ret); +break ; + } +usleep_range (10000 ,11000 );Why is there a second delay after reading
MAX98373_R21FF_REV_ID? Is this really necessary?If the second
usleep_range()isn't needed, it would be better/clearer
to make code loop on "while (count < 4)". And then outside the while
loop, usedev_err()to share what the failure was.Quoted 27 lines
sound/soc/codecs/max98373.c +5
-7+ } +} +static int max98373_probe (struct snd_soc_component *component) {struct max98373_priv *max98373 =snd_soc_component_get_drvdata (component);/* Software Reset */ -regmap_write (max98373->regmap, -MAX98373_R2000_SW_RESET ,MAX98373_SOFT_RESET ); -usleep_range (10000 ,11000 ); +max98373_reset (max98373, component->dev);/* IV default slot configuration */ regmap_write(max98373->regmap,@@ -818,9 +849,7 @@ static int max98373_resume(struct device *dev) {struct max98373_priv *max98373 =dev_get_drvdata (dev); -regmap_write (max98373->regmap, -MAX98373_R2000_SW_RESET ,MAX98373_SOFT_RESET ); -usleep_range (10000 ,11000 ); +max98373_reset (max98373, dev);regcache_cache_only (max98373->regmap, false);regcache_sync (max98373->regmap);return 0 ; --Quoted 2 lines
2.7.4
cheers,
grant
Quoted 34 lines
-----Original Message-----
From: Grant Grundler <[email protected]>
Sent: Monday, November 26, 2018 6:28 PM
To: Grant Grundler <[email protected]>
Cc: Ryan Lee <[email protected]>; Liam Girdwood <[email protected]>; [email protected]; [email protected]; [email protected]; Kuninori Morimoto <[email protected]>; Benson Leung <[email protected]>; [email protected]; LKML <[email protected]>
Subject: Re: [PATCH] ASoC: max98373: Addedmax98373_resetfor stable amp resetEXTERNAL EMAIL
I just realized I had one more question...
Quoted 6 lines · Grant Grundler
Hi Ryan!
Just some questions inline - in general I like the reset function.
On Mon, Nov 26, 2018 at 10:46 AM Ryan Lee
Quoted 5 lines · <[email protected]> wrote:
Quoted 5 lines
Signed-off-by Ryan Lee <[email protected]>---
Changes : Createdmax98373_resetfunction to minimize code duplication.
Changedregmap_writetoregmap_update_bits. Other bits exceptLSB need to be masked.
Quoted 1 line
Quoted 1 line
Added reset verification step to make sure software reset is
Quoted 8 lines
completed well. Software reset is done in 10ms in normal case.
Quoted 1 line
Quoted 1 line
Revision ID is available when the amp is in the idle state which means
software reset is completed.
Why not poll the RevID register a few times until it gives a value?
Then structure the code to try reset twice (maybe three times). This would avoid the unusual "sleep time after reset is increased" code.
Let me fix unusual things here. Thanks for the comment.
Quoted 101 lines
cheers,
grantQuoted 1 line
Quoted 1 line
Software reset will be performed maximum 3 times to avoid amp
reset failure. Generally it is done in the first trial.
Quoted 1 line
Quoted 1 line
sleep time after software reset is increased + 30ms for every retrial.
Maximum possible msleep time is 100 ms (initial 10 ms + 30 ms * 3 times).
Quoted 9 lines
Why is the sleep time increased after each SW reset?
What is the failure case that you've seen which would benefit from this?Quoted 5 lines
sound/soc/codecs/max98373.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-)Quoted 5 lines
sound/soc/codecs/max98373.c static struct snd_soc_dai_driver max98373_dai[]
Quoted 5 lines
(quoted diff) +0
-0
b/sound/soc/codecs/max98373.cindex a09d013..55af7f02 100644sound/soc/codecs/max98373.c +0
-0@@ -724,14 +724,45 @@ static struct snd_soc_dai_driver max98373_dai[]= {
Quoted 78 lines
Quoted 17 lines
sound/soc/codecs/max98373.c +14
-0} }; +static void max98373_reset(struct max98373_priv *max98373, struct +device *dev) { + int ret, reg, count, delay; + + count = 0; + while (true) { + /* Software Reset */ + ret = regmap_update_bits(max98373->regmap, + MAX98373_R2000_SW_RESET, + MAX98373_SOFT_RESET, + MAX98373_SOFT_RESET); + if (ret) + dev_err(dev, "Reset command failed. + (ret:%d)\n", ret);sound/soc/codecs/max98373.c static struct snd_soc_dai_driver max98373_dai[] = { · line 749
Quoted 10 lines
sound/soc/codecs/max98373.c +10
-0+ + delay =10000 + (count *30000 ); +usleep_range (delay, delay +1000 ); + +/* Software Reset Verification */ + ret =regmap_read (max98373->regmap, +MAX98373_R21FF_REV_ID , ®); +if (!ret) { +dev_info (dev,"Reset completed (retry:%d)\n" , count); +break ;Instead of break, can the code return here?
"break" implies something else will happen after the while loop exits
- there isn't.sound/soc/codecs/max98373.c static struct snd_soc_dai_driver max98373_dai[] = { · line 756
Quoted 7 lines
sound/soc/codecs/max98373.c +7
-0+ } + +if (++count >3 ) { +dev_err (dev,"Reset failed. (ret:%d)\n" , ret); +break ; + } +usleep_range (10000 ,11000 );Why is there a second delay after reading
MAX98373_R21FF_REV_ID? Is this really necessary?If the second
usleep_range()isn't needed, it would be better/clearer
to make code loop on "while (count < 4)". And then outside the while
loop, usedev_err()to share what the failure was.Quoted 26 lines
sound/soc/codecs/max98373.c +4
-3+ } +} +static int max98373_probe (struct snd_soc_component *component) {struct max98373_priv *max98373 =snd_soc_component_get_drvdata (component);/* Software Reset */ -regmap_write (max98373->regmap, -MAX98373_R2000_SW_RESET ,MAX98373_SOFT_RESET ); -usleep_range (10000 ,11000 ); +max98373_reset (max98373, component->dev);/* IV default slot configuration */ regmap_write(max98373->regmap, @@ -818,9 +849,7 @@ staticint max98373_resume(struct device *dev) { struct max98373_priv *max98373 = dev_get_drvdata(dev);sound/soc/codecs/max98373.c +1
-4-regmap_write (max98373->regmap, -MAX98373_R2000_SW_RESET ,MAX98373_SOFT_RESET ); -usleep_range (10000 ,11000 ); +max98373_reset (max98373, dev);regcache_cache_only (max98373->regmap, false);regcache_sync (max98373->regmap);return 0 ; --Quoted 2 lines
2.7.4
cheers,
grant
Grant,
Thanks for your feedback. Please find my answers inline.
Quoted 32 lines
-----Original Message-----
From: Grant Grundler <[email protected]>
Sent: Monday, November 26, 2018 6:25 PM
To: Ryan Lee <[email protected]>
Cc: Liam Girdwood <[email protected]>; [email protected]; [email protected]; [email protected]; Grant Grundler <[email protected]>; Kuninori Morimoto <[email protected]>; Benson Leung <[email protected]>; [email protected]; LKML <linux- [email protected]>
Subject: Re: [PATCH] ASoC: max98373: Addedmax98373_resetfor stable amp resetEXTERNAL EMAIL
Hi Ryan!
Just some questions inline - in general I like the reset function.
Quoted 5 lines · Ryan Lee
Signed-off-by Ryan Lee <[email protected]>---
Changes : Createdmax98373_resetfunction to minimize code duplication.
Changedregmap_writetoregmap_update_bits. Other bits except LSBneed to be masked.
Quoted 1 line
Added reset verification step to make sure software reset is
completed well. Software reset is done in 10ms in normal case.
Quoted 1 line
Revision ID is available when the amp is in the idle state which means
Quoted 8 lines
software reset is completed.
Quoted 1 line
Software reset will be performed maximum 3 times to avoid amp reset
failure. Generally it is done in the first trial.
Quoted 1 line
sleep time after software reset is increased + 30ms for every retrial.
Maximum possible msleep time is 100 ms (initial 10 ms + 30 ms * 3 times).
Why is the sleep time increased after each SW reset?
What is the failure case that you've seen which would benefit from this?
Generally 10ms is enough time for amp software reset but I wanted to add more guard time for the retrial because it is already failed once. I have not seen a failure issue with 10ms delay on my test setup but I wanted to make it more conservative.
Let me remove this.
Quoted 35 lines
sound/soc/codecs/max98373.c static struct snd_soc_dai_driver max98373_dai[] =
Quoted 11 lines
sound/soc/codecs/max98373.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-)sound/soc/codecs/max98373.c +0
-0@@ -724,14 +724,45 @@ static struct snd_soc_dai_driver max98373_dai[] ={
Quoted 23 lines
sound/soc/codecs/max98373.c +20
-0} }; +static void max98373_reset (struct max98373_priv *max98373,struct +device *dev) { +int ret, reg, count, delay; + + count =0 ; +while (true) { +/* Software Reset */ + ret =regmap_update_bits (max98373->regmap, +MAX98373_R2000_SW_RESET , +MAX98373_SOFT_RESET , +MAX98373_SOFT_RESET ); +if (ret) + dev_err(dev, "Reset command failed. + (ret:%d)\n", ret); + + delay = 10000 + (count * 30000); + usleep_range(delay, delay + 1000); + +/* Software Reset Verification */ + ret = regmap_read(max98373->regmap,
Quoted 8 lines
sound/soc/codecs/max98373.c static struct snd_soc_dai_driver max98373_dai[] = { · line 749
Quoted 4 lines
sound/soc/codecs/max98373.c +4
-0+ MAX98373_R21FF_REV_ID, ®); +if (!ret) { +dev_info (dev,"Reset completed (retry:%d)\n" , count); +break ;Instead of break, can the code return here?
"break" implies something else will happen after the while loop exits
- there isn't.
Okay. I will fix it. Thanks for the comment.
Quoted 11 lines
sound/soc/codecs/max98373.c static struct snd_soc_dai_driver max98373_dai[] = { · line 756
Quoted 8 lines
sound/soc/codecs/max98373.c +7
-0+ } + +if (++count >3 ) { +dev_err (dev,"Reset failed. (ret:%d)\n" , ret); +break ; + } +usleep_range (10000 ,11000 );Why is there a second delay after reading
MAX98373_R21FF_REV_ID? Is this really necessary?
It is not very necessary. I just wanted to make it more conservative because this delay is applied only when reset is failed.
Quoted 4 lines
If the second
usleep_range()isn't needed, it would be better/clearer
to make code loop on "while (count < 4)". And then outside the while
loop, usedev_err()to share what the failure was.
OK. Let me fix it.
Quoted 32 lines
Quoted 27 lines
sound/soc/codecs/max98373.c +4
-3+ } +} +static int max98373_probe (struct snd_soc_component *component) {struct max98373_priv *max98373 =snd_soc_component_get_drvdata (component);/* Software Reset */ -regmap_write (max98373->regmap, -MAX98373_R2000_SW_RESET ,MAX98373_SOFT_RESET ); -usleep_range (10000 ,11000 ); +max98373_reset (max98373, component->dev);/* IV default slot configuration */ regmap_write(max98373->regmap, @@ -818,9 +849,7 @@ static intmax98373_resume(struct device *dev) { struct max98373_priv *max98373 = dev_get_drvdata(dev);sound/soc/codecs/max98373.c +1
-4-regmap_write (max98373->regmap, -MAX98373_R2000_SW_RESET ,MAX98373_SOFT_RESET ); -usleep_range (10000 ,11000 ); +max98373_reset (max98373, dev);regcache_cache_only (max98373->regmap, false);regcache_sync (max98373->regmap);return 0 ; --Quoted 2 lines
2.7.4
cheers,
grant
Mark Brown
maintainerQuoted 2 lines · Ryan Lee
Signed-off-by Ryan Lee <[email protected]>---
This really needs a changelog to explain what is going on here, and we need some more documentation in the code. It is *extremely* unusual to have to poll for reset like this, and if the failure mode is I/O errors that's going to be pretty painful.
Quoted 13 lines
-----Original Message-----
From: Mark Brown <[email protected]>
Sent: Tuesday, November 27, 2018 3:51 AM
To: Ryan Lee <[email protected]>
Cc: Liam Girdwood <[email protected]>; Jaroslav Kysela <[email protected]>; Takashi Iwai <[email protected]>; Grant Grundler <[email protected]>; Kuninori Morimoto <[email protected]>; Benson Leung <[email protected]>; [email protected]; linux- [email protected]
Subject: Re: [PATCH] ASoC: max98373: Addedmax98373_resetfor stable amp reset
Quoted 8 lines
Quoted 2 lines · Ryan Lee
Signed-off-by Ryan Lee <[email protected]>---
This really needs a changelog to explain what is going on here, and we need some more documentation in the code. It is *extremely* unusual to have to poll for reset like this, and if the failure mode is I/O errors that's going to be pretty painful.
OK. I agree that this is very unusual. I wanted to make this code change very conservative and this caused unusual overhead. Let me fix this.