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 | 14 + sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/nau8825.c | 860 +++++++++++++++++++++ sound/soc/codecs/nau8825.h | 258 +++++++ 5 files changed, 1138 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 +14 -0
@@ -0,0 +1,14 @@ +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). + +Example: + + codec: nau8825@1a { + compatible = "nuvoton,nau8825"; + reg = <0x1a>; + };
sound/soc/codecs/Kconfig +4 -0
@@ -78,6 +78,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
@@ -892,6 +893,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
@@ -71,6 +71,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
@@ -262,6 +263,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 +860 -0
860 lines not on this page · raw message
sound/soc/codecs/nau8825.h new file +258 -0
258 lines not on this page · raw message
Signature · 1 line
2.5.0.rc2.392.g76e840b
Mark Brown
maintainerOn Mon, Jul 27, 2015 at 04:13:57PM -0700, Anatol Pomozov wrote:
Looks mostly good, a few things below though:
sound/soc/codecs/nau8825.c line 565
Quoted 3 lines
sound/soc/codecs/nau8825.c new file +3
-0+break ; +case 1 : +dev_info (nau8825->dev,"OMTP (micgnd1) mic connected\n" );
This is far too noisy - these should be dev_dbg() at most.
sound/soc/codecs/nau8825.c line 654
Quoted 4 lines
sound/soc/codecs/nau8825.c new file +4
-0+ }else { +dev_warn (nau8825->dev,"Headset completion IRQ fired but no headset connected\n" ); +nau8825_eject_jack (nau8825); + }
Things like this that aren't supposed to happen are fine but normal operation shouild be quiet.
sound/soc/codecs/nau8825.c line 694
Quoted 2 lines
sound/soc/codecs/nau8825.c new file +2
-0+/* VMID Enable and Tieoff */ +regmap_write (regmap,NAU8825_REG_BIAS_ADJ ,0x0060 );
You're leavinng VMID enabled all the timme?
sound/soc/codecs/nau8825.c line 706
Quoted 2 lines
sound/soc/codecs/nau8825.c new file +2
-0+/* Jack Detect pull up (High=eject, Low=insert) */ +regmap_write (regmap,NAU8825_REG_GPIO12_CTRL ,0x0800 );
This seems like it should be a board setting?
sound/soc/codecs/nau8825.c line 708
Quoted 2 lines
sound/soc/codecs/nau8825.c new file +2
-0+/* Setup SAR ADC */ +regmap_write (regmap,NAU8825_REG_SAR_CTRL ,0x0280 );
Lots of magic numbers in these things... some of them I can guess what's going on but this one is a bit obscure, perhaps it should be user controllable?
sound/soc/codecs/nau8825.c line 714
Quoted 4 lines
sound/soc/codecs/nau8825.c new file +4
-0+/* Setup ADC x128 OSR */ +regmap_write (regmap,NAU8825_REG_ADC_RATE ,0x0002 ); +/* Setup DAC x128 OSR */ +regmap_write (regmap,NAU8825_REG_DAC_CTRL1 ,0x0082 );
I'd expect this to be user controllable.
Quoted 25 lines
sound/soc/codecs/nau8825.c new file +25
-0+static int nau8825_i2c_probe (struct i2c_client *i2c, +const struct i2c_device_id *id) +{ +struct device *dev = &i2c->dev; +struct nau8825 *nau8825; +int ret, value; + + nau8825 =devm_kzalloc (dev,sizeof (*nau8825),GFP_KERNEL ); +if (!nau8825) +return -ENOMEM ; + +i2c_set_clientdata (i2c, nau8825); + + nau8825->regmap =devm_regmap_init_i2c (i2c, &nau8825_regmap_config); +if (IS_ERR (nau8825->regmap)) +return PTR_ERR (nau8825->regmap); + nau8825->irq = i2c->irq; + nau8825->dev = dev; + +nau8825_reset_chip (nau8825->regmap); + ret =regmap_read (nau8825->regmap,NAU8825_REG_I2C_DEVICE_ID , &value); +if (ret <0 ) { +dev_err (dev,"Failed to read device id from the NAU8825: %d\n" , + ret); +return ret;
sound/soc/codecs/nau8825.c line 833
Quoted 10 lines
sound/soc/codecs/nau8825.c new file +10
-0+ } +if ((value &NAU8825_SOFTWARE_ID_MASK ) != +NAU8825_SOFTWARE_ID_NAU8825 ) { +dev_err (dev,"Not a NAU8825 chip\n" ); +return -ENODEV ; + } + +return snd_soc_register_codec (&i2c->dev, &nau8825_codec_driver, + &nau8825_dai,1 ); +}
I'd expect any initial register initialistion to happen here (if only so we save power until the card registers).
Hi
Quoted 9 lines · Mark Brown
On Mon, Jul 27, 2015 at 04:13:57PM -0700, Anatol Pomozov wrote:
Looks mostly good, a few things below though:
sound/soc/codecs/nau8825.c line 565
Quoted 3 lines
sound/soc/codecs/nau8825.c new file +3
-0+break ; +case 1 : +dev_info (nau8825->dev,"OMTP (micgnd1) mic connected\n" );This is far too noisy - these should be
dev_dbg()at most.
Done
Quoted 6 lines
sound/soc/codecs/nau8825.c line 654
Quoted 5 lines
sound/soc/codecs/nau8825.c new file +4
-0+ }else { +dev_warn (nau8825->dev,"Headset completion IRQ fired but no headset connected\n" ); +nau8825_eject_jack (nau8825); + }
Quoted 7 lines
Things like this that aren't supposed to happen are fine but normal operation shouild be quiet.
sound/soc/codecs/nau8825.c line 694
Quoted 2 lines
sound/soc/codecs/nau8825.c new file +2
-0+/* VMID Enable and Tieoff */ +regmap_write (regmap,NAU8825_REG_BIAS_ADJ ,0x0060 );You're leavinng VMID enabled all the timme?
Currently yes. One of the next steps is to look at the power management for this chip (set_bias and suspend/resume). I need to work with Nuvoton HW engineers to find correct sequence of steps.
Quoted 5 lines
sound/soc/codecs/nau8825.c line 706
Quoted 3 lines
sound/soc/codecs/nau8825.c new file +2
-0+/* Jack Detect pull up (High=eject, Low=insert) */ +regmap_write (regmap,NAU8825_REG_GPIO12_CTRL ,0x0800 );This seems like it should be a board setting?
Created DTS property for it. Thanks.
Quoted 5 lines
sound/soc/codecs/nau8825.c line 708
Quoted 3 lines
sound/soc/codecs/nau8825.c new file +2
-0+/* Setup SAR ADC */ +regmap_write (regmap,NAU8825_REG_SAR_CTRL ,0x0280 );Lots of magic numbers in these things...
These init config settings recommended by Nuvoton engineers. I found that chip requires quite a lot of initial preconfiguration to get it into operating state.
Quoted 3 lines
some of them I can guess
what's going on but this one is a bit obscure, perhaps it should be user controllable?
This setting configures SARADC (ADC for sensing button presses). It sets sample rate, series resistor and ADC voltage range. It does not look like they need to be user-controllable.
Quoted 7 lines
sound/soc/codecs/nau8825.c line 714
Quoted 5 lines
sound/soc/codecs/nau8825.c new file +4
-0+ /* Setup ADC x128 OSR */Moved to +regmap_write (regmap,NAU8825_REG_ADC_RATE ,0x0002 ); +/* Setup DAC x128 OSR */ +regmap_write (regmap,NAU8825_REG_DAC_CTRL1 ,0x0082 );I'd expect this to be user controllable.
The oversampling configuration is important for chip audio quality. There is audible hissing without these settings.
My understanding that all users need to set these values and it is better to move it to the driver initialization sequence.
Quoted 30 lines
Quoted 30 lines
sound/soc/codecs/nau8825.c new file +30
-0+static int nau8825_i2c_probe (struct i2c_client *i2c, +const struct i2c_device_id *id) +{ +struct device *dev = &i2c->dev; +struct nau8825 *nau8825; +int ret, value; + + nau8825 =devm_kzalloc (dev,sizeof (*nau8825),GFP_KERNEL ); +if (!nau8825) +return -ENOMEM ; + +i2c_set_clientdata (i2c, nau8825); + + nau8825->regmap =devm_regmap_init_i2c (i2c, &nau8825_regmap_config); +if (IS_ERR (nau8825->regmap)) +return PTR_ERR (nau8825->regmap); + nau8825->irq = i2c->irq; + nau8825->dev = dev; + +nau8825_reset_chip (nau8825->regmap); + ret =regmap_read (nau8825->regmap,NAU8825_REG_I2C_DEVICE_ID , &value); +if (ret <0 ) { +dev_err (dev,"Failed to read device id from the NAU8825: %d\n" , + ret); +return ret; + } +if ((value &NAU8825_SOFTWARE_ID_MASK ) != +NAU8825_SOFTWARE_ID_NAU8825 ) { +dev_err (dev,"Not a NAU8825 chip\n" ); +return -ENODEV ;
Quoted 8 lines
sound/soc/codecs/nau8825.c line 833
Quoted 5 lines
sound/soc/codecs/nau8825.c new file +5
-0+ } + +return snd_soc_register_codec (&i2c->dev, &nau8825_codec_driver, + &nau8825_dai,1 ); +}I'd expect any initial register initialistion to happen here (if only so we save power until the card registers).
Moved most of the initialization here. The only part is left in codec_probe() is interruption initialization via I2S master mode toggling. That toggling trick depends on MCLK signal to initialize interruption block correctly. In our case (a tegra SoC device) MCLK is initialized later at audio platform driver probe.
Mark Brown
maintainerQuoted 11 lines · Anatol Pomozov
Quoted 6 lines · Mark Brown
sound/soc/codecs/nau8825.c line 708
Quoted 2 lines · Anatol Pomozov
sound/soc/codecs/nau8825.c new file +2
-0+/* Setup SAR ADC */ +regmap_write (regmap,NAU8825_REG_SAR_CTRL ,0x0280 );Lots of magic numbers in these things...
These init config settings recommended by Nuvoton engineers. I found that chip requires quite a lot of initial preconfiguration to get it into operating state.
Random register write lists from the vendor for documented registers are not generally a good thing to rely on too much, they frequently set up use case specific things in the middle of other perhaps useful changes.
Quoted 7 lines
Quoted 3 lines
some of them I can guess
what's going on but this one is a bit obscure, perhaps it should be user controllable?This setting configures SARADC (ADC for sensing button presses). It sets sample rate, series resistor and ADC voltage range. It does not look like they need to be user-controllable.
Those sound like they may well be system dependent, the sample rate will most likely feed back into the sensitivity of the detection (how long the button needs to be pressed for and so on) and the other bits sound like they could change depending on the configuration of the accessory.
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
sound/soc/codecs/nau8825.c new file +4
-0+ /* Setup ADC x128 OSR */Moved to +regmap_write (regmap,NAU8825_REG_ADC_RATE ,0x0002 ); +/* Setup DAC x128 OSR */ +regmap_write (regmap,NAU8825_REG_DAC_CTRL1 ,0x0082 );
Quoted 7 lines
Quoted 1 line
I'd expect this to be user controllable.
The oversampling configuration is important for chip audio quality. There is audible hissing without these settings.
My understanding that all users need to set these values and it is better to move it to the driver initialization sequence.
That sounds like spectacularly poor quality of implementation, but even if there's a noticeable reduction in audio quality the control should still be given to the user, they may have an application where power is much more important than audio quality (eg, if they are doing some form of recognition on the audio then all they need is something good enough for their algorithm).
Quoted 8 lines
Quoted 2 lines
I'd expect any initial register initialistion to happen here (if only so we save power until the card registers).
Moved most of the initialization here. The only part is left in
codec_probe()is interruption initialization via I2S master mode toggling. That toggling trick depends on MCLK signal to initialize interruption block correctly. In our case (a tegra SoC device) MCLK is initialized later at audio platform driver probe.
If you need to control MCLK you should be using the clock API to get MCLK which you can do in the driver model probe. Relying on the machine driver to control MCLK for you in this way is at best fragile.
Hi
Quoted 8 lines · Mark Brown
Quoted 7 lines · Anatol Pomozov
Quoted 6 lines · Mark Brown
sound/soc/codecs/nau8825.c line 708
Quoted 2 lines · Anatol Pomozov
sound/soc/codecs/nau8825.c new file +2
-0+/* Setup SAR ADC */ +regmap_write (regmap,NAU8825_REG_SAR_CTRL ,0x0280 );Lots of magic numbers in these things...
Okay, I moved the magic number to board configuration options. Now most of these numbers can be configured via dts.
Quoted 13 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
sound/soc/codecs/nau8825.c new file +4
-0+ /* Setup ADC x128 OSR */Moved to +regmap_write (regmap,NAU8825_REG_ADC_RATE ,0x0002 ); +/* Setup DAC x128 OSR */ +regmap_write (regmap,NAU8825_REG_DAC_CTRL1 ,0x0082 );Quoted 7 lines
Quoted 1 line
I'd expect this to be user controllable.
The oversampling configuration is important for chip audio quality. There is audible hissing without these settings.
My understanding that all users need to set these values and it is better to move it to the driver initialization sequence.
Quoted 6 lines
That sounds like spectacularly poor quality of implementation, but even if there's a noticeable reduction in audio quality the control should still be given to the user, they may have an application where power is much more important than audio quality (eg, if they are doing some form of recognition on the audio then all they need is something good enough for their algorithm).
Moved it to ALSA controls. Though I still feel a bit uncomfortable that the default control value is not usable.
I have to set "ADC Decimation Rate" and "DAC Oversampling Rate" controls in userspace from its defaults to "128".
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines
I'd expect any initial register initialistion to happen here (if only so we save power until the card registers).
Moved most of the initialization here. The only part is left in
codec_probe()is interruption initialization via I2S master mode toggling. That toggling trick depends on MCLK signal to initialize interruption block correctly. In our case (a tegra SoC device) MCLK is initialized later at audio platform driver probe.
Quoted 3 lines
If you need to control MCLK you should be using the clock API to get MCLK which you can do in the driver model probe. Relying on the machine driver to control MCLK for you in this way is at best fragile.
After discussing it with my teammates who works on Intel+NAU8825 platform I found that they use MCLK only at playback/capture time. The rest of the time VCO is suppose to be sysclk source. Thus using get_clk() is not flexible for all cases.
What I propose is to initialize driver with VCO as a sysclk source. And later a platform driver can change it to MCLK. Added set_sysclk() stub that works well with VCO->MCKL transition, tested it on TegraX1. Follow-up changes should improve VCO/FLL configuration.
Quoted 7 lines
Documentation/devicetree/bindings/sound/nau8825.txt
Quoted 4 lines
Documentation/devicetree/bindings/sound/nau8825.txt new file +4
-0+ codec: nau8825@1a { + compatible = "nuvoton,nau8825"; + reg = <0x1a>; + nuvoton,jkdet-pullup = "true";...this isn't how boolean properties are done, the property simply needs to exist.
Fixed.
Quoted 15 lines
Quoted 15 lines
sound/soc/codecs/nau8825.c new file +14
-0+static int nau8825_output_driver_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kcontrol,int event) +{ +struct snd_soc_codec *codec =snd_soc_dapm_to_codec (w->dapm); +struct nau8825 *nau8825 =snd_soc_codec_get_drvdata (codec); +struct regmap *regmap = nau8825->regmap; + +if (SND_SOC_DAPM_EVENT_ON (event)) { +/* Power Up L and R Output Drivers */ +regmap_update_bits (regmap,NAU8825_REG_POWER_UP_CONTROL ,0x3c , +0x3c ); +/* Power up Main Output Drivers (The main driver must be turned +on after the predriver to avoid pops) */ + regmap_update_bits(regmap, NAU8825_REG_POWER_UP_CONTROL, 0x3,
Quoted 8 lines
sound/soc/codecs/nau8825.c line 232
Quoted 5 lines
sound/soc/codecs/nau8825.c new file +5
-0+ 0x3); + }else { +/* Power Down L and R Output Drivers */ +regmap_update_bits (regmap,NAU8825_REG_POWER_UP_CONTROL ,0x3f , +0x0 );You should be able to implement this with _S widgets without requiring explicit code, they're designed for exactly this situation.
I've decided to split this function into 6 different widgets. And it seems enough. No audible pop/clicks here.
Quoted 13 lines
sound/soc/codecs/nau8825.c line 488
Quoted 10 lines
sound/soc/codecs/nau8825.c new file +9
-0+int nau8825_enable_jack_detect (struct snd_soc_codec *codec, +struct snd_soc_jack *jack) +{ +struct nau8825 *nau8825 =snd_soc_codec_get_drvdata (codec); + +snd_jack_set_key (jack->jack,SND_JACK_BTN_0 ,KEY_MEDIA ); +snd_jack_set_key (jack->jack,SND_JACK_BTN_1 ,KEY_VOICECOMMAND ); +snd_jack_set_key (jack->jack,SND_JACK_BTN_2 ,KEY_VOLUMEUP ); +snd_jack_set_key (jack->jack,SND_JACK_BTN_3 ,KEY_VOLUMEDOWN );The driver shouldn't do this - it's up to the system integration to define how the buttons are mapped.
I was following code from ts3a227e driver that does the same.
Quoted 10 lines
sound/soc/codecs/nau8825.c line 494
Quoted 7 lines
sound/soc/codecs/nau8825.c new file +6
-0+ + nau8825->jack = jack; + +return 0 ; +} +EXPORT_SYMBOL_GPL (nau8825_enable_jack_detect);This function doesn't appear to affect the hardware. I would expect that the jack detection hardware is turned off when not in use.
Disabling jack detection means disable HeadsetCompletion IRQ. But the IRQ handler does a bunch of manual stuff like grounding/ungrounding jack pins. If IRQ handler is not called then neither playback nor capture will not work.
At this point this function just sets jack structure needed later in IRQ handler.
Quoted 10 lines
Quoted 10 lines
sound/soc/codecs/nau8825.c new file +9
-0+static void nau8825_setup_buttons (struct regmap *regmap) +{ +/* Setup Button Detect (Debounce, number of buttons, and Hysteresis) */ +regmap_write (regmap,NAU8825_REG_KEYDET_CTRL ,0x7311 ); + +/* Setup 4 buttons impedane according to Android specification +* https://source.android.com/accessories/headset-spec.html +* Button 0 - 0-70 Ohm +* Button 1 - 110-180 Ohm
Quoted 8 lines
sound/soc/codecs/nau8825.c line 685
Quoted 6 lines
sound/soc/codecs/nau8825.c new file +6
-0+* Button 2 - 210-290 Ohm +* Button 3 - 360-680 Ohm +*/ +regmap_write (regmap,NAU8825_REG_VDET_THRESHOLD_1 ,0x0f1f ); +regmap_write (regmap,NAU8825_REG_VDET_THRESHOLD_2 ,0x325f ); +}This looks like system configuration...
Moved to DTS.
Quoted 8 lines
sound/soc/codecs/nau8825.c line 764
Quoted 6 lines
sound/soc/codecs/nau8825.c new file +5
-0+/* The interrupt clock is gated by x1[10:8], +* one of them needs to be enabled all the time for +* interrupts to happen. */ +snd_soc_dapm_force_enable_pin (&codec->dapm,"DDACR" ); +snd_soc_dapm_sync (&codec->dapm);This should be tied to jack detection, not done unconditionally.
Mark Brown
maintainerQuoted 16 lines · Anatol Pomozov
Quoted 14 lines · Mark Brown
Quoted 12 lines · Anatol Pomozov
Quoted 6 lines
sound/soc/codecs/nau8825.c line 714
Quoted 4 lines
sound/soc/codecs/nau8825.c new file +4
-0+ /* Setup ADC x128 OSR */Moved to +regmap_write (regmap,NAU8825_REG_ADC_RATE ,0x0002 ); +/* Setup DAC x128 OSR */ +regmap_write (regmap,NAU8825_REG_DAC_CTRL1 ,0x0082 );I'd expect this to be user controllable.
The oversampling configuration is important for chip audio quality. There is audible hissing without these settings.
My understanding that all users need to set these values and it is better to move it to the driver initialization sequence.
Quoted 8 lines
Quoted 3 lines
That sounds like spectacularly poor quality of implementation, but even if there's a noticeable reduction in audio quality the control should still be given to the user, they may have an application where power is
Moved it to ALSA controls. Though I still feel a bit uncomfortable that the default control value is not usable.
I have to set "ADC Decimation Rate" and "DAC Oversampling Rate" controls in userspace from its defaults to "128".
Setting the default isn't too bad in this case (especially with a comment explaining why) - that doesn't preclude also providing user configuration.
Quoted 8 lines
Quoted 3 lines
If you need to control MCLK you should be using the clock API to get MCLK which you can do in the driver model probe. Relying on the machine driver to control MCLK for you in this way is at best fragile.
After discussing it with my teammates who works on Intel+NAU8825 platform I found that they use MCLK only at playback/capture time. The rest of the time VCO is suppose to be sysclk source. Thus using
get_clk()is not flexible for all cases.
I'm sorry, I don't understand. What makes you say that "using get_clk() is not flexible for all cases", I can't quite parse that bit?
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
sound/soc/codecs/nau8825.c new file +8
-0+int nau8825_enable_jack_detect (struct snd_soc_codec *codec, +struct snd_soc_jack *jack) +{ +struct nau8825 *nau8825 =snd_soc_codec_get_drvdata (codec); +snd_jack_set_key (jack->jack,SND_JACK_BTN_0 ,KEY_MEDIA ); +snd_jack_set_key (jack->jack,SND_JACK_BTN_1 ,KEY_VOICECOMMAND ); +snd_jack_set_key (jack->jack,SND_JACK_BTN_2 ,KEY_VOLUMEUP ); +snd_jack_set_key (jack->jack,SND_JACK_BTN_3 ,KEY_VOLUMEDOWN );
Quoted 4 lines
Quoted 2 lines
The driver shouldn't do this - it's up to the system integration to define how the buttons are mapped.
I was following code from ts3a227e driver that does the same.
That device is specifically tied to Chromebooks which have a defined mapping, as opposed to being a generic device which is usable on a range of devices.
Quoted 9 lines
Quoted 8 lines
sound/soc/codecs/nau8825.c line 494
Quoted 5 lines
sound/soc/codecs/nau8825.c new file +4
-0+ nau8825->jack = jack; +return 0 ; +} +EXPORT_SYMBOL_GPL (nau8825_enable_jack_detect);This function doesn't appear to affect the hardware. I would expect that the jack detection hardware is turned off when not in use.
Quoted 4 lines
Disabling jack detection means disable HeadsetCompletion IRQ. But the IRQ handler does a bunch of manual stuff like grounding/ungrounding jack pins. If IRQ handler is not called then neither playback nor capture will not work.
The assumption would be that if the system doesn't have or need jack detection then the jack pins won't be reconfigurable anyway.
Quoted 2 lines
At this point this function just sets jack structure needed later in IRQ handler.
I can see what it's doing, I'd just also expect it to also be starting and stopping the detection in the hardware.
Hi
Quoted 8 lines
Quoted 4 lines
Moved it to ALSA controls. Though I still feel a bit uncomfortable that the default control value is not usable.
I have to set "ADC Decimation Rate" and "DAC Oversampling Rate" controls in userspace from its defaults to "128".Setting the default isn't too bad in this case (especially with a comment explaining why) - that doesn't preclude also providing user configuration.
What is the best way to set default control value? Just a regmap_write()?
Quoted 7 lines
Quoted 4 lines
After discussing it with my teammates who works on Intel+NAU8825 platform I found that they use MCLK only at playback/capture time. The rest of the time VCO is suppose to be sysclk source. Thus using
get_clk()is not flexible for all cases.I'm sorry, I don't understand. What makes you say that "using
get_clk()is not flexible for all cases", I can't quite parse that bit?
My initial assumption was that you are talking about moving complete clock handling (clock initialization, MCLK frequency calculation based on rate, policy of switching clock sources i.e. everything that platform drivers do) to the the driver code.
I've looked at other codec drivers and did not find many examples of using clk api. The drivers seems expect clock signal is pre-configured already. e.g. tegra has a utility function that configures audio clocks tegra_asoc_utils_set_rate() and it actively used in tegra-based platform drivers.
Locally I tried to move clock initialization out of platform code to codec itself. Codec calls devm_clk_get() in init and sets frequency in nau8825_set_sysclk(). See it here
https://github.com/anatol/linux/tree/nau8825 It works fine on a Tegra-based device. But I found that devm_clk_get() is DTS specific and does not work with ACPI. We need NAU8825 driver for Intel platform as well.
Quoted 5 lines
Quoted 1 line
I was following code from ts3a227e driver that does the same.
That device is specifically tied to Chromebooks which have a defined mapping, as opposed to being a generic device which is usable on a range of devices.
I do not see anything Chromebook specific about this chip
http://www.ti.com/product/ts3a227e
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
This function doesn't appear to affect the hardware. I would expect that the jack detection hardware is turned off when not in use.
Disabling jack detection means disable HeadsetCompletion IRQ. But the IRQ handler does a bunch of manual stuff like grounding/ungrounding jack pins. If IRQ handler is not called then neither playback nor capture will not work.
Quoted 8 lines
The assumption would be that if the system doesn't have or need jack detection then the jack pins won't be reconfigurable anyway.
Quoted 2 lines
At this point this function just sets jack structure needed later in IRQ handler.
I can see what it's doing, I'd just also expect it to also be starting and stopping the detection in the hardware.
If we move IRQ enabling from init() function to enable_jack_detect() then it means chip will be unusable after the init(). It won't be able to playback nor capture audio. All developers will be forced to call nau88225_enable_jack_detect() from their platform driver to enable basic chip functionality. I think it is better if basic functionality is enabled during driver init and does not require additional steps.
It is better if I rename nau8825_enable_jack_detect() to nau8825_set_jack() to make cleaner what the function suppose to do. It sets jack structure that driver uses to report events to upper level. If the jack pointer is not set then driver still handles jack insert/eject internally but does not report it to the userspace.
Mark Brown
maintainerQuoted 10 lines · Anatol Pomozov
Quoted 8 lines
Quoted 4 lines
Moved it to ALSA controls. Though I still feel a bit uncomfortable that the default control value is not usable.
I have to set "ADC Decimation Rate" and "DAC Oversampling Rate" controls in userspace from its defaults to "128".Setting the default isn't too bad in this case (especially with a comment explaining why) - that doesn't preclude also providing user configuration.
What is the best way to set default control value? Just a
regmap_write()?
Yes.
Quoted 7 lines
Quoted 2 lines
I'm sorry, I don't understand. What makes you say that "using
get_clk()is not flexible for all cases", I can't quite parse that bit?My initial assumption was that you are talking about moving complete clock handling (clock initialization, MCLK frequency calculation based on rate, policy of switching clock sources i.e. everything that platform drivers do) to the the driver code.
That is the ideal thing.
Quoted 5 lines
I've looked at other codec drivers and did not find many examples of using clk api. The drivers seems expect clock signal is pre-configured already. e.g. tegra has a utility function that configures audio clocks
tegra_asoc_utils_set_rate()and it actively used in tegra-based platform drivers.
Most of these drivers predate the clock API, while there's no pressing need to update things (and it's pretty disruptive to existing systems especially older ones) if you're running into problems with new code that are best fixed with the clock API then you should do that.
Quoted 7 lines
Locally I tried to move clock initialization out of platform code to codec itself. Codec calls
devm_clk_get()in init and sets frequency innau8825_set_sysclk(). See it here
https://github.com/anatol/linux/tree/nau8825 It works fine on a Tegra-based device. But I found thatdevm_clk_get()is DTS specific and does not work with ACPI. We need NAU8825 driver for Intel platform as well.
No, that is not the case at all - what makes you claim that devm_clk_get() is DT specific?
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
I was following code from ts3a227e driver that does the same.
That device is specifically tied to Chromebooks which have a defined mapping, as opposed to being a generic device which is usable on a range of devices.
I do not see anything Chromebook specific about this chip
My understanding is that the accessories it supports are Chrombook/Android ones (note that there's no configuration of ranges for detection in the code).
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
At this point this function just sets jack structure needed later in IRQ handler.
I can see what it's doing, I'd just also expect it to also be starting and stopping the detection in the hardware.
Quoted 6 lines
If we move IRQ enabling from
init()function toenable_jack_detect()then it means chip will be unusable after theinit(). It won't be able to playback nor capture audio. All developers will be forced to callnau88225_enable_jack_detect()from their platform driver to enable basic chip functionality. I think it is better if basic functionality is enabled during driver init and does not require additional steps.
I very much doubt that this will be a problem for all boards. To repeat what I said in my previous reply:
| The assumption would be that if the system doesn't have or need jack | detection then the jack pins won't be reconfigurable anyway.
Your board may be wired up with jack detection configured in a way that needs this, I would be surprised if all boards were.
Quoted 5 lines
It is better if I rename
nau8825_enable_jack_detect()tonau8825_set_jack()to make cleaner what the function suppose to do. It sets jack structure that driver uses to report events to upper level. If the jack pointer is not set then driver still handles jack insert/eject internally but does not report it to the userspace.
No, that doesn't help.
Hi
Quoted 10 lines · Mark Brown
Quoted 7 lines
Locally I tried to move clock initialization out of platform code to codec itself. Codec calls
devm_clk_get()in init and sets frequency innau8825_set_sysclk(). See it here
https://github.com/anatol/linux/tree/nau8825 It works fine on a Tegra-based device. But I found thatdevm_clk_get()is DTS specific and does not work with ACPI. We need NAU8825 driver for Intel platform as well.No, that is not the case at all - what makes you claim that
devm_clk_get()is DT specific?
clk_dev uses of_clk_get_by_name() that is implemented for DTS only. See include/linux/clk.h.
ACPI has a compatible API for getting simple properties (strings/numbers), but no API for dealing with clocks.
Quoted 8 lines
I very much doubt that this will be a problem for all boards. To repeat what I said in my previous reply:
| The assumption would be that if the system doesn't have or need jack | detection then the jack pins won't be reconfigurable anyway.
Your board may be wired up with jack detection configured in a way that needs this, I would be surprised if all boards were.
I am still trying to understand the use-case for NAU8825 without jack detection functionality. Are you talking about a board configuration that does not wire jack to JKDET codec pin and (maybe) statically connects output to speakers?
If platform driver does not enable jack detection, what NAU8825 functionality suppose to work? Does output (HPL/HPR) suppose to work? Does mic suppose to work? Is OMTP/CTIA mic detection functionality needed?
Mark Brown
maintainerQuoted 7 lines · Anatol Pomozov
Quoted 2 lines · Mark Brown
No, that is not the case at all - what makes you claim that
devm_clk_get()is DT specific?
clk_devusesof_clk_get_by_name()that is implemented for DTS only. Seeinclude/linux/clk.h.
That means that the clock API can work with DT, not that DT is mandatory - notice how there are stubs for the non-DT case.
Quoted 2 lines
ACPI has a compatible API for getting simple properties (strings/numbers), but no API for dealing with clocks.
So ACPI based platforms have to deal with providing clocks in some other way, that's something that is abstracted away by the clock API. There are a number of drivers for both board file based and ACPI based systems already in tree which manage to make use of the clock API.
Quoted 6 lines
Quoted 5 lines
I very much doubt that this will be a problem for all boards. To repeat what I said in my previous reply:
| The assumption would be that if the system doesn't have or need jack | detection then the jack pins won't be reconfigurable anyway.
Quoted 7 lines
Quoted 2 lines
Your board may be wired up with jack detection configured in a way that needs this, I would be surprised if all boards were.
I am still trying to understand the use-case for NAU8825 without jack detection functionality. Are you talking about a board configuration that does not wire jack to JKDET codec pin and (maybe) statically connects output to speakers?
I'm not specifically familiar with this CODEC, however this sort of detection circuitry is all pretty standard. I'm thinking of the sort of straightforward configurations where the detection inputs and any outputs required to flip polarity of the jack are just not wired up.
Quoted 4 lines
If platform driver does not enable jack detection, what NAU8825 functionality suppose to work? Does output (HPL/HPR) suppose to work? Does mic suppose to work? Is OMTP/CTIA mic detection functionality needed?
I'd expect the detection functionality wouldn't work without being wired up as expected but I'd expect it to be perfectly possible to support the headphones with the default ground confirguration. I'd also expect mics to work, either connected to the headset with a fixed polarity or just elsewhere in the system. If the device is capable of supprorting headphones it must be capable of supporting them with a fixed ground, and similarly for microphones.
Hi
Quoted 12 lines · Mark Brown
Quoted 7 lines · Anatol Pomozov
Quoted 2 lines · Mark Brown
No, that is not the case at all - what makes you claim that
devm_clk_get()is DT specific?
clk_devusesof_clk_get_by_name()that is implemented for DTS only. Seeinclude/linux/clk.h.That means that the clock API can work with DT, not that DT is mandatory - notice how there are stubs for the non-DT case.
Quoted 7 lines
Quoted 2 lines
ACPI has a compatible API for getting simple properties (strings/numbers), but no API for dealing with clocks.
So ACPI based platforms have to deal with providing clocks in some other way, that's something that is abstracted away by the clock API. There are a number of drivers for both board file based and ACPI based systems already in tree which manage to make use of the clock API.
What is the best example of driver that uses clk API in both DT and ACPI friendly way? I will use it as a template for my driver.
Quoted 9 lines
Quoted 4 lines
I am still trying to understand the use-case for NAU8825 without jack detection functionality. Are you talking about a board configuration that does not wire jack to JKDET codec pin and (maybe) statically connects output to speakers?
I'm not specifically familiar with this CODEC, however this sort of detection circuitry is all pretty standard. I'm thinking of the sort of straightforward configurations where the detection inputs and any outputs required to flip polarity of the jack are just not wired up.
This corresponds to codec's JKDET/GPIO1 pin that is used as a default source for jack detection interruption. And better place to describe a board configuration like this is DTS.
Looking at Nuvoton's documentation I see it mentions that jack detection IRQ source can be set to one of the GPIO pins or its combination. In DTS it will look something like
nuvoton,jkdet-source = <N>; // 0 to disable jkdet functionality, 1
for gpio1 (chip default), 2 for gpio2
The chip documentation on jack detection is sparse so I need to clarify all aspects of configuration with Nuvoton engs.
And I believe this jack detection source configuration can be added later and should not block the rest of the driver.
Mark Brown
maintainerQuoted 9 lines · Anatol Pomozov
Quoted 4 lines · Mark Brown
So ACPI based platforms have to deal with providing clocks in some other way, that's something that is abstracted away by the clock API. There are a number of drivers for both board file based and ACPI based systems already in tree which manage to make use of the clock API.
What is the best example of driver that uses clk API in both DT and ACPI friendly way? I will use it as a template for my driver.
Any driver using the clock API should provide a suitable reference. The mechanism used to resolve clocks is completely opaque to the driver using the clock API.
Hi
Sorry for the delay.
Quoted 8 lines · Mark Brown
Quoted 6 lines · Anatol Pomozov
Quoted 4 lines · Mark Brown
So ACPI based platforms have to deal with providing clocks in some other way, that's something that is abstracted away by the clock API. There are a number of drivers for both board file based and ACPI based systems already in tree which manage to make use of the clock API.
Quoted 6 lines
Quoted 2 lines
What is the best example of driver that uses clk API in both DT and ACPI friendly way? I will use it as a template for my driver.
Any driver using the clock API should provide a suitable reference. The mechanism used to resolve clocks is completely opaque to the driver using the clock API.
Okay, I added clk support for MCLK. set_sysclk() callback sets rate for this clock. Platform driver needs to call snd_soc_codec_set_sysclk() to choose codec clock source and set its rate.
Another change - added 10ms delay after enabling charge pump to eliminate pop.