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