ip22zilog.c 32 KB

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