Staging: add line6 usb driver
[linux-2.6-block.git] / drivers / staging / line6 / driver.h
1 /*
2  * Line6 Linux USB driver - 0.8.0
3  *
4  * Copyright (C) 2004-2009 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
16 #include "config.h"
17
18 #include <linux/spinlock.h>
19 #include <linux/usb.h>
20 #include <linux/wait.h>
21
22 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
23 #include <sound/driver.h>
24 #endif
25
26 #include <sound/core.h>
27
28 #include "midi.h"
29
30
31 #define DRIVER_NAME "line6usb"
32
33 #define LINE6_TIMEOUT 1
34 #define LINE6_MAX_DEVICES 8
35 #define LINE6_BUFSIZE_LISTEN 32
36 #define LINE6_MESSAGE_MAXLEN 256
37
38
39 /*
40         Line6 MIDI control commands
41 */
42 #define LINE6_PARAM_CHANGE   0xb0
43 #define LINE6_PROGRAM_CHANGE 0xc0
44 #define LINE6_SYSEX_BEGIN    0xf0
45 #define LINE6_SYSEX_END      0xf7
46 #define LINE6_RESET          0xff
47
48 /*
49         MIDI channel for messages initiated by the host
50         (and eventually echoed back by the device)
51 */
52 #define LINE6_CHANNEL_HOST   0x00
53
54 /*
55         MIDI channel for messages initiated by the device
56 */
57 #define LINE6_CHANNEL_DEVICE 0x02
58
59 #define LINE6_CHANNEL_UNKNOWN 5  /* don't know yet what this is good for */
60
61 #define LINE6_CHANNEL_MASK 0x0f
62
63
64 #define MISSING_CASE printk("line6usb driver bug: missing case in %s:%d\n", __FILE__, __LINE__)
65
66
67 #define CHECK_RETURN(x) if((err = x) < 0) return err
68
69
70 extern const unsigned char line6_midi_id[3];
71 extern struct usb_line6 *line6_devices[LINE6_MAX_DEVICES];
72 extern struct workqueue_struct *line6_workqueue;
73
74 static const int SYSEX_DATA_OFS = sizeof(line6_midi_id) + 3;
75 static const int SYSEX_EXTRA_SIZE = sizeof(line6_midi_id) + 4;
76
77
78 /**
79          Common properties of Line6 devices.
80 */
81 struct line6_properties {
82         const char *name;
83         int device_bit;
84         int capabilities;
85 };
86
87 /**
88          Common data shared by all Line6 devices.
89          Corresponds to a pair of USB endpoints.
90 */
91 struct usb_line6 {
92         /**
93                  USB device.
94         */
95         struct usb_device *usbdev;
96
97         /**
98                  Product id.
99         */
100         int product;
101
102         /**
103                  Properties.
104         */
105         const struct line6_properties *properties;
106
107         /**
108                  Interface number.
109         */
110         int interface_number;
111
112         /**
113                  Interval (ms).
114         */
115         int interval;
116
117         /**
118                  Maximum size of USB packet.
119         */
120         int max_packet_size;
121
122         /**
123                  Device representing the USB interface.
124         */
125         struct device *ifcdev;
126
127         /**
128                  Line6 sound card data structure.
129                  Each device has at least MIDI or PCM.
130         */
131         struct snd_card *card;
132
133         /**
134                  Line6 PCM device data structure.
135         */
136         struct snd_line6_pcm *line6pcm;
137
138         /**
139                  Line6 MIDI device data structure.
140         */
141         struct snd_line6_midi *line6midi;
142
143         /**
144                  USB endpoint for listening to control commands.
145         */
146         int ep_control_read;
147
148         /**
149                  USB endpoint for writing control commands.
150         */
151         int ep_control_write;
152
153         /**
154                  URB for listening to PODxt Pro control endpoint.
155         */
156         struct urb *urb_listen;
157
158         /**
159                  Buffer for listening to PODxt Pro control endpoint.
160         */
161         unsigned char *buffer_listen;
162
163         /**
164                  Buffer for message to be processed.
165         */
166         unsigned char *buffer_message;
167
168         /**
169                  Length of message to be processed.
170         */
171         int message_length;
172 };
173
174
175 extern char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, int code2, int size);
176 extern ssize_t line6_nop_read(struct device *dev, DEVICE_ATTRIBUTE char *buf);
177 extern ssize_t line6_nop_write(struct device *dev, DEVICE_ATTRIBUTE const char *buf, size_t count);
178 extern int line6_read_data(struct usb_line6 *line6, int address, void *data, size_t datalen);
179 extern int line6_read_serial_number(struct usb_line6 *line6, int *serial_number);
180 extern int line6_send_program(struct usb_line6 *line6, int value);
181 extern int line6_send_raw_message(struct usb_line6 *line6, const char *buffer, int size);
182 extern int line6_send_raw_message_async(struct usb_line6 *line6, const char *buffer, int size);
183 extern int line6_send_sysex_message(struct usb_line6 *line6, const char *buffer, int size);
184 extern ssize_t line6_set_raw(struct device *dev, DEVICE_ATTRIBUTE const char *buf, size_t count);
185 extern int line6_transmit_parameter(struct usb_line6 *line6, int param, int value);
186 extern int line6_write_data(struct usb_line6 *line6, int address, void *data, size_t datalen);
187 extern void line6_write_hexdump(struct usb_line6 *line6, char dir, const unsigned char *buffer, int size);
188
189
190 #endif