]>
Commit | Line | Data |
---|---|---|
a10e763b | 1 | // SPDX-License-Identifier: GPL-2.0-only |
16dc1040 | 2 | /* |
c6fffce9 | 3 | * Line 6 Pod HD |
16dc1040 SH |
4 | * |
5 | * Copyright (C) 2011 Stefan Hajnoczi <stefanha@gmail.com> | |
790869da | 6 | * Copyright (C) 2015 Andrej Krutak <dev@andree.sk> |
c1d25075 | 7 | * Copyright (C) 2017 Hans P. Moller <hmoller@uc.cl> |
16dc1040 SH |
8 | */ |
9 | ||
ccddbe4a TI |
10 | #include <linux/usb.h> |
11 | #include <linux/slab.h> | |
12 | #include <linux/module.h> | |
16dc1040 SH |
13 | #include <sound/core.h> |
14 | #include <sound/pcm.h> | |
15 | ||
16dc1040 SH |
16 | #include "driver.h" |
17 | #include "pcm.h" | |
ccddbe4a | 18 | |
790869da AK |
19 | #define PODHD_STARTUP_DELAY 500 |
20 | ||
ccddbe4a TI |
21 | enum { |
22 | LINE6_PODHD300, | |
23 | LINE6_PODHD400, | |
cc18b2f4 | 24 | LINE6_PODHD500, |
790869da | 25 | LINE6_PODX3, |
c1d25075 | 26 | LINE6_PODX3LIVE, |
729fbfc9 HME |
27 | LINE6_PODHD500X, |
28 | LINE6_PODHDDESKTOP | |
790869da AK |
29 | }; |
30 | ||
31 | struct usb_line6_podhd { | |
32 | /* Generic Line 6 USB data */ | |
33 | struct usb_line6 line6; | |
34 | ||
790869da AK |
35 | /* Serial number of device */ |
36 | u32 serial_number; | |
37 | ||
38 | /* Firmware version */ | |
39 | int firmware_version; | |
ccddbe4a TI |
40 | }; |
41 | ||
f23a09ee TI |
42 | #define line6_to_podhd(x) container_of(x, struct usb_line6_podhd, line6) |
43 | ||
37cc306b | 44 | static const struct snd_ratden podhd_ratden = { |
16dc1040 SH |
45 | .num_min = 48000, |
46 | .num_max = 48000, | |
47 | .num_step = 1, | |
48 | .den = 1, | |
49 | }; | |
50 | ||
51 | static struct line6_pcm_properties podhd_pcm_properties = { | |
1263f611 | 52 | .playback_hw = { |
16dc1040 SH |
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 | | |
16dc1040 SH |
58 | SNDRV_PCM_INFO_SYNC_START), |
59 | .formats = SNDRV_PCM_FMTBIT_S24_3LE, | |
60 | .rates = SNDRV_PCM_RATE_48000, | |
61 | .rate_min = 48000, | |
62 | .rate_max = 48000, | |
63 | .channels_min = 2, | |
64 | .channels_max = 2, | |
65 | .buffer_bytes_max = 60000, | |
66 | .period_bytes_min = 64, | |
67 | .period_bytes_max = 8192, | |
68 | .periods_min = 1, | |
69 | .periods_max = 1024}, | |
1263f611 | 70 | .capture_hw = { |
16dc1040 SH |
71 | .info = (SNDRV_PCM_INFO_MMAP | |
72 | SNDRV_PCM_INFO_INTERLEAVED | | |
73 | SNDRV_PCM_INFO_BLOCK_TRANSFER | | |
74 | SNDRV_PCM_INFO_MMAP_VALID | | |
16dc1040 SH |
75 | SNDRV_PCM_INFO_SYNC_START), |
76 | .formats = SNDRV_PCM_FMTBIT_S24_3LE, | |
77 | .rates = SNDRV_PCM_RATE_48000, | |
78 | .rate_min = 48000, | |
79 | .rate_max = 48000, | |
80 | .channels_min = 2, | |
81 | .channels_max = 2, | |
82 | .buffer_bytes_max = 60000, | |
83 | .period_bytes_min = 64, | |
84 | .period_bytes_max = 8192, | |
85 | .periods_min = 1, | |
86 | .periods_max = 1024}, | |
1263f611 | 87 | .rates = { |
16dc1040 SH |
88 | .nrats = 1, |
89 | .rats = &podhd_ratden}, | |
790869da | 90 | .bytes_per_channel = 3 /* SNDRV_PCM_FMTBIT_S24_3LE */ |
16dc1040 SH |
91 | }; |
92 | ||
790869da AK |
93 | static struct line6_pcm_properties podx3_pcm_properties = { |
94 | .playback_hw = { | |
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, | |
103 | .rate_min = 48000, | |
104 | .rate_max = 48000, | |
105 | .channels_min = 2, | |
106 | .channels_max = 2, | |
107 | .buffer_bytes_max = 60000, | |
108 | .period_bytes_min = 64, | |
109 | .period_bytes_max = 8192, | |
110 | .periods_min = 1, | |
111 | .periods_max = 1024}, | |
112 | .capture_hw = { | |
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, | |
120 | .rate_min = 48000, | |
121 | .rate_max = 48000, | |
122 | /* 1+2: Main signal (out), 3+4: Tone 1, | |
123 | * 5+6: Tone 2, 7+8: raw | |
124 | */ | |
125 | .channels_min = 8, | |
126 | .channels_max = 8, | |
127 | .buffer_bytes_max = 60000, | |
128 | .period_bytes_min = 64, | |
129 | .period_bytes_max = 8192, | |
130 | .periods_min = 1, | |
131 | .periods_max = 1024}, | |
132 | .rates = { | |
133 | .nrats = 1, | |
134 | .rats = &podhd_ratden}, | |
135 | .bytes_per_channel = 3 /* SNDRV_PCM_FMTBIT_S24_3LE */ | |
136 | }; | |
fc90172b | 137 | static struct usb_driver podhd_driver; |
790869da | 138 | |
790869da AK |
139 | static ssize_t serial_number_show(struct device *dev, |
140 | struct device_attribute *attr, char *buf) | |
141 | { | |
142 | struct snd_card *card = dev_to_snd_card(dev); | |
143 | struct usb_line6_podhd *pod = card->private_data; | |
144 | ||
145 | return sprintf(buf, "%u\n", pod->serial_number); | |
146 | } | |
147 | ||
148 | static ssize_t firmware_version_show(struct device *dev, | |
149 | struct device_attribute *attr, char *buf) | |
150 | { | |
151 | struct snd_card *card = dev_to_snd_card(dev); | |
152 | struct usb_line6_podhd *pod = card->private_data; | |
153 | ||
154 | return sprintf(buf, "%06x\n", pod->firmware_version); | |
155 | } | |
156 | ||
157 | static DEVICE_ATTR_RO(firmware_version); | |
158 | static DEVICE_ATTR_RO(serial_number); | |
159 | ||
160 | static struct attribute *podhd_dev_attrs[] = { | |
161 | &dev_attr_firmware_version.attr, | |
162 | &dev_attr_serial_number.attr, | |
163 | NULL | |
164 | }; | |
165 | ||
166 | static const struct attribute_group podhd_dev_attr_group = { | |
167 | .name = "podhd", | |
168 | .attrs = podhd_dev_attrs, | |
169 | }; | |
170 | ||
171 | /* | |
172 | * POD X3 startup procedure. | |
173 | * | |
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. | |
177 | */ | |
178 | ||
790869da AK |
179 | static int podhd_dev_start(struct usb_line6_podhd *pod) |
180 | { | |
181 | int ret; | |
e5c812e8 | 182 | u8 *init_bytes; |
790869da AK |
183 | int i; |
184 | struct usb_device *usbdev = pod->line6.usbdev; | |
185 | ||
e5c812e8 GKH |
186 | init_bytes = kmalloc(8, GFP_KERNEL); |
187 | if (!init_bytes) | |
188 | return -ENOMEM; | |
189 | ||
790869da AK |
190 | ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), |
191 | 0x67, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, | |
192 | 0x11, 0, | |
193 | NULL, 0, LINE6_TIMEOUT * HZ); | |
194 | if (ret < 0) { | |
195 | dev_err(pod->line6.ifcdev, "read request failed (error %d)\n", ret); | |
e5c812e8 | 196 | goto exit; |
790869da AK |
197 | } |
198 | ||
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, | |
202 | 0x11, 0x0, | |
e5c812e8 | 203 | init_bytes, 3, LINE6_TIMEOUT * HZ); |
790869da AK |
204 | if (ret < 0) { |
205 | dev_err(pod->line6.ifcdev, | |
206 | "receive length failed (error %d)\n", ret); | |
e5c812e8 | 207 | goto exit; |
790869da AK |
208 | } |
209 | ||
210 | pod->firmware_version = | |
211 | (init_bytes[0] << 16) | (init_bytes[1] << 8) | (init_bytes[2] << 0); | |
212 | ||
213 | for (i = 0; i <= 16; i++) { | |
214 | ret = line6_read_data(&pod->line6, 0xf000 + 0x08 * i, init_bytes, 8); | |
215 | if (ret < 0) | |
e5c812e8 | 216 | goto exit; |
790869da AK |
217 | } |
218 | ||
219 | ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), | |
220 | USB_REQ_SET_FEATURE, | |
221 | USB_TYPE_STANDARD | USB_RECIP_DEVICE | USB_DIR_OUT, | |
222 | 1, 0, | |
223 | NULL, 0, LINE6_TIMEOUT * HZ); | |
e5c812e8 GKH |
224 | exit: |
225 | kfree(init_bytes); | |
226 | return ret; | |
790869da AK |
227 | } |
228 | ||
a91c1da7 | 229 | static void podhd_startup(struct usb_line6 *line6) |
790869da | 230 | { |
f23a09ee | 231 | struct usb_line6_podhd *pod = line6_to_podhd(line6); |
790869da AK |
232 | |
233 | podhd_dev_start(pod); | |
234 | line6_read_serial_number(&pod->line6, &pod->serial_number); | |
a91c1da7 TI |
235 | if (snd_card_register(line6->card)) |
236 | dev_err(line6->ifcdev, "Failed to register POD HD card.\n"); | |
790869da AK |
237 | } |
238 | ||
239 | static void podhd_disconnect(struct usb_line6 *line6) | |
240 | { | |
f23a09ee | 241 | struct usb_line6_podhd *pod = line6_to_podhd(line6); |
790869da | 242 | |
8cad7a3d | 243 | if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL_INFO) { |
fc90172b AK |
244 | struct usb_interface *intf; |
245 | ||
fc90172b AK |
246 | intf = usb_ifnum_to_if(line6->usbdev, |
247 | pod->line6.properties->ctrl_if); | |
54a4b2b4 TI |
248 | if (intf) |
249 | usb_driver_release_interface(&podhd_driver, intf); | |
790869da AK |
250 | } |
251 | } | |
252 | ||
16dc1040 SH |
253 | /* |
254 | Try to init POD HD device. | |
255 | */ | |
f66fd990 TI |
256 | static int podhd_init(struct usb_line6 *line6, |
257 | const struct usb_device_id *id) | |
16dc1040 SH |
258 | { |
259 | int err; | |
f23a09ee | 260 | struct usb_line6_podhd *pod = line6_to_podhd(line6); |
fc90172b | 261 | struct usb_interface *intf; |
790869da AK |
262 | |
263 | line6->disconnect = podhd_disconnect; | |
a91c1da7 | 264 | line6->startup = podhd_startup; |
cb02ffc7 | 265 | |
790869da | 266 | if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL) { |
fc90172b AK |
267 | /* claim the data interface */ |
268 | intf = usb_ifnum_to_if(line6->usbdev, | |
269 | pod->line6.properties->ctrl_if); | |
270 | if (!intf) { | |
271 | dev_err(pod->line6.ifcdev, "interface %d not found\n", | |
272 | pod->line6.properties->ctrl_if); | |
273 | return -ENODEV; | |
274 | } | |
275 | ||
276 | err = usb_driver_claim_interface(&podhd_driver, intf, NULL); | |
277 | if (err != 0) { | |
278 | dev_err(pod->line6.ifcdev, "can't claim interface %d, error %d\n", | |
279 | pod->line6.properties->ctrl_if, err); | |
280 | return err; | |
281 | } | |
8cad7a3d | 282 | } |
fc90172b | 283 | |
8cad7a3d | 284 | if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL_INFO) { |
790869da AK |
285 | /* create sysfs entries: */ |
286 | err = snd_card_add_dev_attr(line6->card, &podhd_dev_attr_group); | |
287 | if (err < 0) | |
288 | return err; | |
289 | } | |
16dc1040 | 290 | |
cfa76969 AK |
291 | if (pod->line6.properties->capabilities & LINE6_CAP_PCM) { |
292 | /* initialize PCM subsystem: */ | |
293 | err = line6_init_pcm(line6, | |
b907900e AK |
294 | (id->driver_info == LINE6_PODX3 || |
295 | id->driver_info == LINE6_PODX3LIVE) ? &podx3_pcm_properties : | |
cfa76969 AK |
296 | &podhd_pcm_properties); |
297 | if (err < 0) | |
298 | return err; | |
299 | } | |
16dc1040 | 300 | |
8cad7a3d | 301 | if (!(pod->line6.properties->capabilities & LINE6_CAP_CONTROL_INFO)) { |
790869da | 302 | /* register USB audio system directly */ |
a91c1da7 | 303 | return snd_card_register(line6->card); |
790869da AK |
304 | } |
305 | ||
306 | /* init device and delay registering */ | |
a91c1da7 TI |
307 | schedule_delayed_work(&line6->startup_work, |
308 | msecs_to_jiffies(PODHD_STARTUP_DELAY)); | |
790869da | 309 | return 0; |
16dc1040 SH |
310 | } |
311 | ||
ccddbe4a TI |
312 | #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod) |
313 | #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n) | |
314 | ||
315 | /* table of devices that work with this driver */ | |
316 | static const struct usb_device_id podhd_id_table[] = { | |
790869da | 317 | /* TODO: no need to alloc data interfaces when only audio is used */ |
ccddbe4a TI |
318 | { LINE6_DEVICE(0x5057), .driver_info = LINE6_PODHD300 }, |
319 | { LINE6_DEVICE(0x5058), .driver_info = LINE6_PODHD400 }, | |
cc18b2f4 | 320 | { LINE6_IF_NUM(0x414D, 0), .driver_info = LINE6_PODHD500 }, |
790869da | 321 | { LINE6_IF_NUM(0x414A, 0), .driver_info = LINE6_PODX3 }, |
c039aaa7 | 322 | { LINE6_IF_NUM(0x414B, 0), .driver_info = LINE6_PODX3LIVE }, |
c1d25075 | 323 | { LINE6_IF_NUM(0x4159, 0), .driver_info = LINE6_PODHD500X }, |
729fbfc9 | 324 | { LINE6_IF_NUM(0x4156, 0), .driver_info = LINE6_PODHDDESKTOP }, |
ccddbe4a TI |
325 | {} |
326 | }; | |
327 | ||
328 | MODULE_DEVICE_TABLE(usb, podhd_id_table); | |
329 | ||
330 | static const struct line6_properties podhd_properties_table[] = { | |
331 | [LINE6_PODHD300] = { | |
332 | .id = "PODHD300", | |
333 | .name = "POD HD300", | |
790869da | 334 | .capabilities = LINE6_CAP_PCM |
ccddbe4a TI |
335 | | LINE6_CAP_HWMON, |
336 | .altsetting = 5, | |
337 | .ep_ctrl_r = 0x84, | |
338 | .ep_ctrl_w = 0x03, | |
339 | .ep_audio_r = 0x82, | |
340 | .ep_audio_w = 0x01, | |
341 | }, | |
342 | [LINE6_PODHD400] = { | |
343 | .id = "PODHD400", | |
344 | .name = "POD HD400", | |
790869da | 345 | .capabilities = LINE6_CAP_PCM |
ccddbe4a TI |
346 | | LINE6_CAP_HWMON, |
347 | .altsetting = 5, | |
348 | .ep_ctrl_r = 0x84, | |
349 | .ep_ctrl_w = 0x03, | |
350 | .ep_audio_r = 0x82, | |
351 | .ep_audio_w = 0x01, | |
352 | }, | |
cc18b2f4 | 353 | [LINE6_PODHD500] = { |
ccddbe4a TI |
354 | .id = "PODHD500", |
355 | .name = "POD HD500", | |
cc18b2f4 | 356 | .capabilities = LINE6_CAP_PCM | LINE6_CAP_CONTROL |
ccddbe4a TI |
357 | | LINE6_CAP_HWMON, |
358 | .altsetting = 1, | |
cc18b2f4 | 359 | .ctrl_if = 1, |
ccddbe4a TI |
360 | .ep_ctrl_r = 0x81, |
361 | .ep_ctrl_w = 0x01, | |
362 | .ep_audio_r = 0x86, | |
363 | .ep_audio_w = 0x02, | |
364 | }, | |
790869da AK |
365 | [LINE6_PODX3] = { |
366 | .id = "PODX3", | |
367 | .name = "POD X3", | |
8cad7a3d | 368 | .capabilities = LINE6_CAP_CONTROL | LINE6_CAP_CONTROL_INFO |
790869da AK |
369 | | LINE6_CAP_PCM | LINE6_CAP_HWMON | LINE6_CAP_IN_NEEDS_OUT, |
370 | .altsetting = 1, | |
371 | .ep_ctrl_r = 0x81, | |
372 | .ep_ctrl_w = 0x01, | |
fc90172b | 373 | .ctrl_if = 1, |
790869da AK |
374 | .ep_audio_r = 0x86, |
375 | .ep_audio_w = 0x02, | |
376 | }, | |
c039aaa7 AK |
377 | [LINE6_PODX3LIVE] = { |
378 | .id = "PODX3LIVE", | |
379 | .name = "POD X3 LIVE", | |
8cad7a3d | 380 | .capabilities = LINE6_CAP_CONTROL | LINE6_CAP_CONTROL_INFO |
c039aaa7 AK |
381 | | LINE6_CAP_PCM | LINE6_CAP_HWMON | LINE6_CAP_IN_NEEDS_OUT, |
382 | .altsetting = 1, | |
383 | .ep_ctrl_r = 0x81, | |
384 | .ep_ctrl_w = 0x01, | |
fc90172b | 385 | .ctrl_if = 1, |
c039aaa7 AK |
386 | .ep_audio_r = 0x86, |
387 | .ep_audio_w = 0x02, | |
388 | }, | |
c1d25075 HME |
389 | [LINE6_PODHD500X] = { |
390 | .id = "PODHD500X", | |
391 | .name = "POD HD500X", | |
392 | .capabilities = LINE6_CAP_CONTROL | |
393 | | LINE6_CAP_PCM | LINE6_CAP_HWMON, | |
394 | .altsetting = 1, | |
395 | .ep_ctrl_r = 0x81, | |
396 | .ep_ctrl_w = 0x01, | |
397 | .ctrl_if = 1, | |
398 | .ep_audio_r = 0x86, | |
399 | .ep_audio_w = 0x02, | |
400 | }, | |
729fbfc9 HME |
401 | [LINE6_PODHDDESKTOP] = { |
402 | .id = "PODHDDESKTOP", | |
403 | .name = "POD HDDESKTOP", | |
404 | .capabilities = LINE6_CAP_CONTROL | |
405 | | LINE6_CAP_PCM | LINE6_CAP_HWMON, | |
406 | .altsetting = 1, | |
407 | .ep_ctrl_r = 0x81, | |
408 | .ep_ctrl_w = 0x01, | |
409 | .ctrl_if = 1, | |
410 | .ep_audio_r = 0x86, | |
411 | .ep_audio_w = 0x02, | |
412 | }, | |
ccddbe4a TI |
413 | }; |
414 | ||
ccddbe4a TI |
415 | /* |
416 | Probe USB device. | |
417 | */ | |
418 | static int podhd_probe(struct usb_interface *interface, | |
419 | const struct usb_device_id *id) | |
420 | { | |
12865cac | 421 | return line6_probe(interface, id, "Line6-PODHD", |
85a9339b | 422 | &podhd_properties_table[id->driver_info], |
790869da | 423 | podhd_init, sizeof(struct usb_line6_podhd)); |
ccddbe4a TI |
424 | } |
425 | ||
426 | static struct usb_driver podhd_driver = { | |
427 | .name = KBUILD_MODNAME, | |
428 | .probe = podhd_probe, | |
429 | .disconnect = line6_disconnect, | |
430 | #ifdef CONFIG_PM | |
431 | .suspend = line6_suspend, | |
432 | .resume = line6_resume, | |
433 | .reset_resume = line6_resume, | |
434 | #endif | |
435 | .id_table = podhd_id_table, | |
436 | }; | |
437 | ||
438 | module_usb_driver(podhd_driver); | |
439 | ||
c6fffce9 | 440 | MODULE_DESCRIPTION("Line 6 PODHD USB driver"); |
ccddbe4a | 441 | MODULE_LICENSE("GPL"); |