xref: /openbsd/sys/arch/armv7/omap/omap_machdep.c (revision a6445c1d)
1 /*	$OpenBSD	*/
2 /*
3  * Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <sys/param.h>
19 #include <sys/types.h>
20 #include <sys/device.h>
21 #include <sys/systm.h>
22 #include <sys/termios.h>
23 
24 #include <machine/bus.h>
25 #include <machine/bootconfig.h>
26 
27 #include <dev/ic/comreg.h>
28 #include <dev/ic/comvar.h>
29 
30 #include <arm/cortex/smc.h>
31 #include <arm/armv7/armv7var.h>
32 #include <armv7/armv7/armv7var.h>
33 #include <armv7/armv7/armv7_machdep.h>
34 
35 extern void omap4_smc_call(uint32_t, uint32_t);
36 extern void omdog_reset(void);
37 extern int comcnspeed;
38 extern int comcnmode;
39 
40 const char *platform_boot_name = "OpenBSD/omap";
41 
42 void
43 platform_smc_write(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t off,
44     uint32_t op, uint32_t val)
45 {
46 	switch (op) {
47 	case 0x100:	/* PL310 DEBUG */
48 	case 0x102:	/* PL310 CTL */
49 		break;
50 	default:
51 		panic("platform_smc_write: invalid operation %d", op);
52 	}
53 
54 	omap4_smc_call(op, val);
55 }
56 
57 void
58 platform_init_cons(void)
59 {
60 	paddr_t paddr;
61 
62 	switch (board_id) {
63 	case BOARD_ID_OMAP3_BEAGLE:
64 	case BOARD_ID_OMAP3_OVERO:
65 		paddr = 0x49020000;
66 		break;
67 	case BOARD_ID_AM335X_BEAGLEBONE:
68 		paddr = 0x44e09000;
69 		break;
70 	case BOARD_ID_OMAP4_PANDA:
71 		paddr = 0x48020000;
72 		break;
73 	}
74 
75 	comcnattach(&armv7_a4x_bs_tag, paddr, comcnspeed, 48000000, comcnmode);
76 	comdefaultrate = comcnspeed;
77 }
78 
79 void
80 platform_watchdog_reset(void)
81 {
82 	omdog_reset();
83 }
84 
85 void
86 platform_powerdown(void)
87 {
88 
89 }
90 
91 void
92 platform_print_board_type(void)
93 {
94 	switch (board_id) {
95 	case BOARD_ID_OMAP3_BEAGLE:
96 		printf("board type: beagle\n");
97 		break;
98 	case BOARD_ID_AM335X_BEAGLEBONE:
99 		printf("board type: beaglebone\n");
100 		break;
101 	case BOARD_ID_OMAP3_OVERO:
102 		printf("board type: overo\n");
103 		break;
104 	case BOARD_ID_OMAP4_PANDA:
105 		printf("board type: panda\n");
106 		break;
107 	default:
108 		printf("board type %x unknown", board_id);
109 	}
110 }
111 
112 void
113 platform_bootconfig_dram(BootConfig *bootconfig, psize_t *memstart, psize_t *memsize)
114 {
115 	uint32_t sdrc_mcfg_0, sdrc_mcfg_1, memsize0, memsize1;
116 	int loop;
117 
118 	if (bootconfig->dramblocks == 0) {
119 		sdrc_mcfg_0 = *(uint32_t *)0x6d000080;
120 		sdrc_mcfg_1 = *(uint32_t *)0x6d0000b0;
121 		memsize0 = (((sdrc_mcfg_0 >> 8))&0x3ff) * (2 * 1024 * 1024);
122 		memsize1 = (((sdrc_mcfg_1 >> 8))&0x3ff) * (2 * 1024 * 1024);
123 		*memsize = memsize0 + memsize1;
124 
125 		*memstart = SDRAM_START;
126 		*memsize =  0x02000000; /* 32MB */
127 		/* Fake bootconfig structure for the benefit of pmap.c */
128 		/* XXX must make the memory description h/w independant */
129 		bootconfig->dram[0].address = *memstart;
130 		bootconfig->dram[0].pages = memsize0 / PAGE_SIZE;
131 		bootconfig->dramblocks = 1;
132 		if (memsize1 != 0) {
133 			bootconfig->dram[1].address = bootconfig->dram[0].address
134 			    + memsize0; /* XXX */
135 			bootconfig->dram[1].pages = memsize1 / PAGE_SIZE;
136 			bootconfig->dramblocks++; /* both banks populated */
137 		}
138 	} else {
139 		/* doesn't deal with multiple segments, hopefully u-boot collaped them into one */
140 		*memstart = bootconfig->dram[0].address;
141 		*memsize = bootconfig->dram[0].pages * PAGE_SIZE;
142 		printf("memory size derived from u-boot\n");
143 		for (loop = 0; loop < bootconfig->dramblocks; loop++) {
144 			printf("bootconf.mem[%d].address = %08x pages %d/0x%08x\n",
145 			    loop, bootconfig->dram[0].address, bootconfig->dram[0].pages,
146 			        bootconfig->dram[0].pages * PAGE_SIZE);
147 		}
148 	}
149 
150 }
151 
152 void
153 platform_disable_l2_if_needed(void)
154 {
155 	switch (board_id) {
156 	case BOARD_ID_OMAP4_PANDA:
157 		/* disable external L2 cache */
158 		omap4_smc_call(0x102, 0);
159 		break;
160 	}
161 }
162