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