diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-28 13:51:43 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-28 13:51:43 -0400 |
commit | e31a94ed371c70855eb30b77c490d6d85dd4da26 (patch) | |
tree | 58d9f1a75a22319f97731db8d9ac07b78a8d8aaf /arch/mips/kernel/cevt-ds1287.c | |
parent | 9d9ad4b51d2b29b5bbeb4011f5e76f7538119cf9 (diff) | |
parent | fcbd3b4b92efe29b59df16b910138cf43683be88 (diff) |
Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
* 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus: (45 commits)
[MIPS] Pb1200/DBAu1200: move platform code to its proper place
[MIPS] Fix handling of trap and breakpoint instructions
[MIPS] Pb1200: do register SMC 91C111
[MIPS] DBAu1200: fix bad SMC 91C111 resource size
[NET] Kconfig: Rename MIKROTIK_RB500 -> MIKROTIK_RB532
[MIPS] IP27: Fix build bug due to missing include
[MIPS] Fix some sparse warnings on traps.c and irq-msc01.c
[MIPS] cevt-gt641xx: Kill unnecessary include
[MIPS] DS1287: Add clockevent driver
[MIPS] add DECstation I/O ASIC clocksource
[MIPS] rbtx4938: minor cleanup
[MIPS] Alchemy: kill unused PCI_IRQ_TABLE_LOOKUP macro
[MIPS] rbtx4938: misc cleanups
[MIPS] jmr3927: use generic txx9 gpio
[MIPS] rbhma4500: use generic txx9 gpio
[MIPS] generic txx9 gpio support
[MIPS] make fallback gpio.h gpiolib-friendly
[MIPS] unexport null_perf_irq() and make it static
[MIPS] unexport rtc_mips_set_time()
[MIPS] unexport copy_from_user_page()
...
Diffstat (limited to 'arch/mips/kernel/cevt-ds1287.c')
-rw-r--r-- | arch/mips/kernel/cevt-ds1287.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/arch/mips/kernel/cevt-ds1287.c b/arch/mips/kernel/cevt-ds1287.c new file mode 100644 index 000000000000..df4acb68bfb5 --- /dev/null +++ b/arch/mips/kernel/cevt-ds1287.c | |||
@@ -0,0 +1,129 @@ | |||
1 | /* | ||
2 | * DS1287 clockevent driver | ||
3 | * | ||
4 | * Copyright (C) 2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> | ||
5 | * | ||
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. | ||
10 | * | ||
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. | ||
15 | * | ||
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 | ||
19 | */ | ||
20 | #include <linux/clockchips.h> | ||
21 | #include <linux/init.h> | ||
22 | #include <linux/interrupt.h> | ||
23 | #include <linux/mc146818rtc.h> | ||
24 | |||
25 | #include <asm/time.h> | ||
26 | |||
27 | int ds1287_timer_state(void) | ||
28 | { | ||
29 | return (CMOS_READ(RTC_REG_C) & RTC_PF) != 0; | ||
30 | } | ||
31 | |||
32 | int ds1287_set_base_clock(unsigned int hz) | ||
33 | { | ||
34 | u8 rate; | ||
35 | |||
36 | switch (hz) { | ||
37 | case 128: | ||
38 | rate = 0x9; | ||
39 | break; | ||
40 | case 256: | ||
41 | rate = 0x8; | ||
42 | break; | ||
43 | case 1024: | ||
44 | rate = 0x6; | ||
45 | break; | ||
46 | default: | ||
47 | return -EINVAL; | ||
48 | } | ||
49 | |||
50 | CMOS_WRITE(RTC_REF_CLCK_32KHZ | rate, RTC_REG_A); | ||
51 | |||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | static int ds1287_set_next_event(unsigned long delta, | ||
56 | struct clock_event_device *evt) | ||
57 | { | ||
58 | return -EINVAL; | ||
59 | } | ||
60 | |||
61 | static void ds1287_set_mode(enum clock_event_mode mode, | ||
62 | struct clock_event_device *evt) | ||
63 | { | ||
64 | u8 val; | ||
65 | |||
66 | spin_lock(&rtc_lock); | ||
67 | |||
68 | val = CMOS_READ(RTC_REG_B); | ||
69 | |||
70 | switch (mode) { | ||
71 | case CLOCK_EVT_MODE_PERIODIC: | ||
72 | val |= RTC_PIE; | ||
73 | break; | ||
74 | default: | ||
75 | val &= ~RTC_PIE; | ||
76 | break; | ||
77 | } | ||
78 | |||
79 | CMOS_WRITE(val, RTC_REG_B); | ||
80 | |||
81 | spin_unlock(&rtc_lock); | ||
82 | } | ||
83 | |||
84 | static void ds1287_event_handler(struct clock_event_device *dev) | ||
85 | { | ||
86 | } | ||
87 | |||
88 | static struct clock_event_device ds1287_clockevent = { | ||
89 | .name = "ds1287", | ||
90 | .features = CLOCK_EVT_FEAT_PERIODIC, | ||
91 | .cpumask = CPU_MASK_CPU0, | ||
92 | .set_next_event = ds1287_set_next_event, | ||
93 | .set_mode = ds1287_set_mode, | ||
94 | .event_handler = ds1287_event_handler, | ||
95 | }; | ||
96 | |||
97 | static irqreturn_t ds1287_interrupt(int irq, void *dev_id) | ||
98 | { | ||
99 | struct clock_event_device *cd = &ds1287_clockevent; | ||
100 | |||
101 | /* Ack the RTC interrupt. */ | ||
102 | CMOS_READ(RTC_REG_C); | ||
103 | |||
104 | cd->event_handler(cd); | ||
105 | |||
106 | return IRQ_HANDLED; | ||
107 | } | ||
108 | |||
109 | static struct irqaction ds1287_irqaction = { | ||
110 | .handler = ds1287_interrupt, | ||
111 | .flags = IRQF_DISABLED | IRQF_PERCPU, | ||
112 | .name = "ds1287", | ||
113 | }; | ||
114 | |||
115 | int __init ds1287_clockevent_init(int irq) | ||
116 | { | ||
117 | struct clock_event_device *cd; | ||
118 | |||
119 | cd = &ds1287_clockevent; | ||
120 | cd->rating = 100; | ||
121 | cd->irq = irq; | ||
122 | clockevent_set_clock(cd, 32768); | ||
123 | cd->max_delta_ns = clockevent_delta2ns(0x7fffffff, cd); | ||
124 | cd->min_delta_ns = clockevent_delta2ns(0x300, cd); | ||
125 | |||
126 | clockevents_register_device(&ds1287_clockevent); | ||
127 | |||
128 | return setup_irq(irq, &ds1287_irqaction); | ||
129 | } | ||