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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/* drivers/devfreq/exynos_ppmu_fw.c
*
* Copyright (c) 2014 Samsung Electronics Co., Ltd.
* http://www.samsung.com/
*
* EXYNOS - PPMU control with firmware code.
*
* 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/errno.h>
#include <linux/printk.h>
#include "exynos_ppmu_fw.h"
#include "FW_exynos_ppmu.h"
static int ppmu_get_check_null(struct ppmu_info *ppmu)
{
if (ppmu == NULL) {
pr_err("DEVFREQ(PPMU) : ppmu has not address\n");
return -EINVAL;
}
return 0;
}
/*
* Helper Function
*/
int ppmu_init(struct ppmu_info *ppmu)
{
if (ppmu_get_check_null(ppmu))
return -EINVAL;
if (ppmu->base == NULL) {
pr_err("DEVFREQ(PPMU) : ppmu base address is null\n");
return -EINVAL;
}
ppmu->base = ioremap((unsigned long)ppmu->base, SZ_1K);
if (ppmu->base == NULL) {
pr_err("DEVFREQ(PPMU) : ppmu base remap failed\n");
return -EINVAL;
}
return 0;
}
int ppmu_term(struct ppmu_info *ppmu)
{
if (ppmu_get_check_null(ppmu))
return -EINVAL;
iounmap(ppmu->base);
return 0;
}
int ppmu_init_fw(struct ppmu_info *ppmu)
{
PPMU_Init(ppmu->base);
PPMU_SetEvent(ppmu->base,
PPMU2_EVENT_RD_DATA,
PPMU2_EVENT_WR_DATA,
0,
PPMU2_EVENT3_RW_DATA);
return 0;
}
int ppmu_reset(struct ppmu_info *ppmu)
{
if (ppmu_get_check_null(ppmu))
return -EINVAL;
PPMU_Start(ppmu->base, PPMU_MODE_MANUAL);
return 0;
}
int ppmu_disable(struct ppmu_info *ppmu)
{
PPMU_DeInit(ppmu->base);
return 0;
}
int ppmu_reset_total(struct ppmu_info *ppmu,
unsigned int size)
{
unsigned int i;
for (i = 0; i < size; ++i) {
PPMU_Reset((ppmu+i)->base);
PPMU_Start((ppmu+i)->base, PPMU_MODE_MANUAL);
}
return 0;
}
int ppmu_count(struct ppmu_info *ppmu,
unsigned long long *ccnt,
unsigned long long *pmcnt0,
unsigned long long *pmcnt1,
unsigned long long *pmcnt3)
{
unsigned int val_ccnt;
unsigned int val_pmcnt0;
unsigned int val_pmcnt1;
unsigned int val_pmcnt2;
unsigned long long val_pmcnt3;
if (ppmu_get_check_null(ppmu))
return -EINVAL;
PPMU_GetResult(ppmu->base,
&val_ccnt,
&val_pmcnt0,
&val_pmcnt1,
&val_pmcnt2,
&val_pmcnt3);
*ccnt = val_ccnt;
*pmcnt0 = val_pmcnt0;
*pmcnt1 = val_pmcnt1;
*pmcnt3 = val_pmcnt3;
return 0;
}
int ppmu_count_total(struct ppmu_info *ppmu,
unsigned int size,
pfn_ppmu_count pfn_count,
unsigned long long *ccnt,
unsigned long long *pmcnt)
{
unsigned int i;
unsigned long long val_ccnt = 0;
unsigned long long val_pmcnt0 = 0;
unsigned long long val_pmcnt1 = 0;
unsigned long long val_pmcnt3 = 0;
if (ccnt == NULL ||
pmcnt == NULL) {
pr_err("DEVFREQ(PPMU) : count argument is NULL\n");
return -EINVAL;
}
*ccnt = 0;
*pmcnt = 0;
if (pfn_count != NULL) {
return pfn_count(ppmu, size, ccnt, pmcnt);
} else {
for (i = 0; i < size; ++i) {
if (ppmu_count(ppmu + i, &val_ccnt, &val_pmcnt0, &val_pmcnt1, &val_pmcnt3))
return -EINVAL;
if (*ccnt < val_ccnt)
*ccnt = val_ccnt;
*pmcnt += val_pmcnt3;
}
}
return 0;
}
int ppmu_count_stop(struct ppmu_info *ppmu, unsigned int size)
{
int i;
for (i = 0; i < size; ++i)
PPMU_Stop((ppmu+i)->base);
return 0;
}
|