blob: 95c2b7e8c74ce600685a51bf78fcd4a73c573615 [file] [log] [blame]
Keerthy662797b2016-09-30 09:34:02 +05301/*
2 * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
3 * Keerthy <j-keerthy@ti.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <fdtdec.h>
10#include <errno.h>
11#include <dm.h>
12#include <i2c.h>
13#include <power/pmic.h>
14#include <power/regulator.h>
15#include <power/lp873x.h>
16#include <dm/device.h>
17
18DECLARE_GLOBAL_DATA_PTR;
19
20static const struct pmic_child_info pmic_children_info[] = {
21 { .prefix = "ldo", .driver = LP873X_LDO_DRIVER },
22 { .prefix = "buck", .driver = LP873X_BUCK_DRIVER },
23 { },
24};
25
26static int lp873x_write(struct udevice *dev, uint reg, const uint8_t *buff,
27 int len)
28{
29 if (dm_i2c_write(dev, reg, buff, len)) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090030 pr_err("write error to device: %p register: %#x!", dev, reg);
Keerthy662797b2016-09-30 09:34:02 +053031 return -EIO;
32 }
33
34 return 0;
35}
36
37static int lp873x_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
38{
39 if (dm_i2c_read(dev, reg, buff, len)) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090040 pr_err("read error from device: %p register: %#x!", dev, reg);
Keerthy662797b2016-09-30 09:34:02 +053041 return -EIO;
42 }
43
44 return 0;
45}
46
47static int lp873x_bind(struct udevice *dev)
48{
Simon Glass2c2d2c22017-05-18 20:09:32 -060049 ofnode regulators_node;
Keerthy662797b2016-09-30 09:34:02 +053050 int children;
Keerthy662797b2016-09-30 09:34:02 +053051
Simon Glass2c2d2c22017-05-18 20:09:32 -060052 regulators_node = dev_read_subnode(dev, "regulators");
53 if (!ofnode_valid(regulators_node)) {
54 debug("%s: %s regulators subnode not found!", __func__,
55 dev->name);
Keerthy662797b2016-09-30 09:34:02 +053056 return -ENXIO;
57 }
58
59 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
60 if (!children)
61 printf("%s: %s - no child found\n", __func__, dev->name);
62
63 /* Always return success for this device */
64 return 0;
65}
66
67static struct dm_pmic_ops lp873x_ops = {
68 .read = lp873x_read,
69 .write = lp873x_write,
70};
71
72static const struct udevice_id lp873x_ids[] = {
73 { .compatible = "ti,lp8732", .data = LP8732 },
74 { .compatible = "ti,lp8733" , .data = LP8733 },
75 { }
76};
77
78U_BOOT_DRIVER(pmic_lp873x) = {
79 .name = "lp873x_pmic",
80 .id = UCLASS_PMIC,
81 .of_match = lp873x_ids,
82 .bind = lp873x_bind,
83 .ops = &lp873x_ops,
84};