zs.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * zs.c: Serial port driver for IOASIC DECstations.
  4. *
  5. * Derived from drivers/sbus/char/sunserial.c by Paul Mackerras.
  6. * Derived from drivers/macintosh/macserial.c by Harald Koerfgen.
  7. *
  8. * DECstation changes
  9. * Copyright (C) 1998-2000 Harald Koerfgen
  10. * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007 Maciej W. Rozycki
  11. *
  12. * For the rest of the code the original Copyright applies:
  13. * Copyright (C) 1996 Paul Mackerras (Paul.Mackerras@cs.anu.edu.au)
  14. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  15. *
  16. *
  17. * Note: for IOASIC systems the wiring is as follows:
  18. *
  19. * mouse/keyboard:
  20. * DIN-7 MJ-4 signal SCC
  21. * 2 1 TxD <- A.TxD
  22. * 3 4 RxD -> A.RxD
  23. *
  24. * EIA-232/EIA-423:
  25. * DB-25 MMJ-6 signal SCC
  26. * 2 2 TxD <- B.TxD
  27. * 3 5 RxD -> B.RxD
  28. * 4 RTS <- ~A.RTS
  29. * 5 CTS -> ~B.CTS
  30. * 6 6 DSR -> ~A.SYNC
  31. * 8 CD -> ~B.DCD
  32. * 12 DSRS(DCE) -> ~A.CTS (*)
  33. * 15 TxC -> B.TxC
  34. * 17 RxC -> B.RxC
  35. * 20 1 DTR <- ~A.DTR
  36. * 22 RI -> ~A.DCD
  37. * 23 DSRS(DTE) <- ~B.RTS
  38. *
  39. * (*) EIA-232 defines the signal at this pin to be SCD, while DSRS(DCE)
  40. * is shared with DSRS(DTE) at pin 23.
  41. *
  42. * As you can immediately notice the wiring of the RTS, DTR and DSR signals
  43. * is a bit odd. This makes the handling of port B unnecessarily
  44. * complicated and prevents the use of some automatic modes of operation.
  45. */
  46. #include <linux/bug.h>
  47. #include <linux/console.h>
  48. #include <linux/delay.h>
  49. #include <linux/errno.h>
  50. #include <linux/init.h>
  51. #include <linux/interrupt.h>
  52. #include <linux/io.h>
  53. #include <linux/ioport.h>
  54. #include <linux/irqflags.h>
  55. #include <linux/kernel.h>
  56. #include <linux/module.h>
  57. #include <linux/major.h>
  58. #include <linux/serial.h>
  59. #include <linux/serial_core.h>
  60. #include <linux/spinlock.h>
  61. #include <linux/sysrq.h>
  62. #include <linux/tty.h>
  63. #include <linux/tty_flip.h>
  64. #include <linux/types.h>
  65. #include <linux/atomic.h>
  66. #include <asm/dec/interrupts.h>
  67. #include <asm/dec/ioasic_addrs.h>
  68. #include <asm/dec/system.h>
  69. #include "zs.h"
  70. MODULE_AUTHOR("Maciej W. Rozycki <macro@linux-mips.org>");
  71. MODULE_DESCRIPTION("DECstation Z85C30 serial driver");
  72. MODULE_LICENSE("GPL");
  73. static char zs_name[] __initdata = "DECstation Z85C30 serial driver version ";
  74. static char zs_version[] __initdata = "0.10";
  75. /*
  76. * It would be nice to dynamically allocate everything that
  77. * depends on ZS_NUM_SCCS, so we could support any number of
  78. * Z85C30s, but for now...
  79. */
  80. #define ZS_NUM_SCCS 2 /* Max # of ZS chips supported. */
  81. #define ZS_NUM_CHAN 2 /* 2 channels per chip. */
  82. #define ZS_CHAN_A 0 /* Index of the channel A. */
  83. #define ZS_CHAN_B 1 /* Index of the channel B. */
  84. #define ZS_CHAN_IO_SIZE 8 /* IOMEM space size. */
  85. #define ZS_CHAN_IO_STRIDE 4 /* Register alignment. */
  86. #define ZS_CHAN_IO_OFFSET 1 /* The SCC resides on the high byte
  87. of the 16-bit IOBUS. */
  88. #define ZS_CLOCK 7372800 /* Z85C30 PCLK input clock rate. */
  89. #define to_zport(uport) container_of(uport, struct zs_port, port)
  90. struct zs_parms {
  91. resource_size_t scc[ZS_NUM_SCCS];
  92. int irq[ZS_NUM_SCCS];
  93. };
  94. static struct zs_scc zs_sccs[ZS_NUM_SCCS];
  95. static u8 zs_init_regs[ZS_NUM_REGS] __initdata = {
  96. 0, /* write 0 */
  97. PAR_SPEC, /* write 1 */
  98. 0, /* write 2 */
  99. 0, /* write 3 */
  100. X16CLK | SB1, /* write 4 */
  101. 0, /* write 5 */
  102. 0, 0, 0, /* write 6, 7, 8 */
  103. MIE | DLC | NV, /* write 9 */
  104. NRZ, /* write 10 */
  105. TCBR | RCBR, /* write 11 */
  106. 0, 0, /* BRG time constant, write 12 + 13 */
  107. BRSRC | BRENABL, /* write 14 */
  108. 0, /* write 15 */
  109. };
  110. /*
  111. * Debugging.
  112. */
  113. #undef ZS_DEBUG_REGS
  114. /*
  115. * Reading and writing Z85C30 registers.
  116. */
  117. static void recovery_delay(void)
  118. {
  119. udelay(2);
  120. }
  121. static u8 read_zsreg(struct zs_port *zport, int reg)
  122. {
  123. void __iomem *control = zport->port.membase + ZS_CHAN_IO_OFFSET;
  124. u8 retval;
  125. if (reg != 0) {
  126. writeb(reg & 0xf, control);
  127. fast_iob();
  128. recovery_delay();
  129. }
  130. retval = readb(control);
  131. recovery_delay();
  132. return retval;
  133. }
  134. static void write_zsreg(struct zs_port *zport, int reg, u8 value)
  135. {
  136. void __iomem *control = zport->port.membase + ZS_CHAN_IO_OFFSET;
  137. if (reg != 0) {
  138. writeb(reg & 0xf, control);
  139. fast_iob(); recovery_delay();
  140. }
  141. writeb(value, control);
  142. fast_iob();
  143. recovery_delay();
  144. return;
  145. }
  146. static u8 read_zsdata(struct zs_port *zport)
  147. {
  148. void __iomem *data = zport->port.membase +
  149. ZS_CHAN_IO_STRIDE + ZS_CHAN_IO_OFFSET;
  150. u8 retval;
  151. retval = readb(data);
  152. recovery_delay();
  153. return retval;
  154. }
  155. static void write_zsdata(struct zs_port *zport, u8 value)
  156. {
  157. void __iomem *data = zport->port.membase +
  158. ZS_CHAN_IO_STRIDE + ZS_CHAN_IO_OFFSET;
  159. writeb(value, data);
  160. fast_iob();
  161. recovery_delay();
  162. return;
  163. }
  164. #ifdef ZS_DEBUG_REGS
  165. void zs_dump(void)
  166. {
  167. struct zs_port *zport;
  168. int i, j;
  169. for (i = 0; i < ZS_NUM_SCCS * ZS_NUM_CHAN; i++) {
  170. zport = &zs_sccs[i / ZS_NUM_CHAN].zport[i % ZS_NUM_CHAN];
  171. if (!zport->scc)
  172. continue;
  173. for (j = 0; j < 16; j++)
  174. printk("W%-2d = 0x%02x\t", j, zport->regs[j]);
  175. printk("\n");
  176. for (j = 0; j < 16; j++)
  177. printk("R%-2d = 0x%02x\t", j, read_zsreg(zport, j));
  178. printk("\n\n");
  179. }
  180. }
  181. #endif
  182. static void zs_spin_lock_cond_irq(spinlock_t *lock, int irq)
  183. {
  184. if (irq)
  185. spin_lock_irq(lock);
  186. else
  187. spin_lock(lock);
  188. }
  189. static void zs_spin_unlock_cond_irq(spinlock_t *lock, int irq)
  190. {
  191. if (irq)
  192. spin_unlock_irq(lock);
  193. else
  194. spin_unlock(lock);
  195. }
  196. static int zs_receive_drain(struct zs_port *zport)
  197. {
  198. int loops = 10000;
  199. while ((read_zsreg(zport, R0) & Rx_CH_AV) && --loops)
  200. read_zsdata(zport);
  201. return loops;
  202. }
  203. static int zs_transmit_drain(struct zs_port *zport, int irq)
  204. {
  205. struct zs_scc *scc = zport->scc;
  206. int loops = 10000;
  207. while (!(read_zsreg(zport, R0) & Tx_BUF_EMP) && --loops) {
  208. zs_spin_unlock_cond_irq(&scc->zlock, irq);
  209. udelay(2);
  210. zs_spin_lock_cond_irq(&scc->zlock, irq);
  211. }
  212. return loops;
  213. }
  214. static int zs_line_drain(struct zs_port *zport, int irq)
  215. {
  216. struct zs_scc *scc = zport->scc;
  217. int loops = 10000;
  218. while (!(read_zsreg(zport, R1) & ALL_SNT) && --loops) {
  219. zs_spin_unlock_cond_irq(&scc->zlock, irq);
  220. udelay(2);
  221. zs_spin_lock_cond_irq(&scc->zlock, irq);
  222. }
  223. return loops;
  224. }
  225. static void load_zsregs(struct zs_port *zport, u8 *regs, int irq)
  226. {
  227. /* Let the current transmission finish. */
  228. zs_line_drain(zport, irq);
  229. /* Load 'em up. */
  230. write_zsreg(zport, R3, regs[3] & ~RxENABLE);
  231. write_zsreg(zport, R5, regs[5] & ~TxENAB);
  232. write_zsreg(zport, R4, regs[4]);
  233. write_zsreg(zport, R9, regs[9]);
  234. write_zsreg(zport, R1, regs[1]);
  235. write_zsreg(zport, R2, regs[2]);
  236. write_zsreg(zport, R10, regs[10]);
  237. write_zsreg(zport, R14, regs[14] & ~BRENABL);
  238. write_zsreg(zport, R11, regs[11]);
  239. write_zsreg(zport, R12, regs[12]);
  240. write_zsreg(zport, R13, regs[13]);
  241. write_zsreg(zport, R14, regs[14]);
  242. write_zsreg(zport, R15, regs[15]);
  243. if (regs[3] & RxENABLE)
  244. write_zsreg(zport, R3, regs[3]);
  245. if (regs[5] & TxENAB)
  246. write_zsreg(zport, R5, regs[5]);
  247. return;
  248. }
  249. /*
  250. * Status handling routines.
  251. */
  252. /*
  253. * zs_tx_empty() -- get the transmitter empty status
  254. *
  255. * Purpose: Let user call ioctl() to get info when the UART physically
  256. * is emptied. On bus types like RS485, the transmitter must
  257. * release the bus after transmitting. This must be done when
  258. * the transmit shift register is empty, not be done when the
  259. * transmit holding register is empty. This functionality
  260. * allows an RS485 driver to be written in user space.
  261. */
  262. static unsigned int zs_tx_empty(struct uart_port *uport)
  263. {
  264. struct zs_port *zport = to_zport(uport);
  265. struct zs_scc *scc = zport->scc;
  266. unsigned long flags;
  267. u8 status;
  268. spin_lock_irqsave(&scc->zlock, flags);
  269. status = read_zsreg(zport, R1);
  270. spin_unlock_irqrestore(&scc->zlock, flags);
  271. return status & ALL_SNT ? TIOCSER_TEMT : 0;
  272. }
  273. static unsigned int zs_raw_get_ab_mctrl(struct zs_port *zport_a,
  274. struct zs_port *zport_b)
  275. {
  276. u8 status_a, status_b;
  277. unsigned int mctrl;
  278. status_a = read_zsreg(zport_a, R0);
  279. status_b = read_zsreg(zport_b, R0);
  280. mctrl = ((status_b & CTS) ? TIOCM_CTS : 0) |
  281. ((status_b & DCD) ? TIOCM_CAR : 0) |
  282. ((status_a & DCD) ? TIOCM_RNG : 0) |
  283. ((status_a & SYNC_HUNT) ? TIOCM_DSR : 0);
  284. return mctrl;
  285. }
  286. static unsigned int zs_raw_get_mctrl(struct zs_port *zport)
  287. {
  288. struct zs_port *zport_a = &zport->scc->zport[ZS_CHAN_A];
  289. return zport != zport_a ? zs_raw_get_ab_mctrl(zport_a, zport) : 0;
  290. }
  291. static unsigned int zs_raw_xor_mctrl(struct zs_port *zport)
  292. {
  293. struct zs_port *zport_a = &zport->scc->zport[ZS_CHAN_A];
  294. unsigned int mmask, mctrl, delta;
  295. u8 mask_a, mask_b;
  296. if (zport == zport_a)
  297. return 0;
  298. mask_a = zport_a->regs[15];
  299. mask_b = zport->regs[15];
  300. mmask = ((mask_b & CTSIE) ? TIOCM_CTS : 0) |
  301. ((mask_b & DCDIE) ? TIOCM_CAR : 0) |
  302. ((mask_a & DCDIE) ? TIOCM_RNG : 0) |
  303. ((mask_a & SYNCIE) ? TIOCM_DSR : 0);
  304. mctrl = zport->mctrl;
  305. if (mmask) {
  306. mctrl &= ~mmask;
  307. mctrl |= zs_raw_get_ab_mctrl(zport_a, zport) & mmask;
  308. }
  309. delta = mctrl ^ zport->mctrl;
  310. if (delta)
  311. zport->mctrl = mctrl;
  312. return delta;
  313. }
  314. static unsigned int zs_get_mctrl(struct uart_port *uport)
  315. {
  316. struct zs_port *zport = to_zport(uport);
  317. struct zs_scc *scc = zport->scc;
  318. unsigned int mctrl;
  319. spin_lock(&scc->zlock);
  320. mctrl = zs_raw_get_mctrl(zport);
  321. spin_unlock(&scc->zlock);
  322. return mctrl;
  323. }
  324. static void zs_set_mctrl(struct uart_port *uport, unsigned int mctrl)
  325. {
  326. struct zs_port *zport = to_zport(uport);
  327. struct zs_scc *scc = zport->scc;
  328. struct zs_port *zport_a = &scc->zport[ZS_CHAN_A];
  329. u8 oldloop, newloop;
  330. spin_lock(&scc->zlock);
  331. if (zport != zport_a) {
  332. if (mctrl & TIOCM_DTR)
  333. zport_a->regs[5] |= DTR;
  334. else
  335. zport_a->regs[5] &= ~DTR;
  336. if (mctrl & TIOCM_RTS)
  337. zport_a->regs[5] |= RTS;
  338. else
  339. zport_a->regs[5] &= ~RTS;
  340. write_zsreg(zport_a, R5, zport_a->regs[5]);
  341. }
  342. /* Rarely modified, so don't poke at hardware unless necessary. */
  343. oldloop = zport->regs[14];
  344. newloop = oldloop;
  345. if (mctrl & TIOCM_LOOP)
  346. newloop |= LOOPBAK;
  347. else
  348. newloop &= ~LOOPBAK;
  349. if (newloop != oldloop) {
  350. zport->regs[14] = newloop;
  351. write_zsreg(zport, R14, zport->regs[14]);
  352. }
  353. spin_unlock(&scc->zlock);
  354. }
  355. static void zs_raw_stop_tx(struct zs_port *zport)
  356. {
  357. write_zsreg(zport, R0, RES_Tx_P);
  358. zport->tx_stopped = 1;
  359. }
  360. static void zs_stop_tx(struct uart_port *uport)
  361. {
  362. struct zs_port *zport = to_zport(uport);
  363. struct zs_scc *scc = zport->scc;
  364. spin_lock(&scc->zlock);
  365. zs_raw_stop_tx(zport);
  366. spin_unlock(&scc->zlock);
  367. }
  368. static void zs_raw_transmit_chars(struct zs_port *);
  369. static void zs_start_tx(struct uart_port *uport)
  370. {
  371. struct zs_port *zport = to_zport(uport);
  372. struct zs_scc *scc = zport->scc;
  373. spin_lock(&scc->zlock);
  374. if (zport->tx_stopped) {
  375. zs_transmit_drain(zport, 0);
  376. zport->tx_stopped = 0;
  377. zs_raw_transmit_chars(zport);
  378. }
  379. spin_unlock(&scc->zlock);
  380. }
  381. static void zs_stop_rx(struct uart_port *uport)
  382. {
  383. struct zs_port *zport = to_zport(uport);
  384. struct zs_scc *scc = zport->scc;
  385. struct zs_port *zport_a = &scc->zport[ZS_CHAN_A];
  386. spin_lock(&scc->zlock);
  387. zport->regs[15] &= ~BRKIE;
  388. zport->regs[1] &= ~(RxINT_MASK | TxINT_ENAB);
  389. zport->regs[1] |= RxINT_DISAB;
  390. if (zport != zport_a) {
  391. /* A-side DCD tracks RI and SYNC tracks DSR. */
  392. zport_a->regs[15] &= ~(DCDIE | SYNCIE);
  393. write_zsreg(zport_a, R15, zport_a->regs[15]);
  394. if (!(zport_a->regs[15] & BRKIE)) {
  395. zport_a->regs[1] &= ~EXT_INT_ENAB;
  396. write_zsreg(zport_a, R1, zport_a->regs[1]);
  397. }
  398. /* This-side DCD tracks DCD and CTS tracks CTS. */
  399. zport->regs[15] &= ~(DCDIE | CTSIE);
  400. zport->regs[1] &= ~EXT_INT_ENAB;
  401. } else {
  402. /* DCD tracks RI and SYNC tracks DSR for the B side. */
  403. if (!(zport->regs[15] & (DCDIE | SYNCIE)))
  404. zport->regs[1] &= ~EXT_INT_ENAB;
  405. }
  406. write_zsreg(zport, R15, zport->regs[15]);
  407. write_zsreg(zport, R1, zport->regs[1]);
  408. spin_unlock(&scc->zlock);
  409. }
  410. static void zs_enable_ms(struct uart_port *uport)
  411. {
  412. struct zs_port *zport = to_zport(uport);
  413. struct zs_scc *scc = zport->scc;
  414. struct zs_port *zport_a = &scc->zport[ZS_CHAN_A];
  415. if (zport == zport_a)
  416. return;
  417. spin_lock(&scc->zlock);
  418. /* Clear Ext interrupts if not being handled already. */
  419. if (!(zport_a->regs[1] & EXT_INT_ENAB))
  420. write_zsreg(zport_a, R0, RES_EXT_INT);
  421. /* A-side DCD tracks RI and SYNC tracks DSR. */
  422. zport_a->regs[1] |= EXT_INT_ENAB;
  423. zport_a->regs[15] |= DCDIE | SYNCIE;
  424. /* This-side DCD tracks DCD and CTS tracks CTS. */
  425. zport->regs[15] |= DCDIE | CTSIE;
  426. zs_raw_xor_mctrl(zport);
  427. write_zsreg(zport_a, R1, zport_a->regs[1]);
  428. write_zsreg(zport_a, R15, zport_a->regs[15]);
  429. write_zsreg(zport, R15, zport->regs[15]);
  430. spin_unlock(&scc->zlock);
  431. }
  432. static void zs_break_ctl(struct uart_port *uport, int break_state)
  433. {
  434. struct zs_port *zport = to_zport(uport);
  435. struct zs_scc *scc = zport->scc;
  436. unsigned long flags;
  437. spin_lock_irqsave(&scc->zlock, flags);
  438. if (break_state == -1)
  439. zport->regs[5] |= SND_BRK;
  440. else
  441. zport->regs[5] &= ~SND_BRK;
  442. write_zsreg(zport, R5, zport->regs[5]);
  443. spin_unlock_irqrestore(&scc->zlock, flags);
  444. }
  445. /*
  446. * Interrupt handling routines.
  447. */
  448. #define Rx_BRK 0x0100 /* BREAK event software flag. */
  449. #define Rx_SYS 0x0200 /* SysRq event software flag. */
  450. static void zs_receive_chars(struct zs_port *zport)
  451. {
  452. struct uart_port *uport = &zport->port;
  453. struct zs_scc *scc = zport->scc;
  454. struct uart_icount *icount;
  455. unsigned int avail, status;
  456. int count;
  457. u8 ch, flag;
  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);
  507. }
  508. static void zs_raw_transmit_chars(struct zs_port *zport)
  509. {
  510. struct tty_port *tport = &zport->port.state->port;
  511. unsigned char ch;
  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_tx_stopped(&zport->port) ||
  521. !uart_fifo_get(&zport->port, &ch)) {
  522. zs_raw_stop_tx(zport);
  523. return;
  524. }
  525. /* Send char. */
  526. write_zsdata(zport, ch);
  527. if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS)
  528. uart_write_wakeup(&zport->port);
  529. /* Are we are done? */
  530. if (kfifo_is_empty(&tport->xmit_fifo))
  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. const 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 & (IGNBRK | 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 = NULL;
  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(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 const 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->has_sysrq = IS_ENABLED(CONFIG_SERIAL_ZS_CONSOLE);
  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, unsigned char 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. /* Resume any transmission as the TxIP bit won't be set. */
  999. if (!zport->tx_stopped)
  1000. zs_raw_transmit_chars(zport);
  1001. }
  1002. spin_unlock_irqrestore(&scc->zlock, flags);
  1003. }
  1004. /*
  1005. * Setup serial console baud/bits/parity. We do two things here:
  1006. * - construct a cflag setting for the first uart_open()
  1007. * - initialise the serial port
  1008. * Return non-zero if we didn't find a serial port.
  1009. */
  1010. static int __init zs_console_setup(struct console *co, char *options)
  1011. {
  1012. int chip = co->index / ZS_NUM_CHAN, side = co->index % ZS_NUM_CHAN;
  1013. struct zs_port *zport = &zs_sccs[chip].zport[side];
  1014. struct uart_port *uport = &zport->port;
  1015. int baud = 9600;
  1016. int bits = 8;
  1017. int parity = 'n';
  1018. int flow = 'n';
  1019. int ret;
  1020. ret = zs_map_port(uport);
  1021. if (ret)
  1022. return ret;
  1023. zs_reset(zport);
  1024. zs_pm(uport, 0, -1);
  1025. if (options)
  1026. uart_parse_options(options, &baud, &parity, &bits, &flow);
  1027. return uart_set_options(uport, co, baud, parity, bits, flow);
  1028. }
  1029. static struct uart_driver zs_reg;
  1030. static struct console zs_console = {
  1031. .name = "ttyS",
  1032. .write = zs_console_write,
  1033. .device = uart_console_device,
  1034. .setup = zs_console_setup,
  1035. .flags = CON_PRINTBUFFER,
  1036. .index = -1,
  1037. .data = &zs_reg,
  1038. };
  1039. /*
  1040. * Register console.
  1041. */
  1042. static int __init zs_serial_console_init(void)
  1043. {
  1044. int ret;
  1045. ret = zs_probe_sccs();
  1046. if (ret)
  1047. return ret;
  1048. register_console(&zs_console);
  1049. return 0;
  1050. }
  1051. console_initcall(zs_serial_console_init);
  1052. #define SERIAL_ZS_CONSOLE &zs_console
  1053. #else
  1054. #define SERIAL_ZS_CONSOLE NULL
  1055. #endif /* CONFIG_SERIAL_ZS_CONSOLE */
  1056. static struct uart_driver zs_reg = {
  1057. .owner = THIS_MODULE,
  1058. .driver_name = "serial",
  1059. .dev_name = "ttyS",
  1060. .major = TTY_MAJOR,
  1061. .minor = 64,
  1062. .nr = ZS_NUM_SCCS * ZS_NUM_CHAN,
  1063. .cons = SERIAL_ZS_CONSOLE,
  1064. };
  1065. /* zs_init inits the driver. */
  1066. static int __init zs_init(void)
  1067. {
  1068. int i, ret;
  1069. pr_info("%s%s\n", zs_name, zs_version);
  1070. /* Find out how many Z85C30 SCCs we have. */
  1071. ret = zs_probe_sccs();
  1072. if (ret)
  1073. return ret;
  1074. ret = uart_register_driver(&zs_reg);
  1075. if (ret)
  1076. return ret;
  1077. for (i = 0; i < ZS_NUM_SCCS * ZS_NUM_CHAN; i++) {
  1078. struct zs_scc *scc = &zs_sccs[i / ZS_NUM_CHAN];
  1079. struct zs_port *zport = &scc->zport[i % ZS_NUM_CHAN];
  1080. struct uart_port *uport = &zport->port;
  1081. if (zport->scc)
  1082. uart_add_one_port(&zs_reg, uport);
  1083. }
  1084. return 0;
  1085. }
  1086. static void __exit zs_exit(void)
  1087. {
  1088. int i;
  1089. for (i = ZS_NUM_SCCS * ZS_NUM_CHAN - 1; i >= 0; i--) {
  1090. struct zs_scc *scc = &zs_sccs[i / ZS_NUM_CHAN];
  1091. struct zs_port *zport = &scc->zport[i % ZS_NUM_CHAN];
  1092. struct uart_port *uport = &zport->port;
  1093. if (zport->scc)
  1094. uart_remove_one_port(&zs_reg, uport);
  1095. }
  1096. uart_unregister_driver(&zs_reg);
  1097. }
  1098. module_init(zs_init);
  1099. module_exit(zs_exit);