Przemyslaw Marczak | 52a3de5 | 2015-04-20 20:07:46 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014-2015 Samsung Electronics |
| 3 | * Przemyslaw Marczak <p.marczak@samsung.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <fdtdec.h> |
| 10 | #include <errno.h> |
| 11 | #include <dm.h> |
| 12 | #include <i2c.h> |
| 13 | #include <power/pmic.h> |
| 14 | #include <power/regulator.h> |
| 15 | #include <power/max77686_pmic.h> |
| 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Przemyslaw Marczak | f415a3e | 2015-05-13 13:38:26 +0200 | [diff] [blame] | 19 | static const struct pmic_child_info pmic_children_info[] = { |
Simon Glass | b5ffa4f | 2015-07-02 18:16:02 -0600 | [diff] [blame] | 20 | { .prefix = "LDO", .driver = MAX77686_LDO_DRIVER }, |
| 21 | { .prefix = "BUCK", .driver = MAX77686_BUCK_DRIVER }, |
Przemyslaw Marczak | 52a3de5 | 2015-04-20 20:07:46 +0200 | [diff] [blame] | 22 | { }, |
| 23 | }; |
| 24 | |
Przemyslaw Marczak | f415a3e | 2015-05-13 13:38:26 +0200 | [diff] [blame] | 25 | static int max77686_reg_count(struct udevice *dev) |
| 26 | { |
| 27 | return MAX77686_NUM_OF_REGS; |
| 28 | } |
| 29 | |
Przemyslaw Marczak | 52a3de5 | 2015-04-20 20:07:46 +0200 | [diff] [blame] | 30 | static int max77686_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 31 | int len) |
| 32 | { |
| 33 | if (dm_i2c_write(dev, reg, buff, len)) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 34 | pr_err("write error to device: %p register: %#x!", dev, reg); |
Przemyslaw Marczak | 52a3de5 | 2015-04-20 20:07:46 +0200 | [diff] [blame] | 35 | return -EIO; |
| 36 | } |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | static int max77686_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 42 | { |
| 43 | if (dm_i2c_read(dev, reg, buff, len)) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 44 | pr_err("read error from device: %p register: %#x!", dev, reg); |
Przemyslaw Marczak | 52a3de5 | 2015-04-20 20:07:46 +0200 | [diff] [blame] | 45 | return -EIO; |
| 46 | } |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static int max77686_bind(struct udevice *dev) |
| 52 | { |
Simon Glass | 7a869e6 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 53 | ofnode regulators_node; |
Przemyslaw Marczak | f415a3e | 2015-05-13 13:38:26 +0200 | [diff] [blame] | 54 | int children; |
Przemyslaw Marczak | 52a3de5 | 2015-04-20 20:07:46 +0200 | [diff] [blame] | 55 | |
Simon Glass | 7a869e6 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 56 | regulators_node = dev_read_subnode(dev, "voltage-regulators"); |
| 57 | if (!ofnode_valid(regulators_node)) { |
Przemyslaw Marczak | 52a3de5 | 2015-04-20 20:07:46 +0200 | [diff] [blame] | 58 | debug("%s: %s regulators subnode not found!", __func__, |
| 59 | dev->name); |
| 60 | return -ENXIO; |
| 61 | } |
| 62 | |
| 63 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
| 64 | |
Przemyslaw Marczak | f415a3e | 2015-05-13 13:38:26 +0200 | [diff] [blame] | 65 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 66 | if (!children) |
Przemyslaw Marczak | 52a3de5 | 2015-04-20 20:07:46 +0200 | [diff] [blame] | 67 | debug("%s: %s - no child found\n", __func__, dev->name); |
| 68 | |
| 69 | /* Always return success for this device */ |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static struct dm_pmic_ops max77686_ops = { |
Przemyslaw Marczak | f415a3e | 2015-05-13 13:38:26 +0200 | [diff] [blame] | 74 | .reg_count = max77686_reg_count, |
Przemyslaw Marczak | 52a3de5 | 2015-04-20 20:07:46 +0200 | [diff] [blame] | 75 | .read = max77686_read, |
| 76 | .write = max77686_write, |
| 77 | }; |
| 78 | |
| 79 | static const struct udevice_id max77686_ids[] = { |
| 80 | { .compatible = "maxim,max77686" }, |
| 81 | { } |
| 82 | }; |
| 83 | |
| 84 | U_BOOT_DRIVER(pmic_max77686) = { |
Simon Glass | b5ffa4f | 2015-07-02 18:16:02 -0600 | [diff] [blame] | 85 | .name = "max77686_pmic", |
Przemyslaw Marczak | 52a3de5 | 2015-04-20 20:07:46 +0200 | [diff] [blame] | 86 | .id = UCLASS_PMIC, |
| 87 | .of_match = max77686_ids, |
| 88 | .bind = max77686_bind, |
| 89 | .ops = &max77686_ops, |
| 90 | }; |