xref: /linux/drivers/cpuidle/cpuidle-kirkwood.c (revision 488540bf41ce8ccfe8b54c646c3ea67a7196edcd)
19cfc94ebSAndrew Lunn /*
29cfc94ebSAndrew Lunn  * arch/arm/mach-kirkwood/cpuidle.c
39cfc94ebSAndrew Lunn  *
49cfc94ebSAndrew Lunn  * CPU idle Marvell Kirkwood SoCs
59cfc94ebSAndrew Lunn  *
69cfc94ebSAndrew Lunn  * This file is licensed under the terms of the GNU General Public
79cfc94ebSAndrew Lunn  * License version 2.  This program is licensed "as is" without any
89cfc94ebSAndrew Lunn  * warranty of any kind, whether express or implied.
99cfc94ebSAndrew Lunn  *
109cfc94ebSAndrew Lunn  * The cpu idle uses wait-for-interrupt and DDR self refresh in order
119cfc94ebSAndrew Lunn  * to implement two idle states -
129cfc94ebSAndrew Lunn  * #1 wait-for-interrupt
139cfc94ebSAndrew Lunn  * #2 wait-for-interrupt and DDR self refresh
149cfc94ebSAndrew Lunn  */
159cfc94ebSAndrew Lunn 
169cfc94ebSAndrew Lunn #include <linux/kernel.h>
179cfc94ebSAndrew Lunn #include <linux/module.h>
189cfc94ebSAndrew Lunn #include <linux/init.h>
199cfc94ebSAndrew Lunn #include <linux/platform_device.h>
209cfc94ebSAndrew Lunn #include <linux/cpuidle.h>
219cfc94ebSAndrew Lunn #include <linux/io.h>
229cfc94ebSAndrew Lunn #include <linux/export.h>
239cfc94ebSAndrew Lunn #include <asm/proc-fns.h>
249cfc94ebSAndrew Lunn #include <asm/cpuidle.h>
259cfc94ebSAndrew Lunn 
269cfc94ebSAndrew Lunn #define KIRKWOOD_MAX_STATES	2
279cfc94ebSAndrew Lunn 
289cfc94ebSAndrew Lunn static void __iomem *ddr_operation_base;
299cfc94ebSAndrew Lunn 
309cfc94ebSAndrew Lunn /* Actual code that puts the SoC in different idle states */
319cfc94ebSAndrew Lunn static int kirkwood_enter_idle(struct cpuidle_device *dev,
329cfc94ebSAndrew Lunn 			       struct cpuidle_driver *drv,
339cfc94ebSAndrew Lunn 			       int index)
349cfc94ebSAndrew Lunn {
359cfc94ebSAndrew Lunn 	writel(0x7, ddr_operation_base);
369cfc94ebSAndrew Lunn 	cpu_do_idle();
379cfc94ebSAndrew Lunn 
389cfc94ebSAndrew Lunn 	return index;
399cfc94ebSAndrew Lunn }
409cfc94ebSAndrew Lunn 
419cfc94ebSAndrew Lunn static struct cpuidle_driver kirkwood_idle_driver = {
429cfc94ebSAndrew Lunn 	.name			= "kirkwood_idle",
439cfc94ebSAndrew Lunn 	.owner			= THIS_MODULE,
449cfc94ebSAndrew Lunn 	.en_core_tk_irqen	= 1,
459cfc94ebSAndrew Lunn 	.states[0]		= ARM_CPUIDLE_WFI_STATE,
469cfc94ebSAndrew Lunn 	.states[1]		= {
479cfc94ebSAndrew Lunn 		.enter			= kirkwood_enter_idle,
489cfc94ebSAndrew Lunn 		.exit_latency		= 10,
499cfc94ebSAndrew Lunn 		.target_residency	= 100000,
509cfc94ebSAndrew Lunn 		.flags			= CPUIDLE_FLAG_TIME_VALID,
519cfc94ebSAndrew Lunn 		.name			= "DDR SR",
529cfc94ebSAndrew Lunn 		.desc			= "WFI and DDR Self Refresh",
539cfc94ebSAndrew Lunn 	},
549cfc94ebSAndrew Lunn 	.state_count = KIRKWOOD_MAX_STATES,
559cfc94ebSAndrew Lunn };
569cfc94ebSAndrew Lunn static struct cpuidle_device *device;
579cfc94ebSAndrew Lunn 
589cfc94ebSAndrew Lunn static DEFINE_PER_CPU(struct cpuidle_device, kirkwood_cpuidle_device);
599cfc94ebSAndrew Lunn 
609cfc94ebSAndrew Lunn /* Initialize CPU idle by registering the idle states */
619cfc94ebSAndrew Lunn static int kirkwood_cpuidle_probe(struct platform_device *pdev)
629cfc94ebSAndrew Lunn {
639cfc94ebSAndrew Lunn 	struct resource *res;
649cfc94ebSAndrew Lunn 
659cfc94ebSAndrew Lunn 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
669cfc94ebSAndrew Lunn 	if (res == NULL)
679cfc94ebSAndrew Lunn 		return -EINVAL;
689cfc94ebSAndrew Lunn 
69*488540bfSSilviu-Mihai Popescu 	ddr_operation_base = devm_ioremap_resource(&pdev->dev, res);
70*488540bfSSilviu-Mihai Popescu 	if (IS_ERR(ddr_operation_base))
71*488540bfSSilviu-Mihai Popescu 		return PTR_ERR(ddr_operation_base);
729cfc94ebSAndrew Lunn 
739cfc94ebSAndrew Lunn 	device = &per_cpu(kirkwood_cpuidle_device, smp_processor_id());
749cfc94ebSAndrew Lunn 	device->state_count = KIRKWOOD_MAX_STATES;
759cfc94ebSAndrew Lunn 
769cfc94ebSAndrew Lunn 	cpuidle_register_driver(&kirkwood_idle_driver);
779cfc94ebSAndrew Lunn 	if (cpuidle_register_device(device)) {
789cfc94ebSAndrew Lunn 		pr_err("kirkwood_init_cpuidle: Failed registering\n");
799cfc94ebSAndrew Lunn 		return -EIO;
809cfc94ebSAndrew Lunn 	}
819cfc94ebSAndrew Lunn 	return 0;
829cfc94ebSAndrew Lunn }
839cfc94ebSAndrew Lunn 
849cfc94ebSAndrew Lunn int kirkwood_cpuidle_remove(struct platform_device *pdev)
859cfc94ebSAndrew Lunn {
869cfc94ebSAndrew Lunn 	cpuidle_unregister_device(device);
879cfc94ebSAndrew Lunn 	cpuidle_unregister_driver(&kirkwood_idle_driver);
889cfc94ebSAndrew Lunn 
899cfc94ebSAndrew Lunn 	return 0;
909cfc94ebSAndrew Lunn }
919cfc94ebSAndrew Lunn 
929cfc94ebSAndrew Lunn static struct platform_driver kirkwood_cpuidle_driver = {
939cfc94ebSAndrew Lunn 	.probe = kirkwood_cpuidle_probe,
949cfc94ebSAndrew Lunn 	.remove = kirkwood_cpuidle_remove,
959cfc94ebSAndrew Lunn 	.driver = {
969cfc94ebSAndrew Lunn 		   .name = "kirkwood_cpuidle",
979cfc94ebSAndrew Lunn 		   .owner = THIS_MODULE,
989cfc94ebSAndrew Lunn 		   },
999cfc94ebSAndrew Lunn };
1009cfc94ebSAndrew Lunn 
1019cfc94ebSAndrew Lunn module_platform_driver(kirkwood_cpuidle_driver);
1029cfc94ebSAndrew Lunn 
1039cfc94ebSAndrew Lunn MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>");
1049cfc94ebSAndrew Lunn MODULE_DESCRIPTION("Kirkwood cpu idle driver");
1059cfc94ebSAndrew Lunn MODULE_LICENSE("GPL v2");
1069cfc94ebSAndrew Lunn MODULE_ALIAS("platform:kirkwood-cpuidle");
107