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
32 struct usb_line6_podhd
{
33 /* Generic Line 6 USB data */
34 struct usb_line6 line6
;
36 /* Serial number of device */
39 /* Firmware version */
43 #define line6_to_podhd(x) container_of(x, struct usb_line6_podhd, line6)
45 static const struct snd_ratden podhd_ratden
= {
52 static struct line6_pcm_properties podhd_pcm_properties
= {
54 .info
= (SNDRV_PCM_INFO_MMAP
|
55 SNDRV_PCM_INFO_INTERLEAVED
|
56 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
57 SNDRV_PCM_INFO_MMAP_VALID
|
58 SNDRV_PCM_INFO_PAUSE
|
59 SNDRV_PCM_INFO_SYNC_START
),
60 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
61 .rates
= SNDRV_PCM_RATE_48000
,
66 .buffer_bytes_max
= 60000,
67 .period_bytes_min
= 64,
68 .period_bytes_max
= 8192,
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_SYNC_START
),
77 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
78 .rates
= SNDRV_PCM_RATE_48000
,
83 .buffer_bytes_max
= 60000,
84 .period_bytes_min
= 64,
85 .period_bytes_max
= 8192,
90 .rats
= &podhd_ratden
},
91 .bytes_per_channel
= 3 /* SNDRV_PCM_FMTBIT_S24_3LE */
94 static struct line6_pcm_properties podx3_pcm_properties
= {
96 .info
= (SNDRV_PCM_INFO_MMAP
|
97 SNDRV_PCM_INFO_INTERLEAVED
|
98 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
99 SNDRV_PCM_INFO_MMAP_VALID
|
100 SNDRV_PCM_INFO_PAUSE
|
101 SNDRV_PCM_INFO_SYNC_START
),
102 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
103 .rates
= SNDRV_PCM_RATE_48000
,
108 .buffer_bytes_max
= 60000,
109 .period_bytes_min
= 64,
110 .period_bytes_max
= 8192,
112 .periods_max
= 1024},
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_SYNC_START
),
119 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
120 .rates
= SNDRV_PCM_RATE_48000
,
123 /* 1+2: Main signal (out), 3+4: Tone 1,
124 * 5+6: Tone 2, 7+8: raw
128 .buffer_bytes_max
= 60000,
129 .period_bytes_min
= 64,
130 .period_bytes_max
= 8192,
132 .periods_max
= 1024},
135 .rats
= &podhd_ratden
},
136 .bytes_per_channel
= 3 /* SNDRV_PCM_FMTBIT_S24_3LE */
138 static struct usb_driver podhd_driver
;
140 static ssize_t
serial_number_show(struct device
*dev
,
141 struct device_attribute
*attr
, char *buf
)
143 struct snd_card
*card
= dev_to_snd_card(dev
);
144 struct usb_line6_podhd
*pod
= card
->private_data
;
146 return sprintf(buf
, "%u\n", pod
->serial_number
);
149 static ssize_t
firmware_version_show(struct device
*dev
,
150 struct device_attribute
*attr
, char *buf
)
152 struct snd_card
*card
= dev_to_snd_card(dev
);
153 struct usb_line6_podhd
*pod
= card
->private_data
;
155 return sprintf(buf
, "%06x\n", pod
->firmware_version
);
158 static DEVICE_ATTR_RO(firmware_version
);
159 static DEVICE_ATTR_RO(serial_number
);
161 static struct attribute
*podhd_dev_attrs
[] = {
162 &dev_attr_firmware_version
.attr
,
163 &dev_attr_serial_number
.attr
,
167 static const struct attribute_group podhd_dev_attr_group
= {
169 .attrs
= podhd_dev_attrs
,
173 * POD X3 startup procedure.
175 * May be compatible with other POD HD's, since it's also similar to the
176 * previous POD setup. In any case, it doesn't seem to be required for the
177 * audio nor bulk interfaces to work.
180 static int podhd_dev_start(struct usb_line6_podhd
*pod
)
185 struct usb_device
*usbdev
= pod
->line6
.usbdev
;
187 init_bytes
= kmalloc(8, GFP_KERNEL
);
191 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0),
192 0x67, USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
194 NULL
, 0, LINE6_TIMEOUT
* HZ
);
196 dev_err(pod
->line6
.ifcdev
, "read request failed (error %d)\n", ret
);
200 /* NOTE: looks like some kind of ping message */
201 ret
= usb_control_msg(usbdev
, usb_rcvctrlpipe(usbdev
, 0), 0x67,
202 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
204 init_bytes
, 3, LINE6_TIMEOUT
* HZ
);
206 dev_err(pod
->line6
.ifcdev
,
207 "receive length failed (error %d)\n", ret
);
211 pod
->firmware_version
=
212 (init_bytes
[0] << 16) | (init_bytes
[1] << 8) | (init_bytes
[2] << 0);
214 for (i
= 0; i
<= 16; i
++) {
215 ret
= line6_read_data(&pod
->line6
, 0xf000 + 0x08 * i
, init_bytes
, 8);
220 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0),
222 USB_TYPE_STANDARD
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
224 NULL
, 0, LINE6_TIMEOUT
* HZ
);
230 static void podhd_startup(struct usb_line6
*line6
)
232 struct usb_line6_podhd
*pod
= line6_to_podhd(line6
);
234 podhd_dev_start(pod
);
235 line6_read_serial_number(&pod
->line6
, &pod
->serial_number
);
236 if (snd_card_register(line6
->card
))
237 dev_err(line6
->ifcdev
, "Failed to register POD HD card.\n");
240 static void podhd_disconnect(struct usb_line6
*line6
)
242 struct usb_line6_podhd
*pod
= line6_to_podhd(line6
);
244 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL_INFO
) {
245 struct usb_interface
*intf
;
247 intf
= usb_ifnum_to_if(line6
->usbdev
,
248 pod
->line6
.properties
->ctrl_if
);
250 usb_driver_release_interface(&podhd_driver
, intf
);
255 Try to init POD HD device.
257 static int podhd_init(struct usb_line6
*line6
,
258 const struct usb_device_id
*id
)
261 struct usb_line6_podhd
*pod
= line6_to_podhd(line6
);
262 struct usb_interface
*intf
;
264 line6
->disconnect
= podhd_disconnect
;
265 line6
->startup
= podhd_startup
;
267 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL
) {
268 /* claim the data interface */
269 intf
= usb_ifnum_to_if(line6
->usbdev
,
270 pod
->line6
.properties
->ctrl_if
);
272 dev_err(pod
->line6
.ifcdev
, "interface %d not found\n",
273 pod
->line6
.properties
->ctrl_if
);
277 err
= usb_driver_claim_interface(&podhd_driver
, intf
, NULL
);
279 dev_err(pod
->line6
.ifcdev
, "can't claim interface %d, error %d\n",
280 pod
->line6
.properties
->ctrl_if
, err
);
285 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL_INFO
) {
286 /* create sysfs entries: */
287 err
= snd_card_add_dev_attr(line6
->card
, &podhd_dev_attr_group
);
292 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_PCM
) {
293 /* initialize PCM subsystem: */
294 err
= line6_init_pcm(line6
,
295 (id
->driver_info
== LINE6_PODX3
||
296 id
->driver_info
== LINE6_PODX3LIVE
) ? &podx3_pcm_properties
:
297 &podhd_pcm_properties
);
302 if (!(pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL_INFO
)) {
303 /* register USB audio system directly */
304 return snd_card_register(line6
->card
);
307 /* init device and delay registering */
308 schedule_delayed_work(&line6
->startup_work
,
309 msecs_to_jiffies(PODHD_STARTUP_DELAY
));
313 #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
314 #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
316 /* table of devices that work with this driver */
317 static const struct usb_device_id podhd_id_table
[] = {
318 /* TODO: no need to alloc data interfaces when only audio is used */
319 { LINE6_DEVICE(0x5057), .driver_info
= LINE6_PODHD300
},
320 { LINE6_DEVICE(0x5058), .driver_info
= LINE6_PODHD400
},
321 { LINE6_IF_NUM(0x414D, 0), .driver_info
= LINE6_PODHD500_0
},
322 { LINE6_IF_NUM(0x414D, 1), .driver_info
= LINE6_PODHD500_1
},
323 { LINE6_IF_NUM(0x414A, 0), .driver_info
= LINE6_PODX3
},
324 { LINE6_IF_NUM(0x414B, 0), .driver_info
= LINE6_PODX3LIVE
},
325 { LINE6_IF_NUM(0x4159, 0), .driver_info
= LINE6_PODHD500X
},
326 { LINE6_IF_NUM(0x4156, 0), .driver_info
= LINE6_PODHDDESKTOP
},
330 MODULE_DEVICE_TABLE(usb
, podhd_id_table
);
332 static const struct line6_properties podhd_properties_table
[] = {
336 .capabilities
= LINE6_CAP_PCM
347 .capabilities
= LINE6_CAP_PCM
355 [LINE6_PODHD500_0
] = {
358 .capabilities
= LINE6_CAP_PCM
366 [LINE6_PODHD500_1
] = {
369 .capabilities
= LINE6_CAP_PCM
380 .capabilities
= LINE6_CAP_CONTROL
| LINE6_CAP_CONTROL_INFO
381 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
| LINE6_CAP_IN_NEEDS_OUT
,
389 [LINE6_PODX3LIVE
] = {
391 .name
= "POD X3 LIVE",
392 .capabilities
= LINE6_CAP_CONTROL
| LINE6_CAP_CONTROL_INFO
393 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
| LINE6_CAP_IN_NEEDS_OUT
,
401 [LINE6_PODHD500X
] = {
403 .name
= "POD HD500X",
404 .capabilities
= LINE6_CAP_CONTROL
405 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
,
413 [LINE6_PODHDDESKTOP
] = {
414 .id
= "PODHDDESKTOP",
415 .name
= "POD HDDESKTOP",
416 .capabilities
= LINE6_CAP_CONTROL
417 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
,
430 static int podhd_probe(struct usb_interface
*interface
,
431 const struct usb_device_id
*id
)
433 return line6_probe(interface
, id
, "Line6-PODHD",
434 &podhd_properties_table
[id
->driver_info
],
435 podhd_init
, sizeof(struct usb_line6_podhd
));
438 static struct usb_driver podhd_driver
= {
439 .name
= KBUILD_MODNAME
,
440 .probe
= podhd_probe
,
441 .disconnect
= line6_disconnect
,
443 .suspend
= line6_suspend
,
444 .resume
= line6_resume
,
445 .reset_resume
= line6_resume
,
447 .id_table
= podhd_id_table
,
450 module_usb_driver(podhd_driver
);
452 MODULE_DESCRIPTION("Line 6 PODHD USB driver");
453 MODULE_LICENSE("GPL");