18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * USB Audio Driver for ALSA 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Quirks and vendor-specific extensions for mixer interfaces 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de> 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Many codes borrowed from audio.c by 108c2ecf20Sopenharmony_ci * Alan Cox (alan@lxorguk.ukuu.org.uk) 118c2ecf20Sopenharmony_ci * Thomas Sailer (sailer@ife.ee.ethz.ch) 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * Audio Advantage Micro II support added by: 148c2ecf20Sopenharmony_ci * Przemek Rudy (prudy1@o2.pl) 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <linux/hid.h> 188c2ecf20Sopenharmony_ci#include <linux/init.h> 198c2ecf20Sopenharmony_ci#include <linux/math64.h> 208c2ecf20Sopenharmony_ci#include <linux/slab.h> 218c2ecf20Sopenharmony_ci#include <linux/usb.h> 228c2ecf20Sopenharmony_ci#include <linux/usb/audio.h> 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#include <sound/asoundef.h> 258c2ecf20Sopenharmony_ci#include <sound/core.h> 268c2ecf20Sopenharmony_ci#include <sound/control.h> 278c2ecf20Sopenharmony_ci#include <sound/hwdep.h> 288c2ecf20Sopenharmony_ci#include <sound/info.h> 298c2ecf20Sopenharmony_ci#include <sound/tlv.h> 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#include "usbaudio.h" 328c2ecf20Sopenharmony_ci#include "mixer.h" 338c2ecf20Sopenharmony_ci#include "mixer_quirks.h" 348c2ecf20Sopenharmony_ci#include "mixer_scarlett.h" 358c2ecf20Sopenharmony_ci#include "mixer_scarlett_gen2.h" 368c2ecf20Sopenharmony_ci#include "mixer_us16x08.h" 378c2ecf20Sopenharmony_ci#include "mixer_s1810c.h" 388c2ecf20Sopenharmony_ci#include "helper.h" 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistruct std_mono_table { 418c2ecf20Sopenharmony_ci unsigned int unitid, control, cmask; 428c2ecf20Sopenharmony_ci int val_type; 438c2ecf20Sopenharmony_ci const char *name; 448c2ecf20Sopenharmony_ci snd_kcontrol_tlv_rw_t *tlv_callback; 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/* This function allows for the creation of standard UAC controls. 488c2ecf20Sopenharmony_ci * See the quirks for M-Audio FTUs or Ebox-44. 498c2ecf20Sopenharmony_ci * If you don't want to set a TLV callback pass NULL. 508c2ecf20Sopenharmony_ci * 518c2ecf20Sopenharmony_ci * Since there doesn't seem to be a devices that needs a multichannel 528c2ecf20Sopenharmony_ci * version, we keep it mono for simplicity. 538c2ecf20Sopenharmony_ci */ 548c2ecf20Sopenharmony_cistatic int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer, 558c2ecf20Sopenharmony_ci unsigned int unitid, 568c2ecf20Sopenharmony_ci unsigned int control, 578c2ecf20Sopenharmony_ci unsigned int cmask, 588c2ecf20Sopenharmony_ci int val_type, 598c2ecf20Sopenharmony_ci unsigned int idx_off, 608c2ecf20Sopenharmony_ci const char *name, 618c2ecf20Sopenharmony_ci snd_kcontrol_tlv_rw_t *tlv_callback) 628c2ecf20Sopenharmony_ci{ 638c2ecf20Sopenharmony_ci struct usb_mixer_elem_info *cval; 648c2ecf20Sopenharmony_ci struct snd_kcontrol *kctl; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci cval = kzalloc(sizeof(*cval), GFP_KERNEL); 678c2ecf20Sopenharmony_ci if (!cval) 688c2ecf20Sopenharmony_ci return -ENOMEM; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid); 718c2ecf20Sopenharmony_ci cval->val_type = val_type; 728c2ecf20Sopenharmony_ci cval->channels = 1; 738c2ecf20Sopenharmony_ci cval->control = control; 748c2ecf20Sopenharmony_ci cval->cmask = cmask; 758c2ecf20Sopenharmony_ci cval->idx_off = idx_off; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci /* get_min_max() is called only for integer volumes later, 788c2ecf20Sopenharmony_ci * so provide a short-cut for booleans */ 798c2ecf20Sopenharmony_ci cval->min = 0; 808c2ecf20Sopenharmony_ci cval->max = 1; 818c2ecf20Sopenharmony_ci cval->res = 0; 828c2ecf20Sopenharmony_ci cval->dBmin = 0; 838c2ecf20Sopenharmony_ci cval->dBmax = 0; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci /* Create control */ 868c2ecf20Sopenharmony_ci kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval); 878c2ecf20Sopenharmony_ci if (!kctl) { 888c2ecf20Sopenharmony_ci kfree(cval); 898c2ecf20Sopenharmony_ci return -ENOMEM; 908c2ecf20Sopenharmony_ci } 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci /* Set name */ 938c2ecf20Sopenharmony_ci snprintf(kctl->id.name, sizeof(kctl->id.name), name); 948c2ecf20Sopenharmony_ci kctl->private_free = snd_usb_mixer_elem_free; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci /* set TLV */ 978c2ecf20Sopenharmony_ci if (tlv_callback) { 988c2ecf20Sopenharmony_ci kctl->tlv.c = tlv_callback; 998c2ecf20Sopenharmony_ci kctl->vd[0].access |= 1008c2ecf20Sopenharmony_ci SNDRV_CTL_ELEM_ACCESS_TLV_READ | 1018c2ecf20Sopenharmony_ci SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; 1028c2ecf20Sopenharmony_ci } 1038c2ecf20Sopenharmony_ci /* Add control to mixer */ 1048c2ecf20Sopenharmony_ci return snd_usb_mixer_add_control(&cval->head, kctl); 1058c2ecf20Sopenharmony_ci} 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistatic int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer, 1088c2ecf20Sopenharmony_ci unsigned int unitid, 1098c2ecf20Sopenharmony_ci unsigned int control, 1108c2ecf20Sopenharmony_ci unsigned int cmask, 1118c2ecf20Sopenharmony_ci int val_type, 1128c2ecf20Sopenharmony_ci const char *name, 1138c2ecf20Sopenharmony_ci snd_kcontrol_tlv_rw_t *tlv_callback) 1148c2ecf20Sopenharmony_ci{ 1158c2ecf20Sopenharmony_ci return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask, 1168c2ecf20Sopenharmony_ci val_type, 0 /* Offset */, name, tlv_callback); 1178c2ecf20Sopenharmony_ci} 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci/* 1208c2ecf20Sopenharmony_ci * Create a set of standard UAC controls from a table 1218c2ecf20Sopenharmony_ci */ 1228c2ecf20Sopenharmony_cistatic int snd_create_std_mono_table(struct usb_mixer_interface *mixer, 1238c2ecf20Sopenharmony_ci const struct std_mono_table *t) 1248c2ecf20Sopenharmony_ci{ 1258c2ecf20Sopenharmony_ci int err; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci while (t->name != NULL) { 1288c2ecf20Sopenharmony_ci err = snd_create_std_mono_ctl(mixer, t->unitid, t->control, 1298c2ecf20Sopenharmony_ci t->cmask, t->val_type, t->name, t->tlv_callback); 1308c2ecf20Sopenharmony_ci if (err < 0) 1318c2ecf20Sopenharmony_ci return err; 1328c2ecf20Sopenharmony_ci t++; 1338c2ecf20Sopenharmony_ci } 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci return 0; 1368c2ecf20Sopenharmony_ci} 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_cistatic int add_single_ctl_with_resume(struct usb_mixer_interface *mixer, 1398c2ecf20Sopenharmony_ci int id, 1408c2ecf20Sopenharmony_ci usb_mixer_elem_resume_func_t resume, 1418c2ecf20Sopenharmony_ci const struct snd_kcontrol_new *knew, 1428c2ecf20Sopenharmony_ci struct usb_mixer_elem_list **listp) 1438c2ecf20Sopenharmony_ci{ 1448c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list; 1458c2ecf20Sopenharmony_ci struct snd_kcontrol *kctl; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci list = kzalloc(sizeof(*list), GFP_KERNEL); 1488c2ecf20Sopenharmony_ci if (!list) 1498c2ecf20Sopenharmony_ci return -ENOMEM; 1508c2ecf20Sopenharmony_ci if (listp) 1518c2ecf20Sopenharmony_ci *listp = list; 1528c2ecf20Sopenharmony_ci list->mixer = mixer; 1538c2ecf20Sopenharmony_ci list->id = id; 1548c2ecf20Sopenharmony_ci list->resume = resume; 1558c2ecf20Sopenharmony_ci kctl = snd_ctl_new1(knew, list); 1568c2ecf20Sopenharmony_ci if (!kctl) { 1578c2ecf20Sopenharmony_ci kfree(list); 1588c2ecf20Sopenharmony_ci return -ENOMEM; 1598c2ecf20Sopenharmony_ci } 1608c2ecf20Sopenharmony_ci kctl->private_free = snd_usb_mixer_elem_free; 1618c2ecf20Sopenharmony_ci /* don't use snd_usb_mixer_add_control() here, this is a special list element */ 1628c2ecf20Sopenharmony_ci return snd_usb_mixer_add_list(list, kctl, false); 1638c2ecf20Sopenharmony_ci} 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci/* 1668c2ecf20Sopenharmony_ci * Sound Blaster remote control configuration 1678c2ecf20Sopenharmony_ci * 1688c2ecf20Sopenharmony_ci * format of remote control data: 1698c2ecf20Sopenharmony_ci * Extigy: xx 00 1708c2ecf20Sopenharmony_ci * Audigy 2 NX: 06 80 xx 00 00 00 1718c2ecf20Sopenharmony_ci * Live! 24-bit: 06 80 xx yy 22 83 1728c2ecf20Sopenharmony_ci */ 1738c2ecf20Sopenharmony_cistatic const struct rc_config { 1748c2ecf20Sopenharmony_ci u32 usb_id; 1758c2ecf20Sopenharmony_ci u8 offset; 1768c2ecf20Sopenharmony_ci u8 length; 1778c2ecf20Sopenharmony_ci u8 packet_length; 1788c2ecf20Sopenharmony_ci u8 min_packet_length; /* minimum accepted length of the URB result */ 1798c2ecf20Sopenharmony_ci u8 mute_mixer_id; 1808c2ecf20Sopenharmony_ci u32 mute_code; 1818c2ecf20Sopenharmony_ci} rc_configs[] = { 1828c2ecf20Sopenharmony_ci { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */ 1838c2ecf20Sopenharmony_ci { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */ 1848c2ecf20Sopenharmony_ci { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */ 1858c2ecf20Sopenharmony_ci { USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */ 1868c2ecf20Sopenharmony_ci { USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */ 1878c2ecf20Sopenharmony_ci { USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */ 1888c2ecf20Sopenharmony_ci { USB_ID(0x041e, 0x3263), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */ 1898c2ecf20Sopenharmony_ci { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */ 1908c2ecf20Sopenharmony_ci}; 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_cistatic void snd_usb_soundblaster_remote_complete(struct urb *urb) 1938c2ecf20Sopenharmony_ci{ 1948c2ecf20Sopenharmony_ci struct usb_mixer_interface *mixer = urb->context; 1958c2ecf20Sopenharmony_ci const struct rc_config *rc = mixer->rc_cfg; 1968c2ecf20Sopenharmony_ci u32 code; 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci if (urb->status < 0 || urb->actual_length < rc->min_packet_length) 1998c2ecf20Sopenharmony_ci return; 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci code = mixer->rc_buffer[rc->offset]; 2028c2ecf20Sopenharmony_ci if (rc->length == 2) 2038c2ecf20Sopenharmony_ci code |= mixer->rc_buffer[rc->offset + 1] << 8; 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci /* the Mute button actually changes the mixer control */ 2068c2ecf20Sopenharmony_ci if (code == rc->mute_code) 2078c2ecf20Sopenharmony_ci snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id); 2088c2ecf20Sopenharmony_ci mixer->rc_code = code; 2098c2ecf20Sopenharmony_ci wmb(); 2108c2ecf20Sopenharmony_ci wake_up(&mixer->rc_waitq); 2118c2ecf20Sopenharmony_ci} 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_cistatic long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf, 2148c2ecf20Sopenharmony_ci long count, loff_t *offset) 2158c2ecf20Sopenharmony_ci{ 2168c2ecf20Sopenharmony_ci struct usb_mixer_interface *mixer = hw->private_data; 2178c2ecf20Sopenharmony_ci int err; 2188c2ecf20Sopenharmony_ci u32 rc_code; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci if (count != 1 && count != 4) 2218c2ecf20Sopenharmony_ci return -EINVAL; 2228c2ecf20Sopenharmony_ci err = wait_event_interruptible(mixer->rc_waitq, 2238c2ecf20Sopenharmony_ci (rc_code = xchg(&mixer->rc_code, 0)) != 0); 2248c2ecf20Sopenharmony_ci if (err == 0) { 2258c2ecf20Sopenharmony_ci if (count == 1) 2268c2ecf20Sopenharmony_ci err = put_user(rc_code, buf); 2278c2ecf20Sopenharmony_ci else 2288c2ecf20Sopenharmony_ci err = put_user(rc_code, (u32 __user *)buf); 2298c2ecf20Sopenharmony_ci } 2308c2ecf20Sopenharmony_ci return err < 0 ? err : count; 2318c2ecf20Sopenharmony_ci} 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_cistatic __poll_t snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file, 2348c2ecf20Sopenharmony_ci poll_table *wait) 2358c2ecf20Sopenharmony_ci{ 2368c2ecf20Sopenharmony_ci struct usb_mixer_interface *mixer = hw->private_data; 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci poll_wait(file, &mixer->rc_waitq, wait); 2398c2ecf20Sopenharmony_ci return mixer->rc_code ? EPOLLIN | EPOLLRDNORM : 0; 2408c2ecf20Sopenharmony_ci} 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_cistatic int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer) 2438c2ecf20Sopenharmony_ci{ 2448c2ecf20Sopenharmony_ci struct snd_hwdep *hwdep; 2458c2ecf20Sopenharmony_ci int err, len, i; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(rc_configs); ++i) 2488c2ecf20Sopenharmony_ci if (rc_configs[i].usb_id == mixer->chip->usb_id) 2498c2ecf20Sopenharmony_ci break; 2508c2ecf20Sopenharmony_ci if (i >= ARRAY_SIZE(rc_configs)) 2518c2ecf20Sopenharmony_ci return 0; 2528c2ecf20Sopenharmony_ci mixer->rc_cfg = &rc_configs[i]; 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci len = mixer->rc_cfg->packet_length; 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci init_waitqueue_head(&mixer->rc_waitq); 2578c2ecf20Sopenharmony_ci err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep); 2588c2ecf20Sopenharmony_ci if (err < 0) 2598c2ecf20Sopenharmony_ci return err; 2608c2ecf20Sopenharmony_ci snprintf(hwdep->name, sizeof(hwdep->name), 2618c2ecf20Sopenharmony_ci "%s remote control", mixer->chip->card->shortname); 2628c2ecf20Sopenharmony_ci hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC; 2638c2ecf20Sopenharmony_ci hwdep->private_data = mixer; 2648c2ecf20Sopenharmony_ci hwdep->ops.read = snd_usb_sbrc_hwdep_read; 2658c2ecf20Sopenharmony_ci hwdep->ops.poll = snd_usb_sbrc_hwdep_poll; 2668c2ecf20Sopenharmony_ci hwdep->exclusive = 1; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL); 2698c2ecf20Sopenharmony_ci if (!mixer->rc_urb) 2708c2ecf20Sopenharmony_ci return -ENOMEM; 2718c2ecf20Sopenharmony_ci mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL); 2728c2ecf20Sopenharmony_ci if (!mixer->rc_setup_packet) { 2738c2ecf20Sopenharmony_ci usb_free_urb(mixer->rc_urb); 2748c2ecf20Sopenharmony_ci mixer->rc_urb = NULL; 2758c2ecf20Sopenharmony_ci return -ENOMEM; 2768c2ecf20Sopenharmony_ci } 2778c2ecf20Sopenharmony_ci mixer->rc_setup_packet->bRequestType = 2788c2ecf20Sopenharmony_ci USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE; 2798c2ecf20Sopenharmony_ci mixer->rc_setup_packet->bRequest = UAC_GET_MEM; 2808c2ecf20Sopenharmony_ci mixer->rc_setup_packet->wValue = cpu_to_le16(0); 2818c2ecf20Sopenharmony_ci mixer->rc_setup_packet->wIndex = cpu_to_le16(0); 2828c2ecf20Sopenharmony_ci mixer->rc_setup_packet->wLength = cpu_to_le16(len); 2838c2ecf20Sopenharmony_ci usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev, 2848c2ecf20Sopenharmony_ci usb_rcvctrlpipe(mixer->chip->dev, 0), 2858c2ecf20Sopenharmony_ci (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len, 2868c2ecf20Sopenharmony_ci snd_usb_soundblaster_remote_complete, mixer); 2878c2ecf20Sopenharmony_ci return 0; 2888c2ecf20Sopenharmony_ci} 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci#define snd_audigy2nx_led_info snd_ctl_boolean_mono_info 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_cistatic int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2938c2ecf20Sopenharmony_ci{ 2948c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = kcontrol->private_value >> 8; 2958c2ecf20Sopenharmony_ci return 0; 2968c2ecf20Sopenharmony_ci} 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_cistatic int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer, 2998c2ecf20Sopenharmony_ci int value, int index) 3008c2ecf20Sopenharmony_ci{ 3018c2ecf20Sopenharmony_ci struct snd_usb_audio *chip = mixer->chip; 3028c2ecf20Sopenharmony_ci int err; 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(chip); 3058c2ecf20Sopenharmony_ci if (err < 0) 3068c2ecf20Sopenharmony_ci return err; 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci if (chip->usb_id == USB_ID(0x041e, 0x3042)) 3098c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 3108c2ecf20Sopenharmony_ci usb_sndctrlpipe(chip->dev, 0), 0x24, 3118c2ecf20Sopenharmony_ci USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 3128c2ecf20Sopenharmony_ci !value, 0, NULL, 0); 3138c2ecf20Sopenharmony_ci /* USB X-Fi S51 Pro */ 3148c2ecf20Sopenharmony_ci if (chip->usb_id == USB_ID(0x041e, 0x30df)) 3158c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 3168c2ecf20Sopenharmony_ci usb_sndctrlpipe(chip->dev, 0), 0x24, 3178c2ecf20Sopenharmony_ci USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 3188c2ecf20Sopenharmony_ci !value, 0, NULL, 0); 3198c2ecf20Sopenharmony_ci else 3208c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 3218c2ecf20Sopenharmony_ci usb_sndctrlpipe(chip->dev, 0), 0x24, 3228c2ecf20Sopenharmony_ci USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 3238c2ecf20Sopenharmony_ci value, index + 2, NULL, 0); 3248c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(chip); 3258c2ecf20Sopenharmony_ci return err; 3268c2ecf20Sopenharmony_ci} 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_cistatic int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, 3298c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 3308c2ecf20Sopenharmony_ci{ 3318c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); 3328c2ecf20Sopenharmony_ci struct usb_mixer_interface *mixer = list->mixer; 3338c2ecf20Sopenharmony_ci int index = kcontrol->private_value & 0xff; 3348c2ecf20Sopenharmony_ci unsigned int value = ucontrol->value.integer.value[0]; 3358c2ecf20Sopenharmony_ci int old_value = kcontrol->private_value >> 8; 3368c2ecf20Sopenharmony_ci int err; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci if (value > 1) 3398c2ecf20Sopenharmony_ci return -EINVAL; 3408c2ecf20Sopenharmony_ci if (value == old_value) 3418c2ecf20Sopenharmony_ci return 0; 3428c2ecf20Sopenharmony_ci kcontrol->private_value = (value << 8) | index; 3438c2ecf20Sopenharmony_ci err = snd_audigy2nx_led_update(mixer, value, index); 3448c2ecf20Sopenharmony_ci return err < 0 ? err : 1; 3458c2ecf20Sopenharmony_ci} 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_cistatic int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list) 3488c2ecf20Sopenharmony_ci{ 3498c2ecf20Sopenharmony_ci int priv_value = list->kctl->private_value; 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci return snd_audigy2nx_led_update(list->mixer, priv_value >> 8, 3528c2ecf20Sopenharmony_ci priv_value & 0xff); 3538c2ecf20Sopenharmony_ci} 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci/* name and private_value are set dynamically */ 3568c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_audigy2nx_control = { 3578c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3588c2ecf20Sopenharmony_ci .info = snd_audigy2nx_led_info, 3598c2ecf20Sopenharmony_ci .get = snd_audigy2nx_led_get, 3608c2ecf20Sopenharmony_ci .put = snd_audigy2nx_led_put, 3618c2ecf20Sopenharmony_ci}; 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_cistatic const char * const snd_audigy2nx_led_names[] = { 3648c2ecf20Sopenharmony_ci "CMSS LED Switch", 3658c2ecf20Sopenharmony_ci "Power LED Switch", 3668c2ecf20Sopenharmony_ci "Dolby Digital LED Switch", 3678c2ecf20Sopenharmony_ci}; 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_cistatic int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer) 3708c2ecf20Sopenharmony_ci{ 3718c2ecf20Sopenharmony_ci int i, err; 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) { 3748c2ecf20Sopenharmony_ci struct snd_kcontrol_new knew; 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci /* USB X-Fi S51 doesn't have a CMSS LED */ 3778c2ecf20Sopenharmony_ci if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0) 3788c2ecf20Sopenharmony_ci continue; 3798c2ecf20Sopenharmony_ci /* USB X-Fi S51 Pro doesn't have one either */ 3808c2ecf20Sopenharmony_ci if ((mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) && i == 0) 3818c2ecf20Sopenharmony_ci continue; 3828c2ecf20Sopenharmony_ci if (i > 1 && /* Live24ext has 2 LEDs only */ 3838c2ecf20Sopenharmony_ci (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || 3848c2ecf20Sopenharmony_ci mixer->chip->usb_id == USB_ID(0x041e, 0x3042) || 3858c2ecf20Sopenharmony_ci mixer->chip->usb_id == USB_ID(0x041e, 0x30df) || 3868c2ecf20Sopenharmony_ci mixer->chip->usb_id == USB_ID(0x041e, 0x3048))) 3878c2ecf20Sopenharmony_ci break; 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci knew = snd_audigy2nx_control; 3908c2ecf20Sopenharmony_ci knew.name = snd_audigy2nx_led_names[i]; 3918c2ecf20Sopenharmony_ci knew.private_value = (1 << 8) | i; /* LED on as default */ 3928c2ecf20Sopenharmony_ci err = add_single_ctl_with_resume(mixer, 0, 3938c2ecf20Sopenharmony_ci snd_audigy2nx_led_resume, 3948c2ecf20Sopenharmony_ci &knew, NULL); 3958c2ecf20Sopenharmony_ci if (err < 0) 3968c2ecf20Sopenharmony_ci return err; 3978c2ecf20Sopenharmony_ci } 3988c2ecf20Sopenharmony_ci return 0; 3998c2ecf20Sopenharmony_ci} 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_cistatic void snd_audigy2nx_proc_read(struct snd_info_entry *entry, 4028c2ecf20Sopenharmony_ci struct snd_info_buffer *buffer) 4038c2ecf20Sopenharmony_ci{ 4048c2ecf20Sopenharmony_ci static const struct sb_jack { 4058c2ecf20Sopenharmony_ci int unitid; 4068c2ecf20Sopenharmony_ci const char *name; 4078c2ecf20Sopenharmony_ci } jacks_audigy2nx[] = { 4088c2ecf20Sopenharmony_ci {4, "dig in "}, 4098c2ecf20Sopenharmony_ci {7, "line in"}, 4108c2ecf20Sopenharmony_ci {19, "spk out"}, 4118c2ecf20Sopenharmony_ci {20, "hph out"}, 4128c2ecf20Sopenharmony_ci {-1, NULL} 4138c2ecf20Sopenharmony_ci }, jacks_live24ext[] = { 4148c2ecf20Sopenharmony_ci {4, "line in"}, /* &1=Line, &2=Mic*/ 4158c2ecf20Sopenharmony_ci {3, "hph out"}, /* headphones */ 4168c2ecf20Sopenharmony_ci {0, "RC "}, /* last command, 6 bytes see rc_config above */ 4178c2ecf20Sopenharmony_ci {-1, NULL} 4188c2ecf20Sopenharmony_ci }; 4198c2ecf20Sopenharmony_ci const struct sb_jack *jacks; 4208c2ecf20Sopenharmony_ci struct usb_mixer_interface *mixer = entry->private_data; 4218c2ecf20Sopenharmony_ci int i, err; 4228c2ecf20Sopenharmony_ci u8 buf[3]; 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname); 4258c2ecf20Sopenharmony_ci if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020)) 4268c2ecf20Sopenharmony_ci jacks = jacks_audigy2nx; 4278c2ecf20Sopenharmony_ci else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || 4288c2ecf20Sopenharmony_ci mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) 4298c2ecf20Sopenharmony_ci jacks = jacks_live24ext; 4308c2ecf20Sopenharmony_ci else 4318c2ecf20Sopenharmony_ci return; 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ci for (i = 0; jacks[i].name; ++i) { 4348c2ecf20Sopenharmony_ci snd_iprintf(buffer, "%s: ", jacks[i].name); 4358c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(mixer->chip); 4368c2ecf20Sopenharmony_ci if (err < 0) 4378c2ecf20Sopenharmony_ci return; 4388c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(mixer->chip->dev, 4398c2ecf20Sopenharmony_ci usb_rcvctrlpipe(mixer->chip->dev, 0), 4408c2ecf20Sopenharmony_ci UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS | 4418c2ecf20Sopenharmony_ci USB_RECIP_INTERFACE, 0, 4428c2ecf20Sopenharmony_ci jacks[i].unitid << 8, buf, 3); 4438c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(mixer->chip); 4448c2ecf20Sopenharmony_ci if (err == 3 && (buf[0] == 3 || buf[0] == 6)) 4458c2ecf20Sopenharmony_ci snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]); 4468c2ecf20Sopenharmony_ci else 4478c2ecf20Sopenharmony_ci snd_iprintf(buffer, "?\n"); 4488c2ecf20Sopenharmony_ci } 4498c2ecf20Sopenharmony_ci} 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci/* EMU0204 */ 4528c2ecf20Sopenharmony_cistatic int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol, 4538c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 4548c2ecf20Sopenharmony_ci{ 4558c2ecf20Sopenharmony_ci static const char * const texts[2] = {"1/2", "3/4"}; 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); 4588c2ecf20Sopenharmony_ci} 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_cistatic int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol, 4618c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 4628c2ecf20Sopenharmony_ci{ 4638c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = kcontrol->private_value; 4648c2ecf20Sopenharmony_ci return 0; 4658c2ecf20Sopenharmony_ci} 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_cistatic int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer, 4688c2ecf20Sopenharmony_ci int value) 4698c2ecf20Sopenharmony_ci{ 4708c2ecf20Sopenharmony_ci struct snd_usb_audio *chip = mixer->chip; 4718c2ecf20Sopenharmony_ci int err; 4728c2ecf20Sopenharmony_ci unsigned char buf[2]; 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(chip); 4758c2ecf20Sopenharmony_ci if (err < 0) 4768c2ecf20Sopenharmony_ci return err; 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci buf[0] = 0x01; 4798c2ecf20Sopenharmony_ci buf[1] = value ? 0x02 : 0x01; 4808c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 4818c2ecf20Sopenharmony_ci usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR, 4828c2ecf20Sopenharmony_ci USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, 4838c2ecf20Sopenharmony_ci 0x0400, 0x0e00, buf, 2); 4848c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(chip); 4858c2ecf20Sopenharmony_ci return err; 4868c2ecf20Sopenharmony_ci} 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_cistatic int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol, 4898c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 4908c2ecf20Sopenharmony_ci{ 4918c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); 4928c2ecf20Sopenharmony_ci struct usb_mixer_interface *mixer = list->mixer; 4938c2ecf20Sopenharmony_ci unsigned int value = ucontrol->value.enumerated.item[0]; 4948c2ecf20Sopenharmony_ci int err; 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci if (value > 1) 4978c2ecf20Sopenharmony_ci return -EINVAL; 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci if (value == kcontrol->private_value) 5008c2ecf20Sopenharmony_ci return 0; 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci kcontrol->private_value = value; 5038c2ecf20Sopenharmony_ci err = snd_emu0204_ch_switch_update(mixer, value); 5048c2ecf20Sopenharmony_ci return err < 0 ? err : 1; 5058c2ecf20Sopenharmony_ci} 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_cistatic int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list) 5088c2ecf20Sopenharmony_ci{ 5098c2ecf20Sopenharmony_ci return snd_emu0204_ch_switch_update(list->mixer, 5108c2ecf20Sopenharmony_ci list->kctl->private_value); 5118c2ecf20Sopenharmony_ci} 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_emu0204_control = { 5148c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 5158c2ecf20Sopenharmony_ci .name = "Front Jack Channels", 5168c2ecf20Sopenharmony_ci .info = snd_emu0204_ch_switch_info, 5178c2ecf20Sopenharmony_ci .get = snd_emu0204_ch_switch_get, 5188c2ecf20Sopenharmony_ci .put = snd_emu0204_ch_switch_put, 5198c2ecf20Sopenharmony_ci .private_value = 0, 5208c2ecf20Sopenharmony_ci}; 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_cistatic int snd_emu0204_controls_create(struct usb_mixer_interface *mixer) 5238c2ecf20Sopenharmony_ci{ 5248c2ecf20Sopenharmony_ci return add_single_ctl_with_resume(mixer, 0, 5258c2ecf20Sopenharmony_ci snd_emu0204_ch_switch_resume, 5268c2ecf20Sopenharmony_ci &snd_emu0204_control, NULL); 5278c2ecf20Sopenharmony_ci} 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci/* ASUS Xonar U1 / U3 controls */ 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_cistatic int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol, 5328c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 5338c2ecf20Sopenharmony_ci{ 5348c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02); 5358c2ecf20Sopenharmony_ci return 0; 5368c2ecf20Sopenharmony_ci} 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_cistatic int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer, 5398c2ecf20Sopenharmony_ci unsigned char status) 5408c2ecf20Sopenharmony_ci{ 5418c2ecf20Sopenharmony_ci struct snd_usb_audio *chip = mixer->chip; 5428c2ecf20Sopenharmony_ci int err; 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(chip); 5458c2ecf20Sopenharmony_ci if (err < 0) 5468c2ecf20Sopenharmony_ci return err; 5478c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 5488c2ecf20Sopenharmony_ci usb_sndctrlpipe(chip->dev, 0), 0x08, 5498c2ecf20Sopenharmony_ci USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 5508c2ecf20Sopenharmony_ci 50, 0, &status, 1); 5518c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(chip); 5528c2ecf20Sopenharmony_ci return err; 5538c2ecf20Sopenharmony_ci} 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_cistatic int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol, 5568c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 5578c2ecf20Sopenharmony_ci{ 5588c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); 5598c2ecf20Sopenharmony_ci u8 old_status, new_status; 5608c2ecf20Sopenharmony_ci int err; 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci old_status = kcontrol->private_value; 5638c2ecf20Sopenharmony_ci if (ucontrol->value.integer.value[0]) 5648c2ecf20Sopenharmony_ci new_status = old_status | 0x02; 5658c2ecf20Sopenharmony_ci else 5668c2ecf20Sopenharmony_ci new_status = old_status & ~0x02; 5678c2ecf20Sopenharmony_ci if (new_status == old_status) 5688c2ecf20Sopenharmony_ci return 0; 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci kcontrol->private_value = new_status; 5718c2ecf20Sopenharmony_ci err = snd_xonar_u1_switch_update(list->mixer, new_status); 5728c2ecf20Sopenharmony_ci return err < 0 ? err : 1; 5738c2ecf20Sopenharmony_ci} 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_cistatic int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list) 5768c2ecf20Sopenharmony_ci{ 5778c2ecf20Sopenharmony_ci return snd_xonar_u1_switch_update(list->mixer, 5788c2ecf20Sopenharmony_ci list->kctl->private_value); 5798c2ecf20Sopenharmony_ci} 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_xonar_u1_output_switch = { 5828c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 5838c2ecf20Sopenharmony_ci .name = "Digital Playback Switch", 5848c2ecf20Sopenharmony_ci .info = snd_ctl_boolean_mono_info, 5858c2ecf20Sopenharmony_ci .get = snd_xonar_u1_switch_get, 5868c2ecf20Sopenharmony_ci .put = snd_xonar_u1_switch_put, 5878c2ecf20Sopenharmony_ci .private_value = 0x05, 5888c2ecf20Sopenharmony_ci}; 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_cistatic int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer) 5918c2ecf20Sopenharmony_ci{ 5928c2ecf20Sopenharmony_ci return add_single_ctl_with_resume(mixer, 0, 5938c2ecf20Sopenharmony_ci snd_xonar_u1_switch_resume, 5948c2ecf20Sopenharmony_ci &snd_xonar_u1_output_switch, NULL); 5958c2ecf20Sopenharmony_ci} 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_ci/* Digidesign Mbox 1 clock source switch (internal/spdif) */ 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_cistatic int snd_mbox1_switch_get(struct snd_kcontrol *kctl, 6008c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 6018c2ecf20Sopenharmony_ci{ 6028c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = kctl->private_value; 6038c2ecf20Sopenharmony_ci return 0; 6048c2ecf20Sopenharmony_ci} 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_cistatic int snd_mbox1_switch_update(struct usb_mixer_interface *mixer, int val) 6078c2ecf20Sopenharmony_ci{ 6088c2ecf20Sopenharmony_ci struct snd_usb_audio *chip = mixer->chip; 6098c2ecf20Sopenharmony_ci int err; 6108c2ecf20Sopenharmony_ci unsigned char buff[3]; 6118c2ecf20Sopenharmony_ci 6128c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(chip); 6138c2ecf20Sopenharmony_ci if (err < 0) 6148c2ecf20Sopenharmony_ci return err; 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci /* Prepare for magic command to toggle clock source */ 6178c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 6188c2ecf20Sopenharmony_ci usb_rcvctrlpipe(chip->dev, 0), 0x81, 6198c2ecf20Sopenharmony_ci USB_DIR_IN | 6208c2ecf20Sopenharmony_ci USB_TYPE_CLASS | 6218c2ecf20Sopenharmony_ci USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1); 6228c2ecf20Sopenharmony_ci if (err < 0) 6238c2ecf20Sopenharmony_ci goto err; 6248c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 6258c2ecf20Sopenharmony_ci usb_rcvctrlpipe(chip->dev, 0), 0x81, 6268c2ecf20Sopenharmony_ci USB_DIR_IN | 6278c2ecf20Sopenharmony_ci USB_TYPE_CLASS | 6288c2ecf20Sopenharmony_ci USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3); 6298c2ecf20Sopenharmony_ci if (err < 0) 6308c2ecf20Sopenharmony_ci goto err; 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci /* 2 possibilities: Internal -> send sample rate 6338c2ecf20Sopenharmony_ci * S/PDIF sync -> send zeroes 6348c2ecf20Sopenharmony_ci * NB: Sample rate locked to 48kHz on purpose to 6358c2ecf20Sopenharmony_ci * prevent user from resetting the sample rate 6368c2ecf20Sopenharmony_ci * while S/PDIF sync is enabled and confusing 6378c2ecf20Sopenharmony_ci * this configuration. 6388c2ecf20Sopenharmony_ci */ 6398c2ecf20Sopenharmony_ci if (val == 0) { 6408c2ecf20Sopenharmony_ci buff[0] = 0x80; 6418c2ecf20Sopenharmony_ci buff[1] = 0xbb; 6428c2ecf20Sopenharmony_ci buff[2] = 0x00; 6438c2ecf20Sopenharmony_ci } else { 6448c2ecf20Sopenharmony_ci buff[0] = buff[1] = buff[2] = 0x00; 6458c2ecf20Sopenharmony_ci } 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci /* Send the magic command to toggle the clock source */ 6488c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 6498c2ecf20Sopenharmony_ci usb_sndctrlpipe(chip->dev, 0), 0x1, 6508c2ecf20Sopenharmony_ci USB_TYPE_CLASS | 6518c2ecf20Sopenharmony_ci USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3); 6528c2ecf20Sopenharmony_ci if (err < 0) 6538c2ecf20Sopenharmony_ci goto err; 6548c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 6558c2ecf20Sopenharmony_ci usb_rcvctrlpipe(chip->dev, 0), 0x81, 6568c2ecf20Sopenharmony_ci USB_DIR_IN | 6578c2ecf20Sopenharmony_ci USB_TYPE_CLASS | 6588c2ecf20Sopenharmony_ci USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3); 6598c2ecf20Sopenharmony_ci if (err < 0) 6608c2ecf20Sopenharmony_ci goto err; 6618c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 6628c2ecf20Sopenharmony_ci usb_rcvctrlpipe(chip->dev, 0), 0x81, 6638c2ecf20Sopenharmony_ci USB_DIR_IN | 6648c2ecf20Sopenharmony_ci USB_TYPE_CLASS | 6658c2ecf20Sopenharmony_ci USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3); 6668c2ecf20Sopenharmony_ci if (err < 0) 6678c2ecf20Sopenharmony_ci goto err; 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_cierr: 6708c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(chip); 6718c2ecf20Sopenharmony_ci return err; 6728c2ecf20Sopenharmony_ci} 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_cistatic int snd_mbox1_switch_put(struct snd_kcontrol *kctl, 6758c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 6768c2ecf20Sopenharmony_ci{ 6778c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); 6788c2ecf20Sopenharmony_ci struct usb_mixer_interface *mixer = list->mixer; 6798c2ecf20Sopenharmony_ci int err; 6808c2ecf20Sopenharmony_ci bool cur_val, new_val; 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci cur_val = kctl->private_value; 6838c2ecf20Sopenharmony_ci new_val = ucontrol->value.enumerated.item[0]; 6848c2ecf20Sopenharmony_ci if (cur_val == new_val) 6858c2ecf20Sopenharmony_ci return 0; 6868c2ecf20Sopenharmony_ci 6878c2ecf20Sopenharmony_ci kctl->private_value = new_val; 6888c2ecf20Sopenharmony_ci err = snd_mbox1_switch_update(mixer, new_val); 6898c2ecf20Sopenharmony_ci return err < 0 ? err : 1; 6908c2ecf20Sopenharmony_ci} 6918c2ecf20Sopenharmony_ci 6928c2ecf20Sopenharmony_cistatic int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol, 6938c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 6948c2ecf20Sopenharmony_ci{ 6958c2ecf20Sopenharmony_ci static const char *const texts[2] = { 6968c2ecf20Sopenharmony_ci "Internal", 6978c2ecf20Sopenharmony_ci "S/PDIF" 6988c2ecf20Sopenharmony_ci }; 6998c2ecf20Sopenharmony_ci 7008c2ecf20Sopenharmony_ci return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); 7018c2ecf20Sopenharmony_ci} 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_cistatic int snd_mbox1_switch_resume(struct usb_mixer_elem_list *list) 7048c2ecf20Sopenharmony_ci{ 7058c2ecf20Sopenharmony_ci return snd_mbox1_switch_update(list->mixer, list->kctl->private_value); 7068c2ecf20Sopenharmony_ci} 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_mbox1_switch = { 7098c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 7108c2ecf20Sopenharmony_ci .name = "Clock Source", 7118c2ecf20Sopenharmony_ci .index = 0, 7128c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 7138c2ecf20Sopenharmony_ci .info = snd_mbox1_switch_info, 7148c2ecf20Sopenharmony_ci .get = snd_mbox1_switch_get, 7158c2ecf20Sopenharmony_ci .put = snd_mbox1_switch_put, 7168c2ecf20Sopenharmony_ci .private_value = 0 7178c2ecf20Sopenharmony_ci}; 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_cistatic int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer) 7208c2ecf20Sopenharmony_ci{ 7218c2ecf20Sopenharmony_ci return add_single_ctl_with_resume(mixer, 0, 7228c2ecf20Sopenharmony_ci snd_mbox1_switch_resume, 7238c2ecf20Sopenharmony_ci &snd_mbox1_switch, NULL); 7248c2ecf20Sopenharmony_ci} 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci/* Native Instruments device quirks */ 7278c2ecf20Sopenharmony_ci 7288c2ecf20Sopenharmony_ci#define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex)) 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_cistatic int snd_ni_control_init_val(struct usb_mixer_interface *mixer, 7318c2ecf20Sopenharmony_ci struct snd_kcontrol *kctl) 7328c2ecf20Sopenharmony_ci{ 7338c2ecf20Sopenharmony_ci struct usb_device *dev = mixer->chip->dev; 7348c2ecf20Sopenharmony_ci unsigned int pval = kctl->private_value; 7358c2ecf20Sopenharmony_ci u8 value; 7368c2ecf20Sopenharmony_ci int err; 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 7398c2ecf20Sopenharmony_ci (pval >> 16) & 0xff, 7408c2ecf20Sopenharmony_ci USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 7418c2ecf20Sopenharmony_ci 0, pval & 0xffff, &value, 1); 7428c2ecf20Sopenharmony_ci if (err < 0) { 7438c2ecf20Sopenharmony_ci dev_err(&dev->dev, 7448c2ecf20Sopenharmony_ci "unable to issue vendor read request (ret = %d)", err); 7458c2ecf20Sopenharmony_ci return err; 7468c2ecf20Sopenharmony_ci } 7478c2ecf20Sopenharmony_ci 7488c2ecf20Sopenharmony_ci kctl->private_value |= ((unsigned int)value << 24); 7498c2ecf20Sopenharmony_ci return 0; 7508c2ecf20Sopenharmony_ci} 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_cistatic int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol, 7538c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 7548c2ecf20Sopenharmony_ci{ 7558c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = kcontrol->private_value >> 24; 7568c2ecf20Sopenharmony_ci return 0; 7578c2ecf20Sopenharmony_ci} 7588c2ecf20Sopenharmony_ci 7598c2ecf20Sopenharmony_cistatic int snd_ni_update_cur_val(struct usb_mixer_elem_list *list) 7608c2ecf20Sopenharmony_ci{ 7618c2ecf20Sopenharmony_ci struct snd_usb_audio *chip = list->mixer->chip; 7628c2ecf20Sopenharmony_ci unsigned int pval = list->kctl->private_value; 7638c2ecf20Sopenharmony_ci int err; 7648c2ecf20Sopenharmony_ci 7658c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(chip); 7668c2ecf20Sopenharmony_ci if (err < 0) 7678c2ecf20Sopenharmony_ci return err; 7688c2ecf20Sopenharmony_ci err = usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), 7698c2ecf20Sopenharmony_ci (pval >> 16) & 0xff, 7708c2ecf20Sopenharmony_ci USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, 7718c2ecf20Sopenharmony_ci pval >> 24, pval & 0xffff, NULL, 0, 1000); 7728c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(chip); 7738c2ecf20Sopenharmony_ci return err; 7748c2ecf20Sopenharmony_ci} 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_cistatic int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol, 7778c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 7788c2ecf20Sopenharmony_ci{ 7798c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); 7808c2ecf20Sopenharmony_ci u8 oldval = (kcontrol->private_value >> 24) & 0xff; 7818c2ecf20Sopenharmony_ci u8 newval = ucontrol->value.integer.value[0]; 7828c2ecf20Sopenharmony_ci int err; 7838c2ecf20Sopenharmony_ci 7848c2ecf20Sopenharmony_ci if (oldval == newval) 7858c2ecf20Sopenharmony_ci return 0; 7868c2ecf20Sopenharmony_ci 7878c2ecf20Sopenharmony_ci kcontrol->private_value &= ~(0xff << 24); 7888c2ecf20Sopenharmony_ci kcontrol->private_value |= (unsigned int)newval << 24; 7898c2ecf20Sopenharmony_ci err = snd_ni_update_cur_val(list); 7908c2ecf20Sopenharmony_ci return err < 0 ? err : 1; 7918c2ecf20Sopenharmony_ci} 7928c2ecf20Sopenharmony_ci 7938c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = { 7948c2ecf20Sopenharmony_ci { 7958c2ecf20Sopenharmony_ci .name = "Direct Thru Channel A", 7968c2ecf20Sopenharmony_ci .private_value = _MAKE_NI_CONTROL(0x01, 0x03), 7978c2ecf20Sopenharmony_ci }, 7988c2ecf20Sopenharmony_ci { 7998c2ecf20Sopenharmony_ci .name = "Direct Thru Channel B", 8008c2ecf20Sopenharmony_ci .private_value = _MAKE_NI_CONTROL(0x01, 0x05), 8018c2ecf20Sopenharmony_ci }, 8028c2ecf20Sopenharmony_ci { 8038c2ecf20Sopenharmony_ci .name = "Phono Input Channel A", 8048c2ecf20Sopenharmony_ci .private_value = _MAKE_NI_CONTROL(0x02, 0x03), 8058c2ecf20Sopenharmony_ci }, 8068c2ecf20Sopenharmony_ci { 8078c2ecf20Sopenharmony_ci .name = "Phono Input Channel B", 8088c2ecf20Sopenharmony_ci .private_value = _MAKE_NI_CONTROL(0x02, 0x05), 8098c2ecf20Sopenharmony_ci }, 8108c2ecf20Sopenharmony_ci}; 8118c2ecf20Sopenharmony_ci 8128c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = { 8138c2ecf20Sopenharmony_ci { 8148c2ecf20Sopenharmony_ci .name = "Direct Thru Channel A", 8158c2ecf20Sopenharmony_ci .private_value = _MAKE_NI_CONTROL(0x01, 0x03), 8168c2ecf20Sopenharmony_ci }, 8178c2ecf20Sopenharmony_ci { 8188c2ecf20Sopenharmony_ci .name = "Direct Thru Channel B", 8198c2ecf20Sopenharmony_ci .private_value = _MAKE_NI_CONTROL(0x01, 0x05), 8208c2ecf20Sopenharmony_ci }, 8218c2ecf20Sopenharmony_ci { 8228c2ecf20Sopenharmony_ci .name = "Direct Thru Channel C", 8238c2ecf20Sopenharmony_ci .private_value = _MAKE_NI_CONTROL(0x01, 0x07), 8248c2ecf20Sopenharmony_ci }, 8258c2ecf20Sopenharmony_ci { 8268c2ecf20Sopenharmony_ci .name = "Direct Thru Channel D", 8278c2ecf20Sopenharmony_ci .private_value = _MAKE_NI_CONTROL(0x01, 0x09), 8288c2ecf20Sopenharmony_ci }, 8298c2ecf20Sopenharmony_ci { 8308c2ecf20Sopenharmony_ci .name = "Phono Input Channel A", 8318c2ecf20Sopenharmony_ci .private_value = _MAKE_NI_CONTROL(0x02, 0x03), 8328c2ecf20Sopenharmony_ci }, 8338c2ecf20Sopenharmony_ci { 8348c2ecf20Sopenharmony_ci .name = "Phono Input Channel B", 8358c2ecf20Sopenharmony_ci .private_value = _MAKE_NI_CONTROL(0x02, 0x05), 8368c2ecf20Sopenharmony_ci }, 8378c2ecf20Sopenharmony_ci { 8388c2ecf20Sopenharmony_ci .name = "Phono Input Channel C", 8398c2ecf20Sopenharmony_ci .private_value = _MAKE_NI_CONTROL(0x02, 0x07), 8408c2ecf20Sopenharmony_ci }, 8418c2ecf20Sopenharmony_ci { 8428c2ecf20Sopenharmony_ci .name = "Phono Input Channel D", 8438c2ecf20Sopenharmony_ci .private_value = _MAKE_NI_CONTROL(0x02, 0x09), 8448c2ecf20Sopenharmony_ci }, 8458c2ecf20Sopenharmony_ci}; 8468c2ecf20Sopenharmony_ci 8478c2ecf20Sopenharmony_cistatic int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer, 8488c2ecf20Sopenharmony_ci const struct snd_kcontrol_new *kc, 8498c2ecf20Sopenharmony_ci unsigned int count) 8508c2ecf20Sopenharmony_ci{ 8518c2ecf20Sopenharmony_ci int i, err = 0; 8528c2ecf20Sopenharmony_ci struct snd_kcontrol_new template = { 8538c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 8548c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 8558c2ecf20Sopenharmony_ci .get = snd_nativeinstruments_control_get, 8568c2ecf20Sopenharmony_ci .put = snd_nativeinstruments_control_put, 8578c2ecf20Sopenharmony_ci .info = snd_ctl_boolean_mono_info, 8588c2ecf20Sopenharmony_ci }; 8598c2ecf20Sopenharmony_ci 8608c2ecf20Sopenharmony_ci for (i = 0; i < count; i++) { 8618c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list; 8628c2ecf20Sopenharmony_ci 8638c2ecf20Sopenharmony_ci template.name = kc[i].name; 8648c2ecf20Sopenharmony_ci template.private_value = kc[i].private_value; 8658c2ecf20Sopenharmony_ci 8668c2ecf20Sopenharmony_ci err = add_single_ctl_with_resume(mixer, 0, 8678c2ecf20Sopenharmony_ci snd_ni_update_cur_val, 8688c2ecf20Sopenharmony_ci &template, &list); 8698c2ecf20Sopenharmony_ci if (err < 0) 8708c2ecf20Sopenharmony_ci break; 8718c2ecf20Sopenharmony_ci snd_ni_control_init_val(mixer, list->kctl); 8728c2ecf20Sopenharmony_ci } 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ci return err; 8758c2ecf20Sopenharmony_ci} 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci/* M-Audio FastTrack Ultra quirks */ 8788c2ecf20Sopenharmony_ci/* FTU Effect switch (also used by C400/C600) */ 8798c2ecf20Sopenharmony_cistatic int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol, 8808c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 8818c2ecf20Sopenharmony_ci{ 8828c2ecf20Sopenharmony_ci static const char *const texts[8] = { 8838c2ecf20Sopenharmony_ci "Room 1", "Room 2", "Room 3", "Hall 1", 8848c2ecf20Sopenharmony_ci "Hall 2", "Plate", "Delay", "Echo" 8858c2ecf20Sopenharmony_ci }; 8868c2ecf20Sopenharmony_ci 8878c2ecf20Sopenharmony_ci return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); 8888c2ecf20Sopenharmony_ci} 8898c2ecf20Sopenharmony_ci 8908c2ecf20Sopenharmony_cistatic int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer, 8918c2ecf20Sopenharmony_ci struct snd_kcontrol *kctl) 8928c2ecf20Sopenharmony_ci{ 8938c2ecf20Sopenharmony_ci struct usb_device *dev = mixer->chip->dev; 8948c2ecf20Sopenharmony_ci unsigned int pval = kctl->private_value; 8958c2ecf20Sopenharmony_ci int err; 8968c2ecf20Sopenharmony_ci unsigned char value[2]; 8978c2ecf20Sopenharmony_ci 8988c2ecf20Sopenharmony_ci value[0] = 0x00; 8998c2ecf20Sopenharmony_ci value[1] = 0x00; 9008c2ecf20Sopenharmony_ci 9018c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR, 9028c2ecf20Sopenharmony_ci USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 9038c2ecf20Sopenharmony_ci pval & 0xff00, 9048c2ecf20Sopenharmony_ci snd_usb_ctrl_intf(mixer->chip) | ((pval & 0xff) << 8), 9058c2ecf20Sopenharmony_ci value, 2); 9068c2ecf20Sopenharmony_ci if (err < 0) 9078c2ecf20Sopenharmony_ci return err; 9088c2ecf20Sopenharmony_ci 9098c2ecf20Sopenharmony_ci kctl->private_value |= (unsigned int)value[0] << 24; 9108c2ecf20Sopenharmony_ci return 0; 9118c2ecf20Sopenharmony_ci} 9128c2ecf20Sopenharmony_ci 9138c2ecf20Sopenharmony_cistatic int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl, 9148c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 9158c2ecf20Sopenharmony_ci{ 9168c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = kctl->private_value >> 24; 9178c2ecf20Sopenharmony_ci return 0; 9188c2ecf20Sopenharmony_ci} 9198c2ecf20Sopenharmony_ci 9208c2ecf20Sopenharmony_cistatic int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list) 9218c2ecf20Sopenharmony_ci{ 9228c2ecf20Sopenharmony_ci struct snd_usb_audio *chip = list->mixer->chip; 9238c2ecf20Sopenharmony_ci unsigned int pval = list->kctl->private_value; 9248c2ecf20Sopenharmony_ci unsigned char value[2]; 9258c2ecf20Sopenharmony_ci int err; 9268c2ecf20Sopenharmony_ci 9278c2ecf20Sopenharmony_ci value[0] = pval >> 24; 9288c2ecf20Sopenharmony_ci value[1] = 0; 9298c2ecf20Sopenharmony_ci 9308c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(chip); 9318c2ecf20Sopenharmony_ci if (err < 0) 9328c2ecf20Sopenharmony_ci return err; 9338c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 9348c2ecf20Sopenharmony_ci usb_sndctrlpipe(chip->dev, 0), 9358c2ecf20Sopenharmony_ci UAC_SET_CUR, 9368c2ecf20Sopenharmony_ci USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, 9378c2ecf20Sopenharmony_ci pval & 0xff00, 9388c2ecf20Sopenharmony_ci snd_usb_ctrl_intf(chip) | ((pval & 0xff) << 8), 9398c2ecf20Sopenharmony_ci value, 2); 9408c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(chip); 9418c2ecf20Sopenharmony_ci return err; 9428c2ecf20Sopenharmony_ci} 9438c2ecf20Sopenharmony_ci 9448c2ecf20Sopenharmony_cistatic int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl, 9458c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 9468c2ecf20Sopenharmony_ci{ 9478c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); 9488c2ecf20Sopenharmony_ci unsigned int pval = list->kctl->private_value; 9498c2ecf20Sopenharmony_ci int cur_val, err, new_val; 9508c2ecf20Sopenharmony_ci 9518c2ecf20Sopenharmony_ci cur_val = pval >> 24; 9528c2ecf20Sopenharmony_ci new_val = ucontrol->value.enumerated.item[0]; 9538c2ecf20Sopenharmony_ci if (cur_val == new_val) 9548c2ecf20Sopenharmony_ci return 0; 9558c2ecf20Sopenharmony_ci 9568c2ecf20Sopenharmony_ci kctl->private_value &= ~(0xff << 24); 9578c2ecf20Sopenharmony_ci kctl->private_value |= new_val << 24; 9588c2ecf20Sopenharmony_ci err = snd_ftu_eff_switch_update(list); 9598c2ecf20Sopenharmony_ci return err < 0 ? err : 1; 9608c2ecf20Sopenharmony_ci} 9618c2ecf20Sopenharmony_ci 9628c2ecf20Sopenharmony_cistatic int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer, 9638c2ecf20Sopenharmony_ci int validx, int bUnitID) 9648c2ecf20Sopenharmony_ci{ 9658c2ecf20Sopenharmony_ci static struct snd_kcontrol_new template = { 9668c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 9678c2ecf20Sopenharmony_ci .name = "Effect Program Switch", 9688c2ecf20Sopenharmony_ci .index = 0, 9698c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 9708c2ecf20Sopenharmony_ci .info = snd_ftu_eff_switch_info, 9718c2ecf20Sopenharmony_ci .get = snd_ftu_eff_switch_get, 9728c2ecf20Sopenharmony_ci .put = snd_ftu_eff_switch_put 9738c2ecf20Sopenharmony_ci }; 9748c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list; 9758c2ecf20Sopenharmony_ci int err; 9768c2ecf20Sopenharmony_ci 9778c2ecf20Sopenharmony_ci err = add_single_ctl_with_resume(mixer, bUnitID, 9788c2ecf20Sopenharmony_ci snd_ftu_eff_switch_update, 9798c2ecf20Sopenharmony_ci &template, &list); 9808c2ecf20Sopenharmony_ci if (err < 0) 9818c2ecf20Sopenharmony_ci return err; 9828c2ecf20Sopenharmony_ci list->kctl->private_value = (validx << 8) | bUnitID; 9838c2ecf20Sopenharmony_ci snd_ftu_eff_switch_init(mixer, list->kctl); 9848c2ecf20Sopenharmony_ci return 0; 9858c2ecf20Sopenharmony_ci} 9868c2ecf20Sopenharmony_ci 9878c2ecf20Sopenharmony_ci/* Create volume controls for FTU devices*/ 9888c2ecf20Sopenharmony_cistatic int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer) 9898c2ecf20Sopenharmony_ci{ 9908c2ecf20Sopenharmony_ci char name[64]; 9918c2ecf20Sopenharmony_ci unsigned int control, cmask; 9928c2ecf20Sopenharmony_ci int in, out, err; 9938c2ecf20Sopenharmony_ci 9948c2ecf20Sopenharmony_ci const unsigned int id = 5; 9958c2ecf20Sopenharmony_ci const int val_type = USB_MIXER_S16; 9968c2ecf20Sopenharmony_ci 9978c2ecf20Sopenharmony_ci for (out = 0; out < 8; out++) { 9988c2ecf20Sopenharmony_ci control = out + 1; 9998c2ecf20Sopenharmony_ci for (in = 0; in < 8; in++) { 10008c2ecf20Sopenharmony_ci cmask = 1 << in; 10018c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), 10028c2ecf20Sopenharmony_ci "AIn%d - Out%d Capture Volume", 10038c2ecf20Sopenharmony_ci in + 1, out + 1); 10048c2ecf20Sopenharmony_ci err = snd_create_std_mono_ctl(mixer, id, control, 10058c2ecf20Sopenharmony_ci cmask, val_type, name, 10068c2ecf20Sopenharmony_ci &snd_usb_mixer_vol_tlv); 10078c2ecf20Sopenharmony_ci if (err < 0) 10088c2ecf20Sopenharmony_ci return err; 10098c2ecf20Sopenharmony_ci } 10108c2ecf20Sopenharmony_ci for (in = 8; in < 16; in++) { 10118c2ecf20Sopenharmony_ci cmask = 1 << in; 10128c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), 10138c2ecf20Sopenharmony_ci "DIn%d - Out%d Playback Volume", 10148c2ecf20Sopenharmony_ci in - 7, out + 1); 10158c2ecf20Sopenharmony_ci err = snd_create_std_mono_ctl(mixer, id, control, 10168c2ecf20Sopenharmony_ci cmask, val_type, name, 10178c2ecf20Sopenharmony_ci &snd_usb_mixer_vol_tlv); 10188c2ecf20Sopenharmony_ci if (err < 0) 10198c2ecf20Sopenharmony_ci return err; 10208c2ecf20Sopenharmony_ci } 10218c2ecf20Sopenharmony_ci } 10228c2ecf20Sopenharmony_ci 10238c2ecf20Sopenharmony_ci return 0; 10248c2ecf20Sopenharmony_ci} 10258c2ecf20Sopenharmony_ci 10268c2ecf20Sopenharmony_ci/* This control needs a volume quirk, see mixer.c */ 10278c2ecf20Sopenharmony_cistatic int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer) 10288c2ecf20Sopenharmony_ci{ 10298c2ecf20Sopenharmony_ci static const char name[] = "Effect Volume"; 10308c2ecf20Sopenharmony_ci const unsigned int id = 6; 10318c2ecf20Sopenharmony_ci const int val_type = USB_MIXER_U8; 10328c2ecf20Sopenharmony_ci const unsigned int control = 2; 10338c2ecf20Sopenharmony_ci const unsigned int cmask = 0; 10348c2ecf20Sopenharmony_ci 10358c2ecf20Sopenharmony_ci return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, 10368c2ecf20Sopenharmony_ci name, snd_usb_mixer_vol_tlv); 10378c2ecf20Sopenharmony_ci} 10388c2ecf20Sopenharmony_ci 10398c2ecf20Sopenharmony_ci/* This control needs a volume quirk, see mixer.c */ 10408c2ecf20Sopenharmony_cistatic int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer) 10418c2ecf20Sopenharmony_ci{ 10428c2ecf20Sopenharmony_ci static const char name[] = "Effect Duration"; 10438c2ecf20Sopenharmony_ci const unsigned int id = 6; 10448c2ecf20Sopenharmony_ci const int val_type = USB_MIXER_S16; 10458c2ecf20Sopenharmony_ci const unsigned int control = 3; 10468c2ecf20Sopenharmony_ci const unsigned int cmask = 0; 10478c2ecf20Sopenharmony_ci 10488c2ecf20Sopenharmony_ci return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, 10498c2ecf20Sopenharmony_ci name, snd_usb_mixer_vol_tlv); 10508c2ecf20Sopenharmony_ci} 10518c2ecf20Sopenharmony_ci 10528c2ecf20Sopenharmony_ci/* This control needs a volume quirk, see mixer.c */ 10538c2ecf20Sopenharmony_cistatic int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer) 10548c2ecf20Sopenharmony_ci{ 10558c2ecf20Sopenharmony_ci static const char name[] = "Effect Feedback Volume"; 10568c2ecf20Sopenharmony_ci const unsigned int id = 6; 10578c2ecf20Sopenharmony_ci const int val_type = USB_MIXER_U8; 10588c2ecf20Sopenharmony_ci const unsigned int control = 4; 10598c2ecf20Sopenharmony_ci const unsigned int cmask = 0; 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, 10628c2ecf20Sopenharmony_ci name, NULL); 10638c2ecf20Sopenharmony_ci} 10648c2ecf20Sopenharmony_ci 10658c2ecf20Sopenharmony_cistatic int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer) 10668c2ecf20Sopenharmony_ci{ 10678c2ecf20Sopenharmony_ci unsigned int cmask; 10688c2ecf20Sopenharmony_ci int err, ch; 10698c2ecf20Sopenharmony_ci char name[48]; 10708c2ecf20Sopenharmony_ci 10718c2ecf20Sopenharmony_ci const unsigned int id = 7; 10728c2ecf20Sopenharmony_ci const int val_type = USB_MIXER_S16; 10738c2ecf20Sopenharmony_ci const unsigned int control = 7; 10748c2ecf20Sopenharmony_ci 10758c2ecf20Sopenharmony_ci for (ch = 0; ch < 4; ++ch) { 10768c2ecf20Sopenharmony_ci cmask = 1 << ch; 10778c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), 10788c2ecf20Sopenharmony_ci "Effect Return %d Volume", ch + 1); 10798c2ecf20Sopenharmony_ci err = snd_create_std_mono_ctl(mixer, id, control, 10808c2ecf20Sopenharmony_ci cmask, val_type, name, 10818c2ecf20Sopenharmony_ci snd_usb_mixer_vol_tlv); 10828c2ecf20Sopenharmony_ci if (err < 0) 10838c2ecf20Sopenharmony_ci return err; 10848c2ecf20Sopenharmony_ci } 10858c2ecf20Sopenharmony_ci 10868c2ecf20Sopenharmony_ci return 0; 10878c2ecf20Sopenharmony_ci} 10888c2ecf20Sopenharmony_ci 10898c2ecf20Sopenharmony_cistatic int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer) 10908c2ecf20Sopenharmony_ci{ 10918c2ecf20Sopenharmony_ci unsigned int cmask; 10928c2ecf20Sopenharmony_ci int err, ch; 10938c2ecf20Sopenharmony_ci char name[48]; 10948c2ecf20Sopenharmony_ci 10958c2ecf20Sopenharmony_ci const unsigned int id = 5; 10968c2ecf20Sopenharmony_ci const int val_type = USB_MIXER_S16; 10978c2ecf20Sopenharmony_ci const unsigned int control = 9; 10988c2ecf20Sopenharmony_ci 10998c2ecf20Sopenharmony_ci for (ch = 0; ch < 8; ++ch) { 11008c2ecf20Sopenharmony_ci cmask = 1 << ch; 11018c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), 11028c2ecf20Sopenharmony_ci "Effect Send AIn%d Volume", ch + 1); 11038c2ecf20Sopenharmony_ci err = snd_create_std_mono_ctl(mixer, id, control, cmask, 11048c2ecf20Sopenharmony_ci val_type, name, 11058c2ecf20Sopenharmony_ci snd_usb_mixer_vol_tlv); 11068c2ecf20Sopenharmony_ci if (err < 0) 11078c2ecf20Sopenharmony_ci return err; 11088c2ecf20Sopenharmony_ci } 11098c2ecf20Sopenharmony_ci for (ch = 8; ch < 16; ++ch) { 11108c2ecf20Sopenharmony_ci cmask = 1 << ch; 11118c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), 11128c2ecf20Sopenharmony_ci "Effect Send DIn%d Volume", ch - 7); 11138c2ecf20Sopenharmony_ci err = snd_create_std_mono_ctl(mixer, id, control, cmask, 11148c2ecf20Sopenharmony_ci val_type, name, 11158c2ecf20Sopenharmony_ci snd_usb_mixer_vol_tlv); 11168c2ecf20Sopenharmony_ci if (err < 0) 11178c2ecf20Sopenharmony_ci return err; 11188c2ecf20Sopenharmony_ci } 11198c2ecf20Sopenharmony_ci return 0; 11208c2ecf20Sopenharmony_ci} 11218c2ecf20Sopenharmony_ci 11228c2ecf20Sopenharmony_cistatic int snd_ftu_create_mixer(struct usb_mixer_interface *mixer) 11238c2ecf20Sopenharmony_ci{ 11248c2ecf20Sopenharmony_ci int err; 11258c2ecf20Sopenharmony_ci 11268c2ecf20Sopenharmony_ci err = snd_ftu_create_volume_ctls(mixer); 11278c2ecf20Sopenharmony_ci if (err < 0) 11288c2ecf20Sopenharmony_ci return err; 11298c2ecf20Sopenharmony_ci 11308c2ecf20Sopenharmony_ci err = snd_ftu_create_effect_switch(mixer, 1, 6); 11318c2ecf20Sopenharmony_ci if (err < 0) 11328c2ecf20Sopenharmony_ci return err; 11338c2ecf20Sopenharmony_ci 11348c2ecf20Sopenharmony_ci err = snd_ftu_create_effect_volume_ctl(mixer); 11358c2ecf20Sopenharmony_ci if (err < 0) 11368c2ecf20Sopenharmony_ci return err; 11378c2ecf20Sopenharmony_ci 11388c2ecf20Sopenharmony_ci err = snd_ftu_create_effect_duration_ctl(mixer); 11398c2ecf20Sopenharmony_ci if (err < 0) 11408c2ecf20Sopenharmony_ci return err; 11418c2ecf20Sopenharmony_ci 11428c2ecf20Sopenharmony_ci err = snd_ftu_create_effect_feedback_ctl(mixer); 11438c2ecf20Sopenharmony_ci if (err < 0) 11448c2ecf20Sopenharmony_ci return err; 11458c2ecf20Sopenharmony_ci 11468c2ecf20Sopenharmony_ci err = snd_ftu_create_effect_return_ctls(mixer); 11478c2ecf20Sopenharmony_ci if (err < 0) 11488c2ecf20Sopenharmony_ci return err; 11498c2ecf20Sopenharmony_ci 11508c2ecf20Sopenharmony_ci err = snd_ftu_create_effect_send_ctls(mixer); 11518c2ecf20Sopenharmony_ci if (err < 0) 11528c2ecf20Sopenharmony_ci return err; 11538c2ecf20Sopenharmony_ci 11548c2ecf20Sopenharmony_ci return 0; 11558c2ecf20Sopenharmony_ci} 11568c2ecf20Sopenharmony_ci 11578c2ecf20Sopenharmony_civoid snd_emuusb_set_samplerate(struct snd_usb_audio *chip, 11588c2ecf20Sopenharmony_ci unsigned char samplerate_id) 11598c2ecf20Sopenharmony_ci{ 11608c2ecf20Sopenharmony_ci struct usb_mixer_interface *mixer; 11618c2ecf20Sopenharmony_ci struct usb_mixer_elem_info *cval; 11628c2ecf20Sopenharmony_ci int unitid = 12; /* SampleRate ExtensionUnit ID */ 11638c2ecf20Sopenharmony_ci 11648c2ecf20Sopenharmony_ci list_for_each_entry(mixer, &chip->mixer_list, list) { 11658c2ecf20Sopenharmony_ci if (mixer->id_elems[unitid]) { 11668c2ecf20Sopenharmony_ci cval = mixer_elem_list_to_info(mixer->id_elems[unitid]); 11678c2ecf20Sopenharmony_ci snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR, 11688c2ecf20Sopenharmony_ci cval->control << 8, 11698c2ecf20Sopenharmony_ci samplerate_id); 11708c2ecf20Sopenharmony_ci snd_usb_mixer_notify_id(mixer, unitid); 11718c2ecf20Sopenharmony_ci break; 11728c2ecf20Sopenharmony_ci } 11738c2ecf20Sopenharmony_ci } 11748c2ecf20Sopenharmony_ci} 11758c2ecf20Sopenharmony_ci 11768c2ecf20Sopenharmony_ci/* M-Audio Fast Track C400/C600 */ 11778c2ecf20Sopenharmony_ci/* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */ 11788c2ecf20Sopenharmony_cistatic int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer) 11798c2ecf20Sopenharmony_ci{ 11808c2ecf20Sopenharmony_ci char name[64]; 11818c2ecf20Sopenharmony_ci unsigned int cmask, offset; 11828c2ecf20Sopenharmony_ci int out, chan, err; 11838c2ecf20Sopenharmony_ci int num_outs = 0; 11848c2ecf20Sopenharmony_ci int num_ins = 0; 11858c2ecf20Sopenharmony_ci 11868c2ecf20Sopenharmony_ci const unsigned int id = 0x40; 11878c2ecf20Sopenharmony_ci const int val_type = USB_MIXER_S16; 11888c2ecf20Sopenharmony_ci const int control = 1; 11898c2ecf20Sopenharmony_ci 11908c2ecf20Sopenharmony_ci switch (mixer->chip->usb_id) { 11918c2ecf20Sopenharmony_ci case USB_ID(0x0763, 0x2030): 11928c2ecf20Sopenharmony_ci num_outs = 6; 11938c2ecf20Sopenharmony_ci num_ins = 4; 11948c2ecf20Sopenharmony_ci break; 11958c2ecf20Sopenharmony_ci case USB_ID(0x0763, 0x2031): 11968c2ecf20Sopenharmony_ci num_outs = 8; 11978c2ecf20Sopenharmony_ci num_ins = 6; 11988c2ecf20Sopenharmony_ci break; 11998c2ecf20Sopenharmony_ci } 12008c2ecf20Sopenharmony_ci 12018c2ecf20Sopenharmony_ci for (chan = 0; chan < num_outs + num_ins; chan++) { 12028c2ecf20Sopenharmony_ci for (out = 0; out < num_outs; out++) { 12038c2ecf20Sopenharmony_ci if (chan < num_outs) { 12048c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), 12058c2ecf20Sopenharmony_ci "PCM%d-Out%d Playback Volume", 12068c2ecf20Sopenharmony_ci chan + 1, out + 1); 12078c2ecf20Sopenharmony_ci } else { 12088c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), 12098c2ecf20Sopenharmony_ci "In%d-Out%d Playback Volume", 12108c2ecf20Sopenharmony_ci chan - num_outs + 1, out + 1); 12118c2ecf20Sopenharmony_ci } 12128c2ecf20Sopenharmony_ci 12138c2ecf20Sopenharmony_ci cmask = (out == 0) ? 0 : 1 << (out - 1); 12148c2ecf20Sopenharmony_ci offset = chan * num_outs; 12158c2ecf20Sopenharmony_ci err = snd_create_std_mono_ctl_offset(mixer, id, control, 12168c2ecf20Sopenharmony_ci cmask, val_type, offset, name, 12178c2ecf20Sopenharmony_ci &snd_usb_mixer_vol_tlv); 12188c2ecf20Sopenharmony_ci if (err < 0) 12198c2ecf20Sopenharmony_ci return err; 12208c2ecf20Sopenharmony_ci } 12218c2ecf20Sopenharmony_ci } 12228c2ecf20Sopenharmony_ci 12238c2ecf20Sopenharmony_ci return 0; 12248c2ecf20Sopenharmony_ci} 12258c2ecf20Sopenharmony_ci 12268c2ecf20Sopenharmony_ci/* This control needs a volume quirk, see mixer.c */ 12278c2ecf20Sopenharmony_cistatic int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer) 12288c2ecf20Sopenharmony_ci{ 12298c2ecf20Sopenharmony_ci static const char name[] = "Effect Volume"; 12308c2ecf20Sopenharmony_ci const unsigned int id = 0x43; 12318c2ecf20Sopenharmony_ci const int val_type = USB_MIXER_U8; 12328c2ecf20Sopenharmony_ci const unsigned int control = 3; 12338c2ecf20Sopenharmony_ci const unsigned int cmask = 0; 12348c2ecf20Sopenharmony_ci 12358c2ecf20Sopenharmony_ci return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, 12368c2ecf20Sopenharmony_ci name, snd_usb_mixer_vol_tlv); 12378c2ecf20Sopenharmony_ci} 12388c2ecf20Sopenharmony_ci 12398c2ecf20Sopenharmony_ci/* This control needs a volume quirk, see mixer.c */ 12408c2ecf20Sopenharmony_cistatic int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer) 12418c2ecf20Sopenharmony_ci{ 12428c2ecf20Sopenharmony_ci static const char name[] = "Effect Duration"; 12438c2ecf20Sopenharmony_ci const unsigned int id = 0x43; 12448c2ecf20Sopenharmony_ci const int val_type = USB_MIXER_S16; 12458c2ecf20Sopenharmony_ci const unsigned int control = 4; 12468c2ecf20Sopenharmony_ci const unsigned int cmask = 0; 12478c2ecf20Sopenharmony_ci 12488c2ecf20Sopenharmony_ci return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, 12498c2ecf20Sopenharmony_ci name, snd_usb_mixer_vol_tlv); 12508c2ecf20Sopenharmony_ci} 12518c2ecf20Sopenharmony_ci 12528c2ecf20Sopenharmony_ci/* This control needs a volume quirk, see mixer.c */ 12538c2ecf20Sopenharmony_cistatic int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer) 12548c2ecf20Sopenharmony_ci{ 12558c2ecf20Sopenharmony_ci static const char name[] = "Effect Feedback Volume"; 12568c2ecf20Sopenharmony_ci const unsigned int id = 0x43; 12578c2ecf20Sopenharmony_ci const int val_type = USB_MIXER_U8; 12588c2ecf20Sopenharmony_ci const unsigned int control = 5; 12598c2ecf20Sopenharmony_ci const unsigned int cmask = 0; 12608c2ecf20Sopenharmony_ci 12618c2ecf20Sopenharmony_ci return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, 12628c2ecf20Sopenharmony_ci name, NULL); 12638c2ecf20Sopenharmony_ci} 12648c2ecf20Sopenharmony_ci 12658c2ecf20Sopenharmony_cistatic int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer) 12668c2ecf20Sopenharmony_ci{ 12678c2ecf20Sopenharmony_ci char name[64]; 12688c2ecf20Sopenharmony_ci unsigned int cmask; 12698c2ecf20Sopenharmony_ci int chan, err; 12708c2ecf20Sopenharmony_ci int num_outs = 0; 12718c2ecf20Sopenharmony_ci int num_ins = 0; 12728c2ecf20Sopenharmony_ci 12738c2ecf20Sopenharmony_ci const unsigned int id = 0x42; 12748c2ecf20Sopenharmony_ci const int val_type = USB_MIXER_S16; 12758c2ecf20Sopenharmony_ci const int control = 1; 12768c2ecf20Sopenharmony_ci 12778c2ecf20Sopenharmony_ci switch (mixer->chip->usb_id) { 12788c2ecf20Sopenharmony_ci case USB_ID(0x0763, 0x2030): 12798c2ecf20Sopenharmony_ci num_outs = 6; 12808c2ecf20Sopenharmony_ci num_ins = 4; 12818c2ecf20Sopenharmony_ci break; 12828c2ecf20Sopenharmony_ci case USB_ID(0x0763, 0x2031): 12838c2ecf20Sopenharmony_ci num_outs = 8; 12848c2ecf20Sopenharmony_ci num_ins = 6; 12858c2ecf20Sopenharmony_ci break; 12868c2ecf20Sopenharmony_ci } 12878c2ecf20Sopenharmony_ci 12888c2ecf20Sopenharmony_ci for (chan = 0; chan < num_outs + num_ins; chan++) { 12898c2ecf20Sopenharmony_ci if (chan < num_outs) { 12908c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), 12918c2ecf20Sopenharmony_ci "Effect Send DOut%d", 12928c2ecf20Sopenharmony_ci chan + 1); 12938c2ecf20Sopenharmony_ci } else { 12948c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), 12958c2ecf20Sopenharmony_ci "Effect Send AIn%d", 12968c2ecf20Sopenharmony_ci chan - num_outs + 1); 12978c2ecf20Sopenharmony_ci } 12988c2ecf20Sopenharmony_ci 12998c2ecf20Sopenharmony_ci cmask = (chan == 0) ? 0 : 1 << (chan - 1); 13008c2ecf20Sopenharmony_ci err = snd_create_std_mono_ctl(mixer, id, control, 13018c2ecf20Sopenharmony_ci cmask, val_type, name, 13028c2ecf20Sopenharmony_ci &snd_usb_mixer_vol_tlv); 13038c2ecf20Sopenharmony_ci if (err < 0) 13048c2ecf20Sopenharmony_ci return err; 13058c2ecf20Sopenharmony_ci } 13068c2ecf20Sopenharmony_ci 13078c2ecf20Sopenharmony_ci return 0; 13088c2ecf20Sopenharmony_ci} 13098c2ecf20Sopenharmony_ci 13108c2ecf20Sopenharmony_cistatic int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer) 13118c2ecf20Sopenharmony_ci{ 13128c2ecf20Sopenharmony_ci char name[64]; 13138c2ecf20Sopenharmony_ci unsigned int cmask; 13148c2ecf20Sopenharmony_ci int chan, err; 13158c2ecf20Sopenharmony_ci int num_outs = 0; 13168c2ecf20Sopenharmony_ci int offset = 0; 13178c2ecf20Sopenharmony_ci 13188c2ecf20Sopenharmony_ci const unsigned int id = 0x40; 13198c2ecf20Sopenharmony_ci const int val_type = USB_MIXER_S16; 13208c2ecf20Sopenharmony_ci const int control = 1; 13218c2ecf20Sopenharmony_ci 13228c2ecf20Sopenharmony_ci switch (mixer->chip->usb_id) { 13238c2ecf20Sopenharmony_ci case USB_ID(0x0763, 0x2030): 13248c2ecf20Sopenharmony_ci num_outs = 6; 13258c2ecf20Sopenharmony_ci offset = 0x3c; 13268c2ecf20Sopenharmony_ci /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */ 13278c2ecf20Sopenharmony_ci break; 13288c2ecf20Sopenharmony_ci case USB_ID(0x0763, 0x2031): 13298c2ecf20Sopenharmony_ci num_outs = 8; 13308c2ecf20Sopenharmony_ci offset = 0x70; 13318c2ecf20Sopenharmony_ci /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */ 13328c2ecf20Sopenharmony_ci break; 13338c2ecf20Sopenharmony_ci } 13348c2ecf20Sopenharmony_ci 13358c2ecf20Sopenharmony_ci for (chan = 0; chan < num_outs; chan++) { 13368c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), 13378c2ecf20Sopenharmony_ci "Effect Return %d", 13388c2ecf20Sopenharmony_ci chan + 1); 13398c2ecf20Sopenharmony_ci 13408c2ecf20Sopenharmony_ci cmask = (chan == 0) ? 0 : 13418c2ecf20Sopenharmony_ci 1 << (chan + (chan % 2) * num_outs - 1); 13428c2ecf20Sopenharmony_ci err = snd_create_std_mono_ctl_offset(mixer, id, control, 13438c2ecf20Sopenharmony_ci cmask, val_type, offset, name, 13448c2ecf20Sopenharmony_ci &snd_usb_mixer_vol_tlv); 13458c2ecf20Sopenharmony_ci if (err < 0) 13468c2ecf20Sopenharmony_ci return err; 13478c2ecf20Sopenharmony_ci } 13488c2ecf20Sopenharmony_ci 13498c2ecf20Sopenharmony_ci return 0; 13508c2ecf20Sopenharmony_ci} 13518c2ecf20Sopenharmony_ci 13528c2ecf20Sopenharmony_cistatic int snd_c400_create_mixer(struct usb_mixer_interface *mixer) 13538c2ecf20Sopenharmony_ci{ 13548c2ecf20Sopenharmony_ci int err; 13558c2ecf20Sopenharmony_ci 13568c2ecf20Sopenharmony_ci err = snd_c400_create_vol_ctls(mixer); 13578c2ecf20Sopenharmony_ci if (err < 0) 13588c2ecf20Sopenharmony_ci return err; 13598c2ecf20Sopenharmony_ci 13608c2ecf20Sopenharmony_ci err = snd_c400_create_effect_vol_ctls(mixer); 13618c2ecf20Sopenharmony_ci if (err < 0) 13628c2ecf20Sopenharmony_ci return err; 13638c2ecf20Sopenharmony_ci 13648c2ecf20Sopenharmony_ci err = snd_c400_create_effect_ret_vol_ctls(mixer); 13658c2ecf20Sopenharmony_ci if (err < 0) 13668c2ecf20Sopenharmony_ci return err; 13678c2ecf20Sopenharmony_ci 13688c2ecf20Sopenharmony_ci err = snd_ftu_create_effect_switch(mixer, 2, 0x43); 13698c2ecf20Sopenharmony_ci if (err < 0) 13708c2ecf20Sopenharmony_ci return err; 13718c2ecf20Sopenharmony_ci 13728c2ecf20Sopenharmony_ci err = snd_c400_create_effect_volume_ctl(mixer); 13738c2ecf20Sopenharmony_ci if (err < 0) 13748c2ecf20Sopenharmony_ci return err; 13758c2ecf20Sopenharmony_ci 13768c2ecf20Sopenharmony_ci err = snd_c400_create_effect_duration_ctl(mixer); 13778c2ecf20Sopenharmony_ci if (err < 0) 13788c2ecf20Sopenharmony_ci return err; 13798c2ecf20Sopenharmony_ci 13808c2ecf20Sopenharmony_ci err = snd_c400_create_effect_feedback_ctl(mixer); 13818c2ecf20Sopenharmony_ci if (err < 0) 13828c2ecf20Sopenharmony_ci return err; 13838c2ecf20Sopenharmony_ci 13848c2ecf20Sopenharmony_ci return 0; 13858c2ecf20Sopenharmony_ci} 13868c2ecf20Sopenharmony_ci 13878c2ecf20Sopenharmony_ci/* 13888c2ecf20Sopenharmony_ci * The mixer units for Ebox-44 are corrupt, and even where they 13898c2ecf20Sopenharmony_ci * are valid they presents mono controls as L and R channels of 13908c2ecf20Sopenharmony_ci * stereo. So we provide a good mixer here. 13918c2ecf20Sopenharmony_ci */ 13928c2ecf20Sopenharmony_cistatic const struct std_mono_table ebox44_table[] = { 13938c2ecf20Sopenharmony_ci { 13948c2ecf20Sopenharmony_ci .unitid = 4, 13958c2ecf20Sopenharmony_ci .control = 1, 13968c2ecf20Sopenharmony_ci .cmask = 0x0, 13978c2ecf20Sopenharmony_ci .val_type = USB_MIXER_INV_BOOLEAN, 13988c2ecf20Sopenharmony_ci .name = "Headphone Playback Switch" 13998c2ecf20Sopenharmony_ci }, 14008c2ecf20Sopenharmony_ci { 14018c2ecf20Sopenharmony_ci .unitid = 4, 14028c2ecf20Sopenharmony_ci .control = 2, 14038c2ecf20Sopenharmony_ci .cmask = 0x1, 14048c2ecf20Sopenharmony_ci .val_type = USB_MIXER_S16, 14058c2ecf20Sopenharmony_ci .name = "Headphone A Mix Playback Volume" 14068c2ecf20Sopenharmony_ci }, 14078c2ecf20Sopenharmony_ci { 14088c2ecf20Sopenharmony_ci .unitid = 4, 14098c2ecf20Sopenharmony_ci .control = 2, 14108c2ecf20Sopenharmony_ci .cmask = 0x2, 14118c2ecf20Sopenharmony_ci .val_type = USB_MIXER_S16, 14128c2ecf20Sopenharmony_ci .name = "Headphone B Mix Playback Volume" 14138c2ecf20Sopenharmony_ci }, 14148c2ecf20Sopenharmony_ci 14158c2ecf20Sopenharmony_ci { 14168c2ecf20Sopenharmony_ci .unitid = 7, 14178c2ecf20Sopenharmony_ci .control = 1, 14188c2ecf20Sopenharmony_ci .cmask = 0x0, 14198c2ecf20Sopenharmony_ci .val_type = USB_MIXER_INV_BOOLEAN, 14208c2ecf20Sopenharmony_ci .name = "Output Playback Switch" 14218c2ecf20Sopenharmony_ci }, 14228c2ecf20Sopenharmony_ci { 14238c2ecf20Sopenharmony_ci .unitid = 7, 14248c2ecf20Sopenharmony_ci .control = 2, 14258c2ecf20Sopenharmony_ci .cmask = 0x1, 14268c2ecf20Sopenharmony_ci .val_type = USB_MIXER_S16, 14278c2ecf20Sopenharmony_ci .name = "Output A Playback Volume" 14288c2ecf20Sopenharmony_ci }, 14298c2ecf20Sopenharmony_ci { 14308c2ecf20Sopenharmony_ci .unitid = 7, 14318c2ecf20Sopenharmony_ci .control = 2, 14328c2ecf20Sopenharmony_ci .cmask = 0x2, 14338c2ecf20Sopenharmony_ci .val_type = USB_MIXER_S16, 14348c2ecf20Sopenharmony_ci .name = "Output B Playback Volume" 14358c2ecf20Sopenharmony_ci }, 14368c2ecf20Sopenharmony_ci 14378c2ecf20Sopenharmony_ci { 14388c2ecf20Sopenharmony_ci .unitid = 10, 14398c2ecf20Sopenharmony_ci .control = 1, 14408c2ecf20Sopenharmony_ci .cmask = 0x0, 14418c2ecf20Sopenharmony_ci .val_type = USB_MIXER_INV_BOOLEAN, 14428c2ecf20Sopenharmony_ci .name = "Input Capture Switch" 14438c2ecf20Sopenharmony_ci }, 14448c2ecf20Sopenharmony_ci { 14458c2ecf20Sopenharmony_ci .unitid = 10, 14468c2ecf20Sopenharmony_ci .control = 2, 14478c2ecf20Sopenharmony_ci .cmask = 0x1, 14488c2ecf20Sopenharmony_ci .val_type = USB_MIXER_S16, 14498c2ecf20Sopenharmony_ci .name = "Input A Capture Volume" 14508c2ecf20Sopenharmony_ci }, 14518c2ecf20Sopenharmony_ci { 14528c2ecf20Sopenharmony_ci .unitid = 10, 14538c2ecf20Sopenharmony_ci .control = 2, 14548c2ecf20Sopenharmony_ci .cmask = 0x2, 14558c2ecf20Sopenharmony_ci .val_type = USB_MIXER_S16, 14568c2ecf20Sopenharmony_ci .name = "Input B Capture Volume" 14578c2ecf20Sopenharmony_ci }, 14588c2ecf20Sopenharmony_ci 14598c2ecf20Sopenharmony_ci {} 14608c2ecf20Sopenharmony_ci}; 14618c2ecf20Sopenharmony_ci 14628c2ecf20Sopenharmony_ci/* Audio Advantage Micro II findings: 14638c2ecf20Sopenharmony_ci * 14648c2ecf20Sopenharmony_ci * Mapping spdif AES bits to vendor register.bit: 14658c2ecf20Sopenharmony_ci * AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00 14668c2ecf20Sopenharmony_ci * AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01 14678c2ecf20Sopenharmony_ci * AES2: [0 0 0 0 0 0 0 0] 14688c2ecf20Sopenharmony_ci * AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request 14698c2ecf20Sopenharmony_ci * (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices 14708c2ecf20Sopenharmony_ci * 14718c2ecf20Sopenharmony_ci * power on values: 14728c2ecf20Sopenharmony_ci * r2: 0x10 14738c2ecf20Sopenharmony_ci * r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set 14748c2ecf20Sopenharmony_ci * just after it to 0xa0, presumably it disables/mutes some analog 14758c2ecf20Sopenharmony_ci * parts when there is no audio.) 14768c2ecf20Sopenharmony_ci * r9: 0x28 14778c2ecf20Sopenharmony_ci * 14788c2ecf20Sopenharmony_ci * Optical transmitter on/off: 14798c2ecf20Sopenharmony_ci * vendor register.bit: 9.1 14808c2ecf20Sopenharmony_ci * 0 - on (0x28 register value) 14818c2ecf20Sopenharmony_ci * 1 - off (0x2a register value) 14828c2ecf20Sopenharmony_ci * 14838c2ecf20Sopenharmony_ci */ 14848c2ecf20Sopenharmony_cistatic int snd_microii_spdif_info(struct snd_kcontrol *kcontrol, 14858c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 14868c2ecf20Sopenharmony_ci{ 14878c2ecf20Sopenharmony_ci uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; 14888c2ecf20Sopenharmony_ci uinfo->count = 1; 14898c2ecf20Sopenharmony_ci return 0; 14908c2ecf20Sopenharmony_ci} 14918c2ecf20Sopenharmony_ci 14928c2ecf20Sopenharmony_cistatic int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol, 14938c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 14948c2ecf20Sopenharmony_ci{ 14958c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); 14968c2ecf20Sopenharmony_ci struct snd_usb_audio *chip = list->mixer->chip; 14978c2ecf20Sopenharmony_ci int err; 14988c2ecf20Sopenharmony_ci struct usb_interface *iface; 14998c2ecf20Sopenharmony_ci struct usb_host_interface *alts; 15008c2ecf20Sopenharmony_ci unsigned int ep; 15018c2ecf20Sopenharmony_ci unsigned char data[3]; 15028c2ecf20Sopenharmony_ci int rate; 15038c2ecf20Sopenharmony_ci 15048c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(chip); 15058c2ecf20Sopenharmony_ci if (err < 0) 15068c2ecf20Sopenharmony_ci return err; 15078c2ecf20Sopenharmony_ci 15088c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff; 15098c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff; 15108c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[2] = 0x00; 15118c2ecf20Sopenharmony_ci 15128c2ecf20Sopenharmony_ci /* use known values for that card: interface#1 altsetting#1 */ 15138c2ecf20Sopenharmony_ci iface = usb_ifnum_to_if(chip->dev, 1); 15148c2ecf20Sopenharmony_ci if (!iface || iface->num_altsetting < 2) { 15158c2ecf20Sopenharmony_ci err = -EINVAL; 15168c2ecf20Sopenharmony_ci goto end; 15178c2ecf20Sopenharmony_ci } 15188c2ecf20Sopenharmony_ci alts = &iface->altsetting[1]; 15198c2ecf20Sopenharmony_ci if (get_iface_desc(alts)->bNumEndpoints < 1) { 15208c2ecf20Sopenharmony_ci err = -EINVAL; 15218c2ecf20Sopenharmony_ci goto end; 15228c2ecf20Sopenharmony_ci } 15238c2ecf20Sopenharmony_ci ep = get_endpoint(alts, 0)->bEndpointAddress; 15248c2ecf20Sopenharmony_ci 15258c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 15268c2ecf20Sopenharmony_ci usb_rcvctrlpipe(chip->dev, 0), 15278c2ecf20Sopenharmony_ci UAC_GET_CUR, 15288c2ecf20Sopenharmony_ci USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN, 15298c2ecf20Sopenharmony_ci UAC_EP_CS_ATTR_SAMPLE_RATE << 8, 15308c2ecf20Sopenharmony_ci ep, 15318c2ecf20Sopenharmony_ci data, 15328c2ecf20Sopenharmony_ci sizeof(data)); 15338c2ecf20Sopenharmony_ci if (err < 0) 15348c2ecf20Sopenharmony_ci goto end; 15358c2ecf20Sopenharmony_ci 15368c2ecf20Sopenharmony_ci rate = data[0] | (data[1] << 8) | (data[2] << 16); 15378c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[3] = (rate == 48000) ? 15388c2ecf20Sopenharmony_ci IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100; 15398c2ecf20Sopenharmony_ci 15408c2ecf20Sopenharmony_ci err = 0; 15418c2ecf20Sopenharmony_ci end: 15428c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(chip); 15438c2ecf20Sopenharmony_ci return err; 15448c2ecf20Sopenharmony_ci} 15458c2ecf20Sopenharmony_ci 15468c2ecf20Sopenharmony_cistatic int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list) 15478c2ecf20Sopenharmony_ci{ 15488c2ecf20Sopenharmony_ci struct snd_usb_audio *chip = list->mixer->chip; 15498c2ecf20Sopenharmony_ci unsigned int pval = list->kctl->private_value; 15508c2ecf20Sopenharmony_ci u8 reg; 15518c2ecf20Sopenharmony_ci int err; 15528c2ecf20Sopenharmony_ci 15538c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(chip); 15548c2ecf20Sopenharmony_ci if (err < 0) 15558c2ecf20Sopenharmony_ci return err; 15568c2ecf20Sopenharmony_ci 15578c2ecf20Sopenharmony_ci reg = ((pval >> 4) & 0xf0) | (pval & 0x0f); 15588c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 15598c2ecf20Sopenharmony_ci usb_sndctrlpipe(chip->dev, 0), 15608c2ecf20Sopenharmony_ci UAC_SET_CUR, 15618c2ecf20Sopenharmony_ci USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 15628c2ecf20Sopenharmony_ci reg, 15638c2ecf20Sopenharmony_ci 2, 15648c2ecf20Sopenharmony_ci NULL, 15658c2ecf20Sopenharmony_ci 0); 15668c2ecf20Sopenharmony_ci if (err < 0) 15678c2ecf20Sopenharmony_ci goto end; 15688c2ecf20Sopenharmony_ci 15698c2ecf20Sopenharmony_ci reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20; 15708c2ecf20Sopenharmony_ci reg |= (pval >> 12) & 0x0f; 15718c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 15728c2ecf20Sopenharmony_ci usb_sndctrlpipe(chip->dev, 0), 15738c2ecf20Sopenharmony_ci UAC_SET_CUR, 15748c2ecf20Sopenharmony_ci USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 15758c2ecf20Sopenharmony_ci reg, 15768c2ecf20Sopenharmony_ci 3, 15778c2ecf20Sopenharmony_ci NULL, 15788c2ecf20Sopenharmony_ci 0); 15798c2ecf20Sopenharmony_ci if (err < 0) 15808c2ecf20Sopenharmony_ci goto end; 15818c2ecf20Sopenharmony_ci 15828c2ecf20Sopenharmony_ci end: 15838c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(chip); 15848c2ecf20Sopenharmony_ci return err; 15858c2ecf20Sopenharmony_ci} 15868c2ecf20Sopenharmony_ci 15878c2ecf20Sopenharmony_cistatic int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol, 15888c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 15898c2ecf20Sopenharmony_ci{ 15908c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); 15918c2ecf20Sopenharmony_ci unsigned int pval, pval_old; 15928c2ecf20Sopenharmony_ci int err; 15938c2ecf20Sopenharmony_ci 15948c2ecf20Sopenharmony_ci pval = pval_old = kcontrol->private_value; 15958c2ecf20Sopenharmony_ci pval &= 0xfffff0f0; 15968c2ecf20Sopenharmony_ci pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8; 15978c2ecf20Sopenharmony_ci pval |= (ucontrol->value.iec958.status[0] & 0x0f); 15988c2ecf20Sopenharmony_ci 15998c2ecf20Sopenharmony_ci pval &= 0xffff0fff; 16008c2ecf20Sopenharmony_ci pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8; 16018c2ecf20Sopenharmony_ci 16028c2ecf20Sopenharmony_ci /* The frequency bits in AES3 cannot be set via register access. */ 16038c2ecf20Sopenharmony_ci 16048c2ecf20Sopenharmony_ci /* Silently ignore any bits from the request that cannot be set. */ 16058c2ecf20Sopenharmony_ci 16068c2ecf20Sopenharmony_ci if (pval == pval_old) 16078c2ecf20Sopenharmony_ci return 0; 16088c2ecf20Sopenharmony_ci 16098c2ecf20Sopenharmony_ci kcontrol->private_value = pval; 16108c2ecf20Sopenharmony_ci err = snd_microii_spdif_default_update(list); 16118c2ecf20Sopenharmony_ci return err < 0 ? err : 1; 16128c2ecf20Sopenharmony_ci} 16138c2ecf20Sopenharmony_ci 16148c2ecf20Sopenharmony_cistatic int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol, 16158c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 16168c2ecf20Sopenharmony_ci{ 16178c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[0] = 0x0f; 16188c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[1] = 0xff; 16198c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[2] = 0x00; 16208c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[3] = 0x00; 16218c2ecf20Sopenharmony_ci 16228c2ecf20Sopenharmony_ci return 0; 16238c2ecf20Sopenharmony_ci} 16248c2ecf20Sopenharmony_ci 16258c2ecf20Sopenharmony_cistatic int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol, 16268c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 16278c2ecf20Sopenharmony_ci{ 16288c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02); 16298c2ecf20Sopenharmony_ci 16308c2ecf20Sopenharmony_ci return 0; 16318c2ecf20Sopenharmony_ci} 16328c2ecf20Sopenharmony_ci 16338c2ecf20Sopenharmony_cistatic int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list) 16348c2ecf20Sopenharmony_ci{ 16358c2ecf20Sopenharmony_ci struct snd_usb_audio *chip = list->mixer->chip; 16368c2ecf20Sopenharmony_ci u8 reg = list->kctl->private_value; 16378c2ecf20Sopenharmony_ci int err; 16388c2ecf20Sopenharmony_ci 16398c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(chip); 16408c2ecf20Sopenharmony_ci if (err < 0) 16418c2ecf20Sopenharmony_ci return err; 16428c2ecf20Sopenharmony_ci 16438c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 16448c2ecf20Sopenharmony_ci usb_sndctrlpipe(chip->dev, 0), 16458c2ecf20Sopenharmony_ci UAC_SET_CUR, 16468c2ecf20Sopenharmony_ci USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 16478c2ecf20Sopenharmony_ci reg, 16488c2ecf20Sopenharmony_ci 9, 16498c2ecf20Sopenharmony_ci NULL, 16508c2ecf20Sopenharmony_ci 0); 16518c2ecf20Sopenharmony_ci 16528c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(chip); 16538c2ecf20Sopenharmony_ci return err; 16548c2ecf20Sopenharmony_ci} 16558c2ecf20Sopenharmony_ci 16568c2ecf20Sopenharmony_cistatic int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol, 16578c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 16588c2ecf20Sopenharmony_ci{ 16598c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); 16608c2ecf20Sopenharmony_ci u8 reg; 16618c2ecf20Sopenharmony_ci int err; 16628c2ecf20Sopenharmony_ci 16638c2ecf20Sopenharmony_ci reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a; 16648c2ecf20Sopenharmony_ci if (reg != list->kctl->private_value) 16658c2ecf20Sopenharmony_ci return 0; 16668c2ecf20Sopenharmony_ci 16678c2ecf20Sopenharmony_ci kcontrol->private_value = reg; 16688c2ecf20Sopenharmony_ci err = snd_microii_spdif_switch_update(list); 16698c2ecf20Sopenharmony_ci return err < 0 ? err : 1; 16708c2ecf20Sopenharmony_ci} 16718c2ecf20Sopenharmony_ci 16728c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_microii_mixer_spdif[] = { 16738c2ecf20Sopenharmony_ci { 16748c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_PCM, 16758c2ecf20Sopenharmony_ci .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), 16768c2ecf20Sopenharmony_ci .info = snd_microii_spdif_info, 16778c2ecf20Sopenharmony_ci .get = snd_microii_spdif_default_get, 16788c2ecf20Sopenharmony_ci .put = snd_microii_spdif_default_put, 16798c2ecf20Sopenharmony_ci .private_value = 0x00000100UL,/* reset value */ 16808c2ecf20Sopenharmony_ci }, 16818c2ecf20Sopenharmony_ci { 16828c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READ, 16838c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_PCM, 16848c2ecf20Sopenharmony_ci .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK), 16858c2ecf20Sopenharmony_ci .info = snd_microii_spdif_info, 16868c2ecf20Sopenharmony_ci .get = snd_microii_spdif_mask_get, 16878c2ecf20Sopenharmony_ci }, 16888c2ecf20Sopenharmony_ci { 16898c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 16908c2ecf20Sopenharmony_ci .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), 16918c2ecf20Sopenharmony_ci .info = snd_ctl_boolean_mono_info, 16928c2ecf20Sopenharmony_ci .get = snd_microii_spdif_switch_get, 16938c2ecf20Sopenharmony_ci .put = snd_microii_spdif_switch_put, 16948c2ecf20Sopenharmony_ci .private_value = 0x00000028UL,/* reset value */ 16958c2ecf20Sopenharmony_ci } 16968c2ecf20Sopenharmony_ci}; 16978c2ecf20Sopenharmony_ci 16988c2ecf20Sopenharmony_cistatic int snd_microii_controls_create(struct usb_mixer_interface *mixer) 16998c2ecf20Sopenharmony_ci{ 17008c2ecf20Sopenharmony_ci int err, i; 17018c2ecf20Sopenharmony_ci static const usb_mixer_elem_resume_func_t resume_funcs[] = { 17028c2ecf20Sopenharmony_ci snd_microii_spdif_default_update, 17038c2ecf20Sopenharmony_ci NULL, 17048c2ecf20Sopenharmony_ci snd_microii_spdif_switch_update 17058c2ecf20Sopenharmony_ci }; 17068c2ecf20Sopenharmony_ci 17078c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) { 17088c2ecf20Sopenharmony_ci err = add_single_ctl_with_resume(mixer, 0, 17098c2ecf20Sopenharmony_ci resume_funcs[i], 17108c2ecf20Sopenharmony_ci &snd_microii_mixer_spdif[i], 17118c2ecf20Sopenharmony_ci NULL); 17128c2ecf20Sopenharmony_ci if (err < 0) 17138c2ecf20Sopenharmony_ci return err; 17148c2ecf20Sopenharmony_ci } 17158c2ecf20Sopenharmony_ci 17168c2ecf20Sopenharmony_ci return 0; 17178c2ecf20Sopenharmony_ci} 17188c2ecf20Sopenharmony_ci 17198c2ecf20Sopenharmony_ci/* Creative Sound Blaster E1 */ 17208c2ecf20Sopenharmony_ci 17218c2ecf20Sopenharmony_cistatic int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol, 17228c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 17238c2ecf20Sopenharmony_ci{ 17248c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = kcontrol->private_value; 17258c2ecf20Sopenharmony_ci return 0; 17268c2ecf20Sopenharmony_ci} 17278c2ecf20Sopenharmony_ci 17288c2ecf20Sopenharmony_cistatic int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer, 17298c2ecf20Sopenharmony_ci unsigned char state) 17308c2ecf20Sopenharmony_ci{ 17318c2ecf20Sopenharmony_ci struct snd_usb_audio *chip = mixer->chip; 17328c2ecf20Sopenharmony_ci int err; 17338c2ecf20Sopenharmony_ci unsigned char buff[2]; 17348c2ecf20Sopenharmony_ci 17358c2ecf20Sopenharmony_ci buff[0] = 0x02; 17368c2ecf20Sopenharmony_ci buff[1] = state ? 0x02 : 0x00; 17378c2ecf20Sopenharmony_ci 17388c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(chip); 17398c2ecf20Sopenharmony_ci if (err < 0) 17408c2ecf20Sopenharmony_ci return err; 17418c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 17428c2ecf20Sopenharmony_ci usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT, 17438c2ecf20Sopenharmony_ci USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT, 17448c2ecf20Sopenharmony_ci 0x0202, 3, buff, 2); 17458c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(chip); 17468c2ecf20Sopenharmony_ci return err; 17478c2ecf20Sopenharmony_ci} 17488c2ecf20Sopenharmony_ci 17498c2ecf20Sopenharmony_cistatic int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol, 17508c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 17518c2ecf20Sopenharmony_ci{ 17528c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); 17538c2ecf20Sopenharmony_ci unsigned char value = !!ucontrol->value.integer.value[0]; 17548c2ecf20Sopenharmony_ci int err; 17558c2ecf20Sopenharmony_ci 17568c2ecf20Sopenharmony_ci if (kcontrol->private_value == value) 17578c2ecf20Sopenharmony_ci return 0; 17588c2ecf20Sopenharmony_ci kcontrol->private_value = value; 17598c2ecf20Sopenharmony_ci err = snd_soundblaster_e1_switch_update(list->mixer, value); 17608c2ecf20Sopenharmony_ci return err < 0 ? err : 1; 17618c2ecf20Sopenharmony_ci} 17628c2ecf20Sopenharmony_ci 17638c2ecf20Sopenharmony_cistatic int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list) 17648c2ecf20Sopenharmony_ci{ 17658c2ecf20Sopenharmony_ci return snd_soundblaster_e1_switch_update(list->mixer, 17668c2ecf20Sopenharmony_ci list->kctl->private_value); 17678c2ecf20Sopenharmony_ci} 17688c2ecf20Sopenharmony_ci 17698c2ecf20Sopenharmony_cistatic int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol, 17708c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 17718c2ecf20Sopenharmony_ci{ 17728c2ecf20Sopenharmony_ci static const char *const texts[2] = { 17738c2ecf20Sopenharmony_ci "Mic", "Aux" 17748c2ecf20Sopenharmony_ci }; 17758c2ecf20Sopenharmony_ci 17768c2ecf20Sopenharmony_ci return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); 17778c2ecf20Sopenharmony_ci} 17788c2ecf20Sopenharmony_ci 17798c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_soundblaster_e1_input_switch = { 17808c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 17818c2ecf20Sopenharmony_ci .name = "Input Source", 17828c2ecf20Sopenharmony_ci .info = snd_soundblaster_e1_switch_info, 17838c2ecf20Sopenharmony_ci .get = snd_soundblaster_e1_switch_get, 17848c2ecf20Sopenharmony_ci .put = snd_soundblaster_e1_switch_put, 17858c2ecf20Sopenharmony_ci .private_value = 0, 17868c2ecf20Sopenharmony_ci}; 17878c2ecf20Sopenharmony_ci 17888c2ecf20Sopenharmony_cistatic int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer) 17898c2ecf20Sopenharmony_ci{ 17908c2ecf20Sopenharmony_ci return add_single_ctl_with_resume(mixer, 0, 17918c2ecf20Sopenharmony_ci snd_soundblaster_e1_switch_resume, 17928c2ecf20Sopenharmony_ci &snd_soundblaster_e1_input_switch, 17938c2ecf20Sopenharmony_ci NULL); 17948c2ecf20Sopenharmony_ci} 17958c2ecf20Sopenharmony_ci 17968c2ecf20Sopenharmony_cistatic void dell_dock_init_vol(struct snd_usb_audio *chip, int ch, int id) 17978c2ecf20Sopenharmony_ci{ 17988c2ecf20Sopenharmony_ci u16 buf = 0; 17998c2ecf20Sopenharmony_ci 18008c2ecf20Sopenharmony_ci snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR, 18018c2ecf20Sopenharmony_ci USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, 18028c2ecf20Sopenharmony_ci ch, snd_usb_ctrl_intf(chip) | (id << 8), 18038c2ecf20Sopenharmony_ci &buf, 2); 18048c2ecf20Sopenharmony_ci} 18058c2ecf20Sopenharmony_ci 18068c2ecf20Sopenharmony_cistatic int dell_dock_mixer_init(struct usb_mixer_interface *mixer) 18078c2ecf20Sopenharmony_ci{ 18088c2ecf20Sopenharmony_ci /* fix to 0dB playback volumes */ 18098c2ecf20Sopenharmony_ci dell_dock_init_vol(mixer->chip, 1, 16); 18108c2ecf20Sopenharmony_ci dell_dock_init_vol(mixer->chip, 2, 16); 18118c2ecf20Sopenharmony_ci dell_dock_init_vol(mixer->chip, 1, 19); 18128c2ecf20Sopenharmony_ci dell_dock_init_vol(mixer->chip, 2, 19); 18138c2ecf20Sopenharmony_ci return 0; 18148c2ecf20Sopenharmony_ci} 18158c2ecf20Sopenharmony_ci 18168c2ecf20Sopenharmony_ci/* RME Class Compliant device quirks */ 18178c2ecf20Sopenharmony_ci 18188c2ecf20Sopenharmony_ci#define SND_RME_GET_STATUS1 23 18198c2ecf20Sopenharmony_ci#define SND_RME_GET_CURRENT_FREQ 17 18208c2ecf20Sopenharmony_ci#define SND_RME_CLK_SYSTEM_SHIFT 16 18218c2ecf20Sopenharmony_ci#define SND_RME_CLK_SYSTEM_MASK 0x1f 18228c2ecf20Sopenharmony_ci#define SND_RME_CLK_AES_SHIFT 8 18238c2ecf20Sopenharmony_ci#define SND_RME_CLK_SPDIF_SHIFT 12 18248c2ecf20Sopenharmony_ci#define SND_RME_CLK_AES_SPDIF_MASK 0xf 18258c2ecf20Sopenharmony_ci#define SND_RME_CLK_SYNC_SHIFT 6 18268c2ecf20Sopenharmony_ci#define SND_RME_CLK_SYNC_MASK 0x3 18278c2ecf20Sopenharmony_ci#define SND_RME_CLK_FREQMUL_SHIFT 18 18288c2ecf20Sopenharmony_ci#define SND_RME_CLK_FREQMUL_MASK 0x7 18298c2ecf20Sopenharmony_ci#define SND_RME_CLK_SYSTEM(x) \ 18308c2ecf20Sopenharmony_ci ((x >> SND_RME_CLK_SYSTEM_SHIFT) & SND_RME_CLK_SYSTEM_MASK) 18318c2ecf20Sopenharmony_ci#define SND_RME_CLK_AES(x) \ 18328c2ecf20Sopenharmony_ci ((x >> SND_RME_CLK_AES_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK) 18338c2ecf20Sopenharmony_ci#define SND_RME_CLK_SPDIF(x) \ 18348c2ecf20Sopenharmony_ci ((x >> SND_RME_CLK_SPDIF_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK) 18358c2ecf20Sopenharmony_ci#define SND_RME_CLK_SYNC(x) \ 18368c2ecf20Sopenharmony_ci ((x >> SND_RME_CLK_SYNC_SHIFT) & SND_RME_CLK_SYNC_MASK) 18378c2ecf20Sopenharmony_ci#define SND_RME_CLK_FREQMUL(x) \ 18388c2ecf20Sopenharmony_ci ((x >> SND_RME_CLK_FREQMUL_SHIFT) & SND_RME_CLK_FREQMUL_MASK) 18398c2ecf20Sopenharmony_ci#define SND_RME_CLK_AES_LOCK 0x1 18408c2ecf20Sopenharmony_ci#define SND_RME_CLK_AES_SYNC 0x4 18418c2ecf20Sopenharmony_ci#define SND_RME_CLK_SPDIF_LOCK 0x2 18428c2ecf20Sopenharmony_ci#define SND_RME_CLK_SPDIF_SYNC 0x8 18438c2ecf20Sopenharmony_ci#define SND_RME_SPDIF_IF_SHIFT 4 18448c2ecf20Sopenharmony_ci#define SND_RME_SPDIF_FORMAT_SHIFT 5 18458c2ecf20Sopenharmony_ci#define SND_RME_BINARY_MASK 0x1 18468c2ecf20Sopenharmony_ci#define SND_RME_SPDIF_IF(x) \ 18478c2ecf20Sopenharmony_ci ((x >> SND_RME_SPDIF_IF_SHIFT) & SND_RME_BINARY_MASK) 18488c2ecf20Sopenharmony_ci#define SND_RME_SPDIF_FORMAT(x) \ 18498c2ecf20Sopenharmony_ci ((x >> SND_RME_SPDIF_FORMAT_SHIFT) & SND_RME_BINARY_MASK) 18508c2ecf20Sopenharmony_ci 18518c2ecf20Sopenharmony_cistatic const u32 snd_rme_rate_table[] = { 18528c2ecf20Sopenharmony_ci 32000, 44100, 48000, 50000, 18538c2ecf20Sopenharmony_ci 64000, 88200, 96000, 100000, 18548c2ecf20Sopenharmony_ci 128000, 176400, 192000, 200000, 18558c2ecf20Sopenharmony_ci 256000, 352800, 384000, 400000, 18568c2ecf20Sopenharmony_ci 512000, 705600, 768000, 800000 18578c2ecf20Sopenharmony_ci}; 18588c2ecf20Sopenharmony_ci/* maximum number of items for AES and S/PDIF rates for above table */ 18598c2ecf20Sopenharmony_ci#define SND_RME_RATE_IDX_AES_SPDIF_NUM 12 18608c2ecf20Sopenharmony_ci 18618c2ecf20Sopenharmony_cienum snd_rme_domain { 18628c2ecf20Sopenharmony_ci SND_RME_DOMAIN_SYSTEM, 18638c2ecf20Sopenharmony_ci SND_RME_DOMAIN_AES, 18648c2ecf20Sopenharmony_ci SND_RME_DOMAIN_SPDIF 18658c2ecf20Sopenharmony_ci}; 18668c2ecf20Sopenharmony_ci 18678c2ecf20Sopenharmony_cienum snd_rme_clock_status { 18688c2ecf20Sopenharmony_ci SND_RME_CLOCK_NOLOCK, 18698c2ecf20Sopenharmony_ci SND_RME_CLOCK_LOCK, 18708c2ecf20Sopenharmony_ci SND_RME_CLOCK_SYNC 18718c2ecf20Sopenharmony_ci}; 18728c2ecf20Sopenharmony_ci 18738c2ecf20Sopenharmony_cistatic int snd_rme_read_value(struct snd_usb_audio *chip, 18748c2ecf20Sopenharmony_ci unsigned int item, 18758c2ecf20Sopenharmony_ci u32 *value) 18768c2ecf20Sopenharmony_ci{ 18778c2ecf20Sopenharmony_ci struct usb_device *dev = chip->dev; 18788c2ecf20Sopenharmony_ci int err; 18798c2ecf20Sopenharmony_ci 18808c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 18818c2ecf20Sopenharmony_ci item, 18828c2ecf20Sopenharmony_ci USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 18838c2ecf20Sopenharmony_ci 0, 0, 18848c2ecf20Sopenharmony_ci value, sizeof(*value)); 18858c2ecf20Sopenharmony_ci if (err < 0) 18868c2ecf20Sopenharmony_ci dev_err(&dev->dev, 18878c2ecf20Sopenharmony_ci "unable to issue vendor read request %d (ret = %d)", 18888c2ecf20Sopenharmony_ci item, err); 18898c2ecf20Sopenharmony_ci return err; 18908c2ecf20Sopenharmony_ci} 18918c2ecf20Sopenharmony_ci 18928c2ecf20Sopenharmony_cistatic int snd_rme_get_status1(struct snd_kcontrol *kcontrol, 18938c2ecf20Sopenharmony_ci u32 *status1) 18948c2ecf20Sopenharmony_ci{ 18958c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); 18968c2ecf20Sopenharmony_ci struct snd_usb_audio *chip = list->mixer->chip; 18978c2ecf20Sopenharmony_ci int err; 18988c2ecf20Sopenharmony_ci 18998c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(chip); 19008c2ecf20Sopenharmony_ci if (err < 0) 19018c2ecf20Sopenharmony_ci return err; 19028c2ecf20Sopenharmony_ci err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, status1); 19038c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(chip); 19048c2ecf20Sopenharmony_ci return err; 19058c2ecf20Sopenharmony_ci} 19068c2ecf20Sopenharmony_ci 19078c2ecf20Sopenharmony_cistatic int snd_rme_rate_get(struct snd_kcontrol *kcontrol, 19088c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 19098c2ecf20Sopenharmony_ci{ 19108c2ecf20Sopenharmony_ci u32 status1; 19118c2ecf20Sopenharmony_ci u32 rate = 0; 19128c2ecf20Sopenharmony_ci int idx; 19138c2ecf20Sopenharmony_ci int err; 19148c2ecf20Sopenharmony_ci 19158c2ecf20Sopenharmony_ci err = snd_rme_get_status1(kcontrol, &status1); 19168c2ecf20Sopenharmony_ci if (err < 0) 19178c2ecf20Sopenharmony_ci return err; 19188c2ecf20Sopenharmony_ci switch (kcontrol->private_value) { 19198c2ecf20Sopenharmony_ci case SND_RME_DOMAIN_SYSTEM: 19208c2ecf20Sopenharmony_ci idx = SND_RME_CLK_SYSTEM(status1); 19218c2ecf20Sopenharmony_ci if (idx < ARRAY_SIZE(snd_rme_rate_table)) 19228c2ecf20Sopenharmony_ci rate = snd_rme_rate_table[idx]; 19238c2ecf20Sopenharmony_ci break; 19248c2ecf20Sopenharmony_ci case SND_RME_DOMAIN_AES: 19258c2ecf20Sopenharmony_ci idx = SND_RME_CLK_AES(status1); 19268c2ecf20Sopenharmony_ci if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM) 19278c2ecf20Sopenharmony_ci rate = snd_rme_rate_table[idx]; 19288c2ecf20Sopenharmony_ci break; 19298c2ecf20Sopenharmony_ci case SND_RME_DOMAIN_SPDIF: 19308c2ecf20Sopenharmony_ci idx = SND_RME_CLK_SPDIF(status1); 19318c2ecf20Sopenharmony_ci if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM) 19328c2ecf20Sopenharmony_ci rate = snd_rme_rate_table[idx]; 19338c2ecf20Sopenharmony_ci break; 19348c2ecf20Sopenharmony_ci default: 19358c2ecf20Sopenharmony_ci return -EINVAL; 19368c2ecf20Sopenharmony_ci } 19378c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = rate; 19388c2ecf20Sopenharmony_ci return 0; 19398c2ecf20Sopenharmony_ci} 19408c2ecf20Sopenharmony_ci 19418c2ecf20Sopenharmony_cistatic int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol, 19428c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 19438c2ecf20Sopenharmony_ci{ 19448c2ecf20Sopenharmony_ci u32 status1; 19458c2ecf20Sopenharmony_ci int idx = SND_RME_CLOCK_NOLOCK; 19468c2ecf20Sopenharmony_ci int err; 19478c2ecf20Sopenharmony_ci 19488c2ecf20Sopenharmony_ci err = snd_rme_get_status1(kcontrol, &status1); 19498c2ecf20Sopenharmony_ci if (err < 0) 19508c2ecf20Sopenharmony_ci return err; 19518c2ecf20Sopenharmony_ci switch (kcontrol->private_value) { 19528c2ecf20Sopenharmony_ci case SND_RME_DOMAIN_AES: /* AES */ 19538c2ecf20Sopenharmony_ci if (status1 & SND_RME_CLK_AES_SYNC) 19548c2ecf20Sopenharmony_ci idx = SND_RME_CLOCK_SYNC; 19558c2ecf20Sopenharmony_ci else if (status1 & SND_RME_CLK_AES_LOCK) 19568c2ecf20Sopenharmony_ci idx = SND_RME_CLOCK_LOCK; 19578c2ecf20Sopenharmony_ci break; 19588c2ecf20Sopenharmony_ci case SND_RME_DOMAIN_SPDIF: /* SPDIF */ 19598c2ecf20Sopenharmony_ci if (status1 & SND_RME_CLK_SPDIF_SYNC) 19608c2ecf20Sopenharmony_ci idx = SND_RME_CLOCK_SYNC; 19618c2ecf20Sopenharmony_ci else if (status1 & SND_RME_CLK_SPDIF_LOCK) 19628c2ecf20Sopenharmony_ci idx = SND_RME_CLOCK_LOCK; 19638c2ecf20Sopenharmony_ci break; 19648c2ecf20Sopenharmony_ci default: 19658c2ecf20Sopenharmony_ci return -EINVAL; 19668c2ecf20Sopenharmony_ci } 19678c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = idx; 19688c2ecf20Sopenharmony_ci return 0; 19698c2ecf20Sopenharmony_ci} 19708c2ecf20Sopenharmony_ci 19718c2ecf20Sopenharmony_cistatic int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol, 19728c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 19738c2ecf20Sopenharmony_ci{ 19748c2ecf20Sopenharmony_ci u32 status1; 19758c2ecf20Sopenharmony_ci int err; 19768c2ecf20Sopenharmony_ci 19778c2ecf20Sopenharmony_ci err = snd_rme_get_status1(kcontrol, &status1); 19788c2ecf20Sopenharmony_ci if (err < 0) 19798c2ecf20Sopenharmony_ci return err; 19808c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_IF(status1); 19818c2ecf20Sopenharmony_ci return 0; 19828c2ecf20Sopenharmony_ci} 19838c2ecf20Sopenharmony_ci 19848c2ecf20Sopenharmony_cistatic int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol, 19858c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 19868c2ecf20Sopenharmony_ci{ 19878c2ecf20Sopenharmony_ci u32 status1; 19888c2ecf20Sopenharmony_ci int err; 19898c2ecf20Sopenharmony_ci 19908c2ecf20Sopenharmony_ci err = snd_rme_get_status1(kcontrol, &status1); 19918c2ecf20Sopenharmony_ci if (err < 0) 19928c2ecf20Sopenharmony_ci return err; 19938c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_FORMAT(status1); 19948c2ecf20Sopenharmony_ci return 0; 19958c2ecf20Sopenharmony_ci} 19968c2ecf20Sopenharmony_ci 19978c2ecf20Sopenharmony_cistatic int snd_rme_sync_source_get(struct snd_kcontrol *kcontrol, 19988c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 19998c2ecf20Sopenharmony_ci{ 20008c2ecf20Sopenharmony_ci u32 status1; 20018c2ecf20Sopenharmony_ci int err; 20028c2ecf20Sopenharmony_ci 20038c2ecf20Sopenharmony_ci err = snd_rme_get_status1(kcontrol, &status1); 20048c2ecf20Sopenharmony_ci if (err < 0) 20058c2ecf20Sopenharmony_ci return err; 20068c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = SND_RME_CLK_SYNC(status1); 20078c2ecf20Sopenharmony_ci return 0; 20088c2ecf20Sopenharmony_ci} 20098c2ecf20Sopenharmony_ci 20108c2ecf20Sopenharmony_cistatic int snd_rme_current_freq_get(struct snd_kcontrol *kcontrol, 20118c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 20128c2ecf20Sopenharmony_ci{ 20138c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); 20148c2ecf20Sopenharmony_ci struct snd_usb_audio *chip = list->mixer->chip; 20158c2ecf20Sopenharmony_ci u32 status1; 20168c2ecf20Sopenharmony_ci const u64 num = 104857600000000ULL; 20178c2ecf20Sopenharmony_ci u32 den; 20188c2ecf20Sopenharmony_ci unsigned int freq; 20198c2ecf20Sopenharmony_ci int err; 20208c2ecf20Sopenharmony_ci 20218c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(chip); 20228c2ecf20Sopenharmony_ci if (err < 0) 20238c2ecf20Sopenharmony_ci return err; 20248c2ecf20Sopenharmony_ci err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, &status1); 20258c2ecf20Sopenharmony_ci if (err < 0) 20268c2ecf20Sopenharmony_ci goto end; 20278c2ecf20Sopenharmony_ci err = snd_rme_read_value(chip, SND_RME_GET_CURRENT_FREQ, &den); 20288c2ecf20Sopenharmony_ci if (err < 0) 20298c2ecf20Sopenharmony_ci goto end; 20308c2ecf20Sopenharmony_ci freq = (den == 0) ? 0 : div64_u64(num, den); 20318c2ecf20Sopenharmony_ci freq <<= SND_RME_CLK_FREQMUL(status1); 20328c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = freq; 20338c2ecf20Sopenharmony_ci 20348c2ecf20Sopenharmony_ciend: 20358c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(chip); 20368c2ecf20Sopenharmony_ci return err; 20378c2ecf20Sopenharmony_ci} 20388c2ecf20Sopenharmony_ci 20398c2ecf20Sopenharmony_cistatic int snd_rme_rate_info(struct snd_kcontrol *kcontrol, 20408c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 20418c2ecf20Sopenharmony_ci{ 20428c2ecf20Sopenharmony_ci uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 20438c2ecf20Sopenharmony_ci uinfo->count = 1; 20448c2ecf20Sopenharmony_ci switch (kcontrol->private_value) { 20458c2ecf20Sopenharmony_ci case SND_RME_DOMAIN_SYSTEM: 20468c2ecf20Sopenharmony_ci uinfo->value.integer.min = 32000; 20478c2ecf20Sopenharmony_ci uinfo->value.integer.max = 800000; 20488c2ecf20Sopenharmony_ci break; 20498c2ecf20Sopenharmony_ci case SND_RME_DOMAIN_AES: 20508c2ecf20Sopenharmony_ci case SND_RME_DOMAIN_SPDIF: 20518c2ecf20Sopenharmony_ci default: 20528c2ecf20Sopenharmony_ci uinfo->value.integer.min = 0; 20538c2ecf20Sopenharmony_ci uinfo->value.integer.max = 200000; 20548c2ecf20Sopenharmony_ci } 20558c2ecf20Sopenharmony_ci uinfo->value.integer.step = 0; 20568c2ecf20Sopenharmony_ci return 0; 20578c2ecf20Sopenharmony_ci} 20588c2ecf20Sopenharmony_ci 20598c2ecf20Sopenharmony_cistatic int snd_rme_sync_state_info(struct snd_kcontrol *kcontrol, 20608c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 20618c2ecf20Sopenharmony_ci{ 20628c2ecf20Sopenharmony_ci static const char *const sync_states[] = { 20638c2ecf20Sopenharmony_ci "No Lock", "Lock", "Sync" 20648c2ecf20Sopenharmony_ci }; 20658c2ecf20Sopenharmony_ci 20668c2ecf20Sopenharmony_ci return snd_ctl_enum_info(uinfo, 1, 20678c2ecf20Sopenharmony_ci ARRAY_SIZE(sync_states), sync_states); 20688c2ecf20Sopenharmony_ci} 20698c2ecf20Sopenharmony_ci 20708c2ecf20Sopenharmony_cistatic int snd_rme_spdif_if_info(struct snd_kcontrol *kcontrol, 20718c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 20728c2ecf20Sopenharmony_ci{ 20738c2ecf20Sopenharmony_ci static const char *const spdif_if[] = { 20748c2ecf20Sopenharmony_ci "Coaxial", "Optical" 20758c2ecf20Sopenharmony_ci }; 20768c2ecf20Sopenharmony_ci 20778c2ecf20Sopenharmony_ci return snd_ctl_enum_info(uinfo, 1, 20788c2ecf20Sopenharmony_ci ARRAY_SIZE(spdif_if), spdif_if); 20798c2ecf20Sopenharmony_ci} 20808c2ecf20Sopenharmony_ci 20818c2ecf20Sopenharmony_cistatic int snd_rme_spdif_format_info(struct snd_kcontrol *kcontrol, 20828c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 20838c2ecf20Sopenharmony_ci{ 20848c2ecf20Sopenharmony_ci static const char *const optical_type[] = { 20858c2ecf20Sopenharmony_ci "Consumer", "Professional" 20868c2ecf20Sopenharmony_ci }; 20878c2ecf20Sopenharmony_ci 20888c2ecf20Sopenharmony_ci return snd_ctl_enum_info(uinfo, 1, 20898c2ecf20Sopenharmony_ci ARRAY_SIZE(optical_type), optical_type); 20908c2ecf20Sopenharmony_ci} 20918c2ecf20Sopenharmony_ci 20928c2ecf20Sopenharmony_cistatic int snd_rme_sync_source_info(struct snd_kcontrol *kcontrol, 20938c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 20948c2ecf20Sopenharmony_ci{ 20958c2ecf20Sopenharmony_ci static const char *const sync_sources[] = { 20968c2ecf20Sopenharmony_ci "Internal", "AES", "SPDIF", "Internal" 20978c2ecf20Sopenharmony_ci }; 20988c2ecf20Sopenharmony_ci 20998c2ecf20Sopenharmony_ci return snd_ctl_enum_info(uinfo, 1, 21008c2ecf20Sopenharmony_ci ARRAY_SIZE(sync_sources), sync_sources); 21018c2ecf20Sopenharmony_ci} 21028c2ecf20Sopenharmony_ci 21038c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_rme_controls[] = { 21048c2ecf20Sopenharmony_ci { 21058c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21068c2ecf20Sopenharmony_ci .name = "AES Rate", 21078c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 21088c2ecf20Sopenharmony_ci .info = snd_rme_rate_info, 21098c2ecf20Sopenharmony_ci .get = snd_rme_rate_get, 21108c2ecf20Sopenharmony_ci .private_value = SND_RME_DOMAIN_AES 21118c2ecf20Sopenharmony_ci }, 21128c2ecf20Sopenharmony_ci { 21138c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21148c2ecf20Sopenharmony_ci .name = "AES Sync", 21158c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 21168c2ecf20Sopenharmony_ci .info = snd_rme_sync_state_info, 21178c2ecf20Sopenharmony_ci .get = snd_rme_sync_state_get, 21188c2ecf20Sopenharmony_ci .private_value = SND_RME_DOMAIN_AES 21198c2ecf20Sopenharmony_ci }, 21208c2ecf20Sopenharmony_ci { 21218c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21228c2ecf20Sopenharmony_ci .name = "SPDIF Rate", 21238c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 21248c2ecf20Sopenharmony_ci .info = snd_rme_rate_info, 21258c2ecf20Sopenharmony_ci .get = snd_rme_rate_get, 21268c2ecf20Sopenharmony_ci .private_value = SND_RME_DOMAIN_SPDIF 21278c2ecf20Sopenharmony_ci }, 21288c2ecf20Sopenharmony_ci { 21298c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21308c2ecf20Sopenharmony_ci .name = "SPDIF Sync", 21318c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 21328c2ecf20Sopenharmony_ci .info = snd_rme_sync_state_info, 21338c2ecf20Sopenharmony_ci .get = snd_rme_sync_state_get, 21348c2ecf20Sopenharmony_ci .private_value = SND_RME_DOMAIN_SPDIF 21358c2ecf20Sopenharmony_ci }, 21368c2ecf20Sopenharmony_ci { 21378c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21388c2ecf20Sopenharmony_ci .name = "SPDIF Interface", 21398c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 21408c2ecf20Sopenharmony_ci .info = snd_rme_spdif_if_info, 21418c2ecf20Sopenharmony_ci .get = snd_rme_spdif_if_get, 21428c2ecf20Sopenharmony_ci }, 21438c2ecf20Sopenharmony_ci { 21448c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21458c2ecf20Sopenharmony_ci .name = "SPDIF Format", 21468c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 21478c2ecf20Sopenharmony_ci .info = snd_rme_spdif_format_info, 21488c2ecf20Sopenharmony_ci .get = snd_rme_spdif_format_get, 21498c2ecf20Sopenharmony_ci }, 21508c2ecf20Sopenharmony_ci { 21518c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21528c2ecf20Sopenharmony_ci .name = "Sync Source", 21538c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 21548c2ecf20Sopenharmony_ci .info = snd_rme_sync_source_info, 21558c2ecf20Sopenharmony_ci .get = snd_rme_sync_source_get 21568c2ecf20Sopenharmony_ci }, 21578c2ecf20Sopenharmony_ci { 21588c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21598c2ecf20Sopenharmony_ci .name = "System Rate", 21608c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 21618c2ecf20Sopenharmony_ci .info = snd_rme_rate_info, 21628c2ecf20Sopenharmony_ci .get = snd_rme_rate_get, 21638c2ecf20Sopenharmony_ci .private_value = SND_RME_DOMAIN_SYSTEM 21648c2ecf20Sopenharmony_ci }, 21658c2ecf20Sopenharmony_ci { 21668c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21678c2ecf20Sopenharmony_ci .name = "Current Frequency", 21688c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 21698c2ecf20Sopenharmony_ci .info = snd_rme_rate_info, 21708c2ecf20Sopenharmony_ci .get = snd_rme_current_freq_get 21718c2ecf20Sopenharmony_ci } 21728c2ecf20Sopenharmony_ci}; 21738c2ecf20Sopenharmony_ci 21748c2ecf20Sopenharmony_cistatic int snd_rme_controls_create(struct usb_mixer_interface *mixer) 21758c2ecf20Sopenharmony_ci{ 21768c2ecf20Sopenharmony_ci int err, i; 21778c2ecf20Sopenharmony_ci 21788c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(snd_rme_controls); ++i) { 21798c2ecf20Sopenharmony_ci err = add_single_ctl_with_resume(mixer, 0, 21808c2ecf20Sopenharmony_ci NULL, 21818c2ecf20Sopenharmony_ci &snd_rme_controls[i], 21828c2ecf20Sopenharmony_ci NULL); 21838c2ecf20Sopenharmony_ci if (err < 0) 21848c2ecf20Sopenharmony_ci return err; 21858c2ecf20Sopenharmony_ci } 21868c2ecf20Sopenharmony_ci 21878c2ecf20Sopenharmony_ci return 0; 21888c2ecf20Sopenharmony_ci} 21898c2ecf20Sopenharmony_ci 21908c2ecf20Sopenharmony_ci/* 21918c2ecf20Sopenharmony_ci * RME Babyface Pro (FS) 21928c2ecf20Sopenharmony_ci * 21938c2ecf20Sopenharmony_ci * These devices exposes a couple of DSP functions via request to EP0. 21948c2ecf20Sopenharmony_ci * Switches are available via control registers, while routing is controlled 21958c2ecf20Sopenharmony_ci * by controlling the volume on each possible crossing point. 21968c2ecf20Sopenharmony_ci * Volume control is linear, from -inf (dec. 0) to +6dB (dec. 65536) with 21978c2ecf20Sopenharmony_ci * 0dB being at dec. 32768. 21988c2ecf20Sopenharmony_ci */ 21998c2ecf20Sopenharmony_cienum { 22008c2ecf20Sopenharmony_ci SND_BBFPRO_CTL_REG1 = 0, 22018c2ecf20Sopenharmony_ci SND_BBFPRO_CTL_REG2 22028c2ecf20Sopenharmony_ci}; 22038c2ecf20Sopenharmony_ci 22048c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_REG_MASK 1 22058c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_IDX_MASK 0xff 22068c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_IDX_SHIFT 1 22078c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_VAL_MASK 1 22088c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_VAL_SHIFT 9 22098c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_REG1_CLK_MASTER 0 22108c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_REG1_CLK_OPTICAL 1 22118c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_REG1_SPDIF_PRO 7 22128c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_REG1_SPDIF_EMPH 8 22138c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_REG1_SPDIF_OPTICAL 10 22148c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_REG2_48V_AN1 0 22158c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_REG2_48V_AN2 1 22168c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_REG2_SENS_IN3 2 22178c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_REG2_SENS_IN4 3 22188c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_REG2_PAD_AN1 4 22198c2ecf20Sopenharmony_ci#define SND_BBFPRO_CTL_REG2_PAD_AN2 5 22208c2ecf20Sopenharmony_ci 22218c2ecf20Sopenharmony_ci#define SND_BBFPRO_MIXER_IDX_MASK 0x1ff 22228c2ecf20Sopenharmony_ci#define SND_BBFPRO_MIXER_VAL_MASK 0x3ffff 22238c2ecf20Sopenharmony_ci#define SND_BBFPRO_MIXER_VAL_SHIFT 9 22248c2ecf20Sopenharmony_ci#define SND_BBFPRO_MIXER_VAL_MIN 0 // -inf 22258c2ecf20Sopenharmony_ci#define SND_BBFPRO_MIXER_VAL_MAX 65536 // +6dB 22268c2ecf20Sopenharmony_ci 22278c2ecf20Sopenharmony_ci#define SND_BBFPRO_USBREQ_CTL_REG1 0x10 22288c2ecf20Sopenharmony_ci#define SND_BBFPRO_USBREQ_CTL_REG2 0x17 22298c2ecf20Sopenharmony_ci#define SND_BBFPRO_USBREQ_MIXER 0x12 22308c2ecf20Sopenharmony_ci 22318c2ecf20Sopenharmony_cistatic int snd_bbfpro_ctl_update(struct usb_mixer_interface *mixer, u8 reg, 22328c2ecf20Sopenharmony_ci u8 index, u8 value) 22338c2ecf20Sopenharmony_ci{ 22348c2ecf20Sopenharmony_ci int err; 22358c2ecf20Sopenharmony_ci u16 usb_req, usb_idx, usb_val; 22368c2ecf20Sopenharmony_ci struct snd_usb_audio *chip = mixer->chip; 22378c2ecf20Sopenharmony_ci 22388c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(chip); 22398c2ecf20Sopenharmony_ci if (err < 0) 22408c2ecf20Sopenharmony_ci return err; 22418c2ecf20Sopenharmony_ci 22428c2ecf20Sopenharmony_ci if (reg == SND_BBFPRO_CTL_REG1) { 22438c2ecf20Sopenharmony_ci usb_req = SND_BBFPRO_USBREQ_CTL_REG1; 22448c2ecf20Sopenharmony_ci if (index == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) { 22458c2ecf20Sopenharmony_ci usb_idx = 3; 22468c2ecf20Sopenharmony_ci usb_val = value ? 3 : 0; 22478c2ecf20Sopenharmony_ci } else { 22488c2ecf20Sopenharmony_ci usb_idx = 1 << index; 22498c2ecf20Sopenharmony_ci usb_val = value ? usb_idx : 0; 22508c2ecf20Sopenharmony_ci } 22518c2ecf20Sopenharmony_ci } else { 22528c2ecf20Sopenharmony_ci usb_req = SND_BBFPRO_USBREQ_CTL_REG2; 22538c2ecf20Sopenharmony_ci usb_idx = 1 << index; 22548c2ecf20Sopenharmony_ci usb_val = value ? usb_idx : 0; 22558c2ecf20Sopenharmony_ci } 22568c2ecf20Sopenharmony_ci 22578c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 22588c2ecf20Sopenharmony_ci usb_sndctrlpipe(chip->dev, 0), usb_req, 22598c2ecf20Sopenharmony_ci USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 22608c2ecf20Sopenharmony_ci usb_val, usb_idx, NULL, 0); 22618c2ecf20Sopenharmony_ci 22628c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(chip); 22638c2ecf20Sopenharmony_ci return err; 22648c2ecf20Sopenharmony_ci} 22658c2ecf20Sopenharmony_ci 22668c2ecf20Sopenharmony_cistatic int snd_bbfpro_ctl_get(struct snd_kcontrol *kcontrol, 22678c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 22688c2ecf20Sopenharmony_ci{ 22698c2ecf20Sopenharmony_ci u8 reg, idx, val; 22708c2ecf20Sopenharmony_ci int pv; 22718c2ecf20Sopenharmony_ci 22728c2ecf20Sopenharmony_ci pv = kcontrol->private_value; 22738c2ecf20Sopenharmony_ci reg = pv & SND_BBFPRO_CTL_REG_MASK; 22748c2ecf20Sopenharmony_ci idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK; 22758c2ecf20Sopenharmony_ci val = kcontrol->private_value >> SND_BBFPRO_CTL_VAL_SHIFT; 22768c2ecf20Sopenharmony_ci 22778c2ecf20Sopenharmony_ci if ((reg == SND_BBFPRO_CTL_REG1 && 22788c2ecf20Sopenharmony_ci idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) || 22798c2ecf20Sopenharmony_ci (reg == SND_BBFPRO_CTL_REG2 && 22808c2ecf20Sopenharmony_ci (idx == SND_BBFPRO_CTL_REG2_SENS_IN3 || 22818c2ecf20Sopenharmony_ci idx == SND_BBFPRO_CTL_REG2_SENS_IN4))) { 22828c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = val; 22838c2ecf20Sopenharmony_ci } else { 22848c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = val; 22858c2ecf20Sopenharmony_ci } 22868c2ecf20Sopenharmony_ci return 0; 22878c2ecf20Sopenharmony_ci} 22888c2ecf20Sopenharmony_ci 22898c2ecf20Sopenharmony_cistatic int snd_bbfpro_ctl_info(struct snd_kcontrol *kcontrol, 22908c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 22918c2ecf20Sopenharmony_ci{ 22928c2ecf20Sopenharmony_ci u8 reg, idx; 22938c2ecf20Sopenharmony_ci int pv; 22948c2ecf20Sopenharmony_ci 22958c2ecf20Sopenharmony_ci pv = kcontrol->private_value; 22968c2ecf20Sopenharmony_ci reg = pv & SND_BBFPRO_CTL_REG_MASK; 22978c2ecf20Sopenharmony_ci idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK; 22988c2ecf20Sopenharmony_ci 22998c2ecf20Sopenharmony_ci if (reg == SND_BBFPRO_CTL_REG1 && 23008c2ecf20Sopenharmony_ci idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) { 23018c2ecf20Sopenharmony_ci static const char * const texts[2] = { 23028c2ecf20Sopenharmony_ci "AutoSync", 23038c2ecf20Sopenharmony_ci "Internal" 23048c2ecf20Sopenharmony_ci }; 23058c2ecf20Sopenharmony_ci return snd_ctl_enum_info(uinfo, 1, 2, texts); 23068c2ecf20Sopenharmony_ci } else if (reg == SND_BBFPRO_CTL_REG2 && 23078c2ecf20Sopenharmony_ci (idx == SND_BBFPRO_CTL_REG2_SENS_IN3 || 23088c2ecf20Sopenharmony_ci idx == SND_BBFPRO_CTL_REG2_SENS_IN4)) { 23098c2ecf20Sopenharmony_ci static const char * const texts[2] = { 23108c2ecf20Sopenharmony_ci "-10dBV", 23118c2ecf20Sopenharmony_ci "+4dBu" 23128c2ecf20Sopenharmony_ci }; 23138c2ecf20Sopenharmony_ci return snd_ctl_enum_info(uinfo, 1, 2, texts); 23148c2ecf20Sopenharmony_ci } 23158c2ecf20Sopenharmony_ci 23168c2ecf20Sopenharmony_ci uinfo->count = 1; 23178c2ecf20Sopenharmony_ci uinfo->value.integer.min = 0; 23188c2ecf20Sopenharmony_ci uinfo->value.integer.max = 1; 23198c2ecf20Sopenharmony_ci uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 23208c2ecf20Sopenharmony_ci return 0; 23218c2ecf20Sopenharmony_ci} 23228c2ecf20Sopenharmony_ci 23238c2ecf20Sopenharmony_cistatic int snd_bbfpro_ctl_put(struct snd_kcontrol *kcontrol, 23248c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 23258c2ecf20Sopenharmony_ci{ 23268c2ecf20Sopenharmony_ci int err; 23278c2ecf20Sopenharmony_ci u8 reg, idx; 23288c2ecf20Sopenharmony_ci int old_value, pv, val; 23298c2ecf20Sopenharmony_ci 23308c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); 23318c2ecf20Sopenharmony_ci struct usb_mixer_interface *mixer = list->mixer; 23328c2ecf20Sopenharmony_ci 23338c2ecf20Sopenharmony_ci pv = kcontrol->private_value; 23348c2ecf20Sopenharmony_ci reg = pv & SND_BBFPRO_CTL_REG_MASK; 23358c2ecf20Sopenharmony_ci idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK; 23368c2ecf20Sopenharmony_ci old_value = (pv >> SND_BBFPRO_CTL_VAL_SHIFT) & SND_BBFPRO_CTL_VAL_MASK; 23378c2ecf20Sopenharmony_ci 23388c2ecf20Sopenharmony_ci if ((reg == SND_BBFPRO_CTL_REG1 && 23398c2ecf20Sopenharmony_ci idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) || 23408c2ecf20Sopenharmony_ci (reg == SND_BBFPRO_CTL_REG2 && 23418c2ecf20Sopenharmony_ci (idx == SND_BBFPRO_CTL_REG2_SENS_IN3 || 23428c2ecf20Sopenharmony_ci idx == SND_BBFPRO_CTL_REG2_SENS_IN4))) { 23438c2ecf20Sopenharmony_ci val = ucontrol->value.enumerated.item[0]; 23448c2ecf20Sopenharmony_ci } else { 23458c2ecf20Sopenharmony_ci val = ucontrol->value.integer.value[0]; 23468c2ecf20Sopenharmony_ci } 23478c2ecf20Sopenharmony_ci 23488c2ecf20Sopenharmony_ci if (val > 1) 23498c2ecf20Sopenharmony_ci return -EINVAL; 23508c2ecf20Sopenharmony_ci 23518c2ecf20Sopenharmony_ci if (val == old_value) 23528c2ecf20Sopenharmony_ci return 0; 23538c2ecf20Sopenharmony_ci 23548c2ecf20Sopenharmony_ci kcontrol->private_value = reg 23558c2ecf20Sopenharmony_ci | ((idx & SND_BBFPRO_CTL_IDX_MASK) << SND_BBFPRO_CTL_IDX_SHIFT) 23568c2ecf20Sopenharmony_ci | ((val & SND_BBFPRO_CTL_VAL_MASK) << SND_BBFPRO_CTL_VAL_SHIFT); 23578c2ecf20Sopenharmony_ci 23588c2ecf20Sopenharmony_ci err = snd_bbfpro_ctl_update(mixer, reg, idx, val); 23598c2ecf20Sopenharmony_ci return err < 0 ? err : 1; 23608c2ecf20Sopenharmony_ci} 23618c2ecf20Sopenharmony_ci 23628c2ecf20Sopenharmony_cistatic int snd_bbfpro_ctl_resume(struct usb_mixer_elem_list *list) 23638c2ecf20Sopenharmony_ci{ 23648c2ecf20Sopenharmony_ci u8 reg, idx; 23658c2ecf20Sopenharmony_ci int value, pv; 23668c2ecf20Sopenharmony_ci 23678c2ecf20Sopenharmony_ci pv = list->kctl->private_value; 23688c2ecf20Sopenharmony_ci reg = pv & SND_BBFPRO_CTL_REG_MASK; 23698c2ecf20Sopenharmony_ci idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK; 23708c2ecf20Sopenharmony_ci value = (pv >> SND_BBFPRO_CTL_VAL_SHIFT) & SND_BBFPRO_CTL_VAL_MASK; 23718c2ecf20Sopenharmony_ci 23728c2ecf20Sopenharmony_ci return snd_bbfpro_ctl_update(list->mixer, reg, idx, value); 23738c2ecf20Sopenharmony_ci} 23748c2ecf20Sopenharmony_ci 23758c2ecf20Sopenharmony_cistatic int snd_bbfpro_vol_update(struct usb_mixer_interface *mixer, u16 index, 23768c2ecf20Sopenharmony_ci u32 value) 23778c2ecf20Sopenharmony_ci{ 23788c2ecf20Sopenharmony_ci struct snd_usb_audio *chip = mixer->chip; 23798c2ecf20Sopenharmony_ci int err; 23808c2ecf20Sopenharmony_ci u16 idx; 23818c2ecf20Sopenharmony_ci u16 usb_idx, usb_val; 23828c2ecf20Sopenharmony_ci u32 v; 23838c2ecf20Sopenharmony_ci 23848c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(chip); 23858c2ecf20Sopenharmony_ci if (err < 0) 23868c2ecf20Sopenharmony_ci return err; 23878c2ecf20Sopenharmony_ci 23888c2ecf20Sopenharmony_ci idx = index & SND_BBFPRO_MIXER_IDX_MASK; 23898c2ecf20Sopenharmony_ci // 18 bit linear volume, split so 2 bits end up in index. 23908c2ecf20Sopenharmony_ci v = value & SND_BBFPRO_MIXER_VAL_MASK; 23918c2ecf20Sopenharmony_ci usb_idx = idx | (v & 0x3) << 14; 23928c2ecf20Sopenharmony_ci usb_val = (v >> 2) & 0xffff; 23938c2ecf20Sopenharmony_ci 23948c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg(chip->dev, 23958c2ecf20Sopenharmony_ci usb_sndctrlpipe(chip->dev, 0), 23968c2ecf20Sopenharmony_ci SND_BBFPRO_USBREQ_MIXER, 23978c2ecf20Sopenharmony_ci USB_DIR_OUT | USB_TYPE_VENDOR | 23988c2ecf20Sopenharmony_ci USB_RECIP_DEVICE, 23998c2ecf20Sopenharmony_ci usb_val, usb_idx, NULL, 0); 24008c2ecf20Sopenharmony_ci 24018c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(chip); 24028c2ecf20Sopenharmony_ci return err; 24038c2ecf20Sopenharmony_ci} 24048c2ecf20Sopenharmony_ci 24058c2ecf20Sopenharmony_cistatic int snd_bbfpro_vol_get(struct snd_kcontrol *kcontrol, 24068c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 24078c2ecf20Sopenharmony_ci{ 24088c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = 24098c2ecf20Sopenharmony_ci kcontrol->private_value >> SND_BBFPRO_MIXER_VAL_SHIFT; 24108c2ecf20Sopenharmony_ci return 0; 24118c2ecf20Sopenharmony_ci} 24128c2ecf20Sopenharmony_ci 24138c2ecf20Sopenharmony_cistatic int snd_bbfpro_vol_info(struct snd_kcontrol *kcontrol, 24148c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 24158c2ecf20Sopenharmony_ci{ 24168c2ecf20Sopenharmony_ci uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 24178c2ecf20Sopenharmony_ci uinfo->count = 1; 24188c2ecf20Sopenharmony_ci uinfo->value.integer.min = SND_BBFPRO_MIXER_VAL_MIN; 24198c2ecf20Sopenharmony_ci uinfo->value.integer.max = SND_BBFPRO_MIXER_VAL_MAX; 24208c2ecf20Sopenharmony_ci return 0; 24218c2ecf20Sopenharmony_ci} 24228c2ecf20Sopenharmony_ci 24238c2ecf20Sopenharmony_cistatic int snd_bbfpro_vol_put(struct snd_kcontrol *kcontrol, 24248c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 24258c2ecf20Sopenharmony_ci{ 24268c2ecf20Sopenharmony_ci int err; 24278c2ecf20Sopenharmony_ci u16 idx; 24288c2ecf20Sopenharmony_ci u32 new_val, old_value, uvalue; 24298c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); 24308c2ecf20Sopenharmony_ci struct usb_mixer_interface *mixer = list->mixer; 24318c2ecf20Sopenharmony_ci 24328c2ecf20Sopenharmony_ci uvalue = ucontrol->value.integer.value[0]; 24338c2ecf20Sopenharmony_ci idx = kcontrol->private_value & SND_BBFPRO_MIXER_IDX_MASK; 24348c2ecf20Sopenharmony_ci old_value = kcontrol->private_value >> SND_BBFPRO_MIXER_VAL_SHIFT; 24358c2ecf20Sopenharmony_ci 24368c2ecf20Sopenharmony_ci if (uvalue > SND_BBFPRO_MIXER_VAL_MAX) 24378c2ecf20Sopenharmony_ci return -EINVAL; 24388c2ecf20Sopenharmony_ci 24398c2ecf20Sopenharmony_ci if (uvalue == old_value) 24408c2ecf20Sopenharmony_ci return 0; 24418c2ecf20Sopenharmony_ci 24428c2ecf20Sopenharmony_ci new_val = uvalue & SND_BBFPRO_MIXER_VAL_MASK; 24438c2ecf20Sopenharmony_ci 24448c2ecf20Sopenharmony_ci kcontrol->private_value = idx 24458c2ecf20Sopenharmony_ci | (new_val << SND_BBFPRO_MIXER_VAL_SHIFT); 24468c2ecf20Sopenharmony_ci 24478c2ecf20Sopenharmony_ci err = snd_bbfpro_vol_update(mixer, idx, new_val); 24488c2ecf20Sopenharmony_ci return err < 0 ? err : 1; 24498c2ecf20Sopenharmony_ci} 24508c2ecf20Sopenharmony_ci 24518c2ecf20Sopenharmony_cistatic int snd_bbfpro_vol_resume(struct usb_mixer_elem_list *list) 24528c2ecf20Sopenharmony_ci{ 24538c2ecf20Sopenharmony_ci int pv = list->kctl->private_value; 24548c2ecf20Sopenharmony_ci u16 idx = pv & SND_BBFPRO_MIXER_IDX_MASK; 24558c2ecf20Sopenharmony_ci u32 val = (pv >> SND_BBFPRO_MIXER_VAL_SHIFT) 24568c2ecf20Sopenharmony_ci & SND_BBFPRO_MIXER_VAL_MASK; 24578c2ecf20Sopenharmony_ci return snd_bbfpro_vol_update(list->mixer, idx, val); 24588c2ecf20Sopenharmony_ci} 24598c2ecf20Sopenharmony_ci 24608c2ecf20Sopenharmony_ci// Predfine elements 24618c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_bbfpro_ctl_control = { 24628c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 24638c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 24648c2ecf20Sopenharmony_ci .index = 0, 24658c2ecf20Sopenharmony_ci .info = snd_bbfpro_ctl_info, 24668c2ecf20Sopenharmony_ci .get = snd_bbfpro_ctl_get, 24678c2ecf20Sopenharmony_ci .put = snd_bbfpro_ctl_put 24688c2ecf20Sopenharmony_ci}; 24698c2ecf20Sopenharmony_ci 24708c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_bbfpro_vol_control = { 24718c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 24728c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 24738c2ecf20Sopenharmony_ci .index = 0, 24748c2ecf20Sopenharmony_ci .info = snd_bbfpro_vol_info, 24758c2ecf20Sopenharmony_ci .get = snd_bbfpro_vol_get, 24768c2ecf20Sopenharmony_ci .put = snd_bbfpro_vol_put 24778c2ecf20Sopenharmony_ci}; 24788c2ecf20Sopenharmony_ci 24798c2ecf20Sopenharmony_cistatic int snd_bbfpro_ctl_add(struct usb_mixer_interface *mixer, u8 reg, 24808c2ecf20Sopenharmony_ci u8 index, char *name) 24818c2ecf20Sopenharmony_ci{ 24828c2ecf20Sopenharmony_ci struct snd_kcontrol_new knew = snd_bbfpro_ctl_control; 24838c2ecf20Sopenharmony_ci 24848c2ecf20Sopenharmony_ci knew.name = name; 24858c2ecf20Sopenharmony_ci knew.private_value = (reg & SND_BBFPRO_CTL_REG_MASK) 24868c2ecf20Sopenharmony_ci | ((index & SND_BBFPRO_CTL_IDX_MASK) 24878c2ecf20Sopenharmony_ci << SND_BBFPRO_CTL_IDX_SHIFT); 24888c2ecf20Sopenharmony_ci 24898c2ecf20Sopenharmony_ci return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_ctl_resume, 24908c2ecf20Sopenharmony_ci &knew, NULL); 24918c2ecf20Sopenharmony_ci} 24928c2ecf20Sopenharmony_ci 24938c2ecf20Sopenharmony_cistatic int snd_bbfpro_vol_add(struct usb_mixer_interface *mixer, u16 index, 24948c2ecf20Sopenharmony_ci char *name) 24958c2ecf20Sopenharmony_ci{ 24968c2ecf20Sopenharmony_ci struct snd_kcontrol_new knew = snd_bbfpro_vol_control; 24978c2ecf20Sopenharmony_ci 24988c2ecf20Sopenharmony_ci knew.name = name; 24998c2ecf20Sopenharmony_ci knew.private_value = index & SND_BBFPRO_MIXER_IDX_MASK; 25008c2ecf20Sopenharmony_ci 25018c2ecf20Sopenharmony_ci return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_vol_resume, 25028c2ecf20Sopenharmony_ci &knew, NULL); 25038c2ecf20Sopenharmony_ci} 25048c2ecf20Sopenharmony_ci 25058c2ecf20Sopenharmony_cistatic int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer) 25068c2ecf20Sopenharmony_ci{ 25078c2ecf20Sopenharmony_ci int err, i, o; 25088c2ecf20Sopenharmony_ci char name[48]; 25098c2ecf20Sopenharmony_ci 25108c2ecf20Sopenharmony_ci static const char * const input[] = { 25118c2ecf20Sopenharmony_ci "AN1", "AN2", "IN3", "IN4", "AS1", "AS2", "ADAT3", 25128c2ecf20Sopenharmony_ci "ADAT4", "ADAT5", "ADAT6", "ADAT7", "ADAT8"}; 25138c2ecf20Sopenharmony_ci 25148c2ecf20Sopenharmony_ci static const char * const output[] = { 25158c2ecf20Sopenharmony_ci "AN1", "AN2", "PH3", "PH4", "AS1", "AS2", "ADAT3", "ADAT4", 25168c2ecf20Sopenharmony_ci "ADAT5", "ADAT6", "ADAT7", "ADAT8"}; 25178c2ecf20Sopenharmony_ci 25188c2ecf20Sopenharmony_ci for (o = 0 ; o < 12 ; ++o) { 25198c2ecf20Sopenharmony_ci for (i = 0 ; i < 12 ; ++i) { 25208c2ecf20Sopenharmony_ci // Line routing 25218c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), 25228c2ecf20Sopenharmony_ci "%s-%s-%s Playback Volume", 25238c2ecf20Sopenharmony_ci (i < 2 ? "Mic" : "Line"), 25248c2ecf20Sopenharmony_ci input[i], output[o]); 25258c2ecf20Sopenharmony_ci err = snd_bbfpro_vol_add(mixer, (26 * o + i), name); 25268c2ecf20Sopenharmony_ci if (err < 0) 25278c2ecf20Sopenharmony_ci return err; 25288c2ecf20Sopenharmony_ci 25298c2ecf20Sopenharmony_ci // PCM routing... yes, it is output remapping 25308c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), 25318c2ecf20Sopenharmony_ci "PCM-%s-%s Playback Volume", 25328c2ecf20Sopenharmony_ci output[i], output[o]); 25338c2ecf20Sopenharmony_ci err = snd_bbfpro_vol_add(mixer, (26 * o + 12 + i), 25348c2ecf20Sopenharmony_ci name); 25358c2ecf20Sopenharmony_ci if (err < 0) 25368c2ecf20Sopenharmony_ci return err; 25378c2ecf20Sopenharmony_ci } 25388c2ecf20Sopenharmony_ci } 25398c2ecf20Sopenharmony_ci 25408c2ecf20Sopenharmony_ci // Control Reg 1 25418c2ecf20Sopenharmony_ci err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1, 25428c2ecf20Sopenharmony_ci SND_BBFPRO_CTL_REG1_CLK_OPTICAL, 25438c2ecf20Sopenharmony_ci "Sample Clock Source"); 25448c2ecf20Sopenharmony_ci if (err < 0) 25458c2ecf20Sopenharmony_ci return err; 25468c2ecf20Sopenharmony_ci 25478c2ecf20Sopenharmony_ci err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1, 25488c2ecf20Sopenharmony_ci SND_BBFPRO_CTL_REG1_SPDIF_PRO, 25498c2ecf20Sopenharmony_ci "IEC958 Pro Mask"); 25508c2ecf20Sopenharmony_ci if (err < 0) 25518c2ecf20Sopenharmony_ci return err; 25528c2ecf20Sopenharmony_ci 25538c2ecf20Sopenharmony_ci err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1, 25548c2ecf20Sopenharmony_ci SND_BBFPRO_CTL_REG1_SPDIF_EMPH, 25558c2ecf20Sopenharmony_ci "IEC958 Emphasis"); 25568c2ecf20Sopenharmony_ci if (err < 0) 25578c2ecf20Sopenharmony_ci return err; 25588c2ecf20Sopenharmony_ci 25598c2ecf20Sopenharmony_ci err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1, 25608c2ecf20Sopenharmony_ci SND_BBFPRO_CTL_REG1_SPDIF_OPTICAL, 25618c2ecf20Sopenharmony_ci "IEC958 Switch"); 25628c2ecf20Sopenharmony_ci if (err < 0) 25638c2ecf20Sopenharmony_ci return err; 25648c2ecf20Sopenharmony_ci 25658c2ecf20Sopenharmony_ci // Control Reg 2 25668c2ecf20Sopenharmony_ci err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, 25678c2ecf20Sopenharmony_ci SND_BBFPRO_CTL_REG2_48V_AN1, 25688c2ecf20Sopenharmony_ci "Mic-AN1 48V"); 25698c2ecf20Sopenharmony_ci if (err < 0) 25708c2ecf20Sopenharmony_ci return err; 25718c2ecf20Sopenharmony_ci 25728c2ecf20Sopenharmony_ci err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, 25738c2ecf20Sopenharmony_ci SND_BBFPRO_CTL_REG2_48V_AN2, 25748c2ecf20Sopenharmony_ci "Mic-AN2 48V"); 25758c2ecf20Sopenharmony_ci if (err < 0) 25768c2ecf20Sopenharmony_ci return err; 25778c2ecf20Sopenharmony_ci 25788c2ecf20Sopenharmony_ci err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, 25798c2ecf20Sopenharmony_ci SND_BBFPRO_CTL_REG2_SENS_IN3, 25808c2ecf20Sopenharmony_ci "Line-IN3 Sens."); 25818c2ecf20Sopenharmony_ci if (err < 0) 25828c2ecf20Sopenharmony_ci return err; 25838c2ecf20Sopenharmony_ci 25848c2ecf20Sopenharmony_ci err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, 25858c2ecf20Sopenharmony_ci SND_BBFPRO_CTL_REG2_SENS_IN4, 25868c2ecf20Sopenharmony_ci "Line-IN4 Sens."); 25878c2ecf20Sopenharmony_ci if (err < 0) 25888c2ecf20Sopenharmony_ci return err; 25898c2ecf20Sopenharmony_ci 25908c2ecf20Sopenharmony_ci err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, 25918c2ecf20Sopenharmony_ci SND_BBFPRO_CTL_REG2_PAD_AN1, 25928c2ecf20Sopenharmony_ci "Mic-AN1 PAD"); 25938c2ecf20Sopenharmony_ci if (err < 0) 25948c2ecf20Sopenharmony_ci return err; 25958c2ecf20Sopenharmony_ci 25968c2ecf20Sopenharmony_ci err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, 25978c2ecf20Sopenharmony_ci SND_BBFPRO_CTL_REG2_PAD_AN2, 25988c2ecf20Sopenharmony_ci "Mic-AN2 PAD"); 25998c2ecf20Sopenharmony_ci if (err < 0) 26008c2ecf20Sopenharmony_ci return err; 26018c2ecf20Sopenharmony_ci 26028c2ecf20Sopenharmony_ci return 0; 26038c2ecf20Sopenharmony_ci} 26048c2ecf20Sopenharmony_ci 26058c2ecf20Sopenharmony_ci/* 26068c2ecf20Sopenharmony_ci * Pioneer DJ DJM Mixers 26078c2ecf20Sopenharmony_ci * 26088c2ecf20Sopenharmony_ci * These devices generally have options for soft-switching the playback and 26098c2ecf20Sopenharmony_ci * capture sources in addition to the recording level. Although different 26108c2ecf20Sopenharmony_ci * devices have different configurations, there seems to be canonical values 26118c2ecf20Sopenharmony_ci * for specific capture/playback types: See the definitions of these below. 26128c2ecf20Sopenharmony_ci * 26138c2ecf20Sopenharmony_ci * The wValue is masked with the stereo channel number. e.g. Setting Ch2 to 26148c2ecf20Sopenharmony_ci * capture phono would be 0x0203. Capture, playback and capture level have 26158c2ecf20Sopenharmony_ci * different wIndexes. 26168c2ecf20Sopenharmony_ci */ 26178c2ecf20Sopenharmony_ci 26188c2ecf20Sopenharmony_ci// Capture types 26198c2ecf20Sopenharmony_ci#define SND_DJM_CAP_LINE 0x00 26208c2ecf20Sopenharmony_ci#define SND_DJM_CAP_CDLINE 0x01 26218c2ecf20Sopenharmony_ci#define SND_DJM_CAP_DIGITAL 0x02 26228c2ecf20Sopenharmony_ci#define SND_DJM_CAP_PHONO 0x03 26238c2ecf20Sopenharmony_ci#define SND_DJM_CAP_PFADER 0x06 26248c2ecf20Sopenharmony_ci#define SND_DJM_CAP_XFADERA 0x07 26258c2ecf20Sopenharmony_ci#define SND_DJM_CAP_XFADERB 0x08 26268c2ecf20Sopenharmony_ci#define SND_DJM_CAP_MIC 0x09 26278c2ecf20Sopenharmony_ci#define SND_DJM_CAP_AUX 0x0d 26288c2ecf20Sopenharmony_ci#define SND_DJM_CAP_RECOUT 0x0a 26298c2ecf20Sopenharmony_ci#define SND_DJM_CAP_NONE 0x0f 26308c2ecf20Sopenharmony_ci#define SND_DJM_CAP_CH1PFADER 0x11 26318c2ecf20Sopenharmony_ci#define SND_DJM_CAP_CH2PFADER 0x12 26328c2ecf20Sopenharmony_ci#define SND_DJM_CAP_CH3PFADER 0x13 26338c2ecf20Sopenharmony_ci#define SND_DJM_CAP_CH4PFADER 0x14 26348c2ecf20Sopenharmony_ci 26358c2ecf20Sopenharmony_ci// Playback types 26368c2ecf20Sopenharmony_ci#define SND_DJM_PB_CH1 0x00 26378c2ecf20Sopenharmony_ci#define SND_DJM_PB_CH2 0x01 26388c2ecf20Sopenharmony_ci#define SND_DJM_PB_AUX 0x04 26398c2ecf20Sopenharmony_ci 26408c2ecf20Sopenharmony_ci#define SND_DJM_WINDEX_CAP 0x8002 26418c2ecf20Sopenharmony_ci#define SND_DJM_WINDEX_CAPLVL 0x8003 26428c2ecf20Sopenharmony_ci#define SND_DJM_WINDEX_PB 0x8016 26438c2ecf20Sopenharmony_ci 26448c2ecf20Sopenharmony_ci// kcontrol->private_value layout 26458c2ecf20Sopenharmony_ci#define SND_DJM_VALUE_MASK 0x0000ffff 26468c2ecf20Sopenharmony_ci#define SND_DJM_GROUP_MASK 0x00ff0000 26478c2ecf20Sopenharmony_ci#define SND_DJM_DEVICE_MASK 0xff000000 26488c2ecf20Sopenharmony_ci#define SND_DJM_GROUP_SHIFT 16 26498c2ecf20Sopenharmony_ci#define SND_DJM_DEVICE_SHIFT 24 26508c2ecf20Sopenharmony_ci 26518c2ecf20Sopenharmony_ci// device table index 26528c2ecf20Sopenharmony_ci#define SND_DJM_250MK2_IDX 0x0 26538c2ecf20Sopenharmony_ci#define SND_DJM_750_IDX 0x1 26548c2ecf20Sopenharmony_ci#define SND_DJM_900NXS2_IDX 0x2 26558c2ecf20Sopenharmony_ci 26568c2ecf20Sopenharmony_ci 26578c2ecf20Sopenharmony_ci#define SND_DJM_CTL(_name, suffix, _default_value, _windex) { \ 26588c2ecf20Sopenharmony_ci .name = _name, \ 26598c2ecf20Sopenharmony_ci .options = snd_djm_opts_##suffix, \ 26608c2ecf20Sopenharmony_ci .noptions = ARRAY_SIZE(snd_djm_opts_##suffix), \ 26618c2ecf20Sopenharmony_ci .default_value = _default_value, \ 26628c2ecf20Sopenharmony_ci .wIndex = _windex } 26638c2ecf20Sopenharmony_ci 26648c2ecf20Sopenharmony_ci#define SND_DJM_DEVICE(suffix) { \ 26658c2ecf20Sopenharmony_ci .controls = snd_djm_ctls_##suffix, \ 26668c2ecf20Sopenharmony_ci .ncontrols = ARRAY_SIZE(snd_djm_ctls_##suffix) } 26678c2ecf20Sopenharmony_ci 26688c2ecf20Sopenharmony_ci 26698c2ecf20Sopenharmony_cistruct snd_djm_device { 26708c2ecf20Sopenharmony_ci const char *name; 26718c2ecf20Sopenharmony_ci const struct snd_djm_ctl *controls; 26728c2ecf20Sopenharmony_ci size_t ncontrols; 26738c2ecf20Sopenharmony_ci}; 26748c2ecf20Sopenharmony_ci 26758c2ecf20Sopenharmony_cistruct snd_djm_ctl { 26768c2ecf20Sopenharmony_ci const char *name; 26778c2ecf20Sopenharmony_ci const u16 *options; 26788c2ecf20Sopenharmony_ci size_t noptions; 26798c2ecf20Sopenharmony_ci u16 default_value; 26808c2ecf20Sopenharmony_ci u16 wIndex; 26818c2ecf20Sopenharmony_ci}; 26828c2ecf20Sopenharmony_ci 26838c2ecf20Sopenharmony_cistatic const char *snd_djm_get_label_caplevel(u16 wvalue) 26848c2ecf20Sopenharmony_ci{ 26858c2ecf20Sopenharmony_ci switch (wvalue) { 26868c2ecf20Sopenharmony_ci case 0x0000: return "-19dB"; 26878c2ecf20Sopenharmony_ci case 0x0100: return "-15dB"; 26888c2ecf20Sopenharmony_ci case 0x0200: return "-10dB"; 26898c2ecf20Sopenharmony_ci case 0x0300: return "-5dB"; 26908c2ecf20Sopenharmony_ci default: return NULL; 26918c2ecf20Sopenharmony_ci } 26928c2ecf20Sopenharmony_ci}; 26938c2ecf20Sopenharmony_ci 26948c2ecf20Sopenharmony_cistatic const char *snd_djm_get_label_cap(u16 wvalue) 26958c2ecf20Sopenharmony_ci{ 26968c2ecf20Sopenharmony_ci switch (wvalue & 0x00ff) { 26978c2ecf20Sopenharmony_ci case SND_DJM_CAP_LINE: return "Control Tone LINE"; 26988c2ecf20Sopenharmony_ci case SND_DJM_CAP_CDLINE: return "Control Tone CD/LINE"; 26998c2ecf20Sopenharmony_ci case SND_DJM_CAP_DIGITAL: return "Control Tone DIGITAL"; 27008c2ecf20Sopenharmony_ci case SND_DJM_CAP_PHONO: return "Control Tone PHONO"; 27018c2ecf20Sopenharmony_ci case SND_DJM_CAP_PFADER: return "Post Fader"; 27028c2ecf20Sopenharmony_ci case SND_DJM_CAP_XFADERA: return "Cross Fader A"; 27038c2ecf20Sopenharmony_ci case SND_DJM_CAP_XFADERB: return "Cross Fader B"; 27048c2ecf20Sopenharmony_ci case SND_DJM_CAP_MIC: return "Mic"; 27058c2ecf20Sopenharmony_ci case SND_DJM_CAP_RECOUT: return "Rec Out"; 27068c2ecf20Sopenharmony_ci case SND_DJM_CAP_AUX: return "Aux"; 27078c2ecf20Sopenharmony_ci case SND_DJM_CAP_NONE: return "None"; 27088c2ecf20Sopenharmony_ci case SND_DJM_CAP_CH1PFADER: return "Post Fader Ch1"; 27098c2ecf20Sopenharmony_ci case SND_DJM_CAP_CH2PFADER: return "Post Fader Ch2"; 27108c2ecf20Sopenharmony_ci case SND_DJM_CAP_CH3PFADER: return "Post Fader Ch3"; 27118c2ecf20Sopenharmony_ci case SND_DJM_CAP_CH4PFADER: return "Post Fader Ch4"; 27128c2ecf20Sopenharmony_ci default: return NULL; 27138c2ecf20Sopenharmony_ci } 27148c2ecf20Sopenharmony_ci}; 27158c2ecf20Sopenharmony_ci 27168c2ecf20Sopenharmony_cistatic const char *snd_djm_get_label_pb(u16 wvalue) 27178c2ecf20Sopenharmony_ci{ 27188c2ecf20Sopenharmony_ci switch (wvalue & 0x00ff) { 27198c2ecf20Sopenharmony_ci case SND_DJM_PB_CH1: return "Ch1"; 27208c2ecf20Sopenharmony_ci case SND_DJM_PB_CH2: return "Ch2"; 27218c2ecf20Sopenharmony_ci case SND_DJM_PB_AUX: return "Aux"; 27228c2ecf20Sopenharmony_ci default: return NULL; 27238c2ecf20Sopenharmony_ci } 27248c2ecf20Sopenharmony_ci}; 27258c2ecf20Sopenharmony_ci 27268c2ecf20Sopenharmony_cistatic const char *snd_djm_get_label(u16 wvalue, u16 windex) 27278c2ecf20Sopenharmony_ci{ 27288c2ecf20Sopenharmony_ci switch (windex) { 27298c2ecf20Sopenharmony_ci case SND_DJM_WINDEX_CAPLVL: return snd_djm_get_label_caplevel(wvalue); 27308c2ecf20Sopenharmony_ci case SND_DJM_WINDEX_CAP: return snd_djm_get_label_cap(wvalue); 27318c2ecf20Sopenharmony_ci case SND_DJM_WINDEX_PB: return snd_djm_get_label_pb(wvalue); 27328c2ecf20Sopenharmony_ci default: return NULL; 27338c2ecf20Sopenharmony_ci } 27348c2ecf20Sopenharmony_ci}; 27358c2ecf20Sopenharmony_ci 27368c2ecf20Sopenharmony_ci 27378c2ecf20Sopenharmony_ci// DJM-250MK2 27388c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_cap_level[] = { 27398c2ecf20Sopenharmony_ci 0x0000, 0x0100, 0x0200, 0x0300 }; 27408c2ecf20Sopenharmony_ci 27418c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_250mk2_cap1[] = { 27428c2ecf20Sopenharmony_ci 0x0103, 0x0100, 0x0106, 0x0107, 0x0108, 0x0109, 0x010d, 0x010a }; 27438c2ecf20Sopenharmony_ci 27448c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_250mk2_cap2[] = { 27458c2ecf20Sopenharmony_ci 0x0203, 0x0200, 0x0206, 0x0207, 0x0208, 0x0209, 0x020d, 0x020a }; 27468c2ecf20Sopenharmony_ci 27478c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_250mk2_cap3[] = { 27488c2ecf20Sopenharmony_ci 0x030a, 0x0311, 0x0312, 0x0307, 0x0308, 0x0309, 0x030d }; 27498c2ecf20Sopenharmony_ci 27508c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_250mk2_pb1[] = { 0x0100, 0x0101, 0x0104 }; 27518c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_250mk2_pb2[] = { 0x0200, 0x0201, 0x0204 }; 27528c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_250mk2_pb3[] = { 0x0300, 0x0301, 0x0304 }; 27538c2ecf20Sopenharmony_ci 27548c2ecf20Sopenharmony_cistatic const struct snd_djm_ctl snd_djm_ctls_250mk2[] = { 27558c2ecf20Sopenharmony_ci SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL), 27568c2ecf20Sopenharmony_ci SND_DJM_CTL("Ch1 Input", 250mk2_cap1, 2, SND_DJM_WINDEX_CAP), 27578c2ecf20Sopenharmony_ci SND_DJM_CTL("Ch2 Input", 250mk2_cap2, 2, SND_DJM_WINDEX_CAP), 27588c2ecf20Sopenharmony_ci SND_DJM_CTL("Ch3 Input", 250mk2_cap3, 0, SND_DJM_WINDEX_CAP), 27598c2ecf20Sopenharmony_ci SND_DJM_CTL("Ch1 Output", 250mk2_pb1, 0, SND_DJM_WINDEX_PB), 27608c2ecf20Sopenharmony_ci SND_DJM_CTL("Ch2 Output", 250mk2_pb2, 1, SND_DJM_WINDEX_PB), 27618c2ecf20Sopenharmony_ci SND_DJM_CTL("Ch3 Output", 250mk2_pb3, 2, SND_DJM_WINDEX_PB) 27628c2ecf20Sopenharmony_ci}; 27638c2ecf20Sopenharmony_ci 27648c2ecf20Sopenharmony_ci 27658c2ecf20Sopenharmony_ci// DJM-750 27668c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_750_cap1[] = { 27678c2ecf20Sopenharmony_ci 0x0101, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a, 0x010f }; 27688c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_750_cap2[] = { 27698c2ecf20Sopenharmony_ci 0x0200, 0x0201, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a, 0x020f }; 27708c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_750_cap3[] = { 27718c2ecf20Sopenharmony_ci 0x0300, 0x0301, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a, 0x030f }; 27728c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_750_cap4[] = { 27738c2ecf20Sopenharmony_ci 0x0401, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040f }; 27748c2ecf20Sopenharmony_ci 27758c2ecf20Sopenharmony_cistatic const struct snd_djm_ctl snd_djm_ctls_750[] = { 27768c2ecf20Sopenharmony_ci SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL), 27778c2ecf20Sopenharmony_ci SND_DJM_CTL("Ch1 Input", 750_cap1, 2, SND_DJM_WINDEX_CAP), 27788c2ecf20Sopenharmony_ci SND_DJM_CTL("Ch2 Input", 750_cap2, 2, SND_DJM_WINDEX_CAP), 27798c2ecf20Sopenharmony_ci SND_DJM_CTL("Ch3 Input", 750_cap3, 0, SND_DJM_WINDEX_CAP), 27808c2ecf20Sopenharmony_ci SND_DJM_CTL("Ch4 Input", 750_cap4, 0, SND_DJM_WINDEX_CAP) 27818c2ecf20Sopenharmony_ci}; 27828c2ecf20Sopenharmony_ci 27838c2ecf20Sopenharmony_ci 27848c2ecf20Sopenharmony_ci// DJM-900NXS2 27858c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_900nxs2_cap1[] = { 27868c2ecf20Sopenharmony_ci 0x0100, 0x0102, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a }; 27878c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_900nxs2_cap2[] = { 27888c2ecf20Sopenharmony_ci 0x0200, 0x0202, 0x0203, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a }; 27898c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_900nxs2_cap3[] = { 27908c2ecf20Sopenharmony_ci 0x0300, 0x0302, 0x0303, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a }; 27918c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_900nxs2_cap4[] = { 27928c2ecf20Sopenharmony_ci 0x0400, 0x0402, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a }; 27938c2ecf20Sopenharmony_cistatic const u16 snd_djm_opts_900nxs2_cap5[] = { 27948c2ecf20Sopenharmony_ci 0x0507, 0x0508, 0x0509, 0x050a, 0x0511, 0x0512, 0x0513, 0x0514 }; 27958c2ecf20Sopenharmony_ci 27968c2ecf20Sopenharmony_cistatic const struct snd_djm_ctl snd_djm_ctls_900nxs2[] = { 27978c2ecf20Sopenharmony_ci SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL), 27988c2ecf20Sopenharmony_ci SND_DJM_CTL("Ch1 Input", 900nxs2_cap1, 2, SND_DJM_WINDEX_CAP), 27998c2ecf20Sopenharmony_ci SND_DJM_CTL("Ch2 Input", 900nxs2_cap2, 2, SND_DJM_WINDEX_CAP), 28008c2ecf20Sopenharmony_ci SND_DJM_CTL("Ch3 Input", 900nxs2_cap3, 2, SND_DJM_WINDEX_CAP), 28018c2ecf20Sopenharmony_ci SND_DJM_CTL("Ch4 Input", 900nxs2_cap4, 2, SND_DJM_WINDEX_CAP), 28028c2ecf20Sopenharmony_ci SND_DJM_CTL("Ch5 Input", 900nxs2_cap5, 3, SND_DJM_WINDEX_CAP) 28038c2ecf20Sopenharmony_ci}; 28048c2ecf20Sopenharmony_ci 28058c2ecf20Sopenharmony_ci 28068c2ecf20Sopenharmony_cistatic const struct snd_djm_device snd_djm_devices[] = { 28078c2ecf20Sopenharmony_ci SND_DJM_DEVICE(250mk2), 28088c2ecf20Sopenharmony_ci SND_DJM_DEVICE(750), 28098c2ecf20Sopenharmony_ci SND_DJM_DEVICE(900nxs2) 28108c2ecf20Sopenharmony_ci}; 28118c2ecf20Sopenharmony_ci 28128c2ecf20Sopenharmony_ci 28138c2ecf20Sopenharmony_cistatic int snd_djm_controls_info(struct snd_kcontrol *kctl, 28148c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *info) 28158c2ecf20Sopenharmony_ci{ 28168c2ecf20Sopenharmony_ci unsigned long private_value = kctl->private_value; 28178c2ecf20Sopenharmony_ci u8 device_idx = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT; 28188c2ecf20Sopenharmony_ci u8 ctl_idx = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT; 28198c2ecf20Sopenharmony_ci const struct snd_djm_device *device = &snd_djm_devices[device_idx]; 28208c2ecf20Sopenharmony_ci const char *name; 28218c2ecf20Sopenharmony_ci const struct snd_djm_ctl *ctl; 28228c2ecf20Sopenharmony_ci size_t noptions; 28238c2ecf20Sopenharmony_ci 28248c2ecf20Sopenharmony_ci if (ctl_idx >= device->ncontrols) 28258c2ecf20Sopenharmony_ci return -EINVAL; 28268c2ecf20Sopenharmony_ci 28278c2ecf20Sopenharmony_ci ctl = &device->controls[ctl_idx]; 28288c2ecf20Sopenharmony_ci noptions = ctl->noptions; 28298c2ecf20Sopenharmony_ci if (info->value.enumerated.item >= noptions) 28308c2ecf20Sopenharmony_ci info->value.enumerated.item = noptions - 1; 28318c2ecf20Sopenharmony_ci 28328c2ecf20Sopenharmony_ci name = snd_djm_get_label(ctl->options[info->value.enumerated.item], 28338c2ecf20Sopenharmony_ci ctl->wIndex); 28348c2ecf20Sopenharmony_ci if (!name) 28358c2ecf20Sopenharmony_ci return -EINVAL; 28368c2ecf20Sopenharmony_ci 28378c2ecf20Sopenharmony_ci strlcpy(info->value.enumerated.name, name, sizeof(info->value.enumerated.name)); 28388c2ecf20Sopenharmony_ci info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 28398c2ecf20Sopenharmony_ci info->count = 1; 28408c2ecf20Sopenharmony_ci info->value.enumerated.items = noptions; 28418c2ecf20Sopenharmony_ci return 0; 28428c2ecf20Sopenharmony_ci} 28438c2ecf20Sopenharmony_ci 28448c2ecf20Sopenharmony_cistatic int snd_djm_controls_update(struct usb_mixer_interface *mixer, 28458c2ecf20Sopenharmony_ci u8 device_idx, u8 group, u16 value) 28468c2ecf20Sopenharmony_ci{ 28478c2ecf20Sopenharmony_ci int err; 28488c2ecf20Sopenharmony_ci const struct snd_djm_device *device = &snd_djm_devices[device_idx]; 28498c2ecf20Sopenharmony_ci 28508c2ecf20Sopenharmony_ci if ((group >= device->ncontrols) || value >= device->controls[group].noptions) 28518c2ecf20Sopenharmony_ci return -EINVAL; 28528c2ecf20Sopenharmony_ci 28538c2ecf20Sopenharmony_ci err = snd_usb_lock_shutdown(mixer->chip); 28548c2ecf20Sopenharmony_ci if (err) 28558c2ecf20Sopenharmony_ci return err; 28568c2ecf20Sopenharmony_ci 28578c2ecf20Sopenharmony_ci err = snd_usb_ctl_msg( 28588c2ecf20Sopenharmony_ci mixer->chip->dev, usb_sndctrlpipe(mixer->chip->dev, 0), 28598c2ecf20Sopenharmony_ci USB_REQ_SET_FEATURE, 28608c2ecf20Sopenharmony_ci USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 28618c2ecf20Sopenharmony_ci device->controls[group].options[value], 28628c2ecf20Sopenharmony_ci device->controls[group].wIndex, 28638c2ecf20Sopenharmony_ci NULL, 0); 28648c2ecf20Sopenharmony_ci 28658c2ecf20Sopenharmony_ci snd_usb_unlock_shutdown(mixer->chip); 28668c2ecf20Sopenharmony_ci return err; 28678c2ecf20Sopenharmony_ci} 28688c2ecf20Sopenharmony_ci 28698c2ecf20Sopenharmony_cistatic int snd_djm_controls_get(struct snd_kcontrol *kctl, 28708c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *elem) 28718c2ecf20Sopenharmony_ci{ 28728c2ecf20Sopenharmony_ci elem->value.enumerated.item[0] = kctl->private_value & SND_DJM_VALUE_MASK; 28738c2ecf20Sopenharmony_ci return 0; 28748c2ecf20Sopenharmony_ci} 28758c2ecf20Sopenharmony_ci 28768c2ecf20Sopenharmony_cistatic int snd_djm_controls_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *elem) 28778c2ecf20Sopenharmony_ci{ 28788c2ecf20Sopenharmony_ci struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); 28798c2ecf20Sopenharmony_ci struct usb_mixer_interface *mixer = list->mixer; 28808c2ecf20Sopenharmony_ci unsigned long private_value = kctl->private_value; 28818c2ecf20Sopenharmony_ci 28828c2ecf20Sopenharmony_ci u8 device = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT; 28838c2ecf20Sopenharmony_ci u8 group = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT; 28848c2ecf20Sopenharmony_ci u16 value = elem->value.enumerated.item[0]; 28858c2ecf20Sopenharmony_ci 28868c2ecf20Sopenharmony_ci kctl->private_value = (((unsigned long)device << SND_DJM_DEVICE_SHIFT) | 28878c2ecf20Sopenharmony_ci (group << SND_DJM_GROUP_SHIFT) | 28888c2ecf20Sopenharmony_ci value); 28898c2ecf20Sopenharmony_ci 28908c2ecf20Sopenharmony_ci return snd_djm_controls_update(mixer, device, group, value); 28918c2ecf20Sopenharmony_ci} 28928c2ecf20Sopenharmony_ci 28938c2ecf20Sopenharmony_cistatic int snd_djm_controls_resume(struct usb_mixer_elem_list *list) 28948c2ecf20Sopenharmony_ci{ 28958c2ecf20Sopenharmony_ci unsigned long private_value = list->kctl->private_value; 28968c2ecf20Sopenharmony_ci u8 device = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT; 28978c2ecf20Sopenharmony_ci u8 group = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT; 28988c2ecf20Sopenharmony_ci u16 value = (private_value & SND_DJM_VALUE_MASK); 28998c2ecf20Sopenharmony_ci 29008c2ecf20Sopenharmony_ci return snd_djm_controls_update(list->mixer, device, group, value); 29018c2ecf20Sopenharmony_ci} 29028c2ecf20Sopenharmony_ci 29038c2ecf20Sopenharmony_cistatic int snd_djm_controls_create(struct usb_mixer_interface *mixer, 29048c2ecf20Sopenharmony_ci const u8 device_idx) 29058c2ecf20Sopenharmony_ci{ 29068c2ecf20Sopenharmony_ci int err, i; 29078c2ecf20Sopenharmony_ci u16 value; 29088c2ecf20Sopenharmony_ci 29098c2ecf20Sopenharmony_ci const struct snd_djm_device *device = &snd_djm_devices[device_idx]; 29108c2ecf20Sopenharmony_ci 29118c2ecf20Sopenharmony_ci struct snd_kcontrol_new knew = { 29128c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 29138c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 29148c2ecf20Sopenharmony_ci .index = 0, 29158c2ecf20Sopenharmony_ci .info = snd_djm_controls_info, 29168c2ecf20Sopenharmony_ci .get = snd_djm_controls_get, 29178c2ecf20Sopenharmony_ci .put = snd_djm_controls_put 29188c2ecf20Sopenharmony_ci }; 29198c2ecf20Sopenharmony_ci 29208c2ecf20Sopenharmony_ci for (i = 0; i < device->ncontrols; i++) { 29218c2ecf20Sopenharmony_ci value = device->controls[i].default_value; 29228c2ecf20Sopenharmony_ci knew.name = device->controls[i].name; 29238c2ecf20Sopenharmony_ci knew.private_value = ( 29248c2ecf20Sopenharmony_ci ((unsigned long)device_idx << SND_DJM_DEVICE_SHIFT) | 29258c2ecf20Sopenharmony_ci (i << SND_DJM_GROUP_SHIFT) | 29268c2ecf20Sopenharmony_ci value); 29278c2ecf20Sopenharmony_ci err = snd_djm_controls_update(mixer, device_idx, i, value); 29288c2ecf20Sopenharmony_ci if (err) 29298c2ecf20Sopenharmony_ci return err; 29308c2ecf20Sopenharmony_ci err = add_single_ctl_with_resume(mixer, 0, snd_djm_controls_resume, 29318c2ecf20Sopenharmony_ci &knew, NULL); 29328c2ecf20Sopenharmony_ci if (err) 29338c2ecf20Sopenharmony_ci return err; 29348c2ecf20Sopenharmony_ci } 29358c2ecf20Sopenharmony_ci return 0; 29368c2ecf20Sopenharmony_ci} 29378c2ecf20Sopenharmony_ci 29388c2ecf20Sopenharmony_ciint snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) 29398c2ecf20Sopenharmony_ci{ 29408c2ecf20Sopenharmony_ci int err = 0; 29418c2ecf20Sopenharmony_ci 29428c2ecf20Sopenharmony_ci err = snd_usb_soundblaster_remote_init(mixer); 29438c2ecf20Sopenharmony_ci if (err < 0) 29448c2ecf20Sopenharmony_ci return err; 29458c2ecf20Sopenharmony_ci 29468c2ecf20Sopenharmony_ci switch (mixer->chip->usb_id) { 29478c2ecf20Sopenharmony_ci /* Tascam US-16x08 */ 29488c2ecf20Sopenharmony_ci case USB_ID(0x0644, 0x8047): 29498c2ecf20Sopenharmony_ci err = snd_us16x08_controls_create(mixer); 29508c2ecf20Sopenharmony_ci break; 29518c2ecf20Sopenharmony_ci case USB_ID(0x041e, 0x3020): 29528c2ecf20Sopenharmony_ci case USB_ID(0x041e, 0x3040): 29538c2ecf20Sopenharmony_ci case USB_ID(0x041e, 0x3042): 29548c2ecf20Sopenharmony_ci case USB_ID(0x041e, 0x30df): 29558c2ecf20Sopenharmony_ci case USB_ID(0x041e, 0x3048): 29568c2ecf20Sopenharmony_ci err = snd_audigy2nx_controls_create(mixer); 29578c2ecf20Sopenharmony_ci if (err < 0) 29588c2ecf20Sopenharmony_ci break; 29598c2ecf20Sopenharmony_ci snd_card_ro_proc_new(mixer->chip->card, "audigy2nx", 29608c2ecf20Sopenharmony_ci mixer, snd_audigy2nx_proc_read); 29618c2ecf20Sopenharmony_ci break; 29628c2ecf20Sopenharmony_ci 29638c2ecf20Sopenharmony_ci /* EMU0204 */ 29648c2ecf20Sopenharmony_ci case USB_ID(0x041e, 0x3f19): 29658c2ecf20Sopenharmony_ci err = snd_emu0204_controls_create(mixer); 29668c2ecf20Sopenharmony_ci break; 29678c2ecf20Sopenharmony_ci 29688c2ecf20Sopenharmony_ci case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */ 29698c2ecf20Sopenharmony_ci case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */ 29708c2ecf20Sopenharmony_ci err = snd_c400_create_mixer(mixer); 29718c2ecf20Sopenharmony_ci break; 29728c2ecf20Sopenharmony_ci 29738c2ecf20Sopenharmony_ci case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */ 29748c2ecf20Sopenharmony_ci case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */ 29758c2ecf20Sopenharmony_ci err = snd_ftu_create_mixer(mixer); 29768c2ecf20Sopenharmony_ci break; 29778c2ecf20Sopenharmony_ci 29788c2ecf20Sopenharmony_ci case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */ 29798c2ecf20Sopenharmony_ci case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */ 29808c2ecf20Sopenharmony_ci case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */ 29818c2ecf20Sopenharmony_ci err = snd_xonar_u1_controls_create(mixer); 29828c2ecf20Sopenharmony_ci break; 29838c2ecf20Sopenharmony_ci 29848c2ecf20Sopenharmony_ci case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */ 29858c2ecf20Sopenharmony_ci err = snd_microii_controls_create(mixer); 29868c2ecf20Sopenharmony_ci break; 29878c2ecf20Sopenharmony_ci 29888c2ecf20Sopenharmony_ci case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */ 29898c2ecf20Sopenharmony_ci err = snd_mbox1_create_sync_switch(mixer); 29908c2ecf20Sopenharmony_ci break; 29918c2ecf20Sopenharmony_ci 29928c2ecf20Sopenharmony_ci case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */ 29938c2ecf20Sopenharmony_ci err = snd_nativeinstruments_create_mixer(mixer, 29948c2ecf20Sopenharmony_ci snd_nativeinstruments_ta6_mixers, 29958c2ecf20Sopenharmony_ci ARRAY_SIZE(snd_nativeinstruments_ta6_mixers)); 29968c2ecf20Sopenharmony_ci break; 29978c2ecf20Sopenharmony_ci 29988c2ecf20Sopenharmony_ci case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */ 29998c2ecf20Sopenharmony_ci err = snd_nativeinstruments_create_mixer(mixer, 30008c2ecf20Sopenharmony_ci snd_nativeinstruments_ta10_mixers, 30018c2ecf20Sopenharmony_ci ARRAY_SIZE(snd_nativeinstruments_ta10_mixers)); 30028c2ecf20Sopenharmony_ci break; 30038c2ecf20Sopenharmony_ci 30048c2ecf20Sopenharmony_ci case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */ 30058c2ecf20Sopenharmony_ci /* detection is disabled in mixer_maps.c */ 30068c2ecf20Sopenharmony_ci err = snd_create_std_mono_table(mixer, ebox44_table); 30078c2ecf20Sopenharmony_ci break; 30088c2ecf20Sopenharmony_ci 30098c2ecf20Sopenharmony_ci case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */ 30108c2ecf20Sopenharmony_ci case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */ 30118c2ecf20Sopenharmony_ci case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */ 30128c2ecf20Sopenharmony_ci case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */ 30138c2ecf20Sopenharmony_ci case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */ 30148c2ecf20Sopenharmony_ci err = snd_scarlett_controls_create(mixer); 30158c2ecf20Sopenharmony_ci break; 30168c2ecf20Sopenharmony_ci 30178c2ecf20Sopenharmony_ci case USB_ID(0x1235, 0x8203): /* Focusrite Scarlett 6i6 2nd Gen */ 30188c2ecf20Sopenharmony_ci case USB_ID(0x1235, 0x8204): /* Focusrite Scarlett 18i8 2nd Gen */ 30198c2ecf20Sopenharmony_ci case USB_ID(0x1235, 0x8201): /* Focusrite Scarlett 18i20 2nd Gen */ 30208c2ecf20Sopenharmony_ci err = snd_scarlett_gen2_init(mixer); 30218c2ecf20Sopenharmony_ci break; 30228c2ecf20Sopenharmony_ci 30238c2ecf20Sopenharmony_ci case USB_ID(0x041e, 0x323b): /* Creative Sound Blaster E1 */ 30248c2ecf20Sopenharmony_ci err = snd_soundblaster_e1_switch_create(mixer); 30258c2ecf20Sopenharmony_ci break; 30268c2ecf20Sopenharmony_ci case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */ 30278c2ecf20Sopenharmony_ci err = dell_dock_mixer_init(mixer); 30288c2ecf20Sopenharmony_ci break; 30298c2ecf20Sopenharmony_ci 30308c2ecf20Sopenharmony_ci case USB_ID(0x2a39, 0x3fd2): /* RME ADI-2 Pro */ 30318c2ecf20Sopenharmony_ci case USB_ID(0x2a39, 0x3fd3): /* RME ADI-2 DAC */ 30328c2ecf20Sopenharmony_ci case USB_ID(0x2a39, 0x3fd4): /* RME */ 30338c2ecf20Sopenharmony_ci err = snd_rme_controls_create(mixer); 30348c2ecf20Sopenharmony_ci break; 30358c2ecf20Sopenharmony_ci 30368c2ecf20Sopenharmony_ci case USB_ID(0x194f, 0x010c): /* Presonus Studio 1810c */ 30378c2ecf20Sopenharmony_ci err = snd_sc1810_init_mixer(mixer); 30388c2ecf20Sopenharmony_ci break; 30398c2ecf20Sopenharmony_ci case USB_ID(0x2a39, 0x3fb0): /* RME Babyface Pro FS */ 30408c2ecf20Sopenharmony_ci err = snd_bbfpro_controls_create(mixer); 30418c2ecf20Sopenharmony_ci break; 30428c2ecf20Sopenharmony_ci case USB_ID(0x2b73, 0x0017): /* Pioneer DJ DJM-250MK2 */ 30438c2ecf20Sopenharmony_ci err = snd_djm_controls_create(mixer, SND_DJM_250MK2_IDX); 30448c2ecf20Sopenharmony_ci break; 30458c2ecf20Sopenharmony_ci case USB_ID(0x08e4, 0x017f): /* Pioneer DJ DJM-750 */ 30468c2ecf20Sopenharmony_ci err = snd_djm_controls_create(mixer, SND_DJM_750_IDX); 30478c2ecf20Sopenharmony_ci break; 30488c2ecf20Sopenharmony_ci case USB_ID(0x2b73, 0x000a): /* Pioneer DJ DJM-900NXS2 */ 30498c2ecf20Sopenharmony_ci err = snd_djm_controls_create(mixer, SND_DJM_900NXS2_IDX); 30508c2ecf20Sopenharmony_ci break; 30518c2ecf20Sopenharmony_ci } 30528c2ecf20Sopenharmony_ci 30538c2ecf20Sopenharmony_ci return err; 30548c2ecf20Sopenharmony_ci} 30558c2ecf20Sopenharmony_ci 30568c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 30578c2ecf20Sopenharmony_civoid snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer) 30588c2ecf20Sopenharmony_ci{ 30598c2ecf20Sopenharmony_ci switch (mixer->chip->usb_id) { 30608c2ecf20Sopenharmony_ci case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */ 30618c2ecf20Sopenharmony_ci dell_dock_mixer_init(mixer); 30628c2ecf20Sopenharmony_ci break; 30638c2ecf20Sopenharmony_ci } 30648c2ecf20Sopenharmony_ci} 30658c2ecf20Sopenharmony_ci#endif 30668c2ecf20Sopenharmony_ci 30678c2ecf20Sopenharmony_civoid snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer, 30688c2ecf20Sopenharmony_ci int unitid) 30698c2ecf20Sopenharmony_ci{ 30708c2ecf20Sopenharmony_ci if (!mixer->rc_cfg) 30718c2ecf20Sopenharmony_ci return; 30728c2ecf20Sopenharmony_ci /* unit ids specific to Extigy/Audigy 2 NX: */ 30738c2ecf20Sopenharmony_ci switch (unitid) { 30748c2ecf20Sopenharmony_ci case 0: /* remote control */ 30758c2ecf20Sopenharmony_ci mixer->rc_urb->dev = mixer->chip->dev; 30768c2ecf20Sopenharmony_ci usb_submit_urb(mixer->rc_urb, GFP_ATOMIC); 30778c2ecf20Sopenharmony_ci break; 30788c2ecf20Sopenharmony_ci case 4: /* digital in jack */ 30798c2ecf20Sopenharmony_ci case 7: /* line in jacks */ 30808c2ecf20Sopenharmony_ci case 19: /* speaker out jacks */ 30818c2ecf20Sopenharmony_ci case 20: /* headphones out jack */ 30828c2ecf20Sopenharmony_ci break; 30838c2ecf20Sopenharmony_ci /* live24ext: 4 = line-in jack */ 30848c2ecf20Sopenharmony_ci case 3: /* hp-out jack (may actuate Mute) */ 30858c2ecf20Sopenharmony_ci if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || 30868c2ecf20Sopenharmony_ci mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) 30878c2ecf20Sopenharmony_ci snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id); 30888c2ecf20Sopenharmony_ci break; 30898c2ecf20Sopenharmony_ci default: 30908c2ecf20Sopenharmony_ci usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid); 30918c2ecf20Sopenharmony_ci break; 30928c2ecf20Sopenharmony_ci } 30938c2ecf20Sopenharmony_ci} 30948c2ecf20Sopenharmony_ci 30958c2ecf20Sopenharmony_cistatic void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer, 30968c2ecf20Sopenharmony_ci struct usb_mixer_elem_info *cval, 30978c2ecf20Sopenharmony_ci struct snd_kcontrol *kctl) 30988c2ecf20Sopenharmony_ci{ 30998c2ecf20Sopenharmony_ci /* Approximation using 10 ranges based on output measurement on hw v1.2. 31008c2ecf20Sopenharmony_ci * This seems close to the cubic mapping e.g. alsamixer uses. */ 31018c2ecf20Sopenharmony_ci static const DECLARE_TLV_DB_RANGE(scale, 31028c2ecf20Sopenharmony_ci 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970), 31038c2ecf20Sopenharmony_ci 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160), 31048c2ecf20Sopenharmony_ci 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710), 31058c2ecf20Sopenharmony_ci 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560), 31068c2ecf20Sopenharmony_ci 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324), 31078c2ecf20Sopenharmony_ci 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031), 31088c2ecf20Sopenharmony_ci 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393), 31098c2ecf20Sopenharmony_ci 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032), 31108c2ecf20Sopenharmony_ci 32, 40, TLV_DB_MINMAX_ITEM(-968, -490), 31118c2ecf20Sopenharmony_ci 41, 50, TLV_DB_MINMAX_ITEM(-441, 0), 31128c2ecf20Sopenharmony_ci ); 31138c2ecf20Sopenharmony_ci 31148c2ecf20Sopenharmony_ci if (cval->min == 0 && cval->max == 50) { 31158c2ecf20Sopenharmony_ci usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n"); 31168c2ecf20Sopenharmony_ci kctl->tlv.p = scale; 31178c2ecf20Sopenharmony_ci kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; 31188c2ecf20Sopenharmony_ci kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; 31198c2ecf20Sopenharmony_ci 31208c2ecf20Sopenharmony_ci } else if (cval->min == 0 && cval->max <= 1000) { 31218c2ecf20Sopenharmony_ci /* Some other clearly broken DragonFly variant. 31228c2ecf20Sopenharmony_ci * At least a 0..53 variant (hw v1.0) exists. 31238c2ecf20Sopenharmony_ci */ 31248c2ecf20Sopenharmony_ci usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device"); 31258c2ecf20Sopenharmony_ci kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; 31268c2ecf20Sopenharmony_ci } 31278c2ecf20Sopenharmony_ci} 31288c2ecf20Sopenharmony_ci 31298c2ecf20Sopenharmony_civoid snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer, 31308c2ecf20Sopenharmony_ci struct usb_mixer_elem_info *cval, int unitid, 31318c2ecf20Sopenharmony_ci struct snd_kcontrol *kctl) 31328c2ecf20Sopenharmony_ci{ 31338c2ecf20Sopenharmony_ci switch (mixer->chip->usb_id) { 31348c2ecf20Sopenharmony_ci case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */ 31358c2ecf20Sopenharmony_ci if (unitid == 7 && cval->control == UAC_FU_VOLUME) 31368c2ecf20Sopenharmony_ci snd_dragonfly_quirk_db_scale(mixer, cval, kctl); 31378c2ecf20Sopenharmony_ci break; 31388c2ecf20Sopenharmony_ci /* lowest playback value is muted on some devices */ 31398c2ecf20Sopenharmony_ci case USB_ID(0x0d8c, 0x000c): /* C-Media */ 31408c2ecf20Sopenharmony_ci case USB_ID(0x0d8c, 0x0014): /* C-Media */ 31418c2ecf20Sopenharmony_ci case USB_ID(0x19f7, 0x0003): /* RODE NT-USB */ 31428c2ecf20Sopenharmony_ci if (strstr(kctl->id.name, "Playback")) 31438c2ecf20Sopenharmony_ci cval->min_mute = 1; 31448c2ecf20Sopenharmony_ci break; 31458c2ecf20Sopenharmony_ci } 31468c2ecf20Sopenharmony_ci} 31478c2ecf20Sopenharmony_ci 3148