blob: 5ff4f20521135c31bd34582df52c2d3141e0e14b [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>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060013#include <linux/printk.h>
Przemyslaw Marczak91815122015-10-27 13:07:58 +010014#include <power/pmic.h>
15#include <power/s2mps11.h>
16
Jaehoon Chung75536662018-01-16 15:33:51 +090017static const struct pmic_child_info pmic_children_info[] = {
18 { .prefix = S2MPS11_OF_LDO_PREFIX, .driver = S2MPS11_LDO_DRIVER },
19 { .prefix = S2MPS11_OF_BUCK_PREFIX, .driver = S2MPS11_BUCK_DRIVER },
20 { },
21};
22
Przemyslaw Marczak91815122015-10-27 13:07:58 +010023static int s2mps11_reg_count(struct udevice *dev)
24{
25 return S2MPS11_REG_COUNT;
26}
27
28static int s2mps11_write(struct udevice *dev, uint reg, const uint8_t *buff,
29 int len)
30{
31 int ret;
32
33 ret = dm_i2c_write(dev, reg, buff, len);
34 if (ret)
Simon Glass73126ac2018-11-18 08:14:28 -070035 pr_err("write error to device: %p register: %#x!\n", dev, reg);
Przemyslaw Marczak91815122015-10-27 13:07:58 +010036
37 return ret;
38}
39
40static int s2mps11_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
41{
42 int ret;
43
44 ret = dm_i2c_read(dev, reg, buff, len);
45 if (ret)
Simon Glass73126ac2018-11-18 08:14:28 -070046 pr_err("read error from device: %p register: %#x!\n", dev, reg);
Przemyslaw Marczak91815122015-10-27 13:07:58 +010047
48 return ret;
49}
50
Jaehoon Chung75536662018-01-16 15:33:51 +090051static int s2mps11_probe(struct udevice *dev)
52{
53 ofnode regulators_node;
54 int children;
55
56 regulators_node = dev_read_subnode(dev, "voltage-regulators");
57 if (!ofnode_valid(regulators_node)) {
Simon Glass73126ac2018-11-18 08:14:28 -070058 debug("%s: %s regulators subnode not found!\n", __func__,
59 dev->name);
Jaehoon Chung75536662018-01-16 15:33:51 +090060 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 return 0;
70}
71
Przemyslaw Marczak91815122015-10-27 13:07:58 +010072static struct dm_pmic_ops s2mps11_ops = {
73 .reg_count = s2mps11_reg_count,
74 .read = s2mps11_read,
75 .write = s2mps11_write,
76};
77
78static const struct udevice_id s2mps11_ids[] = {
79 { .compatible = "samsung,s2mps11-pmic" },
80 { }
81};
82
83U_BOOT_DRIVER(pmic_s2mps11) = {
84 .name = "s2mps11_pmic",
85 .id = UCLASS_PMIC,
86 .of_match = s2mps11_ids,
87 .ops = &s2mps11_ops,
Jaehoon Chung75536662018-01-16 15:33:51 +090088 .probe = s2mps11_probe,
Przemyslaw Marczak91815122015-10-27 13:07:58 +010089};