xref: /minix/minix/kernel/arch/earm/bsp/ti/omap_rtc.c (revision 7f5f010b)
1 /*
2  * This is a mini driver for the AM335X Real Time Clock. The majority of the
3  * work is done in user space in readclock, but for power-off the clock needs
4  * to be put into run mode at the last possible moment in arch_reset.c. This
5  * driver just implements mapping the memory and re-starting the clock.
6  */
7 
8 #include <assert.h>
9 #include <sys/types.h>
10 #include <machine/cpu.h>
11 #include <minix/type.h>
12 #include <minix/board.h>
13 #include <io.h>
14 
15 #include "kernel/kernel.h"
16 #include "kernel/proc.h"
17 #include "kernel/vm.h"
18 #include "kernel/proto.h"
19 #include "arch_proto.h"
20 #include "omap_rtc.h"
21 
22 #define RTC_SS_BASE 0x44e3e000
23 #define RTC_SS_SIZE 0x1000
24 #define RTC_CTRL_REG 0x40
25 #define RTC_CTRL_RTC_STOP_BIT 0
26 
27 struct omap_rtc
28 {
29 	vir_bytes base;
30 	vir_bytes size;
31 };
32 
33 static struct omap_rtc omap_rtc = {
34 	.base = RTC_SS_BASE,
35 	.size = RTC_SS_SIZE
36 };
37 
38 static kern_phys_map rtc_phys_map;
39 
40 void
41 omap3_rtc_init(void)
42 {
43 	if (BOARD_IS_BB(machine.board_id)) {
44 		kern_phys_map_ptr(omap_rtc.base, omap_rtc.size,
45 		    VMMF_UNCACHED | VMMF_WRITE, &rtc_phys_map,
46 		    (vir_bytes) & omap_rtc.base);
47 	}
48 }
49 
50 void
51 omap3_rtc_run(void)
52 {
53 	if (BOARD_IS_BB(machine.board_id)) {
54 		/* Setting the stop bit starts the RTC running */
55 		mmio_set((omap_rtc.base + RTC_CTRL_REG),
56 		    (1 << RTC_CTRL_RTC_STOP_BIT));
57 	}
58 }
59