xref: /linux/drivers/usb/gadget/function/u_uac1_legacy.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * u_uac1.h -- interface to USB gadget "ALSA AUDIO" utilities
4  *
5  * Copyright (C) 2008 Bryan Wu <cooloney@kernel.org>
6  * Copyright (C) 2008 Analog Devices, Inc
7  */
8 
9 #ifndef __U_UAC1_LEGACY_H
10 #define __U_UAC1_LEGACY_H
11 
12 #include <linux/device.h>
13 #include <linux/err.h>
14 #include <linux/usb/audio.h>
15 #include <linux/usb/composite.h>
16 
17 #include <sound/core.h>
18 #include <sound/pcm.h>
19 #include <sound/pcm_params.h>
20 
21 #define FILE_PCM_PLAYBACK	"/dev/snd/pcmC0D0p"
22 #define FILE_PCM_CAPTURE	"/dev/snd/pcmC0D0c"
23 #define FILE_CONTROL		"/dev/snd/controlC0"
24 
25 #define UAC1_OUT_EP_MAX_PACKET_SIZE	200
26 #define UAC1_REQ_COUNT			256
27 #define UAC1_AUDIO_BUF_SIZE		48000
28 
29 /*
30  * This represents the USB side of an audio card device, managed by a USB
31  * function which provides control and stream interfaces.
32  */
33 
34 struct gaudio_snd_dev {
35 	struct gaudio			*card;
36 	struct file			*filp;
37 	struct snd_pcm_substream	*substream;
38 	int				access;
39 	int				format;
40 	int				channels;
41 	int				rate;
42 };
43 
44 struct gaudio {
45 	struct usb_function		func;
46 	struct usb_gadget		*gadget;
47 
48 	/* ALSA sound device interfaces */
49 	struct gaudio_snd_dev		control;
50 	struct gaudio_snd_dev		playback;
51 	struct gaudio_snd_dev		capture;
52 
53 	/* TODO */
54 };
55 
56 struct f_uac1_legacy_opts {
57 	struct usb_function_instance	func_inst;
58 	int				req_buf_size;
59 	int				req_count;
60 	int				audio_buf_size;
61 	char				*fn_play;
62 	char				*fn_cap;
63 	char				*fn_cntl;
64 	unsigned			bound:1;
65 	unsigned			fn_play_alloc:1;
66 	unsigned			fn_cap_alloc:1;
67 	unsigned			fn_cntl_alloc:1;
68 	struct mutex			lock;
69 	int				refcnt;
70 };
71 
72 int gaudio_setup(struct gaudio *card);
73 void gaudio_cleanup(struct gaudio *the_card);
74 
75 size_t u_audio_playback(struct gaudio *card, void *buf, size_t count);
76 int u_audio_get_playback_channels(struct gaudio *card);
77 int u_audio_get_playback_rate(struct gaudio *card);
78 
79 #endif /* __U_UAC1_LEGACY_H */
80