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