1a10e763bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
261864d84STakashi Iwai /*
3c078a4aaSChris Rorvick * Line 6 Linux USB driver
461864d84STakashi Iwai *
561864d84STakashi Iwai * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
661864d84STakashi Iwai * Emil Myhrman (emil.myhrman@gmail.com)
761864d84STakashi Iwai */
861864d84STakashi Iwai
961864d84STakashi Iwai #include <linux/wait.h>
10ccddbe4aSTakashi Iwai #include <linux/usb.h>
11ccddbe4aSTakashi Iwai #include <linux/slab.h>
12ccddbe4aSTakashi Iwai #include <linux/module.h>
13f44edd7bSTakashi Iwai #include <linux/leds.h>
14ccddbe4aSTakashi Iwai #include <sound/core.h>
1561864d84STakashi Iwai #include <sound/control.h>
1661864d84STakashi Iwai
1761864d84STakashi Iwai #include "capture.h"
1861864d84STakashi Iwai #include "driver.h"
1961864d84STakashi Iwai #include "playback.h"
20ccddbe4aSTakashi Iwai
21ccddbe4aSTakashi Iwai enum line6_device_type {
22ccddbe4aSTakashi Iwai LINE6_GUITARPORT,
23ccddbe4aSTakashi Iwai LINE6_PODSTUDIO_GX,
24ccddbe4aSTakashi Iwai LINE6_PODSTUDIO_UX1,
25ccddbe4aSTakashi Iwai LINE6_PODSTUDIO_UX2,
26ccddbe4aSTakashi Iwai LINE6_TONEPORT_GX,
27ccddbe4aSTakashi Iwai LINE6_TONEPORT_UX1,
28ccddbe4aSTakashi Iwai LINE6_TONEPORT_UX2,
29ccddbe4aSTakashi Iwai };
30ccddbe4aSTakashi Iwai
31f44edd7bSTakashi Iwai struct usb_line6_toneport;
32f44edd7bSTakashi Iwai
33f44edd7bSTakashi Iwai struct toneport_led {
34f44edd7bSTakashi Iwai struct led_classdev dev;
35f44edd7bSTakashi Iwai char name[64];
36f44edd7bSTakashi Iwai struct usb_line6_toneport *toneport;
37f44edd7bSTakashi Iwai bool registered;
38f44edd7bSTakashi Iwai };
39f44edd7bSTakashi Iwai
40ccddbe4aSTakashi Iwai struct usb_line6_toneport {
41cddbd4f1STakashi Iwai /* Generic Line 6 USB data */
42ccddbe4aSTakashi Iwai struct usb_line6 line6;
43ccddbe4aSTakashi Iwai
44cddbd4f1STakashi Iwai /* Source selector */
45ccddbe4aSTakashi Iwai int source;
46ccddbe4aSTakashi Iwai
47cddbd4f1STakashi Iwai /* Serial number of device */
4812b00157SChris Rorvick u32 serial_number;
49ccddbe4aSTakashi Iwai
50cddbd4f1STakashi Iwai /* Firmware version (x 100) */
510e806151SChris Rorvick u8 firmware_version;
52ccddbe4aSTakashi Iwai
53cddbd4f1STakashi Iwai /* Device type */
54ccddbe4aSTakashi Iwai enum line6_device_type type;
55f44edd7bSTakashi Iwai
56f44edd7bSTakashi Iwai /* LED instances */
57f44edd7bSTakashi Iwai struct toneport_led leds[2];
58ccddbe4aSTakashi Iwai };
5961864d84STakashi Iwai
60f23a09eeSTakashi Iwai #define line6_to_toneport(x) container_of(x, struct usb_line6_toneport, line6)
61f23a09eeSTakashi Iwai
6261864d84STakashi Iwai static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2);
6361864d84STakashi Iwai
6461864d84STakashi Iwai #define TONEPORT_PCM_DELAY 1
6561864d84STakashi Iwai
6637cc306bSTakashi Iwai static const struct snd_ratden toneport_ratden = {
6761864d84STakashi Iwai .num_min = 44100,
6861864d84STakashi Iwai .num_max = 44100,
6961864d84STakashi Iwai .num_step = 1,
7061864d84STakashi Iwai .den = 1
7161864d84STakashi Iwai };
7261864d84STakashi Iwai
7361864d84STakashi Iwai static struct line6_pcm_properties toneport_pcm_properties = {
741263f611STakashi Iwai .playback_hw = {
7561864d84STakashi Iwai .info = (SNDRV_PCM_INFO_MMAP |
7661864d84STakashi Iwai SNDRV_PCM_INFO_INTERLEAVED |
7761864d84STakashi Iwai SNDRV_PCM_INFO_BLOCK_TRANSFER |
7861864d84STakashi Iwai SNDRV_PCM_INFO_MMAP_VALID |
7961864d84STakashi Iwai SNDRV_PCM_INFO_PAUSE |
8061864d84STakashi Iwai SNDRV_PCM_INFO_SYNC_START),
8161864d84STakashi Iwai .formats = SNDRV_PCM_FMTBIT_S16_LE,
8261864d84STakashi Iwai .rates = SNDRV_PCM_RATE_KNOT,
8361864d84STakashi Iwai .rate_min = 44100,
8461864d84STakashi Iwai .rate_max = 44100,
8561864d84STakashi Iwai .channels_min = 2,
8661864d84STakashi Iwai .channels_max = 2,
8761864d84STakashi Iwai .buffer_bytes_max = 60000,
8861864d84STakashi Iwai .period_bytes_min = 64,
8961864d84STakashi Iwai .period_bytes_max = 8192,
9061864d84STakashi Iwai .periods_min = 1,
9161864d84STakashi Iwai .periods_max = 1024},
921263f611STakashi Iwai .capture_hw = {
9361864d84STakashi Iwai .info = (SNDRV_PCM_INFO_MMAP |
9461864d84STakashi Iwai SNDRV_PCM_INFO_INTERLEAVED |
9561864d84STakashi Iwai SNDRV_PCM_INFO_BLOCK_TRANSFER |
9661864d84STakashi Iwai SNDRV_PCM_INFO_MMAP_VALID |
9761864d84STakashi Iwai SNDRV_PCM_INFO_SYNC_START),
9861864d84STakashi Iwai .formats = SNDRV_PCM_FMTBIT_S16_LE,
9961864d84STakashi Iwai .rates = SNDRV_PCM_RATE_KNOT,
10061864d84STakashi Iwai .rate_min = 44100,
10161864d84STakashi Iwai .rate_max = 44100,
10261864d84STakashi Iwai .channels_min = 2,
10361864d84STakashi Iwai .channels_max = 2,
10461864d84STakashi Iwai .buffer_bytes_max = 60000,
10561864d84STakashi Iwai .period_bytes_min = 64,
10661864d84STakashi Iwai .period_bytes_max = 8192,
10761864d84STakashi Iwai .periods_min = 1,
10861864d84STakashi Iwai .periods_max = 1024},
1091263f611STakashi Iwai .rates = {
11061864d84STakashi Iwai .nrats = 1,
11161864d84STakashi Iwai .rats = &toneport_ratden},
11297d78acfSAndrej Krutak .bytes_per_channel = 2
11361864d84STakashi Iwai };
11461864d84STakashi Iwai
11561864d84STakashi Iwai static const struct {
11661864d84STakashi Iwai const char *name;
11761864d84STakashi Iwai int code;
11861864d84STakashi Iwai } toneport_source_info[] = {
11961864d84STakashi Iwai {"Microphone", 0x0a01},
12061864d84STakashi Iwai {"Line", 0x0801},
12161864d84STakashi Iwai {"Instrument", 0x0b01},
12261864d84STakashi Iwai {"Inst & Mic", 0x0901}
12361864d84STakashi Iwai };
12461864d84STakashi Iwai
toneport_send_cmd(struct usb_device * usbdev,int cmd1,int cmd2)12561864d84STakashi Iwai static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2)
12661864d84STakashi Iwai {
12761864d84STakashi Iwai int ret;
12861864d84STakashi Iwai
1296d2d427eSGreg Kroah-Hartman ret = usb_control_msg_send(usbdev, 0, 0x67,
13061864d84STakashi Iwai USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
131*f4000b58SJohan Hovold cmd1, cmd2, NULL, 0, LINE6_TIMEOUT,
1326d2d427eSGreg Kroah-Hartman GFP_KERNEL);
13361864d84STakashi Iwai
1346d2d427eSGreg Kroah-Hartman if (ret) {
13561864d84STakashi Iwai dev_err(&usbdev->dev, "send failed (error %d)\n", ret);
13661864d84STakashi Iwai return ret;
13761864d84STakashi Iwai }
13861864d84STakashi Iwai
13961864d84STakashi Iwai return 0;
14061864d84STakashi Iwai }
14161864d84STakashi Iwai
14261864d84STakashi Iwai /* monitor info callback */
snd_toneport_monitor_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)14361864d84STakashi Iwai static int snd_toneport_monitor_info(struct snd_kcontrol *kcontrol,
14461864d84STakashi Iwai struct snd_ctl_elem_info *uinfo)
14561864d84STakashi Iwai {
14661864d84STakashi Iwai uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
14761864d84STakashi Iwai uinfo->count = 1;
14861864d84STakashi Iwai uinfo->value.integer.min = 0;
14961864d84STakashi Iwai uinfo->value.integer.max = 256;
15061864d84STakashi Iwai return 0;
15161864d84STakashi Iwai }
15261864d84STakashi Iwai
15361864d84STakashi Iwai /* monitor get callback */
snd_toneport_monitor_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)15461864d84STakashi Iwai static int snd_toneport_monitor_get(struct snd_kcontrol *kcontrol,
15561864d84STakashi Iwai struct snd_ctl_elem_value *ucontrol)
15661864d84STakashi Iwai {
15761864d84STakashi Iwai struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
15861864d84STakashi Iwai
15961864d84STakashi Iwai ucontrol->value.integer.value[0] = line6pcm->volume_monitor;
16061864d84STakashi Iwai return 0;
16161864d84STakashi Iwai }
16261864d84STakashi Iwai
16361864d84STakashi Iwai /* monitor put callback */
snd_toneport_monitor_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)16461864d84STakashi Iwai static int snd_toneport_monitor_put(struct snd_kcontrol *kcontrol,
16561864d84STakashi Iwai struct snd_ctl_elem_value *ucontrol)
16661864d84STakashi Iwai {
16761864d84STakashi Iwai struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
168247d95eeSTakashi Iwai int err;
16961864d84STakashi Iwai
17061864d84STakashi Iwai if (ucontrol->value.integer.value[0] == line6pcm->volume_monitor)
17161864d84STakashi Iwai return 0;
17261864d84STakashi Iwai
17361864d84STakashi Iwai line6pcm->volume_monitor = ucontrol->value.integer.value[0];
17461864d84STakashi Iwai
175247d95eeSTakashi Iwai if (line6pcm->volume_monitor > 0) {
176f56742ccSAndrej Krutak err = line6_pcm_acquire(line6pcm, LINE6_STREAM_MONITOR, true);
177247d95eeSTakashi Iwai if (err < 0) {
178247d95eeSTakashi Iwai line6pcm->volume_monitor = 0;
17963e20df1STakashi Iwai line6_pcm_release(line6pcm, LINE6_STREAM_MONITOR);
180247d95eeSTakashi Iwai return err;
181247d95eeSTakashi Iwai }
182247d95eeSTakashi Iwai } else {
183247d95eeSTakashi Iwai line6_pcm_release(line6pcm, LINE6_STREAM_MONITOR);
184247d95eeSTakashi Iwai }
18561864d84STakashi Iwai
18661864d84STakashi Iwai return 1;
18761864d84STakashi Iwai }
18861864d84STakashi Iwai
18961864d84STakashi Iwai /* source info callback */
snd_toneport_source_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)19061864d84STakashi Iwai static int snd_toneport_source_info(struct snd_kcontrol *kcontrol,
19161864d84STakashi Iwai struct snd_ctl_elem_info *uinfo)
19261864d84STakashi Iwai {
19361864d84STakashi Iwai const int size = ARRAY_SIZE(toneport_source_info);
19461864d84STakashi Iwai
19561864d84STakashi Iwai uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
19661864d84STakashi Iwai uinfo->count = 1;
19761864d84STakashi Iwai uinfo->value.enumerated.items = size;
19861864d84STakashi Iwai
19961864d84STakashi Iwai if (uinfo->value.enumerated.item >= size)
20061864d84STakashi Iwai uinfo->value.enumerated.item = size - 1;
20161864d84STakashi Iwai
20261864d84STakashi Iwai strcpy(uinfo->value.enumerated.name,
20361864d84STakashi Iwai toneport_source_info[uinfo->value.enumerated.item].name);
20461864d84STakashi Iwai
20561864d84STakashi Iwai return 0;
20661864d84STakashi Iwai }
20761864d84STakashi Iwai
20861864d84STakashi Iwai /* source get callback */
snd_toneport_source_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)20961864d84STakashi Iwai static int snd_toneport_source_get(struct snd_kcontrol *kcontrol,
21061864d84STakashi Iwai struct snd_ctl_elem_value *ucontrol)
21161864d84STakashi Iwai {
21261864d84STakashi Iwai struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
213f23a09eeSTakashi Iwai struct usb_line6_toneport *toneport = line6_to_toneport(line6pcm->line6);
214f23a09eeSTakashi Iwai
21561864d84STakashi Iwai ucontrol->value.enumerated.item[0] = toneport->source;
21661864d84STakashi Iwai return 0;
21761864d84STakashi Iwai }
21861864d84STakashi Iwai
21961864d84STakashi Iwai /* source put callback */
snd_toneport_source_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)22061864d84STakashi Iwai static int snd_toneport_source_put(struct snd_kcontrol *kcontrol,
22161864d84STakashi Iwai struct snd_ctl_elem_value *ucontrol)
22261864d84STakashi Iwai {
22361864d84STakashi Iwai struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
224f23a09eeSTakashi Iwai struct usb_line6_toneport *toneport = line6_to_toneport(line6pcm->line6);
22561864d84STakashi Iwai unsigned int source;
22661864d84STakashi Iwai
22761864d84STakashi Iwai source = ucontrol->value.enumerated.item[0];
22861864d84STakashi Iwai if (source >= ARRAY_SIZE(toneport_source_info))
22961864d84STakashi Iwai return -EINVAL;
23061864d84STakashi Iwai if (source == toneport->source)
23161864d84STakashi Iwai return 0;
23261864d84STakashi Iwai
23361864d84STakashi Iwai toneport->source = source;
23461864d84STakashi Iwai toneport_send_cmd(toneport->line6.usbdev,
23561864d84STakashi Iwai toneport_source_info[source].code, 0x0000);
23661864d84STakashi Iwai return 1;
23761864d84STakashi Iwai }
23861864d84STakashi Iwai
toneport_startup(struct usb_line6 * line6)2390b074ab7STakashi Iwai static void toneport_startup(struct usb_line6 *line6)
24061864d84STakashi Iwai {
241f56742ccSAndrej Krutak line6_pcm_acquire(line6->line6pcm, LINE6_STREAM_MONITOR, true);
24261864d84STakashi Iwai }
24361864d84STakashi Iwai
24461864d84STakashi Iwai /* control definition */
24549c41e1fSBhumika Goyal static const struct snd_kcontrol_new toneport_control_monitor = {
24661864d84STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
24761864d84STakashi Iwai .name = "Monitor Playback Volume",
24861864d84STakashi Iwai .index = 0,
24961864d84STakashi Iwai .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
25061864d84STakashi Iwai .info = snd_toneport_monitor_info,
25161864d84STakashi Iwai .get = snd_toneport_monitor_get,
25261864d84STakashi Iwai .put = snd_toneport_monitor_put
25361864d84STakashi Iwai };
25461864d84STakashi Iwai
25561864d84STakashi Iwai /* source selector definition */
25649c41e1fSBhumika Goyal static const struct snd_kcontrol_new toneport_control_source = {
25761864d84STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
25861864d84STakashi Iwai .name = "PCM Capture Source",
25961864d84STakashi Iwai .index = 0,
26061864d84STakashi Iwai .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
26161864d84STakashi Iwai .info = snd_toneport_source_info,
26261864d84STakashi Iwai .get = snd_toneport_source_get,
26361864d84STakashi Iwai .put = snd_toneport_source_put
26461864d84STakashi Iwai };
26561864d84STakashi Iwai
26661864d84STakashi Iwai /*
267f44edd7bSTakashi Iwai For the led on Guitarport.
268f44edd7bSTakashi Iwai Brightness goes from 0x00 to 0x26. Set a value above this to have led
269f44edd7bSTakashi Iwai blink.
270f44edd7bSTakashi Iwai (void cmd_0x02(byte red, byte green)
271f44edd7bSTakashi Iwai */
272f44edd7bSTakashi Iwai
toneport_has_led(struct usb_line6_toneport * toneport)273f2bd242fSChris Rorvick static bool toneport_has_led(struct usb_line6_toneport *toneport)
274f44edd7bSTakashi Iwai {
275f2bd242fSChris Rorvick switch (toneport->type) {
276f2bd242fSChris Rorvick case LINE6_GUITARPORT:
277f2bd242fSChris Rorvick case LINE6_TONEPORT_GX:
278f44edd7bSTakashi Iwai /* add your device here if you are missing support for the LEDs */
279f2bd242fSChris Rorvick return true;
280f2bd242fSChris Rorvick
281f2bd242fSChris Rorvick default:
282f2bd242fSChris Rorvick return false;
283f2bd242fSChris Rorvick }
284f44edd7bSTakashi Iwai }
285f44edd7bSTakashi Iwai
28605b8ccfbSJacek Anaszewski static const char * const toneport_led_colors[2] = { "red", "green" };
28705b8ccfbSJacek Anaszewski static const int toneport_led_init_vals[2] = { 0x00, 0x26 };
288f44edd7bSTakashi Iwai
toneport_update_led(struct usb_line6_toneport * toneport)289f44edd7bSTakashi Iwai static void toneport_update_led(struct usb_line6_toneport *toneport)
290f44edd7bSTakashi Iwai {
291f44edd7bSTakashi Iwai toneport_send_cmd(toneport->line6.usbdev,
292f44edd7bSTakashi Iwai (toneport->leds[0].dev.brightness << 8) | 0x0002,
293f44edd7bSTakashi Iwai toneport->leds[1].dev.brightness);
294f44edd7bSTakashi Iwai }
295f44edd7bSTakashi Iwai
toneport_led_brightness_set(struct led_classdev * led_cdev,enum led_brightness brightness)296f44edd7bSTakashi Iwai static void toneport_led_brightness_set(struct led_classdev *led_cdev,
297f44edd7bSTakashi Iwai enum led_brightness brightness)
298f44edd7bSTakashi Iwai {
299f44edd7bSTakashi Iwai struct toneport_led *leds =
300f44edd7bSTakashi Iwai container_of(led_cdev, struct toneport_led, dev);
301f44edd7bSTakashi Iwai toneport_update_led(leds->toneport);
302f44edd7bSTakashi Iwai }
303f44edd7bSTakashi Iwai
toneport_init_leds(struct usb_line6_toneport * toneport)304f44edd7bSTakashi Iwai static int toneport_init_leds(struct usb_line6_toneport *toneport)
305f44edd7bSTakashi Iwai {
306f44edd7bSTakashi Iwai struct device *dev = &toneport->line6.usbdev->dev;
307f44edd7bSTakashi Iwai int i, err;
308f44edd7bSTakashi Iwai
309f44edd7bSTakashi Iwai for (i = 0; i < 2; i++) {
310f44edd7bSTakashi Iwai struct toneport_led *led = &toneport->leds[i];
311f44edd7bSTakashi Iwai struct led_classdev *leddev = &led->dev;
312f44edd7bSTakashi Iwai
313f44edd7bSTakashi Iwai led->toneport = toneport;
314f44edd7bSTakashi Iwai snprintf(led->name, sizeof(led->name), "%s::%s",
31505b8ccfbSJacek Anaszewski dev_name(dev), toneport_led_colors[i]);
316f44edd7bSTakashi Iwai leddev->name = led->name;
31705b8ccfbSJacek Anaszewski leddev->brightness = toneport_led_init_vals[i];
318f44edd7bSTakashi Iwai leddev->max_brightness = 0x26;
319f44edd7bSTakashi Iwai leddev->brightness_set = toneport_led_brightness_set;
320f44edd7bSTakashi Iwai err = led_classdev_register(dev, leddev);
321f44edd7bSTakashi Iwai if (err)
322f44edd7bSTakashi Iwai return err;
323f44edd7bSTakashi Iwai led->registered = true;
324f44edd7bSTakashi Iwai }
325f44edd7bSTakashi Iwai
326f44edd7bSTakashi Iwai return 0;
327f44edd7bSTakashi Iwai }
328f44edd7bSTakashi Iwai
toneport_remove_leds(struct usb_line6_toneport * toneport)329f44edd7bSTakashi Iwai static void toneport_remove_leds(struct usb_line6_toneport *toneport)
330f44edd7bSTakashi Iwai {
331f44edd7bSTakashi Iwai struct toneport_led *led;
332f44edd7bSTakashi Iwai int i;
333f44edd7bSTakashi Iwai
334f44edd7bSTakashi Iwai for (i = 0; i < 2; i++) {
335f44edd7bSTakashi Iwai led = &toneport->leds[i];
336f44edd7bSTakashi Iwai if (!led->registered)
337f44edd7bSTakashi Iwai break;
338f44edd7bSTakashi Iwai led_classdev_unregister(&led->dev);
339f44edd7bSTakashi Iwai led->registered = false;
340f44edd7bSTakashi Iwai }
341f44edd7bSTakashi Iwai }
342f44edd7bSTakashi Iwai
toneport_has_source_select(struct usb_line6_toneport * toneport)34389444601SChris Rorvick static bool toneport_has_source_select(struct usb_line6_toneport *toneport)
34489444601SChris Rorvick {
34589444601SChris Rorvick switch (toneport->type) {
34689444601SChris Rorvick case LINE6_TONEPORT_UX1:
34789444601SChris Rorvick case LINE6_TONEPORT_UX2:
34889444601SChris Rorvick case LINE6_PODSTUDIO_UX1:
34989444601SChris Rorvick case LINE6_PODSTUDIO_UX2:
35089444601SChris Rorvick return true;
35189444601SChris Rorvick
35289444601SChris Rorvick default:
35389444601SChris Rorvick return false;
35489444601SChris Rorvick }
35589444601SChris Rorvick }
35689444601SChris Rorvick
357f44edd7bSTakashi Iwai /*
35861864d84STakashi Iwai Setup Toneport device.
35961864d84STakashi Iwai */
toneport_setup(struct usb_line6_toneport * toneport)360e5c812e8SGreg Kroah-Hartman static int toneport_setup(struct usb_line6_toneport *toneport)
36161864d84STakashi Iwai {
362e5c812e8SGreg Kroah-Hartman u32 *ticks;
36361864d84STakashi Iwai struct usb_line6 *line6 = &toneport->line6;
36461864d84STakashi Iwai struct usb_device *usbdev = line6->usbdev;
36561864d84STakashi Iwai
366e5c812e8SGreg Kroah-Hartman ticks = kmalloc(sizeof(*ticks), GFP_KERNEL);
367e5c812e8SGreg Kroah-Hartman if (!ticks)
368e5c812e8SGreg Kroah-Hartman return -ENOMEM;
369e5c812e8SGreg Kroah-Hartman
37061864d84STakashi Iwai /* sync time on device with host: */
371a8eaad7bSArnd Bergmann /* note: 32-bit timestamps overflow in year 2106 */
372e5c812e8SGreg Kroah-Hartman *ticks = (u32)ktime_get_real_seconds();
373e5c812e8SGreg Kroah-Hartman line6_write_data(line6, 0x80c6, ticks, 4);
374e5c812e8SGreg Kroah-Hartman kfree(ticks);
37561864d84STakashi Iwai
37661864d84STakashi Iwai /* enable device: */
37761864d84STakashi Iwai toneport_send_cmd(usbdev, 0x0301, 0x0000);
37861864d84STakashi Iwai
37961864d84STakashi Iwai /* initialize source select: */
38089444601SChris Rorvick if (toneport_has_source_select(toneport))
38161864d84STakashi Iwai toneport_send_cmd(usbdev,
38261864d84STakashi Iwai toneport_source_info[toneport->source].code,
38361864d84STakashi Iwai 0x0000);
38461864d84STakashi Iwai
385f2bd242fSChris Rorvick if (toneport_has_led(toneport))
386f44edd7bSTakashi Iwai toneport_update_led(toneport);
3876dd1c05cSTakashi Iwai
3880b074ab7STakashi Iwai schedule_delayed_work(&toneport->line6.startup_work,
3897f84ff68STakashi Iwai msecs_to_jiffies(TONEPORT_PCM_DELAY * 1000));
390e5c812e8SGreg Kroah-Hartman return 0;
39161864d84STakashi Iwai }
39261864d84STakashi Iwai
39361864d84STakashi Iwai /*
39461864d84STakashi Iwai Toneport device disconnected.
39561864d84STakashi Iwai */
line6_toneport_disconnect(struct usb_line6 * line6)396f66fd990STakashi Iwai static void line6_toneport_disconnect(struct usb_line6 *line6)
39761864d84STakashi Iwai {
398f23a09eeSTakashi Iwai struct usb_line6_toneport *toneport = line6_to_toneport(line6);
39961864d84STakashi Iwai
400f2bd242fSChris Rorvick if (toneport_has_led(toneport))
401f44edd7bSTakashi Iwai toneport_remove_leds(toneport);
40261864d84STakashi Iwai }
40361864d84STakashi Iwai
40461864d84STakashi Iwai
40561864d84STakashi Iwai /*
40661864d84STakashi Iwai Try to init Toneport device.
40761864d84STakashi Iwai */
toneport_init(struct usb_line6 * line6,const struct usb_device_id * id)408f66fd990STakashi Iwai static int toneport_init(struct usb_line6 *line6,
409f66fd990STakashi Iwai const struct usb_device_id *id)
41061864d84STakashi Iwai {
41161864d84STakashi Iwai int err;
412f23a09eeSTakashi Iwai struct usb_line6_toneport *toneport = line6_to_toneport(line6);
41361864d84STakashi Iwai
414f66fd990STakashi Iwai toneport->type = id->driver_info;
4156dd1c05cSTakashi Iwai
41661864d84STakashi Iwai line6->disconnect = line6_toneport_disconnect;
4170b074ab7STakashi Iwai line6->startup = toneport_startup;
41861864d84STakashi Iwai
41961864d84STakashi Iwai /* initialize PCM subsystem: */
42061864d84STakashi Iwai err = line6_init_pcm(line6, &toneport_pcm_properties);
42161864d84STakashi Iwai if (err < 0)
42261864d84STakashi Iwai return err;
42361864d84STakashi Iwai
42461864d84STakashi Iwai /* register monitor control: */
42561864d84STakashi Iwai err = snd_ctl_add(line6->card,
42661864d84STakashi Iwai snd_ctl_new1(&toneport_control_monitor,
42761864d84STakashi Iwai line6->line6pcm));
42861864d84STakashi Iwai if (err < 0)
42961864d84STakashi Iwai return err;
43061864d84STakashi Iwai
43161864d84STakashi Iwai /* register source select control: */
43289444601SChris Rorvick if (toneport_has_source_select(toneport)) {
43361864d84STakashi Iwai err =
43461864d84STakashi Iwai snd_ctl_add(line6->card,
43561864d84STakashi Iwai snd_ctl_new1(&toneport_control_source,
43661864d84STakashi Iwai line6->line6pcm));
43761864d84STakashi Iwai if (err < 0)
43861864d84STakashi Iwai return err;
43961864d84STakashi Iwai }
44061864d84STakashi Iwai
44161864d84STakashi Iwai line6_read_serial_number(line6, &toneport->serial_number);
44261864d84STakashi Iwai line6_read_data(line6, 0x80c2, &toneport->firmware_version, 1);
44361864d84STakashi Iwai
444f2bd242fSChris Rorvick if (toneport_has_led(toneport)) {
445f44edd7bSTakashi Iwai err = toneport_init_leds(toneport);
446b2a3b023STakashi Iwai if (err < 0)
447b2a3b023STakashi Iwai return err;
44861864d84STakashi Iwai }
44961864d84STakashi Iwai
450e5c812e8SGreg Kroah-Hartman err = toneport_setup(toneport);
451e5c812e8SGreg Kroah-Hartman if (err)
452e5c812e8SGreg Kroah-Hartman return err;
45361864d84STakashi Iwai
45485a9339bSTakashi Iwai /* register audio system: */
45585a9339bSTakashi Iwai return snd_card_register(line6->card);
45661864d84STakashi Iwai }
45761864d84STakashi Iwai
458ccddbe4aSTakashi Iwai #ifdef CONFIG_PM
45961864d84STakashi Iwai /*
46061864d84STakashi Iwai Resume Toneport device after reset.
46161864d84STakashi Iwai */
toneport_reset_resume(struct usb_interface * interface)462ccddbe4aSTakashi Iwai static int toneport_reset_resume(struct usb_interface *interface)
46361864d84STakashi Iwai {
464e5c812e8SGreg Kroah-Hartman int err;
465e5c812e8SGreg Kroah-Hartman
466e5c812e8SGreg Kroah-Hartman err = toneport_setup(usb_get_intfdata(interface));
467e5c812e8SGreg Kroah-Hartman if (err)
468e5c812e8SGreg Kroah-Hartman return err;
469ccddbe4aSTakashi Iwai return line6_resume(interface);
47061864d84STakashi Iwai }
471ccddbe4aSTakashi Iwai #endif
472ccddbe4aSTakashi Iwai
473ccddbe4aSTakashi Iwai #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
474ccddbe4aSTakashi Iwai #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
475ccddbe4aSTakashi Iwai
476ccddbe4aSTakashi Iwai /* table of devices that work with this driver */
477ccddbe4aSTakashi Iwai static const struct usb_device_id toneport_id_table[] = {
478ccddbe4aSTakashi Iwai { LINE6_DEVICE(0x4750), .driver_info = LINE6_GUITARPORT },
479ccddbe4aSTakashi Iwai { LINE6_DEVICE(0x4153), .driver_info = LINE6_PODSTUDIO_GX },
480ccddbe4aSTakashi Iwai { LINE6_DEVICE(0x4150), .driver_info = LINE6_PODSTUDIO_UX1 },
481ccddbe4aSTakashi Iwai { LINE6_IF_NUM(0x4151, 0), .driver_info = LINE6_PODSTUDIO_UX2 },
482ccddbe4aSTakashi Iwai { LINE6_DEVICE(0x4147), .driver_info = LINE6_TONEPORT_GX },
483ccddbe4aSTakashi Iwai { LINE6_DEVICE(0x4141), .driver_info = LINE6_TONEPORT_UX1 },
484ccddbe4aSTakashi Iwai { LINE6_IF_NUM(0x4142, 0), .driver_info = LINE6_TONEPORT_UX2 },
485ccddbe4aSTakashi Iwai {}
486ccddbe4aSTakashi Iwai };
487ccddbe4aSTakashi Iwai
488ccddbe4aSTakashi Iwai MODULE_DEVICE_TABLE(usb, toneport_id_table);
489ccddbe4aSTakashi Iwai
490ccddbe4aSTakashi Iwai static const struct line6_properties toneport_properties_table[] = {
491ccddbe4aSTakashi Iwai [LINE6_GUITARPORT] = {
492ccddbe4aSTakashi Iwai .id = "GuitarPort",
493ccddbe4aSTakashi Iwai .name = "GuitarPort",
494ccddbe4aSTakashi Iwai .capabilities = LINE6_CAP_PCM,
495ccddbe4aSTakashi Iwai .altsetting = 2, /* 1..4 seem to be ok */
496ccddbe4aSTakashi Iwai /* no control channel */
497ccddbe4aSTakashi Iwai .ep_audio_r = 0x82,
498ccddbe4aSTakashi Iwai .ep_audio_w = 0x01,
499ccddbe4aSTakashi Iwai },
500ccddbe4aSTakashi Iwai [LINE6_PODSTUDIO_GX] = {
501ccddbe4aSTakashi Iwai .id = "PODStudioGX",
502ccddbe4aSTakashi Iwai .name = "POD Studio GX",
503ccddbe4aSTakashi Iwai .capabilities = LINE6_CAP_PCM,
504ccddbe4aSTakashi Iwai .altsetting = 2, /* 1..4 seem to be ok */
505ccddbe4aSTakashi Iwai /* no control channel */
506ccddbe4aSTakashi Iwai .ep_audio_r = 0x82,
507ccddbe4aSTakashi Iwai .ep_audio_w = 0x01,
508ccddbe4aSTakashi Iwai },
509ccddbe4aSTakashi Iwai [LINE6_PODSTUDIO_UX1] = {
510ccddbe4aSTakashi Iwai .id = "PODStudioUX1",
511ccddbe4aSTakashi Iwai .name = "POD Studio UX1",
512ccddbe4aSTakashi Iwai .capabilities = LINE6_CAP_PCM,
513ccddbe4aSTakashi Iwai .altsetting = 2, /* 1..4 seem to be ok */
514ccddbe4aSTakashi Iwai /* no control channel */
515ccddbe4aSTakashi Iwai .ep_audio_r = 0x82,
516ccddbe4aSTakashi Iwai .ep_audio_w = 0x01,
517ccddbe4aSTakashi Iwai },
518ccddbe4aSTakashi Iwai [LINE6_PODSTUDIO_UX2] = {
519ccddbe4aSTakashi Iwai .id = "PODStudioUX2",
520ccddbe4aSTakashi Iwai .name = "POD Studio UX2",
521ccddbe4aSTakashi Iwai .capabilities = LINE6_CAP_PCM,
522ccddbe4aSTakashi Iwai .altsetting = 2, /* defaults to 44.1kHz, 16-bit */
523ccddbe4aSTakashi Iwai /* no control channel */
524ccddbe4aSTakashi Iwai .ep_audio_r = 0x82,
525ccddbe4aSTakashi Iwai .ep_audio_w = 0x01,
526ccddbe4aSTakashi Iwai },
527ccddbe4aSTakashi Iwai [LINE6_TONEPORT_GX] = {
528ccddbe4aSTakashi Iwai .id = "TonePortGX",
529ccddbe4aSTakashi Iwai .name = "TonePort GX",
530ccddbe4aSTakashi Iwai .capabilities = LINE6_CAP_PCM,
531ccddbe4aSTakashi Iwai .altsetting = 2, /* 1..4 seem to be ok */
532ccddbe4aSTakashi Iwai /* no control channel */
533ccddbe4aSTakashi Iwai .ep_audio_r = 0x82,
534ccddbe4aSTakashi Iwai .ep_audio_w = 0x01,
535ccddbe4aSTakashi Iwai },
536ccddbe4aSTakashi Iwai [LINE6_TONEPORT_UX1] = {
537ccddbe4aSTakashi Iwai .id = "TonePortUX1",
538ccddbe4aSTakashi Iwai .name = "TonePort UX1",
539ccddbe4aSTakashi Iwai .capabilities = LINE6_CAP_PCM,
540ccddbe4aSTakashi Iwai .altsetting = 2, /* 1..4 seem to be ok */
541ccddbe4aSTakashi Iwai /* no control channel */
542ccddbe4aSTakashi Iwai .ep_audio_r = 0x82,
543ccddbe4aSTakashi Iwai .ep_audio_w = 0x01,
544ccddbe4aSTakashi Iwai },
545ccddbe4aSTakashi Iwai [LINE6_TONEPORT_UX2] = {
546ccddbe4aSTakashi Iwai .id = "TonePortUX2",
547ccddbe4aSTakashi Iwai .name = "TonePort UX2",
548ccddbe4aSTakashi Iwai .capabilities = LINE6_CAP_PCM,
549ccddbe4aSTakashi Iwai .altsetting = 2, /* defaults to 44.1kHz, 16-bit */
550ccddbe4aSTakashi Iwai /* no control channel */
551ccddbe4aSTakashi Iwai .ep_audio_r = 0x82,
552ccddbe4aSTakashi Iwai .ep_audio_w = 0x01,
553ccddbe4aSTakashi Iwai },
554ccddbe4aSTakashi Iwai };
555ccddbe4aSTakashi Iwai
556ccddbe4aSTakashi Iwai /*
557ccddbe4aSTakashi Iwai Probe USB device.
558ccddbe4aSTakashi Iwai */
toneport_probe(struct usb_interface * interface,const struct usb_device_id * id)559ccddbe4aSTakashi Iwai static int toneport_probe(struct usb_interface *interface,
560ccddbe4aSTakashi Iwai const struct usb_device_id *id)
561ccddbe4aSTakashi Iwai {
56212865cacSChris Rorvick return line6_probe(interface, id, "Line6-TonePort",
563ccddbe4aSTakashi Iwai &toneport_properties_table[id->driver_info],
564aca514b8STakashi Iwai toneport_init, sizeof(struct usb_line6_toneport));
565ccddbe4aSTakashi Iwai }
566ccddbe4aSTakashi Iwai
567ccddbe4aSTakashi Iwai static struct usb_driver toneport_driver = {
568ccddbe4aSTakashi Iwai .name = KBUILD_MODNAME,
569ccddbe4aSTakashi Iwai .probe = toneport_probe,
570ccddbe4aSTakashi Iwai .disconnect = line6_disconnect,
571ccddbe4aSTakashi Iwai #ifdef CONFIG_PM
572ccddbe4aSTakashi Iwai .suspend = line6_suspend,
573ccddbe4aSTakashi Iwai .resume = line6_resume,
574ccddbe4aSTakashi Iwai .reset_resume = toneport_reset_resume,
575ccddbe4aSTakashi Iwai #endif
576ccddbe4aSTakashi Iwai .id_table = toneport_id_table,
577ccddbe4aSTakashi Iwai };
578ccddbe4aSTakashi Iwai
579ccddbe4aSTakashi Iwai module_usb_driver(toneport_driver);
580ccddbe4aSTakashi Iwai
581ccddbe4aSTakashi Iwai MODULE_DESCRIPTION("TonePort USB driver");
582ccddbe4aSTakashi Iwai MODULE_LICENSE("GPL");
583