RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / staging / line6 / pod.c
blob63318d717cd70486adf8cc8ab99c63e1b2624fab
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 <linux/slab.h>
16 #include "audio.h"
17 #include "capture.h"
18 #include "control.h"
19 #include "playback.h"
20 #include "pod.h"
23 #define POD_SYSEX_CODE 3
24 #define POD_BYTES_PER_FRAME 6 /* 24bit audio (stereo) */
27 enum {
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 */
41 enum {
42 POD_monitor_level = 0x04,
43 POD_routing = 0x05,
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
51 enum {
52 POD_DUMP_MEMORY = 2
55 enum {
56 POD_BUSY_READ,
57 POD_BUSY_WRITE,
58 POD_CHANNEL_DIRTY,
59 POD_SAVE_PRESSED,
60 POD_BUSY_MIDISEND
64 static struct snd_ratden pod_ratden = {
65 .num_min = 78125,
66 .num_max = 78125,
67 .num_step = 1,
68 .den = 2
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,
81 .rate_min = 39062,
82 .rate_max = 39063,
83 .channels_min = 2,
84 .channels_max = 2,
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,
88 .periods_min = 1,
89 .periods_max = 1024
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,
99 .rate_min = 39062,
100 .rate_max = 39063,
101 .channels_min = 2,
102 .channels_max = 2,
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,
106 .periods_min = 1,
107 .periods_max = 1024
109 .snd_line6_rates = {
110 .nrats = 1,
111 .rats = &pod_ratden
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)
126 int i;
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)
149 enum {
150 REQUEST_NONE,
151 REQUEST_DUMP,
152 REQUEST_VERSION
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;
161 } else {
162 if (pod->versionreq_ok)
163 request = REQUEST_DUMP;
164 else if (pod->startup_count++ & 1)
165 request = REQUEST_DUMP;
166 else
167 request = REQUEST_VERSION;
170 switch (request) {
171 case REQUEST_DUMP:
172 line6_dump_request_async(&pod->dumpreq, &pod->line6, 0);
173 break;
175 case REQUEST_VERSION:
176 pod_version_request_async(pod);
177 break;
179 default:
180 return;
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);
198 if (!sysex)
199 return;
200 /* Don't know what this is good for, but PODxt Pro transmits it, so we
201 * also do... */
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);
207 kfree(sysex);
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);
217 pod->dirty = 1;
221 Handle SAVE button
223 static void pod_save_button_pressed(struct usb_line6_pod *pod, int type, int index)
225 pod->dirty = 0;
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 */
243 default:
244 return; /* ignore all others */
247 /* process all remaining messages */
248 switch (buf[0]) {
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);
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);
291 } else
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));
295 break;
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) \
301 case POD_ ## x: \
302 pod->x.value = value; \
303 wake_up_interruptible(&pod->x.wait); \
304 break;
306 switch (buf[6]) {
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
316 default:
317 DEBUG_MESSAGES(dev_err(pod->line6.ifcdev, "unknown tuner/system response %02X\n", buf[6]));
320 break;
323 case POD_SYSEX_FINISH:
324 /* do we need to respond to this? */
325 break;
327 case POD_SYSEX_SAVE:
328 pod_save_button_pressed(pod, buf[6], buf[7]);
329 break;
331 case POD_SYSEX_CLIP:
332 DEBUG_MESSAGES(dev_err(pod->line6.ifcdev, "audio clipped\n"));
333 pod->clipping.value = 1;
334 wake_up_interruptible(&pod->clipping.wait);
335 break;
337 case POD_SYSEX_STORE:
338 DEBUG_MESSAGES(dev_err(pod->line6.ifcdev, "message %02X not yet implemented\n", buf[5]));
339 break;
341 default:
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);
354 } else
355 DEBUG_MESSAGES(dev_err(pod->line6.ifcdev, "multiple firmware version message\n"));
356 } else
357 DEBUG_MESSAGES(dev_err(pod->line6.ifcdev, "unknown sysex header\n"));
359 break;
361 case LINE6_SYSEX_END:
362 break;
364 default:
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
378 byte.
380 void pod_midi_postprocess(struct usb_line6_pod *pod, unsigned char *data, int length)
382 int i;
384 if (!pod->midi_postprocess)
385 return;
387 for (i = 0; i < length; ++i) {
388 if (data[i] == (LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST)) {
389 line6_invalidate_current(&pod->dumpreq);
390 break;
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);
394 break;
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;
408 else
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)
429 unsigned long value;
430 short block;
431 int ret;
433 ret = strict_strtoul(buf, 10, &value);
434 if (ret)
435 return ret;
437 block = (value < 0x40) ? block0 : block1;
438 value &= 0x3f;
439 location[0] = block >> 7;
440 location[1] = value | (block & 0x7f);
441 return 0;
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);
451 int ret;
452 int size = 3 + sizeof(pod->prog_data_buf);
453 char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_STORE, size);
455 if (!sysex)
456 return 0;
458 sysex[SYSEX_DATA_OFS] = 5; /* see pod_dump() */
459 ret = pod_resolve(buf, block0, block1, sysex + SYSEX_DATA_OFS + 1);
460 if (ret) {
461 kfree(sysex);
462 return ret;
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);
468 kfree(sysex);
469 /* needs some delay here on AMD64 platform */
470 return count;
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);
480 int ret;
481 int size = 4;
482 char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_DUMPMEM, size);
484 if (!sysex)
485 return 0;
487 ret = pod_resolve(buf, block0, block1, sysex + SYSEX_DATA_OFS);
488 if (ret) {
489 kfree(sysex);
490 return ret;
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);
499 kfree(sysex);
500 /* needs some delay here on AMD64 platform */
501 return count;
505 Generic get name function.
507 static ssize_t get_name_generic(struct usb_line6_pod *pod, const char *str, char *buf)
509 int length = 0;
510 const char *p1;
511 char *p2;
512 char *last_non_space = buf;
514 int retval = line6_wait_dump(&pod->dumpreq, 0);
515 if (retval < 0)
516 return retval;
518 for (p1 = str, p2 = buf; *p1; ++p1, ++p2) {
519 *p2 = *p1;
520 if (*p2 != ' ')
521 last_non_space = p2;
522 if (++length == POD_NAME_LENGTH)
523 break;
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);
550 unsigned long value;
551 int ret;
553 ret = strict_strtoul(buf, 10, &value);
554 if (ret)
555 return ret;
557 pod_send_channel(pod, value);
558 return count;
562 "read" request on "name" special file.
564 static ssize_t pod_get_name(struct device *dev, struct device_attribute *attr,
565 char *buf)
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,
587 char *buf)
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);
592 if (retval < 0)
593 return retval;
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));
611 return -EINVAL;
614 pod_dump(pod, buf);
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)
624 char *sysex;
625 int value;
626 static const int size = 1;
627 int retval = 0;
628 DECLARE_WAITQUEUE(wait, current);
630 if (((pod->prog_data.control[POD_tuner] & 0x40) == 0) && tuner)
631 return -ENODEV;
633 /* send value request to tuner: */
634 param->value = POD_system_invalid;
635 sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEMREQ, size);
636 if (!sysex)
637 return 0;
638 sysex[SYSEX_DATA_OFS] = code;
639 line6_send_sysex_message(&pod->line6, sysex, size);
640 kfree(sysex);
642 /* wait for tuner to respond: */
643 add_wait_queue(&param->wait, &wait);
644 current->state = TASK_INTERRUPTIBLE;
646 while (param->value == POD_system_invalid) {
647 if (signal_pending(current)) {
648 retval = -ERESTARTSYS;
649 break;
650 } else
651 schedule();
654 current->state = TASK_RUNNING;
655 remove_wait_queue(&param->wait, &wait);
657 if (retval < 0)
658 return retval;
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,
670 int tuner)
672 char *sysex;
673 static const int size = 5;
674 unsigned short value;
675 unsigned long result;
676 int ret;
678 if (((pod->prog_data.control[POD_tuner] & 0x40) == 0) && tuner)
679 return -EINVAL;
681 /* send value to tuner: */
682 sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEM, size);
683 if (!sysex)
684 return 0;
686 ret = strict_strtoul(buf, 10, &result);
687 if (ret)
688 return ret;
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);
697 kfree(sysex);
698 return count;
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);
710 if (retval < 0)
711 return retval;
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));
730 return -EINVAL;
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);
746 int size = 0;
747 char *sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_FINISH, size);
748 if (!sysex)
749 return 0;
750 line6_send_sysex_message(&pod->line6, sysex, size);
751 kfree(sysex);
752 return count;
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,
819 char *buf)
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';
824 buf[1] = '\n';
825 return 2;
829 "read" request on "midi_postprocess" special file.
831 static ssize_t pod_get_midi_postprocess(struct device *dev,
832 struct device_attribute *attr,
833 char *buf)
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);
849 unsigned long value;
850 int ret;
852 ret = strict_strtoul(buf, 10, &value);
853 if (ret)
854 return ret;
856 pod->midi_postprocess = value ? 1 : 0;
857 return count;
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,
876 char *buf)
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);
903 int err = 0;
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)) {
911 err = -ERESTARTSYS;
912 break;
913 } else
914 schedule();
917 current->state = TASK_RUNNING;
918 remove_wait_queue(&pod->clipping.wait, &wait);
919 return err;
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, \
929 tuner, sign); \
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, \
941 tuner); \
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_IWUSR | 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_IWUSR | S_IRUGO, pod_get_dump, pod_set_dump);
960 static DEVICE_ATTR(dump_buf, S_IWUSR | S_IRUGO, pod_get_dump_buf, pod_set_dump_buf);
961 static DEVICE_ATTR(finish, S_IWUSR, 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_IWUSR | S_IRUGO, pod_get_midi_postprocess, pod_set_midi_postprocess);
964 static DEVICE_ATTR(monitor_level, S_IWUSR | 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_IWUSR, line6_nop_read, pod_set_retrieve_amp_setup);
968 static DEVICE_ATTR(retrieve_channel, S_IWUSR, line6_nop_read, pod_set_retrieve_channel);
969 static DEVICE_ATTR(retrieve_effects_setup, S_IWUSR, line6_nop_read, pod_set_retrieve_effects_setup);
970 static DEVICE_ATTR(routing, S_IWUSR | 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_IWUSR, line6_nop_read, pod_set_store_amp_setup);
973 static DEVICE_ATTR(store_channel, S_IWUSR, line6_nop_read, pod_set_store_channel);
974 static DEVICE_ATTR(store_effects_setup, S_IWUSR, line6_nop_read, pod_set_store_effects_setup);
975 static DEVICE_ATTR(tuner_freq, S_IWUSR | S_IRUGO, pod_get_tuner_freq, pod_set_tuner_freq);
976 static DEVICE_ATTR(tuner_mute, S_IWUSR | 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);
980 #if CREATE_RAW_FILE
981 static DEVICE_ATTR(raw, S_IWUSR, line6_nop_read, line6_set_raw);
982 #endif
985 POD destructor.
987 static void pod_destruct(struct usb_interface *interface)
989 struct usb_line6_pod *pod = usb_get_intfdata(interface);
990 struct usb_line6 *line6;
992 if (pod == NULL)
993 return;
994 line6 = &pod->line6;
995 if (line6 == NULL)
996 return;
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)
1010 int err;
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));
1037 #if CREATE_RAW_FILE
1038 CHECK_RETURN(device_create_file(dev, &dev_attr_raw));
1039 #endif
1041 return 0;
1045 Init POD device.
1047 int pod_init(struct usb_interface *interface, struct usb_line6_pod *pod)
1049 int err;
1050 struct usb_line6 *line6 = &pod->line6;
1052 if ((interface == NULL) || (pod == NULL))
1053 return -ENODEV;
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));
1071 if (err < 0) {
1072 dev_err(&interface->dev, "Out of memory\n");
1073 pod_destruct(interface);
1074 return -ENOMEM;
1077 pod->buffer_versionreq = kmemdup(pod_request_version,
1078 sizeof(pod_request_version),
1079 GFP_KERNEL);
1081 if (pod->buffer_versionreq == NULL) {
1082 dev_err(&interface->dev, "Out of memory\n");
1083 pod_destruct(interface);
1084 return -ENOMEM;
1087 /* create sysfs entries: */
1088 err = pod_create_files2(&interface->dev);
1089 if (err < 0) {
1090 pod_destruct(interface);
1091 return err;
1094 /* initialize audio system: */
1095 err = line6_init_audio(line6);
1096 if (err < 0) {
1097 pod_destruct(interface);
1098 return err;
1101 /* initialize MIDI subsystem: */
1102 err = line6_init_midi(line6);
1103 if (err < 0) {
1104 pod_destruct(interface);
1105 return err;
1108 /* initialize PCM subsystem: */
1109 err = line6_init_pcm(line6, &pod_pcm_properties);
1110 if (err < 0) {
1111 pod_destruct(interface);
1112 return err;
1115 /* register audio system: */
1116 err = line6_register_audio(line6);
1117 if (err < 0) {
1118 pod_destruct(interface);
1119 return err;
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);
1129 return 0;
1133 POD device disconnected.
1135 void pod_disconnect(struct usb_interface *interface)
1137 struct usb_line6_pod *pod;
1139 if (interface == NULL)
1140 return;
1141 pod = usb_get_intfdata(interface);
1143 if (pod != NULL) {
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);
1152 if (dev != NULL) {
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);
1182 #if CREATE_RAW_FILE
1183 device_remove_file(dev, &dev_attr_raw);
1184 #endif
1188 pod_destruct(interface);