blob: 2fa6c7e6b290fabff05cd0b234adc0e3ade00e63 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Przemyslaw Marczak3753f282015-04-20 20:07:48 +02002/*
3 * Copyright (C) 2015 Samsung Electronics
4 *
5 * Przemyslaw Marczak <p.marczak@samsung.com>
Przemyslaw Marczak3753f282015-04-20 20:07:48 +02006 */
7
8#include <common.h>
Przemyslaw Marczak3753f282015-04-20 20:07:48 +02009#include <errno.h>
10#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020012#include <power/pmic.h>
13#include <power/regulator.h>
14
Simon Glass1c1ddf62020-07-19 10:15:44 -060015#include "regulator_common.h"
16
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020017static int fixed_regulator_ofdata_to_platdata(struct udevice *dev)
18{
19 struct dm_regulator_uclass_platdata *uc_pdata;
Sven Schwermer25957522019-06-24 13:03:33 +020020 struct regulator_common_platdata *dev_pdata;
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020021
22 dev_pdata = dev_get_platdata(dev);
23 uc_pdata = dev_get_uclass_platdata(dev);
24 if (!uc_pdata)
25 return -ENXIO;
26
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020027 uc_pdata->type = REGULATOR_TYPE_FIXED;
28
Sven Schwermer25957522019-06-24 13:03:33 +020029 return regulator_common_ofdata_to_platdata(dev, dev_pdata, "gpio");
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020030}
31
32static int fixed_regulator_get_value(struct udevice *dev)
33{
34 struct dm_regulator_uclass_platdata *uc_pdata;
35
36 uc_pdata = dev_get_uclass_platdata(dev);
37 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{
50 struct dm_regulator_uclass_platdata *uc_pdata;
51
52 uc_pdata = dev_get_uclass_platdata(dev);
53 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
Keerthy8690d6a2017-06-13 09:53:46 +053064static int fixed_regulator_get_enable(struct udevice *dev)
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020065{
Sven Schwermer25957522019-06-24 13:03:33 +020066 return regulator_common_get_enable(dev, dev_get_platdata(dev));
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020067}
68
69static int fixed_regulator_set_enable(struct udevice *dev, bool enable)
70{
Sven Schwermer25957522019-06-24 13:03:33 +020071 return regulator_common_set_enable(dev, dev_get_platdata(dev), enable);
Przemyslaw Marczak3753f282015-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 Lozano2901ac62020-06-25 01:10:04 -030086U_BOOT_DRIVER(regulator_fixed) = {
87 .name = "regulator_fixed",
Przemyslaw Marczak3753f282015-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,
Sven Schwermer25957522019-06-24 13:03:33 +020092 .platdata_auto_alloc_size = sizeof(struct regulator_common_platdata),
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020093};