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