blob: eea072ae824f4be635279cb1130a9f1a4a09e21e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass01651492015-07-02 18:16:00 -06002/*
3 * Copyright (C) 2015 Google, Inc
Simon Glass01651492015-07-02 18:16:00 -06004 */
5
6#include <common.h>
7#include <fdtdec.h>
8#include <errno.h>
9#include <dm.h>
10#include <i2c.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060012#include <linux/printk.h>
Simon Glass01651492015-07-02 18:16:00 -060013#include <power/pmic.h>
14#include <power/regulator.h>
15#include <power/s5m8767.h>
16
Simon Glass01651492015-07-02 18:16:00 -060017static const struct pmic_child_info pmic_children_info[] = {
18 { .prefix = "LDO", .driver = S5M8767_LDO_DRIVER },
19 { .prefix = "BUCK", .driver = S5M8767_BUCK_DRIVER },
20 { },
21};
22
23static int s5m8767_reg_count(struct udevice *dev)
24{
25 return S5M8767_NUM_OF_REGS;
26}
27
28static int s5m8767_write(struct udevice *dev, uint reg, const uint8_t *buff,
29 int len)
30{
31 if (dm_i2c_write(dev, reg, buff, len)) {
Simon Glass73126ac2018-11-18 08:14:28 -070032 pr_err("write error to device: %p register: %#x!\n", dev, reg);
Simon Glass01651492015-07-02 18:16:00 -060033 return -EIO;
34 }
35
36 return 0;
37}
38
39static int s5m8767_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
40{
41 if (dm_i2c_read(dev, reg, buff, len)) {
Simon Glass73126ac2018-11-18 08:14:28 -070042 pr_err("read error from device: %p register: %#x!\n", dev, reg);
Simon Glass01651492015-07-02 18:16:00 -060043 return -EIO;
44 }
45
46 return 0;
47}
48
49int s5m8767_enable_32khz_cp(struct udevice *dev)
50{
51 return pmic_clrsetbits(dev, S5M8767_EN32KHZ_CP, 0, 1 << 1);
52}
53
54static int s5m8767_bind(struct udevice *dev)
55{
Simon Glass01651492015-07-02 18:16:00 -060056 int children;
Simon Glass2c2d2c22017-05-18 20:09:32 -060057 ofnode node;
Simon Glass01651492015-07-02 18:16:00 -060058
Simon Glass2c2d2c22017-05-18 20:09:32 -060059 node = dev_read_subnode(dev, "regulators");
60 if (!ofnode_valid(node)) {
Simon Glass73126ac2018-11-18 08:14:28 -070061 debug("%s: %s regulators subnode not found!\n", __func__,
Simon Glass01651492015-07-02 18:16:00 -060062 dev->name);
63 return -ENXIO;
64 }
65
66 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
67
68 children = pmic_bind_children(dev, node, pmic_children_info);
69 if (!children)
70 debug("%s: %s - no child found\n", __func__, dev->name);
71
72 /* Always return success for this device */
73 return 0;
74}
75
76static struct dm_pmic_ops s5m8767_ops = {
77 .reg_count = s5m8767_reg_count,
78 .read = s5m8767_read,
79 .write = s5m8767_write,
80};
81
82static const struct udevice_id s5m8767_ids[] = {
83 { .compatible = "samsung,s5m8767-pmic" },
84 { }
85};
86
87U_BOOT_DRIVER(pmic_s5m8767) = {
88 .name = "s5m8767_pmic",
89 .id = UCLASS_PMIC,
90 .of_match = s5m8767_ids,
91 .bind = s5m8767_bind,
92 .ops = &s5m8767_ops,
93};