regulator: core: Provide regmap based voltage_sel operations
Since the voltage selector operations are intended to directly map a
bitfield in the device register map into regulator API operations the
code for implementing them is usually very standard we can save some
code by providing standard implementations for devices using the regmap
API.
Drivers using regmap can pass their regmap in in the regmap_config
struct, set vsel_reg and vsel_mask in their regulator_desc and then
use regulator_{get,set}_voltage_sel_regmap in their ops. This saves
a small amount of code from each driver.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Liam Girdwood <lrg@ti.com>
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index 2e75373..d1c2389 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -164,6 +164,9 @@
* @irq: Interrupt number for the regulator.
* @type: Indicates if the regulator is a voltage or current regulator.
* @owner: Module providing the regulator, used for refcounting.
+
+ * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_
+ * @vsel_mask: Mask for register bitfield used for selector
*/
struct regulator_desc {
const char *name;
@@ -174,6 +177,9 @@
int irq;
enum regulator_type type;
struct module *owner;
+
+ unsigned int vsel_reg;
+ unsigned int vsel_mask;
};
/**
@@ -250,6 +256,9 @@
int regulator_mode_to_status(unsigned int);
+int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
+int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
+
void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
#endif