xref: /minix/minix/kernel/arch/earm/bsp/ti/omap_reset.c (revision 7f5f010b)
1 #include <assert.h>
2 #include <sys/types.h>
3 #include <machine/cpu.h>
4 #include <minix/type.h>
5 #include <minix/board.h>
6 #include <io.h>
7 
8 #include "kernel/kernel.h"
9 #include "kernel/proc.h"
10 #include "kernel/vm.h"
11 #include "kernel/proto.h"
12 #include "arch_proto.h"
13 #include "bsp_reset.h"
14 
15 #include "omap_rtc.h"
16 
17 #define AM335X_CM_BASE 0x44E00000
18 #define AM335X_CM_SIZE 0x1000
19 
20 #define AM335X_PRM_DEVICE_OFFSET 0xf00
21 #define AM335X_PRM_RSTCTRL_REG 0x00
22 #define AM335X_RST_GLOBAL_WARM_SW_BIT 0
23 
24 #define DM37XX_CM_BASE 0x48307000
25 #define DM37XX_CM_SIZE 0x1000
26 #define DM37XX_PRM_RSTCTRL_REG 0x250
27 #define DM37XX_RST_DPLL3_BIT 2
28 
29 struct omap_reset
30 {
31 	vir_bytes base;
32 	vir_bytes size;
33 };
34 
35 static struct omap_reset omap_reset;
36 
37 static kern_phys_map reset_phys_map;
38 
39 void
40 bsp_reset_init(void)
41 {
42 	if (BOARD_IS_BBXM(machine.board_id)) {
43 		omap_reset.base = DM37XX_CM_BASE;
44 		omap_reset.size = DM37XX_CM_SIZE;
45 	} else if (BOARD_IS_BB(machine.board_id)) {
46 		omap_reset.base = AM335X_CM_BASE;
47 		omap_reset.size = AM335X_CM_SIZE;
48 	}
49 
50 	kern_phys_map_ptr(omap_reset.base, omap_reset.size,
51 	    VMMF_UNCACHED | VMMF_WRITE,
52 	    &reset_phys_map, (vir_bytes) & omap_reset.base);
53 }
54 
55 void
56 bsp_reset(void)
57 {
58 	if (BOARD_IS_BBXM(machine.board_id)) {
59 		mmio_set((omap_reset.base + DM37XX_PRM_RSTCTRL_REG),
60 		    (1 << DM37XX_RST_DPLL3_BIT));
61 	} else if (BOARD_IS_BB(machine.board_id)) {
62 		mmio_set((omap_reset.base + AM335X_PRM_DEVICE_OFFSET +
63 			AM335X_PRM_RSTCTRL_REG),
64 		    (1 << AM335X_RST_GLOBAL_WARM_SW_BIT));
65 	}
66 }
67 
68 void
69 bsp_poweroff(void)
70 {
71 
72 /*
73  * The am335x can signal an external power management chip to cut the power
74  * by toggling the PMIC_POWER_EN pin. It might fail if there isn't an
75  * external PMIC or if the PMIC hasn't been configured to respond to toggles.
76  * The only way to pull the pin low is via ALARM2 (see TRM 20.3.3.8).
77  * At this point PM should have already signaled readclock to set the alarm.
78  */
79 	if (BOARD_IS_BB(machine.board_id)) {
80 		/* rtc was frozen to prevent premature power-off, unfreeze it
81 		 * now */
82 		omap3_rtc_run();
83 
84 		/* wait for the alarm to go off and PMIC to disable power to
85 		 * SoC */
86 		while (1);
87 	}
88 }
89