xref: /onnv-gate/usr/src/uts/common/io/audio/ac97/ac97_ad.c (revision 10413:63f6889c8957)
19484Sgarrett.damore@Sun.COM /*
29484Sgarrett.damore@Sun.COM  * CDDL HEADER START
39484Sgarrett.damore@Sun.COM  *
49484Sgarrett.damore@Sun.COM  * The contents of this file are subject to the terms of the
59484Sgarrett.damore@Sun.COM  * Common Development and Distribution License (the "License").
69484Sgarrett.damore@Sun.COM  * You may not use this file except in compliance with the License.
79484Sgarrett.damore@Sun.COM  *
89484Sgarrett.damore@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
99484Sgarrett.damore@Sun.COM  * or http://www.opensolaris.org/os/licensing.
109484Sgarrett.damore@Sun.COM  * See the License for the specific language governing permissions
119484Sgarrett.damore@Sun.COM  * and limitations under the License.
129484Sgarrett.damore@Sun.COM  *
139484Sgarrett.damore@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
149484Sgarrett.damore@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
159484Sgarrett.damore@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
169484Sgarrett.damore@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
179484Sgarrett.damore@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
189484Sgarrett.damore@Sun.COM  *
199484Sgarrett.damore@Sun.COM  * CDDL HEADER END
209484Sgarrett.damore@Sun.COM  */
219484Sgarrett.damore@Sun.COM /*
229484Sgarrett.damore@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
239484Sgarrett.damore@Sun.COM  * Use is subject to license terms.
249484Sgarrett.damore@Sun.COM  */
259484Sgarrett.damore@Sun.COM 
269484Sgarrett.damore@Sun.COM /*
279484Sgarrett.damore@Sun.COM  * ADS (Analog Devices) codec extensions.
289484Sgarrett.damore@Sun.COM  */
299484Sgarrett.damore@Sun.COM 
309484Sgarrett.damore@Sun.COM /*
319484Sgarrett.damore@Sun.COM  * TODO:
329484Sgarrett.damore@Sun.COM  *
339484Sgarrett.damore@Sun.COM  * Most vendors connect the surr-out of ad1980/ad1985 codecs to the
349484Sgarrett.damore@Sun.COM  * line-out jack. So far we haven't found which vendors don't
359484Sgarrett.damore@Sun.COM  * do that. So we assume that all vendors swap the surr-out
369484Sgarrett.damore@Sun.COM  * and the line-out outputs. So we need swap the two outputs.
379484Sgarrett.damore@Sun.COM  *
389484Sgarrett.damore@Sun.COM  * Historically we internally processed the "ad198x-swap-output"
399484Sgarrett.damore@Sun.COM  * property. If someday some vendors do not swap the outputs, we would
409484Sgarrett.damore@Sun.COM  * set "ad198x-swap-output = 0" in the driver.conf file, and unload
419484Sgarrett.damore@Sun.COM  * and reload the driver (or reboot).
429484Sgarrett.damore@Sun.COM  *
439484Sgarrett.damore@Sun.COM  * TODO:
449484Sgarrett.damore@Sun.COM  *
459484Sgarrett.damore@Sun.COM  * Since we don't have access (at present) to any such systems, we have
469484Sgarrett.damore@Sun.COM  * not implemented this swapping property.  Once we can test it, we will
479484Sgarrett.damore@Sun.COM  * add it.  This is noted as CR 6819556.
489484Sgarrett.damore@Sun.COM  *
499484Sgarrett.damore@Sun.COM  * The old code did this:
509484Sgarrett.damore@Sun.COM  *
519484Sgarrett.damore@Sun.COM  *	if (ddi_prop_get_int(DDI_DEV_T_ANY, statep->dip,
529484Sgarrett.damore@Sun.COM  *	    DDI_PROP_DONTPASS, "ad198x-swap-output", 1) == 1) {
539484Sgarrett.damore@Sun.COM  *		statep->swap_out = B_TRUE;
549484Sgarrett.damore@Sun.COM  *		(void) audioixp_read_ac97(statep, CODEC_AD_REG_MISC, &tmp);
559484Sgarrett.damore@Sun.COM  *		(void) audioixp_write_ac97(statep,
569484Sgarrett.damore@Sun.COM  *		    CODEC_AD_REG_MISC,
579484Sgarrett.damore@Sun.COM  *		    tmp | AD1980_MISC_LOSEL | AD1980_MISC_HPSEL);
589484Sgarrett.damore@Sun.COM  *
599484Sgarrett.damore@Sun.COM  */
609484Sgarrett.damore@Sun.COM 
619484Sgarrett.damore@Sun.COM #include <sys/types.h>
629484Sgarrett.damore@Sun.COM #include <sys/ddi.h>
639484Sgarrett.damore@Sun.COM #include <sys/sunddi.h>
649484Sgarrett.damore@Sun.COM #include <sys/audio/audio_driver.h>
659484Sgarrett.damore@Sun.COM #include <sys/audio/ac97.h>
669484Sgarrett.damore@Sun.COM #include <sys/note.h>
679484Sgarrett.damore@Sun.COM #include "ac97_impl.h"
689484Sgarrett.damore@Sun.COM 
699484Sgarrett.damore@Sun.COM #define	ADS_EQ_CTRL_REGISTER		0x60
709484Sgarrett.damore@Sun.COM #define	AECR_EQM			0x8000	/* disable EQ */
719484Sgarrett.damore@Sun.COM #define	AECR_SYM			0x0080
729484Sgarrett.damore@Sun.COM 
739484Sgarrett.damore@Sun.COM #define	ADS_EQ_DATA_REGISTER		0x62
749484Sgarrett.damore@Sun.COM 
759484Sgarrett.damore@Sun.COM #define	ADS_MIXER_ADC_IGAIN_REGISTER	0x64
769484Sgarrett.damore@Sun.COM #define	AMADIR_LEFT_MASK		0x0f00
779484Sgarrett.damore@Sun.COM #define	AMADIR_RIGHT_MASK		0x000f
789484Sgarrett.damore@Sun.COM #define	AMADIR_MXM			0x8000
799484Sgarrett.damore@Sun.COM 
809484Sgarrett.damore@Sun.COM #define	ADS_JS_INTS_STATUS_REGISTER	0x72
819484Sgarrett.damore@Sun.COM #define	AJISR_JS0INT			0x0001
829484Sgarrett.damore@Sun.COM #define	AJISR_JS1INT			0x0002
839484Sgarrett.damore@Sun.COM #define	AJISR_JS0ST			0x0004
849484Sgarrett.damore@Sun.COM #define	AJISR_JS1ST			0x0008
859484Sgarrett.damore@Sun.COM #define	AJISR_JS0MD			0x0010
869484Sgarrett.damore@Sun.COM #define	AJISR_JS1MD			0x0020
879484Sgarrett.damore@Sun.COM #define	AJISR_JS0TMR			0x0040
889484Sgarrett.damore@Sun.COM #define	AJISR_JS1TMR			0x0080
899484Sgarrett.damore@Sun.COM #define	AJISR_JS0EQB			0x0100
909484Sgarrett.damore@Sun.COM #define	AJISR_JS1EQB			0x0200
919484Sgarrett.damore@Sun.COM #define	AJISR_JSMT_MASK			0x1c00
929484Sgarrett.damore@Sun.COM #define	AJISR_JSMT_NONE			0x0000
939484Sgarrett.damore@Sun.COM #define	AJISR_JSMT_HP_LNOUT		0x0400	/* hp mutes line out */
949484Sgarrett.damore@Sun.COM #define	AJISR_JSMT_HP_BOTH		0x0800	/* hp mutes both mono & line */
959484Sgarrett.damore@Sun.COM #define	AJISR_JSMT_LNOUT_MONO		0x1000	/* lineout mutes mono */
969484Sgarrett.damore@Sun.COM #define	AJISR_JSMT_ALL			0x1800	/* all JS muting enabled */
979484Sgarrett.damore@Sun.COM 
989484Sgarrett.damore@Sun.COM #define	ADS_SERIAL_CFG_REGISTER		0x74
999484Sgarrett.damore@Sun.COM #define	ASCR_SPLNK			0x0001
1009484Sgarrett.damore@Sun.COM #define	ASCR_SPDZ			0x0002
1019484Sgarrett.damore@Sun.COM #define	ASCR_SPAL			0x0004
1029484Sgarrett.damore@Sun.COM #define	ASCR_INTS			0x0010
1039484Sgarrett.damore@Sun.COM #define	ASCR_CHEN			0x0100
1049484Sgarrett.damore@Sun.COM #define	ASCR_REGM0			0x1000
1059484Sgarrett.damore@Sun.COM #define	ASCR_REGM1			0x2000
1069484Sgarrett.damore@Sun.COM #define	ASCR_REGM2			0x4000
1079484Sgarrett.damore@Sun.COM #define	ASCR_SLOT16			0x8000
1089484Sgarrett.damore@Sun.COM 
1099484Sgarrett.damore@Sun.COM #define	ADS_MISC_CFG_REGISTER		0x76
1109484Sgarrett.damore@Sun.COM #define	AMCR_MBG_MASK			0x0003
1119484Sgarrett.damore@Sun.COM #define	AMCR_MBG_20dB			0x0000
1129484Sgarrett.damore@Sun.COM #define	AMCR_MBG_10dB			0x0001
1139484Sgarrett.damore@Sun.COM #define	AMCR_MBG_30dB			0x0002
1149484Sgarrett.damore@Sun.COM #define	AMCR_VREFD			0x0004
1159484Sgarrett.damore@Sun.COM #define	AMCR_VREFH			0x0008
1169484Sgarrett.damore@Sun.COM #define	AMCR_MADST			0x0010	/* AD1981B */
1179484Sgarrett.damore@Sun.COM #define	AMCR_SRU			0x0010	/* AD1980 */
1189484Sgarrett.damore@Sun.COM #define	AMCR_LOSEL			0x0020	/* AD1980 */
1199484Sgarrett.damore@Sun.COM #define	AMCR_2CMIC			0x0040
1209484Sgarrett.damore@Sun.COM #define	AMCR_MADPD			0x0080	/* AD1981B */
1219484Sgarrett.damore@Sun.COM #define	AMCR_SPRD			0x0080	/* AD1980 */
1229484Sgarrett.damore@Sun.COM #define	AMCR_DMIX_6TO2			0x0100	/* AD1980 */
1239484Sgarrett.damore@Sun.COM #define	AMCR_DMIX_FORCE			0x0200	/* AD1980 */
1249484Sgarrett.damore@Sun.COM #define	AMCR_FMXE			0x0200	/* AD1981B */
1259484Sgarrett.damore@Sun.COM #define	AMCR_HPSEL			0x0400	/* AD1980 */
1269484Sgarrett.damore@Sun.COM #define	AMCR_CLDIS			0x0800	/* AD1980 */
1279484Sgarrett.damore@Sun.COM #define	AMCR_LODIS			0x1000	/* AD1980 */
1289484Sgarrett.damore@Sun.COM #define	AMCR_DAM			0x0800	/* AD1981B */
1299484Sgarrett.damore@Sun.COM #define	AMCR_MSPLT			0x2000
1309484Sgarrett.damore@Sun.COM #define	AMCR_AC97NC			0x4000	/* AD1980 */
1319484Sgarrett.damore@Sun.COM #define	AMCR_DACZ			0x8000
1329484Sgarrett.damore@Sun.COM 
1339484Sgarrett.damore@Sun.COM static void
ads_set_micboost(ac97_ctrl_t * actrl,uint64_t value)1349484Sgarrett.damore@Sun.COM ads_set_micboost(ac97_ctrl_t *actrl, uint64_t value)
1359484Sgarrett.damore@Sun.COM {
1369484Sgarrett.damore@Sun.COM 	ac97_t	*ac = actrl->actrl_ac97;
1379484Sgarrett.damore@Sun.COM 	uint16_t	v;
1389484Sgarrett.damore@Sun.COM 
139*10413SGarrett.Damore@Sun.COM 	ac_wr(ac, AC97_INTERRUPT_PAGING_REGISTER, 0);	/* select page 0 */
1409484Sgarrett.damore@Sun.COM 	switch (value) {
1419484Sgarrett.damore@Sun.COM 	case 0x1:
1429484Sgarrett.damore@Sun.COM 		/* 0db */
143*10413SGarrett.Damore@Sun.COM 		ac_clr(ac, AC97_MIC_VOLUME_REGISTER, MICVR_20dB_BOOST);
1449484Sgarrett.damore@Sun.COM 		break;
1459484Sgarrett.damore@Sun.COM 	case 0x2:
1469484Sgarrett.damore@Sun.COM 		/* 10dB */
147*10413SGarrett.Damore@Sun.COM 		ac_set(ac, AC97_MIC_VOLUME_REGISTER, MICVR_20dB_BOOST);
148*10413SGarrett.Damore@Sun.COM 		v = ac_rd(ac, ADS_MISC_CFG_REGISTER);
1499484Sgarrett.damore@Sun.COM 		v &= ~AMCR_MBG_MASK;
1509484Sgarrett.damore@Sun.COM 		v |= AMCR_MBG_10dB;
151*10413SGarrett.Damore@Sun.COM 		ac_wr(ac, ADS_MISC_CFG_REGISTER, v);
1529484Sgarrett.damore@Sun.COM 		break;
1539484Sgarrett.damore@Sun.COM 	case 0x4:
1549484Sgarrett.damore@Sun.COM 		/* 20dB */
155*10413SGarrett.Damore@Sun.COM 		ac_set(ac, AC97_MIC_VOLUME_REGISTER, MICVR_20dB_BOOST);
156*10413SGarrett.Damore@Sun.COM 		v = ac_rd(ac, ADS_MISC_CFG_REGISTER);
1579484Sgarrett.damore@Sun.COM 		v &= ~AMCR_MBG_MASK;
1589484Sgarrett.damore@Sun.COM 		v |= AMCR_MBG_20dB;
159*10413SGarrett.Damore@Sun.COM 		ac_wr(ac, ADS_MISC_CFG_REGISTER, v);
1609484Sgarrett.damore@Sun.COM 		break;
1619484Sgarrett.damore@Sun.COM 	case 0x8:
1629484Sgarrett.damore@Sun.COM 		/* 30dB */
163*10413SGarrett.Damore@Sun.COM 		ac_set(ac, AC97_MIC_VOLUME_REGISTER, MICVR_20dB_BOOST);
164*10413SGarrett.Damore@Sun.COM 		v = ac_rd(ac, ADS_MISC_CFG_REGISTER);
1659484Sgarrett.damore@Sun.COM 		v &= ~AMCR_MBG_MASK;
1669484Sgarrett.damore@Sun.COM 		v |= AMCR_MBG_30dB;
167*10413SGarrett.Damore@Sun.COM 		ac_wr(ac, ADS_MISC_CFG_REGISTER, v);
1689484Sgarrett.damore@Sun.COM 		break;
1699484Sgarrett.damore@Sun.COM 	}
1709484Sgarrett.damore@Sun.COM }
1719484Sgarrett.damore@Sun.COM 
1729484Sgarrett.damore@Sun.COM static void
ads_set_micsrc(ac97_ctrl_t * actrl,uint64_t value)1739484Sgarrett.damore@Sun.COM ads_set_micsrc(ac97_ctrl_t *actrl, uint64_t value)
1749484Sgarrett.damore@Sun.COM {
1759484Sgarrett.damore@Sun.COM 	ac97_t	*ac = actrl->actrl_ac97;
1769484Sgarrett.damore@Sun.COM 
177*10413SGarrett.Damore@Sun.COM 	ac_wr(ac, AC97_INTERRUPT_PAGING_REGISTER, 0);	/* select page 0 */
1789484Sgarrett.damore@Sun.COM 	switch (value) {
1799484Sgarrett.damore@Sun.COM 	case 0x1:	/* mic1 */
180*10413SGarrett.Damore@Sun.COM 		ac_clr(ac, ADS_MISC_CFG_REGISTER, AMCR_2CMIC);
181*10413SGarrett.Damore@Sun.COM 		ac_clr(ac, AC97_GENERAL_PURPOSE_REGISTER, GPR_MS_MIC2);
1829484Sgarrett.damore@Sun.COM 		break;
1839484Sgarrett.damore@Sun.COM 	case 0x2:	/* mic2 */
184*10413SGarrett.Damore@Sun.COM 		ac_clr(ac, ADS_MISC_CFG_REGISTER, AMCR_2CMIC);
185*10413SGarrett.Damore@Sun.COM 		ac_set(ac, AC97_GENERAL_PURPOSE_REGISTER, GPR_MS_MIC2);
1869484Sgarrett.damore@Sun.COM 		break;
1879484Sgarrett.damore@Sun.COM 	case 0x4:	/* stereo - ms bit clear to allow MIC1 to be mixed */
188*10413SGarrett.Damore@Sun.COM 		ac_set(ac, ADS_MISC_CFG_REGISTER, AMCR_2CMIC);
189*10413SGarrett.Damore@Sun.COM 		ac_clr(ac, AC97_GENERAL_PURPOSE_REGISTER, GPR_MS_MIC2);
1909484Sgarrett.damore@Sun.COM 		break;
1919484Sgarrett.damore@Sun.COM 	}
1929484Sgarrett.damore@Sun.COM }
1939484Sgarrett.damore@Sun.COM 
1949484Sgarrett.damore@Sun.COM static void
ads_setup_micsrc(ac97_t * ac)1959484Sgarrett.damore@Sun.COM ads_setup_micsrc(ac97_t *ac)
1969484Sgarrett.damore@Sun.COM {
1979484Sgarrett.damore@Sun.COM 	static const char	*values[] = {
1989484Sgarrett.damore@Sun.COM 		AUDIO_PORT_MIC1,
1999484Sgarrett.damore@Sun.COM 		AUDIO_PORT_MIC2,
2009484Sgarrett.damore@Sun.COM 		AUDIO_PORT_STEREO,
2019484Sgarrett.damore@Sun.COM 		NULL
2029484Sgarrett.damore@Sun.COM 	};
2039484Sgarrett.damore@Sun.COM 	ac97_ctrl_probe_t cpt = {
2049484Sgarrett.damore@Sun.COM 		AUDIO_CTRL_ID_MICSRC, 1, 0x7, 0x7, AUDIO_CTRL_TYPE_ENUM,
2059484Sgarrett.damore@Sun.COM 		AC97_FLAGS | AUDIO_CTRL_FLAG_REC, 0, ads_set_micsrc,
2069484Sgarrett.damore@Sun.COM 		NULL, 0, values };
2079484Sgarrett.damore@Sun.COM 
208*10413SGarrett.Damore@Sun.COM 	ac_add_control(ac, &cpt);
2099484Sgarrett.damore@Sun.COM }
2109484Sgarrett.damore@Sun.COM 
2119484Sgarrett.damore@Sun.COM static void
ads_setup_micboost(ac97_t * ac)2129484Sgarrett.damore@Sun.COM ads_setup_micboost(ac97_t *ac)
2139484Sgarrett.damore@Sun.COM {
2149484Sgarrett.damore@Sun.COM 	ac97_ctrl_t		*ctrl;
2159484Sgarrett.damore@Sun.COM 
2169484Sgarrett.damore@Sun.COM 	static const char	*values[] = {
2179484Sgarrett.damore@Sun.COM 		AUDIO_VALUE_OFF,	/* 0dB */
2189484Sgarrett.damore@Sun.COM 		AUDIO_VALUE_LOW,	/* 10dB */
2199484Sgarrett.damore@Sun.COM 		AUDIO_VALUE_MEDIUM,	/* 20dB */
2209484Sgarrett.damore@Sun.COM 		AUDIO_VALUE_HIGH,	/* 30dB */
2219484Sgarrett.damore@Sun.COM 		NULL
2229484Sgarrett.damore@Sun.COM 	};
2239484Sgarrett.damore@Sun.COM 	ac97_ctrl_probe_t cpt = {
2249484Sgarrett.damore@Sun.COM 		AUDIO_CTRL_ID_MICBOOST, 1, 0xf, 0xf, AUDIO_CTRL_TYPE_ENUM,
2259484Sgarrett.damore@Sun.COM 		AC97_FLAGS | AUDIO_CTRL_FLAG_REC, 0, ads_set_micboost,
2269484Sgarrett.damore@Sun.COM 		NULL, 0, values };
2279484Sgarrett.damore@Sun.COM 
2289484Sgarrett.damore@Sun.COM 	ctrl = ac97_control_find(ac, AUDIO_CTRL_ID_MICBOOST);
2299484Sgarrett.damore@Sun.COM 	if (ctrl) {
2309484Sgarrett.damore@Sun.COM 		if (ctrl->actrl_initval) {
2319484Sgarrett.damore@Sun.COM 			/* 20dB by default */
2329484Sgarrett.damore@Sun.COM 			cpt.cp_initval = 2;
2339484Sgarrett.damore@Sun.COM 		}
2349484Sgarrett.damore@Sun.COM 	}
2359484Sgarrett.damore@Sun.COM 
236*10413SGarrett.Damore@Sun.COM 	ac_add_control(ac, &cpt);
2379484Sgarrett.damore@Sun.COM }
2389484Sgarrett.damore@Sun.COM 
2399484Sgarrett.damore@Sun.COM void
ad1981a_init(ac97_t * ac)2409484Sgarrett.damore@Sun.COM ad1981a_init(ac97_t *ac)
2419484Sgarrett.damore@Sun.COM {
2429484Sgarrett.damore@Sun.COM 	ads_setup_micboost(ac);
2439484Sgarrett.damore@Sun.COM }
2449484Sgarrett.damore@Sun.COM 
2459484Sgarrett.damore@Sun.COM void
ad1981b_init(ac97_t * ac)2469484Sgarrett.damore@Sun.COM ad1981b_init(ac97_t *ac)
2479484Sgarrett.damore@Sun.COM {
2489484Sgarrett.damore@Sun.COM 	ads_setup_micboost(ac);
2499484Sgarrett.damore@Sun.COM 	ads_setup_micsrc(ac);	/* this part can use a mic array */
2509484Sgarrett.damore@Sun.COM }
251