xref: /openbmc/linux/drivers/mfd/rk8xx-core.c (revision 3c90b3b0)
1c20e8c5bSSebastian Reichel // SPDX-License-Identifier: GPL-2.0-only
2c20e8c5bSSebastian Reichel /*
3c20e8c5bSSebastian Reichel  * MFD core driver for Rockchip RK8XX
4c20e8c5bSSebastian Reichel  *
5c20e8c5bSSebastian Reichel  * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
6c20e8c5bSSebastian Reichel  * Copyright (C) 2016 PHYTEC Messtechnik GmbH
7c20e8c5bSSebastian Reichel  *
8c20e8c5bSSebastian Reichel  * Author: Chris Zhong <zyw@rock-chips.com>
9c20e8c5bSSebastian Reichel  * Author: Zhang Qing <zhangqing@rock-chips.com>
10c20e8c5bSSebastian Reichel  * Author: Wadim Egorov <w.egorov@phytec.de>
11c20e8c5bSSebastian Reichel  */
12c20e8c5bSSebastian Reichel 
13c20e8c5bSSebastian Reichel #include <linux/interrupt.h>
14c20e8c5bSSebastian Reichel #include <linux/mfd/rk808.h>
15c20e8c5bSSebastian Reichel #include <linux/mfd/core.h>
16c20e8c5bSSebastian Reichel #include <linux/module.h>
17dc0c386eSRob Herring #include <linux/property.h>
18c20e8c5bSSebastian Reichel #include <linux/regmap.h>
19c20e8c5bSSebastian Reichel #include <linux/reboot.h>
20c20e8c5bSSebastian Reichel 
21c20e8c5bSSebastian Reichel struct rk808_reg_data {
22c20e8c5bSSebastian Reichel 	int addr;
23c20e8c5bSSebastian Reichel 	int mask;
24c20e8c5bSSebastian Reichel 	int value;
25c20e8c5bSSebastian Reichel };
26c20e8c5bSSebastian Reichel 
27c20e8c5bSSebastian Reichel static const struct resource rtc_resources[] = {
28c20e8c5bSSebastian Reichel 	DEFINE_RES_IRQ(RK808_IRQ_RTC_ALARM),
29c20e8c5bSSebastian Reichel };
30c20e8c5bSSebastian Reichel 
31c20e8c5bSSebastian Reichel static const struct resource rk817_rtc_resources[] = {
32c20e8c5bSSebastian Reichel 	DEFINE_RES_IRQ(RK817_IRQ_RTC_ALARM),
33c20e8c5bSSebastian Reichel };
34c20e8c5bSSebastian Reichel 
35c20e8c5bSSebastian Reichel static const struct resource rk805_key_resources[] = {
36c20e8c5bSSebastian Reichel 	DEFINE_RES_IRQ(RK805_IRQ_PWRON_RISE),
37c20e8c5bSSebastian Reichel 	DEFINE_RES_IRQ(RK805_IRQ_PWRON_FALL),
38c20e8c5bSSebastian Reichel };
39c20e8c5bSSebastian Reichel 
40210f418fSSebastian Reichel static struct resource rk806_pwrkey_resources[] = {
41210f418fSSebastian Reichel 	DEFINE_RES_IRQ(RK806_IRQ_PWRON_FALL),
42210f418fSSebastian Reichel 	DEFINE_RES_IRQ(RK806_IRQ_PWRON_RISE),
43210f418fSSebastian Reichel };
44210f418fSSebastian Reichel 
45c20e8c5bSSebastian Reichel static const struct resource rk817_pwrkey_resources[] = {
46c20e8c5bSSebastian Reichel 	DEFINE_RES_IRQ(RK817_IRQ_PWRON_RISE),
47c20e8c5bSSebastian Reichel 	DEFINE_RES_IRQ(RK817_IRQ_PWRON_FALL),
48c20e8c5bSSebastian Reichel };
49c20e8c5bSSebastian Reichel 
50c20e8c5bSSebastian Reichel static const struct resource rk817_charger_resources[] = {
51c20e8c5bSSebastian Reichel 	DEFINE_RES_IRQ(RK817_IRQ_PLUG_IN),
52c20e8c5bSSebastian Reichel 	DEFINE_RES_IRQ(RK817_IRQ_PLUG_OUT),
53c20e8c5bSSebastian Reichel };
54c20e8c5bSSebastian Reichel 
55c20e8c5bSSebastian Reichel static const struct mfd_cell rk805s[] = {
56*3c90b3b0SNeil Armstrong 	{ .name = "rk808-clkout", },
57*3c90b3b0SNeil Armstrong 	{ .name = "rk808-regulator", },
58*3c90b3b0SNeil Armstrong 	{ .name = "rk805-pinctrl", },
59c20e8c5bSSebastian Reichel 	{
60c20e8c5bSSebastian Reichel 		.name = "rk808-rtc",
61c20e8c5bSSebastian Reichel 		.num_resources = ARRAY_SIZE(rtc_resources),
62c20e8c5bSSebastian Reichel 		.resources = &rtc_resources[0],
63c20e8c5bSSebastian Reichel 	},
64c20e8c5bSSebastian Reichel 	{	.name = "rk805-pwrkey",
65c20e8c5bSSebastian Reichel 		.num_resources = ARRAY_SIZE(rk805_key_resources),
66c20e8c5bSSebastian Reichel 		.resources = &rk805_key_resources[0],
67c20e8c5bSSebastian Reichel 	},
68c20e8c5bSSebastian Reichel };
69c20e8c5bSSebastian Reichel 
70210f418fSSebastian Reichel static const struct mfd_cell rk806s[] = {
71*3c90b3b0SNeil Armstrong 	{ .name = "rk805-pinctrl", },
72*3c90b3b0SNeil Armstrong 	{ .name = "rk808-regulator", },
73210f418fSSebastian Reichel 	{
74210f418fSSebastian Reichel 		.name = "rk805-pwrkey",
75210f418fSSebastian Reichel 		.resources = rk806_pwrkey_resources,
76210f418fSSebastian Reichel 		.num_resources = ARRAY_SIZE(rk806_pwrkey_resources),
77210f418fSSebastian Reichel 	},
78210f418fSSebastian Reichel };
79210f418fSSebastian Reichel 
80c20e8c5bSSebastian Reichel static const struct mfd_cell rk808s[] = {
81*3c90b3b0SNeil Armstrong 	{ .name = "rk808-clkout", },
82*3c90b3b0SNeil Armstrong 	{ .name = "rk808-regulator", },
83c20e8c5bSSebastian Reichel 	{
84c20e8c5bSSebastian Reichel 		.name = "rk808-rtc",
85c20e8c5bSSebastian Reichel 		.num_resources = ARRAY_SIZE(rtc_resources),
86c20e8c5bSSebastian Reichel 		.resources = rtc_resources,
87c20e8c5bSSebastian Reichel 	},
88c20e8c5bSSebastian Reichel };
89c20e8c5bSSebastian Reichel 
90c20e8c5bSSebastian Reichel static const struct mfd_cell rk817s[] = {
91*3c90b3b0SNeil Armstrong 	{ .name = "rk808-clkout", },
92*3c90b3b0SNeil Armstrong 	{ .name = "rk808-regulator", },
93c20e8c5bSSebastian Reichel 	{
94c20e8c5bSSebastian Reichel 		.name = "rk805-pwrkey",
95c20e8c5bSSebastian Reichel 		.num_resources = ARRAY_SIZE(rk817_pwrkey_resources),
96c20e8c5bSSebastian Reichel 		.resources = &rk817_pwrkey_resources[0],
97c20e8c5bSSebastian Reichel 	},
98c20e8c5bSSebastian Reichel 	{
99c20e8c5bSSebastian Reichel 		.name = "rk808-rtc",
100c20e8c5bSSebastian Reichel 		.num_resources = ARRAY_SIZE(rk817_rtc_resources),
101c20e8c5bSSebastian Reichel 		.resources = &rk817_rtc_resources[0],
102c20e8c5bSSebastian Reichel 	},
103*3c90b3b0SNeil Armstrong 	{ .name = "rk817-codec", },
104c20e8c5bSSebastian Reichel 	{
105c20e8c5bSSebastian Reichel 		.name = "rk817-charger",
106c20e8c5bSSebastian Reichel 		.num_resources = ARRAY_SIZE(rk817_charger_resources),
107c20e8c5bSSebastian Reichel 		.resources = &rk817_charger_resources[0],
108c20e8c5bSSebastian Reichel 	},
109c20e8c5bSSebastian Reichel };
110c20e8c5bSSebastian Reichel 
111c20e8c5bSSebastian Reichel static const struct mfd_cell rk818s[] = {
112*3c90b3b0SNeil Armstrong 	{ .name = "rk808-clkout", },
113*3c90b3b0SNeil Armstrong 	{ .name = "rk808-regulator", },
114c20e8c5bSSebastian Reichel 	{
115c20e8c5bSSebastian Reichel 		.name = "rk808-rtc",
116c20e8c5bSSebastian Reichel 		.num_resources = ARRAY_SIZE(rtc_resources),
117c20e8c5bSSebastian Reichel 		.resources = rtc_resources,
118c20e8c5bSSebastian Reichel 	},
119c20e8c5bSSebastian Reichel };
120c20e8c5bSSebastian Reichel 
121c20e8c5bSSebastian Reichel static const struct rk808_reg_data rk805_pre_init_reg[] = {
122c20e8c5bSSebastian Reichel 	{RK805_BUCK1_CONFIG_REG, RK805_BUCK1_2_ILMAX_MASK,
123c20e8c5bSSebastian Reichel 				 RK805_BUCK1_2_ILMAX_4000MA},
124c20e8c5bSSebastian Reichel 	{RK805_BUCK2_CONFIG_REG, RK805_BUCK1_2_ILMAX_MASK,
125c20e8c5bSSebastian Reichel 				 RK805_BUCK1_2_ILMAX_4000MA},
126c20e8c5bSSebastian Reichel 	{RK805_BUCK3_CONFIG_REG, RK805_BUCK3_4_ILMAX_MASK,
127c20e8c5bSSebastian Reichel 				 RK805_BUCK3_ILMAX_3000MA},
128c20e8c5bSSebastian Reichel 	{RK805_BUCK4_CONFIG_REG, RK805_BUCK3_4_ILMAX_MASK,
129c20e8c5bSSebastian Reichel 				 RK805_BUCK4_ILMAX_3500MA},
130c20e8c5bSSebastian Reichel 	{RK805_BUCK4_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_400MA},
131c20e8c5bSSebastian Reichel 	{RK805_THERMAL_REG, TEMP_HOTDIE_MSK, TEMP115C},
132c20e8c5bSSebastian Reichel };
133c20e8c5bSSebastian Reichel 
134210f418fSSebastian Reichel static const struct rk808_reg_data rk806_pre_init_reg[] = {
135210f418fSSebastian Reichel 	{ RK806_GPIO_INT_CONFIG, RK806_INT_POL_MSK, RK806_INT_POL_L },
136210f418fSSebastian Reichel 	{ RK806_SYS_CFG3, RK806_SLAVE_RESTART_FUN_MSK, RK806_SLAVE_RESTART_FUN_EN },
137210f418fSSebastian Reichel 	{ RK806_SYS_OPTION, RK806_SYS_ENB2_2M_MSK, RK806_SYS_ENB2_2M_EN },
138210f418fSSebastian Reichel };
139210f418fSSebastian Reichel 
140c20e8c5bSSebastian Reichel static const struct rk808_reg_data rk808_pre_init_reg[] = {
141c20e8c5bSSebastian Reichel 	{ RK808_BUCK3_CONFIG_REG, BUCK_ILMIN_MASK,  BUCK_ILMIN_150MA },
142c20e8c5bSSebastian Reichel 	{ RK808_BUCK4_CONFIG_REG, BUCK_ILMIN_MASK,  BUCK_ILMIN_200MA },
143c20e8c5bSSebastian Reichel 	{ RK808_BOOST_CONFIG_REG, BOOST_ILMIN_MASK, BOOST_ILMIN_100MA },
144c20e8c5bSSebastian Reichel 	{ RK808_BUCK1_CONFIG_REG, BUCK1_RATE_MASK,  BUCK_ILMIN_200MA },
145c20e8c5bSSebastian Reichel 	{ RK808_BUCK2_CONFIG_REG, BUCK2_RATE_MASK,  BUCK_ILMIN_200MA },
146c20e8c5bSSebastian Reichel 	{ RK808_DCDC_UV_ACT_REG,  BUCK_UV_ACT_MASK, BUCK_UV_ACT_DISABLE},
147c20e8c5bSSebastian Reichel 	{ RK808_VB_MON_REG,       MASK_ALL,         VB_LO_ACT |
148c20e8c5bSSebastian Reichel 						    VB_LO_SEL_3500MV },
149c20e8c5bSSebastian Reichel };
150c20e8c5bSSebastian Reichel 
151c20e8c5bSSebastian Reichel static const struct rk808_reg_data rk817_pre_init_reg[] = {
152c20e8c5bSSebastian Reichel 	{RK817_RTC_CTRL_REG, RTC_STOP, RTC_STOP},
153c20e8c5bSSebastian Reichel 	/* Codec specific registers */
154c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DTOP_VUCTL, MASK_ALL, 0x03 },
155c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DTOP_VUCTIME, MASK_ALL, 0x00 },
156c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DTOP_LPT_SRST, MASK_ALL, 0x00 },
157c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DTOP_DIGEN_CLKE, MASK_ALL, 0x00 },
158c20e8c5bSSebastian Reichel 	/* from vendor driver, CODEC_AREF_RTCFG0 not defined in data sheet */
159c20e8c5bSSebastian Reichel 	{ RK817_CODEC_AREF_RTCFG0, MASK_ALL, 0x00 },
160c20e8c5bSSebastian Reichel 	{ RK817_CODEC_AREF_RTCFG1, MASK_ALL, 0x06 },
161c20e8c5bSSebastian Reichel 	{ RK817_CODEC_AADC_CFG0, MASK_ALL, 0xc8 },
162c20e8c5bSSebastian Reichel 	/* from vendor driver, CODEC_AADC_CFG1 not defined in data sheet */
163c20e8c5bSSebastian Reichel 	{ RK817_CODEC_AADC_CFG1, MASK_ALL, 0x00 },
164c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DADC_VOLL, MASK_ALL, 0x00 },
165c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DADC_VOLR, MASK_ALL, 0x00 },
166c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DADC_SR_ACL0, MASK_ALL, 0x00 },
167c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DADC_ALC1, MASK_ALL, 0x00 },
168c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DADC_ALC2, MASK_ALL, 0x00 },
169c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DADC_NG, MASK_ALL, 0x00 },
170c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DADC_HPF, MASK_ALL, 0x00 },
171c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DADC_RVOLL, MASK_ALL, 0xff },
172c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DADC_RVOLR, MASK_ALL, 0xff },
173c20e8c5bSSebastian Reichel 	{ RK817_CODEC_AMIC_CFG0, MASK_ALL, 0x70 },
174c20e8c5bSSebastian Reichel 	{ RK817_CODEC_AMIC_CFG1, MASK_ALL, 0x00 },
175c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DMIC_PGA_GAIN, MASK_ALL, 0x66 },
176c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DMIC_LMT1, MASK_ALL, 0x00 },
177c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DMIC_LMT2, MASK_ALL, 0x00 },
178c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DMIC_NG1, MASK_ALL, 0x00 },
179c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DMIC_NG2, MASK_ALL, 0x00 },
180c20e8c5bSSebastian Reichel 	/* from vendor driver, CODEC_ADAC_CFG0 not defined in data sheet */
181c20e8c5bSSebastian Reichel 	{ RK817_CODEC_ADAC_CFG0, MASK_ALL, 0x00 },
182c20e8c5bSSebastian Reichel 	{ RK817_CODEC_ADAC_CFG1, MASK_ALL, 0x07 },
183c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_POPD_DACST, MASK_ALL, 0x82 },
184c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_VOLL, MASK_ALL, 0x00 },
185c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_VOLR, MASK_ALL, 0x00 },
186c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_SR_LMT0, MASK_ALL, 0x00 },
187c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_LMT1, MASK_ALL, 0x00 },
188c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_LMT2, MASK_ALL, 0x00 },
189c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_MUTE_MIXCTL, MASK_ALL, 0xa0 },
190c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_RVOLL, MASK_ALL, 0xff },
191c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DADC_RVOLR, MASK_ALL, 0xff },
192c20e8c5bSSebastian Reichel 	{ RK817_CODEC_AMIC_CFG0, MASK_ALL, 0x70 },
193c20e8c5bSSebastian Reichel 	{ RK817_CODEC_AMIC_CFG1, MASK_ALL, 0x00 },
194c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DMIC_PGA_GAIN, MASK_ALL, 0x66 },
195c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DMIC_LMT1, MASK_ALL, 0x00 },
196c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DMIC_LMT2, MASK_ALL, 0x00 },
197c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DMIC_NG1, MASK_ALL, 0x00 },
198c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DMIC_NG2, MASK_ALL, 0x00 },
199c20e8c5bSSebastian Reichel 	/* from vendor driver, CODEC_ADAC_CFG0 not defined in data sheet */
200c20e8c5bSSebastian Reichel 	{ RK817_CODEC_ADAC_CFG0, MASK_ALL, 0x00 },
201c20e8c5bSSebastian Reichel 	{ RK817_CODEC_ADAC_CFG1, MASK_ALL, 0x07 },
202c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_POPD_DACST, MASK_ALL, 0x82 },
203c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_VOLL, MASK_ALL, 0x00 },
204c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_VOLR, MASK_ALL, 0x00 },
205c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_SR_LMT0, MASK_ALL, 0x00 },
206c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_LMT1, MASK_ALL, 0x00 },
207c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_LMT2, MASK_ALL, 0x00 },
208c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_MUTE_MIXCTL, MASK_ALL, 0xa0 },
209c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_RVOLL, MASK_ALL, 0xff },
210c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DDAC_RVOLR, MASK_ALL, 0xff },
211c20e8c5bSSebastian Reichel 	{ RK817_CODEC_AHP_ANTI0, MASK_ALL, 0x00 },
212c20e8c5bSSebastian Reichel 	{ RK817_CODEC_AHP_ANTI1, MASK_ALL, 0x00 },
213c20e8c5bSSebastian Reichel 	{ RK817_CODEC_AHP_CFG0, MASK_ALL, 0xe0 },
214c20e8c5bSSebastian Reichel 	{ RK817_CODEC_AHP_CFG1, MASK_ALL, 0x1f },
215c20e8c5bSSebastian Reichel 	{ RK817_CODEC_AHP_CP, MASK_ALL, 0x09 },
216c20e8c5bSSebastian Reichel 	{ RK817_CODEC_ACLASSD_CFG1, MASK_ALL, 0x69 },
217c20e8c5bSSebastian Reichel 	{ RK817_CODEC_ACLASSD_CFG2, MASK_ALL, 0x44 },
218c20e8c5bSSebastian Reichel 	{ RK817_CODEC_APLL_CFG0, MASK_ALL, 0x04 },
219c20e8c5bSSebastian Reichel 	{ RK817_CODEC_APLL_CFG1, MASK_ALL, 0x00 },
220c20e8c5bSSebastian Reichel 	{ RK817_CODEC_APLL_CFG2, MASK_ALL, 0x30 },
221c20e8c5bSSebastian Reichel 	{ RK817_CODEC_APLL_CFG3, MASK_ALL, 0x19 },
222c20e8c5bSSebastian Reichel 	{ RK817_CODEC_APLL_CFG4, MASK_ALL, 0x65 },
223c20e8c5bSSebastian Reichel 	{ RK817_CODEC_APLL_CFG5, MASK_ALL, 0x01 },
224c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DI2S_CKM, MASK_ALL, 0x01 },
225c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DI2S_RSD, MASK_ALL, 0x00 },
226c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DI2S_RXCR1, MASK_ALL, 0x00 },
227c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DI2S_RXCR2, MASK_ALL, 0x17 },
228c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DI2S_RXCMD_TSD, MASK_ALL, 0x00 },
229c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DI2S_TXCR1, MASK_ALL, 0x00 },
230c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DI2S_TXCR2, MASK_ALL, 0x17 },
231c20e8c5bSSebastian Reichel 	{ RK817_CODEC_DI2S_TXCR3_TXCMD, MASK_ALL, 0x00 },
232c20e8c5bSSebastian Reichel 	{RK817_GPIO_INT_CFG, RK817_INT_POL_MSK, RK817_INT_POL_L},
233c20e8c5bSSebastian Reichel 	{RK817_SYS_CFG(1), RK817_HOTDIE_TEMP_MSK | RK817_TSD_TEMP_MSK,
234c20e8c5bSSebastian Reichel 					   RK817_HOTDIE_105 | RK817_TSD_140},
235c20e8c5bSSebastian Reichel };
236c20e8c5bSSebastian Reichel 
237c20e8c5bSSebastian Reichel static const struct rk808_reg_data rk818_pre_init_reg[] = {
238c20e8c5bSSebastian Reichel 	/* improve efficiency */
239c20e8c5bSSebastian Reichel 	{ RK818_BUCK2_CONFIG_REG, BUCK2_RATE_MASK,  BUCK_ILMIN_250MA },
240c20e8c5bSSebastian Reichel 	{ RK818_BUCK4_CONFIG_REG, BUCK_ILMIN_MASK,  BUCK_ILMIN_250MA },
241c20e8c5bSSebastian Reichel 	{ RK818_BOOST_CONFIG_REG, BOOST_ILMIN_MASK, BOOST_ILMIN_100MA },
242c20e8c5bSSebastian Reichel 	{ RK818_USB_CTRL_REG,	  RK818_USB_ILIM_SEL_MASK,
243c20e8c5bSSebastian Reichel 						    RK818_USB_ILMIN_2000MA },
244c20e8c5bSSebastian Reichel 	/* close charger when usb lower then 3.4V */
245c20e8c5bSSebastian Reichel 	{ RK818_USB_CTRL_REG,	  RK818_USB_CHG_SD_VSEL_MASK,
246c20e8c5bSSebastian Reichel 						    (0x7 << 4) },
247c20e8c5bSSebastian Reichel 	/* no action when vref */
248c20e8c5bSSebastian Reichel 	{ RK818_H5V_EN_REG,	  BIT(1),	    RK818_REF_RDY_CTRL },
249c20e8c5bSSebastian Reichel 	/* enable HDMI 5V */
250c20e8c5bSSebastian Reichel 	{ RK818_H5V_EN_REG,	  BIT(0),	    RK818_H5V_EN },
251c20e8c5bSSebastian Reichel 	{ RK808_VB_MON_REG,	  MASK_ALL,	    VB_LO_ACT |
252c20e8c5bSSebastian Reichel 						    VB_LO_SEL_3500MV },
253c20e8c5bSSebastian Reichel };
254c20e8c5bSSebastian Reichel 
255c20e8c5bSSebastian Reichel static const struct regmap_irq rk805_irqs[] = {
256c20e8c5bSSebastian Reichel 	[RK805_IRQ_PWRON_RISE] = {
257c20e8c5bSSebastian Reichel 		.mask = RK805_IRQ_PWRON_RISE_MSK,
258c20e8c5bSSebastian Reichel 		.reg_offset = 0,
259c20e8c5bSSebastian Reichel 	},
260c20e8c5bSSebastian Reichel 	[RK805_IRQ_VB_LOW] = {
261c20e8c5bSSebastian Reichel 		.mask = RK805_IRQ_VB_LOW_MSK,
262c20e8c5bSSebastian Reichel 		.reg_offset = 0,
263c20e8c5bSSebastian Reichel 	},
264c20e8c5bSSebastian Reichel 	[RK805_IRQ_PWRON] = {
265c20e8c5bSSebastian Reichel 		.mask = RK805_IRQ_PWRON_MSK,
266c20e8c5bSSebastian Reichel 		.reg_offset = 0,
267c20e8c5bSSebastian Reichel 	},
268c20e8c5bSSebastian Reichel 	[RK805_IRQ_PWRON_LP] = {
269c20e8c5bSSebastian Reichel 		.mask = RK805_IRQ_PWRON_LP_MSK,
270c20e8c5bSSebastian Reichel 		.reg_offset = 0,
271c20e8c5bSSebastian Reichel 	},
272c20e8c5bSSebastian Reichel 	[RK805_IRQ_HOTDIE] = {
273c20e8c5bSSebastian Reichel 		.mask = RK805_IRQ_HOTDIE_MSK,
274c20e8c5bSSebastian Reichel 		.reg_offset = 0,
275c20e8c5bSSebastian Reichel 	},
276c20e8c5bSSebastian Reichel 	[RK805_IRQ_RTC_ALARM] = {
277c20e8c5bSSebastian Reichel 		.mask = RK805_IRQ_RTC_ALARM_MSK,
278c20e8c5bSSebastian Reichel 		.reg_offset = 0,
279c20e8c5bSSebastian Reichel 	},
280c20e8c5bSSebastian Reichel 	[RK805_IRQ_RTC_PERIOD] = {
281c20e8c5bSSebastian Reichel 		.mask = RK805_IRQ_RTC_PERIOD_MSK,
282c20e8c5bSSebastian Reichel 		.reg_offset = 0,
283c20e8c5bSSebastian Reichel 	},
284c20e8c5bSSebastian Reichel 	[RK805_IRQ_PWRON_FALL] = {
285c20e8c5bSSebastian Reichel 		.mask = RK805_IRQ_PWRON_FALL_MSK,
286c20e8c5bSSebastian Reichel 		.reg_offset = 0,
287c20e8c5bSSebastian Reichel 	},
288c20e8c5bSSebastian Reichel };
289c20e8c5bSSebastian Reichel 
290210f418fSSebastian Reichel static const struct regmap_irq rk806_irqs[] = {
291210f418fSSebastian Reichel 	/* INT_STS0 IRQs */
292210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_PWRON_FALL, 0, RK806_INT_STS_PWRON_FALL),
293210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_PWRON_RISE, 0, RK806_INT_STS_PWRON_RISE),
294210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_PWRON, 0, RK806_INT_STS_PWRON),
295210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_PWRON_LP, 0, RK806_INT_STS_PWRON_LP),
296210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_HOTDIE, 0, RK806_INT_STS_HOTDIE),
297210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_VDC_RISE, 0, RK806_INT_STS_VDC_RISE),
298210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_VDC_FALL, 0, RK806_INT_STS_VDC_FALL),
299210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_VB_LO, 0, RK806_INT_STS_VB_LO),
300210f418fSSebastian Reichel 	/* INT_STS1 IRQs */
301210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_REV0, 1, RK806_INT_STS_REV0),
302210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_REV1, 1, RK806_INT_STS_REV1),
303210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_REV2, 1, RK806_INT_STS_REV2),
304210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_CRC_ERROR, 1, RK806_INT_STS_CRC_ERROR),
305210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_SLP3_GPIO, 1, RK806_INT_STS_SLP3_GPIO),
306210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_SLP2_GPIO, 1, RK806_INT_STS_SLP2_GPIO),
307210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_SLP1_GPIO, 1, RK806_INT_STS_SLP1_GPIO),
308210f418fSSebastian Reichel 	REGMAP_IRQ_REG(RK806_IRQ_WDT, 1, RK806_INT_STS_WDT),
309210f418fSSebastian Reichel };
310210f418fSSebastian Reichel 
311c20e8c5bSSebastian Reichel static const struct regmap_irq rk808_irqs[] = {
312c20e8c5bSSebastian Reichel 	/* INT_STS */
313c20e8c5bSSebastian Reichel 	[RK808_IRQ_VOUT_LO] = {
314c20e8c5bSSebastian Reichel 		.mask = RK808_IRQ_VOUT_LO_MSK,
315c20e8c5bSSebastian Reichel 		.reg_offset = 0,
316c20e8c5bSSebastian Reichel 	},
317c20e8c5bSSebastian Reichel 	[RK808_IRQ_VB_LO] = {
318c20e8c5bSSebastian Reichel 		.mask = RK808_IRQ_VB_LO_MSK,
319c20e8c5bSSebastian Reichel 		.reg_offset = 0,
320c20e8c5bSSebastian Reichel 	},
321c20e8c5bSSebastian Reichel 	[RK808_IRQ_PWRON] = {
322c20e8c5bSSebastian Reichel 		.mask = RK808_IRQ_PWRON_MSK,
323c20e8c5bSSebastian Reichel 		.reg_offset = 0,
324c20e8c5bSSebastian Reichel 	},
325c20e8c5bSSebastian Reichel 	[RK808_IRQ_PWRON_LP] = {
326c20e8c5bSSebastian Reichel 		.mask = RK808_IRQ_PWRON_LP_MSK,
327c20e8c5bSSebastian Reichel 		.reg_offset = 0,
328c20e8c5bSSebastian Reichel 	},
329c20e8c5bSSebastian Reichel 	[RK808_IRQ_HOTDIE] = {
330c20e8c5bSSebastian Reichel 		.mask = RK808_IRQ_HOTDIE_MSK,
331c20e8c5bSSebastian Reichel 		.reg_offset = 0,
332c20e8c5bSSebastian Reichel 	},
333c20e8c5bSSebastian Reichel 	[RK808_IRQ_RTC_ALARM] = {
334c20e8c5bSSebastian Reichel 		.mask = RK808_IRQ_RTC_ALARM_MSK,
335c20e8c5bSSebastian Reichel 		.reg_offset = 0,
336c20e8c5bSSebastian Reichel 	},
337c20e8c5bSSebastian Reichel 	[RK808_IRQ_RTC_PERIOD] = {
338c20e8c5bSSebastian Reichel 		.mask = RK808_IRQ_RTC_PERIOD_MSK,
339c20e8c5bSSebastian Reichel 		.reg_offset = 0,
340c20e8c5bSSebastian Reichel 	},
341c20e8c5bSSebastian Reichel 
342c20e8c5bSSebastian Reichel 	/* INT_STS2 */
343c20e8c5bSSebastian Reichel 	[RK808_IRQ_PLUG_IN_INT] = {
344c20e8c5bSSebastian Reichel 		.mask = RK808_IRQ_PLUG_IN_INT_MSK,
345c20e8c5bSSebastian Reichel 		.reg_offset = 1,
346c20e8c5bSSebastian Reichel 	},
347c20e8c5bSSebastian Reichel 	[RK808_IRQ_PLUG_OUT_INT] = {
348c20e8c5bSSebastian Reichel 		.mask = RK808_IRQ_PLUG_OUT_INT_MSK,
349c20e8c5bSSebastian Reichel 		.reg_offset = 1,
350c20e8c5bSSebastian Reichel 	},
351c20e8c5bSSebastian Reichel };
352c20e8c5bSSebastian Reichel 
353c20e8c5bSSebastian Reichel static const struct regmap_irq rk818_irqs[] = {
354c20e8c5bSSebastian Reichel 	/* INT_STS */
355c20e8c5bSSebastian Reichel 	[RK818_IRQ_VOUT_LO] = {
356c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_VOUT_LO_MSK,
357c20e8c5bSSebastian Reichel 		.reg_offset = 0,
358c20e8c5bSSebastian Reichel 	},
359c20e8c5bSSebastian Reichel 	[RK818_IRQ_VB_LO] = {
360c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_VB_LO_MSK,
361c20e8c5bSSebastian Reichel 		.reg_offset = 0,
362c20e8c5bSSebastian Reichel 	},
363c20e8c5bSSebastian Reichel 	[RK818_IRQ_PWRON] = {
364c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_PWRON_MSK,
365c20e8c5bSSebastian Reichel 		.reg_offset = 0,
366c20e8c5bSSebastian Reichel 	},
367c20e8c5bSSebastian Reichel 	[RK818_IRQ_PWRON_LP] = {
368c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_PWRON_LP_MSK,
369c20e8c5bSSebastian Reichel 		.reg_offset = 0,
370c20e8c5bSSebastian Reichel 	},
371c20e8c5bSSebastian Reichel 	[RK818_IRQ_HOTDIE] = {
372c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_HOTDIE_MSK,
373c20e8c5bSSebastian Reichel 		.reg_offset = 0,
374c20e8c5bSSebastian Reichel 	},
375c20e8c5bSSebastian Reichel 	[RK818_IRQ_RTC_ALARM] = {
376c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_RTC_ALARM_MSK,
377c20e8c5bSSebastian Reichel 		.reg_offset = 0,
378c20e8c5bSSebastian Reichel 	},
379c20e8c5bSSebastian Reichel 	[RK818_IRQ_RTC_PERIOD] = {
380c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_RTC_PERIOD_MSK,
381c20e8c5bSSebastian Reichel 		.reg_offset = 0,
382c20e8c5bSSebastian Reichel 	},
383c20e8c5bSSebastian Reichel 	[RK818_IRQ_USB_OV] = {
384c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_USB_OV_MSK,
385c20e8c5bSSebastian Reichel 		.reg_offset = 0,
386c20e8c5bSSebastian Reichel 	},
387c20e8c5bSSebastian Reichel 
388c20e8c5bSSebastian Reichel 	/* INT_STS2 */
389c20e8c5bSSebastian Reichel 	[RK818_IRQ_PLUG_IN] = {
390c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_PLUG_IN_MSK,
391c20e8c5bSSebastian Reichel 		.reg_offset = 1,
392c20e8c5bSSebastian Reichel 	},
393c20e8c5bSSebastian Reichel 	[RK818_IRQ_PLUG_OUT] = {
394c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_PLUG_OUT_MSK,
395c20e8c5bSSebastian Reichel 		.reg_offset = 1,
396c20e8c5bSSebastian Reichel 	},
397c20e8c5bSSebastian Reichel 	[RK818_IRQ_CHG_OK] = {
398c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_CHG_OK_MSK,
399c20e8c5bSSebastian Reichel 		.reg_offset = 1,
400c20e8c5bSSebastian Reichel 	},
401c20e8c5bSSebastian Reichel 	[RK818_IRQ_CHG_TE] = {
402c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_CHG_TE_MSK,
403c20e8c5bSSebastian Reichel 		.reg_offset = 1,
404c20e8c5bSSebastian Reichel 	},
405c20e8c5bSSebastian Reichel 	[RK818_IRQ_CHG_TS1] = {
406c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_CHG_TS1_MSK,
407c20e8c5bSSebastian Reichel 		.reg_offset = 1,
408c20e8c5bSSebastian Reichel 	},
409c20e8c5bSSebastian Reichel 	[RK818_IRQ_TS2] = {
410c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_TS2_MSK,
411c20e8c5bSSebastian Reichel 		.reg_offset = 1,
412c20e8c5bSSebastian Reichel 	},
413c20e8c5bSSebastian Reichel 	[RK818_IRQ_CHG_CVTLIM] = {
414c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_CHG_CVTLIM_MSK,
415c20e8c5bSSebastian Reichel 		.reg_offset = 1,
416c20e8c5bSSebastian Reichel 	},
417c20e8c5bSSebastian Reichel 	[RK818_IRQ_DISCHG_ILIM] = {
418c20e8c5bSSebastian Reichel 		.mask = RK818_IRQ_DISCHG_ILIM_MSK,
419c20e8c5bSSebastian Reichel 		.reg_offset = 1,
420c20e8c5bSSebastian Reichel 	},
421c20e8c5bSSebastian Reichel };
422c20e8c5bSSebastian Reichel 
423c20e8c5bSSebastian Reichel static const struct regmap_irq rk817_irqs[RK817_IRQ_END] = {
424c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(0, 8),
425c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(1, 8),
426c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(2, 8),
427c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(3, 8),
428c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(4, 8),
429c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(5, 8),
430c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(6, 8),
431c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(7, 8),
432c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(8, 8),
433c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(9, 8),
434c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(10, 8),
435c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(11, 8),
436c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(12, 8),
437c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(13, 8),
438c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(14, 8),
439c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(15, 8),
440c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(16, 8),
441c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(17, 8),
442c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(18, 8),
443c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(19, 8),
444c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(20, 8),
445c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(21, 8),
446c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(22, 8),
447c20e8c5bSSebastian Reichel 	REGMAP_IRQ_REG_LINE(23, 8)
448c20e8c5bSSebastian Reichel };
449c20e8c5bSSebastian Reichel 
450c20e8c5bSSebastian Reichel static struct regmap_irq_chip rk805_irq_chip = {
451c20e8c5bSSebastian Reichel 	.name = "rk805",
452c20e8c5bSSebastian Reichel 	.irqs = rk805_irqs,
453c20e8c5bSSebastian Reichel 	.num_irqs = ARRAY_SIZE(rk805_irqs),
454c20e8c5bSSebastian Reichel 	.num_regs = 1,
455c20e8c5bSSebastian Reichel 	.status_base = RK805_INT_STS_REG,
456c20e8c5bSSebastian Reichel 	.mask_base = RK805_INT_STS_MSK_REG,
457c20e8c5bSSebastian Reichel 	.ack_base = RK805_INT_STS_REG,
458c20e8c5bSSebastian Reichel 	.init_ack_masked = true,
459c20e8c5bSSebastian Reichel };
460c20e8c5bSSebastian Reichel 
461210f418fSSebastian Reichel static struct regmap_irq_chip rk806_irq_chip = {
462210f418fSSebastian Reichel 	.name = "rk806",
463210f418fSSebastian Reichel 	.irqs = rk806_irqs,
464210f418fSSebastian Reichel 	.num_irqs = ARRAY_SIZE(rk806_irqs),
465210f418fSSebastian Reichel 	.num_regs = 2,
466210f418fSSebastian Reichel 	.irq_reg_stride = 2,
467210f418fSSebastian Reichel 	.mask_base = RK806_INT_MSK0,
468210f418fSSebastian Reichel 	.status_base = RK806_INT_STS0,
469210f418fSSebastian Reichel 	.ack_base = RK806_INT_STS0,
470210f418fSSebastian Reichel 	.init_ack_masked = true,
471210f418fSSebastian Reichel };
472210f418fSSebastian Reichel 
473c20e8c5bSSebastian Reichel static const struct regmap_irq_chip rk808_irq_chip = {
474c20e8c5bSSebastian Reichel 	.name = "rk808",
475c20e8c5bSSebastian Reichel 	.irqs = rk808_irqs,
476c20e8c5bSSebastian Reichel 	.num_irqs = ARRAY_SIZE(rk808_irqs),
477c20e8c5bSSebastian Reichel 	.num_regs = 2,
478c20e8c5bSSebastian Reichel 	.irq_reg_stride = 2,
479c20e8c5bSSebastian Reichel 	.status_base = RK808_INT_STS_REG1,
480c20e8c5bSSebastian Reichel 	.mask_base = RK808_INT_STS_MSK_REG1,
481c20e8c5bSSebastian Reichel 	.ack_base = RK808_INT_STS_REG1,
482c20e8c5bSSebastian Reichel 	.init_ack_masked = true,
483c20e8c5bSSebastian Reichel };
484c20e8c5bSSebastian Reichel 
485c20e8c5bSSebastian Reichel static struct regmap_irq_chip rk817_irq_chip = {
486c20e8c5bSSebastian Reichel 	.name = "rk817",
487c20e8c5bSSebastian Reichel 	.irqs = rk817_irqs,
488c20e8c5bSSebastian Reichel 	.num_irqs = ARRAY_SIZE(rk817_irqs),
489c20e8c5bSSebastian Reichel 	.num_regs = 3,
490c20e8c5bSSebastian Reichel 	.irq_reg_stride = 2,
491c20e8c5bSSebastian Reichel 	.status_base = RK817_INT_STS_REG0,
492c20e8c5bSSebastian Reichel 	.mask_base = RK817_INT_STS_MSK_REG0,
493c20e8c5bSSebastian Reichel 	.ack_base = RK817_INT_STS_REG0,
494c20e8c5bSSebastian Reichel 	.init_ack_masked = true,
495c20e8c5bSSebastian Reichel };
496c20e8c5bSSebastian Reichel 
497c20e8c5bSSebastian Reichel static const struct regmap_irq_chip rk818_irq_chip = {
498c20e8c5bSSebastian Reichel 	.name = "rk818",
499c20e8c5bSSebastian Reichel 	.irqs = rk818_irqs,
500c20e8c5bSSebastian Reichel 	.num_irqs = ARRAY_SIZE(rk818_irqs),
501c20e8c5bSSebastian Reichel 	.num_regs = 2,
502c20e8c5bSSebastian Reichel 	.irq_reg_stride = 2,
503c20e8c5bSSebastian Reichel 	.status_base = RK818_INT_STS_REG1,
504c20e8c5bSSebastian Reichel 	.mask_base = RK818_INT_STS_MSK_REG1,
505c20e8c5bSSebastian Reichel 	.ack_base = RK818_INT_STS_REG1,
506c20e8c5bSSebastian Reichel 	.init_ack_masked = true,
507c20e8c5bSSebastian Reichel };
508c20e8c5bSSebastian Reichel 
rk808_power_off(struct sys_off_data * data)509c20e8c5bSSebastian Reichel static int rk808_power_off(struct sys_off_data *data)
510c20e8c5bSSebastian Reichel {
511c20e8c5bSSebastian Reichel 	struct rk808 *rk808 = data->cb_data;
512c20e8c5bSSebastian Reichel 	int ret;
513c20e8c5bSSebastian Reichel 	unsigned int reg, bit;
514c20e8c5bSSebastian Reichel 
515c20e8c5bSSebastian Reichel 	switch (rk808->variant) {
516c20e8c5bSSebastian Reichel 	case RK805_ID:
517c20e8c5bSSebastian Reichel 		reg = RK805_DEV_CTRL_REG;
518c20e8c5bSSebastian Reichel 		bit = DEV_OFF;
519c20e8c5bSSebastian Reichel 		break;
520c20e8c5bSSebastian Reichel 	case RK808_ID:
521c20e8c5bSSebastian Reichel 		reg = RK808_DEVCTRL_REG,
522c20e8c5bSSebastian Reichel 		bit = DEV_OFF_RST;
523c20e8c5bSSebastian Reichel 		break;
524c20e8c5bSSebastian Reichel 	case RK809_ID:
525c20e8c5bSSebastian Reichel 	case RK817_ID:
526c20e8c5bSSebastian Reichel 		reg = RK817_SYS_CFG(3);
527c20e8c5bSSebastian Reichel 		bit = DEV_OFF;
528c20e8c5bSSebastian Reichel 		break;
529c20e8c5bSSebastian Reichel 	case RK818_ID:
530c20e8c5bSSebastian Reichel 		reg = RK818_DEVCTRL_REG;
531c20e8c5bSSebastian Reichel 		bit = DEV_OFF;
532c20e8c5bSSebastian Reichel 		break;
533c20e8c5bSSebastian Reichel 	default:
534c20e8c5bSSebastian Reichel 		return NOTIFY_DONE;
535c20e8c5bSSebastian Reichel 	}
536c20e8c5bSSebastian Reichel 	ret = regmap_update_bits(rk808->regmap, reg, bit, bit);
537c20e8c5bSSebastian Reichel 	if (ret)
538c20e8c5bSSebastian Reichel 		dev_err(rk808->dev, "Failed to shutdown device!\n");
539c20e8c5bSSebastian Reichel 
540c20e8c5bSSebastian Reichel 	return NOTIFY_DONE;
541c20e8c5bSSebastian Reichel }
542c20e8c5bSSebastian Reichel 
rk808_restart(struct sys_off_data * data)543c20e8c5bSSebastian Reichel static int rk808_restart(struct sys_off_data *data)
544c20e8c5bSSebastian Reichel {
545c20e8c5bSSebastian Reichel 	struct rk808 *rk808 = data->cb_data;
546c20e8c5bSSebastian Reichel 	unsigned int reg, bit;
547c20e8c5bSSebastian Reichel 	int ret;
548c20e8c5bSSebastian Reichel 
549c20e8c5bSSebastian Reichel 	switch (rk808->variant) {
550c20e8c5bSSebastian Reichel 	case RK809_ID:
551c20e8c5bSSebastian Reichel 	case RK817_ID:
552c20e8c5bSSebastian Reichel 		reg = RK817_SYS_CFG(3);
553c20e8c5bSSebastian Reichel 		bit = DEV_RST;
554c20e8c5bSSebastian Reichel 		break;
555c20e8c5bSSebastian Reichel 
556c20e8c5bSSebastian Reichel 	default:
557c20e8c5bSSebastian Reichel 		return NOTIFY_DONE;
558c20e8c5bSSebastian Reichel 	}
559c20e8c5bSSebastian Reichel 	ret = regmap_update_bits(rk808->regmap, reg, bit, bit);
560c20e8c5bSSebastian Reichel 	if (ret)
561c20e8c5bSSebastian Reichel 		dev_err(rk808->dev, "Failed to restart device!\n");
562c20e8c5bSSebastian Reichel 
563c20e8c5bSSebastian Reichel 	return NOTIFY_DONE;
564c20e8c5bSSebastian Reichel }
565c20e8c5bSSebastian Reichel 
rk8xx_shutdown(struct device * dev)566c20e8c5bSSebastian Reichel void rk8xx_shutdown(struct device *dev)
567c20e8c5bSSebastian Reichel {
568c20e8c5bSSebastian Reichel 	struct rk808 *rk808 = dev_get_drvdata(dev);
569c20e8c5bSSebastian Reichel 	int ret;
570c20e8c5bSSebastian Reichel 
571c20e8c5bSSebastian Reichel 	switch (rk808->variant) {
572c20e8c5bSSebastian Reichel 	case RK805_ID:
573c20e8c5bSSebastian Reichel 		ret = regmap_update_bits(rk808->regmap,
574c20e8c5bSSebastian Reichel 					 RK805_GPIO_IO_POL_REG,
575c20e8c5bSSebastian Reichel 					 SLP_SD_MSK,
576c20e8c5bSSebastian Reichel 					 SHUTDOWN_FUN);
577c20e8c5bSSebastian Reichel 		break;
578c20e8c5bSSebastian Reichel 	case RK809_ID:
579c20e8c5bSSebastian Reichel 	case RK817_ID:
580c20e8c5bSSebastian Reichel 		ret = regmap_update_bits(rk808->regmap,
581c20e8c5bSSebastian Reichel 					 RK817_SYS_CFG(3),
582c20e8c5bSSebastian Reichel 					 RK817_SLPPIN_FUNC_MSK,
583c20e8c5bSSebastian Reichel 					 SLPPIN_DN_FUN);
584c20e8c5bSSebastian Reichel 		break;
585c20e8c5bSSebastian Reichel 	default:
586c20e8c5bSSebastian Reichel 		return;
587c20e8c5bSSebastian Reichel 	}
588c20e8c5bSSebastian Reichel 	if (ret)
589c20e8c5bSSebastian Reichel 		dev_warn(dev,
590c20e8c5bSSebastian Reichel 			 "Cannot switch to power down function\n");
591c20e8c5bSSebastian Reichel }
592c20e8c5bSSebastian Reichel EXPORT_SYMBOL_GPL(rk8xx_shutdown);
593c20e8c5bSSebastian Reichel 
rk8xx_probe(struct device * dev,int variant,unsigned int irq,struct regmap * regmap)594c20e8c5bSSebastian Reichel int rk8xx_probe(struct device *dev, int variant, unsigned int irq, struct regmap *regmap)
595c20e8c5bSSebastian Reichel {
596c20e8c5bSSebastian Reichel 	struct rk808 *rk808;
597c20e8c5bSSebastian Reichel 	const struct rk808_reg_data *pre_init_reg;
598c20e8c5bSSebastian Reichel 	const struct mfd_cell *cells;
599210f418fSSebastian Reichel 	int dual_support = 0;
600c20e8c5bSSebastian Reichel 	int nr_pre_init_regs;
601c20e8c5bSSebastian Reichel 	int nr_cells;
602c20e8c5bSSebastian Reichel 	int ret;
603c20e8c5bSSebastian Reichel 	int i;
604c20e8c5bSSebastian Reichel 
605c20e8c5bSSebastian Reichel 	rk808 = devm_kzalloc(dev, sizeof(*rk808), GFP_KERNEL);
606c20e8c5bSSebastian Reichel 	if (!rk808)
607c20e8c5bSSebastian Reichel 		return -ENOMEM;
608c20e8c5bSSebastian Reichel 	rk808->dev = dev;
609c20e8c5bSSebastian Reichel 	rk808->variant = variant;
610c20e8c5bSSebastian Reichel 	rk808->regmap = regmap;
611c20e8c5bSSebastian Reichel 	dev_set_drvdata(dev, rk808);
612c20e8c5bSSebastian Reichel 
613c20e8c5bSSebastian Reichel 	switch (rk808->variant) {
614c20e8c5bSSebastian Reichel 	case RK805_ID:
615c20e8c5bSSebastian Reichel 		rk808->regmap_irq_chip = &rk805_irq_chip;
616c20e8c5bSSebastian Reichel 		pre_init_reg = rk805_pre_init_reg;
617c20e8c5bSSebastian Reichel 		nr_pre_init_regs = ARRAY_SIZE(rk805_pre_init_reg);
618c20e8c5bSSebastian Reichel 		cells = rk805s;
619c20e8c5bSSebastian Reichel 		nr_cells = ARRAY_SIZE(rk805s);
620c20e8c5bSSebastian Reichel 		break;
621210f418fSSebastian Reichel 	case RK806_ID:
622210f418fSSebastian Reichel 		rk808->regmap_irq_chip = &rk806_irq_chip;
623210f418fSSebastian Reichel 		pre_init_reg = rk806_pre_init_reg;
624210f418fSSebastian Reichel 		nr_pre_init_regs = ARRAY_SIZE(rk806_pre_init_reg);
625210f418fSSebastian Reichel 		cells = rk806s;
626210f418fSSebastian Reichel 		nr_cells = ARRAY_SIZE(rk806s);
627210f418fSSebastian Reichel 		dual_support = IRQF_SHARED;
628210f418fSSebastian Reichel 		break;
629c20e8c5bSSebastian Reichel 	case RK808_ID:
630c20e8c5bSSebastian Reichel 		rk808->regmap_irq_chip = &rk808_irq_chip;
631c20e8c5bSSebastian Reichel 		pre_init_reg = rk808_pre_init_reg;
632c20e8c5bSSebastian Reichel 		nr_pre_init_regs = ARRAY_SIZE(rk808_pre_init_reg);
633c20e8c5bSSebastian Reichel 		cells = rk808s;
634c20e8c5bSSebastian Reichel 		nr_cells = ARRAY_SIZE(rk808s);
635c20e8c5bSSebastian Reichel 		break;
636c20e8c5bSSebastian Reichel 	case RK818_ID:
637c20e8c5bSSebastian Reichel 		rk808->regmap_irq_chip = &rk818_irq_chip;
638c20e8c5bSSebastian Reichel 		pre_init_reg = rk818_pre_init_reg;
639c20e8c5bSSebastian Reichel 		nr_pre_init_regs = ARRAY_SIZE(rk818_pre_init_reg);
640c20e8c5bSSebastian Reichel 		cells = rk818s;
641c20e8c5bSSebastian Reichel 		nr_cells = ARRAY_SIZE(rk818s);
642c20e8c5bSSebastian Reichel 		break;
643c20e8c5bSSebastian Reichel 	case RK809_ID:
644c20e8c5bSSebastian Reichel 	case RK817_ID:
645c20e8c5bSSebastian Reichel 		rk808->regmap_irq_chip = &rk817_irq_chip;
646c20e8c5bSSebastian Reichel 		pre_init_reg = rk817_pre_init_reg;
647c20e8c5bSSebastian Reichel 		nr_pre_init_regs = ARRAY_SIZE(rk817_pre_init_reg);
648c20e8c5bSSebastian Reichel 		cells = rk817s;
649c20e8c5bSSebastian Reichel 		nr_cells = ARRAY_SIZE(rk817s);
650c20e8c5bSSebastian Reichel 		break;
651c20e8c5bSSebastian Reichel 	default:
652c20e8c5bSSebastian Reichel 		dev_err(dev, "Unsupported RK8XX ID %lu\n", rk808->variant);
653c20e8c5bSSebastian Reichel 		return -EINVAL;
654c20e8c5bSSebastian Reichel 	}
655c20e8c5bSSebastian Reichel 
656c20e8c5bSSebastian Reichel 	if (!irq)
657c20e8c5bSSebastian Reichel 		return dev_err_probe(dev, -EINVAL, "No interrupt support, no core IRQ\n");
658c20e8c5bSSebastian Reichel 
659c20e8c5bSSebastian Reichel 	ret = devm_regmap_add_irq_chip(dev, rk808->regmap, irq,
660210f418fSSebastian Reichel 				       IRQF_ONESHOT | dual_support, -1,
661c20e8c5bSSebastian Reichel 				       rk808->regmap_irq_chip, &rk808->irq_data);
662c20e8c5bSSebastian Reichel 	if (ret)
663c20e8c5bSSebastian Reichel 		return dev_err_probe(dev, ret, "Failed to add irq_chip\n");
664c20e8c5bSSebastian Reichel 
665c20e8c5bSSebastian Reichel 	for (i = 0; i < nr_pre_init_regs; i++) {
666c20e8c5bSSebastian Reichel 		ret = regmap_update_bits(rk808->regmap,
667c20e8c5bSSebastian Reichel 					pre_init_reg[i].addr,
668c20e8c5bSSebastian Reichel 					pre_init_reg[i].mask,
669c20e8c5bSSebastian Reichel 					pre_init_reg[i].value);
670c20e8c5bSSebastian Reichel 		if (ret)
671c20e8c5bSSebastian Reichel 			return dev_err_probe(dev, ret, "0x%x write err\n",
672c20e8c5bSSebastian Reichel 					     pre_init_reg[i].addr);
673c20e8c5bSSebastian Reichel 	}
674c20e8c5bSSebastian Reichel 
675*3c90b3b0SNeil Armstrong 	ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, cells, nr_cells, NULL, 0,
676c20e8c5bSSebastian Reichel 			      regmap_irq_get_domain(rk808->irq_data));
677c20e8c5bSSebastian Reichel 	if (ret)
678c20e8c5bSSebastian Reichel 		return dev_err_probe(dev, ret, "failed to add MFD devices\n");
679c20e8c5bSSebastian Reichel 
680c20e8c5bSSebastian Reichel 	if (device_property_read_bool(dev, "rockchip,system-power-controller")) {
681c20e8c5bSSebastian Reichel 		ret = devm_register_sys_off_handler(dev,
682c20e8c5bSSebastian Reichel 				    SYS_OFF_MODE_POWER_OFF_PREPARE, SYS_OFF_PRIO_HIGH,
683c20e8c5bSSebastian Reichel 				    &rk808_power_off, rk808);
684c20e8c5bSSebastian Reichel 		if (ret)
685c20e8c5bSSebastian Reichel 			return dev_err_probe(dev, ret,
686c20e8c5bSSebastian Reichel 					     "failed to register poweroff handler\n");
687c20e8c5bSSebastian Reichel 
688c20e8c5bSSebastian Reichel 		switch (rk808->variant) {
689c20e8c5bSSebastian Reichel 		case RK809_ID:
690c20e8c5bSSebastian Reichel 		case RK817_ID:
691c20e8c5bSSebastian Reichel 			ret = devm_register_sys_off_handler(dev,
692c20e8c5bSSebastian Reichel 							    SYS_OFF_MODE_RESTART, SYS_OFF_PRIO_HIGH,
693c20e8c5bSSebastian Reichel 							    &rk808_restart, rk808);
694c20e8c5bSSebastian Reichel 			if (ret)
695c20e8c5bSSebastian Reichel 				dev_warn(dev, "failed to register rst handler, %d\n", ret);
696c20e8c5bSSebastian Reichel 			break;
697c20e8c5bSSebastian Reichel 		default:
698c20e8c5bSSebastian Reichel 			dev_dbg(dev, "pmic controlled board reset not supported\n");
699c20e8c5bSSebastian Reichel 			break;
700c20e8c5bSSebastian Reichel 		}
701c20e8c5bSSebastian Reichel 	}
702c20e8c5bSSebastian Reichel 
703c20e8c5bSSebastian Reichel 	return 0;
704c20e8c5bSSebastian Reichel }
705c20e8c5bSSebastian Reichel EXPORT_SYMBOL_GPL(rk8xx_probe);
706c20e8c5bSSebastian Reichel 
rk8xx_suspend(struct device * dev)707c20e8c5bSSebastian Reichel int rk8xx_suspend(struct device *dev)
708c20e8c5bSSebastian Reichel {
709c20e8c5bSSebastian Reichel 	struct rk808 *rk808 = dev_get_drvdata(dev);
710c20e8c5bSSebastian Reichel 	int ret = 0;
711c20e8c5bSSebastian Reichel 
712c20e8c5bSSebastian Reichel 	switch (rk808->variant) {
713c20e8c5bSSebastian Reichel 	case RK805_ID:
714c20e8c5bSSebastian Reichel 		ret = regmap_update_bits(rk808->regmap,
715c20e8c5bSSebastian Reichel 					 RK805_GPIO_IO_POL_REG,
716c20e8c5bSSebastian Reichel 					 SLP_SD_MSK,
717c20e8c5bSSebastian Reichel 					 SLEEP_FUN);
718c20e8c5bSSebastian Reichel 		break;
719c20e8c5bSSebastian Reichel 	case RK809_ID:
720c20e8c5bSSebastian Reichel 	case RK817_ID:
721c20e8c5bSSebastian Reichel 		ret = regmap_update_bits(rk808->regmap,
722c20e8c5bSSebastian Reichel 					 RK817_SYS_CFG(3),
723c20e8c5bSSebastian Reichel 					 RK817_SLPPIN_FUNC_MSK,
724c20e8c5bSSebastian Reichel 					 SLPPIN_SLP_FUN);
725c20e8c5bSSebastian Reichel 		break;
726c20e8c5bSSebastian Reichel 	default:
727c20e8c5bSSebastian Reichel 		break;
728c20e8c5bSSebastian Reichel 	}
729c20e8c5bSSebastian Reichel 
730c20e8c5bSSebastian Reichel 	return ret;
731c20e8c5bSSebastian Reichel }
732c20e8c5bSSebastian Reichel EXPORT_SYMBOL_GPL(rk8xx_suspend);
733c20e8c5bSSebastian Reichel 
rk8xx_resume(struct device * dev)734c20e8c5bSSebastian Reichel int rk8xx_resume(struct device *dev)
735c20e8c5bSSebastian Reichel {
736c20e8c5bSSebastian Reichel 	struct rk808 *rk808 = dev_get_drvdata(dev);
737c20e8c5bSSebastian Reichel 	int ret = 0;
738c20e8c5bSSebastian Reichel 
739c20e8c5bSSebastian Reichel 	switch (rk808->variant) {
740c20e8c5bSSebastian Reichel 	case RK809_ID:
741c20e8c5bSSebastian Reichel 	case RK817_ID:
742c20e8c5bSSebastian Reichel 		ret = regmap_update_bits(rk808->regmap,
743c20e8c5bSSebastian Reichel 					 RK817_SYS_CFG(3),
744c20e8c5bSSebastian Reichel 					 RK817_SLPPIN_FUNC_MSK,
745c20e8c5bSSebastian Reichel 					 SLPPIN_NULL_FUN);
746c20e8c5bSSebastian Reichel 		break;
747c20e8c5bSSebastian Reichel 	default:
748c20e8c5bSSebastian Reichel 		break;
749c20e8c5bSSebastian Reichel 	}
750c20e8c5bSSebastian Reichel 
751c20e8c5bSSebastian Reichel 	return ret;
752c20e8c5bSSebastian Reichel }
753c20e8c5bSSebastian Reichel EXPORT_SYMBOL_GPL(rk8xx_resume);
754c20e8c5bSSebastian Reichel 
755c20e8c5bSSebastian Reichel MODULE_LICENSE("GPL");
756c20e8c5bSSebastian Reichel MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
757c20e8c5bSSebastian Reichel MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>");
758c20e8c5bSSebastian Reichel MODULE_AUTHOR("Wadim Egorov <w.egorov@phytec.de>");
759c20e8c5bSSebastian Reichel MODULE_DESCRIPTION("RK8xx PMIC core");
760