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