specialix.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591
  1. /*
  2. * specialix.c -- specialix IO8+ multiport serial driver.
  3. *
  4. * Copyright (C) 1997 Roger Wolff (R.E.Wolff@BitWizard.nl)
  5. * Copyright (C) 1994-1996 Dmitry Gorodchanin (pgmdsg@ibi.com)
  6. *
  7. * Specialix pays for the development and support of this driver.
  8. * Please DO contact io8-linux@specialix.co.uk if you require
  9. * support. But please read the documentation (specialix.txt)
  10. * first.
  11. *
  12. * This driver was developped in the BitWizard linux device
  13. * driver service. If you require a linux device driver for your
  14. * product, please contact devices@BitWizard.nl for a quote.
  15. *
  16. * This code is firmly based on the riscom/8 serial driver,
  17. * written by Dmitry Gorodchanin. The specialix IO8+ card
  18. * programming information was obtained from the CL-CD1865 Data
  19. * Book, and Specialix document number 6200059: IO8+ Hardware
  20. * Functional Specification.
  21. *
  22. * This program is free software; you can redistribute it and/or
  23. * modify it under the terms of the GNU General Public License as
  24. * published by the Free Software Foundation; either version 2 of
  25. * the License, or (at your option) any later version.
  26. *
  27. * This program is distributed in the hope that it will be
  28. * useful, but WITHOUT ANY WARRANTY; without even the implied
  29. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  30. * PURPOSE. See the GNU General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU General Public
  33. * License along with this program; if not, write to the Free
  34. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  35. * USA.
  36. *
  37. * Revision history:
  38. *
  39. * Revision 1.0: April 1st 1997.
  40. * Initial release for alpha testing.
  41. * Revision 1.1: April 14th 1997.
  42. * Incorporated Richard Hudsons suggestions,
  43. * removed some debugging printk's.
  44. * Revision 1.2: April 15th 1997.
  45. * Ported to 2.1.x kernels.
  46. * Revision 1.3: April 17th 1997
  47. * Backported to 2.0. (Compatibility macros).
  48. * Revision 1.4: April 18th 1997
  49. * Fixed DTR/RTS bug that caused the card to indicate
  50. * "don't send data" to a modem after the password prompt.
  51. * Fixed bug for premature (fake) interrupts.
  52. * Revision 1.5: April 19th 1997
  53. * fixed a minor typo in the header file, cleanup a little.
  54. * performance warnings are now MAXed at once per minute.
  55. * Revision 1.6: May 23 1997
  56. * Changed the specialix=... format to include interrupt.
  57. * Revision 1.7: May 27 1997
  58. * Made many more debug printk's a compile time option.
  59. * Revision 1.8: Jul 1 1997
  60. * port to linux-2.1.43 kernel.
  61. * Revision 1.9: Oct 9 1998
  62. * Added stuff for the IO8+/PCI version.
  63. * Revision 1.10: Oct 22 1999 / Jan 21 2000.
  64. * Added stuff for setserial.
  65. * Nicolas Mailhot (Nicolas.Mailhot@email.enst.fr)
  66. *
  67. */
  68. #define VERSION "1.11"
  69. /*
  70. * There is a bunch of documentation about the card, jumpers, config
  71. * settings, restrictions, cables, device names and numbers in
  72. * Documentation/specialix.txt
  73. */
  74. #include <linux/config.h>
  75. #include <linux/module.h>
  76. #include <asm/io.h>
  77. #include <linux/kernel.h>
  78. #include <linux/sched.h>
  79. #include <linux/ioport.h>
  80. #include <linux/interrupt.h>
  81. #include <linux/errno.h>
  82. #include <linux/tty.h>
  83. #include <linux/tty_flip.h>
  84. #include <linux/mm.h>
  85. #include <linux/serial.h>
  86. #include <linux/fcntl.h>
  87. #include <linux/major.h>
  88. #include <linux/delay.h>
  89. #include <linux/pci.h>
  90. #include <linux/init.h>
  91. #include <asm/uaccess.h>
  92. #include "specialix_io8.h"
  93. #include "cd1865.h"
  94. /*
  95. This driver can spew a whole lot of debugging output at you. If you
  96. need maximum performance, you should disable the DEBUG define. To
  97. aid in debugging in the field, I'm leaving the compile-time debug
  98. features enabled, and disable them "runtime". That allows me to
  99. instruct people with problems to enable debugging without requiring
  100. them to recompile...
  101. */
  102. #define DEBUG
  103. static int sx_debug;
  104. static int sx_rxfifo = SPECIALIX_RXFIFO;
  105. #ifdef DEBUG
  106. #define dprintk(f, str...) if (sx_debug & f) printk (str)
  107. #else
  108. #define dprintk(f, str...) /* nothing */
  109. #endif
  110. #define SX_DEBUG_FLOW 0x0001
  111. #define SX_DEBUG_DATA 0x0002
  112. #define SX_DEBUG_PROBE 0x0004
  113. #define SX_DEBUG_CHAN 0x0008
  114. #define SX_DEBUG_INIT 0x0010
  115. #define SX_DEBUG_RX 0x0020
  116. #define SX_DEBUG_TX 0x0040
  117. #define SX_DEBUG_IRQ 0x0080
  118. #define SX_DEBUG_OPEN 0x0100
  119. #define SX_DEBUG_TERMIOS 0x0200
  120. #define SX_DEBUG_SIGNALS 0x0400
  121. #define SX_DEBUG_FIFO 0x0800
  122. #define func_enter() dprintk (SX_DEBUG_FLOW, "io8: enter %s\n",__FUNCTION__)
  123. #define func_exit() dprintk (SX_DEBUG_FLOW, "io8: exit %s\n", __FUNCTION__)
  124. #define jiffies_from_ms(a) ((((a) * HZ)/1000)+1)
  125. /* Configurable options: */
  126. /* Am I paranoid or not ? ;-) */
  127. #define SPECIALIX_PARANOIA_CHECK
  128. /* Do I trust the IRQ from the card? (enabeling it doesn't seem to help)
  129. When the IRQ routine leaves the chip in a state that is keeps on
  130. requiring attention, the timer doesn't help either. */
  131. #undef SPECIALIX_TIMER
  132. #ifdef SPECIALIX_TIMER
  133. static int sx_poll = HZ;
  134. #endif
  135. /*
  136. * The following defines are mostly for testing purposes. But if you need
  137. * some nice reporting in your syslog, you can define them also.
  138. */
  139. #undef SX_REPORT_FIFO
  140. #undef SX_REPORT_OVERRUN
  141. #ifdef CONFIG_SPECIALIX_RTSCTS
  142. #define SX_CRTSCTS(bla) 1
  143. #else
  144. #define SX_CRTSCTS(tty) C_CRTSCTS(tty)
  145. #endif
  146. /* Used to be outb (0xff, 0x80); */
  147. #define short_pause() udelay (1)
  148. #define SPECIALIX_LEGAL_FLAGS \
  149. (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \
  150. ASYNC_SPD_HI | ASYNC_SPEED_VHI | ASYNC_SESSION_LOCKOUT | \
  151. ASYNC_PGRP_LOCKOUT | ASYNC_CALLOUT_NOHUP)
  152. #undef RS_EVENT_WRITE_WAKEUP
  153. #define RS_EVENT_WRITE_WAKEUP 0
  154. static struct tty_driver *specialix_driver;
  155. static unsigned char * tmp_buf;
  156. static unsigned long baud_table[] = {
  157. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
  158. 9600, 19200, 38400, 57600, 115200, 0,
  159. };
  160. static struct specialix_board sx_board[SX_NBOARD] = {
  161. { 0, SX_IOBASE1, 9, },
  162. { 0, SX_IOBASE2, 11, },
  163. { 0, SX_IOBASE3, 12, },
  164. { 0, SX_IOBASE4, 15, },
  165. };
  166. static struct specialix_port sx_port[SX_NBOARD * SX_NPORT];
  167. #ifdef SPECIALIX_TIMER
  168. static struct timer_list missed_irq_timer;
  169. static irqreturn_t sx_interrupt(int irq, void * dev_id, struct pt_regs * regs);
  170. #endif
  171. static inline int sx_paranoia_check(struct specialix_port const * port,
  172. char *name, const char *routine)
  173. {
  174. #ifdef SPECIALIX_PARANOIA_CHECK
  175. static const char *badmagic =
  176. KERN_ERR "sx: Warning: bad specialix port magic number for device %s in %s\n";
  177. static const char *badinfo =
  178. KERN_ERR "sx: Warning: null specialix port for device %s in %s\n";
  179. if (!port) {
  180. printk(badinfo, name, routine);
  181. return 1;
  182. }
  183. if (port->magic != SPECIALIX_MAGIC) {
  184. printk(badmagic, name, routine);
  185. return 1;
  186. }
  187. #endif
  188. return 0;
  189. }
  190. /*
  191. *
  192. * Service functions for specialix IO8+ driver.
  193. *
  194. */
  195. /* Get board number from pointer */
  196. static inline int board_No (struct specialix_board * bp)
  197. {
  198. return bp - sx_board;
  199. }
  200. /* Get port number from pointer */
  201. static inline int port_No (struct specialix_port const * port)
  202. {
  203. return SX_PORT(port - sx_port);
  204. }
  205. /* Get pointer to board from pointer to port */
  206. static inline struct specialix_board * port_Board(struct specialix_port const * port)
  207. {
  208. return &sx_board[SX_BOARD(port - sx_port)];
  209. }
  210. /* Input Byte from CL CD186x register */
  211. static inline unsigned char sx_in(struct specialix_board * bp, unsigned short reg)
  212. {
  213. bp->reg = reg | 0x80;
  214. outb (reg | 0x80, bp->base + SX_ADDR_REG);
  215. return inb (bp->base + SX_DATA_REG);
  216. }
  217. /* Output Byte to CL CD186x register */
  218. static inline void sx_out(struct specialix_board * bp, unsigned short reg,
  219. unsigned char val)
  220. {
  221. bp->reg = reg | 0x80;
  222. outb (reg | 0x80, bp->base + SX_ADDR_REG);
  223. outb (val, bp->base + SX_DATA_REG);
  224. }
  225. /* Input Byte from CL CD186x register */
  226. static inline unsigned char sx_in_off(struct specialix_board * bp, unsigned short reg)
  227. {
  228. bp->reg = reg;
  229. outb (reg, bp->base + SX_ADDR_REG);
  230. return inb (bp->base + SX_DATA_REG);
  231. }
  232. /* Output Byte to CL CD186x register */
  233. static inline void sx_out_off(struct specialix_board * bp, unsigned short reg,
  234. unsigned char val)
  235. {
  236. bp->reg = reg;
  237. outb (reg, bp->base + SX_ADDR_REG);
  238. outb (val, bp->base + SX_DATA_REG);
  239. }
  240. /* Wait for Channel Command Register ready */
  241. static inline void sx_wait_CCR(struct specialix_board * bp)
  242. {
  243. unsigned long delay, flags;
  244. unsigned char ccr;
  245. for (delay = SX_CCR_TIMEOUT; delay; delay--) {
  246. spin_lock_irqsave(&bp->lock, flags);
  247. ccr = sx_in(bp, CD186x_CCR);
  248. spin_unlock_irqrestore(&bp->lock, flags);
  249. if (!ccr)
  250. return;
  251. udelay (1);
  252. }
  253. printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp));
  254. }
  255. /* Wait for Channel Command Register ready */
  256. static inline void sx_wait_CCR_off(struct specialix_board * bp)
  257. {
  258. unsigned long delay;
  259. unsigned char crr;
  260. unsigned long flags;
  261. for (delay = SX_CCR_TIMEOUT; delay; delay--) {
  262. spin_lock_irqsave(&bp->lock, flags);
  263. crr = sx_in_off(bp, CD186x_CCR);
  264. spin_unlock_irqrestore(&bp->lock, flags);
  265. if (!crr)
  266. return;
  267. udelay (1);
  268. }
  269. printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp));
  270. }
  271. /*
  272. * specialix IO8+ IO range functions.
  273. */
  274. static inline int sx_request_io_range(struct specialix_board * bp)
  275. {
  276. return request_region(bp->base,
  277. bp->flags & SX_BOARD_IS_PCI ? SX_PCI_IO_SPACE : SX_IO_SPACE,
  278. "specialix IO8+") == NULL;
  279. }
  280. static inline void sx_release_io_range(struct specialix_board * bp)
  281. {
  282. release_region(bp->base,
  283. bp->flags&SX_BOARD_IS_PCI?SX_PCI_IO_SPACE:SX_IO_SPACE);
  284. }
  285. /* Must be called with enabled interrupts */
  286. /* Ugly. Very ugly. Don't use this for anything else than initialization
  287. code */
  288. static inline void sx_long_delay(unsigned long delay)
  289. {
  290. unsigned long i;
  291. for (i = jiffies + delay; time_after(i, jiffies); ) ;
  292. }
  293. /* Set the IRQ using the RTS lines that run to the PAL on the board.... */
  294. static int sx_set_irq ( struct specialix_board *bp)
  295. {
  296. int virq;
  297. int i;
  298. unsigned long flags;
  299. if (bp->flags & SX_BOARD_IS_PCI)
  300. return 1;
  301. switch (bp->irq) {
  302. /* In the same order as in the docs... */
  303. case 15: virq = 0;break;
  304. case 12: virq = 1;break;
  305. case 11: virq = 2;break;
  306. case 9: virq = 3;break;
  307. default: printk (KERN_ERR "Speclialix: cannot set irq to %d.\n", bp->irq);
  308. return 0;
  309. }
  310. spin_lock_irqsave(&bp->lock, flags);
  311. for (i=0;i<2;i++) {
  312. sx_out(bp, CD186x_CAR, i);
  313. sx_out(bp, CD186x_MSVRTS, ((virq >> i) & 0x1)? MSVR_RTS:0);
  314. }
  315. spin_unlock_irqrestore(&bp->lock, flags);
  316. return 1;
  317. }
  318. /* Reset and setup CD186x chip */
  319. static int sx_init_CD186x(struct specialix_board * bp)
  320. {
  321. unsigned long flags;
  322. int scaler;
  323. int rv = 1;
  324. func_enter();
  325. sx_wait_CCR_off(bp); /* Wait for CCR ready */
  326. spin_lock_irqsave(&bp->lock, flags);
  327. sx_out_off(bp, CD186x_CCR, CCR_HARDRESET); /* Reset CD186x chip */
  328. spin_unlock_irqrestore(&bp->lock, flags);
  329. sx_long_delay(HZ/20); /* Delay 0.05 sec */
  330. spin_lock_irqsave(&bp->lock, flags);
  331. sx_out_off(bp, CD186x_GIVR, SX_ID); /* Set ID for this chip */
  332. sx_out_off(bp, CD186x_GICR, 0); /* Clear all bits */
  333. sx_out_off(bp, CD186x_PILR1, SX_ACK_MINT); /* Prio for modem intr */
  334. sx_out_off(bp, CD186x_PILR2, SX_ACK_TINT); /* Prio for transmitter intr */
  335. sx_out_off(bp, CD186x_PILR3, SX_ACK_RINT); /* Prio for receiver intr */
  336. /* Set RegAckEn */
  337. sx_out_off(bp, CD186x_SRCR, sx_in (bp, CD186x_SRCR) | SRCR_REGACKEN);
  338. /* Setting up prescaler. We need 4 ticks per 1 ms */
  339. scaler = SX_OSCFREQ/SPECIALIX_TPS;
  340. sx_out_off(bp, CD186x_PPRH, scaler >> 8);
  341. sx_out_off(bp, CD186x_PPRL, scaler & 0xff);
  342. spin_unlock_irqrestore(&bp->lock, flags);
  343. if (!sx_set_irq (bp)) {
  344. /* Figure out how to pass this along... */
  345. printk (KERN_ERR "Cannot set irq to %d.\n", bp->irq);
  346. rv = 0;
  347. }
  348. func_exit();
  349. return rv;
  350. }
  351. static int read_cross_byte (struct specialix_board *bp, int reg, int bit)
  352. {
  353. int i;
  354. int t;
  355. unsigned long flags;
  356. spin_lock_irqsave(&bp->lock, flags);
  357. for (i=0, t=0;i<8;i++) {
  358. sx_out_off (bp, CD186x_CAR, i);
  359. if (sx_in_off (bp, reg) & bit)
  360. t |= 1 << i;
  361. }
  362. spin_unlock_irqrestore(&bp->lock, flags);
  363. return t;
  364. }
  365. #ifdef SPECIALIX_TIMER
  366. void missed_irq (unsigned long data)
  367. {
  368. unsigned char irq;
  369. unsigned long flags;
  370. struct specialix_board *bp = (struct specialix_board *)data;
  371. spin_lock_irqsave(&bp->lock, flags);
  372. irq = sx_in ((struct specialix_board *)data, CD186x_SRSR) &
  373. (SRSR_RREQint |
  374. SRSR_TREQint |
  375. SRSR_MREQint);
  376. spin_unlock_irqrestore(&bp->lock, flags);
  377. if (irq) {
  378. printk (KERN_INFO "Missed interrupt... Calling int from timer. \n");
  379. sx_interrupt (((struct specialix_board *)data)->irq,
  380. (void*)data, NULL);
  381. }
  382. missed_irq_timer.expires = jiffies + sx_poll;
  383. add_timer (&missed_irq_timer);
  384. }
  385. #endif
  386. /* Main probing routine, also sets irq. */
  387. static int sx_probe(struct specialix_board *bp)
  388. {
  389. unsigned char val1, val2;
  390. #if 0
  391. int irqs = 0;
  392. int retries;
  393. #endif
  394. int rev;
  395. int chip;
  396. func_enter();
  397. if (sx_request_io_range(bp)) {
  398. func_exit();
  399. return 1;
  400. }
  401. /* Are the I/O ports here ? */
  402. sx_out_off(bp, CD186x_PPRL, 0x5a);
  403. short_pause ();
  404. val1 = sx_in_off(bp, CD186x_PPRL);
  405. sx_out_off(bp, CD186x_PPRL, 0xa5);
  406. short_pause ();
  407. val2 = sx_in_off(bp, CD186x_PPRL);
  408. if ((val1 != 0x5a) || (val2 != 0xa5)) {
  409. printk(KERN_INFO "sx%d: specialix IO8+ Board at 0x%03x not found.\n",
  410. board_No(bp), bp->base);
  411. sx_release_io_range(bp);
  412. func_exit();
  413. return 1;
  414. }
  415. /* Check the DSR lines that Specialix uses as board
  416. identification */
  417. val1 = read_cross_byte (bp, CD186x_MSVR, MSVR_DSR);
  418. val2 = read_cross_byte (bp, CD186x_MSVR, MSVR_RTS);
  419. dprintk (SX_DEBUG_INIT, "sx%d: DSR lines are: %02x, rts lines are: %02x\n",
  420. board_No(bp), val1, val2);
  421. /* They managed to switch the bit order between the docs and
  422. the IO8+ card. The new PCI card now conforms to old docs.
  423. They changed the PCI docs to reflect the situation on the
  424. old card. */
  425. val2 = (bp->flags & SX_BOARD_IS_PCI)?0x4d : 0xb2;
  426. if (val1 != val2) {
  427. printk(KERN_INFO "sx%d: specialix IO8+ ID %02x at 0x%03x not found (%02x).\n",
  428. board_No(bp), val2, bp->base, val1);
  429. sx_release_io_range(bp);
  430. func_exit();
  431. return 1;
  432. }
  433. #if 0
  434. /* It's time to find IRQ for this board */
  435. for (retries = 0; retries < 5 && irqs <= 0; retries++) {
  436. irqs = probe_irq_on();
  437. sx_init_CD186x(bp); /* Reset CD186x chip */
  438. sx_out(bp, CD186x_CAR, 2); /* Select port 2 */
  439. sx_wait_CCR(bp);
  440. sx_out(bp, CD186x_CCR, CCR_TXEN); /* Enable transmitter */
  441. sx_out(bp, CD186x_IER, IER_TXRDY); /* Enable tx empty intr */
  442. sx_long_delay(HZ/20);
  443. irqs = probe_irq_off(irqs);
  444. dprintk (SX_DEBUG_INIT, "SRSR = %02x, ", sx_in(bp, CD186x_SRSR));
  445. dprintk (SX_DEBUG_INIT, "TRAR = %02x, ", sx_in(bp, CD186x_TRAR));
  446. dprintk (SX_DEBUG_INIT, "GIVR = %02x, ", sx_in(bp, CD186x_GIVR));
  447. dprintk (SX_DEBUG_INIT, "GICR = %02x, ", sx_in(bp, CD186x_GICR));
  448. dprintk (SX_DEBUG_INIT, "\n");
  449. /* Reset CD186x again */
  450. if (!sx_init_CD186x(bp)) {
  451. /* Hmmm. This is dead code anyway. */
  452. }
  453. dprintk (SX_DEBUG_INIT "val1 = %02x, val2 = %02x, val3 = %02x.\n",
  454. val1, val2, val3);
  455. }
  456. #if 0
  457. if (irqs <= 0) {
  458. printk(KERN_ERR "sx%d: Can't find IRQ for specialix IO8+ board at 0x%03x.\n",
  459. board_No(bp), bp->base);
  460. sx_release_io_range(bp);
  461. func_exit();
  462. return 1;
  463. }
  464. #endif
  465. printk (KERN_INFO "Started with irq=%d, but now have irq=%d.\n", bp->irq, irqs);
  466. if (irqs > 0)
  467. bp->irq = irqs;
  468. #endif
  469. /* Reset CD186x again */
  470. if (!sx_init_CD186x(bp)) {
  471. sx_release_io_range(bp);
  472. func_exit();
  473. return 1;
  474. }
  475. sx_request_io_range(bp);
  476. bp->flags |= SX_BOARD_PRESENT;
  477. /* Chip revcode pkgtype
  478. GFRCR SRCR bit 7
  479. CD180 rev B 0x81 0
  480. CD180 rev C 0x82 0
  481. CD1864 rev A 0x82 1
  482. CD1865 rev A 0x83 1 -- Do not use!!! Does not work.
  483. CD1865 rev B 0x84 1
  484. -- Thanks to Gwen Wang, Cirrus Logic.
  485. */
  486. switch (sx_in_off(bp, CD186x_GFRCR)) {
  487. case 0x82:chip = 1864;rev='A';break;
  488. case 0x83:chip = 1865;rev='A';break;
  489. case 0x84:chip = 1865;rev='B';break;
  490. case 0x85:chip = 1865;rev='C';break; /* Does not exist at this time */
  491. default:chip=-1;rev='x';
  492. }
  493. dprintk (SX_DEBUG_INIT, " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR) );
  494. #ifdef SPECIALIX_TIMER
  495. init_timer (&missed_irq_timer);
  496. missed_irq_timer.function = missed_irq;
  497. missed_irq_timer.data = (unsigned long) bp;
  498. missed_irq_timer.expires = jiffies + sx_poll;
  499. add_timer (&missed_irq_timer);
  500. #endif
  501. printk(KERN_INFO"sx%d: specialix IO8+ board detected at 0x%03x, IRQ %d, CD%d Rev. %c.\n",
  502. board_No(bp),
  503. bp->base, bp->irq,
  504. chip, rev);
  505. func_exit();
  506. return 0;
  507. }
  508. /*
  509. *
  510. * Interrupt processing routines.
  511. * */
  512. static inline void sx_mark_event(struct specialix_port * port, int event)
  513. {
  514. func_enter();
  515. set_bit(event, &port->event);
  516. schedule_work(&port->tqueue);
  517. func_exit();
  518. }
  519. static inline struct specialix_port * sx_get_port(struct specialix_board * bp,
  520. unsigned char const * what)
  521. {
  522. unsigned char channel;
  523. struct specialix_port * port = NULL;
  524. channel = sx_in(bp, CD186x_GICR) >> GICR_CHAN_OFF;
  525. dprintk (SX_DEBUG_CHAN, "channel: %d\n", channel);
  526. if (channel < CD186x_NCH) {
  527. port = &sx_port[board_No(bp) * SX_NPORT + channel];
  528. dprintk (SX_DEBUG_CHAN, "port: %d %p flags: 0x%x\n",board_No(bp) * SX_NPORT + channel, port, port->flags & ASYNC_INITIALIZED);
  529. if (port->flags & ASYNC_INITIALIZED) {
  530. dprintk (SX_DEBUG_CHAN, "port: %d %p\n", channel, port);
  531. func_exit();
  532. return port;
  533. }
  534. }
  535. printk(KERN_INFO "sx%d: %s interrupt from invalid port %d\n",
  536. board_No(bp), what, channel);
  537. return NULL;
  538. }
  539. static inline void sx_receive_exc(struct specialix_board * bp)
  540. {
  541. struct specialix_port *port;
  542. struct tty_struct *tty;
  543. unsigned char status;
  544. unsigned char ch, flag;
  545. func_enter();
  546. port = sx_get_port(bp, "Receive");
  547. if (!port) {
  548. dprintk (SX_DEBUG_RX, "Hmm, couldn't find port.\n");
  549. func_exit();
  550. return;
  551. }
  552. tty = port->tty;
  553. status = sx_in(bp, CD186x_RCSR);
  554. dprintk (SX_DEBUG_RX, "status: 0x%x\n", status);
  555. if (status & RCSR_OE) {
  556. port->overrun++;
  557. dprintk(SX_DEBUG_FIFO, "sx%d: port %d: Overrun. Total %ld overruns.\n",
  558. board_No(bp), port_No(port), port->overrun);
  559. }
  560. status &= port->mark_mask;
  561. /* This flip buffer check needs to be below the reading of the
  562. status register to reset the chip's IRQ.... */
  563. if (tty_buffer_request_room(tty, 1) == 0) {
  564. dprintk(SX_DEBUG_FIFO, "sx%d: port %d: Working around flip buffer overflow.\n",
  565. board_No(bp), port_No(port));
  566. func_exit();
  567. return;
  568. }
  569. ch = sx_in(bp, CD186x_RDR);
  570. if (!status) {
  571. func_exit();
  572. return;
  573. }
  574. if (status & RCSR_TOUT) {
  575. printk(KERN_INFO "sx%d: port %d: Receiver timeout. Hardware problems ?\n",
  576. board_No(bp), port_No(port));
  577. func_exit();
  578. return;
  579. } else if (status & RCSR_BREAK) {
  580. dprintk(SX_DEBUG_RX, "sx%d: port %d: Handling break...\n",
  581. board_No(bp), port_No(port));
  582. flag = TTY_BREAK;
  583. if (port->flags & ASYNC_SAK)
  584. do_SAK(tty);
  585. } else if (status & RCSR_PE)
  586. flag = TTY_PARITY;
  587. else if (status & RCSR_FE)
  588. flag = TTY_FRAME;
  589. else if (status & RCSR_OE)
  590. flag = TTY_OVERRUN;
  591. else
  592. flag = TTY_NORMAL;
  593. if(tty_insert_flip_char(tty, ch, flag))
  594. tty_flip_buffer_push(tty);
  595. func_exit();
  596. }
  597. static inline void sx_receive(struct specialix_board * bp)
  598. {
  599. struct specialix_port *port;
  600. struct tty_struct *tty;
  601. unsigned char count;
  602. func_enter();
  603. if (!(port = sx_get_port(bp, "Receive"))) {
  604. dprintk (SX_DEBUG_RX, "Hmm, couldn't find port.\n");
  605. func_exit();
  606. return;
  607. }
  608. tty = port->tty;
  609. count = sx_in(bp, CD186x_RDCR);
  610. dprintk (SX_DEBUG_RX, "port: %p: count: %d\n", port, count);
  611. port->hits[count > 8 ? 9 : count]++;
  612. tty_buffer_request_room(tty, count);
  613. while (count--)
  614. tty_insert_flip_char(tty, sx_in(bp, CD186x_RDR), TTY_NORMAL);
  615. tty_flip_buffer_push(tty);
  616. func_exit();
  617. }
  618. static inline void sx_transmit(struct specialix_board * bp)
  619. {
  620. struct specialix_port *port;
  621. struct tty_struct *tty;
  622. unsigned char count;
  623. func_enter();
  624. if (!(port = sx_get_port(bp, "Transmit"))) {
  625. func_exit();
  626. return;
  627. }
  628. dprintk (SX_DEBUG_TX, "port: %p\n", port);
  629. tty = port->tty;
  630. if (port->IER & IER_TXEMPTY) {
  631. /* FIFO drained */
  632. sx_out(bp, CD186x_CAR, port_No(port));
  633. port->IER &= ~IER_TXEMPTY;
  634. sx_out(bp, CD186x_IER, port->IER);
  635. func_exit();
  636. return;
  637. }
  638. if ((port->xmit_cnt <= 0 && !port->break_length)
  639. || tty->stopped || tty->hw_stopped) {
  640. sx_out(bp, CD186x_CAR, port_No(port));
  641. port->IER &= ~IER_TXRDY;
  642. sx_out(bp, CD186x_IER, port->IER);
  643. func_exit();
  644. return;
  645. }
  646. if (port->break_length) {
  647. if (port->break_length > 0) {
  648. if (port->COR2 & COR2_ETC) {
  649. sx_out(bp, CD186x_TDR, CD186x_C_ESC);
  650. sx_out(bp, CD186x_TDR, CD186x_C_SBRK);
  651. port->COR2 &= ~COR2_ETC;
  652. }
  653. count = min_t(int, port->break_length, 0xff);
  654. sx_out(bp, CD186x_TDR, CD186x_C_ESC);
  655. sx_out(bp, CD186x_TDR, CD186x_C_DELAY);
  656. sx_out(bp, CD186x_TDR, count);
  657. if (!(port->break_length -= count))
  658. port->break_length--;
  659. } else {
  660. sx_out(bp, CD186x_TDR, CD186x_C_ESC);
  661. sx_out(bp, CD186x_TDR, CD186x_C_EBRK);
  662. sx_out(bp, CD186x_COR2, port->COR2);
  663. sx_wait_CCR(bp);
  664. sx_out(bp, CD186x_CCR, CCR_CORCHG2);
  665. port->break_length = 0;
  666. }
  667. func_exit();
  668. return;
  669. }
  670. count = CD186x_NFIFO;
  671. do {
  672. sx_out(bp, CD186x_TDR, port->xmit_buf[port->xmit_tail++]);
  673. port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1);
  674. if (--port->xmit_cnt <= 0)
  675. break;
  676. } while (--count > 0);
  677. if (port->xmit_cnt <= 0) {
  678. sx_out(bp, CD186x_CAR, port_No(port));
  679. port->IER &= ~IER_TXRDY;
  680. sx_out(bp, CD186x_IER, port->IER);
  681. }
  682. if (port->xmit_cnt <= port->wakeup_chars)
  683. sx_mark_event(port, RS_EVENT_WRITE_WAKEUP);
  684. func_exit();
  685. }
  686. static inline void sx_check_modem(struct specialix_board * bp)
  687. {
  688. struct specialix_port *port;
  689. struct tty_struct *tty;
  690. unsigned char mcr;
  691. int msvr_cd;
  692. dprintk (SX_DEBUG_SIGNALS, "Modem intr. ");
  693. if (!(port = sx_get_port(bp, "Modem")))
  694. return;
  695. tty = port->tty;
  696. mcr = sx_in(bp, CD186x_MCR);
  697. printk ("mcr = %02x.\n", mcr);
  698. if ((mcr & MCR_CDCHG)) {
  699. dprintk (SX_DEBUG_SIGNALS, "CD just changed... ");
  700. msvr_cd = sx_in(bp, CD186x_MSVR) & MSVR_CD;
  701. if (msvr_cd) {
  702. dprintk (SX_DEBUG_SIGNALS, "Waking up guys in open.\n");
  703. wake_up_interruptible(&port->open_wait);
  704. } else {
  705. dprintk (SX_DEBUG_SIGNALS, "Sending HUP.\n");
  706. schedule_work(&port->tqueue_hangup);
  707. }
  708. }
  709. #ifdef SPECIALIX_BRAIN_DAMAGED_CTS
  710. if (mcr & MCR_CTSCHG) {
  711. if (sx_in(bp, CD186x_MSVR) & MSVR_CTS) {
  712. tty->hw_stopped = 0;
  713. port->IER |= IER_TXRDY;
  714. if (port->xmit_cnt <= port->wakeup_chars)
  715. sx_mark_event(port, RS_EVENT_WRITE_WAKEUP);
  716. } else {
  717. tty->hw_stopped = 1;
  718. port->IER &= ~IER_TXRDY;
  719. }
  720. sx_out(bp, CD186x_IER, port->IER);
  721. }
  722. if (mcr & MCR_DSSXHG) {
  723. if (sx_in(bp, CD186x_MSVR) & MSVR_DSR) {
  724. tty->hw_stopped = 0;
  725. port->IER |= IER_TXRDY;
  726. if (port->xmit_cnt <= port->wakeup_chars)
  727. sx_mark_event(port, RS_EVENT_WRITE_WAKEUP);
  728. } else {
  729. tty->hw_stopped = 1;
  730. port->IER &= ~IER_TXRDY;
  731. }
  732. sx_out(bp, CD186x_IER, port->IER);
  733. }
  734. #endif /* SPECIALIX_BRAIN_DAMAGED_CTS */
  735. /* Clear change bits */
  736. sx_out(bp, CD186x_MCR, 0);
  737. }
  738. /* The main interrupt processing routine */
  739. static irqreturn_t sx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  740. {
  741. unsigned char status;
  742. unsigned char ack;
  743. struct specialix_board *bp;
  744. unsigned long loop = 0;
  745. int saved_reg;
  746. unsigned long flags;
  747. func_enter();
  748. bp = dev_id;
  749. spin_lock_irqsave(&bp->lock, flags);
  750. dprintk (SX_DEBUG_FLOW, "enter %s port %d room: %ld\n", __FUNCTION__, port_No(sx_get_port(bp, "INT")), SERIAL_XMIT_SIZE - sx_get_port(bp, "ITN")->xmit_cnt - 1);
  751. if (!bp || !(bp->flags & SX_BOARD_ACTIVE)) {
  752. dprintk (SX_DEBUG_IRQ, "sx: False interrupt. irq %d.\n", irq);
  753. spin_unlock_irqrestore(&bp->lock, flags);
  754. func_exit();
  755. return IRQ_NONE;
  756. }
  757. saved_reg = bp->reg;
  758. while ((++loop < 16) && (status = (sx_in(bp, CD186x_SRSR) &
  759. (SRSR_RREQint |
  760. SRSR_TREQint |
  761. SRSR_MREQint)))) {
  762. if (status & SRSR_RREQint) {
  763. ack = sx_in(bp, CD186x_RRAR);
  764. if (ack == (SX_ID | GIVR_IT_RCV))
  765. sx_receive(bp);
  766. else if (ack == (SX_ID | GIVR_IT_REXC))
  767. sx_receive_exc(bp);
  768. else
  769. printk(KERN_ERR "sx%d: status: 0x%x Bad receive ack 0x%02x.\n",
  770. board_No(bp), status, ack);
  771. } else if (status & SRSR_TREQint) {
  772. ack = sx_in(bp, CD186x_TRAR);
  773. if (ack == (SX_ID | GIVR_IT_TX))
  774. sx_transmit(bp);
  775. else
  776. printk(KERN_ERR "sx%d: status: 0x%x Bad transmit ack 0x%02x. port: %d\n",
  777. board_No(bp), status, ack, port_No (sx_get_port (bp, "Int")));
  778. } else if (status & SRSR_MREQint) {
  779. ack = sx_in(bp, CD186x_MRAR);
  780. if (ack == (SX_ID | GIVR_IT_MODEM))
  781. sx_check_modem(bp);
  782. else
  783. printk(KERN_ERR "sx%d: status: 0x%x Bad modem ack 0x%02x.\n",
  784. board_No(bp), status, ack);
  785. }
  786. sx_out(bp, CD186x_EOIR, 0); /* Mark end of interrupt */
  787. }
  788. bp->reg = saved_reg;
  789. outb (bp->reg, bp->base + SX_ADDR_REG);
  790. spin_unlock_irqrestore(&bp->lock, flags);
  791. func_exit();
  792. return IRQ_HANDLED;
  793. }
  794. /*
  795. * Routines for open & close processing.
  796. */
  797. static void turn_ints_off (struct specialix_board *bp)
  798. {
  799. unsigned long flags;
  800. func_enter();
  801. if (bp->flags & SX_BOARD_IS_PCI) {
  802. /* This was intended for enabeling the interrupt on the
  803. * PCI card. However it seems that it's already enabled
  804. * and as PCI interrupts can be shared, there is no real
  805. * reason to have to turn it off. */
  806. }
  807. spin_lock_irqsave(&bp->lock, flags);
  808. (void) sx_in_off (bp, 0); /* Turn off interrupts. */
  809. spin_unlock_irqrestore(&bp->lock, flags);
  810. func_exit();
  811. }
  812. static void turn_ints_on (struct specialix_board *bp)
  813. {
  814. unsigned long flags;
  815. func_enter();
  816. if (bp->flags & SX_BOARD_IS_PCI) {
  817. /* play with the PCI chip. See comment above. */
  818. }
  819. spin_lock_irqsave(&bp->lock, flags);
  820. (void) sx_in (bp, 0); /* Turn ON interrupts. */
  821. spin_unlock_irqrestore(&bp->lock, flags);
  822. func_exit();
  823. }
  824. /* Called with disabled interrupts */
  825. static inline int sx_setup_board(struct specialix_board * bp)
  826. {
  827. int error;
  828. if (bp->flags & SX_BOARD_ACTIVE)
  829. return 0;
  830. if (bp->flags & SX_BOARD_IS_PCI)
  831. error = request_irq(bp->irq, sx_interrupt, SA_INTERRUPT | SA_SHIRQ, "specialix IO8+", bp);
  832. else
  833. error = request_irq(bp->irq, sx_interrupt, SA_INTERRUPT, "specialix IO8+", bp);
  834. if (error)
  835. return error;
  836. turn_ints_on (bp);
  837. bp->flags |= SX_BOARD_ACTIVE;
  838. return 0;
  839. }
  840. /* Called with disabled interrupts */
  841. static inline void sx_shutdown_board(struct specialix_board *bp)
  842. {
  843. func_enter();
  844. if (!(bp->flags & SX_BOARD_ACTIVE)) {
  845. func_exit();
  846. return;
  847. }
  848. bp->flags &= ~SX_BOARD_ACTIVE;
  849. dprintk (SX_DEBUG_IRQ, "Freeing IRQ%d for board %d.\n",
  850. bp->irq, board_No (bp));
  851. free_irq(bp->irq, bp);
  852. turn_ints_off (bp);
  853. func_exit();
  854. }
  855. /*
  856. * Setting up port characteristics.
  857. * Must be called with disabled interrupts
  858. */
  859. static void sx_change_speed(struct specialix_board *bp, struct specialix_port *port)
  860. {
  861. struct tty_struct *tty;
  862. unsigned long baud;
  863. long tmp;
  864. unsigned char cor1 = 0, cor3 = 0;
  865. unsigned char mcor1 = 0, mcor2 = 0;
  866. static unsigned long again;
  867. unsigned long flags;
  868. func_enter();
  869. if (!(tty = port->tty) || !tty->termios) {
  870. func_exit();
  871. return;
  872. }
  873. port->IER = 0;
  874. port->COR2 = 0;
  875. /* Select port on the board */
  876. spin_lock_irqsave(&bp->lock, flags);
  877. sx_out(bp, CD186x_CAR, port_No(port));
  878. /* The Specialix board doens't implement the RTS lines.
  879. They are used to set the IRQ level. Don't touch them. */
  880. if (SX_CRTSCTS(tty))
  881. port->MSVR = MSVR_DTR | (sx_in(bp, CD186x_MSVR) & MSVR_RTS);
  882. else
  883. port->MSVR = (sx_in(bp, CD186x_MSVR) & MSVR_RTS);
  884. spin_unlock_irqrestore(&bp->lock, flags);
  885. dprintk (SX_DEBUG_TERMIOS, "sx: got MSVR=%02x.\n", port->MSVR);
  886. baud = C_BAUD(tty);
  887. if (baud & CBAUDEX) {
  888. baud &= ~CBAUDEX;
  889. if (baud < 1 || baud > 2)
  890. port->tty->termios->c_cflag &= ~CBAUDEX;
  891. else
  892. baud += 15;
  893. }
  894. if (baud == 15) {
  895. if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  896. baud ++;
  897. if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  898. baud += 2;
  899. }
  900. if (!baud_table[baud]) {
  901. /* Drop DTR & exit */
  902. dprintk (SX_DEBUG_TERMIOS, "Dropping DTR... Hmm....\n");
  903. if (!SX_CRTSCTS (tty)) {
  904. port -> MSVR &= ~ MSVR_DTR;
  905. spin_lock_irqsave(&bp->lock, flags);
  906. sx_out(bp, CD186x_MSVR, port->MSVR );
  907. spin_unlock_irqrestore(&bp->lock, flags);
  908. }
  909. else
  910. dprintk (SX_DEBUG_TERMIOS, "Can't drop DTR: no DTR.\n");
  911. return;
  912. } else {
  913. /* Set DTR on */
  914. if (!SX_CRTSCTS (tty)) {
  915. port ->MSVR |= MSVR_DTR;
  916. }
  917. }
  918. /*
  919. * Now we must calculate some speed depended things
  920. */
  921. /* Set baud rate for port */
  922. tmp = port->custom_divisor ;
  923. if ( tmp )
  924. printk (KERN_INFO "sx%d: Using custom baud rate divisor %ld. \n"
  925. "This is an untested option, please be carefull.\n",
  926. port_No (port), tmp);
  927. else
  928. tmp = (((SX_OSCFREQ + baud_table[baud]/2) / baud_table[baud] +
  929. CD186x_TPC/2) / CD186x_TPC);
  930. if ((tmp < 0x10) && time_before(again, jiffies)) {
  931. again = jiffies + HZ * 60;
  932. /* Page 48 of version 2.0 of the CL-CD1865 databook */
  933. if (tmp >= 12) {
  934. printk (KERN_INFO "sx%d: Baud rate divisor is %ld. \n"
  935. "Performance degradation is possible.\n"
  936. "Read specialix.txt for more info.\n",
  937. port_No (port), tmp);
  938. } else {
  939. printk (KERN_INFO "sx%d: Baud rate divisor is %ld. \n"
  940. "Warning: overstressing Cirrus chip. "
  941. "This might not work.\n"
  942. "Read specialix.txt for more info.\n",
  943. port_No (port), tmp);
  944. }
  945. }
  946. spin_lock_irqsave(&bp->lock, flags);
  947. sx_out(bp, CD186x_RBPRH, (tmp >> 8) & 0xff);
  948. sx_out(bp, CD186x_TBPRH, (tmp >> 8) & 0xff);
  949. sx_out(bp, CD186x_RBPRL, tmp & 0xff);
  950. sx_out(bp, CD186x_TBPRL, tmp & 0xff);
  951. spin_unlock_irqrestore(&bp->lock, flags);
  952. if (port->custom_divisor) {
  953. baud = (SX_OSCFREQ + port->custom_divisor/2) / port->custom_divisor;
  954. baud = ( baud + 5 ) / 10;
  955. } else
  956. baud = (baud_table[baud] + 5) / 10; /* Estimated CPS */
  957. /* Two timer ticks seems enough to wakeup something like SLIP driver */
  958. tmp = ((baud + HZ/2) / HZ) * 2 - CD186x_NFIFO;
  959. port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
  960. SERIAL_XMIT_SIZE - 1 : tmp);
  961. /* Receiver timeout will be transmission time for 1.5 chars */
  962. tmp = (SPECIALIX_TPS + SPECIALIX_TPS/2 + baud/2) / baud;
  963. tmp = (tmp > 0xff) ? 0xff : tmp;
  964. spin_lock_irqsave(&bp->lock, flags);
  965. sx_out(bp, CD186x_RTPR, tmp);
  966. spin_unlock_irqrestore(&bp->lock, flags);
  967. switch (C_CSIZE(tty)) {
  968. case CS5:
  969. cor1 |= COR1_5BITS;
  970. break;
  971. case CS6:
  972. cor1 |= COR1_6BITS;
  973. break;
  974. case CS7:
  975. cor1 |= COR1_7BITS;
  976. break;
  977. case CS8:
  978. cor1 |= COR1_8BITS;
  979. break;
  980. }
  981. if (C_CSTOPB(tty))
  982. cor1 |= COR1_2SB;
  983. cor1 |= COR1_IGNORE;
  984. if (C_PARENB(tty)) {
  985. cor1 |= COR1_NORMPAR;
  986. if (C_PARODD(tty))
  987. cor1 |= COR1_ODDP;
  988. if (I_INPCK(tty))
  989. cor1 &= ~COR1_IGNORE;
  990. }
  991. /* Set marking of some errors */
  992. port->mark_mask = RCSR_OE | RCSR_TOUT;
  993. if (I_INPCK(tty))
  994. port->mark_mask |= RCSR_FE | RCSR_PE;
  995. if (I_BRKINT(tty) || I_PARMRK(tty))
  996. port->mark_mask |= RCSR_BREAK;
  997. if (I_IGNPAR(tty))
  998. port->mark_mask &= ~(RCSR_FE | RCSR_PE);
  999. if (I_IGNBRK(tty)) {
  1000. port->mark_mask &= ~RCSR_BREAK;
  1001. if (I_IGNPAR(tty))
  1002. /* Real raw mode. Ignore all */
  1003. port->mark_mask &= ~RCSR_OE;
  1004. }
  1005. /* Enable Hardware Flow Control */
  1006. if (C_CRTSCTS(tty)) {
  1007. #ifdef SPECIALIX_BRAIN_DAMAGED_CTS
  1008. port->IER |= IER_DSR | IER_CTS;
  1009. mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
  1010. mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
  1011. spin_lock_irqsave(&bp->lock, flags);
  1012. tty->hw_stopped = !(sx_in(bp, CD186x_MSVR) & (MSVR_CTS|MSVR_DSR));
  1013. spin_unlock_irqrestore(&bp->lock, flags);
  1014. #else
  1015. port->COR2 |= COR2_CTSAE;
  1016. #endif
  1017. }
  1018. /* Enable Software Flow Control. FIXME: I'm not sure about this */
  1019. /* Some people reported that it works, but I still doubt it */
  1020. if (I_IXON(tty)) {
  1021. port->COR2 |= COR2_TXIBE;
  1022. cor3 |= (COR3_FCT | COR3_SCDE);
  1023. if (I_IXANY(tty))
  1024. port->COR2 |= COR2_IXM;
  1025. spin_lock_irqsave(&bp->lock, flags);
  1026. sx_out(bp, CD186x_SCHR1, START_CHAR(tty));
  1027. sx_out(bp, CD186x_SCHR2, STOP_CHAR(tty));
  1028. sx_out(bp, CD186x_SCHR3, START_CHAR(tty));
  1029. sx_out(bp, CD186x_SCHR4, STOP_CHAR(tty));
  1030. spin_unlock_irqrestore(&bp->lock, flags);
  1031. }
  1032. if (!C_CLOCAL(tty)) {
  1033. /* Enable CD check */
  1034. port->IER |= IER_CD;
  1035. mcor1 |= MCOR1_CDZD;
  1036. mcor2 |= MCOR2_CDOD;
  1037. }
  1038. if (C_CREAD(tty))
  1039. /* Enable receiver */
  1040. port->IER |= IER_RXD;
  1041. /* Set input FIFO size (1-8 bytes) */
  1042. cor3 |= sx_rxfifo;
  1043. /* Setting up CD186x channel registers */
  1044. spin_lock_irqsave(&bp->lock, flags);
  1045. sx_out(bp, CD186x_COR1, cor1);
  1046. sx_out(bp, CD186x_COR2, port->COR2);
  1047. sx_out(bp, CD186x_COR3, cor3);
  1048. spin_unlock_irqrestore(&bp->lock, flags);
  1049. /* Make CD186x know about registers change */
  1050. sx_wait_CCR(bp);
  1051. spin_lock_irqsave(&bp->lock, flags);
  1052. sx_out(bp, CD186x_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3);
  1053. /* Setting up modem option registers */
  1054. dprintk (SX_DEBUG_TERMIOS, "Mcor1 = %02x, mcor2 = %02x.\n", mcor1, mcor2);
  1055. sx_out(bp, CD186x_MCOR1, mcor1);
  1056. sx_out(bp, CD186x_MCOR2, mcor2);
  1057. spin_unlock_irqrestore(&bp->lock, flags);
  1058. /* Enable CD186x transmitter & receiver */
  1059. sx_wait_CCR(bp);
  1060. spin_lock_irqsave(&bp->lock, flags);
  1061. sx_out(bp, CD186x_CCR, CCR_TXEN | CCR_RXEN);
  1062. /* Enable interrupts */
  1063. sx_out(bp, CD186x_IER, port->IER);
  1064. /* And finally set the modem lines... */
  1065. sx_out(bp, CD186x_MSVR, port->MSVR);
  1066. spin_unlock_irqrestore(&bp->lock, flags);
  1067. func_exit();
  1068. }
  1069. /* Must be called with interrupts enabled */
  1070. static int sx_setup_port(struct specialix_board *bp, struct specialix_port *port)
  1071. {
  1072. unsigned long flags;
  1073. func_enter();
  1074. if (port->flags & ASYNC_INITIALIZED) {
  1075. func_exit();
  1076. return 0;
  1077. }
  1078. if (!port->xmit_buf) {
  1079. /* We may sleep in get_zeroed_page() */
  1080. unsigned long tmp;
  1081. if (!(tmp = get_zeroed_page(GFP_KERNEL))) {
  1082. func_exit();
  1083. return -ENOMEM;
  1084. }
  1085. if (port->xmit_buf) {
  1086. free_page(tmp);
  1087. func_exit();
  1088. return -ERESTARTSYS;
  1089. }
  1090. port->xmit_buf = (unsigned char *) tmp;
  1091. }
  1092. spin_lock_irqsave(&port->lock, flags);
  1093. if (port->tty)
  1094. clear_bit(TTY_IO_ERROR, &port->tty->flags);
  1095. port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
  1096. sx_change_speed(bp, port);
  1097. port->flags |= ASYNC_INITIALIZED;
  1098. spin_unlock_irqrestore(&port->lock, flags);
  1099. func_exit();
  1100. return 0;
  1101. }
  1102. /* Must be called with interrupts disabled */
  1103. static void sx_shutdown_port(struct specialix_board *bp, struct specialix_port *port)
  1104. {
  1105. struct tty_struct *tty;
  1106. int i;
  1107. unsigned long flags;
  1108. func_enter();
  1109. if (!(port->flags & ASYNC_INITIALIZED)) {
  1110. func_exit();
  1111. return;
  1112. }
  1113. if (sx_debug & SX_DEBUG_FIFO) {
  1114. dprintk(SX_DEBUG_FIFO, "sx%d: port %d: %ld overruns, FIFO hits [ ",
  1115. board_No(bp), port_No(port), port->overrun);
  1116. for (i = 0; i < 10; i++) {
  1117. dprintk(SX_DEBUG_FIFO, "%ld ", port->hits[i]);
  1118. }
  1119. dprintk(SX_DEBUG_FIFO, "].\n");
  1120. }
  1121. if (port->xmit_buf) {
  1122. free_page((unsigned long) port->xmit_buf);
  1123. port->xmit_buf = NULL;
  1124. }
  1125. /* Select port */
  1126. spin_lock_irqsave(&bp->lock, flags);
  1127. sx_out(bp, CD186x_CAR, port_No(port));
  1128. if (!(tty = port->tty) || C_HUPCL(tty)) {
  1129. /* Drop DTR */
  1130. sx_out(bp, CD186x_MSVDTR, 0);
  1131. }
  1132. spin_unlock_irqrestore(&bp->lock, flags);
  1133. /* Reset port */
  1134. sx_wait_CCR(bp);
  1135. spin_lock_irqsave(&bp->lock, flags);
  1136. sx_out(bp, CD186x_CCR, CCR_SOFTRESET);
  1137. /* Disable all interrupts from this port */
  1138. port->IER = 0;
  1139. sx_out(bp, CD186x_IER, port->IER);
  1140. spin_unlock_irqrestore(&bp->lock, flags);
  1141. if (tty)
  1142. set_bit(TTY_IO_ERROR, &tty->flags);
  1143. port->flags &= ~ASYNC_INITIALIZED;
  1144. if (!bp->count)
  1145. sx_shutdown_board(bp);
  1146. func_exit();
  1147. }
  1148. static int block_til_ready(struct tty_struct *tty, struct file * filp,
  1149. struct specialix_port *port)
  1150. {
  1151. DECLARE_WAITQUEUE(wait, current);
  1152. struct specialix_board *bp = port_Board(port);
  1153. int retval;
  1154. int do_clocal = 0;
  1155. int CD;
  1156. unsigned long flags;
  1157. func_enter();
  1158. /*
  1159. * If the device is in the middle of being closed, then block
  1160. * until it's done, and then try again.
  1161. */
  1162. if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
  1163. interruptible_sleep_on(&port->close_wait);
  1164. if (port->flags & ASYNC_HUP_NOTIFY) {
  1165. func_exit();
  1166. return -EAGAIN;
  1167. } else {
  1168. func_exit();
  1169. return -ERESTARTSYS;
  1170. }
  1171. }
  1172. /*
  1173. * If non-blocking mode is set, or the port is not enabled,
  1174. * then make the check up front and then exit.
  1175. */
  1176. if ((filp->f_flags & O_NONBLOCK) ||
  1177. (tty->flags & (1 << TTY_IO_ERROR))) {
  1178. port->flags |= ASYNC_NORMAL_ACTIVE;
  1179. func_exit();
  1180. return 0;
  1181. }
  1182. if (C_CLOCAL(tty))
  1183. do_clocal = 1;
  1184. /*
  1185. * Block waiting for the carrier detect and the line to become
  1186. * free (i.e., not in use by the callout). While we are in
  1187. * this loop, info->count is dropped by one, so that
  1188. * rs_close() knows when to free things. We restore it upon
  1189. * exit, either normal or abnormal.
  1190. */
  1191. retval = 0;
  1192. add_wait_queue(&port->open_wait, &wait);
  1193. spin_lock_irqsave(&port->lock, flags);
  1194. if (!tty_hung_up_p(filp)) {
  1195. port->count--;
  1196. }
  1197. spin_unlock_irqrestore(&port->lock, flags);
  1198. port->blocked_open++;
  1199. while (1) {
  1200. spin_lock_irqsave(&bp->lock, flags);
  1201. sx_out(bp, CD186x_CAR, port_No(port));
  1202. CD = sx_in(bp, CD186x_MSVR) & MSVR_CD;
  1203. if (SX_CRTSCTS (tty)) {
  1204. /* Activate RTS */
  1205. port->MSVR |= MSVR_DTR; /* WTF? */
  1206. sx_out (bp, CD186x_MSVR, port->MSVR);
  1207. } else {
  1208. /* Activate DTR */
  1209. port->MSVR |= MSVR_DTR;
  1210. sx_out (bp, CD186x_MSVR, port->MSVR);
  1211. }
  1212. spin_unlock_irqrestore(&bp->lock, flags);
  1213. set_current_state(TASK_INTERRUPTIBLE);
  1214. if (tty_hung_up_p(filp) ||
  1215. !(port->flags & ASYNC_INITIALIZED)) {
  1216. if (port->flags & ASYNC_HUP_NOTIFY)
  1217. retval = -EAGAIN;
  1218. else
  1219. retval = -ERESTARTSYS;
  1220. break;
  1221. }
  1222. if (!(port->flags & ASYNC_CLOSING) &&
  1223. (do_clocal || CD))
  1224. break;
  1225. if (signal_pending(current)) {
  1226. retval = -ERESTARTSYS;
  1227. break;
  1228. }
  1229. schedule();
  1230. }
  1231. set_current_state(TASK_RUNNING);
  1232. remove_wait_queue(&port->open_wait, &wait);
  1233. spin_lock_irqsave(&port->lock, flags);
  1234. if (!tty_hung_up_p(filp)) {
  1235. port->count++;
  1236. }
  1237. port->blocked_open--;
  1238. spin_unlock_irqrestore(&port->lock, flags);
  1239. if (retval) {
  1240. func_exit();
  1241. return retval;
  1242. }
  1243. port->flags |= ASYNC_NORMAL_ACTIVE;
  1244. func_exit();
  1245. return 0;
  1246. }
  1247. static int sx_open(struct tty_struct * tty, struct file * filp)
  1248. {
  1249. int board;
  1250. int error;
  1251. struct specialix_port * port;
  1252. struct specialix_board * bp;
  1253. int i;
  1254. unsigned long flags;
  1255. func_enter();
  1256. board = SX_BOARD(tty->index);
  1257. if (board >= SX_NBOARD || !(sx_board[board].flags & SX_BOARD_PRESENT)) {
  1258. func_exit();
  1259. return -ENODEV;
  1260. }
  1261. bp = &sx_board[board];
  1262. port = sx_port + board * SX_NPORT + SX_PORT(tty->index);
  1263. port->overrun = 0;
  1264. for (i = 0; i < 10; i++)
  1265. port->hits[i]=0;
  1266. dprintk (SX_DEBUG_OPEN, "Board = %d, bp = %p, port = %p, portno = %d.\n",
  1267. board, bp, port, SX_PORT(tty->index));
  1268. if (sx_paranoia_check(port, tty->name, "sx_open")) {
  1269. func_enter();
  1270. return -ENODEV;
  1271. }
  1272. if ((error = sx_setup_board(bp))) {
  1273. func_exit();
  1274. return error;
  1275. }
  1276. spin_lock_irqsave(&bp->lock, flags);
  1277. port->count++;
  1278. bp->count++;
  1279. tty->driver_data = port;
  1280. port->tty = tty;
  1281. spin_unlock_irqrestore(&bp->lock, flags);
  1282. if ((error = sx_setup_port(bp, port))) {
  1283. func_enter();
  1284. return error;
  1285. }
  1286. if ((error = block_til_ready(tty, filp, port))) {
  1287. func_enter();
  1288. return error;
  1289. }
  1290. func_exit();
  1291. return 0;
  1292. }
  1293. static void sx_close(struct tty_struct * tty, struct file * filp)
  1294. {
  1295. struct specialix_port *port = (struct specialix_port *) tty->driver_data;
  1296. struct specialix_board *bp;
  1297. unsigned long flags;
  1298. unsigned long timeout;
  1299. func_enter();
  1300. if (!port || sx_paranoia_check(port, tty->name, "close")) {
  1301. func_exit();
  1302. return;
  1303. }
  1304. spin_lock_irqsave(&port->lock, flags);
  1305. if (tty_hung_up_p(filp)) {
  1306. spin_unlock_irqrestore(&port->lock, flags);
  1307. func_exit();
  1308. return;
  1309. }
  1310. bp = port_Board(port);
  1311. if ((tty->count == 1) && (port->count != 1)) {
  1312. printk(KERN_ERR "sx%d: sx_close: bad port count;"
  1313. " tty->count is 1, port count is %d\n",
  1314. board_No(bp), port->count);
  1315. port->count = 1;
  1316. }
  1317. if (port->count > 1) {
  1318. port->count--;
  1319. bp->count--;
  1320. spin_unlock_irqrestore(&port->lock, flags);
  1321. func_exit();
  1322. return;
  1323. }
  1324. port->flags |= ASYNC_CLOSING;
  1325. /*
  1326. * Now we wait for the transmit buffer to clear; and we notify
  1327. * the line discipline to only process XON/XOFF characters.
  1328. */
  1329. tty->closing = 1;
  1330. spin_unlock_irqrestore(&port->lock, flags);
  1331. dprintk (SX_DEBUG_OPEN, "Closing\n");
  1332. if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) {
  1333. tty_wait_until_sent(tty, port->closing_wait);
  1334. }
  1335. /*
  1336. * At this point we stop accepting input. To do this, we
  1337. * disable the receive line status interrupts, and tell the
  1338. * interrupt driver to stop checking the data ready bit in the
  1339. * line status register.
  1340. */
  1341. dprintk (SX_DEBUG_OPEN, "Closed\n");
  1342. port->IER &= ~IER_RXD;
  1343. if (port->flags & ASYNC_INITIALIZED) {
  1344. port->IER &= ~IER_TXRDY;
  1345. port->IER |= IER_TXEMPTY;
  1346. spin_lock_irqsave(&bp->lock, flags);
  1347. sx_out(bp, CD186x_CAR, port_No(port));
  1348. sx_out(bp, CD186x_IER, port->IER);
  1349. spin_unlock_irqrestore(&bp->lock, flags);
  1350. /*
  1351. * Before we drop DTR, make sure the UART transmitter
  1352. * has completely drained; this is especially
  1353. * important if there is a transmit FIFO!
  1354. */
  1355. timeout = jiffies+HZ;
  1356. while(port->IER & IER_TXEMPTY) {
  1357. set_current_state (TASK_INTERRUPTIBLE);
  1358. msleep_interruptible(jiffies_to_msecs(port->timeout));
  1359. if (time_after(jiffies, timeout)) {
  1360. printk (KERN_INFO "Timeout waiting for close\n");
  1361. break;
  1362. }
  1363. }
  1364. }
  1365. if (--bp->count < 0) {
  1366. printk(KERN_ERR "sx%d: sx_shutdown_port: bad board count: %d port: %d\n",
  1367. board_No(bp), bp->count, tty->index);
  1368. bp->count = 0;
  1369. }
  1370. if (--port->count < 0) {
  1371. printk(KERN_ERR "sx%d: sx_close: bad port count for tty%d: %d\n",
  1372. board_No(bp), port_No(port), port->count);
  1373. port->count = 0;
  1374. }
  1375. sx_shutdown_port(bp, port);
  1376. if (tty->driver->flush_buffer)
  1377. tty->driver->flush_buffer(tty);
  1378. tty_ldisc_flush(tty);
  1379. spin_lock_irqsave(&port->lock, flags);
  1380. tty->closing = 0;
  1381. port->event = 0;
  1382. port->tty = NULL;
  1383. spin_unlock_irqrestore(&port->lock, flags);
  1384. if (port->blocked_open) {
  1385. if (port->close_delay) {
  1386. msleep_interruptible(jiffies_to_msecs(port->close_delay));
  1387. }
  1388. wake_up_interruptible(&port->open_wait);
  1389. }
  1390. port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  1391. wake_up_interruptible(&port->close_wait);
  1392. func_exit();
  1393. }
  1394. static int sx_write(struct tty_struct * tty,
  1395. const unsigned char *buf, int count)
  1396. {
  1397. struct specialix_port *port = (struct specialix_port *)tty->driver_data;
  1398. struct specialix_board *bp;
  1399. int c, total = 0;
  1400. unsigned long flags;
  1401. func_enter();
  1402. if (sx_paranoia_check(port, tty->name, "sx_write")) {
  1403. func_exit();
  1404. return 0;
  1405. }
  1406. bp = port_Board(port);
  1407. if (!tty || !port->xmit_buf || !tmp_buf) {
  1408. func_exit();
  1409. return 0;
  1410. }
  1411. while (1) {
  1412. spin_lock_irqsave(&port->lock, flags);
  1413. c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
  1414. SERIAL_XMIT_SIZE - port->xmit_head));
  1415. if (c <= 0) {
  1416. spin_unlock_irqrestore(&port->lock, flags);
  1417. break;
  1418. }
  1419. memcpy(port->xmit_buf + port->xmit_head, buf, c);
  1420. port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
  1421. port->xmit_cnt += c;
  1422. spin_unlock_irqrestore(&port->lock, flags);
  1423. buf += c;
  1424. count -= c;
  1425. total += c;
  1426. }
  1427. spin_lock_irqsave(&bp->lock, flags);
  1428. if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
  1429. !(port->IER & IER_TXRDY)) {
  1430. port->IER |= IER_TXRDY;
  1431. sx_out(bp, CD186x_CAR, port_No(port));
  1432. sx_out(bp, CD186x_IER, port->IER);
  1433. }
  1434. spin_unlock_irqrestore(&bp->lock, flags);
  1435. func_exit();
  1436. return total;
  1437. }
  1438. static void sx_put_char(struct tty_struct * tty, unsigned char ch)
  1439. {
  1440. struct specialix_port *port = (struct specialix_port *)tty->driver_data;
  1441. unsigned long flags;
  1442. struct specialix_board * bp;
  1443. func_enter();
  1444. if (sx_paranoia_check(port, tty->name, "sx_put_char")) {
  1445. func_exit();
  1446. return;
  1447. }
  1448. dprintk (SX_DEBUG_TX, "check tty: %p %p\n", tty, port->xmit_buf);
  1449. if (!tty || !port->xmit_buf) {
  1450. func_exit();
  1451. return;
  1452. }
  1453. bp = port_Board(port);
  1454. spin_lock_irqsave(&port->lock, flags);
  1455. dprintk (SX_DEBUG_TX, "xmit_cnt: %d xmit_buf: %p\n", port->xmit_cnt, port->xmit_buf);
  1456. if ((port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) || (!port->xmit_buf)) {
  1457. spin_unlock_irqrestore(&port->lock, flags);
  1458. dprintk (SX_DEBUG_TX, "Exit size\n");
  1459. func_exit();
  1460. return;
  1461. }
  1462. dprintk (SX_DEBUG_TX, "Handle xmit: %p %p\n", port, port->xmit_buf);
  1463. port->xmit_buf[port->xmit_head++] = ch;
  1464. port->xmit_head &= SERIAL_XMIT_SIZE - 1;
  1465. port->xmit_cnt++;
  1466. spin_unlock_irqrestore(&port->lock, flags);
  1467. func_exit();
  1468. }
  1469. static void sx_flush_chars(struct tty_struct * tty)
  1470. {
  1471. struct specialix_port *port = (struct specialix_port *)tty->driver_data;
  1472. unsigned long flags;
  1473. struct specialix_board * bp = port_Board(port);
  1474. func_enter();
  1475. if (sx_paranoia_check(port, tty->name, "sx_flush_chars")) {
  1476. func_exit();
  1477. return;
  1478. }
  1479. if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
  1480. !port->xmit_buf) {
  1481. func_exit();
  1482. return;
  1483. }
  1484. spin_lock_irqsave(&bp->lock, flags);
  1485. port->IER |= IER_TXRDY;
  1486. sx_out(port_Board(port), CD186x_CAR, port_No(port));
  1487. sx_out(port_Board(port), CD186x_IER, port->IER);
  1488. spin_unlock_irqrestore(&bp->lock, flags);
  1489. func_exit();
  1490. }
  1491. static int sx_write_room(struct tty_struct * tty)
  1492. {
  1493. struct specialix_port *port = (struct specialix_port *)tty->driver_data;
  1494. int ret;
  1495. func_enter();
  1496. if (sx_paranoia_check(port, tty->name, "sx_write_room")) {
  1497. func_exit();
  1498. return 0;
  1499. }
  1500. ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
  1501. if (ret < 0)
  1502. ret = 0;
  1503. func_exit();
  1504. return ret;
  1505. }
  1506. static int sx_chars_in_buffer(struct tty_struct *tty)
  1507. {
  1508. struct specialix_port *port = (struct specialix_port *)tty->driver_data;
  1509. func_enter();
  1510. if (sx_paranoia_check(port, tty->name, "sx_chars_in_buffer")) {
  1511. func_exit();
  1512. return 0;
  1513. }
  1514. func_exit();
  1515. return port->xmit_cnt;
  1516. }
  1517. static void sx_flush_buffer(struct tty_struct *tty)
  1518. {
  1519. struct specialix_port *port = (struct specialix_port *)tty->driver_data;
  1520. unsigned long flags;
  1521. struct specialix_board * bp;
  1522. func_enter();
  1523. if (sx_paranoia_check(port, tty->name, "sx_flush_buffer")) {
  1524. func_exit();
  1525. return;
  1526. }
  1527. bp = port_Board(port);
  1528. spin_lock_irqsave(&port->lock, flags);
  1529. port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
  1530. spin_unlock_irqrestore(&port->lock, flags);
  1531. tty_wakeup(tty);
  1532. func_exit();
  1533. }
  1534. static int sx_tiocmget(struct tty_struct *tty, struct file *file)
  1535. {
  1536. struct specialix_port *port = (struct specialix_port *)tty->driver_data;
  1537. struct specialix_board * bp;
  1538. unsigned char status;
  1539. unsigned int result;
  1540. unsigned long flags;
  1541. func_enter();
  1542. if (sx_paranoia_check(port, tty->name, __FUNCTION__)) {
  1543. func_exit();
  1544. return -ENODEV;
  1545. }
  1546. bp = port_Board(port);
  1547. spin_lock_irqsave (&bp->lock, flags);
  1548. sx_out(bp, CD186x_CAR, port_No(port));
  1549. status = sx_in(bp, CD186x_MSVR);
  1550. spin_unlock_irqrestore(&bp->lock, flags);
  1551. dprintk (SX_DEBUG_INIT, "Got msvr[%d] = %02x, car = %d.\n",
  1552. port_No(port), status, sx_in (bp, CD186x_CAR));
  1553. dprintk (SX_DEBUG_INIT, "sx_port = %p, port = %p\n", sx_port, port);
  1554. if (SX_CRTSCTS(port->tty)) {
  1555. result = /* (status & MSVR_RTS) ? */ TIOCM_DTR /* : 0) */
  1556. | ((status & MSVR_DTR) ? TIOCM_RTS : 0)
  1557. | ((status & MSVR_CD) ? TIOCM_CAR : 0)
  1558. |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */
  1559. | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
  1560. } else {
  1561. result = /* (status & MSVR_RTS) ? */ TIOCM_RTS /* : 0) */
  1562. | ((status & MSVR_DTR) ? TIOCM_DTR : 0)
  1563. | ((status & MSVR_CD) ? TIOCM_CAR : 0)
  1564. |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */
  1565. | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
  1566. }
  1567. func_exit();
  1568. return result;
  1569. }
  1570. static int sx_tiocmset(struct tty_struct *tty, struct file *file,
  1571. unsigned int set, unsigned int clear)
  1572. {
  1573. struct specialix_port *port = (struct specialix_port *)tty->driver_data;
  1574. unsigned long flags;
  1575. struct specialix_board *bp;
  1576. func_enter();
  1577. if (sx_paranoia_check(port, tty->name, __FUNCTION__)) {
  1578. func_exit();
  1579. return -ENODEV;
  1580. }
  1581. bp = port_Board(port);
  1582. spin_lock_irqsave(&port->lock, flags);
  1583. /* if (set & TIOCM_RTS)
  1584. port->MSVR |= MSVR_RTS; */
  1585. /* if (set & TIOCM_DTR)
  1586. port->MSVR |= MSVR_DTR; */
  1587. if (SX_CRTSCTS(port->tty)) {
  1588. if (set & TIOCM_RTS)
  1589. port->MSVR |= MSVR_DTR;
  1590. } else {
  1591. if (set & TIOCM_DTR)
  1592. port->MSVR |= MSVR_DTR;
  1593. }
  1594. /* if (clear & TIOCM_RTS)
  1595. port->MSVR &= ~MSVR_RTS; */
  1596. /* if (clear & TIOCM_DTR)
  1597. port->MSVR &= ~MSVR_DTR; */
  1598. if (SX_CRTSCTS(port->tty)) {
  1599. if (clear & TIOCM_RTS)
  1600. port->MSVR &= ~MSVR_DTR;
  1601. } else {
  1602. if (clear & TIOCM_DTR)
  1603. port->MSVR &= ~MSVR_DTR;
  1604. }
  1605. spin_lock_irqsave(&bp->lock, flags);
  1606. sx_out(bp, CD186x_CAR, port_No(port));
  1607. sx_out(bp, CD186x_MSVR, port->MSVR);
  1608. spin_unlock_irqrestore(&bp->lock, flags);
  1609. spin_unlock_irqrestore(&port->lock, flags);
  1610. func_exit();
  1611. return 0;
  1612. }
  1613. static inline void sx_send_break(struct specialix_port * port, unsigned long length)
  1614. {
  1615. struct specialix_board *bp = port_Board(port);
  1616. unsigned long flags;
  1617. func_enter();
  1618. spin_lock_irqsave (&port->lock, flags);
  1619. port->break_length = SPECIALIX_TPS / HZ * length;
  1620. port->COR2 |= COR2_ETC;
  1621. port->IER |= IER_TXRDY;
  1622. spin_lock_irqsave(&bp->lock, flags);
  1623. sx_out(bp, CD186x_CAR, port_No(port));
  1624. sx_out(bp, CD186x_COR2, port->COR2);
  1625. sx_out(bp, CD186x_IER, port->IER);
  1626. spin_unlock_irqrestore(&bp->lock, flags);
  1627. spin_unlock_irqrestore (&port->lock, flags);
  1628. sx_wait_CCR(bp);
  1629. spin_lock_irqsave(&bp->lock, flags);
  1630. sx_out(bp, CD186x_CCR, CCR_CORCHG2);
  1631. spin_unlock_irqrestore(&bp->lock, flags);
  1632. sx_wait_CCR(bp);
  1633. func_exit();
  1634. }
  1635. static inline int sx_set_serial_info(struct specialix_port * port,
  1636. struct serial_struct __user * newinfo)
  1637. {
  1638. struct serial_struct tmp;
  1639. struct specialix_board *bp = port_Board(port);
  1640. int change_speed;
  1641. func_enter();
  1642. /*
  1643. if (!access_ok(VERIFY_READ, (void *) newinfo, sizeof(tmp))) {
  1644. func_exit();
  1645. return -EFAULT;
  1646. }
  1647. */
  1648. if (copy_from_user(&tmp, newinfo, sizeof(tmp))) {
  1649. func_enter();
  1650. return -EFAULT;
  1651. }
  1652. #if 0
  1653. if ((tmp.irq != bp->irq) ||
  1654. (tmp.port != bp->base) ||
  1655. (tmp.type != PORT_CIRRUS) ||
  1656. (tmp.baud_base != (SX_OSCFREQ + CD186x_TPC/2) / CD186x_TPC) ||
  1657. (tmp.custom_divisor != 0) ||
  1658. (tmp.xmit_fifo_size != CD186x_NFIFO) ||
  1659. (tmp.flags & ~SPECIALIX_LEGAL_FLAGS)) {
  1660. func_exit();
  1661. return -EINVAL;
  1662. }
  1663. #endif
  1664. change_speed = ((port->flags & ASYNC_SPD_MASK) !=
  1665. (tmp.flags & ASYNC_SPD_MASK));
  1666. change_speed |= (tmp.custom_divisor != port->custom_divisor);
  1667. if (!capable(CAP_SYS_ADMIN)) {
  1668. if ((tmp.close_delay != port->close_delay) ||
  1669. (tmp.closing_wait != port->closing_wait) ||
  1670. ((tmp.flags & ~ASYNC_USR_MASK) !=
  1671. (port->flags & ~ASYNC_USR_MASK))) {
  1672. func_exit();
  1673. return -EPERM;
  1674. }
  1675. port->flags = ((port->flags & ~ASYNC_USR_MASK) |
  1676. (tmp.flags & ASYNC_USR_MASK));
  1677. port->custom_divisor = tmp.custom_divisor;
  1678. } else {
  1679. port->flags = ((port->flags & ~ASYNC_FLAGS) |
  1680. (tmp.flags & ASYNC_FLAGS));
  1681. port->close_delay = tmp.close_delay;
  1682. port->closing_wait = tmp.closing_wait;
  1683. port->custom_divisor = tmp.custom_divisor;
  1684. }
  1685. if (change_speed) {
  1686. sx_change_speed(bp, port);
  1687. }
  1688. func_exit();
  1689. return 0;
  1690. }
  1691. static inline int sx_get_serial_info(struct specialix_port * port,
  1692. struct serial_struct __user *retinfo)
  1693. {
  1694. struct serial_struct tmp;
  1695. struct specialix_board *bp = port_Board(port);
  1696. func_enter();
  1697. /*
  1698. if (!access_ok(VERIFY_WRITE, (void *) retinfo, sizeof(tmp)))
  1699. return -EFAULT;
  1700. */
  1701. memset(&tmp, 0, sizeof(tmp));
  1702. tmp.type = PORT_CIRRUS;
  1703. tmp.line = port - sx_port;
  1704. tmp.port = bp->base;
  1705. tmp.irq = bp->irq;
  1706. tmp.flags = port->flags;
  1707. tmp.baud_base = (SX_OSCFREQ + CD186x_TPC/2) / CD186x_TPC;
  1708. tmp.close_delay = port->close_delay * HZ/100;
  1709. tmp.closing_wait = port->closing_wait * HZ/100;
  1710. tmp.custom_divisor = port->custom_divisor;
  1711. tmp.xmit_fifo_size = CD186x_NFIFO;
  1712. if (copy_to_user(retinfo, &tmp, sizeof(tmp))) {
  1713. func_exit();
  1714. return -EFAULT;
  1715. }
  1716. func_exit();
  1717. return 0;
  1718. }
  1719. static int sx_ioctl(struct tty_struct * tty, struct file * filp,
  1720. unsigned int cmd, unsigned long arg)
  1721. {
  1722. struct specialix_port *port = (struct specialix_port *)tty->driver_data;
  1723. int retval;
  1724. void __user *argp = (void __user *)arg;
  1725. func_enter();
  1726. if (sx_paranoia_check(port, tty->name, "sx_ioctl")) {
  1727. func_exit();
  1728. return -ENODEV;
  1729. }
  1730. switch (cmd) {
  1731. case TCSBRK: /* SVID version: non-zero arg --> no break */
  1732. retval = tty_check_change(tty);
  1733. if (retval) {
  1734. func_exit();
  1735. return retval;
  1736. }
  1737. tty_wait_until_sent(tty, 0);
  1738. if (!arg)
  1739. sx_send_break(port, HZ/4); /* 1/4 second */
  1740. return 0;
  1741. case TCSBRKP: /* support for POSIX tcsendbreak() */
  1742. retval = tty_check_change(tty);
  1743. if (retval) {
  1744. func_exit();
  1745. return retval;
  1746. }
  1747. tty_wait_until_sent(tty, 0);
  1748. sx_send_break(port, arg ? arg*(HZ/10) : HZ/4);
  1749. func_exit();
  1750. return 0;
  1751. case TIOCGSOFTCAR:
  1752. if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)argp)) {
  1753. func_exit();
  1754. return -EFAULT;
  1755. }
  1756. func_exit();
  1757. return 0;
  1758. case TIOCSSOFTCAR:
  1759. if (get_user(arg, (unsigned long __user *) argp)) {
  1760. func_exit();
  1761. return -EFAULT;
  1762. }
  1763. tty->termios->c_cflag =
  1764. ((tty->termios->c_cflag & ~CLOCAL) |
  1765. (arg ? CLOCAL : 0));
  1766. func_exit();
  1767. return 0;
  1768. case TIOCGSERIAL:
  1769. func_exit();
  1770. return sx_get_serial_info(port, argp);
  1771. case TIOCSSERIAL:
  1772. func_exit();
  1773. return sx_set_serial_info(port, argp);
  1774. default:
  1775. func_exit();
  1776. return -ENOIOCTLCMD;
  1777. }
  1778. func_exit();
  1779. return 0;
  1780. }
  1781. static void sx_throttle(struct tty_struct * tty)
  1782. {
  1783. struct specialix_port *port = (struct specialix_port *)tty->driver_data;
  1784. struct specialix_board *bp;
  1785. unsigned long flags;
  1786. func_enter();
  1787. if (sx_paranoia_check(port, tty->name, "sx_throttle")) {
  1788. func_exit();
  1789. return;
  1790. }
  1791. bp = port_Board(port);
  1792. /* Use DTR instead of RTS ! */
  1793. if (SX_CRTSCTS (tty))
  1794. port->MSVR &= ~MSVR_DTR;
  1795. else {
  1796. /* Auch!!! I think the system shouldn't call this then. */
  1797. /* Or maybe we're supposed (allowed?) to do our side of hw
  1798. handshake anyway, even when hardware handshake is off.
  1799. When you see this in your logs, please report.... */
  1800. printk (KERN_ERR "sx%d: Need to throttle, but can't (hardware hs is off)\n",
  1801. port_No (port));
  1802. }
  1803. spin_lock_irqsave(&bp->lock, flags);
  1804. sx_out(bp, CD186x_CAR, port_No(port));
  1805. spin_unlock_irqrestore(&bp->lock, flags);
  1806. if (I_IXOFF(tty)) {
  1807. spin_unlock_irqrestore(&bp->lock, flags);
  1808. sx_wait_CCR(bp);
  1809. spin_lock_irqsave(&bp->lock, flags);
  1810. sx_out(bp, CD186x_CCR, CCR_SSCH2);
  1811. spin_unlock_irqrestore(&bp->lock, flags);
  1812. sx_wait_CCR(bp);
  1813. }
  1814. spin_lock_irqsave(&bp->lock, flags);
  1815. sx_out(bp, CD186x_MSVR, port->MSVR);
  1816. spin_unlock_irqrestore(&bp->lock, flags);
  1817. func_exit();
  1818. }
  1819. static void sx_unthrottle(struct tty_struct * tty)
  1820. {
  1821. struct specialix_port *port = (struct specialix_port *)tty->driver_data;
  1822. struct specialix_board *bp;
  1823. unsigned long flags;
  1824. func_enter();
  1825. if (sx_paranoia_check(port, tty->name, "sx_unthrottle")) {
  1826. func_exit();
  1827. return;
  1828. }
  1829. bp = port_Board(port);
  1830. spin_lock_irqsave(&port->lock, flags);
  1831. /* XXXX Use DTR INSTEAD???? */
  1832. if (SX_CRTSCTS(tty)) {
  1833. port->MSVR |= MSVR_DTR;
  1834. } /* Else clause: see remark in "sx_throttle"... */
  1835. spin_lock_irqsave(&bp->lock, flags);
  1836. sx_out(bp, CD186x_CAR, port_No(port));
  1837. spin_unlock_irqrestore(&bp->lock, flags);
  1838. if (I_IXOFF(tty)) {
  1839. spin_unlock_irqrestore(&port->lock, flags);
  1840. sx_wait_CCR(bp);
  1841. spin_lock_irqsave(&bp->lock, flags);
  1842. sx_out(bp, CD186x_CCR, CCR_SSCH1);
  1843. spin_unlock_irqrestore(&bp->lock, flags);
  1844. sx_wait_CCR(bp);
  1845. spin_lock_irqsave(&port->lock, flags);
  1846. }
  1847. spin_lock_irqsave(&bp->lock, flags);
  1848. sx_out(bp, CD186x_MSVR, port->MSVR);
  1849. spin_unlock_irqrestore(&bp->lock, flags);
  1850. spin_unlock_irqrestore(&port->lock, flags);
  1851. func_exit();
  1852. }
  1853. static void sx_stop(struct tty_struct * tty)
  1854. {
  1855. struct specialix_port *port = (struct specialix_port *)tty->driver_data;
  1856. struct specialix_board *bp;
  1857. unsigned long flags;
  1858. func_enter();
  1859. if (sx_paranoia_check(port, tty->name, "sx_stop")) {
  1860. func_exit();
  1861. return;
  1862. }
  1863. bp = port_Board(port);
  1864. spin_lock_irqsave(&port->lock, flags);
  1865. port->IER &= ~IER_TXRDY;
  1866. spin_lock_irqsave(&bp->lock, flags);
  1867. sx_out(bp, CD186x_CAR, port_No(port));
  1868. sx_out(bp, CD186x_IER, port->IER);
  1869. spin_unlock_irqrestore(&bp->lock, flags);
  1870. spin_unlock_irqrestore(&port->lock, flags);
  1871. func_exit();
  1872. }
  1873. static void sx_start(struct tty_struct * tty)
  1874. {
  1875. struct specialix_port *port = (struct specialix_port *)tty->driver_data;
  1876. struct specialix_board *bp;
  1877. unsigned long flags;
  1878. func_enter();
  1879. if (sx_paranoia_check(port, tty->name, "sx_start")) {
  1880. func_exit();
  1881. return;
  1882. }
  1883. bp = port_Board(port);
  1884. spin_lock_irqsave(&port->lock, flags);
  1885. if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) {
  1886. port->IER |= IER_TXRDY;
  1887. spin_lock_irqsave(&bp->lock, flags);
  1888. sx_out(bp, CD186x_CAR, port_No(port));
  1889. sx_out(bp, CD186x_IER, port->IER);
  1890. spin_unlock_irqrestore(&bp->lock, flags);
  1891. }
  1892. spin_unlock_irqrestore(&port->lock, flags);
  1893. func_exit();
  1894. }
  1895. /*
  1896. * This routine is called from the work-queue when the interrupt
  1897. * routine has signalled that a hangup has occurred. The path of
  1898. * hangup processing is:
  1899. *
  1900. * serial interrupt routine -> (workqueue) ->
  1901. * do_sx_hangup() -> tty->hangup() -> sx_hangup()
  1902. *
  1903. */
  1904. static void do_sx_hangup(void *private_)
  1905. {
  1906. struct specialix_port *port = (struct specialix_port *) private_;
  1907. struct tty_struct *tty;
  1908. func_enter();
  1909. tty = port->tty;
  1910. if (tty)
  1911. tty_hangup(tty); /* FIXME: module removal race here */
  1912. func_exit();
  1913. }
  1914. static void sx_hangup(struct tty_struct * tty)
  1915. {
  1916. struct specialix_port *port = (struct specialix_port *)tty->driver_data;
  1917. struct specialix_board *bp;
  1918. unsigned long flags;
  1919. func_enter();
  1920. if (sx_paranoia_check(port, tty->name, "sx_hangup")) {
  1921. func_exit();
  1922. return;
  1923. }
  1924. bp = port_Board(port);
  1925. sx_shutdown_port(bp, port);
  1926. spin_lock_irqsave(&port->lock, flags);
  1927. port->event = 0;
  1928. bp->count -= port->count;
  1929. if (bp->count < 0) {
  1930. printk(KERN_ERR "sx%d: sx_hangup: bad board count: %d port: %d\n",
  1931. board_No(bp), bp->count, tty->index);
  1932. bp->count = 0;
  1933. }
  1934. port->count = 0;
  1935. port->flags &= ~ASYNC_NORMAL_ACTIVE;
  1936. port->tty = NULL;
  1937. spin_unlock_irqrestore(&port->lock, flags);
  1938. wake_up_interruptible(&port->open_wait);
  1939. func_exit();
  1940. }
  1941. static void sx_set_termios(struct tty_struct * tty, struct termios * old_termios)
  1942. {
  1943. struct specialix_port *port = (struct specialix_port *)tty->driver_data;
  1944. unsigned long flags;
  1945. struct specialix_board * bp;
  1946. if (sx_paranoia_check(port, tty->name, "sx_set_termios"))
  1947. return;
  1948. if (tty->termios->c_cflag == old_termios->c_cflag &&
  1949. tty->termios->c_iflag == old_termios->c_iflag)
  1950. return;
  1951. bp = port_Board(port);
  1952. spin_lock_irqsave(&port->lock, flags);
  1953. sx_change_speed(port_Board(port), port);
  1954. spin_unlock_irqrestore(&port->lock, flags);
  1955. if ((old_termios->c_cflag & CRTSCTS) &&
  1956. !(tty->termios->c_cflag & CRTSCTS)) {
  1957. tty->hw_stopped = 0;
  1958. sx_start(tty);
  1959. }
  1960. }
  1961. static void do_softint(void *private_)
  1962. {
  1963. struct specialix_port *port = (struct specialix_port *) private_;
  1964. struct tty_struct *tty;
  1965. func_enter();
  1966. if(!(tty = port->tty)) {
  1967. func_exit();
  1968. return;
  1969. }
  1970. if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) {
  1971. tty_wakeup(tty);
  1972. //wake_up_interruptible(&tty->write_wait);
  1973. }
  1974. func_exit();
  1975. }
  1976. static struct tty_operations sx_ops = {
  1977. .open = sx_open,
  1978. .close = sx_close,
  1979. .write = sx_write,
  1980. .put_char = sx_put_char,
  1981. .flush_chars = sx_flush_chars,
  1982. .write_room = sx_write_room,
  1983. .chars_in_buffer = sx_chars_in_buffer,
  1984. .flush_buffer = sx_flush_buffer,
  1985. .ioctl = sx_ioctl,
  1986. .throttle = sx_throttle,
  1987. .unthrottle = sx_unthrottle,
  1988. .set_termios = sx_set_termios,
  1989. .stop = sx_stop,
  1990. .start = sx_start,
  1991. .hangup = sx_hangup,
  1992. .tiocmget = sx_tiocmget,
  1993. .tiocmset = sx_tiocmset,
  1994. };
  1995. static int sx_init_drivers(void)
  1996. {
  1997. int error;
  1998. int i;
  1999. func_enter();
  2000. specialix_driver = alloc_tty_driver(SX_NBOARD * SX_NPORT);
  2001. if (!specialix_driver) {
  2002. printk(KERN_ERR "sx: Couldn't allocate tty_driver.\n");
  2003. func_exit();
  2004. return 1;
  2005. }
  2006. if (!(tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL))) {
  2007. printk(KERN_ERR "sx: Couldn't get free page.\n");
  2008. put_tty_driver(specialix_driver);
  2009. func_exit();
  2010. return 1;
  2011. }
  2012. specialix_driver->owner = THIS_MODULE;
  2013. specialix_driver->name = "ttyW";
  2014. specialix_driver->major = SPECIALIX_NORMAL_MAJOR;
  2015. specialix_driver->type = TTY_DRIVER_TYPE_SERIAL;
  2016. specialix_driver->subtype = SERIAL_TYPE_NORMAL;
  2017. specialix_driver->init_termios = tty_std_termios;
  2018. specialix_driver->init_termios.c_cflag =
  2019. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  2020. specialix_driver->flags = TTY_DRIVER_REAL_RAW;
  2021. tty_set_operations(specialix_driver, &sx_ops);
  2022. if ((error = tty_register_driver(specialix_driver))) {
  2023. put_tty_driver(specialix_driver);
  2024. free_page((unsigned long)tmp_buf);
  2025. printk(KERN_ERR "sx: Couldn't register specialix IO8+ driver, error = %d\n",
  2026. error);
  2027. func_exit();
  2028. return 1;
  2029. }
  2030. memset(sx_port, 0, sizeof(sx_port));
  2031. for (i = 0; i < SX_NPORT * SX_NBOARD; i++) {
  2032. sx_port[i].magic = SPECIALIX_MAGIC;
  2033. INIT_WORK(&sx_port[i].tqueue, do_softint, &sx_port[i]);
  2034. INIT_WORK(&sx_port[i].tqueue_hangup, do_sx_hangup, &sx_port[i]);
  2035. sx_port[i].close_delay = 50 * HZ/100;
  2036. sx_port[i].closing_wait = 3000 * HZ/100;
  2037. init_waitqueue_head(&sx_port[i].open_wait);
  2038. init_waitqueue_head(&sx_port[i].close_wait);
  2039. spin_lock_init(&sx_port[i].lock);
  2040. }
  2041. func_exit();
  2042. return 0;
  2043. }
  2044. static void sx_release_drivers(void)
  2045. {
  2046. func_enter();
  2047. free_page((unsigned long)tmp_buf);
  2048. tty_unregister_driver(specialix_driver);
  2049. put_tty_driver(specialix_driver);
  2050. func_exit();
  2051. }
  2052. /*
  2053. * This routine must be called by kernel at boot time
  2054. */
  2055. static int __init specialix_init(void)
  2056. {
  2057. int i;
  2058. int found = 0;
  2059. func_enter();
  2060. printk(KERN_INFO "sx: Specialix IO8+ driver v" VERSION ", (c) R.E.Wolff 1997/1998.\n");
  2061. printk(KERN_INFO "sx: derived from work (c) D.Gorodchanin 1994-1996.\n");
  2062. #ifdef CONFIG_SPECIALIX_RTSCTS
  2063. printk (KERN_INFO "sx: DTR/RTS pin is always RTS.\n");
  2064. #else
  2065. printk (KERN_INFO "sx: DTR/RTS pin is RTS when CRTSCTS is on.\n");
  2066. #endif
  2067. for (i = 0; i < SX_NBOARD; i++)
  2068. sx_board[i].lock = SPIN_LOCK_UNLOCKED;
  2069. if (sx_init_drivers()) {
  2070. func_exit();
  2071. return -EIO;
  2072. }
  2073. for (i = 0; i < SX_NBOARD; i++)
  2074. if (sx_board[i].base && !sx_probe(&sx_board[i]))
  2075. found++;
  2076. #ifdef CONFIG_PCI
  2077. {
  2078. struct pci_dev *pdev = NULL;
  2079. i=0;
  2080. while (i < SX_NBOARD) {
  2081. if (sx_board[i].flags & SX_BOARD_PRESENT) {
  2082. i++;
  2083. continue;
  2084. }
  2085. pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX,
  2086. PCI_DEVICE_ID_SPECIALIX_IO8,
  2087. pdev);
  2088. if (!pdev) break;
  2089. if (pci_enable_device(pdev))
  2090. continue;
  2091. sx_board[i].irq = pdev->irq;
  2092. sx_board[i].base = pci_resource_start (pdev, 2);
  2093. sx_board[i].flags |= SX_BOARD_IS_PCI;
  2094. if (!sx_probe(&sx_board[i]))
  2095. found ++;
  2096. }
  2097. }
  2098. #endif
  2099. if (!found) {
  2100. sx_release_drivers();
  2101. printk(KERN_INFO "sx: No specialix IO8+ boards detected.\n");
  2102. func_exit();
  2103. return -EIO;
  2104. }
  2105. func_exit();
  2106. return 0;
  2107. }
  2108. static int iobase[SX_NBOARD] = {0,};
  2109. static int irq [SX_NBOARD] = {0,};
  2110. module_param_array(iobase, int, NULL, 0);
  2111. module_param_array(irq, int, NULL, 0);
  2112. module_param(sx_debug, int, 0);
  2113. module_param(sx_rxfifo, int, 0);
  2114. #ifdef SPECIALIX_TIMER
  2115. module_param(sx_poll, int, 0);
  2116. #endif
  2117. /*
  2118. * You can setup up to 4 boards.
  2119. * by specifying "iobase=0xXXX,0xXXX ..." as insmod parameter.
  2120. * You should specify the IRQs too in that case "irq=....,...".
  2121. *
  2122. * More than 4 boards in one computer is not possible, as the card can
  2123. * only use 4 different interrupts.
  2124. *
  2125. */
  2126. static int __init specialix_init_module(void)
  2127. {
  2128. int i;
  2129. func_enter();
  2130. if (iobase[0] || iobase[1] || iobase[2] || iobase[3]) {
  2131. for(i = 0; i < SX_NBOARD; i++) {
  2132. sx_board[i].base = iobase[i];
  2133. sx_board[i].irq = irq[i];
  2134. sx_board[i].count= 0;
  2135. }
  2136. }
  2137. func_exit();
  2138. return specialix_init();
  2139. }
  2140. static void __exit specialix_exit_module(void)
  2141. {
  2142. int i;
  2143. func_enter();
  2144. sx_release_drivers();
  2145. for (i = 0; i < SX_NBOARD; i++)
  2146. if (sx_board[i].flags & SX_BOARD_PRESENT)
  2147. sx_release_io_range(&sx_board[i]);
  2148. #ifdef SPECIALIX_TIMER
  2149. del_timer (&missed_irq_timer);
  2150. #endif
  2151. func_exit();
  2152. }
  2153. module_init(specialix_init_module);
  2154. module_exit(specialix_exit_module);
  2155. MODULE_LICENSE("GPL");