jsm_neo.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  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 guaranteed
  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. struct circ_buf *circ;
  396. if (!ch)
  397. return;
  398. circ = &ch->uart_port.state->xmit;
  399. /* No data to write to the UART */
  400. if (uart_circ_empty(circ))
  401. return;
  402. /* If port is "stopped", don't send any data to the UART */
  403. if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_BREAK_SENDING))
  404. return;
  405. /*
  406. * If FIFOs are disabled. Send data directly to txrx register
  407. */
  408. if (!(ch->ch_flags & CH_FIFO_ENABLED)) {
  409. u8 lsrbits = readb(&ch->ch_neo_uart->lsr);
  410. ch->ch_cached_lsr |= lsrbits;
  411. if (ch->ch_cached_lsr & UART_LSR_THRE) {
  412. ch->ch_cached_lsr &= ~(UART_LSR_THRE);
  413. writeb(circ->buf[circ->tail], &ch->ch_neo_uart->txrx);
  414. jsm_printk(WRITE, INFO, &ch->ch_bd->pci_dev,
  415. "Tx data: %x\n", circ->buf[circ->head]);
  416. circ->tail = (circ->tail + 1) & (UART_XMIT_SIZE - 1);
  417. ch->ch_txcount++;
  418. }
  419. return;
  420. }
  421. /*
  422. * We have to do it this way, because of the EXAR TXFIFO count bug.
  423. */
  424. if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM)))
  425. return;
  426. n = UART_17158_TX_FIFOSIZE - ch->ch_t_tlevel;
  427. /* cache head and tail of queue */
  428. head = circ->head & (UART_XMIT_SIZE - 1);
  429. tail = circ->tail & (UART_XMIT_SIZE - 1);
  430. qlen = uart_circ_chars_pending(circ);
  431. /* Find minimum of the FIFO space, versus queue length */
  432. n = min(n, qlen);
  433. while (n > 0) {
  434. s = ((head >= tail) ? head : UART_XMIT_SIZE) - tail;
  435. s = min(s, n);
  436. if (s <= 0)
  437. break;
  438. memcpy_toio(&ch->ch_neo_uart->txrxburst, circ->buf + tail, s);
  439. /* Add and flip queue if needed */
  440. tail = (tail + s) & (UART_XMIT_SIZE - 1);
  441. n -= s;
  442. ch->ch_txcount += s;
  443. len_written += s;
  444. }
  445. /* Update the final tail */
  446. circ->tail = tail & (UART_XMIT_SIZE - 1);
  447. if (len_written >= ch->ch_t_tlevel)
  448. ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  449. if (uart_circ_empty(circ))
  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. /* Scrub off lower bits. They signify delta's, which I don't care about */
  458. /* Keep DDCD and DDSR though */
  459. msignals &= 0xf8;
  460. if (msignals & UART_MSR_DDCD)
  461. uart_handle_dcd_change(&ch->uart_port, msignals & UART_MSR_DCD);
  462. if (msignals & UART_MSR_DDSR)
  463. uart_handle_cts_change(&ch->uart_port, msignals & UART_MSR_CTS);
  464. if (msignals & UART_MSR_DCD)
  465. ch->ch_mistat |= UART_MSR_DCD;
  466. else
  467. ch->ch_mistat &= ~UART_MSR_DCD;
  468. if (msignals & UART_MSR_DSR)
  469. ch->ch_mistat |= UART_MSR_DSR;
  470. else
  471. ch->ch_mistat &= ~UART_MSR_DSR;
  472. if (msignals & UART_MSR_RI)
  473. ch->ch_mistat |= UART_MSR_RI;
  474. else
  475. ch->ch_mistat &= ~UART_MSR_RI;
  476. if (msignals & UART_MSR_CTS)
  477. ch->ch_mistat |= UART_MSR_CTS;
  478. else
  479. ch->ch_mistat &= ~UART_MSR_CTS;
  480. jsm_printk(MSIGS, INFO, &ch->ch_bd->pci_dev,
  481. "Port: %d DTR: %d RTS: %d CTS: %d DSR: %d " "RI: %d CD: %d\n",
  482. ch->ch_portnum,
  483. !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_DTR),
  484. !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_RTS),
  485. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_CTS),
  486. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_DSR),
  487. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_RI),
  488. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_DCD));
  489. }
  490. /* Make the UART raise any of the output signals we want up */
  491. static void neo_assert_modem_signals(struct jsm_channel *ch)
  492. {
  493. if (!ch)
  494. return;
  495. writeb(ch->ch_mostat, &ch->ch_neo_uart->mcr);
  496. /* flush write operation */
  497. neo_pci_posting_flush(ch->ch_bd);
  498. }
  499. /*
  500. * Flush the WRITE FIFO on the Neo.
  501. *
  502. * NOTE: Channel lock MUST be held before calling this function!
  503. */
  504. static void neo_flush_uart_write(struct jsm_channel *ch)
  505. {
  506. u8 tmp = 0;
  507. int i = 0;
  508. if (!ch)
  509. return;
  510. writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr);
  511. for (i = 0; i < 10; i++) {
  512. /* Check to see if the UART feels it completely flushed the FIFO. */
  513. tmp = readb(&ch->ch_neo_uart->isr_fcr);
  514. if (tmp & 4) {
  515. jsm_printk(IOCTL, INFO, &ch->ch_bd->pci_dev,
  516. "Still flushing TX UART... i: %d\n", i);
  517. udelay(10);
  518. }
  519. else
  520. break;
  521. }
  522. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  523. }
  524. /*
  525. * Flush the READ FIFO on the Neo.
  526. *
  527. * NOTE: Channel lock MUST be held before calling this function!
  528. */
  529. static void neo_flush_uart_read(struct jsm_channel *ch)
  530. {
  531. u8 tmp = 0;
  532. int i = 0;
  533. if (!ch)
  534. return;
  535. writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR), &ch->ch_neo_uart->isr_fcr);
  536. for (i = 0; i < 10; i++) {
  537. /* Check to see if the UART feels it completely flushed the FIFO. */
  538. tmp = readb(&ch->ch_neo_uart->isr_fcr);
  539. if (tmp & 2) {
  540. jsm_printk(IOCTL, INFO, &ch->ch_bd->pci_dev,
  541. "Still flushing RX UART... i: %d\n", i);
  542. udelay(10);
  543. }
  544. else
  545. break;
  546. }
  547. }
  548. /*
  549. * No locks are assumed to be held when calling this function.
  550. */
  551. static void neo_clear_break(struct jsm_channel *ch, int force)
  552. {
  553. unsigned long lock_flags;
  554. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  555. /* Turn break off, and unset some variables */
  556. if (ch->ch_flags & CH_BREAK_SENDING) {
  557. u8 temp = readb(&ch->ch_neo_uart->lcr);
  558. writeb((temp & ~UART_LCR_SBC), &ch->ch_neo_uart->lcr);
  559. ch->ch_flags &= ~(CH_BREAK_SENDING);
  560. jsm_printk(IOCTL, INFO, &ch->ch_bd->pci_dev,
  561. "clear break Finishing UART_LCR_SBC! finished: %lx\n", jiffies);
  562. /* flush write operation */
  563. neo_pci_posting_flush(ch->ch_bd);
  564. }
  565. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  566. }
  567. /*
  568. * Parse the ISR register.
  569. */
  570. static inline void neo_parse_isr(struct jsm_board *brd, u32 port)
  571. {
  572. struct jsm_channel *ch;
  573. u8 isr;
  574. u8 cause;
  575. unsigned long lock_flags;
  576. if (!brd)
  577. return;
  578. if (port > brd->maxports)
  579. return;
  580. ch = brd->channels[port];
  581. if (!ch)
  582. return;
  583. /* Here we try to figure out what caused the interrupt to happen */
  584. while (1) {
  585. isr = readb(&ch->ch_neo_uart->isr_fcr);
  586. /* Bail if no pending interrupt */
  587. if (isr & UART_IIR_NO_INT)
  588. break;
  589. /*
  590. * Yank off the upper 2 bits, which just show that the FIFO's are enabled.
  591. */
  592. isr &= ~(UART_17158_IIR_FIFO_ENABLED);
  593. jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
  594. "%s:%d isr: %x\n", __FILE__, __LINE__, isr);
  595. if (isr & (UART_17158_IIR_RDI_TIMEOUT | UART_IIR_RDI)) {
  596. /* Read data from uart -> queue */
  597. neo_copy_data_from_uart_to_queue(ch);
  598. /* Call our tty layer to enforce queue flow control if needed. */
  599. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  600. jsm_check_queue_flow_control(ch);
  601. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  602. }
  603. if (isr & UART_IIR_THRI) {
  604. /* Transfer data (if any) from Write Queue -> UART. */
  605. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  606. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  607. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  608. neo_copy_data_from_queue_to_uart(ch);
  609. }
  610. if (isr & UART_17158_IIR_XONXOFF) {
  611. cause = readb(&ch->ch_neo_uart->xoffchar1);
  612. jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
  613. "Port %d. Got ISR_XONXOFF: cause:%x\n", port, cause);
  614. /*
  615. * Since the UART detected either an XON or
  616. * XOFF match, we need to figure out which
  617. * one it was, so we can suspend or resume data flow.
  618. */
  619. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  620. if (cause == UART_17158_XON_DETECT) {
  621. /* Is output stopped right now, if so, resume it */
  622. if (brd->channels[port]->ch_flags & CH_STOP) {
  623. ch->ch_flags &= ~(CH_STOP);
  624. }
  625. jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
  626. "Port %d. XON detected in incoming data\n", port);
  627. }
  628. else if (cause == UART_17158_XOFF_DETECT) {
  629. if (!(brd->channels[port]->ch_flags & CH_STOP)) {
  630. ch->ch_flags |= CH_STOP;
  631. jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
  632. "Setting CH_STOP\n");
  633. }
  634. jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
  635. "Port: %d. XOFF detected in incoming data\n", port);
  636. }
  637. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  638. }
  639. if (isr & UART_17158_IIR_HWFLOW_STATE_CHANGE) {
  640. /*
  641. * If we get here, this means the hardware is doing auto flow control.
  642. * Check to see whether RTS/DTR or CTS/DSR caused this interrupt.
  643. */
  644. cause = readb(&ch->ch_neo_uart->mcr);
  645. /* Which pin is doing auto flow? RTS or DTR? */
  646. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  647. if ((cause & 0x4) == 0) {
  648. if (cause & UART_MCR_RTS)
  649. ch->ch_mostat |= UART_MCR_RTS;
  650. else
  651. ch->ch_mostat &= ~(UART_MCR_RTS);
  652. } else {
  653. if (cause & UART_MCR_DTR)
  654. ch->ch_mostat |= UART_MCR_DTR;
  655. else
  656. ch->ch_mostat &= ~(UART_MCR_DTR);
  657. }
  658. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  659. }
  660. /* Parse any modem signal changes */
  661. jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
  662. "MOD_STAT: sending to parse_modem_sigs\n");
  663. neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr));
  664. }
  665. }
  666. static inline void neo_parse_lsr(struct jsm_board *brd, u32 port)
  667. {
  668. struct jsm_channel *ch;
  669. int linestatus;
  670. unsigned long lock_flags;
  671. if (!brd)
  672. return;
  673. if (port > brd->maxports)
  674. return;
  675. ch = brd->channels[port];
  676. if (!ch)
  677. return;
  678. linestatus = readb(&ch->ch_neo_uart->lsr);
  679. jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
  680. "%s:%d port: %d linestatus: %x\n", __FILE__, __LINE__, port, linestatus);
  681. ch->ch_cached_lsr |= linestatus;
  682. if (ch->ch_cached_lsr & UART_LSR_DR) {
  683. /* Read data from uart -> queue */
  684. neo_copy_data_from_uart_to_queue(ch);
  685. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  686. jsm_check_queue_flow_control(ch);
  687. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  688. }
  689. /*
  690. * This is a special flag. It indicates that at least 1
  691. * RX error (parity, framing, or break) has happened.
  692. * Mark this in our struct, which will tell me that I have
  693. *to do the special RX+LSR read for this FIFO load.
  694. */
  695. if (linestatus & UART_17158_RX_FIFO_DATA_ERROR)
  696. jsm_printk(INTR, DEBUG, &ch->ch_bd->pci_dev,
  697. "%s:%d Port: %d Got an RX error, need to parse LSR\n",
  698. __FILE__, __LINE__, port);
  699. /*
  700. * The next 3 tests should *NOT* happen, as the above test
  701. * should encapsulate all 3... At least, thats what Exar says.
  702. */
  703. if (linestatus & UART_LSR_PE) {
  704. ch->ch_err_parity++;
  705. jsm_printk(INTR, DEBUG, &ch->ch_bd->pci_dev,
  706. "%s:%d Port: %d. PAR ERR!\n", __FILE__, __LINE__, port);
  707. }
  708. if (linestatus & UART_LSR_FE) {
  709. ch->ch_err_frame++;
  710. jsm_printk(INTR, DEBUG, &ch->ch_bd->pci_dev,
  711. "%s:%d Port: %d. FRM ERR!\n", __FILE__, __LINE__, port);
  712. }
  713. if (linestatus & UART_LSR_BI) {
  714. ch->ch_err_break++;
  715. jsm_printk(INTR, DEBUG, &ch->ch_bd->pci_dev,
  716. "%s:%d Port: %d. BRK INTR!\n", __FILE__, __LINE__, port);
  717. }
  718. if (linestatus & UART_LSR_OE) {
  719. /*
  720. * Rx Oruns. Exar says that an orun will NOT corrupt
  721. * the FIFO. It will just replace the holding register
  722. * with this new data byte. So basically just ignore this.
  723. * Probably we should eventually have an orun stat in our driver...
  724. */
  725. ch->ch_err_overrun++;
  726. jsm_printk(INTR, DEBUG, &ch->ch_bd->pci_dev,
  727. "%s:%d Port: %d. Rx Overrun!\n", __FILE__, __LINE__, port);
  728. }
  729. if (linestatus & UART_LSR_THRE) {
  730. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  731. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  732. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  733. /* Transfer data (if any) from Write Queue -> UART. */
  734. neo_copy_data_from_queue_to_uart(ch);
  735. }
  736. else if (linestatus & UART_17158_TX_AND_FIFO_CLR) {
  737. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  738. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  739. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  740. /* Transfer data (if any) from Write Queue -> UART. */
  741. neo_copy_data_from_queue_to_uart(ch);
  742. }
  743. }
  744. /*
  745. * neo_param()
  746. * Send any/all changes to the line to the UART.
  747. */
  748. static void neo_param(struct jsm_channel *ch)
  749. {
  750. u8 lcr = 0;
  751. u8 uart_lcr, ier;
  752. u32 baud;
  753. int quot;
  754. struct jsm_board *bd;
  755. bd = ch->ch_bd;
  756. if (!bd)
  757. return;
  758. /*
  759. * If baud rate is zero, flush queues, and set mval to drop DTR.
  760. */
  761. if ((ch->ch_c_cflag & (CBAUD)) == 0) {
  762. ch->ch_r_head = ch->ch_r_tail = 0;
  763. ch->ch_e_head = ch->ch_e_tail = 0;
  764. neo_flush_uart_write(ch);
  765. neo_flush_uart_read(ch);
  766. ch->ch_flags |= (CH_BAUD0);
  767. ch->ch_mostat &= ~(UART_MCR_RTS | UART_MCR_DTR);
  768. neo_assert_modem_signals(ch);
  769. return;
  770. } else {
  771. int i;
  772. unsigned int cflag;
  773. static struct {
  774. unsigned int rate;
  775. unsigned int cflag;
  776. } baud_rates[] = {
  777. { 921600, B921600 },
  778. { 460800, B460800 },
  779. { 230400, B230400 },
  780. { 115200, B115200 },
  781. { 57600, B57600 },
  782. { 38400, B38400 },
  783. { 19200, B19200 },
  784. { 9600, B9600 },
  785. { 4800, B4800 },
  786. { 2400, B2400 },
  787. { 1200, B1200 },
  788. { 600, B600 },
  789. { 300, B300 },
  790. { 200, B200 },
  791. { 150, B150 },
  792. { 134, B134 },
  793. { 110, B110 },
  794. { 75, B75 },
  795. { 50, B50 },
  796. };
  797. cflag = C_BAUD(ch->uart_port.state->port.tty);
  798. baud = 9600;
  799. for (i = 0; i < ARRAY_SIZE(baud_rates); i++) {
  800. if (baud_rates[i].cflag == cflag) {
  801. baud = baud_rates[i].rate;
  802. break;
  803. }
  804. }
  805. if (ch->ch_flags & CH_BAUD0)
  806. ch->ch_flags &= ~(CH_BAUD0);
  807. }
  808. if (ch->ch_c_cflag & PARENB)
  809. lcr |= UART_LCR_PARITY;
  810. if (!(ch->ch_c_cflag & PARODD))
  811. lcr |= UART_LCR_EPAR;
  812. /*
  813. * Not all platforms support mark/space parity,
  814. * so this will hide behind an ifdef.
  815. */
  816. #ifdef CMSPAR
  817. if (ch->ch_c_cflag & CMSPAR)
  818. lcr |= UART_LCR_SPAR;
  819. #endif
  820. if (ch->ch_c_cflag & CSTOPB)
  821. lcr |= UART_LCR_STOP;
  822. switch (ch->ch_c_cflag & CSIZE) {
  823. case CS5:
  824. lcr |= UART_LCR_WLEN5;
  825. break;
  826. case CS6:
  827. lcr |= UART_LCR_WLEN6;
  828. break;
  829. case CS7:
  830. lcr |= UART_LCR_WLEN7;
  831. break;
  832. case CS8:
  833. default:
  834. lcr |= UART_LCR_WLEN8;
  835. break;
  836. }
  837. ier = readb(&ch->ch_neo_uart->ier);
  838. uart_lcr = readb(&ch->ch_neo_uart->lcr);
  839. if (baud == 0)
  840. baud = 9600;
  841. quot = ch->ch_bd->bd_dividend / baud;
  842. if (quot != 0) {
  843. writeb(UART_LCR_DLAB, &ch->ch_neo_uart->lcr);
  844. writeb((quot & 0xff), &ch->ch_neo_uart->txrx);
  845. writeb((quot >> 8), &ch->ch_neo_uart->ier);
  846. writeb(lcr, &ch->ch_neo_uart->lcr);
  847. }
  848. if (uart_lcr != lcr)
  849. writeb(lcr, &ch->ch_neo_uart->lcr);
  850. if (ch->ch_c_cflag & CREAD)
  851. ier |= (UART_IER_RDI | UART_IER_RLSI);
  852. ier |= (UART_IER_THRI | UART_IER_MSI);
  853. writeb(ier, &ch->ch_neo_uart->ier);
  854. /* Set new start/stop chars */
  855. neo_set_new_start_stop_chars(ch);
  856. if (ch->ch_c_cflag & CRTSCTS)
  857. neo_set_cts_flow_control(ch);
  858. else if (ch->ch_c_iflag & IXON) {
  859. /* If start/stop is set to disable, then we should disable flow control */
  860. if ((ch->ch_startc == __DISABLED_CHAR) || (ch->ch_stopc == __DISABLED_CHAR))
  861. neo_set_no_output_flow_control(ch);
  862. else
  863. neo_set_ixon_flow_control(ch);
  864. }
  865. else
  866. neo_set_no_output_flow_control(ch);
  867. if (ch->ch_c_cflag & CRTSCTS)
  868. neo_set_rts_flow_control(ch);
  869. else if (ch->ch_c_iflag & IXOFF) {
  870. /* If start/stop is set to disable, then we should disable flow control */
  871. if ((ch->ch_startc == __DISABLED_CHAR) || (ch->ch_stopc == __DISABLED_CHAR))
  872. neo_set_no_input_flow_control(ch);
  873. else
  874. neo_set_ixoff_flow_control(ch);
  875. }
  876. else
  877. neo_set_no_input_flow_control(ch);
  878. /*
  879. * Adjust the RX FIFO Trigger level if baud is less than 9600.
  880. * Not exactly elegant, but this is needed because of the Exar chip's
  881. * delay on firing off the RX FIFO interrupt on slower baud rates.
  882. */
  883. if (baud < 9600) {
  884. writeb(1, &ch->ch_neo_uart->rfifo);
  885. ch->ch_r_tlevel = 1;
  886. }
  887. neo_assert_modem_signals(ch);
  888. /* Get current status of the modem signals now */
  889. neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr));
  890. return;
  891. }
  892. /*
  893. * jsm_neo_intr()
  894. *
  895. * Neo specific interrupt handler.
  896. */
  897. static irqreturn_t neo_intr(int irq, void *voidbrd)
  898. {
  899. struct jsm_board *brd = voidbrd;
  900. struct jsm_channel *ch;
  901. int port = 0;
  902. int type = 0;
  903. int current_port;
  904. u32 tmp;
  905. u32 uart_poll;
  906. unsigned long lock_flags;
  907. unsigned long lock_flags2;
  908. int outofloop_count = 0;
  909. /* Lock out the slow poller from running on this board. */
  910. spin_lock_irqsave(&brd->bd_intr_lock, lock_flags);
  911. /*
  912. * Read in "extended" IRQ information from the 32bit Neo register.
  913. * Bits 0-7: What port triggered the interrupt.
  914. * Bits 8-31: Each 3bits indicate what type of interrupt occurred.
  915. */
  916. uart_poll = readl(brd->re_map_membase + UART_17158_POLL_ADDR_OFFSET);
  917. jsm_printk(INTR, INFO, &brd->pci_dev,
  918. "%s:%d uart_poll: %x\n", __FILE__, __LINE__, uart_poll);
  919. if (!uart_poll) {
  920. jsm_printk(INTR, INFO, &brd->pci_dev,
  921. "Kernel interrupted to me, but no pending interrupts...\n");
  922. spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags);
  923. return IRQ_NONE;
  924. }
  925. /* At this point, we have at least SOMETHING to service, dig further... */
  926. current_port = 0;
  927. /* Loop on each port */
  928. while (((uart_poll & 0xff) != 0) && (outofloop_count < 0xff)){
  929. tmp = uart_poll;
  930. outofloop_count++;
  931. /* Check current port to see if it has interrupt pending */
  932. if ((tmp & jsm_offset_table[current_port]) != 0) {
  933. port = current_port;
  934. type = tmp >> (8 + (port * 3));
  935. type &= 0x7;
  936. } else {
  937. current_port++;
  938. continue;
  939. }
  940. jsm_printk(INTR, INFO, &brd->pci_dev,
  941. "%s:%d port: %x type: %x\n", __FILE__, __LINE__, port, type);
  942. /* Remove this port + type from uart_poll */
  943. uart_poll &= ~(jsm_offset_table[port]);
  944. if (!type) {
  945. /* If no type, just ignore it, and move onto next port */
  946. jsm_printk(INTR, ERR, &brd->pci_dev,
  947. "Interrupt with no type! port: %d\n", port);
  948. continue;
  949. }
  950. /* Switch on type of interrupt we have */
  951. switch (type) {
  952. case UART_17158_RXRDY_TIMEOUT:
  953. /*
  954. * RXRDY Time-out is cleared by reading data in the
  955. * RX FIFO until it falls below the trigger level.
  956. */
  957. /* Verify the port is in range. */
  958. if (port > brd->nasync)
  959. continue;
  960. ch = brd->channels[port];
  961. neo_copy_data_from_uart_to_queue(ch);
  962. /* Call our tty layer to enforce queue flow control if needed. */
  963. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  964. jsm_check_queue_flow_control(ch);
  965. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  966. continue;
  967. case UART_17158_RX_LINE_STATUS:
  968. /*
  969. * RXRDY and RX LINE Status (logic OR of LSR[4:1])
  970. */
  971. neo_parse_lsr(brd, port);
  972. continue;
  973. case UART_17158_TXRDY:
  974. /*
  975. * TXRDY interrupt clears after reading ISR register for the UART channel.
  976. */
  977. /*
  978. * Yes, this is odd...
  979. * Why would I check EVERY possibility of type of
  980. * interrupt, when we know its TXRDY???
  981. * Becuz for some reason, even tho we got triggered for TXRDY,
  982. * it seems to be occasionally wrong. Instead of TX, which
  983. * it should be, I was getting things like RXDY too. Weird.
  984. */
  985. neo_parse_isr(brd, port);
  986. continue;
  987. case UART_17158_MSR:
  988. /*
  989. * MSR or flow control was seen.
  990. */
  991. neo_parse_isr(brd, port);
  992. continue;
  993. default:
  994. /*
  995. * The UART triggered us with a bogus interrupt type.
  996. * It appears the Exar chip, when REALLY bogged down, will throw
  997. * these once and awhile.
  998. * Its harmless, just ignore it and move on.
  999. */
  1000. jsm_printk(INTR, ERR, &brd->pci_dev,
  1001. "%s:%d Unknown Interrupt type: %x\n", __FILE__, __LINE__, type);
  1002. continue;
  1003. }
  1004. }
  1005. spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags);
  1006. jsm_printk(INTR, INFO, &brd->pci_dev, "finish.\n");
  1007. return IRQ_HANDLED;
  1008. }
  1009. /*
  1010. * Neo specific way of turning off the receiver.
  1011. * Used as a way to enforce queue flow control when in
  1012. * hardware flow control mode.
  1013. */
  1014. static void neo_disable_receiver(struct jsm_channel *ch)
  1015. {
  1016. u8 tmp = readb(&ch->ch_neo_uart->ier);
  1017. tmp &= ~(UART_IER_RDI);
  1018. writeb(tmp, &ch->ch_neo_uart->ier);
  1019. /* flush write operation */
  1020. neo_pci_posting_flush(ch->ch_bd);
  1021. }
  1022. /*
  1023. * Neo specific way of turning on the receiver.
  1024. * Used as a way to un-enforce queue flow control when in
  1025. * hardware flow control mode.
  1026. */
  1027. static void neo_enable_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. static void neo_send_start_character(struct jsm_channel *ch)
  1036. {
  1037. if (!ch)
  1038. return;
  1039. if (ch->ch_startc != __DISABLED_CHAR) {
  1040. ch->ch_xon_sends++;
  1041. writeb(ch->ch_startc, &ch->ch_neo_uart->txrx);
  1042. /* flush write operation */
  1043. neo_pci_posting_flush(ch->ch_bd);
  1044. }
  1045. }
  1046. static void neo_send_stop_character(struct jsm_channel *ch)
  1047. {
  1048. if (!ch)
  1049. return;
  1050. if (ch->ch_stopc != __DISABLED_CHAR) {
  1051. ch->ch_xoff_sends++;
  1052. writeb(ch->ch_stopc, &ch->ch_neo_uart->txrx);
  1053. /* flush write operation */
  1054. neo_pci_posting_flush(ch->ch_bd);
  1055. }
  1056. }
  1057. /*
  1058. * neo_uart_init
  1059. */
  1060. static void neo_uart_init(struct jsm_channel *ch)
  1061. {
  1062. writeb(0, &ch->ch_neo_uart->ier);
  1063. writeb(0, &ch->ch_neo_uart->efr);
  1064. writeb(UART_EFR_ECB, &ch->ch_neo_uart->efr);
  1065. /* Clear out UART and FIFO */
  1066. readb(&ch->ch_neo_uart->txrx);
  1067. writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr);
  1068. readb(&ch->ch_neo_uart->lsr);
  1069. readb(&ch->ch_neo_uart->msr);
  1070. ch->ch_flags |= CH_FIFO_ENABLED;
  1071. /* Assert any signals we want up */
  1072. writeb(ch->ch_mostat, &ch->ch_neo_uart->mcr);
  1073. }
  1074. /*
  1075. * Make the UART completely turn off.
  1076. */
  1077. static void neo_uart_off(struct jsm_channel *ch)
  1078. {
  1079. /* Turn off UART enhanced bits */
  1080. writeb(0, &ch->ch_neo_uart->efr);
  1081. /* Stop all interrupts from occurring. */
  1082. writeb(0, &ch->ch_neo_uart->ier);
  1083. }
  1084. static u32 neo_get_uart_bytes_left(struct jsm_channel *ch)
  1085. {
  1086. u8 left = 0;
  1087. u8 lsr = readb(&ch->ch_neo_uart->lsr);
  1088. /* We must cache the LSR as some of the bits get reset once read... */
  1089. ch->ch_cached_lsr |= lsr;
  1090. /* Determine whether the Transmitter is empty or not */
  1091. if (!(lsr & UART_LSR_TEMT))
  1092. left = 1;
  1093. else {
  1094. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  1095. left = 0;
  1096. }
  1097. return left;
  1098. }
  1099. /* Channel lock MUST be held by the calling function! */
  1100. static void neo_send_break(struct jsm_channel *ch)
  1101. {
  1102. /*
  1103. * Set the time we should stop sending the break.
  1104. * If we are already sending a break, toss away the existing
  1105. * time to stop, and use this new value instead.
  1106. */
  1107. /* Tell the UART to start sending the break */
  1108. if (!(ch->ch_flags & CH_BREAK_SENDING)) {
  1109. u8 temp = readb(&ch->ch_neo_uart->lcr);
  1110. writeb((temp | UART_LCR_SBC), &ch->ch_neo_uart->lcr);
  1111. ch->ch_flags |= (CH_BREAK_SENDING);
  1112. /* flush write operation */
  1113. neo_pci_posting_flush(ch->ch_bd);
  1114. }
  1115. }
  1116. /*
  1117. * neo_send_immediate_char.
  1118. *
  1119. * Sends a specific character as soon as possible to the UART,
  1120. * jumping over any bytes that might be in the write queue.
  1121. *
  1122. * The channel lock MUST be held by the calling function.
  1123. */
  1124. static void neo_send_immediate_char(struct jsm_channel *ch, unsigned char c)
  1125. {
  1126. if (!ch)
  1127. return;
  1128. writeb(c, &ch->ch_neo_uart->txrx);
  1129. /* flush write operation */
  1130. neo_pci_posting_flush(ch->ch_bd);
  1131. }
  1132. struct board_ops jsm_neo_ops = {
  1133. .intr = neo_intr,
  1134. .uart_init = neo_uart_init,
  1135. .uart_off = neo_uart_off,
  1136. .param = neo_param,
  1137. .assert_modem_signals = neo_assert_modem_signals,
  1138. .flush_uart_write = neo_flush_uart_write,
  1139. .flush_uart_read = neo_flush_uart_read,
  1140. .disable_receiver = neo_disable_receiver,
  1141. .enable_receiver = neo_enable_receiver,
  1142. .send_break = neo_send_break,
  1143. .clear_break = neo_clear_break,
  1144. .send_start_character = neo_send_start_character,
  1145. .send_stop_character = neo_send_stop_character,
  1146. .copy_data_from_queue_to_uart = neo_copy_data_from_queue_to_uart,
  1147. .get_uart_bytes_left = neo_get_uart_bytes_left,
  1148. .send_immediate_char = neo_send_immediate_char
  1149. };