blob: 2c8fa4ea312f2ac14aa39aa081f37e7118150377 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Keerthy662797b2016-09-30 09:34:02 +05302/*
3 * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
4 * Keerthy <j-keerthy@ti.com>
Keerthy662797b2016-09-30 09:34:02 +05305 */
6
Keerthy662797b2016-09-30 09:34:02 +05307#include <fdtdec.h>
8#include <errno.h>
9#include <dm.h>
10#include <i2c.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060012#include <linux/printk.h>
Keerthy662797b2016-09-30 09:34:02 +053013#include <power/pmic.h>
14#include <power/regulator.h>
15#include <power/lp873x.h>
16#include <dm/device.h>
17
Keerthy662797b2016-09-30 09:34:02 +053018static const struct pmic_child_info pmic_children_info[] = {
19 { .prefix = "ldo", .driver = LP873X_LDO_DRIVER },
20 { .prefix = "buck", .driver = LP873X_BUCK_DRIVER },
21 { },
22};
23
24static int lp873x_write(struct udevice *dev, uint reg, const uint8_t *buff,
25 int len)
26{
27 if (dm_i2c_write(dev, reg, buff, len)) {
Simon Glass73126ac2018-11-18 08:14:28 -070028 pr_err("write error to device: %p register: %#x!\n", dev, reg);
Keerthy662797b2016-09-30 09:34:02 +053029 return -EIO;
30 }
31
32 return 0;
33}
34
35static int lp873x_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
36{
37 if (dm_i2c_read(dev, reg, buff, len)) {
Simon Glass73126ac2018-11-18 08:14:28 -070038 pr_err("read error from device: %p register: %#x!\n", dev, reg);
Keerthy662797b2016-09-30 09:34:02 +053039 return -EIO;
40 }
41
42 return 0;
43}
44
45static int lp873x_bind(struct udevice *dev)
46{
Simon Glass2c2d2c22017-05-18 20:09:32 -060047 ofnode regulators_node;
Keerthy662797b2016-09-30 09:34:02 +053048 int children;
Keerthy662797b2016-09-30 09:34:02 +053049
Simon Glass2c2d2c22017-05-18 20:09:32 -060050 regulators_node = dev_read_subnode(dev, "regulators");
51 if (!ofnode_valid(regulators_node)) {
Simon Glass73126ac2018-11-18 08:14:28 -070052 debug("%s: %s regulators subnode not found!\n", __func__,
Simon Glass2c2d2c22017-05-18 20:09:32 -060053 dev->name);
Keerthy662797b2016-09-30 09:34:02 +053054 return -ENXIO;
55 }
56
57 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
58 if (!children)
59 printf("%s: %s - no child found\n", __func__, dev->name);
60
61 /* Always return success for this device */
62 return 0;
63}
64
65static struct dm_pmic_ops lp873x_ops = {
66 .read = lp873x_read,
67 .write = lp873x_write,
68};
69
70static const struct udevice_id lp873x_ids[] = {
71 { .compatible = "ti,lp8732", .data = LP8732 },
72 { .compatible = "ti,lp8733" , .data = LP8733 },
73 { }
74};
75
76U_BOOT_DRIVER(pmic_lp873x) = {
77 .name = "lp873x_pmic",
78 .id = UCLASS_PMIC,
79 .of_match = lp873x_ids,
80 .bind = lp873x_bind,
81 .ops = &lp873x_ops,
82};