aboutsummaryrefslogtreecommitdiff
path: root/drivers/cpufreq/arm-bl-cpufreq_driver.c
blob: 75aaa4498aa6eda49fe090f12f65d6f147f3449d (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
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
/*
 * arm-bl-cpufreq.c: Simple cpufreq backend for the ARM big.LITTLE switcher
 * Copyright (C) 2012  Linaro Limited
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/* WARNING: This code is experimental and depends on external firmware */

#define MODULE_NAME "arm-bl-cpufreq"
#define pr_fmt(fmt) MODULE_NAME ": " fmt

#include <linux/bug.h>
#include <linux/cache.h>
#include <linux/cpufreq.h>
#include <linux/cpumask.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/printk.h>
#include <linux/string.h>
#include <linux/spinlock.h>

#ifdef CONFIG_ARM_BL_CPUFREQ_TEST
#include <linux/delay.h>
#include <linux/sched.h>
#endif

#include "arm-bl-cpufreq.h"

/* Dummy frequencies representing the big and little clusters: */
#define FREQ_BIG	1000000
#define FREQ_LITTLE	 100000

/*  Cluster numbers */
#define CLUSTER_BIG	0
#define CLUSTER_LITTLE	1

/*
 * Switch latency advertised to cpufreq.  This value is bogus and will
 * need to be properly calibrated when running on real hardware.
 */
#define BL_CPUFREQ_FAKE_LATENCY 1

static int pre_init_tests(void);
static int post_init_tests(void);
static short int test_config = 1;

static DEFINE_SPINLOCK(switcher_lock);

static struct cpufreq_frequency_table __read_mostly bl_freqs[] = {
	{ CLUSTER_BIG,		FREQ_BIG		},
	{ CLUSTER_LITTLE,	FREQ_LITTLE		},
	{ 0,			CPUFREQ_TABLE_END	},
};


/* Miscellaneous helpers */

static unsigned int entry_to_freq(
	struct cpufreq_frequency_table const *entry)
{
	return entry->frequency;
}

static unsigned int entry_to_cluster(
	struct cpufreq_frequency_table const *entry)
{
	return entry->index;
}

static struct cpufreq_frequency_table const *find_entry_by_cluster(int cluster)
{
	unsigned int i;

	for(i = 0; entry_to_freq(&bl_freqs[i]) != CPUFREQ_TABLE_END; i++)
		if(entry_to_cluster(&bl_freqs[i]) == cluster)
			return &bl_freqs[i];

	WARN(1, pr_fmt("%s(): invalid cluster number %d, assuming 0\n"),
		__func__, cluster);
	return &bl_freqs[0];
}

static unsigned int cluster_to_freq(int cluster)
{
	return entry_to_freq(find_entry_by_cluster(cluster));
}

/*
 * Functions to get the current status.
 *
 * If you intend to use the result (i.e., it's not just for diagnostic
 * purposes) then you should be holding switcher_lock ... otherwise
 * the current cluster may change unexpectedly.
 */
static int get_current_cluster(void)
{
	return (__arm_bl_get_cluster() >> 8) & 0xF;
}

static unsigned int get_current_freq(void)
{
	return cluster_to_freq(get_current_cluster());
}

/*
 * Switch to the requested cluster.
 * There is no "switch_to_frequency" function, because the cpufreq frequency
 * table helpers can easily look up the appropriate cluster number for us.
 */
static void switch_to_entry(struct cpufreq_frequency_table const *target)
{
	int old_cluster;
	struct cpufreq_freqs freqs;

	pr_info("Switching to cluster %d\n", entry_to_cluster(target));

	spin_lock(&switcher_lock);

	old_cluster = get_current_cluster();
	if(entry_to_cluster(target) != old_cluster) {
		freqs.old = cluster_to_freq(old_cluster);
		freqs.new = entry_to_freq(target);

		for_each_cpu(freqs.cpu, cpu_present_mask)
			cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);

		__arm_bl_switch_cluster();

		for_each_cpu(freqs.cpu, cpu_present_mask)
			cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);

	}

	spin_unlock(&switcher_lock);
}


/* Cpufreq methods and module code */

