aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-04-26 12:48:00 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-26 12:48:00 -0400
commit1292ebb82c00c69cf983e871faa221ce88ed3338 (patch)
tree91f624dd175c9d3e842db78789c6a0c79a78eee5
parentb82287587ef9917afbea5fcbf7aa63424b6f3719 (diff)
parent784506cbddd17bcd5929f827df39b0c7014e3f1e (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6: (61 commits) ide: sanitize handling of IDE_HFLAG_NO_SET_MODE host flag sis5513: fail early for unsupported chipsets it821x: fix kzalloc() failure handling qd65xx: use IDE_HFLAG_SINGLE host flag qd65xx: always use ->selectproc method ide-cd: put proc-related functions together under single ifdef ide-cd: Replace __FUNCTION__ with __func__ IDE: Coding Style fixes to drivers/ide/ide-cd.c IDE: Coding Style fixes to drivers/ide/pci/cy82c693.c IDE: Coding Style fixes to drivers/ide/pci/it8213.c IDE: Coding Style fixes to drivers/ide/ide-floppy.c IDE: Coding Style fixes to drivers/ide/legacy/ali14xx.c IDE: Coding Style fixes to drivers/ide/legacy/hd.c IDE: Coding Style fixes to drivers/ide/pci/cmd640.c IDE: Coding Style fixes to drivers/ide/pci/opti621.c IDE: Coding Style fixes to drivers/ide/ide-pnp.c IDE: Coding Style fixes to drivers/ide/ide-proc.c IDE: Coding Style fixes to drivers/ide/legacy/ide-4drives.c IDE: Coding Style fixes to drivers/ide/legacy/umc8672.c IDE: Coding Style fixes to drivers/ide/pci/generic.c ...
-rw-r--r--drivers/ide/Kconfig2
-rw-r--r--drivers/ide/arm/bast-ide.c12
-rw-r--r--drivers/ide/arm/icside.c2
-rw-r--r--drivers/ide/arm/ide_arm.c2
-rw-r--r--drivers/ide/arm/palm_bk3710.c26
-rw-r--r--drivers/ide/arm/rapide.c2
-rw-r--r--drivers/ide/cris/ide-cris.c2
-rw-r--r--drivers/ide/h8300/ide-h8300.c3
-rw-r--r--drivers/ide/ide-cd.c412
-rw-r--r--drivers/ide/ide-cd.h4
-rw-r--r--drivers/ide/ide-disk.c159
-rw-r--r--drivers/ide/ide-dma.c13
-rw-r--r--drivers/ide/ide-floppy.c16
-rw-r--r--drivers/ide/ide-generic.c16
-rw-r--r--drivers/ide/ide-io.c4
-rw-r--r--drivers/ide/ide-lib.c22
-rw-r--r--drivers/ide/ide-pnp.c12
-rw-r--r--drivers/ide/ide-probe.c48
-rw-r--r--drivers/ide/ide-proc.c155
-rw-r--r--drivers/ide/ide.c69
-rw-r--r--drivers/ide/legacy/ali14xx.c30
-rw-r--r--drivers/ide/legacy/buddha.c2
-rw-r--r--drivers/ide/legacy/dtc2278.c22
-rw-r--r--drivers/ide/legacy/falconide.c9
-rw-r--r--drivers/ide/legacy/gayle.c2
-rw-r--r--drivers/ide/legacy/hd.c78
-rw-r--r--drivers/ide/legacy/ht6560b.c34
-rw-r--r--drivers/ide/legacy/ide-4drives.c36
-rw-r--r--drivers/ide/legacy/ide-cs.c2
-rw-r--r--drivers/ide/legacy/ide_platform.c7
-rw-r--r--drivers/ide/legacy/macide.c2
-rw-r--r--drivers/ide/legacy/q40ide.c2
-rw-r--r--drivers/ide/legacy/qd65xx.c165
-rw-r--r--drivers/ide/legacy/qd65xx.h1
-rw-r--r--drivers/ide/legacy/umc8672.c81
-rw-r--r--drivers/ide/mips/au1xxx-ide.c8
-rw-r--r--drivers/ide/mips/swarm.c9
-rw-r--r--drivers/ide/pci/aec62xx.c3
-rw-r--r--drivers/ide/pci/alim15x3.c1
-rw-r--r--drivers/ide/pci/amd74xx.c4
-rw-r--r--drivers/ide/pci/atiixp.c5
-rw-r--r--drivers/ide/pci/cmd640.c188
-rw-r--r--drivers/ide/pci/cmd64x.c9
-rw-r--r--drivers/ide/pci/cs5520.c3
-rw-r--r--drivers/ide/pci/cs5530.c3
-rw-r--r--drivers/ide/pci/cs5535.c2
-rw-r--r--drivers/ide/pci/cy82c693.c77
-rw-r--r--drivers/ide/pci/delkin_cb.c6
-rw-r--r--drivers/ide/pci/generic.c10
-rw-r--r--drivers/ide/pci/hpt34x.c2
-rw-r--r--drivers/ide/pci/hpt366.c2
-rw-r--r--drivers/ide/pci/it8213.c12
-rw-r--r--drivers/ide/pci/it821x.c25
-rw-r--r--drivers/ide/pci/jmicron.c4
-rw-r--r--drivers/ide/pci/ns87415.c3
-rw-r--r--drivers/ide/pci/opti621.c61
-rw-r--r--drivers/ide/pci/piix.c4
-rw-r--r--drivers/ide/pci/rz1000.c2
-rw-r--r--drivers/ide/pci/sc1200.c3
-rw-r--r--drivers/ide/pci/scc_pata.c17
-rw-r--r--drivers/ide/pci/serverworks.c5
-rw-r--r--drivers/ide/pci/sgiioc4.c12
-rw-r--r--drivers/ide/pci/siimage.c1
-rw-r--r--drivers/ide/pci/sis5513.c225
-rw-r--r--drivers/ide/pci/sl82c105.c3
-rw-r--r--drivers/ide/pci/slc90e66.c8
-rw-r--r--drivers/ide/pci/tc86c001.c28
-rw-r--r--drivers/ide/pci/triflex.c1
-rw-r--r--drivers/ide/pci/trm290.c1
-rw-r--r--drivers/ide/pci/via82cxxx.c4
-rw-r--r--drivers/ide/ppc/mpc8xx.c58
-rw-r--r--drivers/ide/ppc/pmac.c90
-rw-r--r--drivers/ide/setup-pci.c129
-rw-r--r--include/linux/Kbuild1
-rw-r--r--include/linux/hdsmart.h126
-rw-r--r--include/linux/ide.h23
76 files changed, 1194 insertions, 1438 deletions
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index 87532034d105..3f9e10001e19 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -1031,7 +1031,7 @@ comment "Other IDE chipsets support"
1031comment "Note: most of these also require special kernel boot parameters" 1031comment "Note: most of these also require special kernel boot parameters"
1032 1032
1033config BLK_DEV_4DRIVES 1033config BLK_DEV_4DRIVES
1034 bool "Generic 4 drives/port support" 1034 tristate "Generic 4 drives/port support"
1035 help 1035 help
1036 Certain older chipsets, including the Tekram 690CD, use a single set 1036 Certain older chipsets, including the Tekram 690CD, use a single set
1037 of I/O ports at 0x1f0 to control up to four drives, instead of the 1037 of I/O ports at 0x1f0 to control up to four drives, instead of the
diff --git a/drivers/ide/arm/bast-ide.c b/drivers/ide/arm/bast-ide.c
index ec46c44b061c..a80b9574865e 100644
--- a/drivers/ide/arm/bast-ide.c
+++ b/drivers/ide/arm/bast-ide.c
@@ -21,6 +21,8 @@
21#include <asm/arch/bast-map.h> 21#include <asm/arch/bast-map.h>
22#include <asm/arch/bast-irq.h> 22#include <asm/arch/bast-irq.h>
23 23
24#define DRV_NAME "bast-ide"
25
24static int __init bastide_register(unsigned int base, unsigned int aux, int irq) 26static int __init bastide_register(unsigned int base, unsigned int aux, int irq)
25{ 27{
26 ide_hwif_t *hwif; 28 ide_hwif_t *hwif;
@@ -41,7 +43,7 @@ static int __init bastide_register(unsigned int base, unsigned int aux, int irq)
41 hw.io_ports[IDE_CONTROL_OFFSET] = aux + (6 * 0x20); 43 hw.io_ports[IDE_CONTROL_OFFSET] = aux + (6 * 0x20);
42 hw.irq = irq; 44 hw.irq = irq;
43 45
44 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); 46 hwif = ide_find_port();
45 if (hwif == NULL) 47 if (hwif == NULL)
46 goto out; 48 goto out;
47 49
@@ -53,6 +55,7 @@ static int __init bastide_register(unsigned int base, unsigned int aux, int irq)
53 ide_init_port_data(hwif, i); 55 ide_init_port_data(hwif, i);
54 56
55 ide_init_port_hw(hwif, &hw); 57 ide_init_port_hw(hwif, &hw);
58 hwif->mmio = 1;
56 hwif->quirkproc = NULL; 59 hwif->quirkproc = NULL;
57 60
58 idx[0] = i; 61 idx[0] = i;
@@ -64,6 +67,8 @@ out:
64 67
65static int __init bastide_init(void) 68static int __init bastide_init(void)
66{ 69{
70 unsigned long base = BAST_VA_IDEPRI + BAST_IDE_CS;
71
67 /* we can treat the VR1000 and the BAST the same */ 72 /* we can treat the VR1000 and the BAST the same */
68 73
69 if (!(machine_is_bast() || machine_is_vr1000())) 74 if (!(machine_is_bast() || machine_is_vr1000()))
@@ -71,6 +76,11 @@ static int __init bastide_init(void)
71 76
72 printk("BAST: IDE driver, (c) 2003-2004 Simtec Electronics\n"); 77 printk("BAST: IDE driver, (c) 2003-2004 Simtec Electronics\n");
73 78
79 if (!request_mem_region(base, 0x400000, DRV_NAME)) {
80 printk(KERN_ERR "%s: resources busy\n", DRV_NAME);
81 return -EBUSY;
82 }
83
74 bastide_register(BAST_VA_IDEPRI, BAST_VA_IDEPRIAUX, IRQ_IDE0); 84 bastide_register(BAST_VA_IDEPRI, BAST_VA_IDEPRIAUX, IRQ_IDE0);
75 bastide_register(BAST_VA_IDESEC, BAST_VA_IDESECAUX, IRQ_IDE1); 85 bastide_register(BAST_VA_IDESEC, BAST_VA_IDESECAUX, IRQ_IDE1);
76 86
diff --git a/drivers/ide/arm/icside.c b/drivers/ide/arm/icside.c
index e816b0ffcfe6..fd12bbe93f11 100644
--- a/drivers/ide/arm/icside.c
+++ b/drivers/ide/arm/icside.c
@@ -400,7 +400,7 @@ icside_setup(void __iomem *base, struct cardinfo *info, struct expansion_card *e
400 unsigned long port = (unsigned long)base + info->dataoffset; 400 unsigned long port = (unsigned long)base + info->dataoffset;
401 ide_hwif_t *hwif; 401 ide_hwif_t *hwif;
402 402
403 hwif = ide_find_port(port); 403 hwif = ide_find_port();
404 if (hwif) { 404 if (hwif) {
405 int i; 405 int i;
406 406
diff --git a/drivers/ide/arm/ide_arm.c b/drivers/ide/arm/ide_arm.c
index be9ff7334c52..82643df7c49a 100644
--- a/drivers/ide/arm/ide_arm.c
+++ b/drivers/ide/arm/ide_arm.c
@@ -34,7 +34,7 @@ static int __init ide_arm_init(void)
34 ide_std_init_ports(&hw, IDE_ARM_IO, IDE_ARM_IO + 0x206); 34 ide_std_init_ports(&hw, IDE_ARM_IO, IDE_ARM_IO + 0x206);
35 hw.irq = IDE_ARM_IRQ; 35 hw.irq = IDE_ARM_IRQ;
36 36
37 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); 37 hwif = ide_find_port();
38 if (hwif) { 38 if (hwif) {
39 ide_init_port_hw(hwif, &hw); 39 ide_init_port_hw(hwif, &hw);
40 idx[0] = hwif->index; 40 idx[0] = hwif->index;
diff --git a/drivers/ide/arm/palm_bk3710.c b/drivers/ide/arm/palm_bk3710.c
index 420fcb78a7cd..666df779a5f4 100644
--- a/drivers/ide/arm/palm_bk3710.c
+++ b/drivers/ide/arm/palm_bk3710.c
@@ -96,11 +96,11 @@ static void palm_bk3710_setudmamode(void __iomem *base, unsigned int dev,
96 u16 val16; 96 u16 val16;
97 97
98 /* DMA Data Setup */ 98 /* DMA Data Setup */
99 t0 = (palm_bk3710_udmatimings[mode].cycletime + ide_palm_clk - 1) 99 t0 = DIV_ROUND_UP(palm_bk3710_udmatimings[mode].cycletime,
100 / ide_palm_clk - 1; 100 ide_palm_clk) - 1;
101 tenv = (20 + ide_palm_clk - 1) / ide_palm_clk - 1; 101 tenv = DIV_ROUND_UP(20, ide_palm_clk) - 1;
102 trp = (palm_bk3710_udmatimings[mode].rptime + ide_palm_clk - 1) 102 trp = DIV_ROUND_UP(palm_bk3710_udmatimings[mode].rptime,
103 / ide_palm_clk - 1; 103 ide_palm_clk) - 1;
104 104
105 /* udmatim Register */ 105 /* udmatim Register */
106 val16 = readw(base + BK3710_UDMATIM) & (dev ? 0xFF0F : 0xFFF0); 106 val16 = readw(base + BK3710_UDMATIM) & (dev ? 0xFF0F : 0xFFF0);
@@ -141,8 +141,8 @@ static void palm_bk3710_setdmamode(void __iomem *base, unsigned int dev,
141 cycletime = max_t(int, t->cycle, min_cycle); 141 cycletime = max_t(int, t->cycle, min_cycle);
142 142
143 /* DMA Data Setup */ 143 /* DMA Data Setup */
144 t0 = (cycletime + ide_palm_clk - 1) / ide_palm_clk; 144 t0 = DIV_ROUND_UP(cycletime, ide_palm_clk);
145 td = (t->active + ide_palm_clk - 1) / ide_palm_clk; 145 td = DIV_ROUND_UP(t->active, ide_palm_clk);
146 tkw = t0 - td - 1; 146 tkw = t0 - td - 1;
147 td -= 1; 147 td -= 1;
148 148
@@ -168,9 +168,9 @@ static void palm_bk3710_setpiomode(void __iomem *base, ide_drive_t *mate,
168 struct ide_timing *t; 168 struct ide_timing *t;
169 169
170 /* PIO Data Setup */ 170 /* PIO Data Setup */
171 t0 = (cycletime + ide_palm_clk - 1) / ide_palm_clk; 171 t0 = DIV_ROUND_UP(cycletime, ide_palm_clk);
172 t2 = (ide_timing_find_mode(XFER_PIO_0 + mode)->active + 172 t2 = DIV_ROUND_UP(ide_timing_find_mode(XFER_PIO_0 + mode)->active,
173 ide_palm_clk - 1) / ide_palm_clk; 173 ide_palm_clk);
174 174
175 t2i = t0 - t2 - 1; 175 t2i = t0 - t2 - 1;
176 t2 -= 1; 176 t2 -= 1;
@@ -192,8 +192,8 @@ static void palm_bk3710_setpiomode(void __iomem *base, ide_drive_t *mate,
192 192
193 /* TASKFILE Setup */ 193 /* TASKFILE Setup */
194 t = ide_timing_find_mode(XFER_PIO_0 + mode); 194 t = ide_timing_find_mode(XFER_PIO_0 + mode);
195 t0 = (t->cyc8b + ide_palm_clk - 1) / ide_palm_clk; 195 t0 = DIV_ROUND_UP(t->cyc8b, ide_palm_clk);
196 t2 = (t->act8b + ide_palm_clk - 1) / ide_palm_clk; 196 t2 = DIV_ROUND_UP(t->act8b, ide_palm_clk);
197 197
198 t2i = t0 - t2 - 1; 198 t2i = t0 - t2 - 1;
199 t2 -= 1; 199 t2 -= 1;
@@ -378,7 +378,7 @@ static int __devinit palm_bk3710_probe(struct platform_device *pdev)
378 hw.irq = irq->start; 378 hw.irq = irq->start;
379 hw.chipset = ide_palm3710; 379 hw.chipset = ide_palm3710;
380 380
381 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); 381 hwif = ide_find_port();
382 if (hwif == NULL) 382 if (hwif == NULL)
383 goto out; 383 goto out;
384 384
diff --git a/drivers/ide/arm/rapide.c b/drivers/ide/arm/rapide.c
index b30adcf321c3..2c3d0ec91dc3 100644
--- a/drivers/ide/arm/rapide.c
+++ b/drivers/ide/arm/rapide.c
@@ -44,7 +44,7 @@ rapide_probe(struct expansion_card *ec, const struct ecard_id *id)
44 goto release; 44 goto release;
45 } 45 }
46 46
47 hwif = ide_find_port((unsigned long)base); 47 hwif = ide_find_port();
48 if (hwif) { 48 if (hwif) {
49 memset(&hw, 0, sizeof(hw)); 49 memset(&hw, 0, sizeof(hw));
50 rapide_setup_ports(&hw, base, base + 0x818, 1 << 6, ec->irq); 50 rapide_setup_ports(&hw, base, base + 0x818, 1 << 6, ec->irq);
diff --git a/drivers/ide/cris/ide-cris.c b/drivers/ide/cris/ide-cris.c
index 31266d278095..790a7759d455 100644
--- a/drivers/ide/cris/ide-cris.c
+++ b/drivers/ide/cris/ide-cris.c
@@ -804,7 +804,7 @@ static int __init init_e100_ide(void)
804 804
805 cris_setup_ports(&hw, cris_ide_base_address(h)); 805 cris_setup_ports(&hw, cris_ide_base_address(h));
806 806
807 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); 807 hwif = ide_find_port();
808 if (hwif == NULL) 808 if (hwif == NULL)
809 continue; 809 continue;
810 ide_init_port_data(hwif, hwif->index); 810 ide_init_port_data(hwif, hwif->index);
diff --git a/drivers/ide/h8300/ide-h8300.c b/drivers/ide/h8300/ide-h8300.c
index 4108ec4ffa7f..92b02b96d7db 100644
--- a/drivers/ide/h8300/ide-h8300.c
+++ b/drivers/ide/h8300/ide-h8300.c
@@ -99,8 +99,7 @@ static int __init h8300_ide_init(void)
99 99
100 hw_setup(&hw); 100 hw_setup(&hw);
101 101
102 /* register if */ 102 hwif = ide_find_port();
103 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]);
104 if (hwif == NULL) { 103 if (hwif == NULL) {
105 printk(KERN_ERR "ide-h8300: IDE I/F register failed\n"); 104 printk(KERN_ERR "ide-h8300: IDE I/F register failed\n");
106 return -ENOENT; 105 return -ENOENT;
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index fe5aefbf8339..1afd95ad4653 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -13,8 +13,8 @@
13 * 13 *
14 * Suggestions are welcome. Patches that work are more welcome though. ;-) 14 * Suggestions are welcome. Patches that work are more welcome though. ;-)
15 * For those wishing to work on this driver, please be sure you download 15 * For those wishing to work on this driver, please be sure you download
16 * and comply with the latest Mt. Fuji (SFF8090 version 4) and ATAPI 16 * and comply with the latest Mt. Fuji (SFF8090 version 4) and ATAPI
17 * (SFF-8020i rev 2.6) standards. These documents can be obtained by 17 * (SFF-8020i rev 2.6) standards. These documents can be obtained by
18 * anonymous ftp from: 18 * anonymous ftp from:
19 * ftp://fission.dt.wdc.com/pub/standards/SFF_atapi/spec/SFF8020-r2.6/PS/8020r26.ps 19 * ftp://fission.dt.wdc.com/pub/standards/SFF_atapi/spec/SFF8020-r2.6/PS/8020r26.ps
20 * ftp://ftp.avc-pioneer.com/Mtfuji4/Spec/Fuji4r10.pdf 20 * ftp://ftp.avc-pioneer.com/Mtfuji4/Spec/Fuji4r10.pdf
@@ -51,7 +51,7 @@
51 51
52static DEFINE_MUTEX(idecd_ref_mutex); 52static DEFINE_MUTEX(idecd_ref_mutex);
53 53
54#define to_ide_cd(obj) container_of(obj, struct cdrom_info, kref) 54#define to_ide_cd(obj) container_of(obj, struct cdrom_info, kref)
55 55
56#define ide_cd_g(disk) \ 56#define ide_cd_g(disk) \
57 container_of((disk)->private_data, struct cdrom_info, driver) 57 container_of((disk)->private_data, struct cdrom_info, driver)
@@ -83,13 +83,12 @@ static void ide_cd_put(struct cdrom_info *cd)
83 83
84/* Mark that we've seen a media change, and invalidate our internal 84/* Mark that we've seen a media change, and invalidate our internal
85 buffers. */ 85 buffers. */
86static void cdrom_saw_media_change (ide_drive_t *drive) 86static void cdrom_saw_media_change(ide_drive_t *drive)
87{ 87{
88 struct cdrom_info *cd = drive->driver_data; 88 struct cdrom_info *cd = drive->driver_data;
89 89
90 cd->cd_flags |= IDE_CD_FLAG_MEDIA_CHANGED; 90 cd->cd_flags |= IDE_CD_FLAG_MEDIA_CHANGED;
91 cd->cd_flags &= ~IDE_CD_FLAG_TOC_VALID; 91 cd->cd_flags &= ~IDE_CD_FLAG_TOC_VALID;
92 cd->nsectors_buffered = 0;
93} 92}
94 93
95static int cdrom_log_sense(ide_drive_t *drive, struct request *rq, 94static int cdrom_log_sense(ide_drive_t *drive, struct request *rq,
@@ -101,38 +100,39 @@ static int cdrom_log_sense(ide_drive_t *drive, struct request *rq,
101 return 0; 100 return 0;
102 101
103 switch (sense->sense_key) { 102 switch (sense->sense_key) {
104 case NO_SENSE: case RECOVERED_ERROR: 103 case NO_SENSE:
105 break; 104 case RECOVERED_ERROR:
106 case NOT_READY: 105 break;
107 /* 106 case NOT_READY:
108 * don't care about tray state messages for 107 /*
109 * e.g. capacity commands or in-progress or 108 * don't care about tray state messages for
110 * becoming ready 109 * e.g. capacity commands or in-progress or
111 */ 110 * becoming ready
112 if (sense->asc == 0x3a || sense->asc == 0x04) 111 */
113 break; 112 if (sense->asc == 0x3a || sense->asc == 0x04)
114 log = 1;
115 break;
116 case ILLEGAL_REQUEST:
117 /*
118 * don't log START_STOP unit with LoEj set, since
119 * we cannot reliably check if drive can auto-close
120 */
121 if (rq->cmd[0] == GPCMD_START_STOP_UNIT && sense->asc == 0x24)
122 break;
123 log = 1;
124 break;
125 case UNIT_ATTENTION:
126 /*
127 * Make good and sure we've seen this potential media
128 * change. Some drives (i.e. Creative) fail to present
129 * the correct sense key in the error register.
130 */
131 cdrom_saw_media_change(drive);
132 break; 113 break;
133 default: 114 log = 1;
134 log = 1; 115 break;
116 case ILLEGAL_REQUEST:
117 /*
118 * don't log START_STOP unit with LoEj set, since
119 * we cannot reliably check if drive can auto-close
120 */
121 if (rq->cmd[0] == GPCMD_START_STOP_UNIT && sense->asc == 0x24)
135 break; 122 break;
123 log = 1;
124 break;
125 case UNIT_ATTENTION:
126 /*
127 * Make good and sure we've seen this potential media
128 * change. Some drives (i.e. Creative) fail to present
129 * the correct sense key in the error register.
130 */
131 cdrom_saw_media_change(drive);
132 break;
133 default:
134 log = 1;
135 break;
136 } 136 }
137 return log; 137 return log;
138} 138}
@@ -159,8 +159,8 @@ void cdrom_analyze_sense_data(ide_drive_t *drive,
159 if (sense->sense_key == 0x05 && sense->asc == 0x24) 159 if (sense->sense_key == 0x05 && sense->asc == 0x24)
160 return; 160 return;
161 161
162 if (sense->error_code == 0x70) { /* Current Error */ 162 if (sense->error_code == 0x70) { /* Current Error */
163 switch(sense->sense_key) { 163 switch (sense->sense_key) {
164 case MEDIUM_ERROR: 164 case MEDIUM_ERROR:
165 case VOLUME_OVERFLOW: 165 case VOLUME_OVERFLOW:
166 case ILLEGAL_REQUEST: 166 case ILLEGAL_REQUEST:
@@ -179,7 +179,7 @@ void cdrom_analyze_sense_data(ide_drive_t *drive,
179 bio_sectors = 4; 179 bio_sectors = 4;
180 if (drive->queue->hardsect_size == 2048) 180 if (drive->queue->hardsect_size == 2048)
181 sector <<= 2; /* Device sector size is 2K */ 181 sector <<= 2; /* Device sector size is 2K */
182 sector &= ~(bio_sectors -1); 182 sector &= ~(bio_sectors - 1);
183 valid = (sector - failed_command->sector) << 9; 183 valid = (sector - failed_command->sector) << 9;
184 184
185 if (valid < 0) 185 if (valid < 0)
@@ -188,8 +188,8 @@ void cdrom_analyze_sense_data(ide_drive_t *drive,
188 drive->probed_capacity - sector < 4 * 75) { 188 drive->probed_capacity - sector < 4 * 75) {
189 set_capacity(info->disk, sector); 189 set_capacity(info->disk, sector);
190 } 190 }
191 } 191 }
192 } 192 }
193 193
194 ide_cd_log_error(drive->name, failed_command, sense); 194 ide_cd_log_error(drive->name, failed_command, sense);
195} 195}
@@ -230,7 +230,7 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
230 (void) ide_do_drive_cmd(drive, rq, ide_preempt); 230 (void) ide_do_drive_cmd(drive, rq, ide_preempt);
231} 231}
232 232
233static void cdrom_end_request (ide_drive_t *drive, int uptodate) 233static void cdrom_end_request(ide_drive_t *drive, int uptodate)
234{ 234{
235 struct request *rq = HWGROUP(drive)->rq; 235 struct request *rq = HWGROUP(drive)->rq;
236 int nsectors = rq->hard_cur_sectors; 236 int nsectors = rq->hard_cur_sectors;
@@ -293,7 +293,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
293{ 293{
294 struct request *rq = HWGROUP(drive)->rq; 294 struct request *rq = HWGROUP(drive)->rq;
295 int stat, err, sense_key; 295 int stat, err, sense_key;
296 296
297 /* Check for errors. */ 297 /* Check for errors. */
298 stat = ide_read_status(drive); 298 stat = ide_read_status(drive);
299 299
@@ -334,26 +334,26 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
334 334
335 /* Check for tray open. */ 335 /* Check for tray open. */
336 if (sense_key == NOT_READY) { 336 if (sense_key == NOT_READY) {
337 cdrom_saw_media_change (drive); 337 cdrom_saw_media_change(drive);
338 } else if (sense_key == UNIT_ATTENTION) { 338 } else if (sense_key == UNIT_ATTENTION) {
339 /* Check for media change. */ 339 /* Check for media change. */
340 cdrom_saw_media_change (drive); 340 cdrom_saw_media_change(drive);
341 /*printk("%s: media changed\n",drive->name);*/ 341 /*printk("%s: media changed\n",drive->name);*/
342 return 0; 342 return 0;
343 } else if ((sense_key == ILLEGAL_REQUEST) && 343 } else if (sense_key == ILLEGAL_REQUEST &&
344 (rq->cmd[0] == GPCMD_START_STOP_UNIT)) { 344 rq->cmd[0] == GPCMD_START_STOP_UNIT) {
345 /* 345 /*
346 * Don't print error message for this condition-- 346 * Don't print error message for this condition--
347 * SFF8090i indicates that 5/24/00 is the correct 347 * SFF8090i indicates that 5/24/00 is the correct
348 * response to a request to close the tray if the 348 * response to a request to close the tray if the
349 * drive doesn't have that capability. 349 * drive doesn't have that capability.
350 * cdrom_log_sense() knows this! 350 * cdrom_log_sense() knows this!
351 */ 351 */
352 } else if (!(rq->cmd_flags & REQ_QUIET)) { 352 } else if (!(rq->cmd_flags & REQ_QUIET)) {
353 /* Otherwise, print an error. */ 353 /* Otherwise, print an error. */
354 ide_dump_status(drive, "packet command error", stat); 354 ide_dump_status(drive, "packet command error", stat);
355 } 355 }
356 356
357 rq->cmd_flags |= REQ_FAILED; 357 rq->cmd_flags |= REQ_FAILED;
358 358
359 /* 359 /*
@@ -374,10 +374,10 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
374 if (sense_key == NOT_READY) { 374 if (sense_key == NOT_READY) {
375 /* Tray open. */ 375 /* Tray open. */
376 if (rq_data_dir(rq) == READ) { 376 if (rq_data_dir(rq) == READ) {
377 cdrom_saw_media_change (drive); 377 cdrom_saw_media_change(drive);
378 378
379 /* Fail the request. */ 379 /* Fail the request. */
380 printk ("%s: tray open\n", drive->name); 380 printk("%s: tray open\n", drive->name);
381 do_end_request = 1; 381 do_end_request = 1;
382 } else { 382 } else {
383 struct cdrom_info *info = drive->driver_data; 383 struct cdrom_info *info = drive->driver_data;
@@ -399,7 +399,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
399 */ 399 */
400 spin_lock_irqsave(&ide_lock, flags); 400 spin_lock_irqsave(&ide_lock, flags);
401 blk_plug_device(drive->queue); 401 blk_plug_device(drive->queue);
402 spin_unlock_irqrestore(&ide_lock,flags); 402 spin_unlock_irqrestore(&ide_lock, flags);
403 return 1; 403 return 1;
404 } 404 }
405 } 405 }
@@ -407,25 +407,31 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
407 /* Media change. */ 407 /* Media change. */
408 cdrom_saw_media_change (drive); 408 cdrom_saw_media_change (drive);
409 409
410 /* Arrange to retry the request. 410 /*
411 But be sure to give up if we've retried 411 * Arrange to retry the request.
412 too many times. */ 412 * But be sure to give up if we've retried
413 * too many times.
414 */
413 if (++rq->errors > ERROR_MAX) 415 if (++rq->errors > ERROR_MAX)
414 do_end_request = 1; 416 do_end_request = 1;
415 } else if (sense_key == ILLEGAL_REQUEST || 417 } else if (sense_key == ILLEGAL_REQUEST ||
416 sense_key == DATA_PROTECT) { 418 sense_key == DATA_PROTECT) {
417 /* No point in retrying after an illegal 419 /*
418 request or data protect error.*/ 420 * No point in retrying after an illegal
419 ide_dump_status_no_sense (drive, "command error", stat); 421 * request or data protect error.
422 */
423 ide_dump_status_no_sense(drive, "command error", stat);
420 do_end_request = 1; 424 do_end_request = 1;
421 } else if (sense_key == MEDIUM_ERROR) { 425 } else if (sense_key == MEDIUM_ERROR) {
422 /* No point in re-trying a zillion times on a bad 426 /*
423 * sector... If we got here the error is not correctable */ 427 * No point in re-trying a zillion times on a bad
424 ide_dump_status_no_sense (drive, "media error (bad sector)", stat); 428 * sector... If we got here the error is not correctable
429 */
430 ide_dump_status_no_sense(drive, "media error (bad sector)", stat);
425 do_end_request = 1; 431 do_end_request = 1;
426 } else if (sense_key == BLANK_CHECK) { 432 } else if (sense_key == BLANK_CHECK) {
427 /* Disk appears blank ?? */ 433 /* Disk appears blank ?? */
428 ide_dump_status_no_sense (drive, "media error (blank)", stat); 434 ide_dump_status_no_sense(drive, "media error (blank)", stat);
429 do_end_request = 1; 435 do_end_request = 1;
430 } else if ((err & ~ABRT_ERR) != 0) { 436 } else if ((err & ~ABRT_ERR) != 0) {
431 /* Go to the default handler 437 /* Go to the default handler
@@ -486,18 +492,18 @@ static int cdrom_timer_expiry(ide_drive_t *drive)
486 * ide_timer_expiry keep polling us for these. 492 * ide_timer_expiry keep polling us for these.
487 */ 493 */
488 switch (rq->cmd[0]) { 494 switch (rq->cmd[0]) {
489 case GPCMD_BLANK: 495 case GPCMD_BLANK:
490 case GPCMD_FORMAT_UNIT: 496 case GPCMD_FORMAT_UNIT:
491 case GPCMD_RESERVE_RZONE_TRACK: 497 case GPCMD_RESERVE_RZONE_TRACK:
492 case GPCMD_CLOSE_TRACK: 498 case GPCMD_CLOSE_TRACK:
493 case GPCMD_FLUSH_CACHE: 499 case GPCMD_FLUSH_CACHE:
494 wait = ATAPI_WAIT_PC; 500 wait = ATAPI_WAIT_PC;
495 break; 501 break;
496 default: 502 default:
497 if (!(rq->cmd_flags & REQ_QUIET)) 503 if (!(rq->cmd_flags & REQ_QUIET))
498 printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n", rq->cmd[0]); 504 printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n", rq->cmd[0]);
499 wait = 0; 505 wait = 0;
500 break; 506 break;
501 } 507 }
502 return wait; 508 return wait;
503} 509}
@@ -557,7 +563,7 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive,
557 HANDLER is the interrupt handler to call when the command completes 563 HANDLER is the interrupt handler to call when the command completes
558 or there's data ready. */ 564 or there's data ready. */
559#define ATAPI_MIN_CDB_BYTES 12 565#define ATAPI_MIN_CDB_BYTES 12
560static ide_startstop_t cdrom_transfer_packet_command (ide_drive_t *drive, 566static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
561 struct request *rq, 567 struct request *rq,
562 ide_handler_t *handler) 568 ide_handler_t *handler)
563{ 569{
@@ -626,47 +632,6 @@ static void ide_cd_drain_data(ide_drive_t *drive, int nsects)
626} 632}
627 633
628/* 634/*
629 * Buffer up to SECTORS_TO_TRANSFER sectors from the drive in our sector
630 * buffer. Once the first sector is added, any subsequent sectors are
631 * assumed to be continuous (until the buffer is cleared). For the first
632 * sector added, SECTOR is its sector number. (SECTOR is then ignored until
633 * the buffer is cleared.)
634 */
635static void cdrom_buffer_sectors (ide_drive_t *drive, unsigned long sector,
636 int sectors_to_transfer)
637{
638 struct cdrom_info *info = drive->driver_data;
639
640 /* Number of sectors to read into the buffer. */
641 int sectors_to_buffer = min_t(int, sectors_to_transfer,
642 (SECTOR_BUFFER_SIZE >> SECTOR_BITS) -
643 info->nsectors_buffered);
644
645 char *dest;
646
647 /* If we couldn't get a buffer, don't try to buffer anything... */
648 if (info->buffer == NULL)
649 sectors_to_buffer = 0;
650
651 /* If this is the first sector in the buffer, remember its number. */
652 if (info->nsectors_buffered == 0)
653 info->sector_buffered = sector;
654
655 /* Read the data into the buffer. */
656 dest = info->buffer + info->nsectors_buffered * SECTOR_SIZE;
657 while (sectors_to_buffer > 0) {
658 HWIF(drive)->atapi_input_bytes(drive, dest, SECTOR_SIZE);
659 --sectors_to_buffer;
660 --sectors_to_transfer;
661 ++info->nsectors_buffered;
662 dest += SECTOR_SIZE;
663 }
664
665 /* Throw away any remaining data. */
666 ide_cd_drain_data(drive, sectors_to_transfer);
667}
668
669/*
670 * Check the contents of the interrupt reason register from the cdrom 635 * Check the contents of the interrupt reason register from the cdrom
671 * and attempt to recover if there are problems. Returns 0 if everything's 636 * and attempt to recover if there are problems. Returns 0 if everything's
672 * ok; nonzero if the request has been terminated. 637 * ok; nonzero if the request has been terminated.
@@ -686,7 +651,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
686 651
687 /* Whoops... */ 652 /* Whoops... */
688 printk(KERN_ERR "%s: %s: wrong transfer direction!\n", 653 printk(KERN_ERR "%s: %s: wrong transfer direction!\n",
689 drive->name, __FUNCTION__); 654 drive->name, __func__);
690 655
691 xf = rw ? hwif->atapi_output_bytes : hwif->atapi_input_bytes; 656 xf = rw ? hwif->atapi_output_bytes : hwif->atapi_input_bytes;
692 ide_cd_pad_transfer(drive, xf, len); 657 ide_cd_pad_transfer(drive, xf, len);
@@ -699,7 +664,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
699 } else { 664 } else {
700 /* Drive wants a command packet, or invalid ireason... */ 665 /* Drive wants a command packet, or invalid ireason... */
701 printk(KERN_ERR "%s: %s: bad interrupt reason 0x%02x\n", 666 printk(KERN_ERR "%s: %s: bad interrupt reason 0x%02x\n",
702 drive->name, __FUNCTION__, ireason); 667 drive->name, __func__, ireason);
703 } 668 }
704 669
705 if (rq->cmd_type == REQ_TYPE_ATA_PC) 670 if (rq->cmd_type == REQ_TYPE_ATA_PC)
@@ -721,7 +686,7 @@ static int ide_cd_check_transfer_size(ide_drive_t *drive, int len)
721 return 0; 686 return 0;
722 687
723 printk(KERN_ERR "%s: %s: Bad transfer size %d\n", 688 printk(KERN_ERR "%s: %s: Bad transfer size %d\n",
724 drive->name, __FUNCTION__, len); 689 drive->name, __func__, len);
725 690
726 if (cd->cd_flags & IDE_CD_FLAG_LIMIT_NFRAMES) 691 if (cd->cd_flags & IDE_CD_FLAG_LIMIT_NFRAMES)
727 printk(KERN_ERR " This drive is not supported by " 692 printk(KERN_ERR " This drive is not supported by "
@@ -734,65 +699,6 @@ static int ide_cd_check_transfer_size(ide_drive_t *drive, int len)
734 return 1; 699 return 1;
735} 700}
736 701
737/*
738 * Try to satisfy some of the current read request from our cached data.
739 * Returns nonzero if the request has been completed, zero otherwise.
740 */
741static int cdrom_read_from_buffer (ide_drive_t *drive)
742{
743 struct cdrom_info *info = drive->driver_data;
744 struct request *rq = HWGROUP(drive)->rq;
745 unsigned short sectors_per_frame;
746
747 sectors_per_frame = queue_hardsect_size(drive->queue) >> SECTOR_BITS;
748
749 /* Can't do anything if there's no buffer. */
750 if (info->buffer == NULL) return 0;
751
752 /* Loop while this request needs data and the next block is present
753 in our cache. */
754 while (rq->nr_sectors > 0 &&
755 rq->sector >= info->sector_buffered &&
756 rq->sector < info->sector_buffered + info->nsectors_buffered) {
757 if (rq->current_nr_sectors == 0)
758 cdrom_end_request(drive, 1);
759
760 memcpy (rq->buffer,
761 info->buffer +
762 (rq->sector - info->sector_buffered) * SECTOR_SIZE,
763 SECTOR_SIZE);
764 rq->buffer += SECTOR_SIZE;
765 --rq->current_nr_sectors;
766 --rq->nr_sectors;
767 ++rq->sector;
768 }
769
770 /* If we've satisfied the current request,
771 terminate it successfully. */
772 if (rq->nr_sectors == 0) {
773 cdrom_end_request(drive, 1);
774 return -1;
775 }
776
777 /* Move on to the next buffer if needed. */
778 if (rq->current_nr_sectors == 0)
779 cdrom_end_request(drive, 1);
780
781 /* If this condition does not hold, then the kluge i use to
782 represent the number of sectors to skip at the start of a transfer
783 will fail. I think that this will never happen, but let's be
784 paranoid and check. */
785 if (rq->current_nr_sectors < bio_cur_sectors(rq->bio) &&
786 (rq->sector & (sectors_per_frame - 1))) {
787 printk(KERN_ERR "%s: cdrom_read_from_buffer: buffer botch (%ld)\n",
788 drive->name, (long)rq->sector);
789 cdrom_end_request(drive, 0);
790 return -1;
791 }
792
793 return 0;
794}
795
796static ide_startstop_t cdrom_newpc_intr(ide_drive_t *); 702static ide_startstop_t cdrom_newpc_intr(ide_drive_t *);
797 703
798/* 704/*
@@ -825,7 +731,7 @@ static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive)
825 if (rq->current_nr_sectors != 731 if (rq->current_nr_sectors !=
826 bio_cur_sectors(rq->bio)) { 732 bio_cur_sectors(rq->bio)) {
827 printk(KERN_ERR "%s: %s: buffer botch (%u)\n", 733 printk(KERN_ERR "%s: %s: buffer botch (%u)\n",
828 drive->name, __FUNCTION__, 734 drive->name, __func__,
829 rq->current_nr_sectors); 735 rq->current_nr_sectors);
830 cdrom_end_request(drive, 0); 736 cdrom_end_request(drive, 0);
831 return ide_stopped; 737 return ide_stopped;
@@ -849,7 +755,7 @@ static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive)
849#define IDECD_SEEK_TIMER (5 * WAIT_MIN_SLEEP) /* 100 ms */ 755#define IDECD_SEEK_TIMER (5 * WAIT_MIN_SLEEP) /* 100 ms */
850#define IDECD_SEEK_TIMEOUT (2 * WAIT_CMD) /* 20 sec */ 756#define IDECD_SEEK_TIMEOUT (2 * WAIT_CMD) /* 20 sec */
851 757
852static ide_startstop_t cdrom_seek_intr (ide_drive_t *drive) 758static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive)
853{ 759{
854 struct cdrom_info *info = drive->driver_data; 760 struct cdrom_info *info = drive->driver_data;
855 int stat; 761 int stat;
@@ -866,14 +772,14 @@ static ide_startstop_t cdrom_seek_intr (ide_drive_t *drive)
866 * this condition is far too common, to bother 772 * this condition is far too common, to bother
867 * users about it 773 * users about it
868 */ 774 */
869 /* printk("%s: disabled DSC seek overlap\n", drive->name);*/ 775 /* printk("%s: disabled DSC seek overlap\n", drive->name);*/
870 drive->dsc_overlap = 0; 776 drive->dsc_overlap = 0;
871 } 777 }
872 } 778 }
873 return ide_stopped; 779 return ide_stopped;
874} 780}
875 781
876static ide_startstop_t cdrom_start_seek_continuation (ide_drive_t *drive) 782static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive)
877{ 783{
878 struct request *rq = HWGROUP(drive)->rq; 784 struct request *rq = HWGROUP(drive)->rq;
879 sector_t frame = rq->sector; 785 sector_t frame = rq->sector;
@@ -888,7 +794,7 @@ static ide_startstop_t cdrom_start_seek_continuation (ide_drive_t *drive)
888 return cdrom_transfer_packet_command(drive, rq, &cdrom_seek_intr); 794 return cdrom_transfer_packet_command(drive, rq, &cdrom_seek_intr);
889} 795}
890 796
891static ide_startstop_t cdrom_start_seek (ide_drive_t *drive, unsigned int block) 797static ide_startstop_t cdrom_start_seek(ide_drive_t *drive, unsigned int block)
892{ 798{
893 struct cdrom_info *info = drive->driver_data; 799 struct cdrom_info *info = drive->driver_data;
894 800
@@ -897,9 +803,11 @@ static ide_startstop_t cdrom_start_seek (ide_drive_t *drive, unsigned int block)
897 return cdrom_start_packet_command(drive, 0, cdrom_start_seek_continuation); 803 return cdrom_start_packet_command(drive, 0, cdrom_start_seek_continuation);
898} 804}
899 805
900/* Fix up a possibly partially-processed request so that we can 806/*
901 start it over entirely, or even put it back on the request queue. */ 807 * Fix up a possibly partially-processed request so that we can
902static void restore_request (struct request *rq) 808 * start it over entirely, or even put it back on the request queue.
809 */
810static void restore_request(struct request *rq)
903{ 811{
904 if (rq->buffer != bio_data(rq->bio)) { 812 if (rq->buffer != bio_data(rq->bio)) {
905 sector_t n = (rq->buffer - (char *) bio_data(rq->bio)) / SECTOR_SIZE; 813 sector_t n = (rq->buffer - (char *) bio_data(rq->bio)) / SECTOR_SIZE;
@@ -950,7 +858,7 @@ int ide_cd_queue_pc(ide_drive_t *drive, struct request *rq)
950 error = ide_do_drive_cmd(drive, rq, ide_wait); 858 error = ide_do_drive_cmd(drive, rq, ide_wait);
951 time = jiffies - time; 859 time = jiffies - time;
952 860
953 /* FIXME: we should probably abort/retry or something 861 /* FIXME: we should probably abort/retry or something
954 * in case of failure */ 862 * in case of failure */
955 if (rq->cmd_flags & REQ_FAILED) { 863 if (rq->cmd_flags & REQ_FAILED) {
956 /* The request failed. Retry if it was due to a unit 864 /* The request failed. Retry if it was due to a unit
@@ -1057,7 +965,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1057 if (rq->current_nr_sectors > 0) { 965 if (rq->current_nr_sectors > 0) {
1058 printk(KERN_ERR "%s: %s: data underrun " 966 printk(KERN_ERR "%s: %s: data underrun "
1059 "(%d blocks)\n", 967 "(%d blocks)\n",
1060 drive->name, __FUNCTION__, 968 drive->name, __func__,
1061 rq->current_nr_sectors); 969 rq->current_nr_sectors);
1062 if (!write) 970 if (!write)
1063 rq->cmd_flags |= REQ_FAILED; 971 rq->cmd_flags |= REQ_FAILED;
@@ -1134,11 +1042,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1134 if (!ptr) { 1042 if (!ptr) {
1135 if (blk_fs_request(rq) && !write) 1043 if (blk_fs_request(rq) && !write)
1136 /* 1044 /*
1137 * If the buffers are full, cache the rest 1045 * If the buffers are full, pipe the rest into
1138 * of the data in our internal buffer. 1046 * oblivion. */
1139 */ 1047 ide_cd_drain_data(drive, thislen >> 9);
1140 cdrom_buffer_sectors(drive, rq->sector,
1141 thislen >> 9);
1142 else { 1048 else {
1143 printk(KERN_ERR "%s: confused, missing data\n", 1049 printk(KERN_ERR "%s: confused, missing data\n",
1144 drive->name); 1050 drive->name);
@@ -1243,10 +1149,6 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
1243 * weirdness which might be present in the request packet. 1149 * weirdness which might be present in the request packet.
1244 */ 1150 */
1245 restore_request(rq); 1151 restore_request(rq);
1246
1247 /* Satisfy whatever we can of this request from our cache. */
1248 if (cdrom_read_from_buffer(drive))
1249 return ide_stopped;
1250 } 1152 }
1251 1153
1252 /* 1154 /*
@@ -1262,9 +1164,6 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
1262 } else 1164 } else
1263 cd->dma = drive->using_dma; 1165 cd->dma = drive->using_dma;
1264 1166
1265 /* Clear the local sector buffer. */
1266 cd->nsectors_buffered = 0;
1267
1268 if (write) 1167 if (write)
1269 cd->devinfo.media_written = 1; 1168 cd->devinfo.media_written = 1;
1270 1169
@@ -1320,7 +1219,7 @@ static ide_startstop_t cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1320 * cdrom driver request routine. 1219 * cdrom driver request routine.
1321 */ 1220 */
1322static ide_startstop_t 1221static ide_startstop_t
1323ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block) 1222ide_do_rw_cdrom(ide_drive_t *drive, struct request *rq, sector_t block)
1324{ 1223{
1325 ide_startstop_t action; 1224 ide_startstop_t action;
1326 struct cdrom_info *info = drive->driver_data; 1225 struct cdrom_info *info = drive->driver_data;
@@ -1335,13 +1234,13 @@ ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block)
1335 ide_stall_queue(drive, IDECD_SEEK_TIMER); 1234 ide_stall_queue(drive, IDECD_SEEK_TIMER);
1336 return ide_stopped; 1235 return ide_stopped;
1337 } 1236 }
1338 printk (KERN_ERR "%s: DSC timeout\n", drive->name); 1237 printk(KERN_ERR "%s: DSC timeout\n", drive->name);
1339 } 1238 }
1340 info->cd_flags &= ~IDE_CD_FLAG_SEEKING; 1239 info->cd_flags &= ~IDE_CD_FLAG_SEEKING;
1341 } 1240 }
1342 if ((rq_data_dir(rq) == READ) && IDE_LARGE_SEEK(info->last_block, block, IDECD_SEEK_THRESHOLD) && drive->dsc_overlap) { 1241 if ((rq_data_dir(rq) == READ) && IDE_LARGE_SEEK(info->last_block, block, IDECD_SEEK_THRESHOLD) && drive->dsc_overlap)
1343 action = cdrom_start_seek(drive, block); 1242 action = cdrom_start_seek(drive, block);
1344 } else 1243 else
1345 action = cdrom_start_rw(drive, rq); 1244 action = cdrom_start_rw(drive, rq);
1346 info->last_block = block; 1245 info->last_block = block;
1347 return action; 1246 return action;
@@ -1374,7 +1273,7 @@ ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block)
1374 */ 1273 */
1375 1274
1376static 1275static
1377void msf_from_bcd (struct atapi_msf *msf) 1276void msf_from_bcd(struct atapi_msf *msf)
1378{ 1277{
1379 msf->minute = BCD2BIN(msf->minute); 1278 msf->minute = BCD2BIN(msf->minute);
1380 msf->second = BCD2BIN(msf->second); 1279 msf->second = BCD2BIN(msf->second);
@@ -1474,7 +1373,7 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
1474 /* Try to allocate space. */ 1373 /* Try to allocate space. */
1475 toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL); 1374 toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL);
1476 if (toc == NULL) { 1375 if (toc == NULL) {
1477 printk (KERN_ERR "%s: No cdrom TOC buffer!\n", drive->name); 1376 printk(KERN_ERR "%s: No cdrom TOC buffer!\n", drive->name);
1478 return -ENOMEM; 1377 return -ENOMEM;
1479 } 1378 }
1480 info->toc = toc; 1379 info->toc = toc;
@@ -1569,9 +1468,9 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
1569 toc->ent[i].track = BCD2BIN(toc->ent[i].track); 1468 toc->ent[i].track = BCD2BIN(toc->ent[i].track);
1570 msf_from_bcd(&toc->ent[i].addr.msf); 1469 msf_from_bcd(&toc->ent[i].addr.msf);
1571 } 1470 }
1572 toc->ent[i].addr.lba = msf_to_lba (toc->ent[i].addr.msf.minute, 1471 toc->ent[i].addr.lba = msf_to_lba(toc->ent[i].addr.msf.minute,
1573 toc->ent[i].addr.msf.second, 1472 toc->ent[i].addr.msf.second,
1574 toc->ent[i].addr.msf.frame); 1473 toc->ent[i].addr.msf.frame);
1575 } 1474 }
1576 1475
1577 /* Read the multisession information. */ 1476 /* Read the multisession information. */
@@ -1595,9 +1494,9 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
1595 if (stat) 1494 if (stat)
1596 return stat; 1495 return stat;
1597 1496
1598 msf_from_bcd (&ms_tmp.ent.addr.msf); 1497 msf_from_bcd(&ms_tmp.ent.addr.msf);
1599 toc->last_session_lba = msf_to_lba(ms_tmp.ent.addr.msf.minute, 1498 toc->last_session_lba = msf_to_lba(ms_tmp.ent.addr.msf.minute,
1600 ms_tmp.ent.addr.msf.second, 1499 ms_tmp.ent.addr.msf.second,
1601 ms_tmp.ent.addr.msf.frame); 1500 ms_tmp.ent.addr.msf.frame);
1602 } 1501 }
1603 1502
@@ -1679,7 +1578,7 @@ static struct cdrom_device_ops ide_cdrom_dops = {
1679 .generic_packet = ide_cdrom_packet, 1578 .generic_packet = ide_cdrom_packet,
1680}; 1579};
1681 1580
1682static int ide_cdrom_register (ide_drive_t *drive, int nslots) 1581static int ide_cdrom_register(ide_drive_t *drive, int nslots)
1683{ 1582{
1684 struct cdrom_info *info = drive->driver_data; 1583 struct cdrom_info *info = drive->driver_data;
1685 struct cdrom_device_info *devinfo = &info->devinfo; 1584 struct cdrom_device_info *devinfo = &info->devinfo;
@@ -1698,7 +1597,7 @@ static int ide_cdrom_register (ide_drive_t *drive, int nslots)
1698} 1597}
1699 1598
1700static 1599static
1701int ide_cdrom_probe_capabilities (ide_drive_t *drive) 1600int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1702{ 1601{
1703 struct cdrom_info *cd = drive->driver_data; 1602 struct cdrom_info *cd = drive->driver_data;
1704 struct cdrom_device_info *cdi = &cd->devinfo; 1603 struct cdrom_device_info *cdi = &cd->devinfo;
@@ -1870,7 +1769,7 @@ static int ide_cdrom_prep_pc(struct request *rq)
1870 rq->errors = ILLEGAL_REQUEST; 1769 rq->errors = ILLEGAL_REQUEST;
1871 return BLKPREP_KILL; 1770 return BLKPREP_KILL;
1872 } 1771 }
1873 1772
1874 return BLKPREP_OK; 1773 return BLKPREP_OK;
1875} 1774}
1876 1775
@@ -1948,7 +1847,7 @@ static unsigned int ide_cd_flags(struct hd_driveid *id)
1948} 1847}
1949 1848
1950static 1849static
1951int ide_cdrom_setup (ide_drive_t *drive) 1850int ide_cdrom_setup(ide_drive_t *drive)
1952{ 1851{
1953 struct cdrom_info *cd = drive->driver_data; 1852 struct cdrom_info *cd = drive->driver_data;
1954 struct cdrom_device_info *cdi = &cd->devinfo; 1853 struct cdrom_device_info *cdi = &cd->devinfo;
@@ -1979,7 +1878,7 @@ int ide_cdrom_setup (ide_drive_t *drive)
1979 else if (cd->cd_flags & IDE_CD_FLAG_SANYO_3CD) 1878 else if (cd->cd_flags & IDE_CD_FLAG_SANYO_3CD)
1980 cdi->sanyo_slot = 3; /* 3 => use CD in slot 0 */ 1879 cdi->sanyo_slot = 3; /* 3 => use CD in slot 0 */
1981 1880
1982 nslots = ide_cdrom_probe_capabilities (drive); 1881 nslots = ide_cdrom_probe_capabilities(drive);
1983 1882
1984 /* 1883 /*
1985 * set correct block size 1884 * set correct block size
@@ -1991,7 +1890,7 @@ int ide_cdrom_setup (ide_drive_t *drive)
1991 drive->dsc_overlap = (drive->next != drive); 1890 drive->dsc_overlap = (drive->next != drive);
1992 1891
1993 if (ide_cdrom_register(drive, nslots)) { 1892 if (ide_cdrom_register(drive, nslots)) {
1994 printk (KERN_ERR "%s: ide_cdrom_setup failed to register device with the cdrom driver.\n", drive->name); 1893 printk(KERN_ERR "%s: ide_cdrom_setup failed to register device with the cdrom driver.\n", drive->name);
1995 cd->devinfo.handle = NULL; 1894 cd->devinfo.handle = NULL;
1996 return 1; 1895 return 1;
1997 } 1896 }
@@ -1999,19 +1898,6 @@ int ide_cdrom_setup (ide_drive_t *drive)
1999 return 0; 1898 return 0;
2000} 1899}
2001 1900
2002#ifdef CONFIG_IDE_PROC_FS
2003static
2004sector_t ide_cdrom_capacity (ide_drive_t *drive)
2005{
2006 unsigned long capacity, sectors_per_frame;
2007
2008 if (cdrom_read_capacity(drive, &capacity, &sectors_per_frame, NULL))
2009 return 0;
2010
2011 return capacity * sectors_per_frame;
2012}
2013#endif
2014
2015static void ide_cd_remove(ide_drive_t *drive) 1901static void ide_cd_remove(ide_drive_t *drive)
2016{ 1902{
2017 struct cdrom_info *info = drive->driver_data; 1903 struct cdrom_info *info = drive->driver_data;
@@ -2030,7 +1916,6 @@ static void ide_cd_release(struct kref *kref)
2030 ide_drive_t *drive = info->drive; 1916 ide_drive_t *drive = info->drive;
2031 struct gendisk *g = info->disk; 1917 struct gendisk *g = info->disk;
2032 1918
2033 kfree(info->buffer);
2034 kfree(info->toc); 1919 kfree(info->toc);
2035 if (devinfo->handle == drive) 1920 if (devinfo->handle == drive)
2036 unregister_cdrom(devinfo); 1921 unregister_cdrom(devinfo);
@@ -2045,14 +1930,24 @@ static void ide_cd_release(struct kref *kref)
2045static int ide_cd_probe(ide_drive_t *); 1930static int ide_cd_probe(ide_drive_t *);
2046 1931
2047#ifdef CONFIG_IDE_PROC_FS 1932#ifdef CONFIG_IDE_PROC_FS
1933static sector_t ide_cdrom_capacity(ide_drive_t *drive)
1934{
1935 unsigned long capacity, sectors_per_frame;
1936
1937 if (cdrom_read_capacity(drive, &capacity, &sectors_per_frame, NULL))
1938 return 0;
1939
1940 return capacity * sectors_per_frame;
1941}
1942
2048static int proc_idecd_read_capacity 1943static int proc_idecd_read_capacity
2049 (char *page, char **start, off_t off, int count, int *eof, void *data) 1944 (char *page, char **start, off_t off, int count, int *eof, void *data)
2050{ 1945{
2051 ide_drive_t *drive = data; 1946 ide_drive_t *drive = data;
2052 int len; 1947 int len;
2053 1948
2054 len = sprintf(page,"%llu\n", (long long)ide_cdrom_capacity(drive)); 1949 len = sprintf(page, "%llu\n", (long long)ide_cdrom_capacity(drive));
2055 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 1950 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
2056} 1951}
2057 1952
2058static ide_proc_entry_t idecd_proc[] = { 1953static ide_proc_entry_t idecd_proc[] = {
@@ -2081,20 +1976,17 @@ static ide_driver_t ide_cdrom_driver = {
2081#endif 1976#endif
2082}; 1977};
2083 1978
2084static int idecd_open(struct inode * inode, struct file * file) 1979static int idecd_open(struct inode *inode, struct file *file)
2085{ 1980{
2086 struct gendisk *disk = inode->i_bdev->bd_disk; 1981 struct gendisk *disk = inode->i_bdev->bd_disk;
2087 struct cdrom_info *info; 1982 struct cdrom_info *info;
2088 int rc = -ENOMEM; 1983 int rc = -ENOMEM;
2089 1984
2090 if (!(info = ide_cd_get(disk))) 1985 info = ide_cd_get(disk);
1986 if (!info)
2091 return -ENXIO; 1987 return -ENXIO;
2092 1988
2093 if (!info->buffer) 1989 rc = cdrom_open(&info->devinfo, inode, file);
2094 info->buffer = kmalloc(SECTOR_BUFFER_SIZE, GFP_KERNEL|__GFP_REPEAT);
2095
2096 if (info->buffer)
2097 rc = cdrom_open(&info->devinfo, inode, file);
2098 1990
2099 if (rc < 0) 1991 if (rc < 0)
2100 ide_cd_put(info); 1992 ide_cd_put(info);
@@ -2102,12 +1994,12 @@ static int idecd_open(struct inode * inode, struct file * file)
2102 return rc; 1994 return rc;
2103} 1995}
2104 1996
2105static int idecd_release(struct inode * inode, struct file * file) 1997static int idecd_release(struct inode *inode, struct file *file)
2106{ 1998{
2107 struct gendisk *disk = inode->i_bdev->bd_disk; 1999 struct gendisk *disk = inode->i_bdev->bd_disk;
2108 struct cdrom_info *info = ide_cd_g(disk); 2000 struct cdrom_info *info = ide_cd_g(disk);
2109 2001
2110 cdrom_release (&info->devinfo, file); 2002 cdrom_release(&info->devinfo, file);
2111 2003
2112 ide_cd_put(info); 2004 ide_cd_put(info);
2113 2005
@@ -2139,7 +2031,7 @@ static int idecd_get_spindown(struct cdrom_device_info *cdi, unsigned long arg)
2139 struct packet_command cgc; 2031 struct packet_command cgc;
2140 char buffer[16]; 2032 char buffer[16];
2141 int stat; 2033 int stat;
2142 char spindown; 2034 char spindown;
2143 2035
2144 init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN); 2036 init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN);
2145 2037
@@ -2148,12 +2040,12 @@ static int idecd_get_spindown(struct cdrom_device_info *cdi, unsigned long arg)
2148 return stat; 2040 return stat;
2149 2041
2150 spindown = buffer[11] & 0x0f; 2042 spindown = buffer[11] & 0x0f;
2151 if (copy_to_user((void __user *)arg, &spindown, sizeof (char))) 2043 if (copy_to_user((void __user *)arg, &spindown, sizeof(char)))
2152 return -EFAULT; 2044 return -EFAULT;
2153 return 0; 2045 return 0;
2154} 2046}
2155 2047
2156static int idecd_ioctl (struct inode *inode, struct file *file, 2048static int idecd_ioctl(struct inode *inode, struct file *file,
2157 unsigned int cmd, unsigned long arg) 2049 unsigned int cmd, unsigned long arg)
2158{ 2050{
2159 struct block_device *bdev = inode->i_bdev; 2051 struct block_device *bdev = inode->i_bdev;
@@ -2161,13 +2053,13 @@ static int idecd_ioctl (struct inode *inode, struct file *file,
2161 int err; 2053 int err;
2162 2054
2163 switch (cmd) { 2055 switch (cmd) {
2164 case CDROMSETSPINDOWN: 2056 case CDROMSETSPINDOWN:
2165 return idecd_set_spindown(&info->devinfo, arg); 2057 return idecd_set_spindown(&info->devinfo, arg);
2166 case CDROMGETSPINDOWN: 2058 case CDROMGETSPINDOWN:
2167 return idecd_get_spindown(&info->devinfo, arg); 2059 return idecd_get_spindown(&info->devinfo, arg);
2168 default: 2060 default:
2169 break; 2061 break;
2170 } 2062 }
2171 2063
2172 err = generic_ide_ioctl(info->drive, file, bdev, cmd, arg); 2064 err = generic_ide_ioctl(info->drive, file, bdev, cmd, arg);
2173 if (err == -EINVAL) 2065 if (err == -EINVAL)
@@ -2193,16 +2085,16 @@ static int idecd_revalidate_disk(struct gendisk *disk)
2193} 2085}
2194 2086
2195static struct block_device_operations idecd_ops = { 2087static struct block_device_operations idecd_ops = {
2196 .owner = THIS_MODULE, 2088 .owner = THIS_MODULE,
2197 .open = idecd_open, 2089 .open = idecd_open,
2198 .release = idecd_release, 2090 .release = idecd_release,
2199 .ioctl = idecd_ioctl, 2091 .ioctl = idecd_ioctl,
2200 .media_changed = idecd_media_changed, 2092 .media_changed = idecd_media_changed,
2201 .revalidate_disk= idecd_revalidate_disk 2093 .revalidate_disk = idecd_revalidate_disk
2202}; 2094};
2203 2095
2204/* options */ 2096/* options */
2205static char *ignore = NULL; 2097static char *ignore;
2206 2098
2207module_param(ignore, charp, 0400); 2099module_param(ignore, charp, 0400);
2208MODULE_DESCRIPTION("ATAPI CD-ROM Driver"); 2100MODULE_DESCRIPTION("ATAPI CD-ROM Driver");
diff --git a/drivers/ide/ide-cd.h b/drivers/ide/ide-cd.h
index 22e3751a681e..a58801c4484d 100644
--- a/drivers/ide/ide-cd.h
+++ b/drivers/ide/ide-cd.h
@@ -119,10 +119,6 @@ struct cdrom_info {
119 119
120 struct atapi_toc *toc; 120 struct atapi_toc *toc;
121 121
122 unsigned long sector_buffered;
123 unsigned long nsectors_buffered;
124 unsigned char *buffer;
125
126 /* The result of the last successful request sense command 122 /* The result of the last successful request sense command
127 on this device. */ 123 on this device. */
128 struct request_sense sense_data; 124 struct request_sense sense_data;
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 39501d130256..8e08d083fce9 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -16,8 +16,6 @@
16 16
17#define IDEDISK_VERSION "1.18" 17#define IDEDISK_VERSION "1.18"
18 18
19//#define DEBUG
20
21#include <linux/module.h> 19#include <linux/module.h>
22#include <linux/types.h> 20#include <linux/types.h>
23#include <linux/string.h> 21#include <linux/string.h>
@@ -88,7 +86,7 @@ static void ide_disk_put(struct ide_disk_obj *idkp)
88 * 86 *
89 * It is called only once for each drive. 87 * It is called only once for each drive.
90 */ 88 */
91static int lba_capacity_is_ok (struct hd_driveid *id) 89static int lba_capacity_is_ok(struct hd_driveid *id)
92{ 90{
93 unsigned long lba_sects, chs_sects, head, tail; 91 unsigned long lba_sects, chs_sects, head, tail;
94 92
@@ -176,7 +174,8 @@ static void ide_tf_set_cmd(ide_drive_t *drive, ide_task_t *task, u8 dma)
176 * __ide_do_rw_disk() issues READ and WRITE commands to a disk, 174 * __ide_do_rw_disk() issues READ and WRITE commands to a disk,
177 * using LBA if supported, or CHS otherwise, to address sectors. 175 * using LBA if supported, or CHS otherwise, to address sectors.
178 */ 176 */
179static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq, sector_t block) 177static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
178 sector_t block)
180{ 179{
181 ide_hwif_t *hwif = HWIF(drive); 180 ide_hwif_t *hwif = HWIF(drive);
182 unsigned int dma = drive->using_dma; 181 unsigned int dma = drive->using_dma;
@@ -228,7 +227,8 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
228 tf->device = (block >> 8) & 0xf; 227 tf->device = (block >> 8) & 0xf;
229 } 228 }
230 } else { 229 } else {
231 unsigned int sect,head,cyl,track; 230 unsigned int sect, head, cyl, track;
231
232 track = (int)block / drive->sect; 232 track = (int)block / drive->sect;
233 sect = (int)block % drive->sect + 1; 233 sect = (int)block % drive->sect + 1;
234 head = track % drive->head; 234 head = track % drive->head;
@@ -271,7 +271,8 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
271 * 1073741822 == 549756 MB or 48bit addressing fake drive 271 * 1073741822 == 549756 MB or 48bit addressing fake drive
272 */ 272 */
273 273
274static ide_startstop_t ide_do_rw_disk (ide_drive_t *drive, struct request *rq, sector_t block) 274static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
275 sector_t block)
275{ 276{
276 ide_hwif_t *hwif = HWIF(drive); 277 ide_hwif_t *hwif = HWIF(drive);
277 278
@@ -452,7 +453,7 @@ static void idedisk_check_hpa(ide_drive_t *drive)
452 * in above order (i.e., if value of higher priority is available, 453 * in above order (i.e., if value of higher priority is available,
453 * reset will be ignored). 454 * reset will be ignored).
454 */ 455 */
455static void init_idedisk_capacity (ide_drive_t *drive) 456static void init_idedisk_capacity(ide_drive_t *drive)
456{ 457{
457 struct hd_driveid *id = drive->id; 458 struct hd_driveid *id = drive->id;
458 /* 459 /*
@@ -479,7 +480,7 @@ static void init_idedisk_capacity (ide_drive_t *drive)
479 } 480 }
480} 481}
481 482
482static sector_t idedisk_capacity (ide_drive_t *drive) 483static sector_t idedisk_capacity(ide_drive_t *drive)
483{ 484{
484 return drive->capacity64 - drive->sect0; 485 return drive->capacity64 - drive->sect0;
485} 486}
@@ -524,10 +525,11 @@ static int proc_idedisk_read_cache
524 int len; 525 int len;
525 526
526 if (drive->id_read) 527 if (drive->id_read)
527 len = sprintf(out,"%i\n", drive->id->buf_size / 2); 528 len = sprintf(out, "%i\n", drive->id->buf_size / 2);
528 else 529 else
529 len = sprintf(out,"(none)\n"); 530 len = sprintf(out, "(none)\n");
530 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 531
532 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
531} 533}
532 534
533static int proc_idedisk_read_capacity 535static int proc_idedisk_read_capacity
@@ -536,54 +538,52 @@ static int proc_idedisk_read_capacity
536 ide_drive_t*drive = (ide_drive_t *)data; 538 ide_drive_t*drive = (ide_drive_t *)data;
537 int len; 539 int len;
538 540
539 len = sprintf(page,"%llu\n", (long long)idedisk_capacity(drive)); 541 len = sprintf(page, "%llu\n", (long long)idedisk_capacity(drive));
540 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 542
543 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
541} 544}
542 545
543static int proc_idedisk_read_smart_thresholds 546static int proc_idedisk_read_smart(char *page, char **start, off_t off,
544 (char *page, char **start, off_t off, int count, int *eof, void *data) 547 int count, int *eof, void *data, u8 sub_cmd)
545{ 548{
546 ide_drive_t *drive = (ide_drive_t *)data; 549 ide_drive_t *drive = (ide_drive_t *)data;
547 int len = 0, i = 0; 550 int len = 0, i = 0;
548 551
549 if (get_smart_data(drive, page, SMART_READ_THRESHOLDS) == 0) { 552 if (get_smart_data(drive, page, sub_cmd) == 0) {
550 unsigned short *val = (unsigned short *) page; 553 unsigned short *val = (unsigned short *) page;
551 char *out = ((char *)val) + (SECTOR_WORDS * 4); 554 char *out = ((char *)val) + (SECTOR_WORDS * 4);
552 page = out; 555 page = out;
553 do { 556 do {
554 out += sprintf(out, "%04x%c", le16_to_cpu(*val), (++i & 7) ? ' ' : '\n'); 557 out += sprintf(out, "%04x%c", le16_to_cpu(*val),
558 (++i & 7) ? ' ' : '\n');
555 val += 1; 559 val += 1;
556 } while (i < (SECTOR_WORDS * 2)); 560 } while (i < (SECTOR_WORDS * 2));
557 len = out - page; 561 len = out - page;
558 } 562 }
559 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 563
564 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
560} 565}
561 566
562static int proc_idedisk_read_smart_values 567static int proc_idedisk_read_sv
563 (char *page, char **start, off_t off, int count, int *eof, void *data) 568 (char *page, char **start, off_t off, int count, int *eof, void *data)
564{ 569{
565 ide_drive_t *drive = (ide_drive_t *)data; 570 return proc_idedisk_read_smart(page, start, off, count, eof, data,
566 int len = 0, i = 0; 571 SMART_READ_VALUES);
572}
567 573
568 if (get_smart_data(drive, page, SMART_READ_VALUES) == 0) { 574static int proc_idedisk_read_st
569 unsigned short *val = (unsigned short *) page; 575 (char *page, char **start, off_t off, int count, int *eof, void *data)
570 char *out = ((char *)val) + (SECTOR_WORDS * 4); 576{
571 page = out; 577 return proc_idedisk_read_smart(page, start, off, count, eof, data,
572 do { 578 SMART_READ_THRESHOLDS);
573 out += sprintf(out, "%04x%c", le16_to_cpu(*val), (++i & 7) ? ' ' : '\n');
574 val += 1;
575 } while (i < (SECTOR_WORDS * 2));
576 len = out - page;
577 }
578 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
579} 579}
580 580
581static ide_proc_entry_t idedisk_proc[] = { 581static ide_proc_entry_t idedisk_proc[] = {
582 { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL }, 582 { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL },
583 { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL }, 583 { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL },
584 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, 584 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
585 { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_smart_values, NULL }, 585 { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL },
586 { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_smart_thresholds, NULL }, 586 { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL },
587 { NULL, 0, NULL, NULL } 587 { NULL, 0, NULL, NULL }
588}; 588};
589#endif /* CONFIG_IDE_PROC_FS */ 589#endif /* CONFIG_IDE_PROC_FS */
@@ -625,12 +625,13 @@ static int set_multcount(ide_drive_t *drive, int arg)
625 if (drive->special.b.set_multmode) 625 if (drive->special.b.set_multmode)
626 return -EBUSY; 626 return -EBUSY;
627 627
628 ide_init_drive_cmd (&rq); 628 ide_init_drive_cmd(&rq);
629 rq.cmd_type = REQ_TYPE_ATA_TASKFILE; 629 rq.cmd_type = REQ_TYPE_ATA_TASKFILE;
630 630
631 drive->mult_req = arg; 631 drive->mult_req = arg;
632 drive->special.b.set_multmode = 1; 632 drive->special.b.set_multmode = 1;
633 (void) ide_do_drive_cmd (drive, &rq, ide_wait); 633 (void)ide_do_drive_cmd(drive, &rq, ide_wait);
634
634 return (drive->mult_count == arg) ? 0 : -EIO; 635 return (drive->mult_count == arg) ? 0 : -EIO;
635} 636}
636 637
@@ -706,7 +707,7 @@ static int write_cache(ide_drive_t *drive, int arg)
706 return err; 707 return err;
707} 708}
708 709
709static int do_idedisk_flushcache (ide_drive_t *drive) 710static int do_idedisk_flushcache(ide_drive_t *drive)
710{ 711{
711 ide_task_t args; 712 ide_task_t args;
712 713
@@ -719,7 +720,7 @@ static int do_idedisk_flushcache (ide_drive_t *drive)
719 return ide_no_data_taskfile(drive, &args); 720 return ide_no_data_taskfile(drive, &args);
720} 721}
721 722
722static int set_acoustic (ide_drive_t *drive, int arg) 723static int set_acoustic(ide_drive_t *drive, int arg)
723{ 724{
724 ide_task_t args; 725 ide_task_t args;
725 726
@@ -753,7 +754,7 @@ static int set_lba_addressing(ide_drive_t *drive, int arg)
753 return 0; 754 return 0;
754 755
755 if (!idedisk_supports_lba48(drive->id)) 756 if (!idedisk_supports_lba48(drive->id))
756 return -EIO; 757 return -EIO;
757 drive->addressing = arg; 758 drive->addressing = arg;
758 return 0; 759 return 0;
759} 760}
@@ -763,23 +764,35 @@ static void idedisk_add_settings(ide_drive_t *drive)
763{ 764{
764 struct hd_driveid *id = drive->id; 765 struct hd_driveid *id = drive->id;
765 766
766 ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 65535, 1, 1, &drive->bios_cyl, NULL); 767 ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 65535, 1, 1,
767 ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL); 768 &drive->bios_cyl, NULL);
768 ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL); 769 ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1,
769 ide_add_setting(drive, "address", SETTING_RW, TYPE_BYTE, 0, 2, 1, 1, &drive->addressing, set_lba_addressing); 770 &drive->bios_head, NULL);
770 ide_add_setting(drive, "multcount", SETTING_RW, TYPE_BYTE, 0, id->max_multsect, 1, 1, &drive->mult_count, set_multcount); 771 ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1,
771 ide_add_setting(drive, "nowerr", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->nowerr, set_nowerr); 772 &drive->bios_sect, NULL);
772 ide_add_setting(drive, "lun", SETTING_RW, TYPE_INT, 0, 7, 1, 1, &drive->lun, NULL); 773 ide_add_setting(drive, "address", SETTING_RW, TYPE_BYTE, 0, 2, 1, 1,
773 ide_add_setting(drive, "wcache", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->wcache, write_cache); 774 &drive->addressing, set_lba_addressing);
774 ide_add_setting(drive, "acoustic", SETTING_RW, TYPE_BYTE, 0, 254, 1, 1, &drive->acoustic, set_acoustic); 775 ide_add_setting(drive, "multcount", SETTING_RW, TYPE_BYTE, 0,
775 ide_add_setting(drive, "failures", SETTING_RW, TYPE_INT, 0, 65535, 1, 1, &drive->failures, NULL); 776 id->max_multsect, 1, 1, &drive->mult_count,
776 ide_add_setting(drive, "max_failures", SETTING_RW, TYPE_INT, 0, 65535, 1, 1, &drive->max_failures, NULL); 777 set_multcount);
778 ide_add_setting(drive, "nowerr", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1,
779 &drive->nowerr, set_nowerr);
780 ide_add_setting(drive, "lun", SETTING_RW, TYPE_INT, 0, 7, 1, 1,
781 &drive->lun, NULL);
782 ide_add_setting(drive, "wcache", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1,
783 &drive->wcache, write_cache);
784 ide_add_setting(drive, "acoustic", SETTING_RW, TYPE_BYTE, 0, 254, 1, 1,
785 &drive->acoustic, set_acoustic);
786 ide_add_setting(drive, "failures", SETTING_RW, TYPE_INT, 0, 65535, 1, 1,
787 &drive->failures, NULL);
788 ide_add_setting(drive, "max_failures", SETTING_RW, TYPE_INT, 0, 65535,
789 1, 1, &drive->max_failures, NULL);
777} 790}
778#else 791#else
779static inline void idedisk_add_settings(ide_drive_t *drive) { ; } 792static inline void idedisk_add_settings(ide_drive_t *drive) { ; }
780#endif 793#endif
781 794
782static void idedisk_setup (ide_drive_t *drive) 795static void idedisk_setup(ide_drive_t *drive)
783{ 796{
784 ide_hwif_t *hwif = drive->hwif; 797 ide_hwif_t *hwif = drive->hwif;
785 struct hd_driveid *id = drive->id; 798 struct hd_driveid *id = drive->id;
@@ -792,11 +805,10 @@ static void idedisk_setup (ide_drive_t *drive)
792 805
793 if (drive->removable) { 806 if (drive->removable) {
794 /* 807 /*
795 * Removable disks (eg. SYQUEST); ignore 'WD' drives 808 * Removable disks (eg. SYQUEST); ignore 'WD' drives
796 */ 809 */
797 if (id->model[0] != 'W' || id->model[1] != 'D') { 810 if (id->model[0] != 'W' || id->model[1] != 'D')
798 drive->doorlocking = 1; 811 drive->doorlocking = 1;
799 }
800 } 812 }
801 813
802 (void)set_lba_addressing(drive, 1); 814 (void)set_lba_addressing(drive, 1);
@@ -810,10 +822,11 @@ static void idedisk_setup (ide_drive_t *drive)
810 blk_queue_max_sectors(drive->queue, max_s); 822 blk_queue_max_sectors(drive->queue, max_s);
811 } 823 }
812 824
813 printk(KERN_INFO "%s: max request size: %dKiB\n", drive->name, drive->queue->max_sectors / 2); 825 printk(KERN_INFO "%s: max request size: %dKiB\n", drive->name,
826 drive->queue->max_sectors / 2);
814 827
815 /* calculate drive capacity, and select LBA if possible */ 828 /* calculate drive capacity, and select LBA if possible */
816 init_idedisk_capacity (drive); 829 init_idedisk_capacity(drive);
817 830
818 /* limit drive capacity to 137GB if LBA48 cannot be used */ 831 /* limit drive capacity to 137GB if LBA48 cannot be used */
819 if (drive->addressing == 0 && drive->capacity64 > 1ULL << 28) { 832 if (drive->addressing == 0 && drive->capacity64 > 1ULL << 28) {
@@ -826,9 +839,9 @@ static void idedisk_setup (ide_drive_t *drive)
826 839
827 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && drive->addressing) { 840 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && drive->addressing) {
828 if (drive->capacity64 > 1ULL << 28) { 841 if (drive->capacity64 > 1ULL << 28) {
829 printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode will" 842 printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
830 " be used for accessing sectors > %u\n", 843 " will be used for accessing sectors "
831 drive->name, 1 << 28); 844 "> %u\n", drive->name, 1 << 28);
832 } else 845 } else
833 drive->addressing = 0; 846 drive->addressing = 0;
834 } 847 }
@@ -837,7 +850,8 @@ static void idedisk_setup (ide_drive_t *drive)
837 * if possible, give fdisk access to more of the drive, 850 * if possible, give fdisk access to more of the drive,
838 * by correcting bios_cyls: 851 * by correcting bios_cyls:
839 */ 852 */
840 capacity = idedisk_capacity (drive); 853 capacity = idedisk_capacity(drive);
854
841 if (!drive->forced_geom) { 855 if (!drive->forced_geom) {
842 856
843 if (idedisk_supports_lba48(drive->id)) { 857 if (idedisk_supports_lba48(drive->id)) {
@@ -993,7 +1007,8 @@ static int idedisk_open(struct inode *inode, struct file *filp)
993 struct ide_disk_obj *idkp; 1007 struct ide_disk_obj *idkp;
994 ide_drive_t *drive; 1008 ide_drive_t *drive;
995 1009
996 if (!(idkp = ide_disk_get(disk))) 1010 idkp = ide_disk_get(disk);
1011 if (idkp == NULL)
997 return -ENXIO; 1012 return -ENXIO;
998 1013
999 drive = idkp->drive; 1014 drive = idkp->drive;
@@ -1115,13 +1130,13 @@ static int idedisk_revalidate_disk(struct gendisk *disk)
1115} 1130}
1116 1131
1117static struct block_device_operations idedisk_ops = { 1132static struct block_device_operations idedisk_ops = {
1118 .owner = THIS_MODULE, 1133 .owner = THIS_MODULE,
1119 .open = idedisk_open, 1134 .open = idedisk_open,
1120 .release = idedisk_release, 1135 .release = idedisk_release,
1121 .ioctl = idedisk_ioctl, 1136 .ioctl = idedisk_ioctl,
1122 .getgeo = idedisk_getgeo, 1137 .getgeo = idedisk_getgeo,
1123 .media_changed = idedisk_media_changed, 1138 .media_changed = idedisk_media_changed,
1124 .revalidate_disk= idedisk_revalidate_disk 1139 .revalidate_disk = idedisk_revalidate_disk
1125}; 1140};
1126 1141
1127MODULE_DESCRIPTION("ATA DISK Driver"); 1142MODULE_DESCRIPTION("ATA DISK Driver");
@@ -1184,7 +1199,7 @@ failed:
1184 return -ENODEV; 1199 return -ENODEV;
1185} 1200}
1186 1201
1187static void __exit idedisk_exit (void) 1202static void __exit idedisk_exit(void)
1188{ 1203{
1189 driver_unregister(&idedisk_driver.gen_driver); 1204 driver_unregister(&idedisk_driver.gen_driver);
1190} 1205}
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index d61e5788d310..8757e5ef6c95 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -703,17 +703,8 @@ static int ide_tune_dma(ide_drive_t *drive)
703 703
704 speed = ide_max_dma_mode(drive); 704 speed = ide_max_dma_mode(drive);
705 705
706 if (!speed) { 706 if (!speed)
707 /* is this really correct/needed? */ 707 return 0;
708 if ((hwif->host_flags & IDE_HFLAG_CY82C693) &&
709 ide_dma_good_drive(drive))
710 return 1;
711 else
712 return 0;
713 }
714
715 if (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)
716 return 1;
717 708
718 if (ide_set_dma_mode(drive, speed)) 709 if (ide_set_dma_mode(drive, speed))
719 return 0; 710 return 0;
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index 5f133dfb541c..ed19a8bbd2d2 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -396,7 +396,7 @@ static void idefloppy_retry_pc(ide_drive_t *drive)
396} 396}
397 397
398/* The usual interrupt handler called during a packet command. */ 398/* The usual interrupt handler called during a packet command. */
399static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive) 399static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive)
400{ 400{
401 idefloppy_floppy_t *floppy = drive->driver_data; 401 idefloppy_floppy_t *floppy = drive->driver_data;
402 ide_hwif_t *hwif = drive->hwif; 402 ide_hwif_t *hwif = drive->hwif;
@@ -1596,13 +1596,13 @@ static int idefloppy_revalidate_disk(struct gendisk *disk)
1596} 1596}
1597 1597
1598static struct block_device_operations idefloppy_ops = { 1598static struct block_device_operations idefloppy_ops = {
1599 .owner = THIS_MODULE, 1599 .owner = THIS_MODULE,
1600 .open = idefloppy_open, 1600 .open = idefloppy_open,
1601 .release = idefloppy_release, 1601 .release = idefloppy_release,
1602 .ioctl = idefloppy_ioctl, 1602 .ioctl = idefloppy_ioctl,
1603 .getgeo = idefloppy_getgeo, 1603 .getgeo = idefloppy_getgeo,
1604 .media_changed = idefloppy_media_changed, 1604 .media_changed = idefloppy_media_changed,
1605 .revalidate_disk= idefloppy_revalidate_disk 1605 .revalidate_disk = idefloppy_revalidate_disk
1606}; 1606};
1607 1607
1608static int ide_floppy_probe(ide_drive_t *drive) 1608static int ide_floppy_probe(ide_drive_t *drive)
diff --git a/drivers/ide/ide-generic.c b/drivers/ide/ide-generic.c
index 25fda0a3263f..19f63e393d18 100644
--- a/drivers/ide/ide-generic.c
+++ b/drivers/ide/ide-generic.c
@@ -33,7 +33,7 @@ static ssize_t store_add(struct class *cls, const char *buf, size_t n)
33 if (sscanf(buf, "%x:%x:%d", &base, &ctl, &irq) != 3) 33 if (sscanf(buf, "%x:%x:%d", &base, &ctl, &irq) != 3)
34 return -EINVAL; 34 return -EINVAL;
35 35
36 hwif = ide_find_port(base); 36 hwif = ide_find_port();
37 if (hwif == NULL) 37 if (hwif == NULL)
38 return -ENOENT; 38 return -ENOENT;
39 39
@@ -90,11 +90,21 @@ static int __init ide_generic_init(void)
90 int i; 90 int i;
91 91
92 for (i = 0; i < MAX_HWIFS; i++) { 92 for (i = 0; i < MAX_HWIFS; i++) {
93 ide_hwif_t *hwif = &ide_hwifs[i]; 93 ide_hwif_t *hwif;
94 unsigned long io_addr = ide_default_io_base(i); 94 unsigned long io_addr = ide_default_io_base(i);
95 hw_regs_t hw; 95 hw_regs_t hw;
96 96
97 if (hwif->chipset == ide_unknown && io_addr) { 97 if (io_addr) {
98 /*
99 * Skip probing if the corresponding
100 * slot is already occupied.
101 */
102 hwif = ide_find_port();
103 if (hwif == NULL || hwif->index != i) {
104 idx[i] = 0xff;
105 continue;
106 }
107
98 memset(&hw, 0, sizeof(hw)); 108 memset(&hw, 0, sizeof(hw));
99 ide_std_init_ports(&hw, io_addr, io_addr + 0x206); 109 ide_std_init_ports(&hw, io_addr, io_addr + 0x206);
100 hw.irq = ide_default_irq(io_addr); 110 hw.irq = ide_default_irq(io_addr);
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 31e5afadb7e9..51d181ee9cf7 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -726,10 +726,6 @@ static ide_startstop_t do_special (ide_drive_t *drive)
726 s->b.set_tune = 0; 726 s->b.set_tune = 0;
727 727
728 if (set_pio_mode_abuse(drive->hwif, req_pio)) { 728 if (set_pio_mode_abuse(drive->hwif, req_pio)) {
729
730 if (hwif->set_pio_mode == NULL)
731 return ide_stopped;
732
733 /* 729 /*
734 * take ide_lock for drive->[no_]unmask/[no_]io_32bit 730 * take ide_lock for drive->[no_]unmask/[no_]io_32bit
735 */ 731 */
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 7031a8dcf692..c859de77aa8f 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -274,16 +274,6 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode)
274 if (overridden) 274 if (overridden)
275 printk(KERN_INFO "%s: tPIO > 2, assuming tPIO = 2\n", 275 printk(KERN_INFO "%s: tPIO > 2, assuming tPIO = 2\n",
276 drive->name); 276 drive->name);
277
278 /*
279 * Conservative "downgrade" for all pre-ATA2 drives
280 */
281 if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_DOWNGRADE) == 0 &&
282 pio_mode && pio_mode < 4) {
283 pio_mode--;
284 printk(KERN_INFO "%s: applying conservative "
285 "PIO \"downgrade\"\n", drive->name);
286 }
287 } 277 }
288 278
289 if (pio_mode > max_mode) 279 if (pio_mode > max_mode)
@@ -300,7 +290,8 @@ void ide_set_pio(ide_drive_t *drive, u8 req_pio)
300 ide_hwif_t *hwif = drive->hwif; 290 ide_hwif_t *hwif = drive->hwif;
301 u8 host_pio, pio; 291 u8 host_pio, pio;
302 292
303 if (hwif->set_pio_mode == NULL) 293 if (hwif->set_pio_mode == NULL ||
294 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
304 return; 295 return;
305 296
306 BUG_ON(hwif->pio_mask == 0x00); 297 BUG_ON(hwif->pio_mask == 0x00);
@@ -353,6 +344,9 @@ int ide_set_pio_mode(ide_drive_t *drive, const u8 mode)
353{ 344{
354 ide_hwif_t *hwif = drive->hwif; 345 ide_hwif_t *hwif = drive->hwif;
355 346
347 if (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)
348 return 0;
349
356 if (hwif->set_pio_mode == NULL) 350 if (hwif->set_pio_mode == NULL)
357 return -1; 351 return -1;
358 352
@@ -380,6 +374,9 @@ int ide_set_dma_mode(ide_drive_t *drive, const u8 mode)
380{ 374{
381 ide_hwif_t *hwif = drive->hwif; 375 ide_hwif_t *hwif = drive->hwif;
382 376
377 if (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)
378 return 0;
379
383 if (hwif->set_dma_mode == NULL) 380 if (hwif->set_dma_mode == NULL)
384 return -1; 381 return -1;
385 382
@@ -410,7 +407,8 @@ int ide_set_xfer_rate(ide_drive_t *drive, u8 rate)
410{ 407{
411 ide_hwif_t *hwif = drive->hwif; 408 ide_hwif_t *hwif = drive->hwif;
412 409
413 if (hwif->set_dma_mode == NULL) 410 if (hwif->set_dma_mode == NULL ||
411 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
414 return -1; 412 return -1;
415 413
416 rate = ide_rate_filter(drive, rate); 414 rate = ide_rate_filter(drive, rate);
diff --git a/drivers/ide/ide-pnp.c b/drivers/ide/ide-pnp.c
index 34c2ad36ce54..8a178a55a027 100644
--- a/drivers/ide/ide-pnp.c
+++ b/drivers/ide/ide-pnp.c
@@ -11,7 +11,7 @@
11 * 11 *
12 * You should have received a copy of the GNU General Public License 12 * You should have received a copy of the GNU General Public License
13 * (for example /usr/src/linux/COPYING); if not, write to the Free 13 * (for example /usr/src/linux/COPYING); if not, write to the Free
14 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 14 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */ 15 */
16 16
17#include <linux/init.h> 17#include <linux/init.h>
@@ -20,12 +20,12 @@
20 20
21/* Add your devices here :)) */ 21/* Add your devices here :)) */
22static struct pnp_device_id idepnp_devices[] = { 22static struct pnp_device_id idepnp_devices[] = {
23 /* Generic ESDI/IDE/ATA compatible hard disk controller */ 23 /* Generic ESDI/IDE/ATA compatible hard disk controller */
24 {.id = "PNP0600", .driver_data = 0}, 24 {.id = "PNP0600", .driver_data = 0},
25 {.id = ""} 25 {.id = ""}
26}; 26};
27 27
28static int idepnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id) 28static int idepnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
29{ 29{
30 hw_regs_t hw; 30 hw_regs_t hw;
31 ide_hwif_t *hwif; 31 ide_hwif_t *hwif;
@@ -38,7 +38,7 @@ static int idepnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id
38 pnp_port_start(dev, 1)); 38 pnp_port_start(dev, 1));
39 hw.irq = pnp_irq(dev, 0); 39 hw.irq = pnp_irq(dev, 0);
40 40
41 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); 41 hwif = ide_find_port();
42 if (hwif) { 42 if (hwif) {
43 u8 index = hwif->index; 43 u8 index = hwif->index;
44 u8 idx[4] = { index, 0xff, 0xff, 0xff }; 44 u8 idx[4] = { index, 0xff, 0xff, 0xff };
@@ -47,7 +47,7 @@ static int idepnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id
47 ide_init_port_hw(hwif, &hw); 47 ide_init_port_hw(hwif, &hw);
48 48
49 printk(KERN_INFO "ide%d: generic PnP IDE interface\n", index); 49 printk(KERN_INFO "ide%d: generic PnP IDE interface\n", index);
50 pnp_set_drvdata(dev,hwif); 50 pnp_set_drvdata(dev, hwif);
51 51
52 ide_device_add(idx, NULL); 52 ide_device_add(idx, NULL);
53 53
@@ -57,7 +57,7 @@ static int idepnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id
57 return -1; 57 return -1;
58} 58}
59 59
60static void idepnp_remove(struct pnp_dev * dev) 60static void idepnp_remove(struct pnp_dev *dev)
61{ 61{
62 ide_hwif_t *hwif = pnp_get_drvdata(dev); 62 ide_hwif_t *hwif = pnp_get_drvdata(dev);
63 63
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 6a196c27b0aa..875429728021 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -1444,6 +1444,54 @@ static int ide_sysfs_register_port(ide_hwif_t *hwif)
1444 return rc; 1444 return rc;
1445} 1445}
1446 1446
1447/**
1448 * ide_find_port_slot - find free ide_hwifs[] slot
1449 * @d: IDE port info
1450 *
1451 * Return the new hwif. If we are out of free slots return NULL.
1452 */
1453
1454ide_hwif_t *ide_find_port_slot(const struct ide_port_info *d)
1455{
1456 ide_hwif_t *hwif;
1457 int i;
1458 u8 bootable = (d && (d->host_flags & IDE_HFLAG_NON_BOOTABLE)) ? 0 : 1;
1459
1460 /*
1461 * Claim an unassigned slot.
1462 *
1463 * Give preference to claiming other slots before claiming ide0/ide1,
1464 * just in case there's another interface yet-to-be-scanned
1465 * which uses ports 0x1f0/0x170 (the ide0/ide1 defaults).
1466 *
1467 * Unless there is a bootable card that does not use the standard
1468 * ports 0x1f0/0x170 (the ide0/ide1 defaults).
1469 */
1470 if (bootable) {
1471 i = (d && (d->host_flags & IDE_HFLAG_QD_2ND_PORT)) ? 1 : 0;
1472
1473 for (; i < MAX_HWIFS; i++) {
1474 hwif = &ide_hwifs[i];
1475 if (hwif->chipset == ide_unknown)
1476 return hwif;
1477 }
1478 } else {
1479 for (i = 2; i < MAX_HWIFS; i++) {
1480 hwif = &ide_hwifs[i];
1481 if (hwif->chipset == ide_unknown)
1482 return hwif;
1483 }
1484 for (i = 0; i < 2 && i < MAX_HWIFS; i++) {
1485 hwif = &ide_hwifs[i];
1486 if (hwif->chipset == ide_unknown)
1487 return hwif;
1488 }
1489 }
1490
1491 return NULL;
1492}
1493EXPORT_SYMBOL_GPL(ide_find_port_slot);
1494
1447int ide_device_add_all(u8 *idx, const struct ide_port_info *d) 1495int ide_device_add_all(u8 *idx, const struct ide_port_info *d)
1448{ 1496{
1449 ide_hwif_t *hwif, *mate = NULL; 1497 ide_hwif_t *hwif, *mate = NULL;
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index edd7f186dc4d..5d3562b45039 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -47,28 +47,28 @@ static int proc_ide_read_imodel
47 const char *name; 47 const char *name;
48 48
49 switch (hwif->chipset) { 49 switch (hwif->chipset) {
50 case ide_generic: name = "generic"; break; 50 case ide_generic: name = "generic"; break;
51 case ide_pci: name = "pci"; break; 51 case ide_pci: name = "pci"; break;
52 case ide_cmd640: name = "cmd640"; break; 52 case ide_cmd640: name = "cmd640"; break;
53 case ide_dtc2278: name = "dtc2278"; break; 53 case ide_dtc2278: name = "dtc2278"; break;
54 case ide_ali14xx: name = "ali14xx"; break; 54 case ide_ali14xx: name = "ali14xx"; break;
55 case ide_qd65xx: name = "qd65xx"; break; 55 case ide_qd65xx: name = "qd65xx"; break;
56 case ide_umc8672: name = "umc8672"; break; 56 case ide_umc8672: name = "umc8672"; break;
57 case ide_ht6560b: name = "ht6560b"; break; 57 case ide_ht6560b: name = "ht6560b"; break;
58 case ide_rz1000: name = "rz1000"; break; 58 case ide_rz1000: name = "rz1000"; break;
59 case ide_trm290: name = "trm290"; break; 59 case ide_trm290: name = "trm290"; break;
60 case ide_cmd646: name = "cmd646"; break; 60 case ide_cmd646: name = "cmd646"; break;
61 case ide_cy82c693: name = "cy82c693"; break; 61 case ide_cy82c693: name = "cy82c693"; break;
62 case ide_4drives: name = "4drives"; break; 62 case ide_4drives: name = "4drives"; break;
63 case ide_pmac: name = "mac-io"; break; 63 case ide_pmac: name = "mac-io"; break;
64 case ide_au1xxx: name = "au1xxx"; break; 64 case ide_au1xxx: name = "au1xxx"; break;
65 case ide_palm3710: name = "palm3710"; break; 65 case ide_palm3710: name = "palm3710"; break;
66 case ide_etrax100: name = "etrax100"; break; 66 case ide_etrax100: name = "etrax100"; break;
67 case ide_acorn: name = "acorn"; break; 67 case ide_acorn: name = "acorn"; break;
68 default: name = "(unknown)"; break; 68 default: name = "(unknown)"; break;
69 } 69 }
70 len = sprintf(page, "%s\n", name); 70 len = sprintf(page, "%s\n", name);
71 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 71 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
72} 72}
73 73
74static int proc_ide_read_mate 74static int proc_ide_read_mate
@@ -81,7 +81,7 @@ static int proc_ide_read_mate
81 len = sprintf(page, "%s\n", hwif->mate->name); 81 len = sprintf(page, "%s\n", hwif->mate->name);
82 else 82 else
83 len = sprintf(page, "(none)\n"); 83 len = sprintf(page, "(none)\n");
84 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 84 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
85} 85}
86 86
87static int proc_ide_read_channel 87static int proc_ide_read_channel
@@ -93,7 +93,7 @@ static int proc_ide_read_channel
93 page[0] = hwif->channel ? '1' : '0'; 93 page[0] = hwif->channel ? '1' : '0';
94 page[1] = '\n'; 94 page[1] = '\n';
95 len = 2; 95 len = 2;
96 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 96 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
97} 97}
98 98
99static int proc_ide_read_identify 99static int proc_ide_read_identify
@@ -120,7 +120,7 @@ static int proc_ide_read_identify
120 len = out - page; 120 len = out - page;
121 } 121 }
122 } 122 }
123 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 123 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
124} 124}
125 125
126/** 126/**
@@ -197,7 +197,7 @@ EXPORT_SYMBOL(ide_add_setting);
197 * The caller must hold the setting semaphore. 197 * The caller must hold the setting semaphore.
198 */ 198 */
199 199
200static void __ide_remove_setting (ide_drive_t *drive, char *name) 200static void __ide_remove_setting(ide_drive_t *drive, char *name)
201{ 201{
202 ide_settings_t **p, *setting; 202 ide_settings_t **p, *setting;
203 203
@@ -205,7 +205,8 @@ static void __ide_remove_setting (ide_drive_t *drive, char *name)
205 205
206 while ((*p) && strcmp((*p)->name, name)) 206 while ((*p) && strcmp((*p)->name, name))
207 p = &((*p)->next); 207 p = &((*p)->next);
208 if ((setting = (*p)) == NULL) 208 setting = (*p);
209 if (setting == NULL)
209 return; 210 return;
210 211
211 (*p) = setting->next; 212 (*p) = setting->next;
@@ -223,7 +224,7 @@ static void __ide_remove_setting (ide_drive_t *drive, char *name)
223 * caller must hold ide_setting_mtx. 224 * caller must hold ide_setting_mtx.
224 */ 225 */
225 226
226static void auto_remove_settings (ide_drive_t *drive) 227static void auto_remove_settings(ide_drive_t *drive)
227{ 228{
228 ide_settings_t *setting; 229 ide_settings_t *setting;
229repeat: 230repeat:
@@ -279,16 +280,16 @@ static int ide_read_setting(ide_drive_t *drive, ide_settings_t *setting)
279 280
280 if ((setting->rw & SETTING_READ)) { 281 if ((setting->rw & SETTING_READ)) {
281 spin_lock_irqsave(&ide_lock, flags); 282 spin_lock_irqsave(&ide_lock, flags);
282 switch(setting->data_type) { 283 switch (setting->data_type) {
283 case TYPE_BYTE: 284 case TYPE_BYTE:
284 val = *((u8 *) setting->data); 285 val = *((u8 *) setting->data);
285 break; 286 break;
286 case TYPE_SHORT: 287 case TYPE_SHORT:
287 val = *((u16 *) setting->data); 288 val = *((u16 *) setting->data);
288 break; 289 break;
289 case TYPE_INT: 290 case TYPE_INT:
290 val = *((u32 *) setting->data); 291 val = *((u32 *) setting->data);
291 break; 292 break;
292 } 293 }
293 spin_unlock_irqrestore(&ide_lock, flags); 294 spin_unlock_irqrestore(&ide_lock, flags);
294 } 295 }
@@ -326,15 +327,15 @@ static int ide_write_setting(ide_drive_t *drive, ide_settings_t *setting, int va
326 if (ide_spin_wait_hwgroup(drive)) 327 if (ide_spin_wait_hwgroup(drive))
327 return -EBUSY; 328 return -EBUSY;
328 switch (setting->data_type) { 329 switch (setting->data_type) {
329 case TYPE_BYTE: 330 case TYPE_BYTE:
330 *((u8 *) setting->data) = val; 331 *((u8 *) setting->data) = val;
331 break; 332 break;
332 case TYPE_SHORT: 333 case TYPE_SHORT:
333 *((u16 *) setting->data) = val; 334 *((u16 *) setting->data) = val;
334 break; 335 break;
335 case TYPE_INT: 336 case TYPE_INT:
336 *((u32 *) setting->data) = val; 337 *((u32 *) setting->data) = val;
337 break; 338 break;
338 } 339 }
339 spin_unlock_irq(&ide_lock); 340 spin_unlock_irq(&ide_lock);
340 return 0; 341 return 0;
@@ -390,7 +391,7 @@ void ide_add_generic_settings (ide_drive_t *drive)
390 391
391static void proc_ide_settings_warn(void) 392static void proc_ide_settings_warn(void)
392{ 393{
393 static int warned = 0; 394 static int warned;
394 395
395 if (warned) 396 if (warned)
396 return; 397 return;
@@ -413,11 +414,12 @@ static int proc_ide_read_settings
413 mutex_lock(&ide_setting_mtx); 414 mutex_lock(&ide_setting_mtx);
414 out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n"); 415 out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
415 out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n"); 416 out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
416 while(setting) { 417 while (setting) {
417 mul_factor = setting->mul_factor; 418 mul_factor = setting->mul_factor;
418 div_factor = setting->div_factor; 419 div_factor = setting->div_factor;
419 out += sprintf(out, "%-24s", setting->name); 420 out += sprintf(out, "%-24s", setting->name);
420 if ((rc = ide_read_setting(drive, setting)) >= 0) 421 rc = ide_read_setting(drive, setting);
422 if (rc >= 0)
421 out += sprintf(out, "%-16d", rc * mul_factor / div_factor); 423 out += sprintf(out, "%-16d", rc * mul_factor / div_factor);
422 else 424 else
423 out += sprintf(out, "%-16s", "write-only"); 425 out += sprintf(out, "%-16s", "write-only");
@@ -431,7 +433,7 @@ static int proc_ide_read_settings
431 } 433 }
432 len = out - page; 434 len = out - page;
433 mutex_unlock(&ide_setting_mtx); 435 mutex_unlock(&ide_setting_mtx);
434 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 436 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
435} 437}
436 438
437#define MAX_LEN 30 439#define MAX_LEN 30
@@ -512,8 +514,7 @@ static int proc_ide_write_settings(struct file *file, const char __user *buffer,
512 514
513 mutex_lock(&ide_setting_mtx); 515 mutex_lock(&ide_setting_mtx);
514 setting = ide_find_setting_by_name(drive, name); 516 setting = ide_find_setting_by_name(drive, name);
515 if (!setting) 517 if (!setting) {
516 {
517 mutex_unlock(&ide_setting_mtx); 518 mutex_unlock(&ide_setting_mtx);
518 goto parse_error; 519 goto parse_error;
519 } 520 }
@@ -533,8 +534,8 @@ parse_error:
533int proc_ide_read_capacity 534int proc_ide_read_capacity
534 (char *page, char **start, off_t off, int count, int *eof, void *data) 535 (char *page, char **start, off_t off, int count, int *eof, void *data)
535{ 536{
536 int len = sprintf(page,"%llu\n", (long long)0x7fffffff); 537 int len = sprintf(page, "%llu\n", (long long)0x7fffffff);
537 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 538 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
538} 539}
539 540
540EXPORT_SYMBOL_GPL(proc_ide_read_capacity); 541EXPORT_SYMBOL_GPL(proc_ide_read_capacity);
@@ -546,13 +547,13 @@ int proc_ide_read_geometry
546 char *out = page; 547 char *out = page;
547 int len; 548 int len;
548 549
549 out += sprintf(out,"physical %d/%d/%d\n", 550 out += sprintf(out, "physical %d/%d/%d\n",
550 drive->cyl, drive->head, drive->sect); 551 drive->cyl, drive->head, drive->sect);
551 out += sprintf(out,"logical %d/%d/%d\n", 552 out += sprintf(out, "logical %d/%d/%d\n",
552 drive->bios_cyl, drive->bios_head, drive->bios_sect); 553 drive->bios_cyl, drive->bios_head, drive->bios_sect);
553 554
554 len = out - page; 555 len = out - page;
555 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 556 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
556} 557}
557 558
558EXPORT_SYMBOL(proc_ide_read_geometry); 559EXPORT_SYMBOL(proc_ide_read_geometry);
@@ -566,7 +567,7 @@ static int proc_ide_read_dmodel
566 567
567 len = sprintf(page, "%.40s\n", 568 len = sprintf(page, "%.40s\n",
568 (id && id->model[0]) ? (char *)id->model : "(none)"); 569 (id && id->model[0]) ? (char *)id->model : "(none)");
569 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 570 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
570} 571}
571 572
572static int proc_ide_read_driver 573static int proc_ide_read_driver
@@ -583,7 +584,7 @@ static int proc_ide_read_driver
583 dev->driver->name, ide_drv->version); 584 dev->driver->name, ide_drv->version);
584 } else 585 } else
585 len = sprintf(page, "ide-default version 0.9.newide\n"); 586 len = sprintf(page, "ide-default version 0.9.newide\n");
586 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 587 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
587} 588}
588 589
589static int ide_replace_subdriver(ide_drive_t *drive, const char *driver) 590static int ide_replace_subdriver(ide_drive_t *drive, const char *driver)
@@ -639,30 +640,26 @@ static int proc_ide_read_media
639 int len; 640 int len;
640 641
641 switch (drive->media) { 642 switch (drive->media) {
642 case ide_disk: media = "disk\n"; 643 case ide_disk: media = "disk\n"; break;
643 break; 644 case ide_cdrom: media = "cdrom\n"; break;
644 case ide_cdrom: media = "cdrom\n"; 645 case ide_tape: media = "tape\n"; break;
645 break; 646 case ide_floppy: media = "floppy\n"; break;
646 case ide_tape: media = "tape\n"; 647 case ide_optical: media = "optical\n"; break;
647 break; 648 default: media = "UNKNOWN\n"; break;
648 case ide_floppy:media = "floppy\n";
649 break;
650 case ide_optical:media = "optical\n";
651 break;
652 default: media = "UNKNOWN\n";
653 break;
654 } 649 }
655 strcpy(page,media); 650 strcpy(page, media);
656 len = strlen(media); 651 len = strlen(media);
657 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 652 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
658} 653}
659 654
660static ide_proc_entry_t generic_drive_entries[] = { 655static ide_proc_entry_t generic_drive_entries[] = {
661 { "driver", S_IFREG|S_IRUGO, proc_ide_read_driver, proc_ide_write_driver }, 656 { "driver", S_IFREG|S_IRUGO, proc_ide_read_driver,
662 { "identify", S_IFREG|S_IRUSR, proc_ide_read_identify, NULL }, 657 proc_ide_write_driver },
663 { "media", S_IFREG|S_IRUGO, proc_ide_read_media, NULL }, 658 { "identify", S_IFREG|S_IRUSR, proc_ide_read_identify, NULL },
664 { "model", S_IFREG|S_IRUGO, proc_ide_read_dmodel, NULL }, 659 { "media", S_IFREG|S_IRUGO, proc_ide_read_media, NULL },
665 { "settings", S_IFREG|S_IRUSR|S_IWUSR,proc_ide_read_settings, proc_ide_write_settings }, 660 { "model", S_IFREG|S_IRUGO, proc_ide_read_dmodel, NULL },
661 { "settings", S_IFREG|S_IRUSR|S_IWUSR, proc_ide_read_settings,
662 proc_ide_write_settings },
666 { NULL, 0, NULL, NULL } 663 { NULL, 0, NULL, NULL }
667}; 664};
668 665
@@ -734,7 +731,6 @@ void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver)
734 spin_unlock_irqrestore(&ide_lock, flags); 731 spin_unlock_irqrestore(&ide_lock, flags);
735 mutex_unlock(&ide_setting_mtx); 732 mutex_unlock(&ide_setting_mtx);
736} 733}
737
738EXPORT_SYMBOL(ide_proc_unregister_driver); 734EXPORT_SYMBOL(ide_proc_unregister_driver);
739 735
740void ide_proc_port_register_devices(ide_hwif_t *hwif) 736void ide_proc_port_register_devices(ide_hwif_t *hwif)
@@ -755,7 +751,7 @@ void ide_proc_port_register_devices(ide_hwif_t *hwif)
755 drive->proc = proc_mkdir(drive->name, parent); 751 drive->proc = proc_mkdir(drive->name, parent);
756 if (drive->proc) 752 if (drive->proc)
757 ide_add_proc_entries(drive->proc, generic_drive_entries, drive); 753 ide_add_proc_entries(drive->proc, generic_drive_entries, drive);
758 sprintf(name,"ide%d/%s", (drive->name[2]-'a')/2, drive->name); 754 sprintf(name, "ide%d/%s", (drive->name[2]-'a')/2, drive->name);
759 ent = proc_symlink(drive->name, proc_ide_root, name); 755 ent = proc_symlink(drive->name, proc_ide_root, name);
760 if (!ent) return; 756 if (!ent) return;
761 } 757 }
@@ -795,7 +791,6 @@ void ide_pci_create_host_proc(const char *name, get_info_t *get_info)
795{ 791{
796 create_proc_info_entry(name, 0, proc_ide_root, get_info); 792 create_proc_info_entry(name, 0, proc_ide_root, get_info);
797} 793}
798
799EXPORT_SYMBOL_GPL(ide_pci_create_host_proc); 794EXPORT_SYMBOL_GPL(ide_pci_create_host_proc);
800#endif 795#endif
801 796
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 917c72dcd33d..d868ca44d033 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -100,13 +100,8 @@ int ide_noacpitfs = 1;
100int ide_noacpionboot = 1; 100int ide_noacpionboot = 1;
101#endif 101#endif
102 102
103/*
104 * This is declared extern in ide.h, for access by other IDE modules:
105 */
106ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */ 103ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */
107 104
108EXPORT_SYMBOL(ide_hwifs);
109
110static void ide_port_init_devices_data(ide_hwif_t *); 105static void ide_port_init_devices_data(ide_hwif_t *);
111 106
112/* 107/*
@@ -232,30 +227,6 @@ static int ide_system_bus_speed(void)
232 return pci_dev_present(pci_default) ? 33 : 50; 227 return pci_dev_present(pci_default) ? 33 : 50;
233} 228}
234 229
235ide_hwif_t * ide_find_port(unsigned long base)
236{
237 ide_hwif_t *hwif;
238 int i;
239
240 for (i = 0; i < MAX_HWIFS; i++) {
241 hwif = &ide_hwifs[i];
242 if (hwif->io_ports[IDE_DATA_OFFSET] == base)
243 goto found;
244 }
245
246 for (i = 0; i < MAX_HWIFS; i++) {
247 hwif = &ide_hwifs[i];
248 if (hwif->chipset == ide_unknown)
249 goto found;
250 }
251
252 hwif = NULL;
253found:
254 return hwif;
255}
256
257EXPORT_SYMBOL_GPL(ide_find_port);
258
259static struct resource* hwif_request_region(ide_hwif_t *hwif, 230static struct resource* hwif_request_region(ide_hwif_t *hwif,
260 unsigned long addr, int num) 231 unsigned long addr, int num)
261{ 232{
@@ -280,29 +251,21 @@ static struct resource* hwif_request_region(ide_hwif_t *hwif,
280int ide_hwif_request_regions(ide_hwif_t *hwif) 251int ide_hwif_request_regions(ide_hwif_t *hwif)
281{ 252{
282 unsigned long addr; 253 unsigned long addr;
283 unsigned int i;
284 254
285 if (hwif->mmio) 255 if (hwif->mmio)
286 return 0; 256 return 0;
257
287 addr = hwif->io_ports[IDE_CONTROL_OFFSET]; 258 addr = hwif->io_ports[IDE_CONTROL_OFFSET];
259
288 if (addr && !hwif_request_region(hwif, addr, 1)) 260 if (addr && !hwif_request_region(hwif, addr, 1))
289 goto control_region_busy; 261 goto control_region_busy;
290 hwif->straight8 = 0; 262
291 addr = hwif->io_ports[IDE_DATA_OFFSET]; 263 addr = hwif->io_ports[IDE_DATA_OFFSET];
292 if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) { 264 BUG_ON((addr | 7) != hwif->io_ports[IDE_STATUS_OFFSET]);
293 if (!hwif_request_region(hwif, addr, 8)) 265
294 goto data_region_busy; 266 if (!hwif_request_region(hwif, addr, 8))
295 hwif->straight8 = 1; 267 goto data_region_busy;
296 return 0; 268
297 }
298 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
299 addr = hwif->io_ports[i];
300 if (!hwif_request_region(hwif, addr, 1)) {
301 while (--i)
302 release_region(addr, 1);
303 goto data_region_busy;
304 }
305 }
306 return 0; 269 return 0;
307 270
308data_region_busy: 271data_region_busy:
@@ -328,19 +291,13 @@ control_region_busy:
328 291
329void ide_hwif_release_regions(ide_hwif_t *hwif) 292void ide_hwif_release_regions(ide_hwif_t *hwif)
330{ 293{
331 u32 i = 0;
332
333 if (hwif->mmio) 294 if (hwif->mmio)
334 return; 295 return;
296
335 if (hwif->io_ports[IDE_CONTROL_OFFSET]) 297 if (hwif->io_ports[IDE_CONTROL_OFFSET])
336 release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1); 298 release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
337 if (hwif->straight8) { 299
338 release_region(hwif->io_ports[IDE_DATA_OFFSET], 8); 300 release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
339 return;
340 }
341 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
342 if (hwif->io_ports[i])
343 release_region(hwif->io_ports[i], 1);
344} 301}
345 302
346void ide_remove_port_from_hwgroup(ide_hwif_t *hwif) 303void ide_remove_port_from_hwgroup(ide_hwif_t *hwif)
@@ -627,11 +584,13 @@ out:
627int set_pio_mode(ide_drive_t *drive, int arg) 584int set_pio_mode(ide_drive_t *drive, int arg)
628{ 585{
629 struct request rq; 586 struct request rq;
587 ide_hwif_t *hwif = drive->hwif;
630 588
631 if (arg < 0 || arg > 255) 589 if (arg < 0 || arg > 255)
632 return -EINVAL; 590 return -EINVAL;
633 591
634 if (drive->hwif->set_pio_mode == NULL) 592 if (hwif->set_pio_mode == NULL ||
593 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
635 return -ENOSYS; 594 return -ENOSYS;
636 595
637 if (drive->special.b.set_tune) 596 if (drive->special.b.set_tune)
diff --git a/drivers/ide/legacy/ali14xx.c b/drivers/ide/legacy/ali14xx.c
index bc8b1f8de614..33bb7b87be5d 100644
--- a/drivers/ide/legacy/ali14xx.c
+++ b/drivers/ide/legacy/ali14xx.c
@@ -86,7 +86,7 @@ static u8 regOff; /* output to base port to close registers */
86/* 86/*
87 * Read a controller register. 87 * Read a controller register.
88 */ 88 */
89static inline u8 inReg (u8 reg) 89static inline u8 inReg(u8 reg)
90{ 90{
91 outb_p(reg, regPort); 91 outb_p(reg, regPort);
92 return inb(dataPort); 92 return inb(dataPort);
@@ -95,7 +95,7 @@ static inline u8 inReg (u8 reg)
95/* 95/*
96 * Write a controller register. 96 * Write a controller register.
97 */ 97 */
98static void outReg (u8 data, u8 reg) 98static void outReg(u8 data, u8 reg)
99{ 99{
100 outb_p(reg, regPort); 100 outb_p(reg, regPort);
101 outb_p(data, dataPort); 101 outb_p(data, dataPort);
@@ -143,7 +143,7 @@ static void ali14xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
143/* 143/*
144 * Auto-detect the IDE controller port. 144 * Auto-detect the IDE controller port.
145 */ 145 */
146static int __init findPort (void) 146static int __init findPort(void)
147{ 147{
148 int i; 148 int i;
149 u8 t; 149 u8 t;
@@ -175,7 +175,8 @@ static int __init findPort (void)
175/* 175/*
176 * Initialize controller registers with default values. 176 * Initialize controller registers with default values.
177 */ 177 */
178static int __init initRegisters (void) { 178static int __init initRegisters(void)
179{
179 const RegInitializer *p; 180 const RegInitializer *p;
180 u8 t; 181 u8 t;
181 unsigned long flags; 182 unsigned long flags;
@@ -199,7 +200,8 @@ static const struct ide_port_info ali14xx_port_info = {
199 200
200static int __init ali14xx_probe(void) 201static int __init ali14xx_probe(void)
201{ 202{
202 static u8 idx[4] = { 0, 1, 0xff, 0xff }; 203 ide_hwif_t *hwif, *mate;
204 static u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
203 hw_regs_t hw[2]; 205 hw_regs_t hw[2];
204 206
205 printk(KERN_DEBUG "ali14xx: base=0x%03x, regOn=0x%02x.\n", 207 printk(KERN_DEBUG "ali14xx: base=0x%03x, regOn=0x%02x.\n",
@@ -219,18 +221,26 @@ static int __init ali14xx_probe(void)
219 ide_std_init_ports(&hw[1], 0x170, 0x376); 221 ide_std_init_ports(&hw[1], 0x170, 0x376);
220 hw[1].irq = 15; 222 hw[1].irq = 15;
221 223
222 ide_init_port_hw(&ide_hwifs[0], &hw[0]); 224 hwif = ide_find_port();
223 ide_init_port_hw(&ide_hwifs[1], &hw[1]); 225 if (hwif) {
226 ide_init_port_hw(hwif, &hw[0]);
227 hwif->set_pio_mode = &ali14xx_set_pio_mode;
228 idx[0] = hwif->index;
229 }
224 230
225 ide_hwifs[0].set_pio_mode = &ali14xx_set_pio_mode; 231 mate = ide_find_port();
226 ide_hwifs[1].set_pio_mode = &ali14xx_set_pio_mode; 232 if (mate) {
233 ide_init_port_hw(mate, &hw[1]);
234 mate->set_pio_mode = &ali14xx_set_pio_mode;
235 idx[1] = mate->index;
236 }
227 237
228 ide_device_add(idx, &ali14xx_port_info); 238 ide_device_add(idx, &ali14xx_port_info);
229 239
230 return 0; 240 return 0;
231} 241}
232 242
233int probe_ali14xx = 0; 243int probe_ali14xx;
234 244
235module_param_named(probe, probe_ali14xx, bool, 0); 245module_param_named(probe, probe_ali14xx, bool, 0);
236MODULE_PARM_DESC(probe, "probe for ALI M14xx chipsets"); 246MODULE_PARM_DESC(probe, "probe for ALI M14xx chipsets");
diff --git a/drivers/ide/legacy/buddha.c b/drivers/ide/legacy/buddha.c
index fdd3791e465f..6956eb8f2d5f 100644
--- a/drivers/ide/legacy/buddha.c
+++ b/drivers/ide/legacy/buddha.c
@@ -221,7 +221,7 @@ fail_base2:
221 221
222 buddha_setup_ports(&hw, base, ctl, irq_port, ack_intr); 222 buddha_setup_ports(&hw, base, ctl, irq_port, ack_intr);
223 223
224 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); 224 hwif = ide_find_port();
225 if (hwif) { 225 if (hwif) {
226 u8 index = hwif->index; 226 u8 index = hwif->index;
227 227
diff --git a/drivers/ide/legacy/dtc2278.c b/drivers/ide/legacy/dtc2278.c
index 5f69cd2ea6f7..9c6b3249a004 100644
--- a/drivers/ide/legacy/dtc2278.c
+++ b/drivers/ide/legacy/dtc2278.c
@@ -102,15 +102,9 @@ static int __init dtc2278_probe(void)
102{ 102{
103 unsigned long flags; 103 unsigned long flags;
104 ide_hwif_t *hwif, *mate; 104 ide_hwif_t *hwif, *mate;
105 static u8 idx[4] = { 0, 1, 0xff, 0xff }; 105 static u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
106 hw_regs_t hw[2]; 106 hw_regs_t hw[2];
107 107
108 hwif = &ide_hwifs[0];
109 mate = &ide_hwifs[1];
110
111 if (hwif->chipset != ide_unknown || mate->chipset != ide_unknown)
112 return 1;
113
114 local_irq_save(flags); 108 local_irq_save(flags);
115 /* 109 /*
116 * This enables the second interface 110 * This enables the second interface
@@ -137,10 +131,18 @@ static int __init dtc2278_probe(void)
137 ide_std_init_ports(&hw[1], 0x170, 0x376); 131 ide_std_init_ports(&hw[1], 0x170, 0x376);
138 hw[1].irq = 15; 132 hw[1].irq = 15;
139 133
140 ide_init_port_hw(hwif, &hw[0]); 134 hwif = ide_find_port();
141 ide_init_port_hw(mate, &hw[1]); 135 if (hwif) {
136 ide_init_port_hw(hwif, &hw[0]);
137 hwif->set_pio_mode = dtc2278_set_pio_mode;
138 idx[0] = hwif->index;
139 }
142 140
143 hwif->set_pio_mode = &dtc2278_set_pio_mode; 141 mate = ide_find_port();
142 if (mate) {
143 ide_init_port_hw(mate, &hw[1]);
144 idx[1] = mate->index;
145 }
144 146
145 ide_device_add(idx, &dtc2278_port_info); 147 ide_device_add(idx, &dtc2278_port_info);
146 148
diff --git a/drivers/ide/legacy/falconide.c b/drivers/ide/legacy/falconide.c
index e950afa5939c..8c9c9f7f54ca 100644
--- a/drivers/ide/legacy/falconide.c
+++ b/drivers/ide/legacy/falconide.c
@@ -22,6 +22,7 @@
22#include <asm/atariints.h> 22#include <asm/atariints.h>
23#include <asm/atari_stdma.h> 23#include <asm/atari_stdma.h>
24 24
25#define DRV_NAME "falconide"
25 26
26 /* 27 /*
27 * Base of the IDE interface 28 * Base of the IDE interface
@@ -74,15 +75,21 @@ static int __init falconide_init(void)
74 75
75 printk(KERN_INFO "ide: Falcon IDE controller\n"); 76 printk(KERN_INFO "ide: Falcon IDE controller\n");
76 77
78 if (!request_mem_region(ATA_HD_BASE, 0x40, DRV_NAME)) {
79 printk(KERN_ERR "%s: resources busy\n", DRV_NAME);
80 return -EBUSY;
81 }
82
77 falconide_setup_ports(&hw); 83 falconide_setup_ports(&hw);
78 84
79 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); 85 hwif = ide_find_port();
80 if (hwif) { 86 if (hwif) {
81 u8 index = hwif->index; 87 u8 index = hwif->index;
82 u8 idx[4] = { index, 0xff, 0xff, 0xff }; 88 u8 idx[4] = { index, 0xff, 0xff, 0xff };
83 89
84 ide_init_port_data(hwif, index); 90 ide_init_port_data(hwif, index);
85 ide_init_port_hw(hwif, &hw); 91 ide_init_port_hw(hwif, &hw);
92 hwif->mmio = 1;
86 93
87 ide_get_lock(NULL, NULL); 94 ide_get_lock(NULL, NULL);
88 ide_device_add(idx, NULL); 95 ide_device_add(idx, NULL);
diff --git a/drivers/ide/legacy/gayle.c b/drivers/ide/legacy/gayle.c
index e3b4638cc883..fcc8d52bf2a1 100644
--- a/drivers/ide/legacy/gayle.c
+++ b/drivers/ide/legacy/gayle.c
@@ -175,7 +175,7 @@ found:
175 175
176 gayle_setup_ports(&hw, base, ctrlport, irqport, ack_intr); 176 gayle_setup_ports(&hw, base, ctrlport, irqport, ack_intr);
177 177
178 hwif = ide_find_port(base); 178 hwif = ide_find_port();
179 if (hwif) { 179 if (hwif) {
180 u8 index = hwif->index; 180 u8 index = hwif->index;
181 181
diff --git a/drivers/ide/legacy/hd.c b/drivers/ide/legacy/hd.c
index 0b0d86731927..abdedf56643e 100644
--- a/drivers/ide/legacy/hd.c
+++ b/drivers/ide/legacy/hd.c
@@ -122,12 +122,12 @@ static int hd_error;
122 * This struct defines the HD's and their types. 122 * This struct defines the HD's and their types.
123 */ 123 */
124struct hd_i_struct { 124struct hd_i_struct {
125 unsigned int head,sect,cyl,wpcom,lzone,ctl; 125 unsigned int head, sect, cyl, wpcom, lzone, ctl;
126 int unit; 126 int unit;
127 int recalibrate; 127 int recalibrate;
128 int special_op; 128 int special_op;
129}; 129};
130 130
131#ifdef HD_TYPE 131#ifdef HD_TYPE
132static struct hd_i_struct hd_info[] = { HD_TYPE }; 132static struct hd_i_struct hd_info[] = { HD_TYPE };
133static int NR_HD = ARRAY_SIZE(hd_info); 133static int NR_HD = ARRAY_SIZE(hd_info);
@@ -168,7 +168,7 @@ unsigned long read_timer(void)
168 168
169 spin_lock_irqsave(&i8253_lock, flags); 169 spin_lock_irqsave(&i8253_lock, flags);
170 t = jiffies * 11932; 170 t = jiffies * 11932;
171 outb_p(0, 0x43); 171 outb_p(0, 0x43);
172 i = inb_p(0x40); 172 i = inb_p(0x40);
173 i |= inb(0x40) << 8; 173 i |= inb(0x40) << 8;
174 spin_unlock_irqrestore(&i8253_lock, flags); 174 spin_unlock_irqrestore(&i8253_lock, flags);
@@ -183,7 +183,7 @@ static void __init hd_setup(char *str, int *ints)
183 if (ints[0] != 3) 183 if (ints[0] != 3)
184 return; 184 return;
185 if (hd_info[0].head != 0) 185 if (hd_info[0].head != 0)
186 hdind=1; 186 hdind = 1;
187 hd_info[hdind].head = ints[2]; 187 hd_info[hdind].head = ints[2];
188 hd_info[hdind].sect = ints[3]; 188 hd_info[hdind].sect = ints[3];
189 hd_info[hdind].cyl = ints[1]; 189 hd_info[hdind].cyl = ints[1];
@@ -193,7 +193,7 @@ static void __init hd_setup(char *str, int *ints)
193 NR_HD = hdind+1; 193 NR_HD = hdind+1;
194} 194}
195 195
196static void dump_status (const char *msg, unsigned int stat) 196static void dump_status(const char *msg, unsigned int stat)
197{ 197{
198 char *name = "hd?"; 198 char *name = "hd?";
199 if (CURRENT) 199 if (CURRENT)
@@ -291,7 +291,6 @@ static int controller_ready(unsigned int drive, unsigned int head)
291 return 0; 291 return 0;
292} 292}
293 293
294
295static void hd_out(struct hd_i_struct *disk, 294static void hd_out(struct hd_i_struct *disk,
296 unsigned int nsect, 295 unsigned int nsect,
297 unsigned int sect, 296 unsigned int sect,
@@ -313,15 +312,15 @@ static void hd_out(struct hd_i_struct *disk,
313 return; 312 return;
314 } 313 }
315 SET_HANDLER(intr_addr); 314 SET_HANDLER(intr_addr);
316 outb_p(disk->ctl,HD_CMD); 315 outb_p(disk->ctl, HD_CMD);
317 port=HD_DATA; 316 port = HD_DATA;
318 outb_p(disk->wpcom>>2,++port); 317 outb_p(disk->wpcom >> 2, ++port);
319 outb_p(nsect,++port); 318 outb_p(nsect, ++port);
320 outb_p(sect,++port); 319 outb_p(sect, ++port);
321 outb_p(cyl,++port); 320 outb_p(cyl, ++port);
322 outb_p(cyl>>8,++port); 321 outb_p(cyl >> 8, ++port);
323 outb_p(0xA0|(disk->unit<<4)|head,++port); 322 outb_p(0xA0 | (disk->unit << 4) | head, ++port);
324 outb_p(cmd,++port); 323 outb_p(cmd, ++port);
325} 324}
326 325
327static void hd_request (void); 326static void hd_request (void);
@@ -344,14 +343,14 @@ static void reset_controller(void)
344{ 343{
345 int i; 344 int i;
346 345
347 outb_p(4,HD_CMD); 346 outb_p(4, HD_CMD);
348 for(i = 0; i < 1000; i++) barrier(); 347 for (i = 0; i < 1000; i++) barrier();
349 outb_p(hd_info[0].ctl & 0x0f,HD_CMD); 348 outb_p(hd_info[0].ctl & 0x0f, HD_CMD);
350 for(i = 0; i < 1000; i++) barrier(); 349 for (i = 0; i < 1000; i++) barrier();
351 if (drive_busy()) 350 if (drive_busy())
352 printk("hd: controller still busy\n"); 351 printk("hd: controller still busy\n");
353 else if ((hd_error = inb(HD_ERROR)) != 1) 352 else if ((hd_error = inb(HD_ERROR)) != 1)
354 printk("hd: controller reset failed: %02x\n",hd_error); 353 printk("hd: controller reset failed: %02x\n", hd_error);
355} 354}
356 355
357static void reset_hd(void) 356static void reset_hd(void)
@@ -371,8 +370,8 @@ repeat:
371 if (++i < NR_HD) { 370 if (++i < NR_HD) {
372 struct hd_i_struct *disk = &hd_info[i]; 371 struct hd_i_struct *disk = &hd_info[i];
373 disk->special_op = disk->recalibrate = 1; 372 disk->special_op = disk->recalibrate = 1;
374 hd_out(disk,disk->sect,disk->sect,disk->head-1, 373 hd_out(disk, disk->sect, disk->sect, disk->head-1,
375 disk->cyl,WIN_SPECIFY,&reset_hd); 374 disk->cyl, WIN_SPECIFY, &reset_hd);
376 if (reset) 375 if (reset)
377 goto repeat; 376 goto repeat;
378 } else 377 } else
@@ -393,7 +392,7 @@ static void unexpected_hd_interrupt(void)
393 unsigned int stat = inb_p(HD_STATUS); 392 unsigned int stat = inb_p(HD_STATUS);
394 393
395 if (stat & (BUSY_STAT|DRQ_STAT|ECC_STAT|ERR_STAT)) { 394 if (stat & (BUSY_STAT|DRQ_STAT|ECC_STAT|ERR_STAT)) {
396 dump_status ("unexpected interrupt", stat); 395 dump_status("unexpected interrupt", stat);
397 SET_TIMER; 396 SET_TIMER;
398 } 397 }
399} 398}
@@ -453,7 +452,7 @@ static void read_intr(void)
453 return; 452 return;
454ok_to_read: 453ok_to_read:
455 req = CURRENT; 454 req = CURRENT;
456 insw(HD_DATA,req->buffer,256); 455 insw(HD_DATA, req->buffer, 256);
457 req->sector++; 456 req->sector++;
458 req->buffer += 512; 457 req->buffer += 512;
459 req->errors = 0; 458 req->errors = 0;
@@ -507,7 +506,7 @@ ok_to_write:
507 end_request(req, 1); 506 end_request(req, 1);
508 if (i > 0) { 507 if (i > 0) {
509 SET_HANDLER(&write_intr); 508 SET_HANDLER(&write_intr);
510 outsw(HD_DATA,req->buffer,256); 509 outsw(HD_DATA, req->buffer, 256);
511 local_irq_enable(); 510 local_irq_enable();
512 } else { 511 } else {
513#if (HD_DELAY > 0) 512#if (HD_DELAY > 0)
@@ -560,11 +559,11 @@ static int do_special_op(struct hd_i_struct *disk, struct request *req)
560{ 559{
561 if (disk->recalibrate) { 560 if (disk->recalibrate) {
562 disk->recalibrate = 0; 561 disk->recalibrate = 0;
563 hd_out(disk,disk->sect,0,0,0,WIN_RESTORE,&recal_intr); 562 hd_out(disk, disk->sect, 0, 0, 0, WIN_RESTORE, &recal_intr);
564 return reset; 563 return reset;
565 } 564 }
566 if (disk->head > 16) { 565 if (disk->head > 16) {
567 printk ("%s: cannot handle device with more than 16 heads - giving up\n", req->rq_disk->disk_name); 566 printk("%s: cannot handle device with more than 16 heads - giving up\n", req->rq_disk->disk_name);
568 end_request(req, 0); 567 end_request(req, 0);
569 } 568 }
570 disk->special_op = 0; 569 disk->special_op = 0;
@@ -633,19 +632,21 @@ repeat:
633 if (blk_fs_request(req)) { 632 if (blk_fs_request(req)) {
634 switch (rq_data_dir(req)) { 633 switch (rq_data_dir(req)) {
635 case READ: 634 case READ:
636 hd_out(disk,nsect,sec,head,cyl,WIN_READ,&read_intr); 635 hd_out(disk, nsect, sec, head, cyl, WIN_READ,
636 &read_intr);
637 if (reset) 637 if (reset)
638 goto repeat; 638 goto repeat;
639 break; 639 break;
640 case WRITE: 640 case WRITE:
641 hd_out(disk,nsect,sec,head,cyl,WIN_WRITE,&write_intr); 641 hd_out(disk, nsect, sec, head, cyl, WIN_WRITE,
642 &write_intr);
642 if (reset) 643 if (reset)
643 goto repeat; 644 goto repeat;
644 if (wait_DRQ()) { 645 if (wait_DRQ()) {
645 bad_rw_intr(); 646 bad_rw_intr();
646 goto repeat; 647 goto repeat;
647 } 648 }
648 outsw(HD_DATA,req->buffer,256); 649 outsw(HD_DATA, req->buffer, 256);
649 break; 650 break;
650 default: 651 default:
651 printk("unknown hd-command\n"); 652 printk("unknown hd-command\n");
@@ -655,7 +656,7 @@ repeat:
655 } 656 }
656} 657}
657 658
658static void do_hd_request (struct request_queue * q) 659static void do_hd_request(struct request_queue *q)
659{ 660{
660 disable_irq(HD_IRQ); 661 disable_irq(HD_IRQ);
661 hd_request(); 662 hd_request();
@@ -708,12 +709,12 @@ static int __init hd_init(void)
708{ 709{
709 int drive; 710 int drive;
710 711
711 if (register_blkdev(MAJOR_NR,"hd")) 712 if (register_blkdev(MAJOR_NR, "hd"))
712 return -1; 713 return -1;
713 714
714 hd_queue = blk_init_queue(do_hd_request, &hd_lock); 715 hd_queue = blk_init_queue(do_hd_request, &hd_lock);
715 if (!hd_queue) { 716 if (!hd_queue) {
716 unregister_blkdev(MAJOR_NR,"hd"); 717 unregister_blkdev(MAJOR_NR, "hd");
717 return -ENOMEM; 718 return -ENOMEM;
718 } 719 }
719 720
@@ -742,7 +743,7 @@ static int __init hd_init(void)
742 goto out; 743 goto out;
743 } 744 }
744 745
745 for (drive=0 ; drive < NR_HD ; drive++) { 746 for (drive = 0 ; drive < NR_HD ; drive++) {
746 struct gendisk *disk = alloc_disk(64); 747 struct gendisk *disk = alloc_disk(64);
747 struct hd_i_struct *p = &hd_info[drive]; 748 struct hd_i_struct *p = &hd_info[drive];
748 if (!disk) 749 if (!disk)
@@ -756,7 +757,7 @@ static int __init hd_init(void)
756 disk->queue = hd_queue; 757 disk->queue = hd_queue;
757 p->unit = drive; 758 p->unit = drive;
758 hd_gendisk[drive] = disk; 759 hd_gendisk[drive] = disk;
759 printk ("%s: %luMB, CHS=%d/%d/%d\n", 760 printk("%s: %luMB, CHS=%d/%d/%d\n",
760 disk->disk_name, (unsigned long)get_capacity(disk)/2048, 761 disk->disk_name, (unsigned long)get_capacity(disk)/2048,
761 p->cyl, p->head, p->sect); 762 p->cyl, p->head, p->sect);
762 } 763 }
@@ -776,7 +777,7 @@ static int __init hd_init(void)
776 } 777 }
777 778
778 /* Let them fly */ 779 /* Let them fly */
779 for(drive=0; drive < NR_HD; drive++) 780 for (drive = 0; drive < NR_HD; drive++)
780 add_disk(hd_gendisk[drive]); 781 add_disk(hd_gendisk[drive]);
781 782
782 return 0; 783 return 0;
@@ -791,7 +792,7 @@ out1:
791 NR_HD = 0; 792 NR_HD = 0;
792out: 793out:
793 del_timer(&device_timer); 794 del_timer(&device_timer);
794 unregister_blkdev(MAJOR_NR,"hd"); 795 unregister_blkdev(MAJOR_NR, "hd");
795 blk_cleanup_queue(hd_queue); 796 blk_cleanup_queue(hd_queue);
796 return -1; 797 return -1;
797Enomem: 798Enomem:
@@ -800,7 +801,8 @@ Enomem:
800 goto out; 801 goto out;
801} 802}
802 803
803static int __init parse_hd_setup (char *line) { 804static int __init parse_hd_setup(char *line)
805{
804 int ints[6]; 806 int ints[6];
805 807
806 (void) get_options(line, ARRAY_SIZE(ints), ints); 808 (void) get_options(line, ARRAY_SIZE(ints), ints);
diff --git a/drivers/ide/legacy/ht6560b.c b/drivers/ide/legacy/ht6560b.c
index 88fe9070c9c3..60f52f5158c9 100644
--- a/drivers/ide/legacy/ht6560b.c
+++ b/drivers/ide/legacy/ht6560b.c
@@ -35,6 +35,7 @@
35 * Try: http://www.maf.iki.fi/~maf/ht6560b/ 35 * Try: http://www.maf.iki.fi/~maf/ht6560b/
36 */ 36 */
37 37
38#define DRV_NAME "ht6560b"
38#define HT6560B_VERSION "v0.08" 39#define HT6560B_VERSION "v0.08"
39 40
40#include <linux/module.h> 41#include <linux/module.h>
@@ -339,16 +340,13 @@ static const struct ide_port_info ht6560b_port_info __initdata = {
339static int __init ht6560b_init(void) 340static int __init ht6560b_init(void)
340{ 341{
341 ide_hwif_t *hwif, *mate; 342 ide_hwif_t *hwif, *mate;
342 static u8 idx[4] = { 0, 1, 0xff, 0xff }; 343 static u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
343 hw_regs_t hw[2]; 344 hw_regs_t hw[2];
344 345
345 if (probe_ht6560b == 0) 346 if (probe_ht6560b == 0)
346 return -ENODEV; 347 return -ENODEV;
347 348
348 hwif = &ide_hwifs[0]; 349 if (!request_region(HT_CONFIG_PORT, 1, DRV_NAME)) {
349 mate = &ide_hwifs[1];
350
351 if (!request_region(HT_CONFIG_PORT, 1, hwif->name)) {
352 printk(KERN_NOTICE "%s: HT_CONFIG_PORT not found\n", 350 printk(KERN_NOTICE "%s: HT_CONFIG_PORT not found\n",
353 __FUNCTION__); 351 __FUNCTION__);
354 return -ENODEV; 352 return -ENODEV;
@@ -367,17 +365,23 @@ static int __init ht6560b_init(void)
367 ide_std_init_ports(&hw[1], 0x170, 0x376); 365 ide_std_init_ports(&hw[1], 0x170, 0x376);
368 hw[1].irq = 15; 366 hw[1].irq = 15;
369 367
370 ide_init_port_hw(hwif, &hw[0]); 368 hwif = ide_find_port();
371 ide_init_port_hw(mate, &hw[1]); 369 if (hwif) {
372 370 ide_init_port_hw(hwif, &hw[0]);
373 hwif->selectproc = &ht6560b_selectproc; 371 hwif->selectproc = ht6560b_selectproc;
374 hwif->set_pio_mode = &ht6560b_set_pio_mode; 372 hwif->set_pio_mode = ht6560b_set_pio_mode;
375 373 hwif->port_init_devs = ht6560b_port_init_devs;
376 mate->selectproc = &ht6560b_selectproc; 374 idx[0] = hwif->index;
377 mate->set_pio_mode = &ht6560b_set_pio_mode; 375 }
378 376
379 hwif->port_init_devs = ht6560b_port_init_devs; 377 mate = ide_find_port();
380 mate->port_init_devs = ht6560b_port_init_devs; 378 if (mate) {
379 ide_init_port_hw(mate, &hw[1]);
380 mate->selectproc = ht6560b_selectproc;
381 mate->set_pio_mode = ht6560b_set_pio_mode;
382 mate->port_init_devs = ht6560b_port_init_devs;
383 idx[1] = mate->index;
384 }
381 385
382 ide_device_add(idx, &ht6560b_port_info); 386 ide_device_add(idx, &ht6560b_port_info);
383 387
diff --git a/drivers/ide/legacy/ide-4drives.c b/drivers/ide/legacy/ide-4drives.c
index ecd7f3553554..c352f12348af 100644
--- a/drivers/ide/legacy/ide-4drives.c
+++ b/drivers/ide/legacy/ide-4drives.c
@@ -4,7 +4,7 @@
4#include <linux/module.h> 4#include <linux/module.h>
5#include <linux/ide.h> 5#include <linux/ide.h>
6 6
7int probe_4drives = 0; 7int probe_4drives;
8 8
9module_param_named(probe, probe_4drives, bool, 0); 9module_param_named(probe, probe_4drives, bool, 0);
10MODULE_PARM_DESC(probe, "probe for generic IDE chipset with 4 drives/port"); 10MODULE_PARM_DESC(probe, "probe for generic IDE chipset with 4 drives/port");
@@ -12,31 +12,37 @@ MODULE_PARM_DESC(probe, "probe for generic IDE chipset with 4 drives/port");
12static int __init ide_4drives_init(void) 12static int __init ide_4drives_init(void)
13{ 13{
14 ide_hwif_t *hwif, *mate; 14 ide_hwif_t *hwif, *mate;
15 u8 idx[4] = { 0, 1, 0xff, 0xff }; 15 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
16 hw_regs_t hw; 16 hw_regs_t hw;
17 17
18 if (probe_4drives == 0) 18 if (probe_4drives == 0)
19 return -ENODEV; 19 return -ENODEV;
20 20
21 hwif = &ide_hwifs[0];
22 mate = &ide_hwifs[1];
23
24 memset(&hw, 0, sizeof(hw)); 21 memset(&hw, 0, sizeof(hw));
25 22
26 ide_std_init_ports(&hw, 0x1f0, 0x3f6); 23 ide_std_init_ports(&hw, 0x1f0, 0x3f6);
27 hw.irq = 14; 24 hw.irq = 14;
28 hw.chipset = ide_4drives; 25 hw.chipset = ide_4drives;
29 26
30 ide_init_port_hw(hwif, &hw); 27 hwif = ide_find_port();
31 ide_init_port_hw(mate, &hw); 28 if (hwif) {
32 29 ide_init_port_hw(hwif, &hw);
33 mate->drives[0].select.all ^= 0x20; 30 idx[0] = hwif->index;
34 mate->drives[1].select.all ^= 0x20; 31 }
35 32
36 hwif->mate = mate; 33 mate = ide_find_port();
37 mate->mate = hwif; 34 if (mate) {
38 35 ide_init_port_hw(mate, &hw);
39 hwif->serialized = mate->serialized = 1; 36 mate->drives[0].select.all ^= 0x20;
37 mate->drives[1].select.all ^= 0x20;
38 idx[1] = mate->index;
39
40 if (hwif) {
41 hwif->mate = mate;
42 mate->mate = hwif;
43 hwif->serialized = mate->serialized = 1;
44 }
45 }
40 46
41 ide_device_add(idx, NULL); 47 ide_device_add(idx, NULL);
42 48
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index 9a23b94f2939..b97b8d51b3eb 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -156,7 +156,7 @@ static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq
156 hw.chipset = ide_pci; 156 hw.chipset = ide_pci;
157 hw.dev = &handle->dev; 157 hw.dev = &handle->dev;
158 158
159 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); 159 hwif = ide_find_port();
160 if (hwif == NULL) 160 if (hwif == NULL)
161 return -1; 161 return -1;
162 162
diff --git a/drivers/ide/legacy/ide_platform.c b/drivers/ide/legacy/ide_platform.c
index 361b1bb544bf..bf240775531e 100644
--- a/drivers/ide/legacy/ide_platform.c
+++ b/drivers/ide/legacy/ide_platform.c
@@ -89,7 +89,7 @@ static int __devinit plat_ide_probe(struct platform_device *pdev)
89 res_alt->start, res_alt->end - res_alt->start + 1); 89 res_alt->start, res_alt->end - res_alt->start + 1);
90 } 90 }
91 91
92 hwif = ide_find_port((unsigned long)base); 92 hwif = ide_find_port();
93 if (!hwif) { 93 if (!hwif) {
94 ret = -ENODEV; 94 ret = -ENODEV;
95 goto out; 95 goto out;
@@ -100,11 +100,10 @@ static int __devinit plat_ide_probe(struct platform_device *pdev)
100 hw.dev = &pdev->dev; 100 hw.dev = &pdev->dev;
101 101
102 ide_init_port_hw(hwif, &hw); 102 ide_init_port_hw(hwif, &hw);
103 hwif->mmio = 1;
103 104
104 if (mmio) { 105 if (mmio)
105 hwif->mmio = 1;
106 default_hwif_mmiops(hwif); 106 default_hwif_mmiops(hwif);
107 }
108 107
109 idx[0] = hwif->index; 108 idx[0] = hwif->index;
110 109
diff --git a/drivers/ide/legacy/macide.c b/drivers/ide/legacy/macide.c
index eaf5dbe58bc2..7429b80cb089 100644
--- a/drivers/ide/legacy/macide.c
+++ b/drivers/ide/legacy/macide.c
@@ -120,7 +120,7 @@ static int __init macide_init(void)
120 120
121 macide_setup_ports(&hw, base, irq, ack_intr); 121 macide_setup_ports(&hw, base, irq, ack_intr);
122 122
123 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); 123 hwif = ide_find_port();
124 if (hwif) { 124 if (hwif) {
125 u8 index = hwif->index; 125 u8 index = hwif->index;
126 u8 idx[4] = { index, 0xff, 0xff, 0xff }; 126 u8 idx[4] = { index, 0xff, 0xff, 0xff };
diff --git a/drivers/ide/legacy/q40ide.c b/drivers/ide/legacy/q40ide.c
index 2da28759686e..fcbff0eced1b 100644
--- a/drivers/ide/legacy/q40ide.c
+++ b/drivers/ide/legacy/q40ide.c
@@ -137,7 +137,7 @@ static int __init q40ide_init(void)
137// m68kide_iops, 137// m68kide_iops,
138 q40ide_default_irq(pcide_bases[i])); 138 q40ide_default_irq(pcide_bases[i]));
139 139
140 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); 140 hwif = ide_find_port();
141 if (hwif) { 141 if (hwif) {
142 ide_init_port_data(hwif, hwif->index); 142 ide_init_port_data(hwif, hwif->index);
143 ide_init_port_hw(hwif, &hw); 143 ide_init_port_hw(hwif, &hw);
diff --git a/drivers/ide/legacy/qd65xx.c b/drivers/ide/legacy/qd65xx.c
index 7016bdf4fcc1..6e820c7c5c6b 100644
--- a/drivers/ide/legacy/qd65xx.c
+++ b/drivers/ide/legacy/qd65xx.c
@@ -88,12 +88,12 @@
88static int timings[4]={-1,-1,-1,-1}; /* stores current timing for each timer */ 88static int timings[4]={-1,-1,-1,-1}; /* stores current timing for each timer */
89 89
90/* 90/*
91 * qd_select: 91 * qd65xx_select:
92 * 92 *
93 * This routine is invoked from ide.c to prepare for access to a given drive. 93 * This routine is invoked to prepare for access to a given drive.
94 */ 94 */
95 95
96static void qd_select (ide_drive_t *drive) 96static void qd65xx_select(ide_drive_t *drive)
97{ 97{
98 u8 index = (( (QD_TIMREG(drive)) & 0x80 ) >> 7) | 98 u8 index = (( (QD_TIMREG(drive)) & 0x80 ) >> 7) |
99 (QD_TIMREG(drive) & 0x02); 99 (QD_TIMREG(drive) & 0x02);
@@ -168,36 +168,15 @@ static int qd_find_disk_type (ide_drive_t *drive,
168} 168}
169 169
170/* 170/*
171 * qd_timing_ok:
172 *
173 * check whether timings don't conflict
174 */
175
176static int qd_timing_ok (ide_drive_t drives[])
177{
178 return (IDE_IMPLY(drives[0].present && drives[1].present,
179 IDE_IMPLY(QD_TIMREG(drives) == QD_TIMREG(drives+1),
180 QD_TIMING(drives) == QD_TIMING(drives+1))));
181 /* if same timing register, must be same timing */
182}
183
184/*
185 * qd_set_timing: 171 * qd_set_timing:
186 * 172 *
187 * records the timing, and enables selectproc as needed 173 * records the timing
188 */ 174 */
189 175
190static void qd_set_timing (ide_drive_t *drive, u8 timing) 176static void qd_set_timing (ide_drive_t *drive, u8 timing)
191{ 177{
192 ide_hwif_t *hwif = HWIF(drive);
193
194 drive->drive_data &= 0xff00; 178 drive->drive_data &= 0xff00;
195 drive->drive_data |= timing; 179 drive->drive_data |= timing;
196 if (qd_timing_ok(hwif->drives)) {
197 qd_select(drive); /* selects once */
198 hwif->selectproc = NULL;
199 } else
200 hwif->selectproc = &qd_select;
201 180
202 printk(KERN_DEBUG "%s: %#x\n", drive->name, timing); 181 printk(KERN_DEBUG "%s: %#x\n", drive->name, timing);
203} 182}
@@ -225,10 +204,11 @@ static void qd6500_set_pio_mode(ide_drive_t *drive, const u8 pio)
225 204
226static void qd6580_set_pio_mode(ide_drive_t *drive, const u8 pio) 205static void qd6580_set_pio_mode(ide_drive_t *drive, const u8 pio)
227{ 206{
228 int base = HWIF(drive)->select_data; 207 ide_hwif_t *hwif = drive->hwif;
229 unsigned int cycle_time; 208 unsigned int cycle_time;
230 int active_time = 175; 209 int active_time = 175;
231 int recovery_time = 415; /* worst case values from the dos driver */ 210 int recovery_time = 415; /* worst case values from the dos driver */
211 u8 base = (hwif->config_data & 0xff00) >> 8;
232 212
233 if (drive->id && !qd_find_disk_type(drive, &active_time, &recovery_time)) { 213 if (drive->id && !qd_find_disk_type(drive, &active_time, &recovery_time)) {
234 cycle_time = ide_pio_cycle_time(drive, pio); 214 cycle_time = ide_pio_cycle_time(drive, pio);
@@ -299,21 +279,10 @@ static int __init qd_testreg(int port)
299 return (readreg != QD_TESTVAL); 279 return (readreg != QD_TESTVAL);
300} 280}
301 281
302/*
303 * qd_setup:
304 *
305 * called to setup an ata channel : adjusts attributes & links for tuning
306 */
307
308static void __init qd_setup(ide_hwif_t *hwif, int base, int config)
309{
310 hwif->select_data = base;
311 hwif->config_data = config;
312}
313
314static void __init qd6500_port_init_devs(ide_hwif_t *hwif) 282static void __init qd6500_port_init_devs(ide_hwif_t *hwif)
315{ 283{
316 u8 base = hwif->select_data, config = QD_CONFIG(hwif); 284 u8 base = (hwif->config_data & 0xff00) >> 8;
285 u8 config = QD_CONFIG(hwif);
317 286
318 hwif->drives[0].drive_data = QD6500_DEF_DATA; 287 hwif->drives[0].drive_data = QD6500_DEF_DATA;
319 hwif->drives[1].drive_data = QD6500_DEF_DATA; 288 hwif->drives[1].drive_data = QD6500_DEF_DATA;
@@ -322,9 +291,10 @@ static void __init qd6500_port_init_devs(ide_hwif_t *hwif)
322static void __init qd6580_port_init_devs(ide_hwif_t *hwif) 291static void __init qd6580_port_init_devs(ide_hwif_t *hwif)
323{ 292{
324 u16 t1, t2; 293 u16 t1, t2;
325 u8 base = hwif->select_data, config = QD_CONFIG(hwif); 294 u8 base = (hwif->config_data & 0xff00) >> 8;
295 u8 config = QD_CONFIG(hwif);
326 296
327 if (QD_CONTROL(hwif) & QD_CONTR_SEC_DISABLED) { 297 if (hwif->host_flags & IDE_HFLAG_SINGLE) {
328 t1 = QD6580_DEF_DATA; 298 t1 = QD6580_DEF_DATA;
329 t2 = QD6580_DEF_DATA2; 299 t2 = QD6580_DEF_DATA2;
330 } else 300 } else
@@ -355,14 +325,18 @@ static int __init qd_probe(int base)
355 u8 config, unit; 325 u8 config, unit;
356 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; 326 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
357 hw_regs_t hw[2]; 327 hw_regs_t hw[2];
328 struct ide_port_info d = qd65xx_port_info;
358 329
359 config = inb(QD_CONFIG_PORT); 330 config = inb(QD_CONFIG_PORT);
360 331
361 if (! ((config & QD_CONFIG_BASEPORT) >> 1 == (base == 0xb0)) ) 332 if (! ((config & QD_CONFIG_BASEPORT) >> 1 == (base == 0xb0)) )
362 return 1; 333 return -ENODEV;
363 334
364 unit = ! (config & QD_CONFIG_IDE_BASEPORT); 335 unit = ! (config & QD_CONFIG_IDE_BASEPORT);
365 336
337 if (unit)
338 d.host_flags |= IDE_HFLAG_QD_2ND_PORT;
339
366 memset(&hw, 0, sizeof(hw)); 340 memset(&hw, 0, sizeof(hw));
367 341
368 ide_std_init_ports(&hw[0], 0x1f0, 0x3f6); 342 ide_std_init_ports(&hw[0], 0x1f0, 0x3f6);
@@ -373,30 +347,37 @@ static int __init qd_probe(int base)
373 347
374 if ((config & 0xf0) == QD_CONFIG_QD6500) { 348 if ((config & 0xf0) == QD_CONFIG_QD6500) {
375 349
376 if (qd_testreg(base)) return 1; /* bad register */ 350 if (qd_testreg(base))
351 return -ENODEV; /* bad register */
377 352
378 /* qd6500 found */ 353 /* qd6500 found */
379 354
380 hwif = &ide_hwifs[unit];
381 printk(KERN_NOTICE "%s: qd6500 at %#x\n", hwif->name, base);
382 printk(KERN_DEBUG "qd6500: config=%#x, ID3=%u\n",
383 config, QD_ID3);
384
385 if (config & QD_CONFIG_DISABLED) { 355 if (config & QD_CONFIG_DISABLED) {
386 printk(KERN_WARNING "qd6500 is disabled !\n"); 356 printk(KERN_WARNING "qd6500 is disabled !\n");
387 return 1; 357 return -ENODEV;
388 } 358 }
389 359
360 printk(KERN_NOTICE "qd6500 at %#x\n", base);
361 printk(KERN_DEBUG "qd6500: config=%#x, ID3=%u\n",
362 config, QD_ID3);
363
364 d.host_flags |= IDE_HFLAG_SINGLE;
365
366 hwif = ide_find_port_slot(&d);
367 if (hwif == NULL)
368 return -ENOENT;
369
390 ide_init_port_hw(hwif, &hw[unit]); 370 ide_init_port_hw(hwif, &hw[unit]);
391 371
392 qd_setup(hwif, base, config); 372 hwif->config_data = (base << 8) | config;
393 373
394 hwif->port_init_devs = qd6500_port_init_devs; 374 hwif->port_init_devs = qd6500_port_init_devs;
395 hwif->set_pio_mode = &qd6500_set_pio_mode; 375 hwif->set_pio_mode = qd6500_set_pio_mode;
376 hwif->selectproc = qd65xx_select;
396 377
397 idx[unit] = unit; 378 idx[unit] = hwif->index;
398 379
399 ide_device_add(idx, &qd65xx_port_info); 380 ide_device_add(idx, &d);
400 381
401 return 1; 382 return 1;
402 } 383 }
@@ -406,8 +387,8 @@ static int __init qd_probe(int base)
406 387
407 u8 control; 388 u8 control;
408 389
409 if (qd_testreg(base) || qd_testreg(base+0x02)) return 1; 390 if (qd_testreg(base) || qd_testreg(base + 0x02))
410 /* bad registers */ 391 return -ENODEV; /* bad registers */
411 392
412 /* qd6580 found */ 393 /* qd6580 found */
413 394
@@ -422,46 +403,52 @@ static int __init qd_probe(int base)
422 if (control & QD_CONTR_SEC_DISABLED) { 403 if (control & QD_CONTR_SEC_DISABLED) {
423 /* secondary disabled */ 404 /* secondary disabled */
424 405
425 hwif = &ide_hwifs[unit]; 406 printk(KERN_INFO "qd6580: single IDE board\n");
426 printk(KERN_INFO "%s: qd6580: single IDE board\n", 407
427 hwif->name); 408 d.host_flags |= IDE_HFLAG_SINGLE;
409
410 hwif = ide_find_port_slot(&d);
411 if (hwif == NULL)
412 return -ENOENT;
428 413
429 ide_init_port_hw(hwif, &hw[unit]); 414 ide_init_port_hw(hwif, &hw[unit]);
430 415
431 qd_setup(hwif, base, config | (control << 8)); 416 hwif->config_data = (base << 8) | config;
432 417
433 hwif->port_init_devs = qd6580_port_init_devs; 418 hwif->port_init_devs = qd6580_port_init_devs;
434 hwif->set_pio_mode = &qd6580_set_pio_mode; 419 hwif->set_pio_mode = qd6580_set_pio_mode;
420 hwif->selectproc = qd65xx_select;
435 421
436 idx[unit] = unit; 422 idx[unit] = hwif->index;
437 423
438 ide_device_add(idx, &qd65xx_port_info); 424 ide_device_add(idx, &d);
439 425
440 return 1; 426 return 1;
441 } else { 427 } else {
442 ide_hwif_t *mate; 428 ide_hwif_t *mate;
443 429
444 hwif = &ide_hwifs[0];
445 mate = &ide_hwifs[1];
446 /* secondary enabled */ 430 /* secondary enabled */
447 printk(KERN_INFO "%s&%s: qd6580: dual IDE board\n", 431 printk(KERN_INFO "qd6580: dual IDE board\n");
448 hwif->name, mate->name); 432
449 433 hwif = ide_find_port();
450 ide_init_port_hw(hwif, &hw[0]); 434 if (hwif) {
451 ide_init_port_hw(mate, &hw[1]); 435 ide_init_port_hw(hwif, &hw[0]);
452 436 hwif->config_data = (base << 8) | config;
453 qd_setup(hwif, base, config | (control << 8)); 437 hwif->port_init_devs = qd6580_port_init_devs;
454 438 hwif->set_pio_mode = qd6580_set_pio_mode;
455 hwif->port_init_devs = qd6580_port_init_devs; 439 hwif->selectproc = qd65xx_select;
456 hwif->set_pio_mode = &qd6580_set_pio_mode; 440 idx[0] = hwif->index;
457 441 }
458 qd_setup(mate, base, config | (control << 8)); 442
459 443 mate = ide_find_port();
460 mate->port_init_devs = qd6580_port_init_devs; 444 if (mate) {
461 mate->set_pio_mode = &qd6580_set_pio_mode; 445 ide_init_port_hw(mate, &hw[1]);
462 446 mate->config_data = (base << 8) | config;
463 idx[0] = 0; 447 mate->port_init_devs = qd6580_port_init_devs;
464 idx[1] = 1; 448 mate->set_pio_mode = qd6580_set_pio_mode;
449 mate->selectproc = qd65xx_select;
450 idx[1] = mate->index;
451 }
465 452
466 ide_device_add(idx, &qd65xx_port_info); 453 ide_device_add(idx, &qd65xx_port_info);
467 454
@@ -469,7 +456,7 @@ static int __init qd_probe(int base)
469 } 456 }
470 } 457 }
471 /* no qd65xx found */ 458 /* no qd65xx found */
472 return 1; 459 return -ENODEV;
473} 460}
474 461
475int probe_qd65xx = 0; 462int probe_qd65xx = 0;
@@ -479,14 +466,18 @@ MODULE_PARM_DESC(probe, "probe for QD65xx chipsets");
479 466
480static int __init qd65xx_init(void) 467static int __init qd65xx_init(void)
481{ 468{
469 int rc1, rc2 = -ENODEV;
470
482 if (probe_qd65xx == 0) 471 if (probe_qd65xx == 0)
483 return -ENODEV; 472 return -ENODEV;
484 473
485 if (qd_probe(0x30)) 474 rc1 = qd_probe(0x30);
486 qd_probe(0xb0); 475 if (rc1)
487 if (ide_hwifs[0].chipset != ide_qd65xx && 476 rc2 = qd_probe(0xb0);
488 ide_hwifs[1].chipset != ide_qd65xx) 477
478 if (rc1 < 0 && rc2 < 0)
489 return -ENODEV; 479 return -ENODEV;
480
490 return 0; 481 return 0;
491} 482}
492 483
diff --git a/drivers/ide/legacy/qd65xx.h b/drivers/ide/legacy/qd65xx.h
index 28dd50a15d55..c83dea85e621 100644
--- a/drivers/ide/legacy/qd65xx.h
+++ b/drivers/ide/legacy/qd65xx.h
@@ -30,7 +30,6 @@
30#define QD_ID3 ((config & QD_CONFIG_ID3)!=0) 30#define QD_ID3 ((config & QD_CONFIG_ID3)!=0)
31 31
32#define QD_CONFIG(hwif) ((hwif)->config_data & 0x00ff) 32#define QD_CONFIG(hwif) ((hwif)->config_data & 0x00ff)
33#define QD_CONTROL(hwif) (((hwif)->config_data & 0xff00) >> 8)
34 33
35#define QD_TIMING(drive) (byte)(((drive)->drive_data) & 0x00ff) 34#define QD_TIMING(drive) (byte)(((drive)->drive_data) & 0x00ff)
36#define QD_TIMREG(drive) (byte)((((drive)->drive_data) & 0xff00) >> 8) 35#define QD_TIMREG(drive) (byte)((((drive)->drive_data) & 0xff00) >> 8)
diff --git a/drivers/ide/legacy/umc8672.c b/drivers/ide/legacy/umc8672.c
index bc1944811b99..4d90badd2bda 100644
--- a/drivers/ide/legacy/umc8672.c
+++ b/drivers/ide/legacy/umc8672.c
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21/* 21/*
22 * VLB Controller Support from 22 * VLB Controller Support from
23 * Wolfram Podien 23 * Wolfram Podien
24 * Rohoefe 3 24 * Rohoefe 3
25 * D28832 Achim 25 * D28832 Achim
@@ -32,7 +32,7 @@
32 * #define UMC_DRIVE0 11 32 * #define UMC_DRIVE0 11
33 * in the beginning of the driver, which sets the speed of drive 0 to 11 (there 33 * in the beginning of the driver, which sets the speed of drive 0 to 11 (there
34 * are some lines present). 0 - 11 are allowed speed values. These values are 34 * are some lines present). 0 - 11 are allowed speed values. These values are
35 * the results from the DOS speed test program supplied from UMC. 11 is the 35 * the results from the DOS speed test program supplied from UMC. 11 is the
36 * highest speed (about PIO mode 3) 36 * highest speed (about PIO mode 3)
37 */ 37 */
38#define REALLY_SLOW_IO /* some systems can safely undef this */ 38#define REALLY_SLOW_IO /* some systems can safely undef this */
@@ -60,62 +60,62 @@
60#define UMC_DRIVE3 1 /* In case of crash reduce speed */ 60#define UMC_DRIVE3 1 /* In case of crash reduce speed */
61 61
62static u8 current_speeds[4] = {UMC_DRIVE0, UMC_DRIVE1, UMC_DRIVE2, UMC_DRIVE3}; 62static u8 current_speeds[4] = {UMC_DRIVE0, UMC_DRIVE1, UMC_DRIVE2, UMC_DRIVE3};
63static const u8 pio_to_umc [5] = {0,3,7,10,11}; /* rough guesses */ 63static const u8 pio_to_umc [5] = {0, 3, 7, 10, 11}; /* rough guesses */
64 64
65/* 0 1 2 3 4 5 6 7 8 9 10 11 */ 65/* 0 1 2 3 4 5 6 7 8 9 10 11 */
66static const u8 speedtab [3][12] = { 66static const u8 speedtab [3][12] = {
67 {0xf, 0xb, 0x2, 0x2, 0x2, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1 }, 67 {0x0f, 0x0b, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1},
68 {0x3, 0x2, 0x2, 0x2, 0x2, 0x2, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1 }, 68 {0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1},
69 {0xff,0xcb,0xc0,0x58,0x36,0x33,0x23,0x22,0x21,0x11,0x10,0x0}}; 69 {0xff, 0xcb, 0xc0, 0x58, 0x36, 0x33, 0x23, 0x22, 0x21, 0x11, 0x10, 0x0}
70};
70 71
71static void out_umc (char port,char wert) 72static void out_umc(char port, char wert)
72{ 73{
73 outb_p(port,0x108); 74 outb_p(port, 0x108);
74 outb_p(wert,0x109); 75 outb_p(wert, 0x109);
75} 76}
76 77
77static inline u8 in_umc (char port) 78static inline u8 in_umc(char port)
78{ 79{
79 outb_p(port,0x108); 80 outb_p(port, 0x108);
80 return inb_p(0x109); 81 return inb_p(0x109);
81} 82}
82 83
83static void umc_set_speeds (u8 speeds[]) 84static void umc_set_speeds(u8 speeds[])
84{ 85{
85 int i, tmp; 86 int i, tmp;
86 87
87 outb_p(0x5A,0x108); /* enable umc */ 88 outb_p(0x5A, 0x108); /* enable umc */
88 89
89 out_umc (0xd7,(speedtab[0][speeds[2]] | (speedtab[0][speeds[3]]<<4))); 90 out_umc(0xd7, (speedtab[0][speeds[2]] | (speedtab[0][speeds[3]]<<4)));
90 out_umc (0xd6,(speedtab[0][speeds[0]] | (speedtab[0][speeds[1]]<<4))); 91 out_umc(0xd6, (speedtab[0][speeds[0]] | (speedtab[0][speeds[1]]<<4)));
91 tmp = 0; 92 tmp = 0;
92 for (i = 3; i >= 0; i--) { 93 for (i = 3; i >= 0; i--)
93 tmp = (tmp << 2) | speedtab[1][speeds[i]]; 94 tmp = (tmp << 2) | speedtab[1][speeds[i]];
95 out_umc(0xdc, tmp);
96 for (i = 0; i < 4; i++) {
97 out_umc(0xd0 + i, speedtab[2][speeds[i]]);
98 out_umc(0xd8 + i, speedtab[2][speeds[i]]);
94 } 99 }
95 out_umc (0xdc,tmp); 100 outb_p(0xa5, 0x108); /* disable umc */
96 for (i = 0;i < 4; i++) {
97 out_umc (0xd0+i,speedtab[2][speeds[i]]);
98 out_umc (0xd8+i,speedtab[2][speeds[i]]);
99 }
100 outb_p(0xa5,0x108); /* disable umc */
101 101
102 printk ("umc8672: drive speeds [0 to 11]: %d %d %d %d\n", 102 printk("umc8672: drive speeds [0 to 11]: %d %d %d %d\n",
103 speeds[0], speeds[1], speeds[2], speeds[3]); 103 speeds[0], speeds[1], speeds[2], speeds[3]);
104} 104}
105 105
106static void umc_set_pio_mode(ide_drive_t *drive, const u8 pio) 106static void umc_set_pio_mode(ide_drive_t *drive, const u8 pio)
107{ 107{
108 ide_hwif_t *hwif = drive->hwif;
108 unsigned long flags; 109 unsigned long flags;
109 ide_hwgroup_t *hwgroup = ide_hwifs[HWIF(drive)->index^1].hwgroup;
110 110
111 printk("%s: setting umc8672 to PIO mode%d (speed %d)\n", 111 printk("%s: setting umc8672 to PIO mode%d (speed %d)\n",
112 drive->name, pio, pio_to_umc[pio]); 112 drive->name, pio, pio_to_umc[pio]);
113 spin_lock_irqsave(&ide_lock, flags); 113 spin_lock_irqsave(&ide_lock, flags);
114 if (hwgroup && hwgroup->handler != NULL) { 114 if (hwif->mate && hwif->mate->hwgroup->handler) {
115 printk(KERN_ERR "umc8672: other interface is busy: exiting tune_umc()\n"); 115 printk(KERN_ERR "umc8672: other interface is busy: exiting tune_umc()\n");
116 } else { 116 } else {
117 current_speeds[drive->name[2] - 'a'] = pio_to_umc[pio]; 117 current_speeds[drive->name[2] - 'a'] = pio_to_umc[pio];
118 umc_set_speeds (current_speeds); 118 umc_set_speeds(current_speeds);
119 } 119 }
120 spin_unlock_irqrestore(&ide_lock, flags); 120 spin_unlock_irqrestore(&ide_lock, flags);
121} 121}
@@ -128,8 +128,9 @@ static const struct ide_port_info umc8672_port_info __initdata = {
128 128
129static int __init umc8672_probe(void) 129static int __init umc8672_probe(void)
130{ 130{
131 ide_hwif_t *hwif, *mate;
131 unsigned long flags; 132 unsigned long flags;
132 static u8 idx[4] = { 0, 1, 0xff, 0xff }; 133 static u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
133 hw_regs_t hw[2]; 134 hw_regs_t hw[2];
134 135
135 if (!request_region(0x108, 2, "umc8672")) { 136 if (!request_region(0x108, 2, "umc8672")) {
@@ -137,16 +138,16 @@ static int __init umc8672_probe(void)
137 return 1; 138 return 1;
138 } 139 }
139 local_irq_save(flags); 140 local_irq_save(flags);
140 outb_p(0x5A,0x108); /* enable umc */ 141 outb_p(0x5A, 0x108); /* enable umc */
141 if (in_umc (0xd5) != 0xa0) { 142 if (in_umc (0xd5) != 0xa0) {
142 local_irq_restore(flags); 143 local_irq_restore(flags);
143 printk(KERN_ERR "umc8672: not found\n"); 144 printk(KERN_ERR "umc8672: not found\n");
144 release_region(0x108, 2); 145 release_region(0x108, 2);
145 return 1; 146 return 1;
146 } 147 }
147 outb_p(0xa5,0x108); /* disable umc */ 148 outb_p(0xa5, 0x108); /* disable umc */
148 149
149 umc_set_speeds (current_speeds); 150 umc_set_speeds(current_speeds);
150 local_irq_restore(flags); 151 local_irq_restore(flags);
151 152
152 memset(&hw, 0, sizeof(hw)); 153 memset(&hw, 0, sizeof(hw));
@@ -157,18 +158,26 @@ static int __init umc8672_probe(void)
157 ide_std_init_ports(&hw[1], 0x170, 0x376); 158 ide_std_init_ports(&hw[1], 0x170, 0x376);
158 hw[1].irq = 15; 159 hw[1].irq = 15;
159 160
160 ide_init_port_hw(&ide_hwifs[0], &hw[0]); 161 hwif = ide_find_port();
161 ide_init_port_hw(&ide_hwifs[1], &hw[1]); 162 if (hwif) {
163 ide_init_port_hw(hwif, &hw[0]);
164 hwif->set_pio_mode = umc_set_pio_mode;
165 idx[0] = hwif->index;
166 }
162 167
163 ide_hwifs[0].set_pio_mode = &umc_set_pio_mode; 168 mate = ide_find_port();
164 ide_hwifs[1].set_pio_mode = &umc_set_pio_mode; 169 if (mate) {
170 ide_init_port_hw(mate, &hw[1]);
171 mate->set_pio_mode = umc_set_pio_mode;
172 idx[1] = mate->index;
173 }
165 174
166 ide_device_add(idx, &umc8672_port_info); 175 ide_device_add(idx, &umc8672_port_info);
167 176
168 return 0; 177 return 0;
169} 178}
170 179
171int probe_umc8672 = 0; 180int probe_umc8672;
172 181
173module_param_named(probe, probe_umc8672, bool, 0); 182module_param_named(probe, probe_umc8672, bool, 0);
174MODULE_PARM_DESC(probe, "probe for UMC8672 chipset"); 183MODULE_PARM_DESC(probe, "probe for UMC8672 chipset");
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c
index 9b628248f2f4..a8cd0035936d 100644
--- a/drivers/ide/mips/au1xxx-ide.c
+++ b/drivers/ide/mips/au1xxx-ide.c
@@ -599,9 +599,11 @@ static int au_ide_probe(struct device *dev)
599 goto out; 599 goto out;
600 } 600 }
601 601
602 /* FIXME: This might possibly break PCMCIA IDE devices */ 602 hwif = ide_find_port();
603 603 if (hwif == NULL) {
604 hwif = &ide_hwifs[pdev->id]; 604 ret = -ENOENT;
605 goto out;
606 }
605 607
606 memset(&hw, 0, sizeof(hw)); 608 memset(&hw, 0, sizeof(hw));
607 auide_setup_ports(&hw, ahwif); 609 auide_setup_ports(&hw, ahwif);
diff --git a/drivers/ide/mips/swarm.c b/drivers/ide/mips/swarm.c
index 956259fc09ba..bbe8d5853348 100644
--- a/drivers/ide/mips/swarm.c
+++ b/drivers/ide/mips/swarm.c
@@ -76,17 +76,12 @@ static int __devinit swarm_ide_probe(struct device *dev)
76 if (!SIBYTE_HAVE_IDE) 76 if (!SIBYTE_HAVE_IDE)
77 return -ENODEV; 77 return -ENODEV;
78 78
79 /* Find an empty slot. */ 79 hwif = ide_find_port();
80 for (i = 0; i < MAX_HWIFS; i++) 80 if (hwif == NULL) {
81 if (!ide_hwifs[i].io_ports[IDE_DATA_OFFSET])
82 break;
83 if (i >= MAX_HWIFS) {
84 printk(KERN_ERR DRV_NAME ": no free slot for interface\n"); 81 printk(KERN_ERR DRV_NAME ": no free slot for interface\n");
85 return -ENOMEM; 82 return -ENOMEM;
86 } 83 }
87 84
88 hwif = ide_hwifs + i;
89
90 base = ioremap(A_IO_EXT_BASE, 0x800); 85 base = ioremap(A_IO_EXT_BASE, 0x800);
91 offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS)); 86 offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS));
92 size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS)); 87 size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS));
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index cfb3265bc1a8..c9ba15afe97d 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -220,7 +220,8 @@ static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
220 .init_hwif = init_hwif_aec62xx, 220 .init_hwif = init_hwif_aec62xx,
221 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, 221 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
222 .host_flags = IDE_HFLAG_NO_ATAPI_DMA | 222 .host_flags = IDE_HFLAG_NO_ATAPI_DMA |
223 IDE_HFLAG_ABUSE_SET_DMA_MODE, 223 IDE_HFLAG_ABUSE_SET_DMA_MODE |
224 IDE_HFLAG_NON_BOOTABLE,
224 .pio_mask = ATA_PIO4, 225 .pio_mask = ATA_PIO4,
225 .mwdma_mask = ATA_MWDMA2, 226 .mwdma_mask = ATA_MWDMA2,
226 .udma_mask = ATA_UDMA4, 227 .udma_mask = ATA_UDMA4,
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index b3b6f514ce2d..3fa2d9f7b1b2 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -750,7 +750,6 @@ static const struct ide_port_info ali15x3_chipset __devinitdata = {
750 .init_chipset = init_chipset_ali15x3, 750 .init_chipset = init_chipset_ali15x3,
751 .init_hwif = init_hwif_ali15x3, 751 .init_hwif = init_hwif_ali15x3,
752 .init_dma = init_dma_ali15x3, 752 .init_dma = init_dma_ali15x3,
753 .host_flags = IDE_HFLAG_BOOTABLE,
754 .pio_mask = ATA_PIO5, 753 .pio_mask = ATA_PIO5,
755 .swdma_mask = ATA_SWDMA2, 754 .swdma_mask = ATA_SWDMA2,
756 .mwdma_mask = ATA_MWDMA2, 755 .mwdma_mask = ATA_MWDMA2,
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index 2ef890ce8097..ff684d312378 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -219,12 +219,10 @@ static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
219 219
220#define IDE_HFLAGS_AMD \ 220#define IDE_HFLAGS_AMD \
221 (IDE_HFLAG_PIO_NO_BLACKLIST | \ 221 (IDE_HFLAG_PIO_NO_BLACKLIST | \
222 IDE_HFLAG_PIO_NO_DOWNGRADE | \
223 IDE_HFLAG_ABUSE_SET_DMA_MODE | \ 222 IDE_HFLAG_ABUSE_SET_DMA_MODE | \
224 IDE_HFLAG_POST_SET_MODE | \ 223 IDE_HFLAG_POST_SET_MODE | \
225 IDE_HFLAG_IO_32BIT | \ 224 IDE_HFLAG_IO_32BIT | \
226 IDE_HFLAG_UNMASK_IRQS | \ 225 IDE_HFLAG_UNMASK_IRQS)
227 IDE_HFLAG_BOOTABLE)
228 226
229#define DECLARE_AMD_DEV(name_str, swdma, udma) \ 227#define DECLARE_AMD_DEV(name_str, swdma, udma) \
230 { \ 228 { \
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index 7e037c880cb0..91722f88b7bd 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -151,7 +151,7 @@ static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
151 .name = "ATIIXP", 151 .name = "ATIIXP",
152 .init_hwif = init_hwif_atiixp, 152 .init_hwif = init_hwif_atiixp,
153 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}}, 153 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
154 .host_flags = IDE_HFLAG_LEGACY_IRQS | IDE_HFLAG_BOOTABLE, 154 .host_flags = IDE_HFLAG_LEGACY_IRQS,
155 .pio_mask = ATA_PIO4, 155 .pio_mask = ATA_PIO4,
156 .mwdma_mask = ATA_MWDMA2, 156 .mwdma_mask = ATA_MWDMA2,
157 .udma_mask = ATA_UDMA5, 157 .udma_mask = ATA_UDMA5,
@@ -159,8 +159,7 @@ static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
159 .name = "SB600_PATA", 159 .name = "SB600_PATA",
160 .init_hwif = init_hwif_atiixp, 160 .init_hwif = init_hwif_atiixp,
161 .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}}, 161 .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}},
162 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_LEGACY_IRQS | 162 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_LEGACY_IRQS,
163 IDE_HFLAG_BOOTABLE,
164 .pio_mask = ATA_PIO4, 163 .pio_mask = ATA_PIO4,
165 .mwdma_mask = ATA_MWDMA2, 164 .mwdma_mask = ATA_MWDMA2,
166 .udma_mask = ATA_UDMA5, 165 .udma_mask = ATA_UDMA5,
diff --git a/drivers/ide/pci/cmd640.c b/drivers/ide/pci/cmd640.c
index a1cfe033a55f..b076dbfc43a7 100644
--- a/drivers/ide/pci/cmd640.c
+++ b/drivers/ide/pci/cmd640.c
@@ -4,7 +4,7 @@
4 4
5/* 5/*
6 * Original authors: abramov@cecmow.enet.dec.com (Igor Abramov) 6 * Original authors: abramov@cecmow.enet.dec.com (Igor Abramov)
7 * mlord@pobox.com (Mark Lord) 7 * mlord@pobox.com (Mark Lord)
8 * 8 *
9 * See linux/MAINTAINERS for address of current maintainer. 9 * See linux/MAINTAINERS for address of current maintainer.
10 * 10 *
@@ -98,7 +98,7 @@
98 98
99#define CMD640_PREFETCH_MASKS 1 99#define CMD640_PREFETCH_MASKS 1
100 100
101//#define CMD640_DUMP_REGS 101/*#define CMD640_DUMP_REGS */
102 102
103#include <linux/types.h> 103#include <linux/types.h>
104#include <linux/kernel.h> 104#include <linux/kernel.h>
@@ -112,7 +112,7 @@
112/* 112/*
113 * This flag is set in ide.c by the parameter: ide0=cmd640_vlb 113 * This flag is set in ide.c by the parameter: ide0=cmd640_vlb
114 */ 114 */
115int cmd640_vlb = 0; 115int cmd640_vlb;
116 116
117/* 117/*
118 * CMD640 specific registers definition. 118 * CMD640 specific registers definition.
@@ -185,7 +185,6 @@ static DEFINE_SPINLOCK(cmd640_lock);
185 * These are initialized to point at the devices we control 185 * These are initialized to point at the devices we control
186 */ 186 */
187static ide_hwif_t *cmd_hwif0, *cmd_hwif1; 187static ide_hwif_t *cmd_hwif0, *cmd_hwif1;
188static ide_drive_t *cmd_drives[4];
189 188
190/* 189/*
191 * Interface to access cmd640x registers 190 * Interface to access cmd640x registers
@@ -207,13 +206,13 @@ static unsigned int cmd640_chip_version;
207 206
208/* PCI method 1 access */ 207/* PCI method 1 access */
209 208
210static void put_cmd640_reg_pci1 (u16 reg, u8 val) 209static void put_cmd640_reg_pci1(u16 reg, u8 val)
211{ 210{
212 outl_p((reg & 0xfc) | cmd640_key, 0xcf8); 211 outl_p((reg & 0xfc) | cmd640_key, 0xcf8);
213 outb_p(val, (reg & 3) | 0xcfc); 212 outb_p(val, (reg & 3) | 0xcfc);
214} 213}
215 214
216static u8 get_cmd640_reg_pci1 (u16 reg) 215static u8 get_cmd640_reg_pci1(u16 reg)
217{ 216{
218 outl_p((reg & 0xfc) | cmd640_key, 0xcf8); 217 outl_p((reg & 0xfc) | cmd640_key, 0xcf8);
219 return inb_p((reg & 3) | 0xcfc); 218 return inb_p((reg & 3) | 0xcfc);
@@ -221,14 +220,14 @@ static u8 get_cmd640_reg_pci1 (u16 reg)
221 220
222/* PCI method 2 access (from CMD datasheet) */ 221/* PCI method 2 access (from CMD datasheet) */
223 222
224static void put_cmd640_reg_pci2 (u16 reg, u8 val) 223static void put_cmd640_reg_pci2(u16 reg, u8 val)
225{ 224{
226 outb_p(0x10, 0xcf8); 225 outb_p(0x10, 0xcf8);
227 outb_p(val, cmd640_key + reg); 226 outb_p(val, cmd640_key + reg);
228 outb_p(0, 0xcf8); 227 outb_p(0, 0xcf8);
229} 228}
230 229
231static u8 get_cmd640_reg_pci2 (u16 reg) 230static u8 get_cmd640_reg_pci2(u16 reg)
232{ 231{
233 u8 b; 232 u8 b;
234 233
@@ -240,13 +239,13 @@ static u8 get_cmd640_reg_pci2 (u16 reg)
240 239
241/* VLB access */ 240/* VLB access */
242 241
243static void put_cmd640_reg_vlb (u16 reg, u8 val) 242static void put_cmd640_reg_vlb(u16 reg, u8 val)
244{ 243{
245 outb_p(reg, cmd640_key); 244 outb_p(reg, cmd640_key);
246 outb_p(val, cmd640_key + 4); 245 outb_p(val, cmd640_key + 4);
247} 246}
248 247
249static u8 get_cmd640_reg_vlb (u16 reg) 248static u8 get_cmd640_reg_vlb(u16 reg)
250{ 249{
251 outb_p(reg, cmd640_key); 250 outb_p(reg, cmd640_key);
252 return inb_p(cmd640_key + 4); 251 return inb_p(cmd640_key + 4);
@@ -268,11 +267,11 @@ static void put_cmd640_reg(u16 reg, u8 val)
268 unsigned long flags; 267 unsigned long flags;
269 268
270 spin_lock_irqsave(&cmd640_lock, flags); 269 spin_lock_irqsave(&cmd640_lock, flags);
271 __put_cmd640_reg(reg,val); 270 __put_cmd640_reg(reg, val);
272 spin_unlock_irqrestore(&cmd640_lock, flags); 271 spin_unlock_irqrestore(&cmd640_lock, flags);
273} 272}
274 273
275static int __init match_pci_cmd640_device (void) 274static int __init match_pci_cmd640_device(void)
276{ 275{
277 const u8 ven_dev[4] = {0x95, 0x10, 0x40, 0x06}; 276 const u8 ven_dev[4] = {0x95, 0x10, 0x40, 0x06};
278 unsigned int i; 277 unsigned int i;
@@ -292,7 +291,7 @@ static int __init match_pci_cmd640_device (void)
292/* 291/*
293 * Probe for CMD640x -- pci method 1 292 * Probe for CMD640x -- pci method 1
294 */ 293 */
295static int __init probe_for_cmd640_pci1 (void) 294static int __init probe_for_cmd640_pci1(void)
296{ 295{
297 __get_cmd640_reg = get_cmd640_reg_pci1; 296 __get_cmd640_reg = get_cmd640_reg_pci1;
298 __put_cmd640_reg = put_cmd640_reg_pci1; 297 __put_cmd640_reg = put_cmd640_reg_pci1;
@@ -308,7 +307,7 @@ static int __init probe_for_cmd640_pci1 (void)
308/* 307/*
309 * Probe for CMD640x -- pci method 2 308 * Probe for CMD640x -- pci method 2
310 */ 309 */
311static int __init probe_for_cmd640_pci2 (void) 310static int __init probe_for_cmd640_pci2(void)
312{ 311{
313 __get_cmd640_reg = get_cmd640_reg_pci2; 312 __get_cmd640_reg = get_cmd640_reg_pci2;
314 __put_cmd640_reg = put_cmd640_reg_pci2; 313 __put_cmd640_reg = put_cmd640_reg_pci2;
@@ -322,7 +321,7 @@ static int __init probe_for_cmd640_pci2 (void)
322/* 321/*
323 * Probe for CMD640x -- vlb 322 * Probe for CMD640x -- vlb
324 */ 323 */
325static int __init probe_for_cmd640_vlb (void) 324static int __init probe_for_cmd640_vlb(void)
326{ 325{
327 u8 b; 326 u8 b;
328 327
@@ -343,7 +342,7 @@ static int __init probe_for_cmd640_vlb (void)
343 * Returns 1 if an IDE interface/drive exists at 0x170, 342 * Returns 1 if an IDE interface/drive exists at 0x170,
344 * Returns 0 otherwise. 343 * Returns 0 otherwise.
345 */ 344 */
346static int __init secondary_port_responding (void) 345static int __init secondary_port_responding(void)
347{ 346{
348 unsigned long flags; 347 unsigned long flags;
349 348
@@ -367,7 +366,7 @@ static int __init secondary_port_responding (void)
367/* 366/*
368 * Dump out all cmd640 registers. May be called from ide.c 367 * Dump out all cmd640 registers. May be called from ide.c
369 */ 368 */
370static void cmd640_dump_regs (void) 369static void cmd640_dump_regs(void)
371{ 370{
372 unsigned int reg = cmd640_vlb ? 0x50 : 0x00; 371 unsigned int reg = cmd640_vlb ? 0x50 : 0x00;
373 372
@@ -386,9 +385,8 @@ static void cmd640_dump_regs (void)
386 * Check whether prefetch is on for a drive, 385 * Check whether prefetch is on for a drive,
387 * and initialize the unmask flags for safe operation. 386 * and initialize the unmask flags for safe operation.
388 */ 387 */
389static void __init check_prefetch (unsigned int index) 388static void __init check_prefetch(ide_drive_t *drive, unsigned int index)
390{ 389{
391 ide_drive_t *drive = cmd_drives[index];
392 u8 b = get_cmd640_reg(prefetch_regs[index]); 390 u8 b = get_cmd640_reg(prefetch_regs[index]);
393 391
394 if (b & prefetch_masks[index]) { /* is prefetch off? */ 392 if (b & prefetch_masks[index]) { /* is prefetch off? */
@@ -404,28 +402,13 @@ static void __init check_prefetch (unsigned int index)
404 } 402 }
405} 403}
406 404
407/*
408 * Figure out which devices we control
409 */
410static void __init setup_device_ptrs (void)
411{
412 cmd_hwif0 = &ide_hwifs[0];
413 cmd_hwif1 = &ide_hwifs[1];
414
415 cmd_drives[0] = &cmd_hwif0->drives[0];
416 cmd_drives[1] = &cmd_hwif0->drives[1];
417 cmd_drives[2] = &cmd_hwif1->drives[0];
418 cmd_drives[3] = &cmd_hwif1->drives[1];
419}
420
421#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED 405#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
422 406
423/* 407/*
424 * Sets prefetch mode for a drive. 408 * Sets prefetch mode for a drive.
425 */ 409 */
426static void set_prefetch_mode (unsigned int index, int mode) 410static void set_prefetch_mode(ide_drive_t *drive, unsigned int index, int mode)
427{ 411{
428 ide_drive_t *drive = cmd_drives[index];
429 unsigned long flags; 412 unsigned long flags;
430 int reg = prefetch_regs[index]; 413 int reg = prefetch_regs[index];
431 u8 b; 414 u8 b;
@@ -452,7 +435,7 @@ static void set_prefetch_mode (unsigned int index, int mode)
452/* 435/*
453 * Dump out current drive clocks settings 436 * Dump out current drive clocks settings
454 */ 437 */
455static void display_clocks (unsigned int index) 438static void display_clocks(unsigned int index)
456{ 439{
457 u8 active_count, recovery_count; 440 u8 active_count, recovery_count;
458 441
@@ -471,7 +454,7 @@ static void display_clocks (unsigned int index)
471 * Pack active and recovery counts into single byte representation 454 * Pack active and recovery counts into single byte representation
472 * used by controller 455 * used by controller
473 */ 456 */
474static inline u8 pack_nibbles (u8 upper, u8 lower) 457static inline u8 pack_nibbles(u8 upper, u8 lower)
475{ 458{
476 return ((upper & 0x0f) << 4) | (lower & 0x0f); 459 return ((upper & 0x0f) << 4) | (lower & 0x0f);
477} 460}
@@ -479,7 +462,7 @@ static inline u8 pack_nibbles (u8 upper, u8 lower)
479/* 462/*
480 * This routine retrieves the initial drive timings from the chipset. 463 * This routine retrieves the initial drive timings from the chipset.
481 */ 464 */
482static void __init retrieve_drive_counts (unsigned int index) 465static void __init retrieve_drive_counts(unsigned int index)
483{ 466{
484 u8 b; 467 u8 b;
485 468
@@ -488,10 +471,10 @@ static void __init retrieve_drive_counts (unsigned int index)
488 */ 471 */
489 b = get_cmd640_reg(arttim_regs[index]) & ~0x3f; 472 b = get_cmd640_reg(arttim_regs[index]) & ~0x3f;
490 switch (b) { 473 switch (b) {
491 case 0x00: b = 4; break; 474 case 0x00: b = 4; break;
492 case 0x80: b = 3; break; 475 case 0x80: b = 3; break;
493 case 0x40: b = 2; break; 476 case 0x40: b = 2; break;
494 default: b = 5; break; 477 default: b = 5; break;
495 } 478 }
496 setup_counts[index] = b; 479 setup_counts[index] = b;
497 480
@@ -508,7 +491,7 @@ static void __init retrieve_drive_counts (unsigned int index)
508 * This routine writes the prepared setup/active/recovery counts 491 * This routine writes the prepared setup/active/recovery counts
509 * for a drive into the cmd640 chipset registers to active them. 492 * for a drive into the cmd640 chipset registers to active them.
510 */ 493 */
511static void program_drive_counts (unsigned int index) 494static void program_drive_counts(ide_drive_t *drive, unsigned int index)
512{ 495{
513 unsigned long flags; 496 unsigned long flags;
514 u8 setup_count = setup_counts[index]; 497 u8 setup_count = setup_counts[index];
@@ -522,8 +505,11 @@ static void program_drive_counts (unsigned int index)
522 * so we merge the timings, using the slowest value for each timing. 505 * so we merge the timings, using the slowest value for each timing.
523 */ 506 */
524 if (index > 1) { 507 if (index > 1) {
525 unsigned int mate; 508 ide_hwif_t *hwif = drive->hwif;
526 if (cmd_drives[mate = index ^ 1]->present) { 509 ide_drive_t *peer = &hwif->drives[!drive->select.b.unit];
510 unsigned int mate = index ^ 1;
511
512 if (peer->present) {
527 if (setup_count < setup_counts[mate]) 513 if (setup_count < setup_counts[mate])
528 setup_count = setup_counts[mate]; 514 setup_count = setup_counts[mate];
529 if (active_count < active_counts[mate]) 515 if (active_count < active_counts[mate])
@@ -537,11 +523,11 @@ static void program_drive_counts (unsigned int index)
537 * Convert setup_count to internal chipset representation 523 * Convert setup_count to internal chipset representation
538 */ 524 */
539 switch (setup_count) { 525 switch (setup_count) {
540 case 4: setup_count = 0x00; break; 526 case 4: setup_count = 0x00; break;
541 case 3: setup_count = 0x80; break; 527 case 3: setup_count = 0x80; break;
542 case 1: 528 case 1:
543 case 2: setup_count = 0x40; break; 529 case 2: setup_count = 0x40; break;
544 default: setup_count = 0xc0; /* case 5 */ 530 default: setup_count = 0xc0; /* case 5 */
545 } 531 }
546 532
547 /* 533 /*
@@ -562,7 +548,8 @@ static void program_drive_counts (unsigned int index)
562/* 548/*
563 * Set a specific pio_mode for a drive 549 * Set a specific pio_mode for a drive
564 */ 550 */
565static void cmd640_set_mode (unsigned int index, u8 pio_mode, unsigned int cycle_time) 551static void cmd640_set_mode(ide_drive_t *drive, unsigned int index,
552 u8 pio_mode, unsigned int cycle_time)
566{ 553{
567 int setup_time, active_time, recovery_time, clock_time; 554 int setup_time, active_time, recovery_time, clock_time;
568 u8 setup_count, active_count, recovery_count, recovery_count2, cycle_count; 555 u8 setup_count, active_count, recovery_count, recovery_count2, cycle_count;
@@ -574,15 +561,15 @@ static void cmd640_set_mode (unsigned int index, u8 pio_mode, unsigned int cycle
574 active_time = ide_pio_timings[pio_mode].active_time; 561 active_time = ide_pio_timings[pio_mode].active_time;
575 recovery_time = cycle_time - (setup_time + active_time); 562 recovery_time = cycle_time - (setup_time + active_time);
576 clock_time = 1000 / bus_speed; 563 clock_time = 1000 / bus_speed;
577 cycle_count = (cycle_time + clock_time - 1) / clock_time; 564 cycle_count = DIV_ROUND_UP(cycle_time, clock_time);
578 565
579 setup_count = (setup_time + clock_time - 1) / clock_time; 566 setup_count = DIV_ROUND_UP(setup_time, clock_time);
580 567
581 active_count = (active_time + clock_time - 1) / clock_time; 568 active_count = DIV_ROUND_UP(active_time, clock_time);
582 if (active_count < 2) 569 if (active_count < 2)
583 active_count = 2; /* minimum allowed by cmd640 */ 570 active_count = 2; /* minimum allowed by cmd640 */
584 571
585 recovery_count = (recovery_time + clock_time - 1) / clock_time; 572 recovery_count = DIV_ROUND_UP(recovery_time, clock_time);
586 recovery_count2 = cycle_count - (setup_count + active_count); 573 recovery_count2 = cycle_count - (setup_count + active_count);
587 if (recovery_count2 > recovery_count) 574 if (recovery_count2 > recovery_count)
588 recovery_count = recovery_count2; 575 recovery_count = recovery_count2;
@@ -611,7 +598,7 @@ static void cmd640_set_mode (unsigned int index, u8 pio_mode, unsigned int cycle
611 * 1) this is the wrong place to do it (proper is do_special() in ide.c) 598 * 1) this is the wrong place to do it (proper is do_special() in ide.c)
612 * 2) in practice this is rarely, if ever, necessary 599 * 2) in practice this is rarely, if ever, necessary
613 */ 600 */
614 program_drive_counts (index); 601 program_drive_counts(drive, index);
615} 602}
616 603
617static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio) 604static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio)
@@ -619,32 +606,26 @@ static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio)
619 unsigned int index = 0, cycle_time; 606 unsigned int index = 0, cycle_time;
620 u8 b; 607 u8 b;
621 608
622 while (drive != cmd_drives[index]) {
623 if (++index > 3) {
624 printk(KERN_ERR "%s: bad news in %s\n",
625 drive->name, __FUNCTION__);
626 return;
627 }
628 }
629 switch (pio) { 609 switch (pio) {
630 case 6: /* set fast-devsel off */ 610 case 6: /* set fast-devsel off */
631 case 7: /* set fast-devsel on */ 611 case 7: /* set fast-devsel on */
632 b = get_cmd640_reg(CNTRL) & ~0x27; 612 b = get_cmd640_reg(CNTRL) & ~0x27;
633 if (pio & 1) 613 if (pio & 1)
634 b |= 0x27; 614 b |= 0x27;
635 put_cmd640_reg(CNTRL, b); 615 put_cmd640_reg(CNTRL, b);
636 printk("%s: %sabled cmd640 fast host timing (devsel)\n", drive->name, (pio & 1) ? "en" : "dis"); 616 printk("%s: %sabled cmd640 fast host timing (devsel)\n",
637 return; 617 drive->name, (pio & 1) ? "en" : "dis");
638 618 return;
639 case 8: /* set prefetch off */ 619 case 8: /* set prefetch off */
640 case 9: /* set prefetch on */ 620 case 9: /* set prefetch on */
641 set_prefetch_mode(index, pio & 1); 621 set_prefetch_mode(drive, index, pio & 1);
642 printk("%s: %sabled cmd640 prefetch\n", drive->name, (pio & 1) ? "en" : "dis"); 622 printk("%s: %sabled cmd640 prefetch\n",
643 return; 623 drive->name, (pio & 1) ? "en" : "dis");
624 return;
644 } 625 }
645 626
646 cycle_time = ide_pio_cycle_time(drive, pio); 627 cycle_time = ide_pio_cycle_time(drive, pio);
647 cmd640_set_mode(index, pio, cycle_time); 628 cmd640_set_mode(drive, index, pio, cycle_time);
648 629
649 printk("%s: selected cmd640 PIO mode%d (%dns)", 630 printk("%s: selected cmd640 PIO mode%d (%dns)",
650 drive->name, pio, cycle_time); 631 drive->name, pio, cycle_time);
@@ -749,7 +730,7 @@ static int __init cmd640x_init(void)
749 cfr = get_cmd640_reg(CFR); 730 cfr = get_cmd640_reg(CFR);
750 cmd640_chip_version = cfr & CFR_DEVREV; 731 cmd640_chip_version = cfr & CFR_DEVREV;
751 if (cmd640_chip_version == 0) { 732 if (cmd640_chip_version == 0) {
752 printk ("ide: bad cmd640 revision: %d\n", cmd640_chip_version); 733 printk("ide: bad cmd640 revision: %d\n", cmd640_chip_version);
753 return 0; 734 return 0;
754 } 735 }
755 736
@@ -764,17 +745,19 @@ static int __init cmd640x_init(void)
764 printk(KERN_INFO "cmd640: buggy cmd640%c interface on %s, config=0x%02x" 745 printk(KERN_INFO "cmd640: buggy cmd640%c interface on %s, config=0x%02x"
765 "\n", 'a' + cmd640_chip_version - 1, bus_type, cfr); 746 "\n", 'a' + cmd640_chip_version - 1, bus_type, cfr);
766 747
748 cmd_hwif0 = ide_find_port();
749
767 /* 750 /*
768 * Initialize data for primary port 751 * Initialize data for primary port
769 */ 752 */
770 setup_device_ptrs (); 753 if (cmd_hwif0) {
771 754 ide_init_port_hw(cmd_hwif0, &hw[0]);
772 ide_init_port_hw(cmd_hwif0, &hw[0]);
773#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED 755#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
774 cmd_hwif0->set_pio_mode = &cmd640_set_pio_mode; 756 cmd_hwif0->set_pio_mode = &cmd640_set_pio_mode;
775#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ 757#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
776 758
777 idx[0] = cmd_hwif0->index; 759 idx[0] = cmd_hwif0->index;
760 }
778 761
779 /* 762 /*
780 * Ensure compatibility by always using the slowest timings 763 * Ensure compatibility by always using the slowest timings
@@ -786,10 +769,13 @@ static int __init cmd640x_init(void)
786 put_cmd640_reg(CMDTIM, 0); 769 put_cmd640_reg(CMDTIM, 0);
787 put_cmd640_reg(BRST, 0x40); 770 put_cmd640_reg(BRST, 0x40);
788 771
772 cmd_hwif1 = ide_find_port();
773
789 /* 774 /*
790 * Try to enable the secondary interface, if not already enabled 775 * Try to enable the secondary interface, if not already enabled
791 */ 776 */
792 if (cmd_hwif1->drives[0].noprobe && cmd_hwif1->drives[1].noprobe) { 777 if (cmd_hwif1 &&
778 cmd_hwif1->drives[0].noprobe && cmd_hwif1->drives[1].noprobe) {
793 port2 = "not probed"; 779 port2 = "not probed";
794 } else { 780 } else {
795 b = get_cmd640_reg(CNTRL); 781 b = get_cmd640_reg(CNTRL);
@@ -820,7 +806,7 @@ static int __init cmd640x_init(void)
820 /* 806 /*
821 * Initialize data for secondary cmd640 port, if enabled 807 * Initialize data for secondary cmd640 port, if enabled
822 */ 808 */
823 if (second_port_cmd640) { 809 if (second_port_cmd640 && cmd_hwif1) {
824 ide_init_port_hw(cmd_hwif1, &hw[1]); 810 ide_init_port_hw(cmd_hwif1, &hw[1]);
825#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED 811#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
826 cmd_hwif1->set_pio_mode = &cmd640_set_pio_mode; 812 cmd_hwif1->set_pio_mode = &cmd640_set_pio_mode;
@@ -828,7 +814,7 @@ static int __init cmd640x_init(void)
828 814
829 idx[1] = cmd_hwif1->index; 815 idx[1] = cmd_hwif1->index;
830 } 816 }
831 printk(KERN_INFO "%s: %sserialized, secondary interface %s\n", cmd_hwif1->name, 817 printk(KERN_INFO "cmd640: %sserialized, secondary interface %s\n",
832 second_port_cmd640 ? "" : "not ", port2); 818 second_port_cmd640 ? "" : "not ", port2);
833 819
834 /* 820 /*
@@ -836,18 +822,30 @@ static int __init cmd640x_init(void)
836 * Do not unnecessarily disturb any prior BIOS setup of these. 822 * Do not unnecessarily disturb any prior BIOS setup of these.
837 */ 823 */
838 for (index = 0; index < (2 + (second_port_cmd640 << 1)); index++) { 824 for (index = 0; index < (2 + (second_port_cmd640 << 1)); index++) {
839 ide_drive_t *drive = cmd_drives[index]; 825 ide_drive_t *drive;
826
827 if (index > 1) {
828 if (cmd_hwif1 == NULL)
829 continue;
830 drive = &cmd_hwif1->drives[index & 1];
831 } else {
832 if (cmd_hwif0 == NULL)
833 continue;
834 drive = &cmd_hwif0->drives[index & 1];
835 }
836
840#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED 837#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
841 if (drive->autotune || ((index > 1) && second_port_toggled)) { 838 if (drive->autotune || ((index > 1) && second_port_toggled)) {
842 /* 839 /*
843 * Reset timing to the slowest speed and turn off prefetch. 840 * Reset timing to the slowest speed and turn off
844 * This way, the drive identify code has a better chance. 841 * prefetch. This way, the drive identify code has
842 * a better chance.
845 */ 843 */
846 setup_counts [index] = 4; /* max possible */ 844 setup_counts [index] = 4; /* max possible */
847 active_counts [index] = 16; /* max possible */ 845 active_counts [index] = 16; /* max possible */
848 recovery_counts [index] = 16; /* max possible */ 846 recovery_counts [index] = 16; /* max possible */
849 program_drive_counts (index); 847 program_drive_counts(drive, index);
850 set_prefetch_mode (index, 0); 848 set_prefetch_mode(drive, index, 0);
851 printk("cmd640: drive%d timings/prefetch cleared\n", index); 849 printk("cmd640: drive%d timings/prefetch cleared\n", index);
852 } else { 850 } else {
853 /* 851 /*
@@ -855,7 +853,7 @@ static int __init cmd640x_init(void)
855 * This preserves any prior BIOS setup. 853 * This preserves any prior BIOS setup.
856 */ 854 */
857 retrieve_drive_counts (index); 855 retrieve_drive_counts (index);
858 check_prefetch (index); 856 check_prefetch(drive, index);
859 printk("cmd640: drive%d timings/prefetch(%s) preserved", 857 printk("cmd640: drive%d timings/prefetch(%s) preserved",
860 index, drive->no_io_32bit ? "off" : "on"); 858 index, drive->no_io_32bit ? "off" : "on");
861 display_clocks(index); 859 display_clocks(index);
@@ -864,7 +862,7 @@ static int __init cmd640x_init(void)
864 /* 862 /*
865 * Set the drive unmask flags to match the prefetch setting 863 * Set the drive unmask flags to match the prefetch setting
866 */ 864 */
867 check_prefetch (index); 865 check_prefetch(drive, index);
868 printk("cmd640: drive%d timings/prefetch(%s) preserved\n", 866 printk("cmd640: drive%d timings/prefetch(%s) preserved\n",
869 index, drive->no_io_32bit ? "off" : "on"); 867 index, drive->no_io_32bit ? "off" : "on");
870#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ 868#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index edabe6299efd..8baccfef237f 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -440,8 +440,7 @@ static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
440 .init_hwif = init_hwif_cmd64x, 440 .init_hwif = init_hwif_cmd64x,
441 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}}, 441 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}},
442 .host_flags = IDE_HFLAG_CLEAR_SIMPLEX | 442 .host_flags = IDE_HFLAG_CLEAR_SIMPLEX |
443 IDE_HFLAG_ABUSE_PREFETCH | 443 IDE_HFLAG_ABUSE_PREFETCH,
444 IDE_HFLAG_BOOTABLE,
445 .pio_mask = ATA_PIO5, 444 .pio_mask = ATA_PIO5,
446 .mwdma_mask = ATA_MWDMA2, 445 .mwdma_mask = ATA_MWDMA2,
447 .udma_mask = 0x00, /* no udma */ 446 .udma_mask = 0x00, /* no udma */
@@ -451,7 +450,7 @@ static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
451 .init_hwif = init_hwif_cmd64x, 450 .init_hwif = init_hwif_cmd64x,
452 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 451 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
453 .chipset = ide_cmd646, 452 .chipset = ide_cmd646,
454 .host_flags = IDE_HFLAG_ABUSE_PREFETCH | IDE_HFLAG_BOOTABLE, 453 .host_flags = IDE_HFLAG_ABUSE_PREFETCH,
455 .pio_mask = ATA_PIO5, 454 .pio_mask = ATA_PIO5,
456 .mwdma_mask = ATA_MWDMA2, 455 .mwdma_mask = ATA_MWDMA2,
457 .udma_mask = ATA_UDMA2, 456 .udma_mask = ATA_UDMA2,
@@ -460,7 +459,7 @@ static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
460 .init_chipset = init_chipset_cmd64x, 459 .init_chipset = init_chipset_cmd64x,
461 .init_hwif = init_hwif_cmd64x, 460 .init_hwif = init_hwif_cmd64x,
462 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 461 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
463 .host_flags = IDE_HFLAG_ABUSE_PREFETCH | IDE_HFLAG_BOOTABLE, 462 .host_flags = IDE_HFLAG_ABUSE_PREFETCH,
464 .pio_mask = ATA_PIO5, 463 .pio_mask = ATA_PIO5,
465 .mwdma_mask = ATA_MWDMA2, 464 .mwdma_mask = ATA_MWDMA2,
466 .udma_mask = ATA_UDMA4, 465 .udma_mask = ATA_UDMA4,
@@ -469,7 +468,7 @@ static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
469 .init_chipset = init_chipset_cmd64x, 468 .init_chipset = init_chipset_cmd64x,
470 .init_hwif = init_hwif_cmd64x, 469 .init_hwif = init_hwif_cmd64x,
471 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 470 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
472 .host_flags = IDE_HFLAG_ABUSE_PREFETCH | IDE_HFLAG_BOOTABLE, 471 .host_flags = IDE_HFLAG_ABUSE_PREFETCH,
473 .pio_mask = ATA_PIO5, 472 .pio_mask = ATA_PIO5,
474 .mwdma_mask = ATA_MWDMA2, 473 .mwdma_mask = ATA_MWDMA2,
475 .udma_mask = ATA_UDMA5, 474 .udma_mask = ATA_UDMA5,
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c
index 1c163e4ef03f..01b37ecb5a5a 100644
--- a/drivers/ide/pci/cs5520.c
+++ b/drivers/ide/pci/cs5520.c
@@ -122,8 +122,7 @@ static void __devinit init_hwif_cs5520(ide_hwif_t *hwif)
122 IDE_HFLAG_CS5520 | \ 122 IDE_HFLAG_CS5520 | \
123 IDE_HFLAG_VDMA | \ 123 IDE_HFLAG_VDMA | \
124 IDE_HFLAG_NO_ATAPI_DMA | \ 124 IDE_HFLAG_NO_ATAPI_DMA | \
125 IDE_HFLAG_ABUSE_SET_DMA_MODE |\ 125 IDE_HFLAG_ABUSE_SET_DMA_MODE, \
126 IDE_HFLAG_BOOTABLE, \
127 .pio_mask = ATA_PIO4, \ 126 .pio_mask = ATA_PIO4, \
128 } 127 }
129 128
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c
index 941a1344820b..56a369c2a78a 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/pci/cs5530.c
@@ -249,8 +249,7 @@ static const struct ide_port_info cs5530_chipset __devinitdata = {
249 .init_chipset = init_chipset_cs5530, 249 .init_chipset = init_chipset_cs5530,
250 .init_hwif = init_hwif_cs5530, 250 .init_hwif = init_hwif_cs5530,
251 .host_flags = IDE_HFLAG_SERIALIZE | 251 .host_flags = IDE_HFLAG_SERIALIZE |
252 IDE_HFLAG_POST_SET_MODE | 252 IDE_HFLAG_POST_SET_MODE,
253 IDE_HFLAG_BOOTABLE,
254 .pio_mask = ATA_PIO4, 253 .pio_mask = ATA_PIO4,
255 .mwdma_mask = ATA_MWDMA2, 254 .mwdma_mask = ATA_MWDMA2,
256 .udma_mask = ATA_UDMA2, 255 .udma_mask = ATA_UDMA2,
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c
index d7b5ea992e94..c9685f239c65 100644
--- a/drivers/ide/pci/cs5535.c
+++ b/drivers/ide/pci/cs5535.c
@@ -186,7 +186,7 @@ static const struct ide_port_info cs5535_chipset __devinitdata = {
186 .name = "CS5535", 186 .name = "CS5535",
187 .init_hwif = init_hwif_cs5535, 187 .init_hwif = init_hwif_cs5535,
188 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE | 188 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE |
189 IDE_HFLAG_ABUSE_SET_DMA_MODE | IDE_HFLAG_BOOTABLE, 189 IDE_HFLAG_ABUSE_SET_DMA_MODE,
190 .pio_mask = ATA_PIO4, 190 .pio_mask = ATA_PIO4,
191 .mwdma_mask = ATA_MWDMA2, 191 .mwdma_mask = ATA_MWDMA2,
192 .udma_mask = ATA_UDMA4, 192 .udma_mask = ATA_UDMA4,
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c
index 724cbacf4e5b..08eab7e7f051 100644
--- a/drivers/ide/pci/cy82c693.c
+++ b/drivers/ide/pci/cy82c693.c
@@ -6,7 +6,7 @@
6 * 6 *
7 * The CY82C693 chipset is used on Digital's PC-Alpha 164SX boards. 7 * The CY82C693 chipset is used on Digital's PC-Alpha 164SX boards.
8 * Writing the driver was quite simple, since most of the job is 8 * Writing the driver was quite simple, since most of the job is
9 * done by the generic pci-ide support. 9 * done by the generic pci-ide support.
10 * The hard part was finding the CY82C693's datasheet on Cypress's 10 * The hard part was finding the CY82C693's datasheet on Cypress's
11 * web page :-(. But Altavista solved this problem :-). 11 * web page :-(. But Altavista solved this problem :-).
12 * 12 *
@@ -15,12 +15,12 @@
15 * - I recently got a 16.8G IBM DTTA, so I was able to test it with 15 * - I recently got a 16.8G IBM DTTA, so I was able to test it with
16 * a large and fast disk - the results look great, so I'd say the 16 * a large and fast disk - the results look great, so I'd say the
17 * driver is working fine :-) 17 * driver is working fine :-)
18 * hdparm -t reports 8.17 MB/sec at about 6% CPU usage for the DTTA 18 * hdparm -t reports 8.17 MB/sec at about 6% CPU usage for the DTTA
19 * - this is my first linux driver, so there's probably a lot of room 19 * - this is my first linux driver, so there's probably a lot of room
20 * for optimizations and bug fixing, so feel free to do it. 20 * for optimizations and bug fixing, so feel free to do it.
21 * - use idebus=xx parameter to set PCI bus speed - needed to calc 21 * - use idebus=xx parameter to set PCI bus speed - needed to calc
22 * timings for PIO modes (default will be 40) 22 * timings for PIO modes (default will be 40)
23 * - if using PIO mode it's a good idea to set the PIO mode and 23 * - if using PIO mode it's a good idea to set the PIO mode and
24 * 32-bit I/O support (if possible), e.g. hdparm -p2 -c1 /dev/hda 24 * 32-bit I/O support (if possible), e.g. hdparm -p2 -c1 /dev/hda
25 * - I had some problems with my IBM DHEA with PIO modes < 2 25 * - I had some problems with my IBM DHEA with PIO modes < 2
26 * (lost interrupts) ????? 26 * (lost interrupts) ?????
@@ -110,11 +110,11 @@ typedef struct pio_clocks_s {
110 * calc clocks using bus_speed 110 * calc clocks using bus_speed
111 * returns (rounded up) time in bus clocks for time in ns 111 * returns (rounded up) time in bus clocks for time in ns
112 */ 112 */
113static int calc_clk (int time, int bus_speed) 113static int calc_clk(int time, int bus_speed)
114{ 114{
115 int clocks; 115 int clocks;
116 116
117 clocks = (time*bus_speed+999)/1000 -1; 117 clocks = (time*bus_speed+999)/1000 - 1;
118 118
119 if (clocks < 0) 119 if (clocks < 0)
120 clocks = 0; 120 clocks = 0;
@@ -132,8 +132,8 @@ static int calc_clk (int time, int bus_speed)
132 * NOTE: for mode 0,1 and 2 drives 8-bit IDE command control registers are used 132 * NOTE: for mode 0,1 and 2 drives 8-bit IDE command control registers are used
133 * for mode 3 and 4 drives 8 and 16-bit timings are the same 133 * for mode 3 and 4 drives 8 and 16-bit timings are the same
134 * 134 *
135 */ 135 */
136static void compute_clocks (u8 pio, pio_clocks_t *p_pclk) 136static void compute_clocks(u8 pio, pio_clocks_t *p_pclk)
137{ 137{
138 int clk1, clk2; 138 int clk1, clk2;
139 int bus_speed = system_bus_clock(); /* get speed of PCI bus */ 139 int bus_speed = system_bus_clock(); /* get speed of PCI bus */
@@ -158,7 +158,7 @@ static void compute_clocks (u8 pio, pio_clocks_t *p_pclk)
158 clk1 = (clk1<<4)|clk2; /* combine active and recovery clocks */ 158 clk1 = (clk1<<4)|clk2; /* combine active and recovery clocks */
159 159
160 /* note: we use the same values for 16bit IOR and IOW 160 /* note: we use the same values for 16bit IOR and IOW
161 * those are all the same, since I don't have other 161 * those are all the same, since I don't have other
162 * timings than those from ide-lib.c 162 * timings than those from ide-lib.c
163 */ 163 */
164 164
@@ -186,7 +186,7 @@ static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode)
186 outb(index, CY82_INDEX_PORT); 186 outb(index, CY82_INDEX_PORT);
187 data = inb(CY82_DATA_PORT); 187 data = inb(CY82_DATA_PORT);
188 188
189 printk (KERN_INFO "%s (ch=%d, dev=%d): DMA mode is %d (single=%d)\n", 189 printk(KERN_INFO "%s (ch=%d, dev=%d): DMA mode is %d (single=%d)\n",
190 drive->name, HWIF(drive)->channel, drive->select.b.unit, 190 drive->name, HWIF(drive)->channel, drive->select.b.unit,
191 (data&0x3), ((data>>2)&1)); 191 (data&0x3), ((data>>2)&1));
192#endif /* CY82C693_DEBUG_LOGS */ 192#endif /* CY82C693_DEBUG_LOGS */
@@ -202,7 +202,7 @@ static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode)
202 mode & 3, single); 202 mode & 3, single);
203#endif /* CY82C693_DEBUG_INFO */ 203#endif /* CY82C693_DEBUG_INFO */
204 204
205 /* 205 /*
206 * note: below we set the value for Bus Master IDE TimeOut Register 206 * note: below we set the value for Bus Master IDE TimeOut Register
207 * I'm not absolutly sure what this does, but it solved my problem 207 * I'm not absolutly sure what this does, but it solved my problem
208 * with IDE DMA and sound, so I now can play sound and work with 208 * with IDE DMA and sound, so I now can play sound and work with
@@ -216,8 +216,8 @@ static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode)
216 outb(CY82_INDEX_TIMEOUT, CY82_INDEX_PORT); 216 outb(CY82_INDEX_TIMEOUT, CY82_INDEX_PORT);
217 outb(data, CY82_DATA_PORT); 217 outb(data, CY82_DATA_PORT);
218 218
219#if CY82C693_DEBUG_INFO 219#if CY82C693_DEBUG_INFO
220 printk (KERN_INFO "%s: Set IDE Bus Master TimeOut Register to 0x%X\n", 220 printk(KERN_INFO "%s: Set IDE Bus Master TimeOut Register to 0x%X\n",
221 drive->name, data); 221 drive->name, data);
222#endif /* CY82C693_DEBUG_INFO */ 222#endif /* CY82C693_DEBUG_INFO */
223} 223}
@@ -242,14 +242,14 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
242 242
243#if CY82C693_DEBUG_LOGS 243#if CY82C693_DEBUG_LOGS
244 /* for debug let's show the register values */ 244 /* for debug let's show the register values */
245 245
246 if (drive->select.b.unit == 0) { 246 if (drive->select.b.unit == 0) {
247 /* 247 /*
248 * get master drive registers 248 * get master drive registers
249 * address setup control register 249 * address setup control register
250 * is 32 bit !!! 250 * is 32 bit !!!
251 */ 251 */
252 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl); 252 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
253 addrCtrl &= 0x0F; 253 addrCtrl &= 0x0F;
254 254
255 /* now let's get the remaining registers */ 255 /* now let's get the remaining registers */
@@ -261,7 +261,7 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
261 * set slave drive registers 261 * set slave drive registers
262 * address setup control register 262 * address setup control register
263 * is 32 bit !!! 263 * is 32 bit !!!
264 */ 264 */
265 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl); 265 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
266 266
267 addrCtrl &= 0xF0; 267 addrCtrl &= 0xF0;
@@ -288,9 +288,9 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
288 * set master drive 288 * set master drive
289 * address setup control register 289 * address setup control register
290 * is 32 bit !!! 290 * is 32 bit !!!
291 */ 291 */
292 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl); 292 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
293 293
294 addrCtrl &= (~0xF); 294 addrCtrl &= (~0xF);
295 addrCtrl |= (unsigned int)pclk.address_time; 295 addrCtrl |= (unsigned int)pclk.address_time;
296 pci_write_config_dword(dev, CY82_IDE_ADDRSETUP, addrCtrl); 296 pci_write_config_dword(dev, CY82_IDE_ADDRSETUP, addrCtrl);
@@ -299,14 +299,14 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
299 pci_write_config_byte(dev, CY82_IDE_MASTER_IOR, pclk.time_16r); 299 pci_write_config_byte(dev, CY82_IDE_MASTER_IOR, pclk.time_16r);
300 pci_write_config_byte(dev, CY82_IDE_MASTER_IOW, pclk.time_16w); 300 pci_write_config_byte(dev, CY82_IDE_MASTER_IOW, pclk.time_16w);
301 pci_write_config_byte(dev, CY82_IDE_MASTER_8BIT, pclk.time_8); 301 pci_write_config_byte(dev, CY82_IDE_MASTER_8BIT, pclk.time_8);
302 302
303 addrCtrl &= 0xF; 303 addrCtrl &= 0xF;
304 } else { 304 } else {
305 /* 305 /*
306 * set slave drive 306 * set slave drive
307 * address setup control register 307 * address setup control register
308 * is 32 bit !!! 308 * is 32 bit !!!
309 */ 309 */
310 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl); 310 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
311 311
312 addrCtrl &= (~0xF0); 312 addrCtrl &= (~0xF0);
@@ -320,7 +320,7 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
320 320
321 addrCtrl >>= 4; 321 addrCtrl >>= 4;
322 addrCtrl &= 0xF; 322 addrCtrl &= 0xF;
323 } 323 }
324 324
325#if CY82C693_DEBUG_INFO 325#if CY82C693_DEBUG_INFO
326 printk(KERN_INFO "%s (ch=%d, dev=%d): set PIO timing to " 326 printk(KERN_INFO "%s (ch=%d, dev=%d): set PIO timing to "
@@ -340,41 +340,41 @@ static unsigned int __devinit init_chipset_cy82c693(struct pci_dev *dev, const c
340 340
341#ifdef CY82C693_SETDMA_CLOCK 341#ifdef CY82C693_SETDMA_CLOCK
342 u8 data = 0; 342 u8 data = 0;
343#endif /* CY82C693_SETDMA_CLOCK */ 343#endif /* CY82C693_SETDMA_CLOCK */
344 344
345 /* write info about this verion of the driver */ 345 /* write info about this verion of the driver */
346 printk(KERN_INFO CY82_VERSION "\n"); 346 printk(KERN_INFO CY82_VERSION "\n");
347 347
348#ifdef CY82C693_SETDMA_CLOCK 348#ifdef CY82C693_SETDMA_CLOCK
349 /* okay let's set the DMA clock speed */ 349 /* okay let's set the DMA clock speed */
350 350
351 outb(CY82_INDEX_CTRLREG1, CY82_INDEX_PORT); 351 outb(CY82_INDEX_CTRLREG1, CY82_INDEX_PORT);
352 data = inb(CY82_DATA_PORT); 352 data = inb(CY82_DATA_PORT);
353 353
354#if CY82C693_DEBUG_INFO 354#if CY82C693_DEBUG_INFO
355 printk(KERN_INFO "%s: Peripheral Configuration Register: 0x%X\n", 355 printk(KERN_INFO "%s: Peripheral Configuration Register: 0x%X\n",
356 name, data); 356 name, data);
357#endif /* CY82C693_DEBUG_INFO */ 357#endif /* CY82C693_DEBUG_INFO */
358 358
359 /* 359 /*
360 * for some reason sometimes the DMA controller 360 * for some reason sometimes the DMA controller
361 * speed is set to ATCLK/2 ???? - we fix this here 361 * speed is set to ATCLK/2 ???? - we fix this here
362 * 362 *
363 * note: i don't know what causes this strange behaviour, 363 * note: i don't know what causes this strange behaviour,
364 * but even changing the dma speed doesn't solve it :-( 364 * but even changing the dma speed doesn't solve it :-(
365 * the ide performance is still only half the normal speed 365 * the ide performance is still only half the normal speed
366 * 366 *
367 * if anybody knows what goes wrong with my machine, please 367 * if anybody knows what goes wrong with my machine, please
368 * let me know - ASK 368 * let me know - ASK
369 */ 369 */
370 370
371 data |= 0x03; 371 data |= 0x03;
372 372
373 outb(CY82_INDEX_CTRLREG1, CY82_INDEX_PORT); 373 outb(CY82_INDEX_CTRLREG1, CY82_INDEX_PORT);
374 outb(data, CY82_DATA_PORT); 374 outb(data, CY82_DATA_PORT);
375 375
376#if CY82C693_DEBUG_INFO 376#if CY82C693_DEBUG_INFO
377 printk (KERN_INFO "%s: New Peripheral Configuration Register: 0x%X\n", 377 printk(KERN_INFO "%s: New Peripheral Configuration Register: 0x%X\n",
378 name, data); 378 name, data);
379#endif /* CY82C693_DEBUG_INFO */ 379#endif /* CY82C693_DEBUG_INFO */
380 380
@@ -410,8 +410,7 @@ static const struct ide_port_info cy82c693_chipset __devinitdata = {
410 .init_iops = init_iops_cy82c693, 410 .init_iops = init_iops_cy82c693,
411 .init_hwif = init_hwif_cy82c693, 411 .init_hwif = init_hwif_cy82c693,
412 .chipset = ide_cy82c693, 412 .chipset = ide_cy82c693,
413 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_CY82C693 | 413 .host_flags = IDE_HFLAG_SINGLE,
414 IDE_HFLAG_BOOTABLE,
415 .pio_mask = ATA_PIO4, 414 .pio_mask = ATA_PIO4,
416 .swdma_mask = ATA_SWDMA2, 415 .swdma_mask = ATA_SWDMA2,
417 .mwdma_mask = ATA_MWDMA2, 416 .mwdma_mask = ATA_MWDMA2,
@@ -424,7 +423,7 @@ static int __devinit cy82c693_init_one(struct pci_dev *dev, const struct pci_dev
424 423
425 /* CY82C693 is more than only a IDE controller. 424 /* CY82C693 is more than only a IDE controller.
426 Function 1 is primary IDE channel, function 2 - secondary. */ 425 Function 1 is primary IDE channel, function 2 - secondary. */
427 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && 426 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE &&
428 PCI_FUNC(dev->devfn) == 1) { 427 PCI_FUNC(dev->devfn) == 1) {
429 dev2 = pci_get_slot(dev->bus, dev->devfn + 1); 428 dev2 = pci_get_slot(dev->bus, dev->devfn + 1);
430 ret = ide_setup_pci_devices(dev, dev2, &cy82c693_chipset); 429 ret = ide_setup_pci_devices(dev, dev2, &cy82c693_chipset);
diff --git a/drivers/ide/pci/delkin_cb.c b/drivers/ide/pci/delkin_cb.c
index 961698d655eb..753b86fc6637 100644
--- a/drivers/ide/pci/delkin_cb.c
+++ b/drivers/ide/pci/delkin_cb.c
@@ -71,14 +71,13 @@ delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
71 if (setup[i]) 71 if (setup[i])
72 outb(setup[i], base + i); 72 outb(setup[i], base + i);
73 } 73 }
74 pci_release_regions(dev); /* IDE layer handles regions itself */
75 74
76 memset(&hw, 0, sizeof(hw)); 75 memset(&hw, 0, sizeof(hw));
77 ide_std_init_ports(&hw, base + 0x10, base + 0x1e); 76 ide_std_init_ports(&hw, base + 0x10, base + 0x1e);
78 hw.irq = dev->irq; 77 hw.irq = dev->irq;
79 hw.chipset = ide_pci; /* this enables IRQ sharing */ 78 hw.chipset = ide_pci; /* this enables IRQ sharing */
80 79
81 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); 80 hwif = ide_find_port();
82 if (hwif == NULL) 81 if (hwif == NULL)
83 goto out_disable; 82 goto out_disable;
84 83
@@ -90,6 +89,7 @@ delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
90 ide_init_port_data(hwif, i); 89 ide_init_port_data(hwif, i);
91 90
92 ide_init_port_hw(hwif, &hw); 91 ide_init_port_hw(hwif, &hw);
92 hwif->mmio = 1;
93 hwif->quirkproc = &ide_undecoded_slave; 93 hwif->quirkproc = &ide_undecoded_slave;
94 94
95 idx[0] = i; 95 idx[0] = i;
@@ -110,6 +110,7 @@ delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
110 110
111out_disable: 111out_disable:
112 printk(KERN_ERR "delkin_cb: no IDE devices found\n"); 112 printk(KERN_ERR "delkin_cb: no IDE devices found\n");
113 pci_release_regions(dev);
113 pci_disable_device(dev); 114 pci_disable_device(dev);
114 return -ENODEV; 115 return -ENODEV;
115} 116}
@@ -122,6 +123,7 @@ delkin_cb_remove (struct pci_dev *dev)
122 if (hwif) 123 if (hwif)
123 ide_unregister(hwif->index); 124 ide_unregister(hwif->index);
124 125
126 pci_release_regions(dev);
125 pci_disable_device(dev); 127 pci_disable_device(dev);
126} 128}
127 129
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index 7fd83a9d4dee..041720e22762 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -38,8 +38,7 @@ MODULE_PARM_DESC(all_generic_ide, "IDE generic will claim all unknown PCI IDE st
38 { \ 38 { \
39 .name = name_str, \ 39 .name = name_str, \
40 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA | \ 40 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA | \
41 extra_flags | \ 41 extra_flags, \
42 IDE_HFLAG_BOOTABLE, \
43 .swdma_mask = ATA_SWDMA2, \ 42 .swdma_mask = ATA_SWDMA2, \
44 .mwdma_mask = ATA_MWDMA2, \ 43 .mwdma_mask = ATA_MWDMA2, \
45 .udma_mask = ATA_UDMA6, \ 44 .udma_mask = ATA_UDMA6, \
@@ -50,9 +49,8 @@ static const struct ide_port_info generic_chipsets[] __devinitdata = {
50 49
51 { /* 1 */ 50 { /* 1 */
52 .name = "NS87410", 51 .name = "NS87410",
53 .enablebits = {{0x43,0x08,0x08}, {0x47,0x08,0x08}}, 52 .enablebits = { {0x43, 0x08, 0x08}, {0x47, 0x08, 0x08} },
54 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA | 53 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA,
55 IDE_HFLAG_BOOTABLE,
56 .swdma_mask = ATA_SWDMA2, 54 .swdma_mask = ATA_SWDMA2,
57 .mwdma_mask = ATA_MWDMA2, 55 .mwdma_mask = ATA_MWDMA2,
58 .udma_mask = ATA_UDMA6, 56 .udma_mask = ATA_UDMA6,
@@ -99,7 +97,7 @@ static const struct ide_port_info generic_chipsets[] __devinitdata = {
99 * Called when the PCI registration layer (or the IDE initialization) 97 * Called when the PCI registration layer (or the IDE initialization)
100 * finds a device matching our IDE device tables. 98 * finds a device matching our IDE device tables.
101 */ 99 */
102 100
103static int __devinit generic_init_one(struct pci_dev *dev, const struct pci_device_id *id) 101static int __devinit generic_init_one(struct pci_dev *dev, const struct pci_device_id *id)
104{ 102{
105 const struct ide_port_info *d = &generic_chipsets[id->driver_data]; 103 const struct ide_port_info *d = &generic_chipsets[id->driver_data];
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c
index 9f01da46b016..9f2fc3094000 100644
--- a/drivers/ide/pci/hpt34x.c
+++ b/drivers/ide/pci/hpt34x.c
@@ -133,7 +133,7 @@ static const struct ide_port_info hpt34x_chipsets[] __devinitdata = {
133 .init_chipset = init_chipset_hpt34x, 133 .init_chipset = init_chipset_hpt34x,
134 .init_hwif = init_hwif_hpt34x, 134 .init_hwif = init_hwif_hpt34x,
135 .extra = 16, 135 .extra = 16,
136 .host_flags = IDE_HFLAGS_HPT34X, 136 .host_flags = IDE_HFLAGS_HPT34X | IDE_HFLAG_NON_BOOTABLE,
137 .pio_mask = ATA_PIO5, 137 .pio_mask = ATA_PIO5,
138 }, 138 },
139 { /* 1 */ 139 { /* 1 */
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index 82d0e318a1fe..a49090672145 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -1557,7 +1557,7 @@ static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_devic
1557 hpt374_init(dev, dev2); 1557 hpt374_init(dev, dev2);
1558 else { 1558 else {
1559 if (hpt36x_init(dev, dev2)) 1559 if (hpt36x_init(dev, dev2))
1560 d.host_flags |= IDE_HFLAG_BOOTABLE; 1560 d.host_flags &= ~IDE_HFLAG_NON_BOOTABLE;
1561 } 1561 }
1562 1562
1563 ret = ide_setup_pci_devices(dev, dev2, &d); 1563 ret = ide_setup_pci_devices(dev, dev2, &d);
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/pci/it8213.c
index e3427eaab430..5b5b0cc4b76a 100644
--- a/drivers/ide/pci/it8213.c
+++ b/drivers/ide/pci/it8213.c
@@ -35,7 +35,7 @@ static void it8213_set_pio_mode(ide_drive_t *drive, const u8 pio)
35 static DEFINE_SPINLOCK(tune_lock); 35 static DEFINE_SPINLOCK(tune_lock);
36 int control = 0; 36 int control = 0;
37 37
38 static const u8 timings[][2]= { 38 static const u8 timings[][2] = {
39 { 0, 0 }, 39 { 0, 0 },
40 { 0, 0 }, 40 { 0, 0 },
41 { 1, 0 }, 41 { 1, 0 },
@@ -105,11 +105,10 @@ static void it8213_set_dma_mode(ide_drive_t *drive, const u8 speed)
105 105
106 if (!(reg48 & u_flag)) 106 if (!(reg48 & u_flag))
107 pci_write_config_byte(dev, 0x48, reg48 | u_flag); 107 pci_write_config_byte(dev, 0x48, reg48 | u_flag);
108 if (speed >= XFER_UDMA_5) { 108 if (speed >= XFER_UDMA_5)
109 pci_write_config_byte(dev, 0x55, (u8) reg55|w_flag); 109 pci_write_config_byte(dev, 0x55, (u8) reg55|w_flag);
110 } else { 110 else
111 pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag); 111 pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag);
112 }
113 112
114 if ((reg4a & a_speed) != u_speed) 113 if ((reg4a & a_speed) != u_speed)
115 pci_write_config_word(dev, 0x4a, (reg4a & ~a_speed) | u_speed); 114 pci_write_config_word(dev, 0x4a, (reg4a & ~a_speed) | u_speed);
@@ -170,9 +169,8 @@ static void __devinit init_hwif_it8213(ide_hwif_t *hwif)
170 { \ 169 { \
171 .name = name_str, \ 170 .name = name_str, \
172 .init_hwif = init_hwif_it8213, \ 171 .init_hwif = init_hwif_it8213, \
173 .enablebits = {{0x41,0x80,0x80}}, \ 172 .enablebits = { {0x41, 0x80, 0x80} }, \
174 .host_flags = IDE_HFLAG_SINGLE | \ 173 .host_flags = IDE_HFLAG_SINGLE, \
175 IDE_HFLAG_BOOTABLE, \
176 .pio_mask = ATA_PIO4, \ 174 .pio_mask = ATA_PIO4, \
177 .swdma_mask = ATA_SWDMA2_ONLY, \ 175 .swdma_mask = ATA_SWDMA2_ONLY, \
178 .mwdma_mask = ATA_MWDMA12_ONLY, \ 176 .mwdma_mask = ATA_MWDMA12_ONLY, \
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
index d8a167451fd6..a38ec47423a0 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/pci/it821x.c
@@ -523,16 +523,12 @@ static void __devinit it821x_quirkproc(ide_drive_t *drive)
523static void __devinit init_hwif_it821x(ide_hwif_t *hwif) 523static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
524{ 524{
525 struct pci_dev *dev = to_pci_dev(hwif->dev); 525 struct pci_dev *dev = to_pci_dev(hwif->dev);
526 struct it821x_dev *idev = kzalloc(sizeof(struct it821x_dev), GFP_KERNEL); 526 struct it821x_dev **itdevs = (struct it821x_dev **)pci_get_drvdata(dev);
527 struct it821x_dev *idev = itdevs[hwif->channel];
527 u8 conf; 528 u8 conf;
528 529
529 hwif->quirkproc = &it821x_quirkproc; 530 hwif->quirkproc = &it821x_quirkproc;
530 531
531 if (idev == NULL) {
532 printk(KERN_ERR "it821x: out of memory, falling back to legacy behaviour.\n");
533 return;
534 }
535
536 ide_set_hwifdata(hwif, idev); 532 ide_set_hwifdata(hwif, idev);
537 533
538 pci_read_config_byte(dev, 0x50, &conf); 534 pci_read_config_byte(dev, 0x50, &conf);
@@ -623,7 +619,6 @@ static unsigned int __devinit init_chipset_it821x(struct pci_dev *dev, const cha
623 .name = name_str, \ 619 .name = name_str, \
624 .init_chipset = init_chipset_it821x, \ 620 .init_chipset = init_chipset_it821x, \
625 .init_hwif = init_hwif_it821x, \ 621 .init_hwif = init_hwif_it821x, \
626 .host_flags = IDE_HFLAG_BOOTABLE, \
627 .pio_mask = ATA_PIO4, \ 622 .pio_mask = ATA_PIO4, \
628 } 623 }
629 624
@@ -642,6 +637,22 @@ static const struct ide_port_info it821x_chipsets[] __devinitdata = {
642 637
643static int __devinit it821x_init_one(struct pci_dev *dev, const struct pci_device_id *id) 638static int __devinit it821x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
644{ 639{
640 struct it821x_dev *itdevs[2] = { NULL, NULL} , *itdev;
641 unsigned int i;
642
643 for (i = 0; i < 2; i++) {
644 itdev = kzalloc(sizeof(*itdev), GFP_KERNEL);
645 if (itdev == NULL) {
646 kfree(itdevs[0]);
647 printk(KERN_ERR "it821x: out of memory\n");
648 return -ENOMEM;
649 }
650
651 itdevs[i] = itdev;
652 }
653
654 pci_set_drvdata(dev, itdevs);
655
645 return ide_setup_pci_device(dev, &it821x_chipsets[id->driver_data]); 656 return ide_setup_pci_device(dev, &it821x_chipsets[id->driver_data]);
646} 657}
647 658
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
index a56bcb4f22f4..673f7dc8ba65 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/pci/jmicron.c
@@ -63,8 +63,7 @@ static u8 __devinit ata66_jmicron(ide_hwif_t *hwif)
63 * actually do our cable checking etc. Thankfully we don't need 63 * actually do our cable checking etc. Thankfully we don't need
64 * to do the plumbing for other cases. 64 * to do the plumbing for other cases.
65 */ 65 */
66 switch (port_map[port]) 66 switch (port_map[port]) {
67 {
68 case PORT_PATA0: 67 case PORT_PATA0:
69 if (control & (1 << 3)) /* 40/80 pin primary */ 68 if (control & (1 << 3)) /* 40/80 pin primary */
70 return ATA_CBL_PATA40; 69 return ATA_CBL_PATA40;
@@ -114,7 +113,6 @@ static void __devinit init_hwif_jmicron(ide_hwif_t *hwif)
114static const struct ide_port_info jmicron_chipset __devinitdata = { 113static const struct ide_port_info jmicron_chipset __devinitdata = {
115 .name = "JMB", 114 .name = "JMB",
116 .init_hwif = init_hwif_jmicron, 115 .init_hwif = init_hwif_jmicron,
117 .host_flags = IDE_HFLAG_BOOTABLE,
118 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } }, 116 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
119 .pio_mask = ATA_PIO5, 117 .pio_mask = ATA_PIO5,
120 .mwdma_mask = ATA_MWDMA2, 118 .mwdma_mask = ATA_MWDMA2,
diff --git a/drivers/ide/pci/ns87415.c b/drivers/ide/pci/ns87415.c
index 75513320aad9..3015d6916d4c 100644
--- a/drivers/ide/pci/ns87415.c
+++ b/drivers/ide/pci/ns87415.c
@@ -265,8 +265,7 @@ static const struct ide_port_info ns87415_chipset __devinitdata = {
265#endif 265#endif
266 .init_hwif = init_hwif_ns87415, 266 .init_hwif = init_hwif_ns87415,
267 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA | 267 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA |
268 IDE_HFLAG_NO_ATAPI_DMA | 268 IDE_HFLAG_NO_ATAPI_DMA,
269 IDE_HFLAG_BOOTABLE,
270}; 269};
271 270
272static int __devinit ns87415_init_one(struct pci_dev *dev, const struct pci_device_id *id) 271static int __devinit ns87415_init_one(struct pci_dev *dev, const struct pci_device_id *id)
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/pci/opti621.c
index 46e8748f507e..88a4dd94eeea 100644
--- a/drivers/ide/pci/opti621.c
+++ b/drivers/ide/pci/opti621.c
@@ -57,9 +57,9 @@
57 * (use idebus=xx to select PCI bus speed). 57 * (use idebus=xx to select PCI bus speed).
58 * 58 *
59 * Version 0.1, Nov 8, 1996 59 * Version 0.1, Nov 8, 1996
60 * by Jaromir Koutek, for 2.1.8. 60 * by Jaromir Koutek, for 2.1.8.
61 * Initial version of driver. 61 * Initial version of driver.
62 * 62 *
63 * Version 0.2 63 * Version 0.2
64 * Number 0.2 skipped. 64 * Number 0.2 skipped.
65 * 65 *
@@ -75,7 +75,7 @@
75 * by Jaromir Koutek 75 * by Jaromir Koutek
76 * Updates for use with (again) new IDE block driver. 76 * Updates for use with (again) new IDE block driver.
77 * Update of documentation. 77 * Update of documentation.
78 * 78 *
79 * Version 0.6, Jan 2, 1999 79 * Version 0.6, Jan 2, 1999
80 * by Jaromir Koutek 80 * by Jaromir Koutek
81 * Reversed to version 0.3 of the driver, because 81 * Reversed to version 0.3 of the driver, because
@@ -208,29 +208,34 @@ typedef struct pio_clocks_s {
208 208
209static void compute_clocks(int pio, pio_clocks_t *clks) 209static void compute_clocks(int pio, pio_clocks_t *clks)
210{ 210{
211 if (pio != PIO_NOT_EXIST) { 211 if (pio != PIO_NOT_EXIST) {
212 int adr_setup, data_pls; 212 int adr_setup, data_pls;
213 int bus_speed = system_bus_clock(); 213 int bus_speed = system_bus_clock();
214 214
215 adr_setup = ide_pio_timings[pio].setup_time; 215 adr_setup = ide_pio_timings[pio].setup_time;
216 data_pls = ide_pio_timings[pio].active_time; 216 data_pls = ide_pio_timings[pio].active_time;
217 clks->address_time = cmpt_clk(adr_setup, bus_speed); 217 clks->address_time = cmpt_clk(adr_setup, bus_speed);
218 clks->data_time = cmpt_clk(data_pls, bus_speed); 218 clks->data_time = cmpt_clk(data_pls, bus_speed);
219 clks->recovery_time = cmpt_clk(ide_pio_timings[pio].cycle_time 219 clks->recovery_time = cmpt_clk(ide_pio_timings[pio].cycle_time
220 - adr_setup-data_pls, bus_speed); 220 - adr_setup-data_pls, bus_speed);
221 if (clks->address_time<1) clks->address_time = 1; 221 if (clks->address_time < 1)
222 if (clks->address_time>4) clks->address_time = 4; 222 clks->address_time = 1;
223 if (clks->data_time<1) clks->data_time = 1; 223 if (clks->address_time > 4)
224 if (clks->data_time>16) clks->data_time = 16; 224 clks->address_time = 4;
225 if (clks->recovery_time<2) clks->recovery_time = 2; 225 if (clks->data_time < 1)
226 if (clks->recovery_time>17) clks->recovery_time = 17; 226 clks->data_time = 1;
227 if (clks->data_time > 16)
228 clks->data_time = 16;
229 if (clks->recovery_time < 2)
230 clks->recovery_time = 2;
231 if (clks->recovery_time > 17)
232 clks->recovery_time = 17;
227 } else { 233 } else {
228 clks->address_time = 1; 234 clks->address_time = 1;
229 clks->data_time = 1; 235 clks->data_time = 1;
230 clks->recovery_time = 2; 236 clks->recovery_time = 2;
231 /* minimal values */ 237 /* minimal values */
232 } 238 }
233
234} 239}
235 240
236static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio) 241static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio)
@@ -247,8 +252,8 @@ static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio)
247 252
248 /* sets drive->drive_data for both drives */ 253 /* sets drive->drive_data for both drives */
249 compute_pios(drive, pio); 254 compute_pios(drive, pio);
250 pio1 = hwif->drives[0].drive_data; 255 pio1 = hwif->drives[0].drive_data;
251 pio2 = hwif->drives[1].drive_data; 256 pio2 = hwif->drives[1].drive_data;
252 257
253 compute_clocks(pio1, &first); 258 compute_clocks(pio1, &first);
254 compute_clocks(pio2, &second); 259 compute_clocks(pio2, &second);
@@ -275,7 +280,7 @@ static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio)
275 280
276 spin_lock_irqsave(&opti621_lock, flags); 281 spin_lock_irqsave(&opti621_lock, flags);
277 282
278 reg_base = hwif->io_ports[IDE_DATA_OFFSET]; 283 reg_base = hwif->io_ports[IDE_DATA_OFFSET];
279 284
280 /* allow Register-B */ 285 /* allow Register-B */
281 outb(0xc0, reg_base + CNTRL_REG); 286 outb(0xc0, reg_base + CNTRL_REG);
@@ -324,7 +329,7 @@ static void __devinit opti621_port_init_devs(ide_hwif_t *hwif)
324/* 329/*
325 * init_hwif_opti621() is called once for each hwif found at boot. 330 * init_hwif_opti621() is called once for each hwif found at boot.
326 */ 331 */
327static void __devinit init_hwif_opti621 (ide_hwif_t *hwif) 332static void __devinit init_hwif_opti621(ide_hwif_t *hwif)
328{ 333{
329 hwif->port_init_devs = opti621_port_init_devs; 334 hwif->port_init_devs = opti621_port_init_devs;
330 hwif->set_pio_mode = &opti621_set_pio_mode; 335 hwif->set_pio_mode = &opti621_set_pio_mode;
@@ -334,18 +339,16 @@ static const struct ide_port_info opti621_chipsets[] __devinitdata = {
334 { /* 0 */ 339 { /* 0 */
335 .name = "OPTI621", 340 .name = "OPTI621",
336 .init_hwif = init_hwif_opti621, 341 .init_hwif = init_hwif_opti621,
337 .enablebits = {{0x45,0x80,0x00}, {0x40,0x08,0x00}}, 342 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
338 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA | 343 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA,
339 IDE_HFLAG_BOOTABLE,
340 .pio_mask = ATA_PIO3, 344 .pio_mask = ATA_PIO3,
341 .swdma_mask = ATA_SWDMA2, 345 .swdma_mask = ATA_SWDMA2,
342 .mwdma_mask = ATA_MWDMA2, 346 .mwdma_mask = ATA_MWDMA2,
343 },{ /* 1 */ 347 }, { /* 1 */
344 .name = "OPTI621X", 348 .name = "OPTI621X",
345 .init_hwif = init_hwif_opti621, 349 .init_hwif = init_hwif_opti621,
346 .enablebits = {{0x45,0x80,0x00}, {0x40,0x08,0x00}}, 350 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
347 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA | 351 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA,
348 IDE_HFLAG_BOOTABLE,
349 .pio_mask = ATA_PIO3, 352 .pio_mask = ATA_PIO3,
350 .swdma_mask = ATA_SWDMA2, 353 .swdma_mask = ATA_SWDMA2,
351 .mwdma_mask = ATA_MWDMA2, 354 .mwdma_mask = ATA_MWDMA2,
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index decef0f47674..89d74ffdb207 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -307,9 +307,9 @@ static void __devinit init_hwif_ich(ide_hwif_t *hwif)
307} 307}
308 308
309#ifndef CONFIG_IA64 309#ifndef CONFIG_IA64
310 #define IDE_HFLAGS_PIIX (IDE_HFLAG_LEGACY_IRQS | IDE_HFLAG_BOOTABLE) 310 #define IDE_HFLAGS_PIIX IDE_HFLAG_LEGACY_IRQS
311#else 311#else
312 #define IDE_HFLAGS_PIIX IDE_HFLAG_BOOTABLE 312 #define IDE_HFLAGS_PIIX 0
313#endif 313#endif
314 314
315#define DECLARE_PIIX_DEV(name_str, udma) \ 315#define DECLARE_PIIX_DEV(name_str, udma) \
diff --git a/drivers/ide/pci/rz1000.c b/drivers/ide/pci/rz1000.c
index 51676612f78f..532154adba29 100644
--- a/drivers/ide/pci/rz1000.c
+++ b/drivers/ide/pci/rz1000.c
@@ -43,7 +43,7 @@ static const struct ide_port_info rz1000_chipset __devinitdata = {
43 .name = "RZ100x", 43 .name = "RZ100x",
44 .init_hwif = init_hwif_rz1000, 44 .init_hwif = init_hwif_rz1000,
45 .chipset = ide_rz1000, 45 .chipset = ide_rz1000,
46 .host_flags = IDE_HFLAG_NO_DMA | IDE_HFLAG_BOOTABLE, 46 .host_flags = IDE_HFLAG_NO_DMA,
47}; 47};
48 48
49static int __devinit rz1000_init_one(struct pci_dev *dev, const struct pci_device_id *id) 49static int __devinit rz1000_init_one(struct pci_dev *dev, const struct pci_device_id *id)
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index 561aa47c7720..44985c8f36e7 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -307,8 +307,7 @@ static const struct ide_port_info sc1200_chipset __devinitdata = {
307 .init_hwif = init_hwif_sc1200, 307 .init_hwif = init_hwif_sc1200,
308 .host_flags = IDE_HFLAG_SERIALIZE | 308 .host_flags = IDE_HFLAG_SERIALIZE |
309 IDE_HFLAG_POST_SET_MODE | 309 IDE_HFLAG_POST_SET_MODE |
310 IDE_HFLAG_ABUSE_DMA_MODES | 310 IDE_HFLAG_ABUSE_DMA_MODES,
311 IDE_HFLAG_BOOTABLE,
312 .pio_mask = ATA_PIO4, 311 .pio_mask = ATA_PIO4,
313 .mwdma_mask = ATA_MWDMA2, 312 .mwdma_mask = ATA_MWDMA2,
314 .udma_mask = ATA_UDMA2, 313 .udma_mask = ATA_UDMA2,
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/pci/scc_pata.c
index ef07c7a8b97a..52145796f12f 100644
--- a/drivers/ide/pci/scc_pata.c
+++ b/drivers/ide/pci/scc_pata.c
@@ -65,7 +65,7 @@
65 65
66static struct scc_ports { 66static struct scc_ports {
67 unsigned long ctl, dma; 67 unsigned long ctl, dma;
68 unsigned char hwif_id; /* for removing hwif from system */ 68 ide_hwif_t *hwif; /* for removing port from system */
69} scc_ports[MAX_HWIFS]; 69} scc_ports[MAX_HWIFS];
70 70
71/* PIO transfer mode table */ 71/* PIO transfer mode table */
@@ -534,12 +534,8 @@ static int scc_ide_setup_pci_device(struct pci_dev *dev,
534 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; 534 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
535 int i; 535 int i;
536 536
537 for (i = 0; i < MAX_HWIFS; i++) { 537 hwif = ide_find_port();
538 hwif = &ide_hwifs[i]; 538 if (hwif == NULL) {
539 if (hwif->chipset == ide_unknown)
540 break; /* pick an unused entry */
541 }
542 if (i == MAX_HWIFS) {
543 printk(KERN_ERR "%s: too many IDE interfaces, " 539 printk(KERN_ERR "%s: too many IDE interfaces, "
544 "no room in table\n", SCC_PATA_NAME); 540 "no room in table\n", SCC_PATA_NAME);
545 return -ENOMEM; 541 return -ENOMEM;
@@ -696,7 +692,7 @@ static void __devinit init_hwif_scc(ide_hwif_t *hwif)
696{ 692{
697 struct scc_ports *ports = ide_get_hwifdata(hwif); 693 struct scc_ports *ports = ide_get_hwifdata(hwif);
698 694
699 ports->hwif_id = hwif->index; 695 ports->hwif = hwif;
700 696
701 hwif->dma_command = hwif->dma_base; 697 hwif->dma_command = hwif->dma_base;
702 hwif->dma_status = hwif->dma_base + 0x04; 698 hwif->dma_status = hwif->dma_base + 0x04;
@@ -725,8 +721,7 @@ static void __devinit init_hwif_scc(ide_hwif_t *hwif)
725 .name = name_str, \ 721 .name = name_str, \
726 .init_iops = init_iops_scc, \ 722 .init_iops = init_iops_scc, \
727 .init_hwif = init_hwif_scc, \ 723 .init_hwif = init_hwif_scc, \
728 .host_flags = IDE_HFLAG_SINGLE | \ 724 .host_flags = IDE_HFLAG_SINGLE, \
729 IDE_HFLAG_BOOTABLE, \
730 .pio_mask = ATA_PIO4, \ 725 .pio_mask = ATA_PIO4, \
731 } 726 }
732 727
@@ -758,7 +753,7 @@ static int __devinit scc_init_one(struct pci_dev *dev, const struct pci_device_i
758static void __devexit scc_remove(struct pci_dev *dev) 753static void __devexit scc_remove(struct pci_dev *dev)
759{ 754{
760 struct scc_ports *ports = pci_get_drvdata(dev); 755 struct scc_ports *ports = pci_get_drvdata(dev);
761 ide_hwif_t *hwif = &ide_hwifs[ports->hwif_id]; 756 ide_hwif_t *hwif = ports->hwif;
762 unsigned long ctl_base = pci_resource_start(dev, 0); 757 unsigned long ctl_base = pci_resource_start(dev, 0);
763 unsigned long dma_base = pci_resource_start(dev, 1); 758 unsigned long dma_base = pci_resource_start(dev, 1);
764 unsigned long ctl_size = pci_resource_len(dev, 0); 759 unsigned long ctl_size = pci_resource_len(dev, 0);
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index c11880b0709f..cfe927469793 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -350,8 +350,7 @@ static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
350 350
351#define IDE_HFLAGS_SVWKS \ 351#define IDE_HFLAGS_SVWKS \
352 (IDE_HFLAG_LEGACY_IRQS | \ 352 (IDE_HFLAG_LEGACY_IRQS | \
353 IDE_HFLAG_ABUSE_SET_DMA_MODE | \ 353 IDE_HFLAG_ABUSE_SET_DMA_MODE)
354 IDE_HFLAG_BOOTABLE)
355 354
356static const struct ide_port_info serverworks_chipsets[] __devinitdata = { 355static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
357 { /* 0 */ 356 { /* 0 */
@@ -418,7 +417,7 @@ static int __devinit svwks_init_one(struct pci_dev *dev, const struct pci_device
418 else if (idx == 2 || idx == 3) { 417 else if (idx == 2 || idx == 3) {
419 if ((PCI_FUNC(dev->devfn) & 1) == 0) { 418 if ((PCI_FUNC(dev->devfn) & 1) == 0) {
420 if (pci_resource_start(dev, 0) != 0x01f1) 419 if (pci_resource_start(dev, 0) != 0x01f1)
421 d.host_flags &= ~IDE_HFLAG_BOOTABLE; 420 d.host_flags |= IDE_HFLAG_NON_BOOTABLE;
422 d.host_flags |= IDE_HFLAG_SINGLE; 421 d.host_flags |= IDE_HFLAG_SINGLE;
423 } else 422 } else
424 d.host_flags &= ~IDE_HFLAG_SINGLE; 423 d.host_flags &= ~IDE_HFLAG_SINGLE;
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c
index 9d1a3038af9b..6bd9523cf642 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/pci/sgiioc4.c
@@ -590,20 +590,12 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
590 unsigned long bar0, cmd_phys_base, ctl; 590 unsigned long bar0, cmd_phys_base, ctl;
591 void __iomem *virt_base; 591 void __iomem *virt_base;
592 ide_hwif_t *hwif; 592 ide_hwif_t *hwif;
593 int h;
594 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; 593 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
595 hw_regs_t hw; 594 hw_regs_t hw;
596 struct ide_port_info d = sgiioc4_port_info; 595 struct ide_port_info d = sgiioc4_port_info;
597 596
598 /* 597 hwif = ide_find_port();
599 * Find an empty HWIF; if none available, return -ENOMEM. 598 if (hwif == NULL) {
600 */
601 for (h = 0; h < MAX_HWIFS; ++h) {
602 hwif = &ide_hwifs[h];
603 if (hwif->chipset == ide_unknown)
604 break;
605 }
606 if (h == MAX_HWIFS) {
607 printk(KERN_ERR "%s: too many IDE interfaces, no room in table\n", 599 printk(KERN_ERR "%s: too many IDE interfaces, no room in table\n",
608 DRV_NAME); 600 DRV_NAME);
609 return -ENOMEM; 601 return -ENOMEM;
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index b6be1b45f329..c9ecab8aeb61 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -808,7 +808,6 @@ static void __devinit init_hwif_siimage(ide_hwif_t *hwif)
808 .init_chipset = init_chipset_siimage, \ 808 .init_chipset = init_chipset_siimage, \
809 .init_iops = init_iops_siimage, \ 809 .init_iops = init_iops_siimage, \
810 .init_hwif = init_hwif_siimage, \ 810 .init_hwif = init_hwif_siimage, \
811 .host_flags = IDE_HFLAG_BOOTABLE, \
812 .pio_mask = ATA_PIO4, \ 811 .pio_mask = ATA_PIO4, \
813 .mwdma_mask = ATA_MWDMA2, \ 812 .mwdma_mask = ATA_MWDMA2, \
814 .udma_mask = ATA_UDMA6, \ 813 .udma_mask = ATA_UDMA6, \
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 512bb4c1fd5c..181b647e5ca9 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -59,10 +59,10 @@
59#define ATA_16 0x01 59#define ATA_16 0x01
60#define ATA_33 0x02 60#define ATA_33 0x02
61#define ATA_66 0x03 61#define ATA_66 0x03
62#define ATA_100a 0x04 // SiS730/SiS550 is ATA100 with ATA66 layout 62#define ATA_100a 0x04 /* SiS730/SiS550 is ATA100 with ATA66 layout */
63#define ATA_100 0x05 63#define ATA_100 0x05
64#define ATA_133a 0x06 // SiS961b with 133 support 64#define ATA_133a 0x06 /* SiS961b with 133 support */
65#define ATA_133 0x07 // SiS962/963 65#define ATA_133 0x07 /* SiS962/963 */
66 66
67static u8 chipset_family; 67static u8 chipset_family;
68 68
@@ -111,69 +111,70 @@ static const struct {
111 Indexed by chipset_family and (dma_mode - XFER_UDMA_0) */ 111 Indexed by chipset_family and (dma_mode - XFER_UDMA_0) */
112 112
113/* {0, ATA_16, ATA_33, ATA_66, ATA_100a, ATA_100, ATA_133} */ 113/* {0, ATA_16, ATA_33, ATA_66, ATA_100a, ATA_100, ATA_133} */
114static u8 cycle_time_offset[] = {0,0,5,4,4,0,0}; 114static u8 cycle_time_offset[] = { 0, 0, 5, 4, 4, 0, 0 };
115static u8 cycle_time_range[] = {0,0,2,3,3,4,4}; 115static u8 cycle_time_range[] = { 0, 0, 2, 3, 3, 4, 4 };
116static u8 cycle_time_value[][XFER_UDMA_6 - XFER_UDMA_0 + 1] = { 116static u8 cycle_time_value[][XFER_UDMA_6 - XFER_UDMA_0 + 1] = {
117 {0,0,0,0,0,0,0}, /* no udma */ 117 { 0, 0, 0, 0, 0, 0, 0 }, /* no UDMA */
118 {0,0,0,0,0,0,0}, /* no udma */ 118 { 0, 0, 0, 0, 0, 0, 0 }, /* no UDMA */
119 {3,2,1,0,0,0,0}, /* ATA_33 */ 119 { 3, 2, 1, 0, 0, 0, 0 }, /* ATA_33 */
120 {7,5,3,2,1,0,0}, /* ATA_66 */ 120 { 7, 5, 3, 2, 1, 0, 0 }, /* ATA_66 */
121 {7,5,3,2,1,0,0}, /* ATA_100a (730 specific), differences are on cycle_time range and offset */ 121 { 7, 5, 3, 2, 1, 0, 0 }, /* ATA_100a (730 specific),
122 {11,7,5,4,2,1,0}, /* ATA_100 */ 122 different cycle_time range and offset */
123 {15,10,7,5,3,2,1}, /* ATA_133a (earliest 691 southbridges) */ 123 { 11, 7, 5, 4, 2, 1, 0 }, /* ATA_100 */
124 {15,10,7,5,3,2,1}, /* ATA_133 */ 124 { 15, 10, 7, 5, 3, 2, 1 }, /* ATA_133a (earliest 691 southbridges) */
125 { 15, 10, 7, 5, 3, 2, 1 }, /* ATA_133 */
125}; 126};
126/* CRC Valid Setup Time vary across IDE clock setting 33/66/100/133 127/* CRC Valid Setup Time vary across IDE clock setting 33/66/100/133
127 See SiS962 data sheet for more detail */ 128 See SiS962 data sheet for more detail */
128static u8 cvs_time_value[][XFER_UDMA_6 - XFER_UDMA_0 + 1] = { 129static u8 cvs_time_value[][XFER_UDMA_6 - XFER_UDMA_0 + 1] = {
129 {0,0,0,0,0,0,0}, /* no udma */ 130 { 0, 0, 0, 0, 0, 0, 0 }, /* no UDMA */
130 {0,0,0,0,0,0,0}, /* no udma */ 131 { 0, 0, 0, 0, 0, 0, 0 }, /* no UDMA */
131 {2,1,1,0,0,0,0}, 132 { 2, 1, 1, 0, 0, 0, 0 },
132 {4,3,2,1,0,0,0}, 133 { 4, 3, 2, 1, 0, 0, 0 },
133 {4,3,2,1,0,0,0}, 134 { 4, 3, 2, 1, 0, 0, 0 },
134 {6,4,3,1,1,1,0}, 135 { 6, 4, 3, 1, 1, 1, 0 },
135 {9,6,4,2,2,2,2}, 136 { 9, 6, 4, 2, 2, 2, 2 },
136 {9,6,4,2,2,2,2}, 137 { 9, 6, 4, 2, 2, 2, 2 },
137}; 138};
138/* Initialize time, Active time, Recovery time vary across 139/* Initialize time, Active time, Recovery time vary across
139 IDE clock settings. These 3 arrays hold the register value 140 IDE clock settings. These 3 arrays hold the register value
140 for PIO0/1/2/3/4 and DMA0/1/2 mode in order */ 141 for PIO0/1/2/3/4 and DMA0/1/2 mode in order */
141static u8 ini_time_value[][8] = { 142static u8 ini_time_value[][8] = {
142 {0,0,0,0,0,0,0,0}, 143 { 0, 0, 0, 0, 0, 0, 0, 0 },
143 {0,0,0,0,0,0,0,0}, 144 { 0, 0, 0, 0, 0, 0, 0, 0 },
144 {2,1,0,0,0,1,0,0}, 145 { 2, 1, 0, 0, 0, 1, 0, 0 },
145 {4,3,1,1,1,3,1,1}, 146 { 4, 3, 1, 1, 1, 3, 1, 1 },
146 {4,3,1,1,1,3,1,1}, 147 { 4, 3, 1, 1, 1, 3, 1, 1 },
147 {6,4,2,2,2,4,2,2}, 148 { 6, 4, 2, 2, 2, 4, 2, 2 },
148 {9,6,3,3,3,6,3,3}, 149 { 9, 6, 3, 3, 3, 6, 3, 3 },
149 {9,6,3,3,3,6,3,3}, 150 { 9, 6, 3, 3, 3, 6, 3, 3 },
150}; 151};
151static u8 act_time_value[][8] = { 152static u8 act_time_value[][8] = {
152 {0,0,0,0,0,0,0,0}, 153 { 0, 0, 0, 0, 0, 0, 0, 0 },
153 {0,0,0,0,0,0,0,0}, 154 { 0, 0, 0, 0, 0, 0, 0, 0 },
154 {9,9,9,2,2,7,2,2}, 155 { 9, 9, 9, 2, 2, 7, 2, 2 },
155 {19,19,19,5,4,14,5,4}, 156 { 19, 19, 19, 5, 4, 14, 5, 4 },
156 {19,19,19,5,4,14,5,4}, 157 { 19, 19, 19, 5, 4, 14, 5, 4 },
157 {28,28,28,7,6,21,7,6}, 158 { 28, 28, 28, 7, 6, 21, 7, 6 },
158 {38,38,38,10,9,28,10,9}, 159 { 38, 38, 38, 10, 9, 28, 10, 9 },
159 {38,38,38,10,9,28,10,9}, 160 { 38, 38, 38, 10, 9, 28, 10, 9 },
160}; 161};
161static u8 rco_time_value[][8] = { 162static u8 rco_time_value[][8] = {
162 {0,0,0,0,0,0,0,0}, 163 { 0, 0, 0, 0, 0, 0, 0, 0 },
163 {0,0,0,0,0,0,0,0}, 164 { 0, 0, 0, 0, 0, 0, 0, 0 },
164 {9,2,0,2,0,7,1,1}, 165 { 9, 2, 0, 2, 0, 7, 1, 1 },
165 {19,5,1,5,2,16,3,2}, 166 { 19, 5, 1, 5, 2, 16, 3, 2 },
166 {19,5,1,5,2,16,3,2}, 167 { 19, 5, 1, 5, 2, 16, 3, 2 },
167 {30,9,3,9,4,25,6,4}, 168 { 30, 9, 3, 9, 4, 25, 6, 4 },
168 {40,12,4,12,5,34,12,5}, 169 { 40, 12, 4, 12, 5, 34, 12, 5 },
169 {40,12,4,12,5,34,12,5}, 170 { 40, 12, 4, 12, 5, 34, 12, 5 },
170}; 171};
171 172
172/* 173/*
173 * Printing configuration 174 * Printing configuration
174 */ 175 */
175/* Used for chipset type printing at boot time */ 176/* Used for chipset type printing at boot time */
176static char* chipset_capability[] = { 177static char *chipset_capability[] = {
177 "ATA", "ATA 16", 178 "ATA", "ATA 16",
178 "ATA 33", "ATA 66", 179 "ATA 33", "ATA 66",
179 "ATA 100 (1st gen)", "ATA 100 (2nd gen)", 180 "ATA 100 (1st gen)", "ATA 100 (2nd gen)",
@@ -272,7 +273,7 @@ static void sis_program_timings(ide_drive_t *drive, const u8 mode)
272 sis_ata133_program_timings(drive, mode); 273 sis_ata133_program_timings(drive, mode);
273} 274}
274 275
275static void config_drive_art_rwp (ide_drive_t *drive) 276static void config_drive_art_rwp(ide_drive_t *drive)
276{ 277{
277 ide_hwif_t *hwif = HWIF(drive); 278 ide_hwif_t *hwif = HWIF(drive);
278 struct pci_dev *dev = to_pci_dev(hwif->dev); 279 struct pci_dev *dev = to_pci_dev(hwif->dev);
@@ -358,8 +359,7 @@ static u8 sis5513_ata133_udma_filter(ide_drive_t *drive)
358 return (regdw & 0x08) ? ATA_UDMA6 : ATA_UDMA5; 359 return (regdw & 0x08) ? ATA_UDMA6 : ATA_UDMA5;
359} 360}
360 361
361/* Chip detection and general config */ 362static int __devinit sis_find_family(struct pci_dev *dev)
362static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const char *name)
363{ 363{
364 struct pci_dev *host; 364 struct pci_dev *host;
365 int i = 0; 365 int i = 0;
@@ -381,7 +381,7 @@ static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const c
381 chipset_family = ATA_100a; 381 chipset_family = ATA_100a;
382 } 382 }
383 pci_dev_put(host); 383 pci_dev_put(host);
384 384
385 printk(KERN_INFO "SIS5513: %s %s controller\n", 385 printk(KERN_INFO "SIS5513: %s %s controller\n",
386 SiSHostChipInfo[i].name, chipset_capability[chipset_family]); 386 SiSHostChipInfo[i].name, chipset_capability[chipset_family]);
387 } 387 }
@@ -440,63 +440,60 @@ static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const c
440 } 440 }
441 } 441 }
442 442
443 if (!chipset_family) 443 return chipset_family;
444 return -1; 444}
445 445
446static unsigned int __devinit init_chipset_sis5513(struct pci_dev *dev,
447 const char *name)
448{
446 /* Make general config ops here 449 /* Make general config ops here
447 1/ tell IDE channels to operate in Compatibility mode only 450 1/ tell IDE channels to operate in Compatibility mode only
448 2/ tell old chips to allow per drive IDE timings */ 451 2/ tell old chips to allow per drive IDE timings */
449 452
450 { 453 u8 reg;
451 u8 reg; 454 u16 regw;
452 u16 regw; 455
453 456 switch (chipset_family) {
454 switch(chipset_family) { 457 case ATA_133:
455 case ATA_133: 458 /* SiS962 operation mode */
456 /* SiS962 operation mode */ 459 pci_read_config_word(dev, 0x50, &regw);
457 pci_read_config_word(dev, 0x50, &regw); 460 if (regw & 0x08)
458 if (regw & 0x08) 461 pci_write_config_word(dev, 0x50, regw&0xfff7);
459 pci_write_config_word(dev, 0x50, regw&0xfff7); 462 pci_read_config_word(dev, 0x52, &regw);
460 pci_read_config_word(dev, 0x52, &regw); 463 if (regw & 0x08)
461 if (regw & 0x08) 464 pci_write_config_word(dev, 0x52, regw&0xfff7);
462 pci_write_config_word(dev, 0x52, regw&0xfff7); 465 break;
463 break; 466 case ATA_133a:
464 case ATA_133a: 467 case ATA_100:
465 case ATA_100: 468 /* Fixup latency */
466 /* Fixup latency */ 469 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x80);
467 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x80); 470 /* Set compatibility bit */
468 /* Set compatibility bit */ 471 pci_read_config_byte(dev, 0x49, &reg);
469 pci_read_config_byte(dev, 0x49, &reg); 472 if (!(reg & 0x01))
470 if (!(reg & 0x01)) { 473 pci_write_config_byte(dev, 0x49, reg|0x01);
471 pci_write_config_byte(dev, 0x49, reg|0x01); 474 break;
472 } 475 case ATA_100a:
473 break; 476 case ATA_66:
474 case ATA_100a: 477 /* Fixup latency */
475 case ATA_66: 478 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x10);
476 /* Fixup latency */ 479
477 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x10); 480 /* On ATA_66 chips the bit was elsewhere */
478 481 pci_read_config_byte(dev, 0x52, &reg);
479 /* On ATA_66 chips the bit was elsewhere */ 482 if (!(reg & 0x04))
480 pci_read_config_byte(dev, 0x52, &reg); 483 pci_write_config_byte(dev, 0x52, reg|0x04);
481 if (!(reg & 0x04)) { 484 break;
482 pci_write_config_byte(dev, 0x52, reg|0x04); 485 case ATA_33:
483 } 486 /* On ATA_33 we didn't have a single bit to set */
484 break; 487 pci_read_config_byte(dev, 0x09, &reg);
485 case ATA_33: 488 if ((reg & 0x0f) != 0x00)
486 /* On ATA_33 we didn't have a single bit to set */ 489 pci_write_config_byte(dev, 0x09, reg&0xf0);
487 pci_read_config_byte(dev, 0x09, &reg); 490 case ATA_16:
488 if ((reg & 0x0f) != 0x00) { 491 /* force per drive recovery and active timings
489 pci_write_config_byte(dev, 0x09, reg&0xf0); 492 needed on ATA_33 and below chips */
490 } 493 pci_read_config_byte(dev, 0x52, &reg);
491 case ATA_16: 494 if (!(reg & 0x08))
492 /* force per drive recovery and active timings 495 pci_write_config_byte(dev, 0x52, reg|0x08);
493 needed on ATA_33 and below chips */ 496 break;
494 pci_read_config_byte(dev, 0x52, &reg);
495 if (!(reg & 0x08)) {
496 pci_write_config_byte(dev, 0x52, reg|0x08);
497 }
498 break;
499 }
500 } 497 }
501 498
502 return 0; 499 return 0;
@@ -546,10 +543,8 @@ static u8 __devinit ata66_sis5513(ide_hwif_t *hwif)
546 return ata66 ? ATA_CBL_PATA80 : ATA_CBL_PATA40; 543 return ata66 ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
547} 544}
548 545
549static void __devinit init_hwif_sis5513 (ide_hwif_t *hwif) 546static void __devinit init_hwif_sis5513(ide_hwif_t *hwif)
550{ 547{
551 u8 udma_rates[] = { 0x00, 0x00, 0x07, 0x1f, 0x3f, 0x3f, 0x7f, 0x7f };
552
553 hwif->set_pio_mode = &sis_set_pio_mode; 548 hwif->set_pio_mode = &sis_set_pio_mode;
554 hwif->set_dma_mode = &sis_set_dma_mode; 549 hwif->set_dma_mode = &sis_set_dma_mode;
555 550
@@ -557,27 +552,29 @@ static void __devinit init_hwif_sis5513 (ide_hwif_t *hwif)
557 hwif->udma_filter = sis5513_ata133_udma_filter; 552 hwif->udma_filter = sis5513_ata133_udma_filter;
558 553
559 hwif->cable_detect = ata66_sis5513; 554 hwif->cable_detect = ata66_sis5513;
560
561 if (hwif->dma_base == 0)
562 return;
563
564 hwif->ultra_mask = udma_rates[chipset_family];
565} 555}
566 556
567static const struct ide_port_info sis5513_chipset __devinitdata = { 557static const struct ide_port_info sis5513_chipset __devinitdata = {
568 .name = "SIS5513", 558 .name = "SIS5513",
569 .init_chipset = init_chipset_sis5513, 559 .init_chipset = init_chipset_sis5513,
570 .init_hwif = init_hwif_sis5513, 560 .init_hwif = init_hwif_sis5513,
571 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, 561 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
572 .host_flags = IDE_HFLAG_LEGACY_IRQS | IDE_HFLAG_NO_AUTODMA | 562 .host_flags = IDE_HFLAG_LEGACY_IRQS | IDE_HFLAG_NO_AUTODMA,
573 IDE_HFLAG_BOOTABLE,
574 .pio_mask = ATA_PIO4, 563 .pio_mask = ATA_PIO4,
575 .mwdma_mask = ATA_MWDMA2, 564 .mwdma_mask = ATA_MWDMA2,
576}; 565};
577 566
578static int __devinit sis5513_init_one(struct pci_dev *dev, const struct pci_device_id *id) 567static int __devinit sis5513_init_one(struct pci_dev *dev, const struct pci_device_id *id)
579{ 568{
580 return ide_setup_pci_device(dev, &sis5513_chipset); 569 struct ide_port_info d = sis5513_chipset;
570 u8 udma_rates[] = { 0x00, 0x00, 0x07, 0x1f, 0x3f, 0x3f, 0x7f, 0x7f };
571
572 if (sis_find_family(dev) == 0)
573 return -ENOTSUPP;
574
575 d.udma_mask = udma_rates[chipset_family];
576
577 return ide_setup_pci_device(dev, &d);
581} 578}
582 579
583static const struct pci_device_id sis5513_pci_tbl[] = { 580static const struct pci_device_id sis5513_pci_tbl[] = {
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c
index 1f00251a4a87..40b3eeb2d847 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/pci/sl82c105.c
@@ -332,8 +332,7 @@ static const struct ide_port_info sl82c105_chipset __devinitdata = {
332#if defined(CONFIG_LOPEC) || defined(CONFIG_SANDPOINT) 332#if defined(CONFIG_LOPEC) || defined(CONFIG_SANDPOINT)
333 IDE_HFLAG_FORCE_LEGACY_IRQS | 333 IDE_HFLAG_FORCE_LEGACY_IRQS |
334#endif 334#endif
335 IDE_HFLAG_NO_AUTODMA | 335 IDE_HFLAG_NO_AUTODMA,
336 IDE_HFLAG_BOOTABLE,
337 .pio_mask = ATA_PIO5, 336 .pio_mask = ATA_PIO5,
338}; 337};
339 338
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index 65f4c2ffaa59..eab557c45d1b 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -27,9 +27,9 @@ static void slc90e66_set_pio_mode(ide_drive_t *drive, const u8 pio)
27 unsigned long flags; 27 unsigned long flags;
28 u16 master_data; 28 u16 master_data;
29 u8 slave_data; 29 u8 slave_data;
30 int control = 0; 30 int control = 0;
31 /* ISP RTC */ 31 /* ISP RTC */
32 static const u8 timings[][2]= { 32 static const u8 timings[][2] = {
33 { 0, 0 }, 33 { 0, 0 },
34 { 0, 0 }, 34 { 0, 0 },
35 { 1, 0 }, 35 { 1, 0 },
@@ -136,8 +136,8 @@ static void __devinit init_hwif_slc90e66(ide_hwif_t *hwif)
136static const struct ide_port_info slc90e66_chipset __devinitdata = { 136static const struct ide_port_info slc90e66_chipset __devinitdata = {
137 .name = "SLC90E66", 137 .name = "SLC90E66",
138 .init_hwif = init_hwif_slc90e66, 138 .init_hwif = init_hwif_slc90e66,
139 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, 139 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
140 .host_flags = IDE_HFLAG_LEGACY_IRQS | IDE_HFLAG_BOOTABLE, 140 .host_flags = IDE_HFLAG_LEGACY_IRQS,
141 .pio_mask = ATA_PIO4, 141 .pio_mask = ATA_PIO4,
142 .swdma_mask = ATA_SWDMA2_ONLY, 142 .swdma_mask = ATA_SWDMA2_ONLY,
143 .mwdma_mask = ATA_MWDMA12_ONLY, 143 .mwdma_mask = ATA_MWDMA12_ONLY,
diff --git a/drivers/ide/pci/tc86c001.c b/drivers/ide/pci/tc86c001.c
index 1e4a6262bcef..c15435182e3c 100644
--- a/drivers/ide/pci/tc86c001.c
+++ b/drivers/ide/pci/tc86c001.c
@@ -18,20 +18,20 @@ static void tc86c001_set_mode(ide_drive_t *drive, const u8 speed)
18 u16 mode, scr = inw(scr_port); 18 u16 mode, scr = inw(scr_port);
19 19
20 switch (speed) { 20 switch (speed) {
21 case XFER_UDMA_4: mode = 0x00c0; break; 21 case XFER_UDMA_4: mode = 0x00c0; break;
22 case XFER_UDMA_3: mode = 0x00b0; break; 22 case XFER_UDMA_3: mode = 0x00b0; break;
23 case XFER_UDMA_2: mode = 0x00a0; break; 23 case XFER_UDMA_2: mode = 0x00a0; break;
24 case XFER_UDMA_1: mode = 0x0090; break; 24 case XFER_UDMA_1: mode = 0x0090; break;
25 case XFER_UDMA_0: mode = 0x0080; break; 25 case XFER_UDMA_0: mode = 0x0080; break;
26 case XFER_MW_DMA_2: mode = 0x0070; break; 26 case XFER_MW_DMA_2: mode = 0x0070; break;
27 case XFER_MW_DMA_1: mode = 0x0060; break; 27 case XFER_MW_DMA_1: mode = 0x0060; break;
28 case XFER_MW_DMA_0: mode = 0x0050; break; 28 case XFER_MW_DMA_0: mode = 0x0050; break;
29 case XFER_PIO_4: mode = 0x0400; break; 29 case XFER_PIO_4: mode = 0x0400; break;
30 case XFER_PIO_3: mode = 0x0300; break; 30 case XFER_PIO_3: mode = 0x0300; break;
31 case XFER_PIO_2: mode = 0x0200; break; 31 case XFER_PIO_2: mode = 0x0200; break;
32 case XFER_PIO_1: mode = 0x0100; break; 32 case XFER_PIO_1: mode = 0x0100; break;
33 case XFER_PIO_0: 33 case XFER_PIO_0:
34 default: mode = 0x0000; break; 34 default: mode = 0x0000; break;
35 } 35 }
36 36
37 scr &= (speed < XFER_MW_DMA_0) ? 0xf8ff : 0xff0f; 37 scr &= (speed < XFER_MW_DMA_0) ? 0xf8ff : 0xff0f;
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c
index a67d02a3f96e..3316b197c779 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/pci/triflex.c
@@ -97,7 +97,6 @@ static const struct ide_port_info triflex_device __devinitdata = {
97 .name = "TRIFLEX", 97 .name = "TRIFLEX",
98 .init_hwif = init_hwif_triflex, 98 .init_hwif = init_hwif_triflex,
99 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}}, 99 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
100 .host_flags = IDE_HFLAG_BOOTABLE,
101 .pio_mask = ATA_PIO4, 100 .pio_mask = ATA_PIO4,
102 .swdma_mask = ATA_SWDMA2, 101 .swdma_mask = ATA_SWDMA2,
103 .mwdma_mask = ATA_MWDMA2, 102 .mwdma_mask = ATA_MWDMA2,
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c
index de750f7a43e9..2b8f3a2837d7 100644
--- a/drivers/ide/pci/trm290.c
+++ b/drivers/ide/pci/trm290.c
@@ -337,7 +337,6 @@ static const struct ide_port_info trm290_chipset __devinitdata = {
337 IDE_HFLAG_TRUST_BIOS_FOR_DMA | 337 IDE_HFLAG_TRUST_BIOS_FOR_DMA |
338#endif 338#endif
339 IDE_HFLAG_NO_AUTODMA | 339 IDE_HFLAG_NO_AUTODMA |
340 IDE_HFLAG_BOOTABLE |
341 IDE_HFLAG_NO_LBA48, 340 IDE_HFLAG_NO_LBA48,
342}; 341};
343 342
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index 9004e7521889..cff3cafedc47 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -429,11 +429,9 @@ static const struct ide_port_info via82cxxx_chipset __devinitdata = {
429 .init_hwif = init_hwif_via82cxxx, 429 .init_hwif = init_hwif_via82cxxx,
430 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } }, 430 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
431 .host_flags = IDE_HFLAG_PIO_NO_BLACKLIST | 431 .host_flags = IDE_HFLAG_PIO_NO_BLACKLIST |
432 IDE_HFLAG_PIO_NO_DOWNGRADE |
433 IDE_HFLAG_ABUSE_SET_DMA_MODE | 432 IDE_HFLAG_ABUSE_SET_DMA_MODE |
434 IDE_HFLAG_POST_SET_MODE | 433 IDE_HFLAG_POST_SET_MODE |
435 IDE_HFLAG_IO_32BIT | 434 IDE_HFLAG_IO_32BIT,
436 IDE_HFLAG_BOOTABLE,
437 .pio_mask = ATA_PIO5, 435 .pio_mask = ATA_PIO5,
438 .swdma_mask = ATA_SWDMA2, 436 .swdma_mask = ATA_SWDMA2,
439 .mwdma_mask = ATA_MWDMA2, 437 .mwdma_mask = ATA_MWDMA2,
diff --git a/drivers/ide/ppc/mpc8xx.c b/drivers/ide/ppc/mpc8xx.c
index a784a97ca7ec..467656f06ccc 100644
--- a/drivers/ide/ppc/mpc8xx.c
+++ b/drivers/ide/ppc/mpc8xx.c
@@ -36,6 +36,8 @@
36#include <asm/machdep.h> 36#include <asm/machdep.h>
37#include <asm/irq.h> 37#include <asm/irq.h>
38 38
39#define DRV_NAME "ide-mpc8xx"
40
39static int identify (volatile u8 *p); 41static int identify (volatile u8 *p);
40static void print_fixed (volatile u8 *p); 42static void print_fixed (volatile u8 *p);
41static void print_funcid (int func); 43static void print_funcid (int func);
@@ -127,7 +129,7 @@ static int pcmcia_schlvl = PCMCIA_SCHLVL;
127 * MPC8xx's internal PCMCIA interface 129 * MPC8xx's internal PCMCIA interface
128 */ 130 */
129#if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT) 131#if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT)
130static void __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port) 132static int __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port)
131{ 133{
132 unsigned long *p = hw->io_ports; 134 unsigned long *p = hw->io_ports;
133 int i; 135 int i;
@@ -182,6 +184,13 @@ static void __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port)
182 pcmcia_phy_base, pcmcia_phy_end, 184 pcmcia_phy_base, pcmcia_phy_end,
183 pcmcia_phy_end - pcmcia_phy_base); 185 pcmcia_phy_end - pcmcia_phy_base);
184 186
187 if (!request_mem_region(pcmcia_phy_base,
188 pcmcia_phy_end - pcmcia_phy_base,
189 DRV_NAME)) {
190 printk(KERN_ERR "%s: resources busy\n", DRV_NAME);
191 return -EBUSY;
192 }
193
185 pcmcia_base=(unsigned long)ioremap(pcmcia_phy_base, 194 pcmcia_base=(unsigned long)ioremap(pcmcia_phy_base,
186 pcmcia_phy_end-pcmcia_phy_base); 195 pcmcia_phy_end-pcmcia_phy_base);
187 196
@@ -236,7 +245,7 @@ static void __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port)
236 if (pcmp->pcmc_pipr & (M8XX_PCMCIA_CD1(_slot_)|M8XX_PCMCIA_CD2(_slot_))) { 245 if (pcmp->pcmc_pipr & (M8XX_PCMCIA_CD1(_slot_)|M8XX_PCMCIA_CD2(_slot_))) {
237 printk ("No card in slot %c: PIPR=%08x\n", 246 printk ("No card in slot %c: PIPR=%08x\n",
238 'A' + _slot_, (u32) pcmp->pcmc_pipr); 247 'A' + _slot_, (u32) pcmp->pcmc_pipr);
239 return; /* No card in slot */ 248 return -ENODEV; /* No card in slot */
240 } 249 }
241 250
242 check_ide_device (pcmcia_base); 251 check_ide_device (pcmcia_base);
@@ -279,9 +288,6 @@ static void __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port)
279 } 288 }
280#endif /* CONFIG_IDE_8xx_PCCARD */ 289#endif /* CONFIG_IDE_8xx_PCCARD */
281 290
282 ide_hwifs[data_port].pio_mask = ATA_PIO4;
283 ide_hwifs[data_port].set_pio_mode = m8xx_ide_set_pio_mode;
284
285 /* Enable Harddisk Interrupt, 291 /* Enable Harddisk Interrupt,
286 * and make it edge sensitive 292 * and make it edge sensitive
287 */ 293 */
@@ -296,6 +302,8 @@ static void __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port)
296 /* Enable falling edge irq */ 302 /* Enable falling edge irq */
297 pcmp->pcmc_per = 0x100000 >> (16 * _slot_); 303 pcmp->pcmc_per = 0x100000 >> (16 * _slot_);
298#endif /* CONFIG_IDE_8xx_PCCARD */ 304#endif /* CONFIG_IDE_8xx_PCCARD */
305
306 return 0;
299} 307}
300#endif /* CONFIG_IDE_8xx_PCCARD || CONFIG_IDE_8xx_DIRECT */ 308#endif /* CONFIG_IDE_8xx_PCCARD || CONFIG_IDE_8xx_DIRECT */
301 309
@@ -304,7 +312,7 @@ static void __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port)
304 * MPC8xx's internal PCMCIA interface 312 * MPC8xx's internal PCMCIA interface
305 */ 313 */
306#if defined(CONFIG_IDE_EXT_DIRECT) 314#if defined(CONFIG_IDE_EXT_DIRECT)
307static void __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port) 315static int __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port)
308{ 316{
309 unsigned long *p = hw->io_ports; 317 unsigned long *p = hw->io_ports;
310 int i; 318 int i;
@@ -327,7 +335,12 @@ static void __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port)
327 printk ("IDE phys mem : %08x...%08x (size %08x)\n", 335 printk ("IDE phys mem : %08x...%08x (size %08x)\n",
328 ide_phy_base, ide_phy_end, 336 ide_phy_base, ide_phy_end,
329 ide_phy_end - ide_phy_base); 337 ide_phy_end - ide_phy_base);
330 338
339 if (!request_mem_region(ide_phy_base, 0x200, DRV_NAME)) {
340 printk(KERN_ERR "%s: resources busy\n", DRV_NAME);
341 return -EBUSY;
342 }
343
331 ide_base=(unsigned long)ioremap(ide_phy_base, 344 ide_base=(unsigned long)ioremap(ide_phy_base,
332 ide_phy_end-ide_phy_base); 345 ide_phy_end-ide_phy_base);
333 346
@@ -357,15 +370,14 @@ static void __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port)
357 hw->irq = ioport_dsc[data_port].irq; 370 hw->irq = ioport_dsc[data_port].irq;
358 hw->ack_intr = (ide_ack_intr_t *)ide_interrupt_ack; 371 hw->ack_intr = (ide_ack_intr_t *)ide_interrupt_ack;
359 372
360 ide_hwifs[data_port].pio_mask = ATA_PIO4;
361 ide_hwifs[data_port].set_pio_mode = m8xx_ide_set_pio_mode;
362
363 /* Enable Harddisk Interrupt, 373 /* Enable Harddisk Interrupt,
364 * and make it edge sensitive 374 * and make it edge sensitive
365 */ 375 */
366 /* (11-18) Set edge detect for irq, no wakeup from low power mode */ 376 /* (11-18) Set edge detect for irq, no wakeup from low power mode */
367 ((immap_t *) IMAP_ADDR)->im_siu_conf.sc_siel |= 377 ((immap_t *) IMAP_ADDR)->im_siu_conf.sc_siel |=
368 (0x80000000 >> ioport_dsc[data_port].irq); 378 (0x80000000 >> ioport_dsc[data_port].irq);
379
380 return 0;
369} 381}
370#endif /* CONFIG_IDE_8xx_DIRECT */ 382#endif /* CONFIG_IDE_8xx_DIRECT */
371 383
@@ -794,14 +806,28 @@ static int __init mpc8xx_ide_probe(void)
794 806
795#ifdef IDE0_BASE_OFFSET 807#ifdef IDE0_BASE_OFFSET
796 memset(&hw, 0, sizeof(hw)); 808 memset(&hw, 0, sizeof(hw));
797 m8xx_ide_init_ports(&hw, 0); 809 if (!m8xx_ide_init_ports(&hw, 0)) {
798 ide_init_port_hw(&ide_hwifs[0], &hw); 810 ide_hwif_t *hwif = &ide_hwifs[0];
799 idx[0] = 0; 811
812 ide_init_port_hw(hwif, &hw);
813 hwif->mmio = 1;
814 hwif->pio_mask = ATA_PIO4;
815 hwif->set_pio_mode = m8xx_ide_set_pio_mode;
816
817 idx[0] = 0;
818 }
800#ifdef IDE1_BASE_OFFSET 819#ifdef IDE1_BASE_OFFSET
801 memset(&hw, 0, sizeof(hw)); 820 memset(&hw, 0, sizeof(hw));
802 m8xx_ide_init_ports(&hw, 1); 821 if (!m8xx_ide_init_ports(&hw, 1)) {
803 ide_init_port_hw(&ide_hwifs[1], &hw); 822 ide_hwif_t *mate = &ide_hwifs[1];
804 idx[1] = 1; 823
824 ide_init_port_hw(mate, &hw);
825 mate->mmio = 1;
826 mate->pio_mask = ATA_PIO4;
827 mate->set_pio_mode = m8xx_ide_set_pio_mode;
828
829 idx[1] = 1;
830 }
805#endif 831#endif
806#endif 832#endif
807 833
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index 88619b50d9ef..177961edc430 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -79,8 +79,6 @@ typedef struct pmac_ide_hwif {
79 79
80} pmac_ide_hwif_t; 80} pmac_ide_hwif_t;
81 81
82static pmac_ide_hwif_t pmac_ide[MAX_HWIFS];
83
84enum { 82enum {
85 controller_ohare, /* OHare based */ 83 controller_ohare, /* OHare based */
86 controller_heathrow, /* Heathrow/Paddington */ 84 controller_heathrow, /* Heathrow/Paddington */
@@ -923,7 +921,6 @@ pmac_ide_do_resume(ide_hwif_t *hwif)
923static const struct ide_port_info pmac_port_info = { 921static const struct ide_port_info pmac_port_info = {
924 .chipset = ide_pmac, 922 .chipset = ide_pmac,
925 .host_flags = IDE_HFLAG_SET_PIO_MODE_KEEP_DMA | 923 .host_flags = IDE_HFLAG_SET_PIO_MODE_KEEP_DMA |
926 IDE_HFLAG_PIO_NO_DOWNGRADE |
927 IDE_HFLAG_POST_SET_MODE | 924 IDE_HFLAG_POST_SET_MODE |
928 IDE_HFLAG_NO_DMA | /* no SFF-style DMA */ 925 IDE_HFLAG_NO_DMA | /* no SFF-style DMA */
929 IDE_HFLAG_UNMASK_IRQS, 926 IDE_HFLAG_UNMASK_IRQS,
@@ -1088,35 +1085,36 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
1088{ 1085{
1089 void __iomem *base; 1086 void __iomem *base;
1090 unsigned long regbase; 1087 unsigned long regbase;
1091 int irq;
1092 ide_hwif_t *hwif; 1088 ide_hwif_t *hwif;
1093 pmac_ide_hwif_t *pmif; 1089 pmac_ide_hwif_t *pmif;
1094 int i, rc; 1090 int irq, rc;
1095 hw_regs_t hw; 1091 hw_regs_t hw;
1096 1092
1097 i = 0; 1093 pmif = kzalloc(sizeof(*pmif), GFP_KERNEL);
1098 while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0 1094 if (pmif == NULL)
1099 || pmac_ide[i].node != NULL)) 1095 return -ENOMEM;
1100 ++i; 1096
1101 if (i >= MAX_HWIFS) { 1097 hwif = ide_find_port();
1098 if (hwif == NULL) {
1102 printk(KERN_ERR "ide-pmac: MacIO interface attach with no slot\n"); 1099 printk(KERN_ERR "ide-pmac: MacIO interface attach with no slot\n");
1103 printk(KERN_ERR " %s\n", mdev->ofdev.node->full_name); 1100 printk(KERN_ERR " %s\n", mdev->ofdev.node->full_name);
1104 return -ENODEV; 1101 rc = -ENODEV;
1102 goto out_free_pmif;
1105 } 1103 }
1106 1104
1107 pmif = &pmac_ide[i];
1108 hwif = &ide_hwifs[i];
1109
1110 if (macio_resource_count(mdev) == 0) { 1105 if (macio_resource_count(mdev) == 0) {
1111 printk(KERN_WARNING "ide%d: no address for %s\n", 1106 printk(KERN_WARNING "ide-pmac: no address for %s\n",
1112 i, mdev->ofdev.node->full_name); 1107 mdev->ofdev.node->full_name);
1113 return -ENXIO; 1108 rc = -ENXIO;
1109 goto out_free_pmif;
1114 } 1110 }
1115 1111
1116 /* Request memory resource for IO ports */ 1112 /* Request memory resource for IO ports */
1117 if (macio_request_resource(mdev, 0, "ide-pmac (ports)")) { 1113 if (macio_request_resource(mdev, 0, "ide-pmac (ports)")) {
1118 printk(KERN_ERR "ide%d: can't request mmio resource !\n", i); 1114 printk(KERN_ERR "ide-pmac: can't request MMIO resource for "
1119 return -EBUSY; 1115 "%s!\n", mdev->ofdev.node->full_name);
1116 rc = -EBUSY;
1117 goto out_free_pmif;
1120 } 1118 }
1121 1119
1122 /* XXX This is bogus. Should be fixed in the registry by checking 1120 /* XXX This is bogus. Should be fixed in the registry by checking
@@ -1125,8 +1123,8 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
1125 * where that happens though... 1123 * where that happens though...
1126 */ 1124 */
1127 if (macio_irq_count(mdev) == 0) { 1125 if (macio_irq_count(mdev) == 0) {
1128 printk(KERN_WARNING "ide%d: no intrs for device %s, using 13\n", 1126 printk(KERN_WARNING "ide-pmac: no intrs for device %s, using "
1129 i, mdev->ofdev.node->full_name); 1127 "13\n", mdev->ofdev.node->full_name);
1130 irq = irq_create_mapping(NULL, 13); 1128 irq = irq_create_mapping(NULL, 13);
1131 } else 1129 } else
1132 irq = macio_irq(mdev, 0); 1130 irq = macio_irq(mdev, 0);
@@ -1144,7 +1142,9 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
1144#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC 1142#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
1145 if (macio_resource_count(mdev) >= 2) { 1143 if (macio_resource_count(mdev) >= 2) {
1146 if (macio_request_resource(mdev, 1, "ide-pmac (dma)")) 1144 if (macio_request_resource(mdev, 1, "ide-pmac (dma)"))
1147 printk(KERN_WARNING "ide%d: can't request DMA resource !\n", i); 1145 printk(KERN_WARNING "ide-pmac: can't request DMA "
1146 "resource for %s!\n",
1147 mdev->ofdev.node->full_name);
1148 else 1148 else
1149 pmif->dma_regs = ioremap(macio_resource_start(mdev, 1), 0x1000); 1149 pmif->dma_regs = ioremap(macio_resource_start(mdev, 1), 0x1000);
1150 } else 1150 } else
@@ -1166,11 +1166,15 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
1166 iounmap(pmif->dma_regs); 1166 iounmap(pmif->dma_regs);
1167 macio_release_resource(mdev, 1); 1167 macio_release_resource(mdev, 1);
1168 } 1168 }
1169 memset(pmif, 0, sizeof(*pmif));
1170 macio_release_resource(mdev, 0); 1169 macio_release_resource(mdev, 0);
1170 kfree(pmif);
1171 } 1171 }
1172 1172
1173 return rc; 1173 return rc;
1174
1175out_free_pmif:
1176 kfree(pmif);
1177 return rc;
1174} 1178}
1175 1179
1176static int 1180static int
@@ -1215,7 +1219,7 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1215 pmac_ide_hwif_t *pmif; 1219 pmac_ide_hwif_t *pmif;
1216 void __iomem *base; 1220 void __iomem *base;
1217 unsigned long rbase, rlen; 1221 unsigned long rbase, rlen;
1218 int i, rc; 1222 int rc;
1219 hw_regs_t hw; 1223 hw_regs_t hw;
1220 1224
1221 np = pci_device_to_OF_node(pdev); 1225 np = pci_device_to_OF_node(pdev);
@@ -1223,30 +1227,32 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1223 printk(KERN_ERR "ide-pmac: cannot find MacIO node for Kauai ATA interface\n"); 1227 printk(KERN_ERR "ide-pmac: cannot find MacIO node for Kauai ATA interface\n");
1224 return -ENODEV; 1228 return -ENODEV;
1225 } 1229 }
1226 i = 0; 1230
1227 while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0 1231 pmif = kzalloc(sizeof(*pmif), GFP_KERNEL);
1228 || pmac_ide[i].node != NULL)) 1232 if (pmif == NULL)
1229 ++i; 1233 return -ENOMEM;
1230 if (i >= MAX_HWIFS) { 1234
1235 hwif = ide_find_port();
1236 if (hwif == NULL) {
1231 printk(KERN_ERR "ide-pmac: PCI interface attach with no slot\n"); 1237 printk(KERN_ERR "ide-pmac: PCI interface attach with no slot\n");
1232 printk(KERN_ERR " %s\n", np->full_name); 1238 printk(KERN_ERR " %s\n", np->full_name);
1233 return -ENODEV; 1239 rc = -ENODEV;
1240 goto out_free_pmif;
1234 } 1241 }
1235 1242
1236 pmif = &pmac_ide[i];
1237 hwif = &ide_hwifs[i];
1238
1239 if (pci_enable_device(pdev)) { 1243 if (pci_enable_device(pdev)) {
1240 printk(KERN_WARNING "ide%i: Can't enable PCI device for %s\n", 1244 printk(KERN_WARNING "ide-pmac: Can't enable PCI device for "
1241 i, np->full_name); 1245 "%s\n", np->full_name);
1242 return -ENXIO; 1246 rc = -ENXIO;
1247 goto out_free_pmif;
1243 } 1248 }
1244 pci_set_master(pdev); 1249 pci_set_master(pdev);
1245 1250
1246 if (pci_request_regions(pdev, "Kauai ATA")) { 1251 if (pci_request_regions(pdev, "Kauai ATA")) {
1247 printk(KERN_ERR "ide%d: Cannot obtain PCI resources for %s\n", 1252 printk(KERN_ERR "ide-pmac: Cannot obtain PCI resources for "
1248 i, np->full_name); 1253 "%s\n", np->full_name);
1249 return -ENXIO; 1254 rc = -ENXIO;
1255 goto out_free_pmif;
1250 } 1256 }
1251 1257
1252 hwif->dev = &pdev->dev; 1258 hwif->dev = &pdev->dev;
@@ -1276,11 +1282,15 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1276 /* The inteface is released to the common IDE layer */ 1282 /* The inteface is released to the common IDE layer */
1277 pci_set_drvdata(pdev, NULL); 1283 pci_set_drvdata(pdev, NULL);
1278 iounmap(base); 1284 iounmap(base);
1279 memset(pmif, 0, sizeof(*pmif));
1280 pci_release_regions(pdev); 1285 pci_release_regions(pdev);
1286 kfree(pmif);
1281 } 1287 }
1282 1288
1283 return rc; 1289 return rc;
1290
1291out_free_pmif:
1292 kfree(pmif);
1293 return rc;
1284} 1294}
1285 1295
1286static int 1296static int
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index f7ede0e42881..6302010fd8e2 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -20,73 +20,6 @@
20#include <asm/io.h> 20#include <asm/io.h>
21#include <asm/irq.h> 21#include <asm/irq.h>
22 22
23
24/**
25 * ide_match_hwif - match a PCI IDE against an ide_hwif
26 * @io_base: I/O base of device
27 * @bootable: set if its bootable
28 * @name: name of device
29 *
30 * Match a PCI IDE port against an entry in ide_hwifs[],
31 * based on io_base port if possible. Return the matching hwif,
32 * or a new hwif. If we find an error (clashing, out of devices, etc)
33 * return NULL
34 *
35 * FIXME: we need to handle mmio matches here too
36 */
37
38static ide_hwif_t *ide_match_hwif(unsigned long io_base, u8 bootable, const char *name)
39{
40 int h;
41 ide_hwif_t *hwif;
42
43 /*
44 * Look for a hwif with matching io_base default value.
45 * If chipset is "ide_unknown", then claim that hwif slot.
46 * Otherwise, some other chipset has already claimed it.. :(
47 */
48 for (h = 0; h < MAX_HWIFS; ++h) {
49 hwif = &ide_hwifs[h];
50 if (hwif->io_ports[IDE_DATA_OFFSET] == io_base) {
51 if (hwif->chipset == ide_unknown)
52 return hwif; /* match */
53 printk(KERN_ERR "%s: port 0x%04lx already claimed by %s\n",
54 name, io_base, hwif->name);
55 return NULL; /* already claimed */
56 }
57 }
58 /*
59 * Okay, there is no hwif matching our io_base,
60 * so we'll just claim an unassigned slot.
61 * Give preference to claiming other slots before claiming ide0/ide1,
62 * just in case there's another interface yet-to-be-scanned
63 * which uses ports 1f0/170 (the ide0/ide1 defaults).
64 *
65 * Unless there is a bootable card that does not use the standard
66 * ports 1f0/170 (the ide0/ide1 defaults). The (bootable) flag.
67 */
68 if (bootable) {
69 for (h = 0; h < MAX_HWIFS; ++h) {
70 hwif = &ide_hwifs[h];
71 if (hwif->chipset == ide_unknown)
72 return hwif; /* pick an unused entry */
73 }
74 } else {
75 for (h = 2; h < MAX_HWIFS; ++h) {
76 hwif = ide_hwifs + h;
77 if (hwif->chipset == ide_unknown)
78 return hwif; /* pick an unused entry */
79 }
80 }
81 for (h = 0; h < 2 && h < MAX_HWIFS; ++h) {
82 hwif = ide_hwifs + h;
83 if (hwif->chipset == ide_unknown)
84 return hwif; /* pick an unused entry */
85 }
86 printk(KERN_ERR "%s: too many IDE interfaces, no room in table\n", name);
87 return NULL;
88}
89
90/** 23/**
91 * ide_setup_pci_baseregs - place a PCI IDE controller native 24 * ide_setup_pci_baseregs - place a PCI IDE controller native
92 * @dev: PCI device of interface to switch native 25 * @dev: PCI device of interface to switch native
@@ -94,13 +27,13 @@ static ide_hwif_t *ide_match_hwif(unsigned long io_base, u8 bootable, const char
94 * 27 *
95 * We attempt to place the PCI interface into PCI native mode. If 28 * We attempt to place the PCI interface into PCI native mode. If
96 * we succeed the BARs are ok and the controller is in PCI mode. 29 * we succeed the BARs are ok and the controller is in PCI mode.
97 * Returns 0 on success or an errno code. 30 * Returns 0 on success or an errno code.
98 * 31 *
99 * FIXME: if we program the interface and then fail to set the BARS 32 * FIXME: if we program the interface and then fail to set the BARS
100 * we don't switch it back to legacy mode. Do we actually care ?? 33 * we don't switch it back to legacy mode. Do we actually care ??
101 */ 34 */
102 35
103static int ide_setup_pci_baseregs (struct pci_dev *dev, const char *name) 36static int ide_setup_pci_baseregs(struct pci_dev *dev, const char *name)
104{ 37{
105 u8 progif = 0; 38 u8 progif = 0;
106 39
@@ -207,7 +140,6 @@ void ide_setup_pci_noise(struct pci_dev *dev, const struct ide_port_info *d)
207 " PCI slot %s\n", d->name, dev->vendor, dev->device, 140 " PCI slot %s\n", d->name, dev->vendor, dev->device,
208 dev->revision, pci_name(dev)); 141 dev->revision, pci_name(dev));
209} 142}
210
211EXPORT_SYMBOL_GPL(ide_setup_pci_noise); 143EXPORT_SYMBOL_GPL(ide_setup_pci_noise);
212 144
213 145
@@ -220,7 +152,7 @@ EXPORT_SYMBOL_GPL(ide_setup_pci_noise);
220 * but if that fails then we only need IO space. The PCI code should 152 * but if that fails then we only need IO space. The PCI code should
221 * have setup the proper resources for us already for controllers in 153 * have setup the proper resources for us already for controllers in
222 * legacy mode. 154 * legacy mode.
223 * 155 *
224 * Returns zero on success or an error code 156 * Returns zero on success or an error code
225 */ 157 */
226 158
@@ -279,8 +211,8 @@ static int ide_pci_configure(struct pci_dev *dev, const struct ide_port_info *d)
279 * Maybe the user deliberately *disabled* the device, 211 * Maybe the user deliberately *disabled* the device,
280 * but we'll eventually ignore it again if no drives respond. 212 * but we'll eventually ignore it again if no drives respond.
281 */ 213 */
282 if (ide_setup_pci_baseregs(dev, d->name) || pci_write_config_word(dev, PCI_COMMAND, pcicmd|PCI_COMMAND_IO)) 214 if (ide_setup_pci_baseregs(dev, d->name) ||
283 { 215 pci_write_config_word(dev, PCI_COMMAND, pcicmd | PCI_COMMAND_IO)) {
284 printk(KERN_INFO "%s: device disabled (BIOS)\n", d->name); 216 printk(KERN_INFO "%s: device disabled (BIOS)\n", d->name);
285 return -ENODEV; 217 return -ENODEV;
286 } 218 }
@@ -301,26 +233,24 @@ static int ide_pci_configure(struct pci_dev *dev, const struct ide_port_info *d)
301 * @d: IDE port info 233 * @d: IDE port info
302 * @bar: BAR number 234 * @bar: BAR number
303 * 235 *
304 * Checks if a BAR is configured and points to MMIO space. If so 236 * Checks if a BAR is configured and points to MMIO space. If so,
305 * print an error and return an error code. Otherwise return 0 237 * return an error code. Otherwise return 0
306 */ 238 */
307 239
308static int ide_pci_check_iomem(struct pci_dev *dev, const struct ide_port_info *d, int bar) 240static int ide_pci_check_iomem(struct pci_dev *dev, const struct ide_port_info *d,
241 int bar)
309{ 242{
310 ulong flags = pci_resource_flags(dev, bar); 243 ulong flags = pci_resource_flags(dev, bar);
311 244
312 /* Unconfigured ? */ 245 /* Unconfigured ? */
313 if (!flags || pci_resource_len(dev, bar) == 0) 246 if (!flags || pci_resource_len(dev, bar) == 0)
314 return 0; 247 return 0;
315 248
316 /* I/O space */ 249 /* I/O space */
317 if(flags & PCI_BASE_ADDRESS_IO_MASK) 250 if (flags & IORESOURCE_IO)
318 return 0; 251 return 0;
319 252
320 /* Bad */ 253 /* Bad */
321 printk(KERN_ERR "%s: IO baseregs (BIOS) are reported "
322 "as MEM, report to "
323 "<andre@linux-ide.org>.\n", d->name);
324 return -EINVAL; 254 return -EINVAL;
325} 255}
326 256
@@ -344,14 +274,16 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev,
344{ 274{
345 unsigned long ctl = 0, base = 0; 275 unsigned long ctl = 0, base = 0;
346 ide_hwif_t *hwif; 276 ide_hwif_t *hwif;
347 u8 bootable = (d->host_flags & IDE_HFLAG_BOOTABLE) ? 1 : 0;
348 struct hw_regs_s hw; 277 struct hw_regs_s hw;
349 278
350 if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) { 279 if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) {
351 /* Possibly we should fail if these checks report true */ 280 if (ide_pci_check_iomem(dev, d, 2 * port) ||
352 ide_pci_check_iomem(dev, d, 2*port); 281 ide_pci_check_iomem(dev, d, 2 * port + 1)) {
353 ide_pci_check_iomem(dev, d, 2*port+1); 282 printk(KERN_ERR "%s: I/O baseregs (BIOS) are reported "
354 283 "as MEM for port %d!\n", d->name, port);
284 return NULL;
285 }
286
355 ctl = pci_resource_start(dev, 2*port+1); 287 ctl = pci_resource_start(dev, 2*port+1);
356 base = pci_resource_start(dev, 2*port); 288 base = pci_resource_start(dev, 2*port);
357 if ((ctl && !base) || (base && !ctl)) { 289 if ((ctl && !base) || (base && !ctl)) {
@@ -360,14 +292,18 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev,
360 return NULL; 292 return NULL;
361 } 293 }
362 } 294 }
363 if (!ctl) 295 if (!ctl) {
364 {
365 /* Use default values */ 296 /* Use default values */
366 ctl = port ? 0x374 : 0x3f4; 297 ctl = port ? 0x374 : 0x3f4;
367 base = port ? 0x170 : 0x1f0; 298 base = port ? 0x170 : 0x1f0;
368 } 299 }
369 if ((hwif = ide_match_hwif(base, bootable, d->name)) == NULL) 300
370 return NULL; /* no room in ide_hwifs[] */ 301 hwif = ide_find_port_slot(d);
302 if (hwif == NULL) {
303 printk(KERN_ERR "%s: too many IDE interfaces, no room in "
304 "table\n", d->name);
305 return NULL;
306 }
371 307
372 memset(&hw, 0, sizeof(hw)); 308 memset(&hw, 0, sizeof(hw));
373 hw.irq = irq; 309 hw.irq = irq;
@@ -407,9 +343,9 @@ void ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
407 unsigned long dma_base = ide_get_or_set_dma_base(d, hwif); 343 unsigned long dma_base = ide_get_or_set_dma_base(d, hwif);
408 if (dma_base && !(pcicmd & PCI_COMMAND_MASTER)) { 344 if (dma_base && !(pcicmd & PCI_COMMAND_MASTER)) {
409 /* 345 /*
410 * Set up BM-DMA capability 346 * Set up BM-DMA capability
411 * (PnP BIOS should have done this) 347 * (PnP BIOS should have done this)
412 */ 348 */
413 pci_set_master(dev); 349 pci_set_master(dev);
414 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) || !(pcicmd & PCI_COMMAND_MASTER)) { 350 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) || !(pcicmd & PCI_COMMAND_MASTER)) {
415 printk(KERN_ERR "%s: %s error updating PCICMD\n", 351 printk(KERN_ERR "%s: %s error updating PCICMD\n",
@@ -514,7 +450,6 @@ void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d, int
514 *(idx + port) = hwif->index; 450 *(idx + port) = hwif->index;
515 } 451 }
516} 452}
517
518EXPORT_SYMBOL_GPL(ide_pci_setup_ports); 453EXPORT_SYMBOL_GPL(ide_pci_setup_ports);
519 454
520/* 455/*
@@ -597,7 +532,6 @@ int ide_setup_pci_device(struct pci_dev *dev, const struct ide_port_info *d)
597 532
598 return ret; 533 return ret;
599} 534}
600
601EXPORT_SYMBOL_GPL(ide_setup_pci_device); 535EXPORT_SYMBOL_GPL(ide_setup_pci_device);
602 536
603int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2, 537int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2,
@@ -621,5 +555,4 @@ int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2,
621out: 555out:
622 return ret; 556 return ret;
623} 557}
624
625EXPORT_SYMBOL_GPL(ide_setup_pci_devices); 558EXPORT_SYMBOL_GPL(ide_setup_pci_devices);
diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index cbb5ccb27de3..bda6f04791d4 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -210,7 +210,6 @@ unifdef-y += hayesesp.h
210unifdef-y += hdlcdrv.h 210unifdef-y += hdlcdrv.h
211unifdef-y += hdlc.h 211unifdef-y += hdlc.h
212unifdef-y += hdreg.h 212unifdef-y += hdreg.h
213unifdef-y += hdsmart.h
214unifdef-y += hid.h 213unifdef-y += hid.h
215unifdef-y += hiddev.h 214unifdef-y += hiddev.h
216unifdef-y += hidraw.h 215unifdef-y += hidraw.h
diff --git a/include/linux/hdsmart.h b/include/linux/hdsmart.h
deleted file mode 100644
index 4f4faf9d4238..000000000000
--- a/include/linux/hdsmart.h
+++ /dev/null
@@ -1,126 +0,0 @@
1/*
2 * linux/include/linux/hdsmart.h
3 *
4 * Copyright (C) 1999-2000 Michael Cornwell <cornwell@acm.org>
5 * Copyright (C) 2000 Andre Hedrick <andre@linux-ide.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * You should have received a copy of the GNU General Public License
13 * (for example /usr/src/linux/COPYING); if not, write to the Free
14 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16
17#ifndef _LINUX_HDSMART_H
18#define _LINUX_HDSMART_H
19
20#ifndef __KERNEL__
21#define OFFLINE_FULL_SCAN 0
22#define SHORT_SELF_TEST 1
23#define EXTEND_SELF_TEST 2
24#define SHORT_CAPTIVE_SELF_TEST 129
25#define EXTEND_CAPTIVE_SELF_TEST 130
26
27/* smart_attribute is the vendor specific in SFF-8035 spec */
28typedef struct ata_smart_attribute_s {
29 unsigned char id;
30 unsigned short status_flag;
31 unsigned char normalized;
32 unsigned char worse_normal;
33 unsigned char raw[6];
34 unsigned char reserv;
35} __attribute__ ((packed)) ata_smart_attribute_t;
36
37/* smart_values is format of the read drive Atrribute command */
38typedef struct ata_smart_values_s {
39 unsigned short revnumber;
40 ata_smart_attribute_t vendor_attributes [30];
41 unsigned char offline_data_collection_status;
42 unsigned char self_test_exec_status;
43 unsigned short total_time_to_complete_off_line;
44 unsigned char vendor_specific_366;
45 unsigned char offline_data_collection_capability;
46 unsigned short smart_capability;
47 unsigned char errorlog_capability;
48 unsigned char vendor_specific_371;
49 unsigned char short_test_completion_time;
50 unsigned char extend_test_completion_time;
51 unsigned char reserved_374_385 [12];
52 unsigned char vendor_specific_386_509 [125];
53 unsigned char chksum;
54} __attribute__ ((packed)) ata_smart_values_t;
55
56/* Smart Threshold data structures */
57/* Vendor attribute of SMART Threshold */
58typedef struct ata_smart_threshold_entry_s {
59 unsigned char id;
60 unsigned char normalized_threshold;
61 unsigned char reserved[10];
62} __attribute__ ((packed)) ata_smart_threshold_entry_t;
63
64/* Format of Read SMART THreshold Command */
65typedef struct ata_smart_thresholds_s {
66 unsigned short revnumber;
67 ata_smart_threshold_entry_t thres_entries[30];
68 unsigned char reserved[149];
69 unsigned char chksum;
70} __attribute__ ((packed)) ata_smart_thresholds_t;
71
72typedef struct ata_smart_errorlog_command_struct_s {
73 unsigned char devicecontrolreg;
74 unsigned char featuresreg;
75 unsigned char sector_count;
76 unsigned char sector_number;
77 unsigned char cylinder_low;
78 unsigned char cylinder_high;
79 unsigned char drive_head;
80 unsigned char commandreg;
81 unsigned int timestamp;
82} __attribute__ ((packed)) ata_smart_errorlog_command_struct_t;
83
84typedef struct ata_smart_errorlog_error_struct_s {
85 unsigned char error_condition;
86 unsigned char extended_error[14];
87 unsigned char state;
88 unsigned short timestamp;
89} __attribute__ ((packed)) ata_smart_errorlog_error_struct_t;
90
91typedef struct ata_smart_errorlog_struct_s {
92 ata_smart_errorlog_command_struct_t commands[6];
93 ata_smart_errorlog_error_struct_t error_struct;
94} __attribute__ ((packed)) ata_smart_errorlog_struct_t;
95
96typedef struct ata_smart_errorlog_s {
97 unsigned char revnumber;
98 unsigned char error_log_pointer;
99 ata_smart_errorlog_struct_t errorlog_struct[5];
100 unsigned short ata_error_count;
101 unsigned short non_fatal_count;
102 unsigned short drive_timeout_count;
103 unsigned char reserved[53];
104 unsigned char chksum;
105} __attribute__ ((packed)) ata_smart_errorlog_t;
106
107typedef struct ata_smart_selftestlog_struct_s {
108 unsigned char selftestnumber;
109 unsigned char selfteststatus;
110 unsigned short timestamp;
111 unsigned char selftestfailurecheckpoint;
112 unsigned int lbafirstfailure;
113 unsigned char vendorspecific[15];
114} __attribute__ ((packed)) ata_smart_selftestlog_struct_t;
115
116typedef struct ata_smart_selftestlog_s {
117 unsigned short revnumber;
118 ata_smart_selftestlog_struct_t selftest_struct[21];
119 unsigned char vendorspecific[2];
120 unsigned char mostrecenttest;
121 unsigned char resevered[2];
122 unsigned char chksum;
123} __attribute__ ((packed)) ata_smart_selftestlog_t;
124#endif /* __KERNEL__ */
125
126#endif /* _LINUX_HDSMART_H */
diff --git a/include/linux/ide.h b/include/linux/ide.h
index 5f3e82ae901a..f20410dd4482 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -170,7 +170,6 @@ typedef struct hw_regs_s {
170 struct device *dev; 170 struct device *dev;
171} hw_regs_t; 171} hw_regs_t;
172 172
173struct hwif_s * ide_find_port(unsigned long);
174void ide_init_port_data(struct hwif_s *, unsigned int); 173void ide_init_port_data(struct hwif_s *, unsigned int);
175void ide_init_port_hw(struct hwif_s *, hw_regs_t *); 174void ide_init_port_hw(struct hwif_s *, hw_regs_t *);
176 175
@@ -522,7 +521,6 @@ typedef struct hwif_s {
522 unsigned reset : 1; /* reset after probe */ 521 unsigned reset : 1; /* reset after probe */
523 unsigned sg_mapped : 1; /* sg_table and sg_nents are ready */ 522 unsigned sg_mapped : 1; /* sg_table and sg_nents are ready */
524 unsigned mmio : 1; /* host uses MMIO */ 523 unsigned mmio : 1; /* host uses MMIO */
525 unsigned straight8 : 1; /* Alan's straight 8 check */
526 524
527 struct device gendev; 525 struct device gendev;
528 struct device *portdev; 526 struct device *portdev;
@@ -809,6 +807,13 @@ extern ide_hwif_t ide_hwifs[]; /* master data repository */
809#endif 807#endif
810extern int noautodma; 808extern int noautodma;
811 809
810ide_hwif_t *ide_find_port_slot(const struct ide_port_info *);
811
812static inline ide_hwif_t *ide_find_port(void)
813{
814 return ide_find_port_slot(NULL);
815}
816
812extern int ide_end_request (ide_drive_t *drive, int uptodate, int nrsecs); 817extern int ide_end_request (ide_drive_t *drive, int uptodate, int nrsecs);
813int ide_end_dequeued_request(ide_drive_t *drive, struct request *rq, 818int ide_end_dequeued_request(ide_drive_t *drive, struct request *rq,
814 int uptodate, int nr_sectors); 819 int uptodate, int nr_sectors);
@@ -1027,8 +1032,8 @@ enum {
1027 IDE_HFLAG_SINGLE = (1 << 1), 1032 IDE_HFLAG_SINGLE = (1 << 1),
1028 /* don't use legacy PIO blacklist */ 1033 /* don't use legacy PIO blacklist */
1029 IDE_HFLAG_PIO_NO_BLACKLIST = (1 << 2), 1034 IDE_HFLAG_PIO_NO_BLACKLIST = (1 << 2),
1030 /* don't use conservative PIO "downgrade" */ 1035 /* set for the second port of QD65xx */
1031 IDE_HFLAG_PIO_NO_DOWNGRADE = (1 << 3), 1036 IDE_HFLAG_QD_2ND_PORT = (1 << 3),
1032 /* use PIO8/9 for prefetch off/on */ 1037 /* use PIO8/9 for prefetch off/on */
1033 IDE_HFLAG_ABUSE_PREFETCH = (1 << 4), 1038 IDE_HFLAG_ABUSE_PREFETCH = (1 << 4),
1034 /* use PIO6/7 for fast-devsel off/on */ 1039 /* use PIO6/7 for fast-devsel off/on */
@@ -1050,8 +1055,8 @@ enum {
1050 IDE_HFLAG_VDMA = (1 << 11), 1055 IDE_HFLAG_VDMA = (1 << 11),
1051 /* ATAPI DMA is unsupported */ 1056 /* ATAPI DMA is unsupported */
1052 IDE_HFLAG_NO_ATAPI_DMA = (1 << 12), 1057 IDE_HFLAG_NO_ATAPI_DMA = (1 << 12),
1053 /* set if host is a "bootable" controller */ 1058 /* set if host is a "non-bootable" controller */
1054 IDE_HFLAG_BOOTABLE = (1 << 13), 1059 IDE_HFLAG_NON_BOOTABLE = (1 << 13),
1055 /* host doesn't support DMA */ 1060 /* host doesn't support DMA */
1056 IDE_HFLAG_NO_DMA = (1 << 14), 1061 IDE_HFLAG_NO_DMA = (1 << 14),
1057 /* check if host is PCI IDE device before allowing DMA */ 1062 /* check if host is PCI IDE device before allowing DMA */
@@ -1079,8 +1084,6 @@ enum {
1079 /* unmask IRQs */ 1084 /* unmask IRQs */
1080 IDE_HFLAG_UNMASK_IRQS = (1 << 25), 1085 IDE_HFLAG_UNMASK_IRQS = (1 << 25),
1081 IDE_HFLAG_ABUSE_SET_DMA_MODE = (1 << 26), 1086 IDE_HFLAG_ABUSE_SET_DMA_MODE = (1 << 26),
1082 /* host is CY82C693 */
1083 IDE_HFLAG_CY82C693 = (1 << 27),
1084 /* force host out of "simplex" mode */ 1087 /* force host out of "simplex" mode */
1085 IDE_HFLAG_CLEAR_SIMPLEX = (1 << 28), 1088 IDE_HFLAG_CLEAR_SIMPLEX = (1 << 28),
1086 /* DSC overlap is unsupported */ 1089 /* DSC overlap is unsupported */
@@ -1092,9 +1095,9 @@ enum {
1092}; 1095};
1093 1096
1094#ifdef CONFIG_BLK_DEV_OFFBOARD 1097#ifdef CONFIG_BLK_DEV_OFFBOARD
1095# define IDE_HFLAG_OFF_BOARD IDE_HFLAG_BOOTABLE
1096#else
1097# define IDE_HFLAG_OFF_BOARD 0 1098# define IDE_HFLAG_OFF_BOARD 0
1099#else
1100# define IDE_HFLAG_OFF_BOARD IDE_HFLAG_NON_BOOTABLE
1098#endif 1101#endif
1099 1102
1100struct ide_port_info { 1103struct ide_port_info {