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