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 (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
26 * CMI (C-Media) codec extensions.
29 #include <sys/types.h>
31 #include <sys/sunddi.h>
32 #include <sys/audio/audio_driver.h>
33 #include <sys/audio/ac97.h>
35 #include "ac97_impl.h"
38 * C-Media 9739 part is weird. Instead of having independent volume
39 * controls for each of the channels, it uses a single master volume
40 * and just provides mute support for the other bits. It does this
41 * for PCM volume as well, so we can't use it either. Ugh. It also
42 * has an optional 30 dB mic boost. Apparently the 9761 behaves in
43 * much the same fashion as the 9739.
45 * C-Media 9738 is a more or less typical 4CH device according to the
46 * datasheet. It however supports jack retasking allowing the line in
47 * jack to function as a surround output. Google suggests that the
48 * volume controls on this part are about as busted as on the other
49 * parts. So, we just use synthetic volume for it.
51 * C-Media 9780 is largely a mystery (ENODATASHEET).
55 #define CMI_TASK_REGISTER 0x5A /* 9738 jack retasking */
56 #define CTR_F2R 0x2000 /* front routed to rear */
57 #define CTR_S2LNI 0x0400 /* surround to line in */
59 #define CMI_MULTICH_REGISTER 0x64 /* 9739 and 9761a */
60 #define CMR_PCBSW 0x8000 /* PC Beep volume bypass */
61 #define CMR_P47 0x4000 /* configure P47 function */
62 #define CMR_REFCTL 0x2000 /* enable vref output */
63 #define CMR_CLCTL 0x1000 /* center/lfe output enable */
64 #define CMR_S2LNI 0x0400 /* surround to line in */
65 #define CMR_MIX2S 0x0200 /* analog input pass to surround */
66 #define CMR_BSTSEL 0x0001 /* micboost use 30dB */
69 cmi_set_micboost(ac97_ctrl_t
*actrl
, uint64_t value
)
71 ac97_t
*ac
= actrl
->actrl_ac97
;
73 ac_wr(ac
, AC97_INTERRUPT_PAGING_REGISTER
, 0); /* select page 0 */
77 ac_clr(ac
, AC97_MIC_VOLUME_REGISTER
, MICVR_20dB_BOOST
);
78 ac_clr(ac
, CMI_MULTICH_REGISTER
, CMR_BSTSEL
);
82 ac_set(ac
, AC97_MIC_VOLUME_REGISTER
, MICVR_20dB_BOOST
);
83 ac_clr(ac
, CMI_MULTICH_REGISTER
, CMR_BSTSEL
);
87 ac_set(ac
, AC97_MIC_VOLUME_REGISTER
, MICVR_20dB_BOOST
);
88 ac_set(ac
, CMI_MULTICH_REGISTER
, CMR_BSTSEL
);
94 cmi_set_linein_func(ac97_ctrl_t
*actrl
, uint64_t value
)
96 ac97_t
*ac
= actrl
->actrl_ac97
;
98 ac_wr(ac
, AC97_INTERRUPT_PAGING_REGISTER
, 0); /* select page 0 */
100 ac_set(ac
, CMI_MULTICH_REGISTER
, CMR_S2LNI
);
102 ac_clr(ac
, CMI_MULTICH_REGISTER
, CMR_S2LNI
);
107 cmi_set_mic_func(ac97_ctrl_t
*actrl
, uint64_t value
)
109 ac97_t
*ac
= actrl
->actrl_ac97
;
111 ac_wr(ac
, AC97_INTERRUPT_PAGING_REGISTER
, 0); /* select page 0 */
113 ac_set(ac
, CMI_MULTICH_REGISTER
, CMR_CLCTL
);
115 ac_clr(ac
, CMI_MULTICH_REGISTER
, CMR_CLCTL
);
120 cmi_setup_micboost(ac97_t
*ac
)
124 static const char *values
[] = {
125 AUDIO_VALUE_OFF
, /* 0dB */
126 AUDIO_VALUE_MEDIUM
, /* 20dB */
127 AUDIO_VALUE_HIGH
, /* 30dB */
130 ac97_ctrl_probe_t cpt
= {
131 AUDIO_CTRL_ID_MICBOOST
, 1, 0xf, 0xf, AUDIO_CTRL_TYPE_ENUM
,
132 AC97_FLAGS
| AUDIO_CTRL_FLAG_REC
, 0, cmi_set_micboost
,
135 ctrl
= ac97_control_find(ac
, AUDIO_CTRL_ID_MICBOOST
);
137 if (ctrl
->actrl_initval
) {
138 /* 20dB by default */
143 ac_add_control(ac
, &cpt
);
146 static const char *cmi_linein_funcs
[] = {
152 static const char *cmi_mic_funcs
[] = {
159 cmi_setup_jack_funcs(ac97_t
*ac
)
161 ac97_ctrl_probe_t cp
;
164 ac97_ctrl_probe_t linein_cpt
= {
165 AUDIO_CTRL_ID_JACK1
, 1, 3, 3, AUDIO_CTRL_TYPE_ENUM
, AC97_FLAGS
,
166 0, cmi_set_linein_func
, NULL
, 0, cmi_linein_funcs
168 ac97_ctrl_probe_t mic_cpt
= {
169 AUDIO_CTRL_ID_JACK2
, 1, 3, 3, AUDIO_CTRL_TYPE_ENUM
, AC97_FLAGS
,
170 0, cmi_set_mic_func
, NULL
, 0, cmi_mic_funcs
173 bcopy(&linein_cpt
, &cp
, sizeof (cp
));
174 ival
= ac_get_prop(ac
, AC97_PROP_LINEIN_FUNC
, 0);
175 if ((ival
>= 1) && (ival
<= 2)) {
176 cp
.cp_initval
= ival
;
178 ac_add_control(ac
, &cp
);
180 bcopy(&mic_cpt
, &cp
, sizeof (cp
));
181 ival
= ac_get_prop(ac
, AC97_PROP_MIC_FUNC
, 0);
182 if ((ival
>= 1) && (ival
<= 2)) {
183 cp
.cp_initval
= ival
;
185 ac_add_control(ac
, &cp
);
189 cmi_set_linein_func_9738(ac97_ctrl_t
*actrl
, uint64_t value
)
191 ac97_t
*ac
= actrl
->actrl_ac97
;
194 ac_set(ac
, CMI_TASK_REGISTER
, CTR_S2LNI
);
196 ac_clr(ac
, CMI_TASK_REGISTER
, CTR_S2LNI
);
201 cmi_set_spread_9738(ac97_ctrl_t
*actrl
, uint64_t value
)
203 ac97_t
*ac
= actrl
->actrl_ac97
;
206 ac_set(ac
, CMI_TASK_REGISTER
, CTR_F2R
);
208 ac_clr(ac
, CMI_TASK_REGISTER
, CTR_F2R
);
213 cmi_setup_jack_func_9738(ac97_t
*ac
)
215 ac97_ctrl_probe_t cp
;
218 ac97_ctrl_probe_t linein_cpt
= {
219 AUDIO_CTRL_ID_JACK1
, 1, 3, 3, AUDIO_CTRL_TYPE_ENUM
, AC97_FLAGS
,
220 0, cmi_set_linein_func_9738
, NULL
, 0, cmi_linein_funcs
222 ac97_ctrl_probe_t spread_cpt
= {
223 AUDIO_CTRL_ID_SPREAD
, 0, 0, 1, AUDIO_CTRL_TYPE_BOOLEAN
,
224 AC97_FLAGS
, 0, cmi_set_spread_9738
,
227 bcopy(&linein_cpt
, &cp
, sizeof (cp
));
228 ival
= ac_get_prop(ac
, AC97_PROP_LINEIN_FUNC
, 0);
229 if ((ival
>= 1) && (ival
<= 2)) {
230 cp
.cp_initval
= ival
;
232 ac_add_control(ac
, &cp
);
234 bcopy(&spread_cpt
, &cp
, sizeof (cp
));
235 ival
= ac_get_prop(ac
, AC97_PROP_SPREAD
, -1);
236 if ((ival
>= 0) && (ival
<= 1)) {
237 cp
.cp_initval
= ival
;
239 ac_add_control(ac
, &cp
);
244 cmi_setup_volume(ac97_t
*ac
)
249 * These CMI parts seem to be really weird. They don't have
250 * *any* functioning volume controls on them (mute only) apart
251 * from the record and monitor sources (excluding PCM). I
252 * don't understand why not. We just eliminate all of the
253 * volume controls and replace with a soft volume control.
254 * Its not an ideal situation, but I don't know what else I
257 ctrl
= ac97_control_find(ac
, AUDIO_CTRL_ID_VOLUME
);
259 ac97_control_remove(ctrl
);
261 ctrl
= ac97_control_find(ac
, AUDIO_CTRL_ID_FRONT
);
263 ac97_control_remove(ctrl
);
265 ctrl
= ac97_control_find(ac
, AUDIO_CTRL_ID_SURROUND
);
267 ac97_control_remove(ctrl
);
269 ctrl
= ac97_control_find(ac
, AUDIO_CTRL_ID_CENTER
);
271 ac97_control_remove(ctrl
);
273 ctrl
= ac97_control_find(ac
, AUDIO_CTRL_ID_LFE
);
275 ac97_control_remove(ctrl
);
278 /* make sure we have disabled mute and attenuation on physical ctrls */
279 ac_wr(ac
, AC97_INTERRUPT_PAGING_REGISTER
, 0); /* select page 0 */
280 ac_wr(ac
, AC97_PCM_OUT_VOLUME_REGISTER
, 0);
281 ac_wr(ac
, AC97_MASTER_VOLUME_REGISTER
, 0);
282 ac_wr(ac
, AC97_EXTENDED_C_LFE_VOLUME_REGISTER
, 0);
283 ac_wr(ac
, AC97_EXTENDED_LRS_VOLUME_REGISTER
, 0);
286 * NB: This is probably not the best way to do this, because
287 * it will make overriding this hard for drivers that desire
288 * to. Fortunately, we don't think any drivers that want to
289 * override or fine tune AC'97 controls (i.e. creative cards)
290 * use these C-Media codecs.
292 audio_dev_add_soft_volume(ac_get_dev(ac
));
296 cmi9739_init(ac97_t
*ac
)
298 cmi_setup_volume(ac
);
299 cmi_setup_micboost(ac
);
300 cmi_setup_jack_funcs(ac
);
304 cmi9761_init(ac97_t
*ac
)
306 cmi_setup_volume(ac
);
307 cmi_setup_micboost(ac
);
308 cmi_setup_jack_funcs(ac
);
312 cmi9738_init(ac97_t
*ac
)
314 cmi_setup_volume(ac
);
315 cmi_setup_jack_func_9738(ac
);