xref: /rk3399_rockchip-uboot/drivers/power/pmic/rk8xx.c (revision 11f9ae3a9f57d1ecc3b8cc16cfbf5e4e599e5330)
1 /*
2  * Copyright (C) 2015 Google, Inc
3  * Written by Simon Glass <sjg@chromium.org>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #include <common.h>
9 #include <dm.h>
10 #include <errno.h>
11 #include <irq-generic.h>
12 #include <power/rk8xx_pmic.h>
13 #include <power/pmic.h>
14 
15 DECLARE_GLOBAL_DATA_PTR;
16 
17 #if CONFIG_IS_ENABLED(IRQ)
18 /* RK805 */
19 static const struct virq_reg rk805_irqs[] = {
20 	[RK8XX_IRQ_PWRON_FALL] = {
21 		.mask = RK805_IRQ_PWRON_FALL_MSK,
22 		.reg_offset = 0,
23 	},
24 	[RK8XX_IRQ_PWRON_RISE] = {
25 		.mask = RK805_IRQ_PWRON_RISE_MSK,
26 		.reg_offset = 0,
27 	},
28 };
29 
30 static struct virq_chip rk805_irq_chip = {
31 	.status_base		= RK805_INT_STS_REG,
32 	.mask_base		= RK805_INT_MSK_REG,
33 	.num_regs		= 1,
34 	.read			= pmic_reg_read,
35 	.write			= pmic_reg_write,
36 	.irqs			= rk805_irqs,
37 	.num_irqs		= ARRAY_SIZE(rk805_irqs),
38 };
39 
40 /* RK808 */
41 static const struct virq_reg rk808_irqs[] = {
42 	[RK8XX_IRQ_PLUG_OUT] = {
43 		.mask = RK808_IRQ_PLUG_OUT_MSK,
44 		.reg_offset = 1,
45 	},
46 };
47 
48 static struct virq_chip rk808_irq_chip = {
49 	.status_base		= RK808_INT_STS_REG1,
50 	.mask_base		= RK808_INT_MSK_REG1,
51 	.irq_reg_stride		= 2,
52 	.num_regs		= 2,
53 	.read			= pmic_reg_read,
54 	.write			= pmic_reg_write,
55 	.irqs			= rk808_irqs,
56 	.num_irqs		= ARRAY_SIZE(rk808_irqs),
57 };
58 
59 /* RK816 */
60 static const struct virq_reg rk816_irqs[] = {
61 	[RK8XX_IRQ_PWRON_FALL] = {
62 		.mask = RK816_IRQ_PWRON_FALL_MSK,
63 		.reg_offset = 0,
64 	},
65 	[RK8XX_IRQ_PWRON_RISE] = {
66 		.mask = RK816_IRQ_PWRON_RISE_MSK,
67 		.reg_offset = 0,
68 	},
69 	[RK8XX_IRQ_PLUG_OUT] = {
70 		.mask = RK816_IRQ_PLUG_OUT_MSK,
71 		.reg_offset = 2,
72 	},
73 	[RK8XX_IRQ_CHG_OK] = {
74 		.mask = RK816_IRQ_CHR_OK_MSK,
75 		.reg_offset = 2,
76 	},
77 };
78 
79 static struct virq_chip rk816_irq_chip = {
80 	.status_base		= RK816_INT_STS_REG1,
81 	.mask_base		= RK816_INT_MSK_REG1,
82 	.irq_unalign_reg_idx	= 1,	/* idx <= 1, stride = 3 */
83 	.irq_unalign_reg_stride	= 3,
84 	.irq_reg_stride		= 2,	/* idx > 1, stride = 2 */
85 	.num_regs		= 3,
86 	.read			= pmic_reg_read,
87 	.write			= pmic_reg_write,
88 	.irqs			= rk816_irqs,
89 	.num_irqs		= ARRAY_SIZE(rk816_irqs),
90 };
91 
92 /* RK818 */
93 static const struct virq_reg rk818_irqs[] = {
94 	[RK8XX_IRQ_PLUG_OUT] = {
95 		.mask = RK818_IRQ_PLUG_OUT_MSK,
96 		.reg_offset = 1,
97 	},
98 	[RK8XX_IRQ_CHG_OK] = {
99 		.mask = RK818_IRQ_CHR_OK_MSK,
100 		.reg_offset = 1,
101 	},
102 };
103 
104 static struct virq_chip rk818_irq_chip = {
105 	.status_base		= RK818_INT_STS_REG1,
106 	.mask_base		= RK818_INT_MSK_REG1,
107 	.irq_reg_stride		= 2,
108 	.num_regs		= 2,
109 	.read			= pmic_reg_read,
110 	.write			= pmic_reg_write,
111 	.irqs			= rk818_irqs,
112 	.num_irqs		= ARRAY_SIZE(rk818_irqs),
113 };
114 
115 /* RK817/RK809 */
116 static const struct virq_reg rk817_irqs[] = {
117 	[RK8XX_IRQ_PWRON_FALL] = {
118 		.mask = RK817_IRQ_PWRON_FALL_MSK,
119 		.reg_offset = 0,
120 	},
121 	[RK8XX_IRQ_PWRON_RISE] = {
122 		.mask = RK817_IRQ_PWRON_RISE_MSK,
123 		.reg_offset = 0,
124 	},
125 	[RK8XX_IRQ_PLUG_OUT] = {
126 		.mask = RK817_IRQ_PLUG_OUT_MSK,
127 		.reg_offset = 1,
128 	},
129 	[RK8XX_IRQ_PLUG_IN] = {
130 		.mask = RK817_IRQ_PLUG_IN_MSK,
131 		.reg_offset = 1,
132 	},
133 };
134 
135 static struct virq_chip rk817_irq_chip = {
136 	.status_base		= RK817_INT_STS_REG0,
137 	.mask_base		= RK817_INT_MSK_REG0,
138 	.irq_reg_stride		= 2,
139 	.num_regs		= 3,
140 	.read			= pmic_reg_read,
141 	.write			= pmic_reg_write,
142 	.irqs			= rk817_irqs,
143 	.num_irqs		= ARRAY_SIZE(rk817_irqs),
144 };
145 #endif
146 
147 static struct reg_data rk817_init_reg[] = {
148 /* enable the under-voltage protection,
149  * the under-voltage protection will shutdown the LDO3 and reset the PMIC
150  */
151 	{ RK817_BUCK4_CMIN, 0x6b, 0x6e},
152 	{ RK817_PMIC_SYS_CFG1, 0x20, 0x70},
153 	/* Set pmic_sleep as none function */
154 	{ RK817_PMIC_SYS_CFG3, 0x00, 0x18 },
155 
156 #ifdef CONFIG_DM_CHARGE_DISPLAY
157 	/* Set pmic_int active low */
158 	{ RK817_GPIO_INT_CFG,  0x00, 0x02 },
159 #endif
160 };
161 
162 static struct reg_data rk818_init_current[] = {
163 	{ REG_USB_CTRL, 0x07, 0x0f}, /* 2A */
164 };
165 
166 static const struct pmic_child_info pmic_children_info[] = {
167 	{ .prefix = "DCDC", .driver = "rk8xx_buck"},
168 	{ .prefix = "LDO", .driver = "rk8xx_ldo"},
169 	{ .prefix = "SWITCH", .driver = "rk8xx_switch"},
170 	{ },
171 };
172 
173 static const struct pmic_child_info power_key_info[] = {
174 	{ .prefix = "pwrkey", .driver = "rk8xx_pwrkey"},
175 	{ },
176 };
177 
178 static const struct pmic_child_info rtc_info[] = {
179 	{ .prefix = "rtc", .driver = "rk8xx_rtc"},
180 	{ },
181 };
182 
183 static const struct pmic_child_info fuel_gauge_info[] = {
184 	{ .addr = "1c", .prefix = "battery", .driver = "rk818_fg"},
185 	{ .addr = "20", .prefix = "battery", .driver = "rk817_fg"},
186 	{ .addr = "1a", .prefix = "battery", .driver = "rk816_fg"},
187 	{ },
188 };
189 
190 static const struct pmic_child_info rk817_codec_info[] = {
191 	{ .prefix = "codec", .driver = "rk817_codec"},
192 	{ },
193 };
194 
195 static int rk8xx_reg_count(struct udevice *dev)
196 {
197 	struct rk8xx_priv *priv = dev_get_priv(dev);
198 
199 	switch (priv->variant) {
200 	case RK809_ID:
201 	case RK817_ID:
202 		return RK817_NUM_OF_REGS;
203 	default:
204 		return RK808_NUM_OF_REGS;
205 	}
206 }
207 
208 static int rk8xx_write(struct udevice *dev, uint reg, const uint8_t *buff,
209 			  int len)
210 {
211 	int ret;
212 
213 	ret = dm_i2c_write(dev, reg, buff, len);
214 	if (ret) {
215 		printf("%s: write reg 0x%02x failed, ret=%d\n", __func__, reg, ret);
216 		return ret;
217 	}
218 
219 	return 0;
220 }
221 
222 static int rk8xx_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
223 {
224 	int ret;
225 
226 	ret = dm_i2c_read(dev, reg, buff, len);
227 	if (ret) {
228 		printf("%s: read reg 0x%02x failed, ret=%d\n", __func__, reg, ret);
229 		return ret;
230 	}
231 
232 	return 0;
233 }
234 
235 static int rk8xx_suspend(struct udevice *dev)
236 {
237 	struct rk8xx_priv *priv = dev_get_priv(dev);
238 	int ret = 0;
239 	u8 val;
240 
241 	switch (priv->variant) {
242 	case RK809_ID:
243 	case RK817_ID:
244 		/* pmic_sleep active high */
245 		ret = rk8xx_read(dev, RK817_PMIC_SYS_CFG3, &val, 1);
246 		if (ret)
247 			return ret;
248 		priv->sleep_pin = val;
249 		val &= ~0x38;
250 		val |= 0x28;
251 		ret = rk8xx_write(dev, RK817_PMIC_SYS_CFG3, &val, 1);
252 		break;
253 	default:
254 		return 0;
255 	}
256 
257 	return ret;
258 }
259 
260 static int rk8xx_resume(struct udevice *dev)
261 {
262 	struct rk8xx_priv *priv = dev_get_priv(dev);
263 	int ret = 0;
264 
265 	switch (priv->variant) {
266 	case RK809_ID:
267 	case RK817_ID:
268 		ret = rk8xx_write(dev, RK817_PMIC_SYS_CFG3, &priv->sleep_pin, 1);
269 		break;
270 	default:
271 		return 0;
272 	}
273 
274 	return ret;
275 }
276 
277 static int rk8xx_shutdown(struct udevice *dev)
278 {
279 	struct rk8xx_priv *priv = dev_get_priv(dev);
280 	u8 val, dev_off, devctrl_reg;
281 	int ret = 0;
282 
283 	switch (priv->variant) {
284 	case RK808_ID:
285 		devctrl_reg = REG_DEVCTRL;
286 		dev_off = BIT(3);
287 		break;
288 	case RK805_ID:
289 	case RK816_ID:
290 	case RK818_ID:
291 		devctrl_reg = REG_DEVCTRL;
292 		dev_off = BIT(0);
293 		break;
294 	case RK809_ID:
295 	case RK817_ID:
296 		devctrl_reg = RK817_REG_SYS_CFG3;
297 		dev_off = BIT(0);
298 		break;
299 	default:
300 		printf("Unknown PMIC: RK%x\n", priv->variant);
301 		return -EINVAL;
302 	}
303 
304 	ret = rk8xx_read(dev, devctrl_reg, &val, 1);
305 	if (ret)
306 		return ret;
307 
308 	val |= dev_off;
309 	ret = rk8xx_write(dev, devctrl_reg, &val, 1);
310 	if (ret)
311 		return ret;
312 
313 	return 0;
314 }
315 
316 #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
317 static int rk8xx_bind(struct udevice *dev)
318 {
319 	ofnode regulators_node;
320 	int children;
321 
322 	regulators_node = dev_read_subnode(dev, "regulators");
323 	if (!ofnode_valid(regulators_node)) {
324 		debug("%s: %s regulators subnode not found!\n", __func__,
325 		      dev->name);
326 		return -ENXIO;
327 	}
328 
329 	debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
330 
331 	children = pmic_bind_children(dev, regulators_node, pmic_children_info);
332 	if (!children)
333 		debug("%s: %s - no child found\n", __func__, dev->name);
334 
335 	children = pmic_bind_children(dev, dev->node, power_key_info);
336 	if (!children)
337 		debug("%s: %s - no child found\n", __func__, dev->name);
338 
339 	children = pmic_bind_children(dev, dev->node, rtc_info);
340 	if (!children)
341 		debug("%s: %s - no child found\n", __func__, dev->name);
342 
343 	children = pmic_bind_children(dev, dev->node, fuel_gauge_info);
344 	if (!children)
345 		debug("%s: %s - no child found\n", __func__, dev->name);
346 
347 	children = pmic_bind_children(dev, dev->node, rk817_codec_info);
348 	if (!children)
349 		debug("%s: %s - no child found\n", __func__, dev->name);
350 
351 	/* Always return success for this device */
352 	return 0;
353 }
354 #endif
355 
356 #if CONFIG_IS_ENABLED(IRQ)
357 /*
358  * When system suspend during U-Boot charge, make sure the plugout event
359  * be able to wakeup cpu in wfi/wfe state.
360  */
361 #ifdef CONFIG_DM_CHARGE_DISPLAY
362 static void rk8xx_plug_out_handler(int irq, void *data)
363 {
364 	printf("Plug out interrupt\n");
365 }
366 #endif
367 
368 static int rk8xx_ofdata_to_platdata(struct udevice *dev)
369 {
370 	struct rk8xx_priv *rk8xx = dev_get_priv(dev);
371 	u32 interrupt, phandle, val;
372 	int ret;
373 
374 	phandle = dev_read_u32_default(dev, "interrupt-parent", -ENODATA);
375 	if (phandle == -ENODATA) {
376 		printf("Read 'interrupt-parent' failed, ret=%d\n", phandle);
377 		return phandle;
378 	}
379 
380 	ret = dev_read_u32_array(dev, "interrupts", &interrupt, 1);
381 	if (ret) {
382 		printf("Read 'interrupts' failed, ret=%d\n", ret);
383 		return ret;
384 	}
385 
386 	rk8xx->irq = phandle_gpio_to_irq(phandle, interrupt);
387 	if (rk8xx->irq < 0) {
388 		printf("Failed to request rk8xx irq, ret=%d\n", rk8xx->irq);
389 		return rk8xx->irq;
390 	}
391 
392 	val = dev_read_u32_default(dev, "long-press-off-time-sec", 0);
393 	if (val <= 6)
394 		rk8xx->lp_off_time = RK8XX_LP_TIME_6S;
395 	else if (val <= 8)
396 		rk8xx->lp_off_time = RK8XX_LP_TIME_8S;
397 	else if (val <= 10)
398 		rk8xx->lp_off_time = RK8XX_LP_TIME_10S;
399 	else
400 		rk8xx->lp_off_time = RK8XX_LP_TIME_12S;
401 
402 	val = dev_read_u32_default(dev, "long-press-restart", 0);
403 	if (val)
404 		rk8xx->lp_action = RK8XX_LP_RESTART;
405 	else
406 		rk8xx->lp_action = RK8XX_LP_OFF;
407 
408 	val = dev_read_u32_default(dev, "not-save-power-en", 0);
409 	rk8xx->not_save_power_en = val;
410 
411 	val = dev_read_bool(dev, "vsys-off-shutdown");
412 	rk8xx->sys_can_sd = val;
413 
414 	return 0;
415 }
416 
417 static int rk8xx_irq_chip_init(struct udevice *dev)
418 {
419 	struct rk8xx_priv *priv = dev_get_priv(dev);
420 	struct virq_chip *irq_chip = NULL;
421 	__maybe_unused int irq_plugout = 1;
422 	int ret;
423 
424 	switch (priv->variant) {
425 	case RK808_ID:
426 		irq_chip = &rk808_irq_chip;
427 		break;
428 	case RK805_ID:
429 		irq_chip = &rk805_irq_chip;
430 		irq_plugout = 0;
431 		break;
432 	case RK816_ID:
433 		irq_chip = &rk816_irq_chip;
434 		break;
435 	case RK818_ID:
436 		irq_chip = &rk818_irq_chip;
437 		break;
438 	case RK809_ID:
439 	case RK817_ID:
440 		irq_chip = &rk817_irq_chip;
441 		break;
442 	default:
443 		return -EINVAL;
444 	}
445 
446 	if (irq_chip) {
447 		ret = virq_add_chip(dev, irq_chip, priv->irq);
448 		if (ret) {
449 			printf("Failed to add irqchip(irq=%d), ret=%d\n",
450 			       priv->irq, ret);
451 			return ret;
452 		}
453 
454 		priv->irq_chip = irq_chip;
455 
456 #ifdef CONFIG_DM_CHARGE_DISPLAY
457 		int irq;
458 
459 		if (irq_plugout) {
460 			irq = virq_to_irq(irq_chip, RK8XX_IRQ_PLUG_OUT);
461 			if (irq < 0) {
462 				printf("Failed to register plugout irq, ret=%d\n", irq);
463 				return irq;
464 			}
465 			irq_install_handler(irq, rk8xx_plug_out_handler, dev);
466 			irq_handler_enable_suspend_only(irq);
467 		}
468 #endif
469 	}
470 
471 	return 0;
472 }
473 #else
474 static inline int rk8xx_ofdata_to_platdata(struct udevice *dev) { return 0; }
475 static inline int rk8xx_irq_chip_init(struct udevice *dev) { return 0; }
476 #endif
477 
478 static int rk8xx_probe(struct udevice *dev)
479 {
480 	struct rk8xx_priv *priv = dev_get_priv(dev);
481 	struct reg_data *init_current = NULL;
482 	struct reg_data *init_data = NULL;
483 	int init_current_num = 0;
484 	int init_data_num = 0;
485 	int ret = 0, i, show_variant;
486 	uint8_t msb, lsb, id_msb, id_lsb;
487 	uint8_t on_source = 0, off_source = 0;
488 	uint8_t pwron_key = 0, lp_off_msk = 0, lp_act_msk = 0;
489 	uint8_t power_en0, power_en1, power_en2, power_en3;
490 	uint8_t on, off;
491 	uint8_t value;
492 
493 	/* read Chip variant */
494 	if (device_is_compatible(dev, "rockchip,rk817") ||
495 	    device_is_compatible(dev, "rockchip,rk809")) {
496 		id_msb = RK817_ID_MSB;
497 		id_lsb = RK817_ID_LSB;
498 	} else {
499 		id_msb = ID_MSB;
500 		id_lsb = ID_LSB;
501 	}
502 
503 	ret = rk8xx_read(dev, id_msb, &msb, 1);
504 	if (ret)
505 		return ret;
506 	ret = rk8xx_read(dev, id_lsb, &lsb, 1);
507 	if (ret)
508 		return ret;
509 
510 	priv->variant = ((msb << 8) | lsb) & RK8XX_ID_MSK;
511 	show_variant = priv->variant;
512 	switch (priv->variant) {
513 	case RK808_ID:
514 		show_variant = 0x808;	/* RK808 hardware ID is 0 */
515 		pwron_key = RK8XX_DEVCTRL_REG;
516 		lp_off_msk = RK8XX_LP_OFF_MSK;
517 		break;
518 	case RK805_ID:
519 	case RK816_ID:
520 		on_source = RK8XX_ON_SOURCE;
521 		off_source = RK8XX_OFF_SOURCE;
522 		pwron_key = RK8XX_DEVCTRL_REG;
523 		lp_off_msk = RK8XX_LP_OFF_MSK;
524 		lp_act_msk = RK8XX_LP_ACTION_MSK;
525 		break;
526 	case RK818_ID:
527 		on_source = RK8XX_ON_SOURCE;
528 		off_source = RK8XX_OFF_SOURCE;
529 		pwron_key = RK8XX_DEVCTRL_REG;
530 		lp_off_msk = RK8XX_LP_OFF_MSK;
531 		lp_act_msk = RK8XX_LP_ACTION_MSK;
532 		/* set current if no fuel gauge */
533 		if (!ofnode_valid(dev_read_subnode(dev, "battery"))) {
534 			init_current = rk818_init_current;
535 			init_current_num = ARRAY_SIZE(rk818_init_current);
536 		}
537 		break;
538 	case RK809_ID:
539 	case RK817_ID:
540 		if (device_is_compatible(dev, "rockchip,rk809") && (priv->variant != RK809_ID)) {
541 			dev_err(dev, "the dts is RK809, the hardware is RK817\n");
542 			run_command("download", 0);
543 		}
544 
545 		if (device_is_compatible(dev, "rockchip,rk817") && (priv->variant != RK817_ID)) {
546 			dev_err(dev, "the dts is RK817, the hardware is RK809\n");
547 			run_command("download", 0);
548 		}
549 
550 		on_source = RK817_ON_SOURCE;
551 		off_source = RK817_OFF_SOURCE;
552 		pwron_key = RK817_PWRON_KEY;
553 		lp_off_msk = RK8XX_LP_OFF_MSK;
554 		lp_act_msk = RK8XX_LP_ACTION_MSK;
555 		init_data = rk817_init_reg;
556 		init_data_num = ARRAY_SIZE(rk817_init_reg);
557 
558 		/* whether the system voltage can be shutdown in PWR_off mode */
559 		if (priv->sys_can_sd) {
560 			ret = rk8xx_read(dev, RK817_PMIC_CHRG_TERM, &value, 1);
561 			if (ret)
562 				return ret;
563 			value |= 0x80;
564 			ret = rk8xx_write(dev, RK817_PMIC_CHRG_TERM, &value, 1);
565 			if (ret)
566 				return ret;
567 		} else {
568 			ret = rk8xx_read(dev, RK817_PMIC_CHRG_TERM, &value, 1);
569 			if (ret)
570 				return ret;
571 			value &= 0x7f;
572 			ret = rk8xx_write(dev, RK817_PMIC_CHRG_TERM, &value, 1);
573 			if (ret)
574 				return ret;
575 		}
576 
577 		/* judge whether save the PMIC_POWER_EN register */
578 		if (priv->not_save_power_en)
579 			break;
580 
581 		ret = rk8xx_read(dev, RK817_POWER_EN0, &power_en0, 1);
582 		if (ret)
583 			return ret;
584 		ret = rk8xx_read(dev, RK817_POWER_EN1, &power_en1, 1);
585 		if (ret)
586 			return ret;
587 		ret = rk8xx_read(dev, RK817_POWER_EN2, &power_en2, 1);
588 		if (ret)
589 			return ret;
590 		ret = rk8xx_read(dev, RK817_POWER_EN3, &power_en3, 1);
591 		if (ret)
592 			return ret;
593 
594 		value = (power_en0 & 0x0f) | ((power_en1 & 0x0f) << 4);
595 		rk8xx_write(dev, RK817_POWER_EN_SAVE0, &value, 1);
596 		value = (power_en2 & 0x0f) | ((power_en3 & 0x0f) << 4);
597 		rk8xx_write(dev, RK817_POWER_EN_SAVE1, &value, 1);
598 		break;
599 	default:
600 		printf("Unknown PMIC: RK%x!!\n", priv->variant);
601 		return -EINVAL;
602 	}
603 
604 	/* common init */
605 	for (i = 0; i < init_data_num; i++) {
606 		ret = pmic_clrsetbits(dev,
607 				      init_data[i].reg,
608 				      init_data[i].mask,
609 				      init_data[i].val);
610 		if (ret < 0) {
611 			printf("%s: i2c set reg 0x%x failed, ret=%d\n",
612 			       __func__, init_data[i].reg, ret);
613 		}
614 	}
615 
616 	/* current init */
617 	for (i = 0; i < init_current_num; i++) {
618 		ret = pmic_clrsetbits(dev,
619 				      init_current[i].reg,
620 				      init_current[i].mask,
621 				      init_current[i].val);
622 		if (ret < 0) {
623 			printf("%s: i2c set reg 0x%x failed, ret=%d\n",
624 			       __func__, init_current[i].reg, ret);
625 		}
626 	}
627 
628 	printf("PMIC:  RK%x ", show_variant);
629 
630 	if (on_source && off_source) {
631 		rk8xx_read(dev, on_source, &on, 1);
632 		rk8xx_read(dev, off_source, &off, 1);
633 		printf("(on=0x%02x, off=0x%02x)", on, off);
634 	}
635 	printf("\n");
636 
637 	if (pwron_key) {
638 		ret = rk8xx_read(dev, pwron_key, &value, 1);
639 		if (ret)
640 			return ret;
641 		value &= ~(lp_off_msk | lp_act_msk);
642 		if (lp_off_msk)
643 			value |= priv->lp_off_time;
644 		if (lp_act_msk)
645 			value |= priv->lp_action;
646 		rk8xx_write(dev, pwron_key, &value, 1);
647 	}
648 
649 	ret = rk8xx_irq_chip_init(dev);
650 	if (ret) {
651 		printf("IRQ chip initial failed\n");
652 		return ret;
653 	}
654 
655 	return 0;
656 }
657 
658 static struct dm_pmic_ops rk8xx_ops = {
659 	.reg_count = rk8xx_reg_count,
660 	.read = rk8xx_read,
661 	.write = rk8xx_write,
662 	.suspend = rk8xx_suspend,
663 	.resume = rk8xx_resume,
664 	.shutdown = rk8xx_shutdown,
665 };
666 
667 static const struct udevice_id rk8xx_ids[] = {
668 	{ .compatible = "rockchip,rk805" },
669 	{ .compatible = "rockchip,rk808" },
670 	{ .compatible = "rockchip,rk809" },
671 	{ .compatible = "rockchip,rk816" },
672 	{ .compatible = "rockchip,rk817" },
673 	{ .compatible = "rockchip,rk818" },
674 	{ }
675 };
676 
677 U_BOOT_DRIVER(pmic_rk8xx) = {
678 	.name = "rk8xx pmic",
679 	.id = UCLASS_PMIC,
680 	.of_match = rk8xx_ids,
681 #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
682 	.bind = rk8xx_bind,
683 #endif
684 	.ofdata_to_platdata = rk8xx_ofdata_to_platdata,
685 	.priv_auto_alloc_size = sizeof(struct rk8xx_priv),
686 	.probe = rk8xx_probe,
687 	.ops = &rk8xx_ops,
688 };
689