blob: 7e6f7d1966f171a6fefa6578cab6433aa9cdd861 [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
Tom Rinid678a592024-05-18 20:20:43 -06007#include <common.h>
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +02008#include <fdtdec.h>
9#include <errno.h>
10#include <dm.h>
11#include <i2c.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060012#include <log.h>
Simon Glass1e94b462023-09-14 18:21:46 -060013#include <linux/printk.h>
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020014#include <power/pmic.h>
15#include <power/regulator.h>
16#include <power/max77686_pmic.h>
17
Przemyslaw Marczakf415a3e2015-05-13 13:38:26 +020018static const struct pmic_child_info pmic_children_info[] = {
Simon Glassb5ffa4f2015-07-02 18:16:02 -060019 { .prefix = "LDO", .driver = MAX77686_LDO_DRIVER },
20 { .prefix = "BUCK", .driver = MAX77686_BUCK_DRIVER },
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020021 { },
22};
23
Przemyslaw Marczakf415a3e2015-05-13 13:38:26 +020024static int max77686_reg_count(struct udevice *dev)
25{
26 return MAX77686_NUM_OF_REGS;
27}
28
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020029static int max77686_write(struct udevice *dev, uint reg, const uint8_t *buff,
30 int len)
31{
32 if (dm_i2c_write(dev, reg, buff, len)) {
Simon Glassc83c4362018-11-18 08:14:28 -070033 pr_err("write error to device: %p register: %#x!\n", dev, reg);
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020034 return -EIO;
35 }
36
37 return 0;
38}
39
40static int max77686_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
41{
42 if (dm_i2c_read(dev, reg, buff, len)) {
Simon Glassc83c4362018-11-18 08:14:28 -070043 pr_err("read error from device: %p register: %#x!\n", dev, reg);
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020044 return -EIO;
45 }
46
47 return 0;
48}
49
50static int max77686_bind(struct udevice *dev)
51{
Simon Glass7a869e62017-05-18 20:09:32 -060052 ofnode regulators_node;
Przemyslaw Marczakf415a3e2015-05-13 13:38:26 +020053 int children;
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020054
Simon Glass7a869e62017-05-18 20:09:32 -060055 regulators_node = dev_read_subnode(dev, "voltage-regulators");
56 if (!ofnode_valid(regulators_node)) {
Simon Glassc83c4362018-11-18 08:14:28 -070057 debug("%s: %s regulators subnode not found!\n", __func__,
58 dev->name);
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020059 return -ENXIO;
60 }
61
62 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
63
Przemyslaw Marczakf415a3e2015-05-13 13:38:26 +020064 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
65 if (!children)
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020066 debug("%s: %s - no child found\n", __func__, dev->name);
67
68 /* Always return success for this device */
69 return 0;
70}
71
72static struct dm_pmic_ops max77686_ops = {
Przemyslaw Marczakf415a3e2015-05-13 13:38:26 +020073 .reg_count = max77686_reg_count,
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020074 .read = max77686_read,
75 .write = max77686_write,
76};
77
78static const struct udevice_id max77686_ids[] = {
79 { .compatible = "maxim,max77686" },
80 { }
81};
82
83U_BOOT_DRIVER(pmic_max77686) = {
Simon Glassb5ffa4f2015-07-02 18:16:02 -060084 .name = "max77686_pmic",
Przemyslaw Marczak52a3de52015-04-20 20:07:46 +020085 .id = UCLASS_PMIC,
86 .of_match = max77686_ids,
87 .bind = max77686_bind,
88 .ops = &max77686_ops,
89};