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 * ALC (Realtek/Advance Logic) codec extensions.
289484Sgarrett.damore@Sun.COM */
299484Sgarrett.damore@Sun.COM
309484Sgarrett.damore@Sun.COM #include <sys/types.h>
319484Sgarrett.damore@Sun.COM #include <sys/ddi.h>
329484Sgarrett.damore@Sun.COM #include <sys/sunddi.h>
339484Sgarrett.damore@Sun.COM #include <sys/audio/audio_driver.h>
349484Sgarrett.damore@Sun.COM #include <sys/audio/ac97.h>
359484Sgarrett.damore@Sun.COM #include <sys/note.h>
369484Sgarrett.damore@Sun.COM #include "ac97_impl.h"
379484Sgarrett.damore@Sun.COM
389484Sgarrett.damore@Sun.COM #define ALC_DATA_FLOW_CTRL_REGISTER 0x6a
399484Sgarrett.damore@Sun.COM #define ADFC_SPDIFIN_EN 0x8000
409484Sgarrett.damore@Sun.COM #define ADFC_SPDIFIN_MON_EN 0x4000
419484Sgarrett.damore@Sun.COM #define ADFC_SPDIF_OUT_MASK 0x3000
429484Sgarrett.damore@Sun.COM #define ADFC_SPDIF_OUT_ACLINK 0x0000
439484Sgarrett.damore@Sun.COM #define ADFC_SPDIF_OUT_ADC 0x1000
449484Sgarrett.damore@Sun.COM #define ADFC_SPDIF_OUT_BYPASS 0x2000
459484Sgarrett.damore@Sun.COM #define ADFC_PCM_SPDIFIN 0x0800
469484Sgarrett.damore@Sun.COM #define ADFC_BACK_SURROUND 0x0400 /* ALC850 only */
479484Sgarrett.damore@Sun.COM #define ADFC_CENTER_LFE 0x0400 /* ALC650 series */
489484Sgarrett.damore@Sun.COM #define ADFC_MIC 0x0000
499484Sgarrett.damore@Sun.COM #define ADFC_SURROUND 0x0200
509484Sgarrett.damore@Sun.COM #define ADFC_LINEIN 0x0000
519484Sgarrett.damore@Sun.COM #define ADFC_FRONT_MIC_MONO_OUT 0x0100 /* ALC850 */
529484Sgarrett.damore@Sun.COM #define ADFC_ANALOG_INPUT_PASS_CLFE 0x0020
539484Sgarrett.damore@Sun.COM #define ADFC_ANALOG_INPUT_PASS_SURROUND 0x0010
549484Sgarrett.damore@Sun.COM #define ADFC_SURROUND_MIRROR 0x0001
559484Sgarrett.damore@Sun.COM
569484Sgarrett.damore@Sun.COM #define ALC_SURROUND_DAC_REGISTER 0x64
579484Sgarrett.damore@Sun.COM #define ASD_SURROUND_MUTE 0x8000
589484Sgarrett.damore@Sun.COM #define ASD_SURR_LEFT_VOL 0x1f00
599484Sgarrett.damore@Sun.COM #define ASD_SURR_RIGHT_VOL 0x001f
609484Sgarrett.damore@Sun.COM
619484Sgarrett.damore@Sun.COM #define ALC_CEN_LFE_DAC_REGISTER 0x66
629484Sgarrett.damore@Sun.COM #define ACLD_CEN_LFE_MUTE 0x8000
639484Sgarrett.damore@Sun.COM #define ACLD_LFE_VOL 0x1f00
649484Sgarrett.damore@Sun.COM #define ACLD_CEN_VOL 0x001f
659484Sgarrett.damore@Sun.COM
669484Sgarrett.damore@Sun.COM #define ALC_MISC_CTRL_REGISTER 0x7a
679484Sgarrett.damore@Sun.COM #define AMC_XTLSEL 0x8000
689484Sgarrett.damore@Sun.COM #define AMC_VREFOUT_DIS 0x1000
699484Sgarrett.damore@Sun.COM #define AMC_INDEP_MUTE_CTRL 0x0800
709484Sgarrett.damore@Sun.COM #define AMC_JD2_SURR_CEN_LFE 0x0008
719484Sgarrett.damore@Sun.COM #define AMC_JD1_SURR_CEN_LFE 0x0004
729484Sgarrett.damore@Sun.COM #define AMC_PIN47_SPDIF 0x0002
739484Sgarrett.damore@Sun.COM #define AMC_PIN47_EAPD 0x0000
749484Sgarrett.damore@Sun.COM #define AMC_JD0_SURR_CEN_LFE 0x0001
759484Sgarrett.damore@Sun.COM
769484Sgarrett.damore@Sun.COM static void
alc650_set_linein_func(ac97_ctrl_t * actrl,uint64_t value)779484Sgarrett.damore@Sun.COM alc650_set_linein_func(ac97_ctrl_t *actrl, uint64_t value)
789484Sgarrett.damore@Sun.COM {
799484Sgarrett.damore@Sun.COM ac97_t *ac = actrl->actrl_ac97;
809484Sgarrett.damore@Sun.COM
81*10413SGarrett.Damore@Sun.COM ac_wr(ac, AC97_INTERRUPT_PAGING_REGISTER, 0); /* select page 0 */
829484Sgarrett.damore@Sun.COM if (value & 2) {
83*10413SGarrett.Damore@Sun.COM ac_set(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_SURROUND);
849484Sgarrett.damore@Sun.COM } else {
85*10413SGarrett.Damore@Sun.COM ac_clr(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_SURROUND);
869484Sgarrett.damore@Sun.COM }
879484Sgarrett.damore@Sun.COM }
889484Sgarrett.damore@Sun.COM
899484Sgarrett.damore@Sun.COM static void
alc650_set_mic_func(ac97_ctrl_t * actrl,uint64_t value)909484Sgarrett.damore@Sun.COM alc650_set_mic_func(ac97_ctrl_t *actrl, uint64_t value)
919484Sgarrett.damore@Sun.COM {
929484Sgarrett.damore@Sun.COM ac97_t *ac = actrl->actrl_ac97;
939484Sgarrett.damore@Sun.COM
94*10413SGarrett.Damore@Sun.COM ac_wr(ac, AC97_INTERRUPT_PAGING_REGISTER, 0); /* select page 0 */
959484Sgarrett.damore@Sun.COM if (value & 2) {
96*10413SGarrett.Damore@Sun.COM ac_set(ac, ALC_MISC_CTRL_REGISTER, AMC_VREFOUT_DIS);
97*10413SGarrett.Damore@Sun.COM ac_set(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_CENTER_LFE);
989484Sgarrett.damore@Sun.COM } else {
99*10413SGarrett.Damore@Sun.COM ac_clr(ac, ALC_MISC_CTRL_REGISTER, AMC_VREFOUT_DIS);
100*10413SGarrett.Damore@Sun.COM ac_clr(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_CENTER_LFE);
1019484Sgarrett.damore@Sun.COM }
1029484Sgarrett.damore@Sun.COM }
1039484Sgarrett.damore@Sun.COM
1049484Sgarrett.damore@Sun.COM #if 0
1059484Sgarrett.damore@Sun.COM static void
1069484Sgarrett.damore@Sun.COM alc850_set_auxin_func(ac97_ctrl_t *actrl, uint64_t value)
1079484Sgarrett.damore@Sun.COM {
1089484Sgarrett.damore@Sun.COM ac97_t *ac = actrl->actrl_ac97;
1099484Sgarrett.damore@Sun.COM
110*10413SGarrett.Damore@Sun.COM ac_wr(ac, AC97_INTERRUPT_PAGING_REGISTER, 0); /* select page 0 */
1119484Sgarrett.damore@Sun.COM if (value & 2) {
112*10413SGarrett.Damore@Sun.COM ac_set(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_BACK_SURROUND);
1139484Sgarrett.damore@Sun.COM } else {
114*10413SGarrett.Damore@Sun.COM ac_clr(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_BACK_SURROUND);
1159484Sgarrett.damore@Sun.COM }
1169484Sgarrett.damore@Sun.COM }
1179484Sgarrett.damore@Sun.COM #endif
1189484Sgarrett.damore@Sun.COM
1199484Sgarrett.damore@Sun.COM static void
alc650_set_pcm(ac97_ctrl_t * actrl,uint64_t value)1209484Sgarrett.damore@Sun.COM alc650_set_pcm(ac97_ctrl_t *actrl, uint64_t value)
1219484Sgarrett.damore@Sun.COM {
1229484Sgarrett.damore@Sun.COM ac97_t *ac = actrl->actrl_ac97;
1239484Sgarrett.damore@Sun.COM uint16_t adj_value;
1249484Sgarrett.damore@Sun.COM uint16_t mute;
1259484Sgarrett.damore@Sun.COM uint8_t vol;
1269484Sgarrett.damore@Sun.COM
1279484Sgarrett.damore@Sun.COM /* limit input values to 16 bits and split to right and left */
1289484Sgarrett.damore@Sun.COM vol = value & 0xff;
1299484Sgarrett.damore@Sun.COM
1309484Sgarrett.damore@Sun.COM /* If this control is mute-able than set as muted if needed */
1319484Sgarrett.damore@Sun.COM mute = vol ? 0 : ASD_SURROUND_MUTE;
132*10413SGarrett.Damore@Sun.COM adj_value = ac_val_scale(vol, vol, 5) | mute;
1339484Sgarrett.damore@Sun.COM
1349484Sgarrett.damore@Sun.COM /* select page 0 */
135*10413SGarrett.Damore@Sun.COM ac_wr(ac, AC97_INTERRUPT_PAGING_REGISTER, 0);
1369484Sgarrett.damore@Sun.COM /* adjust all three PCM volumes */
137*10413SGarrett.Damore@Sun.COM ac_wr(ac, AC97_PCM_OUT_VOLUME_REGISTER, adj_value);
138*10413SGarrett.Damore@Sun.COM ac_wr(ac, ALC_SURROUND_DAC_REGISTER, adj_value);
139*10413SGarrett.Damore@Sun.COM ac_wr(ac, ALC_CEN_LFE_DAC_REGISTER, adj_value);
1409484Sgarrett.damore@Sun.COM }
1419484Sgarrett.damore@Sun.COM
1429484Sgarrett.damore@Sun.COM static const char *alc_linein_funcs[] = {
1439484Sgarrett.damore@Sun.COM AUDIO_PORT_LINEIN,
1449484Sgarrett.damore@Sun.COM AUDIO_PORT_SURROUND,
1459484Sgarrett.damore@Sun.COM NULL
1469484Sgarrett.damore@Sun.COM };
1479484Sgarrett.damore@Sun.COM
1489484Sgarrett.damore@Sun.COM static const char *alc_mic_funcs[] = {
1499484Sgarrett.damore@Sun.COM AUDIO_PORT_MIC,
1509484Sgarrett.damore@Sun.COM AUDIO_PORT_CENLFE,
1519484Sgarrett.damore@Sun.COM NULL
1529484Sgarrett.damore@Sun.COM };
1539484Sgarrett.damore@Sun.COM
1549484Sgarrett.damore@Sun.COM static ac97_ctrl_probe_t alc650_linein_func_cpt = {
1559484Sgarrett.damore@Sun.COM AUDIO_CTRL_ID_JACK1, 1, 3, 3, AUDIO_CTRL_TYPE_ENUM, AC97_FLAGS,
1569484Sgarrett.damore@Sun.COM 0, alc650_set_linein_func, NULL, 0, alc_linein_funcs
1579484Sgarrett.damore@Sun.COM };
1589484Sgarrett.damore@Sun.COM static ac97_ctrl_probe_t alc650_mic_func_cpt = {
1599484Sgarrett.damore@Sun.COM AUDIO_CTRL_ID_JACK2, 1, 3, 3, AUDIO_CTRL_TYPE_ENUM, AC97_FLAGS,
1609484Sgarrett.damore@Sun.COM 0, alc650_set_mic_func, NULL, 0, alc_mic_funcs
1619484Sgarrett.damore@Sun.COM };
1629484Sgarrett.damore@Sun.COM
1639484Sgarrett.damore@Sun.COM static void
alc_pcm_override(ac97_t * ac)1649484Sgarrett.damore@Sun.COM alc_pcm_override(ac97_t *ac)
1659484Sgarrett.damore@Sun.COM {
1669484Sgarrett.damore@Sun.COM ac97_ctrl_t *ctrl;
1679484Sgarrett.damore@Sun.COM
1689484Sgarrett.damore@Sun.COM /* override master PCM volume function */
1699484Sgarrett.damore@Sun.COM ctrl = ac97_control_find(ac, AUDIO_CTRL_ID_VOLUME);
1709484Sgarrett.damore@Sun.COM if (ctrl != NULL) {
1719484Sgarrett.damore@Sun.COM ctrl->actrl_write_fn = alc650_set_pcm;
1729484Sgarrett.damore@Sun.COM }
1739484Sgarrett.damore@Sun.COM }
1749484Sgarrett.damore@Sun.COM
1759484Sgarrett.damore@Sun.COM void
alc650_init(ac97_t * ac)1769484Sgarrett.damore@Sun.COM alc650_init(ac97_t *ac)
1779484Sgarrett.damore@Sun.COM {
1789484Sgarrett.damore@Sun.COM ac97_ctrl_probe_t cp;
1799484Sgarrett.damore@Sun.COM int ival;
1809484Sgarrett.damore@Sun.COM
1819484Sgarrett.damore@Sun.COM bcopy(&alc650_linein_func_cpt, &cp, sizeof (cp));
182*10413SGarrett.Damore@Sun.COM ival = ac_get_prop(ac, AC97_PROP_LINEIN_FUNC, 0);
1839484Sgarrett.damore@Sun.COM if ((ival >= 1) && (ival <= 2)) {
1849484Sgarrett.damore@Sun.COM cp.cp_initval = ival;
1859484Sgarrett.damore@Sun.COM }
186*10413SGarrett.Damore@Sun.COM ac_add_control(ac, &cp);
1879484Sgarrett.damore@Sun.COM
1889484Sgarrett.damore@Sun.COM bcopy(&alc650_mic_func_cpt, &cp, sizeof (cp));
189*10413SGarrett.Damore@Sun.COM ival = ac_get_prop(ac, AC97_PROP_MIC_FUNC, 0);
1909484Sgarrett.damore@Sun.COM if ((ival >= 1) && (ival <= 2)) {
1919484Sgarrett.damore@Sun.COM cp.cp_initval = ival;
1929484Sgarrett.damore@Sun.COM }
193*10413SGarrett.Damore@Sun.COM ac_add_control(ac, &cp);
1949484Sgarrett.damore@Sun.COM
1959484Sgarrett.damore@Sun.COM alc_pcm_override(ac);
1969484Sgarrett.damore@Sun.COM }
1979484Sgarrett.damore@Sun.COM
1989484Sgarrett.damore@Sun.COM void
alc850_init(ac97_t * ac)1999484Sgarrett.damore@Sun.COM alc850_init(ac97_t *ac)
2009484Sgarrett.damore@Sun.COM {
2019484Sgarrett.damore@Sun.COM /*
2029484Sgarrett.damore@Sun.COM * NB: We could probably enable 7.1 here using the AUXIN source,
2039484Sgarrett.damore@Sun.COM * but there are a few details still missing from the data sheet.
2049484Sgarrett.damore@Sun.COM * (Such as, how is volume from the back-surround DAC managed?,
2059484Sgarrett.damore@Sun.COM * and what SDATA slots are the back surround delivered on?)
2069484Sgarrett.damore@Sun.COM *
2079484Sgarrett.damore@Sun.COM * Also, the AC'97 controllers themselves don't necessarily support
2089484Sgarrett.damore@Sun.COM * 7.1, so we'd have to figure out how to coordinate detection
2099484Sgarrett.damore@Sun.COM * with the controller. 5.1 should be good enough for now.
2109484Sgarrett.damore@Sun.COM *
2119484Sgarrett.damore@Sun.COM * Unlike other products, ALC850 has separate pins for 5.1 data,
2129484Sgarrett.damore@Sun.COM * so jack retasking isn't needed. However, it can retask
2139484Sgarrett.damore@Sun.COM * some jacks, but we don't have full details for that right
2149484Sgarrett.damore@Sun.COM * now. We've not seen it on any systems (yet) where this was
2159484Sgarrett.damore@Sun.COM * necessary, though.
2169484Sgarrett.damore@Sun.COM */
2179484Sgarrett.damore@Sun.COM
2189484Sgarrett.damore@Sun.COM alc_pcm_override(ac);
2199484Sgarrett.damore@Sun.COM }
220