xref: /openbmc/linux/sound/soc/codecs/rt715-sdca.h (revision e343d34a9c912fc5c321e2a9fbc02e9dc9534ade)
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 	enum sdw_slave_status status;
2820d17057SJack Yu 	struct sdw_bus_params params;
2920d17057SJack Yu 	bool hw_init;
30d34d0897SPierre-Louis Bossart 	bool first_hw_init;
3120d17057SJack Yu 	int l_is_unmute;
3220d17057SJack Yu 	int r_is_unmute;
3320d17057SJack Yu 	int hw_sdw_ver;
3420d17057SJack Yu 	int kctl_switch_orig[4];
3520d17057SJack Yu 	int kctl_2ch_orig[2];
3620d17057SJack Yu 	int kctl_4ch_orig[4];
3720d17057SJack Yu 	int kctl_8ch_orig[8];
3820d17057SJack Yu };
3920d17057SJack Yu 
4020d17057SJack Yu struct rt715_sdw_stream_data {
4120d17057SJack Yu 	struct sdw_stream_runtime *sdw_stream;
4220d17057SJack Yu };
4320d17057SJack Yu 
4420d17057SJack Yu struct rt715_sdca_kcontrol_private {
4520d17057SJack Yu 	unsigned int reg_base;
4620d17057SJack Yu 	unsigned int count;
4720d17057SJack Yu 	unsigned int max;
4820d17057SJack Yu 	unsigned int shift;
4920d17057SJack Yu 	unsigned int invert;
5020d17057SJack Yu };
5120d17057SJack Yu 
5220d17057SJack Yu /* MIPI Register */
5320d17057SJack Yu #define RT715_INT_CTRL					0x005a
5420d17057SJack Yu #define RT715_INT_MASK					0x005e
5520d17057SJack Yu 
5620d17057SJack Yu /* NID */
5720d17057SJack Yu #define RT715_AUDIO_FUNCTION_GROUP			0x01
5820d17057SJack Yu #define RT715_MIC_ADC					0x07
5920d17057SJack Yu #define RT715_LINE_ADC					0x08
6020d17057SJack Yu #define RT715_MIX_ADC					0x09
6120d17057SJack Yu #define RT715_DMIC1					0x12
6220d17057SJack Yu #define RT715_DMIC2					0x13
6320d17057SJack Yu #define RT715_MIC1					0x18
6420d17057SJack Yu #define RT715_MIC2					0x19
6520d17057SJack Yu #define RT715_LINE1					0x1a
6620d17057SJack Yu #define RT715_LINE2					0x1b
6720d17057SJack Yu #define RT715_DMIC3					0x1d
6820d17057SJack Yu #define RT715_DMIC4					0x29
6920d17057SJack Yu #define RT715_VENDOR_REG				0x20
7020d17057SJack Yu #define RT715_MUX_IN1					0x22
7120d17057SJack Yu #define RT715_MUX_IN2					0x23
7220d17057SJack Yu #define RT715_MUX_IN3					0x24
7320d17057SJack Yu #define RT715_MUX_IN4					0x25
7420d17057SJack Yu #define RT715_MIX_ADC2					0x27
7520d17057SJack Yu #define RT715_INLINE_CMD				0x55
7620d17057SJack Yu #define RT715_VENDOR_HDA_CTL				0x61
7720d17057SJack Yu 
7820d17057SJack Yu /* Index (NID:20h) */
7920d17057SJack Yu #define RT715_PRODUCT_NUM				0x0
8020d17057SJack Yu #define RT715_IRQ_CTRL					0x2b
8120d17057SJack Yu #define RT715_AD_FUNC_EN				0x36
8220d17057SJack Yu #define RT715_REV_1					0x37
8320d17057SJack Yu #define RT715_SDW_INPUT_SEL				0x39
84*e343d34aSJack Yu #define RT715_DFLL_VAD					0x44
8520d17057SJack Yu #define RT715_EXT_DMIC_CLK_CTRL2			0x54
8620d17057SJack Yu 
8720d17057SJack Yu /* Index (NID:61h) */
8820d17057SJack Yu #define RT715_HDA_LEGACY_MUX_CTL1			0x00
8920d17057SJack Yu 
9020d17057SJack Yu /* SDCA (Function) */
9120d17057SJack Yu #define FUN_JACK_CODEC				0x01
9220d17057SJack Yu #define FUN_MIC_ARRAY				0x02
9320d17057SJack Yu #define FUN_HID						0x03
9420d17057SJack Yu /* SDCA (Entity) */
9520d17057SJack Yu #define RT715_SDCA_ST_EN							0x00
9620d17057SJack Yu #define RT715_SDCA_CS_FREQ_IND_EN					0x01
9720d17057SJack Yu #define RT715_SDCA_FU_ADC8_9_VOL					0x02
9820d17057SJack Yu #define RT715_SDCA_SMPU_TRIG_ST_EN					0x05
9920d17057SJack Yu #define RT715_SDCA_FU_ADC10_11_VOL					0x06
10020d17057SJack Yu #define RT715_SDCA_FU_ADC7_27_VOL					0x0a
10120d17057SJack Yu #define RT715_SDCA_FU_AMIC_GAIN_EN					0x0c
10220d17057SJack Yu #define RT715_SDCA_FU_DMIC_GAIN_EN					0x0e
10320d17057SJack Yu #define RT715_SDCA_CX_CLK_SEL_EN					0x10
10420d17057SJack Yu #define RT715_SDCA_CREQ_POW_EN						0x18
10520d17057SJack Yu /* SDCA (Control) */
10620d17057SJack Yu #define RT715_SDCA_ST_CTRL							0x00
10720d17057SJack Yu #define RT715_SDCA_CX_CLK_SEL_CTRL					0x01
10820d17057SJack Yu #define RT715_SDCA_REQ_POW_CTRL					0x01
10920d17057SJack Yu #define RT715_SDCA_FU_MUTE_CTRL					0x01
11020d17057SJack Yu #define RT715_SDCA_FU_VOL_CTRL						0x02
11120d17057SJack Yu #define RT715_SDCA_FU_DMIC_GAIN_CTRL				0x0b
11220d17057SJack Yu #define RT715_SDCA_FREQ_IND_CTRL					0x10
11320d17057SJack Yu #define RT715_SDCA_SMPU_TRIG_EN_CTRL				0x10
11420d17057SJack Yu #define RT715_SDCA_SMPU_TRIG_ST_CTRL				0x11
11520d17057SJack Yu /* SDCA (Channel) */
11620d17057SJack Yu #define CH_00						0x00
11720d17057SJack Yu #define CH_01						0x01
11820d17057SJack Yu #define CH_02						0x02
11920d17057SJack Yu #define CH_03						0x03
12020d17057SJack Yu #define CH_04						0x04
12120d17057SJack Yu #define CH_05						0x05
12220d17057SJack Yu #define CH_06						0x06
12320d17057SJack Yu #define CH_07						0x07
12420d17057SJack Yu #define CH_08						0x08
12520d17057SJack Yu 
12620d17057SJack Yu #define RT715_SDCA_DB_STEP			375
12720d17057SJack Yu 
12820d17057SJack Yu enum {
12920d17057SJack Yu 	RT715_AIF1,
13020d17057SJack Yu 	RT715_AIF2,
13120d17057SJack Yu };
13220d17057SJack Yu 
13320d17057SJack Yu int rt715_sdca_io_init(struct device *dev, struct sdw_slave *slave);
13420d17057SJack Yu int rt715_sdca_init(struct device *dev, struct regmap *mbq_regmap,
13520d17057SJack Yu 	struct regmap *regmap, struct sdw_slave *slave);
13620d17057SJack Yu 
13720d17057SJack Yu #endif /* __RT715_SDCA_H__ */
138