Skip to contentSkip to conversation

ASoC: nau8540: new codec driver

PATCH In review John Hsu 2 participants 6 messages Jan 5, 2017 – Jan 26, 2017

Subsystems (3)
lore
Share & tools
lore

John Hsu

author
#0 lore raw

PATCH 1/1 ASoC: nau8540: new codec driver

Add codec driver of NAU85L40

---
 .../devicetree/bindings/sound/nau8540.txt          |  16 +
 sound/soc/codecs/Kconfig                           |   5 +
 sound/soc/codecs/Makefile                          |   2 +
 sound/soc/codecs/nau8540.c                         | 813 +++++++++++++++++++++
 sound/soc/codecs/nau8540.h                         | 228 ++++++
 5 files changed, 1064 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/nau8540.txt
 create mode 100644 sound/soc/codecs/nau8540.c
 create mode 100644 sound/soc/codecs/nau8540.h
Documentation/devicetree/bindings/sound/nau8540.txt new file +16 -0
new file mode 100644
index 0000000..2cc6cf6
@@ -0,0 +1,16 @@
+NAU85L40 audio CODEC
+
+This device supports I2C only.
+
+Required properties:
+
+  - compatible : "nuvoton,nau8540"
+
+  - reg : the I2C address of the device.
+
+Example:
+
+codec: nau8540@1c {
+       compatible = "nuvoton,nau8540";
+       reg = <0x1c>;
+};
sound/soc/codecs/Kconfig +5 -0
index 9e1718a..c31cdc9 100644
@@ -95,6 +95,7 @@ config SND_SOC_ALL_CODECS
        select SND_SOC_MAX9877 if I2C
        select SND_SOC_MC13783 if MFD_MC13XXX
        select SND_SOC_ML26124 if I2C
+       select SND_SOC_NAU8540 if I2C
        select SND_SOC_NAU8810 if I2C
        select SND_SOC_NAU8825 if I2C
        select SND_SOC_HDMI_CODEC
@@ -1105,6 +1106,10 @@ config SND_SOC_MC13783
 config SND_SOC_ML26124
        tristate
 
+config SND_SOC_NAU8540
+       tristate "Nuvoton Technology Corporation NAU85L40 CODEC"
+       depends on I2C
+
 config SND_SOC_NAU8810
        tristate "Nuvoton Technology Corporation NAU88C10 CODEC"
        depends on I2C
sound/soc/codecs/Makefile +2 -0
index 7e1dad7..0a7f4ff 100644
@@ -90,6 +90,7 @@ snd-soc-mc13783-objs := mc13783.o
 snd-soc-ml26124-objs := ml26124.o
 snd-soc-msm8916-analog-objs := msm8916-wcd-analog.o
 snd-soc-msm8916-digital-objs := msm8916-wcd-digital.o
+snd-soc-nau8540-objs := nau8540.o
 snd-soc-nau8810-objs := nau8810.o
 snd-soc-nau8825-objs := nau8825.o
 snd-soc-hdmi-codec-objs := hdmi-codec.o
@@ -318,6 +319,7 @@ obj-$(CONFIG_SND_SOC_MC13783)       += snd-soc-mc13783.o
 obj-$(CONFIG_SND_SOC_ML26124)  += snd-soc-ml26124.o
 obj-$(CONFIG_SND_SOC_MSM8916_WCD_ANALOG) +=snd-soc-msm8916-analog.o
 obj-$(CONFIG_SND_SOC_MSM8916_WCD_DIGITAL) +=snd-soc-msm8916-digital.o
+obj-$(CONFIG_SND_SOC_NAU8540)   += snd-soc-nau8540.o
 obj-$(CONFIG_SND_SOC_NAU8810)   += snd-soc-nau8810.o
 obj-$(CONFIG_SND_SOC_NAU8825)   += snd-soc-nau8825.o
 obj-$(CONFIG_SND_SOC_HDMI_CODEC)       += snd-soc-hdmi-codec.o
sound/soc/codecs/nau8540.c new file +813 -0

813 lines not on this page · raw message

sound/soc/codecs/nau8540.h new file +228 -0

228 lines not on this page · raw message

--
2.6.4

