aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2012-04-15 06:23:30 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-04-16 14:52:03 -0400
commit4ab5b3d92c863e55fa28cc41a7b005b7ae87afee (patch)
treeb4a57df2df36e334fbdab58e3e6b626a996312c5
parent65b19ce6c223287ac95bbc22b12ef5a2738472d1 (diff)
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>
-rw-r--r--drivers/regulator/core.c44
-rw-r--r--include/linux/regulator/driver.h9
2 files changed, 53 insertions, 0 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index bca1e5989243..02d2e15b2262 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1838,6 +1838,50 @@ int regulator_is_supported_voltage(struct regulator *regulator,
1838} 1838}
1839EXPORT_SYMBOL_GPL(regulator_is_supported_voltage); 1839EXPORT_SYMBOL_GPL(regulator_is_supported_voltage);
1840 1840
1841/**
1842 * regulator_get_voltage_sel_regmap - standard get_voltage_sel for regmap users
1843 *
1844 * @rdev: regulator to operate on
1845 *
1846 * Regulators that use regmap for their register I/O can set the
1847 * vsel_reg and vsel_mask fields in their descriptor and then use this
1848 * as their get_voltage_vsel operation, saving some code.
1849 */
1850int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev)
1851{
1852 unsigned int val;
1853 int ret;
1854
1855 ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
1856 if (ret != 0)
1857 return ret;
1858
1859 val &= rdev->desc->vsel_mask;
1860 val >>= ffs(rdev->desc->vsel_mask) - 1;
1861
1862 return val;
1863}
1864EXPORT_SYMBOL_GPL(regulator_get_voltage_sel_regmap);
1865
1866/**
1867 * regulator_set_voltage_sel_regmap - standard set_voltage_sel for regmap users
1868 *
1869 * @rdev: regulator to operate on
1870 * @sel: Selector to set
1871 *
1872 * Regulators that use regmap for their register I/O can set the
1873 * vsel_reg and vsel_mask fields in their descriptor and then use this
1874 * as their set_voltage_vsel operation, saving some code.
1875 */
1876int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel)
1877{
1878 sel <<= ffs(rdev->desc->vsel_mask) - 1;
1879
1880 return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
1881 rdev->desc->vsel_mask, sel);
1882}
1883EXPORT_SYMBOL_GPL(regulator_set_voltage_sel_regmap);
1884
1841static int _regulator_do_set_voltage(struct regulator_dev *rdev, 1885static int _regulator_do_set_voltage(struct regulator_dev *rdev,
1842 int min_uV, int max_uV) 1886 int min_uV, int max_uV)
1843{ 1887{
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index 2e753731217b..d1c238970a6e 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -164,6 +164,9 @@ enum regulator_type {
164 * @irq: Interrupt number for the regulator. 164 * @irq: Interrupt number for the regulator.
165 * @type: Indicates if the regulator is a voltage or current regulator. 165 * @type: Indicates if the regulator is a voltage or current regulator.
166 * @owner: Module providing the regulator, used for refcounting. 166 * @owner: Module providing the regulator, used for refcounting.
167
168 * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_
169 * @vsel_mask: Mask for register bitfield used for selector
167 */ 170 */
168struct regulator_desc { 171struct regulator_desc {
169 const char *name; 172 const char *name;
@@ -174,6 +177,9 @@ struct regulator_desc {
174 int irq; 177 int irq;
175 enum regulator_type type; 178 enum regulator_type type;
176 struct module *owner; 179 struct module *owner;
180
181 unsigned int vsel_reg;
182 unsigned int vsel_mask;
177}; 183};
178 184
179/** 185/**
@@ -250,6 +256,9 @@ int rdev_get_id(struct regulator_dev *rdev);
250 256
251int regulator_mode_to_status(unsigned int); 257int regulator_mode_to_status(unsigned int);
252 258
259int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
260int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
261
253void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); 262void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
254 263
255#endif 264#endif