serial167.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724
  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 void 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;
  956. if (!info->xmit_buf)
  957. return;
  958. local_irq_save(flags);
  959. if (info->xmit_cnt >= PAGE_SIZE - 1) {
  960. local_irq_restore(flags);
  961. return;
  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. } /* cy_put_char */
  968. static void cy_flush_chars(struct tty_struct *tty)
  969. {
  970. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  971. unsigned long flags;
  972. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  973. int channel;
  974. #ifdef SERIAL_DEBUG_IO
  975. printk("cy_flush_chars %s\n", tty->name); /* */
  976. #endif
  977. if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
  978. return;
  979. if (info->xmit_cnt <= 0 || tty->stopped
  980. || tty->hw_stopped || !info->xmit_buf)
  981. return;
  982. channel = info->line;
  983. local_irq_save(flags);
  984. base_addr[CyCAR] = channel;
  985. base_addr[CyIER] |= CyTxMpty;
  986. local_irq_restore(flags);
  987. } /* cy_flush_chars */
  988. /* This routine gets called when tty_write has put something into
  989. the write_queue. If the port is not already transmitting stuff,
  990. start it off by enabling interrupts. The interrupt service
  991. routine will then ensure that the characters are sent. If the
  992. port is already active, there is no need to kick it.
  993. */
  994. static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
  995. {
  996. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  997. unsigned long flags;
  998. int c, total = 0;
  999. #ifdef SERIAL_DEBUG_IO
  1000. printk("cy_write %s\n", tty->name); /* */
  1001. #endif
  1002. if (serial_paranoia_check(info, tty->name, "cy_write")) {
  1003. return 0;
  1004. }
  1005. if (!info->xmit_buf) {
  1006. return 0;
  1007. }
  1008. while (1) {
  1009. local_irq_save(flags);
  1010. c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
  1011. SERIAL_XMIT_SIZE - info->xmit_head));
  1012. if (c <= 0) {
  1013. local_irq_restore(flags);
  1014. break;
  1015. }
  1016. memcpy(info->xmit_buf + info->xmit_head, buf, c);
  1017. info->xmit_head =
  1018. (info->xmit_head + c) & (SERIAL_XMIT_SIZE - 1);
  1019. info->xmit_cnt += c;
  1020. local_irq_restore(flags);
  1021. buf += c;
  1022. count -= c;
  1023. total += c;
  1024. }
  1025. if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
  1026. start_xmit(info);
  1027. }
  1028. return total;
  1029. } /* cy_write */
  1030. static int cy_write_room(struct tty_struct *tty)
  1031. {
  1032. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1033. int ret;
  1034. #ifdef SERIAL_DEBUG_IO
  1035. printk("cy_write_room %s\n", tty->name); /* */
  1036. #endif
  1037. if (serial_paranoia_check(info, tty->name, "cy_write_room"))
  1038. return 0;
  1039. ret = PAGE_SIZE - info->xmit_cnt - 1;
  1040. if (ret < 0)
  1041. ret = 0;
  1042. return ret;
  1043. } /* cy_write_room */
  1044. static int cy_chars_in_buffer(struct tty_struct *tty)
  1045. {
  1046. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1047. #ifdef SERIAL_DEBUG_IO
  1048. printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt); /* */
  1049. #endif
  1050. if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
  1051. return 0;
  1052. return info->xmit_cnt;
  1053. } /* cy_chars_in_buffer */
  1054. static void cy_flush_buffer(struct tty_struct *tty)
  1055. {
  1056. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1057. unsigned long flags;
  1058. #ifdef SERIAL_DEBUG_IO
  1059. printk("cy_flush_buffer %s\n", tty->name); /* */
  1060. #endif
  1061. if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
  1062. return;
  1063. local_irq_save(flags);
  1064. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  1065. local_irq_restore(flags);
  1066. tty_wakeup(tty);
  1067. } /* cy_flush_buffer */
  1068. /* This routine is called by the upper-layer tty layer to signal
  1069. that incoming characters should be throttled or that the
  1070. throttle should be released.
  1071. */
  1072. static void cy_throttle(struct tty_struct *tty)
  1073. {
  1074. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1075. unsigned long flags;
  1076. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1077. int channel;
  1078. #ifdef SERIAL_DEBUG_THROTTLE
  1079. char buf[64];
  1080. printk("throttle %s: %d....\n", tty_name(tty, buf),
  1081. tty->ldisc.chars_in_buffer(tty));
  1082. printk("cy_throttle %s\n", tty->name);
  1083. #endif
  1084. if (serial_paranoia_check(info, tty->name, "cy_nthrottle")) {
  1085. return;
  1086. }
  1087. if (I_IXOFF(tty)) {
  1088. info->x_char = STOP_CHAR(tty);
  1089. /* Should use the "Send Special Character" feature!!! */
  1090. }
  1091. channel = info->line;
  1092. local_irq_save(flags);
  1093. base_addr[CyCAR] = (u_char) channel;
  1094. base_addr[CyMSVR1] = 0;
  1095. local_irq_restore(flags);
  1096. } /* cy_throttle */
  1097. static void cy_unthrottle(struct tty_struct *tty)
  1098. {
  1099. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1100. unsigned long flags;
  1101. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1102. int channel;
  1103. #ifdef SERIAL_DEBUG_THROTTLE
  1104. char buf[64];
  1105. printk("throttle %s: %d....\n", tty_name(tty, buf),
  1106. tty->ldisc.chars_in_buffer(tty));
  1107. printk("cy_unthrottle %s\n", tty->name);
  1108. #endif
  1109. if (serial_paranoia_check(info, tty->name, "cy_nthrottle")) {
  1110. return;
  1111. }
  1112. if (I_IXOFF(tty)) {
  1113. info->x_char = START_CHAR(tty);
  1114. /* Should use the "Send Special Character" feature!!! */
  1115. }
  1116. channel = info->line;
  1117. local_irq_save(flags);
  1118. base_addr[CyCAR] = (u_char) channel;
  1119. base_addr[CyMSVR1] = CyRTS;
  1120. local_irq_restore(flags);
  1121. } /* cy_unthrottle */
  1122. static int
  1123. get_serial_info(struct cyclades_port *info,
  1124. struct serial_struct __user * retinfo)
  1125. {
  1126. struct serial_struct tmp;
  1127. /* CP('g'); */
  1128. if (!retinfo)
  1129. return -EFAULT;
  1130. memset(&tmp, 0, sizeof(tmp));
  1131. tmp.type = info->type;
  1132. tmp.line = info->line;
  1133. tmp.port = info->line;
  1134. tmp.irq = 0;
  1135. tmp.flags = info->flags;
  1136. tmp.baud_base = 0; /*!!! */
  1137. tmp.close_delay = info->close_delay;
  1138. tmp.custom_divisor = 0; /*!!! */
  1139. tmp.hub6 = 0; /*!!! */
  1140. return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
  1141. } /* get_serial_info */
  1142. static int
  1143. set_serial_info(struct cyclades_port *info,
  1144. struct serial_struct __user * new_info)
  1145. {
  1146. struct serial_struct new_serial;
  1147. struct cyclades_port old_info;
  1148. /* CP('s'); */
  1149. if (!new_info)
  1150. return -EFAULT;
  1151. if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
  1152. return -EFAULT;
  1153. old_info = *info;
  1154. if (!capable(CAP_SYS_ADMIN)) {
  1155. if ((new_serial.close_delay != info->close_delay) ||
  1156. ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) !=
  1157. (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)))
  1158. return -EPERM;
  1159. info->flags = ((info->flags & ~ASYNC_USR_MASK) |
  1160. (new_serial.flags & ASYNC_USR_MASK));
  1161. goto check_and_exit;
  1162. }
  1163. /*
  1164. * OK, past this point, all the error checking has been done.
  1165. * At this point, we start making changes.....
  1166. */
  1167. info->flags = ((info->flags & ~ASYNC_FLAGS) |
  1168. (new_serial.flags & ASYNC_FLAGS));
  1169. info->close_delay = new_serial.close_delay;
  1170. check_and_exit:
  1171. if (info->flags & ASYNC_INITIALIZED) {
  1172. config_setup(info);
  1173. return 0;
  1174. }
  1175. return startup(info);
  1176. } /* set_serial_info */
  1177. static int cy_tiocmget(struct tty_struct *tty, struct file *file)
  1178. {
  1179. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1180. int channel;
  1181. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1182. unsigned long flags;
  1183. unsigned char status;
  1184. channel = info->line;
  1185. local_irq_save(flags);
  1186. base_addr[CyCAR] = (u_char) channel;
  1187. status = base_addr[CyMSVR1] | base_addr[CyMSVR2];
  1188. local_irq_restore(flags);
  1189. return ((status & CyRTS) ? TIOCM_RTS : 0)
  1190. | ((status & CyDTR) ? TIOCM_DTR : 0)
  1191. | ((status & CyDCD) ? TIOCM_CAR : 0)
  1192. | ((status & CyDSR) ? TIOCM_DSR : 0)
  1193. | ((status & CyCTS) ? TIOCM_CTS : 0);
  1194. } /* cy_tiocmget */
  1195. static int
  1196. cy_tiocmset(struct tty_struct *tty, struct file *file,
  1197. unsigned int set, unsigned int clear)
  1198. {
  1199. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1200. int channel;
  1201. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1202. unsigned long flags;
  1203. channel = info->line;
  1204. if (set & TIOCM_RTS) {
  1205. local_irq_save(flags);
  1206. base_addr[CyCAR] = (u_char) channel;
  1207. base_addr[CyMSVR1] = CyRTS;
  1208. local_irq_restore(flags);
  1209. }
  1210. if (set & TIOCM_DTR) {
  1211. local_irq_save(flags);
  1212. base_addr[CyCAR] = (u_char) channel;
  1213. /* CP('S');CP('2'); */
  1214. base_addr[CyMSVR2] = CyDTR;
  1215. #ifdef SERIAL_DEBUG_DTR
  1216. printk("cyc: %d: raising DTR\n", __LINE__);
  1217. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
  1218. base_addr[CyMSVR2]);
  1219. #endif
  1220. local_irq_restore(flags);
  1221. }
  1222. if (clear & TIOCM_RTS) {
  1223. local_irq_save(flags);
  1224. base_addr[CyCAR] = (u_char) channel;
  1225. base_addr[CyMSVR1] = 0;
  1226. local_irq_restore(flags);
  1227. }
  1228. if (clear & TIOCM_DTR) {
  1229. local_irq_save(flags);
  1230. base_addr[CyCAR] = (u_char) channel;
  1231. /* CP('C');CP('2'); */
  1232. base_addr[CyMSVR2] = 0;
  1233. #ifdef SERIAL_DEBUG_DTR
  1234. printk("cyc: %d: dropping DTR\n", __LINE__);
  1235. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
  1236. base_addr[CyMSVR2]);
  1237. #endif
  1238. local_irq_restore(flags);
  1239. }
  1240. return 0;
  1241. } /* set_modem_info */
  1242. static void send_break(struct cyclades_port *info, int duration)
  1243. { /* Let the transmit ISR take care of this (since it
  1244. requires stuffing characters into the output stream).
  1245. */
  1246. info->x_break = duration;
  1247. if (!info->xmit_cnt) {
  1248. start_xmit(info);
  1249. }
  1250. } /* send_break */
  1251. static int
  1252. get_mon_info(struct cyclades_port *info, struct cyclades_monitor __user * mon)
  1253. {
  1254. if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
  1255. return -EFAULT;
  1256. info->mon.int_count = 0;
  1257. info->mon.char_count = 0;
  1258. info->mon.char_max = 0;
  1259. info->mon.char_last = 0;
  1260. return 0;
  1261. }
  1262. static int set_threshold(struct cyclades_port *info, unsigned long __user * arg)
  1263. {
  1264. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1265. unsigned long value;
  1266. int channel;
  1267. if (get_user(value, arg))
  1268. return -EFAULT;
  1269. channel = info->line;
  1270. info->cor4 &= ~CyREC_FIFO;
  1271. info->cor4 |= value & CyREC_FIFO;
  1272. base_addr[CyCOR4] = info->cor4;
  1273. return 0;
  1274. }
  1275. static int
  1276. get_threshold(struct cyclades_port *info, unsigned long __user * value)
  1277. {
  1278. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1279. int channel;
  1280. unsigned long tmp;
  1281. channel = info->line;
  1282. tmp = base_addr[CyCOR4] & CyREC_FIFO;
  1283. return put_user(tmp, value);
  1284. }
  1285. static int
  1286. set_default_threshold(struct cyclades_port *info, unsigned long __user * arg)
  1287. {
  1288. unsigned long value;
  1289. if (get_user(value, arg))
  1290. return -EFAULT;
  1291. info->default_threshold = value & 0x0f;
  1292. return 0;
  1293. }
  1294. static int
  1295. get_default_threshold(struct cyclades_port *info, unsigned long __user * value)
  1296. {
  1297. return put_user(info->default_threshold, value);
  1298. }
  1299. static int set_timeout(struct cyclades_port *info, unsigned long __user * arg)
  1300. {
  1301. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1302. int channel;
  1303. unsigned long value;
  1304. if (get_user(value, arg))
  1305. return -EFAULT;
  1306. channel = info->line;
  1307. base_addr[CyRTPRL] = value & 0xff;
  1308. base_addr[CyRTPRH] = (value >> 8) & 0xff;
  1309. return 0;
  1310. }
  1311. static int get_timeout(struct cyclades_port *info, unsigned long __user * value)
  1312. {
  1313. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1314. int channel;
  1315. unsigned long tmp;
  1316. channel = info->line;
  1317. tmp = base_addr[CyRTPRL];
  1318. return put_user(tmp, value);
  1319. }
  1320. static int set_default_timeout(struct cyclades_port *info, unsigned long value)
  1321. {
  1322. info->default_timeout = value & 0xff;
  1323. return 0;
  1324. }
  1325. static int
  1326. get_default_timeout(struct cyclades_port *info, unsigned long __user * value)
  1327. {
  1328. return put_user(info->default_timeout, value);
  1329. }
  1330. static int
  1331. cy_ioctl(struct tty_struct *tty, struct file *file,
  1332. unsigned int cmd, unsigned long arg)
  1333. {
  1334. unsigned long val;
  1335. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1336. int ret_val = 0;
  1337. void __user *argp = (void __user *)arg;
  1338. #ifdef SERIAL_DEBUG_OTHER
  1339. printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */
  1340. #endif
  1341. switch (cmd) {
  1342. case CYGETMON:
  1343. ret_val = get_mon_info(info, argp);
  1344. break;
  1345. case CYGETTHRESH:
  1346. ret_val = get_threshold(info, argp);
  1347. break;
  1348. case CYSETTHRESH:
  1349. ret_val = set_threshold(info, argp);
  1350. break;
  1351. case CYGETDEFTHRESH:
  1352. ret_val = get_default_threshold(info, argp);
  1353. break;
  1354. case CYSETDEFTHRESH:
  1355. ret_val = set_default_threshold(info, argp);
  1356. break;
  1357. case CYGETTIMEOUT:
  1358. ret_val = get_timeout(info, argp);
  1359. break;
  1360. case CYSETTIMEOUT:
  1361. ret_val = set_timeout(info, argp);
  1362. break;
  1363. case CYGETDEFTIMEOUT:
  1364. ret_val = get_default_timeout(info, argp);
  1365. break;
  1366. case CYSETDEFTIMEOUT:
  1367. ret_val = set_default_timeout(info, (unsigned long)arg);
  1368. break;
  1369. case TCSBRK: /* SVID version: non-zero arg --> no break */
  1370. ret_val = tty_check_change(tty);
  1371. if (ret_val)
  1372. break;
  1373. tty_wait_until_sent(tty, 0);
  1374. if (!arg)
  1375. send_break(info, HZ / 4); /* 1/4 second */
  1376. break;
  1377. case TCSBRKP: /* support for POSIX tcsendbreak() */
  1378. ret_val = tty_check_change(tty);
  1379. if (ret_val)
  1380. break;
  1381. tty_wait_until_sent(tty, 0);
  1382. send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
  1383. break;
  1384. /* The following commands are incompletely implemented!!! */
  1385. case TIOCGSOFTCAR:
  1386. ret_val =
  1387. put_user(C_CLOCAL(tty) ? 1 : 0,
  1388. (unsigned long __user *)argp);
  1389. break;
  1390. case TIOCSSOFTCAR:
  1391. ret_val = get_user(val, (unsigned long __user *)argp);
  1392. if (ret_val)
  1393. break;
  1394. tty->termios->c_cflag =
  1395. ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0));
  1396. break;
  1397. case TIOCGSERIAL:
  1398. ret_val = get_serial_info(info, argp);
  1399. break;
  1400. case TIOCSSERIAL:
  1401. ret_val = set_serial_info(info, argp);
  1402. break;
  1403. default:
  1404. ret_val = -ENOIOCTLCMD;
  1405. }
  1406. #ifdef SERIAL_DEBUG_OTHER
  1407. printk("cy_ioctl done\n");
  1408. #endif
  1409. return ret_val;
  1410. } /* cy_ioctl */
  1411. static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
  1412. {
  1413. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1414. #ifdef SERIAL_DEBUG_OTHER
  1415. printk("cy_set_termios %s\n", tty->name);
  1416. #endif
  1417. if (tty->termios->c_cflag == old_termios->c_cflag)
  1418. return;
  1419. config_setup(info);
  1420. if ((old_termios->c_cflag & CRTSCTS) &&
  1421. !(tty->termios->c_cflag & CRTSCTS)) {
  1422. tty->stopped = 0;
  1423. cy_start(tty);
  1424. }
  1425. #ifdef tytso_patch_94Nov25_1726
  1426. if (!(old_termios->c_cflag & CLOCAL) &&
  1427. (tty->termios->c_cflag & CLOCAL))
  1428. wake_up_interruptible(&info->open_wait);
  1429. #endif
  1430. } /* cy_set_termios */
  1431. static void cy_close(struct tty_struct *tty, struct file *filp)
  1432. {
  1433. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1434. /* CP('C'); */
  1435. #ifdef SERIAL_DEBUG_OTHER
  1436. printk("cy_close %s\n", tty->name);
  1437. #endif
  1438. if (!info || serial_paranoia_check(info, tty->name, "cy_close")) {
  1439. return;
  1440. }
  1441. #ifdef SERIAL_DEBUG_OPEN
  1442. printk("cy_close %s, count = %d\n", tty->name, info->count);
  1443. #endif
  1444. if ((tty->count == 1) && (info->count != 1)) {
  1445. /*
  1446. * Uh, oh. tty->count is 1, which means that the tty
  1447. * structure will be freed. Info->count should always
  1448. * be one in these conditions. If it's greater than
  1449. * one, we've got real problems, since it means the
  1450. * serial port won't be shutdown.
  1451. */
  1452. printk("cy_close: bad serial port count; tty->count is 1, "
  1453. "info->count is %d\n", info->count);
  1454. info->count = 1;
  1455. }
  1456. #ifdef SERIAL_DEBUG_COUNT
  1457. printk("cyc: %d: decrementing count to %d\n", __LINE__,
  1458. info->count - 1);
  1459. #endif
  1460. if (--info->count < 0) {
  1461. printk("cy_close: bad serial port count for ttys%d: %d\n",
  1462. info->line, info->count);
  1463. #ifdef SERIAL_DEBUG_COUNT
  1464. printk("cyc: %d: setting count to 0\n", __LINE__);
  1465. #endif
  1466. info->count = 0;
  1467. }
  1468. if (info->count)
  1469. return;
  1470. info->flags |= ASYNC_CLOSING;
  1471. if (info->flags & ASYNC_INITIALIZED)
  1472. tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
  1473. shutdown(info);
  1474. if (tty->driver->flush_buffer)
  1475. tty->driver->flush_buffer(tty);
  1476. tty_ldisc_flush(tty);
  1477. info->tty = NULL;
  1478. if (info->blocked_open) {
  1479. if (info->close_delay) {
  1480. msleep_interruptible(jiffies_to_msecs
  1481. (info->close_delay));
  1482. }
  1483. wake_up_interruptible(&info->open_wait);
  1484. }
  1485. info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
  1486. wake_up_interruptible(&info->close_wait);
  1487. #ifdef SERIAL_DEBUG_OTHER
  1488. printk("cy_close done\n");
  1489. #endif
  1490. } /* cy_close */
  1491. /*
  1492. * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
  1493. */
  1494. void cy_hangup(struct tty_struct *tty)
  1495. {
  1496. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  1497. #ifdef SERIAL_DEBUG_OTHER
  1498. printk("cy_hangup %s\n", tty->name); /* */
  1499. #endif
  1500. if (serial_paranoia_check(info, tty->name, "cy_hangup"))
  1501. return;
  1502. shutdown(info);
  1503. #if 0
  1504. info->event = 0;
  1505. info->count = 0;
  1506. #ifdef SERIAL_DEBUG_COUNT
  1507. printk("cyc: %d: setting count to 0\n", __LINE__);
  1508. #endif
  1509. info->tty = 0;
  1510. #endif
  1511. info->flags &= ~ASYNC_NORMAL_ACTIVE;
  1512. wake_up_interruptible(&info->open_wait);
  1513. } /* cy_hangup */
  1514. /*
  1515. * ------------------------------------------------------------
  1516. * cy_open() and friends
  1517. * ------------------------------------------------------------
  1518. */
  1519. static int
  1520. block_til_ready(struct tty_struct *tty, struct file *filp,
  1521. struct cyclades_port *info)
  1522. {
  1523. DECLARE_WAITQUEUE(wait, current);
  1524. unsigned long flags;
  1525. int channel;
  1526. int retval;
  1527. volatile u_char *base_addr = (u_char *) BASE_ADDR;
  1528. /*
  1529. * If the device is in the middle of being closed, then block
  1530. * until it's done, and then try again.
  1531. */
  1532. if (info->flags & ASYNC_CLOSING) {
  1533. interruptible_sleep_on(&info->close_wait);
  1534. if (info->flags & ASYNC_HUP_NOTIFY) {
  1535. return -EAGAIN;
  1536. } else {
  1537. return -ERESTARTSYS;
  1538. }
  1539. }
  1540. /*
  1541. * If non-blocking mode is set, then make the check up front
  1542. * and then exit.
  1543. */
  1544. if (filp->f_flags & O_NONBLOCK) {
  1545. info->flags |= ASYNC_NORMAL_ACTIVE;
  1546. return 0;
  1547. }
  1548. /*
  1549. * Block waiting for the carrier detect and the line to become
  1550. * free (i.e., not in use by the callout). While we are in
  1551. * this loop, info->count is dropped by one, so that
  1552. * cy_close() knows when to free things. We restore it upon
  1553. * exit, either normal or abnormal.
  1554. */
  1555. retval = 0;
  1556. add_wait_queue(&info->open_wait, &wait);
  1557. #ifdef SERIAL_DEBUG_OPEN
  1558. printk("block_til_ready before block: %s, count = %d\n",
  1559. tty->name, info->count);
  1560. /**/
  1561. #endif
  1562. info->count--;
  1563. #ifdef SERIAL_DEBUG_COUNT
  1564. printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count);
  1565. #endif
  1566. info->blocked_open++;
  1567. channel = info->line;
  1568. while (1) {
  1569. local_irq_save(flags);
  1570. base_addr[CyCAR] = (u_char) channel;
  1571. base_addr[CyMSVR1] = CyRTS;
  1572. /* CP('S');CP('4'); */
  1573. base_addr[CyMSVR2] = CyDTR;
  1574. #ifdef SERIAL_DEBUG_DTR
  1575. printk("cyc: %d: raising DTR\n", __LINE__);
  1576. printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
  1577. base_addr[CyMSVR2]);
  1578. #endif
  1579. local_irq_restore(flags);
  1580. set_current_state(TASK_INTERRUPTIBLE);
  1581. if (tty_hung_up_p(filp)
  1582. || !(info->flags & ASYNC_INITIALIZED)) {
  1583. if (info->flags & ASYNC_HUP_NOTIFY) {
  1584. retval = -EAGAIN;
  1585. } else {
  1586. retval = -ERESTARTSYS;
  1587. }
  1588. break;
  1589. }
  1590. local_irq_save(flags);
  1591. base_addr[CyCAR] = (u_char) channel;
  1592. /* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */
  1593. if (!(info->flags & ASYNC_CLOSING)
  1594. && (C_CLOCAL(tty)
  1595. || (base_addr[CyMSVR1] & CyDCD))) {
  1596. local_irq_restore(flags);
  1597. break;
  1598. }
  1599. local_irq_restore(flags);
  1600. if (signal_pending(current)) {
  1601. retval = -ERESTARTSYS;
  1602. break;
  1603. }
  1604. #ifdef SERIAL_DEBUG_OPEN
  1605. printk("block_til_ready blocking: %s, count = %d\n",
  1606. tty->name, info->count);
  1607. /**/
  1608. #endif
  1609. schedule();
  1610. }
  1611. __set_current_state(TASK_RUNNING);
  1612. remove_wait_queue(&info->open_wait, &wait);
  1613. if (!tty_hung_up_p(filp)) {
  1614. info->count++;
  1615. #ifdef SERIAL_DEBUG_COUNT
  1616. printk("cyc: %d: incrementing count to %d\n", __LINE__,
  1617. info->count);
  1618. #endif
  1619. }
  1620. info->blocked_open--;
  1621. #ifdef SERIAL_DEBUG_OPEN
  1622. printk("block_til_ready after blocking: %s, count = %d\n",
  1623. tty->name, info->count);
  1624. /**/
  1625. #endif
  1626. if (retval)
  1627. return retval;
  1628. info->flags |= ASYNC_NORMAL_ACTIVE;
  1629. return 0;
  1630. } /* block_til_ready */
  1631. /*
  1632. * This routine is called whenever a serial port is opened. It
  1633. * performs the serial-specific initialization for the tty structure.
  1634. */
  1635. int cy_open(struct tty_struct *tty, struct file *filp)
  1636. {
  1637. struct cyclades_port *info;
  1638. int retval, line;
  1639. /* CP('O'); */
  1640. line = tty->index;
  1641. if ((line < 0) || (NR_PORTS <= line)) {
  1642. return -ENODEV;
  1643. }
  1644. info = &cy_port[line];
  1645. if (info->line < 0) {
  1646. return -ENODEV;
  1647. }
  1648. #ifdef SERIAL_DEBUG_OTHER
  1649. printk("cy_open %s\n", tty->name); /* */
  1650. #endif
  1651. if (serial_paranoia_check(info, tty->name, "cy_open")) {
  1652. return -ENODEV;
  1653. }
  1654. #ifdef SERIAL_DEBUG_OPEN
  1655. printk("cy_open %s, count = %d\n", tty->name, info->count);
  1656. /**/
  1657. #endif
  1658. info->count++;
  1659. #ifdef SERIAL_DEBUG_COUNT
  1660. printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
  1661. #endif
  1662. tty->driver_data = info;
  1663. info->tty = tty;
  1664. /*
  1665. * Start up serial port
  1666. */
  1667. retval = startup(info);
  1668. if (retval) {
  1669. return retval;
  1670. }
  1671. retval = block_til_ready(tty, filp, info);
  1672. if (retval) {
  1673. #ifdef SERIAL_DEBUG_OPEN
  1674. printk("cy_open returning after block_til_ready with %d\n",
  1675. retval);
  1676. #endif
  1677. return retval;
  1678. }
  1679. #ifdef SERIAL_DEBUG_OPEN
  1680. printk("cy_open done\n");
  1681. /**/
  1682. #endif
  1683. return 0;
  1684. } /* cy_open */
  1685. /*
  1686. * ---------------------------------------------------------------------
  1687. * serial167_init() and friends
  1688. *
  1689. * serial167_init() is called at boot-time to initialize the serial driver.
  1690. * ---------------------------------------------------------------------
  1691. */
  1692. /*
  1693. * This routine prints out the appropriate serial driver version
  1694. * number, and identifies which options were configured into this
  1695. * driver.
  1696. */
  1697. static void show_version(void)
  1698. {
  1699. printk("MVME166/167 cd2401 driver\n");
  1700. } /* show_version */
  1701. /* initialize chips on card -- return number of valid
  1702. chips (which is number of ports/4) */
  1703. /*
  1704. * This initialises the hardware to a reasonable state. It should
  1705. * probe the chip first so as to copy 166-Bug setup as a default for
  1706. * port 0. It initialises CMR to CyASYNC; that is never done again, so
  1707. * as to limit the number of CyINIT_CHAN commands in normal running.
  1708. *
  1709. * ... I wonder what I should do if this fails ...
  1710. */
  1711. void mvme167_serial_console_setup(int cflag)
  1712. {
  1713. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1714. int ch;
  1715. u_char spd;
  1716. u_char rcor, rbpr, badspeed = 0;
  1717. unsigned long flags;
  1718. local_irq_save(flags);
  1719. /*
  1720. * First probe channel zero of the chip, to see what speed has
  1721. * been selected.
  1722. */
  1723. base_addr[CyCAR] = 0;
  1724. rcor = base_addr[CyRCOR] << 5;
  1725. rbpr = base_addr[CyRBPR];
  1726. for (spd = 0; spd < sizeof(baud_bpr); spd++)
  1727. if (rbpr == baud_bpr[spd] && rcor == baud_co[spd])
  1728. break;
  1729. if (spd >= sizeof(baud_bpr)) {
  1730. spd = 14; /* 19200 */
  1731. badspeed = 1; /* Failed to identify speed */
  1732. }
  1733. initial_console_speed = spd;
  1734. /* OK, we have chosen a speed, now reset and reinitialise */
  1735. my_udelay(20000L); /* Allow time for any active o/p to complete */
  1736. if (base_addr[CyCCR] != 0x00) {
  1737. local_irq_restore(flags);
  1738. /* printk(" chip is never idle (CCR != 0)\n"); */
  1739. return;
  1740. }
  1741. base_addr[CyCCR] = CyCHIP_RESET; /* Reset the chip */
  1742. my_udelay(1000L);
  1743. if (base_addr[CyGFRCR] == 0x00) {
  1744. local_irq_restore(flags);
  1745. /* printk(" chip is not responding (GFRCR stayed 0)\n"); */
  1746. return;
  1747. }
  1748. /*
  1749. * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms
  1750. * tick
  1751. */
  1752. base_addr[CyTPR] = 10;
  1753. base_addr[CyPILR1] = 0x01; /* Interrupt level for modem change */
  1754. base_addr[CyPILR2] = 0x02; /* Interrupt level for tx ints */
  1755. base_addr[CyPILR3] = 0x03; /* Interrupt level for rx ints */
  1756. /*
  1757. * Attempt to set up all channels to something reasonable, and
  1758. * bang out a INIT_CHAN command. We should then be able to limit
  1759. * the ammount of fiddling we have to do in normal running.
  1760. */
  1761. for (ch = 3; ch >= 0; ch--) {
  1762. base_addr[CyCAR] = (u_char) ch;
  1763. base_addr[CyIER] = 0;
  1764. base_addr[CyCMR] = CyASYNC;
  1765. base_addr[CyLICR] = (u_char) ch << 2;
  1766. base_addr[CyLIVR] = 0x5c;
  1767. base_addr[CyTCOR] = baud_co[spd];
  1768. base_addr[CyTBPR] = baud_bpr[spd];
  1769. base_addr[CyRCOR] = baud_co[spd] >> 5;
  1770. base_addr[CyRBPR] = baud_bpr[spd];
  1771. base_addr[CySCHR1] = 'Q' & 0x1f;
  1772. base_addr[CySCHR2] = 'X' & 0x1f;
  1773. base_addr[CySCRL] = 0;
  1774. base_addr[CySCRH] = 0;
  1775. base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
  1776. base_addr[CyCOR2] = 0;
  1777. base_addr[CyCOR3] = Cy_1_STOP;
  1778. base_addr[CyCOR4] = baud_cor4[spd];
  1779. base_addr[CyCOR5] = 0;
  1780. base_addr[CyCOR6] = 0;
  1781. base_addr[CyCOR7] = 0;
  1782. base_addr[CyRTPRL] = 2;
  1783. base_addr[CyRTPRH] = 0;
  1784. base_addr[CyMSVR1] = 0;
  1785. base_addr[CyMSVR2] = 0;
  1786. write_cy_cmd(base_addr, CyINIT_CHAN | CyDIS_RCVR | CyDIS_XMTR);
  1787. }
  1788. /*
  1789. * Now do specials for channel zero....
  1790. */
  1791. base_addr[CyMSVR1] = CyRTS;
  1792. base_addr[CyMSVR2] = CyDTR;
  1793. base_addr[CyIER] = CyRxData;
  1794. write_cy_cmd(base_addr, CyENB_RCVR | CyENB_XMTR);
  1795. local_irq_restore(flags);
  1796. my_udelay(20000L); /* Let it all settle down */
  1797. printk("CD2401 initialised, chip is rev 0x%02x\n", base_addr[CyGFRCR]);
  1798. if (badspeed)
  1799. printk
  1800. (" WARNING: Failed to identify line speed, rcor=%02x,rbpr=%02x\n",
  1801. rcor >> 5, rbpr);
  1802. } /* serial_console_init */
  1803. static const struct tty_operations cy_ops = {
  1804. .open = cy_open,
  1805. .close = cy_close,
  1806. .write = cy_write,
  1807. .put_char = cy_put_char,
  1808. .flush_chars = cy_flush_chars,
  1809. .write_room = cy_write_room,
  1810. .chars_in_buffer = cy_chars_in_buffer,
  1811. .flush_buffer = cy_flush_buffer,
  1812. .ioctl = cy_ioctl,
  1813. .throttle = cy_throttle,
  1814. .unthrottle = cy_unthrottle,
  1815. .set_termios = cy_set_termios,
  1816. .stop = cy_stop,
  1817. .start = cy_start,
  1818. .hangup = cy_hangup,
  1819. .tiocmget = cy_tiocmget,
  1820. .tiocmset = cy_tiocmset,
  1821. };
  1822. /* The serial driver boot-time initialization code!
  1823. Hardware I/O ports are mapped to character special devices on a
  1824. first found, first allocated manner. That is, this code searches
  1825. for Cyclom cards in the system. As each is found, it is probed
  1826. to discover how many chips (and thus how many ports) are present.
  1827. These ports are mapped to the tty ports 64 and upward in monotonic
  1828. fashion. If an 8-port card is replaced with a 16-port card, the
  1829. port mapping on a following card will shift.
  1830. This approach is different from what is used in the other serial
  1831. device driver because the Cyclom is more properly a multiplexer,
  1832. not just an aggregation of serial ports on one card.
  1833. If there are more cards with more ports than have been statically
  1834. allocated above, a warning is printed and the extra ports are ignored.
  1835. */
  1836. static int __init serial167_init(void)
  1837. {
  1838. struct cyclades_port *info;
  1839. int ret = 0;
  1840. int good_ports = 0;
  1841. int port_num = 0;
  1842. int index;
  1843. int DefSpeed;
  1844. #ifdef notyet
  1845. struct sigaction sa;
  1846. #endif
  1847. if (!(mvme16x_config & MVME16x_CONFIG_GOT_CD2401))
  1848. return 0;
  1849. cy_serial_driver = alloc_tty_driver(NR_PORTS);
  1850. if (!cy_serial_driver)
  1851. return -ENOMEM;
  1852. #if 0
  1853. scrn[1] = '\0';
  1854. #endif
  1855. show_version();
  1856. /* Has "console=0,9600n8" been used in bootinfo to change speed? */
  1857. if (serial_console_cflag)
  1858. DefSpeed = serial_console_cflag & 0017;
  1859. else {
  1860. DefSpeed = initial_console_speed;
  1861. serial_console_info = &cy_port[0];
  1862. serial_console_cflag = DefSpeed | CS8;
  1863. #if 0
  1864. serial_console = 64; /*callout_driver.minor_start */
  1865. #endif
  1866. }
  1867. /* Initialize the tty_driver structure */
  1868. cy_serial_driver->owner = THIS_MODULE;
  1869. cy_serial_driver->name = "ttyS";
  1870. cy_serial_driver->major = TTY_MAJOR;
  1871. cy_serial_driver->minor_start = 64;
  1872. cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
  1873. cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
  1874. cy_serial_driver->init_termios = tty_std_termios;
  1875. cy_serial_driver->init_termios.c_cflag =
  1876. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  1877. cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
  1878. tty_set_operations(cy_serial_driver, &cy_ops);
  1879. ret = tty_register_driver(cy_serial_driver);
  1880. if (ret) {
  1881. printk(KERN_ERR "Couldn't register MVME166/7 serial driver\n");
  1882. put_tty_driver(cy_serial_driver);
  1883. return ret;
  1884. }
  1885. port_num = 0;
  1886. info = cy_port;
  1887. for (index = 0; index < 1; index++) {
  1888. good_ports = 4;
  1889. if (port_num < NR_PORTS) {
  1890. while (good_ports-- && port_num < NR_PORTS) {
  1891. /*** initialize port ***/
  1892. info->magic = CYCLADES_MAGIC;
  1893. info->type = PORT_CIRRUS;
  1894. info->card = index;
  1895. info->line = port_num;
  1896. info->flags = STD_COM_FLAGS;
  1897. info->tty = NULL;
  1898. info->xmit_fifo_size = 12;
  1899. info->cor1 = CyPARITY_NONE | Cy_8_BITS;
  1900. info->cor2 = CyETC;
  1901. info->cor3 = Cy_1_STOP;
  1902. info->cor4 = 0x08; /* _very_ small receive threshold */
  1903. info->cor5 = 0;
  1904. info->cor6 = 0;
  1905. info->cor7 = 0;
  1906. info->tbpr = baud_bpr[DefSpeed]; /* Tx BPR */
  1907. info->tco = baud_co[DefSpeed]; /* Tx CO */
  1908. info->rbpr = baud_bpr[DefSpeed]; /* Rx BPR */
  1909. info->rco = baud_co[DefSpeed] >> 5; /* Rx CO */
  1910. info->close_delay = 0;
  1911. info->x_char = 0;
  1912. info->count = 0;
  1913. #ifdef SERIAL_DEBUG_COUNT
  1914. printk("cyc: %d: setting count to 0\n",
  1915. __LINE__);
  1916. #endif
  1917. info->blocked_open = 0;
  1918. info->default_threshold = 0;
  1919. info->default_timeout = 0;
  1920. init_waitqueue_head(&info->open_wait);
  1921. init_waitqueue_head(&info->close_wait);
  1922. /* info->session */
  1923. /* info->pgrp */
  1924. /*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/
  1925. info->read_status_mask =
  1926. CyTIMEOUT | CySPECHAR | CyBREAK | CyPARITY |
  1927. CyFRAME | CyOVERRUN;
  1928. /* info->timeout */
  1929. printk("ttyS%d ", info->line);
  1930. port_num++;
  1931. info++;
  1932. if (!(port_num & 7)) {
  1933. printk("\n ");
  1934. }
  1935. }
  1936. }
  1937. printk("\n");
  1938. }
  1939. while (port_num < NR_PORTS) {
  1940. info->line = -1;
  1941. port_num++;
  1942. info++;
  1943. }
  1944. #ifdef CONFIG_REMOTE_DEBUG
  1945. debug_setup();
  1946. #endif
  1947. ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0,
  1948. "cd2401_errors", cd2401_rxerr_interrupt);
  1949. if (ret) {
  1950. printk(KERN_ERR "Could't get cd2401_errors IRQ");
  1951. goto cleanup_serial_driver;
  1952. }
  1953. ret = request_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt, 0,
  1954. "cd2401_modem", cd2401_modem_interrupt);
  1955. if (ret) {
  1956. printk(KERN_ERR "Could't get cd2401_modem IRQ");
  1957. goto cleanup_irq_cd2401_errors;
  1958. }
  1959. ret = request_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt, 0,
  1960. "cd2401_txints", cd2401_tx_interrupt);
  1961. if (ret) {
  1962. printk(KERN_ERR "Could't get cd2401_txints IRQ");
  1963. goto cleanup_irq_cd2401_modem;
  1964. }
  1965. ret = request_irq(MVME167_IRQ_SER_RX, cd2401_rx_interrupt, 0,
  1966. "cd2401_rxints", cd2401_rx_interrupt);
  1967. if (ret) {
  1968. printk(KERN_ERR "Could't get cd2401_rxints IRQ");
  1969. goto cleanup_irq_cd2401_txints;
  1970. }
  1971. /* Now we have registered the interrupt handlers, allow the interrupts */
  1972. pcc2chip[PccSCCMICR] = 0x15; /* Serial ints are level 5 */
  1973. pcc2chip[PccSCCTICR] = 0x15;
  1974. pcc2chip[PccSCCRICR] = 0x15;
  1975. pcc2chip[PccIMLR] = 3; /* Allow PCC2 ints above 3!? */
  1976. return 0;
  1977. cleanup_irq_cd2401_txints:
  1978. free_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt);
  1979. cleanup_irq_cd2401_modem:
  1980. free_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt);
  1981. cleanup_irq_cd2401_errors:
  1982. free_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt);
  1983. cleanup_serial_driver:
  1984. if (tty_unregister_driver(cy_serial_driver))
  1985. printk(KERN_ERR
  1986. "Couldn't unregister MVME166/7 serial driver\n");
  1987. put_tty_driver(cy_serial_driver);
  1988. return ret;
  1989. } /* serial167_init */
  1990. module_init(serial167_init);
  1991. #ifdef CYCLOM_SHOW_STATUS
  1992. static void show_status(int line_num)
  1993. {
  1994. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  1995. int channel;
  1996. struct cyclades_port *info;
  1997. unsigned long flags;
  1998. info = &cy_port[line_num];
  1999. channel = info->line;
  2000. printk(" channel %d\n", channel);
  2001. /**/ printk(" cy_port\n");
  2002. printk(" card line flags = %d %d %x\n",
  2003. info->card, info->line, info->flags);
  2004. printk
  2005. (" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n",
  2006. (long)info->tty, info->read_status_mask, info->timeout,
  2007. info->xmit_fifo_size);
  2008. printk(" cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n",
  2009. info->cor1, info->cor2, info->cor3, info->cor4, info->cor5,
  2010. info->cor6, info->cor7);
  2011. printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n", info->tbpr, info->tco,
  2012. info->rbpr, info->rco);
  2013. printk(" close_delay event count = %d %d %d\n", info->close_delay,
  2014. info->event, info->count);
  2015. printk(" x_char blocked_open = %x %x\n", info->x_char,
  2016. info->blocked_open);
  2017. printk(" open_wait = %lx %lx %lx\n", (long)info->open_wait);
  2018. local_irq_save(flags);
  2019. /* Global Registers */
  2020. printk(" CyGFRCR %x\n", base_addr[CyGFRCR]);
  2021. printk(" CyCAR %x\n", base_addr[CyCAR]);
  2022. printk(" CyRISR %x\n", base_addr[CyRISR]);
  2023. printk(" CyTISR %x\n", base_addr[CyTISR]);
  2024. printk(" CyMISR %x\n", base_addr[CyMISR]);
  2025. printk(" CyRIR %x\n", base_addr[CyRIR]);
  2026. printk(" CyTIR %x\n", base_addr[CyTIR]);
  2027. printk(" CyMIR %x\n", base_addr[CyMIR]);
  2028. printk(" CyTPR %x\n", base_addr[CyTPR]);
  2029. base_addr[CyCAR] = (u_char) channel;
  2030. /* Virtual Registers */
  2031. #if 0
  2032. printk(" CyRIVR %x\n", base_addr[CyRIVR]);
  2033. printk(" CyTIVR %x\n", base_addr[CyTIVR]);
  2034. printk(" CyMIVR %x\n", base_addr[CyMIVR]);
  2035. printk(" CyMISR %x\n", base_addr[CyMISR]);
  2036. #endif
  2037. /* Channel Registers */
  2038. printk(" CyCCR %x\n", base_addr[CyCCR]);
  2039. printk(" CyIER %x\n", base_addr[CyIER]);
  2040. printk(" CyCOR1 %x\n", base_addr[CyCOR1]);
  2041. printk(" CyCOR2 %x\n", base_addr[CyCOR2]);
  2042. printk(" CyCOR3 %x\n", base_addr[CyCOR3]);
  2043. printk(" CyCOR4 %x\n", base_addr[CyCOR4]);
  2044. printk(" CyCOR5 %x\n", base_addr[CyCOR5]);
  2045. #if 0
  2046. printk(" CyCCSR %x\n", base_addr[CyCCSR]);
  2047. printk(" CyRDCR %x\n", base_addr[CyRDCR]);
  2048. #endif
  2049. printk(" CySCHR1 %x\n", base_addr[CySCHR1]);
  2050. printk(" CySCHR2 %x\n", base_addr[CySCHR2]);
  2051. #if 0
  2052. printk(" CySCHR3 %x\n", base_addr[CySCHR3]);
  2053. printk(" CySCHR4 %x\n", base_addr[CySCHR4]);
  2054. printk(" CySCRL %x\n", base_addr[CySCRL]);
  2055. printk(" CySCRH %x\n", base_addr[CySCRH]);
  2056. printk(" CyLNC %x\n", base_addr[CyLNC]);
  2057. printk(" CyMCOR1 %x\n", base_addr[CyMCOR1]);
  2058. printk(" CyMCOR2 %x\n", base_addr[CyMCOR2]);
  2059. #endif
  2060. printk(" CyRTPRL %x\n", base_addr[CyRTPRL]);
  2061. printk(" CyRTPRH %x\n", base_addr[CyRTPRH]);
  2062. printk(" CyMSVR1 %x\n", base_addr[CyMSVR1]);
  2063. printk(" CyMSVR2 %x\n", base_addr[CyMSVR2]);
  2064. printk(" CyRBPR %x\n", base_addr[CyRBPR]);
  2065. printk(" CyRCOR %x\n", base_addr[CyRCOR]);
  2066. printk(" CyTBPR %x\n", base_addr[CyTBPR]);
  2067. printk(" CyTCOR %x\n", base_addr[CyTCOR]);
  2068. local_irq_restore(flags);
  2069. } /* show_status */
  2070. #endif
  2071. #if 0
  2072. /* Dummy routine in mvme16x/config.c for now */
  2073. /* Serial console setup. Called from linux/init/main.c */
  2074. void console_setup(char *str, int *ints)
  2075. {
  2076. char *s;
  2077. int baud, bits, parity;
  2078. int cflag = 0;
  2079. /* Sanity check. */
  2080. if (ints[0] > 3 || ints[1] > 3)
  2081. return;
  2082. /* Get baud, bits and parity */
  2083. baud = 2400;
  2084. bits = 8;
  2085. parity = 'n';
  2086. if (ints[2])
  2087. baud = ints[2];
  2088. if ((s = strchr(str, ','))) {
  2089. do {
  2090. s++;
  2091. } while (*s >= '0' && *s <= '9');
  2092. if (*s)
  2093. parity = *s++;
  2094. if (*s)
  2095. bits = *s - '0';
  2096. }
  2097. /* Now construct a cflag setting. */
  2098. switch (baud) {
  2099. case 1200:
  2100. cflag |= B1200;
  2101. break;
  2102. case 9600:
  2103. cflag |= B9600;
  2104. break;
  2105. case 19200:
  2106. cflag |= B19200;
  2107. break;
  2108. case 38400:
  2109. cflag |= B38400;
  2110. break;
  2111. case 2400:
  2112. default:
  2113. cflag |= B2400;
  2114. break;
  2115. }
  2116. switch (bits) {
  2117. case 7:
  2118. cflag |= CS7;
  2119. break;
  2120. default:
  2121. case 8:
  2122. cflag |= CS8;
  2123. break;
  2124. }
  2125. switch (parity) {
  2126. case 'o':
  2127. case 'O':
  2128. cflag |= PARODD;
  2129. break;
  2130. case 'e':
  2131. case 'E':
  2132. cflag |= PARENB;
  2133. break;
  2134. }
  2135. serial_console_info = &cy_port[ints[1]];
  2136. serial_console_cflag = cflag;
  2137. serial_console = ints[1] + 64; /*callout_driver.minor_start */
  2138. }
  2139. #endif
  2140. /*
  2141. * The following is probably out of date for 2.1.x serial console stuff.
  2142. *
  2143. * The console is registered early on from arch/m68k/kernel/setup.c, and
  2144. * it therefore relies on the chip being setup correctly by 166-Bug. This
  2145. * seems reasonable, as the serial port has been used to invoke the system
  2146. * boot. It also means that this function must not rely on any data
  2147. * initialisation performed by serial167_init() etc.
  2148. *
  2149. * Of course, once the console has been registered, we had better ensure
  2150. * that serial167_init() doesn't leave the chip non-functional.
  2151. *
  2152. * The console must be locked when we get here.
  2153. */
  2154. void serial167_console_write(struct console *co, const char *str,
  2155. unsigned count)
  2156. {
  2157. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  2158. unsigned long flags;
  2159. volatile u_char sink;
  2160. u_char ier;
  2161. int port;
  2162. u_char do_lf = 0;
  2163. int i = 0;
  2164. local_irq_save(flags);
  2165. /* Ensure transmitter is enabled! */
  2166. port = 0;
  2167. base_addr[CyCAR] = (u_char) port;
  2168. while (base_addr[CyCCR])
  2169. ;
  2170. base_addr[CyCCR] = CyENB_XMTR;
  2171. ier = base_addr[CyIER];
  2172. base_addr[CyIER] = CyTxMpty;
  2173. while (1) {
  2174. if (pcc2chip[PccSCCTICR] & 0x20) {
  2175. /* We have a Tx int. Acknowledge it */
  2176. sink = pcc2chip[PccTPIACKR];
  2177. if ((base_addr[CyLICR] >> 2) == port) {
  2178. if (i == count) {
  2179. /* Last char of string is now output */
  2180. base_addr[CyTEOIR] = CyNOTRANS;
  2181. break;
  2182. }
  2183. if (do_lf) {
  2184. base_addr[CyTDR] = '\n';
  2185. str++;
  2186. i++;
  2187. do_lf = 0;
  2188. } else if (*str == '\n') {
  2189. base_addr[CyTDR] = '\r';
  2190. do_lf = 1;
  2191. } else {
  2192. base_addr[CyTDR] = *str++;
  2193. i++;
  2194. }
  2195. base_addr[CyTEOIR] = 0;
  2196. } else
  2197. base_addr[CyTEOIR] = CyNOTRANS;
  2198. }
  2199. }
  2200. base_addr[CyIER] = ier;
  2201. local_irq_restore(flags);
  2202. }
  2203. static struct tty_driver *serial167_console_device(struct console *c,
  2204. int *index)
  2205. {
  2206. *index = c->index;
  2207. return cy_serial_driver;
  2208. }
  2209. static struct console sercons = {
  2210. .name = "ttyS",
  2211. .write = serial167_console_write,
  2212. .device = serial167_console_device,
  2213. .flags = CON_PRINTBUFFER,
  2214. .index = -1,
  2215. };
  2216. static int __init serial167_console_init(void)
  2217. {
  2218. if (vme_brdtype == VME_TYPE_MVME166 ||
  2219. vme_brdtype == VME_TYPE_MVME167 ||
  2220. vme_brdtype == VME_TYPE_MVME177) {
  2221. mvme167_serial_console_setup(0);
  2222. register_console(&sercons);
  2223. }
  2224. return 0;
  2225. }
  2226. console_initcall(serial167_console_init);
  2227. #ifdef CONFIG_REMOTE_DEBUG
  2228. void putDebugChar(int c)
  2229. {
  2230. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  2231. unsigned long flags;
  2232. volatile u_char sink;
  2233. u_char ier;
  2234. int port;
  2235. local_irq_save(flags);
  2236. /* Ensure transmitter is enabled! */
  2237. port = DEBUG_PORT;
  2238. base_addr[CyCAR] = (u_char) port;
  2239. while (base_addr[CyCCR])
  2240. ;
  2241. base_addr[CyCCR] = CyENB_XMTR;
  2242. ier = base_addr[CyIER];
  2243. base_addr[CyIER] = CyTxMpty;
  2244. while (1) {
  2245. if (pcc2chip[PccSCCTICR] & 0x20) {
  2246. /* We have a Tx int. Acknowledge it */
  2247. sink = pcc2chip[PccTPIACKR];
  2248. if ((base_addr[CyLICR] >> 2) == port) {
  2249. base_addr[CyTDR] = c;
  2250. base_addr[CyTEOIR] = 0;
  2251. break;
  2252. } else
  2253. base_addr[CyTEOIR] = CyNOTRANS;
  2254. }
  2255. }
  2256. base_addr[CyIER] = ier;
  2257. local_irq_restore(flags);
  2258. }
  2259. int getDebugChar()
  2260. {
  2261. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  2262. unsigned long flags;
  2263. volatile u_char sink;
  2264. u_char ier;
  2265. int port;
  2266. int i, c;
  2267. i = debugiq.out;
  2268. if (i != debugiq.in) {
  2269. c = debugiq.buf[i];
  2270. if (++i == DEBUG_LEN)
  2271. i = 0;
  2272. debugiq.out = i;
  2273. return c;
  2274. }
  2275. /* OK, nothing in queue, wait in poll loop */
  2276. local_irq_save(flags);
  2277. /* Ensure receiver is enabled! */
  2278. port = DEBUG_PORT;
  2279. base_addr[CyCAR] = (u_char) port;
  2280. #if 0
  2281. while (base_addr[CyCCR])
  2282. ;
  2283. base_addr[CyCCR] = CyENB_RCVR;
  2284. #endif
  2285. ier = base_addr[CyIER];
  2286. base_addr[CyIER] = CyRxData;
  2287. while (1) {
  2288. if (pcc2chip[PccSCCRICR] & 0x20) {
  2289. /* We have a Rx int. Acknowledge it */
  2290. sink = pcc2chip[PccRPIACKR];
  2291. if ((base_addr[CyLICR] >> 2) == port) {
  2292. int cnt = base_addr[CyRFOC];
  2293. while (cnt-- > 0) {
  2294. c = base_addr[CyRDR];
  2295. if (c == 0)
  2296. printk
  2297. ("!! debug char is null (cnt=%d) !!",
  2298. cnt);
  2299. else
  2300. queueDebugChar(c);
  2301. }
  2302. base_addr[CyREOIR] = 0;
  2303. i = debugiq.out;
  2304. if (i == debugiq.in)
  2305. panic("Debug input queue empty!");
  2306. c = debugiq.buf[i];
  2307. if (++i == DEBUG_LEN)
  2308. i = 0;
  2309. debugiq.out = i;
  2310. break;
  2311. } else
  2312. base_addr[CyREOIR] = CyNOTRANS;
  2313. }
  2314. }
  2315. base_addr[CyIER] = ier;
  2316. local_irq_restore(flags);
  2317. return (c);
  2318. }
  2319. void queueDebugChar(int c)
  2320. {
  2321. int i;
  2322. i = debugiq.in;
  2323. debugiq.buf[i] = c;
  2324. if (++i == DEBUG_LEN)
  2325. i = 0;
  2326. if (i != debugiq.out)
  2327. debugiq.in = i;
  2328. }
  2329. static void debug_setup()
  2330. {
  2331. unsigned long flags;
  2332. volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
  2333. int i, cflag;
  2334. cflag = B19200;
  2335. local_irq_save(flags);
  2336. for (i = 0; i < 4; i++) {
  2337. base_addr[CyCAR] = i;
  2338. base_addr[CyLICR] = i << 2;
  2339. }
  2340. debugiq.in = debugiq.out = 0;
  2341. base_addr[CyCAR] = DEBUG_PORT;
  2342. /* baud rate */
  2343. i = cflag & CBAUD;
  2344. base_addr[CyIER] = 0;
  2345. base_addr[CyCMR] = CyASYNC;
  2346. base_addr[CyLICR] = DEBUG_PORT << 2;
  2347. base_addr[CyLIVR] = 0x5c;
  2348. /* tx and rx baud rate */
  2349. base_addr[CyTCOR] = baud_co[i];
  2350. base_addr[CyTBPR] = baud_bpr[i];
  2351. base_addr[CyRCOR] = baud_co[i] >> 5;
  2352. base_addr[CyRBPR] = baud_bpr[i];
  2353. /* set line characteristics according configuration */
  2354. base_addr[CySCHR1] = 0;
  2355. base_addr[CySCHR2] = 0;
  2356. base_addr[CySCRL] = 0;
  2357. base_addr[CySCRH] = 0;
  2358. base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
  2359. base_addr[CyCOR2] = 0;
  2360. base_addr[CyCOR3] = Cy_1_STOP;
  2361. base_addr[CyCOR4] = baud_cor4[i];
  2362. base_addr[CyCOR5] = 0;
  2363. base_addr[CyCOR6] = 0;
  2364. base_addr[CyCOR7] = 0;
  2365. write_cy_cmd(base_addr, CyINIT_CHAN);
  2366. write_cy_cmd(base_addr, CyENB_RCVR);
  2367. base_addr[CyCAR] = DEBUG_PORT; /* !!! Is this needed? */
  2368. base_addr[CyRTPRL] = 2;
  2369. base_addr[CyRTPRH] = 0;
  2370. base_addr[CyMSVR1] = CyRTS;
  2371. base_addr[CyMSVR2] = CyDTR;
  2372. base_addr[CyIER] = CyRxData;
  2373. local_irq_restore(flags);
  2374. } /* debug_setup */
  2375. #endif
  2376. MODULE_LICENSE("GPL");