diff mbox

[08/10] power/reset: keystone: Register with kernel restart handler

Message ID 1411779438-23127-9-git-send-email-linux@roeck-us.net (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Guenter Roeck Sept. 27, 2014, 12:57 a.m. UTC
Register with kernel restart handler instead of setting arm_pm_restart directly.

Move notifier registration to the end of the probe function to avoid having to
implement error handling.

Cc: Ivan Khoronzhuk <ivan.khoronzhuk@ti.com>
Cc: Santosh Shilimkar <santosh.shilimkar@ti.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/power/reset/keystone-reset.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

Comments

Santosh Shilimkar Sept. 28, 2014, 10:57 p.m. UTC | #1
On Friday 26 September 2014 08:57 PM, Guenter Roeck wrote:
> Register with kernel restart handler instead of setting arm_pm_restart directly.
> 
> Move notifier registration to the end of the probe function to avoid having to
> implement error handling.
> 
> Cc: Ivan Khoronzhuk <ivan.khoronzhuk@ti.com>
> Cc: Santosh Shilimkar <santosh.shilimkar@ti.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
Looks ok for me.
Acked-by: Santosh Shilimkar <santosh.shilimkar@ti.com>

Ivan,
Can you please just test it once ? Thanks !!

Regards,
Santosh


--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ivan Khoronzhuk Sept. 29, 2014, 1:53 p.m. UTC | #2
On 09/27/2014 03:57 AM, Guenter Roeck wrote:
> Register with kernel restart handler instead of setting arm_pm_restart directly.
>
> Move notifier registration to the end of the probe function to avoid having to
> implement error handling.
>
> Cc: Ivan Khoronzhuk <ivan.khoronzhuk@ti.com>
> Cc: Santosh Shilimkar <santosh.shilimkar@ti.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>   drivers/power/reset/keystone-reset.c | 18 ++++++++++++++----
>   1 file changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/power/reset/keystone-reset.c b/drivers/power/reset/keystone-reset.c
> index 408a18f..9d46586 100644
> --- a/drivers/power/reset/keystone-reset.c
> +++ b/drivers/power/reset/keystone-reset.c
> @@ -12,9 +12,9 @@
>   
>   #include <linux/io.h>
>   #include <linux/module.h>
> +#include <linux/notifier.h>
>   #include <linux/reboot.h>
>   #include <linux/regmap.h>
> -#include <asm/system_misc.h>
>   #include <linux/mfd/syscon.h>
>   #include <linux/of_platform.h>
>   
> @@ -52,7 +52,8 @@ static inline int rsctrl_enable_rspll_write(void)
>   				  RSCTRL_KEY_MASK, RSCTRL_KEY);
>   }
>   
> -static void rsctrl_restart(enum reboot_mode mode, const char *cmd)
> +static int rsctrl_restart_handler(struct notifier_block *this,
> +				  unsigned long mode, void *cmd)
>   {
>   	/* enable write access to RSTCTRL */
>   	rsctrl_enable_rspll_write();
> @@ -60,8 +61,15 @@ static void rsctrl_restart(enum reboot_mode mode, const char *cmd)
>   	/* reset the SOC */
>   	regmap_update_bits(pllctrl_regs, rspll_offset + RSCTRL_RG,
>   			   RSCTRL_RESET_MASK, 0);
> +
> +	return NOTIFY_DONE;
>   }
>   
> +static struct notifier_block rsctrl_restart_nb = {
> +	.notifier_call = rsctrl_restart_handler,
> +	.priority = 128,
> +};
> +
>   static struct of_device_id rsctrl_of_match[] = {
>   	{.compatible = "ti,keystone-reset", },
>   	{},
> @@ -114,8 +122,6 @@ static int rsctrl_probe(struct platform_device *pdev)
>   	if (ret)
>   		return ret;
>   
> -	arm_pm_restart = rsctrl_restart;
> -
>   	/* disable a reset isolation for all module clocks */
>   	ret = regmap_write(pllctrl_regs, rspll_offset + RSISO_RG, 0);
>   	if (ret)
> @@ -147,6 +153,10 @@ static int rsctrl_probe(struct platform_device *pdev)
>   			return ret;
>   	}
>   
> +	ret = register_restart_handler(&rsctrl_restart_nb);
> +	if (ret)
> +		dev_err(dev, "cannot register restart handler (err=%d)\n", ret);

What about return ret? Even the register_restart_handler() always 
returns 0 currently.

> +
>   	return 0;
>   }
>   

