0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <linux/kernel.h>
0018 #include <linux/module.h>
0019 #include <linux/pci.h>
0020 #include <linux/blkdev.h>
0021 #include <linux/delay.h>
0022 #include <scsi/scsi_host.h>
0023 #include <linux/libata.h>
0024
0025 #define DRV_NAME "pata_hpt366"
0026 #define DRV_VERSION "0.6.13"
0027
0028 struct hpt_clock {
0029 u8 xfer_mode;
0030 u32 timing;
0031 };
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 static const struct hpt_clock hpt366_40[] = {
0055 { XFER_UDMA_4, 0x900fd943 },
0056 { XFER_UDMA_3, 0x900ad943 },
0057 { XFER_UDMA_2, 0x900bd943 },
0058 { XFER_UDMA_1, 0x9008d943 },
0059 { XFER_UDMA_0, 0x9008d943 },
0060
0061 { XFER_MW_DMA_2, 0xa008d943 },
0062 { XFER_MW_DMA_1, 0xa010d955 },
0063 { XFER_MW_DMA_0, 0xa010d9fc },
0064
0065 { XFER_PIO_4, 0xc008d963 },
0066 { XFER_PIO_3, 0xc010d974 },
0067 { XFER_PIO_2, 0xc010d997 },
0068 { XFER_PIO_1, 0xc010d9c7 },
0069 { XFER_PIO_0, 0xc018d9d9 },
0070 { 0, 0x0120d9d9 }
0071 };
0072
0073 static const struct hpt_clock hpt366_33[] = {
0074 { XFER_UDMA_4, 0x90c9a731 },
0075 { XFER_UDMA_3, 0x90cfa731 },
0076 { XFER_UDMA_2, 0x90caa731 },
0077 { XFER_UDMA_1, 0x90cba731 },
0078 { XFER_UDMA_0, 0x90c8a731 },
0079
0080 { XFER_MW_DMA_2, 0xa0c8a731 },
0081 { XFER_MW_DMA_1, 0xa0c8a732 },
0082 { XFER_MW_DMA_0, 0xa0c8a797 },
0083
0084 { XFER_PIO_4, 0xc0c8a731 },
0085 { XFER_PIO_3, 0xc0c8a742 },
0086 { XFER_PIO_2, 0xc0d0a753 },
0087 { XFER_PIO_1, 0xc0d0a7a3 },
0088 { XFER_PIO_0, 0xc0d0a7aa },
0089 { 0, 0x0120a7a7 }
0090 };
0091
0092 static const struct hpt_clock hpt366_25[] = {
0093 { XFER_UDMA_4, 0x90c98521 },
0094 { XFER_UDMA_3, 0x90cf8521 },
0095 { XFER_UDMA_2, 0x90cf8521 },
0096 { XFER_UDMA_1, 0x90cb8521 },
0097 { XFER_UDMA_0, 0x90cb8521 },
0098
0099 { XFER_MW_DMA_2, 0xa0ca8521 },
0100 { XFER_MW_DMA_1, 0xa0ca8532 },
0101 { XFER_MW_DMA_0, 0xa0ca8575 },
0102
0103 { XFER_PIO_4, 0xc0ca8521 },
0104 { XFER_PIO_3, 0xc0ca8532 },
0105 { XFER_PIO_2, 0xc0ca8542 },
0106 { XFER_PIO_1, 0xc0d08572 },
0107 { XFER_PIO_0, 0xc0d08585 },
0108 { 0, 0x01208585 }
0109 };
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120 static u32 hpt36x_find_mode(struct ata_port *ap, int speed)
0121 {
0122 struct hpt_clock *clocks = ap->host->private_data;
0123
0124 while (clocks->xfer_mode) {
0125 if (clocks->xfer_mode == speed)
0126 return clocks->timing;
0127 clocks++;
0128 }
0129 BUG();
0130 return 0xffffffffU;
0131 }
0132
0133 static const char * const bad_ata33[] = {
0134 "Maxtor 92720U8", "Maxtor 92040U6", "Maxtor 91360U4", "Maxtor 91020U3",
0135 "Maxtor 90845U3", "Maxtor 90650U2",
0136 "Maxtor 91360D8", "Maxtor 91190D7", "Maxtor 91020D6", "Maxtor 90845D5",
0137 "Maxtor 90680D4", "Maxtor 90510D3", "Maxtor 90340D2",
0138 "Maxtor 91152D8", "Maxtor 91008D7", "Maxtor 90845D6", "Maxtor 90840D6",
0139 "Maxtor 90720D5", "Maxtor 90648D5", "Maxtor 90576D4",
0140 "Maxtor 90510D4",
0141 "Maxtor 90432D3", "Maxtor 90288D2", "Maxtor 90256D2",
0142 "Maxtor 91000D8", "Maxtor 90910D8", "Maxtor 90875D7", "Maxtor 90840D7",
0143 "Maxtor 90750D6", "Maxtor 90625D5", "Maxtor 90500D4",
0144 "Maxtor 91728D8", "Maxtor 91512D7", "Maxtor 91303D6", "Maxtor 91080D5",
0145 "Maxtor 90845D4", "Maxtor 90680D4", "Maxtor 90648D3", "Maxtor 90432D2",
0146 NULL
0147 };
0148
0149 static const char * const bad_ata66_4[] = {
0150 "IBM-DTLA-307075",
0151 "IBM-DTLA-307060",
0152 "IBM-DTLA-307045",
0153 "IBM-DTLA-307030",
0154 "IBM-DTLA-307020",
0155 "IBM-DTLA-307015",
0156 "IBM-DTLA-305040",
0157 "IBM-DTLA-305030",
0158 "IBM-DTLA-305020",
0159 "IC35L010AVER07-0",
0160 "IC35L020AVER07-0",
0161 "IC35L030AVER07-0",
0162 "IC35L040AVER07-0",
0163 "IC35L060AVER07-0",
0164 "WDC AC310200R",
0165 NULL
0166 };
0167
0168 static const char * const bad_ata66_3[] = {
0169 "WDC AC310200R",
0170 NULL
0171 };
0172
0173 static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr,
0174 const char * const list[])
0175 {
0176 unsigned char model_num[ATA_ID_PROD_LEN + 1];
0177 int i;
0178
0179 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
0180
0181 i = match_string(list, -1, model_num);
0182 if (i >= 0) {
0183 ata_dev_warn(dev, "%s is not supported for %s\n", modestr, list[i]);
0184 return 1;
0185 }
0186 return 0;
0187 }
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197 static unsigned int hpt366_filter(struct ata_device *adev, unsigned int mask)
0198 {
0199 if (adev->class == ATA_DEV_ATA) {
0200 if (hpt_dma_blacklisted(adev, "UDMA", bad_ata33))
0201 mask &= ~ATA_MASK_UDMA;
0202 if (hpt_dma_blacklisted(adev, "UDMA3", bad_ata66_3))
0203 mask &= ~(0xF8 << ATA_SHIFT_UDMA);
0204 if (hpt_dma_blacklisted(adev, "UDMA4", bad_ata66_4))
0205 mask &= ~(0xF0 << ATA_SHIFT_UDMA);
0206 } else if (adev->class == ATA_DEV_ATAPI)
0207 mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
0208
0209 return mask;
0210 }
0211
0212 static int hpt36x_cable_detect(struct ata_port *ap)
0213 {
0214 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
0215 u8 ata66;
0216
0217
0218
0219
0220
0221 pci_read_config_byte(pdev, 0x5A, &ata66);
0222 if (ata66 & 2)
0223 return ATA_CBL_PATA40;
0224 return ATA_CBL_PATA80;
0225 }
0226
0227 static void hpt366_set_mode(struct ata_port *ap, struct ata_device *adev,
0228 u8 mode)
0229 {
0230 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
0231 u32 addr = 0x40 + 4 * adev->devno;
0232 u32 mask, reg, t;
0233
0234
0235 if (mode < XFER_MW_DMA_0)
0236 mask = 0xc1f8ffff;
0237 else if (mode < XFER_UDMA_0)
0238 mask = 0x303800ff;
0239 else
0240 mask = 0x30070000;
0241
0242 t = hpt36x_find_mode(ap, mode);
0243
0244
0245
0246
0247
0248
0249 pci_read_config_dword(pdev, addr, ®);
0250 reg = ((reg & ~mask) | (t & mask)) & ~0xc0000000;
0251 pci_write_config_dword(pdev, addr, reg);
0252 }
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262 static void hpt366_set_piomode(struct ata_port *ap, struct ata_device *adev)
0263 {
0264 hpt366_set_mode(ap, adev, adev->pio_mode);
0265 }
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276 static void hpt366_set_dmamode(struct ata_port *ap, struct ata_device *adev)
0277 {
0278 hpt366_set_mode(ap, adev, adev->dma_mode);
0279 }
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290 static int hpt366_prereset(struct ata_link *link, unsigned long deadline)
0291 {
0292 struct ata_port *ap = link->ap;
0293 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
0294
0295
0296
0297
0298
0299
0300 static const struct pci_bits hpt366_enable_bits = {
0301 0x50, 1, 0x30, 0x30
0302 };
0303 u8 mcr2;
0304
0305 if (!pci_test_config_bits(pdev, &hpt366_enable_bits))
0306 return -ENOENT;
0307
0308 pci_read_config_byte(pdev, 0x51, &mcr2);
0309 if (mcr2 & 0x80)
0310 pci_write_config_byte(pdev, 0x51, mcr2 & ~0x80);
0311
0312 return ata_sff_prereset(link, deadline);
0313 }
0314
0315 static struct scsi_host_template hpt36x_sht = {
0316 ATA_BMDMA_SHT(DRV_NAME),
0317 };
0318
0319
0320
0321
0322
0323 static struct ata_port_operations hpt366_port_ops = {
0324 .inherits = &ata_bmdma_port_ops,
0325 .prereset = hpt366_prereset,
0326 .cable_detect = hpt36x_cable_detect,
0327 .mode_filter = hpt366_filter,
0328 .set_piomode = hpt366_set_piomode,
0329 .set_dmamode = hpt366_set_dmamode,
0330 };
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340 static void hpt36x_init_chipset(struct pci_dev *dev)
0341 {
0342 u8 mcr1;
0343
0344 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
0345 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
0346 pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
0347 pci_write_config_byte(dev, PCI_MAX_LAT, 0x08);
0348
0349
0350
0351
0352
0353 pci_read_config_byte(dev, 0x50, &mcr1);
0354 if (mcr1 & 0x30)
0355 pci_write_config_byte(dev, 0x50, mcr1 | 0x30);
0356 }
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379 static int hpt36x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
0380 {
0381 static const struct ata_port_info info_hpt366 = {
0382 .flags = ATA_FLAG_SLAVE_POSS,
0383 .pio_mask = ATA_PIO4,
0384 .mwdma_mask = ATA_MWDMA2,
0385 .udma_mask = ATA_UDMA4,
0386 .port_ops = &hpt366_port_ops
0387 };
0388 const struct ata_port_info *ppi[] = { &info_hpt366, NULL };
0389
0390 const void *hpriv = NULL;
0391 u32 reg1;
0392 int rc;
0393
0394 rc = pcim_enable_device(dev);
0395 if (rc)
0396 return rc;
0397
0398
0399
0400 if (dev->revision > 2)
0401 return -ENODEV;
0402
0403 hpt36x_init_chipset(dev);
0404
0405 pci_read_config_dword(dev, 0x40, ®1);
0406
0407
0408
0409 switch ((reg1 & 0xf00) >> 8) {
0410 case 9:
0411 hpriv = &hpt366_40;
0412 break;
0413 case 5:
0414 hpriv = &hpt366_25;
0415 break;
0416 default:
0417 hpriv = &hpt366_33;
0418 break;
0419 }
0420
0421 return ata_pci_bmdma_init_one(dev, ppi, &hpt36x_sht, (void *)hpriv, 0);
0422 }
0423
0424 #ifdef CONFIG_PM_SLEEP
0425 static int hpt36x_reinit_one(struct pci_dev *dev)
0426 {
0427 struct ata_host *host = pci_get_drvdata(dev);
0428 int rc;
0429
0430 rc = ata_pci_device_do_resume(dev);
0431 if (rc)
0432 return rc;
0433 hpt36x_init_chipset(dev);
0434 ata_host_resume(host);
0435 return 0;
0436 }
0437 #endif
0438
0439 static const struct pci_device_id hpt36x[] = {
0440 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT366), },
0441 { },
0442 };
0443
0444 static struct pci_driver hpt36x_pci_driver = {
0445 .name = DRV_NAME,
0446 .id_table = hpt36x,
0447 .probe = hpt36x_init_one,
0448 .remove = ata_pci_remove_one,
0449 #ifdef CONFIG_PM_SLEEP
0450 .suspend = ata_pci_device_suspend,
0451 .resume = hpt36x_reinit_one,
0452 #endif
0453 };
0454
0455 module_pci_driver(hpt36x_pci_driver);
0456
0457 MODULE_AUTHOR("Alan Cox");
0458 MODULE_DESCRIPTION("low-level driver for the Highpoint HPT366/368");
0459 MODULE_LICENSE("GPL");
0460 MODULE_DEVICE_TABLE(pci, hpt36x);
0461 MODULE_VERSION(DRV_VERSION);