Merge tag 'drivers' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[cascardo/linux.git] / drivers / staging / line6 / driver.h
1 /*
2  * Line6 Linux USB driver - 0.9.1beta
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/spinlock.h>
16 #include <linux/usb.h>
17 #include <sound/core.h>
18
19 #include "midi.h"
20
21 #define DRIVER_NAME "line6usb"
22
23 #if defined(CONFIG_LINE6_USB_DUMP_PCM)
24 #define CONFIG_LINE6_USB_DUMP_ANY
25 #endif
26
27 #define LINE6_TIMEOUT 1
28 #define LINE6_BUFSIZE_LISTEN 32
29 #define LINE6_MESSAGE_MAXLEN 256
30
31 /*
32         Line6 MIDI control commands
33 */
34 #define LINE6_PARAM_CHANGE   0xb0
35 #define LINE6_PROGRAM_CHANGE 0xc0
36 #define LINE6_SYSEX_BEGIN    0xf0
37 #define LINE6_SYSEX_END      0xf7
38 #define LINE6_RESET          0xff
39
40 /*
41         MIDI channel for messages initiated by the host
42         (and eventually echoed back by the device)
43 */
44 #define LINE6_CHANNEL_HOST   0x00
45
46 /*
47         MIDI channel for messages initiated by the device
48 */
49 #define LINE6_CHANNEL_DEVICE 0x02
50
51 #define LINE6_CHANNEL_UNKNOWN 5 /* don't know yet what this is good for */
52
53 #define LINE6_CHANNEL_MASK 0x0f
54
55 #define MISSING_CASE    \
56         printk(KERN_ERR "line6usb driver bug: missing case in %s:%d\n", \
57                 __FILE__, __LINE__)
58
59 #define CHECK_RETURN(x)         \
60 do {                            \
61         err = x;                \
62         if (err < 0)            \
63                 return err;     \
64 } while (0)
65
66 #define CHECK_STARTUP_PROGRESS(x, n)    \
67 do {                                    \
68         if ((x) >= (n))                 \
69                 return;                 \
70         x = (n);                        \
71 } while (0)
72
73 extern const unsigned char line6_midi_id[3];
74
75 static const int SYSEX_DATA_OFS = sizeof(line6_midi_id) + 3;
76 static const int SYSEX_EXTRA_SIZE = sizeof(line6_midi_id) + 4;
77
78 /**
79          Common properties of Line6 devices.
80 */
81 struct line6_properties {
82         /**
83                  Bit identifying this device in the line6usb driver.
84         */
85         int device_bit;
86
87         /**
88                  Card id string (maximum 16 characters).
89                  This can be used to address the device in ALSA programs as
90                  "default:CARD=<id>"
91         */
92         const char *id;
93
94         /**
95                  Card short name (maximum 32 characters).
96         */
97         const char *name;
98
99         /**
100                  Bit vector defining this device's capabilities in the
101                  line6usb driver.
102         */
103         int capabilities;
104 };
105
106 /**
107          Common data shared by all Line6 devices.
108          Corresponds to a pair of USB endpoints.
109 */
110 struct usb_line6 {
111         /**
112                  USB device.
113         */
114         struct usb_device *usbdev;
115
116         /**
117                  Product id.
118         */
119         int product;
120
121         /**
122                  Properties.
123         */
124         const struct line6_properties *properties;
125
126         /**
127                  Interface number.
128         */
129         int interface_number;
130
131         /**
132                  Interval (ms).
133         */
134         int interval;
135
136         /**
137                  Maximum size of USB packet.
138         */
139         int max_packet_size;
140
141         /**
142                  Device representing the USB interface.
143         */
144         struct device *ifcdev;
145
146         /**
147                  Line6 sound card data structure.
148                  Each device has at least MIDI or PCM.
149         */
150         struct snd_card *card;
151
152         /**
153                  Line6 PCM device data structure.
154         */
155         struct snd_line6_pcm *line6pcm;
156
157         /**
158                  Line6 MIDI device data structure.
159         */
160         struct snd_line6_midi *line6midi;
161
162         /**
163                  USB endpoint for listening to control commands.
164         */
165         int ep_control_read;
166
167         /**
168                  USB endpoint for writing control commands.
169         */
170         int ep_control_write;
171
172         /**
173                  URB for listening to PODxt Pro control endpoint.
174         */
175         struct urb *urb_listen;
176
177         /**
178                  Buffer for listening to PODxt Pro control endpoint.
179         */
180         unsigned char *buffer_listen;
181
182         /**
183                  Buffer for message to be processed.
184         */
185         unsigned char *buffer_message;
186
187         /**
188                  Length of message to be processed.
189         */
190         int message_length;
191 };
192
193 extern char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1,
194                                       int code2, int size);
195 extern ssize_t line6_nop_read(struct device *dev,
196                               struct device_attribute *attr, char *buf);
197 extern ssize_t line6_nop_write(struct device *dev,
198                                struct device_attribute *attr,
199                                const char *buf, size_t count);
200 extern int line6_read_data(struct usb_line6 *line6, int address, void *data,
201                            size_t datalen);
202 extern int line6_read_serial_number(struct usb_line6 *line6,
203                                     int *serial_number);
204 extern int line6_send_program(struct usb_line6 *line6, u8 value);
205 extern int line6_send_raw_message(struct usb_line6 *line6, const char *buffer,
206                                   int size);
207 extern int line6_send_raw_message_async(struct usb_line6 *line6,
208                                         const char *buffer, int size);
209 extern int line6_send_sysex_message(struct usb_line6 *line6,
210                                     const char *buffer, int size);
211 extern int line6_send_sysex_message_async(struct usb_line6 *line6,
212                                           const char *buffer, int size);
213 extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr,
214                              const char *buf, size_t count);
215 extern void line6_start_timer(struct timer_list *timer, unsigned int msecs,
216                               void (*function) (unsigned long),
217                               unsigned long data);
218 extern int line6_transmit_parameter(struct usb_line6 *line6, int param,
219                                     u8 value);
220 extern int line6_version_request_async(struct usb_line6 *line6);
221 extern int line6_write_data(struct usb_line6 *line6, int address, void *data,
222                             size_t datalen);
223
224 #ifdef CONFIG_LINE6_USB_DUMP_ANY
225 extern void line6_write_hexdump(struct usb_line6 *line6, char dir,
226                                 const unsigned char *buffer, int size);
227 #endif
228
229 #endif