forked from tewilove/sharp-sbl1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
soc_shared.c
60 lines (42 loc) · 1.32 KB
/
soc_shared.c
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
#include <stdint-gcc.h>
#include "reg.h"
#include "consts_shared.h"
#if AS87 || AS97 || PA21 || PA23 || PB25 || PA28 || DL40 || DL75
#include "consts_msm8974.h"
#endif
#define QTMR_V1_CNTPCT_LO (0x00000000 + QTMR_BASE)
#define QTMR_V1_CNTPCT_HI (0x00000004 + QTMR_BASE)
static uint64_t ticks_per_sec = 19200000;
static uint64_t qtimer_get_phy_timer_cnt() {
uint32_t phy_cnt_lo;
uint32_t phy_cnt_hi_1;
uint32_t phy_cnt_hi_2;
do {
phy_cnt_hi_1 = readl(QTMR_V1_CNTPCT_HI);
phy_cnt_lo = readl(QTMR_V1_CNTPCT_LO);
phy_cnt_hi_2 = readl(QTMR_V1_CNTPCT_HI);
} while (phy_cnt_hi_1 != phy_cnt_hi_2);
return ((uint64_t)phy_cnt_hi_1 << 32) | phy_cnt_lo;
}
void tdelay(uint64_t ticks) {
volatile uint64_t cnt;
uint64_t init_cnt;
uint64_t timeout = 0;
cnt = qtimer_get_phy_timer_cnt();
init_cnt = cnt;
timeout = (cnt + ticks) & (uint64_t)(QTMR_PHY_CNT_MAX_VALUE);
while(timeout < cnt && init_cnt <= cnt)
cnt = qtimer_get_phy_timer_cnt();
while(timeout > cnt)
cnt = qtimer_get_phy_timer_cnt();
}
void udelay(uint64_t nsecs) {
uint64_t ticks;
ticks = ((uint64_t) nsecs * ticks_per_sec) / 1000000;
tdelay(ticks);
}
void mdelay(uint64_t msecs) {
uint64_t ticks;
ticks = ((uint64_t) msecs * ticks_per_sec) / 1000;
tdelay(ticks);
}