rtc-at91rm9200.c (f838bad1b3be8ca0c785ee0e0c570dfda74cf377) rtc-at91rm9200.c (2a4e2b8780c6df42b19c053243dada7fa4d311ee)
1/*
2 * Real Time Clock interface for Linux on Atmel AT91RM9200
3 *
4 * Copyright (C) 2002 Rick Bronson
5 *
6 * Converted to RTC class model by Andrew Victor
7 *
8 * Ported to Linux 2.6 by Steven Scholz

--- 69 unchanged lines hidden (view full) ---

78 * Read current time and date in RTC
79 */
80static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm)
81{
82 at91_rtc_decodetime(AT91_RTC_TIMR, AT91_RTC_CALR, tm);
83 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
84 tm->tm_year = tm->tm_year - 1900;
85
1/*
2 * Real Time Clock interface for Linux on Atmel AT91RM9200
3 *
4 * Copyright (C) 2002 Rick Bronson
5 *
6 * Converted to RTC class model by Andrew Victor
7 *
8 * Ported to Linux 2.6 by Steven Scholz

--- 69 unchanged lines hidden (view full) ---

78 * Read current time and date in RTC
79 */
80static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm)
81{
82 at91_rtc_decodetime(AT91_RTC_TIMR, AT91_RTC_CALR, tm);
83 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
84 tm->tm_year = tm->tm_year - 1900;
85
86 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__,
86 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
87 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
88 tm->tm_hour, tm->tm_min, tm->tm_sec);
89
90 return 0;
91}
92
93/*
94 * Set current time and date in RTC
95 */
96static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
97{
98 unsigned long cr;
99
87 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
88 tm->tm_hour, tm->tm_min, tm->tm_sec);
89
90 return 0;
91}
92
93/*
94 * Set current time and date in RTC
95 */
96static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
97{
98 unsigned long cr;
99
100 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__,
100 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
101 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
102 tm->tm_hour, tm->tm_min, tm->tm_sec);
103
104 /* Stop Time/Calendar from counting */
105 cr = at91_sys_read(AT91_RTC_CR);
106 at91_sys_write(AT91_RTC_CR, cr | AT91_RTC_UPDCAL | AT91_RTC_UPDTIM);
107
108 at91_sys_write(AT91_RTC_IER, AT91_RTC_ACKUPD);

--- 28 unchanged lines hidden (view full) ---

137
138 at91_rtc_decodetime(AT91_RTC_TIMALR, AT91_RTC_CALALR, tm);
139 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
140 tm->tm_year = at91_alarm_year - 1900;
141
142 alrm->enabled = (at91_sys_read(AT91_RTC_IMR) & AT91_RTC_ALARM)
143 ? 1 : 0;
144
101 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
102 tm->tm_hour, tm->tm_min, tm->tm_sec);
103
104 /* Stop Time/Calendar from counting */
105 cr = at91_sys_read(AT91_RTC_CR);
106 at91_sys_write(AT91_RTC_CR, cr | AT91_RTC_UPDCAL | AT91_RTC_UPDTIM);
107
108 at91_sys_write(AT91_RTC_IER, AT91_RTC_ACKUPD);

--- 28 unchanged lines hidden (view full) ---

