Skip to contentSkip to conversation

ASoC: nau8824: new codec driver

PATCH In review John Hsu 2 participants 3 messages Jan 26, 2017 – Feb 2, 2017

Subsystems (3)
lore
Share & tools
lore

John Hsu

author
#0 lore raw

PATCH 1/1 ASoC: nau8824: new codec driver

Add codec driver of NAU88L24

---
 .../devicetree/bindings/sound/nau8824.txt          |   86 +
 sound/soc/codecs/Kconfig                           |    5 +
 sound/soc/codecs/Makefile                          |    2 +
 sound/soc/codecs/nau8824.c                         | 1750 ++++++++++++++++++++
 sound/soc/codecs/nau8824.h                         |  462 ++++++
 5 files changed, 2305 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/nau8824.txt
 create mode 100644 sound/soc/codecs/nau8824.c
 create mode 100644 sound/soc/codecs/nau8824.h
Documentation/devicetree/bindings/sound/nau8824.txt new file +86 -0
new file mode 100644
index 0000000..c0a68a6
@@ -0,0 +1,86 @@
+Nuvoton NAU8824 audio codec
+
+This device supports I2C only.
+
+Required properties:
+  - compatible : Must be "nuvoton,nau8824"
+
+  - reg : the I2C address of the device. This is either 0x1a (CSB=0) or 0x1b (CSB=1).
+
+Optional properties:
+  - nuvoton,vref-impedance: VREF Impedance selection
+      0 - Open
+      1 - 25 kOhm
+      2 - 125 kOhm
+      3 - 2.5 kOhm
+
+  - nuvoton,micbias-voltage: Micbias voltage level.
+      0 - VDDA
+      1 - VDDA
+      2 - VDDA * 1.1
+      3 - VDDA * 1.2
+      4 - VDDA * 1.3
+      5 - VDDA * 1.4
+      6 - VDDA * 1.53
+      7 - VDDA * 1.53
+
+  - nuvoton,sar-threshold-num: Number of buttons supported
+  - nuvoton,sar-threshold: Impedance threshold for each button. Array that contains up to 8 buttons configuration. SAR value is calculated as
+    SAR = 255 * MICBIAS / SAR_VOLTAGE * R / (2000 + R)
+    where MICBIAS is configured by 'nuvoton,micbias-voltage', SAR_VOLTAGE is configured by 'nuvoton,sar-voltage', R - button impedance.
+    Refer datasheet section 10.2 for more information about threshold calculation.
+
+  - nuvoton,sar-hysteresis: Button impedance measurement hysteresis.
+
+  - nuvoton,sar-voltage: Reference voltage for button impedance measurement.
+      0 - VDDA
+      1 - VDDA
+      2 - VDDA * 1.1
+      3 - VDDA * 1.2
+      4 - VDDA * 1.3
+      5 - VDDA * 1.4
+      6 - VDDA * 1.53
+      7 - VDDA * 1.53
+
+  - nuvoton,sar-compare-time: SAR compare time
+      0 - 500 ns
+      1 - 1 us
+      2 - 2 us
+      3 - 4 us
+
+  - nuvoton,sar-sampling-time: SAR sampling time
+      0 - 2 us
+      1 - 4 us
+      2 - 8 us
+      3 - 16 us
+
+  - nuvoton,short-key-debounce: Button short key press debounce time.
+      0 - 30 ms
+      1 - 50 ms
+      2 - 100 ms
+
+  - nuvoton,jack-eject-debounce: Jack ejection debounce time.
+      0 - 0 ms
+      1 - 1 ms
+      2 - 10 ms
+
+
+Example:
+
+  headset: nau8824@1a {
+      compatible = "nuvoton,nau8824";
+      reg = <0x1a>;
+      interrupt-parent = <&gpio>;
+      interrupts = <TEGRA_GPIO(E, 6) IRQ_TYPE_LEVEL_LOW>;
+      nuvoton,vref-impedance = <2>;
+      nuvoton,micbias-voltage = <6>;
+      // Setup 4 buttons impedance according to Android specification
+      nuvoton,sar-threshold-num = <4>;
+      nuvoton,sar-threshold = <0xc 0x1e 0x38 0x60>;
+      nuvoton,sar-hysteresis = <0>;
+      nuvoton,sar-voltage = <6>;
+      nuvoton,sar-compare-time = <1>;
+      nuvoton,sar-sampling-time = <1>;
+      nuvoton,short-key-debounce = <0>;
+      nuvoton,jack-eject-debounce = <1>;
+  };
sound/soc/codecs/Kconfig +5 -0
index 9e1718a..67b5de5 100644
@@ -96,6 +96,7 @@ config SND_SOC_ALL_CODECS
        select SND_SOC_MC13783 if MFD_MC13XXX
        select SND_SOC_ML26124 if I2C
        select SND_SOC_NAU8810 if I2C
