jsm_neo.c 35 KB

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