13bb16560SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
29cfc94ebSAndrew Lunn /*
39cfc94ebSAndrew Lunn * CPU idle Marvell Kirkwood SoCs
49cfc94ebSAndrew Lunn *
59cfc94ebSAndrew Lunn * The cpu idle uses wait-for-interrupt and DDR self refresh in order
69cfc94ebSAndrew Lunn * to implement two idle states -
79cfc94ebSAndrew Lunn * #1 wait-for-interrupt
89cfc94ebSAndrew Lunn * #2 wait-for-interrupt and DDR self refresh
9a8e39c35SDaniel Lezcano *
10a8e39c35SDaniel Lezcano * Maintainer: Jason Cooper <jason@lakedaemon.net>
11a8e39c35SDaniel Lezcano * Maintainer: Andrew Lunn <andrew@lunn.ch>
129cfc94ebSAndrew Lunn */
139cfc94ebSAndrew Lunn
149cfc94ebSAndrew Lunn #include <linux/kernel.h>
159cfc94ebSAndrew Lunn #include <linux/module.h>
169cfc94ebSAndrew Lunn #include <linux/init.h>
179cfc94ebSAndrew Lunn #include <linux/platform_device.h>
189cfc94ebSAndrew Lunn #include <linux/cpuidle.h>
199cfc94ebSAndrew Lunn #include <linux/io.h>
209cfc94ebSAndrew Lunn #include <linux/export.h>
219cfc94ebSAndrew Lunn #include <asm/cpuidle.h>
229cfc94ebSAndrew Lunn
239cfc94ebSAndrew Lunn #define KIRKWOOD_MAX_STATES 2
249cfc94ebSAndrew Lunn
259cfc94ebSAndrew Lunn static void __iomem *ddr_operation_base;
269cfc94ebSAndrew Lunn
279cfc94ebSAndrew Lunn /* Actual code that puts the SoC in different idle states */
kirkwood_enter_idle(struct cpuidle_device * dev,struct cpuidle_driver * drv,int index)289cfc94ebSAndrew Lunn static int kirkwood_enter_idle(struct cpuidle_device *dev,
299cfc94ebSAndrew Lunn struct cpuidle_driver *drv,
309cfc94ebSAndrew Lunn int index)
319cfc94ebSAndrew Lunn {
329cfc94ebSAndrew Lunn writel(0x7, ddr_operation_base);
339cfc94ebSAndrew Lunn cpu_do_idle();
349cfc94ebSAndrew Lunn
359cfc94ebSAndrew Lunn return index;
369cfc94ebSAndrew Lunn }
379cfc94ebSAndrew Lunn
389cfc94ebSAndrew Lunn static struct cpuidle_driver kirkwood_idle_driver = {
399cfc94ebSAndrew Lunn .name = "kirkwood_idle",
409cfc94ebSAndrew Lunn .owner = THIS_MODULE,
419cfc94ebSAndrew Lunn .states[0] = ARM_CPUIDLE_WFI_STATE,
429cfc94ebSAndrew Lunn .states[1] = {
439cfc94ebSAndrew Lunn .enter = kirkwood_enter_idle,
449cfc94ebSAndrew Lunn .exit_latency = 10,
459cfc94ebSAndrew Lunn .target_residency = 100000,
469cfc94ebSAndrew Lunn .name = "DDR SR",
479cfc94ebSAndrew Lunn .desc = "WFI and DDR Self Refresh",
489cfc94ebSAndrew Lunn },
499cfc94ebSAndrew Lunn .state_count = KIRKWOOD_MAX_STATES,
509cfc94ebSAndrew Lunn };
519cfc94ebSAndrew Lunn
529cfc94ebSAndrew Lunn /* Initialize CPU idle by registering the idle states */
kirkwood_cpuidle_probe(struct platform_device * pdev)539cfc94ebSAndrew Lunn static int kirkwood_cpuidle_probe(struct platform_device *pdev)
549cfc94ebSAndrew Lunn {
5585c3ebd4SYangtao Li ddr_operation_base = devm_platform_ioremap_resource(pdev, 0);
56488540bfSSilviu-Mihai Popescu if (IS_ERR(ddr_operation_base))
57488540bfSSilviu-Mihai Popescu return PTR_ERR(ddr_operation_base);
589cfc94ebSAndrew Lunn
5930dc72c6SDaniel Lezcano return cpuidle_register(&kirkwood_idle_driver, NULL);
609cfc94ebSAndrew Lunn }
619cfc94ebSAndrew Lunn
kirkwood_cpuidle_remove(struct platform_device * pdev)62*f9059eb5SYangtao Li static void kirkwood_cpuidle_remove(struct platform_device *pdev)
639cfc94ebSAndrew Lunn {
6430dc72c6SDaniel Lezcano cpuidle_unregister(&kirkwood_idle_driver);
659cfc94ebSAndrew Lunn }
669cfc94ebSAndrew Lunn
679cfc94ebSAndrew Lunn static struct platform_driver kirkwood_cpuidle_driver = {
689cfc94ebSAndrew Lunn .probe = kirkwood_cpuidle_probe,
69*f9059eb5SYangtao Li .remove_new = kirkwood_cpuidle_remove,
709cfc94ebSAndrew Lunn .driver = {
719cfc94ebSAndrew Lunn .name = "kirkwood_cpuidle",
729cfc94ebSAndrew Lunn },
739cfc94ebSAndrew Lunn };
749cfc94ebSAndrew Lunn
759cfc94ebSAndrew Lunn module_platform_driver(kirkwood_cpuidle_driver);
769cfc94ebSAndrew Lunn
779cfc94ebSAndrew Lunn MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>");
789cfc94ebSAndrew Lunn MODULE_DESCRIPTION("Kirkwood cpu idle driver");
799cfc94ebSAndrew Lunn MODULE_LICENSE("GPL v2");
809cfc94ebSAndrew Lunn MODULE_ALIAS("platform:kirkwood-cpuidle");
81