• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *  Copyright (C) 2015 Samsung Electronics
4  *
5  *  Przemyslaw Marczak <p.marczak@samsung.com>
6  */
7 
8 #include "regulator_common.h"
9 #include <common.h>
10 #include <errno.h>
11 #include <dm.h>
12 #include <power/pmic.h>
13 #include <power/regulator.h>
14 
fixed_regulator_ofdata_to_platdata(struct udevice * dev)15 static int fixed_regulator_ofdata_to_platdata(struct udevice *dev)
16 {
17 	struct dm_regulator_uclass_platdata *uc_pdata;
18 	struct regulator_common_platdata *dev_pdata;
19 
20 	dev_pdata = dev_get_platdata(dev);
21 	uc_pdata = dev_get_uclass_platdata(dev);
22 	if (!uc_pdata)
23 		return -ENXIO;
24 
25 	uc_pdata->type = REGULATOR_TYPE_FIXED;
26 
27 	return regulator_common_ofdata_to_platdata(dev, dev_pdata, "gpio");
28 }
29 
fixed_regulator_get_value(struct udevice * dev)30 static 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 
fixed_regulator_get_current(struct udevice * dev)46 static 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 
fixed_regulator_get_enable(struct udevice * dev)62 static int fixed_regulator_get_enable(struct udevice *dev)
63 {
64 	return regulator_common_get_enable(dev, dev_get_platdata(dev));
65 }
66 
fixed_regulator_set_enable(struct udevice * dev,bool enable)67 static int fixed_regulator_set_enable(struct udevice *dev, bool enable)
68 {
69 	return regulator_common_set_enable(dev, dev_get_platdata(dev), enable);
70 }
71 
72 static 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 
79 static const struct udevice_id fixed_regulator_ids[] = {
80 	{ .compatible = "regulator-fixed" },
81 	{ },
82 };
83 
84 U_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,
90 	.platdata_auto_alloc_size = sizeof(struct regulator_common_platdata),
91 };
92