blob: 458c4df688c2dd3e8af3542e0740722f00b55163 [file] [log] [blame]
Tim Harvey338588e2020-12-21 08:19:39 -08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2020 Gateworks Corporation
4 */
5#include <common.h>
6#include <errno.h>
7#include <dm.h>
8#include <i2c.h>
9#include <log.h>
10#include <power/pmic.h>
11#include <power/regulator.h>
12#include <power/mp5416.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
16static const struct pmic_child_info pmic_children_info[] = {
17 /* buck */
18 { .prefix = "b", .driver = MP6416_REGULATOR_DRIVER },
19 /* ldo */
20 { .prefix = "l", .driver = MP6416_REGULATOR_DRIVER },
21 { },
22};
23
24static int mp5416_reg_count(struct udevice *dev)
25{
26 return MP5416_NUM_OF_REGS - 1;
27}
28
29static int mp5416_write(struct udevice *dev, uint reg, const uint8_t *buff,
30 int len)
31{
32 if (dm_i2c_write(dev, reg, buff, len)) {
33 pr_err("write error to device: %p register: %#x!", dev, reg);
34 return -EIO;
35 }
36
37 return 0;
38}
39
40static int mp5416_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
41{
42 if (dm_i2c_read(dev, reg, buff, len)) {
43 pr_err("read error from device: %p register: %#x!", dev, reg);
44 return -EIO;
45 }
46
47 return 0;
48}
49
50static int mp5416_bind(struct udevice *dev)
51{
52 int children;
53 ofnode regulators_node;
54
55 debug("%s %s\n", __func__, dev->name);
56 regulators_node = dev_read_subnode(dev, "regulators");
57 if (!ofnode_valid(regulators_node)) {
58 debug("%s: %s regulators subnode not found!\n", __func__,
59 dev->name);
60 return -ENXIO;
61 }
62
63 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
64
65 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
66 if (!children)
67 debug("%s: %s - no child found\n", __func__, dev->name);
68
69 /* Always return success for this device */
70 return 0;
71}
72
73static int mp5416_probe(struct udevice *dev)
74{
75 debug("%s %s\n", __func__, dev->name);
76
77 return 0;
78}
79
80static struct dm_pmic_ops mp5416_ops = {
81 .reg_count = mp5416_reg_count,
82 .read = mp5416_read,
83 .write = mp5416_write,
84};
85
86static const struct udevice_id mp5416_ids[] = {
87 { .compatible = "mps,mp5416", },
88 { }
89};
90
91U_BOOT_DRIVER(pmic_mp5416) = {
92 .name = "mp5416 pmic",
93 .id = UCLASS_PMIC,
94 .of_match = mp5416_ids,
95 .bind = mp5416_bind,
96 .probe = mp5416_probe,
97 .ops = &mp5416_ops,
98};