blob: bad740ad32188a954f33add9395f1d5baf8a068a [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Yoichi Yuasa42474172008-04-24 09:48:40 +09002/*
3 * DEC I/O ASIC's counter clocksource
4 *
Ralf Baechle70342282013-01-22 12:59:30 +01005 * Copyright (C) 2008 Yoichi Yuasa <yuasa@linux-mips.org>
Yoichi Yuasa42474172008-04-24 09:48:40 +09006 */
7#include <linux/clocksource.h>
Deng-Cheng Zhu7cb24b72015-03-07 10:30:28 -08008#include <linux/sched_clock.h>
Yoichi Yuasa42474172008-04-24 09:48:40 +09009#include <linux/init.h>
10
11#include <asm/ds1287.h>
12#include <asm/time.h>
13#include <asm/dec/ioasic.h>
14#include <asm/dec/ioasic_addrs.h>
15
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +010016static u64 dec_ioasic_hpt_read(struct clocksource *cs)
Yoichi Yuasa42474172008-04-24 09:48:40 +090017{
18 return ioasic_read(IO_REG_FCTR);
19}
20
21static struct clocksource clocksource_dec = {
22 .name = "dec-ioasic",
23 .read = dec_ioasic_hpt_read,
24 .mask = CLOCKSOURCE_MASK(32),
25 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
26};
27
Deng-Cheng Zhu7cb24b72015-03-07 10:30:28 -080028static u64 notrace dec_ioasic_read_sched_clock(void)
29{
30 return ioasic_read(IO_REG_FCTR);
31}
32
Maciej W. Rozyckidaed1282013-09-12 12:01:53 +010033int __init dec_ioasic_clocksource_init(void)
Yoichi Yuasa42474172008-04-24 09:48:40 +090034{
35 unsigned int freq;
36 u32 start, end;
Maciej W. Rozycki85339662013-09-04 23:47:45 +010037 int i = HZ / 8;
Yoichi Yuasa42474172008-04-24 09:48:40 +090038
Maciej W. Rozycki85339662013-09-04 23:47:45 +010039 ds1287_timer_state();
Yoichi Yuasa42474172008-04-24 09:48:40 +090040 while (!ds1287_timer_state())
41 ;
42
Magnus Damm8e196082009-04-21 12:24:00 -070043 start = dec_ioasic_hpt_read(&clocksource_dec);
Yoichi Yuasa42474172008-04-24 09:48:40 +090044
45 while (i--)
46 while (!ds1287_timer_state())
47 ;
48
Magnus Damm8e196082009-04-21 12:24:00 -070049 end = dec_ioasic_hpt_read(&clocksource_dec);
Yoichi Yuasa42474172008-04-24 09:48:40 +090050
Maciej W. Rozycki85339662013-09-04 23:47:45 +010051 freq = (end - start) * 8;
Maciej W. Rozyckidaed1282013-09-12 12:01:53 +010052
53 /* An early revision of the I/O ASIC didn't have the counter. */
54 if (!freq)
55 return -ENXIO;
56
Yoichi Yuasa42474172008-04-24 09:48:40 +090057 printk(KERN_INFO "I/O ASIC clock frequency %dHz\n", freq);
58
59 clocksource_dec.rating = 200 + freq / 10000000;
John Stultz75c4fd82010-04-26 20:23:11 -070060 clocksource_register_hz(&clocksource_dec, freq);
Deng-Cheng Zhu7cb24b72015-03-07 10:30:28 -080061
62 sched_clock_register(dec_ioasic_read_sched_clock, 32, freq);
63
Maciej W. Rozyckidaed1282013-09-12 12:01:53 +010064 return 0;
Yoichi Yuasa42474172008-04-24 09:48:40 +090065}