zs.c 31 KB

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