Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2015 Google, Inc |
| 3 | * Written by Simon Glass <sjg@chromium.org> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <dm.h> |
| 10 | #include <errno.h> |
| 11 | #include <fdtdec.h> |
| 12 | #include <libfdt.h> |
| 13 | #include <power/rk808_pmic.h> |
| 14 | #include <power/pmic.h> |
| 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | static const struct pmic_child_info pmic_children_info[] = { |
| 19 | { .prefix = "DCDC_REG", .driver = "rk808_buck"}, |
| 20 | { .prefix = "LDO_REG", .driver = "rk808_ldo"}, |
| 21 | { .prefix = "SWITCH_REG", .driver = "rk808_switch"}, |
| 22 | { }, |
| 23 | }; |
| 24 | |
| 25 | static int rk808_reg_count(struct udevice *dev) |
| 26 | { |
| 27 | return RK808_NUM_OF_REGS; |
| 28 | } |
| 29 | |
| 30 | static int rk808_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 31 | int len) |
| 32 | { |
| 33 | if (dm_i2c_write(dev, reg, buff, len)) { |
| 34 | debug("write error to device: %p register: %#x!", dev, reg); |
| 35 | return -EIO; |
| 36 | } |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | static int rk808_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 42 | { |
| 43 | if (dm_i2c_read(dev, reg, buff, len)) { |
| 44 | debug("read error from device: %p register: %#x!", dev, reg); |
| 45 | return -EIO; |
| 46 | } |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | #if CONFIG_IS_ENABLED(PMIC_CHILDREN) |
| 52 | static int rk808_bind(struct udevice *dev) |
| 53 | { |
| 54 | const void *blob = gd->fdt_blob; |
| 55 | int regulators_node; |
| 56 | int children; |
| 57 | |
| 58 | regulators_node = fdt_subnode_offset(blob, dev->of_offset, |
| 59 | "regulators"); |
| 60 | if (regulators_node <= 0) { |
| 61 | debug("%s: %s regulators subnode not found!", __func__, |
| 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, regulators_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 | #endif |
| 76 | |
| 77 | static struct dm_pmic_ops rk808_ops = { |
| 78 | .reg_count = rk808_reg_count, |
| 79 | .read = rk808_read, |
| 80 | .write = rk808_write, |
| 81 | }; |
| 82 | |
| 83 | static const struct udevice_id rk808_ids[] = { |
| 84 | { .compatible = "rockchip,rk808" }, |
| 85 | { } |
| 86 | }; |
| 87 | |
| 88 | U_BOOT_DRIVER(pmic_rk808) = { |
| 89 | .name = "rk808 pmic", |
| 90 | .id = UCLASS_PMIC, |
| 91 | .of_match = rk808_ids, |
| 92 | #if CONFIG_IS_ENABLED(PMIC_CHILDREN) |
| 93 | .bind = rk808_bind, |
| 94 | #endif |
| 95 | .ops = &rk808_ops, |
| 96 | }; |