aurora.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365
  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 DEFINE_TIMER(aurora_poll_timer, aurora_timer, 0, 0);
  797. static void
  798. aurora_timer (unsigned long ignored)
  799. {
  800. unsigned long flags;
  801. int i;
  802. save_flags(flags); cli();
  803. printk("SRSR: %02x,%02x - ",
  804. sbus_readb(&aurora_board[0].r[0]->r[CD180_SRSR]),
  805. sbus_readb(&aurora_board[0].r[1]->r[CD180_SRSR]));
  806. for (i = 0; i < 4; i++) {
  807. udelay(1);
  808. printk("%02x ",
  809. sbus_readb(&aurora_board[0].r3->r[i]));
  810. }
  811. printk("\n");
  812. aurora_poll_timer.expires = jiffies + 300;
  813. add_timer (&aurora_poll_timer);
  814. restore_flags(flags);
  815. }
  816. #endif
  817. /*
  818. * Routines for open & close processing.
  819. */
  820. /* Called with disabled interrupts */
  821. static int aurora_setup_board(struct Aurora_board * bp)
  822. {
  823. int error;
  824. #ifdef AURORA_ALLIRQ
  825. int i;
  826. for (i = 0; i < AURORA_ALLIRQ; i++) {
  827. error = request_irq(allirq[i]|0x30, aurora_interrupt, SA_SHIRQ,
  828. "sio16", bp);
  829. if (error)
  830. printk(KERN_ERR "IRQ%d request error %d\n",
  831. allirq[i], error);
  832. }
  833. #else
  834. error = request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ,
  835. "sio16", bp);
  836. if (error) {
  837. printk(KERN_ERR "IRQ request error %d\n", error);
  838. return error;
  839. }
  840. #endif
  841. /* Board reset */
  842. sbus_writeb(0, &bp->r0->r);
  843. udelay(1);
  844. if (bp->flags & AURORA_BOARD_TYPE_2) {
  845. /* unknown yet */
  846. } else {
  847. sbus_writeb((AURORA_CFG_ENABLE_IO | AURORA_CFG_ENABLE_IRQ |
  848. (((bp->irq)&0x0f)>>2)),
  849. &bp->r0->r);
  850. }
  851. udelay(10000);
  852. if (aurora_init_CD180(bp,0))error=1;error=0;
  853. if (aurora_init_CD180(bp,1))error++;
  854. if (error == AURORA_NCD180) {
  855. printk(KERN_ERR "Both chips failed initialisation.\n");
  856. return -EIO;
  857. }
  858. #ifdef AURORA_INT_DEBUG
  859. aurora_poll_timer.expires= jiffies + 1;
  860. add_timer(&aurora_poll_timer);
  861. #endif
  862. #ifdef AURORA_DEBUG
  863. printk("aurora_setup_board: end\n");
  864. #endif
  865. return 0;
  866. }
  867. /* Called with disabled interrupts */
  868. static void aurora_shutdown_board(struct Aurora_board *bp)
  869. {
  870. int i;
  871. #ifdef AURORA_DEBUG
  872. printk("aurora_shutdown_board: start\n");
  873. #endif
  874. #ifdef AURORA_INT_DEBUG
  875. del_timer(&aurora_poll_timer);
  876. #endif
  877. #ifdef AURORA_ALLIRQ
  878. for(i=0;i<AURORA_ALLIRQ;i++){
  879. free_irq(allirq[i]|0x30, bp);
  880. /* IRQ_to_board[allirq[i]&0xf] = NULL;*/
  881. }
  882. #else
  883. free_irq(bp->irq|0x30, bp);
  884. /* IRQ_to_board[bp->irq&0xf] = NULL;*/
  885. #endif
  886. /* Drop all DTR's */
  887. for(i=0;i<16;i++){
  888. sbus_writeb(i & 7, &bp->r[i>>3]->r[CD180_CAR]);
  889. udelay(1);
  890. sbus_writeb(0, &bp->r[i>>3]->r[CD180_MSVR]);
  891. udelay(1);
  892. }
  893. /* Board shutdown */
  894. sbus_writeb(0, &bp->r0->r);
  895. #ifdef AURORA_DEBUG
  896. printk("aurora_shutdown_board: end\n");
  897. #endif
  898. }
  899. /* Setting up port characteristics.
  900. * Must be called with disabled interrupts
  901. */
  902. static void aurora_change_speed(struct Aurora_board *bp, struct Aurora_port *port)
  903. {
  904. struct tty_struct *tty;
  905. unsigned long baud;
  906. long tmp;
  907. unsigned char cor1 = 0, cor3 = 0;
  908. unsigned char mcor1 = 0, mcor2 = 0,chip;
  909. #ifdef AURORA_DEBUG
  910. printk("aurora_change_speed: start\n");
  911. #endif
  912. if (!(tty = port->tty) || !tty->termios)
  913. return;
  914. chip = AURORA_CD180(port_No(port));
  915. port->SRER = 0;
  916. port->COR2 = 0;
  917. port->MSVR = MSVR_RTS|MSVR_DTR;
  918. baud = tty_get_baud_rate(tty);
  919. /* Select port on the board */
  920. sbus_writeb(port_No(port) & 7,
  921. &bp->r[chip]->r[CD180_CAR]);
  922. udelay(1);
  923. if (!baud) {
  924. /* Drop DTR & exit */
  925. port->MSVR &= ~(bp->DTR|bp->RTS);
  926. sbus_writeb(port->MSVR,
  927. &bp->r[chip]->r[CD180_MSVR]);
  928. return;
  929. } else {
  930. /* Set DTR on */
  931. port->MSVR |= bp->DTR;
  932. sbus_writeb(port->MSVR,
  933. &bp->r[chip]->r[CD180_MSVR]);
  934. }
  935. /* Now we must calculate some speed dependent things. */
  936. /* Set baud rate for port. */
  937. tmp = (((bp->oscfreq + baud/2) / baud +
  938. CD180_TPC/2) / CD180_TPC);
  939. /* tmp = (bp->oscfreq/7)/baud;
  940. if((tmp%10)>4)tmp=tmp/10+1;else tmp=tmp/10;*/
  941. /* printk("Prescaler period: %d\n",tmp);*/
  942. sbus_writeb((tmp >> 8) & 0xff,
  943. &bp->r[chip]->r[CD180_RBPRH]);
  944. sbus_writeb((tmp >> 8) & 0xff,
  945. &bp->r[chip]->r[CD180_TBPRH]);
  946. sbus_writeb(tmp & 0xff, &bp->r[chip]->r[CD180_RBPRL]);
  947. sbus_writeb(tmp & 0xff, &bp->r[chip]->r[CD180_TBPRL]);
  948. baud = (baud + 5) / 10; /* Estimated CPS */
  949. /* Two timer ticks seems enough to wakeup something like SLIP driver */
  950. tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
  951. port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
  952. SERIAL_XMIT_SIZE - 1 : tmp);
  953. /* Receiver timeout will be transmission time for 1.5 chars */
  954. tmp = (AURORA_TPS + AURORA_TPS/2 + baud/2) / baud;
  955. tmp = (tmp > 0xff) ? 0xff : tmp;
  956. sbus_writeb(tmp, &bp->r[chip]->r[CD180_RTPR]);
  957. switch (C_CSIZE(tty)) {
  958. case CS5:
  959. cor1 |= COR1_5BITS;
  960. break;
  961. case CS6:
  962. cor1 |= COR1_6BITS;
  963. break;
  964. case CS7:
  965. cor1 |= COR1_7BITS;
  966. break;
  967. case CS8:
  968. cor1 |= COR1_8BITS;
  969. break;
  970. }
  971. if (C_CSTOPB(tty))
  972. cor1 |= COR1_2SB;
  973. cor1 |= COR1_IGNORE;
  974. if (C_PARENB(tty)) {
  975. cor1 |= COR1_NORMPAR;
  976. if (C_PARODD(tty))
  977. cor1 |= COR1_ODDP;
  978. if (I_INPCK(tty))
  979. cor1 &= ~COR1_IGNORE;
  980. }
  981. /* Set marking of some errors */
  982. port->mark_mask = RCSR_OE | RCSR_TOUT;
  983. if (I_INPCK(tty))
  984. port->mark_mask |= RCSR_FE | RCSR_PE;
  985. if (I_BRKINT(tty) || I_PARMRK(tty))
  986. port->mark_mask |= RCSR_BREAK;
  987. if (I_IGNPAR(tty))
  988. port->mark_mask &= ~(RCSR_FE | RCSR_PE);
  989. if (I_IGNBRK(tty)) {
  990. port->mark_mask &= ~RCSR_BREAK;
  991. if (I_IGNPAR(tty))
  992. /* Real raw mode. Ignore all */
  993. port->mark_mask &= ~RCSR_OE;
  994. }
  995. /* Enable Hardware Flow Control */
  996. if (C_CRTSCTS(tty)) {
  997. /*#ifdef AURORA_BRAIN_DAMAGED_CTS
  998. port->SRER |= SRER_DSR | SRER_CTS;
  999. mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
  1000. mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
  1001. tty->hw_stopped = !(aurora_in(bp, CD180_MSVR) & (MSVR_CTS|MSVR_DSR));
  1002. #else*/
  1003. port->COR2 |= COR2_CTSAE;
  1004. /*#endif*/
  1005. if (bp->flags&AURORA_BOARD_DTR_FLOW_OK) {
  1006. mcor1 |= AURORA_RXTH;
  1007. }
  1008. }
  1009. /* Enable Software Flow Control. FIXME: I'm not sure about this */
  1010. /* Some people reported that it works, but I still doubt */
  1011. if (I_IXON(tty)) {
  1012. port->COR2 |= COR2_TXIBE;
  1013. cor3 |= (COR3_FCT | COR3_SCDE);
  1014. if (I_IXANY(tty))
  1015. port->COR2 |= COR2_IXM;
  1016. sbus_writeb(START_CHAR(tty),
  1017. &bp->r[chip]->r[CD180_SCHR1]);
  1018. sbus_writeb(STOP_CHAR(tty),
  1019. &bp->r[chip]->r[CD180_SCHR2]);
  1020. sbus_writeb(START_CHAR(tty),
  1021. &bp->r[chip]->r[CD180_SCHR3]);
  1022. sbus_writeb(STOP_CHAR(tty),
  1023. &bp->r[chip]->r[CD180_SCHR4]);
  1024. }
  1025. if (!C_CLOCAL(tty)) {
  1026. /* Enable CD check */
  1027. port->SRER |= SRER_CD;
  1028. mcor1 |= MCOR1_CDZD;
  1029. mcor2 |= MCOR2_CDOD;
  1030. }
  1031. if (C_CREAD(tty))
  1032. /* Enable receiver */
  1033. port->SRER |= SRER_RXD;
  1034. /* Set input FIFO size (1-8 bytes) */
  1035. cor3 |= AURORA_RXFIFO;
  1036. /* Setting up CD180 channel registers */
  1037. sbus_writeb(cor1, &bp->r[chip]->r[CD180_COR1]);
  1038. sbus_writeb(port->COR2, &bp->r[chip]->r[CD180_COR2]);
  1039. sbus_writeb(cor3, &bp->r[chip]->r[CD180_COR3]);
  1040. /* Make CD180 know about registers change */
  1041. aurora_wait_CCR(bp->r[chip]);
  1042. sbus_writeb(CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3,
  1043. &bp->r[chip]->r[CD180_CCR]);
  1044. /* Setting up modem option registers */
  1045. sbus_writeb(mcor1, &bp->r[chip]->r[CD180_MCOR1]);
  1046. sbus_writeb(mcor2, &bp->r[chip]->r[CD180_MCOR2]);
  1047. /* Enable CD180 transmitter & receiver */
  1048. aurora_wait_CCR(bp->r[chip]);
  1049. sbus_writeb(CCR_TXEN | CCR_RXEN, &bp->r[chip]->r[CD180_CCR]);
  1050. /* Enable interrupts */
  1051. sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
  1052. /* And finally set RTS on */
  1053. sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
  1054. #ifdef AURORA_DEBUG
  1055. printk("aurora_change_speed: end\n");
  1056. #endif
  1057. }
  1058. /* Must be called with interrupts enabled */
  1059. static int aurora_setup_port(struct Aurora_board *bp, struct Aurora_port *port)
  1060. {
  1061. unsigned long flags;
  1062. #ifdef AURORA_DEBUG
  1063. printk("aurora_setup_port: start %d\n",port_No(port));
  1064. #endif
  1065. if (port->flags & ASYNC_INITIALIZED)
  1066. return 0;
  1067. if (!port->xmit_buf) {
  1068. /* We may sleep in get_zeroed_page() */
  1069. unsigned long tmp;
  1070. if (!(tmp = get_zeroed_page(GFP_KERNEL)))
  1071. return -ENOMEM;
  1072. if (port->xmit_buf) {
  1073. free_page(tmp);
  1074. return -ERESTARTSYS;
  1075. }
  1076. port->xmit_buf = (unsigned char *) tmp;
  1077. }
  1078. save_flags(flags); cli();
  1079. if (port->tty)
  1080. clear_bit(TTY_IO_ERROR, &port->tty->flags);
  1081. #ifdef MODULE
  1082. if ((port->count == 1) && ((++bp->count) == 1))
  1083. bp->flags |= AURORA_BOARD_ACTIVE;
  1084. #endif
  1085. port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
  1086. aurora_change_speed(bp, port);
  1087. port->flags |= ASYNC_INITIALIZED;
  1088. restore_flags(flags);
  1089. #ifdef AURORA_DEBUG
  1090. printk("aurora_setup_port: end\n");
  1091. #endif
  1092. return 0;
  1093. }
  1094. /* Must be called with interrupts disabled */
  1095. static void aurora_shutdown_port(struct Aurora_board *bp, struct Aurora_port *port)
  1096. {
  1097. struct tty_struct *tty;
  1098. unsigned char chip;
  1099. #ifdef AURORA_DEBUG
  1100. printk("aurora_shutdown_port: start\n");
  1101. #endif
  1102. if (!(port->flags & ASYNC_INITIALIZED))
  1103. return;
  1104. chip = AURORA_CD180(port_No(port));
  1105. #ifdef AURORA_REPORT_OVERRUN
  1106. printk("aurora%d: port %d: Total %ld overruns were detected.\n",
  1107. board_No(bp), port_No(port), port->overrun);
  1108. #endif
  1109. #ifdef AURORA_REPORT_FIFO
  1110. {
  1111. int i;
  1112. printk("aurora%d: port %d: FIFO hits [ ",
  1113. board_No(bp), port_No(port));
  1114. for (i = 0; i < 10; i++) {
  1115. printk("%ld ", port->hits[i]);
  1116. }
  1117. printk("].\n");
  1118. }
  1119. #endif
  1120. if (port->xmit_buf) {
  1121. free_page((unsigned long) port->xmit_buf);
  1122. port->xmit_buf = NULL;
  1123. }
  1124. if (!(tty = port->tty) || C_HUPCL(tty)) {
  1125. /* Drop DTR */
  1126. port->MSVR &= ~(bp->DTR|bp->RTS);
  1127. sbus_writeb(port->MSVR,
  1128. &bp->r[chip]->r[CD180_MSVR]);
  1129. }
  1130. /* Select port */
  1131. sbus_writeb(port_No(port) & 7,
  1132. &bp->r[chip]->r[CD180_CAR]);
  1133. udelay(1);
  1134. /* Reset port */
  1135. aurora_wait_CCR(bp->r[chip]);
  1136. sbus_writeb(CCR_SOFTRESET, &bp->r[chip]->r[CD180_CCR]);
  1137. /* Disable all interrupts from this port */
  1138. port->SRER = 0;
  1139. sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
  1140. if (tty)
  1141. set_bit(TTY_IO_ERROR, &tty->flags);
  1142. port->flags &= ~ASYNC_INITIALIZED;
  1143. #ifdef MODULE
  1144. if (--bp->count < 0) {
  1145. printk(KERN_DEBUG "aurora%d: aurora_shutdown_port: "
  1146. "bad board count: %d\n",
  1147. board_No(bp), bp->count);
  1148. bp->count = 0;
  1149. }
  1150. if (!bp->count)
  1151. bp->flags &= ~AURORA_BOARD_ACTIVE;
  1152. #endif
  1153. #ifdef AURORA_DEBUG
  1154. printk("aurora_shutdown_port: end\n");
  1155. #endif
  1156. }
  1157. static int block_til_ready(struct tty_struct *tty, struct file * filp,
  1158. struct Aurora_port *port)
  1159. {
  1160. DECLARE_WAITQUEUE(wait, current);
  1161. struct Aurora_board *bp = port_Board(port);
  1162. int retval;
  1163. int do_clocal = 0;
  1164. int CD;
  1165. unsigned char chip;
  1166. #ifdef AURORA_DEBUG
  1167. printk("block_til_ready: start\n");
  1168. #endif
  1169. chip = AURORA_CD180(port_No(port));
  1170. /* If the device is in the middle of being closed, then block
  1171. * until it's done, and then try again.
  1172. */
  1173. if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
  1174. interruptible_sleep_on(&port->close_wait);
  1175. if (port->flags & ASYNC_HUP_NOTIFY)
  1176. return -EAGAIN;
  1177. else
  1178. return -ERESTARTSYS;
  1179. }
  1180. /* If non-blocking mode is set, or the port is not enabled,
  1181. * then make the check up front and then exit.
  1182. */
  1183. if ((filp->f_flags & O_NONBLOCK) ||
  1184. (tty->flags & (1 << TTY_IO_ERROR))) {
  1185. port->flags |= ASYNC_NORMAL_ACTIVE;
  1186. return 0;
  1187. }
  1188. if (C_CLOCAL(tty))
  1189. do_clocal = 1;
  1190. /* Block waiting for the carrier detect and the line to become
  1191. * free (i.e., not in use by the callout). While we are in
  1192. * this loop, info->count is dropped by one, so that
  1193. * rs_close() knows when to free things. We restore it upon
  1194. * exit, either normal or abnormal.
  1195. */
  1196. retval = 0;
  1197. add_wait_queue(&port->open_wait, &wait);
  1198. cli();
  1199. if (!tty_hung_up_p(filp))
  1200. port->count--;
  1201. sti();
  1202. port->blocked_open++;
  1203. while (1) {
  1204. cli();
  1205. sbus_writeb(port_No(port) & 7,
  1206. &bp->r[chip]->r[CD180_CAR]);
  1207. udelay(1);
  1208. CD = sbus_readb(&bp->r[chip]->r[CD180_MSVR]) & MSVR_CD;
  1209. port->MSVR=bp->RTS;
  1210. /* auto drops DTR */
  1211. sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
  1212. sti();
  1213. set_current_state(TASK_INTERRUPTIBLE);
  1214. if (tty_hung_up_p(filp) ||
  1215. !(port->flags & ASYNC_INITIALIZED)) {
  1216. if (port->flags & ASYNC_HUP_NOTIFY)
  1217. retval = -EAGAIN;
  1218. else
  1219. retval = -ERESTARTSYS;
  1220. break;
  1221. }
  1222. if (!(port->flags & ASYNC_CLOSING) &&
  1223. (do_clocal || CD))
  1224. break;
  1225. if (signal_pending(current)) {
  1226. retval = -ERESTARTSYS;
  1227. break;
  1228. }
  1229. schedule();
  1230. }
  1231. current->state = TASK_RUNNING;
  1232. remove_wait_queue(&port->open_wait, &wait);
  1233. if (!tty_hung_up_p(filp))
  1234. port->count++;
  1235. port->blocked_open--;
  1236. if (retval)
  1237. return retval;
  1238. port->flags |= ASYNC_NORMAL_ACTIVE;
  1239. #ifdef AURORA_DEBUG
  1240. printk("block_til_ready: end\n");
  1241. #endif
  1242. return 0;
  1243. }
  1244. static int aurora_open(struct tty_struct * tty, struct file * filp)
  1245. {
  1246. int board;
  1247. int error;
  1248. struct Aurora_port * port;
  1249. struct Aurora_board * bp;
  1250. unsigned long flags;
  1251. #ifdef AURORA_DEBUG
  1252. printk("aurora_open: start\n");
  1253. #endif
  1254. board = AURORA_BOARD(tty->index);
  1255. if (board > AURORA_NBOARD ||
  1256. !(aurora_board[board].flags & AURORA_BOARD_PRESENT)) {
  1257. #ifdef AURORA_DEBUG
  1258. printk("aurora_open: error board %d present %d\n",
  1259. board, aurora_board[board].flags & AURORA_BOARD_PRESENT);
  1260. #endif
  1261. return -ENODEV;
  1262. }
  1263. bp = &aurora_board[board];
  1264. port = aurora_port + board * AURORA_NPORT * AURORA_NCD180 + AURORA_PORT(tty->index);
  1265. if ((aurora_paranoia_check(port, tty->name, "aurora_open")) {
  1266. #ifdef AURORA_DEBUG
  1267. printk("aurora_open: error paranoia check\n");
  1268. #endif
  1269. return -ENODEV;
  1270. }
  1271. port->count++;
  1272. tty->driver_data = port;
  1273. port->tty = tty;
  1274. if ((error = aurora_setup_port(bp, port))) {
  1275. #ifdef AURORA_DEBUG
  1276. printk("aurora_open: error aurora_setup_port ret %d\n",error);
  1277. #endif
  1278. return error;
  1279. }
  1280. if ((error = block_til_ready(tty, filp, port))) {
  1281. #ifdef AURORA_DEBUG
  1282. printk("aurora_open: error block_til_ready ret %d\n",error);
  1283. #endif
  1284. return error;
  1285. }
  1286. #ifdef AURORA_DEBUG
  1287. printk("aurora_open: end\n");
  1288. #endif
  1289. return 0;
  1290. }
  1291. static void aurora_close(struct tty_struct * tty, struct file * filp)
  1292. {
  1293. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1294. struct Aurora_board *bp;
  1295. unsigned long flags;
  1296. unsigned long timeout;
  1297. unsigned char chip;
  1298. #ifdef AURORA_DEBUG
  1299. printk("aurora_close: start\n");
  1300. #endif
  1301. if (!port || (aurora_paranoia_check(port, tty->name, "close"))
  1302. return;
  1303. chip = AURORA_CD180(port_No(port));
  1304. save_flags(flags); cli();
  1305. if (tty_hung_up_p(filp)) {
  1306. restore_flags(flags);
  1307. return;
  1308. }
  1309. bp = port_Board(port);
  1310. if ((tty->count == 1) && (port->count != 1)) {
  1311. printk(KERN_DEBUG "aurora%d: aurora_close: bad port count; "
  1312. "tty->count is 1, port count is %d\n",
  1313. board_No(bp), port->count);
  1314. port->count = 1;
  1315. }
  1316. if (--port->count < 0) {
  1317. printk(KERN_DEBUG "aurora%d: aurora_close: bad port "
  1318. "count for tty%d: %d\n",
  1319. board_No(bp), port_No(port), port->count);
  1320. port->count = 0;
  1321. }
  1322. if (port->count) {
  1323. restore_flags(flags);
  1324. return;
  1325. }
  1326. port->flags |= ASYNC_CLOSING;
  1327. /* Now we wait for the transmit buffer to clear; and we notify
  1328. * the line discipline to only process XON/XOFF characters.
  1329. */
  1330. tty->closing = 1;
  1331. if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE){
  1332. #ifdef AURORA_DEBUG
  1333. printk("aurora_close: waiting to flush...\n");
  1334. #endif
  1335. tty_wait_until_sent(tty, port->closing_wait);
  1336. }
  1337. /* At this point we stop accepting input. To do this, we
  1338. * disable the receive line status interrupts, and tell the
  1339. * interrupt driver to stop checking the data ready bit in the
  1340. * line status register.
  1341. */
  1342. port->SRER &= ~SRER_RXD;
  1343. if (port->flags & ASYNC_INITIALIZED) {
  1344. port->SRER &= ~SRER_TXRDY;
  1345. port->SRER |= SRER_TXEMPTY;
  1346. sbus_writeb(port_No(port) & 7,
  1347. &bp->r[chip]->r[CD180_CAR]);
  1348. udelay(1);
  1349. sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
  1350. /*
  1351. * Before we drop DTR, make sure the UART transmitter
  1352. * has completely drained; this is especially
  1353. * important if there is a transmit FIFO!
  1354. */
  1355. timeout = jiffies+HZ;
  1356. while(port->SRER & SRER_TXEMPTY) {
  1357. msleep_interruptible(jiffies_to_msecs(port->timeout));
  1358. if (time_after(jiffies, timeout))
  1359. break;
  1360. }
  1361. }
  1362. #ifdef AURORA_DEBUG
  1363. printk("aurora_close: shutdown_port\n");
  1364. #endif
  1365. aurora_shutdown_port(bp, port);
  1366. if (tty->driver->flush_buffer)
  1367. tty->driver->flush_buffer(tty);
  1368. tty_ldisc_flush(tty);
  1369. tty->closing = 0;
  1370. port->event = 0;
  1371. port->tty = 0;
  1372. if (port->blocked_open) {
  1373. if (port->close_delay) {
  1374. msleep_interruptible(jiffies_to_msecs(port->close_delay));
  1375. }
  1376. wake_up_interruptible(&port->open_wait);
  1377. }
  1378. port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  1379. wake_up_interruptible(&port->close_wait);
  1380. restore_flags(flags);
  1381. #ifdef AURORA_DEBUG
  1382. printk("aurora_close: end\n");
  1383. #endif
  1384. }
  1385. static int aurora_write(struct tty_struct * tty,
  1386. const unsigned char *buf, int count)
  1387. {
  1388. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1389. struct Aurora_board *bp;
  1390. int c, total = 0;
  1391. unsigned long flags;
  1392. unsigned char chip;
  1393. #ifdef AURORA_DEBUG
  1394. printk("aurora_write: start %d\n",count);
  1395. #endif
  1396. if ((aurora_paranoia_check(port, tty->name, "aurora_write"))
  1397. return 0;
  1398. chip = AURORA_CD180(port_No(port));
  1399. bp = port_Board(port);
  1400. if (!tty || !port->xmit_buf || !tmp_buf)
  1401. return 0;
  1402. save_flags(flags);
  1403. while (1) {
  1404. cli();
  1405. c = min(count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
  1406. SERIAL_XMIT_SIZE - port->xmit_head));
  1407. if (c <= 0) {
  1408. restore_flags(flags);
  1409. break;
  1410. }
  1411. memcpy(port->xmit_buf + port->xmit_head, buf, c);
  1412. port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
  1413. port->xmit_cnt += c;
  1414. restore_flags(flags);
  1415. buf += c;
  1416. count -= c;
  1417. total += c;
  1418. }
  1419. cli();
  1420. if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
  1421. !(port->SRER & SRER_TXRDY)) {
  1422. port->SRER |= SRER_TXRDY;
  1423. sbus_writeb(port_No(port) & 7,
  1424. &bp->r[chip]->r[CD180_CAR]);
  1425. udelay(1);
  1426. sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
  1427. }
  1428. restore_flags(flags);
  1429. #ifdef AURORA_DEBUG
  1430. printk("aurora_write: end %d\n",total);
  1431. #endif
  1432. return total;
  1433. }
  1434. static void aurora_put_char(struct tty_struct * tty, unsigned char ch)
  1435. {
  1436. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1437. unsigned long flags;
  1438. #ifdef AURORA_DEBUG
  1439. printk("aurora_put_char: start %c\n",ch);
  1440. #endif
  1441. if ((aurora_paranoia_check(port, tty->name, "aurora_put_char"))
  1442. return;
  1443. if (!tty || !port->xmit_buf)
  1444. return;
  1445. save_flags(flags); cli();
  1446. if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
  1447. restore_flags(flags);
  1448. return;
  1449. }
  1450. port->xmit_buf[port->xmit_head++] = ch;
  1451. port->xmit_head &= SERIAL_XMIT_SIZE - 1;
  1452. port->xmit_cnt++;
  1453. restore_flags(flags);
  1454. #ifdef AURORA_DEBUG
  1455. printk("aurora_put_char: end\n");
  1456. #endif
  1457. }
  1458. static void aurora_flush_chars(struct tty_struct * tty)
  1459. {
  1460. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1461. unsigned long flags;
  1462. unsigned char chip;
  1463. /*#ifdef AURORA_DEBUG
  1464. printk("aurora_flush_chars: start\n");
  1465. #endif*/
  1466. if ((aurora_paranoia_check(port, tty->name, "aurora_flush_chars"))
  1467. return;
  1468. chip = AURORA_CD180(port_No(port));
  1469. if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
  1470. !port->xmit_buf)
  1471. return;
  1472. save_flags(flags); cli();
  1473. port->SRER |= SRER_TXRDY;
  1474. sbus_writeb(port_No(port) & 7,
  1475. &port_Board(port)->r[chip]->r[CD180_CAR]);
  1476. udelay(1);
  1477. sbus_writeb(port->SRER,
  1478. &port_Board(port)->r[chip]->r[CD180_SRER]);
  1479. restore_flags(flags);
  1480. /*#ifdef AURORA_DEBUG
  1481. printk("aurora_flush_chars: end\n");
  1482. #endif*/
  1483. }
  1484. static int aurora_write_room(struct tty_struct * tty)
  1485. {
  1486. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1487. int ret;
  1488. #ifdef AURORA_DEBUG
  1489. printk("aurora_write_room: start\n");
  1490. #endif
  1491. if ((aurora_paranoia_check(port, tty->name, "aurora_write_room"))
  1492. return 0;
  1493. ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
  1494. if (ret < 0)
  1495. ret = 0;
  1496. #ifdef AURORA_DEBUG
  1497. printk("aurora_write_room: end\n");
  1498. #endif
  1499. return ret;
  1500. }
  1501. static int aurora_chars_in_buffer(struct tty_struct *tty)
  1502. {
  1503. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1504. if ((aurora_paranoia_check(port, tty->name, "aurora_chars_in_buffer"))
  1505. return 0;
  1506. return port->xmit_cnt;
  1507. }
  1508. static void aurora_flush_buffer(struct tty_struct *tty)
  1509. {
  1510. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1511. unsigned long flags;
  1512. #ifdef AURORA_DEBUG
  1513. printk("aurora_flush_buffer: start\n");
  1514. #endif
  1515. if ((aurora_paranoia_check(port, tty->name, "aurora_flush_buffer"))
  1516. return;
  1517. save_flags(flags); cli();
  1518. port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
  1519. restore_flags(flags);
  1520. tty_wakeup(tty);
  1521. #ifdef AURORA_DEBUG
  1522. printk("aurora_flush_buffer: end\n");
  1523. #endif
  1524. }
  1525. static int aurora_tiocmget(struct tty_struct *tty, struct file *file)
  1526. {
  1527. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1528. struct Aurora_board * bp;
  1529. unsigned char status,chip;
  1530. unsigned int result;
  1531. unsigned long flags;
  1532. #ifdef AURORA_DEBUG
  1533. printk("aurora_get_modem_info: start\n");
  1534. #endif
  1535. if ((aurora_paranoia_check(port, tty->name, __FUNCTION__))
  1536. return -ENODEV;
  1537. chip = AURORA_CD180(port_No(port));
  1538. bp = port_Board(port);
  1539. save_flags(flags); cli();
  1540. sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
  1541. udelay(1);
  1542. status = sbus_readb(&bp->r[chip]->r[CD180_MSVR]);
  1543. result = 0/*bp->r[chip]->r[AURORA_RI] & (1u << port_No(port)) ? 0 : TIOCM_RNG*/;
  1544. restore_flags(flags);
  1545. result |= ((status & bp->RTS) ? TIOCM_RTS : 0)
  1546. | ((status & bp->DTR) ? TIOCM_DTR : 0)
  1547. | ((status & MSVR_CD) ? TIOCM_CAR : 0)
  1548. | ((status & MSVR_DSR) ? TIOCM_DSR : 0)
  1549. | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
  1550. #ifdef AURORA_DEBUG
  1551. printk("aurora_get_modem_info: end\n");
  1552. #endif
  1553. return result;
  1554. }
  1555. static int aurora_tiocmset(struct tty_struct *tty, struct file *file,
  1556. unsigned int set, unsigned int clear)
  1557. {
  1558. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1559. unsigned int arg;
  1560. unsigned long flags;
  1561. struct Aurora_board *bp = port_Board(port);
  1562. unsigned char chip;
  1563. #ifdef AURORA_DEBUG
  1564. printk("aurora_set_modem_info: start\n");
  1565. #endif
  1566. if ((aurora_paranoia_check(port, tty->name, __FUNCTION__))
  1567. return -ENODEV;
  1568. chip = AURORA_CD180(port_No(port));
  1569. save_flags(flags); cli();
  1570. if (set & TIOCM_RTS)
  1571. port->MSVR |= bp->RTS;
  1572. if (set & TIOCM_DTR)
  1573. port->MSVR |= bp->DTR;
  1574. if (clear & TIOCM_RTS)
  1575. port->MSVR &= ~bp->RTS;
  1576. if (clear & TIOCM_DTR)
  1577. port->MSVR &= ~bp->DTR;
  1578. sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
  1579. udelay(1);
  1580. sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
  1581. restore_flags(flags);
  1582. #ifdef AURORA_DEBUG
  1583. printk("aurora_set_modem_info: end\n");
  1584. #endif
  1585. return 0;
  1586. }
  1587. static void aurora_send_break(struct Aurora_port * port, unsigned long length)
  1588. {
  1589. struct Aurora_board *bp = port_Board(port);
  1590. unsigned long flags;
  1591. unsigned char chip;
  1592. #ifdef AURORA_DEBUG
  1593. printk("aurora_send_break: start\n");
  1594. #endif
  1595. chip = AURORA_CD180(port_No(port));
  1596. save_flags(flags); cli();
  1597. port->break_length = AURORA_TPS / HZ * length;
  1598. port->COR2 |= COR2_ETC;
  1599. port->SRER |= SRER_TXRDY;
  1600. sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
  1601. udelay(1);
  1602. sbus_writeb(port->COR2, &bp->r[chip]->r[CD180_COR2]);
  1603. sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
  1604. aurora_wait_CCR(bp->r[chip]);
  1605. sbus_writeb(CCR_CORCHG2, &bp->r[chip]->r[CD180_CCR]);
  1606. aurora_wait_CCR(bp->r[chip]);
  1607. restore_flags(flags);
  1608. #ifdef AURORA_DEBUG
  1609. printk("aurora_send_break: end\n");
  1610. #endif
  1611. }
  1612. static int aurora_set_serial_info(struct Aurora_port * port,
  1613. struct serial_struct * newinfo)
  1614. {
  1615. struct serial_struct tmp;
  1616. struct Aurora_board *bp = port_Board(port);
  1617. int change_speed;
  1618. unsigned long flags;
  1619. #ifdef AURORA_DEBUG
  1620. printk("aurora_set_serial_info: start\n");
  1621. #endif
  1622. if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
  1623. return -EFAULT;
  1624. #if 0
  1625. if ((tmp.irq != bp->irq) ||
  1626. (tmp.port != bp->base) ||
  1627. (tmp.type != PORT_CIRRUS) ||
  1628. (tmp.baud_base != (bp->oscfreq + CD180_TPC/2) / CD180_TPC) ||
  1629. (tmp.custom_divisor != 0) ||
  1630. (tmp.xmit_fifo_size != CD180_NFIFO) ||
  1631. (tmp.flags & ~AURORA_LEGAL_FLAGS))
  1632. return -EINVAL;
  1633. #endif
  1634. change_speed = ((port->flags & ASYNC_SPD_MASK) !=
  1635. (tmp.flags & ASYNC_SPD_MASK));
  1636. if (!capable(CAP_SYS_ADMIN)) {
  1637. if ((tmp.close_delay != port->close_delay) ||
  1638. (tmp.closing_wait != port->closing_wait) ||
  1639. ((tmp.flags & ~ASYNC_USR_MASK) !=
  1640. (port->flags & ~ASYNC_USR_MASK)))
  1641. return -EPERM;
  1642. port->flags = ((port->flags & ~ASYNC_USR_MASK) |
  1643. (tmp.flags & ASYNC_USR_MASK));
  1644. } else {
  1645. port->flags = ((port->flags & ~ASYNC_FLAGS) |
  1646. (tmp.flags & ASYNC_FLAGS));
  1647. port->close_delay = tmp.close_delay;
  1648. port->closing_wait = tmp.closing_wait;
  1649. }
  1650. if (change_speed) {
  1651. save_flags(flags); cli();
  1652. aurora_change_speed(bp, port);
  1653. restore_flags(flags);
  1654. }
  1655. #ifdef AURORA_DEBUG
  1656. printk("aurora_set_serial_info: end\n");
  1657. #endif
  1658. return 0;
  1659. }
  1660. extern int aurora_get_serial_info(struct Aurora_port * port,
  1661. struct serial_struct * retinfo)
  1662. {
  1663. struct serial_struct tmp;
  1664. struct Aurora_board *bp = port_Board(port);
  1665. #ifdef AURORA_DEBUG
  1666. printk("aurora_get_serial_info: start\n");
  1667. #endif
  1668. if (!access_ok(VERIFY_WRITE, (void *) retinfo, sizeof(tmp)))
  1669. return -EFAULT;
  1670. memset(&tmp, 0, sizeof(tmp));
  1671. tmp.type = PORT_CIRRUS;
  1672. tmp.line = port - aurora_port;
  1673. tmp.port = 0;
  1674. tmp.irq = bp->irq;
  1675. tmp.flags = port->flags;
  1676. tmp.baud_base = (bp->oscfreq + CD180_TPC/2) / CD180_TPC;
  1677. tmp.close_delay = port->close_delay * HZ/100;
  1678. tmp.closing_wait = port->closing_wait * HZ/100;
  1679. tmp.xmit_fifo_size = CD180_NFIFO;
  1680. copy_to_user(retinfo, &tmp, sizeof(tmp));
  1681. #ifdef AURORA_DEBUG
  1682. printk("aurora_get_serial_info: end\n");
  1683. #endif
  1684. return 0;
  1685. }
  1686. static int aurora_ioctl(struct tty_struct * tty, struct file * filp,
  1687. unsigned int cmd, unsigned long arg)
  1688. {
  1689. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1690. int retval;
  1691. #ifdef AURORA_DEBUG
  1692. printk("aurora_ioctl: start\n");
  1693. #endif
  1694. if ((aurora_paranoia_check(port, tty->name, "aurora_ioctl"))
  1695. return -ENODEV;
  1696. switch (cmd) {
  1697. case TCSBRK: /* SVID version: non-zero arg --> no break */
  1698. retval = tty_check_change(tty);
  1699. if (retval)
  1700. return retval;
  1701. tty_wait_until_sent(tty, 0);
  1702. if (!arg)
  1703. aurora_send_break(port, HZ/4); /* 1/4 second */
  1704. return 0;
  1705. case TCSBRKP: /* support for POSIX tcsendbreak() */
  1706. retval = tty_check_change(tty);
  1707. if (retval)
  1708. return retval;
  1709. tty_wait_until_sent(tty, 0);
  1710. aurora_send_break(port, arg ? arg*(HZ/10) : HZ/4);
  1711. return 0;
  1712. case TIOCGSOFTCAR:
  1713. return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *)arg);
  1714. case TIOCSSOFTCAR:
  1715. if (get_user(arg,(unsigned long *)arg))
  1716. return -EFAULT;
  1717. tty->termios->c_cflag =
  1718. ((tty->termios->c_cflag & ~CLOCAL) |
  1719. (arg ? CLOCAL : 0));
  1720. return 0;
  1721. case TIOCGSERIAL:
  1722. return aurora_get_serial_info(port, (struct serial_struct *) arg);
  1723. case TIOCSSERIAL:
  1724. return aurora_set_serial_info(port, (struct serial_struct *) arg);
  1725. default:
  1726. return -ENOIOCTLCMD;
  1727. };
  1728. #ifdef AURORA_DEBUG
  1729. printk("aurora_ioctl: end\n");
  1730. #endif
  1731. return 0;
  1732. }
  1733. static void aurora_throttle(struct tty_struct * tty)
  1734. {
  1735. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1736. struct Aurora_board *bp;
  1737. unsigned long flags;
  1738. unsigned char chip;
  1739. #ifdef AURORA_DEBUG
  1740. printk("aurora_throttle: start\n");
  1741. #endif
  1742. if ((aurora_paranoia_check(port, tty->name, "aurora_throttle"))
  1743. return;
  1744. bp = port_Board(port);
  1745. chip = AURORA_CD180(port_No(port));
  1746. save_flags(flags); cli();
  1747. port->MSVR &= ~bp->RTS;
  1748. sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
  1749. udelay(1);
  1750. if (I_IXOFF(tty)) {
  1751. aurora_wait_CCR(bp->r[chip]);
  1752. sbus_writeb(CCR_SSCH2, &bp->r[chip]->r[CD180_CCR]);
  1753. aurora_wait_CCR(bp->r[chip]);
  1754. }
  1755. sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
  1756. restore_flags(flags);
  1757. #ifdef AURORA_DEBUG
  1758. printk("aurora_throttle: end\n");
  1759. #endif
  1760. }
  1761. static void aurora_unthrottle(struct tty_struct * tty)
  1762. {
  1763. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1764. struct Aurora_board *bp;
  1765. unsigned long flags;
  1766. unsigned char chip;
  1767. #ifdef AURORA_DEBUG
  1768. printk("aurora_unthrottle: start\n");
  1769. #endif
  1770. if ((aurora_paranoia_check(port, tty->name, "aurora_unthrottle"))
  1771. return;
  1772. bp = port_Board(port);
  1773. chip = AURORA_CD180(port_No(port));
  1774. save_flags(flags); cli();
  1775. port->MSVR |= bp->RTS;
  1776. sbus_writeb(port_No(port) & 7,
  1777. &bp->r[chip]->r[CD180_CAR]);
  1778. udelay(1);
  1779. if (I_IXOFF(tty)) {
  1780. aurora_wait_CCR(bp->r[chip]);
  1781. sbus_writeb(CCR_SSCH1,
  1782. &bp->r[chip]->r[CD180_CCR]);
  1783. aurora_wait_CCR(bp->r[chip]);
  1784. }
  1785. sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
  1786. restore_flags(flags);
  1787. #ifdef AURORA_DEBUG
  1788. printk("aurora_unthrottle: end\n");
  1789. #endif
  1790. }
  1791. static void aurora_stop(struct tty_struct * tty)
  1792. {
  1793. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1794. struct Aurora_board *bp;
  1795. unsigned long flags;
  1796. unsigned char chip;
  1797. #ifdef AURORA_DEBUG
  1798. printk("aurora_stop: start\n");
  1799. #endif
  1800. if ((aurora_paranoia_check(port, tty->name, "aurora_stop"))
  1801. return;
  1802. bp = port_Board(port);
  1803. chip = AURORA_CD180(port_No(port));
  1804. save_flags(flags); cli();
  1805. port->SRER &= ~SRER_TXRDY;
  1806. sbus_writeb(port_No(port) & 7,
  1807. &bp->r[chip]->r[CD180_CAR]);
  1808. udelay(1);
  1809. sbus_writeb(port->SRER,
  1810. &bp->r[chip]->r[CD180_SRER]);
  1811. restore_flags(flags);
  1812. #ifdef AURORA_DEBUG
  1813. printk("aurora_stop: end\n");
  1814. #endif
  1815. }
  1816. static void aurora_start(struct tty_struct * tty)
  1817. {
  1818. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1819. struct Aurora_board *bp;
  1820. unsigned long flags;
  1821. unsigned char chip;
  1822. #ifdef AURORA_DEBUG
  1823. printk("aurora_start: start\n");
  1824. #endif
  1825. if ((aurora_paranoia_check(port, tty->name, "aurora_start"))
  1826. return;
  1827. bp = port_Board(port);
  1828. chip = AURORA_CD180(port_No(port));
  1829. save_flags(flags); cli();
  1830. if (port->xmit_cnt && port->xmit_buf && !(port->SRER & SRER_TXRDY)) {
  1831. port->SRER |= SRER_TXRDY;
  1832. sbus_writeb(port_No(port) & 7,
  1833. &bp->r[chip]->r[CD180_CAR]);
  1834. udelay(1);
  1835. sbus_writeb(port->SRER,
  1836. &bp->r[chip]->r[CD180_SRER]);
  1837. }
  1838. restore_flags(flags);
  1839. #ifdef AURORA_DEBUG
  1840. printk("aurora_start: end\n");
  1841. #endif
  1842. }
  1843. /*
  1844. * This routine is called from the scheduler tqueue when the interrupt
  1845. * routine has signalled that a hangup has occurred. The path of
  1846. * hangup processing is:
  1847. *
  1848. * serial interrupt routine -> (scheduler tqueue) ->
  1849. * do_aurora_hangup() -> tty->hangup() -> aurora_hangup()
  1850. *
  1851. */
  1852. static void do_aurora_hangup(void *private_)
  1853. {
  1854. struct Aurora_port *port = (struct Aurora_port *) private_;
  1855. struct tty_struct *tty;
  1856. #ifdef AURORA_DEBUG
  1857. printk("do_aurora_hangup: start\n");
  1858. #endif
  1859. tty = port->tty;
  1860. if (tty != NULL) {
  1861. tty_hangup(tty); /* FIXME: module removal race - AKPM */
  1862. #ifdef AURORA_DEBUG
  1863. printk("do_aurora_hangup: end\n");
  1864. #endif
  1865. }
  1866. }
  1867. static void aurora_hangup(struct tty_struct * tty)
  1868. {
  1869. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1870. struct Aurora_board *bp;
  1871. #ifdef AURORA_DEBUG
  1872. printk("aurora_hangup: start\n");
  1873. #endif
  1874. if ((aurora_paranoia_check(port, tty->name, "aurora_hangup"))
  1875. return;
  1876. bp = port_Board(port);
  1877. aurora_shutdown_port(bp, port);
  1878. port->event = 0;
  1879. port->count = 0;
  1880. port->flags &= ~ASYNC_NORMAL_ACTIVE;
  1881. port->tty = 0;
  1882. wake_up_interruptible(&port->open_wait);
  1883. #ifdef AURORA_DEBUG
  1884. printk("aurora_hangup: end\n");
  1885. #endif
  1886. }
  1887. static void aurora_set_termios(struct tty_struct * tty, struct termios * old_termios)
  1888. {
  1889. struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
  1890. unsigned long flags;
  1891. #ifdef AURORA_DEBUG
  1892. printk("aurora_set_termios: start\n");
  1893. #endif
  1894. if ((aurora_paranoia_check(port, tty->name, "aurora_set_termios"))
  1895. return;
  1896. if (tty->termios->c_cflag == old_termios->c_cflag &&
  1897. tty->termios->c_iflag == old_termios->c_iflag)
  1898. return;
  1899. save_flags(flags); cli();
  1900. aurora_change_speed(port_Board(port), port);
  1901. restore_flags(flags);
  1902. if ((old_termios->c_cflag & CRTSCTS) &&
  1903. !(tty->termios->c_cflag & CRTSCTS)) {
  1904. tty->hw_stopped = 0;
  1905. aurora_start(tty);
  1906. }
  1907. #ifdef AURORA_DEBUG
  1908. printk("aurora_set_termios: end\n");
  1909. #endif
  1910. }
  1911. static void do_aurora_bh(void)
  1912. {
  1913. run_task_queue(&tq_aurora);
  1914. }
  1915. static void do_softint(void *private_)
  1916. {
  1917. struct Aurora_port *port = (struct Aurora_port *) private_;
  1918. struct tty_struct *tty;
  1919. #ifdef AURORA_DEBUG
  1920. printk("do_softint: start\n");
  1921. #endif
  1922. tty = port->tty;
  1923. if (tty == NULL)
  1924. return;
  1925. if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) {
  1926. tty_wakeup(tty);
  1927. }
  1928. #ifdef AURORA_DEBUG
  1929. printk("do_softint: end\n");
  1930. #endif
  1931. }
  1932. static struct tty_operations aurora_ops = {
  1933. .open = aurora_open,
  1934. .close = aurora_close,
  1935. .write = aurora_write,
  1936. .put_char = aurora_put_char,
  1937. .flush_chars = aurora_flush_chars,
  1938. .write_room = aurora_write_room,
  1939. .chars_in_buffer = aurora_chars_in_buffer,
  1940. .flush_buffer = aurora_flush_buffer,
  1941. .ioctl = aurora_ioctl,
  1942. .throttle = aurora_throttle,
  1943. .unthrottle = aurora_unthrottle,
  1944. .set_termios = aurora_set_termios,
  1945. .stop = aurora_stop,
  1946. .start = aurora_start,
  1947. .hangup = aurora_hangup,
  1948. .tiocmget = aurora_tiocmget,
  1949. .tiocmset = aurora_tiocmset,
  1950. };
  1951. static int aurora_init_drivers(void)
  1952. {
  1953. int error;
  1954. int i;
  1955. #ifdef AURORA_DEBUG
  1956. printk("aurora_init_drivers: start\n");
  1957. #endif
  1958. tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL);
  1959. if (tmp_buf == NULL) {
  1960. printk(KERN_ERR "aurora: Couldn't get free page.\n");
  1961. return 1;
  1962. }
  1963. init_bh(AURORA_BH, do_aurora_bh);
  1964. aurora_driver = alloc_tty_driver(AURORA_INPORTS);
  1965. if (!aurora_driver) {
  1966. printk(KERN_ERR "aurora: Couldn't allocate tty driver.\n");
  1967. free_page((unsigned long) tmp_buf);
  1968. return 1;
  1969. }
  1970. aurora_driver->owner = THIS_MODULE;
  1971. aurora_driver->name = "ttyA";
  1972. aurora_driver->major = AURORA_MAJOR;
  1973. aurora_driver->type = TTY_DRIVER_TYPE_SERIAL;
  1974. aurora_driver->subtype = SERIAL_TYPE_NORMAL;
  1975. aurora_driver->init_termios = tty_std_termios;
  1976. aurora_driver->init_termios.c_cflag =
  1977. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  1978. aurora_driver->flags = TTY_DRIVER_REAL_RAW;
  1979. tty_set_operations(aurora_driver, &aurora_ops);
  1980. error = tty_register_driver(aurora_driver);
  1981. if (error) {
  1982. put_tty_driver(aurora_driver);
  1983. free_page((unsigned long) tmp_buf);
  1984. printk(KERN_ERR "aurora: Couldn't register aurora driver, error = %d\n",
  1985. error);
  1986. return 1;
  1987. }
  1988. memset(aurora_port, 0, sizeof(aurora_port));
  1989. for (i = 0; i < AURORA_TNPORTS; i++) {
  1990. aurora_port[i].magic = AURORA_MAGIC;
  1991. aurora_port[i].tqueue.routine = do_softint;
  1992. aurora_port[i].tqueue.data = &aurora_port[i];
  1993. aurora_port[i].tqueue_hangup.routine = do_aurora_hangup;
  1994. aurora_port[i].tqueue_hangup.data = &aurora_port[i];
  1995. aurora_port[i].close_delay = 50 * HZ/100;
  1996. aurora_port[i].closing_wait = 3000 * HZ/100;
  1997. init_waitqueue_head(&aurora_port[i].open_wait);
  1998. init_waitqueue_head(&aurora_port[i].close_wait);
  1999. }
  2000. #ifdef AURORA_DEBUG
  2001. printk("aurora_init_drivers: end\n");
  2002. #endif
  2003. return 0;
  2004. }
  2005. static void aurora_release_drivers(void)
  2006. {
  2007. #ifdef AURORA_DEBUG
  2008. printk("aurora_release_drivers: start\n");
  2009. #endif
  2010. free_page((unsigned long)tmp_buf);
  2011. tty_unregister_driver(aurora_driver);
  2012. put_tty_driver(aurora_driver);
  2013. #ifdef AURORA_DEBUG
  2014. printk("aurora_release_drivers: end\n");
  2015. #endif
  2016. }
  2017. /*
  2018. * Called at boot time.
  2019. *
  2020. * You can specify IO base for up to RC_NBOARD cards,
  2021. * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
  2022. * Note that there will be no probing at default
  2023. * addresses in this case.
  2024. *
  2025. */
  2026. void __init aurora_setup(char *str, int *ints)
  2027. {
  2028. int i;
  2029. for(i=0;(i<ints[0])&&(i<4);i++) {
  2030. if (ints[i+1]) irqs[i]=ints[i+1];
  2031. }
  2032. }
  2033. static int __init aurora_real_init(void)
  2034. {
  2035. int found;
  2036. int i;
  2037. printk(KERN_INFO "aurora: Driver starting.\n");
  2038. if(aurora_init_drivers())
  2039. return -EIO;
  2040. found = aurora_probe();
  2041. if(!found) {
  2042. aurora_release_drivers();
  2043. printk(KERN_INFO "aurora: No Aurora Multiport boards detected.\n");
  2044. return -EIO;
  2045. } else {
  2046. printk(KERN_INFO "aurora: %d boards found.\n", found);
  2047. }
  2048. for (i = 0; i < found; i++) {
  2049. int ret = aurora_setup_board(&aurora_board[i]);
  2050. if (ret) {
  2051. #ifdef AURORA_DEBUG
  2052. printk(KERN_ERR "aurora_init: error aurora_setup_board ret %d\n",
  2053. ret);
  2054. #endif
  2055. return ret;
  2056. }
  2057. }
  2058. return 0;
  2059. }
  2060. int irq = 0;
  2061. int irq1 = 0;
  2062. int irq2 = 0;
  2063. int irq3 = 0;
  2064. module_param(irq , int, 0);
  2065. module_param(irq1, int, 0);
  2066. module_param(irq2, int, 0);
  2067. module_param(irq3, int, 0);
  2068. static int __init aurora_init(void)
  2069. {
  2070. if (irq ) irqs[0]=irq ;
  2071. if (irq1) irqs[1]=irq1;
  2072. if (irq2) irqs[2]=irq2;
  2073. if (irq3) irqs[3]=irq3;
  2074. return aurora_real_init();
  2075. }
  2076. static void __exit aurora_cleanup(void)
  2077. {
  2078. int i;
  2079. #ifdef AURORA_DEBUG
  2080. printk("cleanup_module: aurora_release_drivers\n");
  2081. #endif
  2082. aurora_release_drivers();
  2083. for (i = 0; i < AURORA_NBOARD; i++)
  2084. if (aurora_board[i].flags & AURORA_BOARD_PRESENT) {
  2085. aurora_shutdown_board(&aurora_board[i]);
  2086. aurora_release_io_range(&aurora_board[i]);
  2087. }
  2088. }
  2089. module_init(aurora_init);
  2090. module_exit(aurora_cleanup);
  2091. MODULE_LICENSE("GPL");