static int bl_cpufreq_init(struct cpufreq_policy *policy)
{
	int err;

	/*
	 * Set CPU and policy min and max frequencies based on bl_freqs:
	 */
	err = cpufreq_frequency_table_cpuinfo(policy, bl_freqs);
	if (err)
		goto error;

	/*
	 *Populate frequency table needed by Interactive governor policy.
	 */
	cpufreq_frequency_table_get_attr(bl_freqs,policy->cpu);

	/*
	 * No need for locking here:
	 * cpufreq is not active until initialisation has finished.
	 * Ideally, transition_latency should be calibrated here.
	 */
	policy->cpuinfo.transition_latency = BL_CPUFREQ_FAKE_LATENCY;
	policy->cur = get_current_freq();

	/*
	 * A b.L switch can be triggered from any CPU, but will affect them all.
	 * The set of related CPUs should perhaps be determined from the
	 * system CPU topology, rather than just the set of CPUs present...
	 */
	policy->shared_type = CPUFREQ_SHARED_TYPE_ANY;
	cpumask_copy(policy->related_cpus, cpu_present_mask);
	/*
	 * We do not set ->cpus here, because it doesn't actually matter if
	 * we try to switch on two CPUs at the same time.  Setting ->cpus
	 * to cpu_present_mask might provide a way to avoid the need to take
	 * switcher_lock when switching, though.
	 */

	pr_info("cpufreq initialised successfully\n");
	return 0;

error:
	pr_warning("cpufreq initialisation failed (%d)\n", err);
	return err;
}

static int bl_cpufreq_verify(struct cpufreq_policy *policy)
{
	return cpufreq_frequency_table_verify(policy, bl_freqs);
}

static int bl_cpufreq_target(struct cpufreq_policy *policy,
			     unsigned int target_freq,
			     unsigned int relation)
{
	int err;
	int index;

	err = cpufreq_frequency_table_target(policy, bl_freqs, target_freq,
					     relation, &index);
	if(err)
		return err;

	switch_to_entry(&bl_freqs[index]);
	return 0;
}

static unsigned int bl_cpufreq_get(unsigned int __always_unused cpu)
{
	/*
	 * The cpu argument is ignored, because all CPUs have the same
	 * performance point, by definition.
	 */
	return get_current_freq();
}

static struct cpufreq_driver __read_mostly bl_cpufreq_driver = {
	.owner = THIS_MODULE,
	.name = MODULE_NAME,

	.init = bl_cpufreq_init,
	.verify = bl_cpufreq_verify,
	.target = bl_cpufreq_target,
	.get = bl_cpufreq_get,
	/* what else? */
};

static int __init bl_cpufreq_module_init(void)
{
	int err;

	/* test_config :
	 *	- 0: Do not run tests
	 *	- 1: Run tests and then register cpufreq driver if tests passed
	 */
	if ((test_config > 0) && (pre_init_tests() != 0))
		return -ECANCELED;

	err = cpufreq_register_driver(&bl_cpufreq_driver);
	if (err)
		pr_info("cpufreq backend driver registration "
						"failed (%d)\n", err);
	else {
		pr_info("cpufreq backend driver registered.\n");

		if ((test_config > 0) && (post_init_tests() != 0)) {
			cpufreq_unregister_driver(&bl_cpufreq_driver);
			return -ECANCELED;
		}
	}

	return err;
}
module_init(bl_cpufreq_module_init);

static void __exit bl_cpufreq_module_exit(void)
{
	cpufreq_unregister_driver(&bl_cpufreq_driver);

	pr_info("cpufreq backend driver unloaded.\n");
}
module_exit(bl_cpufreq_module_exit);


MODULE_AUTHOR("Dave Martin");
MODULE_DESCRIPTION("Simple cpufreq interface for the ARM big.LITTLE switcher");
MODULE_LICENSE("GPL");


#ifdef CONFIG_ARM_BL_CPUFREQ_TEST
#undef pr_fmt
#define pr_fmt(fmt) MODULE_NAME ": [test] " fmt

static DECLARE_WAIT_QUEUE_HEAD(test_wq);
static int test_transition_count;
unsigned int test_transition_freq;

module_param(test_config, short, 1);
MODULE_PARM_DESC(test_config, "Make tests before registring cpufreq driver. "
		"(0 : no tests, 1 : tests and registring driver (default))");

