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