1 /* SPDX-License-Identifier: GPL-2.0
2 *
3 * Copyright (c) 2022-2025 Qualcomm Innovation Center, Inc. All rights reserved.
4 */
5
6 #ifndef __LINUX_SND_SOC_USB_H
7 #define __LINUX_SND_SOC_USB_H
8
9 #include <sound/soc.h>
10
11 enum snd_soc_usb_kctl {
12 SND_SOC_USB_KCTL_CARD_ROUTE,
13 SND_SOC_USB_KCTL_PCM_ROUTE,
14 };
15
16 /**
17 * struct snd_soc_usb_device - SoC USB representation of a USB sound device
18 * @card_idx: sound card index associated with USB device
19 * @chip_idx: USB sound chip array index
20 * @cpcm_idx: capture PCM index array associated with USB device
21 * @ppcm_idx: playback PCM index array associated with USB device
22 * @num_capture: number of capture streams
23 * @num_playback: number of playback streams
24 * @list: list head for SoC USB devices
25 **/
26 struct snd_soc_usb_device {
27 int card_idx;
28 int chip_idx;
29
30 /* PCM index arrays */
31 unsigned int *cpcm_idx; /* TODO: capture path is not tested yet */
32 unsigned int *ppcm_idx;
33 int num_capture; /* TODO: capture path is not tested yet */
34 int num_playback;
35
36 struct list_head list;
37 };
38
39 /**
40 * struct snd_soc_usb - representation of a SoC USB backend entity
41 * @list: list head for SND SOC struct list
42 * @component: reference to ASoC component
43 * @connection_status_cb: callback to notify connection events
44 * @update_offload_route_info: callback to fetch mapped ASoC card and pcm
45 * device pair. This is unrelated to the concept
46 * of DAPM route. The "route" argument carries
47 * an array used for a kcontrol output for either
48 * the card or pcm index. "path" determines the
49 * which entry to look for. (ie mapped card or pcm)
50 * @priv_data: driver data
51 **/
52 struct snd_soc_usb {
53 struct list_head list;
54 struct snd_soc_component *component;
55 int (*connection_status_cb)(struct snd_soc_usb *usb,
56 struct snd_soc_usb_device *sdev,
57 bool connected);
58 int (*update_offload_route_info)(struct snd_soc_component *component,
59 int card, int pcm, int direction,
60 enum snd_soc_usb_kctl path,
61 long *route);
62 void *priv_data;
63 };
64
65 #if IS_ENABLED(CONFIG_SND_SOC_USB)
66 int snd_soc_usb_find_supported_format(int card_idx,
67 struct snd_pcm_hw_params *params,
68 int direction);
69
70 int snd_soc_usb_connect(struct device *usbdev, struct snd_soc_usb_device *sdev);
71 int snd_soc_usb_disconnect(struct device *usbdev, struct snd_soc_usb_device *sdev);
72 void *snd_soc_usb_find_priv_data(struct device *usbdev);
73
74 int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component,
75 struct snd_soc_jack *jack);
76 int snd_soc_usb_update_offload_route(struct device *dev, int card, int pcm,
77 int direction, enum snd_soc_usb_kctl path,
78 long *route);
79
80 struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *component,
81 void *data);
82 void snd_soc_usb_free_port(struct snd_soc_usb *usb);
83 void snd_soc_usb_add_port(struct snd_soc_usb *usb);
84 void snd_soc_usb_remove_port(struct snd_soc_usb *usb);
85 #else
86 static inline int
snd_soc_usb_find_supported_format(int card_idx,struct snd_pcm_hw_params * params,int direction)87 snd_soc_usb_find_supported_format(int card_idx, struct snd_pcm_hw_params *params,
88 int direction)
89 {
90 return -EINVAL;
91 }
92
snd_soc_usb_connect(struct device * usbdev,struct snd_soc_usb_device * sdev)93 static inline int snd_soc_usb_connect(struct device *usbdev,
94 struct snd_soc_usb_device *sdev)
95 {
96 return -ENODEV;
97 }
98
snd_soc_usb_disconnect(struct device * usbdev,struct snd_soc_usb_device * sdev)99 static inline int snd_soc_usb_disconnect(struct device *usbdev,
100 struct snd_soc_usb_device *sdev)
101 {
102 return -EINVAL;
103 }
104
snd_soc_usb_find_priv_data(struct device * usbdev)105 static inline void *snd_soc_usb_find_priv_data(struct device *usbdev)
106 {
107 return NULL;
108 }
109
snd_soc_usb_setup_offload_jack(struct snd_soc_component * component,struct snd_soc_jack * jack)110 static inline int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component,
111 struct snd_soc_jack *jack)
112 {
113 return 0;
114 }
115
snd_soc_usb_update_offload_route(struct device * dev,int card,int pcm,int direction,enum snd_soc_usb_kctl path,long * route)116 static int snd_soc_usb_update_offload_route(struct device *dev, int card, int pcm,
117 int direction, enum snd_soc_usb_kctl path,
118 long *route)
119 {
120 return -ENODEV;
121 }
122
123 static inline struct snd_soc_usb *
snd_soc_usb_allocate_port(struct snd_soc_component * component,void * data)124 snd_soc_usb_allocate_port(struct snd_soc_component *component, void *data)
125 {
126 return ERR_PTR(-ENOMEM);
127 }
128
snd_soc_usb_free_port(struct snd_soc_usb * usb)129 static inline void snd_soc_usb_free_port(struct snd_soc_usb *usb)
130 { }
131
snd_soc_usb_add_port(struct snd_soc_usb * usb)132 static inline void snd_soc_usb_add_port(struct snd_soc_usb *usb)
133 { }
134
snd_soc_usb_remove_port(struct snd_soc_usb * usb)135 static inline void snd_soc_usb_remove_port(struct snd_soc_usb *usb)
136 { }
137 #endif /* IS_ENABLED(CONFIG_SND_SOC_USB) */
138 #endif /*__LINUX_SND_SOC_USB_H */
139