Santosh,
I've tested it. That's fine.
Guenter Roeck Sept. 29, 2014, 3:11 p.m. UTC | #3
On Mon, Sep 29, 2014 at 04:53:14PM +0300, Ivan Khoronzhuk wrote:
> On 09/27/2014 03:57 AM, Guenter Roeck wrote:
> >Register with kernel restart handler instead of setting arm_pm_restart directly.
> >
> >Move notifier registration to the end of the probe function to avoid having to
> >implement error handling.
> >
> >Cc: Ivan Khoronzhuk <ivan.khoronzhuk@ti.com>
> >Cc: Santosh Shilimkar <santosh.shilimkar@ti.com>
> >Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> >---
> >  drivers/power/reset/keystone-reset.c | 18 ++++++++++++++----
> >  1 file changed, 14 insertions(+), 4 deletions(-)
> >
> >diff --git a/drivers/power/reset/keystone-reset.c b/drivers/power/reset/keystone-reset.c
> >index 408a18f..9d46586 100644
> >--- a/drivers/power/reset/keystone-reset.c
> >+++ b/drivers/power/reset/keystone-reset.c
> >@@ -12,9 +12,9 @@
> >  #include <linux/io.h>
> >  #include <linux/module.h>
> >+#include <linux/notifier.h>
> >  #include <linux/reboot.h>
> >  #include <linux/regmap.h>
> >-#include <asm/system_misc.h>
> >  #include <linux/mfd/syscon.h>
> >  #include <linux/of_platform.h>
> >@@ -52,7 +52,8 @@ static inline int rsctrl_enable_rspll_write(void)
> >  				  RSCTRL_KEY_MASK, RSCTRL_KEY);
> >  }
> >-static void rsctrl_restart(enum reboot_mode mode, const char *cmd)
> >+static int rsctrl_restart_handler(struct notifier_block *this,
> >+				  unsigned long mode, void *cmd)
> >  {
> >  	/* enable write access to RSTCTRL */
> >  	rsctrl_enable_rspll_write();
> >@@ -60,8 +61,15 @@ static void rsctrl_restart(enum reboot_mode mode, const char *cmd)
> >  	/* reset the SOC */
> >  	regmap_update_bits(pllctrl_regs, rspll_offset + RSCTRL_RG,
> >  			   RSCTRL_RESET_MASK, 0);
> >+
> >+	return NOTIFY_DONE;
> >  }
> >+static struct notifier_block rsctrl_restart_nb = {
> >+	.notifier_call = rsctrl_restart_handler,
> >+	.priority = 128,
> >+};
> >+
> >  static struct of_device_id rsctrl_of_match[] = {
> >  	{.compatible = "ti,keystone-reset", },
> >  	{},
> >@@ -114,8 +122,6 @@ static int rsctrl_probe(struct platform_device *pdev)
> >  	if (ret)
> >  		return ret;
> >-	arm_pm_restart = rsctrl_restart;
> >-
> >  	/* disable a reset isolation for all module clocks */
> >  	ret = regmap_write(pllctrl_regs, rspll_offset + RSISO_RG, 0);
> >  	if (ret)
> >@@ -147,6 +153,10 @@ static int rsctrl_probe(struct platform_device *pdev)
> >  			return ret;
> >  	}
> >+	ret = register_restart_handler(&rsctrl_restart_nb);
> >+	if (ret)
> >+		dev_err(dev, "cannot register restart handler (err=%d)\n", ret);
> 
> What about return ret? Even the register_restart_handler() always
> returns 0 currently.
> 
Yes, you have a point. I'll redo the series and return an error in this case,
unless the driver has additional functionality (we don't want it to fail to
load if it also provides poweroff handling, for example).

Thanks,
Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/power/reset/keystone-reset.c b/drivers/power/reset/keystone-reset.c
index 408a18f..9d46586 100644
--- a/drivers/power/reset/keystone-reset.c
+++ b/drivers/power/reset/keystone-reset.c
@@ -12,9 +12,9 @@ 
 
 #include <linux/io.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #include <linux/reboot.h>
 #include <linux/regmap.h>
-#include <asm/system_misc.h>
 #include <linux/mfd/syscon.h>
 #include <linux/of_platform.h>
 
@@ -52,7 +52,8 @@  static inline int rsctrl_enable_rspll_write(void)
 				  RSCTRL_KEY_MASK, RSCTRL_KEY);
 }
 
-static void rsctrl_restart(enum reboot_mode mode, const char *cmd)
+static int rsctrl_restart_handler(struct notifier_block *this,
+				  unsigned long mode, void *cmd)
 {
 	/* enable write access to RSTCTRL */
 	rsctrl_enable_rspll_write();
@@ -60,8 +61,15 @@  static void rsctrl_restart(enum reboot_mode mode, const char *cmd)
 	/* reset the SOC */
 	regmap_update_bits(pllctrl_regs, rspll_offset + RSCTRL_RG,
 			   RSCTRL_RESET_MASK, 0);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block rsctrl_restart_nb = {
+	.notifier_call = rsctrl_restart_handler,
+	.priority = 128,
+};
+
 static struct of_device_id rsctrl_of_match[] = {
 	{.compatible = "ti,keystone-reset", },
 	{},
@@ -114,8 +122,6 @@  static int rsctrl_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	arm_pm_restart = rsctrl_restart;
-
 	/* disable a reset isolation for all module clocks */
 	ret = regmap_write(pllctrl_regs, rspll_offset + RSISO_RG, 0);
 	if (ret)
@@ -147,6 +153,10 @@  static int rsctrl_probe(struct platform_device *pdev)
 			return ret;
 	}
 
+	ret = register_restart_handler(&rsctrl_restart_nb);
+	if (ret)
+		dev_err(dev, "cannot register restart handler (err=%d)\n", ret);
+
 	return 0;
 }