1 // SPDX-License-Identifier: GPL-2.0+
3 * Faraday FTRTC010 Real Time Clock
5 * (C) Copyright 2009 Faraday Technology
6 * Po-Yu Chuang <ratbert@faraday-tech.com>
15 unsigned int sec; /* 0x00 */
16 unsigned int min; /* 0x04 */
17 unsigned int hour; /* 0x08 */
18 unsigned int day; /* 0x0c */
19 unsigned int alarm_sec; /* 0x10 */
20 unsigned int alarm_min; /* 0x14 */
21 unsigned int alarm_hour; /* 0x18 */
22 unsigned int record; /* 0x1c */
23 unsigned int cr; /* 0x20 */
24 unsigned int wsec; /* 0x24 */
25 unsigned int wmin; /* 0x28 */
26 unsigned int whour; /* 0x2c */
27 unsigned int wday; /* 0x30 */
28 unsigned int intr; /* 0x34 */
29 unsigned int div; /* 0x38 */
30 unsigned int rev; /* 0x3c */
34 * RTC Control Register
36 #define FTRTC010_CR_ENABLE (1 << 0)
37 #define FTRTC010_CR_INTERRUPT_SEC (1 << 1) /* per second irq */
38 #define FTRTC010_CR_INTERRUPT_MIN (1 << 2) /* per minute irq */
39 #define FTRTC010_CR_INTERRUPT_HR (1 << 3) /* per hour irq */
40 #define FTRTC010_CR_INTERRUPT_DAY (1 << 4) /* per day irq */
42 static struct ftrtc010 *rtc = (struct ftrtc010 *)CONFIG_FTRTC010_BASE;
44 static void ftrtc010_enable(void)
46 writel(FTRTC010_CR_ENABLE, &rtc->cr);
50 * return current time in seconds
52 static unsigned long ftrtc010_time(void)
58 unsigned long second2;
61 second = readl(&rtc->sec);
62 day = readl(&rtc->day);
63 hour = readl(&rtc->hour);
64 minute = readl(&rtc->min);
65 second2 = readl(&rtc->sec);
66 } while (second != second2);
68 return day * 24 * 60 * 60 + hour * 60 * 60 + minute * 60 + second;
72 * Get the current time from the RTC
75 int rtc_get(struct rtc_time *tmp)
79 debug("%s(): record register: %x\n",
80 __func__, readl(&rtc->record));
82 #ifdef CONFIG_FTRTC010_PCLK
83 now = (ftrtc010_time() + readl(&rtc->record)) / RTC_DIV_COUNT;
84 #else /* CONFIG_FTRTC010_EXTCLK */
85 now = ftrtc010_time() + readl(&rtc->record);
96 int rtc_set(struct rtc_time *tmp)
101 debug("%s(): DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
103 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
104 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
106 new = rtc_mktime(tmp);
108 now = ftrtc010_time();
110 debug("%s(): write %lx to record register\n", __func__, new - now);
112 writel(new - now, &rtc->record);
119 debug("%s()\n", __func__);