xref: /OK3568_Linux_fs/u-boot/drivers/power/pmic/rk8xx.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 	/* GATE pin function: gate function */
156 	{ RK817_GPIO_INT_CFG, 0x00, 0x20 },
157 #ifdef CONFIG_DM_CHARGE_DISPLAY
158 	/* Set pmic_int active low */
159 	{ RK817_GPIO_INT_CFG,  0x00, 0x02 },
160 #endif
161 };
162 
163 static struct reg_data rk818_init_current[] = {
164 	{ REG_USB_CTRL, 0x07, 0x0f}, /* 2A */
165 };
166 
167 static const struct pmic_child_info pmic_children_info[] = {
168 	{ .prefix = "DCDC", .driver = "rk8xx_buck"},
169 	{ .prefix = "LDO", .driver = "rk8xx_ldo"},
170 	{ .prefix = "SWITCH", .driver = "rk8xx_switch"},
171 	{ },
172 };
173 
174 static const struct pmic_child_info power_key_info[] = {
175 	{ .prefix = "pwrkey", .driver = "rk8xx_pwrkey"},
176 	{ },
177 };
178 
179 static const struct pmic_child_info rtc_info[] = {
180 	{ .prefix = "rtc", .driver = "rk8xx_rtc"},
181 	{ },
182 };
183 
184 static const struct pmic_child_info fuel_gauge_info[] = {
185 	{ .addr = "1c", .prefix = "battery", .driver = "rk818_fg"},
186 	{ .addr = "20", .prefix = "battery", .driver = "rk817_fg"},
187 	{ .addr = "1a", .prefix = "battery", .driver = "rk816_fg"},
188 	{ },
189 };
190 
191 static const struct pmic_child_info rk817_codec_info[] = {
192 	{ .prefix = "codec", .driver = "rk817_codec"},
193 	{ },
194 };
195 
rk8xx_reg_count(struct udevice * dev)196 static int rk8xx_reg_count(struct udevice *dev)
197 {
198 	struct rk8xx_priv *priv = dev_get_priv(dev);
199 
200 	switch (priv->variant) {
201 	case RK809_ID:
202 	case RK817_ID:
203 		return RK817_NUM_OF_REGS;
204 	default:
205 		return RK808_NUM_OF_REGS;
206 	}
207 }
208 
rk8xx_write(struct udevice * dev,uint reg,const uint8_t * buff,int len)209 static int rk8xx_write(struct udevice *dev, uint reg, const uint8_t *buff,
210 			  int len)
211 {
212 	int ret;
213 
214 	ret = dm_i2c_write(dev, reg, buff, len);
215 	if (ret) {
216 		printf("%s: write reg 0x%02x failed, ret=%d\n", __func__, reg, ret);
217 		return ret;
218 	}
219 
220 	return 0;
221 }
222 
rk8xx_read(struct udevice * dev,uint reg,uint8_t * buff,int len)223 static int rk8xx_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
224 {
225 	int ret;
226 
227 	ret = dm_i2c_read(dev, reg, buff, len);
228 	if (ret) {
229 		printf("%s: read reg 0x%02x failed, ret=%d\n", __func__, reg, ret);
230 		return ret;
231 	}
232 
233 	return 0;
234 }
235 
rk8xx_suspend(struct udevice * dev)236 static int rk8xx_suspend(struct udevice *dev)
237 {
238 	struct rk8xx_priv *priv = dev_get_priv(dev);
239 	int ret = 0;
240 	u8 val;
241 
242 	switch (priv->variant) {
243 	case RK809_ID:
244 	case RK817_ID:
245 		/* pmic_sleep active high */
246 		ret = rk8xx_read(dev, RK817_PMIC_SYS_CFG3, &val, 1);
247 		if (ret)
248 			return ret;
249 		priv->sleep_pin = val;
250 		val &= ~0x38;
251 		val |= 0x28;
252 		ret = rk8xx_write(dev, RK817_PMIC_SYS_CFG3, &val, 1);
253 		break;
254 	default:
255 		return 0;
256 	}
257 
258 	return ret;
259 }
260 
rk8xx_resume(struct udevice * dev)261 static int rk8xx_resume(struct udevice *dev)
262 {
263 	struct rk8xx_priv *priv = dev_get_priv(dev);
264 	int ret = 0;
265 
266 	switch (priv->variant) {
267 	case RK809_ID:
268 	case RK817_ID:
269 		ret = rk8xx_write(dev, RK817_PMIC_SYS_CFG3, &priv->sleep_pin, 1);
270 		break;
271 	default:
272 		return 0;
273 	}
274 
275 	return ret;
276 }
277 
rk8xx_shutdown(struct udevice * dev)278 static int rk8xx_shutdown(struct udevice *dev)
279 {
280 	struct rk8xx_priv *priv = dev_get_priv(dev);
281 	u8 val, dev_off, devctrl_reg;
282 	int ret = 0;
283 
284 	switch (priv->variant) {
285 	case RK808_ID:
286 		devctrl_reg = REG_DEVCTRL;
287 		dev_off = BIT(3);
288 		break;
289 	case RK805_ID:
290 	case RK816_ID:
291 	case RK818_ID:
292 		devctrl_reg = REG_DEVCTRL;
293 		dev_off = BIT(0);
294 		break;
295 	case RK809_ID:
296 	case RK817_ID:
297 		devctrl_reg = RK817_REG_SYS_CFG3;
298 		dev_off = BIT(0);
299 		break;
300 	default:
301 		printf("Unknown PMIC: RK%x\n", priv->variant);
302 		return -EINVAL;
303 	}
304 
305 	ret = rk8xx_read(dev, devctrl_reg, &val, 1);
306 	if (ret)
307 		return ret;
308 
309 	val |= dev_off;
310 	ret = rk8xx_write(dev, devctrl_reg, &val, 1);
311 	if (ret)
312 		return ret;
313 
314 	return 0;
315 }
316 
317 #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
rk8xx_bind(struct udevice * dev)318 static int rk8xx_bind(struct udevice *dev)
319 {
320 	ofnode regulators_node;
321 	int children;
322 
323 	regulators_node = dev_read_subnode(dev, "regulators");
324 	if (!ofnode_valid(regulators_node)) {
325 		debug("%s: %s regulators subnode not found!\n", __func__,
326 		      dev->name);
327 		return -ENXIO;
328 	}
329 
330 	debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
331 
332 	children = pmic_bind_children(dev, regulators_node, pmic_children_info);
333 	if (!children)
334 		debug("%s: %s - no child found\n", __func__, dev->name);
335 
336 	children = pmic_bind_children(dev, dev->node, power_key_info);
337 	if (!children)
338 		debug("%s: %s - no child found\n", __func__, dev->name);
339 
340 	children = pmic_bind_children(dev, dev->node, rtc_info);
341 	if (!children)
342 		debug("%s: %s - no child found\n", __func__, dev->name);
343 
344 	children = pmic_bind_children(dev, dev->node, fuel_gauge_info);
345 	if (!children)
346 		debug("%s: %s - no child found\n", __func__, dev->name);
347 
348 	children = pmic_bind_children(dev, dev->node, rk817_codec_info);
349 	if (!children)
350 		debug("%s: %s - no child found\n", __func__, dev->name);
351 
352 	/* Always return success for this device */
353 	return 0;
354 }
355 #endif
356 
357 #if CONFIG_IS_ENABLED(IRQ)
358 /*
359  * When system suspend during U-Boot charge, make sure the plugout event
360  * be able to wakeup cpu in wfi/wfe state.
361  */
362 #ifdef CONFIG_DM_CHARGE_DISPLAY
rk8xx_plug_out_handler(int irq,void * data)363 static void rk8xx_plug_out_handler(int irq, void *data)
364 {
365 	printf("Plug out interrupt\n");
366 }
367 #endif
368 
rk8xx_ofdata_to_platdata(struct udevice * dev)369 static int rk8xx_ofdata_to_platdata(struct udevice *dev)
370 {
371 	struct rk8xx_priv *rk8xx = dev_get_priv(dev);
372 	u32 interrupt, phandle, val;
373 	int ret;
374 
375 	phandle = dev_read_u32_default(dev, "interrupt-parent", -ENODATA);
376 	if (phandle == -ENODATA) {
377 		printf("Read 'interrupt-parent' failed, ret=%d\n", phandle);
378 		return phandle;
379 	}
380 
381 	ret = dev_read_u32_array(dev, "interrupts", &interrupt, 1);
382 	if (ret) {
383 		printf("Read 'interrupts' failed, ret=%d\n", ret);
384 		return ret;
385 	}
386 
387 	rk8xx->irq = phandle_gpio_to_irq(phandle, interrupt);
388 	if (rk8xx->irq < 0) {
389 		printf("Failed to request rk8xx irq, ret=%d\n", rk8xx->irq);
390 		return rk8xx->irq;
391 	}
392 
393 	val = dev_read_u32_default(dev, "long-press-off-time-sec", 0);
394 	if (val <= 6)
395 		rk8xx->lp_off_time = RK8XX_LP_TIME_6S;
396 	else if (val <= 8)
397 		rk8xx->lp_off_time = RK8XX_LP_TIME_8S;
398 	else if (val <= 10)
399 		rk8xx->lp_off_time = RK8XX_LP_TIME_10S;
400 	else
401 		rk8xx->lp_off_time = RK8XX_LP_TIME_12S;
402 
403 	val = dev_read_u32_default(dev, "long-press-restart", 0);
404 	if (val)
405 		rk8xx->lp_action = RK8XX_LP_RESTART;
406 	else
407 		rk8xx->lp_action = RK8XX_LP_OFF;
408 
409 	val = dev_read_u32_default(dev, "not-save-power-en", 0);
410 	rk8xx->not_save_power_en = val;
411 
412 	val = dev_read_bool(dev, "vsys-off-shutdown");
413 	rk8xx->sys_can_sd = val;
414 
415 	return 0;
416 }
417 
rk8xx_irq_chip_init(struct udevice * dev)418 static int rk8xx_irq_chip_init(struct udevice *dev)
419 {
420 	struct rk8xx_priv *priv = dev_get_priv(dev);
421 	struct virq_chip *irq_chip = NULL;
422 	__maybe_unused int irq_plugout = 1;
423 	int ret;
424 
425 	switch (priv->variant) {
426 	case RK808_ID:
427 		irq_chip = &rk808_irq_chip;
428 		break;
429 	case RK805_ID:
430 		irq_chip = &rk805_irq_chip;
431 		irq_plugout = 0;
432 		break;
433 	case RK816_ID:
434 		irq_chip = &rk816_irq_chip;
435 		break;
436 	case RK818_ID:
437 		irq_chip = &rk818_irq_chip;
438 		break;
439 	case RK809_ID:
440 	case RK817_ID:
441 		irq_chip = &rk817_irq_chip;
442 		break;
443 	default:
444 		return -EINVAL;
445 	}
446 
447 	if (irq_chip) {
448 		ret = virq_add_chip(dev, irq_chip, priv->irq);
449 		if (ret) {
450 			printf("Failed to add irqchip(irq=%d), ret=%d\n",
451 			       priv->irq, ret);
452 			return ret;
453 		}
454 
455 		priv->irq_chip = irq_chip;
456 
457 #ifdef CONFIG_DM_CHARGE_DISPLAY
458 		int irq;
459 
460 		if (irq_plugout) {
461 			irq = virq_to_irq(irq_chip, RK8XX_IRQ_PLUG_OUT);
462 			if (irq < 0) {
463 				printf("Failed to register plugout irq, ret=%d\n", irq);
464 				return irq;
465 			}
466 			irq_install_handler(irq, rk8xx_plug_out_handler, dev);
467 			irq_handler_enable_suspend_only(irq);
468 		}
469 #endif
470 	}
471 
472 	return 0;
473 }
474 #else
rk8xx_ofdata_to_platdata(struct udevice * dev)475 static inline int rk8xx_ofdata_to_platdata(struct udevice *dev) { return 0; }
rk8xx_irq_chip_init(struct udevice * dev)476 static inline int rk8xx_irq_chip_init(struct udevice *dev) { return 0; }
477 #endif
478 
rk8xx_probe(struct udevice * dev)479 static int rk8xx_probe(struct udevice *dev)
480 {
481 	struct rk8xx_priv *priv = dev_get_priv(dev);
482 	struct reg_data *init_current = NULL;
483 	struct reg_data *init_data = NULL;
484 	int init_current_num = 0;
485 	int init_data_num = 0;
486 	int ret = 0, i, show_variant;
487 	uint8_t msb, lsb, id_msb, id_lsb;
488 	uint8_t on_source = 0, off_source = 0;
489 	uint8_t pwron_key = 0, lp_off_msk = 0, lp_act_msk = 0;
490 	uint8_t power_en0, power_en1, power_en2, power_en3;
491 	uint8_t on, off;
492 	uint8_t value;
493 
494 	/* read Chip variant */
495 	if (device_is_compatible(dev, "rockchip,rk817") ||
496 	    device_is_compatible(dev, "rockchip,rk809")) {
497 		id_msb = RK817_ID_MSB;
498 		id_lsb = RK817_ID_LSB;
499 	} else {
500 		id_msb = ID_MSB;
501 		id_lsb = ID_LSB;
502 	}
503 
504 	ret = rk8xx_read(dev, id_msb, &msb, 1);
505 	if (ret)
506 		return ret;
507 	ret = rk8xx_read(dev, id_lsb, &lsb, 1);
508 	if (ret)
509 		return ret;
510 
511 	priv->variant = ((msb << 8) | lsb) & RK8XX_ID_MSK;
512 	show_variant = priv->variant;
513 	switch (priv->variant) {
514 	case RK808_ID:
515 		show_variant = 0x808;	/* RK808 hardware ID is 0 */
516 		pwron_key = RK8XX_DEVCTRL_REG;
517 		lp_off_msk = RK8XX_LP_OFF_MSK;
518 		break;
519 	case RK805_ID:
520 	case RK816_ID:
521 		on_source = RK8XX_ON_SOURCE;
522 		off_source = RK8XX_OFF_SOURCE;
523 		pwron_key = RK8XX_DEVCTRL_REG;
524 		lp_off_msk = RK8XX_LP_OFF_MSK;
525 		lp_act_msk = RK8XX_LP_ACTION_MSK;
526 		break;
527 	case RK818_ID:
528 		on_source = RK8XX_ON_SOURCE;
529 		off_source = RK8XX_OFF_SOURCE;
530 		pwron_key = RK8XX_DEVCTRL_REG;
531 		lp_off_msk = RK8XX_LP_OFF_MSK;
532 		lp_act_msk = RK8XX_LP_ACTION_MSK;
533 		/* set current if no fuel gauge */
534 		if (!ofnode_valid(dev_read_subnode(dev, "battery"))) {
535 			init_current = rk818_init_current;
536 			init_current_num = ARRAY_SIZE(rk818_init_current);
537 		}
538 		break;
539 	case RK809_ID:
540 	case RK817_ID:
541 		if (device_is_compatible(dev, "rockchip,rk809") && (priv->variant != RK809_ID)) {
542 			dev_err(dev, "the dts is RK809, the hardware is RK817\n");
543 			run_command("download", 0);
544 		}
545 
546 		if (device_is_compatible(dev, "rockchip,rk817") && (priv->variant != RK817_ID)) {
547 			dev_err(dev, "the dts is RK817, the hardware is RK809\n");
548 			run_command("download", 0);
549 		}
550 
551 		on_source = RK817_ON_SOURCE;
552 		off_source = RK817_OFF_SOURCE;
553 		pwron_key = RK817_PWRON_KEY;
554 		lp_off_msk = RK8XX_LP_OFF_MSK;
555 		lp_act_msk = RK8XX_LP_ACTION_MSK;
556 		init_data = rk817_init_reg;
557 		init_data_num = ARRAY_SIZE(rk817_init_reg);
558 
559 		/* whether the system voltage can be shutdown in PWR_off mode */
560 		if (priv->sys_can_sd) {
561 			ret = rk8xx_read(dev, RK817_PMIC_CHRG_TERM, &value, 1);
562 			if (ret)
563 				return ret;
564 			value |= 0x80;
565 			ret = rk8xx_write(dev, RK817_PMIC_CHRG_TERM, &value, 1);
566 			if (ret)
567 				return ret;
568 		} else {
569 			ret = rk8xx_read(dev, RK817_PMIC_CHRG_TERM, &value, 1);
570 			if (ret)
571 				return ret;
572 			value &= 0x7f;
573 			ret = rk8xx_write(dev, RK817_PMIC_CHRG_TERM, &value, 1);
574 			if (ret)
575 				return ret;
576 		}
577 
578 		/* judge whether save the PMIC_POWER_EN register */
579 		if (!priv->not_save_power_en) {
580 			ret = rk8xx_read(dev, RK817_POWER_EN0, &power_en0, 1);
581 			if (ret)
582 				return ret;
583 			ret = rk8xx_read(dev, RK817_POWER_EN1, &power_en1, 1);
584 			if (ret)
585 				return ret;
586 			ret = rk8xx_read(dev, RK817_POWER_EN2, &power_en2, 1);
587 			if (ret)
588 				return ret;
589 			ret = rk8xx_read(dev, RK817_POWER_EN3, &power_en3, 1);
590 			if (ret)
591 				return ret;
592 
593 			value = (power_en0 & 0x0f) | ((power_en1 & 0x0f) << 4);
594 			rk8xx_write(dev, RK817_POWER_EN_SAVE0, &value, 1);
595 			value = (power_en2 & 0x0f) | ((power_en3 & 0x0f) << 4);
596 			rk8xx_write(dev, RK817_POWER_EN_SAVE1, &value, 1);
597 		}
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