Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <errno.h> |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 10 | #include <power/rk8xx_pmic.h> |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 11 | #include <power/pmic.h> |
| 12 | |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 13 | static const struct pmic_child_info pmic_children_info[] = { |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 14 | { .prefix = "DCDC_REG", .driver = "rk8xx_buck"}, |
| 15 | { .prefix = "LDO_REG", .driver = "rk8xx_ldo"}, |
| 16 | { .prefix = "SWITCH_REG", .driver = "rk8xx_switch"}, |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 17 | { }, |
| 18 | }; |
| 19 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 20 | static int rk8xx_reg_count(struct udevice *dev) |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 21 | { |
| 22 | return RK808_NUM_OF_REGS; |
| 23 | } |
| 24 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 25 | static int rk8xx_write(struct udevice *dev, uint reg, const uint8_t *buff, |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 26 | int len) |
| 27 | { |
Simon Glass | 46ad8cb | 2016-01-21 19:43:58 -0700 | [diff] [blame] | 28 | int ret; |
| 29 | |
| 30 | ret = dm_i2c_write(dev, reg, buff, len); |
| 31 | if (ret) { |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 32 | debug("write error to device: %p register: %#x!", dev, reg); |
Simon Glass | 46ad8cb | 2016-01-21 19:43:58 -0700 | [diff] [blame] | 33 | return ret; |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 39 | static int rk8xx_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 40 | { |
Simon Glass | 46ad8cb | 2016-01-21 19:43:58 -0700 | [diff] [blame] | 41 | int ret; |
| 42 | |
| 43 | ret = dm_i2c_read(dev, reg, buff, len); |
| 44 | if (ret) { |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 45 | debug("read error from device: %p register: %#x!", dev, reg); |
Simon Glass | 46ad8cb | 2016-01-21 19:43:58 -0700 | [diff] [blame] | 46 | return ret; |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | #if CONFIG_IS_ENABLED(PMIC_CHILDREN) |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 53 | static int rk8xx_bind(struct udevice *dev) |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 54 | { |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 55 | ofnode regulators_node; |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 56 | int children; |
| 57 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 58 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 59 | if (!ofnode_valid(regulators_node)) { |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 60 | debug("%s: %s regulators subnode not found!", __func__, |
| 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, regulators_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 | #endif |
| 75 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 76 | static int rk8xx_probe(struct udevice *dev) |
Jacob Chen | 0234adb | 2017-05-02 14:54:49 +0800 | [diff] [blame] | 77 | { |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 78 | struct rk8xx_priv *priv = dev_get_priv(dev); |
Jacob Chen | 0234adb | 2017-05-02 14:54:49 +0800 | [diff] [blame] | 79 | uint8_t msb, lsb; |
| 80 | |
| 81 | /* read Chip variant */ |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 82 | rk8xx_read(dev, ID_MSB, &msb, 1); |
| 83 | rk8xx_read(dev, ID_LSB, &lsb, 1); |
Jacob Chen | 0234adb | 2017-05-02 14:54:49 +0800 | [diff] [blame] | 84 | |
| 85 | priv->variant = ((msb << 8) | lsb) & RK8XX_ID_MSK; |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 90 | static struct dm_pmic_ops rk8xx_ops = { |
| 91 | .reg_count = rk8xx_reg_count, |
| 92 | .read = rk8xx_read, |
| 93 | .write = rk8xx_write, |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 96 | static const struct udevice_id rk8xx_ids[] = { |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 97 | { .compatible = "rockchip,rk808" }, |
Jacob Chen | 0234adb | 2017-05-02 14:54:49 +0800 | [diff] [blame] | 98 | { .compatible = "rockchip,rk818" }, |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 99 | { } |
| 100 | }; |
| 101 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 102 | U_BOOT_DRIVER(pmic_rk8xx) = { |
| 103 | .name = "rk8xx pmic", |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 104 | .id = UCLASS_PMIC, |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 105 | .of_match = rk8xx_ids, |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 106 | #if CONFIG_IS_ENABLED(PMIC_CHILDREN) |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 107 | .bind = rk8xx_bind, |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 108 | #endif |
Kever Yang | 00ab7fb | 2017-05-05 14:50:56 +0800 | [diff] [blame] | 109 | .priv_auto_alloc_size = sizeof(struct rk8xx_priv), |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 110 | .probe = rk8xx_probe, |
| 111 | .ops = &rk8xx_ops, |
Simon Glass | a8bd2ac | 2016-01-21 19:43:29 -0700 | [diff] [blame] | 112 | }; |