xref: /openbmc/linux/sound/soc/codecs/rt715-sdca.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
120d17057SJack Yu /* SPDX-License-Identifier: GPL-2.0-only */
220d17057SJack Yu /*
320d17057SJack Yu  * rt715-sdca.h -- RT715 ALSA SoC audio driver header
420d17057SJack Yu  *
520d17057SJack Yu  * Copyright(c) 2020 Realtek Semiconductor Corp.
620d17057SJack Yu  */
720d17057SJack Yu 
820d17057SJack Yu #ifndef __RT715_SDCA_H__
920d17057SJack Yu #define __RT715_SDCA_H__
1020d17057SJack Yu 
1120d17057SJack Yu #include <linux/regmap.h>
1220d17057SJack Yu #include <linux/soundwire/sdw.h>
1320d17057SJack Yu #include <linux/soundwire/sdw_type.h>
1420d17057SJack Yu #include <sound/soc.h>
1520d17057SJack Yu #include <linux/workqueue.h>
1620d17057SJack Yu #include <linux/device.h>
1720d17057SJack Yu 
1820d17057SJack Yu struct rt715_sdca_priv {
1920d17057SJack Yu 	struct regmap *regmap;
2020d17057SJack Yu 	struct regmap *mbq_regmap;
2120d17057SJack Yu 	struct snd_soc_codec *codec;
2220d17057SJack Yu 	struct sdw_slave *slave;
2320d17057SJack Yu 	struct delayed_work adc_mute_work;
2420d17057SJack Yu 	int dbg_nid;
2520d17057SJack Yu 	int dbg_vid;
2620d17057SJack Yu 	int dbg_payload;
2720d17057SJack Yu 	struct sdw_bus_params params;
2820d17057SJack Yu 	bool hw_init;
2920d17057SJack Yu 	bool first_hw_init;
30d34d0897SPierre-Louis Bossart 	int l_is_unmute;
3120d17057SJack Yu 	int r_is_unmute;
3220d17057SJack Yu 	int hw_sdw_ver;
3320d17057SJack Yu 	int kctl_switch_orig[4];
3420d17057SJack Yu 	int kctl_2ch_orig[2];
3520d17057SJack Yu 	int kctl_4ch_orig[4];
3620d17057SJack Yu 	int kctl_8ch_orig[8];
3720d17057SJack Yu };
3820d17057SJack Yu 
3920d17057SJack Yu struct rt715_sdca_kcontrol_private {
4020d17057SJack Yu 	unsigned int reg_base;
4120d17057SJack Yu 	unsigned int count;
4220d17057SJack Yu 	unsigned int max;
4320d17057SJack Yu 	unsigned int shift;
4420d17057SJack Yu 	unsigned int invert;
4520d17057SJack Yu };
4620d17057SJack Yu 
4720d17057SJack Yu /* MIPI Register */
4820d17057SJack Yu #define RT715_INT_CTRL					0x005a
4920d17057SJack Yu #define RT715_INT_MASK					0x005e
5020d17057SJack Yu 
5120d17057SJack Yu /* NID */
5220d17057SJack Yu #define RT715_AUDIO_FUNCTION_GROUP			0x01
5320d17057SJack Yu #define RT715_MIC_ADC					0x07
5420d17057SJack Yu #define RT715_LINE_ADC					0x08
5520d17057SJack Yu #define RT715_MIX_ADC					0x09
5620d17057SJack Yu #define RT715_DMIC1					0x12
5720d17057SJack Yu #define RT715_DMIC2					0x13
5820d17057SJack Yu #define RT715_MIC1					0x18
5920d17057SJack Yu #define RT715_MIC2					0x19
6020d17057SJack Yu #define RT715_LINE1					0x1a
6120d17057SJack Yu #define RT715_LINE2					0x1b
6220d17057SJack Yu #define RT715_DMIC3					0x1d
6320d17057SJack Yu #define RT715_DMIC4					0x29
6420d17057SJack Yu #define RT715_VENDOR_REG				0x20
6520d17057SJack Yu #define RT715_MUX_IN1					0x22
6620d17057SJack Yu #define RT715_MUX_IN2					0x23
6720d17057SJack Yu #define RT715_MUX_IN3					0x24
6820d17057SJack Yu #define RT715_MUX_IN4					0x25
6920d17057SJack Yu #define RT715_MIX_ADC2					0x27
7020d17057SJack Yu #define RT715_INLINE_CMD				0x55
7120d17057SJack Yu #define RT715_VENDOR_HDA_CTL				0x61
7220d17057SJack Yu 
7320d17057SJack Yu /* Index (NID:20h) */
7420d17057SJack Yu #define RT715_PRODUCT_NUM				0x0
7520d17057SJack Yu #define RT715_IRQ_CTRL					0x2b
7620d17057SJack Yu #define RT715_AD_FUNC_EN				0x36
7720d17057SJack Yu #define RT715_REV_1					0x37
7820d17057SJack Yu #define RT715_SDW_INPUT_SEL				0x39
7920d17057SJack Yu #define RT715_DFLL_VAD					0x44
80*e343d34aSJack Yu #define RT715_EXT_DMIC_CLK_CTRL2			0x54
8120d17057SJack Yu 
8220d17057SJack Yu /* Index (NID:61h) */
8320d17057SJack Yu #define RT715_HDA_LEGACY_MUX_CTL1			0x00
8420d17057SJack Yu 
8520d17057SJack Yu /* SDCA (Function) */
8620d17057SJack Yu #define FUN_JACK_CODEC				0x01
8720d17057SJack Yu #define FUN_MIC_ARRAY				0x02
8820d17057SJack Yu #define FUN_HID						0x03
8920d17057SJack Yu /* SDCA (Entity) */
9020d17057SJack Yu #define RT715_SDCA_ST_EN							0x00
9120d17057SJack Yu #define RT715_SDCA_CS_FREQ_IND_EN					0x01
9220d17057SJack Yu #define RT715_SDCA_FU_ADC8_9_VOL					0x02
9320d17057SJack Yu #define RT715_SDCA_SMPU_TRIG_ST_EN					0x05
9420d17057SJack Yu #define RT715_SDCA_FU_ADC10_11_VOL					0x06
9520d17057SJack Yu #define RT715_SDCA_FU_ADC7_27_VOL					0x0a
9620d17057SJack Yu #define RT715_SDCA_FU_AMIC_GAIN_EN					0x0c
9720d17057SJack Yu #define RT715_SDCA_FU_DMIC_GAIN_EN					0x0e
9820d17057SJack Yu #define RT715_SDCA_CX_CLK_SEL_EN					0x10
9920d17057SJack Yu #define RT715_SDCA_CREQ_POW_EN						0x18
10020d17057SJack Yu /* SDCA (Control) */
10120d17057SJack Yu #define RT715_SDCA_ST_CTRL							0x00
10220d17057SJack Yu #define RT715_SDCA_CX_CLK_SEL_CTRL					0x01
10320d17057SJack Yu #define RT715_SDCA_REQ_POW_CTRL					0x01
10420d17057SJack Yu #define RT715_SDCA_FU_MUTE_CTRL					0x01
10520d17057SJack Yu #define RT715_SDCA_FU_VOL_CTRL						0x02
10620d17057SJack Yu #define RT715_SDCA_FU_DMIC_GAIN_CTRL				0x0b
10720d17057SJack Yu #define RT715_SDCA_FREQ_IND_CTRL					0x10
10820d17057SJack Yu #define RT715_SDCA_SMPU_TRIG_EN_CTRL				0x10
10920d17057SJack Yu #define RT715_SDCA_SMPU_TRIG_ST_CTRL				0x11
11020d17057SJack Yu /* SDCA (Channel) */
11120d17057SJack Yu #define CH_00						0x00
11220d17057SJack Yu #define CH_01						0x01
11320d17057SJack Yu #define CH_02						0x02
11420d17057SJack Yu #define CH_03						0x03
11520d17057SJack Yu #define CH_04						0x04
11620d17057SJack Yu #define CH_05						0x05
11720d17057SJack Yu #define CH_06						0x06
11820d17057SJack Yu #define CH_07						0x07
11920d17057SJack Yu #define CH_08						0x08
12020d17057SJack Yu 
12120d17057SJack Yu #define RT715_SDCA_DB_STEP			375
12220d17057SJack Yu 
12320d17057SJack Yu enum {
12420d17057SJack Yu 	RT715_AIF1,
12520d17057SJack Yu 	RT715_AIF2,
12620d17057SJack Yu };
12720d17057SJack Yu 
12820d17057SJack Yu int rt715_sdca_io_init(struct device *dev, struct sdw_slave *slave);
12920d17057SJack Yu int rt715_sdca_init(struct device *dev, struct regmap *mbq_regmap,
13020d17057SJack Yu 	struct regmap *regmap, struct sdw_slave *slave);
13120d17057SJack Yu 
13220d17057SJack Yu #endif /* __RT715_SDCA_H__ */
13320d17057SJack Yu