2 * Line6 Linux USB driver - 0.9.1beta
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>
28 Locate name in binary program dump
30 #define POD_NAME_OFFSET 0
31 #define POD_NAME_LENGTH 16
36 #define POD_CONTROL_SIZE 0x80
37 #define POD_BUFSIZE_DUMPREQ 7
38 #define POD_STARTUP_DELAY 1000
41 Stages of POD startup procedure
45 POD_STARTUP_VERSIONREQ,
46 POD_STARTUP_WORKQUEUE,
48 POD_STARTUP_LAST = POD_STARTUP_SETUP - 1
61 struct usb_line6_pod {
63 Generic Line6 USB data.
65 struct usb_line6 line6;
68 Instrument monitor level.
73 Timer for device initializaton.
75 struct timer_list startup_timer;
78 Work handler for device initializaton.
80 struct work_struct startup_work;
83 Current progress in startup procedure.
88 Serial number of device.
93 Firmware version (x 100).
103 #define POD_SYSEX_CODE 3
104 #define POD_BYTES_PER_FRAME 6 /* 24bit audio (stereo) */
109 POD_SYSEX_SAVE = 0x24,
110 POD_SYSEX_SYSTEM = 0x56,
111 POD_SYSEX_SYSTEMREQ = 0x57,
112 /* POD_SYSEX_UPDATE = 0x6c, */ /* software update! */
113 POD_SYSEX_STORE = 0x71,
114 POD_SYSEX_FINISH = 0x72,
115 POD_SYSEX_DUMPMEM = 0x73,
116 POD_SYSEX_DUMP = 0x74,
117 POD_SYSEX_DUMPREQ = 0x75
119 /* dumps entire internal memory of PODxt Pro */
120 /* POD_SYSEX_DUMPMEM2 = 0x76 */
124 POD_MONITOR_LEVEL = 0x04,
125 POD_SYSTEM_INVALID = 0x10000
142 static struct snd_ratden pod_ratden = {
149 static struct line6_pcm_properties pod_pcm_properties = {
150 .snd_line6_playback_hw = {
151 .info = (SNDRV_PCM_INFO_MMAP |
152 SNDRV_PCM_INFO_INTERLEAVED |
153 SNDRV_PCM_INFO_BLOCK_TRANSFER |
154 SNDRV_PCM_INFO_MMAP_VALID |
155 SNDRV_PCM_INFO_PAUSE |
157 SNDRV_PCM_INFO_RESUME |
159 SNDRV_PCM_INFO_SYNC_START),
160 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
161 .rates = SNDRV_PCM_RATE_KNOT,
166 .buffer_bytes_max = 60000,
167 .period_bytes_min = 64,
168 .period_bytes_max = 8192,
170 .periods_max = 1024},
171 .snd_line6_capture_hw = {
172 .info = (SNDRV_PCM_INFO_MMAP |
173 SNDRV_PCM_INFO_INTERLEAVED |
174 SNDRV_PCM_INFO_BLOCK_TRANSFER |
175 SNDRV_PCM_INFO_MMAP_VALID |
177 SNDRV_PCM_INFO_RESUME |
179 SNDRV_PCM_INFO_SYNC_START),
180 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
181 .rates = SNDRV_PCM_RATE_KNOT,
186 .buffer_bytes_max = 60000,
187 .period_bytes_min = 64,
188 .period_bytes_max = 8192,
190 .periods_max = 1024},
193 .rats = &pod_ratden},
194 .bytes_per_frame = POD_BYTES_PER_FRAME
197 static const char pod_version_header[] = {
198 0xf2, 0x7e, 0x7f, 0x06, 0x02
201 /* forward declarations: */
202 static void pod_startup2(unsigned long data);
203 static void pod_startup3(struct usb_line6_pod *pod);
205 static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code,
208 return line6_alloc_sysex_buffer(&pod->line6, POD_SYSEX_CODE, code,
213 Process a completely received message.
215 static void line6_pod_process_message(struct usb_line6 *line6)
217 struct usb_line6_pod *pod = (struct usb_line6_pod *) line6;
218 const unsigned char *buf = pod->line6.buffer_message;
220 if (memcmp(buf, pod_version_header, sizeof(pod_version_header)) == 0) {
221 pod->firmware_version = buf[13] * 100 + buf[14] * 10 + buf[15];
222 pod->device_id = ((int)buf[8] << 16) | ((int)buf[9] << 8) |
228 /* Only look for sysex messages from this device */
229 if (buf[0] != (LINE6_SYSEX_BEGIN | LINE6_CHANNEL_DEVICE) &&
230 buf[0] != (LINE6_SYSEX_BEGIN | LINE6_CHANNEL_UNKNOWN)) {
233 if (memcmp(buf + 1, line6_midi_id, sizeof(line6_midi_id)) != 0)
236 if (buf[5] == POD_SYSEX_SYSTEM && buf[6] == POD_MONITOR_LEVEL) {
237 short value = ((int)buf[7] << 12) | ((int)buf[8] << 8) |
238 ((int)buf[9] << 4) | (int)buf[10];
239 pod->monitor_level = value;
244 Send system parameter (from integer).
246 static int pod_set_system_param_int(struct usb_line6_pod *pod, int value,
250 static const int size = 5;
252 sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEM, size);
255 sysex[SYSEX_DATA_OFS] = code;
256 sysex[SYSEX_DATA_OFS + 1] = (value >> 12) & 0x0f;
257 sysex[SYSEX_DATA_OFS + 2] = (value >> 8) & 0x0f;
258 sysex[SYSEX_DATA_OFS + 3] = (value >> 4) & 0x0f;
259 sysex[SYSEX_DATA_OFS + 4] = (value) & 0x0f;
260 line6_send_sysex_message(&pod->line6, sysex, size);
266 "read" request on "serial_number" special file.
268 static ssize_t serial_number_show(struct device *dev,
269 struct device_attribute *attr, char *buf)
271 struct usb_interface *interface = to_usb_interface(dev);
272 struct usb_line6_pod *pod = usb_get_intfdata(interface);
274 return sprintf(buf, "%d\n", pod->serial_number);
278 "read" request on "firmware_version" special file.
280 static ssize_t firmware_version_show(struct device *dev,
281 struct device_attribute *attr, char *buf)
283 struct usb_interface *interface = to_usb_interface(dev);
284 struct usb_line6_pod *pod = usb_get_intfdata(interface);
286 return sprintf(buf, "%d.%02d\n", pod->firmware_version / 100,
287 pod->firmware_version % 100);
291 "read" request on "device_id" special file.
293 static ssize_t device_id_show(struct device *dev,
294 struct device_attribute *attr, char *buf)
296 struct usb_interface *interface = to_usb_interface(dev);
297 struct usb_line6_pod *pod = usb_get_intfdata(interface);
299 return sprintf(buf, "%d\n", pod->device_id);
303 POD startup procedure.
304 This is a sequence of functions with special requirements (e.g., must
305 not run immediately after initialization, must not run in interrupt
306 context). After the last one has finished, the device is ready to use.
309 static void pod_startup1(struct usb_line6_pod *pod)
311 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_INIT);
313 /* delay startup procedure: */
314 line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2,
318 static void pod_startup2(unsigned long data)
320 struct usb_line6_pod *pod = (struct usb_line6_pod *)data;
321 struct usb_line6 *line6 = &pod->line6;
323 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_VERSIONREQ);
325 /* request firmware version: */
326 line6_version_request_async(line6);
329 static void pod_startup3(struct usb_line6_pod *pod)
331 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_WORKQUEUE);
333 /* schedule work for global work queue: */
334 schedule_work(&pod->startup_work);
337 static void pod_startup4(struct work_struct *work)
339 struct usb_line6_pod *pod =
340 container_of(work, struct usb_line6_pod, startup_work);
341 struct usb_line6 *line6 = &pod->line6;
343 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_SETUP);
346 line6_read_serial_number(&pod->line6, &pod->serial_number);
348 /* ALSA audio interface: */
349 line6_register_audio(line6);
352 /* POD special files: */
353 static DEVICE_ATTR_RO(device_id);
354 static DEVICE_ATTR_RO(firmware_version);
355 static DEVICE_ATTR_RO(serial_number);
357 /* control info callback */
358 static int snd_pod_control_monitor_info(struct snd_kcontrol *kcontrol,
359 struct snd_ctl_elem_info *uinfo)
361 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
363 uinfo->value.integer.min = 0;
364 uinfo->value.integer.max = 65535;
368 /* control get callback */
369 static int snd_pod_control_monitor_get(struct snd_kcontrol *kcontrol,
370 struct snd_ctl_elem_value *ucontrol)
372 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
373 struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6;
375 ucontrol->value.integer.value[0] = pod->monitor_level;
379 /* control put callback */
380 static int snd_pod_control_monitor_put(struct snd_kcontrol *kcontrol,
381 struct snd_ctl_elem_value *ucontrol)
383 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
384 struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6;
386 if (ucontrol->value.integer.value[0] == pod->monitor_level)
389 pod->monitor_level = ucontrol->value.integer.value[0];
390 pod_set_system_param_int(pod, ucontrol->value.integer.value[0],
395 /* control definition */
396 static struct snd_kcontrol_new pod_control_monitor = {
397 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
398 .name = "Monitor Playback Volume",
400 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
401 .info = snd_pod_control_monitor_info,
402 .get = snd_pod_control_monitor_get,
403 .put = snd_pod_control_monitor_put
409 static void pod_destruct(struct usb_interface *interface)
411 struct usb_line6_pod *pod = usb_get_intfdata(interface);
415 line6_cleanup_audio(&pod->line6);
417 del_timer(&pod->startup_timer);
418 cancel_work_sync(&pod->startup_work);
422 POD device disconnected.
424 static void line6_pod_disconnect(struct usb_interface *interface)
426 struct usb_line6_pod *pod;
428 if (interface == NULL)
430 pod = usb_get_intfdata(interface);
433 struct snd_line6_pcm *line6pcm = pod->line6.line6pcm;
434 struct device *dev = &interface->dev;
436 if (line6pcm != NULL)
437 line6_pcm_disconnect(line6pcm);
440 /* remove sysfs entries: */
441 device_remove_file(dev, &dev_attr_device_id);
442 device_remove_file(dev, &dev_attr_firmware_version);
443 device_remove_file(dev, &dev_attr_serial_number);
447 pod_destruct(interface);
451 Create sysfs entries.
453 static int pod_create_files2(struct device *dev)
457 CHECK_RETURN(device_create_file(dev, &dev_attr_device_id));
458 CHECK_RETURN(device_create_file(dev, &dev_attr_firmware_version));
459 CHECK_RETURN(device_create_file(dev, &dev_attr_serial_number));
464 Try to init POD device.
466 static int pod_try_init(struct usb_interface *interface,
467 struct usb_line6 *line6)
470 struct usb_line6_pod *pod = (struct usb_line6_pod *) line6;
472 line6->process_message = line6_pod_process_message;
473 line6->disconnect = line6_pod_disconnect;
475 init_timer(&pod->startup_timer);
476 INIT_WORK(&pod->startup_work, pod_startup4);
478 if ((interface == NULL) || (pod == NULL))
481 /* create sysfs entries: */
482 err = pod_create_files2(&interface->dev);
486 /* initialize audio system: */
487 err = line6_init_audio(line6);
491 /* initialize MIDI subsystem: */
492 err = line6_init_midi(line6);
496 /* initialize PCM subsystem: */
497 err = line6_init_pcm(line6, &pod_pcm_properties);
501 /* register monitor control: */
502 err = snd_ctl_add(line6->card,
503 snd_ctl_new1(&pod_control_monitor, line6->line6pcm));
508 When the sound card is registered at this point, the PODxt Live
509 displays "Invalid Code Error 07", so we do it later in the event
513 if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL) {
514 pod->monitor_level = POD_SYSTEM_INVALID;
516 /* initiate startup procedure: */
524 Init POD device (and clean up in case of failure).
526 static int pod_init(struct usb_interface *interface,
527 struct usb_line6 *line6)
529 int err = pod_try_init(interface, line6);
532 pod_destruct(interface);
537 #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
538 #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
540 /* table of devices that work with this driver */
541 static const struct usb_device_id pod_id_table[] = {
542 { LINE6_DEVICE(0x4250), .driver_info = LINE6_BASSPODXT },
543 { LINE6_DEVICE(0x4642), .driver_info = LINE6_BASSPODXTLIVE },
544 { LINE6_DEVICE(0x4252), .driver_info = LINE6_BASSPODXTPRO },
545 { LINE6_IF_NUM(0x5051, 1), .driver_info = LINE6_POCKETPOD },
546 { LINE6_DEVICE(0x5044), .driver_info = LINE6_PODXT },
547 { LINE6_IF_NUM(0x4650, 0), .driver_info = LINE6_PODXTLIVE_POD },
548 { LINE6_DEVICE(0x5050), .driver_info = LINE6_PODXTPRO },
552 MODULE_DEVICE_TABLE(usb, pod_id_table);
554 static const struct line6_properties pod_properties_table[] = {
555 [LINE6_BASSPODXT] = {
558 .capabilities = LINE6_CAP_CONTROL
567 [LINE6_BASSPODXTLIVE] = {
568 .id = "BassPODxtLive",
569 .name = "BassPODxt Live",
570 .capabilities = LINE6_CAP_CONTROL
579 [LINE6_BASSPODXTPRO] = {
580 .id = "BassPODxtPro",
581 .name = "BassPODxt Pro",
582 .capabilities = LINE6_CAP_CONTROL
591 [LINE6_POCKETPOD] = {
593 .name = "Pocket POD",
594 .capabilities = LINE6_CAP_CONTROL,
598 /* no audio channel */
603 .capabilities = LINE6_CAP_CONTROL
612 [LINE6_PODXTLIVE_POD] = {
614 .name = "PODxt Live",
615 .capabilities = LINE6_CAP_CONTROL
627 .capabilities = LINE6_CAP_CONTROL
641 static int pod_probe(struct usb_interface *interface,
642 const struct usb_device_id *id)
644 struct usb_line6_pod *pod;
647 pod = kzalloc(sizeof(*pod), GFP_KERNEL);
650 err = line6_probe(interface, &pod->line6,
651 &pod_properties_table[id->driver_info],
658 static struct usb_driver pod_driver = {
659 .name = KBUILD_MODNAME,
661 .disconnect = line6_disconnect,
663 .suspend = line6_suspend,
664 .resume = line6_resume,
665 .reset_resume = line6_resume,
667 .id_table = pod_id_table,
670 module_usb_driver(pod_driver);
672 MODULE_DESCRIPTION("Line6 POD USB driver");
673 MODULE_LICENSE("GPL");