Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | b08ce89 | 2015-08-30 16:55:29 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | b08ce89 | 2015-08-30 16:55:29 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 7 | #include <common.h> |
Simon Glass | b08ce89 | 2015-08-30 16:55:29 -0600 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <errno.h> |
| 10 | #include <fdtdec.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 12 | #include <linux/libfdt.h> |
Simon Glass | b08ce89 | 2015-08-30 16:55:29 -0600 | [diff] [blame] | 13 | #include <power/act8846_pmic.h> |
| 14 | #include <power/pmic.h> |
| 15 | |
Simon Glass | b08ce89 | 2015-08-30 16:55:29 -0600 | [diff] [blame] | 16 | static const struct pmic_child_info pmic_children_info[] = { |
| 17 | { .prefix = "REG", .driver = "act8846_reg"}, |
| 18 | { }, |
| 19 | }; |
| 20 | |
| 21 | static int act8846_reg_count(struct udevice *dev) |
| 22 | { |
| 23 | return ACT8846_NUM_OF_REGS; |
| 24 | } |
| 25 | |
| 26 | static int act8846_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 27 | int len) |
| 28 | { |
| 29 | if (dm_i2c_write(dev, reg, buff, len)) { |
John Keeping | f7f311d | 2016-08-07 12:55:40 +0100 | [diff] [blame] | 30 | debug("write error to device: %p register: %#x!\n", dev, reg); |
Simon Glass | b08ce89 | 2015-08-30 16:55:29 -0600 | [diff] [blame] | 31 | return -EIO; |
| 32 | } |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | static int act8846_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 38 | { |
| 39 | if (dm_i2c_read(dev, reg, buff, len)) { |
John Keeping | f7f311d | 2016-08-07 12:55:40 +0100 | [diff] [blame] | 40 | debug("read error from device: %p register: %#x!\n", dev, reg); |
Simon Glass | b08ce89 | 2015-08-30 16:55:29 -0600 | [diff] [blame] | 41 | return -EIO; |
| 42 | } |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | static int act8846_bind(struct udevice *dev) |
| 48 | { |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 49 | ofnode regulators_node; |
Simon Glass | b08ce89 | 2015-08-30 16:55:29 -0600 | [diff] [blame] | 50 | int children; |
| 51 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 52 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 53 | if (!ofnode_valid(regulators_node)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 54 | debug("%s: %s regulators subnode not found!\n", __func__, |
Simon Glass | b08ce89 | 2015-08-30 16:55:29 -0600 | [diff] [blame] | 55 | dev->name); |
| 56 | return -ENXIO; |
| 57 | } |
| 58 | |
| 59 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
| 60 | |
| 61 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 62 | if (!children) |
| 63 | debug("%s: %s - no child found\n", __func__, dev->name); |
| 64 | |
| 65 | /* Always return success for this device */ |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static struct dm_pmic_ops act8846_ops = { |
| 70 | .reg_count = act8846_reg_count, |
| 71 | .read = act8846_read, |
| 72 | .write = act8846_write, |
| 73 | }; |
| 74 | |
| 75 | static const struct udevice_id act8846_ids[] = { |
| 76 | { .compatible = "active-semi,act8846" }, |
| 77 | { } |
| 78 | }; |
| 79 | |
| 80 | U_BOOT_DRIVER(pmic_act8846) = { |
| 81 | .name = "act8846 pmic", |
| 82 | .id = UCLASS_PMIC, |
| 83 | .of_match = act8846_ids, |
| 84 | .bind = act8846_bind, |
| 85 | .ops = &act8846_ops, |
| 86 | }; |