xref: /openbmc/linux/arch/mips/kernel/csrc-ioasic.c (revision ada8e951)
14247417dSYoichi Yuasa /*
24247417dSYoichi Yuasa  *  DEC I/O ASIC's counter clocksource
34247417dSYoichi Yuasa  *
4ada8e951SYoichi Yuasa  *  Copyright (C) 2008  Yoichi Yuasa <yuasa@linux-mips.org>
54247417dSYoichi Yuasa  *
64247417dSYoichi Yuasa  *  This program is free software; you can redistribute it and/or modify
74247417dSYoichi Yuasa  *  it under the terms of the GNU General Public License as published by
84247417dSYoichi Yuasa  *  the Free Software Foundation; either version 2 of the License, or
94247417dSYoichi Yuasa  *  (at your option) any later version.
104247417dSYoichi Yuasa  *
114247417dSYoichi Yuasa  *  This program is distributed in the hope that it will be useful,
124247417dSYoichi Yuasa  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
134247417dSYoichi Yuasa  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
144247417dSYoichi Yuasa  *  GNU General Public License for more details.
154247417dSYoichi Yuasa  *
164247417dSYoichi Yuasa  *  You should have received a copy of the GNU General Public License
174247417dSYoichi Yuasa  *  along with this program; if not, write to the Free Software
184247417dSYoichi Yuasa  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
194247417dSYoichi Yuasa  */
204247417dSYoichi Yuasa #include <linux/clocksource.h>
214247417dSYoichi Yuasa #include <linux/init.h>
224247417dSYoichi Yuasa 
234247417dSYoichi Yuasa #include <asm/ds1287.h>
244247417dSYoichi Yuasa #include <asm/time.h>
254247417dSYoichi Yuasa #include <asm/dec/ioasic.h>
264247417dSYoichi Yuasa #include <asm/dec/ioasic_addrs.h>
274247417dSYoichi Yuasa 
288e19608eSMagnus Damm static cycle_t dec_ioasic_hpt_read(struct clocksource *cs)
294247417dSYoichi Yuasa {
304247417dSYoichi Yuasa 	return ioasic_read(IO_REG_FCTR);
314247417dSYoichi Yuasa }
324247417dSYoichi Yuasa 
334247417dSYoichi Yuasa static struct clocksource clocksource_dec = {
344247417dSYoichi Yuasa 	.name		= "dec-ioasic",
354247417dSYoichi Yuasa 	.read		= dec_ioasic_hpt_read,
364247417dSYoichi Yuasa 	.mask		= CLOCKSOURCE_MASK(32),
374247417dSYoichi Yuasa 	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
384247417dSYoichi Yuasa };
394247417dSYoichi Yuasa 
404247417dSYoichi Yuasa void __init dec_ioasic_clocksource_init(void)
414247417dSYoichi Yuasa {
424247417dSYoichi Yuasa 	unsigned int freq;
434247417dSYoichi Yuasa 	u32 start, end;
444247417dSYoichi Yuasa 	int i = HZ / 10;
454247417dSYoichi Yuasa 
464247417dSYoichi Yuasa 
474247417dSYoichi Yuasa 	while (!ds1287_timer_state())
484247417dSYoichi Yuasa 		;
494247417dSYoichi Yuasa 
508e19608eSMagnus Damm 	start = dec_ioasic_hpt_read(&clocksource_dec);
514247417dSYoichi Yuasa 
524247417dSYoichi Yuasa 	while (i--)
534247417dSYoichi Yuasa 		while (!ds1287_timer_state())
544247417dSYoichi Yuasa 			;
554247417dSYoichi Yuasa 
568e19608eSMagnus Damm 	end = dec_ioasic_hpt_read(&clocksource_dec);
574247417dSYoichi Yuasa 
584247417dSYoichi Yuasa 	freq = (end - start) * 10;
594247417dSYoichi Yuasa 	printk(KERN_INFO "I/O ASIC clock frequency %dHz\n", freq);
604247417dSYoichi Yuasa 
614247417dSYoichi Yuasa 	clocksource_dec.rating = 200 + freq / 10000000;
624247417dSYoichi Yuasa 	clocksource_set_clock(&clocksource_dec, freq);
634247417dSYoichi Yuasa 
644247417dSYoichi Yuasa 	clocksource_register(&clocksource_dec);
654247417dSYoichi Yuasa }
66