Message ID | 1413390039-19364-3-git-send-email-javier.martinez@collabora.co.uk (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Wed, Oct 15, 2014 at 06:20:32PM +0200, Javier Martinez Canillas wrote: > +#define MAX77802_MODE(pval) ((pval == MAX77802_OPMODE_NORMAL) ? \ > + REGULATOR_MODE_NORMAL : REGULATOR_MODE_STANDBY) > + Make this a static inline function if there's any need for it, this is both more legible and more helpful for the compiler. > + switch (mode) { > + case REGULATOR_MODE_IDLE: > + case REGULATOR_MODE_STANDBY: > + val = MAX77802_OPMODE_LP; /* ON in Low Power Mode */ > + break; You should never have multiple modes mapping onto a singel value - if the user sets a mode they should find that the device has that mode.
Hello Mark, Thanks a lot for your feedback. On 10/16/2014 10:36 AM, Mark Brown wrote: > On Wed, Oct 15, 2014 at 06:20:32PM +0200, Javier Martinez Canillas wrote: > >> +#define MAX77802_MODE(pval) ((pval == MAX77802_OPMODE_NORMAL) ? \ >> + REGULATOR_MODE_NORMAL : REGULATOR_MODE_STANDBY) >> + > > Make this a static inline function if there's any need for it, this is > both more legible and more helpful for the compiler. > Ok, will change that. >> + switch (mode) { >> + case REGULATOR_MODE_IDLE: >> + case REGULATOR_MODE_STANDBY: >> + val = MAX77802_OPMODE_LP; /* ON in Low Power Mode */ >> + break; > > You should never have multiple modes mapping onto a singel value - if > the user sets a mode they should find that the device has that mode. > I see, thanks for the clarification. I think STANDBY better maps the device Low Power Mode according the description in include/linux/regulator/consumer.h so I'll just make IDLE invalid in v2. Best regards, Javier -- To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/regulator/max77802.c b/drivers/regulator/max77802.c index 26f6963..baf834d 100644 --- a/drivers/regulator/max77802.c +++ b/drivers/regulator/max77802.c @@ -51,6 +51,9 @@ #define MAX77802_OFF_PWRREQ 0x1 +#define MAX77802_MODE(pval) ((pval == MAX77802_OPMODE_NORMAL) ? \ + REGULATOR_MODE_NORMAL : REGULATOR_MODE_STANDBY) + /* MAX77802 has two register formats: 2-bit and 4-bit */ static const unsigned int ramp_table_77802_2bit[] = { 12500, @@ -105,6 +108,45 @@ static int max77802_set_suspend_disable(struct regulator_dev *rdev) } /* + * 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_IDLE: + 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_MODE(max77802->opmode[id]); +} + +/* * Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state * (Enable Control Logic1 by PWRREQ) * @@ -268,6 +310,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, };
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> --- drivers/regulator/max77802.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)