serial167.c 67 KB

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