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.
21 #define POD_SYSEX_CODE 3
22 #define POD_BYTES_PER_FRAME 6 /* 24bit audio (stereo) */
26 POD_SYSEX_CLIP
= 0x0f,
27 POD_SYSEX_SAVE
= 0x24,
28 POD_SYSEX_SYSTEM
= 0x56,
29 POD_SYSEX_SYSTEMREQ
= 0x57,
30 /* POD_SYSEX_UPDATE = 0x6c, */ /* software update! */
31 POD_SYSEX_STORE
= 0x71,
32 POD_SYSEX_FINISH
= 0x72,
33 POD_SYSEX_DUMPMEM
= 0x73,
34 POD_SYSEX_DUMP
= 0x74,
35 POD_SYSEX_DUMPREQ
= 0x75
36 /* POD_SYSEX_DUMPMEM2 = 0x76 */ /* dumps entire internal memory of PODxt Pro */
40 POD_monitor_level
= 0x04,
42 POD_tuner_mute
= 0x13,
43 POD_tuner_freq
= 0x15,
44 POD_tuner_note
= 0x16,
45 POD_tuner_pitch
= 0x17,
46 POD_system_invalid
= 0x7fff
62 static struct snd_ratden pod_ratden
= {
69 static struct line6_pcm_properties pod_pcm_properties
= {
70 .snd_line6_playback_hw
= {
71 .info
= (SNDRV_PCM_INFO_MMAP
|
72 SNDRV_PCM_INFO_INTERLEAVED
|
73 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
74 SNDRV_PCM_INFO_MMAP_VALID
|
75 SNDRV_PCM_INFO_PAUSE
|
76 SNDRV_PCM_INFO_SYNC_START
),
77 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
78 .rates
= SNDRV_PCM_RATE_KNOT
,
83 .buffer_bytes_max
= 60000,
84 .period_bytes_min
= LINE6_ISO_PACKET_SIZE_MAX
* POD_BYTES_PER_FRAME
, /* at least one URB must fit into one period */
85 .period_bytes_max
= 8192,
89 .snd_line6_capture_hw
= {
90 .info
= (SNDRV_PCM_INFO_MMAP
|
91 SNDRV_PCM_INFO_INTERLEAVED
|
92 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
93 SNDRV_PCM_INFO_MMAP_VALID
|
94 SNDRV_PCM_INFO_SYNC_START
),
95 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
96 .rates
= SNDRV_PCM_RATE_KNOT
,
101 .buffer_bytes_max
= 60000,
102 .period_bytes_min
= LINE6_ISO_PACKET_SIZE_MAX
* POD_BYTES_PER_FRAME
, /* at least one URB must fit into one period */
103 .period_bytes_max
= 8192,
111 .bytes_per_frame
= POD_BYTES_PER_FRAME
114 static const char pod_request_version
[] = { 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7 };
115 static const char pod_request_channel
[] = { 0xf0, 0x00, 0x01, 0x0c, 0x03, 0x75, 0xf7 };
116 static const char pod_version_header
[] = { 0xf2, 0x7e, 0x7f, 0x06, 0x02 };
120 Mark all parameters as dirty and notify waiting processes.
122 static void pod_mark_batch_all_dirty(struct usb_line6_pod
*pod
)
126 for (i
= POD_CONTROL_SIZE
; i
--;)
127 set_bit(i
, pod
->param_dirty
);
131 Send an asynchronous request for the POD firmware version and device ID.
133 static int pod_version_request_async(struct usb_line6_pod
*pod
)
135 return line6_send_raw_message_async(&pod
->line6
, pod
->buffer_versionreq
, sizeof(pod_request_version
));
138 static void pod_create_files_work(struct work_struct
*work
)
140 struct usb_line6_pod
*pod
= container_of(work
, struct usb_line6_pod
, create_files_work
);
142 pod_create_files(pod
->firmware_version
, pod
->line6
.properties
->device_bit
, pod
->line6
.ifcdev
);
145 static void pod_startup_timeout(unsigned long arg
)
153 int request
= REQUEST_NONE
;
154 struct usb_line6_pod
*pod
= (struct usb_line6_pod
*)arg
;
156 if (pod
->dumpreq
.ok
) {
157 if (!pod
->versionreq_ok
)
158 request
= REQUEST_VERSION
;
160 if (pod
->versionreq_ok
)
161 request
= REQUEST_DUMP
;
162 else if (pod
->startup_count
++ & 1)
163 request
= REQUEST_DUMP
;
165 request
= REQUEST_VERSION
;
170 line6_dump_request_async(&pod
->dumpreq
, &pod
->line6
, 0);
173 case REQUEST_VERSION
:
174 pod_version_request_async(pod
);
181 line6_startup_delayed(&pod
->dumpreq
, 1, pod_startup_timeout
, pod
);
184 static char *pod_alloc_sysex_buffer(struct usb_line6_pod
*pod
, int code
, int size
)
186 return line6_alloc_sysex_buffer(&pod
->line6
, POD_SYSEX_CODE
, code
, size
);
190 Send channel dump data to the PODxt Pro.
192 static void pod_dump(struct usb_line6_pod
*pod
, const unsigned char *data
)
194 int size
= 1 + sizeof(pod
->prog_data
);
195 char *sysex
= pod_alloc_sysex_buffer(pod
, POD_SYSEX_DUMP
, size
);
198 /* Don't know what this is good for, but PODxt Pro transmits it, so we
200 sysex
[SYSEX_DATA_OFS
] = 5;
201 memcpy(sysex
+ SYSEX_DATA_OFS
+ 1, data
, sizeof(pod
->prog_data
));
202 line6_send_sysex_message(&pod
->line6
, sysex
, size
);
203 memcpy(&pod
->prog_data
, data
, sizeof(pod
->prog_data
));
204 pod_mark_batch_all_dirty(pod
);
209 Store parameter value in driver memory and mark it as dirty.
211 static void pod_store_parameter(struct usb_line6_pod
*pod
, int param
, int value
)
213 pod
->prog_data
.control
[param
] = value
;
214 set_bit(param
, pod
->param_dirty
);
221 static void pod_save_button_pressed(struct usb_line6_pod
*pod
, int type
, int index
)
224 set_bit(POD_SAVE_PRESSED
, &pod
->atomic_flags
);
228 Process a completely received message.
230 void pod_process_message(struct usb_line6_pod
*pod
)
232 const unsigned char *buf
= pod
->line6
.buffer_message
;
234 /* filter messages by type */
235 switch (buf
[0] & 0xf0) {
236 case LINE6_PARAM_CHANGE
:
237 case LINE6_PROGRAM_CHANGE
:
238 case LINE6_SYSEX_BEGIN
:
239 break; /* handle these further down */
242 return; /* ignore all others */
245 /* process all remaining messages */
247 case LINE6_PARAM_CHANGE
| LINE6_CHANNEL_DEVICE
:
248 pod_store_parameter(pod
, buf
[1], buf
[2]);
249 /* intentionally no break here! */
251 case LINE6_PARAM_CHANGE
| LINE6_CHANNEL_HOST
:
252 if ((buf
[1] == POD_amp_model_setup
) ||
253 (buf
[1] == POD_effect_setup
))
254 /* these also affect other settings */
255 line6_dump_request_async(&pod
->dumpreq
, &pod
->line6
, 0);
259 case LINE6_PROGRAM_CHANGE
| LINE6_CHANNEL_DEVICE
:
260 case LINE6_PROGRAM_CHANGE
| LINE6_CHANNEL_HOST
:
261 pod
->channel_num
= buf
[1];
263 set_bit(POD_CHANNEL_DIRTY
, &pod
->atomic_flags
);
264 line6_dump_request_async(&pod
->dumpreq
, &pod
->line6
, 0);
267 case LINE6_SYSEX_BEGIN
| LINE6_CHANNEL_DEVICE
:
268 case LINE6_SYSEX_BEGIN
| LINE6_CHANNEL_UNKNOWN
:
269 if (memcmp(buf
+ 1, line6_midi_id
, sizeof(line6_midi_id
)) == 0) {
272 if (pod
->line6
.message_length
== sizeof(pod
->prog_data
) + 7) {
273 switch (pod
->dumpreq
.in_progress
) {
274 case LINE6_DUMP_CURRENT
:
275 memcpy(&pod
->prog_data
, buf
+ 7, sizeof(pod
->prog_data
));
276 pod_mark_batch_all_dirty(pod
);
280 case POD_DUMP_MEMORY
:
281 memcpy(&pod
->prog_data_buf
, buf
+ 7, sizeof(pod
->prog_data_buf
));
285 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "unknown dump code %02X\n", pod
->dumpreq
.in_progress
));
288 line6_dump_finished(&pod
->dumpreq
);
290 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "wrong size of channel dump message (%d instead of %d)\n",
291 pod
->line6
.message_length
, (int)sizeof(pod
->prog_data
) + 7));
295 case POD_SYSEX_SYSTEM
: {
296 short value
= ((int)buf
[7] << 12) | ((int)buf
[8] << 8) | ((int)buf
[9] << 4) | (int)buf
[10];
298 #define PROCESS_SYSTEM_PARAM(x) \
300 pod->x.value = value; \
301 wake_up_interruptible(&pod->x.wait); \
305 PROCESS_SYSTEM_PARAM(monitor_level
);
306 PROCESS_SYSTEM_PARAM(routing
);
307 PROCESS_SYSTEM_PARAM(tuner_mute
);
308 PROCESS_SYSTEM_PARAM(tuner_freq
);
309 PROCESS_SYSTEM_PARAM(tuner_note
);
310 PROCESS_SYSTEM_PARAM(tuner_pitch
);
312 #undef PROCESS_SYSTEM_PARAM
315 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "unknown tuner/system response %02X\n", buf
[6]));
321 case POD_SYSEX_FINISH
:
322 /* do we need to respond to this? */
326 pod_save_button_pressed(pod
, buf
[6], buf
[7]);
330 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "audio clipped\n"));
331 pod
->clipping
.value
= 1;
332 wake_up_interruptible(&pod
->clipping
.wait
);
335 case POD_SYSEX_STORE
:
336 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "message %02X not yet implemented\n", buf
[5]));
340 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "unknown sysex message %02X\n", buf
[5]));
342 } else if (memcmp(buf
, pod_version_header
, sizeof(pod_version_header
)) == 0) {
343 if (pod
->versionreq_ok
== 0) {
344 pod
->firmware_version
= buf
[13] * 100 + buf
[14] * 10 + buf
[15];
345 pod
->device_id
= ((int)buf
[8] << 16) | ((int)buf
[9] << 8) | (int)buf
[10];
346 pod
->versionreq_ok
= 1;
348 /* Now we know the firmware version, so we schedule a bottom half
349 handler to create the special files: */
350 INIT_WORK(&pod
->create_files_work
, pod_create_files_work
);
351 queue_work(line6_workqueue
, &pod
->create_files_work
);
353 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "multiple firmware version message\n"));
355 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "unknown sysex header\n"));
359 case LINE6_SYSEX_END
:
363 DEBUG_MESSAGES(dev_err(pod
->line6
.ifcdev
, "POD: unknown message %02X\n", buf
[0]));
368 Detect some cases that require a channel dump after sending a command to the
369 device. Important notes:
370 *) The actual dump request can not be sent here since we are not allowed to
371 wait for the completion of the first message in this context, and sending
372 the dump request before completion of the previous message leaves the POD
373 in an undefined state. The dump request will be sent when the echoed
374 commands are received.
375 *) This method fails if a param change message is "chopped" after the first
378 void pod_midi_postprocess(struct usb_line6_pod
*pod
, unsigned char *data
, int length
)
382 if (!pod
->midi_postprocess
)
385 for (i
= 0; i
< length
; ++i
) {
386 if (data
[i
] == (LINE6_PROGRAM_CHANGE
| LINE6_CHANNEL_HOST
)) {
387 line6_invalidate_current(&pod
->dumpreq
);
389 } else if ((data
[i
] == (LINE6_PARAM_CHANGE
| LINE6_CHANNEL_HOST
)) && (i
< length
- 1))
390 if ((data
[i
+ 1] == POD_amp_model_setup
) || (data
[i
+ 1] == POD_effect_setup
)) {
391 line6_invalidate_current(&pod
->dumpreq
);
398 Send channel number (i.e., switch to a different sound).
400 static void pod_send_channel(struct usb_line6_pod
*pod
, int value
)
402 line6_invalidate_current(&pod
->dumpreq
);
404 if (line6_send_program(&pod
->line6
, value
) == 0)
405 pod
->channel_num
= value
;
407 line6_dump_finished(&pod
->dumpreq
);
411 Transmit PODxt Pro control parameter.
413 void pod_transmit_parameter(struct usb_line6_pod
*pod
, int param
, int value
)
415 if (line6_transmit_parameter(&pod
->line6
, param
, value
) == 0)
416 pod_store_parameter(pod
, param
, value
);
418 if ((param
== POD_amp_model_setup
) || (param
== POD_effect_setup
)) /* these also affect other settings */
419 line6_invalidate_current(&pod
->dumpreq
);
423 Resolve value to memory location.
425 static void pod_resolve(const char *buf
, short block0
, short block1
, unsigned char *location
)
427 int value
= simple_strtoul(buf
, NULL
, 10);
428 short block
= (value
< 0x40) ? block0
: block1
;
430 location
[0] = block
>> 7;
431 location
[1] = value
| (block
& 0x7f);
435 Send command to store channel/effects setup/amp setup to PODxt Pro.
437 static ssize_t
pod_send_store_command(struct device
*dev
, const char *buf
, size_t count
, short block0
, short block1
)
439 struct usb_interface
*interface
= to_usb_interface(dev
);
440 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
442 int size
= 3 + sizeof(pod
->prog_data_buf
);
443 char *sysex
= pod_alloc_sysex_buffer(pod
, POD_SYSEX_STORE
, size
);
447 sysex
[SYSEX_DATA_OFS
] = 5; /* see pod_dump() */
448 pod_resolve(buf
, block0
, block1
, sysex
+ SYSEX_DATA_OFS
+ 1);
449 memcpy(sysex
+ SYSEX_DATA_OFS
+ 3, &pod
->prog_data_buf
, sizeof(pod
->prog_data_buf
));
451 line6_send_sysex_message(&pod
->line6
, sysex
, size
);
453 /* needs some delay here on AMD64 platform */
458 Send command to retrieve channel/effects setup/amp setup to PODxt Pro.
460 static ssize_t
pod_send_retrieve_command(struct device
*dev
, const char *buf
, size_t count
, short block0
, short block1
)
462 struct usb_interface
*interface
= to_usb_interface(dev
);
463 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
465 char *sysex
= pod_alloc_sysex_buffer(pod
, POD_SYSEX_DUMPMEM
, size
);
470 pod_resolve(buf
, block0
, block1
, sysex
+ SYSEX_DATA_OFS
);
471 sysex
[SYSEX_DATA_OFS
+ 2] = 0;
472 sysex
[SYSEX_DATA_OFS
+ 3] = 0;
473 line6_dump_started(&pod
->dumpreq
, POD_DUMP_MEMORY
);
475 if (line6_send_sysex_message(&pod
->line6
, sysex
, size
) < size
)
476 line6_dump_finished(&pod
->dumpreq
);
479 /* needs some delay here on AMD64 platform */
484 Generic get name function.
486 static ssize_t
get_name_generic(struct usb_line6_pod
*pod
, const char *str
, char *buf
)
491 char *last_non_space
= buf
;
493 int retval
= line6_wait_dump(&pod
->dumpreq
, 0);
497 for (p1
= str
, p2
= buf
; *p1
; ++p1
, ++p2
) {
501 if (++length
== POD_NAME_LENGTH
)
505 *(last_non_space
+ 1) = '\n';
506 return last_non_space
- buf
+ 2;
510 "read" request on "channel" special file.
512 static ssize_t
pod_get_channel(struct device
*dev
,
513 struct device_attribute
*attr
, char *buf
)
515 struct usb_interface
*interface
= to_usb_interface(dev
);
516 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
517 return sprintf(buf
, "%d\n", pod
->channel_num
);
521 "write" request on "channel" special file.
523 static ssize_t
pod_set_channel(struct device
*dev
,
524 struct device_attribute
*attr
,
525 const char *buf
, size_t count
)
527 struct usb_interface
*interface
= to_usb_interface(dev
);
528 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
529 int value
= simple_strtoul(buf
, NULL
, 10);
530 pod_send_channel(pod
, value
);
535 "read" request on "name" special file.
537 static ssize_t
pod_get_name(struct device
*dev
, struct device_attribute
*attr
,
540 struct usb_interface
*interface
= to_usb_interface(dev
);
541 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
542 return get_name_generic(pod
, pod
->prog_data
.header
+ POD_NAME_OFFSET
, buf
);
546 "read" request on "name" special file.
548 static ssize_t
pod_get_name_buf(struct device
*dev
,
549 struct device_attribute
*attr
, char *buf
)
551 struct usb_interface
*interface
= to_usb_interface(dev
);
552 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
553 return get_name_generic(pod
, pod
->prog_data_buf
.header
+ POD_NAME_OFFSET
, buf
);
557 "read" request on "dump" special file.
559 static ssize_t
pod_get_dump(struct device
*dev
, struct device_attribute
*attr
,
562 struct usb_interface
*interface
= to_usb_interface(dev
);
563 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
564 int retval
= line6_wait_dump(&pod
->dumpreq
, 0);
567 memcpy(buf
, &pod
->prog_data
, sizeof(pod
->prog_data
));
568 return sizeof(pod
->prog_data
);
572 "write" request on "dump" special file.
574 static ssize_t
pod_set_dump(struct device
*dev
, struct device_attribute
*attr
,
575 const char *buf
, size_t count
)
577 struct usb_interface
*interface
= to_usb_interface(dev
);
578 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
580 if (count
!= sizeof(pod
->prog_data
)) {
581 dev_err(pod
->line6
.ifcdev
,
582 "data block must be exactly %d bytes\n",
583 (int)sizeof(pod
->prog_data
));
588 return sizeof(pod
->prog_data
);
592 Request system parameter.
593 @param tuner non-zero, if code refers to a tuner parameter
595 static ssize_t
pod_get_system_param(struct usb_line6_pod
*pod
, char *buf
, int code
, struct ValueWait
*param
, int tuner
, int sign
)
599 static const int size
= 1;
601 DECLARE_WAITQUEUE(wait
, current
);
603 if (((pod
->prog_data
.control
[POD_tuner
] & 0x40) == 0) && tuner
)
606 /* send value request to tuner: */
607 param
->value
= POD_system_invalid
;
608 sysex
= pod_alloc_sysex_buffer(pod
, POD_SYSEX_SYSTEMREQ
, size
);
611 sysex
[SYSEX_DATA_OFS
] = code
;
612 line6_send_sysex_message(&pod
->line6
, sysex
, size
);
615 /* wait for tuner to respond: */
616 add_wait_queue(¶m
->wait
, &wait
);
617 current
->state
= TASK_INTERRUPTIBLE
;
619 while (param
->value
== POD_system_invalid
) {
620 if (signal_pending(current
)) {
621 retval
= -ERESTARTSYS
;
627 current
->state
= TASK_RUNNING
;
628 remove_wait_queue(¶m
->wait
, &wait
);
633 value
= sign
? (int)(signed short)param
->value
: (int)(unsigned short)param
->value
;
634 return sprintf(buf
, "%d\n", value
);
638 Send system parameter.
639 @param tuner non-zero, if code refers to a tuner parameter
641 static ssize_t
pod_set_system_param(struct usb_line6_pod
*pod
, const char *buf
,
642 int count
, int code
, unsigned short mask
,
646 static const int size
= 5;
647 unsigned short value
;
649 if (((pod
->prog_data
.control
[POD_tuner
] & 0x40) == 0) && tuner
)
652 /* send value to tuner: */
653 sysex
= pod_alloc_sysex_buffer(pod
, POD_SYSEX_SYSTEM
, size
);
656 value
= simple_strtoul(buf
, NULL
, 10) & mask
;
657 sysex
[SYSEX_DATA_OFS
] = code
;
658 sysex
[SYSEX_DATA_OFS
+ 1] = (value
>> 12) & 0x0f;
659 sysex
[SYSEX_DATA_OFS
+ 2] = (value
>> 8) & 0x0f;
660 sysex
[SYSEX_DATA_OFS
+ 3] = (value
>> 4) & 0x0f;
661 sysex
[SYSEX_DATA_OFS
+ 4] = (value
) & 0x0f;
662 line6_send_sysex_message(&pod
->line6
, sysex
, size
);
668 "read" request on "dump_buf" special file.
670 static ssize_t
pod_get_dump_buf(struct device
*dev
,
671 struct device_attribute
*attr
, char *buf
)
673 struct usb_interface
*interface
= to_usb_interface(dev
);
674 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
675 int retval
= line6_wait_dump(&pod
->dumpreq
, 0);
678 memcpy(buf
, &pod
->prog_data_buf
, sizeof(pod
->prog_data_buf
));
679 return sizeof(pod
->prog_data_buf
);
683 "write" request on "dump_buf" special file.
685 static ssize_t
pod_set_dump_buf(struct device
*dev
,
686 struct device_attribute
*attr
,
687 const char *buf
, size_t count
)
689 struct usb_interface
*interface
= to_usb_interface(dev
);
690 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
692 if (count
!= sizeof(pod
->prog_data
)) {
693 dev_err(pod
->line6
.ifcdev
,
694 "data block must be exactly %d bytes\n",
695 (int)sizeof(pod
->prog_data
));
699 memcpy(&pod
->prog_data_buf
, buf
, sizeof(pod
->prog_data
));
700 return sizeof(pod
->prog_data
);
704 "write" request on "finish" special file.
706 static ssize_t
pod_set_finish(struct device
*dev
,
707 struct device_attribute
*attr
,
708 const char *buf
, size_t count
)
710 struct usb_interface
*interface
= to_usb_interface(dev
);
711 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
713 char *sysex
= pod_alloc_sysex_buffer(pod
, POD_SYSEX_FINISH
, size
);
716 line6_send_sysex_message(&pod
->line6
, sysex
, size
);
722 "write" request on "store_channel" special file.
724 static ssize_t
pod_set_store_channel(struct device
*dev
,
725 struct device_attribute
*attr
,
726 const char *buf
, size_t count
)
728 return pod_send_store_command(dev
, buf
, count
, 0x0000, 0x00c0);
732 "write" request on "store_effects_setup" special file.
734 static ssize_t
pod_set_store_effects_setup(struct device
*dev
,
735 struct device_attribute
*attr
,
736 const char *buf
, size_t count
)
738 return pod_send_store_command(dev
, buf
, count
, 0x0080, 0x0080);
742 "write" request on "store_amp_setup" special file.
744 static ssize_t
pod_set_store_amp_setup(struct device
*dev
,
745 struct device_attribute
*attr
,
746 const char *buf
, size_t count
)
748 return pod_send_store_command(dev
, buf
, count
, 0x0040, 0x0100);
752 "write" request on "retrieve_channel" special file.
754 static ssize_t
pod_set_retrieve_channel(struct device
*dev
,
755 struct device_attribute
*attr
,
756 const char *buf
, size_t count
)
758 return pod_send_retrieve_command(dev
, buf
, count
, 0x0000, 0x00c0);
762 "write" request on "retrieve_effects_setup" special file.
764 static ssize_t
pod_set_retrieve_effects_setup(struct device
*dev
,
765 struct device_attribute
*attr
,
766 const char *buf
, size_t count
)
768 return pod_send_retrieve_command(dev
, buf
, count
, 0x0080, 0x0080);
772 "write" request on "retrieve_amp_setup" special file.
774 static ssize_t
pod_set_retrieve_amp_setup(struct device
*dev
,
775 struct device_attribute
*attr
,
776 const char *buf
, size_t count
)
778 return pod_send_retrieve_command(dev
, buf
, count
, 0x0040, 0x0100);
782 "read" request on "dirty" special file.
784 static ssize_t
pod_get_dirty(struct device
*dev
, struct device_attribute
*attr
,
787 struct usb_interface
*interface
= to_usb_interface(dev
);
788 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
789 buf
[0] = pod
->dirty
? '1' : '0';
795 "read" request on "midi_postprocess" special file.
797 static ssize_t
pod_get_midi_postprocess(struct device
*dev
,
798 struct device_attribute
*attr
,
801 struct usb_interface
*interface
= to_usb_interface(dev
);
802 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
803 return sprintf(buf
, "%d\n", pod
->midi_postprocess
);
807 "write" request on "midi_postprocess" special file.
809 static ssize_t
pod_set_midi_postprocess(struct device
*dev
,
810 struct device_attribute
*attr
,
811 const char *buf
, size_t count
)
813 struct usb_interface
*interface
= to_usb_interface(dev
);
814 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
815 int value
= simple_strtoul(buf
, NULL
, 10);
816 pod
->midi_postprocess
= value
? 1 : 0;
821 "read" request on "serial_number" special file.
823 static ssize_t
pod_get_serial_number(struct device
*dev
,
824 struct device_attribute
*attr
, char *buf
)
826 struct usb_interface
*interface
= to_usb_interface(dev
);
827 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
828 return sprintf(buf
, "%d\n", pod
->serial_number
);
832 "read" request on "firmware_version" special file.
834 static ssize_t
pod_get_firmware_version(struct device
*dev
,
835 struct device_attribute
*attr
,
838 struct usb_interface
*interface
= to_usb_interface(dev
);
839 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
840 return sprintf(buf
, "%d.%02d\n", pod
->firmware_version
/ 100,
841 pod
->firmware_version
% 100);
845 "read" request on "device_id" special file.
847 static ssize_t
pod_get_device_id(struct device
*dev
,
848 struct device_attribute
*attr
, char *buf
)
850 struct usb_interface
*interface
= to_usb_interface(dev
);
851 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
852 return sprintf(buf
, "%d\n", pod
->device_id
);
856 "read" request on "clip" special file.
858 static ssize_t
pod_wait_for_clip(struct device
*dev
,
859 struct device_attribute
*attr
, char *buf
)
861 struct usb_interface
*interface
= to_usb_interface(dev
);
862 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
864 DECLARE_WAITQUEUE(wait
, current
);
865 pod
->clipping
.value
= 0;
866 add_wait_queue(&pod
->clipping
.wait
, &wait
);
867 current
->state
= TASK_INTERRUPTIBLE
;
869 while (pod
->clipping
.value
== 0) {
870 if (signal_pending(current
)) {
877 current
->state
= TASK_RUNNING
;
878 remove_wait_queue(&pod
->clipping
.wait
, &wait
);
882 #define POD_GET_SYSTEM_PARAM(code, tuner, sign) \
883 static ssize_t pod_get_ ## code(struct device *dev, \
884 struct device_attribute *attr, char *buf) \
886 struct usb_interface *interface = to_usb_interface(dev); \
887 struct usb_line6_pod *pod = usb_get_intfdata(interface); \
888 return pod_get_system_param(pod, buf, POD_ ## code, &pod->code, \
892 #define POD_GET_SET_SYSTEM_PARAM(code, mask, tuner, sign) \
893 POD_GET_SYSTEM_PARAM(code, tuner, sign) \
894 static ssize_t pod_set_ ## code(struct device *dev, \
895 struct device_attribute *attr, \
896 const char *buf, size_t count) \
898 struct usb_interface *interface = to_usb_interface(dev); \
899 struct usb_line6_pod *pod = usb_get_intfdata(interface); \
900 return pod_set_system_param(pod, buf, count, POD_ ## code, mask, \
904 POD_GET_SET_SYSTEM_PARAM(monitor_level
, 0xffff, 0, 0);
905 POD_GET_SET_SYSTEM_PARAM(routing
, 0x0003, 0, 0);
906 POD_GET_SET_SYSTEM_PARAM(tuner_mute
, 0x0001, 1, 0);
907 POD_GET_SET_SYSTEM_PARAM(tuner_freq
, 0xffff, 1, 0);
908 POD_GET_SYSTEM_PARAM(tuner_note
, 1, 1);
909 POD_GET_SYSTEM_PARAM(tuner_pitch
, 1, 1);
911 #undef GET_SET_SYSTEM_PARAM
912 #undef GET_SYSTEM_PARAM
914 /* POD special files: */
915 static DEVICE_ATTR(channel
, S_IWUGO
| S_IRUGO
, pod_get_channel
, pod_set_channel
);
916 static DEVICE_ATTR(clip
, S_IRUGO
, pod_wait_for_clip
, line6_nop_write
);
917 static DEVICE_ATTR(device_id
, S_IRUGO
, pod_get_device_id
, line6_nop_write
);
918 static DEVICE_ATTR(dirty
, S_IRUGO
, pod_get_dirty
, line6_nop_write
);
919 static DEVICE_ATTR(dump
, S_IWUGO
| S_IRUGO
, pod_get_dump
, pod_set_dump
);
920 static DEVICE_ATTR(dump_buf
, S_IWUGO
| S_IRUGO
, pod_get_dump_buf
, pod_set_dump_buf
);
921 static DEVICE_ATTR(finish
, S_IWUGO
, line6_nop_read
, pod_set_finish
);
922 static DEVICE_ATTR(firmware_version
, S_IRUGO
, pod_get_firmware_version
, line6_nop_write
);
923 static DEVICE_ATTR(midi_postprocess
, S_IWUGO
| S_IRUGO
, pod_get_midi_postprocess
, pod_set_midi_postprocess
);
924 static DEVICE_ATTR(monitor_level
, S_IWUGO
| S_IRUGO
, pod_get_monitor_level
, pod_set_monitor_level
);
925 static DEVICE_ATTR(name
, S_IRUGO
, pod_get_name
, line6_nop_write
);
926 static DEVICE_ATTR(name_buf
, S_IRUGO
, pod_get_name_buf
, line6_nop_write
);
927 static DEVICE_ATTR(retrieve_amp_setup
, S_IWUGO
, line6_nop_read
, pod_set_retrieve_amp_setup
);
928 static DEVICE_ATTR(retrieve_channel
, S_IWUGO
, line6_nop_read
, pod_set_retrieve_channel
);
929 static DEVICE_ATTR(retrieve_effects_setup
, S_IWUGO
, line6_nop_read
, pod_set_retrieve_effects_setup
);
930 static DEVICE_ATTR(routing
, S_IWUGO
| S_IRUGO
, pod_get_routing
, pod_set_routing
);
931 static DEVICE_ATTR(serial_number
, S_IRUGO
, pod_get_serial_number
, line6_nop_write
);
932 static DEVICE_ATTR(store_amp_setup
, S_IWUGO
, line6_nop_read
, pod_set_store_amp_setup
);
933 static DEVICE_ATTR(store_channel
, S_IWUGO
, line6_nop_read
, pod_set_store_channel
);
934 static DEVICE_ATTR(store_effects_setup
, S_IWUGO
, line6_nop_read
, pod_set_store_effects_setup
);
935 static DEVICE_ATTR(tuner_freq
, S_IWUGO
| S_IRUGO
, pod_get_tuner_freq
, pod_set_tuner_freq
);
936 static DEVICE_ATTR(tuner_mute
, S_IWUGO
| S_IRUGO
, pod_get_tuner_mute
, pod_set_tuner_mute
);
937 static DEVICE_ATTR(tuner_note
, S_IRUGO
, pod_get_tuner_note
, line6_nop_write
);
938 static DEVICE_ATTR(tuner_pitch
, S_IRUGO
, pod_get_tuner_pitch
, line6_nop_write
);
941 static DEVICE_ATTR(raw
, S_IWUGO
, line6_nop_read
, line6_set_raw
);
947 static void pod_destruct(struct usb_interface
*interface
)
949 struct usb_line6_pod
*pod
= usb_get_intfdata(interface
);
950 struct usb_line6
*line6
;
957 line6_cleanup_audio(line6
);
959 /* free dump request data: */
960 line6_dumpreq_destruct(&pod
->dumpreq
);
962 kfree(pod
->buffer_versionreq
);
966 Create sysfs entries.
968 static int pod_create_files2(struct device
*dev
)
972 CHECK_RETURN(device_create_file(dev
, &dev_attr_channel
));
973 CHECK_RETURN(device_create_file(dev
, &dev_attr_clip
));
974 CHECK_RETURN(device_create_file(dev
, &dev_attr_device_id
));
975 CHECK_RETURN(device_create_file(dev
, &dev_attr_dirty
));
976 CHECK_RETURN(device_create_file(dev
, &dev_attr_dump
));
977 CHECK_RETURN(device_create_file(dev
, &dev_attr_dump_buf
));
978 CHECK_RETURN(device_create_file(dev
, &dev_attr_finish
));
979 CHECK_RETURN(device_create_file(dev
, &dev_attr_firmware_version
));
980 CHECK_RETURN(device_create_file(dev
, &dev_attr_midi_postprocess
));
981 CHECK_RETURN(device_create_file(dev
, &dev_attr_monitor_level
));
982 CHECK_RETURN(device_create_file(dev
, &dev_attr_name
));
983 CHECK_RETURN(device_create_file(dev
, &dev_attr_name_buf
));
984 CHECK_RETURN(device_create_file(dev
, &dev_attr_retrieve_amp_setup
));
985 CHECK_RETURN(device_create_file(dev
, &dev_attr_retrieve_channel
));
986 CHECK_RETURN(device_create_file(dev
, &dev_attr_retrieve_effects_setup
));
987 CHECK_RETURN(device_create_file(dev
, &dev_attr_routing
));
988 CHECK_RETURN(device_create_file(dev
, &dev_attr_serial_number
));
989 CHECK_RETURN(device_create_file(dev
, &dev_attr_store_amp_setup
));
990 CHECK_RETURN(device_create_file(dev
, &dev_attr_store_channel
));
991 CHECK_RETURN(device_create_file(dev
, &dev_attr_store_effects_setup
));
992 CHECK_RETURN(device_create_file(dev
, &dev_attr_tuner_freq
));
993 CHECK_RETURN(device_create_file(dev
, &dev_attr_tuner_mute
));
994 CHECK_RETURN(device_create_file(dev
, &dev_attr_tuner_note
));
995 CHECK_RETURN(device_create_file(dev
, &dev_attr_tuner_pitch
));
998 CHECK_RETURN(device_create_file(dev
, &dev_attr_raw
));
1007 int pod_init(struct usb_interface
*interface
, struct usb_line6_pod
*pod
)
1010 struct usb_line6
*line6
= &pod
->line6
;
1012 if ((interface
== NULL
) || (pod
== NULL
))
1015 pod
->channel_num
= 255;
1017 /* initialize wait queues: */
1018 init_waitqueue_head(&pod
->monitor_level
.wait
);
1019 init_waitqueue_head(&pod
->routing
.wait
);
1020 init_waitqueue_head(&pod
->tuner_mute
.wait
);
1021 init_waitqueue_head(&pod
->tuner_freq
.wait
);
1022 init_waitqueue_head(&pod
->tuner_note
.wait
);
1023 init_waitqueue_head(&pod
->tuner_pitch
.wait
);
1024 init_waitqueue_head(&pod
->clipping
.wait
);
1026 memset(pod
->param_dirty
, 0xff, sizeof(pod
->param_dirty
));
1028 /* initialize USB buffers: */
1029 err
= line6_dumpreq_init(&pod
->dumpreq
, pod_request_channel
,
1030 sizeof(pod_request_channel
));
1032 dev_err(&interface
->dev
, "Out of memory\n");
1033 pod_destruct(interface
);
1037 pod
->buffer_versionreq
= kmalloc(sizeof(pod_request_version
),
1040 if (pod
->buffer_versionreq
== NULL
) {
1041 dev_err(&interface
->dev
, "Out of memory\n");
1042 pod_destruct(interface
);
1046 memcpy(pod
->buffer_versionreq
, pod_request_version
,
1047 sizeof(pod_request_version
));
1049 /* create sysfs entries: */
1050 err
= pod_create_files2(&interface
->dev
);
1052 pod_destruct(interface
);
1056 /* initialize audio system: */
1057 err
= line6_init_audio(line6
);
1059 pod_destruct(interface
);
1063 /* initialize MIDI subsystem: */
1064 err
= line6_init_midi(line6
);
1066 pod_destruct(interface
);
1070 /* initialize PCM subsystem: */
1071 err
= line6_init_pcm(line6
, &pod_pcm_properties
);
1073 pod_destruct(interface
);
1077 /* register audio system: */
1078 err
= line6_register_audio(line6
);
1080 pod_destruct(interface
);
1084 if (pod
->line6
.properties
->capabilities
& LINE6_BIT_CONTROL
) {
1085 /* query some data: */
1086 line6_startup_delayed(&pod
->dumpreq
, POD_STARTUP_DELAY
,
1087 pod_startup_timeout
, pod
);
1088 line6_read_serial_number(&pod
->line6
, &pod
->serial_number
);
1095 POD device disconnected.
1097 void pod_disconnect(struct usb_interface
*interface
)
1099 struct usb_line6_pod
*pod
;
1101 if (interface
== NULL
)
1103 pod
= usb_get_intfdata(interface
);
1106 struct snd_line6_pcm
*line6pcm
= pod
->line6
.line6pcm
;
1107 struct device
*dev
= &interface
->dev
;
1109 if (line6pcm
!= NULL
) {
1110 unlink_wait_clear_audio_out_urbs(line6pcm
);
1111 unlink_wait_clear_audio_in_urbs(line6pcm
);
1115 /* remove sysfs entries: */
1116 if (pod
->versionreq_ok
)
1117 pod_remove_files(pod
->firmware_version
, pod
->line6
.properties
->device_bit
, dev
);
1119 device_remove_file(dev
, &dev_attr_channel
);
1120 device_remove_file(dev
, &dev_attr_clip
);
1121 device_remove_file(dev
, &dev_attr_device_id
);
1122 device_remove_file(dev
, &dev_attr_dirty
);
1123 device_remove_file(dev
, &dev_attr_dump
);
1124 device_remove_file(dev
, &dev_attr_dump_buf
);
1125 device_remove_file(dev
, &dev_attr_finish
);
1126 device_remove_file(dev
, &dev_attr_firmware_version
);
1127 device_remove_file(dev
, &dev_attr_midi_postprocess
);
1128 device_remove_file(dev
, &dev_attr_monitor_level
);
1129 device_remove_file(dev
, &dev_attr_name
);
1130 device_remove_file(dev
, &dev_attr_name_buf
);
1131 device_remove_file(dev
, &dev_attr_retrieve_amp_setup
);
1132 device_remove_file(dev
, &dev_attr_retrieve_channel
);
1133 device_remove_file(dev
, &dev_attr_retrieve_effects_setup
);
1134 device_remove_file(dev
, &dev_attr_routing
);
1135 device_remove_file(dev
, &dev_attr_serial_number
);
1136 device_remove_file(dev
, &dev_attr_store_amp_setup
);
1137 device_remove_file(dev
, &dev_attr_store_channel
);
1138 device_remove_file(dev
, &dev_attr_store_effects_setup
);
1139 device_remove_file(dev
, &dev_attr_tuner_freq
);
1140 device_remove_file(dev
, &dev_attr_tuner_mute
);
1141 device_remove_file(dev
, &dev_attr_tuner_note
);
1142 device_remove_file(dev
, &dev_attr_tuner_pitch
);
1145 device_remove_file(dev
, &dev_attr_raw
);
1150 pod_destruct(interface
);