blob: 4e5693c97aa42165c40014f3b703aa084f8c3c95 [file] [log] [blame]
Thomas Gleixnera10e7632019-05-31 01:09:32 -07001// SPDX-License-Identifier: GPL-2.0-only
Markus Grabner705ecec2009-02-27 19:43:04 -08002/*
Chris Rorvickc078a4a2015-01-20 02:20:50 -06003 * Line 6 Linux USB driver
Markus Grabner705ecec2009-02-27 19:43:04 -08004 *
Markus Grabner1027f472010-08-12 01:35:30 +02005 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
Markus Grabner705ecec2009-02-27 19:43:04 -08006 * Emil Myhrman (emil.myhrman@gmail.com)
Markus Grabner705ecec2009-02-27 19:43:04 -08007 */
8
Markus Grabner1027f472010-08-12 01:35:30 +02009#include <linux/wait.h>
Takashi Iwaiccddbe42015-01-15 08:22:31 +010010#include <linux/usb.h>
11#include <linux/slab.h>
12#include <linux/module.h>
Takashi Iwaif44edd72015-01-20 09:36:31 +010013#include <linux/leds.h>
Takashi Iwaiccddbe42015-01-15 08:22:31 +010014#include <sound/core.h>
Markus Grabner1027f472010-08-12 01:35:30 +020015#include <sound/control.h>
Markus Grabner705ecec2009-02-27 19:43:04 -080016
Markus Grabner705ecec2009-02-27 19:43:04 -080017#include "capture.h"
Markus Grabner1027f472010-08-12 01:35:30 +020018#include "driver.h"
Markus Grabner705ecec2009-02-27 19:43:04 -080019#include "playback.h"
Takashi Iwaiccddbe42015-01-15 08:22:31 +010020
21enum line6_device_type {
22 LINE6_GUITARPORT,
23 LINE6_PODSTUDIO_GX,
24 LINE6_PODSTUDIO_UX1,
25 LINE6_PODSTUDIO_UX2,
26 LINE6_TONEPORT_GX,
27 LINE6_TONEPORT_UX1,
28 LINE6_TONEPORT_UX2,
29};
30
Takashi Iwaif44edd72015-01-20 09:36:31 +010031struct usb_line6_toneport;
32
33struct toneport_led {
34 struct led_classdev dev;
35 char name[64];
36 struct usb_line6_toneport *toneport;
37 bool registered;
38};
39
Takashi Iwaiccddbe42015-01-15 08:22:31 +010040struct usb_line6_toneport {
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010041 /* Generic Line 6 USB data */
Takashi Iwaiccddbe42015-01-15 08:22:31 +010042 struct usb_line6 line6;
43
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010044 /* Source selector */
Takashi Iwaiccddbe42015-01-15 08:22:31 +010045 int source;
46
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010047 /* Serial number of device */
Chris Rorvick12b00152015-02-10 23:03:16 -060048 u32 serial_number;
Takashi Iwaiccddbe42015-01-15 08:22:31 +010049
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010050 /* Firmware version (x 100) */
Chris Rorvick0e806152015-02-10 23:03:17 -060051 u8 firmware_version;
Takashi Iwaiccddbe42015-01-15 08:22:31 +010052
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010053 /* Device type */
Takashi Iwaiccddbe42015-01-15 08:22:31 +010054 enum line6_device_type type;
Takashi Iwaif44edd72015-01-20 09:36:31 +010055
56 /* LED instances */
57 struct toneport_led leds[2];
Takashi Iwaiccddbe42015-01-15 08:22:31 +010058};
Markus Grabner705ecec2009-02-27 19:43:04 -080059
Takashi Iwaif23a09ee2019-05-28 09:05:31 +020060#define line6_to_toneport(x) container_of(x, struct usb_line6_toneport, line6)
61
Markus Grabner705ecec2009-02-27 19:43:04 -080062static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2);
63
Markus Grabner1027f472010-08-12 01:35:30 +020064#define TONEPORT_PCM_DELAY 1
65
Takashi Iwai37cc3062020-01-03 09:17:06 +010066static const struct snd_ratden toneport_ratden = {
Markus Grabner705ecec2009-02-27 19:43:04 -080067 .num_min = 44100,
68 .num_max = 44100,
69 .num_step = 1,
70 .den = 1
71};
72
73static struct line6_pcm_properties toneport_pcm_properties = {
Takashi Iwai1263f612015-01-28 15:08:59 +010074 .playback_hw = {
Markus Grabnere1a164d2010-08-23 01:08:25 +020075 .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 |
Markus Grabnere1a164d2010-08-23 01:08:25 +020080 SNDRV_PCM_INFO_SYNC_START),
81 .formats = SNDRV_PCM_FMTBIT_S16_LE,
82 .rates = SNDRV_PCM_RATE_KNOT,
83 .rate_min = 44100,
84 .rate_max = 44100,
85 .channels_min = 2,
86 .channels_max = 2,
87 .buffer_bytes_max = 60000,
88 .period_bytes_min = 64,
89 .period_bytes_max = 8192,
90 .periods_min = 1,
91 .periods_max = 1024},
Takashi Iwai1263f612015-01-28 15:08:59 +010092 .capture_hw = {
Markus Grabnere1a164d2010-08-23 01:08:25 +020093 .info = (SNDRV_PCM_INFO_MMAP |
94 SNDRV_PCM_INFO_INTERLEAVED |
95 SNDRV_PCM_INFO_BLOCK_TRANSFER |
96 SNDRV_PCM_INFO_MMAP_VALID |
Markus Grabnere1a164d2010-08-23 01:08:25 +020097 SNDRV_PCM_INFO_SYNC_START),
98 .formats = SNDRV_PCM_FMTBIT_S16_LE,
99 .rates = SNDRV_PCM_RATE_KNOT,
100 .rate_min = 44100,
101 .rate_max = 44100,
102 .channels_min = 2,
103 .channels_max = 2,
104 .buffer_bytes_max = 60000,
105 .period_bytes_min = 64,
106 .period_bytes_max = 8192,
107 .periods_min = 1,
108 .periods_max = 1024},
Takashi Iwai1263f612015-01-28 15:08:59 +0100109 .rates = {
Markus Grabnere1a164d2010-08-23 01:08:25 +0200110 .nrats = 1,
111 .rats = &toneport_ratden},
Andrej Krutak97d78ac2016-09-18 20:59:24 +0200112 .bytes_per_channel = 2
Markus Grabner705ecec2009-02-27 19:43:04 -0800113};
114
Stefan Hajnoczi709b2fa2013-01-11 23:08:13 +0100115static const struct {
Markus Grabner1027f472010-08-12 01:35:30 +0200116 const char *name;
117 int code;
Stefan Hajnoczi709b2fa2013-01-11 23:08:13 +0100118} toneport_source_info[] = {
Markus Grabnere1a164d2010-08-23 01:08:25 +0200119 {"Microphone", 0x0a01},
120 {"Line", 0x0801},
121 {"Instrument", 0x0b01},
122 {"Inst & Mic", 0x0901}
Markus Grabner1027f472010-08-12 01:35:30 +0200123};
124
Markus Grabner705ecec2009-02-27 19:43:04 -0800125static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2)
126{
127 int ret;
Markus Grabner705ecec2009-02-27 19:43:04 -0800128
Greg Kroah-Hartman6d2d4272020-09-23 15:43:46 +0200129 ret = usb_control_msg_send(usbdev, 0, 0x67,
130 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
131 cmd1, cmd2, NULL, 0, LINE6_TIMEOUT * HZ,
132 GFP_KERNEL);
Greg Kroah-Hartman63537732009-02-27 22:43:45 -0800133
Greg Kroah-Hartman6d2d4272020-09-23 15:43:46 +0200134 if (ret) {
Greg Kroah-Hartmand86938f2012-04-20 16:53:32 -0700135 dev_err(&usbdev->dev, "send failed (error %d)\n", ret);
Markus Grabner705ecec2009-02-27 19:43:04 -0800136 return ret;
137 }
138
139 return 0;
140}
141
Markus Grabner1027f472010-08-12 01:35:30 +0200142/* monitor info callback */
143static int snd_toneport_monitor_info(struct snd_kcontrol *kcontrol,
144 struct snd_ctl_elem_info *uinfo)
145{
146 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
147 uinfo->count = 1;
148 uinfo->value.integer.min = 0;
149 uinfo->value.integer.max = 256;
150 return 0;
151}
152
153/* monitor get callback */
154static int snd_toneport_monitor_get(struct snd_kcontrol *kcontrol,
155 struct snd_ctl_elem_value *ucontrol)
156{
157 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
Jerry Snitselaarf3c52612014-04-24 00:31:48 -0700158
Markus Grabner1027f472010-08-12 01:35:30 +0200159 ucontrol->value.integer.value[0] = line6pcm->volume_monitor;
160 return 0;
161}
162
163/* monitor put callback */
164static int snd_toneport_monitor_put(struct snd_kcontrol *kcontrol,
165 struct snd_ctl_elem_value *ucontrol)
166{
167 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
Takashi Iwai247d95e2015-01-27 16:42:14 +0100168 int err;
Markus Grabner1027f472010-08-12 01:35:30 +0200169
Markus Grabnere1a164d2010-08-23 01:08:25 +0200170 if (ucontrol->value.integer.value[0] == line6pcm->volume_monitor)
Markus Grabner1027f472010-08-12 01:35:30 +0200171 return 0;
172
173 line6pcm->volume_monitor = ucontrol->value.integer.value[0];
Markus Grabnere1a164d2010-08-23 01:08:25 +0200174
Takashi Iwai247d95e2015-01-27 16:42:14 +0100175 if (line6pcm->volume_monitor > 0) {
Andrej Krutakf56742c2016-09-18 20:59:25 +0200176 err = line6_pcm_acquire(line6pcm, LINE6_STREAM_MONITOR, true);
Takashi Iwai247d95e2015-01-27 16:42:14 +0100177 if (err < 0) {
178 line6pcm->volume_monitor = 0;
179 line6_pcm_release(line6pcm, LINE6_STREAM_MONITOR);
180 return err;
181 }
182 } else {
Takashi Iwai63e20df2015-01-27 15:24:09 +0100183 line6_pcm_release(line6pcm, LINE6_STREAM_MONITOR);
Takashi Iwai247d95e2015-01-27 16:42:14 +0100184 }
Markus Grabnere1a164d2010-08-23 01:08:25 +0200185
Markus Grabner1027f472010-08-12 01:35:30 +0200186 return 1;
187}
188
189/* source info callback */
190static int snd_toneport_source_info(struct snd_kcontrol *kcontrol,
191 struct snd_ctl_elem_info *uinfo)
192{
193 const int size = ARRAY_SIZE(toneport_source_info);
Fabian Mewesa6b46992014-03-24 23:46:31 +0100194
Markus Grabner1027f472010-08-12 01:35:30 +0200195 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
196 uinfo->count = 1;
197 uinfo->value.enumerated.items = size;
198
Markus Grabnere1a164d2010-08-23 01:08:25 +0200199 if (uinfo->value.enumerated.item >= size)
Markus Grabner1027f472010-08-12 01:35:30 +0200200 uinfo->value.enumerated.item = size - 1;
201
202 strcpy(uinfo->value.enumerated.name,
203 toneport_source_info[uinfo->value.enumerated.item].name);
204
205 return 0;
206}
207
208/* source get callback */
209static int snd_toneport_source_get(struct snd_kcontrol *kcontrol,
210 struct snd_ctl_elem_value *ucontrol)
211{
212 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
Takashi Iwaif23a09ee2019-05-28 09:05:31 +0200213 struct usb_line6_toneport *toneport = line6_to_toneport(line6pcm->line6);
214
Markus Grabner1027f472010-08-12 01:35:30 +0200215 ucontrol->value.enumerated.item[0] = toneport->source;
216 return 0;
217}
218
219/* source put callback */
220static int snd_toneport_source_put(struct snd_kcontrol *kcontrol,
221 struct snd_ctl_elem_value *ucontrol)
222{
223 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
Takashi Iwaif23a09ee2019-05-28 09:05:31 +0200224 struct usb_line6_toneport *toneport = line6_to_toneport(line6pcm->line6);
Dan Carpenterc3cb7182013-09-13 11:07:13 +0300225 unsigned int source;
Markus Grabner1027f472010-08-12 01:35:30 +0200226
Dan Carpenterc3cb7182013-09-13 11:07:13 +0300227 source = ucontrol->value.enumerated.item[0];
228 if (source >= ARRAY_SIZE(toneport_source_info))
229 return -EINVAL;
230 if (source == toneport->source)
Markus Grabner1027f472010-08-12 01:35:30 +0200231 return 0;
232
Dan Carpenterc3cb7182013-09-13 11:07:13 +0300233 toneport->source = source;
Markus Grabnere1a164d2010-08-23 01:08:25 +0200234 toneport_send_cmd(toneport->line6.usbdev,
Dan Carpenterc3cb7182013-09-13 11:07:13 +0300235 toneport_source_info[source].code, 0x0000);
Markus Grabner1027f472010-08-12 01:35:30 +0200236 return 1;
237}
238
Takashi Iwai0b074ab2019-05-28 08:39:44 +0200239static void toneport_startup(struct usb_line6 *line6)
Markus Grabner1027f472010-08-12 01:35:30 +0200240{
Andrej Krutakf56742c2016-09-18 20:59:25 +0200241 line6_pcm_acquire(line6->line6pcm, LINE6_STREAM_MONITOR, true);
Markus Grabner1027f472010-08-12 01:35:30 +0200242}
243
244/* control definition */
Bhumika Goyal49c41e12017-04-12 18:40:47 +0530245static const struct snd_kcontrol_new toneport_control_monitor = {
Markus Grabner1027f472010-08-12 01:35:30 +0200246 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
247 .name = "Monitor Playback Volume",
248 .index = 0,
249 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
250 .info = snd_toneport_monitor_info,
251 .get = snd_toneport_monitor_get,
252 .put = snd_toneport_monitor_put
253};
254
255/* source selector definition */
Bhumika Goyal49c41e12017-04-12 18:40:47 +0530256static const struct snd_kcontrol_new toneport_control_source = {
Markus Grabner1027f472010-08-12 01:35:30 +0200257 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
258 .name = "PCM Capture Source",
259 .index = 0,
260 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
261 .info = snd_toneport_source_info,
262 .get = snd_toneport_source_get,
263 .put = snd_toneport_source_put
264};
265
Markus Grabner705ecec2009-02-27 19:43:04 -0800266/*
Takashi Iwaif44edd72015-01-20 09:36:31 +0100267 For the led on Guitarport.
268 Brightness goes from 0x00 to 0x26. Set a value above this to have led
269 blink.
270 (void cmd_0x02(byte red, byte green)
271*/
272
Chris Rorvickf2bd2422015-02-07 10:43:18 -0600273static bool toneport_has_led(struct usb_line6_toneport *toneport)
Takashi Iwaif44edd72015-01-20 09:36:31 +0100274{
Chris Rorvickf2bd2422015-02-07 10:43:18 -0600275 switch (toneport->type) {
276 case LINE6_GUITARPORT:
277 case LINE6_TONEPORT_GX:
Takashi Iwaif44edd72015-01-20 09:36:31 +0100278 /* add your device here if you are missing support for the LEDs */
Chris Rorvickf2bd2422015-02-07 10:43:18 -0600279 return true;
280
281 default:
282 return false;
283 }
Takashi Iwaif44edd72015-01-20 09:36:31 +0100284}
285
Jacek Anaszewski05b8ccf2019-04-06 19:04:44 +0200286static const char * const toneport_led_colors[2] = { "red", "green" };
287static const int toneport_led_init_vals[2] = { 0x00, 0x26 };
Takashi Iwaif44edd72015-01-20 09:36:31 +0100288
289static void toneport_update_led(struct usb_line6_toneport *toneport)
290{
291 toneport_send_cmd(toneport->line6.usbdev,
292 (toneport->leds[0].dev.brightness << 8) | 0x0002,
293 toneport->leds[1].dev.brightness);
294}
295
296static void toneport_led_brightness_set(struct led_classdev *led_cdev,
297 enum led_brightness brightness)
298{
299 struct toneport_led *leds =
300 container_of(led_cdev, struct toneport_led, dev);
301 toneport_update_led(leds->toneport);
302}
303
304static int toneport_init_leds(struct usb_line6_toneport *toneport)
305{
306 struct device *dev = &toneport->line6.usbdev->dev;
307 int i, err;
308
309 for (i = 0; i < 2; i++) {
310 struct toneport_led *led = &toneport->leds[i];
311 struct led_classdev *leddev = &led->dev;
312
313 led->toneport = toneport;
314 snprintf(led->name, sizeof(led->name), "%s::%s",
Jacek Anaszewski05b8ccf2019-04-06 19:04:44 +0200315 dev_name(dev), toneport_led_colors[i]);
Takashi Iwaif44edd72015-01-20 09:36:31 +0100316 leddev->name = led->name;
Jacek Anaszewski05b8ccf2019-04-06 19:04:44 +0200317 leddev->brightness = toneport_led_init_vals[i];
Takashi Iwaif44edd72015-01-20 09:36:31 +0100318 leddev->max_brightness = 0x26;
319 leddev->brightness_set = toneport_led_brightness_set;
320 err = led_classdev_register(dev, leddev);
321 if (err)
322 return err;
323 led->registered = true;
324 }
325
326 return 0;
327}
328
329static void toneport_remove_leds(struct usb_line6_toneport *toneport)
330{
331 struct toneport_led *led;
332 int i;
333
334 for (i = 0; i < 2; i++) {
335 led = &toneport->leds[i];
336 if (!led->registered)
337 break;
338 led_classdev_unregister(&led->dev);
339 led->registered = false;
340 }
341}
342
Chris Rorvick89444602015-02-07 10:43:17 -0600343static bool toneport_has_source_select(struct usb_line6_toneport *toneport)
344{
345 switch (toneport->type) {
346 case LINE6_TONEPORT_UX1:
347 case LINE6_TONEPORT_UX2:
348 case LINE6_PODSTUDIO_UX1:
349 case LINE6_PODSTUDIO_UX2:
350 return true;
351
352 default:
353 return false;
354 }
355}
356
Takashi Iwaif44edd72015-01-20 09:36:31 +0100357/*
Markus Grabner1027f472010-08-12 01:35:30 +0200358 Setup Toneport device.
Markus Grabner705ecec2009-02-27 19:43:04 -0800359*/
Greg Kroah-Hartmane5c812e2019-04-28 18:04:11 +0200360static int toneport_setup(struct usb_line6_toneport *toneport)
Markus Grabner705ecec2009-02-27 19:43:04 -0800361{
Greg Kroah-Hartmane5c812e2019-04-28 18:04:11 +0200362 u32 *ticks;
Markus Grabner705ecec2009-02-27 19:43:04 -0800363 struct usb_line6 *line6 = &toneport->line6;
Markus Grabner1027f472010-08-12 01:35:30 +0200364 struct usb_device *usbdev = line6->usbdev;
365
Greg Kroah-Hartmane5c812e2019-04-28 18:04:11 +0200366 ticks = kmalloc(sizeof(*ticks), GFP_KERNEL);
367 if (!ticks)
368 return -ENOMEM;
369
Markus Grabner1027f472010-08-12 01:35:30 +0200370 /* sync time on device with host: */
Arnd Bergmanna8eaad72018-06-18 17:41:01 +0200371 /* note: 32-bit timestamps overflow in year 2106 */
Greg Kroah-Hartmane5c812e2019-04-28 18:04:11 +0200372 *ticks = (u32)ktime_get_real_seconds();
373 line6_write_data(line6, 0x80c6, ticks, 4);
374 kfree(ticks);
Markus Grabner1027f472010-08-12 01:35:30 +0200375
376 /* enable device: */
377 toneport_send_cmd(usbdev, 0x0301, 0x0000);
378
379 /* initialize source select: */
Chris Rorvick89444602015-02-07 10:43:17 -0600380 if (toneport_has_source_select(toneport))
Markus Grabnere1a164d2010-08-23 01:08:25 +0200381 toneport_send_cmd(usbdev,
382 toneport_source_info[toneport->source].code,
383 0x0000);
Markus Grabner1027f472010-08-12 01:35:30 +0200384
Chris Rorvickf2bd2422015-02-07 10:43:18 -0600385 if (toneport_has_led(toneport))
Takashi Iwaif44edd72015-01-20 09:36:31 +0100386 toneport_update_led(toneport);
Takashi Iwai6dd1c052015-01-20 09:40:20 +0100387
Takashi Iwai0b074ab2019-05-28 08:39:44 +0200388 schedule_delayed_work(&toneport->line6.startup_work,
Takashi Iwai7f84ff62019-05-08 15:01:24 +0200389 msecs_to_jiffies(TONEPORT_PCM_DELAY * 1000));
Greg Kroah-Hartmane5c812e2019-04-28 18:04:11 +0200390 return 0;
Markus Grabner1027f472010-08-12 01:35:30 +0200391}
392
393/*
Chris Rorvickd29b8542015-01-12 12:43:00 -0800394 Toneport device disconnected.
395*/
Takashi Iwaif66fd992015-01-25 18:22:58 +0100396static void line6_toneport_disconnect(struct usb_line6 *line6)
Chris Rorvickd29b8542015-01-12 12:43:00 -0800397{
Takashi Iwaif23a09ee2019-05-28 09:05:31 +0200398 struct usb_line6_toneport *toneport = line6_to_toneport(line6);
Chris Rorvickd29b8542015-01-12 12:43:00 -0800399
Chris Rorvickf2bd2422015-02-07 10:43:18 -0600400 if (toneport_has_led(toneport))
Takashi Iwaif44edd72015-01-20 09:36:31 +0100401 toneport_remove_leds(toneport);
Chris Rorvickd29b8542015-01-12 12:43:00 -0800402}
403
404
405/*
Markus Grabner1027f472010-08-12 01:35:30 +0200406 Try to init Toneport device.
407*/
Takashi Iwaif66fd992015-01-25 18:22:58 +0100408static int toneport_init(struct usb_line6 *line6,
409 const struct usb_device_id *id)
Markus Grabner1027f472010-08-12 01:35:30 +0200410{
411 int err;
Takashi Iwaif23a09ee2019-05-28 09:05:31 +0200412 struct usb_line6_toneport *toneport = line6_to_toneport(line6);
Markus Grabner705ecec2009-02-27 19:43:04 -0800413
Takashi Iwaif66fd992015-01-25 18:22:58 +0100414 toneport->type = id->driver_info;
Takashi Iwai6dd1c052015-01-20 09:40:20 +0100415
Chris Rorvicka46c4672015-01-12 12:42:59 -0800416 line6->disconnect = line6_toneport_disconnect;
Takashi Iwai0b074ab2019-05-28 08:39:44 +0200417 line6->startup = toneport_startup;
Chris Rorvicka46c4672015-01-12 12:42:59 -0800418
Markus Grabner705ecec2009-02-27 19:43:04 -0800419 /* initialize PCM subsystem: */
Greg Kroah-Hartman63537732009-02-27 22:43:45 -0800420 err = line6_init_pcm(line6, &toneport_pcm_properties);
Greg Kroah-Hartman027360c2010-09-21 16:58:00 -0700421 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800422 return err;
Markus Grabner705ecec2009-02-27 19:43:04 -0800423
Markus Grabner1027f472010-08-12 01:35:30 +0200424 /* register monitor control: */
Greg Kroah-Hartman027360c2010-09-21 16:58:00 -0700425 err = snd_ctl_add(line6->card,
426 snd_ctl_new1(&toneport_control_monitor,
427 line6->line6pcm));
428 if (err < 0)
Markus Grabner1027f472010-08-12 01:35:30 +0200429 return err;
Markus Grabner1027f472010-08-12 01:35:30 +0200430
431 /* register source select control: */
Chris Rorvick89444602015-02-07 10:43:17 -0600432 if (toneport_has_source_select(toneport)) {
Markus Grabnere1a164d2010-08-23 01:08:25 +0200433 err =
434 snd_ctl_add(line6->card,
435 snd_ctl_new1(&toneport_control_source,
436 line6->line6pcm));
Greg Kroah-Hartman027360c2010-09-21 16:58:00 -0700437 if (err < 0)
Markus Grabner1027f472010-08-12 01:35:30 +0200438 return err;
Markus Grabner1027f472010-08-12 01:35:30 +0200439 }
440
Markus Grabner705ecec2009-02-27 19:43:04 -0800441 line6_read_serial_number(line6, &toneport->serial_number);
442 line6_read_data(line6, 0x80c2, &toneport->firmware_version, 1);
443
Chris Rorvickf2bd2422015-02-07 10:43:18 -0600444 if (toneport_has_led(toneport)) {
Takashi Iwaif44edd72015-01-20 09:36:31 +0100445 err = toneport_init_leds(toneport);
Takashi Iwaib2a3b022015-01-19 16:08:02 +0100446 if (err < 0)
447 return err;
Markus Grabner705ecec2009-02-27 19:43:04 -0800448 }
449
Greg Kroah-Hartmane5c812e2019-04-28 18:04:11 +0200450 err = toneport_setup(toneport);
451 if (err)
452 return err;
Markus Grabner1027f472010-08-12 01:35:30 +0200453
Takashi Iwai85a93392015-01-19 15:54:00 +0100454 /* register audio system: */
455 return snd_card_register(line6->card);
Markus Grabner1027f472010-08-12 01:35:30 +0200456}
457
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100458#ifdef CONFIG_PM
Markus Grabner1027f472010-08-12 01:35:30 +0200459/*
460 Resume Toneport device after reset.
461*/
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100462static int toneport_reset_resume(struct usb_interface *interface)
Markus Grabner1027f472010-08-12 01:35:30 +0200463{
Greg Kroah-Hartmane5c812e2019-04-28 18:04:11 +0200464 int err;
465
466 err = toneport_setup(usb_get_intfdata(interface));
467 if (err)
468 return err;
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100469 return line6_resume(interface);
Markus Grabner1027f472010-08-12 01:35:30 +0200470}
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100471#endif
472
473#define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
474#define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
475
476/* table of devices that work with this driver */
477static const struct usb_device_id toneport_id_table[] = {
478 { LINE6_DEVICE(0x4750), .driver_info = LINE6_GUITARPORT },
479 { LINE6_DEVICE(0x4153), .driver_info = LINE6_PODSTUDIO_GX },
480 { LINE6_DEVICE(0x4150), .driver_info = LINE6_PODSTUDIO_UX1 },
481 { LINE6_IF_NUM(0x4151, 0), .driver_info = LINE6_PODSTUDIO_UX2 },
482 { LINE6_DEVICE(0x4147), .driver_info = LINE6_TONEPORT_GX },
483 { LINE6_DEVICE(0x4141), .driver_info = LINE6_TONEPORT_UX1 },
484 { LINE6_IF_NUM(0x4142, 0), .driver_info = LINE6_TONEPORT_UX2 },
485 {}
486};
487
488MODULE_DEVICE_TABLE(usb, toneport_id_table);
489
490static const struct line6_properties toneport_properties_table[] = {
491 [LINE6_GUITARPORT] = {
492 .id = "GuitarPort",
493 .name = "GuitarPort",
494 .capabilities = LINE6_CAP_PCM,
495 .altsetting = 2, /* 1..4 seem to be ok */
496 /* no control channel */
497 .ep_audio_r = 0x82,
498 .ep_audio_w = 0x01,
499 },
500 [LINE6_PODSTUDIO_GX] = {
501 .id = "PODStudioGX",
502 .name = "POD Studio GX",
503 .capabilities = LINE6_CAP_PCM,
504 .altsetting = 2, /* 1..4 seem to be ok */
505 /* no control channel */
506 .ep_audio_r = 0x82,
507 .ep_audio_w = 0x01,
508 },
509 [LINE6_PODSTUDIO_UX1] = {
510 .id = "PODStudioUX1",
511 .name = "POD Studio UX1",
512 .capabilities = LINE6_CAP_PCM,
513 .altsetting = 2, /* 1..4 seem to be ok */
514 /* no control channel */
515 .ep_audio_r = 0x82,
516 .ep_audio_w = 0x01,
517 },
518 [LINE6_PODSTUDIO_UX2] = {
519 .id = "PODStudioUX2",
520 .name = "POD Studio UX2",
521 .capabilities = LINE6_CAP_PCM,
522 .altsetting = 2, /* defaults to 44.1kHz, 16-bit */
523 /* no control channel */
524 .ep_audio_r = 0x82,
525 .ep_audio_w = 0x01,
526 },
527 [LINE6_TONEPORT_GX] = {
528 .id = "TonePortGX",
529 .name = "TonePort GX",
530 .capabilities = LINE6_CAP_PCM,
531 .altsetting = 2, /* 1..4 seem to be ok */
532 /* no control channel */
533 .ep_audio_r = 0x82,
534 .ep_audio_w = 0x01,
535 },
536 [LINE6_TONEPORT_UX1] = {
537 .id = "TonePortUX1",
538 .name = "TonePort UX1",
539 .capabilities = LINE6_CAP_PCM,
540 .altsetting = 2, /* 1..4 seem to be ok */
541 /* no control channel */
542 .ep_audio_r = 0x82,
543 .ep_audio_w = 0x01,
544 },
545 [LINE6_TONEPORT_UX2] = {
546 .id = "TonePortUX2",
547 .name = "TonePort UX2",
548 .capabilities = LINE6_CAP_PCM,
549 .altsetting = 2, /* defaults to 44.1kHz, 16-bit */
550 /* no control channel */
551 .ep_audio_r = 0x82,
552 .ep_audio_w = 0x01,
553 },
554};
555
556/*
557 Probe USB device.
558*/
559static int toneport_probe(struct usb_interface *interface,
560 const struct usb_device_id *id)
561{
Chris Rorvick12865ca2015-02-07 10:43:19 -0600562 return line6_probe(interface, id, "Line6-TonePort",
Takashi Iwai85a93392015-01-19 15:54:00 +0100563 &toneport_properties_table[id->driver_info],
Takashi Iwaiaca514b2015-01-25 18:36:29 +0100564 toneport_init, sizeof(struct usb_line6_toneport));
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100565}
566
567static struct usb_driver toneport_driver = {
568 .name = KBUILD_MODNAME,
569 .probe = toneport_probe,
570 .disconnect = line6_disconnect,
571#ifdef CONFIG_PM
572 .suspend = line6_suspend,
573 .resume = line6_resume,
574 .reset_resume = toneport_reset_resume,
575#endif
576 .id_table = toneport_id_table,
577};
578
579module_usb_driver(toneport_driver);
580
581MODULE_DESCRIPTION("TonePort USB driver");
582MODULE_LICENSE("GPL");