1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2020 MediaTek Inc.
4  */
5 
6 #ifndef __MFD_MT6358_CORE_H__
7 #define __MFD_MT6358_CORE_H__
8 
9 #define MT6358_REG_WIDTH 16
10 
11 struct irq_top_t {
12 	int hwirq_base;
13 	unsigned int num_int_regs;
14 	unsigned int num_int_bits;
15 	unsigned int en_reg;
16 	unsigned int en_reg_shift;
17 	unsigned int sta_reg;
18 	unsigned int sta_reg_shift;
19 	unsigned int top_offset;
20 };
21 
22 struct pmic_irq_data {
23 	unsigned int num_top;
24 	unsigned int num_pmic_irqs;
25 	unsigned short top_int_status_reg;
26 	bool *enable_hwirq;
27 	bool *cache_hwirq;
28 };
29 
30 enum mt6358_irq_top_status_shift {
31 	MT6358_BUCK_TOP = 0,
32 	MT6358_LDO_TOP,
33 	MT6358_PSC_TOP,
34 	MT6358_SCK_TOP,
35 	MT6358_BM_TOP,
36 	MT6358_HK_TOP,
37 	MT6358_AUD_TOP,
38 	MT6358_MISC_TOP,
39 };
40 
41 enum mt6358_irq_numbers {
42 	MT6358_IRQ_VPROC11_OC = 0,
43 	MT6358_IRQ_VPROC12_OC,
44 	MT6358_IRQ_VCORE_OC,
45 	MT6358_IRQ_VGPU_OC,
46 	MT6358_IRQ_VMODEM_OC,
47 	MT6358_IRQ_VDRAM1_OC,
48 	MT6358_IRQ_VS1_OC,
49 	MT6358_IRQ_VS2_OC,
50 	MT6358_IRQ_VPA_OC,
51 	MT6358_IRQ_VCORE_PREOC,
52 	MT6358_IRQ_VFE28_OC = 16,
53 	MT6358_IRQ_VXO22_OC,
54 	MT6358_IRQ_VRF18_OC,
55 	MT6358_IRQ_VRF12_OC,
56 	MT6358_IRQ_VEFUSE_OC,
57 	MT6358_IRQ_VCN33_OC,
58 	MT6358_IRQ_VCN28_OC,
59 	MT6358_IRQ_VCN18_OC,
60 	MT6358_IRQ_VCAMA1_OC,
61 	MT6358_IRQ_VCAMA2_OC,
62 	MT6358_IRQ_VCAMD_OC,
63 	MT6358_IRQ_VCAMIO_OC,
64 	MT6358_IRQ_VLDO28_OC,
65 	MT6358_IRQ_VA12_OC,
66 	MT6358_IRQ_VAUX18_OC,
67 	MT6358_IRQ_VAUD28_OC,
68 	MT6358_IRQ_VIO28_OC,
69 	MT6358_IRQ_VIO18_OC,
70 	MT6358_IRQ_VSRAM_PROC11_OC,
71 	MT6358_IRQ_VSRAM_PROC12_OC,
72 	MT6358_IRQ_VSRAM_OTHERS_OC,
73 	MT6358_IRQ_VSRAM_GPU_OC,
74 	MT6358_IRQ_VDRAM2_OC,
75 	MT6358_IRQ_VMC_OC,
76 	MT6358_IRQ_VMCH_OC,
77 	MT6358_IRQ_VEMC_OC,
78 	MT6358_IRQ_VSIM1_OC,
79 	MT6358_IRQ_VSIM2_OC,
80 	MT6358_IRQ_VIBR_OC,
81 	MT6358_IRQ_VUSB_OC,
82 	MT6358_IRQ_VBIF28_OC,
83 	MT6358_IRQ_PWRKEY = 48,
84 	MT6358_IRQ_HOMEKEY,
85 	MT6358_IRQ_PWRKEY_R,
86 	MT6358_IRQ_HOMEKEY_R,
87 	MT6358_IRQ_NI_LBAT_INT,
88 	MT6358_IRQ_CHRDET,
89 	MT6358_IRQ_CHRDET_EDGE,
90 	MT6358_IRQ_VCDT_HV_DET,
91 	MT6358_IRQ_RTC = 64,
92 	MT6358_IRQ_FG_BAT0_H = 80,
93 	MT6358_IRQ_FG_BAT0_L,
94 	MT6358_IRQ_FG_CUR_H,
95 	MT6358_IRQ_FG_CUR_L,
96 	MT6358_IRQ_FG_ZCV,
97 	MT6358_IRQ_FG_BAT1_H,
98 	MT6358_IRQ_FG_BAT1_L,
99 	MT6358_IRQ_FG_N_CHARGE_L,
100 	MT6358_IRQ_FG_IAVG_H,
101 	MT6358_IRQ_FG_IAVG_L,
102 	MT6358_IRQ_FG_TIME_H,
103 	MT6358_IRQ_FG_DISCHARGE,
104 	MT6358_IRQ_FG_CHARGE,
105 	MT6358_IRQ_BATON_LV = 96,
106 	MT6358_IRQ_BATON_HT,
107 	MT6358_IRQ_BATON_BAT_IN,
108 	MT6358_IRQ_BATON_BAT_OUT,
109 	MT6358_IRQ_BIF,
110 	MT6358_IRQ_BAT_H = 112,
111 	MT6358_IRQ_BAT_L,
112 	MT6358_IRQ_BAT2_H,
113 	MT6358_IRQ_BAT2_L,
114 	MT6358_IRQ_BAT_TEMP_H,
115 	MT6358_IRQ_BAT_TEMP_L,
116 	MT6358_IRQ_AUXADC_IMP,
117 	MT6358_IRQ_NAG_C_DLTV,
118 	MT6358_IRQ_AUDIO = 128,
119 	MT6358_IRQ_ACCDET = 133,
120 	MT6358_IRQ_ACCDET_EINT0,
121 	MT6358_IRQ_ACCDET_EINT1,
122 	MT6358_IRQ_SPI_CMD_ALERT = 144,
123 	MT6358_IRQ_NR,
124 };
125 
126 #define MT6358_IRQ_BUCK_BASE MT6358_IRQ_VPROC11_OC
127 #define MT6358_IRQ_LDO_BASE MT6358_IRQ_VFE28_OC
128 #define MT6358_IRQ_PSC_BASE MT6358_IRQ_PWRKEY
129 #define MT6358_IRQ_SCK_BASE MT6358_IRQ_RTC
130 #define MT6358_IRQ_BM_BASE MT6358_IRQ_FG_BAT0_H
131 #define MT6358_IRQ_HK_BASE MT6358_IRQ_BAT_H
132 #define MT6358_IRQ_AUD_BASE MT6358_IRQ_AUDIO
133 #define MT6358_IRQ_MISC_BASE MT6358_IRQ_SPI_CMD_ALERT
134 
135 #define MT6358_IRQ_BUCK_BITS (MT6358_IRQ_VCORE_PREOC - MT6358_IRQ_BUCK_BASE + 1)
136 #define MT6358_IRQ_LDO_BITS (MT6358_IRQ_VBIF28_OC - MT6358_IRQ_LDO_BASE + 1)
137 #define MT6358_IRQ_PSC_BITS (MT6358_IRQ_VCDT_HV_DET - MT6358_IRQ_PSC_BASE + 1)
138 #define MT6358_IRQ_SCK_BITS (MT6358_IRQ_RTC - MT6358_IRQ_SCK_BASE + 1)
139 #define MT6358_IRQ_BM_BITS (MT6358_IRQ_BIF - MT6358_IRQ_BM_BASE + 1)
140 #define MT6358_IRQ_HK_BITS (MT6358_IRQ_NAG_C_DLTV - MT6358_IRQ_HK_BASE + 1)
141 #define MT6358_IRQ_AUD_BITS (MT6358_IRQ_ACCDET_EINT1 - MT6358_IRQ_AUD_BASE + 1)
142 #define MT6358_IRQ_MISC_BITS	\
143 	(MT6358_IRQ_SPI_CMD_ALERT - MT6358_IRQ_MISC_BASE + 1)
144 
145 #define MT6358_TOP_GEN(sp)	\
146 {	\
147 	.hwirq_base = MT6358_IRQ_##sp##_BASE,	\
148 	.num_int_regs =	\
149 		((MT6358_IRQ_##sp##_BITS - 1) / MT6358_REG_WIDTH) + 1,	\
150 	.num_int_bits = MT6358_IRQ_##sp##_BITS, \
151 	.en_reg = MT6358_##sp##_TOP_INT_CON0,	\
152 	.en_reg_shift = 0x6,	\
153 	.sta_reg = MT6358_##sp##_TOP_INT_STATUS0,	\
154 	.sta_reg_shift = 0x2,	\
155 	.top_offset = MT6358_##sp##_TOP,	\
156 }
157 
158 #endif /* __MFD_MT6358_CORE_H__ */
159