serial167.c 74 KB

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