ip22zilog.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  1. /*
  2. * Driver for Zilog serial chips found on SGI workstations and
  3. * servers. This driver could actually be made more generic.
  4. *
  5. * This is based on the drivers/serial/sunzilog.c code as of 2.6.0-test7 and the
  6. * old drivers/sgi/char/sgiserial.c code which itself is based of the original
  7. * drivers/sbus/char/zs.c code. A lot of code has been simply moved over
  8. * directly from there but much has been rewritten. Credits therefore go out
  9. * to David S. Miller, Eddie C. Dost, Pete Zaitcev, Ted Ts'o and Alex Buell
  10. * for their work there.
  11. *
  12. * Copyright (C) 2002 Ralf Baechle (ralf@linux-mips.org)
  13. * Copyright (C) 2002 David S. Miller (davem@redhat.com)
  14. */
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <linux/errno.h>
  18. #include <linux/delay.h>
  19. #include <linux/tty.h>
  20. #include <linux/tty_flip.h>
  21. #include <linux/major.h>
  22. #include <linux/string.h>
  23. #include <linux/ptrace.h>
  24. #include <linux/ioport.h>
  25. #include <linux/slab.h>
  26. #include <linux/circ_buf.h>
  27. #include <linux/serial.h>
  28. #include <linux/sysrq.h>
  29. #include <linux/console.h>
  30. #include <linux/spinlock.h>
  31. #include <linux/init.h>
  32. #include <asm/io.h>
  33. #include <asm/irq.h>
  34. #include <asm/sgialib.h>
  35. #include <asm/sgi/ioc.h>
  36. #include <asm/sgi/hpc3.h>
  37. #include <asm/sgi/ip22.h>
  38. #if defined(CONFIG_SERIAL_IP22_ZILOG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  39. #define SUPPORT_SYSRQ
  40. #endif
  41. #include <linux/serial_core.h>
  42. #include "ip22zilog.h"
  43. void ip22_do_break(void);
  44. /*
  45. * On IP22 we need to delay after register accesses but we do not need to
  46. * flush writes.
  47. */
  48. #define ZSDELAY() udelay(5)
  49. #define ZSDELAY_LONG() udelay(20)
  50. #define ZS_WSYNC(channel) do { } while (0)
  51. #define NUM_IP22ZILOG 1
  52. #define NUM_CHANNELS (NUM_IP22ZILOG * 2)
  53. #define ZS_CLOCK 3672000 /* Zilog input clock rate. */
  54. #define ZS_CLOCK_DIVISOR 16 /* Divisor this driver uses. */
  55. /*
  56. * We wrap our port structure around the generic uart_port.
  57. */
  58. struct uart_ip22zilog_port {
  59. struct uart_port port;
  60. /* IRQ servicing chain. */
  61. struct uart_ip22zilog_port *next;
  62. /* Current values of Zilog write registers. */
  63. unsigned char curregs[NUM_ZSREGS];
  64. unsigned int flags;
  65. #define IP22ZILOG_FLAG_IS_CONS 0x00000004
  66. #define IP22ZILOG_FLAG_IS_KGDB 0x00000008
  67. #define IP22ZILOG_FLAG_MODEM_STATUS 0x00000010
  68. #define IP22ZILOG_FLAG_IS_CHANNEL_A 0x00000020
  69. #define IP22ZILOG_FLAG_REGS_HELD 0x00000040
  70. #define IP22ZILOG_FLAG_TX_STOPPED 0x00000080
  71. #define IP22ZILOG_FLAG_TX_ACTIVE 0x00000100
  72. unsigned int cflag;
  73. /* L1-A keyboard break state. */
  74. int kbd_id;
  75. int l1_down;
  76. unsigned char parity_mask;
  77. unsigned char prev_status;
  78. };
  79. #define ZILOG_CHANNEL_FROM_PORT(PORT) ((struct zilog_channel *)((PORT)->membase))
  80. #define UART_ZILOG(PORT) ((struct uart_ip22zilog_port *)(PORT))
  81. #define IP22ZILOG_GET_CURR_REG(PORT, REGNUM) \
  82. (UART_ZILOG(PORT)->curregs[REGNUM])
  83. #define IP22ZILOG_SET_CURR_REG(PORT, REGNUM, REGVAL) \
  84. ((UART_ZILOG(PORT)->curregs[REGNUM]) = (REGVAL))
  85. #define ZS_IS_CONS(UP) ((UP)->flags & IP22ZILOG_FLAG_IS_CONS)
  86. #define ZS_IS_KGDB(UP) ((UP)->flags & IP22ZILOG_FLAG_IS_KGDB)
  87. #define ZS_WANTS_MODEM_STATUS(UP) ((UP)->flags & IP22ZILOG_FLAG_MODEM_STATUS)
  88. #define ZS_IS_CHANNEL_A(UP) ((UP)->flags & IP22ZILOG_FLAG_IS_CHANNEL_A)
  89. #define ZS_REGS_HELD(UP) ((UP)->flags & IP22ZILOG_FLAG_REGS_HELD)
  90. #define ZS_TX_STOPPED(UP) ((UP)->flags & IP22ZILOG_FLAG_TX_STOPPED)
  91. #define ZS_TX_ACTIVE(UP) ((UP)->flags & IP22ZILOG_FLAG_TX_ACTIVE)
  92. /* Reading and writing Zilog8530 registers. The delays are to make this
  93. * driver work on the IP22 which needs a settling delay after each chip
  94. * register access, other machines handle this in hardware via auxiliary
  95. * flip-flops which implement the settle time we do in software.
  96. *
  97. * The port lock must be held and local IRQs must be disabled
  98. * when {read,write}_zsreg is invoked.
  99. */
  100. static unsigned char read_zsreg(struct zilog_channel *channel,
  101. unsigned char reg)
  102. {
  103. unsigned char retval;
  104. writeb(reg, &channel->control);
  105. ZSDELAY();
  106. retval = readb(&channel->control);
  107. ZSDELAY();
  108. return retval;
  109. }
  110. static void write_zsreg(struct zilog_channel *channel,
  111. unsigned char reg, unsigned char value)
  112. {
  113. writeb(reg, &channel->control);
  114. ZSDELAY();
  115. writeb(value, &channel->control);
  116. ZSDELAY();
  117. }
  118. static void ip22zilog_clear_fifo(struct zilog_channel *channel)
  119. {
  120. int i;
  121. for (i = 0; i < 32; i++) {
  122. unsigned char regval;
  123. regval = readb(&channel->control);
  124. ZSDELAY();
  125. if (regval & Rx_CH_AV)
  126. break;
  127. regval = read_zsreg(channel, R1);
  128. readb(&channel->data);
  129. ZSDELAY();
  130. if (regval & (PAR_ERR | Rx_OVR | CRC_ERR)) {
  131. writeb(ERR_RES, &channel->control);
  132. ZSDELAY();
  133. ZS_WSYNC(channel);
  134. }
  135. }
  136. }
  137. /* This function must only be called when the TX is not busy. The UART
  138. * port lock must be held and local interrupts disabled.
  139. */
  140. static void __load_zsregs(struct zilog_channel *channel, unsigned char *regs)
  141. {
  142. int i;
  143. /* Let pending transmits finish. */
  144. for (i = 0; i < 1000; i++) {
  145. unsigned char stat = read_zsreg(channel, R1);
  146. if (stat & ALL_SNT)
  147. break;
  148. udelay(100);
  149. }
  150. writeb(ERR_RES, &channel->control);
  151. ZSDELAY();
  152. ZS_WSYNC(channel);
  153. ip22zilog_clear_fifo(channel);
  154. /* Disable all interrupts. */
  155. write_zsreg(channel, R1,
  156. regs[R1] & ~(RxINT_MASK | TxINT_ENAB | EXT_INT_ENAB));
  157. /* Set parity, sync config, stop bits, and clock divisor. */
  158. write_zsreg(channel, R4, regs[R4]);
  159. /* Set misc. TX/RX control bits. */
  160. write_zsreg(channel, R10, regs[R10]);
  161. /* Set TX/RX controls sans the enable bits. */
  162. write_zsreg(channel, R3, regs[R3] & ~RxENAB);
  163. write_zsreg(channel, R5, regs[R5] & ~TxENAB);
  164. /* Synchronous mode config. */
  165. write_zsreg(channel, R6, regs[R6]);
  166. write_zsreg(channel, R7, regs[R7]);
  167. /* Don't mess with the interrupt vector (R2, unused by us) and
  168. * master interrupt control (R9). We make sure this is setup
  169. * properly at probe time then never touch it again.
  170. */
  171. /* Disable baud generator. */
  172. write_zsreg(channel, R14, regs[R14] & ~BRENAB);
  173. /* Clock mode control. */
  174. write_zsreg(channel, R11, regs[R11]);
  175. /* Lower and upper byte of baud rate generator divisor. */
  176. write_zsreg(channel, R12, regs[R12]);
  177. write_zsreg(channel, R13, regs[R13]);
  178. /* Now rewrite R14, with BRENAB (if set). */
  179. write_zsreg(channel, R14, regs[R14]);
  180. /* External status interrupt control. */
  181. write_zsreg(channel, R15, regs[R15]);
  182. /* Reset external status interrupts. */
  183. write_zsreg(channel, R0, RES_EXT_INT);
  184. write_zsreg(channel, R0, RES_EXT_INT);
  185. /* Rewrite R3/R5, this time without enables masked. */
  186. write_zsreg(channel, R3, regs[R3]);
  187. write_zsreg(channel, R5, regs[R5]);
  188. /* Rewrite R1, this time without IRQ enabled masked. */
  189. write_zsreg(channel, R1, regs[R1]);
  190. }
  191. /* Reprogram the Zilog channel HW registers with the copies found in the
  192. * software state struct. If the transmitter is busy, we defer this update
  193. * until the next TX complete interrupt. Else, we do it right now.
  194. *
  195. * The UART port lock must be held and local interrupts disabled.
  196. */
  197. static void ip22zilog_maybe_update_regs(struct uart_ip22zilog_port *up,
  198. struct zilog_channel *channel)
  199. {
  200. if (!ZS_REGS_HELD(up)) {
  201. if (ZS_TX_ACTIVE(up)) {
  202. up->flags |= IP22ZILOG_FLAG_REGS_HELD;
  203. } else {
  204. __load_zsregs(channel, up->curregs);
  205. }
  206. }
  207. }
  208. static void ip22zilog_receive_chars(struct uart_ip22zilog_port *up,
  209. struct zilog_channel *channel)
  210. {
  211. struct tty_struct *tty = up->port.info->tty; /* XXX info==NULL? */
  212. while (1) {
  213. unsigned char ch, r1, flag;
  214. r1 = read_zsreg(channel, R1);
  215. if (r1 & (PAR_ERR | Rx_OVR | CRC_ERR)) {
  216. writeb(ERR_RES, &channel->control);
  217. ZSDELAY();
  218. ZS_WSYNC(channel);
  219. }
  220. ch = readb(&channel->control);
  221. ZSDELAY();
  222. /* This funny hack depends upon BRK_ABRT not interfering
  223. * with the other bits we care about in R1.
  224. */
  225. if (ch & BRK_ABRT)
  226. r1 |= BRK_ABRT;
  227. ch = readb(&channel->data);
  228. ZSDELAY();
  229. ch &= up->parity_mask;
  230. if (ZS_IS_CONS(up) && (r1 & BRK_ABRT)) {
  231. /* Wait for BREAK to deassert to avoid potentially
  232. * confusing the PROM.
  233. */
  234. while (1) {
  235. ch = readb(&channel->control);
  236. ZSDELAY();
  237. if (!(ch & BRK_ABRT))
  238. break;
  239. }
  240. ip22_do_break();
  241. return;
  242. }
  243. /* A real serial line, record the character and status. */
  244. flag = TTY_NORMAL;
  245. up->port.icount.rx++;
  246. if (r1 & (BRK_ABRT | PAR_ERR | Rx_OVR | CRC_ERR)) {
  247. if (r1 & BRK_ABRT) {
  248. r1 &= ~(PAR_ERR | CRC_ERR);
  249. up->port.icount.brk++;
  250. if (uart_handle_break(&up->port))
  251. goto next_char;
  252. }
  253. else if (r1 & PAR_ERR)
  254. up->port.icount.parity++;
  255. else if (r1 & CRC_ERR)
  256. up->port.icount.frame++;
  257. if (r1 & Rx_OVR)
  258. up->port.icount.overrun++;
  259. r1 &= up->port.read_status_mask;
  260. if (r1 & BRK_ABRT)
  261. flag = TTY_BREAK;
  262. else if (r1 & PAR_ERR)
  263. flag = TTY_PARITY;
  264. else if (r1 & CRC_ERR)
  265. flag = TTY_FRAME;
  266. }
  267. if (uart_handle_sysrq_char(&up->port, ch))
  268. goto next_char;
  269. if (up->port.ignore_status_mask == 0xff ||
  270. (r1 & up->port.ignore_status_mask) == 0)
  271. tty_insert_flip_char(tty, ch, flag);
  272. if (r1 & Rx_OVR)
  273. tty_insert_flip_char(tty, 0, TTY_OVERRUN);
  274. next_char:
  275. ch = readb(&channel->control);
  276. ZSDELAY();
  277. if (!(ch & Rx_CH_AV))
  278. break;
  279. }
  280. tty_flip_buffer_push(tty);
  281. }
  282. static void ip22zilog_status_handle(struct uart_ip22zilog_port *up,
  283. struct zilog_channel *channel)
  284. {
  285. unsigned char status;
  286. status = readb(&channel->control);
  287. ZSDELAY();
  288. writeb(RES_EXT_INT, &channel->control);
  289. ZSDELAY();
  290. ZS_WSYNC(channel);
  291. if (ZS_WANTS_MODEM_STATUS(up)) {
  292. if (status & SYNC)
  293. up->port.icount.dsr++;
  294. /* The Zilog just gives us an interrupt when DCD/CTS/etc. change.
  295. * But it does not tell us which bit has changed, we have to keep
  296. * track of this ourselves.
  297. */
  298. if ((status & DCD) ^ up->prev_status)
  299. uart_handle_dcd_change(&up->port,
  300. (status & DCD));
  301. if ((status & CTS) ^ up->prev_status)
  302. uart_handle_cts_change(&up->port,
  303. (status & CTS));
  304. wake_up_interruptible(&up->port.info->delta_msr_wait);
  305. }
  306. up->prev_status = status;
  307. }
  308. static void ip22zilog_transmit_chars(struct uart_ip22zilog_port *up,
  309. struct zilog_channel *channel)
  310. {
  311. struct circ_buf *xmit;
  312. if (ZS_IS_CONS(up)) {
  313. unsigned char status = readb(&channel->control);
  314. ZSDELAY();
  315. /* TX still busy? Just wait for the next TX done interrupt.
  316. *
  317. * It can occur because of how we do serial console writes. It would
  318. * be nice to transmit console writes just like we normally would for
  319. * a TTY line. (ie. buffered and TX interrupt driven). That is not
  320. * easy because console writes cannot sleep. One solution might be
  321. * to poll on enough port->xmit space becomming free. -DaveM
  322. */
  323. if (!(status & Tx_BUF_EMP))
  324. return;
  325. }
  326. up->flags &= ~IP22ZILOG_FLAG_TX_ACTIVE;
  327. if (ZS_REGS_HELD(up)) {
  328. __load_zsregs(channel, up->curregs);
  329. up->flags &= ~IP22ZILOG_FLAG_REGS_HELD;
  330. }
  331. if (ZS_TX_STOPPED(up)) {
  332. up->flags &= ~IP22ZILOG_FLAG_TX_STOPPED;
  333. goto ack_tx_int;
  334. }
  335. if (up->port.x_char) {
  336. up->flags |= IP22ZILOG_FLAG_TX_ACTIVE;
  337. writeb(up->port.x_char, &channel->data);
  338. ZSDELAY();
  339. ZS_WSYNC(channel);
  340. up->port.icount.tx++;
  341. up->port.x_char = 0;
  342. return;
  343. }
  344. if (up->port.info == NULL)
  345. goto ack_tx_int;
  346. xmit = &up->port.info->xmit;
  347. if (uart_circ_empty(xmit))
  348. goto ack_tx_int;
  349. if (uart_tx_stopped(&up->port))
  350. goto ack_tx_int;
  351. up->flags |= IP22ZILOG_FLAG_TX_ACTIVE;
  352. writeb(xmit->buf[xmit->tail], &channel->data);
  353. ZSDELAY();
  354. ZS_WSYNC(channel);
  355. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  356. up->port.icount.tx++;
  357. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  358. uart_write_wakeup(&up->port);
  359. return;
  360. ack_tx_int:
  361. writeb(RES_Tx_P, &channel->control);
  362. ZSDELAY();
  363. ZS_WSYNC(channel);
  364. }
  365. static irqreturn_t ip22zilog_interrupt(int irq, void *dev_id)
  366. {
  367. struct uart_ip22zilog_port *up = dev_id;
  368. while (up) {
  369. struct zilog_channel *channel
  370. = ZILOG_CHANNEL_FROM_PORT(&up->port);
  371. unsigned char r3;
  372. spin_lock(&up->port.lock);
  373. r3 = read_zsreg(channel, R3);
  374. /* Channel A */
  375. if (r3 & (CHAEXT | CHATxIP | CHARxIP)) {
  376. writeb(RES_H_IUS, &channel->control);
  377. ZSDELAY();
  378. ZS_WSYNC(channel);
  379. if (r3 & CHARxIP)
  380. ip22zilog_receive_chars(up, channel);
  381. if (r3 & CHAEXT)
  382. ip22zilog_status_handle(up, channel);
  383. if (r3 & CHATxIP)
  384. ip22zilog_transmit_chars(up, channel);
  385. }
  386. spin_unlock(&up->port.lock);
  387. /* Channel B */
  388. up = up->next;
  389. channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
  390. spin_lock(&up->port.lock);
  391. if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) {
  392. writeb(RES_H_IUS, &channel->control);
  393. ZSDELAY();
  394. ZS_WSYNC(channel);
  395. if (r3 & CHBRxIP)
  396. ip22zilog_receive_chars(up, channel);
  397. if (r3 & CHBEXT)
  398. ip22zilog_status_handle(up, channel);
  399. if (r3 & CHBTxIP)
  400. ip22zilog_transmit_chars(up, channel);
  401. }
  402. spin_unlock(&up->port.lock);
  403. up = up->next;
  404. }
  405. return IRQ_HANDLED;
  406. }
  407. /* A convenient way to quickly get R0 status. The caller must _not_ hold the
  408. * port lock, it is acquired here.
  409. */
  410. static __inline__ unsigned char ip22zilog_read_channel_status(struct uart_port *port)
  411. {
  412. struct zilog_channel *channel;
  413. unsigned char status;
  414. channel = ZILOG_CHANNEL_FROM_PORT(port);
  415. status = readb(&channel->control);
  416. ZSDELAY();
  417. return status;
  418. }
  419. /* The port lock is not held. */
  420. static unsigned int ip22zilog_tx_empty(struct uart_port *port)
  421. {
  422. unsigned long flags;
  423. unsigned char status;
  424. unsigned int ret;
  425. spin_lock_irqsave(&port->lock, flags);
  426. status = ip22zilog_read_channel_status(port);
  427. spin_unlock_irqrestore(&port->lock, flags);
  428. if (status & Tx_BUF_EMP)
  429. ret = TIOCSER_TEMT;
  430. else
  431. ret = 0;
  432. return ret;
  433. }
  434. /* The port lock is held and interrupts are disabled. */
  435. static unsigned int ip22zilog_get_mctrl(struct uart_port *port)
  436. {
  437. unsigned char status;
  438. unsigned int ret;
  439. status = ip22zilog_read_channel_status(port);
  440. ret = 0;
  441. if (status & DCD)
  442. ret |= TIOCM_CAR;
  443. if (status & SYNC)
  444. ret |= TIOCM_DSR;
  445. if (status & CTS)
  446. ret |= TIOCM_CTS;
  447. return ret;
  448. }
  449. /* The port lock is held and interrupts are disabled. */
  450. static void ip22zilog_set_mctrl(struct uart_port *port, unsigned int mctrl)
  451. {
  452. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  453. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
  454. unsigned char set_bits, clear_bits;
  455. set_bits = clear_bits = 0;
  456. if (mctrl & TIOCM_RTS)
  457. set_bits |= RTS;
  458. else
  459. clear_bits |= RTS;
  460. if (mctrl & TIOCM_DTR)
  461. set_bits |= DTR;
  462. else
  463. clear_bits |= DTR;
  464. /* NOTE: Not subject to 'transmitter active' rule. */
  465. up->curregs[R5] |= set_bits;
  466. up->curregs[R5] &= ~clear_bits;
  467. write_zsreg(channel, R5, up->curregs[R5]);
  468. }
  469. /* The port lock is held and interrupts are disabled. */
  470. static void ip22zilog_stop_tx(struct uart_port *port)
  471. {
  472. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  473. up->flags |= IP22ZILOG_FLAG_TX_STOPPED;
  474. }
  475. /* The port lock is held and interrupts are disabled. */
  476. static void ip22zilog_start_tx(struct uart_port *port)
  477. {
  478. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  479. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
  480. unsigned char status;
  481. up->flags |= IP22ZILOG_FLAG_TX_ACTIVE;
  482. up->flags &= ~IP22ZILOG_FLAG_TX_STOPPED;
  483. status = readb(&channel->control);
  484. ZSDELAY();
  485. /* TX busy? Just wait for the TX done interrupt. */
  486. if (!(status & Tx_BUF_EMP))
  487. return;
  488. /* Send the first character to jump-start the TX done
  489. * IRQ sending engine.
  490. */
  491. if (port->x_char) {
  492. writeb(port->x_char, &channel->data);
  493. ZSDELAY();
  494. ZS_WSYNC(channel);
  495. port->icount.tx++;
  496. port->x_char = 0;
  497. } else {
  498. struct circ_buf *xmit = &port->info->xmit;
  499. writeb(xmit->buf[xmit->tail], &channel->data);
  500. ZSDELAY();
  501. ZS_WSYNC(channel);
  502. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  503. port->icount.tx++;
  504. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  505. uart_write_wakeup(&up->port);
  506. }
  507. }
  508. /* The port lock is held and interrupts are disabled. */
  509. static void ip22zilog_stop_rx(struct uart_port *port)
  510. {
  511. struct uart_ip22zilog_port *up = UART_ZILOG(port);
  512. struct zilog_channel *channel;
  513. if (ZS_IS_CONS(up))
  514. return;
  515. channel = ZILOG_CHANNEL_FROM_PORT(port);
  516. /* Disable all RX interrupts. */
  517. up->curregs[R1] &= ~RxINT_MASK;
  518. ip22zilog_maybe_update_regs(up, channel);
  519. }
  520. /* The port lock is held. */
  521. static void ip22zilog_enable_ms(struct uart_port *port)
  522. {
  523. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  524. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
  525. unsigned char new_reg;
  526. new_reg = up->curregs[R15] | (DCDIE | SYNCIE | CTSIE);
  527. if (new_reg != up->curregs[R15]) {
  528. up->curregs[R15] = new_reg;
  529. /* NOTE: Not subject to 'transmitter active' rule. */
  530. write_zsreg(channel, R15, up->curregs[R15]);
  531. }
  532. }
  533. /* The port lock is not held. */
  534. static void ip22zilog_break_ctl(struct uart_port *port, int break_state)
  535. {
  536. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  537. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
  538. unsigned char set_bits, clear_bits, new_reg;
  539. unsigned long flags;
  540. set_bits = clear_bits = 0;
  541. if (break_state)
  542. set_bits |= SND_BRK;
  543. else
  544. clear_bits |= SND_BRK;
  545. spin_lock_irqsave(&port->lock, flags);
  546. new_reg = (up->curregs[R5] | set_bits) & ~clear_bits;
  547. if (new_reg != up->curregs[R5]) {
  548. up->curregs[R5] = new_reg;
  549. /* NOTE: Not subject to 'transmitter active' rule. */
  550. write_zsreg(channel, R5, up->curregs[R5]);
  551. }
  552. spin_unlock_irqrestore(&port->lock, flags);
  553. }
  554. static void __ip22zilog_startup(struct uart_ip22zilog_port *up)
  555. {
  556. struct zilog_channel *channel;
  557. channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
  558. up->prev_status = readb(&channel->control);
  559. /* Enable receiver and transmitter. */
  560. up->curregs[R3] |= RxENAB;
  561. up->curregs[R5] |= TxENAB;
  562. up->curregs[R1] |= EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB;
  563. ip22zilog_maybe_update_regs(up, channel);
  564. }
  565. static int ip22zilog_startup(struct uart_port *port)
  566. {
  567. struct uart_ip22zilog_port *up = UART_ZILOG(port);
  568. unsigned long flags;
  569. if (ZS_IS_CONS(up))
  570. return 0;
  571. spin_lock_irqsave(&port->lock, flags);
  572. __ip22zilog_startup(up);
  573. spin_unlock_irqrestore(&port->lock, flags);
  574. return 0;
  575. }
  576. /*
  577. * The test for ZS_IS_CONS is explained by the following e-mail:
  578. *****
  579. * From: Russell King <rmk@arm.linux.org.uk>
  580. * Date: Sun, 8 Dec 2002 10:18:38 +0000
  581. *
  582. * On Sun, Dec 08, 2002 at 02:43:36AM -0500, Pete Zaitcev wrote:
  583. * > I boot my 2.5 boxes using "console=ttyS0,9600" argument,
  584. * > and I noticed that something is not right with reference
  585. * > counting in this case. It seems that when the console
  586. * > is open by kernel initially, this is not accounted
  587. * > as an open, and uart_startup is not called.
  588. *
  589. * That is correct. We are unable to call uart_startup when the serial
  590. * console is initialised because it may need to allocate memory (as
  591. * request_irq does) and the memory allocators may not have been
  592. * initialised.
  593. *
  594. * 1. initialise the port into a state where it can send characters in the
  595. * console write method.
  596. *
  597. * 2. don't do the actual hardware shutdown in your shutdown() method (but
  598. * do the normal software shutdown - ie, free irqs etc)
  599. *****
  600. */
  601. static void ip22zilog_shutdown(struct uart_port *port)
  602. {
  603. struct uart_ip22zilog_port *up = UART_ZILOG(port);
  604. struct zilog_channel *channel;
  605. unsigned long flags;
  606. if (ZS_IS_CONS(up))
  607. return;
  608. spin_lock_irqsave(&port->lock, flags);
  609. channel = ZILOG_CHANNEL_FROM_PORT(port);
  610. /* Disable receiver and transmitter. */
  611. up->curregs[R3] &= ~RxENAB;
  612. up->curregs[R5] &= ~TxENAB;
  613. /* Disable all interrupts and BRK assertion. */
  614. up->curregs[R1] &= ~(EXT_INT_ENAB | TxINT_ENAB | RxINT_MASK);
  615. up->curregs[R5] &= ~SND_BRK;
  616. ip22zilog_maybe_update_regs(up, channel);
  617. spin_unlock_irqrestore(&port->lock, flags);
  618. }
  619. /* Shared by TTY driver and serial console setup. The port lock is held
  620. * and local interrupts are disabled.
  621. */
  622. static void
  623. ip22zilog_convert_to_zs(struct uart_ip22zilog_port *up, unsigned int cflag,
  624. unsigned int iflag, int brg)
  625. {
  626. up->curregs[R10] = NRZ;
  627. up->curregs[R11] = TCBR | RCBR;
  628. /* Program BAUD and clock source. */
  629. up->curregs[R4] &= ~XCLK_MASK;
  630. up->curregs[R4] |= X16CLK;
  631. up->curregs[R12] = brg & 0xff;
  632. up->curregs[R13] = (brg >> 8) & 0xff;
  633. up->curregs[R14] = BRENAB;
  634. /* Character size, stop bits, and parity. */
  635. up->curregs[3] &= ~RxN_MASK;
  636. up->curregs[5] &= ~TxN_MASK;
  637. switch (cflag & CSIZE) {
  638. case CS5:
  639. up->curregs[3] |= Rx5;
  640. up->curregs[5] |= Tx5;
  641. up->parity_mask = 0x1f;
  642. break;
  643. case CS6:
  644. up->curregs[3] |= Rx6;
  645. up->curregs[5] |= Tx6;
  646. up->parity_mask = 0x3f;
  647. break;
  648. case CS7:
  649. up->curregs[3] |= Rx7;
  650. up->curregs[5] |= Tx7;
  651. up->parity_mask = 0x7f;
  652. break;
  653. case CS8:
  654. default:
  655. up->curregs[3] |= Rx8;
  656. up->curregs[5] |= Tx8;
  657. up->parity_mask = 0xff;
  658. break;
  659. };
  660. up->curregs[4] &= ~0x0c;
  661. if (cflag & CSTOPB)
  662. up->curregs[4] |= SB2;
  663. else
  664. up->curregs[4] |= SB1;
  665. if (cflag & PARENB)
  666. up->curregs[4] |= PAR_ENAB;
  667. else
  668. up->curregs[4] &= ~PAR_ENAB;
  669. if (!(cflag & PARODD))
  670. up->curregs[4] |= PAR_EVEN;
  671. else
  672. up->curregs[4] &= ~PAR_EVEN;
  673. up->port.read_status_mask = Rx_OVR;
  674. if (iflag & INPCK)
  675. up->port.read_status_mask |= CRC_ERR | PAR_ERR;
  676. if (iflag & (BRKINT | PARMRK))
  677. up->port.read_status_mask |= BRK_ABRT;
  678. up->port.ignore_status_mask = 0;
  679. if (iflag & IGNPAR)
  680. up->port.ignore_status_mask |= CRC_ERR | PAR_ERR;
  681. if (iflag & IGNBRK) {
  682. up->port.ignore_status_mask |= BRK_ABRT;
  683. if (iflag & IGNPAR)
  684. up->port.ignore_status_mask |= Rx_OVR;
  685. }
  686. if ((cflag & CREAD) == 0)
  687. up->port.ignore_status_mask = 0xff;
  688. }
  689. /* The port lock is not held. */
  690. static void
  691. ip22zilog_set_termios(struct uart_port *port, struct ktermios *termios,
  692. struct ktermios *old)
  693. {
  694. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  695. unsigned long flags;
  696. int baud, brg;
  697. baud = uart_get_baud_rate(port, termios, old, 1200, 76800);
  698. spin_lock_irqsave(&up->port.lock, flags);
  699. brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
  700. ip22zilog_convert_to_zs(up, termios->c_cflag, termios->c_iflag, brg);
  701. if (UART_ENABLE_MS(&up->port, termios->c_cflag))
  702. up->flags |= IP22ZILOG_FLAG_MODEM_STATUS;
  703. else
  704. up->flags &= ~IP22ZILOG_FLAG_MODEM_STATUS;
  705. up->cflag = termios->c_cflag;
  706. ip22zilog_maybe_update_regs(up, ZILOG_CHANNEL_FROM_PORT(port));
  707. uart_update_timeout(port, termios->c_cflag, baud);
  708. spin_unlock_irqrestore(&up->port.lock, flags);
  709. }
  710. static const char *ip22zilog_type(struct uart_port *port)
  711. {
  712. return "IP22-Zilog";
  713. }
  714. /* We do not request/release mappings of the registers here, this
  715. * happens at early serial probe time.
  716. */
  717. static void ip22zilog_release_port(struct uart_port *port)
  718. {
  719. }
  720. static int ip22zilog_request_port(struct uart_port *port)
  721. {
  722. return 0;
  723. }
  724. /* These do not need to do anything interesting either. */
  725. static void ip22zilog_config_port(struct uart_port *port, int flags)
  726. {
  727. }
  728. /* We do not support letting the user mess with the divisor, IRQ, etc. */
  729. static int ip22zilog_verify_port(struct uart_port *port, struct serial_struct *ser)
  730. {
  731. return -EINVAL;
  732. }
  733. static struct uart_ops ip22zilog_pops = {
  734. .tx_empty = ip22zilog_tx_empty,
  735. .set_mctrl = ip22zilog_set_mctrl,
  736. .get_mctrl = ip22zilog_get_mctrl,
  737. .stop_tx = ip22zilog_stop_tx,
  738. .start_tx = ip22zilog_start_tx,
  739. .stop_rx = ip22zilog_stop_rx,
  740. .enable_ms = ip22zilog_enable_ms,
  741. .break_ctl = ip22zilog_break_ctl,
  742. .startup = ip22zilog_startup,
  743. .shutdown = ip22zilog_shutdown,
  744. .set_termios = ip22zilog_set_termios,
  745. .type = ip22zilog_type,
  746. .release_port = ip22zilog_release_port,
  747. .request_port = ip22zilog_request_port,
  748. .config_port = ip22zilog_config_port,
  749. .verify_port = ip22zilog_verify_port,
  750. };
  751. static struct uart_ip22zilog_port *ip22zilog_port_table;
  752. static struct zilog_layout **ip22zilog_chip_regs;
  753. static struct uart_ip22zilog_port *ip22zilog_irq_chain;
  754. static int zilog_irq = -1;
  755. static void * __init alloc_one_table(unsigned long size)
  756. {
  757. return kzalloc(size, GFP_KERNEL);
  758. }
  759. static void __init ip22zilog_alloc_tables(void)
  760. {
  761. ip22zilog_port_table = (struct uart_ip22zilog_port *)
  762. alloc_one_table(NUM_CHANNELS * sizeof(struct uart_ip22zilog_port));
  763. ip22zilog_chip_regs = (struct zilog_layout **)
  764. alloc_one_table(NUM_IP22ZILOG * sizeof(struct zilog_layout *));
  765. if (ip22zilog_port_table == NULL || ip22zilog_chip_regs == NULL) {
  766. panic("IP22-Zilog: Cannot allocate IP22-Zilog tables.");
  767. }
  768. }
  769. /* Get the address of the registers for IP22-Zilog instance CHIP. */
  770. static struct zilog_layout * __init get_zs(int chip)
  771. {
  772. unsigned long base;
  773. if (chip < 0 || chip >= NUM_IP22ZILOG) {
  774. panic("IP22-Zilog: Illegal chip number %d in get_zs.", chip);
  775. }
  776. /* Not probe-able, hard code it. */
  777. base = (unsigned long) &sgioc->uart;
  778. zilog_irq = SGI_SERIAL_IRQ;
  779. request_mem_region(base, 8, "IP22-Zilog");
  780. return (struct zilog_layout *) base;
  781. }
  782. #define ZS_PUT_CHAR_MAX_DELAY 2000 /* 10 ms */
  783. #ifdef CONFIG_SERIAL_IP22_ZILOG_CONSOLE
  784. static void ip22zilog_put_char(struct uart_port *port, int ch)
  785. {
  786. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
  787. int loops = ZS_PUT_CHAR_MAX_DELAY;
  788. /* This is a timed polling loop so do not switch the explicit
  789. * udelay with ZSDELAY as that is a NOP on some platforms. -DaveM
  790. */
  791. do {
  792. unsigned char val = readb(&channel->control);
  793. if (val & Tx_BUF_EMP) {
  794. ZSDELAY();
  795. break;
  796. }
  797. udelay(5);
  798. } while (--loops);
  799. writeb(ch, &channel->data);
  800. ZSDELAY();
  801. ZS_WSYNC(channel);
  802. }
  803. static void
  804. ip22zilog_console_write(struct console *con, const char *s, unsigned int count)
  805. {
  806. struct uart_ip22zilog_port *up = &ip22zilog_port_table[con->index];
  807. unsigned long flags;
  808. spin_lock_irqsave(&up->port.lock, flags);
  809. uart_console_write(&up->port, s, count, ip22zilog_put_char);
  810. udelay(2);
  811. spin_unlock_irqrestore(&up->port.lock, flags);
  812. }
  813. void
  814. ip22serial_console_termios(struct console *con, char *options)
  815. {
  816. int baud = 9600, bits = 8, cflag;
  817. int parity = 'n';
  818. int flow = 'n';
  819. if (options)
  820. uart_parse_options(options, &baud, &parity, &bits, &flow);
  821. cflag = CREAD | HUPCL | CLOCAL;
  822. switch (baud) {
  823. case 150: cflag |= B150; break;
  824. case 300: cflag |= B300; break;
  825. case 600: cflag |= B600; break;
  826. case 1200: cflag |= B1200; break;
  827. case 2400: cflag |= B2400; break;
  828. case 4800: cflag |= B4800; break;
  829. case 9600: cflag |= B9600; break;
  830. case 19200: cflag |= B19200; break;
  831. case 38400: cflag |= B38400; break;
  832. default: baud = 9600; cflag |= B9600; break;
  833. }
  834. con->cflag = cflag | CS8; /* 8N1 */
  835. uart_update_timeout(&ip22zilog_port_table[con->index].port, cflag, baud);
  836. }
  837. static int __init ip22zilog_console_setup(struct console *con, char *options)
  838. {
  839. struct uart_ip22zilog_port *up = &ip22zilog_port_table[con->index];
  840. unsigned long flags;
  841. int baud, brg;
  842. printk("Console: ttyS%d (IP22-Zilog)\n", con->index);
  843. /* Get firmware console settings. */
  844. ip22serial_console_termios(con, options);
  845. /* Firmware console speed is limited to 150-->38400 baud so
  846. * this hackish cflag thing is OK.
  847. */
  848. switch (con->cflag & CBAUD) {
  849. case B150: baud = 150; break;
  850. case B300: baud = 300; break;
  851. case B600: baud = 600; break;
  852. case B1200: baud = 1200; break;
  853. case B2400: baud = 2400; break;
  854. case B4800: baud = 4800; break;
  855. default: case B9600: baud = 9600; break;
  856. case B19200: baud = 19200; break;
  857. case B38400: baud = 38400; break;
  858. };
  859. brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
  860. spin_lock_irqsave(&up->port.lock, flags);
  861. up->curregs[R15] = BRKIE;
  862. ip22zilog_convert_to_zs(up, con->cflag, 0, brg);
  863. __ip22zilog_startup(up);
  864. spin_unlock_irqrestore(&up->port.lock, flags);
  865. return 0;
  866. }
  867. static struct uart_driver ip22zilog_reg;
  868. static struct console ip22zilog_console = {
  869. .name = "ttyS",
  870. .write = ip22zilog_console_write,
  871. .device = uart_console_device,
  872. .setup = ip22zilog_console_setup,
  873. .flags = CON_PRINTBUFFER,
  874. .index = -1,
  875. .data = &ip22zilog_reg,
  876. };
  877. #endif /* CONFIG_SERIAL_IP22_ZILOG_CONSOLE */
  878. static struct uart_driver ip22zilog_reg = {
  879. .owner = THIS_MODULE,
  880. .driver_name = "serial",
  881. .dev_name = "ttyS",
  882. .major = TTY_MAJOR,
  883. .minor = 64,
  884. .nr = NUM_CHANNELS,
  885. #ifdef CONFIG_SERIAL_IP22_ZILOG_CONSOLE
  886. .cons = &ip22zilog_console,
  887. #endif
  888. };
  889. static void __init ip22zilog_prepare(void)
  890. {
  891. struct uart_ip22zilog_port *up;
  892. struct zilog_layout *rp;
  893. int channel, chip;
  894. /*
  895. * Temporary fix.
  896. */
  897. for (channel = 0; channel < NUM_CHANNELS; channel++)
  898. spin_lock_init(&ip22zilog_port_table[channel].port.lock);
  899. ip22zilog_irq_chain = &ip22zilog_port_table[NUM_CHANNELS - 1];
  900. up = &ip22zilog_port_table[0];
  901. for (channel = NUM_CHANNELS - 1 ; channel > 0; channel--)
  902. up[channel].next = &up[channel - 1];
  903. up[channel].next = NULL;
  904. for (chip = 0; chip < NUM_IP22ZILOG; chip++) {
  905. if (!ip22zilog_chip_regs[chip]) {
  906. ip22zilog_chip_regs[chip] = rp = get_zs(chip);
  907. up[(chip * 2) + 0].port.membase = (char *) &rp->channelB;
  908. up[(chip * 2) + 1].port.membase = (char *) &rp->channelA;
  909. /* In theory mapbase is the physical address ... */
  910. up[(chip * 2) + 0].port.mapbase =
  911. (unsigned long) ioremap((unsigned long) &rp->channelB, 8);
  912. up[(chip * 2) + 1].port.mapbase =
  913. (unsigned long) ioremap((unsigned long) &rp->channelA, 8);
  914. }
  915. /* Channel A */
  916. up[(chip * 2) + 0].port.iotype = UPIO_MEM;
  917. up[(chip * 2) + 0].port.irq = zilog_irq;
  918. up[(chip * 2) + 0].port.uartclk = ZS_CLOCK;
  919. up[(chip * 2) + 0].port.fifosize = 1;
  920. up[(chip * 2) + 0].port.ops = &ip22zilog_pops;
  921. up[(chip * 2) + 0].port.type = PORT_IP22ZILOG;
  922. up[(chip * 2) + 0].port.flags = 0;
  923. up[(chip * 2) + 0].port.line = (chip * 2) + 0;
  924. up[(chip * 2) + 0].flags = 0;
  925. /* Channel B */
  926. up[(chip * 2) + 1].port.iotype = UPIO_MEM;
  927. up[(chip * 2) + 1].port.irq = zilog_irq;
  928. up[(chip * 2) + 1].port.uartclk = ZS_CLOCK;
  929. up[(chip * 2) + 1].port.fifosize = 1;
  930. up[(chip * 2) + 1].port.ops = &ip22zilog_pops;
  931. up[(chip * 2) + 1].port.type = PORT_IP22ZILOG;
  932. up[(chip * 2) + 1].port.line = (chip * 2) + 1;
  933. up[(chip * 2) + 1].flags |= IP22ZILOG_FLAG_IS_CHANNEL_A;
  934. }
  935. }
  936. static void __init ip22zilog_init_hw(void)
  937. {
  938. int i;
  939. for (i = 0; i < NUM_CHANNELS; i++) {
  940. struct uart_ip22zilog_port *up = &ip22zilog_port_table[i];
  941. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
  942. unsigned long flags;
  943. int baud, brg;
  944. spin_lock_irqsave(&up->port.lock, flags);
  945. if (ZS_IS_CHANNEL_A(up)) {
  946. write_zsreg(channel, R9, FHWRES);
  947. ZSDELAY_LONG();
  948. (void) read_zsreg(channel, R0);
  949. }
  950. /* Normal serial TTY. */
  951. up->parity_mask = 0xff;
  952. up->curregs[R1] = EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB;
  953. up->curregs[R4] = PAR_EVEN | X16CLK | SB1;
  954. up->curregs[R3] = RxENAB | Rx8;
  955. up->curregs[R5] = TxENAB | Tx8;
  956. up->curregs[R9] = NV | MIE;
  957. up->curregs[R10] = NRZ;
  958. up->curregs[R11] = TCBR | RCBR;
  959. baud = 9600;
  960. brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
  961. up->curregs[R12] = (brg & 0xff);
  962. up->curregs[R13] = (brg >> 8) & 0xff;
  963. up->curregs[R14] = BRENAB;
  964. __load_zsregs(channel, up->curregs);
  965. /* set master interrupt enable */
  966. write_zsreg(channel, R9, up->curregs[R9]);
  967. spin_unlock_irqrestore(&up->port.lock, flags);
  968. }
  969. }
  970. static int __init ip22zilog_ports_init(void)
  971. {
  972. int ret;
  973. printk(KERN_INFO "Serial: IP22 Zilog driver (%d chips).\n", NUM_IP22ZILOG);
  974. ip22zilog_prepare();
  975. if (request_irq(zilog_irq, ip22zilog_interrupt, 0,
  976. "IP22-Zilog", ip22zilog_irq_chain)) {
  977. panic("IP22-Zilog: Unable to register zs interrupt handler.\n");
  978. }
  979. ip22zilog_init_hw();
  980. ret = uart_register_driver(&ip22zilog_reg);
  981. if (ret == 0) {
  982. int i;
  983. for (i = 0; i < NUM_CHANNELS; i++) {
  984. struct uart_ip22zilog_port *up = &ip22zilog_port_table[i];
  985. uart_add_one_port(&ip22zilog_reg, &up->port);
  986. }
  987. }
  988. return ret;
  989. }
  990. static int __init ip22zilog_init(void)
  991. {
  992. /* IP22 Zilog setup is hard coded, no probing to do. */
  993. ip22zilog_alloc_tables();
  994. ip22zilog_ports_init();
  995. return 0;
  996. }
  997. static void __exit ip22zilog_exit(void)
  998. {
  999. int i;
  1000. struct uart_ip22zilog_port *up;
  1001. for (i = 0; i < NUM_CHANNELS; i++) {
  1002. up = &ip22zilog_port_table[i];
  1003. uart_remove_one_port(&ip22zilog_reg, &up->port);
  1004. }
  1005. /* Free IO mem */
  1006. up = &ip22zilog_port_table[0];
  1007. for (i = 0; i < NUM_IP22ZILOG; i++) {
  1008. if (up[(i * 2) + 0].port.mapbase) {
  1009. iounmap((void*)up[(i * 2) + 0].port.mapbase);
  1010. up[(i * 2) + 0].port.mapbase = 0;
  1011. }
  1012. if (up[(i * 2) + 1].port.mapbase) {
  1013. iounmap((void*)up[(i * 2) + 1].port.mapbase);
  1014. up[(i * 2) + 1].port.mapbase = 0;
  1015. }
  1016. }
  1017. uart_unregister_driver(&ip22zilog_reg);
  1018. }
  1019. module_init(ip22zilog_init);
  1020. module_exit(ip22zilog_exit);
  1021. /* David wrote it but I'm to blame for the bugs ... */
  1022. MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");
  1023. MODULE_DESCRIPTION("SGI Zilog serial port driver");
  1024. MODULE_LICENSE("GPL");