blob: e8d6faca160caf27ae3aecc84c11b8d13f4b8ea6 [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
17DECLARE_GLOBAL_DATA_PTR;
18
19static const struct pmic_child_info pmic_children_info[] = {
20 { .prefix = SANDBOX_OF_LDO_PREFIX, .driver = SANDBOX_LDO_DRIVER },
21 { .prefix = SANDBOX_OF_BUCK_PREFIX, .driver = SANDBOX_BUCK_DRIVER },
22 { },
23};
24
25static int sandbox_pmic_reg_count(struct udevice *dev)
26{
27 return SANDBOX_PMIC_REG_COUNT;
28}
29
30static int sandbox_pmic_write(struct udevice *dev, uint reg,
31 const uint8_t *buff, int len)
32{
33 if (dm_i2c_write(dev, reg, buff, len)) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090034 pr_err("write error to device: %p register: %#x!", dev, reg);
Przemyslaw Marczak5d387d02015-05-13 13:38:32 +020035 return -EIO;
36 }
37
38 return 0;
39}
40
41static int sandbox_pmic_read(struct udevice *dev, uint reg,
42 uint8_t *buff, int len)
43{
44 if (dm_i2c_read(dev, reg, buff, len)) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090045 pr_err("read error from device: %p register: %#x!", dev, reg);
Przemyslaw Marczak5d387d02015-05-13 13:38:32 +020046 return -EIO;
47 }
48
49 return 0;
50}
51
52static int sandbox_pmic_bind(struct udevice *dev)
53{
Simon Glass7a869e62017-05-18 20:09:32 -060054 if (!pmic_bind_children(dev, dev_ofnode(dev), pmic_children_info))
Masahiro Yamada9b643e32017-09-16 14:10:41 +090055 pr_err("%s:%d PMIC: %s - no child found!", __func__, __LINE__,
Przemyslaw Marczak5d387d02015-05-13 13:38:32 +020056 dev->name);
57
58 /* Always return success for this device - allows for PMIC I/O */
59 return 0;
60}
61
62static struct dm_pmic_ops sandbox_pmic_ops = {
63 .reg_count = sandbox_pmic_reg_count,
64 .read = sandbox_pmic_read,
65 .write = sandbox_pmic_write,
66};
67
68static const struct udevice_id sandbox_pmic_ids[] = {
69 { .compatible = "sandbox,pmic" },
70 { }
71};
72
73U_BOOT_DRIVER(sandbox_pmic) = {
74 .name = "sandbox_pmic",
75 .id = UCLASS_PMIC,
76 .of_match = sandbox_pmic_ids,
77 .bind = sandbox_pmic_bind,
78 .ops = &sandbox_pmic_ops,
79};