18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * card driver for models with CS4398/CS4362A DACs (Xonar D1/DX) 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) Clemens Ladisch <clemens@ladisch.de> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/* 98c2ecf20Sopenharmony_ci * Xonar D1/DX 108c2ecf20Sopenharmony_ci * ----------- 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * CMI8788: 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * I²C <-> CS4398 (addr 1001111) (front) 158c2ecf20Sopenharmony_ci * <-> CS4362A (addr 0011000) (surround, center/LFE, back) 168c2ecf20Sopenharmony_ci * 178c2ecf20Sopenharmony_ci * GPI 0 <- external power present (DX only) 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * GPIO 0 -> enable output to speakers 208c2ecf20Sopenharmony_ci * GPIO 1 -> route output to front panel 218c2ecf20Sopenharmony_ci * GPIO 2 -> M0 of CS5361 228c2ecf20Sopenharmony_ci * GPIO 3 -> M1 of CS5361 238c2ecf20Sopenharmony_ci * GPIO 6 -> ? 248c2ecf20Sopenharmony_ci * GPIO 7 -> ? 258c2ecf20Sopenharmony_ci * GPIO 8 -> route input jack to line-in (0) or mic-in (1) 268c2ecf20Sopenharmony_ci * 278c2ecf20Sopenharmony_ci * CM9780: 288c2ecf20Sopenharmony_ci * 298c2ecf20Sopenharmony_ci * LINE_OUT -> input of ADC 308c2ecf20Sopenharmony_ci * 318c2ecf20Sopenharmony_ci * AUX_IN <- aux 328c2ecf20Sopenharmony_ci * MIC_IN <- mic 338c2ecf20Sopenharmony_ci * FMIC_IN <- front mic 348c2ecf20Sopenharmony_ci * 358c2ecf20Sopenharmony_ci * GPO 0 -> route line-in (0) or AC97 output (1) to CS5361 input 368c2ecf20Sopenharmony_ci */ 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#include <linux/pci.h> 398c2ecf20Sopenharmony_ci#include <linux/delay.h> 408c2ecf20Sopenharmony_ci#include <sound/ac97_codec.h> 418c2ecf20Sopenharmony_ci#include <sound/control.h> 428c2ecf20Sopenharmony_ci#include <sound/core.h> 438c2ecf20Sopenharmony_ci#include <sound/pcm.h> 448c2ecf20Sopenharmony_ci#include <sound/pcm_params.h> 458c2ecf20Sopenharmony_ci#include <sound/tlv.h> 468c2ecf20Sopenharmony_ci#include "xonar.h" 478c2ecf20Sopenharmony_ci#include "cm9780.h" 488c2ecf20Sopenharmony_ci#include "cs4398.h" 498c2ecf20Sopenharmony_ci#include "cs4362a.h" 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#define GPI_EXT_POWER 0x01 528c2ecf20Sopenharmony_ci#define GPIO_D1_OUTPUT_ENABLE 0x0001 538c2ecf20Sopenharmony_ci#define GPIO_D1_FRONT_PANEL 0x0002 548c2ecf20Sopenharmony_ci#define GPIO_D1_MAGIC 0x00c0 558c2ecf20Sopenharmony_ci#define GPIO_D1_INPUT_ROUTE 0x0100 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */ 588c2ecf20Sopenharmony_ci#define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */ 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cistruct xonar_cs43xx { 618c2ecf20Sopenharmony_ci struct xonar_generic generic; 628c2ecf20Sopenharmony_ci u8 cs4398_regs[8]; 638c2ecf20Sopenharmony_ci u8 cs4362a_regs[15]; 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic void cs4398_write(struct oxygen *chip, u8 reg, u8 value) 678c2ecf20Sopenharmony_ci{ 688c2ecf20Sopenharmony_ci struct xonar_cs43xx *data = chip->model_data; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value); 718c2ecf20Sopenharmony_ci if (reg < ARRAY_SIZE(data->cs4398_regs)) 728c2ecf20Sopenharmony_ci data->cs4398_regs[reg] = value; 738c2ecf20Sopenharmony_ci} 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistatic void cs4398_write_cached(struct oxygen *chip, u8 reg, u8 value) 768c2ecf20Sopenharmony_ci{ 778c2ecf20Sopenharmony_ci struct xonar_cs43xx *data = chip->model_data; 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci if (value != data->cs4398_regs[reg]) 808c2ecf20Sopenharmony_ci cs4398_write(chip, reg, value); 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistatic void cs4362a_write(struct oxygen *chip, u8 reg, u8 value) 848c2ecf20Sopenharmony_ci{ 858c2ecf20Sopenharmony_ci struct xonar_cs43xx *data = chip->model_data; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value); 888c2ecf20Sopenharmony_ci if (reg < ARRAY_SIZE(data->cs4362a_regs)) 898c2ecf20Sopenharmony_ci data->cs4362a_regs[reg] = value; 908c2ecf20Sopenharmony_ci} 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_cistatic void cs4362a_write_cached(struct oxygen *chip, u8 reg, u8 value) 938c2ecf20Sopenharmony_ci{ 948c2ecf20Sopenharmony_ci struct xonar_cs43xx *data = chip->model_data; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci if (value != data->cs4362a_regs[reg]) 978c2ecf20Sopenharmony_ci cs4362a_write(chip, reg, value); 988c2ecf20Sopenharmony_ci} 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_cistatic void cs43xx_registers_init(struct oxygen *chip) 1018c2ecf20Sopenharmony_ci{ 1028c2ecf20Sopenharmony_ci struct xonar_cs43xx *data = chip->model_data; 1038c2ecf20Sopenharmony_ci unsigned int i; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci /* set CPEN (control port mode) and power down */ 1068c2ecf20Sopenharmony_ci cs4398_write(chip, 8, CS4398_CPEN | CS4398_PDN); 1078c2ecf20Sopenharmony_ci cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN); 1088c2ecf20Sopenharmony_ci /* configure */ 1098c2ecf20Sopenharmony_ci cs4398_write(chip, 2, data->cs4398_regs[2]); 1108c2ecf20Sopenharmony_ci cs4398_write(chip, 3, CS4398_ATAPI_B_R | CS4398_ATAPI_A_L); 1118c2ecf20Sopenharmony_ci cs4398_write(chip, 4, data->cs4398_regs[4]); 1128c2ecf20Sopenharmony_ci cs4398_write(chip, 5, data->cs4398_regs[5]); 1138c2ecf20Sopenharmony_ci cs4398_write(chip, 6, data->cs4398_regs[6]); 1148c2ecf20Sopenharmony_ci cs4398_write(chip, 7, data->cs4398_regs[7]); 1158c2ecf20Sopenharmony_ci cs4362a_write(chip, 0x02, CS4362A_DIF_LJUST); 1168c2ecf20Sopenharmony_ci cs4362a_write(chip, 0x03, CS4362A_MUTEC_6 | CS4362A_AMUTE | 1178c2ecf20Sopenharmony_ci CS4362A_RMP_UP | CS4362A_ZERO_CROSS | CS4362A_SOFT_RAMP); 1188c2ecf20Sopenharmony_ci cs4362a_write(chip, 0x04, data->cs4362a_regs[0x04]); 1198c2ecf20Sopenharmony_ci cs4362a_write(chip, 0x05, 0); 1208c2ecf20Sopenharmony_ci for (i = 6; i <= 14; ++i) 1218c2ecf20Sopenharmony_ci cs4362a_write(chip, i, data->cs4362a_regs[i]); 1228c2ecf20Sopenharmony_ci /* clear power down */ 1238c2ecf20Sopenharmony_ci cs4398_write(chip, 8, CS4398_CPEN); 1248c2ecf20Sopenharmony_ci cs4362a_write(chip, 0x01, CS4362A_CPEN); 1258c2ecf20Sopenharmony_ci} 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_cistatic void xonar_d1_init(struct oxygen *chip) 1288c2ecf20Sopenharmony_ci{ 1298c2ecf20Sopenharmony_ci struct xonar_cs43xx *data = chip->model_data; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci data->generic.anti_pop_delay = 800; 1328c2ecf20Sopenharmony_ci data->generic.output_enable_bit = GPIO_D1_OUTPUT_ENABLE; 1338c2ecf20Sopenharmony_ci data->cs4398_regs[2] = 1348c2ecf20Sopenharmony_ci CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST; 1358c2ecf20Sopenharmony_ci data->cs4398_regs[4] = CS4398_MUTEP_LOW | 1368c2ecf20Sopenharmony_ci CS4398_MUTE_B | CS4398_MUTE_A | CS4398_PAMUTE; 1378c2ecf20Sopenharmony_ci data->cs4398_regs[5] = 60 * 2; 1388c2ecf20Sopenharmony_ci data->cs4398_regs[6] = 60 * 2; 1398c2ecf20Sopenharmony_ci data->cs4398_regs[7] = CS4398_RMP_DN | CS4398_RMP_UP | 1408c2ecf20Sopenharmony_ci CS4398_ZERO_CROSS | CS4398_SOFT_RAMP; 1418c2ecf20Sopenharmony_ci data->cs4362a_regs[4] = CS4362A_RMP_DN | CS4362A_DEM_NONE; 1428c2ecf20Sopenharmony_ci data->cs4362a_regs[6] = CS4362A_FM_SINGLE | 1438c2ecf20Sopenharmony_ci CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L; 1448c2ecf20Sopenharmony_ci data->cs4362a_regs[7] = 60 | CS4362A_MUTE; 1458c2ecf20Sopenharmony_ci data->cs4362a_regs[8] = 60 | CS4362A_MUTE; 1468c2ecf20Sopenharmony_ci data->cs4362a_regs[9] = data->cs4362a_regs[6]; 1478c2ecf20Sopenharmony_ci data->cs4362a_regs[10] = 60 | CS4362A_MUTE; 1488c2ecf20Sopenharmony_ci data->cs4362a_regs[11] = 60 | CS4362A_MUTE; 1498c2ecf20Sopenharmony_ci data->cs4362a_regs[12] = data->cs4362a_regs[6]; 1508c2ecf20Sopenharmony_ci data->cs4362a_regs[13] = 60 | CS4362A_MUTE; 1518c2ecf20Sopenharmony_ci data->cs4362a_regs[14] = 60 | CS4362A_MUTE; 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, 1548c2ecf20Sopenharmony_ci OXYGEN_2WIRE_LENGTH_8 | 1558c2ecf20Sopenharmony_ci OXYGEN_2WIRE_INTERRUPT_MASK | 1568c2ecf20Sopenharmony_ci OXYGEN_2WIRE_SPEED_FAST); 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci cs43xx_registers_init(chip); 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, 1618c2ecf20Sopenharmony_ci GPIO_D1_FRONT_PANEL | 1628c2ecf20Sopenharmony_ci GPIO_D1_MAGIC | 1638c2ecf20Sopenharmony_ci GPIO_D1_INPUT_ROUTE); 1648c2ecf20Sopenharmony_ci oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, 1658c2ecf20Sopenharmony_ci GPIO_D1_FRONT_PANEL | GPIO_D1_INPUT_ROUTE); 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci xonar_init_cs53x1(chip); 1688c2ecf20Sopenharmony_ci xonar_enable_output(chip); 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci snd_component_add(chip->card, "CS4398"); 1718c2ecf20Sopenharmony_ci snd_component_add(chip->card, "CS4362A"); 1728c2ecf20Sopenharmony_ci snd_component_add(chip->card, "CS5361"); 1738c2ecf20Sopenharmony_ci} 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_cistatic void xonar_dx_init(struct oxygen *chip) 1768c2ecf20Sopenharmony_ci{ 1778c2ecf20Sopenharmony_ci struct xonar_cs43xx *data = chip->model_data; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci data->generic.ext_power_reg = OXYGEN_GPI_DATA; 1808c2ecf20Sopenharmony_ci data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; 1818c2ecf20Sopenharmony_ci data->generic.ext_power_bit = GPI_EXT_POWER; 1828c2ecf20Sopenharmony_ci xonar_init_ext_power(chip); 1838c2ecf20Sopenharmony_ci xonar_d1_init(chip); 1848c2ecf20Sopenharmony_ci} 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_cistatic void xonar_d1_cleanup(struct oxygen *chip) 1878c2ecf20Sopenharmony_ci{ 1888c2ecf20Sopenharmony_ci xonar_disable_output(chip); 1898c2ecf20Sopenharmony_ci cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN); 1908c2ecf20Sopenharmony_ci oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC); 1918c2ecf20Sopenharmony_ci} 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_cistatic void xonar_d1_suspend(struct oxygen *chip) 1948c2ecf20Sopenharmony_ci{ 1958c2ecf20Sopenharmony_ci xonar_d1_cleanup(chip); 1968c2ecf20Sopenharmony_ci} 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_cistatic void xonar_d1_resume(struct oxygen *chip) 1998c2ecf20Sopenharmony_ci{ 2008c2ecf20Sopenharmony_ci oxygen_set_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC); 2018c2ecf20Sopenharmony_ci msleep(1); 2028c2ecf20Sopenharmony_ci cs43xx_registers_init(chip); 2038c2ecf20Sopenharmony_ci xonar_enable_output(chip); 2048c2ecf20Sopenharmony_ci} 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_cistatic void set_cs43xx_params(struct oxygen *chip, 2078c2ecf20Sopenharmony_ci struct snd_pcm_hw_params *params) 2088c2ecf20Sopenharmony_ci{ 2098c2ecf20Sopenharmony_ci struct xonar_cs43xx *data = chip->model_data; 2108c2ecf20Sopenharmony_ci u8 cs4398_fm, cs4362a_fm; 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci if (params_rate(params) <= 50000) { 2138c2ecf20Sopenharmony_ci cs4398_fm = CS4398_FM_SINGLE; 2148c2ecf20Sopenharmony_ci cs4362a_fm = CS4362A_FM_SINGLE; 2158c2ecf20Sopenharmony_ci } else if (params_rate(params) <= 100000) { 2168c2ecf20Sopenharmony_ci cs4398_fm = CS4398_FM_DOUBLE; 2178c2ecf20Sopenharmony_ci cs4362a_fm = CS4362A_FM_DOUBLE; 2188c2ecf20Sopenharmony_ci } else { 2198c2ecf20Sopenharmony_ci cs4398_fm = CS4398_FM_QUAD; 2208c2ecf20Sopenharmony_ci cs4362a_fm = CS4362A_FM_QUAD; 2218c2ecf20Sopenharmony_ci } 2228c2ecf20Sopenharmony_ci cs4398_fm |= CS4398_DEM_NONE | CS4398_DIF_LJUST; 2238c2ecf20Sopenharmony_ci cs4398_write_cached(chip, 2, cs4398_fm); 2248c2ecf20Sopenharmony_ci cs4362a_fm |= data->cs4362a_regs[6] & ~CS4362A_FM_MASK; 2258c2ecf20Sopenharmony_ci cs4362a_write_cached(chip, 6, cs4362a_fm); 2268c2ecf20Sopenharmony_ci cs4362a_write_cached(chip, 12, cs4362a_fm); 2278c2ecf20Sopenharmony_ci cs4362a_fm &= CS4362A_FM_MASK; 2288c2ecf20Sopenharmony_ci cs4362a_fm |= data->cs4362a_regs[9] & ~CS4362A_FM_MASK; 2298c2ecf20Sopenharmony_ci cs4362a_write_cached(chip, 9, cs4362a_fm); 2308c2ecf20Sopenharmony_ci} 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_cistatic void update_cs4362a_volumes(struct oxygen *chip) 2338c2ecf20Sopenharmony_ci{ 2348c2ecf20Sopenharmony_ci unsigned int i; 2358c2ecf20Sopenharmony_ci u8 mute; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci mute = chip->dac_mute ? CS4362A_MUTE : 0; 2388c2ecf20Sopenharmony_ci for (i = 0; i < 6; ++i) 2398c2ecf20Sopenharmony_ci cs4362a_write_cached(chip, 7 + i + i / 2, 2408c2ecf20Sopenharmony_ci (127 - chip->dac_volume[2 + i]) | mute); 2418c2ecf20Sopenharmony_ci} 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_cistatic void update_cs43xx_volume(struct oxygen *chip) 2448c2ecf20Sopenharmony_ci{ 2458c2ecf20Sopenharmony_ci cs4398_write_cached(chip, 5, (127 - chip->dac_volume[0]) * 2); 2468c2ecf20Sopenharmony_ci cs4398_write_cached(chip, 6, (127 - chip->dac_volume[1]) * 2); 2478c2ecf20Sopenharmony_ci update_cs4362a_volumes(chip); 2488c2ecf20Sopenharmony_ci} 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_cistatic void update_cs43xx_mute(struct oxygen *chip) 2518c2ecf20Sopenharmony_ci{ 2528c2ecf20Sopenharmony_ci u8 reg; 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci reg = CS4398_MUTEP_LOW | CS4398_PAMUTE; 2558c2ecf20Sopenharmony_ci if (chip->dac_mute) 2568c2ecf20Sopenharmony_ci reg |= CS4398_MUTE_B | CS4398_MUTE_A; 2578c2ecf20Sopenharmony_ci cs4398_write_cached(chip, 4, reg); 2588c2ecf20Sopenharmony_ci update_cs4362a_volumes(chip); 2598c2ecf20Sopenharmony_ci} 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_cistatic void update_cs43xx_center_lfe_mix(struct oxygen *chip, bool mixed) 2628c2ecf20Sopenharmony_ci{ 2638c2ecf20Sopenharmony_ci struct xonar_cs43xx *data = chip->model_data; 2648c2ecf20Sopenharmony_ci u8 reg; 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci reg = data->cs4362a_regs[9] & ~CS4362A_ATAPI_MASK; 2678c2ecf20Sopenharmony_ci if (mixed) 2688c2ecf20Sopenharmony_ci reg |= CS4362A_ATAPI_B_LR | CS4362A_ATAPI_A_LR; 2698c2ecf20Sopenharmony_ci else 2708c2ecf20Sopenharmony_ci reg |= CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L; 2718c2ecf20Sopenharmony_ci cs4362a_write_cached(chip, 9, reg); 2728c2ecf20Sopenharmony_ci} 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new front_panel_switch = { 2758c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2768c2ecf20Sopenharmony_ci .name = "Front Panel Playback Switch", 2778c2ecf20Sopenharmony_ci .info = snd_ctl_boolean_mono_info, 2788c2ecf20Sopenharmony_ci .get = xonar_gpio_bit_switch_get, 2798c2ecf20Sopenharmony_ci .put = xonar_gpio_bit_switch_put, 2808c2ecf20Sopenharmony_ci .private_value = GPIO_D1_FRONT_PANEL, 2818c2ecf20Sopenharmony_ci}; 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_cistatic int rolloff_info(struct snd_kcontrol *ctl, 2848c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *info) 2858c2ecf20Sopenharmony_ci{ 2868c2ecf20Sopenharmony_ci static const char *const names[2] = { 2878c2ecf20Sopenharmony_ci "Fast Roll-off", "Slow Roll-off" 2888c2ecf20Sopenharmony_ci }; 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci return snd_ctl_enum_info(info, 1, 2, names); 2918c2ecf20Sopenharmony_ci} 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_cistatic int rolloff_get(struct snd_kcontrol *ctl, 2948c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *value) 2958c2ecf20Sopenharmony_ci{ 2968c2ecf20Sopenharmony_ci struct oxygen *chip = ctl->private_data; 2978c2ecf20Sopenharmony_ci struct xonar_cs43xx *data = chip->model_data; 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci value->value.enumerated.item[0] = 3008c2ecf20Sopenharmony_ci (data->cs4398_regs[7] & CS4398_FILT_SEL) != 0; 3018c2ecf20Sopenharmony_ci return 0; 3028c2ecf20Sopenharmony_ci} 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_cistatic int rolloff_put(struct snd_kcontrol *ctl, 3058c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *value) 3068c2ecf20Sopenharmony_ci{ 3078c2ecf20Sopenharmony_ci struct oxygen *chip = ctl->private_data; 3088c2ecf20Sopenharmony_ci struct xonar_cs43xx *data = chip->model_data; 3098c2ecf20Sopenharmony_ci int changed; 3108c2ecf20Sopenharmony_ci u8 reg; 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci mutex_lock(&chip->mutex); 3138c2ecf20Sopenharmony_ci reg = data->cs4398_regs[7]; 3148c2ecf20Sopenharmony_ci if (value->value.enumerated.item[0]) 3158c2ecf20Sopenharmony_ci reg |= CS4398_FILT_SEL; 3168c2ecf20Sopenharmony_ci else 3178c2ecf20Sopenharmony_ci reg &= ~CS4398_FILT_SEL; 3188c2ecf20Sopenharmony_ci changed = reg != data->cs4398_regs[7]; 3198c2ecf20Sopenharmony_ci if (changed) { 3208c2ecf20Sopenharmony_ci cs4398_write(chip, 7, reg); 3218c2ecf20Sopenharmony_ci if (reg & CS4398_FILT_SEL) 3228c2ecf20Sopenharmony_ci reg = data->cs4362a_regs[0x04] | CS4362A_FILT_SEL; 3238c2ecf20Sopenharmony_ci else 3248c2ecf20Sopenharmony_ci reg = data->cs4362a_regs[0x04] & ~CS4362A_FILT_SEL; 3258c2ecf20Sopenharmony_ci cs4362a_write(chip, 0x04, reg); 3268c2ecf20Sopenharmony_ci } 3278c2ecf20Sopenharmony_ci mutex_unlock(&chip->mutex); 3288c2ecf20Sopenharmony_ci return changed; 3298c2ecf20Sopenharmony_ci} 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rolloff_control = { 3328c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3338c2ecf20Sopenharmony_ci .name = "DAC Filter Playback Enum", 3348c2ecf20Sopenharmony_ci .info = rolloff_info, 3358c2ecf20Sopenharmony_ci .get = rolloff_get, 3368c2ecf20Sopenharmony_ci .put = rolloff_put, 3378c2ecf20Sopenharmony_ci}; 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_cistatic void xonar_d1_line_mic_ac97_switch(struct oxygen *chip, 3408c2ecf20Sopenharmony_ci unsigned int reg, unsigned int mute) 3418c2ecf20Sopenharmony_ci{ 3428c2ecf20Sopenharmony_ci if (reg == AC97_LINE) { 3438c2ecf20Sopenharmony_ci spin_lock_irq(&chip->reg_lock); 3448c2ecf20Sopenharmony_ci oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, 3458c2ecf20Sopenharmony_ci mute ? GPIO_D1_INPUT_ROUTE : 0, 3468c2ecf20Sopenharmony_ci GPIO_D1_INPUT_ROUTE); 3478c2ecf20Sopenharmony_ci spin_unlock_irq(&chip->reg_lock); 3488c2ecf20Sopenharmony_ci } 3498c2ecf20Sopenharmony_ci} 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -6000, 100, 0); 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_cistatic int xonar_d1_mixer_init(struct oxygen *chip) 3548c2ecf20Sopenharmony_ci{ 3558c2ecf20Sopenharmony_ci int err; 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci err = snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip)); 3588c2ecf20Sopenharmony_ci if (err < 0) 3598c2ecf20Sopenharmony_ci return err; 3608c2ecf20Sopenharmony_ci err = snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip)); 3618c2ecf20Sopenharmony_ci if (err < 0) 3628c2ecf20Sopenharmony_ci return err; 3638c2ecf20Sopenharmony_ci return 0; 3648c2ecf20Sopenharmony_ci} 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_cistatic void dump_cs4362a_registers(struct xonar_cs43xx *data, 3678c2ecf20Sopenharmony_ci struct snd_info_buffer *buffer) 3688c2ecf20Sopenharmony_ci{ 3698c2ecf20Sopenharmony_ci unsigned int i; 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci snd_iprintf(buffer, "\nCS4362A:"); 3728c2ecf20Sopenharmony_ci for (i = 1; i <= 14; ++i) 3738c2ecf20Sopenharmony_ci snd_iprintf(buffer, " %02x", data->cs4362a_regs[i]); 3748c2ecf20Sopenharmony_ci snd_iprintf(buffer, "\n"); 3758c2ecf20Sopenharmony_ci} 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_cistatic void dump_d1_registers(struct oxygen *chip, 3788c2ecf20Sopenharmony_ci struct snd_info_buffer *buffer) 3798c2ecf20Sopenharmony_ci{ 3808c2ecf20Sopenharmony_ci struct xonar_cs43xx *data = chip->model_data; 3818c2ecf20Sopenharmony_ci unsigned int i; 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci snd_iprintf(buffer, "\nCS4398: 7?"); 3848c2ecf20Sopenharmony_ci for (i = 2; i < 8; ++i) 3858c2ecf20Sopenharmony_ci snd_iprintf(buffer, " %02x", data->cs4398_regs[i]); 3868c2ecf20Sopenharmony_ci snd_iprintf(buffer, "\n"); 3878c2ecf20Sopenharmony_ci dump_cs4362a_registers(data, buffer); 3888c2ecf20Sopenharmony_ci} 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_cistatic const struct oxygen_model model_xonar_d1 = { 3918c2ecf20Sopenharmony_ci .longname = "Asus Virtuoso 100", 3928c2ecf20Sopenharmony_ci .chip = "AV200", 3938c2ecf20Sopenharmony_ci .init = xonar_d1_init, 3948c2ecf20Sopenharmony_ci .mixer_init = xonar_d1_mixer_init, 3958c2ecf20Sopenharmony_ci .cleanup = xonar_d1_cleanup, 3968c2ecf20Sopenharmony_ci .suspend = xonar_d1_suspend, 3978c2ecf20Sopenharmony_ci .resume = xonar_d1_resume, 3988c2ecf20Sopenharmony_ci .set_dac_params = set_cs43xx_params, 3998c2ecf20Sopenharmony_ci .set_adc_params = xonar_set_cs53x1_params, 4008c2ecf20Sopenharmony_ci .update_dac_volume = update_cs43xx_volume, 4018c2ecf20Sopenharmony_ci .update_dac_mute = update_cs43xx_mute, 4028c2ecf20Sopenharmony_ci .update_center_lfe_mix = update_cs43xx_center_lfe_mix, 4038c2ecf20Sopenharmony_ci .ac97_switch = xonar_d1_line_mic_ac97_switch, 4048c2ecf20Sopenharmony_ci .dump_registers = dump_d1_registers, 4058c2ecf20Sopenharmony_ci .dac_tlv = cs4362a_db_scale, 4068c2ecf20Sopenharmony_ci .model_data_size = sizeof(struct xonar_cs43xx), 4078c2ecf20Sopenharmony_ci .device_config = PLAYBACK_0_TO_I2S | 4088c2ecf20Sopenharmony_ci PLAYBACK_1_TO_SPDIF | 4098c2ecf20Sopenharmony_ci CAPTURE_0_FROM_I2S_2 | 4108c2ecf20Sopenharmony_ci CAPTURE_1_FROM_SPDIF | 4118c2ecf20Sopenharmony_ci AC97_FMIC_SWITCH, 4128c2ecf20Sopenharmony_ci .dac_channels_pcm = 8, 4138c2ecf20Sopenharmony_ci .dac_channels_mixer = 8, 4148c2ecf20Sopenharmony_ci .dac_volume_min = 127 - 60, 4158c2ecf20Sopenharmony_ci .dac_volume_max = 127, 4168c2ecf20Sopenharmony_ci .function_flags = OXYGEN_FUNCTION_2WIRE, 4178c2ecf20Sopenharmony_ci .dac_mclks = OXYGEN_MCLKS(256, 128, 128), 4188c2ecf20Sopenharmony_ci .adc_mclks = OXYGEN_MCLKS(256, 128, 128), 4198c2ecf20Sopenharmony_ci .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 4208c2ecf20Sopenharmony_ci .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 4218c2ecf20Sopenharmony_ci}; 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ciint get_xonar_cs43xx_model(struct oxygen *chip, 4248c2ecf20Sopenharmony_ci const struct pci_device_id *id) 4258c2ecf20Sopenharmony_ci{ 4268c2ecf20Sopenharmony_ci switch (id->subdevice) { 4278c2ecf20Sopenharmony_ci case 0x834f: 4288c2ecf20Sopenharmony_ci chip->model = model_xonar_d1; 4298c2ecf20Sopenharmony_ci chip->model.shortname = "Xonar D1"; 4308c2ecf20Sopenharmony_ci break; 4318c2ecf20Sopenharmony_ci case 0x8275: 4328c2ecf20Sopenharmony_ci case 0x8327: 4338c2ecf20Sopenharmony_ci chip->model = model_xonar_d1; 4348c2ecf20Sopenharmony_ci chip->model.shortname = "Xonar DX"; 4358c2ecf20Sopenharmony_ci chip->model.init = xonar_dx_init; 4368c2ecf20Sopenharmony_ci break; 4378c2ecf20Sopenharmony_ci default: 4388c2ecf20Sopenharmony_ci return -EINVAL; 4398c2ecf20Sopenharmony_ci } 4408c2ecf20Sopenharmony_ci return 0; 4418c2ecf20Sopenharmony_ci} 442