[PATCH 1/3] ASoC:codec:max98373: Changed amp shutdown register as volatile

2021-03-24 Thread Ryan Lee
0x20FF(amp global enable) register was defined as non-volatile,
but it is not. Overheating, overcurrent can cause amp shutdown
in hardware.
'regmap_write' compare register readback value before writing
to avoid same value writing. 'regmap_read' just read cache
not actual hardware value for the non-volatile register.
When amp is internally shutdown by some reason, next 'AMP ON'
command can be ignored because regmap think amp is already ON.

Signed-off-by: Ryan Lee 
---
 sound/soc/codecs/max98373-i2c.c | 1 +
 sound/soc/codecs/max98373-sdw.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/sound/soc/codecs/max98373-i2c.c b/sound/soc/codecs/max98373-i2c.c
index 85f6865019d4..ddb6436835d7 100644
--- a/sound/soc/codecs/max98373-i2c.c
+++ b/sound/soc/codecs/max98373-i2c.c
@@ -446,6 +446,7 @@ static bool max98373_volatile_reg(struct device *dev, 
unsigned int reg)
case MAX98373_R2054_MEAS_ADC_PVDD_CH_READBACK:
case MAX98373_R2055_MEAS_ADC_THERM_CH_READBACK:
case MAX98373_R20B6_BDE_CUR_STATE_READBACK:
+   case MAX98373_R20FF_GLOBAL_SHDN:
case MAX98373_R21FF_REV_ID:
return true;
default:
diff --git a/sound/soc/codecs/max98373-sdw.c b/sound/soc/codecs/max98373-sdw.c
index d8c47667a9ea..f3a12205cd48 100644
--- a/sound/soc/codecs/max98373-sdw.c
+++ b/sound/soc/codecs/max98373-sdw.c
@@ -220,6 +220,7 @@ static bool max98373_volatile_reg(struct device *dev, 
unsigned int reg)
case MAX98373_R2054_MEAS_ADC_PVDD_CH_READBACK:
case MAX98373_R2055_MEAS_ADC_THERM_CH_READBACK:
case MAX98373_R20B6_BDE_CUR_STATE_READBACK:
+   case MAX98373_R20FF_GLOBAL_SHDN:
case MAX98373_R21FF_REV_ID:
/* SoundWire Control Port Registers */
case MAX98373_R0040_SCP_INIT_STAT_1 ... MAX98373_R0070_SCP_FRAME_CTLR:
-- 
2.17.1



[PATCH 3/3] ASoC:codec:max98373: Added controls for autorestart config

2021-03-24 Thread Ryan Lee
3 new controls are added.
"OVC Autorestart Switch" : controls whether or not the speaker amplifier
automatically re-enables after an overcurrent fault condition.
"THERM Autorestart Switch" : controls whether or not the device
automatically resumes playback when the die temperature recovers from
thermal shutdown.
"CMON Autorestart Switch" : controls whether or not the device
automatically resumes playback when the clock returns after stopping.

Above Auto Restart functions are enabled by default.

Signed-off-by: Ryan Lee 
---
 sound/soc/codecs/max98373.c | 14 ++
 sound/soc/codecs/max98373.h |  3 +++
 2 files changed, 17 insertions(+)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 1346a98ce8a1..e14fe98349a5 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -204,6 +204,15 @@ SOC_SINGLE("Ramp Up Switch", MAX98373_R203F_AMP_DSP_CFG,
MAX98373_AMP_DSP_CFG_RMP_UP_SHIFT, 1, 0),
 SOC_SINGLE("Ramp Down Switch", MAX98373_R203F_AMP_DSP_CFG,
MAX98373_AMP_DSP_CFG_RMP_DN_SHIFT, 1, 0),
+/* Speaker Amplifier Overcurrent Automatic Restart Enable */
+SOC_SINGLE("OVC Autorestart Switch", MAX98373_R20FE_DEVICE_AUTO_RESTART_CFG,
+   MAX98373_OVC_AUTORESTART_SHIFT, 1, 0),
+/* Thermal Shutdown Automatic Restart Enable */
+SOC_SINGLE("THERM Autorestart Switch", MAX98373_R20FE_DEVICE_AUTO_RESTART_CFG,
+   MAX98373_THERM_AUTORESTART_SHIFT, 1, 0),
+/* Clock Monitor Automatic Restart Enable */
+SOC_SINGLE("CMON Autorestart Switch", MAX98373_R20FE_DEVICE_AUTO_RESTART_CFG,
+   MAX98373_CMON_AUTORESTART_SHIFT, 1, 0),
 SOC_SINGLE("CLK Monitor Switch", MAX98373_R20FE_DEVICE_AUTO_RESTART_CFG,
MAX98373_CLOCK_MON_SHIFT, 1, 0),
 SOC_SINGLE("Dither Switch", MAX98373_R203F_AMP_DSP_CFG,
@@ -392,6 +401,11 @@ static int max98373_probe(struct snd_soc_component 
*component)
MAX98373_R2021_PCM_TX_HIZ_EN_2,
1 << (max98373->i_slot - 8), 0);
 
+   /* enable auto restart function by default */
+   regmap_write(max98373->regmap,
+   MAX98373_R20FE_DEVICE_AUTO_RESTART_CFG,
+   0xF);
+
/* speaker feedback slot configuration */
regmap_write(max98373->regmap,
MAX98373_R2023_PCM_TX_SRC_2,
diff --git a/sound/soc/codecs/max98373.h b/sound/soc/codecs/max98373.h
index 71f5a5228f34..73a2cf69d84a 100644
--- a/sound/soc/codecs/max98373.h
+++ b/sound/soc/codecs/max98373.h
@@ -195,6 +195,9 @@
 #define MAX98373_LIMITER_EN_SHIFT (0)
 
 /* MAX98373_R20FE_DEVICE_AUTO_RESTART_CFG */
+#define MAX98373_OVC_AUTORESTART_SHIFT (3)
+#define MAX98373_THERM_AUTORESTART_SHIFT (2)
+#define MAX98373_CMON_AUTORESTART_SHIFT (1)
 #define MAX98373_CLOCK_MON_SHIFT (0)
 
 /* MAX98373_R20FF_GLOBAL_SHDN */
-- 
2.17.1



[PATCH 2/3] ASoC:codec:max98373: Added 30ms turn on/off time delay

2021-03-24 Thread Ryan Lee
Amp requires 10 ~ 30ms for the power ON and OFF.
Added 30ms delay for stability.

Signed-off-by: Ryan Lee 
---
 sound/soc/codecs/max98373.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 746c829312b8..1346a98ce8a1 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -28,11 +28,13 @@ static int max98373_dac_event(struct snd_soc_dapm_widget *w,
regmap_update_bits(max98373->regmap,
MAX98373_R20FF_GLOBAL_SHDN,
MAX98373_GLOBAL_EN_MASK, 1);
+   usleep_range(3, 31000);
break;
case SND_SOC_DAPM_POST_PMD:
regmap_update_bits(max98373->regmap,
MAX98373_R20FF_GLOBAL_SHDN,
MAX98373_GLOBAL_EN_MASK, 0);
+   usleep_range(3, 31000);
max98373->tdm_mode = false;
break;
default:
-- 
2.17.1



[V3] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-29 Thread Ryan Lee
This patch added max98373_reset function to avoid amp software reset failure 
and code duplication.
Reset verification step has been added for stable amp reset and it repeats 
verification maximum 3 times when it is failed.
Chip revision ID is available when the amp is in the idle state which means 
software reset is completed well.
Additional 10ms delay was added for every retrial and maximum 30ms delay can be 
applied.

Signed-off-by: Ryan Lee 
---

Changes since v2:
- Added commit message.
Changes since v1:
- Removed unusual repeat for amp software reset and verification.
- Amp software reset will be performed once and it repeats verification maximum 
3 times if it is failed.
- Wait 10ms before every verification trial. Maximum 30ms delay will be applied 
to wait AMP idle state.
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 | 35 +--
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index a09d013..9c8616a 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -724,14 +724,39 @@ static struct snd_soc_dai_driver max98373_dai[] = {
}
 };
 
+static void max98373_reset(struct max98373_priv *max98373, struct device *dev)
+{
+   int ret, reg, count;
+
+   /* 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);
+
+   count = 0;
+   while (count < 3) {
+   usleep_range(1, 11000);
+   /* Software Reset Verification */
+   ret = regmap_read(max98373->regmap,
+   MAX98373_R21FF_REV_ID, );
+   if (!ret) {
+   dev_info(dev, "Reset completed (retry:%d)\n", count);
+   return;
+   }
+   count++;
+   }
+   dev_err(dev, "Reset failed. (ret:%d)\n", ret);
+}
+
 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(1, 11000);
+   max98373_reset(max98373, component->dev);
 
/* IV default slot configuration */
regmap_write(max98373->regmap,
@@ -818,9 +843,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(1, 11000);
+   max98373_reset(max98373, dev);
regcache_cache_only(max98373->regmap, false);
regcache_sync(max98373->regmap);
return 0;
-- 
2.7.4



[V3] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-29 Thread Ryan Lee
This patch added max98373_reset function to avoid amp software reset failure 
and code duplication.
Reset verification step has been added for stable amp reset and it repeats 
verification maximum 3 times when it is failed.
Chip revision ID is available when the amp is in the idle state which means 
software reset is completed well.
Additional 10ms delay was added for every retrial and maximum 30ms delay can be 
applied.

Signed-off-by: Ryan Lee 
---

Changes since v2:
- Added commit message.
Changes since v1:
- Removed unusual repeat for amp software reset and verification.
- Amp software reset will be performed once and it repeats verification maximum 
3 times if it is failed.
- Wait 10ms before every verification trial. Maximum 30ms delay will be applied 
to wait AMP idle state.
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 | 35 +--
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index a09d013..9c8616a 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -724,14 +724,39 @@ static struct snd_soc_dai_driver max98373_dai[] = {
}
 };
 
+static void max98373_reset(struct max98373_priv *max98373, struct device *dev)
+{
+   int ret, reg, count;
+
+   /* 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);
+
+   count = 0;
+   while (count < 3) {
+   usleep_range(1, 11000);
+   /* Software Reset Verification */
+   ret = regmap_read(max98373->regmap,
+   MAX98373_R21FF_REV_ID, );
+   if (!ret) {
+   dev_info(dev, "Reset completed (retry:%d)\n", count);
+   return;
+   }
+   count++;
+   }
+   dev_err(dev, "Reset failed. (ret:%d)\n", ret);
+}
+
 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(1, 11000);
+   max98373_reset(max98373, component->dev);
 
/* IV default slot configuration */
regmap_write(max98373->regmap,
@@ -818,9 +843,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(1, 11000);
+   max98373_reset(max98373, dev);
regcache_cache_only(max98373->regmap, false);
regcache_sync(max98373->regmap);
return 0;
-- 
2.7.4



RE: [PATCH V2] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-29 Thread Ryan Lee
>-Original Message-
>From: Mark Brown 
>Sent: Thursday, November 29, 2018 3:26 AM
>To: Grant Grundler 
>Cc: Ryan Lee ; Liam Girdwood
>; pe...@perex.cz; ti...@suse.com; Kuninori
>Morimoto ; Benson Leung
>; alsa-de...@alsa-project.org; LKML ker...@vger.kernel.org>; ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH V2] ASoC: max98373: Added max98373_reset for stable
>amp reset
>
>On Wed, Nov 28, 2018 at 05:55:48PM -0800, Grant Grundler wrote:
>> On Wed, Nov 28, 2018 at 9:07 AM Ryan Lee
> wrote:
>
>> > >Not seeing a changelog here like I asked for :(
>
>> > Actually I added changelog as below. Do you mean this is not sufficient?
>
>> The text is probably sufficient but not in a format that Mark can
>> directly apply.
>> Please take a quick look at Documentation/process/submitting-patches.rst.
>
>> Mark wants the "commit message" to be before the '---' line. So move
>> the "Changes:" text up to become the commit message and drop the
>> "Changes" line. That should explain why this commit is needed and
>> include the S-o-B line.
>
>Right.  If you compare what's in git and what you're sending with other
>commits and mails and make sure everything looks similar you're probably on
>the right track.
I'm sorry for the mistake. Let me fix it.


RE: [PATCH V2] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-29 Thread Ryan Lee
>-Original Message-
>From: Mark Brown 
>Sent: Thursday, November 29, 2018 3:26 AM
>To: Grant Grundler 
>Cc: Ryan Lee ; Liam Girdwood
>; pe...@perex.cz; ti...@suse.com; Kuninori
>Morimoto ; Benson Leung
>; alsa-de...@alsa-project.org; LKML ker...@vger.kernel.org>; ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH V2] ASoC: max98373: Added max98373_reset for stable
>amp reset
>
>On Wed, Nov 28, 2018 at 05:55:48PM -0800, Grant Grundler wrote:
>> On Wed, Nov 28, 2018 at 9:07 AM Ryan Lee
> wrote:
>
>> > >Not seeing a changelog here like I asked for :(
>
>> > Actually I added changelog as below. Do you mean this is not sufficient?
>
>> The text is probably sufficient but not in a format that Mark can
>> directly apply.
>> Please take a quick look at Documentation/process/submitting-patches.rst.
>
>> Mark wants the "commit message" to be before the '---' line. So move
>> the "Changes:" text up to become the commit message and drop the
>> "Changes" line. That should explain why this commit is needed and
>> include the S-o-B line.
>
>Right.  If you compare what's in git and what you're sending with other
>commits and mails and make sure everything looks similar you're probably on
>the right track.
I'm sorry for the mistake. Let me fix it.


RE: [PATCH V2] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-29 Thread Ryan Lee
>-Original Message-
>From: Grant Grundler 
>Sent: Wednesday, November 28, 2018 5:56 PM
>To: Ryan Lee 
>Cc: broo...@kernel.org; Liam Girdwood ;
>pe...@perex.cz; ti...@suse.com; Grant Grundler
>; Kuninori Morimoto
>; Benson Leung
>; alsa-de...@alsa-project.org; LKML ker...@vger.kernel.org>; ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH V2] ASoC: max98373: Added max98373_reset for stable
>amp reset
>
>EXTERNAL EMAIL
>
>
>
>On Wed, Nov 28, 2018 at 9:07 AM Ryan Lee
> wrote:
>>
>> >-Original Message-
>> >From: Mark Brown 
>> >Sent: Wednesday, November 28, 2018 1:50 AM
>> >To: Ryan Lee 
>> >Cc: Liam Girdwood ; Jaroslav Kysela
>> >; Takashi Iwai ; Grant Grundler
>> >; Kuninori Morimoto
>> >; Benson Leung
>> >; alsa-de...@alsa-project.org; linux-
>> >ker...@vger.kernel.org; ryan.lee.ma...@gmail.com
>> >Subject: Re: [PATCH V2] ASoC: max98373: Added max98373_reset for
>> >stable amp reset
>> >
>> >On Wed, Nov 28, 2018 at 03:20:16AM +, Ryan Lee wrote:
>> >> Signed-off-by: Ryan Lee 
>> >> ---
>> >
>> >Not seeing a changelog here like I asked for :(
>>
>> Actually I added changelog as below. Do you mean this is not sufficient?
>
>The text is probably sufficient but not in a format that Mark can directly 
>apply.
>Please take a quick look at Documentation/process/submitting-patches.rst.
>
>Mark wants the "commit message" to be before the '---' line. So move the
>"Changes:" text up to become the commit message and drop the "Changes"
>line. That should explain why this commit is needed and include the S-o-B line.
Thanks for your help. I will fix it.
>
>cheers,
>grant
>
>>
>> Changes since v1 : Removed unusual repeat for amp software reset and
>verification.
>>Amp software reset will be performed once and it repeats
>verification maximum 3 times if it is failed.
>>Wait 10ms before every verification trial. Maximum 30ms 
>> delay will
>be applied to wait AMP idle state.
>>
>> >
>> >> 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).
>> >
>> >This looks like it's supposed to be a changelog but it isn't one?


RE: [PATCH V2] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-29 Thread Ryan Lee
>-Original Message-
>From: Grant Grundler 
>Sent: Wednesday, November 28, 2018 5:56 PM
>To: Ryan Lee 
>Cc: broo...@kernel.org; Liam Girdwood ;
>pe...@perex.cz; ti...@suse.com; Grant Grundler
>; Kuninori Morimoto
>; Benson Leung
>; alsa-de...@alsa-project.org; LKML ker...@vger.kernel.org>; ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH V2] ASoC: max98373: Added max98373_reset for stable
>amp reset
>
>EXTERNAL EMAIL
>
>
>
>On Wed, Nov 28, 2018 at 9:07 AM Ryan Lee
> wrote:
>>
>> >-Original Message-
>> >From: Mark Brown 
>> >Sent: Wednesday, November 28, 2018 1:50 AM
>> >To: Ryan Lee 
>> >Cc: Liam Girdwood ; Jaroslav Kysela
>> >; Takashi Iwai ; Grant Grundler
>> >; Kuninori Morimoto
>> >; Benson Leung
>> >; alsa-de...@alsa-project.org; linux-
>> >ker...@vger.kernel.org; ryan.lee.ma...@gmail.com
>> >Subject: Re: [PATCH V2] ASoC: max98373: Added max98373_reset for
>> >stable amp reset
>> >
>> >On Wed, Nov 28, 2018 at 03:20:16AM +, Ryan Lee wrote:
>> >> Signed-off-by: Ryan Lee 
>> >> ---
>> >
>> >Not seeing a changelog here like I asked for :(
>>
>> Actually I added changelog as below. Do you mean this is not sufficient?
>
>The text is probably sufficient but not in a format that Mark can directly 
>apply.
>Please take a quick look at Documentation/process/submitting-patches.rst.
>
>Mark wants the "commit message" to be before the '---' line. So move the
>"Changes:" text up to become the commit message and drop the "Changes"
>line. That should explain why this commit is needed and include the S-o-B line.
Thanks for your help. I will fix it.
>
>cheers,
>grant
>
>>
>> Changes since v1 : Removed unusual repeat for amp software reset and
>verification.
>>Amp software reset will be performed once and it repeats
>verification maximum 3 times if it is failed.
>>Wait 10ms before every verification trial. Maximum 30ms 
>> delay will
>be applied to wait AMP idle state.
>>
>> >
>> >> 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).
>> >
>> >This looks like it's supposed to be a changelog but it isn't one?


RE: [PATCH V2] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-28 Thread Ryan Lee
>-Original Message-
>From: Mark Brown 
>Sent: Wednesday, November 28, 2018 1:50 AM
>To: Ryan Lee 
>Cc: Liam Girdwood ; Jaroslav Kysela
>; Takashi Iwai ; Grant Grundler
>; Kuninori Morimoto
>; Benson Leung
>; alsa-de...@alsa-project.org; linux-
>ker...@vger.kernel.org; ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH V2] ASoC: max98373: Added max98373_reset for stable
>amp reset
>
>On Wed, Nov 28, 2018 at 03:20:16AM +0000, Ryan Lee wrote:
>> Signed-off-by: Ryan Lee 
>> ---
>
>Not seeing a changelog here like I asked for :(

Actually I added changelog as below. Do you mean this is not sufficient?

Changes since v1 : Removed unusual repeat for amp software reset and 
verification.
   Amp software reset will be performed once and it repeats 
verification maximum 3 times if it is failed.
   Wait 10ms before every verification trial. Maximum 30ms 
delay will be applied to wait AMP idle state.

>
>> 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).
>
>This looks like it's supposed to be a changelog but it isn't one?


RE: [PATCH V2] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-28 Thread Ryan Lee
>-Original Message-
>From: Mark Brown 
>Sent: Wednesday, November 28, 2018 1:50 AM
>To: Ryan Lee 
>Cc: Liam Girdwood ; Jaroslav Kysela
>; Takashi Iwai ; Grant Grundler
>; Kuninori Morimoto
>; Benson Leung
>; alsa-de...@alsa-project.org; linux-
>ker...@vger.kernel.org; ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH V2] ASoC: max98373: Added max98373_reset for stable
>amp reset
>
>On Wed, Nov 28, 2018 at 03:20:16AM +0000, Ryan Lee wrote:
>> Signed-off-by: Ryan Lee 
>> ---
>
>Not seeing a changelog here like I asked for :(

Actually I added changelog as below. Do you mean this is not sufficient?

Changes since v1 : Removed unusual repeat for amp software reset and 
verification.
   Amp software reset will be performed once and it repeats 
verification maximum 3 times if it is failed.
   Wait 10ms before every verification trial. Maximum 30ms 
delay will be applied to wait AMP idle state.

>
>> 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).
>
>This looks like it's supposed to be a changelog but it isn't one?


[PATCH V2] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-27 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changes since v1 : Removed unusual repeat for amp software reset and 
verification.
   Amp software reset will be performed once and it repeats 
verification maximum 3 times if it is failed.
   Wait 10ms before every verification trial. Maximum 30ms 
delay will be applied to wait AMP idle state.

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 | 35 +--
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index a09d013..9c8616a 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -724,14 +724,39 @@ static struct snd_soc_dai_driver max98373_dai[] = {
}
 };
 
+static void max98373_reset(struct max98373_priv *max98373, struct device *dev)
+{
+   int ret, reg, count;
+
+   /* 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);
+
+   count = 0;
+   while (count < 3) {
+   usleep_range(1, 11000);
+   /* Software Reset Verification */
+   ret = regmap_read(max98373->regmap,
+   MAX98373_R21FF_REV_ID, );
+   if (!ret) {
+   dev_info(dev, "Reset completed (retry:%d)\n", count);
+   return;
+   }
+   count++;
+   }
+   dev_err(dev, "Reset failed. (ret:%d)\n", ret);
+}
+
 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(1, 11000);
+   max98373_reset(max98373, component->dev);
 
/* IV default slot configuration */
regmap_write(max98373->regmap,
@@ -818,9 +843,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(1, 11000);
+   max98373_reset(max98373, dev);
regcache_cache_only(max98373->regmap, false);
regcache_sync(max98373->regmap);
return 0;
-- 
2.7.4



[PATCH V2] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-27 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changes since v1 : Removed unusual repeat for amp software reset and 
verification.
   Amp software reset will be performed once and it repeats 
verification maximum 3 times if it is failed.
   Wait 10ms before every verification trial. Maximum 30ms 
delay will be applied to wait AMP idle state.

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 | 35 +--
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index a09d013..9c8616a 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -724,14 +724,39 @@ static struct snd_soc_dai_driver max98373_dai[] = {
}
 };
 
+static void max98373_reset(struct max98373_priv *max98373, struct device *dev)
+{
+   int ret, reg, count;
+
+   /* 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);
+
+   count = 0;
+   while (count < 3) {
+   usleep_range(1, 11000);
+   /* Software Reset Verification */
+   ret = regmap_read(max98373->regmap,
+   MAX98373_R21FF_REV_ID, );
+   if (!ret) {
+   dev_info(dev, "Reset completed (retry:%d)\n", count);
+   return;
+   }
+   count++;
+   }
+   dev_err(dev, "Reset failed. (ret:%d)\n", ret);
+}
+
 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(1, 11000);
+   max98373_reset(max98373, component->dev);
 
/* IV default slot configuration */
regmap_write(max98373->regmap,
@@ -818,9 +843,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(1, 11000);
+   max98373_reset(max98373, dev);
regcache_cache_only(max98373->regmap, false);
regcache_sync(max98373->regmap);
return 0;
-- 
2.7.4



RE: [PATCH] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-27 Thread Ryan Lee
>-Original Message-
>From: Mark Brown 
>Sent: Tuesday, November 27, 2018 3:51 AM
>To: Ryan Lee 
>Cc: Liam Girdwood ; Jaroslav Kysela
>; Takashi Iwai ; Grant Grundler
>; Kuninori Morimoto
>; Benson Leung
>; alsa-de...@alsa-project.org; linux-
>ker...@vger.kernel.org
>Subject: Re: [PATCH] ASoC: max98373: Added max98373_reset for stable amp
>reset
>
>On Mon, Nov 26, 2018 at 06:46:05PM +0000, Ryan Lee wrote:
>> Signed-off-by: Ryan Lee 
>> ---
>
>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.


RE: [PATCH] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-27 Thread Ryan Lee
>-Original Message-
>From: Mark Brown 
>Sent: Tuesday, November 27, 2018 3:51 AM
>To: Ryan Lee 
>Cc: Liam Girdwood ; Jaroslav Kysela
>; Takashi Iwai ; Grant Grundler
>; Kuninori Morimoto
>; Benson Leung
>; alsa-de...@alsa-project.org; linux-
>ker...@vger.kernel.org
>Subject: Re: [PATCH] ASoC: max98373: Added max98373_reset for stable amp
>reset
>
>On Mon, Nov 26, 2018 at 06:46:05PM +0000, Ryan Lee wrote:
>> Signed-off-by: Ryan Lee 
>> ---
>
>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.


RE: [PATCH] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-27 Thread Ryan Lee
Grant,
Thanks for your feedback. Please find my answers inline.
>-Original Message-
>From: Grant Grundler 
>Sent: Monday, November 26, 2018 6:25 PM
>To: Ryan Lee 
>Cc: Liam Girdwood ; broo...@kernel.org;
>pe...@perex.cz; ti...@suse.com; Grant Grundler
>; Kuninori Morimoto
>; Benson Leung
>; alsa-de...@alsa-project.org; LKML ker...@vger.kernel.org>
>Subject: Re: [PATCH] ASoC: max98373: Added max98373_reset for stable amp
>reset
>
>EXTERNAL EMAIL
>
>
>
>Hi Ryan!
>
>Just some questions inline - in general I like the reset function.
>
>On Mon, Nov 26, 2018 at 10:46 AM Ryan Lee
> wrote:
>>
>> Signed-off-by: Ryan Lee 
>> ---
>>  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).
>
>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.

>
>>
>>  sound/soc/codecs/max98373.c | 41
>> +++--
>>  1 file changed, 35 insertions(+), 6 deletions(-)
>>
>> diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
>> index a09d013..55af7f02 100644
>> --- a/sound/soc/codecs/max98373.c
>> +++ b/sound/soc/codecs/max98373.c
>> @@ -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 = 1 + (count * 3);
>> +   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.
Okay. I will fix it. Thanks for the comment.

>
>> +   }
>> +
>> +   if (++count > 3){
>> +   dev_err(dev, "Reset failed. (ret:%d)\n", ret);
>> +   break;
>> +   }
>> +   usleep_range(1, 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.

>
>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.
OK. Let me fix it.

>
>> +   }
>> +}
>> +
>>  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(1000

RE: [PATCH] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-27 Thread Ryan Lee
Grant,
Thanks for your feedback. Please find my answers inline.
>-Original Message-
>From: Grant Grundler 
>Sent: Monday, November 26, 2018 6:25 PM
>To: Ryan Lee 
>Cc: Liam Girdwood ; broo...@kernel.org;
>pe...@perex.cz; ti...@suse.com; Grant Grundler
>; Kuninori Morimoto
>; Benson Leung
>; alsa-de...@alsa-project.org; LKML ker...@vger.kernel.org>
>Subject: Re: [PATCH] ASoC: max98373: Added max98373_reset for stable amp
>reset
>
>EXTERNAL EMAIL
>
>
>
>Hi Ryan!
>
>Just some questions inline - in general I like the reset function.
>
>On Mon, Nov 26, 2018 at 10:46 AM Ryan Lee
> wrote:
>>
>> Signed-off-by: Ryan Lee 
>> ---
>>  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).
>
>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.

>
>>
>>  sound/soc/codecs/max98373.c | 41
>> +++--
>>  1 file changed, 35 insertions(+), 6 deletions(-)
>>
>> diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
>> index a09d013..55af7f02 100644
>> --- a/sound/soc/codecs/max98373.c
>> +++ b/sound/soc/codecs/max98373.c
>> @@ -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 = 1 + (count * 3);
>> +   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.
Okay. I will fix it. Thanks for the comment.

