blob: acfeae2df9702969d683f1d1ee60f8d579c23153 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Przemyslaw Marczakd5175dc2015-05-13 13:38:32 +02002/*
3 * Copyright (C) 2015 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
Przemyslaw Marczakd5175dc2015-05-13 13:38:32 +02005 */
6
Simon Glass10dda9e2022-09-06 20:26:54 -06007#define LOG_CATEGORY UCLASS_PMIC
8
Przemyslaw Marczakd5175dc2015-05-13 13:38:32 +02009#include <common.h>
10#include <fdtdec.h>
11#include <errno.h>
12#include <dm.h>
13#include <i2c.h>
Simon Glass10dda9e2022-09-06 20:26:54 -060014#include <log.h>
Przemyslaw Marczakd5175dc2015-05-13 13:38:32 +020015#include <power/pmic.h>
16#include <power/regulator.h>
17#include <power/sandbox_pmic.h>
18
Przemyslaw Marczakd5175dc2015-05-13 13:38:32 +020019static 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)) {
Simon Glass10dda9e2022-09-06 20:26:54 -060034 log_err("write error to device: %p register: %#x!\n", dev, reg);
Przemyslaw Marczakd5175dc2015-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)) {
Simon Glass10dda9e2022-09-06 20:26:54 -060045 log_err("read error from device: %p register: %#x!\n", dev, reg);
Przemyslaw Marczakd5175dc2015-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 Glass2c2d2c22017-05-18 20:09:32 -060054 if (!pmic_bind_children(dev, dev_ofnode(dev), pmic_children_info))
Simon Glass10dda9e2022-09-06 20:26:54 -060055 log_err("PMIC: %s - no child found!\n", dev->name);
Przemyslaw Marczakd5175dc2015-05-13 13:38:32 +020056
57 /* Always return success for this device - allows for PMIC I/O */
58 return 0;
59}
60
61static struct dm_pmic_ops sandbox_pmic_ops = {
62 .reg_count = sandbox_pmic_reg_count,
63 .read = sandbox_pmic_read,
64 .write = sandbox_pmic_write,
65};
66
67static const struct udevice_id sandbox_pmic_ids[] = {
68 { .compatible = "sandbox,pmic" },
69 { }
70};
71
72U_BOOT_DRIVER(sandbox_pmic) = {
73 .name = "sandbox_pmic",
74 .id = UCLASS_PMIC,
75 .of_match = sandbox_pmic_ids,
76 .bind = sandbox_pmic_bind,
77 .ops = &sandbox_pmic_ops,
78};