linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@gmail.com>
To: "Oyvind Aabling" <Oyvind.Aabling@uni-c.dk>
Cc: <linux-kernel@vger.kernel.org>, Jiri Slaby <jirislaby@gmail.com>
Subject: [RFC 2/5] Char: moxa, cleanup module-param passed isa init
Date: Thu, 24 Jan 2008 10:32:42 +0100	[thread overview]
Message-ID: <1201167165-27635-2-git-send-email-jirislaby@gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0801221042270.19094@dbs1.uni-c.dtu.dk>

Make the code more readable, remap the base address directly. Describe
module parameters.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
 drivers/char/moxa.c |   64 ++++++++++++++++++++++++++------------------------
 1 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 7f4d1ec..485dea6 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -95,7 +95,6 @@ MODULE_DEVICE_TABLE(pci, moxa_pcibrds);
 static struct moxa_board_conf {
 	int boardType;
 	int numPorts;
-	unsigned long baseAddr;
 	int busType;
 
 	int loadstat;
@@ -159,18 +158,21 @@ struct moxa_port {
 static int ttymajor = MOXAMAJOR;
 /* Variables for insmod */
 #ifdef MODULE
-static int baseaddr[4];
-static int type[4];
-static int numports[4];
+static unsigned long baseaddr[MAX_BOARDS];
+static unsigned int type[MAX_BOARDS];
+static unsigned int numports[MAX_BOARDS];
 #endif
 
 MODULE_AUTHOR("William Chen");
 MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver");
 MODULE_LICENSE("GPL");
 #ifdef MODULE
-module_param_array(type, int, NULL, 0);
-module_param_array(baseaddr, int, NULL, 0);
-module_param_array(numports, int, NULL, 0);
+module_param_array(type, uint, NULL, 0);
+MODULE_PARM_DESC(type, "card type: C218=2, C320=4");
+module_param_array(baseaddr, ulong, NULL, 0);
+MODULE_PARM_DESC(baseaddr, "base address");
+module_param_array(numports, uint, NULL, 0);
+MODULE_PARM_DESC(numports, "numports (ignored for C218)");
 #endif
 module_param(ttymajor, int, 0);
 
@@ -335,8 +337,9 @@ static struct pci_driver moxa_pci_driver = {
 
 static int __init moxa_init(void)
 {
-	int i, numBoards = 0, retval = 0;
 	struct moxa_port *ch;
+	unsigned int i, isabrds = 0;
+	int retval = 0;
 
 	printk(KERN_INFO "MOXA Intellio family driver version %s\n",
 			MOXA_VERSION);
@@ -380,46 +383,45 @@ static int __init moxa_init(void)
 
 	mod_timer(&moxaTimer, jiffies + HZ / 50);
 
-	/* Find the boards defined form module args. */
+	/* Find the boards defined from module args. */
 #ifdef MODULE
+	{
+	struct moxa_board_conf *brd = moxa_boards;
 	for (i = 0; i < MAX_BOARDS; i++) {
-		if ((type[i] == MOXA_BOARD_C218_ISA) ||
-		    (type[i] == MOXA_BOARD_C320_ISA)) {
+		if (!baseaddr[i])
+			break;
+		if (type[i] == MOXA_BOARD_C218_ISA ||
+				type[i] == MOXA_BOARD_C320_ISA) {
 			pr_debug("Moxa board %2d: %s board(baseAddr=%lx)\n",
-			       numBoards + 1, moxa_brdname[type[i] - 1],
-			       (unsigned long)baseaddr[i]);
-			if (numBoards >= MAX_BOARDS) {
-				printk(KERN_WARNING "More than %d MOXA "
-					"Intellio family boards found. Board "
-					"is ignored.\n", MAX_BOARDS);
+					isabrds + 1, moxa_brdname[type[i] - 1],
+					baseaddr[i]);
+			brd->boardType = type[i];
+			brd->numPorts = type[i] == MOXA_BOARD_C218_ISA ? 8 :
+					numports[i];
+			brd->busType = MOXA_BUS_TYPE_ISA;
+			brd->basemem = ioremap(baseaddr[i], 0x4000);
+			if (!brd->basemem) {
+				printk(KERN_ERR "moxa: can't remap %lx\n",
+						baseaddr[i]);
 				continue;
 			}
-			moxa_boards[numBoards].boardType = type[i];
-			if (type[i] == MOXA_BOARD_C218_ISA)
-				moxa_boards[numBoards].numPorts = 8;
-			else
-				moxa_boards[numBoards].numPorts = numports[i];
-			moxa_boards[numBoards].busType = MOXA_BUS_TYPE_ISA;
-			moxa_boards[numBoards].baseAddr = baseaddr[i];
-			numBoards++;
+				
+			brd++;
+			isabrds++;
 		}
 	}
+	}
 #endif
 
 #ifdef CONFIG_PCI
 	retval = pci_register_driver(&moxa_pci_driver);
 	if (retval) {
 		printk(KERN_ERR "Can't register moxa pci driver!\n");
-		if (numBoards)
+		if (isabrds)
 			retval = 0;
 	}
 #endif
 
-	for (i = 0; i < numBoards; i++) {
-		moxa_boards[i].basemem = ioremap(moxa_boards[i].baseAddr,
-				0x4000);
-	}
-
 	return retval;
 }
 
-- 
1.5.3.7


  parent reply	other threads:[~2008-01-24  9:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Pine.LNX.4.64.0801202145230.18101@dbs1.uni-c.dtu.dk>
2008-01-21 22:51 ` [PATCH] drivers/char/moxa.c, kernel 2.6.23.14 Jiri Slaby
2008-01-22 10:23   ` Oyvind Aabling
2008-01-23 15:37     ` Jiri Slaby
2008-01-24 23:34       ` Oyvind Aabling
2008-01-24 23:38         ` Jiri Slaby
2008-01-24  9:32     ` [RFC 1/5] Char: moxa, remove static isa support Jiri Slaby
2008-01-24  9:32     ` Jiri Slaby [this message]
2008-01-24  9:32     ` [RFC 3/5] Char: moxa, pci io space fixup Jiri Slaby
2008-01-24  9:32     ` [RFC 4/5] Char: moxa, fix TIOC(G/S)SOFTCAR param Jiri Slaby
2008-01-24  9:32     ` [RFC 5/5] Char: moxa, add firmware loading Jiri Slaby
2008-01-27 19:16       ` [RFC 1/6] " Jiri Slaby
2008-01-27 19:16       ` [RFC 2/6] Char: moxa, merge c2xx and c320 " Jiri Slaby
2008-01-27 19:16       ` [RFC 3/6] Char: moxa, remove port->port Jiri Slaby
2008-01-27 19:16       ` [RFC 4/6] Char: moxa, remove unused port entries Jiri Slaby
2008-01-27 19:16       ` [RFC 5/6] Char: moxa, centralize board readiness Jiri Slaby
2008-01-27 19:16       ` [RFC 6/6] Char: moxa, timer cleanup 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=1201167165-27635-2-git-send-email-jirislaby@gmail.com \
    --to=jirislaby@gmail.com \
    --cc=Oyvind.Aabling@uni-c.dk \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).