/src/u-boot/drivers/power/pmic/pfuze100.c
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-2.0+ |
2 | | /* |
3 | | * Copyright (C) 2015 Freescale Semiconductor, Inc |
4 | | * Peng Fan <Peng.Fan@freescale.com> |
5 | | */ |
6 | | |
7 | | #include <fdtdec.h> |
8 | | #include <errno.h> |
9 | | #include <dm.h> |
10 | | #include <i2c.h> |
11 | | #include <log.h> |
12 | | #include <linux/printk.h> |
13 | | #include <power/pmic.h> |
14 | | #include <power/regulator.h> |
15 | | #include <power/pfuze100_pmic.h> |
16 | | #include <power/pfuze3000_pmic.h> |
17 | | |
18 | | static const struct pmic_child_info pmic_children_info[] = { |
19 | | /* sw[x], swbst */ |
20 | | { .prefix = "s", .driver = PFUZE100_REGULATOR_DRIVER }, |
21 | | /* vgen[x], vsnvs, vcc, v33, vcc_sd */ |
22 | | { .prefix = "v", .driver = PFUZE100_REGULATOR_DRIVER }, |
23 | | { }, |
24 | | }; |
25 | | |
26 | | static int pfuze100_reg_count(struct udevice *dev) |
27 | 0 | { |
28 | 0 | return dev->driver_data == PFUZE3000 ? PFUZE3000_NUM_OF_REGS : PFUZE100_NUM_OF_REGS; |
29 | 0 | } |
30 | | |
31 | | static int pfuze100_write(struct udevice *dev, uint reg, const uint8_t *buff, |
32 | | int len) |
33 | 0 | { |
34 | 0 | if (dm_i2c_write(dev, reg, buff, len)) { |
35 | 0 | pr_err("write error to device: %p register: %#x!\n", dev, reg); |
36 | 0 | return -EIO; |
37 | 0 | } |
38 | | |
39 | 0 | return 0; |
40 | 0 | } |
41 | | |
42 | | static int pfuze100_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
43 | 0 | { |
44 | 0 | if (dm_i2c_read(dev, reg, buff, len)) { |
45 | 0 | debug("read error from device: %p register: %#x!\n", dev, reg); |
46 | 0 | return -EIO; |
47 | 0 | } |
48 | | |
49 | 0 | return 0; |
50 | 0 | } |
51 | | |
52 | | static int pfuze100_bind(struct udevice *dev) |
53 | 0 | { |
54 | 0 | ofnode regulators_node; |
55 | 0 | int children; |
56 | |
|
57 | 0 | regulators_node = dev_read_subnode(dev, "regulators"); |
58 | 0 | if (!ofnode_valid(regulators_node)) { |
59 | 0 | debug("%s: %s regulators subnode not found!\n", __func__, |
60 | 0 | dev->name); |
61 | 0 | return -ENXIO; |
62 | 0 | } |
63 | | |
64 | 0 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
65 | |
|
66 | 0 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
67 | 0 | if (!children) |
68 | 0 | debug("%s: %s - no child found\n", __func__, dev->name); |
69 | | |
70 | | /* Always return success for this device */ |
71 | 0 | return 0; |
72 | 0 | } |
73 | | |
74 | | static struct dm_pmic_ops pfuze100_ops = { |
75 | | .reg_count = pfuze100_reg_count, |
76 | | .read = pfuze100_read, |
77 | | .write = pfuze100_write, |
78 | | }; |
79 | | |
80 | | static const struct udevice_id pfuze100_ids[] = { |
81 | | { .compatible = "fsl,pfuze100", .data = PFUZE100, }, |
82 | | { .compatible = "fsl,pfuze200", .data = PFUZE200, }, |
83 | | { .compatible = "fsl,pfuze3000", .data = PFUZE3000, }, |
84 | | { } |
85 | | }; |
86 | | |
87 | | U_BOOT_DRIVER(pmic_pfuze100) = { |
88 | | .name = "pfuze100 pmic", |
89 | | .id = UCLASS_PMIC, |
90 | | .of_match = pfuze100_ids, |
91 | | .bind = pfuze100_bind, |
92 | | .ops = &pfuze100_ops, |
93 | | }; |