From: Jiri Slaby <jirislaby@gmail.com>
To: Andrew Morton <akpm@osdl.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: [PATCH 6/7] Char: moxa, pci_probing prepare
Date: Fri, 5 Jan 2007 18:12:00 +0100 (CET) [thread overview]
Message-ID: <16195189622607828668@wsc.cz> (raw)
In-Reply-To: <16079316021425814645@wsc.cz>
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>
---
commit cd7aa5e22313e6a0f2ec6a02960793fc54c26416
tree 8ff42a1436ecfa86ef0297f7d68317a0b8a454d3
parent d35a569e31595b9b8f70bfd1d3aae7f830d183fe
author Jiri Slaby <jirislaby@gmail.com> Wed, 03 Jan 2007 15:04:59 +0059
committer Jiri Slaby <jirislaby@gmail.com> Fri, 05 Jan 2007 17:55:22 +0059
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 8849d66..9b7067b 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -275,10 +275,35 @@ static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0);
static DEFINE_SPINLOCK(moxa_lock);
#ifdef CONFIG_PCI
-static int moxa_get_PCI_conf(struct pci_dev *p, int board_type,
- struct moxa_board_conf *board)
+static int __devinit moxa_pci_probe(struct pci_dev *pdev,
+ const struct pci_device_id *ent)
{
- board->baseAddr = pci_resource_start (p, 2);
+ struct moxa_board_conf *board;
+ unsigned int i;
+ int board_type = ent->driver_data;
+ int retval;
+
+ retval = pci_enable_device(pdev);
+ if (retval)
+ goto err;
+
+ for (i = 0; i < MAX_BOARDS; i++)
+ if (moxa_boards[i].basemem == NULL)
+ break;
+
+ retval = -ENODEV;
+ if (i >= MAX_BOARDS) {
+ if (verbose)
+ printk("More than %d MOXA Intellio family boards "
+ "found. Board is ignored.\n", MAX_BOARDS);
+ goto err;
+ }
+
+ board = &moxa_boards[i];
+ board->basemem = pci_iomap(pdev, 2, 0x4000);
+ if (board->basemem == NULL)
+ goto err;
+
board->boardType = board_type;
switch (board_type) {
case MOXA_BOARD_C218_ISA:
@@ -295,9 +320,21 @@ static int moxa_get_PCI_conf(struct pci_dev *p, int board_type,
}
board->busType = MOXA_BUS_TYPE_PCI;
/* don't lose the reference in the next pci_get_device iteration */
- board->pdev = pci_dev_get(p);
+ board->pdev = pci_dev_get(pdev);
+ pci_set_drvdata(pdev, board);
return (0);
+err:
+ return retval;
+}
+
+static void __devexit moxa_pci_remove(struct pci_dev *pdev)
+{
+ struct moxa_board_conf *brd = pci_get_drvdata(pdev);
+
+ pci_iounmap(pdev, brd->basemem);
+ brd->basemem = NULL;
+ pci_dev_put(pdev);
}
#endif /* CONFIG_PCI */
@@ -401,18 +438,7 @@ static int __init moxa_init(void)
i = 0;
while (i < n) {
while ((p = pci_get_device(moxa_pcibrds[i].vendor, moxa_pcibrds[i].device, p))!=NULL)
- {
- if (pci_enable_device(p))
- continue;
- if (numBoards >= MAX_BOARDS) {
- if (verbose)
- printk("More than %d MOXA Intellio family boards found. Board is ignored.", MAX_BOARDS);
- } else {
- moxa_get_PCI_conf(p, moxa_pcibrds[i].driver_data,
- &moxa_boards[numBoards]);
- numBoards++;
- }
- }
+ moxa_pci_probe(p, &moxa_pcibrds[i]);
i++;
}
}
@@ -442,10 +468,12 @@ static void __exit moxa_exit(void)
put_tty_driver(moxaDriver);
for (i = 0; i < MAX_BOARDS; i++) {
+#ifdef CONFIG_PCI
+ if (moxa_boards[i].busType == MOXA_BUS_TYPE_PCI)
+ moxa_pci_remove(moxa_boards[i].pdev);
+#endif
if (moxa_boards[i].basemem)
iounmap(moxa_boards[i].basemem);
- if (moxa_boards[i].busType == MOXA_BUS_TYPE_PCI)
- pci_dev_put(moxa_boards[i].pdev);
}
if (verbose)
next prev parent reply other threads:[~2007-01-05 17:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-05 17:10 [PATCH 1/7] Char: moxa, macros cleanup Jiri Slaby
2007-01-05 17:10 ` [PATCH 2/7] Char: moxa, use del_timer_sync Jiri Slaby
2007-01-05 17:11 ` [PATCH 3/7] Char: moxa, remove moxa_pci_devinfo Jiri Slaby
2007-01-05 17:11 ` [PATCH 4/7] Char: moxa, variables cleanup Jiri Slaby
2007-01-05 17:11 ` [PATCH 5/7] Char: moxa, remove useless vairables Jiri Slaby
2007-01-05 17:12 ` Jiri Slaby [this message]
2007-01-05 17:12 ` [PATCH 7/7] Char: moxa, pci probing Jiri Slaby
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16195189622607828668@wsc.cz \
--to=jirislaby@gmail.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.