serial167.c 70 KB

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