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