linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Albert Lee <albertcc@tw.ibm.com>
To: Jeff Garzik <jeff@garzik.org>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Sergei Shtylyov <sshtylyov@ru.mvista.com>,
	Bahadir Balban <bahadir.balban@gmail.com>,
	linux-ide@vger.kernel.org, Mikael Pettersson <mikpe@it.uu.se>,
	Doug Maxey <dwm@enoyolf.org>
Subject: [PATCH 1/1] libata: pata_pdc2027x PLL input clock fix
Date: Tue, 26 Jun 2007 13:43:15 +0800	[thread overview]
Message-ID: <4680A773.2020009@tw.ibm.com> (raw)
In-Reply-To: <46809EA7.5090005@tw.ibm.com>

Recently the PLL input clock of pata_pdc2027x is sometimes detected
higer 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 mesure the time elapsed and
calculate the PLL input clock accordingly.

Signed-off-by: Albert Lee <albertcc@tw.ibm.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
---

Did more test. For mdelay(100) the usec_elapsed is usually 99287.
However, sometimes the usec_elapsed is 118934, longer than expected.

Jun 26 12:12:29 p4ht-s kernel: [ 9156.490991] ACPI: PCI Interrupt 0000:02:05.0[A] -> Link [LNK1] -> GSI 10 (level, low) -> IRQ 10
Jun 26 12:12:29 p4ht-s kernel: [ 9156.610175] usec_elapsed[118934]
Jun 26 12:12:29 p4ht-s kernel: [ 9156.610511] pata_pdc2027x 0000:02:05.0: PLL input clock 16817 kHz

After the patch, the PLL input clock detected looks more accurate.
For your review, thanks.

diff -Nrup 00_libata-dev/drivers/ata/pata_pdc2027x.c 01_gettimeofday/drivers/ata/pata_pdc2027x.c
--- 00_libata-dev/drivers/ata/pata_pdc2027x.c	2007-06-01 12:08:21.000000000 +0800
+++ 01_gettimeofday/drivers/ata/pata_pdc2027x.c	2007-06-26 13:08:34.000000000 +0800
@@ -689,10 +689,12 @@ static long pdc_detect_pll_input_clock(s
 	void __iomem *mmio_base = host->iomap[PDC_MMIO_BAR];
 	u32 scr;
 	long start_count, end_count;
-	long pll_clock;
+	struct timeval start_time, end_time;
+	long pll_clock, usec_elapsed;
 
 	/* Read current counter value */
 	start_count = pdc_read_counter(host);
+	do_gettimeofday(&start_time);
 
 	/* Start the test mode */
 	scr = readl(mmio_base + PDC_SYS_CTL);
@@ -705,6 +707,7 @@ static long pdc_detect_pll_input_clock(s
 
 	/* Read the counter values again */
 	end_count = pdc_read_counter(host);
+	do_gettimeofday(&end_time);
 
 	/* Stop the test mode */
 	scr = readl(mmio_base + PDC_SYS_CTL);
@@ -713,7 +716,11 @@ static long pdc_detect_pll_input_clock(s
 	readl(mmio_base + PDC_SYS_CTL); /* flush */
 
 	/* calculate the input clock in Hz */
-	pll_clock = (start_count - end_count) * 10;
+	usec_elapsed = (end_time.tv_sec - start_time.tv_sec) * 1000000 +
+		(end_time.tv_usec - start_time.tv_usec);
+
+	pll_clock = (start_count - end_count) / 100 *
+		(100000000 / usec_elapsed);
 
 	PDPRINTK("start[%ld] end[%ld] \n", start_count, end_count);
 	PDPRINTK("PLL input clock[%ld]Hz\n", pll_clock);



  reply	other threads:[~2007-06-26  5:43 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-21 11:47 ide/dma not working from 2.6.19 to 2.6.21 Bahadir Balban
2007-06-21 15:28 ` Sergei Shtylyov
2007-06-21 18:17   ` Sergei Shtylyov
2007-06-25  5:22   ` Albert Lee
2007-06-25  9:10     ` Alan Cox
2007-06-26  5:05       ` Albert Lee
2007-06-26  5:43         ` Albert Lee [this message]
2007-07-02 14:14           ` [PATCH 1/1] libata: pata_pdc2027x PLL input clock fix Jeff Garzik
2007-07-02 18:13           ` Bartlomiej Zolnierkiewicz
2007-07-02 18:00             ` Sergei Shtylyov
2007-07-03  5:21               ` [PATCH 1/1] ide: pdc202xx_new " Albert Lee
2007-07-03 14:24                 ` Sergei Shtylyov
2007-07-03 18:59                   ` Bartlomiej Zolnierkiewicz
2007-07-03 20:36                     ` Sergei Shtylyov
2007-07-04  8:20                       ` Albert Lee
2007-07-03 18:57                 ` Bartlomiej Zolnierkiewicz
2007-07-20 14:38                 ` Bahadir Balban
  -- strict thread matches above, loose matches on Subject: below --
2007-07-09 23:04 [PATCH 1/1] libata: pata_pdc2027x " Mikael Pettersson
2007-07-10  3:52 ` Albert Lee
2007-08-16 19:11 ` Jeff Garzik
2007-08-16 20:19   ` Alan Cox
2007-07-10 23:14 Mikael Pettersson
2007-07-11  2:45 ` Albert Lee
2007-07-11 10:26 Mikael Pettersson
2007-07-16  9:12 ` Albert Lee
2007-08-17 20:51 Mikael Pettersson
2007-10-14 17:31 ` Jeff Garzik
2007-10-14 18:33 Mikael Pettersson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4680A773.2020009@tw.ibm.com \
    --to=albertcc@tw.ibm.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=albertl@mail.com \
    --cc=bahadir.balban@gmail.com \
    --cc=dwm@enoyolf.org \
    --cc=jeff@garzik.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=mikpe@it.uu.se \
    --cc=sshtylyov@ru.mvista.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).