252 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/*3 * rt711.h -- RT711 ALSA SoC audio driver header4 *5 * Copyright(c) 2019 Realtek Semiconductor Corp.6 */7 8#ifndef __RT711_H__9#define __RT711_H__10 11extern const struct dev_pm_ops rt711_runtime_pm;12 13struct rt711_priv {14 struct regmap *regmap;15 struct regmap *sdw_regmap;16 struct snd_soc_component *component;17 struct sdw_slave *slave;18 struct sdw_bus_params params;19 bool hw_init;20 bool first_hw_init;21 struct snd_soc_jack *hs_jack;22 struct delayed_work jack_detect_work;23 struct delayed_work jack_btn_check_work;24 struct work_struct calibration_work;25 struct mutex calibrate_mutex; /* for headset calibration */26 int jack_type, jd_src;27 struct mutex disable_irq_lock; /* imp-def irq lock protection */28 bool disable_irq;29};30 31/* NID */32#define RT711_AUDIO_FUNCTION_GROUP 0x0133#define RT711_DAC_OUT2 0x0334#define RT711_ADC_IN1 0x0935#define RT711_ADC_IN2 0x0836#define RT711_DMIC1 0x1237#define RT711_DMIC2 0x1338#define RT711_MIC2 0x1939#define RT711_LINE1 0x1a40#define RT711_LINE2 0x1b41#define RT711_BEEP 0x1d42#define RT711_VENDOR_REG 0x2043#define RT711_HP_OUT 0x2144#define RT711_MIXER_IN1 0x2245#define RT711_MIXER_IN2 0x2346#define RT711_INLINE_CMD 0x5547#define RT711_VENDOR_CALI 0x5848#define RT711_VENDOR_IMS_DRE 0x5b49 50/* Index (NID:20h) */51#define RT711_DAC_DC_CALI_CTL1 0x0052#define RT711_JD_CTL1 0x0853#define RT711_JD_CTL2 0x0954#define RT711_JD_CTL4 0x0b55#define RT711_CC_DET1 0x1156#define RT711_PARA_VERB_CTL 0x1a57#define RT711_COMBO_JACK_AUTO_CTL1 0x4558#define RT711_COMBO_JACK_AUTO_CTL2 0x4659#define RT711_INLINE_CMD_CTL 0x4860#define RT711_DIGITAL_MISC_CTRL4 0x4a61#define RT711_VREFOUT_CTL 0x6b62#define RT711_FSM_CTL 0x6f63#define RT711_IRQ_FLAG_TABLE1 0x8064#define RT711_IRQ_FLAG_TABLE2 0x8165#define RT711_IRQ_FLAG_TABLE3 0x8266#define RT711_TX_RX_MUX_CTL 0x9167 68/* Index (NID:5bh) */69#define RT711_IMS_DIGITAL_CTL1 0x0070#define RT711_HP_IMS_RESULT_L 0x2071#define RT711_HP_IMS_RESULT_R 0x2172 73/* Verb */74#define RT711_VERB_SET_CONNECT_SEL 0x310075#define RT711_VERB_SET_EAPD_BTLENABLE 0x3c0076#define RT711_VERB_GET_CONNECT_SEL 0xb10077#define RT711_VERB_SET_POWER_STATE 0x350078#define RT711_VERB_SET_CHANNEL_STREAMID 0x360079#define RT711_VERB_SET_PIN_WIDGET_CONTROL 0x370080#define RT711_VERB_SET_UNSOLICITED_ENABLE 0x380081#define RT711_SET_AMP_GAIN_MUTE_H 0x730082#define RT711_SET_AMP_GAIN_MUTE_L 0x838083#define RT711_VERB_GET_POWER_STATE 0xb50084#define RT711_VERB_GET_CHANNEL_STREAMID 0xb60085#define RT711_VERB_GET_PIN_SENSE 0xb90086#define RT711_FUNC_RESET 0xff0187 88#define RT711_READ_HDA_3 0x201289#define RT711_READ_HDA_2 0x201390#define RT711_READ_HDA_1 0x201491#define RT711_READ_HDA_0 0x201592#define RT711_PRIV_INDEX_W_H 0x750093#define RT711_PRIV_INDEX_W_L 0x858094#define RT711_PRIV_DATA_W_H 0x740095#define RT711_PRIV_DATA_W_L 0x848096#define RT711_PRIV_INDEX_R_H 0x9d0097#define RT711_PRIV_INDEX_R_L 0xad8098#define RT711_PRIV_DATA_R_H 0x9c0099#define RT711_PRIV_DATA_R_L 0xac80100#define RT711_DAC_FORMAT_H 0x7203101#define RT711_DAC_FORMAT_L 0x8283102#define RT711_ADC1_FORMAT_H 0x7209103#define RT711_ADC1_FORMAT_L 0x8289104#define RT711_ADC2_FORMAT_H 0x7208105#define RT711_ADC2_FORMAT_L 0x8288106 107#define RT711_SET_AUDIO_POWER_STATE\108 (RT711_VERB_SET_POWER_STATE | RT711_AUDIO_FUNCTION_GROUP)109#define RT711_GET_AUDIO_POWER_STATE\110 (RT711_VERB_GET_POWER_STATE | RT711_AUDIO_FUNCTION_GROUP)111#define RT711_SET_PIN_DMIC1\112 (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_DMIC1)113#define RT711_SET_PIN_DMIC2\114 (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_DMIC2)115#define RT711_SET_PIN_HP\116 (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_HP_OUT)117#define RT711_SET_PIN_MIC2\118 (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_MIC2)119#define RT711_SET_PIN_LINE1\120 (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_LINE1)121#define RT711_SET_PIN_LINE2\122 (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_LINE2)123#define RT711_SET_MIC2_UNSOLICITED_ENABLE\124 (RT711_VERB_SET_UNSOLICITED_ENABLE | RT711_MIC2)125#define RT711_SET_HP_UNSOLICITED_ENABLE\126 (RT711_VERB_SET_UNSOLICITED_ENABLE | RT711_HP_OUT)127#define RT711_SET_INLINE_UNSOLICITED_ENABLE\128 (RT711_VERB_SET_UNSOLICITED_ENABLE | RT711_INLINE_CMD)129#define RT711_SET_STREAMID_DAC2\130 (RT711_VERB_SET_CHANNEL_STREAMID | RT711_DAC_OUT2)131#define RT711_SET_STREAMID_ADC1\132 (RT711_VERB_SET_CHANNEL_STREAMID | RT711_ADC_IN1)133#define RT711_SET_STREAMID_ADC2\134 (RT711_VERB_SET_CHANNEL_STREAMID | RT711_ADC_IN2)135#define RT711_GET_STREAMID_DAC2\136 (RT711_VERB_GET_CHANNEL_STREAMID | RT711_DAC_OUT2)137#define RT711_GET_STREAMID_ADC1\138 (RT711_VERB_GET_CHANNEL_STREAMID | RT711_ADC_IN1)139#define RT711_GET_STREAMID_ADC2\140 (RT711_VERB_GET_CHANNEL_STREAMID | RT711_ADC_IN2)141#define RT711_SET_GAIN_DAC2_L\142 (RT711_SET_AMP_GAIN_MUTE_L | RT711_DAC_OUT2)143#define RT711_SET_GAIN_DAC2_H\144 (RT711_SET_AMP_GAIN_MUTE_H | RT711_DAC_OUT2)145#define RT711_SET_GAIN_ADC1_L\146 (RT711_SET_AMP_GAIN_MUTE_L | RT711_ADC_IN1)147#define RT711_SET_GAIN_ADC1_H\148 (RT711_SET_AMP_GAIN_MUTE_H | RT711_ADC_IN1)149#define RT711_SET_GAIN_ADC2_L\150 (RT711_SET_AMP_GAIN_MUTE_L | RT711_ADC_IN2)151#define RT711_SET_GAIN_ADC2_H\152 (RT711_SET_AMP_GAIN_MUTE_H | RT711_ADC_IN2)153#define RT711_SET_GAIN_AMIC_L\154 (RT711_SET_AMP_GAIN_MUTE_L | RT711_MIC2)155#define RT711_SET_GAIN_AMIC_H\156 (RT711_SET_AMP_GAIN_MUTE_H | RT711_MIC2)157#define RT711_SET_GAIN_DMIC1_L\158 (RT711_SET_AMP_GAIN_MUTE_L | RT711_DMIC1)159#define RT711_SET_GAIN_DMIC1_H\160 (RT711_SET_AMP_GAIN_MUTE_H | RT711_DMIC1)161#define RT711_SET_GAIN_DMIC2_L\162 (RT711_SET_AMP_GAIN_MUTE_L | RT711_DMIC2)163#define RT711_SET_GAIN_DMIC2_H\164 (RT711_SET_AMP_GAIN_MUTE_H | RT711_DMIC2)165#define RT711_SET_GAIN_HP_L\166 (RT711_SET_AMP_GAIN_MUTE_L | RT711_HP_OUT)167#define RT711_SET_GAIN_HP_H\168 (RT711_SET_AMP_GAIN_MUTE_H | RT711_HP_OUT)169 170/* DAC DC offset calibration control-1 (0x00)(NID:20h) */171#define RT711_DAC_DC_CALI_TRIGGER (0x1 << 15)172 173/* jack detect control 1 (0x08)(NID:20h) */174#define RT711_JD2_DIGITAL_JD_MODE_SEL (0x1 << 1)175#define RT711_JD2_1_JD_MODE (0x0 << 1)176#define RT711_JD2_2_JD_MODE (0x1 << 1)177 178/* jack detect control 2 (0x09)(NID:20h) */179#define RT711_JD2_2PORT_200K_DECODE_HP (0x1 << 13)180#define RT711_JD2_2PORT_100K_DECODE (0x1 << 12)181#define RT711_JD2_2PORT_100K_DECODE_HP (0x0 << 12)182#define RT711_HP_JD_SEL_JD1 (0x0 << 1)183#define RT711_HP_JD_SEL_JD2 (0x1 << 1)184#define RT711_JD2_1PORT_TYPE_DECODE (0x3 << 10)185#define RT711_JD2_1PORT_JD_LINE2 (0x0 << 10)186#define RT711_JD2_1PORT_JD_HP (0x1 << 10)187#define RT711_JD2_1PORT_JD_LINE1 (0x2 << 10)188#define RT711_JD1_2PORT_TYPE_100K_DECODE (0x1 << 0)189#define RT711_JD1_2PORT_JD_RESERVED (0x0 << 0)190#define RT711_JD1_2PORT_JD_LINE1 (0x1 << 0)191 192/* jack detect control 4 (0x0b)(NID:20h) */193#define RT711_JD2_PAD_PULL_UP_MASK (0x1 << 3)194#define RT711_JD2_PAD_NOT_PULL_UP (0x0 << 3)195#define RT711_JD2_PAD_PULL_UP (0x1 << 3)196#define RT711_JD2_MODE_SEL_MASK (0x3 << 0)197#define RT711_JD2_MODE0_2PORT (0x0 << 0)198#define RT711_JD2_MODE1_3P3V_1PORT (0x1 << 0)199#define RT711_JD2_MODE2_1P8V_1PORT (0x2 << 0)200 201/* CC DET1 (0x11)(NID:20h) */202#define RT711_HP_JD_FINAL_RESULT_CTL_JD12 (0x1 << 10)203#define RT711_HP_JD_FINAL_RESULT_CTL_CCDET (0x0 << 10)204 205/* Parameter & Verb control (0x1a)(NID:20h) */206#define RT711_HIDDEN_REG_SW_RESET (0x1 << 14)207 208/* combo jack auto switch control 2 (0x46)(NID:20h) */209#define RT711_COMBOJACK_AUTO_DET_STATUS (0x1 << 11)210#define RT711_COMBOJACK_AUTO_DET_TRS (0x1 << 10)211#define RT711_COMBOJACK_AUTO_DET_CTIA (0x1 << 9)212#define RT711_COMBOJACK_AUTO_DET_OMTP (0x1 << 8)213 214/* FSM control (0x6f)(NID:20h) */215#define RT711_CALI_CTL (0x0 << 0)216#define RT711_COMBOJACK_CTL (0x1 << 0)217#define RT711_IMS_CTL (0x2 << 0)218#define RT711_DEPOP_CTL (0x3 << 0)219 220/* Impedance Sense Digital Control 1 (0x00)(NID:5bh) */221#define RT711_TRIGGER_IMS (0x1 << 15)222#define RT711_IMS_EN (0x1 << 6)223 224#define RT711_EAPD_HIGH 0x2225#define RT711_EAPD_LOW 0x0226#define RT711_MUTE_SFT 7227/* set input/output mapping to payload[14][15] separately */228#define RT711_DIR_IN_SFT 6229#define RT711_DIR_OUT_SFT 7230 231enum {232 RT711_AIF1,233 RT711_AIF2,234 RT711_AIFS,235};236 237enum rt711_jd_src {238 RT711_JD_NULL,239 RT711_JD1,240 RT711_JD2,241 RT711_JD2_100K,242 RT711_JD2_1P8V_1PORT243};244 245int rt711_io_init(struct device *dev, struct sdw_slave *slave);246int rt711_init(struct device *dev, struct regmap *sdw_regmap,247 struct regmap *regmap, struct sdw_slave *slave);248 249int rt711_jack_detect(struct rt711_priv *rt711, bool *hp, bool *mic);250int rt711_clock_config(struct device *dev);251#endif /* __RT711_H__ */252