Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Przemyslaw Marczak | 9181512 | 2015-10-27 13:07:58 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Samsung Electronics |
| 4 | * Przemyslaw Marczak <p.marczak@samsung.com> |
Przemyslaw Marczak | 9181512 | 2015-10-27 13:07:58 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <fdtdec.h> |
| 9 | #include <errno.h> |
| 10 | #include <dm.h> |
| 11 | #include <i2c.h> |
| 12 | #include <power/pmic.h> |
| 13 | #include <power/s2mps11.h> |
| 14 | |
Jaehoon Chung | 7553666 | 2018-01-16 15:33:51 +0900 | [diff] [blame] | 15 | static const struct pmic_child_info pmic_children_info[] = { |
| 16 | { .prefix = S2MPS11_OF_LDO_PREFIX, .driver = S2MPS11_LDO_DRIVER }, |
| 17 | { .prefix = S2MPS11_OF_BUCK_PREFIX, .driver = S2MPS11_BUCK_DRIVER }, |
| 18 | { }, |
| 19 | }; |
| 20 | |
Przemyslaw Marczak | 9181512 | 2015-10-27 13:07:58 +0100 | [diff] [blame] | 21 | static int s2mps11_reg_count(struct udevice *dev) |
| 22 | { |
| 23 | return S2MPS11_REG_COUNT; |
| 24 | } |
| 25 | |
| 26 | static int s2mps11_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 27 | int len) |
| 28 | { |
| 29 | int ret; |
| 30 | |
| 31 | ret = dm_i2c_write(dev, reg, buff, len); |
| 32 | if (ret) |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 33 | pr_err("write error to device: %p register: %#x!", dev, reg); |
Przemyslaw Marczak | 9181512 | 2015-10-27 13:07:58 +0100 | [diff] [blame] | 34 | |
| 35 | return ret; |
| 36 | } |
| 37 | |
| 38 | static int s2mps11_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 39 | { |
| 40 | int ret; |
| 41 | |
| 42 | ret = dm_i2c_read(dev, reg, buff, len); |
| 43 | if (ret) |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 44 | pr_err("read error from device: %p register: %#x!", dev, reg); |
Przemyslaw Marczak | 9181512 | 2015-10-27 13:07:58 +0100 | [diff] [blame] | 45 | |
| 46 | return ret; |
| 47 | } |
| 48 | |
Jaehoon Chung | 7553666 | 2018-01-16 15:33:51 +0900 | [diff] [blame] | 49 | static int s2mps11_probe(struct udevice *dev) |
| 50 | { |
| 51 | ofnode regulators_node; |
| 52 | int children; |
| 53 | |
| 54 | regulators_node = dev_read_subnode(dev, "voltage-regulators"); |
| 55 | if (!ofnode_valid(regulators_node)) { |
| 56 | debug("%s: %s regulators subnode not found!", __func__, |
| 57 | dev->name); |
| 58 | return -ENXIO; |
| 59 | } |
| 60 | |
| 61 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
| 62 | |
| 63 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 64 | if (!children) |
| 65 | debug("%s: %s - no child found\n", __func__, dev->name); |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
Przemyslaw Marczak | 9181512 | 2015-10-27 13:07:58 +0100 | [diff] [blame] | 70 | static struct dm_pmic_ops s2mps11_ops = { |
| 71 | .reg_count = s2mps11_reg_count, |
| 72 | .read = s2mps11_read, |
| 73 | .write = s2mps11_write, |
| 74 | }; |
| 75 | |
| 76 | static const struct udevice_id s2mps11_ids[] = { |
| 77 | { .compatible = "samsung,s2mps11-pmic" }, |
| 78 | { } |
| 79 | }; |
| 80 | |
| 81 | U_BOOT_DRIVER(pmic_s2mps11) = { |
| 82 | .name = "s2mps11_pmic", |
| 83 | .id = UCLASS_PMIC, |
| 84 | .of_match = s2mps11_ids, |
| 85 | .ops = &s2mps11_ops, |
Jaehoon Chung | 7553666 | 2018-01-16 15:33:51 +0900 | [diff] [blame] | 86 | .probe = s2mps11_probe, |
Przemyslaw Marczak | 9181512 | 2015-10-27 13:07:58 +0100 | [diff] [blame] | 87 | }; |