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>
21 #define VARIAX_STARTUP_DELAY1 1000
22 #define VARIAX_STARTUP_DELAY3 100
23 #define VARIAX_STARTUP_DELAY4 100
26 Stages of Variax startup procedure
29 VARIAX_STARTUP_INIT
= 1,
30 VARIAX_STARTUP_VERSIONREQ
,
32 VARIAX_STARTUP_ACTIVATE
,
33 VARIAX_STARTUP_WORKQUEUE
,
35 VARIAX_STARTUP_LAST
= VARIAX_STARTUP_SETUP
- 1
39 LINE6_PODXTLIVE_VARIAX
,
43 struct usb_line6_variax
{
44 /* Generic Line 6 USB data */
45 struct usb_line6 line6
;
47 /* Buffer for activation code */
48 unsigned char *buffer_activate
;
50 /* Handler for device initialization */
51 struct work_struct startup_work
;
53 /* Timers for device initialization */
54 struct timer_list startup_timer1
;
55 struct timer_list startup_timer2
;
57 /* Current progress in startup procedure */
61 #define VARIAX_OFFSET_ACTIVATE 7
64 This message is sent by the device during initialization and identifies
65 the connected guitar version.
67 static const char variax_init_version
[] = {
68 0xf0, 0x7e, 0x7f, 0x06, 0x02, 0x00, 0x01, 0x0c,
69 0x07, 0x00, 0x00, 0x00
73 This message is the last one sent by the device during initialization.
75 static const char variax_init_done
[] = {
76 0xf0, 0x00, 0x01, 0x0c, 0x07, 0x00, 0x6b
79 static const char variax_activate
[] = {
80 0xf0, 0x00, 0x01, 0x0c, 0x07, 0x00, 0x2a, 0x01,
84 /* forward declarations: */
85 static void variax_startup2(unsigned long data
);
86 static void variax_startup4(unsigned long data
);
87 static void variax_startup5(unsigned long data
);
89 static void variax_activate_async(struct usb_line6_variax
*variax
, int a
)
91 variax
->buffer_activate
[VARIAX_OFFSET_ACTIVATE
] = a
;
92 line6_send_raw_message_async(&variax
->line6
, variax
->buffer_activate
,
93 sizeof(variax_activate
));
97 Variax startup procedure.
98 This is a sequence of functions with special requirements (e.g., must
99 not run immediately after initialization, must not run in interrupt
100 context). After the last one has finished, the device is ready to use.
103 static void variax_startup1(struct usb_line6_variax
*variax
)
105 CHECK_STARTUP_PROGRESS(variax
->startup_progress
, VARIAX_STARTUP_INIT
);
107 /* delay startup procedure: */
108 line6_start_timer(&variax
->startup_timer1
, VARIAX_STARTUP_DELAY1
,
109 variax_startup2
, (unsigned long)variax
);
112 static void variax_startup2(unsigned long data
)
114 struct usb_line6_variax
*variax
= (struct usb_line6_variax
*)data
;
115 struct usb_line6
*line6
= &variax
->line6
;
117 /* schedule another startup procedure until startup is complete: */
118 if (variax
->startup_progress
>= VARIAX_STARTUP_LAST
)
121 variax
->startup_progress
= VARIAX_STARTUP_VERSIONREQ
;
122 line6_start_timer(&variax
->startup_timer1
, VARIAX_STARTUP_DELAY1
,
123 variax_startup2
, (unsigned long)variax
);
125 /* request firmware version: */
126 line6_version_request_async(line6
);
129 static void variax_startup3(struct usb_line6_variax
*variax
)
131 CHECK_STARTUP_PROGRESS(variax
->startup_progress
, VARIAX_STARTUP_WAIT
);
133 /* delay startup procedure: */
134 line6_start_timer(&variax
->startup_timer2
, VARIAX_STARTUP_DELAY3
,
135 variax_startup4
, (unsigned long)variax
);
138 static void variax_startup4(unsigned long data
)
140 struct usb_line6_variax
*variax
= (struct usb_line6_variax
*)data
;
142 CHECK_STARTUP_PROGRESS(variax
->startup_progress
,
143 VARIAX_STARTUP_ACTIVATE
);
145 /* activate device: */
146 variax_activate_async(variax
, 1);
147 line6_start_timer(&variax
->startup_timer2
, VARIAX_STARTUP_DELAY4
,
148 variax_startup5
, (unsigned long)variax
);
151 static void variax_startup5(unsigned long data
)
153 struct usb_line6_variax
*variax
= (struct usb_line6_variax
*)data
;
155 CHECK_STARTUP_PROGRESS(variax
->startup_progress
,
156 VARIAX_STARTUP_WORKQUEUE
);
158 /* schedule work for global work queue: */
159 schedule_work(&variax
->startup_work
);
162 static void variax_startup6(struct work_struct
*work
)
164 struct usb_line6_variax
*variax
=
165 container_of(work
, struct usb_line6_variax
, startup_work
);
167 CHECK_STARTUP_PROGRESS(variax
->startup_progress
, VARIAX_STARTUP_SETUP
);
169 /* ALSA audio interface: */
170 snd_card_register(variax
->line6
.card
);
174 Process a completely received message.
176 static void line6_variax_process_message(struct usb_line6
*line6
)
178 struct usb_line6_variax
*variax
= (struct usb_line6_variax
*) line6
;
179 const unsigned char *buf
= variax
->line6
.buffer_message
;
183 dev_info(variax
->line6
.ifcdev
, "VARIAX reset\n");
186 case LINE6_SYSEX_BEGIN
:
187 if (memcmp(buf
+ 1, variax_init_version
+ 1,
188 sizeof(variax_init_version
) - 1) == 0) {
189 variax_startup3(variax
);
190 } else if (memcmp(buf
+ 1, variax_init_done
+ 1,
191 sizeof(variax_init_done
) - 1) == 0) {
192 /* notify of complete initialization: */
193 variax_startup4((unsigned long)variax
);
202 static void line6_variax_disconnect(struct usb_line6
*line6
)
204 struct usb_line6_variax
*variax
= (struct usb_line6_variax
*)line6
;
206 del_timer(&variax
->startup_timer1
);
207 del_timer(&variax
->startup_timer2
);
208 cancel_work_sync(&variax
->startup_work
);
210 kfree(variax
->buffer_activate
);
214 Try to init workbench device.
216 static int variax_init(struct usb_line6
*line6
,
217 const struct usb_device_id
*id
)
219 struct usb_line6_variax
*variax
= (struct usb_line6_variax
*) line6
;
222 line6
->process_message
= line6_variax_process_message
;
223 line6
->disconnect
= line6_variax_disconnect
;
225 init_timer(&variax
->startup_timer1
);
226 init_timer(&variax
->startup_timer2
);
227 INIT_WORK(&variax
->startup_work
, variax_startup6
);
229 /* initialize USB buffers: */
230 variax
->buffer_activate
= kmemdup(variax_activate
,
231 sizeof(variax_activate
), GFP_KERNEL
);
233 if (variax
->buffer_activate
== NULL
)
236 /* initialize MIDI subsystem: */
237 err
= line6_init_midi(&variax
->line6
);
241 /* initiate startup procedure: */
242 variax_startup1(variax
);
246 #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
247 #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
249 /* table of devices that work with this driver */
250 static const struct usb_device_id variax_id_table
[] = {
251 { LINE6_IF_NUM(0x4650, 1), .driver_info
= LINE6_PODXTLIVE_VARIAX
},
252 { LINE6_DEVICE(0x534d), .driver_info
= LINE6_VARIAX
},
256 MODULE_DEVICE_TABLE(usb
, variax_id_table
);
258 static const struct line6_properties variax_properties_table
[] = {
259 [LINE6_PODXTLIVE_VARIAX
] = {
261 .name
= "PODxt Live",
262 .capabilities
= LINE6_CAP_CONTROL
,
271 .name
= "Variax Workbench",
272 .capabilities
= LINE6_CAP_CONTROL
,
276 /* no audio channel */
283 static int variax_probe(struct usb_interface
*interface
,
284 const struct usb_device_id
*id
)
286 return line6_probe(interface
, id
, "Line6-Variax",
287 &variax_properties_table
[id
->driver_info
],
288 variax_init
, sizeof(struct usb_line6_variax
));
291 static struct usb_driver variax_driver
= {
292 .name
= KBUILD_MODNAME
,
293 .probe
= variax_probe
,
294 .disconnect
= line6_disconnect
,
296 .suspend
= line6_suspend
,
297 .resume
= line6_resume
,
298 .reset_resume
= line6_resume
,
300 .id_table
= variax_id_table
,
303 module_usb_driver(variax_driver
);
305 MODULE_DESCRIPTION("Vairax Workbench USB driver");
306 MODULE_LICENSE("GPL");