Staging: line6: remove DEVICE_ATTRIBUTE
[linux-2.6/linux-2.6-openrd.git] / drivers / staging / line6 / pod.c
blobaf18087f1ed148dc587c9bab35d54fdaf68cc863
1 /*
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.
12 #include "driver.h"
14 #include "audio.h"
15 #include "capture.h"
16 #include "control.h"
17 #include "playback.h"
18 #include "pod.h"
21 #define POD_SYSEX_CODE 3
22 #define POD_BYTES_PER_FRAME 6 /* 24bit audio (stereo) */
25 enum {
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 */
39 enum {
40 POD_monitor_level = 0x04,
41 POD_routing = 0x05,
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
49 enum {
50 POD_DUMP_MEMORY = 2
53 enum {
54 POD_BUSY_READ,
55 POD_BUSY_WRITE,
56 POD_CHANNEL_DIRTY,
57 POD_SAVE_PRESSED,
58 POD_BUSY_MIDISEND
62 static struct snd_ratden pod_ratden = {
63 .num_min = 78125,
64 .num_max = 78125,
65 .num_step = 1,
66 .den = 2
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,
79 .rate_min = 39062,
80 .rate_max = 39063,
81 .channels_min = 2,
82 .channels_max = 2,
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,
86 .periods_min = 1,
87 .periods_max = 1024
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,
97 .rate_min = 39062,
98 .rate_max = 39063,
99 .channels_min = 2,
100 .channels_max = 2,
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,
104 .periods_min = 1,
105 .periods_max = 1024
107 .snd_line6_rates = {
108 .nrats = 1,
109 .rats = &pod_ratden
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)
124 int i;
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 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
139 static void pod_create_files_work(struct work_struct *work)
141 struct usb_line6_pod *pod = container_of(work, struct usb_line6_pod, create_files_work);
142 #else
143 static void pod_create_files_work(void *work)
145 struct usb_line6_pod *pod = (struct usb_line6_pod *)work;
146 #endif
148 pod_create_files(pod->firmware_version, pod->line6.properties->device_bit, pod->line6.ifcdev);
151 static void pod_startup_timeout(unsigned long arg)
153 enum {
154 REQUEST_NONE,
155 REQUEST_DUMP,
156 REQUEST_VERSION
159 int request = REQUEST_NONE;
160 struct usb_line6_pod *pod = (struct usb_line6_pod *)arg;
162 if(pod->dumpreq.ok) {
163 if(!pod->versionreq_ok)
164 request = REQUEST_VERSION;
166 else {
167 if(pod->versionreq_ok)
168 request = REQUEST_DUMP;
169 else if(pod->startup_count++ & 1)
170 request = REQUEST_DUMP;
171 else
172 request = REQUEST_VERSION;
175 switch(request) {
176 case REQUEST_DUMP:
177 line6_dump_request_async(&pod->dumpreq, &pod->line6, 0);
178 break;
180 case REQUEST_VERSION:
181 pod_version_request_async(pod);
182 break;
184 default:
185 return;
188 line6_startup_delayed(&pod->dumpreq, 1, pod_startup_timeout, pod);
191 static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code, int size)
193 return line6_alloc_sysex_buffer(&pod->line6, POD_SYSEX_CODE, code, size);
197 Send channel dump data to the PODxt Pro.
199 static void pod_dump(struct usb_line6_pod *pod, const unsigned char *data)
201 int size = 1 + sizeof(pod->prog_data);
202 char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_DUMP, size);
203 if(!sysex) return;
204 sysex[SYSEX_DATA_OFS] = 5; /* Don't know what this is good for, but PODxt Pro transmits it, so we also do... */
205 memcpy(sysex + SYSEX_DATA_OFS + 1, data, sizeof(pod->prog_data));
206 line6_send_sysex_message(&pod->line6, sysex, size);
207 memcpy(&pod->prog_data, data, sizeof(pod->prog_data));
208 pod_mark_batch_all_dirty(pod);
209 kfree(sysex);
213 Store parameter value in driver memory and mark it as dirty.
215 static void pod_store_parameter(struct usb_line6_pod *pod, int param, int value)
217 pod->prog_data.control[param] = value;
218 set_bit(param, pod->param_dirty);
219 pod->dirty = 1;
223 Handle SAVE button
225 static void pod_save_button_pressed(struct usb_line6_pod *pod, int type, int index)
227 pod->dirty = 0;
228 set_bit(POD_SAVE_PRESSED, &pod->atomic_flags);
232 Process a completely received message.
234 void pod_process_message(struct usb_line6_pod *pod)
236 const unsigned char *buf = pod->line6.buffer_message;
238 /* filter messages by type */
239 switch(buf[0] & 0xf0) {
240 case LINE6_PARAM_CHANGE:
241 case LINE6_PROGRAM_CHANGE:
242 case LINE6_SYSEX_BEGIN:
243 break; /* handle these further down */
245 default:
246 return; /* ignore all others */
249 /* process all remaining messages */
250 switch(buf[0]) {
251 case LINE6_PARAM_CHANGE | LINE6_CHANNEL_DEVICE:
252 pod_store_parameter(pod, buf[1], buf[2]);
253 /* intentionally no break here! */
255 case LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST:
256 if((buf[1] == POD_amp_model_setup) || (buf[1] == POD_effect_setup)) /* these also affect other settings */
257 line6_dump_request_async(&pod->dumpreq, &pod->line6, 0);
259 break;
261 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_DEVICE:
262 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST:
263 pod->channel_num = buf[1];
264 pod->dirty = 0;
265 set_bit(POD_CHANNEL_DIRTY, &pod->atomic_flags);
266 line6_dump_request_async(&pod->dumpreq, &pod->line6, 0);
267 break;
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) {
272 switch(buf[5]) {
273 case POD_SYSEX_DUMP:
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);
279 pod->dumpreq.ok = 1;
280 break;
282 case POD_DUMP_MEMORY:
283 memcpy(&pod->prog_data_buf, buf + 7, sizeof(pod->prog_data_buf));
284 break;
286 default:
287 DEBUG_MESSAGES(dev_err(pod->line6.ifcdev, "unknown dump code %02X\n", pod->dumpreq.in_progress));
290 line6_dump_finished(&pod->dumpreq);
292 else
293 DEBUG_MESSAGES(dev_err(pod->line6.ifcdev, "wrong size of channel dump message (%d instead of %d)\n",
294 pod->line6.message_length, (int)sizeof(pod->prog_data) + 7));
296 break;
298 case POD_SYSEX_SYSTEM: {
299 short value = ((int)buf[7] << 12) | ((int)buf[8] << 8) | ((int)buf[9] << 4) | (int)buf[10];
301 #define PROCESS_SYSTEM_PARAM(x) \
302 case POD_ ## x: \
303 pod->x.value = value; \
304 wake_up_interruptible(&pod->x.wait); \
305 break;
307 switch(buf[6]) {
308 PROCESS_SYSTEM_PARAM(monitor_level);
309 PROCESS_SYSTEM_PARAM(routing);
310 PROCESS_SYSTEM_PARAM(tuner_mute);
311 PROCESS_SYSTEM_PARAM(tuner_freq);
312 PROCESS_SYSTEM_PARAM(tuner_note);
313 PROCESS_SYSTEM_PARAM(tuner_pitch);
315 #undef PROCESS_SYSTEM_PARAM
317 default:
318 DEBUG_MESSAGES(dev_err(pod->line6.ifcdev, "unknown tuner/system response %02X\n", buf[6]));
321 break;
324 case POD_SYSEX_FINISH:
325 /* do we need to respond to this? */
326 break;
328 case POD_SYSEX_SAVE:
329 pod_save_button_pressed(pod, buf[6], buf[7]);
330 break;
332 case POD_SYSEX_CLIP:
333 DEBUG_MESSAGES(dev_err(pod->line6.ifcdev, "audio clipped\n"));
334 pod->clipping.value = 1;
335 wake_up_interruptible(&pod->clipping.wait);
336 break;
338 case POD_SYSEX_STORE:
339 DEBUG_MESSAGES(dev_err(pod->line6.ifcdev, "message %02X not yet implemented\n", buf[5]));
340 break;
342 default:
343 DEBUG_MESSAGES(dev_err(pod->line6.ifcdev, "unknown sysex message %02X\n", buf[5]));
346 else if(memcmp(buf, pod_version_header, sizeof(pod_version_header)) == 0) {
347 if(pod->versionreq_ok == 0) {
348 pod->firmware_version = buf[13] * 100 + buf[14] * 10 + buf[15];
349 pod->device_id = ((int)buf[8] << 16) | ((int)buf[9] << 8) | (int)buf[10];
350 pod->versionreq_ok = 1;
352 /* Now we know the firmware version, so we schedule a bottom half
353 handler to create the special files: */
354 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
355 INIT_WORK(&pod->create_files_work, pod_create_files_work);
356 #else
357 INIT_WORK(&pod->create_files_work, pod_create_files_work, pod);
358 #endif
359 queue_work(line6_workqueue, &pod->create_files_work);
361 else
362 DEBUG_MESSAGES(dev_err(pod->line6.ifcdev, "multiple firmware version message\n"));
364 else
365 DEBUG_MESSAGES(dev_err(pod->line6.ifcdev, "unknown sysex header\n"));
367 break;
369 case LINE6_SYSEX_END:
370 break;
372 default:
373 DEBUG_MESSAGES(dev_err(pod->line6.ifcdev, "POD: unknown message %02X\n", buf[0]));
378 Detect some cases that require a channel dump after sending a command to the
379 device. Important notes:
380 *) The actual dump request can not be sent here since we are not allowed to
381 wait for the completion of the first message in this context, and sending
382 the dump request before completion of the previous message leaves the POD
383 in an undefined state. The dump request will be sent when the echoed
384 commands are received.
385 *) This method fails if a param change message is "chopped" after the first
386 byte.
388 void pod_midi_postprocess(struct usb_line6_pod *pod, unsigned char *data, int length)
390 int i;
392 if(!pod->midi_postprocess)
393 return;
395 for(i = 0; i < length; ++i) {
396 if(data[i] == (LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST)) {
397 line6_invalidate_current(&pod->dumpreq);
398 break;
400 else if((data[i] == (LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST)) && (i < length - 1))
401 if((data[i + 1] == POD_amp_model_setup) || (data[i + 1] == POD_effect_setup)) {
402 line6_invalidate_current(&pod->dumpreq);
403 break;
409 Send channel number (i.e., switch to a different sound).
411 void pod_send_channel(struct usb_line6_pod *pod, int value)
413 line6_invalidate_current(&pod->dumpreq);
415 if(line6_send_program(&pod->line6, value) == 0)
416 pod->channel_num = value;
417 else
418 line6_dump_finished(&pod->dumpreq);
422 Transmit PODxt Pro control parameter.
424 void pod_transmit_parameter(struct usb_line6_pod *pod, int param, int value)
426 if(line6_transmit_parameter(&pod->line6, param, value) == 0)
427 pod_store_parameter(pod, param, value);
429 if((param == POD_amp_model_setup) || (param == POD_effect_setup)) /* these also affect other settings */
430 line6_invalidate_current(&pod->dumpreq);
434 Resolve value to memory location.
436 static void pod_resolve(const char *buf, short block0, short block1, unsigned char *location)
438 int value = simple_strtoul(buf, NULL, 10);
439 short block = (value < 0x40) ? block0 : block1;
440 value &= 0x3f;
441 location[0] = block >> 7;
442 location[1] = value | (block & 0x7f);
446 Send command to store channel/effects setup/amp setup to PODxt Pro.
448 static ssize_t pod_send_store_command(struct device *dev, const char *buf, size_t count, short block0, short block1)
450 struct usb_interface *interface = to_usb_interface(dev);
451 struct usb_line6_pod *pod = usb_get_intfdata(interface);
453 int size = 3 + sizeof(pod->prog_data_buf);
454 char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_STORE, size);
455 if(!sysex) return 0;
457 sysex[SYSEX_DATA_OFS] = 5; /* see pod_dump() */
458 pod_resolve(buf, block0, block1, sysex + SYSEX_DATA_OFS + 1);
459 memcpy(sysex + SYSEX_DATA_OFS + 3, &pod->prog_data_buf, sizeof(pod->prog_data_buf));
461 line6_send_sysex_message(&pod->line6, sysex, size);
462 kfree(sysex);
463 /* needs some delay here on AMD64 platform */
464 return count;
468 Send command to retrieve channel/effects setup/amp setup to PODxt Pro.
470 static ssize_t pod_send_retrieve_command(struct device *dev, const char *buf, size_t count, short block0, short block1)
472 struct usb_interface *interface = to_usb_interface(dev);
473 struct usb_line6_pod *pod = usb_get_intfdata(interface);
475 int size = 4;
476 char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_DUMPMEM, size);
477 if(!sysex) return 0;
479 pod_resolve(buf, block0, block1, sysex + SYSEX_DATA_OFS);
480 sysex[SYSEX_DATA_OFS + 2] = 0;
481 sysex[SYSEX_DATA_OFS + 3] = 0;
482 line6_dump_started(&pod->dumpreq, POD_DUMP_MEMORY);
484 if(line6_send_sysex_message(&pod->line6, sysex, size) < size)
485 line6_dump_finished(&pod->dumpreq);
487 kfree(sysex);
488 /* needs some delay here on AMD64 platform */
489 return count;
493 Generic get name function.
495 static ssize_t get_name_generic(struct usb_line6_pod *pod, const char *str, char *buf)
497 int length = 0;
498 const char *p1;
499 char *p2;
500 char *last_non_space = buf;
502 int retval = line6_wait_dump(&pod->dumpreq, 0);
503 if(retval < 0) return retval;
505 for(p1 = str, p2 = buf; *p1; ++p1, ++p2) {
506 *p2 = *p1;
507 if(*p2 != ' ') last_non_space = p2;
508 if(++length == POD_NAME_LENGTH) break;
511 *(last_non_space + 1) = '\n';
512 return last_non_space - buf + 2;
516 "read" request on "channel" special file.
518 static ssize_t pod_get_channel(struct device *dev,
519 struct device_attribute *attr, char *buf)
521 struct usb_interface *interface = to_usb_interface(dev);
522 struct usb_line6_pod *pod = usb_get_intfdata(interface);
523 return sprintf(buf, "%d\n", pod->channel_num);
527 "write" request on "channel" special file.
529 static ssize_t pod_set_channel(struct device *dev,
530 struct device_attribute *attr,
531 const char *buf, size_t count)
533 struct usb_interface *interface = to_usb_interface(dev);
534 struct usb_line6_pod *pod = usb_get_intfdata(interface);
535 int value = simple_strtoul(buf, NULL, 10);
536 pod_send_channel(pod, value);
537 return count;
541 "read" request on "name" special file.
543 static ssize_t pod_get_name(struct device *dev, struct device_attribute *attr,
544 char *buf)
546 struct usb_interface *interface = to_usb_interface(dev);
547 struct usb_line6_pod *pod = usb_get_intfdata(interface);
548 return get_name_generic(pod, pod->prog_data.header + POD_NAME_OFFSET, buf);
552 "read" request on "name" special file.
554 static ssize_t pod_get_name_buf(struct device *dev,
555 struct device_attribute *attr, char *buf)
557 struct usb_interface *interface = to_usb_interface(dev);
558 struct usb_line6_pod *pod = usb_get_intfdata(interface);
559 return get_name_generic(pod, pod->prog_data_buf.header + POD_NAME_OFFSET, buf);
563 "read" request on "dump" special file.
565 static ssize_t pod_get_dump(struct device *dev, struct device_attribute *attr,
566 char *buf)
568 struct usb_interface *interface = to_usb_interface(dev);
569 struct usb_line6_pod *pod = usb_get_intfdata(interface);
570 int retval = line6_wait_dump(&pod->dumpreq, 0);
571 if(retval < 0) return retval;
572 memcpy(buf, &pod->prog_data, sizeof(pod->prog_data));
573 return sizeof(pod->prog_data);
577 "write" request on "dump" special file.
579 static ssize_t pod_set_dump(struct device *dev, struct device_attribute *attr,
580 const char *buf, size_t count)
582 struct usb_interface *interface = to_usb_interface(dev);
583 struct usb_line6_pod *pod = usb_get_intfdata(interface);
585 if(count != sizeof(pod->prog_data)) {
586 dev_err(pod->line6.ifcdev,
587 "data block must be exactly %d bytes\n",
588 (int)sizeof(pod->prog_data));
589 return -EINVAL;
592 pod_dump(pod, buf);
593 return sizeof(pod->prog_data);
597 Request system parameter.
598 @param tuner non-zero, if code refers to a tuner parameter
600 static ssize_t pod_get_system_param(struct usb_line6_pod *pod, char *buf, int code, struct ValueWait *param, int tuner, int sign)
602 char *sysex;
603 int value;
604 static const int size = 1;
605 int retval = 0;
606 DECLARE_WAITQUEUE(wait, current);
608 if(((pod->prog_data.control[POD_tuner] & 0x40) == 0) && tuner)
609 return -ENODEV;
611 /* send value request to tuner: */
612 param->value = POD_system_invalid;
613 sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEMREQ, size);
614 if(!sysex) return 0;
615 sysex[SYSEX_DATA_OFS] = code;
616 line6_send_sysex_message(&pod->line6, sysex, size);
617 kfree(sysex);
619 /* wait for tuner to respond: */
620 add_wait_queue(&param->wait, &wait);
621 current->state = TASK_INTERRUPTIBLE;
623 while(param->value == POD_system_invalid) {
624 if(signal_pending(current)) {
625 retval = -ERESTARTSYS;
626 break;
628 else
629 schedule();
632 current->state = TASK_RUNNING;
633 remove_wait_queue(&param->wait, &wait);
635 if(retval < 0)
636 return retval;
638 value = sign ? (int)(signed short)param->value : (int)(unsigned short)param->value;
639 return sprintf(buf, "%d\n", value);
643 Send system parameter.
644 @param tuner non-zero, if code refers to a tuner parameter
646 static ssize_t pod_set_system_param(struct usb_line6_pod *pod, const char *buf, int count, int code, unsigned short mask, int tuner)
648 char *sysex;
649 static const int size = 5;
650 unsigned short value;
652 if(((pod->prog_data.control[POD_tuner] & 0x40) == 0) && tuner)
653 return -EINVAL;
655 /* send value to tuner: */
656 sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEM, size);
657 if(!sysex) return 0;
658 value = simple_strtoul(buf, NULL, 10) & mask;
659 sysex[SYSEX_DATA_OFS] = code;
660 sysex[SYSEX_DATA_OFS + 1] = (value >> 12) & 0x0f;
661 sysex[SYSEX_DATA_OFS + 2] = (value >> 8) & 0x0f;
662 sysex[SYSEX_DATA_OFS + 3] = (value >> 4) & 0x0f;
663 sysex[SYSEX_DATA_OFS + 4] = (value ) & 0x0f;
664 line6_send_sysex_message(&pod->line6, sysex, size);
665 kfree(sysex);
666 return count;
670 "read" request on "dump_buf" special file.
672 static ssize_t pod_get_dump_buf(struct device *dev,
673 struct device_attribute *attr, char *buf)
675 struct usb_interface *interface = to_usb_interface(dev);
676 struct usb_line6_pod *pod = usb_get_intfdata(interface);
677 int retval = line6_wait_dump(&pod->dumpreq, 0);
678 if(retval < 0) return retval;
679 memcpy(buf, &pod->prog_data_buf, sizeof(pod->prog_data_buf));
680 return sizeof(pod->prog_data_buf);
684 "write" request on "dump_buf" special file.
686 static ssize_t pod_set_dump_buf(struct device *dev,
687 struct device_attribute *attr,
688 const char *buf, size_t count)
690 struct usb_interface *interface = to_usb_interface(dev);
691 struct usb_line6_pod *pod = usb_get_intfdata(interface);
693 if(count != sizeof(pod->prog_data)) {
694 dev_err(pod->line6.ifcdev,
695 "data block must be exactly %d bytes\n",
696 (int)sizeof(pod->prog_data));
697 return -EINVAL;
700 memcpy(&pod->prog_data_buf, buf, sizeof(pod->prog_data));
701 return sizeof(pod->prog_data);
705 "write" request on "finish" special file.
707 static ssize_t pod_set_finish(struct device *dev,
708 struct device_attribute *attr,
709 const char *buf, size_t count)
711 struct usb_interface *interface = to_usb_interface(dev);
712 struct usb_line6_pod *pod = usb_get_intfdata(interface);
713 int size = 0;
714 char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_FINISH, size);
715 if(!sysex) return 0;
716 line6_send_sysex_message(&pod->line6, sysex, size);
717 kfree(sysex);
718 return count;
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,
785 char *buf)
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';
790 buf[1] = '\n';
791 return 2;
795 "read" request on "midi_postprocess" special file.
797 static ssize_t pod_get_midi_postprocess(struct device *dev,
798 struct device_attribute *attr,
799 char *buf)
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;
817 return count;
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,
836 char *buf)
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, pod->firmware_version % 100);
844 "read" request on "device_id" special file.
846 static ssize_t pod_get_device_id(struct device *dev,
847 struct device_attribute *attr, char *buf)
849 struct usb_interface *interface = to_usb_interface(dev);
850 struct usb_line6_pod *pod = usb_get_intfdata(interface);
851 return sprintf(buf, "%d\n", pod->device_id);
855 "read" request on "clip" special file.
857 static ssize_t pod_wait_for_clip(struct device *dev,
858 struct device_attribute *attr, char *buf)
860 struct usb_interface *interface = to_usb_interface(dev);
861 struct usb_line6_pod *pod = usb_get_intfdata(interface);
862 int err = 0;
863 DECLARE_WAITQUEUE(wait, current);
864 pod->clipping.value = 0;
865 add_wait_queue(&pod->clipping.wait, &wait);
866 current->state = TASK_INTERRUPTIBLE;
868 while(pod->clipping.value == 0) {
869 if(signal_pending(current)) {
870 err = -ERESTARTSYS;
871 break;
873 else
874 schedule();
877 current->state = TASK_RUNNING;
878 remove_wait_queue(&pod->clipping.wait, &wait);
879 return err;
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, tuner, sign); \
891 #define POD_GET_SET_SYSTEM_PARAM(code, mask, tuner, sign) \
892 POD_GET_SYSTEM_PARAM(code, tuner, sign) \
893 static ssize_t pod_set_ ## code(struct device *dev, \
894 struct device_attribute *attr, const char *buf, \
895 size_t count) \
897 struct usb_interface *interface = to_usb_interface(dev); \
898 struct usb_line6_pod *pod = usb_get_intfdata(interface); \
899 return pod_set_system_param(pod, buf, count, POD_ ## code, mask, tuner); \
902 POD_GET_SET_SYSTEM_PARAM(monitor_level, 0xffff, 0, 0);
903 POD_GET_SET_SYSTEM_PARAM(routing, 0x0003, 0, 0);
904 POD_GET_SET_SYSTEM_PARAM(tuner_mute, 0x0001, 1, 0);
905 POD_GET_SET_SYSTEM_PARAM(tuner_freq, 0xffff, 1, 0);
906 POD_GET_SYSTEM_PARAM(tuner_note, 1, 1);
907 POD_GET_SYSTEM_PARAM(tuner_pitch, 1, 1);
909 #undef GET_SET_SYSTEM_PARAM
910 #undef GET_SYSTEM_PARAM
912 /* POD special files: */
913 static DEVICE_ATTR(channel, S_IWUGO | S_IRUGO, pod_get_channel, pod_set_channel);
914 static DEVICE_ATTR(clip, S_IRUGO, pod_wait_for_clip, line6_nop_write);
915 static DEVICE_ATTR(device_id, S_IRUGO, pod_get_device_id, line6_nop_write);
916 static DEVICE_ATTR(dirty, S_IRUGO, pod_get_dirty, line6_nop_write);
917 static DEVICE_ATTR(dump, S_IWUGO | S_IRUGO, pod_get_dump, pod_set_dump);
918 static DEVICE_ATTR(dump_buf, S_IWUGO | S_IRUGO, pod_get_dump_buf, pod_set_dump_buf);
919 static DEVICE_ATTR(finish, S_IWUGO, line6_nop_read, pod_set_finish);
920 static DEVICE_ATTR(firmware_version, S_IRUGO, pod_get_firmware_version, line6_nop_write);
921 static DEVICE_ATTR(midi_postprocess, S_IWUGO | S_IRUGO, pod_get_midi_postprocess, pod_set_midi_postprocess);
922 static DEVICE_ATTR(monitor_level, S_IWUGO | S_IRUGO, pod_get_monitor_level, pod_set_monitor_level);
923 static DEVICE_ATTR(name, S_IRUGO, pod_get_name, line6_nop_write);
924 static DEVICE_ATTR(name_buf, S_IRUGO, pod_get_name_buf, line6_nop_write);
925 static DEVICE_ATTR(retrieve_amp_setup, S_IWUGO, line6_nop_read, pod_set_retrieve_amp_setup);
926 static DEVICE_ATTR(retrieve_channel, S_IWUGO, line6_nop_read, pod_set_retrieve_channel);
927 static DEVICE_ATTR(retrieve_effects_setup, S_IWUGO, line6_nop_read, pod_set_retrieve_effects_setup);
928 static DEVICE_ATTR(routing, S_IWUGO | S_IRUGO, pod_get_routing, pod_set_routing);
929 static DEVICE_ATTR(serial_number, S_IRUGO, pod_get_serial_number, line6_nop_write);
930 static DEVICE_ATTR(store_amp_setup, S_IWUGO, line6_nop_read, pod_set_store_amp_setup);
931 static DEVICE_ATTR(store_channel, S_IWUGO, line6_nop_read, pod_set_store_channel);
932 static DEVICE_ATTR(store_effects_setup, S_IWUGO, line6_nop_read, pod_set_store_effects_setup);
933 static DEVICE_ATTR(tuner_freq, S_IWUGO | S_IRUGO, pod_get_tuner_freq, pod_set_tuner_freq);
934 static DEVICE_ATTR(tuner_mute, S_IWUGO | S_IRUGO, pod_get_tuner_mute, pod_set_tuner_mute);
935 static DEVICE_ATTR(tuner_note, S_IRUGO, pod_get_tuner_note, line6_nop_write);
936 static DEVICE_ATTR(tuner_pitch, S_IRUGO, pod_get_tuner_pitch, line6_nop_write);
938 #if CREATE_RAW_FILE
939 static DEVICE_ATTR(raw, S_IWUGO, line6_nop_read, line6_set_raw);
940 #endif
943 POD destructor.
945 static void pod_destruct(struct usb_interface *interface)
947 struct usb_line6_pod *pod = usb_get_intfdata(interface);
948 struct usb_line6 *line6;
950 if(pod == NULL) return;
951 line6 = &pod->line6;
952 if(line6 == NULL) return;
953 line6_cleanup_audio(line6);
955 /* free dump request data: */
956 line6_dumpreq_destruct(&pod->dumpreq);
958 if(pod->buffer_versionreq) kfree(pod->buffer_versionreq);
962 Create sysfs entries.
964 int pod_create_files2(struct device *dev)
966 int err;
968 CHECK_RETURN(device_create_file(dev, &dev_attr_channel));
969 CHECK_RETURN(device_create_file(dev, &dev_attr_clip));
970 CHECK_RETURN(device_create_file(dev, &dev_attr_device_id));
971 CHECK_RETURN(device_create_file(dev, &dev_attr_dirty));
972 CHECK_RETURN(device_create_file(dev, &dev_attr_dump));
973 CHECK_RETURN(device_create_file(dev, &dev_attr_dump_buf));
974 CHECK_RETURN(device_create_file(dev, &dev_attr_finish));
975 CHECK_RETURN(device_create_file(dev, &dev_attr_firmware_version));
976 CHECK_RETURN(device_create_file(dev, &dev_attr_midi_postprocess));
977 CHECK_RETURN(device_create_file(dev, &dev_attr_monitor_level));
978 CHECK_RETURN(device_create_file(dev, &dev_attr_name));
979 CHECK_RETURN(device_create_file(dev, &dev_attr_name_buf));
980 CHECK_RETURN(device_create_file(dev, &dev_attr_retrieve_amp_setup));
981 CHECK_RETURN(device_create_file(dev, &dev_attr_retrieve_channel));
982 CHECK_RETURN(device_create_file(dev, &dev_attr_retrieve_effects_setup));
983 CHECK_RETURN(device_create_file(dev, &dev_attr_routing));
984 CHECK_RETURN(device_create_file(dev, &dev_attr_serial_number));
985 CHECK_RETURN(device_create_file(dev, &dev_attr_store_amp_setup));
986 CHECK_RETURN(device_create_file(dev, &dev_attr_store_channel));
987 CHECK_RETURN(device_create_file(dev, &dev_attr_store_effects_setup));
988 CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_freq));
989 CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_mute));
990 CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_note));
991 CHECK_RETURN(device_create_file(dev, &dev_attr_tuner_pitch));
993 #if CREATE_RAW_FILE
994 CHECK_RETURN(device_create_file(dev, &dev_attr_raw));
995 #endif
997 return 0;
1001 Init POD device.
1003 int pod_init(struct usb_interface *interface, struct usb_line6_pod *pod)
1005 int err;
1006 struct usb_line6 *line6 = &pod->line6;
1008 if((interface == NULL) || (pod == NULL)) return -ENODEV;
1010 pod->channel_num = 255;
1012 /* initialize wait queues: */
1013 init_waitqueue_head(&pod->monitor_level.wait);
1014 init_waitqueue_head(&pod->routing.wait);
1015 init_waitqueue_head(&pod->tuner_mute.wait);
1016 init_waitqueue_head(&pod->tuner_freq.wait);
1017 init_waitqueue_head(&pod->tuner_note.wait);
1018 init_waitqueue_head(&pod->tuner_pitch.wait);
1019 init_waitqueue_head(&pod->clipping.wait);
1021 memset(pod->param_dirty, 0xff, sizeof(pod->param_dirty));
1023 /* initialize USB buffers: */
1024 err = line6_dumpreq_init(&pod->dumpreq, pod_request_channel, sizeof(pod_request_channel));
1026 if(err < 0) {
1027 dev_err(&interface->dev, "Out of memory\n");
1028 pod_destruct(interface);
1029 return -ENOMEM;
1032 pod->buffer_versionreq = kmalloc(sizeof(pod_request_version), GFP_KERNEL);
1034 if(pod->buffer_versionreq == NULL) {
1035 dev_err(&interface->dev, "Out of memory\n");
1036 pod_destruct(interface);
1037 return -ENOMEM;
1040 memcpy(pod->buffer_versionreq, pod_request_version, sizeof(pod_request_version));
1042 /* create sysfs entries: */
1043 if((err = pod_create_files2(&interface->dev)) < 0) {
1044 pod_destruct(interface);
1045 return err;
1048 /* initialize audio system: */
1049 if((err = line6_init_audio(line6)) < 0) {
1050 pod_destruct(interface);
1051 return err;
1054 /* initialize MIDI subsystem: */
1055 if((err = line6_init_midi(line6)) < 0) {
1056 pod_destruct(interface);
1057 return err;
1060 /* initialize PCM subsystem: */
1061 if((err = line6_init_pcm(line6, &pod_pcm_properties)) < 0) {
1062 pod_destruct(interface);
1063 return err;
1066 /* register audio system: */
1067 if((err = line6_register_audio(line6)) < 0) {
1068 pod_destruct(interface);
1069 return err;
1072 if(pod->line6.properties->capabilities & LINE6_BIT_CONTROL) {
1073 /* query some data: */
1074 line6_startup_delayed(&pod->dumpreq, POD_STARTUP_DELAY, pod_startup_timeout, pod);
1075 line6_read_serial_number(&pod->line6, &pod->serial_number);
1078 return 0;
1082 POD device disconnected.
1084 void pod_disconnect(struct usb_interface *interface)
1086 struct usb_line6_pod *pod;
1088 if(interface == NULL) return;
1089 pod = usb_get_intfdata(interface);
1091 if(pod != NULL) {
1092 struct snd_line6_pcm *line6pcm = pod->line6.line6pcm;
1093 struct device *dev = &interface->dev;
1095 if(line6pcm != NULL) {
1096 unlink_wait_clear_audio_out_urbs(line6pcm);
1097 unlink_wait_clear_audio_in_urbs(line6pcm);
1100 if(dev != NULL) {
1101 /* remove sysfs entries: */
1102 if(pod->versionreq_ok)
1103 pod_remove_files(pod->firmware_version, pod->line6.properties->device_bit, dev);
1105 device_remove_file(dev, &dev_attr_channel);
1106 device_remove_file(dev, &dev_attr_clip);
1107 device_remove_file(dev, &dev_attr_device_id);
1108 device_remove_file(dev, &dev_attr_dirty);
1109 device_remove_file(dev, &dev_attr_dump);
1110 device_remove_file(dev, &dev_attr_dump_buf);
1111 device_remove_file(dev, &dev_attr_finish);
1112 device_remove_file(dev, &dev_attr_firmware_version);
1113 device_remove_file(dev, &dev_attr_midi_postprocess);
1114 device_remove_file(dev, &dev_attr_monitor_level);
1115 device_remove_file(dev, &dev_attr_name);
1116 device_remove_file(dev, &dev_attr_name_buf);
1117 device_remove_file(dev, &dev_attr_retrieve_amp_setup);
1118 device_remove_file(dev, &dev_attr_retrieve_channel);
1119 device_remove_file(dev, &dev_attr_retrieve_effects_setup);
1120 device_remove_file(dev, &dev_attr_routing);
1121 device_remove_file(dev, &dev_attr_serial_number);
1122 device_remove_file(dev, &dev_attr_store_amp_setup);
1123 device_remove_file(dev, &dev_attr_store_channel);
1124 device_remove_file(dev, &dev_attr_store_effects_setup);
1125 device_remove_file(dev, &dev_attr_tuner_freq);
1126 device_remove_file(dev, &dev_attr_tuner_mute);
1127 device_remove_file(dev, &dev_attr_tuner_note);
1128 device_remove_file(dev, &dev_attr_tuner_pitch);
1130 #if CREATE_RAW_FILE
1131 device_remove_file(dev, &dev_attr_raw);
1132 #endif
1136 pod_destruct(interface);