blob: 763e671d54e936114b1732ee07e8cfc7cf4c909a [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
Sven Schwermer2f7a5f22019-06-24 13:03:33 +02008#include "regulator_common.h"
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +02009#include <common.h>
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020010#include <errno.h>
11#include <dm.h>
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020012#include <power/pmic.h>
13#include <power/regulator.h>
14
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020015static int fixed_regulator_ofdata_to_platdata(struct udevice *dev)
16{
17 struct dm_regulator_uclass_platdata *uc_pdata;
Sven Schwermer2f7a5f22019-06-24 13:03:33 +020018 struct regulator_common_platdata *dev_pdata;
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020019
20 dev_pdata = dev_get_platdata(dev);
21 uc_pdata = dev_get_uclass_platdata(dev);
22 if (!uc_pdata)
23 return -ENXIO;
24
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020025 uc_pdata->type = REGULATOR_TYPE_FIXED;
26
Sven Schwermer2f7a5f22019-06-24 13:03:33 +020027 return regulator_common_ofdata_to_platdata(dev, dev_pdata, "gpio");
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020028}
29
30static int fixed_regulator_get_value(struct udevice *dev)
31{
32 struct dm_regulator_uclass_platdata *uc_pdata;
33
34 uc_pdata = dev_get_uclass_platdata(dev);
35 if (!uc_pdata)
36 return -ENXIO;
37
38 if (uc_pdata->min_uV != uc_pdata->max_uV) {
39 debug("Invalid constraints for: %s\n", uc_pdata->name);
40 return -EINVAL;
41 }
42
43 return uc_pdata->min_uV;
44}
45
46static int fixed_regulator_get_current(struct udevice *dev)
47{
48 struct dm_regulator_uclass_platdata *uc_pdata;
49
50 uc_pdata = dev_get_uclass_platdata(dev);
51 if (!uc_pdata)
52 return -ENXIO;
53
54 if (uc_pdata->min_uA != uc_pdata->max_uA) {
55 debug("Invalid constraints for: %s\n", uc_pdata->name);
56 return -EINVAL;
57 }
58
59 return uc_pdata->min_uA;
60}
61
Keerthy0f2194d2017-06-13 09:53:46 +053062static int fixed_regulator_get_enable(struct udevice *dev)
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020063{
Sven Schwermer2f7a5f22019-06-24 13:03:33 +020064 return regulator_common_get_enable(dev, dev_get_platdata(dev));
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020065}
66
67static int fixed_regulator_set_enable(struct udevice *dev, bool enable)
68{
Sven Schwermer2f7a5f22019-06-24 13:03:33 +020069 return regulator_common_set_enable(dev, dev_get_platdata(dev), enable);
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020070}
71
72static const struct dm_regulator_ops fixed_regulator_ops = {
73 .get_value = fixed_regulator_get_value,
74 .get_current = fixed_regulator_get_current,
75 .get_enable = fixed_regulator_get_enable,
76 .set_enable = fixed_regulator_set_enable,
77};
78
79static const struct udevice_id fixed_regulator_ids[] = {
80 { .compatible = "regulator-fixed" },
81 { },
82};
83
84U_BOOT_DRIVER(fixed_regulator) = {
85 .name = "fixed regulator",
86 .id = UCLASS_REGULATOR,
87 .ops = &fixed_regulator_ops,
88 .of_match = fixed_regulator_ids,
89 .ofdata_to_platdata = fixed_regulator_ofdata_to_platdata,
Sven Schwermer2f7a5f22019-06-24 13:03:33 +020090 .platdata_auto_alloc_size = sizeof(struct regulator_common_platdata),
Przemyslaw Marczak9923a8b2015-04-20 20:07:48 +020091};