ASoC: add RT5640 CODEC driver
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 1 line · On Fri, May 31, 2013 at 03:04:59PM +0800, [email protected] wrote:
From: Bard Liao <[email protected]>
This looks pretty good, a few small things below and probably one actual bug.
Quoted 9 lines
* Use
regmap_range_cfgto replace index read/write function.
* Remove I2S3 related code since there is no I2S3 in ALC5640.
* Remove Voice DSP related code since there is no Voice DSP in ALC5640.
* Remove MICBIAS2 since there is no MICBIAS2 in ALC5640.
* Change DMIC1/2 CLK to DMIC1/2 Power since it is for enable/disable DMIC1/2
* Modify some texts for consistent coding style.
* Merge sto adc l/r mux since it shares the same control bits.
* Other minor changes.
Put stuff like this after the --- so it doesn't end up in the commit log.
Review
Quoted 5 lines
(quoted diff) +5
-0+ switch (event) { + case SND_SOC_DAPM_POST_PMU: + snd_soc_update_bits(codec, RT5640_PWR_DIG1, 0x0001, 0x0001); + regmap_update_bits(rt5640->regmap, 0x1c, 0xf000, 0xf000); + break;
It's a bit weird to be using snd_soc_update_bits() and regmap_update_bits()...
Review
Quoted 6 lines
(quoted diff) +6
-0+ SND_SOC_DAPM_SUPPLY("DMIC1 Power", SND_SOC_NOPM, 0, 0, + rt5640_set_dmic1_event, + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), + SND_SOC_DAPM_SUPPLY("DMIC2 Power", SND_SOC_NOPM, 0, 0, + rt5640_set_dmic2_event, + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
The enable bits could be listed here - this would be a bit more idiomatic, would save the PMD event and would enable the writes to be combined.
Review
Quoted 13 lines
(quoted diff) +13
-0+ case SND_SOC_BIAS_STANDBY: + if (SND_SOC_BIAS_OFF == codec->dapm.bias_level) { + snd_soc_update_bits(codec, RT5640_PWR_ANLG1, + RT5640_PWR_VREF1 | RT5640_PWR_MB | + RT5640_PWR_BG | RT5640_PWR_VREF2, + RT5640_PWR_VREF1 | RT5640_PWR_MB | + RT5640_PWR_BG | RT5640_PWR_VREF2); + mdelay(10); + snd_soc_update_bits(codec, RT5640_PWR_ANLG1, + RT5640_PWR_FV1 | RT5640_PWR_FV2, + RT5640_PWR_FV1 | RT5640_PWR_FV2); + regcache_cache_only(rt5640->regmap, false); + regcache_sync(rt5640->regmap);
This looks wrong - you're writing to the device before you take it out of cache only mode so your delay in the above sequence will have no effect.
Review
Quoted 8 lines
(quoted diff) +8
-0+ val = snd_soc_read(codec, RT5640_VENDOR_ID2); + if ((val != RT5640_DEVICE_ID)) { + dev_err(codec->dev, + "Device with ID register %x is not rt5640/39\n", val); + return -ENODEV; + } + + rt5640_reset(codec);
Do these in the I2C probe function before you register the CODEC, that way we don't try to start the sound card if we can't talk to the device.
Review
Quoted 5 lines
(quoted diff) +5
-0+ ret = regmap_register_patch(rt5640->regmap, init_list, + ARRAY_SIZE(init_list)); + if (ret != 0) + dev_warn(codec->dev, "Failed to apply regmap patch: %d\n", + ret);
This should also be in the I2C probe.
Quoted 7 lines
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Monday, June 03, 2013 11:36 PM
To: Bard Liao
Cc: [email protected]; [email protected]; Flove; Oder Chiou; [email protected]; [email protected]
Subject: Re: [PATCH] ASoC: add RT5640 CODEC driver
Quoted 16 lines
Review
Quoted 13 lines
(quoted diff) +13
-0+ case SND_SOC_BIAS_STANDBY: + if (SND_SOC_BIAS_OFF == codec->dapm.bias_level) { + snd_soc_update_bits(codec, RT5640_PWR_ANLG1, + RT5640_PWR_VREF1 | RT5640_PWR_MB | + RT5640_PWR_BG | RT5640_PWR_VREF2, + RT5640_PWR_VREF1 | RT5640_PWR_MB | + RT5640_PWR_BG | RT5640_PWR_VREF2); + mdelay(10); + snd_soc_update_bits(codec, RT5640_PWR_ANLG1, + RT5640_PWR_FV1 | RT5640_PWR_FV2, + RT5640_PWR_FV1 | RT5640_PWR_FV2); + regcache_cache_only(rt5640->regmap, false); + regcache_sync(rt5640->regmap);This looks wrong - you're writing to the device before you take it out of cache only mode so your delay in the above sequence will have no effect.
Actually, I don't know if I need to call "regcache_cache_only(rt5640->regmap, false);" here. We never call "regcache_cache_only(rt5640->regmap, true);" in the codec driver.
I assume the cache_only flag is default false.
If yes, I think I can remove "regcache_cache_only(rt5640->regmap, false);" from the code driver. If not, I will move it to the beginning of if (SND_SOC_BIAS_OFF == codec->dapm.bias_level) condition.
Quoted 1 line
------Please consider the environment before printing this e-mail.
Quoted 5 lines · Bard Liao
Actually, I don't know if I need to call "
regcache_cache_only(rt5640->regmap, false);" here. We never call "regcache_cache_only(rt5640->regmap, true);" in the codec driver.
I assume thecache_onlyflag is default false.
If yes, I think I can remove "regcache_cache_only(rt5640->regmap, false);" from the code driver. If not, I will move it to the beginning of if (SND_SOC_BIAS_OFF==codec->dapm.bias_level) condition.
I'd actually put in code to enable cache only mode when you power off, that way when the support for the LDO enable GPIO is added it will not need to be re-added.
A message that is not in the archive (sent off-list or not yet received): 1121E117AD4ECE49880A389A396215BB8A8969924B@rtitmbs7.realtek.com.tw
Quoted 4 lines · Bard Liao
Stephen,
I remove the DT support from this patch.
Can you add the DT support as a separate patch?
Yes, I'll do that.
I assume you also want me to add the code to control the LDO1_EN GPIO, since that seems missing from this patch. I thought you said you were going to add it. I assume you tested this on Dalmore by manually setting the GPIO from U-Boot before booting the kernel?
I'll try to get to this ASAP; perhaps not today though - we'll see how long the other things I have stacked up take.
Quoted 14 lines
-----Original Message-----
From: Stephen Warren [mailto:[email protected]]
Sent: Monday, June 03, 2013 11:49 PM
To: Bard Liao
Cc: [email protected]; [email protected]; [email protected]; Flove; Oder Chiou; [email protected]
Subject: Re: [PATCH] ASoC: add RT5640 CODEC driverQuoted 4 lines · Bard Liao
Stephen,
I remove the DT support from this patch.
Can you add the DT support as a separate patch?
Quoted 6 lines
Yes, I'll do that.
I assume you also want me to add the code to control the
LDO1_ENGPIO, since that seems missing from this patch. I thought you said you were going to add it. I assume you tested this on Dalmore by manually setting the GPIO from U-Boot before booting the kernel?
Yes, please add the code to control the LDO1_EN_GPIO.
Thanks a lot.
I execute "gpio set 171" command in U-Boot every time before booting the kernel.
Quoted 5 lines
I'll try to get to this ASAP; perhaps not today though - we'll see how long the other things I have stacked up take.
------Please consider the environment before printing this e-mail.
Quoted 11 lines · On 05/31/2013 01:04 AM, [email protected] wrote:
From: Bard Liao <[email protected]>
* Use
regmap_range_cfgto replace index read/write function.
* Remove I2S3 related code since there is no I2S3 in ALC5640.
* Remove Voice DSP related code since there is no Voice DSP in ALC5640.
* Remove MICBIAS2 since there is no MICBIAS2 in ALC5640.
* Change DMIC1/2 CLK to DMIC1/2 Power since it is for enable/disable DMIC1/2
* Modify some texts for consistent coding style.
* Merge sto adc l/r mux since it shares the same control bits.
* Other minor changes.
Review
Quoted 5 lines
(quoted diff) +4
-0+static const struct snd_soc_dapm_widget rt5640_dapm_widgets[] = { + /* Input Lines */ + SND_SOC_DAPM_INPUT("DMIC1"), + SND_SOC_DAPM_INPUT("DMIC2"),
Can you explain that more? In the spec for this part, I don't see any DMIC1/2 input pins. Instead, I think they're alternative uses for the IN1P/N pins, right?
Review
Quoted 4 lines
(quoted diff) +4
-0+ SND_SOC_DAPM_MIXER("HPO MIX L", SND_SOC_NOPM, 0, 0, + rt5640_hpo_mix, ARRAY_SIZE(rt5640_hpo_mix)), + SND_SOC_DAPM_MIXER("HPO MIX R", SND_SOC_NOPM, 0, 0, + rt5640_hpo_mix, ARRAY_SIZE(rt5640_hpo_mix)),
In the version of the driver I posted, I had replaced this with a single "HPO MIX" DAPM_MIXER, because there is a single bit in HW that controls both the L and R channels. I think you should incorporate that same change.
That relies on commit 85762e7 "ASoC: dapm: Implement mixer control sharing".
In an earlier review, IIRC, Mark had asked you to implement platform data to configure whether the microphones were single-ended or not. I don't see that in this patch.
Finally, I really would prefer if you could implement the support for the LDO1_EN GPIO via platform data. Getting that right requires a bit of knowledge of how set_bias_level() is supposed to work on this CODEC, and I think Realtek have the best information to get that right. I'll certainly send a patch to implement this all by device tree after that.
Anyway, I'll go test this patch and see if it works for me on my HW.
Quoted 23 lines · Stephen Warren
Quoted 11 lines · On 05/31/2013 01:04 AM, [email protected] wrote:
From: Bard Liao <[email protected]>
* Use
regmap_range_cfgto replace index read/write function.
* Remove I2S3 related code since there is no I2S3 in ALC5640.
* Remove Voice DSP related code since there is no Voice DSP in ALC5640.
* Remove MICBIAS2 since there is no MICBIAS2 in ALC5640.
* Change DMIC1/2 CLK to DMIC1/2 Power since it is for enable/disable DMIC1/2
* Modify some texts for consistent coding style.
* Merge sto adc l/r mux since it shares the same control bits.
* Other minor changes.Review
Quoted 6 lines
(quoted diff) +5
-0+static const struct snd_soc_dapm_widget rt5640_dapm_widgets[] = { + SND_SOC_DAPM_MIXER("HPO MIX L", SND_SOC_NOPM, 0, 0, + rt5640_hpo_mix, ARRAY_SIZE(rt5640_hpo_mix)), + SND_SOC_DAPM_MIXER("HPO MIX R", SND_SOC_NOPM, 0, 0, + rt5640_hpo_mix, ARRAY_SIZE(rt5640_hpo_mix)),In the version of the driver I posted, I had replaced this with a single "HPO MIX"
DAPM_MIXER, because there is a single bit in HW that controls both the L and R channels. I think you should incorporate that same change.
Quoted 1 line
That relies on commit 85762e7 "ASoC: dapm: Implement mixer control sharing".
Sorry, ignore that comment; what I had done earlier was to make both the SND_SOC_DAPM_MIXER() invocations above use the same rt5640_hpo_mix kcontrol, which is exactly what you have in your patch.
So, this part is fine. Sorry for the noise.
BTW, I tested on my HW, and I see that headphone output still works fine with this version of the driver.
I didn't test speaker output though, but that didn't work with the previous driver I sent either. Are you able to get that working? I also didn't test any capture path.
Quoted 14 lines · On 05/31/2013 01:04 AM, [email protected] wrote:
Quoted 12 lines
From: Bard Liao <[email protected]>
* Use
regmap_range_cfgto replace index read/write function.
* Remove I2S3 related code since there is no I2S3 in ALC5640.
* Remove Voice DSP related code since there is no Voice DSP in ALC5640.
* Remove MICBIAS2 since there is no MICBIAS2 in ALC5640.
* Change DMIC1/2 CLK to DMIC1/2 Power since it is for enable/disable DMIC1/2
* Modify some texts for consistent coding style.
* Merge sto adc l/r mux since it shares the same control bits.
* Other minor changes.+static const struct
snd_soc_dapm_widgetrt5640_dapm_widgets[] = {
Quoted 7 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ /* Input Lines */ + SND_SOC_DAPM_INPUT("DMIC1"), + SND_SOC_DAPM_INPUT("DMIC2"),Can you explain that more? In the spec for this part, I don't see any DMIC1/2 input pins. Instead, I think they're alternative uses for the IN1P/N pins, right?
Yes, DMIC1/2 are alternative uses for the IN1P/N pins.
If you connect it with a DMIC, it will work as a DMIC input. There are DMIC1/2 component in ALC5640.
You can see chapter 4.3 Digital Mixer Path in ALC5640 datasheet for reference. If IN1P/N use as DMIC1/2, the audio path should go through DMIC1/DMIC2.
Quoted 3 lines
In an earlier review, IIRC, Mark had asked you to implement platform data to configure whether the microphones were single-ended or not. I don't see that in this patch.
Ok, I will implement the microphones type configuration in my patch. I thought it will be add in the DT patch.
Quoted 6 lines
Finally, I really would prefer if you could implement the support for the
LDO1_ENGPIO via platform data. Getting that right requires a bit of knowledge of howset_bias_level()is supposed to work on this CODEC, and I think Realtek have the best information to get that right. I'll certainly send a patch to implement this all by device tree after that.
I will do that also, if I have question I will ask you. Thanks.
Quoted 4 lines
Anyway, I'll go test this patch and see if it works for me on my HW.
------Please consider the environment before printing this e-mail.