Commit 08d01c79 authored by Jiri Slaby's avatar Jiri Slaby Committed by Linus Torvalds

Char: moxa, introduce MOXA_IS_320 macro

It allows to simplify the code, especially MoxaPortSetBaud.
Signed-off-by: default avatarJiri Slaby <jirislaby@gmail.com>
Tested-by: default avatarOyvind Aabling <Oyvind.Aabling@uni-c.dk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 92d30a93
...@@ -59,6 +59,9 @@ ...@@ -59,6 +59,9 @@
#define MAX_PORTS_PER_BOARD 32 /* Don't change this value */ #define MAX_PORTS_PER_BOARD 32 /* Don't change this value */
#define MAX_PORTS (MAX_BOARDS * MAX_PORTS_PER_BOARD) #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. * 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, ...@@ -512,11 +515,9 @@ static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr,
const u16 *uptr = ptr; const u16 *uptr = ptr;
size_t wlen, len2, j; size_t wlen, len2, j;
unsigned long key, loadbuf, loadlen, checksum, checksum_ok; unsigned long key, loadbuf, loadlen, checksum, checksum_ok;
unsigned int i, retry, c320; unsigned int i, retry;
u16 usum, keycode; u16 usum, keycode;
c320 = brd->boardType == MOXA_BOARD_C320_PCI ||
brd->boardType == MOXA_BOARD_C320_ISA;
keycode = (brd->boardType == MOXA_BOARD_CP204J) ? CP204J_KeyCode : keycode = (brd->boardType == MOXA_BOARD_CP204J) ? CP204J_KeyCode :
C218_KeyCode; C218_KeyCode;
...@@ -586,7 +587,7 @@ static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr, ...@@ -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) if (readw(baseAddr + Magic_no) != Magic_code)
return -EIO; return -EIO;
if (c320) { if (MOXA_IS_320(brd)) {
if (brd->busType == MOXA_BUS_TYPE_PCI) { /* ASIC board */ if (brd->busType == MOXA_BUS_TYPE_PCI) { /* ASIC board */
writew(0x3800, baseAddr + TMS320_PORT1); writew(0x3800, baseAddr + TMS320_PORT1);
writew(0x3900, baseAddr + TMS320_PORT2); writew(0x3900, baseAddr + TMS320_PORT2);
...@@ -607,7 +608,7 @@ static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr, ...@@ -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) if (readw(baseAddr + Magic_no) != Magic_code)
return -EIO; return -EIO;
if (c320) { if (MOXA_IS_320(brd)) {
j = readw(baseAddr + Module_cnt); j = readw(baseAddr + Module_cnt);
if (j <= 0) if (j <= 0)
return -EIO; return -EIO;
...@@ -1635,18 +1636,9 @@ static void MoxaPortFlushData(struct moxa_port *port, int mode) ...@@ -1635,18 +1636,9 @@ static void MoxaPortFlushData(struct moxa_port *port, int mode)
* int port : port number (0 - 127) * 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. * Function 10: Setting baud rate of this port.
* Syntax: * Syntax:
* long MoxaPortSetBaud(int port, long baud); * speed_t MoxaPortSetBaud(int port, speed_t baud);
* int port : port number (0 - 127) * int port : port number (0 - 127)
* long baud : baud rate (50 - 115200) * long baud : baud rate (50 - 115200)
* *
...@@ -1795,8 +1787,7 @@ static void MoxaPortEnable(struct moxa_port *port) ...@@ -1795,8 +1787,7 @@ static void MoxaPortEnable(struct moxa_port *port)
ofsAddr = port->tableAddr; ofsAddr = port->tableAddr;
writew(lowwater, ofsAddr + Low_water); writew(lowwater, ofsAddr + Low_water);
if (port->board->boardType == MOXA_BOARD_C320_ISA || if (MOXA_IS_320(port->board))
port->board->boardType == MOXA_BOARD_C320_PCI)
moxafunc(ofsAddr, FC_SetBreakIrq, 0); moxafunc(ofsAddr, FC_SetBreakIrq, 0);
else else
writew(readw(ofsAddr + HostStat) | WakeupBreak, writew(readw(ofsAddr + HostStat) | WakeupBreak,
...@@ -1819,33 +1810,18 @@ static void MoxaPortDisable(struct moxa_port *port) ...@@ -1819,33 +1810,18 @@ static void MoxaPortDisable(struct moxa_port *port)
moxafunc(ofsAddr, FC_DisableCH, Magic_code); moxafunc(ofsAddr, FC_DisableCH, Magic_code);
} }
static long MoxaPortGetMaxBaud(struct moxa_port *port) static speed_t MoxaPortSetBaud(struct moxa_port *port, speed_t baud)
{
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)
{ {
void __iomem *ofsAddr; void __iomem *ofsAddr = port->tableAddr;
long max, clock; unsigned int clock, val;
unsigned int val; speed_t max;
if (baud < 50L || (max = MoxaPortGetMaxBaud(port)) == 0) max = MOXA_IS_320(port->board) ? 460800 : 921600;
if (baud < 50)
return 0; return 0;
ofsAddr = port->tableAddr;
if (baud > max) if (baud > max)
baud = max; baud = max;
if (max == 38400L) clock = 921600;
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 */
val = clock / baud; val = clock / baud;
moxafunc(ofsAddr, FC_SetBaud, val); moxafunc(ofsAddr, FC_SetBaud, val);
baud = clock / val; baud = clock / val;
...@@ -1890,11 +1866,9 @@ static int MoxaPortSetTermio(struct moxa_port *port, struct ktermios *termio, ...@@ -1890,11 +1866,9 @@ static int MoxaPortSetTermio(struct moxa_port *port, struct ktermios *termio,
moxafunc(ofsAddr, FC_SetDataMode, (u16)mode); moxafunc(ofsAddr, FC_SetDataMode, (u16)mode);
if (port->board->boardType == MOXA_BOARD_C320_ISA || if (MOXA_IS_320(port->board) && baud >= 921600)
port->board->boardType == MOXA_BOARD_C320_PCI) { return -1;
if (baud >= 921600L)
return -1;
}
baud = MoxaPortSetBaud(port, baud); baud = MoxaPortSetBaud(port, baud);
if (termio->c_iflag & (IXON | IXOFF | IXANY)) { if (termio->c_iflag & (IXON | IXOFF | IXANY)) {
...@@ -1954,8 +1928,7 @@ static int MoxaPortLineStatus(struct moxa_port *port) ...@@ -1954,8 +1928,7 @@ static int MoxaPortLineStatus(struct moxa_port *port)
int val; int val;
ofsAddr = port->tableAddr; ofsAddr = port->tableAddr;
if (port->board->boardType == MOXA_BOARD_C320_ISA || if (MOXA_IS_320(port->board)) {
port->board->boardType == MOXA_BOARD_C320_PCI) {
moxafunc(ofsAddr, FC_LineStatus, 0); moxafunc(ofsAddr, FC_LineStatus, 0);
val = readw(ofsAddr + FuncArg); val = readw(ofsAddr + FuncArg);
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment