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 init_bytes
= kmalloc(8, GFP_KERNEL
);
236 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0),
237 0x67, USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
239 NULL
, 0, LINE6_TIMEOUT
* HZ
);
241 dev_err(pod
->line6
.ifcdev
, "read request failed (error %d)\n", ret
);
245 /* NOTE: looks like some kind of ping message */
246 ret
= usb_control_msg(usbdev
, usb_rcvctrlpipe(usbdev
, 0), 0x67,
247 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
249 init_bytes
, 3, LINE6_TIMEOUT
* HZ
);
251 dev_err(pod
->line6
.ifcdev
,
252 "receive length failed (error %d)\n", ret
);
256 pod
->firmware_version
=
257 (init_bytes
[0] << 16) | (init_bytes
[1] << 8) | (init_bytes
[2] << 0);
259 for (i
= 0; i
<= 16; i
++) {
260 ret
= line6_read_data(&pod
->line6
, 0xf000 + 0x08 * i
, init_bytes
, 8);
265 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0),
267 USB_TYPE_STANDARD
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
269 NULL
, 0, LINE6_TIMEOUT
* HZ
);
275 static void podhd_startup_workqueue(struct work_struct
*work
)
277 struct usb_line6_podhd
*pod
=
278 container_of(work
, struct usb_line6_podhd
, startup_work
);
280 CHECK_STARTUP_PROGRESS(pod
->startup_progress
, PODHD_STARTUP_SETUP
);
282 podhd_dev_start(pod
);
283 line6_read_serial_number(&pod
->line6
, &pod
->serial_number
);
285 podhd_startup_finalize(pod
);
288 static int podhd_startup_finalize(struct usb_line6_podhd
*pod
)
290 struct usb_line6
*line6
= &pod
->line6
;
292 /* ALSA audio interface: */
293 return snd_card_register(line6
->card
);
296 static void podhd_disconnect(struct usb_line6
*line6
)
298 struct usb_line6_podhd
*pod
= (struct usb_line6_podhd
*)line6
;
300 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL_INFO
) {
301 struct usb_interface
*intf
;
303 del_timer_sync(&pod
->startup_timer
);
304 cancel_work_sync(&pod
->startup_work
);
306 intf
= usb_ifnum_to_if(line6
->usbdev
,
307 pod
->line6
.properties
->ctrl_if
);
309 usb_driver_release_interface(&podhd_driver
, intf
);
314 Try to init POD HD device.
316 static int podhd_init(struct usb_line6
*line6
,
317 const struct usb_device_id
*id
)
320 struct usb_line6_podhd
*pod
= (struct usb_line6_podhd
*) line6
;
321 struct usb_interface
*intf
;
323 line6
->disconnect
= podhd_disconnect
;
325 timer_setup(&pod
->startup_timer
, NULL
, 0);
326 INIT_WORK(&pod
->startup_work
, podhd_startup_workqueue
);
328 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL
) {
329 /* claim the data interface */
330 intf
= usb_ifnum_to_if(line6
->usbdev
,
331 pod
->line6
.properties
->ctrl_if
);
333 dev_err(pod
->line6
.ifcdev
, "interface %d not found\n",
334 pod
->line6
.properties
->ctrl_if
);
338 err
= usb_driver_claim_interface(&podhd_driver
, intf
, NULL
);
340 dev_err(pod
->line6
.ifcdev
, "can't claim interface %d, error %d\n",
341 pod
->line6
.properties
->ctrl_if
, err
);
346 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL_INFO
) {
347 /* create sysfs entries: */
348 err
= snd_card_add_dev_attr(line6
->card
, &podhd_dev_attr_group
);
353 if (pod
->line6
.properties
->capabilities
& LINE6_CAP_PCM
) {
354 /* initialize PCM subsystem: */
355 err
= line6_init_pcm(line6
,
356 (id
->driver_info
== LINE6_PODX3
||
357 id
->driver_info
== LINE6_PODX3LIVE
) ? &podx3_pcm_properties
:
358 &podhd_pcm_properties
);
363 if (!(pod
->line6
.properties
->capabilities
& LINE6_CAP_CONTROL_INFO
)) {
364 /* register USB audio system directly */
365 return podhd_startup_finalize(pod
);
368 /* init device and delay registering */
373 #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
374 #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
376 /* table of devices that work with this driver */
377 static const struct usb_device_id podhd_id_table
[] = {
378 /* TODO: no need to alloc data interfaces when only audio is used */
379 { LINE6_DEVICE(0x5057), .driver_info
= LINE6_PODHD300
},
380 { LINE6_DEVICE(0x5058), .driver_info
= LINE6_PODHD400
},
381 { LINE6_IF_NUM(0x414D, 0), .driver_info
= LINE6_PODHD500_0
},
382 { LINE6_IF_NUM(0x414D, 1), .driver_info
= LINE6_PODHD500_1
},
383 { LINE6_IF_NUM(0x414A, 0), .driver_info
= LINE6_PODX3
},
384 { LINE6_IF_NUM(0x414B, 0), .driver_info
= LINE6_PODX3LIVE
},
385 { LINE6_IF_NUM(0x4159, 0), .driver_info
= LINE6_PODHD500X
},
386 { LINE6_IF_NUM(0x4156, 0), .driver_info
= LINE6_PODHDDESKTOP
},
390 MODULE_DEVICE_TABLE(usb
, podhd_id_table
);
392 static const struct line6_properties podhd_properties_table
[] = {
396 .capabilities
= LINE6_CAP_PCM
407 .capabilities
= LINE6_CAP_PCM
415 [LINE6_PODHD500_0
] = {
418 .capabilities
= LINE6_CAP_PCM
426 [LINE6_PODHD500_1
] = {
429 .capabilities
= LINE6_CAP_PCM
440 .capabilities
= LINE6_CAP_CONTROL
| LINE6_CAP_CONTROL_INFO
441 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
| LINE6_CAP_IN_NEEDS_OUT
,
449 [LINE6_PODX3LIVE
] = {
451 .name
= "POD X3 LIVE",
452 .capabilities
= LINE6_CAP_CONTROL
| LINE6_CAP_CONTROL_INFO
453 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
| LINE6_CAP_IN_NEEDS_OUT
,
461 [LINE6_PODHD500X
] = {
463 .name
= "POD HD500X",
464 .capabilities
= LINE6_CAP_CONTROL
465 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
,
473 [LINE6_PODHDDESKTOP
] = {
474 .id
= "PODHDDESKTOP",
475 .name
= "POD HDDESKTOP",
476 .capabilities
= LINE6_CAP_CONTROL
477 | LINE6_CAP_PCM
| LINE6_CAP_HWMON
,
490 static int podhd_probe(struct usb_interface
*interface
,
491 const struct usb_device_id
*id
)
493 return line6_probe(interface
, id
, "Line6-PODHD",
494 &podhd_properties_table
[id
->driver_info
],
495 podhd_init
, sizeof(struct usb_line6_podhd
));
498 static struct usb_driver podhd_driver
= {
499 .name
= KBUILD_MODNAME
,
500 .probe
= podhd_probe
,
501 .disconnect
= line6_disconnect
,
503 .suspend
= line6_suspend
,
504 .resume
= line6_resume
,
505 .reset_resume
= line6_resume
,
507 .id_table
= podhd_id_table
,
510 module_usb_driver(podhd_driver
);
512 MODULE_DESCRIPTION("Line 6 PODHD USB driver");
513 MODULE_LICENSE("GPL");