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