>
>> +   }
>> +
>> +   if (++count > 3){
>> +   dev_err(dev, "Reset failed. (ret:%d)\n", ret);
>> +   break;
>> +   }
>> +   usleep_range(1, 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.

>
>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.
OK. Let me fix it.

>
>> +   }
>> +}
>> +
>>  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(1000

RE: [PATCH] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-27 Thread Ryan Lee
>-Original Message-
>From: Grant Grundler 
>Sent: Monday, November 26, 2018 6:28 PM
>To: Grant Grundler 
>Cc: Ryan Lee ; Liam Girdwood
>; broo...@kernel.org; pe...@perex.cz;
>ti...@suse.com; Kuninori Morimoto ;
>Benson Leung ; alsa-de...@alsa-project.org; LKML
>
>Subject: Re: [PATCH] ASoC: max98373: Added max98373_reset for stable amp
>reset
>
>EXTERNAL EMAIL
>
>
>
>I just realized I had one more question...
>
>On Mon, Nov 26, 2018 at 6:24 PM Grant Grundler 
>wrote:
>>
>> Hi Ryan!
>>
>> Just some questions inline - in general I like the reset function.
>>
>> On Mon, Nov 26, 2018 at 10:46 AM Ryan Lee
> wrote:
>> >
>> > Signed-off-by: Ryan Lee 
>> > ---
>> >  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.
>
>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.

>
>cheers,
>grant
>
>> >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?
>>
>> >
>> >  sound/soc/codecs/max98373.c | 41
>> > +++--
>> >  1 file changed, 35 insertions(+), 6 deletions(-)
>> >
>> > diff --git a/sound/soc/codecs/max98373.c
>> > b/sound/soc/codecs/max98373.c index a09d013..55af7f02 100644
>> > --- a/sound/soc/codecs/max98373.c
>> > +++ b/sound/soc/codecs/max98373.c
>> > @@ -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 = 1 + (count * 3);
>> > +   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.
>>
>> > +   }
>> > +
>> > +   if (++count > 3){
>> > +   dev_err(dev, "Reset failed. (ret:%d)\n", ret);
>> > +   break;
>> > +   }
>> > +   usleep_range(1, 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.
>>
>> > +   }
>> > +}
>> > +
>> >  static int max98373_probe(struct snd_soc_component *component)  {
>> &

RE: [PATCH] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-27 Thread Ryan Lee
>-Original Message-
>From: Grant Grundler 
>Sent: Monday, November 26, 2018 6:28 PM
>To: Grant Grundler 
>Cc: Ryan Lee ; Liam Girdwood
>; broo...@kernel.org; pe...@perex.cz;
>ti...@suse.com; Kuninori Morimoto ;
>Benson Leung ; alsa-de...@alsa-project.org; LKML
>
>Subject: Re: [PATCH] ASoC: max98373: Added max98373_reset for stable amp
>reset
>
>EXTERNAL EMAIL
>
>
>
>I just realized I had one more question...
>
>On Mon, Nov 26, 2018 at 6:24 PM Grant Grundler 
>wrote:
>>
>> Hi Ryan!
>>
>> Just some questions inline - in general I like the reset function.
>>
>> On Mon, Nov 26, 2018 at 10:46 AM Ryan Lee
> wrote:
>> >
>> > Signed-off-by: Ryan Lee 
>> > ---
>> >  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.
>
>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.

>
>cheers,
>grant
>
>> >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?
>>
>> >
>> >  sound/soc/codecs/max98373.c | 41
>> > +++--
>> >  1 file changed, 35 insertions(+), 6 deletions(-)
>> >
>> > diff --git a/sound/soc/codecs/max98373.c
>> > b/sound/soc/codecs/max98373.c index a09d013..55af7f02 100644
>> > --- a/sound/soc/codecs/max98373.c
>> > +++ b/sound/soc/codecs/max98373.c
>> > @@ -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 = 1 + (count * 3);
>> > +   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.
>>
>> > +   }
>> > +
>> > +   if (++count > 3){
>> > +   dev_err(dev, "Reset failed. (ret:%d)\n", ret);
>> > +   break;
>> > +   }
>> > +   usleep_range(1, 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.
>>
>> > +   }
>> > +}
>> > +
>> >  static int max98373_probe(struct snd_soc_component *component)  {
>> &

[PATCH] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-26 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 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(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index a09d013..55af7f02 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -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 = 1 + (count * 3);
+   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(1, 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(1, 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(1, 11000);
+   max98373_reset(max98373, dev);
regcache_cache_only(max98373->regmap, false);
regcache_sync(max98373->regmap);
return 0;
-- 
2.7.4



[PATCH] ASoC: max98373: Added max98373_reset for stable amp reset

2018-11-26 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 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(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index a09d013..55af7f02 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -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 = 1 + (count * 3);
+   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(1, 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(1, 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(1, 11000);
+   max98373_reset(max98373, dev);
regcache_cache_only(max98373->regmap, false);
regcache_sync(max98373->regmap);
return 0;
-- 
2.7.4



[PATCH 3/4] ASoC: max98373: Sort max98373_bde_gain_tlv in reverse order

2018-10-10 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes : Sort 'max98373_bde_gain_tlv' in reverse order.
   Fixed wrong use case of 'TLV_DB_SCALE_ITEM' - TLV_DB_SCALE_ITEM(min, 
step, mute)
   Max value was set in min field and negative value was set in 
step field before.

 sound/soc/codecs/max98373.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 1f5887b..e9c082c 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -482,7 +482,7 @@ static const 
DECLARE_TLV_DB_RANGE(max98373_limiter_thresh_tlv,
 );
 
 static const DECLARE_TLV_DB_RANGE(max98373_bde_gain_tlv,
-   0, 60, TLV_DB_SCALE_ITEM(0, -25, 0),
+   0, 60, TLV_DB_SCALE_ITEM(-1500, 25, 0),
 );
 
 static bool max98373_readable_register(struct device *dev, unsigned int reg)
@@ -653,21 +653,21 @@ SOC_SINGLE("BDE Hold Time", MAX98373_R2090_BDE_LVL_HOLD, 
0, 0xFF, 0),
 SOC_SINGLE("BDE Attack Rate", MAX98373_R2091_BDE_GAIN_ATK_REL_RATE, 4, 0xF, 0),
 SOC_SINGLE("BDE Release Rate", MAX98373_R2091_BDE_GAIN_ATK_REL_RATE, 0, 0xF, 
0),
 SOC_SINGLE_TLV("BDE LVL1 Clip Thresh Volume", MAX98373_R20A9_BDE_L1_CFG_2,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL2 Clip Thresh Volume", MAX98373_R20AC_BDE_L2_CFG_2,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL3 Clip Thresh Volume", MAX98373_R20AF_BDE_L3_CFG_2,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL4 Clip Thresh Volume", MAX98373_R20B2_BDE_L4_CFG_2,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL1 Clip Reduction Volume", MAX98373_R20AA_BDE_L1_CFG_3,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL2 Clip Reduction Volume", MAX98373_R20AD_BDE_L2_CFG_3,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL3 Clip Reduction Volume", MAX98373_R20B0_BDE_L3_CFG_3,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL4 Clip Reduction Volume", MAX98373_R20B3_BDE_L4_CFG_3,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL1 Limiter Thresh Volume", MAX98373_R20A8_BDE_L1_CFG_1,
0, 0xF, 1, max98373_limiter_thresh_tlv),
 SOC_SINGLE_TLV("BDE LVL2 Limiter Thresh Volume", MAX98373_R20AB_BDE_L2_CFG_1,
-- 
2.7.4



[PATCH 4/4] ASoC: max98373: Sort DHT Rot Pnt Volume in reverse order

2018-10-10 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes : Sort 'max98373_dht_spkgain_min_tlv' in reverse order.
   Fixed wrong use case of 'TLV_DB_SCALE_ITEM' - TLV_DB_SCALE_ITEM(min, 
step, mute)
   Max value was set in min field and negative value was set in 
step field before.

 sound/soc/codecs/max98373.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index e9c082c..e75c212 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -470,12 +470,12 @@ static const 
DECLARE_TLV_DB_RANGE(max98373_dht_spkgain_min_tlv,
0, 9, TLV_DB_SCALE_ITEM(800, 100, 0),
 );
 static const DECLARE_TLV_DB_RANGE(max98373_dht_rotation_point_tlv,
-   0, 1, TLV_DB_SCALE_ITEM(-50, -50, 0),
-   2, 7, TLV_DB_SCALE_ITEM(-200, -100, 0),
-   8, 9, TLV_DB_SCALE_ITEM(-1000, -200, 0),
-   10, 11, TLV_DB_SCALE_ITEM(-1500, -300, 0),
-   12, 13, TLV_DB_SCALE_ITEM(-2000, -200, 0),
-   14, 15, TLV_DB_SCALE_ITEM(-2500, -500, 0),
+   0, 1, TLV_DB_SCALE_ITEM(-3000, 500, 0),
+   2, 4, TLV_DB_SCALE_ITEM(-2200, 200, 0),
+   5, 6, TLV_DB_SCALE_ITEM(-1500, 300, 0),
+   7, 9, TLV_DB_SCALE_ITEM(-1000, 200, 0),
+   10, 13, TLV_DB_SCALE_ITEM(-500, 100, 0),
+   14, 15, TLV_DB_SCALE_ITEM(-100, 50, 0),
 );
 static const DECLARE_TLV_DB_RANGE(max98373_limiter_thresh_tlv,
0, 15, TLV_DB_SCALE_ITEM(-1500, 100, 0),
@@ -616,7 +616,7 @@ SOC_SINGLE("DHT Switch", MAX98373_R20D4_DHT_EN,
 SOC_SINGLE_TLV("DHT Min Volume", MAX98373_R20D1_DHT_CFG,
MAX98373_DHT_SPK_GAIN_MIN_SHIFT, 9, 0, max98373_dht_spkgain_min_tlv),
 SOC_SINGLE_TLV("DHT Rot Pnt Volume", MAX98373_R20D1_DHT_CFG,
-   MAX98373_DHT_ROT_PNT_SHIFT, 15, 0, max98373_dht_rotation_point_tlv),
+   MAX98373_DHT_ROT_PNT_SHIFT, 15, 1, max98373_dht_rotation_point_tlv),
 SOC_SINGLE_TLV("DHT Attack Step Volume", MAX98373_R20D2_DHT_ATTACK_CFG,
MAX98373_DHT_ATTACK_STEP_SHIFT, 4, 0, max98373_dht_step_size_tlv),
 SOC_SINGLE_TLV("DHT Release Step Volume", MAX98373_R20D3_DHT_RELEASE_CFG,
-- 
2.7.4



[PATCH 3/4] ASoC: max98373: Sort max98373_bde_gain_tlv in reverse order

2018-10-10 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes : Sort 'max98373_bde_gain_tlv' in reverse order.
   Fixed wrong use case of 'TLV_DB_SCALE_ITEM' - TLV_DB_SCALE_ITEM(min, 
step, mute)
   Max value was set in min field and negative value was set in 
step field before.

 sound/soc/codecs/max98373.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 1f5887b..e9c082c 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -482,7 +482,7 @@ static const 
DECLARE_TLV_DB_RANGE(max98373_limiter_thresh_tlv,
 );
 
 static const DECLARE_TLV_DB_RANGE(max98373_bde_gain_tlv,
-   0, 60, TLV_DB_SCALE_ITEM(0, -25, 0),
+   0, 60, TLV_DB_SCALE_ITEM(-1500, 25, 0),
 );
 
 static bool max98373_readable_register(struct device *dev, unsigned int reg)
@@ -653,21 +653,21 @@ SOC_SINGLE("BDE Hold Time", MAX98373_R2090_BDE_LVL_HOLD, 
0, 0xFF, 0),
 SOC_SINGLE("BDE Attack Rate", MAX98373_R2091_BDE_GAIN_ATK_REL_RATE, 4, 0xF, 0),
 SOC_SINGLE("BDE Release Rate", MAX98373_R2091_BDE_GAIN_ATK_REL_RATE, 0, 0xF, 
0),
 SOC_SINGLE_TLV("BDE LVL1 Clip Thresh Volume", MAX98373_R20A9_BDE_L1_CFG_2,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL2 Clip Thresh Volume", MAX98373_R20AC_BDE_L2_CFG_2,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL3 Clip Thresh Volume", MAX98373_R20AF_BDE_L3_CFG_2,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL4 Clip Thresh Volume", MAX98373_R20B2_BDE_L4_CFG_2,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL1 Clip Reduction Volume", MAX98373_R20AA_BDE_L1_CFG_3,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL2 Clip Reduction Volume", MAX98373_R20AD_BDE_L2_CFG_3,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL3 Clip Reduction Volume", MAX98373_R20B0_BDE_L3_CFG_3,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL4 Clip Reduction Volume", MAX98373_R20B3_BDE_L4_CFG_3,
-   0, 0x3C, 0, max98373_bde_gain_tlv),
+   0, 0x3C, 1, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL1 Limiter Thresh Volume", MAX98373_R20A8_BDE_L1_CFG_1,
0, 0xF, 1, max98373_limiter_thresh_tlv),
 SOC_SINGLE_TLV("BDE LVL2 Limiter Thresh Volume", MAX98373_R20AB_BDE_L2_CFG_1,
-- 
2.7.4



[PATCH 4/4] ASoC: max98373: Sort DHT Rot Pnt Volume in reverse order

2018-10-10 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes : Sort 'max98373_dht_spkgain_min_tlv' in reverse order.
   Fixed wrong use case of 'TLV_DB_SCALE_ITEM' - TLV_DB_SCALE_ITEM(min, 
step, mute)
   Max value was set in min field and negative value was set in 
step field before.

 sound/soc/codecs/max98373.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index e9c082c..e75c212 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -470,12 +470,12 @@ static const 
DECLARE_TLV_DB_RANGE(max98373_dht_spkgain_min_tlv,
0, 9, TLV_DB_SCALE_ITEM(800, 100, 0),
 );
 static const DECLARE_TLV_DB_RANGE(max98373_dht_rotation_point_tlv,
-   0, 1, TLV_DB_SCALE_ITEM(-50, -50, 0),
-   2, 7, TLV_DB_SCALE_ITEM(-200, -100, 0),
-   8, 9, TLV_DB_SCALE_ITEM(-1000, -200, 0),
-   10, 11, TLV_DB_SCALE_ITEM(-1500, -300, 0),
-   12, 13, TLV_DB_SCALE_ITEM(-2000, -200, 0),
-   14, 15, TLV_DB_SCALE_ITEM(-2500, -500, 0),
+   0, 1, TLV_DB_SCALE_ITEM(-3000, 500, 0),
+   2, 4, TLV_DB_SCALE_ITEM(-2200, 200, 0),
+   5, 6, TLV_DB_SCALE_ITEM(-1500, 300, 0),
+   7, 9, TLV_DB_SCALE_ITEM(-1000, 200, 0),
+   10, 13, TLV_DB_SCALE_ITEM(-500, 100, 0),
+   14, 15, TLV_DB_SCALE_ITEM(-100, 50, 0),
 );
 static const DECLARE_TLV_DB_RANGE(max98373_limiter_thresh_tlv,
0, 15, TLV_DB_SCALE_ITEM(-1500, 100, 0),
@@ -616,7 +616,7 @@ SOC_SINGLE("DHT Switch", MAX98373_R20D4_DHT_EN,
 SOC_SINGLE_TLV("DHT Min Volume", MAX98373_R20D1_DHT_CFG,
MAX98373_DHT_SPK_GAIN_MIN_SHIFT, 9, 0, max98373_dht_spkgain_min_tlv),
 SOC_SINGLE_TLV("DHT Rot Pnt Volume", MAX98373_R20D1_DHT_CFG,
-   MAX98373_DHT_ROT_PNT_SHIFT, 15, 0, max98373_dht_rotation_point_tlv),
+   MAX98373_DHT_ROT_PNT_SHIFT, 15, 1, max98373_dht_rotation_point_tlv),
 SOC_SINGLE_TLV("DHT Attack Step Volume", MAX98373_R20D2_DHT_ATTACK_CFG,
MAX98373_DHT_ATTACK_STEP_SHIFT, 4, 0, max98373_dht_step_size_tlv),
 SOC_SINGLE_TLV("DHT Release Step Volume", MAX98373_R20D3_DHT_RELEASE_CFG,
-- 
2.7.4



[PATCH 2/4] ASoC: max98373: Sort BDE Limiter Thresh Volume in reverse order

2018-10-10 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes : Sort 'max98373_limiter_thresh_tlv' in reverse order.
   Fixed wrong use case of 'TLV_DB_SCALE_ITEM' - TLV_DB_SCALE_ITEM(min, 
step, mute)
   Max value was set in min field and negative value was set in 
step field before.

 sound/soc/codecs/max98373.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index bb5ef52..1f5887b 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -478,7 +478,7 @@ static const 
DECLARE_TLV_DB_RANGE(max98373_dht_rotation_point_tlv,
14, 15, TLV_DB_SCALE_ITEM(-2500, -500, 0),
 );
 static const DECLARE_TLV_DB_RANGE(max98373_limiter_thresh_tlv,
-   0, 15, TLV_DB_SCALE_ITEM(0, -100, 0),
+   0, 15, TLV_DB_SCALE_ITEM(-1500, 100, 0),
 );
 
 static const DECLARE_TLV_DB_RANGE(max98373_bde_gain_tlv,
@@ -669,13 +669,13 @@ SOC_SINGLE_TLV("BDE LVL3 Clip Reduction Volume", 
MAX98373_R20B0_BDE_L3_CFG_3,
 SOC_SINGLE_TLV("BDE LVL4 Clip Reduction Volume", MAX98373_R20B3_BDE_L4_CFG_3,
0, 0x3C, 0, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL1 Limiter Thresh Volume", MAX98373_R20A8_BDE_L1_CFG_1,
-   0, 0xF, 0, max98373_limiter_thresh_tlv),
+   0, 0xF, 1, max98373_limiter_thresh_tlv),
 SOC_SINGLE_TLV("BDE LVL2 Limiter Thresh Volume", MAX98373_R20AB_BDE_L2_CFG_1,
-   0, 0xF, 0, max98373_limiter_thresh_tlv),
+   0, 0xF, 1, max98373_limiter_thresh_tlv),
 SOC_SINGLE_TLV("BDE LVL3 Limiter Thresh Volume", MAX98373_R20AE_BDE_L3_CFG_1,
-   0, 0xF, 0, max98373_limiter_thresh_tlv),
+   0, 0xF, 1, max98373_limiter_thresh_tlv),
 SOC_SINGLE_TLV("BDE LVL4 Limiter Thresh Volume", MAX98373_R20B1_BDE_L4_CFG_1,
-   0, 0xF, 0, max98373_limiter_thresh_tlv),
+   0, 0xF, 1, max98373_limiter_thresh_tlv),
 /* Limiter */
 SOC_SINGLE("Limiter Switch", MAX98373_R20E2_LIMITER_EN,
MAX98373_LIMITER_EN_SHIFT, 1, 0),
-- 
2.7.4



[PATCH 1/4] ASoC: max98373: Sort Digital Volume in reverse order

2018-10-10 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes : Sort 'max98373_digital_tlv' in reverse order.
   Fixed wrong use case of 'TLV_DB_SCALE_ITEM' - TLV_DB_SCALE_ITEM(min, 
step, mute)
   Max value was set in min field and negative value was set in 
step field before.

 sound/soc/codecs/max98373.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 1093f76..bb5ef52 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -454,7 +454,7 @@ SND_SOC_DAPM_SIGGEN("IMON"),
 SND_SOC_DAPM_SIGGEN("FBMON"),
 };
 
-static DECLARE_TLV_DB_SCALE(max98373_digital_tlv, 0, -50, 0);
+static DECLARE_TLV_DB_SCALE(max98373_digital_tlv, -6350, 50, 1);
 static const DECLARE_TLV_DB_RANGE(max98373_spk_tlv,
0, 8, TLV_DB_SCALE_ITEM(0, 50, 0),
9, 10, TLV_DB_SCALE_ITEM(500, 100, 0),
@@ -604,7 +604,7 @@ SOC_SINGLE("Dither Switch", MAX98373_R203F_AMP_DSP_CFG,
 SOC_SINGLE("DC Blocker Switch", MAX98373_R203F_AMP_DSP_CFG,
MAX98373_AMP_DSP_CFG_DCBLK_SHIFT, 1, 0),
 SOC_SINGLE_TLV("Digital Volume", MAX98373_R203D_AMP_DIG_VOL_CTRL,
-   0, 0x7F, 0, max98373_digital_tlv),
+   0, 0x7F, 1, max98373_digital_tlv),
 SOC_SINGLE_TLV("Speaker Volume", MAX98373_R203E_AMP_PATH_GAIN,
MAX98373_SPK_DIGI_GAIN_SHIFT, 10, 0, max98373_spk_tlv),
 SOC_SINGLE_TLV("FS Max Volume", MAX98373_R203E_AMP_PATH_GAIN,
-- 
2.7.4



[PATCH 2/4] ASoC: max98373: Sort BDE Limiter Thresh Volume in reverse order

2018-10-10 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes : Sort 'max98373_limiter_thresh_tlv' in reverse order.
   Fixed wrong use case of 'TLV_DB_SCALE_ITEM' - TLV_DB_SCALE_ITEM(min, 
step, mute)
   Max value was set in min field and negative value was set in 
step field before.

 sound/soc/codecs/max98373.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index bb5ef52..1f5887b 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -478,7 +478,7 @@ static const 
DECLARE_TLV_DB_RANGE(max98373_dht_rotation_point_tlv,
14, 15, TLV_DB_SCALE_ITEM(-2500, -500, 0),
 );
 static const DECLARE_TLV_DB_RANGE(max98373_limiter_thresh_tlv,
-   0, 15, TLV_DB_SCALE_ITEM(0, -100, 0),
+   0, 15, TLV_DB_SCALE_ITEM(-1500, 100, 0),
 );
 
 static const DECLARE_TLV_DB_RANGE(max98373_bde_gain_tlv,
@@ -669,13 +669,13 @@ SOC_SINGLE_TLV("BDE LVL3 Clip Reduction Volume", 
MAX98373_R20B0_BDE_L3_CFG_3,
 SOC_SINGLE_TLV("BDE LVL4 Clip Reduction Volume", MAX98373_R20B3_BDE_L4_CFG_3,
0, 0x3C, 0, max98373_bde_gain_tlv),
 SOC_SINGLE_TLV("BDE LVL1 Limiter Thresh Volume", MAX98373_R20A8_BDE_L1_CFG_1,
-   0, 0xF, 0, max98373_limiter_thresh_tlv),
+   0, 0xF, 1, max98373_limiter_thresh_tlv),
 SOC_SINGLE_TLV("BDE LVL2 Limiter Thresh Volume", MAX98373_R20AB_BDE_L2_CFG_1,
-   0, 0xF, 0, max98373_limiter_thresh_tlv),
+   0, 0xF, 1, max98373_limiter_thresh_tlv),
 SOC_SINGLE_TLV("BDE LVL3 Limiter Thresh Volume", MAX98373_R20AE_BDE_L3_CFG_1,
-   0, 0xF, 0, max98373_limiter_thresh_tlv),
+   0, 0xF, 1, max98373_limiter_thresh_tlv),
 SOC_SINGLE_TLV("BDE LVL4 Limiter Thresh Volume", MAX98373_R20B1_BDE_L4_CFG_1,
-   0, 0xF, 0, max98373_limiter_thresh_tlv),
+   0, 0xF, 1, max98373_limiter_thresh_tlv),
 /* Limiter */
 SOC_SINGLE("Limiter Switch", MAX98373_R20E2_LIMITER_EN,
MAX98373_LIMITER_EN_SHIFT, 1, 0),
-- 
2.7.4



[PATCH 1/4] ASoC: max98373: Sort Digital Volume in reverse order

2018-10-10 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes : Sort 'max98373_digital_tlv' in reverse order.
   Fixed wrong use case of 'TLV_DB_SCALE_ITEM' - TLV_DB_SCALE_ITEM(min, 
step, mute)
   Max value was set in min field and negative value was set in 
step field before.

 sound/soc/codecs/max98373.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 1093f76..bb5ef52 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -454,7 +454,7 @@ SND_SOC_DAPM_SIGGEN("IMON"),
 SND_SOC_DAPM_SIGGEN("FBMON"),
 };
 
-static DECLARE_TLV_DB_SCALE(max98373_digital_tlv, 0, -50, 0);
+static DECLARE_TLV_DB_SCALE(max98373_digital_tlv, -6350, 50, 1);
 static const DECLARE_TLV_DB_RANGE(max98373_spk_tlv,
0, 8, TLV_DB_SCALE_ITEM(0, 50, 0),
9, 10, TLV_DB_SCALE_ITEM(500, 100, 0),
@@ -604,7 +604,7 @@ SOC_SINGLE("Dither Switch", MAX98373_R203F_AMP_DSP_CFG,
 SOC_SINGLE("DC Blocker Switch", MAX98373_R203F_AMP_DSP_CFG,
MAX98373_AMP_DSP_CFG_DCBLK_SHIFT, 1, 0),
 SOC_SINGLE_TLV("Digital Volume", MAX98373_R203D_AMP_DIG_VOL_CTRL,
-   0, 0x7F, 0, max98373_digital_tlv),
+   0, 0x7F, 1, max98373_digital_tlv),
 SOC_SINGLE_TLV("Speaker Volume", MAX98373_R203E_AMP_PATH_GAIN,
MAX98373_SPK_DIGI_GAIN_SHIFT, 10, 0, max98373_spk_tlv),
 SOC_SINGLE_TLV("FS Max Volume", MAX98373_R203E_AMP_PATH_GAIN,
-- 
2.7.4



[v2] ASoC: max98373: Added 10ms sleep after amp software reset

2018-08-23 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes since v1 : Applied usleep_range intead of using mdelay

 Changes : Applied 10ms delay after amp software reset.
   10ms guard time is required for stability.

 sound/soc/codecs/max98373.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 2764fae..6aaff03 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -730,6 +730,7 @@ static int max98373_probe(struct snd_soc_component 
*component)
/* Software Reset */
regmap_write(max98373->regmap,
MAX98373_R2000_SW_RESET, MAX98373_SOFT_RESET);
+   usleep_range(1, 11000);
 
/* IV default slot configuration */
regmap_write(max98373->regmap,
@@ -818,6 +819,7 @@ static int max98373_resume(struct device *dev)
 
regmap_write(max98373->regmap,
MAX98373_R2000_SW_RESET, MAX98373_SOFT_RESET);
+   usleep_range(1, 11000);
regcache_cache_only(max98373->regmap, false);
regcache_sync(max98373->regmap);
return 0;
-- 
2.7.4



[v2] ASoC: max98373: Added 10ms sleep after amp software reset

2018-08-23 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes since v1 : Applied usleep_range intead of using mdelay

 Changes : Applied 10ms delay after amp software reset.
   10ms guard time is required for stability.

 sound/soc/codecs/max98373.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 2764fae..6aaff03 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -730,6 +730,7 @@ static int max98373_probe(struct snd_soc_component 
*component)
/* Software Reset */
regmap_write(max98373->regmap,
MAX98373_R2000_SW_RESET, MAX98373_SOFT_RESET);
+   usleep_range(1, 11000);
 
/* IV default slot configuration */
regmap_write(max98373->regmap,
@@ -818,6 +819,7 @@ static int max98373_resume(struct device *dev)
 
regmap_write(max98373->regmap,
MAX98373_R2000_SW_RESET, MAX98373_SOFT_RESET);
+   usleep_range(1, 11000);
regcache_cache_only(max98373->regmap, false);
regcache_sync(max98373->regmap);
return 0;
-- 
2.7.4



RE: [PATCH] ASoC: max98373: Added 10ms delay after amp software reset

2018-08-23 Thread Ryan Lee
>-Original Message-
>From: Dmitry Torokhov 
>Sent: Thursday, August 23, 2018 5:08 PM
>To: Mark Brown 
>Cc: Ryan Lee ; Liam Girdwood
>; Jaroslav Kysela ; Takashi Iwai
>; Kuninori Morimoto ;
>alsa-de...@alsa-project.org; lkml ;
>ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH] ASoC: max98373: Added 10ms delay after amp software
>reset
>
>EXTERNAL EMAIL
>
>
>
>On Thu, Aug 23, 2018 at 10:51:07AM +0100, Mark Brown wrote:
>> On Wed, Aug 22, 2018 at 05:31:04PM -0700, Dmitry Torokhov wrote:
>> > On Wed, Aug 22, 2018 at 5:21 PM Ryan Lee
> wrote:
>> > > +   mdelay(10);
>>
>> > Is it really necessary for the CPU to spin for 10msec here?
>> > usleep_range() would be better solution.
>>
>> Or msleep() for that matter, it's not going ot be the end of the world
>> if we delay a bit too long.
>
>Frankly, I'd rather we did not introduce extra delays. I do not know if we use
>this part, but on ChromeOS we are interested in shaving as much from the boot
>time as possible and 10 msecs here and 10 msecs there do add up.

Thanks for all your feedback.
Let me apply usleep_range() or msleep() instead of using mdelay().

>
>Thanks.
>
>--
>Dmitry


RE: [PATCH] ASoC: max98373: Added 10ms delay after amp software reset

2018-08-23 Thread Ryan Lee
>-Original Message-
>From: Dmitry Torokhov 
>Sent: Thursday, August 23, 2018 5:08 PM
>To: Mark Brown 
>Cc: Ryan Lee ; Liam Girdwood
>; Jaroslav Kysela ; Takashi Iwai
>; Kuninori Morimoto ;
>alsa-de...@alsa-project.org; lkml ;
>ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH] ASoC: max98373: Added 10ms delay after amp software
>reset
>
>EXTERNAL EMAIL
>
>
>
>On Thu, Aug 23, 2018 at 10:51:07AM +0100, Mark Brown wrote:
>> On Wed, Aug 22, 2018 at 05:31:04PM -0700, Dmitry Torokhov wrote:
>> > On Wed, Aug 22, 2018 at 5:21 PM Ryan Lee
> wrote:
>> > > +   mdelay(10);
>>
>> > Is it really necessary for the CPU to spin for 10msec here?
>> > usleep_range() would be better solution.
>>
>> Or msleep() for that matter, it's not going ot be the end of the world
>> if we delay a bit too long.
>
>Frankly, I'd rather we did not introduce extra delays. I do not know if we use
>this part, but on ChromeOS we are interested in shaving as much from the boot
>time as possible and 10 msecs here and 10 msecs there do add up.

Thanks for all your feedback.
Let me apply usleep_range() or msleep() instead of using mdelay().

>
>Thanks.
>
>--
>Dmitry


[PATCH] ASoC: max98373: Added 10ms delay after amp software reset

2018-08-22 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes : Applied 10ms delay after amp software reset.
   10ms guard time is required for stability.
 sound/soc/codecs/max98373.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 2764fae..6aaff03 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -730,6 +730,7 @@ static int max98373_probe(struct snd_soc_component 
*component)
/* Software Reset */
regmap_write(max98373->regmap,
MAX98373_R2000_SW_RESET, MAX98373_SOFT_RESET);
+   mdelay(10);
 
/* IV default slot configuration */
regmap_write(max98373->regmap,
@@ -818,6 +819,7 @@ static int max98373_resume(struct device *dev)
 
regmap_write(max98373->regmap,
MAX98373_R2000_SW_RESET, MAX98373_SOFT_RESET);
+   mdelay(10);
regcache_cache_only(max98373->regmap, false);
regcache_sync(max98373->regmap);
return 0;
-- 
2.7.4



[PATCH] ASoC: max98373: Added 10ms delay after amp software reset

2018-08-22 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes : Applied 10ms delay after amp software reset.
   10ms guard time is required for stability.
 sound/soc/codecs/max98373.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 2764fae..6aaff03 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -730,6 +730,7 @@ static int max98373_probe(struct snd_soc_component 
*component)
/* Software Reset */
regmap_write(max98373->regmap,
MAX98373_R2000_SW_RESET, MAX98373_SOFT_RESET);
+   mdelay(10);
 
/* IV default slot configuration */
regmap_write(max98373->regmap,
@@ -818,6 +819,7 @@ static int max98373_resume(struct device *dev)
 
regmap_write(max98373->regmap,
MAX98373_R2000_SW_RESET, MAX98373_SOFT_RESET);
+   mdelay(10);
regcache_cache_only(max98373->regmap, false);
regcache_sync(max98373->regmap);
return 0;
-- 
2.7.4



[PATCH] ASoC: max98373: Added speaker FS gain cotnrol register to volatile.

2018-08-15 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes : Added Speaker FS gain maximum control(0x203E) register to volatile.
 sound/soc/codecs/max98373.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 92b7125..2764fae 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -520,6 +520,7 @@ static bool max98373_volatile_reg(struct device *dev, 
unsigned int reg)
 {
switch (reg) {
case MAX98373_R2000_SW_RESET ... MAX98373_R2009_INT_FLAG3:
+   case MAX98373_R203E_AMP_PATH_GAIN:
case MAX98373_R2054_MEAS_ADC_PVDD_CH_READBACK:
case MAX98373_R2055_MEAS_ADC_THERM_CH_READBACK:
case MAX98373_R20B6_BDE_CUR_STATE_READBACK:
-- 
2.7.4



[PATCH] ASoC: max98373: Added speaker FS gain cotnrol register to volatile.

2018-08-15 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes : Added Speaker FS gain maximum control(0x203E) register to volatile.
 sound/soc/codecs/max98373.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 92b7125..2764fae 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -520,6 +520,7 @@ static bool max98373_volatile_reg(struct device *dev, 
unsigned int reg)
 {
switch (reg) {
case MAX98373_R2000_SW_RESET ... MAX98373_R2009_INT_FLAG3:
+   case MAX98373_R203E_AMP_PATH_GAIN:
case MAX98373_R2054_MEAS_ADC_PVDD_CH_READBACK:
case MAX98373_R2055_MEAS_ADC_THERM_CH_READBACK:
case MAX98373_R20B6_BDE_CUR_STATE_READBACK:
-- 
2.7.4



[PATCH] ASoC: max98373: Added software reset register to readable registers

2018-08-07 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes : Added 'MAX98373_R2000_SW_RESET' register to 
'max98373_readable_register'
   Software reset didn't work properly after suspend/resume.
 sound/soc/codecs/max98373.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index a925861..92b7125 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -488,6 +488,7 @@ static const DECLARE_TLV_DB_RANGE(max98373_bde_gain_tlv,
 static bool max98373_readable_register(struct device *dev, unsigned int reg)
 {
switch (reg) {
+   case MAX98373_R2000_SW_RESET:
case MAX98373_R2001_INT_RAW1 ... MAX98373_R200C_INT_EN3:
case MAX98373_R2010_IRQ_CTRL:
case MAX98373_R2014_THERM_WARN_THRESH
-- 
2.7.4



[PATCH] ASoC: max98373: Added software reset register to readable registers

2018-08-07 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 Changes : Added 'MAX98373_R2000_SW_RESET' register to 
'max98373_readable_register'
   Software reset didn't work properly after suspend/resume.
 sound/soc/codecs/max98373.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index a925861..92b7125 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -488,6 +488,7 @@ static const DECLARE_TLV_DB_RANGE(max98373_bde_gain_tlv,
 static bool max98373_readable_register(struct device *dev, unsigned int reg)
 {
switch (reg) {
+   case MAX98373_R2000_SW_RESET:
case MAX98373_R2001_INT_RAW1 ... MAX98373_R200C_INT_EN3:
case MAX98373_R2010_IRQ_CTRL:
case MAX98373_R2014_THERM_WARN_THRESH
-- 
2.7.4



[PATCH] ASoC: max98373 Changed SPDX header in C++ comments style

2018-01-18 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
Chagelog:
Changed SPDX header in C comment-style to C++ comment style

 sound/soc/codecs/max98373.c | 4 ++--
 sound/soc/codecs/max98373.h | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 31b0864..562e887 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -1,5 +1,5 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright (c) 2017, Maxim Integrated */
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2017, Maxim Integrated
 
 #include 
 #include 
diff --git a/sound/soc/codecs/max98373.h b/sound/soc/codecs/max98373.h
index d0b359d..f6a37aa 100644
--- a/sound/soc/codecs/max98373.h
+++ b/sound/soc/codecs/max98373.h
@@ -1,5 +1,6 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright (c) 2017, Maxim Integrated */
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2017, Maxim Integrated
+
 #ifndef _MAX98373_H
 #define _MAX98373_H
 
-- 
2.7.4



[PATCH] ASoC: max98373 Changed SPDX header in C++ comments style

2018-01-18 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Chagelog:
Changed SPDX header in C comment-style to C++ comment style

 sound/soc/codecs/max98373.c | 4 ++--
 sound/soc/codecs/max98373.h | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 31b0864..562e887 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -1,5 +1,5 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright (c) 2017, Maxim Integrated */
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2017, Maxim Integrated
 
 #include 
 #include 
diff --git a/sound/soc/codecs/max98373.h b/sound/soc/codecs/max98373.h
index d0b359d..f6a37aa 100644
--- a/sound/soc/codecs/max98373.h
+++ b/sound/soc/codecs/max98373.h
@@ -1,5 +1,6 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright (c) 2017, Maxim Integrated */
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2017, Maxim Integrated
+
 #ifndef _MAX98373_H
 #define _MAX98373_H
 
-- 
2.7.4



RE: [PATCH 1/4] ASoC: max98373: Changed SPDX header in C++ comments style

2018-01-18 Thread Ryan Lee
>-Original Message-
>From: Mark Brown [mailto:broo...@kernel.org]
>Sent: Wednesday, January 10, 2018 2:30 AM
>To: Takashi Iwai <ti...@suse.de>
>Cc: Ryan Lee <ryans@maximintegrated.com>; alsa-de...@alsa-project.org;
>lgirdw...@gmail.com; ryan.lee.ma...@gmail.com; pe...@perex.cz; linux-
>ker...@vger.kernel.org
>Subject: Re: [PATCH 1/4] ASoC: max98373: Changed SPDX header in C++
>comments style
>
>On Wed, Jan 10, 2018 at 11:21:56AM +0100, Takashi Iwai wrote:
>> Mark Brown wrote:
>> > On Tue, Jan 09, 2018 at 09:01:58PM -0800, Ryan Lee wrote:
>
>> > > @@ -1,4 +1,4 @@
>> > > -/* SPDX-License-Identifier: GPL-2.0 */
>> > > +// SPDX-License-Identifier: GPL-2.0
>> > >  /* Copyright (c) 2017, Maxim Integrated */
>
>> > Please change the entire header to C++, mixing C and C++ on adjacent
>> > lines looks ugly.
>
>> I'm not sure whether it's a good direction to go, either.
>
>> I rather wonder why SPDX line *must* be in C++ comment style...
>
>Apparently it's to remove any ambiguity for the tooling or something, plus 
>Linus
>decided he likes C++ comments.
>
>I don't understand why this isn't done as a macro like MODULE_LICENSE() and
>so on but the decision was rushed through and not really publicised
>:9

Thank you for your feedback.
I modified two header lines in C++ comment style and send it again.


RE: [PATCH 1/4] ASoC: max98373: Changed SPDX header in C++ comments style

2018-01-18 Thread Ryan Lee
>-Original Message-
>From: Mark Brown [mailto:broo...@kernel.org]
>Sent: Wednesday, January 10, 2018 2:30 AM
>To: Takashi Iwai 
>Cc: Ryan Lee ; alsa-de...@alsa-project.org;
>lgirdw...@gmail.com; ryan.lee.ma...@gmail.com; pe...@perex.cz; linux-
>ker...@vger.kernel.org
>Subject: Re: [PATCH 1/4] ASoC: max98373: Changed SPDX header in C++
>comments style
>
>On Wed, Jan 10, 2018 at 11:21:56AM +0100, Takashi Iwai wrote:
>> Mark Brown wrote:
>> > On Tue, Jan 09, 2018 at 09:01:58PM -0800, Ryan Lee wrote:
>
>> > > @@ -1,4 +1,4 @@
>> > > -/* SPDX-License-Identifier: GPL-2.0 */
>> > > +// SPDX-License-Identifier: GPL-2.0
>> > >  /* Copyright (c) 2017, Maxim Integrated */
>
>> > Please change the entire header to C++, mixing C and C++ on adjacent
>> > lines looks ugly.
>
>> I'm not sure whether it's a good direction to go, either.
>
>> I rather wonder why SPDX line *must* be in C++ comment style...
>
>Apparently it's to remove any ambiguity for the tooling or something, plus 
>Linus
>decided he likes C++ comments.
>
>I don't understand why this isn't done as a macro like MODULE_LICENSE() and
>so on but the decision was rushed through and not really publicised
>:9

Thank you for your feedback.
I modified two header lines in C++ comment style and send it again.


[PATCH 2/4] ASoC: max98373: Added missing blank lines

2018-01-09 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
Changelog:
Added missing blank line into two places.

 sound/soc/codecs/max98373.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index e040b03..77b86c4 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -176,6 +176,7 @@ static int max98373_get_bclk_sel(int bclk)
}
return 0;
 }
+
 static int max98373_set_clock(struct snd_soc_codec *codec,
struct snd_pcm_hw_params *params)
 {
@@ -270,6 +271,7 @@ static int max98373_dai_hw_params(struct snd_pcm_substream 
*substream,
params_rate(params));
goto err;
}
+
/* set DAI_SR to correct LRCLK frequency */
regmap_update_bits(max98373->regmap,
MAX98373_R2027_PCM_SR_SETUP_1,
-- 
2.7.4



[PATCH 2/4] ASoC: max98373: Added missing blank lines

2018-01-09 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changelog:
Added missing blank line into two places.

 sound/soc/codecs/max98373.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index e040b03..77b86c4 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -176,6 +176,7 @@ static int max98373_get_bclk_sel(int bclk)
}
return 0;
 }
+
 static int max98373_set_clock(struct snd_soc_codec *codec,
struct snd_pcm_hw_params *params)
 {
@@ -270,6 +271,7 @@ static int max98373_dai_hw_params(struct snd_pcm_substream 
*substream,
params_rate(params));
goto err;
}
+
/* set DAI_SR to correct LRCLK frequency */
regmap_update_bits(max98373->regmap,
MAX98373_R2027_PCM_SR_SETUP_1,
-- 
2.7.4



[PATCH 1/4] ASoC: max98373: Changed SPDX header in C++ comments style

2018-01-09 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
Changelog:
Changed SPDX header in C comment-style to C++ comment-style

 sound/soc/codecs/max98373.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 9af0d98..e040b03 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: GPL-2.0 */
+// SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2017, Maxim Integrated */
 
 #include 
-- 
2.7.4



[PATCH 3/4] ASoC: max98373: Added TDM off if parameters are all zeroes

2018-01-09 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
Changelog:
Added tdm_mode off condition when all input parameters are zero

 sound/soc/codecs/max98373.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 77b86c4..c5ff30f 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -311,7 +311,10 @@ static int max98373_dai_tdm_slot(struct snd_soc_dai *dai,
unsigned int mask;
int x, slot_found;
 
-   max98373->tdm_mode = true;
+   if (!tx_mask && !rx_mask && !slots && !slot_width)
+   max98373->tdm_mode = false;
+   else
+   max98373->tdm_mode = true;
 
/* BCLK configuration */
bsel = max98373_get_bclk_sel(slots * slot_width);
-- 
2.7.4



[PATCH 1/4] ASoC: max98373: Changed SPDX header in C++ comments style

2018-01-09 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changelog:
Changed SPDX header in C comment-style to C++ comment-style

 sound/soc/codecs/max98373.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 9af0d98..e040b03 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: GPL-2.0 */
+// SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2017, Maxim Integrated */
 
 #include 
-- 
2.7.4



[PATCH 3/4] ASoC: max98373: Added TDM off if parameters are all zeroes

2018-01-09 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changelog:
Added tdm_mode off condition when all input parameters are zero

 sound/soc/codecs/max98373.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index 77b86c4..c5ff30f 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -311,7 +311,10 @@ static int max98373_dai_tdm_slot(struct snd_soc_dai *dai,
unsigned int mask;
int x, slot_found;
 
-   max98373->tdm_mode = true;
+   if (!tx_mask && !rx_mask && !slots && !slot_width)
+   max98373->tdm_mode = false;
+   else
+   max98373->tdm_mode = true;
 
/* BCLK configuration */
bsel = max98373_get_bclk_sel(slots * slot_width);
-- 
2.7.4



[PATCH 4/4] ASoC: max98373: Modified control names for TLV controls

2018-01-09 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
Changelog:
Added suffix - 'Volume' to all TLV controls.

 sound/soc/codecs/max98373.c | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index c5ff30f..66e9ddb 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -611,13 +611,13 @@ SOC_ENUM("Output Voltage", max98373_out_volt_enum),
 /* Dynamic Headroom Tracking */
 SOC_SINGLE("DHT Switch", MAX98373_R20D4_DHT_EN,
MAX98373_DHT_EN_SHIFT, 1, 0),
-SOC_SINGLE_TLV("DHT Gain Min", MAX98373_R20D1_DHT_CFG,
+SOC_SINGLE_TLV("DHT Min Volume", MAX98373_R20D1_DHT_CFG,
MAX98373_DHT_SPK_GAIN_MIN_SHIFT, 9, 0, max98373_dht_spkgain_min_tlv),
-SOC_SINGLE_TLV("DHT Rot Pnt", MAX98373_R20D1_DHT_CFG,
+SOC_SINGLE_TLV("DHT Rot Pnt Volume", MAX98373_R20D1_DHT_CFG,
MAX98373_DHT_ROT_PNT_SHIFT, 15, 0, max98373_dht_rotation_point_tlv),
-SOC_SINGLE_TLV("DHT Attack Step", MAX98373_R20D2_DHT_ATTACK_CFG,
+SOC_SINGLE_TLV("DHT Attack Step Volume", MAX98373_R20D2_DHT_ATTACK_CFG,
MAX98373_DHT_ATTACK_STEP_SHIFT, 4, 0, max98373_dht_step_size_tlv),
-SOC_SINGLE_TLV("DHT Release Step", MAX98373_R20D3_DHT_RELEASE_CFG,
+SOC_SINGLE_TLV("DHT Release Step Volume", MAX98373_R20D3_DHT_RELEASE_CFG,
MAX98373_DHT_RELEASE_STEP_SHIFT, 4, 0, max98373_dht_step_size_tlv),
 SOC_ENUM("DHT Attack Rate", max98373_dht_attack_rate_enum),
 SOC_ENUM("DHT Release Rate", max98373_dht_release_rate_enum),
@@ -650,36 +650,36 @@ SOC_SINGLE("BDE Thresh Hysteresis", 
MAX98373_R209B_BDE_THRESH_HYST, 0, 0xFF, 0),
 SOC_SINGLE("BDE Hold Time", MAX98373_R2090_BDE_LVL_HOLD, 0, 0xFF, 0),
 SOC_SINGLE("BDE Attack Rate", MAX98373_R2091_BDE_GAIN_ATK_REL_RATE, 4, 0xF, 0),
 SOC_SINGLE("BDE Release Rate", MAX98373_R2091_BDE_GAIN_ATK_REL_RATE, 0, 0xF, 
0),
-SOC_SINGLE_TLV("BDE LVL1 Clip Thresh", MAX98373_R20A9_BDE_L1_CFG_2,
+SOC_SINGLE_TLV("BDE LVL1 Clip Thresh Volume", MAX98373_R20A9_BDE_L1_CFG_2,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL2 Clip Thresh", MAX98373_R20AC_BDE_L2_CFG_2,
+SOC_SINGLE_TLV("BDE LVL2 Clip Thresh Volume", MAX98373_R20AC_BDE_L2_CFG_2,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL3 Clip Thresh", MAX98373_R20AF_BDE_L3_CFG_2,
+SOC_SINGLE_TLV("BDE LVL3 Clip Thresh Volume", MAX98373_R20AF_BDE_L3_CFG_2,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL4 Clip Thresh", MAX98373_R20B2_BDE_L4_CFG_2,
+SOC_SINGLE_TLV("BDE LVL4 Clip Thresh Volume", MAX98373_R20B2_BDE_L4_CFG_2,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL1 Clip Gain Reduct", MAX98373_R20AA_BDE_L1_CFG_3,
+SOC_SINGLE_TLV("BDE LVL1 Clip Reduction Volume", MAX98373_R20AA_BDE_L1_CFG_3,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL2 Clip Gain Reduct", MAX98373_R20AD_BDE_L2_CFG_3,
+SOC_SINGLE_TLV("BDE LVL2 Clip Reduction Volume", MAX98373_R20AD_BDE_L2_CFG_3,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL3 Clip Gain Reduct", MAX98373_R20B0_BDE_L3_CFG_3,
+SOC_SINGLE_TLV("BDE LVL3 Clip Reduction Volume", MAX98373_R20B0_BDE_L3_CFG_3,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL4 Clip Gain Reduct", MAX98373_R20B3_BDE_L4_CFG_3,
+SOC_SINGLE_TLV("BDE LVL4 Clip Reduction Volume", MAX98373_R20B3_BDE_L4_CFG_3,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL1 Limiter Thresh", MAX98373_R20A8_BDE_L1_CFG_1,
+SOC_SINGLE_TLV("BDE LVL1 Limiter Thresh Volume", MAX98373_R20A8_BDE_L1_CFG_1,
0, 0xF, 0, max98373_limiter_thresh_tlv),
-SOC_SINGLE_TLV("BDE LVL2 Limiter Thresh", MAX98373_R20AB_BDE_L2_CFG_1,
+SOC_SINGLE_TLV("BDE LVL2 Limiter Thresh Volume", MAX98373_R20AB_BDE_L2_CFG_1,
0, 0xF, 0, max98373_limiter_thresh_tlv),
-SOC_SINGLE_TLV("BDE LVL3 Limiter Thresh", MAX98373_R20AE_BDE_L3_CFG_1,
+SOC_SINGLE_TLV("BDE LVL3 Limiter Thresh Volume", MAX98373_R20AE_BDE_L3_CFG_1,
0, 0xF, 0, max98373_limiter_thresh_tlv),
-SOC_SINGLE_TLV("BDE LVL4 Limiter Thresh", MAX98373_R20B1_BDE_L4_CFG_1,
+SOC_SINGLE_TLV("BDE LVL4 Limiter Thresh Volume", MAX98373_R20B1_BDE_L4_CFG_1,
0, 0xF, 0, max98373_limiter_thresh_tlv),
 /* Limiter */
 SOC_SINGLE("Limiter Switch", MAX98373_R20E2_LIMITER_EN,
MAX98373_LIMITER_EN_SHIFT, 1, 0),
 SOC_SINGLE("Limiter Src Switch", MAX98373_R20E0_LIMITER_THRESH_CFG,
MAX98373_LIMITER_THRESH_SRC_SHIFT, 1, 0),
-SOC_SINGLE_TLV("Limiter Thresh", MAX98373_R20E0_LIMITER_THRESH_CFG,
+SOC_SINGLE_TLV("Limiter Thresh Volume", MAX98373_R20E0_LIMITER_THRESH_CFG,
MAX98373_LIMITER_THRESH_SHIFT, 15, 0, max98373_limiter_thresh_tlv),
 SOC_ENUM("Limiter Attack Rate", max98373_limiter_attack_rate_enum),
 SOC_ENUM("Limiter Release Rate", max98373_limiter_release_rate_enum),
-- 
2.7.4



[PATCH 4/4] ASoC: max98373: Modified control names for TLV controls

2018-01-09 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changelog:
Added suffix - 'Volume' to all TLV controls.

 sound/soc/codecs/max98373.c | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index c5ff30f..66e9ddb 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -611,13 +611,13 @@ SOC_ENUM("Output Voltage", max98373_out_volt_enum),
 /* Dynamic Headroom Tracking */
 SOC_SINGLE("DHT Switch", MAX98373_R20D4_DHT_EN,
MAX98373_DHT_EN_SHIFT, 1, 0),
-SOC_SINGLE_TLV("DHT Gain Min", MAX98373_R20D1_DHT_CFG,
+SOC_SINGLE_TLV("DHT Min Volume", MAX98373_R20D1_DHT_CFG,
MAX98373_DHT_SPK_GAIN_MIN_SHIFT, 9, 0, max98373_dht_spkgain_min_tlv),
-SOC_SINGLE_TLV("DHT Rot Pnt", MAX98373_R20D1_DHT_CFG,
+SOC_SINGLE_TLV("DHT Rot Pnt Volume", MAX98373_R20D1_DHT_CFG,
MAX98373_DHT_ROT_PNT_SHIFT, 15, 0, max98373_dht_rotation_point_tlv),
-SOC_SINGLE_TLV("DHT Attack Step", MAX98373_R20D2_DHT_ATTACK_CFG,
+SOC_SINGLE_TLV("DHT Attack Step Volume", MAX98373_R20D2_DHT_ATTACK_CFG,
MAX98373_DHT_ATTACK_STEP_SHIFT, 4, 0, max98373_dht_step_size_tlv),
-SOC_SINGLE_TLV("DHT Release Step", MAX98373_R20D3_DHT_RELEASE_CFG,
+SOC_SINGLE_TLV("DHT Release Step Volume", MAX98373_R20D3_DHT_RELEASE_CFG,
MAX98373_DHT_RELEASE_STEP_SHIFT, 4, 0, max98373_dht_step_size_tlv),
 SOC_ENUM("DHT Attack Rate", max98373_dht_attack_rate_enum),
 SOC_ENUM("DHT Release Rate", max98373_dht_release_rate_enum),
@@ -650,36 +650,36 @@ SOC_SINGLE("BDE Thresh Hysteresis", 
MAX98373_R209B_BDE_THRESH_HYST, 0, 0xFF, 0),
 SOC_SINGLE("BDE Hold Time", MAX98373_R2090_BDE_LVL_HOLD, 0, 0xFF, 0),
 SOC_SINGLE("BDE Attack Rate", MAX98373_R2091_BDE_GAIN_ATK_REL_RATE, 4, 0xF, 0),
 SOC_SINGLE("BDE Release Rate", MAX98373_R2091_BDE_GAIN_ATK_REL_RATE, 0, 0xF, 
0),
-SOC_SINGLE_TLV("BDE LVL1 Clip Thresh", MAX98373_R20A9_BDE_L1_CFG_2,
+SOC_SINGLE_TLV("BDE LVL1 Clip Thresh Volume", MAX98373_R20A9_BDE_L1_CFG_2,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL2 Clip Thresh", MAX98373_R20AC_BDE_L2_CFG_2,
+SOC_SINGLE_TLV("BDE LVL2 Clip Thresh Volume", MAX98373_R20AC_BDE_L2_CFG_2,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL3 Clip Thresh", MAX98373_R20AF_BDE_L3_CFG_2,
+SOC_SINGLE_TLV("BDE LVL3 Clip Thresh Volume", MAX98373_R20AF_BDE_L3_CFG_2,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL4 Clip Thresh", MAX98373_R20B2_BDE_L4_CFG_2,
+SOC_SINGLE_TLV("BDE LVL4 Clip Thresh Volume", MAX98373_R20B2_BDE_L4_CFG_2,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL1 Clip Gain Reduct", MAX98373_R20AA_BDE_L1_CFG_3,
+SOC_SINGLE_TLV("BDE LVL1 Clip Reduction Volume", MAX98373_R20AA_BDE_L1_CFG_3,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL2 Clip Gain Reduct", MAX98373_R20AD_BDE_L2_CFG_3,
+SOC_SINGLE_TLV("BDE LVL2 Clip Reduction Volume", MAX98373_R20AD_BDE_L2_CFG_3,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL3 Clip Gain Reduct", MAX98373_R20B0_BDE_L3_CFG_3,
+SOC_SINGLE_TLV("BDE LVL3 Clip Reduction Volume", MAX98373_R20B0_BDE_L3_CFG_3,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL4 Clip Gain Reduct", MAX98373_R20B3_BDE_L4_CFG_3,
+SOC_SINGLE_TLV("BDE LVL4 Clip Reduction Volume", MAX98373_R20B3_BDE_L4_CFG_3,
0, 0x3C, 0, max98373_bde_gain_tlv),
-SOC_SINGLE_TLV("BDE LVL1 Limiter Thresh", MAX98373_R20A8_BDE_L1_CFG_1,
+SOC_SINGLE_TLV("BDE LVL1 Limiter Thresh Volume", MAX98373_R20A8_BDE_L1_CFG_1,
0, 0xF, 0, max98373_limiter_thresh_tlv),
-SOC_SINGLE_TLV("BDE LVL2 Limiter Thresh", MAX98373_R20AB_BDE_L2_CFG_1,
+SOC_SINGLE_TLV("BDE LVL2 Limiter Thresh Volume", MAX98373_R20AB_BDE_L2_CFG_1,
0, 0xF, 0, max98373_limiter_thresh_tlv),
-SOC_SINGLE_TLV("BDE LVL3 Limiter Thresh", MAX98373_R20AE_BDE_L3_CFG_1,
+SOC_SINGLE_TLV("BDE LVL3 Limiter Thresh Volume", MAX98373_R20AE_BDE_L3_CFG_1,
0, 0xF, 0, max98373_limiter_thresh_tlv),
-SOC_SINGLE_TLV("BDE LVL4 Limiter Thresh", MAX98373_R20B1_BDE_L4_CFG_1,
+SOC_SINGLE_TLV("BDE LVL4 Limiter Thresh Volume", MAX98373_R20B1_BDE_L4_CFG_1,
0, 0xF, 0, max98373_limiter_thresh_tlv),
 /* Limiter */
 SOC_SINGLE("Limiter Switch", MAX98373_R20E2_LIMITER_EN,
MAX98373_LIMITER_EN_SHIFT, 1, 0),
 SOC_SINGLE("Limiter Src Switch", MAX98373_R20E0_LIMITER_THRESH_CFG,
MAX98373_LIMITER_THRESH_SRC_SHIFT, 1, 0),
-SOC_SINGLE_TLV("Limiter Thresh", MAX98373_R20E0_LIMITER_THRESH_CFG,
+SOC_SINGLE_TLV("Limiter Thresh Volume", MAX98373_R20E0_LIMITER_THRESH_CFG,
MAX98373_LIMITER_THRESH_SHIFT, 15, 0, max98373_limiter_thresh_tlv),
 SOC_ENUM("Limiter Attack Rate", max98373_limiter_attack_rate_enum),
 SOC_ENUM("Limiter Release Rate", max98373_limiter_release_rate_enum),
-- 
2.7.4



RE: [V3 2/2] ASoC: max98373: Added Amplifier Driver

2018-01-05 Thread Ryan Lee
>-Original Message-
>From: Mark Brown [mailto:broo...@kernel.org]
>Sent: Thursday, January 4, 2018 9:14 AM
>To: Ryan Lee <ryans@maximintegrated.com>
>Cc: lgirdw...@gmail.com; pe...@perex.cz; ti...@suse.com; a...@arndb.de;
>a...@ti.com; robert.jarz...@free.fr; supercraig0...@gmail.com;
>jbru...@baylibre.com; dannenb...@ti.com; romain.per...@collabora.com;
>bryce.fergu...@rockwellcollins.com; kuninori.morimoto...@renesas.com; m-
>steckl...@ti.com; alsa-de...@alsa-project.org; linux-kernel@vger.kernel.org;
>ryan.lee.ma...@gmail.com
>Subject: Re: [V3 2/2] ASoC: max98373: Added Amplifier Driver
>
>On Wed, Jan 03, 2018 at 10:39:17AM -0800, Ryan Lee wrote:
>
>This looks mostly good.  There are a few smaller issues but I think at this 
>point
>it's most sensible to apply and fix those incrementally so I'll do that, please
>follow up with patches fixing the remaining issues.

Thank you. Let me follow up with patches fixing the remaining issues.

>
>> --- /dev/null
>> +++ b/sound/soc/codecs/max98373.c
>> @@ -0,0 +1,971 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +/* Copyright (c) 2017, Maxim Integrated */
>
>SPDX headers are supposed to be C++ comments, please send a followup patch
>fixing this.
>
>> +static int max98373_get_bclk_sel(int bclk) {
>> +int i;
>> +/* match BCLKs per LRCLK */
>> +for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) {
>> +if (bclk_sel_table[i] == bclk)
>> +return i + 2;
>> +}
>> +return 0;
>> +}
>> +static int max98373_set_clock(struct snd_soc_codec *codec,
>
>Missing blank line between the functions.
OK. Thanks.
>
>> +}
>> +/* set DAI_SR to correct LRCLK frequency */
>
>Another missing blank line.
OK. Let me fix.
>
>> +static int max98373_dai_tdm_slot(struct snd_soc_dai *dai,
>> +unsigned int tx_mask, unsigned int rx_mask,
>> +int slots, int slot_width)
>> +{
>> +struct snd_soc_codec *codec = dai->codec;
>> +struct max98373_priv *max98373 =
>snd_soc_codec_get_drvdata(codec);
>> +int bsel = 0;
>> +unsigned int chan_sz = 0;
>> +unsigned int mask;
>> +int x, slot_found;
>> +
>> +max98373->tdm_mode = true;
>
>This should really also support disabling TDM mode - if the parameters are all >0
>just turn TDM off.  Again can be fixed in a followup.
OK. Let me apply it.
>
>> +SOC_SINGLE_TLV("DHT Gain Min", MAX98373_R20D1_DHT_CFG,
>> +MAX98373_DHT_SPK_GAIN_MIN_SHIFT, 9, 0,
>> +max98373_dht_spkgain_min_tlv), SOC_SINGLE_TLV("DHT Rot Pnt",
>MAX98373_R20D1_DHT_CFG,
>> +MAX98373_DHT_ROT_PNT_SHIFT, 15, 0,
>max98373_dht_rotation_point_tlv),
>> +SOC_SINGLE_TLV("DHT Attack Step", MAX98373_R20D2_DHT_ATTACK_CFG,
>> +MAX98373_DHT_ATTACK_STEP_SHIFT, 4, 0,
>max98373_dht_step_size_tlv),
>> +SOC_SINGLE_TLV("DHT Release Step",
>MAX98373_R20D3_DHT_RELEASE_CFG,
>> +MAX98373_DHT_RELEASE_STEP_SHIFT, 4, 0,
>max98373_dht_step_size_tlv),
>
>You should add a Volume on the end of these control names so that userspace
>knows how to display them properly; it's a little confusing as they're not
>actually gains but it tends to work out better.  Same for most of the other TLV
>controls.
OK. Thanks for your feedback.


RE: [V3 2/2] ASoC: max98373: Added Amplifier Driver

2018-01-05 Thread Ryan Lee
>-Original Message-
>From: Mark Brown [mailto:broo...@kernel.org]
>Sent: Thursday, January 4, 2018 9:14 AM
>To: Ryan Lee 
>Cc: lgirdw...@gmail.com; pe...@perex.cz; ti...@suse.com; a...@arndb.de;
>a...@ti.com; robert.jarz...@free.fr; supercraig0...@gmail.com;
>jbru...@baylibre.com; dannenb...@ti.com; romain.per...@collabora.com;
>bryce.fergu...@rockwellcollins.com; kuninori.morimoto...@renesas.com; m-
>steckl...@ti.com; alsa-de...@alsa-project.org; linux-kernel@vger.kernel.org;
>ryan.lee.ma...@gmail.com
>Subject: Re: [V3 2/2] ASoC: max98373: Added Amplifier Driver
>
>On Wed, Jan 03, 2018 at 10:39:17AM -0800, Ryan Lee wrote:
>
>This looks mostly good.  There are a few smaller issues but I think at this 
>point
>it's most sensible to apply and fix those incrementally so I'll do that, please
>follow up with patches fixing the remaining issues.

Thank you. Let me follow up with patches fixing the remaining issues.

>
>> --- /dev/null
>> +++ b/sound/soc/codecs/max98373.c
>> @@ -0,0 +1,971 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +/* Copyright (c) 2017, Maxim Integrated */
>
>SPDX headers are supposed to be C++ comments, please send a followup patch
>fixing this.
>
>> +static int max98373_get_bclk_sel(int bclk) {
>> +int i;
>> +/* match BCLKs per LRCLK */
>> +for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) {
>> +if (bclk_sel_table[i] == bclk)
>> +return i + 2;
>> +}
>> +return 0;
>> +}
>> +static int max98373_set_clock(struct snd_soc_codec *codec,
>
>Missing blank line between the functions.
OK. Thanks.
>
>> +}
>> +/* set DAI_SR to correct LRCLK frequency */
>
>Another missing blank line.
OK. Let me fix.
>
>> +static int max98373_dai_tdm_slot(struct snd_soc_dai *dai,
>> +unsigned int tx_mask, unsigned int rx_mask,
>> +int slots, int slot_width)
>> +{
>> +struct snd_soc_codec *codec = dai->codec;
>> +struct max98373_priv *max98373 =
>snd_soc_codec_get_drvdata(codec);
>> +int bsel = 0;
>> +unsigned int chan_sz = 0;
>> +unsigned int mask;
>> +int x, slot_found;
>> +
>> +max98373->tdm_mode = true;
>
>This should really also support disabling TDM mode - if the parameters are all >0
>just turn TDM off.  Again can be fixed in a followup.
OK. Let me apply it.
>
>> +SOC_SINGLE_TLV("DHT Gain Min", MAX98373_R20D1_DHT_CFG,
>> +MAX98373_DHT_SPK_GAIN_MIN_SHIFT, 9, 0,
>> +max98373_dht_spkgain_min_tlv), SOC_SINGLE_TLV("DHT Rot Pnt",
>MAX98373_R20D1_DHT_CFG,
>> +MAX98373_DHT_ROT_PNT_SHIFT, 15, 0,
>max98373_dht_rotation_point_tlv),
>> +SOC_SINGLE_TLV("DHT Attack Step", MAX98373_R20D2_DHT_ATTACK_CFG,
>> +MAX98373_DHT_ATTACK_STEP_SHIFT, 4, 0,
>max98373_dht_step_size_tlv),
>> +SOC_SINGLE_TLV("DHT Release Step",
>MAX98373_R20D3_DHT_RELEASE_CFG,
>> +MAX98373_DHT_RELEASE_STEP_SHIFT, 4, 0,
>max98373_dht_step_size_tlv),
>
>You should add a Volume on the end of these control names so that userspace
>knows how to display them properly; it's a little confusing as they're not
>actually gains but it tends to work out better.  Same for most of the other TLV
>controls.
OK. Thanks for your feedback.


[V3 2/2] ASoC: max98373: Added Amplifier Driver

2018-01-03 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
Changes since v2:
* Splitted dt bindings to the separated patch
* Changed 'interelave-mode' device property from u32 to boolean

Changes since v1:
* Removed 'codec' from 'max98373_priv' structure
: Now 'max98373_set_clock' function use 'dai->codec.dev' 
instead of using 'max98373->codec.dev'.
* Removed 'max98373_dai_set_sysclk' function
: This function is not necessary. Removed 'sysclk' from 
'max98373_priv' as well.
* Removed 'iface' from 'max98373_priv' structure
: There is no function who refer max98373->iface variable.
* Added SPDX-License-Identifier

 sound/soc/codecs/Kconfig|   5 +
 sound/soc/codecs/Makefile   |   2 +
 sound/soc/codecs/max98373.c | 971 
 sound/soc/codecs/max98373.h | 212 ++
 4 files changed, 1190 insertions(+)
 create mode 100644 sound/soc/codecs/max98373.c
 create mode 100644 sound/soc/codecs/max98373.h

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 8b02bc8..9af2588 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -95,6 +95,7 @@ config SND_SOC_ALL_CODECS
select SND_SOC_MAX98925 if I2C
select SND_SOC_MAX98926 if I2C
select SND_SOC_MAX98927 if I2C
+   select SND_SOC_MAX98373 if I2C
select SND_SOC_MAX9850 if I2C
select SND_SOC_MAX9860 if I2C
select SND_SOC_MAX9768 if I2C
@@ -626,6 +627,10 @@ config SND_SOC_MAX98927
tristate "Maxim Integrated MAX98927 Speaker Amplifier"
depends on I2C
 
+config SND_SOC_MAX98373
+   tristate "Maxim Integrated MAX98373 Speaker Amplifier"
+   depends on I2C
+
 config SND_SOC_MAX9850
tristate
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 0977349..49db8e9 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -90,6 +90,7 @@ snd-soc-max9867-objs := max9867.o
 snd-soc-max98925-objs := max98925.o
 snd-soc-max98926-objs := max98926.o
 snd-soc-max98927-objs := max98927.o
+snd-soc-max98373-objs := max98373.o
 snd-soc-max9850-objs := max9850.o
 snd-soc-max9860-objs := max9860.o
 snd-soc-mc13783-objs := mc13783.o
@@ -334,6 +335,7 @@ obj-$(CONFIG_SND_SOC_MAX9867)   += snd-soc-max9867.o
 obj-$(CONFIG_SND_SOC_MAX98925) += snd-soc-max98925.o
 obj-$(CONFIG_SND_SOC_MAX98926) += snd-soc-max98926.o
 obj-$(CONFIG_SND_SOC_MAX98927) += snd-soc-max98927.o
+obj-$(CONFIG_SND_SOC_MAX98373) += snd-soc-max98373.o
 obj-$(CONFIG_SND_SOC_MAX9850)  += snd-soc-max9850.o
 obj-$(CONFIG_SND_SOC_MAX9860)  += snd-soc-max9860.o
 obj-$(CONFIG_SND_SOC_MC13783)  += snd-soc-mc13783.o
diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
new file mode 100644
index 000..9af0d98
--- /dev/null
+++ b/sound/soc/codecs/max98373.c
@@ -0,0 +1,971 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2017, Maxim Integrated */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "max98373.h"
+
+static struct reg_default max98373_reg[] = {
+   {MAX98373_R2000_SW_RESET, 0x00},
+   {MAX98373_R2001_INT_RAW1, 0x00},
+   {MAX98373_R2002_INT_RAW2, 0x00},
+   {MAX98373_R2003_INT_RAW3, 0x00},
+   {MAX98373_R2004_INT_STATE1, 0x00},
+   {MAX98373_R2005_INT_STATE2, 0x00},
+   {MAX98373_R2006_INT_STATE3, 0x00},
+   {MAX98373_R2007_INT_FLAG1, 0x00},
+   {MAX98373_R2008_INT_FLAG2, 0x00},
+   {MAX98373_R2009_INT_FLAG3, 0x00},
+   {MAX98373_R200A_INT_EN1, 0x00},
+   {MAX98373_R200B_INT_EN2, 0x00},
+   {MAX98373_R200C_INT_EN3, 0x00},
+   {MAX98373_R200D_INT_FLAG_CLR1, 0x00},
+   {MAX98373_R200E_INT_FLAG_CLR2, 0x00},
+   {MAX98373_R200F_INT_FLAG_CLR3, 0x00},
+   {MAX98373_R2010_IRQ_CTRL, 0x00},
+   {MAX98373_R2014_THERM_WARN_THRESH, 0x10},
+   {MAX98373_R2015_THERM_SHDN_THRESH, 0x27},
+   {MAX98373_R2016_THERM_HYSTERESIS, 0x01},
+   {MAX98373_R2017_THERM_FOLDBACK_SET, 0xC0},
+   {MAX98373_R2018_THERM_FOLDBACK_EN, 0x00},
+   {MAX98373_R201E_PIN_DRIVE_STRENGTH, 0x55},
+   {MAX98373_R2020_PCM_TX_HIZ_EN_1, 0xFE},
+   {MAX98373_R2021_PCM_TX_HIZ_EN_2, 0xFF},
+   {MAX98373_R2022_PCM_TX_SRC_1, 0x00},
+   {MAX98373_R2023_PCM_TX_SRC_2, 0x00},
+   {MAX98373_R2024_PCM_DATA_FMT_CFG, 0xC0},
+   {MAX98373_R2025_AUDIO_IF_MODE, 0x00},
+   {MAX98373_R2026_PCM_CLOCK_RATIO, 0x04},
+   {MAX98373_R2027_PCM_SR_SETUP_1, 0x08},
+   {MAX98373_R2028_PCM_SR_SETUP_2, 0x88},
+   {MAX98373_R2029_PCM_TO_SPK_MONO_MIX_1, 0x00},
+   {MAX98373_R202A_PCM_TO_SPK_MONO_MIX_2, 0x00},
+   {MAX98373_R202B_PCM_RX_EN, 0x00},
+   {MAX98373_R202C_PCM_TX_EN, 0x00},
+   {MAX98373_R202E_ICC_RX_CH_EN_1, 0x00},
+   {MAX98373_R202F_ICC_RX_CH_EN_2, 0x00},

[V3 2/2] ASoC: max98373: Added Amplifier Driver

2018-01-03 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changes since v2:
* Splitted dt bindings to the separated patch
* Changed 'interelave-mode' device property from u32 to boolean

Changes since v1:
* Removed 'codec' from 'max98373_priv' structure
: Now 'max98373_set_clock' function use 'dai->codec.dev' 
instead of using 'max98373->codec.dev'.
* Removed 'max98373_dai_set_sysclk' function
: This function is not necessary. Removed 'sysclk' from 
'max98373_priv' as well.
* Removed 'iface' from 'max98373_priv' structure
: There is no function who refer max98373->iface variable.
* Added SPDX-License-Identifier

 sound/soc/codecs/Kconfig|   5 +
 sound/soc/codecs/Makefile   |   2 +
 sound/soc/codecs/max98373.c | 971 
 sound/soc/codecs/max98373.h | 212 ++
 4 files changed, 1190 insertions(+)
 create mode 100644 sound/soc/codecs/max98373.c
 create mode 100644 sound/soc/codecs/max98373.h

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 8b02bc8..9af2588 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -95,6 +95,7 @@ config SND_SOC_ALL_CODECS
select SND_SOC_MAX98925 if I2C
select SND_SOC_MAX98926 if I2C
select SND_SOC_MAX98927 if I2C
+   select SND_SOC_MAX98373 if I2C
select SND_SOC_MAX9850 if I2C
select SND_SOC_MAX9860 if I2C
select SND_SOC_MAX9768 if I2C
@@ -626,6 +627,10 @@ config SND_SOC_MAX98927
tristate "Maxim Integrated MAX98927 Speaker Amplifier"
depends on I2C
 
+config SND_SOC_MAX98373
+   tristate "Maxim Integrated MAX98373 Speaker Amplifier"
+   depends on I2C
+
 config SND_SOC_MAX9850
tristate
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 0977349..49db8e9 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -90,6 +90,7 @@ snd-soc-max9867-objs := max9867.o
 snd-soc-max98925-objs := max98925.o
 snd-soc-max98926-objs := max98926.o
 snd-soc-max98927-objs := max98927.o
+snd-soc-max98373-objs := max98373.o
 snd-soc-max9850-objs := max9850.o
 snd-soc-max9860-objs := max9860.o
 snd-soc-mc13783-objs := mc13783.o
@@ -334,6 +335,7 @@ obj-$(CONFIG_SND_SOC_MAX9867)   += snd-soc-max9867.o
 obj-$(CONFIG_SND_SOC_MAX98925) += snd-soc-max98925.o
 obj-$(CONFIG_SND_SOC_MAX98926) += snd-soc-max98926.o
 obj-$(CONFIG_SND_SOC_MAX98927) += snd-soc-max98927.o
+obj-$(CONFIG_SND_SOC_MAX98373) += snd-soc-max98373.o
 obj-$(CONFIG_SND_SOC_MAX9850)  += snd-soc-max9850.o
 obj-$(CONFIG_SND_SOC_MAX9860)  += snd-soc-max9860.o
 obj-$(CONFIG_SND_SOC_MC13783)  += snd-soc-mc13783.o
diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
new file mode 100644
index 000..9af0d98
--- /dev/null
+++ b/sound/soc/codecs/max98373.c
@@ -0,0 +1,971 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2017, Maxim Integrated */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "max98373.h"
+
+static struct reg_default max98373_reg[] = {
+   {MAX98373_R2000_SW_RESET, 0x00},
+   {MAX98373_R2001_INT_RAW1, 0x00},
+   {MAX98373_R2002_INT_RAW2, 0x00},
+   {MAX98373_R2003_INT_RAW3, 0x00},
+   {MAX98373_R2004_INT_STATE1, 0x00},
+   {MAX98373_R2005_INT_STATE2, 0x00},
+   {MAX98373_R2006_INT_STATE3, 0x00},
+   {MAX98373_R2007_INT_FLAG1, 0x00},
+   {MAX98373_R2008_INT_FLAG2, 0x00},
+   {MAX98373_R2009_INT_FLAG3, 0x00},
+   {MAX98373_R200A_INT_EN1, 0x00},
+   {MAX98373_R200B_INT_EN2, 0x00},
+   {MAX98373_R200C_INT_EN3, 0x00},
+   {MAX98373_R200D_INT_FLAG_CLR1, 0x00},
+   {MAX98373_R200E_INT_FLAG_CLR2, 0x00},
+   {MAX98373_R200F_INT_FLAG_CLR3, 0x00},
+   {MAX98373_R2010_IRQ_CTRL, 0x00},
+   {MAX98373_R2014_THERM_WARN_THRESH, 0x10},
+   {MAX98373_R2015_THERM_SHDN_THRESH, 0x27},
+   {MAX98373_R2016_THERM_HYSTERESIS, 0x01},
+   {MAX98373_R2017_THERM_FOLDBACK_SET, 0xC0},
+   {MAX98373_R2018_THERM_FOLDBACK_EN, 0x00},
+   {MAX98373_R201E_PIN_DRIVE_STRENGTH, 0x55},
+   {MAX98373_R2020_PCM_TX_HIZ_EN_1, 0xFE},
+   {MAX98373_R2021_PCM_TX_HIZ_EN_2, 0xFF},
+   {MAX98373_R2022_PCM_TX_SRC_1, 0x00},
+   {MAX98373_R2023_PCM_TX_SRC_2, 0x00},
+   {MAX98373_R2024_PCM_DATA_FMT_CFG, 0xC0},
+   {MAX98373_R2025_AUDIO_IF_MODE, 0x00},
+   {MAX98373_R2026_PCM_CLOCK_RATIO, 0x04},
+   {MAX98373_R2027_PCM_SR_SETUP_1, 0x08},
+   {MAX98373_R2028_PCM_SR_SETUP_2, 0x88},
+   {MAX98373_R2029_PCM_TO_SPK_MONO_MIX_1, 0x00},
+   {MAX98373_R202A_PCM_TO_SPK_MONO_MIX_2, 0x00},
+   {MAX98373_R202B_PCM_RX_EN, 0x00},
+   {MAX98373_R202C_PCM_TX_EN, 0x00},
+   {MAX98373_R202E_ICC_RX_CH_EN_1, 0x00},
+   {MAX98373_R202F_ICC_RX_CH_EN_2, 0x00},
+   {MAX98373_R2030_ICC_TX_HIZ_EN_1, 0xFF},
+ 

[V3 1/2] dt-bindings: Added device tree binding for max98373 amplifier

2018-01-03 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
Changes since v2:
* Splitted dt bindings to the separated patch
* Changed 'interelave-mode' device property from u32 to boolean

 .../devicetree/bindings/sound/max98373.txt | 40 ++
 1 file changed, 40 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/max98373.txt

diff --git a/Documentation/devicetree/bindings/sound/max98373.txt 
b/Documentation/devicetree/bindings/sound/max98373.txt
new file mode 100644
index 000..456cb1c
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/max98373.txt
@@ -0,0 +1,40 @@
+Maxim Integrated MAX98373 Speaker Amplifier
+
+This device supports I2C.
+
+Required properties:
+
+ - compatible : "maxim,max98373"
+
+ - reg : the I2C address of the device.
+
+Optional properties:
+
+  - maxim,vmon-slot-no : slot number used to send voltage information
+   or in inteleave mode this will be used as
+   interleave slot.
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,imon-slot-no : slot number used to send current information
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,spkfb-slot-no : slot number used to send speaker feedback information
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,interleave-mode : For cases where a single combined channel
+  for the I/V sense data is not sufficient, the device can 
also be configured
+  to share a single data output channel on alternating frames.
+  In this configuration, the current and voltage data will be 
frame interleaved
+  on a single output channel.
+   Boolean, define to enable the interleave mode, Default : 
false
+
+Example:
+
+codec: max98373@31 {
+   compatible = "maxim,max98373";
+   reg = <0x31>;
+   maxim,vmon-slot-no = <0>;
+   maxim,imon-slot-no = <1>;
+   maxim,spkfb-slot-no = <2>;
+   maxim,interleave-mode;
+};
-- 
2.7.4



[V3 1/2] dt-bindings: Added device tree binding for max98373 amplifier

2018-01-03 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changes since v2:
* Splitted dt bindings to the separated patch
* Changed 'interelave-mode' device property from u32 to boolean

 .../devicetree/bindings/sound/max98373.txt | 40 ++
 1 file changed, 40 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/max98373.txt

diff --git a/Documentation/devicetree/bindings/sound/max98373.txt 
b/Documentation/devicetree/bindings/sound/max98373.txt
new file mode 100644
index 000..456cb1c
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/max98373.txt
@@ -0,0 +1,40 @@
+Maxim Integrated MAX98373 Speaker Amplifier
+
+This device supports I2C.
+
+Required properties:
+
+ - compatible : "maxim,max98373"
+
+ - reg : the I2C address of the device.
+
+Optional properties:
+
+  - maxim,vmon-slot-no : slot number used to send voltage information
+   or in inteleave mode this will be used as
+   interleave slot.
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,imon-slot-no : slot number used to send current information
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,spkfb-slot-no : slot number used to send speaker feedback information
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,interleave-mode : For cases where a single combined channel
+  for the I/V sense data is not sufficient, the device can 
also be configured
+  to share a single data output channel on alternating frames.
+  In this configuration, the current and voltage data will be 
frame interleaved
+  on a single output channel.
+   Boolean, define to enable the interleave mode, Default : 
false
+
+Example:
+
+codec: max98373@31 {
+   compatible = "maxim,max98373";
+   reg = <0x31>;
+   maxim,vmon-slot-no = <0>;
+   maxim,imon-slot-no = <1>;
+   maxim,spkfb-slot-no = <2>;
+   maxim,interleave-mode;
+};
-- 
2.7.4



RE: [v2] ASoC: max98373: Added Amplifier Driver

2018-01-03 Thread Ryan Lee

>-Original Message-
>From: Rob Herring [mailto:r...@kernel.org]
>Sent: Tuesday, December 26, 2017 3:33 PM
>To: Ryan Lee <ryans@maximintegrated.com>
>Cc: lgirdw...@gmail.com; broo...@kernel.org; mark.rutl...@arm.com;
>pe...@perex.cz; ti...@suse.com; a...@arndb.de; a...@ti.com;
>robert.jarz...@free.fr; supercraig0...@gmail.com; jbru...@baylibre.com;
>dannenb...@ti.com; romain.per...@collabora.com;
>bryce.fergu...@rockwellcollins.com; kuninori.morimoto...@renesas.com; m-
>steckl...@ti.com; alsa-de...@alsa-project.org; devicet...@vger.kernel.org;
>linux-kernel@vger.kernel.org; ryan.lee.ma...@gmail.com
>Subject: Re: [v2] ASoC: max98373: Added Amplifier Driver
>
>EXTERNAL EMAIL
>
>
>
>On Mon, Dec 25, 2017 at 07:10:10AM -0800, Ryan Lee wrote:
>
>Needs a commit message.
>
>> Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
>> ---
>>
>> Changes since v1:
>>   * Removed 'codec' from 'max98373_priv' structure
>>   : Now 'max98373_set_clock' function use 'dai->codec.dev' 
>> instead of
>using 'max98373->codec.dev'.
>>   * Removed 'max98373_dai_set_sysclk' function
>>   : This function is not necessary. Removed 'sysclk' from
>'max98373_priv' as well.
>>   * Removed 'iface' from 'max98373_priv' structure
>>   : There is no function who refer max98373->iface variable.
>>   * Added SPDX-License-Identifier
>>
>>  .../devicetree/bindings/sound/max98373.txt |  43 +
>
>Please split bindings to separate patch.
Thank you for the feedback.
I will split it.

>
>>  sound/soc/codecs/Kconfig   |   5 +
>>  sound/soc/codecs/Makefile  |   2 +
>>  sound/soc/codecs/max98373.c| 974
>+
>>  sound/soc/codecs/max98373.h| 212 +
>>  5 files changed, 1236 insertions(+)
>>  create mode 100644
>> Documentation/devicetree/bindings/sound/max98373.txt
>>  create mode 100644 sound/soc/codecs/max98373.c  create mode 100644
>> sound/soc/codecs/max98373.h
>>
>> diff --git a/Documentation/devicetree/bindings/sound/max98373.txt
>> b/Documentation/devicetree/bindings/sound/max98373.txt
>> new file mode 100644
>> index 000..22cd259
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/sound/max98373.txt
>> @@ -0,0 +1,43 @@
>> +Maxim Integrated MAX98373 Speaker Amplifier
>> +
>> +This device supports I2C.
>> +
>> +Required properties:
>> +
>> +  - compatible : should be one of the following
>> +- "maxim,max98373"
>> +
>> +  - reg : the I2C address of the device.
>> +
>> +Optional properties:
>> +
>> +  - maxim,vmon-slot-no : slot number used to send voltage information
>> +   or in inteleave mode this will be used as
>> +   interleave slot.
>> +   slot range : 0 ~ 15,  Default : 0
>> +
>> +  - maxim,imon-slot-no : slot number used to send current information
>> +   slot range : 0 ~ 15,  Default : 0
>> +
>> +  - maxim,spkfb-slot-no : slot number used to send speaker feedback
>information
>> +   slot range : 0 ~ 15,  Default : 0
>> +
>> +  - maxim,interleave-mode : When using two MAX98373 in a system it is
>> +   possible to create ADC data that that will
>> +   overflow the frame size. Digital Audio Interleave
>> +   mode provides a means to output VMON and IMON data
>> +   from two devices on a single DOUT line when running
>> +   smaller frames sizes such as 32 BCLKS per LRCLK or
>> +   48 BCLKS per LRCLK.
>> +   Range : 0 (off), 1 (on),  Default : 0
>
>This can be boolean instead.
I will change this to boolean type.
>
>> +
>> +Example:
>> +
>> +codec: max98373@31 {
>> +   compatible = "maxim,max98373";
>> +   reg = <0x31>;
>> +   maxim,vmon-slot-no = <0>;
>> +   maxim,imon-slot-no = <1>;
>> +   maxim,spkfb-slot-no = <2>;
>> +   maxim,interleave-mode = <0>;
>> +};


RE: [v2] ASoC: max98373: Added Amplifier Driver

2018-01-03 Thread Ryan Lee

>-Original Message-
>From: Rob Herring [mailto:r...@kernel.org]
>Sent: Tuesday, December 26, 2017 3:33 PM
>To: Ryan Lee 
>Cc: lgirdw...@gmail.com; broo...@kernel.org; mark.rutl...@arm.com;
>pe...@perex.cz; ti...@suse.com; a...@arndb.de; a...@ti.com;
>robert.jarz...@free.fr; supercraig0...@gmail.com; jbru...@baylibre.com;
>dannenb...@ti.com; romain.per...@collabora.com;
>bryce.fergu...@rockwellcollins.com; kuninori.morimoto...@renesas.com; m-
>steckl...@ti.com; alsa-de...@alsa-project.org; devicet...@vger.kernel.org;
>linux-kernel@vger.kernel.org; ryan.lee.ma...@gmail.com
>Subject: Re: [v2] ASoC: max98373: Added Amplifier Driver
>
>EXTERNAL EMAIL
>
>
>
>On Mon, Dec 25, 2017 at 07:10:10AM -0800, Ryan Lee wrote:
>
>Needs a commit message.
>
>> Signed-off-by: Ryan Lee 
>> ---
>>
>> Changes since v1:
>>   * Removed 'codec' from 'max98373_priv' structure
>>   : Now 'max98373_set_clock' function use 'dai->codec.dev' 
>> instead of
>using 'max98373->codec.dev'.
>>   * Removed 'max98373_dai_set_sysclk' function
>>   : This function is not necessary. Removed 'sysclk' from
>'max98373_priv' as well.
>>   * Removed 'iface' from 'max98373_priv' structure
>>   : There is no function who refer max98373->iface variable.
>>   * Added SPDX-License-Identifier
>>
>>  .../devicetree/bindings/sound/max98373.txt |  43 +
>
>Please split bindings to separate patch.
Thank you for the feedback.
I will split it.

>
>>  sound/soc/codecs/Kconfig   |   5 +
>>  sound/soc/codecs/Makefile  |   2 +
>>  sound/soc/codecs/max98373.c| 974
>+
>>  sound/soc/codecs/max98373.h| 212 +
>>  5 files changed, 1236 insertions(+)
>>  create mode 100644
>> Documentation/devicetree/bindings/sound/max98373.txt
>>  create mode 100644 sound/soc/codecs/max98373.c  create mode 100644
>> sound/soc/codecs/max98373.h
>>
>> diff --git a/Documentation/devicetree/bindings/sound/max98373.txt
>> b/Documentation/devicetree/bindings/sound/max98373.txt
>> new file mode 100644
>> index 000..22cd259
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/sound/max98373.txt
>> @@ -0,0 +1,43 @@
>> +Maxim Integrated MAX98373 Speaker Amplifier
>> +
>> +This device supports I2C.
>> +
>> +Required properties:
>> +
>> +  - compatible : should be one of the following
>> +- "maxim,max98373"
>> +
>> +  - reg : the I2C address of the device.
>> +
>> +Optional properties:
>> +
>> +  - maxim,vmon-slot-no : slot number used to send voltage information
>> +   or in inteleave mode this will be used as
>> +   interleave slot.
>> +   slot range : 0 ~ 15,  Default : 0
>> +
>> +  - maxim,imon-slot-no : slot number used to send current information
>> +   slot range : 0 ~ 15,  Default : 0
>> +
>> +  - maxim,spkfb-slot-no : slot number used to send speaker feedback
>information
>> +   slot range : 0 ~ 15,  Default : 0
>> +
>> +  - maxim,interleave-mode : When using two MAX98373 in a system it is
>> +   possible to create ADC data that that will
>> +   overflow the frame size. Digital Audio Interleave
>> +   mode provides a means to output VMON and IMON data
>> +   from two devices on a single DOUT line when running
>> +   smaller frames sizes such as 32 BCLKS per LRCLK or
>> +   48 BCLKS per LRCLK.
>> +   Range : 0 (off), 1 (on),  Default : 0
>
>This can be boolean instead.
I will change this to boolean type.
>
>> +
>> +Example:
>> +
>> +codec: max98373@31 {
>> +   compatible = "maxim,max98373";
>> +   reg = <0x31>;
>> +   maxim,vmon-slot-no = <0>;
>> +   maxim,imon-slot-no = <1>;
>> +   maxim,spkfb-slot-no = <2>;
>> +   maxim,interleave-mode = <0>;
>> +};


[v2] ASoC: max98373: Added Amplifier Driver

2017-12-25 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---

Changes since v1:
* Removed 'codec' from 'max98373_priv' structure
: Now 'max98373_set_clock' function use 'dai->codec.dev' 
instead of using 'max98373->codec.dev'.
* Removed 'max98373_dai_set_sysclk' function
: This function is not necessary. Removed 'sysclk' from 
'max98373_priv' as well.
* Removed 'iface' from 'max98373_priv' structure
: There is no function who refer max98373->iface variable.
* Added SPDX-License-Identifier

 .../devicetree/bindings/sound/max98373.txt |  43 +
 sound/soc/codecs/Kconfig   |   5 +
 sound/soc/codecs/Makefile  |   2 +
 sound/soc/codecs/max98373.c| 974 +
 sound/soc/codecs/max98373.h| 212 +
 5 files changed, 1236 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/max98373.txt
 create mode 100644 sound/soc/codecs/max98373.c
 create mode 100644 sound/soc/codecs/max98373.h

diff --git a/Documentation/devicetree/bindings/sound/max98373.txt 
b/Documentation/devicetree/bindings/sound/max98373.txt
new file mode 100644
index 000..22cd259
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/max98373.txt
@@ -0,0 +1,43 @@
+Maxim Integrated MAX98373 Speaker Amplifier
+
+This device supports I2C.
+
+Required properties:
+
+  - compatible : should be one of the following
+- "maxim,max98373"
+
+  - reg : the I2C address of the device.
+
+Optional properties:
+
+  - maxim,vmon-slot-no : slot number used to send voltage information
+   or in inteleave mode this will be used as
+   interleave slot.
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,imon-slot-no : slot number used to send current information
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,spkfb-slot-no : slot number used to send speaker feedback information
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,interleave-mode : When using two MAX98373 in a system it is
+   possible to create ADC data that that will
+   overflow the frame size. Digital Audio Interleave
+   mode provides a means to output VMON and IMON data
+   from two devices on a single DOUT line when running
+   smaller frames sizes such as 32 BCLKS per LRCLK or
+   48 BCLKS per LRCLK.
+   Range : 0 (off), 1 (on),  Default : 0
+
+Example:
+
+codec: max98373@31 {
+   compatible = "maxim,max98373";
+   reg = <0x31>;
+   maxim,vmon-slot-no = <0>;
+   maxim,imon-slot-no = <1>;
+   maxim,spkfb-slot-no = <2>;
+   maxim,interleave-mode = <0>;
+};
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 8b02bc8..9af2588 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -95,6 +95,7 @@ config SND_SOC_ALL_CODECS
select SND_SOC_MAX98925 if I2C
select SND_SOC_MAX98926 if I2C
select SND_SOC_MAX98927 if I2C
+   select SND_SOC_MAX98373 if I2C
select SND_SOC_MAX9850 if I2C
select SND_SOC_MAX9860 if I2C
select SND_SOC_MAX9768 if I2C
@@ -626,6 +627,10 @@ config SND_SOC_MAX98927
tristate "Maxim Integrated MAX98927 Speaker Amplifier"
depends on I2C
 
+config SND_SOC_MAX98373
+   tristate "Maxim Integrated MAX98373 Speaker Amplifier"
+   depends on I2C
+
 config SND_SOC_MAX9850
tristate
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 0977349..49db8e9 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -90,6 +90,7 @@ snd-soc-max9867-objs := max9867.o
 snd-soc-max98925-objs := max98925.o
 snd-soc-max98926-objs := max98926.o
 snd-soc-max98927-objs := max98927.o
+snd-soc-max98373-objs := max98373.o
 snd-soc-max9850-objs := max9850.o
 snd-soc-max9860-objs := max9860.o
 snd-soc-mc13783-objs := mc13783.o
@@ -334,6 +335,7 @@ obj-$(CONFIG_SND_SOC_MAX9867)   += snd-soc-max9867.o
 obj-$(CONFIG_SND_SOC_MAX98925) += snd-soc-max98925.o
 obj-$(CONFIG_SND_SOC_MAX98926) += snd-soc-max98926.o
 obj-$(CONFIG_SND_SOC_MAX98927) += snd-soc-max98927.o
+obj-$(CONFIG_SND_SOC_MAX98373) += snd-soc-max98373.o
 obj-$(CONFIG_SND_SOC_MAX9850)  += snd-soc-max9850.o
 obj-$(CONFIG_SND_SOC_MAX9860)  += snd-soc-max9860.o
 obj-$(CONFIG_SND_SOC_MC13783)  += snd-soc-mc13783.o
diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
new file mode 100644
index 000..93d6dc7
--- /dev/null
+++ b/sound/soc/codecs/max98373.c
@@ -0,0 +1,974 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2017, Maxim Integrated */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+

[v2] ASoC: max98373: Added Amplifier Driver

2017-12-25 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---

Changes since v1:
* Removed 'codec' from 'max98373_priv' structure
: Now 'max98373_set_clock' function use 'dai->codec.dev' 
instead of using 'max98373->codec.dev'.
* Removed 'max98373_dai_set_sysclk' function
: This function is not necessary. Removed 'sysclk' from 
'max98373_priv' as well.
* Removed 'iface' from 'max98373_priv' structure
: There is no function who refer max98373->iface variable.
* Added SPDX-License-Identifier

 .../devicetree/bindings/sound/max98373.txt |  43 +
 sound/soc/codecs/Kconfig   |   5 +
 sound/soc/codecs/Makefile  |   2 +
 sound/soc/codecs/max98373.c| 974 +
 sound/soc/codecs/max98373.h| 212 +
 5 files changed, 1236 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/max98373.txt
 create mode 100644 sound/soc/codecs/max98373.c
 create mode 100644 sound/soc/codecs/max98373.h

diff --git a/Documentation/devicetree/bindings/sound/max98373.txt 
b/Documentation/devicetree/bindings/sound/max98373.txt
new file mode 100644
index 000..22cd259
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/max98373.txt
@@ -0,0 +1,43 @@
+Maxim Integrated MAX98373 Speaker Amplifier
+
+This device supports I2C.
+
+Required properties:
+
+  - compatible : should be one of the following
+- "maxim,max98373"
+
+  - reg : the I2C address of the device.
+
+Optional properties:
+
+  - maxim,vmon-slot-no : slot number used to send voltage information
+   or in inteleave mode this will be used as
+   interleave slot.
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,imon-slot-no : slot number used to send current information
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,spkfb-slot-no : slot number used to send speaker feedback information
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,interleave-mode : When using two MAX98373 in a system it is
+   possible to create ADC data that that will
+   overflow the frame size. Digital Audio Interleave
+   mode provides a means to output VMON and IMON data
+   from two devices on a single DOUT line when running
+   smaller frames sizes such as 32 BCLKS per LRCLK or
+   48 BCLKS per LRCLK.
+   Range : 0 (off), 1 (on),  Default : 0
+
+Example:
+
+codec: max98373@31 {
+   compatible = "maxim,max98373";
+   reg = <0x31>;
+   maxim,vmon-slot-no = <0>;
+   maxim,imon-slot-no = <1>;
+   maxim,spkfb-slot-no = <2>;
+   maxim,interleave-mode = <0>;
+};
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 8b02bc8..9af2588 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -95,6 +95,7 @@ config SND_SOC_ALL_CODECS
select SND_SOC_MAX98925 if I2C
select SND_SOC_MAX98926 if I2C
select SND_SOC_MAX98927 if I2C
+   select SND_SOC_MAX98373 if I2C
select SND_SOC_MAX9850 if I2C
select SND_SOC_MAX9860 if I2C
select SND_SOC_MAX9768 if I2C
@@ -626,6 +627,10 @@ config SND_SOC_MAX98927
tristate "Maxim Integrated MAX98927 Speaker Amplifier"
depends on I2C
 
+config SND_SOC_MAX98373
+   tristate "Maxim Integrated MAX98373 Speaker Amplifier"
+   depends on I2C
+
 config SND_SOC_MAX9850
tristate
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 0977349..49db8e9 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -90,6 +90,7 @@ snd-soc-max9867-objs := max9867.o
 snd-soc-max98925-objs := max98925.o
 snd-soc-max98926-objs := max98926.o
 snd-soc-max98927-objs := max98927.o
+snd-soc-max98373-objs := max98373.o
 snd-soc-max9850-objs := max9850.o
 snd-soc-max9860-objs := max9860.o
 snd-soc-mc13783-objs := mc13783.o
@@ -334,6 +335,7 @@ obj-$(CONFIG_SND_SOC_MAX9867)   += snd-soc-max9867.o
 obj-$(CONFIG_SND_SOC_MAX98925) += snd-soc-max98925.o
 obj-$(CONFIG_SND_SOC_MAX98926) += snd-soc-max98926.o
 obj-$(CONFIG_SND_SOC_MAX98927) += snd-soc-max98927.o
+obj-$(CONFIG_SND_SOC_MAX98373) += snd-soc-max98373.o
 obj-$(CONFIG_SND_SOC_MAX9850)  += snd-soc-max9850.o
 obj-$(CONFIG_SND_SOC_MAX9860)  += snd-soc-max9860.o
 obj-$(CONFIG_SND_SOC_MC13783)  += snd-soc-mc13783.o
diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
new file mode 100644
index 000..93d6dc7
--- /dev/null
+++ b/sound/soc/codecs/max98373.c
@@ -0,0 +1,974 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2017, Maxim Integrated */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "max98373.h&quo

RE: [PATCH] ASoC: max98373: Added Amplifier Driver

2017-12-25 Thread Ryan Lee
Hi Philppe Ombredanne,

>-Original Message-
>From: Philippe Ombredanne [mailto:pombreda...@nexb.com]
>Sent: Friday, December 22, 2017 12:39 AM
>To: Ryan Lee <ryans@maximintegrated.com>
>Cc: Liam Girdwood <lgirdw...@gmail.com>; Mark <broo...@kernel.org>;
>Rob Herring <robh...@kernel.org>; Mark Rutland <mark.rutl...@arm.com>;
>Jaroslav Kysela <pe...@perex.cz>; Takashi Iwai <ti...@suse.com>; Arnd
>Bergmann <a...@arndb.de>; a...@ti.com; robert.jarz...@free.fr;
>supercraig0...@gmail.com; jbru...@baylibre.com; dannenb...@ti.com;
>Romain Perier <romain.per...@collabora.com>;
>bryce.fergu...@rockwellcollins.com; kuninori.morimoto...@renesas.com; m-
>steckl...@ti.com; ALSA <alsa-de...@alsa-project.org>; open list:OPEN
>FIRMWARE AND FLATTENED DEVICE TREE BINDINGS
><devicet...@vger.kernel.org>; LKML <linux-kernel@vger.kernel.org>;
>ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH] ASoC: max98373: Added Amplifier Driver
>
>EXTERNAL EMAIL
>
>
>
>Ryan,
>
>On Fri, Dec 22, 2017 at 2:43 AM, Ryan Lee <ryans@maximintegrated.com>
>wrote:
>> Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
>> ---
>>
>> Created max98373 amplifier driver.
>>
>
>
>
>> --- /dev/null
>> +++ b/sound/soc/codecs/max98373.c
>> @@ -0,0 +1,996 @@
>> +/*
>> + * max98373.c  --  MAX98373 ALSA Soc Audio driver
>> + *
>> + * Copyright (C) 2017 Maxim Integrated Products
>> + * Author: Ryan Lee <ryans@maximintegrated.com>
>> + *
>> + *  This program is free software; you can redistribute  it and/or
>> +modify it
>> + *  under  the terms of  the GNU General  Public License as published
>> +by the
>> + *  Free Software Foundation;  either version 2 of the  License, or
>> +(at your
>> + *  option) any later version.
>> + */
>
>Have you considered using the new SPDX tags instead of this fine but long
>legalese?
>
>And if other contributors in your team could follow suit and you could spread
>the word that would be even better!
>
>See Thomas doc patches [1] for details.
>Thanks!
>
>[1]
>https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flkml.org%
>2Flkml%2F2017%2F12%2F4%2F934=01%7C01%7Cryans.lee%40maximint
>egrated.com%7Cd26ec4859b2240fb0a6008d549178c4f%7Cfbd909dfea69478
>8a554f24b7854ad03%7C0=dTVH044XPox7EPR0WU1IGMlLxaWBDl80%
>2B%2FVYhwu51y0%3D=0
>
Thanks for your feedback. I will follow this.
>--
>Cordially
>Philippe Ombredanne


RE: [PATCH] ASoC: max98373: Added Amplifier Driver

2017-12-25 Thread Ryan Lee
Hi Philppe Ombredanne,

>-Original Message-
>From: Philippe Ombredanne [mailto:pombreda...@nexb.com]
>Sent: Friday, December 22, 2017 12:39 AM
>To: Ryan Lee 
>Cc: Liam Girdwood ; Mark ;
>Rob Herring ; Mark Rutland ;
>Jaroslav Kysela ; Takashi Iwai ; Arnd
>Bergmann ; a...@ti.com; robert.jarz...@free.fr;
>supercraig0...@gmail.com; jbru...@baylibre.com; dannenb...@ti.com;
>Romain Perier ;
>bryce.fergu...@rockwellcollins.com; kuninori.morimoto...@renesas.com; m-
>steckl...@ti.com; ALSA ; open list:OPEN
>FIRMWARE AND FLATTENED DEVICE TREE BINDINGS
>; LKML ;
>ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH] ASoC: max98373: Added Amplifier Driver
>
>EXTERNAL EMAIL
>
>
>
>Ryan,
>
>On Fri, Dec 22, 2017 at 2:43 AM, Ryan Lee 
>wrote:
>> Signed-off-by: Ryan Lee 
>> ---
>>
>> Created max98373 amplifier driver.
>>
>
>
>
>> --- /dev/null
>> +++ b/sound/soc/codecs/max98373.c
>> @@ -0,0 +1,996 @@
>> +/*
>> + * max98373.c  --  MAX98373 ALSA Soc Audio driver
>> + *
>> + * Copyright (C) 2017 Maxim Integrated Products
>> + * Author: Ryan Lee 
>> + *
>> + *  This program is free software; you can redistribute  it and/or
>> +modify it
>> + *  under  the terms of  the GNU General  Public License as published
>> +by the
>> + *  Free Software Foundation;  either version 2 of the  License, or
>> +(at your
>> + *  option) any later version.
>> + */
>
>Have you considered using the new SPDX tags instead of this fine but long
>legalese?
>
>And if other contributors in your team could follow suit and you could spread
>the word that would be even better!
>
>See Thomas doc patches [1] for details.
>Thanks!
>
>[1]
>https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flkml.org%
>2Flkml%2F2017%2F12%2F4%2F934=01%7C01%7Cryans.lee%40maximint
>egrated.com%7Cd26ec4859b2240fb0a6008d549178c4f%7Cfbd909dfea69478
>8a554f24b7854ad03%7C0=dTVH044XPox7EPR0WU1IGMlLxaWBDl80%
>2B%2FVYhwu51y0%3D=0
>
Thanks for your feedback. I will follow this.
>--
>Cordially
>Philippe Ombredanne


RE: [PATCH] ASoC: max98373: Added Amplifier Driver

2017-12-25 Thread Ryan Lee
Hi Kuninori Miromoto,

>-Original Message-
>From: Kuninori Morimoto [mailto:kuninori.morimoto...@renesas.com]
>Sent: Thursday, December 21, 2017 6:24 PM
>To: Ryan Lee <ryans@maximintegrated.com>
>Cc: lgirdw...@gmail.com; broo...@kernel.org; robh...@kernel.org;
>mark.rutl...@arm.com; pe...@perex.cz; ti...@suse.com; a...@arndb.de;
>a...@ti.com; robert.jarz...@free.fr; supercraig0...@gmail.com;
>jbru...@baylibre.com; dannenb...@ti.com; romain.per...@collabora.com;
>bryce.fergu...@rockwellcollins.com; m-steckl...@ti.com; alsa-devel@alsa-
>project.org; devicet...@vger.kernel.org; linux-kernel@vger.kernel.org;
>ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH] ASoC: max98373: Added Amplifier Driver
>
>EXTERNAL EMAIL
>
>
>
>Hi Ryan
>
>> Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
>> ---
>>
>> Created max98373 amplifier driver.
>>
>>  .../devicetree/bindings/sound/max98373.txt |  43 +
>>  sound/soc/codecs/Kconfig   |   5 +
>>  sound/soc/codecs/Makefile  |   2 +
>>  sound/soc/codecs/max98373.c| 996
>+
>>  sound/soc/codecs/max98373.h| 225 +
>>  5 files changed, 1271 insertions(+)
>>  create mode 100644
>> Documentation/devicetree/bindings/sound/max98373.txt
>>  create mode 100644 sound/soc/codecs/max98373.c  create mode 100644
>> sound/soc/codecs/max98373.h
>(snip)
>> +struct max98373_priv {
>> + struct regmap *regmap;
>> + struct snd_soc_codec *codec;
>> + unsigned int sysclk;
>> + unsigned int v_slot;
>> + unsigned int i_slot;
>> + unsigned int spkfb_slot;
>> + bool interleave_mode;
>> + unsigned int ch_size;
>> + unsigned int iface;
>> + bool tdm_mode;
>> +};
>
>About this max98373->codec.
>This user is only max98373_set_clock(), and it is called from
>max98373_dai_hw_params().
>You are getting *codec from dai->codec in this function, and max98373 is
>came from it.
>This means, we can remove max98373->codec ?

Thanks for your feedback.
I will remove max98373->codec and change related things.

>
>About max98373->regmap.
>You are using devm_regmap_init_i2c(), and keeping it on max98373.
>Can you check snd_soc_component_add() which is called from
>snd_soc_add_component().
>It will set component->regmap if you called devm_regmap_init_i2c().
>I think you can use snd_soc_component_read/write instead of
>regmap_read/write.
>Then, we can remove max98373->regmap too ?
>Ahh, you want to check Revision ID.
>then, snd_soc_component_init_regmap() can help you ?

I'm sorry but I don't fully understand the benefit of this.
Keeping regmap information in private driver data is very common and I can see 
many ASoC drivers are using it.
I was able to see only a few driver use ' snd_soc_component_read'.
I would like to keep regmap_read/write if it is still acceptable.

>
>Best regards
>---
>Kuninori Morimoto


RE: [PATCH] ASoC: max98373: Added Amplifier Driver

2017-12-25 Thread Ryan Lee
Hi Kuninori Miromoto,

>-Original Message-
>From: Kuninori Morimoto [mailto:kuninori.morimoto...@renesas.com]
>Sent: Thursday, December 21, 2017 6:24 PM
>To: Ryan Lee 
>Cc: lgirdw...@gmail.com; broo...@kernel.org; robh...@kernel.org;
>mark.rutl...@arm.com; pe...@perex.cz; ti...@suse.com; a...@arndb.de;
>a...@ti.com; robert.jarz...@free.fr; supercraig0...@gmail.com;
>jbru...@baylibre.com; dannenb...@ti.com; romain.per...@collabora.com;
>bryce.fergu...@rockwellcollins.com; m-steckl...@ti.com; alsa-devel@alsa-
>project.org; devicet...@vger.kernel.org; linux-kernel@vger.kernel.org;
>ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH] ASoC: max98373: Added Amplifier Driver
>
>EXTERNAL EMAIL
>
>
>
>Hi Ryan
>
>> Signed-off-by: Ryan Lee 
>> ---
>>
>> Created max98373 amplifier driver.
>>
>>  .../devicetree/bindings/sound/max98373.txt |  43 +
>>  sound/soc/codecs/Kconfig   |   5 +
>>  sound/soc/codecs/Makefile  |   2 +
>>  sound/soc/codecs/max98373.c| 996
>+
>>  sound/soc/codecs/max98373.h| 225 +
>>  5 files changed, 1271 insertions(+)
>>  create mode 100644
>> Documentation/devicetree/bindings/sound/max98373.txt
>>  create mode 100644 sound/soc/codecs/max98373.c  create mode 100644
>> sound/soc/codecs/max98373.h
>(snip)
>> +struct max98373_priv {
>> + struct regmap *regmap;
>> + struct snd_soc_codec *codec;
>> + unsigned int sysclk;
>> + unsigned int v_slot;
>> + unsigned int i_slot;
>> + unsigned int spkfb_slot;
>> + bool interleave_mode;
>> + unsigned int ch_size;
>> + unsigned int iface;
>> + bool tdm_mode;
>> +};
>
>About this max98373->codec.
>This user is only max98373_set_clock(), and it is called from
>max98373_dai_hw_params().
>You are getting *codec from dai->codec in this function, and max98373 is
>came from it.
>This means, we can remove max98373->codec ?

Thanks for your feedback.
I will remove max98373->codec and change related things.

>
>About max98373->regmap.
>You are using devm_regmap_init_i2c(), and keeping it on max98373.
>Can you check snd_soc_component_add() which is called from
>snd_soc_add_component().
>It will set component->regmap if you called devm_regmap_init_i2c().
>I think you can use snd_soc_component_read/write instead of
>regmap_read/write.
>Then, we can remove max98373->regmap too ?
>Ahh, you want to check Revision ID.
>then, snd_soc_component_init_regmap() can help you ?

I'm sorry but I don't fully understand the benefit of this.
Keeping regmap information in private driver data is very common and I can see 
many ASoC drivers are using it.
I was able to see only a few driver use ' snd_soc_component_read'.
I would like to keep regmap_read/write if it is still acceptable.

>
>Best regards
>---
>Kuninori Morimoto


[PATCH] ASoC: max98373: Added Amplifier Driver

2017-12-21 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---

Created max98373 amplifier driver.

 .../devicetree/bindings/sound/max98373.txt |  43 +
 sound/soc/codecs/Kconfig   |   5 +
 sound/soc/codecs/Makefile  |   2 +
 sound/soc/codecs/max98373.c| 996 +
 sound/soc/codecs/max98373.h| 225 +
 5 files changed, 1271 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/max98373.txt
 create mode 100644 sound/soc/codecs/max98373.c
 create mode 100644 sound/soc/codecs/max98373.h

diff --git a/Documentation/devicetree/bindings/sound/max98373.txt 
b/Documentation/devicetree/bindings/sound/max98373.txt
new file mode 100644
index 000..22cd259
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/max98373.txt
@@ -0,0 +1,43 @@
+Maxim Integrated MAX98373 Speaker Amplifier
+
+This device supports I2C.
+
+Required properties:
+
+  - compatible : should be one of the following
+- "maxim,max98373"
+
+  - reg : the I2C address of the device.
+
+Optional properties:
+
+  - maxim,vmon-slot-no : slot number used to send voltage information
+   or in inteleave mode this will be used as
+   interleave slot.
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,imon-slot-no : slot number used to send current information
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,spkfb-slot-no : slot number used to send speaker feedback information
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,interleave-mode : When using two MAX98373 in a system it is
+   possible to create ADC data that that will
+   overflow the frame size. Digital Audio Interleave
+   mode provides a means to output VMON and IMON data
+   from two devices on a single DOUT line when running
+   smaller frames sizes such as 32 BCLKS per LRCLK or
+   48 BCLKS per LRCLK.
+   Range : 0 (off), 1 (on),  Default : 0
+
+Example:
+
+codec: max98373@31 {
+   compatible = "maxim,max98373";
+   reg = <0x31>;
+   maxim,vmon-slot-no = <0>;
+   maxim,imon-slot-no = <1>;
+   maxim,spkfb-slot-no = <2>;
+   maxim,interleave-mode = <0>;
+};
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 8b02bc8..9af2588 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -95,6 +95,7 @@ config SND_SOC_ALL_CODECS
select SND_SOC_MAX98925 if I2C
select SND_SOC_MAX98926 if I2C
select SND_SOC_MAX98927 if I2C
+   select SND_SOC_MAX98373 if I2C
select SND_SOC_MAX9850 if I2C
select SND_SOC_MAX9860 if I2C
select SND_SOC_MAX9768 if I2C
@@ -626,6 +627,10 @@ config SND_SOC_MAX98927
tristate "Maxim Integrated MAX98927 Speaker Amplifier"
depends on I2C
 
+config SND_SOC_MAX98373
+   tristate "Maxim Integrated MAX98373 Speaker Amplifier"
+   depends on I2C
+
 config SND_SOC_MAX9850
tristate
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 0977349..49db8e9 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -90,6 +90,7 @@ snd-soc-max9867-objs := max9867.o
 snd-soc-max98925-objs := max98925.o
 snd-soc-max98926-objs := max98926.o
 snd-soc-max98927-objs := max98927.o
+snd-soc-max98373-objs := max98373.o
 snd-soc-max9850-objs := max9850.o
 snd-soc-max9860-objs := max9860.o
 snd-soc-mc13783-objs := mc13783.o
@@ -334,6 +335,7 @@ obj-$(CONFIG_SND_SOC_MAX9867)   += snd-soc-max9867.o
 obj-$(CONFIG_SND_SOC_MAX98925) += snd-soc-max98925.o
 obj-$(CONFIG_SND_SOC_MAX98926) += snd-soc-max98926.o
 obj-$(CONFIG_SND_SOC_MAX98927) += snd-soc-max98927.o
+obj-$(CONFIG_SND_SOC_MAX98373) += snd-soc-max98373.o
 obj-$(CONFIG_SND_SOC_MAX9850)  += snd-soc-max9850.o
 obj-$(CONFIG_SND_SOC_MAX9860)  += snd-soc-max9860.o
 obj-$(CONFIG_SND_SOC_MC13783)  += snd-soc-mc13783.o
diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
new file mode 100644
index 000..434c367
--- /dev/null
+++ b/sound/soc/codecs/max98373.c
@@ -0,0 +1,996 @@
+/*
+ * max98373.c  --  MAX98373 ALSA Soc Audio driver
+ *
+ * Copyright (C) 2017 Maxim Integrated Products
+ * Author: Ryan Lee <ryans@maximintegrated.com>
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "max98373.h"
+
+static struct reg_default max98373_reg[] = {
+   {MAX98373_R2000_SW_R

[PATCH] ASoC: max98373: Added Amplifier Driver

2017-12-21 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---

Created max98373 amplifier driver.

 .../devicetree/bindings/sound/max98373.txt |  43 +
 sound/soc/codecs/Kconfig   |   5 +
 sound/soc/codecs/Makefile  |   2 +
 sound/soc/codecs/max98373.c| 996 +
 sound/soc/codecs/max98373.h| 225 +
 5 files changed, 1271 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/max98373.txt
 create mode 100644 sound/soc/codecs/max98373.c
 create mode 100644 sound/soc/codecs/max98373.h

diff --git a/Documentation/devicetree/bindings/sound/max98373.txt 
b/Documentation/devicetree/bindings/sound/max98373.txt
new file mode 100644
index 000..22cd259
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/max98373.txt
@@ -0,0 +1,43 @@
+Maxim Integrated MAX98373 Speaker Amplifier
+
+This device supports I2C.
+
+Required properties:
+
+  - compatible : should be one of the following
+- "maxim,max98373"
+
+  - reg : the I2C address of the device.
+
+Optional properties:
+
+  - maxim,vmon-slot-no : slot number used to send voltage information
+   or in inteleave mode this will be used as
+   interleave slot.
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,imon-slot-no : slot number used to send current information
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,spkfb-slot-no : slot number used to send speaker feedback information
+   slot range : 0 ~ 15,  Default : 0
+
+  - maxim,interleave-mode : When using two MAX98373 in a system it is
+   possible to create ADC data that that will
+   overflow the frame size. Digital Audio Interleave
+   mode provides a means to output VMON and IMON data
+   from two devices on a single DOUT line when running
+   smaller frames sizes such as 32 BCLKS per LRCLK or
+   48 BCLKS per LRCLK.
+   Range : 0 (off), 1 (on),  Default : 0
+
+Example:
+
+codec: max98373@31 {
+   compatible = "maxim,max98373";
+   reg = <0x31>;
+   maxim,vmon-slot-no = <0>;
+   maxim,imon-slot-no = <1>;
+   maxim,spkfb-slot-no = <2>;
+   maxim,interleave-mode = <0>;
+};
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 8b02bc8..9af2588 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -95,6 +95,7 @@ config SND_SOC_ALL_CODECS
select SND_SOC_MAX98925 if I2C
select SND_SOC_MAX98926 if I2C
select SND_SOC_MAX98927 if I2C
+   select SND_SOC_MAX98373 if I2C
select SND_SOC_MAX9850 if I2C
select SND_SOC_MAX9860 if I2C
select SND_SOC_MAX9768 if I2C
@@ -626,6 +627,10 @@ config SND_SOC_MAX98927
tristate "Maxim Integrated MAX98927 Speaker Amplifier"
depends on I2C
 
+config SND_SOC_MAX98373
+   tristate "Maxim Integrated MAX98373 Speaker Amplifier"
+   depends on I2C
+
 config SND_SOC_MAX9850
tristate
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 0977349..49db8e9 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -90,6 +90,7 @@ snd-soc-max9867-objs := max9867.o
 snd-soc-max98925-objs := max98925.o
 snd-soc-max98926-objs := max98926.o
 snd-soc-max98927-objs := max98927.o
+snd-soc-max98373-objs := max98373.o
 snd-soc-max9850-objs := max9850.o
 snd-soc-max9860-objs := max9860.o
 snd-soc-mc13783-objs := mc13783.o
@@ -334,6 +335,7 @@ obj-$(CONFIG_SND_SOC_MAX9867)   += snd-soc-max9867.o
 obj-$(CONFIG_SND_SOC_MAX98925) += snd-soc-max98925.o
 obj-$(CONFIG_SND_SOC_MAX98926) += snd-soc-max98926.o
 obj-$(CONFIG_SND_SOC_MAX98927) += snd-soc-max98927.o
+obj-$(CONFIG_SND_SOC_MAX98373) += snd-soc-max98373.o
 obj-$(CONFIG_SND_SOC_MAX9850)  += snd-soc-max9850.o
 obj-$(CONFIG_SND_SOC_MAX9860)  += snd-soc-max9860.o
 obj-$(CONFIG_SND_SOC_MC13783)  += snd-soc-mc13783.o
diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
new file mode 100644
index 000..434c367
--- /dev/null
+++ b/sound/soc/codecs/max98373.c
@@ -0,0 +1,996 @@
+/*
+ * max98373.c  --  MAX98373 ALSA Soc Audio driver
+ *
+ * Copyright (C) 2017 Maxim Integrated Products
+ * Author: Ryan Lee 
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "max98373.h"
+
+static struct reg_default max98373_reg[] = {
+   {MAX98373_R2000_SW_RESET, 0x00},
+   {MAX98373_R2001_INT_RAW1, 0x00},
+   {MAX98373_R2002_INT_RAW2, 0x00},
+

[PATCH 2/2] ASoC: max98927: Added max98927_dai_tdm_slot function

2017-09-14 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
Changelog:
Added 'max98927_dai_tdm_slot' function to set proper slot configuration.
Added variable 'tdm_mode' to avoid BCLK overwrite after 'max98927_dai_tdm_slot' 
configure BCLK value.
 :BCLK value is being set inside 'max98927_dai_tdm_slot' function when it is 
tdm mode because number of slots and slot width information is available here.
 :'max98927_set_clock' is called from hw_params and slot information is not 
available in this function so it can overwrite BCLK value.
 :Variable 'tdm_mode' will be cleared after SND_SOC_DAPM_POST_PMD event is 
recieved.
Added 'max98927_get_bclk_sel' to avoid code duplication and support BCLK up to 
512. 

 sound/soc/codecs/max98927.c | 118 ++--
 sound/soc/codecs/max98927.h |   1 +
 2 files changed, 103 insertions(+), 16 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index 6f7b3ef..116cb9b 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -250,6 +250,21 @@ static const int rate_table[] = {
1300, 1920,
 };
 
+/* BCLKs per LRCLK */
+static const int bclk_sel_table[] = {
+   32, 48, 64, 96, 128, 192, 256, 384, 512,
+};
+
+static int max98927_get_bclk_sel(int bclk)
+{
+   int i;
+   /* match BCLKs per LRCLK */
+   for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) {
+   if (bclk_sel_table[i] == bclk)
+   return i + 2;
+   }
+   return 0;
+}
 static int max98927_set_clock(struct max98927_priv *max98927,
struct snd_pcm_hw_params *params)
 {
@@ -275,23 +290,20 @@ static int max98927_set_clock(struct max98927_priv 
*max98927,
i << MAX98927_PCM_MASTER_MODE_MCLK_RATE_SHIFT);
}
 
-   switch (blr_clk_ratio) {
-   case 32:
-   value = 2;
-   break;
-   case 48:
-   value = 3;
-   break;
-   case 64:
-   value = 4;
-   break;
-   default:
-   return -EINVAL;
+   if (!max98927->tdm_mode) {
+   /* BCLK configuration */
+   value = max98927_get_bclk_sel(blr_clk_ratio);
+   if (!value) {
+   dev_err(codec->dev, "format unsupported %d\n",
+   params_format(params));
+   return -EINVAL;
+   }
+
+   regmap_update_bits(max98927->regmap,
+   MAX98927_R0022_PCM_CLK_SETUP,
+   MAX98927_PCM_CLK_SETUP_BSEL_MASK,
+   value);
}
-   regmap_update_bits(max98927->regmap,
-   MAX98927_R0022_PCM_CLK_SETUP,
-   MAX98927_PCM_CLK_SETUP_BSEL_MASK,
-   value);
return 0;
 }
 
@@ -391,6 +403,78 @@ static int max98927_dai_hw_params(struct snd_pcm_substream 
*substream,
return -EINVAL;
 }
 
+static int max98927_dai_tdm_slot(struct snd_soc_dai *dai,
+   unsigned int tx_mask, unsigned int rx_mask,
+   int slots, int slot_width)
+{
+   struct snd_soc_codec *codec = dai->codec;
+   struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec);
+   int bsel = 0;
+   unsigned int chan_sz = 0;
+
+   max98927->tdm_mode = true;
+
+   /* BCLK configuration */
+   bsel = max98927_get_bclk_sel(slots * slot_width);
+   if (bsel == 0) {
+   dev_err(codec->dev, "BCLK %d not supported\n",
+   slots * slot_width);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(max98927->regmap,
+   MAX98927_R0022_PCM_CLK_SETUP,
+   MAX98927_PCM_CLK_SETUP_BSEL_MASK,
+   bsel);
+
+   /* Channel size configuration */
+   switch (slot_width) {
+   case 16:
+   chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_16;
+   break;
+   case 24:
+   chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_24;
+   break;
+   case 32:
+   chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_32;
+   break;
+   default:
+   dev_err(codec->dev, "format unsupported %d\n",
+   slot_width);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(max98927->regmap,
+   MAX98927_R0020_PCM_MODE_CFG,
+   MAX98927_PCM_MODE_CFG_CHANSZ_MASK, chan_sz);
+
+   /* Rx slot configuration */
+   regmap_write(max98927->regmap,
+   MAX98927_R0018_PCM_RX_EN_A,
+   rx_mask & 0xFF);
+   regmap_write(max98927->regmap,
+   MAX98927_R0019_PCM_RX_EN_B,
+   (rx_mask & 0xFF00) >> 8);
+
+   /* Tx slot configuration */
+   regmap_write(max98927->regmap,
+   MAX98927_R001A_PCM_TX_EN_A,
+   tx_mask & 0xFF);
+

[PATCH 2/2] ASoC: max98927: Added max98927_dai_tdm_slot function

2017-09-14 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changelog:
Added 'max98927_dai_tdm_slot' function to set proper slot configuration.
Added variable 'tdm_mode' to avoid BCLK overwrite after 'max98927_dai_tdm_slot' 
configure BCLK value.
 :BCLK value is being set inside 'max98927_dai_tdm_slot' function when it is 
tdm mode because number of slots and slot width information is available here.
 :'max98927_set_clock' is called from hw_params and slot information is not 
available in this function so it can overwrite BCLK value.
 :Variable 'tdm_mode' will be cleared after SND_SOC_DAPM_POST_PMD event is 
recieved.
Added 'max98927_get_bclk_sel' to avoid code duplication and support BCLK up to 
512. 

 sound/soc/codecs/max98927.c | 118 ++--
 sound/soc/codecs/max98927.h |   1 +
 2 files changed, 103 insertions(+), 16 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index 6f7b3ef..116cb9b 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -250,6 +250,21 @@ static const int rate_table[] = {
1300, 1920,
 };
 
+/* BCLKs per LRCLK */
+static const int bclk_sel_table[] = {
+   32, 48, 64, 96, 128, 192, 256, 384, 512,
+};
+
+static int max98927_get_bclk_sel(int bclk)
+{
+   int i;
+   /* match BCLKs per LRCLK */
+   for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) {
+   if (bclk_sel_table[i] == bclk)
+   return i + 2;
+   }
+   return 0;
+}
 static int max98927_set_clock(struct max98927_priv *max98927,
struct snd_pcm_hw_params *params)
 {
@@ -275,23 +290,20 @@ static int max98927_set_clock(struct max98927_priv 
*max98927,
i << MAX98927_PCM_MASTER_MODE_MCLK_RATE_SHIFT);
}
 
-   switch (blr_clk_ratio) {
-   case 32:
-   value = 2;
-   break;
-   case 48:
-   value = 3;
-   break;
-   case 64:
-   value = 4;
-   break;
-   default:
-   return -EINVAL;
+   if (!max98927->tdm_mode) {
+   /* BCLK configuration */
+   value = max98927_get_bclk_sel(blr_clk_ratio);
+   if (!value) {
+   dev_err(codec->dev, "format unsupported %d\n",
+   params_format(params));
+   return -EINVAL;
+   }
+
+   regmap_update_bits(max98927->regmap,
+   MAX98927_R0022_PCM_CLK_SETUP,
+   MAX98927_PCM_CLK_SETUP_BSEL_MASK,
+   value);
}
-   regmap_update_bits(max98927->regmap,
-   MAX98927_R0022_PCM_CLK_SETUP,
-   MAX98927_PCM_CLK_SETUP_BSEL_MASK,
-   value);
return 0;
 }
 
@@ -391,6 +403,78 @@ static int max98927_dai_hw_params(struct snd_pcm_substream 
*substream,
return -EINVAL;
 }
 
+static int max98927_dai_tdm_slot(struct snd_soc_dai *dai,
+   unsigned int tx_mask, unsigned int rx_mask,
+   int slots, int slot_width)
+{
+   struct snd_soc_codec *codec = dai->codec;
+   struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec);
+   int bsel = 0;
+   unsigned int chan_sz = 0;
+
+   max98927->tdm_mode = true;
+
+   /* BCLK configuration */
+   bsel = max98927_get_bclk_sel(slots * slot_width);
+   if (bsel == 0) {
+   dev_err(codec->dev, "BCLK %d not supported\n",
+   slots * slot_width);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(max98927->regmap,
+   MAX98927_R0022_PCM_CLK_SETUP,
+   MAX98927_PCM_CLK_SETUP_BSEL_MASK,
+   bsel);
+
+   /* Channel size configuration */
+   switch (slot_width) {
+   case 16:
+   chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_16;
+   break;
+   case 24:
+   chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_24;
+   break;
+   case 32:
+   chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_32;
+   break;
+   default:
+   dev_err(codec->dev, "format unsupported %d\n",
+   slot_width);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(max98927->regmap,
+   MAX98927_R0020_PCM_MODE_CFG,
+   MAX98927_PCM_MODE_CFG_CHANSZ_MASK, chan_sz);
+
+   /* Rx slot configuration */
+   regmap_write(max98927->regmap,
+   MAX98927_R0018_PCM_RX_EN_A,
+   rx_mask & 0xFF);
+   regmap_write(max98927->regmap,
+   MAX98927_R0019_PCM_RX_EN_B,
+   (rx_mask & 0xFF00) >> 8);
+
+   /* Tx slot configuration */
+   regmap_write(max98927->regmap,
+   MAX98927_R001A_PCM_TX_EN_A,
+   tx_mask & 0xFF);
+   regmap_write(max98927->regmap,
+  

[PATCH 2/2] ASoC: max98927: Added max98927_dai_tdm_slot function

2017-09-14 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
 sound/soc/codecs/max98927.c | 120 ++--
 sound/soc/codecs/max98927.h |   1 +
 2 files changed, 105 insertions(+), 16 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index 6f7b3ef..a1d3935 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -250,6 +250,21 @@ static const int rate_table[] = {
1300, 1920,
 };
 
+/* BCLKs per LRCLK */
+static const int bclk_sel_table[] = {
+   32, 48, 64, 96, 128, 192, 256, 384, 512,
+};
+
+static int max98927_get_bclk_sel(int bclk)
+{
+   int i;
+   /* match BCLKs per LRCLK */
+   for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) {
+   if (bclk_sel_table[i] == bclk)
+   return i + 2;
+   }
+   return 0;
+}
 static int max98927_set_clock(struct max98927_priv *max98927,
struct snd_pcm_hw_params *params)
 {
@@ -275,23 +290,20 @@ static int max98927_set_clock(struct max98927_priv 
*max98927,
i << MAX98927_PCM_MASTER_MODE_MCLK_RATE_SHIFT);
}
 
-   switch (blr_clk_ratio) {
-   case 32:
-   value = 2;
-   break;
-   case 48:
-   value = 3;
-   break;
-   case 64:
-   value = 4;
-   break;
-   default:
-   return -EINVAL;
+   if (!max98927->tdm_mode) {
+   /* BCLK configuration */
+   value = max98927_get_bclk_sel(blr_clk_ratio);
+   if (!value) {
+   dev_err(codec->dev, "format unsupported %d\n",
+   params_format(params));
+   return -EINVAL;
+   }
+
+   regmap_update_bits(max98927->regmap,
+   MAX98927_R0022_PCM_CLK_SETUP,
+   MAX98927_PCM_CLK_SETUP_BSEL_MASK,
+   value);
}
-   regmap_update_bits(max98927->regmap,
-   MAX98927_R0022_PCM_CLK_SETUP,
-   MAX98927_PCM_CLK_SETUP_BSEL_MASK,
-   value);
return 0;
 }
 
@@ -391,6 +403,78 @@ static int max98927_dai_hw_params(struct snd_pcm_substream 
*substream,
return -EINVAL;
 }
 
+static int max98927_dai_tdm_slot(struct snd_soc_dai *dai,
+   unsigned int tx_mask, unsigned int rx_mask,
+   int slots, int slot_width)
+{
+   struct snd_soc_codec *codec = dai->codec;
+   struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec);
+   int bsel = 0;
+   unsigned int chan_sz = 0;
+
+   max98927->tdm_mode = true;
+
+   /* BCLK configuration */
+   bsel = max98927_get_bclk_sel(slots * slot_width);
+   if (bsel == 0) {
+   dev_err(codec->dev, "BCLK %d not supported\n",
+   slots * slot_width);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(max98927->regmap,
+   MAX98927_R0022_PCM_CLK_SETUP,
+   MAX98927_PCM_CLK_SETUP_BSEL_MASK,
+   bsel);
+
+   /* Channel size configuration */
+   switch (slot_width) {
+   case 16:
+   chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_16;
+   break;
+   case 24:
+   chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_24;
+   break;
+   case 32:
+   chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_32;
+   break;
+   default:
+   dev_err(codec->dev, "format unsupported %d\n",
+   slot_width);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(max98927->regmap,
+   MAX98927_R0020_PCM_MODE_CFG,
+   MAX98927_PCM_MODE_CFG_CHANSZ_MASK, chan_sz);
+
+   /* Rx slot configuration */
+   regmap_write(max98927->regmap,
+   MAX98927_R0018_PCM_RX_EN_A,
+   rx_mask & 0xFF);
+   regmap_write(max98927->regmap,
+   MAX98927_R0019_PCM_RX_EN_B,
+   (rx_mask & 0xFF00) >> 8);
+
+   /* Tx slot configuration */
+   regmap_write(max98927->regmap,
+   MAX98927_R001A_PCM_TX_EN_A,
+   tx_mask & 0xFF);
+   regmap_write(max98927->regmap,
+   MAX98927_R001B_PCM_TX_EN_B,
+   (tx_mask & 0xFF00) >> 8);
+
+   /* Tx slot Hi-Z configuration */
+   regmap_write(max98927->regmap,
+   MAX98927_R001C_PCM_TX_HIZ_CTRL_A,
+   ~tx_mask & 0xFF);
+   regmap_write(max98927->regmap,
+   MAX98927_R001D_PCM_TX_HIZ_CTRL_B,
+   (~tx_mask & 0xFF00) >> 8);
+
+   return 0;
+}
+
 #define MAX98927_RATES SNDRV_PCM_RATE_8000_48000
 
 #define MAX98927_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
@@ -410,6 +494,7 @@ static const struct snd_soc_dai_ops max98927_dai_ops 

[PATCH 2/2] ASoC: max98927: Added max98927_dai_tdm_slot function

2017-09-14 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 sound/soc/codecs/max98927.c | 120 ++--
 sound/soc/codecs/max98927.h |   1 +
 2 files changed, 105 insertions(+), 16 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index 6f7b3ef..a1d3935 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -250,6 +250,21 @@ static const int rate_table[] = {
1300, 1920,
 };
 
+/* BCLKs per LRCLK */
+static const int bclk_sel_table[] = {
+   32, 48, 64, 96, 128, 192, 256, 384, 512,
+};
+
+static int max98927_get_bclk_sel(int bclk)
+{
+   int i;
+   /* match BCLKs per LRCLK */
+   for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) {
+   if (bclk_sel_table[i] == bclk)
+   return i + 2;
+   }
+   return 0;
+}
 static int max98927_set_clock(struct max98927_priv *max98927,
struct snd_pcm_hw_params *params)
 {
@@ -275,23 +290,20 @@ static int max98927_set_clock(struct max98927_priv 
*max98927,
i << MAX98927_PCM_MASTER_MODE_MCLK_RATE_SHIFT);
}
 
-   switch (blr_clk_ratio) {
-   case 32:
-   value = 2;
-   break;
-   case 48:
-   value = 3;
-   break;
-   case 64:
-   value = 4;
-   break;
-   default:
-   return -EINVAL;
+   if (!max98927->tdm_mode) {
+   /* BCLK configuration */
+   value = max98927_get_bclk_sel(blr_clk_ratio);
+   if (!value) {
+   dev_err(codec->dev, "format unsupported %d\n",
+   params_format(params));
+   return -EINVAL;
+   }
+
+   regmap_update_bits(max98927->regmap,
+   MAX98927_R0022_PCM_CLK_SETUP,
+   MAX98927_PCM_CLK_SETUP_BSEL_MASK,
+   value);
}
-   regmap_update_bits(max98927->regmap,
-   MAX98927_R0022_PCM_CLK_SETUP,
-   MAX98927_PCM_CLK_SETUP_BSEL_MASK,
-   value);
return 0;
 }
 
@@ -391,6 +403,78 @@ static int max98927_dai_hw_params(struct snd_pcm_substream 
*substream,
return -EINVAL;
 }
 
+static int max98927_dai_tdm_slot(struct snd_soc_dai *dai,
+   unsigned int tx_mask, unsigned int rx_mask,
+   int slots, int slot_width)
+{
+   struct snd_soc_codec *codec = dai->codec;
+   struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec);
+   int bsel = 0;
+   unsigned int chan_sz = 0;
+
+   max98927->tdm_mode = true;
+
+   /* BCLK configuration */
+   bsel = max98927_get_bclk_sel(slots * slot_width);
+   if (bsel == 0) {
+   dev_err(codec->dev, "BCLK %d not supported\n",
+   slots * slot_width);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(max98927->regmap,
+   MAX98927_R0022_PCM_CLK_SETUP,
+   MAX98927_PCM_CLK_SETUP_BSEL_MASK,
+   bsel);
+
+   /* Channel size configuration */
+   switch (slot_width) {
+   case 16:
+   chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_16;
+   break;
+   case 24:
+   chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_24;
+   break;
+   case 32:
+   chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_32;
+   break;
+   default:
+   dev_err(codec->dev, "format unsupported %d\n",
+   slot_width);
+   return -EINVAL;
+   }
+
+   regmap_update_bits(max98927->regmap,
+   MAX98927_R0020_PCM_MODE_CFG,
+   MAX98927_PCM_MODE_CFG_CHANSZ_MASK, chan_sz);
+
+   /* Rx slot configuration */
+   regmap_write(max98927->regmap,
+   MAX98927_R0018_PCM_RX_EN_A,
+   rx_mask & 0xFF);
+   regmap_write(max98927->regmap,
+   MAX98927_R0019_PCM_RX_EN_B,
+   (rx_mask & 0xFF00) >> 8);
+
+   /* Tx slot configuration */
+   regmap_write(max98927->regmap,
+   MAX98927_R001A_PCM_TX_EN_A,
+   tx_mask & 0xFF);
+   regmap_write(max98927->regmap,
+   MAX98927_R001B_PCM_TX_EN_B,
+   (tx_mask & 0xFF00) >> 8);
+
+   /* Tx slot Hi-Z configuration */
+   regmap_write(max98927->regmap,
+   MAX98927_R001C_PCM_TX_HIZ_CTRL_A,
+   ~tx_mask & 0xFF);
+   regmap_write(max98927->regmap,
+   MAX98927_R001D_PCM_TX_HIZ_CTRL_B,
+   (~tx_mask & 0xFF00) >> 8);
+
+   return 0;
+}
+
 #define MAX98927_RATES SNDRV_PCM_RATE_8000_48000
 
 #define MAX98927_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
@@ -410,6 +494,7 @@ static const struct snd_soc_dai_ops max98927_dai_ops = {
.set_sysclk = max

[PATCH 1/2] ASoC: max98927: Added support for DSP_A and DSP_B format

2017-09-14 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
Changelog:
Modified copyright date
Added support for DSP_A and DSP_B format.
Added 'use_pdm' variable to distinguish configuration for pcm and pdm.
Maxim's TDM_MODE1 is matched with DSP_A
Maxim's TDM_MODE0 is matched with DSP_B

 sound/soc/codecs/max98927.c | 35 ---
 sound/soc/codecs/max98927.h |  6 --
 2 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index d9dbbe7..6f7b3ef 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -1,7 +1,7 @@
 /*
  * max98927.c  --  MAX98927 ALSA Soc Audio driver
  *
- * Copyright (C) 2016 Maxim Integrated Products
+ * Copyright (C) 2016-2017 Maxim Integrated Products
  * Author: Ryan Lee <ryans@maximintegrated.com>
  *
  *  This program is free software; you can redistribute  it and/or modify it
@@ -146,6 +146,7 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec);
unsigned int mode = 0;
unsigned int format = 0;
+   bool use_pdm = false;
unsigned int invert = 0;
 
dev_dbg(codec->dev, "%s: fmt 0x%08X\n", __func__, fmt);
@@ -187,22 +188,27 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
/* interface format */
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
case SND_SOC_DAIFMT_I2S:
-   max98927->iface |= SND_SOC_DAIFMT_I2S;
format = MAX98927_PCM_FORMAT_I2S;
break;
case SND_SOC_DAIFMT_LEFT_J:
-   max98927->iface |= SND_SOC_DAIFMT_LEFT_J;
format = MAX98927_PCM_FORMAT_LJ;
break;
+   case SND_SOC_DAIFMT_DSP_A:
+   format = MAX98927_PCM_FORMAT_TDM_MODE1;
+   break;
+   case SND_SOC_DAIFMT_DSP_B:
+   format = MAX98927_PCM_FORMAT_TDM_MODE0;
+   break;
case SND_SOC_DAIFMT_PDM:
-   max98927->iface |= SND_SOC_DAIFMT_PDM;
+   use_pdm = true;
break;
default:
return -EINVAL;
}
+   max98927->iface = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
 
-   /* pcm channel configuration */
-   if (max98927->iface & (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_LEFT_J)) {
+   if (!use_pdm) {
+   /* pcm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0018_PCM_RX_EN_A,
MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN,
@@ -217,13 +223,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 0);
 
-   } else
regmap_update_bits(max98927->regmap,
-   MAX98927_R0018_PCM_RX_EN_A,
-   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
-
-   /* pdm channel configuration */
-   if (max98927->iface & SND_SOC_DAIFMT_PDM) {
+   MAX98927_R0035_PDM_RX_CTRL,
+   MAX98927_PDM_RX_EN_MASK, 0);
+   } else {
+   /* pdm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0035_PDM_RX_CTRL,
MAX98927_PDM_RX_EN_MASK, 1);
@@ -231,10 +235,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
regmap_update_bits(max98927->regmap,
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 3);
-   } else
+
regmap_update_bits(max98927->regmap,
-   MAX98927_R0035_PDM_RX_CTRL,
-   MAX98927_PDM_RX_EN_MASK, 0);
+   MAX98927_R0018_PCM_RX_EN_A,
+   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
+   }
return 0;
 }
 
diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h
index ece6a60..bf7a6f92 100644
--- a/sound/soc/codecs/max98927.h
+++ b/sound/soc/codecs/max98927.h
@@ -1,7 +1,7 @@
 /*
  * max98927.h  --  MAX98927 ALSA Soc Audio driver
  *
- * Copyright 2013-15 Maxim Integrated Products
+ * Copyright (C) 2016-2017 Maxim Integrated Products
  * Author: Ryan Lee <ryans@maximintegrated.com>
  *
  *  This program is free software; you can redistribute  it and/or modify it
@@ -161,7 +161,9 @@
 #define MAX98927_PCM_MODE_CFG_FORMAT_SHIFT (3)
 #define MAX98927_PCM_FORMAT_I2S (0x0 << 0)
 #define MAX98927_PCM_FORMAT_LJ (0x1 << 0)
-
+#define MAX98927_PCM_FORMAT_TDM_MODE0 (0x3 << 0)
+#define MAX98927_PCM_FORMAT_TDM_MODE1 (0x4 << 0)
+#define MAX98927_PCM_FORMAT_TDM_MODE2 (0x5 <&l

[PATCH 1/2] ASoC: max98927: Added support for DSP_A and DSP_B format

2017-09-14 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
 sound/soc/codecs/max98927.c | 35 ---
 sound/soc/codecs/max98927.h |  6 --
 2 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index d9dbbe7..6f7b3ef 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -1,7 +1,7 @@
 /*
  * max98927.c  --  MAX98927 ALSA Soc Audio driver
  *
- * Copyright (C) 2016 Maxim Integrated Products
+ * Copyright (C) 2016-2017 Maxim Integrated Products
  * Author: Ryan Lee <ryans@maximintegrated.com>
  *
  *  This program is free software; you can redistribute  it and/or modify it
@@ -146,6 +146,7 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec);
unsigned int mode = 0;
unsigned int format = 0;
+   bool use_pdm = false;
unsigned int invert = 0;
 
dev_dbg(codec->dev, "%s: fmt 0x%08X\n", __func__, fmt);
@@ -187,22 +188,27 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
/* interface format */
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
case SND_SOC_DAIFMT_I2S:
-   max98927->iface |= SND_SOC_DAIFMT_I2S;
format = MAX98927_PCM_FORMAT_I2S;
break;
case SND_SOC_DAIFMT_LEFT_J:
-   max98927->iface |= SND_SOC_DAIFMT_LEFT_J;
format = MAX98927_PCM_FORMAT_LJ;
break;
+   case SND_SOC_DAIFMT_DSP_A:
+   format = MAX98927_PCM_FORMAT_TDM_MODE1;
+   break;
+   case SND_SOC_DAIFMT_DSP_B:
+   format = MAX98927_PCM_FORMAT_TDM_MODE0;
+   break;
case SND_SOC_DAIFMT_PDM:
-   max98927->iface |= SND_SOC_DAIFMT_PDM;
+   use_pdm = true;
break;
default:
return -EINVAL;
}
+   max98927->iface = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
 
-   /* pcm channel configuration */
-   if (max98927->iface & (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_LEFT_J)) {
+   if (!use_pdm) {
+   /* pcm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0018_PCM_RX_EN_A,
MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN,
@@ -217,13 +223,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 0);
 
-   } else
regmap_update_bits(max98927->regmap,
-   MAX98927_R0018_PCM_RX_EN_A,
-   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
-
-   /* pdm channel configuration */
-   if (max98927->iface & SND_SOC_DAIFMT_PDM) {
+   MAX98927_R0035_PDM_RX_CTRL,
+   MAX98927_PDM_RX_EN_MASK, 0);
+   } else {
+   /* pdm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0035_PDM_RX_CTRL,
MAX98927_PDM_RX_EN_MASK, 1);
@@ -231,10 +235,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
regmap_update_bits(max98927->regmap,
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 3);
-   } else
+
regmap_update_bits(max98927->regmap,
-   MAX98927_R0035_PDM_RX_CTRL,
-   MAX98927_PDM_RX_EN_MASK, 0);
+   MAX98927_R0018_PCM_RX_EN_A,
+   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
+   }
return 0;
 }
 
diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h
index ece6a60..bf7a6f92 100644
--- a/sound/soc/codecs/max98927.h
+++ b/sound/soc/codecs/max98927.h
@@ -1,7 +1,7 @@
 /*
  * max98927.h  --  MAX98927 ALSA Soc Audio driver
  *
- * Copyright 2013-15 Maxim Integrated Products
+ * Copyright (C) 2016-2017 Maxim Integrated Products
  * Author: Ryan Lee <ryans@maximintegrated.com>
  *
  *  This program is free software; you can redistribute  it and/or modify it
@@ -161,7 +161,9 @@
 #define MAX98927_PCM_MODE_CFG_FORMAT_SHIFT (3)
 #define MAX98927_PCM_FORMAT_I2S (0x0 << 0)
 #define MAX98927_PCM_FORMAT_LJ (0x1 << 0)
-
+#define MAX98927_PCM_FORMAT_TDM_MODE0 (0x3 << 0)
+#define MAX98927_PCM_FORMAT_TDM_MODE1 (0x4 << 0)
+#define MAX98927_PCM_FORMAT_TDM_MODE2 (0x5 << 0)
 #define MAX98927_PCM_MODE_CFG_CHANSZ_MASK (0x3 << 6)
 #define MAX98927_PCM_MODE_CFG_CHANSZ_16 (0x1 << 6)
 #define MAX98927_PCM_MODE_CFG_CHANSZ_24 (0x2 << 6)
-- 
2.7.4



[PATCH 1/2] ASoC: max98927: Added support for DSP_A and DSP_B format

2017-09-14 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 sound/soc/codecs/max98927.c | 35 ---
 sound/soc/codecs/max98927.h |  6 --
 2 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index d9dbbe7..6f7b3ef 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -1,7 +1,7 @@
 /*
  * max98927.c  --  MAX98927 ALSA Soc Audio driver
  *
- * Copyright (C) 2016 Maxim Integrated Products
+ * Copyright (C) 2016-2017 Maxim Integrated Products
  * Author: Ryan Lee 
  *
  *  This program is free software; you can redistribute  it and/or modify it
@@ -146,6 +146,7 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec);
unsigned int mode = 0;
unsigned int format = 0;
+   bool use_pdm = false;
unsigned int invert = 0;
 
dev_dbg(codec->dev, "%s: fmt 0x%08X\n", __func__, fmt);
@@ -187,22 +188,27 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
/* interface format */
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
case SND_SOC_DAIFMT_I2S:
-   max98927->iface |= SND_SOC_DAIFMT_I2S;
format = MAX98927_PCM_FORMAT_I2S;
break;
case SND_SOC_DAIFMT_LEFT_J:
-   max98927->iface |= SND_SOC_DAIFMT_LEFT_J;
format = MAX98927_PCM_FORMAT_LJ;
break;
+   case SND_SOC_DAIFMT_DSP_A:
+   format = MAX98927_PCM_FORMAT_TDM_MODE1;
+   break;
+   case SND_SOC_DAIFMT_DSP_B:
+   format = MAX98927_PCM_FORMAT_TDM_MODE0;
+   break;
case SND_SOC_DAIFMT_PDM:
-   max98927->iface |= SND_SOC_DAIFMT_PDM;
+   use_pdm = true;
break;
default:
return -EINVAL;
}
+   max98927->iface = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
 
-   /* pcm channel configuration */
-   if (max98927->iface & (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_LEFT_J)) {
+   if (!use_pdm) {
+   /* pcm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0018_PCM_RX_EN_A,
MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN,
@@ -217,13 +223,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 0);
 
-   } else
regmap_update_bits(max98927->regmap,
-   MAX98927_R0018_PCM_RX_EN_A,
-   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
-
-   /* pdm channel configuration */
-   if (max98927->iface & SND_SOC_DAIFMT_PDM) {
+   MAX98927_R0035_PDM_RX_CTRL,
+   MAX98927_PDM_RX_EN_MASK, 0);
+   } else {
+   /* pdm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0035_PDM_RX_CTRL,
MAX98927_PDM_RX_EN_MASK, 1);
@@ -231,10 +235,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
regmap_update_bits(max98927->regmap,
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 3);
-   } else
+
regmap_update_bits(max98927->regmap,
-   MAX98927_R0035_PDM_RX_CTRL,
-   MAX98927_PDM_RX_EN_MASK, 0);
+   MAX98927_R0018_PCM_RX_EN_A,
+   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
+   }
return 0;
 }
 
diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h
index ece6a60..bf7a6f92 100644
--- a/sound/soc/codecs/max98927.h
+++ b/sound/soc/codecs/max98927.h
@@ -1,7 +1,7 @@
 /*
  * max98927.h  --  MAX98927 ALSA Soc Audio driver
  *
- * Copyright 2013-15 Maxim Integrated Products
+ * Copyright (C) 2016-2017 Maxim Integrated Products
  * Author: Ryan Lee 
  *
  *  This program is free software; you can redistribute  it and/or modify it
@@ -161,7 +161,9 @@
 #define MAX98927_PCM_MODE_CFG_FORMAT_SHIFT (3)
 #define MAX98927_PCM_FORMAT_I2S (0x0 << 0)
 #define MAX98927_PCM_FORMAT_LJ (0x1 << 0)
-
+#define MAX98927_PCM_FORMAT_TDM_MODE0 (0x3 << 0)
+#define MAX98927_PCM_FORMAT_TDM_MODE1 (0x4 << 0)
+#define MAX98927_PCM_FORMAT_TDM_MODE2 (0x5 << 0)
 #define MAX98927_PCM_MODE_CFG_CHANSZ_MASK (0x3 << 6)
 #define MAX98927_PCM_MODE_CFG_CHANSZ_16 (0x1 << 6)
 #define MAX98927_PCM_MODE_CFG_CHANSZ_24 (0x2 << 6)
-- 
2.7.4



[PATCH 1/2] ASoC: max98927: Added support for DSP_A and DSP_B format

2017-09-14 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changelog:
Modified copyright date
Added support for DSP_A and DSP_B format.
Added 'use_pdm' variable to distinguish configuration for pcm and pdm.
Maxim's TDM_MODE1 is matched with DSP_A
Maxim's TDM_MODE0 is matched with DSP_B

 sound/soc/codecs/max98927.c | 35 ---
 sound/soc/codecs/max98927.h |  6 --
 2 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index d9dbbe7..6f7b3ef 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -1,7 +1,7 @@
 /*
  * max98927.c  --  MAX98927 ALSA Soc Audio driver
  *
- * Copyright (C) 2016 Maxim Integrated Products
+ * Copyright (C) 2016-2017 Maxim Integrated Products
  * Author: Ryan Lee 
  *
  *  This program is free software; you can redistribute  it and/or modify it
@@ -146,6 +146,7 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec);
unsigned int mode = 0;
unsigned int format = 0;
+   bool use_pdm = false;
unsigned int invert = 0;
 
dev_dbg(codec->dev, "%s: fmt 0x%08X\n", __func__, fmt);
@@ -187,22 +188,27 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
/* interface format */
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
case SND_SOC_DAIFMT_I2S:
-   max98927->iface |= SND_SOC_DAIFMT_I2S;
format = MAX98927_PCM_FORMAT_I2S;
break;
case SND_SOC_DAIFMT_LEFT_J:
-   max98927->iface |= SND_SOC_DAIFMT_LEFT_J;
format = MAX98927_PCM_FORMAT_LJ;
break;
+   case SND_SOC_DAIFMT_DSP_A:
+   format = MAX98927_PCM_FORMAT_TDM_MODE1;
+   break;
+   case SND_SOC_DAIFMT_DSP_B:
+   format = MAX98927_PCM_FORMAT_TDM_MODE0;
+   break;
case SND_SOC_DAIFMT_PDM:
-   max98927->iface |= SND_SOC_DAIFMT_PDM;
+   use_pdm = true;
break;
default:
return -EINVAL;
}
+   max98927->iface = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
 
-   /* pcm channel configuration */
-   if (max98927->iface & (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_LEFT_J)) {
+   if (!use_pdm) {
+   /* pcm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0018_PCM_RX_EN_A,
MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN,
@@ -217,13 +223,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 0);
 
-   } else
regmap_update_bits(max98927->regmap,
-   MAX98927_R0018_PCM_RX_EN_A,
-   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
-
-   /* pdm channel configuration */
-   if (max98927->iface & SND_SOC_DAIFMT_PDM) {
+   MAX98927_R0035_PDM_RX_CTRL,
+   MAX98927_PDM_RX_EN_MASK, 0);
+   } else {
+   /* pdm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0035_PDM_RX_CTRL,
MAX98927_PDM_RX_EN_MASK, 1);
@@ -231,10 +235,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
regmap_update_bits(max98927->regmap,
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 3);
-   } else
+
regmap_update_bits(max98927->regmap,
-   MAX98927_R0035_PDM_RX_CTRL,
-   MAX98927_PDM_RX_EN_MASK, 0);
+   MAX98927_R0018_PCM_RX_EN_A,
+   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
+   }
return 0;
 }
 
diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h
index ece6a60..bf7a6f92 100644
--- a/sound/soc/codecs/max98927.h
+++ b/sound/soc/codecs/max98927.h
@@ -1,7 +1,7 @@
 /*
  * max98927.h  --  MAX98927 ALSA Soc Audio driver
  *
- * Copyright 2013-15 Maxim Integrated Products
+ * Copyright (C) 2016-2017 Maxim Integrated Products
  * Author: Ryan Lee 
  *
  *  This program is free software; you can redistribute  it and/or modify it
@@ -161,7 +161,9 @@
 #define MAX98927_PCM_MODE_CFG_FORMAT_SHIFT (3)
 #define MAX98927_PCM_FORMAT_I2S (0x0 << 0)
 #define MAX98927_PCM_FORMAT_LJ (0x1 << 0)
-
+#define MAX98927_PCM_FORMAT_TDM_MODE0 (0x3 << 0)
+#define MAX98927_PCM_FORMAT_TDM_MODE1 (0x4 << 0)
+#define MAX98927_PCM_FORMAT_TDM_MODE2 (0x5 << 0)
 #define MAX98927_PCM_MODE_CFG_CHANSZ_MASK (0x3 << 6)
 #define MAX98927_PCM_MODE_CFG_CHANSZ_16 (0x1 << 6)
 #define MAX98927_PCM_MODE_CFG_CHANSZ_24 (0x2 << 6)
-- 
2.7.4



RE: [PATCH 1/3] ASoC: max98927: Added support for DSP_A and DSP_B format

2017-09-14 Thread Ryan Lee
>-Original Message-
>From: Mark Brown [mailto:broo...@kernel.org]
>Sent: Thursday, September 14, 2017 11:50 AM
>To: Ryan Lee <ryans@maximintegrated.com>
>Cc: lgirdw...@gmail.com; pe...@perex.cz; ti...@suse.com;
>kuninori.morimoto...@renesas.com; alsa-de...@alsa-project.org; linux-
>ker...@vger.kernel.org; ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH 1/3] ASoC: max98927: Added support for DSP_A and
>DSP_B format
>
>On Mon, Sep 11, 2017 at 09:12:18AM -0700, Ryan Lee wrote:
>> Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
>> ---
>
>Please make an effort to write changelogs that clearly describe the change
>you're making.  This is doing way more than just implementing DSP mode, it's
>also adding a fairly complicated set_tdm_slot() implementation which isn't
>mentioned at all.  It probably needs splitting into multiple patches as well.

I split this patch as two separated patches and sent again.
One is about adding DSP_A, DSP_B support.
Another is about TDM slot configuration.
I added more changelog inside.

>
>> @@ -414,6 +504,9 @@ static int max98927_dac_event(struct
>snd_soc_dapm_widget *w,
>>  struct max98927_priv *max98927 =
>snd_soc_codec_get_drvdata(codec);
>>
>>  switch (event) {
>> +case SND_SOC_DAPM_PRE_PMU:
>> +max98927->tdm_mode = 0;
>> +break;
>>  case SND_SOC_DAPM_POST_PMU:
>>  regmap_update_bits(max98927->regmap,
>>  MAX98927_R003A_AMP_EN,
>
>Why is an event associated with the DAC changing something related to the DAI
>format?  These things should be unrelated.

In TDM mode, BCLK is being configured inside 'max98927_dai_tdm_slot' because 
TDM slot information(number of slots, slot width) is available in there.
In normal case, BCLK is being configured when 'hw_params' is called and TDM 
slot information is not available in this function.
So I added 'tdm_mode' variable to avoid overwrite BCLK configuration when 
'hw_params' function is called after TDM slot configuration is done.
I wanted to clear this variable once playback is over so I added clear function 
when DAPM event is received.
I referred some codec driver change TDM related things when DAC event is 
received after TDM slot configuration is done.


RE: [PATCH 1/3] ASoC: max98927: Added support for DSP_A and DSP_B format

2017-09-14 Thread Ryan Lee
>-Original Message-
>From: Mark Brown [mailto:broo...@kernel.org]
>Sent: Thursday, September 14, 2017 11:50 AM
>To: Ryan Lee 
>Cc: lgirdw...@gmail.com; pe...@perex.cz; ti...@suse.com;
>kuninori.morimoto...@renesas.com; alsa-de...@alsa-project.org; linux-
>ker...@vger.kernel.org; ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH 1/3] ASoC: max98927: Added support for DSP_A and
>DSP_B format
>
>On Mon, Sep 11, 2017 at 09:12:18AM -0700, Ryan Lee wrote:
>> Signed-off-by: Ryan Lee 
>> ---
>
>Please make an effort to write changelogs that clearly describe the change
>you're making.  This is doing way more than just implementing DSP mode, it's
>also adding a fairly complicated set_tdm_slot() implementation which isn't
>mentioned at all.  It probably needs splitting into multiple patches as well.

I split this patch as two separated patches and sent again.
One is about adding DSP_A, DSP_B support.
Another is about TDM slot configuration.
I added more changelog inside.

>
>> @@ -414,6 +504,9 @@ static int max98927_dac_event(struct
>snd_soc_dapm_widget *w,
>>  struct max98927_priv *max98927 =
>snd_soc_codec_get_drvdata(codec);
>>
>>  switch (event) {
>> +case SND_SOC_DAPM_PRE_PMU:
>> +max98927->tdm_mode = 0;
>> +break;
>>  case SND_SOC_DAPM_POST_PMU:
>>  regmap_update_bits(max98927->regmap,
>>  MAX98927_R003A_AMP_EN,
>
>Why is an event associated with the DAC changing something related to the DAI
>format?  These things should be unrelated.

In TDM mode, BCLK is being configured inside 'max98927_dai_tdm_slot' because 
TDM slot information(number of slots, slot width) is available in there.
In normal case, BCLK is being configured when 'hw_params' is called and TDM 
slot information is not available in this function.
So I added 'tdm_mode' variable to avoid overwrite BCLK configuration when 
'hw_params' function is called after TDM slot configuration is done.
I wanted to clear this variable once playback is over so I added clear function 
when DAPM event is received.
I referred some codec driver change TDM related things when DAC event is 
received after TDM slot configuration is done.


[PATCH 3/3] ASoC: max98927: Removed obsolete variables

2017-09-11 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
Changelog:
Removed obsolete variables that have never been referred from driver before.

 sound/soc/codecs/max98927.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h
index 98b5f17..d215f60 100644
--- a/sound/soc/codecs/max98927.h
+++ b/sound/soc/codecs/max98927.h
@@ -263,17 +263,13 @@
 struct max98927_priv {
struct regmap *regmap;
struct snd_soc_codec *codec;
-   struct max98927_pdata *pdata;
-   unsigned int spk_gain;
unsigned int sysclk;
unsigned int v_l_slot;
unsigned int i_l_slot;
bool interleave_mode;
unsigned int ch_size;
-   unsigned int rate;
unsigned int iface;
unsigned int master;
-   unsigned int digital_gain;
bool tdm_mode;
 };
 #endif
-- 
1.9.1



[PATCH 3/3] ASoC: max98927: Removed obsolete variables

2017-09-11 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changelog:
Removed obsolete variables that have never been referred from driver before.

 sound/soc/codecs/max98927.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h
index 98b5f17..d215f60 100644
--- a/sound/soc/codecs/max98927.h
+++ b/sound/soc/codecs/max98927.h
@@ -263,17 +263,13 @@
 struct max98927_priv {
struct regmap *regmap;
struct snd_soc_codec *codec;
-   struct max98927_pdata *pdata;
-   unsigned int spk_gain;
unsigned int sysclk;
unsigned int v_l_slot;
unsigned int i_l_slot;
bool interleave_mode;
unsigned int ch_size;
-   unsigned int rate;
unsigned int iface;
unsigned int master;
-   unsigned int digital_gain;
bool tdm_mode;
 };
 #endif
-- 
1.9.1



[PATCH 1/3] ASoC: max98927: Added support for DSP_A and DSP_B format

2017-09-11 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
Changelog: 
Added support for DSP_A and DSP_B format
Added 'max98927_dai_tdm_slot' function to set proper slot configuration.
Moved max98927->iface out of switch statement to avoid line duplication.
Added variable 'tdm_mode' to avoid BCLK overwrite after 'max98927_dai_tdm_slot' 
configure BCLK value.

 sound/soc/codecs/max98927.c | 155 +++-
 sound/soc/codecs/max98927.h |   7 +-
 2 files changed, 129 insertions(+), 33 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index d9dbbe7..a1d3935 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -1,7 +1,7 @@
 /*
  * max98927.c  --  MAX98927 ALSA Soc Audio driver
  *
- * Copyright (C) 2016 Maxim Integrated Products
+ * Copyright (C) 2016-2017 Maxim Integrated Products
  * Author: Ryan Lee <ryans@maximintegrated.com>
  *
  *  This program is free software; you can redistribute  it and/or modify it
@@ -146,6 +146,7 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec);
unsigned int mode = 0;
unsigned int format = 0;
+   bool use_pdm = false;
unsigned int invert = 0;
 
dev_dbg(codec->dev, "%s: fmt 0x%08X\n", __func__, fmt);
@@ -187,22 +188,27 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
/* interface format */
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
case SND_SOC_DAIFMT_I2S:
-   max98927->iface |= SND_SOC_DAIFMT_I2S;
format = MAX98927_PCM_FORMAT_I2S;
break;
case SND_SOC_DAIFMT_LEFT_J:
-   max98927->iface |= SND_SOC_DAIFMT_LEFT_J;
format = MAX98927_PCM_FORMAT_LJ;
break;
+   case SND_SOC_DAIFMT_DSP_A:
+   format = MAX98927_PCM_FORMAT_TDM_MODE1;
+   break;
+   case SND_SOC_DAIFMT_DSP_B:
+   format = MAX98927_PCM_FORMAT_TDM_MODE0;
+   break;
case SND_SOC_DAIFMT_PDM:
-   max98927->iface |= SND_SOC_DAIFMT_PDM;
+   use_pdm = true;
break;
default:
return -EINVAL;
}
+   max98927->iface = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
 
-   /* pcm channel configuration */
-   if (max98927->iface & (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_LEFT_J)) {
+   if (!use_pdm) {
+   /* pcm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0018_PCM_RX_EN_A,
MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN,
@@ -217,13 +223,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 0);
 
-   } else
regmap_update_bits(max98927->regmap,
-   MAX98927_R0018_PCM_RX_EN_A,
-   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
-
-   /* pdm channel configuration */
-   if (max98927->iface & SND_SOC_DAIFMT_PDM) {
+   MAX98927_R0035_PDM_RX_CTRL,
+   MAX98927_PDM_RX_EN_MASK, 0);
+   } else {
+   /* pdm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0035_PDM_RX_CTRL,
MAX98927_PDM_RX_EN_MASK, 1);
@@ -231,10 +235,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
regmap_update_bits(max98927->regmap,
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 3);
-   } else
+
regmap_update_bits(max98927->regmap,
-   MAX98927_R0035_PDM_RX_CTRL,
-   MAX98927_PDM_RX_EN_MASK, 0);
+   MAX98927_R0018_PCM_RX_EN_A,
+   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
+   }
return 0;
 }
 
@@ -245,6 +250,21 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
1300, 1920,
 };
 
+/* BCLKs per LRCLK */
+static const int bclk_sel_table[] = {
+   32, 48, 64, 96, 128, 192, 256, 384, 512,
+};
+
+static int max98927_get_bclk_sel(int bclk)
+{
+   int i;
+   /* match BCLKs per LRCLK */
+   for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) {
+   if (bclk_sel_table[i] == bclk)
+   return i + 2;
+   }
+   return 0;
+}
 static int max98927_set_clock(struct max98927_priv *max98927,
struct snd_pcm_hw_params *params)
 {
@@ -270,23 +290,20 @@ static int max98927_set_clock(struct max98927_priv 

[PATCH 1/3] ASoC: max98927: Added support for DSP_A and DSP_B format

2017-09-11 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changelog: 
Added support for DSP_A and DSP_B format
Added 'max98927_dai_tdm_slot' function to set proper slot configuration.
Moved max98927->iface out of switch statement to avoid line duplication.
Added variable 'tdm_mode' to avoid BCLK overwrite after 'max98927_dai_tdm_slot' 
configure BCLK value.

 sound/soc/codecs/max98927.c | 155 +++-
 sound/soc/codecs/max98927.h |   7 +-
 2 files changed, 129 insertions(+), 33 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index d9dbbe7..a1d3935 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -1,7 +1,7 @@
 /*
  * max98927.c  --  MAX98927 ALSA Soc Audio driver
  *
- * Copyright (C) 2016 Maxim Integrated Products
+ * Copyright (C) 2016-2017 Maxim Integrated Products
  * Author: Ryan Lee 
  *
  *  This program is free software; you can redistribute  it and/or modify it
@@ -146,6 +146,7 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec);
unsigned int mode = 0;
unsigned int format = 0;
+   bool use_pdm = false;
unsigned int invert = 0;
 
dev_dbg(codec->dev, "%s: fmt 0x%08X\n", __func__, fmt);
@@ -187,22 +188,27 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
/* interface format */
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
case SND_SOC_DAIFMT_I2S:
-   max98927->iface |= SND_SOC_DAIFMT_I2S;
format = MAX98927_PCM_FORMAT_I2S;
break;
case SND_SOC_DAIFMT_LEFT_J:
-   max98927->iface |= SND_SOC_DAIFMT_LEFT_J;
format = MAX98927_PCM_FORMAT_LJ;
break;
+   case SND_SOC_DAIFMT_DSP_A:
+   format = MAX98927_PCM_FORMAT_TDM_MODE1;
+   break;
+   case SND_SOC_DAIFMT_DSP_B:
+   format = MAX98927_PCM_FORMAT_TDM_MODE0;
+   break;
case SND_SOC_DAIFMT_PDM:
-   max98927->iface |= SND_SOC_DAIFMT_PDM;
+   use_pdm = true;
break;
default:
return -EINVAL;
}
+   max98927->iface = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
 
-   /* pcm channel configuration */
-   if (max98927->iface & (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_LEFT_J)) {
+   if (!use_pdm) {
+   /* pcm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0018_PCM_RX_EN_A,
MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN,
@@ -217,13 +223,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 0);
 
-   } else
regmap_update_bits(max98927->regmap,
-   MAX98927_R0018_PCM_RX_EN_A,
-   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
-
-   /* pdm channel configuration */
-   if (max98927->iface & SND_SOC_DAIFMT_PDM) {
+   MAX98927_R0035_PDM_RX_CTRL,
+   MAX98927_PDM_RX_EN_MASK, 0);
+   } else {
+   /* pdm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0035_PDM_RX_CTRL,
MAX98927_PDM_RX_EN_MASK, 1);
@@ -231,10 +235,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
regmap_update_bits(max98927->regmap,
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 3);
-   } else
+
regmap_update_bits(max98927->regmap,
-   MAX98927_R0035_PDM_RX_CTRL,
-   MAX98927_PDM_RX_EN_MASK, 0);
+   MAX98927_R0018_PCM_RX_EN_A,
+   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
+   }
return 0;
 }
 
@@ -245,6 +250,21 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
1300, 1920,
 };
 
+/* BCLKs per LRCLK */
+static const int bclk_sel_table[] = {
+   32, 48, 64, 96, 128, 192, 256, 384, 512,
+};
+
+static int max98927_get_bclk_sel(int bclk)
+{
+   int i;
+   /* match BCLKs per LRCLK */
+   for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) {
+   if (bclk_sel_table[i] == bclk)
+   return i + 2;
+   }
+   return 0;
+}
 static int max98927_set_clock(struct max98927_priv *max98927,
struct snd_pcm_hw_params *params)
 {
@@ -270,23 +290,20 @@ static int max98927_set_clock(struct max98927_priv 
*max98927,
i << MAX98927_PCM_MASTER_MODE_MCLK

[PATCH 2/3] ASoC: max98927: Added controls for Envelope tracking

2017-09-11 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
Changelog:
Added a control("EnvTrack Headroom") to set different headroom value for 
envelop tracking function.
Added one more control for envelop tracking function enable/disable("EnvTrack 
Switch").
Removed writing process to register 0x0087 because it is read only register.

 sound/soc/codecs/max98927.c | 19 +++
 sound/soc/codecs/max98927.h |  4 
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index a1d3935..73c7a33 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -624,6 +624,18 @@ static SOC_ENUM_SINGLE_DECL(max98927_current_limit,
MAX98927_R0042_BOOST_CTRL1, 1,
max98927_current_limit_text);
 
+static const char * const max98927_env_track_headroom_text[] = {
+   "0.000V", "0.125V", "0.250V", "0.375V", "0.500V", "0.625V",
+   "0.750V", "0.875V", "1.000V", "1.125V", "1.250V", "1.375V",
+   "1.500V", "1.625V", "1.750V", "1.875V", "2.000V", "2.125V",
+   "2.250V", "2.375V", "2.500V", "2.625V", "2.750V", "2.875V",
+   "3.000V", "3.125V", "3.250V", "3.375V", "3.500V"
+};
+
+static SOC_ENUM_SINGLE_DECL(max98927_env_track_headroom,
+   MAX98927_R0082_ENV_TRACK_VOUT_HEADROOM, 0,
+   max98927_env_track_headroom_text);
+
 static const struct snd_kcontrol_new max98927_snd_controls[] = {
SOC_SINGLE_TLV("Speaker Volume", MAX98927_R003C_SPK_GAIN,
0, 6, 0,
@@ -641,6 +653,9 @@ static SOC_ENUM_SINGLE_DECL(max98927_current_limit,
MAX98927_AMP_VOL_SEL_SHIFT, 1, 0),
SOC_ENUM("Boost Output Voltage", max98927_boost_voltage),
SOC_ENUM("Current Limit", max98927_current_limit),
+   SOC_SINGLE("EnvTrack Switch", MAX98927_R0086_ENV_TRACK_CTRL,
+   MAX98927_ENV_TRACKER_EN_SHIFT, 1, 0),
+   SOC_ENUM("EnvTrack Headroom", max98927_env_track_headroom),
 };
 
 static const struct snd_soc_dapm_route max98927_audio_map[] = {
@@ -744,10 +759,6 @@ static int max98927_probe(struct snd_soc_codec *codec)
regmap_write(max98927->regmap,
MAX98927_R0086_ENV_TRACK_CTRL,
0x01);
-   regmap_write(max98927->regmap,
-   MAX98927_R0087_ENV_TRACK_BOOST_VOUT_READ,
-   0x10);
-
/* voltage, current slot configuration */
regmap_write(max98927->regmap,
MAX98927_R001E_PCM_TX_CH_SRC_A,
diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h
index 9ea8397..98b5f17 100644
--- a/sound/soc/codecs/max98927.h
+++ b/sound/soc/codecs/max98927.h
@@ -250,6 +250,10 @@
 #define MAX98927_BROWNOUT_DSP_EN (0x1 << 2)
 #define MAX98927_BROWNOUT_DSP_SHIFT (2)
 
+/* MAX98927_R0086_ENV_TRACK_CTRL */
+#define MAX98927_ENV_TRACKER_EN (0x1 << 0)
+#define MAX98927_ENV_TRACKER_EN_SHIFT (0)
+
 /* MAX98927_R0100_SOFT_RESET */
 #define MAX98927_SOFT_RESET (0x1 << 0)
 
-- 
1.9.1



[PATCH 2/3] ASoC: max98927: Added controls for Envelope tracking

2017-09-11 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changelog:
Added a control("EnvTrack Headroom") to set different headroom value for 
envelop tracking function.
Added one more control for envelop tracking function enable/disable("EnvTrack 
Switch").
Removed writing process to register 0x0087 because it is read only register.

 sound/soc/codecs/max98927.c | 19 +++
 sound/soc/codecs/max98927.h |  4 
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index a1d3935..73c7a33 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -624,6 +624,18 @@ static SOC_ENUM_SINGLE_DECL(max98927_current_limit,
MAX98927_R0042_BOOST_CTRL1, 1,
max98927_current_limit_text);
 
+static const char * const max98927_env_track_headroom_text[] = {
+   "0.000V", "0.125V", "0.250V", "0.375V", "0.500V", "0.625V",
+   "0.750V", "0.875V", "1.000V", "1.125V", "1.250V", "1.375V",
+   "1.500V", "1.625V", "1.750V", "1.875V", "2.000V", "2.125V",
+   "2.250V", "2.375V", "2.500V", "2.625V", "2.750V", "2.875V",
+   "3.000V", "3.125V", "3.250V", "3.375V", "3.500V"
+};
+
+static SOC_ENUM_SINGLE_DECL(max98927_env_track_headroom,
+   MAX98927_R0082_ENV_TRACK_VOUT_HEADROOM, 0,
+   max98927_env_track_headroom_text);
+
 static const struct snd_kcontrol_new max98927_snd_controls[] = {
SOC_SINGLE_TLV("Speaker Volume", MAX98927_R003C_SPK_GAIN,
0, 6, 0,
@@ -641,6 +653,9 @@ static SOC_ENUM_SINGLE_DECL(max98927_current_limit,
MAX98927_AMP_VOL_SEL_SHIFT, 1, 0),
SOC_ENUM("Boost Output Voltage", max98927_boost_voltage),
SOC_ENUM("Current Limit", max98927_current_limit),
+   SOC_SINGLE("EnvTrack Switch", MAX98927_R0086_ENV_TRACK_CTRL,
+   MAX98927_ENV_TRACKER_EN_SHIFT, 1, 0),
+   SOC_ENUM("EnvTrack Headroom", max98927_env_track_headroom),
 };
 
 static const struct snd_soc_dapm_route max98927_audio_map[] = {
@@ -744,10 +759,6 @@ static int max98927_probe(struct snd_soc_codec *codec)
regmap_write(max98927->regmap,
MAX98927_R0086_ENV_TRACK_CTRL,
0x01);
-   regmap_write(max98927->regmap,
-   MAX98927_R0087_ENV_TRACK_BOOST_VOUT_READ,
-   0x10);
-
/* voltage, current slot configuration */
regmap_write(max98927->regmap,
MAX98927_R001E_PCM_TX_CH_SRC_A,
diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h
index 9ea8397..98b5f17 100644
--- a/sound/soc/codecs/max98927.h
+++ b/sound/soc/codecs/max98927.h
@@ -250,6 +250,10 @@
 #define MAX98927_BROWNOUT_DSP_EN (0x1 << 2)
 #define MAX98927_BROWNOUT_DSP_SHIFT (2)
 
+/* MAX98927_R0086_ENV_TRACK_CTRL */
+#define MAX98927_ENV_TRACKER_EN (0x1 << 0)
+#define MAX98927_ENV_TRACKER_EN_SHIFT (0)
+
 /* MAX98927_R0100_SOFT_RESET */
 #define MAX98927_SOFT_RESET (0x1 << 0)
 
-- 
1.9.1



RE: [PATCH 2/9] ASoC: max98927: Added controls for Envelope tracking

2017-09-01 Thread Ryan Lee
>-Original Message-
>From: Mark Brown [mailto:broo...@kernel.org]
>Sent: Thursday, August 31, 2017 4:44 AM
>To: Ryan Lee <ryans@maximintegrated.com>
>Cc: lgirdw...@gmail.com; pe...@perex.cz; ti...@suse.com;
>kuninori.morimoto...@renesas.com; alsa-de...@alsa-project.org; linux-
>ker...@vger.kernel.org; ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH 2/9] ASoC: max98927: Added controls for Envelope tracking
>
>On Mon, Aug 28, 2017 at 04:30:54PM -0700, Ryan Lee wrote:
>
>>  /* Envelope Tracking configuration */
>>  regmap_write(max98927->regmap,
>>  MAX98927_R0082_ENV_TRACK_VOUT_HEADROOM,
>> -0x08);
>> +0x0A);
>>  regmap_write(max98927->regmap,
>>  MAX98927_R0086_ENV_TRACK_CTRL,
>>  0x01);
>> -regmap_write(max98927->regmap,
>> -MAX98927_R0087_ENV_TRACK_BOOST_VOUT_READ,
>> -0x10);
>
>Why are we changing the defaults here?  It was understandable to have a fixed
>default that differed from the chip value when there was no control but now
>there is a control and we're changing the default again for some undocumented
>reason.  It'd be better to leave the values here to avoid breaking 
>compatibility
>with existing users and let users who need different values change things using
>the newly added controls.

Thank you for feedback. Let me keep existing value.
I still need to remove regmap_write for R:0x87 because it is read-only register.



RE: [PATCH 5/9] ASoC: max98927: Removed obsolete variables

2017-09-01 Thread Ryan Lee
>-Original Message-
>From: Mark Brown [mailto:broo...@kernel.org]
>Sent: Thursday, August 31, 2017 4:54 AM
>To: Ryan Lee <ryans@maximintegrated.com>
>Cc: lgirdw...@gmail.com; pe...@perex.cz; ti...@suse.com;
>kuninori.morimoto...@renesas.com; alsa-de...@alsa-project.org; linux-
>ker...@vger.kernel.org; ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH 5/9] ASoC: max98927: Removed obsolete variables
>
>On Mon, Aug 28, 2017 at 04:30:57PM -0700, Ryan Lee wrote:
>> Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
>
>Why are these variables obsolete?  If their use was removed in earlier patches 
>in
>the series they should be handled in that patch, if they're just unused say 
>so.  In
>general your changelogs could really benefit from being a bit longer and
>explaining why changes are being made.
>
>>  mode change 100644 => 100755 sound/soc/codecs/max98927.h
>
>This also changes the permissions to be executable which isn't what we want.

Thank you for your comment.
I wanted to remove these variables because it have never been referred in 
max98927.c from the beginning.


RE: [PATCH 2/9] ASoC: max98927: Added controls for Envelope tracking

2017-09-01 Thread Ryan Lee
>-Original Message-
>From: Mark Brown [mailto:broo...@kernel.org]
>Sent: Thursday, August 31, 2017 4:44 AM
>To: Ryan Lee 
>Cc: lgirdw...@gmail.com; pe...@perex.cz; ti...@suse.com;
>kuninori.morimoto...@renesas.com; alsa-de...@alsa-project.org; linux-
>ker...@vger.kernel.org; ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH 2/9] ASoC: max98927: Added controls for Envelope tracking
>
>On Mon, Aug 28, 2017 at 04:30:54PM -0700, Ryan Lee wrote:
>
>>  /* Envelope Tracking configuration */
>>  regmap_write(max98927->regmap,
>>  MAX98927_R0082_ENV_TRACK_VOUT_HEADROOM,
>> -0x08);
>> +0x0A);
>>  regmap_write(max98927->regmap,
>>  MAX98927_R0086_ENV_TRACK_CTRL,
>>  0x01);
>> -regmap_write(max98927->regmap,
>> -MAX98927_R0087_ENV_TRACK_BOOST_VOUT_READ,
>> -0x10);
>
>Why are we changing the defaults here?  It was understandable to have a fixed
>default that differed from the chip value when there was no control but now
>there is a control and we're changing the default again for some undocumented
>reason.  It'd be better to leave the values here to avoid breaking 
>compatibility
>with existing users and let users who need different values change things using
>the newly added controls.

Thank you for feedback. Let me keep existing value.
I still need to remove regmap_write for R:0x87 because it is read-only register.



RE: [PATCH 5/9] ASoC: max98927: Removed obsolete variables

2017-09-01 Thread Ryan Lee
>-Original Message-
>From: Mark Brown [mailto:broo...@kernel.org]
>Sent: Thursday, August 31, 2017 4:54 AM
>To: Ryan Lee 
>Cc: lgirdw...@gmail.com; pe...@perex.cz; ti...@suse.com;
>kuninori.morimoto...@renesas.com; alsa-de...@alsa-project.org; linux-
>ker...@vger.kernel.org; ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH 5/9] ASoC: max98927: Removed obsolete variables
>
>On Mon, Aug 28, 2017 at 04:30:57PM -0700, Ryan Lee wrote:
>> Signed-off-by: Ryan Lee 
>
>Why are these variables obsolete?  If their use was removed in earlier patches 
>in
>the series they should be handled in that patch, if they're just unused say 
>so.  In
>general your changelogs could really benefit from being a bit longer and
>explaining why changes are being made.
>
>>  mode change 100644 => 100755 sound/soc/codecs/max98927.h
>
>This also changes the permissions to be executable which isn't what we want.

Thank you for your comment.
I wanted to remove these variables because it have never been referred in 
max98927.c from the beginning.


RE: [PATCH 1/9] ASoC: max98927: Added support for DSP_A and DSP_B format

2017-09-01 Thread Ryan Lee
>-Original Message-
>From: Mark Brown [mailto:broo...@kernel.org]
>Sent: Tuesday, August 29, 2017 12:00 PM
>To: Ryan Lee <ryans@maximintegrated.com>
>Cc: lgirdw...@gmail.com; pe...@perex.cz; ti...@suse.com;
>kuninori.morimoto...@renesas.com; alsa-de...@alsa-project.org; linux-
>ker...@vger.kernel.org; ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH 1/9] ASoC: max98927: Added support for DSP_A and DSP_B
>format
>
>On Mon, Aug 28, 2017 at 04:30:53PM -0700, Ryan Lee wrote:
>
>> +if ((max98927->iface == SND_SOC_DAIFMT_DSP_A) ||
>> +(max98927->iface == SND_SOC_DAIFMT_DSP_B))
>> +return 0;
>> +
>> +/* BCLK configuration */
>
>Why do we not configure the BCLK in DSP modes?  That's unusual and seems
>likely to break some systems that rely on exact clocking.

I put this code to avoid overwrite BCLK value in TDM mode. BCLK is being 
configured by ' max98927_dai_tdm_slot'.
Now I added one more variable to check TDM mode instead of checking DAI_FMT.

>
>Also if we're selecting on format a switch statement is generally better to 
>make
>any further special casing easier in future.

OK. Thanks. But I kept if statement on the modified version because it only 
have two cases, tdm and non-tdm.


RE: [PATCH 1/9] ASoC: max98927: Added support for DSP_A and DSP_B format

2017-09-01 Thread Ryan Lee
>-Original Message-
>From: Mark Brown [mailto:broo...@kernel.org]
>Sent: Tuesday, August 29, 2017 12:00 PM
>To: Ryan Lee 
>Cc: lgirdw...@gmail.com; pe...@perex.cz; ti...@suse.com;
>kuninori.morimoto...@renesas.com; alsa-de...@alsa-project.org; linux-
>ker...@vger.kernel.org; ryan.lee.ma...@gmail.com
>Subject: Re: [PATCH 1/9] ASoC: max98927: Added support for DSP_A and DSP_B
>format
>
>On Mon, Aug 28, 2017 at 04:30:53PM -0700, Ryan Lee wrote:
>
>> +if ((max98927->iface == SND_SOC_DAIFMT_DSP_A) ||
>> +(max98927->iface == SND_SOC_DAIFMT_DSP_B))
>> +return 0;
>> +
>> +/* BCLK configuration */
>
>Why do we not configure the BCLK in DSP modes?  That's unusual and seems
>likely to break some systems that rely on exact clocking.

I put this code to avoid overwrite BCLK value in TDM mode. BCLK is being 
configured by ' max98927_dai_tdm_slot'.
Now I added one more variable to check TDM mode instead of checking DAI_FMT.

>
>Also if we're selecting on format a switch statement is generally better to 
>make
>any further special casing easier in future.

OK. Thanks. But I kept if statement on the modified version because it only 
have two cases, tdm and non-tdm.


[PATCH 1/3] ASoC: max98927: Added support for DSP_A and DSP_B format

2017-09-01 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
Changelog: 
Added support for DSP_A and DSP_B format
Added 'max98927_dai_tdm_slot' function to configure for proper slot 
configuration.
Moved max98927->iface out of switch statement to avoid line duplication.
Added variable 'tdm_mode' to avoid BCLK overwrite after 
'max98927_dai_tdm_slot' configure right BCLK value.

 sound/soc/codecs/max98927.c | 155 +++-
 sound/soc/codecs/max98927.h |   7 +-
 2 files changed, 129 insertions(+), 33 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index d9dbbe7..a1d3935 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -1,7 +1,7 @@
 /*
  * max98927.c  --  MAX98927 ALSA Soc Audio driver
  *
- * Copyright (C) 2016 Maxim Integrated Products
+ * Copyright (C) 2016-2017 Maxim Integrated Products
  * Author: Ryan Lee <ryans@maximintegrated.com>
  *
  *  This program is free software; you can redistribute  it and/or modify it
@@ -146,6 +146,7 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec);
unsigned int mode = 0;
unsigned int format = 0;
+   bool use_pdm = false;
unsigned int invert = 0;
 
dev_dbg(codec->dev, "%s: fmt 0x%08X\n", __func__, fmt);
@@ -187,22 +188,27 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
/* interface format */
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
case SND_SOC_DAIFMT_I2S:
-   max98927->iface |= SND_SOC_DAIFMT_I2S;
format = MAX98927_PCM_FORMAT_I2S;
break;
case SND_SOC_DAIFMT_LEFT_J:
-   max98927->iface |= SND_SOC_DAIFMT_LEFT_J;
format = MAX98927_PCM_FORMAT_LJ;
break;
+   case SND_SOC_DAIFMT_DSP_A:
+   format = MAX98927_PCM_FORMAT_TDM_MODE1;
+   break;
+   case SND_SOC_DAIFMT_DSP_B:
+   format = MAX98927_PCM_FORMAT_TDM_MODE0;
+   break;
case SND_SOC_DAIFMT_PDM:
-   max98927->iface |= SND_SOC_DAIFMT_PDM;
+   use_pdm = true;
break;
default:
return -EINVAL;
}
+   max98927->iface = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
 
-   /* pcm channel configuration */
-   if (max98927->iface & (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_LEFT_J)) {
+   if (!use_pdm) {
+   /* pcm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0018_PCM_RX_EN_A,
MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN,
@@ -217,13 +223,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 0);
 
-   } else
regmap_update_bits(max98927->regmap,
-   MAX98927_R0018_PCM_RX_EN_A,
-   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
-
-   /* pdm channel configuration */
-   if (max98927->iface & SND_SOC_DAIFMT_PDM) {
+   MAX98927_R0035_PDM_RX_CTRL,
+   MAX98927_PDM_RX_EN_MASK, 0);
+   } else {
+   /* pdm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0035_PDM_RX_CTRL,
MAX98927_PDM_RX_EN_MASK, 1);
@@ -231,10 +235,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
regmap_update_bits(max98927->regmap,
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 3);
-   } else
+
regmap_update_bits(max98927->regmap,
-   MAX98927_R0035_PDM_RX_CTRL,
-   MAX98927_PDM_RX_EN_MASK, 0);
+   MAX98927_R0018_PCM_RX_EN_A,
+   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
+   }
return 0;
 }
 
@@ -245,6 +250,21 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
1300, 1920,
 };
 
+/* BCLKs per LRCLK */
+static const int bclk_sel_table[] = {
+   32, 48, 64, 96, 128, 192, 256, 384, 512,
+};
+
+static int max98927_get_bclk_sel(int bclk)
+{
+   int i;
+   /* match BCLKs per LRCLK */
+   for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) {
+   if (bclk_sel_table[i] == bclk)
+   return i + 2;
+   }
+   return 0;
+}
 static int max98927_set_clock(struct max98927_priv *max98927,
struct snd_pcm_hw_params *params)
 {
@@ -270,23 +290,20 @@ static i

[PATCH 1/3] ASoC: max98927: Added support for DSP_A and DSP_B format

2017-09-01 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changelog: 
Added support for DSP_A and DSP_B format
Added 'max98927_dai_tdm_slot' function to configure for proper slot 
configuration.
Moved max98927->iface out of switch statement to avoid line duplication.
Added variable 'tdm_mode' to avoid BCLK overwrite after 
'max98927_dai_tdm_slot' configure right BCLK value.

 sound/soc/codecs/max98927.c | 155 +++-
 sound/soc/codecs/max98927.h |   7 +-
 2 files changed, 129 insertions(+), 33 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index d9dbbe7..a1d3935 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -1,7 +1,7 @@
 /*
  * max98927.c  --  MAX98927 ALSA Soc Audio driver
  *
- * Copyright (C) 2016 Maxim Integrated Products
+ * Copyright (C) 2016-2017 Maxim Integrated Products
  * Author: Ryan Lee 
  *
  *  This program is free software; you can redistribute  it and/or modify it
@@ -146,6 +146,7 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec);
unsigned int mode = 0;
unsigned int format = 0;
+   bool use_pdm = false;
unsigned int invert = 0;
 
dev_dbg(codec->dev, "%s: fmt 0x%08X\n", __func__, fmt);
@@ -187,22 +188,27 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
/* interface format */
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
case SND_SOC_DAIFMT_I2S:
-   max98927->iface |= SND_SOC_DAIFMT_I2S;
format = MAX98927_PCM_FORMAT_I2S;
break;
case SND_SOC_DAIFMT_LEFT_J:
-   max98927->iface |= SND_SOC_DAIFMT_LEFT_J;
format = MAX98927_PCM_FORMAT_LJ;
break;
+   case SND_SOC_DAIFMT_DSP_A:
+   format = MAX98927_PCM_FORMAT_TDM_MODE1;
+   break;
+   case SND_SOC_DAIFMT_DSP_B:
+   format = MAX98927_PCM_FORMAT_TDM_MODE0;
+   break;
case SND_SOC_DAIFMT_PDM:
-   max98927->iface |= SND_SOC_DAIFMT_PDM;
+   use_pdm = true;
break;
default:
return -EINVAL;
}
+   max98927->iface = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
 
-   /* pcm channel configuration */
-   if (max98927->iface & (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_LEFT_J)) {
+   if (!use_pdm) {
+   /* pcm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0018_PCM_RX_EN_A,
MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN,
@@ -217,13 +223,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 0);
 
-   } else
regmap_update_bits(max98927->regmap,
-   MAX98927_R0018_PCM_RX_EN_A,
-   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
-
-   /* pdm channel configuration */
-   if (max98927->iface & SND_SOC_DAIFMT_PDM) {
+   MAX98927_R0035_PDM_RX_CTRL,
+   MAX98927_PDM_RX_EN_MASK, 0);
+   } else {
+   /* pdm channel configuration */
regmap_update_bits(max98927->regmap,
MAX98927_R0035_PDM_RX_CTRL,
MAX98927_PDM_RX_EN_MASK, 1);
@@ -231,10 +235,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
regmap_update_bits(max98927->regmap,
MAX98927_R003B_SPK_SRC_SEL,
MAX98927_SPK_SRC_MASK, 3);
-   } else
+
regmap_update_bits(max98927->regmap,
-   MAX98927_R0035_PDM_RX_CTRL,
-   MAX98927_PDM_RX_EN_MASK, 0);
+   MAX98927_R0018_PCM_RX_EN_A,
+   MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
+   }
return 0;
 }
 
@@ -245,6 +250,21 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
1300, 1920,
 };
 
+/* BCLKs per LRCLK */
+static const int bclk_sel_table[] = {
+   32, 48, 64, 96, 128, 192, 256, 384, 512,
+};
+
+static int max98927_get_bclk_sel(int bclk)
+{
+   int i;
+   /* match BCLKs per LRCLK */
+   for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) {
+   if (bclk_sel_table[i] == bclk)
+   return i + 2;
+   }
+   return 0;
+}
 static int max98927_set_clock(struct max98927_priv *max98927,
struct snd_pcm_hw_params *params)
 {
@@ -270,23 +290,20 @@ static int max98927_set_clock(struct max98927_priv 
*max98927,
i << MAX98927_P

[PATCH 2/3] ASoC: max98927: Added controls for Envelope tracking

2017-09-01 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
Changelog:
Added one control to set different headroom value for envelop tracking 
function.
Added one more control to enable/disable envelop tracking function.
Removed writing process to register 0x0087 because it is read only register.

 sound/soc/codecs/max98927.c | 19 +++
 sound/soc/codecs/max98927.h |  4 
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index a1d3935..73c7a33 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -624,6 +624,18 @@ static SOC_ENUM_SINGLE_DECL(max98927_current_limit,
MAX98927_R0042_BOOST_CTRL1, 1,
max98927_current_limit_text);
 
+static const char * const max98927_env_track_headroom_text[] = {
+   "0.000V", "0.125V", "0.250V", "0.375V", "0.500V", "0.625V",
+   "0.750V", "0.875V", "1.000V", "1.125V", "1.250V", "1.375V",
+   "1.500V", "1.625V", "1.750V", "1.875V", "2.000V", "2.125V",
+   "2.250V", "2.375V", "2.500V", "2.625V", "2.750V", "2.875V",
+   "3.000V", "3.125V", "3.250V", "3.375V", "3.500V"
+};
+
+static SOC_ENUM_SINGLE_DECL(max98927_env_track_headroom,
+   MAX98927_R0082_ENV_TRACK_VOUT_HEADROOM, 0,
+   max98927_env_track_headroom_text);
+
 static const struct snd_kcontrol_new max98927_snd_controls[] = {
SOC_SINGLE_TLV("Speaker Volume", MAX98927_R003C_SPK_GAIN,
0, 6, 0,
@@ -641,6 +653,9 @@ static SOC_ENUM_SINGLE_DECL(max98927_current_limit,
MAX98927_AMP_VOL_SEL_SHIFT, 1, 0),
SOC_ENUM("Boost Output Voltage", max98927_boost_voltage),
SOC_ENUM("Current Limit", max98927_current_limit),
+   SOC_SINGLE("EnvTrack Switch", MAX98927_R0086_ENV_TRACK_CTRL,
+   MAX98927_ENV_TRACKER_EN_SHIFT, 1, 0),
+   SOC_ENUM("EnvTrack Headroom", max98927_env_track_headroom),
 };
 
 static const struct snd_soc_dapm_route max98927_audio_map[] = {
@@ -744,10 +759,6 @@ static int max98927_probe(struct snd_soc_codec *codec)
regmap_write(max98927->regmap,
MAX98927_R0086_ENV_TRACK_CTRL,
0x01);
-   regmap_write(max98927->regmap,
-   MAX98927_R0087_ENV_TRACK_BOOST_VOUT_READ,
-   0x10);
-
/* voltage, current slot configuration */
regmap_write(max98927->regmap,
MAX98927_R001E_PCM_TX_CH_SRC_A,
diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h
index 9ea8397..98b5f17 100644
--- a/sound/soc/codecs/max98927.h
+++ b/sound/soc/codecs/max98927.h
@@ -250,6 +250,10 @@
 #define MAX98927_BROWNOUT_DSP_EN (0x1 << 2)
 #define MAX98927_BROWNOUT_DSP_SHIFT (2)
 
+/* MAX98927_R0086_ENV_TRACK_CTRL */
+#define MAX98927_ENV_TRACKER_EN (0x1 << 0)
+#define MAX98927_ENV_TRACKER_EN_SHIFT (0)
+
 /* MAX98927_R0100_SOFT_RESET */
 #define MAX98927_SOFT_RESET (0x1 << 0)
 
-- 
1.9.1



[PATCH 3/3] ASoC: max98927: Removed obsolete variables

2017-09-01 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
Changelog:
Removed obsolete variables that have never been referred from driver 
before.

 sound/soc/codecs/max98927.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h
index 98b5f17..d215f60 100644
--- a/sound/soc/codecs/max98927.h
+++ b/sound/soc/codecs/max98927.h
@@ -263,17 +263,13 @@
 struct max98927_priv {
struct regmap *regmap;
struct snd_soc_codec *codec;
-   struct max98927_pdata *pdata;
-   unsigned int spk_gain;
unsigned int sysclk;
unsigned int v_l_slot;
unsigned int i_l_slot;
bool interleave_mode;
unsigned int ch_size;
-   unsigned int rate;
unsigned int iface;
unsigned int master;
-   unsigned int digital_gain;
bool tdm_mode;
 };
 #endif
-- 
1.9.1



[PATCH 2/3] ASoC: max98927: Added controls for Envelope tracking

2017-09-01 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changelog:
Added one control to set different headroom value for envelop tracking 
function.
Added one more control to enable/disable envelop tracking function.
Removed writing process to register 0x0087 because it is read only register.

 sound/soc/codecs/max98927.c | 19 +++
 sound/soc/codecs/max98927.h |  4 
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index a1d3935..73c7a33 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -624,6 +624,18 @@ static SOC_ENUM_SINGLE_DECL(max98927_current_limit,
MAX98927_R0042_BOOST_CTRL1, 1,
max98927_current_limit_text);
 
+static const char * const max98927_env_track_headroom_text[] = {
+   "0.000V", "0.125V", "0.250V", "0.375V", "0.500V", "0.625V",
+   "0.750V", "0.875V", "1.000V", "1.125V", "1.250V", "1.375V",
+   "1.500V", "1.625V", "1.750V", "1.875V", "2.000V", "2.125V",
+   "2.250V", "2.375V", "2.500V", "2.625V", "2.750V", "2.875V",
+   "3.000V", "3.125V", "3.250V", "3.375V", "3.500V"
+};
+
+static SOC_ENUM_SINGLE_DECL(max98927_env_track_headroom,
+   MAX98927_R0082_ENV_TRACK_VOUT_HEADROOM, 0,
+   max98927_env_track_headroom_text);
+
 static const struct snd_kcontrol_new max98927_snd_controls[] = {
SOC_SINGLE_TLV("Speaker Volume", MAX98927_R003C_SPK_GAIN,
0, 6, 0,
@@ -641,6 +653,9 @@ static SOC_ENUM_SINGLE_DECL(max98927_current_limit,
MAX98927_AMP_VOL_SEL_SHIFT, 1, 0),
SOC_ENUM("Boost Output Voltage", max98927_boost_voltage),
SOC_ENUM("Current Limit", max98927_current_limit),
+   SOC_SINGLE("EnvTrack Switch", MAX98927_R0086_ENV_TRACK_CTRL,
+   MAX98927_ENV_TRACKER_EN_SHIFT, 1, 0),
+   SOC_ENUM("EnvTrack Headroom", max98927_env_track_headroom),
 };
 
 static const struct snd_soc_dapm_route max98927_audio_map[] = {
@@ -744,10 +759,6 @@ static int max98927_probe(struct snd_soc_codec *codec)
regmap_write(max98927->regmap,
MAX98927_R0086_ENV_TRACK_CTRL,
0x01);
-   regmap_write(max98927->regmap,
-   MAX98927_R0087_ENV_TRACK_BOOST_VOUT_READ,
-   0x10);
-
/* voltage, current slot configuration */
regmap_write(max98927->regmap,
MAX98927_R001E_PCM_TX_CH_SRC_A,
diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h
index 9ea8397..98b5f17 100644
--- a/sound/soc/codecs/max98927.h
+++ b/sound/soc/codecs/max98927.h
@@ -250,6 +250,10 @@
 #define MAX98927_BROWNOUT_DSP_EN (0x1 << 2)
 #define MAX98927_BROWNOUT_DSP_SHIFT (2)
 
+/* MAX98927_R0086_ENV_TRACK_CTRL */
+#define MAX98927_ENV_TRACKER_EN (0x1 << 0)
+#define MAX98927_ENV_TRACKER_EN_SHIFT (0)
+
 /* MAX98927_R0100_SOFT_RESET */
 #define MAX98927_SOFT_RESET (0x1 << 0)
 
-- 
1.9.1



[PATCH 3/3] ASoC: max98927: Removed obsolete variables

2017-09-01 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
Changelog:
Removed obsolete variables that have never been referred from driver 
before.

 sound/soc/codecs/max98927.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h
index 98b5f17..d215f60 100644
--- a/sound/soc/codecs/max98927.h
+++ b/sound/soc/codecs/max98927.h
@@ -263,17 +263,13 @@
 struct max98927_priv {
struct regmap *regmap;
struct snd_soc_codec *codec;
-   struct max98927_pdata *pdata;
-   unsigned int spk_gain;
unsigned int sysclk;
unsigned int v_l_slot;
unsigned int i_l_slot;
bool interleave_mode;
unsigned int ch_size;
-   unsigned int rate;
unsigned int iface;
unsigned int master;
-   unsigned int digital_gain;
bool tdm_mode;
 };
 #endif
-- 
1.9.1



RE: [PATCH 1/9] ASoC: max98927: Added TDM support

2017-08-28 Thread Ryan Lee
>Subject: Re: [PATCH 1/9] ASoC: max98927: Added TDM support
>
>On Fri, Aug 25, 2017 at 05:41:02PM -0700, Ryan Lee wrote:
>> Signed-off-by: Ryan Lee <mailto:ryans@maximintegrated.com>
>
>This says it's adding support for TDM mode but...
>
>> +case SND_SOC_DAIFMT_DSP_A:
>> +format = MAX98927_PCM_FORMAT_TDM_MODE1;
>> +break;
>> +case SND_SOC_DAIFMT_DSP_B:
>> +format = MAX98927_PCM_FORMAT_TDM_MODE0;
>> +break;
>>  case SND_SOC_DAIFMT_PDM:
>> -max98927->iface |= SND_SOC_DAIFMT_PDM;
>> +use_pdm = true;
>>  break;
>
>...it looks like it's adding support for two new DSP modes and generally 
>making a
>bunch of other changes.  This probably needs splitting up, or at least a bit 
>more
>of a changelog.

I wanted to split this patch but changes were all about DSP_A and DSP_B format 
support.
I added more description about this patch and send patch series again.




RE: [PATCH 1/9] ASoC: max98927: Added TDM support

2017-08-28 Thread Ryan Lee
>Subject: Re: [PATCH 1/9] ASoC: max98927: Added TDM support
>
>On Fri, Aug 25, 2017 at 05:41:02PM -0700, Ryan Lee wrote:
>> Signed-off-by: Ryan Lee <mailto:ryans@maximintegrated.com>
>
>This says it's adding support for TDM mode but...
>
>> +case SND_SOC_DAIFMT_DSP_A:
>> +format = MAX98927_PCM_FORMAT_TDM_MODE1;
>> +break;
>> +case SND_SOC_DAIFMT_DSP_B:
>> +format = MAX98927_PCM_FORMAT_TDM_MODE0;
>> +break;
>>  case SND_SOC_DAIFMT_PDM:
>> -max98927->iface |= SND_SOC_DAIFMT_PDM;
>> +use_pdm = true;
>>  break;
>
>...it looks like it's adding support for two new DSP modes and generally 
>making a
>bunch of other changes.  This probably needs splitting up, or at least a bit 
>more
>of a changelog.

I wanted to split this patch but changes were all about DSP_A and DSP_B format 
support.
I added more description about this patch and send patch series again.




[PATCH 4/9] ASoC: max98927: Added missing \n to end of dev_err messages

2017-08-28 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
 sound/soc/codecs/max98927.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index c72a244..208d5ba 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -160,7 +160,7 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
mode = MAX98927_PCM_MASTER_MODE_MASTER;
break;
default:
-   dev_err(codec->dev, "DAI clock mode unsupported");
+   dev_err(codec->dev, "DAI clock mode unsupported\n");
return -EINVAL;
}
 
@@ -176,7 +176,7 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
invert = MAX98927_PCM_MODE_CFG_PCM_BCLKEDGE;
break;
default:
-   dev_err(codec->dev, "DAI invert mode unsupported");
+   dev_err(codec->dev, "DAI invert mode unsupported\n");
return -EINVAL;
}
 
@@ -331,7 +331,7 @@ static int max98927_dai_hw_params(struct snd_pcm_substream 
*substream,
chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_32;
break;
default:
-   dev_err(codec->dev, "format unsupported %d",
+   dev_err(codec->dev, "format unsupported %d\n",
params_format(params));
goto err;
}
-- 
1.9.1



[PATCH 2/9] ASoC: max98927: Added controls for Envelope tracking

2017-08-28 Thread Ryan Lee
Signed-off-by: Ryan Lee <ryans@maximintegrated.com>
---
 sound/soc/codecs/max98927.c | 20 
 sound/soc/codecs/max98927.h |  4 
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index 951cc05..1dfcb7b 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -614,6 +614,18 @@ static SOC_ENUM_SINGLE_DECL(max98927_current_limit,
MAX98927_R0042_BOOST_CTRL1, 1,
max98927_current_limit_text);
 
+static const char * const max98927_env_track_headroom_text[] = {
+   "0.000V", "0.125V", "0.250V", "0.375V", "0.500V", "0.625V",
+   "0.750V", "0.875V", "1.000V", "1.125V", "1.250V", "1.375V",
+   "1.500V", "1.625V", "1.750V", "1.875V", "2.000V", "2.125V",
+   "2.250V", "2.375V", "2.500V", "2.625V", "2.750V", "2.875V",
+   "3.000V", "3.125V", "3.250V", "3.375V", "3.500V"
+};
+
+static SOC_ENUM_SINGLE_DECL(max98927_env_track_headroom,
+   MAX98927_R0082_ENV_TRACK_VOUT_HEADROOM, 0,
+   max98927_env_track_headroom_text);
+
 static const struct snd_kcontrol_new max98927_snd_controls[] = {
SOC_SINGLE_TLV("Speaker Volume", MAX98927_R003C_SPK_GAIN,
0, 6, 0,
@@ -631,6 +643,9 @@ static SOC_ENUM_SINGLE_DECL(max98927_current_limit,
MAX98927_AMP_VOL_SEL_SHIFT, 1, 0),
SOC_ENUM("Boost Output Voltage", max98927_boost_voltage),
SOC_ENUM("Current Limit", max98927_current_limit),
+   SOC_SINGLE("EnvTrack Switch", MAX98927_R0086_ENV_TRACK_CTRL,
+   MAX98927_ENV_TRACKER_EN_SHIFT, 1, 0),
+   SOC_ENUM("EnvTrack Headroom", max98927_env_track_headroom),
 };
 
 static const struct snd_soc_dapm_route max98927_audio_map[] = {
@@ -725,13 +740,10 @@ static int max98927_probe(struct snd_soc_codec *codec)
/* Envelope Tracking configuration */
regmap_write(max98927->regmap,
MAX98927_R0082_ENV_TRACK_VOUT_HEADROOM,
-   0x08);
+   0x0A);
regmap_write(max98927->regmap,
MAX98927_R0086_ENV_TRACK_CTRL,
0x01);
-   regmap_write(max98927->regmap,
-   MAX98927_R0087_ENV_TRACK_BOOST_VOUT_READ,
-   0x10);
 
/* voltage, current slot configuration */
regmap_write(max98927->regmap,
diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h
index bf7a6f92..3069a09 100644
--- a/sound/soc/codecs/max98927.h
+++ b/sound/soc/codecs/max98927.h
@@ -250,6 +250,10 @@
 #define MAX98927_BROWNOUT_DSP_EN (0x1 << 2)
 #define MAX98927_BROWNOUT_DSP_SHIFT (2)
 
+/* MAX98927_R0086_ENV_TRACK_CTRL */
+#define MAX98927_ENV_TRACKER_EN (0x1 << 0)
+#define MAX98927_ENV_TRACKER_EN_SHIFT (0)
+
 /* MAX98927_R0100_SOFT_RESET */
 #define MAX98927_SOFT_RESET (0x1 << 0)
 
-- 
1.9.1



[PATCH 4/9] ASoC: max98927: Added missing \n to end of dev_err messages

2017-08-28 Thread Ryan Lee
Signed-off-by: Ryan Lee 
---
 sound/soc/codecs/max98927.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index c72a244..208d5ba 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -160,7 +160,7 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
mode = MAX98927_PCM_MASTER_MODE_MASTER;
break;
default:
-   dev_err(codec->dev, "DAI clock mode unsupported");
+   dev_err(codec->dev, "DAI clock mode unsupported\n");
return -EINVAL;
}
 
@@ -176,7 +176,7 @@ static int max98927_dai_set_fmt(struct snd_soc_dai 
*codec_dai, unsigned int fmt)
invert = MAX98927_PCM_MODE_CFG_PCM_BCLKEDGE;
break;
default:
-   dev_err(codec->dev, "DAI invert mode unsupported");
+   dev_err(codec->dev, "DAI invert mode unsupported\n");
return -EINVAL;
}
 
@@ -331,7 +331,7 @@ static int max98927_dai_hw_params(struct snd_pcm_substream 
*substream,
chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_32;
break;
default:
-   dev_err(codec->dev, "format unsupported %d",
+   dev_err(codec->dev, "format unsupported %d\n",
params_format(params));
goto err;
}
-- 
1.9.1



  1   2   3   >