ARM: imx: cpuidle: Convert imx5 driver to platform driver
Subsystems (4)
RFC PATCH 1/3 ARM: imx: cpuidle: Convert imx5 driver to platform driver
The PM low level code is tied and called from the cpuidle driver.
The platform driver approach allows to split the pm code and the cpuidle driver, hence keeping the code encapsulated inside the pm code.
The idle method called through the arm_pm_idle is changed by a callback in the cpuidle driver, assigned at init time from the platform_data field of the platform device passed in the probe function.
--- arch/arm/mach-imx/cpuidle-imx5.c | 20 +++++++++++++++++--- arch/arm/mach-imx/cpuidle.h | 5 ----- arch/arm/mach-imx/pm-imx5.c | 11 +++++++++-- 3 files changed, 26 insertions(+), 10 deletions(-)
arch/arm/mach-imx/cpuidle-imx5.c +17 -3
@@ -8,12 +8,14 @@#include <linux/cpuidle.h> #include <linux/module.h> -#include <asm/system_misc.h> +#include <linux/platform_device.h> + +static void (*imx5_idle)(void );static int imx5_cpuidle_enter (struct cpuidle_device *dev,struct cpuidle_driver *drv,int index) { -arm_pm_idle (); +imx5_idle ();return index; }
@@ -31,7 +33,19 @@ static struct cpuidle_driver imx5_cpuidle_driver = { .state_count = 1, }; -int __init imx5_cpuidle_init (void ) +static int imx5_cpuidle_probe (struct platform_device *dev) { + imx5_idle = dev->dev.platform_data; +return cpuidle_register (&imx5_cpuidle_driver,NULL ); } + +static struct platform_driver imx5_driver_cpuidle = { + .driver = { + .name ="cpuidle-imx5" , + .owner =THIS_MODULE , + }, + .probe = imx5_cpuidle_probe, +}; + +module_platform_driver (imx5_driver_cpuidle);
arch/arm/mach-imx/cpuidle.h +0 -5
@@ -11,13 +11,8 @@*/ #ifdef CONFIG_CPU_IDLE -extern int imx5_cpuidle_init (void );extern int imx6q_cpuidle_init (void );#else -static inline int imx5_cpuidle_init (void ) -{ -return 0 ; -}static inline int imx6q_cpuidle_init (void ) {return 0 ;
arch/arm/mach-imx/pm-imx5.c +9 -2
@@ -13,12 +13,12 @@#include <linux/io.h> #include <linux/err.h> #include <linux/export.h> +#include <linux/platform_device.h> #include <asm/cacheflush.h> #include <asm/system_misc.h> #include <asm/tlbflush.h> #include "common.h" -#include "cpuidle.h" #include "crm-regs-imx5.h" #include "hardware.h"
@@ -149,6 +149,13 @@ static void imx5_pm_idle(void)imx5_cpu_do_idle (); } +static struct platform_device imx5_cpuidle_pdev = { + .name ="cpuidle-imx5" , + .dev = { + .platform_data = imx5_pm_idle, + }, +}; +static int __init imx5_pm_common_init (void ) {int ret;
@@ -166,7 +173,7 @@ static int __init imx5_pm_common_init(void)/* Set the registers to the default cpu idle state. */ mx5_cpu_lp_set (IMX5_DEFAULT_CPU_IDLE_STATE ); -return imx5_cpuidle_init (); +return platform_device_register (&imx5_cpuidle_pdev); }void __init imx5_pm_init (void )
Signature · 1 line
1.7.9.5
RFC PATCH 2/3 ARM: imx: cpuidle: Convert imx6q driver to platform_driver
The pm code and the cpuidle driver are tied together. The platform driver approach allows to split this code and move the pm low level code from the driver to the pm block.
--- arch/arm/mach-imx/cpuidle-imx6q.c | 31 ++++++++++++++++++------------- arch/arm/mach-imx/cpuidle.h | 20 -------------------- arch/arm/mach-imx/mach-imx6q.c | 8 -------- arch/arm/mach-imx/pm-imx6q.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 41 deletions(-) delete mode 100644 arch/arm/mach-imx/cpuidle.h
arch/arm/mach-imx/cpuidle-imx6q.c +18 -13
@@ -7,16 +7,15 @@*/ #include <linux/cpuidle.h> -#include <linux/module.h> +#include <linux/platform_device.h> #include <asm/cpuidle.h> #include <asm/proc-fns.h> -#include "common.h" -#include "cpuidle.h" -static atomic_t master =ATOMIC_INIT (0 );static DEFINE_SPINLOCK (master_lock); +static void (*imx6q_idle)(void ); +static int imx6q_enter_wait (struct cpuidle_device *dev,struct cpuidle_driver *drv,int index) {
@@ -27,9 +26,9 @@ static int imx6q_enter_wait(struct cpuidle_device *dev,*/ if (!spin_trylock (&master_lock)) goto idle; -imx6q_set_lpm (WAIT_UNCLOCKED ); -cpu_do_idle (); -imx6q_set_lpm (WAIT_CLOCKED ); + +imx6q_idle (); +spin_unlock (&master_lock); goto done; }
@@ -63,13 +62,19 @@ static struct cpuidle_driver imx6q_cpuidle_driver = { .safe_state_index = 0, }; -int __init imx6q_cpuidle_init (void ) +static int imx6q_cpuidle_probe (struct platform_device *dev) { -/* Need to enable SCU standby for entering WAIT modes */ -imx_scu_standby_enable (); - -/* Set chicken bit to get a reliable WAIT mode support */ -imx6q_set_chicken_bit (); + imx6q_idle = dev->dev.platform_data;return cpuidle_register (&imx6q_cpuidle_driver,NULL ); } + +static struct platform_driver imx6q_driver_cpuidle = { + .driver = { + .name ="cpuidle-imx6q" , + .owner =THIS_MODULE , + }, + .probe = imx6q_cpuidle_probe, +}; + +module_platform_driver (imx6q_driver_cpuidle);
arch/arm/mach-imx/cpuidle.h deleted +0 -20
@@ -1,20 +0,0 @@ -/* -* Copyright 2012 Freescale Semiconductor, Inc. -* Copyright 2012 Linaro Ltd. -* -* The code contained herein is licensed under the GNU General Public -* License. You may obtain a copy of the GNU General Public License -* Version 2 or later at the following locations: -* -* http://www.opensource.org/licenses/gpl-license.html -* http://www.gnu.org/copyleft/gpl.html -*/ - -#ifdef CONFIG_CPU_IDLE -extern int imx6q_cpuidle_init (void ); -#else -static inline int imx6q_cpuidle_init (void ) -{ -return 0 ; -} -#endif
arch/arm/mach-imx/mach-imx6q.c +0 -8
@@ -37,7 +37,6 @@#include <asm/system_misc.h> #include "common.h" -#include "cpuidle.h" #include "hardware.h" static u32 chip_revision;
@@ -265,13 +264,6 @@ static struct platform_device imx6q_cpufreq_pdev = {static void __init imx6q_init_late (void ) { -/* -* WAIT mode is broken on TO 1.0 and 1.1, so there is no point -* to run cpuidle on them. -*/ -if (imx6q_revision () >IMX_CHIP_REVISION_1_1 ) -imx6q_cpuidle_init (); -if (IS_ENABLED (CONFIG_ARM_IMX6Q_CPUFREQ )) {imx6q_opp_init ();platform_device_register (&imx6q_cpufreq_pdev);
arch/arm/mach-imx/pm-imx6q.c +30 -0
@@ -14,6 +14,7 @@#include <linux/io.h> #include <linux/of.h> #include <linux/suspend.h> +#include <linux/platform_device.h> #include <asm/cacheflush.h> #include <asm/proc-fns.h> #include <asm/suspend.h>
@@ -50,12 +51,41 @@ static int imx6q_pm_enter(suspend_state_t state)return 0 ; } +static void imx6q_pm_idle (void ) +{ +imx6q_set_lpm (WAIT_UNCLOCKED ); +cpu_do_idle (); +imx6q_set_lpm (WAIT_CLOCKED ); +} +static const struct platform_suspend_ops imx6q_pm_ops = { .enter = imx6q_pm_enter, .valid = suspend_valid_only_mem, }; +static struct platform_device imx6q_cpuidle_device = { + .name ="cpuidle-imx6q" , + .dev = { + .platform_data = imx6q_pm_idle, + }, +}; +void __init imx6q_pm_init (void ) { +/* +* WAIT mode is broken on TO 1.0 and 1.1, so there is no point +* to run cpuidle on them. +*/ +if (imx6q_revision () >IMX_CHIP_REVISION_1_1 ) { + +/* Need to enable SCU standby for entering WAIT modes */ +imx_scu_standby_enable (); + +/* Set chicken bit to get a reliable WAIT mode support */ +imx6q_set_chicken_bit (); + +platform_device_register (&imx6q_cpuidle_device); + } +suspend_set_ops (&imx6q_pm_ops); }
Signature · 1 line
1.7.9.5
RFC PATCH 2/3 ARM: imx: cpuidle: Convert imx6q driver to platform_driver
Quoted 10 lines · Daniel Lezcano
arch/arm/mach-imx/pm-imx6q.c +8
-0+static struct platform_device imx6q_cpuidle_device = { + .name ="cpuidle-imx6q" , + .dev = { + .platform_data = imx6q_pm_idle, + }, +}; +void __init imx6q_pm_init (void ) { +/*
arch/arm/mach-imx/pm-imx6q.c static int imx6q_pm_enter(suspend_state_t state) · line 85
Quoted 10 lines
arch/arm/mach-imx/pm-imx6q.c +10
-0+* WAIT mode is broken on TO 1.0 and 1.1, so there is no point +* to run cpuidle on them. +*/ +if (imx6q_revision () >IMX_CHIP_REVISION_1_1 ) { + +/* Need to enable SCU standby for entering WAIT modes */ +imx_scu_standby_enable (); + +/* Set chicken bit to get a reliable WAIT mode support */ +imx6q_set_chicken_bit ();
So this is a behavior change. Before the patch, these two functions will not get called if CONFIG_CPU_IDLE is not enabled. We only want to call them when cpuidle driver is instantiated.
Shawn
Quoted 14 lines
arch/arm/mach-imx/pm-imx6q.c +4
-0+ +platform_device_register (&imx6q_cpuidle_device); + } +suspend_set_ops (&imx6q_pm_ops); }Signature · 7 lines
1.7.9.5 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
RFC PATCH 2/3 ARM: imx: cpuidle: Convert imx6q driver to platform_driver
Quoted 17 lines · Shawn Guo
Quoted 16 lines · Daniel Lezcano
arch/arm/mach-imx/pm-imx6q.c +14
-0+static struct platform_device imx6q_cpuidle_device = { + .name ="cpuidle-imx6q" , + .dev = { + .platform_data = imx6q_pm_idle, + }, +}; +void __init imx6q_pm_init (void ) { +/* +* WAIT mode is broken on TO 1.0 and 1.1, so there is no point +* to run cpuidle on them. +*/ +if (imx6q_revision () >IMX_CHIP_REVISION_1_1 ) { + +/* Need to enable SCU standby for entering WAIT modes */
Quoted 8 lines
arch/arm/mach-imx/pm-imx6q.c static int imx6q_pm_enter(suspend_state_t state) · line 85
Quoted 4 lines
arch/arm/mach-imx/pm-imx6q.c +4
-0+imx_scu_standby_enable (); + +/* Set chicken bit to get a reliable WAIT mode support */ +imx6q_set_chicken_bit ();So this is a behavior change. Before the patch, these two functions will not get called if
CONFIG_CPU_IDLEis not enabled. We only want to call them when cpuidle driver is instantiated.
Yep, I will look at changing that.
Thanks for the review !
-- Daniel
Quoted 15 lines
Quoted 14 lines
arch/arm/mach-imx/pm-imx6q.c +4
-1+ +platform_device_register (&imx6q_cpuidle_device); + } +suspend_set_ops (&imx6q_pm_ops); } --1.7.9.5
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 5 lines
<http://www.linaro.org/> Linaro.org ? Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
RFC PATCH 3/3 ARM: imx: cpuidle: Move the drivers to drivers/cpuidle
In reply to Daniel LezcanoFor the sake of consistency and in order to facilitate code consolidation across cpuidle drivers, moving them to the drivers/cpuidle directory is appreciable. The different drivers for at91, calxeda, big-little (tc2), kirkwood, ux500 and zynq are now in this directory.
As there is no more dependency between the low level pm code and the cpuidle backend driver we can safely move it to the directory the drivers belong to.
---
arch/arm/mach-imx/Makefile | 5 -----
drivers/cpuidle/Kconfig.arm | 14 ++++++++++++++
drivers/cpuidle/Makefile | 2 ++
.../mach-imx => drivers/cpuidle}/cpuidle-imx5.c | 0
.../mach-imx => drivers/cpuidle}/cpuidle-imx6q.c | 0
5 files changed, 16 insertions(+), 5 deletions(-)
rename {arch/arm/mach-imx => drivers/cpuidle}/cpuidle-imx5.c (100%)
rename {arch/arm/mach-imx => drivers/cpuidle}/cpuidle-imx6q.c (100%)arch/arm/mach-imx/Makefile +0 -5
@@ -27,11 +27,6 @@ obj-$(CONFIG_MXC_AVIC) += avic.o obj-$(CONFIG_MXC_USE_EPIT) += epit.o obj-$(CONFIG_MXC_DEBUG_BOARD) += 3ds_debugboard.o -ifeq ($(CONFIG_CPU_IDLE),y) -obj-$(CONFIG_SOC_IMX5) += cpuidle-imx5.o -obj-$(CONFIG_SOC_IMX6Q) += cpuidle-imx6q.o -endif - ifdef CONFIG_SND_IMX_SOC obj-y += ssi-fiq.o obj-y += ssi-fiq-ksym.o
drivers/cpuidle/Kconfig.arm +14 -0
@@ -44,3 +44,17 @@ config ARM_AT91_CPUIDLE depends on ARCH_AT91 help Select this to enable cpuidle for AT91 processors + +config ARM_IMX5_CPUIDLE + bool "Cpu Idle Driver for the IMX5 processors" + default y + depends on SOC_IMX5 + help + Select this to enable cpuidle for IMX5 processors + +config ARM_IMX6Q_CPUIDLE + bool "Cpu Idle Driver for the IMX6Q processors" + default y + depends on SOC_IMX6Q + help + Select this to enable cpuidle for IMX6Q processors
drivers/cpuidle/Makefile +2 -0
@@ -13,3 +13,5 @@ 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_ARM_IMX5_CPUIDLE) += cpuidle-imx5.o +obj-$(CONFIG_ARM_IMX6Q_CPUIDLE) += cpuidle-imx6q.o
drivers/cpuidle/cpuidle-imx5.c renamed from arch/arm/mach-imx/cpuidle-imx5.c +0 -0
drivers/cpuidle/cpuidle-imx6q.c renamed from arch/arm/mach-imx/cpuidle-imx6q.c +0 -0
Signature · 1 line
1.7.9.5
Sascha Hauer
maintainerRFC PATCH 3/3 ARM: imx: cpuidle: Move the drivers to drivers/cpuidle
Daniel,
Quoted 4 lines · Daniel Lezcano
drivers/cpuidle/Kconfig.arm +4
-0+ +config ARM_IMX5_CPUIDLE + bool "Cpu Idle Driver for the IMX5 processors" + default y
drivers/cpuidle/Kconfig.arm config ARM_AT91_CPUIDLE · line 60
Quoted 10 lines
drivers/cpuidle/Kconfig.arm +10
-0+ depends on SOC_IMX5 + help + Select this to enable cpuidle for IMX5 processors + +config ARM_IMX6Q_CPUIDLE + bool "Cpu Idle Driver for the IMX6Q processors" + default y + depends on SOC_IMX6Q + help + Select this to enable cpuidle for IMX6Q processors
I can't say much to this series except there's some whitespace damage here. Please resend this series with Cc: Shawn Guo <[email protected]>
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
RFC PATCH 3/3 ARM: imx: cpuidle: Move the drivers to drivers/cpuidle
Quoted 12 lines · Sascha Hauer
Daniel,
Quoted 9 lines · Daniel Lezcano
drivers/cpuidle/Kconfig.arm +9
-0+ +config ARM_IMX5_CPUIDLE + bool "Cpu Idle Driver for the IMX5 processors" + default y + depends on SOC_IMX5 + help + Select this to enable cpuidle for IMX5 processors + +config ARM_IMX6Q_CPUIDLE
Quoted 8 lines
drivers/cpuidle/Kconfig.arm config ARM_AT91_CPUIDLE · line 60
Quoted 5 lines
drivers/cpuidle/Kconfig.arm +5
-0+ bool "Cpu Idle Driver for the IMX6Q processors" + default y + depends on SOC_IMX6Q + help + Select this to enable cpuidle for IMX6Q processorsI can't say much to this series except there's some whitespace damage here. Please resend this series with Cc: Shawn Guo <[email protected]>
I like it in general. Will take a deep look and test it on hardware tomorrow.
Shawn
RFC PATCH 1/3 ARM: imx: cpuidle: Convert imx5 driver to platform driver
In reply to Daniel Lezcanoarch/arm/mach-imx/pm-imx5.c static void imx5_pm_idle(void) · line 155
Quoted 8 lines · Daniel Lezcano
arch/arm/mach-imx/pm-imx5.c +4
-0@@ -149,6 +149,13 @@ static void imx5_pm_idle(void)imx5_cpu_do_idle (); } +static struct platform_device imx5_cpuidle_pdev = { + .name ="cpuidle-imx5" , + .dev = { + .platform_data = imx5_pm_idle,
This is a little bit hackish and less future proof. We should probably create a data structure with the function hook as a field in it.
Shawn
Quoted 23 lines
arch/arm/mach-imx/pm-imx5.c +4
-1+ }, +}; +static int __init imx5_pm_common_init (void ) {int ret;@@ -166,7 +173,7 @@ static int __init imx5_pm_common_init(void)/* Set the registers to the default cpu idle state. */ mx5_cpu_lp_set (IMX5_DEFAULT_CPU_IDLE_STATE ); -return imx5_cpuidle_init (); +return platform_device_register (&imx5_cpuidle_pdev); }void __init imx5_pm_init (void )Signature · 7 lines
1.7.9.5 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
RFC PATCH 1/3 ARM: imx: cpuidle: Convert imx5 driver to platform driver
Quoted 5 lines · Shawn Guo
Quoted 4 lines · Daniel Lezcano
arch/arm/mach-imx/pm-imx5.c +0
-0@@ -149,6 +149,13 @@ static void imx5_pm_idle(void)imx5_cpu_do_idle (); }
Quoted 7 lines
arch/arm/mach-imx/pm-imx5.c static void imx5_pm_idle(void) · line 155
Quoted 4 lines
arch/arm/mach-imx/pm-imx5.c +4
-0+static struct platform_device imx5_cpuidle_pdev = { + .name ="cpuidle-imx5" , + .dev = { + .platform_data = imx5_pm_idle,This is a little bit hackish and less future proof. We should probably create a data structure with the function hook as a field in it.
Yeah, I agree that is what I was planning for the near future as soon as the driver is moved into the drivers/cpuidle directory. As the other drivers are following the same scheme I want to define a common ops structure to be shared across the different driver. But I need to have several drivers in the same place in order to define the different idle callback.
Is it acceptable we keep this for the moment as the other cpuidle driver like cpuidle-at91 and then consolidate with a structure with an additional patchset addressing several drivers at once ?
Quoted 24 lines
Quoted 23 lines
arch/arm/mach-imx/pm-imx5.c +4
-2+ }, +}; +static int __init imx5_pm_common_init (void ) {int ret;@@ -166,7 +173,7 @@ static int __init imx5_pm_common_init(void)/* Set the registers to the default cpu idle state. */ mx5_cpu_lp_set (IMX5_DEFAULT_CPU_IDLE_STATE ); -return imx5_cpuidle_init (); +return platform_device_register (&imx5_cpuidle_pdev); }void __init imx5_pm_init (void ) --1.7.9.5
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 5 lines
<http://www.linaro.org/> Linaro.org ? Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
RFC PATCH 1/3 ARM: imx: cpuidle: Convert imx5 driver to platform driver
Quoted 21 lines · Daniel Lezcano
Quoted 5 lines · Shawn Guo
Quoted 4 lines · Daniel Lezcano
arch/arm/mach-imx/pm-imx5.c +0
-0@@ -149,6 +149,13 @@ static void imx5_pm_idle(void)imx5_cpu_do_idle (); }Quoted 7 lines
arch/arm/mach-imx/pm-imx5.c static void imx5_pm_idle(void) · line 155
Quoted 4 lines
arch/arm/mach-imx/pm-imx5.c +4
-0+static struct platform_device imx5_cpuidle_pdev = { + .name ="cpuidle-imx5" , + .dev = { + .platform_data = imx5_pm_idle,This is a little bit hackish and less future proof. We should probably create a data structure with the function hook as a field in it.
Yeah, I agree that is what I was planning for the near future as soon as the driver is moved into the
drivers/cpuidledirectory. As the other drivers are following the same scheme I want to define a common ops structure to be shared across the different driver. But I need to have several drivers in the same place in order to define the different idle callback.
Quoted 3 lines
Is it acceptable we keep this for the moment as the other cpuidle driver like cpuidle-at91 and then consolidate with a structure with an additional patchset addressing several drivers at once ?
Okay.
Shawn