treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / usb / gadget / function / u_audio.h
blob81d3d4ed6dfb15b4f589d9ba9070f587b33addb2
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * u_audio.h -- interface to USB gadget "ALSA sound card" utilities
5 * Copyright (C) 2016
6 * Author: Ruslan Bilovol <ruslan.bilovol@gmail.com>
7 */
9 #ifndef __U_AUDIO_H
10 #define __U_AUDIO_H
12 #include <linux/usb/composite.h>
14 struct uac_params {
15 /* playback */
16 int p_chmask; /* channel mask */
17 int p_srate; /* rate in Hz */
18 int p_ssize; /* sample size */
20 /* capture */
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 */
28 struct g_audio {
29 struct usb_function func;
30 struct usb_gadget *gadget;
32 struct usb_ep *in_ep;
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)
53 uint num = 0;
55 while (chanmask) {
56 num += (chanmask & 1);
57 chanmask >>= 1;
60 return num;
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.
72 * Context: may sleep
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 */