Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * CPU idle Marvell Kirkwood SoCs
0004  *
0005  * The cpu idle uses wait-for-interrupt and DDR self refresh in order
0006  * to implement two idle states -
0007  * #1 wait-for-interrupt
0008  * #2 wait-for-interrupt and DDR self refresh
0009  *
0010  * Maintainer: Jason Cooper <jason@lakedaemon.net>
0011  * Maintainer: Andrew Lunn <andrew@lunn.ch>
0012  */
0013 
0014 #include <linux/kernel.h>
0015 #include <linux/module.h>
0016 #include <linux/init.h>
0017 #include <linux/platform_device.h>
0018 #include <linux/cpuidle.h>
0019 #include <linux/io.h>
0020 #include <linux/export.h>
0021 #include <asm/cpuidle.h>
0022 
0023 #define KIRKWOOD_MAX_STATES 2
0024 
0025 static void __iomem *ddr_operation_base;
0026 
0027 /* Actual code that puts the SoC in different idle states */
0028 static int kirkwood_enter_idle(struct cpuidle_device *dev,
0029                    struct cpuidle_driver *drv,
0030                    int index)
0031 {
0032     writel(0x7, ddr_operation_base);
0033     cpu_do_idle();
0034 
0035     return index;
0036 }
0037 
0038 static struct cpuidle_driver kirkwood_idle_driver = {
0039     .name           = "kirkwood_idle",
0040     .owner          = THIS_MODULE,
0041     .states[0]      = ARM_CPUIDLE_WFI_STATE,
0042     .states[1]      = {
0043         .enter          = kirkwood_enter_idle,
0044         .exit_latency       = 10,
0045         .target_residency   = 100000,
0046         .name           = "DDR SR",
0047         .desc           = "WFI and DDR Self Refresh",
0048     },
0049     .state_count = KIRKWOOD_MAX_STATES,
0050 };
0051 
0052 /* Initialize CPU idle by registering the idle states */
0053 static int kirkwood_cpuidle_probe(struct platform_device *pdev)
0054 {
0055     ddr_operation_base = devm_platform_ioremap_resource(pdev, 0);
0056     if (IS_ERR(ddr_operation_base))
0057         return PTR_ERR(ddr_operation_base);
0058 
0059     return cpuidle_register(&kirkwood_idle_driver, NULL);
0060 }
0061 
0062 static int kirkwood_cpuidle_remove(struct platform_device *pdev)
0063 {
0064     cpuidle_unregister(&kirkwood_idle_driver);
0065     return 0;
0066 }
0067 
0068 static struct platform_driver kirkwood_cpuidle_driver = {
0069     .probe = kirkwood_cpuidle_probe,
0070     .remove = kirkwood_cpuidle_remove,
0071     .driver = {
0072            .name = "kirkwood_cpuidle",
0073            },
0074 };
0075 
0076 module_platform_driver(kirkwood_cpuidle_driver);
0077 
0078 MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>");
0079 MODULE_DESCRIPTION("Kirkwood cpu idle driver");
0080 MODULE_LICENSE("GPL v2");
0081 MODULE_ALIAS("platform:kirkwood-cpuidle");