serial167.c 63 KB

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