/*
* moxa.c -- MOXA Intellio family multiport serial driver.
*
- * Copyright (C) 1999-2000 Moxa Technologies (support@moxa.com.tw).
+ * Copyright (C) 1999-2000 Moxa Technologies (support@moxa.com).
+ * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
*
* This code is loosely based on the Linux serial driver, written by
* Linus Torvalds, Theodore T'so and others.
#include "moxa.h"
-#define MOXA_VERSION "5.1k"
+#define MOXA_VERSION "6.0k"
#define MOXA_FW_HDRLEN 32
#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.
*/
static int moxa_write_room(struct tty_struct *);
static void moxa_flush_buffer(struct tty_struct *);
static int moxa_chars_in_buffer(struct tty_struct *);
-static void moxa_flush_chars(struct tty_struct *);
-static void moxa_put_char(struct tty_struct *, unsigned char);
static void moxa_throttle(struct tty_struct *);
static void moxa_unthrottle(struct tty_struct *);
static void moxa_set_termios(struct tty_struct *, struct ktermios *);
.write_room = moxa_write_room,
.flush_buffer = moxa_flush_buffer,
.chars_in_buffer = moxa_chars_in_buffer,
- .flush_chars = moxa_flush_chars,
- .put_char = moxa_put_char,
.ioctl = moxa_ioctl,
.throttle = moxa_throttle,
.unthrottle = moxa_unthrottle,
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;
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);
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;
static int moxa_load_fw(struct moxa_board_conf *brd, const struct firmware *fw)
{
- void *ptr = fw->data;
+ const void *ptr = fw->data;
char rsn[64];
u16 lens[5];
size_t len;
u8 model; /* C218T=1, C320T=2, CP204=3 */
u8 reserved2[8];
__le16 len[5];
- } *hdr = ptr;
+ } const *hdr = ptr;
BUILD_BUG_ON(ARRAY_SIZE(hdr->len) != ARRAY_SIZE(lens));
ret = request_firmware(&fw, file, dev);
if (ret) {
- printk(KERN_ERR "request_firmware failed\n");
+ printk(KERN_ERR "MOXA: request_firmware failed. Make sure "
+ "you've placed '%s' file into your firmware "
+ "loader directory (e.g. /lib/firmware)\n",
+ file);
goto err_free;
}
goto err;
}
- board->basemem = ioremap(pci_resource_start(pdev, 2), 0x4000);
+ board->basemem = ioremap_nocache(pci_resource_start(pdev, 2), 0x4000);
if (board->basemem == NULL) {
dev_err(&pdev->dev, "can't remap io space 2\n");
goto err_reg;
pci_set_drvdata(pdev, board);
+ dev_info(&pdev->dev, "board '%s' ready (%u ports, firmware loaded)\n",
+ moxa_brdname[board_type - 1], board->numPorts);
+
return 0;
err_base:
iounmap(board->basemem);
brd->numPorts = type[i] == MOXA_BOARD_C218_ISA ? 8 :
numports[i];
brd->busType = MOXA_BUS_TYPE_ISA;
- brd->basemem = ioremap(baseaddr[i], 0x4000);
+ brd->basemem = ioremap_nocache(baseaddr[i], 0x4000);
if (!brd->basemem) {
printk(KERN_ERR "MOXA: can't remap %lx\n",
baseaddr[i]);
continue;
}
+ printk(KERN_INFO "MOXA isa board found at 0x%.8lu and "
+ "ready (%u ports, firmware loaded)\n",
+ baseaddr[i], brd->numPorts);
+
brd++;
isabrds++;
}
*/
if (ch == NULL)
return 0;
+ lock_kernel();
chars = MoxaPortTxQueue(ch);
if (chars) {
/*
if (!(ch->statusflags & EMPTYWAIT))
moxa_setup_empty_event(tty);
}
+ unlock_kernel();
return chars;
}
-static void moxa_flush_chars(struct tty_struct *tty)
-{
- /*
- * Don't think I need this, because this is called to empty the TX
- * buffer for the 16450, 16550, etc.
- */
-}
-
-static void moxa_put_char(struct tty_struct *tty, unsigned char c)
-{
- struct moxa_port *ch = tty->driver_data;
-
- if (ch == NULL)
- return;
- spin_lock_bh(&moxa_lock);
- MoxaPortWriteData(ch, &c, 1);
- spin_unlock_bh(&moxa_lock);
-
- ch->statusflags |= LOWWAIT;
-}
-
static int moxa_tiocmget(struct tty_struct *tty, struct file *file)
{
struct moxa_port *ch;
* 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)
*
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,
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;
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)) {
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 {