72 #include <linux/kernel.h>
73 #include <linux/module.h>
74 #include <linux/pci.h>
78 #include <linux/slab.h>
83 #define DRV_NAME "pata_it821x"
84 #define DRV_VERSION "0.4.2"
114 static int it8212_noraid;
138 conf = timing & 0xFF;
139 pci_write_config_byte(pdev, 0x54 + 4 * channel, conf);
167 conf = timing & 0xFF;
169 pci_write_config_byte(pdev, 0x56 + 4 * channel + unit, conf);
172 pci_write_config_byte(pdev, 0x56 + 4 * channel, conf);
173 pci_write_config_byte(pdev, 0x56 + 4 * channel + 1, conf);
198 if (itdev->
want[0][0] > itdev->
want[1][0]) {
199 clock = itdev->
want[0][1];
200 altclock = itdev->
want[1][1];
202 clock = itdev->
want[1][1];
203 altclock = itdev->
want[0][1];
224 pci_read_config_byte(pdev, 0x50, &v);
225 v &= ~(1 << (1 + ap->
port_no));
227 pci_write_config_byte(pdev, 0x50, v);
234 it821x_program_udma(ap, pair, itdev->
udma[1-unit]);
235 it821x_program(ap, pair, itdev->
pio[1-unit]);
242 it821x_program_udma(ap, adev, itdev->
udma[unit]);
243 it821x_program(ap, adev, itdev->
pio[unit]);
259 static const u16 pio[] = { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 };
263 int unit = adev->
devno;
267 itdev->
want[
unit][1] = pio_want[mode_wanted];
269 itdev->
pio[
unit] = pio[mode_wanted];
270 it821x_clock_strategy(ap, adev);
271 it821x_program(ap, adev, itdev->
pio[unit]);
288 static const u16 dma[] = { 0x8866, 0x3222, 0x3121 };
290 static const u16 udma[] = { 0x4433, 0x4231, 0x3121, 0x2121, 0x1111, 0x2211, 0x1111 };
296 int unit = adev->
devno;
302 itdev->
want[
unit][1] = udma_want[mode_wanted];
305 itdev->
udma[
unit] = udma[mode_wanted];
306 if (mode_wanted >= 5)
310 pci_read_config_byte(pdev, 0x50, &conf);
312 conf &= channel ? 0x9F: 0xE7;
314 conf &= ~ (1 << (3 + 2 * channel +
unit));
315 pci_write_config_byte(pdev, 0x50, conf);
316 it821x_clock_strategy(ap, adev);
317 it821x_program_udma(ap, adev, itdev->
udma[unit]);
321 itdev->
want[
unit][1] = mwdma_want[mode_wanted];
327 pci_read_config_byte(pdev, 0x50, &conf);
329 conf |= channel ? 0x60: 0x18;
331 conf |= 1 << (3 + 2 * channel +
unit);
332 pci_write_config_byte(pdev, 0x50, conf);
333 it821x_clock_strategy(ap, adev);
346 static void it821x_passthru_bmdma_start(
struct ata_queued_cmd *qc)
351 int unit = adev->
devno;
354 it821x_program(ap, adev, itdev->
mwdma[unit]);
356 it821x_program_udma(ap, adev, itdev->
udma[unit]);
374 int unit = adev->
devno;
378 it821x_program(ap, adev, itdev->
pio[unit]);
390 static void it821x_passthru_dev_select(
struct ata_port *ap,
396 it821x_program(ap, adev, itdev->
pio[adev->
devno]);
411 static unsigned int it821x_smart_qc_issue(
struct ata_queued_cmd *qc)
413 switch(qc->
tf.command)
433 return ata_bmdma_qc_issue(qc);
448 static unsigned int it821x_passthru_qc_issue(
struct ata_queued_cmd *qc)
450 it821x_passthru_dev_select(qc->
ap, qc->
dev->devno);
451 return ata_bmdma_qc_issue(qc);
500 static void it821x_dev_config(
struct ata_device *adev)
509 if (
strstr(model_num,
"Integrated Technology Express")) {
512 adev->
id[147] ?
"Bootable " :
"",
514 if (adev->
id[129] != 1)
537 static unsigned int it821x_read_id(
struct ata_device *adev,
540 unsigned int err_mask;
548 id[83] &= ~(1 << 12);
549 id[83] &= ~(1 << 13);
551 id[85] &= ~(1 << 10);
554 if (
strstr(model_num,
"Integrated Technology Express")) {
582 if (ata_qc_raw_nbytes(qc) < 2048)
604 static void it821x_display_disk(
int n,
u8 *
buf)
606 unsigned char id[41];
610 char *cbl =
"(40 wire cable)";
612 static const char *types[5] = {
613 "RAID0",
"RAID1",
"RAID 0+1",
"JBOD",
"DISK"
624 }
else if (buf[49]) {
633 snprintf(mbuf, 8,
"%5s%d", mtype, mode - 1);
638 n, mbuf, types[buf[52]],
id, cbl);
641 n, mbuf, types[buf[52]], buf[53],
id, cbl);
657 static u8 *it821x_firmware_command(
struct ata_port *ap,
u8 cmd,
int len)
669 iowrite8(ap->ctl, ap->ioaddr.ctl_addr);
672 iowrite8(cmd, ap->ioaddr.command_addr);
677 status =
ioread8(ap->ioaddr.status_addr);
702 static void it821x_probe_firmware(
struct ata_port *ap)
710 buf = it821x_firmware_command(ap, 0xFA, 512);
718 for (i = 0; i < 4; i++)
719 it821x_display_disk(i, buf + 128 * i);
736 static int it821x_port_start(
struct ata_port *ap)
742 int ret = ata_bmdma_port_start(ap);
751 pci_read_config_byte(pdev, 0x50, &conf);
759 it821x_probe_firmware(ap);
762 if (conf & (1 << (1 + ap->
port_no)))
789 static int it821x_rdc_cable(
struct ata_port *ap)
794 pci_read_config_word(pdev, 0x40, &r40);
795 if (r40 & (1 << (2 + ap->
port_no)))
805 .inherits = &ata_bmdma_port_ops,
807 .check_atapi_dma= it821x_check_atapi_dma,
808 .qc_issue = it821x_smart_qc_issue,
811 .set_mode = it821x_smart_set_mode,
812 .dev_config = it821x_dev_config,
813 .read_id = it821x_read_id,
815 .port_start = it821x_port_start,
819 .inherits = &ata_bmdma_port_ops,
821 .check_atapi_dma= it821x_check_atapi_dma,
822 .sff_dev_select = it821x_passthru_dev_select,
823 .bmdma_start = it821x_passthru_bmdma_start,
824 .bmdma_stop = it821x_passthru_bmdma_stop,
825 .qc_issue = it821x_passthru_qc_issue,
828 .set_piomode = it821x_passthru_set_piomode,
829 .set_dmamode = it821x_passthru_set_dmamode,
831 .port_start = it821x_port_start,
835 .inherits = &ata_bmdma_port_ops,
837 .check_atapi_dma= it821x_check_atapi_dma,
838 .sff_dev_select = it821x_passthru_dev_select,
839 .bmdma_start = it821x_passthru_bmdma_start,
840 .bmdma_stop = it821x_passthru_bmdma_stop,
841 .qc_issue = it821x_passthru_qc_issue,
843 .cable_detect = it821x_rdc_cable,
844 .set_piomode = it821x_passthru_set_piomode,
845 .set_dmamode = it821x_passthru_set_dmamode,
847 .port_start = it821x_port_start,
850 static void it821x_disable_raid(
struct pci_dev *pdev)
858 pci_write_config_byte(pdev, 0x5E, 0x01);
861 pci_write_config_byte(pdev, 0x50, 0x00);
865 pci_write_config_word(pdev, 0x40, 0xA0F3);
867 pci_write_config_dword(pdev,0x4C, 0x02040204);
868 pci_write_config_byte(pdev, 0x42, 0x36);
882 .port_ops = &it821x_smart_port_ops
889 .port_ops = &it821x_passthru_port_ops
896 .port_ops = &it821x_rdc_port_ops
903 .port_ops = &it821x_rdc_port_ops
907 static char *mode[2] = {
"pass through",
"smart" };
917 ppi[0] = &info_rdc_11;
924 it821x_disable_raid(pdev);
926 pci_read_config_byte(pdev, 0x50, &conf);
932 ppi[0] = &info_passthru;
934 ppi[0] = &info_smart;
936 return ata_pci_bmdma_init_one(pdev, ppi, &it821x_sht,
NULL, 0);
940 static int it821x_reinit_one(
struct pci_dev *pdev)
945 rc = ata_pci_device_do_resume(pdev);
950 it821x_disable_raid(pdev);
951 ata_host_resume(host);
964 static struct pci_driver it821x_pci_driver = {
967 .probe = it821x_init_one,
968 .remove = ata_pci_remove_one,
970 .suspend = ata_pci_device_suspend,
971 .resume = it821x_reinit_one,