blob: 4670a84560ebab526b4c4689f87f172021b5226b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peng Fan1c1f6072015-08-14 11:36:16 +02002/*
3 * Copyright (C) 2015 Freescale Semiconductor, Inc
4 * Peng Fan <Peng.Fan@freescale.com>
Peng Fan1c1f6072015-08-14 11:36:16 +02005 */
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>
15
Peng Fan1c1f6072015-08-14 11:36:16 +020016static const struct pmic_child_info pmic_children_info[] = {
17 /* sw[x], swbst */
18 { .prefix = "s", .driver = PFUZE100_REGULATOR_DRIVER },
19 /* vgen[x], vsnvs, vcc, v33, vcc_sd */
20 { .prefix = "v", .driver = PFUZE100_REGULATOR_DRIVER },
21 { },
22};
23
24static int pfuze100_reg_count(struct udevice *dev)
25{
26 return PFUZE100_NUM_OF_REGS;
27}
28
29static int pfuze100_write(struct udevice *dev, uint reg, const uint8_t *buff,
30 int len)
31{
32 if (dm_i2c_write(dev, reg, buff, len)) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090033 pr_err("write error to device: %p register: %#x!", dev, reg);
Peng Fan1c1f6072015-08-14 11:36:16 +020034 return -EIO;
35 }
36
37 return 0;
38}
39
40static int pfuze100_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
41{
42 if (dm_i2c_read(dev, reg, buff, len)) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090043 pr_err("read error from device: %p register: %#x!", dev, reg);
Peng Fan1c1f6072015-08-14 11:36:16 +020044 return -EIO;
45 }
46
47 return 0;
48}
49
50static int pfuze100_bind(struct udevice *dev)
51{
Simon Glass7a869e62017-05-18 20:09:32 -060052 ofnode regulators_node;
Peng Fan1c1f6072015-08-14 11:36:16 +020053 int children;
Peng Fan1c1f6072015-08-14 11:36:16 +020054
Simon Glass7a869e62017-05-18 20:09:32 -060055 regulators_node = dev_read_subnode(dev, "regulators");
56 if (!ofnode_valid(regulators_node)) {
Peng Fan1c1f6072015-08-14 11:36:16 +020057 debug("%s: %s regulators subnode not found!", __func__,
58 dev->name);
59 return -ENXIO;
60 }
61
62 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
63
64 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
65 if (!children)
66 debug("%s: %s - no child found\n", __func__, dev->name);
67
68 /* Always return success for this device */
69 return 0;
70}
71
72static struct dm_pmic_ops pfuze100_ops = {
73 .reg_count = pfuze100_reg_count,
74 .read = pfuze100_read,
75 .write = pfuze100_write,
76};
77
78static const struct udevice_id pfuze100_ids[] = {
79 { .compatible = "fsl,pfuze100", .data = PFUZE100, },
80 { .compatible = "fsl,pfuze200", .data = PFUZE200, },
81 { .compatible = "fsl,pfuze3000", .data = PFUZE3000, },
82 { }
83};
84
85U_BOOT_DRIVER(pmic_pfuze100) = {
86 .name = "pfuze100 pmic",
87 .id = UCLASS_PMIC,
88 .of_match = pfuze100_ids,
89 .bind = pfuze100_bind,
90 .ops = &pfuze100_ops,
91};