Path: blob/master/drivers/clocksource/scx200_hrt.c
15111 views
/*1* Copyright (C) 2006 Jim Cromie2*3* This is a clocksource driver for the Geode SCx200's 1 or 27 MHz4* high-resolution timer. The Geode SC-1100 (at least) has a buggy5* time stamp counter (TSC), which loses time unless 'idle=poll' is6* given as a boot-arg. In its absence, the Generic Timekeeping code7* will detect and de-rate the bad TSC, allowing this timer to take8* over timekeeping duties.9*10* Based on work by John Stultz, and Ted Phelps (in a 2.6.12-rc6 patch)11*12* This program is free software; you can redistribute it and/or13* modify it under the terms of the GNU General Public License as14* published by the Free Software Foundation; either version 2 of the15* License, or (at your option) any later version.16*/1718#include <linux/clocksource.h>19#include <linux/init.h>20#include <linux/module.h>21#include <linux/ioport.h>22#include <linux/scx200.h>2324#define NAME "scx200_hrt"2526static int mhz27;27module_param(mhz27, int, 0); /* load time only */28MODULE_PARM_DESC(mhz27, "count at 27.0 MHz (default is 1.0 MHz)");2930static int ppm;31module_param(ppm, int, 0); /* load time only */32MODULE_PARM_DESC(ppm, "+-adjust to actual XO freq (ppm)");3334/* HiRes Timer configuration register address */35#define SCx200_TMCNFG_OFFSET (SCx200_TIMER_OFFSET + 5)3637/* and config settings */38#define HR_TMEN (1 << 0) /* timer interrupt enable */39#define HR_TMCLKSEL (1 << 1) /* 1|0 counts at 27|1 MHz */40#define HR_TM27MPD (1 << 2) /* 1 turns off input clock (power-down) */4142/* The base timer frequency, * 27 if selected */43#define HRT_FREQ 10000004445static cycle_t read_hrt(struct clocksource *cs)46{47/* Read the timer value */48return (cycle_t) inl(scx200_cb_base + SCx200_TIMER_OFFSET);49}5051#define HRT_SHIFT_1 2252#define HRT_SHIFT_27 265354static struct clocksource cs_hrt = {55.name = "scx200_hrt",56.rating = 250,57.read = read_hrt,58.mask = CLOCKSOURCE_MASK(32),59.flags = CLOCK_SOURCE_IS_CONTINUOUS,60/* mult, shift are set based on mhz27 flag */61};6263static int __init init_hrt_clocksource(void)64{65/* Make sure scx200 has initialized the configuration block */66if (!scx200_cb_present())67return -ENODEV;6869/* Reserve the timer's ISA io-region for ourselves */70if (!request_region(scx200_cb_base + SCx200_TIMER_OFFSET,71SCx200_TIMER_SIZE,72"NatSemi SCx200 High-Resolution Timer")) {73printk(KERN_WARNING NAME ": unable to lock timer region\n");74return -ENODEV;75}7677/* write timer config */78outb(HR_TMEN | (mhz27 ? HR_TMCLKSEL : 0),79scx200_cb_base + SCx200_TMCNFG_OFFSET);8081if (mhz27) {82cs_hrt.shift = HRT_SHIFT_27;83cs_hrt.mult = clocksource_hz2mult((HRT_FREQ + ppm) * 27,84cs_hrt.shift);85} else {86cs_hrt.shift = HRT_SHIFT_1;87cs_hrt.mult = clocksource_hz2mult(HRT_FREQ + ppm,88cs_hrt.shift);89}90printk(KERN_INFO "enabling scx200 high-res timer (%s MHz +%d ppm)\n",91mhz27 ? "27":"1", ppm);9293return clocksource_register(&cs_hrt);94}9596module_init(init_hrt_clocksource);9798MODULE_AUTHOR("Jim Cromie <[email protected]>");99MODULE_DESCRIPTION("clocksource on SCx200 HiRes Timer");100MODULE_LICENSE("GPL");101102103