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 <linux/device.h>
0022 #include <scsi/scsi_host.h>
0023 #include <linux/libata.h>
0024 #include <linux/ata.h>
0025
0026 #define DRV_NAME "pata_radisys"
0027 #define DRV_VERSION "0.4.4"
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 static void radisys_set_piomode (struct ata_port *ap, struct ata_device *adev)
0041 {
0042 unsigned int pio = adev->pio_mode - XFER_PIO_0;
0043 struct pci_dev *dev = to_pci_dev(ap->host->dev);
0044 u16 idetm_data;
0045 int control = 0;
0046
0047
0048
0049
0050
0051
0052
0053
0054 static const
0055 u8 timings[][2] = { { 0, 0 },
0056 { 0, 0 },
0057 { 1, 1 },
0058 { 2, 2 },
0059 { 3, 3 }, };
0060
0061 if (pio > 0)
0062 control |= 1;
0063 if (ata_pio_need_iordy(adev))
0064 control |= 2;
0065
0066 pci_read_config_word(dev, 0x40, &idetm_data);
0067
0068
0069
0070 idetm_data &= 0xCCCC;
0071 idetm_data |= (control << (4 * adev->devno));
0072 idetm_data |= (timings[pio][0] << 12) |
0073 (timings[pio][1] << 8);
0074 pci_write_config_word(dev, 0x40, idetm_data);
0075
0076
0077 ap->private_data = adev;
0078 }
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 static void radisys_set_dmamode (struct ata_port *ap, struct ata_device *adev)
0092 {
0093 struct pci_dev *dev = to_pci_dev(ap->host->dev);
0094 u16 idetm_data;
0095 u8 udma_enable;
0096
0097 static const
0098 u8 timings[][2] = { { 0, 0 },
0099 { 0, 0 },
0100 { 1, 1 },
0101 { 2, 2 },
0102 { 3, 3 }, };
0103
0104
0105
0106
0107
0108
0109 pci_read_config_word(dev, 0x40, &idetm_data);
0110 pci_read_config_byte(dev, 0x48, &udma_enable);
0111
0112 if (adev->dma_mode < XFER_UDMA_0) {
0113 unsigned int mwdma = adev->dma_mode - XFER_MW_DMA_0;
0114 const unsigned int needed_pio[3] = {
0115 XFER_PIO_0, XFER_PIO_3, XFER_PIO_4
0116 };
0117 int pio = needed_pio[mwdma] - XFER_PIO_0;
0118 int control = 3;
0119
0120
0121
0122
0123 if (adev->pio_mode < needed_pio[mwdma])
0124 control = 1;
0125
0126
0127
0128
0129 idetm_data &= 0xCCCC;
0130 idetm_data |= control << (4 * adev->devno);
0131 idetm_data |= (timings[pio][0] << 12) | (timings[pio][1] << 8);
0132
0133 udma_enable &= ~(1 << adev->devno);
0134 } else {
0135 u8 udma_mode;
0136
0137
0138
0139 pci_read_config_byte(dev, 0x4A, &udma_mode);
0140
0141 if (adev->xfer_mode == XFER_UDMA_2)
0142 udma_mode &= ~(2 << (adev->devno * 4));
0143 else
0144 udma_mode |= (2 << (adev->devno * 4));
0145
0146 pci_write_config_byte(dev, 0x4A, udma_mode);
0147
0148 udma_enable |= (1 << adev->devno);
0149 }
0150 pci_write_config_word(dev, 0x40, idetm_data);
0151 pci_write_config_byte(dev, 0x48, udma_enable);
0152
0153
0154 ap->private_data = adev;
0155 }
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168 static unsigned int radisys_qc_issue(struct ata_queued_cmd *qc)
0169 {
0170 struct ata_port *ap = qc->ap;
0171 struct ata_device *adev = qc->dev;
0172
0173 if (adev != ap->private_data) {
0174
0175 if (adev->dma_mode < XFER_UDMA_0 || !ata_dma_enabled(adev)) {
0176 if (ata_dma_enabled(adev))
0177 radisys_set_dmamode(ap, adev);
0178 else if (adev->pio_mode)
0179 radisys_set_piomode(ap, adev);
0180 }
0181 }
0182 return ata_bmdma_qc_issue(qc);
0183 }
0184
0185
0186 static struct scsi_host_template radisys_sht = {
0187 ATA_BMDMA_SHT(DRV_NAME),
0188 };
0189
0190 static struct ata_port_operations radisys_pata_ops = {
0191 .inherits = &ata_bmdma_port_ops,
0192 .qc_issue = radisys_qc_issue,
0193 .cable_detect = ata_cable_unknown,
0194 .set_piomode = radisys_set_piomode,
0195 .set_dmamode = radisys_set_dmamode,
0196 };
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214 static int radisys_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
0215 {
0216 static const struct ata_port_info info = {
0217 .flags = ATA_FLAG_SLAVE_POSS,
0218 .pio_mask = ATA_PIO4,
0219 .mwdma_mask = ATA_MWDMA12_ONLY,
0220 .udma_mask = ATA_UDMA24_ONLY,
0221 .port_ops = &radisys_pata_ops,
0222 };
0223 const struct ata_port_info *ppi[] = { &info, NULL };
0224
0225 ata_print_version_once(&pdev->dev, DRV_VERSION);
0226
0227 return ata_pci_bmdma_init_one(pdev, ppi, &radisys_sht, NULL, 0);
0228 }
0229
0230 static const struct pci_device_id radisys_pci_tbl[] = {
0231 { PCI_VDEVICE(RADISYS, 0x8201), },
0232
0233 { }
0234 };
0235
0236 static struct pci_driver radisys_pci_driver = {
0237 .name = DRV_NAME,
0238 .id_table = radisys_pci_tbl,
0239 .probe = radisys_init_one,
0240 .remove = ata_pci_remove_one,
0241 #ifdef CONFIG_PM_SLEEP
0242 .suspend = ata_pci_device_suspend,
0243 .resume = ata_pci_device_resume,
0244 #endif
0245 };
0246
0247 module_pci_driver(radisys_pci_driver);
0248
0249 MODULE_AUTHOR("Alan Cox");
0250 MODULE_DESCRIPTION("SCSI low-level driver for Radisys R82600 controllers");
0251 MODULE_LICENSE("GPL");
0252 MODULE_DEVICE_TABLE(pci, radisys_pci_tbl);
0253 MODULE_VERSION(DRV_VERSION);