static int test_cpufreq_frequency_table(void)
{
	int nTest = 0, failCount = 0, testResult = 0;
	struct cpufreq_frequency_table const *entry;

	/* Get big and little cpufreq_frequency_table entries and check
	 * entry_to_freq() and entry_to_cluster() return corresponding
	 * frequencies and cluster id.
	 */
	entry = find_entry_by_cluster(CLUSTER_BIG);

	++nTest;
	if (entry_to_freq(entry) != FREQ_BIG) {
		testResult = 0;
		++failCount;
	} else
		testResult = 1;
	pr_info("name=pre-init/frequency_table/%d:entry_to_freq(big) "
			"result=%s\n", nTest, (testResult ? "PASS" : "FAIL"));

	++nTest;
	if (entry_to_cluster(entry) != CLUSTER_BIG) {
		testResult = 0;
		++failCount;
	} else
		testResult = 1;
	pr_info("name=pre-init/frequency_table/%d:entry_to_cluster(big) "
			"result=%s\n", nTest, (testResult ? "PASS" : "FAIL"));

	entry = find_entry_by_cluster(CLUSTER_LITTLE);

	++nTest;
	if (entry_to_freq(entry) != FREQ_LITTLE) {
		testResult = 0;
		++failCount;
	} else
		testResult = 1;
	pr_info("name=pre-init/frequency_table/%d:entry_to_freq(little) "
			"result=%s\n", nTest, (testResult ? "PASS" : "FAIL"));

	++nTest;
	if (entry_to_cluster(entry) != CLUSTER_LITTLE) {
		testResult = 0;
		++failCount;
	} else
		testResult = 1;
	pr_info("name=pre-init/frequency_table/%d:entry_to_cluster(little) "
			"result=%s\n", nTest, (testResult ? "PASS" : "FAIL"));


	pr_info("name=pre-init/frequency_table run=%d result=%s pass=%d "
			"fail=%d\n", nTest, (failCount == 0 ? "PASS" : "FAIL"),
			(nTest - failCount), failCount);
	if (failCount != 0)
		return -1;

	return 0;
}


static int test_cluster_to_freq(void)
{
	int nTest = 0, failCount = 0, testResult = 0;

	/* Check if test_cluster_to_freq() result is consistent, ie :
	 *	- CLUSTER_BIG => FREQ_BIG
	 *	- CLUSTER_LITTLE => FREQ_LITTLE
	 */
	++nTest;
	if (cluster_to_freq(CLUSTER_BIG) != FREQ_BIG) {
		testResult = 0;
		++failCount;
	} else
		testResult = 1;
	pr_info("name=pre-init/cluster_to_freq/%d:cluster_to_freq(big) "
			"result=%s\n", nTest, (testResult ? "PASS" : "FAIL"));

	++nTest;
	if (cluster_to_freq(CLUSTER_LITTLE) != FREQ_LITTLE) {
		testResult = 0;
		++failCount;
	} else
		testResult = 1;
	pr_info("name=pre-init/cluster_to_freq/%d:cluster_to_freq(little) "
			"result=%s\n", nTest, (testResult ? "PASS" : "FAIL"));


	pr_info("name=pre-init/cluster_to_freq run=%d result=%s pass=%d "
			"fail=%d\n", nTest, (failCount == 0 ? "PASS" : "FAIL"),
			(nTest - failCount), failCount);
	if (failCount != 0)
		return -1;

	return 0;
}

static int test_get_current_cluster(void)
{
	int nTest = 0, failCount = 0, testResult = 0;
	unsigned int cluster = get_current_cluster();

	/* Check if get_current_cluster() return a consistent value, ie
	 * CLUSTER_BIG or CLUSTER_LITTLE
	 */
	++nTest;
	if ((cluster != CLUSTER_BIG) && (cluster != CLUSTER_LITTLE)) {
		testResult = 0;
		++failCount;
	} else
		testResult = 1;
	pr_info("name=pre-init/get_current_cluster/%d:get_current_cluster() "
			"result=%s\n", nTest, (testResult ? "PASS" : "FAIL"));


	pr_info("name=pre-init/get_current_cluster run=%d result=%s pass=%d "
			"fail=%d\n", nTest, (failCount == 0 ? "PASS" : "FAIL"),
			(nTest - failCount), failCount);
	if (failCount != 0)
		return -1;

	return 0;
}

static int test_bl_cpufreq_get(void)
{
	int nTest = 0, failCount = 0, testResult = 0;
	const int current_freq = get_current_freq();
	unsigned int cpu;

	/* Check bl_cpufreq_get() retun value : value for all cores has to be
	 * the same as get_current_freq()
	 */
	for_each_cpu(cpu, cpu_present_mask) {
		++nTest;
		if (bl_cpufreq_get(cpu) != current_freq) {
			testResult = 0;
			++failCount;
		} else
			testResult = 1;
		pr_info("name=pre-init/bl_cpufreq_get/%d:bl_cpufreq_get(%u) "
						"result=%s\n", nTest, cpu,
						(testResult ? "PASS" : "FAIL"));
	}


	pr_info("name=pre-init/bl_cpufreq_get run=%d result=%s pass=%d "
			"fail=%d\n", nTest, (failCount == 0 ? "PASS" : "FAIL"),
			(nTest - failCount), failCount);
	if (failCount != 0)
		return -1;

	return 0;
}

