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