2 * Faraday FTRTC010 Real Time Clock
4 * (C) Copyright 2009 Faraday Technology
5 * Po-Yu Chuang <ratbert@faraday-tech.com>
7 * SPDX-License-Identifier: GPL-2.0+
16 unsigned int sec; /* 0x00 */
17 unsigned int min; /* 0x04 */
18 unsigned int hour; /* 0x08 */
19 unsigned int day; /* 0x0c */
20 unsigned int alarm_sec; /* 0x10 */
21 unsigned int alarm_min; /* 0x14 */
22 unsigned int alarm_hour; /* 0x18 */
23 unsigned int record; /* 0x1c */
24 unsigned int cr; /* 0x20 */
25 unsigned int wsec; /* 0x24 */
26 unsigned int wmin; /* 0x28 */
27 unsigned int whour; /* 0x2c */
28 unsigned int wday; /* 0x30 */
29 unsigned int intr; /* 0x34 */
30 unsigned int div; /* 0x38 */
31 unsigned int rev; /* 0x3c */
35 * RTC Control Register
37 #define FTRTC010_CR_ENABLE (1 << 0)
38 #define FTRTC010_CR_INTERRUPT_SEC (1 << 1) /* per second irq */
39 #define FTRTC010_CR_INTERRUPT_MIN (1 << 2) /* per minute irq */
40 #define FTRTC010_CR_INTERRUPT_HR (1 << 3) /* per hour irq */
41 #define FTRTC010_CR_INTERRUPT_DAY (1 << 4) /* per day irq */
43 static struct ftrtc010 *rtc = (struct ftrtc010 *)CONFIG_FTRTC010_BASE;
45 static void ftrtc010_enable(void)
47 writel(FTRTC010_CR_ENABLE, &rtc->cr);
51 * return current time in seconds
53 static unsigned long ftrtc010_time(void)
59 unsigned long second2;
62 second = readl(&rtc->sec);
63 day = readl(&rtc->day);
64 hour = readl(&rtc->hour);
65 minute = readl(&rtc->min);
66 second2 = readl(&rtc->sec);
67 } while (second != second2);
69 return day * 24 * 60 * 60 + hour * 60 * 60 + minute * 60 + second;
73 * Get the current time from the RTC
76 int rtc_get(struct rtc_time *tmp)
80 debug("%s(): record register: %x\n",
81 __func__, readl(&rtc->record));
83 #ifdef CONFIG_FTRTC010_PCLK
84 now = (ftrtc010_time() + readl(&rtc->record)) / RTC_DIV_COUNT;
85 #else /* CONFIG_FTRTC010_EXTCLK */
86 now = ftrtc010_time() + readl(&rtc->record);
97 int rtc_set(struct rtc_time *tmp)
102 debug("%s(): DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
104 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
105 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
107 new = rtc_mktime(tmp);
109 now = ftrtc010_time();
111 debug("%s(): write %lx to record register\n", __func__, new - now);
113 writel(new - now, &rtc->record);
120 debug("%s()\n", __func__);