Svyatoslav Ryhel | 9c58dd6 | 2024-10-06 14:50:02 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright(C) 2024 Svyatoslav Ryhel <clamor95@gmail.com> |
| 4 | */ |
| 5 | |
| 6 | #include <dm.h> |
| 7 | #include <dm/lists.h> |
| 8 | #include <power/pmic.h> |
Svyatoslav Ryhel | 8df7d47 | 2024-10-06 14:59:54 +0300 | [diff] [blame] | 9 | #include <power/max8907.h> |
| 10 | |
| 11 | static const struct pmic_child_info pmic_children_info[] = { |
| 12 | { .prefix = "ldo", .driver = MAX8907_LDO_DRIVER }, |
| 13 | { .prefix = "sd", .driver = MAX8907_SD_DRIVER }, |
| 14 | { }, |
| 15 | }; |
Svyatoslav Ryhel | 9c58dd6 | 2024-10-06 14:50:02 +0300 | [diff] [blame] | 16 | |
| 17 | static int max8907_write(struct udevice *dev, uint reg, const uint8_t *buff, int len) |
| 18 | { |
| 19 | int ret; |
| 20 | |
| 21 | ret = dm_i2c_write(dev, reg, buff, len); |
| 22 | if (ret) { |
| 23 | log_debug("%s: write error to device: %p register: %#x!\n", |
| 24 | __func__, dev, reg); |
| 25 | return ret; |
| 26 | } |
| 27 | |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | static int max8907_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 32 | { |
| 33 | int ret; |
| 34 | |
| 35 | ret = dm_i2c_read(dev, reg, buff, len); |
| 36 | if (ret) { |
| 37 | log_debug("%s: read error from device: %p register: %#x!\n", |
| 38 | __func__, dev, reg); |
| 39 | return ret; |
| 40 | } |
| 41 | |
Svyatoslav Ryhel | 8df7d47 | 2024-10-06 14:59:54 +0300 | [diff] [blame] | 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static int max8907_bind(struct udevice *dev) |
| 46 | { |
| 47 | ofnode regulators_node; |
Svyatoslav Ryhel | 9f8ea82 | 2024-10-06 16:51:21 +0300 | [diff] [blame^] | 48 | int children, ret; |
| 49 | |
| 50 | if (IS_ENABLED(CONFIG_SYSRESET_MAX8907) && |
| 51 | dev_read_bool(dev, "maxim,system-power-controller")) { |
| 52 | ret = device_bind_driver_to_node(dev, MAX8907_RST_DRIVER, |
| 53 | "sysreset", dev_ofnode(dev), |
| 54 | NULL); |
| 55 | if (ret) { |
| 56 | log_debug("%s: cannot bind SYSRESET (ret = %d)\n", |
| 57 | __func__, ret); |
| 58 | return ret; |
| 59 | } |
| 60 | } |
Svyatoslav Ryhel | 8df7d47 | 2024-10-06 14:59:54 +0300 | [diff] [blame] | 61 | |
| 62 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 63 | if (!ofnode_valid(regulators_node)) { |
| 64 | log_err("%s regulators subnode not found!\n", dev->name); |
| 65 | return -ENXIO; |
| 66 | } |
| 67 | |
| 68 | log_debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
| 69 | |
| 70 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 71 | if (!children) |
| 72 | log_err("%s - no child found\n", dev->name); |
| 73 | |
| 74 | /* Always return success for this device */ |
Svyatoslav Ryhel | 9c58dd6 | 2024-10-06 14:50:02 +0300 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static struct dm_pmic_ops max8907_ops = { |
| 79 | .read = max8907_read, |
| 80 | .write = max8907_write, |
| 81 | }; |
| 82 | |
| 83 | static const struct udevice_id max8907_ids[] = { |
| 84 | { .compatible = "maxim,max8907" }, |
| 85 | { } |
| 86 | }; |
| 87 | |
| 88 | U_BOOT_DRIVER(pmic_max8907) = { |
| 89 | .name = "max8907_pmic", |
| 90 | .id = UCLASS_PMIC, |
| 91 | .of_match = max8907_ids, |
Svyatoslav Ryhel | 8df7d47 | 2024-10-06 14:59:54 +0300 | [diff] [blame] | 92 | .bind = max8907_bind, |
Svyatoslav Ryhel | 9c58dd6 | 2024-10-06 14:50:02 +0300 | [diff] [blame] | 93 | .ops = &max8907_ops, |
| 94 | }; |