]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/char/moxa.c
Merge branch 'linus' into x86/amd-iommu
[linux-2.6-omap-h63xx.git] / drivers / char / moxa.c
index 876c79b1cee0ff1f772421d97c193877298b3058..e21346da3101c7c4c3304d5bcb935d0592f37723 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.
  */
@@ -193,8 +197,6 @@ static int moxa_write(struct tty_struct *, const unsigned char *, int);
 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 *);
@@ -391,8 +393,6 @@ static const struct tty_operations moxa_ops = {
        .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,
@@ -516,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;
 
@@ -590,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);
@@ -611,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;
@@ -723,7 +721,7 @@ static int moxa_load_code(struct moxa_board_conf *brd, const void *ptr,
 
 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;
@@ -736,7 +734,7 @@ static int moxa_load_fw(struct moxa_board_conf *brd, const struct firmware *fw)
                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));
 
@@ -848,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;
        }
 
@@ -936,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;
@@ -964,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);
@@ -1038,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]);
@@ -1050,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++;
                }
@@ -1272,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) {
                /*
@@ -1281,30 +1290,10 @@ static int moxa_chars_in_buffer(struct tty_struct *tty)
                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;
@@ -1660,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)
  *
@@ -1820,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,
@@ -1844,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;
@@ -1915,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)) {
@@ -1979,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 {