Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[firefly-linux-kernel-4.4.55.git] / arch / metag / kernel / clock.c
1 /*
2  * arch/metag/kernel/clock.c
3  *
4  * Copyright (C) 2012 Imagination Technologies Ltd.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/delay.h>
12 #include <linux/io.h>
13
14 #include <asm/param.h>
15 #include <asm/clock.h>
16
17 struct meta_clock_desc _meta_clock;
18
19 /* Default machine get_core_freq callback. */
20 static unsigned long get_core_freq_default(void)
21 {
22 #ifdef CONFIG_METAG_META21
23         /*
24          * Meta 2 cores divide down the core clock for the Meta timers, so we
25          * can estimate the core clock from the divider.
26          */
27         return (metag_in32(EXPAND_TIMER_DIV) + 1) * 1000000;
28 #else
29         /*
30          * On Meta 1 we don't know the core clock, but assuming the Meta timer
31          * is correct it can be estimated based on loops_per_jiffy.
32          */
33         return (loops_per_jiffy * HZ * 5) >> 1;
34 #endif
35 }
36
37 /**
38  * setup_meta_clocks() - Set up the Meta clock.
39  * @desc:       Clock descriptor usually provided by machine description
40  *
41  * Ensures all callbacks are valid.
42  */
43 void __init setup_meta_clocks(struct meta_clock_desc *desc)
44 {
45         /* copy callbacks */
46         if (desc)
47                 _meta_clock = *desc;
48
49         /* set fallback functions */
50         if (!_meta_clock.get_core_freq)
51                 _meta_clock.get_core_freq = get_core_freq_default;
52 }
53