serial167.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858
  1. /*
  2. * linux/drivers/char/serial167.c
  3. *
  4. * Driver for MVME166/7 board serial ports, which are via a CD2401.
  5. * Based very much on cyclades.c.
  6. *
  7. * MVME166/7 work by Richard Hirst [richard@sleepie.demon.co.uk]
  8. *
  9. * ==============================================================
  10. *
  11. * static char rcsid[] =
  12. * "$Revision: 1.36.1.4 $$Date: 1995/03/29 06:14:14 $";
  13. *
  14. * linux/kernel/cyclades.c
  15. *
  16. * Maintained by Marcio Saito (cyclades@netcom.com) and
  17. * Randolph Bentson (bentson@grieg.seaslug.org)
  18. *
  19. * Much of the design and some of the code came from serial.c
  20. * which was copyright (C) 1991, 1992 Linus Torvalds. It was
  21. * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92,
  22. * and then fixed as suggested by Michael K. Johnson 12/12/92.
  23. *
  24. * This version does not support shared irq's.
  25. *
  26. * $Log: cyclades.c,v $
  27. * Revision 1.36.1.4 1995/03/29 06:14:14 bentson
  28. * disambiguate between Cyclom-16Y and Cyclom-32Ye;
  29. *
  30. * Changes:
  31. *
  32. * 200 lines of changes record removed - RGH 11-10-95, starting work on
  33. * converting this to drive serial ports on mvme166 (cd2401).
  34. *
  35. * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 2000/08/25
  36. * - get rid of verify_area
  37. * - use get_user to access memory from userspace in set_threshold,
  38. * set_default_threshold and set_timeout
  39. * - don't use the panic function in serial167_init
  40. * - do resource release on failure on serial167_init
  41. * - include missing restore_flags in mvme167_serial_console_setup
  42. *
  43. * Kars de Jong <jongk@linux-m68k.org> - 2004/09/06
  44. * - replace bottom half handler with task queue handler
  45. */
  46. #include <linux/config.h>
  47. #include <linux/errno.h>
  48. #include <linux/signal.h>
  49. #include <linux/sched.h>
  50. #include <linux/timer.h>
  51. #include <linux/tty.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/serial.h>
  54. #include <linux/serialP.h>
  55. #include <linux/string.h>
  56. #include <linux/fcntl.h>
  57. #include <linux/ptrace.h>
  58. #include <linux/serial167.h>
  59. #include <linux/delay.h>
  60. #include <linux/major.h>
  61. #include <linux/mm.h>
  62. #include <linux/console.h>
  63. #include <linux/module.h>
  64. #include <linux/bitops.h>
  65. #include <asm/system.h>
  66. #include <asm/io.h>
  67. #include <asm/mvme16xhw.h>
  68. #include <asm/bootinfo.h>
  69. #include <asm/setup.h>
  70. #include <linux/types.h>
  71. #include <linux/kernel.h>
  72. #include <asm/uaccess.h>
  73. #include <linux/init.h>
  74. #define SERIAL_PARANOIA_CHECK
  75. #undef SERIAL_DEBUG_OPEN
  76. #undef SERIAL_DEBUG_THROTTLE
  77. #undef SERIAL_DEBUG_OTHER
  78. #undef SERIAL_DEBUG_IO
  79. #undef SERIAL_DEBUG_COUNT
  80. #undef SERIAL_DEBUG_DTR
  81. #undef CYCLOM_16Y_HACK
  82. #define CYCLOM_ENABLE_MONITORING
  83. #define WAKEUP_CHARS 256
  84. #define STD_COM_FLAGS (0)
  85. #define SERIAL_TYPE_NORMAL 1
  86. static struct tty_driver *cy_serial_driver;
  87. extern int serial_console;
  88. static struct cyclades_port *serial_console_info = NULL;
  89. static unsigned int serial_console_cflag = 0;
  90. u_char initial_console_speed;
  91. /* Base address of cd2401 chip on mvme166/7 */
  92. #define BASE_ADDR (0xfff45000)
  93. #define pcc2chip ((volatile u_char *)0xfff42000)
  94. #define PccSCCMICR 0x1d
  95. #define PccSCCTICR 0x1e
  96. #define PccSCCRICR 0x1f
  97. #define PccTPIACKR 0x25
  98. #define PccRPIACKR 0x27
  99. #define PccIMLR 0x3f
  100. /* This is the per-port data structure */
  101. struct cyclades_port cy_port[] = {
  102. /* CARD# */
  103. {-1 }, /* ttyS0 */
  104. {-1 }, /* ttyS1 */
  105. {-1 }, /* ttyS2 */
  106. {-1 }, /* ttyS3 */
  107. };
  108. #define NR_PORTS (sizeof(cy_port)/sizeof(struct cyclades_port))
  109. /*
  110. * tmp_buf is used as a temporary buffer by serial_write. We need to
  111. * lock it in case the copy_from_user blocks while swapping in a page,
  112. * and some other program tries to do a serial write at the same time.
  113. * Since the lock will only come under contention when the system is
  114. * swapping and available memory is low, it makes sense to share one
  115. * buffer across all the serial ports, since it significantly saves
  116. * memory if large numbers of serial ports are open.
  117. */
  118. static unsigned char *tmp_buf = 0;
  119. DECLARE_MUTEX(tmp_buf_sem);
  120. /*
  121. * This is used to look up the divisor speeds and the timeouts
  122. * We're normally limited to 15 distinct baud rates. The extra
  123. * are accessed via settings in info->flags.
  124. * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  125. * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  126. * HI VHI
  127. */
  128. static int baud_table[] = {
  129. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
  130. 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000,
  131. 0};
  132. #if 0
  133. static char baud_co[] = { /* 25 MHz clock option table */
  134. /* value => 00 01 02 03 04 */
  135. /* divide by 8 32 128 512 2048 */
  136. 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
  137. 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  138. static char baud_bpr[] = { /* 25 MHz baud rate period table */
  139. 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
  140. 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15};
  141. #endif
  142. /* I think 166 brd clocks 2401 at 20MHz.... */
  143. /* These values are written directly to tcor, and >> 5 for writing to rcor */
  144. static u_char baud_co[] = { /* 20 MHz clock option table */
  145. 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x60, 0x60, 0x40,
  146. 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  147. /* These values written directly to tbpr/rbpr */
  148. static u_char baud_bpr[] = { /* 20 MHz baud rate period table */
  149. 0x00, 0xc0, 0x80, 0x58, 0x6c, 0x40, 0xc0, 0x81, 0x40, 0x81,
  150. 0x57, 0x40, 0x81, 0x40, 0x81, 0x40, 0x2b, 0x20, 0x15, 0x10};
  151. static u_char baud_cor4[] = { /* receive threshold */
  152. 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  153. 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07};
  154. static void shutdown(struct cyclades_port *);
  155. static int startup (struct cyclades_port *);
  156. static void cy_throttle(struct tty_struct *);
  157. static void cy_unthrottle(struct tty_struct *);
  158. static void config_setup(struct cyclades_port *);
  159. extern void console_print(const char *);
  160. #ifdef CYCLOM_SHOW_STATUS
  161. static void show_status(int);
  162. #endif
  163. #ifdef CONFIG_REMOTE_DEBUG
  164. static void debug_setup(void);
  165. void queueDebugChar (int c);
  166. int getDebugChar(void);
  167. #define DEBUG_PORT 1
  168. #define DEBUG_LEN 256
  169. typedef struct {
  170. int in;
  171. int out;
  172. unsigned char buf[DEBUG_LEN];
  173. } debugq;
  174. debugq debugiq;
  175. #endif
  176. /*
  177. * I have my own version of udelay(), as it is needed when initialising
  178. * the chip, before the delay loop has been calibrated. Should probably
  179. * reference one of the vmechip2 or pccchip2 counter for an accurate
  180. * delay, but this wild guess will do for now.
  181. */
  182. void my_udelay (long us)
  183. {
  184. u_char x;
  185. volatile u_char *p = &x;
  186. int i;
  187. while (us--)
  188. for (i = 100; i; i--)
  189. x |= *p;
  190. }
  191. static inline int
  192. serial_paranoia_check(struct cyclades_port *info, char *name,
  193. const char *routine)
  194. {
  195. #ifdef SERIAL_PARANOIA_CHECK
  196. static const char *badmagic =
  197. "Warning: bad magic number for serial struct (%s) in %s\n";
  198. static const char *badinfo =
  199. "Warning: null cyclades_port for (%s) in %s\n";
  200. static const char *badrange =
  201. "Warning: cyclades_port out of range for (%s) in %s\n";
  202. if (!info) {
  203. printk(badinfo, name, routine);
  204. return 1;
  205. }
  206. if( (long)info < (long)(&cy_port[0])
  207. || (long)(&cy_port[NR_PORTS]) < (long)info ){
  208. printk(badrange, name, routine);
  209. return 1;
  210. }
  211. if (info->magic != CYCLADES_MAGIC) {
  212. printk(badmagic, name, routine);
  213. return 1;
  214. }
  215. #endif
  216. return 0;
  217. } /* serial_paranoia_check */
  218. #if 0
  219. /* The following diagnostic routines allow the driver to spew
  220. information on the screen, even (especially!) during interrupts.
  221. */
  222. void
  223. SP(char *data){
  224. unsigned long flags;
  225. local_irq_save(flags);
  226. console_print(data);
  227. local_irq_restore(flags);
  228. }
  229. char scrn[2];
  230. void
  231. CP(char data){
  232. unsigned long flags;
  233. local_irq_save(flags);
  234. scrn[0] = data;
  235. console_print(scrn);
  236. local_irq_restore(flags);
  237. }/* CP */
  238. void CP1(int data) { (data<10)? CP(data+'0'): CP(data+'A'-10); }/* CP1 */
  239. void CP2(int data) { CP1((data>>4) & 0x0f); CP1( data & 0x0f); }/* CP2 */
  240. void CP4(int data) { CP2((data>>8) & 0xff); CP2(data & 0xff); }/* CP4 */
  241. void CP8(long data) { CP4((data>>16) & 0xffff); CP4(data & 0xffff); }/* CP8 */
  242. #endif
  243. /* This routine waits up to 1000 micro-seconds for the previous
  244. command to the Cirrus chip to complete and then issues the
  245. new command. An error is returned if the previous command
  246. didn't finish within the time limit.
  247. */
  248. u_short
  249. write_cy_cmd(volatile u_char *base_addr, u_char cmd)
  250. {
  251. unsigned long flags;
  252. volatile int i;
  253. local_irq_save(flags);
  254. /* Check to see that the previous command has completed */
  255. for(i = 0 ; i < 100 ; i++){
  256. if (base_addr[CyCCR] == 0){
  257. break;
  258. }
  259. my_udelay(10L);
  260. }
  261. /* if the CCR never cleared, the previous command
  262. didn't finish within the "reasonable time" */
  263. if ( i == 10 ) {
  264. local_irq_restore(flags);
  265. return (-1);
  266. }
  267. /* Issue the new command */
  268. base_addr[CyCCR] = cmd;
  269. local_irq_restore(flags);
  270. return(0);
  271. } /* write_cy_cmd */
  272. /* cy_start and cy_stop provide software output flow control as a
  273. function of XON/XOFF, software CTS, and other such stuff. */
  274. static void
  275. cy_stop(struct tty_struct *tty)
  276. {
  277. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  278. volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
  279. int channel;
  280. unsigned long flags;
  281. #ifdef SERIAL_DEBUG_OTHER
  282. printk("cy_stop %s\n", tty->name); /* */
  283. #endif
  284. if (serial_paranoia_check(info, tty->name, "cy_stop"))
  285. return;
  286. channel = info->line;
  287. local_irq_save(flags);
  288. base_addr[CyCAR] = (u_char)(channel); /* index channel */
  289. base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
  290. local_irq_restore(flags);
  291. return;
  292. } /* cy_stop */
  293. static void
  294. cy_start(struct tty_struct *tty)
  295. {
  296. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  297. volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
  298. int channel;
  299. unsigned long flags;
  300. #ifdef SERIAL_DEBUG_OTHER
  301. printk("cy_start %s\n", tty->name); /* */
  302. #endif
  303. if (serial_paranoia_check(info, tty->name, "cy_start"))
  304. return;
  305. channel = info->line;
  306. local_irq_save(flags);
  307. base_addr[CyCAR] = (u_char)(channel);
  308. base_addr[CyIER] |= CyTxMpty;
  309. local_irq_restore(flags);
  310. return;
  311. } /* cy_start */
  312. /*
  313. * This routine is used by the interrupt handler to schedule
  314. * processing in the software interrupt portion of the driver
  315. * (also known as the "bottom half"). This can be called any
  316. * number of times for any channel without harm.
  317. */
  318. static inline void
  319. cy_sched_event(struct cyclades_port *info, int event)
  320. {
  321. info->event |= 1 << event; /* remember what kind of event and who */
  322. schedule_work(&info->tqueue);
  323. } /* cy_sched_event */
  324. /* The real interrupt service routines are called
  325. whenever the card wants its hand held--chars
  326. received, out buffer empty, modem change, etc.
  327. */
  328. static irqreturn_t
  329. cd2401_rxerr_interrupt(int irq, void *dev_id, struct pt_regs *fp)
  330. {
  331. struct tty_struct *tty;
  332. struct cyclades_port *info;
  333. volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
  334. unsigned char err, rfoc;
  335. int channel;
  336. char data;
  337. /* determine the channel and change to that context */
  338. channel = (u_short ) (base_addr[CyLICR] >> 2);
  339. info = &cy_port[channel];
  340. info->last_active = jiffies;
  341. if ((err = base_addr[CyRISR]) & CyTIMEOUT) {
  342. /* This is a receive timeout interrupt, ignore it */
  343. base_addr[CyREOIR] = CyNOTRANS;
  344. return IRQ_HANDLED;
  345. }
  346. /* Read a byte of data if there is any - assume the error
  347. * is associated with this character */
  348. if ((rfoc = base_addr[CyRFOC]) != 0)
  349. data = base_addr[CyRDR];
  350. else
  351. data = 0;
  352. /* if there is nowhere to put the data, discard it */
  353. if(info->tty == 0) {
  354. base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
  355. return IRQ_HANDLED;
  356. }
  357. else { /* there is an open port for this data */
  358. tty = info->tty;
  359. if(err & info->ignore_status_mask){
  360. base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
  361. return IRQ_HANDLED;
  362. }
  363. if (tty->flip.count < TTY_FLIPBUF_SIZE){
  364. tty->flip.count++;
  365. if (err & info->read_status_mask){
  366. if(err & CyBREAK){
  367. *tty->flip.flag_buf_ptr++ = TTY_BREAK;
  368. *tty->flip.char_buf_ptr++ = data;
  369. if (info->flags & ASYNC_SAK){
  370. do_SAK(tty);
  371. }
  372. }else if(err & CyFRAME){
  373. *tty->flip.flag_buf_ptr++ = TTY_FRAME;
  374. *tty->flip.char_buf_ptr++ = data;
  375. }else if(err & CyPARITY){
  376. *tty->flip.flag_buf_ptr++ = TTY_PARITY;
  377. *tty->flip.char_buf_ptr++ = data;
  378. }else if(err & CyOVERRUN){
  379. *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
  380. *tty->flip.char_buf_ptr++ = 0;
  381. /*
  382. If the flip buffer itself is
  383. overflowing, we still loose
  384. the next incoming character.
  385. */
  386. if(tty->flip.count < TTY_FLIPBUF_SIZE){
  387. tty->flip.count++;
  388. *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
  389. *tty->flip.char_buf_ptr++ = data;
  390. }
  391. /* These two conditions may imply */
  392. /* a normal read should be done. */
  393. /* else if(data & CyTIMEOUT) */
  394. /* else if(data & CySPECHAR) */
  395. }else{
  396. *tty->flip.flag_buf_ptr++ = 0;
  397. *tty->flip.char_buf_ptr++ = 0;
  398. }
  399. }else{
  400. *tty->flip.flag_buf_ptr++ = 0;
  401. *tty->flip.char_buf_ptr++ = 0;
  402. }
  403. }else{
  404. /* there was a software buffer overrun
  405. and nothing could be done about it!!! */
  406. }
  407. }
  408. schedule_delayed_work(&tty->flip.work, 1);
  409. /* end of service */
  410. base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
  411. return IRQ_HANDLED;
  412. } /* cy_rxerr_interrupt */
  413. static irqreturn_t
  414. cd2401_modem_interrupt(int irq, void *dev_id, struct pt_regs *fp)
  415. {
  416. struct cyclades_port *info;
  417. volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
  418. int channel;
  419. int mdm_change;
  420. int mdm_status;
  421. /* determine the channel and change to that context */
  422. channel = (u_short ) (base_addr[CyLICR] >> 2);
  423. info = &cy_port[channel];
  424. info->last_active = jiffies;
  425. mdm_change = base_addr[CyMISR];
  426. mdm_status = base_addr[CyMSVR1];
  427. if(info->tty == 0){ /* nowhere to put the data, ignore it */
  428. ;
  429. }else{
  430. if((mdm_change & CyDCD)
  431. && (info->flags & ASYNC_CHECK_CD)){
  432. if(mdm_status & CyDCD){
  433. /* CP('!'); */
  434. cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP);
  435. } else {
  436. /* CP('@'); */
  437. cy_sched_event(info, Cy_EVENT_HANGUP);
  438. }
  439. }
  440. if((mdm_change & CyCTS)
  441. && (info->flags & ASYNC_CTS_FLOW)){
  442. if(info->tty->stopped){
  443. if(mdm_status & CyCTS){
  444. /* !!! cy_start isn't used because... */
  445. info->tty->stopped = 0;
  446. base_addr[CyIER] |= CyTxMpty;
  447. cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
  448. }
  449. }else{
  450. if(!(mdm_status & CyCTS)){
  451. /* !!! cy_stop isn't used because... */
  452. info->tty->stopped = 1;
  453. base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
  454. }
  455. }
  456. }
  457. if(mdm_status & CyDSR){
  458. }
  459. }
  460. base_addr[CyMEOIR] = 0;
  461. return IRQ_HANDLED;
  462. } /* cy_modem_interrupt */
  463. static irqreturn_t
  464. cd2401_tx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
  465. {
  466. struct cyclades_port *info;
  467. volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
  468. int channel;
  469. int char_count, saved_cnt;
  470. int outch;
  471. /* determine the channel and change to that context */
  472. channel = (u_short ) (base_addr[CyLICR] >> 2);
  473. #ifdef CONFIG_REMOTE_DEBUG
  474. if (channel == DEBUG_PORT) {
  475. panic ("TxInt on debug port!!!");
  476. }
  477. #endif
  478. info = &cy_port[channel];
  479. /* validate the port number (as configured and open) */
  480. if( (channel < 0) || (NR_PORTS <= channel) ){
  481. base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
  482. base_addr[CyTEOIR] = CyNOTRANS;
  483. return IRQ_HANDLED;
  484. }
  485. info->last_active = jiffies;
  486. if(info->tty == 0){
  487. base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
  488. if (info->xmit_cnt < WAKEUP_CHARS) {
  489. cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
  490. }
  491. base_addr[CyTEOIR] = CyNOTRANS;
  492. return IRQ_HANDLED;
  493. }
  494. /* load the on-chip space available for outbound data */
  495. saved_cnt = char_count = base_addr[CyTFTC];
  496. if(info->x_char) { /* send special char */
  497. outch = info->x_char;
  498. base_addr[CyTDR] = outch;
  499. char_count--;
  500. info->x_char = 0;
  501. }
  502. if (info->x_break){
  503. /* The Cirrus chip requires the "Embedded Transmit
  504. Commands" of start break, delay, and end break
  505. sequences to be sent. The duration of the
  506. break is given in TICs, which runs at HZ
  507. (typically 100) and the PPR runs at 200 Hz,
  508. so the delay is duration * 200/HZ, and thus a
  509. break can run from 1/100 sec to about 5/4 sec.
  510. Need to check these values - RGH 141095.
  511. */
  512. base_addr[CyTDR] = 0; /* start break */
  513. base_addr[CyTDR] = 0x81;
  514. base_addr[CyTDR] = 0; /* delay a bit */
  515. base_addr[CyTDR] = 0x82;
  516. base_addr[CyTDR] = info->x_break*200/HZ;
  517. base_addr[CyTDR] = 0; /* terminate break */
  518. base_addr[CyTDR] = 0x83;
  519. char_count -= 7;
  520. info->x_break = 0;
  521. }
  522. while (char_count > 0){
  523. if (!info->xmit_cnt){
  524. base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
  525. break;
  526. }
  527. if (info->xmit_buf == 0){
  528. base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
  529. break;
  530. }
  531. if (info->tty->stopped || info->tty->hw_stopped){
  532. base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
  533. break;
  534. }
  535. /* Because the Embedded Transmit Commands have been
  536. enabled, we must check to see if the escape
  537. character, NULL, is being sent. If it is, we
  538. must ensure that there is room for it to be
  539. doubled in the output stream. Therefore we
  540. no longer advance the pointer when the character
  541. is fetched, but rather wait until after the check
  542. for a NULL output character. (This is necessary
  543. because there may not be room for the two chars
  544. needed to send a NULL.
  545. */
  546. outch = info->xmit_buf[info->xmit_tail];
  547. if( outch ){
  548. info->xmit_cnt--;
  549. info->xmit_tail = (info->xmit_tail + 1)
  550. & (PAGE_SIZE - 1);
  551. base_addr[CyTDR] = outch;
  552. char_count--;
  553. }else{
  554. if(char_count > 1){
  555. info->xmit_cnt--;
  556. info->xmit_tail = (info->xmit_tail + 1)
  557. & (PAGE_SIZE - 1);
  558. base_addr[CyTDR] = outch;
  559. base_addr[CyTDR] = 0;
  560. char_count--;
  561. char_count--;
  562. }else{
  563. break;
  564. }
  565. }
  566. }
  567. if (info->xmit_cnt < WAKEUP_CHARS) {
  568. cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
  569. }
  570. base_addr[CyTEOIR] = (char_count != saved_cnt) ? 0 : CyNOTRANS;
  571. return IRQ_HANDLED;
  572. } /* cy_tx_interrupt */
  573. static irqreturn_t
  574. cd2401_rx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
  575. {
  576. struct tty_struct *tty;
  577. struct cyclades_port *info;
  578. volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
  579. int channel;
  580. char data;
  581. int char_count;
  582. int save_cnt;
  583. /* determine the channel and change to that context */
  584. channel = (u_short ) (base_addr[CyLICR] >> 2);
  585. info = &cy_port[channel];
  586. info->last_active = jiffies;
  587. save_cnt = char_count = base_addr[CyRFOC];
  588. #ifdef CONFIG_REMOTE_DEBUG
  589. if (channel == DEBUG_PORT) {
  590. while (char_count--) {
  591. data = base_addr[CyRDR];
  592. queueDebugChar(data);
  593. }
  594. }
  595. else
  596. #endif
  597. /* if there is nowhere to put the data, discard it */
  598. if(info->tty == 0){
  599. while(char_count--){
  600. data = base_addr[CyRDR];
  601. }
  602. }else{ /* there is an open port for this data */
  603. tty = info->tty;
  604. /* load # characters available from the chip */
  605. #ifdef CYCLOM_ENABLE_MONITORING
  606. ++info->mon.int_count;
  607. info->mon.char_count += char_count;
  608. if (char_count > info->mon.char_max)
  609. info->mon.char_max = char_count;
  610. info->mon.char_last = char_count;
  611. #endif
  612. while(char_count--){
  613. data = base_addr[CyRDR];
  614. if (tty->flip.count >= TTY_FLIPBUF_SIZE){
  615. continue;
  616. }
  617. tty->flip.count++;
  618. *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
  619. *tty->flip.char_buf_ptr++ = data;
  620. #ifdef CYCLOM_16Y_HACK
  621. udelay(10L);
  622. #endif
  623. }
  624. schedule_delayed_work(&tty->flip.work, 1);
  625. }
  626. /* end of service */
  627. base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS;
  628. return IRQ_HANDLED;
  629. } /* cy_rx_interrupt */
  630. /*
  631. * This routine is used to handle the "bottom half" processing for the
  632. * serial driver, known also the "software interrupt" processing.
  633. * This processing is done at the kernel interrupt level, after the
  634. * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
  635. * is where time-consuming activities which can not be done in the
  636. * interrupt driver proper are done; the interrupt driver schedules
  637. * them using cy_sched_event(), and they get done here.
  638. *
  639. * This is done through one level of indirection--the task queue.
  640. * When a hardware interrupt service routine wants service by the
  641. * driver's bottom half, it enqueues the appropriate tq_struct (one
  642. * per port) to the keventd work queue and sets a request flag
  643. * that the work queue be processed.
  644. *
  645. * Although this may seem unwieldy, it gives the system a way to
  646. * pass an argument (in this case the pointer to the cyclades_port
  647. * structure) to the bottom half of the driver. Previous kernels
  648. * had to poll every port to see if that port needed servicing.
  649. */
  650. static void
  651. do_softint(void *private_)
  652. {
  653. struct cyclades_port *info = (struct cyclades_port *) private_;
  654. struct tty_struct *tty;
  655. tty = info->tty;
  656. if (!tty)
  657. return;
  658. if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
  659. tty_hangup(info->tty);
  660. wake_up_interruptible(&info->open_wait);
  661. info->flags &= ~ASYNC_NORMAL_ACTIVE;
  662. }
  663. if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) {
  664. wake_up_interruptible(&info->open_wait);
  665. }
  666. if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
  667. tty_wakeup(tty);
  668. }
  669. } /* do_softint */
  670. /* This is called whenever a port becomes active;
  671. interrupts are enabled and DTR & RTS are turned on.
  672. */
  673. static int
  674. startup(struct cyclades_port * info)
  675. {
  676. unsigned long flags;
  677. volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
  678. int channel;
  679. if (info->flags & ASYNC_INITIALIZED){
  680. return 0;
  681. }
  682. if (!info->type){
  683. if (info->tty){
  684. set_bit(TTY_IO_ERROR, &info->tty->flags);
  685. }
  686. return 0;
  687. }
  688. if (!info->xmit_buf){
  689. info->xmit_buf = (unsigned char *) get_zeroed_page (GFP_KERNEL);
  690. if (!info->xmit_buf){
  691. return -ENOMEM;
  692. }
  693. }
  694. config_setup(info);
  695. channel = info->line;
  696. #ifdef SERIAL_DEBUG_OPEN
  697. printk("startup channel %d\n", channel);
  698. #endif
  699. local_irq_save(flags);
  700. base_addr[CyCAR] = (u_char)channel;
  701. write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR);
  702. base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */
  703. base_addr[CyMSVR1] = CyRTS;
  704. /* CP('S');CP('1'); */
  705. base_addr[CyMSVR2] = CyDTR;
  706. #ifdef SERIAL_DEBUG_DTR
  707. printk("cyc: %d: raising DTR\n", __LINE__);
  708. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
  709. #endif
  710. base_addr[CyIER] |= CyRxData;
  711. info->flags |= ASYNC_INITIALIZED;
  712. if (info->tty){
  713. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  714. }
  715. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  716. local_irq_restore(flags);
  717. #ifdef SERIAL_DEBUG_OPEN
  718. printk(" done\n");
  719. #endif
  720. return 0;
  721. } /* startup */
  722. void
  723. start_xmit( struct cyclades_port *info )
  724. {
  725. unsigned long flags;
  726. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  727. int channel;
  728. channel = info->line;
  729. local_irq_save(flags);
  730. base_addr[CyCAR] = channel;
  731. base_addr[CyIER] |= CyTxMpty;
  732. local_irq_restore(flags);
  733. } /* start_xmit */
  734. /*
  735. * This routine shuts down a serial port; interrupts are disabled,
  736. * and DTR is dropped if the hangup on close termio flag is on.
  737. */
  738. static void
  739. shutdown(struct cyclades_port * info)
  740. {
  741. unsigned long flags;
  742. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  743. int channel;
  744. if (!(info->flags & ASYNC_INITIALIZED)){
  745. /* CP('$'); */
  746. return;
  747. }
  748. channel = info->line;
  749. #ifdef SERIAL_DEBUG_OPEN
  750. printk("shutdown channel %d\n", channel);
  751. #endif
  752. /* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE
  753. SENT BEFORE DROPPING THE LINE !!! (Perhaps
  754. set some flag that is read when XMTY happens.)
  755. Other choices are to delay some fixed interval
  756. or schedule some later processing.
  757. */
  758. local_irq_save(flags);
  759. if (info->xmit_buf){
  760. free_page((unsigned long) info->xmit_buf);
  761. info->xmit_buf = 0;
  762. }
  763. base_addr[CyCAR] = (u_char)channel;
  764. if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
  765. base_addr[CyMSVR1] = 0;
  766. /* CP('C');CP('1'); */
  767. base_addr[CyMSVR2] = 0;
  768. #ifdef SERIAL_DEBUG_DTR
  769. printk("cyc: %d: dropping DTR\n", __LINE__);
  770. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
  771. #endif
  772. }
  773. write_cy_cmd(base_addr,CyDIS_RCVR);
  774. /* it may be appropriate to clear _XMIT at
  775. some later date (after testing)!!! */
  776. if (info->tty){
  777. set_bit(TTY_IO_ERROR, &info->tty->flags);
  778. }
  779. info->flags &= ~ASYNC_INITIALIZED;
  780. local_irq_restore(flags);
  781. #ifdef SERIAL_DEBUG_OPEN
  782. printk(" done\n");
  783. #endif
  784. return;
  785. } /* shutdown */
  786. /*
  787. * This routine finds or computes the various line characteristics.
  788. */
  789. static void
  790. config_setup(struct cyclades_port * info)
  791. {
  792. unsigned long flags;
  793. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  794. int channel;
  795. unsigned cflag;
  796. int i;
  797. unsigned char ti, need_init_chan = 0;
  798. if (!info->tty || !info->tty->termios){
  799. return;
  800. }
  801. if (info->line == -1){
  802. return;
  803. }
  804. cflag = info->tty->termios->c_cflag;
  805. /* baud rate */
  806. i = cflag & CBAUD;
  807. #ifdef CBAUDEX
  808. /* Starting with kernel 1.1.65, there is direct support for
  809. higher baud rates. The following code supports those
  810. changes. The conditional aspect allows this driver to be
  811. used for earlier as well as later kernel versions. (The
  812. mapping is slightly different from serial.c because there
  813. is still the possibility of supporting 75 kbit/sec with
  814. the Cyclades board.)
  815. */
  816. if (i & CBAUDEX) {
  817. if (i == B57600)
  818. i = 16;
  819. else if(i == B115200)
  820. i = 18;
  821. #ifdef B78600
  822. else if(i == B78600)
  823. i = 17;
  824. #endif
  825. else
  826. info->tty->termios->c_cflag &= ~CBAUDEX;
  827. }
  828. #endif
  829. if (i == 15) {
  830. if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  831. i += 1;
  832. if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  833. i += 3;
  834. }
  835. /* Don't ever change the speed of the console port. It will
  836. * run at the speed specified in bootinfo, or at 19.2K */
  837. /* Actually, it should run at whatever speed 166Bug was using */
  838. /* Note info->timeout isn't used at present */
  839. if (info != serial_console_info) {
  840. info->tbpr = baud_bpr[i]; /* Tx BPR */
  841. info->tco = baud_co[i]; /* Tx CO */
  842. info->rbpr = baud_bpr[i]; /* Rx BPR */
  843. info->rco = baud_co[i] >> 5; /* Rx CO */
  844. if (baud_table[i] == 134) {
  845. info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
  846. /* get it right for 134.5 baud */
  847. } else if (baud_table[i]) {
  848. info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2;
  849. /* this needs to be propagated into the card info */
  850. } else {
  851. info->timeout = 0;
  852. }
  853. }
  854. /* By tradition (is it a standard?) a baud rate of zero
  855. implies the line should be/has been closed. A bit
  856. later in this routine such a test is performed. */
  857. /* byte size and parity */
  858. info->cor7 = 0;
  859. info->cor6 = 0;
  860. info->cor5 = 0;
  861. info->cor4 = (info->default_threshold
  862. ? info->default_threshold
  863. : baud_cor4[i]); /* receive threshold */
  864. /* Following two lines added 101295, RGH. */
  865. /* It is obviously wrong to access CyCORx, and not info->corx here,
  866. * try and remember to fix it later! */
  867. channel = info->line;
  868. base_addr[CyCAR] = (u_char)channel;
  869. if (C_CLOCAL(info->tty)) {
  870. if (base_addr[CyIER] & CyMdmCh)
  871. base_addr[CyIER] &= ~CyMdmCh; /* without modem intr */
  872. /* ignore 1->0 modem transitions */
  873. if (base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD))
  874. base_addr[CyCOR4] &= ~(CyDSR|CyCTS|CyDCD);
  875. /* ignore 0->1 modem transitions */
  876. if (base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD))
  877. base_addr[CyCOR5] &= ~(CyDSR|CyCTS|CyDCD);
  878. } else {
  879. if ((base_addr[CyIER] & CyMdmCh) != CyMdmCh)
  880. base_addr[CyIER] |= CyMdmCh; /* with modem intr */
  881. /* act on 1->0 modem transitions */
  882. if ((base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD))
  883. base_addr[CyCOR4] |= CyDSR|CyCTS|CyDCD;
  884. /* act on 0->1 modem transitions */
  885. if ((base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD))
  886. base_addr[CyCOR5] |= CyDSR|CyCTS|CyDCD;
  887. }
  888. info->cor3 = (cflag & CSTOPB) ? Cy_2_STOP : Cy_1_STOP;
  889. info->cor2 = CyETC;
  890. switch(cflag & CSIZE){
  891. case CS5:
  892. info->cor1 = Cy_5_BITS;
  893. break;
  894. case CS6:
  895. info->cor1 = Cy_6_BITS;
  896. break;
  897. case CS7:
  898. info->cor1 = Cy_7_BITS;
  899. break;
  900. case CS8:
  901. info->cor1 = Cy_8_BITS;
  902. break;
  903. }
  904. if (cflag & PARENB){
  905. if (cflag & PARODD){
  906. info->cor1 |= CyPARITY_O;
  907. }else{
  908. info->cor1 |= CyPARITY_E;
  909. }
  910. }else{
  911. info->cor1 |= CyPARITY_NONE;
  912. }
  913. /* CTS flow control flag */
  914. #if 0
  915. /* Don't complcate matters for now! RGH 141095 */
  916. if (cflag & CRTSCTS){
  917. info->flags |= ASYNC_CTS_FLOW;
  918. info->cor2 |= CyCtsAE;
  919. }else{
  920. info->flags &= ~ASYNC_CTS_FLOW;
  921. info->cor2 &= ~CyCtsAE;
  922. }
  923. #endif
  924. if (cflag & CLOCAL)
  925. info->flags &= ~ASYNC_CHECK_CD;
  926. else
  927. info->flags |= ASYNC_CHECK_CD;
  928. /***********************************************
  929. The hardware option, CyRtsAO, presents RTS when
  930. the chip has characters to send. Since most modems
  931. use RTS as reverse (inbound) flow control, this
  932. option is not used. If inbound flow control is
  933. necessary, DTR can be programmed to provide the
  934. appropriate signals for use with a non-standard
  935. cable. Contact Marcio Saito for details.
  936. ***********************************************/
  937. channel = info->line;
  938. local_irq_save(flags);
  939. base_addr[CyCAR] = (u_char)channel;
  940. /* CyCMR set once only in mvme167_init_serial() */
  941. if (base_addr[CyLICR] != channel << 2)
  942. base_addr[CyLICR] = channel << 2;
  943. if (base_addr[CyLIVR] != 0x5c)
  944. base_addr[CyLIVR] = 0x5c;
  945. /* tx and rx baud rate */
  946. if (base_addr[CyCOR1] != info->cor1)
  947. need_init_chan = 1;
  948. if (base_addr[CyTCOR] != info->tco)
  949. base_addr[CyTCOR] = info->tco;
  950. if (base_addr[CyTBPR] != info->tbpr)
  951. base_addr[CyTBPR] = info->tbpr;
  952. if (base_addr[CyRCOR] != info->rco)
  953. base_addr[CyRCOR] = info->rco;
  954. if (base_addr[CyRBPR] != info->rbpr)
  955. base_addr[CyRBPR] = info->rbpr;
  956. /* set line characteristics according configuration */
  957. if (base_addr[CySCHR1] != START_CHAR(info->tty))
  958. base_addr[CySCHR1] = START_CHAR(info->tty);
  959. if (base_addr[CySCHR2] != STOP_CHAR(info->tty))
  960. base_addr[CySCHR2] = STOP_CHAR(info->tty);
  961. if (base_addr[CySCRL] != START_CHAR(info->tty))
  962. base_addr[CySCRL] = START_CHAR(info->tty);
  963. if (base_addr[CySCRH] != START_CHAR(info->tty))
  964. base_addr[CySCRH] = START_CHAR(info->tty);
  965. if (base_addr[CyCOR1] != info->cor1)
  966. base_addr[CyCOR1] = info->cor1;
  967. if (base_addr[CyCOR2] != info->cor2)
  968. base_addr[CyCOR2] = info->cor2;
  969. if (base_addr[CyCOR3] != info->cor3)
  970. base_addr[CyCOR3] = info->cor3;
  971. if (base_addr[CyCOR4] != info->cor4)
  972. base_addr[CyCOR4] = info->cor4;
  973. if (base_addr[CyCOR5] != info->cor5)
  974. base_addr[CyCOR5] = info->cor5;
  975. if (base_addr[CyCOR6] != info->cor6)
  976. base_addr[CyCOR6] = info->cor6;
  977. if (base_addr[CyCOR7] != info->cor7)
  978. base_addr[CyCOR7] = info->cor7;
  979. if (need_init_chan)
  980. write_cy_cmd(base_addr,CyINIT_CHAN);
  981. base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */
  982. /* 2ms default rx timeout */
  983. ti = info->default_timeout ? info->default_timeout : 0x02;
  984. if (base_addr[CyRTPRL] != ti)
  985. base_addr[CyRTPRL] = ti;
  986. if (base_addr[CyRTPRH] != 0)
  987. base_addr[CyRTPRH] = 0;
  988. /* Set up RTS here also ????? RGH 141095 */
  989. if(i == 0){ /* baud rate is zero, turn off line */
  990. if ((base_addr[CyMSVR2] & CyDTR) == CyDTR)
  991. base_addr[CyMSVR2] = 0;
  992. #ifdef SERIAL_DEBUG_DTR
  993. printk("cyc: %d: dropping DTR\n", __LINE__);
  994. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
  995. #endif
  996. }else{
  997. if ((base_addr[CyMSVR2] & CyDTR) != CyDTR)
  998. base_addr[CyMSVR2] = CyDTR;
  999. #ifdef SERIAL_DEBUG_DTR
  1000. printk("cyc: %d: raising DTR\n", __LINE__);
  1001. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
  1002. #endif
  1003. }
  1004. if (info->tty){
  1005. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  1006. }
  1007. local_irq_restore(flags);
  1008. } /* config_setup */
  1009. static void
  1010. cy_put_char(struct tty_struct *tty, unsigned char ch)
  1011. {
  1012. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1013. unsigned long flags;
  1014. #ifdef SERIAL_DEBUG_IO
  1015. printk("cy_put_char %s(0x%02x)\n", tty->name, ch);
  1016. #endif
  1017. if (serial_paranoia_check(info, tty->name, "cy_put_char"))
  1018. return;
  1019. if (!tty || !info->xmit_buf)
  1020. return;
  1021. local_irq_save(flags);
  1022. if (info->xmit_cnt >= PAGE_SIZE - 1) {
  1023. local_irq_restore(flags);
  1024. return;
  1025. }
  1026. info->xmit_buf[info->xmit_head++] = ch;
  1027. info->xmit_head &= PAGE_SIZE - 1;
  1028. info->xmit_cnt++;
  1029. local_irq_restore(flags);
  1030. } /* cy_put_char */
  1031. static void
  1032. cy_flush_chars(struct tty_struct *tty)
  1033. {
  1034. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1035. unsigned long flags;
  1036. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  1037. int channel;
  1038. #ifdef SERIAL_DEBUG_IO
  1039. printk("cy_flush_chars %s\n", tty->name); /* */
  1040. #endif
  1041. if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
  1042. return;
  1043. if (info->xmit_cnt <= 0 || tty->stopped
  1044. || tty->hw_stopped || !info->xmit_buf)
  1045. return;
  1046. channel = info->line;
  1047. local_irq_save(flags);
  1048. base_addr[CyCAR] = channel;
  1049. base_addr[CyIER] |= CyTxMpty;
  1050. local_irq_restore(flags);
  1051. } /* cy_flush_chars */
  1052. /* This routine gets called when tty_write has put something into
  1053. the write_queue. If the port is not already transmitting stuff,
  1054. start it off by enabling interrupts. The interrupt service
  1055. routine will then ensure that the characters are sent. If the
  1056. port is already active, there is no need to kick it.
  1057. */
  1058. static int
  1059. cy_write(struct tty_struct * tty,
  1060. const unsigned char *buf, int count)
  1061. {
  1062. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1063. unsigned long flags;
  1064. int c, total = 0;
  1065. #ifdef SERIAL_DEBUG_IO
  1066. printk("cy_write %s\n", tty->name); /* */
  1067. #endif
  1068. if (serial_paranoia_check(info, tty->name, "cy_write")){
  1069. return 0;
  1070. }
  1071. if (!tty || !info->xmit_buf || !tmp_buf){
  1072. return 0;
  1073. }
  1074. while (1) {
  1075. local_irq_save(flags);
  1076. c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
  1077. SERIAL_XMIT_SIZE - info->xmit_head));
  1078. if (c <= 0) {
  1079. local_irq_restore(flags);
  1080. break;
  1081. }
  1082. memcpy(info->xmit_buf + info->xmit_head, buf, c);
  1083. info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
  1084. info->xmit_cnt += c;
  1085. local_irq_restore(flags);
  1086. buf += c;
  1087. count -= c;
  1088. total += c;
  1089. }
  1090. if (info->xmit_cnt
  1091. && !tty->stopped
  1092. && !tty->hw_stopped ) {
  1093. start_xmit(info);
  1094. }
  1095. return total;
  1096. } /* cy_write */
  1097. static int
  1098. cy_write_room(struct tty_struct *tty)
  1099. {
  1100. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1101. int ret;
  1102. #ifdef SERIAL_DEBUG_IO
  1103. printk("cy_write_room %s\n", tty->name); /* */
  1104. #endif
  1105. if (serial_paranoia_check(info, tty->name, "cy_write_room"))
  1106. return 0;
  1107. ret = PAGE_SIZE - info->xmit_cnt - 1;
  1108. if (ret < 0)
  1109. ret = 0;
  1110. return ret;
  1111. } /* cy_write_room */
  1112. static int
  1113. cy_chars_in_buffer(struct tty_struct *tty)
  1114. {
  1115. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1116. #ifdef SERIAL_DEBUG_IO
  1117. printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt); /* */
  1118. #endif
  1119. if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
  1120. return 0;
  1121. return info->xmit_cnt;
  1122. } /* cy_chars_in_buffer */
  1123. static void
  1124. cy_flush_buffer(struct tty_struct *tty)
  1125. {
  1126. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1127. unsigned long flags;
  1128. #ifdef SERIAL_DEBUG_IO
  1129. printk("cy_flush_buffer %s\n", tty->name); /* */
  1130. #endif
  1131. if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
  1132. return;
  1133. local_irq_save(flags);
  1134. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  1135. local_irq_restore(flags);
  1136. tty_wakeup(tty);
  1137. } /* cy_flush_buffer */
  1138. /* This routine is called by the upper-layer tty layer to signal
  1139. that incoming characters should be throttled or that the
  1140. throttle should be released.
  1141. */
  1142. static void
  1143. cy_throttle(struct tty_struct * tty)
  1144. {
  1145. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1146. unsigned long flags;
  1147. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  1148. int channel;
  1149. #ifdef SERIAL_DEBUG_THROTTLE
  1150. char buf[64];
  1151. printk("throttle %s: %d....\n", tty_name(tty, buf),
  1152. tty->ldisc.chars_in_buffer(tty));
  1153. printk("cy_throttle %s\n", tty->name);
  1154. #endif
  1155. if (serial_paranoia_check(info, tty->name, "cy_nthrottle")){
  1156. return;
  1157. }
  1158. if (I_IXOFF(tty)) {
  1159. info->x_char = STOP_CHAR(tty);
  1160. /* Should use the "Send Special Character" feature!!! */
  1161. }
  1162. channel = info->line;
  1163. local_irq_save(flags);
  1164. base_addr[CyCAR] = (u_char)channel;
  1165. base_addr[CyMSVR1] = 0;
  1166. local_irq_restore(flags);
  1167. return;
  1168. } /* cy_throttle */
  1169. static void
  1170. cy_unthrottle(struct tty_struct * tty)
  1171. {
  1172. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1173. unsigned long flags;
  1174. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  1175. int channel;
  1176. #ifdef SERIAL_DEBUG_THROTTLE
  1177. char buf[64];
  1178. printk("throttle %s: %d....\n", tty_name(tty, buf),
  1179. tty->ldisc.chars_in_buffer(tty));
  1180. printk("cy_unthrottle %s\n", tty->name);
  1181. #endif
  1182. if (serial_paranoia_check(info, tty->name, "cy_nthrottle")){
  1183. return;
  1184. }
  1185. if (I_IXOFF(tty)) {
  1186. info->x_char = START_CHAR(tty);
  1187. /* Should use the "Send Special Character" feature!!! */
  1188. }
  1189. channel = info->line;
  1190. local_irq_save(flags);
  1191. base_addr[CyCAR] = (u_char)channel;
  1192. base_addr[CyMSVR1] = CyRTS;
  1193. local_irq_restore(flags);
  1194. return;
  1195. } /* cy_unthrottle */
  1196. static int
  1197. get_serial_info(struct cyclades_port * info,
  1198. struct serial_struct * retinfo)
  1199. {
  1200. struct serial_struct tmp;
  1201. /* CP('g'); */
  1202. if (!retinfo)
  1203. return -EFAULT;
  1204. memset(&tmp, 0, sizeof(tmp));
  1205. tmp.type = info->type;
  1206. tmp.line = info->line;
  1207. tmp.port = info->line;
  1208. tmp.irq = 0;
  1209. tmp.flags = info->flags;
  1210. tmp.baud_base = 0; /*!!!*/
  1211. tmp.close_delay = info->close_delay;
  1212. tmp.custom_divisor = 0; /*!!!*/
  1213. tmp.hub6 = 0; /*!!!*/
  1214. return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0;
  1215. } /* get_serial_info */
  1216. static int
  1217. set_serial_info(struct cyclades_port * info,
  1218. struct serial_struct * new_info)
  1219. {
  1220. struct serial_struct new_serial;
  1221. struct cyclades_port old_info;
  1222. /* CP('s'); */
  1223. if (!new_info)
  1224. return -EFAULT;
  1225. if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
  1226. return -EFAULT;
  1227. old_info = *info;
  1228. if (!capable(CAP_SYS_ADMIN)) {
  1229. if ((new_serial.close_delay != info->close_delay) ||
  1230. ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) !=
  1231. (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)))
  1232. return -EPERM;
  1233. info->flags = ((info->flags & ~ASYNC_USR_MASK) |
  1234. (new_serial.flags & ASYNC_USR_MASK));
  1235. goto check_and_exit;
  1236. }
  1237. /*
  1238. * OK, past this point, all the error checking has been done.
  1239. * At this point, we start making changes.....
  1240. */
  1241. info->flags = ((info->flags & ~ASYNC_FLAGS) |
  1242. (new_serial.flags & ASYNC_FLAGS));
  1243. info->close_delay = new_serial.close_delay;
  1244. check_and_exit:
  1245. if (info->flags & ASYNC_INITIALIZED){
  1246. config_setup(info);
  1247. return 0;
  1248. }else{
  1249. return startup(info);
  1250. }
  1251. } /* set_serial_info */
  1252. static int
  1253. cy_tiocmget(struct tty_struct *tty, struct file *file)
  1254. {
  1255. struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
  1256. int channel;
  1257. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  1258. unsigned long flags;
  1259. unsigned char status;
  1260. unsigned int result;
  1261. channel = info->line;
  1262. local_irq_save(flags);
  1263. base_addr[CyCAR] = (u_char)channel;
  1264. status = base_addr[CyMSVR1] | base_addr[CyMSVR2];
  1265. local_irq_restore(flags);
  1266. return ((status & CyRTS) ? TIOCM_RTS : 0)
  1267. | ((status & CyDTR) ? TIOCM_DTR : 0)
  1268. | ((status & CyDCD) ? TIOCM_CAR : 0)
  1269. | ((status & CyDSR) ? TIOCM_DSR : 0)
  1270. | ((status & CyCTS) ? TIOCM_CTS : 0);
  1271. } /* cy_tiocmget */
  1272. static int
  1273. cy_tiocmset(struct tty_struct *tty, struct file *file,
  1274. unsigned int set, unsigned int clear)
  1275. {
  1276. struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
  1277. int channel;
  1278. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  1279. unsigned long flags;
  1280. unsigned int arg;
  1281. channel = info->line;
  1282. if (set & TIOCM_RTS){
  1283. local_irq_save(flags);
  1284. base_addr[CyCAR] = (u_char)channel;
  1285. base_addr[CyMSVR1] = CyRTS;
  1286. local_irq_restore(flags);
  1287. }
  1288. if (set & TIOCM_DTR){
  1289. local_irq_save(flags);
  1290. base_addr[CyCAR] = (u_char)channel;
  1291. /* CP('S');CP('2'); */
  1292. base_addr[CyMSVR2] = CyDTR;
  1293. #ifdef SERIAL_DEBUG_DTR
  1294. printk("cyc: %d: raising DTR\n", __LINE__);
  1295. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
  1296. #endif
  1297. local_irq_restore(flags);
  1298. }
  1299. if (clear & TIOCM_RTS){
  1300. local_irq_save(flags);
  1301. base_addr[CyCAR] = (u_char)channel;
  1302. base_addr[CyMSVR1] = 0;
  1303. local_irq_restore(flags);
  1304. }
  1305. if (clear & TIOCM_DTR){
  1306. local_irq_save(flags);
  1307. base_addr[CyCAR] = (u_char)channel;
  1308. /* CP('C');CP('2'); */
  1309. base_addr[CyMSVR2] = 0;
  1310. #ifdef SERIAL_DEBUG_DTR
  1311. printk("cyc: %d: dropping DTR\n", __LINE__);
  1312. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
  1313. #endif
  1314. local_irq_restore(flags);
  1315. }
  1316. return 0;
  1317. } /* set_modem_info */
  1318. static void
  1319. send_break( struct cyclades_port * info, int duration)
  1320. { /* Let the transmit ISR take care of this (since it
  1321. requires stuffing characters into the output stream).
  1322. */
  1323. info->x_break = duration;
  1324. if (!info->xmit_cnt ) {
  1325. start_xmit(info);
  1326. }
  1327. } /* send_break */
  1328. static int
  1329. get_mon_info(struct cyclades_port * info, struct cyclades_monitor * mon)
  1330. {
  1331. if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
  1332. return -EFAULT;
  1333. info->mon.int_count = 0;
  1334. info->mon.char_count = 0;
  1335. info->mon.char_max = 0;
  1336. info->mon.char_last = 0;
  1337. return 0;
  1338. }
  1339. static int
  1340. set_threshold(struct cyclades_port * info, unsigned long *arg)
  1341. {
  1342. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  1343. unsigned long value;
  1344. int channel;
  1345. if (get_user(value, arg))
  1346. return -EFAULT;
  1347. channel = info->line;
  1348. info->cor4 &= ~CyREC_FIFO;
  1349. info->cor4 |= value & CyREC_FIFO;
  1350. base_addr[CyCOR4] = info->cor4;
  1351. return 0;
  1352. }
  1353. static int
  1354. get_threshold(struct cyclades_port * info, unsigned long *value)
  1355. {
  1356. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  1357. int channel;
  1358. unsigned long tmp;
  1359. channel = info->line;
  1360. tmp = base_addr[CyCOR4] & CyREC_FIFO;
  1361. return put_user(tmp,value);
  1362. }
  1363. static int
  1364. set_default_threshold(struct cyclades_port * info, unsigned long *arg)
  1365. {
  1366. unsigned long value;
  1367. if (get_user(value, arg))
  1368. return -EFAULT;
  1369. info->default_threshold = value & 0x0f;
  1370. return 0;
  1371. }
  1372. static int
  1373. get_default_threshold(struct cyclades_port * info, unsigned long *value)
  1374. {
  1375. return put_user(info->default_threshold,value);
  1376. }
  1377. static int
  1378. set_timeout(struct cyclades_port * info, unsigned long *arg)
  1379. {
  1380. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  1381. int channel;
  1382. unsigned long value;
  1383. if (get_user(value, arg))
  1384. return -EFAULT;
  1385. channel = info->line;
  1386. base_addr[CyRTPRL] = value & 0xff;
  1387. base_addr[CyRTPRH] = (value >> 8) & 0xff;
  1388. return 0;
  1389. }
  1390. static int
  1391. get_timeout(struct cyclades_port * info, unsigned long *value)
  1392. {
  1393. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  1394. int channel;
  1395. unsigned long tmp;
  1396. channel = info->line;
  1397. tmp = base_addr[CyRTPRL];
  1398. return put_user(tmp,value);
  1399. }
  1400. static int
  1401. set_default_timeout(struct cyclades_port * info, unsigned long value)
  1402. {
  1403. info->default_timeout = value & 0xff;
  1404. return 0;
  1405. }
  1406. static int
  1407. get_default_timeout(struct cyclades_port * info, unsigned long *value)
  1408. {
  1409. return put_user(info->default_timeout,value);
  1410. }
  1411. static int
  1412. cy_ioctl(struct tty_struct *tty, struct file * file,
  1413. unsigned int cmd, unsigned long arg)
  1414. {
  1415. unsigned long val;
  1416. struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
  1417. int ret_val = 0;
  1418. #ifdef SERIAL_DEBUG_OTHER
  1419. printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */
  1420. #endif
  1421. switch (cmd) {
  1422. case CYGETMON:
  1423. ret_val = get_mon_info(info, (struct cyclades_monitor *)arg);
  1424. break;
  1425. case CYGETTHRESH:
  1426. ret_val = get_threshold(info, (unsigned long *)arg);
  1427. break;
  1428. case CYSETTHRESH:
  1429. ret_val = set_threshold(info, (unsigned long *)arg);
  1430. break;
  1431. case CYGETDEFTHRESH:
  1432. ret_val = get_default_threshold(info, (unsigned long *)arg);
  1433. break;
  1434. case CYSETDEFTHRESH:
  1435. ret_val = set_default_threshold(info, (unsigned long *)arg);
  1436. break;
  1437. case CYGETTIMEOUT:
  1438. ret_val = get_timeout(info, (unsigned long *)arg);
  1439. break;
  1440. case CYSETTIMEOUT:
  1441. ret_val = set_timeout(info, (unsigned long *)arg);
  1442. break;
  1443. case CYGETDEFTIMEOUT:
  1444. ret_val = get_default_timeout(info, (unsigned long *)arg);
  1445. break;
  1446. case CYSETDEFTIMEOUT:
  1447. ret_val = set_default_timeout(info, (unsigned long)arg);
  1448. break;
  1449. case TCSBRK: /* SVID version: non-zero arg --> no break */
  1450. ret_val = tty_check_change(tty);
  1451. if (ret_val)
  1452. break;
  1453. tty_wait_until_sent(tty,0);
  1454. if (!arg)
  1455. send_break(info, HZ/4); /* 1/4 second */
  1456. break;
  1457. case TCSBRKP: /* support for POSIX tcsendbreak() */
  1458. ret_val = tty_check_change(tty);
  1459. if (ret_val)
  1460. break;
  1461. tty_wait_until_sent(tty,0);
  1462. send_break(info, arg ? arg*(HZ/10) : HZ/4);
  1463. break;
  1464. /* The following commands are incompletely implemented!!! */
  1465. case TIOCGSOFTCAR:
  1466. ret_val = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *) arg);
  1467. break;
  1468. case TIOCSSOFTCAR:
  1469. ret_val = get_user(val, (unsigned long *) arg);
  1470. if (ret_val)
  1471. break;
  1472. tty->termios->c_cflag =
  1473. ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0));
  1474. break;
  1475. case TIOCGSERIAL:
  1476. ret_val = get_serial_info(info, (struct serial_struct *) arg);
  1477. break;
  1478. case TIOCSSERIAL:
  1479. ret_val = set_serial_info(info,
  1480. (struct serial_struct *) arg);
  1481. break;
  1482. default:
  1483. ret_val = -ENOIOCTLCMD;
  1484. }
  1485. #ifdef SERIAL_DEBUG_OTHER
  1486. printk("cy_ioctl done\n");
  1487. #endif
  1488. return ret_val;
  1489. } /* cy_ioctl */
  1490. static void
  1491. cy_set_termios(struct tty_struct *tty, struct termios * old_termios)
  1492. {
  1493. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1494. #ifdef SERIAL_DEBUG_OTHER
  1495. printk("cy_set_termios %s\n", tty->name);
  1496. #endif
  1497. if (tty->termios->c_cflag == old_termios->c_cflag)
  1498. return;
  1499. config_setup(info);
  1500. if ((old_termios->c_cflag & CRTSCTS) &&
  1501. !(tty->termios->c_cflag & CRTSCTS)) {
  1502. tty->stopped = 0;
  1503. cy_start(tty);
  1504. }
  1505. #ifdef tytso_patch_94Nov25_1726
  1506. if (!(old_termios->c_cflag & CLOCAL) &&
  1507. (tty->termios->c_cflag & CLOCAL))
  1508. wake_up_interruptible(&info->open_wait);
  1509. #endif
  1510. return;
  1511. } /* cy_set_termios */
  1512. static void
  1513. cy_close(struct tty_struct * tty, struct file * filp)
  1514. {
  1515. struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
  1516. /* CP('C'); */
  1517. #ifdef SERIAL_DEBUG_OTHER
  1518. printk("cy_close %s\n", tty->name);
  1519. #endif
  1520. if (!info
  1521. || serial_paranoia_check(info, tty->name, "cy_close")){
  1522. return;
  1523. }
  1524. #ifdef SERIAL_DEBUG_OPEN
  1525. printk("cy_close %s, count = %d\n", tty->name, info->count);
  1526. #endif
  1527. if ((tty->count == 1) && (info->count != 1)) {
  1528. /*
  1529. * Uh, oh. tty->count is 1, which means that the tty
  1530. * structure will be freed. Info->count should always
  1531. * be one in these conditions. If it's greater than
  1532. * one, we've got real problems, since it means the
  1533. * serial port won't be shutdown.
  1534. */
  1535. printk("cy_close: bad serial port count; tty->count is 1, "
  1536. "info->count is %d\n", info->count);
  1537. info->count = 1;
  1538. }
  1539. #ifdef SERIAL_DEBUG_COUNT
  1540. printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count - 1);
  1541. #endif
  1542. if (--info->count < 0) {
  1543. printk("cy_close: bad serial port count for ttys%d: %d\n",
  1544. info->line, info->count);
  1545. #ifdef SERIAL_DEBUG_COUNT
  1546. printk("cyc: %d: setting count to 0\n", __LINE__);
  1547. #endif
  1548. info->count = 0;
  1549. }
  1550. if (info->count)
  1551. return;
  1552. info->flags |= ASYNC_CLOSING;
  1553. if (info->flags & ASYNC_INITIALIZED)
  1554. tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
  1555. shutdown(info);
  1556. if (tty->driver->flush_buffer)
  1557. tty->driver->flush_buffer(tty);
  1558. tty_ldisc_flush(tty);
  1559. info->event = 0;
  1560. info->tty = 0;
  1561. if (info->blocked_open) {
  1562. if (info->close_delay) {
  1563. msleep_interruptible(jiffies_to_msecs(info->close_delay));
  1564. }
  1565. wake_up_interruptible(&info->open_wait);
  1566. }
  1567. info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  1568. wake_up_interruptible(&info->close_wait);
  1569. #ifdef SERIAL_DEBUG_OTHER
  1570. printk("cy_close done\n");
  1571. #endif
  1572. return;
  1573. } /* cy_close */
  1574. /*
  1575. * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
  1576. */
  1577. void
  1578. cy_hangup(struct tty_struct *tty)
  1579. {
  1580. struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
  1581. #ifdef SERIAL_DEBUG_OTHER
  1582. printk("cy_hangup %s\n", tty->name); /* */
  1583. #endif
  1584. if (serial_paranoia_check(info, tty->name, "cy_hangup"))
  1585. return;
  1586. shutdown(info);
  1587. #if 0
  1588. info->event = 0;
  1589. info->count = 0;
  1590. #ifdef SERIAL_DEBUG_COUNT
  1591. printk("cyc: %d: setting count to 0\n", __LINE__);
  1592. #endif
  1593. info->tty = 0;
  1594. #endif
  1595. info->flags &= ~ASYNC_NORMAL_ACTIVE;
  1596. wake_up_interruptible(&info->open_wait);
  1597. } /* cy_hangup */
  1598. /*
  1599. * ------------------------------------------------------------
  1600. * cy_open() and friends
  1601. * ------------------------------------------------------------
  1602. */
  1603. static int
  1604. block_til_ready(struct tty_struct *tty, struct file * filp,
  1605. struct cyclades_port *info)
  1606. {
  1607. DECLARE_WAITQUEUE(wait, current);
  1608. unsigned long flags;
  1609. int channel;
  1610. int retval;
  1611. volatile u_char *base_addr = (u_char *)BASE_ADDR;
  1612. /*
  1613. * If the device is in the middle of being closed, then block
  1614. * until it's done, and then try again.
  1615. */
  1616. if (info->flags & ASYNC_CLOSING) {
  1617. interruptible_sleep_on(&info->close_wait);
  1618. if (info->flags & ASYNC_HUP_NOTIFY){
  1619. return -EAGAIN;
  1620. }else{
  1621. return -ERESTARTSYS;
  1622. }
  1623. }
  1624. /*
  1625. * If non-blocking mode is set, then make the check up front
  1626. * and then exit.
  1627. */
  1628. if (filp->f_flags & O_NONBLOCK) {
  1629. info->flags |= ASYNC_NORMAL_ACTIVE;
  1630. return 0;
  1631. }
  1632. /*
  1633. * Block waiting for the carrier detect and the line to become
  1634. * free (i.e., not in use by the callout). While we are in
  1635. * this loop, info->count is dropped by one, so that
  1636. * cy_close() knows when to free things. We restore it upon
  1637. * exit, either normal or abnormal.
  1638. */
  1639. retval = 0;
  1640. add_wait_queue(&info->open_wait, &wait);
  1641. #ifdef SERIAL_DEBUG_OPEN
  1642. printk("block_til_ready before block: %s, count = %d\n",
  1643. tty->name, info->count);/**/
  1644. #endif
  1645. info->count--;
  1646. #ifdef SERIAL_DEBUG_COUNT
  1647. printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count);
  1648. #endif
  1649. info->blocked_open++;
  1650. channel = info->line;
  1651. while (1) {
  1652. local_irq_save(flags);
  1653. base_addr[CyCAR] = (u_char)channel;
  1654. base_addr[CyMSVR1] = CyRTS;
  1655. /* CP('S');CP('4'); */
  1656. base_addr[CyMSVR2] = CyDTR;
  1657. #ifdef SERIAL_DEBUG_DTR
  1658. printk("cyc: %d: raising DTR\n", __LINE__);
  1659. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
  1660. #endif
  1661. local_irq_restore(flags);
  1662. set_current_state(TASK_INTERRUPTIBLE);
  1663. if (tty_hung_up_p(filp)
  1664. || !(info->flags & ASYNC_INITIALIZED) ){
  1665. if (info->flags & ASYNC_HUP_NOTIFY) {
  1666. retval = -EAGAIN;
  1667. }else{
  1668. retval = -ERESTARTSYS;
  1669. }
  1670. break;
  1671. }
  1672. local_irq_save(flags);
  1673. base_addr[CyCAR] = (u_char)channel;
  1674. /* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */
  1675. if (!(info->flags & ASYNC_CLOSING)
  1676. && (C_CLOCAL(tty)
  1677. || (base_addr[CyMSVR1] & CyDCD))) {
  1678. local_irq_restore(flags);
  1679. break;
  1680. }
  1681. local_irq_restore(flags);
  1682. if (signal_pending(current)) {
  1683. retval = -ERESTARTSYS;
  1684. break;
  1685. }
  1686. #ifdef SERIAL_DEBUG_OPEN
  1687. printk("block_til_ready blocking: %s, count = %d\n",
  1688. tty->name, info->count);/**/
  1689. #endif
  1690. schedule();
  1691. }
  1692. current->state = TASK_RUNNING;
  1693. remove_wait_queue(&info->open_wait, &wait);
  1694. if (!tty_hung_up_p(filp)){
  1695. info->count++;
  1696. #ifdef SERIAL_DEBUG_COUNT
  1697. printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
  1698. #endif
  1699. }
  1700. info->blocked_open--;
  1701. #ifdef SERIAL_DEBUG_OPEN
  1702. printk("block_til_ready after blocking: %s, count = %d\n",
  1703. tty->name, info->count);/**/
  1704. #endif
  1705. if (retval)
  1706. return retval;
  1707. info->flags |= ASYNC_NORMAL_ACTIVE;
  1708. return 0;
  1709. } /* block_til_ready */
  1710. /*
  1711. * This routine is called whenever a serial port is opened. It
  1712. * performs the serial-specific initialization for the tty structure.
  1713. */
  1714. int
  1715. cy_open(struct tty_struct *tty, struct file * filp)
  1716. {
  1717. struct cyclades_port *info;
  1718. int retval, line;
  1719. /* CP('O'); */
  1720. line = tty->index;
  1721. if ((line < 0) || (NR_PORTS <= line)){
  1722. return -ENODEV;
  1723. }
  1724. info = &cy_port[line];
  1725. if (info->line < 0){
  1726. return -ENODEV;
  1727. }
  1728. #ifdef SERIAL_DEBUG_OTHER
  1729. printk("cy_open %s\n", tty->name); /* */
  1730. #endif
  1731. if (serial_paranoia_check(info, tty->name, "cy_open")){
  1732. return -ENODEV;
  1733. }
  1734. #ifdef SERIAL_DEBUG_OPEN
  1735. printk("cy_open %s, count = %d\n", tty->name, info->count);/**/
  1736. #endif
  1737. info->count++;
  1738. #ifdef SERIAL_DEBUG_COUNT
  1739. printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
  1740. #endif
  1741. tty->driver_data = info;
  1742. info->tty = tty;
  1743. if (!tmp_buf) {
  1744. tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL);
  1745. if (!tmp_buf){
  1746. return -ENOMEM;
  1747. }
  1748. }
  1749. /*
  1750. * Start up serial port
  1751. */
  1752. retval = startup(info);
  1753. if (retval){
  1754. return retval;
  1755. }
  1756. retval = block_til_ready(tty, filp, info);
  1757. if (retval) {
  1758. #ifdef SERIAL_DEBUG_OPEN
  1759. printk("cy_open returning after block_til_ready with %d\n",
  1760. retval);
  1761. #endif
  1762. return retval;
  1763. }
  1764. #ifdef SERIAL_DEBUG_OPEN
  1765. printk("cy_open done\n");/**/
  1766. #endif
  1767. return 0;
  1768. } /* cy_open */
  1769. /*
  1770. * ---------------------------------------------------------------------
  1771. * serial167_init() and friends
  1772. *
  1773. * serial167_init() is called at boot-time to initialize the serial driver.
  1774. * ---------------------------------------------------------------------
  1775. */
  1776. /*
  1777. * This routine prints out the appropriate serial driver version
  1778. * number, and identifies which options were configured into this
  1779. * driver.
  1780. */
  1781. static void
  1782. show_version(void)
  1783. {
  1784. printk("MVME166/167 cd2401 driver\n");
  1785. } /* show_version */
  1786. /* initialize chips on card -- return number of valid
  1787. chips (which is number of ports/4) */
  1788. /*
  1789. * This initialises the hardware to a reasonable state. It should
  1790. * probe the chip first so as to copy 166-Bug setup as a default for
  1791. * port 0. It initialises CMR to CyASYNC; that is never done again, so
  1792. * as to limit the number of CyINIT_CHAN commands in normal running.
  1793. *
  1794. * ... I wonder what I should do if this fails ...
  1795. */
  1796. void
  1797. mvme167_serial_console_setup(int cflag)
  1798. {
  1799. volatile unsigned char* base_addr = (u_char *)BASE_ADDR;
  1800. int ch;
  1801. u_char spd;
  1802. u_char rcor, rbpr, badspeed = 0;
  1803. unsigned long flags;
  1804. local_irq_save(flags);
  1805. /*
  1806. * First probe channel zero of the chip, to see what speed has
  1807. * been selected.
  1808. */
  1809. base_addr[CyCAR] = 0;
  1810. rcor = base_addr[CyRCOR] << 5;
  1811. rbpr = base_addr[CyRBPR];
  1812. for (spd = 0; spd < sizeof(baud_bpr); spd++)
  1813. if (rbpr == baud_bpr[spd] && rcor == baud_co[spd])
  1814. break;
  1815. if (spd >= sizeof(baud_bpr)) {
  1816. spd = 14; /* 19200 */
  1817. badspeed = 1; /* Failed to identify speed */
  1818. }
  1819. initial_console_speed = spd;
  1820. /* OK, we have chosen a speed, now reset and reinitialise */
  1821. my_udelay(20000L); /* Allow time for any active o/p to complete */
  1822. if(base_addr[CyCCR] != 0x00){
  1823. local_irq_restore(flags);
  1824. /* printk(" chip is never idle (CCR != 0)\n"); */
  1825. return;
  1826. }
  1827. base_addr[CyCCR] = CyCHIP_RESET; /* Reset the chip */
  1828. my_udelay(1000L);
  1829. if(base_addr[CyGFRCR] == 0x00){
  1830. local_irq_restore(flags);
  1831. /* printk(" chip is not responding (GFRCR stayed 0)\n"); */
  1832. return;
  1833. }
  1834. /*
  1835. * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms
  1836. * tick
  1837. */
  1838. base_addr[CyTPR] = 10;
  1839. base_addr[CyPILR1] = 0x01; /* Interrupt level for modem change */
  1840. base_addr[CyPILR2] = 0x02; /* Interrupt level for tx ints */
  1841. base_addr[CyPILR3] = 0x03; /* Interrupt level for rx ints */
  1842. /*
  1843. * Attempt to set up all channels to something reasonable, and
  1844. * bang out a INIT_CHAN command. We should then be able to limit
  1845. * the ammount of fiddling we have to do in normal running.
  1846. */
  1847. for (ch = 3; ch >= 0 ; ch--) {
  1848. base_addr[CyCAR] = (u_char)ch;
  1849. base_addr[CyIER] = 0;
  1850. base_addr[CyCMR] = CyASYNC;
  1851. base_addr[CyLICR] = (u_char)ch << 2;
  1852. base_addr[CyLIVR] = 0x5c;
  1853. base_addr[CyTCOR] = baud_co[spd];
  1854. base_addr[CyTBPR] = baud_bpr[spd];
  1855. base_addr[CyRCOR] = baud_co[spd] >> 5;
  1856. base_addr[CyRBPR] = baud_bpr[spd];
  1857. base_addr[CySCHR1] = 'Q' & 0x1f;
  1858. base_addr[CySCHR2] = 'X' & 0x1f;
  1859. base_addr[CySCRL] = 0;
  1860. base_addr[CySCRH] = 0;
  1861. base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
  1862. base_addr[CyCOR2] = 0;
  1863. base_addr[CyCOR3] = Cy_1_STOP;
  1864. base_addr[CyCOR4] = baud_cor4[spd];
  1865. base_addr[CyCOR5] = 0;
  1866. base_addr[CyCOR6] = 0;
  1867. base_addr[CyCOR7] = 0;
  1868. base_addr[CyRTPRL] = 2;
  1869. base_addr[CyRTPRH] = 0;
  1870. base_addr[CyMSVR1] = 0;
  1871. base_addr[CyMSVR2] = 0;
  1872. write_cy_cmd(base_addr,CyINIT_CHAN|CyDIS_RCVR|CyDIS_XMTR);
  1873. }
  1874. /*
  1875. * Now do specials for channel zero....
  1876. */
  1877. base_addr[CyMSVR1] = CyRTS;
  1878. base_addr[CyMSVR2] = CyDTR;
  1879. base_addr[CyIER] = CyRxData;
  1880. write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR);
  1881. local_irq_restore(flags);
  1882. my_udelay(20000L); /* Let it all settle down */
  1883. printk("CD2401 initialised, chip is rev 0x%02x\n", base_addr[CyGFRCR]);
  1884. if (badspeed)
  1885. printk(" WARNING: Failed to identify line speed, rcor=%02x,rbpr=%02x\n",
  1886. rcor >> 5, rbpr);
  1887. } /* serial_console_init */
  1888. static struct tty_operations cy_ops = {
  1889. .open = cy_open,
  1890. .close = cy_close,
  1891. .write = cy_write,
  1892. .put_char = cy_put_char,
  1893. .flush_chars = cy_flush_chars,
  1894. .write_room = cy_write_room,
  1895. .chars_in_buffer = cy_chars_in_buffer,
  1896. .flush_buffer = cy_flush_buffer,
  1897. .ioctl = cy_ioctl,
  1898. .throttle = cy_throttle,
  1899. .unthrottle = cy_unthrottle,
  1900. .set_termios = cy_set_termios,
  1901. .stop = cy_stop,
  1902. .start = cy_start,
  1903. .hangup = cy_hangup,
  1904. .tiocmget = cy_tiocmget,
  1905. .tiocmset = cy_tiocmset,
  1906. };
  1907. /* The serial driver boot-time initialization code!
  1908. Hardware I/O ports are mapped to character special devices on a
  1909. first found, first allocated manner. That is, this code searches
  1910. for Cyclom cards in the system. As each is found, it is probed
  1911. to discover how many chips (and thus how many ports) are present.
  1912. These ports are mapped to the tty ports 64 and upward in monotonic
  1913. fashion. If an 8-port card is replaced with a 16-port card, the
  1914. port mapping on a following card will shift.
  1915. This approach is different from what is used in the other serial
  1916. device driver because the Cyclom is more properly a multiplexer,
  1917. not just an aggregation of serial ports on one card.
  1918. If there are more cards with more ports than have been statically
  1919. allocated above, a warning is printed and the extra ports are ignored.
  1920. */
  1921. static int __init
  1922. serial167_init(void)
  1923. {
  1924. struct cyclades_port *info;
  1925. int ret = 0;
  1926. int good_ports = 0;
  1927. int port_num = 0;
  1928. int index;
  1929. int DefSpeed;
  1930. #ifdef notyet
  1931. struct sigaction sa;
  1932. #endif
  1933. if (!(mvme16x_config &MVME16x_CONFIG_GOT_CD2401))
  1934. return 0;
  1935. cy_serial_driver = alloc_tty_driver(NR_PORTS);
  1936. if (!cy_serial_driver)
  1937. return -ENOMEM;
  1938. #if 0
  1939. scrn[1] = '\0';
  1940. #endif
  1941. show_version();
  1942. /* Has "console=0,9600n8" been used in bootinfo to change speed? */
  1943. if (serial_console_cflag)
  1944. DefSpeed = serial_console_cflag & 0017;
  1945. else {
  1946. DefSpeed = initial_console_speed;
  1947. serial_console_info = &cy_port[0];
  1948. serial_console_cflag = DefSpeed | CS8;
  1949. #if 0
  1950. serial_console = 64; /*callout_driver.minor_start*/
  1951. #endif
  1952. }
  1953. /* Initialize the tty_driver structure */
  1954. cy_serial_driver->owner = THIS_MODULE;
  1955. cy_serial_driver->devfs_name = "tts/";
  1956. cy_serial_driver->name = "ttyS";
  1957. cy_serial_driver->major = TTY_MAJOR;
  1958. cy_serial_driver->minor_start = 64;
  1959. cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
  1960. cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
  1961. cy_serial_driver->init_termios = tty_std_termios;
  1962. cy_serial_driver->init_termios.c_cflag =
  1963. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  1964. cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
  1965. tty_set_operations(cy_serial_driver, &cy_ops);
  1966. ret = tty_register_driver(cy_serial_driver);
  1967. if (ret) {
  1968. printk(KERN_ERR "Couldn't register MVME166/7 serial driver\n");
  1969. put_tty_driver(cy_serial_driver);
  1970. return ret;
  1971. }
  1972. port_num = 0;
  1973. info = cy_port;
  1974. for (index = 0; index < 1; index++) {
  1975. good_ports = 4;
  1976. if(port_num < NR_PORTS){
  1977. while( good_ports-- && port_num < NR_PORTS){
  1978. /*** initialize port ***/
  1979. info->magic = CYCLADES_MAGIC;
  1980. info->type = PORT_CIRRUS;
  1981. info->card = index;
  1982. info->line = port_num;
  1983. info->flags = STD_COM_FLAGS;
  1984. info->tty = 0;
  1985. info->xmit_fifo_size = 12;
  1986. info->cor1 = CyPARITY_NONE|Cy_8_BITS;
  1987. info->cor2 = CyETC;
  1988. info->cor3 = Cy_1_STOP;
  1989. info->cor4 = 0x08; /* _very_ small receive threshold */
  1990. info->cor5 = 0;
  1991. info->cor6 = 0;
  1992. info->cor7 = 0;
  1993. info->tbpr = baud_bpr[DefSpeed]; /* Tx BPR */
  1994. info->tco = baud_co[DefSpeed]; /* Tx CO */
  1995. info->rbpr = baud_bpr[DefSpeed]; /* Rx BPR */
  1996. info->rco = baud_co[DefSpeed] >> 5; /* Rx CO */
  1997. info->close_delay = 0;
  1998. info->x_char = 0;
  1999. info->event = 0;
  2000. info->count = 0;
  2001. #ifdef SERIAL_DEBUG_COUNT
  2002. printk("cyc: %d: setting count to 0\n", __LINE__);
  2003. #endif
  2004. info->blocked_open = 0;
  2005. info->default_threshold = 0;
  2006. info->default_timeout = 0;
  2007. INIT_WORK(&info->tqueue, do_softint, info);
  2008. init_waitqueue_head(&info->open_wait);
  2009. init_waitqueue_head(&info->close_wait);
  2010. /* info->session */
  2011. /* info->pgrp */
  2012. /*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/
  2013. info->read_status_mask = CyTIMEOUT| CySPECHAR| CyBREAK
  2014. | CyPARITY| CyFRAME| CyOVERRUN;
  2015. /* info->timeout */
  2016. printk("ttyS%d ", info->line);
  2017. port_num++;info++;
  2018. if(!(port_num & 7)){
  2019. printk("\n ");
  2020. }
  2021. }
  2022. }
  2023. printk("\n");
  2024. }
  2025. while( port_num < NR_PORTS){
  2026. info->line = -1;
  2027. port_num++;info++;
  2028. }
  2029. #ifdef CONFIG_REMOTE_DEBUG
  2030. debug_setup();
  2031. #endif
  2032. ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0,
  2033. "cd2401_errors", cd2401_rxerr_interrupt);
  2034. if (ret) {
  2035. printk(KERN_ERR "Could't get cd2401_errors IRQ");
  2036. goto cleanup_serial_driver;
  2037. }
  2038. ret = request_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt, 0,
  2039. "cd2401_modem", cd2401_modem_interrupt);
  2040. if (ret) {
  2041. printk(KERN_ERR "Could't get cd2401_modem IRQ");
  2042. goto cleanup_irq_cd2401_errors;
  2043. }
  2044. ret = request_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt, 0,
  2045. "cd2401_txints", cd2401_tx_interrupt);
  2046. if (ret) {
  2047. printk(KERN_ERR "Could't get cd2401_txints IRQ");
  2048. goto cleanup_irq_cd2401_modem;
  2049. }
  2050. ret = request_irq(MVME167_IRQ_SER_RX, cd2401_rx_interrupt, 0,
  2051. "cd2401_rxints", cd2401_rx_interrupt);
  2052. if (ret) {
  2053. printk(KERN_ERR "Could't get cd2401_rxints IRQ");
  2054. goto cleanup_irq_cd2401_txints;
  2055. }
  2056. /* Now we have registered the interrupt handlers, allow the interrupts */
  2057. pcc2chip[PccSCCMICR] = 0x15; /* Serial ints are level 5 */
  2058. pcc2chip[PccSCCTICR] = 0x15;
  2059. pcc2chip[PccSCCRICR] = 0x15;
  2060. pcc2chip[PccIMLR] = 3; /* Allow PCC2 ints above 3!? */
  2061. return 0;
  2062. cleanup_irq_cd2401_txints:
  2063. free_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt);
  2064. cleanup_irq_cd2401_modem:
  2065. free_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt);
  2066. cleanup_irq_cd2401_errors:
  2067. free_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt);
  2068. cleanup_serial_driver:
  2069. if (tty_unregister_driver(cy_serial_driver))
  2070. printk(KERN_ERR "Couldn't unregister MVME166/7 serial driver\n");
  2071. put_tty_driver(cy_serial_driver);
  2072. return ret;
  2073. } /* serial167_init */
  2074. module_init(serial167_init);
  2075. #ifdef CYCLOM_SHOW_STATUS
  2076. static void
  2077. show_status(int line_num)
  2078. {
  2079. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  2080. int channel;
  2081. struct cyclades_port * info;
  2082. unsigned long flags;
  2083. info = &cy_port[line_num];
  2084. channel = info->line;
  2085. printk(" channel %d\n", channel);/**/
  2086. printk(" cy_port\n");
  2087. printk(" card line flags = %d %d %x\n",
  2088. info->card, info->line, info->flags);
  2089. printk(" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n",
  2090. (long)info->tty, info->read_status_mask,
  2091. info->timeout, info->xmit_fifo_size);
  2092. printk(" cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n",
  2093. info->cor1, info->cor2, info->cor3, info->cor4, info->cor5,
  2094. info->cor6, info->cor7);
  2095. printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n",
  2096. info->tbpr, info->tco, info->rbpr, info->rco);
  2097. printk(" close_delay event count = %d %d %d\n",
  2098. info->close_delay, info->event, info->count);
  2099. printk(" x_char blocked_open = %x %x\n",
  2100. info->x_char, info->blocked_open);
  2101. printk(" open_wait = %lx %lx %lx\n",
  2102. (long)info->open_wait);
  2103. local_irq_save(flags);
  2104. /* Global Registers */
  2105. printk(" CyGFRCR %x\n", base_addr[CyGFRCR]);
  2106. printk(" CyCAR %x\n", base_addr[CyCAR]);
  2107. printk(" CyRISR %x\n", base_addr[CyRISR]);
  2108. printk(" CyTISR %x\n", base_addr[CyTISR]);
  2109. printk(" CyMISR %x\n", base_addr[CyMISR]);
  2110. printk(" CyRIR %x\n", base_addr[CyRIR]);
  2111. printk(" CyTIR %x\n", base_addr[CyTIR]);
  2112. printk(" CyMIR %x\n", base_addr[CyMIR]);
  2113. printk(" CyTPR %x\n", base_addr[CyTPR]);
  2114. base_addr[CyCAR] = (u_char)channel;
  2115. /* Virtual Registers */
  2116. #if 0
  2117. printk(" CyRIVR %x\n", base_addr[CyRIVR]);
  2118. printk(" CyTIVR %x\n", base_addr[CyTIVR]);
  2119. printk(" CyMIVR %x\n", base_addr[CyMIVR]);
  2120. printk(" CyMISR %x\n", base_addr[CyMISR]);
  2121. #endif
  2122. /* Channel Registers */
  2123. printk(" CyCCR %x\n", base_addr[CyCCR]);
  2124. printk(" CyIER %x\n", base_addr[CyIER]);
  2125. printk(" CyCOR1 %x\n", base_addr[CyCOR1]);
  2126. printk(" CyCOR2 %x\n", base_addr[CyCOR2]);
  2127. printk(" CyCOR3 %x\n", base_addr[CyCOR3]);
  2128. printk(" CyCOR4 %x\n", base_addr[CyCOR4]);
  2129. printk(" CyCOR5 %x\n", base_addr[CyCOR5]);
  2130. #if 0
  2131. printk(" CyCCSR %x\n", base_addr[CyCCSR]);
  2132. printk(" CyRDCR %x\n", base_addr[CyRDCR]);
  2133. #endif
  2134. printk(" CySCHR1 %x\n", base_addr[CySCHR1]);
  2135. printk(" CySCHR2 %x\n", base_addr[CySCHR2]);
  2136. #if 0
  2137. printk(" CySCHR3 %x\n", base_addr[CySCHR3]);
  2138. printk(" CySCHR4 %x\n", base_addr[CySCHR4]);
  2139. printk(" CySCRL %x\n", base_addr[CySCRL]);
  2140. printk(" CySCRH %x\n", base_addr[CySCRH]);
  2141. printk(" CyLNC %x\n", base_addr[CyLNC]);
  2142. printk(" CyMCOR1 %x\n", base_addr[CyMCOR1]);
  2143. printk(" CyMCOR2 %x\n", base_addr[CyMCOR2]);
  2144. #endif
  2145. printk(" CyRTPRL %x\n", base_addr[CyRTPRL]);
  2146. printk(" CyRTPRH %x\n", base_addr[CyRTPRH]);
  2147. printk(" CyMSVR1 %x\n", base_addr[CyMSVR1]);
  2148. printk(" CyMSVR2 %x\n", base_addr[CyMSVR2]);
  2149. printk(" CyRBPR %x\n", base_addr[CyRBPR]);
  2150. printk(" CyRCOR %x\n", base_addr[CyRCOR]);
  2151. printk(" CyTBPR %x\n", base_addr[CyTBPR]);
  2152. printk(" CyTCOR %x\n", base_addr[CyTCOR]);
  2153. local_irq_restore(flags);
  2154. } /* show_status */
  2155. #endif
  2156. #if 0
  2157. /* Dummy routine in mvme16x/config.c for now */
  2158. /* Serial console setup. Called from linux/init/main.c */
  2159. void console_setup(char *str, int *ints)
  2160. {
  2161. char *s;
  2162. int baud, bits, parity;
  2163. int cflag = 0;
  2164. /* Sanity check. */
  2165. if (ints[0] > 3 || ints[1] > 3) return;
  2166. /* Get baud, bits and parity */
  2167. baud = 2400;
  2168. bits = 8;
  2169. parity = 'n';
  2170. if (ints[2]) baud = ints[2];
  2171. if ((s = strchr(str, ','))) {
  2172. do {
  2173. s++;
  2174. } while(*s >= '0' && *s <= '9');
  2175. if (*s) parity = *s++;
  2176. if (*s) bits = *s - '0';
  2177. }
  2178. /* Now construct a cflag setting. */
  2179. switch(baud) {
  2180. case 1200:
  2181. cflag |= B1200;
  2182. break;
  2183. case 9600:
  2184. cflag |= B9600;
  2185. break;
  2186. case 19200:
  2187. cflag |= B19200;
  2188. break;
  2189. case 38400:
  2190. cflag |= B38400;
  2191. break;
  2192. case 2400:
  2193. default:
  2194. cflag |= B2400;
  2195. break;
  2196. }
  2197. switch(bits) {
  2198. case 7:
  2199. cflag |= CS7;
  2200. break;
  2201. default:
  2202. case 8:
  2203. cflag |= CS8;
  2204. break;
  2205. }
  2206. switch(parity) {
  2207. case 'o': case 'O':
  2208. cflag |= PARODD;
  2209. break;
  2210. case 'e': case 'E':
  2211. cflag |= PARENB;
  2212. break;
  2213. }
  2214. serial_console_info = &cy_port[ints[1]];
  2215. serial_console_cflag = cflag;
  2216. serial_console = ints[1] + 64; /*callout_driver.minor_start*/
  2217. }
  2218. #endif
  2219. /*
  2220. * The following is probably out of date for 2.1.x serial console stuff.
  2221. *
  2222. * The console is registered early on from arch/m68k/kernel/setup.c, and
  2223. * it therefore relies on the chip being setup correctly by 166-Bug. This
  2224. * seems reasonable, as the serial port has been used to invoke the system
  2225. * boot. It also means that this function must not rely on any data
  2226. * initialisation performed by serial167_init() etc.
  2227. *
  2228. * Of course, once the console has been registered, we had better ensure
  2229. * that serial167_init() doesn't leave the chip non-functional.
  2230. *
  2231. * The console must be locked when we get here.
  2232. */
  2233. void serial167_console_write(struct console *co, const char *str, unsigned count)
  2234. {
  2235. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  2236. unsigned long flags;
  2237. volatile u_char sink;
  2238. u_char ier;
  2239. int port;
  2240. u_char do_lf = 0;
  2241. int i = 0;
  2242. local_irq_save(flags);
  2243. /* Ensure transmitter is enabled! */
  2244. port = 0;
  2245. base_addr[CyCAR] = (u_char)port;
  2246. while (base_addr[CyCCR])
  2247. ;
  2248. base_addr[CyCCR] = CyENB_XMTR;
  2249. ier = base_addr[CyIER];
  2250. base_addr[CyIER] = CyTxMpty;
  2251. while (1) {
  2252. if (pcc2chip[PccSCCTICR] & 0x20)
  2253. {
  2254. /* We have a Tx int. Acknowledge it */
  2255. sink = pcc2chip[PccTPIACKR];
  2256. if ((base_addr[CyLICR] >> 2) == port) {
  2257. if (i == count) {
  2258. /* Last char of string is now output */
  2259. base_addr[CyTEOIR] = CyNOTRANS;
  2260. break;
  2261. }
  2262. if (do_lf) {
  2263. base_addr[CyTDR] = '\n';
  2264. str++;
  2265. i++;
  2266. do_lf = 0;
  2267. }
  2268. else if (*str == '\n') {
  2269. base_addr[CyTDR] = '\r';
  2270. do_lf = 1;
  2271. }
  2272. else {
  2273. base_addr[CyTDR] = *str++;
  2274. i++;
  2275. }
  2276. base_addr[CyTEOIR] = 0;
  2277. }
  2278. else
  2279. base_addr[CyTEOIR] = CyNOTRANS;
  2280. }
  2281. }
  2282. base_addr[CyIER] = ier;
  2283. local_irq_restore(flags);
  2284. }
  2285. static struct tty_driver *serial167_console_device(struct console *c, int *index)
  2286. {
  2287. *index = c->index;
  2288. return cy_serial_driver;
  2289. }
  2290. static int __init serial167_console_setup(struct console *co, char *options)
  2291. {
  2292. return 0;
  2293. }
  2294. static struct console sercons = {
  2295. .name = "ttyS",
  2296. .write = serial167_console_write,
  2297. .device = serial167_console_device,
  2298. .setup = serial167_console_setup,
  2299. .flags = CON_PRINTBUFFER,
  2300. .index = -1,
  2301. };
  2302. static int __init serial167_console_init(void)
  2303. {
  2304. if (vme_brdtype == VME_TYPE_MVME166 ||
  2305. vme_brdtype == VME_TYPE_MVME167 ||
  2306. vme_brdtype == VME_TYPE_MVME177) {
  2307. mvme167_serial_console_setup(0);
  2308. register_console(&sercons);
  2309. }
  2310. return 0;
  2311. }
  2312. console_initcall(serial167_console_init);
  2313. #ifdef CONFIG_REMOTE_DEBUG
  2314. void putDebugChar (int c)
  2315. {
  2316. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  2317. unsigned long flags;
  2318. volatile u_char sink;
  2319. u_char ier;
  2320. int port;
  2321. local_irq_save(flags);
  2322. /* Ensure transmitter is enabled! */
  2323. port = DEBUG_PORT;
  2324. base_addr[CyCAR] = (u_char)port;
  2325. while (base_addr[CyCCR])
  2326. ;
  2327. base_addr[CyCCR] = CyENB_XMTR;
  2328. ier = base_addr[CyIER];
  2329. base_addr[CyIER] = CyTxMpty;
  2330. while (1) {
  2331. if (pcc2chip[PccSCCTICR] & 0x20)
  2332. {
  2333. /* We have a Tx int. Acknowledge it */
  2334. sink = pcc2chip[PccTPIACKR];
  2335. if ((base_addr[CyLICR] >> 2) == port) {
  2336. base_addr[CyTDR] = c;
  2337. base_addr[CyTEOIR] = 0;
  2338. break;
  2339. }
  2340. else
  2341. base_addr[CyTEOIR] = CyNOTRANS;
  2342. }
  2343. }
  2344. base_addr[CyIER] = ier;
  2345. local_irq_restore(flags);
  2346. }
  2347. int getDebugChar()
  2348. {
  2349. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  2350. unsigned long flags;
  2351. volatile u_char sink;
  2352. u_char ier;
  2353. int port;
  2354. int i, c;
  2355. i = debugiq.out;
  2356. if (i != debugiq.in) {
  2357. c = debugiq.buf[i];
  2358. if (++i == DEBUG_LEN)
  2359. i = 0;
  2360. debugiq.out = i;
  2361. return c;
  2362. }
  2363. /* OK, nothing in queue, wait in poll loop */
  2364. local_irq_save(flags);
  2365. /* Ensure receiver is enabled! */
  2366. port = DEBUG_PORT;
  2367. base_addr[CyCAR] = (u_char)port;
  2368. #if 0
  2369. while (base_addr[CyCCR])
  2370. ;
  2371. base_addr[CyCCR] = CyENB_RCVR;
  2372. #endif
  2373. ier = base_addr[CyIER];
  2374. base_addr[CyIER] = CyRxData;
  2375. while (1) {
  2376. if (pcc2chip[PccSCCRICR] & 0x20)
  2377. {
  2378. /* We have a Rx int. Acknowledge it */
  2379. sink = pcc2chip[PccRPIACKR];
  2380. if ((base_addr[CyLICR] >> 2) == port) {
  2381. int cnt = base_addr[CyRFOC];
  2382. while (cnt-- > 0)
  2383. {
  2384. c = base_addr[CyRDR];
  2385. if (c == 0)
  2386. printk ("!! debug char is null (cnt=%d) !!", cnt);
  2387. else
  2388. queueDebugChar (c);
  2389. }
  2390. base_addr[CyREOIR] = 0;
  2391. i = debugiq.out;
  2392. if (i == debugiq.in)
  2393. panic ("Debug input queue empty!");
  2394. c = debugiq.buf[i];
  2395. if (++i == DEBUG_LEN)
  2396. i = 0;
  2397. debugiq.out = i;
  2398. break;
  2399. }
  2400. else
  2401. base_addr[CyREOIR] = CyNOTRANS;
  2402. }
  2403. }
  2404. base_addr[CyIER] = ier;
  2405. local_irq_restore(flags);
  2406. return (c);
  2407. }
  2408. void queueDebugChar (int c)
  2409. {
  2410. int i;
  2411. i = debugiq.in;
  2412. debugiq.buf[i] = c;
  2413. if (++i == DEBUG_LEN)
  2414. i = 0;
  2415. if (i != debugiq.out)
  2416. debugiq.in = i;
  2417. }
  2418. static void
  2419. debug_setup()
  2420. {
  2421. unsigned long flags;
  2422. volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
  2423. int i, cflag;
  2424. cflag = B19200;
  2425. local_irq_save(flags);
  2426. for (i = 0; i < 4; i++)
  2427. {
  2428. base_addr[CyCAR] = i;
  2429. base_addr[CyLICR] = i << 2;
  2430. }
  2431. debugiq.in = debugiq.out = 0;
  2432. base_addr[CyCAR] = DEBUG_PORT;
  2433. /* baud rate */
  2434. i = cflag & CBAUD;
  2435. base_addr[CyIER] = 0;
  2436. base_addr[CyCMR] = CyASYNC;
  2437. base_addr[CyLICR] = DEBUG_PORT << 2;
  2438. base_addr[CyLIVR] = 0x5c;
  2439. /* tx and rx baud rate */
  2440. base_addr[CyTCOR] = baud_co[i];
  2441. base_addr[CyTBPR] = baud_bpr[i];
  2442. base_addr[CyRCOR] = baud_co[i] >> 5;
  2443. base_addr[CyRBPR] = baud_bpr[i];
  2444. /* set line characteristics according configuration */
  2445. base_addr[CySCHR1] = 0;
  2446. base_addr[CySCHR2] = 0;
  2447. base_addr[CySCRL] = 0;
  2448. base_addr[CySCRH] = 0;
  2449. base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
  2450. base_addr[CyCOR2] = 0;
  2451. base_addr[CyCOR3] = Cy_1_STOP;
  2452. base_addr[CyCOR4] = baud_cor4[i];
  2453. base_addr[CyCOR5] = 0;
  2454. base_addr[CyCOR6] = 0;
  2455. base_addr[CyCOR7] = 0;
  2456. write_cy_cmd(base_addr,CyINIT_CHAN);
  2457. write_cy_cmd(base_addr,CyENB_RCVR);
  2458. base_addr[CyCAR] = DEBUG_PORT; /* !!! Is this needed? */
  2459. base_addr[CyRTPRL] = 2;
  2460. base_addr[CyRTPRH] = 0;
  2461. base_addr[CyMSVR1] = CyRTS;
  2462. base_addr[CyMSVR2] = CyDTR;
  2463. base_addr[CyIER] = CyRxData;
  2464. local_irq_restore(flags);
  2465. } /* debug_setup */
  2466. #endif
  2467. MODULE_LICENSE("GPL");