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 | * |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software |
| 25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 26 | */ |
| 27 | |
| 28 | #include <linux/init.h> |
Stephen Rothwell | 36db045 | 2010-03-29 16:02:50 +1100 | [diff] [blame] | 29 | #include <linux/slab.h> |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 30 | #include <linux/usb.h> |
| 31 | #include <linux/usb/audio.h> |
| 32 | |
| 33 | #include <sound/core.h> |
| 34 | #include <sound/control.h> |
| 35 | #include <sound/hwdep.h> |
| 36 | #include <sound/info.h> |
| 37 | |
| 38 | #include "usbaudio.h" |
Daniel Mack | f0b5e63 | 2010-03-11 21:13:23 +0100 | [diff] [blame] | 39 | #include "mixer.h" |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 40 | #include "mixer_quirks.h" |
| 41 | #include "helper.h" |
| 42 | |
Daniel Mack | d5a0bf6 | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 43 | extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl; |
| 44 | |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 45 | /* private_free callback */ |
| 46 | static void usb_mixer_elem_free(struct snd_kcontrol *kctl) |
| 47 | { |
| 48 | kfree(kctl->private_data); |
| 49 | kctl->private_data = NULL; |
| 50 | } |
| 51 | |
| 52 | /* This function allows for the creation of standard UAC controls. |
| 53 | * See the quirks for M-Audio FTUs or Ebox-44. |
| 54 | * If you don't want to set a TLV callback pass NULL. |
| 55 | * |
| 56 | * Since there doesn't seem to be a devices that needs a multichannel |
| 57 | * version, we keep it mono for simplicity. |
| 58 | */ |
| 59 | static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer, |
| 60 | unsigned int unitid, |
| 61 | unsigned int control, |
| 62 | unsigned int cmask, |
| 63 | int val_type, |
| 64 | const char *name, |
| 65 | snd_kcontrol_tlv_rw_t *tlv_callback) |
| 66 | { |
| 67 | int err; |
| 68 | struct usb_mixer_elem_info *cval; |
| 69 | struct snd_kcontrol *kctl; |
| 70 | |
| 71 | cval = kzalloc(sizeof(*cval), GFP_KERNEL); |
| 72 | if (!cval) |
| 73 | return -ENOMEM; |
| 74 | |
| 75 | cval->id = unitid; |
| 76 | cval->mixer = mixer; |
| 77 | cval->val_type = val_type; |
| 78 | cval->channels = 1; |
| 79 | cval->control = control; |
| 80 | cval->cmask = cmask; |
| 81 | |
| 82 | /* FIXME: Do we need this? |
| 83 | * The following values are for compatibility with |
| 84 | * Ebox-44 mixer. |
| 85 | * But the corresponding ebox-44 function says: |
| 86 | * "Volume controls will override these values" |
| 87 | * |
| 88 | * These values don't have any effect at all for |
| 89 | * M-Audio FTUs. |
| 90 | * So I think, we can safely omit the range settings here. |
| 91 | */ |
| 92 | cval->min = 0; |
| 93 | cval->max = 1; |
| 94 | cval->res = 0; |
| 95 | cval->dBmin = 0; |
| 96 | cval->dBmax = 0; |
| 97 | |
| 98 | /* Create control */ |
| 99 | kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval); |
| 100 | if (!kctl) { |
| 101 | kfree(cval); |
| 102 | return -ENOMEM; |
| 103 | } |
| 104 | |
| 105 | /* Set name */ |
| 106 | snprintf(kctl->id.name, sizeof(kctl->id.name), name); |
| 107 | kctl->private_free = usb_mixer_elem_free; |
| 108 | |
| 109 | /* set TLV */ |
| 110 | if (tlv_callback) { |
| 111 | kctl->tlv.c = tlv_callback; |
| 112 | kctl->vd[0].access |= |
| 113 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | |
| 114 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; |
| 115 | } |
| 116 | /* Add control to mixer */ |
| 117 | err = snd_usb_mixer_add_control(mixer, kctl); |
| 118 | if (err < 0) |
| 119 | return err; |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 124 | /* |
| 125 | * Sound Blaster remote control configuration |
| 126 | * |
| 127 | * format of remote control data: |
| 128 | * Extigy: xx 00 |
| 129 | * Audigy 2 NX: 06 80 xx 00 00 00 |
| 130 | * Live! 24-bit: 06 80 xx yy 22 83 |
| 131 | */ |
| 132 | static const struct rc_config { |
| 133 | u32 usb_id; |
| 134 | u8 offset; |
| 135 | u8 length; |
| 136 | u8 packet_length; |
| 137 | u8 min_packet_length; /* minimum accepted length of the URB result */ |
| 138 | u8 mute_mixer_id; |
| 139 | u32 mute_code; |
| 140 | } rc_configs[] = { |
| 141 | { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */ |
| 142 | { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */ |
| 143 | { 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] | 144 | { 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] | 145 | { 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] | 146 | { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */ |
| 147 | }; |
| 148 | |
| 149 | static void snd_usb_soundblaster_remote_complete(struct urb *urb) |
| 150 | { |
| 151 | struct usb_mixer_interface *mixer = urb->context; |
| 152 | const struct rc_config *rc = mixer->rc_cfg; |
| 153 | u32 code; |
| 154 | |
| 155 | if (urb->status < 0 || urb->actual_length < rc->min_packet_length) |
| 156 | return; |
| 157 | |
| 158 | code = mixer->rc_buffer[rc->offset]; |
| 159 | if (rc->length == 2) |
| 160 | code |= mixer->rc_buffer[rc->offset + 1] << 8; |
| 161 | |
| 162 | /* the Mute button actually changes the mixer control */ |
| 163 | if (code == rc->mute_code) |
| 164 | snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id); |
| 165 | mixer->rc_code = code; |
| 166 | wmb(); |
| 167 | wake_up(&mixer->rc_waitq); |
| 168 | } |
| 169 | |
| 170 | static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf, |
| 171 | long count, loff_t *offset) |
| 172 | { |
| 173 | struct usb_mixer_interface *mixer = hw->private_data; |
| 174 | int err; |
| 175 | u32 rc_code; |
| 176 | |
| 177 | if (count != 1 && count != 4) |
| 178 | return -EINVAL; |
| 179 | err = wait_event_interruptible(mixer->rc_waitq, |
| 180 | (rc_code = xchg(&mixer->rc_code, 0)) != 0); |
| 181 | if (err == 0) { |
| 182 | if (count == 1) |
| 183 | err = put_user(rc_code, buf); |
| 184 | else |
| 185 | err = put_user(rc_code, (u32 __user *)buf); |
| 186 | } |
| 187 | return err < 0 ? err : count; |
| 188 | } |
| 189 | |
| 190 | static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file, |
| 191 | poll_table *wait) |
| 192 | { |
| 193 | struct usb_mixer_interface *mixer = hw->private_data; |
| 194 | |
| 195 | poll_wait(file, &mixer->rc_waitq, wait); |
| 196 | return mixer->rc_code ? POLLIN | POLLRDNORM : 0; |
| 197 | } |
| 198 | |
| 199 | static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer) |
| 200 | { |
| 201 | struct snd_hwdep *hwdep; |
| 202 | int err, len, i; |
| 203 | |
| 204 | for (i = 0; i < ARRAY_SIZE(rc_configs); ++i) |
| 205 | if (rc_configs[i].usb_id == mixer->chip->usb_id) |
| 206 | break; |
| 207 | if (i >= ARRAY_SIZE(rc_configs)) |
| 208 | return 0; |
| 209 | mixer->rc_cfg = &rc_configs[i]; |
| 210 | |
| 211 | len = mixer->rc_cfg->packet_length; |
| 212 | |
| 213 | init_waitqueue_head(&mixer->rc_waitq); |
| 214 | err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep); |
| 215 | if (err < 0) |
| 216 | return err; |
| 217 | snprintf(hwdep->name, sizeof(hwdep->name), |
| 218 | "%s remote control", mixer->chip->card->shortname); |
| 219 | hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC; |
| 220 | hwdep->private_data = mixer; |
| 221 | hwdep->ops.read = snd_usb_sbrc_hwdep_read; |
| 222 | hwdep->ops.poll = snd_usb_sbrc_hwdep_poll; |
| 223 | hwdep->exclusive = 1; |
| 224 | |
| 225 | mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL); |
| 226 | if (!mixer->rc_urb) |
| 227 | return -ENOMEM; |
| 228 | mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL); |
| 229 | if (!mixer->rc_setup_packet) { |
| 230 | usb_free_urb(mixer->rc_urb); |
| 231 | mixer->rc_urb = NULL; |
| 232 | return -ENOMEM; |
| 233 | } |
| 234 | mixer->rc_setup_packet->bRequestType = |
| 235 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE; |
| 236 | mixer->rc_setup_packet->bRequest = UAC_GET_MEM; |
| 237 | mixer->rc_setup_packet->wValue = cpu_to_le16(0); |
| 238 | mixer->rc_setup_packet->wIndex = cpu_to_le16(0); |
| 239 | mixer->rc_setup_packet->wLength = cpu_to_le16(len); |
| 240 | usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev, |
| 241 | usb_rcvctrlpipe(mixer->chip->dev, 0), |
| 242 | (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len, |
| 243 | snd_usb_soundblaster_remote_complete, mixer); |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info |
| 248 | |
| 249 | static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 250 | { |
| 251 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 252 | int index = kcontrol->private_value; |
| 253 | |
| 254 | ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index]; |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 259 | { |
| 260 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 261 | int index = kcontrol->private_value; |
| 262 | int value = ucontrol->value.integer.value[0]; |
| 263 | int err, changed; |
| 264 | |
| 265 | if (value > 1) |
| 266 | return -EINVAL; |
| 267 | changed = value != mixer->audigy2nx_leds[index]; |
Mandar Joshi | ca8dc34 | 2010-11-02 14:43:19 +0000 | [diff] [blame] | 268 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) |
| 269 | err = snd_usb_ctl_msg(mixer->chip->dev, |
| 270 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, |
| 271 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
Clemens Ladisch | 17d900c | 2011-09-26 21:15:27 +0200 | [diff] [blame] | 272 | !value, 0, NULL, 0); |
Mathieu Bouffard | 7cdd8d7 | 2011-05-18 17:09:17 +0200 | [diff] [blame] | 273 | /* USB X-Fi S51 Pro */ |
| 274 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) |
| 275 | err = snd_usb_ctl_msg(mixer->chip->dev, |
| 276 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, |
| 277 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
Clemens Ladisch | 17d900c | 2011-09-26 21:15:27 +0200 | [diff] [blame] | 278 | !value, 0, NULL, 0); |
Mandar Joshi | ca8dc34 | 2010-11-02 14:43:19 +0000 | [diff] [blame] | 279 | else |
| 280 | err = snd_usb_ctl_msg(mixer->chip->dev, |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 281 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, |
| 282 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
Clemens Ladisch | 17d900c | 2011-09-26 21:15:27 +0200 | [diff] [blame] | 283 | value, index + 2, NULL, 0); |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 284 | if (err < 0) |
| 285 | return err; |
| 286 | mixer->audigy2nx_leds[index] = value; |
| 287 | return changed; |
| 288 | } |
| 289 | |
| 290 | static struct snd_kcontrol_new snd_audigy2nx_controls[] = { |
| 291 | { |
| 292 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 293 | .name = "CMSS LED Switch", |
| 294 | .info = snd_audigy2nx_led_info, |
| 295 | .get = snd_audigy2nx_led_get, |
| 296 | .put = snd_audigy2nx_led_put, |
| 297 | .private_value = 0, |
| 298 | }, |
| 299 | { |
| 300 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 301 | .name = "Power LED Switch", |
| 302 | .info = snd_audigy2nx_led_info, |
| 303 | .get = snd_audigy2nx_led_get, |
| 304 | .put = snd_audigy2nx_led_put, |
| 305 | .private_value = 1, |
| 306 | }, |
| 307 | { |
| 308 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 309 | .name = "Dolby Digital LED Switch", |
| 310 | .info = snd_audigy2nx_led_info, |
| 311 | .get = snd_audigy2nx_led_get, |
| 312 | .put = snd_audigy2nx_led_put, |
| 313 | .private_value = 2, |
| 314 | }, |
| 315 | }; |
| 316 | |
| 317 | static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer) |
| 318 | { |
| 319 | int i, err; |
| 320 | |
| 321 | for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) { |
Mandar Joshi | ca8dc34 | 2010-11-02 14:43:19 +0000 | [diff] [blame] | 322 | /* USB X-Fi S51 doesn't have a CMSS LED */ |
| 323 | if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0) |
| 324 | continue; |
Mathieu Bouffard | 7cdd8d7 | 2011-05-18 17:09:17 +0200 | [diff] [blame] | 325 | /* USB X-Fi S51 Pro doesn't have one either */ |
| 326 | if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0) |
| 327 | continue; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 328 | if (i > 1 && /* Live24ext has 2 LEDs only */ |
| 329 | (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || |
Mandar Joshi | ca8dc34 | 2010-11-02 14:43:19 +0000 | [diff] [blame] | 330 | mixer->chip->usb_id == USB_ID(0x041e, 0x3042) || |
Mathieu Bouffard | 7cdd8d7 | 2011-05-18 17:09:17 +0200 | [diff] [blame] | 331 | mixer->chip->usb_id == USB_ID(0x041e, 0x30df) || |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 332 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048))) |
| 333 | break; |
| 334 | err = snd_ctl_add(mixer->chip->card, |
| 335 | snd_ctl_new1(&snd_audigy2nx_controls[i], mixer)); |
| 336 | if (err < 0) |
| 337 | return err; |
| 338 | } |
| 339 | mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */ |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, |
| 344 | struct snd_info_buffer *buffer) |
| 345 | { |
| 346 | static const struct sb_jack { |
| 347 | int unitid; |
| 348 | const char *name; |
| 349 | } jacks_audigy2nx[] = { |
| 350 | {4, "dig in "}, |
| 351 | {7, "line in"}, |
| 352 | {19, "spk out"}, |
| 353 | {20, "hph out"}, |
| 354 | {-1, NULL} |
| 355 | }, jacks_live24ext[] = { |
| 356 | {4, "line in"}, /* &1=Line, &2=Mic*/ |
| 357 | {3, "hph out"}, /* headphones */ |
| 358 | {0, "RC "}, /* last command, 6 bytes see rc_config above */ |
| 359 | {-1, NULL} |
| 360 | }; |
| 361 | const struct sb_jack *jacks; |
| 362 | struct usb_mixer_interface *mixer = entry->private_data; |
| 363 | int i, err; |
| 364 | u8 buf[3]; |
| 365 | |
| 366 | snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname); |
| 367 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020)) |
| 368 | jacks = jacks_audigy2nx; |
| 369 | else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || |
| 370 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) |
| 371 | jacks = jacks_live24ext; |
| 372 | else |
| 373 | return; |
| 374 | |
| 375 | for (i = 0; jacks[i].name; ++i) { |
| 376 | snd_iprintf(buffer, "%s: ", jacks[i].name); |
| 377 | err = snd_usb_ctl_msg(mixer->chip->dev, |
| 378 | usb_rcvctrlpipe(mixer->chip->dev, 0), |
| 379 | UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS | |
| 380 | USB_RECIP_INTERFACE, 0, |
Clemens Ladisch | 17d900c | 2011-09-26 21:15:27 +0200 | [diff] [blame] | 381 | jacks[i].unitid << 8, buf, 3); |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 382 | if (err == 3 && (buf[0] == 3 || buf[0] == 6)) |
| 383 | snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]); |
| 384 | else |
| 385 | snd_iprintf(buffer, "?\n"); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol, |
| 390 | struct snd_ctl_elem_value *ucontrol) |
| 391 | { |
| 392 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 393 | |
| 394 | ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02); |
| 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol, |
| 399 | struct snd_ctl_elem_value *ucontrol) |
| 400 | { |
| 401 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 402 | u8 old_status, new_status; |
| 403 | int err, changed; |
| 404 | |
| 405 | old_status = mixer->xonar_u1_status; |
| 406 | if (ucontrol->value.integer.value[0]) |
| 407 | new_status = old_status | 0x02; |
| 408 | else |
| 409 | new_status = old_status & ~0x02; |
| 410 | changed = new_status != old_status; |
| 411 | err = snd_usb_ctl_msg(mixer->chip->dev, |
| 412 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x08, |
| 413 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
Clemens Ladisch | 17d900c | 2011-09-26 21:15:27 +0200 | [diff] [blame] | 414 | 50, 0, &new_status, 1); |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 415 | if (err < 0) |
| 416 | return err; |
| 417 | mixer->xonar_u1_status = new_status; |
| 418 | return changed; |
| 419 | } |
| 420 | |
| 421 | static struct snd_kcontrol_new snd_xonar_u1_output_switch = { |
| 422 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 423 | .name = "Digital Playback Switch", |
| 424 | .info = snd_ctl_boolean_mono_info, |
| 425 | .get = snd_xonar_u1_switch_get, |
| 426 | .put = snd_xonar_u1_switch_put, |
| 427 | }; |
| 428 | |
| 429 | static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer) |
| 430 | { |
| 431 | int err; |
| 432 | |
| 433 | err = snd_ctl_add(mixer->chip->card, |
| 434 | snd_ctl_new1(&snd_xonar_u1_output_switch, mixer)); |
| 435 | if (err < 0) |
| 436 | return err; |
| 437 | mixer->xonar_u1_status = 0x05; |
| 438 | return 0; |
| 439 | } |
| 440 | |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 441 | /* Native Instruments device quirks */ |
| 442 | |
| 443 | #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex)) |
| 444 | |
| 445 | static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol, |
| 446 | struct snd_ctl_elem_value *ucontrol) |
| 447 | { |
| 448 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 449 | struct usb_device *dev = mixer->chip->dev; |
| 450 | u8 bRequest = (kcontrol->private_value >> 16) & 0xff; |
| 451 | u16 wIndex = kcontrol->private_value & 0xffff; |
| 452 | u8 tmp; |
| 453 | |
| 454 | int ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest, |
| 455 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
| 456 | 0, cpu_to_le16(wIndex), |
| 457 | &tmp, sizeof(tmp), 1000); |
| 458 | |
| 459 | if (ret < 0) { |
| 460 | snd_printk(KERN_ERR |
| 461 | "unable to issue vendor read request (ret = %d)", ret); |
| 462 | return ret; |
| 463 | } |
| 464 | |
| 465 | ucontrol->value.integer.value[0] = tmp; |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol, |
| 471 | struct snd_ctl_elem_value *ucontrol) |
| 472 | { |
| 473 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 474 | struct usb_device *dev = mixer->chip->dev; |
| 475 | u8 bRequest = (kcontrol->private_value >> 16) & 0xff; |
| 476 | u16 wIndex = kcontrol->private_value & 0xffff; |
| 477 | u16 wValue = ucontrol->value.integer.value[0]; |
| 478 | |
| 479 | int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), bRequest, |
| 480 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, |
| 481 | cpu_to_le16(wValue), cpu_to_le16(wIndex), |
| 482 | NULL, 0, 1000); |
| 483 | |
| 484 | if (ret < 0) { |
| 485 | snd_printk(KERN_ERR |
| 486 | "unable to issue vendor write request (ret = %d)", ret); |
| 487 | return ret; |
| 488 | } |
| 489 | |
| 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | static struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = { |
| 494 | { |
| 495 | .name = "Direct Thru Channel A", |
| 496 | .private_value = _MAKE_NI_CONTROL(0x01, 0x03), |
| 497 | }, |
| 498 | { |
| 499 | .name = "Direct Thru Channel B", |
| 500 | .private_value = _MAKE_NI_CONTROL(0x01, 0x05), |
| 501 | }, |
| 502 | { |
| 503 | .name = "Phono Input Channel A", |
| 504 | .private_value = _MAKE_NI_CONTROL(0x02, 0x03), |
| 505 | }, |
| 506 | { |
| 507 | .name = "Phono Input Channel B", |
| 508 | .private_value = _MAKE_NI_CONTROL(0x02, 0x05), |
| 509 | }, |
| 510 | }; |
| 511 | |
| 512 | static struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = { |
| 513 | { |
| 514 | .name = "Direct Thru Channel A", |
| 515 | .private_value = _MAKE_NI_CONTROL(0x01, 0x03), |
| 516 | }, |
| 517 | { |
| 518 | .name = "Direct Thru Channel B", |
| 519 | .private_value = _MAKE_NI_CONTROL(0x01, 0x05), |
| 520 | }, |
| 521 | { |
| 522 | .name = "Direct Thru Channel C", |
| 523 | .private_value = _MAKE_NI_CONTROL(0x01, 0x07), |
| 524 | }, |
| 525 | { |
| 526 | .name = "Direct Thru Channel D", |
| 527 | .private_value = _MAKE_NI_CONTROL(0x01, 0x09), |
| 528 | }, |
| 529 | { |
| 530 | .name = "Phono Input Channel A", |
| 531 | .private_value = _MAKE_NI_CONTROL(0x02, 0x03), |
| 532 | }, |
| 533 | { |
| 534 | .name = "Phono Input Channel B", |
| 535 | .private_value = _MAKE_NI_CONTROL(0x02, 0x05), |
| 536 | }, |
| 537 | { |
| 538 | .name = "Phono Input Channel C", |
| 539 | .private_value = _MAKE_NI_CONTROL(0x02, 0x07), |
| 540 | }, |
| 541 | { |
| 542 | .name = "Phono Input Channel D", |
| 543 | .private_value = _MAKE_NI_CONTROL(0x02, 0x09), |
| 544 | }, |
| 545 | }; |
| 546 | |
| 547 | static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer, |
| 548 | const struct snd_kcontrol_new *kc, |
| 549 | unsigned int count) |
| 550 | { |
| 551 | int i, err = 0; |
| 552 | struct snd_kcontrol_new template = { |
| 553 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 554 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 555 | .get = snd_nativeinstruments_control_get, |
| 556 | .put = snd_nativeinstruments_control_put, |
| 557 | .info = snd_ctl_boolean_mono_info, |
| 558 | }; |
| 559 | |
| 560 | for (i = 0; i < count; i++) { |
| 561 | struct snd_kcontrol *c; |
| 562 | |
| 563 | template.name = kc[i].name; |
| 564 | template.private_value = kc[i].private_value; |
| 565 | |
| 566 | c = snd_ctl_new1(&template, mixer); |
| 567 | err = snd_ctl_add(mixer->chip->card, c); |
| 568 | |
| 569 | if (err < 0) |
| 570 | break; |
| 571 | } |
| 572 | |
| 573 | return err; |
| 574 | } |
| 575 | |
Daniel Mack | d5a0bf6 | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 576 | /* M-Audio FastTrack Ultra quirks */ |
| 577 | |
Felix Homann | cfe8f97 | 2012-04-23 20:24:26 +0200 | [diff] [blame^] | 578 | /* Create volume controls for FTU devices*/ |
| 579 | static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer) |
Daniel Mack | d5a0bf6 | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 580 | { |
| 581 | char name[64]; |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 582 | unsigned int control, cmask; |
Daniel Mack | d5a0bf6 | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 583 | int in, out, err; |
| 584 | |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 585 | const unsigned int id = 5; |
| 586 | const int val_type = USB_MIXER_S16; |
| 587 | |
Daniel Mack | d5a0bf6 | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 588 | for (out = 0; out < 8; out++) { |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 589 | control = out + 1; |
Daniel Mack | d5a0bf6 | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 590 | for (in = 0; in < 8; in++) { |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 591 | cmask = 1 << in; |
Daniel Mack | d5a0bf6 | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 592 | snprintf(name, sizeof(name), |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 593 | "AIn%d - Out%d Capture Volume", |
| 594 | in + 1, out + 1); |
| 595 | err = snd_create_std_mono_ctl(mixer, id, control, |
| 596 | cmask, val_type, name, |
Felix Homann | 25ee7ef | 2012-04-23 20:24:25 +0200 | [diff] [blame] | 597 | &snd_usb_mixer_vol_tlv); |
Daniel Mack | d5a0bf6 | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 598 | if (err < 0) |
| 599 | return err; |
| 600 | } |
Daniel Mack | d5a0bf6 | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 601 | for (in = 8; in < 16; in++) { |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 602 | cmask = 1 << in; |
Daniel Mack | d5a0bf6 | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 603 | snprintf(name, sizeof(name), |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 604 | "DIn%d - Out%d Playback Volume", |
| 605 | in - 7, out + 1); |
| 606 | err = snd_create_std_mono_ctl(mixer, id, control, |
| 607 | cmask, val_type, name, |
Felix Homann | 25ee7ef | 2012-04-23 20:24:25 +0200 | [diff] [blame] | 608 | &snd_usb_mixer_vol_tlv); |
Daniel Mack | d5a0bf6 | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 609 | if (err < 0) |
| 610 | return err; |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | return 0; |
| 615 | } |
| 616 | |
Felix Homann | cfe8f97 | 2012-04-23 20:24:26 +0200 | [diff] [blame^] | 617 | static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer) |
Mark Hills | 7536c30 | 2012-04-14 17:19:24 +0100 | [diff] [blame] | 618 | { |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 619 | int err; |
Mark Hills | 7536c30 | 2012-04-14 17:19:24 +0100 | [diff] [blame] | 620 | |
Felix Homann | cfe8f97 | 2012-04-23 20:24:26 +0200 | [diff] [blame^] | 621 | err = snd_ftu_create_volume_ctls(mixer); |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 622 | if (err < 0) |
| 623 | return err; |
Mark Hills | 7536c30 | 2012-04-14 17:19:24 +0100 | [diff] [blame] | 624 | |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 625 | return 0; |
Mark Hills | 7536c30 | 2012-04-14 17:19:24 +0100 | [diff] [blame] | 626 | } |
| 627 | |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 628 | |
Mark Hills | 7536c30 | 2012-04-14 17:19:24 +0100 | [diff] [blame] | 629 | /* |
| 630 | * Create mixer for Electrix Ebox-44 |
| 631 | * |
| 632 | * The mixer units from this device are corrupt, and even where they |
| 633 | * are valid they presents mono controls as L and R channels of |
| 634 | * stereo. So we create a good mixer in code. |
| 635 | */ |
| 636 | |
| 637 | static int snd_ebox44_create_mixer(struct usb_mixer_interface *mixer) |
| 638 | { |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 639 | snd_create_std_mono_ctl(mixer, 4, 1, 0x0, USB_MIXER_INV_BOOLEAN, |
| 640 | "Headphone Playback Switch", NULL); |
| 641 | snd_create_std_mono_ctl(mixer, 4, 2, 0x1, USB_MIXER_S16, |
| 642 | "Headphone A Mix Playback Volume", NULL); |
| 643 | snd_create_std_mono_ctl(mixer, 4, 2, 0x2, USB_MIXER_S16, |
| 644 | "Headphone B Mix Playback Volume", NULL); |
Mark Hills | 7536c30 | 2012-04-14 17:19:24 +0100 | [diff] [blame] | 645 | |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 646 | snd_create_std_mono_ctl(mixer, 7, 1, 0x0, USB_MIXER_INV_BOOLEAN, |
| 647 | "Output Playback Switch", NULL); |
| 648 | snd_create_std_mono_ctl(mixer, 7, 2, 0x1, USB_MIXER_S16, |
| 649 | "Output A Playback Volume", NULL); |
| 650 | snd_create_std_mono_ctl(mixer, 7, 2, 0x2, USB_MIXER_S16, |
| 651 | "Output B Playback Volume", NULL); |
Mark Hills | 7536c30 | 2012-04-14 17:19:24 +0100 | [diff] [blame] | 652 | |
Felix Homann | 8a4d1d3 | 2012-04-23 20:24:23 +0200 | [diff] [blame] | 653 | snd_create_std_mono_ctl(mixer, 10, 1, 0x0, USB_MIXER_INV_BOOLEAN, |
| 654 | "Input Capture Switch", NULL); |
| 655 | snd_create_std_mono_ctl(mixer, 10, 2, 0x1, USB_MIXER_S16, |
| 656 | "Input A Capture Volume", NULL); |
| 657 | snd_create_std_mono_ctl(mixer, 10, 2, 0x2, USB_MIXER_S16, |
| 658 | "Input B Capture Volume", NULL); |
Mark Hills | 7536c30 | 2012-04-14 17:19:24 +0100 | [diff] [blame] | 659 | |
| 660 | return 0; |
| 661 | } |
| 662 | |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 663 | void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, |
| 664 | unsigned char samplerate_id) |
| 665 | { |
| 666 | struct usb_mixer_interface *mixer; |
| 667 | struct usb_mixer_elem_info *cval; |
| 668 | int unitid = 12; /* SamleRate ExtensionUnit ID */ |
| 669 | |
| 670 | list_for_each_entry(mixer, &chip->mixer_list, list) { |
| 671 | cval = mixer->id_elems[unitid]; |
| 672 | if (cval) { |
| 673 | snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR, |
| 674 | cval->control << 8, |
| 675 | samplerate_id); |
| 676 | snd_usb_mixer_notify_id(mixer, unitid); |
| 677 | } |
| 678 | break; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) |
| 683 | { |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 684 | int err = 0; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 685 | struct snd_info_entry *entry; |
| 686 | |
| 687 | if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0) |
| 688 | return err; |
| 689 | |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 690 | switch (mixer->chip->usb_id) { |
| 691 | case USB_ID(0x041e, 0x3020): |
| 692 | case USB_ID(0x041e, 0x3040): |
| 693 | case USB_ID(0x041e, 0x3042): |
Mathieu Bouffard | 7cdd8d7 | 2011-05-18 17:09:17 +0200 | [diff] [blame] | 694 | case USB_ID(0x041e, 0x30df): |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 695 | case USB_ID(0x041e, 0x3048): |
| 696 | err = snd_audigy2nx_controls_create(mixer); |
| 697 | if (err < 0) |
| 698 | break; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 699 | if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry)) |
| 700 | snd_info_set_text_ops(entry, mixer, |
| 701 | snd_audigy2nx_proc_read); |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 702 | break; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 703 | |
Daniel Mack | d5a0bf6 | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 704 | case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */ |
| 705 | case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */ |
Felix Homann | cfe8f97 | 2012-04-23 20:24:26 +0200 | [diff] [blame^] | 706 | err = snd_ftu_create_mixer(mixer); |
Daniel Mack | d5a0bf6 | 2011-05-25 09:09:03 +0200 | [diff] [blame] | 707 | break; |
| 708 | |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 709 | case USB_ID(0x0b05, 0x1739): |
| 710 | case USB_ID(0x0b05, 0x1743): |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 711 | err = snd_xonar_u1_controls_create(mixer); |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 712 | break; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 713 | |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 714 | case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */ |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 715 | err = snd_nativeinstruments_create_mixer(mixer, |
| 716 | snd_nativeinstruments_ta6_mixers, |
| 717 | ARRAY_SIZE(snd_nativeinstruments_ta6_mixers)); |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 718 | break; |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 719 | |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 720 | case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */ |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 721 | err = snd_nativeinstruments_create_mixer(mixer, |
| 722 | snd_nativeinstruments_ta10_mixers, |
| 723 | ARRAY_SIZE(snd_nativeinstruments_ta10_mixers)); |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 724 | break; |
Mark Hills | 7536c30 | 2012-04-14 17:19:24 +0100 | [diff] [blame] | 725 | |
| 726 | case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */ |
| 727 | err = snd_ebox44_create_mixer(mixer); |
| 728 | break; |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 729 | } |
| 730 | |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 731 | return err; |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer, |
| 735 | int unitid) |
| 736 | { |
| 737 | if (!mixer->rc_cfg) |
| 738 | return; |
| 739 | /* unit ids specific to Extigy/Audigy 2 NX: */ |
| 740 | switch (unitid) { |
| 741 | case 0: /* remote control */ |
| 742 | mixer->rc_urb->dev = mixer->chip->dev; |
| 743 | usb_submit_urb(mixer->rc_urb, GFP_ATOMIC); |
| 744 | break; |
| 745 | case 4: /* digital in jack */ |
| 746 | case 7: /* line in jacks */ |
| 747 | case 19: /* speaker out jacks */ |
| 748 | case 20: /* headphones out jack */ |
| 749 | break; |
| 750 | /* live24ext: 4 = line-in jack */ |
| 751 | case 3: /* hp-out jack (may actuate Mute) */ |
| 752 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || |
| 753 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) |
| 754 | snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id); |
| 755 | break; |
| 756 | default: |
| 757 | snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid); |
| 758 | break; |
| 759 | } |
| 760 | } |
| 761 | |