ip22zilog.c 32 KB

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