aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/moxa.c
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2008-04-30 03:53:47 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-30 11:29:43 -0400
commit08d01c792568ba07d2bcf5202dbc8484dbff6747 (patch)
tree7daef55c2bda5fd618a8fb38c82025edfdd97fc7 /drivers/char/moxa.c
parent92d30a9372040a6411e6ed1234fea6153e750874 (diff)
Char: moxa, introduce MOXA_IS_320 macro
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> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char/moxa.c')
-rw-r--r--drivers/char/moxa.c65
1 files changed, 19 insertions, 46 deletions
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 7f8773523fbf..318c465451e6 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -59,6 +59,9 @@
59#define MAX_PORTS_PER_BOARD 32 /* Don't change this value */ 59#define MAX_PORTS_PER_BOARD 32 /* Don't change this value */
60#define MAX_PORTS (MAX_BOARDS * MAX_PORTS_PER_BOARD) 60#define MAX_PORTS (MAX_BOARDS * MAX_PORTS_PER_BOARD)
61 61
62#define MOXA_IS_320(brd) ((brd)->boardType == MOXA_BOARD_C320_ISA || \
63 (brd)->boardType == MOXA_BOARD_C320_PCI)
64
62/* 65/*
63 * Define the Moxa PCI vendor and device IDs. 66 * Define the Moxa PCI vendor and device IDs.
64 */ 67 */
@@ -512,11 +515,9 @@ static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr,
512 const u16 *uptr = ptr; 515 const u16 *uptr = ptr;
513 size_t wlen, len2, j; 516 size_t wlen, len2, j;
514 unsigned long key, loadbuf, loadlen, checksum, checksum_ok; 517 unsigned long key, loadbuf, loadlen, checksum, checksum_ok;
515 unsigned int i, retry, c320; 518 unsigned int i, retry;
516 u16 usum, keycode; 519 u16 usum, keycode;
517 520
518 c320 = brd->boardType == MOXA_BOARD_C320_PCI ||
519 brd->boardType == MOXA_BOARD_C320_ISA;
520 keycode = (brd->boardType == MOXA_BOARD_CP204J) ? CP204J_KeyCode : 521 keycode = (brd->boardType == MOXA_BOARD_CP204J) ? CP204J_KeyCode :
521 C218_KeyCode; 522 C218_KeyCode;
522 523
@@ -586,7 +587,7 @@ static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr,
586 if (readw(baseAddr + Magic_no) != Magic_code) 587 if (readw(baseAddr + Magic_no) != Magic_code)
587 return -EIO; 588 return -EIO;
588 589
589 if (c320) { 590 if (MOXA_IS_320(brd)) {
590 if (brd->busType == MOXA_BUS_TYPE_PCI) { /* ASIC board */ 591 if (brd->busType == MOXA_BUS_TYPE_PCI) { /* ASIC board */
591 writew(0x3800, baseAddr + TMS320_PORT1); 592 writew(0x3800, baseAddr + TMS320_PORT1);
592 writew(0x3900, baseAddr + TMS320_PORT2); 593 writew(0x3900, baseAddr + TMS320_PORT2);
@@ -607,7 +608,7 @@ static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr,
607 if (readw(baseAddr + Magic_no) != Magic_code) 608 if (readw(baseAddr + Magic_no) != Magic_code)
608 return -EIO; 609 return -EIO;
609 610
610 if (c320) { 611 if (MOXA_IS_320(brd)) {
611 j = readw(baseAddr + Module_cnt); 612 j = readw(baseAddr + Module_cnt);
612 if (j <= 0) 613 if (j <= 0)
613 return -EIO; 614 return -EIO;
@@ -1635,18 +1636,9 @@ static void MoxaPortFlushData(struct moxa_port *port, int mode)
1635 * int port : port number (0 - 127) 1636 * int port : port number (0 - 127)
1636 * 1637 *
1637 * 1638 *
1638 * Function 8: Get the maximun available baud rate of this port.
1639 * Syntax:
1640 * long MoxaPortGetMaxBaud(int port);
1641 * int port : port number (0 - 127)
1642 *
1643 * return: 0 : this port is invalid
1644 * 38400/57600/115200 bps
1645 *
1646 *
1647 * Function 10: Setting baud rate of this port. 1639 * Function 10: Setting baud rate of this port.
1648 * Syntax: 1640 * Syntax:
1649 * long MoxaPortSetBaud(int port, long baud); 1641 * speed_t MoxaPortSetBaud(int port, speed_t baud);
1650 * int port : port number (0 - 127) 1642 * int port : port number (0 - 127)
1651 * long baud : baud rate (50 - 115200) 1643 * long baud : baud rate (50 - 115200)
1652 * 1644 *
@@ -1795,8 +1787,7 @@ static void MoxaPortEnable(struct moxa_port *port)
1795 1787
1796 ofsAddr = port->tableAddr; 1788 ofsAddr = port->tableAddr;
1797 writew(lowwater, ofsAddr + Low_water); 1789 writew(lowwater, ofsAddr + Low_water);
1798 if (port->board->boardType == MOXA_BOARD_C320_ISA || 1790 if (MOXA_IS_320(port->board))
1799 port->board->boardType == MOXA_BOARD_C320_PCI)
1800 moxafunc(ofsAddr, FC_SetBreakIrq, 0); 1791 moxafunc(ofsAddr, FC_SetBreakIrq, 0);
1801 else 1792 else
1802 writew(readw(ofsAddr + HostStat) | WakeupBreak, 1793 writew(readw(ofsAddr + HostStat) | WakeupBreak,
@@ -1819,33 +1810,18 @@ static void MoxaPortDisable(struct moxa_port *port)
1819 moxafunc(ofsAddr, FC_DisableCH, Magic_code); 1810 moxafunc(ofsAddr, FC_DisableCH, Magic_code);
1820} 1811}
1821 1812
1822static long MoxaPortGetMaxBaud(struct moxa_port *port) 1813static speed_t MoxaPortSetBaud(struct moxa_port *port, speed_t baud)
1823{
1824 if (port->board->boardType == MOXA_BOARD_C320_ISA ||
1825 port->board->boardType == MOXA_BOARD_C320_PCI)
1826 return 460800L;
1827 else
1828 return 921600L;
1829}
1830
1831
1832static long MoxaPortSetBaud(struct moxa_port *port, long baud)
1833{ 1814{
1834 void __iomem *ofsAddr; 1815 void __iomem *ofsAddr = port->tableAddr;
1835 long max, clock; 1816 unsigned int clock, val;
1836 unsigned int val; 1817 speed_t max;
1837 1818
1838 if (baud < 50L || (max = MoxaPortGetMaxBaud(port)) == 0) 1819 max = MOXA_IS_320(port->board) ? 460800 : 921600;
1820 if (baud < 50)
1839 return 0; 1821 return 0;
1840 ofsAddr = port->tableAddr;
1841 if (baud > max) 1822 if (baud > max)
1842 baud = max; 1823 baud = max;
1843 if (max == 38400L) 1824 clock = 921600;
1844 clock = 614400L; /* for 9.8304 Mhz : max. 38400 bps */
1845 else if (max == 57600L)
1846 clock = 691200L; /* for 11.0592 Mhz : max. 57600 bps */
1847 else
1848 clock = 921600L; /* for 14.7456 Mhz : max. 115200 bps */
1849 val = clock / baud; 1825 val = clock / baud;
1850 moxafunc(ofsAddr, FC_SetBaud, val); 1826 moxafunc(ofsAddr, FC_SetBaud, val);
1851 baud = clock / val; 1827 baud = clock / val;
@@ -1890,11 +1866,9 @@ static int MoxaPortSetTermio(struct moxa_port *port, struct ktermios *termio,
1890 1866
1891 moxafunc(ofsAddr, FC_SetDataMode, (u16)mode); 1867 moxafunc(ofsAddr, FC_SetDataMode, (u16)mode);
1892 1868
1893 if (port->board->boardType == MOXA_BOARD_C320_ISA || 1869 if (MOXA_IS_320(port->board) && baud >= 921600)
1894 port->board->boardType == MOXA_BOARD_C320_PCI) { 1870 return -1;
1895 if (baud >= 921600L) 1871
1896 return -1;
1897 }
1898 baud = MoxaPortSetBaud(port, baud); 1872 baud = MoxaPortSetBaud(port, baud);
1899 1873
1900 if (termio->c_iflag & (IXON | IXOFF | IXANY)) { 1874 if (termio->c_iflag & (IXON | IXOFF | IXANY)) {
@@ -1954,8 +1928,7 @@ static int MoxaPortLineStatus(struct moxa_port *port)
1954 int val; 1928 int val;
1955 1929
1956 ofsAddr = port->tableAddr; 1930 ofsAddr = port->tableAddr;
1957 if (port->board->boardType == MOXA_BOARD_C320_ISA || 1931 if (MOXA_IS_320(port->board)) {
1958 port->board->boardType == MOXA_BOARD_C320_PCI) {
1959 moxafunc(ofsAddr, FC_LineStatus, 0); 1932 moxafunc(ofsAddr, FC_LineStatus, 0);
1960 val = readw(ofsAddr + FuncArg); 1933 val = readw(ofsAddr + FuncArg);
1961 } else { 1934 } else {