137
138 at91_rtc_decodetime(AT91_RTC_TIMALR, AT91_RTC_CALALR, tm);
139 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
140 tm->tm_year = at91_alarm_year - 1900;
141
142 alrm->enabled = (at91_sys_read(AT91_RTC_IMR) & AT91_RTC_ALARM)
143 ? 1 : 0;
144
145 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__,
145 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
146 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
147 tm->tm_hour, tm->tm_min, tm->tm_sec);
148
149 return 0;
150}
151
152/*
153 * Set alarm time and date in RTC

--- 19 unchanged lines hidden (view full) ---

173 at91_sys_write(AT91_RTC_CALALR,
174 BIN2BCD(tm.tm_mon + 1) << 16 /* tm_mon starts at zero */
175 | BIN2BCD(tm.tm_mday) << 24
176 | AT91_RTC_DATEEN | AT91_RTC_MTHEN);
177
178 if (alrm->enabled)
179 at91_sys_write(AT91_RTC_IER, AT91_RTC_ALARM);
180
146 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
147 tm->tm_hour, tm->tm_min, tm->tm_sec);
148
149 return 0;
150}
151
152/*
153 * Set alarm time and date in RTC

--- 19 unchanged lines hidden (view full) ---

173 at91_sys_write(AT91_RTC_CALALR,
174 BIN2BCD(tm.tm_mon + 1) << 16 /* tm_mon starts at zero */
175 | BIN2BCD(tm.tm_mday) << 24
176 | AT91_RTC_DATEEN | AT91_RTC_MTHEN);
177
178 if (alrm->enabled)
179 at91_sys_write(AT91_RTC_IER, AT91_RTC_ALARM);
180
181 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__,
181 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
182 at91_alarm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour,
183 tm.tm_min, tm.tm_sec);
184
185 return 0;
186}
187
188/*
189 * Handle commands from user-space
190 */
191static int at91_rtc_ioctl(struct device *dev, unsigned int cmd,
192 unsigned long arg)
193{
194 int ret = 0;
195
182 at91_alarm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour,
183 tm.tm_min, tm.tm_sec);
184
185 return 0;
186}
187
188/*
189 * Handle commands from user-space
190 */
191static int at91_rtc_ioctl(struct device *dev, unsigned int cmd,
192 unsigned long arg)
193{
194 int ret = 0;
195
196 pr_debug("%s(): cmd=%08x, arg=%08lx.\n", __FUNCTION__, cmd, arg);
196 pr_debug("%s(): cmd=%08x, arg=%08lx.\n", __func__, cmd, arg);
197
198 switch (cmd) {
199 case RTC_AIE_OFF: /* alarm off */
200 at91_sys_write(AT91_RTC_IDR, AT91_RTC_ALARM);
201 break;
202 case RTC_AIE_ON: /* alarm on */
203 at91_sys_write(AT91_RTC_IER, AT91_RTC_ALARM);
204 break;

--- 55 unchanged lines hidden (view full) ---

260 events |= (RTC_UF | RTC_IRQF);
261 if (rtsr & AT91_RTC_ACKUPD)
262 complete(&at91_rtc_updated);
263
264 at91_sys_write(AT91_RTC_SCCR, rtsr); /* clear status reg */
265
266 rtc_update_irq(rtc, 1, events);
267
197
198 switch (cmd) {
199 case RTC_AIE_OFF: /* alarm off */
200 at91_sys_write(AT91_RTC_IDR, AT91_RTC_ALARM);
201 break;
202 case RTC_AIE_ON: /* alarm on */
203 at91_sys_write(AT91_RTC_IER, AT91_RTC_ALARM);
204 break;

--- 55 unchanged lines hidden (view full) ---

260 events |= (RTC_UF | RTC_IRQF);
261 if (rtsr & AT91_RTC_ACKUPD)
262 complete(&at91_rtc_updated);
263
264 at91_sys_write(AT91_RTC_SCCR, rtsr); /* clear status reg */
265
266 rtc_update_irq(rtc, 1, events);
267
268 pr_debug("%s(): num=%ld, events=0x%02lx\n", __FUNCTION__,
268 pr_debug("%s(): num=%ld, events=0x%02lx\n", __func__,
269 events >> 8, events & 0x000000FF);
270
271 return IRQ_HANDLED;
272 }
273 return IRQ_NONE; /* not handled */
274}
275
276static const struct rtc_class_ops at91_rtc_ops = {

--- 134 unchanged lines hidden ---
269 events >> 8, events & 0x000000FF);
270
271 return IRQ_HANDLED;
272 }
273 return IRQ_NONE; /* not handled */
274}
275
276static const struct rtc_class_ops at91_rtc_ops = {

--- 134 unchanged lines hidden ---