summaryrefstree
path: root/kernel/drivers/devfreq/exynos_ppmu.c
blob: 68ece6ab088d19a78c7bdeba6b7cdb71eba6257f (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
70
71
72
/*
 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
 *		http://www.samsung.com/
 *
 * EXYNOS - PPMU support
 *
 * 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.
 */

#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/err.h>
#include <linux/io.h>

#include "exynos_ppmu.h"

/* For PPMU Control */
#define PPMU_ENABLE		BIT(0)
#define PPMU_DISABLE		0x0
#define PPMU_COUNTER_RESET	BIT(1)
#define PPMU_CYCLE_RESET	BIT(2)

#define PPMU_ENABLE_COUNT0	BIT(0)
#define PPMU_ENABLE_COUNT1	BIT(1)
#define PPMU_ENABLE_COUNT2	BIT(2)
#define PPMU_ENABLE_COUNT3	BIT(3)
#define PPMU_ENABLE_CYCLE	BIT(31)

void exynos_ppmu_reset(void __iomem *ppmu_base)
{
	unsigned int cntens = PPMU_ENABLE_CYCLE | PPMU_ENABLE_COUNT0 |
				PPMU_ENABLE_COUNT1 | PPMU_ENABLE_COUNT2 |
				PPMU_ENABLE_COUNT3;

	__raw_writel(PPMU_CYCLE_RESET | PPMU_COUNTER_RESET, ppmu_base);
	__raw_writel(cntens, ppmu_base + PPMU_CNTENS);
	__raw_writel(cntens, ppmu_base + PPMU_FLAG);
	__raw_writel(0x0, ppmu_base + PPMU_CCNT);
}

void exynos_ppmu_setevent(void __iomem *ppmu_base,
			  unsigned int ch,
			  unsigned int evt)
{
	__raw_writel(evt, ppmu_base + PPMU_BEVTSEL(ch));
}

void exynos_ppmu_start(void __iomem *ppmu_base)
{
	__raw_writel(PPMU_ENABLE, ppmu_base);
}

void exynos_ppmu_stop(void __iomem *ppmu_base)
{
	__raw_writel(PPMU_DISABLE, ppmu_base);
}

unsigned int exynos_ppmu_read(void __iomem *ppmu_base,
			      unsigned int ch)
{
	unsigned int total;

	if (ch == PPMU_PMNCNT3)
		total = ((__raw_readl(ppmu_base + PMCNT_OFFSET(ch)) << 8) |
			  __raw_readl(ppmu_base + PMCNT_OFFSET(ch + 1)));
	else
		total = __raw_readl(ppmu_base + PMCNT_OFFSET(ch));

	return total;
}