jsm_neo.c 36 KB

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