Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1 | /* |
Chris Rorvick | c078a4a | 2015-01-20 02:20:50 -0600 | [diff] [blame] | 2 | * Line 6 Linux USB driver |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 3 | * |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 4 | * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 5 | * Emil Myhrman (emil.myhrman@gmail.com) |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation, version 2. |
| 10 | * |
| 11 | */ |
| 12 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 13 | #include <linux/wait.h> |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 14 | #include <linux/usb.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/module.h> |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 17 | #include <linux/leds.h> |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 18 | #include <sound/core.h> |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 19 | #include <sound/control.h> |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 20 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 21 | #include "capture.h" |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 22 | #include "driver.h" |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 23 | #include "playback.h" |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 24 | |
| 25 | enum line6_device_type { |
| 26 | LINE6_GUITARPORT, |
| 27 | LINE6_PODSTUDIO_GX, |
| 28 | LINE6_PODSTUDIO_UX1, |
| 29 | LINE6_PODSTUDIO_UX2, |
| 30 | LINE6_TONEPORT_GX, |
| 31 | LINE6_TONEPORT_UX1, |
| 32 | LINE6_TONEPORT_UX2, |
| 33 | }; |
| 34 | |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 35 | struct usb_line6_toneport; |
| 36 | |
| 37 | struct toneport_led { |
| 38 | struct led_classdev dev; |
| 39 | char name[64]; |
| 40 | struct usb_line6_toneport *toneport; |
| 41 | bool registered; |
| 42 | }; |
| 43 | |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 44 | struct usb_line6_toneport { |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 45 | /* Generic Line 6 USB data */ |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 46 | struct usb_line6 line6; |
| 47 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 48 | /* Source selector */ |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 49 | int source; |
| 50 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 51 | /* Serial number of device */ |
Chris Rorvick | 12b0015 | 2015-02-10 23:03:16 -0600 | [diff] [blame] | 52 | u32 serial_number; |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 53 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 54 | /* Firmware version (x 100) */ |
Chris Rorvick | 0e80615 | 2015-02-10 23:03:17 -0600 | [diff] [blame] | 55 | u8 firmware_version; |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 56 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 57 | /* Timer for delayed PCM startup */ |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 58 | struct timer_list timer; |
| 59 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 60 | /* Device type */ |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 61 | enum line6_device_type type; |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 62 | |
| 63 | /* LED instances */ |
| 64 | struct toneport_led leds[2]; |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 65 | }; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 66 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 67 | static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2); |
| 68 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 69 | #define TONEPORT_PCM_DELAY 1 |
| 70 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 71 | static struct snd_ratden toneport_ratden = { |
| 72 | .num_min = 44100, |
| 73 | .num_max = 44100, |
| 74 | .num_step = 1, |
| 75 | .den = 1 |
| 76 | }; |
| 77 | |
| 78 | static struct line6_pcm_properties toneport_pcm_properties = { |
Takashi Iwai | 1263f61 | 2015-01-28 15:08:59 +0100 | [diff] [blame] | 79 | .playback_hw = { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 80 | .info = (SNDRV_PCM_INFO_MMAP | |
| 81 | SNDRV_PCM_INFO_INTERLEAVED | |
| 82 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 83 | SNDRV_PCM_INFO_MMAP_VALID | |
| 84 | SNDRV_PCM_INFO_PAUSE | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 85 | SNDRV_PCM_INFO_SYNC_START), |
| 86 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 87 | .rates = SNDRV_PCM_RATE_KNOT, |
| 88 | .rate_min = 44100, |
| 89 | .rate_max = 44100, |
| 90 | .channels_min = 2, |
| 91 | .channels_max = 2, |
| 92 | .buffer_bytes_max = 60000, |
| 93 | .period_bytes_min = 64, |
| 94 | .period_bytes_max = 8192, |
| 95 | .periods_min = 1, |
| 96 | .periods_max = 1024}, |
Takashi Iwai | 1263f61 | 2015-01-28 15:08:59 +0100 | [diff] [blame] | 97 | .capture_hw = { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 98 | .info = (SNDRV_PCM_INFO_MMAP | |
| 99 | SNDRV_PCM_INFO_INTERLEAVED | |
| 100 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 101 | SNDRV_PCM_INFO_MMAP_VALID | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 102 | SNDRV_PCM_INFO_SYNC_START), |
| 103 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 104 | .rates = SNDRV_PCM_RATE_KNOT, |
| 105 | .rate_min = 44100, |
| 106 | .rate_max = 44100, |
| 107 | .channels_min = 2, |
| 108 | .channels_max = 2, |
| 109 | .buffer_bytes_max = 60000, |
| 110 | .period_bytes_min = 64, |
| 111 | .period_bytes_max = 8192, |
| 112 | .periods_min = 1, |
| 113 | .periods_max = 1024}, |
Takashi Iwai | 1263f61 | 2015-01-28 15:08:59 +0100 | [diff] [blame] | 114 | .rates = { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 115 | .nrats = 1, |
| 116 | .rats = &toneport_ratden}, |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 117 | .bytes_per_frame = 4 |
| 118 | }; |
| 119 | |
Stefan Hajnoczi | 709b2fa | 2013-01-11 23:08:13 +0100 | [diff] [blame] | 120 | static const struct { |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 121 | const char *name; |
| 122 | int code; |
Stefan Hajnoczi | 709b2fa | 2013-01-11 23:08:13 +0100 | [diff] [blame] | 123 | } toneport_source_info[] = { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 124 | {"Microphone", 0x0a01}, |
| 125 | {"Line", 0x0801}, |
| 126 | {"Instrument", 0x0b01}, |
| 127 | {"Inst & Mic", 0x0901} |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 128 | }; |
| 129 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 130 | static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2) |
| 131 | { |
| 132 | int ret; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 133 | |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 134 | ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67, |
| 135 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, |
| 136 | cmd1, cmd2, NULL, 0, LINE6_TIMEOUT * HZ); |
| 137 | |
| 138 | if (ret < 0) { |
Greg Kroah-Hartman | d86938f | 2012-04-20 16:53:32 -0700 | [diff] [blame] | 139 | dev_err(&usbdev->dev, "send failed (error %d)\n", ret); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 140 | return ret; |
| 141 | } |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 146 | /* monitor info callback */ |
| 147 | static int snd_toneport_monitor_info(struct snd_kcontrol *kcontrol, |
| 148 | struct snd_ctl_elem_info *uinfo) |
| 149 | { |
| 150 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 151 | uinfo->count = 1; |
| 152 | uinfo->value.integer.min = 0; |
| 153 | uinfo->value.integer.max = 256; |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | /* monitor get callback */ |
| 158 | static int snd_toneport_monitor_get(struct snd_kcontrol *kcontrol, |
| 159 | struct snd_ctl_elem_value *ucontrol) |
| 160 | { |
| 161 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
Jerry Snitselaar | f3c5261 | 2014-04-24 00:31:48 -0700 | [diff] [blame] | 162 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 163 | ucontrol->value.integer.value[0] = line6pcm->volume_monitor; |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | /* monitor put callback */ |
| 168 | static int snd_toneport_monitor_put(struct snd_kcontrol *kcontrol, |
| 169 | struct snd_ctl_elem_value *ucontrol) |
| 170 | { |
| 171 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 247d95e | 2015-01-27 16:42:14 +0100 | [diff] [blame] | 172 | int err; |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 173 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 174 | if (ucontrol->value.integer.value[0] == line6pcm->volume_monitor) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 175 | return 0; |
| 176 | |
| 177 | line6pcm->volume_monitor = ucontrol->value.integer.value[0]; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 178 | |
Takashi Iwai | 247d95e | 2015-01-27 16:42:14 +0100 | [diff] [blame] | 179 | if (line6pcm->volume_monitor > 0) { |
| 180 | err = line6_pcm_acquire(line6pcm, LINE6_STREAM_MONITOR); |
| 181 | if (err < 0) { |
| 182 | line6pcm->volume_monitor = 0; |
| 183 | line6_pcm_release(line6pcm, LINE6_STREAM_MONITOR); |
| 184 | return err; |
| 185 | } |
| 186 | } else { |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 187 | line6_pcm_release(line6pcm, LINE6_STREAM_MONITOR); |
Takashi Iwai | 247d95e | 2015-01-27 16:42:14 +0100 | [diff] [blame] | 188 | } |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 189 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 190 | return 1; |
| 191 | } |
| 192 | |
| 193 | /* source info callback */ |
| 194 | static int snd_toneport_source_info(struct snd_kcontrol *kcontrol, |
| 195 | struct snd_ctl_elem_info *uinfo) |
| 196 | { |
| 197 | const int size = ARRAY_SIZE(toneport_source_info); |
Fabian Mewes | a6b4699 | 2014-03-24 23:46:31 +0100 | [diff] [blame] | 198 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 199 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 200 | uinfo->count = 1; |
| 201 | uinfo->value.enumerated.items = size; |
| 202 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 203 | if (uinfo->value.enumerated.item >= size) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 204 | uinfo->value.enumerated.item = size - 1; |
| 205 | |
| 206 | strcpy(uinfo->value.enumerated.name, |
| 207 | toneport_source_info[uinfo->value.enumerated.item].name); |
| 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | /* source get callback */ |
| 213 | static int snd_toneport_source_get(struct snd_kcontrol *kcontrol, |
| 214 | struct snd_ctl_elem_value *ucontrol) |
| 215 | { |
| 216 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 217 | struct usb_line6_toneport *toneport = |
| 218 | (struct usb_line6_toneport *)line6pcm->line6; |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 219 | ucontrol->value.enumerated.item[0] = toneport->source; |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | /* source put callback */ |
| 224 | static int snd_toneport_source_put(struct snd_kcontrol *kcontrol, |
| 225 | struct snd_ctl_elem_value *ucontrol) |
| 226 | { |
| 227 | struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 228 | struct usb_line6_toneport *toneport = |
| 229 | (struct usb_line6_toneport *)line6pcm->line6; |
Dan Carpenter | c3cb718 | 2013-09-13 11:07:13 +0300 | [diff] [blame] | 230 | unsigned int source; |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 231 | |
Dan Carpenter | c3cb718 | 2013-09-13 11:07:13 +0300 | [diff] [blame] | 232 | source = ucontrol->value.enumerated.item[0]; |
| 233 | if (source >= ARRAY_SIZE(toneport_source_info)) |
| 234 | return -EINVAL; |
| 235 | if (source == toneport->source) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 236 | return 0; |
| 237 | |
Dan Carpenter | c3cb718 | 2013-09-13 11:07:13 +0300 | [diff] [blame] | 238 | toneport->source = source; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 239 | toneport_send_cmd(toneport->line6.usbdev, |
Dan Carpenter | c3cb718 | 2013-09-13 11:07:13 +0300 | [diff] [blame] | 240 | toneport_source_info[source].code, 0x0000); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 241 | return 1; |
| 242 | } |
| 243 | |
| 244 | static void toneport_start_pcm(unsigned long arg) |
| 245 | { |
| 246 | struct usb_line6_toneport *toneport = (struct usb_line6_toneport *)arg; |
| 247 | struct usb_line6 *line6 = &toneport->line6; |
Jerry Snitselaar | f3c5261 | 2014-04-24 00:31:48 -0700 | [diff] [blame] | 248 | |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 249 | line6_pcm_acquire(line6->line6pcm, LINE6_STREAM_MONITOR); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /* control definition */ |
| 253 | static struct snd_kcontrol_new toneport_control_monitor = { |
| 254 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 255 | .name = "Monitor Playback Volume", |
| 256 | .index = 0, |
| 257 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 258 | .info = snd_toneport_monitor_info, |
| 259 | .get = snd_toneport_monitor_get, |
| 260 | .put = snd_toneport_monitor_put |
| 261 | }; |
| 262 | |
| 263 | /* source selector definition */ |
| 264 | static struct snd_kcontrol_new toneport_control_source = { |
| 265 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 266 | .name = "PCM Capture Source", |
| 267 | .index = 0, |
| 268 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 269 | .info = snd_toneport_source_info, |
| 270 | .get = snd_toneport_source_get, |
| 271 | .put = snd_toneport_source_put |
| 272 | }; |
| 273 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 274 | /* |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 275 | For the led on Guitarport. |
| 276 | Brightness goes from 0x00 to 0x26. Set a value above this to have led |
| 277 | blink. |
| 278 | (void cmd_0x02(byte red, byte green) |
| 279 | */ |
| 280 | |
Chris Rorvick | f2bd242 | 2015-02-07 10:43:18 -0600 | [diff] [blame] | 281 | static bool toneport_has_led(struct usb_line6_toneport *toneport) |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 282 | { |
Chris Rorvick | f2bd242 | 2015-02-07 10:43:18 -0600 | [diff] [blame] | 283 | switch (toneport->type) { |
| 284 | case LINE6_GUITARPORT: |
| 285 | case LINE6_TONEPORT_GX: |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 286 | /* add your device here if you are missing support for the LEDs */ |
Chris Rorvick | f2bd242 | 2015-02-07 10:43:18 -0600 | [diff] [blame] | 287 | return true; |
| 288 | |
| 289 | default: |
| 290 | return false; |
| 291 | } |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | static const char * const led_colors[2] = { "red", "green" }; |
| 295 | static const int led_init_vals[2] = { 0x00, 0x26 }; |
| 296 | |
| 297 | static void toneport_update_led(struct usb_line6_toneport *toneport) |
| 298 | { |
| 299 | toneport_send_cmd(toneport->line6.usbdev, |
| 300 | (toneport->leds[0].dev.brightness << 8) | 0x0002, |
| 301 | toneport->leds[1].dev.brightness); |
| 302 | } |
| 303 | |
| 304 | static void toneport_led_brightness_set(struct led_classdev *led_cdev, |
| 305 | enum led_brightness brightness) |
| 306 | { |
| 307 | struct toneport_led *leds = |
| 308 | container_of(led_cdev, struct toneport_led, dev); |
| 309 | toneport_update_led(leds->toneport); |
| 310 | } |
| 311 | |
| 312 | static int toneport_init_leds(struct usb_line6_toneport *toneport) |
| 313 | { |
| 314 | struct device *dev = &toneport->line6.usbdev->dev; |
| 315 | int i, err; |
| 316 | |
| 317 | for (i = 0; i < 2; i++) { |
| 318 | struct toneport_led *led = &toneport->leds[i]; |
| 319 | struct led_classdev *leddev = &led->dev; |
| 320 | |
| 321 | led->toneport = toneport; |
| 322 | snprintf(led->name, sizeof(led->name), "%s::%s", |
| 323 | dev_name(dev), led_colors[i]); |
| 324 | leddev->name = led->name; |
| 325 | leddev->brightness = led_init_vals[i]; |
| 326 | leddev->max_brightness = 0x26; |
| 327 | leddev->brightness_set = toneport_led_brightness_set; |
| 328 | err = led_classdev_register(dev, leddev); |
| 329 | if (err) |
| 330 | return err; |
| 331 | led->registered = true; |
| 332 | } |
| 333 | |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | static void toneport_remove_leds(struct usb_line6_toneport *toneport) |
| 338 | { |
| 339 | struct toneport_led *led; |
| 340 | int i; |
| 341 | |
| 342 | for (i = 0; i < 2; i++) { |
| 343 | led = &toneport->leds[i]; |
| 344 | if (!led->registered) |
| 345 | break; |
| 346 | led_classdev_unregister(&led->dev); |
| 347 | led->registered = false; |
| 348 | } |
| 349 | } |
| 350 | |
Chris Rorvick | 8944460 | 2015-02-07 10:43:17 -0600 | [diff] [blame] | 351 | static bool toneport_has_source_select(struct usb_line6_toneport *toneport) |
| 352 | { |
| 353 | switch (toneport->type) { |
| 354 | case LINE6_TONEPORT_UX1: |
| 355 | case LINE6_TONEPORT_UX2: |
| 356 | case LINE6_PODSTUDIO_UX1: |
| 357 | case LINE6_PODSTUDIO_UX2: |
| 358 | return true; |
| 359 | |
| 360 | default: |
| 361 | return false; |
| 362 | } |
| 363 | } |
| 364 | |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 365 | /* |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 366 | Setup Toneport device. |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 367 | */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 368 | static void toneport_setup(struct usb_line6_toneport *toneport) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 369 | { |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 370 | int ticks; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 371 | struct usb_line6 *line6 = &toneport->line6; |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 372 | struct usb_device *usbdev = line6->usbdev; |
| 373 | |
| 374 | /* sync time on device with host: */ |
| 375 | ticks = (int)get_seconds(); |
| 376 | line6_write_data(line6, 0x80c6, &ticks, 4); |
| 377 | |
| 378 | /* enable device: */ |
| 379 | toneport_send_cmd(usbdev, 0x0301, 0x0000); |
| 380 | |
| 381 | /* initialize source select: */ |
Chris Rorvick | 8944460 | 2015-02-07 10:43:17 -0600 | [diff] [blame] | 382 | if (toneport_has_source_select(toneport)) |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 383 | toneport_send_cmd(usbdev, |
| 384 | toneport_source_info[toneport->source].code, |
| 385 | 0x0000); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 386 | |
Chris Rorvick | f2bd242 | 2015-02-07 10:43:18 -0600 | [diff] [blame] | 387 | if (toneport_has_led(toneport)) |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 388 | toneport_update_led(toneport); |
Takashi Iwai | 6dd1c05 | 2015-01-20 09:40:20 +0100 | [diff] [blame] | 389 | |
| 390 | mod_timer(&toneport->timer, jiffies + TONEPORT_PCM_DELAY * HZ); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | /* |
Chris Rorvick | d29b854 | 2015-01-12 12:43:00 -0800 | [diff] [blame] | 394 | Toneport device disconnected. |
| 395 | */ |
Takashi Iwai | f66fd99 | 2015-01-25 18:22:58 +0100 | [diff] [blame] | 396 | static void line6_toneport_disconnect(struct usb_line6 *line6) |
Chris Rorvick | d29b854 | 2015-01-12 12:43:00 -0800 | [diff] [blame] | 397 | { |
Takashi Iwai | f66fd99 | 2015-01-25 18:22:58 +0100 | [diff] [blame] | 398 | struct usb_line6_toneport *toneport = |
| 399 | (struct usb_line6_toneport *)line6; |
Chris Rorvick | d29b854 | 2015-01-12 12:43:00 -0800 | [diff] [blame] | 400 | |
Chris Rorvick | d29b854 | 2015-01-12 12:43:00 -0800 | [diff] [blame] | 401 | del_timer_sync(&toneport->timer); |
Chris Rorvick | d29b854 | 2015-01-12 12:43:00 -0800 | [diff] [blame] | 402 | |
Chris Rorvick | f2bd242 | 2015-02-07 10:43:18 -0600 | [diff] [blame] | 403 | if (toneport_has_led(toneport)) |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 404 | toneport_remove_leds(toneport); |
Chris Rorvick | d29b854 | 2015-01-12 12:43:00 -0800 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | |
| 408 | /* |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 409 | Try to init Toneport device. |
| 410 | */ |
Takashi Iwai | f66fd99 | 2015-01-25 18:22:58 +0100 | [diff] [blame] | 411 | static int toneport_init(struct usb_line6 *line6, |
| 412 | const struct usb_device_id *id) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 413 | { |
| 414 | int err; |
Chris Rorvick | a221dd4 | 2015-01-12 12:42:56 -0800 | [diff] [blame] | 415 | struct usb_line6_toneport *toneport = (struct usb_line6_toneport *) line6; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 416 | |
Takashi Iwai | f66fd99 | 2015-01-25 18:22:58 +0100 | [diff] [blame] | 417 | toneport->type = id->driver_info; |
Takashi Iwai | 6dd1c05 | 2015-01-20 09:40:20 +0100 | [diff] [blame] | 418 | setup_timer(&toneport->timer, toneport_start_pcm, |
| 419 | (unsigned long)toneport); |
| 420 | |
Chris Rorvick | a46c467 | 2015-01-12 12:42:59 -0800 | [diff] [blame] | 421 | line6->disconnect = line6_toneport_disconnect; |
| 422 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 423 | /* initialize PCM subsystem: */ |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 424 | err = line6_init_pcm(line6, &toneport_pcm_properties); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 425 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 426 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 427 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 428 | /* register monitor control: */ |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 429 | err = snd_ctl_add(line6->card, |
| 430 | snd_ctl_new1(&toneport_control_monitor, |
| 431 | line6->line6pcm)); |
| 432 | if (err < 0) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 433 | return err; |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 434 | |
| 435 | /* register source select control: */ |
Chris Rorvick | 8944460 | 2015-02-07 10:43:17 -0600 | [diff] [blame] | 436 | if (toneport_has_source_select(toneport)) { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 437 | err = |
| 438 | snd_ctl_add(line6->card, |
| 439 | snd_ctl_new1(&toneport_control_source, |
| 440 | line6->line6pcm)); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 441 | if (err < 0) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 442 | return err; |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 443 | } |
| 444 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 445 | line6_read_serial_number(line6, &toneport->serial_number); |
| 446 | line6_read_data(line6, 0x80c2, &toneport->firmware_version, 1); |
| 447 | |
Chris Rorvick | f2bd242 | 2015-02-07 10:43:18 -0600 | [diff] [blame] | 448 | if (toneport_has_led(toneport)) { |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 449 | err = toneport_init_leds(toneport); |
Takashi Iwai | b2a3b02 | 2015-01-19 16:08:02 +0100 | [diff] [blame] | 450 | if (err < 0) |
| 451 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 452 | } |
| 453 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 454 | toneport_setup(toneport); |
| 455 | |
Takashi Iwai | 85a9339 | 2015-01-19 15:54:00 +0100 | [diff] [blame] | 456 | /* register audio system: */ |
| 457 | return snd_card_register(line6->card); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 458 | } |
| 459 | |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 460 | #ifdef CONFIG_PM |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 461 | /* |
| 462 | Resume Toneport device after reset. |
| 463 | */ |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 464 | static int toneport_reset_resume(struct usb_interface *interface) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 465 | { |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 466 | toneport_setup(usb_get_intfdata(interface)); |
| 467 | return line6_resume(interface); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 468 | } |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 469 | #endif |
| 470 | |
| 471 | #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod) |
| 472 | #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n) |
| 473 | |
| 474 | /* table of devices that work with this driver */ |
| 475 | static const struct usb_device_id toneport_id_table[] = { |
| 476 | { LINE6_DEVICE(0x4750), .driver_info = LINE6_GUITARPORT }, |
| 477 | { LINE6_DEVICE(0x4153), .driver_info = LINE6_PODSTUDIO_GX }, |
| 478 | { LINE6_DEVICE(0x4150), .driver_info = LINE6_PODSTUDIO_UX1 }, |
| 479 | { LINE6_IF_NUM(0x4151, 0), .driver_info = LINE6_PODSTUDIO_UX2 }, |
| 480 | { LINE6_DEVICE(0x4147), .driver_info = LINE6_TONEPORT_GX }, |
| 481 | { LINE6_DEVICE(0x4141), .driver_info = LINE6_TONEPORT_UX1 }, |
| 482 | { LINE6_IF_NUM(0x4142, 0), .driver_info = LINE6_TONEPORT_UX2 }, |
| 483 | {} |
| 484 | }; |
| 485 | |
| 486 | MODULE_DEVICE_TABLE(usb, toneport_id_table); |
| 487 | |
| 488 | static const struct line6_properties toneport_properties_table[] = { |
| 489 | [LINE6_GUITARPORT] = { |
| 490 | .id = "GuitarPort", |
| 491 | .name = "GuitarPort", |
| 492 | .capabilities = LINE6_CAP_PCM, |
| 493 | .altsetting = 2, /* 1..4 seem to be ok */ |
| 494 | /* no control channel */ |
| 495 | .ep_audio_r = 0x82, |
| 496 | .ep_audio_w = 0x01, |
| 497 | }, |
| 498 | [LINE6_PODSTUDIO_GX] = { |
| 499 | .id = "PODStudioGX", |
| 500 | .name = "POD Studio GX", |
| 501 | .capabilities = LINE6_CAP_PCM, |
| 502 | .altsetting = 2, /* 1..4 seem to be ok */ |
| 503 | /* no control channel */ |
| 504 | .ep_audio_r = 0x82, |
| 505 | .ep_audio_w = 0x01, |
| 506 | }, |
| 507 | [LINE6_PODSTUDIO_UX1] = { |
| 508 | .id = "PODStudioUX1", |
| 509 | .name = "POD Studio UX1", |
| 510 | .capabilities = LINE6_CAP_PCM, |
| 511 | .altsetting = 2, /* 1..4 seem to be ok */ |
| 512 | /* no control channel */ |
| 513 | .ep_audio_r = 0x82, |
| 514 | .ep_audio_w = 0x01, |
| 515 | }, |
| 516 | [LINE6_PODSTUDIO_UX2] = { |
| 517 | .id = "PODStudioUX2", |
| 518 | .name = "POD Studio UX2", |
| 519 | .capabilities = LINE6_CAP_PCM, |
| 520 | .altsetting = 2, /* defaults to 44.1kHz, 16-bit */ |
| 521 | /* no control channel */ |
| 522 | .ep_audio_r = 0x82, |
| 523 | .ep_audio_w = 0x01, |
| 524 | }, |
| 525 | [LINE6_TONEPORT_GX] = { |
| 526 | .id = "TonePortGX", |
| 527 | .name = "TonePort GX", |
| 528 | .capabilities = LINE6_CAP_PCM, |
| 529 | .altsetting = 2, /* 1..4 seem to be ok */ |
| 530 | /* no control channel */ |
| 531 | .ep_audio_r = 0x82, |
| 532 | .ep_audio_w = 0x01, |
| 533 | }, |
| 534 | [LINE6_TONEPORT_UX1] = { |
| 535 | .id = "TonePortUX1", |
| 536 | .name = "TonePort UX1", |
| 537 | .capabilities = LINE6_CAP_PCM, |
| 538 | .altsetting = 2, /* 1..4 seem to be ok */ |
| 539 | /* no control channel */ |
| 540 | .ep_audio_r = 0x82, |
| 541 | .ep_audio_w = 0x01, |
| 542 | }, |
| 543 | [LINE6_TONEPORT_UX2] = { |
| 544 | .id = "TonePortUX2", |
| 545 | .name = "TonePort UX2", |
| 546 | .capabilities = LINE6_CAP_PCM, |
| 547 | .altsetting = 2, /* defaults to 44.1kHz, 16-bit */ |
| 548 | /* no control channel */ |
| 549 | .ep_audio_r = 0x82, |
| 550 | .ep_audio_w = 0x01, |
| 551 | }, |
| 552 | }; |
| 553 | |
| 554 | /* |
| 555 | Probe USB device. |
| 556 | */ |
| 557 | static int toneport_probe(struct usb_interface *interface, |
| 558 | const struct usb_device_id *id) |
| 559 | { |
Chris Rorvick | 12865ca | 2015-02-07 10:43:19 -0600 | [diff] [blame] | 560 | return line6_probe(interface, id, "Line6-TonePort", |
Takashi Iwai | 85a9339 | 2015-01-19 15:54:00 +0100 | [diff] [blame] | 561 | &toneport_properties_table[id->driver_info], |
Takashi Iwai | aca514b | 2015-01-25 18:36:29 +0100 | [diff] [blame] | 562 | toneport_init, sizeof(struct usb_line6_toneport)); |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | static struct usb_driver toneport_driver = { |
| 566 | .name = KBUILD_MODNAME, |
| 567 | .probe = toneport_probe, |
| 568 | .disconnect = line6_disconnect, |
| 569 | #ifdef CONFIG_PM |
| 570 | .suspend = line6_suspend, |
| 571 | .resume = line6_resume, |
| 572 | .reset_resume = toneport_reset_resume, |
| 573 | #endif |
| 574 | .id_table = toneport_id_table, |
| 575 | }; |
| 576 | |
| 577 | module_usb_driver(toneport_driver); |
| 578 | |
| 579 | MODULE_DESCRIPTION("TonePort USB driver"); |
| 580 | MODULE_LICENSE("GPL"); |