blob: 8295fab3f02d4c162f3a60d0338614be6d170e62 [file] [log] [blame]
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +02001/*
2 * Copyright (C) 2014-2015 Samsung Electronics
3 * Przemyslaw Marczak <p.marczak@samsung.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/max77686_pmic.h>
16
17DECLARE_GLOBAL_DATA_PTR;
18
Przemyslaw Marczak10314982015-05-13 13:38:26 +020019static const struct pmic_child_info pmic_children_info[] = {
Simon Glass50a49262015-07-02 18:16:02 -060020 { .prefix = "LDO", .driver = MAX77686_LDO_DRIVER },
21 { .prefix = "BUCK", .driver = MAX77686_BUCK_DRIVER },
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020022 { },
23};
24
Przemyslaw Marczak10314982015-05-13 13:38:26 +020025static int max77686_reg_count(struct udevice *dev)
26{
27 return MAX77686_NUM_OF_REGS;
28}
29
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020030static int max77686_write(struct udevice *dev, uint reg, const uint8_t *buff,
31 int len)
32{
33 if (dm_i2c_write(dev, reg, buff, len)) {
34 error("write error to device: %p register: %#x!", dev, reg);
35 return -EIO;
36 }
37
38 return 0;
39}
40
41static int max77686_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
42{
43 if (dm_i2c_read(dev, reg, buff, len)) {
44 error("read error from device: %p register: %#x!", dev, reg);
45 return -EIO;
46 }
47
48 return 0;
49}
50
51static int max77686_bind(struct udevice *dev)
52{
53 int regulators_node;
54 const void *blob = gd->fdt_blob;
Przemyslaw Marczak10314982015-05-13 13:38:26 +020055 int children;
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020056
Simon Glassdd79d6e2017-01-17 16:52:55 -070057 regulators_node = fdt_subnode_offset(blob, dev_of_offset(dev),
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020058 "voltage-regulators");
59 if (regulators_node <= 0) {
60 debug("%s: %s regulators subnode not found!", __func__,
61 dev->name);
62 return -ENXIO;
63 }
64
65 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
66
Przemyslaw Marczak10314982015-05-13 13:38:26 +020067 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
68 if (!children)
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020069 debug("%s: %s - no child found\n", __func__, dev->name);
70
71 /* Always return success for this device */
72 return 0;
73}
74
75static struct dm_pmic_ops max77686_ops = {
Przemyslaw Marczak10314982015-05-13 13:38:26 +020076 .reg_count = max77686_reg_count,
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020077 .read = max77686_read,
78 .write = max77686_write,
79};
80
81static const struct udevice_id max77686_ids[] = {
82 { .compatible = "maxim,max77686" },
83 { }
84};
85
86U_BOOT_DRIVER(pmic_max77686) = {
Simon Glass50a49262015-07-02 18:16:02 -060087 .name = "max77686_pmic",
Przemyslaw Marczak58ea76f2015-04-20 20:07:46 +020088 .id = UCLASS_PMIC,
89 .of_match = max77686_ids,
90 .bind = max77686_bind,
91 .ops = &max77686_ops,
92};