add opendir alias
[minix.git] / lib / libgpio / clkconf.c
blob7fb73cdfe1b711b10eae8e9c12c9a6e46e40c958
1 /* kernel headers */
2 #include <minix/syslib.h>
3 #include <minix/drvlib.h>
4 #include <minix/log.h>
5 #include <minix/mmio.h>
7 /* system headers */
8 #include <sys/mman.h>
9 #include <sys/types.h>
11 /* usr headers */
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <stdarg.h>
15 #include <string.h>
16 #include <errno.h>
17 #include <assert.h>
19 /* local headers */
20 #include "clkconf.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 CM_BASE 0x48004000
30 static u32_t base = 0;
31 static u32_t use_count = 0;
33 int
34 clkconf_init()
36 use_count++;
38 if (base != 0) {
39 /* when used in a library we can't guaranty we only call this
40 * method once */
41 log_trace(&log, "Called %d times\n", use_count);
42 return OK;
44 struct minix_mem_range mr;
45 mr.mr_base = CM_BASE;
46 mr.mr_limit = CM_BASE + 0x1000;
48 if (sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr) != 0) {
49 log_warn(&log, "Unable to request permission to map memory\n");
50 return EPERM;
53 base = (uint32_t) vm_map_phys(SELF, (void *) CM_BASE, 0x1000);
55 if (base == (uint32_t) MAP_FAILED) {
56 log_warn(&log, "Unable to map GPIO memory\n");
57 return EPERM;
59 return OK;
62 int
63 clkconf_set(u32_t clk, u32_t mask, u32_t value)
65 set32(base + clk, mask, value);
66 return OK;
69 int
70 clkconf_release()
72 assert(use_count > 0);
73 use_count--;
74 if (use_count == 0) {
75 vm_unmap_phys(SELF, (void *) base, 0x1000);
77 return OK;