aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/legacy/ide-cs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide/legacy/ide-cs.c')
-rw-r--r--drivers/ide/legacy/ide-cs.c76
1 files changed, 53 insertions, 23 deletions
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index b97b8d51b3eb..855e157b18d3 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -51,6 +51,8 @@
51#include <pcmcia/cisreg.h> 51#include <pcmcia/cisreg.h>
52#include <pcmcia/ciscode.h> 52#include <pcmcia/ciscode.h>
53 53
54#define DRV_NAME "ide-cs"
55
54/*====================================================================*/ 56/*====================================================================*/
55 57
56/* Module parameters */ 58/* Module parameters */
@@ -72,16 +74,11 @@ static char *version =
72 74
73/*====================================================================*/ 75/*====================================================================*/
74 76
75static const char ide_major[] = {
76 IDE0_MAJOR, IDE1_MAJOR, IDE2_MAJOR, IDE3_MAJOR,
77 IDE4_MAJOR, IDE5_MAJOR
78};
79
80typedef struct ide_info_t { 77typedef struct ide_info_t {
81 struct pcmcia_device *p_dev; 78 struct pcmcia_device *p_dev;
79 ide_hwif_t *hwif;
82 int ndev; 80 int ndev;
83 dev_node_t node; 81 dev_node_t node;
84 int hd;
85} ide_info_t; 82} ide_info_t;
86 83
87static void ide_release(struct pcmcia_device *); 84static void ide_release(struct pcmcia_device *);
@@ -136,20 +133,44 @@ static int ide_probe(struct pcmcia_device *link)
136 133
137static void ide_detach(struct pcmcia_device *link) 134static void ide_detach(struct pcmcia_device *link)
138{ 135{
136 ide_info_t *info = link->priv;
137 ide_hwif_t *hwif = info->hwif;
138
139 DEBUG(0, "ide_detach(0x%p)\n", link); 139 DEBUG(0, "ide_detach(0x%p)\n", link);
140 140
141 ide_release(link); 141 ide_release(link);
142 142
143 kfree(link->priv); 143 release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
144 release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
145
146 kfree(info);
144} /* ide_detach */ 147} /* ide_detach */
145 148
146static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq, struct pcmcia_device *handle) 149static const struct ide_port_ops idecs_port_ops = {
150 .quirkproc = ide_undecoded_slave,
151};
152
153static ide_hwif_t *idecs_register(unsigned long io, unsigned long ctl,
154 unsigned long irq, struct pcmcia_device *handle)
147{ 155{
148 ide_hwif_t *hwif; 156 ide_hwif_t *hwif;
149 hw_regs_t hw; 157 hw_regs_t hw;
150 int i; 158 int i;
151 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; 159 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
152 160
161 if (!request_region(io, 8, DRV_NAME)) {
162 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
163 DRV_NAME, io, io + 7);
164 return NULL;
165 }
166
167 if (!request_region(ctl, 1, DRV_NAME)) {
168 printk(KERN_ERR "%s: I/O resource 0x%lX not free.\n",
169 DRV_NAME, ctl);
170 release_region(io, 8);
171 return NULL;
172 }
173
153 memset(&hw, 0, sizeof(hw)); 174 memset(&hw, 0, sizeof(hw));
154 ide_std_init_ports(&hw, io, ctl); 175 ide_std_init_ports(&hw, io, ctl);
155 hw.irq = irq; 176 hw.irq = irq;
@@ -158,7 +179,7 @@ static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq
158 179
159 hwif = ide_find_port(); 180 hwif = ide_find_port();
160 if (hwif == NULL) 181 if (hwif == NULL)
161 return -1; 182 goto out_release;
162 183
163 i = hwif->index; 184 i = hwif->index;
164 185
@@ -168,13 +189,19 @@ static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq
168 ide_init_port_data(hwif, i); 189 ide_init_port_data(hwif, i);
169 190
170 ide_init_port_hw(hwif, &hw); 191 ide_init_port_hw(hwif, &hw);
171 hwif->quirkproc = &ide_undecoded_slave; 192 hwif->port_ops = &idecs_port_ops;
172 193
173 idx[0] = i; 194 idx[0] = i;
174 195
175 ide_device_add(idx, NULL); 196 ide_device_add(idx, NULL);
176 197
177 return hwif->present ? i : -1; 198 if (hwif->present)
199 return hwif;
200
201out_release:
202 release_region(ctl, 1);
203 release_region(io, 8);
204 return NULL;
178} 205}
179 206
180/*====================================================================== 207/*======================================================================
@@ -199,8 +226,9 @@ static int ide_config(struct pcmcia_device *link)
199 cistpl_cftable_entry_t dflt; 226 cistpl_cftable_entry_t dflt;
200 } *stk = NULL; 227 } *stk = NULL;
201 cistpl_cftable_entry_t *cfg; 228 cistpl_cftable_entry_t *cfg;
202 int i, pass, last_ret = 0, last_fn = 0, hd, is_kme = 0; 229 int i, pass, last_ret = 0, last_fn = 0, is_kme = 0;
203 unsigned long io_base, ctl_base; 230 unsigned long io_base, ctl_base;
231 ide_hwif_t *hwif;
204 232
205 DEBUG(0, "ide_config(0x%p)\n", link); 233 DEBUG(0, "ide_config(0x%p)\n", link);
206 234
@@ -296,14 +324,15 @@ static int ide_config(struct pcmcia_device *link)
296 outb(0x81, ctl_base+1); 324 outb(0x81, ctl_base+1);
297 325
298 /* retry registration in case device is still spinning up */ 326 /* retry registration in case device is still spinning up */
299 for (hd = -1, i = 0; i < 10; i++) { 327 for (i = 0; i < 10; i++) {
300 hd = idecs_register(io_base, ctl_base, link->irq.AssignedIRQ, link); 328 hwif = idecs_register(io_base, ctl_base, link->irq.AssignedIRQ, link);
301 if (hd >= 0) break; 329 if (hwif)
330 break;
302 if (link->io.NumPorts1 == 0x20) { 331 if (link->io.NumPorts1 == 0x20) {
303 outb(0x02, ctl_base + 0x10); 332 outb(0x02, ctl_base + 0x10);
304 hd = idecs_register(io_base + 0x10, ctl_base + 0x10, 333 hwif = idecs_register(io_base + 0x10, ctl_base + 0x10,
305 link->irq.AssignedIRQ, link); 334 link->irq.AssignedIRQ, link);
306 if (hd >= 0) { 335 if (hwif) {
307 io_base += 0x10; 336 io_base += 0x10;
308 ctl_base += 0x10; 337 ctl_base += 0x10;
309 break; 338 break;
@@ -312,7 +341,7 @@ static int ide_config(struct pcmcia_device *link)
312 msleep(100); 341 msleep(100);
313 } 342 }
314 343
315 if (hd < 0) { 344 if (hwif == NULL) {
316 printk(KERN_NOTICE "ide-cs: ide_register() at 0x%3lx & 0x%3lx" 345 printk(KERN_NOTICE "ide-cs: ide_register() at 0x%3lx & 0x%3lx"
317 ", irq %u failed\n", io_base, ctl_base, 346 ", irq %u failed\n", io_base, ctl_base,
318 link->irq.AssignedIRQ); 347 link->irq.AssignedIRQ);
@@ -320,10 +349,10 @@ static int ide_config(struct pcmcia_device *link)
320 } 349 }
321 350
322 info->ndev = 1; 351 info->ndev = 1;
323 sprintf(info->node.dev_name, "hd%c", 'a' + (hd * 2)); 352 sprintf(info->node.dev_name, "hd%c", 'a' + hwif->index * 2);
324 info->node.major = ide_major[hd]; 353 info->node.major = hwif->major;
325 info->node.minor = 0; 354 info->node.minor = 0;
326 info->hd = hd; 355 info->hwif = hwif;
327 link->dev_node = &info->node; 356 link->dev_node = &info->node;
328 printk(KERN_INFO "ide-cs: %s: Vpp = %d.%d\n", 357 printk(KERN_INFO "ide-cs: %s: Vpp = %d.%d\n",
329 info->node.dev_name, link->conf.Vpp / 10, link->conf.Vpp % 10); 358 info->node.dev_name, link->conf.Vpp / 10, link->conf.Vpp % 10);
@@ -354,13 +383,14 @@ failed:
354void ide_release(struct pcmcia_device *link) 383void ide_release(struct pcmcia_device *link)
355{ 384{
356 ide_info_t *info = link->priv; 385 ide_info_t *info = link->priv;
386 ide_hwif_t *hwif = info->hwif;
357 387
358 DEBUG(0, "ide_release(0x%p)\n", link); 388 DEBUG(0, "ide_release(0x%p)\n", link);
359 389
360 if (info->ndev) { 390 if (info->ndev) {
361 /* FIXME: if this fails we need to queue the cleanup somehow 391 /* FIXME: if this fails we need to queue the cleanup somehow
362 -- need to investigate the required PCMCIA magic */ 392 -- need to investigate the required PCMCIA magic */
363 ide_unregister(info->hd); 393 ide_unregister(hwif->index);
364 } 394 }
365 info->ndev = 0; 395 info->ndev = 0;
366 396