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