4 * Copyright (C) 2011 Stefan Hajnoczi <stefanha@gmail.com>
5 * Copyright (C) 2015 Andrej Krutak <dev@andree.sk>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, version 2.
13 #include <linux/usb.h>
14 #include <linux/slab.h>
15 #include <linux/module.h>
16 #include <sound/core.h>
17 #include <sound/pcm.h>
22 #define PODHD_STARTUP_DELAY 500
25 * Stages of POD startup procedure
28 PODHD_STARTUP_INIT = 1,
29 PODHD_STARTUP_SCHEDULE_WORKQUEUE,
31 PODHD_STARTUP_LAST = PODHD_STARTUP_SETUP - 1
43 struct usb_line6_podhd {
44 /* Generic Line 6 USB data */
45 struct usb_line6 line6;
47 /* Timer for device initialization */
48 struct timer_list startup_timer;
50 /* Work handler for device initialization */
51 struct work_struct startup_work;
53 /* Current progress in startup procedure */
56 /* Serial number of device */
59 /* Firmware version */
63 static struct snd_ratden podhd_ratden = {
70 static struct line6_pcm_properties podhd_pcm_properties = {
72 .info = (SNDRV_PCM_INFO_MMAP |
73 SNDRV_PCM_INFO_INTERLEAVED |
74 SNDRV_PCM_INFO_BLOCK_TRANSFER |
75 SNDRV_PCM_INFO_MMAP_VALID |
76 SNDRV_PCM_INFO_PAUSE |
77 SNDRV_PCM_INFO_SYNC_START),
78 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
79 .rates = SNDRV_PCM_RATE_48000,
84 .buffer_bytes_max = 60000,
85 .period_bytes_min = 64,
86 .period_bytes_max = 8192,
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_48000,
101 .buffer_bytes_max = 60000,
102 .period_bytes_min = 64,
103 .period_bytes_max = 8192,
105 .periods_max = 1024},
108 .rats = &podhd_ratden},
109 .bytes_per_channel = 3 /* SNDRV_PCM_FMTBIT_S24_3LE */
112 static struct line6_pcm_properties podx3_pcm_properties = {
114 .info = (SNDRV_PCM_INFO_MMAP |
115 SNDRV_PCM_INFO_INTERLEAVED |
116 SNDRV_PCM_INFO_BLOCK_TRANSFER |
117 SNDRV_PCM_INFO_MMAP_VALID |
118 SNDRV_PCM_INFO_PAUSE |
119 SNDRV_PCM_INFO_SYNC_START),
120 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
121 .rates = SNDRV_PCM_RATE_48000,
126 .buffer_bytes_max = 60000,
127 .period_bytes_min = 64,
128 .period_bytes_max = 8192,
130 .periods_max = 1024},
132 .info = (SNDRV_PCM_INFO_MMAP |
133 SNDRV_PCM_INFO_INTERLEAVED |
134 SNDRV_PCM_INFO_BLOCK_TRANSFER |
135 SNDRV_PCM_INFO_MMAP_VALID |
136 SNDRV_PCM_INFO_SYNC_START),
137 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
138 .rates = SNDRV_PCM_RATE_48000,
141 /* 1+2: Main signal (out), 3+4: Tone 1,
142 * 5+6: Tone 2, 7+8: raw
146 .buffer_bytes_max = 60000,
147 .period_bytes_min = 64,
148 .period_bytes_max = 8192,
150 .periods_max = 1024},
153 .rats = &podhd_ratden},
154 .bytes_per_channel = 3 /* SNDRV_PCM_FMTBIT_S24_3LE */
157 static void podhd_startup_start_workqueue(unsigned long data);
158 static void podhd_startup_workqueue(struct work_struct *work);
159 static int podhd_startup_finalize(struct usb_line6_podhd *pod);
161 static ssize_t serial_number_show(struct device *dev,
162 struct device_attribute *attr, char *buf)
164 struct snd_card *card = dev_to_snd_card(dev);
165 struct usb_line6_podhd *pod = card->private_data;
167 return sprintf(buf, "%u\n", pod->serial_number);
170 static ssize_t firmware_version_show(struct device *dev,
171 struct device_attribute *attr, char *buf)
173 struct snd_card *card = dev_to_snd_card(dev);
174 struct usb_line6_podhd *pod = card->private_data;
176 return sprintf(buf, "%06x\n", pod->firmware_version);
179 static DEVICE_ATTR_RO(firmware_version);
180 static DEVICE_ATTR_RO(serial_number);
182 static struct attribute *podhd_dev_attrs[] = {
183 &dev_attr_firmware_version.attr,
184 &dev_attr_serial_number.attr,
188 static const struct attribute_group podhd_dev_attr_group = {
190 .attrs = podhd_dev_attrs,
194 * POD X3 startup procedure.
196 * May be compatible with other POD HD's, since it's also similar to the
197 * previous POD setup. In any case, it doesn't seem to be required for the
198 * audio nor bulk interfaces to work.
201 static void podhd_startup(struct usb_line6_podhd *pod)
203 CHECK_STARTUP_PROGRESS(pod->startup_progress, PODHD_STARTUP_INIT);
205 /* delay startup procedure: */
206 line6_start_timer(&pod->startup_timer, PODHD_STARTUP_DELAY,
207 podhd_startup_start_workqueue, (unsigned long)pod);
210 static void podhd_startup_start_workqueue(unsigned long data)
212 struct usb_line6_podhd *pod = (struct usb_line6_podhd *)data;
214 CHECK_STARTUP_PROGRESS(pod->startup_progress,
215 PODHD_STARTUP_SCHEDULE_WORKQUEUE);
217 /* schedule work for global work queue: */
218 schedule_work(&pod->startup_work);
221 static int podhd_dev_start(struct usb_line6_podhd *pod)
226 struct usb_device *usbdev = pod->line6.usbdev;
228 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0),
229 0x67, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
231 NULL, 0, LINE6_TIMEOUT * HZ);
233 dev_err(pod->line6.ifcdev, "read request failed (error %d)\n", ret);
237 /* NOTE: looks like some kind of ping message */
238 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
239 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
241 &init_bytes, 3, LINE6_TIMEOUT * HZ);
243 dev_err(pod->line6.ifcdev,
244 "receive length failed (error %d)\n", ret);
248 pod->firmware_version =
249 (init_bytes[0] << 16) | (init_bytes[1] << 8) | (init_bytes[2] << 0);
251 for (i = 0; i <= 16; i++) {
252 ret = line6_read_data(&pod->line6, 0xf000 + 0x08 * i, init_bytes, 8);
257 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0),
259 USB_TYPE_STANDARD | USB_RECIP_DEVICE | USB_DIR_OUT,
261 NULL, 0, LINE6_TIMEOUT * HZ);
268 static void podhd_startup_workqueue(struct work_struct *work)
270 struct usb_line6_podhd *pod =
271 container_of(work, struct usb_line6_podhd, startup_work);
273 CHECK_STARTUP_PROGRESS(pod->startup_progress, PODHD_STARTUP_SETUP);
275 podhd_dev_start(pod);
276 line6_read_serial_number(&pod->line6, &pod->serial_number);
278 podhd_startup_finalize(pod);
281 static int podhd_startup_finalize(struct usb_line6_podhd *pod)
283 struct usb_line6 *line6 = &pod->line6;
285 /* ALSA audio interface: */
286 return snd_card_register(line6->card);
289 static void podhd_disconnect(struct usb_line6 *line6)
291 struct usb_line6_podhd *pod = (struct usb_line6_podhd *)line6;
293 if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL) {
294 del_timer_sync(&pod->startup_timer);
295 cancel_work_sync(&pod->startup_work);
300 Try to init POD HD device.
302 static int podhd_init(struct usb_line6 *line6,
303 const struct usb_device_id *id)
306 struct usb_line6_podhd *pod = (struct usb_line6_podhd *) line6;
308 line6->disconnect = podhd_disconnect;
310 if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL) {
311 /* create sysfs entries: */
312 err = snd_card_add_dev_attr(line6->card, &podhd_dev_attr_group);
317 if (pod->line6.properties->capabilities & LINE6_CAP_PCM) {
318 /* initialize PCM subsystem: */
319 err = line6_init_pcm(line6,
320 (id->driver_info == LINE6_PODX3) ? &podx3_pcm_properties :
321 &podhd_pcm_properties);
326 if (!(pod->line6.properties->capabilities & LINE6_CAP_CONTROL)) {
327 /* register USB audio system directly */
328 return podhd_startup_finalize(pod);
331 /* init device and delay registering */
332 init_timer(&pod->startup_timer);
333 INIT_WORK(&pod->startup_work, podhd_startup_workqueue);
338 #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
339 #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
341 /* table of devices that work with this driver */
342 static const struct usb_device_id podhd_id_table[] = {
343 /* TODO: no need to alloc data interfaces when only audio is used */
344 { LINE6_DEVICE(0x5057), .driver_info = LINE6_PODHD300 },
345 { LINE6_DEVICE(0x5058), .driver_info = LINE6_PODHD400 },
346 { LINE6_IF_NUM(0x414D, 0), .driver_info = LINE6_PODHD500_0 },
347 { LINE6_IF_NUM(0x414D, 1), .driver_info = LINE6_PODHD500_1 },
348 { LINE6_IF_NUM(0x414A, 0), .driver_info = LINE6_PODX3 },
349 { LINE6_IF_NUM(0x414B, 0), .driver_info = LINE6_PODX3LIVE },
353 MODULE_DEVICE_TABLE(usb, podhd_id_table);
355 static const struct line6_properties podhd_properties_table[] = {
359 .capabilities = LINE6_CAP_PCM
370 .capabilities = LINE6_CAP_PCM
378 [LINE6_PODHD500_0] = {
381 .capabilities = LINE6_CAP_PCM
389 [LINE6_PODHD500_1] = {
392 .capabilities = LINE6_CAP_PCM
403 .capabilities = LINE6_CAP_CONTROL
404 | LINE6_CAP_PCM | LINE6_CAP_HWMON | LINE6_CAP_IN_NEEDS_OUT,
411 [LINE6_PODX3LIVE] = {
413 .name = "POD X3 LIVE",
414 .capabilities = LINE6_CAP_CONTROL
415 | LINE6_CAP_PCM | LINE6_CAP_HWMON | LINE6_CAP_IN_NEEDS_OUT,
427 static int podhd_probe(struct usb_interface *interface,
428 const struct usb_device_id *id)
430 return line6_probe(interface, id, "Line6-PODHD",
431 &podhd_properties_table[id->driver_info],
432 podhd_init, sizeof(struct usb_line6_podhd));
435 static struct usb_driver podhd_driver = {
436 .name = KBUILD_MODNAME,
437 .probe = podhd_probe,
438 .disconnect = line6_disconnect,
440 .suspend = line6_suspend,
441 .resume = line6_resume,
442 .reset_resume = line6_resume,
444 .id_table = podhd_id_table,
447 module_usb_driver(podhd_driver);
449 MODULE_DESCRIPTION("Line 6 PODHD USB driver");
450 MODULE_LICENSE("GPL");