2 #include <minix/syslib.h>
3 #include <minix/drvlib.h>
5 #include <minix/mmio.h>
6 #include <minix/clkconf.h>
7 #include <minix/type.h>
8 #include <minix/board.h>
12 #include <sys/types.h>
22 /* used for logging */
23 static struct log log
= {
24 .name
= "omap_clkconf",
25 .log_level
= LEVEL_INFO
,
26 .log_func
= default_log
29 #define DM37XX_CM_BASE 0x48004000
30 #define AM335X_CM_BASE 0x44E00000
32 static u32_t base
= 0;
33 static u32_t use_count
= 0;
39 struct machine machine
;
40 sys_getmachine(&machine
);
45 /* when used in a library we can't guaranty we only call this
47 log_trace(&log
, "Called %d times\n", use_count
);
51 if (BOARD_IS_BBXM(machine
.board_id
)){
52 cm_base
= DM37XX_CM_BASE
;
53 } else if (BOARD_IS_BB(machine
.board_id
)){
54 cm_base
= AM335X_CM_BASE
;
56 struct minix_mem_range mr
;
58 mr
.mr_limit
= cm_base
+ 0x1000;
60 if (sys_privctl(SELF
, SYS_PRIV_ADD_MEM
, &mr
) != 0) {
61 log_warn(&log
, "Unable to request permission to map memory\n");
65 base
= (uint32_t) vm_map_phys(SELF
, (void *) cm_base
, 0x1000);
67 if (base
== (uint32_t) MAP_FAILED
) {
68 log_warn(&log
, "Unable to map GPIO memory\n");
75 clkconf_set(u32_t clk
, u32_t mask
, u32_t value
)
77 set32(base
+ clk
, mask
, value
);
84 assert(use_count
> 0);
87 vm_unmap_phys(SELF
, (void *) base
, 0x1000);