xref: /openbmc/linux/sound/pci/ice1712/prodigy192.c (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  *   ALSA driver for ICEnsemble VT1724 (Envy24HT)
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  *   Lowlevel functions for AudioTrak Prodigy 192 cards
67d4b4380SPavel Hofman  *   Supported IEC958 input from optional MI/ODI/O add-on card.
77d4b4380SPavel Hofman  *
87d4b4380SPavel Hofman  *   Specifics (SW, HW):
97d4b4380SPavel Hofman  *   -------------------
107d4b4380SPavel Hofman  *   	* 49.5MHz crystal
117d4b4380SPavel Hofman  *   	* SPDIF-OUT on the card:
127d4b4380SPavel Hofman  *  	  - coax (through isolation transformer)/toslink supplied by
137d4b4380SPavel Hofman  *          74HC04 gates - 3 in parallel
147d4b4380SPavel Hofman  *   	  - output switched between on-board CD drive dig-out connector
157d4b4380SPavel Hofman  *          and ice1724 SPDTX pin, using 74HC02 NOR gates, controlled
167d4b4380SPavel Hofman  *          by GPIO20 (0 = CD dig-out, 1 = SPDTX)
177d4b4380SPavel Hofman  *   	* SPDTX goes straight to MI/ODI/O card's SPDIF-OUT coax
187d4b4380SPavel Hofman  *
197d4b4380SPavel Hofman  *   	* MI/ODI/O card: AK4114 based, used for iec958 input only
207d4b4380SPavel Hofman  *   		- toslink input -> RX0
217d4b4380SPavel Hofman  *   		- coax input -> RX1
227d4b4380SPavel Hofman  *   		- 4wire protocol:
237d4b4380SPavel Hofman  *   			AK4114		ICE1724
247d4b4380SPavel Hofman  *   			------------------------------
257d4b4380SPavel Hofman  * 			CDTO (pin 32) -- GPIO11 pin 86
267d4b4380SPavel Hofman  * 			CDTI (pin 33) -- GPIO10 pin 77
277d4b4380SPavel Hofman  * 			CCLK (pin 34) -- GPIO9 pin 76
287d4b4380SPavel Hofman  * 			CSN  (pin 35) -- GPIO8 pin 75
297d4b4380SPavel Hofman  *   		- output data Mode 7 (24bit, I2S, slave)
30c5a30f85SPavel Hofman  *		- both MCKO1 and MCKO2 of ak4114 are fed to FPGA, which
31c5a30f85SPavel Hofman  *		  outputs master clock to SPMCLKIN of ice1724.
32c5a30f85SPavel Hofman  *		  Experimentally I found out that only a combination of
33c5a30f85SPavel Hofman  *		  OCKS0=1, OCKS1=1 (128fs, 64fs output) and ice1724 -
34c5a30f85SPavel Hofman  *		  VT1724_MT_I2S_MCLK_128X=0 (256fs input) yields correct
35*c7fabbc5SRandy Dunlap  *		  sampling rate. That means that the FPGA doubles the
36c5a30f85SPavel Hofman  *		  MCK01 rate.
371da177e4SLinus Torvalds  *
381da177e4SLinus Torvalds  *	Copyright (c) 2003 Takashi Iwai <tiwai@suse.de>
391da177e4SLinus Torvalds  *      Copyright (c) 2003 Dimitromanolakis Apostolos <apostol@cs.utoronto.ca>
401da177e4SLinus Torvalds  *      Copyright (c) 2004 Kouichi ONO <co2b@ceres.dti.ne.jp>
411da177e4SLinus Torvalds  */
421da177e4SLinus Torvalds 
431da177e4SLinus Torvalds #include <linux/delay.h>
441da177e4SLinus Torvalds #include <linux/interrupt.h>
451da177e4SLinus Torvalds #include <linux/init.h>
461da177e4SLinus Torvalds #include <linux/slab.h>
471da177e4SLinus Torvalds #include <sound/core.h>
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds #include "ice1712.h"
501da177e4SLinus Torvalds #include "envy24ht.h"
511da177e4SLinus Torvalds #include "prodigy192.h"
521da177e4SLinus Torvalds #include "stac946x.h"
53f640c320STakashi Iwai #include <sound/tlv.h>
541da177e4SLinus Torvalds 
557cda8ba9STakashi Iwai struct prodigy192_spec {
567cda8ba9STakashi Iwai 	struct ak4114 *ak4114;
577cda8ba9STakashi Iwai 	/* rate change needs atomic mute/unmute of all dacs*/
587cda8ba9STakashi Iwai 	struct mutex mute_mutex;
597cda8ba9STakashi Iwai };
607cda8ba9STakashi Iwai 
stac9460_put(struct snd_ice1712 * ice,int reg,unsigned char val)61ab0c7d72STakashi Iwai static inline void stac9460_put(struct snd_ice1712 *ice, int reg, unsigned char val)
621da177e4SLinus Torvalds {
631da177e4SLinus Torvalds 	snd_vt1724_write_i2c(ice, PRODIGY192_STAC9460_ADDR, reg, val);
641da177e4SLinus Torvalds }
651da177e4SLinus Torvalds 
stac9460_get(struct snd_ice1712 * ice,int reg)66ab0c7d72STakashi Iwai static inline unsigned char stac9460_get(struct snd_ice1712 *ice, int reg)
671da177e4SLinus Torvalds {
681da177e4SLinus Torvalds 	return snd_vt1724_read_i2c(ice, PRODIGY192_STAC9460_ADDR, reg);
691da177e4SLinus Torvalds }
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds /*
721da177e4SLinus Torvalds  * DAC mute control
731da177e4SLinus Torvalds  */
746632d64bSPavel Hofman 
756632d64bSPavel Hofman /*
766632d64bSPavel Hofman  * idx = STAC9460 volume register number, mute: 0 = mute, 1 = unmute
776632d64bSPavel Hofman  */
stac9460_dac_mute(struct snd_ice1712 * ice,int idx,unsigned char mute)786632d64bSPavel Hofman static int stac9460_dac_mute(struct snd_ice1712 *ice, int idx,
796632d64bSPavel Hofman 		unsigned char mute)
806632d64bSPavel Hofman {
816632d64bSPavel Hofman 	unsigned char new, old;
826632d64bSPavel Hofman 	int change;
836632d64bSPavel Hofman 	old = stac9460_get(ice, idx);
846632d64bSPavel Hofman 	new = (~mute << 7 & 0x80) | (old & ~0x80);
856632d64bSPavel Hofman 	change = (new != old);
866632d64bSPavel Hofman 	if (change)
876dfb5affSTakashi Iwai 		/* dev_dbg(ice->card->dev, "Volume register 0x%02x: 0x%02x\n", idx, new);*/
886632d64bSPavel Hofman 		stac9460_put(ice, idx, new);
896632d64bSPavel Hofman 	return change;
906632d64bSPavel Hofman }
916632d64bSPavel Hofman 
92a5ce8890STakashi Iwai #define stac9460_dac_mute_info		snd_ctl_boolean_mono_info
931da177e4SLinus Torvalds 
stac9460_dac_mute_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)94ab0c7d72STakashi Iwai static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
951da177e4SLinus Torvalds {
96ab0c7d72STakashi Iwai 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
971da177e4SLinus Torvalds 	unsigned char val;
981da177e4SLinus Torvalds 	int idx;
991da177e4SLinus Torvalds 
1001da177e4SLinus Torvalds 	if (kcontrol->private_value)
1011da177e4SLinus Torvalds 		idx = STAC946X_MASTER_VOLUME;
1021da177e4SLinus Torvalds 	else
1031da177e4SLinus Torvalds 		idx  = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
1041da177e4SLinus Torvalds 	val = stac9460_get(ice, idx);
1051da177e4SLinus Torvalds 	ucontrol->value.integer.value[0] = (~val >> 7) & 0x1;
1061da177e4SLinus Torvalds 	return 0;
1071da177e4SLinus Torvalds }
1081da177e4SLinus Torvalds 
stac9460_dac_mute_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)109ab0c7d72STakashi Iwai static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1101da177e4SLinus Torvalds {
111ab0c7d72STakashi Iwai 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1127cda8ba9STakashi Iwai 	struct prodigy192_spec *spec = ice->spec;
1136632d64bSPavel Hofman 	int idx, change;
1141da177e4SLinus Torvalds 
1151da177e4SLinus Torvalds 	if (kcontrol->private_value)
1161da177e4SLinus Torvalds 		idx = STAC946X_MASTER_VOLUME;
1171da177e4SLinus Torvalds 	else
1181da177e4SLinus Torvalds 		idx  = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
1196632d64bSPavel Hofman 	/* due to possible conflicts with stac9460_set_rate_val, mutexing */
1207cda8ba9STakashi Iwai 	mutex_lock(&spec->mute_mutex);
121e2ea7cfcSTakashi Iwai 	/*
1226dfb5affSTakashi Iwai 	dev_dbg(ice->card->dev, "Mute put: reg 0x%02x, ctrl value: 0x%02x\n", idx,
123e2ea7cfcSTakashi Iwai 	       ucontrol->value.integer.value[0]);
124e2ea7cfcSTakashi Iwai 	*/
1256632d64bSPavel Hofman 	change = stac9460_dac_mute(ice, idx, ucontrol->value.integer.value[0]);
1267cda8ba9STakashi Iwai 	mutex_unlock(&spec->mute_mutex);
1271da177e4SLinus Torvalds 	return change;
1281da177e4SLinus Torvalds }
1291da177e4SLinus Torvalds 
1301da177e4SLinus Torvalds /*
1311da177e4SLinus Torvalds  * DAC volume attenuation mixer control
1321da177e4SLinus Torvalds  */
stac9460_dac_vol_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)133ab0c7d72STakashi Iwai static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1341da177e4SLinus Torvalds {
1351da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1361da177e4SLinus Torvalds 	uinfo->count = 1;
1371da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;			/* mute */
1381da177e4SLinus Torvalds 	uinfo->value.integer.max = 0x7f;		/* 0dB */
1391da177e4SLinus Torvalds 	return 0;
1401da177e4SLinus Torvalds }
1411da177e4SLinus Torvalds 
stac9460_dac_vol_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)142ab0c7d72STakashi Iwai static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1431da177e4SLinus Torvalds {
144ab0c7d72STakashi Iwai 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1451da177e4SLinus Torvalds 	int idx;
1461da177e4SLinus Torvalds 	unsigned char vol;
1471da177e4SLinus Torvalds 
1481da177e4SLinus Torvalds 	if (kcontrol->private_value)
1491da177e4SLinus Torvalds 		idx = STAC946X_MASTER_VOLUME;
1501da177e4SLinus Torvalds 	else
1511da177e4SLinus Torvalds 		idx  = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
1521da177e4SLinus Torvalds 	vol = stac9460_get(ice, idx) & 0x7f;
1531da177e4SLinus Torvalds 	ucontrol->value.integer.value[0] = 0x7f - vol;
1541da177e4SLinus Torvalds 
1551da177e4SLinus Torvalds 	return 0;
1561da177e4SLinus Torvalds }
1571da177e4SLinus Torvalds 
stac9460_dac_vol_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)158ab0c7d72STakashi Iwai static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1591da177e4SLinus Torvalds {
160ab0c7d72STakashi Iwai 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1611da177e4SLinus Torvalds 	int idx;
1621da177e4SLinus Torvalds 	unsigned char tmp, ovol, nvol;
1631da177e4SLinus Torvalds 	int change;
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds 	if (kcontrol->private_value)
1661da177e4SLinus Torvalds 		idx = STAC946X_MASTER_VOLUME;
1671da177e4SLinus Torvalds 	else
1681da177e4SLinus Torvalds 		idx  = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
1691da177e4SLinus Torvalds 	nvol = ucontrol->value.integer.value[0];
1701da177e4SLinus Torvalds 	tmp = stac9460_get(ice, idx);
1711da177e4SLinus Torvalds 	ovol = 0x7f - (tmp & 0x7f);
1721da177e4SLinus Torvalds 	change = (ovol != nvol);
1731da177e4SLinus Torvalds 	if (change) {
1746632d64bSPavel Hofman 		ovol =  (0x7f - nvol) | (tmp & 0x80);
175e2ea7cfcSTakashi Iwai 		/*
1766dfb5affSTakashi Iwai 		dev_dbg(ice->card->dev, "DAC Volume: reg 0x%02x: 0x%02x\n",
177e2ea7cfcSTakashi Iwai 		       idx, ovol);
178e2ea7cfcSTakashi Iwai 		*/
1791da177e4SLinus Torvalds 		stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
1801da177e4SLinus Torvalds 	}
1811da177e4SLinus Torvalds 	return change;
1821da177e4SLinus Torvalds }
1831da177e4SLinus Torvalds 
1841da177e4SLinus Torvalds /*
1851da177e4SLinus Torvalds  * ADC mute control
1861da177e4SLinus Torvalds  */
187a5ce8890STakashi Iwai #define stac9460_adc_mute_info		snd_ctl_boolean_stereo_info
1881da177e4SLinus Torvalds 
stac9460_adc_mute_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)189ab0c7d72STakashi Iwai static int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1901da177e4SLinus Torvalds {
191ab0c7d72STakashi Iwai 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1921da177e4SLinus Torvalds 	unsigned char val;
1931da177e4SLinus Torvalds 	int i;
1941da177e4SLinus Torvalds 
1951da177e4SLinus Torvalds 	for (i = 0; i < 2; ++i) {
1961da177e4SLinus Torvalds 		val = stac9460_get(ice, STAC946X_MIC_L_VOLUME + i);
1971da177e4SLinus Torvalds 		ucontrol->value.integer.value[i] = ~val>>7 & 0x1;
1981da177e4SLinus Torvalds 	}
1991da177e4SLinus Torvalds 
2001da177e4SLinus Torvalds 	return 0;
2011da177e4SLinus Torvalds }
2021da177e4SLinus Torvalds 
stac9460_adc_mute_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)203ab0c7d72STakashi Iwai static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2041da177e4SLinus Torvalds {
205ab0c7d72STakashi Iwai 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2061da177e4SLinus Torvalds 	unsigned char new, old;
2071da177e4SLinus Torvalds 	int i, reg;
2081da177e4SLinus Torvalds 	int change;
2091da177e4SLinus Torvalds 
2101da177e4SLinus Torvalds 	for (i = 0; i < 2; ++i) {
2111da177e4SLinus Torvalds 		reg = STAC946X_MIC_L_VOLUME + i;
2121da177e4SLinus Torvalds 		old = stac9460_get(ice, reg);
2131da177e4SLinus Torvalds 		new = (~ucontrol->value.integer.value[i]<<7&0x80) | (old&~0x80);
2141da177e4SLinus Torvalds 		change = (new != old);
2151da177e4SLinus Torvalds 		if (change)
2161da177e4SLinus Torvalds 			stac9460_put(ice, reg, new);
2171da177e4SLinus Torvalds 	}
2181da177e4SLinus Torvalds 
2191da177e4SLinus Torvalds 	return change;
2201da177e4SLinus Torvalds }
2211da177e4SLinus Torvalds 
2221da177e4SLinus Torvalds /*
2231da177e4SLinus Torvalds  * ADC gain mixer control
2241da177e4SLinus Torvalds  */
stac9460_adc_vol_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)225ab0c7d72STakashi Iwai static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2261da177e4SLinus Torvalds {
2271da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2281da177e4SLinus Torvalds 	uinfo->count = 2;
2291da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;		/* 0dB */
2301da177e4SLinus Torvalds 	uinfo->value.integer.max = 0x0f;	/* 22.5dB */
2311da177e4SLinus Torvalds 	return 0;
2321da177e4SLinus Torvalds }
2331da177e4SLinus Torvalds 
stac9460_adc_vol_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)234ab0c7d72STakashi Iwai static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2351da177e4SLinus Torvalds {
236ab0c7d72STakashi Iwai 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2371da177e4SLinus Torvalds 	int i, reg;
2381da177e4SLinus Torvalds 	unsigned char vol;
2391da177e4SLinus Torvalds 
2401da177e4SLinus Torvalds 	for (i = 0; i < 2; ++i) {
2411da177e4SLinus Torvalds 		reg = STAC946X_MIC_L_VOLUME + i;
2421da177e4SLinus Torvalds 		vol = stac9460_get(ice, reg) & 0x0f;
2431da177e4SLinus Torvalds 		ucontrol->value.integer.value[i] = 0x0f - vol;
2441da177e4SLinus Torvalds 	}
2451da177e4SLinus Torvalds 
2461da177e4SLinus Torvalds 	return 0;
2471da177e4SLinus Torvalds }
2481da177e4SLinus Torvalds 
stac9460_adc_vol_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)249ab0c7d72STakashi Iwai static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2501da177e4SLinus Torvalds {
251ab0c7d72STakashi Iwai 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2521da177e4SLinus Torvalds 	int i, reg;
2531da177e4SLinus Torvalds 	unsigned char ovol, nvol;
2541da177e4SLinus Torvalds 	int change;
2551da177e4SLinus Torvalds 
2561da177e4SLinus Torvalds 	for (i = 0; i < 2; ++i) {
2571da177e4SLinus Torvalds 		reg = STAC946X_MIC_L_VOLUME + i;
2589cd17cd2STakashi Iwai 		nvol = ucontrol->value.integer.value[i] & 0x0f;
2591da177e4SLinus Torvalds 		ovol = 0x0f - stac9460_get(ice, reg);
2601da177e4SLinus Torvalds 		change = ((ovol & 0x0f)  != nvol);
2611da177e4SLinus Torvalds 		if (change)
2621da177e4SLinus Torvalds 			stac9460_put(ice, reg, (0x0f - nvol) | (ovol & ~0x0f));
2631da177e4SLinus Torvalds 	}
2641da177e4SLinus Torvalds 
2651da177e4SLinus Torvalds 	return change;
2661da177e4SLinus Torvalds }
2671da177e4SLinus Torvalds 
stac9460_mic_sw_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)2687d4b4380SPavel Hofman static int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol,
2697d4b4380SPavel Hofman 	       			struct snd_ctl_elem_info *uinfo)
2707d4b4380SPavel Hofman {
271a2af050fSTakashi Iwai 	static const char * const texts[2] = { "Line In", "Mic" };
2727d4b4380SPavel Hofman 
273597da2e4STakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 2, texts);
2747d4b4380SPavel Hofman }
2757d4b4380SPavel Hofman 
2767d4b4380SPavel Hofman 
stac9460_mic_sw_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2777d4b4380SPavel Hofman static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,
2787d4b4380SPavel Hofman 	       		struct snd_ctl_elem_value *ucontrol)
2797d4b4380SPavel Hofman {
2807d4b4380SPavel Hofman 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2817d4b4380SPavel Hofman 	unsigned char val;
2827d4b4380SPavel Hofman 
2837d4b4380SPavel Hofman 	val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
2847d4b4380SPavel Hofman 	ucontrol->value.enumerated.item[0] = (val >> 7) & 0x1;
2857d4b4380SPavel Hofman 	return 0;
2867d4b4380SPavel Hofman }
2877d4b4380SPavel Hofman 
stac9460_mic_sw_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2887d4b4380SPavel Hofman static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
2897d4b4380SPavel Hofman 	       		struct snd_ctl_elem_value *ucontrol)
2907d4b4380SPavel Hofman {
2917d4b4380SPavel Hofman 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2927d4b4380SPavel Hofman 	unsigned char new, old;
2937d4b4380SPavel Hofman 	int change;
2947d4b4380SPavel Hofman 	old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
2957d4b4380SPavel Hofman 	new = (ucontrol->value.enumerated.item[0] << 7 & 0x80) | (old & ~0x80);
2967d4b4380SPavel Hofman 	change = (new != old);
2977d4b4380SPavel Hofman 	if (change)
2987d4b4380SPavel Hofman 		stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new);
2997d4b4380SPavel Hofman 	return change;
3007d4b4380SPavel Hofman }
3016632d64bSPavel Hofman /*
3026632d64bSPavel Hofman  * Handler for setting correct codec rate - called when rate change is detected
3036632d64bSPavel Hofman  */
stac9460_set_rate_val(struct snd_ice1712 * ice,unsigned int rate)304841b23d4SPavel Hofman static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)
3056632d64bSPavel Hofman {
3066632d64bSPavel Hofman 	unsigned char old, new;
3076632d64bSPavel Hofman 	int idx;
3086632d64bSPavel Hofman 	unsigned char changed[7];
3097cda8ba9STakashi Iwai 	struct prodigy192_spec *spec = ice->spec;
3106632d64bSPavel Hofman 
3116632d64bSPavel Hofman 	if (rate == 0)  /* no hint - S/PDIF input is master, simply return */
3126632d64bSPavel Hofman 		return;
3136632d64bSPavel Hofman 	else if (rate <= 48000)
3146632d64bSPavel Hofman 		new = 0x08;	/* 256x, base rate mode */
3156632d64bSPavel Hofman 	else if (rate <= 96000)
3166632d64bSPavel Hofman 		new = 0x11;	/* 256x, mid rate mode */
3176632d64bSPavel Hofman 	else
3186632d64bSPavel Hofman 		new = 0x12;	/* 128x, high rate mode */
3196632d64bSPavel Hofman 	old = stac9460_get(ice, STAC946X_MASTER_CLOCKING);
3206632d64bSPavel Hofman 	if (old == new)
3216632d64bSPavel Hofman 		return;
3226632d64bSPavel Hofman 	/* change detected, setting master clock, muting first */
3236632d64bSPavel Hofman 	/* due to possible conflicts with mute controls - mutexing */
3247cda8ba9STakashi Iwai 	mutex_lock(&spec->mute_mutex);
3256632d64bSPavel Hofman 	/* we have to remember current mute status for each DAC */
3266632d64bSPavel Hofman 	for (idx = 0; idx < 7 ; ++idx)
3276632d64bSPavel Hofman 		changed[idx] = stac9460_dac_mute(ice,
3286632d64bSPavel Hofman 				STAC946X_MASTER_VOLUME + idx, 0);
3296dfb5affSTakashi Iwai 	/*dev_dbg(ice->card->dev, "Rate change: %d, new MC: 0x%02x\n", rate, new);*/
3306632d64bSPavel Hofman 	stac9460_put(ice, STAC946X_MASTER_CLOCKING, new);
3316632d64bSPavel Hofman 	udelay(10);
3326632d64bSPavel Hofman 	/* unmuting - only originally unmuted dacs -
3336632d64bSPavel Hofman 	 * i.e. those changed when muting */
3346632d64bSPavel Hofman 	for (idx = 0; idx < 7 ; ++idx) {
3356632d64bSPavel Hofman 		if (changed[idx])
3366632d64bSPavel Hofman 			stac9460_dac_mute(ice, STAC946X_MASTER_VOLUME + idx, 1);
3376632d64bSPavel Hofman 	}
3387cda8ba9STakashi Iwai 	mutex_unlock(&spec->mute_mutex);
3396632d64bSPavel Hofman }
3406632d64bSPavel Hofman 
3411da177e4SLinus Torvalds 
3420cb29ea0STakashi Iwai static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0);
3430cb29ea0STakashi Iwai static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0);
344f640c320STakashi Iwai 
3451da177e4SLinus Torvalds /*
3461da177e4SLinus Torvalds  * mixers
3471da177e4SLinus Torvalds  */
3481da177e4SLinus Torvalds 
349b4e5e707STakashi Iwai static const struct snd_kcontrol_new stac_controls[] = {
3501da177e4SLinus Torvalds 	{
3511da177e4SLinus Torvalds 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3521da177e4SLinus Torvalds 		.name = "Master Playback Switch",
3531da177e4SLinus Torvalds 		.info = stac9460_dac_mute_info,
3541da177e4SLinus Torvalds 		.get = stac9460_dac_mute_get,
3551da177e4SLinus Torvalds 		.put = stac9460_dac_mute_put,
3561da177e4SLinus Torvalds 		.private_value = 1,
357f640c320STakashi Iwai 		.tlv = { .p = db_scale_dac }
3581da177e4SLinus Torvalds 	},
3591da177e4SLinus Torvalds 	{
3601da177e4SLinus Torvalds 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
361f640c320STakashi Iwai 		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
362f640c320STakashi Iwai 			   SNDRV_CTL_ELEM_ACCESS_TLV_READ),
3631da177e4SLinus Torvalds 		.name = "Master Playback Volume",
3641da177e4SLinus Torvalds 		.info = stac9460_dac_vol_info,
3651da177e4SLinus Torvalds 		.get = stac9460_dac_vol_get,
3661da177e4SLinus Torvalds 		.put = stac9460_dac_vol_put,
3671da177e4SLinus Torvalds 		.private_value = 1,
368f640c320STakashi Iwai 		.tlv = { .p = db_scale_dac }
3691da177e4SLinus Torvalds 	},
3701da177e4SLinus Torvalds 	{
3711da177e4SLinus Torvalds 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3721da177e4SLinus Torvalds 		.name = "DAC Switch",
3731da177e4SLinus Torvalds 		.count = 6,
3741da177e4SLinus Torvalds 		.info = stac9460_dac_mute_info,
3751da177e4SLinus Torvalds 		.get = stac9460_dac_mute_get,
3761da177e4SLinus Torvalds 		.put = stac9460_dac_mute_put,
3771da177e4SLinus Torvalds 	},
3781da177e4SLinus Torvalds 	{
3791da177e4SLinus Torvalds 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
380f640c320STakashi Iwai 		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
381f640c320STakashi Iwai 			   SNDRV_CTL_ELEM_ACCESS_TLV_READ),
3821da177e4SLinus Torvalds 		.name = "DAC Volume",
3831da177e4SLinus Torvalds 		.count = 6,
3841da177e4SLinus Torvalds 		.info = stac9460_dac_vol_info,
3851da177e4SLinus Torvalds 		.get = stac9460_dac_vol_get,
3861da177e4SLinus Torvalds 		.put = stac9460_dac_vol_put,
387f640c320STakashi Iwai 		.tlv = { .p = db_scale_dac }
3881da177e4SLinus Torvalds 	},
3891da177e4SLinus Torvalds 	{
3901da177e4SLinus Torvalds 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3917d4b4380SPavel Hofman 		.name = "ADC Capture Switch",
3921da177e4SLinus Torvalds 		.count = 1,
3931da177e4SLinus Torvalds 		.info = stac9460_adc_mute_info,
3941da177e4SLinus Torvalds 		.get = stac9460_adc_mute_get,
3951da177e4SLinus Torvalds 		.put = stac9460_adc_mute_put,
3961da177e4SLinus Torvalds 
3971da177e4SLinus Torvalds 	},
3981da177e4SLinus Torvalds 	{
3991da177e4SLinus Torvalds 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
400f640c320STakashi Iwai 		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
401f640c320STakashi Iwai 			   SNDRV_CTL_ELEM_ACCESS_TLV_READ),
4027d4b4380SPavel Hofman 		.name = "ADC Capture Volume",
4031da177e4SLinus Torvalds 		.count = 1,
4041da177e4SLinus Torvalds 		.info = stac9460_adc_vol_info,
4051da177e4SLinus Torvalds 		.get = stac9460_adc_vol_get,
4061da177e4SLinus Torvalds 		.put = stac9460_adc_vol_put,
407f640c320STakashi Iwai 		.tlv = { .p = db_scale_adc }
4081da177e4SLinus Torvalds 	},
4097d4b4380SPavel Hofman 	{
4107d4b4380SPavel Hofman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4117d4b4380SPavel Hofman 		.name = "Analog Capture Input",
4127d4b4380SPavel Hofman 		.info = stac9460_mic_sw_info,
4137d4b4380SPavel Hofman 		.get = stac9460_mic_sw_get,
4147d4b4380SPavel Hofman 		.put = stac9460_mic_sw_put,
4157d4b4380SPavel Hofman 
4167d4b4380SPavel Hofman 	},
4171da177e4SLinus Torvalds };
4181da177e4SLinus Torvalds 
4197d4b4380SPavel Hofman /* AK4114 - ICE1724 connections on Prodigy192 + MI/ODI/O */
4207d4b4380SPavel Hofman /* CDTO (pin 32) -- GPIO11 pin 86
4217d4b4380SPavel Hofman  * CDTI (pin 33) -- GPIO10 pin 77
4227d4b4380SPavel Hofman  * CCLK (pin 34) -- GPIO9 pin 76
4237d4b4380SPavel Hofman  * CSN  (pin 35) -- GPIO8 pin 75
4247d4b4380SPavel Hofman  */
4257d4b4380SPavel Hofman #define AK4114_ADDR	0x00 /* C1-C0: Chip Address
4267d4b4380SPavel Hofman 			      * (According to datasheet fixed to “00”)
4277d4b4380SPavel Hofman 			      */
4287d4b4380SPavel Hofman 
4297d4b4380SPavel Hofman /*
4307d4b4380SPavel Hofman  * 4wire ak4114 protocol - writing data
4317d4b4380SPavel Hofman  */
write_data(struct snd_ice1712 * ice,unsigned int gpio,unsigned int data,int idx)4327d4b4380SPavel Hofman static void write_data(struct snd_ice1712 *ice, unsigned int gpio,
4337d4b4380SPavel Hofman 		       unsigned int data, int idx)
4347d4b4380SPavel Hofman {
4357d4b4380SPavel Hofman 	for (; idx >= 0; idx--) {
4367d4b4380SPavel Hofman 		/* drop clock */
4377d4b4380SPavel Hofman 		gpio &= ~VT1724_PRODIGY192_CCLK;
4387d4b4380SPavel Hofman 		snd_ice1712_gpio_write(ice, gpio);
4397d4b4380SPavel Hofman 		udelay(1);
4407d4b4380SPavel Hofman 		/* set data */
4417d4b4380SPavel Hofman 		if (data & (1 << idx))
4427d4b4380SPavel Hofman 			gpio |= VT1724_PRODIGY192_CDOUT;
4437d4b4380SPavel Hofman 		else
4447d4b4380SPavel Hofman 			gpio &= ~VT1724_PRODIGY192_CDOUT;
4457d4b4380SPavel Hofman 		snd_ice1712_gpio_write(ice, gpio);
4467d4b4380SPavel Hofman 		udelay(1);
4477d4b4380SPavel Hofman 		/* raise clock */
4487d4b4380SPavel Hofman 		gpio |= VT1724_PRODIGY192_CCLK;
4497d4b4380SPavel Hofman 		snd_ice1712_gpio_write(ice, gpio);
4507d4b4380SPavel Hofman 		udelay(1);
4517d4b4380SPavel Hofman 	}
4527d4b4380SPavel Hofman }
4537d4b4380SPavel Hofman 
4547d4b4380SPavel Hofman /*
4557d4b4380SPavel Hofman  * 4wire ak4114 protocol - reading data
4567d4b4380SPavel Hofman  */
read_data(struct snd_ice1712 * ice,unsigned int gpio,int idx)4577d4b4380SPavel Hofman static unsigned char read_data(struct snd_ice1712 *ice, unsigned int gpio,
4587d4b4380SPavel Hofman 			       int idx)
4597d4b4380SPavel Hofman {
4607d4b4380SPavel Hofman 	unsigned char data = 0;
4617d4b4380SPavel Hofman 
4627d4b4380SPavel Hofman 	for (; idx >= 0; idx--) {
4637d4b4380SPavel Hofman 		/* drop clock */
4647d4b4380SPavel Hofman 		gpio &= ~VT1724_PRODIGY192_CCLK;
4657d4b4380SPavel Hofman 		snd_ice1712_gpio_write(ice, gpio);
4667d4b4380SPavel Hofman 		udelay(1);
4677d4b4380SPavel Hofman 		/* read data */
4687d4b4380SPavel Hofman 		if (snd_ice1712_gpio_read(ice) & VT1724_PRODIGY192_CDIN)
4697d4b4380SPavel Hofman 			data |= (1 << idx);
4707d4b4380SPavel Hofman 		udelay(1);
4717d4b4380SPavel Hofman 		/* raise clock */
4727d4b4380SPavel Hofman 		gpio |= VT1724_PRODIGY192_CCLK;
4737d4b4380SPavel Hofman 		snd_ice1712_gpio_write(ice, gpio);
4747d4b4380SPavel Hofman 		udelay(1);
4757d4b4380SPavel Hofman 	}
4767d4b4380SPavel Hofman 	return data;
4777d4b4380SPavel Hofman }
4787d4b4380SPavel Hofman /*
4797d4b4380SPavel Hofman  * 4wire ak4114 protocol - starting sequence
4807d4b4380SPavel Hofman  */
prodigy192_4wire_start(struct snd_ice1712 * ice)4817d4b4380SPavel Hofman static unsigned int prodigy192_4wire_start(struct snd_ice1712 *ice)
4827d4b4380SPavel Hofman {
4837d4b4380SPavel Hofman 	unsigned int tmp;
4847d4b4380SPavel Hofman 
4857d4b4380SPavel Hofman 	snd_ice1712_save_gpio_status(ice);
4867d4b4380SPavel Hofman 	tmp = snd_ice1712_gpio_read(ice);
4877d4b4380SPavel Hofman 
4887d4b4380SPavel Hofman 	tmp |= VT1724_PRODIGY192_CCLK; /* high at init */
4897d4b4380SPavel Hofman 	tmp &= ~VT1724_PRODIGY192_CS; /* drop chip select */
4907d4b4380SPavel Hofman 	snd_ice1712_gpio_write(ice, tmp);
4917d4b4380SPavel Hofman 	udelay(1);
4927d4b4380SPavel Hofman 	return tmp;
4937d4b4380SPavel Hofman }
4947d4b4380SPavel Hofman 
4957d4b4380SPavel Hofman /*
4967d4b4380SPavel Hofman  * 4wire ak4114 protocol - final sequence
4977d4b4380SPavel Hofman  */
prodigy192_4wire_finish(struct snd_ice1712 * ice,unsigned int tmp)4987d4b4380SPavel Hofman static void prodigy192_4wire_finish(struct snd_ice1712 *ice, unsigned int tmp)
4997d4b4380SPavel Hofman {
5007d4b4380SPavel Hofman 	tmp |= VT1724_PRODIGY192_CS; /* raise chip select */
5017d4b4380SPavel Hofman 	snd_ice1712_gpio_write(ice, tmp);
5027d4b4380SPavel Hofman 	udelay(1);
5037d4b4380SPavel Hofman 	snd_ice1712_restore_gpio_status(ice);
5047d4b4380SPavel Hofman }
5057d4b4380SPavel Hofman 
5067d4b4380SPavel Hofman /*
5077d4b4380SPavel Hofman  * Write data to addr register of ak4114
5087d4b4380SPavel Hofman  */
prodigy192_ak4114_write(void * private_data,unsigned char addr,unsigned char data)5097d4b4380SPavel Hofman static void prodigy192_ak4114_write(void *private_data, unsigned char addr,
5107d4b4380SPavel Hofman 			       unsigned char data)
5117d4b4380SPavel Hofman {
5127d4b4380SPavel Hofman 	struct snd_ice1712 *ice = private_data;
5137d4b4380SPavel Hofman 	unsigned int tmp, addrdata;
5147d4b4380SPavel Hofman 	tmp = prodigy192_4wire_start(ice);
5157d4b4380SPavel Hofman 	addrdata = (AK4114_ADDR << 6) | 0x20 | (addr & 0x1f);
5167d4b4380SPavel Hofman 	addrdata = (addrdata << 8) | data;
5177d4b4380SPavel Hofman 	write_data(ice, tmp, addrdata, 15);
5187d4b4380SPavel Hofman 	prodigy192_4wire_finish(ice, tmp);
5197d4b4380SPavel Hofman }
5207d4b4380SPavel Hofman 
5217d4b4380SPavel Hofman /*
5227d4b4380SPavel Hofman  * Read data from addr register of ak4114
5237d4b4380SPavel Hofman  */
prodigy192_ak4114_read(void * private_data,unsigned char addr)5247d4b4380SPavel Hofman static unsigned char prodigy192_ak4114_read(void *private_data,
5257d4b4380SPavel Hofman 					    unsigned char addr)
5267d4b4380SPavel Hofman {
5277d4b4380SPavel Hofman 	struct snd_ice1712 *ice = private_data;
5287d4b4380SPavel Hofman 	unsigned int tmp;
5297d4b4380SPavel Hofman 	unsigned char data;
5307d4b4380SPavel Hofman 
5317d4b4380SPavel Hofman 	tmp = prodigy192_4wire_start(ice);
5327d4b4380SPavel Hofman 	write_data(ice, tmp, (AK4114_ADDR << 6) | (addr & 0x1f), 7);
5337d4b4380SPavel Hofman 	data = read_data(ice, tmp, 7);
5347d4b4380SPavel Hofman 	prodigy192_4wire_finish(ice, tmp);
5357d4b4380SPavel Hofman 	return data;
5367d4b4380SPavel Hofman }
5377d4b4380SPavel Hofman 
5387d4b4380SPavel Hofman 
ak4114_input_sw_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)5397d4b4380SPavel Hofman static int ak4114_input_sw_info(struct snd_kcontrol *kcontrol,
5407d4b4380SPavel Hofman 	       			struct snd_ctl_elem_info *uinfo)
5417d4b4380SPavel Hofman {
542a2af050fSTakashi Iwai 	static const char * const texts[2] = { "Toslink", "Coax" };
5437d4b4380SPavel Hofman 
544597da2e4STakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 2, texts);
5457d4b4380SPavel Hofman }
5467d4b4380SPavel Hofman 
5477d4b4380SPavel Hofman 
ak4114_input_sw_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)5487d4b4380SPavel Hofman static int ak4114_input_sw_get(struct snd_kcontrol *kcontrol,
5497d4b4380SPavel Hofman 	       		struct snd_ctl_elem_value *ucontrol)
5507d4b4380SPavel Hofman {
5517d4b4380SPavel Hofman 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
5527d4b4380SPavel Hofman 	unsigned char val;
5537d4b4380SPavel Hofman 
5547d4b4380SPavel Hofman 	val = prodigy192_ak4114_read(ice, AK4114_REG_IO1);
5557d4b4380SPavel Hofman 	/* AK4114_IPS0 bit = 0 -> RX0 = Toslink
5567d4b4380SPavel Hofman 	 * AK4114_IPS0 bit = 1 -> RX1 = Coax
5577d4b4380SPavel Hofman 	 */
5587d4b4380SPavel Hofman 	ucontrol->value.enumerated.item[0] = (val & AK4114_IPS0) ? 1 : 0;
5597d4b4380SPavel Hofman 	return 0;
5607d4b4380SPavel Hofman }
5617d4b4380SPavel Hofman 
ak4114_input_sw_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)5627d4b4380SPavel Hofman static int ak4114_input_sw_put(struct snd_kcontrol *kcontrol,
5637d4b4380SPavel Hofman 	       		struct snd_ctl_elem_value *ucontrol)
5647d4b4380SPavel Hofman {
5657d4b4380SPavel Hofman 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
5667d4b4380SPavel Hofman 	unsigned char new, old, itemvalue;
5677d4b4380SPavel Hofman 	int change;
5687d4b4380SPavel Hofman 
5697d4b4380SPavel Hofman 	old = prodigy192_ak4114_read(ice, AK4114_REG_IO1);
5707d4b4380SPavel Hofman 	/* AK4114_IPS0 could be any bit */
5717d4b4380SPavel Hofman 	itemvalue = (ucontrol->value.enumerated.item[0]) ? 0xff : 0x00;
5727d4b4380SPavel Hofman 
5737d4b4380SPavel Hofman 	new = (itemvalue & AK4114_IPS0) | (old & ~AK4114_IPS0);
5747d4b4380SPavel Hofman 	change = (new != old);
5757d4b4380SPavel Hofman 	if (change)
5767d4b4380SPavel Hofman 		prodigy192_ak4114_write(ice, AK4114_REG_IO1, new);
5777d4b4380SPavel Hofman 	return change;
5787d4b4380SPavel Hofman }
5797d4b4380SPavel Hofman 
5807d4b4380SPavel Hofman 
581b4e5e707STakashi Iwai static const struct snd_kcontrol_new ak4114_controls[] = {
5827d4b4380SPavel Hofman 	{
5837d4b4380SPavel Hofman 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5847d4b4380SPavel Hofman 		.name = "MIODIO IEC958 Capture Input",
5857d4b4380SPavel Hofman 		.info = ak4114_input_sw_info,
5867d4b4380SPavel Hofman 		.get = ak4114_input_sw_get,
5877d4b4380SPavel Hofman 		.put = ak4114_input_sw_put,
5887d4b4380SPavel Hofman 
5897d4b4380SPavel Hofman 	}
5907d4b4380SPavel Hofman };
5917d4b4380SPavel Hofman 
5927d4b4380SPavel Hofman 
prodigy192_ak4114_init(struct snd_ice1712 * ice)5937d4b4380SPavel Hofman static int prodigy192_ak4114_init(struct snd_ice1712 *ice)
5947d4b4380SPavel Hofman {
5957d4b4380SPavel Hofman 	static const unsigned char ak4114_init_vals[] = {
5967d4b4380SPavel Hofman 		AK4114_RST | AK4114_PWN | AK4114_OCKS0 | AK4114_OCKS1,
597c5a30f85SPavel Hofman 		/* ice1724 expects I2S and provides clock,
598c5a30f85SPavel Hofman 		 * DEM0 disables the deemphasis filter
599c5a30f85SPavel Hofman 		 */
600c5a30f85SPavel Hofman 		AK4114_DIF_I24I2S | AK4114_DEM0 ,
6017d4b4380SPavel Hofman 		AK4114_TX1E,
6027d4b4380SPavel Hofman 		AK4114_EFH_1024 | AK4114_DIT, /* default input RX0 */
6037d4b4380SPavel Hofman 		0,
6047d4b4380SPavel Hofman 		0
6057d4b4380SPavel Hofman 	};
6067d4b4380SPavel Hofman 	static const unsigned char ak4114_init_txcsb[] = {
6077d4b4380SPavel Hofman 		0x41, 0x02, 0x2c, 0x00, 0x00
6087d4b4380SPavel Hofman 	};
6097cda8ba9STakashi Iwai 	struct prodigy192_spec *spec = ice->spec;
610841b23d4SPavel Hofman 	int err;
6117d4b4380SPavel Hofman 
612841b23d4SPavel Hofman 	err = snd_ak4114_create(ice->card,
6137d4b4380SPavel Hofman 				 prodigy192_ak4114_read,
6147d4b4380SPavel Hofman 				 prodigy192_ak4114_write,
6157d4b4380SPavel Hofman 				 ak4114_init_vals, ak4114_init_txcsb,
6167cda8ba9STakashi Iwai 				 ice, &spec->ak4114);
617841b23d4SPavel Hofman 	if (err < 0)
618841b23d4SPavel Hofman 		return err;
619841b23d4SPavel Hofman 	/* AK4114 in Prodigy192 cannot detect external rate correctly.
620841b23d4SPavel Hofman 	 * No reason to stop capture stream due to incorrect checks */
621841b23d4SPavel Hofman 	spec->ak4114->check_flags = AK4114_CHECK_NO_RATE;
622841b23d4SPavel Hofman 	return 0;
6237d4b4380SPavel Hofman }
6247d4b4380SPavel Hofman 
stac9460_proc_regs_read(struct snd_info_entry * entry,struct snd_info_buffer * buffer)6256632d64bSPavel Hofman static void stac9460_proc_regs_read(struct snd_info_entry *entry,
6266632d64bSPavel Hofman 		struct snd_info_buffer *buffer)
6276632d64bSPavel Hofman {
6289fe856e4SJoe Perches 	struct snd_ice1712 *ice = entry->private_data;
6296632d64bSPavel Hofman 	int reg, val;
6306632d64bSPavel Hofman 	/* registers 0x0 - 0x14 */
6316632d64bSPavel Hofman 	for (reg = 0; reg <= 0x15; reg++) {
6326632d64bSPavel Hofman 		val = stac9460_get(ice, reg);
6336632d64bSPavel Hofman 		snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val);
6346632d64bSPavel Hofman 	}
6356632d64bSPavel Hofman }
6366632d64bSPavel Hofman 
6376632d64bSPavel Hofman 
stac9460_proc_init(struct snd_ice1712 * ice)6386632d64bSPavel Hofman static void stac9460_proc_init(struct snd_ice1712 *ice)
6396632d64bSPavel Hofman {
64047f2769bSTakashi Iwai 	snd_card_ro_proc_new(ice->card, "stac9460_codec", ice,
64147f2769bSTakashi Iwai 			     stac9460_proc_regs_read);
6426632d64bSPavel Hofman }
6436632d64bSPavel Hofman 
6446632d64bSPavel Hofman 
prodigy192_add_controls(struct snd_ice1712 * ice)645e23e7a14SBill Pemberton static int prodigy192_add_controls(struct snd_ice1712 *ice)
6461da177e4SLinus Torvalds {
6477cda8ba9STakashi Iwai 	struct prodigy192_spec *spec = ice->spec;
6481da177e4SLinus Torvalds 	unsigned int i;
6491da177e4SLinus Torvalds 	int err;
6501da177e4SLinus Torvalds 
6511da177e4SLinus Torvalds 	for (i = 0; i < ARRAY_SIZE(stac_controls); i++) {
6527d4b4380SPavel Hofman 		err = snd_ctl_add(ice->card,
6537d4b4380SPavel Hofman 				  snd_ctl_new1(&stac_controls[i], ice));
6547d4b4380SPavel Hofman 		if (err < 0)
6557d4b4380SPavel Hofman 			return err;
6567d4b4380SPavel Hofman 	}
6577cda8ba9STakashi Iwai 	if (spec->ak4114) {
6587d4b4380SPavel Hofman 		/* ak4114 is connected */
6597d4b4380SPavel Hofman 		for (i = 0; i < ARRAY_SIZE(ak4114_controls); i++) {
6607d4b4380SPavel Hofman 			err = snd_ctl_add(ice->card,
6617d4b4380SPavel Hofman 					  snd_ctl_new1(&ak4114_controls[i],
6627d4b4380SPavel Hofman 						       ice));
6637d4b4380SPavel Hofman 			if (err < 0)
6647d4b4380SPavel Hofman 				return err;
6657d4b4380SPavel Hofman 		}
6667cda8ba9STakashi Iwai 		err = snd_ak4114_build(spec->ak4114,
6677d4b4380SPavel Hofman 				NULL, /* ak4114 in MIO/DI/O handles no IEC958 output */
6687d4b4380SPavel Hofman 				ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
6691da177e4SLinus Torvalds 		if (err < 0)
6701da177e4SLinus Torvalds 			return err;
6711da177e4SLinus Torvalds 	}
6726632d64bSPavel Hofman 	stac9460_proc_init(ice);
6731da177e4SLinus Torvalds 	return 0;
6741da177e4SLinus Torvalds }
6751da177e4SLinus Torvalds 
6767d4b4380SPavel Hofman /*
6777d4b4380SPavel Hofman  * check for presence of MI/ODI/O add-on card with digital inputs
6787d4b4380SPavel Hofman  */
prodigy192_miodio_exists(struct snd_ice1712 * ice)6797d4b4380SPavel Hofman static int prodigy192_miodio_exists(struct snd_ice1712 *ice)
6807d4b4380SPavel Hofman {
6817d4b4380SPavel Hofman 
6827d4b4380SPavel Hofman 	unsigned char orig_value;
6837d4b4380SPavel Hofman 	const unsigned char test_data = 0xd1;	/* random value */
6847d4b4380SPavel Hofman 	unsigned char addr = AK4114_REG_INT0_MASK; /* random SAFE address */
6857d4b4380SPavel Hofman 	int exists = 0;
6867d4b4380SPavel Hofman 
6877d4b4380SPavel Hofman 	orig_value = prodigy192_ak4114_read(ice, addr);
6887d4b4380SPavel Hofman 	prodigy192_ak4114_write(ice, addr, test_data);
6897d4b4380SPavel Hofman 	if (prodigy192_ak4114_read(ice, addr) == test_data) {
6907d4b4380SPavel Hofman 		/* ak4114 seems to communicate, apparently exists */
6917d4b4380SPavel Hofman 		/* writing back original value */
6927d4b4380SPavel Hofman 		prodigy192_ak4114_write(ice, addr, orig_value);
6937d4b4380SPavel Hofman 		exists = 1;
6947d4b4380SPavel Hofman 	}
6957d4b4380SPavel Hofman 	return exists;
6967d4b4380SPavel Hofman }
6971da177e4SLinus Torvalds 
6981da177e4SLinus Torvalds /*
6991da177e4SLinus Torvalds  * initialize the chip
7001da177e4SLinus Torvalds  */
prodigy192_init(struct snd_ice1712 * ice)701e23e7a14SBill Pemberton static int prodigy192_init(struct snd_ice1712 *ice)
7021da177e4SLinus Torvalds {
70332b47da0STakashi Iwai 	static const unsigned short stac_inits_prodigy[] = {
7041da177e4SLinus Torvalds 		STAC946X_RESET, 0,
7056632d64bSPavel Hofman 		STAC946X_MASTER_CLOCKING, 0x11,
7061da177e4SLinus Torvalds /*		STAC946X_MASTER_VOLUME, 0,
7071da177e4SLinus Torvalds 		STAC946X_LF_VOLUME, 0,
7081da177e4SLinus Torvalds 		STAC946X_RF_VOLUME, 0,
7091da177e4SLinus Torvalds 		STAC946X_LR_VOLUME, 0,
7101da177e4SLinus Torvalds 		STAC946X_RR_VOLUME, 0,
7111da177e4SLinus Torvalds 		STAC946X_CENTER_VOLUME, 0,
7121da177e4SLinus Torvalds 		STAC946X_LFE_VOLUME, 0,*/
7131da177e4SLinus Torvalds 		(unsigned short)-1
7141da177e4SLinus Torvalds 	};
71532b47da0STakashi Iwai 	const unsigned short *p;
7167d4b4380SPavel Hofman 	int err = 0;
7177cda8ba9STakashi Iwai 	struct prodigy192_spec *spec;
7181da177e4SLinus Torvalds 
7191da177e4SLinus Torvalds 	/* prodigy 192 */
7201da177e4SLinus Torvalds 	ice->num_total_dacs = 6;
7211da177e4SLinus Torvalds 	ice->num_total_adcs = 2;
7227d4b4380SPavel Hofman 	ice->vt1720 = 0;  /* ice1724, e.g. 23 GPIOs */
7231da177e4SLinus Torvalds 
7247cda8ba9STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7257cda8ba9STakashi Iwai 	if (!spec)
7267cda8ba9STakashi Iwai 		return -ENOMEM;
7277cda8ba9STakashi Iwai 	ice->spec = spec;
7287cda8ba9STakashi Iwai 	mutex_init(&spec->mute_mutex);
7297cda8ba9STakashi Iwai 
7301da177e4SLinus Torvalds 	/* initialize codec */
7311da177e4SLinus Torvalds 	p = stac_inits_prodigy;
7321da177e4SLinus Torvalds 	for (; *p != (unsigned short)-1; p += 2)
7331da177e4SLinus Torvalds 		stac9460_put(ice, p[0], p[1]);
734841b23d4SPavel Hofman 	ice->gpio.set_pro_rate = stac9460_set_rate_val;
7351da177e4SLinus Torvalds 
7367d4b4380SPavel Hofman 	/* MI/ODI/O add on card with AK4114 */
7377d4b4380SPavel Hofman 	if (prodigy192_miodio_exists(ice)) {
7387d4b4380SPavel Hofman 		err = prodigy192_ak4114_init(ice);
7397d4b4380SPavel Hofman 		/* from this moment if err = 0 then
7407cda8ba9STakashi Iwai 		 * spec->ak4114 should not be null
7417d4b4380SPavel Hofman 		 */
7426dfb5affSTakashi Iwai 		dev_dbg(ice->card->dev,
7436dfb5affSTakashi Iwai 			"AK4114 initialized with status %d\n", err);
7447d4b4380SPavel Hofman 	} else
7456dfb5affSTakashi Iwai 		dev_dbg(ice->card->dev, "AK4114 not found\n");
7467d4b4380SPavel Hofman 
747387417b5SSudip Mukherjee 	return err;
7481da177e4SLinus Torvalds }
7491da177e4SLinus Torvalds 
7501da177e4SLinus Torvalds 
7511da177e4SLinus Torvalds /*
7521da177e4SLinus Torvalds  * Aureon boards don't provide the EEPROM data except for the vendor IDs.
7531da177e4SLinus Torvalds  * hence the driver needs to sets up it properly.
7541da177e4SLinus Torvalds  */
7551da177e4SLinus Torvalds 
756f16a4e96STakashi Iwai static const unsigned char prodigy71_eeprom[] = {
7577d4b4380SPavel Hofman 	[ICE_EEP2_SYSCONF]     = 0x6a,	/* 49MHz crystal, mpu401,
7587d4b4380SPavel Hofman 					 * spdif-in+ 1 stereo ADC,
7597d4b4380SPavel Hofman 					 * 3 stereo DACs
7607d4b4380SPavel Hofman 					 */
761189bc171STakashi Iwai 	[ICE_EEP2_ACLINK]      = 0x80,	/* I2S */
762189bc171STakashi Iwai 	[ICE_EEP2_I2S]         = 0xf8,	/* vol, 96k, 24bit, 192k */
763189bc171STakashi Iwai 	[ICE_EEP2_SPDIF]       = 0xc3,	/* out-en, out-int, spdif-in */
764189bc171STakashi Iwai 	[ICE_EEP2_GPIO_DIR]    = 0xff,
7657d4b4380SPavel Hofman 	[ICE_EEP2_GPIO_DIR1]   = ~(VT1724_PRODIGY192_CDIN >> 8) ,
766189bc171STakashi Iwai 	[ICE_EEP2_GPIO_DIR2]   = 0xbf,
767189bc171STakashi Iwai 	[ICE_EEP2_GPIO_MASK]   = 0x00,
768189bc171STakashi Iwai 	[ICE_EEP2_GPIO_MASK1]  = 0x00,
769189bc171STakashi Iwai 	[ICE_EEP2_GPIO_MASK2]  = 0x00,
770189bc171STakashi Iwai 	[ICE_EEP2_GPIO_STATE]  = 0x00,
771189bc171STakashi Iwai 	[ICE_EEP2_GPIO_STATE1] = 0x00,
7727d4b4380SPavel Hofman 	[ICE_EEP2_GPIO_STATE2] = 0x10,  /* GPIO20: 0 = CD drive dig. input
7737d4b4380SPavel Hofman 					 * passthrough,
7747d4b4380SPavel Hofman 					 * 1 = SPDIF-OUT from ice1724
7757d4b4380SPavel Hofman 					 */
7761da177e4SLinus Torvalds };
7771da177e4SLinus Torvalds 
7781da177e4SLinus Torvalds 
7791da177e4SLinus Torvalds /* entry point */
780e23e7a14SBill Pemberton struct snd_ice1712_card_info snd_vt1724_prodigy192_cards[] = {
7811da177e4SLinus Torvalds 	{
7821da177e4SLinus Torvalds 		.subvendor = VT1724_SUBDEVICE_PRODIGY192VE,
7831da177e4SLinus Torvalds 		.name = "Audiotrak Prodigy 192",
7841da177e4SLinus Torvalds 		.model = "prodigy192",
7851da177e4SLinus Torvalds 		.chip_init = prodigy192_init,
7861da177e4SLinus Torvalds 		.build_controls = prodigy192_add_controls,
7871da177e4SLinus Torvalds 		.eeprom_size = sizeof(prodigy71_eeprom),
7881da177e4SLinus Torvalds 		.eeprom_data = prodigy71_eeprom,
7891da177e4SLinus Torvalds 	},
7901da177e4SLinus Torvalds 	{ } /* terminator */
7911da177e4SLinus Torvalds };
792