dgnc_cls.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. /*
  2. * Copyright 2003 Digi International (www.digi.com)
  3. * Scott H Kilau <Scott_Kilau at digi dot com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2, or (at your option)
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
  12. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. * PURPOSE. See the GNU General Public License for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/sched.h> /* For jiffies, task states */
  17. #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
  18. #include <linux/delay.h> /* For udelay */
  19. #include <linux/io.h> /* For read[bwl]/write[bwl] */
  20. #include <linux/serial.h> /* For struct async_serial */
  21. #include <linux/serial_reg.h> /* For the various UART offsets */
  22. #include <linux/pci.h>
  23. #include "dgnc_driver.h" /* Driver main header file */
  24. #include "dgnc_cls.h"
  25. #include "dgnc_tty.h"
  26. static inline void cls_parse_isr(struct dgnc_board *brd, uint port);
  27. static inline void cls_clear_break(struct channel_t *ch, int force);
  28. static inline void cls_set_cts_flow_control(struct channel_t *ch);
  29. static inline void cls_set_rts_flow_control(struct channel_t *ch);
  30. static inline void cls_set_ixon_flow_control(struct channel_t *ch);
  31. static inline void cls_set_ixoff_flow_control(struct channel_t *ch);
  32. static inline void cls_set_no_output_flow_control(struct channel_t *ch);
  33. static inline void cls_set_no_input_flow_control(struct channel_t *ch);
  34. static void cls_parse_modem(struct channel_t *ch, unsigned char signals);
  35. static void cls_tasklet(unsigned long data);
  36. static void cls_vpd(struct dgnc_board *brd);
  37. static void cls_uart_init(struct channel_t *ch);
  38. static void cls_uart_off(struct channel_t *ch);
  39. static int cls_drain(struct tty_struct *tty, uint seconds);
  40. static void cls_param(struct tty_struct *tty);
  41. static void cls_assert_modem_signals(struct channel_t *ch);
  42. static void cls_flush_uart_write(struct channel_t *ch);
  43. static void cls_flush_uart_read(struct channel_t *ch);
  44. static void cls_disable_receiver(struct channel_t *ch);
  45. static void cls_enable_receiver(struct channel_t *ch);
  46. static void cls_send_break(struct channel_t *ch, int msecs);
  47. static void cls_send_start_character(struct channel_t *ch);
  48. static void cls_send_stop_character(struct channel_t *ch);
  49. static void cls_copy_data_from_uart_to_queue(struct channel_t *ch);
  50. static void cls_copy_data_from_queue_to_uart(struct channel_t *ch);
  51. static uint cls_get_uart_bytes_left(struct channel_t *ch);
  52. static void cls_send_immediate_char(struct channel_t *ch, unsigned char);
  53. static irqreturn_t cls_intr(int irq, void *voidbrd);
  54. struct board_ops dgnc_cls_ops = {
  55. .tasklet = cls_tasklet,
  56. .intr = cls_intr,
  57. .uart_init = cls_uart_init,
  58. .uart_off = cls_uart_off,
  59. .drain = cls_drain,
  60. .param = cls_param,
  61. .vpd = cls_vpd,
  62. .assert_modem_signals = cls_assert_modem_signals,
  63. .flush_uart_write = cls_flush_uart_write,
  64. .flush_uart_read = cls_flush_uart_read,
  65. .disable_receiver = cls_disable_receiver,
  66. .enable_receiver = cls_enable_receiver,
  67. .send_break = cls_send_break,
  68. .send_start_character = cls_send_start_character,
  69. .send_stop_character = cls_send_stop_character,
  70. .copy_data_from_queue_to_uart = cls_copy_data_from_queue_to_uart,
  71. .get_uart_bytes_left = cls_get_uart_bytes_left,
  72. .send_immediate_char = cls_send_immediate_char
  73. };
  74. static inline void cls_set_cts_flow_control(struct channel_t *ch)
  75. {
  76. unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
  77. unsigned char ier = readb(&ch->ch_cls_uart->ier);
  78. unsigned char isr_fcr = 0;
  79. /*
  80. * The Enhanced Register Set may only be accessed when
  81. * the Line Control Register is set to 0xBFh.
  82. */
  83. writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
  84. isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
  85. /* Turn on CTS flow control, turn off IXON flow control */
  86. isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_CTSDSR);
  87. isr_fcr &= ~(UART_EXAR654_EFR_IXON);
  88. writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
  89. /* Write old LCR value back out, which turns enhanced access off */
  90. writeb(lcrb, &ch->ch_cls_uart->lcr);
  91. /*
  92. * Enable interrupts for CTS flow, turn off interrupts for
  93. * received XOFF chars
  94. */
  95. ier |= (UART_EXAR654_IER_CTSDSR);
  96. ier &= ~(UART_EXAR654_IER_XOFF);
  97. writeb(ier, &ch->ch_cls_uart->ier);
  98. /* Set the usual FIFO values */
  99. writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
  100. writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_56 |
  101. UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
  102. &ch->ch_cls_uart->isr_fcr);
  103. ch->ch_t_tlevel = 16;
  104. }
  105. static inline void cls_set_ixon_flow_control(struct channel_t *ch)
  106. {
  107. unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
  108. unsigned char ier = readb(&ch->ch_cls_uart->ier);
  109. unsigned char isr_fcr = 0;
  110. /*
  111. * The Enhanced Register Set may only be accessed when
  112. * the Line Control Register is set to 0xBFh.
  113. */
  114. writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
  115. isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
  116. /* Turn on IXON flow control, turn off CTS flow control */
  117. isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_IXON);
  118. isr_fcr &= ~(UART_EXAR654_EFR_CTSDSR);
  119. writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
  120. /* Now set our current start/stop chars while in enhanced mode */
  121. writeb(ch->ch_startc, &ch->ch_cls_uart->mcr);
  122. writeb(0, &ch->ch_cls_uart->lsr);
  123. writeb(ch->ch_stopc, &ch->ch_cls_uart->msr);
  124. writeb(0, &ch->ch_cls_uart->spr);
  125. /* Write old LCR value back out, which turns enhanced access off */
  126. writeb(lcrb, &ch->ch_cls_uart->lcr);
  127. /*
  128. * Disable interrupts for CTS flow, turn on interrupts for
  129. * received XOFF chars
  130. */
  131. ier &= ~(UART_EXAR654_IER_CTSDSR);
  132. ier |= (UART_EXAR654_IER_XOFF);
  133. writeb(ier, &ch->ch_cls_uart->ier);
  134. /* Set the usual FIFO values */
  135. writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
  136. writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
  137. UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
  138. &ch->ch_cls_uart->isr_fcr);
  139. }
  140. static inline void cls_set_no_output_flow_control(struct channel_t *ch)
  141. {
  142. unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
  143. unsigned char ier = readb(&ch->ch_cls_uart->ier);
  144. unsigned char isr_fcr = 0;
  145. /*
  146. * The Enhanced Register Set may only be accessed when
  147. * the Line Control Register is set to 0xBFh.
  148. */
  149. writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
  150. isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
  151. /* Turn off IXON flow control, turn off CTS flow control */
  152. isr_fcr |= (UART_EXAR654_EFR_ECB);
  153. isr_fcr &= ~(UART_EXAR654_EFR_CTSDSR | UART_EXAR654_EFR_IXON);
  154. writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
  155. /* Write old LCR value back out, which turns enhanced access off */
  156. writeb(lcrb, &ch->ch_cls_uart->lcr);
  157. /*
  158. * Disable interrupts for CTS flow, turn off interrupts for
  159. * received XOFF chars
  160. */
  161. ier &= ~(UART_EXAR654_IER_CTSDSR);
  162. ier &= ~(UART_EXAR654_IER_XOFF);
  163. writeb(ier, &ch->ch_cls_uart->ier);
  164. /* Set the usual FIFO values */
  165. writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
  166. writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
  167. UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
  168. &ch->ch_cls_uart->isr_fcr);
  169. ch->ch_r_watermark = 0;
  170. ch->ch_t_tlevel = 16;
  171. ch->ch_r_tlevel = 16;
  172. }
  173. static inline void cls_set_rts_flow_control(struct channel_t *ch)
  174. {
  175. unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
  176. unsigned char ier = readb(&ch->ch_cls_uart->ier);
  177. unsigned char isr_fcr = 0;
  178. /*
  179. * The Enhanced Register Set may only be accessed when
  180. * the Line Control Register is set to 0xBFh.
  181. */
  182. writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
  183. isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
  184. /* Turn on RTS flow control, turn off IXOFF flow control */
  185. isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_RTSDTR);
  186. isr_fcr &= ~(UART_EXAR654_EFR_IXOFF);
  187. writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
  188. /* Write old LCR value back out, which turns enhanced access off */
  189. writeb(lcrb, &ch->ch_cls_uart->lcr);
  190. /* Enable interrupts for RTS flow */
  191. ier |= (UART_EXAR654_IER_RTSDTR);
  192. writeb(ier, &ch->ch_cls_uart->ier);
  193. /* Set the usual FIFO values */
  194. writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
  195. writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_56 |
  196. UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
  197. &ch->ch_cls_uart->isr_fcr);
  198. ch->ch_r_watermark = 4;
  199. ch->ch_r_tlevel = 8;
  200. }
  201. static inline void cls_set_ixoff_flow_control(struct channel_t *ch)
  202. {
  203. unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
  204. unsigned char ier = readb(&ch->ch_cls_uart->ier);
  205. unsigned char isr_fcr = 0;
  206. /*
  207. * The Enhanced Register Set may only be accessed when
  208. * the Line Control Register is set to 0xBFh.
  209. */
  210. writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
  211. isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
  212. /* Turn on IXOFF flow control, turn off RTS flow control */
  213. isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_IXOFF);
  214. isr_fcr &= ~(UART_EXAR654_EFR_RTSDTR);
  215. writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
  216. /* Now set our current start/stop chars while in enhanced mode */
  217. writeb(ch->ch_startc, &ch->ch_cls_uart->mcr);
  218. writeb(0, &ch->ch_cls_uart->lsr);
  219. writeb(ch->ch_stopc, &ch->ch_cls_uart->msr);
  220. writeb(0, &ch->ch_cls_uart->spr);
  221. /* Write old LCR value back out, which turns enhanced access off */
  222. writeb(lcrb, &ch->ch_cls_uart->lcr);
  223. /* Disable interrupts for RTS flow */
  224. ier &= ~(UART_EXAR654_IER_RTSDTR);
  225. writeb(ier, &ch->ch_cls_uart->ier);
  226. /* Set the usual FIFO values */
  227. writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
  228. writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
  229. UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
  230. &ch->ch_cls_uart->isr_fcr);
  231. }
  232. static inline void cls_set_no_input_flow_control(struct channel_t *ch)
  233. {
  234. unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
  235. unsigned char ier = readb(&ch->ch_cls_uart->ier);
  236. unsigned char isr_fcr = 0;
  237. /*
  238. * The Enhanced Register Set may only be accessed when
  239. * the Line Control Register is set to 0xBFh.
  240. */
  241. writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
  242. isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
  243. /* Turn off IXOFF flow control, turn off RTS flow control */
  244. isr_fcr |= (UART_EXAR654_EFR_ECB);
  245. isr_fcr &= ~(UART_EXAR654_EFR_RTSDTR | UART_EXAR654_EFR_IXOFF);
  246. writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
  247. /* Write old LCR value back out, which turns enhanced access off */
  248. writeb(lcrb, &ch->ch_cls_uart->lcr);
  249. /* Disable interrupts for RTS flow */
  250. ier &= ~(UART_EXAR654_IER_RTSDTR);
  251. writeb(ier, &ch->ch_cls_uart->ier);
  252. /* Set the usual FIFO values */
  253. writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
  254. writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
  255. UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
  256. &ch->ch_cls_uart->isr_fcr);
  257. ch->ch_t_tlevel = 16;
  258. ch->ch_r_tlevel = 16;
  259. }
  260. /*
  261. * cls_clear_break.
  262. * Determines whether its time to shut off break condition.
  263. *
  264. * No locks are assumed to be held when calling this function.
  265. * channel lock is held and released in this function.
  266. */
  267. static inline void cls_clear_break(struct channel_t *ch, int force)
  268. {
  269. unsigned long flags;
  270. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  271. return;
  272. spin_lock_irqsave(&ch->ch_lock, flags);
  273. /* Bail if we aren't currently sending a break. */
  274. if (!ch->ch_stop_sending_break) {
  275. spin_unlock_irqrestore(&ch->ch_lock, flags);
  276. return;
  277. }
  278. /* Turn break off, and unset some variables */
  279. if (ch->ch_flags & CH_BREAK_SENDING) {
  280. if (time_after(jiffies, ch->ch_stop_sending_break) || force) {
  281. unsigned char temp = readb(&ch->ch_cls_uart->lcr);
  282. writeb((temp & ~UART_LCR_SBC), &ch->ch_cls_uart->lcr);
  283. ch->ch_flags &= ~(CH_BREAK_SENDING);
  284. ch->ch_stop_sending_break = 0;
  285. }
  286. }
  287. spin_unlock_irqrestore(&ch->ch_lock, flags);
  288. }
  289. /* Parse the ISR register for the specific port */
  290. static inline void cls_parse_isr(struct dgnc_board *brd, uint port)
  291. {
  292. struct channel_t *ch;
  293. unsigned char isr = 0;
  294. unsigned long flags;
  295. /*
  296. * No need to verify board pointer, it was already
  297. * verified in the interrupt routine.
  298. */
  299. if (port >= brd->nasync)
  300. return;
  301. ch = brd->channels[port];
  302. if (ch->magic != DGNC_CHANNEL_MAGIC)
  303. return;
  304. /* Here we try to figure out what caused the interrupt to happen */
  305. while (1) {
  306. isr = readb(&ch->ch_cls_uart->isr_fcr);
  307. /* Bail if no pending interrupt on port */
  308. if (isr & UART_IIR_NO_INT)
  309. break;
  310. /* Receive Interrupt pending */
  311. if (isr & (UART_IIR_RDI | UART_IIR_RDI_TIMEOUT)) {
  312. /* Read data from uart -> queue */
  313. brd->intr_rx++;
  314. ch->ch_intr_rx++;
  315. cls_copy_data_from_uart_to_queue(ch);
  316. dgnc_check_queue_flow_control(ch);
  317. }
  318. /* Transmit Hold register empty pending */
  319. if (isr & UART_IIR_THRI) {
  320. /* Transfer data (if any) from Write Queue -> UART. */
  321. spin_lock_irqsave(&ch->ch_lock, flags);
  322. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  323. brd->intr_tx++;
  324. ch->ch_intr_tx++;
  325. spin_unlock_irqrestore(&ch->ch_lock, flags);
  326. cls_copy_data_from_queue_to_uart(ch);
  327. }
  328. /* CTS/RTS change of state */
  329. if (isr & UART_IIR_CTSRTS) {
  330. brd->intr_modem++;
  331. ch->ch_intr_modem++;
  332. /*
  333. * Don't need to do anything, the cls_parse_modem
  334. * below will grab the updated modem signals.
  335. */
  336. }
  337. /* Parse any modem signal changes */
  338. cls_parse_modem(ch, readb(&ch->ch_cls_uart->msr));
  339. }
  340. }
  341. /*
  342. * cls_param()
  343. * Send any/all changes to the line to the UART.
  344. */
  345. static void cls_param(struct tty_struct *tty)
  346. {
  347. unsigned char lcr = 0;
  348. unsigned char uart_lcr = 0;
  349. unsigned char ier = 0;
  350. unsigned char uart_ier = 0;
  351. uint baud = 9600;
  352. int quot = 0;
  353. struct dgnc_board *bd;
  354. struct channel_t *ch;
  355. struct un_t *un;
  356. if (!tty || tty->magic != TTY_MAGIC)
  357. return;
  358. un = (struct un_t *)tty->driver_data;
  359. if (!un || un->magic != DGNC_UNIT_MAGIC)
  360. return;
  361. ch = un->un_ch;
  362. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  363. return;
  364. bd = ch->ch_bd;
  365. if (!bd || bd->magic != DGNC_BOARD_MAGIC)
  366. return;
  367. /*
  368. * If baud rate is zero, flush queues, and set mval to drop DTR.
  369. */
  370. if ((ch->ch_c_cflag & (CBAUD)) == 0) {
  371. ch->ch_r_head = 0;
  372. ch->ch_r_tail = 0;
  373. ch->ch_e_head = 0;
  374. ch->ch_e_tail = 0;
  375. ch->ch_w_head = 0;
  376. ch->ch_w_tail = 0;
  377. cls_flush_uart_write(ch);
  378. cls_flush_uart_read(ch);
  379. /* The baudrate is B0 so all modem lines are to be dropped. */
  380. ch->ch_flags |= (CH_BAUD0);
  381. ch->ch_mostat &= ~(UART_MCR_RTS | UART_MCR_DTR);
  382. cls_assert_modem_signals(ch);
  383. ch->ch_old_baud = 0;
  384. return;
  385. } else if (ch->ch_custom_speed) {
  386. baud = ch->ch_custom_speed;
  387. /* Handle transition from B0 */
  388. if (ch->ch_flags & CH_BAUD0) {
  389. ch->ch_flags &= ~(CH_BAUD0);
  390. /*
  391. * Bring back up RTS and DTR...
  392. * Also handle RTS or DTR toggle if set.
  393. */
  394. if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
  395. ch->ch_mostat |= (UART_MCR_RTS);
  396. if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
  397. ch->ch_mostat |= (UART_MCR_DTR);
  398. }
  399. } else {
  400. int iindex = 0;
  401. int jindex = 0;
  402. ulong bauds[4][16] = {
  403. { /* slowbaud */
  404. 0, 50, 75, 110,
  405. 134, 150, 200, 300,
  406. 600, 1200, 1800, 2400,
  407. 4800, 9600, 19200, 38400 },
  408. { /* slowbaud & CBAUDEX */
  409. 0, 57600, 115200, 230400,
  410. 460800, 150, 200, 921600,
  411. 600, 1200, 1800, 2400,
  412. 4800, 9600, 19200, 38400 },
  413. { /* fastbaud */
  414. 0, 57600, 76800, 115200,
  415. 131657, 153600, 230400, 460800,
  416. 921600, 1200, 1800, 2400,
  417. 4800, 9600, 19200, 38400 },
  418. { /* fastbaud & CBAUDEX */
  419. 0, 57600, 115200, 230400,
  420. 460800, 150, 200, 921600,
  421. 600, 1200, 1800, 2400,
  422. 4800, 9600, 19200, 38400 }
  423. };
  424. /*
  425. * Only use the TXPrint baud rate if the terminal
  426. * unit is NOT open
  427. */
  428. if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
  429. (un->un_type == DGNC_PRINT))
  430. baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
  431. else
  432. baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
  433. if (ch->ch_c_cflag & CBAUDEX)
  434. iindex = 1;
  435. if (ch->ch_digi.digi_flags & DIGI_FAST)
  436. iindex += 2;
  437. jindex = baud;
  438. if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) &&
  439. (jindex < 16)) {
  440. baud = bauds[iindex][jindex];
  441. } else {
  442. baud = 0;
  443. }
  444. if (baud == 0)
  445. baud = 9600;
  446. /* Handle transition from B0 */
  447. if (ch->ch_flags & CH_BAUD0) {
  448. ch->ch_flags &= ~(CH_BAUD0);
  449. /*
  450. * Bring back up RTS and DTR...
  451. * Also handle RTS or DTR toggle if set.
  452. */
  453. if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
  454. ch->ch_mostat |= (UART_MCR_RTS);
  455. if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
  456. ch->ch_mostat |= (UART_MCR_DTR);
  457. }
  458. }
  459. if (ch->ch_c_cflag & PARENB)
  460. lcr |= UART_LCR_PARITY;
  461. if (!(ch->ch_c_cflag & PARODD))
  462. lcr |= UART_LCR_EPAR;
  463. /*
  464. * Not all platforms support mark/space parity,
  465. * so this will hide behind an ifdef.
  466. */
  467. #ifdef CMSPAR
  468. if (ch->ch_c_cflag & CMSPAR)
  469. lcr |= UART_LCR_SPAR;
  470. #endif
  471. if (ch->ch_c_cflag & CSTOPB)
  472. lcr |= UART_LCR_STOP;
  473. switch (ch->ch_c_cflag & CSIZE) {
  474. case CS5:
  475. lcr |= UART_LCR_WLEN5;
  476. break;
  477. case CS6:
  478. lcr |= UART_LCR_WLEN6;
  479. break;
  480. case CS7:
  481. lcr |= UART_LCR_WLEN7;
  482. break;
  483. case CS8:
  484. default:
  485. lcr |= UART_LCR_WLEN8;
  486. break;
  487. }
  488. uart_ier = readb(&ch->ch_cls_uart->ier);
  489. ier = uart_ier;
  490. uart_lcr = readb(&ch->ch_cls_uart->lcr);
  491. if (baud == 0)
  492. baud = 9600;
  493. quot = ch->ch_bd->bd_dividend / baud;
  494. if (quot != 0 && ch->ch_old_baud != baud) {
  495. ch->ch_old_baud = baud;
  496. writeb(UART_LCR_DLAB, &ch->ch_cls_uart->lcr);
  497. writeb((quot & 0xff), &ch->ch_cls_uart->txrx);
  498. writeb((quot >> 8), &ch->ch_cls_uart->ier);
  499. writeb(lcr, &ch->ch_cls_uart->lcr);
  500. }
  501. if (uart_lcr != lcr)
  502. writeb(lcr, &ch->ch_cls_uart->lcr);
  503. if (ch->ch_c_cflag & CREAD)
  504. ier |= (UART_IER_RDI | UART_IER_RLSI);
  505. else
  506. ier &= ~(UART_IER_RDI | UART_IER_RLSI);
  507. /*
  508. * Have the UART interrupt on modem signal changes ONLY when
  509. * we are in hardware flow control mode, or CLOCAL/FORCEDCD is not set.
  510. */
  511. if ((ch->ch_digi.digi_flags & CTSPACE) ||
  512. (ch->ch_digi.digi_flags & RTSPACE) ||
  513. (ch->ch_c_cflag & CRTSCTS) ||
  514. !(ch->ch_digi.digi_flags & DIGI_FORCEDCD) ||
  515. !(ch->ch_c_cflag & CLOCAL))
  516. ier |= UART_IER_MSI;
  517. else
  518. ier &= ~UART_IER_MSI;
  519. ier |= UART_IER_THRI;
  520. if (ier != uart_ier)
  521. writeb(ier, &ch->ch_cls_uart->ier);
  522. if (ch->ch_digi.digi_flags & CTSPACE || ch->ch_c_cflag & CRTSCTS) {
  523. cls_set_cts_flow_control(ch);
  524. } else if (ch->ch_c_iflag & IXON) {
  525. /*
  526. * If start/stop is set to disable, then we should
  527. * disable flow control
  528. */
  529. if ((ch->ch_startc == _POSIX_VDISABLE) ||
  530. (ch->ch_stopc == _POSIX_VDISABLE))
  531. cls_set_no_output_flow_control(ch);
  532. else
  533. cls_set_ixon_flow_control(ch);
  534. } else {
  535. cls_set_no_output_flow_control(ch);
  536. }
  537. if (ch->ch_digi.digi_flags & RTSPACE || ch->ch_c_cflag & CRTSCTS) {
  538. cls_set_rts_flow_control(ch);
  539. } else if (ch->ch_c_iflag & IXOFF) {
  540. /*
  541. * If start/stop is set to disable, then we should disable
  542. * flow control
  543. */
  544. if ((ch->ch_startc == _POSIX_VDISABLE) ||
  545. (ch->ch_stopc == _POSIX_VDISABLE))
  546. cls_set_no_input_flow_control(ch);
  547. else
  548. cls_set_ixoff_flow_control(ch);
  549. } else {
  550. cls_set_no_input_flow_control(ch);
  551. }
  552. cls_assert_modem_signals(ch);
  553. /* Get current status of the modem signals now */
  554. cls_parse_modem(ch, readb(&ch->ch_cls_uart->msr));
  555. }
  556. /*
  557. * Our board poller function.
  558. */
  559. static void cls_tasklet(unsigned long data)
  560. {
  561. struct dgnc_board *bd = (struct dgnc_board *)data;
  562. struct channel_t *ch;
  563. unsigned long flags;
  564. int i;
  565. int state = 0;
  566. int ports = 0;
  567. if (!bd || bd->magic != DGNC_BOARD_MAGIC)
  568. return;
  569. /* Cache a couple board values */
  570. spin_lock_irqsave(&bd->bd_lock, flags);
  571. state = bd->state;
  572. ports = bd->nasync;
  573. spin_unlock_irqrestore(&bd->bd_lock, flags);
  574. /*
  575. * Do NOT allow the interrupt routine to read the intr registers
  576. * Until we release this lock.
  577. */
  578. spin_lock_irqsave(&bd->bd_intr_lock, flags);
  579. /*
  580. * If board is ready, parse deeper to see if there is anything to do.
  581. */
  582. if ((state == BOARD_READY) && (ports > 0)) {
  583. /* Loop on each port */
  584. for (i = 0; i < ports; i++) {
  585. ch = bd->channels[i];
  586. /*
  587. * NOTE: Remember you CANNOT hold any channel
  588. * locks when calling input.
  589. * During input processing, its possible we
  590. * will call ld, which might do callbacks back
  591. * into us.
  592. */
  593. dgnc_input(ch);
  594. /*
  595. * Channel lock is grabbed and then released
  596. * inside this routine.
  597. */
  598. cls_copy_data_from_queue_to_uart(ch);
  599. dgnc_wakeup_writes(ch);
  600. /*
  601. * Check carrier function.
  602. */
  603. dgnc_carrier(ch);
  604. /*
  605. * The timing check of turning off the break is done
  606. * inside clear_break()
  607. */
  608. if (ch->ch_stop_sending_break)
  609. cls_clear_break(ch, 0);
  610. }
  611. }
  612. spin_unlock_irqrestore(&bd->bd_intr_lock, flags);
  613. }
  614. /*
  615. * cls_intr()
  616. *
  617. * Classic specific interrupt handler.
  618. */
  619. static irqreturn_t cls_intr(int irq, void *voidbrd)
  620. {
  621. struct dgnc_board *brd = voidbrd;
  622. uint i = 0;
  623. unsigned char poll_reg;
  624. unsigned long flags;
  625. /*
  626. * Check to make sure it didn't receive interrupt with a null board
  627. * associated or a board pointer that wasn't ours.
  628. */
  629. if (!brd || brd->magic != DGNC_BOARD_MAGIC)
  630. return IRQ_NONE;
  631. spin_lock_irqsave(&brd->bd_intr_lock, flags);
  632. brd->intr_count++;
  633. /*
  634. * Check the board's global interrupt offset to see if we
  635. * we actually do have an interrupt pending for us.
  636. */
  637. poll_reg = readb(brd->re_map_membase + UART_CLASSIC_POLL_ADDR_OFFSET);
  638. /* If 0, no interrupts pending */
  639. if (!poll_reg) {
  640. spin_unlock_irqrestore(&brd->bd_intr_lock, flags);
  641. return IRQ_NONE;
  642. }
  643. /* Parse each port to find out what caused the interrupt */
  644. for (i = 0; i < brd->nasync; i++)
  645. cls_parse_isr(brd, i);
  646. /*
  647. * Schedule tasklet to more in-depth servicing at a better time.
  648. */
  649. tasklet_schedule(&brd->helper_tasklet);
  650. spin_unlock_irqrestore(&brd->bd_intr_lock, flags);
  651. return IRQ_HANDLED;
  652. }
  653. static void cls_disable_receiver(struct channel_t *ch)
  654. {
  655. unsigned char tmp = readb(&ch->ch_cls_uart->ier);
  656. tmp &= ~(UART_IER_RDI);
  657. writeb(tmp, &ch->ch_cls_uart->ier);
  658. }
  659. static void cls_enable_receiver(struct channel_t *ch)
  660. {
  661. unsigned char tmp = readb(&ch->ch_cls_uart->ier);
  662. tmp |= (UART_IER_RDI);
  663. writeb(tmp, &ch->ch_cls_uart->ier);
  664. }
  665. static void cls_copy_data_from_uart_to_queue(struct channel_t *ch)
  666. {
  667. int qleft = 0;
  668. unsigned char linestatus = 0;
  669. unsigned char error_mask = 0;
  670. ushort head;
  671. ushort tail;
  672. unsigned long flags;
  673. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  674. return;
  675. spin_lock_irqsave(&ch->ch_lock, flags);
  676. /* cache head and tail of queue */
  677. head = ch->ch_r_head;
  678. tail = ch->ch_r_tail;
  679. /* Store how much space we have left in the queue */
  680. qleft = (tail - head - 1);
  681. if (qleft < 0)
  682. qleft += RQUEUEMASK + 1;
  683. /*
  684. * Create a mask to determine whether we should
  685. * insert the character (if any) into our queue.
  686. */
  687. if (ch->ch_c_iflag & IGNBRK)
  688. error_mask |= UART_LSR_BI;
  689. while (1) {
  690. linestatus = readb(&ch->ch_cls_uart->lsr);
  691. if (!(linestatus & (UART_LSR_DR)))
  692. break;
  693. /*
  694. * Discard character if we are ignoring the error mask.
  695. */
  696. if (linestatus & error_mask) {
  697. linestatus = 0;
  698. readb(&ch->ch_cls_uart->txrx);
  699. continue;
  700. }
  701. /*
  702. * If our queue is full, we have no choice but to drop some
  703. * data. The assumption is that HWFLOW or SWFLOW should have
  704. * stopped things way way before we got to this point.
  705. *
  706. * I decided that I wanted to ditch the oldest data first,
  707. * I hope thats okay with everyone? Yes? Good.
  708. */
  709. while (qleft < 1) {
  710. tail = (tail + 1) & RQUEUEMASK;
  711. ch->ch_r_tail = tail;
  712. ch->ch_err_overrun++;
  713. qleft++;
  714. }
  715. ch->ch_equeue[head] = linestatus & (UART_LSR_BI | UART_LSR_PE
  716. | UART_LSR_FE);
  717. ch->ch_rqueue[head] = readb(&ch->ch_cls_uart->txrx);
  718. qleft--;
  719. if (ch->ch_equeue[head] & UART_LSR_PE)
  720. ch->ch_err_parity++;
  721. if (ch->ch_equeue[head] & UART_LSR_BI)
  722. ch->ch_err_break++;
  723. if (ch->ch_equeue[head] & UART_LSR_FE)
  724. ch->ch_err_frame++;
  725. /* Add to, and flip head if needed */
  726. head = (head + 1) & RQUEUEMASK;
  727. ch->ch_rxcount++;
  728. }
  729. /*
  730. * Write new final heads to channel structure.
  731. */
  732. ch->ch_r_head = head & RQUEUEMASK;
  733. ch->ch_e_head = head & EQUEUEMASK;
  734. spin_unlock_irqrestore(&ch->ch_lock, flags);
  735. }
  736. /*
  737. * This function basically goes to sleep for secs, or until
  738. * it gets signalled that the port has fully drained.
  739. */
  740. static int cls_drain(struct tty_struct *tty, uint seconds)
  741. {
  742. unsigned long flags;
  743. struct channel_t *ch;
  744. struct un_t *un;
  745. if (!tty || tty->magic != TTY_MAGIC)
  746. return -ENXIO;
  747. un = (struct un_t *)tty->driver_data;
  748. if (!un || un->magic != DGNC_UNIT_MAGIC)
  749. return -ENXIO;
  750. ch = un->un_ch;
  751. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  752. return -ENXIO;
  753. spin_lock_irqsave(&ch->ch_lock, flags);
  754. un->un_flags |= UN_EMPTY;
  755. spin_unlock_irqrestore(&ch->ch_lock, flags);
  756. /*
  757. * NOTE: Do something with time passed in.
  758. */
  759. /* If ret is non-zero, user ctrl-c'ed us */
  760. return wait_event_interruptible(un->un_flags_wait,
  761. ((un->un_flags & UN_EMPTY) == 0));
  762. }
  763. /* Channel lock MUST be held before calling this function! */
  764. static void cls_flush_uart_write(struct channel_t *ch)
  765. {
  766. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  767. return;
  768. writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT),
  769. &ch->ch_cls_uart->isr_fcr);
  770. udelay(10);
  771. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  772. }
  773. /* Channel lock MUST be held before calling this function! */
  774. static void cls_flush_uart_read(struct channel_t *ch)
  775. {
  776. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  777. return;
  778. /*
  779. * For complete POSIX compatibility, we should be purging the
  780. * read FIFO in the UART here.
  781. *
  782. * However, clearing the read FIFO (UART_FCR_CLEAR_RCVR) also
  783. * incorrectly flushes write data as well as just basically trashing the
  784. * FIFO.
  785. *
  786. * Presumably, this is a bug in this UART.
  787. */
  788. udelay(10);
  789. }
  790. static void cls_copy_data_from_queue_to_uart(struct channel_t *ch)
  791. {
  792. ushort head;
  793. ushort tail;
  794. int n;
  795. int qlen;
  796. uint len_written = 0;
  797. unsigned long flags;
  798. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  799. return;
  800. spin_lock_irqsave(&ch->ch_lock, flags);
  801. /* No data to write to the UART */
  802. if (ch->ch_w_tail == ch->ch_w_head)
  803. goto exit_unlock;
  804. /* If port is "stopped", don't send any data to the UART */
  805. if ((ch->ch_flags & CH_FORCED_STOP) ||
  806. (ch->ch_flags & CH_BREAK_SENDING))
  807. goto exit_unlock;
  808. if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM)))
  809. goto exit_unlock;
  810. n = 32;
  811. /* cache head and tail of queue */
  812. head = ch->ch_w_head & WQUEUEMASK;
  813. tail = ch->ch_w_tail & WQUEUEMASK;
  814. qlen = (head - tail) & WQUEUEMASK;
  815. /* Find minimum of the FIFO space, versus queue length */
  816. n = min(n, qlen);
  817. while (n > 0) {
  818. /*
  819. * If RTS Toggle mode is on, turn on RTS now if not already set,
  820. * and make sure we get an event when the data transfer has
  821. * completed.
  822. */
  823. if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
  824. if (!(ch->ch_mostat & UART_MCR_RTS)) {
  825. ch->ch_mostat |= (UART_MCR_RTS);
  826. cls_assert_modem_signals(ch);
  827. }
  828. ch->ch_tun.un_flags |= (UN_EMPTY);
  829. }
  830. /*
  831. * If DTR Toggle mode is on, turn on DTR now if not already set,
  832. * and make sure we get an event when the data transfer has
  833. * completed.
  834. */
  835. if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
  836. if (!(ch->ch_mostat & UART_MCR_DTR)) {
  837. ch->ch_mostat |= (UART_MCR_DTR);
  838. cls_assert_modem_signals(ch);
  839. }
  840. ch->ch_tun.un_flags |= (UN_EMPTY);
  841. }
  842. writeb(ch->ch_wqueue[ch->ch_w_tail], &ch->ch_cls_uart->txrx);
  843. ch->ch_w_tail++;
  844. ch->ch_w_tail &= WQUEUEMASK;
  845. ch->ch_txcount++;
  846. len_written++;
  847. n--;
  848. }
  849. if (len_written > 0)
  850. ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  851. exit_unlock:
  852. spin_unlock_irqrestore(&ch->ch_lock, flags);
  853. }
  854. static void cls_parse_modem(struct channel_t *ch, unsigned char signals)
  855. {
  856. unsigned char msignals = signals;
  857. unsigned long flags;
  858. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  859. return;
  860. /*
  861. * Do altpin switching. Altpin switches DCD and DSR.
  862. * This prolly breaks DSRPACE, so we should be more clever here.
  863. */
  864. spin_lock_irqsave(&ch->ch_lock, flags);
  865. if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
  866. unsigned char mswap = signals;
  867. if (mswap & UART_MSR_DDCD) {
  868. msignals &= ~UART_MSR_DDCD;
  869. msignals |= UART_MSR_DDSR;
  870. }
  871. if (mswap & UART_MSR_DDSR) {
  872. msignals &= ~UART_MSR_DDSR;
  873. msignals |= UART_MSR_DDCD;
  874. }
  875. if (mswap & UART_MSR_DCD) {
  876. msignals &= ~UART_MSR_DCD;
  877. msignals |= UART_MSR_DSR;
  878. }
  879. if (mswap & UART_MSR_DSR) {
  880. msignals &= ~UART_MSR_DSR;
  881. msignals |= UART_MSR_DCD;
  882. }
  883. }
  884. spin_unlock_irqrestore(&ch->ch_lock, flags);
  885. /*
  886. * Scrub off lower bits. They signify delta's, which I don't
  887. * care about
  888. */
  889. signals &= 0xf0;
  890. spin_lock_irqsave(&ch->ch_lock, flags);
  891. if (msignals & UART_MSR_DCD)
  892. ch->ch_mistat |= UART_MSR_DCD;
  893. else
  894. ch->ch_mistat &= ~UART_MSR_DCD;
  895. if (msignals & UART_MSR_DSR)
  896. ch->ch_mistat |= UART_MSR_DSR;
  897. else
  898. ch->ch_mistat &= ~UART_MSR_DSR;
  899. if (msignals & UART_MSR_RI)
  900. ch->ch_mistat |= UART_MSR_RI;
  901. else
  902. ch->ch_mistat &= ~UART_MSR_RI;
  903. if (msignals & UART_MSR_CTS)
  904. ch->ch_mistat |= UART_MSR_CTS;
  905. else
  906. ch->ch_mistat &= ~UART_MSR_CTS;
  907. spin_unlock_irqrestore(&ch->ch_lock, flags);
  908. }
  909. /* Make the UART raise any of the output signals we want up */
  910. static void cls_assert_modem_signals(struct channel_t *ch)
  911. {
  912. unsigned char out;
  913. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  914. return;
  915. out = ch->ch_mostat;
  916. if (ch->ch_flags & CH_LOOPBACK)
  917. out |= UART_MCR_LOOP;
  918. writeb(out, &ch->ch_cls_uart->mcr);
  919. /* Give time for the UART to actually drop the signals */
  920. udelay(10);
  921. }
  922. static void cls_send_start_character(struct channel_t *ch)
  923. {
  924. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  925. return;
  926. if (ch->ch_startc != _POSIX_VDISABLE) {
  927. ch->ch_xon_sends++;
  928. writeb(ch->ch_startc, &ch->ch_cls_uart->txrx);
  929. }
  930. }
  931. static void cls_send_stop_character(struct channel_t *ch)
  932. {
  933. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  934. return;
  935. if (ch->ch_stopc != _POSIX_VDISABLE) {
  936. ch->ch_xoff_sends++;
  937. writeb(ch->ch_stopc, &ch->ch_cls_uart->txrx);
  938. }
  939. }
  940. /* Inits UART */
  941. static void cls_uart_init(struct channel_t *ch)
  942. {
  943. unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
  944. unsigned char isr_fcr = 0;
  945. writeb(0, &ch->ch_cls_uart->ier);
  946. /*
  947. * The Enhanced Register Set may only be accessed when
  948. * the Line Control Register is set to 0xBFh.
  949. */
  950. writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
  951. isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
  952. /* Turn on Enhanced/Extended controls */
  953. isr_fcr |= (UART_EXAR654_EFR_ECB);
  954. writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
  955. /* Write old LCR value back out, which turns enhanced access off */
  956. writeb(lcrb, &ch->ch_cls_uart->lcr);
  957. /* Clear out UART and FIFO */
  958. readb(&ch->ch_cls_uart->txrx);
  959. writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT),
  960. &ch->ch_cls_uart->isr_fcr);
  961. udelay(10);
  962. ch->ch_flags |= (CH_FIFO_ENABLED | CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  963. readb(&ch->ch_cls_uart->lsr);
  964. readb(&ch->ch_cls_uart->msr);
  965. }
  966. /*
  967. * Turns off UART.
  968. */
  969. static void cls_uart_off(struct channel_t *ch)
  970. {
  971. writeb(0, &ch->ch_cls_uart->ier);
  972. }
  973. /*
  974. * cls_get_uarts_bytes_left.
  975. * Returns 0 is nothing left in the FIFO, returns 1 otherwise.
  976. *
  977. * The channel lock MUST be held by the calling function.
  978. */
  979. static uint cls_get_uart_bytes_left(struct channel_t *ch)
  980. {
  981. unsigned char left = 0;
  982. unsigned char lsr = 0;
  983. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  984. return 0;
  985. lsr = readb(&ch->ch_cls_uart->lsr);
  986. /* Determine whether the Transmitter is empty or not */
  987. if (!(lsr & UART_LSR_TEMT)) {
  988. if (ch->ch_flags & CH_TX_FIFO_EMPTY)
  989. tasklet_schedule(&ch->ch_bd->helper_tasklet);
  990. left = 1;
  991. } else {
  992. ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
  993. left = 0;
  994. }
  995. return left;
  996. }
  997. /*
  998. * cls_send_break.
  999. * Starts sending a break thru the UART.
  1000. *
  1001. * The channel lock MUST be held by the calling function.
  1002. */
  1003. static void cls_send_break(struct channel_t *ch, int msecs)
  1004. {
  1005. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  1006. return;
  1007. /*
  1008. * If we receive a time of 0, this means turn off the break.
  1009. */
  1010. if (msecs == 0) {
  1011. /* Turn break off, and unset some variables */
  1012. if (ch->ch_flags & CH_BREAK_SENDING) {
  1013. unsigned char temp = readb(&ch->ch_cls_uart->lcr);
  1014. writeb((temp & ~UART_LCR_SBC), &ch->ch_cls_uart->lcr);
  1015. ch->ch_flags &= ~(CH_BREAK_SENDING);
  1016. ch->ch_stop_sending_break = 0;
  1017. }
  1018. return;
  1019. }
  1020. /*
  1021. * Set the time we should stop sending the break.
  1022. * If we are already sending a break, toss away the existing
  1023. * time to stop, and use this new value instead.
  1024. */
  1025. ch->ch_stop_sending_break = jiffies + dgnc_jiffies_from_ms(msecs);
  1026. /* Tell the UART to start sending the break */
  1027. if (!(ch->ch_flags & CH_BREAK_SENDING)) {
  1028. unsigned char temp = readb(&ch->ch_cls_uart->lcr);
  1029. writeb((temp | UART_LCR_SBC), &ch->ch_cls_uart->lcr);
  1030. ch->ch_flags |= (CH_BREAK_SENDING);
  1031. }
  1032. }
  1033. /*
  1034. * cls_send_immediate_char.
  1035. * Sends a specific character as soon as possible to the UART,
  1036. * jumping over any bytes that might be in the write queue.
  1037. *
  1038. * The channel lock MUST be held by the calling function.
  1039. */
  1040. static void cls_send_immediate_char(struct channel_t *ch, unsigned char c)
  1041. {
  1042. if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
  1043. return;
  1044. writeb(c, &ch->ch_cls_uart->txrx);
  1045. }
  1046. static void cls_vpd(struct dgnc_board *brd)
  1047. {
  1048. ulong vpdbase; /* Start of io base of the card */
  1049. u8 __iomem *re_map_vpdbase;/* Remapped memory of the card */
  1050. int i = 0;
  1051. vpdbase = pci_resource_start(brd->pdev, 3);
  1052. /* No VPD */
  1053. if (!vpdbase)
  1054. return;
  1055. re_map_vpdbase = ioremap(vpdbase, 0x400);
  1056. if (!re_map_vpdbase)
  1057. return;
  1058. /* Store the VPD into our buffer */
  1059. for (i = 0; i < 0x40; i++) {
  1060. brd->vpd[i] = readb(re_map_vpdbase + i);
  1061. pr_info("%x ", brd->vpd[i]);
  1062. }
  1063. pr_info("\n");
  1064. iounmap(re_map_vpdbase);
  1065. }