1 /*
2  *  CLPS711X CPU idle driver
3  *
4  *  Copyright (C) 2014 Alexander Shiyan <shc_work@mail.ru>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  */
11 
12 #include <linux/cpuidle.h>
13 #include <linux/err.h>
14 #include <linux/io.h>
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 
18 #define CLPS711X_CPUIDLE_NAME	"clps711x-cpuidle"
19 
20 static void __iomem *clps711x_halt;
21 
22 static int clps711x_cpuidle_halt(struct cpuidle_device *dev,
23 				 struct cpuidle_driver *drv, int index)
24 {
25 	writel(0xaa, clps711x_halt);
26 
27 	return index;
28 }
29 
30 static struct cpuidle_driver clps711x_idle_driver = {
31 	.name		= CLPS711X_CPUIDLE_NAME,
32 	.owner		= THIS_MODULE,
33 	.states[0]	= {
34 		.name		= "HALT",
35 		.desc		= "CLPS711X HALT",
36 		.enter		= clps711x_cpuidle_halt,
37 		.exit_latency	= 1,
38 	},
39 	.state_count	= 1,
40 };
41 
42 static int __init clps711x_cpuidle_probe(struct platform_device *pdev)
43 {
44 	struct resource *res;
45 
46 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
47 	clps711x_halt = devm_ioremap_resource(&pdev->dev, res);
48 	if (IS_ERR(clps711x_halt))
49 		return PTR_ERR(clps711x_halt);
50 
51 	return cpuidle_register(&clps711x_idle_driver, NULL);
52 }
53 
54 static struct platform_driver clps711x_cpuidle_driver = {
55 	.driver	= {
56 		.name	= CLPS711X_CPUIDLE_NAME,
57 	},
58 };
59 module_platform_driver_probe(clps711x_cpuidle_driver, clps711x_cpuidle_probe);
60 
61 MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
62 MODULE_DESCRIPTION("CLPS711X CPU idle driver");
63 MODULE_LICENSE("GPL");
64