blob: 25c339ab12cc5c2ba4f2f23e2ae62146365b11db [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassa8bd2ac2016-01-21 19:43:29 -07002/*
3 * Copyright (C) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glassa8bd2ac2016-01-21 19:43:29 -07005 */
6
7#include <common.h>
8#include <dm.h>
9#include <errno.h>
Jacob Chen614704b2017-05-02 14:54:52 +080010#include <power/rk8xx_pmic.h>
Simon Glassa8bd2ac2016-01-21 19:43:29 -070011#include <power/pmic.h>
12
Simon Glassa8bd2ac2016-01-21 19:43:29 -070013static const struct pmic_child_info pmic_children_info[] = {
Jacob Chen614704b2017-05-02 14:54:52 +080014 { .prefix = "DCDC_REG", .driver = "rk8xx_buck"},
15 { .prefix = "LDO_REG", .driver = "rk8xx_ldo"},
16 { .prefix = "SWITCH_REG", .driver = "rk8xx_switch"},
Simon Glassa8bd2ac2016-01-21 19:43:29 -070017 { },
18};
19
Jacob Chen614704b2017-05-02 14:54:52 +080020static int rk8xx_reg_count(struct udevice *dev)
Simon Glassa8bd2ac2016-01-21 19:43:29 -070021{
22 return RK808_NUM_OF_REGS;
23}
24
Jacob Chen614704b2017-05-02 14:54:52 +080025static int rk8xx_write(struct udevice *dev, uint reg, const uint8_t *buff,
Simon Glassa8bd2ac2016-01-21 19:43:29 -070026 int len)
27{
Simon Glass46ad8cb2016-01-21 19:43:58 -070028 int ret;
29
30 ret = dm_i2c_write(dev, reg, buff, len);
31 if (ret) {
Simon Glass73126ac2018-11-18 08:14:28 -070032 debug("write error to device: %p register: %#x!\n", dev, reg);
Simon Glass46ad8cb2016-01-21 19:43:58 -070033 return ret;
Simon Glassa8bd2ac2016-01-21 19:43:29 -070034 }
35
36 return 0;
37}
38
Jacob Chen614704b2017-05-02 14:54:52 +080039static int rk8xx_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
Simon Glassa8bd2ac2016-01-21 19:43:29 -070040{
Simon Glass46ad8cb2016-01-21 19:43:58 -070041 int ret;
42
43 ret = dm_i2c_read(dev, reg, buff, len);
44 if (ret) {
Simon Glass73126ac2018-11-18 08:14:28 -070045 debug("read error from device: %p register: %#x!\n", dev, reg);
Simon Glass46ad8cb2016-01-21 19:43:58 -070046 return ret;
Simon Glassa8bd2ac2016-01-21 19:43:29 -070047 }
48
49 return 0;
50}
51
52#if CONFIG_IS_ENABLED(PMIC_CHILDREN)
Jacob Chen614704b2017-05-02 14:54:52 +080053static int rk8xx_bind(struct udevice *dev)
Simon Glassa8bd2ac2016-01-21 19:43:29 -070054{
Simon Glass2c2d2c22017-05-18 20:09:32 -060055 ofnode regulators_node;
Simon Glassa8bd2ac2016-01-21 19:43:29 -070056 int children;
57
Simon Glass2c2d2c22017-05-18 20:09:32 -060058 regulators_node = dev_read_subnode(dev, "regulators");
59 if (!ofnode_valid(regulators_node)) {
Simon Glass73126ac2018-11-18 08:14:28 -070060 debug("%s: %s regulators subnode not found!\n", __func__,
Simon Glassa8bd2ac2016-01-21 19:43:29 -070061 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 Chen614704b2017-05-02 14:54:52 +080076static int rk8xx_probe(struct udevice *dev)
Jacob Chen0234adb2017-05-02 14:54:49 +080077{
Jacob Chen614704b2017-05-02 14:54:52 +080078 struct rk8xx_priv *priv = dev_get_priv(dev);
Jacob Chen0234adb2017-05-02 14:54:49 +080079 uint8_t msb, lsb;
80
81 /* read Chip variant */
Jacob Chen614704b2017-05-02 14:54:52 +080082 rk8xx_read(dev, ID_MSB, &msb, 1);
83 rk8xx_read(dev, ID_LSB, &lsb, 1);
Jacob Chen0234adb2017-05-02 14:54:49 +080084
85 priv->variant = ((msb << 8) | lsb) & RK8XX_ID_MSK;
86
87 return 0;
88}
89
Jacob Chen614704b2017-05-02 14:54:52 +080090static struct dm_pmic_ops rk8xx_ops = {
91 .reg_count = rk8xx_reg_count,
92 .read = rk8xx_read,
93 .write = rk8xx_write,
Simon Glassa8bd2ac2016-01-21 19:43:29 -070094};
95
Jacob Chen614704b2017-05-02 14:54:52 +080096static const struct udevice_id rk8xx_ids[] = {
Simon Glassa8bd2ac2016-01-21 19:43:29 -070097 { .compatible = "rockchip,rk808" },
Jacob Chen0234adb2017-05-02 14:54:49 +080098 { .compatible = "rockchip,rk818" },
Simon Glassa8bd2ac2016-01-21 19:43:29 -070099 { }
100};
101
Jacob Chen614704b2017-05-02 14:54:52 +0800102U_BOOT_DRIVER(pmic_rk8xx) = {
103 .name = "rk8xx pmic",
Simon Glassa8bd2ac2016-01-21 19:43:29 -0700104 .id = UCLASS_PMIC,
Jacob Chen614704b2017-05-02 14:54:52 +0800105 .of_match = rk8xx_ids,
Simon Glassa8bd2ac2016-01-21 19:43:29 -0700106#if CONFIG_IS_ENABLED(PMIC_CHILDREN)
Jacob Chen614704b2017-05-02 14:54:52 +0800107 .bind = rk8xx_bind,
Simon Glassa8bd2ac2016-01-21 19:43:29 -0700108#endif
Kever Yang00ab7fb2017-05-05 14:50:56 +0800109 .priv_auto_alloc_size = sizeof(struct rk8xx_priv),
Jacob Chen614704b2017-05-02 14:54:52 +0800110 .probe = rk8xx_probe,
111 .ops = &rk8xx_ops,
Simon Glassa8bd2ac2016-01-21 19:43:29 -0700112};