Tom Rini | 8b0c8a1 | 2018-05-06 18:27:01 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause |
Patrick Delaunay | 3cba451 | 2018-03-12 10:46:12 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2018, STMicroelectronics - All Rights Reserved |
Patrick Delaunay | 3cba451 | 2018-03-12 10:46:12 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <errno.h> |
| 9 | #include <i2c.h> |
| 10 | #include <power/pmic.h> |
Patrick Delaunay | 91be594 | 2019-02-04 11:26:16 +0100 | [diff] [blame^] | 11 | #include <power/stpmic1.h> |
Patrick Delaunay | 3cba451 | 2018-03-12 10:46:12 +0100 | [diff] [blame] | 12 | |
| 13 | #define STMPU1_NUM_OF_REGS 0x100 |
| 14 | |
Patrice Chotard | 0de0541 | 2018-04-26 17:13:10 +0200 | [diff] [blame] | 15 | #ifndef CONFIG_SPL_BUILD |
| 16 | static const struct pmic_child_info stpmu1_children_info[] = { |
| 17 | { .prefix = "ldo", .driver = "stpmu1_ldo" }, |
| 18 | { .prefix = "buck", .driver = "stpmu1_buck" }, |
| 19 | { .prefix = "vref_ddr", .driver = "stpmu1_vref_ddr" }, |
| 20 | { .prefix = "pwr_sw", .driver = "stpmu1_pwr_sw" }, |
| 21 | { .prefix = "boost", .driver = "stpmu1_boost" }, |
| 22 | { }, |
| 23 | }; |
| 24 | #endif /* CONFIG_SPL_BUILD */ |
| 25 | |
Patrick Delaunay | 3cba451 | 2018-03-12 10:46:12 +0100 | [diff] [blame] | 26 | static int stpmu1_reg_count(struct udevice *dev) |
| 27 | { |
| 28 | return STMPU1_NUM_OF_REGS; |
| 29 | } |
| 30 | |
| 31 | static int stpmu1_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 32 | int len) |
| 33 | { |
| 34 | int ret; |
| 35 | |
| 36 | ret = dm_i2c_write(dev, reg, buff, len); |
| 37 | if (ret) |
| 38 | dev_err(dev, "%s: failed to write register %#x :%d", |
| 39 | __func__, reg, ret); |
| 40 | |
| 41 | return ret; |
| 42 | } |
| 43 | |
| 44 | static int stpmu1_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 45 | { |
| 46 | int ret; |
| 47 | |
| 48 | ret = dm_i2c_read(dev, reg, buff, len); |
| 49 | if (ret) |
| 50 | dev_err(dev, "%s: failed to read register %#x : %d", |
| 51 | __func__, reg, ret); |
| 52 | |
| 53 | return ret; |
| 54 | } |
| 55 | |
Patrice Chotard | 0de0541 | 2018-04-26 17:13:10 +0200 | [diff] [blame] | 56 | static int stpmu1_bind(struct udevice *dev) |
| 57 | { |
| 58 | #ifndef CONFIG_SPL_BUILD |
| 59 | ofnode regulators_node; |
| 60 | int children; |
| 61 | |
| 62 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 63 | if (!ofnode_valid(regulators_node)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 64 | dev_dbg(dev, "regulators subnode not found!\n"); |
Patrice Chotard | 0de0541 | 2018-04-26 17:13:10 +0200 | [diff] [blame] | 65 | return -ENXIO; |
| 66 | } |
| 67 | dev_dbg(dev, "found regulators subnode\n"); |
| 68 | |
| 69 | children = pmic_bind_children(dev, regulators_node, |
| 70 | stpmu1_children_info); |
| 71 | if (!children) |
| 72 | dev_dbg(dev, "no child found\n"); |
| 73 | #endif /* CONFIG_SPL_BUILD */ |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
Patrick Delaunay | 3cba451 | 2018-03-12 10:46:12 +0100 | [diff] [blame] | 78 | static struct dm_pmic_ops stpmu1_ops = { |
| 79 | .reg_count = stpmu1_reg_count, |
| 80 | .read = stpmu1_read, |
| 81 | .write = stpmu1_write, |
| 82 | }; |
| 83 | |
| 84 | static const struct udevice_id stpmu1_ids[] = { |
| 85 | { .compatible = "st,stpmu1" }, |
| 86 | { } |
| 87 | }; |
| 88 | |
| 89 | U_BOOT_DRIVER(pmic_stpmu1) = { |
| 90 | .name = "stpmu1_pmic", |
| 91 | .id = UCLASS_PMIC, |
| 92 | .of_match = stpmu1_ids, |
Patrice Chotard | 0de0541 | 2018-04-26 17:13:10 +0200 | [diff] [blame] | 93 | .bind = stpmu1_bind, |
Patrick Delaunay | 3cba451 | 2018-03-12 10:46:12 +0100 | [diff] [blame] | 94 | .ops = &stpmu1_ops, |
| 95 | }; |