107ab85deSAlek Du /* 207ab85deSAlek Du * pata_sch.c - Intel SCH PATA controllers 307ab85deSAlek Du * 407ab85deSAlek Du * Copyright (c) 2008 Alek Du <alek.du@intel.com> 507ab85deSAlek Du * 607ab85deSAlek Du * This program is free software; you can redistribute it and/or modify 707ab85deSAlek Du * it under the terms of the GNU General Public License 2 as published 807ab85deSAlek Du * by the Free Software Foundation. 907ab85deSAlek Du * 1007ab85deSAlek Du * This program is distributed in the hope that it will be useful, 1107ab85deSAlek Du * but WITHOUT ANY WARRANTY; without even the implied warranty of 1207ab85deSAlek Du * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1307ab85deSAlek Du * GNU General Public License for more details. 1407ab85deSAlek Du * 1507ab85deSAlek Du * You should have received a copy of the GNU General Public License 1607ab85deSAlek Du * along with this program; see the file COPYING. If not, write to 1707ab85deSAlek Du * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 1807ab85deSAlek Du * 1907ab85deSAlek Du */ 2007ab85deSAlek Du 2107ab85deSAlek Du /* 2207ab85deSAlek Du * Supports: 2307ab85deSAlek Du * Intel SCH (AF82US15W, AF82US15L, AF82UL11L) chipsets -- see spec at: 2407ab85deSAlek Du * http://download.intel.com/design/chipsets/embedded/datashts/319537.pdf 2507ab85deSAlek Du */ 2607ab85deSAlek Du 2707ab85deSAlek Du #include <linux/kernel.h> 2807ab85deSAlek Du #include <linux/module.h> 2907ab85deSAlek Du #include <linux/pci.h> 3007ab85deSAlek Du #include <linux/init.h> 3107ab85deSAlek Du #include <linux/blkdev.h> 3207ab85deSAlek Du #include <linux/delay.h> 3307ab85deSAlek Du #include <linux/device.h> 3407ab85deSAlek Du #include <scsi/scsi_host.h> 3507ab85deSAlek Du #include <linux/libata.h> 3607ab85deSAlek Du #include <linux/dmi.h> 3707ab85deSAlek Du 3807ab85deSAlek Du #define DRV_NAME "pata_sch" 3907ab85deSAlek Du #define DRV_VERSION "0.2" 4007ab85deSAlek Du 4107ab85deSAlek Du /* see SCH datasheet page 351 */ 4207ab85deSAlek Du enum { 4307ab85deSAlek Du D0TIM = 0x80, /* Device 0 Timing Register */ 4407ab85deSAlek Du D1TIM = 0x84, /* Device 1 Timing Register */ 4507ab85deSAlek Du PM = 0x07, /* PIO Mode Bit Mask */ 4607ab85deSAlek Du MDM = (0x03 << 8), /* Multi-word DMA Mode Bit Mask */ 4707ab85deSAlek Du UDM = (0x07 << 16), /* Ultra DMA Mode Bit Mask */ 4807ab85deSAlek Du PPE = (1 << 30), /* Prefetch/Post Enable */ 4907ab85deSAlek Du USD = (1 << 31), /* Use Synchronous DMA */ 5007ab85deSAlek Du }; 5107ab85deSAlek Du 5207ab85deSAlek Du static int sch_init_one(struct pci_dev *pdev, 5307ab85deSAlek Du const struct pci_device_id *ent); 5407ab85deSAlek Du static void sch_set_piomode(struct ata_port *ap, struct ata_device *adev); 5507ab85deSAlek Du static void sch_set_dmamode(struct ata_port *ap, struct ata_device *adev); 5607ab85deSAlek Du 5707ab85deSAlek Du static const struct pci_device_id sch_pci_tbl[] = { 5807ab85deSAlek Du /* Intel SCH PATA Controller */ 5907ab85deSAlek Du { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SCH_IDE), 0 }, 6007ab85deSAlek Du { } /* terminate list */ 6107ab85deSAlek Du }; 6207ab85deSAlek Du 6307ab85deSAlek Du static struct pci_driver sch_pci_driver = { 6407ab85deSAlek Du .name = DRV_NAME, 6507ab85deSAlek Du .id_table = sch_pci_tbl, 6607ab85deSAlek Du .probe = sch_init_one, 6707ab85deSAlek Du .remove = ata_pci_remove_one, 6807ab85deSAlek Du #ifdef CONFIG_PM 6907ab85deSAlek Du .suspend = ata_pci_device_suspend, 7007ab85deSAlek Du .resume = ata_pci_device_resume, 7107ab85deSAlek Du #endif 7207ab85deSAlek Du }; 7307ab85deSAlek Du 7407ab85deSAlek Du static struct scsi_host_template sch_sht = { 7507ab85deSAlek Du ATA_BMDMA_SHT(DRV_NAME), 7607ab85deSAlek Du }; 7707ab85deSAlek Du 7807ab85deSAlek Du static struct ata_port_operations sch_pata_ops = { 7907ab85deSAlek Du .inherits = &ata_bmdma_port_ops, 8007ab85deSAlek Du .cable_detect = ata_cable_unknown, 8107ab85deSAlek Du .set_piomode = sch_set_piomode, 8207ab85deSAlek Du .set_dmamode = sch_set_dmamode, 8307ab85deSAlek Du }; 8407ab85deSAlek Du 8507ab85deSAlek Du static struct ata_port_info sch_port_info = { 86bc170e65SMark Salter .flags = ATA_FLAG_SLAVE_POSS, 87*14bdef98SErik Inge Bolsø .pio_mask = ATA_PIO4, 88*14bdef98SErik Inge Bolsø .mwdma_mask = ATA_MWDMA2, 89*14bdef98SErik Inge Bolsø .udma_mask = ATA_UDMA5, 9007ab85deSAlek Du .port_ops = &sch_pata_ops, 9107ab85deSAlek Du }; 9207ab85deSAlek Du 9307ab85deSAlek Du MODULE_AUTHOR("Alek Du <alek.du@intel.com>"); 9407ab85deSAlek Du MODULE_DESCRIPTION("SCSI low-level driver for Intel SCH PATA controllers"); 9507ab85deSAlek Du MODULE_LICENSE("GPL"); 9607ab85deSAlek Du MODULE_DEVICE_TABLE(pci, sch_pci_tbl); 9707ab85deSAlek Du MODULE_VERSION(DRV_VERSION); 9807ab85deSAlek Du 9907ab85deSAlek Du /** 10007ab85deSAlek Du * sch_set_piomode - Initialize host controller PATA PIO timings 10107ab85deSAlek Du * @ap: Port whose timings we are configuring 10207ab85deSAlek Du * @adev: ATA device 10307ab85deSAlek Du * 10407ab85deSAlek Du * Set PIO mode for device, in host controller PCI config space. 10507ab85deSAlek Du * 10607ab85deSAlek Du * LOCKING: 10707ab85deSAlek Du * None (inherited from caller). 10807ab85deSAlek Du */ 10907ab85deSAlek Du 11007ab85deSAlek Du static void sch_set_piomode(struct ata_port *ap, struct ata_device *adev) 11107ab85deSAlek Du { 11207ab85deSAlek Du unsigned int pio = adev->pio_mode - XFER_PIO_0; 11307ab85deSAlek Du struct pci_dev *dev = to_pci_dev(ap->host->dev); 11407ab85deSAlek Du unsigned int port = adev->devno ? D1TIM : D0TIM; 11507ab85deSAlek Du unsigned int data; 11607ab85deSAlek Du 11707ab85deSAlek Du pci_read_config_dword(dev, port, &data); 11807ab85deSAlek Du /* see SCH datasheet page 351 */ 11907ab85deSAlek Du /* set PIO mode */ 12007ab85deSAlek Du data &= ~(PM | PPE); 12107ab85deSAlek Du data |= pio; 12207ab85deSAlek Du /* enable PPE for block device */ 12307ab85deSAlek Du if (adev->class == ATA_DEV_ATA) 12407ab85deSAlek Du data |= PPE; 12507ab85deSAlek Du pci_write_config_dword(dev, port, data); 12607ab85deSAlek Du } 12707ab85deSAlek Du 12807ab85deSAlek Du /** 12907ab85deSAlek Du * sch_set_dmamode - Initialize host controller PATA DMA timings 13007ab85deSAlek Du * @ap: Port whose timings we are configuring 13107ab85deSAlek Du * @adev: ATA device 13207ab85deSAlek Du * 13307ab85deSAlek Du * Set MW/UDMA mode for device, in host controller PCI config space. 13407ab85deSAlek Du * 13507ab85deSAlek Du * LOCKING: 13607ab85deSAlek Du * None (inherited from caller). 13707ab85deSAlek Du */ 13807ab85deSAlek Du 13907ab85deSAlek Du static void sch_set_dmamode(struct ata_port *ap, struct ata_device *adev) 14007ab85deSAlek Du { 14107ab85deSAlek Du unsigned int dma_mode = adev->dma_mode; 14207ab85deSAlek Du struct pci_dev *dev = to_pci_dev(ap->host->dev); 14307ab85deSAlek Du unsigned int port = adev->devno ? D1TIM : D0TIM; 14407ab85deSAlek Du unsigned int data; 14507ab85deSAlek Du 14607ab85deSAlek Du pci_read_config_dword(dev, port, &data); 14707ab85deSAlek Du /* see SCH datasheet page 351 */ 14807ab85deSAlek Du if (dma_mode >= XFER_UDMA_0) { 14907ab85deSAlek Du /* enable Synchronous DMA mode */ 15007ab85deSAlek Du data |= USD; 15107ab85deSAlek Du data &= ~UDM; 15207ab85deSAlek Du data |= (dma_mode - XFER_UDMA_0) << 16; 15307ab85deSAlek Du } else { /* must be MWDMA mode, since we masked SWDMA already */ 15407ab85deSAlek Du data &= ~(USD | MDM); 15507ab85deSAlek Du data |= (dma_mode - XFER_MW_DMA_0) << 8; 15607ab85deSAlek Du } 15707ab85deSAlek Du pci_write_config_dword(dev, port, data); 15807ab85deSAlek Du } 15907ab85deSAlek Du 16007ab85deSAlek Du /** 16107ab85deSAlek Du * sch_init_one - Register SCH ATA PCI device with kernel services 16207ab85deSAlek Du * @pdev: PCI device to register 16307ab85deSAlek Du * @ent: Entry in sch_pci_tbl matching with @pdev 16407ab85deSAlek Du * 16507ab85deSAlek Du * LOCKING: 16607ab85deSAlek Du * Inherited from PCI layer (may sleep). 16707ab85deSAlek Du * 16807ab85deSAlek Du * RETURNS: 16907ab85deSAlek Du * Zero on success, or -ERRNO value. 17007ab85deSAlek Du */ 17107ab85deSAlek Du 17207ab85deSAlek Du static int __devinit sch_init_one(struct pci_dev *pdev, 17307ab85deSAlek Du const struct pci_device_id *ent) 17407ab85deSAlek Du { 17507ab85deSAlek Du static int printed_version; 17607ab85deSAlek Du const struct ata_port_info *ppi[] = { &sch_port_info, NULL }; 17707ab85deSAlek Du struct ata_host *host; 17807ab85deSAlek Du int rc; 17907ab85deSAlek Du 18007ab85deSAlek Du if (!printed_version++) 18107ab85deSAlek Du dev_printk(KERN_DEBUG, &pdev->dev, 18207ab85deSAlek Du "version " DRV_VERSION "\n"); 18307ab85deSAlek Du 18407ab85deSAlek Du /* enable device and prepare host */ 18507ab85deSAlek Du rc = pcim_enable_device(pdev); 18607ab85deSAlek Du if (rc) 18707ab85deSAlek Du return rc; 18807ab85deSAlek Du rc = ata_pci_sff_prepare_host(pdev, ppi, &host); 18907ab85deSAlek Du if (rc) 19007ab85deSAlek Du return rc; 19107ab85deSAlek Du pci_set_master(pdev); 19207ab85deSAlek Du return ata_pci_sff_activate_host(host, ata_sff_interrupt, &sch_sht); 19307ab85deSAlek Du } 19407ab85deSAlek Du 19507ab85deSAlek Du static int __init sch_init(void) 19607ab85deSAlek Du { 19707ab85deSAlek Du return pci_register_driver(&sch_pci_driver); 19807ab85deSAlek Du } 19907ab85deSAlek Du 20007ab85deSAlek Du static void __exit sch_exit(void) 20107ab85deSAlek Du { 20207ab85deSAlek Du pci_unregister_driver(&sch_pci_driver); 20307ab85deSAlek Du } 20407ab85deSAlek Du 20507ab85deSAlek Du module_init(sch_init); 20607ab85deSAlek Du module_exit(sch_exit); 207