4 * Copyright (C) 2011 Stefan Hajnoczi <stefanha@gmail.com>
5 * Copyright (C) 2015 Andrej Krutak <dev@andree.sk>
6 * Copyright (C) 2017 Hans P. Moller <hmoller@uc.cl>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation, version 2.
14 #include <linux/usb.h>
15 #include <linux/slab.h>
16 #include <linux/module.h>
17 #include <sound/core.h>
18 #include <sound/pcm.h>
23 #define PODHD_STARTUP_DELAY 500
26 * Stages of POD startup procedure
29 PODHD_STARTUP_INIT
= 1,
30 PODHD_STARTUP_SCHEDULE_WORKQUEUE
,
32 PODHD_STARTUP_LAST
= PODHD_STARTUP_SETUP
- 1
45 struct usb_line6_podhd
{
46 /* Generic Line 6 USB data */
47 struct usb_line6 line6
;
49 /* Timer for device initialization */
50 struct timer_list startup_timer
;
52 /* Work handler for device initialization */
53 struct work_struct startup_work
;
55 /* Current progress in startup procedure */
58 /* Serial number of device */
61 /* Firmware version */
65 static struct snd_ratden podhd_ratden
= {
72 static struct line6_pcm_properties podhd_pcm_properties
= {
74 .info
= (SNDRV_PCM_INFO_MMAP
|
75 SNDRV_PCM_INFO_INTERLEAVED
|
76 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
77 SNDRV_PCM_INFO_MMAP_VALID
|
78 SNDRV_PCM_INFO_PAUSE
|
79 SNDRV_PCM_INFO_SYNC_START
),
80 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
81 .rates
= SNDRV_PCM_RATE_48000
,
86 .buffer_bytes_max
= 60000,
87 .period_bytes_min
= 64,
88 .period_bytes_max
= 8192,
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_48000
,
103 .buffer_bytes_max
= 60000,
104 .period_bytes_min
= 64,
105 .period_bytes_max
= 8192,
107 .periods_max
= 1024},
110 .rats
= &podhd_ratden
},
111 .bytes_per_channel
= 3 /* SNDRV_PCM_FMTBIT_S24_3LE */
114 static struct line6_pcm_properties podx3_pcm_properties
= {
116 .info
= (SNDRV_PCM_INFO_MMAP
|
117 SNDRV_PCM_INFO_INTERLEAVED
|
118 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
119 SNDRV_PCM_INFO_MMAP_VALID
|
120 SNDRV_PCM_INFO_PAUSE
|
121 SNDRV_PCM_INFO_SYNC_START
),
122 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
123 .rates
= SNDRV_PCM_RATE_48000
,
128 .buffer_bytes_max
= 60000,
129 .period_bytes_min
= 64,
130 .period_bytes_max
= 8192,
132 .periods_max
= 1024},
134 .info
= (SNDRV_PCM_INFO_MMAP
|
135 SNDRV_PCM_INFO_INTERLEAVED
|
136 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
137 SNDRV_PCM_INFO_MMAP_VALID
|
138 SNDRV_PCM_INFO_SYNC_START
),
139 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
140 .rates
= SNDRV_PCM_RATE_48000
,
143 /* 1+2: Main signal (out), 3+4: Tone 1,
144 * 5+6: Tone 2, 7+8: raw
148 .buffer_bytes_max
= 60000,
149 .period_bytes_min
= 64,
150 .period_bytes_max
= 8192,
152 .periods_max
= 1024},
155 .rats
= &podhd_ratden
},
156 .bytes_per_channel
= 3 /* SNDRV_PCM_FMTBIT_S24_3LE */
158 static struct usb_driver podhd_driver
;
160 static void podhd_startup_start_workqueue(unsigned long data
);
161 static void podhd_startup_workqueue(struct work_struct
*work
);
162 static int podhd_startup_finalize(struct usb_line6_podhd
*pod
);
164 static ssize_t
serial_number_show(struct device
*dev
,
165 struct device_attribute
*attr
, char *buf
)
167 struct snd_card
*card
= dev_to_snd_card(dev
);
168 struct usb_line6_podhd
*pod
= card
->private_data
;
170 return sprintf(buf
, "%u\n", pod
->serial_number
);
173 static ssize_t
firmware_version_show(struct device
*dev
,
174 struct device_attribute
*attr
, char *buf
)
176 struct snd_card
*card
= dev_to_snd_card(dev
);
177 struct usb_line6_podhd
*pod
= card
->private_data
;
179 return sprintf(buf
, "%06x\n", pod
->firmware_version
);
182 static DEVICE_ATTR_RO(firmware_version
);
183 static DEVICE_ATTR_RO(serial_number
);
185 static struct attribute
*podhd_dev_attrs
[] = {
186 &dev_attr_firmware_version
.attr
,
187 &dev_attr_serial_number
.attr
,
191 static const struct attribute_group podhd_dev_attr_group
= {
193 .attrs
= podhd_dev_attrs
,
197 * POD X3 startup procedure.
199 * May be compatible with other POD HD's, since it's also similar to the
200 * previous POD setup. In any case, it doesn't seem to be required for the
201 * audio nor bulk interfaces to work.
204 static void podhd_startup(struct usb_line6_podhd
*pod
)
206 CHECK_STARTUP_PROGRESS(pod
->startup_progress
, PODHD_STARTUP_INIT
);
208 /* delay startup procedure: */
209 line6_start_timer(&pod
->startup_timer
, PODHD_STARTUP_DELAY
,
210 podhd_startup_start_workqueue
, (unsigned long)pod
);
213 static void podhd_startup_start_workqueue(unsigned long data
)
215 struct usb_line6_podhd
*pod
= (struct usb_line6_podhd
*)data
;
217 CHECK_STARTUP_PROGRESS(pod
->startup_progress
,
218 PODHD_STARTUP_SCHEDULE_WORKQUEUE
);
220 /* schedule work for global work queue: */
221 schedule_work(&pod
->startup_work
);
224 static int podhd_dev_start(struct usb_line6_podhd
*pod
)
229 struct usb_device
*usbdev
= pod
->line6
.usbdev
;
231 init_bytes
= kmalloc(8, GFP_KERNEL
);
235 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0),
236 0x67, USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
238 NULL
, 0, LINE6_TIMEOUT
* HZ
);
240 dev_err(pod
->line6
.ifcdev
, "read request failed (error %d)\n", ret
);
244 /* NOTE: looks like some kind of ping message */
245 ret
= usb_control_msg(usbdev
, usb_rcvctrlpipe(usbdev
, 0), 0x67,
246 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
248 init_bytes
, 3, LINE6_TIMEOUT
* HZ
);
250 dev_err(pod
->line6
.ifcdev
,
251 "receive length failed (error %d)\n", ret
);
255 pod
->firmware_version
=
256 (init_bytes
[0] << 16) | (init_bytes
[1] << 8) | (init_bytes
[2] << 0);
258 for (i
= 0; i
<= 16; i
++) {
259 ret
= line6_read_data(&pod
->line6
, 0xf000 + 0x08 * i
, init_bytes
, 8);
264 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0),
266 USB_TYPE_STANDARD
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
268 NULL
, 0, LINE6_TIMEOUT
* HZ
);
274 static void podhd_startup_workqueue(struct work_struct
*work
)
276 struct usb_line6_podhd
*pod
=
277 container_of(work
, struct usb_line6_podhd
, startup_work
);
279 CHECK_STARTUP_PROGRESS(pod
->startup_progress
, PODHD_STARTUP_SETUP
);
281 podhd_dev_start(pod
);
282 line6_read_serial_number(&pod
->line6
, &pod
->serial_number
);
284 podhd_startup_finalize(pod
);
287 static int podhd_startup_finalize(struct usb_line6_podhd
*pod
)
289 struct usb_line6
*line6
= &pod
->line6
;
291 /* ALSA audio interface: */
292 return snd_card_register(line6
->card
);
295 static void podhd_disconnect(struct usb_line6
*line6
)
297 struct usb_line6_podhd
*pod
= (struct usb_line6_podhd
*)line6
;
299 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL_INFO
) {
300 struct usb_interface
*intf
;
302 del_timer_sync(&pod
->startup_timer
);
303 cancel_work_sync(&pod
->startup_work
);
305 intf
= usb_ifnum_to_if(line6
->usbdev
,
306 pod
->line6
.properties
->ctrl_if
);
308 usb_driver_release_interface(&podhd_driver
, intf
);
313 Try to init POD HD device.
315 static int podhd_init(struct usb_line6
*line6
,
316 const struct usb_device_id
*id
)
319 struct usb_line6_podhd
*pod
= (struct usb_line6_podhd
*) line6
;
320 struct usb_interface
*intf
;
322 line6
->disconnect
= podhd_disconnect
;
324 init_timer(&pod
->startup_timer
);
325 INIT_WORK(&pod
->startup_work
, podhd_startup_workqueue
);
327 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL
) {
328 /* claim the data interface */
329 intf
= usb_ifnum_to_if(line6
->usbdev
,
330 pod
->line6
.properties
->ctrl_if
);
332 dev_err(pod
->line6
.ifcdev
, "interface %d not found\n",
333 pod
->line6
.properties
->ctrl_if
);
337 err
= usb_driver_claim_interface(&podhd_driver
, intf
, NULL
);
339 dev_err(pod
->line6
.ifcdev
, "can't claim interface %d, error %d\n",
340 pod
->line6
.properties
->ctrl_if
, err
);
345 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL_INFO
) {
346 /* create sysfs entries: */
347 err
= snd_card_add_dev_attr(line6
->card
, &podhd_dev_attr_group
);
352 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_PCM
) {
353 /* initialize PCM subsystem: */
354 err
= line6_init_pcm(line6
,
355 (id
->driver_info
== LINE6_PODX3
||
356 id
->driver_info
== LINE6_PODX3LIVE
) ? &podx3_pcm_properties
:
357 &podhd_pcm_properties
);
362 if (!(pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL_INFO
)) {
363 /* register USB audio system directly */
364 return podhd_startup_finalize(pod
);
367 /* init device and delay registering */
372 #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
373 #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
375 /* table of devices that work with this driver */
376 static const struct usb_device_id podhd_id_table
[] = {
377 /* TODO: no need to alloc data interfaces when only audio is used */
378 { LINE6_DEVICE(0x5057), .driver_info
= LINE6_PODHD300
},
379 { LINE6_DEVICE(0x5058), .driver_info
= LINE6_PODHD400
},
380 { LINE6_IF_NUM(0x414D, 0), .driver_info
= LINE6_PODHD500_0
},
381 { LINE6_IF_NUM(0x414D, 1), .driver_info
= LINE6_PODHD500_1
},
382 { LINE6_IF_NUM(0x414A, 0), .driver_info
= LINE6_PODX3
},
383 { LINE6_IF_NUM(0x414B, 0), .driver_info
= LINE6_PODX3LIVE
},
384 { LINE6_IF_NUM(0x4159, 0), .driver_info
= LINE6_PODHD500X
},
388 MODULE_DEVICE_TABLE(usb
, podhd_id_table
);
390 static const struct line6_properties podhd_properties_table
[] = {
394 .capabilities
= LINE6_CAP_PCM
405 .capabilities
= LINE6_CAP_PCM
413 [LINE6_PODHD500_0
] = {
416 .capabilities
= LINE6_CAP_PCM
424 [LINE6_PODHD500_1
] = {
427 .capabilities
= LINE6_CAP_PCM
438 .capabilities
= LINE6_CAP_CONTROL
| LINE6_CAP_CONTROL_INFO
439 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
| LINE6_CAP_IN_NEEDS_OUT
,
447 [LINE6_PODX3LIVE
] = {
449 .name
= "POD X3 LIVE",
450 .capabilities
= LINE6_CAP_CONTROL
| LINE6_CAP_CONTROL_INFO
451 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
| LINE6_CAP_IN_NEEDS_OUT
,
459 [LINE6_PODHD500X
] = {
461 .name
= "POD HD500X",
462 .capabilities
= LINE6_CAP_CONTROL
463 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
,
476 static int podhd_probe(struct usb_interface
*interface
,
477 const struct usb_device_id
*id
)
479 return line6_probe(interface
, id
, "Line6-PODHD",
480 &podhd_properties_table
[id
->driver_info
],
481 podhd_init
, sizeof(struct usb_line6_podhd
));
484 static struct usb_driver podhd_driver
= {
485 .name
= KBUILD_MODNAME
,
486 .probe
= podhd_probe
,
487 .disconnect
= line6_disconnect
,
489 .suspend
= line6_suspend
,
490 .resume
= line6_resume
,
491 .reset_resume
= line6_resume
,
493 .id_table
= podhd_id_table
,
496 module_usb_driver(podhd_driver
);
498 MODULE_DESCRIPTION("Line 6 PODHD USB driver");
499 MODULE_LICENSE("GPL");