0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include <linux/kernel.h>
0017 #include <linux/module.h>
0018 #include <linux/pci.h>
0019 #include <linux/blkdev.h>
0020 #include <linux/delay.h>
0021 #include <scsi/scsi_host.h>
0022 #include <linux/libata.h>
0023
0024 #define DRV_NAME "pata_hpt3x3"
0025 #define DRV_VERSION "0.6.1"
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 static void hpt3x3_set_piomode(struct ata_port *ap, struct ata_device *adev)
0038 {
0039 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
0040 u32 r1, r2;
0041 int dn = 2 * ap->port_no + adev->devno;
0042
0043 pci_read_config_dword(pdev, 0x44, &r1);
0044 pci_read_config_dword(pdev, 0x48, &r2);
0045
0046 r1 &= ~(7 << (3 * dn));
0047 r1 |= (adev->pio_mode - XFER_PIO_0) << (3 * dn);
0048 r2 &= ~(0x11 << dn);
0049
0050 pci_write_config_dword(pdev, 0x44, r1);
0051 pci_write_config_dword(pdev, 0x48, r2);
0052 }
0053
0054 #if defined(CONFIG_PATA_HPT3X3_DMA)
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 static void hpt3x3_set_dmamode(struct ata_port *ap, struct ata_device *adev)
0068 {
0069 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
0070 u32 r1, r2;
0071 int dn = 2 * ap->port_no + adev->devno;
0072 int mode_num = adev->dma_mode & 0x0F;
0073
0074 pci_read_config_dword(pdev, 0x44, &r1);
0075 pci_read_config_dword(pdev, 0x48, &r2);
0076
0077 r1 &= ~(7 << (3 * dn));
0078 r1 |= (mode_num << (3 * dn));
0079 r2 &= ~(0x11 << dn);
0080
0081 if (adev->dma_mode >= XFER_UDMA_0)
0082 r2 |= (0x01 << dn);
0083 else
0084 r2 |= (0x10 << dn);
0085
0086 pci_write_config_dword(pdev, 0x44, r1);
0087 pci_write_config_dword(pdev, 0x48, r2);
0088 }
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098 static void hpt3x3_freeze(struct ata_port *ap)
0099 {
0100 void __iomem *mmio = ap->ioaddr.bmdma_addr;
0101
0102 iowrite8(ioread8(mmio + ATA_DMA_CMD) & ~ ATA_DMA_START,
0103 mmio + ATA_DMA_CMD);
0104 ata_sff_dma_pause(ap);
0105 ata_sff_freeze(ap);
0106 }
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116 static void hpt3x3_bmdma_setup(struct ata_queued_cmd *qc)
0117 {
0118 struct ata_port *ap = qc->ap;
0119 u8 r = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
0120 r |= ATA_DMA_INTR | ATA_DMA_ERR;
0121 iowrite8(r, ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
0122 return ata_bmdma_setup(qc);
0123 }
0124
0125
0126
0127
0128
0129
0130
0131
0132 static int hpt3x3_atapi_dma(struct ata_queued_cmd *qc)
0133 {
0134 return 1;
0135 }
0136
0137 #endif
0138
0139 static struct scsi_host_template hpt3x3_sht = {
0140 ATA_BMDMA_SHT(DRV_NAME),
0141 };
0142
0143 static struct ata_port_operations hpt3x3_port_ops = {
0144 .inherits = &ata_bmdma_port_ops,
0145 .cable_detect = ata_cable_40wire,
0146 .set_piomode = hpt3x3_set_piomode,
0147 #if defined(CONFIG_PATA_HPT3X3_DMA)
0148 .set_dmamode = hpt3x3_set_dmamode,
0149 .bmdma_setup = hpt3x3_bmdma_setup,
0150 .check_atapi_dma= hpt3x3_atapi_dma,
0151 .freeze = hpt3x3_freeze,
0152 #endif
0153
0154 };
0155
0156
0157
0158
0159
0160
0161
0162
0163 static void hpt3x3_init_chipset(struct pci_dev *dev)
0164 {
0165 u16 cmd;
0166
0167 pci_write_config_word(dev, 0x80, 0x00);
0168
0169 pci_read_config_word(dev, PCI_COMMAND, &cmd);
0170 if (cmd & PCI_COMMAND_MEMORY)
0171 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0xF0);
0172 else
0173 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20);
0174 }
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185 static int hpt3x3_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
0186 {
0187 static const struct ata_port_info info = {
0188 .flags = ATA_FLAG_SLAVE_POSS,
0189 .pio_mask = ATA_PIO4,
0190 #if defined(CONFIG_PATA_HPT3X3_DMA)
0191
0192 .mwdma_mask = ATA_MWDMA2,
0193 .udma_mask = ATA_UDMA2,
0194 #endif
0195 .port_ops = &hpt3x3_port_ops
0196 };
0197
0198 static const u8 offset_cmd[2] = { 0x20, 0x28 };
0199 static const u8 offset_ctl[2] = { 0x36, 0x3E };
0200 const struct ata_port_info *ppi[] = { &info, NULL };
0201 struct ata_host *host;
0202 int i, rc;
0203 void __iomem *base;
0204
0205 hpt3x3_init_chipset(pdev);
0206
0207 ata_print_version_once(&pdev->dev, DRV_VERSION);
0208
0209 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2);
0210 if (!host)
0211 return -ENOMEM;
0212
0213 rc = pcim_enable_device(pdev);
0214 if (rc)
0215 return rc;
0216
0217
0218 rc = pcim_iomap_regions(pdev, 1 << 4, DRV_NAME);
0219 if (rc == -EBUSY)
0220 pcim_pin_device(pdev);
0221 if (rc)
0222 return rc;
0223 host->iomap = pcim_iomap_table(pdev);
0224 rc = dma_set_mask_and_coherent(&pdev->dev, ATA_DMA_MASK);
0225 if (rc)
0226 return rc;
0227
0228 base = host->iomap[4];
0229
0230 for (i = 0; i < host->n_ports; i++) {
0231 struct ata_port *ap = host->ports[i];
0232 struct ata_ioports *ioaddr = &ap->ioaddr;
0233
0234 ioaddr->cmd_addr = base + offset_cmd[i];
0235 ioaddr->altstatus_addr =
0236 ioaddr->ctl_addr = base + offset_ctl[i];
0237 ioaddr->scr_addr = NULL;
0238 ata_sff_std_ports(ioaddr);
0239 ioaddr->bmdma_addr = base + 8 * i;
0240
0241 ata_port_pbar_desc(ap, 4, -1, "ioport");
0242 ata_port_pbar_desc(ap, 4, offset_cmd[i], "cmd");
0243 }
0244 pci_set_master(pdev);
0245 return ata_host_activate(host, pdev->irq, ata_bmdma_interrupt,
0246 IRQF_SHARED, &hpt3x3_sht);
0247 }
0248
0249 #ifdef CONFIG_PM_SLEEP
0250 static int hpt3x3_reinit_one(struct pci_dev *dev)
0251 {
0252 struct ata_host *host = pci_get_drvdata(dev);
0253 int rc;
0254
0255 rc = ata_pci_device_do_resume(dev);
0256 if (rc)
0257 return rc;
0258
0259 hpt3x3_init_chipset(dev);
0260
0261 ata_host_resume(host);
0262 return 0;
0263 }
0264 #endif
0265
0266 static const struct pci_device_id hpt3x3[] = {
0267 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT343), },
0268
0269 { },
0270 };
0271
0272 static struct pci_driver hpt3x3_pci_driver = {
0273 .name = DRV_NAME,
0274 .id_table = hpt3x3,
0275 .probe = hpt3x3_init_one,
0276 .remove = ata_pci_remove_one,
0277 #ifdef CONFIG_PM_SLEEP
0278 .suspend = ata_pci_device_suspend,
0279 .resume = hpt3x3_reinit_one,
0280 #endif
0281 };
0282
0283 module_pci_driver(hpt3x3_pci_driver);
0284
0285 MODULE_AUTHOR("Alan Cox");
0286 MODULE_DESCRIPTION("low-level driver for the Highpoint HPT343/363");
0287 MODULE_LICENSE("GPL");
0288 MODULE_DEVICE_TABLE(pci, hpt3x3);
0289 MODULE_VERSION(DRV_VERSION);