ip22zilog.c 32 KB

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