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