blob: 3058ef0f893d810c94f7a21538dfb88b9481db68 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassb08ce892015-08-30 16:55:29 -06002/*
3 * Copyright (C) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glassb08ce892015-08-30 16:55:29 -06005 */
6
Simon Glassb08ce892015-08-30 16:55:29 -06007#include <dm.h>
8#include <errno.h>
9#include <fdtdec.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090011#include <linux/libfdt.h>
Simon Glassb08ce892015-08-30 16:55:29 -060012#include <power/act8846_pmic.h>
13#include <power/pmic.h>
14
Simon Glassb08ce892015-08-30 16:55:29 -060015static const struct pmic_child_info pmic_children_info[] = {
16 { .prefix = "REG", .driver = "act8846_reg"},
17 { },
18};
19
20static int act8846_reg_count(struct udevice *dev)
21{
22 return ACT8846_NUM_OF_REGS;
23}
24
25static int act8846_write(struct udevice *dev, uint reg, const uint8_t *buff,
26 int len)
27{
28 if (dm_i2c_write(dev, reg, buff, len)) {
John Keepingf7f311d2016-08-07 12:55:40 +010029 debug("write error to device: %p register: %#x!\n", dev, reg);
Simon Glassb08ce892015-08-30 16:55:29 -060030 return -EIO;
31 }
32
33 return 0;
34}
35
36static int act8846_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
37{
38 if (dm_i2c_read(dev, reg, buff, len)) {
John Keepingf7f311d2016-08-07 12:55:40 +010039 debug("read error from device: %p register: %#x!\n", dev, reg);
Simon Glassb08ce892015-08-30 16:55:29 -060040 return -EIO;
41 }
42
43 return 0;
44}
45
46static int act8846_bind(struct udevice *dev)
47{
Simon Glass2c2d2c22017-05-18 20:09:32 -060048 ofnode regulators_node;
Simon Glassb08ce892015-08-30 16:55:29 -060049 int children;
50
Simon Glass2c2d2c22017-05-18 20:09:32 -060051 regulators_node = dev_read_subnode(dev, "regulators");
52 if (!ofnode_valid(regulators_node)) {
Simon Glass73126ac2018-11-18 08:14:28 -070053 debug("%s: %s regulators subnode not found!\n", __func__,
Simon Glassb08ce892015-08-30 16:55:29 -060054 dev->name);
55 return -ENXIO;
56 }
57
58 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
59
60 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
61 if (!children)
62 debug("%s: %s - no child found\n", __func__, dev->name);
63
64 /* Always return success for this device */
65 return 0;
66}
67
68static struct dm_pmic_ops act8846_ops = {
69 .reg_count = act8846_reg_count,
70 .read = act8846_read,
71 .write = act8846_write,
72};
73
74static const struct udevice_id act8846_ids[] = {
75 { .compatible = "active-semi,act8846" },
76 { }
77};
78
79U_BOOT_DRIVER(pmic_act8846) = {
80 .name = "act8846 pmic",
81 .id = UCLASS_PMIC,
82 .of_match = act8846_ids,
83 .bind = act8846_bind,
84 .ops = &act8846_ops,
85};