mfd: rk808: add reboot support to rk808.c
Subsystems (2)
PATCH v3 1/1 mfd: rk808: add reboot support to rk808.c
This adds reboot support to the rk808 pmic driver and enables it for the rk809 and rk817 devices.
This only enables if the rockchip,system-power-controller flag is set.
---
This patch was created to address issues with psci-reset on rk356x chips. Until the rk356x series ATF open source code is released so we can fix the issue at the source, this is the only way to ensure reliable resetting on devices using these chips.
After testing the rk808 (thanks Robin!), it was found DEV_OFF_RST does not reset the PMIC to a power on state. Since the rk805 and rk818 match this register layout, I'm removing support for all three in the v2. It may be possible to add support to them using an RTC wakeup, but that has not been explored and is outside the scope of this patch.
Changelog:
V3: Thanks Dmitry!
- Adjust priority to be in line with other pmic drivers
- Move ret handling to case switch
- Make default registration debug
- Add unregister function on removal
V2:
- Squash the patch from Frank Wunderlich for rk809 support.
- Remove support for the rk805, rk808, and rk818 devices.
- Only register the reset handler for supported devices.
- Remove unnecessary dev_err and dev_warn statements.
- Register the reset handler directly
drivers/mfd/rk808.c | 45 +++++++++++++++++++++++++++++++++++++++ include/linux/mfd/rk808.h | 1 + 2 files changed, 46 insertions(+)
drivers/mfd/rk808.c +45 -0
@@ -19,6 +19,7 @@#include <linux/module.h> #include <linux/of_device.h> #include <linux/regmap.h> +#include <linux/reboot.h> struct rk808_reg_data {int addr;
@@ -543,6 +544,7 @@ static void rk808_pm_power_off(void) reg =RK808_DEVCTRL_REG , bit =DEV_OFF_RST ;break ; +case RK809_ID :case RK817_ID : reg =RK817_SYS_CFG (3 ); bit =DEV_OFF ;
@@ -559,6 +561,34 @@ static void rk808_pm_power_off(void)dev_err (&rk808_i2c_client->dev,"Failed to shutdown device!\n" ); } +static int rk808_restart_notify (struct notifier_block *this,unsigned long mode,void *cmd) +{ +int ret; +unsigned int reg, bit; +struct rk808 *rk808 =i2c_get_clientdata (rk808_i2c_client); + +switch (rk808->variant) { +case RK809_ID : +case RK817_ID : + reg =RK817_SYS_CFG (3 ); + bit =DEV_RST ; +break ; + +default : +return NOTIFY_DONE ; + } + ret =regmap_update_bits (rk808->regmap, reg, bit, bit); +if (ret) +dev_err (&rk808_i2c_client->dev,"Failed to restart device!\n" ); + +return NOTIFY_DONE ; +} + +static struct notifier_block rk808_restart_handler = { + .notifier_call = rk808_restart_notify, + .priority =192 , +}; +static void rk8xx_shutdown (struct i2c_client *client) {struct rk808 *rk808 =i2c_get_clientdata (client);
@@ -727,6 +757,18 @@ static int rk808_probe(struct i2c_client *client,if (of_property_read_bool (np,"rockchip,system-power-controller" )) { rk808_i2c_client = client; pm_power_off = rk808_pm_power_off; + +switch (rk808->variant) { +case RK809_ID : +case RK817_ID : + ret =register_restart_handler (&rk808_restart_handler); +if (ret) +dev_warn (&client->dev,"failed to register restart handler, %d\n" , ret); +break ; +default : +dev_dbg (&client->dev,"pmic controlled board reset not supported\n" ); +break ; + } }return 0 ;
@@ -749,6 +791,9 @@ static int rk808_remove(struct i2c_client *client)if (pm_power_off == rk808_pm_power_off) pm_power_off =NULL ; +if (of_property_read_bool (np,"rockchip,system-power-controller" )) +unregister_restart_handler (&rk808_restart_handler); +return 0 ; }
include/linux/mfd/rk808.h +1 -0
@@ -373,6 +373,7 @@ enum rk805_reg {#define SWITCH2_EN BIT(6)#define SWITCH1_EN BIT(5)#define DEV_OFF_RST BIT(3) +#define DEV_RST BIT(2)#define DEV_OFF BIT(0)#define RTC_STOP BIT(0)
Signature · 7 lines
2.25.1 _______________________________________________ Linux-rockchip mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rockchip
20.12.2021 17:46, Peter Geis пишет:
drivers/mfd/rk808.c static void rk808_pm_power_off(void) · line 568
Quoted 5 lines
drivers/mfd/rk808.c +5
-0+static int rk808_restart_notify (struct notifier_block *this,unsigned long mode,void *cmd) +{ +int ret; +unsigned int reg, bit; +struct rk808 *rk808 =i2c_get_clientdata (rk808_i2c_client);
Such code usually should be written in a form of reverse Xmas tree in kernel, but no need to respin just because of it. The patch looks good to me, thank you.
_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
Hi
drivers/mfd/rk808.c static int rk808_remove(struct i2c_client *client) · line 798
Quoted 11 lines
Gesendet: Montag, 20. Dezember 2021 um 15:46 Uhr
Von: "Peter Geis" <[email protected]>drivers/mfd/rk808.c +3
-0@@ -749,6 +791,9 @@ static int rk808_remove(struct i2c_client *client)if (pm_power_off == rk808_pm_power_off) pm_power_off =NULL ; +if (of_property_read_bool (np,"rockchip,system-power-controller" )) +unregister_restart_handler (&rk808_restart_handler); +return 0 ; }
this change misses a declaration
struct device_node *np = client->dev.of_node;
regards Frank
20.12.2021 19:33, Frank Wunderlich пишет:
Quoted 16 lines
Hi
drivers/mfd/rk808.c static int rk808_remove(struct i2c_client *client) · line 798
Quoted 11 lines
Gesendet: Montag, 20. Dezember 2021 um 15:46 Uhr
Von: "Peter Geis" <[email protected]>drivers/mfd/rk808.c +3
-0@@ -749,6 +791,9 @@ static int rk808_remove(struct i2c_client *client)if (pm_power_off == rk808_pm_power_off) pm_power_off =NULL ; +if (of_property_read_bool (np,"rockchip,system-power-controller" )) +unregister_restart_handler (&rk808_restart_handler); +return 0 ; }this change misses a declaration
Quoted 1 line
struct
device_node*np =client->dev.of_node;
Good catch, technically the whole of_property_read_bool() could be dropped from rk808_remove() since unregister_restart_handler() survives if handler wasn't registered.
Quoted 18 lines · Dmitry Osipenko
20.12.2021 19:33, Frank Wunderlich пишет:
Quoted 16 lines
Hi
drivers/mfd/rk808.c static int rk808_remove(struct i2c_client *client) · line 798
Quoted 11 lines
Gesendet: Montag, 20. Dezember 2021 um 15:46 Uhr
Von: "Peter Geis" <[email protected]>drivers/mfd/rk808.c +3
-0@@ -749,6 +791,9 @@ static int rk808_remove(struct i2c_client *client)if (pm_power_off == rk808_pm_power_off) pm_power_off =NULL ; +if (of_property_read_bool (np,"rockchip,system-power-controller" )) +unregister_restart_handler (&rk808_restart_handler); +return 0 ; }this change misses a declaration
Quoted 5 lines
Quoted 1 line
struct
device_node*np =client->dev.of_node;Good catch, technically the whole
of_property_read_bool()could be dropped fromrk808_remove()sinceunregister_restart_handler()survives if handler wasn't registered.
Thank you all!
Quoted 16 lines · Frank Wunderlich
Hi
drivers/mfd/rk808.c static int rk808_remove(struct i2c_client *client) · line 798
Quoted 11 lines
Gesendet: Montag, 20. Dezember 2021 um 15:46 Uhr
Von: "Peter Geis" <[email protected]>drivers/mfd/rk808.c +3
-0@@ -749,6 +791,9 @@ static int rk808_remove(struct i2c_client *client)if (pm_power_off == rk808_pm_power_off) pm_power_off =NULL ; +if (of_property_read_bool (np,"rockchip,system-power-controller" )) +unregister_restart_handler (&rk808_restart_handler); +return 0 ; }this change misses a declaration
Quoted 1 line
struct
device_node*np =client->dev.of_node;
How did this compile when you tested it?
Signature · 4 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog
Am 21. Dezember 2021 09:48:43 MEZ schrieb Lee Jones <[email protected]>:
Quoted 20 lines · Frank Wunderlich
Quoted 6 lines
Hi
Review static int rk808_remove(struct i2c_client
Quoted 3 lines
Gesendet: Montag, 20. Dezember 2021 um 15:46 Uhr
Von: "Peter Geis" <[email protected]>(quoted diff) +0
-0@@ -749,6 +791,9 @@ static int rk808_remove(struct i2c_client*client)
Quoted 4 lines
drivers/mfd/rk808.c static int rk808_remove(struct i2c_client *client)
Quoted 4 lines
drivers/mfd/rk808.c +1
-0if (pm_power_off == rk808_pm_power_off) pm_power_off =NULL ; + if (of_property_read_bool(np,"rockchip,system-power-controller"))
Quoted 7 lines
drivers/mfd/rk808.c static int rk808_remove(struct i2c_client *client) · line 798
Quoted 4 lines
drivers/mfd/rk808.c +2
-0+unregister_restart_handler (&rk808_restart_handler); +return 0 ; }this change misses a declaration
Quoted 3 lines
Quoted 1 line
struct
device_node*np =client->dev.of_node;How did this compile when you tested it?
Here i have squashed the change in:
https://github.com/frank-w/BPI-R2-4.14/commit/06430ffcb6d58d33014fb940256de77807ed620f
With the change i can compile it...
But in v4 (patch is tagged as v3 too) the of_property_read_bool was dropped completely. regards Frank
Quoted 23 lines · Frank Wunderlich
Am 21. Dezember 2021 09:48:43 MEZ schrieb Lee Jones <[email protected]>:
Quoted 22 lines · Frank Wunderlich
Quoted 6 lines
Hi
Review static int rk808_remove(struct i2c_client
Quoted 3 lines
Gesendet: Montag, 20. Dezember 2021 um 15:46 Uhr
Von: "Peter Geis" <[email protected]>(quoted diff) +0
-0@@ -749,6 +791,9 @@ static int rk808_remove(struct i2c_client*client)
Quoted 4 lines
drivers/mfd/rk808.c static int rk808_remove(struct i2c_client *client)
Quoted 4 lines
drivers/mfd/rk808.c +1
-0if (pm_power_off == rk808_pm_power_off) pm_power_off =NULL ; + if (of_property_read_bool(np,"rockchip,system-power-controller"))
Quoted 8 lines
drivers/mfd/rk808.c static int rk808_remove(struct i2c_client *client) · line 798
Quoted 4 lines
drivers/mfd/rk808.c +2
-0+unregister_restart_handler (&rk808_restart_handler); +return 0 ; }this change misses a declaration
struct
device_node*np =client->dev.of_node;
Quoted 7 lines
Quoted 1 line
How did this compile when you tested it?
Here i have squashed the change in:
https://github.com/frank-w/BPI-R2-4.14/commit/06430ffcb6d58d33014fb940256de77807ed620f
With the change i can compile it...
Not sure I understand.
Please make sure all patches you send for inclusion into the Linux kernel are fully tested. They should also be bisectable i.e. not depend on patches applied *on top*.
Quoted 2 lines
But in v4 (patch is tagged as v3 too) the
of_property_read_boolwas dropped completely. regards Frank
Signature · 4 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 7 lines
Gesendet: Mittwoch, 22. Dezember 2021 um 12:09 Uhr
Von: "Lee Jones" <[email protected]>
An: "Frank Wunderlich" <[email protected]>Quoted 4 lines
Here i have squashed the change in:
https://github.com/frank-w/BPI-R2-4.14/commit/06430ffcb6d58d33014fb940256de77807ed620f
Quoted 10 lines
Quoted 1 line
With the change i can compile it...
Not sure I understand.
Please make sure all patches you send for inclusion into the Linux kernel are fully tested. They should also be bisectable i.e. not depend on patches applied *on top*.
Quoted 2 lines
But in v4 (patch is tagged as v3 too) the
of_property_read_boolwas dropped completely. regards Frank
only v1 was sent by me :)
v4 is compilable and works on rk809 (Bananapi r2 pro)
regards Frank
Quoted 15 lines · Frank Wunderlich
Quoted 15 lines
Gesendet: Mittwoch, 22. Dezember 2021 um 12:09 Uhr
Von: "Lee Jones" <[email protected]>
An: "Frank Wunderlich" <[email protected]>Quoted 5 lines
Here i have squashed the change in:
https://github.com/frank-w/BPI-R2-4.14/commit/06430ffcb6d58d33014fb940256de77807ed620f
With the change i can compile it...
Not sure I understand.
Please make sure all patches you send for inclusion into the Linux kernel are fully tested. They should also be bisectable i.e. not depend on patches applied *on top*.
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
But in v4 (patch is tagged as v3 too) the
of_property_read_boolwas dropped completely. regards Frankonly v1 was sent by me :)
v4 is compilable and works on rk809 (Bananapi r2 pro)
My comments are directed at whoever sent patches without testing.
Signature · 4 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 18 lines · Lee Jones
Quoted 15 lines · Frank Wunderlich
Quoted 15 lines
Gesendet: Mittwoch, 22. Dezember 2021 um 12:09 Uhr
Von: "Lee Jones" <[email protected]>
An: "Frank Wunderlich" <[email protected]>Quoted 5 lines
Here i have squashed the change in:
https://github.com/frank-w/BPI-R2-4.14/commit/06430ffcb6d58d33014fb940256de77807ed620f
With the change i can compile it...
Not sure I understand.
Please make sure all patches you send for inclusion into the Linux kernel are fully tested. They should also be bisectable i.e. not depend on patches applied *on top*.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
But in v4 (patch is tagged as v3 too) the
of_property_read_boolwas dropped completely. regards Frankonly v1 was sent by me :)
v4 is compilable and works on rk809 (Bananapi r2 pro)
My comments are directed at whoever sent patches without testing.
Apologies, due to an unfortunate set of circumstances I missed the build failed and I was using a stale kernel.
Quoted 6 lines
--
Lee Jones [李琼斯]
Senior Technical Lead - Developer ServicesLinaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog