sunsab.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  1. /* sunsab.c: ASYNC Driver for the SIEMENS SAB82532 DUSCC.
  2. *
  3. * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
  4. * Copyright (C) 2002 David S. Miller (davem@redhat.com)
  5. *
  6. * Rewrote buffer handling to use CIRC(Circular Buffer) macros.
  7. * Maxim Krasnyanskiy <maxk@qualcomm.com>
  8. *
  9. * Fixed to use tty_get_baud_rate, and to allow for arbitrary baud
  10. * rates to be programmed into the UART. Also eliminated a lot of
  11. * duplicated code in the console setup.
  12. * Theodore Ts'o <tytso@mit.edu>, 2001-Oct-12
  13. *
  14. * Ported to new 2.5.x UART layer.
  15. * David S. Miller <davem@redhat.com>
  16. */
  17. #include <linux/config.h>
  18. #include <linux/module.h>
  19. #include <linux/kernel.h>
  20. #include <linux/sched.h>
  21. #include <linux/errno.h>
  22. #include <linux/tty.h>
  23. #include <linux/tty_flip.h>
  24. #include <linux/major.h>
  25. #include <linux/string.h>
  26. #include <linux/ptrace.h>
  27. #include <linux/ioport.h>
  28. #include <linux/circ_buf.h>
  29. #include <linux/serial.h>
  30. #include <linux/sysrq.h>
  31. #include <linux/console.h>
  32. #include <linux/spinlock.h>
  33. #include <linux/slab.h>
  34. #include <linux/delay.h>
  35. #include <linux/init.h>
  36. #include <asm/io.h>
  37. #include <asm/irq.h>
  38. #include <asm/oplib.h>
  39. #include <asm/ebus.h>
  40. #if defined(CONFIG_SERIAL_SUNZILOG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  41. #define SUPPORT_SYSRQ
  42. #endif
  43. #include <linux/serial_core.h>
  44. #include "suncore.h"
  45. #include "sunsab.h"
  46. struct uart_sunsab_port {
  47. struct uart_port port; /* Generic UART port */
  48. union sab82532_async_regs __iomem *regs; /* Chip registers */
  49. unsigned long irqflags; /* IRQ state flags */
  50. int dsr; /* Current DSR state */
  51. unsigned int cec_timeout; /* Chip poll timeout... */
  52. unsigned int tec_timeout; /* likewise */
  53. unsigned char interrupt_mask0;/* ISR0 masking */
  54. unsigned char interrupt_mask1;/* ISR1 masking */
  55. unsigned char pvr_dtr_bit; /* Which PVR bit is DTR */
  56. unsigned char pvr_dsr_bit; /* Which PVR bit is DSR */
  57. int type; /* SAB82532 version */
  58. /* Setting configuration bits while the transmitter is active
  59. * can cause garbage characters to get emitted by the chip.
  60. * Therefore, we cache such writes here and do the real register
  61. * write the next time the transmitter becomes idle.
  62. */
  63. unsigned int cached_ebrg;
  64. unsigned char cached_mode;
  65. unsigned char cached_pvr;
  66. unsigned char cached_dafo;
  67. };
  68. /*
  69. * This assumes you have a 29.4912 MHz clock for your UART.
  70. */
  71. #define SAB_BASE_BAUD ( 29491200 / 16 )
  72. static char *sab82532_version[16] = {
  73. "V1.0", "V2.0", "V3.2", "V(0x03)",
  74. "V(0x04)", "V(0x05)", "V(0x06)", "V(0x07)",
  75. "V(0x08)", "V(0x09)", "V(0x0a)", "V(0x0b)",
  76. "V(0x0c)", "V(0x0d)", "V(0x0e)", "V(0x0f)"
  77. };
  78. #define SAB82532_MAX_TEC_TIMEOUT 200000 /* 1 character time (at 50 baud) */
  79. #define SAB82532_MAX_CEC_TIMEOUT 50000 /* 2.5 TX CLKs (at 50 baud) */
  80. #define SAB82532_RECV_FIFO_SIZE 32 /* Standard async fifo sizes */
  81. #define SAB82532_XMIT_FIFO_SIZE 32
  82. static __inline__ void sunsab_tec_wait(struct uart_sunsab_port *up)
  83. {
  84. int timeout = up->tec_timeout;
  85. while ((readb(&up->regs->r.star) & SAB82532_STAR_TEC) && --timeout)
  86. udelay(1);
  87. }
  88. static __inline__ void sunsab_cec_wait(struct uart_sunsab_port *up)
  89. {
  90. int timeout = up->cec_timeout;
  91. while ((readb(&up->regs->r.star) & SAB82532_STAR_CEC) && --timeout)
  92. udelay(1);
  93. }
  94. static struct tty_struct *
  95. receive_chars(struct uart_sunsab_port *up,
  96. union sab82532_irq_status *stat,
  97. struct pt_regs *regs)
  98. {
  99. struct tty_struct *tty = NULL;
  100. unsigned char buf[32];
  101. int saw_console_brk = 0;
  102. int free_fifo = 0;
  103. int count = 0;
  104. int i;
  105. if (up->port.info != NULL) /* Unopened serial console */
  106. tty = up->port.info->tty;
  107. /* Read number of BYTES (Character + Status) available. */
  108. if (stat->sreg.isr0 & SAB82532_ISR0_RPF) {
  109. count = SAB82532_RECV_FIFO_SIZE;
  110. free_fifo++;
  111. }
  112. if (stat->sreg.isr0 & SAB82532_ISR0_TCD) {
  113. count = readb(&up->regs->r.rbcl) & (SAB82532_RECV_FIFO_SIZE - 1);
  114. free_fifo++;
  115. }
  116. /* Issue a FIFO read command in case we where idle. */
  117. if (stat->sreg.isr0 & SAB82532_ISR0_TIME) {
  118. sunsab_cec_wait(up);
  119. writeb(SAB82532_CMDR_RFRD, &up->regs->w.cmdr);
  120. return tty;
  121. }
  122. if (stat->sreg.isr0 & SAB82532_ISR0_RFO)
  123. free_fifo++;
  124. /* Read the FIFO. */
  125. for (i = 0; i < count; i++)
  126. buf[i] = readb(&up->regs->r.rfifo[i]);
  127. /* Issue Receive Message Complete command. */
  128. if (free_fifo) {
  129. sunsab_cec_wait(up);
  130. writeb(SAB82532_CMDR_RMC, &up->regs->w.cmdr);
  131. }
  132. /* Count may be zero for BRK, so we check for it here */
  133. if ((stat->sreg.isr1 & SAB82532_ISR1_BRK) &&
  134. (up->port.line == up->port.cons->index))
  135. saw_console_brk = 1;
  136. for (i = 0; i < count; i++) {
  137. unsigned char ch = buf[i];
  138. if (tty == NULL) {
  139. uart_handle_sysrq_char(&up->port, ch, regs);
  140. continue;
  141. }
  142. if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
  143. tty->flip.work.func((void *)tty);
  144. if (tty->flip.count >= TTY_FLIPBUF_SIZE)
  145. return tty; // if TTY_DONT_FLIP is set
  146. }
  147. *tty->flip.char_buf_ptr = ch;
  148. *tty->flip.flag_buf_ptr = TTY_NORMAL;
  149. up->port.icount.rx++;
  150. if (unlikely(stat->sreg.isr0 & (SAB82532_ISR0_PERR |
  151. SAB82532_ISR0_FERR |
  152. SAB82532_ISR0_RFO)) ||
  153. unlikely(stat->sreg.isr1 & SAB82532_ISR1_BRK)) {
  154. /*
  155. * For statistics only
  156. */
  157. if (stat->sreg.isr1 & SAB82532_ISR1_BRK) {
  158. stat->sreg.isr0 &= ~(SAB82532_ISR0_PERR |
  159. SAB82532_ISR0_FERR);
  160. up->port.icount.brk++;
  161. /*
  162. * We do the SysRQ and SAK checking
  163. * here because otherwise the break
  164. * may get masked by ignore_status_mask
  165. * or read_status_mask.
  166. */
  167. if (uart_handle_break(&up->port))
  168. continue;
  169. } else if (stat->sreg.isr0 & SAB82532_ISR0_PERR)
  170. up->port.icount.parity++;
  171. else if (stat->sreg.isr0 & SAB82532_ISR0_FERR)
  172. up->port.icount.frame++;
  173. if (stat->sreg.isr0 & SAB82532_ISR0_RFO)
  174. up->port.icount.overrun++;
  175. /*
  176. * Mask off conditions which should be ingored.
  177. */
  178. stat->sreg.isr0 &= (up->port.read_status_mask & 0xff);
  179. stat->sreg.isr1 &= ((up->port.read_status_mask >> 8) & 0xff);
  180. if (stat->sreg.isr1 & SAB82532_ISR1_BRK) {
  181. *tty->flip.flag_buf_ptr = TTY_BREAK;
  182. } else if (stat->sreg.isr0 & SAB82532_ISR0_PERR)
  183. *tty->flip.flag_buf_ptr = TTY_PARITY;
  184. else if (stat->sreg.isr0 & SAB82532_ISR0_FERR)
  185. *tty->flip.flag_buf_ptr = TTY_FRAME;
  186. }
  187. if (uart_handle_sysrq_char(&up->port, ch, regs))
  188. continue;
  189. if ((stat->sreg.isr0 & (up->port.ignore_status_mask & 0xff)) == 0 &&
  190. (stat->sreg.isr1 & ((up->port.ignore_status_mask >> 8) & 0xff)) == 0){
  191. tty->flip.flag_buf_ptr++;
  192. tty->flip.char_buf_ptr++;
  193. tty->flip.count++;
  194. }
  195. if ((stat->sreg.isr0 & SAB82532_ISR0_RFO) &&
  196. tty->flip.count < TTY_FLIPBUF_SIZE) {
  197. /*
  198. * Overrun is special, since it's reported
  199. * immediately, and doesn't affect the current
  200. * character.
  201. */
  202. *tty->flip.flag_buf_ptr = TTY_OVERRUN;
  203. tty->flip.flag_buf_ptr++;
  204. tty->flip.char_buf_ptr++;
  205. tty->flip.count++;
  206. }
  207. }
  208. if (saw_console_brk)
  209. sun_do_break();
  210. return tty;
  211. }
  212. static void sunsab_stop_tx(struct uart_port *);
  213. static void sunsab_tx_idle(struct uart_sunsab_port *);
  214. static void transmit_chars(struct uart_sunsab_port *up,
  215. union sab82532_irq_status *stat)
  216. {
  217. struct circ_buf *xmit = &up->port.info->xmit;
  218. int i;
  219. if (stat->sreg.isr1 & SAB82532_ISR1_ALLS) {
  220. up->interrupt_mask1 |= SAB82532_IMR1_ALLS;
  221. writeb(up->interrupt_mask1, &up->regs->w.imr1);
  222. set_bit(SAB82532_ALLS, &up->irqflags);
  223. }
  224. #if 0 /* bde@nwlink.com says this check causes problems */
  225. if (!(stat->sreg.isr1 & SAB82532_ISR1_XPR))
  226. return;
  227. #endif
  228. if (!(readb(&up->regs->r.star) & SAB82532_STAR_XFW))
  229. return;
  230. set_bit(SAB82532_XPR, &up->irqflags);
  231. sunsab_tx_idle(up);
  232. if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
  233. up->interrupt_mask1 |= SAB82532_IMR1_XPR;
  234. writeb(up->interrupt_mask1, &up->regs->w.imr1);
  235. uart_write_wakeup(&up->port);
  236. return;
  237. }
  238. up->interrupt_mask1 &= ~(SAB82532_IMR1_ALLS|SAB82532_IMR1_XPR);
  239. writeb(up->interrupt_mask1, &up->regs->w.imr1);
  240. clear_bit(SAB82532_ALLS, &up->irqflags);
  241. /* Stuff 32 bytes into Transmit FIFO. */
  242. clear_bit(SAB82532_XPR, &up->irqflags);
  243. for (i = 0; i < up->port.fifosize; i++) {
  244. writeb(xmit->buf[xmit->tail],
  245. &up->regs->w.xfifo[i]);
  246. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  247. up->port.icount.tx++;
  248. if (uart_circ_empty(xmit))
  249. break;
  250. }
  251. /* Issue a Transmit Frame command. */
  252. sunsab_cec_wait(up);
  253. writeb(SAB82532_CMDR_XF, &up->regs->w.cmdr);
  254. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  255. uart_write_wakeup(&up->port);
  256. if (uart_circ_empty(xmit))
  257. sunsab_stop_tx(&up->port);
  258. }
  259. static void check_status(struct uart_sunsab_port *up,
  260. union sab82532_irq_status *stat)
  261. {
  262. if (stat->sreg.isr0 & SAB82532_ISR0_CDSC)
  263. uart_handle_dcd_change(&up->port,
  264. !(readb(&up->regs->r.vstr) & SAB82532_VSTR_CD));
  265. if (stat->sreg.isr1 & SAB82532_ISR1_CSC)
  266. uart_handle_cts_change(&up->port,
  267. (readb(&up->regs->r.star) & SAB82532_STAR_CTS));
  268. if ((readb(&up->regs->r.pvr) & up->pvr_dsr_bit) ^ up->dsr) {
  269. up->dsr = (readb(&up->regs->r.pvr) & up->pvr_dsr_bit) ? 0 : 1;
  270. up->port.icount.dsr++;
  271. }
  272. wake_up_interruptible(&up->port.info->delta_msr_wait);
  273. }
  274. static irqreturn_t sunsab_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  275. {
  276. struct uart_sunsab_port *up = dev_id;
  277. struct tty_struct *tty;
  278. union sab82532_irq_status status;
  279. unsigned long flags;
  280. spin_lock_irqsave(&up->port.lock, flags);
  281. status.stat = 0;
  282. if (readb(&up->regs->r.gis) & SAB82532_GIS_ISA0)
  283. status.sreg.isr0 = readb(&up->regs->r.isr0);
  284. if (readb(&up->regs->r.gis) & SAB82532_GIS_ISA1)
  285. status.sreg.isr1 = readb(&up->regs->r.isr1);
  286. tty = NULL;
  287. if (status.stat) {
  288. if ((status.sreg.isr0 & (SAB82532_ISR0_TCD | SAB82532_ISR0_TIME |
  289. SAB82532_ISR0_RFO | SAB82532_ISR0_RPF)) ||
  290. (status.sreg.isr1 & SAB82532_ISR1_BRK))
  291. tty = receive_chars(up, &status, regs);
  292. if ((status.sreg.isr0 & SAB82532_ISR0_CDSC) ||
  293. (status.sreg.isr1 & SAB82532_ISR1_CSC))
  294. check_status(up, &status);
  295. if (status.sreg.isr1 & (SAB82532_ISR1_ALLS | SAB82532_ISR1_XPR))
  296. transmit_chars(up, &status);
  297. }
  298. spin_unlock(&up->port.lock);
  299. if (tty)
  300. tty_flip_buffer_push(tty);
  301. up++;
  302. spin_lock(&up->port.lock);
  303. status.stat = 0;
  304. if (readb(&up->regs->r.gis) & SAB82532_GIS_ISB0)
  305. status.sreg.isr0 = readb(&up->regs->r.isr0);
  306. if (readb(&up->regs->r.gis) & SAB82532_GIS_ISB1)
  307. status.sreg.isr1 = readb(&up->regs->r.isr1);
  308. tty = NULL;
  309. if (status.stat) {
  310. if ((status.sreg.isr0 & (SAB82532_ISR0_TCD | SAB82532_ISR0_TIME |
  311. SAB82532_ISR0_RFO | SAB82532_ISR0_RPF)) ||
  312. (status.sreg.isr1 & SAB82532_ISR1_BRK))
  313. tty = receive_chars(up, &status, regs);
  314. if ((status.sreg.isr0 & SAB82532_ISR0_CDSC) ||
  315. (status.sreg.isr1 & (SAB82532_ISR1_BRK | SAB82532_ISR1_CSC)))
  316. check_status(up, &status);
  317. if (status.sreg.isr1 & (SAB82532_ISR1_ALLS | SAB82532_ISR1_XPR))
  318. transmit_chars(up, &status);
  319. }
  320. spin_unlock_irqrestore(&up->port.lock, flags);
  321. if (tty)
  322. tty_flip_buffer_push(tty);
  323. return IRQ_HANDLED;
  324. }
  325. /* port->lock is not held. */
  326. static unsigned int sunsab_tx_empty(struct uart_port *port)
  327. {
  328. struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
  329. int ret;
  330. /* Do not need a lock for a state test like this. */
  331. if (test_bit(SAB82532_ALLS, &up->irqflags))
  332. ret = TIOCSER_TEMT;
  333. else
  334. ret = 0;
  335. return ret;
  336. }
  337. /* port->lock held by caller. */
  338. static void sunsab_set_mctrl(struct uart_port *port, unsigned int mctrl)
  339. {
  340. struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
  341. if (mctrl & TIOCM_RTS) {
  342. up->cached_mode &= ~SAB82532_MODE_FRTS;
  343. up->cached_mode |= SAB82532_MODE_RTS;
  344. } else {
  345. up->cached_mode |= (SAB82532_MODE_FRTS |
  346. SAB82532_MODE_RTS);
  347. }
  348. if (mctrl & TIOCM_DTR) {
  349. up->cached_pvr &= ~(up->pvr_dtr_bit);
  350. } else {
  351. up->cached_pvr |= up->pvr_dtr_bit;
  352. }
  353. set_bit(SAB82532_REGS_PENDING, &up->irqflags);
  354. if (test_bit(SAB82532_XPR, &up->irqflags))
  355. sunsab_tx_idle(up);
  356. }
  357. /* port->lock is held by caller and interrupts are disabled. */
  358. static unsigned int sunsab_get_mctrl(struct uart_port *port)
  359. {
  360. struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
  361. unsigned char val;
  362. unsigned int result;
  363. result = 0;
  364. val = readb(&up->regs->r.pvr);
  365. result |= (val & up->pvr_dsr_bit) ? 0 : TIOCM_DSR;
  366. val = readb(&up->regs->r.vstr);
  367. result |= (val & SAB82532_VSTR_CD) ? 0 : TIOCM_CAR;
  368. val = readb(&up->regs->r.star);
  369. result |= (val & SAB82532_STAR_CTS) ? TIOCM_CTS : 0;
  370. return result;
  371. }
  372. /* port->lock held by caller. */
  373. static void sunsab_stop_tx(struct uart_port *port)
  374. {
  375. struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
  376. up->interrupt_mask1 |= SAB82532_IMR1_XPR;
  377. writeb(up->interrupt_mask1, &up->regs->w.imr1);
  378. }
  379. /* port->lock held by caller. */
  380. static void sunsab_tx_idle(struct uart_sunsab_port *up)
  381. {
  382. if (test_bit(SAB82532_REGS_PENDING, &up->irqflags)) {
  383. u8 tmp;
  384. clear_bit(SAB82532_REGS_PENDING, &up->irqflags);
  385. writeb(up->cached_mode, &up->regs->rw.mode);
  386. writeb(up->cached_pvr, &up->regs->rw.pvr);
  387. writeb(up->cached_dafo, &up->regs->w.dafo);
  388. writeb(up->cached_ebrg & 0xff, &up->regs->w.bgr);
  389. tmp = readb(&up->regs->rw.ccr2);
  390. tmp &= ~0xc0;
  391. tmp |= (up->cached_ebrg >> 2) & 0xc0;
  392. writeb(tmp, &up->regs->rw.ccr2);
  393. }
  394. }
  395. /* port->lock held by caller. */
  396. static void sunsab_start_tx(struct uart_port *port)
  397. {
  398. struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
  399. struct circ_buf *xmit = &up->port.info->xmit;
  400. int i;
  401. up->interrupt_mask1 &= ~(SAB82532_IMR1_ALLS|SAB82532_IMR1_XPR);
  402. writeb(up->interrupt_mask1, &up->regs->w.imr1);
  403. if (!test_bit(SAB82532_XPR, &up->irqflags))
  404. return;
  405. clear_bit(SAB82532_ALLS, &up->irqflags);
  406. clear_bit(SAB82532_XPR, &up->irqflags);
  407. for (i = 0; i < up->port.fifosize; i++) {
  408. writeb(xmit->buf[xmit->tail],
  409. &up->regs->w.xfifo[i]);
  410. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  411. up->port.icount.tx++;
  412. if (uart_circ_empty(xmit))
  413. break;
  414. }
  415. /* Issue a Transmit Frame command. */
  416. sunsab_cec_wait(up);
  417. writeb(SAB82532_CMDR_XF, &up->regs->w.cmdr);
  418. }
  419. /* port->lock is not held. */
  420. static void sunsab_send_xchar(struct uart_port *port, char ch)
  421. {
  422. struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
  423. unsigned long flags;
  424. spin_lock_irqsave(&up->port.lock, flags);
  425. sunsab_tec_wait(up);
  426. writeb(ch, &up->regs->w.tic);
  427. spin_unlock_irqrestore(&up->port.lock, flags);
  428. }
  429. /* port->lock held by caller. */
  430. static void sunsab_stop_rx(struct uart_port *port)
  431. {
  432. struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
  433. up->interrupt_mask0 |= SAB82532_ISR0_TCD;
  434. writeb(up->interrupt_mask1, &up->regs->w.imr0);
  435. }
  436. /* port->lock held by caller. */
  437. static void sunsab_enable_ms(struct uart_port *port)
  438. {
  439. /* For now we always receive these interrupts. */
  440. }
  441. /* port->lock is not held. */
  442. static void sunsab_break_ctl(struct uart_port *port, int break_state)
  443. {
  444. struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
  445. unsigned long flags;
  446. unsigned char val;
  447. spin_lock_irqsave(&up->port.lock, flags);
  448. val = up->cached_dafo;
  449. if (break_state)
  450. val |= SAB82532_DAFO_XBRK;
  451. else
  452. val &= ~SAB82532_DAFO_XBRK;
  453. up->cached_dafo = val;
  454. set_bit(SAB82532_REGS_PENDING, &up->irqflags);
  455. if (test_bit(SAB82532_XPR, &up->irqflags))
  456. sunsab_tx_idle(up);
  457. spin_unlock_irqrestore(&up->port.lock, flags);
  458. }
  459. /* port->lock is not held. */
  460. static int sunsab_startup(struct uart_port *port)
  461. {
  462. struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
  463. unsigned long flags;
  464. unsigned char tmp;
  465. spin_lock_irqsave(&up->port.lock, flags);
  466. /*
  467. * Wait for any commands or immediate characters
  468. */
  469. sunsab_cec_wait(up);
  470. sunsab_tec_wait(up);
  471. /*
  472. * Clear the FIFO buffers.
  473. */
  474. writeb(SAB82532_CMDR_RRES, &up->regs->w.cmdr);
  475. sunsab_cec_wait(up);
  476. writeb(SAB82532_CMDR_XRES, &up->regs->w.cmdr);
  477. /*
  478. * Clear the interrupt registers.
  479. */
  480. (void) readb(&up->regs->r.isr0);
  481. (void) readb(&up->regs->r.isr1);
  482. /*
  483. * Now, initialize the UART
  484. */
  485. writeb(0, &up->regs->w.ccr0); /* power-down */
  486. writeb(SAB82532_CCR0_MCE | SAB82532_CCR0_SC_NRZ |
  487. SAB82532_CCR0_SM_ASYNC, &up->regs->w.ccr0);
  488. writeb(SAB82532_CCR1_ODS | SAB82532_CCR1_BCR | 7, &up->regs->w.ccr1);
  489. writeb(SAB82532_CCR2_BDF | SAB82532_CCR2_SSEL |
  490. SAB82532_CCR2_TOE, &up->regs->w.ccr2);
  491. writeb(0, &up->regs->w.ccr3);
  492. writeb(SAB82532_CCR4_MCK4 | SAB82532_CCR4_EBRG, &up->regs->w.ccr4);
  493. up->cached_mode = (SAB82532_MODE_RTS | SAB82532_MODE_FCTS |
  494. SAB82532_MODE_RAC);
  495. writeb(up->cached_mode, &up->regs->w.mode);
  496. writeb(SAB82532_RFC_DPS|SAB82532_RFC_RFTH_32, &up->regs->w.rfc);
  497. tmp = readb(&up->regs->rw.ccr0);
  498. tmp |= SAB82532_CCR0_PU; /* power-up */
  499. writeb(tmp, &up->regs->rw.ccr0);
  500. /*
  501. * Finally, enable interrupts
  502. */
  503. up->interrupt_mask0 = (SAB82532_IMR0_PERR | SAB82532_IMR0_FERR |
  504. SAB82532_IMR0_PLLA);
  505. writeb(up->interrupt_mask0, &up->regs->w.imr0);
  506. up->interrupt_mask1 = (SAB82532_IMR1_BRKT | SAB82532_IMR1_ALLS |
  507. SAB82532_IMR1_XOFF | SAB82532_IMR1_TIN |
  508. SAB82532_IMR1_CSC | SAB82532_IMR1_XON |
  509. SAB82532_IMR1_XPR);
  510. writeb(up->interrupt_mask1, &up->regs->w.imr1);
  511. set_bit(SAB82532_ALLS, &up->irqflags);
  512. set_bit(SAB82532_XPR, &up->irqflags);
  513. spin_unlock_irqrestore(&up->port.lock, flags);
  514. return 0;
  515. }
  516. /* port->lock is not held. */
  517. static void sunsab_shutdown(struct uart_port *port)
  518. {
  519. struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
  520. unsigned long flags;
  521. spin_lock_irqsave(&up->port.lock, flags);
  522. /* Disable Interrupts */
  523. up->interrupt_mask0 = 0xff;
  524. writeb(up->interrupt_mask0, &up->regs->w.imr0);
  525. up->interrupt_mask1 = 0xff;
  526. writeb(up->interrupt_mask1, &up->regs->w.imr1);
  527. /* Disable break condition */
  528. up->cached_dafo = readb(&up->regs->rw.dafo);
  529. up->cached_dafo &= ~SAB82532_DAFO_XBRK;
  530. writeb(up->cached_dafo, &up->regs->rw.dafo);
  531. /* Disable Receiver */
  532. up->cached_mode &= ~SAB82532_MODE_RAC;
  533. writeb(up->cached_mode, &up->regs->rw.mode);
  534. /*
  535. * XXX FIXME
  536. *
  537. * If the chip is powered down here the system hangs/crashes during
  538. * reboot or shutdown. This needs to be investigated further,
  539. * similar behaviour occurs in 2.4 when the driver is configured
  540. * as a module only. One hint may be that data is sometimes
  541. * transmitted at 9600 baud during shutdown (regardless of the
  542. * speed the chip was configured for when the port was open).
  543. */
  544. #if 0
  545. /* Power Down */
  546. tmp = readb(&up->regs->rw.ccr0);
  547. tmp &= ~SAB82532_CCR0_PU;
  548. writeb(tmp, &up->regs->rw.ccr0);
  549. #endif
  550. spin_unlock_irqrestore(&up->port.lock, flags);
  551. }
  552. /*
  553. * This is used to figure out the divisor speeds.
  554. *
  555. * The formula is: Baud = SAB_BASE_BAUD / ((N + 1) * (1 << M)),
  556. *
  557. * with 0 <= N < 64 and 0 <= M < 16
  558. */
  559. static void calc_ebrg(int baud, int *n_ret, int *m_ret)
  560. {
  561. int n, m;
  562. if (baud == 0) {
  563. *n_ret = 0;
  564. *m_ret = 0;
  565. return;
  566. }
  567. /*
  568. * We scale numbers by 10 so that we get better accuracy
  569. * without having to use floating point. Here we increment m
  570. * until n is within the valid range.
  571. */
  572. n = (SAB_BASE_BAUD * 10) / baud;
  573. m = 0;
  574. while (n >= 640) {
  575. n = n / 2;
  576. m++;
  577. }
  578. n = (n+5) / 10;
  579. /*
  580. * We try very hard to avoid speeds with M == 0 since they may
  581. * not work correctly for XTAL frequences above 10 MHz.
  582. */
  583. if ((m == 0) && ((n & 1) == 0)) {
  584. n = n / 2;
  585. m++;
  586. }
  587. *n_ret = n - 1;
  588. *m_ret = m;
  589. }
  590. /* Internal routine, port->lock is held and local interrupts are disabled. */
  591. static void sunsab_convert_to_sab(struct uart_sunsab_port *up, unsigned int cflag,
  592. unsigned int iflag, unsigned int baud,
  593. unsigned int quot)
  594. {
  595. unsigned char dafo;
  596. int bits, n, m;
  597. /* Byte size and parity */
  598. switch (cflag & CSIZE) {
  599. case CS5: dafo = SAB82532_DAFO_CHL5; bits = 7; break;
  600. case CS6: dafo = SAB82532_DAFO_CHL6; bits = 8; break;
  601. case CS7: dafo = SAB82532_DAFO_CHL7; bits = 9; break;
  602. case CS8: dafo = SAB82532_DAFO_CHL8; bits = 10; break;
  603. /* Never happens, but GCC is too dumb to figure it out */
  604. default: dafo = SAB82532_DAFO_CHL5; bits = 7; break;
  605. }
  606. if (cflag & CSTOPB) {
  607. dafo |= SAB82532_DAFO_STOP;
  608. bits++;
  609. }
  610. if (cflag & PARENB) {
  611. dafo |= SAB82532_DAFO_PARE;
  612. bits++;
  613. }
  614. if (cflag & PARODD) {
  615. dafo |= SAB82532_DAFO_PAR_ODD;
  616. } else {
  617. dafo |= SAB82532_DAFO_PAR_EVEN;
  618. }
  619. up->cached_dafo = dafo;
  620. calc_ebrg(baud, &n, &m);
  621. up->cached_ebrg = n | (m << 6);
  622. up->tec_timeout = (10 * 1000000) / baud;
  623. up->cec_timeout = up->tec_timeout >> 2;
  624. /* CTS flow control flags */
  625. /* We encode read_status_mask and ignore_status_mask like so:
  626. *
  627. * ---------------------
  628. * | ... | ISR1 | ISR0 |
  629. * ---------------------
  630. * .. 15 8 7 0
  631. */
  632. up->port.read_status_mask = (SAB82532_ISR0_TCD | SAB82532_ISR0_TIME |
  633. SAB82532_ISR0_RFO | SAB82532_ISR0_RPF |
  634. SAB82532_ISR0_CDSC);
  635. up->port.read_status_mask |= (SAB82532_ISR1_CSC |
  636. SAB82532_ISR1_ALLS |
  637. SAB82532_ISR1_XPR) << 8;
  638. if (iflag & INPCK)
  639. up->port.read_status_mask |= (SAB82532_ISR0_PERR |
  640. SAB82532_ISR0_FERR);
  641. if (iflag & (BRKINT | PARMRK))
  642. up->port.read_status_mask |= (SAB82532_ISR1_BRK << 8);
  643. /*
  644. * Characteres to ignore
  645. */
  646. up->port.ignore_status_mask = 0;
  647. if (iflag & IGNPAR)
  648. up->port.ignore_status_mask |= (SAB82532_ISR0_PERR |
  649. SAB82532_ISR0_FERR);
  650. if (iflag & IGNBRK) {
  651. up->port.ignore_status_mask |= (SAB82532_ISR1_BRK << 8);
  652. /*
  653. * If we're ignoring parity and break indicators,
  654. * ignore overruns too (for real raw support).
  655. */
  656. if (iflag & IGNPAR)
  657. up->port.ignore_status_mask |= SAB82532_ISR0_RFO;
  658. }
  659. /*
  660. * ignore all characters if CREAD is not set
  661. */
  662. if ((cflag & CREAD) == 0)
  663. up->port.ignore_status_mask |= (SAB82532_ISR0_RPF |
  664. SAB82532_ISR0_TCD);
  665. uart_update_timeout(&up->port, cflag,
  666. (up->port.uartclk / (16 * quot)));
  667. /* Now schedule a register update when the chip's
  668. * transmitter is idle.
  669. */
  670. up->cached_mode |= SAB82532_MODE_RAC;
  671. set_bit(SAB82532_REGS_PENDING, &up->irqflags);
  672. if (test_bit(SAB82532_XPR, &up->irqflags))
  673. sunsab_tx_idle(up);
  674. }
  675. /* port->lock is not held. */
  676. static void sunsab_set_termios(struct uart_port *port, struct termios *termios,
  677. struct termios *old)
  678. {
  679. struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
  680. unsigned long flags;
  681. unsigned int baud = uart_get_baud_rate(port, termios, old, 0, 4000000);
  682. unsigned int quot = uart_get_divisor(port, baud);
  683. spin_lock_irqsave(&up->port.lock, flags);
  684. sunsab_convert_to_sab(up, termios->c_cflag, termios->c_iflag, baud, quot);
  685. spin_unlock_irqrestore(&up->port.lock, flags);
  686. }
  687. static const char *sunsab_type(struct uart_port *port)
  688. {
  689. struct uart_sunsab_port *up = (void *)port;
  690. static char buf[36];
  691. sprintf(buf, "SAB82532 %s", sab82532_version[up->type]);
  692. return buf;
  693. }
  694. static void sunsab_release_port(struct uart_port *port)
  695. {
  696. }
  697. static int sunsab_request_port(struct uart_port *port)
  698. {
  699. return 0;
  700. }
  701. static void sunsab_config_port(struct uart_port *port, int flags)
  702. {
  703. }
  704. static int sunsab_verify_port(struct uart_port *port, struct serial_struct *ser)
  705. {
  706. return -EINVAL;
  707. }
  708. static struct uart_ops sunsab_pops = {
  709. .tx_empty = sunsab_tx_empty,
  710. .set_mctrl = sunsab_set_mctrl,
  711. .get_mctrl = sunsab_get_mctrl,
  712. .stop_tx = sunsab_stop_tx,
  713. .start_tx = sunsab_start_tx,
  714. .send_xchar = sunsab_send_xchar,
  715. .stop_rx = sunsab_stop_rx,
  716. .enable_ms = sunsab_enable_ms,
  717. .break_ctl = sunsab_break_ctl,
  718. .startup = sunsab_startup,
  719. .shutdown = sunsab_shutdown,
  720. .set_termios = sunsab_set_termios,
  721. .type = sunsab_type,
  722. .release_port = sunsab_release_port,
  723. .request_port = sunsab_request_port,
  724. .config_port = sunsab_config_port,
  725. .verify_port = sunsab_verify_port,
  726. };
  727. static struct uart_driver sunsab_reg = {
  728. .owner = THIS_MODULE,
  729. .driver_name = "serial",
  730. .devfs_name = "tts/",
  731. .dev_name = "ttyS",
  732. .major = TTY_MAJOR,
  733. };
  734. static struct uart_sunsab_port *sunsab_ports;
  735. static int num_channels;
  736. #ifdef CONFIG_SERIAL_SUNSAB_CONSOLE
  737. static __inline__ void sunsab_console_putchar(struct uart_sunsab_port *up, char c)
  738. {
  739. unsigned long flags;
  740. spin_lock_irqsave(&up->port.lock, flags);
  741. sunsab_tec_wait(up);
  742. writeb(c, &up->regs->w.tic);
  743. spin_unlock_irqrestore(&up->port.lock, flags);
  744. }
  745. static void sunsab_console_write(struct console *con, const char *s, unsigned n)
  746. {
  747. struct uart_sunsab_port *up = &sunsab_ports[con->index];
  748. int i;
  749. for (i = 0; i < n; i++) {
  750. if (*s == '\n')
  751. sunsab_console_putchar(up, '\r');
  752. sunsab_console_putchar(up, *s++);
  753. }
  754. sunsab_tec_wait(up);
  755. }
  756. static int sunsab_console_setup(struct console *con, char *options)
  757. {
  758. struct uart_sunsab_port *up = &sunsab_ports[con->index];
  759. unsigned long flags;
  760. unsigned int baud, quot;
  761. printk("Console: ttyS%d (SAB82532)\n",
  762. (sunsab_reg.minor - 64) + con->index);
  763. sunserial_console_termios(con);
  764. /* Firmware console speed is limited to 150-->38400 baud so
  765. * this hackish cflag thing is OK.
  766. */
  767. switch (con->cflag & CBAUD) {
  768. case B150: baud = 150; break;
  769. case B300: baud = 300; break;
  770. case B600: baud = 600; break;
  771. case B1200: baud = 1200; break;
  772. case B2400: baud = 2400; break;
  773. case B4800: baud = 4800; break;
  774. default: case B9600: baud = 9600; break;
  775. case B19200: baud = 19200; break;
  776. case B38400: baud = 38400; break;
  777. };
  778. /*
  779. * Temporary fix.
  780. */
  781. spin_lock_init(&up->port.lock);
  782. /*
  783. * Initialize the hardware
  784. */
  785. sunsab_startup(&up->port);
  786. spin_lock_irqsave(&up->port.lock, flags);
  787. /*
  788. * Finally, enable interrupts
  789. */
  790. up->interrupt_mask0 = SAB82532_IMR0_PERR | SAB82532_IMR0_FERR |
  791. SAB82532_IMR0_PLLA | SAB82532_IMR0_CDSC;
  792. writeb(up->interrupt_mask0, &up->regs->w.imr0);
  793. up->interrupt_mask1 = SAB82532_IMR1_BRKT | SAB82532_IMR1_ALLS |
  794. SAB82532_IMR1_XOFF | SAB82532_IMR1_TIN |
  795. SAB82532_IMR1_CSC | SAB82532_IMR1_XON |
  796. SAB82532_IMR1_XPR;
  797. writeb(up->interrupt_mask1, &up->regs->w.imr1);
  798. quot = uart_get_divisor(&up->port, baud);
  799. sunsab_convert_to_sab(up, con->cflag, 0, baud, quot);
  800. sunsab_set_mctrl(&up->port, TIOCM_DTR | TIOCM_RTS);
  801. spin_unlock_irqrestore(&up->port.lock, flags);
  802. return 0;
  803. }
  804. static struct console sunsab_console = {
  805. .name = "ttyS",
  806. .write = sunsab_console_write,
  807. .device = uart_console_device,
  808. .setup = sunsab_console_setup,
  809. .flags = CON_PRINTBUFFER,
  810. .index = -1,
  811. .data = &sunsab_reg,
  812. };
  813. #define SUNSAB_CONSOLE (&sunsab_console)
  814. static void __init sunsab_console_init(void)
  815. {
  816. int i;
  817. if (con_is_present())
  818. return;
  819. for (i = 0; i < num_channels; i++) {
  820. int this_minor = sunsab_reg.minor + i;
  821. if ((this_minor - 64) == (serial_console - 1))
  822. break;
  823. }
  824. if (i == num_channels)
  825. return;
  826. sunsab_console.index = i;
  827. register_console(&sunsab_console);
  828. }
  829. #else
  830. #define SUNSAB_CONSOLE (NULL)
  831. #define sunsab_console_init() do { } while (0)
  832. #endif
  833. static void __init for_each_sab_edev(void (*callback)(struct linux_ebus_device *, void *), void *arg)
  834. {
  835. struct linux_ebus *ebus;
  836. struct linux_ebus_device *edev = NULL;
  837. for_each_ebus(ebus) {
  838. for_each_ebusdev(edev, ebus) {
  839. if (!strcmp(edev->prom_name, "se")) {
  840. callback(edev, arg);
  841. continue;
  842. } else if (!strcmp(edev->prom_name, "serial")) {
  843. char compat[32];
  844. int clen;
  845. /* On RIO this can be an SE, check it. We could
  846. * just check ebus->is_rio, but this is more portable.
  847. */
  848. clen = prom_getproperty(edev->prom_node, "compatible",
  849. compat, sizeof(compat));
  850. if (clen > 0) {
  851. if (strncmp(compat, "sab82532", 8) == 0) {
  852. callback(edev, arg);
  853. continue;
  854. }
  855. }
  856. }
  857. }
  858. }
  859. }
  860. static void __init sab_count_callback(struct linux_ebus_device *edev, void *arg)
  861. {
  862. int *count_p = arg;
  863. (*count_p)++;
  864. }
  865. static void __init sab_attach_callback(struct linux_ebus_device *edev, void *arg)
  866. {
  867. int *instance_p = arg;
  868. struct uart_sunsab_port *up;
  869. unsigned long regs, offset;
  870. int i;
  871. /* Note: ports are located in reverse order */
  872. regs = edev->resource[0].start;
  873. offset = sizeof(union sab82532_async_regs);
  874. for (i = 0; i < 2; i++) {
  875. up = &sunsab_ports[(*instance_p * 2) + 1 - i];
  876. memset(up, 0, sizeof(*up));
  877. up->regs = ioremap(regs + offset, sizeof(union sab82532_async_regs));
  878. up->port.irq = edev->irqs[0];
  879. up->port.fifosize = SAB82532_XMIT_FIFO_SIZE;
  880. up->port.mapbase = (unsigned long)up->regs;
  881. up->port.iotype = SERIAL_IO_MEM;
  882. writeb(SAB82532_IPC_IC_ACT_LOW, &up->regs->w.ipc);
  883. offset -= sizeof(union sab82532_async_regs);
  884. }
  885. (*instance_p)++;
  886. }
  887. static int __init probe_for_sabs(void)
  888. {
  889. int this_sab = 0;
  890. /* Find device instances. */
  891. for_each_sab_edev(&sab_count_callback, &this_sab);
  892. if (!this_sab)
  893. return -ENODEV;
  894. /* Allocate tables. */
  895. sunsab_ports = kmalloc(sizeof(struct uart_sunsab_port) * this_sab * 2,
  896. GFP_KERNEL);
  897. if (!sunsab_ports)
  898. return -ENOMEM;
  899. num_channels = this_sab * 2;
  900. this_sab = 0;
  901. for_each_sab_edev(&sab_attach_callback, &this_sab);
  902. return 0;
  903. }
  904. static void __init sunsab_init_hw(void)
  905. {
  906. int i;
  907. for (i = 0; i < num_channels; i++) {
  908. struct uart_sunsab_port *up = &sunsab_ports[i];
  909. up->port.line = i;
  910. up->port.ops = &sunsab_pops;
  911. up->port.type = PORT_SUNSAB;
  912. up->port.uartclk = SAB_BASE_BAUD;
  913. up->type = readb(&up->regs->r.vstr) & 0x0f;
  914. writeb(~((1 << 1) | (1 << 2) | (1 << 4)), &up->regs->w.pcr);
  915. writeb(0xff, &up->regs->w.pim);
  916. if (up->port.line == 0) {
  917. up->pvr_dsr_bit = (1 << 0);
  918. up->pvr_dtr_bit = (1 << 1);
  919. } else {
  920. up->pvr_dsr_bit = (1 << 3);
  921. up->pvr_dtr_bit = (1 << 2);
  922. }
  923. up->cached_pvr = (1 << 1) | (1 << 2) | (1 << 4);
  924. writeb(up->cached_pvr, &up->regs->w.pvr);
  925. up->cached_mode = readb(&up->regs->rw.mode);
  926. up->cached_mode |= SAB82532_MODE_FRTS;
  927. writeb(up->cached_mode, &up->regs->rw.mode);
  928. up->cached_mode |= SAB82532_MODE_RTS;
  929. writeb(up->cached_mode, &up->regs->rw.mode);
  930. up->tec_timeout = SAB82532_MAX_TEC_TIMEOUT;
  931. up->cec_timeout = SAB82532_MAX_CEC_TIMEOUT;
  932. if (!(up->port.line & 0x01)) {
  933. if (request_irq(up->port.irq, sunsab_interrupt,
  934. SA_SHIRQ, "serial(sab82532)", up)) {
  935. printk("sunsab%d: can't get IRQ %x\n",
  936. i, up->port.irq);
  937. continue;
  938. }
  939. }
  940. }
  941. }
  942. static int __init sunsab_init(void)
  943. {
  944. int ret = probe_for_sabs();
  945. int i;
  946. if (ret < 0)
  947. return ret;
  948. sunsab_init_hw();
  949. sunsab_reg.minor = sunserial_current_minor;
  950. sunsab_reg.nr = num_channels;
  951. sunsab_reg.cons = SUNSAB_CONSOLE;
  952. ret = uart_register_driver(&sunsab_reg);
  953. if (ret < 0) {
  954. int i;
  955. for (i = 0; i < num_channels; i++) {
  956. struct uart_sunsab_port *up = &sunsab_ports[i];
  957. if (!(up->port.line & 0x01))
  958. free_irq(up->port.irq, up);
  959. iounmap(up->regs);
  960. }
  961. kfree(sunsab_ports);
  962. sunsab_ports = NULL;
  963. return ret;
  964. }
  965. sunserial_current_minor += num_channels;
  966. sunsab_console_init();
  967. for (i = 0; i < num_channels; i++) {
  968. struct uart_sunsab_port *up = &sunsab_ports[i];
  969. uart_add_one_port(&sunsab_reg, &up->port);
  970. }
  971. return 0;
  972. }
  973. static void __exit sunsab_exit(void)
  974. {
  975. int i;
  976. for (i = 0; i < num_channels; i++) {
  977. struct uart_sunsab_port *up = &sunsab_ports[i];
  978. uart_remove_one_port(&sunsab_reg, &up->port);
  979. if (!(up->port.line & 0x01))
  980. free_irq(up->port.irq, up);
  981. iounmap(up->regs);
  982. }
  983. sunserial_current_minor -= num_channels;
  984. uart_unregister_driver(&sunsab_reg);
  985. kfree(sunsab_ports);
  986. sunsab_ports = NULL;
  987. }
  988. module_init(sunsab_init);
  989. module_exit(sunsab_exit);
  990. MODULE_AUTHOR("Eddie C. Dost and David S. Miller");
  991. MODULE_DESCRIPTION("Sun SAB82532 serial port driver");
  992. MODULE_LICENSE("GPL");