blob: 58ddbe6393ff7e3bf2ba2e17c4166c423fcafd97 [file] [log] [blame]
Markus Grabner705ecec2009-02-27 19:43:04 -08001/*
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#include "driver.h"
13
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
15
Markus Grabner705ecec2009-02-27 19:43:04 -080016#include "audio.h"
17#include "control.h"
18#include "variax.h"
19
20
21#define VARIAX_SYSEX_CODE 7
22#define VARIAX_SYSEX_PARAM 0x3b
23#define VARIAX_SYSEX_ACTIVATE 0x2a
24#define VARIAX_MODEL_HEADER_LENGTH 7
25#define VARIAX_MODEL_MESSAGE_LENGTH 199
26#define VARIAX_OFFSET_ACTIVATE 7
27
28
29static const char variax_activate[] = {
30 0xf0, 0x00, 0x01, 0x0c, 0x07, 0x00, 0x2a, 0x01,
31 0xf7
32};
33static const char variax_request_bank[] = {
34 0xf0, 0x00, 0x01, 0x0c, 0x07, 0x00, 0x6d, 0xf7
35};
36static const char variax_request_model1[] = {
37 0xf0, 0x00, 0x01, 0x0c, 0x07, 0x00, 0x3c, 0x00,
38 0x02, 0x00, 0x00, 0x00, 0x00, 0x03, 0x05, 0x03,
39 0x00, 0x00, 0x00, 0xf7
40};
41static const char variax_request_model2[] = {
42 0xf0, 0x00, 0x01, 0x0c, 0x07, 0x00, 0x3c, 0x00,
43 0x02, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x03,
44 0x00, 0x00, 0x00, 0xf7
45};
46
47
48/*
49 Decode data transmitted by workbench.
50*/
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -080051static void variax_decode(const unsigned char *raw_data, unsigned char *data,
52 int raw_size)
Markus Grabner705ecec2009-02-27 19:43:04 -080053{
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -080054 for (; raw_size > 0; raw_size -= 6) {
Markus Grabner705ecec2009-02-27 19:43:04 -080055 data[2] = raw_data[0] | (raw_data[1] << 4);
56 data[1] = raw_data[2] | (raw_data[3] << 4);
57 data[0] = raw_data[4] | (raw_data[5] << 4);
58 raw_data += 6;
59 data += 3;
60 }
61}
62
63static void variax_activate_timeout(unsigned long arg)
64{
65 struct usb_line6_variax *variax = (struct usb_line6_variax *)arg;
66 variax->buffer_activate[VARIAX_OFFSET_ACTIVATE] = 1;
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -080067 line6_send_raw_message_async(&variax->line6, variax->buffer_activate,
68 sizeof(variax_activate));
Markus Grabner705ecec2009-02-27 19:43:04 -080069}
70
71/*
72 Send an asynchronous activation request after a given interval.
73*/
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -080074static void variax_activate_delayed(struct usb_line6_variax *variax,
75 int seconds)
Markus Grabner705ecec2009-02-27 19:43:04 -080076{
77 variax->activate_timer.expires = jiffies + seconds * HZ;
78 variax->activate_timer.function = variax_activate_timeout;
79 variax->activate_timer.data = (unsigned long)variax;
80 add_timer(&variax->activate_timer);
81}
82
83static void variax_startup_timeout(unsigned long arg)
84{
85 struct usb_line6_variax *variax = (struct usb_line6_variax *)arg;
86
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -080087 if (variax->dumpreq.ok)
Markus Grabner705ecec2009-02-27 19:43:04 -080088 return;
89
90 line6_dump_request_async(&variax->dumpreq, &variax->line6, 0);
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -080091 line6_startup_delayed(&variax->dumpreq, 1, variax_startup_timeout,
92 variax);
Markus Grabner705ecec2009-02-27 19:43:04 -080093}
94
95/*
96 Process a completely received message.
97*/
98void variax_process_message(struct usb_line6_variax *variax)
99{
100 const unsigned char *buf = variax->line6.buffer_message;
101
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800102 switch (buf[0]) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800103 case LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST:
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800104 switch (buf[1]) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800105 case VARIAXMIDI_volume:
106 variax->volume = buf[2];
107 break;
108
109 case VARIAXMIDI_tone:
110 variax->tone = buf[2];
111 }
112
113 break;
114
115 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_DEVICE:
116 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST:
117 variax->model = buf[1];
118 line6_dump_request_async(&variax->dumpreq, &variax->line6, 0);
119 break;
120
121 case LINE6_RESET:
122 dev_info(variax->line6.ifcdev, "VARIAX reset\n");
123 variax_activate_delayed(variax, VARIAX_ACTIVATE_DELAY);
124 break;
125
126 case LINE6_SYSEX_BEGIN:
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800127 if (memcmp(buf + 1, variax_request_model1 + 1,
128 VARIAX_MODEL_HEADER_LENGTH - 1) == 0) {
129 if (variax->line6.message_length ==
130 VARIAX_MODEL_MESSAGE_LENGTH) {
131 switch (variax->dumpreq.in_progress) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800132 case VARIAX_DUMP_PASS1:
133 variax_decode(buf + VARIAX_MODEL_HEADER_LENGTH, (unsigned char *)&variax->model_data,
134 (sizeof(variax->model_data.name) + sizeof(variax->model_data.control) / 2) * 2);
135 line6_dump_request_async(&variax->dumpreq, &variax->line6, 1);
136 line6_dump_started(&variax->dumpreq, VARIAX_DUMP_PASS2);
137 break;
138
139 case VARIAX_DUMP_PASS2:
140 /* model name is transmitted twice, so skip it here: */
141 variax_decode(buf + VARIAX_MODEL_HEADER_LENGTH,
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800142 (unsigned char *)&variax->model_data.control + sizeof(variax->model_data.control) / 2,
143 sizeof(variax->model_data.control) / 2 * 2);
Markus Grabner705ecec2009-02-27 19:43:04 -0800144 variax->dumpreq.ok = 1;
145 line6_dump_request_async(&variax->dumpreq, &variax->line6, 2);
146 line6_dump_started(&variax->dumpreq, VARIAX_DUMP_PASS3);
147 }
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800148 } else {
Markus Grabner705ecec2009-02-27 19:43:04 -0800149 DEBUG_MESSAGES(dev_err(variax->line6.ifcdev, "illegal length %d of model data\n", variax->line6.message_length));
150 line6_dump_finished(&variax->dumpreq);
151 }
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800152 } else if (memcmp(buf + 1, variax_request_bank + 1,
153 sizeof(variax_request_bank) - 2) == 0) {
154 memcpy(variax->bank,
155 buf + sizeof(variax_request_bank) - 1,
156 sizeof(variax->bank));
Markus Grabner705ecec2009-02-27 19:43:04 -0800157 variax->dumpreq.ok = 1;
158 line6_dump_finished(&variax->dumpreq);
159 }
160
161 break;
162
163 case LINE6_SYSEX_END:
164 break;
165
166 default:
167 DEBUG_MESSAGES(dev_err(variax->line6.ifcdev, "Variax: unknown message %02X\n", buf[0]));
168 }
169}
170
171/*
172 "read" request on "volume" special file.
173*/
Greg Kroah-Hartman77491e52009-02-27 20:25:43 -0800174static ssize_t variax_get_volume(struct device *dev,
175 struct device_attribute *attr, char *buf)
Markus Grabner705ecec2009-02-27 19:43:04 -0800176{
177 struct usb_line6_variax *variax = usb_get_intfdata(to_usb_interface(dev));
178 return sprintf(buf, "%d\n", variax->volume);
179}
180
181/*
182 "write" request on "volume" special file.
183*/
Greg Kroah-Hartman77491e52009-02-27 20:25:43 -0800184static ssize_t variax_set_volume(struct device *dev,
185 struct device_attribute *attr,
186 const char *buf, size_t count)
Markus Grabner705ecec2009-02-27 19:43:04 -0800187{
188 struct usb_line6_variax *variax = usb_get_intfdata(to_usb_interface(dev));
Shawn Bohrerc0e6e7c2009-11-15 22:18:00 -0600189 unsigned long value;
190 int ret;
191
192 ret = strict_strtoul(buf, 10, &value);
193 if (ret)
194 return ret;
Markus Grabner705ecec2009-02-27 19:43:04 -0800195
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800196 if (line6_transmit_parameter(&variax->line6, VARIAXMIDI_volume,
197 value) == 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800198 variax->volume = value;
199
200 return count;
201}
202
203/*
204 "read" request on "model" special file.
205*/
Greg Kroah-Hartman77491e52009-02-27 20:25:43 -0800206static ssize_t variax_get_model(struct device *dev,
207 struct device_attribute *attr, char *buf)
Markus Grabner705ecec2009-02-27 19:43:04 -0800208{
209 struct usb_line6_variax *variax = usb_get_intfdata(to_usb_interface(dev));
210 return sprintf(buf, "%d\n", variax->model);
211}
212
213/*
214 "write" request on "model" special file.
215*/
Greg Kroah-Hartman77491e52009-02-27 20:25:43 -0800216static ssize_t variax_set_model(struct device *dev,
217 struct device_attribute *attr,
218 const char *buf, size_t count)
Markus Grabner705ecec2009-02-27 19:43:04 -0800219{
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800220 struct usb_line6_variax *variax = usb_get_intfdata(to_usb_interface(dev));
Shawn Bohrerc0e6e7c2009-11-15 22:18:00 -0600221 unsigned long value;
222 int ret;
223
224 ret = strict_strtoul(buf, 10, &value);
225 if (ret)
226 return ret;
Markus Grabner705ecec2009-02-27 19:43:04 -0800227
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800228 if (line6_send_program(&variax->line6, value) == 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800229 variax->model = value;
230
231 return count;
232}
233
234/*
235 "read" request on "active" special file.
236*/
Greg Kroah-Hartman77491e52009-02-27 20:25:43 -0800237static ssize_t variax_get_active(struct device *dev,
238 struct device_attribute *attr, char *buf)
Markus Grabner705ecec2009-02-27 19:43:04 -0800239{
240 struct usb_line6_variax *variax = usb_get_intfdata(to_usb_interface(dev));
241 return sprintf(buf, "%d\n", variax->buffer_activate[VARIAX_OFFSET_ACTIVATE]);
242}
243
244/*
245 "write" request on "active" special file.
246*/
Greg Kroah-Hartman77491e52009-02-27 20:25:43 -0800247static ssize_t variax_set_active(struct device *dev,
248 struct device_attribute *attr,
249 const char *buf, size_t count)
Markus Grabner705ecec2009-02-27 19:43:04 -0800250{
251 struct usb_line6_variax *variax = usb_get_intfdata(to_usb_interface(dev));
Shawn Bohrerc0e6e7c2009-11-15 22:18:00 -0600252 unsigned long value;
253 int ret;
254
255 ret = strict_strtoul(buf, 10, &value);
256 if (ret)
257 return ret;
258
Sylvain Trias0f7cf002010-02-24 00:17:52 +0100259 variax->buffer_activate[VARIAX_OFFSET_ACTIVATE] = value ? 1 : 0;
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800260 line6_send_raw_message_async(&variax->line6, variax->buffer_activate,
261 sizeof(variax_activate));
Markus Grabner705ecec2009-02-27 19:43:04 -0800262 return count;
263}
264
265/*
266 "read" request on "tone" special file.
267*/
Greg Kroah-Hartman77491e52009-02-27 20:25:43 -0800268static ssize_t variax_get_tone(struct device *dev,
269 struct device_attribute *attr, char *buf)
Markus Grabner705ecec2009-02-27 19:43:04 -0800270{
271 struct usb_line6_variax *variax = usb_get_intfdata(to_usb_interface(dev));
272 return sprintf(buf, "%d\n", variax->tone);
273}
274
275/*
276 "write" request on "tone" special file.
277*/
Greg Kroah-Hartman77491e52009-02-27 20:25:43 -0800278static ssize_t variax_set_tone(struct device *dev,
279 struct device_attribute *attr,
280 const char *buf, size_t count)
Markus Grabner705ecec2009-02-27 19:43:04 -0800281{
282 struct usb_line6_variax *variax = usb_get_intfdata(to_usb_interface(dev));
Shawn Bohrerc0e6e7c2009-11-15 22:18:00 -0600283 unsigned long value;
284 int ret;
285
286 ret = strict_strtoul(buf, 10, &value);
287 if (ret)
288 return ret;
Markus Grabner705ecec2009-02-27 19:43:04 -0800289
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800290 if (line6_transmit_parameter(&variax->line6, VARIAXMIDI_tone,
291 value) == 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800292 variax->tone = value;
293
294 return count;
295}
296
297static ssize_t get_string(char *buf, const char *data, int length)
298{
299 int i;
300 memcpy(buf, data, length);
301
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800302 for (i = length; i--;) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800303 char c = buf[i];
304
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800305 if ((c != 0) && (c != ' '))
Markus Grabner705ecec2009-02-27 19:43:04 -0800306 break;
307 }
308
309 buf[i + 1] = '\n';
310 return i + 2;
311}
312
313/*
314 "read" request on "name" special file.
315*/
Greg Kroah-Hartman77491e52009-02-27 20:25:43 -0800316static ssize_t variax_get_name(struct device *dev,
317 struct device_attribute *attr, char *buf)
Markus Grabner705ecec2009-02-27 19:43:04 -0800318{
319 struct usb_line6_variax *variax = usb_get_intfdata(to_usb_interface(dev));
320 line6_wait_dump(&variax->dumpreq, 0);
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800321 return get_string(buf, variax->model_data.name,
322 sizeof(variax->model_data.name));
Markus Grabner705ecec2009-02-27 19:43:04 -0800323}
324
325/*
326 "read" request on "bank" special file.
327*/
Greg Kroah-Hartman77491e52009-02-27 20:25:43 -0800328static ssize_t variax_get_bank(struct device *dev,
329 struct device_attribute *attr, char *buf)
Markus Grabner705ecec2009-02-27 19:43:04 -0800330{
331 struct usb_line6_variax *variax = usb_get_intfdata(to_usb_interface(dev));
332 line6_wait_dump(&variax->dumpreq, 0);
333 return get_string(buf, variax->bank, sizeof(variax->bank));
334}
335
336/*
337 "read" request on "dump" special file.
338*/
Greg Kroah-Hartman77491e52009-02-27 20:25:43 -0800339static ssize_t variax_get_dump(struct device *dev,
340 struct device_attribute *attr, char *buf)
Markus Grabner705ecec2009-02-27 19:43:04 -0800341{
342 struct usb_line6_variax *variax = usb_get_intfdata(to_usb_interface(dev));
343 int retval;
344 retval = line6_wait_dump(&variax->dumpreq, 0);
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800345 if (retval < 0)
346 return retval;
347 memcpy(buf, &variax->model_data.control,
348 sizeof(variax->model_data.control));
Markus Grabner705ecec2009-02-27 19:43:04 -0800349 return sizeof(variax->model_data.control);
350}
351
352#if CREATE_RAW_FILE
353
354/*
355 "write" request on "raw" special file.
356*/
Greg Kroah-Hartman77491e52009-02-27 20:25:43 -0800357static ssize_t variax_set_raw2(struct device *dev,
358 struct device_attribute *attr,
359 const char *buf, size_t count)
Markus Grabner705ecec2009-02-27 19:43:04 -0800360{
361 struct usb_line6_variax *variax = usb_get_intfdata(to_usb_interface(dev));
362 int size;
363 int i;
364 char *sysex;
365
366 count -= count % 3;
367 size = count * 2;
368 sysex = variax_alloc_sysex_buffer(variax, VARIAX_SYSEX_PARAM, size);
369
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800370 if (!sysex)
Markus Grabner705ecec2009-02-27 19:43:04 -0800371 return 0;
372
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800373 for (i = 0; i < count; i += 3) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800374 const unsigned char *p1 = buf + i;
375 char *p2 = sysex + SYSEX_DATA_OFS + i * 2;
376 p2[0] = p1[2] & 0x0f;
377 p2[1] = p1[2] >> 4;
378 p2[2] = p1[1] & 0x0f;
379 p2[3] = p1[1] >> 4;
380 p2[4] = p1[0] & 0x0f;
381 p2[5] = p1[0] >> 4;
382 }
383
384 line6_send_sysex_message(&variax->line6, sysex, size);
385 kfree(sysex);
386 return count;
387}
388
389#endif
390
391/* Variax workbench special files: */
392static DEVICE_ATTR(model, S_IWUGO | S_IRUGO, variax_get_model, variax_set_model);
393static DEVICE_ATTR(volume, S_IWUGO | S_IRUGO, variax_get_volume, variax_set_volume);
394static DEVICE_ATTR(tone, S_IWUGO | S_IRUGO, variax_get_tone, variax_set_tone);
395static DEVICE_ATTR(name, S_IRUGO, variax_get_name, line6_nop_write);
396static DEVICE_ATTR(bank, S_IRUGO, variax_get_bank, line6_nop_write);
397static DEVICE_ATTR(dump, S_IRUGO, variax_get_dump, line6_nop_write);
398static DEVICE_ATTR(active, S_IWUGO | S_IRUGO, variax_get_active, variax_set_active);
399
400#if CREATE_RAW_FILE
401static DEVICE_ATTR(raw, S_IWUGO, line6_nop_read, line6_set_raw);
402static DEVICE_ATTR(raw2, S_IWUGO, line6_nop_read, variax_set_raw2);
403#endif
404
405
406/*
407 Variax destructor.
408*/
409static void variax_destruct(struct usb_interface *interface)
410{
411 struct usb_line6_variax *variax = usb_get_intfdata(interface);
412 struct usb_line6 *line6;
413
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800414 if (variax == NULL)
415 return;
Markus Grabner705ecec2009-02-27 19:43:04 -0800416 line6 = &variax->line6;
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800417 if (line6 == NULL)
418 return;
Markus Grabner705ecec2009-02-27 19:43:04 -0800419 line6_cleanup_audio(line6);
420
421 /* free dump request data: */
422 line6_dumpreq_destructbuf(&variax->dumpreq, 2);
423 line6_dumpreq_destructbuf(&variax->dumpreq, 1);
424 line6_dumpreq_destruct(&variax->dumpreq);
425
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800426 kfree(variax->buffer_activate);
Markus Grabner705ecec2009-02-27 19:43:04 -0800427 del_timer_sync(&variax->activate_timer);
428}
429
430/*
431 Create sysfs entries.
432*/
Greg Kroah-Hartmanb702ed252009-02-27 20:45:03 -0800433static int variax_create_files2(struct device *dev)
Markus Grabner705ecec2009-02-27 19:43:04 -0800434{
435 int err;
436 CHECK_RETURN(device_create_file(dev, &dev_attr_model));
437 CHECK_RETURN(device_create_file(dev, &dev_attr_volume));
438 CHECK_RETURN(device_create_file(dev, &dev_attr_tone));
439 CHECK_RETURN(device_create_file(dev, &dev_attr_name));
440 CHECK_RETURN(device_create_file(dev, &dev_attr_bank));
441 CHECK_RETURN(device_create_file(dev, &dev_attr_dump));
442 CHECK_RETURN(device_create_file(dev, &dev_attr_active));
443#if CREATE_RAW_FILE
444 CHECK_RETURN(device_create_file(dev, &dev_attr_raw));
445 CHECK_RETURN(device_create_file(dev, &dev_attr_raw2));
446#endif
447 return 0;
448}
449
450/*
451 Init workbench device.
452*/
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800453int variax_init(struct usb_interface *interface,
454 struct usb_line6_variax *variax)
Markus Grabner705ecec2009-02-27 19:43:04 -0800455{
456 int err;
457
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800458 if ((interface == NULL) || (variax == NULL))
459 return -ENODEV;
Markus Grabner705ecec2009-02-27 19:43:04 -0800460
461 /* initialize USB buffers: */
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800462 err = line6_dumpreq_init(&variax->dumpreq, variax_request_model1,
463 sizeof(variax_request_model1));
Markus Grabner705ecec2009-02-27 19:43:04 -0800464
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800465 if (err < 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800466 dev_err(&interface->dev, "Out of memory\n");
467 variax_destruct(interface);
468 return err;
469 }
470
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800471 err = line6_dumpreq_initbuf(&variax->dumpreq, variax_request_model2,
472 sizeof(variax_request_model2), 1);
Markus Grabner705ecec2009-02-27 19:43:04 -0800473
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800474 if (err < 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800475 dev_err(&interface->dev, "Out of memory\n");
476 variax_destruct(interface);
477 return err;
478 }
479
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800480 err = line6_dumpreq_initbuf(&variax->dumpreq, variax_request_bank,
481 sizeof(variax_request_bank), 2);
Markus Grabner705ecec2009-02-27 19:43:04 -0800482
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800483 if (err < 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800484 dev_err(&interface->dev, "Out of memory\n");
485 variax_destruct(interface);
486 return err;
487 }
488
Julia Lawall94002c02010-05-15 23:21:43 +0200489 variax->buffer_activate = kmemdup(variax_activate,
490 sizeof(variax_activate), GFP_KERNEL);
Markus Grabner705ecec2009-02-27 19:43:04 -0800491
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800492 if (variax->buffer_activate == NULL) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800493 dev_err(&interface->dev, "Out of memory\n");
494 variax_destruct(interface);
495 return -ENOMEM;
496 }
497
Markus Grabner705ecec2009-02-27 19:43:04 -0800498 init_timer(&variax->activate_timer);
499
500 /* create sysfs entries: */
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800501 err = variax_create_files(0, 0, &interface->dev);
502 if (err < 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800503 variax_destruct(interface);
504 return err;
505 }
506
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800507 err = variax_create_files2(&interface->dev);
508 if (err < 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800509 variax_destruct(interface);
510 return err;
511 }
512
513 /* initialize audio system: */
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800514 err = line6_init_audio(&variax->line6);
515 if (err < 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800516 variax_destruct(interface);
517 return err;
518 }
519
520 /* initialize MIDI subsystem: */
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800521 err = line6_init_midi(&variax->line6);
522 if (err < 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800523 variax_destruct(interface);
524 return err;
525 }
526
527 /* register audio system: */
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800528 err = line6_register_audio(&variax->line6);
529 if (err < 0) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800530 variax_destruct(interface);
531 return err;
532 }
533
534 variax_activate_delayed(variax, VARIAX_ACTIVATE_DELAY);
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800535 line6_startup_delayed(&variax->dumpreq, VARIAX_STARTUP_DELAY,
536 variax_startup_timeout, variax);
Markus Grabner705ecec2009-02-27 19:43:04 -0800537 return 0;
538}
539
540/*
541 Workbench device disconnected.
542*/
543void variax_disconnect(struct usb_interface *interface)
544{
545 struct device *dev;
546
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800547 if (interface == NULL)
548 return;
Markus Grabner705ecec2009-02-27 19:43:04 -0800549 dev = &interface->dev;
550
Greg Kroah-Hartman9cd57f72009-02-27 22:43:57 -0800551 if (dev != NULL) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800552 /* remove sysfs entries: */
553 variax_remove_files(0, 0, dev);
554 device_remove_file(dev, &dev_attr_model);
555 device_remove_file(dev, &dev_attr_volume);
556 device_remove_file(dev, &dev_attr_tone);
557 device_remove_file(dev, &dev_attr_name);
558 device_remove_file(dev, &dev_attr_bank);
559 device_remove_file(dev, &dev_attr_dump);
560 device_remove_file(dev, &dev_attr_active);
561#if CREATE_RAW_FILE
562 device_remove_file(dev, &dev_attr_raw);
563 device_remove_file(dev, &dev_attr_raw2);
564#endif
565 }
566
567 variax_destruct(interface);
568}