18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 48c2ecf20Sopenharmony_ci * Routines for Sound Blaster mixer control 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <linux/io.h> 88c2ecf20Sopenharmony_ci#include <linux/delay.h> 98c2ecf20Sopenharmony_ci#include <linux/time.h> 108c2ecf20Sopenharmony_ci#include <sound/core.h> 118c2ecf20Sopenharmony_ci#include <sound/sb.h> 128c2ecf20Sopenharmony_ci#include <sound/control.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#undef IO_DEBUG 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_civoid snd_sbmixer_write(struct snd_sb *chip, unsigned char reg, unsigned char data) 178c2ecf20Sopenharmony_ci{ 188c2ecf20Sopenharmony_ci outb(reg, SBP(chip, MIXER_ADDR)); 198c2ecf20Sopenharmony_ci udelay(10); 208c2ecf20Sopenharmony_ci outb(data, SBP(chip, MIXER_DATA)); 218c2ecf20Sopenharmony_ci udelay(10); 228c2ecf20Sopenharmony_ci#ifdef IO_DEBUG 238c2ecf20Sopenharmony_ci snd_printk(KERN_DEBUG "mixer_write 0x%x 0x%x\n", reg, data); 248c2ecf20Sopenharmony_ci#endif 258c2ecf20Sopenharmony_ci} 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ciunsigned char snd_sbmixer_read(struct snd_sb *chip, unsigned char reg) 288c2ecf20Sopenharmony_ci{ 298c2ecf20Sopenharmony_ci unsigned char result; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci outb(reg, SBP(chip, MIXER_ADDR)); 328c2ecf20Sopenharmony_ci udelay(10); 338c2ecf20Sopenharmony_ci result = inb(SBP(chip, MIXER_DATA)); 348c2ecf20Sopenharmony_ci udelay(10); 358c2ecf20Sopenharmony_ci#ifdef IO_DEBUG 368c2ecf20Sopenharmony_ci snd_printk(KERN_DEBUG "mixer_read 0x%x 0x%x\n", reg, result); 378c2ecf20Sopenharmony_ci#endif 388c2ecf20Sopenharmony_ci return result; 398c2ecf20Sopenharmony_ci} 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/* 428c2ecf20Sopenharmony_ci * Single channel mixer element 438c2ecf20Sopenharmony_ci */ 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistatic int snd_sbmixer_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 468c2ecf20Sopenharmony_ci{ 478c2ecf20Sopenharmony_ci int mask = (kcontrol->private_value >> 24) & 0xff; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; 508c2ecf20Sopenharmony_ci uinfo->count = 1; 518c2ecf20Sopenharmony_ci uinfo->value.integer.min = 0; 528c2ecf20Sopenharmony_ci uinfo->value.integer.max = mask; 538c2ecf20Sopenharmony_ci return 0; 548c2ecf20Sopenharmony_ci} 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistatic int snd_sbmixer_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci struct snd_sb *sb = snd_kcontrol_chip(kcontrol); 598c2ecf20Sopenharmony_ci unsigned long flags; 608c2ecf20Sopenharmony_ci int reg = kcontrol->private_value & 0xff; 618c2ecf20Sopenharmony_ci int shift = (kcontrol->private_value >> 16) & 0xff; 628c2ecf20Sopenharmony_ci int mask = (kcontrol->private_value >> 24) & 0xff; 638c2ecf20Sopenharmony_ci unsigned char val; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci spin_lock_irqsave(&sb->mixer_lock, flags); 668c2ecf20Sopenharmony_ci val = (snd_sbmixer_read(sb, reg) >> shift) & mask; 678c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&sb->mixer_lock, flags); 688c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = val; 698c2ecf20Sopenharmony_ci return 0; 708c2ecf20Sopenharmony_ci} 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistatic int snd_sbmixer_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci struct snd_sb *sb = snd_kcontrol_chip(kcontrol); 758c2ecf20Sopenharmony_ci unsigned long flags; 768c2ecf20Sopenharmony_ci int reg = kcontrol->private_value & 0xff; 778c2ecf20Sopenharmony_ci int shift = (kcontrol->private_value >> 16) & 0x07; 788c2ecf20Sopenharmony_ci int mask = (kcontrol->private_value >> 24) & 0xff; 798c2ecf20Sopenharmony_ci int change; 808c2ecf20Sopenharmony_ci unsigned char val, oval; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci val = (ucontrol->value.integer.value[0] & mask) << shift; 838c2ecf20Sopenharmony_ci spin_lock_irqsave(&sb->mixer_lock, flags); 848c2ecf20Sopenharmony_ci oval = snd_sbmixer_read(sb, reg); 858c2ecf20Sopenharmony_ci val = (oval & ~(mask << shift)) | val; 868c2ecf20Sopenharmony_ci change = val != oval; 878c2ecf20Sopenharmony_ci if (change) 888c2ecf20Sopenharmony_ci snd_sbmixer_write(sb, reg, val); 898c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&sb->mixer_lock, flags); 908c2ecf20Sopenharmony_ci return change; 918c2ecf20Sopenharmony_ci} 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci/* 948c2ecf20Sopenharmony_ci * Double channel mixer element 958c2ecf20Sopenharmony_ci */ 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistatic int snd_sbmixer_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 988c2ecf20Sopenharmony_ci{ 998c2ecf20Sopenharmony_ci int mask = (kcontrol->private_value >> 24) & 0xff; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; 1028c2ecf20Sopenharmony_ci uinfo->count = 2; 1038c2ecf20Sopenharmony_ci uinfo->value.integer.min = 0; 1048c2ecf20Sopenharmony_ci uinfo->value.integer.max = mask; 1058c2ecf20Sopenharmony_ci return 0; 1068c2ecf20Sopenharmony_ci} 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistatic int snd_sbmixer_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1098c2ecf20Sopenharmony_ci{ 1108c2ecf20Sopenharmony_ci struct snd_sb *sb = snd_kcontrol_chip(kcontrol); 1118c2ecf20Sopenharmony_ci unsigned long flags; 1128c2ecf20Sopenharmony_ci int left_reg = kcontrol->private_value & 0xff; 1138c2ecf20Sopenharmony_ci int right_reg = (kcontrol->private_value >> 8) & 0xff; 1148c2ecf20Sopenharmony_ci int left_shift = (kcontrol->private_value >> 16) & 0x07; 1158c2ecf20Sopenharmony_ci int right_shift = (kcontrol->private_value >> 19) & 0x07; 1168c2ecf20Sopenharmony_ci int mask = (kcontrol->private_value >> 24) & 0xff; 1178c2ecf20Sopenharmony_ci unsigned char left, right; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci spin_lock_irqsave(&sb->mixer_lock, flags); 1208c2ecf20Sopenharmony_ci left = (snd_sbmixer_read(sb, left_reg) >> left_shift) & mask; 1218c2ecf20Sopenharmony_ci right = (snd_sbmixer_read(sb, right_reg) >> right_shift) & mask; 1228c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&sb->mixer_lock, flags); 1238c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = left; 1248c2ecf20Sopenharmony_ci ucontrol->value.integer.value[1] = right; 1258c2ecf20Sopenharmony_ci return 0; 1268c2ecf20Sopenharmony_ci} 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cistatic int snd_sbmixer_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1298c2ecf20Sopenharmony_ci{ 1308c2ecf20Sopenharmony_ci struct snd_sb *sb = snd_kcontrol_chip(kcontrol); 1318c2ecf20Sopenharmony_ci unsigned long flags; 1328c2ecf20Sopenharmony_ci int left_reg = kcontrol->private_value & 0xff; 1338c2ecf20Sopenharmony_ci int right_reg = (kcontrol->private_value >> 8) & 0xff; 1348c2ecf20Sopenharmony_ci int left_shift = (kcontrol->private_value >> 16) & 0x07; 1358c2ecf20Sopenharmony_ci int right_shift = (kcontrol->private_value >> 19) & 0x07; 1368c2ecf20Sopenharmony_ci int mask = (kcontrol->private_value >> 24) & 0xff; 1378c2ecf20Sopenharmony_ci int change; 1388c2ecf20Sopenharmony_ci unsigned char left, right, oleft, oright; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci left = (ucontrol->value.integer.value[0] & mask) << left_shift; 1418c2ecf20Sopenharmony_ci right = (ucontrol->value.integer.value[1] & mask) << right_shift; 1428c2ecf20Sopenharmony_ci spin_lock_irqsave(&sb->mixer_lock, flags); 1438c2ecf20Sopenharmony_ci if (left_reg == right_reg) { 1448c2ecf20Sopenharmony_ci oleft = snd_sbmixer_read(sb, left_reg); 1458c2ecf20Sopenharmony_ci left = (oleft & ~((mask << left_shift) | (mask << right_shift))) | left | right; 1468c2ecf20Sopenharmony_ci change = left != oleft; 1478c2ecf20Sopenharmony_ci if (change) 1488c2ecf20Sopenharmony_ci snd_sbmixer_write(sb, left_reg, left); 1498c2ecf20Sopenharmony_ci } else { 1508c2ecf20Sopenharmony_ci oleft = snd_sbmixer_read(sb, left_reg); 1518c2ecf20Sopenharmony_ci oright = snd_sbmixer_read(sb, right_reg); 1528c2ecf20Sopenharmony_ci left = (oleft & ~(mask << left_shift)) | left; 1538c2ecf20Sopenharmony_ci right = (oright & ~(mask << right_shift)) | right; 1548c2ecf20Sopenharmony_ci change = left != oleft || right != oright; 1558c2ecf20Sopenharmony_ci if (change) { 1568c2ecf20Sopenharmony_ci snd_sbmixer_write(sb, left_reg, left); 1578c2ecf20Sopenharmony_ci snd_sbmixer_write(sb, right_reg, right); 1588c2ecf20Sopenharmony_ci } 1598c2ecf20Sopenharmony_ci } 1608c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&sb->mixer_lock, flags); 1618c2ecf20Sopenharmony_ci return change; 1628c2ecf20Sopenharmony_ci} 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci/* 1658c2ecf20Sopenharmony_ci * DT-019x / ALS-007 capture/input switch 1668c2ecf20Sopenharmony_ci */ 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_cistatic int snd_dt019x_input_sw_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1698c2ecf20Sopenharmony_ci{ 1708c2ecf20Sopenharmony_ci static const char * const texts[5] = { 1718c2ecf20Sopenharmony_ci "CD", "Mic", "Line", "Synth", "Master" 1728c2ecf20Sopenharmony_ci }; 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci return snd_ctl_enum_info(uinfo, 1, 5, texts); 1758c2ecf20Sopenharmony_ci} 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_cistatic int snd_dt019x_input_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1788c2ecf20Sopenharmony_ci{ 1798c2ecf20Sopenharmony_ci struct snd_sb *sb = snd_kcontrol_chip(kcontrol); 1808c2ecf20Sopenharmony_ci unsigned long flags; 1818c2ecf20Sopenharmony_ci unsigned char oval; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci spin_lock_irqsave(&sb->mixer_lock, flags); 1848c2ecf20Sopenharmony_ci oval = snd_sbmixer_read(sb, SB_DT019X_CAPTURE_SW); 1858c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&sb->mixer_lock, flags); 1868c2ecf20Sopenharmony_ci switch (oval & 0x07) { 1878c2ecf20Sopenharmony_ci case SB_DT019X_CAP_CD: 1888c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = 0; 1898c2ecf20Sopenharmony_ci break; 1908c2ecf20Sopenharmony_ci case SB_DT019X_CAP_MIC: 1918c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = 1; 1928c2ecf20Sopenharmony_ci break; 1938c2ecf20Sopenharmony_ci case SB_DT019X_CAP_LINE: 1948c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = 2; 1958c2ecf20Sopenharmony_ci break; 1968c2ecf20Sopenharmony_ci case SB_DT019X_CAP_MAIN: 1978c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = 4; 1988c2ecf20Sopenharmony_ci break; 1998c2ecf20Sopenharmony_ci /* To record the synth on these cards you must record the main. */ 2008c2ecf20Sopenharmony_ci /* Thus SB_DT019X_CAP_SYNTH == SB_DT019X_CAP_MAIN and would cause */ 2018c2ecf20Sopenharmony_ci /* duplicate case labels if left uncommented. */ 2028c2ecf20Sopenharmony_ci /* case SB_DT019X_CAP_SYNTH: 2038c2ecf20Sopenharmony_ci * ucontrol->value.enumerated.item[0] = 3; 2048c2ecf20Sopenharmony_ci * break; 2058c2ecf20Sopenharmony_ci */ 2068c2ecf20Sopenharmony_ci default: 2078c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = 4; 2088c2ecf20Sopenharmony_ci break; 2098c2ecf20Sopenharmony_ci } 2108c2ecf20Sopenharmony_ci return 0; 2118c2ecf20Sopenharmony_ci} 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_cistatic int snd_dt019x_input_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2148c2ecf20Sopenharmony_ci{ 2158c2ecf20Sopenharmony_ci struct snd_sb *sb = snd_kcontrol_chip(kcontrol); 2168c2ecf20Sopenharmony_ci unsigned long flags; 2178c2ecf20Sopenharmony_ci int change; 2188c2ecf20Sopenharmony_ci unsigned char nval, oval; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci if (ucontrol->value.enumerated.item[0] > 4) 2218c2ecf20Sopenharmony_ci return -EINVAL; 2228c2ecf20Sopenharmony_ci switch (ucontrol->value.enumerated.item[0]) { 2238c2ecf20Sopenharmony_ci case 0: 2248c2ecf20Sopenharmony_ci nval = SB_DT019X_CAP_CD; 2258c2ecf20Sopenharmony_ci break; 2268c2ecf20Sopenharmony_ci case 1: 2278c2ecf20Sopenharmony_ci nval = SB_DT019X_CAP_MIC; 2288c2ecf20Sopenharmony_ci break; 2298c2ecf20Sopenharmony_ci case 2: 2308c2ecf20Sopenharmony_ci nval = SB_DT019X_CAP_LINE; 2318c2ecf20Sopenharmony_ci break; 2328c2ecf20Sopenharmony_ci case 3: 2338c2ecf20Sopenharmony_ci nval = SB_DT019X_CAP_SYNTH; 2348c2ecf20Sopenharmony_ci break; 2358c2ecf20Sopenharmony_ci case 4: 2368c2ecf20Sopenharmony_ci nval = SB_DT019X_CAP_MAIN; 2378c2ecf20Sopenharmony_ci break; 2388c2ecf20Sopenharmony_ci default: 2398c2ecf20Sopenharmony_ci nval = SB_DT019X_CAP_MAIN; 2408c2ecf20Sopenharmony_ci } 2418c2ecf20Sopenharmony_ci spin_lock_irqsave(&sb->mixer_lock, flags); 2428c2ecf20Sopenharmony_ci oval = snd_sbmixer_read(sb, SB_DT019X_CAPTURE_SW); 2438c2ecf20Sopenharmony_ci change = nval != oval; 2448c2ecf20Sopenharmony_ci if (change) 2458c2ecf20Sopenharmony_ci snd_sbmixer_write(sb, SB_DT019X_CAPTURE_SW, nval); 2468c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&sb->mixer_lock, flags); 2478c2ecf20Sopenharmony_ci return change; 2488c2ecf20Sopenharmony_ci} 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci/* 2518c2ecf20Sopenharmony_ci * ALS4000 mono recording control switch 2528c2ecf20Sopenharmony_ci */ 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_cistatic int snd_als4k_mono_capture_route_info(struct snd_kcontrol *kcontrol, 2558c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 2568c2ecf20Sopenharmony_ci{ 2578c2ecf20Sopenharmony_ci static const char * const texts[3] = { 2588c2ecf20Sopenharmony_ci "L chan only", "R chan only", "L ch/2 + R ch/2" 2598c2ecf20Sopenharmony_ci }; 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci return snd_ctl_enum_info(uinfo, 1, 3, texts); 2628c2ecf20Sopenharmony_ci} 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_cistatic int snd_als4k_mono_capture_route_get(struct snd_kcontrol *kcontrol, 2658c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 2668c2ecf20Sopenharmony_ci{ 2678c2ecf20Sopenharmony_ci struct snd_sb *sb = snd_kcontrol_chip(kcontrol); 2688c2ecf20Sopenharmony_ci unsigned long flags; 2698c2ecf20Sopenharmony_ci unsigned char oval; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci spin_lock_irqsave(&sb->mixer_lock, flags); 2728c2ecf20Sopenharmony_ci oval = snd_sbmixer_read(sb, SB_ALS4000_MONO_IO_CTRL); 2738c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&sb->mixer_lock, flags); 2748c2ecf20Sopenharmony_ci oval >>= 6; 2758c2ecf20Sopenharmony_ci if (oval > 2) 2768c2ecf20Sopenharmony_ci oval = 2; 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = oval; 2798c2ecf20Sopenharmony_ci return 0; 2808c2ecf20Sopenharmony_ci} 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_cistatic int snd_als4k_mono_capture_route_put(struct snd_kcontrol *kcontrol, 2838c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 2848c2ecf20Sopenharmony_ci{ 2858c2ecf20Sopenharmony_ci struct snd_sb *sb = snd_kcontrol_chip(kcontrol); 2868c2ecf20Sopenharmony_ci unsigned long flags; 2878c2ecf20Sopenharmony_ci int change; 2888c2ecf20Sopenharmony_ci unsigned char nval, oval; 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci if (ucontrol->value.enumerated.item[0] > 2) 2918c2ecf20Sopenharmony_ci return -EINVAL; 2928c2ecf20Sopenharmony_ci spin_lock_irqsave(&sb->mixer_lock, flags); 2938c2ecf20Sopenharmony_ci oval = snd_sbmixer_read(sb, SB_ALS4000_MONO_IO_CTRL); 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci nval = (oval & ~(3 << 6)) 2968c2ecf20Sopenharmony_ci | (ucontrol->value.enumerated.item[0] << 6); 2978c2ecf20Sopenharmony_ci change = nval != oval; 2988c2ecf20Sopenharmony_ci if (change) 2998c2ecf20Sopenharmony_ci snd_sbmixer_write(sb, SB_ALS4000_MONO_IO_CTRL, nval); 3008c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&sb->mixer_lock, flags); 3018c2ecf20Sopenharmony_ci return change; 3028c2ecf20Sopenharmony_ci} 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci/* 3058c2ecf20Sopenharmony_ci * SBPRO input multiplexer 3068c2ecf20Sopenharmony_ci */ 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_cistatic int snd_sb8mixer_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 3098c2ecf20Sopenharmony_ci{ 3108c2ecf20Sopenharmony_ci static const char * const texts[3] = { 3118c2ecf20Sopenharmony_ci "Mic", "CD", "Line" 3128c2ecf20Sopenharmony_ci }; 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci return snd_ctl_enum_info(uinfo, 1, 3, texts); 3158c2ecf20Sopenharmony_ci} 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_cistatic int snd_sb8mixer_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 3198c2ecf20Sopenharmony_ci{ 3208c2ecf20Sopenharmony_ci struct snd_sb *sb = snd_kcontrol_chip(kcontrol); 3218c2ecf20Sopenharmony_ci unsigned long flags; 3228c2ecf20Sopenharmony_ci unsigned char oval; 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci spin_lock_irqsave(&sb->mixer_lock, flags); 3258c2ecf20Sopenharmony_ci oval = snd_sbmixer_read(sb, SB_DSP_CAPTURE_SOURCE); 3268c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&sb->mixer_lock, flags); 3278c2ecf20Sopenharmony_ci switch ((oval >> 0x01) & 0x03) { 3288c2ecf20Sopenharmony_ci case SB_DSP_MIXS_CD: 3298c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = 1; 3308c2ecf20Sopenharmony_ci break; 3318c2ecf20Sopenharmony_ci case SB_DSP_MIXS_LINE: 3328c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = 2; 3338c2ecf20Sopenharmony_ci break; 3348c2ecf20Sopenharmony_ci default: 3358c2ecf20Sopenharmony_ci ucontrol->value.enumerated.item[0] = 0; 3368c2ecf20Sopenharmony_ci break; 3378c2ecf20Sopenharmony_ci } 3388c2ecf20Sopenharmony_ci return 0; 3398c2ecf20Sopenharmony_ci} 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_cistatic int snd_sb8mixer_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 3428c2ecf20Sopenharmony_ci{ 3438c2ecf20Sopenharmony_ci struct snd_sb *sb = snd_kcontrol_chip(kcontrol); 3448c2ecf20Sopenharmony_ci unsigned long flags; 3458c2ecf20Sopenharmony_ci int change; 3468c2ecf20Sopenharmony_ci unsigned char nval, oval; 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci if (ucontrol->value.enumerated.item[0] > 2) 3498c2ecf20Sopenharmony_ci return -EINVAL; 3508c2ecf20Sopenharmony_ci switch (ucontrol->value.enumerated.item[0]) { 3518c2ecf20Sopenharmony_ci case 1: 3528c2ecf20Sopenharmony_ci nval = SB_DSP_MIXS_CD; 3538c2ecf20Sopenharmony_ci break; 3548c2ecf20Sopenharmony_ci case 2: 3558c2ecf20Sopenharmony_ci nval = SB_DSP_MIXS_LINE; 3568c2ecf20Sopenharmony_ci break; 3578c2ecf20Sopenharmony_ci default: 3588c2ecf20Sopenharmony_ci nval = SB_DSP_MIXS_MIC; 3598c2ecf20Sopenharmony_ci } 3608c2ecf20Sopenharmony_ci nval <<= 1; 3618c2ecf20Sopenharmony_ci spin_lock_irqsave(&sb->mixer_lock, flags); 3628c2ecf20Sopenharmony_ci oval = snd_sbmixer_read(sb, SB_DSP_CAPTURE_SOURCE); 3638c2ecf20Sopenharmony_ci nval |= oval & ~0x06; 3648c2ecf20Sopenharmony_ci change = nval != oval; 3658c2ecf20Sopenharmony_ci if (change) 3668c2ecf20Sopenharmony_ci snd_sbmixer_write(sb, SB_DSP_CAPTURE_SOURCE, nval); 3678c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&sb->mixer_lock, flags); 3688c2ecf20Sopenharmony_ci return change; 3698c2ecf20Sopenharmony_ci} 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci/* 3728c2ecf20Sopenharmony_ci * SB16 input switch 3738c2ecf20Sopenharmony_ci */ 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_cistatic int snd_sb16mixer_info_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 3768c2ecf20Sopenharmony_ci{ 3778c2ecf20Sopenharmony_ci uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 3788c2ecf20Sopenharmony_ci uinfo->count = 4; 3798c2ecf20Sopenharmony_ci uinfo->value.integer.min = 0; 3808c2ecf20Sopenharmony_ci uinfo->value.integer.max = 1; 3818c2ecf20Sopenharmony_ci return 0; 3828c2ecf20Sopenharmony_ci} 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_cistatic int snd_sb16mixer_get_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 3858c2ecf20Sopenharmony_ci{ 3868c2ecf20Sopenharmony_ci struct snd_sb *sb = snd_kcontrol_chip(kcontrol); 3878c2ecf20Sopenharmony_ci unsigned long flags; 3888c2ecf20Sopenharmony_ci int reg1 = kcontrol->private_value & 0xff; 3898c2ecf20Sopenharmony_ci int reg2 = (kcontrol->private_value >> 8) & 0xff; 3908c2ecf20Sopenharmony_ci int left_shift = (kcontrol->private_value >> 16) & 0x0f; 3918c2ecf20Sopenharmony_ci int right_shift = (kcontrol->private_value >> 24) & 0x0f; 3928c2ecf20Sopenharmony_ci unsigned char val1, val2; 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci spin_lock_irqsave(&sb->mixer_lock, flags); 3958c2ecf20Sopenharmony_ci val1 = snd_sbmixer_read(sb, reg1); 3968c2ecf20Sopenharmony_ci val2 = snd_sbmixer_read(sb, reg2); 3978c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&sb->mixer_lock, flags); 3988c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = (val1 >> left_shift) & 0x01; 3998c2ecf20Sopenharmony_ci ucontrol->value.integer.value[1] = (val2 >> left_shift) & 0x01; 4008c2ecf20Sopenharmony_ci ucontrol->value.integer.value[2] = (val1 >> right_shift) & 0x01; 4018c2ecf20Sopenharmony_ci ucontrol->value.integer.value[3] = (val2 >> right_shift) & 0x01; 4028c2ecf20Sopenharmony_ci return 0; 4038c2ecf20Sopenharmony_ci} 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_cistatic int snd_sb16mixer_put_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 4068c2ecf20Sopenharmony_ci{ 4078c2ecf20Sopenharmony_ci struct snd_sb *sb = snd_kcontrol_chip(kcontrol); 4088c2ecf20Sopenharmony_ci unsigned long flags; 4098c2ecf20Sopenharmony_ci int reg1 = kcontrol->private_value & 0xff; 4108c2ecf20Sopenharmony_ci int reg2 = (kcontrol->private_value >> 8) & 0xff; 4118c2ecf20Sopenharmony_ci int left_shift = (kcontrol->private_value >> 16) & 0x0f; 4128c2ecf20Sopenharmony_ci int right_shift = (kcontrol->private_value >> 24) & 0x0f; 4138c2ecf20Sopenharmony_ci int change; 4148c2ecf20Sopenharmony_ci unsigned char val1, val2, oval1, oval2; 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci spin_lock_irqsave(&sb->mixer_lock, flags); 4178c2ecf20Sopenharmony_ci oval1 = snd_sbmixer_read(sb, reg1); 4188c2ecf20Sopenharmony_ci oval2 = snd_sbmixer_read(sb, reg2); 4198c2ecf20Sopenharmony_ci val1 = oval1 & ~((1 << left_shift) | (1 << right_shift)); 4208c2ecf20Sopenharmony_ci val2 = oval2 & ~((1 << left_shift) | (1 << right_shift)); 4218c2ecf20Sopenharmony_ci val1 |= (ucontrol->value.integer.value[0] & 1) << left_shift; 4228c2ecf20Sopenharmony_ci val2 |= (ucontrol->value.integer.value[1] & 1) << left_shift; 4238c2ecf20Sopenharmony_ci val1 |= (ucontrol->value.integer.value[2] & 1) << right_shift; 4248c2ecf20Sopenharmony_ci val2 |= (ucontrol->value.integer.value[3] & 1) << right_shift; 4258c2ecf20Sopenharmony_ci change = val1 != oval1 || val2 != oval2; 4268c2ecf20Sopenharmony_ci if (change) { 4278c2ecf20Sopenharmony_ci snd_sbmixer_write(sb, reg1, val1); 4288c2ecf20Sopenharmony_ci snd_sbmixer_write(sb, reg2, val2); 4298c2ecf20Sopenharmony_ci } 4308c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&sb->mixer_lock, flags); 4318c2ecf20Sopenharmony_ci return change; 4328c2ecf20Sopenharmony_ci} 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_ci/* 4368c2ecf20Sopenharmony_ci */ 4378c2ecf20Sopenharmony_ci/* 4388c2ecf20Sopenharmony_ci */ 4398c2ecf20Sopenharmony_ciint snd_sbmixer_add_ctl(struct snd_sb *chip, const char *name, int index, int type, unsigned long value) 4408c2ecf20Sopenharmony_ci{ 4418c2ecf20Sopenharmony_ci static const struct snd_kcontrol_new newctls[] = { 4428c2ecf20Sopenharmony_ci [SB_MIX_SINGLE] = { 4438c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 4448c2ecf20Sopenharmony_ci .info = snd_sbmixer_info_single, 4458c2ecf20Sopenharmony_ci .get = snd_sbmixer_get_single, 4468c2ecf20Sopenharmony_ci .put = snd_sbmixer_put_single, 4478c2ecf20Sopenharmony_ci }, 4488c2ecf20Sopenharmony_ci [SB_MIX_DOUBLE] = { 4498c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 4508c2ecf20Sopenharmony_ci .info = snd_sbmixer_info_double, 4518c2ecf20Sopenharmony_ci .get = snd_sbmixer_get_double, 4528c2ecf20Sopenharmony_ci .put = snd_sbmixer_put_double, 4538c2ecf20Sopenharmony_ci }, 4548c2ecf20Sopenharmony_ci [SB_MIX_INPUT_SW] = { 4558c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 4568c2ecf20Sopenharmony_ci .info = snd_sb16mixer_info_input_sw, 4578c2ecf20Sopenharmony_ci .get = snd_sb16mixer_get_input_sw, 4588c2ecf20Sopenharmony_ci .put = snd_sb16mixer_put_input_sw, 4598c2ecf20Sopenharmony_ci }, 4608c2ecf20Sopenharmony_ci [SB_MIX_CAPTURE_PRO] = { 4618c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 4628c2ecf20Sopenharmony_ci .info = snd_sb8mixer_info_mux, 4638c2ecf20Sopenharmony_ci .get = snd_sb8mixer_get_mux, 4648c2ecf20Sopenharmony_ci .put = snd_sb8mixer_put_mux, 4658c2ecf20Sopenharmony_ci }, 4668c2ecf20Sopenharmony_ci [SB_MIX_CAPTURE_DT019X] = { 4678c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 4688c2ecf20Sopenharmony_ci .info = snd_dt019x_input_sw_info, 4698c2ecf20Sopenharmony_ci .get = snd_dt019x_input_sw_get, 4708c2ecf20Sopenharmony_ci .put = snd_dt019x_input_sw_put, 4718c2ecf20Sopenharmony_ci }, 4728c2ecf20Sopenharmony_ci [SB_MIX_MONO_CAPTURE_ALS4K] = { 4738c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 4748c2ecf20Sopenharmony_ci .info = snd_als4k_mono_capture_route_info, 4758c2ecf20Sopenharmony_ci .get = snd_als4k_mono_capture_route_get, 4768c2ecf20Sopenharmony_ci .put = snd_als4k_mono_capture_route_put, 4778c2ecf20Sopenharmony_ci }, 4788c2ecf20Sopenharmony_ci }; 4798c2ecf20Sopenharmony_ci struct snd_kcontrol *ctl; 4808c2ecf20Sopenharmony_ci int err; 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci ctl = snd_ctl_new1(&newctls[type], chip); 4838c2ecf20Sopenharmony_ci if (! ctl) 4848c2ecf20Sopenharmony_ci return -ENOMEM; 4858c2ecf20Sopenharmony_ci strlcpy(ctl->id.name, name, sizeof(ctl->id.name)); 4868c2ecf20Sopenharmony_ci ctl->id.index = index; 4878c2ecf20Sopenharmony_ci ctl->private_value = value; 4888c2ecf20Sopenharmony_ci if ((err = snd_ctl_add(chip->card, ctl)) < 0) 4898c2ecf20Sopenharmony_ci return err; 4908c2ecf20Sopenharmony_ci return 0; 4918c2ecf20Sopenharmony_ci} 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci/* 4948c2ecf20Sopenharmony_ci * SB 2.0 specific mixer elements 4958c2ecf20Sopenharmony_ci */ 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_cistatic const struct sbmix_elem snd_sb20_controls[] = { 4988c2ecf20Sopenharmony_ci SB_SINGLE("Master Playback Volume", SB_DSP20_MASTER_DEV, 1, 7), 4998c2ecf20Sopenharmony_ci SB_SINGLE("PCM Playback Volume", SB_DSP20_PCM_DEV, 1, 3), 5008c2ecf20Sopenharmony_ci SB_SINGLE("Synth Playback Volume", SB_DSP20_FM_DEV, 1, 7), 5018c2ecf20Sopenharmony_ci SB_SINGLE("CD Playback Volume", SB_DSP20_CD_DEV, 1, 7) 5028c2ecf20Sopenharmony_ci}; 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_cistatic const unsigned char snd_sb20_init_values[][2] = { 5058c2ecf20Sopenharmony_ci { SB_DSP20_MASTER_DEV, 0 }, 5068c2ecf20Sopenharmony_ci { SB_DSP20_FM_DEV, 0 }, 5078c2ecf20Sopenharmony_ci}; 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci/* 5108c2ecf20Sopenharmony_ci * SB Pro specific mixer elements 5118c2ecf20Sopenharmony_ci */ 5128c2ecf20Sopenharmony_cistatic const struct sbmix_elem snd_sbpro_controls[] = { 5138c2ecf20Sopenharmony_ci SB_DOUBLE("Master Playback Volume", 5148c2ecf20Sopenharmony_ci SB_DSP_MASTER_DEV, SB_DSP_MASTER_DEV, 5, 1, 7), 5158c2ecf20Sopenharmony_ci SB_DOUBLE("PCM Playback Volume", 5168c2ecf20Sopenharmony_ci SB_DSP_PCM_DEV, SB_DSP_PCM_DEV, 5, 1, 7), 5178c2ecf20Sopenharmony_ci SB_SINGLE("PCM Playback Filter", SB_DSP_PLAYBACK_FILT, 5, 1), 5188c2ecf20Sopenharmony_ci SB_DOUBLE("Synth Playback Volume", 5198c2ecf20Sopenharmony_ci SB_DSP_FM_DEV, SB_DSP_FM_DEV, 5, 1, 7), 5208c2ecf20Sopenharmony_ci SB_DOUBLE("CD Playback Volume", SB_DSP_CD_DEV, SB_DSP_CD_DEV, 5, 1, 7), 5218c2ecf20Sopenharmony_ci SB_DOUBLE("Line Playback Volume", 5228c2ecf20Sopenharmony_ci SB_DSP_LINE_DEV, SB_DSP_LINE_DEV, 5, 1, 7), 5238c2ecf20Sopenharmony_ci SB_SINGLE("Mic Playback Volume", SB_DSP_MIC_DEV, 1, 3), 5248c2ecf20Sopenharmony_ci { 5258c2ecf20Sopenharmony_ci .name = "Capture Source", 5268c2ecf20Sopenharmony_ci .type = SB_MIX_CAPTURE_PRO 5278c2ecf20Sopenharmony_ci }, 5288c2ecf20Sopenharmony_ci SB_SINGLE("Capture Filter", SB_DSP_CAPTURE_FILT, 5, 1), 5298c2ecf20Sopenharmony_ci SB_SINGLE("Capture Low-Pass Filter", SB_DSP_CAPTURE_FILT, 3, 1) 5308c2ecf20Sopenharmony_ci}; 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_cistatic const unsigned char snd_sbpro_init_values[][2] = { 5338c2ecf20Sopenharmony_ci { SB_DSP_MASTER_DEV, 0 }, 5348c2ecf20Sopenharmony_ci { SB_DSP_PCM_DEV, 0 }, 5358c2ecf20Sopenharmony_ci { SB_DSP_FM_DEV, 0 }, 5368c2ecf20Sopenharmony_ci}; 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci/* 5398c2ecf20Sopenharmony_ci * SB16 specific mixer elements 5408c2ecf20Sopenharmony_ci */ 5418c2ecf20Sopenharmony_cistatic const struct sbmix_elem snd_sb16_controls[] = { 5428c2ecf20Sopenharmony_ci SB_DOUBLE("Master Playback Volume", 5438c2ecf20Sopenharmony_ci SB_DSP4_MASTER_DEV, (SB_DSP4_MASTER_DEV + 1), 3, 3, 31), 5448c2ecf20Sopenharmony_ci SB_DOUBLE("PCM Playback Volume", 5458c2ecf20Sopenharmony_ci SB_DSP4_PCM_DEV, (SB_DSP4_PCM_DEV + 1), 3, 3, 31), 5468c2ecf20Sopenharmony_ci SB16_INPUT_SW("Synth Capture Route", 5478c2ecf20Sopenharmony_ci SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 6, 5), 5488c2ecf20Sopenharmony_ci SB_DOUBLE("Synth Playback Volume", 5498c2ecf20Sopenharmony_ci SB_DSP4_SYNTH_DEV, (SB_DSP4_SYNTH_DEV + 1), 3, 3, 31), 5508c2ecf20Sopenharmony_ci SB16_INPUT_SW("CD Capture Route", 5518c2ecf20Sopenharmony_ci SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 2, 1), 5528c2ecf20Sopenharmony_ci SB_DOUBLE("CD Playback Switch", 5538c2ecf20Sopenharmony_ci SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1), 5548c2ecf20Sopenharmony_ci SB_DOUBLE("CD Playback Volume", 5558c2ecf20Sopenharmony_ci SB_DSP4_CD_DEV, (SB_DSP4_CD_DEV + 1), 3, 3, 31), 5568c2ecf20Sopenharmony_ci SB16_INPUT_SW("Mic Capture Route", 5578c2ecf20Sopenharmony_ci SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0), 5588c2ecf20Sopenharmony_ci SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1), 5598c2ecf20Sopenharmony_ci SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31), 5608c2ecf20Sopenharmony_ci SB_SINGLE("Beep Volume", SB_DSP4_SPEAKER_DEV, 6, 3), 5618c2ecf20Sopenharmony_ci SB_DOUBLE("Capture Volume", 5628c2ecf20Sopenharmony_ci SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3), 5638c2ecf20Sopenharmony_ci SB_DOUBLE("Playback Volume", 5648c2ecf20Sopenharmony_ci SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3), 5658c2ecf20Sopenharmony_ci SB16_INPUT_SW("Line Capture Route", 5668c2ecf20Sopenharmony_ci SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 4, 3), 5678c2ecf20Sopenharmony_ci SB_DOUBLE("Line Playback Switch", 5688c2ecf20Sopenharmony_ci SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1), 5698c2ecf20Sopenharmony_ci SB_DOUBLE("Line Playback Volume", 5708c2ecf20Sopenharmony_ci SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31), 5718c2ecf20Sopenharmony_ci SB_SINGLE("Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1), 5728c2ecf20Sopenharmony_ci SB_SINGLE("3D Enhancement Switch", SB_DSP4_3DSE, 0, 1), 5738c2ecf20Sopenharmony_ci SB_DOUBLE("Tone Control - Bass", 5748c2ecf20Sopenharmony_ci SB_DSP4_BASS_DEV, (SB_DSP4_BASS_DEV + 1), 4, 4, 15), 5758c2ecf20Sopenharmony_ci SB_DOUBLE("Tone Control - Treble", 5768c2ecf20Sopenharmony_ci SB_DSP4_TREBLE_DEV, (SB_DSP4_TREBLE_DEV + 1), 4, 4, 15) 5778c2ecf20Sopenharmony_ci}; 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_cistatic const unsigned char snd_sb16_init_values[][2] = { 5808c2ecf20Sopenharmony_ci { SB_DSP4_MASTER_DEV + 0, 0 }, 5818c2ecf20Sopenharmony_ci { SB_DSP4_MASTER_DEV + 1, 0 }, 5828c2ecf20Sopenharmony_ci { SB_DSP4_PCM_DEV + 0, 0 }, 5838c2ecf20Sopenharmony_ci { SB_DSP4_PCM_DEV + 1, 0 }, 5848c2ecf20Sopenharmony_ci { SB_DSP4_SYNTH_DEV + 0, 0 }, 5858c2ecf20Sopenharmony_ci { SB_DSP4_SYNTH_DEV + 1, 0 }, 5868c2ecf20Sopenharmony_ci { SB_DSP4_INPUT_LEFT, 0 }, 5878c2ecf20Sopenharmony_ci { SB_DSP4_INPUT_RIGHT, 0 }, 5888c2ecf20Sopenharmony_ci { SB_DSP4_OUTPUT_SW, 0 }, 5898c2ecf20Sopenharmony_ci { SB_DSP4_SPEAKER_DEV, 0 }, 5908c2ecf20Sopenharmony_ci}; 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci/* 5938c2ecf20Sopenharmony_ci * DT019x specific mixer elements 5948c2ecf20Sopenharmony_ci */ 5958c2ecf20Sopenharmony_cistatic const struct sbmix_elem snd_dt019x_controls[] = { 5968c2ecf20Sopenharmony_ci /* ALS4000 below has some parts which we might be lacking, 5978c2ecf20Sopenharmony_ci * e.g. snd_als4000_ctl_mono_playback_switch - check it! */ 5988c2ecf20Sopenharmony_ci SB_DOUBLE("Master Playback Volume", 5998c2ecf20Sopenharmony_ci SB_DT019X_MASTER_DEV, SB_DT019X_MASTER_DEV, 4, 0, 15), 6008c2ecf20Sopenharmony_ci SB_DOUBLE("PCM Playback Switch", 6018c2ecf20Sopenharmony_ci SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 2, 1, 1), 6028c2ecf20Sopenharmony_ci SB_DOUBLE("PCM Playback Volume", 6038c2ecf20Sopenharmony_ci SB_DT019X_PCM_DEV, SB_DT019X_PCM_DEV, 4, 0, 15), 6048c2ecf20Sopenharmony_ci SB_DOUBLE("Synth Playback Switch", 6058c2ecf20Sopenharmony_ci SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 4, 3, 1), 6068c2ecf20Sopenharmony_ci SB_DOUBLE("Synth Playback Volume", 6078c2ecf20Sopenharmony_ci SB_DT019X_SYNTH_DEV, SB_DT019X_SYNTH_DEV, 4, 0, 15), 6088c2ecf20Sopenharmony_ci SB_DOUBLE("CD Playback Switch", 6098c2ecf20Sopenharmony_ci SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1), 6108c2ecf20Sopenharmony_ci SB_DOUBLE("CD Playback Volume", 6118c2ecf20Sopenharmony_ci SB_DT019X_CD_DEV, SB_DT019X_CD_DEV, 4, 0, 15), 6128c2ecf20Sopenharmony_ci SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1), 6138c2ecf20Sopenharmony_ci SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV, 4, 7), 6148c2ecf20Sopenharmony_ci SB_SINGLE("Beep Volume", SB_DT019X_SPKR_DEV, 0, 7), 6158c2ecf20Sopenharmony_ci SB_DOUBLE("Line Playback Switch", 6168c2ecf20Sopenharmony_ci SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1), 6178c2ecf20Sopenharmony_ci SB_DOUBLE("Line Playback Volume", 6188c2ecf20Sopenharmony_ci SB_DT019X_LINE_DEV, SB_DT019X_LINE_DEV, 4, 0, 15), 6198c2ecf20Sopenharmony_ci { 6208c2ecf20Sopenharmony_ci .name = "Capture Source", 6218c2ecf20Sopenharmony_ci .type = SB_MIX_CAPTURE_DT019X 6228c2ecf20Sopenharmony_ci } 6238c2ecf20Sopenharmony_ci}; 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_cistatic const unsigned char snd_dt019x_init_values[][2] = { 6268c2ecf20Sopenharmony_ci { SB_DT019X_MASTER_DEV, 0 }, 6278c2ecf20Sopenharmony_ci { SB_DT019X_PCM_DEV, 0 }, 6288c2ecf20Sopenharmony_ci { SB_DT019X_SYNTH_DEV, 0 }, 6298c2ecf20Sopenharmony_ci { SB_DT019X_CD_DEV, 0 }, 6308c2ecf20Sopenharmony_ci { SB_DT019X_MIC_DEV, 0 }, /* Includes PC-speaker in high nibble */ 6318c2ecf20Sopenharmony_ci { SB_DT019X_LINE_DEV, 0 }, 6328c2ecf20Sopenharmony_ci { SB_DSP4_OUTPUT_SW, 0 }, 6338c2ecf20Sopenharmony_ci { SB_DT019X_OUTPUT_SW2, 0 }, 6348c2ecf20Sopenharmony_ci { SB_DT019X_CAPTURE_SW, 0x06 }, 6358c2ecf20Sopenharmony_ci}; 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci/* 6388c2ecf20Sopenharmony_ci * ALS4000 specific mixer elements 6398c2ecf20Sopenharmony_ci */ 6408c2ecf20Sopenharmony_cistatic const struct sbmix_elem snd_als4000_controls[] = { 6418c2ecf20Sopenharmony_ci SB_DOUBLE("PCM Playback Switch", 6428c2ecf20Sopenharmony_ci SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 2, 1, 1), 6438c2ecf20Sopenharmony_ci SB_DOUBLE("Synth Playback Switch", 6448c2ecf20Sopenharmony_ci SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 4, 3, 1), 6458c2ecf20Sopenharmony_ci SB_SINGLE("Mic Boost (+20dB)", SB_ALS4000_MIC_IN_GAIN, 0, 0x03), 6468c2ecf20Sopenharmony_ci SB_SINGLE("Master Mono Playback Switch", SB_ALS4000_MONO_IO_CTRL, 5, 1), 6478c2ecf20Sopenharmony_ci { 6488c2ecf20Sopenharmony_ci .name = "Master Mono Capture Route", 6498c2ecf20Sopenharmony_ci .type = SB_MIX_MONO_CAPTURE_ALS4K 6508c2ecf20Sopenharmony_ci }, 6518c2ecf20Sopenharmony_ci SB_SINGLE("Mono Playback Switch", SB_DT019X_OUTPUT_SW2, 0, 1), 6528c2ecf20Sopenharmony_ci SB_SINGLE("Analog Loopback Switch", SB_ALS4000_MIC_IN_GAIN, 7, 0x01), 6538c2ecf20Sopenharmony_ci SB_SINGLE("3D Control - Switch", SB_ALS4000_3D_SND_FX, 6, 0x01), 6548c2ecf20Sopenharmony_ci SB_SINGLE("Digital Loopback Switch", 6558c2ecf20Sopenharmony_ci SB_ALS4000_CR3_CONFIGURATION, 7, 0x01), 6568c2ecf20Sopenharmony_ci /* FIXME: functionality of 3D controls might be swapped, I didn't find 6578c2ecf20Sopenharmony_ci * a description of how to identify what is supposed to be what */ 6588c2ecf20Sopenharmony_ci SB_SINGLE("3D Control - Level", SB_ALS4000_3D_SND_FX, 0, 0x07), 6598c2ecf20Sopenharmony_ci /* FIXME: maybe there's actually some standard 3D ctrl name for it?? */ 6608c2ecf20Sopenharmony_ci SB_SINGLE("3D Control - Freq", SB_ALS4000_3D_SND_FX, 4, 0x03), 6618c2ecf20Sopenharmony_ci /* FIXME: ALS4000a.pdf mentions BBD (Bucket Brigade Device) time delay, 6628c2ecf20Sopenharmony_ci * but what ALSA 3D attribute is that actually? "Center", "Depth", 6638c2ecf20Sopenharmony_ci * "Wide" or "Space" or even "Level"? Assuming "Wide" for now... */ 6648c2ecf20Sopenharmony_ci SB_SINGLE("3D Control - Wide", SB_ALS4000_3D_TIME_DELAY, 0, 0x0f), 6658c2ecf20Sopenharmony_ci SB_SINGLE("3D PowerOff Switch", SB_ALS4000_3D_TIME_DELAY, 4, 0x01), 6668c2ecf20Sopenharmony_ci SB_SINGLE("Master Playback 8kHz / 20kHz LPF Switch", 6678c2ecf20Sopenharmony_ci SB_ALS4000_FMDAC, 5, 0x01), 6688c2ecf20Sopenharmony_ci#ifdef NOT_AVAILABLE 6698c2ecf20Sopenharmony_ci SB_SINGLE("FMDAC Switch (Option ?)", SB_ALS4000_FMDAC, 0, 0x01), 6708c2ecf20Sopenharmony_ci SB_SINGLE("QSound Mode", SB_ALS4000_QSOUND, 1, 0x1f), 6718c2ecf20Sopenharmony_ci#endif 6728c2ecf20Sopenharmony_ci}; 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_cistatic const unsigned char snd_als4000_init_values[][2] = { 6758c2ecf20Sopenharmony_ci { SB_DSP4_MASTER_DEV + 0, 0 }, 6768c2ecf20Sopenharmony_ci { SB_DSP4_MASTER_DEV + 1, 0 }, 6778c2ecf20Sopenharmony_ci { SB_DSP4_PCM_DEV + 0, 0 }, 6788c2ecf20Sopenharmony_ci { SB_DSP4_PCM_DEV + 1, 0 }, 6798c2ecf20Sopenharmony_ci { SB_DSP4_SYNTH_DEV + 0, 0 }, 6808c2ecf20Sopenharmony_ci { SB_DSP4_SYNTH_DEV + 1, 0 }, 6818c2ecf20Sopenharmony_ci { SB_DSP4_SPEAKER_DEV, 0 }, 6828c2ecf20Sopenharmony_ci { SB_DSP4_OUTPUT_SW, 0 }, 6838c2ecf20Sopenharmony_ci { SB_DSP4_INPUT_LEFT, 0 }, 6848c2ecf20Sopenharmony_ci { SB_DSP4_INPUT_RIGHT, 0 }, 6858c2ecf20Sopenharmony_ci { SB_DT019X_OUTPUT_SW2, 0 }, 6868c2ecf20Sopenharmony_ci { SB_ALS4000_MIC_IN_GAIN, 0 }, 6878c2ecf20Sopenharmony_ci}; 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ci/* 6908c2ecf20Sopenharmony_ci */ 6918c2ecf20Sopenharmony_cistatic int snd_sbmixer_init(struct snd_sb *chip, 6928c2ecf20Sopenharmony_ci const struct sbmix_elem *controls, 6938c2ecf20Sopenharmony_ci int controls_count, 6948c2ecf20Sopenharmony_ci const unsigned char map[][2], 6958c2ecf20Sopenharmony_ci int map_count, 6968c2ecf20Sopenharmony_ci char *name) 6978c2ecf20Sopenharmony_ci{ 6988c2ecf20Sopenharmony_ci unsigned long flags; 6998c2ecf20Sopenharmony_ci struct snd_card *card = chip->card; 7008c2ecf20Sopenharmony_ci int idx, err; 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_ci /* mixer reset */ 7038c2ecf20Sopenharmony_ci spin_lock_irqsave(&chip->mixer_lock, flags); 7048c2ecf20Sopenharmony_ci snd_sbmixer_write(chip, 0x00, 0x00); 7058c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&chip->mixer_lock, flags); 7068c2ecf20Sopenharmony_ci 7078c2ecf20Sopenharmony_ci /* mute and zero volume channels */ 7088c2ecf20Sopenharmony_ci for (idx = 0; idx < map_count; idx++) { 7098c2ecf20Sopenharmony_ci spin_lock_irqsave(&chip->mixer_lock, flags); 7108c2ecf20Sopenharmony_ci snd_sbmixer_write(chip, map[idx][0], map[idx][1]); 7118c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&chip->mixer_lock, flags); 7128c2ecf20Sopenharmony_ci } 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ci for (idx = 0; idx < controls_count; idx++) { 7158c2ecf20Sopenharmony_ci err = snd_sbmixer_add_ctl_elem(chip, &controls[idx]); 7168c2ecf20Sopenharmony_ci if (err < 0) 7178c2ecf20Sopenharmony_ci return err; 7188c2ecf20Sopenharmony_ci } 7198c2ecf20Sopenharmony_ci snd_component_add(card, name); 7208c2ecf20Sopenharmony_ci strcpy(card->mixername, name); 7218c2ecf20Sopenharmony_ci return 0; 7228c2ecf20Sopenharmony_ci} 7238c2ecf20Sopenharmony_ci 7248c2ecf20Sopenharmony_ciint snd_sbmixer_new(struct snd_sb *chip) 7258c2ecf20Sopenharmony_ci{ 7268c2ecf20Sopenharmony_ci struct snd_card *card; 7278c2ecf20Sopenharmony_ci int err; 7288c2ecf20Sopenharmony_ci 7298c2ecf20Sopenharmony_ci if (snd_BUG_ON(!chip || !chip->card)) 7308c2ecf20Sopenharmony_ci return -EINVAL; 7318c2ecf20Sopenharmony_ci 7328c2ecf20Sopenharmony_ci card = chip->card; 7338c2ecf20Sopenharmony_ci 7348c2ecf20Sopenharmony_ci switch (chip->hardware) { 7358c2ecf20Sopenharmony_ci case SB_HW_10: 7368c2ecf20Sopenharmony_ci return 0; /* no mixer chip on SB1.x */ 7378c2ecf20Sopenharmony_ci case SB_HW_20: 7388c2ecf20Sopenharmony_ci case SB_HW_201: 7398c2ecf20Sopenharmony_ci if ((err = snd_sbmixer_init(chip, 7408c2ecf20Sopenharmony_ci snd_sb20_controls, 7418c2ecf20Sopenharmony_ci ARRAY_SIZE(snd_sb20_controls), 7428c2ecf20Sopenharmony_ci snd_sb20_init_values, 7438c2ecf20Sopenharmony_ci ARRAY_SIZE(snd_sb20_init_values), 7448c2ecf20Sopenharmony_ci "CTL1335")) < 0) 7458c2ecf20Sopenharmony_ci return err; 7468c2ecf20Sopenharmony_ci break; 7478c2ecf20Sopenharmony_ci case SB_HW_PRO: 7488c2ecf20Sopenharmony_ci case SB_HW_JAZZ16: 7498c2ecf20Sopenharmony_ci if ((err = snd_sbmixer_init(chip, 7508c2ecf20Sopenharmony_ci snd_sbpro_controls, 7518c2ecf20Sopenharmony_ci ARRAY_SIZE(snd_sbpro_controls), 7528c2ecf20Sopenharmony_ci snd_sbpro_init_values, 7538c2ecf20Sopenharmony_ci ARRAY_SIZE(snd_sbpro_init_values), 7548c2ecf20Sopenharmony_ci "CTL1345")) < 0) 7558c2ecf20Sopenharmony_ci return err; 7568c2ecf20Sopenharmony_ci break; 7578c2ecf20Sopenharmony_ci case SB_HW_16: 7588c2ecf20Sopenharmony_ci case SB_HW_ALS100: 7598c2ecf20Sopenharmony_ci case SB_HW_CS5530: 7608c2ecf20Sopenharmony_ci if ((err = snd_sbmixer_init(chip, 7618c2ecf20Sopenharmony_ci snd_sb16_controls, 7628c2ecf20Sopenharmony_ci ARRAY_SIZE(snd_sb16_controls), 7638c2ecf20Sopenharmony_ci snd_sb16_init_values, 7648c2ecf20Sopenharmony_ci ARRAY_SIZE(snd_sb16_init_values), 7658c2ecf20Sopenharmony_ci "CTL1745")) < 0) 7668c2ecf20Sopenharmony_ci return err; 7678c2ecf20Sopenharmony_ci break; 7688c2ecf20Sopenharmony_ci case SB_HW_ALS4000: 7698c2ecf20Sopenharmony_ci /* use only the first 16 controls from SB16 */ 7708c2ecf20Sopenharmony_ci err = snd_sbmixer_init(chip, 7718c2ecf20Sopenharmony_ci snd_sb16_controls, 7728c2ecf20Sopenharmony_ci 16, 7738c2ecf20Sopenharmony_ci snd_sb16_init_values, 7748c2ecf20Sopenharmony_ci ARRAY_SIZE(snd_sb16_init_values), 7758c2ecf20Sopenharmony_ci "ALS4000"); 7768c2ecf20Sopenharmony_ci if (err < 0) 7778c2ecf20Sopenharmony_ci return err; 7788c2ecf20Sopenharmony_ci if ((err = snd_sbmixer_init(chip, 7798c2ecf20Sopenharmony_ci snd_als4000_controls, 7808c2ecf20Sopenharmony_ci ARRAY_SIZE(snd_als4000_controls), 7818c2ecf20Sopenharmony_ci snd_als4000_init_values, 7828c2ecf20Sopenharmony_ci ARRAY_SIZE(snd_als4000_init_values), 7838c2ecf20Sopenharmony_ci "ALS4000")) < 0) 7848c2ecf20Sopenharmony_ci return err; 7858c2ecf20Sopenharmony_ci break; 7868c2ecf20Sopenharmony_ci case SB_HW_DT019X: 7878c2ecf20Sopenharmony_ci err = snd_sbmixer_init(chip, 7888c2ecf20Sopenharmony_ci snd_dt019x_controls, 7898c2ecf20Sopenharmony_ci ARRAY_SIZE(snd_dt019x_controls), 7908c2ecf20Sopenharmony_ci snd_dt019x_init_values, 7918c2ecf20Sopenharmony_ci ARRAY_SIZE(snd_dt019x_init_values), 7928c2ecf20Sopenharmony_ci "DT019X"); 7938c2ecf20Sopenharmony_ci if (err < 0) 7948c2ecf20Sopenharmony_ci return err; 7958c2ecf20Sopenharmony_ci break; 7968c2ecf20Sopenharmony_ci default: 7978c2ecf20Sopenharmony_ci strcpy(card->mixername, "???"); 7988c2ecf20Sopenharmony_ci } 7998c2ecf20Sopenharmony_ci return 0; 8008c2ecf20Sopenharmony_ci} 8018c2ecf20Sopenharmony_ci 8028c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 8038c2ecf20Sopenharmony_cistatic const unsigned char sb20_saved_regs[] = { 8048c2ecf20Sopenharmony_ci SB_DSP20_MASTER_DEV, 8058c2ecf20Sopenharmony_ci SB_DSP20_PCM_DEV, 8068c2ecf20Sopenharmony_ci SB_DSP20_FM_DEV, 8078c2ecf20Sopenharmony_ci SB_DSP20_CD_DEV, 8088c2ecf20Sopenharmony_ci}; 8098c2ecf20Sopenharmony_ci 8108c2ecf20Sopenharmony_cistatic const unsigned char sbpro_saved_regs[] = { 8118c2ecf20Sopenharmony_ci SB_DSP_MASTER_DEV, 8128c2ecf20Sopenharmony_ci SB_DSP_PCM_DEV, 8138c2ecf20Sopenharmony_ci SB_DSP_PLAYBACK_FILT, 8148c2ecf20Sopenharmony_ci SB_DSP_FM_DEV, 8158c2ecf20Sopenharmony_ci SB_DSP_CD_DEV, 8168c2ecf20Sopenharmony_ci SB_DSP_LINE_DEV, 8178c2ecf20Sopenharmony_ci SB_DSP_MIC_DEV, 8188c2ecf20Sopenharmony_ci SB_DSP_CAPTURE_SOURCE, 8198c2ecf20Sopenharmony_ci SB_DSP_CAPTURE_FILT, 8208c2ecf20Sopenharmony_ci}; 8218c2ecf20Sopenharmony_ci 8228c2ecf20Sopenharmony_cistatic const unsigned char sb16_saved_regs[] = { 8238c2ecf20Sopenharmony_ci SB_DSP4_MASTER_DEV, SB_DSP4_MASTER_DEV + 1, 8248c2ecf20Sopenharmony_ci SB_DSP4_3DSE, 8258c2ecf20Sopenharmony_ci SB_DSP4_BASS_DEV, SB_DSP4_BASS_DEV + 1, 8268c2ecf20Sopenharmony_ci SB_DSP4_TREBLE_DEV, SB_DSP4_TREBLE_DEV + 1, 8278c2ecf20Sopenharmony_ci SB_DSP4_PCM_DEV, SB_DSP4_PCM_DEV + 1, 8288c2ecf20Sopenharmony_ci SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 8298c2ecf20Sopenharmony_ci SB_DSP4_SYNTH_DEV, SB_DSP4_SYNTH_DEV + 1, 8308c2ecf20Sopenharmony_ci SB_DSP4_OUTPUT_SW, 8318c2ecf20Sopenharmony_ci SB_DSP4_CD_DEV, SB_DSP4_CD_DEV + 1, 8328c2ecf20Sopenharmony_ci SB_DSP4_LINE_DEV, SB_DSP4_LINE_DEV + 1, 8338c2ecf20Sopenharmony_ci SB_DSP4_MIC_DEV, 8348c2ecf20Sopenharmony_ci SB_DSP4_SPEAKER_DEV, 8358c2ecf20Sopenharmony_ci SB_DSP4_IGAIN_DEV, SB_DSP4_IGAIN_DEV + 1, 8368c2ecf20Sopenharmony_ci SB_DSP4_OGAIN_DEV, SB_DSP4_OGAIN_DEV + 1, 8378c2ecf20Sopenharmony_ci SB_DSP4_MIC_AGC 8388c2ecf20Sopenharmony_ci}; 8398c2ecf20Sopenharmony_ci 8408c2ecf20Sopenharmony_cistatic const unsigned char dt019x_saved_regs[] = { 8418c2ecf20Sopenharmony_ci SB_DT019X_MASTER_DEV, 8428c2ecf20Sopenharmony_ci SB_DT019X_PCM_DEV, 8438c2ecf20Sopenharmony_ci SB_DT019X_SYNTH_DEV, 8448c2ecf20Sopenharmony_ci SB_DT019X_CD_DEV, 8458c2ecf20Sopenharmony_ci SB_DT019X_MIC_DEV, 8468c2ecf20Sopenharmony_ci SB_DT019X_SPKR_DEV, 8478c2ecf20Sopenharmony_ci SB_DT019X_LINE_DEV, 8488c2ecf20Sopenharmony_ci SB_DSP4_OUTPUT_SW, 8498c2ecf20Sopenharmony_ci SB_DT019X_OUTPUT_SW2, 8508c2ecf20Sopenharmony_ci SB_DT019X_CAPTURE_SW, 8518c2ecf20Sopenharmony_ci}; 8528c2ecf20Sopenharmony_ci 8538c2ecf20Sopenharmony_cistatic const unsigned char als4000_saved_regs[] = { 8548c2ecf20Sopenharmony_ci /* please verify in dsheet whether regs to be added 8558c2ecf20Sopenharmony_ci are actually real H/W or just dummy */ 8568c2ecf20Sopenharmony_ci SB_DSP4_MASTER_DEV, SB_DSP4_MASTER_DEV + 1, 8578c2ecf20Sopenharmony_ci SB_DSP4_OUTPUT_SW, 8588c2ecf20Sopenharmony_ci SB_DSP4_PCM_DEV, SB_DSP4_PCM_DEV + 1, 8598c2ecf20Sopenharmony_ci SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 8608c2ecf20Sopenharmony_ci SB_DSP4_SYNTH_DEV, SB_DSP4_SYNTH_DEV + 1, 8618c2ecf20Sopenharmony_ci SB_DSP4_CD_DEV, SB_DSP4_CD_DEV + 1, 8628c2ecf20Sopenharmony_ci SB_DSP4_MIC_DEV, 8638c2ecf20Sopenharmony_ci SB_DSP4_SPEAKER_DEV, 8648c2ecf20Sopenharmony_ci SB_DSP4_IGAIN_DEV, SB_DSP4_IGAIN_DEV + 1, 8658c2ecf20Sopenharmony_ci SB_DSP4_OGAIN_DEV, SB_DSP4_OGAIN_DEV + 1, 8668c2ecf20Sopenharmony_ci SB_DT019X_OUTPUT_SW2, 8678c2ecf20Sopenharmony_ci SB_ALS4000_MONO_IO_CTRL, 8688c2ecf20Sopenharmony_ci SB_ALS4000_MIC_IN_GAIN, 8698c2ecf20Sopenharmony_ci SB_ALS4000_FMDAC, 8708c2ecf20Sopenharmony_ci SB_ALS4000_3D_SND_FX, 8718c2ecf20Sopenharmony_ci SB_ALS4000_3D_TIME_DELAY, 8728c2ecf20Sopenharmony_ci SB_ALS4000_CR3_CONFIGURATION, 8738c2ecf20Sopenharmony_ci}; 8748c2ecf20Sopenharmony_ci 8758c2ecf20Sopenharmony_cistatic void save_mixer(struct snd_sb *chip, const unsigned char *regs, int num_regs) 8768c2ecf20Sopenharmony_ci{ 8778c2ecf20Sopenharmony_ci unsigned char *val = chip->saved_regs; 8788c2ecf20Sopenharmony_ci if (snd_BUG_ON(num_regs > ARRAY_SIZE(chip->saved_regs))) 8798c2ecf20Sopenharmony_ci return; 8808c2ecf20Sopenharmony_ci for (; num_regs; num_regs--) 8818c2ecf20Sopenharmony_ci *val++ = snd_sbmixer_read(chip, *regs++); 8828c2ecf20Sopenharmony_ci} 8838c2ecf20Sopenharmony_ci 8848c2ecf20Sopenharmony_cistatic void restore_mixer(struct snd_sb *chip, const unsigned char *regs, int num_regs) 8858c2ecf20Sopenharmony_ci{ 8868c2ecf20Sopenharmony_ci unsigned char *val = chip->saved_regs; 8878c2ecf20Sopenharmony_ci if (snd_BUG_ON(num_regs > ARRAY_SIZE(chip->saved_regs))) 8888c2ecf20Sopenharmony_ci return; 8898c2ecf20Sopenharmony_ci for (; num_regs; num_regs--) 8908c2ecf20Sopenharmony_ci snd_sbmixer_write(chip, *regs++, *val++); 8918c2ecf20Sopenharmony_ci} 8928c2ecf20Sopenharmony_ci 8938c2ecf20Sopenharmony_civoid snd_sbmixer_suspend(struct snd_sb *chip) 8948c2ecf20Sopenharmony_ci{ 8958c2ecf20Sopenharmony_ci switch (chip->hardware) { 8968c2ecf20Sopenharmony_ci case SB_HW_20: 8978c2ecf20Sopenharmony_ci case SB_HW_201: 8988c2ecf20Sopenharmony_ci save_mixer(chip, sb20_saved_regs, ARRAY_SIZE(sb20_saved_regs)); 8998c2ecf20Sopenharmony_ci break; 9008c2ecf20Sopenharmony_ci case SB_HW_PRO: 9018c2ecf20Sopenharmony_ci case SB_HW_JAZZ16: 9028c2ecf20Sopenharmony_ci save_mixer(chip, sbpro_saved_regs, ARRAY_SIZE(sbpro_saved_regs)); 9038c2ecf20Sopenharmony_ci break; 9048c2ecf20Sopenharmony_ci case SB_HW_16: 9058c2ecf20Sopenharmony_ci case SB_HW_ALS100: 9068c2ecf20Sopenharmony_ci case SB_HW_CS5530: 9078c2ecf20Sopenharmony_ci save_mixer(chip, sb16_saved_regs, ARRAY_SIZE(sb16_saved_regs)); 9088c2ecf20Sopenharmony_ci break; 9098c2ecf20Sopenharmony_ci case SB_HW_ALS4000: 9108c2ecf20Sopenharmony_ci save_mixer(chip, als4000_saved_regs, ARRAY_SIZE(als4000_saved_regs)); 9118c2ecf20Sopenharmony_ci break; 9128c2ecf20Sopenharmony_ci case SB_HW_DT019X: 9138c2ecf20Sopenharmony_ci save_mixer(chip, dt019x_saved_regs, ARRAY_SIZE(dt019x_saved_regs)); 9148c2ecf20Sopenharmony_ci break; 9158c2ecf20Sopenharmony_ci default: 9168c2ecf20Sopenharmony_ci break; 9178c2ecf20Sopenharmony_ci } 9188c2ecf20Sopenharmony_ci} 9198c2ecf20Sopenharmony_ci 9208c2ecf20Sopenharmony_civoid snd_sbmixer_resume(struct snd_sb *chip) 9218c2ecf20Sopenharmony_ci{ 9228c2ecf20Sopenharmony_ci switch (chip->hardware) { 9238c2ecf20Sopenharmony_ci case SB_HW_20: 9248c2ecf20Sopenharmony_ci case SB_HW_201: 9258c2ecf20Sopenharmony_ci restore_mixer(chip, sb20_saved_regs, ARRAY_SIZE(sb20_saved_regs)); 9268c2ecf20Sopenharmony_ci break; 9278c2ecf20Sopenharmony_ci case SB_HW_PRO: 9288c2ecf20Sopenharmony_ci case SB_HW_JAZZ16: 9298c2ecf20Sopenharmony_ci restore_mixer(chip, sbpro_saved_regs, ARRAY_SIZE(sbpro_saved_regs)); 9308c2ecf20Sopenharmony_ci break; 9318c2ecf20Sopenharmony_ci case SB_HW_16: 9328c2ecf20Sopenharmony_ci case SB_HW_ALS100: 9338c2ecf20Sopenharmony_ci case SB_HW_CS5530: 9348c2ecf20Sopenharmony_ci restore_mixer(chip, sb16_saved_regs, ARRAY_SIZE(sb16_saved_regs)); 9358c2ecf20Sopenharmony_ci break; 9368c2ecf20Sopenharmony_ci case SB_HW_ALS4000: 9378c2ecf20Sopenharmony_ci restore_mixer(chip, als4000_saved_regs, ARRAY_SIZE(als4000_saved_regs)); 9388c2ecf20Sopenharmony_ci break; 9398c2ecf20Sopenharmony_ci case SB_HW_DT019X: 9408c2ecf20Sopenharmony_ci restore_mixer(chip, dt019x_saved_regs, ARRAY_SIZE(dt019x_saved_regs)); 9418c2ecf20Sopenharmony_ci break; 9428c2ecf20Sopenharmony_ci default: 9438c2ecf20Sopenharmony_ci break; 9448c2ecf20Sopenharmony_ci } 9458c2ecf20Sopenharmony_ci} 9468c2ecf20Sopenharmony_ci#endif 947