blob: 80209d3d918fecc95776cc660a612c2144170181 [file] [log] [blame]
Przemyslaw Marczak5d387d02015-05-13 13:38:32 +02001/*
2 * Copyright (C) 2015 Samsung Electronics
3 * Przemyslaw Marczak <p.marczak@samsung.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <fdtdec.h>
10#include <errno.h>
11#include <dm.h>
12#include <i2c.h>
13#include <power/pmic.h>
14#include <power/regulator.h>
15#include <power/sandbox_pmic.h>
16
Przemyslaw Marczak5d387d02015-05-13 13:38:32 +020017static const struct pmic_child_info pmic_children_info[] = {
18 { .prefix = SANDBOX_OF_LDO_PREFIX, .driver = SANDBOX_LDO_DRIVER },
19 { .prefix = SANDBOX_OF_BUCK_PREFIX, .driver = SANDBOX_BUCK_DRIVER },
20 { },
21};
22
23static int sandbox_pmic_reg_count(struct udevice *dev)
24{
25 return SANDBOX_PMIC_REG_COUNT;
26}
27
28static int sandbox_pmic_write(struct udevice *dev, uint reg,
29 const uint8_t *buff, int len)
30{
31 if (dm_i2c_write(dev, reg, buff, len)) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090032 pr_err("write error to device: %p register: %#x!", dev, reg);
Przemyslaw Marczak5d387d02015-05-13 13:38:32 +020033 return -EIO;
34 }
35
36 return 0;
37}
38
39static int sandbox_pmic_read(struct udevice *dev, uint reg,
40 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);
Przemyslaw Marczak5d387d02015-05-13 13:38:32 +020044 return -EIO;
45 }
46
47 return 0;
48}
49
50static int sandbox_pmic_bind(struct udevice *dev)
51{
Simon Glass7a869e62017-05-18 20:09:32 -060052 if (!pmic_bind_children(dev, dev_ofnode(dev), pmic_children_info))
Masahiro Yamada9b643e32017-09-16 14:10:41 +090053 pr_err("%s:%d PMIC: %s - no child found!", __func__, __LINE__,
Przemyslaw Marczak5d387d02015-05-13 13:38:32 +020054 dev->name);
55
56 /* Always return success for this device - allows for PMIC I/O */
57 return 0;
58}
59
60static struct dm_pmic_ops sandbox_pmic_ops = {
61 .reg_count = sandbox_pmic_reg_count,
62 .read = sandbox_pmic_read,
63 .write = sandbox_pmic_write,
64};
65
66static const struct udevice_id sandbox_pmic_ids[] = {
67 { .compatible = "sandbox,pmic" },
68 { }
69};
70
71U_BOOT_DRIVER(sandbox_pmic) = {
72 .name = "sandbox_pmic",
73 .id = UCLASS_PMIC,
74 .of_match = sandbox_pmic_ids,
75 .bind = sandbox_pmic_bind,
76 .ops = &sandbox_pmic_ops,
77};