zs.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  1. /*
  2. * zs.c: Serial port driver for IOASIC DECstations.
  3. *
  4. * Derived from drivers/sbus/char/sunserial.c by Paul Mackerras.
  5. * Derived from drivers/macintosh/macserial.c by Harald Koerfgen.
  6. *
  7. * DECstation changes
  8. * Copyright (C) 1998-2000 Harald Koerfgen
  9. * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007 Maciej W. Rozycki
  10. *
  11. * For the rest of the code the original Copyright applies:
  12. * Copyright (C) 1996 Paul Mackerras (Paul.Mackerras@cs.anu.edu.au)
  13. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  14. *
  15. *
  16. * Note: for IOASIC systems the wiring is as follows:
  17. *
  18. * mouse/keyboard:
  19. * DIN-7 MJ-4 signal SCC
  20. * 2 1 TxD <- A.TxD
  21. * 3 4 RxD -> A.RxD
  22. *
  23. * EIA-232/EIA-423:
  24. * DB-25 MMJ-6 signal SCC
  25. * 2 2 TxD <- B.TxD
  26. * 3 5 RxD -> B.RxD
  27. * 4 RTS <- ~A.RTS
  28. * 5 CTS -> ~B.CTS
  29. * 6 6 DSR -> ~A.SYNC
  30. * 8 CD -> ~B.DCD
  31. * 12 DSRS(DCE) -> ~A.CTS (*)
  32. * 15 TxC -> B.TxC
  33. * 17 RxC -> B.RxC
  34. * 20 1 DTR <- ~A.DTR
  35. * 22 RI -> ~A.DCD
  36. * 23 DSRS(DTE) <- ~B.RTS
  37. *
  38. * (*) EIA-232 defines the signal at this pin to be SCD, while DSRS(DCE)
  39. * is shared with DSRS(DTE) at pin 23.
  40. *
  41. * As you can immediately notice the wiring of the RTS, DTR and DSR signals
  42. * is a bit odd. This makes the handling of port B unnecessarily
  43. * complicated and prevents the use of some automatic modes of operation.
  44. */
  45. #if defined(CONFIG_SERIAL_ZS_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  46. #define SUPPORT_SYSRQ
  47. #endif
  48. #include <linux/bug.h>
  49. #include <linux/console.h>
  50. #include <linux/delay.h>
  51. #include <linux/errno.h>
  52. #include <linux/init.h>
  53. #include <linux/interrupt.h>
  54. #include <linux/io.h>
  55. #include <linux/ioport.h>
  56. #include <linux/irqflags.h>
  57. #include <linux/kernel.h>
  58. #include <linux/major.h>
  59. #include <linux/serial.h>
  60. #include <linux/serial_core.h>
  61. #include <linux/spinlock.h>
  62. #include <linux/sysrq.h>
  63. #include <linux/tty.h>
  64. #include <linux/types.h>
  65. #include <asm/atomic.h>
  66. #include <asm/system.h>
  67. #include <asm/dec/interrupts.h>
  68. #include <asm/dec/ioasic_addrs.h>
  69. #include <asm/dec/system.h>
  70. #include "zs.h"
  71. MODULE_AUTHOR("Maciej W. Rozycki <macro@linux-mips.org>");
  72. MODULE_DESCRIPTION("DECstation Z85C30 serial driver");
  73. MODULE_LICENSE("GPL");
  74. static char zs_name[] __initdata = "DECstation Z85C30 serial driver version ";
  75. static char zs_version[] __initdata = "0.10";
  76. /*
  77. * It would be nice to dynamically allocate everything that
  78. * depends on ZS_NUM_SCCS, so we could support any number of
  79. * Z85C30s, but for now...
  80. */
  81. #define ZS_NUM_SCCS 2 /* Max # of ZS chips supported. */
  82. #define ZS_NUM_CHAN 2 /* 2 channels per chip. */
  83. #define ZS_CHAN_A 0 /* Index of the channel A. */
  84. #define ZS_CHAN_B 1 /* Index of the channel B. */
  85. #define ZS_CHAN_IO_SIZE 8 /* IOMEM space size. */
  86. #define ZS_CHAN_IO_STRIDE 4 /* Register alignment. */
  87. #define ZS_CHAN_IO_OFFSET 1 /* The SCC resides on the high byte
  88. of the 16-bit IOBUS. */
  89. #define ZS_CLOCK 7372800 /* Z85C30 PCLK input clock rate. */
  90. #define to_zport(uport) container_of(uport, struct zs_port, port)
  91. struct zs_parms {
  92. resource_size_t scc[ZS_NUM_SCCS];
  93. int irq[ZS_NUM_SCCS];
  94. };
  95. static struct zs_scc zs_sccs[ZS_NUM_SCCS];
  96. static u8 zs_init_regs[ZS_NUM_REGS] __initdata = {
  97. 0, /* write 0 */
  98. PAR_SPEC, /* write 1 */
  99. 0, /* write 2 */
  100. 0, /* write 3 */
  101. X16CLK | SB1, /* write 4 */
  102. 0, /* write 5 */
  103. 0, 0, 0, /* write 6, 7, 8 */
  104. MIE | DLC | NV, /* write 9 */
  105. NRZ, /* write 10 */
  106. TCBR | RCBR, /* write 11 */
  107. 0, 0, /* BRG time constant, write 12 + 13 */
  108. BRSRC | BRENABL, /* write 14 */
  109. 0, /* write 15 */
  110. };
  111. /*
  112. * Debugging.
  113. */
  114. #undef ZS_DEBUG_REGS
  115. /*
  116. * Reading and writing Z85C30 registers.
  117. */
  118. static void recovery_delay(void)
  119. {
  120. udelay(2);
  121. }
  122. static u8 read_zsreg(struct zs_port *zport, int reg)
  123. {
  124. void __iomem *control = zport->port.membase + ZS_CHAN_IO_OFFSET;
  125. u8 retval;
  126. if (reg != 0) {
  127. writeb(reg & 0xf, control);
  128. fast_iob();
  129. recovery_delay();
  130. }
  131. retval = readb(control);
  132. recovery_delay();
  133. return retval;
  134. }
  135. static void write_zsreg(struct zs_port *zport, int reg, u8 value)
  136. {
  137. void __iomem *control = zport->port.membase + ZS_CHAN_IO_OFFSET;
  138. if (reg != 0) {
  139. writeb(reg & 0xf, control);
  140. fast_iob(); recovery_delay();
  141. }
  142. writeb(value, control);
  143. fast_iob();
  144. recovery_delay();
  145. return;
  146. }
  147. static u8 read_zsdata(struct zs_port *zport)
  148. {
  149. void __iomem *data = zport->port.membase +
  150. ZS_CHAN_IO_STRIDE + ZS_CHAN_IO_OFFSET;
  151. u8 retval;
  152. retval = readb(data);
  153. recovery_delay();
  154. return retval;
  155. }
  156. static void write_zsdata(struct zs_port *zport, u8 value)
  157. {
  158. void __iomem *data = zport->port.membase +
  159. ZS_CHAN_IO_STRIDE + ZS_CHAN_IO_OFFSET;
  160. writeb(value, data);
  161. fast_iob();
  162. recovery_delay();
  163. return;
  164. }
  165. #ifdef ZS_DEBUG_REGS
  166. void zs_dump(void)
  167. {
  168. struct zs_port *zport;
  169. int i, j;
  170. for (i = 0; i < ZS_NUM_SCCS * ZS_NUM_CHAN; i++) {
  171. zport = &zs_sccs[i / ZS_NUM_CHAN].zport[i % ZS_NUM_CHAN];
  172. if (!zport->scc)
  173. continue;
  174. for (j = 0; j < 16; j++)
  175. printk("W%-2d = 0x%02x\t", j, zport->regs[j]);
  176. printk("\n");
  177. for (j = 0; j < 16; j++)
  178. printk("R%-2d = 0x%02x\t", j, read_zsreg(zport, j));
  179. printk("\n\n");
  180. }
  181. }
  182. #endif
  183. static void zs_spin_lock_cond_irq(spinlock_t *lock, int irq)
  184. {
  185. if (irq)
  186. spin_lock_irq(lock);
  187. else
  188. spin_lock(lock);
  189. }
  190. static void zs_spin_unlock_cond_irq(spinlock_t *lock, int irq)
  191. {
  192. if (irq)
  193. spin_unlock_irq(lock);
  194. else
  195. spin_unlock(lock);
  196. }
  197. static int zs_receive_drain(struct zs_port *zport)
  198. {
  199. int loops = 10000;
  200. while ((read_zsreg(zport, R0) & Rx_CH_AV) && --loops)
  201. read_zsdata(zport);
  202. return loops;
  203. }
  204. static int zs_transmit_drain(struct zs_port *zport, int irq)
  205. {
  206. struct zs_scc *scc = zport->scc;
  207. int loops = 10000;
  208. while (!(read_zsreg(zport, R0) & Tx_BUF_EMP) && --loops) {
  209. zs_spin_unlock_cond_irq(&scc->zlock, irq);
  210. udelay(2);
  211. zs_spin_lock_cond_irq(&scc->zlock, irq);
  212. }
  213. return loops;
  214. }
  215. static int zs_line_drain(struct zs_port *zport, int irq)
  216. {
  217. struct zs_scc *scc = zport->scc;
  218. int loops = 10000;
  219. while (!(read_zsreg(zport, R1) & ALL_SNT) && --loops) {
  220. zs_spin_unlock_cond_irq(&scc->zlock, irq);
  221. udelay(2);
  222. zs_spin_lock_cond_irq(&scc->zlock, irq);
  223. }
  224. return loops;
  225. }
  226. static void load_zsregs(struct zs_port *zport, u8 *regs, int irq)
  227. {
  228. /* Let the current transmission finish. */
  229. zs_line_drain(zport, irq);
  230. /* Load 'em up. */
  231. write_zsreg(zport, R3, regs[3] & ~RxENABLE);
  232. write_zsreg(zport, R5, regs[5] & ~TxENAB);
  233. write_zsreg(zport, R4, regs[4]);
  234. write_zsreg(zport, R9, regs[9]);
  235. write_zsreg(zport, R1, regs[1]);
  236. write_zsreg(zport, R2, regs[2]);
  237. write_zsreg(zport, R10, regs[10]);
  238. write_zsreg(zport, R14, regs[14] & ~BRENABL);
  239. write_zsreg(zport, R11, regs[11]);
  240. write_zsreg(zport, R12, regs[12]);
  241. write_zsreg(zport, R13, regs[13]);
  242. write_zsreg(zport, R14, regs[14]);
  243. write_zsreg(zport, R15, regs[15]);
  244. if (regs[3] & RxENABLE)
  245. write_zsreg(zport, R3, regs[3]);
  246. if (regs[5] & TxENAB)
  247. write_zsreg(zport, R5, regs[5]);
  248. return;
  249. }
  250. /*
  251. * Status handling routines.
  252. */
  253. /*
  254. * zs_tx_empty() -- get the transmitter empty status
  255. *
  256. * Purpose: Let user call ioctl() to get info when the UART physically
  257. * is emptied. On bus types like RS485, the transmitter must
  258. * release the bus after transmitting. This must be done when
  259. * the transmit shift register is empty, not be done when the
  260. * transmit holding register is empty. This functionality
  261. * allows an RS485 driver to be written in user space.
  262. */
  263. static unsigned int zs_tx_empty(struct uart_port *uport)
  264. {
  265. struct zs_port *zport = to_zport(uport);
  266. struct zs_scc *scc = zport->scc;
  267. unsigned long flags;
  268. u8 status;
  269. spin_lock_irqsave(&scc->zlock, flags);
  270. status = read_zsreg(zport, R1);
  271. spin_unlock_irqrestore(&scc->zlock, flags);
  272. return status & ALL_SNT ? TIOCSER_TEMT : 0;
  273. }
  274. static unsigned int zs_raw_get_ab_mctrl(struct zs_port *zport_a,
  275. struct zs_port *zport_b)
  276. {
  277. u8 status_a, status_b;
  278. unsigned int mctrl;
  279. status_a = read_zsreg(zport_a, R0);
  280. status_b = read_zsreg(zport_b, R0);
  281. mctrl = ((status_b & CTS) ? TIOCM_CTS : 0) |
  282. ((status_b & DCD) ? TIOCM_CAR : 0) |
  283. ((status_a & DCD) ? TIOCM_RNG : 0) |
  284. ((status_a & SYNC_HUNT) ? TIOCM_DSR : 0);
  285. return mctrl;
  286. }
  287. static unsigned int zs_raw_get_mctrl(struct zs_port *zport)
  288. {
  289. struct zs_port *zport_a = &zport->scc->zport[ZS_CHAN_A];
  290. return zport != zport_a ? zs_raw_get_ab_mctrl(zport_a, zport) : 0;
  291. }
  292. static unsigned int zs_raw_xor_mctrl(struct zs_port *zport)
  293. {
  294. struct zs_port *zport_a = &zport->scc->zport[ZS_CHAN_A];
  295. unsigned int mmask, mctrl, delta;
  296. u8 mask_a, mask_b;
  297. if (zport == zport_a)
  298. return 0;
  299. mask_a = zport_a->regs[15];
  300. mask_b = zport->regs[15];
  301. mmask = ((mask_b & CTSIE) ? TIOCM_CTS : 0) |
  302. ((mask_b & DCDIE) ? TIOCM_CAR : 0) |
  303. ((mask_a & DCDIE) ? TIOCM_RNG : 0) |
  304. ((mask_a & SYNCIE) ? TIOCM_DSR : 0);
  305. mctrl = zport->mctrl;
  306. if (mmask) {
  307. mctrl &= ~mmask;
  308. mctrl |= zs_raw_get_ab_mctrl(zport_a, zport) & mmask;
  309. }
  310. delta = mctrl ^ zport->mctrl;
  311. if (delta)
  312. zport->mctrl = mctrl;
  313. return delta;
  314. }
  315. static unsigned int zs_get_mctrl(struct uart_port *uport)
  316. {
  317. struct zs_port *zport = to_zport(uport);
  318. struct zs_scc *scc = zport->scc;
  319. unsigned int mctrl;
  320. spin_lock(&scc->zlock);
  321. mctrl = zs_raw_get_mctrl(zport);
  322. spin_unlock(&scc->zlock);
  323. return mctrl;
  324. }
  325. static void zs_set_mctrl(struct uart_port *uport, unsigned int mctrl)
  326. {
  327. struct zs_port *zport = to_zport(uport);
  328. struct zs_scc *scc = zport->scc;
  329. struct zs_port *zport_a = &scc->zport[ZS_CHAN_A];
  330. u8 oldloop, newloop;
  331. spin_lock(&scc->zlock);
  332. if (zport != zport_a) {
  333. if (mctrl & TIOCM_DTR)
  334. zport_a->regs[5] |= DTR;
  335. else
  336. zport_a->regs[5] &= ~DTR;
  337. if (mctrl & TIOCM_RTS)
  338. zport_a->regs[5] |= RTS;
  339. else
  340. zport_a->regs[5] &= ~RTS;
  341. write_zsreg(zport_a, R5, zport_a->regs[5]);
  342. }
  343. /* Rarely modified, so don't poke at hardware unless necessary. */
  344. oldloop = zport->regs[14];
  345. newloop = oldloop;
  346. if (mctrl & TIOCM_LOOP)
  347. newloop |= LOOPBAK;
  348. else
  349. newloop &= ~LOOPBAK;
  350. if (newloop != oldloop) {
  351. zport->regs[14] = newloop;
  352. write_zsreg(zport, R14, zport->regs[14]);
  353. }
  354. spin_unlock(&scc->zlock);
  355. }
  356. static void zs_raw_stop_tx(struct zs_port *zport)
  357. {
  358. write_zsreg(zport, R0, RES_Tx_P);
  359. zport->tx_stopped = 1;
  360. }
  361. static void zs_stop_tx(struct uart_port *uport)
  362. {
  363. struct zs_port *zport = to_zport(uport);
  364. struct zs_scc *scc = zport->scc;
  365. spin_lock(&scc->zlock);
  366. zs_raw_stop_tx(zport);
  367. spin_unlock(&scc->zlock);
  368. }
  369. static void zs_raw_transmit_chars(struct zs_port *);
  370. static void zs_start_tx(struct uart_port *uport)
  371. {
  372. struct zs_port *zport = to_zport(uport);
  373. struct zs_scc *scc = zport->scc;
  374. spin_lock(&scc->zlock);
  375. if (zport->tx_stopped) {
  376. zs_transmit_drain(zport, 0);
  377. zport->tx_stopped = 0;
  378. zs_raw_transmit_chars(zport);
  379. }
  380. spin_unlock(&scc->zlock);
  381. }
  382. static void zs_stop_rx(struct uart_port *uport)
  383. {
  384. struct zs_port *zport = to_zport(uport);
  385. struct zs_scc *scc = zport->scc;
  386. struct zs_port *zport_a = &scc->zport[ZS_CHAN_A];
  387. spin_lock(&scc->zlock);
  388. zport->regs[15] &= ~BRKIE;
  389. zport->regs[1] &= ~(RxINT_MASK | TxINT_ENAB);
  390. zport->regs[1] |= RxINT_DISAB;
  391. if (zport != zport_a) {
  392. /* A-side DCD tracks RI and SYNC tracks DSR. */
  393. zport_a->regs[15] &= ~(DCDIE | SYNCIE);
  394. write_zsreg(zport_a, R15, zport_a->regs[15]);
  395. if (!(zport_a->regs[15] & BRKIE)) {
  396. zport_a->regs[1] &= ~EXT_INT_ENAB;
  397. write_zsreg(zport_a, R1, zport_a->regs[1]);
  398. }
  399. /* This-side DCD tracks DCD and CTS tracks CTS. */
  400. zport->regs[15] &= ~(DCDIE | CTSIE);
  401. zport->regs[1] &= ~EXT_INT_ENAB;
  402. } else {
  403. /* DCD tracks RI and SYNC tracks DSR for the B side. */
  404. if (!(zport->regs[15] & (DCDIE | SYNCIE)))
  405. zport->regs[1] &= ~EXT_INT_ENAB;
  406. }
  407. write_zsreg(zport, R15, zport->regs[15]);
  408. write_zsreg(zport, R1, zport->regs[1]);
  409. spin_unlock(&scc->zlock);
  410. }
  411. static void zs_enable_ms(struct uart_port *uport)
  412. {
  413. struct zs_port *zport = to_zport(uport);
  414. struct zs_scc *scc = zport->scc;
  415. struct zs_port *zport_a = &scc->zport[ZS_CHAN_A];
  416. if (zport == zport_a)
  417. return;
  418. spin_lock(&scc->zlock);
  419. /* Clear Ext interrupts if not being handled already. */
  420. if (!(zport_a->regs[1] & EXT_INT_ENAB))
  421. write_zsreg(zport_a, R0, RES_EXT_INT);
  422. /* A-side DCD tracks RI and SYNC tracks DSR. */
  423. zport_a->regs[1] |= EXT_INT_ENAB;
  424. zport_a->regs[15] |= DCDIE | SYNCIE;
  425. /* This-side DCD tracks DCD and CTS tracks CTS. */
  426. zport->regs[15] |= DCDIE | CTSIE;
  427. zs_raw_xor_mctrl(zport);
  428. write_zsreg(zport_a, R1, zport_a->regs[1]);
  429. write_zsreg(zport_a, R15, zport_a->regs[15]);
  430. write_zsreg(zport, R15, zport->regs[15]);
  431. spin_unlock(&scc->zlock);
  432. }
  433. static void zs_break_ctl(struct uart_port *uport, int break_state)
  434. {
  435. struct zs_port *zport = to_zport(uport);
  436. struct zs_scc *scc = zport->scc;
  437. unsigned long flags;
  438. spin_lock_irqsave(&scc->zlock, flags);
  439. if (break_state == -1)
  440. zport->regs[5] |= SND_BRK;
  441. else
  442. zport->regs[5] &= ~SND_BRK;
  443. write_zsreg(zport, R5, zport->regs[5]);
  444. spin_unlock_irqrestore(&scc->zlock, flags);
  445. }
  446. /*
  447. * Interrupt handling routines.
  448. */
  449. #define Rx_BRK 0x0100 /* BREAK event software flag. */
  450. #define Rx_SYS 0x0200 /* SysRq event software flag. */
  451. static void zs_receive_chars(struct zs_port *zport)
  452. {
  453. struct uart_port *uport = &zport->port;
  454. struct zs_scc *scc = zport->scc;
  455. struct uart_icount *icount;
  456. unsigned int avail, status, ch, flag;
  457. int count;
  458. for (count = 16; count; count--) {
  459. spin_lock(&scc->zlock);
  460. avail = read_zsreg(zport, R0) & Rx_CH_AV;
  461. spin_unlock(&scc->zlock);
  462. if (!avail)
  463. break;
  464. spin_lock(&scc->zlock);
  465. status = read_zsreg(zport, R1) & (Rx_OVR | FRM_ERR | PAR_ERR);
  466. ch = read_zsdata(zport);
  467. spin_unlock(&scc->zlock);
  468. flag = TTY_NORMAL;
  469. icount = &uport->icount;
  470. icount->rx++;
  471. /* Handle the null char got when BREAK is removed. */
  472. if (!ch)
  473. status |= zport->tty_break;
  474. if (unlikely(status &
  475. (Rx_OVR | FRM_ERR | PAR_ERR | Rx_SYS | Rx_BRK))) {
  476. zport->tty_break = 0;
  477. /* Reset the error indication. */
  478. if (status & (Rx_OVR | FRM_ERR | PAR_ERR)) {
  479. spin_lock(&scc->zlock);
  480. write_zsreg(zport, R0, ERR_RES);
  481. spin_unlock(&scc->zlock);
  482. }
  483. if (status & (Rx_SYS | Rx_BRK)) {
  484. icount->brk++;
  485. /* SysRq discards the null char. */
  486. if (status & Rx_SYS)
  487. continue;
  488. } else if (status & FRM_ERR)
  489. icount->frame++;
  490. else if (status & PAR_ERR)
  491. icount->parity++;
  492. if (status & Rx_OVR)
  493. icount->overrun++;
  494. status &= uport->read_status_mask;
  495. if (status & Rx_BRK)
  496. flag = TTY_BREAK;
  497. else if (status & FRM_ERR)
  498. flag = TTY_FRAME;
  499. else if (status & PAR_ERR)
  500. flag = TTY_PARITY;
  501. }
  502. if (uart_handle_sysrq_char(uport, ch))
  503. continue;
  504. uart_insert_char(uport, status, Rx_OVR, ch, flag);
  505. }
  506. tty_flip_buffer_push(uport->state->port.tty);
  507. }
  508. static void zs_raw_transmit_chars(struct zs_port *zport)
  509. {
  510. struct circ_buf *xmit = &zport->port.state->xmit;
  511. /* XON/XOFF chars. */
  512. if (zport->port.x_char) {
  513. write_zsdata(zport, zport->port.x_char);
  514. zport->port.icount.tx++;
  515. zport->port.x_char = 0;
  516. return;
  517. }
  518. /* If nothing to do or stopped or hardware stopped. */
  519. if (uart_circ_empty(xmit) || uart_tx_stopped(&zport->port)) {
  520. zs_raw_stop_tx(zport);
  521. return;
  522. }
  523. /* Send char. */
  524. write_zsdata(zport, xmit->buf[xmit->tail]);
  525. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  526. zport->port.icount.tx++;
  527. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  528. uart_write_wakeup(&zport->port);
  529. /* Are we are done? */
  530. if (uart_circ_empty(xmit))
  531. zs_raw_stop_tx(zport);
  532. }
  533. static void zs_transmit_chars(struct zs_port *zport)
  534. {
  535. struct zs_scc *scc = zport->scc;
  536. spin_lock(&scc->zlock);
  537. zs_raw_transmit_chars(zport);
  538. spin_unlock(&scc->zlock);
  539. }
  540. static void zs_status_handle(struct zs_port *zport, struct zs_port *zport_a)
  541. {
  542. struct uart_port *uport = &zport->port;
  543. struct zs_scc *scc = zport->scc;
  544. unsigned int delta;
  545. u8 status, brk;
  546. spin_lock(&scc->zlock);
  547. /* Get status from Read Register 0. */
  548. status = read_zsreg(zport, R0);
  549. if (zport->regs[15] & BRKIE) {
  550. brk = status & BRK_ABRT;
  551. if (brk && !zport->brk) {
  552. spin_unlock(&scc->zlock);
  553. if (uart_handle_break(uport))
  554. zport->tty_break = Rx_SYS;
  555. else
  556. zport->tty_break = Rx_BRK;
  557. spin_lock(&scc->zlock);
  558. }
  559. zport->brk = brk;
  560. }
  561. if (zport != zport_a) {
  562. delta = zs_raw_xor_mctrl(zport);
  563. spin_unlock(&scc->zlock);
  564. if (delta & TIOCM_CTS)
  565. uart_handle_cts_change(uport,
  566. zport->mctrl & TIOCM_CTS);
  567. if (delta & TIOCM_CAR)
  568. uart_handle_dcd_change(uport,
  569. zport->mctrl & TIOCM_CAR);
  570. if (delta & TIOCM_RNG)
  571. uport->icount.dsr++;
  572. if (delta & TIOCM_DSR)
  573. uport->icount.rng++;
  574. if (delta)
  575. wake_up_interruptible(&uport->state->port.delta_msr_wait);
  576. spin_lock(&scc->zlock);
  577. }
  578. /* Clear the status condition... */
  579. write_zsreg(zport, R0, RES_EXT_INT);
  580. spin_unlock(&scc->zlock);
  581. }
  582. /*
  583. * This is the Z85C30 driver's generic interrupt routine.
  584. */
  585. static irqreturn_t zs_interrupt(int irq, void *dev_id)
  586. {
  587. struct zs_scc *scc = dev_id;
  588. struct zs_port *zport_a = &scc->zport[ZS_CHAN_A];
  589. struct zs_port *zport_b = &scc->zport[ZS_CHAN_B];
  590. irqreturn_t status = IRQ_NONE;
  591. u8 zs_intreg;
  592. int count;
  593. /*
  594. * NOTE: The read register 3, which holds the irq status,
  595. * does so for both channels on each chip. Although
  596. * the status value itself must be read from the A
  597. * channel and is only valid when read from channel A.
  598. * Yes... broken hardware...
  599. */
  600. for (count = 16; count; count--) {
  601. spin_lock(&scc->zlock);
  602. zs_intreg = read_zsreg(zport_a, R3);
  603. spin_unlock(&scc->zlock);
  604. if (!zs_intreg)
  605. break;
  606. /*
  607. * We do not like losing characters, so we prioritise
  608. * interrupt sources a little bit differently than
  609. * the SCC would, was it allowed to.
  610. */
  611. if (zs_intreg & CHBRxIP)
  612. zs_receive_chars(zport_b);
  613. if (zs_intreg & CHARxIP)
  614. zs_receive_chars(zport_a);
  615. if (zs_intreg & CHBEXT)
  616. zs_status_handle(zport_b, zport_a);
  617. if (zs_intreg & CHAEXT)
  618. zs_status_handle(zport_a, zport_a);
  619. if (zs_intreg & CHBTxIP)
  620. zs_transmit_chars(zport_b);
  621. if (zs_intreg & CHATxIP)
  622. zs_transmit_chars(zport_a);
  623. status = IRQ_HANDLED;
  624. }
  625. return status;
  626. }
  627. /*
  628. * Finally, routines used to initialize the serial port.
  629. */
  630. static int zs_startup(struct uart_port *uport)
  631. {
  632. struct zs_port *zport = to_zport(uport);
  633. struct zs_scc *scc = zport->scc;
  634. unsigned long flags;
  635. int irq_guard;
  636. int ret;
  637. irq_guard = atomic_add_return(1, &scc->irq_guard);
  638. if (irq_guard == 1) {
  639. ret = request_irq(zport->port.irq, zs_interrupt,
  640. IRQF_SHARED, "scc", scc);
  641. if (ret) {
  642. atomic_add(-1, &scc->irq_guard);
  643. printk(KERN_ERR "zs: can't get irq %d\n",
  644. zport->port.irq);
  645. return ret;
  646. }
  647. }
  648. spin_lock_irqsave(&scc->zlock, flags);
  649. /* Clear the receive FIFO. */
  650. zs_receive_drain(zport);
  651. /* Clear the interrupt registers. */
  652. write_zsreg(zport, R0, ERR_RES);
  653. write_zsreg(zport, R0, RES_Tx_P);
  654. /* But Ext only if not being handled already. */
  655. if (!(zport->regs[1] & EXT_INT_ENAB))
  656. write_zsreg(zport, R0, RES_EXT_INT);
  657. /* Finally, enable sequencing and interrupts. */
  658. zport->regs[1] &= ~RxINT_MASK;
  659. zport->regs[1] |= RxINT_ALL | TxINT_ENAB | EXT_INT_ENAB;
  660. zport->regs[3] |= RxENABLE;
  661. zport->regs[15] |= BRKIE;
  662. write_zsreg(zport, R1, zport->regs[1]);
  663. write_zsreg(zport, R3, zport->regs[3]);
  664. write_zsreg(zport, R5, zport->regs[5]);
  665. write_zsreg(zport, R15, zport->regs[15]);
  666. /* Record the current state of RR0. */
  667. zport->mctrl = zs_raw_get_mctrl(zport);
  668. zport->brk = read_zsreg(zport, R0) & BRK_ABRT;
  669. zport->tx_stopped = 1;
  670. spin_unlock_irqrestore(&scc->zlock, flags);
  671. return 0;
  672. }
  673. static void zs_shutdown(struct uart_port *uport)
  674. {
  675. struct zs_port *zport = to_zport(uport);
  676. struct zs_scc *scc = zport->scc;
  677. unsigned long flags;
  678. int irq_guard;
  679. spin_lock_irqsave(&scc->zlock, flags);
  680. zport->regs[3] &= ~RxENABLE;
  681. write_zsreg(zport, R5, zport->regs[5]);
  682. write_zsreg(zport, R3, zport->regs[3]);
  683. spin_unlock_irqrestore(&scc->zlock, flags);
  684. irq_guard = atomic_add_return(-1, &scc->irq_guard);
  685. if (!irq_guard)
  686. free_irq(zport->port.irq, scc);
  687. }
  688. static void zs_reset(struct zs_port *zport)
  689. {
  690. struct zs_scc *scc = zport->scc;
  691. int irq;
  692. unsigned long flags;
  693. spin_lock_irqsave(&scc->zlock, flags);
  694. irq = !irqs_disabled_flags(flags);
  695. if (!scc->initialised) {
  696. /* Reset the pointer first, just in case... */
  697. read_zsreg(zport, R0);
  698. /* And let the current transmission finish. */
  699. zs_line_drain(zport, irq);
  700. write_zsreg(zport, R9, FHWRES);
  701. udelay(10);
  702. write_zsreg(zport, R9, 0);
  703. scc->initialised = 1;
  704. }
  705. load_zsregs(zport, zport->regs, irq);
  706. spin_unlock_irqrestore(&scc->zlock, flags);
  707. }
  708. static void zs_set_termios(struct uart_port *uport, struct ktermios *termios,
  709. struct ktermios *old_termios)
  710. {
  711. struct zs_port *zport = to_zport(uport);
  712. struct zs_scc *scc = zport->scc;
  713. struct zs_port *zport_a = &scc->zport[ZS_CHAN_A];
  714. int irq;
  715. unsigned int baud, brg;
  716. unsigned long flags;
  717. spin_lock_irqsave(&scc->zlock, flags);
  718. irq = !irqs_disabled_flags(flags);
  719. /* Byte size. */
  720. zport->regs[3] &= ~RxNBITS_MASK;
  721. zport->regs[5] &= ~TxNBITS_MASK;
  722. switch (termios->c_cflag & CSIZE) {
  723. case CS5:
  724. zport->regs[3] |= Rx5;
  725. zport->regs[5] |= Tx5;
  726. break;
  727. case CS6:
  728. zport->regs[3] |= Rx6;
  729. zport->regs[5] |= Tx6;
  730. break;
  731. case CS7:
  732. zport->regs[3] |= Rx7;
  733. zport->regs[5] |= Tx7;
  734. break;
  735. case CS8:
  736. default:
  737. zport->regs[3] |= Rx8;
  738. zport->regs[5] |= Tx8;
  739. break;
  740. }
  741. /* Parity and stop bits. */
  742. zport->regs[4] &= ~(XCLK_MASK | SB_MASK | PAR_ENA | PAR_EVEN);
  743. if (termios->c_cflag & CSTOPB)
  744. zport->regs[4] |= SB2;
  745. else
  746. zport->regs[4] |= SB1;
  747. if (termios->c_cflag & PARENB)
  748. zport->regs[4] |= PAR_ENA;
  749. if (!(termios->c_cflag & PARODD))
  750. zport->regs[4] |= PAR_EVEN;
  751. switch (zport->clk_mode) {
  752. case 64:
  753. zport->regs[4] |= X64CLK;
  754. break;
  755. case 32:
  756. zport->regs[4] |= X32CLK;
  757. break;
  758. case 16:
  759. zport->regs[4] |= X16CLK;
  760. break;
  761. case 1:
  762. zport->regs[4] |= X1CLK;
  763. break;
  764. default:
  765. BUG();
  766. }
  767. baud = uart_get_baud_rate(uport, termios, old_termios, 0,
  768. uport->uartclk / zport->clk_mode / 4);
  769. brg = ZS_BPS_TO_BRG(baud, uport->uartclk / zport->clk_mode);
  770. zport->regs[12] = brg & 0xff;
  771. zport->regs[13] = (brg >> 8) & 0xff;
  772. uart_update_timeout(uport, termios->c_cflag, baud);
  773. uport->read_status_mask = Rx_OVR;
  774. if (termios->c_iflag & INPCK)
  775. uport->read_status_mask |= FRM_ERR | PAR_ERR;
  776. if (termios->c_iflag & (BRKINT | PARMRK))
  777. uport->read_status_mask |= Rx_BRK;
  778. uport->ignore_status_mask = 0;
  779. if (termios->c_iflag & IGNPAR)
  780. uport->ignore_status_mask |= FRM_ERR | PAR_ERR;
  781. if (termios->c_iflag & IGNBRK) {
  782. uport->ignore_status_mask |= Rx_BRK;
  783. if (termios->c_iflag & IGNPAR)
  784. uport->ignore_status_mask |= Rx_OVR;
  785. }
  786. if (termios->c_cflag & CREAD)
  787. zport->regs[3] |= RxENABLE;
  788. else
  789. zport->regs[3] &= ~RxENABLE;
  790. if (zport != zport_a) {
  791. if (!(termios->c_cflag & CLOCAL)) {
  792. zport->regs[15] |= DCDIE;
  793. } else
  794. zport->regs[15] &= ~DCDIE;
  795. if (termios->c_cflag & CRTSCTS) {
  796. zport->regs[15] |= CTSIE;
  797. } else
  798. zport->regs[15] &= ~CTSIE;
  799. zs_raw_xor_mctrl(zport);
  800. }
  801. /* Load up the new values. */
  802. load_zsregs(zport, zport->regs, irq);
  803. spin_unlock_irqrestore(&scc->zlock, flags);
  804. }
  805. /*
  806. * Hack alert!
  807. * Required solely so that the initial PROM-based console
  808. * works undisturbed in parallel with this one.
  809. */
  810. static void zs_pm(struct uart_port *uport, unsigned int state,
  811. unsigned int oldstate)
  812. {
  813. struct zs_port *zport = to_zport(uport);
  814. if (state < 3)
  815. zport->regs[5] |= TxENAB;
  816. else
  817. zport->regs[5] &= ~TxENAB;
  818. write_zsreg(zport, R5, zport->regs[5]);
  819. }
  820. static const char *zs_type(struct uart_port *uport)
  821. {
  822. return "Z85C30 SCC";
  823. }
  824. static void zs_release_port(struct uart_port *uport)
  825. {
  826. iounmap(uport->membase);
  827. uport->membase = 0;
  828. release_mem_region(uport->mapbase, ZS_CHAN_IO_SIZE);
  829. }
  830. static int zs_map_port(struct uart_port *uport)
  831. {
  832. if (!uport->membase)
  833. uport->membase = ioremap_nocache(uport->mapbase,
  834. ZS_CHAN_IO_SIZE);
  835. if (!uport->membase) {
  836. printk(KERN_ERR "zs: Cannot map MMIO\n");
  837. return -ENOMEM;
  838. }
  839. return 0;
  840. }
  841. static int zs_request_port(struct uart_port *uport)
  842. {
  843. int ret;
  844. if (!request_mem_region(uport->mapbase, ZS_CHAN_IO_SIZE, "scc")) {
  845. printk(KERN_ERR "zs: Unable to reserve MMIO resource\n");
  846. return -EBUSY;
  847. }
  848. ret = zs_map_port(uport);
  849. if (ret) {
  850. release_mem_region(uport->mapbase, ZS_CHAN_IO_SIZE);
  851. return ret;
  852. }
  853. return 0;
  854. }
  855. static void zs_config_port(struct uart_port *uport, int flags)
  856. {
  857. struct zs_port *zport = to_zport(uport);
  858. if (flags & UART_CONFIG_TYPE) {
  859. if (zs_request_port(uport))
  860. return;
  861. uport->type = PORT_ZS;
  862. zs_reset(zport);
  863. }
  864. }
  865. static int zs_verify_port(struct uart_port *uport, struct serial_struct *ser)
  866. {
  867. struct zs_port *zport = to_zport(uport);
  868. int ret = 0;
  869. if (ser->type != PORT_UNKNOWN && ser->type != PORT_ZS)
  870. ret = -EINVAL;
  871. if (ser->irq != uport->irq)
  872. ret = -EINVAL;
  873. if (ser->baud_base != uport->uartclk / zport->clk_mode / 4)
  874. ret = -EINVAL;
  875. return ret;
  876. }
  877. static struct uart_ops zs_ops = {
  878. .tx_empty = zs_tx_empty,
  879. .set_mctrl = zs_set_mctrl,
  880. .get_mctrl = zs_get_mctrl,
  881. .stop_tx = zs_stop_tx,
  882. .start_tx = zs_start_tx,
  883. .stop_rx = zs_stop_rx,
  884. .enable_ms = zs_enable_ms,
  885. .break_ctl = zs_break_ctl,
  886. .startup = zs_startup,
  887. .shutdown = zs_shutdown,
  888. .set_termios = zs_set_termios,
  889. .pm = zs_pm,
  890. .type = zs_type,
  891. .release_port = zs_release_port,
  892. .request_port = zs_request_port,
  893. .config_port = zs_config_port,
  894. .verify_port = zs_verify_port,
  895. };
  896. /*
  897. * Initialize Z85C30 port structures.
  898. */
  899. static int __init zs_probe_sccs(void)
  900. {
  901. static int probed;
  902. struct zs_parms zs_parms;
  903. int chip, side, irq;
  904. int n_chips = 0;
  905. int i;
  906. if (probed)
  907. return 0;
  908. irq = dec_interrupt[DEC_IRQ_SCC0];
  909. if (irq >= 0) {
  910. zs_parms.scc[n_chips] = IOASIC_SCC0;
  911. zs_parms.irq[n_chips] = dec_interrupt[DEC_IRQ_SCC0];
  912. n_chips++;
  913. }
  914. irq = dec_interrupt[DEC_IRQ_SCC1];
  915. if (irq >= 0) {
  916. zs_parms.scc[n_chips] = IOASIC_SCC1;
  917. zs_parms.irq[n_chips] = dec_interrupt[DEC_IRQ_SCC1];
  918. n_chips++;
  919. }
  920. if (!n_chips)
  921. return -ENXIO;
  922. probed = 1;
  923. for (chip = 0; chip < n_chips; chip++) {
  924. spin_lock_init(&zs_sccs[chip].zlock);
  925. for (side = 0; side < ZS_NUM_CHAN; side++) {
  926. struct zs_port *zport = &zs_sccs[chip].zport[side];
  927. struct uart_port *uport = &zport->port;
  928. zport->scc = &zs_sccs[chip];
  929. zport->clk_mode = 16;
  930. uport->irq = zs_parms.irq[chip];
  931. uport->uartclk = ZS_CLOCK;
  932. uport->fifosize = 1;
  933. uport->iotype = UPIO_MEM;
  934. uport->flags = UPF_BOOT_AUTOCONF;
  935. uport->ops = &zs_ops;
  936. uport->line = chip * ZS_NUM_CHAN + side;
  937. uport->mapbase = dec_kn_slot_base +
  938. zs_parms.scc[chip] +
  939. (side ^ ZS_CHAN_B) * ZS_CHAN_IO_SIZE;
  940. for (i = 0; i < ZS_NUM_REGS; i++)
  941. zport->regs[i] = zs_init_regs[i];
  942. }
  943. }
  944. return 0;
  945. }
  946. #ifdef CONFIG_SERIAL_ZS_CONSOLE
  947. static void zs_console_putchar(struct uart_port *uport, int ch)
  948. {
  949. struct zs_port *zport = to_zport(uport);
  950. struct zs_scc *scc = zport->scc;
  951. int irq;
  952. unsigned long flags;
  953. spin_lock_irqsave(&scc->zlock, flags);
  954. irq = !irqs_disabled_flags(flags);
  955. if (zs_transmit_drain(zport, irq))
  956. write_zsdata(zport, ch);
  957. spin_unlock_irqrestore(&scc->zlock, flags);
  958. }
  959. /*
  960. * Print a string to the serial port trying not to disturb
  961. * any possible real use of the port...
  962. */
  963. static void zs_console_write(struct console *co, const char *s,
  964. unsigned int count)
  965. {
  966. int chip = co->index / ZS_NUM_CHAN, side = co->index % ZS_NUM_CHAN;
  967. struct zs_port *zport = &zs_sccs[chip].zport[side];
  968. struct zs_scc *scc = zport->scc;
  969. unsigned long flags;
  970. u8 txint, txenb;
  971. int irq;
  972. /* Disable transmit interrupts and enable the transmitter. */
  973. spin_lock_irqsave(&scc->zlock, flags);
  974. txint = zport->regs[1];
  975. txenb = zport->regs[5];
  976. if (txint & TxINT_ENAB) {
  977. zport->regs[1] = txint & ~TxINT_ENAB;
  978. write_zsreg(zport, R1, zport->regs[1]);
  979. }
  980. if (!(txenb & TxENAB)) {
  981. zport->regs[5] = txenb | TxENAB;
  982. write_zsreg(zport, R5, zport->regs[5]);
  983. }
  984. spin_unlock_irqrestore(&scc->zlock, flags);
  985. uart_console_write(&zport->port, s, count, zs_console_putchar);
  986. /* Restore transmit interrupts and the transmitter enable. */
  987. spin_lock_irqsave(&scc->zlock, flags);
  988. irq = !irqs_disabled_flags(flags);
  989. zs_line_drain(zport, irq);
  990. if (!(txenb & TxENAB)) {
  991. zport->regs[5] &= ~TxENAB;
  992. write_zsreg(zport, R5, zport->regs[5]);
  993. }
  994. if (txint & TxINT_ENAB) {
  995. zport->regs[1] |= TxINT_ENAB;
  996. write_zsreg(zport, R1, zport->regs[1]);
  997. }
  998. spin_unlock_irqrestore(&scc->zlock, flags);
  999. }
  1000. /*
  1001. * Setup serial console baud/bits/parity. We do two things here:
  1002. * - construct a cflag setting for the first uart_open()
  1003. * - initialise the serial port
  1004. * Return non-zero if we didn't find a serial port.
  1005. */
  1006. static int __init zs_console_setup(struct console *co, char *options)
  1007. {
  1008. int chip = co->index / ZS_NUM_CHAN, side = co->index % ZS_NUM_CHAN;
  1009. struct zs_port *zport = &zs_sccs[chip].zport[side];
  1010. struct uart_port *uport = &zport->port;
  1011. int baud = 9600;
  1012. int bits = 8;
  1013. int parity = 'n';
  1014. int flow = 'n';
  1015. int ret;
  1016. ret = zs_map_port(uport);
  1017. if (ret)
  1018. return ret;
  1019. zs_reset(zport);
  1020. zs_pm(uport, 0, -1);
  1021. if (options)
  1022. uart_parse_options(options, &baud, &parity, &bits, &flow);
  1023. return uart_set_options(uport, co, baud, parity, bits, flow);
  1024. }
  1025. static struct uart_driver zs_reg;
  1026. static struct console zs_console = {
  1027. .name = "ttyS",
  1028. .write = zs_console_write,
  1029. .device = uart_console_device,
  1030. .setup = zs_console_setup,
  1031. .flags = CON_PRINTBUFFER,
  1032. .index = -1,
  1033. .data = &zs_reg,
  1034. };
  1035. /*
  1036. * Register console.
  1037. */
  1038. static int __init zs_serial_console_init(void)
  1039. {
  1040. int ret;
  1041. ret = zs_probe_sccs();
  1042. if (ret)
  1043. return ret;
  1044. register_console(&zs_console);
  1045. return 0;
  1046. }
  1047. console_initcall(zs_serial_console_init);
  1048. #define SERIAL_ZS_CONSOLE &zs_console
  1049. #else
  1050. #define SERIAL_ZS_CONSOLE NULL
  1051. #endif /* CONFIG_SERIAL_ZS_CONSOLE */
  1052. static struct uart_driver zs_reg = {
  1053. .owner = THIS_MODULE,
  1054. .driver_name = "serial",
  1055. .dev_name = "ttyS",
  1056. .major = TTY_MAJOR,
  1057. .minor = 64,
  1058. .nr = ZS_NUM_SCCS * ZS_NUM_CHAN,
  1059. .cons = SERIAL_ZS_CONSOLE,
  1060. };
  1061. /* zs_init inits the driver. */
  1062. static int __init zs_init(void)
  1063. {
  1064. int i, ret;
  1065. pr_info("%s%s\n", zs_name, zs_version);
  1066. /* Find out how many Z85C30 SCCs we have. */
  1067. ret = zs_probe_sccs();
  1068. if (ret)
  1069. return ret;
  1070. ret = uart_register_driver(&zs_reg);
  1071. if (ret)
  1072. return ret;
  1073. for (i = 0; i < ZS_NUM_SCCS * ZS_NUM_CHAN; i++) {
  1074. struct zs_scc *scc = &zs_sccs[i / ZS_NUM_CHAN];
  1075. struct zs_port *zport = &scc->zport[i % ZS_NUM_CHAN];
  1076. struct uart_port *uport = &zport->port;
  1077. if (zport->scc)
  1078. uart_add_one_port(&zs_reg, uport);
  1079. }
  1080. return 0;
  1081. }
  1082. static void __exit zs_exit(void)
  1083. {
  1084. int i;
  1085. for (i = ZS_NUM_SCCS * ZS_NUM_CHAN - 1; i >= 0; i--) {
  1086. struct zs_scc *scc = &zs_sccs[i / ZS_NUM_CHAN];
  1087. struct zs_port *zport = &scc->zport[i % ZS_NUM_CHAN];
  1088. struct uart_port *uport = &zport->port;
  1089. if (zport->scc)
  1090. uart_remove_one_port(&zs_reg, uport);
  1091. }
  1092. uart_unregister_driver(&zs_reg);
  1093. }
  1094. module_init(zs_init);
  1095. module_exit(zs_exit);