serial167.c 67 KB

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