sis5513.c
来自「linux 内核源代码」· C语言 代码 · 共 632 行 · 第 1/2 页
C
632 行
/* * linux/drivers/ide/pci/sis5513.c Version 0.31 Aug 9, 2007 * * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org> * Copyright (C) 2002 Lionel Bouton <Lionel.Bouton@inet6.fr>, Maintainer * Copyright (C) 2003 Vojtech Pavlik <vojtech@suse.cz> * Copyright (C) 2007 Bartlomiej Zolnierkiewicz * * May be copied or modified under the terms of the GNU General Public License * * * Thanks : * * SiS Taiwan : for direct support and hardware. * Daniela Engert : for initial ATA100 advices and numerous others. * John Fremlin, Manfred Spraul, Dave Morgan, Peter Kjellerstedt : * for checking code correctness, providing patches. * * * Original tests and design on the SiS620 chipset. * ATA100 tests and design on the SiS735 chipset. * ATA16/33 support from specs * ATA133 support for SiS961/962 by L.C. Chang <lcchang@sis.com.tw> * ATA133 961/962/963 fixes by Vojtech Pavlik <vojtech@suse.cz> * * Documentation: * SiS chipset documentation available under NDA to companies only * (not to individuals). *//* * The original SiS5513 comes from a SiS5511/55112/5513 chipset. The original * SiS5513 was also used in the SiS5596/5513 chipset. Thus if we see a SiS5511 * or SiS5596, we can assume we see the first MWDMA-16 capable SiS5513 chip. * * Later SiS chipsets integrated the 5513 functionality into the NorthBridge, * starting with SiS5571 and up to SiS745. The PCI ID didn't change, though. We * can figure out that we have a more modern and more capable 5513 by looking * for the respective NorthBridge IDs. * * Even later (96x family) SiS chipsets use the MuTIOL link and place the 5513 * into the SouthBrige. Here we cannot rely on looking up the NorthBridge PCI * ID, while the now ATA-133 capable 5513 still has the same PCI ID. * Fortunately the 5513 can be 'unmasked' by fiddling with some config space * bits, changing its device id to the true one - 5517 for 961 and 5518 for * 962/963. */#include <linux/types.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/delay.h>#include <linux/timer.h>#include <linux/mm.h>#include <linux/ioport.h>#include <linux/blkdev.h>#include <linux/hdreg.h>#include <linux/interrupt.h>#include <linux/pci.h>#include <linux/init.h>#include <linux/ide.h>#include <asm/irq.h>#include "ide-timing.h"/* registers layout and init values are chipset family dependant */#define ATA_16 0x01#define ATA_33 0x02#define ATA_66 0x03#define ATA_100a 0x04 // SiS730/SiS550 is ATA100 with ATA66 layout#define ATA_100 0x05#define ATA_133a 0x06 // SiS961b with 133 support#define ATA_133 0x07 // SiS962/963static u8 chipset_family;/* * Devices supported */static const struct { const char *name; u16 host_id; u8 chipset_family; u8 flags;} SiSHostChipInfo[] = { { "SiS968", PCI_DEVICE_ID_SI_968, ATA_133 }, { "SiS966", PCI_DEVICE_ID_SI_966, ATA_133 }, { "SiS965", PCI_DEVICE_ID_SI_965, ATA_133 }, { "SiS745", PCI_DEVICE_ID_SI_745, ATA_100 }, { "SiS735", PCI_DEVICE_ID_SI_735, ATA_100 }, { "SiS733", PCI_DEVICE_ID_SI_733, ATA_100 }, { "SiS635", PCI_DEVICE_ID_SI_635, ATA_100 }, { "SiS633", PCI_DEVICE_ID_SI_633, ATA_100 }, { "SiS730", PCI_DEVICE_ID_SI_730, ATA_100a }, { "SiS550", PCI_DEVICE_ID_SI_550, ATA_100a }, { "SiS640", PCI_DEVICE_ID_SI_640, ATA_66 }, { "SiS630", PCI_DEVICE_ID_SI_630, ATA_66 }, { "SiS620", PCI_DEVICE_ID_SI_620, ATA_66 }, { "SiS540", PCI_DEVICE_ID_SI_540, ATA_66 }, { "SiS530", PCI_DEVICE_ID_SI_530, ATA_66 }, { "SiS5600", PCI_DEVICE_ID_SI_5600, ATA_33 }, { "SiS5598", PCI_DEVICE_ID_SI_5598, ATA_33 }, { "SiS5597", PCI_DEVICE_ID_SI_5597, ATA_33 }, { "SiS5591/2", PCI_DEVICE_ID_SI_5591, ATA_33 }, { "SiS5582", PCI_DEVICE_ID_SI_5582, ATA_33 }, { "SiS5581", PCI_DEVICE_ID_SI_5581, ATA_33 }, { "SiS5596", PCI_DEVICE_ID_SI_5596, ATA_16 }, { "SiS5571", PCI_DEVICE_ID_SI_5571, ATA_16 }, { "SiS5517", PCI_DEVICE_ID_SI_5517, ATA_16 }, { "SiS551x", PCI_DEVICE_ID_SI_5511, ATA_16 },};/* Cycle time bits and values vary across chip dma capabilities These three arrays hold the register layout and the values to set. Indexed by chipset_family and (dma_mode - XFER_UDMA_0) *//* {0, ATA_16, ATA_33, ATA_66, ATA_100a, ATA_100, ATA_133} */static u8 cycle_time_offset[] = {0,0,5,4,4,0,0};static u8 cycle_time_range[] = {0,0,2,3,3,4,4};static u8 cycle_time_value[][XFER_UDMA_6 - XFER_UDMA_0 + 1] = { {0,0,0,0,0,0,0}, /* no udma */ {0,0,0,0,0,0,0}, /* no udma */ {3,2,1,0,0,0,0}, /* ATA_33 */ {7,5,3,2,1,0,0}, /* ATA_66 */ {7,5,3,2,1,0,0}, /* ATA_100a (730 specific), differences are on cycle_time range and offset */ {11,7,5,4,2,1,0}, /* ATA_100 */ {15,10,7,5,3,2,1}, /* ATA_133a (earliest 691 southbridges) */ {15,10,7,5,3,2,1}, /* ATA_133 */};/* CRC Valid Setup Time vary across IDE clock setting 33/66/100/133 See SiS962 data sheet for more detail */static u8 cvs_time_value[][XFER_UDMA_6 - XFER_UDMA_0 + 1] = { {0,0,0,0,0,0,0}, /* no udma */ {0,0,0,0,0,0,0}, /* no udma */ {2,1,1,0,0,0,0}, {4,3,2,1,0,0,0}, {4,3,2,1,0,0,0}, {6,4,3,1,1,1,0}, {9,6,4,2,2,2,2}, {9,6,4,2,2,2,2},};/* Initialize time, Active time, Recovery time vary across IDE clock settings. These 3 arrays hold the register value for PIO0/1/2/3/4 and DMA0/1/2 mode in order */static u8 ini_time_value[][8] = { {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {2,1,0,0,0,1,0,0}, {4,3,1,1,1,3,1,1}, {4,3,1,1,1,3,1,1}, {6,4,2,2,2,4,2,2}, {9,6,3,3,3,6,3,3}, {9,6,3,3,3,6,3,3},};static u8 act_time_value[][8] = { {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {9,9,9,2,2,7,2,2}, {19,19,19,5,4,14,5,4}, {19,19,19,5,4,14,5,4}, {28,28,28,7,6,21,7,6}, {38,38,38,10,9,28,10,9}, {38,38,38,10,9,28,10,9},};static u8 rco_time_value[][8] = { {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {9,2,0,2,0,7,1,1}, {19,5,1,5,2,16,3,2}, {19,5,1,5,2,16,3,2}, {30,9,3,9,4,25,6,4}, {40,12,4,12,5,34,12,5}, {40,12,4,12,5,34,12,5},};/* * Printing configuration *//* Used for chipset type printing at boot time */static char* chipset_capability[] = { "ATA", "ATA 16", "ATA 33", "ATA 66", "ATA 100 (1st gen)", "ATA 100 (2nd gen)", "ATA 133 (1st gen)", "ATA 133 (2nd gen)"};/* * Configuration functions */static u8 sis_ata133_get_base(ide_drive_t *drive){ struct pci_dev *dev = drive->hwif->pci_dev; u32 reg54 = 0; pci_read_config_dword(dev, 0x54, ®54); return ((reg54 & 0x40000000) ? 0x70 : 0x40) + drive->dn * 4;}static void sis_ata16_program_timings(ide_drive_t *drive, const u8 mode){ struct pci_dev *dev = drive->hwif->pci_dev; u16 t1 = 0; u8 drive_pci = 0x40 + drive->dn * 2; const u16 pio_timings[] = { 0x000, 0x607, 0x404, 0x303, 0x301 }; const u16 mwdma_timings[] = { 0x008, 0x302, 0x301 }; pci_read_config_word(dev, drive_pci, &t1); /* clear active/recovery timings */ t1 &= ~0x070f; if (mode >= XFER_MW_DMA_0) { if (chipset_family > ATA_16) t1 &= ~0x8000; /* disable UDMA */ t1 |= mwdma_timings[mode - XFER_MW_DMA_0]; } else t1 |= pio_timings[mode - XFER_PIO_0]; pci_write_config_word(dev, drive_pci, t1);}static void sis_ata100_program_timings(ide_drive_t *drive, const u8 mode){ struct pci_dev *dev = drive->hwif->pci_dev; u8 t1, drive_pci = 0x40 + drive->dn * 2; /* timing bits: 7:4 active 3:0 recovery */ const u8 pio_timings[] = { 0x00, 0x67, 0x44, 0x33, 0x31 }; const u8 mwdma_timings[] = { 0x08, 0x32, 0x31 }; if (mode >= XFER_MW_DMA_0) { u8 t2 = 0; pci_read_config_byte(dev, drive_pci, &t2); t2 &= ~0x80; /* disable UDMA */ pci_write_config_byte(dev, drive_pci, t2); t1 = mwdma_timings[mode - XFER_MW_DMA_0]; } else t1 = pio_timings[mode - XFER_PIO_0]; pci_write_config_byte(dev, drive_pci + 1, t1);}static void sis_ata133_program_timings(ide_drive_t *drive, const u8 mode){ struct pci_dev *dev = drive->hwif->pci_dev; u32 t1 = 0; u8 drive_pci = sis_ata133_get_base(drive), clk, idx; pci_read_config_dword(dev, drive_pci, &t1); t1 &= 0xc0c00fff; clk = (t1 & 0x08) ? ATA_133 : ATA_100; if (mode >= XFER_MW_DMA_0) { t1 &= ~0x04; /* disable UDMA */ idx = mode - XFER_MW_DMA_0 + 5; } else idx = mode - XFER_PIO_0; t1 |= ini_time_value[clk][idx] << 12; t1 |= act_time_value[clk][idx] << 16; t1 |= rco_time_value[clk][idx] << 24; pci_write_config_dword(dev, drive_pci, t1);}static void sis_program_timings(ide_drive_t *drive, const u8 mode){ if (chipset_family < ATA_100) /* ATA_16/33/66/100a */ sis_ata16_program_timings(drive, mode); else if (chipset_family < ATA_133) /* ATA_100/133a */ sis_ata100_program_timings(drive, mode); else /* ATA_133 */ sis_ata133_program_timings(drive, mode);}static void config_drive_art_rwp (ide_drive_t *drive){ ide_hwif_t *hwif = HWIF(drive); struct pci_dev *dev = hwif->pci_dev; u8 reg4bh = 0; u8 rw_prefetch = 0; pci_read_config_byte(dev, 0x4b, ®4bh); if (drive->media == ide_disk) rw_prefetch = 0x11 << drive->dn; if ((reg4bh & (0x11 << drive->dn)) != rw_prefetch) pci_write_config_byte(dev, 0x4b, reg4bh|rw_prefetch);}static void sis_set_pio_mode(ide_drive_t *drive, const u8 pio){ config_drive_art_rwp(drive); sis_program_timings(drive, XFER_PIO_0 + pio);}static void sis_set_dma_mode(ide_drive_t *drive, const u8 speed){ ide_hwif_t *hwif = HWIF(drive); struct pci_dev *dev = hwif->pci_dev; /* Config chip for mode */ switch(speed) { case XFER_UDMA_6: case XFER_UDMA_5:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?