arm64: configs: synchronize with other 3399 config for 3399 linux
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rockchip / cpuidle.c
1 /*
2  * Copyright (C) 2012-2014 ROCKCHIP, Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
8
9 #include <linux/cpuidle.h>
10 #include <linux/export.h>
11 #include <linux/suspend.h>
12 #include <linux/err.h>
13 #include <linux/irqchip/arm-gic.h>
14 #include <asm/cpuidle.h>
15 #include <asm/cputype.h>
16 #include <asm/io.h>
17 #include <linux/of.h>
18 #include <linux/of_address.h>
19 #include <linux/rockchip/cpu.h>
20
21 static void __iomem *gic_cpu_base;
22
23 static int rockchip_ca9_cpuidle_enter(struct cpuidle_device *dev,
24                 struct cpuidle_driver *drv, int index)
25 {
26         do {
27                 cpu_do_idle();
28         } while (readl_relaxed(gic_cpu_base + GIC_CPU_HIGHPRI) == 0x3FF);
29         return 0;
30 }
31
32 static struct cpuidle_driver rockchip_ca9_cpuidle_driver = {
33         .name = "rockchip_ca9_cpuidle",
34         .owner = THIS_MODULE,
35         .states[0] = ARM_CPUIDLE_WFI_STATE,
36         .state_count = 1,
37 };
38
39 static int __init rockchip_ca9_cpuidle_init(void)
40 {
41         struct device_node *np;
42         int ret;
43
44         if (!cpu_is_rockchip())
45                 return -ENODEV;
46         if (read_cpuid_part() != ARM_CPU_PART_CORTEX_A9)
47                 return -ENODEV;
48         np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic");
49         if (!np)
50                 return -ENODEV;
51         gic_cpu_base = of_iomap(np, 1);
52         if (!gic_cpu_base) {
53                 pr_err("%s: failed to map gic cpu registers\n", __func__);
54                 return -EINVAL;
55         }
56         rockchip_ca9_cpuidle_driver.states[0].enter = rockchip_ca9_cpuidle_enter;
57         ret = cpuidle_register(&rockchip_ca9_cpuidle_driver, NULL);
58         if (ret)
59                 pr_err("%s: failed to register cpuidle driver: %d\n", __func__, ret);
60
61         return ret;
62 }
63
64 device_initcall(rockchip_ca9_cpuidle_init);