xref: /linux/sound/usb/usx2y/usbusx2y.h (revision 666f12ae9f504625e5a93581d8fbcba3dd60c294)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef USBUSX2Y_H
3 #define USBUSX2Y_H
4 #include "../usbaudio.h"
5 #include "../midi.h"
6 #include "usbus428ctldefs.h"
7 
8 #define USX2Y_IN04_SIZE	sizeof(struct us428_ctls)
9 
10 #define NRURBS	        2
11 
12 /* Default value used for nr of packs per urb.
13  * 1 to 4 have been tested ok on uhci.
14  * To use 3 on ohci, you'd need a patch:
15  * look for "0000425-linux-2.6.9-rc4-mm1_ohci-hcd.patch.gz" on
16  * "https://bugtrack.alsa-project.org/alsa-bug/bug_view_page.php?bug_id=0000425"
17  *
18  * 1, 2 and 4 work out of the box on ohci, if I recall correctly.
19  * Bigger is safer operation, smaller gives lower latencies.
20  */
21 #define USX2Y_NRPACKS 4
22 
23 #define USX2Y_NRPACKS_MAX 1024
24 
25 /* If your system works ok with this module's parameter
26  * nrpacks set to 1, you might as well comment
27  * this define out, and thereby produce smaller, faster code.
28  * You'd also set USX2Y_NRPACKS to 1 then.
29  */
30 #define USX2Y_NRPACKS_VARIABLE 1
31 
32 #ifdef USX2Y_NRPACKS_VARIABLE
33 extern int nrpacks;
34 #define nr_of_packs() nrpacks
35 #else
36 #define nr_of_packs() USX2Y_NRPACKS
37 #endif
38 
39 #define URBS_ASYNC_SEQ 10
40 #define URB_DATA_LEN_ASYNC_SEQ 32
41 struct snd_usx2y_async_seq {
42 	struct urb	*urb[URBS_ASYNC_SEQ];
43 	char		*buffer;
44 };
45 
46 struct snd_usx2y_urb_seq {
47 	int	submitted;
48 	int	len;
49 	struct urb	*urb[] __counted_by(len);
50 };
51 
52 #include "usx2yhwdeppcm.h"
53 
54 struct usx2ydev {
55 	struct usb_device	*dev;
56 	int			card_index;
57 	int			stride;
58 	struct urb		*in04_urb;
59 	void			*in04_buf;
60 	char			in04_last[USX2Y_IN04_SIZE];
61 	unsigned int		in04_int_calls;
62 	struct snd_usx2y_urb_seq	*us04;
63 	wait_queue_head_t	in04_wait_queue;
64 	struct snd_usx2y_async_seq	as04;
65 	unsigned int		rate,
66 				format;
67 	int			chip_status;
68 	struct mutex		pcm_mutex;
69 	struct us428ctls_sharedmem	*us428ctls_sharedmem;
70 	int			wait_iso_frame;
71 	wait_queue_head_t	us428ctls_wait_queue_head;
72 	struct snd_usx2y_hwdep_pcm_shm	*hwdep_pcm_shm;
73 	struct snd_usx2y_substream	*subs[4];
74 	struct snd_usx2y_substream	* volatile  prepare_subs;
75 	wait_queue_head_t	prepare_wait_queue;
76 	struct list_head	midi_list;
77 	int			pcm_devs;
78 };
79 
80 
81 struct snd_usx2y_substream {
82 	struct usx2ydev	*usx2y;
83 	struct snd_pcm_substream *pcm_substream;
84 
85 	int			endpoint;
86 	unsigned int		maxpacksize;		/* max packet size in bytes */
87 
88 	atomic_t		state;
89 #define STATE_STOPPED	0
90 #define STATE_STARTING1 1
91 #define STATE_STARTING2 2
92 #define STATE_STARTING3 3
93 #define STATE_PREPARED	4
94 #define STATE_PRERUNNING  6
95 #define STATE_RUNNING	8
96 
97 	int			hwptr;			/* free frame position in the buffer (only for playback) */
98 	int			hwptr_done;		/* processed frame position in the buffer */
99 	int			transfer_done;		/* processed frames since last period update */
100 
101 	struct urb		*urb[NRURBS];	/* data urb table */
102 	struct urb		*completed_urb;
103 	char			*tmpbuf;			/* temporary buffer for playback */
104 };
105 
106 
107 #define usx2y(c) ((struct usx2ydev *)(c)->private_data)
108 
109 int usx2y_audio_create(struct snd_card *card);
110 
111 int usx2y_async_seq04_init(struct usx2ydev *usx2y);
112 int usx2y_in04_init(struct usx2ydev *usx2y);
113 
114 #define NAME_ALLCAPS "US-X2Y"
115 
116 #endif
117