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
46 struct usb_line6_podhd
{
47 /* Generic Line 6 USB data */
48 struct usb_line6 line6
;
50 /* Timer for device initialization */
51 struct timer_list startup_timer
;
53 /* Work handler for device initialization */
54 struct work_struct startup_work
;
56 /* Current progress in startup procedure */
59 /* Serial number of device */
62 /* Firmware version */
66 static struct snd_ratden podhd_ratden
= {
73 static struct line6_pcm_properties podhd_pcm_properties
= {
75 .info
= (SNDRV_PCM_INFO_MMAP
|
76 SNDRV_PCM_INFO_INTERLEAVED
|
77 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
78 SNDRV_PCM_INFO_MMAP_VALID
|
79 SNDRV_PCM_INFO_PAUSE
|
80 SNDRV_PCM_INFO_SYNC_START
),
81 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
82 .rates
= SNDRV_PCM_RATE_48000
,
87 .buffer_bytes_max
= 60000,
88 .period_bytes_min
= 64,
89 .period_bytes_max
= 8192,
93 .info
= (SNDRV_PCM_INFO_MMAP
|
94 SNDRV_PCM_INFO_INTERLEAVED
|
95 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
96 SNDRV_PCM_INFO_MMAP_VALID
|
97 SNDRV_PCM_INFO_SYNC_START
),
98 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
99 .rates
= SNDRV_PCM_RATE_48000
,
104 .buffer_bytes_max
= 60000,
105 .period_bytes_min
= 64,
106 .period_bytes_max
= 8192,
108 .periods_max
= 1024},
111 .rats
= &podhd_ratden
},
112 .bytes_per_channel
= 3 /* SNDRV_PCM_FMTBIT_S24_3LE */
115 static struct line6_pcm_properties podx3_pcm_properties
= {
117 .info
= (SNDRV_PCM_INFO_MMAP
|
118 SNDRV_PCM_INFO_INTERLEAVED
|
119 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
120 SNDRV_PCM_INFO_MMAP_VALID
|
121 SNDRV_PCM_INFO_PAUSE
|
122 SNDRV_PCM_INFO_SYNC_START
),
123 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
124 .rates
= SNDRV_PCM_RATE_48000
,
129 .buffer_bytes_max
= 60000,
130 .period_bytes_min
= 64,
131 .period_bytes_max
= 8192,
133 .periods_max
= 1024},
135 .info
= (SNDRV_PCM_INFO_MMAP
|
136 SNDRV_PCM_INFO_INTERLEAVED
|
137 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
138 SNDRV_PCM_INFO_MMAP_VALID
|
139 SNDRV_PCM_INFO_SYNC_START
),
140 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
141 .rates
= SNDRV_PCM_RATE_48000
,
144 /* 1+2: Main signal (out), 3+4: Tone 1,
145 * 5+6: Tone 2, 7+8: raw
149 .buffer_bytes_max
= 60000,
150 .period_bytes_min
= 64,
151 .period_bytes_max
= 8192,
153 .periods_max
= 1024},
156 .rats
= &podhd_ratden
},
157 .bytes_per_channel
= 3 /* SNDRV_PCM_FMTBIT_S24_3LE */
159 static struct usb_driver podhd_driver
;
161 static void podhd_startup_start_workqueue(struct timer_list
*t
);
162 static void podhd_startup_workqueue(struct work_struct
*work
);
163 static int podhd_startup_finalize(struct usb_line6_podhd
*pod
);
165 static ssize_t
serial_number_show(struct device
*dev
,
166 struct device_attribute
*attr
, char *buf
)
168 struct snd_card
*card
= dev_to_snd_card(dev
);
169 struct usb_line6_podhd
*pod
= card
->private_data
;
171 return sprintf(buf
, "%u\n", pod
->serial_number
);
174 static ssize_t
firmware_version_show(struct device
*dev
,
175 struct device_attribute
*attr
, char *buf
)
177 struct snd_card
*card
= dev_to_snd_card(dev
);
178 struct usb_line6_podhd
*pod
= card
->private_data
;
180 return sprintf(buf
, "%06x\n", pod
->firmware_version
);
183 static DEVICE_ATTR_RO(firmware_version
);
184 static DEVICE_ATTR_RO(serial_number
);
186 static struct attribute
*podhd_dev_attrs
[] = {
187 &dev_attr_firmware_version
.attr
,
188 &dev_attr_serial_number
.attr
,
192 static const struct attribute_group podhd_dev_attr_group
= {
194 .attrs
= podhd_dev_attrs
,
198 * POD X3 startup procedure.
200 * May be compatible with other POD HD's, since it's also similar to the
201 * previous POD setup. In any case, it doesn't seem to be required for the
202 * audio nor bulk interfaces to work.
205 static void podhd_startup(struct usb_line6_podhd
*pod
)
207 CHECK_STARTUP_PROGRESS(pod
->startup_progress
, PODHD_STARTUP_INIT
);
209 /* delay startup procedure: */
210 line6_start_timer(&pod
->startup_timer
, PODHD_STARTUP_DELAY
,
211 podhd_startup_start_workqueue
);
214 static void podhd_startup_start_workqueue(struct timer_list
*t
)
216 struct usb_line6_podhd
*pod
= from_timer(pod
, t
, startup_timer
);
218 CHECK_STARTUP_PROGRESS(pod
->startup_progress
,
219 PODHD_STARTUP_SCHEDULE_WORKQUEUE
);
221 /* schedule work for global work queue: */
222 schedule_work(&pod
->startup_work
);
225 static int podhd_dev_start(struct usb_line6_podhd
*pod
)
230 struct usb_device
*usbdev
= pod
->line6
.usbdev
;
232 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0),
233 0x67, USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
235 NULL
, 0, LINE6_TIMEOUT
* HZ
);
237 dev_err(pod
->line6
.ifcdev
, "read request failed (error %d)\n", ret
);
241 /* NOTE: looks like some kind of ping message */
242 ret
= usb_control_msg(usbdev
, usb_rcvctrlpipe(usbdev
, 0), 0x67,
243 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
245 &init_bytes
, 3, LINE6_TIMEOUT
* HZ
);
247 dev_err(pod
->line6
.ifcdev
,
248 "receive length failed (error %d)\n", ret
);
252 pod
->firmware_version
=
253 (init_bytes
[0] << 16) | (init_bytes
[1] << 8) | (init_bytes
[2] << 0);
255 for (i
= 0; i
<= 16; i
++) {
256 ret
= line6_read_data(&pod
->line6
, 0xf000 + 0x08 * i
, init_bytes
, 8);
261 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0),
263 USB_TYPE_STANDARD
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
265 NULL
, 0, LINE6_TIMEOUT
* HZ
);
272 static void podhd_startup_workqueue(struct work_struct
*work
)
274 struct usb_line6_podhd
*pod
=
275 container_of(work
, struct usb_line6_podhd
, startup_work
);
277 CHECK_STARTUP_PROGRESS(pod
->startup_progress
, PODHD_STARTUP_SETUP
);
279 podhd_dev_start(pod
);
280 line6_read_serial_number(&pod
->line6
, &pod
->serial_number
);
282 podhd_startup_finalize(pod
);
285 static int podhd_startup_finalize(struct usb_line6_podhd
*pod
)
287 struct usb_line6
*line6
= &pod
->line6
;
289 /* ALSA audio interface: */
290 return snd_card_register(line6
->card
);
293 static void podhd_disconnect(struct usb_line6
*line6
)
295 struct usb_line6_podhd
*pod
= (struct usb_line6_podhd
*)line6
;
297 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL_INFO
) {
298 struct usb_interface
*intf
;
300 del_timer_sync(&pod
->startup_timer
);
301 cancel_work_sync(&pod
->startup_work
);
303 intf
= usb_ifnum_to_if(line6
->usbdev
,
304 pod
->line6
.properties
->ctrl_if
);
306 usb_driver_release_interface(&podhd_driver
, intf
);
311 Try to init POD HD device.
313 static int podhd_init(struct usb_line6
*line6
,
314 const struct usb_device_id
*id
)
317 struct usb_line6_podhd
*pod
= (struct usb_line6_podhd
*) line6
;
318 struct usb_interface
*intf
;
320 line6
->disconnect
= podhd_disconnect
;
322 timer_setup(&pod
->startup_timer
, NULL
, 0);
323 INIT_WORK(&pod
->startup_work
, podhd_startup_workqueue
);
325 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL
) {
326 /* claim the data interface */
327 intf
= usb_ifnum_to_if(line6
->usbdev
,
328 pod
->line6
.properties
->ctrl_if
);
330 dev_err(pod
->line6
.ifcdev
, "interface %d not found\n",
331 pod
->line6
.properties
->ctrl_if
);
335 err
= usb_driver_claim_interface(&podhd_driver
, intf
, NULL
);
337 dev_err(pod
->line6
.ifcdev
, "can't claim interface %d, error %d\n",
338 pod
->line6
.properties
->ctrl_if
, err
);
343 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL_INFO
) {
344 /* create sysfs entries: */
345 err
= snd_card_add_dev_attr(line6
->card
, &podhd_dev_attr_group
);
350 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_PCM
) {
351 /* initialize PCM subsystem: */
352 err
= line6_init_pcm(line6
,
353 (id
->driver_info
== LINE6_PODX3
||
354 id
->driver_info
== LINE6_PODX3LIVE
) ? &podx3_pcm_properties
:
355 &podhd_pcm_properties
);
360 if (!(pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL_INFO
)) {
361 /* register USB audio system directly */
362 return podhd_startup_finalize(pod
);
365 /* init device and delay registering */
370 #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
371 #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
373 /* table of devices that work with this driver */
374 static const struct usb_device_id podhd_id_table
[] = {
375 /* TODO: no need to alloc data interfaces when only audio is used */
376 { LINE6_DEVICE(0x5057), .driver_info
= LINE6_PODHD300
},
377 { LINE6_DEVICE(0x5058), .driver_info
= LINE6_PODHD400
},
378 { LINE6_IF_NUM(0x414D, 0), .driver_info
= LINE6_PODHD500_0
},
379 { LINE6_IF_NUM(0x414D, 1), .driver_info
= LINE6_PODHD500_1
},
380 { LINE6_IF_NUM(0x414A, 0), .driver_info
= LINE6_PODX3
},
381 { LINE6_IF_NUM(0x414B, 0), .driver_info
= LINE6_PODX3LIVE
},
382 { LINE6_IF_NUM(0x4159, 0), .driver_info
= LINE6_PODHD500X
},
383 { LINE6_IF_NUM(0x4156, 0), .driver_info
= LINE6_PODHDDESKTOP
},
387 MODULE_DEVICE_TABLE(usb
, podhd_id_table
);
389 static const struct line6_properties podhd_properties_table
[] = {
393 .capabilities
= LINE6_CAP_PCM
404 .capabilities
= LINE6_CAP_PCM
412 [LINE6_PODHD500_0
] = {
415 .capabilities
= LINE6_CAP_PCM
423 [LINE6_PODHD500_1
] = {
426 .capabilities
= LINE6_CAP_PCM
437 .capabilities
= LINE6_CAP_CONTROL
| LINE6_CAP_CONTROL_INFO
438 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
| LINE6_CAP_IN_NEEDS_OUT
,
446 [LINE6_PODX3LIVE
] = {
448 .name
= "POD X3 LIVE",
449 .capabilities
= LINE6_CAP_CONTROL
| LINE6_CAP_CONTROL_INFO
450 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
| LINE6_CAP_IN_NEEDS_OUT
,
458 [LINE6_PODHD500X
] = {
460 .name
= "POD HD500X",
461 .capabilities
= LINE6_CAP_CONTROL
462 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
,
470 [LINE6_PODHDDESKTOP
] = {
471 .id
= "PODHDDESKTOP",
472 .name
= "POD HDDESKTOP",
473 .capabilities
= LINE6_CAP_CONTROL
474 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
,
487 static int podhd_probe(struct usb_interface
*interface
,
488 const struct usb_device_id
*id
)
490 return line6_probe(interface
, id
, "Line6-PODHD",
491 &podhd_properties_table
[id
->driver_info
],
492 podhd_init
, sizeof(struct usb_line6_podhd
));
495 static struct usb_driver podhd_driver
= {
496 .name
= KBUILD_MODNAME
,
497 .probe
= podhd_probe
,
498 .disconnect
= line6_disconnect
,
500 .suspend
= line6_suspend
,
501 .resume
= line6_resume
,
502 .reset_resume
= line6_resume
,
504 .id_table
= podhd_id_table
,
507 module_usb_driver(podhd_driver
);
509 MODULE_DESCRIPTION("Line 6 PODHD USB driver");
510 MODULE_LICENSE("GPL");