blob: fda5bc1516429ee8ec20ff4b9bbf40da893dbbb4 [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
7#include <common.h>
8#include <fdtdec.h>
9#include <errno.h>
10#include <dm.h>
11#include <i2c.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060013#include <linux/printk.h>
Keerthy662797b2016-09-30 09:34:02 +053014#include <power/pmic.h>
15#include <power/regulator.h>
16#include <power/lp873x.h>
17#include <dm/device.h>
18
Keerthy662797b2016-09-30 09:34:02 +053019static const struct pmic_child_info pmic_children_info[] = {
20 { .prefix = "ldo", .driver = LP873X_LDO_DRIVER },
21 { .prefix = "buck", .driver = LP873X_BUCK_DRIVER },
22 { },
23};
24
25static int lp873x_write(struct udevice *dev, uint reg, const uint8_t *buff,
26 int len)
27{
28 if (dm_i2c_write(dev, reg, buff, len)) {
Simon Glass73126ac2018-11-18 08:14:28 -070029 pr_err("write error to device: %p register: %#x!\n", dev, reg);
Keerthy662797b2016-09-30 09:34:02 +053030 return -EIO;
31 }
32
33 return 0;
34}
35
36static int lp873x_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
37{
38 if (dm_i2c_read(dev, reg, buff, len)) {
Simon Glass73126ac2018-11-18 08:14:28 -070039 pr_err("read error from device: %p register: %#x!\n", dev, reg);
Keerthy662797b2016-09-30 09:34:02 +053040 return -EIO;
41 }
42
43 return 0;
44}
45
46static int lp873x_bind(struct udevice *dev)
47{
Simon Glass2c2d2c22017-05-18 20:09:32 -060048 ofnode regulators_node;
Keerthy662797b2016-09-30 09:34:02 +053049 int children;
Keerthy662797b2016-09-30 09:34:02 +053050
Simon Glass2c2d2c22017-05-18 20:09:32 -060051 regulators_node = dev_read_subnode(dev, "regulators");
52 if (!ofnode_valid(regulators_node)) {
Simon Glass73126ac2018-11-18 08:14:28 -070053 debug("%s: %s regulators subnode not found!\n", __func__,
Simon Glass2c2d2c22017-05-18 20:09:32 -060054 dev->name);
Keerthy662797b2016-09-30 09:34:02 +053055 return -ENXIO;
56 }
57
58 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
59 if (!children)
60 printf("%s: %s - no child found\n", __func__, dev->name);
61
62 /* Always return success for this device */
63 return 0;
64}
65
66static struct dm_pmic_ops lp873x_ops = {
67 .read = lp873x_read,
68 .write = lp873x_write,
69};
70
71static const struct udevice_id lp873x_ids[] = {
72 { .compatible = "ti,lp8732", .data = LP8732 },
73 { .compatible = "ti,lp8733" , .data = LP8733 },
74 { }
75};
76
77U_BOOT_DRIVER(pmic_lp873x) = {
78 .name = "lp873x_pmic",
79 .id = UCLASS_PMIC,
80 .of_match = lp873x_ids,
81 .bind = lp873x_bind,
82 .ops = &lp873x_ops,
83};