serial167.c 71 KB

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