diff options
author | Jiri Slaby <jirislaby@gmail.com> | 2007-02-10 04:45:35 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-02-11 13:51:30 -0500 |
commit | 9cde5bf027556bd1e58caa14bfe8cdba64192edd (patch) | |
tree | 733142246490b7250f6488d4d28ea3f6a2018022 | |
parent | 181d6f4fac7f01ede95284954ea1231939dca0d9 (diff) |
[PATCH] Char: moxa, pci_probing prepare
- change pci conf prototype and rename it to moxa_pci_probe
- move some code to moxa_pci_probe
- create moxa_pci_remove
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/char/moxa.c | 64 |
1 files changed, 46 insertions, 18 deletions
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c index 8849d662295e..9b7067b6ab73 100644 --- a/drivers/char/moxa.c +++ b/drivers/char/moxa.c | |||
@@ -275,10 +275,35 @@ static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0); | |||
275 | static DEFINE_SPINLOCK(moxa_lock); | 275 | static DEFINE_SPINLOCK(moxa_lock); |
276 | 276 | ||
277 | #ifdef CONFIG_PCI | 277 | #ifdef CONFIG_PCI |
278 | static int moxa_get_PCI_conf(struct pci_dev *p, int board_type, | 278 | static int __devinit moxa_pci_probe(struct pci_dev *pdev, |
279 | struct moxa_board_conf *board) | 279 | const struct pci_device_id *ent) |
280 | { | 280 | { |
281 | board->baseAddr = pci_resource_start (p, 2); | 281 | struct moxa_board_conf *board; |
282 | unsigned int i; | ||
283 | int board_type = ent->driver_data; | ||
284 | int retval; | ||
285 | |||
286 | retval = pci_enable_device(pdev); | ||
287 | if (retval) | ||
288 | goto err; | ||
289 | |||
290 | for (i = 0; i < MAX_BOARDS; i++) | ||
291 | if (moxa_boards[i].basemem == NULL) | ||
292 | break; | ||
293 | |||
294 | retval = -ENODEV; | ||
295 | if (i >= MAX_BOARDS) { | ||
296 | if (verbose) | ||
297 | printk("More than %d MOXA Intellio family boards " | ||
298 | "found. Board is ignored.\n", MAX_BOARDS); | ||
299 | goto err; | ||
300 | } | ||
301 | |||
302 | board = &moxa_boards[i]; | ||
303 | board->basemem = pci_iomap(pdev, 2, 0x4000); | ||
304 | if (board->basemem == NULL) | ||
305 | goto err; | ||
306 | |||
282 | board->boardType = board_type; | 307 | board->boardType = board_type; |
283 | switch (board_type) { | 308 | switch (board_type) { |
284 | case MOXA_BOARD_C218_ISA: | 309 | case MOXA_BOARD_C218_ISA: |
@@ -295,9 +320,21 @@ static int moxa_get_PCI_conf(struct pci_dev *p, int board_type, | |||
295 | } | 320 | } |
296 | board->busType = MOXA_BUS_TYPE_PCI; | 321 | board->busType = MOXA_BUS_TYPE_PCI; |
297 | /* don't lose the reference in the next pci_get_device iteration */ | 322 | /* don't lose the reference in the next pci_get_device iteration */ |
298 | board->pdev = pci_dev_get(p); | 323 | board->pdev = pci_dev_get(pdev); |
324 | pci_set_drvdata(pdev, board); | ||
299 | 325 | ||
300 | return (0); | 326 | return (0); |
327 | err: | ||
328 | return retval; | ||
329 | } | ||
330 | |||
331 | static void __devexit moxa_pci_remove(struct pci_dev *pdev) | ||
332 | { | ||
333 | struct moxa_board_conf *brd = pci_get_drvdata(pdev); | ||
334 | |||
335 | pci_iounmap(pdev, brd->basemem); | ||
336 | brd->basemem = NULL; | ||
337 | pci_dev_put(pdev); | ||
301 | } | 338 | } |
302 | #endif /* CONFIG_PCI */ | 339 | #endif /* CONFIG_PCI */ |
303 | 340 | ||
@@ -401,18 +438,7 @@ static int __init moxa_init(void) | |||
401 | i = 0; | 438 | i = 0; |
402 | while (i < n) { | 439 | while (i < n) { |
403 | while ((p = pci_get_device(moxa_pcibrds[i].vendor, moxa_pcibrds[i].device, p))!=NULL) | 440 | while ((p = pci_get_device(moxa_pcibrds[i].vendor, moxa_pcibrds[i].device, p))!=NULL) |
404 | { | 441 | moxa_pci_probe(p, &moxa_pcibrds[i]); |
405 | if (pci_enable_device(p)) | ||
406 | continue; | ||
407 | if (numBoards >= MAX_BOARDS) { | ||
408 | if (verbose) | ||
409 | printk("More than %d MOXA Intellio family boards found. Board is ignored.", MAX_BOARDS); | ||
410 | } else { | ||
411 | moxa_get_PCI_conf(p, moxa_pcibrds[i].driver_data, | ||
412 | &moxa_boards[numBoards]); | ||
413 | numBoards++; | ||
414 | } | ||
415 | } | ||
416 | i++; | 442 | i++; |
417 | } | 443 | } |
418 | } | 444 | } |
@@ -442,10 +468,12 @@ static void __exit moxa_exit(void) | |||
442 | put_tty_driver(moxaDriver); | 468 | put_tty_driver(moxaDriver); |
443 | 469 | ||
444 | for (i = 0; i < MAX_BOARDS; i++) { | 470 | for (i = 0; i < MAX_BOARDS; i++) { |
471 | #ifdef CONFIG_PCI | ||
472 | if (moxa_boards[i].busType == MOXA_BUS_TYPE_PCI) | ||
473 | moxa_pci_remove(moxa_boards[i].pdev); | ||
474 | #endif | ||
445 | if (moxa_boards[i].basemem) | 475 | if (moxa_boards[i].basemem) |
446 | iounmap(moxa_boards[i].basemem); | 476 | iounmap(moxa_boards[i].basemem); |
447 | if (moxa_boards[i].busType == MOXA_BUS_TYPE_PCI) | ||
448 | pci_dev_put(moxa_boards[i].pdev); | ||
449 | } | 477 | } |
450 | 478 | ||
451 | if (verbose) | 479 | if (verbose) |