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 3/19] ide: it8213 driver update
Date: Fri, 12 Jan 2007 05:26:27 +0100 [thread overview]
Message-ID: <20070112042627.28794.47002.sendpatchset@localhost.localdomain> (raw)
In-Reply-To: <20070112042621.28794.6937.sendpatchset@localhost.localdomain>
[PATCH] ide: it8213 driver update
* set ATAPI/IORDY/TIME bits correctly in it8213_tuneproc()
* fix UDMA/MWDMA/SWDMA masks in it8213_init_hwif()
* in it8213_tune_chipset() SWDMA2 mode should be used instead of MWDMA0
* backport various fixes from piix/slc90e66 drivers:
- in it8213_tuneproc() the highest possible PIO mode is PIO4 (not PIO5)
- clear ATAPI/IORDY/TIME bits before setting them also for slave device
- use ->speedproc in it8213_config_drive_for_dma()
- don't try to tune PIO in config_chipset_for_pio()
- simplify is_slave calculation in it8213_tuneproc()
- misc cleanups
* fix it8213_ratemask() and it8213_tuneproc() comments
* simplify it8213_init_hwif()
* remove init_chipset_it8213()
* add missing Copyrights and update MODULE_AUTHOR()
* CodingStyle cleanups
* remove dead code
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/pci/it8213.c | 172 ++++++++++++++++++-----------------------------
1 file changed, 66 insertions(+), 106 deletions(-)
Index: a/drivers/ide/pci/it8213.c
===================================================================
--- a.orig/drivers/ide/pci/it8213.c
+++ a/drivers/ide/pci/it8213.c
@@ -1,3 +1,11 @@
+/*
+ * ITE 8213 IDE driver
+ *
+ * Copyright (C) 2006 Jack Lee
+ * Copyright (C) 2006 Alan Cox
+ * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
+ */
+
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/module.h>
@@ -14,14 +22,14 @@
* @drive: IDE drive
*
* Compute the available speeds for the devices on the interface. This
- * is all modes to ATA100 clipped by drive cable setup.
+ * is all modes to ATA133 clipped by drive cable setup.
*/
static u8 it8213_ratemask (ide_drive_t *drive)
{
u8 mode = 4;
if (!eighty_ninty_three(drive))
- mode = min(mode, (u8)1);
+ mode = min_t(u8, mode, 1);
return mode;
}
@@ -62,55 +70,57 @@ static u8 it8213_dma_2_pio (u8 xfer_rate
}
}
-static spinlock_t tune_lock = SPIN_LOCK_UNLOCKED;
-
/*
* it8213_tuneproc - tune a drive
* @drive: drive to tune
- * @mode_wanted: the target operating mode
- *
- * Load the timing settings for this device mode into the
- * controller. By the time we are called the mode has been
- * modified as neccessary to handle the absence of seperate
- * master/slave timers for MWDMA/PIO.
+ * @pio: desired PIO mode
*
- * This code is only used in pass through mode.
+ * Set the interface PIO mode.
*/
-static void it8213_tuneproc (ide_drive_t *drive, u8 pio)
+static void it8213_tuneproc (ide_drive_t *drive, u8 pio)
{
ide_hwif_t *hwif = HWIF(drive);
struct pci_dev *dev = hwif->pci_dev;
- int is_slave = (&hwif->drives[1] == drive);
+ int is_slave = drive->dn & 1;
int master_port = 0x40;
int slave_port = 0x44;
unsigned long flags;
u16 master_data;
u8 slave_data;
+ static DEFINE_SPINLOCK(tune_lock);
+ int control = 0;
- u8 timings[][2] = { { 0, 0 },
- { 0, 0 },
- { 1, 0 },
- { 2, 1 },
- { 2, 3 }, };
+ static const u8 timings[][2]= {
+ { 0, 0 },
+ { 0, 0 },
+ { 1, 0 },
+ { 2, 1 },
+ { 2, 3 }, };
- pio = ide_get_best_pio_mode(drive, pio, 5, NULL);
+ pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
spin_lock_irqsave(&tune_lock, flags);
pci_read_config_word(dev, master_port, &master_data);
+
+ if (pio > 1)
+ control |= 1; /* Programmable timing on */
+ if (drive->media != ide_disk)
+ control |= 4; /* ATAPI */
+ if (pio > 2)
+ control |= 2; /* IORDY */
if (is_slave) {
- master_data = master_data | 0x4000;
+ master_data |= 0x4000;
+ master_data &= ~0x0070;
if (pio > 1)
-
- master_data = master_data | 0x0070;
+ master_data = master_data | (control << 4);
pci_read_config_byte(dev, slave_port, &slave_data);
slave_data = slave_data & 0xf0;
- slave_data = slave_data | (((timings[pio][0] << 2) | (timings[pio][1]) << 0));
+ slave_data = slave_data | (timings[pio][0] << 2) | timings[pio][1];
} else {
- master_data = master_data & 0xccf8;
+ master_data &= ~0x3307;
if (pio > 1)
-
- master_data = master_data | 0x0007;
+ master_data = master_data | control;
master_data = master_data | (timings[pio][0] << 12) | (timings[pio][1] << 8);
}
pci_write_config_word(dev, master_port, master_data);
@@ -119,7 +129,6 @@ static void it8213_tuneproc (ide_drive_t
spin_unlock_irqrestore(&tune_lock, flags);
}
-
/**
* it8213_tune_chipset - set controller timings
* @drive: Drive to set up
@@ -130,7 +139,7 @@ static void it8213_tuneproc (ide_drive_t
* make the thing work.
*/
-static int it8213_tune_chipset (ide_drive_t *drive, byte xferspeed)
+static int it8213_tune_chipset (ide_drive_t *drive, u8 xferspeed)
{
ide_hwif_t *hwif = HWIF(drive);
@@ -154,15 +163,15 @@ static int it8213_tune_chipset (ide_driv
switch(speed) {
case XFER_UDMA_6:
case XFER_UDMA_4:
- case XFER_UDMA_2:u_speed = 2 << (drive->dn * 4); break;
+ case XFER_UDMA_2: u_speed = 2 << (drive->dn * 4); break;
case XFER_UDMA_5:
case XFER_UDMA_3:
- case XFER_UDMA_1:u_speed = 1 << (drive->dn * 4); break;
- case XFER_UDMA_0:u_speed = 0 << (drive->dn * 4); break;
+ case XFER_UDMA_1: u_speed = 1 << (drive->dn * 4); break;
+ case XFER_UDMA_0: u_speed = 0 << (drive->dn * 4); break;
break;
case XFER_MW_DMA_2:
case XFER_MW_DMA_1:
- case XFER_MW_DMA_0:
+ case XFER_SW_DMA_2:
break;
case XFER_PIO_4:
case XFER_PIO_3:
@@ -174,8 +183,7 @@ static int it8213_tune_chipset (ide_driv
return -1;
}
- if (speed >= XFER_UDMA_0)
- {
+ if (speed >= XFER_UDMA_0) {
if (!(reg48 & u_flag))
pci_write_config_byte(dev, 0x48, reg48 | u_flag);
if (speed >= XFER_UDMA_5) {
@@ -186,14 +194,12 @@ static int it8213_tune_chipset (ide_driv
if ((reg4a & a_speed) != u_speed)
pci_write_config_word(dev, 0x4a, (reg4a & ~a_speed) | u_speed);
- if (speed > XFER_UDMA_2)
- {
+ if (speed > XFER_UDMA_2) {
if (!(reg54 & v_flag))
pci_write_config_byte(dev, 0x54, reg54 | v_flag);
} else
pci_write_config_byte(dev, 0x54, reg54 & ~v_flag);
- } else /*if(speed >= XFER_UDMA_0)*/
- {
+ } else {
if (reg48 & u_flag)
pci_write_config_byte(dev, 0x48, reg48 & ~u_flag);
if (reg4a & a_speed)
@@ -202,11 +208,10 @@ static int it8213_tune_chipset (ide_driv
pci_write_config_byte(dev, 0x54, reg54 & ~v_flag);
if (reg55 & w_flag)
pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag);
- }
+ }
it8213_tuneproc(drive, it8213_dma_2_pio(speed));
return ide_config_drive_speed(drive, speed);
- }
-
+}
/*
* config_chipset_for_dma - configure for DMA
@@ -217,48 +222,17 @@ static int it8213_tune_chipset (ide_driv
static int config_chipset_for_dma (ide_drive_t *drive)
{
- u8 speed = ide_dma_speed(drive, it8213_ratemask(drive));
+ u8 speed = ide_dma_speed(drive, it8213_ratemask(drive));
+
if (!speed)
- {
- u8 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL);
- speed = it8213_dma_2_pio(XFER_PIO_0 + tspeed);
- }
-// config_it8213_chipset_for_pio(drive, !speed);
+ return 0;
+
it8213_tune_chipset(drive, speed);
+
return ide_dma_enable(drive);
}
/**
- * config_it8213_chipset_for_pio - set drive timings
- * @drive: drive to tune
- * @speed we want
- *
- * Compute the best pio mode we can for a given device. We must
- * pick a speed that does not cause problems with the other device
- * on the cable.
- */
-/*
-static void config_it8213_chipset_for_pio (ide_drive_t *drive, byte set_speed)
-{
- ide_hwif_t *hwif = HWIF(drive);
-// u8 unit = drive->select.b.unit;
- ide_hwif_t *hwif = drive->hwif;
- ide_drive_t *pair = &hwif->drives[1-unit];
- u8 speed = 0, set_pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
- u8 pair_pio;
-
- if(pair != NULL) {
- pair_pio = ide_get_best_pio_mode(pair, 255, 5, NULL);
- if(pair_pio < set_pio)
- set_pio = pair_pio;
- }
- it8213_tuneproc(drive, set_pio);
- speed = XFER_PIO_0 + set_pio;
- if (set_speed)
- (void) ide_config_drive_speed(drive, speed);
-}
-*/
-/**
* it8213_configure_drive_for_dma - set up for DMA transfers
* @drive: drive we are going to set up
*
@@ -270,26 +244,19 @@ static void config_it8213_chipset_for_pi
static int it8213_config_drive_for_dma (ide_drive_t *drive)
{
-// ide_hwif_t *hwif = drive->hwif;
-// struct hd_driveid *id = drive->id;
- ide_hwif_t *hwif = HWIF(drive);
+ ide_hwif_t *hwif = drive->hwif;
+
if (ide_use_dma(drive)) {
if (config_chipset_for_dma(drive))
return hwif->ide_dma_on(drive);
}
-// config_it8213_chipset_for_pio(drive, 1);
- hwif->tuneproc(drive, 255);
- return hwif->ide_dma_off_quietly(drive);
-}
+ hwif->speedproc(drive, XFER_PIO_0
+ + ide_get_best_pio_mode(drive, 255, 4, NULL));
-static unsigned int __devinit init_chipset_it8213(struct pci_dev *dev, const char *name)
-{
- printk(KERN_INFO "it8213: controller in IDE mode.\n");
- return 0;
+ return hwif->ide_dma_off_quietly(drive);
}
-
/**
* init_hwif_it8213 - set up hwif structs
* @hwif: interface to set up
@@ -302,9 +269,6 @@ static unsigned int __devinit init_chips
static void __devinit init_hwif_it8213(ide_hwif_t *hwif)
{
u8 reg42h = 0, ata66 = 0;
- u8 mask = 0x02;
-
- hwif->atapi_dma = 1;
hwif->speedproc = &it8213_tune_chipset;
hwif->tuneproc = &it8213_tuneproc;
@@ -315,19 +279,19 @@ static void __devinit init_hwif_it8213(i
hwif->drives[1].autotune = 1;
if (!hwif->dma_base)
- goto fallback;
+ return;
+
hwif->atapi_dma = 1;
- hwif->ultra_mask = 0x7f;
- hwif->mwdma_mask = 0x07;
- hwif->swdma_mask = 0x07;
+ hwif->ultra_mask = 0x3f;
+ hwif->mwdma_mask = 0x06;
+ hwif->swdma_mask = 0x04;
pci_read_config_byte(hwif->pci_dev, 0x42, ®42h);
- ata66 = (reg42h & mask) ? 0 : 1;
+ ata66 = (reg42h & 0x02) ? 0 : 1;
hwif->ide_dma_check = &it8213_config_drive_for_dma;
if (!(hwif->udma_four))
hwif->udma_four = ata66;
-// hwif->udma_four = 0;
/*
* The BIOS often doesn't set up DMA on this controller
@@ -338,20 +302,15 @@ static void __devinit init_hwif_it8213(i
hwif->drives[0].autodma = hwif->autodma;
hwif->drives[1].autodma = hwif->autodma;
- return;
-fallback:
- hwif->autodma = 0;
- return;
}
#define DECLARE_ITE_DEV(name_str) \
{ \
.name = name_str, \
- .init_chipset = init_chipset_it8213, \
.init_hwif = init_hwif_it8213, \
.channels = 1, \
- .autodma = AUTODMA, \
+ .autodma = AUTODMA, \
.enablebits = {{0x41,0x80,0x80}}, \
.bootable = ON_BOARD, \
}
@@ -393,10 +352,11 @@ static struct pci_driver driver = {
static int __init it8213_ide_init(void)
{
- return ide_pci_register_driver(&driver); }
+ return ide_pci_register_driver(&driver);
+}
module_init(it8213_ide_init);
-MODULE_AUTHOR("Jack and Alan Cox"); /* Update this */
+MODULE_AUTHOR("Jack Lee, Alan Cox");
MODULE_DESCRIPTION("PCI driver module for the ITE 8213");
MODULE_LICENSE("GPL");
next prev parent reply other threads:[~2007-01-12 4:26 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-12 4:26 [PATCH 2/19] ide: add it8213 driver Bartlomiej Zolnierkiewicz
2007-01-12 4:26 ` Bartlomiej Zolnierkiewicz [this message]
2007-01-12 4:26 ` [PATCH 4/19] ia64: add pci_get_legacy_ide_irq() Bartlomiej Zolnierkiewicz
2007-01-12 4:26 ` [PATCH 5/19] ide: add missing __init tags to IDE PCI host drivers Bartlomiej Zolnierkiewicz
2007-01-12 4:26 ` [PATCH 6/19] pdc202xx_old: remove dead code Bartlomiej Zolnierkiewicz
2007-01-12 4:26 ` [PATCH 7/19] au1xxx-ide: " Bartlomiej Zolnierkiewicz
2007-01-12 4:26 ` [PATCH 8/19] ide: remove write-only ide_pio_data_t.blacklisted Bartlomiej Zolnierkiewicz
2007-01-12 4:27 ` [PATCH 9/19] ide: remove write-only ide_hwif_t.no_dsc flag Bartlomiej Zolnierkiewicz
2007-01-12 4:27 ` [PATCH 10/19] trm290: remove redundant CONFIG_BLK_DEV_IDEDMA Bartlomiej Zolnierkiewicz
2007-01-12 19:24 ` Sergei Shtylyov
2007-01-12 20:44 ` Bartlomiej Zolnierkiewicz
2007-01-12 4:27 ` [PATCH 11/19] ide: remove ide_pci_device_t tables with only one entry Bartlomiej Zolnierkiewicz
2007-01-12 4:27 ` [PATCH 12/19] ide: remove ide_drive_t.usage Bartlomiej Zolnierkiewicz
2007-01-12 4:27 ` [PATCH 13/19] hpt366: remove redundant check from init_dma_hpt366() Bartlomiej Zolnierkiewicz
2007-01-12 4:27 ` [PATCH 14/19] cs5530: small cleanup Bartlomiej Zolnierkiewicz
2007-01-12 4:27 ` [PATCH 15/19] svwks: " Bartlomiej Zolnierkiewicz
2007-01-12 4:27 ` [PATCH 16/19] sis5513: sis5513_config_xfer_rate() cleanup Bartlomiej Zolnierkiewicz
2007-01-12 4:27 ` [PATCH 17/19] ide: unexport ide_set_xfer_rate() Bartlomiej Zolnierkiewicz
2007-01-12 4:28 ` [PATCH 18/19] ide: add ide_use_fast_pio() helper Bartlomiej Zolnierkiewicz
2007-01-12 10:08 ` Alan
2007-01-12 10:08 ` Alan
2007-01-12 14:00 ` Bartlomiej Zolnierkiewicz
2007-01-12 14:30 ` Alan
2007-01-12 14:43 ` Bartlomiej Zolnierkiewicz
2007-01-12 15:16 ` Alan
2007-01-12 17:24 ` Bartlomiej Zolnierkiewicz
2007-01-12 4:28 ` [PATCH 19/19] ide: use PIO/MMIO operations directly where possible Bartlomiej Zolnierkiewicz
2007-01-12 10:06 ` Alan
2007-01-12 10:06 ` Alan
2007-01-12 14:19 ` Bartlomiej Zolnierkiewicz
2007-06-21 17:16 ` Sergei Shtylyov
2007-06-21 18:19 ` Bartlomiej Zolnierkiewicz
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=20070112042627.28794.47002.sendpatchset@localhost.localdomain \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.