Samuel Holland | 3f90261 | 2021-10-08 00:17:16 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
Samuel Holland | 5afa5cd | 2021-10-24 21:00:10 -0500 | [diff] [blame] | 3 | #include <axp_pmic.h> |
Samuel Holland | 3f90261 | 2021-10-08 00:17:16 -0500 | [diff] [blame] | 4 | #include <dm.h> |
Samuel Holland | 5afa5cd | 2021-10-24 21:00:10 -0500 | [diff] [blame] | 5 | #include <dm/lists.h> |
Samuel Holland | 3f90261 | 2021-10-08 00:17:16 -0500 | [diff] [blame] | 6 | #include <i2c.h> |
| 7 | #include <power/pmic.h> |
Samuel Holland | 5afa5cd | 2021-10-24 21:00:10 -0500 | [diff] [blame] | 8 | #include <sysreset.h> |
| 9 | |
| 10 | #if CONFIG_IS_ENABLED(SYSRESET) |
| 11 | static int axp_sysreset_request(struct udevice *dev, enum sysreset_t type) |
| 12 | { |
| 13 | int ret; |
| 14 | |
| 15 | if (type != SYSRESET_POWER_OFF) |
| 16 | return -EPROTONOSUPPORT; |
| 17 | |
| 18 | ret = pmic_clrsetbits(dev->parent, AXP152_SHUTDOWN, 0, AXP152_POWEROFF); |
| 19 | if (ret < 0) |
| 20 | return ret; |
| 21 | |
| 22 | return -EINPROGRESS; |
| 23 | } |
| 24 | |
| 25 | static struct sysreset_ops axp_sysreset_ops = { |
| 26 | .request = axp_sysreset_request, |
| 27 | }; |
| 28 | |
| 29 | U_BOOT_DRIVER(axp_sysreset) = { |
| 30 | .name = "axp_sysreset", |
| 31 | .id = UCLASS_SYSRESET, |
| 32 | .ops = &axp_sysreset_ops, |
| 33 | }; |
| 34 | #endif |
Samuel Holland | 3f90261 | 2021-10-08 00:17:16 -0500 | [diff] [blame] | 35 | |
| 36 | static int axp_pmic_reg_count(struct udevice *dev) |
| 37 | { |
| 38 | /* TODO: Get the specific value from driver data. */ |
| 39 | return 0x100; |
| 40 | } |
| 41 | |
| 42 | static struct dm_pmic_ops axp_pmic_ops = { |
| 43 | .reg_count = axp_pmic_reg_count, |
| 44 | .read = dm_i2c_read, |
| 45 | .write = dm_i2c_write, |
| 46 | }; |
| 47 | |
Samuel Holland | a643856 | 2023-01-21 17:13:06 -0600 | [diff] [blame] | 48 | static const struct pmic_child_info axp_pmic_child_info[] = { |
| 49 | { "aldo", "axp_regulator" }, |
| 50 | { "bldo", "axp_regulator" }, |
| 51 | { "cldo", "axp_regulator" }, |
| 52 | { "dc", "axp_regulator" }, |
| 53 | { "dldo", "axp_regulator" }, |
| 54 | { "eldo", "axp_regulator" }, |
| 55 | { "fldo", "axp_regulator" }, |
| 56 | { "ldo", "axp_regulator" }, |
| 57 | { "sw", "axp_regulator" }, |
| 58 | { } |
| 59 | }; |
| 60 | |
Samuel Holland | 5afa5cd | 2021-10-24 21:00:10 -0500 | [diff] [blame] | 61 | static int axp_pmic_bind(struct udevice *dev) |
| 62 | { |
Samuel Holland | a643856 | 2023-01-21 17:13:06 -0600 | [diff] [blame] | 63 | ofnode regulators_node; |
Samuel Holland | 5afa5cd | 2021-10-24 21:00:10 -0500 | [diff] [blame] | 64 | int ret; |
| 65 | |
| 66 | ret = dm_scan_fdt_dev(dev); |
| 67 | if (ret) |
| 68 | return ret; |
| 69 | |
Samuel Holland | a643856 | 2023-01-21 17:13:06 -0600 | [diff] [blame] | 70 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 71 | if (ofnode_valid(regulators_node)) |
| 72 | pmic_bind_children(dev, regulators_node, axp_pmic_child_info); |
| 73 | |
Samuel Holland | 5afa5cd | 2021-10-24 21:00:10 -0500 | [diff] [blame] | 74 | if (CONFIG_IS_ENABLED(SYSRESET)) { |
| 75 | ret = device_bind_driver_to_node(dev, "axp_sysreset", "axp_sysreset", |
| 76 | dev_ofnode(dev), NULL); |
| 77 | if (ret) |
| 78 | return ret; |
| 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
Samuel Holland | 3f90261 | 2021-10-08 00:17:16 -0500 | [diff] [blame] | 84 | static const struct udevice_id axp_pmic_ids[] = { |
Samuel Holland | 0aa18bf | 2023-01-21 17:13:04 -0600 | [diff] [blame] | 85 | { .compatible = "x-powers,axp152", .data = AXP152_ID }, |
| 86 | { .compatible = "x-powers,axp202", .data = AXP202_ID }, |
| 87 | { .compatible = "x-powers,axp209", .data = AXP209_ID }, |
| 88 | { .compatible = "x-powers,axp221", .data = AXP221_ID }, |
| 89 | { .compatible = "x-powers,axp223", .data = AXP223_ID }, |
Andre Przywara | 943afa7 | 2023-10-17 14:12:44 +0100 | [diff] [blame] | 90 | { .compatible = "x-powers,axp313a", .data = AXP313_ID }, |
Andre Przywara | caf9f72 | 2024-05-10 00:43:19 +0100 | [diff] [blame] | 91 | { .compatible = "x-powers,axp717", .data = AXP717_ID }, |
Samuel Holland | 0aa18bf | 2023-01-21 17:13:04 -0600 | [diff] [blame] | 92 | { .compatible = "x-powers,axp803", .data = AXP803_ID }, |
| 93 | { .compatible = "x-powers,axp806", .data = AXP806_ID }, |
| 94 | { .compatible = "x-powers,axp809", .data = AXP809_ID }, |
| 95 | { .compatible = "x-powers,axp813", .data = AXP813_ID }, |
Samuel Holland | 3f90261 | 2021-10-08 00:17:16 -0500 | [diff] [blame] | 96 | { } |
| 97 | }; |
| 98 | |
| 99 | U_BOOT_DRIVER(axp_pmic) = { |
| 100 | .name = "axp_pmic", |
| 101 | .id = UCLASS_PMIC, |
| 102 | .of_match = axp_pmic_ids, |
Samuel Holland | 5afa5cd | 2021-10-24 21:00:10 -0500 | [diff] [blame] | 103 | .bind = axp_pmic_bind, |
Samuel Holland | 3f90261 | 2021-10-08 00:17:16 -0500 | [diff] [blame] | 104 | .ops = &axp_pmic_ops, |
| 105 | }; |