Commit 80c44e42 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] CLOCK_TICK_RATE: introduce asm-*/8253pit.h, #define PIT_TICK_RATE constant.

From: Thorsten Kranzkowski <dl8bcu@dl8bcu.de>

The calculation of the counter values in drivers/input/misc/pcspkr.c is
incorrectly based on CLOCK_TICK_RATE.  This goes unnoticed in i386 because
there the system clock is driven by the same Programmable Interval Timer chip
as the speaker.  But this doesn't hold true on other archs, e.g.  Alpha.

To solve this problem I made these patches:

1/3:    introduce asm-*/8253pit.h, #define PIT_TICK_RATE constant.
        It seems this is not always the same value.
2/3:    use PIT_TICK_RATE in *spkr.c
3/3:    use CLOCK_TICK_RATE where 1193180 was used in general timing
        calculations. (optional)

There are still some places where the magic number is used instead of the
#define (vt_ioctl.c, gameport.c) but I left them as-is.  I got some responses
from arch maintainers to specifically not touch their respective architectures
so changing these places would mean breakage for them.

Tested on Alpha and i386, ack'ed by Ralf Baechle for MIPS.


This patch:

introduce asm-*/8253pit.h, #define PIT_TICK_RATE constant.
parent 2a12ed0e
......@@ -45,6 +45,7 @@
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/hwrpb.h>
#include <asm/8253pit.h>
#include <linux/mc146818rtc.h>
#include <linux/time.h>
......@@ -254,12 +255,11 @@ validate_cc_value(unsigned long cc)
* arch/i386/time.c.
*/
#define PIC_TICK_RATE 1193180UL
#define CALIBRATE_LATCH 0xffff
#define TIMEOUT_COUNT 0x100000
static unsigned long __init
calibrate_cc_with_pic(void)
calibrate_cc_with_pit(void)
{
int cc, count = 0;
......@@ -287,7 +287,7 @@ calibrate_cc_with_pic(void)
if (count <= 1 || count == TIMEOUT_COUNT)
return 0;
return ((long)cc * PIC_TICK_RATE) / (CALIBRATE_LATCH + 1);
return ((long)cc * PIT_TICK_RATE) / (CALIBRATE_LATCH + 1);
}
/* The Linux interpretation of the CMOS clock register contents:
......@@ -313,7 +313,7 @@ time_init(void)
/* Calibrate CPU clock -- attempt #1. */
if (!est_cycle_freq)
est_cycle_freq = validate_cc_value(calibrate_cc_with_pic());
est_cycle_freq = validate_cc_value(calibrate_cc_with_pit());
cc1 = rpcc_after_update_in_progress();
......
/*
* 8253/8254 Programmable Interval Timer
*/
#ifndef _8253PIT_H
#define _8253PIT_H
#define PIT_TICK_RATE 1193180UL
#endif
/*
* 8253/8254 Programmable Interval Timer
*/
#ifndef _8253PIT_H
#define _8253PIT_H
#include <asm/timex.h>
#define PIT_TICK_RATE CLOCK_TICK_RATE
#endif
/*
* 8253/8254 Programmable Interval Timer
*/
#ifndef _8253PIT_H
#define _8253PIT_H
#define PIT_TICK_RATE 1193182UL
#endif
/*
* 8253/8254 Programmable Interval Timer
*/
#ifndef _8253PIT_H
#define _8253PIT_H
#define PIT_TICK_RATE 1193182UL
#endif
......@@ -7,11 +7,12 @@
#define _ASMx8664_TIMEX_H
#include <linux/config.h>
#include <asm/8253pit.h>
#include <asm/msr.h>
#include <asm/vsyscall.h>
#include <asm/hpet.h>
#define CLOCK_TICK_RATE 1193182 /* Underlying HZ */
#define CLOCK_TICK_RATE PIT_TICK_RATE /* Underlying HZ */
#define CLOCK_TICK_FACTOR 20 /* Factor of both 1000000 and CLOCK_TICK_RATE */
#define FINETUNE ((((((int)LATCH * HZ - CLOCK_TICK_RATE) << SHIFT_HZ) * \
(1000000/CLOCK_TICK_FACTOR) / (CLOCK_TICK_RATE/CLOCK_TICK_FACTOR)) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment