Thomas Gleixner | a10e763 | 2019-05-31 01:09:32 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 2 | /* |
Chris Rorvick | c078a4a | 2015-01-20 02:20:50 -0600 | [diff] [blame] | 3 | * Line 6 Linux USB driver |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 4 | * |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 5 | * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 6 | * Emil Myhrman (emil.myhrman@gmail.com) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 7 | */ |
| 8 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 9 | #include <linux/wait.h> |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 10 | #include <linux/usb.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/module.h> |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 13 | #include <linux/leds.h> |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 14 | #include <sound/core.h> |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 15 | #include <sound/control.h> |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 16 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 17 | #include "capture.h" |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 18 | #include "driver.h" |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 19 | #include "playback.h" |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 20 | |
| 21 | enum 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 Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 31 | struct usb_line6_toneport; |
| 32 | |
| 33 | struct toneport_led { |
| 34 | struct led_classdev dev; |
| 35 | char name[64]; |
| 36 | struct usb_line6_toneport *toneport; |
| 37 | bool registered; |
| 38 | }; |
| 39 | |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 40 | struct usb_line6_toneport { |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 41 | /* Generic Line 6 USB data */ |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 42 | struct usb_line6 line6; |
| 43 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 44 | /* Source selector */ |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 45 | int source; |
| 46 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 47 | /* Serial number of device */ |
Chris Rorvick | 12b0015 | 2015-02-10 23:03:16 -0600 | [diff] [blame] | 48 | u32 serial_number; |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 49 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 50 | /* Firmware version (x 100) */ |
Chris Rorvick | 0e80615 | 2015-02-10 23:03:17 -0600 | [diff] [blame] | 51 | u8 firmware_version; |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 52 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 53 | /* Device type */ |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 54 | enum line6_device_type type; |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 55 | |
| 56 | /* LED instances */ |
| 57 | struct toneport_led leds[2]; |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 58 | }; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 59 | |
Takashi Iwai | f23a09ee | 2019-05-28 09:05:31 +0200 | [diff] [blame] | 60 | #define line6_to_toneport(x) container_of(x, struct usb_line6_toneport, line6) |
| 61 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 62 | static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2); |
| 63 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 64 | #define TONEPORT_PCM_DELAY 1 |
| 65 | |
Takashi Iwai | 37cc306 | 2020-01-03 09:17:06 +0100 | [diff] [blame] | 66 | static const struct snd_ratden toneport_ratden = { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 67 | .num_min = 44100, |
| 68 | .num_max = 44100, |
| 69 | .num_step = 1, |
| 70 | .den = 1 |
| 71 | }; |
| 72 | |
| 73 | static struct line6_pcm_properties toneport_pcm_properties = { |
Takashi Iwai | 1263f61 | 2015-01-28 15:08:59 +0100 | [diff] [blame] | 74 | .playback_hw = { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 75 | .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 Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 80 | 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 Iwai | 1263f61 | 2015-01-28 15:08:59 +0100 | [diff] [blame] | 92 | .capture_hw = { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 93 | .info = (SNDRV_PCM_INFO_MMAP | |
| 94 | SNDRV_PCM_INFO_INTERLEAVED | |
| 95 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 96 | SNDRV_PCM_INFO_MMAP_VALID | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 97 | 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 Iwai | 1263f61 | 2015-01-28 15:08:59 +0100 | [diff] [blame] | 109 | .rates = { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 110 | .nrats = 1, |
| 111 | .rats = &toneport_ratden}, |
Andrej Krutak | 97d78ac | 2016-09-18 20:59:24 +0200 | [diff] [blame] | 112 | .bytes_per_channel = 2 |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 113 | }; |
| 114 | |
Stefan Hajnoczi | 709b2fa | 2013-01-11 23:08:13 +0100 | [diff] [blame] | 115 | static const struct { |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 116 | const char *name; |
| 117 | int code; |
Stefan Hajnoczi | 709b2fa | 2013-01-11 23:08:13 +0100 | [diff] [blame] | 118 | } toneport_source_info[] = { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 119 | {"Microphone", 0x0a01}, |
| 120 | {"Line", 0x0801}, |
| 121 | {"Instrument", 0x0b01}, |
| 122 | {"Inst & Mic", 0x0901} |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 123 | }; |
| 124 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 125 | static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2) |
| 126 | { |
| 127 | int ret; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 128 | |
Greg Kroah-Hartman | 6d2d427 | 2020-09-23 15:43:46 +0200 | [diff] [blame] | 129 | 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-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 133 | |
Greg Kroah-Hartman | 6d2d427 | 2020-09-23 15:43:46 +0200 | [diff] [blame] | 134 | if (ret) { |
Greg Kroah-Hartman | d86938f | 2012-04-20 16:53:32 -0700 | [diff] [blame] | 135 | dev_err(&usbdev->dev, "send failed (error %d)\n", ret); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 136 | return ret; |
| 137 | } |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 142 | /* monitor info callback */ |
| 143 | static 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 */ |
| 154 | static 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 Snitselaar | f3c5261 | 2014-04-24 00:31:48 -0700 | [diff] [blame] | 158 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 159 | ucontrol->value.integer.value[0] = line6pcm->volume_monitor; |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | /* monitor put callback */ |
| 164 | static 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 Iwai | 247d95e | 2015-01-27 16:42:14 +0100 | [diff] [blame] | 168 | int err; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 169 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 170 | if (ucontrol->value.integer.value[0] == line6pcm->volume_monitor) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 171 | return 0; |
| 172 | |
| 173 | line6pcm->volume_monitor = ucontrol->value.integer.value[0]; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 174 | |
Takashi Iwai | 247d95e | 2015-01-27 16:42:14 +0100 | [diff] [blame] | 175 | if (line6pcm->volume_monitor > 0) { |
Andrej Krutak | f56742c | 2016-09-18 20:59:25 +0200 | [diff] [blame] | 176 | err = line6_pcm_acquire(line6pcm, LINE6_STREAM_MONITOR, true); |
Takashi Iwai | 247d95e | 2015-01-27 16:42:14 +0100 | [diff] [blame] | 177 | if (err < 0) { |
| 178 | line6pcm->volume_monitor = 0; |
| 179 | line6_pcm_release(line6pcm, LINE6_STREAM_MONITOR); |
| 180 | return err; |
| 181 | } |
| 182 | } else { |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 183 | line6_pcm_release(line6pcm, LINE6_STREAM_MONITOR); |
Takashi Iwai | 247d95e | 2015-01-27 16:42:14 +0100 | [diff] [blame] | 184 | } |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 185 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 186 | return 1; |
| 187 | } |
| 188 | |
| 189 | /* source info callback */ |
| 190 | static 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 Mewes | a6b4699 | 2014-03-24 23:46:31 +0100 | [diff] [blame] | 194 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 195 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 196 | uinfo->count = 1; |
| 197 | uinfo->value.enumerated.items = size; |
| 198 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 199 | if (uinfo->value.enumerated.item >= size) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 200 | 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 */ |
| 209 | static 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 Iwai | f23a09ee | 2019-05-28 09:05:31 +0200 | [diff] [blame] | 213 | struct usb_line6_toneport *toneport = line6_to_toneport(line6pcm->line6); |
| 214 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 215 | ucontrol->value.enumerated.item[0] = toneport->source; |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | /* source put callback */ |
| 220 | static 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 Iwai | f23a09ee | 2019-05-28 09:05:31 +0200 | [diff] [blame] | 224 | struct usb_line6_toneport *toneport = line6_to_toneport(line6pcm->line6); |
Dan Carpenter | c3cb718 | 2013-09-13 11:07:13 +0300 | [diff] [blame] | 225 | unsigned int source; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 226 | |
Dan Carpenter | c3cb718 | 2013-09-13 11:07:13 +0300 | [diff] [blame] | 227 | source = ucontrol->value.enumerated.item[0]; |
| 228 | if (source >= ARRAY_SIZE(toneport_source_info)) |
| 229 | return -EINVAL; |
| 230 | if (source == toneport->source) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 231 | return 0; |
| 232 | |
Dan Carpenter | c3cb718 | 2013-09-13 11:07:13 +0300 | [diff] [blame] | 233 | toneport->source = source; |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 234 | toneport_send_cmd(toneport->line6.usbdev, |
Dan Carpenter | c3cb718 | 2013-09-13 11:07:13 +0300 | [diff] [blame] | 235 | toneport_source_info[source].code, 0x0000); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 236 | return 1; |
| 237 | } |
| 238 | |
Takashi Iwai | 0b074ab | 2019-05-28 08:39:44 +0200 | [diff] [blame] | 239 | static void toneport_startup(struct usb_line6 *line6) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 240 | { |
Andrej Krutak | f56742c | 2016-09-18 20:59:25 +0200 | [diff] [blame] | 241 | line6_pcm_acquire(line6->line6pcm, LINE6_STREAM_MONITOR, true); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | /* control definition */ |
Bhumika Goyal | 49c41e1 | 2017-04-12 18:40:47 +0530 | [diff] [blame] | 245 | static const struct snd_kcontrol_new toneport_control_monitor = { |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 246 | .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 Goyal | 49c41e1 | 2017-04-12 18:40:47 +0530 | [diff] [blame] | 256 | static const struct snd_kcontrol_new toneport_control_source = { |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 257 | .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 Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 266 | /* |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 267 | 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 Rorvick | f2bd242 | 2015-02-07 10:43:18 -0600 | [diff] [blame] | 273 | static bool toneport_has_led(struct usb_line6_toneport *toneport) |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 274 | { |
Chris Rorvick | f2bd242 | 2015-02-07 10:43:18 -0600 | [diff] [blame] | 275 | switch (toneport->type) { |
| 276 | case LINE6_GUITARPORT: |
| 277 | case LINE6_TONEPORT_GX: |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 278 | /* add your device here if you are missing support for the LEDs */ |
Chris Rorvick | f2bd242 | 2015-02-07 10:43:18 -0600 | [diff] [blame] | 279 | return true; |
| 280 | |
| 281 | default: |
| 282 | return false; |
| 283 | } |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 284 | } |
| 285 | |
Jacek Anaszewski | 05b8ccf | 2019-04-06 19:04:44 +0200 | [diff] [blame] | 286 | static const char * const toneport_led_colors[2] = { "red", "green" }; |
| 287 | static const int toneport_led_init_vals[2] = { 0x00, 0x26 }; |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 288 | |
| 289 | static 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 | |
| 296 | static 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 | |
| 304 | static 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 Anaszewski | 05b8ccf | 2019-04-06 19:04:44 +0200 | [diff] [blame] | 315 | dev_name(dev), toneport_led_colors[i]); |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 316 | leddev->name = led->name; |
Jacek Anaszewski | 05b8ccf | 2019-04-06 19:04:44 +0200 | [diff] [blame] | 317 | leddev->brightness = toneport_led_init_vals[i]; |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 318 | 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 | |
| 329 | static 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 Rorvick | 8944460 | 2015-02-07 10:43:17 -0600 | [diff] [blame] | 343 | static 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 Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 357 | /* |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 358 | Setup Toneport device. |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 359 | */ |
Greg Kroah-Hartman | e5c812e | 2019-04-28 18:04:11 +0200 | [diff] [blame] | 360 | static int toneport_setup(struct usb_line6_toneport *toneport) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 361 | { |
Greg Kroah-Hartman | e5c812e | 2019-04-28 18:04:11 +0200 | [diff] [blame] | 362 | u32 *ticks; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 363 | struct usb_line6 *line6 = &toneport->line6; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 364 | struct usb_device *usbdev = line6->usbdev; |
| 365 | |
Greg Kroah-Hartman | e5c812e | 2019-04-28 18:04:11 +0200 | [diff] [blame] | 366 | ticks = kmalloc(sizeof(*ticks), GFP_KERNEL); |
| 367 | if (!ticks) |
| 368 | return -ENOMEM; |
| 369 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 370 | /* sync time on device with host: */ |
Arnd Bergmann | a8eaad7 | 2018-06-18 17:41:01 +0200 | [diff] [blame] | 371 | /* note: 32-bit timestamps overflow in year 2106 */ |
Greg Kroah-Hartman | e5c812e | 2019-04-28 18:04:11 +0200 | [diff] [blame] | 372 | *ticks = (u32)ktime_get_real_seconds(); |
| 373 | line6_write_data(line6, 0x80c6, ticks, 4); |
| 374 | kfree(ticks); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 375 | |
| 376 | /* enable device: */ |
| 377 | toneport_send_cmd(usbdev, 0x0301, 0x0000); |
| 378 | |
| 379 | /* initialize source select: */ |
Chris Rorvick | 8944460 | 2015-02-07 10:43:17 -0600 | [diff] [blame] | 380 | if (toneport_has_source_select(toneport)) |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 381 | toneport_send_cmd(usbdev, |
| 382 | toneport_source_info[toneport->source].code, |
| 383 | 0x0000); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 384 | |
Chris Rorvick | f2bd242 | 2015-02-07 10:43:18 -0600 | [diff] [blame] | 385 | if (toneport_has_led(toneport)) |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 386 | toneport_update_led(toneport); |
Takashi Iwai | 6dd1c05 | 2015-01-20 09:40:20 +0100 | [diff] [blame] | 387 | |
Takashi Iwai | 0b074ab | 2019-05-28 08:39:44 +0200 | [diff] [blame] | 388 | schedule_delayed_work(&toneport->line6.startup_work, |
Takashi Iwai | 7f84ff6 | 2019-05-08 15:01:24 +0200 | [diff] [blame] | 389 | msecs_to_jiffies(TONEPORT_PCM_DELAY * 1000)); |
Greg Kroah-Hartman | e5c812e | 2019-04-28 18:04:11 +0200 | [diff] [blame] | 390 | return 0; |
Markus Grabner | 1027f47 | 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 | f23a09ee | 2019-05-28 09:05:31 +0200 | [diff] [blame] | 398 | struct usb_line6_toneport *toneport = line6_to_toneport(line6); |
Chris Rorvick | d29b854 | 2015-01-12 12:43:00 -0800 | [diff] [blame] | 399 | |
Chris Rorvick | f2bd242 | 2015-02-07 10:43:18 -0600 | [diff] [blame] | 400 | if (toneport_has_led(toneport)) |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 401 | toneport_remove_leds(toneport); |
Chris Rorvick | d29b854 | 2015-01-12 12:43:00 -0800 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | |
| 405 | /* |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 406 | Try to init Toneport device. |
| 407 | */ |
Takashi Iwai | f66fd99 | 2015-01-25 18:22:58 +0100 | [diff] [blame] | 408 | static int toneport_init(struct usb_line6 *line6, |
| 409 | const struct usb_device_id *id) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 410 | { |
| 411 | int err; |
Takashi Iwai | f23a09ee | 2019-05-28 09:05:31 +0200 | [diff] [blame] | 412 | struct usb_line6_toneport *toneport = line6_to_toneport(line6); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 413 | |
Takashi Iwai | f66fd99 | 2015-01-25 18:22:58 +0100 | [diff] [blame] | 414 | toneport->type = id->driver_info; |
Takashi Iwai | 6dd1c05 | 2015-01-20 09:40:20 +0100 | [diff] [blame] | 415 | |
Chris Rorvick | a46c467 | 2015-01-12 12:42:59 -0800 | [diff] [blame] | 416 | line6->disconnect = line6_toneport_disconnect; |
Takashi Iwai | 0b074ab | 2019-05-28 08:39:44 +0200 | [diff] [blame] | 417 | line6->startup = toneport_startup; |
Chris Rorvick | a46c467 | 2015-01-12 12:42:59 -0800 | [diff] [blame] | 418 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 419 | /* initialize PCM subsystem: */ |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 420 | err = line6_init_pcm(line6, &toneport_pcm_properties); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 421 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 422 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 423 | |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 424 | /* register monitor control: */ |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 425 | err = snd_ctl_add(line6->card, |
| 426 | snd_ctl_new1(&toneport_control_monitor, |
| 427 | line6->line6pcm)); |
| 428 | if (err < 0) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 429 | return err; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 430 | |
| 431 | /* register source select control: */ |
Chris Rorvick | 8944460 | 2015-02-07 10:43:17 -0600 | [diff] [blame] | 432 | if (toneport_has_source_select(toneport)) { |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 433 | err = |
| 434 | snd_ctl_add(line6->card, |
| 435 | snd_ctl_new1(&toneport_control_source, |
| 436 | line6->line6pcm)); |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 437 | if (err < 0) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 438 | return err; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 439 | } |
| 440 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 441 | line6_read_serial_number(line6, &toneport->serial_number); |
| 442 | line6_read_data(line6, 0x80c2, &toneport->firmware_version, 1); |
| 443 | |
Chris Rorvick | f2bd242 | 2015-02-07 10:43:18 -0600 | [diff] [blame] | 444 | if (toneport_has_led(toneport)) { |
Takashi Iwai | f44edd7 | 2015-01-20 09:36:31 +0100 | [diff] [blame] | 445 | err = toneport_init_leds(toneport); |
Takashi Iwai | b2a3b02 | 2015-01-19 16:08:02 +0100 | [diff] [blame] | 446 | if (err < 0) |
| 447 | return err; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 448 | } |
| 449 | |
Greg Kroah-Hartman | e5c812e | 2019-04-28 18:04:11 +0200 | [diff] [blame] | 450 | err = toneport_setup(toneport); |
| 451 | if (err) |
| 452 | return err; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 453 | |
Takashi Iwai | 85a9339 | 2015-01-19 15:54:00 +0100 | [diff] [blame] | 454 | /* register audio system: */ |
| 455 | return snd_card_register(line6->card); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 456 | } |
| 457 | |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 458 | #ifdef CONFIG_PM |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 459 | /* |
| 460 | Resume Toneport device after reset. |
| 461 | */ |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 462 | static int toneport_reset_resume(struct usb_interface *interface) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 463 | { |
Greg Kroah-Hartman | e5c812e | 2019-04-28 18:04:11 +0200 | [diff] [blame] | 464 | int err; |
| 465 | |
| 466 | err = toneport_setup(usb_get_intfdata(interface)); |
| 467 | if (err) |
| 468 | return err; |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 469 | return line6_resume(interface); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 470 | } |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 471 | #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 */ |
| 477 | static 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 | |
| 488 | MODULE_DEVICE_TABLE(usb, toneport_id_table); |
| 489 | |
| 490 | static 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 | */ |
| 559 | static int toneport_probe(struct usb_interface *interface, |
| 560 | const struct usb_device_id *id) |
| 561 | { |
Chris Rorvick | 12865ca | 2015-02-07 10:43:19 -0600 | [diff] [blame] | 562 | return line6_probe(interface, id, "Line6-TonePort", |
Takashi Iwai | 85a9339 | 2015-01-19 15:54:00 +0100 | [diff] [blame] | 563 | &toneport_properties_table[id->driver_info], |
Takashi Iwai | aca514b | 2015-01-25 18:36:29 +0100 | [diff] [blame] | 564 | toneport_init, sizeof(struct usb_line6_toneport)); |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | static 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 | |
| 579 | module_usb_driver(toneport_driver); |
| 580 | |
| 581 | MODULE_DESCRIPTION("TonePort USB driver"); |
| 582 | MODULE_LICENSE("GPL"); |