blob: 64e2f276dabdfa27f81a97ad694a4fb45d16c183 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Przemyslaw Marczak5d387d02015-05-13 13:38:32 +02002/*
3 * Copyright (C) 2015 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
Przemyslaw Marczak5d387d02015-05-13 13:38:32 +02005 */
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/sandbox_pmic.h>
15
Przemyslaw Marczak5d387d02015-05-13 13:38:32 +020016static const struct pmic_child_info pmic_children_info[] = {
17 { .prefix = SANDBOX_OF_LDO_PREFIX, .driver = SANDBOX_LDO_DRIVER },
18 { .prefix = SANDBOX_OF_BUCK_PREFIX, .driver = SANDBOX_BUCK_DRIVER },
19 { },
20};
21
22static int sandbox_pmic_reg_count(struct udevice *dev)
23{
24 return SANDBOX_PMIC_REG_COUNT;
25}
26
27static int sandbox_pmic_write(struct udevice *dev, uint reg,
28 const uint8_t *buff, int len)
29{
30 if (dm_i2c_write(dev, reg, buff, len)) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090031 pr_err("write error to device: %p register: %#x!", dev, reg);
Przemyslaw Marczak5d387d02015-05-13 13:38:32 +020032 return -EIO;
33 }
34
35 return 0;
36}
37
38static int sandbox_pmic_read(struct udevice *dev, uint reg,
39 uint8_t *buff, int len)
40{
41 if (dm_i2c_read(dev, reg, buff, len)) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090042 pr_err("read error from device: %p register: %#x!", dev, reg);
Przemyslaw Marczak5d387d02015-05-13 13:38:32 +020043 return -EIO;
44 }
45
46 return 0;
47}
48
49static int sandbox_pmic_bind(struct udevice *dev)
50{
Simon Glass7a869e62017-05-18 20:09:32 -060051 if (!pmic_bind_children(dev, dev_ofnode(dev), pmic_children_info))
Masahiro Yamada9b643e32017-09-16 14:10:41 +090052 pr_err("%s:%d PMIC: %s - no child found!", __func__, __LINE__,
Przemyslaw Marczak5d387d02015-05-13 13:38:32 +020053 dev->name);
54
55 /* Always return success for this device - allows for PMIC I/O */
56 return 0;
57}
58
59static struct dm_pmic_ops sandbox_pmic_ops = {
60 .reg_count = sandbox_pmic_reg_count,
61 .read = sandbox_pmic_read,
62 .write = sandbox_pmic_write,
63};
64
65static const struct udevice_id sandbox_pmic_ids[] = {
66 { .compatible = "sandbox,pmic" },
67 { }
68};
69
70U_BOOT_DRIVER(sandbox_pmic) = {
71 .name = "sandbox_pmic",
72 .id = UCLASS_PMIC,
73 .of_match = sandbox_pmic_ids,
74 .bind = sandbox_pmic_bind,
75 .ops = &sandbox_pmic_ops,
76};