blob: 9f02c0b6f6fb1f99e026dfb7db3fbccd6d5b1943 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +02002/*
3 * Copyright (C) 2014-2015 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +02005 */
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>
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020013#include <power/pmic.h>
14#include <power/regulator.h>
15#include <power/max77686_pmic.h>
16
Przemyslaw Marczak10314982015-05-13 13:38:26 +020017static const struct pmic_child_info pmic_children_info[] = {
Simon Glass50a49262015-07-02 18:16:02 -060018 { .prefix = "LDO", .driver = MAX77686_LDO_DRIVER },
19 { .prefix = "BUCK", .driver = MAX77686_BUCK_DRIVER },
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020020 { },
21};
22
Przemyslaw Marczak10314982015-05-13 13:38:26 +020023static int max77686_reg_count(struct udevice *dev)
24{
25 return MAX77686_NUM_OF_REGS;
26}
27
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020028static int max77686_write(struct udevice *dev, uint reg, const uint8_t *buff,
29 int len)
30{
31 if (dm_i2c_write(dev, reg, buff, len)) {
Simon Glass73126ac2018-11-18 08:14:28 -070032 pr_err("write error to device: %p register: %#x!\n", dev, reg);
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020033 return -EIO;
34 }
35
36 return 0;
37}
38
39static int max77686_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
40{
41 if (dm_i2c_read(dev, reg, buff, len)) {
Simon Glass73126ac2018-11-18 08:14:28 -070042 pr_err("read error from device: %p register: %#x!\n", dev, reg);
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020043 return -EIO;
44 }
45
46 return 0;
47}
48
49static int max77686_bind(struct udevice *dev)
50{
Simon Glass2c2d2c22017-05-18 20:09:32 -060051 ofnode regulators_node;
Przemyslaw Marczak10314982015-05-13 13:38:26 +020052 int children;
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020053
Simon Glass2c2d2c22017-05-18 20:09:32 -060054 regulators_node = dev_read_subnode(dev, "voltage-regulators");
55 if (!ofnode_valid(regulators_node)) {
Simon Glass73126ac2018-11-18 08:14:28 -070056 debug("%s: %s regulators subnode not found!\n", __func__,
57 dev->name);
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020058 return -ENXIO;
59 }
60
61 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
62
Przemyslaw Marczak10314982015-05-13 13:38:26 +020063 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
64 if (!children)
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020065 debug("%s: %s - no child found\n", __func__, dev->name);
66
67 /* Always return success for this device */
68 return 0;
69}
70
71static struct dm_pmic_ops max77686_ops = {
Przemyslaw Marczak10314982015-05-13 13:38:26 +020072 .reg_count = max77686_reg_count,
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020073 .read = max77686_read,
74 .write = max77686_write,
75};
76
77static const struct udevice_id max77686_ids[] = {
78 { .compatible = "maxim,max77686" },
79 { }
80};
81
82U_BOOT_DRIVER(pmic_max77686) = {
Simon Glass50a49262015-07-02 18:16:02 -060083 .name = "max77686_pmic",
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020084 .id = UCLASS_PMIC,
85 .of_match = max77686_ids,
86 .bind = max77686_bind,
87 .ops = &max77686_ops,
88};