Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: qcom: qdsp6: Add headphone jack for offload connection status

The headphone jack framework has a well defined infrastructure for
notifying userspace entities through input devices. Expose a jack device
that carries information about if an offload capable device is connected.
Applications can further identify specific offloading information through
other SND kcontrols.

Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
Acked-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20250409194804.3773260-26-quic_wcheng@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Wesley Cheng and committed by
Greg Kroah-Hartman
1b8d0d87 72b0b8b2

+156 -1
+4
sound/soc/qcom/Kconfig
··· 118 118 tristate 119 119 select SND_SOC_QDSP6_PRM_LPASS_CLOCKS 120 120 121 + config SND_SOC_QCOM_OFFLOAD_UTILS 122 + tristate 123 + 121 124 config SND_SOC_QDSP6_USB 122 125 tristate "SoC ALSA USB offloading backing for QDSP6" 123 126 depends on SND_SOC_USB 124 127 select AUXILIARY_BUS 128 + select SND_SOC_QCOM_OFFLOAD_UTILS 125 129 126 130 help 127 131 Adds support for USB offloading for QDSP6 ASoC
+2
sound/soc/qcom/Makefile
··· 30 30 snd-soc-qcom-common-y := common.o 31 31 snd-soc-qcom-sdw-y := sdw.o 32 32 snd-soc-x1e80100-y := x1e80100.o 33 + snd-soc-qcom-offload-utils-objs := usb_offload_utils.o 33 34 34 35 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o 35 36 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o ··· 43 42 obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o 44 43 obj-$(CONFIG_SND_SOC_QCOM_SDW) += snd-soc-qcom-sdw.o 45 44 obj-$(CONFIG_SND_SOC_X1E80100) += snd-soc-x1e80100.o 45 + obj-$(CONFIG_SND_SOC_QCOM_OFFLOAD_UTILS) += snd-soc-qcom-offload-utils.o 46 46 47 47 #DSP lib 48 48 obj-$(CONFIG_SND_SOC_QDSP6) += qdsp6/
+41
sound/soc/qcom/qdsp6/q6usb.c
··· 15 15 #include <linux/slab.h> 16 16 17 17 #include <sound/asound.h> 18 + #include <sound/jack.h> 18 19 #include <sound/pcm.h> 19 20 #include <sound/pcm_params.h> 20 21 #include <sound/q6usboffload.h> ··· 33 32 struct auxiliary_device uauxdev; 34 33 struct q6afe_usb_cfg usb_cfg; 35 34 struct snd_soc_usb *usb; 35 + struct snd_soc_jack *hs_jack; 36 36 struct q6usb_offload priv; 37 37 38 38 /* Protects against operations between SOC USB and ASoC */ ··· 146 144 147 145 mutex_lock(&data->mutex); 148 146 if (connected) { 147 + if (data->hs_jack) 148 + snd_jack_report(data->hs_jack->jack, SND_JACK_USB); 149 + 149 150 /* Selects the latest USB headset plugged in for offloading */ 150 151 list_add_tail(&sdev->list, &data->devices); 151 152 } else { 152 153 list_del(&sdev->list); 154 + 155 + if (data->hs_jack) 156 + snd_jack_report(data->hs_jack->jack, 0); 153 157 } 158 + mutex_unlock(&data->mutex); 159 + 160 + return 0; 161 + } 162 + 163 + static void q6usb_component_disable_jack(struct q6usb_port_data *data) 164 + { 165 + /* Offload jack has already been disabled */ 166 + if (!data->hs_jack) 167 + return; 168 + 169 + snd_jack_report(data->hs_jack->jack, 0); 170 + data->hs_jack = NULL; 171 + } 172 + 173 + static void q6usb_component_enable_jack(struct q6usb_port_data *data, 174 + struct snd_soc_jack *jack) 175 + { 176 + snd_jack_report(jack->jack, !list_empty(&data->devices) ? SND_JACK_USB : 0); 177 + data->hs_jack = jack; 178 + } 179 + 180 + static int q6usb_component_set_jack(struct snd_soc_component *component, 181 + struct snd_soc_jack *jack, void *priv) 182 + { 183 + struct q6usb_port_data *data = dev_get_drvdata(component->dev); 184 + 185 + mutex_lock(&data->mutex); 186 + if (jack) 187 + q6usb_component_enable_jack(data, jack); 188 + else 189 + q6usb_component_disable_jack(data); 154 190 mutex_unlock(&data->mutex); 155 191 156 192 return 0; ··· 251 211 252 212 static const struct snd_soc_component_driver q6usb_dai_component = { 253 213 .probe = q6usb_component_probe, 214 + .set_jack = q6usb_component_set_jack, 254 215 .remove = q6usb_component_remove, 255 216 .name = "q6usb-dai-component", 256 217 .dapm_widgets = q6usb_dai_widgets,
+23 -1
sound/soc/qcom/sm8250.c
··· 13 13 #include <linux/input-event-codes.h> 14 14 #include "qdsp6/q6afe.h" 15 15 #include "common.h" 16 + #include "usb_offload_utils.h" 16 17 #include "sdw.h" 17 18 18 19 #define DRIVER_NAME "sm8250" ··· 24 23 struct snd_soc_card *card; 25 24 struct sdw_stream_runtime *sruntime[AFE_PORT_MAX]; 26 25 struct snd_soc_jack jack; 26 + struct snd_soc_jack usb_offload_jack; 27 + bool usb_offload_jack_setup; 27 28 bool jack_setup; 28 29 }; 29 30 30 31 static int sm8250_snd_init(struct snd_soc_pcm_runtime *rtd) 31 32 { 32 33 struct sm8250_snd_data *data = snd_soc_card_get_drvdata(rtd->card); 34 + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); 35 + int ret; 33 36 34 - return qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup); 37 + if (cpu_dai->id == USB_RX) 38 + ret = qcom_snd_usb_offload_jack_setup(rtd, &data->usb_offload_jack, 39 + &data->usb_offload_jack_setup); 40 + else 41 + ret = qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup); 42 + return ret; 43 + } 44 + 45 + static void sm8250_snd_exit(struct snd_soc_pcm_runtime *rtd) 46 + { 47 + struct sm8250_snd_data *data = snd_soc_card_get_drvdata(rtd->card); 48 + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); 49 + 50 + if (cpu_dai->id == USB_RX) 51 + qcom_snd_usb_offload_jack_remove(rtd, 52 + &data->usb_offload_jack_setup); 53 + 35 54 } 36 55 37 56 static int sm8250_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, ··· 169 148 for_each_card_prelinks(card, i, link) { 170 149 if (link->no_pcm == 1) { 171 150 link->init = sm8250_snd_init; 151 + link->exit = sm8250_snd_exit; 172 152 link->be_hw_params_fixup = sm8250_be_hw_params_fixup; 173 153 link->ops = &sm8250_be_ops; 174 154 }
+56
sound/soc/qcom/usb_offload_utils.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (c) 2022-2025 Qualcomm Innovation Center, Inc. All rights reserved. 4 + */ 5 + #include <dt-bindings/sound/qcom,q6afe.h> 6 + #include <linux/module.h> 7 + #include <sound/jack.h> 8 + #include <sound/soc-usb.h> 9 + 10 + #include "usb_offload_utils.h" 11 + 12 + int qcom_snd_usb_offload_jack_setup(struct snd_soc_pcm_runtime *rtd, 13 + struct snd_soc_jack *jack, bool *jack_setup) 14 + { 15 + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); 16 + struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); 17 + int ret = 0; 18 + 19 + if (cpu_dai->id != USB_RX) 20 + return -EINVAL; 21 + 22 + if (!*jack_setup) { 23 + ret = snd_soc_usb_setup_offload_jack(codec_dai->component, jack); 24 + if (ret) 25 + return ret; 26 + } 27 + 28 + *jack_setup = true; 29 + 30 + return 0; 31 + } 32 + EXPORT_SYMBOL_GPL(qcom_snd_usb_offload_jack_setup); 33 + 34 + int qcom_snd_usb_offload_jack_remove(struct snd_soc_pcm_runtime *rtd, 35 + bool *jack_setup) 36 + { 37 + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); 38 + struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); 39 + int ret = 0; 40 + 41 + if (cpu_dai->id != USB_RX) 42 + return -EINVAL; 43 + 44 + if (*jack_setup) { 45 + ret = snd_soc_component_set_jack(codec_dai->component, NULL, NULL); 46 + if (ret) 47 + return ret; 48 + } 49 + 50 + *jack_setup = false; 51 + 52 + return 0; 53 + } 54 + EXPORT_SYMBOL_GPL(qcom_snd_usb_offload_jack_remove); 55 + MODULE_DESCRIPTION("ASoC Q6 USB offload controls"); 56 + MODULE_LICENSE("GPL");
+30
sound/soc/qcom/usb_offload_utils.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 2 + * 3 + * Copyright (c) 2022-2025 Qualcomm Innovation Center, Inc. All rights reserved. 4 + */ 5 + #ifndef __QCOM_SND_USB_OFFLOAD_UTILS_H__ 6 + #define __QCOM_SND_USB_OFFLOAD_UTILS_H__ 7 + 8 + #include <sound/soc.h> 9 + 10 + #if IS_ENABLED(CONFIG_SND_SOC_QCOM_OFFLOAD_UTILS) 11 + int qcom_snd_usb_offload_jack_setup(struct snd_soc_pcm_runtime *rtd, 12 + struct snd_soc_jack *jack, bool *jack_setup); 13 + 14 + int qcom_snd_usb_offload_jack_remove(struct snd_soc_pcm_runtime *rtd, 15 + bool *jack_setup); 16 + #else 17 + static inline int qcom_snd_usb_offload_jack_setup(struct snd_soc_pcm_runtime *rtd, 18 + struct snd_soc_jack *jack, 19 + bool *jack_setup) 20 + { 21 + return -ENODEV; 22 + } 23 + 24 + static inline int qcom_snd_usb_offload_jack_remove(struct snd_soc_pcm_runtime *rtd, 25 + bool *jack_setup) 26 + { 27 + return -ENODEV; 28 + } 29 + #endif /* IS_ENABLED(CONFIG_SND_SOC_QCOM_OFFLOAD_UTILS) */ 30 + #endif /* __QCOM_SND_USB_OFFLOAD_UTILS_H__ */