1 // SPDX-License-Identifier: GPL-2.0-only
3 * MFD core driver for Rockchip RK8XX
5 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
6 * Copyright (C) 2016 PHYTEC Messtechnik GmbH
8 * Author: Chris Zhong <zyw@rock-chips.com>
9 * Author: Zhang Qing <zhangqing@rock-chips.com>
10 * Author: Wadim Egorov <w.egorov@phytec.de>
13 #include <linux/interrupt.h>
14 #include <linux/mfd/rk808.h>
15 #include <linux/mfd/core.h>
16 #include <linux/module.h>
17 #include <linux/property.h>
18 #include <linux/regmap.h>
19 #include <linux/reboot.h>
21 struct rk808_reg_data
{
27 static const struct resource rtc_resources
[] = {
28 DEFINE_RES_IRQ(RK808_IRQ_RTC_ALARM
),
31 static const struct resource rk816_rtc_resources
[] = {
32 DEFINE_RES_IRQ(RK816_IRQ_RTC_ALARM
),
35 static const struct resource rk817_rtc_resources
[] = {
36 DEFINE_RES_IRQ(RK817_IRQ_RTC_ALARM
),
39 static const struct resource rk805_key_resources
[] = {
40 DEFINE_RES_IRQ(RK805_IRQ_PWRON_RISE
),
41 DEFINE_RES_IRQ(RK805_IRQ_PWRON_FALL
),
44 static struct resource rk806_pwrkey_resources
[] = {
45 DEFINE_RES_IRQ(RK806_IRQ_PWRON_FALL
),
46 DEFINE_RES_IRQ(RK806_IRQ_PWRON_RISE
),
49 static const struct resource rk817_pwrkey_resources
[] = {
50 DEFINE_RES_IRQ(RK817_IRQ_PWRON_FALL
),
51 DEFINE_RES_IRQ(RK817_IRQ_PWRON_RISE
),
54 static const struct resource rk817_charger_resources
[] = {
55 DEFINE_RES_IRQ(RK817_IRQ_PLUG_IN
),
56 DEFINE_RES_IRQ(RK817_IRQ_PLUG_OUT
),
59 static const struct mfd_cell rk805s
[] = {
60 { .name
= "rk808-clkout", },
61 { .name
= "rk808-regulator", },
62 { .name
= "rk805-pinctrl", },
65 .num_resources
= ARRAY_SIZE(rtc_resources
),
66 .resources
= &rtc_resources
[0],
68 { .name
= "rk805-pwrkey",
69 .num_resources
= ARRAY_SIZE(rk805_key_resources
),
70 .resources
= &rk805_key_resources
[0],
74 static const struct mfd_cell rk806s
[] = {
75 { .name
= "rk805-pinctrl", },
76 { .name
= "rk808-regulator", },
78 .name
= "rk805-pwrkey",
79 .resources
= rk806_pwrkey_resources
,
80 .num_resources
= ARRAY_SIZE(rk806_pwrkey_resources
),
84 static const struct mfd_cell rk808s
[] = {
85 { .name
= "rk808-clkout", },
86 { .name
= "rk808-regulator", },
89 .num_resources
= ARRAY_SIZE(rtc_resources
),
90 .resources
= rtc_resources
,
94 static const struct mfd_cell rk816s
[] = {
95 { .name
= "rk805-pinctrl", },
96 { .name
= "rk808-clkout", },
97 { .name
= "rk808-regulator", },
99 .name
= "rk805-pwrkey",
100 .num_resources
= ARRAY_SIZE(rk805_key_resources
),
101 .resources
= rk805_key_resources
,
105 .num_resources
= ARRAY_SIZE(rk816_rtc_resources
),
106 .resources
= rk816_rtc_resources
,
110 static const struct mfd_cell rk817s
[] = {
111 { .name
= "rk808-clkout", },
112 { .name
= "rk808-regulator", },
114 .name
= "rk805-pwrkey",
115 .num_resources
= ARRAY_SIZE(rk817_pwrkey_resources
),
116 .resources
= &rk817_pwrkey_resources
[0],
120 .num_resources
= ARRAY_SIZE(rk817_rtc_resources
),
121 .resources
= &rk817_rtc_resources
[0],
123 { .name
= "rk817-codec", },
125 .name
= "rk817-charger",
126 .num_resources
= ARRAY_SIZE(rk817_charger_resources
),
127 .resources
= &rk817_charger_resources
[0],
131 static const struct mfd_cell rk818s
[] = {
132 { .name
= "rk808-clkout", },
133 { .name
= "rk808-regulator", },
136 .num_resources
= ARRAY_SIZE(rtc_resources
),
137 .resources
= rtc_resources
,
141 static const struct rk808_reg_data rk805_pre_init_reg
[] = {
142 {RK805_BUCK1_CONFIG_REG
, RK805_BUCK1_2_ILMAX_MASK
,
143 RK805_BUCK1_2_ILMAX_4000MA
},
144 {RK805_BUCK2_CONFIG_REG
, RK805_BUCK1_2_ILMAX_MASK
,
145 RK805_BUCK1_2_ILMAX_4000MA
},
146 {RK805_BUCK3_CONFIG_REG
, RK805_BUCK3_4_ILMAX_MASK
,
147 RK805_BUCK3_ILMAX_3000MA
},
148 {RK805_BUCK4_CONFIG_REG
, RK805_BUCK3_4_ILMAX_MASK
,
149 RK805_BUCK4_ILMAX_3500MA
},
150 {RK805_BUCK4_CONFIG_REG
, BUCK_ILMIN_MASK
, BUCK_ILMIN_400MA
},
151 {RK805_THERMAL_REG
, TEMP_HOTDIE_MSK
, TEMP115C
},
154 static const struct rk808_reg_data rk806_pre_init_reg
[] = {
155 { RK806_GPIO_INT_CONFIG
, RK806_INT_POL_MSK
, RK806_INT_POL_L
},
156 { RK806_SYS_CFG3
, RK806_SLAVE_RESTART_FUN_MSK
, RK806_SLAVE_RESTART_FUN_EN
},
157 { RK806_SYS_OPTION
, RK806_SYS_ENB2_2M_MSK
, RK806_SYS_ENB2_2M_EN
},
160 static const struct rk808_reg_data rk808_pre_init_reg
[] = {
161 { RK808_BUCK3_CONFIG_REG
, BUCK_ILMIN_MASK
, BUCK_ILMIN_150MA
},
162 { RK808_BUCK4_CONFIG_REG
, BUCK_ILMIN_MASK
, BUCK_ILMIN_200MA
},
163 { RK808_BOOST_CONFIG_REG
, BOOST_ILMIN_MASK
, BOOST_ILMIN_100MA
},
164 { RK808_BUCK1_CONFIG_REG
, BUCK1_RATE_MASK
, BUCK_ILMIN_200MA
},
165 { RK808_BUCK2_CONFIG_REG
, BUCK2_RATE_MASK
, BUCK_ILMIN_200MA
},
166 { RK808_DCDC_UV_ACT_REG
, BUCK_UV_ACT_MASK
, BUCK_UV_ACT_DISABLE
},
167 { RK808_VB_MON_REG
, MASK_ALL
, VB_LO_ACT
|
171 static const struct rk808_reg_data rk816_pre_init_reg
[] = {
172 { RK818_BUCK1_CONFIG_REG
, RK817_RAMP_RATE_MASK
,
173 RK817_RAMP_RATE_12_5MV_PER_US
},
174 { RK818_BUCK2_CONFIG_REG
, RK817_RAMP_RATE_MASK
,
175 RK817_RAMP_RATE_12_5MV_PER_US
},
176 { RK818_BUCK4_CONFIG_REG
, BUCK_ILMIN_MASK
, BUCK_ILMIN_250MA
},
177 { RK808_THERMAL_REG
, TEMP_HOTDIE_MSK
, TEMP105C
},
178 { RK808_VB_MON_REG
, VBAT_LOW_VOL_MASK
| VBAT_LOW_ACT_MASK
,
179 RK808_VBAT_LOW_3V0
| EN_VABT_LOW_SHUT_DOWN
},
182 static const struct rk808_reg_data rk817_pre_init_reg
[] = {
183 {RK817_RTC_CTRL_REG
, RTC_STOP
, RTC_STOP
},
184 /* Codec specific registers */
185 { RK817_CODEC_DTOP_VUCTL
, MASK_ALL
, 0x03 },
186 { RK817_CODEC_DTOP_VUCTIME
, MASK_ALL
, 0x00 },
187 { RK817_CODEC_DTOP_LPT_SRST
, MASK_ALL
, 0x00 },
188 { RK817_CODEC_DTOP_DIGEN_CLKE
, MASK_ALL
, 0x00 },
189 /* from vendor driver, CODEC_AREF_RTCFG0 not defined in data sheet */
190 { RK817_CODEC_AREF_RTCFG0
, MASK_ALL
, 0x00 },
191 { RK817_CODEC_AREF_RTCFG1
, MASK_ALL
, 0x06 },
192 { RK817_CODEC_AADC_CFG0
, MASK_ALL
, 0xc8 },
193 /* from vendor driver, CODEC_AADC_CFG1 not defined in data sheet */
194 { RK817_CODEC_AADC_CFG1
, MASK_ALL
, 0x00 },
195 { RK817_CODEC_DADC_VOLL
, MASK_ALL
, 0x00 },
196 { RK817_CODEC_DADC_VOLR
, MASK_ALL
, 0x00 },
197 { RK817_CODEC_DADC_SR_ACL0
, MASK_ALL
, 0x00 },
198 { RK817_CODEC_DADC_ALC1
, MASK_ALL
, 0x00 },
199 { RK817_CODEC_DADC_ALC2
, MASK_ALL
, 0x00 },
200 { RK817_CODEC_DADC_NG
, MASK_ALL
, 0x00 },
201 { RK817_CODEC_DADC_HPF
, MASK_ALL
, 0x00 },
202 { RK817_CODEC_DADC_RVOLL
, MASK_ALL
, 0xff },
203 { RK817_CODEC_DADC_RVOLR
, MASK_ALL
, 0xff },
204 { RK817_CODEC_AMIC_CFG0
, MASK_ALL
, 0x70 },
205 { RK817_CODEC_AMIC_CFG1
, MASK_ALL
, 0x00 },
206 { RK817_CODEC_DMIC_PGA_GAIN
, MASK_ALL
, 0x66 },
207 { RK817_CODEC_DMIC_LMT1
, MASK_ALL
, 0x00 },
208 { RK817_CODEC_DMIC_LMT2
, MASK_ALL
, 0x00 },
209 { RK817_CODEC_DMIC_NG1
, MASK_ALL
, 0x00 },
210 { RK817_CODEC_DMIC_NG2
, MASK_ALL
, 0x00 },
211 /* from vendor driver, CODEC_ADAC_CFG0 not defined in data sheet */
212 { RK817_CODEC_ADAC_CFG0
, MASK_ALL
, 0x00 },
213 { RK817_CODEC_ADAC_CFG1
, MASK_ALL
, 0x07 },
214 { RK817_CODEC_DDAC_POPD_DACST
, MASK_ALL
, 0x82 },
215 { RK817_CODEC_DDAC_VOLL
, MASK_ALL
, 0x00 },
216 { RK817_CODEC_DDAC_VOLR
, MASK_ALL
, 0x00 },
217 { RK817_CODEC_DDAC_SR_LMT0
, MASK_ALL
, 0x00 },
218 { RK817_CODEC_DDAC_LMT1
, MASK_ALL
, 0x00 },
219 { RK817_CODEC_DDAC_LMT2
, MASK_ALL
, 0x00 },
220 { RK817_CODEC_DDAC_MUTE_MIXCTL
, MASK_ALL
, 0xa0 },
221 { RK817_CODEC_DDAC_RVOLL
, MASK_ALL
, 0xff },
222 { RK817_CODEC_DADC_RVOLR
, MASK_ALL
, 0xff },
223 { RK817_CODEC_AMIC_CFG0
, MASK_ALL
, 0x70 },
224 { RK817_CODEC_AMIC_CFG1
, MASK_ALL
, 0x00 },
225 { RK817_CODEC_DMIC_PGA_GAIN
, MASK_ALL
, 0x66 },
226 { RK817_CODEC_DMIC_LMT1
, MASK_ALL
, 0x00 },
227 { RK817_CODEC_DMIC_LMT2
, MASK_ALL
, 0x00 },
228 { RK817_CODEC_DMIC_NG1
, MASK_ALL
, 0x00 },
229 { RK817_CODEC_DMIC_NG2
, MASK_ALL
, 0x00 },
230 /* from vendor driver, CODEC_ADAC_CFG0 not defined in data sheet */
231 { RK817_CODEC_ADAC_CFG0
, MASK_ALL
, 0x00 },
232 { RK817_CODEC_ADAC_CFG1
, MASK_ALL
, 0x07 },
233 { RK817_CODEC_DDAC_POPD_DACST
, MASK_ALL
, 0x82 },
234 { RK817_CODEC_DDAC_VOLL
, MASK_ALL
, 0x00 },
235 { RK817_CODEC_DDAC_VOLR
, MASK_ALL
, 0x00 },
236 { RK817_CODEC_DDAC_SR_LMT0
, MASK_ALL
, 0x00 },
237 { RK817_CODEC_DDAC_LMT1
, MASK_ALL
, 0x00 },
238 { RK817_CODEC_DDAC_LMT2
, MASK_ALL
, 0x00 },
239 { RK817_CODEC_DDAC_MUTE_MIXCTL
, MASK_ALL
, 0xa0 },
240 { RK817_CODEC_DDAC_RVOLL
, MASK_ALL
, 0xff },
241 { RK817_CODEC_DDAC_RVOLR
, MASK_ALL
, 0xff },
242 { RK817_CODEC_AHP_ANTI0
, MASK_ALL
, 0x00 },
243 { RK817_CODEC_AHP_ANTI1
, MASK_ALL
, 0x00 },
244 { RK817_CODEC_AHP_CFG0
, MASK_ALL
, 0xe0 },
245 { RK817_CODEC_AHP_CFG1
, MASK_ALL
, 0x1f },
246 { RK817_CODEC_AHP_CP
, MASK_ALL
, 0x09 },
247 { RK817_CODEC_ACLASSD_CFG1
, MASK_ALL
, 0x69 },
248 { RK817_CODEC_ACLASSD_CFG2
, MASK_ALL
, 0x44 },
249 { RK817_CODEC_APLL_CFG0
, MASK_ALL
, 0x04 },
250 { RK817_CODEC_APLL_CFG1
, MASK_ALL
, 0x00 },
251 { RK817_CODEC_APLL_CFG2
, MASK_ALL
, 0x30 },
252 { RK817_CODEC_APLL_CFG3
, MASK_ALL
, 0x19 },
253 { RK817_CODEC_APLL_CFG4
, MASK_ALL
, 0x65 },
254 { RK817_CODEC_APLL_CFG5
, MASK_ALL
, 0x01 },
255 { RK817_CODEC_DI2S_CKM
, MASK_ALL
, 0x01 },
256 { RK817_CODEC_DI2S_RSD
, MASK_ALL
, 0x00 },
257 { RK817_CODEC_DI2S_RXCR1
, MASK_ALL
, 0x00 },
258 { RK817_CODEC_DI2S_RXCR2
, MASK_ALL
, 0x17 },
259 { RK817_CODEC_DI2S_RXCMD_TSD
, MASK_ALL
, 0x00 },
260 { RK817_CODEC_DI2S_TXCR1
, MASK_ALL
, 0x00 },
261 { RK817_CODEC_DI2S_TXCR2
, MASK_ALL
, 0x17 },
262 { RK817_CODEC_DI2S_TXCR3_TXCMD
, MASK_ALL
, 0x00 },
263 {RK817_GPIO_INT_CFG
, RK817_INT_POL_MSK
, RK817_INT_POL_L
},
264 {RK817_SYS_CFG(1), RK817_HOTDIE_TEMP_MSK
| RK817_TSD_TEMP_MSK
,
265 RK817_HOTDIE_105
| RK817_TSD_140
},
268 static const struct rk808_reg_data rk818_pre_init_reg
[] = {
269 /* improve efficiency */
270 { RK818_BUCK2_CONFIG_REG
, BUCK2_RATE_MASK
, BUCK_ILMIN_250MA
},
271 { RK818_BUCK4_CONFIG_REG
, BUCK_ILMIN_MASK
, BUCK_ILMIN_250MA
},
272 { RK818_BOOST_CONFIG_REG
, BOOST_ILMIN_MASK
, BOOST_ILMIN_100MA
},
273 { RK818_USB_CTRL_REG
, RK818_USB_ILIM_SEL_MASK
,
274 RK818_USB_ILMIN_2000MA
},
275 /* close charger when usb lower then 3.4V */
276 { RK818_USB_CTRL_REG
, RK818_USB_CHG_SD_VSEL_MASK
,
278 /* no action when vref */
279 { RK818_H5V_EN_REG
, BIT(1), RK818_REF_RDY_CTRL
},
281 { RK818_H5V_EN_REG
, BIT(0), RK818_H5V_EN
},
282 { RK808_VB_MON_REG
, MASK_ALL
, VB_LO_ACT
|
286 static const struct regmap_irq rk805_irqs
[] = {
287 [RK805_IRQ_PWRON_RISE
] = {
288 .mask
= RK805_IRQ_PWRON_RISE_MSK
,
291 [RK805_IRQ_VB_LOW
] = {
292 .mask
= RK805_IRQ_VB_LOW_MSK
,
295 [RK805_IRQ_PWRON
] = {
296 .mask
= RK805_IRQ_PWRON_MSK
,
299 [RK805_IRQ_PWRON_LP
] = {
300 .mask
= RK805_IRQ_PWRON_LP_MSK
,
303 [RK805_IRQ_HOTDIE
] = {
304 .mask
= RK805_IRQ_HOTDIE_MSK
,
307 [RK805_IRQ_RTC_ALARM
] = {
308 .mask
= RK805_IRQ_RTC_ALARM_MSK
,
311 [RK805_IRQ_RTC_PERIOD
] = {
312 .mask
= RK805_IRQ_RTC_PERIOD_MSK
,
315 [RK805_IRQ_PWRON_FALL
] = {
316 .mask
= RK805_IRQ_PWRON_FALL_MSK
,
321 static const struct regmap_irq rk806_irqs
[] = {
323 REGMAP_IRQ_REG(RK806_IRQ_PWRON_FALL
, 0, RK806_INT_STS_PWRON_FALL
),
324 REGMAP_IRQ_REG(RK806_IRQ_PWRON_RISE
, 0, RK806_INT_STS_PWRON_RISE
),
325 REGMAP_IRQ_REG(RK806_IRQ_PWRON
, 0, RK806_INT_STS_PWRON
),
326 REGMAP_IRQ_REG(RK806_IRQ_PWRON_LP
, 0, RK806_INT_STS_PWRON_LP
),
327 REGMAP_IRQ_REG(RK806_IRQ_HOTDIE
, 0, RK806_INT_STS_HOTDIE
),
328 REGMAP_IRQ_REG(RK806_IRQ_VDC_RISE
, 0, RK806_INT_STS_VDC_RISE
),
329 REGMAP_IRQ_REG(RK806_IRQ_VDC_FALL
, 0, RK806_INT_STS_VDC_FALL
),
330 REGMAP_IRQ_REG(RK806_IRQ_VB_LO
, 0, RK806_INT_STS_VB_LO
),
332 REGMAP_IRQ_REG(RK806_IRQ_REV0
, 1, RK806_INT_STS_REV0
),
333 REGMAP_IRQ_REG(RK806_IRQ_REV1
, 1, RK806_INT_STS_REV1
),
334 REGMAP_IRQ_REG(RK806_IRQ_REV2
, 1, RK806_INT_STS_REV2
),
335 REGMAP_IRQ_REG(RK806_IRQ_CRC_ERROR
, 1, RK806_INT_STS_CRC_ERROR
),
336 REGMAP_IRQ_REG(RK806_IRQ_SLP3_GPIO
, 1, RK806_INT_STS_SLP3_GPIO
),
337 REGMAP_IRQ_REG(RK806_IRQ_SLP2_GPIO
, 1, RK806_INT_STS_SLP2_GPIO
),
338 REGMAP_IRQ_REG(RK806_IRQ_SLP1_GPIO
, 1, RK806_INT_STS_SLP1_GPIO
),
339 REGMAP_IRQ_REG(RK806_IRQ_WDT
, 1, RK806_INT_STS_WDT
),
342 static const struct regmap_irq rk808_irqs
[] = {
344 [RK808_IRQ_VOUT_LO
] = {
345 .mask
= RK808_IRQ_VOUT_LO_MSK
,
348 [RK808_IRQ_VB_LO
] = {
349 .mask
= RK808_IRQ_VB_LO_MSK
,
352 [RK808_IRQ_PWRON
] = {
353 .mask
= RK808_IRQ_PWRON_MSK
,
356 [RK808_IRQ_PWRON_LP
] = {
357 .mask
= RK808_IRQ_PWRON_LP_MSK
,
360 [RK808_IRQ_HOTDIE
] = {
361 .mask
= RK808_IRQ_HOTDIE_MSK
,
364 [RK808_IRQ_RTC_ALARM
] = {
365 .mask
= RK808_IRQ_RTC_ALARM_MSK
,
368 [RK808_IRQ_RTC_PERIOD
] = {
369 .mask
= RK808_IRQ_RTC_PERIOD_MSK
,
374 [RK808_IRQ_PLUG_IN_INT
] = {
375 .mask
= RK808_IRQ_PLUG_IN_INT_MSK
,
378 [RK808_IRQ_PLUG_OUT_INT
] = {
379 .mask
= RK808_IRQ_PLUG_OUT_INT_MSK
,
384 static const unsigned int rk816_irq_status_offsets
[] = {
385 RK816_IRQ_STS_OFFSET(RK816_INT_STS_REG1
),
386 RK816_IRQ_STS_OFFSET(RK816_INT_STS_REG2
),
387 RK816_IRQ_STS_OFFSET(RK816_INT_STS_REG3
),
390 static const unsigned int rk816_irq_mask_offsets
[] = {
391 RK816_IRQ_MSK_OFFSET(RK816_INT_STS_MSK_REG1
),
392 RK816_IRQ_MSK_OFFSET(RK816_INT_STS_MSK_REG2
),
393 RK816_IRQ_MSK_OFFSET(RK816_INT_STS_MSK_REG3
),
396 static unsigned int rk816_get_irq_reg(struct regmap_irq_chip_data
*data
,
397 unsigned int base
, int index
)
399 unsigned int irq_reg
= base
;
402 case RK816_INT_STS_REG1
:
403 irq_reg
+= rk816_irq_status_offsets
[index
];
405 case RK816_INT_STS_MSK_REG1
:
406 irq_reg
+= rk816_irq_mask_offsets
[index
];
413 static const struct regmap_irq rk816_irqs
[] = {
414 /* INT_STS_REG1 IRQs */
415 REGMAP_IRQ_REG(RK816_IRQ_PWRON_FALL
, 0, RK816_INT_STS_PWRON_FALL
),
416 REGMAP_IRQ_REG(RK816_IRQ_PWRON_RISE
, 0, RK816_INT_STS_PWRON_RISE
),
418 /* INT_STS_REG2 IRQs */
419 REGMAP_IRQ_REG(RK816_IRQ_VB_LOW
, 1, RK816_INT_STS_VB_LOW
),
420 REGMAP_IRQ_REG(RK816_IRQ_PWRON
, 1, RK816_INT_STS_PWRON
),
421 REGMAP_IRQ_REG(RK816_IRQ_PWRON_LP
, 1, RK816_INT_STS_PWRON_LP
),
422 REGMAP_IRQ_REG(RK816_IRQ_HOTDIE
, 1, RK816_INT_STS_HOTDIE
),
423 REGMAP_IRQ_REG(RK816_IRQ_RTC_ALARM
, 1, RK816_INT_STS_RTC_ALARM
),
424 REGMAP_IRQ_REG(RK816_IRQ_RTC_PERIOD
, 1, RK816_INT_STS_RTC_PERIOD
),
425 REGMAP_IRQ_REG(RK816_IRQ_USB_OV
, 1, RK816_INT_STS_USB_OV
),
428 REGMAP_IRQ_REG(RK816_IRQ_PLUG_IN
, 2, RK816_INT_STS_PLUG_IN
),
429 REGMAP_IRQ_REG(RK816_IRQ_PLUG_OUT
, 2, RK816_INT_STS_PLUG_OUT
),
430 REGMAP_IRQ_REG(RK816_IRQ_CHG_OK
, 2, RK816_INT_STS_CHG_OK
),
431 REGMAP_IRQ_REG(RK816_IRQ_CHG_TE
, 2, RK816_INT_STS_CHG_TE
),
432 REGMAP_IRQ_REG(RK816_IRQ_CHG_TS
, 2, RK816_INT_STS_CHG_TS
),
433 REGMAP_IRQ_REG(RK816_IRQ_CHG_CVTLIM
, 2, RK816_INT_STS_CHG_CVTLIM
),
434 REGMAP_IRQ_REG(RK816_IRQ_DISCHG_ILIM
, 2, RK816_INT_STS_DISCHG_ILIM
),
437 static const struct regmap_irq rk818_irqs
[] = {
439 [RK818_IRQ_VOUT_LO
] = {
440 .mask
= RK818_IRQ_VOUT_LO_MSK
,
443 [RK818_IRQ_VB_LO
] = {
444 .mask
= RK818_IRQ_VB_LO_MSK
,
447 [RK818_IRQ_PWRON
] = {
448 .mask
= RK818_IRQ_PWRON_MSK
,
451 [RK818_IRQ_PWRON_LP
] = {
452 .mask
= RK818_IRQ_PWRON_LP_MSK
,
455 [RK818_IRQ_HOTDIE
] = {
456 .mask
= RK818_IRQ_HOTDIE_MSK
,
459 [RK818_IRQ_RTC_ALARM
] = {
460 .mask
= RK818_IRQ_RTC_ALARM_MSK
,
463 [RK818_IRQ_RTC_PERIOD
] = {
464 .mask
= RK818_IRQ_RTC_PERIOD_MSK
,
467 [RK818_IRQ_USB_OV
] = {
468 .mask
= RK818_IRQ_USB_OV_MSK
,
473 [RK818_IRQ_PLUG_IN
] = {
474 .mask
= RK818_IRQ_PLUG_IN_MSK
,
477 [RK818_IRQ_PLUG_OUT
] = {
478 .mask
= RK818_IRQ_PLUG_OUT_MSK
,
481 [RK818_IRQ_CHG_OK
] = {
482 .mask
= RK818_IRQ_CHG_OK_MSK
,
485 [RK818_IRQ_CHG_TE
] = {
486 .mask
= RK818_IRQ_CHG_TE_MSK
,
489 [RK818_IRQ_CHG_TS1
] = {
490 .mask
= RK818_IRQ_CHG_TS1_MSK
,
494 .mask
= RK818_IRQ_TS2_MSK
,
497 [RK818_IRQ_CHG_CVTLIM
] = {
498 .mask
= RK818_IRQ_CHG_CVTLIM_MSK
,
501 [RK818_IRQ_DISCHG_ILIM
] = {
502 .mask
= RK818_IRQ_DISCHG_ILIM_MSK
,
507 static const struct regmap_irq rk817_irqs
[RK817_IRQ_END
] = {
508 REGMAP_IRQ_REG_LINE(0, 8),
509 REGMAP_IRQ_REG_LINE(1, 8),
510 REGMAP_IRQ_REG_LINE(2, 8),
511 REGMAP_IRQ_REG_LINE(3, 8),
512 REGMAP_IRQ_REG_LINE(4, 8),
513 REGMAP_IRQ_REG_LINE(5, 8),
514 REGMAP_IRQ_REG_LINE(6, 8),
515 REGMAP_IRQ_REG_LINE(7, 8),
516 REGMAP_IRQ_REG_LINE(8, 8),
517 REGMAP_IRQ_REG_LINE(9, 8),
518 REGMAP_IRQ_REG_LINE(10, 8),
519 REGMAP_IRQ_REG_LINE(11, 8),
520 REGMAP_IRQ_REG_LINE(12, 8),
521 REGMAP_IRQ_REG_LINE(13, 8),
522 REGMAP_IRQ_REG_LINE(14, 8),
523 REGMAP_IRQ_REG_LINE(15, 8),
524 REGMAP_IRQ_REG_LINE(16, 8),
525 REGMAP_IRQ_REG_LINE(17, 8),
526 REGMAP_IRQ_REG_LINE(18, 8),
527 REGMAP_IRQ_REG_LINE(19, 8),
528 REGMAP_IRQ_REG_LINE(20, 8),
529 REGMAP_IRQ_REG_LINE(21, 8),
530 REGMAP_IRQ_REG_LINE(22, 8),
531 REGMAP_IRQ_REG_LINE(23, 8)
534 static const struct regmap_irq_chip rk805_irq_chip
= {
537 .num_irqs
= ARRAY_SIZE(rk805_irqs
),
539 .status_base
= RK805_INT_STS_REG
,
540 .mask_base
= RK805_INT_STS_MSK_REG
,
541 .ack_base
= RK805_INT_STS_REG
,
542 .init_ack_masked
= true,
545 static const struct regmap_irq_chip rk806_irq_chip
= {
548 .num_irqs
= ARRAY_SIZE(rk806_irqs
),
551 .mask_base
= RK806_INT_MSK0
,
552 .status_base
= RK806_INT_STS0
,
553 .ack_base
= RK806_INT_STS0
,
554 .init_ack_masked
= true,
557 static const struct regmap_irq_chip rk808_irq_chip
= {
560 .num_irqs
= ARRAY_SIZE(rk808_irqs
),
563 .status_base
= RK808_INT_STS_REG1
,
564 .mask_base
= RK808_INT_STS_MSK_REG1
,
565 .ack_base
= RK808_INT_STS_REG1
,
566 .init_ack_masked
= true,
569 static const struct regmap_irq_chip rk816_irq_chip
= {
572 .num_irqs
= ARRAY_SIZE(rk816_irqs
),
574 .get_irq_reg
= rk816_get_irq_reg
,
575 .status_base
= RK816_INT_STS_REG1
,
576 .mask_base
= RK816_INT_STS_MSK_REG1
,
577 .ack_base
= RK816_INT_STS_REG1
,
578 .init_ack_masked
= true,
581 static const struct regmap_irq_chip rk817_irq_chip
= {
584 .num_irqs
= ARRAY_SIZE(rk817_irqs
),
587 .status_base
= RK817_INT_STS_REG0
,
588 .mask_base
= RK817_INT_STS_MSK_REG0
,
589 .ack_base
= RK817_INT_STS_REG0
,
590 .init_ack_masked
= true,
593 static const struct regmap_irq_chip rk818_irq_chip
= {
596 .num_irqs
= ARRAY_SIZE(rk818_irqs
),
599 .status_base
= RK818_INT_STS_REG1
,
600 .mask_base
= RK818_INT_STS_MSK_REG1
,
601 .ack_base
= RK818_INT_STS_REG1
,
602 .init_ack_masked
= true,
605 static int rk808_power_off(struct sys_off_data
*data
)
607 struct rk808
*rk808
= data
->cb_data
;
609 unsigned int reg
, bit
;
611 switch (rk808
->variant
) {
613 reg
= RK805_DEV_CTRL_REG
;
617 reg
= RK806_SYS_CFG3
;
621 reg
= RK808_DEVCTRL_REG
;
626 reg
= RK817_SYS_CFG(3);
631 reg
= RK818_DEVCTRL_REG
;
637 ret
= regmap_update_bits(rk808
->regmap
, reg
, bit
, bit
);
639 dev_err(rk808
->dev
, "Failed to shutdown device!\n");
644 static int rk808_restart(struct sys_off_data
*data
)
646 struct rk808
*rk808
= data
->cb_data
;
647 unsigned int reg
, bit
;
650 switch (rk808
->variant
) {
653 reg
= RK817_SYS_CFG(3);
660 ret
= regmap_update_bits(rk808
->regmap
, reg
, bit
, bit
);
662 dev_err(rk808
->dev
, "Failed to restart device!\n");
667 void rk8xx_shutdown(struct device
*dev
)
669 struct rk808
*rk808
= dev_get_drvdata(dev
);
672 switch (rk808
->variant
) {
674 ret
= regmap_update_bits(rk808
->regmap
,
675 RK805_GPIO_IO_POL_REG
,
681 ret
= regmap_update_bits(rk808
->regmap
,
683 RK817_SLPPIN_FUNC_MSK
,
691 "Cannot switch to power down function\n");
693 EXPORT_SYMBOL_GPL(rk8xx_shutdown
);
695 int rk8xx_probe(struct device
*dev
, int variant
, unsigned int irq
, struct regmap
*regmap
)
698 const struct rk808_reg_data
*pre_init_reg
;
699 const struct mfd_cell
*cells
;
700 int dual_support
= 0;
701 int nr_pre_init_regs
;
706 rk808
= devm_kzalloc(dev
, sizeof(*rk808
), GFP_KERNEL
);
710 rk808
->variant
= variant
;
711 rk808
->regmap
= regmap
;
712 dev_set_drvdata(dev
, rk808
);
714 switch (rk808
->variant
) {
716 rk808
->regmap_irq_chip
= &rk805_irq_chip
;
717 pre_init_reg
= rk805_pre_init_reg
;
718 nr_pre_init_regs
= ARRAY_SIZE(rk805_pre_init_reg
);
720 nr_cells
= ARRAY_SIZE(rk805s
);
723 rk808
->regmap_irq_chip
= &rk806_irq_chip
;
724 pre_init_reg
= rk806_pre_init_reg
;
725 nr_pre_init_regs
= ARRAY_SIZE(rk806_pre_init_reg
);
727 nr_cells
= ARRAY_SIZE(rk806s
);
728 dual_support
= IRQF_SHARED
;
731 rk808
->regmap_irq_chip
= &rk808_irq_chip
;
732 pre_init_reg
= rk808_pre_init_reg
;
733 nr_pre_init_regs
= ARRAY_SIZE(rk808_pre_init_reg
);
735 nr_cells
= ARRAY_SIZE(rk808s
);
738 rk808
->regmap_irq_chip
= &rk816_irq_chip
;
739 pre_init_reg
= rk816_pre_init_reg
;
740 nr_pre_init_regs
= ARRAY_SIZE(rk816_pre_init_reg
);
742 nr_cells
= ARRAY_SIZE(rk816s
);
745 rk808
->regmap_irq_chip
= &rk818_irq_chip
;
746 pre_init_reg
= rk818_pre_init_reg
;
747 nr_pre_init_regs
= ARRAY_SIZE(rk818_pre_init_reg
);
749 nr_cells
= ARRAY_SIZE(rk818s
);
753 rk808
->regmap_irq_chip
= &rk817_irq_chip
;
754 pre_init_reg
= rk817_pre_init_reg
;
755 nr_pre_init_regs
= ARRAY_SIZE(rk817_pre_init_reg
);
757 nr_cells
= ARRAY_SIZE(rk817s
);
760 dev_err(dev
, "Unsupported RK8XX ID %lu\n", rk808
->variant
);
765 return dev_err_probe(dev
, -EINVAL
, "No interrupt support, no core IRQ\n");
767 ret
= devm_regmap_add_irq_chip(dev
, rk808
->regmap
, irq
,
768 IRQF_ONESHOT
| dual_support
, -1,
769 rk808
->regmap_irq_chip
, &rk808
->irq_data
);
771 return dev_err_probe(dev
, ret
, "Failed to add irq_chip\n");
773 for (i
= 0; i
< nr_pre_init_regs
; i
++) {
774 ret
= regmap_update_bits(rk808
->regmap
,
775 pre_init_reg
[i
].addr
,
776 pre_init_reg
[i
].mask
,
777 pre_init_reg
[i
].value
);
779 return dev_err_probe(dev
, ret
, "0x%x write err\n",
780 pre_init_reg
[i
].addr
);
783 ret
= devm_mfd_add_devices(dev
, PLATFORM_DEVID_AUTO
, cells
, nr_cells
, NULL
, 0,
784 regmap_irq_get_domain(rk808
->irq_data
));
786 return dev_err_probe(dev
, ret
, "failed to add MFD devices\n");
788 if (device_property_read_bool(dev
, "system-power-controller") ||
789 device_property_read_bool(dev
, "rockchip,system-power-controller")) {
790 ret
= devm_register_sys_off_handler(dev
,
791 SYS_OFF_MODE_POWER_OFF_PREPARE
, SYS_OFF_PRIO_HIGH
,
792 &rk808_power_off
, rk808
);
794 return dev_err_probe(dev
, ret
,
795 "failed to register poweroff handler\n");
797 switch (rk808
->variant
) {
800 ret
= devm_register_sys_off_handler(dev
,
801 SYS_OFF_MODE_RESTART
, SYS_OFF_PRIO_HIGH
,
802 &rk808_restart
, rk808
);
804 dev_warn(dev
, "failed to register rst handler, %d\n", ret
);
807 dev_dbg(dev
, "pmic controlled board reset not supported\n");
814 EXPORT_SYMBOL_GPL(rk8xx_probe
);
816 int rk8xx_suspend(struct device
*dev
)
818 struct rk808
*rk808
= dev_get_drvdata(dev
);
821 switch (rk808
->variant
) {
823 ret
= regmap_update_bits(rk808
->regmap
,
824 RK805_GPIO_IO_POL_REG
,
830 ret
= regmap_update_bits(rk808
->regmap
,
832 RK817_SLPPIN_FUNC_MSK
,
841 EXPORT_SYMBOL_GPL(rk8xx_suspend
);
843 int rk8xx_resume(struct device
*dev
)
845 struct rk808
*rk808
= dev_get_drvdata(dev
);
848 switch (rk808
->variant
) {
851 ret
= regmap_update_bits(rk808
->regmap
,
853 RK817_SLPPIN_FUNC_MSK
,
862 EXPORT_SYMBOL_GPL(rk8xx_resume
);
864 MODULE_LICENSE("GPL");
865 MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
866 MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>");
867 MODULE_AUTHOR("Wadim Egorov <w.egorov@phytec.de>");
868 MODULE_DESCRIPTION("RK8xx PMIC core");