1669a5db4SJeff Garzik /* 2ab771630SAlan Cox * New ATA layer SC1200 driver Alan Cox <alan@lxorguk.ukuu.org.uk> 3669a5db4SJeff Garzik * 4669a5db4SJeff Garzik * TODO: Mode selection filtering 5669a5db4SJeff Garzik * TODO: Can't enable second channel until ATA core has serialize 6669a5db4SJeff Garzik * TODO: Needs custom DMA cleanup code 7669a5db4SJeff Garzik * 8669a5db4SJeff Garzik * Based very heavily on 9669a5db4SJeff Garzik * 10669a5db4SJeff Garzik * linux/drivers/ide/pci/sc1200.c Version 0.91 28-Jan-2003 11669a5db4SJeff Garzik * 12669a5db4SJeff Garzik * Copyright (C) 2000-2002 Mark Lord <mlord@pobox.com> 13669a5db4SJeff Garzik * May be copied or modified under the terms of the GNU General Public License 14669a5db4SJeff Garzik * 15669a5db4SJeff Garzik * Development of this chipset driver was funded 16669a5db4SJeff Garzik * by the nice folks at National Semiconductor. 17669a5db4SJeff Garzik * 18669a5db4SJeff Garzik * This program is free software; you can redistribute it and/or modify 19669a5db4SJeff Garzik * it under the terms of the GNU General Public License version 2 as 20669a5db4SJeff Garzik * published by the Free Software Foundation. 21669a5db4SJeff Garzik * 22669a5db4SJeff Garzik * This program is distributed in the hope that it will be useful, 23669a5db4SJeff Garzik * but WITHOUT ANY WARRANTY; without even the implied warranty of 24669a5db4SJeff Garzik * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25669a5db4SJeff Garzik * GNU General Public License for more details. 26669a5db4SJeff Garzik * 27669a5db4SJeff Garzik * You should have received a copy of the GNU General Public License 28669a5db4SJeff Garzik * along with this program; if not, write to the Free Software 29669a5db4SJeff Garzik * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 30669a5db4SJeff Garzik * 31669a5db4SJeff Garzik */ 32669a5db4SJeff Garzik 33669a5db4SJeff Garzik #include <linux/kernel.h> 34669a5db4SJeff Garzik #include <linux/module.h> 35669a5db4SJeff Garzik #include <linux/pci.h> 36669a5db4SJeff Garzik #include <linux/init.h> 37669a5db4SJeff Garzik #include <linux/blkdev.h> 38669a5db4SJeff Garzik #include <linux/delay.h> 39669a5db4SJeff Garzik #include <scsi/scsi_host.h> 40669a5db4SJeff Garzik #include <linux/libata.h> 41669a5db4SJeff Garzik 42669a5db4SJeff Garzik #define DRV_NAME "sc1200" 432a3103ceSJeff Garzik #define DRV_VERSION "0.2.6" 44669a5db4SJeff Garzik 45669a5db4SJeff Garzik #define SC1200_REV_A 0x00 46669a5db4SJeff Garzik #define SC1200_REV_B1 0x01 47669a5db4SJeff Garzik #define SC1200_REV_B3 0x02 48669a5db4SJeff Garzik #define SC1200_REV_C1 0x03 49669a5db4SJeff Garzik #define SC1200_REV_D1 0x04 50669a5db4SJeff Garzik 51669a5db4SJeff Garzik /** 52669a5db4SJeff Garzik * sc1200_clock - PCI clock 53669a5db4SJeff Garzik * 54669a5db4SJeff Garzik * Return the PCI bus clocking for the SC1200 chipset configuration 55669a5db4SJeff Garzik * in use. We return 0 for 33MHz 1 for 48MHz and 2 for 66Mhz 56669a5db4SJeff Garzik */ 57669a5db4SJeff Garzik 58669a5db4SJeff Garzik static int sc1200_clock(void) 59669a5db4SJeff Garzik { 60669a5db4SJeff Garzik /* Magic registers that give us the chipset data */ 61669a5db4SJeff Garzik u8 chip_id = inb(0x903C); 62669a5db4SJeff Garzik u8 silicon_rev = inb(0x903D); 63669a5db4SJeff Garzik u16 pci_clock; 64669a5db4SJeff Garzik 65669a5db4SJeff Garzik if (chip_id == 0x04 && silicon_rev < SC1200_REV_B1) 66669a5db4SJeff Garzik return 0; /* 33 MHz mode */ 67669a5db4SJeff Garzik 68669a5db4SJeff Garzik /* Clock generator configuration 0x901E its 8/9 are the PCI clocking 69669a5db4SJeff Garzik 0/3 is 33Mhz 1 is 48 2 is 66 */ 70669a5db4SJeff Garzik 71669a5db4SJeff Garzik pci_clock = inw(0x901E); 72669a5db4SJeff Garzik pci_clock >>= 8; 73669a5db4SJeff Garzik pci_clock &= 0x03; 74669a5db4SJeff Garzik if (pci_clock == 3) 75669a5db4SJeff Garzik pci_clock = 0; 76669a5db4SJeff Garzik return pci_clock; 77669a5db4SJeff Garzik } 78669a5db4SJeff Garzik 79669a5db4SJeff Garzik /** 80669a5db4SJeff Garzik * sc1200_set_piomode - PIO setup 81669a5db4SJeff Garzik * @ap: ATA interface 82669a5db4SJeff Garzik * @adev: device on the interface 83669a5db4SJeff Garzik * 84669a5db4SJeff Garzik * Set our PIO requirements. This is fairly simple on the SC1200 85669a5db4SJeff Garzik */ 86669a5db4SJeff Garzik 87669a5db4SJeff Garzik static void sc1200_set_piomode(struct ata_port *ap, struct ata_device *adev) 88669a5db4SJeff Garzik { 89669a5db4SJeff Garzik static const u32 pio_timings[4][5] = { 90669a5db4SJeff Garzik {0x00009172, 0x00012171, 0x00020080, 0x00032010, 0x00040010}, // format0 33Mhz 91669a5db4SJeff Garzik {0xd1329172, 0x71212171, 0x30200080, 0x20102010, 0x00100010}, // format1, 33Mhz 92669a5db4SJeff Garzik {0xfaa3f4f3, 0xc23232b2, 0x513101c1, 0x31213121, 0x10211021}, // format1, 48Mhz 93669a5db4SJeff Garzik {0xfff4fff4, 0xf35353d3, 0x814102f1, 0x42314231, 0x11311131} // format1, 66Mhz 94669a5db4SJeff Garzik }; 95669a5db4SJeff Garzik 96669a5db4SJeff Garzik struct pci_dev *pdev = to_pci_dev(ap->host->dev); 97669a5db4SJeff Garzik u32 format; 98669a5db4SJeff Garzik unsigned int reg = 0x40 + 0x10 * ap->port_no; 99669a5db4SJeff Garzik int mode = adev->pio_mode - XFER_PIO_0; 100669a5db4SJeff Garzik 101669a5db4SJeff Garzik pci_read_config_dword(pdev, reg + 4, &format); 102669a5db4SJeff Garzik format >>= 31; 103669a5db4SJeff Garzik format += sc1200_clock(); 104669a5db4SJeff Garzik pci_write_config_dword(pdev, reg + 8 * adev->devno, 105669a5db4SJeff Garzik pio_timings[format][mode]); 106669a5db4SJeff Garzik } 107669a5db4SJeff Garzik 108669a5db4SJeff Garzik /** 109669a5db4SJeff Garzik * sc1200_set_dmamode - DMA timing setup 110669a5db4SJeff Garzik * @ap: ATA interface 111669a5db4SJeff Garzik * @adev: Device being configured 112669a5db4SJeff Garzik * 113669a5db4SJeff Garzik * We cannot mix MWDMA and UDMA without reloading timings each switch 114669a5db4SJeff Garzik * master to slave. 115669a5db4SJeff Garzik */ 116669a5db4SJeff Garzik 117669a5db4SJeff Garzik static void sc1200_set_dmamode(struct ata_port *ap, struct ata_device *adev) 118669a5db4SJeff Garzik { 119669a5db4SJeff Garzik static const u32 udma_timing[3][3] = { 120669a5db4SJeff Garzik { 0x00921250, 0x00911140, 0x00911030 }, 121669a5db4SJeff Garzik { 0x00932470, 0x00922260, 0x00922140 }, 122669a5db4SJeff Garzik { 0x009436A1, 0x00933481, 0x00923261 } 123669a5db4SJeff Garzik }; 124669a5db4SJeff Garzik 125669a5db4SJeff Garzik static const u32 mwdma_timing[3][3] = { 126669a5db4SJeff Garzik { 0x00077771, 0x00012121, 0x00002020 }, 127669a5db4SJeff Garzik { 0x000BBBB2, 0x00024241, 0x00013131 }, 128669a5db4SJeff Garzik { 0x000FFFF3, 0x00035352, 0x00015151 } 129669a5db4SJeff Garzik }; 130669a5db4SJeff Garzik 131669a5db4SJeff Garzik int clock = sc1200_clock(); 132669a5db4SJeff Garzik struct pci_dev *pdev = to_pci_dev(ap->host->dev); 133669a5db4SJeff Garzik unsigned int reg = 0x40 + 0x10 * ap->port_no; 134669a5db4SJeff Garzik int mode = adev->dma_mode; 135669a5db4SJeff Garzik u32 format; 136669a5db4SJeff Garzik 137669a5db4SJeff Garzik if (mode >= XFER_UDMA_0) 138669a5db4SJeff Garzik format = udma_timing[clock][mode - XFER_UDMA_0]; 139669a5db4SJeff Garzik else 140669a5db4SJeff Garzik format = mwdma_timing[clock][mode - XFER_MW_DMA_0]; 141669a5db4SJeff Garzik 142669a5db4SJeff Garzik if (adev->devno == 0) { 143669a5db4SJeff Garzik u32 timings; 144669a5db4SJeff Garzik 145669a5db4SJeff Garzik pci_read_config_dword(pdev, reg + 4, &timings); 146669a5db4SJeff Garzik timings &= 0x80000000UL; 147669a5db4SJeff Garzik timings |= format; 148669a5db4SJeff Garzik pci_write_config_dword(pdev, reg + 4, timings); 149669a5db4SJeff Garzik } else 150669a5db4SJeff Garzik pci_write_config_dword(pdev, reg + 12, format); 151669a5db4SJeff Garzik } 152669a5db4SJeff Garzik 153669a5db4SJeff Garzik /** 1549363c382STejun Heo * sc1200_qc_issue - command issue 155669a5db4SJeff Garzik * @qc: command pending 156669a5db4SJeff Garzik * 157669a5db4SJeff Garzik * Called when the libata layer is about to issue a command. We wrap 158669a5db4SJeff Garzik * this interface so that we can load the correct ATA timings if 1593a4fa0a2SRobert P. J. Day * necessary. Specifically we have a problem that there is only 160669a5db4SJeff Garzik * one MWDMA/UDMA bit. 161669a5db4SJeff Garzik */ 162669a5db4SJeff Garzik 1639363c382STejun Heo static unsigned int sc1200_qc_issue(struct ata_queued_cmd *qc) 164669a5db4SJeff Garzik { 165669a5db4SJeff Garzik struct ata_port *ap = qc->ap; 166669a5db4SJeff Garzik struct ata_device *adev = qc->dev; 167669a5db4SJeff Garzik struct ata_device *prev = ap->private_data; 168669a5db4SJeff Garzik 169669a5db4SJeff Garzik /* See if the DMA settings could be wrong */ 170b15b3ebaSAlan Cox if (ata_dma_enabled(adev) && adev != prev && prev != NULL) { 171669a5db4SJeff Garzik /* Maybe, but do the channels match MWDMA/UDMA ? */ 172b15b3ebaSAlan Cox if ((ata_using_udma(adev) && !ata_using_udma(prev)) || 173b15b3ebaSAlan Cox (ata_using_udma(prev) && !ata_using_udma(adev))) 174669a5db4SJeff Garzik /* Switch the mode bits */ 175669a5db4SJeff Garzik sc1200_set_dmamode(ap, adev); 176669a5db4SJeff Garzik } 177669a5db4SJeff Garzik 1789363c382STejun Heo return ata_sff_qc_issue(qc); 179669a5db4SJeff Garzik } 180669a5db4SJeff Garzik 181669a5db4SJeff Garzik static struct scsi_host_template sc1200_sht = { 18268d1d07bSTejun Heo ATA_BMDMA_SHT(DRV_NAME), 183d26fc955SAlan Cox .sg_tablesize = LIBATA_DUMB_MAX_PRD, 184669a5db4SJeff Garzik }; 185669a5db4SJeff Garzik 186669a5db4SJeff Garzik static struct ata_port_operations sc1200_port_ops = { 187029cfd6bSTejun Heo .inherits = &ata_bmdma_port_ops, 1889363c382STejun Heo .qc_prep = ata_sff_dumb_qc_prep, 1899363c382STejun Heo .qc_issue = sc1200_qc_issue, 190029cfd6bSTejun Heo .cable_detect = ata_cable_40wire, 191029cfd6bSTejun Heo .set_piomode = sc1200_set_piomode, 192029cfd6bSTejun Heo .set_dmamode = sc1200_set_dmamode, 193669a5db4SJeff Garzik }; 194669a5db4SJeff Garzik 195669a5db4SJeff Garzik /** 196669a5db4SJeff Garzik * sc1200_init_one - Initialise an SC1200 197669a5db4SJeff Garzik * @dev: PCI device 198669a5db4SJeff Garzik * @id: Entry in match table 199669a5db4SJeff Garzik * 200669a5db4SJeff Garzik * Just throw the needed data at the libata helper and it does all 201669a5db4SJeff Garzik * our work. 202669a5db4SJeff Garzik */ 203669a5db4SJeff Garzik 204669a5db4SJeff Garzik static int sc1200_init_one(struct pci_dev *dev, const struct pci_device_id *id) 205669a5db4SJeff Garzik { 2061626aeb8STejun Heo static const struct ata_port_info info = { 2071d2808fdSJeff Garzik .flags = ATA_FLAG_SLAVE_POSS, 208*14bdef98SErik Inge Bolsø .pio_mask = ATA_PIO4, 209*14bdef98SErik Inge Bolsø .mwdma_mask = ATA_MWDMA2, 210*14bdef98SErik Inge Bolsø .udma_mask = ATA_UDMA2, 211669a5db4SJeff Garzik .port_ops = &sc1200_port_ops 212669a5db4SJeff Garzik }; 213669a5db4SJeff Garzik /* Can't enable port 2 yet, see top comments */ 2141626aeb8STejun Heo const struct ata_port_info *ppi[] = { &info, &ata_dummy_port_info }; 2151626aeb8STejun Heo 2169363c382STejun Heo return ata_pci_sff_init_one(dev, ppi, &sc1200_sht, NULL); 217669a5db4SJeff Garzik } 218669a5db4SJeff Garzik 2192d2744fcSJeff Garzik static const struct pci_device_id sc1200[] = { 2202d2744fcSJeff Garzik { PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_SCx200_IDE), }, 2212d2744fcSJeff Garzik 2222d2744fcSJeff Garzik { }, 223669a5db4SJeff Garzik }; 224669a5db4SJeff Garzik 225669a5db4SJeff Garzik static struct pci_driver sc1200_pci_driver = { 226669a5db4SJeff Garzik .name = DRV_NAME, 227669a5db4SJeff Garzik .id_table = sc1200, 228669a5db4SJeff Garzik .probe = sc1200_init_one, 22930ced0f0SAlan .remove = ata_pci_remove_one, 230438ac6d5STejun Heo #ifdef CONFIG_PM 23130ced0f0SAlan .suspend = ata_pci_device_suspend, 23230ced0f0SAlan .resume = ata_pci_device_resume, 233438ac6d5STejun Heo #endif 234669a5db4SJeff Garzik }; 235669a5db4SJeff Garzik 236669a5db4SJeff Garzik static int __init sc1200_init(void) 237669a5db4SJeff Garzik { 238669a5db4SJeff Garzik return pci_register_driver(&sc1200_pci_driver); 239669a5db4SJeff Garzik } 240669a5db4SJeff Garzik 241669a5db4SJeff Garzik static void __exit sc1200_exit(void) 242669a5db4SJeff Garzik { 243669a5db4SJeff Garzik pci_unregister_driver(&sc1200_pci_driver); 244669a5db4SJeff Garzik } 245669a5db4SJeff Garzik 246669a5db4SJeff Garzik MODULE_AUTHOR("Alan Cox, Mark Lord"); 247669a5db4SJeff Garzik MODULE_DESCRIPTION("low-level driver for the NS/AMD SC1200"); 248669a5db4SJeff Garzik MODULE_LICENSE("GPL"); 249669a5db4SJeff Garzik MODULE_DEVICE_TABLE(pci, sc1200); 250669a5db4SJeff Garzik MODULE_VERSION(DRV_VERSION); 251669a5db4SJeff Garzik 252669a5db4SJeff Garzik module_init(sc1200_init); 253669a5db4SJeff Garzik module_exit(sc1200_exit); 254