linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
To: linux-ide@vger.kernel.org
Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 33/64] cy82c693: fix PIO timings calculations
Date: Mon, 18 Jan 2010 18:18:47 +0100	[thread overview]
Message-ID: <20100118171847.14623.38391.sendpatchset@localhost> (raw)
In-Reply-To: <20100118171349.14623.90030.sendpatchset@localhost>

From: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Subject: [PATCH] cy82c693: fix PIO timings calculations

Just use the standard ide_timing_compute() helper to calculate
PIO timings.  This fixes many issues with the open-coded version
like using 16-bit timings when 8-bit ones should be used or not
accounting for the enhanced cycle time specified by the device.

Based on libata pata_cypress host driver.

Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/cy82c693.c |  106 +++++++++----------------------------------------
 1 file changed, 20 insertions(+), 86 deletions(-)

Index: b/drivers/ide/cy82c693.c
===================================================================
--- a/drivers/ide/cy82c693.c
+++ b/drivers/ide/cy82c693.c
@@ -1,6 +1,7 @@
 /*
  *  Copyright (C) 1998-2000 Andreas S. Krebs (akrebs@altavista.net), Maintainer
  *  Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>, Integrator
+ *  Copyright (C) 2007-2010 Bartlomiej Zolnierkiewicz
  *
  * CYPRESS CY82C693 chipset IDE controller
  *
@@ -81,80 +82,6 @@
 #define CY82_INDEX_CHANNEL1	0x31
 #define CY82_INDEX_TIMEOUT	0x32
 
-/* the min and max PCI bus speed in MHz - from datasheet */
-#define CY82C963_MIN_BUS_SPEED	25
-#define CY82C963_MAX_BUS_SPEED	33
-
-/* the struct for the PIO mode timings */
-typedef struct pio_clocks_s {
-	u8	address_time;	/* Address setup (clocks) */
-	u8	time_16r;	/* clocks for 16bit IOR (0xF0=Active/data, 0x0F=Recovery) */
-	u8	time_16w;	/* clocks for 16bit IOW (0xF0=Active/data, 0x0F=Recovery) */
-	u8	time_8;		/* clocks for 8bit (0xF0=Active/data, 0x0F=Recovery) */
-} pio_clocks_t;
-
-/*
- * calc clocks using bus_speed
- * returns (rounded up) time in bus clocks for time in ns
- */
-static int calc_clk(int time, int bus_speed)
-{
-	int clocks;
-
-	clocks = (time*bus_speed+999)/1000 - 1;
-
-	if (clocks < 0)
-		clocks = 0;
-
-	if (clocks > 0x0F)
-		clocks = 0x0F;
-
-	return clocks;
-}
-
-/*
- * compute the values for the clock registers for PIO
- * mode and pci_clk [MHz] speed
- *
- * NOTE: for mode 0,1 and 2 drives 8-bit IDE command control registers are used
- *       for mode 3 and 4 drives 8 and 16-bit timings are the same
- *
- */
-static void compute_clocks(u8 pio, pio_clocks_t *p_pclk)
-{
-	struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio);
-	int clk1, clk2;
-	int bus_speed = ide_pci_clk ? ide_pci_clk : 33;
-
-	/* we don't check against CY82C693's min and max speed,
-	 * so you can play with the idebus=xx parameter
-	 */
-
-	/* let's calc the address setup time clocks */
-	p_pclk->address_time = (u8)calc_clk(t->setup, bus_speed);
-
-	/* let's calc the active and recovery time clocks */
-	clk1 = calc_clk(t->active, bus_speed);
-
-	/* calc recovery timing */
-	clk2 = t->cycle - t->active - t->setup;
-
-	clk2 = calc_clk(clk2, bus_speed);
-
-	clk1 = (clk1<<4)|clk2;	/* combine active and recovery clocks */
-
-	/* note: we use the same values for 16bit IOR and IOW
-	 *	those are all the same, since I don't have other
-	 *	timings than those from ide-lib.c
-	 */
-
-	p_pclk->time_16r = (u8)clk1;
-	p_pclk->time_16w = (u8)clk1;
-
-	/* what are good values for 8bit ?? */
-	p_pclk->time_8 = (u8)clk1;
-}
-
 /*
  * set DMA mode a specific channel for CY82C693
  */