===========================================================================================
The privileged confidential information contained in this email is intended for use only by the addressees as indicated by the original sender of this email. If you are not the addressee indicated in this email or are not responsible for delivery of the email to such a person, please kindly reply to the sender indicating this fact and delete all copies of it from your computer and network server immediately. Your cooperation is highly appreciated. It is advised that any unauthorized use of confidential information of Nuvoton is strictly prohibited; and any information in this email irrelevant to the official business of Nuvoton shall be deemed as neither given nor endorsed by Nuvoton.

maintainer
#1 lore raw

On Thu, Jan 05, 2017 at 02:20:44PM +0800, John Hsu wrote:

This looks good overall, a couple of small points though:

Quoted 10 lines
sound/soc/codecs/nau8540.c new file +10 -0
+static int nau8540_config_sysclk(struct nau8540 *nau8540,
+       int clk_id, unsigned int freq)
+{
+       struct regmap *regmap = nau8540->regmap;
+
+       switch (clk_id) {
+       case NAU8540_CLK_DIS:
+       case NAU8540_CLK_MCLK:
+               regmap_update_bits(regmap, NAU8540_REG_CLOCK_SRC,
+                       NAU8540_CLK_SRC_MASK, NAU8540_CLK_SRC_MCLK);

sound/soc/codecs/nau8540.c line 654

Quoted 10 lines
sound/soc/codecs/nau8540.c new file +10 -0
+               regmap_update_bits(regmap, NAU8540_REG_FLL6,
+                       NAU8540_DCO_EN, 0);
+               break;
+
+       case NAU8540_CLK_INTERNAL:
+               regmap_update_bits(regmap, NAU8540_REG_FLL6,
+                       NAU8540_DCO_EN, NAU8540_DCO_EN);
+               regmap_update_bits(regmap, NAU8540_REG_CLOCK_SRC,
+                       NAU8540_CLK_SRC_MASK, NAU8540_CLK_SRC_VCO);
+               break;

The above are fine but...

Quoted 5 lines
sound/soc/codecs/nau8540.c new file +5 -0
+
+       case NAU8540_CLK_FLL_MCLK:
+               regmap_update_bits(regmap, NAU8540_REG_FLL3,
+                       NAU8540_FLL_CLK_SRC_MASK, NAU8540_FLL_CLK_SRC_MCLK);
+               break;

sound/soc/codecs/nau8540.c line 669

Quoted 10 lines
sound/soc/codecs/nau8540.c new file +10 -0
+
+       case NAU8540_CLK_FLL_BLK:
+               regmap_update_bits(regmap, NAU8540_REG_FLL3,
+                       NAU8540_FLL_CLK_SRC_MASK, NAU8540_FLL_CLK_SRC_BLK);
+               break;
+
+       case NAU8540_CLK_FLL_FS:
+               regmap_update_bits(regmap, NAU8540_REG_FLL3,
+                       NAU8540_FLL_CLK_SRC_MASK, NAU8540_FLL_CLK_SRC_FS);
+               break;

...these look like they're mixing in FLL configuration which I'd expect to be done with set_pll() via the source argument and I'm not seeing anything that sets the device to use the FLL here. I'd expect the source selection to go into set_pll() and I'd expect this function to have a setting which tells the device to use the FLL.

sound/soc/codecs/nau8540.c line 688

Quoted 7 lines
sound/soc/codecs/nau8540.c new file +7 -0
+static int nau8540_set_sysclk(struct snd_soc_codec *codec,
+       int clk_id, int source, unsigned int freq, int dir)
+{
+       struct nau8540 *nau8540 = snd_soc_codec_get_drvdata(codec);
+
+       return nau8540_config_sysclk(nau8540, clk_id, freq);
+}

This wrapper isn't really adding anything.

Quoted 11 lines
sound/soc/codecs/nau8540.c new file +11 -0
+static void nau8540_init_regs(struct nau8540 *nau8540)
+{
+       struct regmap *regmap = nau8540->regmap;
+
+       /* Enable Bias/VMID/VMID Tieoff */
+       regmap_update_bits(regmap, NAU8540_REG_VMID_CTRL,
+               NAU8540_VMID_EN | NAU8540_VMID_SEL_MASK,
+               NAU8540_VMID_EN | (0x2 << NAU8540_VMID_SEL_SFT));
+       regmap_update_bits(regmap, NAU8540_REG_REFERENCE,
+               NAU8540_PRECHARGE_DIS | NAU8540_GLOBAL_BIAS_EN,
+               NAU8540_PRECHARGE_DIS | NAU8540_GLOBAL_BIAS_EN);

sound/soc/codecs/nau8540.c line 716

Quoted 10 lines
sound/soc/codecs/nau8540.c new file +10 -0
+       mdelay(2);
+       regmap_update_bits(regmap, NAU8540_REG_MIC_BIAS,
+               NAU8540_PU_PRE, NAU8540_PU_PRE);
+       regmap_update_bits(regmap, NAU8540_REG_CLOCK_CTRL,
+               NAU8540_CLK_ADC_EN | NAU8540_CLK_I2S_EN,
+               NAU8540_CLK_ADC_EN | NAU8540_CLK_I2S_EN);
+       /* ADC OSR selection, CLK_ADC = Fs * OSR */
+       regmap_update_bits(regmap, NAU8540_REG_ADC_SAMPLE_RATE,
+               NAU8540_ADC_OSR_MASK, NAU8540_ADC_OSR_64);
+}

Does this sequence need to be done as part of resume as well?

author
#2 lore raw

Hi,

Quoted 44 lines · Mark Brown

On Thu, Jan 05, 2017 at 02:20:44PM +0800, John Hsu wrote:

This looks good overall, a couple of small points though:

Quoted 11 lines
sound/soc/codecs/nau8540.c new file +10 -0
+static int nau8540_config_sysclk(struct nau8540 *nau8540,
+       int clk_id, unsigned int freq)
+{
+       struct regmap *regmap = nau8540->regmap;
+
+       switch (clk_id) {
+       case NAU8540_CLK_DIS:
+       case NAU8540_CLK_MCLK:
+               regmap_update_bits(regmap, NAU8540_REG_CLOCK_SRC,
+                       NAU8540_CLK_SRC_MASK, NAU8540_CLK_SRC_MCLK);

sound/soc/codecs/nau8540.c line 654

Quoted 10 lines
sound/soc/codecs/nau8540.c new file +10 -0
+               regmap_update_bits(regmap, NAU8540_REG_FLL6,
+                       NAU8540_DCO_EN, 0);
+               break;
+
+       case NAU8540_CLK_INTERNAL:
+               regmap_update_bits(regmap, NAU8540_REG_FLL6,
+                       NAU8540_DCO_EN, NAU8540_DCO_EN);
+               regmap_update_bits(regmap, NAU8540_REG_CLOCK_SRC,
+                       NAU8540_CLK_SRC_MASK, NAU8540_CLK_SRC_VCO);
+               break;

The above are fine but...

Quoted 14 lines
sound/soc/codecs/nau8540.c new file +14 -0
+
+       case NAU8540_CLK_FLL_MCLK:
+               regmap_update_bits(regmap, NAU8540_REG_FLL3,
+                       NAU8540_FLL_CLK_SRC_MASK, NAU8540_FLL_CLK_SRC_MCLK);
+               break;
+
+       case NAU8540_CLK_FLL_BLK:
+               regmap_update_bits(regmap, NAU8540_REG_FLL3,
+                       NAU8540_FLL_CLK_SRC_MASK, NAU8540_FLL_CLK_SRC_BLK);
+               break;
+
+       case NAU8540_CLK_FLL_FS:
+               regmap_update_bits(regmap, NAU8540_REG_FLL3,
+                       NAU8540_FLL_CLK_SRC_MASK, NAU8540_FLL_CLK_SRC_FS);
Quoted 10 lines
Quoted 2 lines

+ break;

...these look like they're mixing in FLL configuration which I'd expect to be done with set_pll() via the source argument and I'm not seeing anything that sets the device to use the FLL here. I'd expect the source selection to go into set_pll() and I'd expect this function to have a setting which tells the device to use the FLL.

I see. These source selection about FLL can move to the set_pll().

Quoted 12 lines

sound/soc/codecs/nau8540.c line 688

Quoted 8 lines
sound/soc/codecs/nau8540.c new file +7 -0
+static int nau8540_set_sysclk(struct snd_soc_codec *codec,
+       int clk_id, int source, unsigned int freq, int dir)
+{
+       struct nau8540 *nau8540 = snd_soc_codec_get_drvdata(codec);
+
+       return nau8540_config_sysclk(nau8540, clk_id, freq);
+}

This wrapper isn't really adding anything.

We will change it and move the config_sysclk to here.

Quoted 16 lines
Quoted 16 lines
sound/soc/codecs/nau8540.c new file +16 -0
+static void nau8540_init_regs(struct nau8540 *nau8540)
+{
+       struct regmap *regmap = nau8540->regmap;
+
+       /* Enable Bias/VMID/VMID Tieoff */
+       regmap_update_bits(regmap, NAU8540_REG_VMID_CTRL,
+               NAU8540_VMID_EN | NAU8540_VMID_SEL_MASK,
+               NAU8540_VMID_EN | (0x2 << NAU8540_VMID_SEL_SFT));
+       regmap_update_bits(regmap, NAU8540_REG_REFERENCE,
+               NAU8540_PRECHARGE_DIS | NAU8540_GLOBAL_BIAS_EN,
+               NAU8540_PRECHARGE_DIS | NAU8540_GLOBAL_BIAS_EN);
+       mdelay(2);
+       regmap_update_bits(regmap, NAU8540_REG_MIC_BIAS,
+               NAU8540_PU_PRE, NAU8540_PU_PRE);
+       regmap_update_bits(regmap, NAU8540_REG_CLOCK_CTRL,
+               NAU8540_CLK_ADC_EN | NAU8540_CLK_I2S_EN,
Quoted 9 lines

sound/soc/codecs/nau8540.c line 716

Quoted 6 lines
sound/soc/codecs/nau8540.c new file +5 -0
+               NAU8540_CLK_ADC_EN | NAU8540_CLK_I2S_EN);
+       /* ADC OSR selection, CLK_ADC = Fs * OSR */
+       regmap_update_bits(regmap, NAU8540_REG_ADC_SAMPLE_RATE,
+               NAU8540_ADC_OSR_MASK, NAU8540_ADC_OSR_64);
+}

Does this sequence need to be done as part of resume as well?

These initiation just only need to do once when the codec boots. I think it's better to do it when driver module is loaded.

===========================================================================================
The privileged confidential information contained in this email is intended for use only by the addressees as indicated by the original sender of this email. If you are not the addressee indicated in this email or are not responsible for delivery of the email to such a person, please kindly reply to the sender indicating this fact and delete all copies of it from your computer and network server immediately. Your cooperation is highly appreciated. It is advised that any unauthorized use of confidential information of Nuvoton is strictly prohibited; and any information in this email irrelevant to the official business of Nuvoton shall be deemed as neither given nor endorsed by Nuvoton.

maintainer
#3 lore raw
Quoted 7 lines · John Hsu
Quoted 3 lines · Mark Brown

On Thu, Jan 05, 2017 at 02:20:44PM +0800, John Hsu wrote:

Does this sequence need to be done as part of resume as well?

These initiation just only need to do once when the codec boots. I think it's better to do it when driver module is loaded.

Why not on resume? While it won't always happen system suspend does frequently mean that the device will have lost power so anything done on boot will have been lost.

author
#4 lore raw

Hi,

Quoted 12 lines · Mark Brown
Quoted 8 lines · John Hsu
Quoted 6 lines · Mark Brown

On Thu, Jan 05, 2017 at 02:20:44PM +0800, John Hsu wrote:

Does this sequence need to be done as part of resume as well?

Quoted 8 lines
Quoted 3 lines

These initiation just only need to do once when the codec boots. I think it's better to do it when driver module is loaded.

Why not on resume? While it won't always happen system suspend does frequently mean that the device will have lost power so anything done on boot will have been lost.

Yes, I can move it to resume.
By the way, is it better to do cache sync instead for the situation?

===========================================================================================
The privileged confidential information contained in this email is intended for use only by the addressees as indicated by the original sender of this email. If you are not the addressee indicated in this email or are not responsible for delivery of the email to such a person, please kindly reply to the sender indicating this fact and delete all copies of it from your computer and network server immediately. Your cooperation is highly appreciated. It is advised that any unauthorized use of confidential information of Nuvoton is strictly prohibited; and any information in this email irrelevant to the official business of Nuvoton shall be deemed as neither given nor endorsed by Nuvoton.

maintainer
#5 lore raw
Quoted 9 lines · John Hsu
Quoted 5 lines · Mark Brown

On Wed, Jan 25, 2017 at 11:45:26AM +0800, John Hsu wrote:

Why not on resume? While it won't always happen system suspend does frequently mean that the device will have lost power so anything done on boot will have been lost.

Yes, I can move it to resume.
By the way, is it better to do cache sync instead for the situation?

Yes, adding a cache sync on resume would also do the trick if it's just writing values in and the ordering doesn't matter.