1 // SPDX-License-Identifier: GPL-2.0-only
3 * Line 6 Linux USB driver
8 #include <linux/slab.h>
9 #include <linux/wait.h>
10 #include <linux/interrupt.h>
11 #include <linux/module.h>
12 #include <linux/usb.h>
14 #include <sound/core.h>
15 #include <sound/control.h>
22 Locate name in binary program dump
24 #define POD_NAME_OFFSET 0
25 #define POD_NAME_LENGTH 16
30 #define POD_CONTROL_SIZE 0x80
31 #define POD_BUFSIZE_DUMPREQ 7
32 #define POD_STARTUP_DELAY 1000
35 Stages of POD startup procedure
38 POD_STARTUP_VERSIONREQ,
53 struct usb_line6_pod {
54 /* Generic Line 6 USB data */
55 struct usb_line6 line6;
57 /* Instrument monitor level */
60 /* Current progress in startup procedure */
63 /* Serial number of device */
66 /* Firmware version (x 100) */
73 #define line6_to_pod(x) container_of(x, struct usb_line6_pod, line6)
75 #define POD_SYSEX_CODE 3
80 POD_SYSEX_SAVE = 0x24,
81 POD_SYSEX_SYSTEM = 0x56,
82 POD_SYSEX_SYSTEMREQ = 0x57,
83 /* POD_SYSEX_UPDATE = 0x6c, */ /* software update! */
84 POD_SYSEX_STORE = 0x71,
85 POD_SYSEX_FINISH = 0x72,
86 POD_SYSEX_DUMPMEM = 0x73,
87 POD_SYSEX_DUMP = 0x74,
88 POD_SYSEX_DUMPREQ = 0x75
90 /* dumps entire internal memory of PODxt Pro */
91 /* POD_SYSEX_DUMPMEM2 = 0x76 */
95 POD_MONITOR_LEVEL = 0x04,
96 POD_SYSTEM_INVALID = 0x10000
113 static const struct snd_ratden pod_ratden = {
120 static struct line6_pcm_properties pod_pcm_properties = {
122 .info = (SNDRV_PCM_INFO_MMAP |
123 SNDRV_PCM_INFO_INTERLEAVED |
124 SNDRV_PCM_INFO_BLOCK_TRANSFER |
125 SNDRV_PCM_INFO_MMAP_VALID |
126 SNDRV_PCM_INFO_PAUSE |
127 SNDRV_PCM_INFO_SYNC_START),
128 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
129 .rates = SNDRV_PCM_RATE_KNOT,
134 .buffer_bytes_max = 60000,
135 .period_bytes_min = 64,
136 .period_bytes_max = 8192,
138 .periods_max = 1024},
140 .info = (SNDRV_PCM_INFO_MMAP |
141 SNDRV_PCM_INFO_INTERLEAVED |
142 SNDRV_PCM_INFO_BLOCK_TRANSFER |
143 SNDRV_PCM_INFO_MMAP_VALID |
144 SNDRV_PCM_INFO_SYNC_START),
145 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
146 .rates = SNDRV_PCM_RATE_KNOT,
151 .buffer_bytes_max = 60000,
152 .period_bytes_min = 64,
153 .period_bytes_max = 8192,
155 .periods_max = 1024},
158 .rats = &pod_ratden},
159 .bytes_per_channel = 3 /* SNDRV_PCM_FMTBIT_S24_3LE */
163 static const char pod_version_header[] = {
164 0xf0, 0x7e, 0x7f, 0x06, 0x02
167 static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code,
170 return line6_alloc_sysex_buffer(&pod->line6, POD_SYSEX_CODE, code,
175 Process a completely received message.
177 static void line6_pod_process_message(struct usb_line6 *line6)
179 struct usb_line6_pod *pod = line6_to_pod(line6);
180 const unsigned char *buf = pod->line6.buffer_message;
182 if (memcmp(buf, pod_version_header, sizeof(pod_version_header)) == 0) {
183 pod->firmware_version = buf[13] * 100 + buf[14] * 10 + buf[15];
184 pod->device_id = ((int)buf[8] << 16) | ((int)buf[9] << 8) |
186 if (pod->startup_progress == POD_STARTUP_VERSIONREQ) {
187 pod->startup_progress = POD_STARTUP_SETUP;
188 schedule_delayed_work(&line6->startup_work, 0);
193 /* Only look for sysex messages from this device */
194 if (buf[0] != (LINE6_SYSEX_BEGIN | LINE6_CHANNEL_DEVICE) &&
195 buf[0] != (LINE6_SYSEX_BEGIN | LINE6_CHANNEL_UNKNOWN)) {
198 if (memcmp(buf + 1, line6_midi_id, sizeof(line6_midi_id)) != 0)
201 if (buf[5] == POD_SYSEX_SYSTEM && buf[6] == POD_MONITOR_LEVEL) {
202 short value = ((int)buf[7] << 12) | ((int)buf[8] << 8) |
203 ((int)buf[9] << 4) | (int)buf[10];
204 pod->monitor_level = value;
209 Send system parameter (from integer).
211 static int pod_set_system_param_int(struct usb_line6_pod *pod, int value,
215 static const int size = 5;
217 sysex = pod_alloc_sysex_buffer(pod, POD_SYSEX_SYSTEM, size);
220 sysex[SYSEX_DATA_OFS] = code;
221 sysex[SYSEX_DATA_OFS + 1] = (value >> 12) & 0x0f;
222 sysex[SYSEX_DATA_OFS + 2] = (value >> 8) & 0x0f;
223 sysex[SYSEX_DATA_OFS + 3] = (value >> 4) & 0x0f;
224 sysex[SYSEX_DATA_OFS + 4] = (value) & 0x0f;
225 line6_send_sysex_message(&pod->line6, sysex, size);
231 "read" request on "serial_number" special file.
233 static ssize_t serial_number_show(struct device *dev,
234 struct device_attribute *attr, char *buf)
236 struct snd_card *card = dev_to_snd_card(dev);
237 struct usb_line6_pod *pod = card->private_data;
239 return sysfs_emit(buf, "%u\n", pod->serial_number);
243 "read" request on "firmware_version" special file.
245 static ssize_t firmware_version_show(struct device *dev,
246 struct device_attribute *attr, char *buf)
248 struct snd_card *card = dev_to_snd_card(dev);
249 struct usb_line6_pod *pod = card->private_data;
251 return sysfs_emit(buf, "%d.%02d\n", pod->firmware_version / 100,
252 pod->firmware_version % 100);
256 "read" request on "device_id" special file.
258 static ssize_t device_id_show(struct device *dev,
259 struct device_attribute *attr, char *buf)
261 struct snd_card *card = dev_to_snd_card(dev);
262 struct usb_line6_pod *pod = card->private_data;
264 return sysfs_emit(buf, "%d\n", pod->device_id);
268 POD startup procedure.
269 This is a sequence of functions with special requirements (e.g., must
270 not run immediately after initialization, must not run in interrupt
271 context). After the last one has finished, the device is ready to use.
274 static void pod_startup(struct usb_line6 *line6)
276 struct usb_line6_pod *pod = line6_to_pod(line6);
278 switch (pod->startup_progress) {
279 case POD_STARTUP_VERSIONREQ:
280 /* request firmware version: */
281 line6_version_request_async(line6);
283 case POD_STARTUP_SETUP:
285 line6_read_serial_number(&pod->line6, &pod->serial_number);
287 /* ALSA audio interface: */
288 if (snd_card_register(line6->card))
289 dev_err(line6->ifcdev, "Failed to register POD card.\n");
290 pod->startup_progress = POD_STARTUP_DONE;
297 /* POD special files: */
298 static DEVICE_ATTR_RO(device_id);
299 static DEVICE_ATTR_RO(firmware_version);
300 static DEVICE_ATTR_RO(serial_number);
302 static struct attribute *pod_dev_attrs[] = {
303 &dev_attr_device_id.attr,
304 &dev_attr_firmware_version.attr,
305 &dev_attr_serial_number.attr,
309 static const struct attribute_group pod_dev_attr_group = {
311 .attrs = pod_dev_attrs,
314 /* control info callback */
315 static int snd_pod_control_monitor_info(struct snd_kcontrol *kcontrol,
316 struct snd_ctl_elem_info *uinfo)
318 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
320 uinfo->value.integer.min = 0;
321 uinfo->value.integer.max = 65535;
325 /* control get callback */
326 static int snd_pod_control_monitor_get(struct snd_kcontrol *kcontrol,
327 struct snd_ctl_elem_value *ucontrol)
329 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
330 struct usb_line6_pod *pod = line6_to_pod(line6pcm->line6);
332 ucontrol->value.integer.value[0] = pod->monitor_level;
336 /* control put callback */
337 static int snd_pod_control_monitor_put(struct snd_kcontrol *kcontrol,
338 struct snd_ctl_elem_value *ucontrol)
340 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
341 struct usb_line6_pod *pod = line6_to_pod(line6pcm->line6);
343 if (ucontrol->value.integer.value[0] == pod->monitor_level)
346 pod->monitor_level = ucontrol->value.integer.value[0];
347 pod_set_system_param_int(pod, ucontrol->value.integer.value[0],
352 /* control definition */
353 static const struct snd_kcontrol_new pod_control_monitor = {
354 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
355 .name = "Monitor Playback Volume",
357 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
358 .info = snd_pod_control_monitor_info,
359 .get = snd_pod_control_monitor_get,
360 .put = snd_pod_control_monitor_put
364 Try to init POD device.
366 static int pod_init(struct usb_line6 *line6,
367 const struct usb_device_id *id)
370 struct usb_line6_pod *pod = line6_to_pod(line6);
372 line6->process_message = line6_pod_process_message;
373 line6->startup = pod_startup;
375 /* create sysfs entries: */
376 err = snd_card_add_dev_attr(line6->card, &pod_dev_attr_group);
380 /* initialize PCM subsystem: */
381 err = line6_init_pcm(line6, &pod_pcm_properties);
385 /* register monitor control: */
386 err = snd_ctl_add(line6->card,
387 snd_ctl_new1(&pod_control_monitor, line6->line6pcm));
392 When the sound card is registered at this point, the PODxt Live
393 displays "Invalid Code Error 07", so we do it later in the event
397 if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL) {
398 pod->monitor_level = POD_SYSTEM_INVALID;
400 /* initiate startup procedure: */
401 schedule_delayed_work(&line6->startup_work,
402 msecs_to_jiffies(POD_STARTUP_DELAY));
408 #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
409 #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
411 /* table of devices that work with this driver */
412 static const struct usb_device_id pod_id_table[] = {
413 { LINE6_DEVICE(0x4250), .driver_info = LINE6_BASSPODXT },
414 { LINE6_DEVICE(0x4642), .driver_info = LINE6_BASSPODXTLIVE },
415 { LINE6_DEVICE(0x4252), .driver_info = LINE6_BASSPODXTPRO },
416 { LINE6_IF_NUM(0x5051, 1), .driver_info = LINE6_POCKETPOD },
417 { LINE6_DEVICE(0x5044), .driver_info = LINE6_PODXT },
418 { LINE6_IF_NUM(0x4650, 0), .driver_info = LINE6_PODXTLIVE_POD },
419 { LINE6_DEVICE(0x5050), .driver_info = LINE6_PODXTPRO },
423 MODULE_DEVICE_TABLE(usb, pod_id_table);
425 static const struct line6_properties pod_properties_table[] = {
426 [LINE6_BASSPODXT] = {
429 .capabilities = LINE6_CAP_CONTROL
430 | LINE6_CAP_CONTROL_MIDI
439 [LINE6_BASSPODXTLIVE] = {
440 .id = "BassPODxtLive",
441 .name = "BassPODxt Live",
442 .capabilities = LINE6_CAP_CONTROL
443 | LINE6_CAP_CONTROL_MIDI
452 [LINE6_BASSPODXTPRO] = {
453 .id = "BassPODxtPro",
454 .name = "BassPODxt Pro",
455 .capabilities = LINE6_CAP_CONTROL
456 | LINE6_CAP_CONTROL_MIDI
465 [LINE6_POCKETPOD] = {
467 .name = "Pocket POD",
468 .capabilities = LINE6_CAP_CONTROL
469 | LINE6_CAP_CONTROL_MIDI,
473 /* no audio channel */
478 .capabilities = LINE6_CAP_CONTROL
479 | LINE6_CAP_CONTROL_MIDI
488 [LINE6_PODXTLIVE_POD] = {
490 .name = "PODxt Live",
491 .capabilities = LINE6_CAP_CONTROL
492 | LINE6_CAP_CONTROL_MIDI
504 .capabilities = LINE6_CAP_CONTROL
505 | LINE6_CAP_CONTROL_MIDI
519 static int pod_probe(struct usb_interface *interface,
520 const struct usb_device_id *id)
522 return line6_probe(interface, id, "Line6-POD",
523 &pod_properties_table[id->driver_info],
524 pod_init, sizeof(struct usb_line6_pod));
527 static struct usb_driver pod_driver = {
528 .name = KBUILD_MODNAME,
530 .disconnect = line6_disconnect,
532 .suspend = line6_suspend,
533 .resume = line6_resume,
534 .reset_resume = line6_resume,
536 .id_table = pod_id_table,
539 module_usb_driver(pod_driver);
541 MODULE_DESCRIPTION("Line 6 POD USB driver");
542 MODULE_LICENSE("GPL");