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
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 #include <linux/kernel.h>
0073 #include <linux/module.h>
0074 #include <linux/pci.h>
0075 #include <linux/blkdev.h>
0076 #include <linux/delay.h>
0077 #include <linux/slab.h>
0078 #include <scsi/scsi_host.h>
0079 #include <linux/libata.h>
0080
0081
0082 #define DRV_NAME "pata_it821x"
0083 #define DRV_VERSION "0.4.2"
0084
0085 struct it821x_dev
0086 {
0087 unsigned int smart:1,
0088 timing10:1;
0089 u8 clock_mode;
0090 u8 want[2][2];
0091
0092
0093 u16 pio[2];
0094 u16 mwdma[2];
0095 u16 udma[2];
0096 u16 last_device;
0097 };
0098
0099 #define ATA_66 0
0100 #define ATA_50 1
0101 #define ATA_ANY 2
0102
0103 #define UDMA_OFF 0
0104 #define MWDMA_OFF 0
0105
0106
0107
0108
0109
0110
0111
0112
0113 static int it8212_noraid;
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126 static void it821x_program(struct ata_port *ap, struct ata_device *adev, u16 timing)
0127 {
0128 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
0129 struct it821x_dev *itdev = ap->private_data;
0130 int channel = ap->port_no;
0131 u8 conf;
0132
0133
0134 if (itdev->clock_mode == ATA_66)
0135 conf = timing >> 8;
0136 else
0137 conf = timing & 0xFF;
0138 pci_write_config_byte(pdev, 0x54 + 4 * channel, conf);
0139 }
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154 static void it821x_program_udma(struct ata_port *ap, struct ata_device *adev, u16 timing)
0155 {
0156 struct it821x_dev *itdev = ap->private_data;
0157 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
0158 int channel = ap->port_no;
0159 int unit = adev->devno;
0160 u8 conf;
0161
0162
0163 if (itdev->clock_mode == ATA_66)
0164 conf = timing >> 8;
0165 else
0166 conf = timing & 0xFF;
0167 if (itdev->timing10 == 0)
0168 pci_write_config_byte(pdev, 0x56 + 4 * channel + unit, conf);
0169 else {
0170
0171 pci_write_config_byte(pdev, 0x56 + 4 * channel, conf);
0172 pci_write_config_byte(pdev, 0x56 + 4 * channel + 1, conf);
0173 }
0174 }
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185 static void it821x_clock_strategy(struct ata_port *ap, struct ata_device *adev)
0186 {
0187 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
0188 struct it821x_dev *itdev = ap->private_data;
0189 u8 unit = adev->devno;
0190 struct ata_device *pair = ata_dev_pair(adev);
0191
0192 int clock, altclock;
0193 u8 v;
0194 int sel = 0;
0195
0196
0197 if (itdev->want[0][0] > itdev->want[1][0]) {
0198 clock = itdev->want[0][1];
0199 altclock = itdev->want[1][1];
0200 } else {
0201 clock = itdev->want[1][1];
0202 altclock = itdev->want[0][1];
0203 }
0204
0205
0206 if (clock == ATA_ANY)
0207 clock = altclock;
0208
0209
0210 if (clock == ATA_ANY)
0211 return;
0212
0213 if (clock == itdev->clock_mode)
0214 return;
0215
0216
0217 if (clock == ATA_66)
0218 itdev->clock_mode = ATA_66;
0219 else {
0220 itdev->clock_mode = ATA_50;
0221 sel = 1;
0222 }
0223 pci_read_config_byte(pdev, 0x50, &v);
0224 v &= ~(1 << (1 + ap->port_no));
0225 v |= sel << (1 + ap->port_no);
0226 pci_write_config_byte(pdev, 0x50, v);
0227
0228
0229
0230
0231
0232 if (pair && itdev->udma[1-unit] != UDMA_OFF) {
0233 it821x_program_udma(ap, pair, itdev->udma[1-unit]);
0234 it821x_program(ap, pair, itdev->pio[1-unit]);
0235 }
0236
0237
0238
0239
0240 if (itdev->udma[unit] != UDMA_OFF) {
0241 it821x_program_udma(ap, adev, itdev->udma[unit]);
0242 it821x_program(ap, adev, itdev->pio[unit]);
0243 }
0244 }
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255 static void it821x_passthru_set_piomode(struct ata_port *ap, struct ata_device *adev)
0256 {
0257
0258 static const u16 pio[] = { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 };
0259 static const u8 pio_want[] = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY };
0260
0261 struct it821x_dev *itdev = ap->private_data;
0262 int unit = adev->devno;
0263 int mode_wanted = adev->pio_mode - XFER_PIO_0;
0264
0265
0266 itdev->want[unit][1] = pio_want[mode_wanted];
0267 itdev->want[unit][0] = 1;
0268 itdev->pio[unit] = pio[mode_wanted];
0269 it821x_clock_strategy(ap, adev);
0270 it821x_program(ap, adev, itdev->pio[unit]);
0271 }
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285 static void it821x_passthru_set_dmamode(struct ata_port *ap, struct ata_device *adev)
0286 {
0287 static const u16 dma[] = { 0x8866, 0x3222, 0x3121 };
0288 static const u8 mwdma_want[] = { ATA_ANY, ATA_66, ATA_ANY };
0289 static const u16 udma[] = { 0x4433, 0x4231, 0x3121, 0x2121, 0x1111, 0x2211, 0x1111 };
0290 static const u8 udma_want[] = { ATA_ANY, ATA_50, ATA_ANY, ATA_66, ATA_66, ATA_50, ATA_66 };
0291
0292 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
0293 struct it821x_dev *itdev = ap->private_data;
0294 int channel = ap->port_no;
0295 int unit = adev->devno;
0296 u8 conf;
0297
0298 if (adev->dma_mode >= XFER_UDMA_0) {
0299 int mode_wanted = adev->dma_mode - XFER_UDMA_0;
0300
0301 itdev->want[unit][1] = udma_want[mode_wanted];
0302 itdev->want[unit][0] = 3;
0303 itdev->mwdma[unit] = MWDMA_OFF;
0304 itdev->udma[unit] = udma[mode_wanted];
0305 if (mode_wanted >= 5)
0306 itdev->udma[unit] |= 0x8080;
0307
0308
0309 pci_read_config_byte(pdev, 0x50, &conf);
0310 if (itdev->timing10)
0311 conf &= channel ? 0x9F: 0xE7;
0312 else
0313 conf &= ~ (1 << (3 + 2 * channel + unit));
0314 pci_write_config_byte(pdev, 0x50, conf);
0315 it821x_clock_strategy(ap, adev);
0316 it821x_program_udma(ap, adev, itdev->udma[unit]);
0317 } else {
0318 int mode_wanted = adev->dma_mode - XFER_MW_DMA_0;
0319
0320 itdev->want[unit][1] = mwdma_want[mode_wanted];
0321 itdev->want[unit][0] = 2;
0322 itdev->mwdma[unit] = dma[mode_wanted];
0323 itdev->udma[unit] = UDMA_OFF;
0324
0325
0326 pci_read_config_byte(pdev, 0x50, &conf);
0327 if (itdev->timing10)
0328 conf |= channel ? 0x60: 0x18;
0329 else
0330 conf |= 1 << (3 + 2 * channel + unit);
0331 pci_write_config_byte(pdev, 0x50, conf);
0332 it821x_clock_strategy(ap, adev);
0333 }
0334 }
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345 static void it821x_passthru_bmdma_start(struct ata_queued_cmd *qc)
0346 {
0347 struct ata_port *ap = qc->ap;
0348 struct ata_device *adev = qc->dev;
0349 struct it821x_dev *itdev = ap->private_data;
0350 int unit = adev->devno;
0351
0352 if (itdev->mwdma[unit] != MWDMA_OFF)
0353 it821x_program(ap, adev, itdev->mwdma[unit]);
0354 else if (itdev->udma[unit] != UDMA_OFF && itdev->timing10)
0355 it821x_program_udma(ap, adev, itdev->udma[unit]);
0356 ata_bmdma_start(qc);
0357 }
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368 static void it821x_passthru_bmdma_stop(struct ata_queued_cmd *qc)
0369 {
0370 struct ata_port *ap = qc->ap;
0371 struct ata_device *adev = qc->dev;
0372 struct it821x_dev *itdev = ap->private_data;
0373 int unit = adev->devno;
0374
0375 ata_bmdma_stop(qc);
0376 if (itdev->mwdma[unit] != MWDMA_OFF)
0377 it821x_program(ap, adev, itdev->pio[unit]);
0378 }
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389 static void it821x_passthru_dev_select(struct ata_port *ap,
0390 unsigned int device)
0391 {
0392 struct it821x_dev *itdev = ap->private_data;
0393 if (itdev && device != itdev->last_device) {
0394 struct ata_device *adev = &ap->link.device[device];
0395 it821x_program(ap, adev, itdev->pio[adev->devno]);
0396 itdev->last_device = device;
0397 }
0398 ata_sff_dev_select(ap, device);
0399 }
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410 static unsigned int it821x_smart_qc_issue(struct ata_queued_cmd *qc)
0411 {
0412 switch(qc->tf.command)
0413 {
0414
0415 case ATA_CMD_READ:
0416 case ATA_CMD_READ_EXT:
0417 case ATA_CMD_WRITE:
0418 case ATA_CMD_WRITE_EXT:
0419 case ATA_CMD_PIO_READ:
0420 case ATA_CMD_PIO_READ_EXT:
0421 case ATA_CMD_PIO_WRITE:
0422 case ATA_CMD_PIO_WRITE_EXT:
0423 case ATA_CMD_READ_MULTI:
0424 case ATA_CMD_READ_MULTI_EXT:
0425 case ATA_CMD_WRITE_MULTI:
0426 case ATA_CMD_WRITE_MULTI_EXT:
0427 case ATA_CMD_ID_ATA:
0428 case ATA_CMD_INIT_DEV_PARAMS:
0429 case 0xFC:
0430
0431 case ATA_CMD_SET_FEATURES:
0432 return ata_bmdma_qc_issue(qc);
0433 }
0434 ata_dev_dbg(qc->dev, "it821x: can't process command 0x%02X\n",
0435 qc->tf.command);
0436 return AC_ERR_DEV;
0437 }
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448 static unsigned int it821x_passthru_qc_issue(struct ata_queued_cmd *qc)
0449 {
0450 it821x_passthru_dev_select(qc->ap, qc->dev->devno);
0451 return ata_bmdma_qc_issue(qc);
0452 }
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465 static int it821x_smart_set_mode(struct ata_link *link, struct ata_device **unused)
0466 {
0467 struct ata_device *dev;
0468
0469 ata_for_each_dev(dev, link, ENABLED) {
0470
0471 dev->pio_mode = XFER_PIO_0;
0472 dev->dma_mode = XFER_MW_DMA_0;
0473
0474
0475 if (ata_id_has_dma(dev->id)) {
0476 ata_dev_info(dev, "configured for DMA\n");
0477 dev->xfer_mode = XFER_MW_DMA_0;
0478 dev->xfer_shift = ATA_SHIFT_MWDMA;
0479 dev->flags &= ~ATA_DFLAG_PIO;
0480 } else {
0481 ata_dev_info(dev, "configured for PIO\n");
0482 dev->xfer_mode = XFER_PIO_0;
0483 dev->xfer_shift = ATA_SHIFT_PIO;
0484 dev->flags |= ATA_DFLAG_PIO;
0485 }
0486 }
0487 return 0;
0488 }
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500 static void it821x_dev_config(struct ata_device *adev)
0501 {
0502 unsigned char model_num[ATA_ID_PROD_LEN + 1];
0503
0504 ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
0505
0506 if (adev->max_sectors > 255)
0507 adev->max_sectors = 255;
0508
0509 if (strstr(model_num, "Integrated Technology Express")) {
0510
0511 if (adev->id[129] == 1)
0512 ata_dev_info(adev, "%sRAID%d volume\n",
0513 adev->id[147] ? "Bootable " : "",
0514 adev->id[129]);
0515 else
0516 ata_dev_info(adev, "%sRAID%d volume (%dK stripe)\n",
0517 adev->id[147] ? "Bootable " : "",
0518 adev->id[129], adev->id[146]);
0519 }
0520
0521
0522 adev->horkage &= ~ATA_HORKAGE_DIAGNOSTIC;
0523
0524 adev->horkage |= ATA_HORKAGE_BROKEN_HPA;
0525 }
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539 static unsigned int it821x_read_id(struct ata_device *adev,
0540 struct ata_taskfile *tf, __le16 *id)
0541 {
0542 unsigned int err_mask;
0543 unsigned char model_num[ATA_ID_PROD_LEN + 1];
0544
0545 err_mask = ata_do_dev_read_id(adev, tf, id);
0546 if (err_mask)
0547 return err_mask;
0548 ata_id_c_string((u16 *)id, model_num, ATA_ID_PROD, sizeof(model_num));
0549
0550 id[83] &= cpu_to_le16(~(1 << 12));
0551 id[84] &= cpu_to_le16(~(1 << 6));
0552 id[85] &= cpu_to_le16(~(1 << 10));
0553 id[76] = 0;
0554
0555 if (strstr(model_num, "Integrated Technology Express")) {
0556
0557 id[49] |= cpu_to_le16(0x0300);
0558 id[83] &= cpu_to_le16(0x7FFF);
0559 id[83] |= cpu_to_le16(0x4400);
0560 id[86] |= cpu_to_le16(0x0400);
0561 id[ATA_ID_MAJOR_VER] |= cpu_to_le16(0x1F);
0562
0563
0564 memset(&id[ATA_ID_SERNO], 0x20, ATA_ID_SERNO_LEN);
0565 }
0566 return err_mask;
0567 }
0568
0569
0570
0571
0572
0573
0574
0575
0576
0577 static int it821x_check_atapi_dma(struct ata_queued_cmd *qc)
0578 {
0579 struct ata_port *ap = qc->ap;
0580 struct it821x_dev *itdev = ap->private_data;
0581
0582
0583 if (ata_qc_raw_nbytes(qc) < 2048)
0584 return -EOPNOTSUPP;
0585
0586
0587 if (itdev->smart)
0588 return -EOPNOTSUPP;
0589
0590 if (itdev->timing10)
0591 return -EOPNOTSUPP;
0592
0593 return 0;
0594 }
0595
0596
0597
0598
0599
0600
0601
0602
0603
0604
0605
0606 static void it821x_display_disk(struct ata_port *ap, int n, u8 *buf)
0607 {
0608 unsigned char id[41];
0609 int mode = 0;
0610 const char *mtype = "";
0611 char mbuf[8];
0612 const char *cbl = "(40 wire cable)";
0613
0614 static const char *types[5] = {
0615 "RAID0", "RAID1", "RAID 0+1", "JBOD", "DISK"
0616 };
0617
0618 if (buf[52] > 4)
0619 return;
0620
0621 ata_id_c_string((u16 *)buf, id, 0, 41);
0622
0623 if (buf[51]) {
0624 mode = ffs(buf[51]);
0625 mtype = "UDMA";
0626 } else if (buf[49]) {
0627 mode = ffs(buf[49]);
0628 mtype = "MWDMA";
0629 }
0630
0631 if (buf[76])
0632 cbl = "";
0633
0634 if (mode)
0635 snprintf(mbuf, 8, "%5s%d", mtype, mode - 1);
0636 else
0637 strcpy(mbuf, "PIO");
0638 if (buf[52] == 4)
0639 ata_port_info(ap, "%d: %-6s %-8s %s %s\n",
0640 n, mbuf, types[buf[52]], id, cbl);
0641 else
0642 ata_port_info(ap, "%d: %-6s %-8s Volume: %1d %s %s\n",
0643 n, mbuf, types[buf[52]], buf[53], id, cbl);
0644 if (buf[125] < 100)
0645 ata_port_info(ap, "%d: Rebuilding: %d%%\n", n, buf[125]);
0646 }
0647
0648
0649
0650
0651
0652
0653
0654
0655
0656
0657
0658
0659 static u8 *it821x_firmware_command(struct ata_port *ap, u8 cmd, int len)
0660 {
0661 u8 status;
0662 int n = 0;
0663 u16 *buf = kmalloc(len, GFP_KERNEL);
0664
0665 if (!buf)
0666 return NULL;
0667
0668
0669
0670 ap->ctl |= ATA_NIEN;
0671 iowrite8(ap->ctl, ap->ioaddr.ctl_addr);
0672 ata_wait_idle(ap);
0673 iowrite8(ATA_DEVICE_OBS, ap->ioaddr.device_addr);
0674 iowrite8(cmd, ap->ioaddr.command_addr);
0675 udelay(1);
0676
0677
0678 while(n++ < 10) {
0679 status = ioread8(ap->ioaddr.status_addr);
0680 if (status & ATA_ERR) {
0681 kfree(buf);
0682 ata_port_err(ap, "%s: rejected\n", __func__);
0683 return NULL;
0684 }
0685 if (status & ATA_DRQ) {
0686 ioread16_rep(ap->ioaddr.data_addr, buf, len/2);
0687 return (u8 *)buf;
0688 }
0689 usleep_range(500, 1000);
0690 }
0691 kfree(buf);
0692 ata_port_err(ap, "%s: timeout\n", __func__);
0693 return NULL;
0694 }
0695
0696
0697
0698
0699
0700
0701
0702
0703
0704 static void it821x_probe_firmware(struct ata_port *ap)
0705 {
0706 u8 *buf;
0707 int i;
0708
0709
0710
0711
0712 buf = it821x_firmware_command(ap, 0xFA, 512);
0713
0714 if (buf != NULL) {
0715 ata_port_info(ap, "pata_it821x: Firmware %02X/%02X/%02X%02X\n",
0716 buf[505],
0717 buf[506],
0718 buf[507],
0719 buf[508]);
0720 for (i = 0; i < 4; i++)
0721 it821x_display_disk(ap, i, buf + 128 * i);
0722 kfree(buf);
0723 }
0724 }
0725
0726
0727
0728
0729
0730
0731
0732
0733
0734
0735
0736
0737
0738 static int it821x_port_start(struct ata_port *ap)
0739 {
0740 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
0741 struct it821x_dev *itdev;
0742 u8 conf;
0743
0744 int ret = ata_bmdma_port_start(ap);
0745 if (ret < 0)
0746 return ret;
0747
0748 itdev = devm_kzalloc(&pdev->dev, sizeof(struct it821x_dev), GFP_KERNEL);
0749 if (itdev == NULL)
0750 return -ENOMEM;
0751 ap->private_data = itdev;
0752
0753 pci_read_config_byte(pdev, 0x50, &conf);
0754
0755 if (conf & 1) {
0756 itdev->smart = 1;
0757
0758
0759
0760 if (ap->port_no == 0)
0761 it821x_probe_firmware(ap);
0762 }
0763
0764 if (conf & (1 << (1 + ap->port_no)))
0765 itdev->clock_mode = ATA_50;
0766 else
0767 itdev->clock_mode = ATA_66;
0768
0769 itdev->want[0][1] = ATA_ANY;
0770 itdev->want[1][1] = ATA_ANY;
0771 itdev->last_device = -1;
0772
0773 if (pdev->revision == 0x10) {
0774 itdev->timing10 = 1;
0775
0776 if (!itdev->smart)
0777 dev_warn(&pdev->dev,
0778 "Revision 0x10, workarounds activated.\n");
0779 }
0780
0781 return 0;
0782 }
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792 static int it821x_rdc_cable(struct ata_port *ap)
0793 {
0794 u16 r40;
0795 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
0796
0797 pci_read_config_word(pdev, 0x40, &r40);
0798 if (r40 & (1 << (2 + ap->port_no)))
0799 return ATA_CBL_PATA40;
0800 return ATA_CBL_PATA80;
0801 }
0802
0803 static struct scsi_host_template it821x_sht = {
0804 ATA_BMDMA_SHT(DRV_NAME),
0805 };
0806
0807 static struct ata_port_operations it821x_smart_port_ops = {
0808 .inherits = &ata_bmdma_port_ops,
0809
0810 .check_atapi_dma= it821x_check_atapi_dma,
0811 .qc_issue = it821x_smart_qc_issue,
0812
0813 .cable_detect = ata_cable_80wire,
0814 .set_mode = it821x_smart_set_mode,
0815 .dev_config = it821x_dev_config,
0816 .read_id = it821x_read_id,
0817
0818 .port_start = it821x_port_start,
0819 };
0820
0821 static struct ata_port_operations it821x_passthru_port_ops = {
0822 .inherits = &ata_bmdma_port_ops,
0823
0824 .check_atapi_dma= it821x_check_atapi_dma,
0825 .sff_dev_select = it821x_passthru_dev_select,
0826 .bmdma_start = it821x_passthru_bmdma_start,
0827 .bmdma_stop = it821x_passthru_bmdma_stop,
0828 .qc_issue = it821x_passthru_qc_issue,
0829
0830 .cable_detect = ata_cable_unknown,
0831 .set_piomode = it821x_passthru_set_piomode,
0832 .set_dmamode = it821x_passthru_set_dmamode,
0833
0834 .port_start = it821x_port_start,
0835 };
0836
0837 static struct ata_port_operations it821x_rdc_port_ops = {
0838 .inherits = &ata_bmdma_port_ops,
0839
0840 .check_atapi_dma= it821x_check_atapi_dma,
0841 .sff_dev_select = it821x_passthru_dev_select,
0842 .bmdma_start = it821x_passthru_bmdma_start,
0843 .bmdma_stop = it821x_passthru_bmdma_stop,
0844 .qc_issue = it821x_passthru_qc_issue,
0845
0846 .cable_detect = it821x_rdc_cable,
0847 .set_piomode = it821x_passthru_set_piomode,
0848 .set_dmamode = it821x_passthru_set_dmamode,
0849
0850 .port_start = it821x_port_start,
0851 };
0852
0853 static void it821x_disable_raid(struct pci_dev *pdev)
0854 {
0855
0856 if (pdev->vendor != PCI_VENDOR_ID_ITE ||
0857 pdev->device != PCI_DEVICE_ID_ITE_8212)
0858 return;
0859
0860
0861 pci_write_config_byte(pdev, 0x5E, 0x01);
0862
0863
0864 pci_write_config_byte(pdev, 0x50, 0x00);
0865 pci_write_config_word(pdev, PCI_COMMAND,
0866 PCI_COMMAND_PARITY | PCI_COMMAND_IO |
0867 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
0868 pci_write_config_word(pdev, 0x40, 0xA0F3);
0869
0870 pci_write_config_dword(pdev,0x4C, 0x02040204);
0871 pci_write_config_byte(pdev, 0x42, 0x36);
0872 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x20);
0873 }
0874
0875
0876 static int it821x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
0877 {
0878 u8 conf;
0879
0880 static const struct ata_port_info info_smart = {
0881 .flags = ATA_FLAG_SLAVE_POSS,
0882 .pio_mask = ATA_PIO4,
0883 .mwdma_mask = ATA_MWDMA2,
0884 .udma_mask = ATA_UDMA6,
0885 .port_ops = &it821x_smart_port_ops
0886 };
0887 static const struct ata_port_info info_passthru = {
0888 .flags = ATA_FLAG_SLAVE_POSS,
0889 .pio_mask = ATA_PIO4,
0890 .mwdma_mask = ATA_MWDMA2,
0891 .udma_mask = ATA_UDMA6,
0892 .port_ops = &it821x_passthru_port_ops
0893 };
0894 static const struct ata_port_info info_rdc = {
0895 .flags = ATA_FLAG_SLAVE_POSS,
0896 .pio_mask = ATA_PIO4,
0897 .mwdma_mask = ATA_MWDMA2,
0898 .udma_mask = ATA_UDMA6,
0899 .port_ops = &it821x_rdc_port_ops
0900 };
0901 static const struct ata_port_info info_rdc_11 = {
0902 .flags = ATA_FLAG_SLAVE_POSS,
0903 .pio_mask = ATA_PIO4,
0904 .mwdma_mask = ATA_MWDMA2,
0905
0906 .port_ops = &it821x_rdc_port_ops
0907 };
0908
0909 const struct ata_port_info *ppi[] = { NULL, NULL };
0910 static const char *mode[2] = { "pass through", "smart" };
0911 int rc;
0912
0913 rc = pcim_enable_device(pdev);
0914 if (rc)
0915 return rc;
0916
0917 if (pdev->vendor == PCI_VENDOR_ID_RDC) {
0918
0919 if (pdev->revision == 0x11)
0920 ppi[0] = &info_rdc_11;
0921 else
0922 ppi[0] = &info_rdc;
0923 } else {
0924
0925 if (it8212_noraid) {
0926 dev_info(&pdev->dev, "forcing bypass mode.\n");
0927 it821x_disable_raid(pdev);
0928 }
0929 pci_read_config_byte(pdev, 0x50, &conf);
0930 conf &= 1;
0931
0932 dev_info(&pdev->dev, "controller in %s mode.\n", mode[conf]);
0933
0934 if (conf == 0)
0935 ppi[0] = &info_passthru;
0936 else
0937 ppi[0] = &info_smart;
0938 }
0939 return ata_pci_bmdma_init_one(pdev, ppi, &it821x_sht, NULL, 0);
0940 }
0941
0942 #ifdef CONFIG_PM_SLEEP
0943 static int it821x_reinit_one(struct pci_dev *pdev)
0944 {
0945 struct ata_host *host = pci_get_drvdata(pdev);
0946 int rc;
0947
0948 rc = ata_pci_device_do_resume(pdev);
0949 if (rc)
0950 return rc;
0951
0952 if (it8212_noraid)
0953 it821x_disable_raid(pdev);
0954 ata_host_resume(host);
0955 return rc;
0956 }
0957 #endif
0958
0959 static const struct pci_device_id it821x[] = {
0960 { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8211), },
0961 { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8212), },
0962 { PCI_VDEVICE(RDC, PCI_DEVICE_ID_RDC_D1010), },
0963
0964 { },
0965 };
0966
0967 static struct pci_driver it821x_pci_driver = {
0968 .name = DRV_NAME,
0969 .id_table = it821x,
0970 .probe = it821x_init_one,
0971 .remove = ata_pci_remove_one,
0972 #ifdef CONFIG_PM_SLEEP
0973 .suspend = ata_pci_device_suspend,
0974 .resume = it821x_reinit_one,
0975 #endif
0976 };
0977
0978 module_pci_driver(it821x_pci_driver);
0979
0980 MODULE_AUTHOR("Alan Cox");
0981 MODULE_DESCRIPTION("low-level driver for the IT8211/IT8212 IDE RAID controller");
0982 MODULE_LICENSE("GPL");
0983 MODULE_DEVICE_TABLE(pci, it821x);
0984 MODULE_VERSION(DRV_VERSION);
0985
0986 module_param_named(noraid, it8212_noraid, int, S_IRUGO);
0987 MODULE_PARM_DESC(noraid, "Force card into bypass mode");