serial167.c 73 KB

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