1669a5db4SJeff Garzik /* 2669a5db4SJeff Garzik * New ATA layer SC1200 driver Alan Cox <alan@redhat.com> 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" 4330ced0f0SAlan #define DRV_VERSION "0.2.4" 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 /** 154669a5db4SJeff Garzik * sc1200_qc_issue_prot - 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 159669a5db4SJeff Garzik * neccessary. Specifically we have a problem that there is only 160669a5db4SJeff Garzik * one MWDMA/UDMA bit. 161669a5db4SJeff Garzik */ 162669a5db4SJeff Garzik 163669a5db4SJeff Garzik static unsigned int sc1200_qc_issue_prot(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 */ 170669a5db4SJeff Garzik if (adev->dma_mode != 0 && adev != prev && prev != NULL) { 171669a5db4SJeff Garzik /* Maybe, but do the channels match MWDMA/UDMA ? */ 172669a5db4SJeff Garzik if ((adev->dma_mode >= XFER_UDMA_0 && prev->dma_mode < XFER_UDMA_0) || 173669a5db4SJeff Garzik (adev->dma_mode < XFER_UDMA_0 && prev->dma_mode >= XFER_UDMA_0)) 174669a5db4SJeff Garzik /* Switch the mode bits */ 175669a5db4SJeff Garzik sc1200_set_dmamode(ap, adev); 176669a5db4SJeff Garzik } 177669a5db4SJeff Garzik 178669a5db4SJeff Garzik return ata_qc_issue_prot(qc); 179669a5db4SJeff Garzik } 180669a5db4SJeff Garzik 181669a5db4SJeff Garzik static struct scsi_host_template sc1200_sht = { 182669a5db4SJeff Garzik .module = THIS_MODULE, 183669a5db4SJeff Garzik .name = DRV_NAME, 184669a5db4SJeff Garzik .ioctl = ata_scsi_ioctl, 185669a5db4SJeff Garzik .queuecommand = ata_scsi_queuecmd, 186669a5db4SJeff Garzik .can_queue = ATA_DEF_QUEUE, 187669a5db4SJeff Garzik .this_id = ATA_SHT_THIS_ID, 188669a5db4SJeff Garzik .sg_tablesize = LIBATA_MAX_PRD, 189669a5db4SJeff Garzik .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 190669a5db4SJeff Garzik .emulated = ATA_SHT_EMULATED, 191669a5db4SJeff Garzik .use_clustering = ATA_SHT_USE_CLUSTERING, 192669a5db4SJeff Garzik .proc_name = DRV_NAME, 193669a5db4SJeff Garzik .dma_boundary = ATA_DMA_BOUNDARY, 194669a5db4SJeff Garzik .slave_configure = ata_scsi_slave_config, 195afdfe899STejun Heo .slave_destroy = ata_scsi_slave_destroy, 196669a5db4SJeff Garzik .bios_param = ata_std_bios_param, 197669a5db4SJeff Garzik }; 198669a5db4SJeff Garzik 199669a5db4SJeff Garzik static struct ata_port_operations sc1200_port_ops = { 200669a5db4SJeff Garzik .port_disable = ata_port_disable, 201669a5db4SJeff Garzik .set_piomode = sc1200_set_piomode, 202669a5db4SJeff Garzik .set_dmamode = sc1200_set_dmamode, 203669a5db4SJeff Garzik .mode_filter = ata_pci_default_filter, 204669a5db4SJeff Garzik 205669a5db4SJeff Garzik .tf_load = ata_tf_load, 206669a5db4SJeff Garzik .tf_read = ata_tf_read, 207669a5db4SJeff Garzik .check_status = ata_check_status, 208669a5db4SJeff Garzik .exec_command = ata_exec_command, 209669a5db4SJeff Garzik .dev_select = ata_std_dev_select, 210669a5db4SJeff Garzik 211bf7551c4SJeff Garzik .freeze = ata_bmdma_freeze, 212bf7551c4SJeff Garzik .thaw = ata_bmdma_thaw, 213669a5db4SJeff Garzik .error_handler = ata_bmdma_error_handler, 214bf7551c4SJeff Garzik .post_internal_cmd = ata_bmdma_post_internal_cmd, 215745975c0SAlan Cox .cable_detect = ata_cable_40wire, 216669a5db4SJeff Garzik 217669a5db4SJeff Garzik .bmdma_setup = ata_bmdma_setup, 218669a5db4SJeff Garzik .bmdma_start = ata_bmdma_start, 219669a5db4SJeff Garzik .bmdma_stop = ata_bmdma_stop, 220669a5db4SJeff Garzik .bmdma_status = ata_bmdma_status, 221669a5db4SJeff Garzik 222669a5db4SJeff Garzik .qc_prep = ata_qc_prep, 223669a5db4SJeff Garzik .qc_issue = sc1200_qc_issue_prot, 224bda30288SJeff Garzik 2250d5ff566STejun Heo .data_xfer = ata_data_xfer, 226669a5db4SJeff Garzik 227669a5db4SJeff Garzik .irq_handler = ata_interrupt, 228669a5db4SJeff Garzik .irq_clear = ata_bmdma_irq_clear, 229246ce3b6SAkira Iguchi .irq_on = ata_irq_on, 230246ce3b6SAkira Iguchi .irq_ack = ata_irq_ack, 231669a5db4SJeff Garzik 232669a5db4SJeff Garzik .port_start = ata_port_start, 233669a5db4SJeff Garzik }; 234669a5db4SJeff Garzik 235669a5db4SJeff Garzik /** 236669a5db4SJeff Garzik * sc1200_init_one - Initialise an SC1200 237669a5db4SJeff Garzik * @dev: PCI device 238669a5db4SJeff Garzik * @id: Entry in match table 239669a5db4SJeff Garzik * 240669a5db4SJeff Garzik * Just throw the needed data at the libata helper and it does all 241669a5db4SJeff Garzik * our work. 242669a5db4SJeff Garzik */ 243669a5db4SJeff Garzik 244669a5db4SJeff Garzik static int sc1200_init_one(struct pci_dev *dev, const struct pci_device_id *id) 245669a5db4SJeff Garzik { 246*1626aeb8STejun Heo static const struct ata_port_info info = { 247669a5db4SJeff Garzik .sht = &sc1200_sht, 248669a5db4SJeff Garzik .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST, 249669a5db4SJeff Garzik .pio_mask = 0x1f, 250669a5db4SJeff Garzik .mwdma_mask = 0x07, 251669a5db4SJeff Garzik .udma_mask = 0x07, 252669a5db4SJeff Garzik .port_ops = &sc1200_port_ops 253669a5db4SJeff Garzik }; 254669a5db4SJeff Garzik /* Can't enable port 2 yet, see top comments */ 255*1626aeb8STejun Heo const struct ata_port_info *ppi[] = { &info, &ata_dummy_port_info }; 256*1626aeb8STejun Heo 257*1626aeb8STejun Heo return ata_pci_init_one(dev, ppi); 258669a5db4SJeff Garzik } 259669a5db4SJeff Garzik 2602d2744fcSJeff Garzik static const struct pci_device_id sc1200[] = { 2612d2744fcSJeff Garzik { PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_SCx200_IDE), }, 2622d2744fcSJeff Garzik 2632d2744fcSJeff Garzik { }, 264669a5db4SJeff Garzik }; 265669a5db4SJeff Garzik 266669a5db4SJeff Garzik static struct pci_driver sc1200_pci_driver = { 267669a5db4SJeff Garzik .name = DRV_NAME, 268669a5db4SJeff Garzik .id_table = sc1200, 269669a5db4SJeff Garzik .probe = sc1200_init_one, 27030ced0f0SAlan .remove = ata_pci_remove_one, 271438ac6d5STejun Heo #ifdef CONFIG_PM 27230ced0f0SAlan .suspend = ata_pci_device_suspend, 27330ced0f0SAlan .resume = ata_pci_device_resume, 274438ac6d5STejun Heo #endif 275669a5db4SJeff Garzik }; 276669a5db4SJeff Garzik 277669a5db4SJeff Garzik static int __init sc1200_init(void) 278669a5db4SJeff Garzik { 279669a5db4SJeff Garzik return pci_register_driver(&sc1200_pci_driver); 280669a5db4SJeff Garzik } 281669a5db4SJeff Garzik 282669a5db4SJeff Garzik static void __exit sc1200_exit(void) 283669a5db4SJeff Garzik { 284669a5db4SJeff Garzik pci_unregister_driver(&sc1200_pci_driver); 285669a5db4SJeff Garzik } 286669a5db4SJeff Garzik 287669a5db4SJeff Garzik MODULE_AUTHOR("Alan Cox, Mark Lord"); 288669a5db4SJeff Garzik MODULE_DESCRIPTION("low-level driver for the NS/AMD SC1200"); 289669a5db4SJeff Garzik MODULE_LICENSE("GPL"); 290669a5db4SJeff Garzik MODULE_DEVICE_TABLE(pci, sc1200); 291669a5db4SJeff Garzik MODULE_VERSION(DRV_VERSION); 292669a5db4SJeff Garzik 293669a5db4SJeff Garzik module_init(sc1200_init); 294669a5db4SJeff Garzik module_exit(sc1200_exit); 295