blob: 64f9e829443405e86bfdf154db3bceb53791d766 [file] [log] [blame]
Jim Cromie6ae74402006-06-26 00:25:19 -07001/*
2 * Copyright (C) 2006 Jim Cromie
3 *
4 * This is a clocksource driver for the Geode SCx200's 1 or 27 MHz
5 * high-resolution timer. The Geode SC-1100 (at least) has a buggy
6 * time stamp counter (TSC), which loses time unless 'idle=poll' is
7 * given as a boot-arg. In its absence, the Generic Timekeeping code
8 * will detect and de-rate the bad TSC, allowing this timer to take
9 * over timekeeping duties.
10 *
11 * Based on work by John Stultz, and Ted Phelps (in a 2.6.12-rc6 patch)
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of the
16 * License, or (at your option) any later version.
17 */
18
19#include <linux/clocksource.h>
20#include <linux/init.h>
21#include <linux/module.h>
22#include <linux/ioport.h>
23#include <linux/scx200.h>
24
25#define NAME "scx200_hrt"
26
27static int mhz27;
28module_param(mhz27, int, 0); /* load time only */
29MODULE_PARM_DESC(mhz27, "count at 27.0 MHz (default is 1.0 MHz)");
30
31static int ppm;
32module_param(ppm, int, 0); /* load time only */
33MODULE_PARM_DESC(ppm, "+-adjust to actual XO freq (ppm)");
34
35/* HiRes Timer configuration register address */
36#define SCx200_TMCNFG_OFFSET (SCx200_TIMER_OFFSET + 5)
37
38/* and config settings */
39#define HR_TMEN (1 << 0) /* timer interrupt enable */
40#define HR_TMCLKSEL (1 << 1) /* 1|0 counts at 27|1 MHz */
41#define HR_TM27MPD (1 << 2) /* 1 turns off input clock (power-down) */
42
43/* The base timer frequency, * 27 if selected */
44#define HRT_FREQ 1000000
45
Magnus Damm8e196082009-04-21 12:24:00 -070046static cycle_t read_hrt(struct clocksource *cs)
Jim Cromie6ae74402006-06-26 00:25:19 -070047{
48 /* Read the timer value */
49 return (cycle_t) inl(scx200_cb_base + SCx200_TIMER_OFFSET);
50}
51
Jim Cromie6ae74402006-06-26 00:25:19 -070052static struct clocksource cs_hrt = {
53 .name = "scx200_hrt",
54 .rating = 250,
55 .read = read_hrt,
56 .mask = CLOCKSOURCE_MASK(32),
Thomas Gleixner73b08d22007-02-16 01:27:36 -080057 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
Jim Cromie6ae74402006-06-26 00:25:19 -070058 /* mult, shift are set based on mhz27 flag */
59};
60
61static int __init init_hrt_clocksource(void)
62{
John Stultz12d6d412012-01-09 16:15:03 -080063 u32 freq;
Jim Cromie856fe982006-10-04 02:15:35 -070064 /* Make sure scx200 has initialized the configuration block */
Jim Cromie6ae74402006-06-26 00:25:19 -070065 if (!scx200_cb_present())
66 return -ENODEV;
67
68 /* Reserve the timer's ISA io-region for ourselves */
69 if (!request_region(scx200_cb_base + SCx200_TIMER_OFFSET,
70 SCx200_TIMER_SIZE,
71 "NatSemi SCx200 High-Resolution Timer")) {
Jim Cromied976f762012-01-26 15:52:15 -080072 pr_warn("unable to lock timer region\n");
Jim Cromie6ae74402006-06-26 00:25:19 -070073 return -ENODEV;
74 }
75
76 /* write timer config */
Jim Cromie856fe982006-10-04 02:15:35 -070077 outb(HR_TMEN | (mhz27 ? HR_TMCLKSEL : 0),
Jim Cromie6ae74402006-06-26 00:25:19 -070078 scx200_cb_base + SCx200_TMCNFG_OFFSET);
79
John Stultz12d6d412012-01-09 16:15:03 -080080 freq = (HRT_FREQ + ppm);
81 if (mhz27)
82 freq *= 27;
83
Ingo Molnar10ea9d62012-02-22 13:19:37 +010084 pr_info("enabling scx200 high-res timer (%s MHz +%d ppm)\n", mhz27 ? "27":"1", ppm);
Jim Cromie6ae74402006-06-26 00:25:19 -070085
John Stultz12d6d412012-01-09 16:15:03 -080086 return clocksource_register_hz(&cs_hrt, freq);
Jim Cromie6ae74402006-06-26 00:25:19 -070087}
88
89module_init(init_hrt_clocksource);
90
91MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
92MODULE_DESCRIPTION("clocksource on SCx200 HiRes Timer");
93MODULE_LICENSE("GPL");