2 * Line6 Linux USB driver - 0.8.0
4 * Copyright (C) 2004-2009 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.
14 #include <linux/slab.h>
23 #define POD_SYSEX_CODE 3
24 #define POD_BYTES_PER_FRAME 6 /* 24bit audio (stereo) */
28 POD_SYSEX_CLIP
= 0x0f,
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
= 0x7fff
64 static struct snd_ratden pod_ratden
= {
71 static struct line6_pcm_properties pod_pcm_properties
= {
72 .snd_line6_playback_hw
= {
73 .info
= (SNDRV_PCM_INFO_MMAP
|
74 SNDRV_PCM_INFO_INTERLEAVED
|
75 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
76 SNDRV_PCM_INFO_MMAP_VALID
|
77 SNDRV_PCM_INFO_PAUSE
|
78 SNDRV_PCM_INFO_SYNC_START
),
79 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
80 .rates
= SNDRV_PCM_RATE_KNOT
,
85 .buffer_bytes_max
= 60000,
86 .period_bytes_min
= LINE6_ISO_PACKET_SIZE_MAX
* POD_BYTES_PER_FRAME
, /* at least one URB must fit into one period */
87 .period_bytes_max
= 8192,
91 .snd_line6_capture_hw
= {
92 .info
= (SNDRV_PCM_INFO_MMAP
|
93 SNDRV_PCM_INFO_INTERLEAVED
|
94 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
95 SNDRV_PCM_INFO_MMAP_VALID
|
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
= LINE6_ISO_PACKET_SIZE_MAX
* POD_BYTES_PER_FRAME
, /* at least one URB must fit into one period */
105 .period_bytes_max
= 8192,
113 .bytes_per_frame
= POD_BYTES_PER_FRAME
116 static const char pod_request_version
[] = { 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7 };
117 static const char pod_request_channel
[] = { 0xf0, 0x00, 0x01, 0x0c, 0x03, 0x75, 0xf7 };
118 static const char pod_version_header
[] = { 0xf2, 0x7e, 0x7f, 0x06, 0x02 };
122 Mark all parameters as dirty and notify waiting processes.
124 static void pod_mark_batch_all_dirty(struct usb_line6_pod
*pod
)
128 for (i
= 0; i
< POD_CONTROL_SIZE
; i
++)
129 set_bit(i
, pod
->param_dirty
);
133 Send an asynchronous request for the POD firmware version and device ID.
135 static int pod_version_request_async(struct usb_line6_pod
*pod
)
137 return line6_send_raw_message_async(&pod
->line6
, pod
->buffer_versionreq
, sizeof(pod_request_version
));
140 static void pod_create_files_work(struct work_struct
*work
)
142 struct usb_line6_pod
*pod
= container_of(work
, struct usb_line6_pod
, create_files_work
);
144 pod_create_files(pod
->firmware_version
, pod
->line6
.properties
->device_bit
, pod
->line6
.ifcdev
);
147 static void pod_startup_timeout(unsigned long arg
)
155 int request
= REQUEST_NONE
;
156 struct usb_line6_pod
*pod
= (struct usb_line6_pod
*)arg
;
158 if (pod
->dumpreq
.ok
) {
159 if (!pod
->versionreq_ok
)
160 request
= REQUEST_VERSION
;
162 if (pod
->versionreq_ok
)
163 request
= REQUEST_DUMP
;
164 else if (pod
->startup_count
++ & 1)
165 request
= REQUEST_DUMP
;
167 request
= REQUEST_VERSION
;
172 line6_dump_request_async(&pod
->dumpreq
, &pod
->line6
, 0);
175 case REQUEST_VERSION
:
176 pod_version_request_async(pod
);
183 line6_startup_delayed(&pod
->dumpreq
, 1, pod_startup_timeout
, pod
);
186 static char *pod_alloc_sysex_buffer(struct usb_line6_pod
*pod
, int code
, int size
)
188 return line6_alloc_sysex_buffer(&pod
->line6
, POD_SYSEX_CODE
, code
, size
);
192 Send channel dump data to the PODxt Pro.
194 static void pod_dump(struct usb_line6_pod
*pod
, const unsigned char *data
)
196 int size
= 1 + sizeof(pod
->prog_data
);
197 char *sysex
= pod_alloc_sysex_buffer(pod
, POD_SYSEX_DUMP
, size
);
200 /* Don't know what this is good for, but PODxt Pro transmits it, so we
202 sysex
[SYSEX_DATA_OFS
] = 5;
203 memcpy(sysex
+ SYSEX_DATA_OFS
+ 1, data
, sizeof(pod
->prog_data
));
204 line6_send_sysex_message(&pod
->line6
, sysex
, size
);
205 memcpy(&pod
->prog_data
, data
, sizeof(pod
->prog_data
));
206 pod_mark_batch_all_dirty(pod
);
211 Store parameter value in driver memory and mark it as dirty.
213 static void pod_store_parameter(struct usb_line6_pod
*pod
, int param
, int value
)
215 pod
->prog_data
.control
[param
] = value
;
216 set_bit(param
, pod
->param_dirty
);
223 static void pod_save_button_pressed(struct usb_line6_pod
*pod
, int type
, int index
)
226 set_bit(POD_SAVE_PRESSED
, &pod
->atomic_flags
);
230 Process a completely received message.
232 void pod_process_message(struct usb_line6_pod
*pod
)
234 const unsigned char *buf
= pod
->line6
.buffer_message
;
236 /* filter messages by type */
237 switch (buf
[0] & 0xf0) {
238 case LINE6_PARAM_CHANGE
:
239 case LINE6_PROGRAM_CHANGE
:
240 case LINE6_SYSEX_BEGIN
:
241 break; /* handle these further down */
244 return; /* ignore all others */
247 /* process all remaining messages */
249 case LINE6_PARAM_CHANGE
| LINE6_CHANNEL_DEVICE
:
250 pod_store_parameter(pod
, buf
[1], buf
[2]);
251 /* intentionally no break here! */
253 case LINE6_PARAM_CHANGE
| LINE6_CHANNEL_HOST
:
254 if ((buf
[1] == POD_amp_model_setup
) ||
255 (buf
[1] == POD_effect_setup
))
256 /* these also affect other settings */
257 line6_dump_request_async(&pod
->dumpreq
, &pod
->line6
, 0);
261 case LINE6_PROGRAM_CHANGE
| LINE6_CHANNEL_DEVICE
:
262 case LINE6_PROGRAM_CHANGE
| LINE6_CHANNEL_HOST
:
263 pod
->channel_num
= buf
[1];
265 set_bit(POD_CHANNEL_DIRTY
, &pod
->atomic_flags
);
266 line6_dump_request_async(&pod
->dumpreq
, &pod
->line6
, 0);
269 case LINE6_SYSEX_BEGIN
| LINE6_CHANNEL_DEVICE
:
270 case LINE6_SYSEX_BEGIN
| LINE6_CHANNEL_UNKNOWN
:
271 if (memcmp(buf
+ 1, line6_midi_id
, sizeof(line6_midi_id
)) == 0) {
274 if (pod
->line6
.message_length
== sizeof(pod
->prog_data
) + 7) {
275 switch (pod
->dumpreq
.in_progress
) {
276 case LINE6_DUMP_CURRENT
:
277 memcpy(&pod
->prog_data
, buf
+ 7, sizeof(pod
->prog_data
));
278 pod_mark_batch_all_dirty(pod
);
282 case POD_DUMP_MEMORY
:
283 memcpy(&pod
->prog_data_buf
, buf
+ 7, sizeof(pod
->prog_data_buf
));
287 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "unknown dump code %02X\n", pod
->dumpreq
.in_progress
));
290 line6_dump_finished(&pod
->dumpreq
);
292 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "wrong size of channel dump message (%d instead of %d)\n",
293 pod
->line6
.message_length
, (int)sizeof(pod
->prog_data
) + 7));
297 case POD_SYSEX_SYSTEM
: {
298 short value
= ((int)buf
[7] << 12) | ((int)buf
[8] << 8) | ((int)buf
[9] << 4) | (int)buf
[10];
300 #define PROCESS_SYSTEM_PARAM(x) \
302 pod->x.value = value; \
303 wake_up_interruptible(&pod->x.wait); \
307 PROCESS_SYSTEM_PARAM(monitor_level
);
308 PROCESS_SYSTEM_PARAM(routing
);
309 PROCESS_SYSTEM_PARAM(tuner_mute
);
310 PROCESS_SYSTEM_PARAM(tuner_freq
);
311 PROCESS_SYSTEM_PARAM(tuner_note
);
312 PROCESS_SYSTEM_PARAM(tuner_pitch
);
314 #undef PROCESS_SYSTEM_PARAM
317 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "unknown tuner/system response %02X\n", buf
[6]));
323 case POD_SYSEX_FINISH
:
324 /* do we need to respond to this? */
328 pod_save_button_pressed(pod
, buf
[6], buf
[7]);
332 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "audio clipped\n"));
333 pod
->clipping
.value
= 1;
334 wake_up_interruptible(&pod
->clipping
.wait
);
337 case POD_SYSEX_STORE
:
338 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "message %02X not yet implemented\n", buf
[5]));
342 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "unknown sysex message %02X\n", buf
[5]));
344 } else if (memcmp(buf
, pod_version_header
, sizeof(pod_version_header
)) == 0) {
345 if (pod
->versionreq_ok
== 0) {
346 pod
->firmware_version
= buf
[13] * 100 + buf
[14] * 10 + buf
[15];
347 pod
->device_id
= ((int)buf
[8] << 16) | ((int)buf
[9] << 8) | (int)buf
[10];
348 pod
->versionreq_ok
= 1;
350 /* Now we know the firmware version, so we schedule a bottom half
351 handler to create the special files: */
352 INIT_WORK(&pod
->create_files_work
, pod_create_files_work
);
353 queue_work(line6_workqueue
, &pod
->create_files_work
);
355 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "multiple firmware version message\n"));
357 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "unknown sysex header\n"));
361 case LINE6_SYSEX_END
:
365 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "POD: unknown message %02X\n", buf
[0]));
370 Detect some cases that require a channel dump after sending a command to the
371 device. Important notes:
372 *) The actual dump request can not be sent here since we are not allowed to
373 wait for the completion of the first message in this context, and sending
374 the dump request before completion of the previous message leaves the POD
375 in an undefined state. The dump request will be sent when the echoed
376 commands are received.
377 *) This method fails if a param change message is "chopped" after the first
380 void pod_midi_postprocess(struct usb_line6_pod
*pod
, unsigned char *data
, int length
)
384 if (!pod
->midi_postprocess
)
387 for (i
= 0; i
< length
; ++i
) {
388 if (data
[i
] == (LINE6_PROGRAM_CHANGE
| LINE6_CHANNEL_HOST
)) {
389 line6_invalidate_current(&pod
->dumpreq
);
391 } else if ((data
[i
] == (LINE6_PARAM_CHANGE
| LINE6_CHANNEL_HOST
)) && (i
< length
- 1))
392 if ((data
[i
+ 1] == POD_amp_model_setup
) || (data
[i
+ 1] == POD_effect_setup
)) {
393 line6_invalidate_current(&pod
->dumpreq
);
400 Send channel number (i.e., switch to a different sound).
402 static void pod_send_channel(struct usb_line6_pod
*pod
, int value
)
404 line6_invalidate_current(&pod
->dumpreq
);
406 if (line6_send_program(&pod
->line6
, value
) == 0)
407 pod
->channel_num
= value
;
409 line6_dump_finished(&pod
->dumpreq
);
413 Transmit PODxt Pro control parameter.
415 void pod_transmit_parameter(struct usb_line6_pod
*pod
, int param
, int value
)
417 if (line6_transmit_parameter(&pod
->line6
, param
, value
) == 0)
418 pod_store_parameter(pod
, param
, value
);
420 if ((param
== POD_amp_model_setup
) || (param
== POD_effect_setup
)) /* these also affect other settings */
421 line6_invalidate_current(&pod
->dumpreq
);
425 Resolve value to memory location.
427 static int pod_resolve(const char *buf
, short block0
, short block1
, unsigned char *location
)
433 ret
= strict_strtoul(buf
, 10, &value
);
437 block
= (value
< 0x40) ? block0
: block1
;
439 location
[0] = block
>> 7;
440 location
[1] = value
| (block
& 0x7f);
445 Send command to store channel/effects setup/amp setup to PODxt Pro.
447 static ssize_t
pod_send_store_command(struct device
*dev
, const char *buf
, size_t count
, short block0
, short block1
)
449 struct usb_interface
*interface
= to_usb_interface(dev
);
450 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
452 int size
= 3 + sizeof(pod
->prog_data_buf
);
453 char *sysex
= pod_alloc_sysex_buffer(pod
, POD_SYSEX_STORE
, size
);
458 sysex
[SYSEX_DATA_OFS
] = 5; /* see pod_dump() */
459 ret
= pod_resolve(buf
, block0
, block1
, sysex
+ SYSEX_DATA_OFS
+ 1);
465 memcpy(sysex
+ SYSEX_DATA_OFS
+ 3, &pod
->prog_data_buf
, sizeof(pod
->prog_data_buf
));
467 line6_send_sysex_message(&pod
->line6
, sysex
, size
);
469 /* needs some delay here on AMD64 platform */
474 Send command to retrieve channel/effects setup/amp setup to PODxt Pro.
476 static ssize_t
pod_send_retrieve_command(struct device
*dev
, const char *buf
, size_t count
, short block0
, short block1
)
478 struct usb_interface
*interface
= to_usb_interface(dev
);
479 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
482 char *sysex
= pod_alloc_sysex_buffer(pod
, POD_SYSEX_DUMPMEM
, size
);
487 ret
= pod_resolve(buf
, block0
, block1
, sysex
+ SYSEX_DATA_OFS
);
492 sysex
[SYSEX_DATA_OFS
+ 2] = 0;
493 sysex
[SYSEX_DATA_OFS
+ 3] = 0;
494 line6_dump_started(&pod
->dumpreq
, POD_DUMP_MEMORY
);
496 if (line6_send_sysex_message(&pod
->line6
, sysex
, size
) < size
)
497 line6_dump_finished(&pod
->dumpreq
);
500 /* needs some delay here on AMD64 platform */
505 Generic get name function.
507 static ssize_t
get_name_generic(struct usb_line6_pod
*pod
, const char *str
, char *buf
)
512 char *last_non_space
= buf
;
514 int retval
= line6_wait_dump(&pod
->dumpreq
, 0);
518 for (p1
= str
, p2
= buf
; *p1
; ++p1
, ++p2
) {
522 if (++length
== POD_NAME_LENGTH
)
526 *(last_non_space
+ 1) = '\n';
527 return last_non_space
- buf
+ 2;
531 "read" request on "channel" special file.
533 static ssize_t
pod_get_channel(struct device
*dev
,
534 struct device_attribute
*attr
, char *buf
)
536 struct usb_interface
*interface
= to_usb_interface(dev
);
537 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
538 return sprintf(buf
, "%d\n", pod
->channel_num
);
542 "write" request on "channel" special file.
544 static ssize_t
pod_set_channel(struct device
*dev
,
545 struct device_attribute
*attr
,
546 const char *buf
, size_t count
)
548 struct usb_interface
*interface
= to_usb_interface(dev
);
549 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
553 ret
= strict_strtoul(buf
, 10, &value
);
557 pod_send_channel(pod
, value
);
562 "read" request on "name" special file.
564 static ssize_t
pod_get_name(struct device
*dev
, struct device_attribute
*attr
,
567 struct usb_interface
*interface
= to_usb_interface(dev
);
568 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
569 return get_name_generic(pod
, pod
->prog_data
.header
+ POD_NAME_OFFSET
, buf
);
573 "read" request on "name" special file.
575 static ssize_t
pod_get_name_buf(struct device
*dev
,
576 struct device_attribute
*attr
, char *buf
)
578 struct usb_interface
*interface
= to_usb_interface(dev
);
579 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
580 return get_name_generic(pod
, pod
->prog_data_buf
.header
+ POD_NAME_OFFSET
, buf
);
584 "read" request on "dump" special file.
586 static ssize_t
pod_get_dump(struct device
*dev
, struct device_attribute
*attr
,
589 struct usb_interface
*interface
= to_usb_interface(dev
);
590 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
591 int retval
= line6_wait_dump(&pod
->dumpreq
, 0);
594 memcpy(buf
, &pod
->prog_data
, sizeof(pod
->prog_data
));
595 return sizeof(pod
->prog_data
);
599 "write" request on "dump" special file.
601 static ssize_t
pod_set_dump(struct device
*dev
, struct device_attribute
*attr
,
602 const char *buf
, size_t count
)
604 struct usb_interface
*interface
= to_usb_interface(dev
);
605 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
607 if (count
!= sizeof(pod
->prog_data
)) {
608 dev_err(pod
->line6
.ifcdev
,
609 "data block must be exactly %zu bytes\n",
610 sizeof(pod
->prog_data
));
615 return sizeof(pod
->prog_data
);
619 Request system parameter.
620 @param tuner non-zero, if code refers to a tuner parameter
622 static ssize_t
pod_get_system_param(struct usb_line6_pod
*pod
, char *buf
, int code
, struct ValueWait
*param
, int tuner
, int sign
)
626 static const int size
= 1;
628 DECLARE_WAITQUEUE(wait
, current
);
630 if (((pod
->prog_data
.control
[POD_tuner
] & 0x40) == 0) && tuner
)
633 /* send value request to tuner: */
634 param
->value
= POD_system_invalid
;
635 sysex
= pod_alloc_sysex_buffer(pod
, POD_SYSEX_SYSTEMREQ
, size
);
638 sysex
[SYSEX_DATA_OFS
] = code
;
639 line6_send_sysex_message(&pod
->line6
, sysex
, size
);
642 /* wait for tuner to respond: */
643 add_wait_queue(¶m
->wait
, &wait
);
644 current
->state
= TASK_INTERRUPTIBLE
;
646 while (param
->value
== POD_system_invalid
) {
647 if (signal_pending(current
)) {
648 retval
= -ERESTARTSYS
;
654 current
->state
= TASK_RUNNING
;
655 remove_wait_queue(¶m
->wait
, &wait
);
660 value
= sign
? (int)(signed short)param
->value
: (int)(unsigned short)param
->value
;
661 return sprintf(buf
, "%d\n", value
);
665 Send system parameter.
666 @param tuner non-zero, if code refers to a tuner parameter
668 static ssize_t
pod_set_system_param(struct usb_line6_pod
*pod
, const char *buf
,
669 int count
, int code
, unsigned short mask
,
673 static const int size
= 5;
674 unsigned short value
;
675 unsigned long result
;
678 if (((pod
->prog_data
.control
[POD_tuner
] & 0x40) == 0) && tuner
)
681 /* send value to tuner: */
682 sysex
= pod_alloc_sysex_buffer(pod
, POD_SYSEX_SYSTEM
, size
);
686 ret
= strict_strtoul(buf
, 10, &result
);
690 value
= result
& mask
;
691 sysex
[SYSEX_DATA_OFS
] = code
;
692 sysex
[SYSEX_DATA_OFS
+ 1] = (value
>> 12) & 0x0f;
693 sysex
[SYSEX_DATA_OFS
+ 2] = (value
>> 8) & 0x0f;
694 sysex
[SYSEX_DATA_OFS
+ 3] = (value
>> 4) & 0x0f;
695 sysex
[SYSEX_DATA_OFS
+ 4] = (value
) & 0x0f;
696 line6_send_sysex_message(&pod
->line6
, sysex
, size
);
702 "read" request on "dump_buf" special file.
704 static ssize_t
pod_get_dump_buf(struct device
*dev
,
705 struct device_attribute
*attr
, char *buf
)
707 struct usb_interface
*interface
= to_usb_interface(dev
);
708 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
709 int retval
= line6_wait_dump(&pod
->dumpreq
, 0);
712 memcpy(buf
, &pod
->prog_data_buf
, sizeof(pod
->prog_data_buf
));
713 return sizeof(pod
->prog_data_buf
);
717 "write" request on "dump_buf" special file.
719 static ssize_t
pod_set_dump_buf(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 if (count
!= sizeof(pod
->prog_data
)) {
727 dev_err(pod
->line6
.ifcdev
,
728 "data block must be exactly %zu bytes\n",
729 sizeof(pod
->prog_data
));
733 memcpy(&pod
->prog_data_buf
, buf
, sizeof(pod
->prog_data
));
734 return sizeof(pod
->prog_data
);
738 "write" request on "finish" special file.
740 static ssize_t
pod_set_finish(struct device
*dev
,
741 struct device_attribute
*attr
,
742 const char *buf
, size_t count
)
744 struct usb_interface
*interface
= to_usb_interface(dev
);
745 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
747 char *sysex
= pod_alloc_sysex_buffer(pod
, POD_SYSEX_FINISH
, size
);
750 line6_send_sysex_message(&pod
->line6
, sysex
, size
);
756 "write" request on "store_channel" special file.
758 static ssize_t
pod_set_store_channel(struct device
*dev
,
759 struct device_attribute
*attr
,
760 const char *buf
, size_t count
)
762 return pod_send_store_command(dev
, buf
, count
, 0x0000, 0x00c0);
766 "write" request on "store_effects_setup" special file.
768 static ssize_t
pod_set_store_effects_setup(struct device
*dev
,
769 struct device_attribute
*attr
,
770 const char *buf
, size_t count
)
772 return pod_send_store_command(dev
, buf
, count
, 0x0080, 0x0080);
776 "write" request on "store_amp_setup" special file.
778 static ssize_t
pod_set_store_amp_setup(struct device
*dev
,
779 struct device_attribute
*attr
,
780 const char *buf
, size_t count
)
782 return pod_send_store_command(dev
, buf
, count
, 0x0040, 0x0100);
786 "write" request on "retrieve_channel" special file.
788 static ssize_t
pod_set_retrieve_channel(struct device
*dev
,
789 struct device_attribute
*attr
,
790 const char *buf
, size_t count
)
792 return pod_send_retrieve_command(dev
, buf
, count
, 0x0000, 0x00c0);
796 "write" request on "retrieve_effects_setup" special file.
798 static ssize_t
pod_set_retrieve_effects_setup(struct device
*dev
,
799 struct device_attribute
*attr
,
800 const char *buf
, size_t count
)
802 return pod_send_retrieve_command(dev
, buf
, count
, 0x0080, 0x0080);
806 "write" request on "retrieve_amp_setup" special file.
808 static ssize_t
pod_set_retrieve_amp_setup(struct device
*dev
,
809 struct device_attribute
*attr
,
810 const char *buf
, size_t count
)
812 return pod_send_retrieve_command(dev
, buf
, count
, 0x0040, 0x0100);
816 "read" request on "dirty" special file.
818 static ssize_t
pod_get_dirty(struct device
*dev
, struct device_attribute
*attr
,
821 struct usb_interface
*interface
= to_usb_interface(dev
);
822 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
823 buf
[0] = pod
->dirty
? '1' : '0';
829 "read" request on "midi_postprocess" special file.
831 static ssize_t
pod_get_midi_postprocess(struct device
*dev
,
832 struct device_attribute
*attr
,
835 struct usb_interface
*interface
= to_usb_interface(dev
);
836 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
837 return sprintf(buf
, "%d\n", pod
->midi_postprocess
);
841 "write" request on "midi_postprocess" special file.
843 static ssize_t
pod_set_midi_postprocess(struct device
*dev
,
844 struct device_attribute
*attr
,
845 const char *buf
, size_t count
)
847 struct usb_interface
*interface
= to_usb_interface(dev
);
848 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
852 ret
= strict_strtoul(buf
, 10, &value
);
856 pod
->midi_postprocess
= value
? 1 : 0;
861 "read" request on "serial_number" special file.
863 static ssize_t
pod_get_serial_number(struct device
*dev
,
864 struct device_attribute
*attr
, char *buf
)
866 struct usb_interface
*interface
= to_usb_interface(dev
);
867 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
868 return sprintf(buf
, "%d\n", pod
->serial_number
);
872 "read" request on "firmware_version" special file.
874 static ssize_t
pod_get_firmware_version(struct device
*dev
,
875 struct device_attribute
*attr
,
878 struct usb_interface
*interface
= to_usb_interface(dev
);
879 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
880 return sprintf(buf
, "%d.%02d\n", pod
->firmware_version
/ 100,
881 pod
->firmware_version
% 100);
885 "read" request on "device_id" special file.
887 static ssize_t
pod_get_device_id(struct device
*dev
,
888 struct device_attribute
*attr
, char *buf
)
890 struct usb_interface
*interface
= to_usb_interface(dev
);
891 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
892 return sprintf(buf
, "%d\n", pod
->device_id
);
896 "read" request on "clip" special file.
898 static ssize_t
pod_wait_for_clip(struct device
*dev
,
899 struct device_attribute
*attr
, char *buf
)
901 struct usb_interface
*interface
= to_usb_interface(dev
);
902 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
904 DECLARE_WAITQUEUE(wait
, current
);
905 pod
->clipping
.value
= 0;
906 add_wait_queue(&pod
->clipping
.wait
, &wait
);
907 current
->state
= TASK_INTERRUPTIBLE
;
909 while (pod
->clipping
.value
== 0) {
910 if (signal_pending(current
)) {
917 current
->state
= TASK_RUNNING
;
918 remove_wait_queue(&pod
->clipping
.wait
, &wait
);
922 #define POD_GET_SYSTEM_PARAM(code, tuner, sign) \
923 static ssize_t pod_get_ ## code(struct device *dev, \
924 struct device_attribute *attr, char *buf) \
926 struct usb_interface *interface = to_usb_interface(dev); \
927 struct usb_line6_pod *pod = usb_get_intfdata(interface); \
928 return pod_get_system_param(pod, buf, POD_ ## code, &pod->code, \
932 #define POD_GET_SET_SYSTEM_PARAM(code, mask, tuner, sign) \
933 POD_GET_SYSTEM_PARAM(code, tuner, sign) \
934 static ssize_t pod_set_ ## code(struct device *dev, \
935 struct device_attribute *attr, \
936 const char *buf, size_t count) \
938 struct usb_interface *interface = to_usb_interface(dev); \
939 struct usb_line6_pod *pod = usb_get_intfdata(interface); \
940 return pod_set_system_param(pod, buf, count, POD_ ## code, mask, \
944 POD_GET_SET_SYSTEM_PARAM(monitor_level
, 0xffff, 0, 0);
945 POD_GET_SET_SYSTEM_PARAM(routing
, 0x0003, 0, 0);
946 POD_GET_SET_SYSTEM_PARAM(tuner_mute
, 0x0001, 1, 0);
947 POD_GET_SET_SYSTEM_PARAM(tuner_freq
, 0xffff, 1, 0);
948 POD_GET_SYSTEM_PARAM(tuner_note
, 1, 1);
949 POD_GET_SYSTEM_PARAM(tuner_pitch
, 1, 1);
951 #undef GET_SET_SYSTEM_PARAM
952 #undef GET_SYSTEM_PARAM
954 /* POD special files: */
955 static DEVICE_ATTR(channel
, S_IWUGO
| S_IRUGO
, pod_get_channel
, pod_set_channel
);
956 static DEVICE_ATTR(clip
, S_IRUGO
, pod_wait_for_clip
, line6_nop_write
);
957 static DEVICE_ATTR(device_id
, S_IRUGO
, pod_get_device_id
, line6_nop_write
);
958 static DEVICE_ATTR(dirty
, S_IRUGO
, pod_get_dirty
, line6_nop_write
);
959 static DEVICE_ATTR(dump
, S_IWUGO
| S_IRUGO
, pod_get_dump
, pod_set_dump
);
960 static DEVICE_ATTR(dump_buf
, S_IWUGO
| S_IRUGO
, pod_get_dump_buf
, pod_set_dump_buf
);
961 static DEVICE_ATTR(finish
, S_IWUGO
, line6_nop_read
, pod_set_finish
);
962 static DEVICE_ATTR(firmware_version
, S_IRUGO
, pod_get_firmware_version
, line6_nop_write
);
963 static DEVICE_ATTR(midi_postprocess
, S_IWUGO
| S_IRUGO
, pod_get_midi_postprocess
, pod_set_midi_postprocess
);
964 static DEVICE_ATTR(monitor_level
, S_IWUGO
| S_IRUGO
, pod_get_monitor_level
, pod_set_monitor_level
);
965 static DEVICE_ATTR(name
, S_IRUGO
, pod_get_name
, line6_nop_write
);
966 static DEVICE_ATTR(name_buf
, S_IRUGO
, pod_get_name_buf
, line6_nop_write
);
967 static DEVICE_ATTR(retrieve_amp_setup
, S_IWUGO
, line6_nop_read
, pod_set_retrieve_amp_setup
);
968 static DEVICE_ATTR(retrieve_channel
, S_IWUGO
, line6_nop_read
, pod_set_retrieve_channel
);
969 static DEVICE_ATTR(retrieve_effects_setup
, S_IWUGO
, line6_nop_read
, pod_set_retrieve_effects_setup
);
970 static DEVICE_ATTR(routing
, S_IWUGO
| S_IRUGO
, pod_get_routing
, pod_set_routing
);
971 static DEVICE_ATTR(serial_number
, S_IRUGO
, pod_get_serial_number
, line6_nop_write
);
972 static DEVICE_ATTR(store_amp_setup
, S_IWUGO
, line6_nop_read
, pod_set_store_amp_setup
);
973 static DEVICE_ATTR(store_channel
, S_IWUGO
, line6_nop_read
, pod_set_store_channel
);
974 static DEVICE_ATTR(store_effects_setup
, S_IWUGO
, line6_nop_read
, pod_set_store_effects_setup
);
975 static DEVICE_ATTR(tuner_freq
, S_IWUGO
| S_IRUGO
, pod_get_tuner_freq
, pod_set_tuner_freq
);
976 static DEVICE_ATTR(tuner_mute
, S_IWUGO
| S_IRUGO
, pod_get_tuner_mute
, pod_set_tuner_mute
);
977 static DEVICE_ATTR(tuner_note
, S_IRUGO
, pod_get_tuner_note
, line6_nop_write
);
978 static DEVICE_ATTR(tuner_pitch
, S_IRUGO
, pod_get_tuner_pitch
, line6_nop_write
);
981 static DEVICE_ATTR(raw
, S_IWUGO
, line6_nop_read
, line6_set_raw
);
987 static void pod_destruct(struct usb_interface
*interface
)
989 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
990 struct usb_line6
*line6
;
997 line6_cleanup_audio(line6
);
999 /* free dump request data: */
1000 line6_dumpreq_destruct(&pod
->dumpreq
);
1002 kfree(pod
->buffer_versionreq
);
1006 Create sysfs entries.
1008 static int pod_create_files2(struct device
*dev
)
1012 CHECK_RETURN(device_create_file(dev
, &dev_attr_channel
));
1013 CHECK_RETURN(device_create_file(dev
, &dev_attr_clip
));
1014 CHECK_RETURN(device_create_file(dev
, &dev_attr_device_id
));
1015 CHECK_RETURN(device_create_file(dev
, &dev_attr_dirty
));
1016 CHECK_RETURN(device_create_file(dev
, &dev_attr_dump
));
1017 CHECK_RETURN(device_create_file(dev
, &dev_attr_dump_buf
));
1018 CHECK_RETURN(device_create_file(dev
, &dev_attr_finish
));
1019 CHECK_RETURN(device_create_file(dev
, &dev_attr_firmware_version
));
1020 CHECK_RETURN(device_create_file(dev
, &dev_attr_midi_postprocess
));
1021 CHECK_RETURN(device_create_file(dev
, &dev_attr_monitor_level
));
1022 CHECK_RETURN(device_create_file(dev
, &dev_attr_name
));
1023 CHECK_RETURN(device_create_file(dev
, &dev_attr_name_buf
));
1024 CHECK_RETURN(device_create_file(dev
, &dev_attr_retrieve_amp_setup
));
1025 CHECK_RETURN(device_create_file(dev
, &dev_attr_retrieve_channel
));
1026 CHECK_RETURN(device_create_file(dev
, &dev_attr_retrieve_effects_setup
));
1027 CHECK_RETURN(device_create_file(dev
, &dev_attr_routing
));
1028 CHECK_RETURN(device_create_file(dev
, &dev_attr_serial_number
));
1029 CHECK_RETURN(device_create_file(dev
, &dev_attr_store_amp_setup
));
1030 CHECK_RETURN(device_create_file(dev
, &dev_attr_store_channel
));
1031 CHECK_RETURN(device_create_file(dev
, &dev_attr_store_effects_setup
));
1032 CHECK_RETURN(device_create_file(dev
, &dev_attr_tuner_freq
));
1033 CHECK_RETURN(device_create_file(dev
, &dev_attr_tuner_mute
));
1034 CHECK_RETURN(device_create_file(dev
, &dev_attr_tuner_note
));
1035 CHECK_RETURN(device_create_file(dev
, &dev_attr_tuner_pitch
));
1038 CHECK_RETURN(device_create_file(dev
, &dev_attr_raw
));
1047 int pod_init(struct usb_interface
*interface
, struct usb_line6_pod
*pod
)
1050 struct usb_line6
*line6
= &pod
->line6
;
1052 if ((interface
== NULL
) || (pod
== NULL
))
1055 pod
->channel_num
= 255;
1057 /* initialize wait queues: */
1058 init_waitqueue_head(&pod
->monitor_level
.wait
);
1059 init_waitqueue_head(&pod
->routing
.wait
);
1060 init_waitqueue_head(&pod
->tuner_mute
.wait
);
1061 init_waitqueue_head(&pod
->tuner_freq
.wait
);
1062 init_waitqueue_head(&pod
->tuner_note
.wait
);
1063 init_waitqueue_head(&pod
->tuner_pitch
.wait
);
1064 init_waitqueue_head(&pod
->clipping
.wait
);
1066 memset(pod
->param_dirty
, 0xff, sizeof(pod
->param_dirty
));
1068 /* initialize USB buffers: */
1069 err
= line6_dumpreq_init(&pod
->dumpreq
, pod_request_channel
,
1070 sizeof(pod_request_channel
));
1072 dev_err(&interface
->dev
, "Out of memory\n");
1073 pod_destruct(interface
);
1077 pod
->buffer_versionreq
= kmemdup(pod_request_version
,
1078 sizeof(pod_request_version
),
1081 if (pod
->buffer_versionreq
== NULL
) {
1082 dev_err(&interface
->dev
, "Out of memory\n");
1083 pod_destruct(interface
);
1087 /* create sysfs entries: */
1088 err
= pod_create_files2(&interface
->dev
);
1090 pod_destruct(interface
);
1094 /* initialize audio system: */
1095 err
= line6_init_audio(line6
);
1097 pod_destruct(interface
);
1101 /* initialize MIDI subsystem: */
1102 err
= line6_init_midi(line6
);
1104 pod_destruct(interface
);
1108 /* initialize PCM subsystem: */
1109 err
= line6_init_pcm(line6
, &pod_pcm_properties
);
1111 pod_destruct(interface
);
1115 /* register audio system: */
1116 err
= line6_register_audio(line6
);
1118 pod_destruct(interface
);
1122 if (pod
->line6
.properties
->capabilities
& LINE6_BIT_CONTROL
) {
1123 /* query some data: */
1124 line6_startup_delayed(&pod
->dumpreq
, POD_STARTUP_DELAY
,
1125 pod_startup_timeout
, pod
);
1126 line6_read_serial_number(&pod
->line6
, &pod
->serial_number
);
1133 POD device disconnected.
1135 void pod_disconnect(struct usb_interface
*interface
)
1137 struct usb_line6_pod
*pod
;
1139 if (interface
== NULL
)
1141 pod
= usb_get_intfdata(interface
);
1144 struct snd_line6_pcm
*line6pcm
= pod
->line6
.line6pcm
;
1145 struct device
*dev
= &interface
->dev
;
1147 if (line6pcm
!= NULL
) {
1148 unlink_wait_clear_audio_out_urbs(line6pcm
);
1149 unlink_wait_clear_audio_in_urbs(line6pcm
);
1153 /* remove sysfs entries: */
1154 if (pod
->versionreq_ok
)
1155 pod_remove_files(pod
->firmware_version
, pod
->line6
.properties
->device_bit
, dev
);
1157 device_remove_file(dev
, &dev_attr_channel
);
1158 device_remove_file(dev
, &dev_attr_clip
);
1159 device_remove_file(dev
, &dev_attr_device_id
);
1160 device_remove_file(dev
, &dev_attr_dirty
);
1161 device_remove_file(dev
, &dev_attr_dump
);
1162 device_remove_file(dev
, &dev_attr_dump_buf
);
1163 device_remove_file(dev
, &dev_attr_finish
);
1164 device_remove_file(dev
, &dev_attr_firmware_version
);
1165 device_remove_file(dev
, &dev_attr_midi_postprocess
);
1166 device_remove_file(dev
, &dev_attr_monitor_level
);
1167 device_remove_file(dev
, &dev_attr_name
);
1168 device_remove_file(dev
, &dev_attr_name_buf
);
1169 device_remove_file(dev
, &dev_attr_retrieve_amp_setup
);
1170 device_remove_file(dev
, &dev_attr_retrieve_channel
);
1171 device_remove_file(dev
, &dev_attr_retrieve_effects_setup
);
1172 device_remove_file(dev
, &dev_attr_routing
);
1173 device_remove_file(dev
, &dev_attr_serial_number
);
1174 device_remove_file(dev
, &dev_attr_store_amp_setup
);
1175 device_remove_file(dev
, &dev_attr_store_channel
);
1176 device_remove_file(dev
, &dev_attr_store_effects_setup
);
1177 device_remove_file(dev
, &dev_attr_tuner_freq
);
1178 device_remove_file(dev
, &dev_attr_tuner_mute
);
1179 device_remove_file(dev
, &dev_attr_tuner_note
);
1180 device_remove_file(dev
, &dev_attr_tuner_pitch
);
1183 device_remove_file(dev
, &dev_attr_raw
);
1188 pod_destruct(interface
);