jsm_cls.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. /*
  2. * Copyright 2003 Digi International (www.digi.com)
  3. * Scott H Kilau <Scott_Kilau at digi dot com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2, or (at your option)
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
  12. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. * PURPOSE. See the GNU General Public License for more details.
  14. *
  15. * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
  16. *
  17. * This is shared code between Digi's CVS archive and the
  18. * Linux Kernel sources.
  19. * Changing the source just for reformatting needlessly breaks
  20. * our CVS diff history.
  21. *
  22. * Send any bug fixes/changes to: Eng.Linux at digi dot com.
  23. * Thank you.
  24. *
  25. */
  26. #include <linux/delay.h> /* For udelay */
  27. #include <linux/io.h> /* For read[bwl]/write[bwl] */
  28. #include <linux/serial.h> /* For struct async_serial */
  29. #include <linux/serial_reg.h> /* For the various UART offsets */
  30. #include <linux/pci.h>
  31. #include <linux/tty.h>
  32. #include "jsm.h" /* Driver main header file */
  33. static struct {
  34. unsigned int rate;
  35. unsigned int cflag;
  36. } baud_rates[] = {
  37. { 921600, B921600 },
  38. { 460800, B460800 },
  39. { 230400, B230400 },
  40. { 115200, B115200 },
  41. { 57600, B57600 },
  42. { 38400, B38400 },
  43. { 19200, B19200 },
  44. { 9600, B9600 },
  45. { 4800, B4800 },
  46. { 2400, B2400 },
  47. { 1200, B1200 },
  48. { 600, B600 },
  49. { 300, B300 },
  50. { 200, B200 },
  51. { 150, B150 },
  52. { 134, B134 },
  53. { 110, B110 },
  54. { 75, B75 },
  55. { 50, B50 },
  56. };
  57. static void cls_set_cts_flow_control(struct jsm_channel *ch)
  58. {
  59. u8 lcrb = readb(&ch->ch_cls_uart->lcr);
  60. u8 ier = readb(&ch->ch_cls_uart->ier);
  61. u8 isr_fcr = 0;
  62. /*
  63. * The Enhanced Register Set may only be accessed when
  64. * the Line Control Register is set to 0xBFh.
  65. */
  66. writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
  67. isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
  68. /* Turn on CTS flow control, turn off IXON flow control */
  69. isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_CTSDSR);
  70. isr_fcr &= ~(UART_EXAR654_EFR_IXON);
  71. writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
  72. /* Write old LCR value back out, which turns enhanced access off */
  73. writeb(lcrb, &ch->ch_cls_uart->lcr);
  74. /*
  75. * Enable interrupts for CTS flow, turn off interrupts for
  76. * received XOFF chars
  77. */
  78. ier |= (UART_EXAR654_IER_CTSDSR);
  79. ier &= ~(UART_EXAR654_IER_XOFF);
  80. writeb(ier, &ch->ch_cls_uart->ier);
  81. /* Set the usual FIFO values */
  82. writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
  83. writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_56 |
  84. UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
  85. &ch->ch_cls_uart->isr_fcr);
  86. ch->ch_t_tlevel = 16;
  87. }
  88. static void cls_set_ixon_flow_control(struct jsm_channel *ch)
  89. {
  90. u8 lcrb = readb(&ch->ch_cls_uart->lcr);
  91. u8 ier = readb(&ch->ch_cls_uart->ier);
  92. u8 isr_fcr = 0;
  93. /*
  94. * The Enhanced Register Set may only be accessed when
  95. * the Line Control Register is set to 0xBFh.
  96. */
  97. writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
  98. isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
  99. /* Turn on IXON flow control, turn off CTS flow control */
  100. isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_IXON);
  101. isr_fcr &= ~(UART_EXAR654_EFR_CTSDSR);
  102. writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
  103. /* Now set our current start/stop chars while in enhanced mode */
  104. writeb(ch->ch_startc, &ch->ch_cls_uart->mcr);
  105. writeb(0, &ch->ch_cls_uart->lsr);
  106. writeb(ch->ch_stopc, &ch->ch_cls_uart->msr);
  107. writeb(0, &ch->ch_cls_uart->spr);
  108. /* Write old LCR value back out, which turns enhanced access off */
  109. writeb(lcrb, &ch->ch_cls_uart->lcr);
  110. /*
  111. * Disable interrupts for CTS flow, turn on interrupts for
  112. * received XOFF chars
  113. */
  114. ier &= ~(UART_EXAR654_IER_CTSDSR);
  115. ier |= (UART_EXAR654_IER_XOFF);
  116. writeb(ier, &ch->ch_cls_uart->ier);
  117. /* Set the usual FIFO values */
  118. writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
  119. writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
  120. UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
  121. &ch->ch_cls_uart->isr_fcr);
  122. }
  123. static void cls_set_no_output_flow_control(struct jsm_channel *ch)
  124. {
  125. u8 lcrb = readb(&ch->ch_cls_uart->lcr);
  126. u8 ier = readb(&ch->ch_cls_uart->ier);
  127. u8 isr_fcr = 0;
  128. /*
  129. * The Enhanced Register Set may only be accessed when
  130. * the Line Control Register is set to 0xBFh.
  131. */
  132. writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
  133. isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
  134. /* Turn off IXON flow control, turn off CTS flow control */
  135. isr_fcr |= (UART_EXAR654_EFR_ECB);
  136. isr_fcr &= ~(UART_EXAR654_EFR_CTSDSR | UART_EXAR654_EFR_IXON);
  137. writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
  138. /* Write old LCR value back out, which turns enhanced access off */
  139. writeb(lcrb, &ch->ch_cls_uart->lcr);
  140. /*
  141. * Disable interrupts for CTS flow, turn off interrupts for
  142. * received XOFF chars
  143. */
  144. ier &= ~(UART_EXAR654_IER_CTSDSR);
  145. ier &= ~(UART_EXAR654_IER_XOFF);
  146. writeb(ier, &ch->ch_cls_uart->ier);
  147. /* Set the usual FIFO values */
  148. writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
  149. writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
  150. UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
  151. &ch->ch_cls_uart->isr_fcr);
  152. ch->ch_r_watermark = 0;
  153. ch->ch_t_tlevel = 16;
  154. ch->ch_r_tlevel = 16;
  155. }
  156. static void cls_set_rts_flow_control(struct jsm_channel *ch)
  157. {
  158. u8 lcrb = readb(&ch->ch_cls_uart->lcr);
  159. u8 ier = readb(&ch->ch_cls_uart->ier);
  160. u8 isr_fcr = 0;
  161. /*
  162. * The Enhanced Register Set may only be accessed when
  163. * the Line Control Register is set to 0xBFh.
  164. */
  165. writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
  166. isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
  167. /* Turn on RTS flow control, turn off IXOFF flow control */
  168. isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_RTSDTR);
  169. isr_fcr &= ~(UART_EXAR654_EFR_IXOFF);
  170. writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
  171. /* Write old LCR value back out, which turns enhanced access off */
  172. writeb(lcrb, &ch->ch_cls_uart->lcr);
  173. /* Enable interrupts for RTS flow */
  174. ier |= (UART_EXAR654_IER_RTSDTR);
  175. writeb(ier, &ch->ch_cls_uart->ier);
  176. /* Set the usual FIFO values */
  177. writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
  178. writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_56 |
  179. UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
  180. &ch->ch_cls_uart->isr_fcr);
  181. ch->ch_r_watermark = 4;
  182. ch->ch_r_tlevel = 8;
  183. }
  184. static void cls_set_ixoff_flow_control(struct jsm_channel *ch)
  185. {
  186. u8 lcrb = readb(&ch->ch_cls_uart->lcr);
  187. u8 ier = readb(&ch->ch_cls_uart->ier);
  188. u8 isr_fcr = 0;
  189. /*
  190. * The Enhanced Register Set may only be accessed when
  191. * the Line Control Register is set to 0xBFh.
  192. */
  193. writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
  194. isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
  195. /* Turn on IXOFF flow control, turn off RTS flow control */
  196. isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_IXOFF);
  197. isr_fcr &= ~(UART_EXAR654_EFR_RTSDTR);
  198. writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
  199. /* Now set our current start/stop chars while in enhanced mode */
  200. writeb(ch->ch_startc, &ch->ch_cls_uart->mcr);
  201. writeb(0, &ch->ch_cls_uart->lsr);
  202. writeb(ch->ch_stopc, &ch->ch_cls_uart->msr);
  203. writeb(0, &ch->ch_cls_uart->spr);
  204. /* Write old LCR value back out, which turns enhanced access off */
  205. writeb(lcrb, &ch->ch_cls_uart->lcr);
  206. /* Disable interrupts for RTS flow */
  207. ier &= ~(UART_EXAR654_IER_RTSDTR);
  208. writeb(ier, &ch->ch_cls_uart->ier);
  209. /* Set the usual FIFO values */
  210. writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
  211. writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
  212. UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
  213. &ch->ch_cls_uart->isr_fcr);
  214. }
  215. static void cls_set_no_input_flow_control(struct jsm_channel *ch)
  216. {
  217. u8 lcrb = readb(&ch->ch_cls_uart->lcr);
  218. u8 ier = readb(&ch->ch_cls_uart->ier);
  219. u8 isr_fcr = 0;
  220. /*
  221. * The Enhanced Register Set may only be accessed when
  222. * the Line Control Register is set to 0xBFh.
  223. */
  224. writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
  225. isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
  226. /* Turn off IXOFF flow control, turn off RTS flow control */
  227. isr_fcr |= (UART_EXAR654_EFR_ECB);
  228. isr_fcr &= ~(UART_EXAR654_EFR_RTSDTR | UART_EXAR654_EFR_IXOFF);
  229. writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
  230. /* Write old LCR value back out, which turns enhanced access off */
  231. writeb(lcrb, &ch->ch_cls_uart->lcr);
  232. /* Disable interrupts for RTS flow */
  233. ier &= ~(UART_EXAR654_IER_RTSDTR);
  234. writeb(ier, &ch->ch_cls_uart->ier);
  235. /* Set the usual FIFO values */
  236. writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
  237. writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
  238. UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
  239. &ch->ch_cls_uart->isr_fcr);
  240. ch->ch_t_tlevel = 16;
  241. ch->ch_r_tlevel = 16;
  242. }
  243. /*
  244. * cls_clear_break.
  245. * Determines whether its time to shut off break condition.
  246. *
  247. * No locks are assumed to be held when calling this function.
  248. * channel lock is held and released in this function.
  249. */
  250. static void cls_clear_break(struct jsm_channel *ch)
  251. {
  252. unsigned long lock_flags;
  253. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  254. /* Turn break off, and unset some variables */
  255. if (ch->ch_flags & CH_BREAK_SENDING) {
  256. u8 temp = readb(&ch->ch_cls_uart->lcr);
  257. writeb((temp & ~UART_LCR_SBC), &ch->ch_cls_uart->lcr);
  258. ch->ch_flags &= ~(CH_BREAK_SENDING);
  259. jsm_dbg(IOCTL, &ch->ch_bd->pci_dev,
  260. "clear break Finishing UART_LCR_SBC! finished: %lx\n",
  261. jiffies);
  262. }
  263. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  264. }
  265. static void cls_disable_receiver(struct jsm_channel *ch)
  266. {
  267. u8 tmp = readb(&ch->ch_cls_uart->ier);
  268. tmp &= ~(UART_IER_RDI);
  269. writeb(tmp, &ch->ch_cls_uart->ier);
  270. }
  271. static void cls_enable_receiver(struct jsm_channel *ch)
  272. {
  273. u8 tmp = readb(&ch->ch_cls_uart->ier);
  274. tmp |= (UART_IER_RDI);
  275. writeb(tmp, &ch->ch_cls_uart->ier);
  276. }
  277. /* Make the UART raise any of the output signals we want up */
  278. static void cls_assert_modem_signals(struct jsm_channel *ch)
  279. {
  280. if (!ch)
  281. return;
  282. writeb(ch->ch_mostat, &ch->ch_cls_uart->mcr);
  283. }
  284. static void cls_copy_data_from_uart_to_queue(struct jsm_channel *ch)
  285. {
  286. int qleft = 0;
  287. u8 linestatus = 0;
  288. u8 error_mask = 0;
  289. u16 head;
  290. u16 tail;
  291. unsigned long flags;
  292. if (!ch)
  293. return;
  294. spin_lock_irqsave(&ch->ch_lock, flags);
  295. /* cache head and tail of queue */
  296. head = ch->ch_r_head & RQUEUEMASK;
  297. tail = ch->ch_r_tail & RQUEUEMASK;
  298. /* Get our cached LSR */
  299. linestatus = ch->ch_cached_lsr;
  300. ch->ch_cached_lsr = 0;
  301. /* Store how much space we have left in the queue */
  302. qleft = tail - head - 1;
  303. if (qleft < 0)
  304. qleft += RQUEUEMASK + 1;
  305. /*
  306. * Create a mask to determine whether we should
  307. * insert the character (if any) into our queue.
  308. */
  309. if (ch->ch_c_iflag & IGNBRK)
  310. error_mask |= UART_LSR_BI;
  311. while (1) {
  312. /*
  313. * Grab the linestatus register, we need to
  314. * check to see if there is any data to read
  315. */
  316. linestatus = readb(&ch->ch_cls_uart->lsr);
  317. /* Break out if there is no data to fetch */
  318. if (!(linestatus & UART_LSR_DR))
  319. break;
  320. /*
  321. * Discard character if we are ignoring the error mask
  322. * which in this case is the break signal.
  323. */
  324. if (linestatus & error_mask) {
  325. u8 discard;
  326. linestatus = 0;
  327. discard = readb(&ch->ch_cls_uart->txrx);
  328. continue;
  329. }
  330. /*
  331. * If our queue is full, we have no choice but to drop some
  332. * data. The assumption is that HWFLOW or SWFLOW should have
  333. * stopped things way way before we got to this point.
  334. *
  335. * I decided that I wanted to ditch the oldest data first,
  336. * I hope thats okay with everyone? Yes? Good.
  337. */
  338. while (qleft < 1) {
  339. tail = (tail + 1) & RQUEUEMASK;
  340. ch->ch_r_tail = tail;
  341. ch->ch_err_overrun++;
  342. qleft++;
  343. }
  344. ch->ch_equeue[head] = linestatus & (UART_LSR_BI | UART_LSR_PE
  345. | UART_LSR_FE);
  346. ch->ch_rqueue[head] = readb(&ch->ch_cls_uart->txrx);
  347. qleft--;
  348. if (ch->ch_equeue[head] & UART_LSR_PE)
  349. ch->ch_err_parity++;
  350. if (ch->ch_equeue[head] & UART_LSR_BI)
  351. ch->ch_err_break++;
  352. if (ch->ch_equeue[head] & UART_LSR_FE)
  353. ch->ch_err_frame++;
  354. /* Add to, and flip head if needed */
  355. head = (head + 1) & RQUEUEMASK;
  356. ch->ch_rxcount++;
  357. }
  358. /*
  359. * Write new final heads to channel structure.
  360. */
  361. ch->ch_r_head = head & RQUEUEMASK;
  362. ch->ch_e_head = head & EQUEUEMASK;
  363. spin_unlock_irqrestore(&ch->ch_lock, flags);
  364. }
  365. static void cls_copy_data_from_queue_to_uart(struct jsm_channel *ch)
  366. {
  367. u16 tail;
  368. int n;
  369. int qlen;
  370. u32 len_written = 0;
  371. struct circ_buf *circ;
  372. if (!ch)
  373. return;
  374. circ = &ch->uart_port.state->xmit;
  375. /* No data to write to the UART */
  376. if (uart_circ_empty(circ))
  377. return;
  378. /* If port is "stopped", don't send any data to the UART */
  379. if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_BREAK_SENDING))
  380. return;
  381. /* We have to do it this way, because of the EXAR TXFIFO count bug. */
  382. if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM)))
  383. return;
  384. n = 32;
  385. /* cache tail of queue */
  386. tail = circ->tail & (UART_XMIT_SIZE - 1);
  387. qlen = uart_circ_chars_pending(circ);
  388. /* Find minimum of the FIFO space, versus queue length */
  389. n = min(n, qlen);
  390. while (n > 0) {
  391. writeb(circ->buf[tail], &ch->ch_cls_uart->txrx);
  392. tail = (tail + 1) & (UART_XMIT_SIZE - 1);
  393. n--;
  394. ch->ch_txcount++;
  395. len_written++;
  396. }
  397. /* Update the final tail */
  398. circ->tail = tail & (UART_XMIT_SIZE - 1);
  399. if (len_written > ch->ch_t_tlevel)
  400. ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  401. if (uart_circ_empty(circ))
  402. uart_write_wakeup(&ch->uart_port);
  403. }
  404. static void cls_parse_modem(struct jsm_channel *ch, u8 signals)
  405. {
  406. u8 msignals = signals;
  407. jsm_dbg(MSIGS, &ch->ch_bd->pci_dev,
  408. "neo_parse_modem: port: %d msignals: %x\n",
  409. ch->ch_portnum, msignals);
  410. /*
  411. * Scrub off lower bits.
  412. * They signify delta's, which I don't care about
  413. * Keep DDCD and DDSR though
  414. */
  415. msignals &= 0xf8;
  416. if (msignals & UART_MSR_DDCD)
  417. uart_handle_dcd_change(&ch->uart_port, msignals & UART_MSR_DCD);
  418. if (msignals & UART_MSR_DDSR)
  419. uart_handle_dcd_change(&ch->uart_port, msignals & UART_MSR_CTS);
  420. if (msignals & UART_MSR_DCD)
  421. ch->ch_mistat |= UART_MSR_DCD;
  422. else
  423. ch->ch_mistat &= ~UART_MSR_DCD;
  424. if (msignals & UART_MSR_DSR)
  425. ch->ch_mistat |= UART_MSR_DSR;
  426. else
  427. ch->ch_mistat &= ~UART_MSR_DSR;
  428. if (msignals & UART_MSR_RI)
  429. ch->ch_mistat |= UART_MSR_RI;
  430. else
  431. ch->ch_mistat &= ~UART_MSR_RI;
  432. if (msignals & UART_MSR_CTS)
  433. ch->ch_mistat |= UART_MSR_CTS;
  434. else
  435. ch->ch_mistat &= ~UART_MSR_CTS;
  436. jsm_dbg(MSIGS, &ch->ch_bd->pci_dev,
  437. "Port: %d DTR: %d RTS: %d CTS: %d DSR: %d " "RI: %d CD: %d\n",
  438. ch->ch_portnum,
  439. !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_DTR),
  440. !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_RTS),
  441. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_CTS),
  442. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_DSR),
  443. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_RI),
  444. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_DCD));
  445. }
  446. /* Parse the ISR register for the specific port */
  447. static inline void cls_parse_isr(struct jsm_board *brd, uint port)
  448. {
  449. struct jsm_channel *ch;
  450. u8 isr = 0;
  451. unsigned long flags;
  452. /*
  453. * No need to verify board pointer, it was already
  454. * verified in the interrupt routine.
  455. */
  456. if (port >= brd->nasync)
  457. return;
  458. ch = brd->channels[port];
  459. if (!ch)
  460. return;
  461. /* Here we try to figure out what caused the interrupt to happen */
  462. while (1) {
  463. isr = readb(&ch->ch_cls_uart->isr_fcr);
  464. /* Bail if no pending interrupt on port */
  465. if (isr & UART_IIR_NO_INT)
  466. break;
  467. /* Receive Interrupt pending */
  468. if (isr & (UART_IIR_RDI | UART_IIR_RDI_TIMEOUT)) {
  469. /* Read data from uart -> queue */
  470. cls_copy_data_from_uart_to_queue(ch);
  471. jsm_check_queue_flow_control(ch);
  472. }
  473. /* Transmit Hold register empty pending */
  474. if (isr & UART_IIR_THRI) {
  475. /* Transfer data (if any) from Write Queue -> UART. */
  476. spin_lock_irqsave(&ch->ch_lock, flags);
  477. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  478. spin_unlock_irqrestore(&ch->ch_lock, flags);
  479. cls_copy_data_from_queue_to_uart(ch);
  480. }
  481. /*
  482. * CTS/RTS change of state:
  483. * Don't need to do anything, the cls_parse_modem
  484. * below will grab the updated modem signals.
  485. */
  486. /* Parse any modem signal changes */
  487. cls_parse_modem(ch, readb(&ch->ch_cls_uart->msr));
  488. }
  489. }
  490. /* Channel lock MUST be held before calling this function! */
  491. static void cls_flush_uart_write(struct jsm_channel *ch)
  492. {
  493. u8 tmp = 0;
  494. u8 i = 0;
  495. if (!ch)
  496. return;
  497. writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT),
  498. &ch->ch_cls_uart->isr_fcr);
  499. for (i = 0; i < 10; i++) {
  500. /* Check to see if the UART feels it completely flushed FIFO */
  501. tmp = readb(&ch->ch_cls_uart->isr_fcr);
  502. if (tmp & UART_FCR_CLEAR_XMIT) {
  503. jsm_dbg(IOCTL, &ch->ch_bd->pci_dev,
  504. "Still flushing TX UART... i: %d\n", i);
  505. udelay(10);
  506. } else
  507. break;
  508. }
  509. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  510. }
  511. /* Channel lock MUST be held before calling this function! */
  512. static void cls_flush_uart_read(struct jsm_channel *ch)
  513. {
  514. if (!ch)
  515. return;
  516. /*
  517. * For complete POSIX compatibility, we should be purging the
  518. * read FIFO in the UART here.
  519. *
  520. * However, clearing the read FIFO (UART_FCR_CLEAR_RCVR) also
  521. * incorrectly flushes write data as well as just basically trashing the
  522. * FIFO.
  523. *
  524. * Presumably, this is a bug in this UART.
  525. */
  526. udelay(10);
  527. }
  528. static void cls_send_start_character(struct jsm_channel *ch)
  529. {
  530. if (!ch)
  531. return;
  532. if (ch->ch_startc != __DISABLED_CHAR) {
  533. ch->ch_xon_sends++;
  534. writeb(ch->ch_startc, &ch->ch_cls_uart->txrx);
  535. }
  536. }
  537. static void cls_send_stop_character(struct jsm_channel *ch)
  538. {
  539. if (!ch)
  540. return;
  541. if (ch->ch_stopc != __DISABLED_CHAR) {
  542. ch->ch_xoff_sends++;
  543. writeb(ch->ch_stopc, &ch->ch_cls_uart->txrx);
  544. }
  545. }
  546. /*
  547. * cls_param()
  548. * Send any/all changes to the line to the UART.
  549. */
  550. static void cls_param(struct jsm_channel *ch)
  551. {
  552. u8 lcr = 0;
  553. u8 uart_lcr = 0;
  554. u8 ier = 0;
  555. u32 baud = 9600;
  556. int quot = 0;
  557. struct jsm_board *bd;
  558. int i;
  559. unsigned int cflag;
  560. bd = ch->ch_bd;
  561. if (!bd)
  562. return;
  563. /*
  564. * If baud rate is zero, flush queues, and set mval to drop DTR.
  565. */
  566. if ((ch->ch_c_cflag & (CBAUD)) == 0) {
  567. ch->ch_r_head = 0;
  568. ch->ch_r_tail = 0;
  569. ch->ch_e_head = 0;
  570. ch->ch_e_tail = 0;
  571. cls_flush_uart_write(ch);
  572. cls_flush_uart_read(ch);
  573. /* The baudrate is B0 so all modem lines are to be dropped. */
  574. ch->ch_flags |= (CH_BAUD0);
  575. ch->ch_mostat &= ~(UART_MCR_RTS | UART_MCR_DTR);
  576. cls_assert_modem_signals(ch);
  577. return;
  578. }
  579. cflag = C_BAUD(ch->uart_port.state->port.tty);
  580. baud = 9600;
  581. for (i = 0; i < ARRAY_SIZE(baud_rates); i++) {
  582. if (baud_rates[i].cflag == cflag) {
  583. baud = baud_rates[i].rate;
  584. break;
  585. }
  586. }
  587. if (ch->ch_flags & CH_BAUD0)
  588. ch->ch_flags &= ~(CH_BAUD0);
  589. if (ch->ch_c_cflag & PARENB)
  590. lcr |= UART_LCR_PARITY;
  591. if (!(ch->ch_c_cflag & PARODD))
  592. lcr |= UART_LCR_EPAR;
  593. /*
  594. * Not all platforms support mark/space parity,
  595. * so this will hide behind an ifdef.
  596. */
  597. #ifdef CMSPAR
  598. if (ch->ch_c_cflag & CMSPAR)
  599. lcr |= UART_LCR_SPAR;
  600. #endif
  601. if (ch->ch_c_cflag & CSTOPB)
  602. lcr |= UART_LCR_STOP;
  603. switch (ch->ch_c_cflag & CSIZE) {
  604. case CS5:
  605. lcr |= UART_LCR_WLEN5;
  606. break;
  607. case CS6:
  608. lcr |= UART_LCR_WLEN6;
  609. break;
  610. case CS7:
  611. lcr |= UART_LCR_WLEN7;
  612. break;
  613. case CS8:
  614. default:
  615. lcr |= UART_LCR_WLEN8;
  616. break;
  617. }
  618. ier = readb(&ch->ch_cls_uart->ier);
  619. uart_lcr = readb(&ch->ch_cls_uart->lcr);
  620. quot = ch->ch_bd->bd_dividend / baud;
  621. if (quot != 0) {
  622. writeb(UART_LCR_DLAB, &ch->ch_cls_uart->lcr);
  623. writeb((quot & 0xff), &ch->ch_cls_uart->txrx);
  624. writeb((quot >> 8), &ch->ch_cls_uart->ier);
  625. writeb(lcr, &ch->ch_cls_uart->lcr);
  626. }
  627. if (uart_lcr != lcr)
  628. writeb(lcr, &ch->ch_cls_uart->lcr);
  629. if (ch->ch_c_cflag & CREAD)
  630. ier |= (UART_IER_RDI | UART_IER_RLSI);
  631. ier |= (UART_IER_THRI | UART_IER_MSI);
  632. writeb(ier, &ch->ch_cls_uart->ier);
  633. if (ch->ch_c_cflag & CRTSCTS)
  634. cls_set_cts_flow_control(ch);
  635. else if (ch->ch_c_iflag & IXON) {
  636. /*
  637. * If start/stop is set to disable,
  638. * then we should disable flow control.
  639. */
  640. if ((ch->ch_startc == __DISABLED_CHAR) ||
  641. (ch->ch_stopc == __DISABLED_CHAR))
  642. cls_set_no_output_flow_control(ch);
  643. else
  644. cls_set_ixon_flow_control(ch);
  645. } else
  646. cls_set_no_output_flow_control(ch);
  647. if (ch->ch_c_cflag & CRTSCTS)
  648. cls_set_rts_flow_control(ch);
  649. else if (ch->ch_c_iflag & IXOFF) {
  650. /*
  651. * If start/stop is set to disable,
  652. * then we should disable flow control.
  653. */
  654. if ((ch->ch_startc == __DISABLED_CHAR) ||
  655. (ch->ch_stopc == __DISABLED_CHAR))
  656. cls_set_no_input_flow_control(ch);
  657. else
  658. cls_set_ixoff_flow_control(ch);
  659. } else
  660. cls_set_no_input_flow_control(ch);
  661. cls_assert_modem_signals(ch);
  662. /* get current status of the modem signals now */
  663. cls_parse_modem(ch, readb(&ch->ch_cls_uart->msr));
  664. }
  665. /*
  666. * cls_intr()
  667. *
  668. * Classic specific interrupt handler.
  669. */
  670. static irqreturn_t cls_intr(int irq, void *voidbrd)
  671. {
  672. struct jsm_board *brd = voidbrd;
  673. unsigned long lock_flags;
  674. unsigned char uart_poll;
  675. uint i = 0;
  676. /* Lock out the slow poller from running on this board. */
  677. spin_lock_irqsave(&brd->bd_intr_lock, lock_flags);
  678. /*
  679. * Check the board's global interrupt offset to see if we
  680. * acctually do have an interrupt pending on us.
  681. */
  682. uart_poll = readb(brd->re_map_membase + UART_CLASSIC_POLL_ADDR_OFFSET);
  683. jsm_dbg(INTR, &brd->pci_dev, "%s:%d uart_poll: %x\n",
  684. __FILE__, __LINE__, uart_poll);
  685. if (!uart_poll) {
  686. jsm_dbg(INTR, &brd->pci_dev,
  687. "Kernel interrupted to me, but no pending interrupts...\n");
  688. spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags);
  689. return IRQ_NONE;
  690. }
  691. /* At this point, we have at least SOMETHING to service, dig further. */
  692. /* Parse each port to find out what caused the interrupt */
  693. for (i = 0; i < brd->nasync; i++)
  694. cls_parse_isr(brd, i);
  695. spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags);
  696. return IRQ_HANDLED;
  697. }
  698. /* Inits UART */
  699. static void cls_uart_init(struct jsm_channel *ch)
  700. {
  701. unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
  702. unsigned char isr_fcr = 0;
  703. writeb(0, &ch->ch_cls_uart->ier);
  704. /*
  705. * The Enhanced Register Set may only be accessed when
  706. * the Line Control Register is set to 0xBFh.
  707. */
  708. writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
  709. isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
  710. /* Turn on Enhanced/Extended controls */
  711. isr_fcr |= (UART_EXAR654_EFR_ECB);
  712. writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
  713. /* Write old LCR value back out, which turns enhanced access off */
  714. writeb(lcrb, &ch->ch_cls_uart->lcr);
  715. /* Clear out UART and FIFO */
  716. readb(&ch->ch_cls_uart->txrx);
  717. writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT),
  718. &ch->ch_cls_uart->isr_fcr);
  719. udelay(10);
  720. ch->ch_flags |= (CH_FIFO_ENABLED | CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  721. readb(&ch->ch_cls_uart->lsr);
  722. readb(&ch->ch_cls_uart->msr);
  723. }
  724. /*
  725. * Turns off UART.
  726. */
  727. static void cls_uart_off(struct jsm_channel *ch)
  728. {
  729. /* Stop all interrupts from accurring. */
  730. writeb(0, &ch->ch_cls_uart->ier);
  731. }
  732. /*
  733. * cls_get_uarts_bytes_left.
  734. * Returns 0 is nothing left in the FIFO, returns 1 otherwise.
  735. *
  736. * The channel lock MUST be held by the calling function.
  737. */
  738. static u32 cls_get_uart_bytes_left(struct jsm_channel *ch)
  739. {
  740. u8 left = 0;
  741. u8 lsr = readb(&ch->ch_cls_uart->lsr);
  742. /* Determine whether the Transmitter is empty or not */
  743. if (!(lsr & UART_LSR_TEMT))
  744. left = 1;
  745. else {
  746. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  747. left = 0;
  748. }
  749. return left;
  750. }
  751. /*
  752. * cls_send_break.
  753. * Starts sending a break thru the UART.
  754. *
  755. * The channel lock MUST be held by the calling function.
  756. */
  757. static void cls_send_break(struct jsm_channel *ch)
  758. {
  759. /* Tell the UART to start sending the break */
  760. if (!(ch->ch_flags & CH_BREAK_SENDING)) {
  761. u8 temp = readb(&ch->ch_cls_uart->lcr);
  762. writeb((temp | UART_LCR_SBC), &ch->ch_cls_uart->lcr);
  763. ch->ch_flags |= (CH_BREAK_SENDING);
  764. }
  765. }
  766. /*
  767. * cls_send_immediate_char.
  768. * Sends a specific character as soon as possible to the UART,
  769. * jumping over any bytes that might be in the write queue.
  770. *
  771. * The channel lock MUST be held by the calling function.
  772. */
  773. static void cls_send_immediate_char(struct jsm_channel *ch, unsigned char c)
  774. {
  775. writeb(c, &ch->ch_cls_uart->txrx);
  776. }
  777. struct board_ops jsm_cls_ops = {
  778. .intr = cls_intr,
  779. .uart_init = cls_uart_init,
  780. .uart_off = cls_uart_off,
  781. .param = cls_param,
  782. .assert_modem_signals = cls_assert_modem_signals,
  783. .flush_uart_write = cls_flush_uart_write,
  784. .flush_uart_read = cls_flush_uart_read,
  785. .disable_receiver = cls_disable_receiver,
  786. .enable_receiver = cls_enable_receiver,
  787. .send_break = cls_send_break,
  788. .clear_break = cls_clear_break,
  789. .send_start_character = cls_send_start_character,
  790. .send_stop_character = cls_send_stop_character,
  791. .copy_data_from_queue_to_uart = cls_copy_data_from_queue_to_uart,
  792. .get_uart_bytes_left = cls_get_uart_bytes_left,
  793. .send_immediate_char = cls_send_immediate_char
  794. };