1 /* 2 * rt298.h -- RT298 ALSA SoC audio driver 3 * 4 * Copyright 2011 Realtek Microelectronics 5 * Author: Johnny Hsu <johnnyhsu@realtek.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 */ 11 12 #ifndef __RT298_H__ 13 #define __RT298_H__ 14 15 #define VERB_CMD(V, N, D) ((N << 20) | (V << 8) | D) 16 17 #define RT298_AUDIO_FUNCTION_GROUP 0x01 18 #define RT298_DAC_OUT1 0x02 19 #define RT298_DAC_OUT2 0x03 20 #define RT298_DIG_CVT 0x06 21 #define RT298_ADC_IN1 0x09 22 #define RT298_ADC_IN2 0x08 23 #define RT298_MIXER_IN 0x0b 24 #define RT298_MIXER_OUT1 0x0c 25 #define RT298_MIXER_OUT2 0x0d 26 #define RT298_DMIC1 0x12 27 #define RT298_DMIC2 0x13 28 #define RT298_SPK_OUT 0x14 29 #define RT298_MIC1 0x18 30 #define RT298_LINE1 0x1a 31 #define RT298_BEEP 0x1d 32 #define RT298_SPDIF 0x1e 33 #define RT298_VENDOR_REGISTERS 0x20 34 #define RT298_HP_OUT 0x21 35 #define RT298_MIXER_IN1 0x22 36 #define RT298_MIXER_IN2 0x23 37 38 #define RT298_SET_PIN_SFT 6 39 #define RT298_SET_PIN_ENABLE 0x40 40 #define RT298_SET_PIN_DISABLE 0 41 #define RT298_SET_EAPD_HIGH 0x2 42 #define RT298_SET_EAPD_LOW 0 43 44 #define RT298_MUTE_SFT 7 45 46 /* Verb commands */ 47 #define RT298_GET_PARAM(NID, PARAM) VERB_CMD(AC_VERB_PARAMETERS, NID, PARAM) 48 #define RT298_SET_POWER(NID) VERB_CMD(AC_VERB_SET_POWER_STATE, NID, 0) 49 #define RT298_SET_AUDIO_POWER RT298_SET_POWER(RT298_AUDIO_FUNCTION_GROUP) 50 #define RT298_SET_HPO_POWER RT298_SET_POWER(RT298_HP_OUT) 51 #define RT298_SET_SPK_POWER RT298_SET_POWER(RT298_SPK_OUT) 52 #define RT298_SET_DMIC1_POWER RT298_SET_POWER(RT298_DMIC1) 53 #define RT298_SPK_MUX\ 54 VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT298_SPK_OUT, 0) 55 #define RT298_HPO_MUX\ 56 VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT298_HP_OUT, 0) 57 #define RT298_ADC0_MUX\ 58 VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT298_MIXER_IN1, 0) 59 #define RT298_ADC1_MUX\ 60 VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT298_MIXER_IN2, 0) 61 #define RT298_SET_MIC1\ 62 VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT298_MIC1, 0) 63 #define RT298_SET_PIN_HPO\ 64 VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT298_HP_OUT, 0) 65 #define RT298_SET_PIN_SPK\ 66 VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT298_SPK_OUT, 0) 67 #define RT298_SET_PIN_DMIC1\ 68 VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT298_DMIC1, 0) 69 #define RT298_SET_PIN_SPDIF\ 70 VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT298_SPDIF, 0) 71 #define RT298_SET_PIN_DIG_CVT\ 72 VERB_CMD(AC_VERB_SET_DIGI_CONVERT_1, RT298_DIG_CVT, 0) 73 #define RT298_SPK_EAPD\ 74 VERB_CMD(AC_VERB_SET_EAPD_BTLENABLE, RT298_SPK_OUT, 0) 75 #define RT298_SET_AMP_GAIN_HPO\ 76 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_HP_OUT, 0) 77 #define RT298_SET_AMP_GAIN_ADC_IN1\ 78 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_ADC_IN1, 0) 79 #define RT298_SET_AMP_GAIN_ADC_IN2\ 80 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_ADC_IN2, 0) 81 #define RT298_GET_HP_SENSE\ 82 VERB_CMD(AC_VERB_GET_PIN_SENSE, RT298_HP_OUT, 0) 83 #define RT298_GET_MIC1_SENSE\ 84 VERB_CMD(AC_VERB_GET_PIN_SENSE, RT298_MIC1, 0) 85 #define RT298_SET_DMIC2_DEFAULT\ 86 VERB_CMD(AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, RT298_DMIC2, 0) 87 #define RT298_SET_SPDIF_DEFAULT\ 88 VERB_CMD(AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, RT298_SPDIF, 0) 89 #define RT298_DACL_GAIN\ 90 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_DAC_OUT1, 0xa000) 91 #define RT298_DACR_GAIN\ 92 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_DAC_OUT1, 0x9000) 93 #define RT298_ADCL_GAIN\ 94 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_ADC_IN1, 0x6000) 95 #define RT298_ADCR_GAIN\ 96 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_ADC_IN1, 0x5000) 97 #define RT298_MIC_GAIN\ 98 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIC1, 0x7000) 99 #define RT298_SPOL_GAIN\ 100 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_SPK_OUT, 0xa000) 101 #define RT298_SPOR_GAIN\ 102 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_SPK_OUT, 0x9000) 103 #define RT298_HPOL_GAIN\ 104 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_HP_OUT, 0xa000) 105 #define RT298_HPOR_GAIN\ 106 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_HP_OUT, 0x9000) 107 #define RT298_F_DAC_SWITCH\ 108 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_OUT1, 0x7000) 109 #define RT298_F_RECMIX_SWITCH\ 110 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_OUT1, 0x7100) 111 #define RT298_REC_MIC_SWITCH\ 112 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_IN, 0x7000) 113 #define RT298_REC_I2S_SWITCH\ 114 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_IN, 0x7100) 115 #define RT298_REC_LINE_SWITCH\ 116 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_IN, 0x7200) 117 #define RT298_REC_BEEP_SWITCH\ 118 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_IN, 0x7300) 119 #define RT298_DAC_FORMAT\ 120 VERB_CMD(AC_VERB_SET_STREAM_FORMAT, RT298_DAC_OUT1, 0) 121 #define RT298_ADC_FORMAT\ 122 VERB_CMD(AC_VERB_SET_STREAM_FORMAT, RT298_ADC_IN1, 0) 123 #define RT298_COEF_INDEX\ 124 VERB_CMD(AC_VERB_SET_COEF_INDEX, RT298_VENDOR_REGISTERS, 0) 125 #define RT298_PROC_COEF\ 126 VERB_CMD(AC_VERB_SET_PROC_COEF, RT298_VENDOR_REGISTERS, 0) 127 128 /* Index registers */ 129 #define RT298_A_BIAS_CTRL1 0x01 130 #define RT298_A_BIAS_CTRL2 0x02 131 #define RT298_POWER_CTRL1 0x03 132 #define RT298_A_BIAS_CTRL3 0x04 133 #define RT298_POWER_CTRL2 0x08 134 #define RT298_I2S_CTRL1 0x09 135 #define RT298_I2S_CTRL2 0x0a 136 #define RT298_CLK_DIV 0x0b 137 #define RT298_DC_GAIN 0x0d 138 #define RT298_POWER_CTRL3 0x0f 139 #define RT298_MIC1_DET_CTRL 0x19 140 #define RT298_MISC_CTRL1 0x20 141 #define RT298_IRQ_CTRL 0x33 142 #define RT298_WIND_FILTER_CTRL 0x46 143 #define RT298_PLL_CTRL1 0x49 144 #define RT298_CBJ_CTRL1 0x4f 145 #define RT298_CBJ_CTRL2 0x50 146 #define RT298_PLL_CTRL 0x63 147 #define RT298_DEPOP_CTRL1 0x66 148 #define RT298_DEPOP_CTRL2 0x67 149 #define RT298_DEPOP_CTRL3 0x68 150 #define RT298_DEPOP_CTRL4 0x69 151 152 /* SPDIF (0x06) */ 153 #define RT298_SPDIF_SEL_SFT 0 154 #define RT298_SPDIF_SEL_PCM0 0 155 #define RT298_SPDIF_SEL_PCM1 1 156 #define RT298_SPDIF_SEL_SPOUT 2 157 #define RT298_SPDIF_SEL_PP 3 158 159 /* RECMIX (0x0b) */ 160 #define RT298_M_REC_BEEP_SFT 0 161 #define RT298_M_REC_LINE1_SFT 1 162 #define RT298_M_REC_MIC1_SFT 2 163 #define RT298_M_REC_I2S_SFT 3 164 165 /* Front (0x0c) */ 166 #define RT298_M_FRONT_DAC_SFT 0 167 #define RT298_M_FRONT_REC_SFT 1 168 169 /* SPK-OUT (0x14) */ 170 #define RT298_M_SPK_MUX_SFT 14 171 #define RT298_SPK_SEL_MASK 0x1 172 #define RT298_SPK_SEL_SFT 0 173 #define RT298_SPK_SEL_F 0 174 #define RT298_SPK_SEL_S 1 175 176 /* HP-OUT (0x21) */ 177 #define RT298_M_HP_MUX_SFT 14 178 #define RT298_HP_SEL_MASK 0x1 179 #define RT298_HP_SEL_SFT 0 180 #define RT298_HP_SEL_F 0 181 #define RT298_HP_SEL_S 1 182 183 /* ADC (0x22) (0x23) */ 184 #define RT298_ADC_SEL_MASK 0x7 185 #define RT298_ADC_SEL_SFT 0 186 #define RT298_ADC_SEL_SURR 0 187 #define RT298_ADC_SEL_FRONT 1 188 #define RT298_ADC_SEL_DMIC 2 189 #define RT298_ADC_SEL_BEEP 4 190 #define RT298_ADC_SEL_LINE1 5 191 #define RT298_ADC_SEL_I2S 6 192 #define RT298_ADC_SEL_MIC1 7 193 194 #define RT298_SCLK_S_MCLK 0 195 #define RT298_SCLK_S_PLL 1 196 197 enum { 198 RT298_AIF1, 199 RT298_AIF2, 200 RT298_AIFS, 201 }; 202 203 int rt298_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack); 204 205 #endif /* __RT298_H__ */ 206 207