ASoC: nau8825: Add driver for headset chip Nuvoton 8825
Subsystems (3)
PATCH 1/1 ASoC: nau8825: Add driver for headset chip Nuvoton 8825
--- .../devicetree/bindings/sound/nau8825.txt | 88 ++ sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/nau8825.c | 1041 ++++++++++++++++++++ sound/soc/codecs/nau8825.h | 317 ++++++ 5 files changed, 1452 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/nau8825.txt create mode 100644 sound/soc/codecs/nau8825.c create mode 100644 sound/soc/codecs/nau8825.h
Documentation/devicetree/bindings/sound/nau8825.txt new file +88 -0
@@ -0,0 +1,88 @@ +Nuvoton NAU8825 audio codec + +This device supports I2C only. + +Required properties: + - compatible : Must be "nuvoton,nau8825" + + - reg : the I2C address of the device. This is either 0x1a (CSB=0) or 0x1b (CSB=1). + +Optional properties: + - nuvoton,jkdet-enable: Enable jack detection via JKDET pin. + - nuvoton,jkdet-pull-enable: Enable JKDET pin pull. If set - pin pull enabled, + otherwise pin in high impedance state. + - nuvoton,jkdet-pull-up: Pull-up JKDET pin. If set then JKDET pin is pull up, otherwise pull down. + - nuvoton,jkdet-polarity: JKDET pin polarity. 0 - active high, 1 - active low. + + - 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,short-key-debounce: Button short key press debounce time. + 0 - 30ms + 1 - 50ms + 2 - 100ms + 3 - 30ms + + - nuvoton,jack-insert-debounce: number from 0 to 7 that sets debounce time to 2^(n+2) ms + - nuvoton,jack-eject-debounce: number from 0 to 7 that sets debounce time to 2^(n+2) ms + + - clocks: list of phandle and clock specifier pairs according to common clock bindings for the + clocks described in clock-names + - clock-names: should include "mclk" for the MCLK master clock + +Example: + + headset: nau8825@1a { + compatible = "nuvoton,nau8825"; + reg = <0x1a>; + interrupt-parent = <&gpio>; + interrupts = <TEGRA_GPIO(E, 6) IRQ_TYPE_LEVEL_LOW>; + nuvoton,jkdet-enable; + nuvoton,jkdet-pull-enable; + nuvoton,jkdet-pull-up; + nuvoton,jkdet-polarity = <GPIO_ACTIVE_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 = <1>; + nuvoton,sar-voltage = <0>; + nuvoton,short-key-debounce = <2>; + nuvoton,jack-insert-debounce = <7>; + nuvoton,jack-eject-debounce = <7>; + + clock-names = "mclk"; + clocks = <&tegra_car TEGRA210_CLK_CLK_OUT_2>; + };
sound/soc/codecs/Kconfig +4 -0
@@ -79,6 +79,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_NAU8825 if I2C select SND_SOC_HDMI_CODEC select SND_SOC_PCM1681 if I2C select SND_SOC_PCM1792A if SPI_MASTER
@@ -896,6 +897,9 @@ config SND_SOC_MC13783 config SND_SOC_ML26124 tristate +config SND_SOC_NAU8825 + tristate + config SND_SOC_TPA6130A2 tristate "Texas Instruments TPA6130A2 headphone amplifier" depends on I2C
sound/soc/codecs/Makefile +2 -0
@@ -72,6 +72,7 @@ snd-soc-max98925-objs := max98925.o snd-soc-max9850-objs := max9850.o snd-soc-mc13783-objs := mc13783.o snd-soc-ml26124-objs := ml26124.o +snd-soc-nau8825-objs := nau8825.o snd-soc-hdmi-codec-objs := hdmi.o snd-soc-pcm1681-objs := pcm1681.o snd-soc-pcm1792a-codec-objs := pcm1792a.o
@@ -264,6 +265,7 @@ obj-$(CONFIG_SND_SOC_MAX98925) += snd-soc-max98925.o obj-$(CONFIG_SND_SOC_MAX9850) += snd-soc-max9850.o obj-$(CONFIG_SND_SOC_MC13783) += snd-soc-mc13783.o obj-$(CONFIG_SND_SOC_ML26124) += snd-soc-ml26124.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 obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o
sound/soc/codecs/nau8825.c new file +1041 -0
1,041 lines not on this page · raw message
sound/soc/codecs/nau8825.h new file +317 -0
317 lines not on this page · raw message
Signature · 1 line
2.5.0.457.gab17608
Mark Brown
maintainersound/soc/codecs/nau8825.c line 217
Quoted 2 lines · Anatol Pomozov
sound/soc/codecs/nau8825.c new file +2
-0+SOC_SINGLE_TLV ("Frontend PGA Gain" ,NAU8825_REG_POWER_UP_CONTROL , + 8, 37, 0, fepga_gain_tlv),
All volume controls need to end in Volume as per ControlNames.txt.
sound/soc/codecs/nau8825.c line 365
Quoted 4 lines
sound/soc/codecs/nau8825.c new file +4
-0+default : +return -EINVAL ; + } + regmap_update_bits(nau8825->regmap, NAU8825_REG_I2S_PCM_CTRL1,
Blank line here.
sound/soc/codecs/nau8825.c line 699
Quoted 5 lines
sound/soc/codecs/nau8825.c new file +5
-0+/* Bias and clock are needed for button detection */ +regmap_update_bits (nau8825->regmap,NAU8825_REG_BIAS_ADJ , +NAU8825_BIAS_VMID ,NAU8825_BIAS_VMID ); +regmap_update_bits (nau8825->regmap,NAU8825_REG_BOOST , +NAU8825_GLOBAL_BIAS_EN ,NAU8825_GLOBAL_BIAS_EN );
These sound like DAPM widgets which should be being eneabled when jack detection is enabled.
sound/soc/codecs/nau8825.c line 716
Quoted 5 lines
sound/soc/codecs/nau8825.c new file +5
-0+/* Ground HP Outputs[1:0], needed for headset auto detection +* Enable Automatic Mic/Gnd switching reading on insert interrupt[6] */ +regmap_update_bits (regmap,NAU8825_REG_HSD_CTRL , +NAU8825_HSD_AUTO_MODE |NAU8825_SPKR_DWN1R |NAU8825_SPKR_DWN1L , +NAU8825_HSD_AUTO_MODE |NAU8825_SPKR_DWN1R |NAU8825_SPKR_DWN1L );
I'm still not happy to see the unconditional enabling of detection and switching.
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!nau8825->mclk_freq) + clk_prepare_enable(nau8825->mclk);
You should be checking the return value here.
sound/soc/codecs/nau8825.c line 817
Quoted 5 lines
sound/soc/codecs/nau8825.c new file +5
-0+if (nau8825->mclk_freq != freq) { + nau8825->mclk_freq = freq; + + freq =clk_round_rate (nau8825->mclk, freq); +clk_set_rate (nau8825->mclk, freq);
Likewise here and in other cases where you're setting clocks.
sound/soc/codecs/nau8825.c line 929
Quoted 2 lines
sound/soc/codecs/nau8825.c new file +2
-0+ nau8825->jkdet_enable =device_property_read_bool (dev, +"nuvoton,jkdet-enable" );
This DT parsing stuff should really be moved out into a separate function which is only called (or only does anything) if there is actually DT data (if there is an of_node set).
sound/soc/codecs/nau8825.c line 1010
Quoted 11 lines
sound/soc/codecs/nau8825.c new file +11
-0+if (nau8825->irq) { +int ret =devm_request_threaded_irq (dev, nau8825->irq,NULL , + nau8825_interrupt,IRQF_TRIGGER_LOW |IRQF_ONESHOT , +"nau8825" , nau8825); + +if (ret) { +dev_err (dev,"Cannot request irq %d (%d)\n" , + nau8825->irq, ret); +return ret; + } + }
So we actually handle systems with no interrupt wired up? That seems to make all the non-optional enabling of the jack detection interrupts a bit odd.
sound/soc/codecs/nau8825.c line 1036
Quoted 9 lines
sound/soc/codecs/nau8825.c new file +9
-0+static struct i2c_driver nau8825_driver = { + .driver = { + .name ="nau8825" , + .owner =THIS_MODULE , + }, + .probe = nau8825_i2c_probe, + .remove = nau8825_i2c_remove, + .id_table = nau8825_i2c_ids, +};
This has a DT binding but no OF IDs defined. It is true that Linux will currently try to guess a suitable driver based on the I2C ID table but it is bad practice to rely on this behaviour, we do see ID collisions sometimes (for example both WonderMedia and Wolfson using WM for their parts).
Hi
Quoted 6 lines · Mark Brown
sound/soc/codecs/nau8825.c line 217
Quoted 2 lines · Anatol Pomozov
sound/soc/codecs/nau8825.c new file +2
-0+SOC_SINGLE_TLV ("Frontend PGA Gain" ,NAU8825_REG_POWER_UP_CONTROL , + 8, 37, 0, fepga_gain_tlv),All volume controls need to end in Volume as per ControlNames.txt.
Done.
Quoted 7 lines
sound/soc/codecs/nau8825.c line 365
Quoted 5 lines
sound/soc/codecs/nau8825.c new file +4
-0+default : +return -EINVAL ; + } + regmap_update_bits(nau8825->regmap, NAU8825_REG_I2S_PCM_CTRL1,Blank line here.
Done.
Quoted 8 lines
sound/soc/codecs/nau8825.c line 699
Quoted 5 lines
sound/soc/codecs/nau8825.c new file +5
-0+/* Bias and clock are needed for button detection */ +regmap_update_bits (nau8825->regmap,NAU8825_REG_BIAS_ADJ , +NAU8825_BIAS_VMID ,NAU8825_BIAS_VMID ); +regmap_update_bits (nau8825->regmap,NAU8825_REG_BOOST , +NAU8825_GLOBAL_BIAS_EN ,NAU8825_GLOBAL_BIAS_EN );These sound like DAPM widgets which should be being eneabled when jack detection is enabled.
The bias/vmid need to be enabled before clock/interruptions. Moving it to set_bias or to a widget makes interrupts non-functional. bias/vmid is also needed for capture and playback. So I think it is ok to enable it here. Later Nuvoton engineers will look at power management closer and might find better place for bias setup.
Quoted 8 lines
sound/soc/codecs/nau8825.c line 716
Quoted 5 lines
sound/soc/codecs/nau8825.c new file +5
-0+/* Ground HP Outputs[1:0], needed for headset auto detection +* Enable Automatic Mic/Gnd switching reading on insert interrupt[6] */ +regmap_update_bits (regmap,NAU8825_REG_HSD_CTRL , +NAU8825_HSD_AUTO_MODE |NAU8825_SPKR_DWN1R |NAU8825_SPKR_DWN1L , +NAU8825_HSD_AUTO_MODE |NAU8825_SPKR_DWN1R |NAU8825_SPKR_DWN1L );I'm still not happy to see the unconditional enabling of detection and switching.
Moved to enable_jack_detection(). Note that it looses "auto mic type detection" functionality if jack_detection is disabled. Such auto mic detection might be useful even in case if there is no physical jack and input/output routes are soldered statically.
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ if (!nau8825->mclk_freq) + clk_prepare_enable(nau8825->mclk);You should be checking the return value here.
Done.
Quoted 7 lines
sound/soc/codecs/nau8825.c line 817
Quoted 6 lines
sound/soc/codecs/nau8825.c new file +5
-0+if (nau8825->mclk_freq != freq) { + nau8825->mclk_freq = freq; + + freq =clk_round_rate (nau8825->mclk, freq); +clk_set_rate (nau8825->mclk, freq);
Quoted 7 lines
Likewise here and in other cases where you're setting clocks.
sound/soc/codecs/nau8825.c line 929
Quoted 2 lines
sound/soc/codecs/nau8825.c new file +2
-0+ nau8825->jkdet_enable =device_property_read_bool (dev, +"nuvoton,jkdet-enable" );This DT parsing stuff should really be moved out into a separate function
Thanks. Moved.
Quoted 2 lines
which is only called (or only does anything) if there is actually DT data (if there is an
of_nodeset).
device_property_read_* handles both DTS and ACPI that covers most (all?) modern systems.
Or are you talking about case when a platform driver passes pre-initialized data from using dev_get_platdata() (like what rt5677 does)? I assume this is a deprecated style that predates DTS/ACPI style configuration.
Quoted 13 lines
sound/soc/codecs/nau8825.c line 1010
Quoted 12 lines
sound/soc/codecs/nau8825.c new file +11
-0+if (nau8825->irq) { +int ret =devm_request_threaded_irq (dev, nau8825->irq,NULL , + nau8825_interrupt,IRQF_TRIGGER_LOW |IRQF_ONESHOT , +"nau8825" , nau8825); + +if (ret) { +dev_err (dev,"Cannot request irq %d (%d)\n" , + nau8825->irq, ret); +return ret; + } + }
Quoted 1 line
So we actually handle systems with no interrupt wired up?
I think it worth adding such configuration. Without the IRQ line this chip looses large part of its functionality (jack detection, mic auto detect, buttons, cross-talk configuration) but at least playback should work.
Quoted 3 lines
That seems to
make all the non-optional enabling of the jack detection interrupts a bit odd.
Moved jack irq enabling to enable_jack_detection()
Quoted 16 lines
sound/soc/codecs/nau8825.c line 1036
Quoted 10 lines
sound/soc/codecs/nau8825.c new file +9
-0+static struct i2c_driver nau8825_driver = { + .driver = { + .name ="nau8825" , + .owner =THIS_MODULE , + }, + .probe = nau8825_i2c_probe, + .remove = nau8825_i2c_remove, + .id_table = nau8825_i2c_ids, +};This has a DT binding but no OF IDs defined. It is true that Linux will currently try to guess a suitable driver based on the I2C ID table but it is bad practice to rely on this behaviour, we do see ID collisions sometimes (for example both WonderMedia and Wolfson using WM for their parts).
Done. Thanks for the pointer.
Mark Brown
maintainerQuoted 5 lines · Anatol Pomozov
Quoted 2 lines · Mark Brown
which is only called (or only does anything) if there is actually DT data (if there is an
of_nodeset).
Quoted 7 lines
device_property_read_* handles both DTS and ACPI that covers most (all?) modern systems.
Or are you talking about case when a platform driver passes pre-initialized data from using
dev_get_platdata()(like what rt5677 does)? I assume this is a deprecated style that predates DTS/ACPI style configuration.
Not all architectures use DT or ACPI, the driver should really support them.