static int test_get_current_freq(void)
{
	int nTest = 0, failCount = 0, testResult = 0;
	unsigned int freq = get_current_freq();

	/* Check if get_current_freq() return a consistent value, ie
	 * FREQ_BIG or FREQ_LITTLE
	 */
	++nTest;
	if ((freq != FREQ_BIG) && (freq != FREQ_LITTLE)) {
		testResult = 0;
		++failCount;
	} else
		testResult = 1;
	pr_info("name=pre-init/get_current_freq/%d:get_current_freq() "
			"result=%s\n", nTest, (testResult ? "PASS" : "FAIL"));


	pr_info("name=pre-init/get_current_freq run=%d result=%s pass=%d "
			"fail=%d\n", nTest, (failCount == 0 ? "PASS" : "FAIL"),
			(nTest - failCount), failCount);
	if (failCount != 0)
		return -1;

	return 0;
}

static int test_cpufreq_driver_target(void)
{
	int nTest = 0, failCount = 0, testResult = 0;
	unsigned int cluster;
	struct cpufreq_frequency_table const *other_entry = NULL;
	const struct cpufreq_frequency_table const *origin_entry =
				find_entry_by_cluster(get_current_cluster());
	struct cpufreq_policy *policy = cpufreq_cpu_get(0);

	/* Try to switch between cluster and check if switch was performed with
	 * success
	 */
	if (entry_to_cluster(origin_entry) == CLUSTER_BIG)
		other_entry = find_entry_by_cluster(CLUSTER_LITTLE);
	else
		other_entry = find_entry_by_cluster(CLUSTER_BIG);

	/* Swicth to "other" cluster, ie cluster not used at module loading time
	 */
	cpufreq_driver_target(policy, entry_to_freq(other_entry),
							CPUFREQ_RELATION_H);
	mdelay(10);
	cluster = get_current_cluster();

	++nTest;
	if (cluster != entry_to_cluster(other_entry)) {
		testResult = 0;
		++failCount;
	} else
		testResult = 1;
	pr_info("name=post-init/cpufreq_driver_target/%d:other result=%s\n",
					nTest, (testResult ? "PASS" : "FAIL"));

	/* Swicth again to "other" cluster
	 */
	cpufreq_driver_target(policy, entry_to_freq(other_entry),
							CPUFREQ_RELATION_H);
	mdelay(10);
	cluster = get_current_cluster();

	++nTest;
	if (cluster != entry_to_cluster(other_entry)) {
		testResult = 0;
		++failCount;
	} else
		testResult = 1;
	pr_info("name=post-init/cpufreq_driver_target/%d:otherAgain "
			"result=%s\n", nTest, (testResult ? "PASS" : "FAIL"));

	/* Swicth back to "origin" cluster, ie cluster used at module loading
	 * time
	 */
	cpufreq_driver_target(policy, entry_to_freq(origin_entry),
							CPUFREQ_RELATION_H);
	mdelay(10);
	cluster = get_current_cluster();

	++nTest;
	if (cluster != entry_to_cluster(origin_entry)) {
		testResult = 0;
		++failCount;
	} else
		testResult = 1;
	pr_info("name=post-init/cpufreq_driver_target/%d:origin result=%s\n",
					nTest, (testResult ? "PASS" : "FAIL"));

	/* Swicth again to "origin" cluster
	 */
	cpufreq_driver_target(policy, entry_to_freq(origin_entry),
							CPUFREQ_RELATION_H);
	mdelay(10);
	cluster = get_current_cluster();

	++nTest;
	if (cluster != entry_to_cluster(origin_entry)) {
		testResult = 0;
		++failCount;
	} else
		testResult = 1;
	pr_info("name=post-init/cpufreq_driver_target/%d:originAgain "
			"result=%s\n", nTest, (testResult ? "PASS" : "FAIL"));

	cpufreq_cpu_put(policy);


	pr_info("name=post-init/cpufreq_driver_target run=%d result=%s pass=%d "
			"fail=%d\n", nTest, (failCount == 0 ? "PASS" : "FAIL"),
			(nTest - failCount), failCount);
	if (failCount != 0)
		return -1;

	return 0;
}

/* Check that new frequency is expected frequency, increment count and wake up
 * test function.
 */
