xref: /linux/sound/soc/codecs/rt766-sdca.h (revision c41ac86802fc0a22a886915a43bcad2e8d482b02)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * rt766-sdca.h -- RT766 SDCA ALSA SoC audio driver header
4  *
5  * Copyright(c) 2026 Realtek Semiconductor Corp.
6  */
7 
8 #ifndef __RT766_H__
9 #define __RT766_H__
10 
11 #include <linux/hid.h>
12 #include <linux/pm.h>
13 #include <linux/regmap.h>
14 #include <linux/soundwire/sdw.h>
15 #include <linux/soundwire/sdw_type.h>
16 #include <sound/soc.h>
17 #include <linux/workqueue.h>
18 
19 struct  rt766_sdca_priv {
20 	struct regmap *regmap;
21 	struct snd_soc_component *component;
22 	struct sdw_slave *slave;
23 	bool hw_init;
24 	bool first_hw_init;
25 	struct snd_soc_jack *hs_jack;
26 	struct mutex disable_irq_lock; /* SDCA irq lock protection */
27 	bool disable_irq;
28 	int jack_type;
29 	bool fu41_dapm_mute;
30 	bool fu41_mixer_l_mute;
31 	bool fu41_mixer_r_mute;
32 	bool fu113_dapm_mute;
33 	bool fu113_mixer_mute[4];
34 	bool fu21_dapm_mute;
35 	bool fu21_mixer_l_mute;
36 	bool fu21_mixer_r_mute;
37 	bool fu36_dapm_mute;
38 	bool fu36_mixer_l_mute;
39 	bool fu36_mixer_r_mute;
40 	struct sdca_function_data *uaj_func_data;
41 	struct sdca_function_data *sm_func_data;
42 	struct sdca_function_data *sa_func_data;
43 	struct sdca_function_data *hid_func_data;
44 	struct sdca_interrupt_info *irq_info;
45 	struct hid_device *hid;
46 };
47 
48 /* vendor registers */
49 #define RT766_VERSION_ID	0xc404
50 #define RT766_DEV_ID1		0xc405
51 #define RT766_DEV_ID0		0xc406
52 #define RT766_BOND_LATCH_ID	0xc407
53 
54 #define RT766_HP_POWER_STATE		0x1000004
55 #define RT766_HP_FSM_CTL2_1		0x100000d
56 
57 /* MCU Patch address */
58 #define RT766_MCU_PATCH_ADDR1_START	0x10010000
59 #define RT766_MCU_PATCH_ADDR1_END	0x10011fff
60 #define RT766_MCU_PATCH_ADDR2_START	0x10020000
61 #define RT766_MCU_PATCH_ADDR2_END	0x10023fff
62 
63 /* Buffer address for HID */
64 #define RT766_BUF_ADDR_HID1	0x44030000
65 #define RT766_BUF_ADDR_HID2	0x44030020
66 
67 /* SDCA (Channel) */
68 #define RT766_CH_1	0x01
69 #define RT766_CH_2	0x02
70 #define RT766_CH_3	0x03
71 #define RT766_CH_4	0x04
72 
73 /* RT766 SDCA Control - function number */
74 #define RT766_FUNC_NUM_UAJ 0x01
75 #define RT766_FUNC_NUM_MIC 0x02
76 #define RT766_FUNC_NUM_HID 0x03
77 #define RT766_FUNC_NUM_AMP 0x04
78 
79 /* RT766 SDCA entity */
80 #define RT766_SDCA_ENT_0		0x00
81 #define RT766_SDCA_ENT_HID101		0x01
82 #define RT766_SDCA_ENT_GE49		0x49
83 #define RT766_SDCA_ENT_USER_FU41	0x05
84 #define RT766_SDCA_ENT_USER_FU36	0x0f
85 #define RT766_SDCA_ENT_USER_FU21	0x03
86 #define RT766_SDCA_ENT_USER_FU113	0x30
87 #define RT766_SDCA_ENT_PDE23		0x33
88 #define RT766_SDCA_ENT_PDE47		0x28
89 #define RT766_SDCA_ENT_PDE11		0x2a
90 #define RT766_SDCA_ENT_PDE34		0x29
91 #define RT766_SDCA_ENT_CS41		0x01
92 #define RT766_SDCA_ENT_CS36		0x11
93 #define RT766_SDCA_ENT_CS113		0x12
94 #define RT766_SDCA_ENT_CS21		0x21
95 #define RT766_SDCA_ENT_PLATFORM_FU33	0x44
96 #define RT766_SDCA_ENT_PPU21		0x04
97 
98 /* sample frequency index */
99 #define RT766_SDCA_RATE_44100HZ		0x08
100 #define RT766_SDCA_RATE_48000HZ		0x09
101 #define RT766_SDCA_RATE_96000HZ		0x0b
102 #define RT766_SDCA_RATE_192000HZ	0x0d
103 
104 /* SDCA Register macros */
105 #define RT766_MUTE_REG(func, fu, ch) \
106 	SDW_SDCA_CTL(RT766_FUNC_NUM_##func, RT766_SDCA_ENT_##fu, SDCA_CTL_FU_MUTE, RT766_CH_##ch)
107 
108 #define RT766_VOLUME_REG(func, fu, ch) \
109 	SDW_SDCA_CTL(RT766_FUNC_NUM_##func, RT766_SDCA_ENT_##fu, SDCA_CTL_FU_CHANNEL_VOLUME, RT766_CH_##ch)
110 
111 #define RT766_GAIN_REG(func, fu, ch) \
112 	SDW_SDCA_CTL(RT766_FUNC_NUM_##func, RT766_SDCA_ENT_##fu, SDCA_CTL_FU_GAIN, RT766_CH_##ch)
113 
114 #define RT766_PDE_REQ_REG(func, pde) \
115 	SDW_SDCA_CTL(RT766_FUNC_NUM_##func, RT766_SDCA_ENT_##pde, SDCA_CTL_PDE_REQUESTED_PS, 0)
116 
117 #define RT766_PDE_ACTUAL_REG(func, pde) \
118 	SDW_SDCA_CTL(RT766_FUNC_NUM_##func, RT766_SDCA_ENT_##pde, SDCA_CTL_PDE_ACTUAL_PS, 0)
119 
120 #define RT766_FUNC_STATUS_REG(func) \
121 	SDW_SDCA_CTL(RT766_FUNC_NUM_##func, RT766_SDCA_ENT_0, SDCA_CTL_ENTITY_0_FUNCTION_STATUS, 0)
122 
123 #define RT766_SDCA_CTL(func, ent, ctl) \
124 	SDW_SDCA_CTL(RT766_FUNC_NUM_##func, RT766_SDCA_ENT_##ent, ctl, 0)
125 
126 enum {
127 	RT766_AIF1,
128 	RT766_AIF2,
129 	RT766_AIF3,
130 };
131 
132 enum {
133 	RT766_DAI_UAJ,
134 	RT766_DAI_AMP,
135 	RT766_DAI_MIC,
136 };
137 
138 int rt766_sdca_io_init(struct device *dev, struct sdw_slave *slave);
139 int rt766_sdca_init(struct device *dev, struct regmap *regmap, struct sdw_slave *slave);
140 #endif /* __RT766_H__ */
141