ip22zilog.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  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. uart_write_wakeup(&up->port);
  353. goto ack_tx_int;
  354. }
  355. if (uart_tx_stopped(&up->port))
  356. goto ack_tx_int;
  357. up->flags |= IP22ZILOG_FLAG_TX_ACTIVE;
  358. writeb(xmit->buf[xmit->tail], &channel->data);
  359. ZSDELAY();
  360. ZS_WSYNC(channel);
  361. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  362. up->port.icount.tx++;
  363. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  364. uart_write_wakeup(&up->port);
  365. return;
  366. ack_tx_int:
  367. writeb(RES_Tx_P, &channel->control);
  368. ZSDELAY();
  369. ZS_WSYNC(channel);
  370. }
  371. static irqreturn_t ip22zilog_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  372. {
  373. struct uart_ip22zilog_port *up = dev_id;
  374. while (up) {
  375. struct zilog_channel *channel
  376. = ZILOG_CHANNEL_FROM_PORT(&up->port);
  377. unsigned char r3;
  378. spin_lock(&up->port.lock);
  379. r3 = read_zsreg(channel, R3);
  380. /* Channel A */
  381. if (r3 & (CHAEXT | CHATxIP | CHARxIP)) {
  382. writeb(RES_H_IUS, &channel->control);
  383. ZSDELAY();
  384. ZS_WSYNC(channel);
  385. if (r3 & CHARxIP)
  386. ip22zilog_receive_chars(up, channel, regs);
  387. if (r3 & CHAEXT)
  388. ip22zilog_status_handle(up, channel, regs);
  389. if (r3 & CHATxIP)
  390. ip22zilog_transmit_chars(up, channel);
  391. }
  392. spin_unlock(&up->port.lock);
  393. /* Channel B */
  394. up = up->next;
  395. channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
  396. spin_lock(&up->port.lock);
  397. if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) {
  398. writeb(RES_H_IUS, &channel->control);
  399. ZSDELAY();
  400. ZS_WSYNC(channel);
  401. if (r3 & CHBRxIP)
  402. ip22zilog_receive_chars(up, channel, regs);
  403. if (r3 & CHBEXT)
  404. ip22zilog_status_handle(up, channel, regs);
  405. if (r3 & CHBTxIP)
  406. ip22zilog_transmit_chars(up, channel);
  407. }
  408. spin_unlock(&up->port.lock);
  409. up = up->next;
  410. }
  411. return IRQ_HANDLED;
  412. }
  413. /* A convenient way to quickly get R0 status. The caller must _not_ hold the
  414. * port lock, it is acquired here.
  415. */
  416. static __inline__ unsigned char ip22zilog_read_channel_status(struct uart_port *port)
  417. {
  418. struct zilog_channel *channel;
  419. unsigned char status;
  420. channel = ZILOG_CHANNEL_FROM_PORT(port);
  421. status = readb(&channel->control);
  422. ZSDELAY();
  423. return status;
  424. }
  425. /* The port lock is not held. */
  426. static unsigned int ip22zilog_tx_empty(struct uart_port *port)
  427. {
  428. unsigned long flags;
  429. unsigned char status;
  430. unsigned int ret;
  431. spin_lock_irqsave(&port->lock, flags);
  432. status = ip22zilog_read_channel_status(port);
  433. spin_unlock_irqrestore(&port->lock, flags);
  434. if (status & Tx_BUF_EMP)
  435. ret = TIOCSER_TEMT;
  436. else
  437. ret = 0;
  438. return ret;
  439. }
  440. /* The port lock is held and interrupts are disabled. */
  441. static unsigned int ip22zilog_get_mctrl(struct uart_port *port)
  442. {
  443. unsigned char status;
  444. unsigned int ret;
  445. status = ip22zilog_read_channel_status(port);
  446. ret = 0;
  447. if (status & DCD)
  448. ret |= TIOCM_CAR;
  449. if (status & SYNC)
  450. ret |= TIOCM_DSR;
  451. if (status & CTS)
  452. ret |= TIOCM_CTS;
  453. return ret;
  454. }
  455. /* The port lock is held and interrupts are disabled. */
  456. static void ip22zilog_set_mctrl(struct uart_port *port, unsigned int mctrl)
  457. {
  458. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  459. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
  460. unsigned char set_bits, clear_bits;
  461. set_bits = clear_bits = 0;
  462. if (mctrl & TIOCM_RTS)
  463. set_bits |= RTS;
  464. else
  465. clear_bits |= RTS;
  466. if (mctrl & TIOCM_DTR)
  467. set_bits |= DTR;
  468. else
  469. clear_bits |= DTR;
  470. /* NOTE: Not subject to 'transmitter active' rule. */
  471. up->curregs[R5] |= set_bits;
  472. up->curregs[R5] &= ~clear_bits;
  473. write_zsreg(channel, R5, up->curregs[R5]);
  474. }
  475. /* The port lock is held and interrupts are disabled. */
  476. static void ip22zilog_stop_tx(struct uart_port *port)
  477. {
  478. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  479. up->flags |= IP22ZILOG_FLAG_TX_STOPPED;
  480. }
  481. /* The port lock is held and interrupts are disabled. */
  482. static void ip22zilog_start_tx(struct uart_port *port)
  483. {
  484. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  485. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
  486. unsigned char status;
  487. up->flags |= IP22ZILOG_FLAG_TX_ACTIVE;
  488. up->flags &= ~IP22ZILOG_FLAG_TX_STOPPED;
  489. status = readb(&channel->control);
  490. ZSDELAY();
  491. /* TX busy? Just wait for the TX done interrupt. */
  492. if (!(status & Tx_BUF_EMP))
  493. return;
  494. /* Send the first character to jump-start the TX done
  495. * IRQ sending engine.
  496. */
  497. if (port->x_char) {
  498. writeb(port->x_char, &channel->data);
  499. ZSDELAY();
  500. ZS_WSYNC(channel);
  501. port->icount.tx++;
  502. port->x_char = 0;
  503. } else {
  504. struct circ_buf *xmit = &port->info->xmit;
  505. writeb(xmit->buf[xmit->tail], &channel->data);
  506. ZSDELAY();
  507. ZS_WSYNC(channel);
  508. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  509. port->icount.tx++;
  510. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  511. uart_write_wakeup(&up->port);
  512. }
  513. }
  514. /* The port lock is held and interrupts are disabled. */
  515. static void ip22zilog_stop_rx(struct uart_port *port)
  516. {
  517. struct uart_ip22zilog_port *up = UART_ZILOG(port);
  518. struct zilog_channel *channel;
  519. if (ZS_IS_CONS(up))
  520. return;
  521. channel = ZILOG_CHANNEL_FROM_PORT(port);
  522. /* Disable all RX interrupts. */
  523. up->curregs[R1] &= ~RxINT_MASK;
  524. ip22zilog_maybe_update_regs(up, channel);
  525. }
  526. /* The port lock is held. */
  527. static void ip22zilog_enable_ms(struct uart_port *port)
  528. {
  529. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  530. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
  531. unsigned char new_reg;
  532. new_reg = up->curregs[R15] | (DCDIE | SYNCIE | CTSIE);
  533. if (new_reg != up->curregs[R15]) {
  534. up->curregs[R15] = new_reg;
  535. /* NOTE: Not subject to 'transmitter active' rule. */
  536. write_zsreg(channel, R15, up->curregs[R15]);
  537. }
  538. }
  539. /* The port lock is not held. */
  540. static void ip22zilog_break_ctl(struct uart_port *port, int break_state)
  541. {
  542. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  543. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
  544. unsigned char set_bits, clear_bits, new_reg;
  545. unsigned long flags;
  546. set_bits = clear_bits = 0;
  547. if (break_state)
  548. set_bits |= SND_BRK;
  549. else
  550. clear_bits |= SND_BRK;
  551. spin_lock_irqsave(&port->lock, flags);
  552. new_reg = (up->curregs[R5] | set_bits) & ~clear_bits;
  553. if (new_reg != up->curregs[R5]) {
  554. up->curregs[R5] = new_reg;
  555. /* NOTE: Not subject to 'transmitter active' rule. */
  556. write_zsreg(channel, R5, up->curregs[R5]);
  557. }
  558. spin_unlock_irqrestore(&port->lock, flags);
  559. }
  560. static void __ip22zilog_startup(struct uart_ip22zilog_port *up)
  561. {
  562. struct zilog_channel *channel;
  563. channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
  564. up->prev_status = readb(&channel->control);
  565. /* Enable receiver and transmitter. */
  566. up->curregs[R3] |= RxENAB;
  567. up->curregs[R5] |= TxENAB;
  568. up->curregs[R1] |= EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB;
  569. ip22zilog_maybe_update_regs(up, channel);
  570. }
  571. static int ip22zilog_startup(struct uart_port *port)
  572. {
  573. struct uart_ip22zilog_port *up = UART_ZILOG(port);
  574. unsigned long flags;
  575. if (ZS_IS_CONS(up))
  576. return 0;
  577. spin_lock_irqsave(&port->lock, flags);
  578. __ip22zilog_startup(up);
  579. spin_unlock_irqrestore(&port->lock, flags);
  580. return 0;
  581. }
  582. /*
  583. * The test for ZS_IS_CONS is explained by the following e-mail:
  584. *****
  585. * From: Russell King <rmk@arm.linux.org.uk>
  586. * Date: Sun, 8 Dec 2002 10:18:38 +0000
  587. *
  588. * On Sun, Dec 08, 2002 at 02:43:36AM -0500, Pete Zaitcev wrote:
  589. * > I boot my 2.5 boxes using "console=ttyS0,9600" argument,
  590. * > and I noticed that something is not right with reference
  591. * > counting in this case. It seems that when the console
  592. * > is open by kernel initially, this is not accounted
  593. * > as an open, and uart_startup is not called.
  594. *
  595. * That is correct. We are unable to call uart_startup when the serial
  596. * console is initialised because it may need to allocate memory (as
  597. * request_irq does) and the memory allocators may not have been
  598. * initialised.
  599. *
  600. * 1. initialise the port into a state where it can send characters in the
  601. * console write method.
  602. *
  603. * 2. don't do the actual hardware shutdown in your shutdown() method (but
  604. * do the normal software shutdown - ie, free irqs etc)
  605. *****
  606. */
  607. static void ip22zilog_shutdown(struct uart_port *port)
  608. {
  609. struct uart_ip22zilog_port *up = UART_ZILOG(port);
  610. struct zilog_channel *channel;
  611. unsigned long flags;
  612. if (ZS_IS_CONS(up))
  613. return;
  614. spin_lock_irqsave(&port->lock, flags);
  615. channel = ZILOG_CHANNEL_FROM_PORT(port);
  616. /* Disable receiver and transmitter. */
  617. up->curregs[R3] &= ~RxENAB;
  618. up->curregs[R5] &= ~TxENAB;
  619. /* Disable all interrupts and BRK assertion. */
  620. up->curregs[R1] &= ~(EXT_INT_ENAB | TxINT_ENAB | RxINT_MASK);
  621. up->curregs[R5] &= ~SND_BRK;
  622. ip22zilog_maybe_update_regs(up, channel);
  623. spin_unlock_irqrestore(&port->lock, flags);
  624. }
  625. /* Shared by TTY driver and serial console setup. The port lock is held
  626. * and local interrupts are disabled.
  627. */
  628. static void
  629. ip22zilog_convert_to_zs(struct uart_ip22zilog_port *up, unsigned int cflag,
  630. unsigned int iflag, int brg)
  631. {
  632. up->curregs[R10] = NRZ;
  633. up->curregs[R11] = TCBR | RCBR;
  634. /* Program BAUD and clock source. */
  635. up->curregs[R4] &= ~XCLK_MASK;
  636. up->curregs[R4] |= X16CLK;
  637. up->curregs[R12] = brg & 0xff;
  638. up->curregs[R13] = (brg >> 8) & 0xff;
  639. up->curregs[R14] = BRENAB;
  640. /* Character size, stop bits, and parity. */
  641. up->curregs[3] &= ~RxN_MASK;
  642. up->curregs[5] &= ~TxN_MASK;
  643. switch (cflag & CSIZE) {
  644. case CS5:
  645. up->curregs[3] |= Rx5;
  646. up->curregs[5] |= Tx5;
  647. up->parity_mask = 0x1f;
  648. break;
  649. case CS6:
  650. up->curregs[3] |= Rx6;
  651. up->curregs[5] |= Tx6;
  652. up->parity_mask = 0x3f;
  653. break;
  654. case CS7:
  655. up->curregs[3] |= Rx7;
  656. up->curregs[5] |= Tx7;
  657. up->parity_mask = 0x7f;
  658. break;
  659. case CS8:
  660. default:
  661. up->curregs[3] |= Rx8;
  662. up->curregs[5] |= Tx8;
  663. up->parity_mask = 0xff;
  664. break;
  665. };
  666. up->curregs[4] &= ~0x0c;
  667. if (cflag & CSTOPB)
  668. up->curregs[4] |= SB2;
  669. else
  670. up->curregs[4] |= SB1;
  671. if (cflag & PARENB)
  672. up->curregs[4] |= PAR_ENAB;
  673. else
  674. up->curregs[4] &= ~PAR_ENAB;
  675. if (!(cflag & PARODD))
  676. up->curregs[4] |= PAR_EVEN;
  677. else
  678. up->curregs[4] &= ~PAR_EVEN;
  679. up->port.read_status_mask = Rx_OVR;
  680. if (iflag & INPCK)
  681. up->port.read_status_mask |= CRC_ERR | PAR_ERR;
  682. if (iflag & (BRKINT | PARMRK))
  683. up->port.read_status_mask |= BRK_ABRT;
  684. up->port.ignore_status_mask = 0;
  685. if (iflag & IGNPAR)
  686. up->port.ignore_status_mask |= CRC_ERR | PAR_ERR;
  687. if (iflag & IGNBRK) {
  688. up->port.ignore_status_mask |= BRK_ABRT;
  689. if (iflag & IGNPAR)
  690. up->port.ignore_status_mask |= Rx_OVR;
  691. }
  692. if ((cflag & CREAD) == 0)
  693. up->port.ignore_status_mask = 0xff;
  694. }
  695. /* The port lock is not held. */
  696. static void
  697. ip22zilog_set_termios(struct uart_port *port, struct termios *termios,
  698. struct termios *old)
  699. {
  700. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  701. unsigned long flags;
  702. int baud, brg;
  703. baud = uart_get_baud_rate(port, termios, old, 1200, 76800);
  704. spin_lock_irqsave(&up->port.lock, flags);
  705. brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
  706. ip22zilog_convert_to_zs(up, termios->c_cflag, termios->c_iflag, brg);
  707. if (UART_ENABLE_MS(&up->port, termios->c_cflag))
  708. up->flags |= IP22ZILOG_FLAG_MODEM_STATUS;
  709. else
  710. up->flags &= ~IP22ZILOG_FLAG_MODEM_STATUS;
  711. up->cflag = termios->c_cflag;
  712. ip22zilog_maybe_update_regs(up, ZILOG_CHANNEL_FROM_PORT(port));
  713. spin_unlock_irqrestore(&up->port.lock, flags);
  714. }
  715. static const char *ip22zilog_type(struct uart_port *port)
  716. {
  717. return "IP22-Zilog";
  718. }
  719. /* We do not request/release mappings of the registers here, this
  720. * happens at early serial probe time.
  721. */
  722. static void ip22zilog_release_port(struct uart_port *port)
  723. {
  724. }
  725. static int ip22zilog_request_port(struct uart_port *port)
  726. {
  727. return 0;
  728. }
  729. /* These do not need to do anything interesting either. */
  730. static void ip22zilog_config_port(struct uart_port *port, int flags)
  731. {
  732. }
  733. /* We do not support letting the user mess with the divisor, IRQ, etc. */
  734. static int ip22zilog_verify_port(struct uart_port *port, struct serial_struct *ser)
  735. {
  736. return -EINVAL;
  737. }
  738. static struct uart_ops ip22zilog_pops = {
  739. .tx_empty = ip22zilog_tx_empty,
  740. .set_mctrl = ip22zilog_set_mctrl,
  741. .get_mctrl = ip22zilog_get_mctrl,
  742. .stop_tx = ip22zilog_stop_tx,
  743. .start_tx = ip22zilog_start_tx,
  744. .stop_rx = ip22zilog_stop_rx,
  745. .enable_ms = ip22zilog_enable_ms,
  746. .break_ctl = ip22zilog_break_ctl,
  747. .startup = ip22zilog_startup,
  748. .shutdown = ip22zilog_shutdown,
  749. .set_termios = ip22zilog_set_termios,
  750. .type = ip22zilog_type,
  751. .release_port = ip22zilog_release_port,
  752. .request_port = ip22zilog_request_port,
  753. .config_port = ip22zilog_config_port,
  754. .verify_port = ip22zilog_verify_port,
  755. };
  756. static struct uart_ip22zilog_port *ip22zilog_port_table;
  757. static struct zilog_layout **ip22zilog_chip_regs;
  758. static struct uart_ip22zilog_port *ip22zilog_irq_chain;
  759. static int zilog_irq = -1;
  760. static void * __init alloc_one_table(unsigned long size)
  761. {
  762. void *ret;
  763. ret = kmalloc(size, GFP_KERNEL);
  764. if (ret != NULL)
  765. memset(ret, 0, size);
  766. return ret;
  767. }
  768. static void __init ip22zilog_alloc_tables(void)
  769. {
  770. ip22zilog_port_table = (struct uart_ip22zilog_port *)
  771. alloc_one_table(NUM_CHANNELS * sizeof(struct uart_ip22zilog_port));
  772. ip22zilog_chip_regs = (struct zilog_layout **)
  773. alloc_one_table(NUM_IP22ZILOG * sizeof(struct zilog_layout *));
  774. if (ip22zilog_port_table == NULL || ip22zilog_chip_regs == NULL) {
  775. panic("IP22-Zilog: Cannot allocate IP22-Zilog tables.");
  776. }
  777. }
  778. /* Get the address of the registers for IP22-Zilog instance CHIP. */
  779. static struct zilog_layout * __init get_zs(int chip)
  780. {
  781. unsigned long base;
  782. if (chip < 0 || chip >= NUM_IP22ZILOG) {
  783. panic("IP22-Zilog: Illegal chip number %d in get_zs.", chip);
  784. }
  785. /* Not probe-able, hard code it. */
  786. base = (unsigned long) &sgioc->uart;
  787. zilog_irq = SGI_SERIAL_IRQ;
  788. request_mem_region(base, 8, "IP22-Zilog");
  789. return (struct zilog_layout *) base;
  790. }
  791. #define ZS_PUT_CHAR_MAX_DELAY 2000 /* 10 ms */
  792. #ifdef CONFIG_SERIAL_IP22_ZILOG_CONSOLE
  793. static void ip22zilog_put_char(struct zilog_channel *channel, unsigned char ch)
  794. {
  795. int loops = ZS_PUT_CHAR_MAX_DELAY;
  796. /* This is a timed polling loop so do not switch the explicit
  797. * udelay with ZSDELAY as that is a NOP on some platforms. -DaveM
  798. */
  799. do {
  800. unsigned char val = readb(&channel->control);
  801. if (val & Tx_BUF_EMP) {
  802. ZSDELAY();
  803. break;
  804. }
  805. udelay(5);
  806. } while (--loops);
  807. writeb(ch, &channel->data);
  808. ZSDELAY();
  809. ZS_WSYNC(channel);
  810. }
  811. static void
  812. ip22zilog_console_write(struct console *con, const char *s, unsigned int count)
  813. {
  814. struct uart_ip22zilog_port *up = &ip22zilog_port_table[con->index];
  815. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
  816. unsigned long flags;
  817. int i;
  818. spin_lock_irqsave(&up->port.lock, flags);
  819. for (i = 0; i < count; i++, s++) {
  820. ip22zilog_put_char(channel, *s);
  821. if (*s == 10)
  822. ip22zilog_put_char(channel, 13);
  823. }
  824. udelay(2);
  825. spin_unlock_irqrestore(&up->port.lock, flags);
  826. }
  827. void
  828. ip22serial_console_termios(struct console *con, char *options)
  829. {
  830. int baud = 9600, bits = 8, cflag;
  831. int parity = 'n';
  832. int flow = 'n';
  833. if (options)
  834. uart_parse_options(options, &baud, &parity, &bits, &flow);
  835. cflag = CREAD | HUPCL | CLOCAL;
  836. switch (baud) {
  837. case 150: cflag |= B150; break;
  838. case 300: cflag |= B300; break;
  839. case 600: cflag |= B600; break;
  840. case 1200: cflag |= B1200; break;
  841. case 2400: cflag |= B2400; break;
  842. case 4800: cflag |= B4800; break;
  843. case 9600: cflag |= B9600; break;
  844. case 19200: cflag |= B19200; break;
  845. case 38400: cflag |= B38400; break;
  846. default: baud = 9600; cflag |= B9600; break;
  847. }
  848. con->cflag = cflag | CS8; /* 8N1 */
  849. }
  850. static int __init ip22zilog_console_setup(struct console *con, char *options)
  851. {
  852. struct uart_ip22zilog_port *up = &ip22zilog_port_table[con->index];
  853. unsigned long flags;
  854. int baud, brg;
  855. printk("Console: ttyS%d (IP22-Zilog)\n", con->index);
  856. /* Get firmware console settings. */
  857. ip22serial_console_termios(con, options);
  858. /* Firmware console speed is limited to 150-->38400 baud so
  859. * this hackish cflag thing is OK.
  860. */
  861. switch (con->cflag & CBAUD) {
  862. case B150: baud = 150; break;
  863. case B300: baud = 300; break;
  864. case B600: baud = 600; break;
  865. case B1200: baud = 1200; break;
  866. case B2400: baud = 2400; break;
  867. case B4800: baud = 4800; break;
  868. default: case B9600: baud = 9600; break;
  869. case B19200: baud = 19200; break;
  870. case B38400: baud = 38400; break;
  871. };
  872. brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
  873. spin_lock_irqsave(&up->port.lock, flags);
  874. up->curregs[R15] = BRKIE;
  875. ip22zilog_convert_to_zs(up, con->cflag, 0, brg);
  876. __ip22zilog_startup(up);
  877. spin_unlock_irqrestore(&up->port.lock, flags);
  878. return 0;
  879. }
  880. static struct uart_driver ip22zilog_reg;
  881. static struct console ip22zilog_console = {
  882. .name = "ttyS",
  883. .write = ip22zilog_console_write,
  884. .device = uart_console_device,
  885. .setup = ip22zilog_console_setup,
  886. .flags = CON_PRINTBUFFER,
  887. .index = -1,
  888. .data = &ip22zilog_reg,
  889. };
  890. #endif /* CONFIG_SERIAL_IP22_ZILOG_CONSOLE */
  891. static struct uart_driver ip22zilog_reg = {
  892. .owner = THIS_MODULE,
  893. .driver_name = "serial",
  894. .devfs_name = "tts/",
  895. .dev_name = "ttyS",
  896. .major = TTY_MAJOR,
  897. .minor = 64,
  898. .nr = NUM_CHANNELS,
  899. #ifdef CONFIG_SERIAL_IP22_ZILOG_CONSOLE
  900. .cons = &ip22zilog_console,
  901. #endif
  902. };
  903. static void __init ip22zilog_prepare(void)
  904. {
  905. struct uart_ip22zilog_port *up;
  906. struct zilog_layout *rp;
  907. int channel, chip;
  908. /*
  909. * Temporary fix.
  910. */
  911. for (channel = 0; channel < NUM_CHANNELS; channel++)
  912. spin_lock_init(&ip22zilog_port_table[channel].port.lock);
  913. ip22zilog_irq_chain = &ip22zilog_port_table[NUM_CHANNELS - 1];
  914. up = &ip22zilog_port_table[0];
  915. for (channel = NUM_CHANNELS - 1 ; channel > 0; channel--)
  916. up[channel].next = &up[channel - 1];
  917. up[channel].next = NULL;
  918. for (chip = 0; chip < NUM_IP22ZILOG; chip++) {
  919. if (!ip22zilog_chip_regs[chip]) {
  920. ip22zilog_chip_regs[chip] = rp = get_zs(chip);
  921. up[(chip * 2) + 0].port.membase = (char *) &rp->channelB;
  922. up[(chip * 2) + 1].port.membase = (char *) &rp->channelA;
  923. /* In theory mapbase is the physical address ... */
  924. up[(chip * 2) + 0].port.mapbase =
  925. (unsigned long) ioremap((unsigned long) &rp->channelB, 8);
  926. up[(chip * 2) + 1].port.mapbase =
  927. (unsigned long) ioremap((unsigned long) &rp->channelA, 8);
  928. }
  929. /* Channel A */
  930. up[(chip * 2) + 0].port.iotype = UPIO_MEM;
  931. up[(chip * 2) + 0].port.irq = zilog_irq;
  932. up[(chip * 2) + 0].port.uartclk = ZS_CLOCK;
  933. up[(chip * 2) + 0].port.fifosize = 1;
  934. up[(chip * 2) + 0].port.ops = &ip22zilog_pops;
  935. up[(chip * 2) + 0].port.type = PORT_IP22ZILOG;
  936. up[(chip * 2) + 0].port.flags = 0;
  937. up[(chip * 2) + 0].port.line = (chip * 2) + 0;
  938. up[(chip * 2) + 0].flags = 0;
  939. /* Channel B */
  940. up[(chip * 2) + 1].port.iotype = UPIO_MEM;
  941. up[(chip * 2) + 1].port.irq = zilog_irq;
  942. up[(chip * 2) + 1].port.uartclk = ZS_CLOCK;
  943. up[(chip * 2) + 1].port.fifosize = 1;
  944. up[(chip * 2) + 1].port.ops = &ip22zilog_pops;
  945. up[(chip * 2) + 1].port.type = PORT_IP22ZILOG;
  946. up[(chip * 2) + 1].port.flags |= IP22ZILOG_FLAG_IS_CHANNEL_A;
  947. up[(chip * 2) + 1].port.line = (chip * 2) + 1;
  948. up[(chip * 2) + 1].flags = 0;
  949. }
  950. }
  951. static void __init ip22zilog_init_hw(void)
  952. {
  953. int i;
  954. for (i = 0; i < NUM_CHANNELS; i++) {
  955. struct uart_ip22zilog_port *up = &ip22zilog_port_table[i];
  956. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
  957. unsigned long flags;
  958. int baud, brg;
  959. spin_lock_irqsave(&up->port.lock, flags);
  960. if (ZS_IS_CHANNEL_A(up)) {
  961. write_zsreg(channel, R9, FHWRES);
  962. ZSDELAY_LONG();
  963. (void) read_zsreg(channel, R0);
  964. }
  965. /* Normal serial TTY. */
  966. up->parity_mask = 0xff;
  967. up->curregs[R1] = EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB;
  968. up->curregs[R4] = PAR_EVEN | X16CLK | SB1;
  969. up->curregs[R3] = RxENAB | Rx8;
  970. up->curregs[R5] = TxENAB | Tx8;
  971. up->curregs[R9] = NV | MIE;
  972. up->curregs[R10] = NRZ;
  973. up->curregs[R11] = TCBR | RCBR;
  974. baud = 9600;
  975. brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
  976. up->curregs[R12] = (brg & 0xff);
  977. up->curregs[R13] = (brg >> 8) & 0xff;
  978. up->curregs[R14] = BRENAB;
  979. __load_zsregs(channel, up->curregs);
  980. /* set master interrupt enable */
  981. write_zsreg(channel, R9, up->curregs[R9]);
  982. spin_unlock_irqrestore(&up->port.lock, flags);
  983. }
  984. }
  985. static int __init ip22zilog_ports_init(void)
  986. {
  987. int ret;
  988. printk(KERN_INFO "Serial: IP22 Zilog driver (%d chips).\n", NUM_IP22ZILOG);
  989. ip22zilog_prepare();
  990. if (request_irq(zilog_irq, ip22zilog_interrupt, 0,
  991. "IP22-Zilog", ip22zilog_irq_chain)) {
  992. panic("IP22-Zilog: Unable to register zs interrupt handler.\n");
  993. }
  994. ip22zilog_init_hw();
  995. ret = uart_register_driver(&ip22zilog_reg);
  996. if (ret == 0) {
  997. int i;
  998. for (i = 0; i < NUM_CHANNELS; i++) {
  999. struct uart_ip22zilog_port *up = &ip22zilog_port_table[i];
  1000. uart_add_one_port(&ip22zilog_reg, &up->port);
  1001. }
  1002. }
  1003. return ret;
  1004. }
  1005. static int __init ip22zilog_init(void)
  1006. {
  1007. /* IP22 Zilog setup is hard coded, no probing to do. */
  1008. ip22zilog_alloc_tables();
  1009. ip22zilog_ports_init();
  1010. return 0;
  1011. }
  1012. static void __exit ip22zilog_exit(void)
  1013. {
  1014. int i;
  1015. for (i = 0; i < NUM_CHANNELS; i++) {
  1016. struct uart_ip22zilog_port *up = &ip22zilog_port_table[i];
  1017. uart_remove_one_port(&ip22zilog_reg, &up->port);
  1018. }
  1019. uart_unregister_driver(&ip22zilog_reg);
  1020. }
  1021. module_init(ip22zilog_init);
  1022. module_exit(ip22zilog_exit);
  1023. /* David wrote it but I'm to blame for the bugs ... */
  1024. MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");
  1025. MODULE_DESCRIPTION("SGI Zilog serial port driver");
  1026. MODULE_LICENSE("GPL");