blob: 3f9525b67d6ba34063156442278b6de09369db3a [file] [log] [blame]
Przemyslaw Marczak91815122015-10-27 13:07:58 +01001/*
2 * Copyright (C) 2015 Samsung Electronics
3 * Przemyslaw Marczak <p.marczak@samsung.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <fdtdec.h>
10#include <errno.h>
11#include <dm.h>
12#include <i2c.h>
13#include <power/pmic.h>
14#include <power/s2mps11.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
Jaehoon Chung75536662018-01-16 15:33:51 +090018static const struct pmic_child_info pmic_children_info[] = {
19 { .prefix = S2MPS11_OF_LDO_PREFIX, .driver = S2MPS11_LDO_DRIVER },
20 { .prefix = S2MPS11_OF_BUCK_PREFIX, .driver = S2MPS11_BUCK_DRIVER },
21 { },
22};
23
Przemyslaw Marczak91815122015-10-27 13:07:58 +010024static int s2mps11_reg_count(struct udevice *dev)
25{
26 return S2MPS11_REG_COUNT;
27}
28
29static int s2mps11_write(struct udevice *dev, uint reg, const uint8_t *buff,
30 int len)
31{
32 int ret;
33
34 ret = dm_i2c_write(dev, reg, buff, len);
35 if (ret)
Masahiro Yamada81e10422017-09-16 14:10:41 +090036 pr_err("write error to device: %p register: %#x!", dev, reg);
Przemyslaw Marczak91815122015-10-27 13:07:58 +010037
38 return ret;
39}
40
41static int s2mps11_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
42{
43 int ret;
44
45 ret = dm_i2c_read(dev, reg, buff, len);
46 if (ret)
Masahiro Yamada81e10422017-09-16 14:10:41 +090047 pr_err("read error from device: %p register: %#x!", dev, reg);
Przemyslaw Marczak91815122015-10-27 13:07:58 +010048
49 return ret;
50}
51
Jaehoon Chung75536662018-01-16 15:33:51 +090052static int s2mps11_probe(struct udevice *dev)
53{
54 ofnode regulators_node;
55 int children;
56
57 regulators_node = dev_read_subnode(dev, "voltage-regulators");
58 if (!ofnode_valid(regulators_node)) {
59 debug("%s: %s regulators subnode not found!", __func__,
60 dev->name);
61 return -ENXIO;
62 }
63
64 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
65
66 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
67 if (!children)
68 debug("%s: %s - no child found\n", __func__, dev->name);
69
70 return 0;
71}
72
Przemyslaw Marczak91815122015-10-27 13:07:58 +010073static struct dm_pmic_ops s2mps11_ops = {
74 .reg_count = s2mps11_reg_count,
75 .read = s2mps11_read,
76 .write = s2mps11_write,
77};
78
79static const struct udevice_id s2mps11_ids[] = {
80 { .compatible = "samsung,s2mps11-pmic" },
81 { }
82};
83
84U_BOOT_DRIVER(pmic_s2mps11) = {
85 .name = "s2mps11_pmic",
86 .id = UCLASS_PMIC,
87 .of_match = s2mps11_ids,
88 .ops = &s2mps11_ops,
Jaehoon Chung75536662018-01-16 15:33:51 +090089 .probe = s2mps11_probe,
Przemyslaw Marczak91815122015-10-27 13:07:58 +010090};