···11+/*22+ * DS1287 clockevent driver33+ *44+ * Copyright (C) 2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>55+ *66+ * This program is free software; you can redistribute it and/or modify77+ * it under the terms of the GNU General Public License as published by88+ * the Free Software Foundation; either version 2 of the License, or99+ * (at your option) any later version.1010+ *1111+ * This program is distributed in the hope that it will be useful,1212+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1313+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1414+ * GNU General Public License for more details.1515+ *1616+ * You should have received a copy of the GNU General Public License1717+ * along with this program; if not, write to the Free Software1818+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA1919+ */2020+#include <linux/clockchips.h>2121+#include <linux/init.h>2222+#include <linux/interrupt.h>2323+#include <linux/mc146818rtc.h>2424+2525+#include <asm/time.h>2626+2727+int ds1287_timer_state(void)2828+{2929+ return (CMOS_READ(RTC_REG_C) & RTC_PF) != 0;3030+}3131+3232+int ds1287_set_base_clock(unsigned int hz)3333+{3434+ u8 rate;3535+3636+ switch (hz) {3737+ case 128:3838+ rate = 0x9;3939+ break;4040+ case 256:4141+ rate = 0x8;4242+ break;4343+ case 1024:4444+ rate = 0x6;4545+ break;4646+ default:4747+ return -EINVAL;4848+ }4949+5050+ CMOS_WRITE(RTC_REF_CLCK_32KHZ | rate, RTC_REG_A);5151+5252+ return 0;5353+}5454+5555+static int ds1287_set_next_event(unsigned long delta,5656+ struct clock_event_device *evt)5757+{5858+ return -EINVAL;5959+}6060+6161+static void ds1287_set_mode(enum clock_event_mode mode,6262+ struct clock_event_device *evt)6363+{6464+ u8 val;6565+6666+ spin_lock(&rtc_lock);6767+6868+ val = CMOS_READ(RTC_REG_B);6969+7070+ switch (mode) {7171+ case CLOCK_EVT_MODE_PERIODIC:7272+ val |= RTC_PIE;7373+ break;7474+ default:7575+ val &= ~RTC_PIE;7676+ break;7777+ }7878+7979+ CMOS_WRITE(val, RTC_REG_B);8080+8181+ spin_unlock(&rtc_lock);8282+}8383+8484+static void ds1287_event_handler(struct clock_event_device *dev)8585+{8686+}8787+8888+static struct clock_event_device ds1287_clockevent = {8989+ .name = "ds1287",9090+ .features = CLOCK_EVT_FEAT_PERIODIC,9191+ .cpumask = CPU_MASK_CPU0,9292+ .set_next_event = ds1287_set_next_event,9393+ .set_mode = ds1287_set_mode,9494+ .event_handler = ds1287_event_handler,9595+};9696+9797+static irqreturn_t ds1287_interrupt(int irq, void *dev_id)9898+{9999+ struct clock_event_device *cd = &ds1287_clockevent;100100+101101+ /* Ack the RTC interrupt. */102102+ CMOS_READ(RTC_REG_C);103103+104104+ cd->event_handler(cd);105105+106106+ return IRQ_HANDLED;107107+}108108+109109+static struct irqaction ds1287_irqaction = {110110+ .handler = ds1287_interrupt,111111+ .flags = IRQF_DISABLED | IRQF_PERCPU,112112+ .name = "ds1287",113113+};114114+115115+int __init ds1287_clockevent_init(int irq)116116+{117117+ struct clock_event_device *cd;118118+119119+ cd = &ds1287_clockevent;120120+ cd->rating = 100;121121+ cd->irq = irq;122122+ clockevent_set_clock(cd, 32768);123123+ cd->max_delta_ns = clockevent_delta2ns(0x7fffffff, cd);124124+ cd->min_delta_ns = clockevent_delta2ns(0x300, cd);125125+126126+ clockevents_register_device(&ds1287_clockevent);127127+128128+ return setup_irq(irq, &ds1287_irqaction);129129+}
+27
include/asm-mips/ds1287.h
···11+/*22+ * DS1287 timer functions.33+ *44+ * Copyright (C) 2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>55+ *66+ * This program is free software; you can redistribute it and/or modify77+ * it under the terms of the GNU General Public License as published by88+ * the Free Software Foundation; either version 2 of the License, or99+ * (at your option) any later version.1010+ *1111+ * This program is distributed in the hope that it will be useful,1212+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1313+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1414+ * GNU General Public License for more details.1515+ *1616+ * You should have received a copy of the GNU General Public License1717+ * along with this program; if not, write to the Free Software1818+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA1919+ */2020+#ifndef __ASM_DS1287_H2121+#define __ASM_DS1287_H2222+2323+extern int ds1287_timer_state(void);2424+extern void ds1287_set_base_clock(unsigned int clock);2525+extern int ds1287_clockevent_init(int irq);2626+2727+#endif