static int test_arm_bl_cpufreq_notifier(struct notifier_block *nb,
						unsigned long val, void *data)
{
	struct cpufreq_freqs *freq = data;

	if (freq->new != test_transition_freq)
		test_transition_freq = -1;

	++test_transition_count;

	wake_up(&test_wq);

	return 0;
}
static struct notifier_block test_arm_bl_cpufreq_notifier_block = {
	.notifier_call  = test_arm_bl_cpufreq_notifier
};

static int test_transitions(void)
{
	int nTest = 0, failCount = 0, testResult = 0;
	unsigned int num_cpu = num_present_cpus();
	unsigned int other_freq;
	const unsigned int origin_freq = cluster_to_freq(get_current_cluster());
	struct cpufreq_policy *policy = cpufreq_cpu_get(0);

	if (origin_freq == FREQ_BIG)
		other_freq = FREQ_LITTLE;
	else
		other_freq = FREQ_BIG;

	/* register test_arm_bl_cpufreq_notifier_block as notifier :
	 * test_arm_bl_cpufreq_notifier_block will be called on cluster
	 * change and increment transition_count
	 */
	cpufreq_register_notifier(&test_arm_bl_cpufreq_notifier_block,
						CPUFREQ_TRANSITION_NOTIFIER);

	/* Switch on little cluster and check notification
	 */
	++nTest;
	test_transition_count = 0;
	test_transition_freq = other_freq;
	cpufreq_driver_target(policy, other_freq, CPUFREQ_RELATION_H);
	wait_event_timeout(test_wq, (test_transition_count == 2 * num_cpu),
							msecs_to_jiffies(200));

	if ((test_transition_count != 2 * num_cpu)
				|| (test_transition_freq != other_freq)) {
		testResult = 0;
		++failCount;
	} else
		testResult = 1;
	pr_info("name=post-init/transitions/%d:other result=%s\n",
					nTest, (testResult ? "PASS" : "FAIL"));


	/* Switch on big cluster and check notification
	 */
	++nTest;
	test_transition_count = 0;
	test_transition_freq = origin_freq;
	cpufreq_driver_target(policy, origin_freq, CPUFREQ_RELATION_H);
	wait_event_timeout(test_wq, (test_transition_count == 2 * num_cpu),
							msecs_to_jiffies(200));

	if ((test_transition_count != 2 * num_cpu)
				|| (test_transition_freq != origin_freq)) {
		testResult = 0;
		++failCount;
	} else
		testResult = 1;
	pr_info("name=post-init/transitions/%d:origin result=%s\n",
					nTest, (testResult ? "PASS" : "FAIL"));

	cpufreq_unregister_notifier(&test_arm_bl_cpufreq_notifier_block,
						CPUFREQ_TRANSITION_NOTIFIER);
	cpufreq_cpu_put(policy);

	pr_info("name=post-init/transitions run=%d result=%s pass=%d fail=%d\n",
				nTest, (failCount == 0 ? "PASS" : "FAIL"),
				(nTest - failCount), failCount);
	if (failCount != 0)
		return -1;

	return 0;
}

static int pre_init_tests(void)
{
	int nTest = 0, failCount = 0;

	pr_info("Begin pre-init tests");

	++nTest;
	if (test_cpufreq_frequency_table() < 0)
		++failCount;

	++nTest;
	if (test_cluster_to_freq() < 0)
		++failCount;

	++nTest;
	if (test_get_current_cluster() < 0)
		++failCount;

	++nTest;
	if (test_get_current_freq() < 0)
		++failCount;

	++nTest;
	if (test_bl_cpufreq_get() < 0)
		++failCount;

	pr_info("name=pre-init run=%d result=%s pass=%d fail=%d\n",
				nTest, (failCount == 0 ? "PASS" : "FAIL"),
				(nTest - failCount), failCount);
	if (failCount != 0)
		return -1;

	return 0;
}

static int post_init_tests(void)
{
	int nTest = 0, failCount = 0;

	pr_info("Begin post-init tests");

	mdelay(100);
	++nTest;
	if (test_cpufreq_driver_target() < 0)
		++failCount;

	mdelay(100);
	++nTest;
	if (test_transitions() < 0)
		++failCount;

	pr_info("name=post-init run=%d result=%s pass=%d fail=%d\n",
				nTest, (failCount == 0 ? "PASS" : "FAIL"),
				(nTest - failCount), failCount);
	if (failCount != 0)
		return -1;

	return 0;
}

#else

static int pre_init_tests(void) { return 0; }
static int post_init_tests(void) { return 0; }

#endif