2 * DS1287 clockevent driver
4 * Copyright (C) 2008 Yoichi Yuasa <yuasa@linux-mips.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <linux/clockchips.h>
21 #include <linux/init.h>
22 #include <linux/interrupt.h>
23 #include <linux/mc146818rtc.h>
24 #include <linux/irq.h>
28 int ds1287_timer_state(void)
30 return (CMOS_READ(RTC_REG_C
) & RTC_PF
) != 0;
33 int ds1287_set_base_clock(unsigned int hz
)
51 CMOS_WRITE(RTC_REF_CLCK_32KHZ
| rate
, RTC_REG_A
);
56 static int ds1287_set_next_event(unsigned long delta
,
57 struct clock_event_device
*evt
)
62 static int ds1287_shutdown(struct clock_event_device
*evt
)
68 val
= CMOS_READ(RTC_REG_B
);
70 CMOS_WRITE(val
, RTC_REG_B
);
72 spin_unlock(&rtc_lock
);
76 static int ds1287_set_periodic(struct clock_event_device
*evt
)
82 val
= CMOS_READ(RTC_REG_B
);
84 CMOS_WRITE(val
, RTC_REG_B
);
86 spin_unlock(&rtc_lock
);
90 static void ds1287_event_handler(struct clock_event_device
*dev
)
94 static struct clock_event_device ds1287_clockevent
= {
96 .features
= CLOCK_EVT_FEAT_PERIODIC
,
97 .set_next_event
= ds1287_set_next_event
,
98 .set_state_shutdown
= ds1287_shutdown
,
99 .set_state_periodic
= ds1287_set_periodic
,
100 .tick_resume
= ds1287_shutdown
,
101 .event_handler
= ds1287_event_handler
,
104 static irqreturn_t
ds1287_interrupt(int irq
, void *dev_id
)
106 struct clock_event_device
*cd
= &ds1287_clockevent
;
108 /* Ack the RTC interrupt. */
109 CMOS_READ(RTC_REG_C
);
111 cd
->event_handler(cd
);
116 static struct irqaction ds1287_irqaction
= {
117 .handler
= ds1287_interrupt
,
118 .flags
= IRQF_PERCPU
| IRQF_TIMER
,
122 int __init
ds1287_clockevent_init(int irq
)
124 struct clock_event_device
*cd
;
126 cd
= &ds1287_clockevent
;
129 clockevent_set_clock(cd
, 32768);
130 cd
->max_delta_ns
= clockevent_delta2ns(0x7fffffff, cd
);
131 cd
->min_delta_ns
= clockevent_delta2ns(0x300, cd
);
132 cd
->cpumask
= cpumask_of(0);
134 clockevents_register_device(&ds1287_clockevent
);
136 return setup_irq(irq
, &ds1287_irqaction
);