aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-02-02 13:56:31 -0500
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-02-02 13:56:31 -0500
commitbfa14b42a3bd671f0287b3db42e703e86ef27b48 (patch)
treead902a99aa59232832d8e663be8d86a615e24114 /drivers
parentc413b9b94d9a8e7548cc4b2e04b7df0439ce76fd (diff)
ide: add ->cable_detect method to ide_hwif_t
* Add ->cable_detect method to ide_hwif_t. * Call the new method in ide_init_port() if: - the host supports UDMA modes > UDMA2 ('hwif->ultra_mask & 78') - DMA initialization was successful (if hwif->dma_base is not set ide_init_port() sets hwif->ultra_mask to zero) - "idex=ata66" is not used ('hwif->cbl != ATA_CBL_PATA40_SHORT') * Convert PCI host drivers to use ->cable_detect method. While at it: * Factor out cable detection to separate functions (if not already done). * hpt366.c/it8213.c/slc90e66.c: - don't check cable type if "idex=ata66" is used * pdc202xx_new.c: - add __devinit tag to pdcnew_cable_detect() * pdc202xx_old.c: - rename pdc202xx_old_cable_detect() to pdc2026x_old_cable_detect() - add __devinit tag to pdc2026x_old_cable_detect() Reviewed-by: Sergei Shtylyov <sshtylyov@ru.mvista.com> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ide/ide-probe.c5
-rw-r--r--drivers/ide/pci/aec62xx.c25
-rw-r--r--drivers/ide/pci/alim15x3.c5
-rw-r--r--drivers/ide/pci/amd74xx.c18
-rw-r--r--drivers/ide/pci/atiixp.c6
-rw-r--r--drivers/ide/pci/cmd64x.c5
-rw-r--r--drivers/ide/pci/cs5535.c6
-rw-r--r--drivers/ide/pci/hpt366.c84
-rw-r--r--drivers/ide/pci/it8213.c21
-rw-r--r--drivers/ide/pci/it821x.c5
-rw-r--r--drivers/ide/pci/jmicron.c6
-rw-r--r--drivers/ide/pci/pdc202xx_new.c8
-rw-r--r--drivers/ide/pci/pdc202xx_old.c10
-rw-r--r--drivers/ide/pci/piix.c7
-rw-r--r--drivers/ide/pci/scc_pata.c3
-rw-r--r--drivers/ide/pci/serverworks.c9
-rw-r--r--drivers/ide/pci/siimage.c5
-rw-r--r--drivers/ide/pci/sis5513.c5
-rw-r--r--drivers/ide/pci/slc90e66.c22
-rw-r--r--drivers/ide/pci/tc86c001.c24
-rw-r--r--drivers/ide/pci/via82cxxx.c6
21 files changed, 135 insertions, 150 deletions
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 4c3d2cf3be5b..c25df65b51f8 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -1343,6 +1343,11 @@ static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
1343 /* call chipset specific routine for each enabled port */ 1343 /* call chipset specific routine for each enabled port */
1344 if (d->init_hwif) 1344 if (d->init_hwif)
1345 d->init_hwif(hwif); 1345 d->init_hwif(hwif);
1346
1347 if (hwif->cable_detect && (hwif->ultra_mask & 0x78)) {
1348 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
1349 hwif->cbl = hwif->cable_detect(hwif);
1350 }
1346} 1351}
1347 1352
1348int ide_device_add_all(u8 *idx, const struct ide_port_info *d) 1353int ide_device_add_all(u8 *idx, const struct ide_port_info *d)
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index 824df78c7012..ca302fcba3ab 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -166,6 +166,16 @@ static unsigned int __devinit init_chipset_aec62xx(struct pci_dev *dev, const ch
166 return dev->irq; 166 return dev->irq;
167} 167}
168 168
169static u8 __devinit atp86x_cable_detect(ide_hwif_t *hwif)
170{
171 struct pci_dev *dev = to_pci_dev(hwif->dev);
172 u8 ata66 = 0, mask = hwif->channel ? 0x02 : 0x01;
173
174 pci_read_config_byte(dev, 0x49, &ata66);
175
176 return (ata66 & mask) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
177}
178
169static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif) 179static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif)
170{ 180{
171 struct pci_dev *dev = to_pci_dev(hwif->dev); 181 struct pci_dev *dev = to_pci_dev(hwif->dev);
@@ -174,21 +184,10 @@ static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif)
174 184
175 if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) 185 if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF)
176 hwif->set_dma_mode = &aec6210_set_mode; 186 hwif->set_dma_mode = &aec6210_set_mode;
177 else 187 else {
178 hwif->set_dma_mode = &aec6260_set_mode; 188 hwif->set_dma_mode = &aec6260_set_mode;
179 189
180 if (hwif->dma_base == 0) 190 hwif->cable_detect = atp86x_cable_detect;
181 return;
182
183 if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF)
184 return;
185
186 if (hwif->cbl != ATA_CBL_PATA40_SHORT) {
187 u8 ata66 = 0, mask = hwif->channel ? 0x02 : 0x01;
188
189 pci_read_config_byte(dev, 0x49, &ata66);
190
191 hwif->cbl = (ata66 & mask) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
192 } 191 }
193} 192}
194 193
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index 130cc6e784e5..91db990ab756 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -666,13 +666,12 @@ static void __devinit init_hwif_common_ali15x3 (ide_hwif_t *hwif)
666 hwif->set_dma_mode = &ali_set_dma_mode; 666 hwif->set_dma_mode = &ali_set_dma_mode;
667 hwif->udma_filter = &ali_udma_filter; 667 hwif->udma_filter = &ali_udma_filter;
668 668
669 hwif->cable_detect = ata66_ali15x3;
670
669 if (hwif->dma_base == 0) 671 if (hwif->dma_base == 0)
670 return; 672 return;
671 673
672 hwif->dma_setup = &ali15x3_dma_setup; 674 hwif->dma_setup = &ali15x3_dma_setup;
673
674 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
675 hwif->cbl = ata66_ali15x3(hwif);
676} 675}
677 676
678/** 677/**
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index 8c52bc9eaa59..d6d58d217142 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -199,6 +199,14 @@ static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev,
199 return dev->irq; 199 return dev->irq;
200} 200}
201 201
202static u8 __devinit amd_cable_detect(ide_hwif_t *hwif)
203{
204 if ((amd_80w >> hwif->channel) & 1)
205 return ATA_CBL_PATA80;
206 else
207 return ATA_CBL_PATA40;
208}
209
202static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif) 210static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
203{ 211{
204 struct pci_dev *dev = to_pci_dev(hwif->dev); 212 struct pci_dev *dev = to_pci_dev(hwif->dev);
@@ -209,15 +217,7 @@ static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
209 hwif->set_pio_mode = &amd_set_pio_mode; 217 hwif->set_pio_mode = &amd_set_pio_mode;
210 hwif->set_dma_mode = &amd_set_drive; 218 hwif->set_dma_mode = &amd_set_drive;
211 219
212 if (!hwif->dma_base) 220 hwif->cable_detect = amd_cable_detect;
213 return;
214
215 if (hwif->cbl != ATA_CBL_PATA40_SHORT) {
216 if ((amd_80w >> hwif->channel) & 1)
217 hwif->cbl = ATA_CBL_PATA80;
218 else
219 hwif->cbl = ATA_CBL_PATA40;
220 }
221} 221}
222 222
223#define IDE_HFLAGS_AMD \ 223#define IDE_HFLAGS_AMD \
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index 648fdf30cdf4..b84185b4b68f 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -147,11 +147,7 @@ static void __devinit init_hwif_atiixp(ide_hwif_t *hwif)
147 hwif->set_pio_mode = &atiixp_set_pio_mode; 147 hwif->set_pio_mode = &atiixp_set_pio_mode;
148 hwif->set_dma_mode = &atiixp_set_dma_mode; 148 hwif->set_dma_mode = &atiixp_set_dma_mode;
149 149
150 if (!hwif->dma_base) 150 hwif->cable_detect = atiixp_cable_detect;
151 return;
152
153 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
154 hwif->cbl = atiixp_cable_detect(hwif);
155} 151}
156 152
157static const struct ide_port_info atiixp_pci_info[] __devinitdata = { 153static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index 04aa9e59670e..181506340d98 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -393,6 +393,8 @@ static void __devinit init_hwif_cmd64x(ide_hwif_t *hwif)
393 hwif->set_pio_mode = &cmd64x_set_pio_mode; 393 hwif->set_pio_mode = &cmd64x_set_pio_mode;
394 hwif->set_dma_mode = &cmd64x_set_dma_mode; 394 hwif->set_dma_mode = &cmd64x_set_dma_mode;
395 395
396 hwif->cable_detect = ata66_cmd64x;
397
396 if (!hwif->dma_base) 398 if (!hwif->dma_base)
397 return; 399 return;
398 400
@@ -411,9 +413,6 @@ static void __devinit init_hwif_cmd64x(ide_hwif_t *hwif)
411 if (dev->device == PCI_DEVICE_ID_CMD_646 && dev->revision < 5) 413 if (dev->device == PCI_DEVICE_ID_CMD_646 && dev->revision < 5)
412 hwif->ultra_mask = 0x00; 414 hwif->ultra_mask = 0x00;
413 415
414 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
415 hwif->cbl = ata66_cmd64x(hwif);
416
417 switch (dev->device) { 416 switch (dev->device) {
418 case PCI_DEVICE_ID_CMD_648: 417 case PCI_DEVICE_ID_CMD_648:
419 case PCI_DEVICE_ID_CMD_649: 418 case PCI_DEVICE_ID_CMD_649:
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c
index 50046436a565..d7b5ea992e94 100644
--- a/drivers/ide/pci/cs5535.c
+++ b/drivers/ide/pci/cs5535.c
@@ -179,11 +179,7 @@ static void __devinit init_hwif_cs5535(ide_hwif_t *hwif)
179 hwif->set_pio_mode = &cs5535_set_pio_mode; 179 hwif->set_pio_mode = &cs5535_set_pio_mode;
180 hwif->set_dma_mode = &cs5535_set_dma_mode; 180 hwif->set_dma_mode = &cs5535_set_dma_mode;
181 181
182 if (hwif->dma_base == 0) 182 hwif->cable_detect = cs5535_cable_detect;
183 return;
184
185 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
186 hwif->cbl = cs5535_cable_detect(hwif);
187} 183}
188 184
189static const struct ide_port_info cs5535_chipset __devinitdata = { 185static const struct ide_port_info cs5535_chipset __devinitdata = {
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index 5623cad569da..7a8c8c7a8b96 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -1279,12 +1279,55 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1279 return dev->irq; 1279 return dev->irq;
1280} 1280}
1281 1281
1282static u8 __devinit hpt3xx_cable_detect(ide_hwif_t *hwif)
1283{
1284 struct pci_dev *dev = to_pci_dev(hwif->dev);
1285 struct hpt_info *info = pci_get_drvdata(dev);
1286 u8 chip_type = info->chip_type;
1287 u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02;
1288
1289 /*
1290 * The HPT37x uses the CBLID pins as outputs for MA15/MA16
1291 * address lines to access an external EEPROM. To read valid
1292 * cable detect state the pins must be enabled as inputs.
1293 */
1294 if (chip_type == HPT374 && (PCI_FUNC(dev->devfn) & 1)) {
1295 /*
1296 * HPT374 PCI function 1
1297 * - set bit 15 of reg 0x52 to enable TCBLID as input
1298 * - set bit 15 of reg 0x56 to enable FCBLID as input
1299 */
1300 u8 mcr_addr = hwif->select_data + 2;
1301 u16 mcr;
1302
1303 pci_read_config_word(dev, mcr_addr, &mcr);
1304 pci_write_config_word(dev, mcr_addr, (mcr | 0x8000));
1305 /* now read cable id register */
1306 pci_read_config_byte(dev, 0x5a, &scr1);
1307 pci_write_config_word(dev, mcr_addr, mcr);
1308 } else if (chip_type >= HPT370) {
1309 /*
1310 * HPT370/372 and 374 pcifn 0
1311 * - clear bit 0 of reg 0x5b to enable P/SCBLID as inputs
1312 */
1313 u8 scr2 = 0;
1314
1315 pci_read_config_byte(dev, 0x5b, &scr2);
1316 pci_write_config_byte(dev, 0x5b, (scr2 & ~1));
1317 /* now read cable id register */
1318 pci_read_config_byte(dev, 0x5a, &scr1);
1319 pci_write_config_byte(dev, 0x5b, scr2);
1320 } else
1321 pci_read_config_byte(dev, 0x5a, &scr1);
1322
1323 return (scr1 & ata66) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
1324}
1325
1282static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) 1326static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1283{ 1327{
1284 struct pci_dev *dev = to_pci_dev(hwif->dev); 1328 struct pci_dev *dev = to_pci_dev(hwif->dev);
1285 struct hpt_info *info = pci_get_drvdata(dev); 1329 struct hpt_info *info = pci_get_drvdata(dev);
1286 int serialize = HPT_SERIALIZE_IO; 1330 int serialize = HPT_SERIALIZE_IO;
1287 u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02;
1288 u8 chip_type = info->chip_type; 1331 u8 chip_type = info->chip_type;
1289 u8 new_mcr, old_mcr = 0; 1332 u8 new_mcr, old_mcr = 0;
1290 1333
@@ -1301,6 +1344,8 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1301 hwif->udma_filter = &hpt3xx_udma_filter; 1344 hwif->udma_filter = &hpt3xx_udma_filter;
1302 hwif->mdma_filter = &hpt3xx_mdma_filter; 1345 hwif->mdma_filter = &hpt3xx_mdma_filter;
1303 1346
1347 hwif->cable_detect = hpt3xx_cable_detect;
1348
1304 /* 1349 /*
1305 * HPT3xxN chips have some complications: 1350 * HPT3xxN chips have some complications:
1306 * 1351 *
@@ -1346,43 +1391,6 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1346 if (hwif->dma_base == 0) 1391 if (hwif->dma_base == 0)
1347 return; 1392 return;
1348 1393
1349 /*
1350 * The HPT37x uses the CBLID pins as outputs for MA15/MA16
1351 * address lines to access an external EEPROM. To read valid
1352 * cable detect state the pins must be enabled as inputs.
1353 */
1354 if (chip_type == HPT374 && (PCI_FUNC(dev->devfn) & 1)) {
1355 /*
1356 * HPT374 PCI function 1
1357 * - set bit 15 of reg 0x52 to enable TCBLID as input
1358 * - set bit 15 of reg 0x56 to enable FCBLID as input
1359 */
1360 u8 mcr_addr = hwif->select_data + 2;
1361 u16 mcr;
1362
1363 pci_read_config_word (dev, mcr_addr, &mcr);
1364 pci_write_config_word(dev, mcr_addr, (mcr | 0x8000));
1365 /* now read cable id register */
1366 pci_read_config_byte (dev, 0x5a, &scr1);
1367 pci_write_config_word(dev, mcr_addr, mcr);
1368 } else if (chip_type >= HPT370) {
1369 /*
1370 * HPT370/372 and 374 pcifn 0
1371 * - clear bit 0 of reg 0x5b to enable P/SCBLID as inputs
1372 */
1373 u8 scr2 = 0;
1374
1375 pci_read_config_byte (dev, 0x5b, &scr2);
1376 pci_write_config_byte(dev, 0x5b, (scr2 & ~1));
1377 /* now read cable id register */
1378 pci_read_config_byte (dev, 0x5a, &scr1);
1379 pci_write_config_byte(dev, 0x5b, scr2);
1380 } else
1381 pci_read_config_byte (dev, 0x5a, &scr1);
1382
1383 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
1384 hwif->cbl = (scr1 & ata66) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
1385
1386 if (chip_type >= HPT374) { 1394 if (chip_type >= HPT374) {
1387 hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq; 1395 hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq;
1388 hwif->ide_dma_end = &hpt374_ide_dma_end; 1396 hwif->ide_dma_end = &hpt374_ide_dma_end;
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/pci/it8213.c
index df74e588a530..c781ea6502d6 100644
--- a/drivers/ide/pci/it8213.c
+++ b/drivers/ide/pci/it8213.c
@@ -143,6 +143,16 @@ static void it8213_set_dma_mode(ide_drive_t *drive, const u8 speed)
143 } 143 }
144} 144}
145 145
146static u8 __devinit it8213_cable_detect(ide_hwif_t *hwif)
147{
148 struct pci_dev *dev = to_pci_dev(hwif->dev);
149 u8 reg42h = 0;
150
151 pci_read_config_byte(dev, 0x42, &reg42h);
152
153 return (reg42h & 0x02) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
154}
155
146/** 156/**
147 * init_hwif_it8213 - set up hwif structs 157 * init_hwif_it8213 - set up hwif structs
148 * @hwif: interface to set up 158 * @hwif: interface to set up
@@ -152,19 +162,10 @@ static void it8213_set_dma_mode(ide_drive_t *drive, const u8 speed)
152 162
153static void __devinit init_hwif_it8213(ide_hwif_t *hwif) 163static void __devinit init_hwif_it8213(ide_hwif_t *hwif)
154{ 164{
155 struct pci_dev *dev = to_pci_dev(hwif->dev);
156 u8 reg42h = 0;
157
158 hwif->set_dma_mode = &it8213_set_dma_mode; 165 hwif->set_dma_mode = &it8213_set_dma_mode;
159 hwif->set_pio_mode = &it8213_set_pio_mode; 166 hwif->set_pio_mode = &it8213_set_pio_mode;
160 167
161 if (!hwif->dma_base) 168 hwif->cable_detect = it8213_cable_detect;
162 return;
163
164 pci_read_config_byte(dev, 0x42, &reg42h);
165
166 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
167 hwif->cbl = (reg42h & 0x02) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
168} 169}
169 170
170 171
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
index 938d35f35c81..79232c6c1f01 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/pci/it821x.c
@@ -579,14 +579,13 @@ static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
579 } else 579 } else
580 hwif->host_flags |= IDE_HFLAG_NO_SET_MODE; 580 hwif->host_flags |= IDE_HFLAG_NO_SET_MODE;
581 581
582 hwif->cable_detect = ata66_it821x;
583
582 if (hwif->dma_base == 0) 584 if (hwif->dma_base == 0)
583 return; 585 return;
584 586
585 hwif->ultra_mask = ATA_UDMA6; 587 hwif->ultra_mask = ATA_UDMA6;
586 hwif->mwdma_mask = ATA_MWDMA2; 588 hwif->mwdma_mask = ATA_MWDMA2;
587
588 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
589 hwif->cbl = ata66_it821x(hwif);
590} 589}
591 590
592static void __devinit it8212_disable_raid(struct pci_dev *dev) 591static void __devinit it8212_disable_raid(struct pci_dev *dev)
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
index 8b40f6479c55..ff53c2df7a13 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/pci/jmicron.c
@@ -111,11 +111,7 @@ static void __devinit init_hwif_jmicron(ide_hwif_t *hwif)
111 hwif->set_pio_mode = &jmicron_set_pio_mode; 111 hwif->set_pio_mode = &jmicron_set_pio_mode;
112 hwif->set_dma_mode = &jmicron_set_dma_mode; 112 hwif->set_dma_mode = &jmicron_set_dma_mode;
113 113
114 if (hwif->dma_base == 0) 114 hwif->cable_detect = ata66_jmicron;
115 return;
116
117 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
118 hwif->cbl = ata66_jmicron(hwif);
119} 115}
120 116
121static const struct ide_port_info jmicron_chipset __devinitdata = { 117static const struct ide_port_info jmicron_chipset __devinitdata = {
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index bb29db03540e..b552960dc1c1 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -197,7 +197,7 @@ static void pdcnew_set_pio_mode(ide_drive_t *drive, const u8 pio)
197 } 197 }
198} 198}
199 199
200static u8 pdcnew_cable_detect(ide_hwif_t *hwif) 200static u8 __devinit pdcnew_cable_detect(ide_hwif_t *hwif)
201{ 201{
202 if (get_indexed_reg(hwif, 0x0b) & 0x04) 202 if (get_indexed_reg(hwif, 0x0b) & 0x04)
203 return ATA_CBL_PATA40; 203 return ATA_CBL_PATA40;
@@ -456,11 +456,7 @@ static void __devinit init_hwif_pdc202new(ide_hwif_t *hwif)
456 hwif->quirkproc = &pdcnew_quirkproc; 456 hwif->quirkproc = &pdcnew_quirkproc;
457 hwif->resetproc = &pdcnew_reset; 457 hwif->resetproc = &pdcnew_reset;
458 458
459 if (hwif->dma_base == 0) 459 hwif->cable_detect = pdcnew_cable_detect;
460 return;
461
462 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
463 hwif->cbl = pdcnew_cable_detect(hwif);
464} 460}
465 461
466static struct pci_dev * __devinit pdc20270_get_dev2(struct pci_dev *dev) 462static struct pci_dev * __devinit pdc20270_get_dev2(struct pci_dev *dev)
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c
index 31a1308414a0..41853a1bc913 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pci/pdc202xx_old.c
@@ -140,7 +140,7 @@ static void pdc202xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
140 pdc202xx_set_mode(drive, XFER_PIO_0 + pio); 140 pdc202xx_set_mode(drive, XFER_PIO_0 + pio);
141} 141}
142 142
143static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif) 143static u8 __devinit pdc2026x_old_cable_detect(ide_hwif_t *hwif)
144{ 144{
145 struct pci_dev *dev = to_pci_dev(hwif->dev); 145 struct pci_dev *dev = to_pci_dev(hwif->dev);
146 u16 CIS = 0, mask = (hwif->channel) ? (1<<11) : (1<<10); 146 u16 CIS = 0, mask = (hwif->channel) ? (1<<11) : (1<<10);
@@ -311,9 +311,12 @@ static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif)
311 311
312 hwif->quirkproc = &pdc202xx_quirkproc; 312 hwif->quirkproc = &pdc202xx_quirkproc;
313 313
314 if (dev->device != PCI_DEVICE_ID_PROMISE_20246) 314 if (dev->device != PCI_DEVICE_ID_PROMISE_20246) {
315 hwif->resetproc = &pdc202xx_reset; 315 hwif->resetproc = &pdc202xx_reset;
316 316
317 hwif->cable_detect = pdc2026x_old_cable_detect;
318 }
319
317 if (hwif->dma_base == 0) 320 if (hwif->dma_base == 0)
318 return; 321 return;
319 322
@@ -321,9 +324,6 @@ static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif)
321 hwif->dma_timeout = &pdc202xx_dma_timeout; 324 hwif->dma_timeout = &pdc202xx_dma_timeout;
322 325
323 if (dev->device != PCI_DEVICE_ID_PROMISE_20246) { 326 if (dev->device != PCI_DEVICE_ID_PROMISE_20246) {
324 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
325 hwif->cbl = pdc202xx_old_cable_detect(hwif);
326
327 hwif->dma_start = &pdc202xx_old_ide_dma_start; 327 hwif->dma_start = &pdc202xx_old_ide_dma_start;
328 hwif->ide_dma_end = &pdc202xx_old_ide_dma_end; 328 hwif->ide_dma_end = &pdc202xx_old_ide_dma_end;
329 } 329 }
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index c1a6b68337d5..039f442c9ea7 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -290,14 +290,11 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
290 hwif->set_pio_mode = &piix_set_pio_mode; 290 hwif->set_pio_mode = &piix_set_pio_mode;
291 hwif->set_dma_mode = &piix_set_dma_mode; 291 hwif->set_dma_mode = &piix_set_dma_mode;
292 292
293 hwif->cable_detect = piix_cable_detect;
294
293 if (!hwif->dma_base) 295 if (!hwif->dma_base)
294 return; 296 return;
295 297
296 if (hwif->ultra_mask & 0x78) {
297 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
298 hwif->cbl = piix_cable_detect(hwif);
299 }
300
301 if (no_piix_dma) 298 if (no_piix_dma)
302 hwif->ultra_mask = hwif->mwdma_mask = hwif->swdma_mask = 0; 299 hwif->ultra_mask = hwif->mwdma_mask = hwif->swdma_mask = 0;
303} 300}
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/pci/scc_pata.c
index dcd44d7c0846..085c1b58a99c 100644
--- a/drivers/ide/pci/scc_pata.c
+++ b/drivers/ide/pci/scc_pata.c
@@ -683,8 +683,7 @@ static void __devinit init_hwif_scc(ide_hwif_t *hwif)
683 else 683 else
684 hwif->ultra_mask = ATA_UDMA5; /* 100MHz */ 684 hwif->ultra_mask = ATA_UDMA5; /* 100MHz */
685 685
686 if (hwif->cbl != ATA_CBL_PATA40_SHORT) 686 hwif->cable_detect = scc_cable_detect;
687 hwif->cbl = scc_cable_detect(hwif);
688} 687}
689 688
690#define DECLARE_SCC_DEV(name_str) \ 689#define DECLARE_SCC_DEV(name_str) \
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index f495253b7d41..d9687a431c5a 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -346,13 +346,8 @@ static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
346 hwif->set_dma_mode = &svwks_set_dma_mode; 346 hwif->set_dma_mode = &svwks_set_dma_mode;
347 hwif->udma_filter = &svwks_udma_filter; 347 hwif->udma_filter = &svwks_udma_filter;
348 348
349 if (!hwif->dma_base) 349 if (dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE)
350 return; 350 hwif->cable_detect = ata66_svwks;
351
352 if (dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
353 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
354 hwif->cbl = ata66_svwks(hwif);
355 }
356} 351}
357 352
358#define IDE_HFLAGS_SVWKS \ 353#define IDE_HFLAGS_SVWKS \
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index 4877bc8cd599..accac8342e17 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -827,15 +827,14 @@ static void __devinit init_hwif_siimage(ide_hwif_t *hwif)
827 } else 827 } else
828 hwif->udma_filter = &sil_pata_udma_filter; 828 hwif->udma_filter = &sil_pata_udma_filter;
829 829
830 hwif->cable_detect = ata66_siimage;
831
830 if (hwif->dma_base == 0) 832 if (hwif->dma_base == 0)
831 return; 833 return;
832 834
833 if (sata) 835 if (sata)
834 hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA; 836 hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA;
835 837
836 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
837 hwif->cbl = ata66_siimage(hwif);
838
839 if (hwif->mmio) { 838 if (hwif->mmio) {
840 hwif->ide_dma_test_irq = &siimage_mmio_ide_dma_test_irq; 839 hwif->ide_dma_test_irq = &siimage_mmio_ide_dma_test_irq;
841 } else { 840 } else {
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 2a461de22aa0..cb5c6fc6f3f9 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -565,13 +565,12 @@ static void __devinit init_hwif_sis5513 (ide_hwif_t *hwif)
565 if (chipset_family >= ATA_133) 565 if (chipset_family >= ATA_133)
566 hwif->udma_filter = sis5513_ata133_udma_filter; 566 hwif->udma_filter = sis5513_ata133_udma_filter;
567 567
568 hwif->cable_detect = ata66_sis5513;
569
568 if (hwif->dma_base == 0) 570 if (hwif->dma_base == 0)
569 return; 571 return;
570 572
571 hwif->ultra_mask = udma_rates[chipset_family]; 573 hwif->ultra_mask = udma_rates[chipset_family];
572
573 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
574 hwif->cbl = ata66_sis5513(hwif);
575} 574}
576 575
577static const struct ide_port_info sis5513_chipset __devinitdata = { 576static const struct ide_port_info sis5513_chipset __devinitdata = {
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index a6cf810c4699..427f95b25fde 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -118,23 +118,23 @@ static void slc90e66_set_dma_mode(ide_drive_t *drive, const u8 speed)
118 } 118 }
119} 119}
120 120
121static void __devinit init_hwif_slc90e66 (ide_hwif_t *hwif) 121static u8 __devinit slc90e66_cable_detect(ide_hwif_t *hwif)
122{ 122{
123 struct pci_dev *dev = to_pci_dev(hwif->dev); 123 struct pci_dev *dev = to_pci_dev(hwif->dev);
124 u8 reg47 = 0; 124 u8 reg47 = 0, mask = hwif->channel ? 0x01 : 0x02;
125 u8 mask = hwif->channel ? 0x01 : 0x02; /* bit0:Primary */
126
127 hwif->set_pio_mode = &slc90e66_set_pio_mode;
128 hwif->set_dma_mode = &slc90e66_set_dma_mode;
129 125
130 pci_read_config_byte(dev, 0x47, &reg47); 126 pci_read_config_byte(dev, 0x47, &reg47);
131 127
132 if (hwif->dma_base == 0) 128 /* bit[0(1)]: 0:80, 1:40 */
133 return; 129 return (reg47 & mask) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
130}
131
132static void __devinit init_hwif_slc90e66(ide_hwif_t *hwif)
133{
134 hwif->set_pio_mode = &slc90e66_set_pio_mode;
135 hwif->set_dma_mode = &slc90e66_set_dma_mode;
134 136
135 if (hwif->cbl != ATA_CBL_PATA40_SHORT) 137 hwif->cable_detect = slc90e66_cable_detect;
136 /* bit[0(1)]: 0:80, 1:40 */
137 hwif->cbl = (reg47 & mask) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
138} 138}
139 139
140static const struct ide_port_info slc90e66_chipset __devinitdata = { 140static const struct ide_port_info slc90e66_chipset __devinitdata = {
diff --git a/drivers/ide/pci/tc86c001.c b/drivers/ide/pci/tc86c001.c
index 9fbbb4f2dd54..2ef2ed2f2b32 100644
--- a/drivers/ide/pci/tc86c001.c
+++ b/drivers/ide/pci/tc86c001.c
@@ -160,6 +160,19 @@ static int tc86c001_busproc(ide_drive_t *drive, int state)
160 return 0; 160 return 0;
161} 161}
162 162
163static u8 __devinit tc86c001_cable_detect(ide_hwif_t *hwif)
164{
165 struct pci_dev *dev = to_pci_dev(hwif->dev);
166 unsigned long sc_base = pci_resource_start(dev, 5);
167 u16 scr1 = inw(sc_base + 0x00);
168
169 /*
170 * System Control 1 Register bit 13 (PDIAGN):
171 * 0=80-pin cable, 1=40-pin cable
172 */
173 return (scr1 & 0x2000) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
174}
175
163static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif) 176static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif)
164{ 177{
165 struct pci_dev *dev = to_pci_dev(hwif->dev); 178 struct pci_dev *dev = to_pci_dev(hwif->dev);
@@ -183,6 +196,8 @@ static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif)
183 196
184 hwif->busproc = &tc86c001_busproc; 197 hwif->busproc = &tc86c001_busproc;
185 198
199 hwif->cable_detect = tc86c001_cable_detect;
200
186 if (!hwif->dma_base) 201 if (!hwif->dma_base)
187 return; 202 return;
188 203
@@ -196,15 +211,6 @@ static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif)
196 hwif->rqsize = 0xffff; 211 hwif->rqsize = 0xffff;
197 212
198 hwif->dma_start = &tc86c001_dma_start; 213 hwif->dma_start = &tc86c001_dma_start;
199
200 if (hwif->cbl != ATA_CBL_PATA40_SHORT) {
201 /*
202 * System Control 1 Register bit 13 (PDIAGN):
203 * 0=80-pin cable, 1=40-pin cable
204 */
205 scr1 = inw(sc_base + 0x00);
206 hwif->cbl = (scr1 & 0x2000) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
207 }
208} 214}
209 215
210static unsigned int __devinit init_chipset_tc86c001(struct pci_dev *dev, 216static unsigned int __devinit init_chipset_tc86c001(struct pci_dev *dev,
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index 24cb9047fb41..c58a279d6b2f 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -424,11 +424,7 @@ static void __devinit init_hwif_via82cxxx(ide_hwif_t *hwif)
424 hwif->set_pio_mode = &via_set_pio_mode; 424 hwif->set_pio_mode = &via_set_pio_mode;
425 hwif->set_dma_mode = &via_set_drive; 425 hwif->set_dma_mode = &via_set_drive;
426 426
427 if (!hwif->dma_base) 427 hwif->cable_detect = via82cxxx_cable_detect;
428 return;
429
430 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
431 hwif->cbl = via82cxxx_cable_detect(hwif);
432} 428}
433 429
434static const struct ide_port_info via82cxxx_chipset __devinitdata = { 430static const struct ide_port_info via82cxxx_chipset __devinitdata = {