Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *	ALSA driver for ICEnsemble VT1724 (Envy24HT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *	Lowlevel functions for Ego Sys Waveterminal 192M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *		Copyright (c) 2006 Guedez Clement <klem.dev@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *		Some functions are taken from the Prodigy192 driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *		source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <sound/tlv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "ice1712.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "envy24ht.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "wtm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "stac946x.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) struct wtm_spec {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	/* rate change needs atomic mute/unmute of all dacs*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	struct mutex mute_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *	2*ADC 6*DAC no1 ringbuffer r/w on i2c bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static inline void stac9460_put(struct snd_ice1712 *ice, int reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 						unsigned char val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	snd_vt1724_write_i2c(ice, STAC9460_I2C_ADDR, reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static inline unsigned char stac9460_get(struct snd_ice1712 *ice, int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	return snd_vt1724_read_i2c(ice, STAC9460_I2C_ADDR, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  *	2*ADC 2*DAC no2 ringbuffer r/w on i2c bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static inline void stac9460_2_put(struct snd_ice1712 *ice, int reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 						unsigned char val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	snd_vt1724_write_i2c(ice, STAC9460_2_I2C_ADDR, reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static inline unsigned char stac9460_2_get(struct snd_ice1712 *ice, int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return snd_vt1724_read_i2c(ice, STAC9460_2_I2C_ADDR, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  *	DAC mute control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static void stac9460_dac_mute_all(struct snd_ice1712 *ice, unsigned char mute,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 				unsigned short int *change_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	unsigned char new, old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int id, idx, change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	/*stac9460 1*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	for (id = 0; id < 7; id++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		if (*change_mask & (0x01 << id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			if (id == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 				idx = STAC946X_MASTER_VOLUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 				idx = STAC946X_LF_VOLUME - 1 + id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			old = stac9460_get(ice, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			new = (~mute << 7 & 0x80) | (old & ~0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			change = (new != old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			if (change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 				stac9460_put(ice, idx, new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 				*change_mask = *change_mask | (0x01 << id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 				*change_mask = *change_mask & ~(0x01 << id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	/*stac9460 2*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	for (id = 0; id < 3; id++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		if (*change_mask & (0x01 << (id + 7))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			if (id == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 				idx = STAC946X_MASTER_VOLUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 				idx = STAC946X_LF_VOLUME - 1 + id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			old = stac9460_2_get(ice, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			new = (~mute << 7 & 0x80) | (old & ~0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			change = (new != old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			if (change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				stac9460_2_put(ice, idx, new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 				*change_mask = *change_mask | (0x01 << id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 				*change_mask = *change_mask & ~(0x01 << id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define stac9460_dac_mute_info		snd_ctl_boolean_mono_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 				struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct wtm_spec *spec = ice->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	unsigned char val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	int idx, id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	mutex_lock(&spec->mute_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (kcontrol->private_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		idx = STAC946X_MASTER_VOLUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		idx = id + STAC946X_LF_VOLUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (id < 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		val = stac9460_get(ice, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		val = stac9460_2_get(ice, idx - 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	ucontrol->value.integer.value[0] = (~val >> 7) & 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	mutex_unlock(&spec->mute_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 				struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	unsigned char new, old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	int id, idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	int change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (kcontrol->private_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		idx = STAC946X_MASTER_VOLUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		old = stac9460_get(ice, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		new = (~ucontrol->value.integer.value[0] << 7 & 0x80) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 							(old & ~0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		change = (new != old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		if (change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			stac9460_put(ice, idx, new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			stac9460_2_put(ice, idx, new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		idx = id + STAC946X_LF_VOLUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		if (id < 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			old = stac9460_get(ice, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			old = stac9460_2_get(ice, idx - 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		new = (~ucontrol->value.integer.value[0] << 7 & 0x80) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 							(old & ~0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		change = (new != old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		if (change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			if (id < 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 				stac9460_put(ice, idx, new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				stac9460_2_put(ice, idx - 6, new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * 	DAC volume attenuation mixer control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 				struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	uinfo->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	uinfo->value.integer.min = 0;			/* mute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	uinfo->value.integer.max = 0x7f;		/* 0dB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 				struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	int idx, id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	unsigned char vol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (kcontrol->private_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		idx = STAC946X_MASTER_VOLUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		idx = id + STAC946X_LF_VOLUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if (id < 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		vol = stac9460_get(ice, idx) & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		vol = stac9460_2_get(ice, idx - 6) & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	ucontrol->value.integer.value[0] = 0x7f - vol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 				struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	int idx, id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	unsigned char tmp, ovol, nvol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	int change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (kcontrol->private_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		idx = STAC946X_MASTER_VOLUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		nvol = ucontrol->value.integer.value[0] & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		tmp = stac9460_get(ice, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		ovol = 0x7f - (tmp & 0x7f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		change = (ovol != nvol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		if (change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			stac9460_2_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		idx = id + STAC946X_LF_VOLUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		nvol = ucontrol->value.integer.value[0] & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		if (id < 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			tmp = stac9460_get(ice, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			tmp = stac9460_2_get(ice, idx - 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		ovol = 0x7f - (tmp & 0x7f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		change = (ovol != nvol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		if (change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			if (id < 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 				stac9460_put(ice, idx, (0x7f - nvol) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 							(tmp & 0x80));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 				stac9460_2_put(ice, idx-6, (0x7f - nvol) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 							(tmp & 0x80));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	return change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  * ADC mute control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) #define stac9460_adc_mute_info		snd_ctl_boolean_stereo_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 				struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	unsigned char val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	int i, id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (id == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		for (i = 0; i < 2; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			val = stac9460_get(ice, STAC946X_MIC_L_VOLUME + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			ucontrol->value.integer.value[i] = ~val>>7 & 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		for (i = 0; i < 2; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			val = stac9460_2_get(ice, STAC946X_MIC_L_VOLUME + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			ucontrol->value.integer.value[i] = ~val>>7 & 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 				struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	unsigned char new, old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	int i, reg, id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	int change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (id == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		for (i = 0; i < 2; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			reg = STAC946X_MIC_L_VOLUME + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			old = stac9460_get(ice, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			new = (~ucontrol->value.integer.value[i]<<7&0x80) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 								(old&~0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			change = (new != old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			if (change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 				stac9460_put(ice, reg, new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		for (i = 0; i < 2; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			reg = STAC946X_MIC_L_VOLUME + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			old = stac9460_2_get(ice, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			new = (~ucontrol->value.integer.value[i]<<7&0x80) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 								(old&~0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			change = (new != old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			if (change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 				stac9460_2_put(ice, reg, new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	return change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)  *ADC gain mixer control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 				struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	uinfo->count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	uinfo->value.integer.min = 0;		/* 0dB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	uinfo->value.integer.max = 0x0f;	/* 22.5dB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 				struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	int i, reg, id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	unsigned char vol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	if (id == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		for (i = 0; i < 2; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			reg = STAC946X_MIC_L_VOLUME + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			vol = stac9460_get(ice, reg) & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			ucontrol->value.integer.value[i] = 0x0f - vol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		for (i = 0; i < 2; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			reg = STAC946X_MIC_L_VOLUME + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			vol = stac9460_2_get(ice, reg) & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			ucontrol->value.integer.value[i] = 0x0f - vol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 				struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	int i, reg, id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	unsigned char ovol, nvol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	int change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	if (id == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		for (i = 0; i < 2; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			reg = STAC946X_MIC_L_VOLUME + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			nvol = ucontrol->value.integer.value[i] & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			ovol = 0x0f - stac9460_get(ice, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			change = ((ovol & 0x0f) != nvol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			if (change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 				stac9460_put(ice, reg, (0x0f - nvol) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 							(ovol & ~0x0f));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		for (i = 0; i < 2; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 			reg = STAC946X_MIC_L_VOLUME + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 			nvol = ucontrol->value.integer.value[i] & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			ovol = 0x0f - stac9460_2_get(ice, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 			change = ((ovol & 0x0f) != nvol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 			if (change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 				stac9460_2_put(ice, reg, (0x0f - nvol) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 							(ovol & ~0x0f));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	return change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)  * MIC / LINE switch fonction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 				struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	static const char * const texts[2] = { "Line In", "Mic" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	return snd_ctl_enum_info(uinfo, 1, 2, texts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 				struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	unsigned char val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	if (id == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		val = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	ucontrol->value.enumerated.item[0] = (val >> 7) & 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 				struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	unsigned char new, old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	int change, id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	if (id == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		old = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	new = (ucontrol->value.enumerated.item[0] << 7 & 0x80) | (old & ~0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	change = (new != old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	if (change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		if (id == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 			stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			stac9460_2_put(ice, STAC946X_GENERAL_PURPOSE, new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	return change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)  * Handler for setting correct codec rate - called when rate change is detected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	unsigned char old, new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	unsigned short int changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	struct wtm_spec *spec = ice->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	if (rate == 0)  /* no hint - S/PDIF input is master, simply return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	else if (rate <= 48000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		new = 0x08;     /* 256x, base rate mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	else if (rate <= 96000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		new = 0x11;     /* 256x, mid rate mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		new = 0x12;     /* 128x, high rate mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	old = stac9460_get(ice, STAC946X_MASTER_CLOCKING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	if (old == new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	/* change detected, setting master clock, muting first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	/* due to possible conflicts with mute controls - mutexing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	mutex_lock(&spec->mute_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	/* we have to remember current mute status for each DAC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	changed = 0xFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	stac9460_dac_mute_all(ice, 0, &changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	/*printk(KERN_DEBUG "Rate change: %d, new MC: 0x%02x\n", rate, new);*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	stac9460_put(ice, STAC946X_MASTER_CLOCKING, new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	stac9460_2_put(ice, STAC946X_MASTER_CLOCKING, new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	udelay(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	/* unmuting - only originally unmuted dacs -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	* i.e. those changed when muting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	stac9460_dac_mute_all(ice, 1, &changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	mutex_unlock(&spec->mute_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) /*Limits value in dB for fader*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)  * Control tabs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) static const struct snd_kcontrol_new stac9640_controls[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 			    SNDRV_CTL_ELEM_ACCESS_TLV_READ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		.name = "Master Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		.info = stac9460_dac_mute_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		.get = stac9460_dac_mute_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		.put = stac9460_dac_mute_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		.private_value = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		.tlv = { .p = db_scale_dac }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		.name = "Master Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		.info = stac9460_dac_vol_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		.get = stac9460_dac_vol_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		.put = stac9460_dac_vol_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		.private_value = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		.name = "MIC/Line Input Enum",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		.count = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		.info = stac9460_mic_sw_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		.get = stac9460_mic_sw_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		.put = stac9460_mic_sw_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		.name = "DAC Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		.count = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		.info = stac9460_dac_mute_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		.get = stac9460_dac_mute_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 		.put = stac9460_dac_mute_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 			    SNDRV_CTL_ELEM_ACCESS_TLV_READ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		.name = "DAC Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		.count = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		.info = stac9460_dac_vol_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		.get = stac9460_dac_vol_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		.put = stac9460_dac_vol_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		.tlv = { .p = db_scale_dac }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		.name = "ADC Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		.count = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		.info = stac9460_adc_mute_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		.get = stac9460_adc_mute_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		.put = stac9460_adc_mute_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 			    SNDRV_CTL_ELEM_ACCESS_TLV_READ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		.name = "ADC Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		.count = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		.info = stac9460_adc_vol_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		.get = stac9460_adc_vol_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		.put = stac9460_adc_vol_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		.tlv = { .p = db_scale_adc }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) /*INIT*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) static int wtm_add_controls(struct snd_ice1712 *ice)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	for (i = 0; i < ARRAY_SIZE(stac9640_controls); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 		err = snd_ctl_add(ice->card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 				snd_ctl_new1(&stac9640_controls[i], ice));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) static int wtm_init(struct snd_ice1712 *ice)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	static const unsigned short stac_inits_wtm[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		STAC946X_RESET, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 		STAC946X_MASTER_CLOCKING, 0x11,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		(unsigned short)-1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	const unsigned short *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	struct wtm_spec *spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	/*WTM 192M*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	ice->num_total_dacs = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	ice->num_total_adcs = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	ice->force_rdma1 = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	/*init mutex for dac mute conflict*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	if (!spec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	ice->spec = spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	mutex_init(&spec->mute_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	/*initialize codec*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	p = stac_inits_wtm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	for (; *p != (unsigned short)-1; p += 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 		stac9460_put(ice, p[0], p[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 		stac9460_2_put(ice, p[0], p[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	ice->gpio.set_pro_rate = stac9460_set_rate_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) static const unsigned char wtm_eeprom[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	[ICE_EEP2_SYSCONF]      = 0x67, /*SYSCONF: clock 192KHz, mpu401,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 							4ADC, 8DAC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	[ICE_EEP2_ACLINK]       = 0x80, /* ACLINK : I2S */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	[ICE_EEP2_I2S]          = 0xf8, /* I2S: vol; 96k, 24bit, 192k */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	[ICE_EEP2_SPDIF]        = 0xc1, /*SPDIF: out-en, spidf ext out*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	[ICE_EEP2_GPIO_DIR]     = 0x9f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	[ICE_EEP2_GPIO_DIR1]    = 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	[ICE_EEP2_GPIO_DIR2]    = 0x7f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	[ICE_EEP2_GPIO_MASK]    = 0x9f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	[ICE_EEP2_GPIO_MASK1]   = 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	[ICE_EEP2_GPIO_MASK2]   = 0x7f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	[ICE_EEP2_GPIO_STATE]   = 0x16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	[ICE_EEP2_GPIO_STATE1]  = 0x80,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	[ICE_EEP2_GPIO_STATE2]  = 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) /*entry point*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) struct snd_ice1712_card_info snd_vt1724_wtm_cards[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 		.subvendor = VT1724_SUBDEVICE_WTM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 		.name = "ESI Waveterminal 192M",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 		.model = "WT192M",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 		.chip_init = wtm_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 		.build_controls = wtm_add_controls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 		.eeprom_size = sizeof(wtm_eeprom),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		.eeprom_data = wtm_eeprom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	{} /*terminator*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) };