* Add support for regulator operation mode of mt6397
@ 2016-05-11 9:31 Henry Chen
2016-05-11 9:31 ` [PATCH RESEND 1/2] regulator: Add support for parsing operation mode Henry Chen
2016-05-11 9:31 ` [PATCH RESEND 2/2] regulator: mt6397: Add buck change mode regulator interface for mt6397 Henry Chen
0 siblings, 2 replies; 4+ messages in thread
From: Henry Chen @ 2016-05-11 9:31 UTC (permalink / raw)
To: linux-arm-kernel
Some regulators support different operating modes, but there is no suitable
property that can pass the opeation mode constraints on runtime at present.
This series making the change to specify supported modes as a devicetree list.
Consumers can change or get the regulator operation mode by regulator_set_mode
/regulator_get_mode and define the support operating mode on devicetree.
There is a requirement from SVS driver. SVS calibartion requires that the
regulator be in its low-noise (pwm mode) state at boot, but at all other times
it can be normal mode for power saving
http://www.spinics.net/lists/devicetree/msg111204.html
Henry Chen (2):
regulator: Add support for parsing operation mode
regulator: mt6397: Add buck change mode regulator interface for mt6397
.../bindings/regulator/mt6397-regulator.txt | 22 +++++
.../devicetree/bindings/regulator/regulator.txt | 10 +++
drivers/regulator/mt6397-regulator.c | 95 +++++++++++++++++++---
drivers/regulator/of_regulator.c | 14 ++++
4 files changed, 129 insertions(+), 12 deletions(-)
--
1.8.1.1.dirty
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH RESEND 1/2] regulator: Add support for parsing operation mode
2016-05-11 9:31 Add support for regulator operation mode of mt6397 Henry Chen
@ 2016-05-11 9:31 ` Henry Chen
2016-05-11 9:31 ` [PATCH RESEND 2/2] regulator: mt6397: Add buck change mode regulator interface for mt6397 Henry Chen
1 sibling, 0 replies; 4+ messages in thread
From: Henry Chen @ 2016-05-11 9:31 UTC (permalink / raw)
To: linux-arm-kernel
Some regulators support their operating mode to be changed by
consumers for module specific purpose.
This patch adds support to parse those properties and fill the
regulator constraints so the regulator core can call the
regualtor_set_mode to change the modes.
Signed-off-by: Henry Chen <henryc.chen@mediatek.com>
---
Documentation/devicetree/bindings/regulator/regulator.txt | 10 ++++++++++
drivers/regulator/of_regulator.c | 14 ++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt
index ecfc593..88f98f0 100644
--- a/Documentation/devicetree/bindings/regulator/regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/regulator.txt
@@ -49,6 +49,16 @@ Optional properties:
0: Disable active discharge.
1: Enable active discharge.
Absence of this property will leave configuration to default.
+- regulator-allow-change-mode: allow the regulator mode to be configured
+- regulator-supported-modes: Regulators can run in a variety of different operating
+ modes depending on output load. This allows further system power savings by
+ selecting the best (and most efficient) regulator mode for a desired load.
+ The definition for each of these operation is defined at
+ include/linux/regulator/consumer.h
+ 0: FAST.
+ 1: NORMAL.
+ 2: IDLE.
+ 3: STANDBY.
Deprecated properties:
- regulator-compatible: If a regulator chip contains multiple
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 6b0aa80..12fe8c8 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -167,6 +167,20 @@ static void of_get_regulation_constraints(struct device_node *np,
suspend_state = NULL;
suspend_np = NULL;
}
+
+ if (of_property_read_bool(np, "regulator-allow-change-mode"))
+ constraints->valid_ops_mask |= REGULATOR_CHANGE_MODE;
+
+ ret = of_property_count_elems_of_size(np,
+ "regulator-supported-modes",
+ sizeof(u32));
+ for (i = 0; i < ret; i++) {
+ u32 mode;
+
+ of_property_read_u32_index(np, "regulator-supported-modes",
+ i, &mode);
+ constraints->valid_modes_mask |= (1 << mode);
+ }
}
/**
--
1.8.1.1.dirty
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH RESEND 2/2] regulator: mt6397: Add buck change mode regulator interface for mt6397
2016-05-11 9:31 Add support for regulator operation mode of mt6397 Henry Chen
2016-05-11 9:31 ` [PATCH RESEND 1/2] regulator: Add support for parsing operation mode Henry Chen
@ 2016-05-11 9:31 ` Henry Chen
[not found] ` <20160511145046.GI6261@sirena.org.uk>
1 sibling, 1 reply; 4+ messages in thread
From: Henry Chen @ 2016-05-11 9:31 UTC (permalink / raw)
To: linux-arm-kernel
BUCKs of mt6397 have auto mode and pwm mode.
User can use regulator interfaces to control modes.
Signed-off-by: Henry Chen <henryc.chen@mediatek.com>
---
.../bindings/regulator/mt6397-regulator.txt | 22 +++++
drivers/regulator/mt6397-regulator.c | 95 +++++++++++++++++++---
2 files changed, 105 insertions(+), 12 deletions(-)
diff --git a/Documentation/devicetree/bindings/regulator/mt6397-regulator.txt b/Documentation/devicetree/bindings/regulator/mt6397-regulator.txt
index a42b1d6..d3167f2 100644
--- a/Documentation/devicetree/bindings/regulator/mt6397-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/mt6397-regulator.txt
@@ -7,6 +7,26 @@ Required properties:
The definition for each of these nodes is defined using the standard binding
for regulators at Documentation/devicetree/bindings/regulator/regulator.txt.
+The mt6397 buck supports two different operating modes: Fast and Normal
+Mode. Some regulators support the modes to be changed by the consumers during
+normal operation.
+
+The regulators that support the standard "regulator-allow-change-mode" property,
+changing their mode during normal operation are:
+ buck_vpca15, buck_vpca7, buck_vsramca15, buck_vsramca7, buck_vcore, buck_vgpu,
+ buck_vdrm, buck_vio18
+
+The possible values for "regulator-supported-modes" are:
+ 0: PWM mode, mapping to regulator fast mode, allow the
+ converter to remain in the PWM mode regardless of the load current, so
+ that the noise spectrum of the converter can be minimized for certain
+ highly-noise-sensitive handset applications.
+ 1: Auto mode, mapping to regulator normal mode, mode switch by current
+ loading. At light load currents, the converter automatically enters
+ PFM mode to save power and improve light load efficiency. At heavy
+ load currents, the converter automatically enters PWM mode to minimiz
+ the noise spectrum of the converter.
+
The valid names for regulators are::
BUCK:
buck_vpca15, buck_vpca7, buck_vsramca15, buck_vsramca7, buck_vcore, buck_vgpu,
@@ -30,6 +50,8 @@ Example:
regulator-max-microvolt = <1350000>;
regulator-ramp-delay = <12500>;
regulator-enable-ramp-delay = <200>;
+ regulator-allow-change-mode;
+ regulator-supported-modes = <0 1>;
};
mt6397_vpca7_reg: buck_vpca7 {
diff --git a/drivers/regulator/mt6397-regulator.c b/drivers/regulator/mt6397-regulator.c
index 17a5b6c..c6c6aa85 100644
--- a/drivers/regulator/mt6397-regulator.c
+++ b/drivers/regulator/mt6397-regulator.c
@@ -23,6 +23,9 @@
#include <linux/regulator/mt6397-regulator.h>
#include <linux/regulator/of_regulator.h>
+#define MT6397_BUCK_MODE_AUTO 0
+#define MT6397_BUCK_MODE_FORCE_PWM 1
+
/*
* MT6397 regulators' information
*
@@ -38,10 +41,14 @@ struct mt6397_regulator_info {
u32 vselon_reg;
u32 vselctrl_reg;
u32 vselctrl_mask;
+ u32 modeset_reg;
+ u32 modeset_mask;
+ u32 modeset_shift;
};
#define MT6397_BUCK(match, vreg, min, max, step, volt_ranges, enreg, \
- vosel, vosel_mask, voselon, vosel_ctrl) \
+ vosel, vosel_mask, voselon, vosel_ctrl, _modeset_reg, \
+ _modeset_shift) \
[MT6397_ID_##vreg] = { \
.desc = { \
.name = #vreg, \
@@ -62,6 +69,9 @@ struct mt6397_regulator_info {
.vselon_reg = voselon, \
.vselctrl_reg = vosel_ctrl, \
.vselctrl_mask = BIT(1), \
+ .modeset_reg = _modeset_reg, \
+ .modeset_mask = BIT(_modeset_shift), \
+ .modeset_shift = _modeset_shift \
}
#define MT6397_LDO(match, vreg, ldo_volt_table, enreg, enbit, vosel, \
@@ -145,6 +155,63 @@ static const u32 ldo_volt_table7[] = {
1300000, 1500000, 1800000, 2000000, 2500000, 2800000, 3000000, 3300000,
};
+static int mt6397_regulator_set_mode(struct regulator_dev *rdev,
+ unsigned int mode)
+{
+ struct mt6397_regulator_info *info = rdev_get_drvdata(rdev);
+ int ret, val;
+
+ switch (mode) {
+ case REGULATOR_MODE_FAST:
+ val = MT6397_BUCK_MODE_FORCE_PWM;
+ break;
+ case REGULATOR_MODE_NORMAL:
+ val = MT6397_BUCK_MODE_AUTO;
+ break;
+ default:
+ ret = -EINVAL;
+ goto err_mode;
+ }
+
+ dev_dbg(&rdev->dev, "mt6397 buck set_mode %#x, %#x, %#x, %#x\n",
+ info->modeset_reg, info->modeset_mask,
+ info->modeset_shift, val);
+
+ val <<= info->modeset_shift;
+ ret = regmap_update_bits(rdev->regmap, info->modeset_reg,
+ info->modeset_mask, val);
+err_mode:
+ if (ret != 0) {
+ dev_err(&rdev->dev,
+ "Failed to set mt6397 buck mode: %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static unsigned int mt6397_regulator_get_mode(struct regulator_dev *rdev)
+{
+ struct mt6397_regulator_info *info = rdev_get_drvdata(rdev);
+ int ret, regval;
+
+ ret = regmap_read(rdev->regmap, info->modeset_reg, ®val);
+ if (ret != 0) {
+ dev_err(&rdev->dev,
+ "Failed to get mt6397 buck mode: %d\n", ret);
+ return ret;
+ }
+
+ switch ((regval & info->modeset_mask) >> info->modeset_shift) {
+ case MT6397_BUCK_MODE_AUTO:
+ return REGULATOR_MODE_NORMAL;
+ case MT6397_BUCK_MODE_FORCE_PWM:
+ return REGULATOR_MODE_FAST;
+ default:
+ return -EINVAL;
+ }
+}
+
static int mt6397_get_status(struct regulator_dev *rdev)
{
int ret;
@@ -160,7 +227,7 @@ static int mt6397_get_status(struct regulator_dev *rdev)
return (regval & info->qi) ? REGULATOR_STATUS_ON : REGULATOR_STATUS_OFF;
}
-static struct regulator_ops mt6397_volt_range_ops = {
+static const struct regulator_ops mt6397_volt_range_ops = {
.list_voltage = regulator_list_voltage_linear_range,
.map_voltage = regulator_map_voltage_linear_range,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
@@ -170,9 +237,11 @@ static struct regulator_ops mt6397_volt_range_ops = {
.disable = regulator_disable_regmap,
.is_enabled = regulator_is_enabled_regmap,
.get_status = mt6397_get_status,
+ .set_mode = mt6397_regulator_set_mode,
+ .get_mode = mt6397_regulator_get_mode,
};
-static struct regulator_ops mt6397_volt_table_ops = {
+static const struct regulator_ops mt6397_volt_table_ops = {
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_iterate,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
@@ -184,7 +253,7 @@ static struct regulator_ops mt6397_volt_table_ops = {
.get_status = mt6397_get_status,
};
-static struct regulator_ops mt6397_volt_fixed_ops = {
+static const struct regulator_ops mt6397_volt_fixed_ops = {
.list_voltage = regulator_list_voltage_linear,
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
@@ -196,28 +265,30 @@ static struct regulator_ops mt6397_volt_fixed_ops = {
static struct mt6397_regulator_info mt6397_regulators[] = {
MT6397_BUCK("buck_vpca15", VPCA15, 700000, 1493750, 6250,
buck_volt_range1, MT6397_VCA15_CON7, MT6397_VCA15_CON9, 0x7f,
- MT6397_VCA15_CON10, MT6397_VCA15_CON5),
+ MT6397_VCA15_CON10, MT6397_VCA15_CON5, MT6397_VCA15_CON2, 11),
MT6397_BUCK("buck_vpca7", VPCA7, 700000, 1493750, 6250,
buck_volt_range1, MT6397_VPCA7_CON7, MT6397_VPCA7_CON9, 0x7f,
- MT6397_VPCA7_CON10, MT6397_VPCA7_CON5),
+ MT6397_VPCA7_CON10, MT6397_VPCA7_CON5, MT6397_VPCA7_CON2, 8),
MT6397_BUCK("buck_vsramca15", VSRAMCA15, 700000, 1493750, 6250,
buck_volt_range1, MT6397_VSRMCA15_CON7, MT6397_VSRMCA15_CON9,
- 0x7f, MT6397_VSRMCA15_CON10, MT6397_VSRMCA15_CON5),
+ 0x7f, MT6397_VSRMCA15_CON10, MT6397_VSRMCA15_CON5,
+ MT6397_VSRMCA15_CON2, 8),
MT6397_BUCK("buck_vsramca7", VSRAMCA7, 700000, 1493750, 6250,
buck_volt_range1, MT6397_VSRMCA7_CON7, MT6397_VSRMCA7_CON9,
- 0x7f, MT6397_VSRMCA7_CON10, MT6397_VSRMCA7_CON5),
+ 0x7f, MT6397_VSRMCA7_CON10, MT6397_VSRMCA7_CON5,
+ MT6397_VSRMCA7_CON2, 8),
MT6397_BUCK("buck_vcore", VCORE, 700000, 1493750, 6250,
buck_volt_range1, MT6397_VCORE_CON7, MT6397_VCORE_CON9, 0x7f,
- MT6397_VCORE_CON10, MT6397_VCORE_CON5),
+ MT6397_VCORE_CON10, MT6397_VCORE_CON5, MT6397_VCORE_CON2, 8),
MT6397_BUCK("buck_vgpu", VGPU, 700000, 1493750, 6250, buck_volt_range1,
MT6397_VGPU_CON7, MT6397_VGPU_CON9, 0x7f,
- MT6397_VGPU_CON10, MT6397_VGPU_CON5),
+ MT6397_VGPU_CON10, MT6397_VGPU_CON5, MT6397_VGPU_CON2, 8),
MT6397_BUCK("buck_vdrm", VDRM, 800000, 1593750, 6250, buck_volt_range2,
MT6397_VDRM_CON7, MT6397_VDRM_CON9, 0x7f,
- MT6397_VDRM_CON10, MT6397_VDRM_CON5),
+ MT6397_VDRM_CON10, MT6397_VDRM_CON5, MT6397_VDRM_CON2, 8),
MT6397_BUCK("buck_vio18", VIO18, 1500000, 2120000, 20000,
buck_volt_range3, MT6397_VIO18_CON7, MT6397_VIO18_CON9, 0x1f,
- MT6397_VIO18_CON10, MT6397_VIO18_CON5),
+ MT6397_VIO18_CON10, MT6397_VIO18_CON5, MT6397_VIO18_CON2, 8),
MT6397_REG_FIXED("ldo_vtcxo", VTCXO, MT6397_ANALDO_CON0, 10, 2800000),
MT6397_REG_FIXED("ldo_va28", VA28, MT6397_ANALDO_CON1, 14, 2800000),
MT6397_LDO("ldo_vcama", VCAMA, ldo_volt_table1,
--
1.8.1.1.dirty
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH RESEND 2/2] regulator: mt6397: Add buck change mode regulator interface for mt6397
[not found] ` <20160511145046.GI6261@sirena.org.uk>
@ 2016-05-13 8:04 ` Henry Chen
0 siblings, 0 replies; 4+ messages in thread
From: Henry Chen @ 2016-05-13 8:04 UTC (permalink / raw)
To: linux-arm-kernel
Hi Mark,
On Wed, 2016-05-11 at 15:50 +0100, Mark Brown wrote:
> On Wed, May 11, 2016 at 05:31:30PM +0800, Henry Chen wrote:
>
> > +The possible values for "regulator-supported-modes" are:
> > + 0: PWM mode, mapping to regulator fast mode, allow the
> > + converter to remain in the PWM mode regardless of the load current, so
> > + that the noise spectrum of the converter can be minimized for certain
> > + highly-noise-sensitive handset applications.
> > + 1: Auto mode, mapping to regulator normal mode, mode switch by current
> > + loading. At light load currents, the converter automatically enters
> > + PFM mode to save power and improve light load efficiency. At heavy
> > + load currents, the converter automatically enters PWM mode to minimiz
> > + the noise spectrum of the converter.
>
> The details of how this maps onto Linux shouldn't be in the bindings.
>
> > + regulator-allow-change-mode;
> > + regulator-supported-modes = <0 1>;
>
> These are problematic too as covered in my other mail.
>
> > -static struct regulator_ops mt6397_volt_range_ops = {
> > +static const struct regulator_ops mt6397_volt_range_ops = {
>
> The constification is fine but an unrelated change. Otherwise this
> looks fine from a code point of view, let's get that merged separately.
Okay, although we didn't have conclusion and solution for regulator
operation mode, as you said that we can get some patch merged
separately, so I will resend the patch which clean up comments from
you and Daniel.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-05-13 8:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-11 9:31 Add support for regulator operation mode of mt6397 Henry Chen
2016-05-11 9:31 ` [PATCH RESEND 1/2] regulator: Add support for parsing operation mode Henry Chen
2016-05-11 9:31 ` [PATCH RESEND 2/2] regulator: mt6397: Add buck change mode regulator interface for mt6397 Henry Chen
[not found] ` <20160511145046.GI6261@sirena.org.uk>
2016-05-13 8:04 ` Henry Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).