From: Albert Lee <albertcc@tw.ibm.com>
To: Jeff Garzik <jgarzik@pobox.com>
Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>,
Doug Maxey <dwm@maxeymade.com>,
Linux IDE <linux-ide@vger.kernel.org>
Subject: Re: [PATCH 0/4] libata-dev-2.6: pdc2027x PLL input clock detection fix, etc.
Date: Mon, 11 Apr 2005 18:11:43 +0800 [thread overview]
Message-ID: <425A4D5F.2010903@tw.ibm.com> (raw)
In-Reply-To: <425A49F6.3040904@tw.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 1542 bytes --]
Hi Jeff,
Desc:
pdc2027x: fix the PLL input clock detection problem:
Sometimes the pdc2027x driver reads incorrect value from the counter and initialize the hardware with incorrect clock rate.
Root Cause:
- The PLL input clock counter on the pdc2027x is a 30-bit deceasing counter.
The driver reads the decreasing counter byte by byte and assemsble back the
whole 30-bit counter when detecting the PLL input clock rate on the fly.
- The driver reads the counter from LSB then MSB, byte by byte.
For example, for 7D030093, the driver read 93, 00, 03 and 7D,
piece by piece. (This is pdc2027x hardware limitation.)
- The counter is running when the driver reads it.
Ex. When 7D030093 decreasing to 7D027FFF, sometimes the driver will read 7D020093.
That is, when the driver read LSB, LSB 0093 is quite close to zero. Later when the
driver read MSB, MSB is already changed from 7D03 to 7D02. => The driver
assembles the wrong bytes and gets 7D020093.
Changes:
- Verify whether the driver is reading while the MSB bits of the counter is changing.
If yes, reread the counter. (Incorrect LSB bits only affect the result by less than 5% under 100ms
delay time and can be ignored.)
- Change the delay time from 1ms to 100ms. This can make the detected clock rate more accurate.
The extra time spent on rereading the counter is less than 1% compared to 100ms.
Attached please find the patch 4/4 against the libata-dev-2.6 tree for your review. Thanks.
Albert
Signed-off-by: Albert Lee <albertcc@tw.ibm.com>
[-- Attachment #2: pdc_060_2.diff --]
[-- Type: text/plain, Size: 2437 bytes --]
--- libata-dev-2.6-reorg/drivers/scsi/pata_pdc2027x.c 2005-04-11 15:05:28.000000000 +0800
+++ libata-dev-2.6-pll-fix/drivers/scsi/pata_pdc2027x.c 2005-04-11 15:05:42.000000000 +0800
@@ -29,7 +29,7 @@
#include <asm/io.h>
#define DRV_NAME "pata_pdc2027x"
-#define DRV_VERSION "0.59"
+#define DRV_VERSION "0.60"
#undef PDC_DEBUG
#ifdef PDC_DEBUG
@@ -463,7 +463,10 @@
{
u8 ctr0, ctr1, ctr2, ctr3;
unsigned long counter;
+ u8 ctr0v, ctr1v, ctr2v, ctr3v;
+ int retry = 1;
+retry:
outb(0x20, probe_ent->port[0].bmdma_addr + 0x01);
ctr0 = inb(probe_ent->port[0].bmdma_addr + 0x03);
outb(0x21, probe_ent->port[0].bmdma_addr + 0x01);
@@ -473,10 +476,32 @@
outb(0x21, probe_ent->port[1].bmdma_addr + 0x01);
ctr3 = inb(probe_ent->port[1].bmdma_addr + 0x03);
+ /* Read the counter values again for verification */
+ outb(0x20, probe_ent->port[0].bmdma_addr + 0x01);
+ ctr0v = inb(probe_ent->port[0].bmdma_addr + 0x03);
+ outb(0x21, probe_ent->port[0].bmdma_addr + 0x01);
+ ctr1v = inb(probe_ent->port[0].bmdma_addr + 0x03);
+ outb(0x20, probe_ent->port[1].bmdma_addr + 0x01);
+ ctr2v = inb(probe_ent->port[1].bmdma_addr + 0x03);
+ outb(0x21, probe_ent->port[1].bmdma_addr + 0x01);
+ ctr3v = inb(probe_ent->port[1].bmdma_addr + 0x03);
+
counter = (ctr3 << 23) | (ctr2 << 15) | (ctr1 << 8) | ctr0;
PDPRINTK("ctr0[%X] ctr1[%X] ctr2[%X] ctr3[%X]\n",
ctr0, ctr1, ctr2, ctr3);
+ PDPRINTK("ctr0[%X] ctr1[%X] ctr2[%X] ctr3[%X]\n",
+ ctr0v, ctr1v, ctr2v, ctr3v);
+
+ /*
+ * The 30-bit decreasing counter are read by 4 pieces.
+ * Incorrect value may be read when ctr2 and ctr3 are changing.
+ */
+ if (retry && !(ctr3 == ctr3v && ctr2 == ctr2v && ctr1 >= ctr1v)) {
+ retry--;
+ PDPRINTK("rereading counter\n");
+ goto retry;
+ }
return counter;
}
@@ -599,8 +624,8 @@
PDPRINTK("scr1[%X]\n", scr1);
outb(scr1 | 0x40, probe_ent->port[0].bmdma_addr + 0x03);
- /* Let the counter run for 1000 us. */
- udelay(1000);
+ /* Let the counter run for 100 ms. */
+ mdelay(100);
/* Read the counter values again */
end_count = pdc_read_counter(probe_ent);
@@ -612,7 +637,7 @@
outb(scr1 & 0xBF, probe_ent->port[0].bmdma_addr + 0x03);
/* calculate the input clock in Hz */
- pll_clock = (long) ((start_count - end_count) * 1000);
+ pll_clock = (long) ((start_count - end_count) * 10);
PDPRINTK("start[%lu] end[%lu] \n", start_count, end_count);
PDPRINTK("PLL input clock[%ld]Hz\n", pll_clock);
next prev parent reply other threads:[~2005-04-11 10:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-11 9:57 [PATCH 0/4] libata-dev-2.6: pdc2027x PLL input clock detection fix, etc Albert Lee
2005-04-11 10:02 ` [PATCH 1/4] libata-dev-2.6: pdc2027x add ata_scsi_ioctl Albert Lee
2005-05-16 2:38 ` Jeff Garzik
2005-04-11 10:04 ` [PATCH 2/4] libata-dev-2.6: pdc2027x change comments Albert Lee
2005-04-11 10:06 ` [PATCH 3/4] libata-dev-2.6: pdc2027x move the PLL counter reading code Albert Lee
2005-04-11 10:11 ` Albert Lee [this message]
2005-04-11 10:28 ` [PATCH 4/4] libata-dev-2.6: pdc2027x PLL input clock detection fix Albert Lee
2005-04-17 1:54 ` [PATCH 2.6.12-rc2 0/2] libata: add reporting of atapi errors Eric A. Cottrell
2005-04-19 6:08 ` [PATCH 1/1] libata-dev-2.6: pdc2027x ATAPI DMA fix Albert Lee
2005-04-27 8:55 ` Albert Lee
2005-04-29 3:19 ` [PATCH 1/1] libata-dev-2.6: pdc2027x yet another PLL fix Albert Lee
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=425A4D5F.2010903@tw.ibm.com \
--to=albertcc@tw.ibm.com \
--cc=bzolnier@gmail.com \
--cc=dwm@maxeymade.com \
--cc=jgarzik@pobox.com \
--cc=linux-ide@vger.kernel.org \
/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).