4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * ALC (Realtek/Advance Logic) codec extensions.
30 #include <sys/types.h>
32 #include <sys/sunddi.h>
33 #include <sys/audio/audio_driver.h>
34 #include <sys/audio/ac97.h>
36 #include "ac97_impl.h"
38 #define ALC_DATA_FLOW_CTRL_REGISTER 0x6a
39 #define ADFC_SPDIFIN_EN 0x8000
40 #define ADFC_SPDIFIN_MON_EN 0x4000
41 #define ADFC_SPDIF_OUT_MASK 0x3000
42 #define ADFC_SPDIF_OUT_ACLINK 0x0000
43 #define ADFC_SPDIF_OUT_ADC 0x1000
44 #define ADFC_SPDIF_OUT_BYPASS 0x2000
45 #define ADFC_PCM_SPDIFIN 0x0800
46 #define ADFC_BACK_SURROUND 0x0400 /* ALC850 only */
47 #define ADFC_CENTER_LFE 0x0400 /* ALC650 series */
48 #define ADFC_MIC 0x0000
49 #define ADFC_SURROUND 0x0200
50 #define ADFC_LINEIN 0x0000
51 #define ADFC_FRONT_MIC_MONO_OUT 0x0100 /* ALC850 */
52 #define ADFC_ANALOG_INPUT_PASS_CLFE 0x0020
53 #define ADFC_ANALOG_INPUT_PASS_SURROUND 0x0010
54 #define ADFC_SURROUND_MIRROR 0x0001
56 #define ALC_SURROUND_DAC_REGISTER 0x64
57 #define ASD_SURROUND_MUTE 0x8000
58 #define ASD_SURR_LEFT_VOL 0x1f00
59 #define ASD_SURR_RIGHT_VOL 0x001f
61 #define ALC_CEN_LFE_DAC_REGISTER 0x66
62 #define ACLD_CEN_LFE_MUTE 0x8000
63 #define ACLD_LFE_VOL 0x1f00
64 #define ACLD_CEN_VOL 0x001f
66 #define ALC_MISC_CTRL_REGISTER 0x7a
67 #define AMC_XTLSEL 0x8000
68 #define AMC_VREFOUT_DIS 0x1000
69 #define AMC_INDEP_MUTE_CTRL 0x0800
70 #define AMC_JD2_SURR_CEN_LFE 0x0008
71 #define AMC_JD1_SURR_CEN_LFE 0x0004
72 #define AMC_PIN47_SPDIF 0x0002
73 #define AMC_PIN47_EAPD 0x0000
74 #define AMC_JD0_SURR_CEN_LFE 0x0001
77 alc650_set_linein_func(ac97_ctrl_t
*actrl
, uint64_t value
)
79 ac97_t
*ac
= actrl
->actrl_ac97
;
81 ac_wr(ac
, AC97_INTERRUPT_PAGING_REGISTER
, 0); /* select page 0 */
83 ac_set(ac
, ALC_DATA_FLOW_CTRL_REGISTER
, ADFC_SURROUND
);
85 ac_clr(ac
, ALC_DATA_FLOW_CTRL_REGISTER
, ADFC_SURROUND
);
90 alc650_set_mic_func(ac97_ctrl_t
*actrl
, uint64_t value
)
92 ac97_t
*ac
= actrl
->actrl_ac97
;
94 ac_wr(ac
, AC97_INTERRUPT_PAGING_REGISTER
, 0); /* select page 0 */
96 ac_set(ac
, ALC_MISC_CTRL_REGISTER
, AMC_VREFOUT_DIS
);
97 ac_set(ac
, ALC_DATA_FLOW_CTRL_REGISTER
, ADFC_CENTER_LFE
);
99 ac_clr(ac
, ALC_MISC_CTRL_REGISTER
, AMC_VREFOUT_DIS
);
100 ac_clr(ac
, ALC_DATA_FLOW_CTRL_REGISTER
, ADFC_CENTER_LFE
);
106 alc850_set_auxin_func(ac97_ctrl_t
*actrl
, uint64_t value
)
108 ac97_t
*ac
= actrl
->actrl_ac97
;
110 ac_wr(ac
, AC97_INTERRUPT_PAGING_REGISTER
, 0); /* select page 0 */
112 ac_set(ac
, ALC_DATA_FLOW_CTRL_REGISTER
, ADFC_BACK_SURROUND
);
114 ac_clr(ac
, ALC_DATA_FLOW_CTRL_REGISTER
, ADFC_BACK_SURROUND
);
120 alc650_set_pcm(ac97_ctrl_t
*actrl
, uint64_t value
)
122 ac97_t
*ac
= actrl
->actrl_ac97
;
127 /* limit input values to 16 bits and split to right and left */
130 /* If this control is mute-able than set as muted if needed */
131 mute
= vol
? 0 : ASD_SURROUND_MUTE
;
132 adj_value
= ac_val_scale(vol
, vol
, 5) | mute
;
135 ac_wr(ac
, AC97_INTERRUPT_PAGING_REGISTER
, 0);
136 /* adjust all three PCM volumes */
137 ac_wr(ac
, AC97_PCM_OUT_VOLUME_REGISTER
, adj_value
);
138 ac_wr(ac
, ALC_SURROUND_DAC_REGISTER
, adj_value
);
139 ac_wr(ac
, ALC_CEN_LFE_DAC_REGISTER
, adj_value
);
142 static const char *alc_linein_funcs
[] = {
148 static const char *alc_mic_funcs
[] = {
154 static ac97_ctrl_probe_t alc650_linein_func_cpt
= {
155 AUDIO_CTRL_ID_JACK1
, 1, 3, 3, AUDIO_CTRL_TYPE_ENUM
, AC97_FLAGS
,
156 0, alc650_set_linein_func
, NULL
, 0, alc_linein_funcs
158 static ac97_ctrl_probe_t alc650_mic_func_cpt
= {
159 AUDIO_CTRL_ID_JACK2
, 1, 3, 3, AUDIO_CTRL_TYPE_ENUM
, AC97_FLAGS
,
160 0, alc650_set_mic_func
, NULL
, 0, alc_mic_funcs
164 alc_pcm_override(ac97_t
*ac
)
168 /* override master PCM volume function */
169 ctrl
= ac97_control_find(ac
, AUDIO_CTRL_ID_VOLUME
);
171 ctrl
->actrl_write_fn
= alc650_set_pcm
;
176 alc650_init(ac97_t
*ac
)
178 ac97_ctrl_probe_t cp
;
181 bcopy(&alc650_linein_func_cpt
, &cp
, sizeof (cp
));
182 ival
= ac_get_prop(ac
, AC97_PROP_LINEIN_FUNC
, 0);
183 if ((ival
>= 1) && (ival
<= 2)) {
184 cp
.cp_initval
= ival
;
186 ac_add_control(ac
, &cp
);
188 bcopy(&alc650_mic_func_cpt
, &cp
, sizeof (cp
));
189 ival
= ac_get_prop(ac
, AC97_PROP_MIC_FUNC
, 0);
190 if ((ival
>= 1) && (ival
<= 2)) {
191 cp
.cp_initval
= ival
;
193 ac_add_control(ac
, &cp
);
195 alc_pcm_override(ac
);
199 alc850_init(ac97_t
*ac
)
202 * NB: We could probably enable 7.1 here using the AUXIN source,
203 * but there are a few details still missing from the data sheet.
204 * (Such as, how is volume from the back-surround DAC managed?,
205 * and what SDATA slots are the back surround delivered on?)
207 * Also, the AC'97 controllers themselves don't necessarily support
208 * 7.1, so we'd have to figure out how to coordinate detection
209 * with the controller. 5.1 should be good enough for now.
211 * Unlike other products, ALC850 has separate pins for 5.1 data,
212 * so jack retasking isn't needed. However, it can retask
213 * some jacks, but we don't have full details for that right
214 * now. We've not seen it on any systems (yet) where this was
218 alc_pcm_override(ac
);