serial167.c 74 KB

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