Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | * USB Audio Driver for ALSA |
| 3 | * |
| 4 | * Quirks and vendor-specific extensions for mixer interfaces |
| 5 | * |
| 6 | * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de> |
| 7 | * |
| 8 | * Many codes borrowed from audio.c by |
| 9 | * Alan Cox (alan@lxorguk.ukuu.org.uk) |
| 10 | * Thomas Sailer (sailer@ife.ee.ethz.ch) |
| 11 | * |
Przemek Rudy | 066624c | 2013-06-27 23:52:33 +0200 | [diff] [blame] | 12 | * Audio Advantage Micro II support added by: |
| 13 | * Przemek Rudy (prudy1@o2.pl) |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify |
| 16 | * it under the terms of the GNU General Public License as published by |
| 17 | * the Free Software Foundation; either version 2 of the License, or |
| 18 | * (at your option) any later version. |
| 19 | * |
| 20 | * This program is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | * GNU General Public License for more details. |
| 24 | * |
| 25 | * You should have received a copy of the GNU General Public License |
| 26 | * along with this program; if not, write to the Free Software |
| 27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 28 | */ |
| 29 | |
| 30 | #include <linux/init.h> |
Stephen Rothwell | 36db045 | 2010-03-29 16:02:50 +1100 | [diff] [blame] | 31 | #include <linux/slab.h> |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 32 | #include <linux/usb.h> |
| 33 | #include <linux/usb/audio.h> |
| 34 | |
Przemek Rudy | 066624c | 2013-06-27 23:52:33 +0200 | [diff] [blame] | 35 | #include <sound/asoundef.h> |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 36 | #include <sound/core.h> |
| 37 | #include <sound/control.h> |
| 38 | #include <sound/hwdep.h> |
| 39 | #include <sound/info.h> |
| 40 | |
| 41 | #include "usbaudio.h" |
Daniel Mack | f0b5e63 | 2010-03-11 21:13:23 +0100 | [diff] [blame] | 42 | #include "mixer.h" |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 43 | #include "mixer_quirks.h" |
Chris J Arges | 76b188c | 2014-11-12 12:07:02 -0600 | [diff] [blame] | 44 | #include "mixer_scarlett.h" |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 45 | #include "helper.h" |
| 46 | |
Daniel Mack | d5a0bf6cc | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 47 | extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl; |
| 48 | |
Mark Hills | b71dad18 | 2012-06-09 13:16:38 +0100 | [diff] [blame] | 49 | struct std_mono_table { |
| 50 | unsigned int unitid, control, cmask; |
| 51 | int val_type; |
| 52 | const char *name; |
| 53 | snd_kcontrol_tlv_rw_t *tlv_callback; |
| 54 | }; |
| 55 | |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 56 | /* This function allows for the creation of standard UAC controls. |
| 57 | * See the quirks for M-Audio FTUs or Ebox-44. |
| 58 | * If you don't want to set a TLV callback pass NULL. |
| 59 | * |
| 60 | * Since there doesn't seem to be a devices that needs a multichannel |
| 61 | * version, we keep it mono for simplicity. |
| 62 | */ |
Eldad Zack | 9f81410 | 2012-11-28 23:55:35 +0100 | [diff] [blame] | 63 | static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer, |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 64 | unsigned int unitid, |
| 65 | unsigned int control, |
| 66 | unsigned int cmask, |
| 67 | int val_type, |
Eldad Zack | 9f81410 | 2012-11-28 23:55:35 +0100 | [diff] [blame] | 68 | unsigned int idx_off, |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 69 | const char *name, |
| 70 | snd_kcontrol_tlv_rw_t *tlv_callback) |
| 71 | { |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 72 | struct usb_mixer_elem_info *cval; |
| 73 | struct snd_kcontrol *kctl; |
| 74 | |
| 75 | cval = kzalloc(sizeof(*cval), GFP_KERNEL); |
| 76 | if (!cval) |
| 77 | return -ENOMEM; |
| 78 | |
Takashi Iwai | 3360b84 | 2014-11-18 11:47:04 +0100 | [diff] [blame] | 79 | snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid); |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 80 | cval->val_type = val_type; |
| 81 | cval->channels = 1; |
| 82 | cval->control = control; |
| 83 | cval->cmask = cmask; |
Eldad Zack | 9f81410 | 2012-11-28 23:55:35 +0100 | [diff] [blame] | 84 | cval->idx_off = idx_off; |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 85 | |
Mark Hills | 7df4a69 | 2012-05-11 18:31:55 +0100 | [diff] [blame] | 86 | /* get_min_max() is called only for integer volumes later, |
| 87 | * so provide a short-cut for booleans */ |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 88 | cval->min = 0; |
| 89 | cval->max = 1; |
| 90 | cval->res = 0; |
| 91 | cval->dBmin = 0; |
| 92 | cval->dBmax = 0; |
| 93 | |
| 94 | /* Create control */ |
| 95 | kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval); |
| 96 | if (!kctl) { |
| 97 | kfree(cval); |
| 98 | return -ENOMEM; |
| 99 | } |
| 100 | |
| 101 | /* Set name */ |
| 102 | snprintf(kctl->id.name, sizeof(kctl->id.name), name); |
Chris J Arges | eef9045 | 2014-11-12 12:07:01 -0600 | [diff] [blame] | 103 | kctl->private_free = snd_usb_mixer_elem_free; |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 104 | |
| 105 | /* set TLV */ |
| 106 | if (tlv_callback) { |
| 107 | kctl->tlv.c = tlv_callback; |
| 108 | kctl->vd[0].access |= |
| 109 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | |
| 110 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; |
| 111 | } |
| 112 | /* Add control to mixer */ |
Takashi Iwai | 3360b84 | 2014-11-18 11:47:04 +0100 | [diff] [blame] | 113 | return snd_usb_mixer_add_control(&cval->head, kctl); |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 114 | } |
| 115 | |
Eldad Zack | 9f81410 | 2012-11-28 23:55:35 +0100 | [diff] [blame] | 116 | static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer, |
| 117 | unsigned int unitid, |
| 118 | unsigned int control, |
| 119 | unsigned int cmask, |
| 120 | int val_type, |
| 121 | const char *name, |
| 122 | snd_kcontrol_tlv_rw_t *tlv_callback) |
| 123 | { |
| 124 | return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask, |
| 125 | val_type, 0 /* Offset */, name, tlv_callback); |
| 126 | } |
| 127 | |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 128 | /* |
Mark Hills | b71dad18 | 2012-06-09 13:16:38 +0100 | [diff] [blame] | 129 | * Create a set of standard UAC controls from a table |
| 130 | */ |
| 131 | static int snd_create_std_mono_table(struct usb_mixer_interface *mixer, |
| 132 | struct std_mono_table *t) |
| 133 | { |
| 134 | int err; |
| 135 | |
| 136 | while (t->name != NULL) { |
| 137 | err = snd_create_std_mono_ctl(mixer, t->unitid, t->control, |
| 138 | t->cmask, t->val_type, t->name, t->tlv_callback); |
| 139 | if (err < 0) |
| 140 | return err; |
| 141 | t++; |
| 142 | } |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
Takashi Iwai | 9cf3689 | 2014-11-18 12:58:51 +0100 | [diff] [blame] | 147 | static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer, |
| 148 | int id, |
| 149 | usb_mixer_elem_resume_func_t resume, |
| 150 | const struct snd_kcontrol_new *knew, |
| 151 | struct usb_mixer_elem_list **listp) |
| 152 | { |
| 153 | struct usb_mixer_elem_list *list; |
| 154 | struct snd_kcontrol *kctl; |
| 155 | |
| 156 | list = kzalloc(sizeof(*list), GFP_KERNEL); |
| 157 | if (!list) |
| 158 | return -ENOMEM; |
| 159 | if (listp) |
| 160 | *listp = list; |
| 161 | list->mixer = mixer; |
| 162 | list->id = id; |
| 163 | list->resume = resume; |
| 164 | kctl = snd_ctl_new1(knew, list); |
| 165 | if (!kctl) { |
| 166 | kfree(list); |
| 167 | return -ENOMEM; |
| 168 | } |
| 169 | kctl->private_free = snd_usb_mixer_elem_free; |
| 170 | return snd_usb_mixer_add_control(list, kctl); |
| 171 | } |
| 172 | |
Mark Hills | b71dad18 | 2012-06-09 13:16:38 +0100 | [diff] [blame] | 173 | /* |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 174 | * Sound Blaster remote control configuration |
| 175 | * |
| 176 | * format of remote control data: |
| 177 | * Extigy: xx 00 |
| 178 | * Audigy 2 NX: 06 80 xx 00 00 00 |
| 179 | * Live! 24-bit: 06 80 xx yy 22 83 |
| 180 | */ |
| 181 | static const struct rc_config { |
| 182 | u32 usb_id; |
| 183 | u8 offset; |
| 184 | u8 length; |
| 185 | u8 packet_length; |
| 186 | u8 min_packet_length; /* minimum accepted length of the URB result */ |
| 187 | u8 mute_mixer_id; |
| 188 | u32 mute_code; |
| 189 | } rc_configs[] = { |
| 190 | { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */ |
| 191 | { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */ |
| 192 | { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */ |
Mandar Joshi | ca8dc34 | 2010-11-02 14:43:19 +0000 | [diff] [blame] | 193 | { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */ |
Mathieu Bouffard | 7cdd8d7 | 2011-05-18 17:09:17 +0200 | [diff] [blame] | 194 | { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */ |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 195 | { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */ |
| 196 | }; |
| 197 | |
| 198 | static void snd_usb_soundblaster_remote_complete(struct urb *urb) |
| 199 | { |
| 200 | struct usb_mixer_interface *mixer = urb->context; |
| 201 | const struct rc_config *rc = mixer->rc_cfg; |
| 202 | u32 code; |
| 203 | |
| 204 | if (urb->status < 0 || urb->actual_length < rc->min_packet_length) |
| 205 | return; |
| 206 | |
| 207 | code = mixer->rc_buffer[rc->offset]; |
| 208 | if (rc->length == 2) |
| 209 | code |= mixer->rc_buffer[rc->offset + 1] << 8; |
| 210 | |
| 211 | /* the Mute button actually changes the mixer control */ |
| 212 | if (code == rc->mute_code) |
| 213 | snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id); |
| 214 | mixer->rc_code = code; |
| 215 | wmb(); |
| 216 | wake_up(&mixer->rc_waitq); |
| 217 | } |
| 218 | |
| 219 | static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf, |
| 220 | long count, loff_t *offset) |
| 221 | { |
| 222 | struct usb_mixer_interface *mixer = hw->private_data; |
| 223 | int err; |
| 224 | u32 rc_code; |
| 225 | |
| 226 | if (count != 1 && count != 4) |
| 227 | return -EINVAL; |
| 228 | err = wait_event_interruptible(mixer->rc_waitq, |
| 229 | (rc_code = xchg(&mixer->rc_code, 0)) != 0); |
| 230 | if (err == 0) { |
| 231 | if (count == 1) |
| 232 | err = put_user(rc_code, buf); |
| 233 | else |
| 234 | err = put_user(rc_code, (u32 __user *)buf); |
| 235 | } |
| 236 | return err < 0 ? err : count; |
| 237 | } |
| 238 | |
| 239 | static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file, |
| 240 | poll_table *wait) |
| 241 | { |
| 242 | struct usb_mixer_interface *mixer = hw->private_data; |
| 243 | |
| 244 | poll_wait(file, &mixer->rc_waitq, wait); |
| 245 | return mixer->rc_code ? POLLIN | POLLRDNORM : 0; |
| 246 | } |
| 247 | |
| 248 | static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer) |
| 249 | { |
| 250 | struct snd_hwdep *hwdep; |
| 251 | int err, len, i; |
| 252 | |
| 253 | for (i = 0; i < ARRAY_SIZE(rc_configs); ++i) |
| 254 | if (rc_configs[i].usb_id == mixer->chip->usb_id) |
| 255 | break; |
| 256 | if (i >= ARRAY_SIZE(rc_configs)) |
| 257 | return 0; |
| 258 | mixer->rc_cfg = &rc_configs[i]; |
| 259 | |
| 260 | len = mixer->rc_cfg->packet_length; |
| 261 | |
| 262 | init_waitqueue_head(&mixer->rc_waitq); |
| 263 | err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep); |
| 264 | if (err < 0) |
| 265 | return err; |
| 266 | snprintf(hwdep->name, sizeof(hwdep->name), |
| 267 | "%s remote control", mixer->chip->card->shortname); |
| 268 | hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC; |
| 269 | hwdep->private_data = mixer; |
| 270 | hwdep->ops.read = snd_usb_sbrc_hwdep_read; |
| 271 | hwdep->ops.poll = snd_usb_sbrc_hwdep_poll; |
| 272 | hwdep->exclusive = 1; |
| 273 | |
| 274 | mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL); |
| 275 | if (!mixer->rc_urb) |
| 276 | return -ENOMEM; |
| 277 | mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL); |
| 278 | if (!mixer->rc_setup_packet) { |
| 279 | usb_free_urb(mixer->rc_urb); |
| 280 | mixer->rc_urb = NULL; |
| 281 | return -ENOMEM; |
| 282 | } |
| 283 | mixer->rc_setup_packet->bRequestType = |
| 284 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE; |
| 285 | mixer->rc_setup_packet->bRequest = UAC_GET_MEM; |
| 286 | mixer->rc_setup_packet->wValue = cpu_to_le16(0); |
| 287 | mixer->rc_setup_packet->wIndex = cpu_to_le16(0); |
| 288 | mixer->rc_setup_packet->wLength = cpu_to_le16(len); |
| 289 | usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev, |
| 290 | usb_rcvctrlpipe(mixer->chip->dev, 0), |
| 291 | (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len, |
| 292 | snd_usb_soundblaster_remote_complete, mixer); |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info |
| 297 | |
| 298 | static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 299 | { |
Takashi Iwai | 9cf3689 | 2014-11-18 12:58:51 +0100 | [diff] [blame] | 300 | ucontrol->value.integer.value[0] = kcontrol->private_value >> 8; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 301 | return 0; |
| 302 | } |
| 303 | |
Takashi Iwai | 9cf3689 | 2014-11-18 12:58:51 +0100 | [diff] [blame] | 304 | static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer, |
| 305 | int value, int index) |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 306 | { |
Takashi Iwai | 9cf3689 | 2014-11-18 12:58:51 +0100 | [diff] [blame] | 307 | struct snd_usb_audio *chip = mixer->chip; |
| 308 | int err; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 309 | |
Takashi Iwai | 9cf3689 | 2014-11-18 12:58:51 +0100 | [diff] [blame] | 310 | down_read(&chip->shutdown_rwsem); |
| 311 | if (chip->shutdown) { |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 312 | err = -ENODEV; |
| 313 | goto out; |
| 314 | } |
Takashi Iwai | 9cf3689 | 2014-11-18 12:58:51 +0100 | [diff] [blame] | 315 | if (chip->usb_id == USB_ID(0x041e, 0x3042)) |
| 316 | err = snd_usb_ctl_msg(chip->dev, |
| 317 | usb_sndctrlpipe(chip->dev, 0), 0x24, |
Mandar Joshi | ca8dc34 | 2010-11-02 14:43:19 +0000 | [diff] [blame] | 318 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
Clemens Ladisch | 17d900c | 2011-09-26 21:15:27 +0200 | [diff] [blame] | 319 | !value, 0, NULL, 0); |
Mathieu Bouffard | 7cdd8d7 | 2011-05-18 17:09:17 +0200 | [diff] [blame] | 320 | /* USB X-Fi S51 Pro */ |
Takashi Iwai | 9cf3689 | 2014-11-18 12:58:51 +0100 | [diff] [blame] | 321 | if (chip->usb_id == USB_ID(0x041e, 0x30df)) |
| 322 | err = snd_usb_ctl_msg(chip->dev, |
| 323 | usb_sndctrlpipe(chip->dev, 0), 0x24, |
Mathieu Bouffard | 7cdd8d7 | 2011-05-18 17:09:17 +0200 | [diff] [blame] | 324 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
Clemens Ladisch | 17d900c | 2011-09-26 21:15:27 +0200 | [diff] [blame] | 325 | !value, 0, NULL, 0); |
Mandar Joshi | ca8dc34 | 2010-11-02 14:43:19 +0000 | [diff] [blame] | 326 | else |
Takashi Iwai | 9cf3689 | 2014-11-18 12:58:51 +0100 | [diff] [blame] | 327 | err = snd_usb_ctl_msg(chip->dev, |
| 328 | usb_sndctrlpipe(chip->dev, 0), 0x24, |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 329 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
Clemens Ladisch | 17d900c | 2011-09-26 21:15:27 +0200 | [diff] [blame] | 330 | value, index + 2, NULL, 0); |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 331 | out: |
Takashi Iwai | 9cf3689 | 2014-11-18 12:58:51 +0100 | [diff] [blame] | 332 | up_read(&chip->shutdown_rwsem); |
| 333 | return err; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 334 | } |
| 335 | |
Takashi Iwai | 9cf3689 | 2014-11-18 12:58:51 +0100 | [diff] [blame] | 336 | static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, |
| 337 | struct snd_ctl_elem_value *ucontrol) |
| 338 | { |
| 339 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 340 | struct usb_mixer_interface *mixer = list->mixer; |
| 341 | int index = kcontrol->private_value & 0xff; |
| 342 | int value = ucontrol->value.integer.value[0]; |
| 343 | int old_value = kcontrol->private_value >> 8; |
| 344 | int err; |
| 345 | |
| 346 | if (value > 1) |
| 347 | return -EINVAL; |
| 348 | if (value == old_value) |
| 349 | return 0; |
| 350 | kcontrol->private_value = (value << 8) | index; |
| 351 | err = snd_audigy2nx_led_update(mixer, value, index); |
| 352 | return err < 0 ? err : 1; |
| 353 | } |
| 354 | |
| 355 | static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list) |
| 356 | { |
| 357 | int priv_value = list->kctl->private_value; |
| 358 | |
| 359 | return snd_audigy2nx_led_update(list->mixer, priv_value >> 8, |
| 360 | priv_value & 0xff); |
| 361 | } |
| 362 | |
| 363 | /* name and private_value are set dynamically */ |
| 364 | static struct snd_kcontrol_new snd_audigy2nx_control = { |
| 365 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 366 | .info = snd_audigy2nx_led_info, |
| 367 | .get = snd_audigy2nx_led_get, |
| 368 | .put = snd_audigy2nx_led_put, |
| 369 | }; |
| 370 | |
| 371 | static const char * const snd_audigy2nx_led_names[] = { |
| 372 | "CMSS LED Switch", |
| 373 | "Power LED Switch", |
| 374 | "Dolby Digital LED Switch", |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 375 | }; |
| 376 | |
| 377 | static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer) |
| 378 | { |
| 379 | int i, err; |
| 380 | |
Takashi Iwai | 9cf3689 | 2014-11-18 12:58:51 +0100 | [diff] [blame] | 381 | for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) { |
| 382 | struct snd_kcontrol_new knew; |
| 383 | |
Mandar Joshi | ca8dc34 | 2010-11-02 14:43:19 +0000 | [diff] [blame] | 384 | /* USB X-Fi S51 doesn't have a CMSS LED */ |
| 385 | if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0) |
| 386 | continue; |
Mathieu Bouffard | 7cdd8d7 | 2011-05-18 17:09:17 +0200 | [diff] [blame] | 387 | /* USB X-Fi S51 Pro doesn't have one either */ |
| 388 | if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0) |
| 389 | continue; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 390 | if (i > 1 && /* Live24ext has 2 LEDs only */ |
| 391 | (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || |
Mandar Joshi | ca8dc34 | 2010-11-02 14:43:19 +0000 | [diff] [blame] | 392 | mixer->chip->usb_id == USB_ID(0x041e, 0x3042) || |
Mathieu Bouffard | 7cdd8d7 | 2011-05-18 17:09:17 +0200 | [diff] [blame] | 393 | mixer->chip->usb_id == USB_ID(0x041e, 0x30df) || |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 394 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048))) |
| 395 | break; |
Takashi Iwai | 9cf3689 | 2014-11-18 12:58:51 +0100 | [diff] [blame] | 396 | |
| 397 | knew = snd_audigy2nx_control; |
| 398 | knew.name = snd_audigy2nx_led_names[i]; |
| 399 | knew.private_value = (1 << 8) | i; /* LED on as default */ |
| 400 | err = add_single_ctl_with_resume(mixer, 0, |
| 401 | snd_audigy2nx_led_resume, |
| 402 | &knew, NULL); |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 403 | if (err < 0) |
| 404 | return err; |
| 405 | } |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, |
| 410 | struct snd_info_buffer *buffer) |
| 411 | { |
| 412 | static const struct sb_jack { |
| 413 | int unitid; |
| 414 | const char *name; |
| 415 | } jacks_audigy2nx[] = { |
| 416 | {4, "dig in "}, |
| 417 | {7, "line in"}, |
| 418 | {19, "spk out"}, |
| 419 | {20, "hph out"}, |
| 420 | {-1, NULL} |
| 421 | }, jacks_live24ext[] = { |
| 422 | {4, "line in"}, /* &1=Line, &2=Mic*/ |
| 423 | {3, "hph out"}, /* headphones */ |
| 424 | {0, "RC "}, /* last command, 6 bytes see rc_config above */ |
| 425 | {-1, NULL} |
| 426 | }; |
| 427 | const struct sb_jack *jacks; |
| 428 | struct usb_mixer_interface *mixer = entry->private_data; |
| 429 | int i, err; |
| 430 | u8 buf[3]; |
| 431 | |
| 432 | snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname); |
| 433 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020)) |
| 434 | jacks = jacks_audigy2nx; |
| 435 | else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || |
| 436 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) |
| 437 | jacks = jacks_live24ext; |
| 438 | else |
| 439 | return; |
| 440 | |
| 441 | for (i = 0; jacks[i].name; ++i) { |
| 442 | snd_iprintf(buffer, "%s: ", jacks[i].name); |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 443 | down_read(&mixer->chip->shutdown_rwsem); |
| 444 | if (mixer->chip->shutdown) |
| 445 | err = 0; |
| 446 | else |
| 447 | err = snd_usb_ctl_msg(mixer->chip->dev, |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 448 | usb_rcvctrlpipe(mixer->chip->dev, 0), |
| 449 | UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS | |
| 450 | USB_RECIP_INTERFACE, 0, |
Clemens Ladisch | 17d900c | 2011-09-26 21:15:27 +0200 | [diff] [blame] | 451 | jacks[i].unitid << 8, buf, 3); |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 452 | up_read(&mixer->chip->shutdown_rwsem); |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 453 | if (err == 3 && (buf[0] == 3 || buf[0] == 6)) |
| 454 | snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]); |
| 455 | else |
| 456 | snd_iprintf(buffer, "?\n"); |
| 457 | } |
| 458 | } |
| 459 | |
Vasily Khoruzhick | 44832a7 | 2013-11-13 13:13:35 +0300 | [diff] [blame] | 460 | /* EMU0204 */ |
| 461 | static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol, |
| 462 | struct snd_ctl_elem_info *uinfo) |
| 463 | { |
Takashi Iwai | 7bbd03e | 2014-10-20 18:21:42 +0200 | [diff] [blame] | 464 | static const char * const texts[2] = {"1/2", "3/4"}; |
Vasily Khoruzhick | 44832a7 | 2013-11-13 13:13:35 +0300 | [diff] [blame] | 465 | |
Takashi Iwai | 7bbd03e | 2014-10-20 18:21:42 +0200 | [diff] [blame] | 466 | return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); |
Vasily Khoruzhick | 44832a7 | 2013-11-13 13:13:35 +0300 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol, |
| 470 | struct snd_ctl_elem_value *ucontrol) |
| 471 | { |
| 472 | ucontrol->value.enumerated.item[0] = kcontrol->private_value; |
| 473 | return 0; |
| 474 | } |
| 475 | |
Takashi Iwai | 5f503ee | 2014-11-18 16:11:37 +0100 | [diff] [blame^] | 476 | static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer, |
| 477 | int value) |
Vasily Khoruzhick | 44832a7 | 2013-11-13 13:13:35 +0300 | [diff] [blame] | 478 | { |
Takashi Iwai | 5f503ee | 2014-11-18 16:11:37 +0100 | [diff] [blame^] | 479 | struct snd_usb_audio *chip = mixer->chip; |
| 480 | int err; |
Vasily Khoruzhick | 44832a7 | 2013-11-13 13:13:35 +0300 | [diff] [blame] | 481 | unsigned char buf[2]; |
| 482 | |
Takashi Iwai | 5f503ee | 2014-11-18 16:11:37 +0100 | [diff] [blame^] | 483 | down_read(&chip->shutdown_rwsem); |
Vasily Khoruzhick | 44832a7 | 2013-11-13 13:13:35 +0300 | [diff] [blame] | 484 | if (mixer->chip->shutdown) { |
| 485 | err = -ENODEV; |
| 486 | goto out; |
| 487 | } |
Takashi Iwai | 5f503ee | 2014-11-18 16:11:37 +0100 | [diff] [blame^] | 488 | |
| 489 | buf[0] = 0x01; |
| 490 | buf[1] = value ? 0x02 : 0x01; |
| 491 | err = snd_usb_ctl_msg(chip->dev, |
| 492 | usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR, |
Vasily Khoruzhick | 44832a7 | 2013-11-13 13:13:35 +0300 | [diff] [blame] | 493 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, |
| 494 | 0x0400, 0x0e00, buf, 2); |
| 495 | out: |
Takashi Iwai | 5f503ee | 2014-11-18 16:11:37 +0100 | [diff] [blame^] | 496 | up_read(&chip->shutdown_rwsem); |
| 497 | return err; |
Vasily Khoruzhick | 44832a7 | 2013-11-13 13:13:35 +0300 | [diff] [blame] | 498 | } |
| 499 | |
Takashi Iwai | 5f503ee | 2014-11-18 16:11:37 +0100 | [diff] [blame^] | 500 | static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol, |
| 501 | struct snd_ctl_elem_value *ucontrol) |
| 502 | { |
| 503 | struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 504 | struct usb_mixer_interface *mixer = list->mixer; |
| 505 | unsigned int value = ucontrol->value.enumerated.item[0]; |
| 506 | int err; |
Vasily Khoruzhick | 44832a7 | 2013-11-13 13:13:35 +0300 | [diff] [blame] | 507 | |
Takashi Iwai | 5f503ee | 2014-11-18 16:11:37 +0100 | [diff] [blame^] | 508 | if (value > 1) |
| 509 | return -EINVAL; |
| 510 | |
| 511 | if (value == kcontrol->private_value) |
| 512 | return 0; |
| 513 | |
| 514 | kcontrol->private_value = value; |
| 515 | err = snd_emu0204_ch_switch_update(mixer, value); |
| 516 | return err < 0 ? err : 1; |
| 517 | } |
| 518 | |
| 519 | static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list) |
| 520 | { |
| 521 | return snd_emu0204_ch_switch_update(list->mixer, |
| 522 | list->kctl->private_value); |
| 523 | } |
| 524 | |
| 525 | static struct snd_kcontrol_new snd_emu0204_control = { |
| 526 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 527 | .name = "Front Jack Channels", |
| 528 | .info = snd_emu0204_ch_switch_info, |
| 529 | .get = snd_emu0204_ch_switch_get, |
| 530 | .put = snd_emu0204_ch_switch_put, |
| 531 | .private_value = 0, |
Vasily Khoruzhick | 44832a7 | 2013-11-13 13:13:35 +0300 | [diff] [blame] | 532 | }; |
| 533 | |
| 534 | static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer) |
| 535 | { |
Takashi Iwai | 5f503ee | 2014-11-18 16:11:37 +0100 | [diff] [blame^] | 536 | return add_single_ctl_with_resume(mixer, 0, |
| 537 | snd_emu0204_ch_switch_resume, |
| 538 | &snd_emu0204_control, NULL); |
Vasily Khoruzhick | 44832a7 | 2013-11-13 13:13:35 +0300 | [diff] [blame] | 539 | } |
Takashi Iwai | 5f503ee | 2014-11-18 16:11:37 +0100 | [diff] [blame^] | 540 | |
Denis Washington | 1d31aff | 2012-12-11 11:38:32 +0100 | [diff] [blame] | 541 | /* ASUS Xonar U1 / U3 controls */ |
| 542 | |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 543 | static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol, |
| 544 | struct snd_ctl_elem_value *ucontrol) |
| 545 | { |
| 546 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 547 | |
| 548 | ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02); |
| 549 | return 0; |
| 550 | } |
| 551 | |
| 552 | static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol, |
| 553 | struct snd_ctl_elem_value *ucontrol) |
| 554 | { |
| 555 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 556 | u8 old_status, new_status; |
| 557 | int err, changed; |
| 558 | |
| 559 | old_status = mixer->xonar_u1_status; |
| 560 | if (ucontrol->value.integer.value[0]) |
| 561 | new_status = old_status | 0x02; |
| 562 | else |
| 563 | new_status = old_status & ~0x02; |
| 564 | changed = new_status != old_status; |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 565 | down_read(&mixer->chip->shutdown_rwsem); |
| 566 | if (mixer->chip->shutdown) |
| 567 | err = -ENODEV; |
| 568 | else |
| 569 | err = snd_usb_ctl_msg(mixer->chip->dev, |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 570 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x08, |
| 571 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
Clemens Ladisch | 17d900c | 2011-09-26 21:15:27 +0200 | [diff] [blame] | 572 | 50, 0, &new_status, 1); |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 573 | up_read(&mixer->chip->shutdown_rwsem); |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 574 | if (err < 0) |
| 575 | return err; |
| 576 | mixer->xonar_u1_status = new_status; |
| 577 | return changed; |
| 578 | } |
| 579 | |
| 580 | static struct snd_kcontrol_new snd_xonar_u1_output_switch = { |
| 581 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 582 | .name = "Digital Playback Switch", |
| 583 | .info = snd_ctl_boolean_mono_info, |
| 584 | .get = snd_xonar_u1_switch_get, |
| 585 | .put = snd_xonar_u1_switch_put, |
| 586 | }; |
| 587 | |
| 588 | static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer) |
| 589 | { |
| 590 | int err; |
| 591 | |
| 592 | err = snd_ctl_add(mixer->chip->card, |
| 593 | snd_ctl_new1(&snd_xonar_u1_output_switch, mixer)); |
| 594 | if (err < 0) |
| 595 | return err; |
| 596 | mixer->xonar_u1_status = 0x05; |
| 597 | return 0; |
| 598 | } |
| 599 | |
Damien Zammit | d497a82 | 2014-11-12 01:09:54 +1100 | [diff] [blame] | 600 | /* Digidesign Mbox 1 clock source switch (internal/spdif) */ |
| 601 | |
| 602 | static int snd_mbox1_switch_get(struct snd_kcontrol *kctl, |
| 603 | struct snd_ctl_elem_value *ucontrol) |
| 604 | { |
| 605 | ucontrol->value.enumerated.item[0] = kctl->private_value; |
| 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | static int snd_mbox1_switch_put(struct snd_kcontrol *kctl, |
| 610 | struct snd_ctl_elem_value *ucontrol) |
| 611 | { |
| 612 | struct snd_usb_audio *chip; |
| 613 | struct usb_mixer_interface *mixer; |
| 614 | int err; |
| 615 | bool cur_val, new_val; |
| 616 | unsigned char buff[3]; |
| 617 | |
| 618 | cur_val = kctl->private_value; |
| 619 | new_val = ucontrol->value.enumerated.item[0]; |
| 620 | |
| 621 | mixer = snd_kcontrol_chip(kctl); |
| 622 | if (snd_BUG_ON(!mixer)) |
| 623 | return -EINVAL; |
| 624 | |
| 625 | chip = mixer->chip; |
| 626 | if (snd_BUG_ON(!chip)) |
| 627 | return -EINVAL; |
| 628 | |
| 629 | if (cur_val == new_val) |
| 630 | return 0; |
| 631 | |
| 632 | down_read(&chip->shutdown_rwsem); |
| 633 | if (chip->shutdown) { |
| 634 | err = -ENODEV; |
| 635 | goto err; |
| 636 | } |
| 637 | |
| 638 | /* Prepare for magic command to toggle clock source */ |
| 639 | err = snd_usb_ctl_msg(chip->dev, |
| 640 | usb_rcvctrlpipe(chip->dev, 0), 0x81, |
| 641 | USB_DIR_IN | |
| 642 | USB_TYPE_CLASS | |
| 643 | USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1); |
| 644 | if (err < 0) |
| 645 | goto err; |
| 646 | err = snd_usb_ctl_msg(chip->dev, |
| 647 | usb_rcvctrlpipe(chip->dev, 0), 0x81, |
| 648 | USB_DIR_IN | |
| 649 | USB_TYPE_CLASS | |
| 650 | USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3); |
| 651 | if (err < 0) |
| 652 | goto err; |
| 653 | |
| 654 | /* 2 possibilities: Internal -> send sample rate |
| 655 | * S/PDIF sync -> send zeroes |
| 656 | * NB: Sample rate locked to 48kHz on purpose to |
| 657 | * prevent user from resetting the sample rate |
| 658 | * while S/PDIF sync is enabled and confusing |
| 659 | * this configuration. |
| 660 | */ |
| 661 | if (new_val == 0) { |
| 662 | buff[0] = 0x80; |
| 663 | buff[1] = 0xbb; |
| 664 | buff[2] = 0x00; |
| 665 | } else { |
| 666 | buff[0] = buff[1] = buff[2] = 0x00; |
| 667 | } |
| 668 | |
| 669 | /* Send the magic command to toggle the clock source */ |
| 670 | err = snd_usb_ctl_msg(chip->dev, |
| 671 | usb_sndctrlpipe(chip->dev, 0), 0x1, |
| 672 | USB_TYPE_CLASS | |
| 673 | USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3); |
| 674 | if (err < 0) |
| 675 | goto err; |
| 676 | err = snd_usb_ctl_msg(chip->dev, |
| 677 | usb_rcvctrlpipe(chip->dev, 0), 0x81, |
| 678 | USB_DIR_IN | |
| 679 | USB_TYPE_CLASS | |
| 680 | USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3); |
| 681 | if (err < 0) |
| 682 | goto err; |
| 683 | err = snd_usb_ctl_msg(chip->dev, |
| 684 | usb_rcvctrlpipe(chip->dev, 0), 0x81, |
| 685 | USB_DIR_IN | |
| 686 | USB_TYPE_CLASS | |
| 687 | USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3); |
| 688 | if (err < 0) |
| 689 | goto err; |
| 690 | kctl->private_value = new_val; |
| 691 | |
| 692 | err: |
| 693 | up_read(&chip->shutdown_rwsem); |
| 694 | return err < 0 ? err : 1; |
| 695 | } |
| 696 | |
| 697 | static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol, |
| 698 | struct snd_ctl_elem_info *uinfo) |
| 699 | { |
| 700 | static const char *const texts[2] = { |
| 701 | "Internal", |
| 702 | "S/PDIF" |
| 703 | }; |
| 704 | |
| 705 | return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); |
| 706 | } |
| 707 | |
| 708 | static struct snd_kcontrol_new snd_mbox1_switch = { |
| 709 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 710 | .name = "Clock Source", |
| 711 | .index = 0, |
| 712 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 713 | .info = snd_mbox1_switch_info, |
| 714 | .get = snd_mbox1_switch_get, |
| 715 | .put = snd_mbox1_switch_put, |
| 716 | .private_value = 0 |
| 717 | }; |
| 718 | |
| 719 | static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer) |
| 720 | { |
| 721 | return snd_ctl_add(mixer->chip->card, |
| 722 | snd_ctl_new1(&snd_mbox1_switch, mixer)); |
| 723 | } |
| 724 | |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 725 | /* Native Instruments device quirks */ |
| 726 | |
| 727 | #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex)) |
| 728 | |
| 729 | static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol, |
| 730 | struct snd_ctl_elem_value *ucontrol) |
| 731 | { |
| 732 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 733 | struct usb_device *dev = mixer->chip->dev; |
| 734 | u8 bRequest = (kcontrol->private_value >> 16) & 0xff; |
| 735 | u16 wIndex = kcontrol->private_value & 0xffff; |
| 736 | u8 tmp; |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 737 | int ret; |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 738 | |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 739 | down_read(&mixer->chip->shutdown_rwsem); |
| 740 | if (mixer->chip->shutdown) |
| 741 | ret = -ENODEV; |
| 742 | else |
Takashi Iwai | 01cb156 | 2014-11-20 21:39:14 +0100 | [diff] [blame] | 743 | ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest, |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 744 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
Eldad Zack | 889d668 | 2013-04-05 20:49:46 +0200 | [diff] [blame] | 745 | 0, wIndex, |
Takashi Iwai | 01cb156 | 2014-11-20 21:39:14 +0100 | [diff] [blame] | 746 | &tmp, sizeof(tmp)); |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 747 | up_read(&mixer->chip->shutdown_rwsem); |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 748 | |
| 749 | if (ret < 0) { |
Takashi Iwai | 0ba41d9 | 2014-02-26 13:02:17 +0100 | [diff] [blame] | 750 | dev_err(&dev->dev, |
| 751 | "unable to issue vendor read request (ret = %d)", ret); |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 752 | return ret; |
| 753 | } |
| 754 | |
| 755 | ucontrol->value.integer.value[0] = tmp; |
| 756 | |
| 757 | return 0; |
| 758 | } |
| 759 | |
| 760 | static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol, |
| 761 | struct snd_ctl_elem_value *ucontrol) |
| 762 | { |
| 763 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 764 | struct usb_device *dev = mixer->chip->dev; |
| 765 | u8 bRequest = (kcontrol->private_value >> 16) & 0xff; |
| 766 | u16 wIndex = kcontrol->private_value & 0xffff; |
| 767 | u16 wValue = ucontrol->value.integer.value[0]; |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 768 | int ret; |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 769 | |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 770 | down_read(&mixer->chip->shutdown_rwsem); |
| 771 | if (mixer->chip->shutdown) |
| 772 | ret = -ENODEV; |
| 773 | else |
| 774 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), bRequest, |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 775 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, |
Eldad Zack | 889d668 | 2013-04-05 20:49:46 +0200 | [diff] [blame] | 776 | wValue, wIndex, |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 777 | NULL, 0, 1000); |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 778 | up_read(&mixer->chip->shutdown_rwsem); |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 779 | |
| 780 | if (ret < 0) { |
Takashi Iwai | 0ba41d9 | 2014-02-26 13:02:17 +0100 | [diff] [blame] | 781 | dev_err(&dev->dev, |
| 782 | "unable to issue vendor write request (ret = %d)", ret); |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 783 | return ret; |
| 784 | } |
| 785 | |
| 786 | return 0; |
| 787 | } |
| 788 | |
| 789 | static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = { |
| 790 | { |
| 791 | .name = "Direct Thru Channel A", |
| 792 | .private_value = _MAKE_NI_CONTROL(0x01, 0x03), |
| 793 | }, |
| 794 | { |
| 795 | .name = "Direct Thru Channel B", |
| 796 | .private_value = _MAKE_NI_CONTROL(0x01, 0x05), |
| 797 | }, |
| 798 | { |
| 799 | .name = "Phono Input Channel A", |
| 800 | .private_value = _MAKE_NI_CONTROL(0x02, 0x03), |
| 801 | }, |
| 802 | { |
| 803 | .name = "Phono Input Channel B", |
| 804 | .private_value = _MAKE_NI_CONTROL(0x02, 0x05), |
| 805 | }, |
| 806 | }; |
| 807 | |
| 808 | static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = { |
| 809 | { |
| 810 | .name = "Direct Thru Channel A", |
| 811 | .private_value = _MAKE_NI_CONTROL(0x01, 0x03), |
| 812 | }, |
| 813 | { |
| 814 | .name = "Direct Thru Channel B", |
| 815 | .private_value = _MAKE_NI_CONTROL(0x01, 0x05), |
| 816 | }, |
| 817 | { |
| 818 | .name = "Direct Thru Channel C", |
| 819 | .private_value = _MAKE_NI_CONTROL(0x01, 0x07), |
| 820 | }, |
| 821 | { |
| 822 | .name = "Direct Thru Channel D", |
| 823 | .private_value = _MAKE_NI_CONTROL(0x01, 0x09), |
| 824 | }, |
| 825 | { |
| 826 | .name = "Phono Input Channel A", |
| 827 | .private_value = _MAKE_NI_CONTROL(0x02, 0x03), |
| 828 | }, |
| 829 | { |
| 830 | .name = "Phono Input Channel B", |
| 831 | .private_value = _MAKE_NI_CONTROL(0x02, 0x05), |
| 832 | }, |
| 833 | { |
| 834 | .name = "Phono Input Channel C", |
| 835 | .private_value = _MAKE_NI_CONTROL(0x02, 0x07), |
| 836 | }, |
| 837 | { |
| 838 | .name = "Phono Input Channel D", |
| 839 | .private_value = _MAKE_NI_CONTROL(0x02, 0x09), |
| 840 | }, |
| 841 | }; |
| 842 | |
| 843 | static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer, |
| 844 | const struct snd_kcontrol_new *kc, |
| 845 | unsigned int count) |
| 846 | { |
| 847 | int i, err = 0; |
| 848 | struct snd_kcontrol_new template = { |
| 849 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 850 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 851 | .get = snd_nativeinstruments_control_get, |
| 852 | .put = snd_nativeinstruments_control_put, |
| 853 | .info = snd_ctl_boolean_mono_info, |
| 854 | }; |
| 855 | |
| 856 | for (i = 0; i < count; i++) { |
| 857 | struct snd_kcontrol *c; |
| 858 | |
| 859 | template.name = kc[i].name; |
| 860 | template.private_value = kc[i].private_value; |
| 861 | |
| 862 | c = snd_ctl_new1(&template, mixer); |
| 863 | err = snd_ctl_add(mixer->chip->card, c); |
| 864 | |
| 865 | if (err < 0) |
| 866 | break; |
| 867 | } |
| 868 | |
| 869 | return err; |
| 870 | } |
| 871 | |
Daniel Mack | d5a0bf6cc | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 872 | /* M-Audio FastTrack Ultra quirks */ |
Matt Gruskin | e9a25e0 | 2013-02-09 12:56:35 -0500 | [diff] [blame] | 873 | /* FTU Effect switch (also used by C400/C600) */ |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 874 | struct snd_ftu_eff_switch_priv_val { |
| 875 | struct usb_mixer_interface *mixer; |
| 876 | int cached_value; |
| 877 | int is_cached; |
Eldad Zack | d847ce0 | 2012-11-28 23:55:37 +0100 | [diff] [blame] | 878 | int bUnitID; |
| 879 | int validx; |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 880 | }; |
| 881 | |
| 882 | static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol, |
| 883 | struct snd_ctl_elem_info *uinfo) |
| 884 | { |
Takashi Iwai | 7bbd03e | 2014-10-20 18:21:42 +0200 | [diff] [blame] | 885 | static const char *const texts[8] = { |
| 886 | "Room 1", "Room 2", "Room 3", "Hall 1", |
| 887 | "Hall 2", "Plate", "Delay", "Echo" |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 888 | }; |
| 889 | |
Takashi Iwai | 7bbd03e | 2014-10-20 18:21:42 +0200 | [diff] [blame] | 890 | return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl, |
| 894 | struct snd_ctl_elem_value *ucontrol) |
| 895 | { |
| 896 | struct snd_usb_audio *chip; |
| 897 | struct usb_mixer_interface *mixer; |
| 898 | struct snd_ftu_eff_switch_priv_val *pval; |
| 899 | int err; |
| 900 | unsigned char value[2]; |
Eldad Zack | d847ce0 | 2012-11-28 23:55:37 +0100 | [diff] [blame] | 901 | int id, validx; |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 902 | |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 903 | const int val_len = 2; |
| 904 | |
| 905 | value[0] = 0x00; |
| 906 | value[1] = 0x00; |
| 907 | |
| 908 | pval = (struct snd_ftu_eff_switch_priv_val *) |
| 909 | kctl->private_value; |
| 910 | |
| 911 | if (pval->is_cached) { |
| 912 | ucontrol->value.enumerated.item[0] = pval->cached_value; |
| 913 | return 0; |
| 914 | } |
| 915 | |
| 916 | mixer = (struct usb_mixer_interface *) pval->mixer; |
| 917 | if (snd_BUG_ON(!mixer)) |
| 918 | return -EINVAL; |
| 919 | |
| 920 | chip = (struct snd_usb_audio *) mixer->chip; |
| 921 | if (snd_BUG_ON(!chip)) |
| 922 | return -EINVAL; |
| 923 | |
Eldad Zack | d847ce0 | 2012-11-28 23:55:37 +0100 | [diff] [blame] | 924 | id = pval->bUnitID; |
| 925 | validx = pval->validx; |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 926 | |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 927 | down_read(&mixer->chip->shutdown_rwsem); |
| 928 | if (mixer->chip->shutdown) |
| 929 | err = -ENODEV; |
| 930 | else |
| 931 | err = snd_usb_ctl_msg(chip->dev, |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 932 | usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR, |
| 933 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, |
| 934 | validx << 8, snd_usb_ctrl_intf(chip) | (id << 8), |
| 935 | value, val_len); |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 936 | up_read(&mixer->chip->shutdown_rwsem); |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 937 | if (err < 0) |
| 938 | return err; |
| 939 | |
| 940 | ucontrol->value.enumerated.item[0] = value[0]; |
| 941 | pval->cached_value = value[0]; |
| 942 | pval->is_cached = 1; |
| 943 | |
| 944 | return 0; |
| 945 | } |
| 946 | |
| 947 | static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl, |
| 948 | struct snd_ctl_elem_value *ucontrol) |
| 949 | { |
| 950 | struct snd_usb_audio *chip; |
| 951 | struct snd_ftu_eff_switch_priv_val *pval; |
| 952 | |
| 953 | struct usb_mixer_interface *mixer; |
| 954 | int changed, cur_val, err, new_val; |
| 955 | unsigned char value[2]; |
Eldad Zack | d847ce0 | 2012-11-28 23:55:37 +0100 | [diff] [blame] | 956 | int id, validx; |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 957 | |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 958 | const int val_len = 2; |
| 959 | |
| 960 | changed = 0; |
| 961 | |
| 962 | pval = (struct snd_ftu_eff_switch_priv_val *) |
| 963 | kctl->private_value; |
| 964 | cur_val = pval->cached_value; |
| 965 | new_val = ucontrol->value.enumerated.item[0]; |
| 966 | |
| 967 | mixer = (struct usb_mixer_interface *) pval->mixer; |
| 968 | if (snd_BUG_ON(!mixer)) |
| 969 | return -EINVAL; |
| 970 | |
| 971 | chip = (struct snd_usb_audio *) mixer->chip; |
| 972 | if (snd_BUG_ON(!chip)) |
| 973 | return -EINVAL; |
| 974 | |
Eldad Zack | d847ce0 | 2012-11-28 23:55:37 +0100 | [diff] [blame] | 975 | id = pval->bUnitID; |
| 976 | validx = pval->validx; |
| 977 | |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 978 | if (!pval->is_cached) { |
| 979 | /* Read current value */ |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 980 | down_read(&mixer->chip->shutdown_rwsem); |
| 981 | if (mixer->chip->shutdown) |
| 982 | err = -ENODEV; |
| 983 | else |
| 984 | err = snd_usb_ctl_msg(chip->dev, |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 985 | usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR, |
| 986 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, |
| 987 | validx << 8, snd_usb_ctrl_intf(chip) | (id << 8), |
| 988 | value, val_len); |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 989 | up_read(&mixer->chip->shutdown_rwsem); |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 990 | if (err < 0) |
| 991 | return err; |
| 992 | |
| 993 | cur_val = value[0]; |
| 994 | pval->cached_value = cur_val; |
| 995 | pval->is_cached = 1; |
| 996 | } |
| 997 | /* update value if needed */ |
| 998 | if (cur_val != new_val) { |
| 999 | value[0] = new_val; |
| 1000 | value[1] = 0; |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 1001 | down_read(&mixer->chip->shutdown_rwsem); |
| 1002 | if (mixer->chip->shutdown) |
| 1003 | err = -ENODEV; |
| 1004 | else |
| 1005 | err = snd_usb_ctl_msg(chip->dev, |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 1006 | usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR, |
| 1007 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, |
| 1008 | validx << 8, snd_usb_ctrl_intf(chip) | (id << 8), |
| 1009 | value, val_len); |
Takashi Iwai | 888ea7d | 2012-10-15 12:40:37 +0200 | [diff] [blame] | 1010 | up_read(&mixer->chip->shutdown_rwsem); |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 1011 | if (err < 0) |
| 1012 | return err; |
| 1013 | |
| 1014 | pval->cached_value = new_val; |
| 1015 | pval->is_cached = 1; |
| 1016 | changed = 1; |
| 1017 | } |
| 1018 | |
| 1019 | return changed; |
| 1020 | } |
| 1021 | |
Takashi Iwai | 1a29058 | 2014-11-11 15:45:57 +0100 | [diff] [blame] | 1022 | static void kctl_private_value_free(struct snd_kcontrol *kctl) |
| 1023 | { |
| 1024 | kfree((void *)kctl->private_value); |
| 1025 | } |
| 1026 | |
Eldad Zack | d847ce0 | 2012-11-28 23:55:37 +0100 | [diff] [blame] | 1027 | static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer, |
| 1028 | int validx, int bUnitID) |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 1029 | { |
| 1030 | static struct snd_kcontrol_new template = { |
| 1031 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1032 | .name = "Effect Program Switch", |
| 1033 | .index = 0, |
| 1034 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 1035 | .info = snd_ftu_eff_switch_info, |
| 1036 | .get = snd_ftu_eff_switch_get, |
| 1037 | .put = snd_ftu_eff_switch_put |
| 1038 | }; |
| 1039 | |
| 1040 | int err; |
| 1041 | struct snd_kcontrol *kctl; |
| 1042 | struct snd_ftu_eff_switch_priv_val *pval; |
| 1043 | |
| 1044 | pval = kzalloc(sizeof(*pval), GFP_KERNEL); |
| 1045 | if (!pval) |
| 1046 | return -ENOMEM; |
| 1047 | |
| 1048 | pval->cached_value = 0; |
| 1049 | pval->is_cached = 0; |
| 1050 | pval->mixer = mixer; |
Eldad Zack | d847ce0 | 2012-11-28 23:55:37 +0100 | [diff] [blame] | 1051 | pval->bUnitID = bUnitID; |
| 1052 | pval->validx = validx; |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 1053 | |
| 1054 | template.private_value = (unsigned long) pval; |
| 1055 | kctl = snd_ctl_new1(&template, mixer->chip); |
| 1056 | if (!kctl) { |
| 1057 | kfree(pval); |
| 1058 | return -ENOMEM; |
| 1059 | } |
| 1060 | |
Takashi Iwai | 1a29058 | 2014-11-11 15:45:57 +0100 | [diff] [blame] | 1061 | kctl->private_free = kctl_private_value_free; |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 1062 | err = snd_ctl_add(mixer->chip->card, kctl); |
| 1063 | if (err < 0) |
| 1064 | return err; |
| 1065 | |
| 1066 | return 0; |
| 1067 | } |
Daniel Mack | d5a0bf6cc | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 1068 | |
Felix Homann | cfe8f97 | 2012-04-23 20:24:26 +0200 | [diff] [blame] | 1069 | /* Create volume controls for FTU devices*/ |
| 1070 | static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer) |
Daniel Mack | d5a0bf6cc | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 1071 | { |
| 1072 | char name[64]; |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 1073 | unsigned int control, cmask; |
Daniel Mack | d5a0bf6cc | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 1074 | int in, out, err; |
| 1075 | |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 1076 | const unsigned int id = 5; |
| 1077 | const int val_type = USB_MIXER_S16; |
| 1078 | |
Daniel Mack | d5a0bf6cc | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 1079 | for (out = 0; out < 8; out++) { |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 1080 | control = out + 1; |
Daniel Mack | d5a0bf6cc | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 1081 | for (in = 0; in < 8; in++) { |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 1082 | cmask = 1 << in; |
Daniel Mack | d5a0bf6cc | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 1083 | snprintf(name, sizeof(name), |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 1084 | "AIn%d - Out%d Capture Volume", |
| 1085 | in + 1, out + 1); |
| 1086 | err = snd_create_std_mono_ctl(mixer, id, control, |
| 1087 | cmask, val_type, name, |
Felix Homann | 25ee7ef | 2012-04-23 20:24:25 +0200 | [diff] [blame] | 1088 | &snd_usb_mixer_vol_tlv); |
Daniel Mack | d5a0bf6cc | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 1089 | if (err < 0) |
| 1090 | return err; |
| 1091 | } |
Daniel Mack | d5a0bf6cc | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 1092 | for (in = 8; in < 16; in++) { |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 1093 | cmask = 1 << in; |
Daniel Mack | d5a0bf6cc | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 1094 | snprintf(name, sizeof(name), |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 1095 | "DIn%d - Out%d Playback Volume", |
| 1096 | in - 7, out + 1); |
| 1097 | err = snd_create_std_mono_ctl(mixer, id, control, |
| 1098 | cmask, val_type, name, |
Felix Homann | 25ee7ef | 2012-04-23 20:24:25 +0200 | [diff] [blame] | 1099 | &snd_usb_mixer_vol_tlv); |
Daniel Mack | d5a0bf6cc | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 1100 | if (err < 0) |
| 1101 | return err; |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | return 0; |
| 1106 | } |
| 1107 | |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 1108 | /* This control needs a volume quirk, see mixer.c */ |
| 1109 | static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer) |
| 1110 | { |
| 1111 | static const char name[] = "Effect Volume"; |
| 1112 | const unsigned int id = 6; |
| 1113 | const int val_type = USB_MIXER_U8; |
| 1114 | const unsigned int control = 2; |
| 1115 | const unsigned int cmask = 0; |
| 1116 | |
| 1117 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, |
| 1118 | name, snd_usb_mixer_vol_tlv); |
| 1119 | } |
| 1120 | |
| 1121 | /* This control needs a volume quirk, see mixer.c */ |
| 1122 | static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer) |
| 1123 | { |
| 1124 | static const char name[] = "Effect Duration"; |
| 1125 | const unsigned int id = 6; |
| 1126 | const int val_type = USB_MIXER_S16; |
| 1127 | const unsigned int control = 3; |
| 1128 | const unsigned int cmask = 0; |
| 1129 | |
| 1130 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, |
| 1131 | name, snd_usb_mixer_vol_tlv); |
| 1132 | } |
| 1133 | |
| 1134 | /* This control needs a volume quirk, see mixer.c */ |
| 1135 | static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer) |
| 1136 | { |
| 1137 | static const char name[] = "Effect Feedback Volume"; |
| 1138 | const unsigned int id = 6; |
| 1139 | const int val_type = USB_MIXER_U8; |
| 1140 | const unsigned int control = 4; |
| 1141 | const unsigned int cmask = 0; |
| 1142 | |
| 1143 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, |
| 1144 | name, NULL); |
| 1145 | } |
| 1146 | |
| 1147 | static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer) |
| 1148 | { |
| 1149 | unsigned int cmask; |
| 1150 | int err, ch; |
| 1151 | char name[48]; |
| 1152 | |
| 1153 | const unsigned int id = 7; |
| 1154 | const int val_type = USB_MIXER_S16; |
| 1155 | const unsigned int control = 7; |
| 1156 | |
| 1157 | for (ch = 0; ch < 4; ++ch) { |
| 1158 | cmask = 1 << ch; |
| 1159 | snprintf(name, sizeof(name), |
| 1160 | "Effect Return %d Volume", ch + 1); |
| 1161 | err = snd_create_std_mono_ctl(mixer, id, control, |
| 1162 | cmask, val_type, name, |
| 1163 | snd_usb_mixer_vol_tlv); |
| 1164 | if (err < 0) |
| 1165 | return err; |
| 1166 | } |
| 1167 | |
| 1168 | return 0; |
| 1169 | } |
| 1170 | |
| 1171 | static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer) |
| 1172 | { |
| 1173 | unsigned int cmask; |
| 1174 | int err, ch; |
| 1175 | char name[48]; |
| 1176 | |
| 1177 | const unsigned int id = 5; |
| 1178 | const int val_type = USB_MIXER_S16; |
| 1179 | const unsigned int control = 9; |
| 1180 | |
| 1181 | for (ch = 0; ch < 8; ++ch) { |
| 1182 | cmask = 1 << ch; |
| 1183 | snprintf(name, sizeof(name), |
| 1184 | "Effect Send AIn%d Volume", ch + 1); |
| 1185 | err = snd_create_std_mono_ctl(mixer, id, control, cmask, |
| 1186 | val_type, name, |
| 1187 | snd_usb_mixer_vol_tlv); |
| 1188 | if (err < 0) |
| 1189 | return err; |
| 1190 | } |
| 1191 | for (ch = 8; ch < 16; ++ch) { |
| 1192 | cmask = 1 << ch; |
| 1193 | snprintf(name, sizeof(name), |
| 1194 | "Effect Send DIn%d Volume", ch - 7); |
| 1195 | err = snd_create_std_mono_ctl(mixer, id, control, cmask, |
| 1196 | val_type, name, |
| 1197 | snd_usb_mixer_vol_tlv); |
| 1198 | if (err < 0) |
| 1199 | return err; |
| 1200 | } |
| 1201 | return 0; |
| 1202 | } |
| 1203 | |
Felix Homann | cfe8f97 | 2012-04-23 20:24:26 +0200 | [diff] [blame] | 1204 | static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer) |
Mark Hills | 7536c30 | 2012-04-14 17:19:24 +0100 | [diff] [blame] | 1205 | { |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 1206 | int err; |
Mark Hills | 7536c30 | 2012-04-14 17:19:24 +0100 | [diff] [blame] | 1207 | |
Felix Homann | cfe8f97 | 2012-04-23 20:24:26 +0200 | [diff] [blame] | 1208 | err = snd_ftu_create_volume_ctls(mixer); |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 1209 | if (err < 0) |
| 1210 | return err; |
Mark Hills | 7536c30 | 2012-04-14 17:19:24 +0100 | [diff] [blame] | 1211 | |
Eldad Zack | d847ce0 | 2012-11-28 23:55:37 +0100 | [diff] [blame] | 1212 | err = snd_ftu_create_effect_switch(mixer, 1, 6); |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 1213 | if (err < 0) |
| 1214 | return err; |
Eldad Zack | d847ce0 | 2012-11-28 23:55:37 +0100 | [diff] [blame] | 1215 | |
Felix Homann | d34bf14 | 2012-04-23 20:24:27 +0200 | [diff] [blame] | 1216 | err = snd_ftu_create_effect_volume_ctl(mixer); |
| 1217 | if (err < 0) |
| 1218 | return err; |
| 1219 | |
| 1220 | err = snd_ftu_create_effect_duration_ctl(mixer); |
| 1221 | if (err < 0) |
| 1222 | return err; |
| 1223 | |
| 1224 | err = snd_ftu_create_effect_feedback_ctl(mixer); |
| 1225 | if (err < 0) |
| 1226 | return err; |
| 1227 | |
| 1228 | err = snd_ftu_create_effect_return_ctls(mixer); |
| 1229 | if (err < 0) |
| 1230 | return err; |
| 1231 | |
| 1232 | err = snd_ftu_create_effect_send_ctls(mixer); |
| 1233 | if (err < 0) |
| 1234 | return err; |
| 1235 | |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 1236 | return 0; |
Mark Hills | 7536c30 | 2012-04-14 17:19:24 +0100 | [diff] [blame] | 1237 | } |
| 1238 | |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 1239 | void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, |
| 1240 | unsigned char samplerate_id) |
| 1241 | { |
| 1242 | struct usb_mixer_interface *mixer; |
| 1243 | struct usb_mixer_elem_info *cval; |
| 1244 | int unitid = 12; /* SamleRate ExtensionUnit ID */ |
| 1245 | |
| 1246 | list_for_each_entry(mixer, &chip->mixer_list, list) { |
Takashi Iwai | 3360b84 | 2014-11-18 11:47:04 +0100 | [diff] [blame] | 1247 | cval = (struct usb_mixer_elem_info *)mixer->id_elems[unitid]; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 1248 | if (cval) { |
| 1249 | snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR, |
| 1250 | cval->control << 8, |
| 1251 | samplerate_id); |
| 1252 | snd_usb_mixer_notify_id(mixer, unitid); |
| 1253 | } |
| 1254 | break; |
| 1255 | } |
| 1256 | } |
| 1257 | |
Matt Gruskin | e9a25e0 | 2013-02-09 12:56:35 -0500 | [diff] [blame] | 1258 | /* M-Audio Fast Track C400/C600 */ |
| 1259 | /* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */ |
Eldad Zack | 09d8e3a | 2012-11-28 23:55:40 +0100 | [diff] [blame] | 1260 | static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer) |
| 1261 | { |
| 1262 | char name[64]; |
| 1263 | unsigned int cmask, offset; |
| 1264 | int out, chan, err; |
Matt Gruskin | e9a25e0 | 2013-02-09 12:56:35 -0500 | [diff] [blame] | 1265 | int num_outs = 0; |
| 1266 | int num_ins = 0; |
Eldad Zack | 09d8e3a | 2012-11-28 23:55:40 +0100 | [diff] [blame] | 1267 | |
| 1268 | const unsigned int id = 0x40; |
| 1269 | const int val_type = USB_MIXER_S16; |
| 1270 | const int control = 1; |
| 1271 | |
Matt Gruskin | e9a25e0 | 2013-02-09 12:56:35 -0500 | [diff] [blame] | 1272 | switch (mixer->chip->usb_id) { |
| 1273 | case USB_ID(0x0763, 0x2030): |
| 1274 | num_outs = 6; |
| 1275 | num_ins = 4; |
| 1276 | break; |
| 1277 | case USB_ID(0x0763, 0x2031): |
| 1278 | num_outs = 8; |
| 1279 | num_ins = 6; |
| 1280 | break; |
| 1281 | } |
| 1282 | |
| 1283 | for (chan = 0; chan < num_outs + num_ins; chan++) { |
| 1284 | for (out = 0; out < num_outs; out++) { |
| 1285 | if (chan < num_outs) { |
Eldad Zack | 09d8e3a | 2012-11-28 23:55:40 +0100 | [diff] [blame] | 1286 | snprintf(name, sizeof(name), |
| 1287 | "PCM%d-Out%d Playback Volume", |
| 1288 | chan + 1, out + 1); |
| 1289 | } else { |
| 1290 | snprintf(name, sizeof(name), |
| 1291 | "In%d-Out%d Playback Volume", |
Matt Gruskin | e9a25e0 | 2013-02-09 12:56:35 -0500 | [diff] [blame] | 1292 | chan - num_outs + 1, out + 1); |
Eldad Zack | 09d8e3a | 2012-11-28 23:55:40 +0100 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | cmask = (out == 0) ? 0 : 1 << (out - 1); |
Matt Gruskin | e9a25e0 | 2013-02-09 12:56:35 -0500 | [diff] [blame] | 1296 | offset = chan * num_outs; |
Eldad Zack | 09d8e3a | 2012-11-28 23:55:40 +0100 | [diff] [blame] | 1297 | err = snd_create_std_mono_ctl_offset(mixer, id, control, |
| 1298 | cmask, val_type, offset, name, |
| 1299 | &snd_usb_mixer_vol_tlv); |
| 1300 | if (err < 0) |
| 1301 | return err; |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | return 0; |
| 1306 | } |
| 1307 | |
| 1308 | /* This control needs a volume quirk, see mixer.c */ |
| 1309 | static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer) |
| 1310 | { |
| 1311 | static const char name[] = "Effect Volume"; |
| 1312 | const unsigned int id = 0x43; |
| 1313 | const int val_type = USB_MIXER_U8; |
| 1314 | const unsigned int control = 3; |
| 1315 | const unsigned int cmask = 0; |
| 1316 | |
| 1317 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, |
| 1318 | name, snd_usb_mixer_vol_tlv); |
| 1319 | } |
| 1320 | |
| 1321 | /* This control needs a volume quirk, see mixer.c */ |
| 1322 | static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer) |
| 1323 | { |
| 1324 | static const char name[] = "Effect Duration"; |
| 1325 | const unsigned int id = 0x43; |
| 1326 | const int val_type = USB_MIXER_S16; |
| 1327 | const unsigned int control = 4; |
| 1328 | const unsigned int cmask = 0; |
| 1329 | |
| 1330 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, |
| 1331 | name, snd_usb_mixer_vol_tlv); |
| 1332 | } |
| 1333 | |
| 1334 | /* This control needs a volume quirk, see mixer.c */ |
| 1335 | static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer) |
| 1336 | { |
| 1337 | static const char name[] = "Effect Feedback Volume"; |
| 1338 | const unsigned int id = 0x43; |
| 1339 | const int val_type = USB_MIXER_U8; |
| 1340 | const unsigned int control = 5; |
| 1341 | const unsigned int cmask = 0; |
| 1342 | |
| 1343 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, |
| 1344 | name, NULL); |
| 1345 | } |
| 1346 | |
| 1347 | static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer) |
| 1348 | { |
| 1349 | char name[64]; |
| 1350 | unsigned int cmask; |
| 1351 | int chan, err; |
Matt Gruskin | e9a25e0 | 2013-02-09 12:56:35 -0500 | [diff] [blame] | 1352 | int num_outs = 0; |
| 1353 | int num_ins = 0; |
Eldad Zack | 09d8e3a | 2012-11-28 23:55:40 +0100 | [diff] [blame] | 1354 | |
| 1355 | const unsigned int id = 0x42; |
| 1356 | const int val_type = USB_MIXER_S16; |
| 1357 | const int control = 1; |
| 1358 | |
Matt Gruskin | e9a25e0 | 2013-02-09 12:56:35 -0500 | [diff] [blame] | 1359 | switch (mixer->chip->usb_id) { |
| 1360 | case USB_ID(0x0763, 0x2030): |
| 1361 | num_outs = 6; |
| 1362 | num_ins = 4; |
| 1363 | break; |
| 1364 | case USB_ID(0x0763, 0x2031): |
| 1365 | num_outs = 8; |
| 1366 | num_ins = 6; |
| 1367 | break; |
| 1368 | } |
| 1369 | |
| 1370 | for (chan = 0; chan < num_outs + num_ins; chan++) { |
| 1371 | if (chan < num_outs) { |
Eldad Zack | 09d8e3a | 2012-11-28 23:55:40 +0100 | [diff] [blame] | 1372 | snprintf(name, sizeof(name), |
| 1373 | "Effect Send DOut%d", |
| 1374 | chan + 1); |
| 1375 | } else { |
| 1376 | snprintf(name, sizeof(name), |
| 1377 | "Effect Send AIn%d", |
Matt Gruskin | e9a25e0 | 2013-02-09 12:56:35 -0500 | [diff] [blame] | 1378 | chan - num_outs + 1); |
Eldad Zack | 09d8e3a | 2012-11-28 23:55:40 +0100 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | cmask = (chan == 0) ? 0 : 1 << (chan - 1); |
| 1382 | err = snd_create_std_mono_ctl(mixer, id, control, |
| 1383 | cmask, val_type, name, |
| 1384 | &snd_usb_mixer_vol_tlv); |
| 1385 | if (err < 0) |
| 1386 | return err; |
| 1387 | } |
| 1388 | |
| 1389 | return 0; |
| 1390 | } |
| 1391 | |
| 1392 | static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer) |
| 1393 | { |
| 1394 | char name[64]; |
| 1395 | unsigned int cmask; |
| 1396 | int chan, err; |
Matt Gruskin | e9a25e0 | 2013-02-09 12:56:35 -0500 | [diff] [blame] | 1397 | int num_outs = 0; |
| 1398 | int offset = 0; |
Eldad Zack | 09d8e3a | 2012-11-28 23:55:40 +0100 | [diff] [blame] | 1399 | |
| 1400 | const unsigned int id = 0x40; |
| 1401 | const int val_type = USB_MIXER_S16; |
| 1402 | const int control = 1; |
Eldad Zack | 09d8e3a | 2012-11-28 23:55:40 +0100 | [diff] [blame] | 1403 | |
Matt Gruskin | e9a25e0 | 2013-02-09 12:56:35 -0500 | [diff] [blame] | 1404 | switch (mixer->chip->usb_id) { |
| 1405 | case USB_ID(0x0763, 0x2030): |
| 1406 | num_outs = 6; |
| 1407 | offset = 0x3c; |
| 1408 | /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */ |
| 1409 | break; |
| 1410 | case USB_ID(0x0763, 0x2031): |
| 1411 | num_outs = 8; |
| 1412 | offset = 0x70; |
| 1413 | /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */ |
| 1414 | break; |
| 1415 | } |
| 1416 | |
| 1417 | for (chan = 0; chan < num_outs; chan++) { |
Eldad Zack | 09d8e3a | 2012-11-28 23:55:40 +0100 | [diff] [blame] | 1418 | snprintf(name, sizeof(name), |
| 1419 | "Effect Return %d", |
| 1420 | chan + 1); |
| 1421 | |
Matt Gruskin | e9a25e0 | 2013-02-09 12:56:35 -0500 | [diff] [blame] | 1422 | cmask = (chan == 0) ? 0 : |
| 1423 | 1 << (chan + (chan % 2) * num_outs - 1); |
Eldad Zack | 09d8e3a | 2012-11-28 23:55:40 +0100 | [diff] [blame] | 1424 | err = snd_create_std_mono_ctl_offset(mixer, id, control, |
| 1425 | cmask, val_type, offset, name, |
| 1426 | &snd_usb_mixer_vol_tlv); |
| 1427 | if (err < 0) |
| 1428 | return err; |
| 1429 | } |
| 1430 | |
| 1431 | return 0; |
| 1432 | } |
| 1433 | |
| 1434 | static int snd_c400_create_mixer(struct usb_mixer_interface *mixer) |
| 1435 | { |
| 1436 | int err; |
| 1437 | |
| 1438 | err = snd_c400_create_vol_ctls(mixer); |
| 1439 | if (err < 0) |
| 1440 | return err; |
| 1441 | |
| 1442 | err = snd_c400_create_effect_vol_ctls(mixer); |
| 1443 | if (err < 0) |
| 1444 | return err; |
| 1445 | |
| 1446 | err = snd_c400_create_effect_ret_vol_ctls(mixer); |
| 1447 | if (err < 0) |
| 1448 | return err; |
| 1449 | |
| 1450 | err = snd_ftu_create_effect_switch(mixer, 2, 0x43); |
| 1451 | if (err < 0) |
| 1452 | return err; |
| 1453 | |
| 1454 | err = snd_c400_create_effect_volume_ctl(mixer); |
| 1455 | if (err < 0) |
| 1456 | return err; |
| 1457 | |
| 1458 | err = snd_c400_create_effect_duration_ctl(mixer); |
| 1459 | if (err < 0) |
| 1460 | return err; |
| 1461 | |
| 1462 | err = snd_c400_create_effect_feedback_ctl(mixer); |
| 1463 | if (err < 0) |
| 1464 | return err; |
| 1465 | |
| 1466 | return 0; |
| 1467 | } |
| 1468 | |
Mark Hills | b71dad18 | 2012-06-09 13:16:38 +0100 | [diff] [blame] | 1469 | /* |
| 1470 | * The mixer units for Ebox-44 are corrupt, and even where they |
| 1471 | * are valid they presents mono controls as L and R channels of |
| 1472 | * stereo. So we provide a good mixer here. |
| 1473 | */ |
Sachin Kamat | e8e7da2 | 2013-01-10 11:19:14 +0530 | [diff] [blame] | 1474 | static struct std_mono_table ebox44_table[] = { |
Mark Hills | 989b013 | 2012-06-09 13:16:39 +0100 | [diff] [blame] | 1475 | { |
| 1476 | .unitid = 4, |
| 1477 | .control = 1, |
| 1478 | .cmask = 0x0, |
| 1479 | .val_type = USB_MIXER_INV_BOOLEAN, |
| 1480 | .name = "Headphone Playback Switch" |
| 1481 | }, |
| 1482 | { |
| 1483 | .unitid = 4, |
| 1484 | .control = 2, |
| 1485 | .cmask = 0x1, |
| 1486 | .val_type = USB_MIXER_S16, |
| 1487 | .name = "Headphone A Mix Playback Volume" |
| 1488 | }, |
| 1489 | { |
| 1490 | .unitid = 4, |
| 1491 | .control = 2, |
| 1492 | .cmask = 0x2, |
| 1493 | .val_type = USB_MIXER_S16, |
| 1494 | .name = "Headphone B Mix Playback Volume" |
| 1495 | }, |
Mark Hills | b71dad18 | 2012-06-09 13:16:38 +0100 | [diff] [blame] | 1496 | |
Mark Hills | 989b013 | 2012-06-09 13:16:39 +0100 | [diff] [blame] | 1497 | { |
| 1498 | .unitid = 7, |
| 1499 | .control = 1, |
| 1500 | .cmask = 0x0, |
| 1501 | .val_type = USB_MIXER_INV_BOOLEAN, |
| 1502 | .name = "Output Playback Switch" |
| 1503 | }, |
| 1504 | { |
| 1505 | .unitid = 7, |
| 1506 | .control = 2, |
| 1507 | .cmask = 0x1, |
| 1508 | .val_type = USB_MIXER_S16, |
| 1509 | .name = "Output A Playback Volume" |
| 1510 | }, |
| 1511 | { |
| 1512 | .unitid = 7, |
| 1513 | .control = 2, |
| 1514 | .cmask = 0x2, |
| 1515 | .val_type = USB_MIXER_S16, |
| 1516 | .name = "Output B Playback Volume" |
| 1517 | }, |
Mark Hills | b71dad18 | 2012-06-09 13:16:38 +0100 | [diff] [blame] | 1518 | |
Mark Hills | 989b013 | 2012-06-09 13:16:39 +0100 | [diff] [blame] | 1519 | { |
| 1520 | .unitid = 10, |
| 1521 | .control = 1, |
| 1522 | .cmask = 0x0, |
| 1523 | .val_type = USB_MIXER_INV_BOOLEAN, |
| 1524 | .name = "Input Capture Switch" |
| 1525 | }, |
| 1526 | { |
| 1527 | .unitid = 10, |
| 1528 | .control = 2, |
| 1529 | .cmask = 0x1, |
| 1530 | .val_type = USB_MIXER_S16, |
| 1531 | .name = "Input A Capture Volume" |
| 1532 | }, |
| 1533 | { |
| 1534 | .unitid = 10, |
| 1535 | .control = 2, |
| 1536 | .cmask = 0x2, |
| 1537 | .val_type = USB_MIXER_S16, |
| 1538 | .name = "Input B Capture Volume" |
| 1539 | }, |
Mark Hills | b71dad18 | 2012-06-09 13:16:38 +0100 | [diff] [blame] | 1540 | |
Mark Hills | 989b013 | 2012-06-09 13:16:39 +0100 | [diff] [blame] | 1541 | {} |
Mark Hills | b71dad18 | 2012-06-09 13:16:38 +0100 | [diff] [blame] | 1542 | }; |
| 1543 | |
Przemek Rudy | 066624c | 2013-06-27 23:52:33 +0200 | [diff] [blame] | 1544 | /* Audio Advantage Micro II findings: |
| 1545 | * |
| 1546 | * Mapping spdif AES bits to vendor register.bit: |
| 1547 | * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00 |
| 1548 | * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01 |
| 1549 | * AES2: [0 0 0 0 0 0 0 0] |
| 1550 | * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request |
| 1551 | * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices |
| 1552 | * |
| 1553 | * power on values: |
| 1554 | * r2: 0x10 |
| 1555 | * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set |
| 1556 | * just after it to 0xa0, presumably it disables/mutes some analog |
| 1557 | * parts when there is no audio.) |
| 1558 | * r9: 0x28 |
| 1559 | * |
| 1560 | * Optical transmitter on/off: |
| 1561 | * vendor register.bit: 9.1 |
| 1562 | * 0 - on (0x28 register value) |
| 1563 | * 1 - off (0x2a register value) |
| 1564 | * |
| 1565 | */ |
| 1566 | static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol, |
| 1567 | struct snd_ctl_elem_info *uinfo) |
| 1568 | { |
| 1569 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 1570 | uinfo->count = 1; |
| 1571 | return 0; |
| 1572 | } |
| 1573 | |
| 1574 | static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol, |
| 1575 | struct snd_ctl_elem_value *ucontrol) |
| 1576 | { |
| 1577 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 1578 | int err; |
| 1579 | struct usb_interface *iface; |
| 1580 | struct usb_host_interface *alts; |
| 1581 | unsigned int ep; |
| 1582 | unsigned char data[3]; |
| 1583 | int rate; |
| 1584 | |
| 1585 | ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff; |
| 1586 | ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff; |
| 1587 | ucontrol->value.iec958.status[2] = 0x00; |
| 1588 | |
| 1589 | /* use known values for that card: interface#1 altsetting#1 */ |
| 1590 | iface = usb_ifnum_to_if(mixer->chip->dev, 1); |
| 1591 | alts = &iface->altsetting[1]; |
| 1592 | ep = get_endpoint(alts, 0)->bEndpointAddress; |
| 1593 | |
| 1594 | err = snd_usb_ctl_msg(mixer->chip->dev, |
| 1595 | usb_rcvctrlpipe(mixer->chip->dev, 0), |
| 1596 | UAC_GET_CUR, |
| 1597 | USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN, |
| 1598 | UAC_EP_CS_ATTR_SAMPLE_RATE << 8, |
| 1599 | ep, |
| 1600 | data, |
| 1601 | sizeof(data)); |
| 1602 | if (err < 0) |
| 1603 | goto end; |
| 1604 | |
| 1605 | rate = data[0] | (data[1] << 8) | (data[2] << 16); |
| 1606 | ucontrol->value.iec958.status[3] = (rate == 48000) ? |
| 1607 | IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100; |
| 1608 | |
| 1609 | err = 0; |
| 1610 | end: |
| 1611 | return err; |
| 1612 | } |
| 1613 | |
| 1614 | static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol, |
| 1615 | struct snd_ctl_elem_value *ucontrol) |
| 1616 | { |
| 1617 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 1618 | int err; |
| 1619 | u8 reg; |
| 1620 | unsigned long priv_backup = kcontrol->private_value; |
| 1621 | |
| 1622 | reg = ((ucontrol->value.iec958.status[1] & 0x0f) << 4) | |
| 1623 | (ucontrol->value.iec958.status[0] & 0x0f); |
| 1624 | err = snd_usb_ctl_msg(mixer->chip->dev, |
| 1625 | usb_sndctrlpipe(mixer->chip->dev, 0), |
| 1626 | UAC_SET_CUR, |
| 1627 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
| 1628 | reg, |
| 1629 | 2, |
| 1630 | NULL, |
| 1631 | 0); |
| 1632 | if (err < 0) |
| 1633 | goto end; |
| 1634 | |
| 1635 | kcontrol->private_value &= 0xfffff0f0; |
| 1636 | kcontrol->private_value |= (ucontrol->value.iec958.status[1] & 0x0f) << 8; |
| 1637 | kcontrol->private_value |= (ucontrol->value.iec958.status[0] & 0x0f); |
| 1638 | |
| 1639 | reg = (ucontrol->value.iec958.status[0] & IEC958_AES0_NONAUDIO) ? |
| 1640 | 0xa0 : 0x20; |
| 1641 | reg |= (ucontrol->value.iec958.status[1] >> 4) & 0x0f; |
| 1642 | err = snd_usb_ctl_msg(mixer->chip->dev, |
| 1643 | usb_sndctrlpipe(mixer->chip->dev, 0), |
| 1644 | UAC_SET_CUR, |
| 1645 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
| 1646 | reg, |
| 1647 | 3, |
| 1648 | NULL, |
| 1649 | 0); |
| 1650 | if (err < 0) |
| 1651 | goto end; |
| 1652 | |
| 1653 | kcontrol->private_value &= 0xffff0fff; |
| 1654 | kcontrol->private_value |= (ucontrol->value.iec958.status[1] & 0xf0) << 8; |
| 1655 | |
| 1656 | /* The frequency bits in AES3 cannot be set via register access. */ |
| 1657 | |
| 1658 | /* Silently ignore any bits from the request that cannot be set. */ |
| 1659 | |
| 1660 | err = (priv_backup != kcontrol->private_value); |
| 1661 | end: |
| 1662 | return err; |
| 1663 | } |
| 1664 | |
| 1665 | static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol, |
| 1666 | struct snd_ctl_elem_value *ucontrol) |
| 1667 | { |
| 1668 | ucontrol->value.iec958.status[0] = 0x0f; |
| 1669 | ucontrol->value.iec958.status[1] = 0xff; |
| 1670 | ucontrol->value.iec958.status[2] = 0x00; |
| 1671 | ucontrol->value.iec958.status[3] = 0x00; |
| 1672 | |
| 1673 | return 0; |
| 1674 | } |
| 1675 | |
| 1676 | static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol, |
| 1677 | struct snd_ctl_elem_value *ucontrol) |
| 1678 | { |
| 1679 | ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02); |
| 1680 | |
| 1681 | return 0; |
| 1682 | } |
| 1683 | |
| 1684 | static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol, |
| 1685 | struct snd_ctl_elem_value *ucontrol) |
| 1686 | { |
| 1687 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 1688 | int err; |
| 1689 | u8 reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a; |
| 1690 | |
| 1691 | err = snd_usb_ctl_msg(mixer->chip->dev, |
| 1692 | usb_sndctrlpipe(mixer->chip->dev, 0), |
| 1693 | UAC_SET_CUR, |
| 1694 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
| 1695 | reg, |
| 1696 | 9, |
| 1697 | NULL, |
| 1698 | 0); |
| 1699 | |
| 1700 | if (!err) { |
| 1701 | err = (reg != (kcontrol->private_value & 0x0ff)); |
| 1702 | if (err) |
| 1703 | kcontrol->private_value = reg; |
| 1704 | } |
| 1705 | |
| 1706 | return err; |
| 1707 | } |
| 1708 | |
| 1709 | static struct snd_kcontrol_new snd_microii_mixer_spdif[] = { |
| 1710 | { |
| 1711 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1712 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), |
| 1713 | .info = snd_microii_spdif_info, |
| 1714 | .get = snd_microii_spdif_default_get, |
| 1715 | .put = snd_microii_spdif_default_put, |
| 1716 | .private_value = 0x00000100UL,/* reset value */ |
| 1717 | }, |
| 1718 | { |
| 1719 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1720 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1721 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK), |
| 1722 | .info = snd_microii_spdif_info, |
| 1723 | .get = snd_microii_spdif_mask_get, |
| 1724 | }, |
| 1725 | { |
| 1726 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1727 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), |
| 1728 | .info = snd_ctl_boolean_mono_info, |
| 1729 | .get = snd_microii_spdif_switch_get, |
| 1730 | .put = snd_microii_spdif_switch_put, |
| 1731 | .private_value = 0x00000028UL,/* reset value */ |
| 1732 | } |
| 1733 | }; |
| 1734 | |
| 1735 | static int snd_microii_controls_create(struct usb_mixer_interface *mixer) |
| 1736 | { |
| 1737 | int err, i; |
| 1738 | |
| 1739 | for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) { |
| 1740 | err = snd_ctl_add(mixer->chip->card, |
| 1741 | snd_ctl_new1(&snd_microii_mixer_spdif[i], mixer)); |
| 1742 | if (err < 0) |
| 1743 | return err; |
| 1744 | } |
| 1745 | |
Mikulas Patocka | 18e4753 | 2013-12-05 14:32:43 -0500 | [diff] [blame] | 1746 | return 0; |
Przemek Rudy | 066624c | 2013-06-27 23:52:33 +0200 | [diff] [blame] | 1747 | } |
| 1748 | |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 1749 | int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) |
| 1750 | { |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 1751 | int err = 0; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 1752 | struct snd_info_entry *entry; |
| 1753 | |
| 1754 | if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0) |
| 1755 | return err; |
| 1756 | |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 1757 | switch (mixer->chip->usb_id) { |
| 1758 | case USB_ID(0x041e, 0x3020): |
| 1759 | case USB_ID(0x041e, 0x3040): |
| 1760 | case USB_ID(0x041e, 0x3042): |
Mathieu Bouffard | 7cdd8d7 | 2011-05-18 17:09:17 +0200 | [diff] [blame] | 1761 | case USB_ID(0x041e, 0x30df): |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 1762 | case USB_ID(0x041e, 0x3048): |
| 1763 | err = snd_audigy2nx_controls_create(mixer); |
| 1764 | if (err < 0) |
| 1765 | break; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 1766 | if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry)) |
| 1767 | snd_info_set_text_ops(entry, mixer, |
| 1768 | snd_audigy2nx_proc_read); |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 1769 | break; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 1770 | |
Vasily Khoruzhick | 44832a7 | 2013-11-13 13:13:35 +0300 | [diff] [blame] | 1771 | /* EMU0204 */ |
| 1772 | case USB_ID(0x041e, 0x3f19): |
| 1773 | err = snd_emu0204_controls_create(mixer); |
| 1774 | if (err < 0) |
| 1775 | break; |
| 1776 | break; |
| 1777 | |
Eldad Zack | 09d8e3a | 2012-11-28 23:55:40 +0100 | [diff] [blame] | 1778 | case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */ |
Matt Gruskin | e9a25e0 | 2013-02-09 12:56:35 -0500 | [diff] [blame] | 1779 | case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */ |
Eldad Zack | 09d8e3a | 2012-11-28 23:55:40 +0100 | [diff] [blame] | 1780 | err = snd_c400_create_mixer(mixer); |
| 1781 | break; |
| 1782 | |
Daniel Mack | d5a0bf6cc | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 1783 | case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */ |
| 1784 | case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */ |
Felix Homann | cfe8f97 | 2012-04-23 20:24:26 +0200 | [diff] [blame] | 1785 | err = snd_ftu_create_mixer(mixer); |
Daniel Mack | d5a0bf6cc | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 1786 | break; |
| 1787 | |
Denis Washington | 1d31aff | 2012-12-11 11:38:32 +0100 | [diff] [blame] | 1788 | case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */ |
| 1789 | case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */ |
| 1790 | case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */ |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 1791 | err = snd_xonar_u1_controls_create(mixer); |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 1792 | break; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 1793 | |
Przemek Rudy | 066624c | 2013-06-27 23:52:33 +0200 | [diff] [blame] | 1794 | case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */ |
| 1795 | err = snd_microii_controls_create(mixer); |
| 1796 | break; |
| 1797 | |
Damien Zammit | d497a82 | 2014-11-12 01:09:54 +1100 | [diff] [blame] | 1798 | case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */ |
| 1799 | err = snd_mbox1_create_sync_switch(mixer); |
| 1800 | break; |
| 1801 | |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 1802 | case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */ |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 1803 | err = snd_nativeinstruments_create_mixer(mixer, |
| 1804 | snd_nativeinstruments_ta6_mixers, |
| 1805 | ARRAY_SIZE(snd_nativeinstruments_ta6_mixers)); |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 1806 | break; |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 1807 | |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 1808 | case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */ |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 1809 | err = snd_nativeinstruments_create_mixer(mixer, |
| 1810 | snd_nativeinstruments_ta10_mixers, |
| 1811 | ARRAY_SIZE(snd_nativeinstruments_ta10_mixers)); |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 1812 | break; |
Mark Hills | 7536c30 | 2012-04-14 17:19:24 +0100 | [diff] [blame] | 1813 | |
| 1814 | case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */ |
Mark Hills | b71dad18 | 2012-06-09 13:16:38 +0100 | [diff] [blame] | 1815 | /* detection is disabled in mixer_maps.c */ |
| 1816 | err = snd_create_std_mono_table(mixer, ebox44_table); |
Mark Hills | 7536c30 | 2012-04-14 17:19:24 +0100 | [diff] [blame] | 1817 | break; |
Chris J Arges | 76b188c | 2014-11-12 12:07:02 -0600 | [diff] [blame] | 1818 | |
| 1819 | case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */ |
| 1820 | case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */ |
| 1821 | case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */ |
| 1822 | case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */ |
| 1823 | case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */ |
| 1824 | err = snd_scarlett_controls_create(mixer); |
| 1825 | break; |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 1826 | } |
| 1827 | |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 1828 | return err; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer, |
| 1832 | int unitid) |
| 1833 | { |
| 1834 | if (!mixer->rc_cfg) |
| 1835 | return; |
| 1836 | /* unit ids specific to Extigy/Audigy 2 NX: */ |
| 1837 | switch (unitid) { |
| 1838 | case 0: /* remote control */ |
| 1839 | mixer->rc_urb->dev = mixer->chip->dev; |
| 1840 | usb_submit_urb(mixer->rc_urb, GFP_ATOMIC); |
| 1841 | break; |
| 1842 | case 4: /* digital in jack */ |
| 1843 | case 7: /* line in jacks */ |
| 1844 | case 19: /* speaker out jacks */ |
| 1845 | case 20: /* headphones out jack */ |
| 1846 | break; |
| 1847 | /* live24ext: 4 = line-in jack */ |
| 1848 | case 3: /* hp-out jack (may actuate Mute) */ |
| 1849 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || |
| 1850 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) |
| 1851 | snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id); |
| 1852 | break; |
| 1853 | default: |
Takashi Iwai | 0ba41d9 | 2014-02-26 13:02:17 +0100 | [diff] [blame] | 1854 | usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid); |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 1855 | break; |
| 1856 | } |
| 1857 | } |
| 1858 | |