aurora.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366
  1. /* $Id: aurora.c,v 1.19 2002/01/08 16:00:16 davem Exp $
  2. * linux/drivers/sbus/char/aurora.c -- Aurora multiport driver
  3. *
  4. * Copyright (c) 1999 by Oliver Aldulea (oli at bv dot ro)
  5. *
  6. * This code is based on the RISCom/8 multiport serial driver written
  7. * by Dmitry Gorodchanin (pgmdsg@ibi.com), based on the Linux serial
  8. * driver, written by Linus Torvalds, Theodore T'so and others.
  9. * The Aurora multiport programming info was obtained mainly from the
  10. * Cirrus Logic CD180 documentation (available on the web), and by
  11. * doing heavy tests on the board. Many thanks to Eddie C. Dost for the
  12. * help on the sbus interface.
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. *
  28. * Revision 1.0
  29. *
  30. * This is the first public release.
  31. *
  32. * Most of the information you need is in the aurora.h file. Please
  33. * read that file before reading this one.
  34. *
  35. * Several parts of the code do not have comments yet.
  36. *
  37. * n.b. The board can support 115.2 bit rates, but only on a few
  38. * ports. The total badwidth of one chip (ports 0-7 or 8-15) is equal
  39. * to OSC_FREQ div 16. In case of my board, each chip can take 6
  40. * channels of 115.2 kbaud. This information is not well-tested.
  41. *
  42. * Fixed to use tty_get_baud_rate().
  43. * Theodore Ts'o <tytso@mit.edu>, 2001-Oct-12
  44. */
  45. #include <linux/module.h>
  46. #include <linux/errno.h>
  47. #include <linux/sched.h>
  48. #ifdef AURORA_INT_DEBUG
  49. #include <linux/timer.h>
  50. #endif
  51. #include <linux/interrupt.h>
  52. #include <linux/tty.h>
  53. #include <linux/tty_flip.h>
  54. #include <linux/major.h>
  55. #include <linux/string.h>
  56. #include <linux/fcntl.h>
  57. #include <linux/mm.h>
  58. #include <linux/kernel.h>
  59. #include <linux/init.h>
  60. #include <linux/delay.h>
  61. #include <linux/bitops.h>
  62. #include <asm/io.h>
  63. #include <asm/irq.h>
  64. #include <asm/oplib.h>
  65. #include <asm/system.h>
  66. #include <asm/kdebug.h>
  67. #include <asm/sbus.h>
  68. #include <asm/uaccess.h>
  69. #include "aurora.h"
  70. #include "cd180.h"
  71. unsigned char irqs[4] = {
  72. 0, 0, 0, 0
  73. };
  74. #ifdef AURORA_INT_DEBUG
  75. int irqhit=0;
  76. #endif
  77. static struct tty_driver *aurora_driver;
  78. static struct Aurora_board aurora_board[AURORA_NBOARD] = {
  79. {0,},
  80. };
  81. static struct Aurora_port aurora_port[AURORA_TNPORTS] = {
  82. { 0, },
  83. };
  84. /* no longer used. static struct Aurora_board * IRQ_to_board[16] = { NULL, } ;*/
  85. static unsigned char * tmp_buf = NULL;
  86. static DECLARE_MUTEX(tmp_buf_sem);
  87. DECLARE_TASK_QUEUE(tq_aurora);
  88. static inline int aurora_paranoia_check(struct Aurora_port const * port,
  89. char *name, const char *routine)
  90. {
  91. #ifdef AURORA_PARANOIA_CHECK
  92. static const char *badmagic =
  93. KERN_DEBUG "aurora: Warning: bad aurora port magic number for device %s in %s\n";
  94. static const char *badinfo =
  95. KERN_DEBUG "aurora: Warning: null aurora port for device %s in %s\n";
  96. if (!port) {
  97. printk(badinfo, name, routine);
  98. return 1;
  99. }
  100. if (port->magic != AURORA_MAGIC) {
  101. printk(badmagic, name, routine);
  102. return 1;
  103. }
  104. #endif
  105. return 0;
  106. }
  107. /*
  108. *
  109. * Service functions for aurora driver.
  110. *
  111. */
  112. /* Get board number from pointer */
  113. extern inline int board_No (struct Aurora_board const * bp)
  114. {
  115. return bp - aurora_board;
  116. }
  117. /* Get port number from pointer */
  118. extern inline int port_No (struct Aurora_port const * port)
  119. {
  120. return AURORA_PORT(port - aurora_port);
  121. }
  122. /* Get pointer to board from pointer to port */
  123. extern inline struct Aurora_board * port_Board(struct Aurora_port const * port)
  124. {
  125. return &aurora_board[AURORA_BOARD(port - aurora_port)];
  126. }
  127. /* Wait for Channel Command Register ready */
  128. extern inline void aurora_wait_CCR(struct aurora_reg128 * r)
  129. {
  130. unsigned long delay;
  131. #ifdef AURORA_DEBUG
  132. printk("aurora_wait_CCR\n");
  133. #endif
  134. /* FIXME: need something more descriptive than 100000 :) */
  135. for (delay = 100000; delay; delay--)
  136. if (!sbus_readb(&r->r[CD180_CCR]))
  137. return;
  138. printk(KERN_DEBUG "aurora: Timeout waiting for CCR.\n");
  139. }
  140. /*
  141. * aurora probe functions.
  142. */
  143. /* Must be called with enabled interrupts */
  144. extern inline void aurora_long_delay(unsigned long delay)
  145. {
  146. unsigned long i;
  147. #ifdef AURORA_DEBUG
  148. printk("aurora_long_delay: start\n");
  149. #endif
  150. for (i = jiffies + delay; time_before(jiffies, i); ) ;
  151. #ifdef AURORA_DEBUG
  152. printk("aurora_long_delay: end\n");
  153. #endif
  154. }
  155. /* Reset and setup CD180 chip */
  156. static int aurora_init_CD180(struct Aurora_board * bp, int chip)
  157. {
  158. unsigned long flags;
  159. int id;
  160. #ifdef AURORA_DEBUG
  161. printk("aurora_init_CD180: start %d:%d\n",
  162. board_No(bp), chip);
  163. #endif
  164. save_flags(flags); cli();
  165. sbus_writeb(0, &bp->r[chip]->r[CD180_CAR]);
  166. sbus_writeb(0, &bp->r[chip]->r[CD180_GSVR]);
  167. /* Wait for CCR ready */
  168. aurora_wait_CCR(bp->r[chip]);
  169. /* Reset CD180 chip */
  170. sbus_writeb(CCR_HARDRESET, &bp->r[chip]->r[CD180_CCR]);
  171. udelay(1);
  172. sti();
  173. id=1000;
  174. while((--id) &&
  175. (sbus_readb(&bp->r[chip]->r[CD180_GSVR])!=0xff))udelay(100);
  176. if(!id) {
  177. printk(KERN_ERR "aurora%d: Chip %d failed init.\n",
  178. board_No(bp), chip);
  179. restore_flags(flags);
  180. return(-1);
  181. }
  182. cli();
  183. sbus_writeb((board_No(bp)<<5)|((chip+1)<<3),
  184. &bp->r[chip]->r[CD180_GSVR]); /* Set ID for this chip */
  185. sbus_writeb(0x80|bp->ACK_MINT,
  186. &bp->r[chip]->r[CD180_MSMR]); /* Prio for modem intr */
  187. sbus_writeb(0x80|bp->ACK_TINT,
  188. &bp->r[chip]->r[CD180_TSMR]); /* Prio for transmitter intr */
  189. sbus_writeb(0x80|bp->ACK_RINT,
  190. &bp->r[chip]->r[CD180_RSMR]); /* Prio for receiver intr */
  191. /* Setting up prescaler. We need 4 tick per 1 ms */
  192. sbus_writeb((bp->oscfreq/(1000000/AURORA_TPS)) >> 8,
  193. &bp->r[chip]->r[CD180_PPRH]);
  194. sbus_writeb((bp->oscfreq/(1000000/AURORA_TPS)) & 0xff,
  195. &bp->r[chip]->r[CD180_PPRL]);
  196. sbus_writeb(SRCR_AUTOPRI|SRCR_GLOBPRI,
  197. &bp->r[chip]->r[CD180_SRCR]);
  198. id = sbus_readb(&bp->r[chip]->r[CD180_GFRCR]);
  199. printk(KERN_INFO "aurora%d: Chip %d id %02x: ",
  200. board_No(bp), chip,id);
  201. if(sbus_readb(&bp->r[chip]->r[CD180_SRCR]) & 128) {
  202. switch (id) {
  203. case 0x82:printk("CL-CD1864 rev A\n");break;
  204. case 0x83:printk("CL-CD1865 rev A\n");break;
  205. case 0x84:printk("CL-CD1865 rev B\n");break;
  206. case 0x85:printk("CL-CD1865 rev C\n");break;
  207. default:printk("Unknown.\n");
  208. };
  209. } else {
  210. switch (id) {
  211. case 0x81:printk("CL-CD180 rev B\n");break;
  212. case 0x82:printk("CL-CD180 rev C\n");break;
  213. default:printk("Unknown.\n");
  214. };
  215. }
  216. restore_flags(flags);
  217. #ifdef AURORA_DEBUG
  218. printk("aurora_init_CD180: end\n");
  219. #endif
  220. return 0;
  221. }
  222. static int valid_irq(unsigned char irq)
  223. {
  224. int i;
  225. for(i=0;i<TYPE_1_IRQS;i++)
  226. if (type_1_irq[i]==irq) return 1;
  227. return 0;
  228. }
  229. static irqreturn_t aurora_interrupt(int irq, void * dev_id, struct pt_regs * regs);
  230. /* Main probing routine, also sets irq. */
  231. static int aurora_probe(void)
  232. {
  233. struct sbus_bus *sbus;
  234. struct sbus_dev *sdev;
  235. int grrr;
  236. char buf[30];
  237. int bn = 0;
  238. struct Aurora_board *bp;
  239. for_each_sbus(sbus) {
  240. for_each_sbusdev(sdev, sbus) {
  241. /* printk("Try: %x %s\n",sdev,sdev->prom_name);*/
  242. if (!strcmp(sdev->prom_name, "sio16")) {
  243. #ifdef AURORA_DEBUG
  244. printk(KERN_INFO "aurora: sio16 at %p\n",sdev);
  245. #endif
  246. if((sdev->reg_addrs[0].reg_size!=1) &&
  247. (sdev->reg_addrs[1].reg_size!=128) &&
  248. (sdev->reg_addrs[2].reg_size!=128) &&
  249. (sdev->reg_addrs[3].reg_size!=4)) {
  250. printk(KERN_ERR "aurora%d: registers' sizes "
  251. "do not match.\n", bn);
  252. break;
  253. }
  254. bp = &aurora_board[bn];
  255. bp->r0 = (struct aurora_reg1 *)
  256. sbus_ioremap(&sdev->resource[0], 0,
  257. sdev->reg_addrs[0].reg_size,
  258. "sio16");
  259. if (bp->r0 == NULL) {
  260. printk(KERN_ERR "aurora%d: can't map "
  261. "reg_addrs[0]\n", bn);
  262. break;
  263. }
  264. #ifdef AURORA_DEBUG
  265. printk("Map reg 0: %p\n", bp->r0);
  266. #endif
  267. bp->r[0] = (struct aurora_reg128 *)
  268. sbus_ioremap(&sdev->resource[1], 0,
  269. sdev->reg_addrs[1].reg_size,
  270. "sio16");
  271. if (bp->r[0] == NULL) {
  272. printk(KERN_ERR "aurora%d: can't map "
  273. "reg_addrs[1]\n", bn);
  274. break;
  275. }
  276. #ifdef AURORA_DEBUG
  277. printk("Map reg 1: %p\n", bp->r[0]);
  278. #endif
  279. bp->r[1] = (struct aurora_reg128 *)
  280. sbus_ioremap(&sdev->resource[2], 0,
  281. sdev->reg_addrs[2].reg_size,
  282. "sio16");
  283. if (bp->r[1] == NULL) {
  284. printk(KERN_ERR "aurora%d: can't map "
  285. "reg_addrs[2]\n", bn);
  286. break;
  287. }
  288. #ifdef AURORA_DEBUG
  289. printk("Map reg 2: %p\n", bp->r[1]);
  290. #endif
  291. bp->r3 = (struct aurora_reg4 *)
  292. sbus_ioremap(&sdev->resource[3], 0,
  293. sdev->reg_addrs[3].reg_size,
  294. "sio16");
  295. if (bp->r3 == NULL) {
  296. printk(KERN_ERR "aurora%d: can't map "
  297. "reg_addrs[3]\n", bn);
  298. break;
  299. }
  300. #ifdef AURORA_DEBUG
  301. printk("Map reg 3: %p\n", bp->r3);
  302. #endif
  303. /* Variables setup */
  304. bp->flags = 0;
  305. #ifdef AURORA_DEBUG
  306. grrr=prom_getint(sdev->prom_node,"intr");
  307. printk("intr pri %d\n", grrr);
  308. #endif
  309. if ((bp->irq=irqs[bn]) && valid_irq(bp->irq) &&
  310. !request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
  311. free_irq(bp->irq|0x30, bp);
  312. } else
  313. if ((bp->irq=prom_getint(sdev->prom_node, "bintr")) && valid_irq(bp->irq) &&
  314. !request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
  315. free_irq(bp->irq|0x30, bp);
  316. } else
  317. if ((bp->irq=prom_getint(sdev->prom_node, "intr")) && valid_irq(bp->irq) &&
  318. !request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
  319. free_irq(bp->irq|0x30, bp);
  320. } else
  321. for(grrr=0;grrr<TYPE_1_IRQS;grrr++) {
  322. if ((bp->irq=type_1_irq[grrr])&&!request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
  323. free_irq(bp->irq|0x30, bp);
  324. break;
  325. } else {
  326. printk(KERN_ERR "aurora%d: Could not get an irq for this board !!!\n",bn);
  327. bp->flags=0xff;
  328. }
  329. }
  330. if(bp->flags==0xff)break;
  331. printk(KERN_INFO "aurora%d: irq %d\n",bn,bp->irq&0x0f);
  332. buf[0]=0;
  333. grrr=prom_getproperty(sdev->prom_node,"dtr_rts",buf,sizeof(buf));
  334. if(!strcmp(buf,"swapped")){
  335. printk(KERN_INFO "aurora%d: Swapped DTR and RTS\n",bn);
  336. bp->DTR=MSVR_RTS;
  337. bp->RTS=MSVR_DTR;
  338. bp->MSVDTR=CD180_MSVRTS;
  339. bp->MSVRTS=CD180_MSVDTR;
  340. bp->flags|=AURORA_BOARD_DTR_FLOW_OK;
  341. }else{
  342. #ifdef AURORA_FORCE_DTR_FLOW
  343. printk(KERN_INFO "aurora%d: Forcing swapped DTR-RTS\n",bn);
  344. bp->DTR=MSVR_RTS;
  345. bp->RTS=MSVR_DTR;
  346. bp->MSVDTR=CD180_MSVRTS;
  347. bp->MSVRTS=CD180_MSVDTR;
  348. bp->flags|=AURORA_BOARD_DTR_FLOW_OK;
  349. #else
  350. printk(KERN_INFO "aurora%d: Normal DTR and RTS\n",bn);
  351. bp->DTR=MSVR_DTR;
  352. bp->RTS=MSVR_RTS;
  353. bp->MSVDTR=CD180_MSVDTR;
  354. bp->MSVRTS=CD180_MSVRTS;
  355. #endif
  356. }
  357. bp->oscfreq=prom_getint(sdev->prom_node,"clk")*100;
  358. printk(KERN_INFO "aurora%d: Oscillator: %d Hz\n",bn,bp->oscfreq);
  359. grrr=prom_getproperty(sdev->prom_node,"chip",buf,sizeof(buf));
  360. printk(KERN_INFO "aurora%d: Chips: %s\n",bn,buf);
  361. grrr=prom_getproperty(sdev->prom_node,"manu",buf,sizeof(buf));
  362. printk(KERN_INFO "aurora%d: Manufacturer: %s\n",bn,buf);
  363. grrr=prom_getproperty(sdev->prom_node,"model",buf,sizeof(buf));
  364. printk(KERN_INFO "aurora%d: Model: %s\n",bn,buf);
  365. grrr=prom_getproperty(sdev->prom_node,"rev",buf,sizeof(buf));
  366. printk(KERN_INFO "aurora%d: Revision: %s\n",bn,buf);
  367. grrr=prom_getproperty(sdev->prom_node,"mode",buf,sizeof(buf));
  368. printk(KERN_INFO "aurora%d: Mode: %s\n",bn,buf);
  369. #ifdef MODULE
  370. bp->count=0;
  371. #endif
  372. bp->flags = AURORA_BOARD_PRESENT;
  373. /* hardware ack */
  374. bp->ACK_MINT=1;
  375. bp->ACK_TINT=2;
  376. bp->ACK_RINT=3;
  377. bn++;
  378. }
  379. }
  380. }
  381. return bn;
  382. }
  383. static void aurora_release_io_range(struct Aurora_board *bp)
  384. {
  385. sbus_iounmap((unsigned long)bp->r0, 1);
  386. sbus_iounmap((unsigned long)bp->r[0], 128);
  387. sbus_iounmap((unsigned long)bp->r[1], 128);
  388. sbus_iounmap((unsigned long)bp->r3, 4);
  389. }
  390. extern inline void aurora_mark_event(struct Aurora_port * port, int event)
  391. {
  392. #ifdef AURORA_DEBUG
  393. printk("aurora_mark_event: start\n");
  394. #endif
  395. set_bit(event, &port->event);
  396. queue_task(&port->tqueue, &tq_aurora);
  397. mark_bh(AURORA_BH);
  398. #ifdef AURORA_DEBUG
  399. printk("aurora_mark_event: end\n");
  400. #endif
  401. }
  402. static __inline__ struct Aurora_port * aurora_get_port(struct Aurora_board const * bp,
  403. int chip,
  404. unsigned char const *what)
  405. {
  406. unsigned char channel;
  407. struct Aurora_port * port;
  408. channel = ((chip << 3) |
  409. ((sbus_readb(&bp->r[chip]->r[CD180_GSCR]) & GSCR_CHAN) >> GSCR_CHAN_OFF));
  410. port = &aurora_port[board_No(bp) * AURORA_NPORT * AURORA_NCD180 + channel];
  411. if (port->flags & ASYNC_INITIALIZED)
  412. return port;
  413. printk(KERN_DEBUG "aurora%d: %s interrupt from invalid port %d\n",
  414. board_No(bp), what, channel);
  415. return NULL;
  416. }
  417. static void aurora_receive_exc(struct Aurora_board const * bp, int chip)
  418. {
  419. struct Aurora_port *port;
  420. struct tty_struct *tty;
  421. unsigned char status;
  422. unsigned char ch;
  423. if (!(port = aurora_get_port(bp, chip, "Receive_x")))
  424. return;
  425. tty = port->tty;
  426. if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
  427. #ifdef AURORA_INTNORM
  428. printk("aurora%d: port %d: Working around flip buffer overflow.\n",
  429. board_No(bp), port_No(port));
  430. #endif
  431. return;
  432. }
  433. #ifdef AURORA_REPORT_OVERRUN
  434. status = sbus_readb(&bp->r[chip]->r[CD180_RCSR]);
  435. if (status & RCSR_OE) {
  436. port->overrun++;
  437. #if 1
  438. printk("aurora%d: port %d: Overrun. Total %ld overruns.\n",
  439. board_No(bp), port_No(port), port->overrun);
  440. #endif
  441. }
  442. status &= port->mark_mask;
  443. #else
  444. status = sbus_readb(&bp->r[chip]->r[CD180_RCSR]) & port->mark_mask;
  445. #endif
  446. ch = sbus_readb(&bp->r[chip]->r[CD180_RDR]);
  447. if (!status)
  448. return;
  449. if (status & RCSR_TOUT) {
  450. /* printk("aurora%d: port %d: Receiver timeout. Hardware problems ?\n",
  451. board_No(bp), port_No(port));*/
  452. return;
  453. } else if (status & RCSR_BREAK) {
  454. printk(KERN_DEBUG "aurora%d: port %d: Handling break...\n",
  455. board_No(bp), port_No(port));
  456. *tty->flip.flag_buf_ptr++ = TTY_BREAK;
  457. if (port->flags & ASYNC_SAK)
  458. do_SAK(tty);
  459. } else if (status & RCSR_PE)
  460. *tty->flip.flag_buf_ptr++ = TTY_PARITY;
  461. else if (status & RCSR_FE)
  462. *tty->flip.flag_buf_ptr++ = TTY_FRAME;
  463. else if (status & RCSR_OE)
  464. *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
  465. else
  466. *tty->flip.flag_buf_ptr++ = 0;
  467. *tty->flip.char_buf_ptr++ = ch;
  468. tty->flip.count++;
  469. queue_task(&tty->flip.tqueue, &tq_timer);
  470. }
  471. static void aurora_receive(struct Aurora_board const * bp, int chip)
  472. {
  473. struct Aurora_port *port;
  474. struct tty_struct *tty;
  475. unsigned char count,cnt;
  476. if (!(port = aurora_get_port(bp, chip, "Receive")))
  477. return;
  478. tty = port->tty;
  479. count = sbus_readb(&bp->r[chip]->r[CD180_RDCR]);
  480. #ifdef AURORA_REPORT_FIFO
  481. port->hits[count > 8 ? 9 : count]++;
  482. #endif
  483. while (count--) {
  484. if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
  485. #ifdef AURORA_INTNORM
  486. printk("aurora%d: port %d: Working around flip buffer overflow.\n",
  487. board_No(bp), port_No(port));
  488. #endif
  489. break;
  490. }
  491. cnt = sbus_readb(&bp->r[chip]->r[CD180_RDR]);
  492. *tty->flip.char_buf_ptr++ = cnt;
  493. *tty->flip.flag_buf_ptr++ = 0;
  494. tty->flip.count++;
  495. }
  496. queue_task(&tty->flip.tqueue, &tq_timer);
  497. }
  498. static void aurora_transmit(struct Aurora_board const * bp, int chip)
  499. {
  500. struct Aurora_port *port;
  501. struct tty_struct *tty;
  502. unsigned char count;
  503. if (!(port = aurora_get_port(bp, chip, "Transmit")))
  504. return;
  505. tty = port->tty;
  506. if (port->SRER & SRER_TXEMPTY) {
  507. /* FIFO drained */
  508. sbus_writeb(port_No(port) & 7,
  509. &bp->r[chip]->r[CD180_CAR]);
  510. udelay(1);
  511. port->SRER &= ~SRER_TXEMPTY;
  512. sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
  513. return;
  514. }
  515. if ((port->xmit_cnt <= 0 && !port->break_length)
  516. || tty->stopped || tty->hw_stopped) {
  517. sbus_writeb(port_No(port) & 7,
  518. &bp->r[chip]->r[CD180_CAR]);
  519. udelay(1);
  520. port->SRER &= ~SRER_TXRDY;
  521. sbus_writeb(port->SRER,
  522. &bp->r[chip]->r[CD180_SRER]);
  523. return;
  524. }
  525. if (port->break_length) {
  526. if (port->break_length > 0) {
  527. if (port->COR2 & COR2_ETC) {
  528. sbus_writeb(CD180_C_ESC,
  529. &bp->r[chip]->r[CD180_TDR]);
  530. sbus_writeb(CD180_C_SBRK,
  531. &bp->r[chip]->r[CD180_TDR]);
  532. port->COR2 &= ~COR2_ETC;
  533. }
  534. count = min(port->break_length, 0xff);
  535. sbus_writeb(CD180_C_ESC,
  536. &bp->r[chip]->r[CD180_TDR]);
  537. sbus_writeb(CD180_C_DELAY,
  538. &bp->r[chip]->r[CD180_TDR]);
  539. sbus_writeb(count,
  540. &bp->r[chip]->r[CD180_TDR]);
  541. if (!(port->break_length -= count))
  542. port->break_length--;
  543. } else {
  544. sbus_writeb(CD180_C_ESC,
  545. &bp->r[chip]->r[CD180_TDR]);
  546. sbus_writeb(CD180_C_EBRK,
  547. &bp->r[chip]->r[CD180_TDR]);
  548. sbus_writeb(port->COR2,
  549. &bp->r[chip]->r[CD180_COR2]);
  550. aurora_wait_CCR(bp->r[chip]);
  551. sbus_writeb(CCR_CORCHG2,
  552. &bp->r[chip]->r[CD180_CCR]);
  553. port->break_length = 0;
  554. }
  555. return;
  556. }
  557. count = CD180_NFIFO;
  558. do {
  559. u8 byte = port->xmit_buf[port->xmit_tail++];
  560. sbus_writeb(byte, &bp->r[chip]->r[CD180_TDR]);
  561. port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1);
  562. if (--port->xmit_cnt <= 0)
  563. break;
  564. } while (--count > 0);
  565. if (port->xmit_cnt <= 0) {
  566. sbus_writeb(port_No(port) & 7,
  567. &bp->r[chip]->r[CD180_CAR]);
  568. udelay(1);
  569. port->SRER &= ~SRER_TXRDY;
  570. sbus_writeb(port->SRER,
  571. &bp->r[chip]->r[CD180_SRER]);
  572. }
  573. if (port->xmit_cnt <= port->wakeup_chars)
  574. aurora_mark_event(port, RS_EVENT_WRITE_WAKEUP);
  575. }
  576. static void aurora_check_modem(struct Aurora_board const * bp, int chip)
  577. {
  578. struct Aurora_port *port;
  579. struct tty_struct *tty;
  580. unsigned char mcr;
  581. if (!(port = aurora_get_port(bp, chip, "Modem")))
  582. return;
  583. tty = port->tty;
  584. mcr = sbus_readb(&bp->r[chip]->r[CD180_MCR]);
  585. if (mcr & MCR_CDCHG) {
  586. if (sbus_readb(&bp->r[chip]->r[CD180_MSVR]) & MSVR_CD)
  587. wake_up_interruptible(&port->open_wait);
  588. else
  589. schedule_task(&port->tqueue_hangup);
  590. }
  591. /* We don't have such things yet. My aurora board has DTR and RTS swapped, but that doesn't count in this driver. Let's hope
  592. * Aurora didn't made any boards with CTS or DSR broken...
  593. */
  594. /* #ifdef AURORA_BRAIN_DAMAGED_CTS
  595. if (mcr & MCR_CTSCHG) {
  596. if (aurora_in(bp, CD180_MSVR) & MSVR_CTS) {
  597. tty->hw_stopped = 0;
  598. port->SRER |= SRER_TXRDY;
  599. if (port->xmit_cnt <= port->wakeup_chars)
  600. aurora_mark_event(port, RS_EVENT_WRITE_WAKEUP);
  601. } else {
  602. tty->hw_stopped = 1;
  603. port->SRER &= ~SRER_TXRDY;
  604. }
  605. sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
  606. }
  607. if (mcr & MCR_DSRCHG) {
  608. if (aurora_in(bp, CD180_MSVR) & MSVR_DSR) {
  609. tty->hw_stopped = 0;
  610. port->SRER |= SRER_TXRDY;
  611. if (port->xmit_cnt <= port->wakeup_chars)
  612. aurora_mark_event(port, RS_EVENT_WRITE_WAKEUP);
  613. } else {
  614. tty->hw_stopped = 1;
  615. port->SRER &= ~SRER_TXRDY;
  616. }
  617. sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
  618. }
  619. #endif AURORA_BRAIN_DAMAGED_CTS */
  620. /* Clear change bits */
  621. sbus_writeb(0, &bp->r[chip]->r[CD180_MCR]);
  622. }
  623. /* The main interrupt processing routine */
  624. static irqreturn_t aurora_interrupt(int irq, void * dev_id, struct pt_regs * regs)
  625. {
  626. unsigned char status;
  627. unsigned char ack,chip/*,chip_id*/;
  628. struct Aurora_board * bp = (struct Aurora_board *) dev_id;
  629. unsigned long loop = 0;
  630. #ifdef AURORA_INT_DEBUG
  631. printk("IRQ%d %d\n",irq,++irqhit);
  632. #ifdef AURORA_FLOODPRO
  633. if (irqhit>=AURORA_FLOODPRO)
  634. sbus_writeb(8, &bp->r0->r);
  635. #endif
  636. #endif
  637. /* old bp = IRQ_to_board[irq&0x0f];*/
  638. if (!bp || !(bp->flags & AURORA_BOARD_ACTIVE))
  639. return IRQ_NONE;
  640. /* The while() below takes care of this.
  641. status = sbus_readb(&bp->r[0]->r[CD180_SRSR]);
  642. #ifdef AURORA_INT_DEBUG
  643. printk("mumu: %02x\n", status);
  644. #endif
  645. if (!(status&SRSR_ANYINT))
  646. return IRQ_NONE; * Nobody has anything to say, so exit *
  647. */
  648. while ((loop++ < 48) &&
  649. (status = sbus_readb(&bp->r[0]->r[CD180_SRSR]) & SRSR_ANYINT)){
  650. #ifdef AURORA_INT_DEBUG
  651. printk("SRSR: %02x\n", status);
  652. #endif
  653. if (status & SRSR_REXT) {
  654. ack = sbus_readb(&bp->r3->r[bp->ACK_RINT]);
  655. #ifdef AURORA_INT_DEBUG
  656. printk("R-ACK %02x\n", ack);
  657. #endif
  658. if ((ack >> 5) == board_No(bp)) {
  659. if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
  660. if ((ack&GSVR_ITMASK)==GSVR_IT_RGD) {
  661. aurora_receive(bp,chip);
  662. sbus_writeb(0,
  663. &bp->r[chip]->r[CD180_EOSRR]);
  664. } else if ((ack & GSVR_ITMASK) == GSVR_IT_REXC) {
  665. aurora_receive_exc(bp,chip);
  666. sbus_writeb(0,
  667. &bp->r[chip]->r[CD180_EOSRR]);
  668. }
  669. }
  670. }
  671. } else if (status & SRSR_TEXT) {
  672. ack = sbus_readb(&bp->r3->r[bp->ACK_TINT]);
  673. #ifdef AURORA_INT_DEBUG
  674. printk("T-ACK %02x\n", ack);
  675. #endif
  676. if ((ack >> 5) == board_No(bp)) {
  677. if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
  678. if ((ack&GSVR_ITMASK)==GSVR_IT_TX) {
  679. aurora_transmit(bp,chip);
  680. sbus_writeb(0,
  681. &bp->r[chip]->r[CD180_EOSRR]);
  682. }
  683. }
  684. }
  685. } else if (status & SRSR_MEXT) {
  686. ack = sbus_readb(&bp->r3->r[bp->ACK_MINT]);
  687. #ifdef AURORA_INT_DEBUG
  688. printk("M-ACK %02x\n", ack);
  689. #endif
  690. if ((ack >> 5) == board_No(bp)) {
  691. if ((chip = ((ack>>3)&3)-1) < AURORA_NCD180) {
  692. if ((ack&GSVR_ITMASK)==GSVR_IT_MDM) {
  693. aurora_check_modem(bp,chip);
  694. sbus_writeb(0,
  695. &bp->r[chip]->r[CD180_EOSRR]);
  696. }
  697. }
  698. }
  699. }
  700. }
  701. /* I guess this faster code can be used with CD1865, using AUROPRI and GLOBPRI. */
  702. #if 0
  703. while ((loop++ < 48)&&(status=bp->r[0]->r[CD180_SRSR]&SRSR_ANYINT)){
  704. #ifdef AURORA_INT_DEBUG
  705. printk("SRSR: %02x\n",status);
  706. #endif
  707. ack = sbus_readb(&bp->r3->r[0]);
  708. #ifdef AURORA_INT_DEBUG
  709. printk("ACK: %02x\n",ack);
  710. #endif
  711. if ((ack>>5)==board_No(bp)) {
  712. if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
  713. ack&=GSVR_ITMASK;
  714. if (ack==GSVR_IT_RGD) {
  715. aurora_receive(bp,chip);
  716. sbus_writeb(0,
  717. &bp->r[chip]->r[CD180_EOSRR]);
  718. } else if (ack==GSVR_IT_REXC) {
  719. aurora_receive_exc(bp,chip);
  720. sbus_writeb(0,
  721. &bp->r[chip]->r[CD180_EOSRR]);
  722. } else if (ack==GSVR_IT_TX) {
  723. aurora_transmit(bp,chip);
  724. sbus_writeb(0,
  725. &bp->r[chip]->r[CD180_EOSRR]);
  726. } else if (ack==GSVR_IT_MDM) {
  727. aurora_check_modem(bp,chip);
  728. sbus_writeb(0,
  729. &bp->r[chip]->r[CD180_EOSRR]);
  730. }
  731. }
  732. }
  733. }
  734. #endif
  735. /* This is the old handling routine, used in riscom8 for only one CD180. I keep it here for reference. */
  736. #if 0
  737. for(chip=0;chip<AURORA_NCD180;chip++){
  738. chip_id=(board_No(bp)<<5)|((chip+1)<<3);
  739. loop=0;
  740. while ((loop++ < 1) &&
  741. ((status = sbus_readb(&bp->r[chip]->r[CD180_SRSR])) &
  742. (SRSR_TEXT | SRSR_MEXT | SRSR_REXT))) {
  743. if (status & SRSR_REXT) {
  744. ack = sbus_readb(&bp->r3->r[bp->ACK_RINT]);
  745. if (ack == (chip_id | GSVR_IT_RGD)) {
  746. #ifdef AURORA_INTMSG
  747. printk("RX ACK\n");
  748. #endif
  749. aurora_receive(bp,chip);
  750. } else if (ack == (chip_id | GSVR_IT_REXC)) {
  751. #ifdef AURORA_INTMSG
  752. printk("RXC ACK\n");
  753. #endif
  754. aurora_receive_exc(bp,chip);
  755. } else {
  756. #ifdef AURORA_INTNORM
  757. printk("aurora%d-%d: Bad receive ack 0x%02x.\n",
  758. board_No(bp), chip, ack);
  759. #endif
  760. }
  761. } else if (status & SRSR_TEXT) {
  762. ack = sbus_readb(&bp->r3->r[bp->ACK_TINT]);
  763. if (ack == (chip_id | GSVR_IT_TX)){
  764. #ifdef AURORA_INTMSG
  765. printk("TX ACK\n");
  766. #endif
  767. aurora_transmit(bp,chip);
  768. } else {
  769. #ifdef AURORA_INTNORM
  770. printk("aurora%d-%d: Bad transmit ack 0x%02x.\n",
  771. board_No(bp), chip, ack);
  772. #endif
  773. }
  774. } else if (status & SRSR_MEXT) {
  775. ack = sbus_readb(&bp->r3->r[bp->ACK_MINT]);
  776. if (ack == (chip_id | GSVR_IT_MDM)){
  777. #ifdef AURORA_INTMSG
  778. printk("MDM ACK\n");
  779. #endif
  780. aurora_check_modem(bp,chip);
  781. } else {
  782. #ifdef AURORA_INTNORM
  783. printk("aurora%d-%d: Bad modem ack 0x%02x.\n",
  784. board_No(bp), chip, ack);
  785. #endif
  786. }
  787. }
  788. sbus_writeb(0, &bp->r[chip]->r[CD180_EOSRR]);
  789. }
  790. }
  791. #endif
  792. return IRQ_HANDLED;
  793. }
  794. #ifdef AURORA_INT_DEBUG
  795. static void aurora_timer (unsigned long ignored);
  796. static struct timer_list aurora_poll_timer =
  797. TIMER_INITIALIZER(aurora_timer, 0, 0);
  798. static void
  799. aurora_timer (unsigned long ignored)
  800. {
  801. unsigned long flags;
  802. int i;
  803. save_flags(flags); cli();
  804. printk("SRSR: %02x,%02x - ",
  805. sbus_readb(&aurora_board[0].r[0]->r[CD180_SRSR]),
  806. sbus_readb(&aurora_board[0].r[1]->r[CD180_SRSR]));
  807. for (i = 0; i < 4; i++) {
  808. udelay(1);
  809. printk("%02x ",
  810. sbus_readb(&aurora_board[0].r3->r[i]));
  811. }
  812. printk("\n");
  813. aurora_poll_timer.expires = jiffies + 300;
  814. add_timer (&aurora_poll_timer);
  815. restore_flags(flags);
  816. }
  817. #endif
  818. /*
  819. * Routines for open & close processing.
  820. */
  821. /* Called with disabled interrupts */
  822. static int aurora_setup_board(struct Aurora_board * bp)
  823. {
  824. int error;
  825. #ifdef AURORA_ALLIRQ
  826. int i;
  827. for (i = 0; i < AURORA_ALLIRQ; i++) {
  828. error = request_irq(allirq[i]|0x30, aurora_interrupt, SA_SHIRQ,
  829. "sio16", bp);
  830. if (error)
  831. printk(KERN_ERR "IRQ%d request error %d\n",
  832. allirq[i], error);
  833. }
  834. #else
  835. error = request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ,
  836. "sio16", bp);
  837. if (error) {
  838. printk(KERN_ERR "IRQ request error %d\n", error);
  839. return error;
  840. }
  841. #endif
  842. /* Board reset */
  843. sbus_writeb(0, &bp->r0->r);
  844. udelay(1);
  845. if (bp->flags & AURORA_BOARD_TYPE_2) {
  846. /* unknown yet */
  847. } else {
  848. sbus_writeb((AURORA_CFG_ENABLE_IO | AURORA_CFG_ENABLE_IRQ |
  849. (((bp->irq)&0x0f)>>2)),
  850. &bp->r0->r);
  851. }
  852. udelay(10000);
  853. if (aurora_init_CD180(bp,0))error=1;error=0;
  854. if (aurora_init_CD180(bp,1))error++;
  855. if (error == AURORA_NCD180) {
  856. printk(KERN_ERR "Both chips failed initialisation.\n");
  857. return -EIO;
  858. }
  859. #ifdef AURORA_INT_DEBUG
  860. aurora_poll_timer.expires= jiffies + 1;
  861. add_timer(&aurora_poll_timer);
  862. #endif
  863. #ifdef AURORA_DEBUG
  864. printk("aurora_setup_board: end\n");
  865. #endif
  866. return 0;
  867. }
  868. /* Called with disabled interrupts */
  869. static void aurora_shutdown_board(struct Aurora_board *bp)
  870. {
  871. int i;
  872. #ifdef AURORA_DEBUG
  873. printk("aurora_shutdown_board: start\n");
  874. #endif
  875. #ifdef AURORA_INT_DEBUG
  876. del_timer(&aurora_poll_timer);
  877. #endif
  878. #ifdef AURORA_ALLIRQ
  879. for(i=0;i<AURORA_ALLIRQ;i++){
  880. free_irq(allirq[i]|0x30, bp);
  881. /* IRQ_to_board[allirq[i]&0xf] = NULL;*/
  882. }
  883. #else
  884. free_irq(bp->irq|0x30, bp);
  885. /* IRQ_to_board[bp->irq&0xf] = NULL;*/
  886. #endif
  887. /* Drop all DTR's */
  888. for(i=0;i<16;i++){
  889. sbus_writeb(i & 7, &bp->r[i>>3]->r[CD180_CAR]);
  890. udelay(1);
  891. sbus_writeb(0, &bp->r[i>>3]->r[CD180_MSVR]);
  892. udelay(1);
  893. }
  894. /* Board shutdown */
  895. sbus_writeb(0, &bp->r0->r);
  896. #ifdef AURORA_DEBUG
  897. printk("aurora_shutdown_board: end\n");
  898. #endif
  899. }
  900. /* Setting up port characteristics.
  901. * Must be called with disabled interrupts
  902. */
  903. static void aurora_change_speed(struct Aurora_board *bp, struct Aurora_port *port)
  904. {
  905. struct tty_struct *tty;
  906. unsigned long baud;
  907. long tmp;
  908. unsigned char cor1 = 0, cor3 = 0;
  909. unsigned char mcor1 = 0, mcor2 = 0,chip;
  910. #ifdef AURORA_DEBUG
  911. printk("aurora_change_speed: start\n");
  912. #endif
  913. if (!(tty = port->tty) || !tty->termios)
  914. return;
  915. chip = AURORA_CD180(port_No(port));
  916. port->SRER = 0;
  917. port->COR2 = 0;
  918. port->MSVR = MSVR_RTS|MSVR_DTR;
  919. baud = tty_get_baud_rate(tty);
  920. /* Select port on the board */
  921. sbus_writeb(port_No(port) & 7,
  922. &bp->r[chip]->r[CD180_CAR]);
  923. udelay(1);
  924. if (!baud) {
  925. /* Drop DTR & exit */
  926. port->MSVR &= ~(bp->DTR|bp->RTS);
  927. sbus_writeb(port->MSVR,
  928. &bp->r[chip]->r[CD180_MSVR]);
  929. return;
  930. } else {
  931. /* Set DTR on */
  932. port->MSVR |= bp->DTR;
  933. sbus_writeb(port->MSVR,
  934. &bp->r[chip]->r[CD180_MSVR]);
  935. }
  936. /* Now we must calculate some speed dependent things. */
  937. /* Set baud rate for port. */
  938. tmp = (((bp->oscfreq + baud/2) / baud +
  939. CD180_TPC/2) / CD180_TPC);
  940. /* tmp = (bp->oscfreq/7)/baud;
  941. if((tmp%10)>4)tmp=tmp/10+1;else tmp=tmp/10;*/
  942. /* printk("Prescaler period: %d\n",tmp);*/
  943. sbus_writeb((tmp >> 8) & 0xff,
  944. &bp->r[chip]->r[CD180_RBPRH]);
  945. sbus_writeb((tmp >> 8) & 0xff,
  946. &bp->r[chip]->r[CD180_TBPRH]);
  947. sbus_writeb(tmp & 0xff, &bp->r[chip]->r[CD180_RBPRL]);
  948. sbus_writeb(tmp & 0xff, &bp->r[chip]->r[CD180_TBPRL]);
  949. baud = (baud + 5) / 10; /* Estimated CPS */
  950. /* Two timer ticks seems enough to wakeup something like SLIP driver */
  951. tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
  952. port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
  953. SERIAL_XMIT_SIZE - 1 : tmp);
  954. /* Receiver timeout will be transmission time for 1.5 chars */
  955. tmp = (AURORA_TPS + AURORA_TPS/2 + baud/2) / baud;
  956. tmp = (tmp > 0xff) ? 0xff : tmp;
  957. sbus_writeb(tmp, &bp->r[chip]->r[CD180_RTPR]);
  958. switch (C_CSIZE(tty)) {
  959. case CS5:
  960. cor1 |= COR1_5BITS;
  961. break;
  962. case CS6:
  963. cor1 |= COR1_6BITS;
  964. break;
  965. case CS7:
  966. cor1 |= COR1_7BITS;
  967. break;
  968. case CS8:
  969. cor1 |= COR1_8BITS;
  970. break;
  971. }
  972. if (C_CSTOPB(tty))
  973. cor1 |= COR1_2SB;
  974. cor1 |= COR1_IGNORE;
  975. if (C_PARENB(tty)) {
  976. cor1 |= COR1_NORMPAR;
  977. if (C_PARODD(tty))
  978. cor1 |= COR1_ODDP;
  979. if (I_INPCK(tty))
  980. cor1 &= ~COR1_IGNORE;
  981. }
  982. /* Set marking of some errors */
  983. port->mark_mask = RCSR_OE | RCSR_TOUT;
  984. if (I_INPCK(tty))
  985. port->mark_mask |= RCSR_FE | RCSR_PE;
  986. if (I_BRKINT(tty) || I_PARMRK(tty))
  987. port->mark_mask |= RCSR_BREAK;
  988. if (I_IGNPAR(tty))
  989. port->mark_mask &= ~(RCSR_FE | RCSR_PE);
  990. if (I_IGNBRK(tty)) {
  991. port->mark_mask &= ~RCSR_BREAK;
  992. if (I_IGNPAR(tty))
  993. /* Real raw mode. Ignore all */
  994. port->mark_mask &= ~RCSR_OE;
  995. }
  996. /* Enable Hardware Flow Control */
  997. if (C_CRTSCTS(tty)) {
  998. /*#ifdef AURORA_BRAIN_DAMAGED_CTS
  999. port->SRER |= SRER_DSR | SRER_CTS;
  1000. mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
  1001. mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
  1002. tty->hw_stopped = !(aurora_in(bp, CD180_MSVR) & (MSVR_CTS|MSVR_DSR));
  1003. #else*/
  1004. port->COR2 |= COR2_CTSAE;
  1005. /*#endif*/
  1006. if (bp->flags&AURORA_BOARD_DTR_FLOW_OK) {
  1007. mcor1 |= AURORA_RXTH;
  1008. }
  1009. }
  1010. /* Enable Software Flow Control. FIXME: I'm not sure about this */
  1011. /* Some people reported that it works, but I still doubt */
  1012. if (I_IXON(tty)) {
  1013. port->COR2 |= COR2_TXIBE;
  1014. cor3 |= (COR3_FCT | COR3_SCDE);
  1015. if (I_IXANY(tty))
  1016. port->COR2 |= COR2_IXM;
  1017. sbus_writeb(START_CHAR(tty),
  1018. &bp->r[chip]->r[CD180_SCHR1]);
  1019. sbus_writeb(STOP_CHAR(tty),
  1020. &bp->r[chip]->r[CD180_SCHR2]);
  1021. sbus_writeb(START_CHAR(tty),
  1022. &bp->r[chip]->r[CD180_SCHR3]);
  1023. sbus_writeb(STOP_CHAR(tty),
  1024. &bp->r[chip]->r[CD180_SCHR4]);
  1025. }
  1026. if (!C_CLOCAL(tty)) {
  1027. /* Enable CD check */
  1028. port->SRER |= SRER_CD;
  1029. mcor1 |= MCOR1_CDZD;
  1030. mcor2 |= MCOR2_CDOD;
  1031. }
  1032. if (C_CREAD(tty))
  1033. /* Enable receiver */
  1034. port->SRER |= SRER_RXD;
  1035. /* Set input FIFO size (1-8 bytes) */
  1036. cor3 |= AURORA_RXFIFO;
  1037. /* Setting up CD180 channel registers */
  1038. sbus_writeb(cor1, &bp->r[chip]->r[CD180_COR1]);
  1039. sbus_writeb(port->COR2, &bp->r[chip]->r[CD180_COR2]);
  1040. sbus_writeb(cor3, &bp->r[chip]->r[CD180_COR3]);
  1041. /* Make CD180 know about registers change */
  1042. aurora_wait_CCR(bp->r[chip]);
  1043. sbus_writeb(CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3,
  1044. &bp->r[chip]->r[CD180_CCR]);
  1045. /* Setting up modem option registers */
  1046. sbus_writeb(mcor1, &bp->r[chip]->r[CD180_MCOR1]);
  1047. sbus_writeb(mcor2, &bp->r[chip]->r[CD180_MCOR2]);
  1048. /* Enable CD180 transmitter & receiver */
  1049. aurora_wait_CCR(bp->r[chip]);
  1050. sbus_writeb(CCR_TXEN | CCR_RXEN, &bp->r[chip]->r[CD180_CCR]);
  1051. /* Enable interrupts */
  1052. sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
  1053. /* And finally set RTS on */
  1054. sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
  1055. #ifdef AURORA_DEBUG
  1056. printk("aurora_change_speed: end\n");
  1057. #endif
  1058. }
  1059. /* Must be called with interrupts enabled */
  1060. static int aurora_setup_port(struct Aurora_board *bp, struct Aurora_port *port)
  1061. {
  1062. unsigned long flags;
  1063. #ifdef AURORA_DEBUG
  1064. printk("aurora_setup_port: start %d\n",port_No(port));
  1065. #endif
  1066. if (port->flags & ASYNC_INITIALIZED)
  1067. return 0;
  1068. if (!port->xmit_buf) {
  1069. /* We may sleep in get_zeroed_page() */
  1070. unsigned long tmp;
  1071. if (!(tmp = get_zeroed_page(GFP_KERNEL)))
  1072. return -ENOMEM;
  1073. if (port->xmit_buf) {
  1074. free_page(tmp);
  1075. return -ERESTARTSYS;
  1076. }
  1077. port->xmit_buf = (unsigned char *) tmp;
  1078. }
  1079. save_flags(flags); cli();
  1080. if (port->tty)
  1081. clear_bit(TTY_IO_ERROR, &port->tty->flags);
  1082. #ifdef MODULE
  1083. if ((port->count == 1) && ((++bp->count) == 1))
  1084. bp->flags |= AURORA_BOARD_ACTIVE;
  1085. #endif
  1086. port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
  1087. aurora_change_speed(bp, port);
  1088. port->flags |= ASYNC_INITIALIZED;
  1089. restore_flags(flags);
  1090. #ifdef AURORA_DEBUG
  1091. printk("aurora_setup_port: end\n");
  1092. #endif
  1093. return 0;
  1094. }
  1095. /* Must be called with interrupts disabled */
  1096. static void aurora_shutdown_port(struct Aurora_board *bp, struct Aurora_port *port)
  1097. {
  1098. struct tty_struct *tty;
  1099. unsigned char chip;
  1100. #ifdef AURORA_DEBUG
  1101. printk("aurora_shutdown_port: start\n");
  1102. #endif
  1103. if (!(port->flags & ASYNC_INITIALIZED))
  1104. return;
  1105. chip = AURORA_CD180(port_No(port));
  1106. #ifdef AURORA_REPORT_OVERRUN
  1107. printk("aurora%d: port %d: Total %ld overruns were detected.\n",
  1108. board_No(bp), port_No(port), port->overrun);
  1109. #endif
  1110. #ifdef AURORA_REPORT_FIFO
  1111. {
  1112. int i;
  1113. printk("aurora%d: port %d: FIFO hits [ ",
  1114. board_No(bp), port_No(port));
  1115. for (i = 0; i < 10; i++) {
  1116. printk("%ld ", port->hits[i]);
  1117. }
  1118. printk("].\n");
  1119. }
  1120. #endif
  1121. if (port->xmit_buf) {
  1122. free_page((unsigned long) port->xmit_buf);
  1123. port->xmit_buf = NULL;
  1124. }
  1125. if (!(tty = port->tty) || C_HUPCL(tty)) {
  1126. /* Drop DTR */
  1127. port->MSVR &= ~(bp->DTR|bp->RTS);
  1128. sbus_writeb(port->MSVR,
  1129. &bp->r[chip]->r[CD180_MSVR]);
  1130. }
  1131. /* Select port */
  1132. sbus_writeb(port_No(port) & 7,
  1133. &bp->r[chip]->r[CD180_CAR]);
  1134. udelay(1);
  1135. /* Reset port */
  1136. aurora_wait_CCR(bp->r[chip]);
  1137. sbus_writeb(CCR_SOFTRESET, &bp->r[chip]->r[CD180_CCR]);
  1138. /* Disable all interrupts from this port */
  1139. port->SRER = 0;
  1140. sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
  1141. if (tty)
  1142. set_bit(TTY_IO_ERROR, &tty->flags);
  1143. port->flags &= ~ASYNC_INITIALIZED;
  1144. #ifdef MODULE
  1145. if (--bp->count < 0) {
  1146. printk(KERN_DEBUG "aurora%d: aurora_shutdown_port: "
  1147. "bad board count: %d\n",
  1148. board_No(bp), bp->count);
  1149. bp->count = 0;
  1150. }
  1151. if (!bp->count)
  1152. bp->flags &= ~AURORA_BOARD_ACTIVE;
  1153. #endif
  1154. #ifdef AURORA_DEBUG
  1155. printk("aurora_shutdown_port: end\n");
  1156. #endif
  1157. }
  1158. static int block_til_ready(struct tty_struct *tty, struct file * filp,
  1159. struct Aurora_port *port)
  1160. {
  1161. DECLARE_WAITQUEUE(wait, current);
  1162. struct Aurora_board *bp = port_Board(port);
  1163. int retval;
  1164. int do_clocal = 0;
  1165. int CD;
  1166. unsigned char chip;
  1167. #ifdef AURORA_DEBUG
  1168. printk("block_til_ready: start\n");
  1169. #endif
  1170. chip = AURORA_CD180(port_No(port));
  1171. /* If the device is in the middle of being closed, then block
  1172. * until it's done, and then try again.
  1173. */
  1174. if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
  1175. interruptible_sleep_on(&port->close_wait);
  1176. if (port->flags & ASYNC_HUP_NOTIFY)
  1177. return -EAGAIN;
  1178. else
  1179. return -ERESTARTSYS;
  1180. }
  1181. /* If non-blocking mode is set, or the port is not enabled,
  1182. * then make the check up front and then exit.
  1183. */
  1184. if ((filp->f_flags & O_NONBLOCK) ||
  1185. (tty->flags & (1 << TTY_IO_ERROR))) {
  1186. port->flags |= ASYNC_NORMAL_ACTIVE;
  1187. return 0;
  1188. }
  1189. if (C_CLOCAL(tty))
  1190. do_clocal = 1;
  1191. /* Block waiting for the carrier detect and the line to become
  1192. * free (i.e., not in use by the callout). While we are in
  1193. * this loop, info->count is dropped by one, so that
  1194. * rs_close() knows when to free things. We restore it upon
  1195. * exit, either normal or abnormal.
  1196. */
  1197. retval = 0;
  1198. add_wait_queue(&port->open_wait, &wait);
  1199. cli();
  1200. if (!tty_hung_up_p(filp))
  1201. port->count--;
  1202. sti();
  1203. port->blocked_open++;
  1204. while (1) {
  1205. cli();
  1206. sbus_writeb(port_No(port) & 7,
  1207. &bp->r[chip]->r[CD180_CAR]);
  1208. udelay(1);
  1209. CD = sbus_readb(&bp->r[chip]->r[CD180_MSVR]) & MSVR_CD;
  1210. port->MSVR=bp->RTS;
  1211. /* auto drops DTR */
  1212. sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
  1213. sti();
  1214. set_current_state(TASK_INTERRUPTIBLE);
  1215. if (tty_hung_up_p(filp) ||
  1216. !(port->flags & ASYNC_INITIALIZED)) {
  1217. if (port->flags & ASYNC_HUP_NOTIFY)
  1218. retval = -EAGAIN;
  1219. else
  1220. retval = -ERESTARTSYS;
  1221. break;
  1222. }
  1223. if (!(port->flags & ASYNC_CLOSING) &&
  1224. (do_clocal || CD))
  1225. break;
  1226. if (signal_pending(current)) {
  1227. retval = -ERESTARTSYS;
  1228. break;
  1229. }
  1230. schedule();
  1231. }
  1232. current->state = TASK_RUNNING;
  1233. remove_wait_queue(&port->open_wait, &wait);
  1234. if (!tty_hung_up_p(filp))
  1235. port->count++;
  1236. port->blocked_open--;
  1237. if (retval)
  1238. return retval;
  1239. port->flags |= ASYNC_NORMAL_ACTIVE;
  1240. #ifdef AURORA_DEBUG
  1241. printk("block_til_ready: end\n");
  1242. #endif
  1243. return 0;
  1244. }
  1245. static int aurora_open(struct tty_struct * tty, struct file * filp)
  1246. {
  1247. int board;
  1248. int error;
  1249. struct Aurora_port * port;
  1250. struct Aurora_board * bp;
  1251. unsigned long flags;
  1252. #ifdef AURORA_DEBUG
  1253. printk("aurora_open: start\n");
  1254. #endif
  1255. board = AURORA_BOARD(tty->index);
  1256. if (board > AURORA_NBOARD ||
  1257. !(aurora_board[board].flags & AURORA_BOARD_PRESENT)) {
  1258. #ifdef AURORA_DEBUG
  1259. printk("aurora_open: error board %d present %d\n",
  1260. board, aurora_board[board].flags & AURORA_BOARD_PRESENT);
  1261. #endif
  1262. return -ENODEV;
  1263. }
  1264. bp = &aurora_board[board];
  1265. port = aurora_port + board * AURORA_NPORT * AURORA_NCD180 + AURORA_PORT(tty->index);
  1266. if ((aurora_paranoia_check(port, tty->name, "aurora_open")) {
  1267. #ifdef AURORA_DEBUG
  1268. printk("aurora_open: error paranoia check\n");
  1269. #endif
  1270. return -ENODEV;
  1271. }
  1272. port->count++;
  1273. tty->driver_data = port;
  1274. port->tty = tty;
  1275. if ((error = aurora_setup_port(bp, port))) {
  1276. #ifdef AURORA_DEBUG
  1277. printk("aurora_open: error aurora_setup_port ret %d\n",error);
  1278. #endif
  1279. return error;
  1280. }
  1281. if ((error = block_til_ready(tty, filp, port))) {
  1282. #ifdef AURORA_DEBUG
  1283. printk("aurora_open: error block_til_ready ret %d\n",error);
  1284. #endif
  1285. return error;
  1286. }
  1287. #ifdef AURORA_DEBUG
  1288. printk("aurora_open: end\n");
  1289. #endif
  1290. return 0;
  1291. }
  1292. static void aurora_close(struct tty_struct * tty, struct file * filp)
  1293. {
  1294. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1295. struct Aurora_board *bp;
  1296. unsigned long flags;
  1297. unsigned long timeout;
  1298. unsigned char chip;
  1299. #ifdef AURORA_DEBUG
  1300. printk("aurora_close: start\n");
  1301. #endif
  1302. if (!port || (aurora_paranoia_check(port, tty->name, "close"))
  1303. return;
  1304. chip = AURORA_CD180(port_No(port));
  1305. save_flags(flags); cli();
  1306. if (tty_hung_up_p(filp)) {
  1307. restore_flags(flags);
  1308. return;
  1309. }
  1310. bp = port_Board(port);
  1311. if ((tty->count == 1) && (port->count != 1)) {
  1312. printk(KERN_DEBUG "aurora%d: aurora_close: bad port count; "
  1313. "tty->count is 1, port count is %d\n",
  1314. board_No(bp), port->count);
  1315. port->count = 1;
  1316. }
  1317. if (--port->count < 0) {
  1318. printk(KERN_DEBUG "aurora%d: aurora_close: bad port "
  1319. "count for tty%d: %d\n",
  1320. board_No(bp), port_No(port), port->count);
  1321. port->count = 0;
  1322. }
  1323. if (port->count) {
  1324. restore_flags(flags);
  1325. return;
  1326. }
  1327. port->flags |= ASYNC_CLOSING;
  1328. /* Now we wait for the transmit buffer to clear; and we notify
  1329. * the line discipline to only process XON/XOFF characters.
  1330. */
  1331. tty->closing = 1;
  1332. if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE){
  1333. #ifdef AURORA_DEBUG
  1334. printk("aurora_close: waiting to flush...\n");
  1335. #endif
  1336. tty_wait_until_sent(tty, port->closing_wait);
  1337. }
  1338. /* At this point we stop accepting input. To do this, we
  1339. * disable the receive line status interrupts, and tell the
  1340. * interrupt driver to stop checking the data ready bit in the
  1341. * line status register.
  1342. */
  1343. port->SRER &= ~SRER_RXD;
  1344. if (port->flags & ASYNC_INITIALIZED) {
  1345. port->SRER &= ~SRER_TXRDY;
  1346. port->SRER |= SRER_TXEMPTY;
  1347. sbus_writeb(port_No(port) & 7,
  1348. &bp->r[chip]->r[CD180_CAR]);
  1349. udelay(1);
  1350. sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
  1351. /*
  1352. * Before we drop DTR, make sure the UART transmitter
  1353. * has completely drained; this is especially
  1354. * important if there is a transmit FIFO!
  1355. */
  1356. timeout = jiffies+HZ;
  1357. while(port->SRER & SRER_TXEMPTY) {
  1358. msleep_interruptible(jiffies_to_msecs(port->timeout));
  1359. if (time_after(jiffies, timeout))
  1360. break;
  1361. }
  1362. }
  1363. #ifdef AURORA_DEBUG
  1364. printk("aurora_close: shutdown_port\n");
  1365. #endif
  1366. aurora_shutdown_port(bp, port);
  1367. if (tty->driver->flush_buffer)
  1368. tty->driver->flush_buffer(tty);
  1369. tty_ldisc_flush(tty);
  1370. tty->closing = 0;
  1371. port->event = 0;
  1372. port->tty = 0;
  1373. if (port->blocked_open) {
  1374. if (port->close_delay) {
  1375. msleep_interruptible(jiffies_to_msecs(port->close_delay));
  1376. }
  1377. wake_up_interruptible(&port->open_wait);
  1378. }
  1379. port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  1380. wake_up_interruptible(&port->close_wait);
  1381. restore_flags(flags);
  1382. #ifdef AURORA_DEBUG
  1383. printk("aurora_close: end\n");
  1384. #endif
  1385. }
  1386. static int aurora_write(struct tty_struct * tty,
  1387. const unsigned char *buf, int count)
  1388. {
  1389. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1390. struct Aurora_board *bp;
  1391. int c, total = 0;
  1392. unsigned long flags;
  1393. unsigned char chip;
  1394. #ifdef AURORA_DEBUG
  1395. printk("aurora_write: start %d\n",count);
  1396. #endif
  1397. if ((aurora_paranoia_check(port, tty->name, "aurora_write"))
  1398. return 0;
  1399. chip = AURORA_CD180(port_No(port));
  1400. bp = port_Board(port);
  1401. if (!tty || !port->xmit_buf || !tmp_buf)
  1402. return 0;
  1403. save_flags(flags);
  1404. while (1) {
  1405. cli();
  1406. c = min(count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
  1407. SERIAL_XMIT_SIZE - port->xmit_head));
  1408. if (c <= 0) {
  1409. restore_flags(flags);
  1410. break;
  1411. }
  1412. memcpy(port->xmit_buf + port->xmit_head, buf, c);
  1413. port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
  1414. port->xmit_cnt += c;
  1415. restore_flags(flags);
  1416. buf += c;
  1417. count -= c;
  1418. total += c;
  1419. }
  1420. cli();
  1421. if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
  1422. !(port->SRER & SRER_TXRDY)) {
  1423. port->SRER |= SRER_TXRDY;
  1424. sbus_writeb(port_No(port) & 7,
  1425. &bp->r[chip]->r[CD180_CAR]);
  1426. udelay(1);
  1427. sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
  1428. }
  1429. restore_flags(flags);
  1430. #ifdef AURORA_DEBUG
  1431. printk("aurora_write: end %d\n",total);
  1432. #endif
  1433. return total;
  1434. }
  1435. static void aurora_put_char(struct tty_struct * tty, unsigned char ch)
  1436. {
  1437. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1438. unsigned long flags;
  1439. #ifdef AURORA_DEBUG
  1440. printk("aurora_put_char: start %c\n",ch);
  1441. #endif
  1442. if ((aurora_paranoia_check(port, tty->name, "aurora_put_char"))
  1443. return;
  1444. if (!tty || !port->xmit_buf)
  1445. return;
  1446. save_flags(flags); cli();
  1447. if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
  1448. restore_flags(flags);
  1449. return;
  1450. }
  1451. port->xmit_buf[port->xmit_head++] = ch;
  1452. port->xmit_head &= SERIAL_XMIT_SIZE - 1;
  1453. port->xmit_cnt++;
  1454. restore_flags(flags);
  1455. #ifdef AURORA_DEBUG
  1456. printk("aurora_put_char: end\n");
  1457. #endif
  1458. }
  1459. static void aurora_flush_chars(struct tty_struct * tty)
  1460. {
  1461. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1462. unsigned long flags;
  1463. unsigned char chip;
  1464. /*#ifdef AURORA_DEBUG
  1465. printk("aurora_flush_chars: start\n");
  1466. #endif*/
  1467. if ((aurora_paranoia_check(port, tty->name, "aurora_flush_chars"))
  1468. return;
  1469. chip = AURORA_CD180(port_No(port));
  1470. if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
  1471. !port->xmit_buf)
  1472. return;
  1473. save_flags(flags); cli();
  1474. port->SRER |= SRER_TXRDY;
  1475. sbus_writeb(port_No(port) & 7,
  1476. &port_Board(port)->r[chip]->r[CD180_CAR]);
  1477. udelay(1);
  1478. sbus_writeb(port->SRER,
  1479. &port_Board(port)->r[chip]->r[CD180_SRER]);
  1480. restore_flags(flags);
  1481. /*#ifdef AURORA_DEBUG
  1482. printk("aurora_flush_chars: end\n");
  1483. #endif*/
  1484. }
  1485. static int aurora_write_room(struct tty_struct * tty)
  1486. {
  1487. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1488. int ret;
  1489. #ifdef AURORA_DEBUG
  1490. printk("aurora_write_room: start\n");
  1491. #endif
  1492. if ((aurora_paranoia_check(port, tty->name, "aurora_write_room"))
  1493. return 0;
  1494. ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
  1495. if (ret < 0)
  1496. ret = 0;
  1497. #ifdef AURORA_DEBUG
  1498. printk("aurora_write_room: end\n");
  1499. #endif
  1500. return ret;
  1501. }
  1502. static int aurora_chars_in_buffer(struct tty_struct *tty)
  1503. {
  1504. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1505. if ((aurora_paranoia_check(port, tty->name, "aurora_chars_in_buffer"))
  1506. return 0;
  1507. return port->xmit_cnt;
  1508. }
  1509. static void aurora_flush_buffer(struct tty_struct *tty)
  1510. {
  1511. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1512. unsigned long flags;
  1513. #ifdef AURORA_DEBUG
  1514. printk("aurora_flush_buffer: start\n");
  1515. #endif
  1516. if ((aurora_paranoia_check(port, tty->name, "aurora_flush_buffer"))
  1517. return;
  1518. save_flags(flags); cli();
  1519. port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
  1520. restore_flags(flags);
  1521. tty_wakeup(tty);
  1522. #ifdef AURORA_DEBUG
  1523. printk("aurora_flush_buffer: end\n");
  1524. #endif
  1525. }
  1526. static int aurora_tiocmget(struct tty_struct *tty, struct file *file)
  1527. {
  1528. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1529. struct Aurora_board * bp;
  1530. unsigned char status,chip;
  1531. unsigned int result;
  1532. unsigned long flags;
  1533. #ifdef AURORA_DEBUG
  1534. printk("aurora_get_modem_info: start\n");
  1535. #endif
  1536. if ((aurora_paranoia_check(port, tty->name, __FUNCTION__))
  1537. return -ENODEV;
  1538. chip = AURORA_CD180(port_No(port));
  1539. bp = port_Board(port);
  1540. save_flags(flags); cli();
  1541. sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
  1542. udelay(1);
  1543. status = sbus_readb(&bp->r[chip]->r[CD180_MSVR]);
  1544. result = 0/*bp->r[chip]->r[AURORA_RI] & (1u << port_No(port)) ? 0 : TIOCM_RNG*/;
  1545. restore_flags(flags);
  1546. result |= ((status & bp->RTS) ? TIOCM_RTS : 0)
  1547. | ((status & bp->DTR) ? TIOCM_DTR : 0)
  1548. | ((status & MSVR_CD) ? TIOCM_CAR : 0)
  1549. | ((status & MSVR_DSR) ? TIOCM_DSR : 0)
  1550. | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
  1551. #ifdef AURORA_DEBUG
  1552. printk("aurora_get_modem_info: end\n");
  1553. #endif
  1554. return result;
  1555. }
  1556. static int aurora_tiocmset(struct tty_struct *tty, struct file *file,
  1557. unsigned int set, unsigned int clear)
  1558. {
  1559. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1560. unsigned int arg;
  1561. unsigned long flags;
  1562. struct Aurora_board *bp = port_Board(port);
  1563. unsigned char chip;
  1564. #ifdef AURORA_DEBUG
  1565. printk("aurora_set_modem_info: start\n");
  1566. #endif
  1567. if ((aurora_paranoia_check(port, tty->name, __FUNCTION__))
  1568. return -ENODEV;
  1569. chip = AURORA_CD180(port_No(port));
  1570. save_flags(flags); cli();
  1571. if (set & TIOCM_RTS)
  1572. port->MSVR |= bp->RTS;
  1573. if (set & TIOCM_DTR)
  1574. port->MSVR |= bp->DTR;
  1575. if (clear & TIOCM_RTS)
  1576. port->MSVR &= ~bp->RTS;
  1577. if (clear & TIOCM_DTR)
  1578. port->MSVR &= ~bp->DTR;
  1579. sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
  1580. udelay(1);
  1581. sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
  1582. restore_flags(flags);
  1583. #ifdef AURORA_DEBUG
  1584. printk("aurora_set_modem_info: end\n");
  1585. #endif
  1586. return 0;
  1587. }
  1588. static void aurora_send_break(struct Aurora_port * port, unsigned long length)
  1589. {
  1590. struct Aurora_board *bp = port_Board(port);
  1591. unsigned long flags;
  1592. unsigned char chip;
  1593. #ifdef AURORA_DEBUG
  1594. printk("aurora_send_break: start\n");
  1595. #endif
  1596. chip = AURORA_CD180(port_No(port));
  1597. save_flags(flags); cli();
  1598. port->break_length = AURORA_TPS / HZ * length;
  1599. port->COR2 |= COR2_ETC;
  1600. port->SRER |= SRER_TXRDY;
  1601. sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
  1602. udelay(1);
  1603. sbus_writeb(port->COR2, &bp->r[chip]->r[CD180_COR2]);
  1604. sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
  1605. aurora_wait_CCR(bp->r[chip]);
  1606. sbus_writeb(CCR_CORCHG2, &bp->r[chip]->r[CD180_CCR]);
  1607. aurora_wait_CCR(bp->r[chip]);
  1608. restore_flags(flags);
  1609. #ifdef AURORA_DEBUG
  1610. printk("aurora_send_break: end\n");
  1611. #endif
  1612. }
  1613. static int aurora_set_serial_info(struct Aurora_port * port,
  1614. struct serial_struct * newinfo)
  1615. {
  1616. struct serial_struct tmp;
  1617. struct Aurora_board *bp = port_Board(port);
  1618. int change_speed;
  1619. unsigned long flags;
  1620. #ifdef AURORA_DEBUG
  1621. printk("aurora_set_serial_info: start\n");
  1622. #endif
  1623. if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
  1624. return -EFAULT;
  1625. #if 0
  1626. if ((tmp.irq != bp->irq) ||
  1627. (tmp.port != bp->base) ||
  1628. (tmp.type != PORT_CIRRUS) ||
  1629. (tmp.baud_base != (bp->oscfreq + CD180_TPC/2) / CD180_TPC) ||
  1630. (tmp.custom_divisor != 0) ||
  1631. (tmp.xmit_fifo_size != CD180_NFIFO) ||
  1632. (tmp.flags & ~AURORA_LEGAL_FLAGS))
  1633. return -EINVAL;
  1634. #endif
  1635. change_speed = ((port->flags & ASYNC_SPD_MASK) !=
  1636. (tmp.flags & ASYNC_SPD_MASK));
  1637. if (!capable(CAP_SYS_ADMIN)) {
  1638. if ((tmp.close_delay != port->close_delay) ||
  1639. (tmp.closing_wait != port->closing_wait) ||
  1640. ((tmp.flags & ~ASYNC_USR_MASK) !=
  1641. (port->flags & ~ASYNC_USR_MASK)))
  1642. return -EPERM;
  1643. port->flags = ((port->flags & ~ASYNC_USR_MASK) |
  1644. (tmp.flags & ASYNC_USR_MASK));
  1645. } else {
  1646. port->flags = ((port->flags & ~ASYNC_FLAGS) |
  1647. (tmp.flags & ASYNC_FLAGS));
  1648. port->close_delay = tmp.close_delay;
  1649. port->closing_wait = tmp.closing_wait;
  1650. }
  1651. if (change_speed) {
  1652. save_flags(flags); cli();
  1653. aurora_change_speed(bp, port);
  1654. restore_flags(flags);
  1655. }
  1656. #ifdef AURORA_DEBUG
  1657. printk("aurora_set_serial_info: end\n");
  1658. #endif
  1659. return 0;
  1660. }
  1661. extern int aurora_get_serial_info(struct Aurora_port * port,
  1662. struct serial_struct * retinfo)
  1663. {
  1664. struct serial_struct tmp;
  1665. struct Aurora_board *bp = port_Board(port);
  1666. #ifdef AURORA_DEBUG
  1667. printk("aurora_get_serial_info: start\n");
  1668. #endif
  1669. if (!access_ok(VERIFY_WRITE, (void *) retinfo, sizeof(tmp)))
  1670. return -EFAULT;
  1671. memset(&tmp, 0, sizeof(tmp));
  1672. tmp.type = PORT_CIRRUS;
  1673. tmp.line = port - aurora_port;
  1674. tmp.port = 0;
  1675. tmp.irq = bp->irq;
  1676. tmp.flags = port->flags;
  1677. tmp.baud_base = (bp->oscfreq + CD180_TPC/2) / CD180_TPC;
  1678. tmp.close_delay = port->close_delay * HZ/100;
  1679. tmp.closing_wait = port->closing_wait * HZ/100;
  1680. tmp.xmit_fifo_size = CD180_NFIFO;
  1681. copy_to_user(retinfo, &tmp, sizeof(tmp));
  1682. #ifdef AURORA_DEBUG
  1683. printk("aurora_get_serial_info: end\n");
  1684. #endif
  1685. return 0;
  1686. }
  1687. static int aurora_ioctl(struct tty_struct * tty, struct file * filp,
  1688. unsigned int cmd, unsigned long arg)
  1689. {
  1690. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1691. int retval;
  1692. #ifdef AURORA_DEBUG
  1693. printk("aurora_ioctl: start\n");
  1694. #endif
  1695. if ((aurora_paranoia_check(port, tty->name, "aurora_ioctl"))
  1696. return -ENODEV;
  1697. switch (cmd) {
  1698. case TCSBRK: /* SVID version: non-zero arg --> no break */
  1699. retval = tty_check_change(tty);
  1700. if (retval)
  1701. return retval;
  1702. tty_wait_until_sent(tty, 0);
  1703. if (!arg)
  1704. aurora_send_break(port, HZ/4); /* 1/4 second */
  1705. return 0;
  1706. case TCSBRKP: /* support for POSIX tcsendbreak() */
  1707. retval = tty_check_change(tty);
  1708. if (retval)
  1709. return retval;
  1710. tty_wait_until_sent(tty, 0);
  1711. aurora_send_break(port, arg ? arg*(HZ/10) : HZ/4);
  1712. return 0;
  1713. case TIOCGSOFTCAR:
  1714. return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *)arg);
  1715. case TIOCSSOFTCAR:
  1716. if (get_user(arg,(unsigned long *)arg))
  1717. return -EFAULT;
  1718. tty->termios->c_cflag =
  1719. ((tty->termios->c_cflag & ~CLOCAL) |
  1720. (arg ? CLOCAL : 0));
  1721. return 0;
  1722. case TIOCGSERIAL:
  1723. return aurora_get_serial_info(port, (struct serial_struct *) arg);
  1724. case TIOCSSERIAL:
  1725. return aurora_set_serial_info(port, (struct serial_struct *) arg);
  1726. default:
  1727. return -ENOIOCTLCMD;
  1728. };
  1729. #ifdef AURORA_DEBUG
  1730. printk("aurora_ioctl: end\n");
  1731. #endif
  1732. return 0;
  1733. }
  1734. static void aurora_throttle(struct tty_struct * tty)
  1735. {
  1736. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1737. struct Aurora_board *bp;
  1738. unsigned long flags;
  1739. unsigned char chip;
  1740. #ifdef AURORA_DEBUG
  1741. printk("aurora_throttle: start\n");
  1742. #endif
  1743. if ((aurora_paranoia_check(port, tty->name, "aurora_throttle"))
  1744. return;
  1745. bp = port_Board(port);
  1746. chip = AURORA_CD180(port_No(port));
  1747. save_flags(flags); cli();
  1748. port->MSVR &= ~bp->RTS;
  1749. sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
  1750. udelay(1);
  1751. if (I_IXOFF(tty)) {
  1752. aurora_wait_CCR(bp->r[chip]);
  1753. sbus_writeb(CCR_SSCH2, &bp->r[chip]->r[CD180_CCR]);
  1754. aurora_wait_CCR(bp->r[chip]);
  1755. }
  1756. sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
  1757. restore_flags(flags);
  1758. #ifdef AURORA_DEBUG
  1759. printk("aurora_throttle: end\n");
  1760. #endif
  1761. }
  1762. static void aurora_unthrottle(struct tty_struct * tty)
  1763. {
  1764. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1765. struct Aurora_board *bp;
  1766. unsigned long flags;
  1767. unsigned char chip;
  1768. #ifdef AURORA_DEBUG
  1769. printk("aurora_unthrottle: start\n");
  1770. #endif
  1771. if ((aurora_paranoia_check(port, tty->name, "aurora_unthrottle"))
  1772. return;
  1773. bp = port_Board(port);
  1774. chip = AURORA_CD180(port_No(port));
  1775. save_flags(flags); cli();
  1776. port->MSVR |= bp->RTS;
  1777. sbus_writeb(port_No(port) & 7,
  1778. &bp->r[chip]->r[CD180_CAR]);
  1779. udelay(1);
  1780. if (I_IXOFF(tty)) {
  1781. aurora_wait_CCR(bp->r[chip]);
  1782. sbus_writeb(CCR_SSCH1,
  1783. &bp->r[chip]->r[CD180_CCR]);
  1784. aurora_wait_CCR(bp->r[chip]);
  1785. }
  1786. sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
  1787. restore_flags(flags);
  1788. #ifdef AURORA_DEBUG
  1789. printk("aurora_unthrottle: end\n");
  1790. #endif
  1791. }
  1792. static void aurora_stop(struct tty_struct * tty)
  1793. {
  1794. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1795. struct Aurora_board *bp;
  1796. unsigned long flags;
  1797. unsigned char chip;
  1798. #ifdef AURORA_DEBUG
  1799. printk("aurora_stop: start\n");
  1800. #endif
  1801. if ((aurora_paranoia_check(port, tty->name, "aurora_stop"))
  1802. return;
  1803. bp = port_Board(port);
  1804. chip = AURORA_CD180(port_No(port));
  1805. save_flags(flags); cli();
  1806. port->SRER &= ~SRER_TXRDY;
  1807. sbus_writeb(port_No(port) & 7,
  1808. &bp->r[chip]->r[CD180_CAR]);
  1809. udelay(1);
  1810. sbus_writeb(port->SRER,
  1811. &bp->r[chip]->r[CD180_SRER]);
  1812. restore_flags(flags);
  1813. #ifdef AURORA_DEBUG
  1814. printk("aurora_stop: end\n");
  1815. #endif
  1816. }
  1817. static void aurora_start(struct tty_struct * tty)
  1818. {
  1819. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1820. struct Aurora_board *bp;
  1821. unsigned long flags;
  1822. unsigned char chip;
  1823. #ifdef AURORA_DEBUG
  1824. printk("aurora_start: start\n");
  1825. #endif
  1826. if ((aurora_paranoia_check(port, tty->name, "aurora_start"))
  1827. return;
  1828. bp = port_Board(port);
  1829. chip = AURORA_CD180(port_No(port));
  1830. save_flags(flags); cli();
  1831. if (port->xmit_cnt && port->xmit_buf && !(port->SRER & SRER_TXRDY)) {
  1832. port->SRER |= SRER_TXRDY;
  1833. sbus_writeb(port_No(port) & 7,
  1834. &bp->r[chip]->r[CD180_CAR]);
  1835. udelay(1);
  1836. sbus_writeb(port->SRER,
  1837. &bp->r[chip]->r[CD180_SRER]);
  1838. }
  1839. restore_flags(flags);
  1840. #ifdef AURORA_DEBUG
  1841. printk("aurora_start: end\n");
  1842. #endif
  1843. }
  1844. /*
  1845. * This routine is called from the scheduler tqueue when the interrupt
  1846. * routine has signalled that a hangup has occurred. The path of
  1847. * hangup processing is:
  1848. *
  1849. * serial interrupt routine -> (scheduler tqueue) ->
  1850. * do_aurora_hangup() -> tty->hangup() -> aurora_hangup()
  1851. *
  1852. */
  1853. static void do_aurora_hangup(void *private_)
  1854. {
  1855. struct Aurora_port *port = (struct Aurora_port *) private_;
  1856. struct tty_struct *tty;
  1857. #ifdef AURORA_DEBUG
  1858. printk("do_aurora_hangup: start\n");
  1859. #endif
  1860. tty = port->tty;
  1861. if (tty != NULL) {
  1862. tty_hangup(tty); /* FIXME: module removal race - AKPM */
  1863. #ifdef AURORA_DEBUG
  1864. printk("do_aurora_hangup: end\n");
  1865. #endif
  1866. }
  1867. }
  1868. static void aurora_hangup(struct tty_struct * tty)
  1869. {
  1870. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1871. struct Aurora_board *bp;
  1872. #ifdef AURORA_DEBUG
  1873. printk("aurora_hangup: start\n");
  1874. #endif
  1875. if ((aurora_paranoia_check(port, tty->name, "aurora_hangup"))
  1876. return;
  1877. bp = port_Board(port);
  1878. aurora_shutdown_port(bp, port);
  1879. port->event = 0;
  1880. port->count = 0;
  1881. port->flags &= ~ASYNC_NORMAL_ACTIVE;
  1882. port->tty = 0;
  1883. wake_up_interruptible(&port->open_wait);
  1884. #ifdef AURORA_DEBUG
  1885. printk("aurora_hangup: end\n");
  1886. #endif
  1887. }
  1888. static void aurora_set_termios(struct tty_struct * tty, struct termios * old_termios)
  1889. {
  1890. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1891. unsigned long flags;
  1892. #ifdef AURORA_DEBUG
  1893. printk("aurora_set_termios: start\n");
  1894. #endif
  1895. if ((aurora_paranoia_check(port, tty->name, "aurora_set_termios"))
  1896. return;
  1897. if (tty->termios->c_cflag == old_termios->c_cflag &&
  1898. tty->termios->c_iflag == old_termios->c_iflag)
  1899. return;
  1900. save_flags(flags); cli();
  1901. aurora_change_speed(port_Board(port), port);
  1902. restore_flags(flags);
  1903. if ((old_termios->c_cflag & CRTSCTS) &&
  1904. !(tty->termios->c_cflag & CRTSCTS)) {
  1905. tty->hw_stopped = 0;
  1906. aurora_start(tty);
  1907. }
  1908. #ifdef AURORA_DEBUG
  1909. printk("aurora_set_termios: end\n");
  1910. #endif
  1911. }
  1912. static void do_aurora_bh(void)
  1913. {
  1914. run_task_queue(&tq_aurora);
  1915. }
  1916. static void do_softint(void *private_)
  1917. {
  1918. struct Aurora_port *port = (struct Aurora_port *) private_;
  1919. struct tty_struct *tty;
  1920. #ifdef AURORA_DEBUG
  1921. printk("do_softint: start\n");
  1922. #endif
  1923. tty = port->tty;
  1924. if (tty == NULL)
  1925. return;
  1926. if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) {
  1927. tty_wakeup(tty);
  1928. }
  1929. #ifdef AURORA_DEBUG
  1930. printk("do_softint: end\n");
  1931. #endif
  1932. }
  1933. static struct tty_operations aurora_ops = {
  1934. .open = aurora_open,
  1935. .close = aurora_close,
  1936. .write = aurora_write,
  1937. .put_char = aurora_put_char,
  1938. .flush_chars = aurora_flush_chars,
  1939. .write_room = aurora_write_room,
  1940. .chars_in_buffer = aurora_chars_in_buffer,
  1941. .flush_buffer = aurora_flush_buffer,
  1942. .ioctl = aurora_ioctl,
  1943. .throttle = aurora_throttle,
  1944. .unthrottle = aurora_unthrottle,
  1945. .set_termios = aurora_set_termios,
  1946. .stop = aurora_stop,
  1947. .start = aurora_start,
  1948. .hangup = aurora_hangup,
  1949. .tiocmget = aurora_tiocmget,
  1950. .tiocmset = aurora_tiocmset,
  1951. };
  1952. static int aurora_init_drivers(void)
  1953. {
  1954. int error;
  1955. int i;
  1956. #ifdef AURORA_DEBUG
  1957. printk("aurora_init_drivers: start\n");
  1958. #endif
  1959. tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL);
  1960. if (tmp_buf == NULL) {
  1961. printk(KERN_ERR "aurora: Couldn't get free page.\n");
  1962. return 1;
  1963. }
  1964. init_bh(AURORA_BH, do_aurora_bh);
  1965. aurora_driver = alloc_tty_driver(AURORA_INPORTS);
  1966. if (!aurora_driver) {
  1967. printk(KERN_ERR "aurora: Couldn't allocate tty driver.\n");
  1968. free_page((unsigned long) tmp_buf);
  1969. return 1;
  1970. }
  1971. aurora_driver->owner = THIS_MODULE;
  1972. aurora_driver->name = "ttyA";
  1973. aurora_driver->major = AURORA_MAJOR;
  1974. aurora_driver->type = TTY_DRIVER_TYPE_SERIAL;
  1975. aurora_driver->subtype = SERIAL_TYPE_NORMAL;
  1976. aurora_driver->init_termios = tty_std_termios;
  1977. aurora_driver->init_termios.c_cflag =
  1978. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  1979. aurora_driver->flags = TTY_DRIVER_REAL_RAW;
  1980. tty_set_operations(aurora_driver, &aurora_ops);
  1981. error = tty_register_driver(aurora_driver);
  1982. if (error) {
  1983. put_tty_driver(aurora_driver);
  1984. free_page((unsigned long) tmp_buf);
  1985. printk(KERN_ERR "aurora: Couldn't register aurora driver, error = %d\n",
  1986. error);
  1987. return 1;
  1988. }
  1989. memset(aurora_port, 0, sizeof(aurora_port));
  1990. for (i = 0; i < AURORA_TNPORTS; i++) {
  1991. aurora_port[i].magic = AURORA_MAGIC;
  1992. aurora_port[i].tqueue.routine = do_softint;
  1993. aurora_port[i].tqueue.data = &aurora_port[i];
  1994. aurora_port[i].tqueue_hangup.routine = do_aurora_hangup;
  1995. aurora_port[i].tqueue_hangup.data = &aurora_port[i];
  1996. aurora_port[i].close_delay = 50 * HZ/100;
  1997. aurora_port[i].closing_wait = 3000 * HZ/100;
  1998. init_waitqueue_head(&aurora_port[i].open_wait);
  1999. init_waitqueue_head(&aurora_port[i].close_wait);
  2000. }
  2001. #ifdef AURORA_DEBUG
  2002. printk("aurora_init_drivers: end\n");
  2003. #endif
  2004. return 0;
  2005. }
  2006. static void aurora_release_drivers(void)
  2007. {
  2008. #ifdef AURORA_DEBUG
  2009. printk("aurora_release_drivers: start\n");
  2010. #endif
  2011. free_page((unsigned long)tmp_buf);
  2012. tty_unregister_driver(aurora_driver);
  2013. put_tty_driver(aurora_driver);
  2014. #ifdef AURORA_DEBUG
  2015. printk("aurora_release_drivers: end\n");
  2016. #endif
  2017. }
  2018. /*
  2019. * Called at boot time.
  2020. *
  2021. * You can specify IO base for up to RC_NBOARD cards,
  2022. * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
  2023. * Note that there will be no probing at default
  2024. * addresses in this case.
  2025. *
  2026. */
  2027. void __init aurora_setup(char *str, int *ints)
  2028. {
  2029. int i;
  2030. for(i=0;(i<ints[0])&&(i<4);i++) {
  2031. if (ints[i+1]) irqs[i]=ints[i+1];
  2032. }
  2033. }
  2034. static int __init aurora_real_init(void)
  2035. {
  2036. int found;
  2037. int i;
  2038. printk(KERN_INFO "aurora: Driver starting.\n");
  2039. if(aurora_init_drivers())
  2040. return -EIO;
  2041. found = aurora_probe();
  2042. if(!found) {
  2043. aurora_release_drivers();
  2044. printk(KERN_INFO "aurora: No Aurora Multiport boards detected.\n");
  2045. return -EIO;
  2046. } else {
  2047. printk(KERN_INFO "aurora: %d boards found.\n", found);
  2048. }
  2049. for (i = 0; i < found; i++) {
  2050. int ret = aurora_setup_board(&aurora_board[i]);
  2051. if (ret) {
  2052. #ifdef AURORA_DEBUG
  2053. printk(KERN_ERR "aurora_init: error aurora_setup_board ret %d\n",
  2054. ret);
  2055. #endif
  2056. return ret;
  2057. }
  2058. }
  2059. return 0;
  2060. }
  2061. int irq = 0;
  2062. int irq1 = 0;
  2063. int irq2 = 0;
  2064. int irq3 = 0;
  2065. module_param(irq , int, 0);
  2066. module_param(irq1, int, 0);
  2067. module_param(irq2, int, 0);
  2068. module_param(irq3, int, 0);
  2069. static int __init aurora_init(void)
  2070. {
  2071. if (irq ) irqs[0]=irq ;
  2072. if (irq1) irqs[1]=irq1;
  2073. if (irq2) irqs[2]=irq2;
  2074. if (irq3) irqs[3]=irq3;
  2075. return aurora_real_init();
  2076. }
  2077. static void __exit aurora_cleanup(void)
  2078. {
  2079. int i;
  2080. #ifdef AURORA_DEBUG
  2081. printk("cleanup_module: aurora_release_drivers\n");
  2082. #endif
  2083. aurora_release_drivers();
  2084. for (i = 0; i < AURORA_NBOARD; i++)
  2085. if (aurora_board[i].flags & AURORA_BOARD_PRESENT) {
  2086. aurora_shutdown_board(&aurora_board[i]);
  2087. aurora_release_io_range(&aurora_board[i]);
  2088. }
  2089. }
  2090. module_init(aurora_init);
  2091. module_exit(aurora_cleanup);
  2092. MODULE_LICENSE("GPL");