summaryrefslogtreecommitdiff
path: root/arch/mips/lantiq/xway/pmu.c
blob: fe85361e032e1146887b9d7e183cc02819b3c1eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 *  This program is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License version 2 as published
 *  by the Free Software Foundation.
 *
 *  Copyright (C) 2010 John Crispin <blogic@openwrt.org>
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/ioport.h>

#include <lantiq_soc.h>

/* PMU - the power management unit allows us to turn part of the core
 * on and off
 */

/* the enable / disable registers */
#define LTQ_PMU_PWDCR	0x1C
#define LTQ_PMU_PWDSR	0x20

#define ltq_pmu_w32(x, y)	ltq_w32((x), ltq_pmu_membase + (y))
#define ltq_pmu_r32(x)		ltq_r32(ltq_pmu_membase + (x))

static struct resource ltq_pmu_resource = {
	.name	= "pmu",
	.start	= LTQ_PMU_BASE_ADDR,
	.end	= LTQ_PMU_BASE_ADDR + LTQ_PMU_SIZE - 1,
	.flags	= IORESOURCE_MEM,
};

static void __iomem *ltq_pmu_membase;

void ltq_pmu_enable(unsigned int module)
{
	int err = 1000000;

	ltq_pmu_w32(ltq_pmu_r32(LTQ_PMU_PWDCR) & ~module, LTQ_PMU_PWDCR);
	do {} while (--err && (ltq_pmu_r32(LTQ_PMU_PWDSR) & module));

	if (!err)
		panic("activating PMU module failed!");
}
EXPORT_SYMBOL(ltq_pmu_enable);

void ltq_pmu_disable(unsigned int module)
{
	ltq_pmu_w32(ltq_pmu_r32(LTQ_PMU_PWDCR) | module, LTQ_PMU_PWDCR);
}
EXPORT_SYMBOL(ltq_pmu_disable);

int __init ltq_pmu_init(void)
{
	if (insert_resource(&iomem_resource, &ltq_pmu_resource) < 0)
		panic("Failed to insert pmu memory");

	if (request_mem_region(ltq_pmu_resource.start,
			resource_size(&ltq_pmu_resource), "pmu") < 0)
		panic("Failed to request pmu memory");

	ltq_pmu_membase = ioremap_nocache(ltq_pmu_resource.start,
				resource_size(&ltq_pmu_resource));
	if (!ltq_pmu_membase)
		panic("Failed to remap pmu memory");
	return 0;
}

core_initcall(ltq_pmu_init);