ARM: at91: cpuidle: convert to platform driver
Subsystems (4)
PATCH v3 1/3 ARM: at91: cpuidle: convert to platform driver
Using the platform driver model is a good way to separate the cpuidle specific code from the low level pm code. It allows to remove the dependency between these two components.
The platform_device is located in the pm code and a 'set' function has been added to set the standby function from the AT91_SOC_START initialization function. Each SoC with a cpuidle driver will set the standby function in the platform_data field at init time. Then pm code will register the cpuidle platform device.
The cpuidle driver will register the platform_driver and use the device's platform_data as a standby callback in the idle path.
--- arch/arm/mach-at91/at91rm9200.c | 3 +++ arch/arm/mach-at91/at91sam9260.c | 3 +++ arch/arm/mach-at91/at91sam9261.c | 3 +++ arch/arm/mach-at91/at91sam9263.c | 3 +++ arch/arm/mach-at91/at91sam9g45.c | 3 +++ arch/arm/mach-at91/at91sam9rl.c | 3 +++ arch/arm/mach-at91/cpuidle.c | 29 +++++++++++++++-------------- arch/arm/mach-at91/pm.c | 12 ++++++++++++ arch/arm/mach-at91/pm.h | 4 ++++ 9 files changed, 49 insertions(+), 14 deletions(-)
arch/arm/mach-at91/at91rm9200.c +3 -0
@@ -27,6 +27,7 @@#include "generic.h" #include "clock.h" #include "sam9_smc.h" +#include "pm.h" /* -------------------------------------------------------------------- * Clocks
@@ -337,6 +338,8 @@ static void __init at91rm9200_initialize(void)/* Initialize GPIO subsystem */ at91_gpio_init (at91rm9200_gpio,cpu_is_at91rm9200_bga () ?AT91RM9200_BGA :AT91RM9200_PQFP ); + +at91_pm_set_standby (at91rm9200_standby); }
arch/arm/mach-at91/at91sam9260.c +3 -0
@@ -28,6 +28,7 @@#include "generic.h" #include "clock.h" #include "sam9_smc.h" +#include "pm.h" /* -------------------------------------------------------------------- * Clocks
@@ -351,6 +352,8 @@ static void __init at91sam9260_initialize(void)/* Register GPIO subsystem */ at91_gpio_init (at91sam9260_gpio,3 ); + +at91_pm_set_standby (at91sam9_standby); }/* --------------------------------------------------------------------
arch/arm/mach-at91/at91sam9261.c +3 -0
@@ -27,6 +27,7 @@#include "generic.h" #include "clock.h" #include "sam9_smc.h" +#include "pm.h" /* -------------------------------------------------------------------- * Clocks
@@ -293,6 +294,8 @@ static void __init at91sam9261_initialize(void)/* Register GPIO subsystem */ at91_gpio_init (at91sam9261_gpio,3 ); + +at91_pm_set_sandby (at91sam9_standby); }/* --------------------------------------------------------------------
arch/arm/mach-at91/at91sam9263.c +3 -0
@@ -26,6 +26,7 @@#include "generic.h" #include "clock.h" #include "sam9_smc.h" +#include "pm.h" /* -------------------------------------------------------------------- * Clocks
@@ -330,6 +331,8 @@ static void __init at91sam9263_initialize(void)/* Register GPIO subsystem */ at91_gpio_init (at91sam9263_gpio,5 ); + +at91_pm_set_standby (at91sam9263_standby); }/* --------------------------------------------------------------------
arch/arm/mach-at91/at91sam9g45.c +3 -0
@@ -26,6 +26,7 @@#include "generic.h" #include "clock.h" #include "sam9_smc.h" +#include "pm.h" /* -------------------------------------------------------------------- * Clocks
@@ -379,6 +380,8 @@ static void __init at91sam9g45_initialize(void)/* Register GPIO subsystem */ at91_gpio_init (at91sam9g45_gpio,5 ); + +at91_pm_set_standby (at91sam9g45_standby); }/* --------------------------------------------------------------------
arch/arm/mach-at91/at91sam9rl.c +3 -0
@@ -27,6 +27,7 @@#include "generic.h" #include "clock.h" #include "sam9_smc.h" +#include "pm.h" /* -------------------------------------------------------------------- * Clocks
@@ -296,6 +297,8 @@ static void __init at91sam9rl_initialize(void)/* Register GPIO subsystem */ at91_gpio_init (at91sam9rl_gpio,4 ); + +at91_pm_set_standby (at91sam9_standby); }/* --------------------------------------------------------------------
arch/arm/mach-at91/cpuidle.c +15 -14
@@ -21,26 +21,17 @@#include <linux/export.h> #include <asm/proc-fns.h> #include <asm/cpuidle.h> -#include <mach/cpu.h> - -#include "pm.h" #define AT91_MAX_STATES 2 +static void (*at91_standby)(void ); +/* Actual code that puts the SoC in different idle states */ static int at91_enter_idle (struct cpuidle_device *dev,struct cpuidle_driver *drv,int index) { -if (cpu_is_at91rm9200 ()) -at91rm9200_standby (); -else if (cpu_is_at91sam9g45 ()) -at91sam9g45_standby (); -else if (cpu_is_at91sam9263 ()) -at91sam9263_standby (); -else -at91sam9_standby (); - +at91_standby ();return index; }
@@ -60,9 +51,19 @@ static struct cpuidle_driver at91_idle_driver = { };/* Initialize CPU idle by registering the idle states */ -static int __init at91_init_cpuidle (void ) +static int at91_cpuidle_probe (struct platform_device *dev) { + at91_standby = (void *)(dev->dev.platform_data); +return cpuidle_register (&at91_idle_driver,NULL ); } -device_initcall (at91_init_cpuidle); +static struct platform_driver at91_cpuidle_driver = { + .driver = { + .name ="cpuidle-at91" , + .owner =THIS_MODULE , + }, + .probe = at91_cpuidle_probe, +}; + +module_platform_driver (at91_cpuidle_driver);
arch/arm/mach-at91/pm.c +12 -0
@@ -314,6 +314,15 @@ static const struct platform_suspend_ops at91_pm_ops = { .end = at91_pm_end, }; +static struct platform_device at91_cpuidle_device = { + .name ="cpuidle-at91" , +}; + +void at91_pm_set_standby (void (*at91_standby)(void )) +{ + at91_cpuidle_device.dev.platform_data = at91_standby; +} +static int __init at91_pm_init (void ) {#ifdef CONFIG_AT91_SLOW_CLOCK
@@ -325,6 +334,9 @@ static int __init at91_pm_init(void)/* AT91RM9200 SDRAM low-power mode cannot be used with self-refresh. */ if (cpu_is_at91rm9200 ())at91_ramc_write (0 ,AT91RM9200_SDRAMC_LPR ,0 ); + +if (at91_cpuidle_device.dev.platform_data) +platform_device_register (&at91_cpuidle_device);suspend_set_ops (&at91_pm_ops);
arch/arm/mach-at91/pm.h +4 -0
@@ -11,9 +11,13 @@#ifndef __ARCH_ARM_MACH_AT91_PM#define __ARCH_ARM_MACH_AT91_PM +#include <asm/proc-fns.h> +#include <mach/at91_ramc.h> #include <mach/at91rm9200_sdramc.h> +extern void at91_pm_set_standby (void (*at91_standby)(void )); +/* * The AT91RM9200 goes into self-refresh mode with this command, and will * terminate self-refresh automatically on the next SDRAM access.
Signature · 1 line
1.7.9.5
PATCH v3 2/3 ARM: at91: cpuidle: Move driver to drivers/cpuidle
As the cpuidle driver code has no more the dependency with the pm code, the 'standby' callback being passed as a parameter to the device's platform data, we can move the cpuidle driver in the drivers/cpuidle directory.
--- arch/arm/mach-at91/Makefile | 1 - drivers/cpuidle/Kconfig.arm | 7 +++++++ drivers/cpuidle/Makefile | 1 + .../cpuidle.c => drivers/cpuidle/cpuidle-at91.c | 0 4 files changed, 8 insertions(+), 1 deletion(-) rename arch/arm/mach-at91/cpuidle.c => drivers/cpuidle/cpuidle-at91.c (100%)
arch/arm/mach-at91/Makefile +0 -1
@@ -98,7 +98,6 @@ obj-y += leds.o # Power Management obj-$(CONFIG_PM) += pm.o obj-$(CONFIG_AT91_SLOW_CLOCK) += pm_slowclock.o -obj-$(CONFIG_CPU_IDLE) += cpuidle.o ifeq ($(CONFIG_PM_DEBUG),y) CFLAGS_pm.o += -DDEBUG
drivers/cpuidle/Kconfig.arm +7 -0
@@ -27,6 +27,13 @@ config ARM_U8500_CPUIDLE help Select this to enable cpuidle for ST-E u8500 processors +config ARM_AT91_CPUIDLE + bool "Cpu Idle Driver for the AT91 processors" + default y + depends on ARCH_AT91 + help + Select this to enable cpuidle for AT91 processors + config CPU_IDLE_BIG_LITTLE bool "Support for ARM big.LITTLE processors" depends on ARCH_VEXPRESS_TC2_PM
drivers/cpuidle/Makefile +1 -0
@@ -11,4 +11,5 @@ obj-$(CONFIG_ARM_HIGHBANK_CPUIDLE) += cpuidle-calxeda.o obj-$(CONFIG_ARM_KIRKWOOD_CPUIDLE) += cpuidle-kirkwood.o obj-$(CONFIG_ARM_ZYNQ_CPUIDLE) += cpuidle-zynq.o obj-$(CONFIG_ARM_U8500_CPUIDLE) += cpuidle-ux500.o +obj-$(CONFIG_ARM_AT91_CPUIDLE) += cpuidle-at91.o obj-$(CONFIG_CPU_IDLE_BIG_LITTLE) += cpuidle-big_little.o
drivers/cpuidle/cpuidle-at91.c renamed from arch/arm/mach-at91/cpuidle.c +0 -0
Signature · 1 line
1.7.9.5
PATCH v3 3/3 ARM: at91: pm: use standby callback instead of cpu_is
In reply to Daniel LezcanoThe cpuidle's platform_device has the standby function set for the correct SoC when supported in the platform data. Remove the { if then else } statements in the at91_pm_enter by using directly the standby ops.
--- arch/arm/mach-at91/pm.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
arch/arm/mach-at91/pm.c +7 -9
@@ -39,6 +39,8 @@#include "at91_rstc.h" #include "at91_shdwc.h" +static void (*at91_pm_standby)(void ); +static void __init show_reset_status (void ) {static char reset[]__initdata ="reset" ;
@@ -266,14 +268,8 @@ static int at91_pm_enter(suspend_state_t state)* For ARM 926 based chips, this requirement is weaker * as at91sam9 can access a RAM in self-refresh mode. */ -if (cpu_is_at91rm9200 ()) -at91rm9200_standby (); -else if (cpu_is_at91sam9g45 ()) -at91sam9g45_standby (); -else if (cpu_is_at91sam9263 ()) -at91sam9263_standby (); -else -at91sam9_standby (); +if (at91_pm_standby) +at91_pm_standby ();break ;case PM_SUSPEND_ON :
@@ -335,8 +331,10 @@ static int __init at91_pm_init(void)if (cpu_is_at91rm9200 ())at91_ramc_write (0 ,AT91RM9200_SDRAMC_LPR ,0 ); -if (at91_cpuidle_device.dev.platform_data) +if (at91_cpuidle_device.dev.platform_data) { + at91_pm_standby = at91_cpuidle_device.dev.platform_data;platform_device_register (&at91_cpuidle_device); + }suspend_set_ops (&at91_pm_ops);
Signature · 1 line
1.7.9.5
PATCH v3 1/3 ARM: at91: cpuidle: convert to platform driver
In reply to Daniel LezcanoQuoted 214 lines · Daniel Lezcano
Using the platform driver model is a good way to separate the cpuidle specific code from the low level pm code. It allows to remove the dependency between these two components.
The
platform_deviceis located in the pm code and a 'set' function has been added to set the standby function from theAT91_SOC_STARTinitialization function. Each SoC with a cpuidle driver will set the standby function in theplatform_datafield at init time. Then pm code will register the cpuidle platform device.The cpuidle driver will register the
platform_driverand use the device'splatform_dataas a standby callback in the idle path.Signed-off-by Daniel Lezcano <[email protected]>--- arch/arm/mach-at91/at91rm9200.c | 3 +++ arch/arm/mach-at91/at91sam9260.c | 3 +++ arch/arm/mach-at91/at91sam9261.c | 3 +++ arch/arm/mach-at91/at91sam9263.c | 3 +++ arch/arm/mach-at91/at91sam9g45.c | 3 +++ arch/arm/mach-at91/at91sam9rl.c | 3 +++ arch/arm/mach-at91/cpuidle.c | 29 +++++++++++++++-------------- arch/arm/mach-at91/pm.c | 12 ++++++++++++ arch/arm/mach-at91/pm.h | 4 ++++ 9 files changed, 49 insertions(+), 14 deletions(-)arch/arm/mach-at91/at91rm9200.c +3
-0@@ -27,6 +27,7 @@#include "generic.h" #include "clock.h" #include "sam9_smc.h" +#include "pm.h" /* -------------------------------------------------------------------- * Clocks @@ -337,6 +338,8 @@ static void __init at91rm9200_initialize(void)/* Initialize GPIO subsystem */ at91_gpio_init (at91rm9200_gpio,cpu_is_at91rm9200_bga () ?AT91RM9200_BGA :AT91RM9200_PQFP ); + +at91_pm_set_standby (at91rm9200_standby); }arch/arm/mach-at91/at91sam9260.c +3
-0@@ -28,6 +28,7 @@#include "generic.h" #include "clock.h" #include "sam9_smc.h" +#include "pm.h" /* -------------------------------------------------------------------- * Clocks @@ -351,6 +352,8 @@ static void __init at91sam9260_initialize(void)/* Register GPIO subsystem */ at91_gpio_init (at91sam9260_gpio,3 ); + +at91_pm_set_standby (at91sam9_standby); }/* -------------------------------------------------------------------- arch/arm/mach-at91/at91sam9261.c +3
-0@@ -27,6 +27,7 @@#include "generic.h" #include "clock.h" #include "sam9_smc.h" +#include "pm.h" /* -------------------------------------------------------------------- * Clocks @@ -293,6 +294,8 @@ static void __init at91sam9261_initialize(void)/* Register GPIO subsystem */ at91_gpio_init (at91sam9261_gpio,3 ); + +at91_pm_set_sandby (at91sam9_standby); }/* -------------------------------------------------------------------- arch/arm/mach-at91/at91sam9263.c +3
-0@@ -26,6 +26,7 @@#include "generic.h" #include "clock.h" #include "sam9_smc.h" +#include "pm.h" /* -------------------------------------------------------------------- * Clocks @@ -330,6 +331,8 @@ static void __init at91sam9263_initialize(void)/* Register GPIO subsystem */ at91_gpio_init (at91sam9263_gpio,5 ); + +at91_pm_set_standby (at91sam9263_standby); }/* -------------------------------------------------------------------- arch/arm/mach-at91/at91sam9g45.c +3
-0@@ -26,6 +26,7 @@#include "generic.h" #include "clock.h" #include "sam9_smc.h" +#include "pm.h" /* -------------------------------------------------------------------- * Clocks @@ -379,6 +380,8 @@ static void __init at91sam9g45_initialize(void)/* Register GPIO subsystem */ at91_gpio_init (at91sam9g45_gpio,5 ); + +at91_pm_set_standby (at91sam9g45_standby); }/* -------------------------------------------------------------------- arch/arm/mach-at91/at91sam9rl.c +3
-0@@ -27,6 +27,7 @@#include "generic.h" #include "clock.h" #include "sam9_smc.h" +#include "pm.h" /* -------------------------------------------------------------------- * Clocks @@ -296,6 +297,8 @@ static void __init at91sam9rl_initialize(void)/* Register GPIO subsystem */ at91_gpio_init (at91sam9rl_gpio,4 ); + +at91_pm_set_standby (at91sam9_standby); }/* -------------------------------------------------------------------- arch/arm/mach-at91/cpuidle.c +15
-14@@ -21,26 +21,17 @@#include <linux/export.h> #include <asm/proc-fns.h> #include <asm/cpuidle.h> -#include <mach/cpu.h> - -#include "pm.h" #define AT91_MAX_STATES 2 +static void (*at91_standby)(void ); +/* Actual code that puts the SoC in different idle states */ static int at91_enter_idle (struct cpuidle_device *dev,struct cpuidle_driver *drv,int index) { -if (cpu_is_at91rm9200 ()) -at91rm9200_standby (); -else if (cpu_is_at91sam9g45 ()) -at91sam9g45_standby (); -else if (cpu_is_at91sam9263 ()) -at91sam9263_standby (); -else -at91sam9_standby (); - +at91_standby ();return index; }@@ -60,9 +51,19 @@ static struct cpuidle_driver at91_idle_driver = { };/* Initialize CPU idle by registering the idle states */ -static int __init at91_init_cpuidle (void ) +static int at91_cpuidle_probe (struct platform_device *dev) { + at91_standby = (void *)(dev->dev.platform_data); +return cpuidle_register (&at91_idle_driver,NULL ); } -device_initcall (at91_init_cpuidle); +static struct platform_driver at91_cpuidle_driver = { + .driver = { + .name ="cpuidle-at91" , + .owner =THIS_MODULE , + }, + .probe = at91_cpuidle_probe, +}; + +module_platform_driver (at91_cpuidle_driver);arch/arm/mach-at91/pm.c +0
-0@@ -314,6 +314,15 @@ static const struct platform_suspend_ops at91_pm_ops = { .end = at91_pm_end,
arch/arm/mach-at91/pm.c static const struct platform_suspend_ops at91_pm_ops = { · line 324
Quoted 10 lines
arch/arm/mach-at91/pm.c +8
-0}; +static struct platform_device at91_cpuidle_device = { + .name ="cpuidle-at91" , +}; + +void at91_pm_set_standby (void (*at91_standby)(void )) +{ + at91_cpuidle_device.dev.platform_data = at91_standby; +}
set the function pointer in this function and then fill the pdata if !null
I do not like this idea put it in the pdata then reput it in function pointer in patch 3
arch/arm/mach-at91/pm.c static int __init at91_pm_init(void) · line 336
Quoted 8 lines
arch/arm/mach-at91/pm.c +1
-0+static int __init at91_pm_init (void ) {#ifdef CONFIG_AT91_SLOW_CLOCK @@ -325,6 +334,9 @@ static int __init at91_pm_init(void)/* AT91RM9200 SDRAM low-power mode cannot be used with self-refresh. */ if (cpu_is_at91rm9200 ())at91_ramc_write (0 ,AT91RM9200_SDRAMC_LPR ,0 );
if need to move to SoC init too
Quoted 27 lines
arch/arm/mach-at91/pm.c +3
-0+ +if (at91_cpuidle_device.dev.platform_data) +platform_device_register (&at91_cpuidle_device);suspend_set_ops (&at91_pm_ops);arch/arm/mach-at91/pm.h +4
-0@@ -11,9 +11,13 @@#ifndef __ARCH_ARM_MACH_AT91_PM#define __ARCH_ARM_MACH_AT91_PM +#include <asm/proc-fns.h> +#include <mach/at91_ramc.h> #include <mach/at91rm9200_sdramc.h> +extern void at91_pm_set_standby (void (*at91_standby)(void )); +/* * The AT91RM9200 goes into self-refresh mode with this command, and will * terminate self-refresh automatically on the next SDRAM access. Signature · 1 line
1.7.9.5