@@ -190,8 +117,11 @@ static void cy82c693_set_pio_mode(ide_dr
 {
 	ide_hwif_t *hwif = drive->hwif;
 	struct pci_dev *dev = to_pci_dev(hwif->dev);
-	pio_clocks_t pclk;
+	int bus_speed = ide_pci_clk ? ide_pci_clk : 33;
+	const unsigned long T = 1000000 / bus_speed;
 	unsigned int addrCtrl;
+	struct ide_timing t;
+	u8 time_16, time_8;
 
 	/* select primary or secondary channel */
 	if (hwif->index > 0) {  /* drive is on the secondary channel */
@@ -204,8 +134,12 @@ static void cy82c693_set_pio_mode(ide_dr
 		}
 	}
 
-	/* let's calc the values for this PIO mode */
-	compute_clocks(pio, &pclk);
+	ide_timing_compute(drive, XFER_PIO_0 + pio, &t, T, 1);
+
+	time_16 = clamp_val(t.recover - 1, 0, 15) |
+		  (clamp_val(t.active - 1, 0, 15) << 4);
+	time_8 = clamp_val(t.act8b - 1, 0, 15) |
+		 (clamp_val(t.rec8b - 1, 0, 15) << 4);
 
 	/* now let's write  the clocks registers */
 	if ((drive->dn & 1) == 0) {
@@ -217,13 +151,13 @@ static void cy82c693_set_pio_mode(ide_dr
 		pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
 
 		addrCtrl &= (~0xF);
-		addrCtrl |= (unsigned int)pclk.address_time;
+		addrCtrl |= clamp_val(t.setup - 1, 0, 15);
 		pci_write_config_dword(dev, CY82_IDE_ADDRSETUP, addrCtrl);
 
 		/* now let's set the remaining registers */
-		pci_write_config_byte(dev, CY82_IDE_MASTER_IOR, pclk.time_16r);
-		pci_write_config_byte(dev, CY82_IDE_MASTER_IOW, pclk.time_16w);
-		pci_write_config_byte(dev, CY82_IDE_MASTER_8BIT, pclk.time_8);
+		pci_write_config_byte(dev, CY82_IDE_MASTER_IOR, time_16);
+		pci_write_config_byte(dev, CY82_IDE_MASTER_IOW, time_16);
+		pci_write_config_byte(dev, CY82_IDE_MASTER_8BIT, time_8);
 	} else {
 		/*
 		 * set slave drive
@@ -233,13 +167,13 @@ static void cy82c693_set_pio_mode(ide_dr
 		pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
 
 		addrCtrl &= (~0xF0);
-		addrCtrl |= ((unsigned int)pclk.address_time<<4);
+		addrCtrl |= (clamp_val(t.setup - 1, 0, 15) << 4);
 		pci_write_config_dword(dev, CY82_IDE_ADDRSETUP, addrCtrl);
 
 		/* now let's set the remaining registers */
-		pci_write_config_byte(dev, CY82_IDE_SLAVE_IOR, pclk.time_16r);
-		pci_write_config_byte(dev, CY82_IDE_SLAVE_IOW, pclk.time_16w);
-		pci_write_config_byte(dev, CY82_IDE_SLAVE_8BIT, pclk.time_8);
+		pci_write_config_byte(dev, CY82_IDE_SLAVE_IOR, time_16);
+		pci_write_config_byte(dev, CY82_IDE_SLAVE_IOW, time_16);
+		pci_write_config_byte(dev, CY82_IDE_SLAVE_8BIT, time_8);
 	}
 }
 
@@ -325,6 +259,6 @@ static void __exit cy82c693_ide_exit(voi
 module_init(cy82c693_ide_init);
 module_exit(cy82c693_ide_exit);
 
-MODULE_AUTHOR("Andreas Krebs, Andre Hedrick");
+MODULE_AUTHOR("Andreas Krebs, Andre Hedrick, Bartlomiej Zolnierkiewicz");
 MODULE_DESCRIPTION("PCI driver module for the Cypress CY82C693 IDE");
 MODULE_LICENSE("GPL");

  parent reply	other threads:[~2010-01-18 17:20 UTC|newest]

Thread overview: 149+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-18 17:13 [PATCH 00/64] more PATA fixes Bartlomiej Zolnierkiewicz
2010-01-18 17:13 ` [PATCH 01/64] libata: fix CFA handling in ide_timing_compute() Bartlomiej Zolnierkiewicz
2010-01-18 18:23   ` Sergei Shtylyov
2010-01-18 18:29     ` Bartlomiej Zolnierkiewicz
2010-01-18 18:57       ` Sergei Shtylyov
2010-01-18 19:04         ` Bartlomiej Zolnierkiewicz
2010-01-21  4:06   ` Jeff Garzik
2010-01-18 17:14 ` [PATCH 02/64] pata_ali: documentation fixes Bartlomiej Zolnierkiewicz
2010-01-21  4:06   ` Jeff Garzik
2010-01-18 17:14 ` [PATCH 03/64] pata_ali: cleanup ali_set_piomode() Bartlomiej Zolnierkiewicz
2010-01-18 17:46   ` Alan Cox
2010-01-18 18:16     ` Bartlomiej Zolnierkiewicz
2010-01-18 17:14 ` [PATCH 04/64] pata_amd: remove bogus code from timing_setup() Bartlomiej Zolnierkiewicz
2010-01-18 17:50   ` Alan Cox
2010-01-18 18:18     ` Bartlomiej Zolnierkiewicz
2010-01-18 17:14 ` [PATCH 05/64] pata_atiixp: remove superfluous wrapper function Bartlomiej Zolnierkiewicz
2010-01-21  4:07   ` Jeff Garzik
2010-01-21  4:09     ` Jeff Garzik
2010-01-21 11:23       ` Bartlomiej Zolnierkiewicz
2010-01-21 16:50         ` Jeff Garzik
2010-01-18 17:14 ` [PATCH 06/64] pata_atiixp: add locking for parallel scanning Bartlomiej Zolnierkiewicz
2010-01-21  4:07   ` Jeff Garzik
2010-01-18 17:14 ` [PATCH 07/64] pata_atiixp: enable parallel scan Bartlomiej Zolnierkiewicz
2010-01-18 17:52   ` Alan Cox
2010-01-18 18:18     ` Bartlomiej Zolnierkiewicz
2010-01-18 17:14 ` [PATCH 08/64] pata_cmd64x: fix PIO setup Bartlomiej Zolnierkiewicz
2010-01-21  4:14   ` Jeff Garzik
2010-01-18 17:15 ` [PATCH 09/64] pata_cmd64x: fix handling of address setup timings Bartlomiej Zolnierkiewicz
2010-01-18 18:46   ` Sergei Shtylyov
2010-01-18 17:15 ` [PATCH 10/64] pata_cmd64x: cmd648_bmdma_stop() fix Bartlomiej Zolnierkiewicz
2010-01-18 17:15 ` [PATCH 11/64] pata_cmd64x: remove unused definitions Bartlomiej Zolnierkiewicz
2010-01-18 17:15 ` [PATCH 12/64] pata_cs5520: convert to use ->init_host method Bartlomiej Zolnierkiewicz
2010-01-18 17:15 ` [PATCH 13/64] pata_cs5535: use correct values for PIO1 and PIO2 data timings Bartlomiej Zolnierkiewicz
2010-01-21  4:16   ` Jeff Garzik
2010-01-18 17:15 ` [PATCH 14/64] pata_cypress: fix PIO timings underclocking Bartlomiej Zolnierkiewicz
2010-01-18 19:05   ` Sergei Shtylyov
2010-01-18 17:15 ` [PATCH 15/64] pata_efar: always program master_data before slave_data Bartlomiej Zolnierkiewicz
2010-01-18 17:55   ` Alan Cox
2010-01-21  4:16   ` Jeff Garzik
2010-01-18 17:16 ` [PATCH 16/64] pata_efar: fix secondary port support Bartlomiej Zolnierkiewicz
2010-01-21  4:17   ` Jeff Garzik
2010-01-18 17:16 ` [PATCH 17/64] pata_efar: add locking for parallel scanning Bartlomiej Zolnierkiewicz
2010-01-18 17:16 ` [PATCH 18/64] pata_efar: enable parallel scan Bartlomiej Zolnierkiewicz
2010-01-18 17:16 ` [PATCH 19/64] pata_serverworks: fix PIO setup for the second channel Bartlomiej Zolnierkiewicz
2010-01-21  4:18   ` Jeff Garzik
2010-01-18 17:16 ` [PATCH 20/64] pata_serverworks: fix error message Bartlomiej Zolnierkiewicz
2010-01-18 17:16 ` [PATCH 21/64] pata_serverworks: cleanup cable detection Bartlomiej Zolnierkiewicz
2010-01-21  4:18   ` Jeff Garzik
2010-01-18 17:17 ` [PATCH 22/64] pata_via: fix address setup timings underlocking Bartlomiej Zolnierkiewicz
2010-01-18 18:00   ` Alan Cox
2010-01-21  4:19   ` Jeff Garzik
2010-01-18 17:17 ` [PATCH 23/64] pata_via: store UDMA masks in via_isa_bridges table Bartlomiej Zolnierkiewicz
2010-01-18 18:03   ` Alan Cox
2010-01-21  4:25   ` Jeff Garzik
2010-01-18 17:17 ` [PATCH 24/64] ide: fix for ide_timing quantisation errors Bartlomiej Zolnierkiewicz
2010-01-18 19:09   ` Sergei Shtylyov
2010-01-19  9:05     ` David Miller
2010-01-18 17:17 ` [PATCH 25/64] ide: use standard timing for XFER_PIO_SLOW mode in ide_timing_compute() Bartlomiej Zolnierkiewicz
2010-01-18 19:11   ` Sergei Shtylyov
2010-01-19  9:25   ` David Miller
2010-01-19 15:09     ` Bartlomiej Zolnierkiewicz
2010-01-19 19:30       ` David Miller
2010-01-19 19:42       ` Sergei Shtylyov
2010-01-19 19:48         ` David Miller
2010-01-19 20:25           ` Bartlomiej Zolnierkiewicz
2010-01-18 17:17 ` [PATCH 26/64] alim15x3: fix PIO timings calculations Bartlomiej Zolnierkiewicz
2010-01-19  9:25   ` David Miller
2010-01-18 17:17 ` [PATCH 27/64] alim15x3: add ali_fifo_control() helper Bartlomiej Zolnierkiewicz
2010-01-19  9:25   ` David Miller
2010-01-18 17:17 ` [PATCH 28/64] alim15x3: remove superfluous locking from ali_set_pio_mode() Bartlomiej Zolnierkiewicz
2010-01-19  9:25   ` David Miller
2010-01-18 17:18 ` [PATCH 29/64] alim15x3: cleanup ali_cable_detect() Bartlomiej Zolnierkiewicz
2010-01-19  9:25   ` David Miller
2010-01-18 17:18 ` [PATCH 30/64] amd74xx: don't change UDMA settings when programming PIO timings Bartlomiej Zolnierkiewicz
2010-01-19  9:26   ` David Miller
2010-01-18 17:18 ` [PATCH 31/64] cmd64x: fix PIO and MWDMA timings calculations Bartlomiej Zolnierkiewicz
2010-01-19  9:26   ` David Miller
2010-01-18 17:18 ` [PATCH 32/64] cmd64x: remove superfluous checks from cmd64x_set_dma_mode() Bartlomiej Zolnierkiewicz
2010-01-19  9:26   ` David Miller
2010-01-18 17:18 ` Bartlomiej Zolnierkiewicz [this message]
2010-01-19  9:26   ` [PATCH 33/64] cy82c693: fix PIO timings calculations David Miller
2010-01-18 17:18 ` [PATCH 34/64] cy82c693: remove stale driver history Bartlomiej Zolnierkiewicz
2010-01-19  9:26   ` David Miller
2010-01-18 17:19 ` [PATCH 35/64] opti621: " Bartlomiej Zolnierkiewicz
2010-01-19  9:26   ` David Miller
2010-01-18 17:19 ` [PATCH 36/64] pdc202xx_old: add ->init_hwif method Bartlomiej Zolnierkiewicz
2010-01-19  9:26   ` David Miller
2010-01-18 17:19 ` [PATCH 37/64] serverworks: cleanup svwks_udma_filter() Bartlomiej Zolnierkiewicz
2010-01-19  9:26   ` David Miller
2010-01-18 17:19 ` [PATCH 38/64] serverworks: add missing pci_dev_put() call Bartlomiej Zolnierkiewicz
2010-01-19  9:27   ` David Miller
2010-01-18 17:19 ` [PATCH 39/64] via82cxxx: vx855 is a single channel controller Bartlomiej Zolnierkiewicz
2010-01-19  9:27   ` David Miller
2010-01-18 17:19 ` [PATCH 40/64] ide: add SATA cable detection support Bartlomiej Zolnierkiewicz
2010-01-19  9:42   ` David Miller
2010-01-18 17:19 ` [PATCH 41/64] via82cxxx: fix SATA cable detection Bartlomiej Zolnierkiewicz
2010-01-19  9:42   ` David Miller
2010-01-18 17:20 ` [PATCH 42/64] via82cxxx: workaround h/w bugs Bartlomiej Zolnierkiewicz
2010-01-19  9:42   ` David Miller
2010-01-18 17:20 ` [PATCH 43/64] via82cxxx: add support for vt8261 and future chips Bartlomiej Zolnierkiewicz
2010-01-19  9:42   ` David Miller
2010-01-18 17:20 ` [PATCH 44/64] via82cxxx: add support for VT6415 PCIE PATA IDE Host Controller Bartlomiej Zolnierkiewicz
2010-01-19  9:42   ` David Miller
2010-01-18 17:20 ` [PATCH 45/64] via82cxxx: fix UDMA settings programming Bartlomiej Zolnierkiewicz
2010-01-19  9:43   ` David Miller
2010-01-18 17:20 ` [PATCH 46/64] ide: add drive->pio_mode field Bartlomiej Zolnierkiewicz
2010-01-18 19:28   ` Sergei Shtylyov
2010-01-19 15:09     ` Bartlomiej Zolnierkiewicz
2010-01-21 17:48       ` Sergei Shtylyov
2010-01-19  9:43   ` David Miller
2010-01-18 17:20 ` [PATCH 47/64] ide: add drive->dma_mode field Bartlomiej Zolnierkiewicz
2010-01-19  9:43   ` David Miller
2010-04-12 14:12   ` Sergei Shtylyov
2010-01-18 17:20 ` [PATCH 48/64] ide: change ->set_pio_mode method parameters Bartlomiej Zolnierkiewicz
2010-01-19  9:45   ` David Miller
2010-01-18 17:20 ` [PATCH 49/64] ide: change ->set_dma_mode " Bartlomiej Zolnierkiewicz
2010-01-19  9:45   ` David Miller
2010-01-18 17:20 ` [PATCH 50/64] ide-timings: use ->pio_mode value to determine fastest PIO speed Bartlomiej Zolnierkiewicz
2010-01-19  9:48   ` David Miller
2010-01-18 17:21 ` [PATCH 51/64] alim15x3: fix handling of address setup timings Bartlomiej Zolnierkiewicz
2010-01-19  9:53   ` David Miller
2010-01-18 17:21 ` [PATCH 52/64] alim15x3: fix handling of command timings Bartlomiej Zolnierkiewicz
2010-01-19  9:53   ` David Miller
2010-01-18 17:21 ` [PATCH 53/64] alim15x3: fix handling of DMA timings Bartlomiej Zolnierkiewicz
2010-01-19  9:53   ` David Miller
2010-01-18 17:21 ` [PATCH 54/64] alim15x3: fix handling of UDMA enable bit Bartlomiej Zolnierkiewicz
2010-01-19  9:53   ` David Miller
2010-04-12 13:53   ` Sergei Shtylyov
2010-04-13 15:15     ` Bartlomiej Zolnierkiewicz
2010-01-18 17:21 ` [PATCH 55/64] amd74xx: use ->pio_mode value to determine pair device speed Bartlomiej Zolnierkiewicz
2010-01-19  9:53   ` David Miller
2010-01-18 17:21 ` [PATCH 56/64] cmd64x: fix handling of address setup timings Bartlomiej Zolnierkiewicz
2010-01-19  9:53   ` David Miller
2010-01-18 17:21 ` [PATCH 57/64] cs5535: use ->pio_mode value to determine pair device speed Bartlomiej Zolnierkiewicz
2010-01-19  9:54   ` David Miller
2010-01-18 17:21 ` [PATCH 58/64] cs5536: " Bartlomiej Zolnierkiewicz
2010-01-19  9:54   ` David Miller
2010-01-18 17:22 ` [PATCH 59/64] it821x: " Bartlomiej Zolnierkiewicz
2010-01-19  9:54   ` David Miller
2010-01-18 17:22 ` [PATCH 60/64] palm_bk3710: " Bartlomiej Zolnierkiewicz
2010-01-19  9:54   ` David Miller
2010-01-18 17:22 ` [PATCH 61/64] siimage: " Bartlomiej Zolnierkiewicz
2010-01-19  9:54   ` David Miller
2010-01-18 17:22 ` [PATCH 62/64] tx493xide: " Bartlomiej Zolnierkiewicz
2010-01-19  9:54   ` David Miller
2010-01-18 17:22 ` [PATCH 63/64] via82cxxx: " Bartlomiej Zolnierkiewicz
2010-01-19  9:54   ` David Miller
2010-01-18 17:22 ` [PATCH 64/64] ide: make ide_get_best_pio_mode() static Bartlomiej Zolnierkiewicz
2010-01-19  9:54   ` David Miller

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=20100118171847.14623.38391.sendpatchset@localhost \
    --to=bzolnier@gmail.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@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).