1 /* 2 * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com> 3 * Keerthy <j-keerthy@ti.com> 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8 #include <common.h> 9 #include <fdtdec.h> 10 #include <errno.h> 11 #include <dm.h> 12 #include <i2c.h> 13 #include <power/pmic.h> 14 #include <power/regulator.h> 15 #include <power/palmas.h> 16 #include <dm/device.h> 17 18 DECLARE_GLOBAL_DATA_PTR; 19 20 static const struct pmic_child_info pmic_children_info[] = { 21 { .prefix = "ldo", .driver = PALMAS_LDO_DRIVER }, 22 { .prefix = "smps", .driver = PALMAS_SMPS_DRIVER }, 23 { }, 24 }; 25 26 static int palmas_write(struct udevice *dev, uint reg, const uint8_t *buff, 27 int len) 28 { 29 if (dm_i2c_write(dev, reg, buff, len)) { 30 error("write error to device: %p register: %#x!", dev, reg); 31 return -EIO; 32 } 33 34 return 0; 35 } 36 37 static int palmas_read(struct udevice *dev, uint reg, uint8_t *buff, int len) 38 { 39 if (dm_i2c_read(dev, reg, buff, len)) { 40 error("read error from device: %p register: %#x!", dev, reg); 41 return -EIO; 42 } 43 44 return 0; 45 } 46 47 static int palmas_bind(struct udevice *dev) 48 { 49 int pmic_node = -1, regulators_node; 50 const void *blob = gd->fdt_blob; 51 int children; 52 int node = dev_of_offset(dev); 53 int subnode, len; 54 55 fdt_for_each_subnode(subnode, blob, node) { 56 const char *name; 57 char *temp; 58 59 name = fdt_get_name(blob, subnode, &len); 60 temp = strstr(name, "pmic"); 61 if (temp) { 62 pmic_node = subnode; 63 break; 64 } 65 } 66 67 if (pmic_node <= 0) { 68 debug("%s: %s pmic subnode not found!", __func__, dev->name); 69 return -ENXIO; 70 } 71 72 regulators_node = fdt_subnode_offset(blob, pmic_node, "regulators"); 73 74 if (regulators_node <= 0) { 75 debug("%s: %s reg subnode not found!", __func__, dev->name); 76 return -ENXIO; 77 } 78 79 children = pmic_bind_children(dev, regulators_node, pmic_children_info); 80 if (!children) 81 debug("%s: %s - no child found\n", __func__, dev->name); 82 83 /* Always return success for this device */ 84 return 0; 85 } 86 87 static struct dm_pmic_ops palmas_ops = { 88 .read = palmas_read, 89 .write = palmas_write, 90 }; 91 92 static const struct udevice_id palmas_ids[] = { 93 { .compatible = "ti,tps659038", .data = TPS659038 }, 94 { .compatible = "ti,tps65917" , .data = TPS65917 }, 95 { } 96 }; 97 98 U_BOOT_DRIVER(pmic_palmas) = { 99 .name = "palmas_pmic", 100 .id = UCLASS_PMIC, 101 .of_match = palmas_ids, 102 .bind = palmas_bind, 103 .ops = &palmas_ops, 104 }; 105