1 /* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* 27 * ALC (Realtek/Advance Logic) codec extensions. 28 */ 29 30 #include <sys/types.h> 31 #include <sys/ddi.h> 32 #include <sys/sunddi.h> 33 #include <sys/audio/audio_driver.h> 34 #include <sys/audio/ac97.h> 35 #include <sys/note.h> 36 #include "ac97_impl.h" 37 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 55 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 60 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 65 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 75 76 static void 77 alc650_set_linein_func(ac97_ctrl_t *actrl, uint64_t value) 78 { 79 ac97_t *ac = actrl->actrl_ac97; 80 81 ac97_wr(ac, AC97_INTERRUPT_PAGING_REGISTER, 0); /* select page 0 */ 82 if (value & 2) { 83 ac97_set(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_SURROUND); 84 } else { 85 ac97_clr(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_SURROUND); 86 } 87 } 88 89 static void 90 alc650_set_mic_func(ac97_ctrl_t *actrl, uint64_t value) 91 { 92 ac97_t *ac = actrl->actrl_ac97; 93 94 ac97_wr(ac, AC97_INTERRUPT_PAGING_REGISTER, 0); /* select page 0 */ 95 if (value & 2) { 96 ac97_set(ac, ALC_MISC_CTRL_REGISTER, AMC_VREFOUT_DIS); 97 ac97_set(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_CENTER_LFE); 98 } else { 99 ac97_clr(ac, ALC_MISC_CTRL_REGISTER, AMC_VREFOUT_DIS); 100 ac97_clr(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_CENTER_LFE); 101 } 102 } 103 104 #if 0 105 static void 106 alc850_set_auxin_func(ac97_ctrl_t *actrl, uint64_t value) 107 { 108 ac97_t *ac = actrl->actrl_ac97; 109 110 ac97_wr(ac, AC97_INTERRUPT_PAGING_REGISTER, 0); /* select page 0 */ 111 if (value & 2) { 112 ac97_set(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_BACK_SURROUND); 113 } else { 114 ac97_clr(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_BACK_SURROUND); 115 } 116 } 117 #endif 118 119 static void 120 alc650_set_pcm(ac97_ctrl_t *actrl, uint64_t value) 121 { 122 ac97_t *ac = actrl->actrl_ac97; 123 uint16_t adj_value; 124 uint16_t mute; 125 uint8_t vol; 126 127 /* limit input values to 16 bits and split to right and left */ 128 vol = value & 0xff; 129 130 /* If this control is mute-able than set as muted if needed */ 131 mute = vol ? 0 : ASD_SURROUND_MUTE; 132 adj_value = ac97_val_scale(vol, vol, 5) | mute; 133 134 /* select page 0 */ 135 ac97_wr(ac, AC97_INTERRUPT_PAGING_REGISTER, 0); 136 /* adjust all three PCM volumes */ 137 ac97_wr(ac, AC97_PCM_OUT_VOLUME_REGISTER, adj_value); 138 ac97_wr(ac, ALC_SURROUND_DAC_REGISTER, adj_value); 139 ac97_wr(ac, ALC_CEN_LFE_DAC_REGISTER, adj_value); 140 } 141 142 static const char *alc_linein_funcs[] = { 143 AUDIO_PORT_LINEIN, 144 AUDIO_PORT_SURROUND, 145 NULL 146 }; 147 148 static const char *alc_mic_funcs[] = { 149 AUDIO_PORT_MIC, 150 AUDIO_PORT_CENLFE, 151 NULL 152 }; 153 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 157 }; 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 161 }; 162 163 static void 164 alc_pcm_override(ac97_t *ac) 165 { 166 ac97_ctrl_t *ctrl; 167 168 /* override master PCM volume function */ 169 ctrl = ac97_control_find(ac, AUDIO_CTRL_ID_VOLUME); 170 if (ctrl != NULL) { 171 ctrl->actrl_write_fn = alc650_set_pcm; 172 } 173 } 174 175 void 176 alc650_init(ac97_t *ac) 177 { 178 ac97_ctrl_probe_t cp; 179 int ival; 180 181 bcopy(&alc650_linein_func_cpt, &cp, sizeof (cp)); 182 ival = ac97_get_prop(ac, AC97_PROP_LINEIN_FUNC, 0); 183 if ((ival >= 1) && (ival <= 2)) { 184 cp.cp_initval = ival; 185 } 186 ac97_alloc_control(ac, &cp); 187 188 bcopy(&alc650_mic_func_cpt, &cp, sizeof (cp)); 189 ival = ac97_get_prop(ac, AC97_PROP_MIC_FUNC, 0); 190 if ((ival >= 1) && (ival <= 2)) { 191 cp.cp_initval = ival; 192 } 193 ac97_alloc_control(ac, &cp); 194 195 alc_pcm_override(ac); 196 } 197 198 void 199 alc850_init(ac97_t *ac) 200 { 201 /* 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?) 206 * 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. 210 * 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 215 * necessary, though. 216 */ 217 218 alc_pcm_override(ac); 219 } 220