]> err.no Git - linux-2.6/blobdiff - drivers/char/moxa.c
V4L/DVB (7848): Fix dependencies for tuner-xc2028 and em28xx-dvb
[linux-2.6] / drivers / char / moxa.c
index 7f8773523fbf11876237fcd97fe0502603ba3b4a..d57d3a61919b310f22e972e97cf1c8797334db1d 100644 (file)
@@ -2,7 +2,8 @@
 /*
  *           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.
@@ -49,7 +50,7 @@
 
 #include "moxa.h"
 
-#define MOXA_VERSION           "5.1k"
+#define MOXA_VERSION           "6.0k"
 
 #define MOXA_FW_HDRLEN         32
 
@@ -59,6 +60,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 +516,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 +588,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 +609,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;
@@ -844,7 +846,10 @@ static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
 
        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;
        }
 
@@ -932,7 +937,7 @@ static int __devinit moxa_pci_probe(struct pci_dev *pdev,
                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;
@@ -960,6 +965,9 @@ static int __devinit moxa_pci_probe(struct pci_dev *pdev,
 
        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);
@@ -1034,7 +1042,7 @@ static int __init moxa_init(void)
                        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]);
@@ -1046,6 +1054,10 @@ static int __init moxa_init(void)
                                continue;
                        }
 
+                       printk(KERN_INFO "MOXA isa board found at 0x%.8lu and "
+                                       "ready (%u ports, firmware loaded)\n",
+                                       baseaddr[i], brd->numPorts);
+
                        brd++;
                        isabrds++;
                }
@@ -1268,6 +1280,7 @@ static int moxa_chars_in_buffer(struct tty_struct *tty)
         */
        if (ch == NULL)
                return 0;
+       lock_kernel();
        chars = MoxaPortTxQueue(ch);
        if (chars) {
                /*
@@ -1277,6 +1290,7 @@ static int moxa_chars_in_buffer(struct tty_struct *tty)
                if (!(ch->statusflags & EMPTYWAIT))
                        moxa_setup_empty_event(tty);
        }
+       unlock_kernel();
        return chars;
 }
 
@@ -1635,18 +1649,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)
  *
@@ -1795,8 +1800,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,
@@ -1819,33 +1823,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;
@@ -1890,11 +1879,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)) {
@@ -1954,8 +1941,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 {