]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
regulator: max77802: Add .{get,set}_mode callbacks
authorJavier Martinez Canillas <javier.martinez@collabora.co.uk>
Thu, 16 Oct 2014 16:48:47 +0000 (18:48 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 20 Oct 2014 11:23:50 +0000 (12:23 +0100)
Some max77802 LDOs (1, 3, 20 and 21) support to be configured in Low
Power Mode during system normal operation. Add function handlers for
the .get_mode and .set_mode operations to set the mode on these LDOs.

Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/max77802.c

index 8425c0d520a8d47b263a24539acf54409d435fe8..6eabb954ec7c670eeaca3af0f39789fd1c150078 100644 (file)
@@ -70,6 +70,12 @@ struct max77802_regulator_prv {
        unsigned int opmode[MAX77802_REG_MAX];
 };
 
+static inline int max77802_map_mode(int mode)
+{
+       return mode == MAX77802_OPMODE_NORMAL ?
+               REGULATOR_MODE_NORMAL : REGULATOR_MODE_STANDBY;
+}
+
 static int max77802_get_opmode_shift(int id)
 {
        if (id == MAX77802_BUCK1 || (id >= MAX77802_BUCK5 &&
@@ -104,6 +110,44 @@ static int max77802_set_suspend_disable(struct regulator_dev *rdev)
                                  rdev->desc->enable_mask, val << shift);
 }
 
+/*
+ * Some LDOs support Low Power Mode while the system is running.
+ *
+ * LDOs 1, 3, 20, 21.
+ */
+static int max77802_set_mode(struct regulator_dev *rdev, unsigned int mode)
+{
+       struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
+       int id = rdev_get_id(rdev);
+       unsigned int val;
+       int shift = max77802_get_opmode_shift(id);
+
+       switch (mode) {
+       case REGULATOR_MODE_STANDBY:
+               val = MAX77802_OPMODE_LP;       /* ON in Low Power Mode */
+               break;
+       case REGULATOR_MODE_NORMAL:
+               val = MAX77802_OPMODE_NORMAL;   /* ON in Normal Mode */
+               break;
+       default:
+               dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n",
+                        rdev->desc->name, mode);
+               return -EINVAL;
+       }
+
+       max77802->opmode[id] = val;
+       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+                                 rdev->desc->enable_mask, val << shift);
+}
+
+static unsigned max77802_get_mode(struct regulator_dev *rdev)
+{
+       struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
+       int id = rdev_get_id(rdev);
+
+       return max77802_map_mode(max77802->opmode[id]);
+}
+
 /*
  * Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state
  * (Enable Control Logic1 by PWRREQ)
@@ -268,6 +312,8 @@ static struct regulator_ops max77802_ldo_ops_logic2 = {
        .get_voltage_sel        = regulator_get_voltage_sel_regmap,
        .set_voltage_sel        = regulator_set_voltage_sel_regmap,
        .set_voltage_time_sel   = regulator_set_voltage_time_sel,
+       .set_mode               = max77802_set_mode,
+       .get_mode               = max77802_get_mode,
        .set_suspend_mode       = max77802_ldo_set_suspend_mode_logic2,
 };