Merge branch 'exec_rm_compat' of git://git.kernel.org/pub/scm/linux/kernel/git/oleg...
[pandora-kernel.git] / arch / mips / lantiq / xway / pmu.c
1 /*
2  *  This program is free software; you can redistribute it and/or modify it
3  *  under the terms of the GNU General Public License version 2 as published
4  *  by the Free Software Foundation.
5  *
6  *  Copyright (C) 2010 John Crispin <blogic@openwrt.org>
7  */
8
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/version.h>
12 #include <linux/ioport.h>
13
14 #include <lantiq_soc.h>
15
16 /* PMU - the power management unit allows us to turn part of the core
17  * on and off
18  */
19
20 /* the enable / disable registers */
21 #define LTQ_PMU_PWDCR   0x1C
22 #define LTQ_PMU_PWDSR   0x20
23
24 #define ltq_pmu_w32(x, y)       ltq_w32((x), ltq_pmu_membase + (y))
25 #define ltq_pmu_r32(x)          ltq_r32(ltq_pmu_membase + (x))
26
27 static struct resource ltq_pmu_resource = {
28         .name   = "pmu",
29         .start  = LTQ_PMU_BASE_ADDR,
30         .end    = LTQ_PMU_BASE_ADDR + LTQ_PMU_SIZE - 1,
31         .flags  = IORESOURCE_MEM,
32 };
33
34 static void __iomem *ltq_pmu_membase;
35
36 void ltq_pmu_enable(unsigned int module)
37 {
38         int err = 1000000;
39
40         ltq_pmu_w32(ltq_pmu_r32(LTQ_PMU_PWDCR) & ~module, LTQ_PMU_PWDCR);
41         do {} while (--err && (ltq_pmu_r32(LTQ_PMU_PWDSR) & module));
42
43         if (!err)
44                 panic("activating PMU module failed!\n");
45 }
46 EXPORT_SYMBOL(ltq_pmu_enable);
47
48 void ltq_pmu_disable(unsigned int module)
49 {
50         ltq_pmu_w32(ltq_pmu_r32(LTQ_PMU_PWDCR) | module, LTQ_PMU_PWDCR);
51 }
52 EXPORT_SYMBOL(ltq_pmu_disable);
53
54 int __init ltq_pmu_init(void)
55 {
56         if (insert_resource(&iomem_resource, &ltq_pmu_resource) < 0)
57                 panic("Failed to insert pmu memory\n");
58
59         if (request_mem_region(ltq_pmu_resource.start,
60                         resource_size(&ltq_pmu_resource), "pmu") < 0)
61                 panic("Failed to request pmu memory\n");
62
63         ltq_pmu_membase = ioremap_nocache(ltq_pmu_resource.start,
64                                 resource_size(&ltq_pmu_resource));
65         if (!ltq_pmu_membase)
66                 panic("Failed to remap pmu memory\n");
67         return 0;
68 }
69
70 core_initcall(ltq_pmu_init);