ASoC: tegra: Support WM8994 by machine driver
Subsystems (4)
v2 cover ASoC: tegra: Support WM8994 by machine driver
Add Wolfson Microelectronics WM8994 codec support to the Tegra ASoC machine driver. The WM8994 codec is found on devices like LG Optimus 2X (P990/star) and Samsung Captivate Glide (SGH-i927).
---
Changes in v2:
- added missing dapm widgets
- added owner into snd_soc_tegra_wm8994
- fix jack detection disable and place it behind check
- change copyright comment style to C++
---
Svyatoslav Ryhel (2):
ASoC: dt-bindings: nvidia,tegra-audio: Document WM8994 CODEC
ASoC: tegra: Support WM8994 by machine driver
.../sound/nvidia,tegra-audio-wm8994.yaml | 110 +++++++++++ sound/soc/tegra/Kconfig | 10 + sound/soc/tegra/Makefile | 2 + sound/soc/tegra/tegra_asoc_machine.c | 2 + sound/soc/tegra/tegra_wm8994.c | 175 ++++++++++++++++++ 5 files changed, 299 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra-audio-wm8994.yaml create mode 100644 sound/soc/tegra/tegra_wm8994.c
Signature · 1 line
2.53.0
PATCH v2 1/2 ASoC: dt-bindings: nvidia,tegra-audio: Document WM8994 CODEC
Add dt-binding for WM8994 CODEC.
--- .../sound/nvidia,tegra-audio-wm8994.yaml | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra-audio-wm8994.yaml
Documentation/devicetree/bindings/sound/nvidia,tegra-audio-wm8994.yaml new file +110 -0
@@ -0,0 +1,110 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/nvidia,tegra-audio-wm8994.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NVIDIA Tegra audio complex with WM8994 CODEC + +maintainers: + - Svyatoslav Ryhel <[email protected]> + +allOf: + - $ref: nvidia,tegra-audio-common.yaml# + +properties: + compatible: + items: + - pattern: '^[a-z0-9]+,tegra-audio-wm8994(-[a-z0-9]+)+$' + - const: nvidia,tegra-audio-wm8994 + + nvidia,audio-routing: + $ref: /schemas/types.yaml#/definitions/non-unique-string-array + description: | + A list of the connections between audio components. + Each entry is a pair of strings, the first being the connection's sink, + the second being the connection's source. Valid names for sources and + sinks are the pins (documented in the binding document), + and the jacks on the board. + minItems: 2 + items: + enum: + # Board Connectors + - Headphone Jack + - Int Spk + - Earpiece + - Line Out + - Mic Jack + - Int Mic + - Internal Mic 1 + - Internal Mic 2 + - FM Radio + + # CODEC Pins + - SPKOUTLP + - SPKOUTLN + - SPKOUTRP + - SPKOUTRN + - HPOUT1L + - HPOUT1R + - HPOUT2P + - HPOUT2N + - LINEOUT1P + - LINEOUT1N + - LINEOUT2P + - LINEOUT2N + - IN1LN + - IN1LP + - IN2LN + - IN2LP:VXRN + - IN1RN + - IN1RP + - IN2RN + - IN2RP:VXRP + - DMIC1DAT + - DMIC2DAT + - MICBIAS1 + - MICBIAS2 + +required: + - nvidia,i2s-controller + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/clock/tegra20-car.h> + #include <dt-bindings/gpio/gpio.h> + + sound { + compatible = "lg,tegra-audio-wm8994-star", + "nvidia,tegra-audio-wm8994"; + nvidia,model = "LG Optimus 2X WM8994"; + + nvidia,audio-routing = + "Headphone Jack", "HPOUT1L", + "Headphone Jack", "HPOUT1R", + "Int Spk", "SPKOUTLN", + "Int Spk", "SPKOUTLP", + "Earpiece", "HPOUT2N", + "Earpiece", "HPOUT2P", + "IN2RN", "MICBIAS2", + "IN2RN", "Mic Jack", + "IN1LN", "MICBIAS1", + "IN1LN", "Internal Mic 1", + "IN1RN", "MICBIAS1", + "IN1RN", "Internal Mic 2"; + + nvidia,i2s-controller = <&tegra_i2s1>; + nvidia,audio-codec = <&wm8994>; + + nvidia,hp-det-gpios = <&gpio 51 GPIO_ACTIVE_HIGH>; + nvidia,mic-det-gpios = <&gpio 27 GPIO_ACTIVE_HIGH>; + nvidia,ext-mic-en-gpios = <&gpio 57 GPIO_ACTIVE_HIGH>; + nvidia,coupled-mic-hp-det; + + clocks = <&tegra_car TEGRA20_CLK_PLL_A>, + <&tegra_car TEGRA20_CLK_PLL_A_OUT0>, + <&tegra_car TEGRA20_CLK_CDEV1>; + clock-names = "pll_a", "pll_a_out0", "mclk"; + };
Signature · 1 line
2.53.0
PATCH v2 2/2 ASoC: tegra: Support WM8994 by machine driver
In reply to Svyatoslav RyhelAdd Wolfson Microelectronics WM8994 codec support to the Tegra ASoC machine driver. The WM8994 codec is found on devices like LG Optimus 2X (P990/star) and Samsung Captivate Glide (SGH-i927).
--- sound/soc/tegra/Kconfig | 10 ++ sound/soc/tegra/Makefile | 2 + sound/soc/tegra/tegra_asoc_machine.c | 2 + sound/soc/tegra/tegra_wm8994.c | 175 +++++++++++++++++++++++++++ 4 files changed, 189 insertions(+) create mode 100644 sound/soc/tegra/tegra_wm8994.c
sound/soc/tegra/Kconfig +10 -0
@@ -239,6 +239,16 @@ config SND_SOC_TEGRA_WM8962 boards using the WM8962 codec. Currently, the supported boards are Microsoft Surface RT. +config SND_SOC_TEGRA_WM8994 + tristate "SoC Audio support for Tegra boards using a WM8994 codec" + depends on I2C && GPIOLIB && MFD_WM8994 + select SND_SOC_TEGRA_MACHINE_DRV + select SND_SOC_WM8994 + help + Say Y or M here if you want to add support for SoC audio on Tegra + boards using the WM8994 codec. Currently, the supported boards are + LG Optimus X2 P990. + config SND_SOC_TEGRA_WM9712 tristate "SoC Audio support for Tegra boards using a WM9712 codec" depends on GPIOLIB
sound/soc/tegra/Makefile +2 -0
@@ -43,10 +43,12 @@ obj-$(CONFIG_SND_SOC_TEGRA210_OPE) += snd-soc-tegra210-ope.o # Tegra machine Support snd-soc-tegra-wm8903-y := tegra_wm8903.o snd-soc-tegra-wm8962-y := tegra_wm8962.o +snd-soc-tegra-wm8994-y := tegra_wm8994.o snd-soc-tegra-machine-y := tegra_asoc_machine.o snd-soc-tegra-audio-graph-card-y := tegra_audio_graph_card.o obj-$(CONFIG_SND_SOC_TEGRA_WM8903) += snd-soc-tegra-wm8903.o obj-$(CONFIG_SND_SOC_TEGRA_WM8962) += snd-soc-tegra-wm8962.o +obj-$(CONFIG_SND_SOC_TEGRA_WM8994) += snd-soc-tegra-wm8994.o obj-$(CONFIG_SND_SOC_TEGRA_MACHINE_DRV) += snd-soc-tegra-machine.o obj-$(CONFIG_SND_SOC_TEGRA_AUDIO_GRAPH_CARD) += snd-soc-tegra-audio-graph-card.o
sound/soc/tegra/tegra_asoc_machine.c +2 -0
@@ -122,6 +122,8 @@ static const struct snd_soc_dapm_widget tegra_machine_dapm_widgets[] = {SND_SOC_DAPM_LINE ("Line In Jack" ,NULL ),SND_SOC_DAPM_LINE ("Line In" ,NULL ),SND_SOC_DAPM_LINE ("LineIn" ,NULL ), +SND_SOC_DAPM_LINE ("Line Out" ,NULL ), + SND_SOC_DAPM_INPUT("FM Radio"), }; static const struct snd_kcontrol_new tegra_machine_controls[] = {
sound/soc/tegra/tegra_wm8994.c new file +175 -0
175 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] sound/soc: NULL pointer dereference in tegra_wm8994_remove() during unload - [Medium] ASoC: tegra…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] sound/soc: NULL pointer dereference in tegra_wm8994_remove() during unload
- [Medium] ASoC: tegra: dropped headphone and button events due to SND_JACK_MICROPHONE --
commit c25c1a719a0690a201ec3decc5bc7bc2cec57601
Author: Svyatoslav Ryhel <[email protected]>
ASoC: tegra: Support WM8994 by machine driver
Add Wolfson Microelectronics WM8994 codec support to the Tegra ASoC machine driver. The WM8994 codec is found on devices like LG Optimus 2X (P990/star) and Samsung Captivate Glide (SGH-i927).
Quoted 6 lines
sound/soc/tegra/tegra_wm8994.c new file +0
-0@@ -0,0 +1,175 @@
[ ... ]
Quoted 9 lines
sound/soc/tegra/tegra_wm8994.c new file +9
-0+static int tegra_wm8994_init (struct snd_soc_pcm_runtime *rtd) +{ +struct tegra_machine *machine =snd_soc_card_get_drvdata (rtd->card); +int err; + + err =tegra_asoc_machine_init (rtd); +if (err) +return err; +
sound/soc/tegra/tegra_wm8994.c line 96
Quoted 10 lines
sound/soc/tegra/tegra_wm8994.c new file +10
-0+if (!machine->gpiod_mic_det && machine->asoc->add_mic_jack) { +struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (rtd,0 ); +struct snd_soc_component *component = codec_dai->component; + + err =snd_soc_card_jack_new_pins (rtd->card,"Mic Jack" , +SND_JACK_MICROPHONE , + machine->mic_jack, + tegra_wm8994_mic_jack_pins, +ARRAY_SIZE (tegra_wm8994_mic_jack_pins)); +if (err) {
[Severity: Medium]
Will this silently drop headphone and button events from the codec?
The ALSA jack is explicitly initialized with only the SND_JACK_MICROPHONE capability. However, the WM8994 codec handles full headset detection and tries to report events as SND_JACK_HEADSET | SND_JACK_BTN_0.
Because the ALSA jack type is restricted to SND_JACK_MICROPHONE, the ALSA core filters out the SND_JACK_HEADPHONE and button bits in snd_jack_report(), preventing them from reaching the input layer. Additionally, since the DAPM pin configuration only maps the microphone, automatic DAPM routing will fail to turn on the Headphone Jack widget upon headset insertion.
Quoted 6 lines
sound/soc/tegra/tegra_wm8994.c new file +6
-0+dev_err (rtd->dev,"Mic Jack creation failed: %d\n" , err); +return err; + } + +wm8994_mic_detect (component, machine->mic_jack,1 ); + }
sound/soc/tegra/tegra_wm8994.c line 112
Quoted 10 lines
sound/soc/tegra/tegra_wm8994.c new file +10
-0+ +return 0 ; +} + +static int tegra_wm8994_remove (struct snd_soc_card *card) +{ +struct snd_soc_dai_link *link = &card->dai_link[0 ]; +struct snd_soc_pcm_runtime *rtd =snd_soc_get_pcm_runtime (card, link); +struct tegra_machine *machine =snd_soc_card_get_drvdata (rtd->card); +struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (rtd,0 );
[Severity: High]
Does this code trigger a NULL pointer dereference during module unload?
When the driver is unbound, devm_snd_soc_register_card() invokes snd_soc_unregister_card(). This calls soc_cleanup_card_resources(), which explicitly deletes and frees all PCM runtimes (rtd) from the rtd_list via snd_soc_remove_pcm_runtime() before calling snd_soc_card_remove(card).
When snd_soc_card_remove() finally invokes this tegra_wm8994_remove() callback, the call to snd_soc_get_pcm_runtime() will return NULL because the rtd_list is empty. The code then unconditionally dereferences this NULL pointer here in rtd->card and the snd_soc_rtd_to_codec(rtd, 0) macro.
Quoted 7 lines
sound/soc/tegra/tegra_wm8994.c new file +7
-0+struct snd_soc_component *component = codec_dai->component; + +if (!machine->gpiod_mic_det && machine->asoc->add_mic_jack) +wm8994_mic_detect (component,NULL ,1 ); + +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Mark Brown
maintainerQuoted 5 lines · Svyatoslav Ryhel
ASoC: tegra: Support WM8994 by machine driver
Add Wolfson Microelectronics WM8994 codec support to the Tegra ASoC machine driver. The WM8994 codec is found on devices like LG Optimus 2X (P990/star) and Samsung Captivate Glide (SGH-i927).
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.4
Thanks!
[1/2] ASoC: dt-bindings: nvidia,tegra-audio: Document WM8994 CODEC
https://git.kernel.org/broonie/sound/c/5b4d158b309a [2/2] ASoC: tegra: Support WM8994 by machine driver https://git.kernel.org/broonie/sound/c/e38398539f79
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark