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>
23 #define POD_SYSEX_CODE 3
24 #define POD_BYTES_PER_FRAME 6 /* 24bit audio (stereo) */
29 POD_SYSEX_SAVE = 0x24,
30 POD_SYSEX_SYSTEM = 0x56,
31 POD_SYSEX_SYSTEMREQ = 0x57,
32 /* POD_SYSEX_UPDATE = 0x6c, */ /* software update! */
33 POD_SYSEX_STORE = 0x71,
34 POD_SYSEX_FINISH = 0x72,
35 POD_SYSEX_DUMPMEM = 0x73,
36 POD_SYSEX_DUMP = 0x74,
37 POD_SYSEX_DUMPREQ = 0x75
38 /* POD_SYSEX_DUMPMEM2 = 0x76 */ /* dumps entire internal memory of PODxt Pro */
42 POD_monitor_level = 0x04,
43 POD_system_invalid = 0x10000
60 static struct snd_ratden pod_ratden = {
67 static struct line6_pcm_properties pod_pcm_properties = {
68 .snd_line6_playback_hw = {
69 .info = (SNDRV_PCM_INFO_MMAP |
70 SNDRV_PCM_INFO_INTERLEAVED |
71 SNDRV_PCM_INFO_BLOCK_TRANSFER |
72 SNDRV_PCM_INFO_MMAP_VALID |
73 SNDRV_PCM_INFO_PAUSE |
75 SNDRV_PCM_INFO_RESUME |
77 SNDRV_PCM_INFO_SYNC_START),
78 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
79 .rates = SNDRV_PCM_RATE_KNOT,
84 .buffer_bytes_max = 60000,
85 .period_bytes_min = 64,
86 .period_bytes_max = 8192,
89 .snd_line6_capture_hw = {
90 .info = (SNDRV_PCM_INFO_MMAP |
91 SNDRV_PCM_INFO_INTERLEAVED |
92 SNDRV_PCM_INFO_BLOCK_TRANSFER |
93 SNDRV_PCM_INFO_MMAP_VALID |
95 SNDRV_PCM_INFO_RESUME |
97 SNDRV_PCM_INFO_SYNC_START),
98 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
99 .rates = SNDRV_PCM_RATE_KNOT,
104 .buffer_bytes_max = 60000,
105 .period_bytes_min = 64,
106 .period_bytes_max = 8192,
108 .periods_max = 1024},
111 .rats = &pod_ratden},
112 .bytes_per_frame = POD_BYTES_PER_FRAME
115 static const char pod_request_channel[] = {
116 0xf0, 0x00, 0x01, 0x0c, 0x03, 0x75, 0xf7
119 static const char pod_version_header[] = {
120 0xf2, 0x7e, 0x7f, 0x06, 0x02
123 /* forward declarations: */
124 static void pod_startup2(unsigned long data);
125 static void pod_startup3(struct usb_line6_pod *pod);
126 static void pod_startup4(struct usb_line6_pod *pod);
128 static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code,
131 return line6_alloc_sysex_buffer(&pod->line6, POD_SYSEX_CODE, code,
136 Store parameter value in driver memory.
138 static void pod_store_parameter(struct usb_line6_pod *pod, int param, int value)
140 pod->prog_data.control[param] = value;
146 static void pod_save_button_pressed(struct usb_line6_pod *pod, int type,
149 set_bit(POD_SAVE_PRESSED, &pod->atomic_flags);
153 Process a completely received message.
155 void line6_pod_process_message(struct usb_line6_pod *pod)
157 const unsigned char *buf = pod->line6.buffer_message;
159 /* filter messages by type */
160 switch (buf[0] & 0xf0) {
161 case LINE6_PARAM_CHANGE:
162 case LINE6_PROGRAM_CHANGE:
163 case LINE6_SYSEX_BEGIN:
164 break; /* handle these further down */
167 return; /* ignore all others */
170 /* process all remaining messages */
172 case LINE6_PARAM_CHANGE | LINE6_CHANNEL_DEVICE:
173 pod_store_parameter(pod, buf[1], buf[2]);
174 /* intentionally no break here! */
176 case LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST:
177 if ((buf[1] == POD_amp_model_setup) ||
178 (buf[1] == POD_effect_setup))
179 /* these also affect other settings */
180 line6_dump_request_async(&pod->dumpreq, &pod->line6, 0,
185 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_DEVICE:
186 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST:
187 set_bit(POD_CHANNEL_DIRTY, &pod->atomic_flags);
188 line6_dump_request_async(&pod->dumpreq, &pod->line6, 0,
192 case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_DEVICE:
193 case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_UNKNOWN:
194 if (memcmp(buf + 1, line6_midi_id, sizeof(line6_midi_id)) == 0) {
197 if (pod->line6.message_length ==
198 sizeof(pod->prog_data) + 7) {
199 switch (pod->dumpreq.in_progress) {
200 case LINE6_DUMP_CURRENT:
201 memcpy(&pod->prog_data, buf + 7,
202 sizeof(pod->prog_data));
205 case POD_DUMP_MEMORY:
206 memcpy(&pod->prog_data_buf,
209 (pod->prog_data_buf));
213 dev_dbg(pod->line6.ifcdev,
214 "unknown dump code %02X\n",
215 pod->dumpreq.in_progress);
218 line6_dump_finished(&pod->dumpreq);
221 dev_dbg(pod->line6.ifcdev,
222 "wrong size of channel dump message (%d instead of %d)\n",
223 pod->line6.message_length,
224 (int)sizeof(pod->prog_data) +
229 case POD_SYSEX_SYSTEM:{
231 ((int)buf[7] << 12) | ((int)buf[8]
233 ((int)buf[9] << 4) | (int)buf[10];
235 if (buf[6] == POD_monitor_level)
236 pod->monitor_level = value;
240 case POD_SYSEX_FINISH:
241 /* do we need to respond to this? */
245 pod_save_button_pressed(pod, buf[6], buf[7]);
248 case POD_SYSEX_STORE:
249 dev_dbg(pod->line6.ifcdev,
250 "message %02X not yet implemented\n",
255 dev_dbg(pod->line6.ifcdev,
256 "unknown sysex message %02X\n",
261 (buf, pod_version_header,
262 sizeof(pod_version_header)) == 0) {
263 pod->firmware_version =
264 buf[13] * 100 + buf[14] * 10 + buf[15];
266 ((int)buf[8] << 16) | ((int)buf[9] << 8) | (int)
270 dev_dbg(pod->line6.ifcdev, "unknown sysex header\n");
274 case LINE6_SYSEX_END:
278 dev_dbg(pod->line6.ifcdev, "POD: unknown message %02X\n",
284 Transmit PODxt Pro control parameter.
286 void line6_pod_transmit_parameter(struct usb_line6_pod *pod, int param,
289 if (line6_transmit_parameter(&pod->line6, param, value) == 0)
290 pod_store_parameter(pod, param, value);
292 if ((param == POD_amp_model_setup) || (param == POD_effect_setup)) /* these also affect other settings */
293 line6_invalidate_current(&pod->dumpreq);
297 Send system parameter (from integer).
299 static int pod_set_system_param_int(struct usb_line6_pod *pod, int value,
303 static const int size = 5;
305 sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEM, size);
308 sysex[SYSEX_DATA_OFS] = code;
309 sysex[SYSEX_DATA_OFS + 1] = (value >> 12) & 0x0f;
310 sysex[SYSEX_DATA_OFS + 2] = (value >> 8) & 0x0f;
311 sysex[SYSEX_DATA_OFS + 3] = (value >> 4) & 0x0f;
312 sysex[SYSEX_DATA_OFS + 4] = (value) & 0x0f;
313 line6_send_sysex_message(&pod->line6, sysex, size);
319 "read" request on "serial_number" special file.
321 static ssize_t pod_get_serial_number(struct device *dev,
322 struct device_attribute *attr, char *buf)
324 struct usb_interface *interface = to_usb_interface(dev);
325 struct usb_line6_pod *pod = usb_get_intfdata(interface);
326 return sprintf(buf, "%d\n", pod->serial_number);
330 "read" request on "firmware_version" special file.
332 static ssize_t pod_get_firmware_version(struct device *dev,
333 struct device_attribute *attr,
336 struct usb_interface *interface = to_usb_interface(dev);
337 struct usb_line6_pod *pod = usb_get_intfdata(interface);
338 return sprintf(buf, "%d.%02d\n", pod->firmware_version / 100,
339 pod->firmware_version % 100);
343 "read" request on "device_id" special file.
345 static ssize_t pod_get_device_id(struct device *dev,
346 struct device_attribute *attr, char *buf)
348 struct usb_interface *interface = to_usb_interface(dev);
349 struct usb_line6_pod *pod = usb_get_intfdata(interface);
350 return sprintf(buf, "%d\n", pod->device_id);
354 POD startup procedure.
355 This is a sequence of functions with special requirements (e.g., must
356 not run immediately after initialization, must not run in interrupt
357 context). After the last one has finished, the device is ready to use.
360 static void pod_startup1(struct usb_line6_pod *pod)
362 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_INIT);
364 /* delay startup procedure: */
365 line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2,
369 static void pod_startup2(unsigned long data)
371 struct usb_line6_pod *pod = (struct usb_line6_pod *)data;
373 /* schedule another startup procedure until startup is complete: */
374 if (pod->startup_progress >= POD_STARTUP_LAST)
377 pod->startup_progress = POD_STARTUP_DUMPREQ;
378 line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2,
381 /* current channel dump: */
382 line6_dump_request_async(&pod->dumpreq, &pod->line6, 0,
386 static void pod_startup3(struct usb_line6_pod *pod)
388 struct usb_line6 *line6 = &pod->line6;
389 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_VERSIONREQ);
391 /* request firmware version: */
392 line6_version_request_async(line6);
395 static void pod_startup4(struct usb_line6_pod *pod)
397 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_WORKQUEUE);
399 /* schedule work for global work queue: */
400 schedule_work(&pod->startup_work);
403 static void pod_startup5(struct work_struct *work)
405 struct usb_line6_pod *pod =
406 container_of(work, struct usb_line6_pod, startup_work);
407 struct usb_line6 *line6 = &pod->line6;
409 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_SETUP);
412 line6_read_serial_number(&pod->line6, &pod->serial_number);
414 /* ALSA audio interface: */
415 line6_register_audio(line6);
418 line6_pod_create_files(pod->firmware_version,
419 line6->properties->device_bit, line6->ifcdev);
422 /* POD special files: */
423 static DEVICE_ATTR(device_id, S_IRUGO, pod_get_device_id, line6_nop_write);
424 static DEVICE_ATTR(firmware_version, S_IRUGO, pod_get_firmware_version,
426 static DEVICE_ATTR(serial_number, S_IRUGO, pod_get_serial_number,
429 /* control info callback */
430 static int snd_pod_control_monitor_info(struct snd_kcontrol *kcontrol,
431 struct snd_ctl_elem_info *uinfo)
433 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
435 uinfo->value.integer.min = 0;
436 uinfo->value.integer.max = 65535;
440 /* control get callback */
441 static int snd_pod_control_monitor_get(struct snd_kcontrol *kcontrol,
442 struct snd_ctl_elem_value *ucontrol)
444 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
445 struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6;
446 ucontrol->value.integer.value[0] = pod->monitor_level;
450 /* control put callback */
451 static int snd_pod_control_monitor_put(struct snd_kcontrol *kcontrol,
452 struct snd_ctl_elem_value *ucontrol)
454 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
455 struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6;
457 if (ucontrol->value.integer.value[0] == pod->monitor_level)
460 pod->monitor_level = ucontrol->value.integer.value[0];
461 pod_set_system_param_int(pod, ucontrol->value.integer.value[0],
466 /* control definition */
467 static struct snd_kcontrol_new pod_control_monitor = {
468 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
469 .name = "Monitor Playback Volume",
471 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
472 .info = snd_pod_control_monitor_info,
473 .get = snd_pod_control_monitor_get,
474 .put = snd_pod_control_monitor_put
480 static void pod_destruct(struct usb_interface *interface)
482 struct usb_line6_pod *pod = usb_get_intfdata(interface);
486 line6_cleanup_audio(&pod->line6);
488 del_timer(&pod->startup_timer);
489 cancel_work_sync(&pod->startup_work);
491 /* free dump request data: */
492 line6_dumpreq_destruct(&pod->dumpreq);
496 Create sysfs entries.
498 static int pod_create_files2(struct device *dev)
502 CHECK_RETURN(device_create_file(dev, &dev_attr_device_id));
503 CHECK_RETURN(device_create_file(dev, &dev_attr_firmware_version));
504 CHECK_RETURN(device_create_file(dev, &dev_attr_serial_number));
509 Try to init POD device.
511 static int pod_try_init(struct usb_interface *interface,
512 struct usb_line6_pod *pod)
515 struct usb_line6 *line6 = &pod->line6;
517 init_timer(&pod->startup_timer);
518 INIT_WORK(&pod->startup_work, pod_startup5);
520 if ((interface == NULL) || (pod == NULL))
523 /* initialize USB buffers: */
524 err = line6_dumpreq_init(&pod->dumpreq, pod_request_channel,
525 sizeof(pod_request_channel));
527 dev_err(&interface->dev, "Out of memory\n");
531 /* create sysfs entries: */
532 err = pod_create_files2(&interface->dev);
536 /* initialize audio system: */
537 err = line6_init_audio(line6);
541 /* initialize MIDI subsystem: */
542 err = line6_init_midi(line6);
546 /* initialize PCM subsystem: */
547 err = line6_init_pcm(line6, &pod_pcm_properties);
551 /* register monitor control: */
552 err = snd_ctl_add(line6->card,
553 snd_ctl_new1(&pod_control_monitor, line6->line6pcm));
558 When the sound card is registered at this point, the PODxt Live
559 displays "Invalid Code Error 07", so we do it later in the event
563 if (pod->line6.properties->capabilities & LINE6_BIT_CONTROL) {
564 pod->monitor_level = POD_system_invalid;
566 /* initiate startup procedure: */
574 Init POD device (and clean up in case of failure).
576 int line6_pod_init(struct usb_interface *interface, struct usb_line6_pod *pod)
578 int err = pod_try_init(interface, pod);
581 pod_destruct(interface);
587 POD device disconnected.
589 void line6_pod_disconnect(struct usb_interface *interface)
591 struct usb_line6_pod *pod;
593 if (interface == NULL)
595 pod = usb_get_intfdata(interface);
598 struct snd_line6_pcm *line6pcm = pod->line6.line6pcm;
599 struct device *dev = &interface->dev;
601 if (line6pcm != NULL)
602 line6_pcm_disconnect(line6pcm);
605 /* remove sysfs entries: */
606 line6_pod_remove_files(pod->firmware_version,
608 properties->device_bit, dev);
610 device_remove_file(dev, &dev_attr_device_id);
611 device_remove_file(dev, &dev_attr_firmware_version);
612 device_remove_file(dev, &dev_attr_serial_number);
616 pod_destruct(interface);