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