1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2011 Stefan Hajnoczi <stefanha@gmail.com>
6 * Copyright (C) 2015 Andrej Krutak <dev@andree.sk>
7 * Copyright (C) 2017 Hans P. Moller <hmoller@uc.cl>
10 #include <linux/usb.h>
11 #include <linux/slab.h>
12 #include <linux/module.h>
13 #include <sound/core.h>
14 #include <sound/pcm.h>
19 #define PODHD_STARTUP_DELAY 500
31 struct usb_line6_podhd
{
32 /* Generic Line 6 USB data */
33 struct usb_line6 line6
;
35 /* Serial number of device */
38 /* Firmware version */
42 #define line6_to_podhd(x) container_of(x, struct usb_line6_podhd, line6)
44 static const struct snd_ratden podhd_ratden
= {
51 static struct line6_pcm_properties podhd_pcm_properties
= {
53 .info
= (SNDRV_PCM_INFO_MMAP
|
54 SNDRV_PCM_INFO_INTERLEAVED
|
55 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
56 SNDRV_PCM_INFO_MMAP_VALID
|
57 SNDRV_PCM_INFO_PAUSE
|
58 SNDRV_PCM_INFO_SYNC_START
),
59 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
60 .rates
= SNDRV_PCM_RATE_48000
,
65 .buffer_bytes_max
= 60000,
66 .period_bytes_min
= 64,
67 .period_bytes_max
= 8192,
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_SYNC_START
),
76 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
77 .rates
= SNDRV_PCM_RATE_48000
,
82 .buffer_bytes_max
= 60000,
83 .period_bytes_min
= 64,
84 .period_bytes_max
= 8192,
89 .rats
= &podhd_ratden
},
90 .bytes_per_channel
= 3 /* SNDRV_PCM_FMTBIT_S24_3LE */
93 static struct line6_pcm_properties podx3_pcm_properties
= {
95 .info
= (SNDRV_PCM_INFO_MMAP
|
96 SNDRV_PCM_INFO_INTERLEAVED
|
97 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
98 SNDRV_PCM_INFO_MMAP_VALID
|
99 SNDRV_PCM_INFO_PAUSE
|
100 SNDRV_PCM_INFO_SYNC_START
),
101 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
102 .rates
= SNDRV_PCM_RATE_48000
,
107 .buffer_bytes_max
= 60000,
108 .period_bytes_min
= 64,
109 .period_bytes_max
= 8192,
111 .periods_max
= 1024},
113 .info
= (SNDRV_PCM_INFO_MMAP
|
114 SNDRV_PCM_INFO_INTERLEAVED
|
115 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
116 SNDRV_PCM_INFO_MMAP_VALID
|
117 SNDRV_PCM_INFO_SYNC_START
),
118 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
119 .rates
= SNDRV_PCM_RATE_48000
,
122 /* 1+2: Main signal (out), 3+4: Tone 1,
123 * 5+6: Tone 2, 7+8: raw
127 .buffer_bytes_max
= 60000,
128 .period_bytes_min
= 64,
129 .period_bytes_max
= 8192,
131 .periods_max
= 1024},
134 .rats
= &podhd_ratden
},
135 .bytes_per_channel
= 3 /* SNDRV_PCM_FMTBIT_S24_3LE */
137 static struct usb_driver podhd_driver
;
139 static ssize_t
serial_number_show(struct device
*dev
,
140 struct device_attribute
*attr
, char *buf
)
142 struct snd_card
*card
= dev_to_snd_card(dev
);
143 struct usb_line6_podhd
*pod
= card
->private_data
;
145 return sprintf(buf
, "%u\n", pod
->serial_number
);
148 static ssize_t
firmware_version_show(struct device
*dev
,
149 struct device_attribute
*attr
, char *buf
)
151 struct snd_card
*card
= dev_to_snd_card(dev
);
152 struct usb_line6_podhd
*pod
= card
->private_data
;
154 return sprintf(buf
, "%06x\n", pod
->firmware_version
);
157 static DEVICE_ATTR_RO(firmware_version
);
158 static DEVICE_ATTR_RO(serial_number
);
160 static struct attribute
*podhd_dev_attrs
[] = {
161 &dev_attr_firmware_version
.attr
,
162 &dev_attr_serial_number
.attr
,
166 static const struct attribute_group podhd_dev_attr_group
= {
168 .attrs
= podhd_dev_attrs
,
172 * POD X3 startup procedure.
174 * May be compatible with other POD HD's, since it's also similar to the
175 * previous POD setup. In any case, it doesn't seem to be required for the
176 * audio nor bulk interfaces to work.
179 static int podhd_dev_start(struct usb_line6_podhd
*pod
)
184 struct usb_device
*usbdev
= pod
->line6
.usbdev
;
186 init_bytes
= kmalloc(8, GFP_KERNEL
);
190 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0),
191 0x67, USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
193 NULL
, 0, LINE6_TIMEOUT
* HZ
);
195 dev_err(pod
->line6
.ifcdev
, "read request failed (error %d)\n", ret
);
199 /* NOTE: looks like some kind of ping message */
200 ret
= usb_control_msg(usbdev
, usb_rcvctrlpipe(usbdev
, 0), 0x67,
201 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
203 init_bytes
, 3, LINE6_TIMEOUT
* HZ
);
205 dev_err(pod
->line6
.ifcdev
,
206 "receive length failed (error %d)\n", ret
);
210 pod
->firmware_version
=
211 (init_bytes
[0] << 16) | (init_bytes
[1] << 8) | (init_bytes
[2] << 0);
213 for (i
= 0; i
<= 16; i
++) {
214 ret
= line6_read_data(&pod
->line6
, 0xf000 + 0x08 * i
, init_bytes
, 8);
219 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0),
221 USB_TYPE_STANDARD
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
223 NULL
, 0, LINE6_TIMEOUT
* HZ
);
229 static void podhd_startup(struct usb_line6
*line6
)
231 struct usb_line6_podhd
*pod
= line6_to_podhd(line6
);
233 podhd_dev_start(pod
);
234 line6_read_serial_number(&pod
->line6
, &pod
->serial_number
);
235 if (snd_card_register(line6
->card
))
236 dev_err(line6
->ifcdev
, "Failed to register POD HD card.\n");
239 static void podhd_disconnect(struct usb_line6
*line6
)
241 struct usb_line6_podhd
*pod
= line6_to_podhd(line6
);
243 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL_INFO
) {
244 struct usb_interface
*intf
;
246 intf
= usb_ifnum_to_if(line6
->usbdev
,
247 pod
->line6
.properties
->ctrl_if
);
249 usb_driver_release_interface(&podhd_driver
, intf
);
254 Try to init POD HD device.
256 static int podhd_init(struct usb_line6
*line6
,
257 const struct usb_device_id
*id
)
260 struct usb_line6_podhd
*pod
= line6_to_podhd(line6
);
261 struct usb_interface
*intf
;
263 line6
->disconnect
= podhd_disconnect
;
264 line6
->startup
= podhd_startup
;
266 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL
) {
267 /* claim the data interface */
268 intf
= usb_ifnum_to_if(line6
->usbdev
,
269 pod
->line6
.properties
->ctrl_if
);
271 dev_err(pod
->line6
.ifcdev
, "interface %d not found\n",
272 pod
->line6
.properties
->ctrl_if
);
276 err
= usb_driver_claim_interface(&podhd_driver
, intf
, NULL
);
278 dev_err(pod
->line6
.ifcdev
, "can't claim interface %d, error %d\n",
279 pod
->line6
.properties
->ctrl_if
, err
);
284 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL_INFO
) {
285 /* create sysfs entries: */
286 err
= snd_card_add_dev_attr(line6
->card
, &podhd_dev_attr_group
);
291 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_PCM
) {
292 /* initialize PCM subsystem: */
293 err
= line6_init_pcm(line6
,
294 (id
->driver_info
== LINE6_PODX3
||
295 id
->driver_info
== LINE6_PODX3LIVE
) ? &podx3_pcm_properties
:
296 &podhd_pcm_properties
);
301 if (!(pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL_INFO
)) {
302 /* register USB audio system directly */
303 return snd_card_register(line6
->card
);
306 /* init device and delay registering */
307 schedule_delayed_work(&line6
->startup_work
,
308 msecs_to_jiffies(PODHD_STARTUP_DELAY
));
312 #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
313 #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
315 /* table of devices that work with this driver */
316 static const struct usb_device_id podhd_id_table
[] = {
317 /* TODO: no need to alloc data interfaces when only audio is used */
318 { LINE6_DEVICE(0x5057), .driver_info
= LINE6_PODHD300
},
319 { LINE6_DEVICE(0x5058), .driver_info
= LINE6_PODHD400
},
320 { LINE6_IF_NUM(0x414D, 0), .driver_info
= LINE6_PODHD500
},
321 { LINE6_IF_NUM(0x414A, 0), .driver_info
= LINE6_PODX3
},
322 { LINE6_IF_NUM(0x414B, 0), .driver_info
= LINE6_PODX3LIVE
},
323 { LINE6_IF_NUM(0x4159, 0), .driver_info
= LINE6_PODHD500X
},
324 { LINE6_IF_NUM(0x4156, 0), .driver_info
= LINE6_PODHDDESKTOP
},
328 MODULE_DEVICE_TABLE(usb
, podhd_id_table
);
330 static const struct line6_properties podhd_properties_table
[] = {
334 .capabilities
= LINE6_CAP_PCM
345 .capabilities
= LINE6_CAP_PCM
356 .capabilities
= LINE6_CAP_PCM
| LINE6_CAP_CONTROL
368 .capabilities
= LINE6_CAP_CONTROL
| LINE6_CAP_CONTROL_INFO
369 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
| LINE6_CAP_IN_NEEDS_OUT
,
377 [LINE6_PODX3LIVE
] = {
379 .name
= "POD X3 LIVE",
380 .capabilities
= LINE6_CAP_CONTROL
| LINE6_CAP_CONTROL_INFO
381 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
| LINE6_CAP_IN_NEEDS_OUT
,
389 [LINE6_PODHD500X
] = {
391 .name
= "POD HD500X",
392 .capabilities
= LINE6_CAP_CONTROL
393 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
,
401 [LINE6_PODHDDESKTOP
] = {
402 .id
= "PODHDDESKTOP",
403 .name
= "POD HDDESKTOP",
404 .capabilities
= LINE6_CAP_CONTROL
405 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
,
418 static int podhd_probe(struct usb_interface
*interface
,
419 const struct usb_device_id
*id
)
421 return line6_probe(interface
, id
, "Line6-PODHD",
422 &podhd_properties_table
[id
->driver_info
],
423 podhd_init
, sizeof(struct usb_line6_podhd
));
426 static struct usb_driver podhd_driver
= {
427 .name
= KBUILD_MODNAME
,
428 .probe
= podhd_probe
,
429 .disconnect
= line6_disconnect
,
431 .suspend
= line6_suspend
,
432 .resume
= line6_resume
,
433 .reset_resume
= line6_resume
,
435 .id_table
= podhd_id_table
,
438 module_usb_driver(podhd_driver
);
440 MODULE_DESCRIPTION("Line 6 PODHD USB driver");
441 MODULE_LICENSE("GPL");