serial167.c 68 KB

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