0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #include <linux/kernel.h>
0039 #include <linux/module.h>
0040 #include <linux/pci.h>
0041 #include <linux/blkdev.h>
0042 #include <linux/delay.h>
0043 #include <scsi/scsi_host.h>
0044 #include <linux/libata.h>
0045
0046 #define DRV_NAME "pata_ninja32"
0047 #define DRV_VERSION "0.1.5"
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 static void ninja32_set_piomode(struct ata_port *ap, struct ata_device *adev)
0060 {
0061 static u16 pio_timing[5] = {
0062 0xd6, 0x85, 0x44, 0x33, 0x13
0063 };
0064 iowrite8(pio_timing[adev->pio_mode - XFER_PIO_0],
0065 ap->ioaddr.bmdma_addr + 0x1f);
0066 ap->private_data = adev;
0067 }
0068
0069
0070 static void ninja32_dev_select(struct ata_port *ap, unsigned int device)
0071 {
0072 struct ata_device *adev = &ap->link.device[device];
0073 if (ap->private_data != adev) {
0074 iowrite8(0xd6, ap->ioaddr.bmdma_addr + 0x1f);
0075 ata_sff_dev_select(ap, device);
0076 ninja32_set_piomode(ap, adev);
0077 }
0078 }
0079
0080 static struct scsi_host_template ninja32_sht = {
0081 ATA_BMDMA_SHT(DRV_NAME),
0082 };
0083
0084 static struct ata_port_operations ninja32_port_ops = {
0085 .inherits = &ata_bmdma_port_ops,
0086 .sff_dev_select = ninja32_dev_select,
0087 .cable_detect = ata_cable_40wire,
0088 .set_piomode = ninja32_set_piomode,
0089 .sff_data_xfer = ata_sff_data_xfer32
0090 };
0091
0092 static void ninja32_program(void __iomem *base)
0093 {
0094 iowrite8(0x05, base + 0x01);
0095 iowrite8(0xBE, base + 0x02);
0096 iowrite8(0x01, base + 0x03);
0097 iowrite8(0x20, base + 0x04);
0098 iowrite8(0x8f, base + 0x05);
0099 iowrite8(0xa4, base + 0x1c);
0100 iowrite8(0x83, base + 0x1d);
0101 }
0102
0103 static int ninja32_init_one(struct pci_dev *dev, const struct pci_device_id *id)
0104 {
0105 struct ata_host *host;
0106 struct ata_port *ap;
0107 void __iomem *base;
0108 int rc;
0109
0110 host = ata_host_alloc(&dev->dev, 1);
0111 if (!host)
0112 return -ENOMEM;
0113 ap = host->ports[0];
0114
0115
0116 rc = pcim_enable_device(dev);
0117 if (rc)
0118 return rc;
0119 rc = pcim_iomap_regions(dev, 1 << 0, DRV_NAME);
0120 if (rc == -EBUSY)
0121 pcim_pin_device(dev);
0122 if (rc)
0123 return rc;
0124
0125 host->iomap = pcim_iomap_table(dev);
0126 rc = dma_set_mask_and_coherent(&dev->dev, ATA_DMA_MASK);
0127 if (rc)
0128 return rc;
0129 pci_set_master(dev);
0130
0131
0132
0133 base = host->iomap[0];
0134 if (!base)
0135 return -ENOMEM;
0136 ap->ops = &ninja32_port_ops;
0137 ap->pio_mask = ATA_PIO4;
0138 ap->flags |= ATA_FLAG_SLAVE_POSS;
0139
0140 ap->ioaddr.cmd_addr = base + 0x10;
0141 ap->ioaddr.ctl_addr = base + 0x1E;
0142 ap->ioaddr.altstatus_addr = base + 0x1E;
0143 ap->ioaddr.bmdma_addr = base;
0144 ata_sff_std_ports(&ap->ioaddr);
0145 ap->pflags |= ATA_PFLAG_PIO32 | ATA_PFLAG_PIO32CHANGE;
0146
0147 ninja32_program(base);
0148
0149 return ata_host_activate(host, dev->irq, ata_bmdma_interrupt,
0150 IRQF_SHARED, &ninja32_sht);
0151 }
0152
0153 #ifdef CONFIG_PM_SLEEP
0154 static int ninja32_reinit_one(struct pci_dev *pdev)
0155 {
0156 struct ata_host *host = pci_get_drvdata(pdev);
0157 int rc;
0158
0159 rc = ata_pci_device_do_resume(pdev);
0160 if (rc)
0161 return rc;
0162 ninja32_program(host->iomap[0]);
0163 ata_host_resume(host);
0164 return 0;
0165 }
0166 #endif
0167
0168 static const struct pci_device_id ninja32[] = {
0169 { 0x10FC, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
0170 { 0x1145, 0x8008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
0171 { 0x1145, 0xf008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
0172 { 0x1145, 0xf021, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
0173 { 0x1145, 0xf024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
0174 { 0x1145, 0xf02C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
0175 { },
0176 };
0177
0178 static struct pci_driver ninja32_pci_driver = {
0179 .name = DRV_NAME,
0180 .id_table = ninja32,
0181 .probe = ninja32_init_one,
0182 .remove = ata_pci_remove_one,
0183 #ifdef CONFIG_PM_SLEEP
0184 .suspend = ata_pci_device_suspend,
0185 .resume = ninja32_reinit_one,
0186 #endif
0187 };
0188
0189 module_pci_driver(ninja32_pci_driver);
0190
0191 MODULE_AUTHOR("Alan Cox");
0192 MODULE_DESCRIPTION("low-level driver for Ninja32 ATA");
0193 MODULE_LICENSE("GPL");
0194 MODULE_DEVICE_TABLE(pci, ninja32);
0195 MODULE_VERSION(DRV_VERSION);