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_CLIP = 0x0f,
30 POD_SYSEX_SAVE = 0x24,
31 POD_SYSEX_SYSTEM = 0x56,
32 POD_SYSEX_SYSTEMREQ = 0x57,
33 /* POD_SYSEX_UPDATE = 0x6c, */ /* software update! */
34 POD_SYSEX_STORE = 0x71,
35 POD_SYSEX_FINISH = 0x72,
36 POD_SYSEX_DUMPMEM = 0x73,
37 POD_SYSEX_DUMP = 0x74,
38 POD_SYSEX_DUMPREQ = 0x75
39 /* POD_SYSEX_DUMPMEM2 = 0x76 */ /* dumps entire internal memory of PODxt Pro */
43 POD_monitor_level = 0x04,
45 POD_tuner_mute = 0x13,
46 POD_tuner_freq = 0x15,
47 POD_tuner_note = 0x16,
48 POD_tuner_pitch = 0x17,
49 POD_system_invalid = 0x10000
66 static struct snd_ratden pod_ratden = {
73 static struct line6_pcm_properties pod_pcm_properties = {
74 .snd_line6_playback_hw = {
75 .info = (SNDRV_PCM_INFO_MMAP |
76 SNDRV_PCM_INFO_INTERLEAVED |
77 SNDRV_PCM_INFO_BLOCK_TRANSFER |
78 SNDRV_PCM_INFO_MMAP_VALID |
79 SNDRV_PCM_INFO_PAUSE |
81 SNDRV_PCM_INFO_RESUME |
83 SNDRV_PCM_INFO_SYNC_START),
84 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
85 .rates = SNDRV_PCM_RATE_KNOT,
90 .buffer_bytes_max = 60000,
91 .period_bytes_min = 64,
92 .period_bytes_max = 8192,
95 .snd_line6_capture_hw = {
96 .info = (SNDRV_PCM_INFO_MMAP |
97 SNDRV_PCM_INFO_INTERLEAVED |
98 SNDRV_PCM_INFO_BLOCK_TRANSFER |
99 SNDRV_PCM_INFO_MMAP_VALID |
101 SNDRV_PCM_INFO_RESUME |
103 SNDRV_PCM_INFO_SYNC_START),
104 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
105 .rates = SNDRV_PCM_RATE_KNOT,
110 .buffer_bytes_max = 60000,
111 .period_bytes_min = 64,
112 .period_bytes_max = 8192,
114 .periods_max = 1024},
117 .rats = &pod_ratden},
118 .bytes_per_frame = POD_BYTES_PER_FRAME
121 static const char pod_request_channel[] = {
122 0xf0, 0x00, 0x01, 0x0c, 0x03, 0x75, 0xf7
125 static const char pod_version_header[] = {
126 0xf2, 0x7e, 0x7f, 0x06, 0x02
129 /* forward declarations: */
130 static void pod_startup2(unsigned long data);
131 static void pod_startup3(struct usb_line6_pod *pod);
132 static void pod_startup4(struct usb_line6_pod *pod);
135 Mark all parameters as dirty and notify waiting processes.
137 static void pod_mark_batch_all_dirty(struct usb_line6_pod *pod)
141 for (i = 0; i < POD_CONTROL_SIZE; i++)
142 set_bit(i, pod->param_dirty);
145 static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code,
148 return line6_alloc_sysex_buffer(&pod->line6, POD_SYSEX_CODE, code,
153 Send channel dump data to the PODxt Pro.
155 static void pod_dump(struct usb_line6_pod *pod, const unsigned char *data)
157 int size = 1 + sizeof(pod->prog_data);
158 char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_DUMP, size);
161 /* Don't know what this is good for, but PODxt Pro transmits it, so we
163 sysex[SYSEX_DATA_OFS] = 5;
164 memcpy(sysex + SYSEX_DATA_OFS + 1, data, sizeof(pod->prog_data));
165 line6_send_sysex_message(&pod->line6, sysex, size);
166 memcpy(&pod->prog_data, data, sizeof(pod->prog_data));
167 pod_mark_batch_all_dirty(pod);
172 Store parameter value in driver memory and mark it as dirty.
174 static void pod_store_parameter(struct usb_line6_pod *pod, int param, int value)
176 pod->prog_data.control[param] = value;
177 set_bit(param, pod->param_dirty);
184 static void pod_save_button_pressed(struct usb_line6_pod *pod, int type,
188 set_bit(POD_SAVE_PRESSED, &pod->atomic_flags);
192 Process a completely received message.
194 void line6_pod_process_message(struct usb_line6_pod *pod)
196 const unsigned char *buf = pod->line6.buffer_message;
198 /* filter messages by type */
199 switch (buf[0] & 0xf0) {
200 case LINE6_PARAM_CHANGE:
201 case LINE6_PROGRAM_CHANGE:
202 case LINE6_SYSEX_BEGIN:
203 break; /* handle these further down */
206 return; /* ignore all others */
209 /* process all remaining messages */
211 case LINE6_PARAM_CHANGE | LINE6_CHANNEL_DEVICE:
212 pod_store_parameter(pod, buf[1], buf[2]);
213 /* intentionally no break here! */
215 case LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST:
216 if ((buf[1] == POD_amp_model_setup) ||
217 (buf[1] == POD_effect_setup))
218 /* these also affect other settings */
219 line6_dump_request_async(&pod->dumpreq, &pod->line6, 0,
224 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_DEVICE:
225 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST:
227 set_bit(POD_CHANNEL_DIRTY, &pod->atomic_flags);
228 line6_dump_request_async(&pod->dumpreq, &pod->line6, 0,
232 case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_DEVICE:
233 case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_UNKNOWN:
234 if (memcmp(buf + 1, line6_midi_id, sizeof(line6_midi_id)) == 0) {
237 if (pod->line6.message_length ==
238 sizeof(pod->prog_data) + 7) {
239 switch (pod->dumpreq.in_progress) {
240 case LINE6_DUMP_CURRENT:
241 memcpy(&pod->prog_data, buf + 7,
242 sizeof(pod->prog_data));
243 pod_mark_batch_all_dirty(pod);
246 case POD_DUMP_MEMORY:
247 memcpy(&pod->prog_data_buf,
250 (pod->prog_data_buf));
254 dev_dbg(pod->line6.ifcdev,
255 "unknown dump code %02X\n",
256 pod->dumpreq.in_progress);
259 line6_dump_finished(&pod->dumpreq);
262 dev_dbg(pod->line6.ifcdev,
263 "wrong size of channel dump message (%d instead of %d)\n",
264 pod->line6.message_length,
265 (int)sizeof(pod->prog_data) +
270 case POD_SYSEX_SYSTEM:{
272 ((int)buf[7] << 12) | ((int)buf[8]
274 ((int)buf[9] << 4) | (int)buf[10];
276 #define PROCESS_SYSTEM_PARAM(x) \
278 pod->x.value = value; \
279 wake_up(&pod->x.wait); \
285 PROCESS_SYSTEM_PARAM(routing);
295 #undef PROCESS_SYSTEM_PARAM
298 dev_dbg(pod->line6.ifcdev,
299 "unknown tuner/system response %02X\n",
306 case POD_SYSEX_FINISH:
307 /* do we need to respond to this? */
311 pod_save_button_pressed(pod, buf[6], buf[7]);
315 dev_dbg(pod->line6.ifcdev, "audio clipped\n");
316 pod->clipping.value = 1;
317 wake_up(&pod->clipping.wait);
320 case POD_SYSEX_STORE:
321 dev_dbg(pod->line6.ifcdev,
322 "message %02X not yet implemented\n",
327 dev_dbg(pod->line6.ifcdev,
328 "unknown sysex message %02X\n",
333 (buf, pod_version_header,
334 sizeof(pod_version_header)) == 0) {
335 pod->firmware_version =
336 buf[13] * 100 + buf[14] * 10 + buf[15];
338 ((int)buf[8] << 16) | ((int)buf[9] << 8) | (int)
342 dev_dbg(pod->line6.ifcdev, "unknown sysex header\n");
346 case LINE6_SYSEX_END:
350 dev_dbg(pod->line6.ifcdev, "POD: unknown message %02X\n",
356 Detect some cases that require a channel dump after sending a command to the
357 device. Important notes:
358 *) The actual dump request can not be sent here since we are not allowed to
359 wait for the completion of the first message in this context, and sending
360 the dump request before completion of the previous message leaves the POD
361 in an undefined state. The dump request will be sent when the echoed
362 commands are received.
363 *) This method fails if a param change message is "chopped" after the first
366 void line6_pod_midi_postprocess(struct usb_line6_pod *pod, unsigned char *data,
371 if (!pod->midi_postprocess)
374 for (i = 0; i < length; ++i) {
375 if (data[i] == (LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST)) {
376 line6_invalidate_current(&pod->dumpreq);
379 if ((data[i] == (LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST))
381 if ((data[i + 1] == POD_amp_model_setup)
382 || (data[i + 1] == POD_effect_setup)) {
383 line6_invalidate_current(&pod->dumpreq);
390 Transmit PODxt Pro control parameter.
392 void line6_pod_transmit_parameter(struct usb_line6_pod *pod, int param,
395 if (line6_transmit_parameter(&pod->line6, param, value) == 0)
396 pod_store_parameter(pod, param, value);
398 if ((param == POD_amp_model_setup) || (param == POD_effect_setup)) /* these also affect other settings */
399 line6_invalidate_current(&pod->dumpreq);
403 Resolve value to memory location.
405 static int pod_resolve(const char *buf, short block0, short block1,
406 unsigned char *location)
412 ret = kstrtou8(buf, 10, &value);
416 block = (value < 0x40) ? block0 : block1;
418 location[0] = block >> 7;
419 location[1] = value | (block & 0x7f);
424 Send command to store channel/effects setup/amp setup to PODxt Pro.
426 static ssize_t pod_send_store_command(struct device *dev, const char *buf,
427 size_t count, short block0, short block1)
429 struct usb_interface *interface = to_usb_interface(dev);
430 struct usb_line6_pod *pod = usb_get_intfdata(interface);
432 int size = 3 + sizeof(pod->prog_data_buf);
433 char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_STORE, size);
438 sysex[SYSEX_DATA_OFS] = 5; /* see pod_dump() */
439 ret = pod_resolve(buf, block0, block1, sysex + SYSEX_DATA_OFS + 1);
445 memcpy(sysex + SYSEX_DATA_OFS + 3, &pod->prog_data_buf,
446 sizeof(pod->prog_data_buf));
448 line6_send_sysex_message(&pod->line6, sysex, size);
450 /* needs some delay here on AMD64 platform */
455 Send command to retrieve channel/effects setup/amp setup to PODxt Pro.
457 static ssize_t pod_send_retrieve_command(struct device *dev, const char *buf,
458 size_t count, short block0,
461 struct usb_interface *interface = to_usb_interface(dev);
462 struct usb_line6_pod *pod = usb_get_intfdata(interface);
465 char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_DUMPMEM, size);
470 ret = pod_resolve(buf, block0, block1, sysex + SYSEX_DATA_OFS);
475 sysex[SYSEX_DATA_OFS + 2] = 0;
476 sysex[SYSEX_DATA_OFS + 3] = 0;
477 line6_dump_started(&pod->dumpreq, POD_DUMP_MEMORY);
479 if (line6_send_sysex_message(&pod->line6, sysex, size) < size)
480 line6_dump_finished(&pod->dumpreq);
483 /* needs some delay here on AMD64 platform */
488 Generic get name function.
490 static ssize_t get_name_generic(struct usb_line6_pod *pod, const char *str,
496 char *last_non_space = buf;
498 int retval = line6_dump_wait_interruptible(&pod->dumpreq);
502 for (p1 = str, p2 = buf; *p1; ++p1, ++p2) {
506 if (++length == POD_NAME_LENGTH)
510 *(last_non_space + 1) = '\n';
511 return last_non_space - buf + 2;
515 "read" request on "name" special file.
517 static ssize_t pod_get_name(struct device *dev, struct device_attribute *attr,
520 struct usb_interface *interface = to_usb_interface(dev);
521 struct usb_line6_pod *pod = usb_get_intfdata(interface);
522 return get_name_generic(pod, pod->prog_data.header + POD_NAME_OFFSET,
527 "read" request on "name" special file.
529 static ssize_t pod_get_name_buf(struct device *dev,
530 struct device_attribute *attr, char *buf)
532 struct usb_interface *interface = to_usb_interface(dev);
533 struct usb_line6_pod *pod = usb_get_intfdata(interface);
534 return get_name_generic(pod,
535 pod->prog_data_buf.header + POD_NAME_OFFSET,
540 "read" request on "dump" special file.
542 static ssize_t pod_get_dump(struct device *dev, struct device_attribute *attr,
545 struct usb_interface *interface = to_usb_interface(dev);
546 struct usb_line6_pod *pod = usb_get_intfdata(interface);
547 int retval = line6_dump_wait_interruptible(&pod->dumpreq);
550 memcpy(buf, &pod->prog_data, sizeof(pod->prog_data));
551 return sizeof(pod->prog_data);
555 "write" request on "dump" special file.
557 static ssize_t pod_set_dump(struct device *dev, struct device_attribute *attr,
558 const char *buf, size_t count)
560 struct usb_interface *interface = to_usb_interface(dev);
561 struct usb_line6_pod *pod = usb_get_intfdata(interface);
563 if (count != sizeof(pod->prog_data)) {
564 dev_err(pod->line6.ifcdev,
565 "data block must be exactly %d bytes\n",
566 (int)sizeof(pod->prog_data));
571 return sizeof(pod->prog_data);
575 Identify system parameters related to the tuner.
577 static bool pod_is_tuner(int code)
580 (code == POD_tuner_mute) ||
581 (code == POD_tuner_freq) ||
582 (code == POD_tuner_note) || (code == POD_tuner_pitch);
586 Get system parameter (as integer).
587 @param tuner non-zero, if code refers to a tuner parameter
589 static int pod_get_system_param_int(struct usb_line6_pod *pod, int *value,
590 int code, struct ValueWait *param, int sign)
593 static const int size = 1;
596 if (((pod->prog_data.control[POD_tuner] & 0x40) == 0)
597 && pod_is_tuner(code))
600 /* send value request to device: */
601 param->value = POD_system_invalid;
602 sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEMREQ, size);
607 sysex[SYSEX_DATA_OFS] = code;
608 line6_send_sysex_message(&pod->line6, sysex, size);
611 /* wait for device to respond: */
613 wait_event_interruptible(param->wait,
614 param->value != POD_system_invalid);
619 *value = sign ? (int)(signed short)param->value : (int)(unsigned short)
622 if (*value == POD_system_invalid)
623 *value = 0; /* don't report uninitialized values */
629 Get system parameter (as string).
630 @param tuner non-zero, if code refers to a tuner parameter
632 static ssize_t pod_get_system_param_string(struct usb_line6_pod *pod, char *buf,
633 int code, struct ValueWait *param,
636 int retval, value = 0;
637 retval = pod_get_system_param_int(pod, &value, code, param, sign);
642 return sprintf(buf, "%d\n", value);
646 Send system parameter (from integer).
647 @param tuner non-zero, if code refers to a tuner parameter
649 static int pod_set_system_param_int(struct usb_line6_pod *pod, int value,
653 static const int size = 5;
655 if (((pod->prog_data.control[POD_tuner] & 0x40) == 0)
656 && pod_is_tuner(code))
659 /* send value to tuner: */
660 sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEM, size);
663 sysex[SYSEX_DATA_OFS] = code;
664 sysex[SYSEX_DATA_OFS + 1] = (value >> 12) & 0x0f;
665 sysex[SYSEX_DATA_OFS + 2] = (value >> 8) & 0x0f;
666 sysex[SYSEX_DATA_OFS + 3] = (value >> 4) & 0x0f;
667 sysex[SYSEX_DATA_OFS + 4] = (value) & 0x0f;
668 line6_send_sysex_message(&pod->line6, sysex, size);
674 Send system parameter (from string).
675 @param tuner non-zero, if code refers to a tuner parameter
677 static ssize_t pod_set_system_param_string(struct usb_line6_pod *pod,
678 const char *buf, int count, int code,
682 unsigned short value = simple_strtoul(buf, NULL, 10) & mask;
683 retval = pod_set_system_param_int(pod, value, code);
684 return (retval < 0) ? retval : count;
688 "read" request on "dump_buf" special file.
690 static ssize_t pod_get_dump_buf(struct device *dev,
691 struct device_attribute *attr, char *buf)
693 struct usb_interface *interface = to_usb_interface(dev);
694 struct usb_line6_pod *pod = usb_get_intfdata(interface);
695 int retval = line6_dump_wait_interruptible(&pod->dumpreq);
698 memcpy(buf, &pod->prog_data_buf, sizeof(pod->prog_data_buf));
699 return sizeof(pod->prog_data_buf);
703 "write" request on "dump_buf" special file.
705 static ssize_t pod_set_dump_buf(struct device *dev,
706 struct device_attribute *attr,
707 const char *buf, size_t count)
709 struct usb_interface *interface = to_usb_interface(dev);
710 struct usb_line6_pod *pod = usb_get_intfdata(interface);
712 if (count != sizeof(pod->prog_data)) {
713 dev_err(pod->line6.ifcdev,
714 "data block must be exactly %d bytes\n",
715 (int)sizeof(pod->prog_data));
719 memcpy(&pod->prog_data_buf, buf, sizeof(pod->prog_data));
720 return sizeof(pod->prog_data);
724 "write" request on "finish" special file.
726 static ssize_t pod_set_finish(struct device *dev,
727 struct device_attribute *attr,
728 const char *buf, size_t count)
730 struct usb_interface *interface = to_usb_interface(dev);
731 struct usb_line6_pod *pod = usb_get_intfdata(interface);
733 char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_FINISH, size);
736 line6_send_sysex_message(&pod->line6, sysex, size);
742 "write" request on "store_channel" special file.
744 static ssize_t pod_set_store_channel(struct device *dev,
745 struct device_attribute *attr,
746 const char *buf, size_t count)
748 return pod_send_store_command(dev, buf, count, 0x0000, 0x00c0);
752 "write" request on "store_effects_setup" special file.
754 static ssize_t pod_set_store_effects_setup(struct device *dev,
755 struct device_attribute *attr,
756 const char *buf, size_t count)
758 return pod_send_store_command(dev, buf, count, 0x0080, 0x0080);
762 "write" request on "store_amp_setup" special file.
764 static ssize_t pod_set_store_amp_setup(struct device *dev,
765 struct device_attribute *attr,
766 const char *buf, size_t count)
768 return pod_send_store_command(dev, buf, count, 0x0040, 0x0100);
772 "write" request on "retrieve_channel" special file.
774 static ssize_t pod_set_retrieve_channel(struct device *dev,
775 struct device_attribute *attr,
776 const char *buf, size_t count)
778 return pod_send_retrieve_command(dev, buf, count, 0x0000, 0x00c0);
782 "write" request on "retrieve_effects_setup" special file.
784 static ssize_t pod_set_retrieve_effects_setup(struct device *dev,
785 struct device_attribute *attr,
786 const char *buf, size_t count)
788 return pod_send_retrieve_command(dev, buf, count, 0x0080, 0x0080);
792 "write" request on "retrieve_amp_setup" special file.
794 static ssize_t pod_set_retrieve_amp_setup(struct device *dev,
795 struct device_attribute *attr,
796 const char *buf, size_t count)
798 return pod_send_retrieve_command(dev, buf, count, 0x0040, 0x0100);
802 "read" request on "dirty" special file.
804 static ssize_t pod_get_dirty(struct device *dev, struct device_attribute *attr,
807 struct usb_interface *interface = to_usb_interface(dev);
808 struct usb_line6_pod *pod = usb_get_intfdata(interface);
809 buf[0] = pod->dirty ? '1' : '0';
815 "read" request on "midi_postprocess" special file.
817 static ssize_t pod_get_midi_postprocess(struct device *dev,
818 struct device_attribute *attr,
821 struct usb_interface *interface = to_usb_interface(dev);
822 struct usb_line6_pod *pod = usb_get_intfdata(interface);
823 return sprintf(buf, "%d\n", pod->midi_postprocess);
827 "write" request on "midi_postprocess" special file.
829 static ssize_t pod_set_midi_postprocess(struct device *dev,
830 struct device_attribute *attr,
831 const char *buf, size_t count)
833 struct usb_interface *interface = to_usb_interface(dev);
834 struct usb_line6_pod *pod = usb_get_intfdata(interface);
838 ret = kstrtou8(buf, 10, &value);
842 pod->midi_postprocess = value ? 1 : 0;
847 "read" request on "serial_number" special file.
849 static ssize_t pod_get_serial_number(struct device *dev,
850 struct device_attribute *attr, char *buf)
852 struct usb_interface *interface = to_usb_interface(dev);
853 struct usb_line6_pod *pod = usb_get_intfdata(interface);
854 return sprintf(buf, "%d\n", pod->serial_number);
858 "read" request on "firmware_version" special file.
860 static ssize_t pod_get_firmware_version(struct device *dev,
861 struct device_attribute *attr,
864 struct usb_interface *interface = to_usb_interface(dev);
865 struct usb_line6_pod *pod = usb_get_intfdata(interface);
866 return sprintf(buf, "%d.%02d\n", pod->firmware_version / 100,
867 pod->firmware_version % 100);
871 "read" request on "device_id" special file.
873 static ssize_t pod_get_device_id(struct device *dev,
874 struct device_attribute *attr, char *buf)
876 struct usb_interface *interface = to_usb_interface(dev);
877 struct usb_line6_pod *pod = usb_get_intfdata(interface);
878 return sprintf(buf, "%d\n", pod->device_id);
882 "read" request on "clip" special file.
884 static ssize_t pod_wait_for_clip(struct device *dev,
885 struct device_attribute *attr, char *buf)
887 struct usb_interface *interface = to_usb_interface(dev);
888 struct usb_line6_pod *pod = usb_get_intfdata(interface);
889 return wait_event_interruptible(pod->clipping.wait,
890 pod->clipping.value != 0);
894 POD startup procedure.
895 This is a sequence of functions with special requirements (e.g., must
896 not run immediately after initialization, must not run in interrupt
897 context). After the last one has finished, the device is ready to use.
900 static void pod_startup1(struct usb_line6_pod *pod)
902 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_INIT);
904 /* delay startup procedure: */
905 line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2,
909 static void pod_startup2(unsigned long data)
911 struct usb_line6_pod *pod = (struct usb_line6_pod *)data;
913 /* schedule another startup procedure until startup is complete: */
914 if (pod->startup_progress >= POD_STARTUP_LAST)
917 pod->startup_progress = POD_STARTUP_DUMPREQ;
918 line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2,
921 /* current channel dump: */
922 line6_dump_request_async(&pod->dumpreq, &pod->line6, 0,
926 static void pod_startup3(struct usb_line6_pod *pod)
928 struct usb_line6 *line6 = &pod->line6;
929 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_VERSIONREQ);
931 /* request firmware version: */
932 line6_version_request_async(line6);
935 static void pod_startup4(struct usb_line6_pod *pod)
937 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_WORKQUEUE);
939 /* schedule work for global work queue: */
940 schedule_work(&pod->startup_work);
943 static void pod_startup5(struct work_struct *work)
945 struct usb_line6_pod *pod =
946 container_of(work, struct usb_line6_pod, startup_work);
947 struct usb_line6 *line6 = &pod->line6;
949 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_SETUP);
952 line6_read_serial_number(&pod->line6, &pod->serial_number);
954 /* ALSA audio interface: */
955 line6_register_audio(line6);
958 line6_pod_create_files(pod->firmware_version,
959 line6->properties->device_bit, line6->ifcdev);
962 #define POD_GET_SYSTEM_PARAM(code, sign) \
963 static ssize_t pod_get_ ## code(struct device *dev, \
964 struct device_attribute *attr, char *buf) \
966 struct usb_interface *interface = to_usb_interface(dev); \
967 struct usb_line6_pod *pod = usb_get_intfdata(interface); \
968 return pod_get_system_param_string(pod, buf, POD_ ## code, \
972 #define POD_GET_SET_SYSTEM_PARAM(code, mask, sign) \
973 POD_GET_SYSTEM_PARAM(code, sign) \
974 static ssize_t pod_set_ ## code(struct device *dev, \
975 struct device_attribute *attr, \
976 const char *buf, size_t count) \
978 struct usb_interface *interface = to_usb_interface(dev); \
979 struct usb_line6_pod *pod = usb_get_intfdata(interface); \
980 return pod_set_system_param_string(pod, buf, count, POD_ ## code, mask); \
983 POD_GET_SET_SYSTEM_PARAM(monitor_level, 0xffff, 0);
984 POD_GET_SET_SYSTEM_PARAM(routing, 0x0003, 0);
985 POD_GET_SET_SYSTEM_PARAM(tuner_mute, 0x0001, 0);
986 POD_GET_SET_SYSTEM_PARAM(tuner_freq, 0xffff, 0);
987 POD_GET_SYSTEM_PARAM(tuner_note, 1);
988 POD_GET_SYSTEM_PARAM(tuner_pitch, 1);
990 #undef GET_SET_SYSTEM_PARAM
991 #undef GET_SYSTEM_PARAM
993 /* POD special files: */
994 static DEVICE_ATTR(clip, S_IRUGO, pod_wait_for_clip, line6_nop_write);
995 static DEVICE_ATTR(device_id, S_IRUGO, pod_get_device_id, line6_nop_write);
996 static DEVICE_ATTR(dirty, S_IRUGO, pod_get_dirty, line6_nop_write);
997 static DEVICE_ATTR(dump, S_IWUSR | S_IRUGO, pod_get_dump, pod_set_dump);
998 static DEVICE_ATTR(dump_buf, S_IWUSR | S_IRUGO, pod_get_dump_buf,
1000 static DEVICE_ATTR(finish, S_IWUSR, line6_nop_read, pod_set_finish);
1001 static DEVICE_ATTR(firmware_version, S_IRUGO, pod_get_firmware_version,
1003 static DEVICE_ATTR(midi_postprocess, S_IWUSR | S_IRUGO,
1004 pod_get_midi_postprocess, pod_set_midi_postprocess);
1005 static DEVICE_ATTR(monitor_level, S_IWUSR | S_IRUGO, pod_get_monitor_level,
1006 pod_set_monitor_level);
1007 static DEVICE_ATTR(name, S_IRUGO, pod_get_name, line6_nop_write);
1008 static DEVICE_ATTR(name_buf, S_IRUGO, pod_get_name_buf, line6_nop_write);
1009 static DEVICE_ATTR(retrieve_amp_setup, S_IWUSR, line6_nop_read,
1010 pod_set_retrieve_amp_setup);
1011 static DEVICE_ATTR(retrieve_channel, S_IWUSR, line6_nop_read,
1012 pod_set_retrieve_channel);
1013 static DEVICE_ATTR(retrieve_effects_setup, S_IWUSR, line6_nop_read,
1014 pod_set_retrieve_effects_setup);
1015 static DEVICE_ATTR(routing, S_IWUSR | S_IRUGO, pod_get_routing,
1017 static DEVICE_ATTR(serial_number, S_IRUGO, pod_get_serial_number,
1019 static DEVICE_ATTR(store_amp_setup, S_IWUSR, line6_nop_read,
1020 pod_set_store_amp_setup);
1021 static DEVICE_ATTR(store_channel, S_IWUSR, line6_nop_read,
1022 pod_set_store_channel);
1023 static DEVICE_ATTR(store_effects_setup, S_IWUSR, line6_nop_read,
1024 pod_set_store_effects_setup);
1025 static DEVICE_ATTR(tuner_freq, S_IWUSR | S_IRUGO, pod_get_tuner_freq,
1026 pod_set_tuner_freq);
1027 static DEVICE_ATTR(tuner_mute, S_IWUSR | S_IRUGO, pod_get_tuner_mute,
1028 pod_set_tuner_mute);
1029 static DEVICE_ATTR(tuner_note, S_IRUGO, pod_get_tuner_note, line6_nop_write);
1030 static DEVICE_ATTR(tuner_pitch, S_IRUGO, pod_get_tuner_pitch, line6_nop_write);
1032 #ifdef CONFIG_LINE6_USB_RAW
1033 static DEVICE_ATTR(raw, S_IWUSR, line6_nop_read, line6_set_raw);
1036 /* control info callback */
1037 static int snd_pod_control_monitor_info(struct snd_kcontrol *kcontrol,
1038 struct snd_ctl_elem_info *uinfo)
1040 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1042 uinfo->value.integer.min = 0;
1043 uinfo->value.integer.max = 65535;
1047 /* control get callback */
1048 static int snd_pod_control_monitor_get(struct snd_kcontrol *kcontrol,
1049 struct snd_ctl_elem_value *ucontrol)
1051 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
1052 struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6;
1053 ucontrol->value.integer.value[0] = pod->monitor_level.value;
1057 /* control put callback */
1058 static int snd_pod_control_monitor_put(struct snd_kcontrol *kcontrol,
1059 struct snd_ctl_elem_value *ucontrol)
1061 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
1062 struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6;
1064 if (ucontrol->value.integer.value[0] == pod->monitor_level.value)
1067 pod->monitor_level.value = ucontrol->value.integer.value[0];
1068 pod_set_system_param_int(pod, ucontrol->value.integer.value[0],
1073 /* control definition */
1074 static struct snd_kcontrol_new pod_control_monitor = {
1075 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1076 .name = "Monitor Playback Volume",
1078 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1079 .info = snd_pod_control_monitor_info,
1080 .get = snd_pod_control_monitor_get,
1081 .put = snd_pod_control_monitor_put
1087 static void pod_destruct(struct usb_interface *interface)
1089 struct usb_line6_pod *pod = usb_get_intfdata(interface);
1093 line6_cleanup_audio(&pod->line6);
1095 del_timer(&pod->startup_timer);
1096 cancel_work_sync(&pod->startup_work);
1098 /* free dump request data: */
1099 line6_dumpreq_destruct(&pod->dumpreq);
1103 Create sysfs entries.
1105 static int pod_create_files2(struct device *dev)
1109 CHECK_RETURN(device_create_file(dev, &dev_attr_clip));
1110 CHECK_RETURN(device_create_file(dev, &dev_attr_device_id));
1111 CHECK_RETURN(device_create_file(dev, &dev_attr_dirty));
1112 CHECK_RETURN(device_create_file(dev, &dev_attr_dump));
1113 CHECK_RETURN(device_create_file(dev, &dev_attr_dump_buf));
1114 CHECK_RETURN(device_create_file(dev, &dev_attr_finish));
1115 CHECK_RETURN(device_create_file(dev, &dev_attr_firmware_version));
1116 CHECK_RETURN(device_create_file(dev, &dev_attr_midi_postprocess));
1117 CHECK_RETURN(device_create_file(dev, &dev_attr_monitor_level));
1118 CHECK_RETURN(device_create_file(dev, &dev_attr_name));
1119 CHECK_RETURN(device_create_file(dev, &dev_attr_name_buf));
1120 CHECK_RETURN(device_create_file(dev, &dev_attr_retrieve_amp_setup));
1121 CHECK_RETURN(device_create_file(dev, &dev_attr_retrieve_channel));
1122 CHECK_RETURN(device_create_file(dev, &dev_attr_retrieve_effects_setup));
1123 CHECK_RETURN(device_create_file(dev, &dev_attr_routing));
1124 CHECK_RETURN(device_create_file(dev, &dev_attr_serial_number));
1125 CHECK_RETURN(device_create_file(dev, &dev_attr_store_amp_setup));
1126 CHECK_RETURN(device_create_file(dev, &dev_attr_store_channel));
1127 CHECK_RETURN(device_create_file(dev, &dev_attr_store_effects_setup));
1128 CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_freq));
1129 CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_mute));
1130 CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_note));
1131 CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_pitch));
1133 #ifdef CONFIG_LINE6_USB_RAW
1134 CHECK_RETURN(device_create_file(dev, &dev_attr_raw));
1141 Try to init POD device.
1143 static int pod_try_init(struct usb_interface *interface,
1144 struct usb_line6_pod *pod)
1147 struct usb_line6 *line6 = &pod->line6;
1149 init_timer(&pod->startup_timer);
1150 INIT_WORK(&pod->startup_work, pod_startup5);
1152 if ((interface == NULL) || (pod == NULL))
1155 /* initialize wait queues: */
1156 init_waitqueue_head(&pod->monitor_level.wait);
1157 init_waitqueue_head(&pod->routing.wait);
1158 init_waitqueue_head(&pod->tuner_mute.wait);
1159 init_waitqueue_head(&pod->tuner_freq.wait);
1160 init_waitqueue_head(&pod->tuner_note.wait);
1161 init_waitqueue_head(&pod->tuner_pitch.wait);
1162 init_waitqueue_head(&pod->clipping.wait);
1164 memset(pod->param_dirty, 0xff, sizeof(pod->param_dirty));
1166 /* initialize USB buffers: */
1167 err = line6_dumpreq_init(&pod->dumpreq, pod_request_channel,
1168 sizeof(pod_request_channel));
1170 dev_err(&interface->dev, "Out of memory\n");
1174 /* create sysfs entries: */
1175 err = pod_create_files2(&interface->dev);
1179 /* initialize audio system: */
1180 err = line6_init_audio(line6);
1184 /* initialize MIDI subsystem: */
1185 err = line6_init_midi(line6);
1189 /* initialize PCM subsystem: */
1190 err = line6_init_pcm(line6, &pod_pcm_properties);
1194 /* register monitor control: */
1195 err = snd_ctl_add(line6->card,
1196 snd_ctl_new1(&pod_control_monitor, line6->line6pcm));
1201 When the sound card is registered at this point, the PODxt Live
1202 displays "Invalid Code Error 07", so we do it later in the event
1206 if (pod->line6.properties->capabilities & LINE6_BIT_CONTROL) {
1207 pod->monitor_level.value = POD_system_invalid;
1209 /* initiate startup procedure: */
1217 Init POD device (and clean up in case of failure).
1219 int line6_pod_init(struct usb_interface *interface, struct usb_line6_pod *pod)
1221 int err = pod_try_init(interface, pod);
1224 pod_destruct(interface);
1230 POD device disconnected.
1232 void line6_pod_disconnect(struct usb_interface *interface)
1234 struct usb_line6_pod *pod;
1236 if (interface == NULL)
1238 pod = usb_get_intfdata(interface);
1241 struct snd_line6_pcm *line6pcm = pod->line6.line6pcm;
1242 struct device *dev = &interface->dev;
1244 if (line6pcm != NULL)
1245 line6_pcm_disconnect(line6pcm);
1248 /* remove sysfs entries: */
1249 line6_pod_remove_files(pod->firmware_version,
1251 properties->device_bit, dev);
1253 device_remove_file(dev, &dev_attr_clip);
1254 device_remove_file(dev, &dev_attr_device_id);
1255 device_remove_file(dev, &dev_attr_dirty);
1256 device_remove_file(dev, &dev_attr_dump);
1257 device_remove_file(dev, &dev_attr_dump_buf);
1258 device_remove_file(dev, &dev_attr_finish);
1259 device_remove_file(dev, &dev_attr_firmware_version);
1260 device_remove_file(dev, &dev_attr_midi_postprocess);
1261 device_remove_file(dev, &dev_attr_monitor_level);
1262 device_remove_file(dev, &dev_attr_name);
1263 device_remove_file(dev, &dev_attr_name_buf);
1264 device_remove_file(dev, &dev_attr_retrieve_amp_setup);
1265 device_remove_file(dev, &dev_attr_retrieve_channel);
1266 device_remove_file(dev,
1267 &dev_attr_retrieve_effects_setup);
1268 device_remove_file(dev, &dev_attr_routing);
1269 device_remove_file(dev, &dev_attr_serial_number);
1270 device_remove_file(dev, &dev_attr_store_amp_setup);
1271 device_remove_file(dev, &dev_attr_store_channel);
1272 device_remove_file(dev, &dev_attr_store_effects_setup);
1273 device_remove_file(dev, &dev_attr_tuner_freq);
1274 device_remove_file(dev, &dev_attr_tuner_mute);
1275 device_remove_file(dev, &dev_attr_tuner_note);
1276 device_remove_file(dev, &dev_attr_tuner_pitch);
1278 #ifdef CONFIG_LINE6_USB_RAW
1279 device_remove_file(dev, &dev_attr_raw);
1284 pod_destruct(interface);