blob: f9f9659621c2cf06f05938e29f1ccbfe807cbc46 [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
Sven Schwermer25957522019-06-24 13:03:33 +02008#include "regulator_common.h"
Przemyslaw Marczak3753f282015-04-20 20:07:48 +02009#include <common.h>
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020010#include <errno.h>
11#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020013#include <power/pmic.h>
14#include <power/regulator.h>
15
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020016static int fixed_regulator_ofdata_to_platdata(struct udevice *dev)
17{
18 struct dm_regulator_uclass_platdata *uc_pdata;
Sven Schwermer25957522019-06-24 13:03:33 +020019 struct regulator_common_platdata *dev_pdata;
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020020
21 dev_pdata = dev_get_platdata(dev);
22 uc_pdata = dev_get_uclass_platdata(dev);
23 if (!uc_pdata)
24 return -ENXIO;
25
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020026 uc_pdata->type = REGULATOR_TYPE_FIXED;
27
Sven Schwermer25957522019-06-24 13:03:33 +020028 return regulator_common_ofdata_to_platdata(dev, dev_pdata, "gpio");
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020029}
30
31static int fixed_regulator_get_value(struct udevice *dev)
32{
33 struct dm_regulator_uclass_platdata *uc_pdata;
34
35 uc_pdata = dev_get_uclass_platdata(dev);
36 if (!uc_pdata)
37 return -ENXIO;
38
39 if (uc_pdata->min_uV != uc_pdata->max_uV) {
40 debug("Invalid constraints for: %s\n", uc_pdata->name);
41 return -EINVAL;
42 }
43
44 return uc_pdata->min_uV;
45}
46
47static int fixed_regulator_get_current(struct udevice *dev)
48{
49 struct dm_regulator_uclass_platdata *uc_pdata;
50
51 uc_pdata = dev_get_uclass_platdata(dev);
52 if (!uc_pdata)
53 return -ENXIO;
54
55 if (uc_pdata->min_uA != uc_pdata->max_uA) {
56 debug("Invalid constraints for: %s\n", uc_pdata->name);
57 return -EINVAL;
58 }
59
60 return uc_pdata->min_uA;
61}
62
Keerthy8690d6a2017-06-13 09:53:46 +053063static int fixed_regulator_get_enable(struct udevice *dev)
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020064{
Sven Schwermer25957522019-06-24 13:03:33 +020065 return regulator_common_get_enable(dev, dev_get_platdata(dev));
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020066}
67
68static int fixed_regulator_set_enable(struct udevice *dev, bool enable)
69{
Sven Schwermer25957522019-06-24 13:03:33 +020070 return regulator_common_set_enable(dev, dev_get_platdata(dev), enable);
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020071}
72
73static const struct dm_regulator_ops fixed_regulator_ops = {
74 .get_value = fixed_regulator_get_value,
75 .get_current = fixed_regulator_get_current,
76 .get_enable = fixed_regulator_get_enable,
77 .set_enable = fixed_regulator_set_enable,
78};
79
80static const struct udevice_id fixed_regulator_ids[] = {
81 { .compatible = "regulator-fixed" },
82 { },
83};
84
85U_BOOT_DRIVER(fixed_regulator) = {
86 .name = "fixed regulator",
87 .id = UCLASS_REGULATOR,
88 .ops = &fixed_regulator_ops,
89 .of_match = fixed_regulator_ids,
90 .ofdata_to_platdata = fixed_regulator_ofdata_to_platdata,
Sven Schwermer25957522019-06-24 13:03:33 +020091 .platdata_auto_alloc_size = sizeof(struct regulator_common_platdata),
Przemyslaw Marczak3753f282015-04-20 20:07:48 +020092};