162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * rt700.h -- RT700 ALSA SoC audio driver header
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright(c) 2019 Realtek Semiconductor Corp.
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef __RT700_H__
962306a36Sopenharmony_ci#define __RT700_H__
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ciextern const struct dev_pm_ops rt700_runtime_pm;
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cistruct  rt700_priv {
1462306a36Sopenharmony_ci	struct snd_soc_component *component;
1562306a36Sopenharmony_ci	struct regmap *regmap;
1662306a36Sopenharmony_ci	struct regmap *sdw_regmap;
1762306a36Sopenharmony_ci	struct sdw_slave *slave;
1862306a36Sopenharmony_ci	struct sdw_bus_params params;
1962306a36Sopenharmony_ci	bool hw_init;
2062306a36Sopenharmony_ci	bool first_hw_init;
2162306a36Sopenharmony_ci	struct snd_soc_jack *hs_jack;
2262306a36Sopenharmony_ci	struct delayed_work jack_detect_work;
2362306a36Sopenharmony_ci	struct delayed_work jack_btn_check_work;
2462306a36Sopenharmony_ci	int jack_type;
2562306a36Sopenharmony_ci	struct mutex disable_irq_lock; /* imp-def irq lock protection */
2662306a36Sopenharmony_ci	bool disable_irq;
2762306a36Sopenharmony_ci};
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci/* NID */
3062306a36Sopenharmony_ci#define RT700_AUDIO_FUNCTION_GROUP			0x01
3162306a36Sopenharmony_ci#define RT700_DAC_OUT1					0x02
3262306a36Sopenharmony_ci#define RT700_DAC_OUT2					0x03
3362306a36Sopenharmony_ci#define RT700_ADC_IN1					0x09
3462306a36Sopenharmony_ci#define RT700_ADC_IN2					0x08
3562306a36Sopenharmony_ci#define RT700_DMIC1					0x12
3662306a36Sopenharmony_ci#define RT700_DMIC2					0x13
3762306a36Sopenharmony_ci#define RT700_SPK_OUT					0x14
3862306a36Sopenharmony_ci#define RT700_MIC2					0x19
3962306a36Sopenharmony_ci#define RT700_LINE1					0x1a
4062306a36Sopenharmony_ci#define RT700_LINE2					0x1b
4162306a36Sopenharmony_ci#define RT700_BEEP					0x1d
4262306a36Sopenharmony_ci#define RT700_SPDIF					0x1e
4362306a36Sopenharmony_ci#define RT700_VENDOR_REGISTERS				0x20
4462306a36Sopenharmony_ci#define RT700_HP_OUT					0x21
4562306a36Sopenharmony_ci#define RT700_MIXER_IN1					0x22
4662306a36Sopenharmony_ci#define RT700_MIXER_IN2					0x23
4762306a36Sopenharmony_ci#define RT700_INLINE_CMD				0x55
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci/* Index (NID:20h) */
5062306a36Sopenharmony_ci#define RT700_DAC_DC_CALI_CTL1				0x00
5162306a36Sopenharmony_ci#define RT700_PARA_VERB_CTL				0x1a
5262306a36Sopenharmony_ci#define RT700_COMBO_JACK_AUTO_CTL1				0x45
5362306a36Sopenharmony_ci#define RT700_COMBO_JACK_AUTO_CTL2				0x46
5462306a36Sopenharmony_ci#define RT700_INLINE_CMD_CTL				0x48
5562306a36Sopenharmony_ci#define RT700_DIGITAL_MISC_CTRL4			0x4a
5662306a36Sopenharmony_ci#define RT700_VREFOUT_CTL				0x6b
5762306a36Sopenharmony_ci#define RT700_FSM_CTL				0x6f
5862306a36Sopenharmony_ci#define RT700_IRQ_FLAG_TABLE1				0x80
5962306a36Sopenharmony_ci#define RT700_IRQ_FLAG_TABLE2				0x81
6062306a36Sopenharmony_ci#define RT700_IRQ_FLAG_TABLE3				0x82
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci/* Verb */
6362306a36Sopenharmony_ci#define RT700_VERB_SET_CONNECT_SEL			0x3100
6462306a36Sopenharmony_ci#define RT700_VERB_SET_EAPD_BTLENABLE			0x3c00
6562306a36Sopenharmony_ci#define RT700_VERB_GET_CONNECT_SEL			0xb100
6662306a36Sopenharmony_ci#define RT700_VERB_SET_POWER_STATE			0x3500
6762306a36Sopenharmony_ci#define RT700_VERB_SET_CHANNEL_STREAMID			0x3600
6862306a36Sopenharmony_ci#define RT700_VERB_SET_PIN_WIDGET_CONTROL		0x3700
6962306a36Sopenharmony_ci#define RT700_VERB_SET_UNSOLICITED_ENABLE		0x3800
7062306a36Sopenharmony_ci#define RT700_SET_AMP_GAIN_MUTE_H			0x7300
7162306a36Sopenharmony_ci#define RT700_SET_AMP_GAIN_MUTE_L			0x8380
7262306a36Sopenharmony_ci#define RT700_VERB_GET_PIN_SENSE			0xb900
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define RT700_READ_HDA_3				0x2012
7562306a36Sopenharmony_ci#define RT700_READ_HDA_2				0x2013
7662306a36Sopenharmony_ci#define RT700_READ_HDA_1				0x2014
7762306a36Sopenharmony_ci#define RT700_READ_HDA_0				0x2015
7862306a36Sopenharmony_ci#define RT700_PRIV_INDEX_W_H				0x7520
7962306a36Sopenharmony_ci#define RT700_PRIV_INDEX_W_L				0x85a0
8062306a36Sopenharmony_ci#define RT700_PRIV_DATA_W_H				0x7420
8162306a36Sopenharmony_ci#define RT700_PRIV_DATA_W_L				0x84a0
8262306a36Sopenharmony_ci#define RT700_PRIV_INDEX_R_H				0x9d20
8362306a36Sopenharmony_ci#define RT700_PRIV_INDEX_R_L				0xada0
8462306a36Sopenharmony_ci#define RT700_PRIV_DATA_R_H				0x9c20
8562306a36Sopenharmony_ci#define RT700_PRIV_DATA_R_L				0xaca0
8662306a36Sopenharmony_ci#define RT700_DAC_FORMAT_H				0x7203
8762306a36Sopenharmony_ci#define RT700_DAC_FORMAT_L				0x8283
8862306a36Sopenharmony_ci#define RT700_ADC_FORMAT_H				0x7209
8962306a36Sopenharmony_ci#define RT700_ADC_FORMAT_L				0x8289
9062306a36Sopenharmony_ci#define RT700_SET_AUDIO_POWER_STATE\
9162306a36Sopenharmony_ci	(RT700_VERB_SET_POWER_STATE | RT700_AUDIO_FUNCTION_GROUP)
9262306a36Sopenharmony_ci#define RT700_SET_PIN_DMIC1\
9362306a36Sopenharmony_ci	(RT700_VERB_SET_PIN_WIDGET_CONTROL | RT700_DMIC1)
9462306a36Sopenharmony_ci#define RT700_SET_PIN_DMIC2\
9562306a36Sopenharmony_ci	(RT700_VERB_SET_PIN_WIDGET_CONTROL | RT700_DMIC2)
9662306a36Sopenharmony_ci#define RT700_SET_PIN_SPK\
9762306a36Sopenharmony_ci	(RT700_VERB_SET_PIN_WIDGET_CONTROL | RT700_SPK_OUT)
9862306a36Sopenharmony_ci#define RT700_SET_PIN_HP\
9962306a36Sopenharmony_ci	(RT700_VERB_SET_PIN_WIDGET_CONTROL | RT700_HP_OUT)
10062306a36Sopenharmony_ci#define RT700_SET_PIN_MIC2\
10162306a36Sopenharmony_ci	(RT700_VERB_SET_PIN_WIDGET_CONTROL | RT700_MIC2)
10262306a36Sopenharmony_ci#define RT700_SET_PIN_LINE1\
10362306a36Sopenharmony_ci	(RT700_VERB_SET_PIN_WIDGET_CONTROL | RT700_LINE1)
10462306a36Sopenharmony_ci#define RT700_SET_PIN_LINE2\
10562306a36Sopenharmony_ci	(RT700_VERB_SET_PIN_WIDGET_CONTROL | RT700_LINE2)
10662306a36Sopenharmony_ci#define RT700_SET_MIC2_UNSOLICITED_ENABLE\
10762306a36Sopenharmony_ci	(RT700_VERB_SET_UNSOLICITED_ENABLE | RT700_MIC2)
10862306a36Sopenharmony_ci#define RT700_SET_HP_UNSOLICITED_ENABLE\
10962306a36Sopenharmony_ci	(RT700_VERB_SET_UNSOLICITED_ENABLE | RT700_HP_OUT)
11062306a36Sopenharmony_ci#define RT700_SET_INLINE_UNSOLICITED_ENABLE\
11162306a36Sopenharmony_ci	(RT700_VERB_SET_UNSOLICITED_ENABLE | RT700_INLINE_CMD)
11262306a36Sopenharmony_ci#define RT700_SET_STREAMID_DAC1\
11362306a36Sopenharmony_ci	(RT700_VERB_SET_CHANNEL_STREAMID | RT700_DAC_OUT1)
11462306a36Sopenharmony_ci#define RT700_SET_STREAMID_DAC2\
11562306a36Sopenharmony_ci	(RT700_VERB_SET_CHANNEL_STREAMID | RT700_DAC_OUT2)
11662306a36Sopenharmony_ci#define RT700_SET_STREAMID_ADC1\
11762306a36Sopenharmony_ci	(RT700_VERB_SET_CHANNEL_STREAMID | RT700_ADC_IN1)
11862306a36Sopenharmony_ci#define RT700_SET_STREAMID_ADC2\
11962306a36Sopenharmony_ci	(RT700_VERB_SET_CHANNEL_STREAMID | RT700_ADC_IN2)
12062306a36Sopenharmony_ci#define RT700_SET_GAIN_DAC1_L\
12162306a36Sopenharmony_ci	(RT700_SET_AMP_GAIN_MUTE_L | RT700_DAC_OUT1)
12262306a36Sopenharmony_ci#define RT700_SET_GAIN_DAC1_H\
12362306a36Sopenharmony_ci	(RT700_SET_AMP_GAIN_MUTE_H | RT700_DAC_OUT1)
12462306a36Sopenharmony_ci#define RT700_SET_GAIN_ADC1_L\
12562306a36Sopenharmony_ci	(RT700_SET_AMP_GAIN_MUTE_L | RT700_ADC_IN1)
12662306a36Sopenharmony_ci#define RT700_SET_GAIN_ADC1_H\
12762306a36Sopenharmony_ci	(RT700_SET_AMP_GAIN_MUTE_H | RT700_ADC_IN1)
12862306a36Sopenharmony_ci#define RT700_SET_GAIN_ADC2_L\
12962306a36Sopenharmony_ci	(RT700_SET_AMP_GAIN_MUTE_L | RT700_ADC_IN2)
13062306a36Sopenharmony_ci#define RT700_SET_GAIN_ADC2_H\
13162306a36Sopenharmony_ci	(RT700_SET_AMP_GAIN_MUTE_H | RT700_ADC_IN2)
13262306a36Sopenharmony_ci#define RT700_SET_GAIN_AMIC_L\
13362306a36Sopenharmony_ci	(RT700_SET_AMP_GAIN_MUTE_L | RT700_MIC2)
13462306a36Sopenharmony_ci#define RT700_SET_GAIN_AMIC_H\
13562306a36Sopenharmony_ci	(RT700_SET_AMP_GAIN_MUTE_H | RT700_MIC2)
13662306a36Sopenharmony_ci#define RT700_SET_GAIN_HP_L\
13762306a36Sopenharmony_ci	(RT700_SET_AMP_GAIN_MUTE_L | RT700_HP_OUT)
13862306a36Sopenharmony_ci#define RT700_SET_GAIN_HP_H\
13962306a36Sopenharmony_ci	(RT700_SET_AMP_GAIN_MUTE_H | RT700_HP_OUT)
14062306a36Sopenharmony_ci#define RT700_SET_GAIN_SPK_L\
14162306a36Sopenharmony_ci	(RT700_SET_AMP_GAIN_MUTE_L | RT700_SPK_OUT)
14262306a36Sopenharmony_ci#define RT700_SET_GAIN_SPK_H\
14362306a36Sopenharmony_ci	(RT700_SET_AMP_GAIN_MUTE_H | RT700_SPK_OUT)
14462306a36Sopenharmony_ci#define RT700_SET_EAPD_SPK\
14562306a36Sopenharmony_ci	(RT700_VERB_SET_EAPD_BTLENABLE | RT700_SPK_OUT)
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ci/* combo jack auto switch control 2 (0x46)(NID:20h) */
14862306a36Sopenharmony_ci#define RT700_COMBOJACK_AUTO_DET_STATUS			(0x1 << 11)
14962306a36Sopenharmony_ci#define RT700_COMBOJACK_AUTO_DET_TRS			(0x1 << 10)
15062306a36Sopenharmony_ci#define RT700_COMBOJACK_AUTO_DET_CTIA			(0x1 << 9)
15162306a36Sopenharmony_ci#define RT700_COMBOJACK_AUTO_DET_OMTP			(0x1 << 8)
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci#define RT700_EAPD_HIGH					0x2
15462306a36Sopenharmony_ci#define RT700_EAPD_LOW					0x0
15562306a36Sopenharmony_ci#define RT700_MUTE_SFT					7
15662306a36Sopenharmony_ci#define RT700_DIR_IN_SFT				6
15762306a36Sopenharmony_ci#define RT700_DIR_OUT_SFT				7
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_cienum {
16062306a36Sopenharmony_ci	RT700_AIF1,
16162306a36Sopenharmony_ci	RT700_AIF2,
16262306a36Sopenharmony_ci	RT700_AIFS,
16362306a36Sopenharmony_ci};
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ciint rt700_io_init(struct device *dev, struct sdw_slave *slave);
16662306a36Sopenharmony_ciint rt700_init(struct device *dev, struct regmap *sdw_regmap,
16762306a36Sopenharmony_ci	       struct regmap *regmap, struct sdw_slave *slave);
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ciint rt700_jack_detect(struct rt700_priv *rt700, bool *hp, bool *mic);
17062306a36Sopenharmony_ciint rt700_clock_config(struct device *dev);
17162306a36Sopenharmony_ci#endif /* __RT700_H__ */
172