Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Peng Fan | 6f4f6d2 | 2015-08-14 11:36:16 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Freescale Semiconductor, Inc |
| 4 | * Peng Fan <Peng.Fan@freescale.com> |
Peng Fan | 6f4f6d2 | 2015-08-14 11:36:16 +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/pfuze100_pmic.h> |
Trent Piepho | 3713c9b | 2018-04-25 10:06:00 -0700 | [diff] [blame] | 15 | #include <power/pfuze3000_pmic.h> |
Peng Fan | 6f4f6d2 | 2015-08-14 11:36:16 +0200 | [diff] [blame] | 16 | |
Peng Fan | 6f4f6d2 | 2015-08-14 11:36:16 +0200 | [diff] [blame] | 17 | static const struct pmic_child_info pmic_children_info[] = { |
| 18 | /* sw[x], swbst */ |
| 19 | { .prefix = "s", .driver = PFUZE100_REGULATOR_DRIVER }, |
| 20 | /* vgen[x], vsnvs, vcc, v33, vcc_sd */ |
| 21 | { .prefix = "v", .driver = PFUZE100_REGULATOR_DRIVER }, |
| 22 | { }, |
| 23 | }; |
| 24 | |
| 25 | static int pfuze100_reg_count(struct udevice *dev) |
| 26 | { |
Trent Piepho | 3713c9b | 2018-04-25 10:06:00 -0700 | [diff] [blame] | 27 | return dev->driver_data == PFUZE3000 ? PFUZE3000_NUM_OF_REGS : PFUZE100_NUM_OF_REGS; |
Peng Fan | 6f4f6d2 | 2015-08-14 11:36:16 +0200 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | static int pfuze100_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 31 | int len) |
| 32 | { |
| 33 | if (dm_i2c_write(dev, reg, buff, len)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 34 | pr_err("write error to device: %p register: %#x!\n", dev, reg); |
Peng Fan | 6f4f6d2 | 2015-08-14 11:36:16 +0200 | [diff] [blame] | 35 | return -EIO; |
| 36 | } |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | static int pfuze100_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 42 | { |
| 43 | if (dm_i2c_read(dev, reg, buff, len)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 44 | pr_err("read error from device: %p register: %#x!\n", dev, reg); |
Peng Fan | 6f4f6d2 | 2015-08-14 11:36:16 +0200 | [diff] [blame] | 45 | return -EIO; |
| 46 | } |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static int pfuze100_bind(struct udevice *dev) |
| 52 | { |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 53 | ofnode regulators_node; |
Peng Fan | 6f4f6d2 | 2015-08-14 11:36:16 +0200 | [diff] [blame] | 54 | int children; |
Peng Fan | 6f4f6d2 | 2015-08-14 11:36:16 +0200 | [diff] [blame] | 55 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 56 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 57 | if (!ofnode_valid(regulators_node)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 58 | debug("%s: %s regulators subnode not found!\n", __func__, |
Peng Fan | 6f4f6d2 | 2015-08-14 11:36:16 +0200 | [diff] [blame] | 59 | dev->name); |
| 60 | return -ENXIO; |
| 61 | } |
| 62 | |
| 63 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
| 64 | |
| 65 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 66 | if (!children) |
| 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 pfuze100_ops = { |
| 74 | .reg_count = pfuze100_reg_count, |
| 75 | .read = pfuze100_read, |
| 76 | .write = pfuze100_write, |
| 77 | }; |
| 78 | |
| 79 | static const struct udevice_id pfuze100_ids[] = { |
| 80 | { .compatible = "fsl,pfuze100", .data = PFUZE100, }, |
| 81 | { .compatible = "fsl,pfuze200", .data = PFUZE200, }, |
| 82 | { .compatible = "fsl,pfuze3000", .data = PFUZE3000, }, |
| 83 | { } |
| 84 | }; |
| 85 | |
| 86 | U_BOOT_DRIVER(pmic_pfuze100) = { |
| 87 | .name = "pfuze100 pmic", |
| 88 | .id = UCLASS_PMIC, |
| 89 | .of_match = pfuze100_ids, |
| 90 | .bind = pfuze100_bind, |
| 91 | .ops = &pfuze100_ops, |
| 92 | }; |