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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
|
/*
* Copyright (c) 2013 Samsung Electronics Co., Ltd.
* http://www.samsung.com
* Sangkyu Kim(skwith.kim@samsung.com)
*
* 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_ppmu2.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;
}
static int ppmu_set_status(struct ppmu_info *ppmu,
struct ppmu_status *status,
unsigned int offset)
{
unsigned int flags = 0, tmp;
if (ppmu_get_check_null(ppmu))
return -EINVAL;
if (status == NULL) {
pr_err("DEVFREQ(PPMU) : status argument is NULL\n");
return -EINVAL;
}
if (status->ccnt == CNT_ENABLE)
flags |= (PMNC_MASK << CCNT_SHIFT);
if (status->pmcnt3 == CNT_ENABLE)
flags |= (PMNC_MASK << PMCNT3_SHIFT);
if (status->pmcnt2 == CNT_ENABLE)
flags |= (PMNC_MASK << PMCNT2_SHIFT);
if (status->pmcnt1 == CNT_ENABLE)
flags |= (PMNC_MASK << PMCNT1_SHIFT);
if (status->pmcnt0 == CNT_ENABLE)
flags |= (PMNC_MASK << PMCNT0_SHIFT);
tmp = __raw_readl(ppmu->base + offset);
tmp |= flags;
__raw_writel(tmp, ppmu->base + offset);
return 0;
}
static int ppmu_get_status(struct ppmu_info *ppmu,
struct ppmu_status *status,
unsigned int offset)
{
unsigned int tmp;
if (ppmu_get_check_null(ppmu))
return -EINVAL;
if (status == NULL) {
pr_err("DEVFREQ(PPMU) : status argument is NULL\n");
return -EINVAL;
}
tmp = __raw_readl(ppmu->base + offset);
status->ccnt = (tmp >> CCNT_SHIFT) & PMNC_MASK;
status->pmcnt3 = (tmp >> PMCNT3_SHIFT) & PMNC_MASK;
status->pmcnt2 = (tmp >> PMCNT2_SHIFT) & PMNC_MASK;
status->pmcnt1 = (tmp >> PMCNT1_SHIFT) & PMNC_MASK;
status->pmcnt0 = (tmp >> PMCNT0_SHIFT) & PMNC_MASK;
return 0;
}
static int ppmu_set_cnt(struct ppmu_info *ppmu,
unsigned int value,
unsigned int offset)
{
if (ppmu_get_check_null(ppmu))
return false;
__raw_writel(value, ppmu->base + offset);
return 0;
}
static int ppmu_get_cnt(struct ppmu_info *ppmu,
unsigned int *value,
unsigned int offset)
{
if (ppmu_get_check_null(ppmu))
return -EINVAL;
if (value == NULL) {
pr_err("DEVFREQ(PPMU) : cnt argument is NULL\n");
return -EINVAL;
}
*value = __raw_readl(ppmu->base + offset);
return 0;
}
static int ppmu_set_event(struct ppmu_info *ppmu,
enum EVENT_TYPE event,
unsigned int offset)
{
if (ppmu_get_check_null(ppmu))
return -EINVAL;
__raw_writel((event & EV_TYPE_MASK) << EV_TYPE_SHIFT, ppmu->base + offset);
return 0;
}
static int ppmu_get_event(struct ppmu_info *ppmu,
enum EVENT_TYPE *event,
unsigned int offset)
{
if (ppmu_get_check_null(ppmu))
return -EINVAL;
if (event == NULL) {
pr_err("DEVFREQ(PPMU) : get event argument is NULL\n");
return -EINVAL;
}
*event = (__raw_readl(ppmu->base + offset) & EV_TYPE_MASK) >> EV_TYPE_SHIFT;
return 0;
}
int ppmu_get_version(struct ppmu_info *ppmu,
struct ppmu_version *version)
{
unsigned int tmp;
if (ppmu_get_check_null(ppmu))
return -EINVAL;
tmp = __raw_readl(ppmu->base + REG_VER);
version->major = (tmp >> VER_MAJOR_SHIFT) & VER_MASK;
version->minor = (tmp >> VER_MINOR_SHIFT) & VER_MASK;
version->revision = (tmp >> VER_REV_SHIFT) & VER_MASK;
version->rtl = (tmp >> VER_RTL_SHIFT) & VER_MASK;
return 0;
}
int ppmu_set_mode(struct ppmu_info *ppmu,
struct ppmu_mode *mode)
{
unsigned int tmp;
if (ppmu_get_check_null(ppmu))
return -EINVAL;
if (mode == NULL) {
pr_err("DEVFREQ(PPMU) : set mode argument is NULL\n");
return -EINVAL;
}
tmp = __raw_readl(ppmu->base + REG_PMNC);
tmp &= ~((PMNC_MODE_OPERATION_MASK << PMNC_MODE_OPERATION_SHIFT) |
(PMNC_MODE_START_MASK << PMNC_MODE_START_SHIFT) |
(PMNC_MASK << PMNC_CCNT_DIVIDING_SHIFT) |
(PMNC_MASK << PMNC_CCNT_RESET_SHIFT) |
(PMNC_MASK << PMNC_CCNT_RESET_PMCNT_SHIFT) |
(PMNC_MASK << PMNC_GLB_CNT_EN_SHIFT));
tmp |= (((mode->operation_mode & PMNC_MODE_OPERATION_MASK) << PMNC_MODE_OPERATION_SHIFT) |
((mode->start_mode & PMNC_MODE_START_MASK) << PMNC_MODE_START_SHIFT) |
((mode->dividing_enable & PMNC_MASK) << PMNC_CCNT_DIVIDING_SHIFT) |
((mode->ccnt_reset & PMNC_MASK) << PMNC_CCNT_RESET_SHIFT) |
((mode->pmcnt_reset & PMNC_MASK) << PMNC_CCNT_RESET_PMCNT_SHIFT));
__raw_writel(tmp, ppmu->base + REG_PMNC);
tmp = __raw_readl(ppmu->base + REG_PMNC);
tmp &= ~((PMNC_MASK << PMNC_CCNT_RESET_SHIFT) |
(PMNC_MASK << PMNC_CCNT_RESET_PMCNT_SHIFT));
__raw_writel(tmp, ppmu->base + REG_PMNC);
tmp = __raw_readl(ppmu->base + REG_PMNC);
tmp |= ((mode->count_enable & PMNC_MASK) << PMNC_GLB_CNT_EN_SHIFT);
__raw_writel(tmp, ppmu->base + REG_PMNC);
return 0;
}
int ppmu_get_mode(struct ppmu_info *ppmu,
struct ppmu_mode *mode)
{
unsigned int tmp;
if (ppmu_get_check_null(ppmu))
return -EINVAL;
if (mode == NULL) {
pr_err("DEVFREQ(PPMU) : get mode argument is NULL\n");
return -EINVAL;
}
tmp = __raw_readl(ppmu->base + REG_PMNC);
mode->operation_mode = (tmp >> PMNC_MODE_OPERATION_SHIFT) & PMNC_MODE_OPERATION_MASK;
mode->start_mode = (tmp >> PMNC_MODE_START_SHIFT) & PMNC_MODE_START_MASK;
mode->dividing_enable = (tmp >> PMNC_CCNT_DIVIDING_SHIFT) & PMNC_MASK;
mode->ccnt_reset = (tmp >> PMNC_CCNT_RESET_SHIFT) & PMNC_MASK;
mode->pmcnt_reset = (tmp >> PMNC_CCNT_RESET_PMCNT_SHIFT) & PMNC_MASK;
mode->count_enable = (tmp >> PMNC_GLB_CNT_EN_SHIFT) & PMNC_MASK;
return 0;
}
int ppmu_counter_enable(struct ppmu_info *ppmu,
struct ppmu_status *status)
{
return ppmu_set_status(ppmu, status, REG_CNTENS);
}
int ppmu_counter_disable(struct ppmu_info *ppmu,
struct ppmu_status *status)
{
return ppmu_set_status(ppmu, status, REG_CNTENC);
}
int ppmu_get_counter_status(struct ppmu_info *ppmu,
struct ppmu_status *status)
{
return ppmu_get_status(ppmu, status, REG_CNTENS);
}
int ppmu_interrupt_enable(struct ppmu_info *ppmu,
struct ppmu_status *status)
{
return ppmu_set_status(ppmu, status, REG_INTENS);
}
int ppmu_interrupt_disable(struct ppmu_info *ppmu,
struct ppmu_status *status)
{
return ppmu_set_status(ppmu, status, REG_INTENS);
}
int ppmu_get_interrupt_status(struct ppmu_info *ppmu,
struct ppmu_status *status)
{
return ppmu_get_status(ppmu, status, REG_INTENS);
}
int ppmu_set_interrupt_flag(struct ppmu_info *ppmu,
struct ppmu_status *status)
{
return ppmu_set_status(ppmu, status, REG_FLAG);
}
int ppmu_get_interrupt_flag(struct ppmu_info *ppmu,
struct ppmu_status *status)
{
return ppmu_get_status(ppmu, status, REG_FLAG);
}
int ppmu_set_cig_info(struct ppmu_info *ppmu,
struct ppmu_cig_info *info)
{
unsigned int tmp = 0;
if (ppmu_get_check_null(ppmu))
return -EINVAL;
if (info == NULL) {
pr_err("DEVFREQ(PPMU) : set cig info argument is NULL\n");
return -EINVAL;
}
tmp = __raw_readl(ppmu->base + REG_CIG_CFG0);
tmp &= ~((CIG_CFG0_LOGIC_REL_MASK << CIG_CFG0_LOGIC_REL_UPPER_SHIFT) |
(CIG_CFG0_LOGIC_REL_MASK << CIG_CFG0_LOGIC_REL_LOWER_SHIFT) |
(CIG_CFG0_REPEAT_MASK << CIG_CFG0_REPEAT_UPPER_SHIFT) |
(CIG_CFG0_REPEAT_MASK << CIG_CFG0_REPEAT_LOWER_SHIFT) |
(CIG_CFG0_PMCNT_MASK << CIG_CFG0_PMCNT2_SHIFT) |
(CIG_CFG0_PMCNT_MASK << CIG_CFG0_PMCNT1_SHIFT) |
(CIG_CFG0_PMCNT_MASK << CIG_CFG0_PMCNT0_SHIFT));
tmp |= (((info->upper_use_pmcnt_all & CIG_CFG0_LOGIC_REL_MASK) << CIG_CFG0_LOGIC_REL_UPPER_SHIFT) |
((info->lower_use_pmcnt_all & CIG_CFG0_LOGIC_REL_MASK) << CIG_CFG0_LOGIC_REL_LOWER_SHIFT) |
((info->upper_repeat_count & CIG_CFG0_REPEAT_MASK) << CIG_CFG0_REPEAT_UPPER_SHIFT) |
((info->lower_repeat_count & CIG_CFG0_REPEAT_MASK) << CIG_CFG0_REPEAT_LOWER_SHIFT) |
((info->use_pmcnt2 & CIG_CFG0_PMCNT_MASK) << CIG_CFG0_PMCNT2_SHIFT) |
((info->use_pmcnt1 & CIG_CFG0_PMCNT_MASK) << CIG_CFG0_PMCNT1_SHIFT) |
((info->use_pmcnt0 & CIG_CFG0_PMCNT_MASK) << CIG_CFG0_PMCNT0_SHIFT));
__raw_writel(tmp, ppmu->base + REG_CIG_CFG0);
__raw_writel(info->lower_bound, ppmu->base + REG_CIG_CFG1);
__raw_writel(info->upper_bound, ppmu->base + REG_CIG_CFG2);
return 0;
}
int ppmu_get_cig_info(struct ppmu_info *ppmu,
struct ppmu_cig_info *info)
{
unsigned int tmp;
if (ppmu_get_check_null(ppmu))
return -EINVAL;
if (info == NULL) {
pr_err("DEVFREQ(PPMU) : get cig info argument is NULL\n");
return -EINVAL;
}
tmp = __raw_readl(ppmu->base + REG_CIG_CFG0);
info->upper_use_pmcnt_all = (tmp >> CIG_CFG0_LOGIC_REL_UPPER_SHIFT) & CIG_CFG0_LOGIC_REL_MASK;
info->lower_use_pmcnt_all = (tmp >> CIG_CFG0_LOGIC_REL_LOWER_SHIFT) & CIG_CFG0_LOGIC_REL_MASK;
info->upper_repeat_count = (tmp >> CIG_CFG0_REPEAT_UPPER_SHIFT) & CIG_CFG0_REPEAT_MASK;
info->lower_repeat_count = (tmp >> CIG_CFG0_REPEAT_LOWER_SHIFT) & CIG_CFG0_REPEAT_MASK;
info->use_pmcnt2 = (tmp >> CIG_CFG0_PMCNT2_SHIFT) & CIG_CFG0_PMCNT_MASK;
info->use_pmcnt1 = (tmp >> CIG_CFG0_PMCNT1_SHIFT) & CIG_CFG0_PMCNT_MASK;
info->use_pmcnt0 = (tmp >> CIG_CFG0_PMCNT0_SHIFT) & CIG_CFG0_PMCNT_MASK;
info->lower_bound = __raw_readl(ppmu->base + REG_CIG_CFG1);
info->upper_bound = __raw_readl(ppmu->base + REG_CIG_CFG2);
return 0;
}
int ppmu_set_cig_result(struct ppmu_info *ppmu,
struct ppmu_cig_result *result)
{
unsigned int tmp;
if (ppmu_get_check_null(ppmu))
return -EINVAL;
if (result == NULL) {
pr_err("DEVFREQ(PPMU) : set cig result argument is NULL\n");
return -EINVAL;
}
tmp = __raw_readl(ppmu->base + REG_CIG_RESULT);
tmp &= ~((CIG_RESULT_OOB_MASK << CIG_RESULT_OOB_UPPER_SHIFT) |
(CIG_RESULT_OOB_MASK << CIG_RESULT_OOB_LOWER_SHIFT));
tmp |= (((result->oob_upper_interrupt & CIG_RESULT_OOB_MASK) << CIG_RESULT_OOB_UPPER_SHIFT) |
((result->oob_lower_interrupt & CIG_RESULT_OOB_MASK) << CIG_RESULT_OOB_LOWER_SHIFT));
return 0;
}
int ppmu_get_cig_result(struct ppmu_info *ppmu,
struct ppmu_cig_result *result)
{
unsigned int tmp;
if (ppmu_get_check_null(ppmu))
return -EINVAL;
if (result == NULL) {
pr_err("DEVFREQ(PPMU) : get cig result argument is NULL\n");
return -EINVAL;
}
tmp = __raw_readl(ppmu->base + REG_CIG_RESULT);
result->recent_compare_upper_index = (tmp >> CIG_RESULT_RECENT_UPPER_SHIFT) & CIG_RESULT_RECENT_MASK;
result->recent_compare_lower_index = (tmp >> CIG_RESULT_RECENT_LOWER_SHIFT) & CIG_RESULT_RECENT_MASK;
result->oob_upper_interrupt = (tmp >> CIG_RESULT_OOB_UPPER_SHIFT) & CIG_RESULT_OOB_MASK;
result->oob_lower_interrupt = (tmp >> CIG_RESULT_OOB_LOWER_SHIFT) & CIG_RESULT_OOB_MASK;
return 0;
}
int ppmu_reset_counter(struct ppmu_info *ppmu,
struct ppmu_status *status)
{
unsigned int tmp = 0;
if (ppmu_get_check_null(ppmu))
return -EINVAL;
if (status == NULL) {
pr_err("DEVFREQ(PPMU) : reset counter argument is NULL\n");
return -EINVAL;
}
tmp |= (((status->ccnt & CNT_MASK) << CCNT_SHIFT) |
((status->pmcnt3 & CNT_MASK) << PMCNT3_SHIFT) |
((status->pmcnt2 & CNT_MASK) << PMCNT2_SHIFT) |
((status->pmcnt1 & CNT_MASK) << PMCNT1_SHIFT) |
((status->pmcnt0 & CNT_MASK) << PMCNT0_SHIFT));
__raw_writel(tmp, ppmu->base + REG_CNT_RESET);
return 0;
}
int ppmu_set_auto(struct ppmu_info *ppmu,
struct ppmu_status *status)
{
if (ppmu_get_check_null(ppmu))
return -EINVAL;
if (status == NULL) {
pr_err("DEVFREQ(PPMU) : set auto argument is NULL\n");
return -EINVAL;
}
return ppmu_set_status(ppmu, status, REG_CNT_AUTO);
}
int ppmu_set_pmcnt0(struct ppmu_info *ppmu,
unsigned int value)
{
return ppmu_set_cnt(ppmu, value, REG_PMCNT0);
}
int ppmu_get_pmcnt0(struct ppmu_info *ppmu,
unsigned int *value)
{
return ppmu_get_cnt(ppmu, value, REG_PMCNT0);
}
int ppmu_set_pmcnt1(struct ppmu_info *ppmu,
unsigned int value)
{
return ppmu_set_cnt(ppmu, value, REG_PMCNT1);
}
int ppmu_get_pmcnt1(struct ppmu_info *ppmu,
unsigned int *value)
{
return ppmu_get_cnt(ppmu, value, REG_PMCNT1);
}
int ppmu_set_pmcnt2(struct ppmu_info *ppmu,
unsigned int value)
{
return ppmu_set_cnt(ppmu, value, REG_PMCNT2);
}
int ppmu_get_pmcnt2(struct ppmu_info *ppmu,
unsigned int *value)
{
return ppmu_get_cnt(ppmu, value, REG_PMCNT2);
}
int ppmu_set_pmcnt3(struct ppmu_info *ppmu,
unsigned long long value)
{
if (ppmu_get_check_null(ppmu))
return -EINVAL;
__raw_writel((value & 0xFFFFFFFF), ppmu->base + REG_PMCNT3_LOW);
__raw_writel((value >> 32), ppmu->base + REG_PMCNT3_HIGH);
return 0;
}
int ppmu_get_pmcnt3(struct ppmu_info *ppmu,
unsigned long long *value)
{
if (ppmu_get_check_null(ppmu))
return -EINVAL;
if (value == NULL) {
pr_err("DEVFREQ(PPMU) : get pmcnt3 argument is NULL\n");
return -EINVAL;
}
*value = __raw_readl(ppmu->base + REG_PMCNT3_HIGH);
*value = *value << 32 | __raw_readl(ppmu->base + REG_PMCNT3_LOW);
return 0;
}
int ppmu_get_ccnt(struct ppmu_info *ppmu,
unsigned int *value)
{
return ppmu_get_cnt(ppmu, value, REG_CCNT);
}
int ppmu_set_event0(struct ppmu_info *ppmu,
enum EVENT_TYPE event)
{
if (event >= EV_RDWR_REQ_HS) {
pr_err("DEVFREQ(PPMU) : event0 do not support %d event\n", event);
return -EINVAL;
}
return ppmu_set_event(ppmu, event, REG_EV0_TYPE);
}
int ppmu_get_event0(struct ppmu_info *ppmu,
enum EVENT_TYPE *event)
{
return ppmu_get_event(ppmu, event, REG_EV0_TYPE);
}
int ppmu_set_event1(struct ppmu_info *ppmu,
enum EVENT_TYPE event)
{
if (event >= EV_RDWR_REQ_HS) {
pr_err("DEVFREQ(PPMU) : event1 do not support %d event\n", event);
return -EINVAL;
}
return ppmu_set_event(ppmu, event, REG_EV1_TYPE);
}
int ppmu_get_event1(struct ppmu_info *ppmu,
enum EVENT_TYPE *event)
{
return ppmu_get_event(ppmu, event, REG_EV1_TYPE);
}
int ppmu_set_event2(struct ppmu_info *ppmu,
enum EVENT_TYPE event)
{
if (event >= EV_RDWR_REQ_HS) {
pr_err("DEVFREQ(PPMU) : event2 do not support %d event\n", event);
return -EINVAL;
}
return ppmu_set_event(ppmu, event, REG_EV2_TYPE);
}
int ppmu_get_event2(struct ppmu_info *ppmu,
enum EVENT_TYPE *event)
{
return ppmu_get_event(ppmu, event, REG_EV2_TYPE);
}
int ppmu_set_event3(struct ppmu_info *ppmu,
enum EVENT_TYPE event)
{
return ppmu_set_event(ppmu, event, REG_EV3_TYPE);
}
int ppmu_get_event3(struct ppmu_info *ppmu,
enum EVENT_TYPE *event)
{
return ppmu_get_event(ppmu, event, REG_EV3_TYPE);
}
/*
* 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_reset(struct ppmu_info *ppmu)
{
int ret;
struct ppmu_mode mode;
struct ppmu_status status;
if (ppmu_get_check_null(ppmu))
return -EINVAL;
ret = ppmu_set_event0(ppmu, EV_RD_DATA_HS);
if (ret)
return ret;
ret = ppmu_set_event1(ppmu, EV_WR_DATA_HS);
if (ret)
return ret;
ret = ppmu_set_event3(ppmu, EV_RDWR_DATA_HS);
if (ret)
return ret;
status.ccnt = CNT_ENABLE;
status.pmcnt0 = CNT_ENABLE;
status.pmcnt1 = CNT_ENABLE;
status.pmcnt3 = CNT_ENABLE;
ret = ppmu_counter_enable(ppmu, &status);
if (ret)
return ret;
ret = ppmu_set_interrupt_flag(ppmu, &status);
if (ret)
return ret;
ret = ppmu_get_mode(ppmu, &mode);
if (ret)
return ret;
mode.ccnt_reset = CNT_ENABLE;
mode.pmcnt_reset = CNT_ENABLE;
mode.count_enable = CNT_ENABLE;
return ppmu_set_mode(ppmu, &mode);
}
int ppmu_disable(struct ppmu_info *ppmu)
{
struct ppmu_status status;
status.ccnt = CNT_ENABLE;
status.pmcnt3 = CNT_ENABLE;
status.pmcnt2 = CNT_ENABLE;
status.pmcnt1 = CNT_ENABLE;
status.pmcnt0 = CNT_ENABLE;
return ppmu_counter_disable(ppmu, &status);
}
int ppmu_reset_total(struct ppmu_info *ppmu,
unsigned int size)
{
unsigned int i;
for (i = 0; i < size; ++i) {
if (ppmu_reset(ppmu + i))
return -EINVAL;
}
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;
if (ppmu_get_check_null(ppmu))
return -EINVAL;
if (ppmu_get_ccnt(ppmu, &val_ccnt))
return -EINVAL;
if (ppmu_get_pmcnt0(ppmu, &val_pmcnt0))
return -EINVAL;
if (ppmu_get_pmcnt1(ppmu, &val_pmcnt1))
return -EINVAL;
if (ppmu_get_pmcnt3(ppmu, pmcnt3))
return -EINVAL;
*ccnt = val_ccnt;
*pmcnt0 = val_pmcnt0;
*pmcnt1 = val_pmcnt1;
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;
for (i = 0; i < size; ++i)
ppmu_disable(ppmu + i);
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)
{
unsigned int i;
for (i = 0; i < size; ++i)
__raw_writel(0x0, ppmu->base + REG_PMNC);
return 0;
}
|