aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/legacy
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-04-26 16:25:17 -0400
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-04-26 16:25:17 -0400
commitd703b79e56eb103b72ad1bceebe8ef4e8635fb1c (patch)
tree69a14e68e1000b1bd23259e2e83647f3e986d3aa /drivers/ide/legacy
parent134d4548a7a1d27781dcbce9725c7f7914f7ae47 (diff)
ide-cs: manage I/O resources in driver
* Make idecs_register() return pointer to hwif structure instead of hwif's index. * Store pointer to hwif structure instead of hwif's index in ide_info_t (fixes ide-cs for IDE[6-9]_MAJOR major numbers). * Remove no longer needed ide_major[]. * Tell IDE layer to not manage resources by setting hwif->mmio flag. * Use {request,release}_region() for resources management. * Use driver name for resources management. Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/legacy')
-rw-r--r--drivers/ide/legacy/ide-cs.c70
1 files changed, 48 insertions, 22 deletions
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index c491850e0f7f..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,24 +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 const struct ide_port_ops idecs_port_ops = { 149static const struct ide_port_ops idecs_port_ops = {
147 .quirkproc = ide_undecoded_slave, 150 .quirkproc = ide_undecoded_slave,
148}; 151};
149 152
150static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq, struct pcmcia_device *handle) 153static ide_hwif_t *idecs_register(unsigned long io, unsigned long ctl,
154 unsigned long irq, struct pcmcia_device *handle)
151{ 155{
152 ide_hwif_t *hwif; 156 ide_hwif_t *hwif;
153 hw_regs_t hw; 157 hw_regs_t hw;
154 int i; 158 int i;
155 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; 159 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
156 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
157 memset(&hw, 0, sizeof(hw)); 174 memset(&hw, 0, sizeof(hw));
158 ide_std_init_ports(&hw, io, ctl); 175 ide_std_init_ports(&hw, io, ctl);
159 hw.irq = irq; 176 hw.irq = irq;
@@ -162,7 +179,7 @@ static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq
162 179
163 hwif = ide_find_port(); 180 hwif = ide_find_port();
164 if (hwif == NULL) 181 if (hwif == NULL)
165 return -1; 182 goto out_release;
166 183
167 i = hwif->index; 184 i = hwif->index;
168 185
@@ -178,7 +195,13 @@ static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq
178 195
179 ide_device_add(idx, NULL); 196 ide_device_add(idx, NULL);
180 197
181 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;
182} 205}
183 206
184/*====================================================================== 207/*======================================================================
@@ -203,8 +226,9 @@ static int ide_config(struct pcmcia_device *link)
203 cistpl_cftable_entry_t dflt; 226 cistpl_cftable_entry_t dflt;
204 } *stk = NULL; 227 } *stk = NULL;
205 cistpl_cftable_entry_t *cfg; 228 cistpl_cftable_entry_t *cfg;
206 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;
207 unsigned long io_base, ctl_base; 230 unsigned long io_base, ctl_base;
231 ide_hwif_t *hwif;
208 232
209 DEBUG(0, "ide_config(0x%p)\n", link); 233 DEBUG(0, "ide_config(0x%p)\n", link);
210 234
@@ -300,14 +324,15 @@ static int ide_config(struct pcmcia_device *link)
300 outb(0x81, ctl_base+1); 324 outb(0x81, ctl_base+1);
301 325
302 /* retry registration in case device is still spinning up */ 326 /* retry registration in case device is still spinning up */
303 for (hd = -1, i = 0; i < 10; i++) { 327 for (i = 0; i < 10; i++) {
304 hd = idecs_register(io_base, ctl_base, link->irq.AssignedIRQ, link); 328 hwif = idecs_register(io_base, ctl_base, link->irq.AssignedIRQ, link);
305 if (hd >= 0) break; 329 if (hwif)
330 break;
306 if (link->io.NumPorts1 == 0x20) { 331 if (link->io.NumPorts1 == 0x20) {
307 outb(0x02, ctl_base + 0x10); 332 outb(0x02, ctl_base + 0x10);
308 hd = idecs_register(io_base + 0x10, ctl_base + 0x10, 333 hwif = idecs_register(io_base + 0x10, ctl_base + 0x10,
309 link->irq.AssignedIRQ, link); 334 link->irq.AssignedIRQ, link);
310 if (hd >= 0) { 335 if (hwif) {
311 io_base += 0x10; 336 io_base += 0x10;
312 ctl_base += 0x10; 337 ctl_base += 0x10;
313 break; 338 break;
@@ -316,7 +341,7 @@ static int ide_config(struct pcmcia_device *link)
316 msleep(100); 341 msleep(100);
317 } 342 }
318 343
319 if (hd < 0) { 344 if (hwif == NULL) {
320 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"
321 ", irq %u failed\n", io_base, ctl_base, 346 ", irq %u failed\n", io_base, ctl_base,
322 link->irq.AssignedIRQ); 347 link->irq.AssignedIRQ);
@@ -324,10 +349,10 @@ static int ide_config(struct pcmcia_device *link)
324 } 349 }
325 350
326 info->ndev = 1; 351 info->ndev = 1;
327 sprintf(info->node.dev_name, "hd%c", 'a' + (hd * 2)); 352 sprintf(info->node.dev_name, "hd%c", 'a' + hwif->index * 2);
328 info->node.major = ide_major[hd]; 353 info->node.major = hwif->major;
329 info->node.minor = 0; 354 info->node.minor = 0;
330 info->hd = hd; 355 info->hwif = hwif;
331 link->dev_node = &info->node; 356 link->dev_node = &info->node;
332 printk(KERN_INFO "ide-cs: %s: Vpp = %d.%d\n", 357 printk(KERN_INFO "ide-cs: %s: Vpp = %d.%d\n",
333 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);
@@ -358,13 +383,14 @@ failed:
358void ide_release(struct pcmcia_device *link) 383void ide_release(struct pcmcia_device *link)
359{ 384{
360 ide_info_t *info = link->priv; 385 ide_info_t *info = link->priv;
386 ide_hwif_t *hwif = info->hwif;
361 387
362 DEBUG(0, "ide_release(0x%p)\n", link); 388 DEBUG(0, "ide_release(0x%p)\n", link);
363 389
364 if (info->ndev) { 390 if (info->ndev) {
365 /* FIXME: if this fails we need to queue the cleanup somehow 391 /* FIXME: if this fails we need to queue the cleanup somehow
366 -- need to investigate the required PCMCIA magic */ 392 -- need to investigate the required PCMCIA magic */
367 ide_unregister(info->hd); 393 ide_unregister(hwif->index);
368 } 394 }
369 info->ndev = 0; 395 info->ndev = 0;
370 396