serial167.c 74 KB

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