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