Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Linux: Kernel

[PATCH V3 2/4] regulator: tps62360: add dt support

 

 

Linux kernel RSS feed   Index | Next | Previous | View Threaded


ldewangan at nvidia

May 10, 2012, 11:38 PM

Post #1 of 6 (76 views)
Permalink
[PATCH V3 2/4] regulator: tps62360: add dt support

Add dt support for the pmu device tps62360 and
Add binding documentation with example.
With this patch driver will support both device-tree and
non-device tree registration.

Signed-off-by: Laxman Dewangan <ldewangan [at] nvidia>
---
Changes from V1:
Fixed compilation error in non-devicetree configuration.
Changes from V2:
Taken care of Grant's review comments.

.../bindings/regulator/tps62360-regulator.txt | 45 ++++++++++++
drivers/regulator/tps62360-regulator.c | 73 +++++++++++++++++++-
2 files changed, 117 insertions(+), 1 deletions(-)
create mode 100644 Documentation/devicetree/bindings/regulator/tps62360-regulator.txt

diff --git a/Documentation/devicetree/bindings/regulator/tps62360-regulator.txt b/Documentation/devicetree/bindings/regulator/tps62360-regulator.txt
new file mode 100644
index 0000000..f411b57
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/tps62360-regulator.txt
@@ -0,0 +1,45 @@
+TPS62360 Voltage regulators
+
+Required properties:
+- compatible: Must be one of the following.
+ "ti,tps62360"
+ "ti,tps62361",
+ "ti,tps62362",
+ "ti,tps62363",
+- reg: I2C slave address
+
+Optional properties:
+- ti,enable-force-pwm: Enable force PWM mode. This is boolean value.
+- ti,enable-vout-discharge: Enable output discharge. This is boolean value.
+- ti,enable-pull-down: Enable pull down. This is boolean value.
+- ti,vsel0-gpio: GPIO for controlling VSEL0 line.
+ If this property is missing, then assume that there is no GPIO
+ for vsel0 control.
+- ti,vsel1-gpio: Gpio for controlling VSEL1 line.
+ If this property is missing, then assume that there is no GPIO
+ for vsel1 control.
+- ti,vsel0-state-high: Inital state of vsel0 input is high.
+ If this property is missing, then assume the state as low (0).
+- ti,vsel1-state-high: Inital state of vsel1 input is high.
+ If this property is missing, then assume the state as low (0).
+
+Any property defined as part of the core regulator binding, defined in
+regulator.txt, can also be used.
+
+Example:
+
+ abc: tps62360 {
+ compatible = "ti,tps62361";
+ reg = <0x60>;
+ regulator-name = "tps62361-vout";
+ regulator-min-microvolt = <500000>;
+ regulator-max-microvolt = <1500000>;
+ regulator-boot-on
+ ti,vsel0-gpio = <&gpio1 16 0>;
+ ti,vsel1-gpio = <&gpio1 17 0>;
+ ti,vsel0-state-high;
+ ti,vsel1-state-high;
+ ti,enable-pull-down;
+ ti,enable-force-pwm;
+ ti,enable-vout-discharge;
+ };
diff --git a/drivers/regulator/tps62360-regulator.c b/drivers/regulator/tps62360-regulator.c
index 3506900..60765cc 100644
--- a/drivers/regulator/tps62360-regulator.c
+++ b/drivers/regulator/tps62360-regulator.c
@@ -26,6 +26,10 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/err.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
+#include <linux/regulator/of_regulator.h>
#include <linux/platform_device.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
@@ -297,6 +301,56 @@ static const struct regmap_config tps62360_regmap_config = {
.cache_type = REGCACHE_RBTREE,
};

