62 #include <linux/kernel.h>
63 #include <linux/module.h>
64 #include <linux/pci.h>
73 #define DRV_NAME "pata_legacy"
74 #define DRV_VERSION "0.6.5"
80 MODULE_PARM_DESC(all,
"Grab all legacy port devices, even if PCI(0=off, 1=on)");
113 unsigned long private;
126 static int legacy_port[
NR_HOST] = { 0x1f0, 0x170, 0x1e8, 0x168, 0x1e0, 0x160 };
131 static int nr_legacy_host;
134 static int probe_all;
137 static int opti82c611a;
138 static int opti82c46x;
139 static int autospeed;
141 static int iordy_mask = 0xFFFFFFFF;
144 #ifdef CONFIG_PATA_QDI_MODULE
150 #ifdef CONFIG_PATA_WINBOND_VLB_MODULE
151 static int winbond = 1;
173 static int legacy_probe_add(
unsigned long port,
unsigned int irq,
180 for (i = 0; i <
NR_HOST; i++) {
184 if (lp->
port == port || legacy_port[i] == port) {
248 .inherits = &legacy_base_port_ops,
253 .inherits = &legacy_base_port_ops,
255 .set_mode = legacy_set_mode,
281 outb(
inb(0x1F2) | 0x80, 0x1F2);
288 while ((
inb(0x1F2) & 0x80) && --tries);
292 outb(
inb(0x1F4) & 0x07, 0x1F4);
295 rt &= 0x07 << (3 * adev->
devno);
297 rt |= (1 + 3 *
pio) << (3 * adev->
devno);
300 outb(
inb(0x1F2) | 0x01, 0x1F2);
306 static unsigned int pdc_data_xfer_vlb(
struct ata_device *
dev,
309 int slop = buflen & 3;
313 if (ata_id_has_dword_io(dev->
id) && (slop == 0 || slop == 3)
320 ioread8(ap->ioaddr.nsect_addr);
321 ioread8(ap->ioaddr.nsect_addr);
322 ioread8(ap->ioaddr.nsect_addr);
334 memcpy(buf + buflen - slop, &pad, slop);
336 memcpy(&pad, buf + buflen - slop, slop);
349 .inherits = &legacy_base_port_ops,
351 .sff_data_xfer = pdc_data_xfer_vlb,
377 iowrite8(recover << 4 | active, ap->ioaddr.device_addr);
378 ioread8(ap->ioaddr.status_addr);
382 .inherits = &legacy_base_port_ops,
411 iowrite8(recover << 4 | active, ap->ioaddr.device_addr);
414 u8 rconf =
inb(0x3E6);
420 ioread8(ap->ioaddr.status_addr);
424 .inherits = &legacy_base_port_ops,
458 static void opti82c611a_set_piomode(
struct ata_port *ap,
465 int khz[4] = { 50000, 40000, 33000, 25000 };
474 clock = 1000000000 / khz[
ioread8(ap->ioaddr.lbah_addr) & 0x03];
492 rc =
ioread8(ap->ioaddr.lbal_addr);
494 rc |= (adev->
devno << 7);
498 iowrite8(active << 4 | recover, ap->ioaddr.error_addr);
502 rc =
ioread8(ap->ioaddr.device_addr);
505 rc |= (setup << 4) | 0x04;
506 iowrite8(rc, ap->ioaddr.device_addr);
509 iowrite8(active << 4 | recover, ap->ioaddr.data_addr);
512 rc =
ioread8(ap->ioaddr.lbal_addr);
518 iowrite8(0x83, ap->ioaddr.nsect_addr);
523 .inherits = &legacy_base_port_ops,
540 int khz[4] = { 50000, 40000, 33000, 25000 };
545 sysclk = opti_syscfg(0xAC) & 0xC0;
553 clock = 1000000000 / khz[sysclk];
571 rc =
ioread8(ap->ioaddr.lbal_addr);
573 rc |= (adev->
devno << 7);
577 iowrite8(active << 4 | recover, ap->ioaddr.error_addr);
581 rc =
ioread8(ap->ioaddr.device_addr);
584 rc |= (setup << 4) | 0x04;
585 iowrite8(rc, ap->ioaddr.device_addr);
588 iowrite8(active << 4 | recover, ap->ioaddr.data_addr);
591 rc =
ioread8(ap->ioaddr.lbal_addr);
597 iowrite8(0x83, ap->ioaddr.nsect_addr);
600 ap->
host->private_data = ap;
618 static unsigned int opti82c46x_qc_issue(
struct ata_queued_cmd *qc)
625 if (ap->
host->private_data != ap->
host
627 opti82c46x_set_piomode(ap, adev);
633 .inherits = &legacy_base_port_ops,
635 .qc_issue = opti82c46x_qc_issue,
668 timing = (recovery << 4) | active | 0x08;
705 static unsigned int vlb32_data_xfer(
struct ata_device *adev,
unsigned char *buf,
706 unsigned int buflen,
int rw)
709 int slop = buflen & 3;
711 if (ata_id_has_dword_io(adev->
id) && (slop == 0 || slop == 3)
721 memcpy(&pad, buf + buflen - slop, slop);
725 memcpy(buf + buflen - slop, &pad, slop);
728 return (buflen + 3) & ~3;
743 .inherits = &legacy_base_port_ops,
745 .qc_issue = qdi_qc_issue,
746 .sff_data_xfer = vlb32_data_xfer,
750 .inherits = &legacy_base_port_ops,
752 .sff_data_xfer = vlb32_data_xfer,
756 .inherits = &legacy_base_port_ops,
758 .qc_issue = qdi_qc_issue,
759 .sff_data_xfer = vlb32_data_xfer,
764 static void winbond_writecfg(
unsigned long port,
u8 reg,
u8 val)
768 outb(reg, port + 0x01);
769 outb(val, port + 0x02);
770 spin_unlock_irqrestore(&winbond_lock, flags);
773 static u8 winbond_readcfg(
unsigned long port,
u8 reg)
779 outb(reg, port + 0x01);
780 val =
inb(port + 0x02);
781 spin_unlock_irqrestore(&winbond_lock, flags);
792 int timing = 0x88 + (ap->
port_no * 4) + (adev->
devno * 2);
794 reg = winbond_readcfg(ld_winbond->
timing, 0x81);
802 active = (
clamp_val(
t.active, 3, 17) - 1) & 0x0F;
803 recovery = (
clamp_val(
t.recover, 1, 15) + 1) & 0x0F;
804 timing = (active << 4) | recovery;
805 winbond_writecfg(ld_winbond->
timing, timing, reg);
815 winbond_writecfg(ld_winbond->
timing, timing + 1, reg);
828 .inherits = &legacy_base_port_ops,
830 .sff_data_xfer = vlb32_data_xfer,
834 {
"BIOS", &legacy_port_ops,
ATA_PIO4,
836 {
"Snooping", &simple_port_ops,
ATA_PIO4,
838 {
"PDC20230", &pdc20230_port_ops,
ATA_PIO2,
841 {
"HT6560A", &ht6560a_port_ops,
ATA_PIO2,
843 {
"HT6560B", &ht6560b_port_ops,
ATA_PIO4,
845 {
"OPTI82C611A", &opti82c611a_port_ops,
ATA_PIO3,
847 {
"OPTI82C46X", &opti82c46x_port_ops,
ATA_PIO3,
849 {
"QDI6500", &qdi6500_port_ops,
ATA_PIO2,
852 {
"QDI6580", &qdi6580_port_ops,
ATA_PIO4,
854 {
"QDI6580DP", &qdi6580dp_port_ops,
ATA_PIO4,
856 {
"W83759A", &winbond_port_ops,
ATA_PIO4,
873 if (winbond && (probe->
port == 0x1F0 || probe->
port == 0x170)) {
874 u8 reg = winbond_readcfg(winbond, 0x81);
876 winbond_writecfg(winbond, 0x81, reg);
877 reg = winbond_readcfg(winbond, 0x83);
879 winbond_writecfg(winbond, 0x83, reg);
880 reg = winbond_readcfg(winbond, 0x85);
882 winbond_writecfg(winbond, 0x85, reg);
884 reg = winbond_readcfg(winbond, 0x81);
889 if (probe->
port == 0x1F0) {
893 outb(
inb(0x1F2) | 0x80, 0x1F2);
901 if ((
inb(0x1F2) & 0x80) == 0) {
913 if (
inb(0x1F2) == 0x00)
915 "controller detected.\n");
926 if (opti82c611a & mask)
928 if (opti82c46x & mask)
930 if (autospeed & mask)
947 int pio_modes = controller->
pio_mask;
948 unsigned long io = probe->
port;
960 iordy |= controller->
flags;
964 return PTR_ERR(pdev);
969 "pata_legacy") ==
NULL)
973 io_addr = devm_ioport_map(&pdev->
dev, io, 8);
974 ctrl_addr = devm_ioport_map(&pdev->
dev, io + 0x0206, 1);
975 if (!io_addr || !ctrl_addr)
978 if (controller->
setup)
979 if (controller->
setup(pdev, probe, ld) < 0)
991 ap->ioaddr.altstatus_addr = ctrl_addr;
992 ap->ioaddr.ctl_addr = ctrl_addr;
994 ap->
host->private_data =
ld;
1009 if (!ata_dev_absent(dev)) {
1010 legacy_host[probe->
slot] = host;
1039 *primary = *secondary = 1;
1044 *primary = *secondary = 1;
1050 pci_read_config_word(p, 0x6C, &r);
1062 static __init void probe_opti_vlb(
void)
1065 static const char *optis[4] = {
1070 u8 ctrl = (opti_syscfg(0x30) & 0xC0) >> 6;
1076 chans = (opti_syscfg(0x3F) & 0x20) ? 2 : 1;
1077 ctrl = opti_syscfg(0xAC);
1082 legacy_probe_add(0x1F0, 14,
OPTI46X, 0);
1083 legacy_probe_add(0x170, 15,
OPTI46X, 0);
1086 legacy_probe_add(0x170, 15,
OPTI46X, 0);
1088 legacy_probe_add(0x1F0, 14,
OPTI46X, 0);
1090 legacy_probe_add(0x1F0, 14,
OPTI46X, 0);
1093 static __init void qdi65_identify_port(
u8 r,
u8 res,
unsigned long port)
1095 static const unsigned long ide_port[2] = { 0x170, 0x1F0 };
1097 if ((r & 0xF0) == 0xC0) {
1102 legacy_probe_add(ide_port[r & 0x01], 14 + (r & 0x01),
1105 if (((r & 0xF0) == 0xA0) || (r & 0xF0) == 0x50) {
1111 res =
inb(port + 3);
1114 legacy_probe_add(ide_port[r & 0x01], 14 + (r & 0x01),
1117 legacy_probe_add(0x1F0, 14,
QDI6580DP, port);
1119 legacy_probe_add(0x170, 15,
QDI6580DP, port + 2);
1125 static __init void probe_qdi_vlb(
void)
1127 unsigned long flags;
1128 static const unsigned long qd_port[2] = { 0x30, 0xB0 };
1135 for (i = 0; i < 2; i++) {
1136 unsigned long port = qd_port[
i];
1164 if ((r & 2) >> 1 == i)
1165 qdi65_identify_port(r, res, port);
1181 static __init int legacy_init(
void)
1187 int pci_present = 0;
1198 for (r = 0; r < 6; r++) {
1205 legacy_check_special_cases(p, &primary, &secondary);
1215 if (primary == 0 || all)
1216 legacy_probe_add(0x1F0, 14,
UNKNOWN, 0);
1217 if (secondary == 0 || all)
1218 legacy_probe_add(0x170, 15,
UNKNOWN, 0);
1220 if (probe_all || !pci_present) {
1222 legacy_probe_add(0x1E8, 11,
UNKNOWN, 0);
1223 legacy_probe_add(0x168, 10,
UNKNOWN, 0);
1224 legacy_probe_add(0x1E0, 8,
UNKNOWN, 0);
1225 legacy_probe_add(0x160, 12,
UNKNOWN, 0);
1233 for (i = 0; i <
NR_HOST; i++, pl++) {
1237 pl->
type = probe_chip_type(pl);
1239 if (legacy_init_one(pl) == 0)
1247 static __exit void legacy_exit(
void)
1251 for (i = 0; i < nr_legacy_host; i++) {