blob: f2aab6c457012f2387a753591216a4162033af6b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Przemyslaw Marczak91815122015-10-27 13:07:58 +01002/*
3 * Copyright (C) 2015 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
Przemyslaw Marczak91815122015-10-27 13:07:58 +01005 */
6
7#include <common.h>
8#include <fdtdec.h>
9#include <errno.h>
10#include <dm.h>
11#include <i2c.h>
12#include <power/pmic.h>
13#include <power/s2mps11.h>
14
Jaehoon Chung75536662018-01-16 15:33:51 +090015static const struct pmic_child_info pmic_children_info[] = {
16 { .prefix = S2MPS11_OF_LDO_PREFIX, .driver = S2MPS11_LDO_DRIVER },
17 { .prefix = S2MPS11_OF_BUCK_PREFIX, .driver = S2MPS11_BUCK_DRIVER },
18 { },
19};
20
Przemyslaw Marczak91815122015-10-27 13:07:58 +010021static int s2mps11_reg_count(struct udevice *dev)
22{
23 return S2MPS11_REG_COUNT;
24}
25
26static int s2mps11_write(struct udevice *dev, uint reg, const uint8_t *buff,
27 int len)
28{
29 int ret;
30
31 ret = dm_i2c_write(dev, reg, buff, len);
32 if (ret)
Simon Glass73126ac2018-11-18 08:14:28 -070033 pr_err("write error to device: %p register: %#x!\n", dev, reg);
Przemyslaw Marczak91815122015-10-27 13:07:58 +010034
35 return ret;
36}
37
38static int s2mps11_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
39{
40 int ret;
41
42 ret = dm_i2c_read(dev, reg, buff, len);
43 if (ret)
Simon Glass73126ac2018-11-18 08:14:28 -070044 pr_err("read error from device: %p register: %#x!\n", dev, reg);
Przemyslaw Marczak91815122015-10-27 13:07:58 +010045
46 return ret;
47}
48
Jaehoon Chung75536662018-01-16 15:33:51 +090049static int s2mps11_probe(struct udevice *dev)
50{
51 ofnode regulators_node;
52 int children;
53
54 regulators_node = dev_read_subnode(dev, "voltage-regulators");
55 if (!ofnode_valid(regulators_node)) {
Simon Glass73126ac2018-11-18 08:14:28 -070056 debug("%s: %s regulators subnode not found!\n", __func__,
57 dev->name);
Jaehoon Chung75536662018-01-16 15:33:51 +090058 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 return 0;
68}
69
Przemyslaw Marczak91815122015-10-27 13:07:58 +010070static struct dm_pmic_ops s2mps11_ops = {
71 .reg_count = s2mps11_reg_count,
72 .read = s2mps11_read,
73 .write = s2mps11_write,
74};
75
76static const struct udevice_id s2mps11_ids[] = {
77 { .compatible = "samsung,s2mps11-pmic" },
78 { }
79};
80
81U_BOOT_DRIVER(pmic_s2mps11) = {
82 .name = "s2mps11_pmic",
83 .id = UCLASS_PMIC,
84 .of_match = s2mps11_ids,
85 .ops = &s2mps11_ops,
Jaehoon Chung75536662018-01-16 15:33:51 +090086 .probe = s2mps11_probe,
Przemyslaw Marczak91815122015-10-27 13:07:58 +010087};