blob: d3e0fb672d96e8959eee57896facd2736e21e954 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +02002/*
3 * Copyright (C) 2015 Samsung Electronics
4 *
5 * Przemyslaw Marczak <p.marczak@samsung.com>
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +02006 */
7
8#include <common.h>
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +02009#include <errno.h>
10#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020012#include <power/pmic.h>
13#include <power/regulator.h>
14
Simon Glassad2f4ac2020-07-19 10:15:44 -060015#include "regulator_common.h"
16
Simon Glassd1998a92020-12-03 16:55:21 -070017static int fixed_regulator_of_to_plat(struct udevice *dev)
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020018{
Simon Glasscaa4daa2020-12-03 16:55:18 -070019 struct dm_regulator_uclass_plat *uc_pdata;
Simon Glass8a8d24b2020-12-03 16:55:23 -070020 struct regulator_common_plat *dev_pdata;
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020021
Simon Glassc69cda22020-12-03 16:55:20 -070022 dev_pdata = dev_get_plat(dev);
Simon Glasscaa4daa2020-12-03 16:55:18 -070023 uc_pdata = dev_get_uclass_plat(dev);
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020024 if (!uc_pdata)
25 return -ENXIO;
26
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020027 uc_pdata->type = REGULATOR_TYPE_FIXED;
28
Simon Glassd1998a92020-12-03 16:55:21 -070029 return regulator_common_of_to_plat(dev, dev_pdata, "gpio");
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020030}
31
32static int fixed_regulator_get_value(struct udevice *dev)
33{
Simon Glasscaa4daa2020-12-03 16:55:18 -070034 struct dm_regulator_uclass_plat *uc_pdata;
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020035
Simon Glasscaa4daa2020-12-03 16:55:18 -070036 uc_pdata = dev_get_uclass_plat(dev);
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020037 if (!uc_pdata)
38 return -ENXIO;
39
40 if (uc_pdata->min_uV != uc_pdata->max_uV) {
41 debug("Invalid constraints for: %s\n", uc_pdata->name);
42 return -EINVAL;
43 }
44
45 return uc_pdata->min_uV;
46}
47
48static int fixed_regulator_get_current(struct udevice *dev)
49{
Simon Glasscaa4daa2020-12-03 16:55:18 -070050 struct dm_regulator_uclass_plat *uc_pdata;
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020051
Simon Glasscaa4daa2020-12-03 16:55:18 -070052 uc_pdata = dev_get_uclass_plat(dev);
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020053 if (!uc_pdata)
54 return -ENXIO;
55
56 if (uc_pdata->min_uA != uc_pdata->max_uA) {
57 debug("Invalid constraints for: %s\n", uc_pdata->name);
58 return -EINVAL;
59 }
60
61 return uc_pdata->min_uA;
62}
63
Keerthy0f2194d2017-06-13 09:53:46 +053064static int fixed_regulator_get_enable(struct udevice *dev)
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020065{
Simon Glassc69cda22020-12-03 16:55:20 -070066 return regulator_common_get_enable(dev, dev_get_plat(dev));
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020067}
68
69static int fixed_regulator_set_enable(struct udevice *dev, bool enable)
70{
Simon Glassc69cda22020-12-03 16:55:20 -070071 return regulator_common_set_enable(dev, dev_get_plat(dev), enable);
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020072}
73
74static const struct dm_regulator_ops fixed_regulator_ops = {
75 .get_value = fixed_regulator_get_value,
76 .get_current = fixed_regulator_get_current,
77 .get_enable = fixed_regulator_get_enable,
78 .set_enable = fixed_regulator_set_enable,
79};
80
81static const struct udevice_id fixed_regulator_ids[] = {
82 { .compatible = "regulator-fixed" },
83 { },
84};
85
Walter Lozanoe3e24702020-06-25 01:10:04 -030086U_BOOT_DRIVER(regulator_fixed) = {
87 .name = "regulator_fixed",
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020088 .id = UCLASS_REGULATOR,
89 .ops = &fixed_regulator_ops,
90 .of_match = fixed_regulator_ids,
Simon Glassd1998a92020-12-03 16:55:21 -070091 .of_to_plat = fixed_regulator_of_to_plat,
Simon Glass8a8d24b2020-12-03 16:55:23 -070092 .plat_auto = sizeof(struct regulator_common_plat),
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020093};