blob: a6b0940956ad493030703078320f7e756ae734ae [file] [log] [blame]
Simon Glassb08ce892015-08-30 16:55:29 -06001/*
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/act8846_pmic.h>
14#include <power/pmic.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
18static const struct pmic_child_info pmic_children_info[] = {
19 { .prefix = "REG", .driver = "act8846_reg"},
20 { },
21};
22
23static int act8846_reg_count(struct udevice *dev)
24{
25 return ACT8846_NUM_OF_REGS;
26}
27
28static int act8846_write(struct udevice *dev, uint reg, const uint8_t *buff,
29 int len)
30{
31 if (dm_i2c_write(dev, reg, buff, len)) {
John Keepingf7f311d2016-08-07 12:55:40 +010032 debug("write error to device: %p register: %#x!\n", dev, reg);
Simon Glassb08ce892015-08-30 16:55:29 -060033 return -EIO;
34 }
35
36 return 0;
37}
38
39static int act8846_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
40{
41 if (dm_i2c_read(dev, reg, buff, len)) {
John Keepingf7f311d2016-08-07 12:55:40 +010042 debug("read error from device: %p register: %#x!\n", dev, reg);
Simon Glassb08ce892015-08-30 16:55:29 -060043 return -EIO;
44 }
45
46 return 0;
47}
48
49static int act8846_bind(struct udevice *dev)
50{
Simon Glass2c2d2c22017-05-18 20:09:32 -060051 ofnode regulators_node;
Simon Glassb08ce892015-08-30 16:55:29 -060052 int children;
53
Simon Glass2c2d2c22017-05-18 20:09:32 -060054 regulators_node = dev_read_subnode(dev, "regulators");
55 if (!ofnode_valid(regulators_node)) {
Simon Glassb08ce892015-08-30 16:55:29 -060056 debug("%s: %s regulators subnode not found!", __func__,
57 dev->name);
58 return -ENXIO;
59 }
60
61 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
62
63 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
64 if (!children)
65 debug("%s: %s - no child found\n", __func__, dev->name);
66
67 /* Always return success for this device */
68 return 0;
69}
70
71static struct dm_pmic_ops act8846_ops = {
72 .reg_count = act8846_reg_count,
73 .read = act8846_read,
74 .write = act8846_write,
75};
76
77static const struct udevice_id act8846_ids[] = {
78 { .compatible = "active-semi,act8846" },
79 { }
80};
81
82U_BOOT_DRIVER(pmic_act8846) = {
83 .name = "act8846 pmic",
84 .id = UCLASS_PMIC,
85 .of_match = act8846_ids,
86 .bind = act8846_bind,
87 .ops = &act8846_ops,
88};