mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: <linux-kernel@vger.kernel.org>, <alan@lxorguk.ukuu.org.uk>,
	Oyvind Aabling <Oyvind.Aabling@uni-c.dk>,
	Jiri Slaby <jirislaby@gmail.com>
Subject: [PATCH 18/19] Char: moxa, introduce MOXA_IS_320 macro
Date: Fri, 22 Feb 2008 15:46:45 +0100	[thread overview]
Message-ID: <1203691606-9310-18-git-send-email-jirislaby@gmail.com> (raw)
In-Reply-To: <1203691606-9310-1-git-send-email-jirislaby@gmail.com>

It allows to simplify the code, especially MoxaPortSetBaud.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Tested-by: Oyvind Aabling <Oyvind.Aabling@uni-c.dk>
---
 drivers/char/moxa.c |   65 +++++++++++++++------------------------------------
 1 files changed, 19 insertions(+), 46 deletions(-)

diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index b0f9995..ee8b821 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -59,6 +59,9 @@
 #define MAX_PORTS_PER_BOARD	32	/* Don't change this value */
 #define MAX_PORTS		(MAX_BOARDS * MAX_PORTS_PER_BOARD)
 
+#define MOXA_IS_320(brd) ((brd)->boardType == MOXA_BOARD_C320_ISA || \
+		(brd)->boardType == MOXA_BOARD_C320_PCI)
+
 /*
  *    Define the Moxa PCI vendor and device IDs.
  */
@@ -512,11 +515,9 @@ static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr,
 	const u16 *uptr = ptr;
 	size_t wlen, len2, j;
 	unsigned long key, loadbuf, loadlen, checksum, checksum_ok;
-	unsigned int i, retry, c320;
+	unsigned int i, retry;
 	u16 usum, keycode;
 
-	c320 = brd->boardType == MOXA_BOARD_C320_PCI ||
-			brd->boardType == MOXA_BOARD_C320_ISA;
 	keycode = (brd->boardType == MOXA_BOARD_CP204J) ? CP204J_KeyCode :
 				C218_KeyCode;
 
@@ -586,7 +587,7 @@ static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr,
 	if (readw(baseAddr + Magic_no) != Magic_code)
 		return -EIO;
 
