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