mfd: palmas: Add power off control
Subsystems (4)
PATCH v2 1/1 mfd: palmas: Add power off control
Hook up "pm_power_off" to palmas power off routine if there is DT property "ti,system-power-controller" defined, so platform which is powered by this regulator can be powered off properly.
Based on work by:
Mallikarjun Kasoju <[email protected]>
--- .../devicetree/bindings/regulator/palmas-pmic.txt | 5 +++ drivers/mfd/palmas.c | 33 ++++++++++++++++++-- include/linux/mfd/palmas.h | 1 + 3 files changed, 37 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/regulator/palmas-pmic.txt +5 -0
@@ -36,6 +36,9 @@ Optional nodes: ti,smps-range - OTP has the wrong range set for the hardware so override 0 - low range, 1 - high range. +- ti,system-power-controller: Telling whether or not this pmic is controlling + the system power. + Example: #include <dt-bindings/interrupt-controller/irq.h>
@@ -48,6 +51,8 @@ pmic { ti,ldo6-vibrator; + ti,system-power-controller; + regulators { smps12_reg : smps12 { regulator-name = "smps12";
drivers/mfd/palmas.c +31 -2
@@ -229,6 +229,32 @@ static void palmas_dt_to_pdata(struct i2c_client *i2c,PALMAS_POWER_CTRL_ENABLE2_MASK ;if (i2c->irq)palmas_set_pdata_irq_flag (i2c, pdata); + + pdata->pm_off =of_property_read_bool (node, +"ti,system-power-controller" ); +} + +static struct palmas *palmas_dev; +static void palmas_power_off (void ) +{ +unsigned int addr; +int ret, slave; + +if (!palmas_dev) +return ; + + slave =PALMAS_BASE_TO_SLAVE (PALMAS_PMU_CONTROL_BASE ); + addr =PALMAS_BASE_TO_REG (PALMAS_PMU_CONTROL_BASE ,PALMAS_DEV_CTRL ); + + ret =regmap_update_bits ( + palmas_dev->regmap[slave], + addr, +PALMAS_DEV_CTRL_DEV_ON , +0 ); + +if (ret) +pr_err ("%s: Unable to write to DEV_CTRL_DEV_ON: %d\n" , + __func__, ret); }static unsigned int palmas_features =PALMAS_PMIC_FEATURE_SMPS10_BOOST ;
@@ -423,10 +449,13 @@ no_irq:*/ if (node) { ret =of_platform_populate (node,NULL ,NULL , &i2c->dev); -if (ret <0 ) +if (ret <0 ) { goto err_irq; -else + }else if (pdata->pm_off && !pm_power_off) { + palmas_dev = palmas; + pm_power_off = palmas_power_off;return ret; + } }return ret;
include/linux/mfd/palmas.h +1 -0
@@ -258,6 +258,7 @@ struct palmas_platform_data {*/ int mux_from_pdata;u8 pad1, pad2; +bool pm_off;struct palmas_pmic_platform_data *pmic_pdata;struct palmas_gpadc_platform_data *gpadc_pdata;
Signature · 1 line
1.7.9.5
Quoted 4 lines · Bill Huang
Hook up "
pm_power_off" to palmas power off routine if there is DT property "ti,system-power-controller" defined, so platform which is powered by this regulator can be powered off properly.
Quoted 8 lines
Based on work by:
Mallikarjun Kasoju <[email protected]>Signed-off-by Bill Huang <[email protected]>cc Mallikarjun Kasoju <[email protected]>--- .../devicetree/bindings/regulator/palmas-pmic.txt | 5 +++ drivers/mfd/palmas.c | 33 ++++++++++++++++++--
Since the specific question on v1 was not answered, I will ask again, any reason why it wont fit in drivers/power/reset/ is'nt it the right place to add this?
Quoted 38 lines
include/linux/mfd/palmas.h | 1 + 3 files changed, 37 insertions(+), 2 deletions(-)Documentation/devicetree/bindings/regulator/palmas-pmic.txt +5
-0@@ -36,6 +36,9 @@ Optional nodes: ti,smps-range - OTP has the wrong range set for the hardware so override 0 - low range, 1 - high range. +- ti,system-power-controller: Telling whether or not this pmic is controlling + the system power. + Example: #include <dt-bindings/interrupt-controller/irq.h>@@ -48,6 +51,8 @@ pmic { ti,ldo6-vibrator; + ti,system-power-controller; + regulators { smps12_reg : smps12 { regulator-name = "smps12";drivers/mfd/palmas.c +4
-0@@ -229,6 +229,32 @@ static void palmas_dt_to_pdata(struct i2c_client *i2c,PALMAS_POWER_CTRL_ENABLE2_MASK ;if (i2c->irq)palmas_set_pdata_irq_flag (i2c, pdata); + + pdata->pm_off =of_property_read_bool (node, +"ti,system-power-controller" ); +}
drivers/mfd/palmas.c static void palmas_dt_to_pdata(struct i2c_client *i2c, · line 245
Quoted 10 lines
drivers/mfd/palmas.c +10
-0+ +static struct palmas *palmas_dev; +static void palmas_power_off (void ) +{ +unsigned int addr; +int ret, slave; + +if (!palmas_dev) +return ; +
If you notice the reference code I send, atleast on TWL6035/37 variants of Palmas, USB IRQ unmask is mandatory for power on with USB cable - example usage scenario: extremely low battery, device powered off, plug in usb cable to restart charging - you'd like to initiate charging logic in bootloader, but that wont work if the device does not do OFF-ON transition with usb cable plugged in for vbus.
Quoted 44 lines
drivers/mfd/palmas.c +17
-2+ slave =PALMAS_BASE_TO_SLAVE (PALMAS_PMU_CONTROL_BASE ); + addr =PALMAS_BASE_TO_REG (PALMAS_PMU_CONTROL_BASE ,PALMAS_DEV_CTRL ); + + ret =regmap_update_bits ( + palmas_dev->regmap[slave], + addr, +PALMAS_DEV_CTRL_DEV_ON , +0 ); + +if (ret) +pr_err ("%s: Unable to write to DEV_CTRL_DEV_ON: %d\n" , + __func__, ret); }static unsigned int palmas_features =PALMAS_PMIC_FEATURE_SMPS10_BOOST ;@@ -423,10 +449,13 @@ no_irq:*/ if (node) { ret =of_platform_populate (node,NULL ,NULL , &i2c->dev); -if (ret <0 ) +if (ret <0 ) { goto err_irq; -else + }else if (pdata->pm_off && !pm_power_off) { + palmas_dev = palmas; + pm_power_off = palmas_power_off;return ret; + } }return ret;include/linux/mfd/palmas.h +1
-0@@ -258,6 +258,7 @@ struct palmas_platform_data {*/ int mux_from_pdata;u8 pad1, pad2; +bool pm_off;struct palmas_pmic_platform_data *pmic_pdata;struct palmas_gpadc_platform_data *gpadc_pdata;
Signature · 2 lines
Regards, Nishanth Menon
Quoted 15 lines · Nishanth Menon
Quoted 7 lines · Bill Huang
Hook up "
pm_power_off" to palmas power off routine if there is DT property "ti,system-power-controller" defined, so platform which is powered by this regulator can be powered off properly.Based on work by:
Mallikarjun Kasoju <[email protected]>Quoted 6 lines
Signed-off-by Bill Huang <[email protected]>cc Mallikarjun Kasoju <[email protected]>--- .../devicetree/bindings/regulator/palmas-pmic.txt | 5 +++ drivers/mfd/palmas.c | 33++++++++++++++++++--
Quoted 3 lines
Since the specific question on v1 was not answered, I will ask again, any reason why it wont fit in
drivers/power/reset/is'nt it the right place to add this?
I think it makes sense to put simple standalone reset drivers into drivers/power/reset. However, where reset is just one tiny function of a larger device that already has a driver, it's fine for one driver to implement multiple features or essentially expose multiple subsystems.
(besides this is system power off not system reset; which is drivers/power/reset?)
Quoted 16 lines · Stephen Warren
Quoted 15 lines · Nishanth Menon
Quoted 13 lines · Bill Huang
Hook up "
pm_power_off" to palmas power off routine if there is DT property "ti,system-power-controller" defined, so platform which is powered by this regulator can be powered off properly.Based on work by:
Mallikarjun Kasoju <[email protected]>Signed-off-by Bill Huang <[email protected]>cc Mallikarjun Kasoju <[email protected]>--- .../devicetree/bindings/regulator/palmas-pmic.txt | 5 +++ drivers/mfd/palmas.c | 33++++++++++++++++++--
Quoted 7 lines
Quoted 3 lines
Since the specific question on v1 was not answered, I will ask again, any reason why it wont fit in
drivers/power/reset/is'nt it the right place to add this?I think it makes sense to put simple standalone reset drivers into
drivers/power/reset. However, where reset is just one tiny function of a larger device that already has a driver, it's fine for one driver to
Yes, this will probably increase in logic when we add stuff like USB IRQ enable.. :(
Quoted 1 line
implement multiple features or essentially expose multiple subsystems.
I would generally agree to the same, but given we seem to now have isolated it out to it's own subsystem, /me shrugs.
Quoted 3 lines
(besides this is system power off not system reset; which is
drivers/power/reset?)
[1] seems to indicate that "or shut it down, by manipulating the main power supply on the board." which seems to be precisely what we are doing here, unless, ofcourse, my understanding of Palmas is wrong at this point..
[1]
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/power/reset/Kconfig
Signature · 2 lines
Regards, Nishanth Menon
Quoted 8 lines · Nishanth Menon
If you notice the reference code I send, atleast on TWL6035/37 variants of Palmas, USB IRQ unmask is mandatory for power on with USB cable - example usage scenario: extremely low battery, device powered off, plug in usb cable to restart charging - you'd like to initiate charging logic in bootloader, but that wont work if the device does not do OFF-ON transition with usb cable plugged in for vbus.
Why do we need to add Palmas USB_IRQ unmask logic in shutdown? Does that mean for all platform using Palmas has to unmask USB IRQ (including those do not power vbus through Palmas)? Can't we just have a simple shutdown function but have the VBus programming been done in USB driver or maybe platform driver since it is platform specific control?
Quoted 9 lines · Bill Huang
Quoted 8 lines · Nishanth Menon
If you notice the reference code I send, atleast on TWL6035/37 variants of Palmas, USB IRQ unmask is mandatory for power on with USB cable - example usage scenario: extremely low battery, device powered off, plug in usb cable to restart charging - you'd like to initiate charging logic in bootloader, but that wont work if the device does not do OFF-ON transition with usb cable plugged in for vbus.
Quoted 5 lines
Why do we need to add Palmas
USB_IRQunmask logic in shutdown? Does that mean for all platform using Palmas has to unmask USB IRQ (including those do not power vbus through Palmas)? Can't we just have a simple shutdown function but have the VBus programming been done in USB driver or maybe platform driver since it is platform specific control?
we dont have a irq cleanup, irq handling is done in palmas-mfd. Further,
Why would USB driver care about vbus supply needs in complete power off
- it is the job of palmas driver? Further, palmas-mfd shutdown handler(currently missing) if probably cleansup things:
mfd_remove_devices(palmas->dev);
palmas_irq_exit(palmas);
shutdown sequence becomes complicated further esp if things are cleanedup in shutdown (Dummy patch[1]).
All I am saying is this: shutdown should allow powerup functionality to work as well, how we do that is upto us - I personally found it a little easier to keep the IRQ unmask in shutdown easier to deal with, but other options might be possible as well.
[1]
drivers/mfd/palmas.c +6 -0
@@ -447,6 +447,11 @@ static int palmas_i2c_remove(struct i2c_client *i2c)return 0 ; } +static void palmas_i2c_shutdown (struct i2c_client *i2c) +{ +palmas_i2c_remove (i2c); +} +static const struct i2c_device_id palmas_i2c_id[] = { {"palmas" , }, {"twl6035" , },
@@ -464,6 +469,7 @@ static struct i2c_driver palmas_i2c_driver = { }, .probe = palmas_i2c_probe, .remove = palmas_i2c_remove, + .shutdown = palmas_i2c_shutdown, .id_table = palmas_i2c_id, };
Signature · 2 lines
Regards, Nishanth Menon
Quoted 24 lines · Nishanth Menon
Quoted 9 lines · Bill Huang
Quoted 8 lines · Nishanth Menon
If you notice the reference code I send, atleast on TWL6035/37 variants of Palmas, USB IRQ unmask is mandatory for power on with USB cable - example usage scenario: extremely low battery, device powered off, plug in usb cable to restart charging - you'd like to initiate charging logic in bootloader, but that wont work if the device does not do OFF-ON transition with usb cable plugged in for vbus.
Quoted 5 lines
Why do we need to add Palmas
USB_IRQunmask logic in shutdown? Does that mean for all platform using Palmas has to unmask USB IRQ (including those do not power vbus through Palmas)? Can't we just have a simple shutdown function but have the VBus programming been done in USB driver or maybe platform driver since it is platform specific control?we dont have a irq cleanup, irq handling is done in palmas-mfd. Further,
Why would USB driver care about vbus supply needs in complete power off
- it is the job of palmas driver? Further, palmas-mfd shutdown handler(currently missing) if probably cleansup things:
mfd_remove_devices(palmas->dev);
palmas_irq_exit(palmas);
Quoted 8 lines
shutdown sequence becomes complicated further esp if things are cleanedup in shutdown (Dummy patch[1]).
All I am saying is this: shutdown should allow powerup functionality to work as well, how we do that is upto us - I personally found it a little easier to keep the IRQ unmask in shutdown easier to deal with, but other options might be possible as well.
I'm not sure if I understand your comments completely (maybe due to I'm not familiar with the mechanism of unmasking USB IRQ in Palmas driver) but doing cleanup in each driver shutdown handler makes sense to me, if those clean up can be done in shutdown then we can make power off function as simple as possible and being part of Palmas mfd driver?
Quoted 26 lines
[1]
drivers/mfd/palmas.c +6
-0@@ -447,6 +447,11 @@ static int palmas_i2c_remove(struct i2c_client *i2c)return 0 ; } +static void palmas_i2c_shutdown (struct i2c_client *i2c) +{ +palmas_i2c_remove (i2c); +} +static const struct i2c_device_id palmas_i2c_id[] = { {"palmas" , }, {"twl6035" , },@@ -464,6 +469,7 @@ static struct i2c_driver palmas_i2c_driver = { }, .probe = palmas_i2c_probe, .remove = palmas_i2c_remove, + .shutdown = palmas_i2c_shutdown, .id_table = palmas_i2c_id, };
Quoted 29 lines · Bill Huang
Quoted 28 lines · Nishanth Menon
Quoted 9 lines · Bill Huang
Quoted 8 lines · Nishanth Menon
If you notice the reference code I send, atleast on TWL6035/37 variants of Palmas, USB IRQ unmask is mandatory for power on with USB cable - example usage scenario: extremely low battery, device powered off, plug in usb cable to restart charging - you'd like to initiate charging logic in bootloader, but that wont work if the device does not do OFF-ON transition with usb cable plugged in for vbus.
Quoted 5 lines
Why do we need to add Palmas
USB_IRQunmask logic in shutdown? Does that mean for all platform using Palmas has to unmask USB IRQ (including those do not power vbus through Palmas)? Can't we just have a simple shutdown function but have the VBus programming been done in USB driver or maybe platform driver since it is platform specific control?we dont have a irq cleanup, irq handling is done in palmas-mfd. Further,
Why would USB driver care about vbus supply needs in complete power off
- it is the job of palmas driver? Further, palmas-mfd shutdown handler(currently missing) if probably cleansup things:mfd_remove_devices(palmas->dev); palmas_irq_exit(palmas);shutdown sequence becomes complicated further esp if things are cleanedup in shutdown (Dummy patch[1]).
Quoted 7 lines
Quoted 4 lines
All I am saying is this: shutdown should allow powerup functionality to work as well, how we do that is upto us - I personally found it a little easier to keep the IRQ unmask in shutdown easier to deal with, but other options might be possible as well.
I'm not sure if I understand your comments completely (maybe due to I'm not familiar with the mechanism of unmasking USB IRQ in Palmas driver)
This is IMHO an weird configuration I saw on TWL6035/6037 Palmas device - so I suspect should be the case in probably other palmas devices as well. I hit power off, and I can start up the device again by supplying vbus -(usecase was, at that point in time, battery charging)
anyways, I was working with busybox and no usb driver even enabled, but I am told by the twl6035/7 support folks that due to design USB IRQ needs to be unmasked at shutdown/poweroff to allow OFF->ON transition sequence to start inside Palmas when vbus is supplied.
Quoted 3 lines
but doing cleanup in each driver shutdown handler makes sense to me, if those clean up can be done in shutdown then we can make power off function as simple as possible and being part of Palmas mfd driver?
not really, mfd shutdown does not guarantee rest of the drivers' shutdown functions are safely called, pm_power_off unfortunately is the only "official point" where we can safely and cleanly shutdown the system.
Signature · 2 lines
Regards, Nishanth Menon
Quoted 49 lines · Nishanth Menon
Quoted 29 lines · Bill Huang
Quoted 28 lines · Nishanth Menon
Quoted 9 lines · Bill Huang
Quoted 8 lines · Nishanth Menon
If you notice the reference code I send, atleast on TWL6035/37 variants of Palmas, USB IRQ unmask is mandatory for power on with USB cable - example usage scenario: extremely low battery, device powered off, plug in usb cable to restart charging - you'd like to initiate charging logic in bootloader, but that wont work if the device does not do OFF-ON transition with usb cable plugged in for vbus.
Quoted 5 lines
Why do we need to add Palmas
USB_IRQunmask logic in shutdown? Does that mean for all platform using Palmas has to unmask USB IRQ (including those do not power vbus through Palmas)? Can't we just have a simple shutdown function but have the VBus programming been done in USB driver or maybe platform driver since it is platform specific control?we dont have a irq cleanup, irq handling is done in palmas-mfd. Further,
Why would USB driver care about vbus supply needs in complete power off
- it is the job of palmas driver? Further, palmas-mfd shutdown handler(currently missing) if probably cleansup things:mfd_remove_devices(palmas->dev); palmas_irq_exit(palmas);shutdown sequence becomes complicated further esp if things are cleanedup in shutdown (Dummy patch[1]).
Quoted 7 lines
Quoted 4 lines
All I am saying is this: shutdown should allow powerup functionality to work as well, how we do that is upto us - I personally found it a little easier to keep the IRQ unmask in shutdown easier to deal with, but other options might be possible as well.
I'm not sure if I understand your comments completely (maybe due to I'm not familiar with the mechanism of unmasking USB IRQ in Palmas driver)
This is IMHO an weird configuration I saw on TWL6035/6037 Palmas device
- so I suspect should be the case in probably other palmas devices as well. I hit power off, and I can start up the device again by supplying vbus -(usecase was, at that point in time, battery charging)anyways, I was working with busybox and no usb driver even enabled, but I am told by the twl6035/7 support folks that due to design USB IRQ needs to be unmasked at shutdown/poweroff to allow
OFF->ONtransition sequence to start inside Palmas when vbus is supplied.
Quoted 8 lines
Quoted 3 lines
but doing cleanup in each driver shutdown handler makes sense to me, if those clean up can be done in shutdown then we can make power off function as simple as possible and being part of Palmas mfd driver?
not really, mfd shutdown does not guarantee rest of the drivers' shutdown functions are safely called,
pm_power_offunfortunately is the only "official point" where we can safely and cleanly shutdown the system.
It looks to me whether or not adding those extra control in a generic Palmas driver is still in doubt, will you send your patch for this in the near future? If not, any objection on making it as a basic and simple power off control (that said, any further processing which has to be in power off routine can be added on top of that, or can be moved to be under drivers/reset if needed) using the existing mechanism?