-
Notifications
You must be signed in to change notification settings - Fork 8
/
omap_Misc.c
executable file
·600 lines (477 loc) · 13 KB
/
omap_Misc.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
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
//(c) uARM project https://github.com/uARM-Palm/uARM [email protected]
#include "omap_Misc.h"
#include <string.h>
#include <stdlib.h>
#include "util.h"
#include "mem.h"
#define OMAP_DSP_CLKM_BASE 0xE1008000UL
#define OMAP_DSP_CLKM_SIZE 2048
#define OMAP_OMAP_CFG_BASE 0xFFFE1000UL
#define OMAP_OMAP_CFG_SIZE 256
#define OMAP_MPUI_BASE 0xFFFEC900UL //access to the dsp from mpu
#define OMAP_MPUI_SIZE 256
#define OMAP_TRAFFIC_CTRL_BASE 0xFFFECC00UL
#define OMAP_TRAFFIC_CTRL_SIZE 256
#define OMAP_MPU_CLK_CTRL_BASE 0xFFFECE00UL
#define OMAP_MPU_CLK_CTRL_SIZE 256
#define OMAP_DPLL_1_BASE 0xFFFECF00UL
#define OMAP_DPLL_1_SIZE 256
#define OMAP_IDCODE_BASE 0xFFFED404UL
#define OMAP_IDCODE_SIZE 4
struct OmapMisc {
//MPU CLOCK CONTROL
struct {
uint16_t CKCTL, IDLECT1, IDLECT2, EWUPCT, RSTCT1, RSTCT2, SYSST;
} mpu;
//DPLL1
struct {
uint16_t CTL_REG;
} dpll;
//OMAP config
struct {
uint32_t FUNC_MUX_CTRL[14], COMP_MODE_CTRL, PULL_DWN_CTRL[4], GATE_INH_CTRL, VOLTAGE_CTRL, TEST_DBG_CTRL, MOD_CONF_CTRL;
} omapCfg;
//TRAFFIC CONTROLLER
struct {
uint32_t EMIFS_CSx_CONFIG[4], EMIFF_SDRAM_CONFIG, TIMEOUT[2];
uint16_t EMIFF_MRS;
uint8_t EMIFS_CONFIG_REG, ENDIANISM, EMIFF_SDRAM_CONFIG_2, EMIFS_CFG_DYN_WAIT;
} trafficCfg;
//DSP CLKM
struct {
uint8_t RSTCT2;
uint16_t IDLECT[2], SYSST;
//guessed, uncodumented
uint16_t CKCTL;
} dspClkm;
//MPUI
struct {
uint32_t CTRL_REG;
uint16_t DSP_API_CONFIG;
uint8_t DSP_BOOT_CONFIG;
} mpui;
};
static bool omapMiscPrvDpllMemAccessF(void* userData, uint32_t pa, uint_fast8_t size, bool write, void* buf)
{
struct OmapMisc* misc = (struct OmapMisc*)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_DPLL_1_BASE) >> 2;
if (write)
val = (size == 2) ? *(uint16_t*)buf : *(uint32_t*)buf;
switch (pa) {
case 0x00 / 4:
if (write)
misc->dpll.CTL_REG = val | 0x0001; //always locked
else
val = misc->dpll.CTL_REG;
break;
default:
return false;
}
if (!write) {
if (size == 2)
*(uint16_t*)buf = val;
else
*(uint32_t*)buf = val;
}
return true;
}
bool omapMiscIsTimerAtCpuSpeed(struct OmapMisc *misc)
{
return (misc->mpu.CKCTL >> 12) & 1;
}
static bool omapMiscPrvMpuClkCtrlMemAccessF(void* userData, uint32_t pa, uint_fast8_t size, bool write, void* buf)
{
struct OmapMisc* misc = (struct OmapMisc*)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_MPU_CLK_CTRL_BASE) >> 2;
if (write)
val = (size == 2) ? *(uint16_t*)buf : *(uint32_t*)buf;
switch (pa) {
case 0x00 / 4:
if (write)
misc->mpu.CKCTL = val;
else
val = misc->mpu.CKCTL;
break;
case 0x04 / 4:
if (write)
misc->mpu.IDLECT1 = val;
else
val = misc->mpu.IDLECT1;
break;
case 0x08 / 4:
if (write)
misc->mpu.IDLECT2 = val;
else
val = misc->mpu.IDLECT2;
break;
case 0x0c / 4:
if (write)
misc->mpu.EWUPCT = val;
else
val = misc->mpu.EWUPCT;
break;
case 0x10 / 4:
if (write) {
misc->mpu.RSTCT1 = val;
if (val & 0x0009)
ERR("MPU has reset itself\n");
}
else
val = misc->mpu.RSTCT1;
break;
case 0x14 / 4:
if (write)
misc->mpu.RSTCT2 = val;
else
val = misc->mpu.RSTCT2;
break;
case 0x18 / 4:
if (write)
misc->mpu.SYSST = val;
else
val = misc->mpu.SYSST;
break;
default:
return false;
}
if (!write) {
if (size == 2)
*(uint16_t*)buf = val;
else
*(uint32_t*)buf = val;
}
return true;
}
static bool omapMiscPrvOmapCfgMemAccessF(void* userData, uint32_t pa, uint_fast8_t size, bool write, void* buf)
{
struct OmapMisc* misc = (struct OmapMisc*)userData;
uint32_t val = 0;
if (size != 4) {
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_OMAP_CFG_BASE) >> 2;
if (write)
val = *(uint32_t*)buf;
switch (pa) {
case 0x00 / 4:
case 0x04 / 4:
case 0x08 / 4:
if (write)
misc->omapCfg.FUNC_MUX_CTRL[pa - 0x00 / 4] = val;
else
val = misc->omapCfg.FUNC_MUX_CTRL[pa - 0x00 / 4];
break;
case 0x0c / 4:
if (write)
misc->omapCfg.COMP_MODE_CTRL = val;
else
val = misc->omapCfg.COMP_MODE_CTRL;
break;
case 0x10 / 4:
case 0x14 / 4:
case 0x18 / 4:
case 0x1c / 4:
case 0x20 / 4:
case 0x24 / 4:
case 0x28 / 4:
case 0x2c / 4:
case 0x30 / 4:
case 0x34 / 4:
case 0x38 / 4:
if (write)
misc->omapCfg.FUNC_MUX_CTRL[pa - 0x10 / 4] = val;
else
val = misc->omapCfg.FUNC_MUX_CTRL[pa - 0x10 / 4];
break;
case 0x40 / 4:
case 0x44 / 4:
case 0x48 / 4:
case 0x4c / 4:
if (write)
misc->omapCfg.PULL_DWN_CTRL[pa - 0x40 / 4] = val;
else
val = misc->omapCfg.PULL_DWN_CTRL[pa - 0x40 / 4];
break;
case 0x50 / 4:
if (write)
misc->omapCfg.GATE_INH_CTRL = val;
else
val = misc->omapCfg.GATE_INH_CTRL;
break;
case 0x60 / 4:
if (write)
misc->omapCfg.VOLTAGE_CTRL = val;
else
val = misc->omapCfg.VOLTAGE_CTRL;
break;
case 0x70 / 4:
if (write)
misc->omapCfg.TEST_DBG_CTRL = val;
else
val = misc->omapCfg.TEST_DBG_CTRL;
break;
case 0x80 / 4:
if (write)
misc->omapCfg.MOD_CONF_CTRL = val;
else
val = misc->omapCfg.MOD_CONF_CTRL;
break;
default:
return false;
}
if (!write)
*(uint32_t*)buf = val;
return true;
}
static bool omapMiscPrvDspClkmMemAccessF(void* userData, uint32_t pa, uint_fast8_t size, bool write, void* buf)
{
struct OmapMisc* misc = (struct OmapMisc*)userData;
uint_fast16_t val = 0;
if (size != 2) {
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_DSP_CLKM_BASE) >> 2;
if (write)
val = *(uint16_t*)buf;
switch (pa) {
case 0x00 / 4:
if (write)
misc->dspClkm.CKCTL = val;
else
val = misc->dspClkm.CKCTL;
break;
case 0x04 / 4:
if (write)
misc->dspClkm.IDLECT[0] = val & 0x01e0;
else
val = misc->dspClkm.IDLECT[0];
break;
case 0x08 / 4:
if (write)
misc->dspClkm.IDLECT[1] = val & 0x0103;
else
val = misc->dspClkm.IDLECT[1];
break;
case 0x14 / 4:
if (write)
misc->dspClkm.RSTCT2 = val & 1;
else
val = misc->dspClkm.RSTCT2;
break;
case 0x18 / 4:
if (write)
misc->dspClkm.SYSST = val & 0x38ff;
else
val = misc->dspClkm.SYSST;
break;
default:
return false;
}
if (!write)
*(uint16_t*)buf = val;
return true;
}
static bool omapMiscPrvMpuiMemAccessF(void* userData, uint32_t pa, uint_fast8_t size, bool write, void* buf)
{
struct OmapMisc* misc = (struct OmapMisc*)userData;
uint32_t val = 0;
if ((size != 4 && size != 2) || (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_MPUI_BASE) >> 2;
if (write)
val = size == 2 ? *(uint16_t*)buf : *(uint32_t*)buf;
switch (pa) {
case 0x00 / 4:
if (write)
misc->mpui.CTRL_REG = val & 0x007ffffful;
else
val = misc->mpui.CTRL_REG;
break;
case 0x04 / 4: //DEBUG_ADDR
case 0x08 / 4: //DEBUG_DATA
case 0x0c / 4: //DEBUG_FLAG
if (write)
return false;
else
val = 0x00fffffful;
break;
case 0x10 / 4: //STATUS_REG
if (write)
return false;
else
val = 0x00001ffful;
break;
case 0x14 / 4:
if (write)
return false;
else
val = 0x00000ffful;
break;
case 0x18 / 4:
if (write)
misc->mpui.DSP_BOOT_CONFIG = val & 0x0f;
else
val = misc->mpui.DSP_BOOT_CONFIG;
break;
case 0x1c / 4:
if (write)
misc->mpui.DSP_API_CONFIG = val;
else
val = misc->mpui.DSP_API_CONFIG;
break;
default:
return false;
}
if (!write) {
if (size == 2)
*(uint16_t*)buf = val;
else
*(uint32_t*)buf = val;
}
return true;
}
static bool omapMiscPrvTrafficCtrlMemAccessF(void* userData, uint32_t pa, uint_fast8_t size, bool write, void* buf)
{
struct OmapMisc* misc = (struct OmapMisc*)userData;
uint32_t val = 0;
if (size != 4) {
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_TRAFFIC_CTRL_BASE) >> 2;
if (write)
val = *(uint32_t*)buf;
switch (pa) {
case 0x00 / 4:
case 0x04 / 4:
case 0x08 / 4:
if (write)
; //ignored
else
val = 0;
break;
case 0x0C / 4:
if (write)
misc->trafficCfg.EMIFS_CONFIG_REG = (val & 0x07) | (misc->trafficCfg.EMIFS_CONFIG_REG & 8); //flahs is always ready
else
val = misc->trafficCfg.EMIFS_CONFIG_REG;
break;
case 0x10 / 4:
case 0x14 / 4:
case 0x18 / 4:
case 0x1C / 4:
if (write)
misc->trafficCfg.EMIFS_CSx_CONFIG[pa - 0x10 / 4] = val & 0x0037fff7ul;
else
val = misc->trafficCfg.EMIFS_CSx_CONFIG[pa - 0x10 / 4];
break;
case 0x20 / 4:
if (write)
misc->trafficCfg.EMIFF_SDRAM_CONFIG = val & 0x0ffffffful;
else
val = misc->trafficCfg.EMIFF_SDRAM_CONFIG;
break;
case 0x24 / 4:
if (write)
misc->trafficCfg.EMIFF_MRS = val & 0x027f;
else
val = misc->trafficCfg.EMIFF_MRS;
break;
case 0x28 / 4:
case 0x2C / 4:
if (write)
misc->trafficCfg.TIMEOUT[pa - 0x28 / 4] = val & 0x00ff00fful;
else
val = misc->trafficCfg.TIMEOUT[pa - 0x28 / 4];
break;
//case 0x30 / 4: //TIMEOUT3 reg
// return false;
case 0x34 / 4:
if (write)
misc->trafficCfg.ENDIANISM = val & 0x03;
else
val = misc->trafficCfg.ENDIANISM;
break;
case 0x3C / 4:
if (write)
misc->trafficCfg.EMIFF_SDRAM_CONFIG_2 = val & 0x03;
else
val = misc->trafficCfg.EMIFF_SDRAM_CONFIG_2;
break;
case 0x40 / 4:
if (write)
misc->trafficCfg.EMIFS_CFG_DYN_WAIT = val & 0x0f;
else
val = misc->trafficCfg.EMIFS_CFG_DYN_WAIT;
break;
default:
return false;
}
if (!write)
*(uint32_t*)buf = val;
return true;
}
static bool omapMiscPrvIdcodeMemAccessF(void* userData, uint32_t pa, uint_fast8_t size, bool write, void* buf)
{
if (pa == OMAP_IDCODE_BASE && size == 4 && !write) {
*(uint32_t*)buf = 0x1b47002ful;
return true;
}
return false;
}
struct OmapMisc* omapMiscInit(struct ArmMem *physMem)
{
struct OmapMisc *misc = (struct OmapMisc*)malloc(sizeof(*misc));
if (!misc)
ERR("cannot alloc MISC stuff\n");
memset(misc, 0, sizeof (*misc));
//MPU CLK CTRL
misc->mpu.CKCTL = 0x3000;
misc->mpu.IDLECT1 = 0x0400;
misc->mpu.IDLECT2 = 0x0100;
misc->mpu.EWUPCT = 0x003f;
misc->mpu.SYSST = 0x0038;
//DPLL
misc->dpll.CTL_REG = 0x2002;
//TRAFFIC CONTROLLER
misc->trafficCfg.EMIFS_CONFIG_REG = 0x08;
misc->trafficCfg.EMIFS_CSx_CONFIG[0] = 0x0000fffbul;
misc->trafficCfg.EMIFS_CSx_CONFIG[1] = 0x0010fffbul;
misc->trafficCfg.EMIFS_CSx_CONFIG[2] = 0x0010fffbul;
misc->trafficCfg.EMIFS_CSx_CONFIG[3] = 0x0000fffbul;
misc->trafficCfg.EMIFF_SDRAM_CONFIG = 0x00618800ul;
misc->trafficCfg.EMIFF_MRS = 0x0037;
misc->trafficCfg.EMIFF_SDRAM_CONFIG_2 = 0x03;
//MPUI
misc->mpui.CTRL_REG = 0x0003ff1ful;
misc->mpui.DSP_API_CONFIG = 0xffff;
if (!memRegionAdd(physMem, OMAP_MPU_CLK_CTRL_BASE, OMAP_MPU_CLK_CTRL_SIZE, omapMiscPrvMpuClkCtrlMemAccessF, misc))
ERR("cannot add MPU CLOCK CTRL to MEM\n");
if (!memRegionAdd(physMem, OMAP_DPLL_1_BASE, OMAP_DPLL_1_SIZE, omapMiscPrvDpllMemAccessF, misc))
ERR("cannot add DPLL1 to MEM\n");
if (!memRegionAdd(physMem, OMAP_OMAP_CFG_BASE, OMAP_OMAP_CFG_SIZE, omapMiscPrvOmapCfgMemAccessF, misc))
ERR("cannot add OMAP CFG to MEM\n");
if (!memRegionAdd(physMem, OMAP_TRAFFIC_CTRL_BASE, OMAP_TRAFFIC_CTRL_SIZE, omapMiscPrvTrafficCtrlMemAccessF, misc))
ERR("cannot add TRAFFIC CTRL to MEM\n");
if (!memRegionAdd(physMem, OMAP_IDCODE_BASE, OMAP_IDCODE_SIZE, omapMiscPrvIdcodeMemAccessF, misc))
ERR("cannot add IDCODE to MEM\n");
if (!memRegionAdd(physMem, OMAP_DSP_CLKM_BASE, OMAP_DSP_CLKM_SIZE, omapMiscPrvDspClkmMemAccessF, misc))
ERR("cannot add DSK CLKM to MEM\n");
if (!memRegionAdd(physMem, OMAP_MPUI_BASE, OMAP_MPUI_SIZE, omapMiscPrvMpuiMemAccessF, misc))
ERR("cannot add MPUI to MEM\n");
return misc;
}