summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2019-11-06 08:11:50 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2019-11-06 11:22:36 +0100
commit3e7e76a81aef908f2e1c11e72e3bb8de8bee8f46 (patch)
tree66a12ff982bcd96de73e4c3dbfdf2500fd72a429 /include
parente0e52b83307ec037912c5c9e762ce6e1ea3b1740 (diff)
downloadbarebox-3e7e76a81aef908f2e1c11e72e3bb8de8bee8f46.tar.gz
barebox-3e7e76a81aef908f2e1c11e72e3bb8de8bee8f46.tar.xz
regulator: import linear voltage range helpers
The incoming stpmic1 regulator driver makes use of these helpers internally. Thus port them out of Linux v5.3. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r--include/regulator.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/include/regulator.h b/include/regulator.h
index 28ae25652a..156acb82f8 100644
--- a/include/regulator.h
+++ b/include/regulator.h
@@ -32,6 +32,7 @@ struct regulator;
* @enable_is_inverted: A flag to indicate set enable_mask bits to disable
* when using regulator_enable_regmap and friends APIs.
*/
+
struct regulator_desc {
unsigned n_voltages;
const struct regulator_ops *ops;
@@ -49,6 +50,9 @@ struct regulator_desc {
unsigned int enable_val;
unsigned int disable_val;
bool enable_is_inverted;
+
+ const struct regulator_linear_range *linear_ranges;
+ int n_linear_ranges;
};
struct regulator_dev {
@@ -65,8 +69,36 @@ struct regulator_ops {
int (*list_voltage) (struct regulator_dev *, unsigned int);
int (*set_voltage_sel) (struct regulator_dev *, unsigned int);
+ int (*map_voltage)(struct regulator_dev *, int min_uV, int max_uV);
+};
+
+/*
+ * struct regulator_linear_range - specify linear voltage ranges
+ *
+ * Specify a range of voltages for regulator_map_linear_range() and
+ * regulator_list_linear_range().
+ *
+ * @min_uV: Lowest voltage in range
+ * @min_sel: Lowest selector for range
+ * @max_sel: Highest selector for range
+ * @uV_step: Step size
+ */
+struct regulator_linear_range {
+ unsigned int min_uV;
+ unsigned int min_sel;
+ unsigned int max_sel;
+ unsigned int uV_step;
};
+/* Initialize struct regulator_linear_range */
+#define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) \
+{ \
+ .min_uV = _min_uV, \
+ .min_sel = _min_sel, \
+ .max_sel = _max_sel, \
+ .uV_step = _step_uV, \
+}
+
#ifdef CONFIG_OFDEVICE
int of_regulator_register(struct regulator_dev *rd, struct device_node *node);
#else
@@ -93,8 +125,22 @@ int regulator_set_voltage_sel_regmap(struct regulator_dev *, unsigned);
int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
int regulator_map_voltage_linear(struct regulator_dev *rdev,
int min_uV, int max_uV);
+int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
+ int min_uV, int max_uV);
int regulator_list_voltage_linear(struct regulator_dev *rdev,
unsigned int selector);
+int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
+ unsigned int selector);
+int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
+int regulator_map_voltage_iterate(struct regulator_dev *rdev,
+ int min_uV, int max_uV);
+
+/*
+ * Helper functions intended to be used by regulator drivers prior registering
+ * their regulators.
+ */
+int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc,
+ unsigned int selector);
#else
static inline struct regulator *regulator_get(struct device_d *dev, const char *id)