Loading...
Note: File does not exist in v3.1.
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * u_audio.h -- interface to USB gadget "ALSA sound card" utilities
4 *
5 * Copyright (C) 2016
6 * Author: Ruslan Bilovol <ruslan.bilovol@gmail.com>
7 */
8
9#ifndef __U_AUDIO_H
10#define __U_AUDIO_H
11
12#include <linux/usb/composite.h>
13
14struct uac_params {
15 /* playback */
16 int p_chmask; /* channel mask */
17 int p_srate; /* rate in Hz */
18 int p_ssize; /* sample size */
19
20 /* capture */
21 int c_chmask; /* channel mask */
22 int c_srate; /* rate in Hz */
23 int c_ssize; /* sample size */
24
25 int req_number; /* number of preallocated requests */
26};
27
28struct g_audio {
29 struct usb_function func;
30 struct usb_gadget *gadget;
31
32 struct usb_ep *in_ep;
33 struct usb_ep *out_ep;
34
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;
39
40 /* The ALSA Sound Card it represents on the USB-Client side */
41 struct snd_uac_chip *uac;
42
43 struct uac_params params;
44};
45
46static inline struct g_audio *func_to_g_audio(struct usb_function *f)
47{
48 return container_of(f, struct g_audio, func);
49}
50
51static inline uint num_channels(uint chanmask)
52{
53 uint num = 0;
54
55 while (chanmask) {
56 num += (chanmask & 1);
57 chanmask >>= 1;
58 }
59
60 return num;
61}
62
63/*
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
68 *
69 * This sets up the single virtual ALSA sound card that may be exported by a
70 * gadget driver using this framework.
71 *
72 * Context: may sleep
73 *
74 * Returns zero on success, or a negative error on failure.
75 */
76int g_audio_setup(struct g_audio *g_audio, const char *pcm_name,
77 const char *card_name);
78void g_audio_cleanup(struct g_audio *g_audio);
79
80int u_audio_start_capture(struct g_audio *g_audio);
81void u_audio_stop_capture(struct g_audio *g_audio);
82int u_audio_start_playback(struct g_audio *g_audio);
83void u_audio_stop_playback(struct g_audio *g_audio);
84
85#endif /* __U_AUDIO_H */