-	if (c320) {
+	if (MOXA_IS_320(brd)) {
 		if (brd->busType == MOXA_BUS_TYPE_PCI) {	/* ASIC board */
 			writew(0x3800, baseAddr + TMS320_PORT1);
 			writew(0x3900, baseAddr + TMS320_PORT2);
@@ -607,7 +608,7 @@ static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr,
 	if (readw(baseAddr + Magic_no) != Magic_code)
 		return -EIO;
 
-	if (c320) {
+	if (MOXA_IS_320(brd)) {
 		j = readw(baseAddr + Module_cnt);
 		if (j <= 0)
 			return -EIO;
@@ -1634,18 +1635,9 @@ static void MoxaPortFlushData(struct moxa_port *port, int mode)
  *           int port           : port number (0 - 127)
  *
  *
- *      Function 8:     Get the maximun available baud rate of this port.
- *      Syntax:
- *      long MoxaPortGetMaxBaud(int port);
- *           int port           : port number (0 - 127)
- *
- *           return:    0       : this port is invalid
- *                      38400/57600/115200 bps
- *
- *
  *      Function 10:    Setting baud rate of this port.
  *      Syntax:
- *      long MoxaPortSetBaud(int port, long baud);
+ *      speed_t MoxaPortSetBaud(int port, speed_t baud);
  *           int port           : port number (0 - 127)
  *           long baud          : baud rate (50 - 115200)
  *
@@ -1794,8 +1786,7 @@ static void MoxaPortEnable(struct moxa_port *port)
 
 	ofsAddr = port->tableAddr;
 	writew(lowwater, ofsAddr + Low_water);
-	if (port->board->boardType == MOXA_BOARD_C320_ISA ||
-			port->board->boardType == MOXA_BOARD_C320_PCI)
+	if (MOXA_IS_320(port->board))
 		moxafunc(ofsAddr, FC_SetBreakIrq, 0);
 	else
 		writew(readw(ofsAddr + HostStat) | WakeupBreak,
@@ -1818,33 +1809,18 @@ static void MoxaPortDisable(struct moxa_port *port)
 	moxafunc(ofsAddr, FC_DisableCH, Magic_code);
 }
 
-static long MoxaPortGetMaxBaud(struct moxa_port *port)
-{
-	if (port->board->boardType == MOXA_BOARD_C320_ISA ||
-			port->board->boardType == MOXA_BOARD_C320_PCI)
-		return 460800L;
-	else
-		return 921600L;
-}
-
-
-static long MoxaPortSetBaud(struct moxa_port *port, long baud)
+static speed_t MoxaPortSetBaud(struct moxa_port *port, speed_t baud)
 {
-	void __iomem *ofsAddr;
-	long max, clock;
-	unsigned int val;
+	void __iomem *ofsAddr = port->tableAddr;
+	unsigned int clock, val;
+	speed_t max;
 
-	if (baud < 50L || (max = MoxaPortGetMaxBaud(port)) == 0)
+	max = MOXA_IS_320(port->board) ? 460800 : 921600;
+	if (baud < 50)
 		return 0;
-	ofsAddr = port->tableAddr;
 	if (baud > max)
 		baud = max;
-	if (max == 38400L)
-		clock = 614400L;	/* for 9.8304 Mhz : max. 38400 bps */
-	else if (max == 57600L)
-		clock = 691200L;	/* for 11.0592 Mhz : max. 57600 bps */
-	else
-		clock = 921600L;	/* for 14.7456 Mhz : max. 115200 bps */
+	clock = 921600;
 	val = clock / baud;
 	moxafunc(ofsAddr, FC_SetBaud, val);
 	baud = clock / val;
@@ -1889,11 +1865,9 @@ static int MoxaPortSetTermio(struct moxa_port *port, struct ktermios *termio,
 
 	moxafunc(ofsAddr, FC_SetDataMode, (u16)mode);
 
-	if (port->board->boardType == MOXA_BOARD_C320_ISA ||
-			port->board->boardType == MOXA_BOARD_C320_PCI) {
-		if (baud >= 921600L)
-			return -1;
-	}
+	if (MOXA_IS_320(port->board) && baud >= 921600)
+		return -1;
+
 	baud = MoxaPortSetBaud(port, baud);
 
 	if (termio->c_iflag & (IXON | IXOFF | IXANY)) {
@@ -1953,8 +1927,7 @@ static int MoxaPortLineStatus(struct moxa_port *port)
 	int val;
 
 	ofsAddr = port->tableAddr;
-	if (port->board->boardType == MOXA_BOARD_C320_ISA ||
-			port->board->boardType == MOXA_BOARD_C320_PCI) {
+	if (MOXA_IS_320(port->board)) {
 		moxafunc(ofsAddr, FC_LineStatus, 0);
 		val = readw(ofsAddr + FuncArg);
 	} else {
-- 
1.5.4.1


  parent reply	other threads:[~2008-02-22 14:54 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-22 14:46 [PATCH 01/19] Char: moxa, remove static isa support Jiri Slaby
2008-02-22 14:46 ` [PATCH 02/19] Char: moxa, cleanup module-param passed isa init Jiri Slaby
2008-02-22 14:46 ` [PATCH 03/19] Char: moxa, pci io space fixup Jiri Slaby
2008-02-22 14:46 ` [PATCH 04/19] Char: moxa, fix TIOC(G/S)SOFTCAR param Jiri Slaby
2008-02-22 14:46 ` [PATCH 05/19] Char: moxa, add firmware loading Jiri Slaby
2008-02-22 14:46 ` [PATCH 06/19] Char: moxa, merge c2xx and c320 " Jiri Slaby
2008-02-22 14:46 ` [PATCH 07/19] Char: moxa, remove port->port Jiri Slaby
2008-02-22 14:46 ` [PATCH 08/19] Char: moxa, remove unused port entries Jiri Slaby
2008-02-22 14:46 ` [PATCH 09/19] Char: moxa, centralize board readiness Jiri Slaby
2008-02-22 14:46 ` [PATCH 10/19] Char: moxa, timer cleanup Jiri Slaby
2008-02-22 14:46 ` [PATCH 11/19] Char: moxa, ioctl cleanup Jiri Slaby
2008-02-22 14:46 ` [PATCH 12/19] Char: moxa, merge 2 poll functions Jiri Slaby
2008-02-22 14:46 ` [PATCH 13/19] Char: moxa, cleanup rx/tx Jiri Slaby
2008-02-22 14:46 ` [PATCH 14/19] Char: moxa, serialise timer Jiri Slaby
2008-02-22 14:46 ` [PATCH 15/19] Char: moxa, rework open/close Jiri Slaby
2008-02-22 14:46 ` [PATCH 16/19] Char: moxa, little cleanup Jiri Slaby
2008-02-22 14:46 ` [PATCH 17/19] Char: moxa, remove useless tty functions Jiri Slaby
2008-02-22 14:46 ` Jiri Slaby [this message]
2008-02-22 14:46 ` [PATCH 19/19] Char: moxa, notify about board readiness Jiri Slaby
2008-02-22 20:09 ` [PATCH 20/21] Char: moxa, update credits Jiri Slaby
2008-02-22 20:09 ` [PATCH 21/21] Char: moxa, add firmware loading fix 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=1203691606-9310-18-git-send-email-jirislaby@gmail.com \
    --to=jirislaby@gmail.com \
    --cc=Oyvind.Aabling@uni-c.dk \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --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

Powered by JetHome