]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ide/pci/hpt366.c
hpt366: fix PCI clock detection for HPT374 (take 4)
[linux-2.6-omap-h63xx.git] / drivers / ide / pci / hpt366.c
index e9b07a97c3408d1da2ac7cca57e268ed4173f3a6..f87eec970574b4ff82e4370accf37291ed04737c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * linux/drivers/ide/pci/hpt366.c              Version 1.10    Jun 29, 2007
+ * linux/drivers/ide/pci/hpt366.c              Version 1.11    Aug 11, 2007
  *
  * Copyright (C) 1999-2003             Andre Hedrick <andre@linux-ide.org>
  * Portions Copyright (C) 2001         Sun Microsystems, Inc.
@@ -68,7 +68,8 @@
  *   HPT37x chip family; save space by introducing the separate transfer mode
  *   table in which the mode lookup is done
  * - use f_CNT value saved by  the HighPoint BIOS as reading it directly gives
- *   the wrong PCI frequency since DPLL has already been calibrated by BIOS
+ *   the wrong PCI frequency since DPLL has already been calibrated by BIOS;
+ *   read it only from the function 0 of HPT374 chips
  * - fix the hotswap code:  it caused RESET- to glitch when tristating the bus,
  *   and for HPT36x the obsolete HDIO_TRISTATE_HWIF handler was called instead
  * - pass to init_chipset() handlers a copy of the IDE PCI device structure as
@@ -652,7 +653,7 @@ static int hpt3xx_tune_chipset(ide_drive_t *drive, u8 speed)
 
 static void hpt3xx_tune_drive(ide_drive_t *drive, u8 pio)
 {
-       pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
+       pio = ide_get_best_pio_mode(drive, pio, 4);
        (void) hpt3xx_tune_chipset (drive, XFER_PIO_0 + pio);
 }
 
@@ -981,6 +982,7 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
        struct hpt_info *info   = kmalloc(sizeof(struct hpt_info), GFP_KERNEL);
        unsigned long io_base   = pci_resource_start(dev, 4);
        u8 pci_clk,  dpll_clk   = 0;    /* PCI and DPLL clock in MHz */
