xref: /rk3399_rockchip-uboot/drivers/power/pmic/pfuze100.c (revision 90aa625c9a9e1fb7a2f001fd8e50099bacaf92b8)
11c1f6076SPeng Fan /*
21c1f6076SPeng Fan  * Copyright (C) 2015 Freescale Semiconductor, Inc
31c1f6076SPeng Fan  * Peng Fan <Peng.Fan@freescale.com>
41c1f6076SPeng Fan  *
51c1f6076SPeng Fan  * SPDX-License-Identifier:      GPL-2.0+
61c1f6076SPeng Fan  */
71c1f6076SPeng Fan 
81c1f6076SPeng Fan #include <common.h>
91c1f6076SPeng Fan #include <fdtdec.h>
101c1f6076SPeng Fan #include <errno.h>
111c1f6076SPeng Fan #include <dm.h>
121c1f6076SPeng Fan #include <i2c.h>
131c1f6076SPeng Fan #include <power/pmic.h>
141c1f6076SPeng Fan #include <power/regulator.h>
151c1f6076SPeng Fan #include <power/pfuze100_pmic.h>
161c1f6076SPeng Fan 
171c1f6076SPeng Fan DECLARE_GLOBAL_DATA_PTR;
181c1f6076SPeng Fan 
191c1f6076SPeng Fan static const struct pmic_child_info pmic_children_info[] = {
201c1f6076SPeng Fan 	/* sw[x], swbst */
211c1f6076SPeng Fan 	{ .prefix = "s", .driver = PFUZE100_REGULATOR_DRIVER },
221c1f6076SPeng Fan 	/* vgen[x], vsnvs, vcc, v33, vcc_sd */
231c1f6076SPeng Fan 	{ .prefix = "v", .driver = PFUZE100_REGULATOR_DRIVER },
241c1f6076SPeng Fan 	{ },
251c1f6076SPeng Fan };
261c1f6076SPeng Fan 
pfuze100_reg_count(struct udevice * dev)271c1f6076SPeng Fan static int pfuze100_reg_count(struct udevice *dev)
281c1f6076SPeng Fan {
291c1f6076SPeng Fan 	return PFUZE100_NUM_OF_REGS;
301c1f6076SPeng Fan }
311c1f6076SPeng Fan 
pfuze100_write(struct udevice * dev,uint reg,const uint8_t * buff,int len)321c1f6076SPeng Fan static int pfuze100_write(struct udevice *dev, uint reg, const uint8_t *buff,
331c1f6076SPeng Fan 			  int len)
341c1f6076SPeng Fan {
351c1f6076SPeng Fan 	if (dm_i2c_write(dev, reg, buff, len)) {
36*90aa625cSMasahiro Yamada 		pr_err("write error to device: %p register: %#x!", dev, reg);
371c1f6076SPeng Fan 		return -EIO;
381c1f6076SPeng Fan 	}
391c1f6076SPeng Fan 
401c1f6076SPeng Fan 	return 0;
411c1f6076SPeng Fan }
421c1f6076SPeng Fan 
pfuze100_read(struct udevice * dev,uint reg,uint8_t * buff,int len)431c1f6076SPeng Fan static int pfuze100_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
441c1f6076SPeng Fan {
451c1f6076SPeng Fan 	if (dm_i2c_read(dev, reg, buff, len)) {
46*90aa625cSMasahiro Yamada 		pr_err("read error from device: %p register: %#x!", dev, reg);
471c1f6076SPeng Fan 		return -EIO;
481c1f6076SPeng Fan 	}
491c1f6076SPeng Fan 
501c1f6076SPeng Fan 	return 0;
511c1f6076SPeng Fan }
521c1f6076SPeng Fan 
pfuze100_bind(struct udevice * dev)531c1f6076SPeng Fan static int pfuze100_bind(struct udevice *dev)
541c1f6076SPeng Fan {
557a869e6cSSimon Glass 	ofnode regulators_node;
561c1f6076SPeng Fan 	int children;
571c1f6076SPeng Fan 
587a869e6cSSimon Glass 	regulators_node = dev_read_subnode(dev, "regulators");
597a869e6cSSimon Glass 	if (!ofnode_valid(regulators_node)) {
601c1f6076SPeng Fan 		debug("%s: %s regulators subnode not found!", __func__,
611c1f6076SPeng Fan 		      dev->name);
621c1f6076SPeng Fan 		return -ENXIO;
631c1f6076SPeng Fan 	}
641c1f6076SPeng Fan 
651c1f6076SPeng Fan 	debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
661c1f6076SPeng Fan 
671c1f6076SPeng Fan 	children = pmic_bind_children(dev, regulators_node, pmic_children_info);
681c1f6076SPeng Fan 	if (!children)
691c1f6076SPeng Fan 		debug("%s: %s - no child found\n", __func__, dev->name);
701c1f6076SPeng Fan 
711c1f6076SPeng Fan 	/* Always return success for this device */
721c1f6076SPeng Fan 	return 0;
731c1f6076SPeng Fan }
741c1f6076SPeng Fan 
751c1f6076SPeng Fan static struct dm_pmic_ops pfuze100_ops = {
761c1f6076SPeng Fan 	.reg_count = pfuze100_reg_count,
771c1f6076SPeng Fan 	.read = pfuze100_read,
781c1f6076SPeng Fan 	.write = pfuze100_write,
791c1f6076SPeng Fan };
801c1f6076SPeng Fan 
811c1f6076SPeng Fan static const struct udevice_id pfuze100_ids[] = {
821c1f6076SPeng Fan 	{ .compatible = "fsl,pfuze100", .data = PFUZE100, },
831c1f6076SPeng Fan 	{ .compatible = "fsl,pfuze200", .data = PFUZE200, },
841c1f6076SPeng Fan 	{ .compatible = "fsl,pfuze3000", .data = PFUZE3000, },
851c1f6076SPeng Fan 	{ }
861c1f6076SPeng Fan };
871c1f6076SPeng Fan 
881c1f6076SPeng Fan U_BOOT_DRIVER(pmic_pfuze100) = {
891c1f6076SPeng Fan 	.name = "pfuze100 pmic",
901c1f6076SPeng Fan 	.id = UCLASS_PMIC,
911c1f6076SPeng Fan 	.of_match = pfuze100_ids,
921c1f6076SPeng Fan 	.bind = pfuze100_bind,
931c1f6076SPeng Fan 	.ops = &pfuze100_ops,
941c1f6076SPeng Fan };
95