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