Commit 8006bf56 authored by Albert Lee's avatar Albert Lee Committed by Bartlomiej Zolnierkiewicz

ide: pdc202xx_new PLL input clock fix

Recently the PLL input clock of Promise 2027x is sometimes detected
higher than expected (e.g. 20.027 MHz compared to 16.714 MHz).
It seems sometimes the mdelay() function is not as precise as it
used to be. Per Alan's advice, HT or power management might affect
the precision of mdelay().

This patch calls gettimeofday() to measure the time elapsed and
calculate the PLL input clock accordingly.
Signed-off-by: default avatarAlbert Lee <albertcc@tw.ibm.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Bahadir Balban <bahadir.balban@gmail.com>
Acked-by: default avatarSergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
parent 52374f89
...@@ -306,11 +306,13 @@ static long __devinit read_counter(u32 dma_base) ...@@ -306,11 +306,13 @@ static long __devinit read_counter(u32 dma_base)
*/ */
static long __devinit detect_pll_input_clock(unsigned long dma_base) static long __devinit detect_pll_input_clock(unsigned long dma_base)
{ {
struct timeval start_time, end_time;
long start_count, end_count; long start_count, end_count;
long pll_input; long pll_input, usec_elapsed;
u8 scr1; u8 scr1;
start_count = read_counter(dma_base); start_count = read_counter(dma_base);
do_gettimeofday(&start_time);
/* Start the test mode */ /* Start the test mode */
outb(0x01, dma_base + 0x01); outb(0x01, dma_base + 0x01);
...@@ -322,6 +324,7 @@ static long __devinit detect_pll_input_clock(unsigned long dma_base) ...@@ -322,6 +324,7 @@ static long __devinit detect_pll_input_clock(unsigned long dma_base)
mdelay(10); mdelay(10);
end_count = read_counter(dma_base); end_count = read_counter(dma_base);
do_gettimeofday(&end_time);
/* Stop the test mode */ /* Stop the test mode */
outb(0x01, dma_base + 0x01); outb(0x01, dma_base + 0x01);
...@@ -333,7 +336,10 @@ static long __devinit detect_pll_input_clock(unsigned long dma_base) ...@@ -333,7 +336,10 @@ static long __devinit detect_pll_input_clock(unsigned long dma_base)
* Calculate the input clock in Hz * Calculate the input clock in Hz
* (the clock counter is 30 bit wide and counts down) * (the clock counter is 30 bit wide and counts down)
*/ */
pll_input = ((start_count - end_count) & 0x3ffffff) * 100; usec_elapsed = (end_time.tv_sec - start_time.tv_sec) * 1000000 +
(end_time.tv_usec - start_time.tv_usec);
pll_input = ((start_count - end_count) & 0x3ffffff) / 10 *
(10000000 / usec_elapsed);
DBG("start[%ld] end[%ld]\n", start_count, end_count); DBG("start[%ld] end[%ld]\n", start_count, end_count);
......
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