1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
7 #define LOG_CATEGORY UCLASS_PMIC
15 #include <power/pmic.h>
16 #include <power/regulator.h>
17 #include <power/sandbox_pmic.h>
19 static 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 },
25 static int sandbox_pmic_reg_count(struct udevice *dev)
27 return SANDBOX_PMIC_REG_COUNT;
30 static int sandbox_pmic_write(struct udevice *dev, uint reg,
31 const uint8_t *buff, int len)
33 if (dm_i2c_write(dev, reg, buff, len)) {
34 log_err("write error to device: %p register: %#x!\n", dev, reg);
41 static int sandbox_pmic_read(struct udevice *dev, uint reg,
42 uint8_t *buff, int len)
44 if (dm_i2c_read(dev, reg, buff, len)) {
45 log_err("read error from device: %p register: %#x!\n", dev, reg);
52 static int sandbox_pmic_bind(struct udevice *dev)
54 if (!pmic_bind_children(dev, dev_ofnode(dev), pmic_children_info))
55 log_err("PMIC: %s - no child found!\n", dev->name);
57 /* Always return success for this device - allows for PMIC I/O */
61 static struct dm_pmic_ops sandbox_pmic_ops = {
62 .reg_count = sandbox_pmic_reg_count,
63 .read = sandbox_pmic_read,
64 .write = sandbox_pmic_write,
67 static const struct udevice_id sandbox_pmic_ids[] = {
68 { .compatible = "sandbox,pmic" },
72 U_BOOT_DRIVER(sandbox_pmic) = {
73 .name = "sandbox_pmic",
75 .of_match = sandbox_pmic_ids,
76 .bind = sandbox_pmic_bind,
77 .ops = &sandbox_pmic_ops,