1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * u_audio.h -- interface to USB gadget "ALSA sound card" utilities
6 * Author: Ruslan Bilovol <ruslan.bilovol@gmail.com>
12 #include <linux/usb/composite.h>
16 int p_chmask
; /* channel mask */
17 int p_srate
; /* rate in Hz */
18 int p_ssize
; /* sample size */
21 int c_chmask
; /* channel mask */
22 int c_srate
; /* rate in Hz */
23 int c_ssize
; /* sample size */
25 int req_number
; /* number of preallocated requests */
29 struct usb_function func
;
30 struct usb_gadget
*gadget
;
33 struct usb_ep
*out_ep
;
35 /* Max packet size for all in_ep possible speeds */
36 unsigned int in_ep_maxpsize
;
37 /* Max packet size for all out_ep possible speeds */
38 unsigned int out_ep_maxpsize
;
40 /* The ALSA Sound Card it represents on the USB-Client side */
41 struct snd_uac_chip
*uac
;
43 struct uac_params params
;
46 static inline struct g_audio
*func_to_g_audio(struct usb_function
*f
)
48 return container_of(f
, struct g_audio
, func
);
51 static inline uint
num_channels(uint chanmask
)
56 num
+= (chanmask
& 1);
64 * g_audio_setup - initialize one virtual ALSA sound card
65 * @g_audio: struct with filled params, in_ep_maxpsize, out_ep_maxpsize
66 * @pcm_name: the id string for a PCM instance of this sound card
67 * @card_name: name of this soundcard
69 * This sets up the single virtual ALSA sound card that may be exported by a
70 * gadget driver using this framework.
74 * Returns zero on success, or a negative error on failure.
76 int g_audio_setup(struct g_audio
*g_audio
, const char *pcm_name
,
77 const char *card_name
);
78 void g_audio_cleanup(struct g_audio
*g_audio
);
80 int u_audio_start_capture(struct g_audio
*g_audio
);
81 void u_audio_stop_capture(struct g_audio
*g_audio
);
82 int u_audio_start_playback(struct g_audio
*g_audio
);
83 void u_audio_stop_playback(struct g_audio
*g_audio
);
85 #endif /* __U_AUDIO_H */