blob: e9503e24a42bc2c11ac48db513376e5c96714004 [file] [log] [blame]
Przemyslaw Marczak52a3de52015-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
19static const struct pmic_child_info pmic_childs_info[] = {
20 { .prefix = "ldo", .driver = MAX77686_LDO_DRIVER },
21 { .prefix = "buck", .driver = MAX77686_BUCK_DRIVER },
22 { },
23};
24
25static int max77686_write(struct udevice *dev, uint reg, const uint8_t *buff,
26 int len)
27{
28 if (dm_i2c_write(dev, reg, buff, len)) {
29 error("write error to device: %p register: %#x!", dev, reg);
30 return -EIO;
31 }
32
33 return 0;
34}
35
36static int max77686_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
37{
38 if (dm_i2c_read(dev, reg, buff, len)) {
39 error("read error from device: %p register: %#x!", dev, reg);
40 return -EIO;
41 }
42
43 return 0;
44}
45
46static int max77686_bind(struct udevice *dev)
47{
48 int regulators_node;
49 const void *blob = gd->fdt_blob;
50 int childs;
51
52 regulators_node = fdt_subnode_offset(blob, dev->of_offset,
53 "voltage-regulators");
54 if (regulators_node <= 0) {
55 debug("%s: %s regulators subnode not found!", __func__,
56 dev->name);
57 return -ENXIO;
58 }
59
60 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
61
62 childs = pmic_bind_childs(dev, regulators_node, pmic_childs_info);
63 if (!childs)
64 debug("%s: %s - no child found\n", __func__, dev->name);
65
66 /* Always return success for this device */
67 return 0;
68}
69
70static struct dm_pmic_ops max77686_ops = {
71 .reg_count = MAX77686_NUM_OF_REGS,
72 .read = max77686_read,
73 .write = max77686_write,
74};
75
76static const struct udevice_id max77686_ids[] = {
77 { .compatible = "maxim,max77686" },
78 { }
79};
80
81U_BOOT_DRIVER(pmic_max77686) = {
82 .name = "max77686 pmic",
83 .id = UCLASS_PMIC,
84 .of_match = max77686_ids,
85 .bind = max77686_bind,
86 .ops = &max77686_ops,
87};