/drivers/char/mxser.c

https://bitbucket.org/evzijst/gittest · C · 3170 lines · 2345 code · 422 blank · 403 comment · 619 complexity · 5f4faaf6c629796ead1d3f62fb60ccd8 MD5 · raw file

Large files are truncated click here to view the full file

  1. /*
  2. * mxser.c -- MOXA Smartio/Industio family multiport serial driver.
  3. *
  4. * Copyright (C) 1999-2001 Moxa Technologies (support@moxa.com.tw).
  5. *
  6. * This code is loosely based on the Linux serial driver, written by
  7. * Linus Torvalds, Theodore T'so and others.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. *
  23. * Original release 10/26/00
  24. *
  25. * 02/06/01 Support MOXA Industio family boards.
  26. * 02/06/01 Support TIOCGICOUNT.
  27. * 02/06/01 Fix the problem for connecting to serial mouse.
  28. * 02/06/01 Fix the problem for H/W flow control.
  29. * 02/06/01 Fix the compling warning when CONFIG_PCI
  30. * don't be defined.
  31. *
  32. * Fed through a cleanup, indent and remove of non 2.6 code by Alan Cox
  33. * <alan@redhat.com>. The original 1.8 code is available on www.moxa.com.
  34. * - Fixed x86_64 cleanness
  35. * - Fixed sleep with spinlock held in mxser_send_break
  36. */
  37. #include <linux/config.h>
  38. #include <linux/module.h>
  39. #include <linux/version.h>
  40. #include <linux/autoconf.h>
  41. #include <linux/errno.h>
  42. #include <linux/signal.h>
  43. #include <linux/sched.h>
  44. #include <linux/timer.h>
  45. #include <linux/interrupt.h>
  46. #include <linux/tty.h>
  47. #include <linux/tty_flip.h>
  48. #include <linux/serial.h>
  49. #include <linux/serial_reg.h>
  50. #include <linux/major.h>
  51. #include <linux/string.h>
  52. #include <linux/fcntl.h>
  53. #include <linux/ptrace.h>
  54. #include <linux/gfp.h>
  55. #include <linux/ioport.h>
  56. #include <linux/mm.h>
  57. #include <linux/smp_lock.h>
  58. #include <linux/delay.h>
  59. #include <linux/pci.h>
  60. #include <asm/system.h>
  61. #include <asm/io.h>
  62. #include <asm/irq.h>
  63. #include <asm/segment.h>
  64. #include <asm/bitops.h>
  65. #include <asm/uaccess.h>
  66. #include "mxser.h"
  67. #define MXSER_VERSION "1.8"
  68. #define MXSERMAJOR 174
  69. #define MXSERCUMAJOR 175
  70. #define MXSER_EVENT_TXLOW 1
  71. #define MXSER_EVENT_HANGUP 2
  72. #define MXSER_BOARDS 4 /* Max. boards */
  73. #define MXSER_PORTS 32 /* Max. ports */
  74. #define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
  75. #define MXSER_ISR_PASS_LIMIT 256
  76. #define MXSER_ERR_IOADDR -1
  77. #define MXSER_ERR_IRQ -2
  78. #define MXSER_ERR_IRQ_CONFLIT -3
  79. #define MXSER_ERR_VECTOR -4
  80. #define SERIAL_TYPE_NORMAL 1
  81. #define SERIAL_TYPE_CALLOUT 2
  82. #define WAKEUP_CHARS 256
  83. #define UART_MCR_AFE 0x20
  84. #define UART_LSR_SPECIAL 0x1E
  85. #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|IXON|IXOFF))
  86. #define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? SA_SHIRQ : SA_INTERRUPT)
  87. #define C168_ASIC_ID 1
  88. #define C104_ASIC_ID 2
  89. #define C102_ASIC_ID 0xB
  90. #define CI132_ASIC_ID 4
  91. #define CI134_ASIC_ID 3
  92. #define CI104J_ASIC_ID 5
  93. enum {
  94. MXSER_BOARD_C168_ISA = 1,
  95. MXSER_BOARD_C104_ISA,
  96. MXSER_BOARD_CI104J,
  97. MXSER_BOARD_C168_PCI,
  98. MXSER_BOARD_C104_PCI,
  99. MXSER_BOARD_C102_ISA,
  100. MXSER_BOARD_CI132,
  101. MXSER_BOARD_CI134,
  102. MXSER_BOARD_CP132,
  103. MXSER_BOARD_CP114,
  104. MXSER_BOARD_CT114,
  105. MXSER_BOARD_CP102,
  106. MXSER_BOARD_CP104U,
  107. MXSER_BOARD_CP168U,
  108. MXSER_BOARD_CP132U,
  109. MXSER_BOARD_CP134U,
  110. MXSER_BOARD_CP104JU,
  111. MXSER_BOARD_RC7000,
  112. MXSER_BOARD_CP118U,
  113. MXSER_BOARD_CP102UL,
  114. MXSER_BOARD_CP102U,
  115. };
  116. static char *mxser_brdname[] = {
  117. "C168 series",
  118. "C104 series",
  119. "CI-104J series",
  120. "C168H/PCI series",
  121. "C104H/PCI series",
  122. "C102 series",
  123. "CI-132 series",
  124. "CI-134 series",
  125. "CP-132 series",
  126. "CP-114 series",
  127. "CT-114 series",
  128. "CP-102 series",
  129. "CP-104U series",
  130. "CP-168U series",
  131. "CP-132U series",
  132. "CP-134U series",
  133. "CP-104JU series",
  134. "Moxa UC7000 Serial",
  135. "CP-118U series",
  136. "CP-102UL series",
  137. "CP-102U series",
  138. };
  139. static int mxser_numports[] = {
  140. 8, // C168-ISA
  141. 4, // C104-ISA
  142. 4, // CI104J
  143. 8, // C168-PCI
  144. 4, // C104-PCI
  145. 2, // C102-ISA
  146. 2, // CI132
  147. 4, // CI134
  148. 2, // CP132
  149. 4, // CP114
  150. 4, // CT114
  151. 2, // CP102
  152. 4, // CP104U
  153. 8, // CP168U
  154. 2, // CP132U
  155. 4, // CP134U
  156. 4, // CP104JU
  157. 8, // RC7000
  158. 8, // CP118U
  159. 2, // CP102UL
  160. 2, // CP102U
  161. };
  162. #define UART_TYPE_NUM 2
  163. static const unsigned int Gmoxa_uart_id[UART_TYPE_NUM] = {
  164. MOXA_MUST_MU150_HWID,
  165. MOXA_MUST_MU860_HWID
  166. };
  167. // This is only for PCI
  168. #define UART_INFO_NUM 3
  169. struct mxpciuart_info {
  170. int type;
  171. int tx_fifo;
  172. int rx_fifo;
  173. int xmit_fifo_size;
  174. int rx_high_water;
  175. int rx_trigger;
  176. int rx_low_water;
  177. long max_baud;
  178. };
  179. static const struct mxpciuart_info Gpci_uart_info[UART_INFO_NUM] = {
  180. {MOXA_OTHER_UART, 16, 16, 16, 14, 14, 1, 921600L},
  181. {MOXA_MUST_MU150_HWID, 64, 64, 64, 48, 48, 16, 230400L},
  182. {MOXA_MUST_MU860_HWID, 128, 128, 128, 96, 96, 32, 921600L}
  183. };
  184. #ifdef CONFIG_PCI
  185. static struct pci_device_id mxser_pcibrds[] = {
  186. {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C168, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_C168_PCI},
  187. {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_C104_PCI},
  188. {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP132},
  189. {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP114},
  190. {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CT114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CT114},
  191. {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102},
  192. {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP104U},
  193. {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP168U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP168U},
  194. {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP132U},
  195. {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP134U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP134U},
  196. {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104JU, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP104JU},
  197. {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_RC7000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_RC7000},
  198. {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP118U},
  199. {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102UL, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102UL},
  200. {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102U},
  201. {0}
  202. };
  203. MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
  204. #endif
  205. typedef struct _moxa_pci_info {
  206. unsigned short busNum;
  207. unsigned short devNum;
  208. struct pci_dev *pdev; // add by Victor Yu. 06-23-2003
  209. } moxa_pci_info;
  210. static int ioaddr[MXSER_BOARDS] = { 0, 0, 0, 0 };
  211. static int ttymajor = MXSERMAJOR;
  212. static int calloutmajor = MXSERCUMAJOR;
  213. static int verbose = 0;
  214. /* Variables for insmod */
  215. MODULE_AUTHOR("Casper Yang");
  216. MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
  217. MODULE_PARM(ioaddr, "1-4i");
  218. MODULE_PARM(ttymajor, "i");
  219. MODULE_PARM(calloutmajor, "i");
  220. MODULE_PARM(verbose, "i");
  221. MODULE_LICENSE("GPL");
  222. struct mxser_log {
  223. int tick;
  224. unsigned long rxcnt[MXSER_PORTS];
  225. unsigned long txcnt[MXSER_PORTS];
  226. };
  227. struct mxser_mon {
  228. unsigned long rxcnt;
  229. unsigned long txcnt;
  230. unsigned long up_rxcnt;
  231. unsigned long up_txcnt;
  232. int modem_status;
  233. unsigned char hold_reason;
  234. };
  235. struct mxser_mon_ext {
  236. unsigned long rx_cnt[32];
  237. unsigned long tx_cnt[32];
  238. unsigned long up_rxcnt[32];
  239. unsigned long up_txcnt[32];
  240. int modem_status[32];
  241. long baudrate[32];
  242. int databits[32];
  243. int stopbits[32];
  244. int parity[32];
  245. int flowctrl[32];
  246. int fifo[32];
  247. int iftype[32];
  248. };
  249. struct mxser_hwconf {
  250. int board_type;
  251. int ports;
  252. int irq;
  253. int vector;
  254. int vector_mask;
  255. int uart_type;
  256. int ioaddr[MXSER_PORTS_PER_BOARD];
  257. int baud_base[MXSER_PORTS_PER_BOARD];
  258. moxa_pci_info pciInfo;
  259. int IsMoxaMustChipFlag; // add by Victor Yu. 08-30-2002
  260. int MaxCanSetBaudRate[MXSER_PORTS_PER_BOARD]; // add by Victor Yu. 09-04-2002
  261. int opmode_ioaddr[MXSER_PORTS_PER_BOARD]; // add by Victor Yu. 01-05-2004
  262. };
  263. struct mxser_struct {
  264. int port;
  265. int base; /* port base address */
  266. int irq; /* port using irq no. */
  267. int vector; /* port irq vector */
  268. int vectormask; /* port vector mask */
  269. int rx_high_water;
  270. int rx_trigger; /* Rx fifo trigger level */
  271. int rx_low_water;
  272. int baud_base; /* max. speed */
  273. int flags; /* defined in tty.h */
  274. int type; /* UART type */
  275. struct tty_struct *tty;
  276. int read_status_mask;
  277. int ignore_status_mask;
  278. int xmit_fifo_size;
  279. int custom_divisor;
  280. int x_char; /* xon/xoff character */
  281. int close_delay;
  282. unsigned short closing_wait;
  283. int IER; /* Interrupt Enable Register */
  284. int MCR; /* Modem control register */
  285. unsigned long event;
  286. int count; /* # of fd on device */
  287. int blocked_open; /* # of blocked opens */
  288. long session; /* Session of opening process */
  289. long pgrp; /* pgrp of opening process */
  290. unsigned char *xmit_buf;
  291. int xmit_head;
  292. int xmit_tail;
  293. int xmit_cnt;
  294. struct work_struct tqueue;
  295. struct termios normal_termios;
  296. struct termios callout_termios;
  297. wait_queue_head_t open_wait;
  298. wait_queue_head_t close_wait;
  299. wait_queue_head_t delta_msr_wait;
  300. struct async_icount icount; /* kernel counters for the 4 input interrupts */
  301. int timeout;
  302. int IsMoxaMustChipFlag; // add by Victor Yu. 08-30-2002
  303. int MaxCanSetBaudRate; // add by Victor Yu. 09-04-2002
  304. int opmode_ioaddr; // add by Victor Yu. 01-05-2004
  305. unsigned char stop_rx;
  306. unsigned char ldisc_stop_rx;
  307. long realbaud;
  308. struct mxser_mon mon_data;
  309. unsigned char err_shadow;
  310. spinlock_t slock;
  311. };
  312. struct mxser_mstatus {
  313. tcflag_t cflag;
  314. int cts;
  315. int dsr;
  316. int ri;
  317. int dcd;
  318. };
  319. static struct mxser_mstatus GMStatus[MXSER_PORTS];
  320. static int mxserBoardCAP[MXSER_BOARDS] = {
  321. 0, 0, 0, 0
  322. /* 0x180, 0x280, 0x200, 0x320 */
  323. };
  324. static struct tty_driver *mxvar_sdriver;
  325. static struct mxser_struct mxvar_table[MXSER_PORTS];
  326. static struct tty_struct *mxvar_tty[MXSER_PORTS + 1];
  327. static struct termios *mxvar_termios[MXSER_PORTS + 1];
  328. static struct termios *mxvar_termios_locked[MXSER_PORTS + 1];
  329. static struct mxser_log mxvar_log;
  330. static int mxvar_diagflag;
  331. static unsigned char mxser_msr[MXSER_PORTS + 1];
  332. static struct mxser_mon_ext mon_data_ext;
  333. static int mxser_set_baud_method[MXSER_PORTS + 1];
  334. static spinlock_t gm_lock;
  335. /*
  336. * This is used to figure out the divisor speeds and the timeouts
  337. */
  338. static struct mxser_hwconf mxsercfg[MXSER_BOARDS];
  339. /*
  340. * static functions:
  341. */
  342. static void mxser_getcfg(int board, struct mxser_hwconf *hwconf);
  343. static int mxser_init(void);
  344. //static void mxser_poll(unsigned long);
  345. static int mxser_get_ISA_conf(int, struct mxser_hwconf *);
  346. static int mxser_get_PCI_conf(int, int, int, struct mxser_hwconf *);
  347. static void mxser_do_softint(void *);
  348. static int mxser_open(struct tty_struct *, struct file *);
  349. static void mxser_close(struct tty_struct *, struct file *);
  350. static int mxser_write(struct tty_struct *, const unsigned char *, int);
  351. static int mxser_write_room(struct tty_struct *);
  352. static void mxser_flush_buffer(struct tty_struct *);
  353. static int mxser_chars_in_buffer(struct tty_struct *);
  354. static void mxser_flush_chars(struct tty_struct *);
  355. static void mxser_put_char(struct tty_struct *, unsigned char);
  356. static int mxser_ioctl(struct tty_struct *, struct file *, uint, ulong);
  357. static int mxser_ioctl_special(unsigned int, void __user *);
  358. static void mxser_throttle(struct tty_struct *);
  359. static void mxser_unthrottle(struct tty_struct *);
  360. static void mxser_set_termios(struct tty_struct *, struct termios *);
  361. static void mxser_stop(struct tty_struct *);
  362. static void mxser_start(struct tty_struct *);
  363. static void mxser_hangup(struct tty_struct *);
  364. static void mxser_rs_break(struct tty_struct *, int);
  365. static irqreturn_t mxser_interrupt(int, void *, struct pt_regs *);
  366. static void mxser_receive_chars(struct mxser_struct *, int *);
  367. static void mxser_transmit_chars(struct mxser_struct *);
  368. static void mxser_check_modem_status(struct mxser_struct *, int);
  369. static int mxser_block_til_ready(struct tty_struct *, struct file *, struct mxser_struct *);
  370. static int mxser_startup(struct mxser_struct *);
  371. static void mxser_shutdown(struct mxser_struct *);
  372. static int mxser_change_speed(struct mxser_struct *, struct termios *old_termios);
  373. static int mxser_get_serial_info(struct mxser_struct *, struct serial_struct __user *);
  374. static int mxser_set_serial_info(struct mxser_struct *, struct serial_struct __user *);
  375. static int mxser_get_lsr_info(struct mxser_struct *, unsigned int __user *);
  376. static void mxser_send_break(struct mxser_struct *, int);
  377. static int mxser_tiocmget(struct tty_struct *, struct file *);
  378. static int mxser_tiocmset(struct tty_struct *, struct file *, unsigned int, unsigned int);
  379. static int mxser_set_baud(struct mxser_struct *info, long newspd);
  380. static void mxser_wait_until_sent(struct tty_struct *tty, int timeout);
  381. static void mxser_startrx(struct tty_struct *tty);
  382. static void mxser_stoprx(struct tty_struct *tty);
  383. static int CheckIsMoxaMust(int io)
  384. {
  385. u8 oldmcr, hwid;
  386. int i;
  387. outb(0, io + UART_LCR);
  388. DISABLE_MOXA_MUST_ENCHANCE_MODE(io);
  389. oldmcr = inb(io + UART_MCR);
  390. outb(0, io + UART_MCR);
  391. SET_MOXA_MUST_XON1_VALUE(io, 0x11);
  392. if ((hwid = inb(io + UART_MCR)) != 0) {
  393. outb(oldmcr, io + UART_MCR);
  394. return (MOXA_OTHER_UART);
  395. }
  396. GET_MOXA_MUST_HARDWARE_ID(io, &hwid);
  397. for (i = 0; i < UART_TYPE_NUM; i++) {
  398. if (hwid == Gmoxa_uart_id[i])
  399. return (int) hwid;
  400. }
  401. return MOXA_OTHER_UART;
  402. }
  403. // above is modified by Victor Yu. 08-15-2002
  404. static struct tty_operations mxser_ops = {
  405. .open = mxser_open,
  406. .close = mxser_close,
  407. .write = mxser_write,
  408. .put_char = mxser_put_char,
  409. .flush_chars = mxser_flush_chars,
  410. .write_room = mxser_write_room,
  411. .chars_in_buffer = mxser_chars_in_buffer,
  412. .flush_buffer = mxser_flush_buffer,
  413. .ioctl = mxser_ioctl,
  414. .throttle = mxser_throttle,
  415. .unthrottle = mxser_unthrottle,
  416. .set_termios = mxser_set_termios,
  417. .stop = mxser_stop,
  418. .start = mxser_start,
  419. .hangup = mxser_hangup,
  420. .tiocmget = mxser_tiocmget,
  421. .tiocmset = mxser_tiocmset,
  422. };
  423. /*
  424. * The MOXA Smartio/Industio serial driver boot-time initialization code!
  425. */
  426. static int __init mxser_module_init(void)
  427. {
  428. int ret;
  429. if (verbose)
  430. printk(KERN_DEBUG "Loading module mxser ...\n");
  431. ret = mxser_init();
  432. if (verbose)
  433. printk(KERN_DEBUG "Done.\n");
  434. return ret;
  435. }
  436. static void __exit mxser_module_exit(void)
  437. {
  438. int i, err = 0;
  439. if (verbose)
  440. printk(KERN_DEBUG "Unloading module mxser ...\n");
  441. if ((err |= tty_unregister_driver(mxvar_sdriver)))
  442. printk(KERN_ERR "Couldn't unregister MOXA Smartio/Industio family serial driver\n");
  443. for (i = 0; i < MXSER_BOARDS; i++) {
  444. struct pci_dev *pdev;
  445. if (mxsercfg[i].board_type == -1)
  446. continue;
  447. else {
  448. pdev = mxsercfg[i].pciInfo.pdev;
  449. free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
  450. if (pdev != NULL) { //PCI
  451. release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2));
  452. release_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3));
  453. } else {
  454. release_region(mxsercfg[i].ioaddr[0], 8 * mxsercfg[i].ports);
  455. release_region(mxsercfg[i].vector, 1);
  456. }
  457. }
  458. }
  459. if (verbose)
  460. printk(KERN_DEBUG "Done.\n");
  461. }
  462. static void process_txrx_fifo(struct mxser_struct *info)
  463. {
  464. int i;
  465. if ((info->type == PORT_16450) || (info->type == PORT_8250)) {
  466. info->rx_trigger = 1;
  467. info->rx_high_water = 1;
  468. info->rx_low_water = 1;
  469. info->xmit_fifo_size = 1;
  470. } else {
  471. for (i = 0; i < UART_INFO_NUM; i++) {
  472. if (info->IsMoxaMustChipFlag == Gpci_uart_info[i].type) {
  473. info->rx_trigger = Gpci_uart_info[i].rx_trigger;
  474. info->rx_low_water = Gpci_uart_info[i].rx_low_water;
  475. info->rx_high_water = Gpci_uart_info[i].rx_high_water;
  476. info->xmit_fifo_size = Gpci_uart_info[i].xmit_fifo_size;
  477. break;
  478. }
  479. }
  480. }
  481. }
  482. static int mxser_initbrd(int board, struct mxser_hwconf *hwconf)
  483. {
  484. struct mxser_struct *info;
  485. int retval;
  486. int i, n;
  487. n = board * MXSER_PORTS_PER_BOARD;
  488. info = &mxvar_table[n];
  489. /*if (verbose) */ {
  490. printk(KERN_DEBUG " ttyM%d - ttyM%d ", n, n + hwconf->ports - 1);
  491. printk(" max. baud rate = %d bps.\n", hwconf->MaxCanSetBaudRate[0]);
  492. }
  493. for (i = 0; i < hwconf->ports; i++, n++, info++) {
  494. info->port = n;
  495. info->base = hwconf->ioaddr[i];
  496. info->irq = hwconf->irq;
  497. info->vector = hwconf->vector;
  498. info->vectormask = hwconf->vector_mask;
  499. info->opmode_ioaddr = hwconf->opmode_ioaddr[i]; // add by Victor Yu. 01-05-2004
  500. info->stop_rx = 0;
  501. info->ldisc_stop_rx = 0;
  502. info->IsMoxaMustChipFlag = hwconf->IsMoxaMustChipFlag;
  503. //Enhance mode enabled here
  504. if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
  505. ENABLE_MOXA_MUST_ENCHANCE_MODE(info->base);
  506. }
  507. info->flags = ASYNC_SHARE_IRQ;
  508. info->type = hwconf->uart_type;
  509. info->baud_base = hwconf->baud_base[i];
  510. info->MaxCanSetBaudRate = hwconf->MaxCanSetBaudRate[i];
  511. process_txrx_fifo(info);
  512. info->custom_divisor = hwconf->baud_base[i] * 16;
  513. info->close_delay = 5 * HZ / 10;
  514. info->closing_wait = 30 * HZ;
  515. INIT_WORK(&info->tqueue, mxser_do_softint, info);
  516. info->normal_termios = mxvar_sdriver->init_termios;
  517. init_waitqueue_head(&info->open_wait);
  518. init_waitqueue_head(&info->close_wait);
  519. init_waitqueue_head(&info->delta_msr_wait);
  520. memset(&info->mon_data, 0, sizeof(struct mxser_mon));
  521. info->err_shadow = 0;
  522. spin_lock_init(&info->slock);
  523. }
  524. /*
  525. * Allocate the IRQ if necessary
  526. */
  527. /* before set INT ISR, disable all int */
  528. for (i = 0; i < hwconf->ports; i++) {
  529. outb(inb(hwconf->ioaddr[i] + UART_IER) & 0xf0, hwconf->ioaddr[i] + UART_IER);
  530. }
  531. n = board * MXSER_PORTS_PER_BOARD;
  532. info = &mxvar_table[n];
  533. retval = request_irq(hwconf->irq, mxser_interrupt, IRQ_T(info), "mxser", info);
  534. if (retval) {
  535. printk(KERN_ERR "Board %d: %s", board, mxser_brdname[hwconf->board_type - 1]);
  536. printk(" Request irq fail,IRQ (%d) may be conflit with another device.\n", info->irq);
  537. return retval;
  538. }
  539. return 0;
  540. }
  541. static void mxser_getcfg(int board, struct mxser_hwconf *hwconf)
  542. {
  543. mxsercfg[board] = *hwconf;
  544. }
  545. #ifdef CONFIG_PCI
  546. static int mxser_get_PCI_conf(int busnum, int devnum, int board_type, struct mxser_hwconf *hwconf)
  547. {
  548. int i, j;
  549. // unsigned int val;
  550. unsigned int ioaddress;
  551. struct pci_dev *pdev = hwconf->pciInfo.pdev;
  552. //io address
  553. hwconf->board_type = board_type;
  554. hwconf->ports = mxser_numports[board_type - 1];
  555. ioaddress = pci_resource_start(pdev, 2);
  556. request_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2), "mxser(IO)");
  557. for (i = 0; i < hwconf->ports; i++) {
  558. hwconf->ioaddr[i] = ioaddress + 8 * i;
  559. }
  560. //vector
  561. ioaddress = pci_resource_start(pdev, 3);
  562. request_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3), "mxser(vector)");
  563. hwconf->vector = ioaddress;
  564. //irq
  565. hwconf->irq = hwconf->pciInfo.pdev->irq;
  566. hwconf->IsMoxaMustChipFlag = CheckIsMoxaMust(hwconf->ioaddr[0]);
  567. hwconf->uart_type = PORT_16550A;
  568. hwconf->vector_mask = 0;
  569. for (i = 0; i < hwconf->ports; i++) {
  570. for (j = 0; j < UART_INFO_NUM; j++) {
  571. if (Gpci_uart_info[j].type == hwconf->IsMoxaMustChipFlag) {
  572. hwconf->MaxCanSetBaudRate[i] = Gpci_uart_info[j].max_baud;
  573. //exception....CP-102
  574. if (board_type == MXSER_BOARD_CP102)
  575. hwconf->MaxCanSetBaudRate[i] = 921600;
  576. break;
  577. }
  578. }
  579. }
  580. if (hwconf->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID) {
  581. for (i = 0; i < hwconf->ports; i++) {
  582. if (i < 4)
  583. hwconf->opmode_ioaddr[i] = ioaddress + 4;
  584. else
  585. hwconf->opmode_ioaddr[i] = ioaddress + 0x0c;
  586. }
  587. outb(0, ioaddress + 4); // default set to RS232 mode
  588. outb(0, ioaddress + 0x0c); //default set to RS232 mode
  589. }
  590. for (i = 0; i < hwconf->ports; i++) {
  591. hwconf->vector_mask |= (1 << i);
  592. hwconf->baud_base[i] = 921600;
  593. }
  594. return (0);
  595. }
  596. #endif
  597. static int mxser_init(void)
  598. {
  599. int i, m, retval, b, n;
  600. int ret1;
  601. struct pci_dev *pdev = NULL;
  602. int index;
  603. unsigned char busnum, devnum;
  604. struct mxser_hwconf hwconf;
  605. mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1);
  606. if (!mxvar_sdriver)
  607. return -ENOMEM;
  608. spin_lock_init(&gm_lock);
  609. for (i = 0; i < MXSER_BOARDS; i++) {
  610. mxsercfg[i].board_type = -1;
  611. }
  612. printk(KERN_INFO "MOXA Smartio/Industio family driver version %s\n", MXSER_VERSION);
  613. /* Initialize the tty_driver structure */
  614. memset(mxvar_sdriver, 0, sizeof(struct tty_driver));
  615. mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
  616. mxvar_sdriver->name = "ttyM";
  617. mxvar_sdriver->major = ttymajor;
  618. mxvar_sdriver->minor_start = 0;
  619. mxvar_sdriver->num = MXSER_PORTS + 1;
  620. mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
  621. mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
  622. mxvar_sdriver->init_termios = tty_std_termios;
  623. mxvar_sdriver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  624. mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW;
  625. tty_set_operations(mxvar_sdriver, &mxser_ops);
  626. mxvar_sdriver->ttys = mxvar_tty;
  627. mxvar_sdriver->termios = mxvar_termios;
  628. mxvar_sdriver->termios_locked = mxvar_termios_locked;
  629. mxvar_sdriver->open = mxser_open;
  630. mxvar_sdriver->close = mxser_close;
  631. mxvar_sdriver->write = mxser_write;
  632. mxvar_sdriver->put_char = mxser_put_char;
  633. mxvar_sdriver->flush_chars = mxser_flush_chars;
  634. mxvar_sdriver->write_room = mxser_write_room;
  635. mxvar_sdriver->chars_in_buffer = mxser_chars_in_buffer;
  636. mxvar_sdriver->flush_buffer = mxser_flush_buffer;
  637. mxvar_sdriver->ioctl = mxser_ioctl;
  638. mxvar_sdriver->throttle = mxser_throttle;
  639. mxvar_sdriver->unthrottle = mxser_unthrottle;
  640. mxvar_sdriver->set_termios = mxser_set_termios;
  641. mxvar_sdriver->stop = mxser_stop;
  642. mxvar_sdriver->start = mxser_start;
  643. mxvar_sdriver->hangup = mxser_hangup;
  644. mxvar_sdriver->break_ctl = mxser_rs_break;
  645. mxvar_sdriver->wait_until_sent = mxser_wait_until_sent;
  646. mxvar_diagflag = 0;
  647. memset(mxvar_table, 0, MXSER_PORTS * sizeof(struct mxser_struct));
  648. memset(&mxvar_log, 0, sizeof(struct mxser_log));
  649. memset(&mxser_msr, 0, sizeof(unsigned char) * (MXSER_PORTS + 1));
  650. memset(&mon_data_ext, 0, sizeof(struct mxser_mon_ext));
  651. memset(&mxser_set_baud_method, 0, sizeof(int) * (MXSER_PORTS + 1));
  652. memset(&hwconf, 0, sizeof(struct mxser_hwconf));
  653. m = 0;
  654. /* Start finding ISA boards here */
  655. for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
  656. int cap;
  657. if (!(cap = mxserBoardCAP[b]))
  658. continue;
  659. retval = mxser_get_ISA_conf(cap, &hwconf);
  660. if (retval != 0)
  661. printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n", mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
  662. if (retval <= 0) {
  663. if (retval == MXSER_ERR_IRQ)
  664. printk(KERN_ERR "Invalid interrupt number,board not configured\n");
  665. else if (retval == MXSER_ERR_IRQ_CONFLIT)
  666. printk(KERN_ERR "Invalid interrupt number,board not configured\n");
  667. else if (retval == MXSER_ERR_VECTOR)
  668. printk(KERN_ERR "Invalid interrupt vector,board not configured\n");
  669. else if (retval == MXSER_ERR_IOADDR)
  670. printk(KERN_ERR "Invalid I/O address,board not configured\n");
  671. continue;
  672. }
  673. hwconf.pciInfo.busNum = 0;
  674. hwconf.pciInfo.devNum = 0;
  675. hwconf.pciInfo.pdev = NULL;
  676. mxser_getcfg(m, &hwconf);
  677. //init mxsercfg first, or mxsercfg data is not correct on ISR.
  678. //mxser_initbrd will hook ISR.
  679. if (mxser_initbrd(m, &hwconf) < 0)
  680. continue;
  681. m++;
  682. }
  683. /* Start finding ISA boards from module arg */
  684. for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
  685. int cap;
  686. if (!(cap = ioaddr[b]))
  687. continue;
  688. retval = mxser_get_ISA_conf(cap, &hwconf);
  689. if (retval != 0)
  690. printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n", mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
  691. if (retval <= 0) {
  692. if (retval == MXSER_ERR_IRQ)
  693. printk(KERN_ERR "Invalid interrupt number,board not configured\n");
  694. else if (retval == MXSER_ERR_IRQ_CONFLIT)
  695. printk(KERN_ERR "Invalid interrupt number,board not configured\n");
  696. else if (retval == MXSER_ERR_VECTOR)
  697. printk(KERN_ERR "Invalid interrupt vector,board not configured\n");
  698. else if (retval == MXSER_ERR_IOADDR)
  699. printk(KERN_ERR "Invalid I/O address,board not configured\n");
  700. continue;
  701. }
  702. hwconf.pciInfo.busNum = 0;
  703. hwconf.pciInfo.devNum = 0;
  704. hwconf.pciInfo.pdev = NULL;
  705. mxser_getcfg(m, &hwconf);
  706. //init mxsercfg first, or mxsercfg data is not correct on ISR.
  707. //mxser_initbrd will hook ISR.
  708. if (mxser_initbrd(m, &hwconf) < 0)
  709. continue;
  710. m++;
  711. }
  712. /* start finding PCI board here */
  713. #ifdef CONFIG_PCI
  714. n = (sizeof(mxser_pcibrds) / sizeof(mxser_pcibrds[0])) - 1;
  715. index = 0;
  716. b = 0;
  717. while (b < n) {
  718. pdev = pci_find_device(mxser_pcibrds[b].vendor, mxser_pcibrds[b].device, pdev);
  719. if (pdev == NULL) {
  720. b++;
  721. continue;
  722. }
  723. hwconf.pciInfo.busNum = busnum = pdev->bus->number;
  724. hwconf.pciInfo.devNum = devnum = PCI_SLOT(pdev->devfn) << 3;
  725. hwconf.pciInfo.pdev = pdev;
  726. printk(KERN_INFO "Found MOXA %s board(BusNo=%d,DevNo=%d)\n", mxser_brdname[(int) (mxser_pcibrds[b].driver_data) - 1], busnum, devnum >> 3);
  727. index++;
  728. if (m >= MXSER_BOARDS) {
  729. printk(KERN_ERR "Too many Smartio/Industio family boards find (maximum %d),board not configured\n", MXSER_BOARDS);
  730. } else {
  731. if (pci_enable_device(pdev)) {
  732. printk(KERN_ERR "Moxa SmartI/O PCI enable fail !\n");
  733. continue;
  734. }
  735. retval = mxser_get_PCI_conf(busnum, devnum, (int) mxser_pcibrds[b].driver_data, &hwconf);
  736. if (retval < 0) {
  737. if (retval == MXSER_ERR_IRQ)
  738. printk(KERN_ERR "Invalid interrupt number,board not configured\n");
  739. else if (retval == MXSER_ERR_IRQ_CONFLIT)
  740. printk(KERN_ERR "Invalid interrupt number,board not configured\n");
  741. else if (retval == MXSER_ERR_VECTOR)
  742. printk(KERN_ERR "Invalid interrupt vector,board not configured\n");
  743. else if (retval == MXSER_ERR_IOADDR)
  744. printk(KERN_ERR "Invalid I/O address,board not configured\n");
  745. continue;
  746. }
  747. mxser_getcfg(m, &hwconf);
  748. //init mxsercfg first, or mxsercfg data is not correct on ISR.
  749. //mxser_initbrd will hook ISR.
  750. if (mxser_initbrd(m, &hwconf) < 0)
  751. continue;
  752. m++;
  753. }
  754. }
  755. #endif
  756. ret1 = 0;
  757. if (!(ret1 = tty_register_driver(mxvar_sdriver))) {
  758. return 0;
  759. } else
  760. printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family driver !\n");
  761. if (ret1) {
  762. for (i = 0; i < MXSER_BOARDS; i++) {
  763. if (mxsercfg[i].board_type == -1)
  764. continue;
  765. else {
  766. free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
  767. //todo: release io, vector
  768. }
  769. }
  770. return -1;
  771. }
  772. return (0);
  773. }
  774. static void mxser_do_softint(void *private_)
  775. {
  776. struct mxser_struct *info = (struct mxser_struct *) private_;
  777. struct tty_struct *tty;
  778. tty = info->tty;
  779. if (tty) {
  780. if (test_and_clear_bit(MXSER_EVENT_TXLOW, &info->event))
  781. tty_wakeup(tty);
  782. if (test_and_clear_bit(MXSER_EVENT_HANGUP, &info->event))
  783. tty_hangup(tty);
  784. }
  785. }
  786. static unsigned char mxser_get_msr(int baseaddr, int mode, int port, struct mxser_struct *info)
  787. {
  788. unsigned char status = 0;
  789. status = inb(baseaddr + UART_MSR);
  790. mxser_msr[port] &= 0x0F;
  791. mxser_msr[port] |= status;
  792. status = mxser_msr[port];
  793. if (mode)
  794. mxser_msr[port] = 0;
  795. return status;
  796. }
  797. /*
  798. * This routine is called whenever a serial port is opened. It
  799. * enables interrupts for a serial port, linking in its async structure into
  800. * the IRQ chain. It also performs the serial-specific
  801. * initialization for the tty structure.
  802. */
  803. static int mxser_open(struct tty_struct *tty, struct file *filp)
  804. {
  805. struct mxser_struct *info;
  806. int retval, line;
  807. line = tty->index;
  808. if (line == MXSER_PORTS)
  809. return 0;
  810. if (line < 0 || line > MXSER_PORTS)
  811. return -ENODEV;
  812. info = mxvar_table + line;
  813. if (!info->base)
  814. return (-ENODEV);
  815. tty->driver_data = info;
  816. info->tty = tty;
  817. /*
  818. * Start up serial port
  819. */
  820. retval = mxser_startup(info);
  821. if (retval)
  822. return (retval);
  823. retval = mxser_block_til_ready(tty, filp, info);
  824. if (retval)
  825. return (retval);
  826. info->count++;
  827. if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
  828. if (tty->driver->subtype == SERIAL_TYPE_NORMAL)
  829. *tty->termios = info->normal_termios;
  830. else
  831. *tty->termios = info->callout_termios;
  832. mxser_change_speed(info, NULL);
  833. }
  834. info->session = current->signal->session;
  835. info->pgrp = process_group(current);
  836. clear_bit(TTY_DONT_FLIP, &tty->flags);
  837. //status = mxser_get_msr(info->base, 0, info->port);
  838. //mxser_check_modem_status(info, status);
  839. /* unmark here for very high baud rate (ex. 921600 bps) used
  840. */
  841. tty->low_latency = 1;
  842. return 0;
  843. }
  844. /*
  845. * This routine is called when the serial port gets closed. First, we
  846. * wait for the last remaining data to be sent. Then, we unlink its
  847. * async structure from the interrupt chain if necessary, and we free
  848. * that IRQ if nothing is left in the chain.
  849. */
  850. static void mxser_close(struct tty_struct *tty, struct file *filp)
  851. {
  852. struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
  853. unsigned long timeout;
  854. unsigned long flags;
  855. struct tty_ldisc *ld;
  856. if (tty->index == MXSER_PORTS)
  857. return;
  858. if (!info)
  859. BUG();
  860. spin_lock_irqsave(&info->slock, flags);
  861. if (tty_hung_up_p(filp)) {
  862. spin_unlock_irqrestore(&info->slock, flags);
  863. return;
  864. }
  865. if ((tty->count == 1) && (info->count != 1)) {
  866. /*
  867. * Uh, oh. tty->count is 1, which means that the tty
  868. * structure will be freed. Info->count should always
  869. * be one in these conditions. If it's greater than
  870. * one, we've got real problems, since it means the
  871. * serial port won't be shutdown.
  872. */
  873. printk(KERN_ERR "mxser_close: bad serial port count; tty->count is 1, " "info->count is %d\n", info->count);
  874. info->count = 1;
  875. }
  876. if (--info->count < 0) {
  877. printk(KERN_ERR "mxser_close: bad serial port count for ttys%d: %d\n", info->port, info->count);
  878. info->count = 0;
  879. }
  880. if (info->count) {
  881. spin_unlock_irqrestore(&info->slock, flags);
  882. return;
  883. }
  884. info->flags |= ASYNC_CLOSING;
  885. spin_unlock_irqrestore(&info->slock, flags);
  886. /*
  887. * Save the termios structure, since this port may have
  888. * separate termios for callout and dialin.
  889. */
  890. if (info->flags & ASYNC_NORMAL_ACTIVE)
  891. info->normal_termios = *tty->termios;
  892. /*
  893. * Now we wait for the transmit buffer to clear; and we notify
  894. * the line discipline to only process XON/XOFF characters.
  895. */
  896. tty->closing = 1;
  897. if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  898. tty_wait_until_sent(tty, info->closing_wait);
  899. /*
  900. * At this point we stop accepting input. To do this, we
  901. * disable the receive line status interrupts, and tell the
  902. * interrupt driver to stop checking the data ready bit in the
  903. * line status register.
  904. */
  905. info->IER &= ~UART_IER_RLSI;
  906. if (info->IsMoxaMustChipFlag)
  907. info->IER &= ~MOXA_MUST_RECV_ISR;
  908. /* by William
  909. info->read_status_mask &= ~UART_LSR_DR;
  910. */
  911. if (info->flags & ASYNC_INITIALIZED) {
  912. outb(info->IER, info->base + UART_IER);
  913. /*
  914. * Before we drop DTR, make sure the UART transmitter
  915. * has completely drained; this is especially
  916. * important if there is a transmit FIFO!
  917. */
  918. timeout = jiffies + HZ;
  919. while (!(inb(info->base + UART_LSR) & UART_LSR_TEMT)) {
  920. set_current_state(TASK_INTERRUPTIBLE);
  921. schedule_timeout(5);
  922. if (time_after(jiffies, timeout))
  923. break;
  924. }
  925. }
  926. mxser_shutdown(info);
  927. if (tty->driver->flush_buffer)
  928. tty->driver->flush_buffer(tty);
  929. ld = tty_ldisc_ref(tty);
  930. if (ld) {
  931. if(ld->flush_buffer)
  932. ld->flush_buffer(tty);
  933. tty_ldisc_deref(ld);
  934. }
  935. tty->closing = 0;
  936. info->event = 0;
  937. info->tty = NULL;
  938. if (info->blocked_open) {
  939. if (info->close_delay) {
  940. set_current_state(TASK_INTERRUPTIBLE);
  941. schedule_timeout(info->close_delay);
  942. }
  943. wake_up_interruptible(&info->open_wait);
  944. }
  945. info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
  946. wake_up_interruptible(&info->close_wait);
  947. }
  948. static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
  949. {
  950. int c, total = 0;
  951. struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
  952. unsigned long flags;
  953. if (!tty || !info->xmit_buf)
  954. return (0);
  955. while (1) {
  956. c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1, SERIAL_XMIT_SIZE - info->xmit_head));
  957. if (c <= 0)
  958. break;
  959. memcpy(info->xmit_buf + info->xmit_head, buf, c);
  960. spin_lock_irqsave(&info->slock, flags);
  961. info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE - 1);
  962. info->xmit_cnt += c;
  963. spin_unlock_irqrestore(&info->slock, flags);
  964. buf += c;
  965. count -= c;
  966. total += c;
  967. }
  968. if (info->xmit_cnt && !tty->stopped && !(info->IER & UART_IER_THRI)) {
  969. if (!tty->hw_stopped || (info->type == PORT_16550A) || (info->IsMoxaMustChipFlag)) {
  970. spin_lock_irqsave(&info->slock, flags);
  971. info->IER |= UART_IER_THRI;
  972. outb(info->IER, info->base + UART_IER);
  973. spin_unlock_irqrestore(&info->slock, flags);
  974. }
  975. }
  976. return total;
  977. }
  978. static void mxser_put_char(struct tty_struct *tty, unsigned char ch)
  979. {
  980. struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
  981. unsigned long flags;
  982. if (!tty || !info->xmit_buf)
  983. return;
  984. if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
  985. return;
  986. spin_lock_irqsave(&info->slock, flags);
  987. info->xmit_buf[info->xmit_head++] = ch;
  988. info->xmit_head &= SERIAL_XMIT_SIZE - 1;
  989. info->xmit_cnt++;
  990. spin_unlock_irqrestore(&info->slock, flags);
  991. if (!tty->stopped && !(info->IER & UART_IER_THRI)) {
  992. if (!tty->hw_stopped || (info->type == PORT_16550A) || info->IsMoxaMustChipFlag) {
  993. spin_lock_irqsave(&info->slock, flags);
  994. info->IER |= UART_IER_THRI;
  995. outb(info->IER, info->base + UART_IER);
  996. spin_unlock_irqrestore(&info->slock, flags);
  997. }
  998. }
  999. }
  1000. static void mxser_flush_chars(struct tty_struct *tty)
  1001. {
  1002. struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
  1003. unsigned long flags;
  1004. if (info->xmit_cnt <= 0 || tty->stopped || !info->xmit_buf || (tty->hw_stopped && (info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)))
  1005. return;
  1006. spin_lock_irqsave(&info->slock, flags);
  1007. info->IER |= UART_IER_THRI;
  1008. outb(info->IER, info->base + UART_IER);
  1009. spin_unlock_irqrestore(&info->slock, flags);
  1010. }
  1011. static int mxser_write_room(struct tty_struct *tty)
  1012. {
  1013. struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
  1014. int ret;
  1015. ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
  1016. if (ret < 0)
  1017. ret = 0;
  1018. return (ret);
  1019. }
  1020. static int mxser_chars_in_buffer(struct tty_struct *tty)
  1021. {
  1022. struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
  1023. return info->xmit_cnt;
  1024. }
  1025. static void mxser_flush_buffer(struct tty_struct *tty)
  1026. {
  1027. struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
  1028. char fcr;
  1029. unsigned long flags;
  1030. spin_lock_irqsave(&info->slock, flags);
  1031. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  1032. /* below added by shinhay */
  1033. fcr = inb(info->base + UART_FCR);
  1034. outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT), info->base + UART_FCR);
  1035. outb(fcr, info->base + UART_FCR);
  1036. spin_unlock_irqrestore(&info->slock, flags);
  1037. /* above added by shinhay */
  1038. wake_up_interruptible(&tty->write_wait);
  1039. if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
  1040. (tty->ldisc.write_wakeup) (tty);
  1041. }
  1042. static int mxser_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
  1043. {
  1044. struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
  1045. int retval;
  1046. struct async_icount cprev, cnow; /* kernel counter temps */
  1047. struct serial_icounter_struct __user *p_cuser;
  1048. unsigned long templ;
  1049. unsigned long flags;
  1050. void __user *argp = (void __user *)arg;
  1051. if (tty->index == MXSER_PORTS)
  1052. return (mxser_ioctl_special(cmd, argp));
  1053. // following add by Victor Yu. 01-05-2004
  1054. if (cmd == MOXA_SET_OP_MODE || cmd == MOXA_GET_OP_MODE) {
  1055. int opmode, p;
  1056. static unsigned char ModeMask[] = { 0xfc, 0xf3, 0xcf, 0x3f };
  1057. int shiftbit;
  1058. unsigned char val, mask;
  1059. p = info->port % 4;
  1060. if (cmd == MOXA_SET_OP_MODE) {
  1061. if (get_user(opmode, (int __user *) argp))
  1062. return -EFAULT;
  1063. if (opmode != RS232_MODE && opmode != RS485_2WIRE_MODE && opmode != RS422_MODE && opmode != RS485_4WIRE_MODE)
  1064. return -EFAULT;
  1065. mask = ModeMask[p];
  1066. shiftbit = p * 2;
  1067. val = inb(info->opmode_ioaddr);
  1068. val &= mask;
  1069. val |= (opmode << shiftbit);
  1070. outb(val, info->opmode_ioaddr);
  1071. } else {
  1072. shiftbit = p * 2;
  1073. opmode = inb(info->opmode_ioaddr) >> shiftbit;
  1074. opmode &= OP_MODE_MASK;
  1075. if (copy_to_user(argp, &opmode, sizeof(int)))
  1076. return -EFAULT;
  1077. }
  1078. return 0;
  1079. }
  1080. // above add by Victor Yu. 01-05-2004
  1081. if ((cmd != TIOCGSERIAL) && (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
  1082. if (tty->flags & (1 << TTY_IO_ERROR))
  1083. return (-EIO);
  1084. }
  1085. switch (cmd) {
  1086. case TCSBRK: /* SVID version: non-zero arg --> no break */
  1087. retval = tty_check_change(tty);
  1088. if (retval)
  1089. return (retval);
  1090. tty_wait_until_sent(tty, 0);
  1091. if (!arg)
  1092. mxser_send_break(info, HZ / 4); /* 1/4 second */
  1093. return (0);
  1094. case TCSBRKP: /* support for POSIX tcsendbreak() */
  1095. retval = tty_check_change(tty);
  1096. if (retval)
  1097. return (retval);
  1098. tty_wait_until_sent(tty, 0);
  1099. mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
  1100. return (0);
  1101. case TIOCGSOFTCAR:
  1102. return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) argp);
  1103. case TIOCSSOFTCAR:
  1104. if (get_user(templ, (unsigned long __user *) argp))
  1105. return -EFAULT;
  1106. arg = templ;
  1107. tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
  1108. return (0);
  1109. case TIOCGSERIAL:
  1110. return mxser_get_serial_info(info, argp);
  1111. case TIOCSSERIAL:
  1112. return mxser_set_serial_info(info, argp);
  1113. case TIOCSERGETLSR: /* Get line status register */
  1114. return mxser_get_lsr_info(info, argp);
  1115. /*
  1116. * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
  1117. * - mask passed in arg for lines of interest
  1118. * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
  1119. * Caller should use TIOCGICOUNT to see which one it was
  1120. */
  1121. case TIOCMIWAIT:{
  1122. DECLARE_WAITQUEUE(wait, current);
  1123. int ret;
  1124. spin_lock_irqsave(&info->slock, flags);
  1125. cprev = info->icount; /* note the counters on entry */
  1126. spin_unlock_irqrestore(&info->slock, flags);
  1127. add_wait_queue(&info->delta_msr_wait, &wait);
  1128. while (1) {
  1129. spin_lock_irqsave(&info->slock, flags);
  1130. cnow = info->icount; /* atomic copy */
  1131. spin_unlock_irqrestore(&info->slock, flags);
  1132. set_current_state(TASK_INTERRUPTIBLE);
  1133. if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
  1134. ret = 0;
  1135. break;
  1136. }
  1137. /* see if a signal did it */
  1138. if (signal_pending(current)) {
  1139. ret = -ERESTARTSYS;
  1140. break;
  1141. }
  1142. cprev = cnow;
  1143. }
  1144. current->state = TASK_RUNNING;
  1145. remove_wait_queue(&info->delta_msr_wait, &wait);
  1146. break;
  1147. }
  1148. /* NOTREACHED */
  1149. /*
  1150. * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
  1151. * Return: write counters to the user passed counter struct
  1152. * NB: both 1->0 and 0->1 transitions are counted except for
  1153. * RI where only 0->1 is counted.
  1154. */
  1155. case TIOCGICOUNT:
  1156. spin_lock_irqsave(&info->slock, flags);
  1157. cnow = info->icount;
  1158. spin_unlock_irqrestore(&info->slock, flags);
  1159. p_cuser = argp;
  1160. /* modified by casper 1/11/2000 */
  1161. if (put_user(cnow.frame, &p_cuser->frame))
  1162. return -EFAULT;
  1163. if (put_user(cnow.brk, &p_cuser->brk))
  1164. return -EFAULT;
  1165. if (put_user(cnow.overrun, &p_cuser->overrun))
  1166. return -EFAULT;
  1167. if (put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
  1168. return -EFAULT;
  1169. if (put_user(cnow.parity, &p_cuser->parity))
  1170. return -EFAULT;
  1171. if (put_user(cnow.rx, &p_cuser->rx))
  1172. return -EFAULT;
  1173. if (put_user(cnow.tx, &p_cuser->tx))
  1174. return -EFAULT;
  1175. put_user(cnow.cts, &p_cuser->cts);
  1176. put_user(cnow.dsr, &p_cuser->dsr);
  1177. put_user(cnow.rng, &p_cuser->rng);
  1178. put_user(cnow.dcd, &p_cuser->dcd);
  1179. /* */
  1180. return 0;
  1181. case MOXA_HighSpeedOn:
  1182. return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *) argp);
  1183. case MOXA_SDS_RSTICOUNTER:{
  1184. info->mon_data.rxcnt = 0;
  1185. info->mon_data.txcnt = 0;
  1186. return 0;
  1187. }
  1188. // (above) added by James.
  1189. case MOXA_ASPP_SETBAUD:{
  1190. long baud;
  1191. if (get_user(baud, (long __user *) argp))
  1192. return -EFAULT;
  1193. mxser_set_baud(info, baud);
  1194. return 0;
  1195. }
  1196. case MOXA_ASPP_GETBAUD:
  1197. if (copy_to_user(argp, &info->realbaud, sizeof(long)))
  1198. return -EFAULT;
  1199. return 0;
  1200. case MOXA_ASPP_OQUEUE:{
  1201. int len, lsr;
  1202. len = mxser_chars_in_buffer(tty);
  1203. lsr = inb(info->base + UART_LSR) & UART_LSR_TEMT;
  1204. len += (lsr ? 0 : 1);
  1205. if (copy_to_user(argp, &len, sizeof(int)))
  1206. return -EFAULT;
  1207. return 0;
  1208. }
  1209. case MOXA_ASPP_MON:{
  1210. int mcr, status;
  1211. // info->mon_data.ser_param = tty->termios->c_cflag;
  1212. status = mxser_get_msr(info->base, 1, info->port, info);
  1213. mxser_check_modem_status(info, status);
  1214. mcr = inb(info->base + UART_MCR);
  1215. if (mcr & MOXA_MUST_MCR_XON_FLAG)
  1216. info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFHOLD;
  1217. else
  1218. info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFHOLD;
  1219. if (mcr & MOXA_MUST_MCR_TX_XON)
  1220. info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFXENT;
  1221. else
  1222. info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFXENT;
  1223. if (info->tty->hw_stopped)
  1224. info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD;
  1225. else
  1226. info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD;
  1227. if (copy_to_user(argp, &info->mon_data, sizeof(struct mxser_mon)))
  1228. return -EFAULT;
  1229. return 0;
  1230. }
  1231. case MOXA_ASPP_LSTATUS:{
  1232. if (copy_to_user(argp, &info->err_shadow, sizeof(unsigned char)))
  1233. return -EFAULT;
  1234. info->err_shadow = 0;
  1235. return 0;
  1236. }
  1237. case MOXA_SET_BAUD_METHOD:{
  1238. int method;
  1239. if (get_user(method, (int __user *) argp))
  1240. return -EFAULT;
  1241. mxser_set_baud_method[info->port] = method;
  1242. if (copy_to_user(argp, &method, sizeof(int)))
  1243. return -EFAULT;
  1244. return 0;
  1245. }
  1246. default:
  1247. return -ENOIOCTLCMD;
  1248. }
  1249. return 0;
  1250. }
  1251. #ifndef CMSPAR
  1252. #define CMSPAR 010000000000
  1253. #endif
  1254. static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
  1255. {
  1256. int i, result, status;
  1257. switch (cmd) {
  1258. case MOXA_GET_CONF:
  1259. if (copy_to_user(argp, mxsercfg, sizeof(struct mxser_hwconf) * 4))
  1260. return -EFAULT;
  1261. return 0;
  1262. case MOXA_GET_MAJOR:
  1263. if (copy_to_user(argp, &ttymajor, sizeof(int)))
  1264. return -EFAULT;
  1265. return 0;
  1266. case MOXA_GET_CUMAJOR:
  1267. if (copy_to_user(argp, &calloutmajor, sizeof(int)))
  1268. return -EFAULT;
  1269. return 0;
  1270. case MOXA_CHKPORTENABLE:
  1271. result = 0;
  1272. for (i = 0; i < MXSER_PORTS; i++) {
  1273. if (mxvar_table[i].base)
  1274. result |= (1 << i);
  1275. }
  1276. return put_user(result, (unsigned long __user *) argp);
  1277. case MOXA_GETDATACOUNT:
  1278. if (copy_to_user(argp, &mxvar_log, sizeof(mxvar_log)))
  1279. return -EFAULT;
  1280. return (0);
  1281. case MOXA_GETMSTATUS:
  1282. for (i = 0; i < MXSER_PORTS; i++) {
  1283. GMStatus[i].ri = 0;
  1284. if (!mxvar_table[i].base) {
  1285. GMStatus[i].dcd = 0;
  1286. GMStatus[i].dsr = 0;
  1287. GMStatus[i].cts = 0;
  1288. continue;
  1289. }
  1290. if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios)
  1291. GMStatus[i].cflag = mxvar_table[i].normal_termios.c_cflag;
  1292. else
  1293. GMStatus[i].cflag = mxvar_table[i].tty->termios->c_cflag;
  1294. status = inb(mxvar_table[i].base + UART_MSR);
  1295. if (status & 0x80 /*UART_MSR_DCD */ )
  1296. GMStatus[i].dcd = 1;
  1297. else
  1298. GMStatus[i].dcd = 0;
  1299. if (status & 0x20 /*UART_MSR_DSR */ )
  1300. GMStatus[i].dsr = 1;
  1301. else
  1302. GMStatus[i].dsr = 0;
  1303. if (status & 0x10 /*UART_MSR_CTS */ )
  1304. GMStatus[i].cts = 1;
  1305. else
  1306. GMStatus[i].cts = 0;
  1307. }
  1308. if (copy_to_user(argp, GMStatus, sizeof(struct mxser_mstatus) * MXSER_PORTS))
  1309. return -EFAULT;
  1310. return 0;
  1311. case MOXA_ASPP_MON_EXT:{
  1312. int status;
  1313. int opmode, p;
  1314. int shiftbit;
  1315. unsigned cflag, iflag;
  1316. for (i = 0; i < MXSER_PORTS; i++) {
  1317. if (!mxvar_table[i].base)
  1318. continue;
  1319. status = mxser_get_msr(mxvar_table[i].base, 0, i, &(mxvar_table[i]));
  1320. // mxser_check_modem_status(&mxvar_table[i], status);
  1321. if (status & UART_MSR_TERI)
  1322. mxvar_table[i].icount.rng++;
  1323. if (status & UART_MSR_DDSR)
  1324. mxvar_table[i].icount.dsr++;
  1325. if (status & UART_MSR_DDCD)
  1326. mxvar_table[i].icount.dcd++;
  1327. if (status & UART_MSR_DCTS)
  1328. mxvar_table[i].icount.cts++;
  1329. mxvar_table[i].mon_data.modem_status = status;
  1330. mon_data_ext.rx_cnt[i] = mxvar_table[i].mon_data.rxcnt;
  1331. mon_data_ext.tx_cnt[i] = mxvar_table[i].mon_data.txcnt;
  1332. mon_data_ext.up_rxcnt[i] = mxvar_table[i].mon_data.up_rxcnt;
  1333. mon_data_ext.up_txcnt[i] = mxvar_table[i].mon_data.up_txcnt;
  1334. mon_data_ext.modem_status[i] = mxvar_table[i].mon_data.modem_status;
  1335. mon_data_ext.baudrate[i] = mxvar_table[i].realbaud;
  1336. if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios) {
  1337. cflag = mxvar_table[i].normal_termios.c_cflag;
  1338. iflag = mxvar_table[i].normal_termios.c_iflag;
  1339. } else {
  1340. cflag = mxvar_table[i].tty->termios->c_cflag;
  1341. iflag = mxvar_table[i].tty->termios->c_iflag;
  1342. }
  1343. mon_data_ext.databits[i] = cflag & CSIZE;
  1344. mon_data_ext.stopbits[i] = cflag & CSTOPB;
  1345. mon_data_ext.parity[i] = cflag & (PARENB | PARODD | CMSPAR);
  1346. mon_data_ext.flowctrl[i] = 0x00;
  1347. if (cflag & CRTSCTS)
  1348. mon_data_ext.flowctrl[i] |= 0x03;
  1349. if (iflag & (IXON | IXOFF))
  1350. mon_data_ext.flowctrl[i] |= 0x0C;
  1351. if (mxvar_table[i].type == PORT_16550A)
  1352. mon_data_ext.fifo[i] = 1;
  1353. else
  1354. mon_data_ext.fifo[i] = 0;
  1355. p = i % 4;
  1356. shiftbit = p * 2;
  1357. opmode = inb(mxvar_table[i].opmode_ioaddr) >> shiftbit;
  1358. opmode &= OP_MODE_MASK;
  1359. mon_data_ext.iftype[i] = opmode;
  1360. }
  1361. if (copy_to_user(argp, &mon_data_ext, sizeof(struct mxser_mon_ext)))
  1362. return -EFAULT;
  1363. return 0;
  1364. }
  1365. default:
  1366. return -ENOIOCTLCMD;
  1367. }
  1368. return 0;
  1369. }
  1370. static void mxser_stoprx(struct tty_struct *tty)
  1371. {
  1372. struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
  1373. //unsigned long flags;
  1374. info->ldisc_stop_rx = 1;
  1375. if (I_IXOFF(tty)) {
  1376. //MX_LOCK(&info->slock);
  1377. // following add by Victor Yu. 09-02-2002
  1378. if (info->IsMoxaMustChipFlag) {
  1379. info->IER &= ~MOXA_MUST_RECV_ISR;
  1380. outb(info->IER, info->base + UART_IER);
  1381. } else {
  1382. // above add by Victor Yu. 09-02-2002
  1383. info->x_char = STOP_CHAR(tty);
  1384. // outb(info->IER, 0); // mask by Victor Yu. 09-02-2002
  1385. outb(0, info->base + UART_IER);
  1386. info->IER |= UART_IER_THRI;
  1387. outb(info->IER, info->base + UART_IER); /* force Tx interrupt */
  1388. } // add by Victor Yu. 09-02-2002
  1389. //MX_UNLOCK(&info->slock);
  1390. }
  1391. if (info->tty->termios->c_cflag & CRTSCTS) {
  1392. //MX_LOCK(&info->slock);
  1393. info->MCR &= ~UART_MCR_RTS;
  1394. outb(info->MCR, info->base + UART_MCR);
  1395. //MX_UNLOCK(&info->slock);
  1396. }
  1397. }
  1398. static void mxser_startrx(struct tty_struct *tty)
  1399. {
  1400. struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
  1401. //unsigned long flags;
  1402. info->ldisc_stop_rx = 0;
  1403. if (I_IXOFF(tty)) {
  1404. if (info->x_char)
  1405. info->x_char = 0;
  1406. else {
  1407. //MX_LOCK(&info->slock);
  1408. // following add by Victor Yu. 09-02-2002
  1409. if (info->IsMoxaMustChipFlag) {
  1410. info->IER |= MOXA_MUST_RECV_ISR;
  1411. outb(info->IER, info->base + UART_IER);
  1412. } else {
  1413. // above add by Victor Yu. 09-02-2002
  1414. info->x_char = START_CHAR(tty);
  1415. // outb(info->IER, 0); // mask by Victor Yu. 09-02-2002
  1416. outb(0, info->base + UART_IER); // add by Victor Yu. 09-02-2002
  1417. info->IER |= UART_IER_THRI; /* force Tx interrupt */
  1418. outb(info->IER, info->base + UART_IER);
  1419. } // add by Victor Yu. 09-02-2002
  1420. //MX_UNLOCK(&info->slock);
  1421. }
  1422. }
  1423. if (info->tty->termios->c_cflag & CRTSCTS) {
  1424. //MX_LOCK(&info->slock);
  1425. info->MCR |= UART_MCR_RTS;
  1426. outb(info->MCR, info->base + UART_MCR);
  1427. //MX_UNLOCK(&info->slock);
  1428. }
  1429. }
  1430. /*
  1431. * This routine is called by the upper-layer tty layer to signal that
  1432. * incoming characters should be throttled.
  1433. */
  1434. static void mxser_throttle(struct tty_struct *tty)
  1435. {
  1436. //struct mxser_struct *info = (struct mxser_struct *)tty->driver_data;
  1437. //unsigned long flags;
  1438. //MX_LOCK(&info->slock);
  1439. mxser_stoprx(tty);
  1440. //MX_UNLOCK(&info->slock);
  1441. }
  1442. static void mxser_unthrottle(struct tty_struct *tty)
  1443. {
  1444. //struct mxser_struct *info = (struct mxser_struct *)tty->driver_data;
  1445. //unsigned long flags;
  1446. //MX_LOCK(&info->slock);
  1447. mxser_startrx(tty);
  1448. //MX_UNLOCK(&info->slock);
  1449. }
  1450. static void mxser_set_termios(struct tty_struct *tty, struct termios *old_termios)
  1451. {
  1452. struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
  1453. unsigned long flags;
  1454. if ((tty->termios->c_cflag != old_termios->c_cflag) || (RELEVANT_IFLAG(tty->termios->c_iflag) != RELEVANT_IFLAG(old_termios->c_iflag))) {
  1455. mxser_change_speed(info, old_termios);
  1456. if ((old_termios->c_cflag & CRTSCTS) && !(tty->termios->c_cflag & CRTSCTS)) {
  1457. tty->hw_stopped = 0;
  1458. mxser_start(tty);
  1459. }
  1460. }
  1461. /* Handle sw stopped */
  1462. if ((old_termios->c_iflag & IXON) && !(tty->termios->c_iflag & IXON)) {
  1463. tty->stopped = 0;
  1464. // following add by Victor Yu. 09-02-2002
  1465. if (info->IsMoxaMustChipFlag) {
  1466. spin_lock_irqsave(&info->slock, flags);
  1467. DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
  1468. spin_unlock_irqrestore(&info->slock, flags);
  1469. }
  1470. // above add by Victor Yu. 09-02-2002
  1471. mxser_start(tty);
  1472. }
  1473. }
  1474. /*
  1475. * mxser_stop() and mxser_start()
  1476. *
  1477. * This routines are called before setting or resetting tty->stopped.
  1478. * They enable or disable transmitter interrupts, as necessary.
  1479. */
  1480. static void mxser_stop(struct tty_struct *tty)
  1481. {
  1482. struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
  1483. unsigned long flags;
  1484. spin_lock_irqsave(&info->slock, flags);
  1485. if (info->IER & UART_IER_THRI) {
  1486. info->IER &= ~UART_IER_THRI;
  1487. outb(info->IER, info->base + UART_IER);
  1488. }
  1489. spin_unlock_irqrestore(&info->slock, flags);
  1490. }
  1491. static void mxser_start(struct tty_struct *tty)
  1492. {
  1493. struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
  1494. unsigned long flags;
  1495. spin_lock_irqsave(&info->slock, flags);
  1496. if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) {
  1497. info->IER |= UART_IER_THRI;
  1498. outb(info->IER, info->base + UART_IER);
  1499. }
  1500. spin_unlock_irqrestore(&info->slock, flags);
  1501. }
  1502. /*
  1503. * mxser_wait_until_sent() --- wait until the transmitter is empty
  1504. */
  1505. static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
  1506. {
  1507. struct mxser_struct *info = (struct mxser_struct