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 | |
| 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 Marczak | d5175dc | 2015-05-13 13:38:32 +0200 | [diff] [blame] | 16 | static 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 | |
| 22 | static int sandbox_pmic_reg_count(struct udevice *dev) |
| 23 | { |
| 24 | return SANDBOX_PMIC_REG_COUNT; |
| 25 | } |
| 26 | |
| 27 | static 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 Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 31 | pr_err("write error to device: %p register: %#x!", dev, reg); |
Przemyslaw Marczak | d5175dc | 2015-05-13 13:38:32 +0200 | [diff] [blame] | 32 | return -EIO; |
| 33 | } |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | static 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 Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 42 | pr_err("read error from device: %p register: %#x!", dev, reg); |
Przemyslaw Marczak | d5175dc | 2015-05-13 13:38:32 +0200 | [diff] [blame] | 43 | return -EIO; |
| 44 | } |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static int sandbox_pmic_bind(struct udevice *dev) |
| 50 | { |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 51 | if (!pmic_bind_children(dev, dev_ofnode(dev), pmic_children_info)) |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 52 | pr_err("%s:%d PMIC: %s - no child found!", __func__, __LINE__, |
Przemyslaw Marczak | d5175dc | 2015-05-13 13:38:32 +0200 | [diff] [blame] | 53 | dev->name); |
| 54 | |
| 55 | /* Always return success for this device - allows for PMIC I/O */ |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static 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 | |
| 65 | static const struct udevice_id sandbox_pmic_ids[] = { |
| 66 | { .compatible = "sandbox,pmic" }, |
| 67 | { } |
| 68 | }; |
| 69 | |
| 70 | U_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 | }; |