+static struct tps62360_regulator_platform_data *
+ of_get_tps62360_platform_data(struct device *dev)
+{
+ struct tps62360_regulator_platform_data *pdata;
+ struct device_node *np = dev->of_node;
+
+ pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata) {
+ dev_err(dev, "Memory alloc failed for platform data\n");
+ return NULL;
+ }
+
+ pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node);
+ if (!pdata->reg_init_data) {
+ dev_err(dev, "Not able to get OF regulator init data\n");
+ return NULL;
+ }
+
+ pdata->vsel0_gpio = of_get_named_gpio(np, "vsel0-gpio", 0);
+ pdata->vsel1_gpio = of_get_named_gpio(np, "vsel1-gpio", 0);
+
+ if (of_find_property(np, "ti,vsel0-state-high", NULL))
+ pdata->vsel0_def_state = 1;
+
+ if (of_find_property(np, "ti,vsel1-state-high", NULL))
+ pdata->vsel1_def_state = 1;
+
+ if (of_find_property(np, "ti,enable-pull-down", NULL))
+ pdata->en_internal_pulldn = true;
+
+ if (of_find_property(np, "ti,enable-force-pwm", NULL))
+ pdata->en_force_pwm = true;
+
+ if (of_find_property(np, "ti,enable-vout-discharge", NULL))
+ pdata->en_discharge = true;
+
+ return pdata;
+}
+
+#if defined(CONFIG_OF)
+static const struct of_device_id tps62360_of_match[] = {
+ { .compatible = "ti,tps62360", .data = (void *)TPS62360},
+ { .compatible = "ti,tps62361", .data = (void *)TPS62361},
+ { .compatible = "ti,tps62362", .data = (void *)TPS62362},
+ { .compatible = "ti,tps62363", .data = (void *)TPS62363},
+ {},
+}
+MODULE_DEVICE_TABLE(of, tps62360_of_match);
+#endif
+
static int __devinit tps62360_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -306,8 +360,24 @@ static int __devinit tps62360_probe(struct i2c_client *client,
struct tps62360_chip *tps;
int ret;
int i;
+ int chip_id;

pdata = client->dev.platform_data;
+ chip_id = id->driver_data;
+
+ if (client->dev.of_node) {
+ const struct of_device_id *match;
+ match = of_match_device(of_match_ptr(tps62360_of_match),
+ &client->dev);
+ if (!match) {
+ dev_err(&client->dev, "Error: No device match found\n");
+ return -ENODEV;
+ }
+ chip_id = (int)match->data;
+ if (!pdata)
+ pdata = of_get_tps62360_platform_data(&client->dev);
+ }
+
if (!pdata) {
dev_err(&client->dev, "%s(): Platform data not found\n",
__func__);
@@ -328,7 +398,7 @@ static int __devinit tps62360_probe(struct i2c_client *client,
tps->vsel1_gpio = pdata->vsel1_gpio;
tps->dev = &client->dev;

- switch (id->driver_data) {
+ switch (chip_id) {
case TPS62360:
case TPS62362:
tps->voltage_base = TPS62360_BASE_VOLTAGE;
@@ -484,6 +554,7 @@ static struct i2c_driver tps62360_i2c_driver = {
.driver = {
.name = "tps62360",
.owner = THIS_MODULE,
+ .of_match_table = of_match_ptr(tps62360_of_match),
},
.probe = tps62360_probe,
.remove = __devexit_p(tps62360_remove),
--
1.7.1.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


broonie at opensource

May 11, 2012, 7:58 AM

Post #2 of 6 (75 views)
Permalink
Re: [PATCH V3 2/4] regulator: tps62360: add dt support [In reply to]

On Fri, May 11, 2012 at 12:08:43PM +0530, Laxman Dewangan wrote:

This looks good overall but I do have a few things with the binding.

> +Optional properties:
> +- ti,enable-force-pwm: Enable force PWM mode. This is boolean value.

Hrm, this is fairly generic - it's REGULATOR_MODE_ACTIVE. But I'm a bit
unsure about how generic exposing it is in bindings since it's often
dynamic in the running system, we've really not got any mainline
examples of something setting a mode. With modern regulators the mode
detection stuff in the hardware is generally good enough that there's no
benefit from doing this, it's suprising to actually see systems that
benefit.

> +- ti,enable-vout-discharge: Enable output discharge. This is boolean value.

This I think we should definitely add a framework feature for this and
make into a generic property, it's a very standard feature and more
normally set unconditionally.
Attachments: signature.asc (0.82 KB)


ldewangan at nvidia

May 11, 2012, 8:35 AM

Post #3 of 6 (74 views)
Permalink
Re: [PATCH V3 2/4] regulator: tps62360: add dt support [In reply to]

On Friday 11 May 2012 08:28 PM, Mark Brown wrote:
> * PGP Signed by an unknown key
>
> On Fri, May 11, 2012 at 12:08:43PM +0530, Laxman Dewangan wrote:
>
> This looks good overall but I do have a few things with the binding.
>
>> +Optional properties:
>> +- ti,enable-force-pwm: Enable force PWM mode. This is boolean value.
> Hrm, this is fairly generic - it's REGULATOR_MODE_ACTIVE. But I'm a bit
> unsure about how generic exposing it is in bindings since it's often
> dynamic in the running system, we've really not got any mainline
> examples of something setting a mode. With modern regulators the mode
> detection stuff in the hardware is generally good enough that there's no
> benefit from doing this, it's suprising to actually see systems that
> benefit.
>

Yaah, I think this flag can map directly to REGULATOR_MODE_FAST. If I
understand PWM mode properly then this is used when high current load is
require or fast switching on load current is require. By enabling force
PWM enable, hw will not switch to PFM mode based on load current.

I think if we map the regulator mode to FAST as the force PWM enable and
NORMAL as force PWM =0 then it will be generic.
Client can pass the initial mode when they fill constraint at the time
of registration and it can also give the opportunity to change mode by
calling regulator_set_mode().
If this is fine then I can create patch for removing this flag from
platform data and add set_mode/get_mode function.

>> +- ti,enable-vout-discharge: Enable output discharge. This is boolean value.
> This I think we should definitely add a framework feature for this and
> make into a generic property, it's a very standard feature and more
> normally set unconditionally.
>

I think this is not require to enable always otherwise there may be
power dissipation from this path always, just when we off the rail
(disable rail or when go to shutdown so that the voltage output can go
down faster).
Should we add "unsigned en_discharge:1" in regulator init data but did
not get how core driver can use this flag specially when shutdown?


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


broonie at opensource

May 11, 2012, 1:36 PM

Post #4 of 6 (70 views)
Permalink
Re: [PATCH V3 2/4] regulator: tps62360: add dt support [In reply to]

On Fri, May 11, 2012 at 12:08:43PM +0530, Laxman Dewangan wrote:
> Add dt support for the pmu device tps62360 and
> Add binding documentation with example.
> With this patch driver will support both device-tree and
> non-device tree registration.

Oh, sorry - I meant to say that I went ahead and applied this. Ideally
the active discharge thing will get factored out quickly though.
Attachments: signature.asc (0.82 KB)


broonie at opensource

May 11, 2012, 2:30 PM

Post #5 of 6 (69 views)
Permalink
Re: [PATCH V3 2/4] regulator: tps62360: add dt support [In reply to]

On Fri, May 11, 2012 at 09:05:01PM +0530, Laxman Dewangan wrote:

> Yaah, I think this flag can map directly to REGULATOR_MODE_FAST. If
> I understand PWM mode properly then this is used when high current
> load is require or fast switching on load current is require. By
> enabling force PWM enable, hw will not switch to PFM mode based on
> load current.

> I think if we map the regulator mode to FAST as the force PWM enable
> and NORMAL as force PWM =0 then it will be generic.

Yes, this is pretty much exactly what _FAST means. With modern hardware
the forced PWM mode just isn't needed, a modern regulator is able to
respond sufficiently quickly to changes in the output load. Mode
switching from software was generally found to be impractical for DCDC
convertors as the load requirements change so quickly and without
software control that by the time you respond from software you can't
switch out of a lower power mode into a higher current one it's too late.

> >>+- ti,enable-vout-discharge: Enable output discharge. This is boolean value.
> >This I think we should definitely add a framework feature for this and
> >make into a generic property, it's a very standard feature and more
> >normally set unconditionally.

> I think this is not require to enable always otherwise there may be
> power dissipation from this path always, just when we off the rail
> (disable rail or when go to shutdown so that the voltage output can
> go down faster).
> Should we add "unsigned en_discharge:1" in regulator init data but
> did not get how core driver can use this flag specially when
> shutdown?

Oh, now you say this I think I remember discussing this with you before!
This is pretty unusual for such hardware. Normally there's something in
the digital block so that the discharge is only enabled if the regulator
is disabled, if it's enabled then the discharge would automatically be
taken off since actively discharging while enabled doesn't make sense
and may in fact be actively harmful.

If the hardware doesn't do that then I'd expect the driver to take care
of this if it implements the framework feature (once the framework
feature is added).


ldewangan at nvidia

May 20, 2012, 12:19 AM

Post #6 of 6 (57 views)
Permalink
Re: [PATCH V3 2/4] regulator: tps62360: add dt support [In reply to]

On Saturday 12 May 2012 03:00 AM, Mark Brown wrote:
> * PGP Signed by an unknown key
>
> On Fri, May 11, 2012 at 09:05:01PM +0530, Laxman Dewangan wrote:
>
>> I think this is not require to enable always otherwise there may be
>> power dissipation from this path always, just when we off the rail
>> (disable rail or when go to shutdown so that the voltage output can
>> go down faster).
>> Should we add "unsigned en_discharge:1" in regulator init data but
>> did not get how core driver can use this flag specially when
>> shutdown?
> Oh, now you say this I think I remember discussing this with you before!
> This is pretty unusual for such hardware. Normally there's something in
> the digital block so that the discharge is only enabled if the regulator
> is disabled, if it's enabled then the discharge would automatically be
> taken off since actively discharging while enabled doesn't make sense
> and may in fact be actively harmful.
>

Just to share here with our new pmu which we got recently, the
discharge path behavior is exactly same as what Mark mentioned
It need to be enable always. The pmu auto disable the DISC path in
normal operation so there is no power dissipation but when it detects
the en_bit is written 0 or any external control is making the rail to be
off, it automatically turn on the path so that ramp-down can happen faster.
Just we need to enable this always.

> If the hardware doesn't do that then I'd expect the driver to take care
> of this if it implements the framework feature (once the framework
> feature is added).

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Linux kernel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.