jsm_neo.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429
  1. /************************************************************************
  2. * Copyright 2003 Digi International (www.digi.com)
  3. *
  4. * Copyright (C) 2004 IBM Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
  13. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. * PURPOSE. See the GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 * Temple Place - Suite 330, Boston,
  19. * MA 02111-1307, USA.
  20. *
  21. * Contact Information:
  22. * Scott H Kilau <Scott_Kilau@digi.com>
  23. * Wendy Xiong <wendyx@us.ibm.com>
  24. *
  25. ***********************************************************************/
  26. #include <linux/delay.h> /* For udelay */
  27. #include <linux/serial_reg.h> /* For the various UART offsets */
  28. #include <linux/tty.h>
  29. #include <linux/pci.h>
  30. #include <asm/io.h>
  31. #include "jsm.h" /* Driver main header file */
  32. static u32 jsm_offset_table[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
  33. /*
  34. * This function allows calls to ensure that all outstanding
  35. * PCI writes have been completed, by doing a PCI read against
  36. * a non-destructive, read-only location on the Neo card.
  37. *
  38. * In this case, we are reading the DVID (Read-only Device Identification)
  39. * value of the Neo card.
  40. */
  41. static inline void neo_pci_posting_flush(struct jsm_board *bd)
  42. {
  43. readb(bd->re_map_membase + 0x8D);
  44. }
  45. static void neo_set_cts_flow_control(struct jsm_channel *ch)
  46. {
  47. u8 ier, efr;
  48. ier = readb(&ch->ch_neo_uart->ier);
  49. efr = readb(&ch->ch_neo_uart->efr);
  50. jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting CTSFLOW\n");
  51. /* Turn on auto CTS flow control */
  52. ier |= (UART_17158_IER_CTSDSR);
  53. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_CTSDSR);
  54. /* Turn off auto Xon flow control */
  55. efr &= ~(UART_17158_EFR_IXON);
  56. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  57. writeb(0, &ch->ch_neo_uart->efr);
  58. /* Turn on UART enhanced bits */
  59. writeb(efr, &ch->ch_neo_uart->efr);
  60. /* Turn on table D, with 8 char hi/low watermarks */
  61. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_4DELAY), &ch->ch_neo_uart->fctr);
  62. /* Feed the UART our trigger levels */
  63. writeb(8, &ch->ch_neo_uart->tfifo);
  64. ch->ch_t_tlevel = 8;
  65. writeb(ier, &ch->ch_neo_uart->ier);
  66. }
  67. static void neo_set_rts_flow_control(struct jsm_channel *ch)
  68. {
  69. u8 ier, efr;
  70. ier = readb(&ch->ch_neo_uart->ier);
  71. efr = readb(&ch->ch_neo_uart->efr);
  72. jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting RTSFLOW\n");
  73. /* Turn on auto RTS flow control */
  74. ier |= (UART_17158_IER_RTSDTR);
  75. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_RTSDTR);
  76. /* Turn off auto Xoff flow control */
  77. ier &= ~(UART_17158_IER_XOFF);
  78. efr &= ~(UART_17158_EFR_IXOFF);
  79. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  80. writeb(0, &ch->ch_neo_uart->efr);
  81. /* Turn on UART enhanced bits */
  82. writeb(efr, &ch->ch_neo_uart->efr);
  83. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_4DELAY), &ch->ch_neo_uart->fctr);
  84. ch->ch_r_watermark = 4;
  85. writeb(56, &ch->ch_neo_uart->rfifo);
  86. ch->ch_r_tlevel = 56;
  87. writeb(ier, &ch->ch_neo_uart->ier);
  88. /*
  89. * From the Neo UART spec sheet:
  90. * The auto RTS/DTR function must be started by asserting
  91. * RTS/DTR# output pin (MCR bit-0 or 1 to logic 1 after
  92. * it is enabled.
  93. */
  94. ch->ch_mostat |= (UART_MCR_RTS);
  95. }
  96. static void neo_set_ixon_flow_control(struct jsm_channel *ch)
  97. {
  98. u8 ier, efr;
  99. ier = readb(&ch->ch_neo_uart->ier);
  100. efr = readb(&ch->ch_neo_uart->efr);
  101. jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting IXON FLOW\n");
  102. /* Turn off auto CTS flow control */
  103. ier &= ~(UART_17158_IER_CTSDSR);
  104. efr &= ~(UART_17158_EFR_CTSDSR);
  105. /* Turn on auto Xon flow control */
  106. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_IXON);
  107. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  108. writeb(0, &ch->ch_neo_uart->efr);
  109. /* Turn on UART enhanced bits */
  110. writeb(efr, &ch->ch_neo_uart->efr);
  111. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  112. ch->ch_r_watermark = 4;
  113. writeb(32, &ch->ch_neo_uart->rfifo);
  114. ch->ch_r_tlevel = 32;
  115. /* Tell UART what start/stop chars it should be looking for */
  116. writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
  117. writeb(0, &ch->ch_neo_uart->xonchar2);
  118. writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
  119. writeb(0, &ch->ch_neo_uart->xoffchar2);
  120. writeb(ier, &ch->ch_neo_uart->ier);
  121. }
  122. static void neo_set_ixoff_flow_control(struct jsm_channel *ch)
  123. {
  124. u8 ier, efr;
  125. ier = readb(&ch->ch_neo_uart->ier);
  126. efr = readb(&ch->ch_neo_uart->efr);
  127. jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting IXOFF FLOW\n");
  128. /* Turn off auto RTS flow control */
  129. ier &= ~(UART_17158_IER_RTSDTR);
  130. efr &= ~(UART_17158_EFR_RTSDTR);
  131. /* Turn on auto Xoff flow control */
  132. ier |= (UART_17158_IER_XOFF);
  133. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_IXOFF);
  134. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  135. writeb(0, &ch->ch_neo_uart->efr);
  136. /* Turn on UART enhanced bits */
  137. writeb(efr, &ch->ch_neo_uart->efr);
  138. /* Turn on table D, with 8 char hi/low watermarks */
  139. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  140. writeb(8, &ch->ch_neo_uart->tfifo);
  141. ch->ch_t_tlevel = 8;
  142. /* Tell UART what start/stop chars it should be looking for */
  143. writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
  144. writeb(0, &ch->ch_neo_uart->xonchar2);
  145. writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
  146. writeb(0, &ch->ch_neo_uart->xoffchar2);
  147. writeb(ier, &ch->ch_neo_uart->ier);
  148. }
  149. static void neo_set_no_input_flow_control(struct jsm_channel *ch)
  150. {
  151. u8 ier, efr;
  152. ier = readb(&ch->ch_neo_uart->ier);
  153. efr = readb(&ch->ch_neo_uart->efr);
  154. jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Unsetting Input FLOW\n");
  155. /* Turn off auto RTS flow control */
  156. ier &= ~(UART_17158_IER_RTSDTR);
  157. efr &= ~(UART_17158_EFR_RTSDTR);
  158. /* Turn off auto Xoff flow control */
  159. ier &= ~(UART_17158_IER_XOFF);
  160. if (ch->ch_c_iflag & IXON)
  161. efr &= ~(UART_17158_EFR_IXOFF);
  162. else
  163. efr &= ~(UART_17158_EFR_ECB | UART_17158_EFR_IXOFF);
  164. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  165. writeb(0, &ch->ch_neo_uart->efr);
  166. /* Turn on UART enhanced bits */
  167. writeb(efr, &ch->ch_neo_uart->efr);
  168. /* Turn on table D, with 8 char hi/low watermarks */
  169. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  170. ch->ch_r_watermark = 0;
  171. writeb(16, &ch->ch_neo_uart->tfifo);
  172. ch->ch_t_tlevel = 16;
  173. writeb(16, &ch->ch_neo_uart->rfifo);
  174. ch->ch_r_tlevel = 16;
  175. writeb(ier, &ch->ch_neo_uart->ier);
  176. }
  177. static void neo_set_no_output_flow_control(struct jsm_channel *ch)
  178. {
  179. u8 ier, efr;
  180. ier = readb(&ch->ch_neo_uart->ier);
  181. efr = readb(&ch->ch_neo_uart->efr);
  182. jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Unsetting Output FLOW\n");
  183. /* Turn off auto CTS flow control */
  184. ier &= ~(UART_17158_IER_CTSDSR);
  185. efr &= ~(UART_17158_EFR_CTSDSR);
  186. /* Turn off auto Xon flow control */
  187. if (ch->ch_c_iflag & IXOFF)
  188. efr &= ~(UART_17158_EFR_IXON);
  189. else
  190. efr &= ~(UART_17158_EFR_ECB | UART_17158_EFR_IXON);
  191. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  192. writeb(0, &ch->ch_neo_uart->efr);
  193. /* Turn on UART enhanced bits */
  194. writeb(efr, &ch->ch_neo_uart->efr);
  195. /* Turn on table D, with 8 char hi/low watermarks */
  196. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  197. ch->ch_r_watermark = 0;
  198. writeb(16, &ch->ch_neo_uart->tfifo);
  199. ch->ch_t_tlevel = 16;
  200. writeb(16, &ch->ch_neo_uart->rfifo);
  201. ch->ch_r_tlevel = 16;
  202. writeb(ier, &ch->ch_neo_uart->ier);
  203. }
  204. static inline void neo_set_new_start_stop_chars(struct jsm_channel *ch)
  205. {
  206. /* if hardware flow control is set, then skip this whole thing */
  207. if (ch->ch_c_cflag & CRTSCTS)
  208. return;
  209. jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "start\n");
  210. /* Tell UART what start/stop chars it should be looking for */
  211. writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
  212. writeb(0, &ch->ch_neo_uart->xonchar2);
  213. writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
  214. writeb(0, &ch->ch_neo_uart->xoffchar2);
  215. }
  216. static void neo_copy_data_from_uart_to_queue(struct jsm_channel *ch)
  217. {
  218. int qleft = 0;
  219. u8 linestatus = 0;
  220. u8 error_mask = 0;
  221. int n = 0;
  222. int total = 0;
  223. u16 head;
  224. u16 tail;
  225. if (!ch)
  226. return;
  227. /* cache head and tail of queue */
  228. head = ch->ch_r_head & RQUEUEMASK;
  229. tail = ch->ch_r_tail & RQUEUEMASK;
  230. /* Get our cached LSR */
  231. linestatus = ch->ch_cached_lsr;
  232. ch->ch_cached_lsr = 0;
  233. /* Store how much space we have left in the queue */
  234. if ((qleft = tail - head - 1) < 0)
  235. qleft += RQUEUEMASK + 1;
  236. /*
  237. * If the UART is not in FIFO mode, force the FIFO copy to
  238. * NOT be run, by setting total to 0.
  239. *
  240. * On the other hand, if the UART IS in FIFO mode, then ask
  241. * the UART to give us an approximation of data it has RX'ed.
  242. */
  243. if (!(ch->ch_flags & CH_FIFO_ENABLED))
  244. total = 0;
  245. else {
  246. total = readb(&ch->ch_neo_uart->rfifo);
  247. /*
  248. * EXAR chip bug - RX FIFO COUNT - Fudge factor.
  249. *
  250. * This resolves a problem/bug with the Exar chip that sometimes
  251. * returns a bogus value in the rfifo register.
  252. * The count can be any where from 0-3 bytes "off".
  253. * Bizarre, but true.
  254. */
  255. total -= 3;
  256. }
  257. /*
  258. * Finally, bound the copy to make sure we don't overflow
  259. * our own queue...
  260. * The byte by byte copy loop below this loop this will
  261. * deal with the queue overflow possibility.
  262. */
  263. total = min(total, qleft);
  264. while (total > 0) {
  265. /*
  266. * Grab the linestatus register, we need to check
  267. * to see if there are any errors in the FIFO.
  268. */
  269. linestatus = readb(&ch->ch_neo_uart->lsr);
  270. /*
  271. * Break out if there is a FIFO error somewhere.
  272. * This will allow us to go byte by byte down below,
  273. * finding the exact location of the error.
  274. */
  275. if (linestatus & UART_17158_RX_FIFO_DATA_ERROR)
  276. break;
  277. /* Make sure we don't go over the end of our queue */
  278. n = min(((u32) total), (RQUEUESIZE - (u32) head));
  279. /*
  280. * Cut down n even further if needed, this is to fix
  281. * a problem with memcpy_fromio() with the Neo on the
  282. * IBM pSeries platform.
  283. * 15 bytes max appears to be the magic number.
  284. */
  285. n = min((u32) n, (u32) 12);
  286. /*
  287. * Since we are grabbing the linestatus register, which
  288. * will reset some bits after our read, we need to ensure
  289. * we don't miss our TX FIFO emptys.
  290. */
  291. if (linestatus & (UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR))
  292. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  293. linestatus = 0;
  294. /* Copy data from uart to the queue */
  295. memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, n);
  296. /*
  297. * Since RX_FIFO_DATA_ERROR was 0, we are guarenteed
  298. * that all the data currently in the FIFO is free of
  299. * breaks and parity/frame/orun errors.
  300. */
  301. memset(ch->ch_equeue + head, 0, n);
  302. /* Add to and flip head if needed */
  303. head = (head + n) & RQUEUEMASK;
  304. total -= n;
  305. qleft -= n;
  306. ch->ch_rxcount += n;
  307. }
  308. /*
  309. * Create a mask to determine whether we should
  310. * insert the character (if any) into our queue.
  311. */
  312. if (ch->ch_c_iflag & IGNBRK)
  313. error_mask |= UART_LSR_BI;
  314. /*
  315. * Now cleanup any leftover bytes still in the UART.
  316. * Also deal with any possible queue overflow here as well.
  317. */
  318. while (1) {
  319. /*
  320. * Its possible we have a linestatus from the loop above
  321. * this, so we "OR" on any extra bits.
  322. */
  323. linestatus |= readb(&ch->ch_neo_uart->lsr);
  324. /*
  325. * If the chip tells us there is no more data pending to
  326. * be read, we can then leave.
  327. * But before we do, cache the linestatus, just in case.
  328. */
  329. if (!(linestatus & UART_LSR_DR)) {
  330. ch->ch_cached_lsr = linestatus;
  331. break;
  332. }
  333. /* No need to store this bit */
  334. linestatus &= ~UART_LSR_DR;
  335. /*
  336. * Since we are grabbing the linestatus register, which
  337. * will reset some bits after our read, we need to ensure
  338. * we don't miss our TX FIFO emptys.
  339. */
  340. if (linestatus & (UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR)) {
  341. linestatus &= ~(UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR);
  342. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  343. }
  344. /*
  345. * Discard character if we are ignoring the error mask.
  346. */
  347. if (linestatus & error_mask) {
  348. u8 discard;
  349. linestatus = 0;
  350. memcpy_fromio(&discard, &ch->ch_neo_uart->txrxburst, 1);
  351. continue;
  352. }
  353. /*
  354. * If our queue is full, we have no choice but to drop some data.
  355. * The assumption is that HWFLOW or SWFLOW should have stopped
  356. * things way way before we got to this point.
  357. *
  358. * I decided that I wanted to ditch the oldest data first,
  359. * I hope thats okay with everyone? Yes? Good.
  360. */
  361. while (qleft < 1) {
  362. jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
  363. "Queue full, dropping DATA:%x LSR:%x\n",
  364. ch->ch_rqueue[tail], ch->ch_equeue[tail]);
  365. ch->ch_r_tail = tail = (tail + 1) & RQUEUEMASK;
  366. ch->ch_err_overrun++;
  367. qleft++;
  368. }
  369. memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, 1);
  370. ch->ch_equeue[head] = (u8) linestatus;
  371. jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
  372. "DATA/LSR pair: %x %x\n", ch->ch_rqueue[head], ch->ch_equeue[head]);
  373. /* Ditch any remaining linestatus value. */
  374. linestatus = 0;
  375. /* Add to and flip head if needed */
  376. head = (head + 1) & RQUEUEMASK;
  377. qleft--;
  378. ch->ch_rxcount++;
  379. }
  380. /*
  381. * Write new final heads to channel structure.
  382. */
  383. ch->ch_r_head = head & RQUEUEMASK;
  384. ch->ch_e_head = head & EQUEUEMASK;
  385. jsm_input(ch);
  386. }
  387. static void neo_copy_data_from_queue_to_uart(struct jsm_channel *ch)
  388. {
  389. u16 head;
  390. u16 tail;
  391. int n;
  392. int s;
  393. int qlen;
  394. u32 len_written = 0;
  395. if (!ch)
  396. return;
  397. /* No data to write to the UART */
  398. if (ch->ch_w_tail == ch->ch_w_head)
  399. return;
  400. /* If port is "stopped", don't send any data to the UART */
  401. if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_BREAK_SENDING))
  402. return;
  403. /*
  404. * If FIFOs are disabled. Send data directly to txrx register
  405. */
  406. if (!(ch->ch_flags & CH_FIFO_ENABLED)) {
  407. u8 lsrbits = readb(&ch->ch_neo_uart->lsr);
  408. ch->ch_cached_lsr |= lsrbits;
  409. if (ch->ch_cached_lsr & UART_LSR_THRE) {
  410. ch->ch_cached_lsr &= ~(UART_LSR_THRE);
  411. writeb(ch->ch_wqueue[ch->ch_w_tail], &ch->ch_neo_uart->txrx);
  412. jsm_printk(WRITE, INFO, &ch->ch_bd->pci_dev,
  413. "Tx data: %x\n", ch->ch_wqueue[ch->ch_w_head]);
  414. ch->ch_w_tail++;
  415. ch->ch_w_tail &= WQUEUEMASK;
  416. ch->ch_txcount++;
  417. }
  418. return;
  419. }
  420. /*
  421. * We have to do it this way, because of the EXAR TXFIFO count bug.
  422. */
  423. if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM)))
  424. return;
  425. len_written = 0;
  426. n = UART_17158_TX_FIFOSIZE - ch->ch_t_tlevel;
  427. /* cache head and tail of queue */
  428. head = ch->ch_w_head & WQUEUEMASK;
  429. tail = ch->ch_w_tail & WQUEUEMASK;
  430. qlen = (head - tail) & WQUEUEMASK;
  431. /* Find minimum of the FIFO space, versus queue length */
  432. n = min(n, qlen);
  433. while (n > 0) {
  434. s = ((head >= tail) ? head : WQUEUESIZE) - tail;
  435. s = min(s, n);
  436. if (s <= 0)
  437. break;
  438. memcpy_toio(&ch->ch_neo_uart->txrxburst, ch->ch_wqueue + tail, s);
  439. /* Add and flip queue if needed */
  440. tail = (tail + s) & WQUEUEMASK;
  441. n -= s;
  442. ch->ch_txcount += s;
  443. len_written += s;
  444. }
  445. /* Update the final tail */
  446. ch->ch_w_tail = tail & WQUEUEMASK;
  447. if (len_written >= ch->ch_t_tlevel)
  448. ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  449. if (!jsm_tty_write(&ch->uart_port))
  450. uart_write_wakeup(&ch->uart_port);
  451. }
  452. static void neo_parse_modem(struct jsm_channel *ch, u8 signals)
  453. {
  454. u8 msignals = signals;
  455. jsm_printk(MSIGS, INFO, &ch->ch_bd->pci_dev,
  456. "neo_parse_modem: port: %d msignals: %x\n", ch->ch_portnum, msignals);
  457. if (!ch)
  458. return;
  459. /* Scrub off lower bits. They signify delta's, which I don't care about */
  460. /* Keep DDCD and DDSR though */
  461. msignals &= 0xf8;
  462. if (msignals & UART_MSR_DDCD)
  463. uart_handle_dcd_change(&ch->uart_port, msignals & UART_MSR_DCD);
  464. if (msignals & UART_MSR_DDSR)
  465. uart_handle_cts_change(&ch->uart_port, msignals & UART_MSR_CTS);
  466. if (msignals & UART_MSR_DCD)
  467. ch->ch_mistat |= UART_MSR_DCD;
  468. else
  469. ch->ch_mistat &= ~UART_MSR_DCD;
  470. if (msignals & UART_MSR_DSR)
  471. ch->ch_mistat |= UART_MSR_DSR;
  472. else
  473. ch->ch_mistat &= ~UART_MSR_DSR;
  474. if (msignals & UART_MSR_RI)
  475. ch->ch_mistat |= UART_MSR_RI;
  476. else
  477. ch->ch_mistat &= ~UART_MSR_RI;
  478. if (msignals & UART_MSR_CTS)
  479. ch->ch_mistat |= UART_MSR_CTS;
  480. else
  481. ch->ch_mistat &= ~UART_MSR_CTS;
  482. jsm_printk(MSIGS, INFO, &ch->ch_bd->pci_dev,
  483. "Port: %d DTR: %d RTS: %d CTS: %d DSR: %d " "RI: %d CD: %d\n",
  484. ch->ch_portnum,
  485. !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_DTR),
  486. !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_RTS),
  487. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_CTS),
  488. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_DSR),
  489. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_RI),
  490. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_DCD));
  491. }
  492. /* Make the UART raise any of the output signals we want up */
  493. static void neo_assert_modem_signals(struct jsm_channel *ch)
  494. {
  495. u8 out;
  496. if (!ch)
  497. return;
  498. out = ch->ch_mostat;
  499. writeb(out, &ch->ch_neo_uart->mcr);
  500. /* flush write operation */
  501. neo_pci_posting_flush(ch->ch_bd);
  502. }
  503. /*
  504. * Flush the WRITE FIFO on the Neo.
  505. *
  506. * NOTE: Channel lock MUST be held before calling this function!
  507. */
  508. static void neo_flush_uart_write(struct jsm_channel *ch)
  509. {
  510. u8 tmp = 0;
  511. int i = 0;
  512. if (!ch)
  513. return;
  514. writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr);
  515. for (i = 0; i < 10; i++) {
  516. /* Check to see if the UART feels it completely flushed the FIFO. */
  517. tmp = readb(&ch->ch_neo_uart->isr_fcr);
  518. if (tmp & 4) {
  519. jsm_printk(IOCTL, INFO, &ch->ch_bd->pci_dev,
  520. "Still flushing TX UART... i: %d\n", i);
  521. udelay(10);
  522. }
  523. else
  524. break;
  525. }
  526. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  527. }
  528. /*
  529. * Flush the READ FIFO on the Neo.
  530. *
  531. * NOTE: Channel lock MUST be held before calling this function!
  532. */
  533. static void neo_flush_uart_read(struct jsm_channel *ch)
  534. {
  535. u8 tmp = 0;
  536. int i = 0;
  537. if (!ch)
  538. return;
  539. writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR), &ch->ch_neo_uart->isr_fcr);
  540. for (i = 0; i < 10; i++) {
  541. /* Check to see if the UART feels it completely flushed the FIFO. */
  542. tmp = readb(&ch->ch_neo_uart->isr_fcr);
  543. if (tmp & 2) {
  544. jsm_printk(IOCTL, INFO, &ch->ch_bd->pci_dev,
  545. "Still flushing RX UART... i: %d\n", i);
  546. udelay(10);
  547. }
  548. else
  549. break;
  550. }
  551. }
  552. /*
  553. * No locks are assumed to be held when calling this function.
  554. */
  555. static void neo_clear_break(struct jsm_channel *ch, int force)
  556. {
  557. unsigned long lock_flags;
  558. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  559. /* Turn break off, and unset some variables */
  560. if (ch->ch_flags & CH_BREAK_SENDING) {
  561. u8 temp = readb(&ch->ch_neo_uart->lcr);
  562. writeb((temp & ~UART_LCR_SBC), &ch->ch_neo_uart->lcr);
  563. ch->ch_flags &= ~(CH_BREAK_SENDING);
  564. jsm_printk(IOCTL, INFO, &ch->ch_bd->pci_dev,
  565. "clear break Finishing UART_LCR_SBC! finished: %lx\n", jiffies);
  566. /* flush write operation */
  567. neo_pci_posting_flush(ch->ch_bd);
  568. }
  569. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  570. }
  571. /*
  572. * Parse the ISR register.
  573. */
  574. static inline void neo_parse_isr(struct jsm_board *brd, u32 port)
  575. {
  576. struct jsm_channel *ch;
  577. u8 isr;
  578. u8 cause;
  579. unsigned long lock_flags;
  580. if (!brd)
  581. return;
  582. if (port > brd->maxports)
  583. return;
  584. ch = brd->channels[port];
  585. if (!ch)
  586. return;
  587. /* Here we try to figure out what caused the interrupt to happen */
  588. while (1) {
  589. isr = readb(&ch->ch_neo_uart->isr_fcr);
  590. /* Bail if no pending interrupt */
  591. if (isr & UART_IIR_NO_INT)
  592. break;
  593. /*
  594. * Yank off the upper 2 bits, which just show that the FIFO's are enabled.
  595. */
  596. isr &= ~(UART_17158_IIR_FIFO_ENABLED);
  597. jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
  598. "%s:%d isr: %x\n", __FILE__, __LINE__, isr);
  599. if (isr & (UART_17158_IIR_RDI_TIMEOUT | UART_IIR_RDI)) {
  600. /* Read data from uart -> queue */
  601. neo_copy_data_from_uart_to_queue(ch);
  602. /* Call our tty layer to enforce queue flow control if needed. */
  603. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  604. jsm_check_queue_flow_control(ch);
  605. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  606. }
  607. if (isr & UART_IIR_THRI) {
  608. /* Transfer data (if any) from Write Queue -> UART. */
  609. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  610. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  611. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  612. neo_copy_data_from_queue_to_uart(ch);
  613. }
  614. if (isr & UART_17158_IIR_XONXOFF) {
  615. cause = readb(&ch->ch_neo_uart->xoffchar1);
  616. jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
  617. "Port %d. Got ISR_XONXOFF: cause:%x\n", port, cause);
  618. /*
  619. * Since the UART detected either an XON or
  620. * XOFF match, we need to figure out which
  621. * one it was, so we can suspend or resume data flow.
  622. */
  623. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  624. if (cause == UART_17158_XON_DETECT) {
  625. /* Is output stopped right now, if so, resume it */
  626. if (brd->channels[port]->ch_flags & CH_STOP) {
  627. ch->ch_flags &= ~(CH_STOP);
  628. }
  629. jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
  630. "Port %d. XON detected in incoming data\n", port);
  631. }
  632. else if (cause == UART_17158_XOFF_DETECT) {
  633. if (!(brd->channels[port]->ch_flags & CH_STOP)) {
  634. ch->ch_flags |= CH_STOP;
  635. jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
  636. "Setting CH_STOP\n");
  637. }
  638. jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
  639. "Port: %d. XOFF detected in incoming data\n", port);
  640. }
  641. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  642. }
  643. if (isr & UART_17158_IIR_HWFLOW_STATE_CHANGE) {
  644. /*
  645. * If we get here, this means the hardware is doing auto flow control.
  646. * Check to see whether RTS/DTR or CTS/DSR caused this interrupt.
  647. */
  648. cause = readb(&ch->ch_neo_uart->mcr);
  649. /* Which pin is doing auto flow? RTS or DTR? */
  650. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  651. if ((cause & 0x4) == 0) {
  652. if (cause & UART_MCR_RTS)
  653. ch->ch_mostat |= UART_MCR_RTS;
  654. else
  655. ch->ch_mostat &= ~(UART_MCR_RTS);
  656. } else {
  657. if (cause & UART_MCR_DTR)
  658. ch->ch_mostat |= UART_MCR_DTR;
  659. else
  660. ch->ch_mostat &= ~(UART_MCR_DTR);
  661. }
  662. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  663. }
  664. /* Parse any modem signal changes */
  665. jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
  666. "MOD_STAT: sending to parse_modem_sigs\n");
  667. neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr));
  668. }
  669. }
  670. static inline void neo_parse_lsr(struct jsm_board *brd, u32 port)
  671. {
  672. struct jsm_channel *ch;
  673. int linestatus;
  674. unsigned long lock_flags;
  675. if (!brd)
  676. return;
  677. if (port > brd->maxports)
  678. return;
  679. ch = brd->channels[port];
  680. if (!ch)
  681. return;
  682. linestatus = readb(&ch->ch_neo_uart->lsr);
  683. jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
  684. "%s:%d port: %d linestatus: %x\n", __FILE__, __LINE__, port, linestatus);
  685. ch->ch_cached_lsr |= linestatus;
  686. if (ch->ch_cached_lsr & UART_LSR_DR) {
  687. /* Read data from uart -> queue */
  688. neo_copy_data_from_uart_to_queue(ch);
  689. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  690. jsm_check_queue_flow_control(ch);
  691. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  692. }
  693. /*
  694. * This is a special flag. It indicates that at least 1
  695. * RX error (parity, framing, or break) has happened.
  696. * Mark this in our struct, which will tell me that I have
  697. *to do the special RX+LSR read for this FIFO load.
  698. */
  699. if (linestatus & UART_17158_RX_FIFO_DATA_ERROR)
  700. jsm_printk(INTR, DEBUG, &ch->ch_bd->pci_dev,
  701. "%s:%d Port: %d Got an RX error, need to parse LSR\n",
  702. __FILE__, __LINE__, port);
  703. /*
  704. * The next 3 tests should *NOT* happen, as the above test
  705. * should encapsulate all 3... At least, thats what Exar says.
  706. */
  707. if (linestatus & UART_LSR_PE) {
  708. ch->ch_err_parity++;
  709. jsm_printk(INTR, DEBUG, &ch->ch_bd->pci_dev,
  710. "%s:%d Port: %d. PAR ERR!\n", __FILE__, __LINE__, port);
  711. }
  712. if (linestatus & UART_LSR_FE) {
  713. ch->ch_err_frame++;
  714. jsm_printk(INTR, DEBUG, &ch->ch_bd->pci_dev,
  715. "%s:%d Port: %d. FRM ERR!\n", __FILE__, __LINE__, port);
  716. }
  717. if (linestatus & UART_LSR_BI) {
  718. ch->ch_err_break++;
  719. jsm_printk(INTR, DEBUG, &ch->ch_bd->pci_dev,
  720. "%s:%d Port: %d. BRK INTR!\n", __FILE__, __LINE__, port);
  721. }
  722. if (linestatus & UART_LSR_OE) {
  723. /*
  724. * Rx Oruns. Exar says that an orun will NOT corrupt
  725. * the FIFO. It will just replace the holding register
  726. * with this new data byte. So basically just ignore this.
  727. * Probably we should eventually have an orun stat in our driver...
  728. */
  729. ch->ch_err_overrun++;
  730. jsm_printk(INTR, DEBUG, &ch->ch_bd->pci_dev,
  731. "%s:%d Port: %d. Rx Overrun!\n", __FILE__, __LINE__, port);
  732. }
  733. if (linestatus & UART_LSR_THRE) {
  734. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  735. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  736. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  737. /* Transfer data (if any) from Write Queue -> UART. */
  738. neo_copy_data_from_queue_to_uart(ch);
  739. }
  740. else if (linestatus & UART_17158_TX_AND_FIFO_CLR) {
  741. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  742. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  743. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  744. /* Transfer data (if any) from Write Queue -> UART. */
  745. neo_copy_data_from_queue_to_uart(ch);
  746. }
  747. }
  748. /*
  749. * neo_param()
  750. * Send any/all changes to the line to the UART.
  751. */
  752. static void neo_param(struct jsm_channel *ch)
  753. {
  754. u8 lcr = 0;
  755. u8 uart_lcr = 0;
  756. u8 ier = 0;
  757. u32 baud = 9600;
  758. int quot = 0;
  759. struct jsm_board *bd;
  760. bd = ch->ch_bd;
  761. if (!bd)
  762. return;
  763. /*
  764. * If baud rate is zero, flush queues, and set mval to drop DTR.
  765. */
  766. if ((ch->ch_c_cflag & (CBAUD)) == 0) {
  767. ch->ch_r_head = ch->ch_r_tail = 0;
  768. ch->ch_e_head = ch->ch_e_tail = 0;
  769. ch->ch_w_head = ch->ch_w_tail = 0;
  770. neo_flush_uart_write(ch);
  771. neo_flush_uart_read(ch);
  772. ch->ch_flags |= (CH_BAUD0);
  773. ch->ch_mostat &= ~(UART_MCR_RTS | UART_MCR_DTR);
  774. neo_assert_modem_signals(ch);
  775. ch->ch_old_baud = 0;
  776. return;
  777. } else if (ch->ch_custom_speed) {
  778. baud = ch->ch_custom_speed;
  779. if (ch->ch_flags & CH_BAUD0)
  780. ch->ch_flags &= ~(CH_BAUD0);
  781. } else {
  782. int i;
  783. unsigned int cflag;
  784. static struct {
  785. unsigned int rate;
  786. unsigned int cflag;
  787. } baud_rates[] = {
  788. { 921600, B921600 },
  789. { 460800, B460800 },
  790. { 230400, B230400 },
  791. { 115200, B115200 },
  792. { 57600, B57600 },
  793. { 38400, B38400 },
  794. { 19200, B19200 },
  795. { 9600, B9600 },
  796. { 4800, B4800 },
  797. { 2400, B2400 },
  798. { 1200, B1200 },
  799. { 600, B600 },
  800. { 300, B300 },
  801. { 200, B200 },
  802. { 150, B150 },
  803. { 134, B134 },
  804. { 110, B110 },
  805. { 75, B75 },
  806. { 50, B50 },
  807. };
  808. cflag = C_BAUD(ch->uart_port.info->port.tty);
  809. baud = 9600;
  810. for (i = 0; i < ARRAY_SIZE(baud_rates); i++) {
  811. if (baud_rates[i].cflag == cflag) {
  812. baud = baud_rates[i].rate;
  813. break;
  814. }
  815. }
  816. if (ch->ch_flags & CH_BAUD0)
  817. ch->ch_flags &= ~(CH_BAUD0);
  818. }
  819. if (ch->ch_c_cflag & PARENB)
  820. lcr |= UART_LCR_PARITY;
  821. if (!(ch->ch_c_cflag & PARODD))
  822. lcr |= UART_LCR_EPAR;
  823. /*
  824. * Not all platforms support mark/space parity,
  825. * so this will hide behind an ifdef.
  826. */
  827. #ifdef CMSPAR
  828. if (ch->ch_c_cflag & CMSPAR)
  829. lcr |= UART_LCR_SPAR;
  830. #endif
  831. if (ch->ch_c_cflag & CSTOPB)
  832. lcr |= UART_LCR_STOP;
  833. switch (ch->ch_c_cflag & CSIZE) {
  834. case CS5:
  835. lcr |= UART_LCR_WLEN5;
  836. break;
  837. case CS6:
  838. lcr |= UART_LCR_WLEN6;
  839. break;
  840. case CS7:
  841. lcr |= UART_LCR_WLEN7;
  842. break;
  843. case CS8:
  844. default:
  845. lcr |= UART_LCR_WLEN8;
  846. break;
  847. }
  848. ier = readb(&ch->ch_neo_uart->ier);
  849. uart_lcr = readb(&ch->ch_neo_uart->lcr);
  850. if (baud == 0)
  851. baud = 9600;
  852. quot = ch->ch_bd->bd_dividend / baud;
  853. if (quot != 0) {
  854. ch->ch_old_baud = baud;
  855. writeb(UART_LCR_DLAB, &ch->ch_neo_uart->lcr);
  856. writeb((quot & 0xff), &ch->ch_neo_uart->txrx);
  857. writeb((quot >> 8), &ch->ch_neo_uart->ier);
  858. writeb(lcr, &ch->ch_neo_uart->lcr);
  859. }
  860. if (uart_lcr != lcr)
  861. writeb(lcr, &ch->ch_neo_uart->lcr);
  862. if (ch->ch_c_cflag & CREAD)
  863. ier |= (UART_IER_RDI | UART_IER_RLSI);
  864. ier |= (UART_IER_THRI | UART_IER_MSI);
  865. writeb(ier, &ch->ch_neo_uart->ier);
  866. /* Set new start/stop chars */
  867. neo_set_new_start_stop_chars(ch);
  868. if (ch->ch_c_cflag & CRTSCTS)
  869. neo_set_cts_flow_control(ch);
  870. else if (ch->ch_c_iflag & IXON) {
  871. /* If start/stop is set to disable, then we should disable flow control */
  872. if ((ch->ch_startc == __DISABLED_CHAR) || (ch->ch_stopc == __DISABLED_CHAR))
  873. neo_set_no_output_flow_control(ch);
  874. else
  875. neo_set_ixon_flow_control(ch);
  876. }
  877. else
  878. neo_set_no_output_flow_control(ch);
  879. if (ch->ch_c_cflag & CRTSCTS)
  880. neo_set_rts_flow_control(ch);
  881. else if (ch->ch_c_iflag & IXOFF) {
  882. /* If start/stop is set to disable, then we should disable flow control */
  883. if ((ch->ch_startc == __DISABLED_CHAR) || (ch->ch_stopc == __DISABLED_CHAR))
  884. neo_set_no_input_flow_control(ch);
  885. else
  886. neo_set_ixoff_flow_control(ch);
  887. }
  888. else
  889. neo_set_no_input_flow_control(ch);
  890. /*
  891. * Adjust the RX FIFO Trigger level if baud is less than 9600.
  892. * Not exactly elegant, but this is needed because of the Exar chip's
  893. * delay on firing off the RX FIFO interrupt on slower baud rates.
  894. */
  895. if (baud < 9600) {
  896. writeb(1, &ch->ch_neo_uart->rfifo);
  897. ch->ch_r_tlevel = 1;
  898. }
  899. neo_assert_modem_signals(ch);
  900. /* Get current status of the modem signals now */
  901. neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr));
  902. return;
  903. }
  904. /*
  905. * jsm_neo_intr()
  906. *
  907. * Neo specific interrupt handler.
  908. */
  909. static irqreturn_t neo_intr(int irq, void *voidbrd)
  910. {
  911. struct jsm_board *brd = voidbrd;
  912. struct jsm_channel *ch;
  913. int port = 0;
  914. int type = 0;
  915. int current_port;
  916. u32 tmp;
  917. u32 uart_poll;
  918. unsigned long lock_flags;
  919. unsigned long lock_flags2;
  920. int outofloop_count = 0;
  921. brd->intr_count++;
  922. /* Lock out the slow poller from running on this board. */
  923. spin_lock_irqsave(&brd->bd_intr_lock, lock_flags);
  924. /*
  925. * Read in "extended" IRQ information from the 32bit Neo register.
  926. * Bits 0-7: What port triggered the interrupt.
  927. * Bits 8-31: Each 3bits indicate what type of interrupt occurred.
  928. */
  929. uart_poll = readl(brd->re_map_membase + UART_17158_POLL_ADDR_OFFSET);
  930. jsm_printk(INTR, INFO, &brd->pci_dev,
  931. "%s:%d uart_poll: %x\n", __FILE__, __LINE__, uart_poll);
  932. if (!uart_poll) {
  933. jsm_printk(INTR, INFO, &brd->pci_dev,
  934. "Kernel interrupted to me, but no pending interrupts...\n");
  935. spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags);
  936. return IRQ_NONE;
  937. }
  938. /* At this point, we have at least SOMETHING to service, dig further... */
  939. current_port = 0;
  940. /* Loop on each port */
  941. while (((uart_poll & 0xff) != 0) && (outofloop_count < 0xff)){
  942. tmp = uart_poll;
  943. outofloop_count++;
  944. /* Check current port to see if it has interrupt pending */
  945. if ((tmp & jsm_offset_table[current_port]) != 0) {
  946. port = current_port;
  947. type = tmp >> (8 + (port * 3));
  948. type &= 0x7;
  949. } else {
  950. current_port++;
  951. continue;
  952. }
  953. jsm_printk(INTR, INFO, &brd->pci_dev,
  954. "%s:%d port: %x type: %x\n", __FILE__, __LINE__, port, type);
  955. /* Remove this port + type from uart_poll */
  956. uart_poll &= ~(jsm_offset_table[port]);
  957. if (!type) {
  958. /* If no type, just ignore it, and move onto next port */
  959. jsm_printk(INTR, ERR, &brd->pci_dev,
  960. "Interrupt with no type! port: %d\n", port);
  961. continue;
  962. }
  963. /* Switch on type of interrupt we have */
  964. switch (type) {
  965. case UART_17158_RXRDY_TIMEOUT:
  966. /*
  967. * RXRDY Time-out is cleared by reading data in the
  968. * RX FIFO until it falls below the trigger level.
  969. */
  970. /* Verify the port is in range. */
  971. if (port > brd->nasync)
  972. continue;
  973. ch = brd->channels[port];
  974. neo_copy_data_from_uart_to_queue(ch);
  975. /* Call our tty layer to enforce queue flow control if needed. */
  976. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  977. jsm_check_queue_flow_control(ch);
  978. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  979. continue;
  980. case UART_17158_RX_LINE_STATUS:
  981. /*
  982. * RXRDY and RX LINE Status (logic OR of LSR[4:1])
  983. */
  984. neo_parse_lsr(brd, port);
  985. continue;
  986. case UART_17158_TXRDY:
  987. /*
  988. * TXRDY interrupt clears after reading ISR register for the UART channel.
  989. */
  990. /*
  991. * Yes, this is odd...
  992. * Why would I check EVERY possibility of type of
  993. * interrupt, when we know its TXRDY???
  994. * Becuz for some reason, even tho we got triggered for TXRDY,
  995. * it seems to be occassionally wrong. Instead of TX, which
  996. * it should be, I was getting things like RXDY too. Weird.
  997. */
  998. neo_parse_isr(brd, port);
  999. continue;
  1000. case UART_17158_MSR:
  1001. /*
  1002. * MSR or flow control was seen.
  1003. */
  1004. neo_parse_isr(brd, port);
  1005. continue;
  1006. default:
  1007. /*
  1008. * The UART triggered us with a bogus interrupt type.
  1009. * It appears the Exar chip, when REALLY bogged down, will throw
  1010. * these once and awhile.
  1011. * Its harmless, just ignore it and move on.
  1012. */
  1013. jsm_printk(INTR, ERR, &brd->pci_dev,
  1014. "%s:%d Unknown Interrupt type: %x\n", __FILE__, __LINE__, type);
  1015. continue;
  1016. }
  1017. }
  1018. spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags);
  1019. jsm_printk(INTR, INFO, &brd->pci_dev, "finish.\n");
  1020. return IRQ_HANDLED;
  1021. }
  1022. /*
  1023. * Neo specific way of turning off the receiver.
  1024. * Used as a way to enforce queue flow control when in
  1025. * hardware flow control mode.
  1026. */
  1027. static void neo_disable_receiver(struct jsm_channel *ch)
  1028. {
  1029. u8 tmp = readb(&ch->ch_neo_uart->ier);
  1030. tmp &= ~(UART_IER_RDI);
  1031. writeb(tmp, &ch->ch_neo_uart->ier);
  1032. /* flush write operation */
  1033. neo_pci_posting_flush(ch->ch_bd);
  1034. }
  1035. /*
  1036. * Neo specific way of turning on the receiver.
  1037. * Used as a way to un-enforce queue flow control when in
  1038. * hardware flow control mode.
  1039. */
  1040. static void neo_enable_receiver(struct jsm_channel *ch)
  1041. {
  1042. u8 tmp = readb(&ch->ch_neo_uart->ier);
  1043. tmp |= (UART_IER_RDI);
  1044. writeb(tmp, &ch->ch_neo_uart->ier);
  1045. /* flush write operation */
  1046. neo_pci_posting_flush(ch->ch_bd);
  1047. }
  1048. static void neo_send_start_character(struct jsm_channel *ch)
  1049. {
  1050. if (!ch)
  1051. return;
  1052. if (ch->ch_startc != __DISABLED_CHAR) {
  1053. ch->ch_xon_sends++;
  1054. writeb(ch->ch_startc, &ch->ch_neo_uart->txrx);
  1055. /* flush write operation */
  1056. neo_pci_posting_flush(ch->ch_bd);
  1057. }
  1058. }
  1059. static void neo_send_stop_character(struct jsm_channel *ch)
  1060. {
  1061. if (!ch)
  1062. return;
  1063. if (ch->ch_stopc != __DISABLED_CHAR) {
  1064. ch->ch_xoff_sends++;
  1065. writeb(ch->ch_stopc, &ch->ch_neo_uart->txrx);
  1066. /* flush write operation */
  1067. neo_pci_posting_flush(ch->ch_bd);
  1068. }
  1069. }
  1070. /*
  1071. * neo_uart_init
  1072. */
  1073. static void neo_uart_init(struct jsm_channel *ch)
  1074. {
  1075. writeb(0, &ch->ch_neo_uart->ier);
  1076. writeb(0, &ch->ch_neo_uart->efr);
  1077. writeb(UART_EFR_ECB, &ch->ch_neo_uart->efr);
  1078. /* Clear out UART and FIFO */
  1079. readb(&ch->ch_neo_uart->txrx);
  1080. writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr);
  1081. readb(&ch->ch_neo_uart->lsr);
  1082. readb(&ch->ch_neo_uart->msr);
  1083. ch->ch_flags |= CH_FIFO_ENABLED;
  1084. /* Assert any signals we want up */
  1085. writeb(ch->ch_mostat, &ch->ch_neo_uart->mcr);
  1086. }
  1087. /*
  1088. * Make the UART completely turn off.
  1089. */
  1090. static void neo_uart_off(struct jsm_channel *ch)
  1091. {
  1092. /* Turn off UART enhanced bits */
  1093. writeb(0, &ch->ch_neo_uart->efr);
  1094. /* Stop all interrupts from occurring. */
  1095. writeb(0, &ch->ch_neo_uart->ier);
  1096. }
  1097. static u32 neo_get_uart_bytes_left(struct jsm_channel *ch)
  1098. {
  1099. u8 left = 0;
  1100. u8 lsr = readb(&ch->ch_neo_uart->lsr);
  1101. /* We must cache the LSR as some of the bits get reset once read... */
  1102. ch->ch_cached_lsr |= lsr;
  1103. /* Determine whether the Transmitter is empty or not */
  1104. if (!(lsr & UART_LSR_TEMT))
  1105. left = 1;
  1106. else {
  1107. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  1108. left = 0;
  1109. }
  1110. return left;
  1111. }
  1112. /* Channel lock MUST be held by the calling function! */
  1113. static void neo_send_break(struct jsm_channel *ch)
  1114. {
  1115. /*
  1116. * Set the time we should stop sending the break.
  1117. * If we are already sending a break, toss away the existing
  1118. * time to stop, and use this new value instead.
  1119. */
  1120. /* Tell the UART to start sending the break */
  1121. if (!(ch->ch_flags & CH_BREAK_SENDING)) {
  1122. u8 temp = readb(&ch->ch_neo_uart->lcr);
  1123. writeb((temp | UART_LCR_SBC), &ch->ch_neo_uart->lcr);
  1124. ch->ch_flags |= (CH_BREAK_SENDING);
  1125. /* flush write operation */
  1126. neo_pci_posting_flush(ch->ch_bd);
  1127. }
  1128. }
  1129. /*
  1130. * neo_send_immediate_char.
  1131. *
  1132. * Sends a specific character as soon as possible to the UART,
  1133. * jumping over any bytes that might be in the write queue.
  1134. *
  1135. * The channel lock MUST be held by the calling function.
  1136. */
  1137. static void neo_send_immediate_char(struct jsm_channel *ch, unsigned char c)
  1138. {
  1139. if (!ch)
  1140. return;
  1141. writeb(c, &ch->ch_neo_uart->txrx);
  1142. /* flush write operation */
  1143. neo_pci_posting_flush(ch->ch_bd);
  1144. }
  1145. struct board_ops jsm_neo_ops = {
  1146. .intr = neo_intr,
  1147. .uart_init = neo_uart_init,
  1148. .uart_off = neo_uart_off,
  1149. .param = neo_param,
  1150. .assert_modem_signals = neo_assert_modem_signals,
  1151. .flush_uart_write = neo_flush_uart_write,
  1152. .flush_uart_read = neo_flush_uart_read,
  1153. .disable_receiver = neo_disable_receiver,
  1154. .enable_receiver = neo_enable_receiver,
  1155. .send_break = neo_send_break,
  1156. .clear_break = neo_clear_break,
  1157. .send_start_character = neo_send_start_character,
  1158. .send_stop_character = neo_send_stop_character,
  1159. .copy_data_from_queue_to_uart = neo_copy_data_from_queue_to_uart,
  1160. .get_uart_bytes_left = neo_get_uart_bytes_left,
  1161. .send_immediate_char = neo_send_immediate_char
  1162. };