specialix.c 63 KB

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