Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /*****************************************************************************/ |
| 2 | /* |
| 3 | * moxa.c -- MOXA Intellio family multiport serial driver. |
| 4 | * |
Jiri Slaby | b9705b6 | 2008-04-30 00:53:48 -0700 | [diff] [blame] | 5 | * Copyright (C) 1999-2000 Moxa Technologies (support@moxa.com). |
| 6 | * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * This code is loosely based on the Linux serial driver, written by |
| 9 | * Linus Torvalds, Theodore T'so and others. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * MOXA Intellio Series Driver |
| 19 | * for : LINUX |
| 20 | * date : 1999/1/7 |
| 21 | * version : 5.1 |
| 22 | */ |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/module.h> |
| 25 | #include <linux/types.h> |
| 26 | #include <linux/mm.h> |
| 27 | #include <linux/ioport.h> |
| 28 | #include <linux/errno.h> |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 29 | #include <linux/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/signal.h> |
| 31 | #include <linux/sched.h> |
| 32 | #include <linux/timer.h> |
| 33 | #include <linux/interrupt.h> |
| 34 | #include <linux/tty.h> |
| 35 | #include <linux/tty_flip.h> |
| 36 | #include <linux/major.h> |
| 37 | #include <linux/string.h> |
| 38 | #include <linux/fcntl.h> |
| 39 | #include <linux/ptrace.h> |
| 40 | #include <linux/serial.h> |
| 41 | #include <linux/tty_driver.h> |
| 42 | #include <linux/delay.h> |
| 43 | #include <linux/pci.h> |
| 44 | #include <linux/init.h> |
| 45 | #include <linux/bitops.h> |
| 46 | |
| 47 | #include <asm/system.h> |
| 48 | #include <asm/io.h> |
| 49 | #include <asm/uaccess.h> |
| 50 | |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 51 | #include "moxa.h" |
| 52 | |
Jiri Slaby | b9705b6 | 2008-04-30 00:53:48 -0700 | [diff] [blame] | 53 | #define MOXA_VERSION "6.0k" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 55 | #define MOXA_FW_HDRLEN 32 |
| 56 | |
Jiri Slaby | 11324ed | 2007-02-10 01:45:31 -0800 | [diff] [blame] | 57 | #define MOXAMAJOR 172 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Jiri Slaby | 11324ed | 2007-02-10 01:45:31 -0800 | [diff] [blame] | 59 | #define MAX_BOARDS 4 /* Don't change this value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #define MAX_PORTS_PER_BOARD 32 /* Don't change this value */ |
Jiri Slaby | 11324ed | 2007-02-10 01:45:31 -0800 | [diff] [blame] | 61 | #define MAX_PORTS (MAX_BOARDS * MAX_PORTS_PER_BOARD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Jiri Slaby | 08d01c79 | 2008-04-30 00:53:47 -0700 | [diff] [blame] | 63 | #define MOXA_IS_320(brd) ((brd)->boardType == MOXA_BOARD_C320_ISA || \ |
| 64 | (brd)->boardType == MOXA_BOARD_C320_PCI) |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | /* |
| 67 | * Define the Moxa PCI vendor and device IDs. |
| 68 | */ |
Jiri Slaby | 11324ed | 2007-02-10 01:45:31 -0800 | [diff] [blame] | 69 | #define MOXA_BUS_TYPE_ISA 0 |
| 70 | #define MOXA_BUS_TYPE_PCI 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | enum { |
| 73 | MOXA_BOARD_C218_PCI = 1, |
| 74 | MOXA_BOARD_C218_ISA, |
| 75 | MOXA_BOARD_C320_PCI, |
| 76 | MOXA_BOARD_C320_ISA, |
| 77 | MOXA_BOARD_CP204J, |
| 78 | }; |
| 79 | |
| 80 | static char *moxa_brdname[] = |
| 81 | { |
| 82 | "C218 Turbo PCI series", |
| 83 | "C218 Turbo ISA series", |
| 84 | "C320 Turbo PCI series", |
| 85 | "C320 Turbo ISA series", |
| 86 | "CP-204J series", |
| 87 | }; |
| 88 | |
| 89 | #ifdef CONFIG_PCI |
| 90 | static struct pci_device_id moxa_pcibrds[] = { |
Jiri Slaby | 5ebb407 | 2007-02-10 01:45:30 -0800 | [diff] [blame] | 91 | { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C218), |
| 92 | .driver_data = MOXA_BOARD_C218_PCI }, |
| 93 | { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C320), |
| 94 | .driver_data = MOXA_BOARD_C320_PCI }, |
| 95 | { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP204J), |
| 96 | .driver_data = MOXA_BOARD_CP204J }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { 0 } |
| 98 | }; |
| 99 | MODULE_DEVICE_TABLE(pci, moxa_pcibrds); |
| 100 | #endif /* CONFIG_PCI */ |
| 101 | |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 102 | struct moxa_port; |
| 103 | |
Jiri Slaby | 8f8ecba | 2007-02-10 01:45:33 -0800 | [diff] [blame] | 104 | static struct moxa_board_conf { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | int boardType; |
| 106 | int numPorts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | int busType; |
Jiri Slaby | 8f8ecba | 2007-02-10 01:45:33 -0800 | [diff] [blame] | 108 | |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 109 | unsigned int ready; |
Jiri Slaby | 8f8ecba | 2007-02-10 01:45:33 -0800 | [diff] [blame] | 110 | |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 111 | struct moxa_port *ports; |
| 112 | |
Jiri Slaby | 8f8ecba | 2007-02-10 01:45:33 -0800 | [diff] [blame] | 113 | void __iomem *basemem; |
| 114 | void __iomem *intNdx; |
| 115 | void __iomem *intPend; |
| 116 | void __iomem *intTable; |
| 117 | } moxa_boards[MAX_BOARDS]; |
| 118 | |
| 119 | struct mxser_mstatus { |
| 120 | tcflag_t cflag; |
| 121 | int cts; |
| 122 | int dsr; |
| 123 | int ri; |
| 124 | int dcd; |
Jiri Slaby | 9dff89c | 2007-02-10 01:45:30 -0800 | [diff] [blame] | 125 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Jiri Slaby | 8f8ecba | 2007-02-10 01:45:33 -0800 | [diff] [blame] | 127 | struct moxaq_str { |
| 128 | int inq; |
| 129 | int outq; |
| 130 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Jiri Slaby | 8f8ecba | 2007-02-10 01:45:33 -0800 | [diff] [blame] | 132 | struct moxa_port { |
Alan Cox | 9de6a51 | 2008-07-16 21:56:02 +0100 | [diff] [blame] | 133 | struct tty_port port; |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 134 | struct moxa_board_conf *board; |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 135 | void __iomem *tableAddr; |
| 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | int type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | int cflag; |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 139 | unsigned long statusflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Alan Cox | 8482bcd | 2009-11-30 13:18:13 +0000 | [diff] [blame] | 141 | u8 DCDState; /* Protected by the port lock */ |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 142 | u8 lineCtrl; |
| 143 | u8 lowChkFlag; |
Jiri Slaby | 8f8ecba | 2007-02-10 01:45:33 -0800 | [diff] [blame] | 144 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 146 | struct mon_str { |
| 147 | int tick; |
| 148 | int rxcnt[MAX_PORTS]; |
| 149 | int txcnt[MAX_PORTS]; |
| 150 | }; |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* statusflags */ |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 153 | #define TXSTOPPED 1 |
| 154 | #define LOWWAIT 2 |
| 155 | #define EMPTYWAIT 3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | #define SERIAL_DO_RESTART |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | #define WAKEUP_CHARS 256 |
| 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | static int ttymajor = MOXAMAJOR; |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 162 | static struct mon_str moxaLog; |
| 163 | static unsigned int moxaFuncTout = HZ / 2; |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 164 | static unsigned int moxaLowWaterChk; |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 165 | static DEFINE_MUTEX(moxa_openlock); |
Alan Cox | e8c6210 | 2009-11-30 13:18:24 +0000 | [diff] [blame] | 166 | static DEFINE_SPINLOCK(moxa_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | /* Variables for insmod */ |
| 168 | #ifdef MODULE |
Jiri Slaby | d353eca | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 169 | static unsigned long baseaddr[MAX_BOARDS]; |
| 170 | static unsigned int type[MAX_BOARDS]; |
| 171 | static unsigned int numports[MAX_BOARDS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | #endif |
| 173 | |
| 174 | MODULE_AUTHOR("William Chen"); |
| 175 | MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver"); |
| 176 | MODULE_LICENSE("GPL"); |
| 177 | #ifdef MODULE |
Jiri Slaby | d353eca | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 178 | module_param_array(type, uint, NULL, 0); |
| 179 | MODULE_PARM_DESC(type, "card type: C218=2, C320=4"); |
| 180 | module_param_array(baseaddr, ulong, NULL, 0); |
| 181 | MODULE_PARM_DESC(baseaddr, "base address"); |
| 182 | module_param_array(numports, uint, NULL, 0); |
| 183 | MODULE_PARM_DESC(numports, "numports (ignored for C218)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | #endif |
| 185 | module_param(ttymajor, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | /* |
| 188 | * static functions: |
| 189 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | static int moxa_open(struct tty_struct *, struct file *); |
| 191 | static void moxa_close(struct tty_struct *, struct file *); |
| 192 | static int moxa_write(struct tty_struct *, const unsigned char *, int); |
| 193 | static int moxa_write_room(struct tty_struct *); |
| 194 | static void moxa_flush_buffer(struct tty_struct *); |
| 195 | static int moxa_chars_in_buffer(struct tty_struct *); |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 196 | static void moxa_set_termios(struct tty_struct *, struct ktermios *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | static void moxa_stop(struct tty_struct *); |
| 198 | static void moxa_start(struct tty_struct *); |
| 199 | static void moxa_hangup(struct tty_struct *); |
| 200 | static int moxa_tiocmget(struct tty_struct *tty, struct file *file); |
| 201 | static int moxa_tiocmset(struct tty_struct *tty, struct file *file, |
| 202 | unsigned int set, unsigned int clear); |
| 203 | static void moxa_poll(unsigned long); |
Alan Cox | db1acaa | 2008-02-08 04:18:43 -0800 | [diff] [blame] | 204 | static void moxa_set_tty_param(struct tty_struct *, struct ktermios *); |
Alan Cox | f176178 | 2009-11-30 13:17:51 +0000 | [diff] [blame] | 205 | static void moxa_shutdown(struct tty_port *); |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 206 | static int moxa_carrier_raised(struct tty_port *); |
Alan Cox | f176178 | 2009-11-30 13:17:51 +0000 | [diff] [blame] | 207 | static void moxa_dtr_rts(struct tty_port *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | /* |
| 209 | * moxa board interface functions: |
| 210 | */ |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 211 | static void MoxaPortEnable(struct moxa_port *); |
| 212 | static void MoxaPortDisable(struct moxa_port *); |
| 213 | static int MoxaPortSetTermio(struct moxa_port *, struct ktermios *, speed_t); |
| 214 | static int MoxaPortGetLineOut(struct moxa_port *, int *, int *); |
| 215 | static void MoxaPortLineCtrl(struct moxa_port *, int, int); |
| 216 | static void MoxaPortFlowCtrl(struct moxa_port *, int, int, int, int, int); |
| 217 | static int MoxaPortLineStatus(struct moxa_port *); |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 218 | static void MoxaPortFlushData(struct moxa_port *, int); |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 219 | static int MoxaPortWriteData(struct tty_struct *, const unsigned char *, int); |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 220 | static int MoxaPortReadData(struct moxa_port *); |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 221 | static int MoxaPortTxQueue(struct moxa_port *); |
| 222 | static int MoxaPortRxQueue(struct moxa_port *); |
| 223 | static int MoxaPortTxFree(struct moxa_port *); |
| 224 | static void MoxaPortTxDisable(struct moxa_port *); |
| 225 | static void MoxaPortTxEnable(struct moxa_port *); |
Jiri Slaby | 8f8ecba | 2007-02-10 01:45:33 -0800 | [diff] [blame] | 226 | static int moxa_get_serial_info(struct moxa_port *, struct serial_struct __user *); |
| 227 | static int moxa_set_serial_info(struct moxa_port *, struct serial_struct __user *); |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 228 | static void MoxaSetFifo(struct moxa_port *port, int enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 230 | /* |
| 231 | * I/O functions |
| 232 | */ |
| 233 | |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 234 | static DEFINE_SPINLOCK(moxafunc_lock); |
| 235 | |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 236 | static void moxa_wait_finish(void __iomem *ofsAddr) |
| 237 | { |
| 238 | unsigned long end = jiffies + moxaFuncTout; |
| 239 | |
| 240 | while (readw(ofsAddr + FuncCode) != 0) |
| 241 | if (time_after(jiffies, end)) |
| 242 | return; |
| 243 | if (readw(ofsAddr + FuncCode) != 0 && printk_ratelimit()) |
| 244 | printk(KERN_WARNING "moxa function expired\n"); |
| 245 | } |
| 246 | |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 247 | static void moxafunc(void __iomem *ofsAddr, u16 cmd, u16 arg) |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 248 | { |
Alan Cox | f5c5a36 | 2009-11-30 13:17:57 +0000 | [diff] [blame] | 249 | unsigned long flags; |
| 250 | spin_lock_irqsave(&moxafunc_lock, flags); |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 251 | writew(arg, ofsAddr + FuncArg); |
| 252 | writew(cmd, ofsAddr + FuncCode); |
| 253 | moxa_wait_finish(ofsAddr); |
Alan Cox | f5c5a36 | 2009-11-30 13:17:57 +0000 | [diff] [blame] | 254 | spin_unlock_irqrestore(&moxafunc_lock, flags); |
| 255 | } |
| 256 | |
| 257 | static int moxafuncret(void __iomem *ofsAddr, u16 cmd, u16 arg) |
| 258 | { |
| 259 | unsigned long flags; |
| 260 | u16 ret; |
| 261 | spin_lock_irqsave(&moxafunc_lock, flags); |
| 262 | writew(arg, ofsAddr + FuncArg); |
| 263 | writew(cmd, ofsAddr + FuncCode); |
| 264 | moxa_wait_finish(ofsAddr); |
| 265 | ret = readw(ofsAddr + FuncArg); |
| 266 | spin_unlock_irqrestore(&moxafunc_lock, flags); |
| 267 | return ret; |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 270 | static void moxa_low_water_check(void __iomem *ofsAddr) |
| 271 | { |
| 272 | u16 rptr, wptr, mask, len; |
| 273 | |
| 274 | if (readb(ofsAddr + FlagStat) & Xoff_state) { |
| 275 | rptr = readw(ofsAddr + RXrptr); |
| 276 | wptr = readw(ofsAddr + RXwptr); |
| 277 | mask = readw(ofsAddr + RX_mask); |
| 278 | len = (wptr - rptr) & mask; |
| 279 | if (len <= Low_water) |
| 280 | moxafunc(ofsAddr, FC_SendXon, 0); |
| 281 | } |
| 282 | } |
| 283 | |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 284 | /* |
| 285 | * TTY operations |
| 286 | */ |
| 287 | |
| 288 | static int moxa_ioctl(struct tty_struct *tty, struct file *file, |
| 289 | unsigned int cmd, unsigned long arg) |
| 290 | { |
| 291 | struct moxa_port *ch = tty->driver_data; |
| 292 | void __user *argp = (void __user *)arg; |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 293 | int status, ret = 0; |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 294 | |
| 295 | if (tty->index == MAX_PORTS) { |
| 296 | if (cmd != MOXA_GETDATACOUNT && cmd != MOXA_GET_IOQUEUE && |
| 297 | cmd != MOXA_GETMSTATUS) |
| 298 | return -EINVAL; |
| 299 | } else if (!ch) |
| 300 | return -ENODEV; |
| 301 | |
| 302 | switch (cmd) { |
| 303 | case MOXA_GETDATACOUNT: |
| 304 | moxaLog.tick = jiffies; |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 305 | if (copy_to_user(argp, &moxaLog, sizeof(moxaLog))) |
| 306 | ret = -EFAULT; |
| 307 | break; |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 308 | case MOXA_FLUSH_QUEUE: |
| 309 | MoxaPortFlushData(ch, arg); |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 310 | break; |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 311 | case MOXA_GET_IOQUEUE: { |
| 312 | struct moxaq_str __user *argm = argp; |
| 313 | struct moxaq_str tmp; |
| 314 | struct moxa_port *p; |
| 315 | unsigned int i, j; |
| 316 | |
| 317 | for (i = 0; i < MAX_BOARDS; i++) { |
| 318 | p = moxa_boards[i].ports; |
| 319 | for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) { |
| 320 | memset(&tmp, 0, sizeof(tmp)); |
Alan Cox | e8c6210 | 2009-11-30 13:18:24 +0000 | [diff] [blame] | 321 | spin_lock_bh(&moxa_lock); |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 322 | if (moxa_boards[i].ready) { |
| 323 | tmp.inq = MoxaPortRxQueue(p); |
| 324 | tmp.outq = MoxaPortTxQueue(p); |
| 325 | } |
Alan Cox | e8c6210 | 2009-11-30 13:18:24 +0000 | [diff] [blame] | 326 | spin_unlock_bh(&moxa_lock); |
| 327 | if (copy_to_user(argm, &tmp, sizeof(tmp))) |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 328 | return -EFAULT; |
| 329 | } |
| 330 | } |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 331 | break; |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 332 | } case MOXA_GET_OQUEUE: |
| 333 | status = MoxaPortTxQueue(ch); |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 334 | ret = put_user(status, (unsigned long __user *)argp); |
| 335 | break; |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 336 | case MOXA_GET_IQUEUE: |
| 337 | status = MoxaPortRxQueue(ch); |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 338 | ret = put_user(status, (unsigned long __user *)argp); |
| 339 | break; |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 340 | case MOXA_GETMSTATUS: { |
| 341 | struct mxser_mstatus __user *argm = argp; |
| 342 | struct mxser_mstatus tmp; |
| 343 | struct moxa_port *p; |
| 344 | unsigned int i, j; |
| 345 | |
| 346 | for (i = 0; i < MAX_BOARDS; i++) { |
| 347 | p = moxa_boards[i].ports; |
| 348 | for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) { |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 349 | struct tty_struct *ttyp; |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 350 | memset(&tmp, 0, sizeof(tmp)); |
Alan Cox | e8c6210 | 2009-11-30 13:18:24 +0000 | [diff] [blame] | 351 | spin_lock_bh(&moxa_lock); |
| 352 | if (!moxa_boards[i].ready) { |
| 353 | spin_unlock_bh(&moxa_lock); |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 354 | goto copy; |
Alan Cox | e8c6210 | 2009-11-30 13:18:24 +0000 | [diff] [blame] | 355 | } |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 356 | |
| 357 | status = MoxaPortLineStatus(p); |
Alan Cox | e8c6210 | 2009-11-30 13:18:24 +0000 | [diff] [blame] | 358 | spin_unlock_bh(&moxa_lock); |
| 359 | |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 360 | if (status & 1) |
| 361 | tmp.cts = 1; |
| 362 | if (status & 2) |
| 363 | tmp.dsr = 1; |
| 364 | if (status & 4) |
| 365 | tmp.dcd = 1; |
| 366 | |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 367 | ttyp = tty_port_tty_get(&p->port); |
| 368 | if (!ttyp || !ttyp->termios) |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 369 | tmp.cflag = p->cflag; |
| 370 | else |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 371 | tmp.cflag = ttyp->termios->c_cflag; |
| 372 | tty_kref_put(tty); |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 373 | copy: |
Alan Cox | e8c6210 | 2009-11-30 13:18:24 +0000 | [diff] [blame] | 374 | if (copy_to_user(argm, &tmp, sizeof(tmp))) |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 375 | return -EFAULT; |
| 376 | } |
| 377 | } |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 378 | break; |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 379 | } |
| 380 | case TIOCGSERIAL: |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 381 | mutex_lock(&ch->port.mutex); |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 382 | ret = moxa_get_serial_info(ch, argp); |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 383 | mutex_unlock(&ch->port.mutex); |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 384 | break; |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 385 | case TIOCSSERIAL: |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 386 | mutex_lock(&ch->port.mutex); |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 387 | ret = moxa_set_serial_info(ch, argp); |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 388 | mutex_unlock(&ch->port.mutex); |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 389 | break; |
| 390 | default: |
| 391 | ret = -ENOIOCTLCMD; |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 392 | } |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 393 | return ret; |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Alan Cox | 9e98966 | 2008-07-22 11:18:03 +0100 | [diff] [blame] | 396 | static int moxa_break_ctl(struct tty_struct *tty, int state) |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 397 | { |
| 398 | struct moxa_port *port = tty->driver_data; |
| 399 | |
| 400 | moxafunc(port->tableAddr, state ? FC_SendBreak : FC_StopBreak, |
| 401 | Magic_code); |
Alan Cox | 9e98966 | 2008-07-22 11:18:03 +0100 | [diff] [blame] | 402 | return 0; |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 405 | static const struct tty_operations moxa_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | .open = moxa_open, |
| 407 | .close = moxa_close, |
| 408 | .write = moxa_write, |
| 409 | .write_room = moxa_write_room, |
| 410 | .flush_buffer = moxa_flush_buffer, |
| 411 | .chars_in_buffer = moxa_chars_in_buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | .ioctl = moxa_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | .set_termios = moxa_set_termios, |
| 414 | .stop = moxa_stop, |
| 415 | .start = moxa_start, |
| 416 | .hangup = moxa_hangup, |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 417 | .break_ctl = moxa_break_ctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | .tiocmget = moxa_tiocmget, |
| 419 | .tiocmset = moxa_tiocmset, |
| 420 | }; |
| 421 | |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 422 | static const struct tty_port_operations moxa_port_ops = { |
| 423 | .carrier_raised = moxa_carrier_raised, |
Alan Cox | f176178 | 2009-11-30 13:17:51 +0000 | [diff] [blame] | 424 | .dtr_rts = moxa_dtr_rts, |
| 425 | .shutdown = moxa_shutdown, |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 426 | }; |
| 427 | |
Jiri Slaby | aa7e522 | 2007-02-10 01:45:27 -0800 | [diff] [blame] | 428 | static struct tty_driver *moxaDriver; |
Jiri Slaby | aa7e522 | 2007-02-10 01:45:27 -0800 | [diff] [blame] | 429 | static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0); |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 430 | |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 431 | /* |
| 432 | * HW init |
| 433 | */ |
| 434 | |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 435 | static int moxa_check_fw_model(struct moxa_board_conf *brd, u8 model) |
| 436 | { |
| 437 | switch (brd->boardType) { |
| 438 | case MOXA_BOARD_C218_ISA: |
| 439 | case MOXA_BOARD_C218_PCI: |
| 440 | if (model != 1) |
| 441 | goto err; |
| 442 | break; |
| 443 | case MOXA_BOARD_CP204J: |
| 444 | if (model != 3) |
| 445 | goto err; |
| 446 | break; |
| 447 | default: |
| 448 | if (model != 2) |
| 449 | goto err; |
| 450 | break; |
| 451 | } |
| 452 | return 0; |
| 453 | err: |
| 454 | return -EINVAL; |
| 455 | } |
| 456 | |
| 457 | static int moxa_check_fw(const void *ptr) |
| 458 | { |
| 459 | const __le16 *lptr = ptr; |
| 460 | |
| 461 | if (*lptr != cpu_to_le16(0x7980)) |
| 462 | return -EINVAL; |
| 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | static int moxa_load_bios(struct moxa_board_conf *brd, const u8 *buf, |
| 468 | size_t len) |
| 469 | { |
| 470 | void __iomem *baseAddr = brd->basemem; |
| 471 | u16 tmp; |
| 472 | |
| 473 | writeb(HW_reset, baseAddr + Control_reg); /* reset */ |
| 474 | msleep(10); |
| 475 | memset_io(baseAddr, 0, 4096); |
| 476 | memcpy_toio(baseAddr, buf, len); /* download BIOS */ |
| 477 | writeb(0, baseAddr + Control_reg); /* restart */ |
| 478 | |
| 479 | msleep(2000); |
| 480 | |
| 481 | switch (brd->boardType) { |
| 482 | case MOXA_BOARD_C218_ISA: |
| 483 | case MOXA_BOARD_C218_PCI: |
| 484 | tmp = readw(baseAddr + C218_key); |
| 485 | if (tmp != C218_KeyCode) |
| 486 | goto err; |
| 487 | break; |
| 488 | case MOXA_BOARD_CP204J: |
| 489 | tmp = readw(baseAddr + C218_key); |
| 490 | if (tmp != CP204J_KeyCode) |
| 491 | goto err; |
| 492 | break; |
| 493 | default: |
| 494 | tmp = readw(baseAddr + C320_key); |
| 495 | if (tmp != C320_KeyCode) |
| 496 | goto err; |
| 497 | tmp = readw(baseAddr + C320_status); |
| 498 | if (tmp != STS_init) { |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 499 | printk(KERN_ERR "MOXA: bios upload failed -- CPU/Basic " |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 500 | "module not found\n"); |
| 501 | return -EIO; |
| 502 | } |
| 503 | break; |
| 504 | } |
| 505 | |
| 506 | return 0; |
| 507 | err: |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 508 | printk(KERN_ERR "MOXA: bios upload failed -- board not found\n"); |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 509 | return -EIO; |
| 510 | } |
| 511 | |
| 512 | static int moxa_load_320b(struct moxa_board_conf *brd, const u8 *ptr, |
| 513 | size_t len) |
| 514 | { |
| 515 | void __iomem *baseAddr = brd->basemem; |
| 516 | |
| 517 | if (len < 7168) { |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 518 | printk(KERN_ERR "MOXA: invalid 320 bios -- too short\n"); |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 519 | return -EINVAL; |
| 520 | } |
| 521 | |
| 522 | writew(len - 7168 - 2, baseAddr + C320bapi_len); |
| 523 | writeb(1, baseAddr + Control_reg); /* Select Page 1 */ |
| 524 | memcpy_toio(baseAddr + DynPage_addr, ptr, 7168); |
| 525 | writeb(2, baseAddr + Control_reg); /* Select Page 2 */ |
| 526 | memcpy_toio(baseAddr + DynPage_addr, ptr + 7168, len - 7168); |
| 527 | |
| 528 | return 0; |
| 529 | } |
| 530 | |
Jiri Slaby | 5292bcd | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 531 | static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr, |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 532 | size_t len) |
| 533 | { |
| 534 | void __iomem *baseAddr = brd->basemem; |
Harvey Harrison | b46f69c | 2008-10-15 22:04:19 -0700 | [diff] [blame] | 535 | const __le16 *uptr = ptr; |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 536 | size_t wlen, len2, j; |
Jiri Slaby | 5292bcd | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 537 | unsigned long key, loadbuf, loadlen, checksum, checksum_ok; |
Jiri Slaby | 08d01c79 | 2008-04-30 00:53:47 -0700 | [diff] [blame] | 538 | unsigned int i, retry; |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 539 | u16 usum, keycode; |
| 540 | |
Jiri Slaby | 5292bcd | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 541 | keycode = (brd->boardType == MOXA_BOARD_CP204J) ? CP204J_KeyCode : |
| 542 | C218_KeyCode; |
| 543 | |
| 544 | switch (brd->boardType) { |
| 545 | case MOXA_BOARD_CP204J: |
| 546 | case MOXA_BOARD_C218_ISA: |
| 547 | case MOXA_BOARD_C218_PCI: |
| 548 | key = C218_key; |
| 549 | loadbuf = C218_LoadBuf; |
| 550 | loadlen = C218DLoad_len; |
| 551 | checksum = C218check_sum; |
| 552 | checksum_ok = C218chksum_ok; |
| 553 | break; |
| 554 | default: |
| 555 | key = C320_key; |
| 556 | keycode = C320_KeyCode; |
| 557 | loadbuf = C320_LoadBuf; |
| 558 | loadlen = C320DLoad_len; |
| 559 | checksum = C320check_sum; |
| 560 | checksum_ok = C320chksum_ok; |
| 561 | break; |
| 562 | } |
| 563 | |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 564 | usum = 0; |
| 565 | wlen = len >> 1; |
| 566 | for (i = 0; i < wlen; i++) |
| 567 | usum += le16_to_cpu(uptr[i]); |
| 568 | retry = 0; |
| 569 | do { |
| 570 | wlen = len >> 1; |
| 571 | j = 0; |
| 572 | while (wlen) { |
| 573 | len2 = (wlen > 2048) ? 2048 : wlen; |
| 574 | wlen -= len2; |
Jiri Slaby | 5292bcd | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 575 | memcpy_toio(baseAddr + loadbuf, ptr + j, len2 << 1); |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 576 | j += len2 << 1; |
| 577 | |
Jiri Slaby | 5292bcd | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 578 | writew(len2, baseAddr + loadlen); |
| 579 | writew(0, baseAddr + key); |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 580 | for (i = 0; i < 100; i++) { |
Jiri Slaby | 5292bcd | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 581 | if (readw(baseAddr + key) == keycode) |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 582 | break; |
| 583 | msleep(10); |
| 584 | } |
Jiri Slaby | 5292bcd | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 585 | if (readw(baseAddr + key) != keycode) |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 586 | return -EIO; |
| 587 | } |
Jiri Slaby | 5292bcd | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 588 | writew(0, baseAddr + loadlen); |
| 589 | writew(usum, baseAddr + checksum); |
| 590 | writew(0, baseAddr + key); |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 591 | for (i = 0; i < 100; i++) { |
Jiri Slaby | 5292bcd | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 592 | if (readw(baseAddr + key) == keycode) |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 593 | break; |
| 594 | msleep(10); |
| 595 | } |
| 596 | retry++; |
Jiri Slaby | 5292bcd | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 597 | } while ((readb(baseAddr + checksum_ok) != 1) && (retry < 3)); |
| 598 | if (readb(baseAddr + checksum_ok) != 1) |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 599 | return -EIO; |
| 600 | |
Jiri Slaby | 5292bcd | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 601 | writew(0, baseAddr + key); |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 602 | for (i = 0; i < 600; i++) { |
| 603 | if (readw(baseAddr + Magic_no) == Magic_code) |
| 604 | break; |
| 605 | msleep(10); |
| 606 | } |
| 607 | if (readw(baseAddr + Magic_no) != Magic_code) |
| 608 | return -EIO; |
| 609 | |
Jiri Slaby | 08d01c79 | 2008-04-30 00:53:47 -0700 | [diff] [blame] | 610 | if (MOXA_IS_320(brd)) { |
Jiri Slaby | 5292bcd | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 611 | if (brd->busType == MOXA_BUS_TYPE_PCI) { /* ASIC board */ |
| 612 | writew(0x3800, baseAddr + TMS320_PORT1); |
| 613 | writew(0x3900, baseAddr + TMS320_PORT2); |
| 614 | writew(28499, baseAddr + TMS320_CLOCK); |
| 615 | } else { |
| 616 | writew(0x3200, baseAddr + TMS320_PORT1); |
| 617 | writew(0x3400, baseAddr + TMS320_PORT2); |
| 618 | writew(19999, baseAddr + TMS320_CLOCK); |
| 619 | } |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 620 | } |
| 621 | writew(1, baseAddr + Disable_IRQ); |
| 622 | writew(0, baseAddr + Magic_no); |
| 623 | for (i = 0; i < 500; i++) { |
| 624 | if (readw(baseAddr + Magic_no) == Magic_code) |
| 625 | break; |
| 626 | msleep(10); |
| 627 | } |
| 628 | if (readw(baseAddr + Magic_no) != Magic_code) |
| 629 | return -EIO; |
| 630 | |
Jiri Slaby | 08d01c79 | 2008-04-30 00:53:47 -0700 | [diff] [blame] | 631 | if (MOXA_IS_320(brd)) { |
Jiri Slaby | 5292bcd | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 632 | j = readw(baseAddr + Module_cnt); |
| 633 | if (j <= 0) |
| 634 | return -EIO; |
| 635 | brd->numPorts = j * 8; |
| 636 | writew(j, baseAddr + Module_no); |
| 637 | writew(0, baseAddr + Magic_no); |
| 638 | for (i = 0; i < 600; i++) { |
| 639 | if (readw(baseAddr + Magic_no) == Magic_code) |
| 640 | break; |
| 641 | msleep(10); |
| 642 | } |
| 643 | if (readw(baseAddr + Magic_no) != Magic_code) |
| 644 | return -EIO; |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 645 | } |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 646 | brd->intNdx = baseAddr + IRQindex; |
| 647 | brd->intPend = baseAddr + IRQpending; |
| 648 | brd->intTable = baseAddr + IRQtable; |
| 649 | |
| 650 | return 0; |
| 651 | } |
| 652 | |
| 653 | static int moxa_load_code(struct moxa_board_conf *brd, const void *ptr, |
| 654 | size_t len) |
| 655 | { |
| 656 | void __iomem *ofsAddr, *baseAddr = brd->basemem; |
| 657 | struct moxa_port *port; |
| 658 | int retval, i; |
| 659 | |
| 660 | if (len % 2) { |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 661 | printk(KERN_ERR "MOXA: bios length is not even\n"); |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 662 | return -EINVAL; |
| 663 | } |
| 664 | |
Jiri Slaby | 5292bcd | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 665 | retval = moxa_real_load_code(brd, ptr, len); /* may change numPorts */ |
| 666 | if (retval) |
| 667 | return retval; |
| 668 | |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 669 | switch (brd->boardType) { |
| 670 | case MOXA_BOARD_C218_ISA: |
| 671 | case MOXA_BOARD_C218_PCI: |
| 672 | case MOXA_BOARD_CP204J: |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 673 | port = brd->ports; |
| 674 | for (i = 0; i < brd->numPorts; i++, port++) { |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 675 | port->board = brd; |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 676 | port->DCDState = 0; |
| 677 | port->tableAddr = baseAddr + Extern_table + |
| 678 | Extern_size * i; |
| 679 | ofsAddr = port->tableAddr; |
| 680 | writew(C218rx_mask, ofsAddr + RX_mask); |
| 681 | writew(C218tx_mask, ofsAddr + TX_mask); |
| 682 | writew(C218rx_spage + i * C218buf_pageno, ofsAddr + Page_rxb); |
| 683 | writew(readw(ofsAddr + Page_rxb) + C218rx_pageno, ofsAddr + EndPage_rxb); |
| 684 | |
| 685 | writew(C218tx_spage + i * C218buf_pageno, ofsAddr + Page_txb); |
| 686 | writew(readw(ofsAddr + Page_txb) + C218tx_pageno, ofsAddr + EndPage_txb); |
| 687 | |
| 688 | } |
| 689 | break; |
| 690 | default: |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 691 | port = brd->ports; |
| 692 | for (i = 0; i < brd->numPorts; i++, port++) { |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 693 | port->board = brd; |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 694 | port->DCDState = 0; |
| 695 | port->tableAddr = baseAddr + Extern_table + |
| 696 | Extern_size * i; |
| 697 | ofsAddr = port->tableAddr; |
| 698 | switch (brd->numPorts) { |
| 699 | case 8: |
| 700 | writew(C320p8rx_mask, ofsAddr + RX_mask); |
| 701 | writew(C320p8tx_mask, ofsAddr + TX_mask); |
| 702 | writew(C320p8rx_spage + i * C320p8buf_pgno, ofsAddr + Page_rxb); |
| 703 | writew(readw(ofsAddr + Page_rxb) + C320p8rx_pgno, ofsAddr + EndPage_rxb); |
| 704 | writew(C320p8tx_spage + i * C320p8buf_pgno, ofsAddr + Page_txb); |
| 705 | writew(readw(ofsAddr + Page_txb) + C320p8tx_pgno, ofsAddr + EndPage_txb); |
| 706 | |
| 707 | break; |
| 708 | case 16: |
| 709 | writew(C320p16rx_mask, ofsAddr + RX_mask); |
| 710 | writew(C320p16tx_mask, ofsAddr + TX_mask); |
| 711 | writew(C320p16rx_spage + i * C320p16buf_pgno, ofsAddr + Page_rxb); |
| 712 | writew(readw(ofsAddr + Page_rxb) + C320p16rx_pgno, ofsAddr + EndPage_rxb); |
| 713 | writew(C320p16tx_spage + i * C320p16buf_pgno, ofsAddr + Page_txb); |
| 714 | writew(readw(ofsAddr + Page_txb) + C320p16tx_pgno, ofsAddr + EndPage_txb); |
| 715 | break; |
| 716 | |
| 717 | case 24: |
| 718 | writew(C320p24rx_mask, ofsAddr + RX_mask); |
| 719 | writew(C320p24tx_mask, ofsAddr + TX_mask); |
| 720 | writew(C320p24rx_spage + i * C320p24buf_pgno, ofsAddr + Page_rxb); |
| 721 | writew(readw(ofsAddr + Page_rxb) + C320p24rx_pgno, ofsAddr + EndPage_rxb); |
| 722 | writew(C320p24tx_spage + i * C320p24buf_pgno, ofsAddr + Page_txb); |
| 723 | writew(readw(ofsAddr + Page_txb), ofsAddr + EndPage_txb); |
| 724 | break; |
| 725 | case 32: |
| 726 | writew(C320p32rx_mask, ofsAddr + RX_mask); |
| 727 | writew(C320p32tx_mask, ofsAddr + TX_mask); |
| 728 | writew(C320p32tx_ofs, ofsAddr + Ofs_txb); |
| 729 | writew(C320p32rx_spage + i * C320p32buf_pgno, ofsAddr + Page_rxb); |
| 730 | writew(readb(ofsAddr + Page_rxb), ofsAddr + EndPage_rxb); |
| 731 | writew(C320p32tx_spage + i * C320p32buf_pgno, ofsAddr + Page_txb); |
| 732 | writew(readw(ofsAddr + Page_txb), ofsAddr + EndPage_txb); |
| 733 | break; |
| 734 | } |
| 735 | } |
| 736 | break; |
| 737 | } |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | static int moxa_load_fw(struct moxa_board_conf *brd, const struct firmware *fw) |
| 742 | { |
David Howells | 2bca76e | 2008-07-08 17:37:15 +0100 | [diff] [blame] | 743 | const void *ptr = fw->data; |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 744 | char rsn[64]; |
| 745 | u16 lens[5]; |
| 746 | size_t len; |
| 747 | unsigned int a, lenp, lencnt; |
| 748 | int ret = -EINVAL; |
| 749 | struct { |
| 750 | __le32 magic; /* 0x34303430 */ |
| 751 | u8 reserved1[2]; |
| 752 | u8 type; /* UNIX = 3 */ |
| 753 | u8 model; /* C218T=1, C320T=2, CP204=3 */ |
| 754 | u8 reserved2[8]; |
| 755 | __le16 len[5]; |
David Howells | 2bca76e | 2008-07-08 17:37:15 +0100 | [diff] [blame] | 756 | } const *hdr = ptr; |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 757 | |
| 758 | BUILD_BUG_ON(ARRAY_SIZE(hdr->len) != ARRAY_SIZE(lens)); |
| 759 | |
| 760 | if (fw->size < MOXA_FW_HDRLEN) { |
| 761 | strcpy(rsn, "too short (even header won't fit)"); |
| 762 | goto err; |
| 763 | } |
| 764 | if (hdr->magic != cpu_to_le32(0x30343034)) { |
| 765 | sprintf(rsn, "bad magic: %.8x", le32_to_cpu(hdr->magic)); |
| 766 | goto err; |
| 767 | } |
| 768 | if (hdr->type != 3) { |
| 769 | sprintf(rsn, "not for linux, type is %u", hdr->type); |
| 770 | goto err; |
| 771 | } |
| 772 | if (moxa_check_fw_model(brd, hdr->model)) { |
| 773 | sprintf(rsn, "not for this card, model is %u", hdr->model); |
| 774 | goto err; |
| 775 | } |
| 776 | |
| 777 | len = MOXA_FW_HDRLEN; |
| 778 | lencnt = hdr->model == 2 ? 5 : 3; |
| 779 | for (a = 0; a < ARRAY_SIZE(lens); a++) { |
| 780 | lens[a] = le16_to_cpu(hdr->len[a]); |
| 781 | if (lens[a] && len + lens[a] <= fw->size && |
| 782 | moxa_check_fw(&fw->data[len])) |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 783 | printk(KERN_WARNING "MOXA firmware: unexpected input " |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 784 | "at offset %u, but going on\n", (u32)len); |
| 785 | if (!lens[a] && a < lencnt) { |
| 786 | sprintf(rsn, "too few entries in fw file"); |
| 787 | goto err; |
| 788 | } |
| 789 | len += lens[a]; |
| 790 | } |
| 791 | |
| 792 | if (len != fw->size) { |
| 793 | sprintf(rsn, "bad length: %u (should be %u)", (u32)fw->size, |
| 794 | (u32)len); |
| 795 | goto err; |
| 796 | } |
| 797 | |
| 798 | ptr += MOXA_FW_HDRLEN; |
| 799 | lenp = 0; /* bios */ |
| 800 | |
| 801 | strcpy(rsn, "read above"); |
| 802 | |
| 803 | ret = moxa_load_bios(brd, ptr, lens[lenp]); |
| 804 | if (ret) |
| 805 | goto err; |
| 806 | |
| 807 | /* we skip the tty section (lens[1]), since we don't need it */ |
| 808 | ptr += lens[lenp] + lens[lenp + 1]; |
| 809 | lenp += 2; /* comm */ |
| 810 | |
| 811 | if (hdr->model == 2) { |
| 812 | ret = moxa_load_320b(brd, ptr, lens[lenp]); |
| 813 | if (ret) |
| 814 | goto err; |
| 815 | /* skip another tty */ |
| 816 | ptr += lens[lenp] + lens[lenp + 1]; |
| 817 | lenp += 2; |
| 818 | } |
| 819 | |
| 820 | ret = moxa_load_code(brd, ptr, lens[lenp]); |
| 821 | if (ret) |
| 822 | goto err; |
| 823 | |
| 824 | return 0; |
| 825 | err: |
| 826 | printk(KERN_ERR "firmware failed to load, reason: %s\n", rsn); |
| 827 | return ret; |
| 828 | } |
| 829 | |
| 830 | static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev) |
| 831 | { |
| 832 | const struct firmware *fw; |
| 833 | const char *file; |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 834 | struct moxa_port *p; |
| 835 | unsigned int i; |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 836 | int ret; |
| 837 | |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 838 | brd->ports = kcalloc(MAX_PORTS_PER_BOARD, sizeof(*brd->ports), |
| 839 | GFP_KERNEL); |
| 840 | if (brd->ports == NULL) { |
| 841 | printk(KERN_ERR "cannot allocate memory for ports\n"); |
| 842 | ret = -ENOMEM; |
| 843 | goto err; |
| 844 | } |
| 845 | |
| 846 | for (i = 0, p = brd->ports; i < MAX_PORTS_PER_BOARD; i++, p++) { |
Alan Cox | 9de6a51 | 2008-07-16 21:56:02 +0100 | [diff] [blame] | 847 | tty_port_init(&p->port); |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 848 | p->port.ops = &moxa_port_ops; |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 849 | p->type = PORT_16550A; |
| 850 | p->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 851 | } |
| 852 | |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 853 | switch (brd->boardType) { |
| 854 | case MOXA_BOARD_C218_ISA: |
| 855 | case MOXA_BOARD_C218_PCI: |
| 856 | file = "c218tunx.cod"; |
| 857 | break; |
| 858 | case MOXA_BOARD_CP204J: |
| 859 | file = "cp204unx.cod"; |
| 860 | break; |
| 861 | default: |
| 862 | file = "c320tunx.cod"; |
| 863 | break; |
| 864 | } |
| 865 | |
| 866 | ret = request_firmware(&fw, file, dev); |
| 867 | if (ret) { |
Jiri Slaby | ec09cd5 | 2008-04-30 00:53:49 -0700 | [diff] [blame] | 868 | printk(KERN_ERR "MOXA: request_firmware failed. Make sure " |
| 869 | "you've placed '%s' file into your firmware " |
| 870 | "loader directory (e.g. /lib/firmware)\n", |
| 871 | file); |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 872 | goto err_free; |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | ret = moxa_load_fw(brd, fw); |
| 876 | |
| 877 | release_firmware(fw); |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 878 | |
| 879 | if (ret) |
| 880 | goto err_free; |
| 881 | |
Jiri Slaby | 2a54134 | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 882 | spin_lock_bh(&moxa_lock); |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 883 | brd->ready = 1; |
Jiri Slaby | 0bcc4ca | 2008-04-30 00:53:42 -0700 | [diff] [blame] | 884 | if (!timer_pending(&moxaTimer)) |
| 885 | mod_timer(&moxaTimer, jiffies + HZ / 50); |
Jiri Slaby | 2a54134 | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 886 | spin_unlock_bh(&moxa_lock); |
Jiri Slaby | 0bcc4ca | 2008-04-30 00:53:42 -0700 | [diff] [blame] | 887 | |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 888 | return 0; |
| 889 | err_free: |
| 890 | kfree(brd->ports); |
| 891 | err: |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 892 | return ret; |
| 893 | } |
| 894 | |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 895 | static void moxa_board_deinit(struct moxa_board_conf *brd) |
| 896 | { |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 897 | unsigned int a, opened; |
| 898 | |
| 899 | mutex_lock(&moxa_openlock); |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 900 | spin_lock_bh(&moxa_lock); |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 901 | brd->ready = 0; |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 902 | spin_unlock_bh(&moxa_lock); |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 903 | |
| 904 | /* pci hot-un-plug support */ |
| 905 | for (a = 0; a < brd->numPorts; a++) |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 906 | if (brd->ports[a].port.flags & ASYNC_INITIALIZED) { |
| 907 | struct tty_struct *tty = tty_port_tty_get( |
| 908 | &brd->ports[a].port); |
| 909 | if (tty) { |
| 910 | tty_hangup(tty); |
| 911 | tty_kref_put(tty); |
| 912 | } |
| 913 | } |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 914 | while (1) { |
| 915 | opened = 0; |
| 916 | for (a = 0; a < brd->numPorts; a++) |
Alan Cox | 9de6a51 | 2008-07-16 21:56:02 +0100 | [diff] [blame] | 917 | if (brd->ports[a].port.flags & ASYNC_INITIALIZED) |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 918 | opened++; |
| 919 | mutex_unlock(&moxa_openlock); |
| 920 | if (!opened) |
| 921 | break; |
| 922 | msleep(50); |
| 923 | mutex_lock(&moxa_openlock); |
| 924 | } |
| 925 | |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 926 | iounmap(brd->basemem); |
| 927 | brd->basemem = NULL; |
| 928 | kfree(brd->ports); |
| 929 | } |
| 930 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | #ifdef CONFIG_PCI |
Jiri Slaby | 9cde5bf | 2007-02-10 01:45:35 -0800 | [diff] [blame] | 932 | static int __devinit moxa_pci_probe(struct pci_dev *pdev, |
| 933 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | { |
Jiri Slaby | 9cde5bf | 2007-02-10 01:45:35 -0800 | [diff] [blame] | 935 | struct moxa_board_conf *board; |
| 936 | unsigned int i; |
| 937 | int board_type = ent->driver_data; |
| 938 | int retval; |
| 939 | |
| 940 | retval = pci_enable_device(pdev); |
Jiri Slaby | 7aeb95d | 2007-10-18 03:06:24 -0700 | [diff] [blame] | 941 | if (retval) { |
| 942 | dev_err(&pdev->dev, "can't enable pci device\n"); |
Jiri Slaby | 9cde5bf | 2007-02-10 01:45:35 -0800 | [diff] [blame] | 943 | goto err; |
Jiri Slaby | 7aeb95d | 2007-10-18 03:06:24 -0700 | [diff] [blame] | 944 | } |
Jiri Slaby | 9cde5bf | 2007-02-10 01:45:35 -0800 | [diff] [blame] | 945 | |
| 946 | for (i = 0; i < MAX_BOARDS; i++) |
| 947 | if (moxa_boards[i].basemem == NULL) |
| 948 | break; |
| 949 | |
| 950 | retval = -ENODEV; |
| 951 | if (i >= MAX_BOARDS) { |
Jiri Slaby | 7aeb95d | 2007-10-18 03:06:24 -0700 | [diff] [blame] | 952 | dev_warn(&pdev->dev, "more than %u MOXA Intellio family boards " |
Jiri Slaby | 9cde5bf | 2007-02-10 01:45:35 -0800 | [diff] [blame] | 953 | "found. Board is ignored.\n", MAX_BOARDS); |
| 954 | goto err; |
| 955 | } |
| 956 | |
| 957 | board = &moxa_boards[i]; |
Jiri Slaby | e46a5e3 | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 958 | |
| 959 | retval = pci_request_region(pdev, 2, "moxa-base"); |
| 960 | if (retval) { |
| 961 | dev_err(&pdev->dev, "can't request pci region 2\n"); |
| 962 | goto err; |
| 963 | } |
| 964 | |
Alan Cox | 24cb233 | 2008-04-30 00:54:19 -0700 | [diff] [blame] | 965 | board->basemem = ioremap_nocache(pci_resource_start(pdev, 2), 0x4000); |
Jiri Slaby | 7aeb95d | 2007-10-18 03:06:24 -0700 | [diff] [blame] | 966 | if (board->basemem == NULL) { |
| 967 | dev_err(&pdev->dev, "can't remap io space 2\n"); |
Jiri Slaby | e46a5e3 | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 968 | goto err_reg; |
Jiri Slaby | 7aeb95d | 2007-10-18 03:06:24 -0700 | [diff] [blame] | 969 | } |
Jiri Slaby | 9cde5bf | 2007-02-10 01:45:35 -0800 | [diff] [blame] | 970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | board->boardType = board_type; |
| 972 | switch (board_type) { |
| 973 | case MOXA_BOARD_C218_ISA: |
| 974 | case MOXA_BOARD_C218_PCI: |
| 975 | board->numPorts = 8; |
| 976 | break; |
| 977 | |
| 978 | case MOXA_BOARD_CP204J: |
| 979 | board->numPorts = 4; |
| 980 | break; |
| 981 | default: |
| 982 | board->numPorts = 0; |
| 983 | break; |
| 984 | } |
| 985 | board->busType = MOXA_BUS_TYPE_PCI; |
Jiri Slaby | a784bf7 | 2007-02-10 01:45:36 -0800 | [diff] [blame] | 986 | |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 987 | retval = moxa_init_board(board, &pdev->dev); |
| 988 | if (retval) |
| 989 | goto err_base; |
| 990 | |
Jiri Slaby | 9cde5bf | 2007-02-10 01:45:35 -0800 | [diff] [blame] | 991 | pci_set_drvdata(pdev, board); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | |
Jiri Slaby | bb9f910 | 2008-04-30 00:53:48 -0700 | [diff] [blame] | 993 | dev_info(&pdev->dev, "board '%s' ready (%u ports, firmware loaded)\n", |
| 994 | moxa_brdname[board_type - 1], board->numPorts); |
| 995 | |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 996 | return 0; |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 997 | err_base: |
| 998 | iounmap(board->basemem); |
| 999 | board->basemem = NULL; |
Jiri Slaby | e46a5e3 | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 1000 | err_reg: |
| 1001 | pci_release_region(pdev, 2); |
Jiri Slaby | 9cde5bf | 2007-02-10 01:45:35 -0800 | [diff] [blame] | 1002 | err: |
| 1003 | return retval; |
| 1004 | } |
| 1005 | |
| 1006 | static void __devexit moxa_pci_remove(struct pci_dev *pdev) |
| 1007 | { |
| 1008 | struct moxa_board_conf *brd = pci_get_drvdata(pdev); |
| 1009 | |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 1010 | moxa_board_deinit(brd); |
| 1011 | |
Jiri Slaby | e46a5e3 | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 1012 | pci_release_region(pdev, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | } |
Jiri Slaby | a784bf7 | 2007-02-10 01:45:36 -0800 | [diff] [blame] | 1014 | |
| 1015 | static struct pci_driver moxa_pci_driver = { |
| 1016 | .name = "moxa", |
| 1017 | .id_table = moxa_pcibrds, |
| 1018 | .probe = moxa_pci_probe, |
| 1019 | .remove = __devexit_p(moxa_pci_remove) |
| 1020 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | #endif /* CONFIG_PCI */ |
| 1022 | |
| 1023 | static int __init moxa_init(void) |
| 1024 | { |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 1025 | unsigned int isabrds = 0; |
Jiri Slaby | d353eca | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 1026 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | |
Jiri Slaby | 7aeb95d | 2007-10-18 03:06:24 -0700 | [diff] [blame] | 1028 | printk(KERN_INFO "MOXA Intellio family driver version %s\n", |
| 1029 | MOXA_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | moxaDriver = alloc_tty_driver(MAX_PORTS + 1); |
| 1031 | if (!moxaDriver) |
| 1032 | return -ENOMEM; |
| 1033 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | moxaDriver->owner = THIS_MODULE; |
Sergey Vlasov | 9b4e3b1 | 2005-09-03 16:26:49 +0100 | [diff] [blame] | 1035 | moxaDriver->name = "ttyMX"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | moxaDriver->major = ttymajor; |
| 1037 | moxaDriver->minor_start = 0; |
| 1038 | moxaDriver->type = TTY_DRIVER_TYPE_SERIAL; |
| 1039 | moxaDriver->subtype = SERIAL_TYPE_NORMAL; |
| 1040 | moxaDriver->init_termios = tty_std_termios; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1042 | moxaDriver->init_termios.c_ispeed = 9600; |
| 1043 | moxaDriver->init_termios.c_ospeed = 9600; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | moxaDriver->flags = TTY_DRIVER_REAL_RAW; |
| 1045 | tty_set_operations(moxaDriver, &moxa_ops); |
| 1046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | if (tty_register_driver(moxaDriver)) { |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1048 | printk(KERN_ERR "can't register MOXA Smartio tty driver!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | put_tty_driver(moxaDriver); |
| 1050 | return -1; |
| 1051 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | |
Jiri Slaby | d353eca | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 1053 | /* Find the boards defined from module args. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | #ifdef MODULE |
Jiri Slaby | d353eca | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 1055 | { |
| 1056 | struct moxa_board_conf *brd = moxa_boards; |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 1057 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | for (i = 0; i < MAX_BOARDS; i++) { |
Jiri Slaby | d353eca | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 1059 | if (!baseaddr[i]) |
| 1060 | break; |
| 1061 | if (type[i] == MOXA_BOARD_C218_ISA || |
| 1062 | type[i] == MOXA_BOARD_C320_ISA) { |
Jiri Slaby | 7aeb95d | 2007-10-18 03:06:24 -0700 | [diff] [blame] | 1063 | pr_debug("Moxa board %2d: %s board(baseAddr=%lx)\n", |
Jiri Slaby | d353eca | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 1064 | isabrds + 1, moxa_brdname[type[i] - 1], |
| 1065 | baseaddr[i]); |
| 1066 | brd->boardType = type[i]; |
| 1067 | brd->numPorts = type[i] == MOXA_BOARD_C218_ISA ? 8 : |
| 1068 | numports[i]; |
| 1069 | brd->busType = MOXA_BUS_TYPE_ISA; |
Alan Cox | 24cb233 | 2008-04-30 00:54:19 -0700 | [diff] [blame] | 1070 | brd->basemem = ioremap_nocache(baseaddr[i], 0x4000); |
Jiri Slaby | d353eca | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 1071 | if (!brd->basemem) { |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1072 | printk(KERN_ERR "MOXA: can't remap %lx\n", |
Jiri Slaby | d353eca | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 1073 | baseaddr[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | continue; |
| 1075 | } |
Jiri Slaby | 0371823 | 2008-04-30 00:53:39 -0700 | [diff] [blame] | 1076 | if (moxa_init_board(brd, NULL)) { |
| 1077 | iounmap(brd->basemem); |
| 1078 | brd->basemem = NULL; |
| 1079 | continue; |
| 1080 | } |
Jiri Slaby | d353eca | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 1081 | |
Jiri Slaby | bb9f910 | 2008-04-30 00:53:48 -0700 | [diff] [blame] | 1082 | printk(KERN_INFO "MOXA isa board found at 0x%.8lu and " |
| 1083 | "ready (%u ports, firmware loaded)\n", |
| 1084 | baseaddr[i], brd->numPorts); |
| 1085 | |
Jiri Slaby | d353eca | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 1086 | brd++; |
| 1087 | isabrds++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | } |
| 1089 | } |
Jiri Slaby | d353eca | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 1090 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | #endif |
Jiri Slaby | a784bf7 | 2007-02-10 01:45:36 -0800 | [diff] [blame] | 1092 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | #ifdef CONFIG_PCI |
Jiri Slaby | a784bf7 | 2007-02-10 01:45:36 -0800 | [diff] [blame] | 1094 | retval = pci_register_driver(&moxa_pci_driver); |
| 1095 | if (retval) { |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1096 | printk(KERN_ERR "Can't register MOXA pci driver!\n"); |
Jiri Slaby | d353eca | 2008-04-30 00:53:37 -0700 | [diff] [blame] | 1097 | if (isabrds) |
Jiri Slaby | a784bf7 | 2007-02-10 01:45:36 -0800 | [diff] [blame] | 1098 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | } |
| 1100 | #endif |
Jiri Slaby | a784bf7 | 2007-02-10 01:45:36 -0800 | [diff] [blame] | 1101 | |
Jiri Slaby | a784bf7 | 2007-02-10 01:45:36 -0800 | [diff] [blame] | 1102 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | static void __exit moxa_exit(void) |
| 1106 | { |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1107 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | |
Jiri Slaby | 9cde5bf | 2007-02-10 01:45:35 -0800 | [diff] [blame] | 1109 | #ifdef CONFIG_PCI |
Jiri Slaby | a784bf7 | 2007-02-10 01:45:36 -0800 | [diff] [blame] | 1110 | pci_unregister_driver(&moxa_pci_driver); |
Jiri Slaby | 9cde5bf | 2007-02-10 01:45:35 -0800 | [diff] [blame] | 1111 | #endif |
Jiri Slaby | a784bf7 | 2007-02-10 01:45:36 -0800 | [diff] [blame] | 1112 | |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 1113 | for (i = 0; i < MAX_BOARDS; i++) /* ISA boards */ |
| 1114 | if (moxa_boards[i].ready) |
| 1115 | moxa_board_deinit(&moxa_boards[i]); |
Jiri Slaby | 2a54134 | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1116 | |
| 1117 | del_timer_sync(&moxaTimer); |
| 1118 | |
| 1119 | if (tty_unregister_driver(moxaDriver)) |
| 1120 | printk(KERN_ERR "Couldn't unregister MOXA Intellio family " |
| 1121 | "serial driver\n"); |
| 1122 | put_tty_driver(moxaDriver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | module_init(moxa_init); |
| 1126 | module_exit(moxa_exit); |
| 1127 | |
Alan Cox | f176178 | 2009-11-30 13:17:51 +0000 | [diff] [blame] | 1128 | static void moxa_shutdown(struct tty_port *port) |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1129 | { |
Alan Cox | f176178 | 2009-11-30 13:17:51 +0000 | [diff] [blame] | 1130 | struct moxa_port *ch = container_of(port, struct moxa_port, port); |
| 1131 | MoxaPortDisable(ch); |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1132 | MoxaPortFlushData(ch, 2); |
Alan Cox | f176178 | 2009-11-30 13:17:51 +0000 | [diff] [blame] | 1133 | clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags); |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 1136 | static int moxa_carrier_raised(struct tty_port *port) |
| 1137 | { |
| 1138 | struct moxa_port *ch = container_of(port, struct moxa_port, port); |
| 1139 | int dcd; |
| 1140 | |
Alan Cox | 8482bcd | 2009-11-30 13:18:13 +0000 | [diff] [blame] | 1141 | spin_lock_irq(&port->lock); |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 1142 | dcd = ch->DCDState; |
Alan Cox | 8482bcd | 2009-11-30 13:18:13 +0000 | [diff] [blame] | 1143 | spin_unlock_irq(&port->lock); |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 1144 | return dcd; |
| 1145 | } |
| 1146 | |
Alan Cox | f176178 | 2009-11-30 13:17:51 +0000 | [diff] [blame] | 1147 | static void moxa_dtr_rts(struct tty_port *port, int onoff) |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1148 | { |
Alan Cox | f176178 | 2009-11-30 13:17:51 +0000 | [diff] [blame] | 1149 | struct moxa_port *ch = container_of(port, struct moxa_port, port); |
| 1150 | MoxaPortLineCtrl(ch, onoff, onoff); |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
Alan Cox | f176178 | 2009-11-30 13:17:51 +0000 | [diff] [blame] | 1153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | static int moxa_open(struct tty_struct *tty, struct file *filp) |
| 1155 | { |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 1156 | struct moxa_board_conf *brd; |
Jiri Slaby | 8f8ecba | 2007-02-10 01:45:33 -0800 | [diff] [blame] | 1157 | struct moxa_port *ch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | int port; |
| 1159 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | |
Jiri Slaby | 11324ed | 2007-02-10 01:45:31 -0800 | [diff] [blame] | 1161 | port = tty->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | if (port == MAX_PORTS) { |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1163 | return capable(CAP_SYS_ADMIN) ? 0 : -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | } |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1165 | if (mutex_lock_interruptible(&moxa_openlock)) |
| 1166 | return -ERESTARTSYS; |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 1167 | brd = &moxa_boards[port / MAX_PORTS_PER_BOARD]; |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1168 | if (!brd->ready) { |
| 1169 | mutex_unlock(&moxa_openlock); |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 1170 | return -ENODEV; |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1171 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | |
Dirk Eibach | f0e8527 | 2009-06-11 14:56:44 +0100 | [diff] [blame] | 1173 | if (port % MAX_PORTS_PER_BOARD >= brd->numPorts) { |
| 1174 | mutex_unlock(&moxa_openlock); |
| 1175 | return -ENODEV; |
| 1176 | } |
| 1177 | |
Jiri Slaby | 810ab09 | 2008-04-30 00:53:41 -0700 | [diff] [blame] | 1178 | ch = &brd->ports[port % MAX_PORTS_PER_BOARD]; |
Alan Cox | 9de6a51 | 2008-07-16 21:56:02 +0100 | [diff] [blame] | 1179 | ch->port.count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | tty->driver_data = ch; |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 1181 | tty_port_tty_set(&ch->port, tty); |
Alan Cox | f176178 | 2009-11-30 13:17:51 +0000 | [diff] [blame] | 1182 | mutex_lock(&ch->port.mutex); |
Alan Cox | 9de6a51 | 2008-07-16 21:56:02 +0100 | [diff] [blame] | 1183 | if (!(ch->port.flags & ASYNC_INITIALIZED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | ch->statusflags = 0; |
Alan Cox | db1acaa | 2008-02-08 04:18:43 -0800 | [diff] [blame] | 1185 | moxa_set_tty_param(tty, tty->termios); |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1186 | MoxaPortLineCtrl(ch, 1, 1); |
| 1187 | MoxaPortEnable(ch); |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1188 | MoxaSetFifo(ch, ch->type == PORT_16550A); |
Alan Cox | 9de6a51 | 2008-07-16 21:56:02 +0100 | [diff] [blame] | 1189 | ch->port.flags |= ASYNC_INITIALIZED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | } |
Alan Cox | f176178 | 2009-11-30 13:17:51 +0000 | [diff] [blame] | 1191 | mutex_unlock(&ch->port.mutex); |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1192 | mutex_unlock(&moxa_openlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | |
Alan Cox | f176178 | 2009-11-30 13:17:51 +0000 | [diff] [blame] | 1194 | retval = tty_port_block_til_ready(&ch->port, tty, filp); |
| 1195 | if (retval == 0) |
| 1196 | set_bit(ASYNCB_NORMAL_ACTIVE, &ch->port.flags); |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1197 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | static void moxa_close(struct tty_struct *tty, struct file *filp) |
| 1201 | { |
Alan Cox | f176178 | 2009-11-30 13:17:51 +0000 | [diff] [blame] | 1202 | struct moxa_port *ch = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | ch->cflag = tty->termios->c_cflag; |
Alan Cox | f176178 | 2009-11-30 13:17:51 +0000 | [diff] [blame] | 1204 | tty_port_close(&ch->port, tty, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | static int moxa_write(struct tty_struct *tty, |
| 1208 | const unsigned char *buf, int count) |
| 1209 | { |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1210 | struct moxa_port *ch = tty->driver_data; |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1211 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | if (ch == NULL) |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1214 | return 0; |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 1215 | |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1216 | spin_lock_bh(&moxa_lock); |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 1217 | len = MoxaPortWriteData(tty, buf, count); |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1218 | spin_unlock_bh(&moxa_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 1220 | set_bit(LOWWAIT, &ch->statusflags); |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1221 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | static int moxa_write_room(struct tty_struct *tty) |
| 1225 | { |
Jiri Slaby | 8f8ecba | 2007-02-10 01:45:33 -0800 | [diff] [blame] | 1226 | struct moxa_port *ch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | |
| 1228 | if (tty->stopped) |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1229 | return 0; |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1230 | ch = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | if (ch == NULL) |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1232 | return 0; |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1233 | return MoxaPortTxFree(ch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | static void moxa_flush_buffer(struct tty_struct *tty) |
| 1237 | { |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1238 | struct moxa_port *ch = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | |
| 1240 | if (ch == NULL) |
| 1241 | return; |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1242 | MoxaPortFlushData(ch, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | tty_wakeup(tty); |
| 1244 | } |
| 1245 | |
| 1246 | static int moxa_chars_in_buffer(struct tty_struct *tty) |
| 1247 | { |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1248 | struct moxa_port *ch = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | int chars; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1251 | chars = MoxaPortTxQueue(ch); |
Alan Cox | f710ebd | 2009-11-30 13:18:18 +0000 | [diff] [blame] | 1252 | if (chars) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | /* |
| 1254 | * Make it possible to wakeup anything waiting for output |
| 1255 | * in tty_ioctl.c, etc. |
| 1256 | */ |
Alan Cox | f710ebd | 2009-11-30 13:18:18 +0000 | [diff] [blame] | 1257 | set_bit(EMPTYWAIT, &ch->statusflags); |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1258 | return chars; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | static int moxa_tiocmget(struct tty_struct *tty, struct file *file) |
| 1262 | { |
Alan Cox | 8482bcd | 2009-11-30 13:18:13 +0000 | [diff] [blame] | 1263 | struct moxa_port *ch = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | int flag = 0, dtr, rts; |
| 1265 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1266 | MoxaPortGetLineOut(ch, &dtr, &rts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | if (dtr) |
| 1268 | flag |= TIOCM_DTR; |
| 1269 | if (rts) |
| 1270 | flag |= TIOCM_RTS; |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1271 | dtr = MoxaPortLineStatus(ch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | if (dtr & 1) |
| 1273 | flag |= TIOCM_CTS; |
| 1274 | if (dtr & 2) |
| 1275 | flag |= TIOCM_DSR; |
| 1276 | if (dtr & 4) |
| 1277 | flag |= TIOCM_CD; |
| 1278 | return flag; |
| 1279 | } |
| 1280 | |
| 1281 | static int moxa_tiocmset(struct tty_struct *tty, struct file *file, |
| 1282 | unsigned int set, unsigned int clear) |
| 1283 | { |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1284 | struct moxa_port *ch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | int port; |
| 1286 | int dtr, rts; |
| 1287 | |
Jiri Slaby | 11324ed | 2007-02-10 01:45:31 -0800 | [diff] [blame] | 1288 | port = tty->index; |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1289 | mutex_lock(&moxa_openlock); |
| 1290 | ch = tty->driver_data; |
| 1291 | if (!ch) { |
| 1292 | mutex_unlock(&moxa_openlock); |
Jiri Slaby | 74d7d97 | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1293 | return -EINVAL; |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1296 | MoxaPortGetLineOut(ch, &dtr, &rts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | if (set & TIOCM_RTS) |
| 1298 | rts = 1; |
| 1299 | if (set & TIOCM_DTR) |
| 1300 | dtr = 1; |
| 1301 | if (clear & TIOCM_RTS) |
| 1302 | rts = 0; |
| 1303 | if (clear & TIOCM_DTR) |
| 1304 | dtr = 0; |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1305 | MoxaPortLineCtrl(ch, dtr, rts); |
Jiri Slaby | a8f5cda | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1306 | mutex_unlock(&moxa_openlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | return 0; |
| 1308 | } |
| 1309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | static void moxa_set_termios(struct tty_struct *tty, |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1311 | struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | { |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1313 | struct moxa_port *ch = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | |
| 1315 | if (ch == NULL) |
| 1316 | return; |
Alan Cox | db1acaa | 2008-02-08 04:18:43 -0800 | [diff] [blame] | 1317 | moxa_set_tty_param(tty, old_termios); |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1318 | if (!(old_termios->c_cflag & CLOCAL) && C_CLOCAL(tty)) |
Alan Cox | 9de6a51 | 2008-07-16 21:56:02 +0100 | [diff] [blame] | 1319 | wake_up_interruptible(&ch->port.open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | static void moxa_stop(struct tty_struct *tty) |
| 1323 | { |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1324 | struct moxa_port *ch = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | |
| 1326 | if (ch == NULL) |
| 1327 | return; |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1328 | MoxaPortTxDisable(ch); |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 1329 | set_bit(TXSTOPPED, &ch->statusflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | |
| 1333 | static void moxa_start(struct tty_struct *tty) |
| 1334 | { |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1335 | struct moxa_port *ch = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | |
| 1337 | if (ch == NULL) |
| 1338 | return; |
| 1339 | |
| 1340 | if (!(ch->statusflags & TXSTOPPED)) |
| 1341 | return; |
| 1342 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1343 | MoxaPortTxEnable(ch); |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 1344 | clear_bit(TXSTOPPED, &ch->statusflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | static void moxa_hangup(struct tty_struct *tty) |
| 1348 | { |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 1349 | struct moxa_port *ch = tty->driver_data; |
Alan Cox | f176178 | 2009-11-30 13:17:51 +0000 | [diff] [blame] | 1350 | tty_port_hangup(&ch->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | } |
| 1352 | |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1353 | static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd) |
| 1354 | { |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 1355 | struct tty_struct *tty; |
Alan Cox | 8482bcd | 2009-11-30 13:18:13 +0000 | [diff] [blame] | 1356 | unsigned long flags; |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1357 | dcd = !!dcd; |
| 1358 | |
Alan Cox | 8482bcd | 2009-11-30 13:18:13 +0000 | [diff] [blame] | 1359 | spin_lock_irqsave(&p->port.lock, flags); |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 1360 | if (dcd != p->DCDState) { |
Alan Cox | 8482bcd | 2009-11-30 13:18:13 +0000 | [diff] [blame] | 1361 | p->DCDState = dcd; |
| 1362 | spin_unlock_irqrestore(&p->port.lock, flags); |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 1363 | tty = tty_port_tty_get(&p->port); |
| 1364 | if (tty && C_CLOCAL(tty) && !dcd) |
| 1365 | tty_hangup(tty); |
| 1366 | tty_kref_put(tty); |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1367 | } |
Alan Cox | 8482bcd | 2009-11-30 13:18:13 +0000 | [diff] [blame] | 1368 | else |
| 1369 | spin_unlock_irqrestore(&p->port.lock, flags); |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | static int moxa_poll_port(struct moxa_port *p, unsigned int handle, |
| 1373 | u16 __iomem *ip) |
| 1374 | { |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 1375 | struct tty_struct *tty = tty_port_tty_get(&p->port); |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1376 | void __iomem *ofsAddr; |
Alan Cox | 9de6a51 | 2008-07-16 21:56:02 +0100 | [diff] [blame] | 1377 | unsigned int inited = p->port.flags & ASYNC_INITIALIZED; |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1378 | u16 intr; |
| 1379 | |
| 1380 | if (tty) { |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 1381 | if (test_bit(EMPTYWAIT, &p->statusflags) && |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1382 | MoxaPortTxQueue(p) == 0) { |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 1383 | clear_bit(EMPTYWAIT, &p->statusflags); |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1384 | tty_wakeup(tty); |
| 1385 | } |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 1386 | if (test_bit(LOWWAIT, &p->statusflags) && !tty->stopped && |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1387 | MoxaPortTxQueue(p) <= WAKEUP_CHARS) { |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 1388 | clear_bit(LOWWAIT, &p->statusflags); |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1389 | tty_wakeup(tty); |
| 1390 | } |
| 1391 | |
Alan Cox | f9b412a | 2009-11-30 13:18:08 +0000 | [diff] [blame] | 1392 | if (inited && !test_bit(TTY_THROTTLED, &tty->flags) && |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1393 | MoxaPortRxQueue(p) > 0) { /* RX */ |
| 1394 | MoxaPortReadData(p); |
| 1395 | tty_schedule_flip(tty); |
| 1396 | } |
| 1397 | } else { |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 1398 | clear_bit(EMPTYWAIT, &p->statusflags); |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1399 | MoxaPortFlushData(p, 0); /* flush RX */ |
| 1400 | } |
| 1401 | |
| 1402 | if (!handle) /* nothing else to do */ |
Jiri Slaby | 0e0fd7d | 2009-04-06 17:34:04 +0100 | [diff] [blame] | 1403 | goto put; |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1404 | |
| 1405 | intr = readw(ip); /* port irq status */ |
| 1406 | if (intr == 0) |
Jiri Slaby | 0e0fd7d | 2009-04-06 17:34:04 +0100 | [diff] [blame] | 1407 | goto put; |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1408 | |
| 1409 | writew(0, ip); /* ACK port */ |
| 1410 | ofsAddr = p->tableAddr; |
| 1411 | if (intr & IntrTx) /* disable tx intr */ |
| 1412 | writew(readw(ofsAddr + HostStat) & ~WakeupTx, |
| 1413 | ofsAddr + HostStat); |
| 1414 | |
| 1415 | if (!inited) |
Jiri Slaby | 0e0fd7d | 2009-04-06 17:34:04 +0100 | [diff] [blame] | 1416 | goto put; |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1417 | |
| 1418 | if (tty && (intr & IntrBreak) && !I_IGNBRK(tty)) { /* BREAK */ |
| 1419 | tty_insert_flip_char(tty, 0, TTY_BREAK); |
| 1420 | tty_schedule_flip(tty); |
| 1421 | } |
| 1422 | |
| 1423 | if (intr & IntrLine) |
| 1424 | moxa_new_dcdstate(p, readb(ofsAddr + FlagStat) & DCD_state); |
Jiri Slaby | 0e0fd7d | 2009-04-06 17:34:04 +0100 | [diff] [blame] | 1425 | put: |
| 1426 | tty_kref_put(tty); |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1427 | |
| 1428 | return 0; |
| 1429 | } |
| 1430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | static void moxa_poll(unsigned long ignored) |
| 1432 | { |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1433 | struct moxa_board_conf *brd; |
| 1434 | u16 __iomem *ip; |
Jiri Slaby | 2a54134 | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1435 | unsigned int card, port, served = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1437 | spin_lock(&moxa_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | for (card = 0; card < MAX_BOARDS; card++) { |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1439 | brd = &moxa_boards[card]; |
| 1440 | if (!brd->ready) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | continue; |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1442 | |
Jiri Slaby | 2a54134 | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1443 | served++; |
| 1444 | |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1445 | ip = NULL; |
| 1446 | if (readb(brd->intPend) == 0xff) |
| 1447 | ip = brd->intTable + readb(brd->intNdx); |
| 1448 | |
| 1449 | for (port = 0; port < brd->numPorts; port++) |
| 1450 | moxa_poll_port(&brd->ports[port], !!ip, ip + port); |
| 1451 | |
| 1452 | if (ip) |
| 1453 | writeb(0, brd->intPend); /* ACK */ |
| 1454 | |
| 1455 | if (moxaLowWaterChk) { |
| 1456 | struct moxa_port *p = brd->ports; |
| 1457 | for (port = 0; port < brd->numPorts; port++, p++) |
| 1458 | if (p->lowChkFlag) { |
| 1459 | p->lowChkFlag = 0; |
| 1460 | moxa_low_water_check(p->tableAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | } |
| 1463 | } |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1464 | moxaLowWaterChk = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | |
Jiri Slaby | 2a54134 | 2008-04-30 00:53:45 -0700 | [diff] [blame] | 1466 | if (served) |
| 1467 | mod_timer(&moxaTimer, jiffies + HZ / 50); |
| 1468 | spin_unlock(&moxa_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | /******************************************************************************/ |
| 1472 | |
Alan Cox | db1acaa | 2008-02-08 04:18:43 -0800 | [diff] [blame] | 1473 | static void moxa_set_tty_param(struct tty_struct *tty, struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | { |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1475 | register struct ktermios *ts = tty->termios; |
| 1476 | struct moxa_port *ch = tty->driver_data; |
Alan Cox | db1acaa | 2008-02-08 04:18:43 -0800 | [diff] [blame] | 1477 | int rts, cts, txflow, rxflow, xany, baud; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | rts = cts = txflow = rxflow = xany = 0; |
| 1480 | if (ts->c_cflag & CRTSCTS) |
| 1481 | rts = cts = 1; |
| 1482 | if (ts->c_iflag & IXON) |
| 1483 | txflow = 1; |
| 1484 | if (ts->c_iflag & IXOFF) |
| 1485 | rxflow = 1; |
| 1486 | if (ts->c_iflag & IXANY) |
| 1487 | xany = 1; |
Alan Cox | db1acaa | 2008-02-08 04:18:43 -0800 | [diff] [blame] | 1488 | |
| 1489 | /* Clear the features we don't support */ |
| 1490 | ts->c_cflag &= ~CMSPAR; |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1491 | MoxaPortFlowCtrl(ch, rts, cts, txflow, rxflow, xany); |
| 1492 | baud = MoxaPortSetTermio(ch, ts, tty_get_baud_rate(tty)); |
Alan Cox | db1acaa | 2008-02-08 04:18:43 -0800 | [diff] [blame] | 1493 | if (baud == -1) |
| 1494 | baud = tty_termios_baud_rate(old_termios); |
| 1495 | /* Not put the baud rate into the termios data */ |
| 1496 | tty_encode_baud_rate(tty, baud, baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | /***************************************************************************** |
| 1500 | * Driver level functions: * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | *****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1503 | static void MoxaPortFlushData(struct moxa_port *port, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | { |
| 1505 | void __iomem *ofsAddr; |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1506 | if (mode < 0 || mode > 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | return; |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1508 | ofsAddr = port->tableAddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | moxafunc(ofsAddr, FC_FlushQueue, mode); |
| 1510 | if (mode != 1) { |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1511 | port->lowChkFlag = 0; |
Jiri Slaby | 6f56b658 | 2007-10-18 03:06:24 -0700 | [diff] [blame] | 1512 | moxa_low_water_check(ofsAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | } |
| 1514 | } |
| 1515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | /* |
| 1517 | * Moxa Port Number Description: |
| 1518 | * |
| 1519 | * MOXA serial driver supports up to 4 MOXA-C218/C320 boards. And, |
| 1520 | * the port number using in MOXA driver functions will be 0 to 31 for |
| 1521 | * first MOXA board, 32 to 63 for second, 64 to 95 for third and 96 |
| 1522 | * to 127 for fourth. For example, if you setup three MOXA boards, |
| 1523 | * first board is C218, second board is C320-16 and third board is |
| 1524 | * C320-32. The port number of first board (C218 - 8 ports) is from |
| 1525 | * 0 to 7. The port number of second board (C320 - 16 ports) is form |
| 1526 | * 32 to 47. The port number of third board (C320 - 32 ports) is from |
| 1527 | * 64 to 95. And those port numbers form 8 to 31, 48 to 63 and 96 to |
| 1528 | * 127 will be invalid. |
| 1529 | * |
| 1530 | * |
| 1531 | * Moxa Functions Description: |
| 1532 | * |
| 1533 | * Function 1: Driver initialization routine, this routine must be |
| 1534 | * called when initialized driver. |
| 1535 | * Syntax: |
| 1536 | * void MoxaDriverInit(); |
| 1537 | * |
| 1538 | * |
| 1539 | * Function 2: Moxa driver private IOCTL command processing. |
| 1540 | * Syntax: |
| 1541 | * int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port); |
| 1542 | * |
| 1543 | * unsigned int cmd : IOCTL command |
| 1544 | * unsigned long arg : IOCTL argument |
| 1545 | * int port : port number (0 - 127) |
| 1546 | * |
| 1547 | * return: 0 (OK) |
| 1548 | * -EINVAL |
| 1549 | * -ENOIOCTLCMD |
| 1550 | * |
| 1551 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | * Function 6: Enable this port to start Tx/Rx data. |
| 1553 | * Syntax: |
| 1554 | * void MoxaPortEnable(int port); |
| 1555 | * int port : port number (0 - 127) |
| 1556 | * |
| 1557 | * |
| 1558 | * Function 7: Disable this port |
| 1559 | * Syntax: |
| 1560 | * void MoxaPortDisable(int port); |
| 1561 | * int port : port number (0 - 127) |
| 1562 | * |
| 1563 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | * Function 10: Setting baud rate of this port. |
| 1565 | * Syntax: |
Jiri Slaby | 08d01c79 | 2008-04-30 00:53:47 -0700 | [diff] [blame] | 1566 | * speed_t MoxaPortSetBaud(int port, speed_t baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | * int port : port number (0 - 127) |
| 1568 | * long baud : baud rate (50 - 115200) |
| 1569 | * |
| 1570 | * return: 0 : this port is invalid or baud < 50 |
| 1571 | * 50 - 115200 : the real baud rate set to the port, if |
| 1572 | * the argument baud is large than maximun |
| 1573 | * available baud rate, the real setting |
| 1574 | * baud rate will be the maximun baud rate. |
| 1575 | * |
| 1576 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | * Function 12: Configure the port. |
| 1578 | * Syntax: |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1579 | * int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | * int port : port number (0 - 127) |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1581 | * struct ktermios * termio : termio structure pointer |
Alan Cox | c7bce30 | 2006-09-30 23:27:24 -0700 | [diff] [blame] | 1582 | * speed_t baud : baud rate |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | * |
| 1584 | * return: -1 : this port is invalid or termio == NULL |
| 1585 | * 0 : setting O.K. |
| 1586 | * |
| 1587 | * |
| 1588 | * Function 13: Get the DTR/RTS state of this port. |
| 1589 | * Syntax: |
| 1590 | * int MoxaPortGetLineOut(int port, int *dtrState, int *rtsState); |
| 1591 | * int port : port number (0 - 127) |
| 1592 | * int * dtrState : pointer to INT to receive the current DTR |
| 1593 | * state. (if NULL, this function will not |
| 1594 | * write to this address) |
| 1595 | * int * rtsState : pointer to INT to receive the current RTS |
| 1596 | * state. (if NULL, this function will not |
| 1597 | * write to this address) |
| 1598 | * |
| 1599 | * return: -1 : this port is invalid |
| 1600 | * 0 : O.K. |
| 1601 | * |
| 1602 | * |
| 1603 | * Function 14: Setting the DTR/RTS output state of this port. |
| 1604 | * Syntax: |
| 1605 | * void MoxaPortLineCtrl(int port, int dtrState, int rtsState); |
| 1606 | * int port : port number (0 - 127) |
| 1607 | * int dtrState : DTR output state (0: off, 1: on) |
| 1608 | * int rtsState : RTS output state (0: off, 1: on) |
| 1609 | * |
| 1610 | * |
| 1611 | * Function 15: Setting the flow control of this port. |
| 1612 | * Syntax: |
| 1613 | * void MoxaPortFlowCtrl(int port, int rtsFlow, int ctsFlow, int rxFlow, |
| 1614 | * int txFlow,int xany); |
| 1615 | * int port : port number (0 - 127) |
| 1616 | * int rtsFlow : H/W RTS flow control (0: no, 1: yes) |
| 1617 | * int ctsFlow : H/W CTS flow control (0: no, 1: yes) |
| 1618 | * int rxFlow : S/W Rx XON/XOFF flow control (0: no, 1: yes) |
| 1619 | * int txFlow : S/W Tx XON/XOFF flow control (0: no, 1: yes) |
| 1620 | * int xany : S/W XANY flow control (0: no, 1: yes) |
| 1621 | * |
| 1622 | * |
| 1623 | * Function 16: Get ths line status of this port |
| 1624 | * Syntax: |
| 1625 | * int MoxaPortLineStatus(int port); |
| 1626 | * int port : port number (0 - 127) |
| 1627 | * |
| 1628 | * return: Bit 0 - CTS state (0: off, 1: on) |
| 1629 | * Bit 1 - DSR state (0: off, 1: on) |
| 1630 | * Bit 2 - DCD state (0: off, 1: on) |
| 1631 | * |
| 1632 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | * Function 19: Flush the Rx/Tx buffer data of this port. |
| 1634 | * Syntax: |
| 1635 | * void MoxaPortFlushData(int port, int mode); |
| 1636 | * int port : port number (0 - 127) |
| 1637 | * int mode |
| 1638 | * 0 : flush the Rx buffer |
| 1639 | * 1 : flush the Tx buffer |
| 1640 | * 2 : flush the Rx and Tx buffer |
| 1641 | * |
| 1642 | * |
| 1643 | * Function 20: Write data. |
| 1644 | * Syntax: |
| 1645 | * int MoxaPortWriteData(int port, unsigned char * buffer, int length); |
| 1646 | * int port : port number (0 - 127) |
| 1647 | * unsigned char * buffer : pointer to write data buffer. |
| 1648 | * int length : write data length |
| 1649 | * |
| 1650 | * return: 0 - length : real write data length |
| 1651 | * |
| 1652 | * |
| 1653 | * Function 21: Read data. |
| 1654 | * Syntax: |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 1655 | * int MoxaPortReadData(int port, struct tty_struct *tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | * int port : port number (0 - 127) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 1657 | * struct tty_struct *tty : tty for data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | * |
| 1659 | * return: 0 - length : real read data length |
| 1660 | * |
| 1661 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | * Function 24: Get the Tx buffer current queued data bytes |
| 1663 | * Syntax: |
| 1664 | * int MoxaPortTxQueue(int port); |
| 1665 | * int port : port number (0 - 127) |
| 1666 | * |
| 1667 | * return: .. : Tx buffer current queued data bytes |
| 1668 | * |
| 1669 | * |
| 1670 | * Function 25: Get the Tx buffer current free space |
| 1671 | * Syntax: |
| 1672 | * int MoxaPortTxFree(int port); |
| 1673 | * int port : port number (0 - 127) |
| 1674 | * |
| 1675 | * return: .. : Tx buffer current free space |
| 1676 | * |
| 1677 | * |
| 1678 | * Function 26: Get the Rx buffer current queued data bytes |
| 1679 | * Syntax: |
| 1680 | * int MoxaPortRxQueue(int port); |
| 1681 | * int port : port number (0 - 127) |
| 1682 | * |
| 1683 | * return: .. : Rx buffer current queued data bytes |
| 1684 | * |
| 1685 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | * Function 28: Disable port data transmission. |
| 1687 | * Syntax: |
| 1688 | * void MoxaPortTxDisable(int port); |
| 1689 | * int port : port number (0 - 127) |
| 1690 | * |
| 1691 | * |
| 1692 | * Function 29: Enable port data transmission. |
| 1693 | * Syntax: |
| 1694 | * void MoxaPortTxEnable(int port); |
| 1695 | * int port : port number (0 - 127) |
| 1696 | * |
| 1697 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | * Function 31: Get the received BREAK signal count and reset it. |
| 1699 | * Syntax: |
| 1700 | * int MoxaPortResetBrkCnt(int port); |
| 1701 | * int port : port number (0 - 127) |
| 1702 | * |
| 1703 | * return: 0 - .. : BREAK signal count |
| 1704 | * |
| 1705 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1708 | static void MoxaPortEnable(struct moxa_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | { |
| 1710 | void __iomem *ofsAddr; |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1711 | u16 lowwater = 512; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1713 | ofsAddr = port->tableAddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | writew(lowwater, ofsAddr + Low_water); |
Jiri Slaby | 08d01c79 | 2008-04-30 00:53:47 -0700 | [diff] [blame] | 1715 | if (MOXA_IS_320(port->board)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | moxafunc(ofsAddr, FC_SetBreakIrq, 0); |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1717 | else |
| 1718 | writew(readw(ofsAddr + HostStat) | WakeupBreak, |
| 1719 | ofsAddr + HostStat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | |
| 1721 | moxafunc(ofsAddr, FC_SetLineIrq, Magic_code); |
| 1722 | moxafunc(ofsAddr, FC_FlushQueue, 2); |
| 1723 | |
| 1724 | moxafunc(ofsAddr, FC_EnableCH, Magic_code); |
| 1725 | MoxaPortLineStatus(port); |
| 1726 | } |
| 1727 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1728 | static void MoxaPortDisable(struct moxa_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | { |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1730 | void __iomem *ofsAddr = port->tableAddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | |
| 1732 | moxafunc(ofsAddr, FC_SetFlowCtl, 0); /* disable flow control */ |
| 1733 | moxafunc(ofsAddr, FC_ClrLineIrq, Magic_code); |
| 1734 | writew(0, ofsAddr + HostStat); |
| 1735 | moxafunc(ofsAddr, FC_DisableCH, Magic_code); |
| 1736 | } |
| 1737 | |
Jiri Slaby | 08d01c79 | 2008-04-30 00:53:47 -0700 | [diff] [blame] | 1738 | static speed_t MoxaPortSetBaud(struct moxa_port *port, speed_t baud) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | { |
Jiri Slaby | 08d01c79 | 2008-04-30 00:53:47 -0700 | [diff] [blame] | 1740 | void __iomem *ofsAddr = port->tableAddr; |
| 1741 | unsigned int clock, val; |
| 1742 | speed_t max; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | |
Jiri Slaby | 08d01c79 | 2008-04-30 00:53:47 -0700 | [diff] [blame] | 1744 | max = MOXA_IS_320(port->board) ? 460800 : 921600; |
| 1745 | if (baud < 50) |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1746 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | if (baud > max) |
| 1748 | baud = max; |
Jiri Slaby | 08d01c79 | 2008-04-30 00:53:47 -0700 | [diff] [blame] | 1749 | clock = 921600; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | val = clock / baud; |
| 1751 | moxafunc(ofsAddr, FC_SetBaud, val); |
| 1752 | baud = clock / val; |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1753 | return baud; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1756 | static int MoxaPortSetTermio(struct moxa_port *port, struct ktermios *termio, |
| 1757 | speed_t baud) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | { |
| 1759 | void __iomem *ofsAddr; |
| 1760 | tcflag_t cflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | tcflag_t mode = 0; |
| 1762 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1763 | ofsAddr = port->tableAddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | cflag = termio->c_cflag; /* termio->c_cflag */ |
| 1765 | |
| 1766 | mode = termio->c_cflag & CSIZE; |
| 1767 | if (mode == CS5) |
| 1768 | mode = MX_CS5; |
| 1769 | else if (mode == CS6) |
| 1770 | mode = MX_CS6; |
| 1771 | else if (mode == CS7) |
| 1772 | mode = MX_CS7; |
| 1773 | else if (mode == CS8) |
| 1774 | mode = MX_CS8; |
| 1775 | |
| 1776 | if (termio->c_cflag & CSTOPB) { |
| 1777 | if (mode == MX_CS5) |
| 1778 | mode |= MX_STOP15; |
| 1779 | else |
| 1780 | mode |= MX_STOP2; |
| 1781 | } else |
| 1782 | mode |= MX_STOP1; |
| 1783 | |
| 1784 | if (termio->c_cflag & PARENB) { |
| 1785 | if (termio->c_cflag & PARODD) |
| 1786 | mode |= MX_PARODD; |
| 1787 | else |
| 1788 | mode |= MX_PAREVEN; |
| 1789 | } else |
| 1790 | mode |= MX_PARNONE; |
| 1791 | |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1792 | moxafunc(ofsAddr, FC_SetDataMode, (u16)mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | |
Jiri Slaby | 08d01c79 | 2008-04-30 00:53:47 -0700 | [diff] [blame] | 1794 | if (MOXA_IS_320(port->board) && baud >= 921600) |
| 1795 | return -1; |
| 1796 | |
Alan Cox | db1acaa | 2008-02-08 04:18:43 -0800 | [diff] [blame] | 1797 | baud = MoxaPortSetBaud(port, baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | |
| 1799 | if (termio->c_iflag & (IXON | IXOFF | IXANY)) { |
Alan Cox | f5c5a36 | 2009-11-30 13:17:57 +0000 | [diff] [blame] | 1800 | spin_lock_irq(&moxafunc_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | writeb(termio->c_cc[VSTART], ofsAddr + FuncArg); |
| 1802 | writeb(termio->c_cc[VSTOP], ofsAddr + FuncArg1); |
| 1803 | writeb(FC_SetXonXoff, ofsAddr + FuncCode); |
Jiri Slaby | 6f56b658 | 2007-10-18 03:06:24 -0700 | [diff] [blame] | 1804 | moxa_wait_finish(ofsAddr); |
Alan Cox | a808ac0 | 2009-11-30 13:18:02 +0000 | [diff] [blame] | 1805 | spin_unlock_irq(&moxafunc_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | |
| 1807 | } |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1808 | return baud; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1811 | static int MoxaPortGetLineOut(struct moxa_port *port, int *dtrState, |
| 1812 | int *rtsState) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | { |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1814 | if (dtrState) |
| 1815 | *dtrState = !!(port->lineCtrl & DTR_ON); |
| 1816 | if (rtsState) |
| 1817 | *rtsState = !!(port->lineCtrl & RTS_ON); |
| 1818 | |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1819 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1822 | static void MoxaPortLineCtrl(struct moxa_port *port, int dtr, int rts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | { |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 1824 | u8 mode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | if (dtr) |
| 1827 | mode |= DTR_ON; |
| 1828 | if (rts) |
| 1829 | mode |= RTS_ON; |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1830 | port->lineCtrl = mode; |
| 1831 | moxafunc(port->tableAddr, FC_LineControl, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1834 | static void MoxaPortFlowCtrl(struct moxa_port *port, int rts, int cts, |
| 1835 | int txflow, int rxflow, int txany) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | { |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1837 | int mode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | if (rts) |
| 1840 | mode |= RTS_FlowCtl; |
| 1841 | if (cts) |
| 1842 | mode |= CTS_FlowCtl; |
| 1843 | if (txflow) |
| 1844 | mode |= Tx_FlowCtl; |
| 1845 | if (rxflow) |
| 1846 | mode |= Rx_FlowCtl; |
| 1847 | if (txany) |
| 1848 | mode |= IXM_IXANY; |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1849 | moxafunc(port->tableAddr, FC_SetFlowCtl, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1852 | static int MoxaPortLineStatus(struct moxa_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | { |
| 1854 | void __iomem *ofsAddr; |
| 1855 | int val; |
| 1856 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1857 | ofsAddr = port->tableAddr; |
Alan Cox | f5c5a36 | 2009-11-30 13:17:57 +0000 | [diff] [blame] | 1858 | if (MOXA_IS_320(port->board)) |
| 1859 | val = moxafuncret(ofsAddr, FC_LineStatus, 0); |
| 1860 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | val = readw(ofsAddr + FlagStat) >> 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | val &= 0x0B; |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1863 | if (val & 8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | val |= 4; |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1865 | moxa_new_dcdstate(port, val & 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | val &= 7; |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1867 | return val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 1870 | static int MoxaPortWriteData(struct tty_struct *tty, |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1871 | const unsigned char *buffer, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | { |
Alan Cox | d450b5a | 2008-10-13 10:39:58 +0100 | [diff] [blame] | 1873 | struct moxa_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | void __iomem *baseAddr, *ofsAddr, *ofs; |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1875 | unsigned int c, total; |
| 1876 | u16 head, tail, tx_mask, spage, epage; |
| 1877 | u16 pageno, pageofs, bufhead; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1879 | ofsAddr = port->tableAddr; |
| 1880 | baseAddr = port->board->basemem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | tx_mask = readw(ofsAddr + TX_mask); |
| 1882 | spage = readw(ofsAddr + Page_txb); |
| 1883 | epage = readw(ofsAddr + EndPage_txb); |
| 1884 | tail = readw(ofsAddr + TXwptr); |
| 1885 | head = readw(ofsAddr + TXrptr); |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1886 | c = (head > tail) ? (head - tail - 1) : (head - tail + tx_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | if (c > len) |
| 1888 | c = len; |
Alan Cox | 9de6a51 | 2008-07-16 21:56:02 +0100 | [diff] [blame] | 1889 | moxaLog.txcnt[port->port.tty->index] += c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | total = c; |
| 1891 | if (spage == epage) { |
| 1892 | bufhead = readw(ofsAddr + Ofs_txb); |
| 1893 | writew(spage, baseAddr + Control_reg); |
| 1894 | while (c > 0) { |
| 1895 | if (head > tail) |
| 1896 | len = head - tail - 1; |
| 1897 | else |
| 1898 | len = tx_mask + 1 - tail; |
| 1899 | len = (c > len) ? len : c; |
| 1900 | ofs = baseAddr + DynPage_addr + bufhead + tail; |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1901 | memcpy_toio(ofs, buffer, len); |
| 1902 | buffer += len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | tail = (tail + len) & tx_mask; |
| 1904 | c -= len; |
| 1905 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | pageno = spage + (tail >> 13); |
| 1908 | pageofs = tail & Page_mask; |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1909 | while (c > 0) { |
| 1910 | len = Page_size - pageofs; |
| 1911 | if (len > c) |
| 1912 | len = c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | writeb(pageno, baseAddr + Control_reg); |
| 1914 | ofs = baseAddr + DynPage_addr + pageofs; |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1915 | memcpy_toio(ofs, buffer, len); |
| 1916 | buffer += len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | if (++pageno == epage) |
| 1918 | pageno = spage; |
| 1919 | pageofs = 0; |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1920 | c -= len; |
| 1921 | } |
| 1922 | tail = (tail + total) & tx_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | } |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1924 | writew(tail, ofsAddr + TXwptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | writeb(1, ofsAddr + CD180TXirq); /* start to send */ |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1926 | return total; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1929 | static int MoxaPortReadData(struct moxa_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | { |
Alan Cox | 9de6a51 | 2008-07-16 21:56:02 +0100 | [diff] [blame] | 1931 | struct tty_struct *tty = port->port.tty; |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1932 | unsigned char *dst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | void __iomem *baseAddr, *ofsAddr, *ofs; |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1934 | unsigned int count, len, total; |
| 1935 | u16 tail, rx_mask, spage, epage; |
| 1936 | u16 pageno, pageofs, bufhead, head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1938 | ofsAddr = port->tableAddr; |
| 1939 | baseAddr = port->board->basemem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | head = readw(ofsAddr + RXrptr); |
| 1941 | tail = readw(ofsAddr + RXwptr); |
| 1942 | rx_mask = readw(ofsAddr + RX_mask); |
| 1943 | spage = readw(ofsAddr + Page_rxb); |
| 1944 | epage = readw(ofsAddr + EndPage_rxb); |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1945 | count = (tail >= head) ? (tail - head) : (tail - head + rx_mask + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | if (count == 0) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 1947 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 1949 | total = count; |
Jiri Slaby | 7bcf97d | 2008-04-30 00:53:43 -0700 | [diff] [blame] | 1950 | moxaLog.rxcnt[tty->index] += total; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | if (spage == epage) { |
| 1952 | bufhead = readw(ofsAddr + Ofs_rxb); |
| 1953 | writew(spage, baseAddr + Control_reg); |
| 1954 | while (count > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | ofs = baseAddr + DynPage_addr + bufhead + head; |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1956 | len = (tail >= head) ? (tail - head) : |
| 1957 | (rx_mask + 1 - head); |
| 1958 | len = tty_prepare_flip_string(tty, &dst, |
| 1959 | min(len, count)); |
| 1960 | memcpy_fromio(dst, ofs, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | head = (head + len) & rx_mask; |
| 1962 | count -= len; |
| 1963 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | pageno = spage + (head >> 13); |
| 1966 | pageofs = head & Page_mask; |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1967 | while (count > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | writew(pageno, baseAddr + Control_reg); |
| 1969 | ofs = baseAddr + DynPage_addr + pageofs; |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1970 | len = tty_prepare_flip_string(tty, &dst, |
| 1971 | min(Page_size - pageofs, count)); |
| 1972 | memcpy_fromio(dst, ofs, len); |
| 1973 | |
| 1974 | count -= len; |
| 1975 | pageofs = (pageofs + len) & Page_mask; |
| 1976 | if (pageofs == 0 && ++pageno == epage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | pageno = spage; |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1978 | } |
| 1979 | head = (head + total) & rx_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | } |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1981 | writew(head, ofsAddr + RXrptr); |
| 1982 | if (readb(ofsAddr + FlagStat) & Xoff_state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | moxaLowWaterChk = 1; |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1984 | port->lowChkFlag = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | } |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1986 | return total; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1990 | static int MoxaPortTxQueue(struct moxa_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | { |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 1992 | void __iomem *ofsAddr = port->tableAddr; |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1993 | u16 rptr, wptr, mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | rptr = readw(ofsAddr + TXrptr); |
| 1996 | wptr = readw(ofsAddr + TXwptr); |
| 1997 | mask = readw(ofsAddr + TX_mask); |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 1998 | return (wptr - rptr) & mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 2001 | static int MoxaPortTxFree(struct moxa_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | { |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 2003 | void __iomem *ofsAddr = port->tableAddr; |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 2004 | u16 rptr, wptr, mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | rptr = readw(ofsAddr + TXrptr); |
| 2007 | wptr = readw(ofsAddr + TXwptr); |
| 2008 | mask = readw(ofsAddr + TX_mask); |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 2009 | return mask - ((wptr - rptr) & mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 2012 | static int MoxaPortRxQueue(struct moxa_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | { |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 2014 | void __iomem *ofsAddr = port->tableAddr; |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 2015 | u16 rptr, wptr, mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | rptr = readw(ofsAddr + RXrptr); |
| 2018 | wptr = readw(ofsAddr + RXwptr); |
| 2019 | mask = readw(ofsAddr + RX_mask); |
Jiri Slaby | 2108eba | 2008-04-30 00:53:44 -0700 | [diff] [blame] | 2020 | return (wptr - rptr) & mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 2023 | static void MoxaPortTxDisable(struct moxa_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | { |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 2025 | moxafunc(port->tableAddr, FC_SetXoffState, Magic_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 2028 | static void MoxaPortTxEnable(struct moxa_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | { |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 2030 | moxafunc(port->tableAddr, FC_SetXonState, Magic_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | } |
| 2032 | |
Jiri Slaby | 8f8ecba | 2007-02-10 01:45:33 -0800 | [diff] [blame] | 2033 | static int moxa_get_serial_info(struct moxa_port *info, |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 2034 | struct serial_struct __user *retinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | { |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 2036 | struct serial_struct tmp = { |
| 2037 | .type = info->type, |
Alan Cox | 9de6a51 | 2008-07-16 21:56:02 +0100 | [diff] [blame] | 2038 | .line = info->port.tty->index, |
| 2039 | .flags = info->port.flags, |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 2040 | .baud_base = 921600, |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 2041 | .close_delay = info->port.close_delay |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 2042 | }; |
| 2043 | return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | |
Jiri Slaby | 8f8ecba | 2007-02-10 01:45:33 -0800 | [diff] [blame] | 2047 | static int moxa_set_serial_info(struct moxa_port *info, |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 2048 | struct serial_struct __user *new_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | { |
| 2050 | struct serial_struct new_serial; |
| 2051 | |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 2052 | if (copy_from_user(&new_serial, new_info, sizeof(new_serial))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | return -EFAULT; |
| 2054 | |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 2055 | if (new_serial.irq != 0 || new_serial.port != 0 || |
| 2056 | new_serial.custom_divisor != 0 || |
| 2057 | new_serial.baud_base != 921600) |
| 2058 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | |
| 2060 | if (!capable(CAP_SYS_ADMIN)) { |
| 2061 | if (((new_serial.flags & ~ASYNC_USR_MASK) != |
Alan Cox | 9de6a51 | 2008-07-16 21:56:02 +0100 | [diff] [blame] | 2062 | (info->port.flags & ~ASYNC_USR_MASK))) |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 2063 | return -EPERM; |
| 2064 | } else |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 2065 | info->port.close_delay = new_serial.close_delay * HZ / 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | |
| 2067 | new_serial.flags = (new_serial.flags & ~ASYNC_FLAGS); |
Alan Cox | 9de6a51 | 2008-07-16 21:56:02 +0100 | [diff] [blame] | 2068 | new_serial.flags |= (info->port.flags & ASYNC_FLAGS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 2070 | MoxaSetFifo(info, new_serial.type == PORT_16550A); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | |
| 2072 | info->type = new_serial.type; |
Jiri Slaby | eaa95a8 | 2008-04-30 00:53:46 -0700 | [diff] [blame] | 2073 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | |
| 2077 | |
| 2078 | /***************************************************************************** |
| 2079 | * Static local functions: * |
| 2080 | *****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 2082 | static void MoxaSetFifo(struct moxa_port *port, int enable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | { |
Jiri Slaby | b4173f4 | 2008-04-30 00:53:40 -0700 | [diff] [blame] | 2084 | void __iomem *ofsAddr = port->tableAddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | |
| 2086 | if (!enable) { |
| 2087 | moxafunc(ofsAddr, FC_SetRxFIFOTrig, 0); |
| 2088 | moxafunc(ofsAddr, FC_SetTxFIFOCnt, 1); |
| 2089 | } else { |
| 2090 | moxafunc(ofsAddr, FC_SetRxFIFOTrig, 3); |
| 2091 | moxafunc(ofsAddr, FC_SetTxFIFOCnt, 16); |
| 2092 | } |
| 2093 | } |