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,
44 POD_tuner_mute = 0x13,
45 POD_tuner_freq = 0x15,
46 POD_tuner_note = 0x16,
47 POD_tuner_pitch = 0x17,
48 POD_system_invalid = 0x10000
65 static struct snd_ratden pod_ratden = {
72 static struct line6_pcm_properties pod_pcm_properties = {
73 .snd_line6_playback_hw = {
74 .info = (SNDRV_PCM_INFO_MMAP |
75 SNDRV_PCM_INFO_INTERLEAVED |
76 SNDRV_PCM_INFO_BLOCK_TRANSFER |
77 SNDRV_PCM_INFO_MMAP_VALID |
78 SNDRV_PCM_INFO_PAUSE |
80 SNDRV_PCM_INFO_RESUME |
82 SNDRV_PCM_INFO_SYNC_START),
83 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
84 .rates = SNDRV_PCM_RATE_KNOT,
89 .buffer_bytes_max = 60000,
90 .period_bytes_min = 64,
91 .period_bytes_max = 8192,
94 .snd_line6_capture_hw = {
95 .info = (SNDRV_PCM_INFO_MMAP |
96 SNDRV_PCM_INFO_INTERLEAVED |
97 SNDRV_PCM_INFO_BLOCK_TRANSFER |
98 SNDRV_PCM_INFO_MMAP_VALID |
100 SNDRV_PCM_INFO_RESUME |
102 SNDRV_PCM_INFO_SYNC_START),
103 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
104 .rates = SNDRV_PCM_RATE_KNOT,
109 .buffer_bytes_max = 60000,
110 .period_bytes_min = 64,
111 .period_bytes_max = 8192,
113 .periods_max = 1024},
116 .rats = &pod_ratden},
117 .bytes_per_frame = POD_BYTES_PER_FRAME
120 static const char pod_request_channel[] = {
121 0xf0, 0x00, 0x01, 0x0c, 0x03, 0x75, 0xf7
124 static const char pod_version_header[] = {
125 0xf2, 0x7e, 0x7f, 0x06, 0x02
128 /* forward declarations: */
129 static void pod_startup2(unsigned long data);
130 static void pod_startup3(struct usb_line6_pod *pod);
131 static void pod_startup4(struct usb_line6_pod *pod);
134 Mark all parameters as dirty and notify waiting processes.
136 static void pod_mark_batch_all_dirty(struct usb_line6_pod *pod)
140 for (i = 0; i < POD_CONTROL_SIZE; i++)
141 set_bit(i, pod->param_dirty);
144 static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code,
147 return line6_alloc_sysex_buffer(&pod->line6, POD_SYSEX_CODE, code,
152 Send channel dump data to the PODxt Pro.
154 static void pod_dump(struct usb_line6_pod *pod, const unsigned char *data)
156 int size = 1 + sizeof(pod->prog_data);
157 char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_DUMP, size);
160 /* Don't know what this is good for, but PODxt Pro transmits it, so we
162 sysex[SYSEX_DATA_OFS] = 5;
163 memcpy(sysex + SYSEX_DATA_OFS + 1, data, sizeof(pod->prog_data));
164 line6_send_sysex_message(&pod->line6, sysex, size);
165 memcpy(&pod->prog_data, data, sizeof(pod->prog_data));
166 pod_mark_batch_all_dirty(pod);
171 Store parameter value in driver memory and mark it as dirty.
173 static void pod_store_parameter(struct usb_line6_pod *pod, int param, int value)
175 pod->prog_data.control[param] = value;
176 set_bit(param, pod->param_dirty);
183 static void pod_save_button_pressed(struct usb_line6_pod *pod, int type,
187 set_bit(POD_SAVE_PRESSED, &pod->atomic_flags);
191 Process a completely received message.
193 void line6_pod_process_message(struct usb_line6_pod *pod)
195 const unsigned char *buf = pod->line6.buffer_message;
197 /* filter messages by type */
198 switch (buf[0] & 0xf0) {
199 case LINE6_PARAM_CHANGE:
200 case LINE6_PROGRAM_CHANGE:
201 case LINE6_SYSEX_BEGIN:
202 break; /* handle these further down */
205 return; /* ignore all others */
208 /* process all remaining messages */
210 case LINE6_PARAM_CHANGE | LINE6_CHANNEL_DEVICE:
211 pod_store_parameter(pod, buf[1], buf[2]);
212 /* intentionally no break here! */
214 case LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST:
215 if ((buf[1] == POD_amp_model_setup) ||
216 (buf[1] == POD_effect_setup))
217 /* these also affect other settings */
218 line6_dump_request_async(&pod->dumpreq, &pod->line6, 0,
223 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_DEVICE:
224 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST:
226 set_bit(POD_CHANNEL_DIRTY, &pod->atomic_flags);
227 line6_dump_request_async(&pod->dumpreq, &pod->line6, 0,
231 case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_DEVICE:
232 case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_UNKNOWN:
233 if (memcmp(buf + 1, line6_midi_id, sizeof(line6_midi_id)) == 0) {
236 if (pod->line6.message_length ==
237 sizeof(pod->prog_data) + 7) {
238 switch (pod->dumpreq.in_progress) {
239 case LINE6_DUMP_CURRENT:
240 memcpy(&pod->prog_data, buf + 7,
241 sizeof(pod->prog_data));
242 pod_mark_batch_all_dirty(pod);
245 case POD_DUMP_MEMORY:
246 memcpy(&pod->prog_data_buf,
249 (pod->prog_data_buf));
253 dev_dbg(pod->line6.ifcdev,
254 "unknown dump code %02X\n",
255 pod->dumpreq.in_progress);
258 line6_dump_finished(&pod->dumpreq);
261 dev_dbg(pod->line6.ifcdev,
262 "wrong size of channel dump message (%d instead of %d)\n",
263 pod->line6.message_length,
264 (int)sizeof(pod->prog_data) +
269 case POD_SYSEX_SYSTEM:{
271 ((int)buf[7] << 12) | ((int)buf[8]
273 ((int)buf[9] << 4) | (int)buf[10];
275 #define PROCESS_SYSTEM_PARAM(x) \
277 pod->x.value = value; \
278 wake_up(&pod->x.wait); \
284 PROCESS_SYSTEM_PARAM(routing);
294 #undef PROCESS_SYSTEM_PARAM
297 dev_dbg(pod->line6.ifcdev,
298 "unknown tuner/system response %02X\n",
305 case POD_SYSEX_FINISH:
306 /* do we need to respond to this? */
310 pod_save_button_pressed(pod, buf[6], buf[7]);
313 case POD_SYSEX_STORE:
314 dev_dbg(pod->line6.ifcdev,
315 "message %02X not yet implemented\n",
320 dev_dbg(pod->line6.ifcdev,
321 "unknown sysex message %02X\n",
326 (buf, pod_version_header,
327 sizeof(pod_version_header)) == 0) {
328 pod->firmware_version =
329 buf[13] * 100 + buf[14] * 10 + buf[15];
331 ((int)buf[8] << 16) | ((int)buf[9] << 8) | (int)
335 dev_dbg(pod->line6.ifcdev, "unknown sysex header\n");
339 case LINE6_SYSEX_END:
343 dev_dbg(pod->line6.ifcdev, "POD: unknown message %02X\n",
349 Detect some cases that require a channel dump after sending a command to the
350 device. Important notes:
351 *) The actual dump request can not be sent here since we are not allowed to
352 wait for the completion of the first message in this context, and sending
353 the dump request before completion of the previous message leaves the POD
354 in an undefined state. The dump request will be sent when the echoed
355 commands are received.
356 *) This method fails if a param change message is "chopped" after the first
359 void line6_pod_midi_postprocess(struct usb_line6_pod *pod, unsigned char *data,
364 if (!pod->midi_postprocess)
367 for (i = 0; i < length; ++i) {
368 if (data[i] == (LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST)) {
369 line6_invalidate_current(&pod->dumpreq);
372 if ((data[i] == (LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST))
374 if ((data[i + 1] == POD_amp_model_setup)
375 || (data[i + 1] == POD_effect_setup)) {
376 line6_invalidate_current(&pod->dumpreq);
383 Transmit PODxt Pro control parameter.
385 void line6_pod_transmit_parameter(struct usb_line6_pod *pod, int param,
388 if (line6_transmit_parameter(&pod->line6, param, value) == 0)
389 pod_store_parameter(pod, param, value);
391 if ((param == POD_amp_model_setup) || (param == POD_effect_setup)) /* these also affect other settings */
392 line6_invalidate_current(&pod->dumpreq);
396 Resolve value to memory location.
398 static int pod_resolve(const char *buf, short block0, short block1,
399 unsigned char *location)
405 ret = kstrtou8(buf, 10, &value);
409 block = (value < 0x40) ? block0 : block1;
411 location[0] = block >> 7;
412 location[1] = value | (block & 0x7f);
417 Send command to store channel/effects setup/amp setup to PODxt Pro.
419 static ssize_t pod_send_store_command(struct device *dev, const char *buf,
420 size_t count, short block0, short block1)
422 struct usb_interface *interface = to_usb_interface(dev);
423 struct usb_line6_pod *pod = usb_get_intfdata(interface);
425 int size = 3 + sizeof(pod->prog_data_buf);
426 char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_STORE, size);
431 sysex[SYSEX_DATA_OFS] = 5; /* see pod_dump() */
432 ret = pod_resolve(buf, block0, block1, sysex + SYSEX_DATA_OFS + 1);
438 memcpy(sysex + SYSEX_DATA_OFS + 3, &pod->prog_data_buf,
439 sizeof(pod->prog_data_buf));
441 line6_send_sysex_message(&pod->line6, sysex, size);
443 /* needs some delay here on AMD64 platform */
448 Send command to retrieve channel/effects setup/amp setup to PODxt Pro.
450 static ssize_t pod_send_retrieve_command(struct device *dev, const char *buf,
451 size_t count, short block0,
454 struct usb_interface *interface = to_usb_interface(dev);
455 struct usb_line6_pod *pod = usb_get_intfdata(interface);
458 char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_DUMPMEM, size);
463 ret = pod_resolve(buf, block0, block1, sysex + SYSEX_DATA_OFS);
468 sysex[SYSEX_DATA_OFS + 2] = 0;
469 sysex[SYSEX_DATA_OFS + 3] = 0;
470 line6_dump_started(&pod->dumpreq, POD_DUMP_MEMORY);
472 if (line6_send_sysex_message(&pod->line6, sysex, size) < size)
473 line6_dump_finished(&pod->dumpreq);
476 /* needs some delay here on AMD64 platform */
481 Generic get name function.
483 static ssize_t get_name_generic(struct usb_line6_pod *pod, const char *str,
489 char *last_non_space = buf;
491 int retval = line6_dump_wait_interruptible(&pod->dumpreq);
495 for (p1 = str, p2 = buf; *p1; ++p1, ++p2) {
499 if (++length == POD_NAME_LENGTH)
503 *(last_non_space + 1) = '\n';
504 return last_non_space - buf + 2;
508 "read" request on "name" special file.
510 static ssize_t pod_get_name(struct device *dev, struct device_attribute *attr,
513 struct usb_interface *interface = to_usb_interface(dev);
514 struct usb_line6_pod *pod = usb_get_intfdata(interface);
515 return get_name_generic(pod, pod->prog_data.header + POD_NAME_OFFSET,
520 "read" request on "name" special file.
522 static ssize_t pod_get_name_buf(struct device *dev,
523 struct device_attribute *attr, char *buf)
525 struct usb_interface *interface = to_usb_interface(dev);
526 struct usb_line6_pod *pod = usb_get_intfdata(interface);
527 return get_name_generic(pod,
528 pod->prog_data_buf.header + POD_NAME_OFFSET,
533 "read" request on "dump" special file.
535 static ssize_t pod_get_dump(struct device *dev, struct device_attribute *attr,
538 struct usb_interface *interface = to_usb_interface(dev);
539 struct usb_line6_pod *pod = usb_get_intfdata(interface);
540 int retval = line6_dump_wait_interruptible(&pod->dumpreq);
543 memcpy(buf, &pod->prog_data, sizeof(pod->prog_data));
544 return sizeof(pod->prog_data);
548 "write" request on "dump" special file.
550 static ssize_t pod_set_dump(struct device *dev, struct device_attribute *attr,
551 const char *buf, size_t count)
553 struct usb_interface *interface = to_usb_interface(dev);
554 struct usb_line6_pod *pod = usb_get_intfdata(interface);
556 if (count != sizeof(pod->prog_data)) {
557 dev_err(pod->line6.ifcdev,
558 "data block must be exactly %d bytes\n",
559 (int)sizeof(pod->prog_data));
564 return sizeof(pod->prog_data);
568 Identify system parameters related to the tuner.
570 static bool pod_is_tuner(int code)
573 (code == POD_tuner_mute) ||
574 (code == POD_tuner_freq) ||
575 (code == POD_tuner_note) || (code == POD_tuner_pitch);
579 Get system parameter (as integer).
580 @param tuner non-zero, if code refers to a tuner parameter
582 static int pod_get_system_param_int(struct usb_line6_pod *pod, int *value,
583 int code, struct ValueWait *param, int sign)
586 static const int size = 1;
589 if (((pod->prog_data.control[POD_tuner] & 0x40) == 0)
590 && pod_is_tuner(code))
593 /* send value request to device: */
594 param->value = POD_system_invalid;
595 sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEMREQ, size);
600 sysex[SYSEX_DATA_OFS] = code;
601 line6_send_sysex_message(&pod->line6, sysex, size);
604 /* wait for device to respond: */
606 wait_event_interruptible(param->wait,
607 param->value != POD_system_invalid);
612 *value = sign ? (int)(signed short)param->value : (int)(unsigned short)
615 if (*value == POD_system_invalid)
616 *value = 0; /* don't report uninitialized values */
622 Get system parameter (as string).
623 @param tuner non-zero, if code refers to a tuner parameter
625 static ssize_t pod_get_system_param_string(struct usb_line6_pod *pod, char *buf,
626 int code, struct ValueWait *param,
629 int retval, value = 0;
630 retval = pod_get_system_param_int(pod, &value, code, param, sign);
635 return sprintf(buf, "%d\n", value);
639 Send system parameter (from integer).
640 @param tuner non-zero, if code refers to a tuner parameter
642 static int pod_set_system_param_int(struct usb_line6_pod *pod, int value,
646 static const int size = 5;
648 if (((pod->prog_data.control[POD_tuner] & 0x40) == 0)
649 && pod_is_tuner(code))
652 /* send value to tuner: */
653 sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEM, size);
656 sysex[SYSEX_DATA_OFS] = code;
657 sysex[SYSEX_DATA_OFS + 1] = (value >> 12) & 0x0f;
658 sysex[SYSEX_DATA_OFS + 2] = (value >> 8) & 0x0f;
659 sysex[SYSEX_DATA_OFS + 3] = (value >> 4) & 0x0f;
660 sysex[SYSEX_DATA_OFS + 4] = (value) & 0x0f;
661 line6_send_sysex_message(&pod->line6, sysex, size);
667 Send system parameter (from string).
668 @param tuner non-zero, if code refers to a tuner parameter
670 static ssize_t pod_set_system_param_string(struct usb_line6_pod *pod,
671 const char *buf, int count, int code,
675 unsigned short value = simple_strtoul(buf, NULL, 10) & mask;
676 retval = pod_set_system_param_int(pod, value, code);
677 return (retval < 0) ? retval : count;
681 "read" request on "dump_buf" special file.
683 static ssize_t pod_get_dump_buf(struct device *dev,
684 struct device_attribute *attr, char *buf)
686 struct usb_interface *interface = to_usb_interface(dev);
687 struct usb_line6_pod *pod = usb_get_intfdata(interface);
688 int retval = line6_dump_wait_interruptible(&pod->dumpreq);
691 memcpy(buf, &pod->prog_data_buf, sizeof(pod->prog_data_buf));
692 return sizeof(pod->prog_data_buf);
696 "write" request on "dump_buf" special file.
698 static ssize_t pod_set_dump_buf(struct device *dev,
699 struct device_attribute *attr,
700 const char *buf, size_t count)
702 struct usb_interface *interface = to_usb_interface(dev);
703 struct usb_line6_pod *pod = usb_get_intfdata(interface);
705 if (count != sizeof(pod->prog_data)) {
706 dev_err(pod->line6.ifcdev,
707 "data block must be exactly %d bytes\n",
708 (int)sizeof(pod->prog_data));
712 memcpy(&pod->prog_data_buf, buf, sizeof(pod->prog_data));
713 return sizeof(pod->prog_data);
717 "write" request on "finish" special file.
719 static ssize_t pod_set_finish(struct device *dev,
720 struct device_attribute *attr,
721 const char *buf, size_t count)
723 struct usb_interface *interface = to_usb_interface(dev);
724 struct usb_line6_pod *pod = usb_get_intfdata(interface);
726 char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_FINISH, size);
729 line6_send_sysex_message(&pod->line6, sysex, size);
735 "write" request on "store_channel" special file.
737 static ssize_t pod_set_store_channel(struct device *dev,
738 struct device_attribute *attr,
739 const char *buf, size_t count)
741 return pod_send_store_command(dev, buf, count, 0x0000, 0x00c0);
745 "write" request on "store_effects_setup" special file.
747 static ssize_t pod_set_store_effects_setup(struct device *dev,
748 struct device_attribute *attr,
749 const char *buf, size_t count)
751 return pod_send_store_command(dev, buf, count, 0x0080, 0x0080);
755 "write" request on "store_amp_setup" special file.
757 static ssize_t pod_set_store_amp_setup(struct device *dev,
758 struct device_attribute *attr,
759 const char *buf, size_t count)
761 return pod_send_store_command(dev, buf, count, 0x0040, 0x0100);
765 "write" request on "retrieve_channel" special file.
767 static ssize_t pod_set_retrieve_channel(struct device *dev,
768 struct device_attribute *attr,
769 const char *buf, size_t count)
771 return pod_send_retrieve_command(dev, buf, count, 0x0000, 0x00c0);
775 "write" request on "retrieve_effects_setup" special file.
777 static ssize_t pod_set_retrieve_effects_setup(struct device *dev,
778 struct device_attribute *attr,
779 const char *buf, size_t count)
781 return pod_send_retrieve_command(dev, buf, count, 0x0080, 0x0080);
785 "write" request on "retrieve_amp_setup" special file.
787 static ssize_t pod_set_retrieve_amp_setup(struct device *dev,
788 struct device_attribute *attr,
789 const char *buf, size_t count)
791 return pod_send_retrieve_command(dev, buf, count, 0x0040, 0x0100);
795 "read" request on "dirty" special file.
797 static ssize_t pod_get_dirty(struct device *dev, struct device_attribute *attr,
800 struct usb_interface *interface = to_usb_interface(dev);
801 struct usb_line6_pod *pod = usb_get_intfdata(interface);
802 buf[0] = pod->dirty ? '1' : '0';
808 "read" request on "midi_postprocess" special file.
810 static ssize_t pod_get_midi_postprocess(struct device *dev,
811 struct device_attribute *attr,
814 struct usb_interface *interface = to_usb_interface(dev);
815 struct usb_line6_pod *pod = usb_get_intfdata(interface);
816 return sprintf(buf, "%d\n", pod->midi_postprocess);
820 "write" request on "midi_postprocess" special file.
822 static ssize_t pod_set_midi_postprocess(struct device *dev,
823 struct device_attribute *attr,
824 const char *buf, size_t count)
826 struct usb_interface *interface = to_usb_interface(dev);
827 struct usb_line6_pod *pod = usb_get_intfdata(interface);
831 ret = kstrtou8(buf, 10, &value);
835 pod->midi_postprocess = value ? 1 : 0;
840 "read" request on "serial_number" special file.
842 static ssize_t pod_get_serial_number(struct device *dev,
843 struct device_attribute *attr, char *buf)
845 struct usb_interface *interface = to_usb_interface(dev);
846 struct usb_line6_pod *pod = usb_get_intfdata(interface);
847 return sprintf(buf, "%d\n", pod->serial_number);
851 "read" request on "firmware_version" special file.
853 static ssize_t pod_get_firmware_version(struct device *dev,
854 struct device_attribute *attr,
857 struct usb_interface *interface = to_usb_interface(dev);
858 struct usb_line6_pod *pod = usb_get_intfdata(interface);
859 return sprintf(buf, "%d.%02d\n", pod->firmware_version / 100,
860 pod->firmware_version % 100);
864 "read" request on "device_id" special file.
866 static ssize_t pod_get_device_id(struct device *dev,
867 struct device_attribute *attr, char *buf)
869 struct usb_interface *interface = to_usb_interface(dev);
870 struct usb_line6_pod *pod = usb_get_intfdata(interface);
871 return sprintf(buf, "%d\n", pod->device_id);
875 POD startup procedure.
876 This is a sequence of functions with special requirements (e.g., must
877 not run immediately after initialization, must not run in interrupt
878 context). After the last one has finished, the device is ready to use.
881 static void pod_startup1(struct usb_line6_pod *pod)
883 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_INIT);
885 /* delay startup procedure: */
886 line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2,
890 static void pod_startup2(unsigned long data)
892 struct usb_line6_pod *pod = (struct usb_line6_pod *)data;
894 /* schedule another startup procedure until startup is complete: */
895 if (pod->startup_progress >= POD_STARTUP_LAST)
898 pod->startup_progress = POD_STARTUP_DUMPREQ;
899 line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2,
902 /* current channel dump: */
903 line6_dump_request_async(&pod->dumpreq, &pod->line6, 0,
907 static void pod_startup3(struct usb_line6_pod *pod)
909 struct usb_line6 *line6 = &pod->line6;
910 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_VERSIONREQ);
912 /* request firmware version: */
913 line6_version_request_async(line6);
916 static void pod_startup4(struct usb_line6_pod *pod)
918 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_WORKQUEUE);
920 /* schedule work for global work queue: */
921 schedule_work(&pod->startup_work);
924 static void pod_startup5(struct work_struct *work)
926 struct usb_line6_pod *pod =
927 container_of(work, struct usb_line6_pod, startup_work);
928 struct usb_line6 *line6 = &pod->line6;
930 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_SETUP);
933 line6_read_serial_number(&pod->line6, &pod->serial_number);
935 /* ALSA audio interface: */
936 line6_register_audio(line6);
939 line6_pod_create_files(pod->firmware_version,
940 line6->properties->device_bit, line6->ifcdev);
943 #define POD_GET_SYSTEM_PARAM(code, sign) \
944 static ssize_t pod_get_ ## code(struct device *dev, \
945 struct device_attribute *attr, char *buf) \
947 struct usb_interface *interface = to_usb_interface(dev); \
948 struct usb_line6_pod *pod = usb_get_intfdata(interface); \
949 return pod_get_system_param_string(pod, buf, POD_ ## code, \
953 #define POD_GET_SET_SYSTEM_PARAM(code, mask, sign) \
954 POD_GET_SYSTEM_PARAM(code, sign) \
955 static ssize_t pod_set_ ## code(struct device *dev, \
956 struct device_attribute *attr, \
957 const char *buf, size_t count) \
959 struct usb_interface *interface = to_usb_interface(dev); \
960 struct usb_line6_pod *pod = usb_get_intfdata(interface); \
961 return pod_set_system_param_string(pod, buf, count, POD_ ## code, mask); \
964 POD_GET_SET_SYSTEM_PARAM(monitor_level, 0xffff, 0);
965 POD_GET_SET_SYSTEM_PARAM(routing, 0x0003, 0);
966 POD_GET_SET_SYSTEM_PARAM(tuner_mute, 0x0001, 0);
967 POD_GET_SET_SYSTEM_PARAM(tuner_freq, 0xffff, 0);
968 POD_GET_SYSTEM_PARAM(tuner_note, 1);
969 POD_GET_SYSTEM_PARAM(tuner_pitch, 1);
971 #undef GET_SET_SYSTEM_PARAM
972 #undef GET_SYSTEM_PARAM
974 /* POD special files: */
975 static DEVICE_ATTR(device_id, S_IRUGO, pod_get_device_id, line6_nop_write);
976 static DEVICE_ATTR(dirty, S_IRUGO, pod_get_dirty, line6_nop_write);
977 static DEVICE_ATTR(dump, S_IWUSR | S_IRUGO, pod_get_dump, pod_set_dump);
978 static DEVICE_ATTR(dump_buf, S_IWUSR | S_IRUGO, pod_get_dump_buf,
980 static DEVICE_ATTR(finish, S_IWUSR, line6_nop_read, pod_set_finish);
981 static DEVICE_ATTR(firmware_version, S_IRUGO, pod_get_firmware_version,
983 static DEVICE_ATTR(midi_postprocess, S_IWUSR | S_IRUGO,
984 pod_get_midi_postprocess, pod_set_midi_postprocess);
985 static DEVICE_ATTR(monitor_level, S_IWUSR | S_IRUGO, pod_get_monitor_level,
986 pod_set_monitor_level);
987 static DEVICE_ATTR(name, S_IRUGO, pod_get_name, line6_nop_write);
988 static DEVICE_ATTR(name_buf, S_IRUGO, pod_get_name_buf, line6_nop_write);
989 static DEVICE_ATTR(retrieve_amp_setup, S_IWUSR, line6_nop_read,
990 pod_set_retrieve_amp_setup);
991 static DEVICE_ATTR(retrieve_channel, S_IWUSR, line6_nop_read,
992 pod_set_retrieve_channel);
993 static DEVICE_ATTR(retrieve_effects_setup, S_IWUSR, line6_nop_read,
994 pod_set_retrieve_effects_setup);
995 static DEVICE_ATTR(routing, S_IWUSR | S_IRUGO, pod_get_routing,
997 static DEVICE_ATTR(serial_number, S_IRUGO, pod_get_serial_number,
999 static DEVICE_ATTR(store_amp_setup, S_IWUSR, line6_nop_read,
1000 pod_set_store_amp_setup);
1001 static DEVICE_ATTR(store_channel, S_IWUSR, line6_nop_read,
1002 pod_set_store_channel);
1003 static DEVICE_ATTR(store_effects_setup, S_IWUSR, line6_nop_read,
1004 pod_set_store_effects_setup);
1005 static DEVICE_ATTR(tuner_freq, S_IWUSR | S_IRUGO, pod_get_tuner_freq,
1006 pod_set_tuner_freq);
1007 static DEVICE_ATTR(tuner_mute, S_IWUSR | S_IRUGO, pod_get_tuner_mute,
1008 pod_set_tuner_mute);
1009 static DEVICE_ATTR(tuner_note, S_IRUGO, pod_get_tuner_note, line6_nop_write);
1010 static DEVICE_ATTR(tuner_pitch, S_IRUGO, pod_get_tuner_pitch, line6_nop_write);
1012 #ifdef CONFIG_LINE6_USB_RAW
1013 static DEVICE_ATTR(raw, S_IWUSR, line6_nop_read, line6_set_raw);
1016 /* control info callback */
1017 static int snd_pod_control_monitor_info(struct snd_kcontrol *kcontrol,
1018 struct snd_ctl_elem_info *uinfo)
1020 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1022 uinfo->value.integer.min = 0;
1023 uinfo->value.integer.max = 65535;
1027 /* control get callback */
1028 static int snd_pod_control_monitor_get(struct snd_kcontrol *kcontrol,
1029 struct snd_ctl_elem_value *ucontrol)
1031 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
1032 struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6;
1033 ucontrol->value.integer.value[0] = pod->monitor_level.value;
1037 /* control put callback */
1038 static int snd_pod_control_monitor_put(struct snd_kcontrol *kcontrol,
1039 struct snd_ctl_elem_value *ucontrol)
1041 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
1042 struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6;
1044 if (ucontrol->value.integer.value[0] == pod->monitor_level.value)
1047 pod->monitor_level.value = ucontrol->value.integer.value[0];
1048 pod_set_system_param_int(pod, ucontrol->value.integer.value[0],
1053 /* control definition */
1054 static struct snd_kcontrol_new pod_control_monitor = {
1055 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1056 .name = "Monitor Playback Volume",
1058 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1059 .info = snd_pod_control_monitor_info,
1060 .get = snd_pod_control_monitor_get,
1061 .put = snd_pod_control_monitor_put
1067 static void pod_destruct(struct usb_interface *interface)
1069 struct usb_line6_pod *pod = usb_get_intfdata(interface);
1073 line6_cleanup_audio(&pod->line6);
1075 del_timer(&pod->startup_timer);
1076 cancel_work_sync(&pod->startup_work);
1078 /* free dump request data: */
1079 line6_dumpreq_destruct(&pod->dumpreq);
1083 Create sysfs entries.
1085 static int pod_create_files2(struct device *dev)
1089 CHECK_RETURN(device_create_file(dev, &dev_attr_device_id));
1090 CHECK_RETURN(device_create_file(dev, &dev_attr_dirty));
1091 CHECK_RETURN(device_create_file(dev, &dev_attr_dump));
1092 CHECK_RETURN(device_create_file(dev, &dev_attr_dump_buf));
1093 CHECK_RETURN(device_create_file(dev, &dev_attr_finish));
1094 CHECK_RETURN(device_create_file(dev, &dev_attr_firmware_version));
1095 CHECK_RETURN(device_create_file(dev, &dev_attr_midi_postprocess));
1096 CHECK_RETURN(device_create_file(dev, &dev_attr_monitor_level));
1097 CHECK_RETURN(device_create_file(dev, &dev_attr_name));
1098 CHECK_RETURN(device_create_file(dev, &dev_attr_name_buf));
1099 CHECK_RETURN(device_create_file(dev, &dev_attr_retrieve_amp_setup));
1100 CHECK_RETURN(device_create_file(dev, &dev_attr_retrieve_channel));
1101 CHECK_RETURN(device_create_file(dev, &dev_attr_retrieve_effects_setup));
1102 CHECK_RETURN(device_create_file(dev, &dev_attr_routing));
1103 CHECK_RETURN(device_create_file(dev, &dev_attr_serial_number));
1104 CHECK_RETURN(device_create_file(dev, &dev_attr_store_amp_setup));
1105 CHECK_RETURN(device_create_file(dev, &dev_attr_store_channel));
1106 CHECK_RETURN(device_create_file(dev, &dev_attr_store_effects_setup));
1107 CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_freq));
1108 CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_mute));
1109 CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_note));
1110 CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_pitch));
1112 #ifdef CONFIG_LINE6_USB_RAW
1113 CHECK_RETURN(device_create_file(dev, &dev_attr_raw));
1120 Try to init POD device.
1122 static int pod_try_init(struct usb_interface *interface,
1123 struct usb_line6_pod *pod)
1126 struct usb_line6 *line6 = &pod->line6;
1128 init_timer(&pod->startup_timer);
1129 INIT_WORK(&pod->startup_work, pod_startup5);
1131 if ((interface == NULL) || (pod == NULL))
1134 /* initialize wait queues: */
1135 init_waitqueue_head(&pod->monitor_level.wait);
1136 init_waitqueue_head(&pod->routing.wait);
1137 init_waitqueue_head(&pod->tuner_mute.wait);
1138 init_waitqueue_head(&pod->tuner_freq.wait);
1139 init_waitqueue_head(&pod->tuner_note.wait);
1140 init_waitqueue_head(&pod->tuner_pitch.wait);
1142 memset(pod->param_dirty, 0xff, sizeof(pod->param_dirty));
1144 /* initialize USB buffers: */
1145 err = line6_dumpreq_init(&pod->dumpreq, pod_request_channel,
1146 sizeof(pod_request_channel));
1148 dev_err(&interface->dev, "Out of memory\n");
1152 /* create sysfs entries: */
1153 err = pod_create_files2(&interface->dev);
1157 /* initialize audio system: */
1158 err = line6_init_audio(line6);
1162 /* initialize MIDI subsystem: */
1163 err = line6_init_midi(line6);
1167 /* initialize PCM subsystem: */
1168 err = line6_init_pcm(line6, &pod_pcm_properties);
1172 /* register monitor control: */
1173 err = snd_ctl_add(line6->card,
1174 snd_ctl_new1(&pod_control_monitor, line6->line6pcm));
1179 When the sound card is registered at this point, the PODxt Live
1180 displays "Invalid Code Error 07", so we do it later in the event
1184 if (pod->line6.properties->capabilities & LINE6_BIT_CONTROL) {
1185 pod->monitor_level.value = POD_system_invalid;
1187 /* initiate startup procedure: */
1195 Init POD device (and clean up in case of failure).
1197 int line6_pod_init(struct usb_interface *interface, struct usb_line6_pod *pod)
1199 int err = pod_try_init(interface, pod);
1202 pod_destruct(interface);
1208 POD device disconnected.
1210 void line6_pod_disconnect(struct usb_interface *interface)
1212 struct usb_line6_pod *pod;
1214 if (interface == NULL)
1216 pod = usb_get_intfdata(interface);
1219 struct snd_line6_pcm *line6pcm = pod->line6.line6pcm;
1220 struct device *dev = &interface->dev;
1222 if (line6pcm != NULL)
1223 line6_pcm_disconnect(line6pcm);
1226 /* remove sysfs entries: */
1227 line6_pod_remove_files(pod->firmware_version,
1229 properties->device_bit, dev);
1231 device_remove_file(dev, &dev_attr_device_id);
1232 device_remove_file(dev, &dev_attr_dirty);
1233 device_remove_file(dev, &dev_attr_dump);
1234 device_remove_file(dev, &dev_attr_dump_buf);
1235 device_remove_file(dev, &dev_attr_finish);
1236 device_remove_file(dev, &dev_attr_firmware_version);
1237 device_remove_file(dev, &dev_attr_midi_postprocess);
1238 device_remove_file(dev, &dev_attr_monitor_level);
1239 device_remove_file(dev, &dev_attr_name);
1240 device_remove_file(dev, &dev_attr_name_buf);
1241 device_remove_file(dev, &dev_attr_retrieve_amp_setup);
1242 device_remove_file(dev, &dev_attr_retrieve_channel);
1243 device_remove_file(dev,
1244 &dev_attr_retrieve_effects_setup);
1245 device_remove_file(dev, &dev_attr_routing);
1246 device_remove_file(dev, &dev_attr_serial_number);
1247 device_remove_file(dev, &dev_attr_store_amp_setup);
1248 device_remove_file(dev, &dev_attr_store_channel);
1249 device_remove_file(dev, &dev_attr_store_effects_setup);
1250 device_remove_file(dev, &dev_attr_tuner_freq);
1251 device_remove_file(dev, &dev_attr_tuner_mute);
1252 device_remove_file(dev, &dev_attr_tuner_note);
1253 device_remove_file(dev, &dev_attr_tuner_pitch);
1255 #ifdef CONFIG_LINE6_USB_RAW
1256 device_remove_file(dev, &dev_attr_raw);
1261 pod_destruct(interface);