+       select SND_SOC_NAU8824 if I2C
        select SND_SOC_NAU8825 if I2C
        select SND_SOC_HDMI_CODEC
        select SND_SOC_PCM1681 if I2C
@@ -1109,6 +1110,10 @@ config SND_SOC_NAU8810
        tristate "Nuvoton Technology Corporation NAU88C10 CODEC"
        depends on I2C
 
+config SND_SOC_NAU8824
+       tristate "Nuvoton Technology Corporation NAU88L24 CODEC"
+       depends on I2C
+
 config SND_SOC_NAU8825
        tristate
 
sound/soc/codecs/Makefile +2 -0
index 7e1dad7..02dd0c3 100644
@@ -91,6 +91,7 @@ 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-nau8810-objs := nau8810.o
+snd-soc-nau8824-objs := nau8824.o
 snd-soc-nau8825-objs := nau8825.o
 snd-soc-hdmi-codec-objs := hdmi-codec.o
 snd-soc-pcm1681-objs := pcm1681.o
@@ -319,6 +320,7 @@ 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_NAU8810)   += snd-soc-nau8810.o
+obj-$(CONFIG_SND_SOC_NAU8824)   += snd-soc-nau8824.o
 obj-$(CONFIG_SND_SOC_NAU8825)   += snd-soc-nau8825.o
 obj-$(CONFIG_SND_SOC_HDMI_CODEC)       += snd-soc-hdmi-codec.o
 obj-$(CONFIG_SND_SOC_PCM1681)  += snd-soc-pcm1681.o
sound/soc/codecs/nau8824.c new file +1750 -0

1,750 lines not on this page · raw message

sound/soc/codecs/nau8824.h new file +462 -0

462 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 26, 2017 at 11:48:09AM +0800, John Hsu wrote:

This looks mostly good, a few fairly small things below:

sound/soc/codecs/nau8824.c line 363

Quoted 2 lines
sound/soc/codecs/nau8824.c new file +2 -0
+       SOC_SINGLE_TLV("Speaker Right Volume from DACR",
+               NAU8824_REG_CLASSD_GAIN_1, 8, 0x1f, 0, spk_vol_tlv),

Names for volume controls need to end with Volume for userspace to understand them properly, give these the same names that the DAPM mixer controls have but end with Volume instead of Switch and then userspace will be able to combine them when displaying.

sound/soc/codecs/nau8824.c line 467

Quoted 3 lines
sound/soc/codecs/nau8824.c new file +3 -0
+       case SND_SOC_DAPM_POST_PMU:
+               /* Prevent startup click by letting charge pump to ramp up */
+               usleep_range(10000, 11000);

I believe the current preference is to do this as just msleep(10).

sound/soc/codecs/nau8824.c line 1331

