18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * rt274.h  --  RT274 ALSA SoC audio driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright 2016 Realtek Microelectronics
68c2ecf20Sopenharmony_ci * Author: Bard Liao <bardliao@realtek.com>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef __RT274_H__
108c2ecf20Sopenharmony_ci#define __RT274_H__
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define VERB_CMD(V, N, D) ((N << 20) | (V << 8) | D)
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#define RT274_AUDIO_FUNCTION_GROUP			0x01
158c2ecf20Sopenharmony_ci#define RT274_DAC_OUT0					0x02
168c2ecf20Sopenharmony_ci#define RT274_DAC_OUT1					0x03
178c2ecf20Sopenharmony_ci#define RT274_ADC_IN2					0x08
188c2ecf20Sopenharmony_ci#define RT274_ADC_IN1					0x09
198c2ecf20Sopenharmony_ci#define RT274_DIG_CVT					0x0a
208c2ecf20Sopenharmony_ci#define RT274_DMIC1					0x12
218c2ecf20Sopenharmony_ci#define RT274_DMIC2					0x13
228c2ecf20Sopenharmony_ci#define RT274_MIC					0x19
238c2ecf20Sopenharmony_ci#define RT274_LINE1					0x1a
248c2ecf20Sopenharmony_ci#define RT274_LINE2					0x1b
258c2ecf20Sopenharmony_ci#define RT274_LINE3					0x16
268c2ecf20Sopenharmony_ci#define RT274_SPDIF					0x1e
278c2ecf20Sopenharmony_ci#define RT274_VENDOR_REGISTERS				0x20
288c2ecf20Sopenharmony_ci#define RT274_HP_OUT					0x21
298c2ecf20Sopenharmony_ci#define RT274_MIXER_IN1					0x22
308c2ecf20Sopenharmony_ci#define RT274_MIXER_IN2					0x23
318c2ecf20Sopenharmony_ci#define RT274_INLINE_CMD				0x55
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define RT274_SET_PIN_SFT				6
348c2ecf20Sopenharmony_ci#define RT274_SET_PIN_ENABLE				0x40
358c2ecf20Sopenharmony_ci#define RT274_SET_PIN_DISABLE				0
368c2ecf20Sopenharmony_ci#define RT274_SET_EAPD_HIGH				0x2
378c2ecf20Sopenharmony_ci#define RT274_SET_EAPD_LOW				0
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define RT274_MUTE_SFT					7
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/* Verb commands */
428c2ecf20Sopenharmony_ci#define RT274_RESET\
438c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_CODEC_RESET, RT274_AUDIO_FUNCTION_GROUP, 0)
448c2ecf20Sopenharmony_ci#define RT274_GET_PARAM(NID, PARAM) VERB_CMD(AC_VERB_PARAMETERS, NID, PARAM)
458c2ecf20Sopenharmony_ci#define RT274_SET_POWER(NID) VERB_CMD(AC_VERB_SET_POWER_STATE, NID, 0)
468c2ecf20Sopenharmony_ci#define RT274_SET_AUDIO_POWER RT274_SET_POWER(RT274_AUDIO_FUNCTION_GROUP)
478c2ecf20Sopenharmony_ci#define RT274_SET_HPO_POWER RT274_SET_POWER(RT274_HP_OUT)
488c2ecf20Sopenharmony_ci#define RT274_SET_DMIC1_POWER RT274_SET_POWER(RT274_DMIC1)
498c2ecf20Sopenharmony_ci#define RT274_LOUT_MUX\
508c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT274_LINE3, 0)
518c2ecf20Sopenharmony_ci#define RT274_HPO_MUX\
528c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT274_HP_OUT, 0)
538c2ecf20Sopenharmony_ci#define RT274_ADC0_MUX\
548c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT274_MIXER_IN1, 0)
558c2ecf20Sopenharmony_ci#define RT274_ADC1_MUX\
568c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT274_MIXER_IN2, 0)
578c2ecf20Sopenharmony_ci#define RT274_SET_MIC\
588c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT274_MIC, 0)
598c2ecf20Sopenharmony_ci#define RT274_SET_PIN_LOUT3\
608c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT274_LINE3, 0)
618c2ecf20Sopenharmony_ci#define RT274_SET_PIN_HPO\
628c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT274_HP_OUT, 0)
638c2ecf20Sopenharmony_ci#define RT274_SET_PIN_DMIC1\
648c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT274_DMIC1, 0)
658c2ecf20Sopenharmony_ci#define RT274_SET_PIN_SPDIF\
668c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT274_SPDIF, 0)
678c2ecf20Sopenharmony_ci#define RT274_SET_PIN_DIG_CVT\
688c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_DIGI_CONVERT_1, RT274_DIG_CVT, 0)
698c2ecf20Sopenharmony_ci#define RT274_SET_AMP_GAIN_HPO\
708c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_HP_OUT, 0)
718c2ecf20Sopenharmony_ci#define RT274_SET_AMP_GAIN_ADC_IN1\
728c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_ADC_IN1, 0)
738c2ecf20Sopenharmony_ci#define RT274_SET_AMP_GAIN_ADC_IN2\
748c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_ADC_IN2, 0)
758c2ecf20Sopenharmony_ci#define RT274_GET_HP_SENSE\
768c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_GET_PIN_SENSE, RT274_HP_OUT, 0)
778c2ecf20Sopenharmony_ci#define RT274_GET_MIC_SENSE\
788c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_GET_PIN_SENSE, RT274_MIC, 0)
798c2ecf20Sopenharmony_ci#define RT274_SET_DMIC2_DEFAULT\
808c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, RT274_DMIC2, 0)
818c2ecf20Sopenharmony_ci#define RT274_SET_SPDIF_DEFAULT\
828c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, RT274_SPDIF, 0)
838c2ecf20Sopenharmony_ci#define RT274_DAC0L_GAIN\
848c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_DAC_OUT0, 0xa000)
858c2ecf20Sopenharmony_ci#define RT274_DAC0R_GAIN\
868c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_DAC_OUT0, 0x9000)
878c2ecf20Sopenharmony_ci#define RT274_DAC1L_GAIN\
888c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_DAC_OUT1, 0xa000)
898c2ecf20Sopenharmony_ci#define RT274_DAC1R_GAIN\
908c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_DAC_OUT1, 0x9000)
918c2ecf20Sopenharmony_ci#define RT274_ADCL_GAIN\
928c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_ADC_IN1, 0x6000)
938c2ecf20Sopenharmony_ci#define RT274_ADCR_GAIN\
948c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_ADC_IN1, 0x5000)
958c2ecf20Sopenharmony_ci#define RT274_MIC_GAIN\
968c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_MIC, 0x7000)
978c2ecf20Sopenharmony_ci#define RT274_LOUTL_GAIN\
988c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_LINE3, 0xa000)
998c2ecf20Sopenharmony_ci#define RT274_LOUTR_GAIN\
1008c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_LINE3, 0x9000)
1018c2ecf20Sopenharmony_ci#define RT274_HPOL_GAIN\
1028c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_HP_OUT, 0xa000)
1038c2ecf20Sopenharmony_ci#define RT274_HPOR_GAIN\
1048c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_HP_OUT, 0x9000)
1058c2ecf20Sopenharmony_ci#define RT274_DAC_FORMAT\
1068c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_STREAM_FORMAT, RT274_DAC_OUT0, 0)
1078c2ecf20Sopenharmony_ci#define RT274_ADC_FORMAT\
1088c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_STREAM_FORMAT, RT274_ADC_IN1, 0)
1098c2ecf20Sopenharmony_ci#define RT274_COEF_INDEX\
1108c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_COEF_INDEX, RT274_VENDOR_REGISTERS, 0)
1118c2ecf20Sopenharmony_ci#define RT274_PROC_COEF\
1128c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_PROC_COEF, RT274_VENDOR_REGISTERS, 0)
1138c2ecf20Sopenharmony_ci#define RT274_UNSOLICITED_INLINE_CMD\
1148c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_UNSOLICITED_ENABLE, RT274_INLINE_CMD, 0)
1158c2ecf20Sopenharmony_ci#define RT274_UNSOLICITED_HP_OUT\
1168c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_UNSOLICITED_ENABLE, RT274_HP_OUT, 0)
1178c2ecf20Sopenharmony_ci#define RT274_UNSOLICITED_MIC\
1188c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_UNSOLICITED_ENABLE, RT274_MIC, 0)
1198c2ecf20Sopenharmony_ci#define RT274_COEF58_INDEX\
1208c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_COEF_INDEX, 0x58, 0)
1218c2ecf20Sopenharmony_ci#define RT274_COEF58_COEF\
1228c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_PROC_COEF, 0x58, 0)
1238c2ecf20Sopenharmony_ci#define RT274_COEF5b_INDEX\
1248c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_COEF_INDEX, 0x5b, 0)
1258c2ecf20Sopenharmony_ci#define RT274_COEF5b_COEF\
1268c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_PROC_COEF, 0x5b, 0)
1278c2ecf20Sopenharmony_ci#define RT274_SET_STREAMID_DAC0\
1288c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_CHANNEL_STREAMID, RT274_DAC_OUT0, 0)
1298c2ecf20Sopenharmony_ci#define RT274_SET_STREAMID_DAC1\
1308c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_CHANNEL_STREAMID, RT274_DAC_OUT1, 0)
1318c2ecf20Sopenharmony_ci#define RT274_SET_STREAMID_ADC1\
1328c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_CHANNEL_STREAMID, RT274_ADC_IN1, 0)
1338c2ecf20Sopenharmony_ci#define RT274_SET_STREAMID_ADC2\
1348c2ecf20Sopenharmony_ci	VERB_CMD(AC_VERB_SET_CHANNEL_STREAMID, RT274_ADC_IN2, 0)
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci/* Index registers */
1378c2ecf20Sopenharmony_ci#define RT274_EAPD_GPIO_IRQ_CTRL	0x10
1388c2ecf20Sopenharmony_ci#define RT274_PAD_CTRL12		0x35
1398c2ecf20Sopenharmony_ci#define RT274_I2S_CTRL1			0x63
1408c2ecf20Sopenharmony_ci#define RT274_I2S_CTRL2			0x64
1418c2ecf20Sopenharmony_ci#define RT274_MCLK_CTRL			0x71
1428c2ecf20Sopenharmony_ci#define RT274_CLK_CTRL			0x72
1438c2ecf20Sopenharmony_ci#define RT274_PLL2_CTRL			0x7b
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci/* EAPD GPIO IRQ control (Index 0x10) */
1478c2ecf20Sopenharmony_ci#define RT274_IRQ_DIS		(0x0 << 13)
1488c2ecf20Sopenharmony_ci#define RT274_IRQ_EN		(0x1 << 13)
1498c2ecf20Sopenharmony_ci#define RT274_IRQ_CLR		(0x1 << 12)
1508c2ecf20Sopenharmony_ci#define RT274_GPI2_SEL_MASK	(0x3 << 7)
1518c2ecf20Sopenharmony_ci#define RT274_GPI2_SEL_GPIO2	(0x0 << 7)
1528c2ecf20Sopenharmony_ci#define RT274_GPI2_SEL_I2S	(0x1 << 7)
1538c2ecf20Sopenharmony_ci#define RT274_GPI2_SEL_DMIC_CLK	(0x2 << 7)
1548c2ecf20Sopenharmony_ci#define RT274_GPI2_SEL_CBJ	(0x3 << 7)
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci/* Front I2S_Interface control 1 (Index 0x63) */
1578c2ecf20Sopenharmony_ci#define RT274_I2S_MODE_MASK	(0x1 << 11)
1588c2ecf20Sopenharmony_ci#define RT274_I2S_MODE_S	(0x0 << 11)
1598c2ecf20Sopenharmony_ci#define RT274_I2S_MODE_M	(0x1 << 11)
1608c2ecf20Sopenharmony_ci#define RT274_TDM_DIS		(0x0 << 10)
1618c2ecf20Sopenharmony_ci#define RT274_TDM_EN		(0x1 << 10)
1628c2ecf20Sopenharmony_ci#define RT274_TDM_CH_NUM	(0x1 << 7)
1638c2ecf20Sopenharmony_ci#define RT274_TDM_2CH		(0x0 << 7)
1648c2ecf20Sopenharmony_ci#define RT274_TDM_4CH		(0x1 << 7)
1658c2ecf20Sopenharmony_ci#define RT274_I2S_FMT_MASK	(0x3 << 8)
1668c2ecf20Sopenharmony_ci#define RT274_I2S_FMT_I2S	(0x0 << 8)
1678c2ecf20Sopenharmony_ci#define RT274_I2S_FMT_LJ	(0x1 << 8)
1688c2ecf20Sopenharmony_ci#define RT274_I2S_FMT_PCMA	(0x2 << 8)
1698c2ecf20Sopenharmony_ci#define RT274_I2S_FMT_PCMB	(0x3 << 8)
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci/* MCLK clock domain control (Index 0x71) */
1728c2ecf20Sopenharmony_ci#define RT274_MCLK_MODE_MASK	(0x1 << 14)
1738c2ecf20Sopenharmony_ci#define RT274_MCLK_MODE_DIS	(0x0 << 14)
1748c2ecf20Sopenharmony_ci#define RT274_MCLK_MODE_EN	(0x1 << 14)
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci/* Clock control (Index 0x72) */
1778c2ecf20Sopenharmony_ci#define RT274_CLK_SRC_MASK	(0x7 << 3)
1788c2ecf20Sopenharmony_ci#define RT274_CLK_SRC_MCLK	(0x0 << 3)
1798c2ecf20Sopenharmony_ci#define RT274_CLK_SRC_PLL2	(0x3 << 3)
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci/* PLL2 control (Index 0x7b) */
1828c2ecf20Sopenharmony_ci#define RT274_PLL2_SRC_MASK	(0x1 << 13)
1838c2ecf20Sopenharmony_ci#define RT274_PLL2_SRC_MCLK	(0x0 << 13)
1848c2ecf20Sopenharmony_ci#define RT274_PLL2_SRC_BCLK	(0x1 << 13)
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci/* HP-OUT (0x21) */
1878c2ecf20Sopenharmony_ci#define RT274_M_HP_MUX_SFT	14
1888c2ecf20Sopenharmony_ci#define RT274_HP_SEL_MASK	0x1
1898c2ecf20Sopenharmony_ci#define RT274_HP_SEL_SFT	0
1908c2ecf20Sopenharmony_ci#define RT274_HP_SEL_F		0
1918c2ecf20Sopenharmony_ci#define RT274_HP_SEL_S		1
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci/* ADC (0x22) (0x23) */
1948c2ecf20Sopenharmony_ci#define RT274_ADC_SEL_MASK	0x7
1958c2ecf20Sopenharmony_ci#define RT274_ADC_SEL_SFT	0
1968c2ecf20Sopenharmony_ci#define RT274_ADC_SEL_MIC	0
1978c2ecf20Sopenharmony_ci#define RT274_ADC_SEL_LINE1	1
1988c2ecf20Sopenharmony_ci#define RT274_ADC_SEL_LINE2	2
1998c2ecf20Sopenharmony_ci#define RT274_ADC_SEL_DMIC	3
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci#define RT274_SCLK_S_MCLK	0
2028c2ecf20Sopenharmony_ci#define RT274_SCLK_S_PLL1	1
2038c2ecf20Sopenharmony_ci#define RT274_SCLK_S_PLL2	2
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci#define RT274_PLL2_S_MCLK	0
2068c2ecf20Sopenharmony_ci#define RT274_PLL2_S_BCLK	1
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_cienum {
2098c2ecf20Sopenharmony_ci	RT274_AIF1,
2108c2ecf20Sopenharmony_ci	RT274_AIFS,
2118c2ecf20Sopenharmony_ci};
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci#endif /* __RT274_H__ */
2148c2ecf20Sopenharmony_ci
215