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/wait.h>
14 #include <linux/interrupt.h>
15 #include <linux/module.h>
16 #include <linux/usb.h>
18 #include <sound/core.h>
19 #include <sound/control.h>
26 Locate name in binary program dump
28 #define POD_NAME_OFFSET 0
29 #define POD_NAME_LENGTH 16
34 #define POD_CONTROL_SIZE 0x80
35 #define POD_BUFSIZE_DUMPREQ 7
36 #define POD_STARTUP_DELAY 1000
39 Stages of POD startup procedure
43 POD_STARTUP_VERSIONREQ
,
44 POD_STARTUP_WORKQUEUE
,
46 POD_STARTUP_LAST
= POD_STARTUP_SETUP
- 1
59 struct usb_line6_pod
{
60 /* Generic Line 6 USB data */
61 struct usb_line6 line6
;
63 /* Instrument monitor level */
66 /* Timer for device initialization */
67 struct timer_list startup_timer
;
69 /* Work handler for device initialization */
70 struct work_struct startup_work
;
72 /* Current progress in startup procedure */
75 /* Serial number of device */
78 /* Firmware version (x 100) */
85 #define POD_SYSEX_CODE 3
90 POD_SYSEX_SAVE
= 0x24,
91 POD_SYSEX_SYSTEM
= 0x56,
92 POD_SYSEX_SYSTEMREQ
= 0x57,
93 /* POD_SYSEX_UPDATE = 0x6c, */ /* software update! */
94 POD_SYSEX_STORE
= 0x71,
95 POD_SYSEX_FINISH
= 0x72,
96 POD_SYSEX_DUMPMEM
= 0x73,
97 POD_SYSEX_DUMP
= 0x74,
98 POD_SYSEX_DUMPREQ
= 0x75
100 /* dumps entire internal memory of PODxt Pro */
101 /* POD_SYSEX_DUMPMEM2 = 0x76 */
105 POD_MONITOR_LEVEL
= 0x04,
106 POD_SYSTEM_INVALID
= 0x10000
123 static struct snd_ratden pod_ratden
= {
130 static struct line6_pcm_properties pod_pcm_properties
= {
132 .info
= (SNDRV_PCM_INFO_MMAP
|
133 SNDRV_PCM_INFO_INTERLEAVED
|
134 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
135 SNDRV_PCM_INFO_MMAP_VALID
|
136 SNDRV_PCM_INFO_PAUSE
|
137 SNDRV_PCM_INFO_SYNC_START
),
138 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
139 .rates
= SNDRV_PCM_RATE_KNOT
,
144 .buffer_bytes_max
= 60000,
145 .period_bytes_min
= 64,
146 .period_bytes_max
= 8192,
148 .periods_max
= 1024},
150 .info
= (SNDRV_PCM_INFO_MMAP
|
151 SNDRV_PCM_INFO_INTERLEAVED
|
152 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
153 SNDRV_PCM_INFO_MMAP_VALID
|
154 SNDRV_PCM_INFO_SYNC_START
),
155 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
156 .rates
= SNDRV_PCM_RATE_KNOT
,
161 .buffer_bytes_max
= 60000,
162 .period_bytes_min
= 64,
163 .period_bytes_max
= 8192,
165 .periods_max
= 1024},
168 .rats
= &pod_ratden
},
169 .bytes_per_channel
= 3 /* SNDRV_PCM_FMTBIT_S24_3LE */
172 static const char pod_version_header
[] = {
173 0xf2, 0x7e, 0x7f, 0x06, 0x02
176 /* forward declarations: */
177 static void pod_startup2(unsigned long data
);
178 static void pod_startup3(struct usb_line6_pod
*pod
);
180 static char *pod_alloc_sysex_buffer(struct usb_line6_pod
*pod
, int code
,
183 return line6_alloc_sysex_buffer(&pod
->line6
, POD_SYSEX_CODE
, code
,
188 Process a completely received message.
190 static void line6_pod_process_message(struct usb_line6
*line6
)
192 struct usb_line6_pod
*pod
= (struct usb_line6_pod
*) line6
;
193 const unsigned char *buf
= pod
->line6
.buffer_message
;
195 if (memcmp(buf
, pod_version_header
, sizeof(pod_version_header
)) == 0) {
196 pod
->firmware_version
= buf
[13] * 100 + buf
[14] * 10 + buf
[15];
197 pod
->device_id
= ((int)buf
[8] << 16) | ((int)buf
[9] << 8) |
203 /* Only look for sysex messages from this device */
204 if (buf
[0] != (LINE6_SYSEX_BEGIN
| LINE6_CHANNEL_DEVICE
) &&
205 buf
[0] != (LINE6_SYSEX_BEGIN
| LINE6_CHANNEL_UNKNOWN
)) {
208 if (memcmp(buf
+ 1, line6_midi_id
, sizeof(line6_midi_id
)) != 0)
211 if (buf
[5] == POD_SYSEX_SYSTEM
&& buf
[6] == POD_MONITOR_LEVEL
) {
212 short value
= ((int)buf
[7] << 12) | ((int)buf
[8] << 8) |
213 ((int)buf
[9] << 4) | (int)buf
[10];
214 pod
->monitor_level
= value
;
219 Send system parameter (from integer).
221 static int pod_set_system_param_int(struct usb_line6_pod
*pod
, int value
,
225 static const int size
= 5;
227 sysex
= pod_alloc_sysex_buffer(pod
, POD_SYSEX_SYSTEM
, size
);
230 sysex
[SYSEX_DATA_OFS
] = code
;
231 sysex
[SYSEX_DATA_OFS
+ 1] = (value
>> 12) & 0x0f;
232 sysex
[SYSEX_DATA_OFS
+ 2] = (value
>> 8) & 0x0f;
233 sysex
[SYSEX_DATA_OFS
+ 3] = (value
>> 4) & 0x0f;
234 sysex
[SYSEX_DATA_OFS
+ 4] = (value
) & 0x0f;
235 line6_send_sysex_message(&pod
->line6
, sysex
, size
);
241 "read" request on "serial_number" special file.
243 static ssize_t
serial_number_show(struct device
*dev
,
244 struct device_attribute
*attr
, char *buf
)
246 struct snd_card
*card
= dev_to_snd_card(dev
);
247 struct usb_line6_pod
*pod
= card
->private_data
;
249 return sprintf(buf
, "%u\n", pod
->serial_number
);
253 "read" request on "firmware_version" special file.
255 static ssize_t
firmware_version_show(struct device
*dev
,
256 struct device_attribute
*attr
, char *buf
)
258 struct snd_card
*card
= dev_to_snd_card(dev
);
259 struct usb_line6_pod
*pod
= card
->private_data
;
261 return sprintf(buf
, "%d.%02d\n", pod
->firmware_version
/ 100,
262 pod
->firmware_version
% 100);
266 "read" request on "device_id" special file.
268 static ssize_t
device_id_show(struct device
*dev
,
269 struct device_attribute
*attr
, char *buf
)
271 struct snd_card
*card
= dev_to_snd_card(dev
);
272 struct usb_line6_pod
*pod
= card
->private_data
;
274 return sprintf(buf
, "%d\n", pod
->device_id
);
278 POD startup procedure.
279 This is a sequence of functions with special requirements (e.g., must
280 not run immediately after initialization, must not run in interrupt
281 context). After the last one has finished, the device is ready to use.
284 static void pod_startup1(struct usb_line6_pod
*pod
)
286 CHECK_STARTUP_PROGRESS(pod
->startup_progress
, POD_STARTUP_INIT
);
288 /* delay startup procedure: */
289 line6_start_timer(&pod
->startup_timer
, POD_STARTUP_DELAY
, pod_startup2
,
293 static void pod_startup2(unsigned long data
)
295 struct usb_line6_pod
*pod
= (struct usb_line6_pod
*)data
;
296 struct usb_line6
*line6
= &pod
->line6
;
298 CHECK_STARTUP_PROGRESS(pod
->startup_progress
, POD_STARTUP_VERSIONREQ
);
300 /* request firmware version: */
301 line6_version_request_async(line6
);
304 static void pod_startup3(struct usb_line6_pod
*pod
)
306 CHECK_STARTUP_PROGRESS(pod
->startup_progress
, POD_STARTUP_WORKQUEUE
);
308 /* schedule work for global work queue: */
309 schedule_work(&pod
->startup_work
);
312 static void pod_startup4(struct work_struct
*work
)
314 struct usb_line6_pod
*pod
=
315 container_of(work
, struct usb_line6_pod
, startup_work
);
316 struct usb_line6
*line6
= &pod
->line6
;
318 CHECK_STARTUP_PROGRESS(pod
->startup_progress
, POD_STARTUP_SETUP
);
321 line6_read_serial_number(&pod
->line6
, &pod
->serial_number
);
323 /* ALSA audio interface: */
324 snd_card_register(line6
->card
);
327 /* POD special files: */
328 static DEVICE_ATTR_RO(device_id
);
329 static DEVICE_ATTR_RO(firmware_version
);
330 static DEVICE_ATTR_RO(serial_number
);
332 static struct attribute
*pod_dev_attrs
[] = {
333 &dev_attr_device_id
.attr
,
334 &dev_attr_firmware_version
.attr
,
335 &dev_attr_serial_number
.attr
,
339 static const struct attribute_group pod_dev_attr_group
= {
341 .attrs
= pod_dev_attrs
,
344 /* control info callback */
345 static int snd_pod_control_monitor_info(struct snd_kcontrol
*kcontrol
,
346 struct snd_ctl_elem_info
*uinfo
)
348 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
350 uinfo
->value
.integer
.min
= 0;
351 uinfo
->value
.integer
.max
= 65535;
355 /* control get callback */
356 static int snd_pod_control_monitor_get(struct snd_kcontrol
*kcontrol
,
357 struct snd_ctl_elem_value
*ucontrol
)
359 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
360 struct usb_line6_pod
*pod
= (struct usb_line6_pod
*)line6pcm
->line6
;
362 ucontrol
->value
.integer
.value
[0] = pod
->monitor_level
;
366 /* control put callback */
367 static int snd_pod_control_monitor_put(struct snd_kcontrol
*kcontrol
,
368 struct snd_ctl_elem_value
*ucontrol
)
370 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
371 struct usb_line6_pod
*pod
= (struct usb_line6_pod
*)line6pcm
->line6
;
373 if (ucontrol
->value
.integer
.value
[0] == pod
->monitor_level
)
376 pod
->monitor_level
= ucontrol
->value
.integer
.value
[0];
377 pod_set_system_param_int(pod
, ucontrol
->value
.integer
.value
[0],
382 /* control definition */
383 static const struct snd_kcontrol_new pod_control_monitor
= {
384 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
385 .name
= "Monitor Playback Volume",
387 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
388 .info
= snd_pod_control_monitor_info
,
389 .get
= snd_pod_control_monitor_get
,
390 .put
= snd_pod_control_monitor_put
394 POD device disconnected.
396 static void line6_pod_disconnect(struct usb_line6
*line6
)
398 struct usb_line6_pod
*pod
= (struct usb_line6_pod
*)line6
;
400 del_timer_sync(&pod
->startup_timer
);
401 cancel_work_sync(&pod
->startup_work
);
405 Try to init POD device.
407 static int pod_init(struct usb_line6
*line6
,
408 const struct usb_device_id
*id
)
411 struct usb_line6_pod
*pod
= (struct usb_line6_pod
*) line6
;
413 line6
->process_message
= line6_pod_process_message
;
414 line6
->disconnect
= line6_pod_disconnect
;
416 init_timer(&pod
->startup_timer
);
417 INIT_WORK(&pod
->startup_work
, pod_startup4
);
419 /* create sysfs entries: */
420 err
= snd_card_add_dev_attr(line6
->card
, &pod_dev_attr_group
);
424 /* initialize MIDI subsystem: */
425 err
= line6_init_midi(line6
);
429 /* initialize PCM subsystem: */
430 err
= line6_init_pcm(line6
, &pod_pcm_properties
);
434 /* register monitor control: */
435 err
= snd_ctl_add(line6
->card
,
436 snd_ctl_new1(&pod_control_monitor
, line6
->line6pcm
));
441 When the sound card is registered at this point, the PODxt Live
442 displays "Invalid Code Error 07", so we do it later in the event
446 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL
) {
447 pod
->monitor_level
= POD_SYSTEM_INVALID
;
449 /* initiate startup procedure: */
456 #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
457 #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
459 /* table of devices that work with this driver */
460 static const struct usb_device_id pod_id_table
[] = {
461 { LINE6_DEVICE(0x4250), .driver_info
= LINE6_BASSPODXT
},
462 { LINE6_DEVICE(0x4642), .driver_info
= LINE6_BASSPODXTLIVE
},
463 { LINE6_DEVICE(0x4252), .driver_info
= LINE6_BASSPODXTPRO
},
464 { LINE6_IF_NUM(0x5051, 1), .driver_info
= LINE6_POCKETPOD
},
465 { LINE6_DEVICE(0x5044), .driver_info
= LINE6_PODXT
},
466 { LINE6_IF_NUM(0x4650, 0), .driver_info
= LINE6_PODXTLIVE_POD
},
467 { LINE6_DEVICE(0x5050), .driver_info
= LINE6_PODXTPRO
},
471 MODULE_DEVICE_TABLE(usb
, pod_id_table
);
473 static const struct line6_properties pod_properties_table
[] = {
474 [LINE6_BASSPODXT
] = {
477 .capabilities
= LINE6_CAP_CONTROL
478 | LINE6_CAP_CONTROL_MIDI
487 [LINE6_BASSPODXTLIVE
] = {
488 .id
= "BassPODxtLive",
489 .name
= "BassPODxt Live",
490 .capabilities
= LINE6_CAP_CONTROL
491 | LINE6_CAP_CONTROL_MIDI
500 [LINE6_BASSPODXTPRO
] = {
501 .id
= "BassPODxtPro",
502 .name
= "BassPODxt Pro",
503 .capabilities
= LINE6_CAP_CONTROL
504 | LINE6_CAP_CONTROL_MIDI
513 [LINE6_POCKETPOD
] = {
515 .name
= "Pocket POD",
516 .capabilities
= LINE6_CAP_CONTROL
517 | LINE6_CAP_CONTROL_MIDI
,
521 /* no audio channel */
526 .capabilities
= LINE6_CAP_CONTROL
527 | LINE6_CAP_CONTROL_MIDI
536 [LINE6_PODXTLIVE_POD
] = {
538 .name
= "PODxt Live",
539 .capabilities
= LINE6_CAP_CONTROL
540 | LINE6_CAP_CONTROL_MIDI
552 .capabilities
= LINE6_CAP_CONTROL
553 | LINE6_CAP_CONTROL_MIDI
567 static int pod_probe(struct usb_interface
*interface
,
568 const struct usb_device_id
*id
)
570 return line6_probe(interface
, id
, "Line6-POD",
571 &pod_properties_table
[id
->driver_info
],
572 pod_init
, sizeof(struct usb_line6_pod
));
575 static struct usb_driver pod_driver
= {
576 .name
= KBUILD_MODNAME
,
578 .disconnect
= line6_disconnect
,
580 .suspend
= line6_suspend
,
581 .resume
= line6_resume
,
582 .reset_resume
= line6_resume
,
584 .id_table
= pod_id_table
,
587 module_usb_driver(pod_driver
);
589 MODULE_DESCRIPTION("Line 6 POD USB driver");
590 MODULE_LICENSE("GPL");