blob: 3812e240ab085340b2ee932132690dce6dbe3041 [file] [log] [blame]
Simon Glassd308c012015-07-02 18:16:00 -06001/*
2 * Copyright (C) 2015 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
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/regulator.h>
14#include <power/s5m8767.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
18static const struct pmic_child_info pmic_children_info[] = {
19 { .prefix = "LDO", .driver = S5M8767_LDO_DRIVER },
20 { .prefix = "BUCK", .driver = S5M8767_BUCK_DRIVER },
21 { },
22};
23
24static int s5m8767_reg_count(struct udevice *dev)
25{
26 return S5M8767_NUM_OF_REGS;
27}
28
29static int s5m8767_write(struct udevice *dev, uint reg, const uint8_t *buff,
30 int len)
31{
32 if (dm_i2c_write(dev, reg, buff, len)) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090033 pr_err("write error to device: %p register: %#x!", dev, reg);
Simon Glassd308c012015-07-02 18:16:00 -060034 return -EIO;
35 }
36
37 return 0;
38}
39
40static int s5m8767_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
41{
42 if (dm_i2c_read(dev, reg, buff, len)) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090043 pr_err("read error from device: %p register: %#x!", dev, reg);
Simon Glassd308c012015-07-02 18:16:00 -060044 return -EIO;
45 }
46
47 return 0;
48}
49
50int s5m8767_enable_32khz_cp(struct udevice *dev)
51{
52 return pmic_clrsetbits(dev, S5M8767_EN32KHZ_CP, 0, 1 << 1);
53}
54
55static int s5m8767_bind(struct udevice *dev)
56{
Simon Glassd308c012015-07-02 18:16:00 -060057 int children;
Simon Glass7a869e62017-05-18 20:09:32 -060058 ofnode node;
Simon Glassd308c012015-07-02 18:16:00 -060059
Simon Glass7a869e62017-05-18 20:09:32 -060060 node = dev_read_subnode(dev, "regulators");
61 if (!ofnode_valid(node)) {
Simon Glassd308c012015-07-02 18:16:00 -060062 debug("%s: %s regulators subnode not found!", __func__,
63 dev->name);
64 return -ENXIO;
65 }
66
67 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
68
69 children = pmic_bind_children(dev, node, pmic_children_info);
70 if (!children)
71 debug("%s: %s - no child found\n", __func__, dev->name);
72
73 /* Always return success for this device */
74 return 0;
75}
76
77static struct dm_pmic_ops s5m8767_ops = {
78 .reg_count = s5m8767_reg_count,
79 .read = s5m8767_read,
80 .write = s5m8767_write,
81};
82
83static const struct udevice_id s5m8767_ids[] = {
84 { .compatible = "samsung,s5m8767-pmic" },
85 { }
86};
87
88U_BOOT_DRIVER(pmic_s5m8767) = {
89 .name = "s5m8767_pmic",
90 .id = UCLASS_PMIC,
91 .of_match = s5m8767_ids,
92 .bind = s5m8767_bind,
93 .ops = &s5m8767_ops,
94};