]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - sound/usb/line6/driver.h
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[mirror_ubuntu-zesty-kernel.git] / sound / usb / line6 / driver.h
1 /*
2 * Line 6 Linux USB driver
3 *
4 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
10 */
11
12 #ifndef DRIVER_H
13 #define DRIVER_H
14
15 #include <linux/usb.h>
16 #include <linux/mutex.h>
17 #include <linux/kfifo.h>
18 #include <sound/core.h>
19
20 #include "midi.h"
21
22 /* USB 1.1 speed configuration */
23 #define USB_LOW_INTERVALS_PER_SECOND 1000
24 #define USB_LOW_ISO_BUFFERS 2
25
26 /* USB 2.0+ speed configuration */
27 #define USB_HIGH_INTERVALS_PER_SECOND 8000
28 #define USB_HIGH_ISO_BUFFERS 16
29
30 /* Fallback USB interval and max packet size values */
31 #define LINE6_FALLBACK_INTERVAL 10
32 #define LINE6_FALLBACK_MAXPACKETSIZE 16
33
34 #define LINE6_TIMEOUT 1
35 #define LINE6_BUFSIZE_LISTEN 64
36 #define LINE6_MIDI_MESSAGE_MAXLEN 256
37
38 #define LINE6_RAW_MESSAGES_MAXCOUNT_ORDER 7
39 /* 4k packets are common, BUFSIZE * MAXCOUNT should be bigger... */
40 #define LINE6_RAW_MESSAGES_MAXCOUNT (1 << LINE6_RAW_MESSAGES_MAXCOUNT_ORDER)
41
42
43 #if LINE6_BUFSIZE_LISTEN > 65535
44 #error "Use dynamic fifo instead"
45 #endif
46
47 /*
48 Line 6 MIDI control commands
49 */
50 #define LINE6_PARAM_CHANGE 0xb0
51 #define LINE6_PROGRAM_CHANGE 0xc0
52 #define LINE6_SYSEX_BEGIN 0xf0
53 #define LINE6_SYSEX_END 0xf7
54 #define LINE6_RESET 0xff
55
56 /*
57 MIDI channel for messages initiated by the host
58 (and eventually echoed back by the device)
59 */
60 #define LINE6_CHANNEL_HOST 0x00
61
62 /*
63 MIDI channel for messages initiated by the device
64 */
65 #define LINE6_CHANNEL_DEVICE 0x02
66
67 #define LINE6_CHANNEL_UNKNOWN 5 /* don't know yet what this is good for */
68
69 #define LINE6_CHANNEL_MASK 0x0f
70
71 #define CHECK_STARTUP_PROGRESS(x, n) \
72 do { \
73 if ((x) >= (n)) \
74 return; \
75 x = (n); \
76 } while (0)
77
78 extern const unsigned char line6_midi_id[3];
79
80 static const int SYSEX_DATA_OFS = sizeof(line6_midi_id) + 3;
81 static const int SYSEX_EXTRA_SIZE = sizeof(line6_midi_id) + 4;
82
83 /*
84 Common properties of Line 6 devices.
85 */
86 struct line6_properties {
87 /* Card id string (maximum 16 characters).
88 * This can be used to address the device in ALSA programs as
89 * "default:CARD=<id>"
90 */
91 const char *id;
92
93 /* Card short name (maximum 32 characters) */
94 const char *name;
95
96 /* Bit vector defining this device's capabilities in line6usb driver */
97 int capabilities;
98
99 int altsetting;
100
101 unsigned ep_ctrl_r;
102 unsigned ep_ctrl_w;
103 unsigned ep_audio_r;
104 unsigned ep_audio_w;
105 };
106
107 /* Capability bits */
108 enum {
109 /* device supports settings parameter via USB */
110 LINE6_CAP_CONTROL = 1 << 0,
111 /* device supports PCM input/output via USB */
112 LINE6_CAP_PCM = 1 << 1,
113 /* device supports hardware monitoring */
114 LINE6_CAP_HWMON = 1 << 2,
115 /* device requires output data when input is read */
116 LINE6_CAP_IN_NEEDS_OUT = 1 << 3,
117 /* device uses raw MIDI via USB (data endpoints) */
118 LINE6_CAP_CONTROL_MIDI = 1 << 4,
119 };
120
121 /*
122 Common data shared by all Line 6 devices.
123 Corresponds to a pair of USB endpoints.
124 */
125 struct usb_line6 {
126 /* USB device */
127 struct usb_device *usbdev;
128
129 /* Properties */
130 const struct line6_properties *properties;
131
132 /* Interval for data USB packets */
133 int interval;
134 /* ...for isochronous transfers framing */
135 int intervals_per_second;
136
137 /* Number of isochronous URBs used for frame transfers */
138 int iso_buffers;
139
140 /* Maximum size of data USB packet */
141 int max_packet_size;
142
143 /* Device representing the USB interface */
144 struct device *ifcdev;
145
146 /* Line 6 sound card data structure.
147 * Each device has at least MIDI or PCM.
148 */
149 struct snd_card *card;
150
151 /* Line 6 PCM device data structure */
152 struct snd_line6_pcm *line6pcm;
153
154 /* Line 6 MIDI device data structure */
155 struct snd_line6_midi *line6midi;
156
157 /* URB for listening to POD data endpoint */
158 struct urb *urb_listen;
159
160 /* Buffer for incoming data from POD data endpoint */
161 unsigned char *buffer_listen;
162
163 /* Buffer for message to be processed, generated from MIDI layer */
164 unsigned char *buffer_message;
165
166 /* Length of message to be processed, generated from MIDI layer */
167 int message_length;
168
169 /* Circular buffer for non-MIDI control messages */
170 struct {
171 struct mutex read_lock;
172 wait_queue_head_t wait_queue;
173 unsigned int active:1;
174 STRUCT_KFIFO_REC_2(LINE6_BUFSIZE_LISTEN * LINE6_RAW_MESSAGES_MAXCOUNT)
175 fifo;
176 } messages;
177
178 /* If MIDI is supported, buffer_message contains the pre-processed data;
179 * otherwise the data is only in urb_listen (buffer_incoming).
180 */
181 void (*process_message)(struct usb_line6 *);
182 void (*disconnect)(struct usb_line6 *line6);
183 };
184
185 extern char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1,
186 int code2, int size);
187 extern int line6_read_data(struct usb_line6 *line6, unsigned address,
188 void *data, unsigned datalen);
189 extern int line6_read_serial_number(struct usb_line6 *line6,
190 u32 *serial_number);
191 extern int line6_send_raw_message_async(struct usb_line6 *line6,
192 const char *buffer, int size);
193 extern int line6_send_sysex_message(struct usb_line6 *line6,
194 const char *buffer, int size);
195 extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr,
196 const char *buf, size_t count);
197 extern void line6_start_timer(struct timer_list *timer, unsigned long msecs,
198 void (*function)(unsigned long),
199 unsigned long data);
200 extern int line6_version_request_async(struct usb_line6 *line6);
201 extern int line6_write_data(struct usb_line6 *line6, unsigned address,
202 void *data, unsigned datalen);
203
204 int line6_probe(struct usb_interface *interface,
205 const struct usb_device_id *id,
206 const char *driver_name,
207 const struct line6_properties *properties,
208 int (*private_init)(struct usb_line6 *, const struct usb_device_id *id),
209 size_t data_size);
210
211 void line6_disconnect(struct usb_interface *interface);
212
213 #ifdef CONFIG_PM
214 int line6_suspend(struct usb_interface *interface, pm_message_t message);
215 int line6_resume(struct usb_interface *interface);
216 #endif
217
218 #endif