Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * rt711.h -- RT711 ALSA SoC audio driver header
0004  *
0005  * Copyright(c) 2019 Realtek Semiconductor Corp.
0006  */
0007 
0008 #ifndef __RT711_H__
0009 #define __RT711_H__
0010 
0011 extern const struct dev_pm_ops rt711_runtime_pm;
0012 
0013 struct  rt711_priv {
0014     struct regmap *regmap;
0015     struct regmap *sdw_regmap;
0016     struct snd_soc_component *component;
0017     struct sdw_slave *slave;
0018     enum sdw_slave_status status;
0019     struct sdw_bus_params params;
0020     bool hw_init;
0021     bool first_hw_init;
0022     struct snd_soc_jack *hs_jack;
0023     struct delayed_work jack_detect_work;
0024     struct delayed_work jack_btn_check_work;
0025     struct work_struct calibration_work;
0026     struct mutex calibrate_mutex; /* for headset calibration */
0027     int jack_type, jd_src;
0028     struct mutex disable_irq_lock; /* imp-def irq lock protection */
0029     bool disable_irq;
0030 };
0031 
0032 struct sdw_stream_data {
0033     struct sdw_stream_runtime *sdw_stream;
0034 };
0035 
0036 /* NID */
0037 #define RT711_AUDIO_FUNCTION_GROUP          0x01
0038 #define RT711_DAC_OUT2                  0x03
0039 #define RT711_ADC_IN1                   0x09
0040 #define RT711_ADC_IN2                   0x08
0041 #define RT711_DMIC1                 0x12
0042 #define RT711_DMIC2                 0x13
0043 #define RT711_MIC2                  0x19
0044 #define RT711_LINE1                 0x1a
0045 #define RT711_LINE2                 0x1b
0046 #define RT711_BEEP                  0x1d
0047 #define RT711_VENDOR_REG                0x20
0048 #define RT711_HP_OUT                    0x21
0049 #define RT711_MIXER_IN1                 0x22
0050 #define RT711_MIXER_IN2                 0x23
0051 #define RT711_INLINE_CMD                0x55
0052 #define RT711_VENDOR_CALI               0x58
0053 #define RT711_VENDOR_IMS_DRE            0x5b
0054 
0055 /* Index (NID:20h) */
0056 #define RT711_DAC_DC_CALI_CTL1              0x00
0057 #define RT711_JD_CTL1               0x08
0058 #define RT711_JD_CTL2               0x09
0059 #define RT711_JD_CTL4               0x0b
0060 #define RT711_CC_DET1               0x11
0061 #define RT711_PARA_VERB_CTL             0x1a
0062 #define RT711_COMBO_JACK_AUTO_CTL1              0x45
0063 #define RT711_COMBO_JACK_AUTO_CTL2              0x46
0064 #define RT711_INLINE_CMD_CTL                0x48
0065 #define RT711_DIGITAL_MISC_CTRL4            0x4a
0066 #define RT711_VREFOUT_CTL               0x6b
0067 #define RT711_FSM_CTL               0x6f
0068 #define RT711_IRQ_FLAG_TABLE1               0x80
0069 #define RT711_IRQ_FLAG_TABLE2               0x81
0070 #define RT711_IRQ_FLAG_TABLE3               0x82
0071 #define RT711_TX_RX_MUX_CTL             0x91
0072 
0073 /* Index (NID:5bh) */
0074 #define RT711_IMS_DIGITAL_CTL1              0x00
0075 #define RT711_HP_IMS_RESULT_L               0x20
0076 #define RT711_HP_IMS_RESULT_R               0x21
0077 
0078 /* Verb */
0079 #define RT711_VERB_SET_CONNECT_SEL          0x3100
0080 #define RT711_VERB_SET_EAPD_BTLENABLE           0x3c00
0081 #define RT711_VERB_GET_CONNECT_SEL          0xb100
0082 #define RT711_VERB_SET_POWER_STATE          0x3500
0083 #define RT711_VERB_SET_CHANNEL_STREAMID         0x3600
0084 #define RT711_VERB_SET_PIN_WIDGET_CONTROL       0x3700
0085 #define RT711_VERB_SET_UNSOLICITED_ENABLE       0x3800
0086 #define RT711_SET_AMP_GAIN_MUTE_H           0x7300
0087 #define RT711_SET_AMP_GAIN_MUTE_L           0x8380
0088 #define RT711_VERB_GET_POWER_STATE          0xb500
0089 #define RT711_VERB_GET_CHANNEL_STREAMID         0xb600
0090 #define RT711_VERB_GET_PIN_SENSE            0xb900
0091 #define RT711_FUNC_RESET            0xff01
0092 
0093 #define RT711_READ_HDA_3                0x2012
0094 #define RT711_READ_HDA_2                0x2013
0095 #define RT711_READ_HDA_1                0x2014
0096 #define RT711_READ_HDA_0                0x2015
0097 #define RT711_PRIV_INDEX_W_H                0x7500
0098 #define RT711_PRIV_INDEX_W_L                0x8580
0099 #define RT711_PRIV_DATA_W_H             0x7400
0100 #define RT711_PRIV_DATA_W_L             0x8480
0101 #define RT711_PRIV_INDEX_R_H                0x9d00
0102 #define RT711_PRIV_INDEX_R_L                0xad80
0103 #define RT711_PRIV_DATA_R_H             0x9c00
0104 #define RT711_PRIV_DATA_R_L             0xac80
0105 #define RT711_DAC_FORMAT_H              0x7203
0106 #define RT711_DAC_FORMAT_L              0x8283
0107 #define RT711_ADC1_FORMAT_H             0x7209
0108 #define RT711_ADC1_FORMAT_L             0x8289
0109 #define RT711_ADC2_FORMAT_H             0x7208
0110 #define RT711_ADC2_FORMAT_L             0x8288
0111 
0112 #define RT711_SET_AUDIO_POWER_STATE\
0113     (RT711_VERB_SET_POWER_STATE | RT711_AUDIO_FUNCTION_GROUP)
0114 #define RT711_GET_AUDIO_POWER_STATE\
0115         (RT711_VERB_GET_POWER_STATE | RT711_AUDIO_FUNCTION_GROUP)
0116 #define RT711_SET_PIN_DMIC1\
0117     (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_DMIC1)
0118 #define RT711_SET_PIN_DMIC2\
0119     (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_DMIC2)
0120 #define RT711_SET_PIN_HP\
0121     (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_HP_OUT)
0122 #define RT711_SET_PIN_MIC2\
0123     (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_MIC2)
0124 #define RT711_SET_PIN_LINE1\
0125     (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_LINE1)
0126 #define RT711_SET_PIN_LINE2\
0127     (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_LINE2)
0128 #define RT711_SET_MIC2_UNSOLICITED_ENABLE\
0129     (RT711_VERB_SET_UNSOLICITED_ENABLE | RT711_MIC2)
0130 #define RT711_SET_HP_UNSOLICITED_ENABLE\
0131     (RT711_VERB_SET_UNSOLICITED_ENABLE | RT711_HP_OUT)
0132 #define RT711_SET_INLINE_UNSOLICITED_ENABLE\
0133     (RT711_VERB_SET_UNSOLICITED_ENABLE | RT711_INLINE_CMD)
0134 #define RT711_SET_STREAMID_DAC2\
0135     (RT711_VERB_SET_CHANNEL_STREAMID | RT711_DAC_OUT2)
0136 #define RT711_SET_STREAMID_ADC1\
0137     (RT711_VERB_SET_CHANNEL_STREAMID | RT711_ADC_IN1)
0138 #define RT711_SET_STREAMID_ADC2\
0139     (RT711_VERB_SET_CHANNEL_STREAMID | RT711_ADC_IN2)
0140 #define RT711_GET_STREAMID_DAC2\
0141     (RT711_VERB_GET_CHANNEL_STREAMID | RT711_DAC_OUT2)
0142 #define RT711_GET_STREAMID_ADC1\
0143     (RT711_VERB_GET_CHANNEL_STREAMID | RT711_ADC_IN1)
0144 #define RT711_GET_STREAMID_ADC2\
0145     (RT711_VERB_GET_CHANNEL_STREAMID | RT711_ADC_IN2)
0146 #define RT711_SET_GAIN_DAC2_L\
0147     (RT711_SET_AMP_GAIN_MUTE_L | RT711_DAC_OUT2)
0148 #define RT711_SET_GAIN_DAC2_H\
0149     (RT711_SET_AMP_GAIN_MUTE_H | RT711_DAC_OUT2)
0150 #define RT711_SET_GAIN_ADC1_L\
0151     (RT711_SET_AMP_GAIN_MUTE_L | RT711_ADC_IN1)
0152 #define RT711_SET_GAIN_ADC1_H\
0153     (RT711_SET_AMP_GAIN_MUTE_H | RT711_ADC_IN1)
0154 #define RT711_SET_GAIN_ADC2_L\
0155     (RT711_SET_AMP_GAIN_MUTE_L | RT711_ADC_IN2)
0156 #define RT711_SET_GAIN_ADC2_H\
0157     (RT711_SET_AMP_GAIN_MUTE_H | RT711_ADC_IN2)
0158 #define RT711_SET_GAIN_AMIC_L\
0159     (RT711_SET_AMP_GAIN_MUTE_L | RT711_MIC2)
0160 #define RT711_SET_GAIN_AMIC_H\
0161     (RT711_SET_AMP_GAIN_MUTE_H | RT711_MIC2)
0162 #define RT711_SET_GAIN_DMIC1_L\
0163     (RT711_SET_AMP_GAIN_MUTE_L | RT711_DMIC1)
0164 #define RT711_SET_GAIN_DMIC1_H\
0165     (RT711_SET_AMP_GAIN_MUTE_H | RT711_DMIC1)
0166 #define RT711_SET_GAIN_DMIC2_L\
0167     (RT711_SET_AMP_GAIN_MUTE_L | RT711_DMIC2)
0168 #define RT711_SET_GAIN_DMIC2_H\
0169     (RT711_SET_AMP_GAIN_MUTE_H | RT711_DMIC2)
0170 #define RT711_SET_GAIN_HP_L\
0171     (RT711_SET_AMP_GAIN_MUTE_L | RT711_HP_OUT)
0172 #define RT711_SET_GAIN_HP_H\
0173     (RT711_SET_AMP_GAIN_MUTE_H | RT711_HP_OUT)
0174 
0175 /* DAC DC offset calibration control-1 (0x00)(NID:20h) */
0176 #define RT711_DAC_DC_CALI_TRIGGER (0x1 << 15)
0177 
0178 /* jack detect control 1 (0x08)(NID:20h) */
0179 #define RT711_JD2_DIGITAL_JD_MODE_SEL (0x1 << 1)
0180 #define RT711_JD2_1_JD_MODE (0x0 << 1)
0181 #define RT711_JD2_2_JD_MODE (0x1 << 1)
0182 
0183 /* jack detect control 2 (0x09)(NID:20h) */
0184 #define RT711_JD2_2PORT_200K_DECODE_HP (0x1 << 13)
0185 #define RT711_JD2_2PORT_100K_DECODE (0x1 << 12)
0186 #define RT711_JD2_2PORT_100K_DECODE_HP (0x0 << 12)
0187 #define RT711_HP_JD_SEL_JD1 (0x0 << 1)
0188 #define RT711_HP_JD_SEL_JD2 (0x1 << 1)
0189 #define RT711_JD2_1PORT_TYPE_DECODE (0x3 << 10)
0190 #define RT711_JD2_1PORT_JD_LINE2 (0x0 << 10)
0191 #define RT711_JD2_1PORT_JD_HP (0x1 << 10)
0192 #define RT711_JD2_1PORT_JD_LINE1 (0x2 << 10)
0193 #define RT711_JD1_2PORT_TYPE_100K_DECODE (0x1 << 0)
0194 #define RT711_JD1_2PORT_JD_RESERVED (0x0 << 0)
0195 #define RT711_JD1_2PORT_JD_LINE1 (0x1 << 0)
0196 
0197 /* jack detect control 4 (0x0b)(NID:20h) */
0198 #define RT711_JD2_PAD_PULL_UP_MASK (0x1 << 3)
0199 #define RT711_JD2_PAD_NOT_PULL_UP (0x0 << 3)
0200 #define RT711_JD2_PAD_PULL_UP (0x1 << 3)
0201 #define RT711_JD2_MODE_SEL_MASK (0x3 << 0)
0202 #define RT711_JD2_MODE0_2PORT (0x0 << 0)
0203 #define RT711_JD2_MODE1_3P3V_1PORT (0x1 << 0)
0204 #define RT711_JD2_MODE2_1P8V_1PORT (0x2 << 0)
0205 
0206 /* CC DET1 (0x11)(NID:20h) */
0207 #define RT711_HP_JD_FINAL_RESULT_CTL_JD12 (0x1 << 10)
0208 #define RT711_HP_JD_FINAL_RESULT_CTL_CCDET (0x0 << 10)
0209 
0210 /* Parameter & Verb control (0x1a)(NID:20h) */
0211 #define RT711_HIDDEN_REG_SW_RESET (0x1 << 14)
0212 
0213 /* combo jack auto switch control 2 (0x46)(NID:20h) */
0214 #define RT711_COMBOJACK_AUTO_DET_STATUS         (0x1 << 11)
0215 #define RT711_COMBOJACK_AUTO_DET_TRS            (0x1 << 10)
0216 #define RT711_COMBOJACK_AUTO_DET_CTIA           (0x1 << 9)
0217 #define RT711_COMBOJACK_AUTO_DET_OMTP           (0x1 << 8)
0218 
0219 /* FSM control (0x6f)(NID:20h) */
0220 #define RT711_CALI_CTL          (0x0 << 0)
0221 #define RT711_COMBOJACK_CTL         (0x1 << 0)
0222 #define RT711_IMS_CTL           (0x2 << 0)
0223 #define RT711_DEPOP_CTL         (0x3 << 0)
0224 
0225 /* Impedance Sense Digital Control 1 (0x00)(NID:5bh) */
0226 #define RT711_TRIGGER_IMS           (0x1 << 15)
0227 #define RT711_IMS_EN            (0x1 << 6)
0228 
0229 #define RT711_EAPD_HIGH                 0x2
0230 #define RT711_EAPD_LOW                  0x0
0231 #define RT711_MUTE_SFT                  7
0232 /* set input/output mapping to payload[14][15] separately */
0233 #define RT711_DIR_IN_SFT                6
0234 #define RT711_DIR_OUT_SFT               7
0235 
0236 enum {
0237     RT711_AIF1,
0238     RT711_AIF2,
0239     RT711_AIFS,
0240 };
0241 
0242 enum rt711_jd_src {
0243     RT711_JD_NULL,
0244     RT711_JD1,
0245     RT711_JD2,
0246     RT711_JD2_100K,
0247     RT711_JD2_1P8V_1PORT
0248 };
0249 
0250 int rt711_io_init(struct device *dev, struct sdw_slave *slave);
0251 int rt711_init(struct device *dev, struct regmap *sdw_regmap,
0252            struct regmap *regmap, struct sdw_slave *slave);
0253 
0254 int rt711_jack_detect(struct rt711_priv *rt711, bool *hp, bool *mic);
0255 int rt711_clock_config(struct device *dev);
0256 #endif /* __RT711_H__ */