Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Przemyslaw Marczak | d5175dc | 2015-05-13 13:38:32 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Samsung Electronics |
| 4 | * Przemyslaw Marczak <p.marczak@samsung.com> |
Przemyslaw Marczak | d5175dc | 2015-05-13 13:38:32 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
Simon Glass | 10dda9e | 2022-09-06 20:26:54 -0600 | [diff] [blame] | 7 | #define LOG_CATEGORY UCLASS_PMIC |
| 8 | |
Przemyslaw Marczak | d5175dc | 2015-05-13 13:38:32 +0200 | [diff] [blame] | 9 | #include <common.h> |
| 10 | #include <fdtdec.h> |
| 11 | #include <errno.h> |
| 12 | #include <dm.h> |
| 13 | #include <i2c.h> |
Simon Glass | 10dda9e | 2022-09-06 20:26:54 -0600 | [diff] [blame] | 14 | #include <log.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 15 | #include <linux/printk.h> |
Przemyslaw Marczak | d5175dc | 2015-05-13 13:38:32 +0200 | [diff] [blame] | 16 | #include <power/pmic.h> |
| 17 | #include <power/regulator.h> |
| 18 | #include <power/sandbox_pmic.h> |
| 19 | |
Przemyslaw Marczak | d5175dc | 2015-05-13 13:38:32 +0200 | [diff] [blame] | 20 | static const struct pmic_child_info pmic_children_info[] = { |
| 21 | { .prefix = SANDBOX_OF_LDO_PREFIX, .driver = SANDBOX_LDO_DRIVER }, |
| 22 | { .prefix = SANDBOX_OF_BUCK_PREFIX, .driver = SANDBOX_BUCK_DRIVER }, |
| 23 | { }, |
| 24 | }; |
| 25 | |
| 26 | static int sandbox_pmic_reg_count(struct udevice *dev) |
| 27 | { |
| 28 | return SANDBOX_PMIC_REG_COUNT; |
| 29 | } |
| 30 | |
| 31 | static int sandbox_pmic_write(struct udevice *dev, uint reg, |
| 32 | const uint8_t *buff, int len) |
| 33 | { |
| 34 | if (dm_i2c_write(dev, reg, buff, len)) { |
Simon Glass | 10dda9e | 2022-09-06 20:26:54 -0600 | [diff] [blame] | 35 | log_err("write error to device: %p register: %#x!\n", dev, reg); |
Przemyslaw Marczak | d5175dc | 2015-05-13 13:38:32 +0200 | [diff] [blame] | 36 | return -EIO; |
| 37 | } |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | static int sandbox_pmic_read(struct udevice *dev, uint reg, |
| 43 | uint8_t *buff, int len) |
| 44 | { |
| 45 | if (dm_i2c_read(dev, reg, buff, len)) { |
Simon Glass | 10dda9e | 2022-09-06 20:26:54 -0600 | [diff] [blame] | 46 | log_err("read error from device: %p register: %#x!\n", dev, reg); |
Przemyslaw Marczak | d5175dc | 2015-05-13 13:38:32 +0200 | [diff] [blame] | 47 | return -EIO; |
| 48 | } |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static int sandbox_pmic_bind(struct udevice *dev) |
| 54 | { |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 55 | if (!pmic_bind_children(dev, dev_ofnode(dev), pmic_children_info)) |
Simon Glass | 10dda9e | 2022-09-06 20:26:54 -0600 | [diff] [blame] | 56 | log_err("PMIC: %s - no child found!\n", dev->name); |
Przemyslaw Marczak | d5175dc | 2015-05-13 13:38:32 +0200 | [diff] [blame] | 57 | |
| 58 | /* Always return success for this device - allows for PMIC I/O */ |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | static 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 | |
| 68 | static const struct udevice_id sandbox_pmic_ids[] = { |
| 69 | { .compatible = "sandbox,pmic" }, |
| 70 | { } |
| 71 | }; |
| 72 | |
| 73 | U_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 | }; |