Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | d308c01 | 2015-07-02 18:16:00 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Google, Inc |
Simon Glass | d308c01 | 2015-07-02 18:16:00 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <fdtdec.h> |
| 8 | #include <errno.h> |
| 9 | #include <dm.h> |
| 10 | #include <i2c.h> |
| 11 | #include <power/pmic.h> |
| 12 | #include <power/regulator.h> |
| 13 | #include <power/s5m8767.h> |
| 14 | |
Simon Glass | d308c01 | 2015-07-02 18:16:00 -0600 | [diff] [blame] | 15 | static const struct pmic_child_info pmic_children_info[] = { |
| 16 | { .prefix = "LDO", .driver = S5M8767_LDO_DRIVER }, |
| 17 | { .prefix = "BUCK", .driver = S5M8767_BUCK_DRIVER }, |
| 18 | { }, |
| 19 | }; |
| 20 | |
| 21 | static int s5m8767_reg_count(struct udevice *dev) |
| 22 | { |
| 23 | return S5M8767_NUM_OF_REGS; |
| 24 | } |
| 25 | |
| 26 | static int s5m8767_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 27 | int len) |
| 28 | { |
| 29 | if (dm_i2c_write(dev, reg, buff, len)) { |
Simon Glass | c83c436 | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 30 | pr_err("write error to device: %p register: %#x!\n", dev, reg); |
Simon Glass | d308c01 | 2015-07-02 18:16:00 -0600 | [diff] [blame] | 31 | return -EIO; |
| 32 | } |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | static int s5m8767_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 38 | { |
| 39 | if (dm_i2c_read(dev, reg, buff, len)) { |
Simon Glass | c83c436 | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 40 | pr_err("read error from device: %p register: %#x!\n", dev, reg); |
Simon Glass | d308c01 | 2015-07-02 18:16:00 -0600 | [diff] [blame] | 41 | return -EIO; |
| 42 | } |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | int s5m8767_enable_32khz_cp(struct udevice *dev) |
| 48 | { |
| 49 | return pmic_clrsetbits(dev, S5M8767_EN32KHZ_CP, 0, 1 << 1); |
| 50 | } |
| 51 | |
| 52 | static int s5m8767_bind(struct udevice *dev) |
| 53 | { |
Simon Glass | d308c01 | 2015-07-02 18:16:00 -0600 | [diff] [blame] | 54 | int children; |
Simon Glass | 7a869e6 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 55 | ofnode node; |
Simon Glass | d308c01 | 2015-07-02 18:16:00 -0600 | [diff] [blame] | 56 | |
Simon Glass | 7a869e6 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 57 | node = dev_read_subnode(dev, "regulators"); |
| 58 | if (!ofnode_valid(node)) { |
Simon Glass | c83c436 | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 59 | debug("%s: %s regulators subnode not found!\n", __func__, |
Simon Glass | d308c01 | 2015-07-02 18:16:00 -0600 | [diff] [blame] | 60 | dev->name); |
| 61 | return -ENXIO; |
| 62 | } |
| 63 | |
| 64 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
| 65 | |
| 66 | children = pmic_bind_children(dev, node, pmic_children_info); |
| 67 | if (!children) |
| 68 | debug("%s: %s - no child found\n", __func__, dev->name); |
| 69 | |
| 70 | /* Always return success for this device */ |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static struct dm_pmic_ops s5m8767_ops = { |
| 75 | .reg_count = s5m8767_reg_count, |
| 76 | .read = s5m8767_read, |
| 77 | .write = s5m8767_write, |
| 78 | }; |
| 79 | |
| 80 | static const struct udevice_id s5m8767_ids[] = { |
| 81 | { .compatible = "samsung,s5m8767-pmic" }, |
| 82 | { } |
| 83 | }; |
| 84 | |
| 85 | U_BOOT_DRIVER(pmic_s5m8767) = { |
| 86 | .name = "s5m8767_pmic", |
| 87 | .id = UCLASS_PMIC, |
| 88 | .of_match = s5m8767_ids, |
| 89 | .bind = s5m8767_bind, |
| 90 | .ops = &s5m8767_ops, |
| 91 | }; |