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 <sound/control.h>
22 #define POD_SYSEX_CODE 3
23 #define POD_BYTES_PER_FRAME 6 /* 24bit audio (stereo) */
28 POD_SYSEX_SAVE = 0x24,
29 POD_SYSEX_SYSTEM = 0x56,
30 POD_SYSEX_SYSTEMREQ = 0x57,
31 /* POD_SYSEX_UPDATE = 0x6c, */ /* software update! */
32 POD_SYSEX_STORE = 0x71,
33 POD_SYSEX_FINISH = 0x72,
34 POD_SYSEX_DUMPMEM = 0x73,
35 POD_SYSEX_DUMP = 0x74,
36 POD_SYSEX_DUMPREQ = 0x75
37 /* POD_SYSEX_DUMPMEM2 = 0x76 */ /* dumps entire internal memory of PODxt Pro */
41 POD_monitor_level = 0x04,
42 POD_system_invalid = 0x10000
59 static struct snd_ratden pod_ratden = {
66 static struct line6_pcm_properties pod_pcm_properties = {
67 .snd_line6_playback_hw = {
68 .info = (SNDRV_PCM_INFO_MMAP |
69 SNDRV_PCM_INFO_INTERLEAVED |
70 SNDRV_PCM_INFO_BLOCK_TRANSFER |
71 SNDRV_PCM_INFO_MMAP_VALID |
72 SNDRV_PCM_INFO_PAUSE |
74 SNDRV_PCM_INFO_RESUME |
76 SNDRV_PCM_INFO_SYNC_START),
77 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
78 .rates = SNDRV_PCM_RATE_KNOT,
83 .buffer_bytes_max = 60000,
84 .period_bytes_min = 64,
85 .period_bytes_max = 8192,
88 .snd_line6_capture_hw = {
89 .info = (SNDRV_PCM_INFO_MMAP |
90 SNDRV_PCM_INFO_INTERLEAVED |
91 SNDRV_PCM_INFO_BLOCK_TRANSFER |
92 SNDRV_PCM_INFO_MMAP_VALID |
94 SNDRV_PCM_INFO_RESUME |
96 SNDRV_PCM_INFO_SYNC_START),
97 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
98 .rates = SNDRV_PCM_RATE_KNOT,
103 .buffer_bytes_max = 60000,
104 .period_bytes_min = 64,
105 .period_bytes_max = 8192,
107 .periods_max = 1024},
110 .rats = &pod_ratden},
111 .bytes_per_frame = POD_BYTES_PER_FRAME
114 static const char pod_request_channel[] = {
115 0xf0, 0x00, 0x01, 0x0c, 0x03, 0x75, 0xf7
118 static const char pod_version_header[] = {
119 0xf2, 0x7e, 0x7f, 0x06, 0x02
122 /* forward declarations: */
123 static void pod_startup2(unsigned long data);
124 static void pod_startup3(struct usb_line6_pod *pod);
125 static void pod_startup4(struct usb_line6_pod *pod);
127 static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code,
130 return line6_alloc_sysex_buffer(&pod->line6, POD_SYSEX_CODE, code,
137 static void pod_save_button_pressed(struct usb_line6_pod *pod, int type,
140 set_bit(POD_SAVE_PRESSED, &pod->atomic_flags);
144 Process a completely received message.
146 void line6_pod_process_message(struct usb_line6_pod *pod)
148 const unsigned char *buf = pod->line6.buffer_message;
150 /* filter messages by type */
151 switch (buf[0] & 0xf0) {
152 case LINE6_PARAM_CHANGE:
153 case LINE6_PROGRAM_CHANGE:
154 case LINE6_SYSEX_BEGIN:
155 break; /* handle these further down */
158 return; /* ignore all others */
161 /* process all remaining messages */
163 case LINE6_PARAM_CHANGE | LINE6_CHANNEL_DEVICE:
164 case LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST:
167 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_DEVICE:
168 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST:
169 set_bit(POD_CHANNEL_DIRTY, &pod->atomic_flags);
170 line6_dump_request_async(&pod->dumpreq, &pod->line6, 0,
174 case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_DEVICE:
175 case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_UNKNOWN:
176 if (memcmp(buf + 1, line6_midi_id, sizeof(line6_midi_id)) == 0) {
179 line6_dump_finished(&pod->dumpreq);
183 case POD_SYSEX_SYSTEM:{
185 ((int)buf[7] << 12) | ((int)buf[8]
187 ((int)buf[9] << 4) | (int)buf[10];
189 if (buf[6] == POD_monitor_level)
190 pod->monitor_level = value;
194 case POD_SYSEX_FINISH:
195 /* do we need to respond to this? */
199 pod_save_button_pressed(pod, buf[6], buf[7]);
202 case POD_SYSEX_STORE:
203 dev_dbg(pod->line6.ifcdev,
204 "message %02X not yet implemented\n",
209 dev_dbg(pod->line6.ifcdev,
210 "unknown sysex message %02X\n",
215 (buf, pod_version_header,
216 sizeof(pod_version_header)) == 0) {
217 pod->firmware_version =
218 buf[13] * 100 + buf[14] * 10 + buf[15];
220 ((int)buf[8] << 16) | ((int)buf[9] << 8) | (int)
224 dev_dbg(pod->line6.ifcdev, "unknown sysex header\n");
228 case LINE6_SYSEX_END:
232 dev_dbg(pod->line6.ifcdev, "POD: unknown message %02X\n",
238 Transmit PODxt Pro control parameter.
240 void line6_pod_transmit_parameter(struct usb_line6_pod *pod, int param,
243 line6_transmit_parameter(&pod->line6, param, value);
247 Send system parameter (from integer).
249 static int pod_set_system_param_int(struct usb_line6_pod *pod, int value,
253 static const int size = 5;
255 sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEM, size);
258 sysex[SYSEX_DATA_OFS] = code;
259 sysex[SYSEX_DATA_OFS + 1] = (value >> 12) & 0x0f;
260 sysex[SYSEX_DATA_OFS + 2] = (value >> 8) & 0x0f;
261 sysex[SYSEX_DATA_OFS + 3] = (value >> 4) & 0x0f;
262 sysex[SYSEX_DATA_OFS + 4] = (value) & 0x0f;
263 line6_send_sysex_message(&pod->line6, sysex, size);
269 "read" request on "serial_number" special file.
271 static ssize_t pod_get_serial_number(struct device *dev,
272 struct device_attribute *attr, char *buf)
274 struct usb_interface *interface = to_usb_interface(dev);
275 struct usb_line6_pod *pod = usb_get_intfdata(interface);
276 return sprintf(buf, "%d\n", pod->serial_number);
280 "read" request on "firmware_version" special file.
282 static ssize_t pod_get_firmware_version(struct device *dev,
283 struct device_attribute *attr,
286 struct usb_interface *interface = to_usb_interface(dev);
287 struct usb_line6_pod *pod = usb_get_intfdata(interface);
288 return sprintf(buf, "%d.%02d\n", pod->firmware_version / 100,
289 pod->firmware_version % 100);
293 "read" request on "device_id" special file.
295 static ssize_t pod_get_device_id(struct device *dev,
296 struct device_attribute *attr, char *buf)
298 struct usb_interface *interface = to_usb_interface(dev);
299 struct usb_line6_pod *pod = usb_get_intfdata(interface);
300 return sprintf(buf, "%d\n", pod->device_id);
304 POD startup procedure.
305 This is a sequence of functions with special requirements (e.g., must
306 not run immediately after initialization, must not run in interrupt
307 context). After the last one has finished, the device is ready to use.
310 static void pod_startup1(struct usb_line6_pod *pod)
312 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_INIT);
314 /* delay startup procedure: */
315 line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2,
319 static void pod_startup2(unsigned long data)
321 struct usb_line6_pod *pod = (struct usb_line6_pod *)data;
323 /* schedule another startup procedure until startup is complete: */
324 if (pod->startup_progress >= POD_STARTUP_LAST)
327 pod->startup_progress = POD_STARTUP_DUMPREQ;
328 line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2,
331 /* current channel dump: */
332 line6_dump_request_async(&pod->dumpreq, &pod->line6, 0,
336 static void pod_startup3(struct usb_line6_pod *pod)
338 struct usb_line6 *line6 = &pod->line6;
339 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_VERSIONREQ);
341 /* request firmware version: */
342 line6_version_request_async(line6);
345 static void pod_startup4(struct usb_line6_pod *pod)
347 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_WORKQUEUE);
349 /* schedule work for global work queue: */
350 schedule_work(&pod->startup_work);
353 static void pod_startup5(struct work_struct *work)
355 struct usb_line6_pod *pod =
356 container_of(work, struct usb_line6_pod, startup_work);
357 struct usb_line6 *line6 = &pod->line6;
359 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_SETUP);
362 line6_read_serial_number(&pod->line6, &pod->serial_number);
364 /* ALSA audio interface: */
365 line6_register_audio(line6);
368 /* POD special files: */
369 static DEVICE_ATTR(device_id, S_IRUGO, pod_get_device_id, line6_nop_write);
370 static DEVICE_ATTR(firmware_version, S_IRUGO, pod_get_firmware_version,
372 static DEVICE_ATTR(serial_number, S_IRUGO, pod_get_serial_number,
375 /* control info callback */
376 static int snd_pod_control_monitor_info(struct snd_kcontrol *kcontrol,
377 struct snd_ctl_elem_info *uinfo)
379 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
381 uinfo->value.integer.min = 0;
382 uinfo->value.integer.max = 65535;
386 /* control get callback */
387 static int snd_pod_control_monitor_get(struct snd_kcontrol *kcontrol,
388 struct snd_ctl_elem_value *ucontrol)
390 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
391 struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6;
392 ucontrol->value.integer.value[0] = pod->monitor_level;
396 /* control put callback */
397 static int snd_pod_control_monitor_put(struct snd_kcontrol *kcontrol,
398 struct snd_ctl_elem_value *ucontrol)
400 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
401 struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6;
403 if (ucontrol->value.integer.value[0] == pod->monitor_level)
406 pod->monitor_level = ucontrol->value.integer.value[0];
407 pod_set_system_param_int(pod, ucontrol->value.integer.value[0],
412 /* control definition */
413 static struct snd_kcontrol_new pod_control_monitor = {
414 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
415 .name = "Monitor Playback Volume",
417 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
418 .info = snd_pod_control_monitor_info,
419 .get = snd_pod_control_monitor_get,
420 .put = snd_pod_control_monitor_put
426 static void pod_destruct(struct usb_interface *interface)
428 struct usb_line6_pod *pod = usb_get_intfdata(interface);
432 line6_cleanup_audio(&pod->line6);
434 del_timer(&pod->startup_timer);
435 cancel_work_sync(&pod->startup_work);
437 /* free dump request data: */
438 line6_dumpreq_destruct(&pod->dumpreq);
442 Create sysfs entries.
444 static int pod_create_files2(struct device *dev)
448 CHECK_RETURN(device_create_file(dev, &dev_attr_device_id));
449 CHECK_RETURN(device_create_file(dev, &dev_attr_firmware_version));
450 CHECK_RETURN(device_create_file(dev, &dev_attr_serial_number));
455 Try to init POD device.
457 static int pod_try_init(struct usb_interface *interface,
458 struct usb_line6_pod *pod)
461 struct usb_line6 *line6 = &pod->line6;
463 init_timer(&pod->startup_timer);
464 INIT_WORK(&pod->startup_work, pod_startup5);
466 if ((interface == NULL) || (pod == NULL))
469 /* initialize USB buffers: */
470 err = line6_dumpreq_init(&pod->dumpreq, pod_request_channel,
471 sizeof(pod_request_channel));
473 dev_err(&interface->dev, "Out of memory\n");
477 /* create sysfs entries: */
478 err = pod_create_files2(&interface->dev);
482 /* initialize audio system: */
483 err = line6_init_audio(line6);
487 /* initialize MIDI subsystem: */
488 err = line6_init_midi(line6);
492 /* initialize PCM subsystem: */
493 err = line6_init_pcm(line6, &pod_pcm_properties);
497 /* register monitor control: */
498 err = snd_ctl_add(line6->card,
499 snd_ctl_new1(&pod_control_monitor, line6->line6pcm));
504 When the sound card is registered at this point, the PODxt Live
505 displays "Invalid Code Error 07", so we do it later in the event
509 if (pod->line6.properties->capabilities & LINE6_BIT_CONTROL) {
510 pod->monitor_level = POD_system_invalid;
512 /* initiate startup procedure: */
520 Init POD device (and clean up in case of failure).
522 int line6_pod_init(struct usb_interface *interface, struct usb_line6_pod *pod)
524 int err = pod_try_init(interface, pod);
527 pod_destruct(interface);
533 POD device disconnected.
535 void line6_pod_disconnect(struct usb_interface *interface)
537 struct usb_line6_pod *pod;
539 if (interface == NULL)
541 pod = usb_get_intfdata(interface);
544 struct snd_line6_pcm *line6pcm = pod->line6.line6pcm;
545 struct device *dev = &interface->dev;
547 if (line6pcm != NULL)
548 line6_pcm_disconnect(line6pcm);
551 /* remove sysfs entries: */
552 device_remove_file(dev, &dev_attr_device_id);
553 device_remove_file(dev, &dev_attr_firmware_version);
554 device_remove_file(dev, &dev_attr_serial_number);
558 pod_destruct(interface);