blob: dc2ab5f555d7a1084428c0aabd99a115047a059d (
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
|
#include <common.h>
#include <clock.h>
#include <init.h>
#include <asm/blackfin.h>
#include <asm/cpu/cdef_LPBlackfin.h>
static ulong get_vco(void)
{
ulong msel;
ulong vco;
msel = (*pPLL_CTL >> 9) & 0x3F;
if (0 == msel)
msel = 64;
vco = CONFIG_CLKIN_HZ;
vco >>= (1 & *pPLL_CTL); /* DF bit */
vco = msel * vco;
return vco;
}
/* Get the Core clock */
ulong get_cclk(void)
{
ulong csel, ssel;
if (*pPLL_STAT & 0x1)
return CONFIG_CLKIN_HZ;
ssel = *pPLL_DIV;
csel = ((ssel >> 4) & 0x03);
ssel &= 0xf;
if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
return get_vco() / ssel;
return get_vco() >> csel;
}
/* Get the System clock */
ulong get_sclk(void)
{
ulong ssel;
if (*pPLL_STAT & 0x1)
return CONFIG_CLKIN_HZ;
ssel = (*pPLL_DIV & 0xf);
return get_vco() / ssel;
}
static uint64_t blackfin_clocksource_read(void)
{
return ~(*pTCOUNT);
}
static struct clocksource cs = {
.read = blackfin_clocksource_read,
.mask = 0xffffffff,
.shift = 10,
};
static int clocksource_init (void)
{
*pTCNTL = 0x1;
*pTSCALE = 0x0;
*pTCOUNT = ~0;
*pTPERIOD = ~0;
*pTCNTL = 0x7;
asm("CSYNC;");
cs.mult = clocksource_hz2mult(get_cclk(), cs.shift);
init_clock(&cs);
return 0;
}
core_initcall(clocksource_init);
|