blob: 54e394df9f7adb277f5e730efe95b66e7ed3c5c1 [file] [log] [blame]
Yoichi Yuasa42474172008-04-24 09:48:40 +09001/*
2 * DEC I/O ASIC's counter clocksource
3 *
Ralf Baechle70342282013-01-22 12:59:30 +01004 * Copyright (C) 2008 Yoichi Yuasa <yuasa@linux-mips.org>
Yoichi Yuasa42474172008-04-24 09:48:40 +09005 *
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.
Yoichi Yuasa42474172008-04-24 09:48:40 +090015 */
16#include <linux/clocksource.h>
17#include <linux/init.h>
18
19#include <asm/ds1287.h>
20#include <asm/time.h>
21#include <asm/dec/ioasic.h>
22#include <asm/dec/ioasic_addrs.h>
23
Magnus Damm8e196082009-04-21 12:24:00 -070024static cycle_t dec_ioasic_hpt_read(struct clocksource *cs)
Yoichi Yuasa42474172008-04-24 09:48:40 +090025{
26 return ioasic_read(IO_REG_FCTR);
27}
28
29static struct clocksource clocksource_dec = {
30 .name = "dec-ioasic",
31 .read = dec_ioasic_hpt_read,
32 .mask = CLOCKSOURCE_MASK(32),
33 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
34};
35
Maciej W. Rozyckidaed1282013-09-12 12:01:53 +010036int __init dec_ioasic_clocksource_init(void)
Yoichi Yuasa42474172008-04-24 09:48:40 +090037{
38 unsigned int freq;
39 u32 start, end;
Maciej W. Rozycki85339662013-09-04 23:47:45 +010040 int i = HZ / 8;
Yoichi Yuasa42474172008-04-24 09:48:40 +090041
Maciej W. Rozycki85339662013-09-04 23:47:45 +010042 ds1287_timer_state();
Yoichi Yuasa42474172008-04-24 09:48:40 +090043 while (!ds1287_timer_state())
44 ;
45
Magnus Damm8e196082009-04-21 12:24:00 -070046 start = dec_ioasic_hpt_read(&clocksource_dec);
Yoichi Yuasa42474172008-04-24 09:48:40 +090047
48 while (i--)
49 while (!ds1287_timer_state())
50 ;
51
Magnus Damm8e196082009-04-21 12:24:00 -070052 end = dec_ioasic_hpt_read(&clocksource_dec);
Yoichi Yuasa42474172008-04-24 09:48:40 +090053
Maciej W. Rozycki85339662013-09-04 23:47:45 +010054 freq = (end - start) * 8;
Maciej W. Rozyckidaed1282013-09-12 12:01:53 +010055
56 /* An early revision of the I/O ASIC didn't have the counter. */
57 if (!freq)
58 return -ENXIO;
59
Yoichi Yuasa42474172008-04-24 09:48:40 +090060 printk(KERN_INFO "I/O ASIC clock frequency %dHz\n", freq);
61
62 clocksource_dec.rating = 200 + freq / 10000000;
John Stultz75c4fd82010-04-26 20:23:11 -070063 clocksource_register_hz(&clocksource_dec, freq);
Maciej W. Rozyckidaed1282013-09-12 12:01:53 +010064 return 0;
Yoichi Yuasa42474172008-04-24 09:48:40 +090065}