+       u8 chip_type;
        enum ata_clock  clock;
 
        if (info == NULL) {
@@ -992,15 +994,8 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
         * Copy everything from a static "template" structure
         * to just allocated per-chip hpt_info structure.
         */
-       *info = *(struct hpt_info *)pci_get_drvdata(dev);
-
-       /*
-        * FIXME: Not portable. Also, why do we enable the ROM in the first place?
-        * We don't seem to be using it.
-        */
-       if (dev->resource[PCI_ROM_RESOURCE].start)
-               pci_write_config_dword(dev, PCI_ROM_ADDRESS,
-                       dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
+       memcpy(info, pci_get_drvdata(dev), sizeof(struct hpt_info));
+       chip_type = info->chip_type;
 
        pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
        pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
@@ -1010,7 +1005,7 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
        /*
         * First, try to estimate the PCI clock frequency...
         */
-       if (info->chip_type >= HPT370) {
+       if (chip_type >= HPT370) {
                u8  scr1  = 0;
                u16 f_cnt = 0;
                u32 temp  = 0;
@@ -1024,7 +1019,7 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
                 * HighPoint does this for HPT372A.
                 * NOTE: This register is only writeable via I/O space.
                 */
-               if (info->chip_type == HPT372A)
+               if (chip_type == HPT372A)
                        outb(0x0e, io_base + 0x9c);
 
                /*
@@ -1042,13 +1037,28 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
                 * First try reading the register in which the HighPoint BIOS
                 * saves f_CNT value before  reprogramming the DPLL from its
                 * default setting (which differs for the various chips).
-                * NOTE: This register is only accessible via I/O space.
                 *
-                * In case the signature check fails, we'll have to resort to
-                * reading the f_CNT register itself in hopes that nobody has
-                * touched the DPLL yet...
+                * NOTE: This register is only accessible via I/O space;
+                * HPT374 BIOS only saves it for the function 0, so we have to
+                * always read it from there -- no need to check the result of
+                * pci_get_slot() for the function 0 as the whole device has
+                * been already "pinned" (via function 1) in init_setup_hpt374()
+                */
+               if (chip_type == HPT374 && (PCI_FUNC(dev->devfn) & 1)) {
+                       struct pci_dev  *dev1 = pci_get_slot(dev->bus,
+                                                            dev->devfn - 1);
+                       unsigned long io_base = pci_resource_start(dev1, 4);
+
+                       temp =  inl(io_base + 0x90);
+                       pci_dev_put(dev1);
+               } else
+                       temp =  inl(io_base + 0x90);
+
+               /*
+                * In case the signature check fails, we'll have to
+                * resort to reading the f_CNT register itself in hopes
+                * that nobody has touched the DPLL yet...
                 */
-               temp = inl(io_base + 0x90);
                if ((temp & 0xFFFFF000) != 0xABCDE000) {
                        int i;
 
@@ -1128,7 +1138,7 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
         * We also  don't like using  the DPLL because this causes glitches
         * on PRST-/SRST- when the state engine gets reset...
         */
-       if (info->chip_type >= HPT374 || info->settings[clock] == NULL) {
+       if (chip_type >= HPT374 || info->settings[clock] == NULL) {
                u16 f_low, delta = pci_clk < 50 ? 2 : 4;
                int adjust;
 
@@ -1198,7 +1208,7 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
        /* Point to this chip's own instance of the hpt_info structure. */
        pci_set_drvdata(dev, info);
 
-       if (info->chip_type >= HPT370) {
+       if (chip_type >= HPT370) {
                u8  mcr1, mcr4;
 
                /*
@@ -1217,7 +1227,7 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
         * the MISC. register to stretch the UltraDMA Tss timing.
         * NOTE: This register is only writeable via I/O space.
         */
-       if (info->chip_type == HPT371N && clock == ATA_CLOCK_66MHZ)
+       if (chip_type == HPT371N && clock == ATA_CLOCK_66MHZ)
 
                outb(inb(io_base + 0x9c) | 0x04, io_base + 0x9c);
 
@@ -1491,7 +1501,7 @@ static int __devinit init_setup_hpt366(struct pci_dev *dev, ide_pci_device_t *d)
                 * to both functions -- really stupid design decision... :-(
                 * Bit 4 is for the primary channel, bit 5 for the secondary.
                 */
-               d->channels = 1;
+               d->host_flags |= IDE_HFLAG_SINGLE;
                d->enablebits[0].mask = d->enablebits[0].val = 0x10;
 
                d->udma_mask = HPT366_ALLOW_ATA66_3 ?
@@ -1554,71 +1564,71 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
                .init_chipset   = init_chipset_hpt366,
                .init_hwif      = init_hwif_hpt366,
                .init_dma       = init_dma_hpt366,
-               .channels       = 2,
                .autodma        = AUTODMA,
                .enablebits     = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
                .bootable       = OFF_BOARD,
-               .extra          = 240
+               .extra          = 240,
+               .pio_mask       = ATA_PIO4,
        },{     /* 1 */
                .name           = "HPT372A",
                .init_setup     = init_setup_hpt372a,
                .init_chipset   = init_chipset_hpt366,
                .init_hwif      = init_hwif_hpt366,
                .init_dma       = init_dma_hpt366,
-               .channels       = 2,
                .autodma        = AUTODMA,
                .enablebits     = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
                .udma_mask      = HPT372_ALLOW_ATA133_6 ? 0x7f : 0x3f,
                .bootable       = OFF_BOARD,
-               .extra          = 240
+               .extra          = 240,
+               .pio_mask       = ATA_PIO4,
        },{     /* 2 */
                .name           = "HPT302",
                .init_setup     = init_setup_hpt302,
                .init_chipset   = init_chipset_hpt366,
                .init_hwif      = init_hwif_hpt366,
                .init_dma       = init_dma_hpt366,
-               .channels       = 2,
                .autodma        = AUTODMA,
                .enablebits     = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
                .udma_mask      = HPT302_ALLOW_ATA133_6 ? 0x7f : 0x3f,
                .bootable       = OFF_BOARD,
-               .extra          = 240
+               .extra          = 240,
+               .pio_mask       = ATA_PIO4,
        },{     /* 3 */
                .name           = "HPT371",
                .init_setup     = init_setup_hpt371,
                .init_chipset   = init_chipset_hpt366,
                .init_hwif      = init_hwif_hpt366,
                .init_dma       = init_dma_hpt366,
-               .channels       = 2,
                .autodma        = AUTODMA,
                .enablebits     = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
                .udma_mask      = HPT371_ALLOW_ATA133_6 ? 0x7f : 0x3f,
                .bootable       = OFF_BOARD,
-               .extra          = 240
+               .extra          = 240,
+               .pio_mask       = ATA_PIO4,
        },{     /* 4 */
                .name           = "HPT374",
                .init_setup     = init_setup_hpt374,
                .init_chipset   = init_chipset_hpt366,
                .init_hwif      = init_hwif_hpt366,
                .init_dma       = init_dma_hpt366,
-               .channels       = 2,    /* 4 */
                .autodma        = AUTODMA,
                .enablebits     = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
                .udma_mask      = 0x3f,
                .bootable       = OFF_BOARD,
-               .extra          = 240
+               .extra          = 240,
+               .pio_mask       = ATA_PIO4,
        },{     /* 5 */
                .name           = "HPT372N",
                .init_setup     = init_setup_hpt372n,
                .init_chipset   = init_chipset_hpt366,
                .init_hwif      = init_hwif_hpt366,
                .init_dma       = init_dma_hpt366,
-               .channels       = 2,    /* 4 */
                .autodma        = AUTODMA,
                .enablebits     = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
                .udma_mask      = HPT372_ALLOW_ATA133_6 ? 0x7f : 0x3f,
                .bootable       = OFF_BOARD,
-               .extra          = 240
+               .extra          = 240,
+               .pio_mask       = ATA_PIO4,
        }
 };