ip22zilog.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  1. /*
  2. * Driver for Zilog serial chips found on SGI workstations and
  3. * servers. This driver could actually be made more generic.
  4. *
  5. * This is based on the drivers/serial/sunzilog.c code as of 2.6.0-test7 and the
  6. * old drivers/sgi/char/sgiserial.c code which itself is based of the original
  7. * drivers/sbus/char/zs.c code. A lot of code has been simply moved over
  8. * directly from there but much has been rewritten. Credits therefore go out
  9. * to David S. Miller, Eddie C. Dost, Pete Zaitcev, Ted Ts'o and Alex Buell
  10. * for their work there.
  11. *
  12. * Copyright (C) 2002 Ralf Baechle (ralf@linux-mips.org)
  13. * Copyright (C) 2002 David S. Miller (davem@redhat.com)
  14. */
  15. #include <linux/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 zilog_channel *channel, unsigned char ch)
  792. {
  793. int loops = ZS_PUT_CHAR_MAX_DELAY;
  794. /* This is a timed polling loop so do not switch the explicit
  795. * udelay with ZSDELAY as that is a NOP on some platforms. -DaveM
  796. */
  797. do {
  798. unsigned char val = readb(&channel->control);
  799. if (val & Tx_BUF_EMP) {
  800. ZSDELAY();
  801. break;
  802. }
  803. udelay(5);
  804. } while (--loops);
  805. writeb(ch, &channel->data);
  806. ZSDELAY();
  807. ZS_WSYNC(channel);
  808. }
  809. static void
  810. ip22zilog_console_write(struct console *con, const char *s, unsigned int count)
  811. {
  812. struct uart_ip22zilog_port *up = &ip22zilog_port_table[con->index];
  813. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
  814. unsigned long flags;
  815. int i;
  816. spin_lock_irqsave(&up->port.lock, flags);
  817. for (i = 0; i < count; i++, s++) {
  818. ip22zilog_put_char(channel, *s);
  819. if (*s == 10)
  820. ip22zilog_put_char(channel, 13);
  821. }
  822. udelay(2);
  823. spin_unlock_irqrestore(&up->port.lock, flags);
  824. }
  825. void
  826. ip22serial_console_termios(struct console *con, char *options)
  827. {
  828. int baud = 9600, bits = 8, cflag;
  829. int parity = 'n';
  830. int flow = 'n';
  831. if (options)
  832. uart_parse_options(options, &baud, &parity, &bits, &flow);
  833. cflag = CREAD | HUPCL | CLOCAL;
  834. switch (baud) {
  835. case 150: cflag |= B150; break;
  836. case 300: cflag |= B300; break;
  837. case 600: cflag |= B600; break;
  838. case 1200: cflag |= B1200; break;
  839. case 2400: cflag |= B2400; break;
  840. case 4800: cflag |= B4800; break;
  841. case 9600: cflag |= B9600; break;
  842. case 19200: cflag |= B19200; break;
  843. case 38400: cflag |= B38400; break;
  844. default: baud = 9600; cflag |= B9600; break;
  845. }
  846. con->cflag = cflag | CS8; /* 8N1 */
  847. }
  848. static int __init ip22zilog_console_setup(struct console *con, char *options)
  849. {
  850. struct uart_ip22zilog_port *up = &ip22zilog_port_table[con->index];
  851. unsigned long flags;
  852. int baud, brg;
  853. printk("Console: ttyS%d (IP22-Zilog)\n", con->index);
  854. /* Get firmware console settings. */
  855. ip22serial_console_termios(con, options);
  856. /* Firmware console speed is limited to 150-->38400 baud so
  857. * this hackish cflag thing is OK.
  858. */
  859. switch (con->cflag & CBAUD) {
  860. case B150: baud = 150; break;
  861. case B300: baud = 300; break;
  862. case B600: baud = 600; break;
  863. case B1200: baud = 1200; break;
  864. case B2400: baud = 2400; break;
  865. case B4800: baud = 4800; break;
  866. default: case B9600: baud = 9600; break;
  867. case B19200: baud = 19200; break;
  868. case B38400: baud = 38400; break;
  869. };
  870. brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
  871. spin_lock_irqsave(&up->port.lock, flags);
  872. up->curregs[R15] = BRKIE;
  873. ip22zilog_convert_to_zs(up, con->cflag, 0, brg);
  874. __ip22zilog_startup(up);
  875. spin_unlock_irqrestore(&up->port.lock, flags);
  876. return 0;
  877. }
  878. static struct uart_driver ip22zilog_reg;
  879. static struct console ip22zilog_console = {
  880. .name = "ttyS",
  881. .write = ip22zilog_console_write,
  882. .device = uart_console_device,
  883. .setup = ip22zilog_console_setup,
  884. .flags = CON_PRINTBUFFER,
  885. .index = -1,
  886. .data = &ip22zilog_reg,
  887. };
  888. #endif /* CONFIG_SERIAL_IP22_ZILOG_CONSOLE */
  889. static struct uart_driver ip22zilog_reg = {
  890. .owner = THIS_MODULE,
  891. .driver_name = "serial",
  892. .devfs_name = "tts/",
  893. .dev_name = "ttyS",
  894. .major = TTY_MAJOR,
  895. .minor = 64,
  896. .nr = NUM_CHANNELS,
  897. #ifdef CONFIG_SERIAL_IP22_ZILOG_CONSOLE
  898. .cons = &ip22zilog_console,
  899. #endif
  900. };
  901. static void __init ip22zilog_prepare(void)
  902. {
  903. struct uart_ip22zilog_port *up;
  904. struct zilog_layout *rp;
  905. int channel, chip;
  906. /*
  907. * Temporary fix.
  908. */
  909. for (channel = 0; channel < NUM_CHANNELS; channel++)
  910. spin_lock_init(&ip22zilog_port_table[channel].port.lock);
  911. ip22zilog_irq_chain = &ip22zilog_port_table[NUM_CHANNELS - 1];
  912. up = &ip22zilog_port_table[0];
  913. for (channel = NUM_CHANNELS - 1 ; channel > 0; channel--)
  914. up[channel].next = &up[channel - 1];
  915. up[channel].next = NULL;
  916. for (chip = 0; chip < NUM_IP22ZILOG; chip++) {
  917. if (!ip22zilog_chip_regs[chip]) {
  918. ip22zilog_chip_regs[chip] = rp = get_zs(chip);
  919. up[(chip * 2) + 0].port.membase = (char *) &rp->channelB;
  920. up[(chip * 2) + 1].port.membase = (char *) &rp->channelA;
  921. /* In theory mapbase is the physical address ... */
  922. up[(chip * 2) + 0].port.mapbase =
  923. (unsigned long) ioremap((unsigned long) &rp->channelB, 8);
  924. up[(chip * 2) + 1].port.mapbase =
  925. (unsigned long) ioremap((unsigned long) &rp->channelA, 8);
  926. }
  927. /* Channel A */
  928. up[(chip * 2) + 0].port.iotype = UPIO_MEM;
  929. up[(chip * 2) + 0].port.irq = zilog_irq;
  930. up[(chip * 2) + 0].port.uartclk = ZS_CLOCK;
  931. up[(chip * 2) + 0].port.fifosize = 1;
  932. up[(chip * 2) + 0].port.ops = &ip22zilog_pops;
  933. up[(chip * 2) + 0].port.type = PORT_IP22ZILOG;
  934. up[(chip * 2) + 0].port.flags = 0;
  935. up[(chip * 2) + 0].port.line = (chip * 2) + 0;
  936. up[(chip * 2) + 0].flags = 0;
  937. /* Channel B */
  938. up[(chip * 2) + 1].port.iotype = UPIO_MEM;
  939. up[(chip * 2) + 1].port.irq = zilog_irq;
  940. up[(chip * 2) + 1].port.uartclk = ZS_CLOCK;
  941. up[(chip * 2) + 1].port.fifosize = 1;
  942. up[(chip * 2) + 1].port.ops = &ip22zilog_pops;
  943. up[(chip * 2) + 1].port.type = PORT_IP22ZILOG;
  944. up[(chip * 2) + 1].port.flags |= IP22ZILOG_FLAG_IS_CHANNEL_A;
  945. up[(chip * 2) + 1].port.line = (chip * 2) + 1;
  946. up[(chip * 2) + 1].flags = 0;
  947. }
  948. }
  949. static void __init ip22zilog_init_hw(void)
  950. {
  951. int i;
  952. for (i = 0; i < NUM_CHANNELS; i++) {
  953. struct uart_ip22zilog_port *up = &ip22zilog_port_table[i];
  954. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
  955. unsigned long flags;
  956. int baud, brg;
  957. spin_lock_irqsave(&up->port.lock, flags);
  958. if (ZS_IS_CHANNEL_A(up)) {
  959. write_zsreg(channel, R9, FHWRES);
  960. ZSDELAY_LONG();
  961. (void) read_zsreg(channel, R0);
  962. }
  963. /* Normal serial TTY. */
  964. up->parity_mask = 0xff;
  965. up->curregs[R1] = EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB;
  966. up->curregs[R4] = PAR_EVEN | X16CLK | SB1;
  967. up->curregs[R3] = RxENAB | Rx8;
  968. up->curregs[R5] = TxENAB | Tx8;
  969. up->curregs[R9] = NV | MIE;
  970. up->curregs[R10] = NRZ;
  971. up->curregs[R11] = TCBR | RCBR;
  972. baud = 9600;
  973. brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
  974. up->curregs[R12] = (brg & 0xff);
  975. up->curregs[R13] = (brg >> 8) & 0xff;
  976. up->curregs[R14] = BRENAB;
  977. __load_zsregs(channel, up->curregs);
  978. /* set master interrupt enable */
  979. write_zsreg(channel, R9, up->curregs[R9]);
  980. spin_unlock_irqrestore(&up->port.lock, flags);
  981. }
  982. }
  983. static int __init ip22zilog_ports_init(void)
  984. {
  985. int ret;
  986. printk(KERN_INFO "Serial: IP22 Zilog driver (%d chips).\n", NUM_IP22ZILOG);
  987. ip22zilog_prepare();
  988. if (request_irq(zilog_irq, ip22zilog_interrupt, 0,
  989. "IP22-Zilog", ip22zilog_irq_chain)) {
  990. panic("IP22-Zilog: Unable to register zs interrupt handler.\n");
  991. }
  992. ip22zilog_init_hw();
  993. ret = uart_register_driver(&ip22zilog_reg);
  994. if (ret == 0) {
  995. int i;
  996. for (i = 0; i < NUM_CHANNELS; i++) {
  997. struct uart_ip22zilog_port *up = &ip22zilog_port_table[i];
  998. uart_add_one_port(&ip22zilog_reg, &up->port);
  999. }
  1000. }
  1001. return ret;
  1002. }
  1003. static int __init ip22zilog_init(void)
  1004. {
  1005. /* IP22 Zilog setup is hard coded, no probing to do. */
  1006. ip22zilog_alloc_tables();
  1007. ip22zilog_ports_init();
  1008. return 0;
  1009. }
  1010. static void __exit ip22zilog_exit(void)
  1011. {
  1012. int i;
  1013. for (i = 0; i < NUM_CHANNELS; i++) {
  1014. struct uart_ip22zilog_port *up = &ip22zilog_port_table[i];
  1015. uart_remove_one_port(&ip22zilog_reg, &up->port);
  1016. }
  1017. uart_unregister_driver(&ip22zilog_reg);
  1018. }
  1019. module_init(ip22zilog_init);
  1020. module_exit(ip22zilog_exit);
  1021. /* David wrote it but I'm to blame for the bugs ... */
  1022. MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");
  1023. MODULE_DESCRIPTION("SGI Zilog serial port driver");
  1024. MODULE_LICENSE("GPL");