blob: ed27ffc0056768b509fb8416c2434e1b297ceeb3 [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
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020017static int fixed_regulator_ofdata_to_platdata(struct udevice *dev)
18{
Simon Glasscaa4daa2020-12-03 16:55:18 -070019 struct dm_regulator_uclass_plat *uc_pdata;
Sven Schwermer2f7a5f22019-06-24 13:03:33 +020020 struct regulator_common_platdata *dev_pdata;
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020021
22 dev_pdata = dev_get_platdata(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
Sven Schwermer2f7a5f22019-06-24 13:03:33 +020029 return regulator_common_ofdata_to_platdata(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{
Sven Schwermer2f7a5f22019-06-24 13:03:33 +020066 return regulator_common_get_enable(dev, dev_get_platdata(dev));
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020067}
68
69static int fixed_regulator_set_enable(struct udevice *dev, bool enable)
70{
Sven Schwermer2f7a5f22019-06-24 13:03:33 +020071 return regulator_common_set_enable(dev, dev_get_platdata(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,
91 .ofdata_to_platdata = fixed_regulator_ofdata_to_platdata,
Simon Glasscaa4daa2020-12-03 16:55:18 -070092 .plat_auto = sizeof(struct regulator_common_platdata),
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020093};