blob: 54e44ce8645bb86bda57722d4caccb1b82a90145 [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>
11#include <power/pmic.h>
12#include <power/regulator.h>
13#include <power/s5m8767.h>
14
Simon Glass01651492015-07-02 18:16:00 -060015static const struct pmic_child_info pmic_children_info[] = {
16 { .prefix = "LDO", .driver = S5M8767_LDO_DRIVER },
17 { .prefix = "BUCK", .driver = S5M8767_BUCK_DRIVER },
18 { },
19};
20
21static int s5m8767_reg_count(struct udevice *dev)
22{
23 return S5M8767_NUM_OF_REGS;
24}
25
26static int s5m8767_write(struct udevice *dev, uint reg, const uint8_t *buff,
27 int len)
28{
29 if (dm_i2c_write(dev, reg, buff, len)) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090030 pr_err("write error to device: %p register: %#x!", dev, reg);
Simon Glass01651492015-07-02 18:16:00 -060031 return -EIO;
32 }
33
34 return 0;
35}
36
37static int s5m8767_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
38{
39 if (dm_i2c_read(dev, reg, buff, len)) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090040 pr_err("read error from device: %p register: %#x!", dev, reg);
Simon Glass01651492015-07-02 18:16:00 -060041 return -EIO;
42 }
43
44 return 0;
45}
46
47int s5m8767_enable_32khz_cp(struct udevice *dev)
48{
49 return pmic_clrsetbits(dev, S5M8767_EN32KHZ_CP, 0, 1 << 1);
50}
51
52static int s5m8767_bind(struct udevice *dev)
53{
Simon Glass01651492015-07-02 18:16:00 -060054 int children;
Simon Glass2c2d2c22017-05-18 20:09:32 -060055 ofnode node;
Simon Glass01651492015-07-02 18:16:00 -060056
Simon Glass2c2d2c22017-05-18 20:09:32 -060057 node = dev_read_subnode(dev, "regulators");
58 if (!ofnode_valid(node)) {
Simon Glass01651492015-07-02 18:16:00 -060059 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, node, pmic_children_info);
67 if (!children)
68 debug("%s: %s - no child found\n", __func__, dev->name);
69
70 /* Always return success for this device */
71 return 0;
72}
73
74static struct dm_pmic_ops s5m8767_ops = {
75 .reg_count = s5m8767_reg_count,
76 .read = s5m8767_read,
77 .write = s5m8767_write,
78};
79
80static const struct udevice_id s5m8767_ids[] = {
81 { .compatible = "samsung,s5m8767-pmic" },
82 { }
83};
84
85U_BOOT_DRIVER(pmic_s5m8767) = {
86 .name = "s5m8767_pmic",
87 .id = UCLASS_PMIC,
88 .of_match = s5m8767_ids,
89 .bind = s5m8767_bind,
90 .ops = &s5m8767_ops,
91};