serial167.c 73 KB

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