1 /* 2 * Copyright (C) EETS GmbH, 2017, Felix Brack <f.brack@eets.ch> 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <dm.h> 9 #include <i2c.h> 10 #include <power/pmic.h> 11 #include <power/regulator.h> 12 #include <power/tps65910_pmic.h> 13 14 DECLARE_GLOBAL_DATA_PTR; 15 16 static const struct pmic_child_info pmic_children_info[] = { 17 { .prefix = "ldo_", .driver = TPS65910_LDO_DRIVER }, 18 { .prefix = "buck_", .driver = TPS65910_BUCK_DRIVER }, 19 { .prefix = "boost_", .driver = TPS65910_BOOST_DRIVER }, 20 { }, 21 }; 22 23 static int pmic_tps65910_reg_count(struct udevice *dev) 24 { 25 return TPS65910_NUM_REGS; 26 } 27 28 static int pmic_tps65910_write(struct udevice *dev, uint reg, const u8 *buffer, 29 int len) 30 { 31 int ret; 32 33 ret = dm_i2c_write(dev, reg, buffer, len); 34 if (ret) 35 pr_err("%s write error on register %02x\n", dev->name, reg); 36 37 return ret; 38 } 39 40 static int pmic_tps65910_read(struct udevice *dev, uint reg, u8 *buffer, 41 int len) 42 { 43 int ret; 44 45 ret = dm_i2c_read(dev, reg, buffer, len); 46 if (ret) 47 pr_err("%s read error on register %02x\n", dev->name, reg); 48 49 return ret; 50 } 51 52 static int pmic_tps65910_bind(struct udevice *dev) 53 { 54 ofnode regulators_node; 55 int children; 56 57 regulators_node = dev_read_subnode(dev, "regulators"); 58 if (!ofnode_valid(regulators_node)) { 59 debug("%s regulators subnode not found\n", dev->name); 60 return -EINVAL; 61 } 62 63 children = pmic_bind_children(dev, regulators_node, pmic_children_info); 64 if (!children) 65 debug("%s has no children (regulators)\n", dev->name); 66 67 return 0; 68 } 69 70 static int pmic_tps65910_probe(struct udevice *dev) 71 { 72 /* use I2C control interface instead of I2C smartreflex interface to 73 * access smartrefelex registers VDD1_OP_REG, VDD1_SR_REG, VDD2_OP_REG 74 * and VDD2_SR_REG 75 */ 76 return pmic_clrsetbits(dev, TPS65910_REG_DEVICE_CTRL, 0, 77 TPS65910_I2C_SEL_MASK); 78 } 79 80 static struct dm_pmic_ops pmic_tps65910_ops = { 81 .reg_count = pmic_tps65910_reg_count, 82 .read = pmic_tps65910_read, 83 .write = pmic_tps65910_write, 84 }; 85 86 static const struct udevice_id pmic_tps65910_match[] = { 87 { .compatible = "ti,tps65910" }, 88 { /* sentinel */ } 89 }; 90 91 U_BOOT_DRIVER(pmic_tps65910) = { 92 .name = "pmic_tps65910", 93 .id = UCLASS_PMIC, 94 .of_match = pmic_tps65910_match, 95 .bind = pmic_tps65910_bind, 96 .probe = pmic_tps65910_probe, 97 .ops = &pmic_tps65910_ops, 98 }; 99