blob: 8e3a8cf870bae55d7c9aae33d674763104ec886d [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +02002/*
3 * Copyright (C) 2014-2015 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
Przemyslaw Marczak52a3de52015-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>
12#include <power/pmic.h>
13#include <power/regulator.h>
14#include <power/max77686_pmic.h>
15
Przemyslaw Marczakf415a3e2015-05-13 13:38:26 +020016static const struct pmic_child_info pmic_children_info[] = {
Simon Glassb5ffa4f2015-07-02 18:16:02 -060017 { .prefix = "LDO", .driver = MAX77686_LDO_DRIVER },
18 { .prefix = "BUCK", .driver = MAX77686_BUCK_DRIVER },
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020019 { },
20};
21
Przemyslaw Marczakf415a3e2015-05-13 13:38:26 +020022static int max77686_reg_count(struct udevice *dev)
23{
24 return MAX77686_NUM_OF_REGS;
25}
26
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020027static int max77686_write(struct udevice *dev, uint reg, const uint8_t *buff,
28 int len)
29{
30 if (dm_i2c_write(dev, reg, buff, len)) {
Simon Glassc83c4362018-11-18 08:14:28 -070031 pr_err("write error to device: %p register: %#x!\n", dev, reg);
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020032 return -EIO;
33 }
34
35 return 0;
36}
37
38static int max77686_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
39{
40 if (dm_i2c_read(dev, reg, buff, len)) {
Simon Glassc83c4362018-11-18 08:14:28 -070041 pr_err("read error from device: %p register: %#x!\n", dev, reg);
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020042 return -EIO;
43 }
44
45 return 0;
46}
47
48static int max77686_bind(struct udevice *dev)
49{
Simon Glass7a869e62017-05-18 20:09:32 -060050 ofnode regulators_node;
Przemyslaw Marczakf415a3e2015-05-13 13:38:26 +020051 int children;
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020052
Simon Glass7a869e62017-05-18 20:09:32 -060053 regulators_node = dev_read_subnode(dev, "voltage-regulators");
54 if (!ofnode_valid(regulators_node)) {
Simon Glassc83c4362018-11-18 08:14:28 -070055 debug("%s: %s regulators subnode not found!\n", __func__,
56 dev->name);
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020057 return -ENXIO;
58 }
59
60 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
61
Przemyslaw Marczakf415a3e2015-05-13 13:38:26 +020062 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
63 if (!children)
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020064 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 = {
Przemyslaw Marczakf415a3e2015-05-13 13:38:26 +020071 .reg_count = max77686_reg_count,
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020072 .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) = {
Simon Glassb5ffa4f2015-07-02 18:16:02 -060082 .name = "max77686_pmic",
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020083 .id = UCLASS_PMIC,
84 .of_match = max77686_ids,
85 .bind = max77686_bind,
86 .ops = &max77686_ops,
87};