Quoted 7 lines
sound/soc/codecs/nau8824.c new file +7 -0
+static int nau8824_codec_probe(struct snd_soc_codec *codec)
+{
+       struct nau8824 *nau8824 = snd_soc_codec_get_drvdata(codec);
+       struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
+
+       nau8824->dapm = dapm;
+       snd_soc_dapm_sync(nau8824->dapm);

This sync shouldn't do anything, just remove it.

sound/soc/codecs/nau8824.c line 1343

Quoted 8 lines
sound/soc/codecs/nau8824.c new file +8 -0
+static int __maybe_unused nau8824_suspend(struct snd_soc_codec *codec)
+{
+       struct nau8824 *nau8824 = snd_soc_codec_get_drvdata(codec);
+
+       if (nau8824->irq) {
+               disable_irq(nau8824->irq);
+               snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF);
+       }

Why are we disabling the IRQ here?

sound/soc/codecs/nau8824.c line 1359

Quoted 4 lines
sound/soc/codecs/nau8824.c new file +4 -0
+       if (nau8824->irq) {
+               nau8824_sema_acquire(nau8824, 0);
+               enable_irq(nau8824->irq);
+       }

We didn't drop this sempahore in the suspend path? This stuff could at least use better comments.

sound/soc/codecs/nau8824.c line 1580

Quoted 4 lines
sound/soc/codecs/nau8824.c new file +4 -0
+       /* Boost FEPGA 20dB */
+       regmap_update_bits(regmap, NAU8824_REG_FEPGA_II,
+               NAU8824_FEPGA_GAINL_MASK | NAU8824_FEPGA_GAINR_MASK,
+               0xa | (0xa << NAU8824_FEPGA_GAINR_SFT));

Possibly something that should be controllable from userspace?

sound/soc/codecs/nau8824.c line 1696

Quoted 7 lines
sound/soc/codecs/nau8824.c new file +7 -0
+       nau8824_reset_chip(nau8824->regmap);
+       ret = regmap_read(nau8824->regmap, NAU8824_REG_I2C_DEVICE_ID, &value);
+       if (ret < 0) {
+               dev_err(dev, "Failed to read device id from the NAU8824: %d\n",
+                       ret);
+               return ret;
+       }

Perhaps check the device ID before resetting the chip (and verify that the device ID is what's expected)? That way if the system is misconfigured then the check will be less disruptive.

author
#2 lore raw

Hi,

Quoted 5 lines · Mark Brown

On Thu, Jan 26, 2017 at 11:48:09AM +0800, John Hsu wrote:

This looks mostly good, a few fairly small things below:

Quoted 10 lines

sound/soc/codecs/nau8824.c line 363

Quoted 3 lines
sound/soc/codecs/nau8824.c new file +2 -0
+       SOC_SINGLE_TLV("Speaker Right Volume from DACR",
+               NAU8824_REG_CLASSD_GAIN_1, 8, 0x1f, 0, spk_vol_tlv),

Names for volume controls need to end with Volume for userspace to understand them properly, give these the same names that the DAPM mixer controls have but end with Volume instead of Switch and then userspace will be able to combine them when displaying.

We'll rename these controls.

Quoted 8 lines

sound/soc/codecs/nau8824.c line 467

Quoted 4 lines
sound/soc/codecs/nau8824.c new file +3 -0
+       case SND_SOC_DAPM_POST_PMU:
+               /* Prevent startup click by letting charge pump to ramp up */
+               usleep_range(10000, 11000);

I believe the current preference is to do this as just msleep(10).

Thanks for remind. Note and change it.

Quoted 12 lines

sound/soc/codecs/nau8824.c line 1331

Quoted 8 lines
sound/soc/codecs/nau8824.c new file +7 -0
+static int nau8824_codec_probe(struct snd_soc_codec *codec)
+{
+       struct nau8824 *nau8824 = snd_soc_codec_get_drvdata(codec);
+       struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
+
+       nau8824->dapm = dapm;
+       snd_soc_dapm_sync(nau8824->dapm);

This sync shouldn't do anything, just remove it.

OK, we'll remove it.

Quoted 13 lines

sound/soc/codecs/nau8824.c line 1343

Quoted 9 lines
sound/soc/codecs/nau8824.c new file +8 -0
+static int __maybe_unused nau8824_suspend(struct snd_soc_codec *codec)
+{
+       struct nau8824 *nau8824 = snd_soc_codec_get_drvdata(codec);
+
+       if (nau8824->irq) {
+               disable_irq(nau8824->irq);
+               snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF);
+       }

Why are we disabling the IRQ here?

In some cases, there is IRQ storm after resume. It's safe to disable IRQ for the case. But the issue is happened because of hardware defect. It's not happened for normal case.

Quoted 10 lines

sound/soc/codecs/nau8824.c line 1359

Quoted 5 lines
sound/soc/codecs/nau8824.c new file +4 -0
+       if (nau8824->irq) {
+               nau8824_sema_acquire(nau8824, 0);
+               enable_irq(nau8824->irq);
+       }

We didn't drop this sempahore in the suspend path? This stuff could at least use better comments.

The semaphore can help to arrange the sequence between playback and jack detection. We can add comment for the purpose.

Quoted 9 lines

sound/soc/codecs/nau8824.c line 1580

Quoted 5 lines
sound/soc/codecs/nau8824.c new file +4 -0
+       /* Boost FEPGA 20dB */
+       regmap_update_bits(regmap, NAU8824_REG_FEPGA_II,
+               NAU8824_FEPGA_GAINL_MASK | NAU8824_FEPGA_GAINR_MASK,
+               0xa | (0xa << NAU8824_FEPGA_GAINR_SFT));

Possibly something that should be controllable from userspace?

OK, the default configuration can be removed and let usersapce to management.

Quoted 9 lines

sound/soc/codecs/nau8824.c line 1696

Quoted 8 lines
sound/soc/codecs/nau8824.c new file +7 -0
+       nau8824_reset_chip(nau8824->regmap);
+       ret = regmap_read(nau8824->regmap, NAU8824_REG_I2C_DEVICE_ID, &value);
+       if (ret < 0) {
+               dev_err(dev, "Failed to read device id from the NAU8824: %d\n",
+                       ret);
+               return ret;
+       }
Quoted 4 lines

Perhaps check the device ID before resetting the chip (and verify that the device ID is what's expected)? That way if the system is misconfigured then the check will be less disruptive.

We'll rearrange the sequence.

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