jsm_neo.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  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. * Contact Information:
  17. * Scott H Kilau <[email protected]>
  18. * Wendy Xiong <[email protected]>
  19. *
  20. ***********************************************************************/
  21. #include <linux/delay.h> /* For udelay */
  22. #include <linux/serial_reg.h> /* For the various UART offsets */
  23. #include <linux/tty.h>
  24. #include <linux/pci.h>
  25. #include <asm/io.h>
  26. #include "jsm.h" /* Driver main header file */
  27. static u32 jsm_offset_table[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
  28. /*
  29. * This function allows calls to ensure that all outstanding
  30. * PCI writes have been completed, by doing a PCI read against
  31. * a non-destructive, read-only location on the Neo card.
  32. *
  33. * In this case, we are reading the DVID (Read-only Device Identification)
  34. * value of the Neo card.
  35. */
  36. static inline void neo_pci_posting_flush(struct jsm_board *bd)
  37. {
  38. readb(bd->re_map_membase + 0x8D);
  39. }
  40. static void neo_set_cts_flow_control(struct jsm_channel *ch)
  41. {
  42. u8 ier, efr;
  43. ier = readb(&ch->ch_neo_uart->ier);
  44. efr = readb(&ch->ch_neo_uart->efr);
  45. jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Setting CTSFLOW\n");
  46. /* Turn on auto CTS flow control */
  47. ier |= (UART_17158_IER_CTSDSR);
  48. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_CTSDSR);
  49. /* Turn off auto Xon flow control */
  50. efr &= ~(UART_17158_EFR_IXON);
  51. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  52. writeb(0, &ch->ch_neo_uart->efr);
  53. /* Turn on UART enhanced bits */
  54. writeb(efr, &ch->ch_neo_uart->efr);
  55. /* Turn on table D, with 8 char hi/low watermarks */
  56. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_4DELAY), &ch->ch_neo_uart->fctr);
  57. /* Feed the UART our trigger levels */
  58. writeb(8, &ch->ch_neo_uart->tfifo);
  59. ch->ch_t_tlevel = 8;
  60. writeb(ier, &ch->ch_neo_uart->ier);
  61. }
  62. static void neo_set_rts_flow_control(struct jsm_channel *ch)
  63. {
  64. u8 ier, efr;
  65. ier = readb(&ch->ch_neo_uart->ier);
  66. efr = readb(&ch->ch_neo_uart->efr);
  67. jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Setting RTSFLOW\n");
  68. /* Turn on auto RTS flow control */
  69. ier |= (UART_17158_IER_RTSDTR);
  70. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_RTSDTR);
  71. /* Turn off auto Xoff flow control */
  72. ier &= ~(UART_17158_IER_XOFF);
  73. efr &= ~(UART_17158_EFR_IXOFF);
  74. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  75. writeb(0, &ch->ch_neo_uart->efr);
  76. /* Turn on UART enhanced bits */
  77. writeb(efr, &ch->ch_neo_uart->efr);
  78. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_4DELAY), &ch->ch_neo_uart->fctr);
  79. ch->ch_r_watermark = 4;
  80. writeb(56, &ch->ch_neo_uart->rfifo);
  81. ch->ch_r_tlevel = 56;
  82. writeb(ier, &ch->ch_neo_uart->ier);
  83. /*
  84. * From the Neo UART spec sheet:
  85. * The auto RTS/DTR function must be started by asserting
  86. * RTS/DTR# output pin (MCR bit-0 or 1 to logic 1 after
  87. * it is enabled.
  88. */
  89. ch->ch_mostat |= (UART_MCR_RTS);
  90. }
  91. static void neo_set_ixon_flow_control(struct jsm_channel *ch)
  92. {
  93. u8 ier, efr;
  94. ier = readb(&ch->ch_neo_uart->ier);
  95. efr = readb(&ch->ch_neo_uart->efr);
  96. jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Setting IXON FLOW\n");
  97. /* Turn off auto CTS flow control */
  98. ier &= ~(UART_17158_IER_CTSDSR);
  99. efr &= ~(UART_17158_EFR_CTSDSR);
  100. /* Turn on auto Xon flow control */
  101. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_IXON);
  102. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  103. writeb(0, &ch->ch_neo_uart->efr);
  104. /* Turn on UART enhanced bits */
  105. writeb(efr, &ch->ch_neo_uart->efr);
  106. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  107. ch->ch_r_watermark = 4;
  108. writeb(32, &ch->ch_neo_uart->rfifo);
  109. ch->ch_r_tlevel = 32;
  110. /* Tell UART what start/stop chars it should be looking for */
  111. writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
  112. writeb(0, &ch->ch_neo_uart->xonchar2);
  113. writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
  114. writeb(0, &ch->ch_neo_uart->xoffchar2);
  115. writeb(ier, &ch->ch_neo_uart->ier);
  116. }
  117. static void neo_set_ixoff_flow_control(struct jsm_channel *ch)
  118. {
  119. u8 ier, efr;
  120. ier = readb(&ch->ch_neo_uart->ier);
  121. efr = readb(&ch->ch_neo_uart->efr);
  122. jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Setting IXOFF FLOW\n");
  123. /* Turn off auto RTS flow control */
  124. ier &= ~(UART_17158_IER_RTSDTR);
  125. efr &= ~(UART_17158_EFR_RTSDTR);
  126. /* Turn on auto Xoff flow control */
  127. ier |= (UART_17158_IER_XOFF);
  128. efr |= (UART_17158_EFR_ECB | UART_17158_EFR_IXOFF);
  129. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  130. writeb(0, &ch->ch_neo_uart->efr);
  131. /* Turn on UART enhanced bits */
  132. writeb(efr, &ch->ch_neo_uart->efr);
  133. /* Turn on table D, with 8 char hi/low watermarks */
  134. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  135. writeb(8, &ch->ch_neo_uart->tfifo);
  136. ch->ch_t_tlevel = 8;
  137. /* Tell UART what start/stop chars it should be looking for */
  138. writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
  139. writeb(0, &ch->ch_neo_uart->xonchar2);
  140. writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
  141. writeb(0, &ch->ch_neo_uart->xoffchar2);
  142. writeb(ier, &ch->ch_neo_uart->ier);
  143. }
  144. static void neo_set_no_input_flow_control(struct jsm_channel *ch)
  145. {
  146. u8 ier, efr;
  147. ier = readb(&ch->ch_neo_uart->ier);
  148. efr = readb(&ch->ch_neo_uart->efr);
  149. jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Unsetting Input FLOW\n");
  150. /* Turn off auto RTS flow control */
  151. ier &= ~(UART_17158_IER_RTSDTR);
  152. efr &= ~(UART_17158_EFR_RTSDTR);
  153. /* Turn off auto Xoff flow control */
  154. ier &= ~(UART_17158_IER_XOFF);
  155. if (ch->ch_c_iflag & IXON)
  156. efr &= ~(UART_17158_EFR_IXOFF);
  157. else
  158. efr &= ~(UART_17158_EFR_ECB | UART_17158_EFR_IXOFF);
  159. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  160. writeb(0, &ch->ch_neo_uart->efr);
  161. /* Turn on UART enhanced bits */
  162. writeb(efr, &ch->ch_neo_uart->efr);
  163. /* Turn on table D, with 8 char hi/low watermarks */
  164. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  165. ch->ch_r_watermark = 0;
  166. writeb(16, &ch->ch_neo_uart->tfifo);
  167. ch->ch_t_tlevel = 16;
  168. writeb(16, &ch->ch_neo_uart->rfifo);
  169. ch->ch_r_tlevel = 16;
  170. writeb(ier, &ch->ch_neo_uart->ier);
  171. }
  172. static void neo_set_no_output_flow_control(struct jsm_channel *ch)
  173. {
  174. u8 ier, efr;
  175. ier = readb(&ch->ch_neo_uart->ier);
  176. efr = readb(&ch->ch_neo_uart->efr);
  177. jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Unsetting Output FLOW\n");
  178. /* Turn off auto CTS flow control */
  179. ier &= ~(UART_17158_IER_CTSDSR);
  180. efr &= ~(UART_17158_EFR_CTSDSR);
  181. /* Turn off auto Xon flow control */
  182. if (ch->ch_c_iflag & IXOFF)
  183. efr &= ~(UART_17158_EFR_IXON);
  184. else
  185. efr &= ~(UART_17158_EFR_ECB | UART_17158_EFR_IXON);
  186. /* Why? Becuz Exar's spec says we have to zero it out before setting it */
  187. writeb(0, &ch->ch_neo_uart->efr);
  188. /* Turn on UART enhanced bits */
  189. writeb(efr, &ch->ch_neo_uart->efr);
  190. /* Turn on table D, with 8 char hi/low watermarks */
  191. writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
  192. ch->ch_r_watermark = 0;
  193. writeb(16, &ch->ch_neo_uart->tfifo);
  194. ch->ch_t_tlevel = 16;
  195. writeb(16, &ch->ch_neo_uart->rfifo);
  196. ch->ch_r_tlevel = 16;
  197. writeb(ier, &ch->ch_neo_uart->ier);
  198. }
  199. static inline void neo_set_new_start_stop_chars(struct jsm_channel *ch)
  200. {
  201. /* if hardware flow control is set, then skip this whole thing */
  202. if (ch->ch_c_cflag & CRTSCTS)
  203. return;
  204. jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "start\n");
  205. /* Tell UART what start/stop chars it should be looking for */
  206. writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
  207. writeb(0, &ch->ch_neo_uart->xonchar2);
  208. writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
  209. writeb(0, &ch->ch_neo_uart->xoffchar2);
  210. }
  211. static void neo_copy_data_from_uart_to_queue(struct jsm_channel *ch)
  212. {
  213. int qleft = 0;
  214. u8 linestatus = 0;
  215. u8 error_mask = 0;
  216. int n = 0;
  217. int total = 0;
  218. u16 head;
  219. u16 tail;
  220. if (!ch)
  221. return;
  222. /* cache head and tail of queue */
  223. head = ch->ch_r_head & RQUEUEMASK;
  224. tail = ch->ch_r_tail & RQUEUEMASK;
  225. /* Get our cached LSR */
  226. linestatus = ch->ch_cached_lsr;
  227. ch->ch_cached_lsr = 0;
  228. /* Store how much space we have left in the queue */
  229. if ((qleft = tail - head - 1) < 0)
  230. qleft += RQUEUEMASK + 1;
  231. /*
  232. * If the UART is not in FIFO mode, force the FIFO copy to
  233. * NOT be run, by setting total to 0.
  234. *
  235. * On the other hand, if the UART IS in FIFO mode, then ask
  236. * the UART to give us an approximation of data it has RX'ed.
  237. */
  238. if (!(ch->ch_flags & CH_FIFO_ENABLED))
  239. total = 0;
  240. else {
  241. total = readb(&ch->ch_neo_uart->rfifo);
  242. /*
  243. * EXAR chip bug - RX FIFO COUNT - Fudge factor.
  244. *
  245. * This resolves a problem/bug with the Exar chip that sometimes
  246. * returns a bogus value in the rfifo register.
  247. * The count can be any where from 0-3 bytes "off".
  248. * Bizarre, but true.
  249. */
  250. total -= 3;
  251. }
  252. /*
  253. * Finally, bound the copy to make sure we don't overflow
  254. * our own queue...
  255. * The byte by byte copy loop below this loop this will
  256. * deal with the queue overflow possibility.
  257. */
  258. total = min(total, qleft);
  259. while (total > 0) {
  260. /*
  261. * Grab the linestatus register, we need to check
  262. * to see if there are any errors in the FIFO.
  263. */
  264. linestatus = readb(&ch->ch_neo_uart->lsr);
  265. /*
  266. * Break out if there is a FIFO error somewhere.
  267. * This will allow us to go byte by byte down below,
  268. * finding the exact location of the error.
  269. */
  270. if (linestatus & UART_17158_RX_FIFO_DATA_ERROR)
  271. break;
  272. /* Make sure we don't go over the end of our queue */
  273. n = min(((u32) total), (RQUEUESIZE - (u32) head));
  274. /*
  275. * Cut down n even further if needed, this is to fix
  276. * a problem with memcpy_fromio() with the Neo on the
  277. * IBM pSeries platform.
  278. * 15 bytes max appears to be the magic number.
  279. */
  280. n = min((u32) n, (u32) 12);
  281. /*
  282. * Since we are grabbing the linestatus register, which
  283. * will reset some bits after our read, we need to ensure
  284. * we don't miss our TX FIFO emptys.
  285. */
  286. if (linestatus & (UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR))
  287. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  288. linestatus = 0;
  289. /* Copy data from uart to the queue */
  290. memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, n);
  291. /*
  292. * Since RX_FIFO_DATA_ERROR was 0, we are guaranteed
  293. * that all the data currently in the FIFO is free of
  294. * breaks and parity/frame/orun errors.
  295. */
  296. memset(ch->ch_equeue + head, 0, n);
  297. /* Add to and flip head if needed */
  298. head = (head + n) & RQUEUEMASK;
  299. total -= n;
  300. qleft -= n;
  301. ch->ch_rxcount += n;
  302. }
  303. /*
  304. * Create a mask to determine whether we should
  305. * insert the character (if any) into our queue.
  306. */
  307. if (ch->ch_c_iflag & IGNBRK)
  308. error_mask |= UART_LSR_BI;
  309. /*
  310. * Now cleanup any leftover bytes still in the UART.
  311. * Also deal with any possible queue overflow here as well.
  312. */
  313. while (1) {
  314. /*
  315. * Its possible we have a linestatus from the loop above
  316. * this, so we "OR" on any extra bits.
  317. */
  318. linestatus |= readb(&ch->ch_neo_uart->lsr);
  319. /*
  320. * If the chip tells us there is no more data pending to
  321. * be read, we can then leave.
  322. * But before we do, cache the linestatus, just in case.
  323. */
  324. if (!(linestatus & UART_LSR_DR)) {
  325. ch->ch_cached_lsr = linestatus;
  326. break;
  327. }
  328. /* No need to store this bit */
  329. linestatus &= ~UART_LSR_DR;
  330. /*
  331. * Since we are grabbing the linestatus register, which
  332. * will reset some bits after our read, we need to ensure
  333. * we don't miss our TX FIFO emptys.
  334. */
  335. if (linestatus & (UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR)) {
  336. linestatus &= ~(UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR);
  337. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  338. }
  339. /*
  340. * Discard character if we are ignoring the error mask.
  341. */
  342. if (linestatus & error_mask) {
  343. u8 discard;
  344. linestatus = 0;
  345. memcpy_fromio(&discard, &ch->ch_neo_uart->txrxburst, 1);
  346. continue;
  347. }
  348. /*
  349. * If our queue is full, we have no choice but to drop some data.
  350. * The assumption is that HWFLOW or SWFLOW should have stopped
  351. * things way way before we got to this point.
  352. *
  353. * I decided that I wanted to ditch the oldest data first,
  354. * I hope thats okay with everyone? Yes? Good.
  355. */
  356. while (qleft < 1) {
  357. jsm_dbg(READ, &ch->ch_bd->pci_dev,
  358. "Queue full, dropping DATA:%x LSR:%x\n",
  359. ch->ch_rqueue[tail], ch->ch_equeue[tail]);
  360. ch->ch_r_tail = tail = (tail + 1) & RQUEUEMASK;
  361. ch->ch_err_overrun++;
  362. qleft++;
  363. }
  364. memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, 1);
  365. ch->ch_equeue[head] = (u8) linestatus;
  366. jsm_dbg(READ, &ch->ch_bd->pci_dev, "DATA/LSR pair: %x %x\n",
  367. ch->ch_rqueue[head], ch->ch_equeue[head]);
  368. /* Ditch any remaining linestatus value. */
  369. linestatus = 0;
  370. /* Add to and flip head if needed */
  371. head = (head + 1) & RQUEUEMASK;
  372. qleft--;
  373. ch->ch_rxcount++;
  374. }
  375. /*
  376. * Write new final heads to channel structure.
  377. */
  378. ch->ch_r_head = head & RQUEUEMASK;
  379. ch->ch_e_head = head & EQUEUEMASK;
  380. jsm_input(ch);
  381. }
  382. static void neo_copy_data_from_queue_to_uart(struct jsm_channel *ch)
  383. {
  384. u16 head;
  385. u16 tail;
  386. int n;
  387. int s;
  388. int qlen;
  389. u32 len_written = 0;
  390. struct circ_buf *circ;
  391. if (!ch)
  392. return;
  393. circ = &ch->uart_port.state->xmit;
  394. /* No data to write to the UART */
  395. if (uart_circ_empty(circ))
  396. return;
  397. /* If port is "stopped", don't send any data to the UART */
  398. if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_BREAK_SENDING))
  399. return;
  400. /*
  401. * If FIFOs are disabled. Send data directly to txrx register
  402. */
  403. if (!(ch->ch_flags & CH_FIFO_ENABLED)) {
  404. u8 lsrbits = readb(&ch->ch_neo_uart->lsr);
  405. ch->ch_cached_lsr |= lsrbits;
  406. if (ch->ch_cached_lsr & UART_LSR_THRE) {
  407. ch->ch_cached_lsr &= ~(UART_LSR_THRE);
  408. writeb(circ->buf[circ->tail], &ch->ch_neo_uart->txrx);
  409. jsm_dbg(WRITE, &ch->ch_bd->pci_dev,
  410. "Tx data: %x\n", circ->buf[circ->tail]);
  411. circ->tail = (circ->tail + 1) & (UART_XMIT_SIZE - 1);
  412. ch->ch_txcount++;
  413. }
  414. return;
  415. }
  416. /*
  417. * We have to do it this way, because of the EXAR TXFIFO count bug.
  418. */
  419. if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM)))
  420. return;
  421. n = UART_17158_TX_FIFOSIZE - ch->ch_t_tlevel;
  422. /* cache head and tail of queue */
  423. head = circ->head & (UART_XMIT_SIZE - 1);
  424. tail = circ->tail & (UART_XMIT_SIZE - 1);
  425. qlen = uart_circ_chars_pending(circ);
  426. /* Find minimum of the FIFO space, versus queue length */
  427. n = min(n, qlen);
  428. while (n > 0) {
  429. s = ((head >= tail) ? head : UART_XMIT_SIZE) - tail;
  430. s = min(s, n);
  431. if (s <= 0)
  432. break;
  433. memcpy_toio(&ch->ch_neo_uart->txrxburst, circ->buf + tail, s);
  434. /* Add and flip queue if needed */
  435. tail = (tail + s) & (UART_XMIT_SIZE - 1);
  436. n -= s;
  437. ch->ch_txcount += s;
  438. len_written += s;
  439. }
  440. /* Update the final tail */
  441. circ->tail = tail & (UART_XMIT_SIZE - 1);
  442. if (len_written >= ch->ch_t_tlevel)
  443. ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  444. if (uart_circ_empty(circ))
  445. uart_write_wakeup(&ch->uart_port);
  446. }
  447. static void neo_parse_modem(struct jsm_channel *ch, u8 signals)
  448. {
  449. u8 msignals = signals;
  450. jsm_dbg(MSIGS, &ch->ch_bd->pci_dev,
  451. "neo_parse_modem: port: %d msignals: %x\n",
  452. ch->ch_portnum, msignals);
  453. /* Scrub off lower bits. They signify delta's, which I don't care about */
  454. /* Keep DDCD and DDSR though */
  455. msignals &= 0xf8;
  456. if (msignals & UART_MSR_DDCD)
  457. uart_handle_dcd_change(&ch->uart_port, msignals & UART_MSR_DCD);
  458. if (msignals & UART_MSR_DDSR)
  459. uart_handle_cts_change(&ch->uart_port, msignals & UART_MSR_CTS);
  460. if (msignals & UART_MSR_DCD)
  461. ch->ch_mistat |= UART_MSR_DCD;
  462. else
  463. ch->ch_mistat &= ~UART_MSR_DCD;
  464. if (msignals & UART_MSR_DSR)
  465. ch->ch_mistat |= UART_MSR_DSR;
  466. else
  467. ch->ch_mistat &= ~UART_MSR_DSR;
  468. if (msignals & UART_MSR_RI)
  469. ch->ch_mistat |= UART_MSR_RI;
  470. else
  471. ch->ch_mistat &= ~UART_MSR_RI;
  472. if (msignals & UART_MSR_CTS)
  473. ch->ch_mistat |= UART_MSR_CTS;
  474. else
  475. ch->ch_mistat &= ~UART_MSR_CTS;
  476. jsm_dbg(MSIGS, &ch->ch_bd->pci_dev,
  477. "Port: %d DTR: %d RTS: %d CTS: %d DSR: %d " "RI: %d CD: %d\n",
  478. ch->ch_portnum,
  479. !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_DTR),
  480. !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_RTS),
  481. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_CTS),
  482. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_DSR),
  483. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_RI),
  484. !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_DCD));
  485. }
  486. /* Make the UART raise any of the output signals we want up */
  487. static void neo_assert_modem_signals(struct jsm_channel *ch)
  488. {
  489. if (!ch)
  490. return;
  491. writeb(ch->ch_mostat, &ch->ch_neo_uart->mcr);
  492. /* flush write operation */
  493. neo_pci_posting_flush(ch->ch_bd);
  494. }
  495. /*
  496. * Flush the WRITE FIFO on the Neo.
  497. *
  498. * NOTE: Channel lock MUST be held before calling this function!
  499. */
  500. static void neo_flush_uart_write(struct jsm_channel *ch)
  501. {
  502. u8 tmp = 0;
  503. int i = 0;
  504. if (!ch)
  505. return;
  506. writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr);
  507. for (i = 0; i < 10; i++) {
  508. /* Check to see if the UART feels it completely flushed the FIFO. */
  509. tmp = readb(&ch->ch_neo_uart->isr_fcr);
  510. if (tmp & UART_FCR_CLEAR_XMIT) {
  511. jsm_dbg(IOCTL, &ch->ch_bd->pci_dev,
  512. "Still flushing TX UART... i: %d\n", i);
  513. udelay(10);
  514. }
  515. else
  516. break;
  517. }
  518. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  519. }
  520. /*
  521. * Flush the READ FIFO on the Neo.
  522. *
  523. * NOTE: Channel lock MUST be held before calling this function!
  524. */
  525. static void neo_flush_uart_read(struct jsm_channel *ch)
  526. {
  527. u8 tmp = 0;
  528. int i = 0;
  529. if (!ch)
  530. return;
  531. writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR), &ch->ch_neo_uart->isr_fcr);
  532. for (i = 0; i < 10; i++) {
  533. /* Check to see if the UART feels it completely flushed the FIFO. */
  534. tmp = readb(&ch->ch_neo_uart->isr_fcr);
  535. if (tmp & 2) {
  536. jsm_dbg(IOCTL, &ch->ch_bd->pci_dev,
  537. "Still flushing RX UART... i: %d\n", i);
  538. udelay(10);
  539. }
  540. else
  541. break;
  542. }
  543. }
  544. /*
  545. * No locks are assumed to be held when calling this function.
  546. */
  547. static void neo_clear_break(struct jsm_channel *ch)
  548. {
  549. unsigned long lock_flags;
  550. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  551. /* Turn break off, and unset some variables */
  552. if (ch->ch_flags & CH_BREAK_SENDING) {
  553. u8 temp = readb(&ch->ch_neo_uart->lcr);
  554. writeb((temp & ~UART_LCR_SBC), &ch->ch_neo_uart->lcr);
  555. ch->ch_flags &= ~(CH_BREAK_SENDING);
  556. jsm_dbg(IOCTL, &ch->ch_bd->pci_dev,
  557. "clear break Finishing UART_LCR_SBC! finished: %lx\n",
  558. jiffies);
  559. /* flush write operation */
  560. neo_pci_posting_flush(ch->ch_bd);
  561. }
  562. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  563. }
  564. /*
  565. * Parse the ISR register.
  566. */
  567. static void neo_parse_isr(struct jsm_board *brd, u32 port)
  568. {
  569. struct jsm_channel *ch;
  570. u8 isr;
  571. u8 cause;
  572. unsigned long lock_flags;
  573. if (!brd)
  574. return;
  575. if (port >= brd->maxports)
  576. return;
  577. ch = brd->channels[port];
  578. if (!ch)
  579. return;
  580. /* Here we try to figure out what caused the interrupt to happen */
  581. while (1) {
  582. isr = readb(&ch->ch_neo_uart->isr_fcr);
  583. /* Bail if no pending interrupt */
  584. if (isr & UART_IIR_NO_INT)
  585. break;
  586. /*
  587. * Yank off the upper 2 bits, which just show that the FIFO's are enabled.
  588. */
  589. isr &= ~(UART_17158_IIR_FIFO_ENABLED);
  590. jsm_dbg(INTR, &ch->ch_bd->pci_dev, "%s:%d isr: %x\n",
  591. __FILE__, __LINE__, isr);
  592. if (isr & (UART_17158_IIR_RDI_TIMEOUT | UART_IIR_RDI)) {
  593. /* Read data from uart -> queue */
  594. neo_copy_data_from_uart_to_queue(ch);
  595. /* Call our tty layer to enforce queue flow control if needed. */
  596. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  597. jsm_check_queue_flow_control(ch);
  598. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  599. }
  600. if (isr & UART_IIR_THRI) {
  601. /* Transfer data (if any) from Write Queue -> UART. */
  602. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  603. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  604. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  605. neo_copy_data_from_queue_to_uart(ch);
  606. }
  607. if (isr & UART_17158_IIR_XONXOFF) {
  608. cause = readb(&ch->ch_neo_uart->xoffchar1);
  609. jsm_dbg(INTR, &ch->ch_bd->pci_dev,
  610. "Port %d. Got ISR_XONXOFF: cause:%x\n",
  611. port, cause);
  612. /*
  613. * Since the UART detected either an XON or
  614. * XOFF match, we need to figure out which
  615. * one it was, so we can suspend or resume data flow.
  616. */
  617. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  618. if (cause == UART_17158_XON_DETECT) {
  619. /* Is output stopped right now, if so, resume it */
  620. if (brd->channels[port]->ch_flags & CH_STOP) {
  621. ch->ch_flags &= ~(CH_STOP);
  622. }
  623. jsm_dbg(INTR, &ch->ch_bd->pci_dev,
  624. "Port %d. XON detected in incoming data\n",
  625. port);
  626. }
  627. else if (cause == UART_17158_XOFF_DETECT) {
  628. if (!(brd->channels[port]->ch_flags & CH_STOP)) {
  629. ch->ch_flags |= CH_STOP;
  630. jsm_dbg(INTR, &ch->ch_bd->pci_dev,
  631. "Setting CH_STOP\n");
  632. }
  633. jsm_dbg(INTR, &ch->ch_bd->pci_dev,
  634. "Port: %d. XOFF detected in incoming data\n",
  635. 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_dbg(INTR, &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_dbg(INTR, &ch->ch_bd->pci_dev, "%s:%d port: %d linestatus: %x\n",
  680. __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_dbg(INTR, &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_dbg(INTR, &ch->ch_bd->pci_dev, "%s:%d Port: %d. PAR ERR!\n",
  706. __FILE__, __LINE__, port);
  707. }
  708. if (linestatus & UART_LSR_FE) {
  709. ch->ch_err_frame++;
  710. jsm_dbg(INTR, &ch->ch_bd->pci_dev, "%s:%d Port: %d. FRM ERR!\n",
  711. __FILE__, __LINE__, port);
  712. }
  713. if (linestatus & UART_LSR_BI) {
  714. ch->ch_err_break++;
  715. jsm_dbg(INTR, &ch->ch_bd->pci_dev,
  716. "%s:%d Port: %d. BRK INTR!\n",
  717. __FILE__, __LINE__, port);
  718. }
  719. if (linestatus & UART_LSR_OE) {
  720. /*
  721. * Rx Oruns. Exar says that an orun will NOT corrupt
  722. * the FIFO. It will just replace the holding register
  723. * with this new data byte. So basically just ignore this.
  724. * Probably we should eventually have an orun stat in our driver...
  725. */
  726. ch->ch_err_overrun++;
  727. jsm_dbg(INTR, &ch->ch_bd->pci_dev,
  728. "%s:%d Port: %d. Rx Overrun!\n",
  729. __FILE__, __LINE__, port);
  730. }
  731. if (linestatus & UART_LSR_THRE) {
  732. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  733. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  734. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  735. /* Transfer data (if any) from Write Queue -> UART. */
  736. neo_copy_data_from_queue_to_uart(ch);
  737. }
  738. else if (linestatus & UART_17158_TX_AND_FIFO_CLR) {
  739. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  740. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  741. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  742. /* Transfer data (if any) from Write Queue -> UART. */
  743. neo_copy_data_from_queue_to_uart(ch);
  744. }
  745. }
  746. /*
  747. * neo_param()
  748. * Send any/all changes to the line to the UART.
  749. */
  750. static void neo_param(struct jsm_channel *ch)
  751. {
  752. u8 lcr = 0;
  753. u8 uart_lcr, ier;
  754. u32 baud;
  755. int quot;
  756. struct jsm_board *bd;
  757. bd = ch->ch_bd;
  758. if (!bd)
  759. return;
  760. /*
  761. * If baud rate is zero, flush queues, and set mval to drop DTR.
  762. */
  763. if ((ch->ch_c_cflag & (CBAUD)) == 0) {
  764. ch->ch_r_head = ch->ch_r_tail = 0;
  765. ch->ch_e_head = ch->ch_e_tail = 0;
  766. neo_flush_uart_write(ch);
  767. neo_flush_uart_read(ch);
  768. ch->ch_flags |= (CH_BAUD0);
  769. ch->ch_mostat &= ~(UART_MCR_RTS | UART_MCR_DTR);
  770. neo_assert_modem_signals(ch);
  771. return;
  772. } else {
  773. int i;
  774. unsigned int cflag;
  775. static struct {
  776. unsigned int rate;
  777. unsigned int cflag;
  778. } baud_rates[] = {
  779. { 921600, B921600 },
  780. { 460800, B460800 },
  781. { 230400, B230400 },
  782. { 115200, B115200 },
  783. { 57600, B57600 },
  784. { 38400, B38400 },
  785. { 19200, B19200 },
  786. { 9600, B9600 },
  787. { 4800, B4800 },
  788. { 2400, B2400 },
  789. { 1200, B1200 },
  790. { 600, B600 },
  791. { 300, B300 },
  792. { 200, B200 },
  793. { 150, B150 },
  794. { 134, B134 },
  795. { 110, B110 },
  796. { 75, B75 },
  797. { 50, B50 },
  798. };
  799. cflag = C_BAUD(ch->uart_port.state->port.tty);
  800. baud = 9600;
  801. for (i = 0; i < ARRAY_SIZE(baud_rates); i++) {
  802. if (baud_rates[i].cflag == cflag) {
  803. baud = baud_rates[i].rate;
  804. break;
  805. }
  806. }
  807. if (ch->ch_flags & CH_BAUD0)
  808. ch->ch_flags &= ~(CH_BAUD0);
  809. }
  810. if (ch->ch_c_cflag & PARENB)
  811. lcr |= UART_LCR_PARITY;
  812. if (!(ch->ch_c_cflag & PARODD))
  813. lcr |= UART_LCR_EPAR;
  814. /*
  815. * Not all platforms support mark/space parity,
  816. * so this will hide behind an ifdef.
  817. */
  818. #ifdef CMSPAR
  819. if (ch->ch_c_cflag & CMSPAR)
  820. lcr |= UART_LCR_SPAR;
  821. #endif
  822. if (ch->ch_c_cflag & CSTOPB)
  823. lcr |= UART_LCR_STOP;
  824. switch (ch->ch_c_cflag & CSIZE) {
  825. case CS5:
  826. lcr |= UART_LCR_WLEN5;
  827. break;
  828. case CS6:
  829. lcr |= UART_LCR_WLEN6;
  830. break;
  831. case CS7:
  832. lcr |= UART_LCR_WLEN7;
  833. break;
  834. case CS8:
  835. default:
  836. lcr |= UART_LCR_WLEN8;
  837. break;
  838. }
  839. ier = readb(&ch->ch_neo_uart->ier);
  840. uart_lcr = readb(&ch->ch_neo_uart->lcr);
  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_dbg(INTR, &brd->pci_dev, "%s:%d uart_poll: %x\n",
  918. __FILE__, __LINE__, uart_poll);
  919. if (!uart_poll) {
  920. jsm_dbg(INTR, &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_dbg(INTR, &brd->pci_dev, "%s:%d port: %x type: %x\n",
  941. __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_dbg(INTR, &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_dbg(INTR, &brd->pci_dev,
  1001. "%s:%d Unknown Interrupt type: %x\n",
  1002. __FILE__, __LINE__, type);
  1003. continue;
  1004. }
  1005. }
  1006. spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags);
  1007. jsm_dbg(INTR, &brd->pci_dev, "finish\n");
  1008. return IRQ_HANDLED;
  1009. }
  1010. /*
  1011. * Neo specific way of turning off the receiver.
  1012. * Used as a way to enforce queue flow control when in
  1013. * hardware flow control mode.
  1014. */
  1015. static void neo_disable_receiver(struct jsm_channel *ch)
  1016. {
  1017. u8 tmp = readb(&ch->ch_neo_uart->ier);
  1018. tmp &= ~(UART_IER_RDI);
  1019. writeb(tmp, &ch->ch_neo_uart->ier);
  1020. /* flush write operation */
  1021. neo_pci_posting_flush(ch->ch_bd);
  1022. }
  1023. /*
  1024. * Neo specific way of turning on the receiver.
  1025. * Used as a way to un-enforce queue flow control when in
  1026. * hardware flow control mode.
  1027. */
  1028. static void neo_enable_receiver(struct jsm_channel *ch)
  1029. {
  1030. u8 tmp = readb(&ch->ch_neo_uart->ier);
  1031. tmp |= (UART_IER_RDI);
  1032. writeb(tmp, &ch->ch_neo_uart->ier);
  1033. /* flush write operation */
  1034. neo_pci_posting_flush(ch->ch_bd);
  1035. }
  1036. static void neo_send_start_character(struct jsm_channel *ch)
  1037. {
  1038. if (!ch)
  1039. return;
  1040. if (ch->ch_startc != __DISABLED_CHAR) {
  1041. ch->ch_xon_sends++;
  1042. writeb(ch->ch_startc, &ch->ch_neo_uart->txrx);
  1043. /* flush write operation */
  1044. neo_pci_posting_flush(ch->ch_bd);
  1045. }
  1046. }
  1047. static void neo_send_stop_character(struct jsm_channel *ch)
  1048. {
  1049. if (!ch)
  1050. return;
  1051. if (ch->ch_stopc != __DISABLED_CHAR) {
  1052. ch->ch_xoff_sends++;
  1053. writeb(ch->ch_stopc, &ch->ch_neo_uart->txrx);
  1054. /* flush write operation */
  1055. neo_pci_posting_flush(ch->ch_bd);
  1056. }
  1057. }
  1058. /*
  1059. * neo_uart_init
  1060. */
  1061. static void neo_uart_init(struct jsm_channel *ch)
  1062. {
  1063. writeb(0, &ch->ch_neo_uart->ier);
  1064. writeb(0, &ch->ch_neo_uart->efr);
  1065. writeb(UART_EFR_ECB, &ch->ch_neo_uart->efr);
  1066. /* Clear out UART and FIFO */
  1067. readb(&ch->ch_neo_uart->txrx);
  1068. writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr);
  1069. readb(&ch->ch_neo_uart->lsr);
  1070. readb(&ch->ch_neo_uart->msr);
  1071. ch->ch_flags |= CH_FIFO_ENABLED;
  1072. /* Assert any signals we want up */
  1073. writeb(ch->ch_mostat, &ch->ch_neo_uart->mcr);
  1074. }
  1075. /*
  1076. * Make the UART completely turn off.
  1077. */
  1078. static void neo_uart_off(struct jsm_channel *ch)
  1079. {
  1080. /* Turn off UART enhanced bits */
  1081. writeb(0, &ch->ch_neo_uart->efr);
  1082. /* Stop all interrupts from occurring. */
  1083. writeb(0, &ch->ch_neo_uart->ier);
  1084. }
  1085. static u32 neo_get_uart_bytes_left(struct jsm_channel *ch)
  1086. {
  1087. u8 left = 0;
  1088. u8 lsr = readb(&ch->ch_neo_uart->lsr);
  1089. /* We must cache the LSR as some of the bits get reset once read... */
  1090. ch->ch_cached_lsr |= lsr;
  1091. /* Determine whether the Transmitter is empty or not */
  1092. if (!(lsr & UART_LSR_TEMT))
  1093. left = 1;
  1094. else {
  1095. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  1096. left = 0;
  1097. }
  1098. return left;
  1099. }
  1100. /* Channel lock MUST be held by the calling function! */
  1101. static void neo_send_break(struct jsm_channel *ch)
  1102. {
  1103. /*
  1104. * Set the time we should stop sending the break.
  1105. * If we are already sending a break, toss away the existing
  1106. * time to stop, and use this new value instead.
  1107. */
  1108. /* Tell the UART to start sending the break */
  1109. if (!(ch->ch_flags & CH_BREAK_SENDING)) {
  1110. u8 temp = readb(&ch->ch_neo_uart->lcr);
  1111. writeb((temp | UART_LCR_SBC), &ch->ch_neo_uart->lcr);
  1112. ch->ch_flags |= (CH_BREAK_SENDING);
  1113. /* flush write operation */
  1114. neo_pci_posting_flush(ch->ch_bd);
  1115. }
  1116. }
  1117. /*
  1118. * neo_send_immediate_char.
  1119. *
  1120. * Sends a specific character as soon as possible to the UART,
  1121. * jumping over any bytes that might be in the write queue.
  1122. *
  1123. * The channel lock MUST be held by the calling function.
  1124. */
  1125. static void neo_send_immediate_char(struct jsm_channel *ch, unsigned char c)
  1126. {
  1127. if (!ch)
  1128. return;
  1129. writeb(c, &ch->ch_neo_uart->txrx);
  1130. /* flush write operation */
  1131. neo_pci_posting_flush(ch->ch_bd);
  1132. }
  1133. struct board_ops jsm_neo_ops = {
  1134. .intr = neo_intr,
  1135. .uart_init = neo_uart_init,
  1136. .uart_off = neo_uart_off,
  1137. .param = neo_param,
  1138. .assert_modem_signals = neo_assert_modem_signals,
  1139. .flush_uart_write = neo_flush_uart_write,
  1140. .flush_uart_read = neo_flush_uart_read,
  1141. .disable_receiver = neo_disable_receiver,
  1142. .enable_receiver = neo_enable_receiver,
  1143. .send_break = neo_send_break,
  1144. .clear_break = neo_clear_break,
  1145. .send_start_character = neo_send_start_character,
  1146. .send_stop_character = neo_send_stop_character,
  1147. .copy_data_from_queue_to_uart = neo_copy_data_from_queue_to_uart,
  1148. .get_uart_bytes_left = neo_get_uart_bytes_left,
  1149. .send_immediate_char = neo_send_immediate_char
  1150. };