1 /* Implements sys_padconf() for the AM335X and DM37XX. */
2
3 #include "kernel/kernel.h"
4 #include "arch_proto.h"
5 #include <sys/types.h>
6 #include <machine/cpu.h>
7 #include <minix/mmio.h>
8 #include <minix/padconf.h>
9 #include <minix/board.h>
10 #include <minix/com.h>
11 #include <assert.h>
12 #include <io.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15
16 #include "bsp_padconf.h"
17
18 struct omap_padconf
19 {
20 vir_bytes base;
21 vir_bytes offset;
22 vir_bytes size;
23 unsigned int board_filter_value;
24 unsigned int board_filter_mask;
25 };
26
27 static struct omap_padconf omap_padconfs[] = {
28 {
29 .base = PADCONF_DM37XX_REGISTERS_BASE,
30 .offset = PADCONF_DM37XX_REGISTERS_OFFSET,
31 .size = PADCONF_DM37XX_REGISTERS_SIZE,
32 .board_filter_value = BOARD_FILTER_BBXM_VALUE,
33 .board_filter_mask = BOARD_FILTER_BBXM_MASK,
34 },
35 {
36 .base = PADCONF_AM335X_REGISTERS_BASE,
37 .offset = PADCONF_AM335X_REGISTERS_OFFSET,
38 .size = PADCONF_AM335X_REGISTERS_SIZE,
39 .board_filter_value = BOARD_FILTER_BB_VALUE,
40 .board_filter_mask = BOARD_FILTER_BB_MASK,
41 },
42 };
43
44 /* initialized in init */
45 static struct omap_padconf *omap_padconf;
46
47 static kern_phys_map padconf_phys_map;
48
49 int
bsp_padconf_set(u32_t padconf,u32_t mask,u32_t value)50 bsp_padconf_set(u32_t padconf, u32_t mask, u32_t value)
51 {
52 /* check that the value will be inside the padconf memory range */
53 if (padconf >= (omap_padconf->size - omap_padconf->offset)) {
54 return EINVAL; /* outside of valid range */
55 }
56
57 set32(padconf + omap_padconf->base + omap_padconf->offset, mask,
58 value);
59
60 return OK;
61 }
62
63 void
bsp_padconf_init(void)64 bsp_padconf_init(void)
65 {
66 int x;
67 omap_padconf = NULL;
68 /* find the correct padconf */
69 for (x = 0; x < sizeof(omap_padconfs) / sizeof(omap_padconfs[0]); x++) {
70 if ((omap_padconfs[x].board_filter_mask & machine.board_id) ==
71 omap_padconfs[x].board_filter_value) {
72 omap_padconf = &omap_padconfs[x];
73 break;
74 }
75 }
76 assert(omap_padconf);
77
78 kern_phys_map_ptr(omap_padconf->base, omap_padconf->size,
79 VMMF_UNCACHED | VMMF_WRITE,
80 &padconf_phys_map, (vir_bytes) & omap_padconf->base);
81
82 return;
83 }
84