gsmmap: Dump SYSTEM INFORMATION messages while processing
[osmocom-bb.git] / src / target / firmware / calypso / rtc.c
1 /* Driver for Calypso RTC controller */
2
3 /* (C) 2010 by Harald Welte <laforge@gnumonks.org>
4  *
5  * All Rights Reserved
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22
23 #include <stdint.h>
24 #include <stdio.h>
25
26 #include <defines.h>
27 #include <debug.h>
28 #include <memory.h>
29 #include <display.h>
30 #include <calypso/irq.h>
31
32 #define BASE_ADDR_RTC   0xfffe1800
33 #define RTC_REG(x)      ((void *)BASE_ADDR_RTC + (x))
34
35 enum rtc_reg {
36         SECOND_REG              = 0x00,
37         MINUTES_REG             = 0x01,
38         HOURS_REG               = 0x02,
39         DAYS_REG                = 0x03,
40         MONTHS_REG              = 0x04,
41         YEARS_REG               = 0x05,
42         WEEK_REG                = 0x06,
43         /* reserved */
44         ALARM_SECOND_REG        = 0x08,
45         ALARM_MINUTES_REG       = 0x09,
46         ALARM_HOURS_REG         = 0x0a,
47         ALARM_DAYS_REG          = 0x0b,
48         ALARM_MONTHS_REG        = 0x0c,
49         ALARM_YEARS_REG         = 0x0d,
50         /* reserved */
51         /* reserved */
52         CTRL_REG                = 0x10,
53         STATUS_REG              = 0x11,
54         INT_REG                 = 0x12,
55         COMP_LSB_REG            = 0x13,
56         COMP_MSB_REG            = 0x14,
57         RES_PROG_REG            = 0x15,
58 };
59
60 static int tick_ctr;
61
62 static void rtc_irq_tick(__unused enum irq_nr nr)
63 {
64         if (tick_ctr & 1)
65                 display_set_attr(DISP_ATTR_INVERT);
66         else
67                 display_unset_attr(DISP_ATTR_INVERT);
68         tick_ctr++;
69 }
70
71 void rtc_init(void)
72 {
73         irq_register_handler(IRQ_RTC_TIMER, &rtc_irq_tick);
74         irq_config(IRQ_RTC_TIMER, 0, 1, 0);
75         irq_enable(IRQ_RTC_TIMER);
76
77         /* clear power-up reset */
78         writeb(0x80, RTC_REG(STATUS_REG));
79         /* enable RTC running */
80         writeb(0x01, RTC_REG(CTRL_REG));
81         /* enable periodic interrupts every second */
82         writeb(0x04, RTC_REG(INT_REG));
83 }