aurora.c 59 KB

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