2 * Line 6 Linux USB driver
4 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
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.
12 #include <linux/slab.h>
13 #include <linux/spinlock.h>
14 #include <linux/usb.h>
15 #include <linux/wait.h>
16 #include <linux/module.h>
17 #include <sound/core.h>
22 #define VARIAX_STARTUP_DELAY1 1000
23 #define VARIAX_STARTUP_DELAY3 100
24 #define VARIAX_STARTUP_DELAY4 100
27 Stages of Variax startup procedure
30 VARIAX_STARTUP_INIT
= 1,
31 VARIAX_STARTUP_VERSIONREQ
,
33 VARIAX_STARTUP_ACTIVATE
,
34 VARIAX_STARTUP_WORKQUEUE
,
36 VARIAX_STARTUP_LAST
= VARIAX_STARTUP_SETUP
- 1
40 LINE6_PODXTLIVE_VARIAX
,
44 struct usb_line6_variax
{
46 Generic Line 6 USB data.
48 struct usb_line6 line6
;
51 Buffer for activation code.
53 unsigned char *buffer_activate
;
56 Handler for device initializaton.
58 struct work_struct startup_work
;
61 Timers for device initializaton.
63 struct timer_list startup_timer1
;
64 struct timer_list startup_timer2
;
67 Current progress in startup procedure.
72 #define VARIAX_OFFSET_ACTIVATE 7
75 This message is sent by the device during initialization and identifies
76 the connected guitar version.
78 static const char variax_init_version
[] = {
79 0xf0, 0x7e, 0x7f, 0x06, 0x02, 0x00, 0x01, 0x0c,
80 0x07, 0x00, 0x00, 0x00
84 This message is the last one sent by the device during initialization.
86 static const char variax_init_done
[] = {
87 0xf0, 0x00, 0x01, 0x0c, 0x07, 0x00, 0x6b
90 static const char variax_activate
[] = {
91 0xf0, 0x00, 0x01, 0x0c, 0x07, 0x00, 0x2a, 0x01,
95 /* forward declarations: */
96 static void variax_startup2(unsigned long data
);
97 static void variax_startup4(unsigned long data
);
98 static void variax_startup5(unsigned long data
);
100 static void variax_activate_async(struct usb_line6_variax
*variax
, int a
)
102 variax
->buffer_activate
[VARIAX_OFFSET_ACTIVATE
] = a
;
103 line6_send_raw_message_async(&variax
->line6
, variax
->buffer_activate
,
104 sizeof(variax_activate
));
108 Variax startup procedure.
109 This is a sequence of functions with special requirements (e.g., must
110 not run immediately after initialization, must not run in interrupt
111 context). After the last one has finished, the device is ready to use.
114 static void variax_startup1(struct usb_line6_variax
*variax
)
116 CHECK_STARTUP_PROGRESS(variax
->startup_progress
, VARIAX_STARTUP_INIT
);
118 /* delay startup procedure: */
119 line6_start_timer(&variax
->startup_timer1
, VARIAX_STARTUP_DELAY1
,
120 variax_startup2
, (unsigned long)variax
);
123 static void variax_startup2(unsigned long data
)
125 struct usb_line6_variax
*variax
= (struct usb_line6_variax
*)data
;
126 struct usb_line6
*line6
= &variax
->line6
;
128 /* schedule another startup procedure until startup is complete: */
129 if (variax
->startup_progress
>= VARIAX_STARTUP_LAST
)
132 variax
->startup_progress
= VARIAX_STARTUP_VERSIONREQ
;
133 line6_start_timer(&variax
->startup_timer1
, VARIAX_STARTUP_DELAY1
,
134 variax_startup2
, (unsigned long)variax
);
136 /* request firmware version: */
137 line6_version_request_async(line6
);
140 static void variax_startup3(struct usb_line6_variax
*variax
)
142 CHECK_STARTUP_PROGRESS(variax
->startup_progress
, VARIAX_STARTUP_WAIT
);
144 /* delay startup procedure: */
145 line6_start_timer(&variax
->startup_timer2
, VARIAX_STARTUP_DELAY3
,
146 variax_startup4
, (unsigned long)variax
);
149 static void variax_startup4(unsigned long data
)
151 struct usb_line6_variax
*variax
= (struct usb_line6_variax
*)data
;
153 CHECK_STARTUP_PROGRESS(variax
->startup_progress
,
154 VARIAX_STARTUP_ACTIVATE
);
156 /* activate device: */
157 variax_activate_async(variax
, 1);
158 line6_start_timer(&variax
->startup_timer2
, VARIAX_STARTUP_DELAY4
,
159 variax_startup5
, (unsigned long)variax
);
162 static void variax_startup5(unsigned long data
)
164 struct usb_line6_variax
*variax
= (struct usb_line6_variax
*)data
;
166 CHECK_STARTUP_PROGRESS(variax
->startup_progress
,
167 VARIAX_STARTUP_WORKQUEUE
);
169 /* schedule work for global work queue: */
170 schedule_work(&variax
->startup_work
);
173 static void variax_startup6(struct work_struct
*work
)
175 struct usb_line6_variax
*variax
=
176 container_of(work
, struct usb_line6_variax
, startup_work
);
178 CHECK_STARTUP_PROGRESS(variax
->startup_progress
, VARIAX_STARTUP_SETUP
);
180 /* ALSA audio interface: */
181 snd_card_register(variax
->line6
.card
);
185 Process a completely received message.
187 static void line6_variax_process_message(struct usb_line6
*line6
)
189 struct usb_line6_variax
*variax
= (struct usb_line6_variax
*) line6
;
190 const unsigned char *buf
= variax
->line6
.buffer_message
;
194 dev_info(variax
->line6
.ifcdev
, "VARIAX reset\n");
197 case LINE6_SYSEX_BEGIN
:
198 if (memcmp(buf
+ 1, variax_init_version
+ 1,
199 sizeof(variax_init_version
) - 1) == 0) {
200 variax_startup3(variax
);
201 } else if (memcmp(buf
+ 1, variax_init_done
+ 1,
202 sizeof(variax_init_done
) - 1) == 0) {
203 /* notify of complete initialization: */
204 variax_startup4((unsigned long)variax
);
213 static void line6_variax_disconnect(struct usb_interface
*interface
)
215 struct usb_line6_variax
*variax
;
220 variax
= usb_get_intfdata(interface
);
224 del_timer(&variax
->startup_timer1
);
225 del_timer(&variax
->startup_timer2
);
226 cancel_work_sync(&variax
->startup_work
);
228 kfree(variax
->buffer_activate
);
232 Try to init workbench device.
234 static int variax_init(struct usb_interface
*interface
,
235 struct usb_line6
*line6
)
237 struct usb_line6_variax
*variax
= (struct usb_line6_variax
*) line6
;
240 line6
->process_message
= line6_variax_process_message
;
241 line6
->disconnect
= line6_variax_disconnect
;
243 init_timer(&variax
->startup_timer1
);
244 init_timer(&variax
->startup_timer2
);
245 INIT_WORK(&variax
->startup_work
, variax_startup6
);
247 if ((interface
== NULL
) || (variax
== NULL
))
250 /* initialize USB buffers: */
251 variax
->buffer_activate
= kmemdup(variax_activate
,
252 sizeof(variax_activate
), GFP_KERNEL
);
254 if (variax
->buffer_activate
== NULL
)
257 /* initialize MIDI subsystem: */
258 err
= line6_init_midi(&variax
->line6
);
262 /* initiate startup procedure: */
263 variax_startup1(variax
);
267 #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
268 #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
270 /* table of devices that work with this driver */
271 static const struct usb_device_id variax_id_table
[] = {
272 { LINE6_IF_NUM(0x4650, 1), .driver_info
= LINE6_PODXTLIVE_VARIAX
},
273 { LINE6_DEVICE(0x534d), .driver_info
= LINE6_VARIAX
},
277 MODULE_DEVICE_TABLE(usb
, variax_id_table
);
279 static const struct line6_properties variax_properties_table
[] = {
280 [LINE6_PODXTLIVE_VARIAX
] = {
282 .name
= "PODxt Live",
283 .capabilities
= LINE6_CAP_CONTROL
294 .name
= "Variax Workbench",
295 .capabilities
= LINE6_CAP_CONTROL
,
299 /* no audio channel */
306 static int variax_probe(struct usb_interface
*interface
,
307 const struct usb_device_id
*id
)
309 struct usb_line6_variax
*variax
;
311 variax
= kzalloc(sizeof(*variax
), GFP_KERNEL
);
314 return line6_probe(interface
, &variax
->line6
,
315 &variax_properties_table
[id
->driver_info
],
319 static struct usb_driver variax_driver
= {
320 .name
= KBUILD_MODNAME
,
321 .probe
= variax_probe
,
322 .disconnect
= line6_disconnect
,
324 .suspend
= line6_suspend
,
325 .resume
= line6_resume
,
326 .reset_resume
= line6_resume
,
328 .id_table
= variax_id_table
,
331 module_usb_driver(variax_driver
);
333 MODULE_DESCRIPTION("Vairax Workbench USB driver");
334 MODULE_LICENSE("GPL");