-
Notifications
You must be signed in to change notification settings - Fork 8
/
omap_ULPD.c
executable file
·116 lines (87 loc) · 2.35 KB
/
omap_ULPD.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
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
//(c) uARM project https://github.com/uARM-Palm/uARM [email protected]
#include "omap_ULPD.h"
#include "omap_IC.h"
#include <string.h>
#include <stdlib.h>
#include "util.h"
#include "mem.h"
#define OMAP_ULPD_BASE 0xFFFE0800UL
#define OMAP_ULPD_SIZE 2048
struct OmapUlpd {
struct SocIc *ic;
uint32_t lowFreqDivider;
uint32_t highFreqCtr, lowFreqCtr;
uint16_t SETUP_ANALOG_CELL3_ULPD1_REG;
uint16_t CLOCK_CTRL_REG;
uint8_t SOFT_REQ_REG, POWER_CTRL_REG;
};
//p 1138
static bool omapUlpdPrvMemAccessF(void* userData, uint32_t pa, uint_fast8_t size, bool write, void* buf)
{
struct OmapUlpd *ulpd = (struct OmapUlpd*)userData;
uint32_t val = 0;
if ((size != 2 && size != 4) || (pa & 3)) {
fprintf(stderr, "%s: Unexpected %s of %u bytes to 0x%08lx\n", __func__, write ? "write" : "read", size, (unsigned long)pa);
return false;
}
pa = (pa - OMAP_ULPD_BASE) >> 2;
if (write)
val = (size == 2) ? *(uint16_t*)buf : *(uint32_t*)buf;
switch (pa) {
case 0x24 / 4:
if (write)
ulpd->SETUP_ANALOG_CELL3_ULPD1_REG = val;
else
val = ulpd->SETUP_ANALOG_CELL3_ULPD1_REG;
break;
case 0x30 / 4:
if (write)
ulpd->CLOCK_CTRL_REG = val;
else
val = ulpd->CLOCK_CTRL_REG;
break;
case 0x34 / 4:
if (write)
ulpd->SOFT_REQ_REG = val & 0x1f;
else
val = ulpd->SOFT_REQ_REG;
break;
case 0x50 / 4:
if (write)
ulpd->POWER_CTRL_REG = val & 0x0f;
else
val = ulpd->POWER_CTRL_REG;
break;
default:
return false;
}
if (!write) {
if (size == 2)
*(uint16_t*)buf = val;
else
*(uint32_t*)buf = val;
}
return true;
}
struct OmapUlpd* omapUlpdInit(struct ArmMem *physMem, struct SocIc *ic)
{
struct OmapUlpd *ulpd = (struct OmapUlpd*)malloc(sizeof(*ulpd));
if (!ulpd)
ERR("cannot alloc ULPD");
memset(ulpd, 0, sizeof (*ulpd));
ulpd->ic = ic;
ulpd->SETUP_ANALOG_CELL3_ULPD1_REG = 0x03ff;
ulpd->CLOCK_CTRL_REG = 0x0010;
ulpd->SOFT_REQ_REG = 0x10;
ulpd->POWER_CTRL_REG = 0x08;
if (!memRegionAdd(physMem, OMAP_ULPD_BASE, OMAP_ULPD_SIZE, omapUlpdPrvMemAccessF, ulpd))
ERR("cannot add ULPD to MEM\n");
return ulpd;
}
void omapUlpdPeriodic(struct OmapUlpd *ulpd)
{
ulpd->highFreqCtr++;
if (++ulpd->lowFreqDivider == 375)
ulpd->lowFreqCtr++;
//TODO
}