stallion.c 123 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811
  1. /*****************************************************************************/
  2. /*
  3. * stallion.c -- stallion multiport serial driver.
  4. *
  5. * Copyright (C) 1996-1999 Stallion Technologies
  6. * Copyright (C) 1994-1996 Greg Ungerer.
  7. *
  8. * This code is loosely based on the Linux serial driver, written by
  9. * Linus Torvalds, Theodore T'so and others.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. /*****************************************************************************/
  26. #include <linux/module.h>
  27. #include <linux/slab.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/tty.h>
  30. #include <linux/tty_flip.h>
  31. #include <linux/serial.h>
  32. #include <linux/cd1400.h>
  33. #include <linux/sc26198.h>
  34. #include <linux/comstats.h>
  35. #include <linux/stallion.h>
  36. #include <linux/ioport.h>
  37. #include <linux/init.h>
  38. #include <linux/smp_lock.h>
  39. #include <linux/device.h>
  40. #include <linux/delay.h>
  41. #include <linux/ctype.h>
  42. #include <asm/io.h>
  43. #include <asm/uaccess.h>
  44. #include <linux/pci.h>
  45. /*****************************************************************************/
  46. /*
  47. * Define different board types. Use the standard Stallion "assigned"
  48. * board numbers. Boards supported in this driver are abbreviated as
  49. * EIO = EasyIO and ECH = EasyConnection 8/32.
  50. */
  51. #define BRD_EASYIO 20
  52. #define BRD_ECH 21
  53. #define BRD_ECHMC 22
  54. #define BRD_ECHPCI 26
  55. #define BRD_ECH64PCI 27
  56. #define BRD_EASYIOPCI 28
  57. struct stlconf {
  58. unsigned int brdtype;
  59. int ioaddr1;
  60. int ioaddr2;
  61. unsigned long memaddr;
  62. int irq;
  63. int irqtype;
  64. };
  65. static unsigned int stl_nrbrds;
  66. /*****************************************************************************/
  67. /*
  68. * Define some important driver characteristics. Device major numbers
  69. * allocated as per Linux Device Registry.
  70. */
  71. #ifndef STL_SIOMEMMAJOR
  72. #define STL_SIOMEMMAJOR 28
  73. #endif
  74. #ifndef STL_SERIALMAJOR
  75. #define STL_SERIALMAJOR 24
  76. #endif
  77. #ifndef STL_CALLOUTMAJOR
  78. #define STL_CALLOUTMAJOR 25
  79. #endif
  80. /*
  81. * Set the TX buffer size. Bigger is better, but we don't want
  82. * to chew too much memory with buffers!
  83. */
  84. #define STL_TXBUFLOW 512
  85. #define STL_TXBUFSIZE 4096
  86. /*****************************************************************************/
  87. /*
  88. * Define our local driver identity first. Set up stuff to deal with
  89. * all the local structures required by a serial tty driver.
  90. */
  91. static char *stl_drvtitle = "Stallion Multiport Serial Driver";
  92. static char *stl_drvname = "stallion";
  93. static char *stl_drvversion = "5.6.0";
  94. static struct tty_driver *stl_serial;
  95. /*
  96. * Define a local default termios struct. All ports will be created
  97. * with this termios initially. Basically all it defines is a raw port
  98. * at 9600, 8 data bits, 1 stop bit.
  99. */
  100. static struct ktermios stl_deftermios = {
  101. .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
  102. .c_cc = INIT_C_CC,
  103. .c_ispeed = 9600,
  104. .c_ospeed = 9600,
  105. };
  106. /*
  107. * Define global place to put buffer overflow characters.
  108. */
  109. static char stl_unwanted[SC26198_RXFIFOSIZE];
  110. /*****************************************************************************/
  111. static DEFINE_MUTEX(stl_brdslock);
  112. static struct stlbrd *stl_brds[STL_MAXBRDS];
  113. /*
  114. * Per board state flags. Used with the state field of the board struct.
  115. * Not really much here!
  116. */
  117. #define BRD_FOUND 0x1
  118. #define STL_PROBED 0x2
  119. /*
  120. * Define the port structure istate flags. These set of flags are
  121. * modified at interrupt time - so setting and reseting them needs
  122. * to be atomic. Use the bit clear/setting routines for this.
  123. */
  124. #define ASYI_TXBUSY 1
  125. #define ASYI_TXLOW 2
  126. #define ASYI_TXFLOWED 3
  127. /*
  128. * Define an array of board names as printable strings. Handy for
  129. * referencing boards when printing trace and stuff.
  130. */
  131. static char *stl_brdnames[] = {
  132. NULL,
  133. NULL,
  134. NULL,
  135. NULL,
  136. NULL,
  137. NULL,
  138. NULL,
  139. NULL,
  140. NULL,
  141. NULL,
  142. NULL,
  143. NULL,
  144. NULL,
  145. NULL,
  146. NULL,
  147. NULL,
  148. NULL,
  149. NULL,
  150. NULL,
  151. NULL,
  152. "EasyIO",
  153. "EC8/32-AT",
  154. "EC8/32-MC",
  155. NULL,
  156. NULL,
  157. NULL,
  158. "EC8/32-PCI",
  159. "EC8/64-PCI",
  160. "EasyIO-PCI",
  161. };
  162. /*****************************************************************************/
  163. /*
  164. * Define some string labels for arguments passed from the module
  165. * load line. These allow for easy board definitions, and easy
  166. * modification of the io, memory and irq resoucres.
  167. */
  168. static unsigned int stl_nargs;
  169. static char *board0[4];
  170. static char *board1[4];
  171. static char *board2[4];
  172. static char *board3[4];
  173. static char **stl_brdsp[] = {
  174. (char **) &board0,
  175. (char **) &board1,
  176. (char **) &board2,
  177. (char **) &board3
  178. };
  179. /*
  180. * Define a set of common board names, and types. This is used to
  181. * parse any module arguments.
  182. */
  183. static struct {
  184. char *name;
  185. int type;
  186. } stl_brdstr[] = {
  187. { "easyio", BRD_EASYIO },
  188. { "eio", BRD_EASYIO },
  189. { "20", BRD_EASYIO },
  190. { "ec8/32", BRD_ECH },
  191. { "ec8/32-at", BRD_ECH },
  192. { "ec8/32-isa", BRD_ECH },
  193. { "ech", BRD_ECH },
  194. { "echat", BRD_ECH },
  195. { "21", BRD_ECH },
  196. { "ec8/32-mc", BRD_ECHMC },
  197. { "ec8/32-mca", BRD_ECHMC },
  198. { "echmc", BRD_ECHMC },
  199. { "echmca", BRD_ECHMC },
  200. { "22", BRD_ECHMC },
  201. { "ec8/32-pc", BRD_ECHPCI },
  202. { "ec8/32-pci", BRD_ECHPCI },
  203. { "26", BRD_ECHPCI },
  204. { "ec8/64-pc", BRD_ECH64PCI },
  205. { "ec8/64-pci", BRD_ECH64PCI },
  206. { "ech-pci", BRD_ECH64PCI },
  207. { "echpci", BRD_ECH64PCI },
  208. { "echpc", BRD_ECH64PCI },
  209. { "27", BRD_ECH64PCI },
  210. { "easyio-pc", BRD_EASYIOPCI },
  211. { "easyio-pci", BRD_EASYIOPCI },
  212. { "eio-pci", BRD_EASYIOPCI },
  213. { "eiopci", BRD_EASYIOPCI },
  214. { "28", BRD_EASYIOPCI },
  215. };
  216. /*
  217. * Define the module agruments.
  218. */
  219. module_param_array(board0, charp, &stl_nargs, 0);
  220. MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
  221. module_param_array(board1, charp, &stl_nargs, 0);
  222. MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
  223. module_param_array(board2, charp, &stl_nargs, 0);
  224. MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
  225. module_param_array(board3, charp, &stl_nargs, 0);
  226. MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
  227. /*****************************************************************************/
  228. /*
  229. * Hardware ID bits for the EasyIO and ECH boards. These defines apply
  230. * to the directly accessible io ports of these boards (not the uarts -
  231. * they are in cd1400.h and sc26198.h).
  232. */
  233. #define EIO_8PORTRS 0x04
  234. #define EIO_4PORTRS 0x05
  235. #define EIO_8PORTDI 0x00
  236. #define EIO_8PORTM 0x06
  237. #define EIO_MK3 0x03
  238. #define EIO_IDBITMASK 0x07
  239. #define EIO_BRDMASK 0xf0
  240. #define ID_BRD4 0x10
  241. #define ID_BRD8 0x20
  242. #define ID_BRD16 0x30
  243. #define EIO_INTRPEND 0x08
  244. #define EIO_INTEDGE 0x00
  245. #define EIO_INTLEVEL 0x08
  246. #define EIO_0WS 0x10
  247. #define ECH_ID 0xa0
  248. #define ECH_IDBITMASK 0xe0
  249. #define ECH_BRDENABLE 0x08
  250. #define ECH_BRDDISABLE 0x00
  251. #define ECH_INTENABLE 0x01
  252. #define ECH_INTDISABLE 0x00
  253. #define ECH_INTLEVEL 0x02
  254. #define ECH_INTEDGE 0x00
  255. #define ECH_INTRPEND 0x01
  256. #define ECH_BRDRESET 0x01
  257. #define ECHMC_INTENABLE 0x01
  258. #define ECHMC_BRDRESET 0x02
  259. #define ECH_PNLSTATUS 2
  260. #define ECH_PNL16PORT 0x20
  261. #define ECH_PNLIDMASK 0x07
  262. #define ECH_PNLXPID 0x40
  263. #define ECH_PNLINTRPEND 0x80
  264. #define ECH_ADDR2MASK 0x1e0
  265. /*
  266. * Define the vector mapping bits for the programmable interrupt board
  267. * hardware. These bits encode the interrupt for the board to use - it
  268. * is software selectable (except the EIO-8M).
  269. */
  270. static unsigned char stl_vecmap[] = {
  271. 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
  272. 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
  273. };
  274. /*
  275. * Lock ordering is that you may not take stallion_lock holding
  276. * brd_lock.
  277. */
  278. static spinlock_t brd_lock; /* Guard the board mapping */
  279. static spinlock_t stallion_lock; /* Guard the tty driver */
  280. /*
  281. * Set up enable and disable macros for the ECH boards. They require
  282. * the secondary io address space to be activated and deactivated.
  283. * This way all ECH boards can share their secondary io region.
  284. * If this is an ECH-PCI board then also need to set the page pointer
  285. * to point to the correct page.
  286. */
  287. #define BRDENABLE(brdnr,pagenr) \
  288. if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
  289. outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
  290. stl_brds[(brdnr)]->ioctrl); \
  291. else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
  292. outb((pagenr), stl_brds[(brdnr)]->ioctrl);
  293. #define BRDDISABLE(brdnr) \
  294. if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
  295. outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
  296. stl_brds[(brdnr)]->ioctrl);
  297. #define STL_CD1400MAXBAUD 230400
  298. #define STL_SC26198MAXBAUD 460800
  299. #define STL_BAUDBASE 115200
  300. #define STL_CLOSEDELAY (5 * HZ / 10)
  301. /*****************************************************************************/
  302. /*
  303. * Define the Stallion PCI vendor and device IDs.
  304. */
  305. #ifndef PCI_VENDOR_ID_STALLION
  306. #define PCI_VENDOR_ID_STALLION 0x124d
  307. #endif
  308. #ifndef PCI_DEVICE_ID_ECHPCI832
  309. #define PCI_DEVICE_ID_ECHPCI832 0x0000
  310. #endif
  311. #ifndef PCI_DEVICE_ID_ECHPCI864
  312. #define PCI_DEVICE_ID_ECHPCI864 0x0002
  313. #endif
  314. #ifndef PCI_DEVICE_ID_EIOPCI
  315. #define PCI_DEVICE_ID_EIOPCI 0x0003
  316. #endif
  317. /*
  318. * Define structure to hold all Stallion PCI boards.
  319. */
  320. static struct pci_device_id stl_pcibrds[] = {
  321. { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864),
  322. .driver_data = BRD_ECH64PCI },
  323. { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI),
  324. .driver_data = BRD_EASYIOPCI },
  325. { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832),
  326. .driver_data = BRD_ECHPCI },
  327. { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410),
  328. .driver_data = BRD_ECHPCI },
  329. { }
  330. };
  331. MODULE_DEVICE_TABLE(pci, stl_pcibrds);
  332. /*****************************************************************************/
  333. /*
  334. * Define macros to extract a brd/port number from a minor number.
  335. */
  336. #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
  337. #define MINOR2PORT(min) ((min) & 0x3f)
  338. /*
  339. * Define a baud rate table that converts termios baud rate selector
  340. * into the actual baud rate value. All baud rate calculations are
  341. * based on the actual baud rate required.
  342. */
  343. static unsigned int stl_baudrates[] = {
  344. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
  345. 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
  346. };
  347. /*****************************************************************************/
  348. /*
  349. * Declare all those functions in this driver!
  350. */
  351. static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
  352. static int stl_brdinit(struct stlbrd *brdp);
  353. static int stl_getportstats(struct stlport *portp, comstats_t __user *cp);
  354. static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp);
  355. static int stl_waitcarrier(struct stlport *portp, struct file *filp);
  356. /*
  357. * CD1400 uart specific handling functions.
  358. */
  359. static void stl_cd1400setreg(struct stlport *portp, int regnr, int value);
  360. static int stl_cd1400getreg(struct stlport *portp, int regnr);
  361. static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value);
  362. static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
  363. static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
  364. static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp);
  365. static int stl_cd1400getsignals(struct stlport *portp);
  366. static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts);
  367. static void stl_cd1400ccrwait(struct stlport *portp);
  368. static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx);
  369. static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx);
  370. static void stl_cd1400disableintrs(struct stlport *portp);
  371. static void stl_cd1400sendbreak(struct stlport *portp, int len);
  372. static void stl_cd1400flowctrl(struct stlport *portp, int state);
  373. static void stl_cd1400sendflow(struct stlport *portp, int state);
  374. static void stl_cd1400flush(struct stlport *portp);
  375. static int stl_cd1400datastate(struct stlport *portp);
  376. static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase);
  377. static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase);
  378. static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr);
  379. static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr);
  380. static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr);
  381. static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr);
  382. /*
  383. * SC26198 uart specific handling functions.
  384. */
  385. static void stl_sc26198setreg(struct stlport *portp, int regnr, int value);
  386. static int stl_sc26198getreg(struct stlport *portp, int regnr);
  387. static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value);
  388. static int stl_sc26198getglobreg(struct stlport *portp, int regnr);
  389. static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
  390. static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
  391. static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp);
  392. static int stl_sc26198getsignals(struct stlport *portp);
  393. static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts);
  394. static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx);
  395. static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx);
  396. static void stl_sc26198disableintrs(struct stlport *portp);
  397. static void stl_sc26198sendbreak(struct stlport *portp, int len);
  398. static void stl_sc26198flowctrl(struct stlport *portp, int state);
  399. static void stl_sc26198sendflow(struct stlport *portp, int state);
  400. static void stl_sc26198flush(struct stlport *portp);
  401. static int stl_sc26198datastate(struct stlport *portp);
  402. static void stl_sc26198wait(struct stlport *portp);
  403. static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty);
  404. static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase);
  405. static void stl_sc26198txisr(struct stlport *port);
  406. static void stl_sc26198rxisr(struct stlport *port, unsigned int iack);
  407. static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch);
  408. static void stl_sc26198rxbadchars(struct stlport *portp);
  409. static void stl_sc26198otherisr(struct stlport *port, unsigned int iack);
  410. /*****************************************************************************/
  411. /*
  412. * Generic UART support structure.
  413. */
  414. typedef struct uart {
  415. int (*panelinit)(struct stlbrd *brdp, struct stlpanel *panelp);
  416. void (*portinit)(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
  417. void (*setport)(struct stlport *portp, struct ktermios *tiosp);
  418. int (*getsignals)(struct stlport *portp);
  419. void (*setsignals)(struct stlport *portp, int dtr, int rts);
  420. void (*enablerxtx)(struct stlport *portp, int rx, int tx);
  421. void (*startrxtx)(struct stlport *portp, int rx, int tx);
  422. void (*disableintrs)(struct stlport *portp);
  423. void (*sendbreak)(struct stlport *portp, int len);
  424. void (*flowctrl)(struct stlport *portp, int state);
  425. void (*sendflow)(struct stlport *portp, int state);
  426. void (*flush)(struct stlport *portp);
  427. int (*datastate)(struct stlport *portp);
  428. void (*intr)(struct stlpanel *panelp, unsigned int iobase);
  429. } uart_t;
  430. /*
  431. * Define some macros to make calling these functions nice and clean.
  432. */
  433. #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
  434. #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
  435. #define stl_setport (* ((uart_t *) portp->uartp)->setport)
  436. #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
  437. #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
  438. #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
  439. #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
  440. #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
  441. #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
  442. #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
  443. #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
  444. #define stl_flush (* ((uart_t *) portp->uartp)->flush)
  445. #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
  446. /*****************************************************************************/
  447. /*
  448. * CD1400 UART specific data initialization.
  449. */
  450. static uart_t stl_cd1400uart = {
  451. stl_cd1400panelinit,
  452. stl_cd1400portinit,
  453. stl_cd1400setport,
  454. stl_cd1400getsignals,
  455. stl_cd1400setsignals,
  456. stl_cd1400enablerxtx,
  457. stl_cd1400startrxtx,
  458. stl_cd1400disableintrs,
  459. stl_cd1400sendbreak,
  460. stl_cd1400flowctrl,
  461. stl_cd1400sendflow,
  462. stl_cd1400flush,
  463. stl_cd1400datastate,
  464. stl_cd1400eiointr
  465. };
  466. /*
  467. * Define the offsets within the register bank of a cd1400 based panel.
  468. * These io address offsets are common to the EasyIO board as well.
  469. */
  470. #define EREG_ADDR 0
  471. #define EREG_DATA 4
  472. #define EREG_RXACK 5
  473. #define EREG_TXACK 6
  474. #define EREG_MDACK 7
  475. #define EREG_BANKSIZE 8
  476. #define CD1400_CLK 25000000
  477. #define CD1400_CLK8M 20000000
  478. /*
  479. * Define the cd1400 baud rate clocks. These are used when calculating
  480. * what clock and divisor to use for the required baud rate. Also
  481. * define the maximum baud rate allowed, and the default base baud.
  482. */
  483. static int stl_cd1400clkdivs[] = {
  484. CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
  485. };
  486. /*****************************************************************************/
  487. /*
  488. * SC26198 UART specific data initization.
  489. */
  490. static uart_t stl_sc26198uart = {
  491. stl_sc26198panelinit,
  492. stl_sc26198portinit,
  493. stl_sc26198setport,
  494. stl_sc26198getsignals,
  495. stl_sc26198setsignals,
  496. stl_sc26198enablerxtx,
  497. stl_sc26198startrxtx,
  498. stl_sc26198disableintrs,
  499. stl_sc26198sendbreak,
  500. stl_sc26198flowctrl,
  501. stl_sc26198sendflow,
  502. stl_sc26198flush,
  503. stl_sc26198datastate,
  504. stl_sc26198intr
  505. };
  506. /*
  507. * Define the offsets within the register bank of a sc26198 based panel.
  508. */
  509. #define XP_DATA 0
  510. #define XP_ADDR 1
  511. #define XP_MODID 2
  512. #define XP_STATUS 2
  513. #define XP_IACK 3
  514. #define XP_BANKSIZE 4
  515. /*
  516. * Define the sc26198 baud rate table. Offsets within the table
  517. * represent the actual baud rate selector of sc26198 registers.
  518. */
  519. static unsigned int sc26198_baudtable[] = {
  520. 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
  521. 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
  522. 230400, 460800, 921600
  523. };
  524. #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
  525. /*****************************************************************************/
  526. /*
  527. * Define the driver info for a user level control device. Used mainly
  528. * to get at port stats - only not using the port device itself.
  529. */
  530. static const struct file_operations stl_fsiomem = {
  531. .owner = THIS_MODULE,
  532. .ioctl = stl_memioctl,
  533. };
  534. static struct class *stallion_class;
  535. static void stl_cd_change(struct stlport *portp)
  536. {
  537. unsigned int oldsigs = portp->sigs;
  538. if (!portp->port.tty)
  539. return;
  540. portp->sigs = stl_getsignals(portp);
  541. if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
  542. wake_up_interruptible(&portp->port.open_wait);
  543. if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0))
  544. if (portp->port.flags & ASYNC_CHECK_CD)
  545. tty_hangup(portp->port.tty);
  546. }
  547. /*
  548. * Check for any arguments passed in on the module load command line.
  549. */
  550. /*****************************************************************************/
  551. /*
  552. * Parse the supplied argument string, into the board conf struct.
  553. */
  554. static int __init stl_parsebrd(struct stlconf *confp, char **argp)
  555. {
  556. char *sp;
  557. unsigned int i;
  558. pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp, argp);
  559. if ((argp[0] == NULL) || (*argp[0] == 0))
  560. return 0;
  561. for (sp = argp[0], i = 0; (*sp != 0) && (i < 25); sp++, i++)
  562. *sp = tolower(*sp);
  563. for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++)
  564. if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
  565. break;
  566. if (i == ARRAY_SIZE(stl_brdstr)) {
  567. printk("STALLION: unknown board name, %s?\n", argp[0]);
  568. return 0;
  569. }
  570. confp->brdtype = stl_brdstr[i].type;
  571. i = 1;
  572. if ((argp[i] != NULL) && (*argp[i] != 0))
  573. confp->ioaddr1 = simple_strtoul(argp[i], NULL, 0);
  574. i++;
  575. if (confp->brdtype == BRD_ECH) {
  576. if ((argp[i] != NULL) && (*argp[i] != 0))
  577. confp->ioaddr2 = simple_strtoul(argp[i], NULL, 0);
  578. i++;
  579. }
  580. if ((argp[i] != NULL) && (*argp[i] != 0))
  581. confp->irq = simple_strtoul(argp[i], NULL, 0);
  582. return 1;
  583. }
  584. /*****************************************************************************/
  585. /*
  586. * Allocate a new board structure. Fill out the basic info in it.
  587. */
  588. static struct stlbrd *stl_allocbrd(void)
  589. {
  590. struct stlbrd *brdp;
  591. brdp = kzalloc(sizeof(struct stlbrd), GFP_KERNEL);
  592. if (!brdp) {
  593. printk("STALLION: failed to allocate memory (size=%Zd)\n",
  594. sizeof(struct stlbrd));
  595. return NULL;
  596. }
  597. brdp->magic = STL_BOARDMAGIC;
  598. return brdp;
  599. }
  600. /*****************************************************************************/
  601. static int stl_open(struct tty_struct *tty, struct file *filp)
  602. {
  603. struct stlport *portp;
  604. struct stlbrd *brdp;
  605. unsigned int minordev, brdnr, panelnr;
  606. int portnr, rc;
  607. pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
  608. minordev = tty->index;
  609. brdnr = MINOR2BRD(minordev);
  610. if (brdnr >= stl_nrbrds)
  611. return -ENODEV;
  612. brdp = stl_brds[brdnr];
  613. if (brdp == NULL)
  614. return -ENODEV;
  615. minordev = MINOR2PORT(minordev);
  616. for (portnr = -1, panelnr = 0; panelnr < STL_MAXPANELS; panelnr++) {
  617. if (brdp->panels[panelnr] == NULL)
  618. break;
  619. if (minordev < brdp->panels[panelnr]->nrports) {
  620. portnr = minordev;
  621. break;
  622. }
  623. minordev -= brdp->panels[panelnr]->nrports;
  624. }
  625. if (portnr < 0)
  626. return -ENODEV;
  627. portp = brdp->panels[panelnr]->ports[portnr];
  628. if (portp == NULL)
  629. return -ENODEV;
  630. /*
  631. * On the first open of the device setup the port hardware, and
  632. * initialize the per port data structure.
  633. */
  634. portp->port.tty = tty;
  635. tty->driver_data = portp;
  636. portp->port.count++;
  637. if ((portp->port.flags & ASYNC_INITIALIZED) == 0) {
  638. if (!portp->tx.buf) {
  639. portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
  640. if (!portp->tx.buf)
  641. return -ENOMEM;
  642. portp->tx.head = portp->tx.buf;
  643. portp->tx.tail = portp->tx.buf;
  644. }
  645. stl_setport(portp, tty->termios);
  646. portp->sigs = stl_getsignals(portp);
  647. stl_setsignals(portp, 1, 1);
  648. stl_enablerxtx(portp, 1, 1);
  649. stl_startrxtx(portp, 1, 0);
  650. clear_bit(TTY_IO_ERROR, &tty->flags);
  651. portp->port.flags |= ASYNC_INITIALIZED;
  652. }
  653. /*
  654. * Check if this port is in the middle of closing. If so then wait
  655. * until it is closed then return error status, based on flag settings.
  656. * The sleep here does not need interrupt protection since the wakeup
  657. * for it is done with the same context.
  658. */
  659. if (portp->port.flags & ASYNC_CLOSING) {
  660. interruptible_sleep_on(&portp->port.close_wait);
  661. if (portp->port.flags & ASYNC_HUP_NOTIFY)
  662. return -EAGAIN;
  663. return -ERESTARTSYS;
  664. }
  665. /*
  666. * Based on type of open being done check if it can overlap with any
  667. * previous opens still in effect. If we are a normal serial device
  668. * then also we might have to wait for carrier.
  669. */
  670. if (!(filp->f_flags & O_NONBLOCK))
  671. if ((rc = stl_waitcarrier(portp, filp)) != 0)
  672. return rc;
  673. portp->port.flags |= ASYNC_NORMAL_ACTIVE;
  674. return 0;
  675. }
  676. /*****************************************************************************/
  677. /*
  678. * Possibly need to wait for carrier (DCD signal) to come high. Say
  679. * maybe because if we are clocal then we don't need to wait...
  680. */
  681. static int stl_waitcarrier(struct stlport *portp, struct file *filp)
  682. {
  683. unsigned long flags;
  684. int rc, doclocal;
  685. pr_debug("stl_waitcarrier(portp=%p,filp=%p)\n", portp, filp);
  686. rc = 0;
  687. doclocal = 0;
  688. spin_lock_irqsave(&stallion_lock, flags);
  689. if (portp->port.tty->termios->c_cflag & CLOCAL)
  690. doclocal++;
  691. portp->openwaitcnt++;
  692. if (! tty_hung_up_p(filp))
  693. portp->port.count--;
  694. for (;;) {
  695. /* Takes brd_lock internally */
  696. stl_setsignals(portp, 1, 1);
  697. if (tty_hung_up_p(filp) ||
  698. ((portp->port.flags & ASYNC_INITIALIZED) == 0)) {
  699. if (portp->port.flags & ASYNC_HUP_NOTIFY)
  700. rc = -EBUSY;
  701. else
  702. rc = -ERESTARTSYS;
  703. break;
  704. }
  705. if (((portp->port.flags & ASYNC_CLOSING) == 0) &&
  706. (doclocal || (portp->sigs & TIOCM_CD)))
  707. break;
  708. if (signal_pending(current)) {
  709. rc = -ERESTARTSYS;
  710. break;
  711. }
  712. /* FIXME */
  713. interruptible_sleep_on(&portp->port.open_wait);
  714. }
  715. if (! tty_hung_up_p(filp))
  716. portp->port.count++;
  717. portp->openwaitcnt--;
  718. spin_unlock_irqrestore(&stallion_lock, flags);
  719. return rc;
  720. }
  721. /*****************************************************************************/
  722. static void stl_flushbuffer(struct tty_struct *tty)
  723. {
  724. struct stlport *portp;
  725. pr_debug("stl_flushbuffer(tty=%p)\n", tty);
  726. if (tty == NULL)
  727. return;
  728. portp = tty->driver_data;
  729. if (portp == NULL)
  730. return;
  731. stl_flush(portp);
  732. tty_wakeup(tty);
  733. }
  734. /*****************************************************************************/
  735. static void stl_waituntilsent(struct tty_struct *tty, int timeout)
  736. {
  737. struct stlport *portp;
  738. unsigned long tend;
  739. pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout);
  740. if (tty == NULL)
  741. return;
  742. portp = tty->driver_data;
  743. if (portp == NULL)
  744. return;
  745. if (timeout == 0)
  746. timeout = HZ;
  747. tend = jiffies + timeout;
  748. lock_kernel();
  749. while (stl_datastate(portp)) {
  750. if (signal_pending(current))
  751. break;
  752. msleep_interruptible(20);
  753. if (time_after_eq(jiffies, tend))
  754. break;
  755. }
  756. unlock_kernel();
  757. }
  758. /*****************************************************************************/
  759. static void stl_close(struct tty_struct *tty, struct file *filp)
  760. {
  761. struct stlport *portp;
  762. unsigned long flags;
  763. pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
  764. portp = tty->driver_data;
  765. if (portp == NULL)
  766. return;
  767. spin_lock_irqsave(&stallion_lock, flags);
  768. if (tty_hung_up_p(filp)) {
  769. spin_unlock_irqrestore(&stallion_lock, flags);
  770. return;
  771. }
  772. if ((tty->count == 1) && (portp->port.count != 1))
  773. portp->port.count = 1;
  774. if (portp->port.count-- > 1) {
  775. spin_unlock_irqrestore(&stallion_lock, flags);
  776. return;
  777. }
  778. portp->port.count = 0;
  779. portp->port.flags |= ASYNC_CLOSING;
  780. /*
  781. * May want to wait for any data to drain before closing. The BUSY
  782. * flag keeps track of whether we are still sending or not - it is
  783. * very accurate for the cd1400, not quite so for the sc26198.
  784. * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
  785. */
  786. tty->closing = 1;
  787. spin_unlock_irqrestore(&stallion_lock, flags);
  788. if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  789. tty_wait_until_sent(tty, portp->closing_wait);
  790. stl_waituntilsent(tty, (HZ / 2));
  791. spin_lock_irqsave(&stallion_lock, flags);
  792. portp->port.flags &= ~ASYNC_INITIALIZED;
  793. spin_unlock_irqrestore(&stallion_lock, flags);
  794. stl_disableintrs(portp);
  795. if (tty->termios->c_cflag & HUPCL)
  796. stl_setsignals(portp, 0, 0);
  797. stl_enablerxtx(portp, 0, 0);
  798. stl_flushbuffer(tty);
  799. portp->istate = 0;
  800. if (portp->tx.buf != NULL) {
  801. kfree(portp->tx.buf);
  802. portp->tx.buf = NULL;
  803. portp->tx.head = NULL;
  804. portp->tx.tail = NULL;
  805. }
  806. set_bit(TTY_IO_ERROR, &tty->flags);
  807. tty_ldisc_flush(tty);
  808. tty->closing = 0;
  809. portp->port.tty = NULL;
  810. if (portp->openwaitcnt) {
  811. if (portp->close_delay)
  812. msleep_interruptible(jiffies_to_msecs(portp->close_delay));
  813. wake_up_interruptible(&portp->port.open_wait);
  814. }
  815. portp->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  816. wake_up_interruptible(&portp->port.close_wait);
  817. }
  818. /*****************************************************************************/
  819. /*
  820. * Write routine. Take data and stuff it in to the TX ring queue.
  821. * If transmit interrupts are not running then start them.
  822. */
  823. static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
  824. {
  825. struct stlport *portp;
  826. unsigned int len, stlen;
  827. unsigned char *chbuf;
  828. char *head, *tail;
  829. pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty, buf, count);
  830. portp = tty->driver_data;
  831. if (portp == NULL)
  832. return 0;
  833. if (portp->tx.buf == NULL)
  834. return 0;
  835. /*
  836. * If copying direct from user space we must cater for page faults,
  837. * causing us to "sleep" here for a while. To handle this copy in all
  838. * the data we need now, into a local buffer. Then when we got it all
  839. * copy it into the TX buffer.
  840. */
  841. chbuf = (unsigned char *) buf;
  842. head = portp->tx.head;
  843. tail = portp->tx.tail;
  844. if (head >= tail) {
  845. len = STL_TXBUFSIZE - (head - tail) - 1;
  846. stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
  847. } else {
  848. len = tail - head - 1;
  849. stlen = len;
  850. }
  851. len = min(len, (unsigned int)count);
  852. count = 0;
  853. while (len > 0) {
  854. stlen = min(len, stlen);
  855. memcpy(head, chbuf, stlen);
  856. len -= stlen;
  857. chbuf += stlen;
  858. count += stlen;
  859. head += stlen;
  860. if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
  861. head = portp->tx.buf;
  862. stlen = tail - head;
  863. }
  864. }
  865. portp->tx.head = head;
  866. clear_bit(ASYI_TXLOW, &portp->istate);
  867. stl_startrxtx(portp, -1, 1);
  868. return count;
  869. }
  870. /*****************************************************************************/
  871. static int stl_putchar(struct tty_struct *tty, unsigned char ch)
  872. {
  873. struct stlport *portp;
  874. unsigned int len;
  875. char *head, *tail;
  876. pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
  877. if (tty == NULL)
  878. return -EINVAL;
  879. portp = tty->driver_data;
  880. if (portp == NULL)
  881. return -EINVAL;
  882. if (portp->tx.buf == NULL)
  883. return -EINVAL;
  884. head = portp->tx.head;
  885. tail = portp->tx.tail;
  886. len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
  887. len--;
  888. if (len > 0) {
  889. *head++ = ch;
  890. if (head >= (portp->tx.buf + STL_TXBUFSIZE))
  891. head = portp->tx.buf;
  892. }
  893. portp->tx.head = head;
  894. return 0;
  895. }
  896. /*****************************************************************************/
  897. /*
  898. * If there are any characters in the buffer then make sure that TX
  899. * interrupts are on and get'em out. Normally used after the putchar
  900. * routine has been called.
  901. */
  902. static void stl_flushchars(struct tty_struct *tty)
  903. {
  904. struct stlport *portp;
  905. pr_debug("stl_flushchars(tty=%p)\n", tty);
  906. if (tty == NULL)
  907. return;
  908. portp = tty->driver_data;
  909. if (portp == NULL)
  910. return;
  911. if (portp->tx.buf == NULL)
  912. return;
  913. stl_startrxtx(portp, -1, 1);
  914. }
  915. /*****************************************************************************/
  916. static int stl_writeroom(struct tty_struct *tty)
  917. {
  918. struct stlport *portp;
  919. char *head, *tail;
  920. pr_debug("stl_writeroom(tty=%p)\n", tty);
  921. if (tty == NULL)
  922. return 0;
  923. portp = tty->driver_data;
  924. if (portp == NULL)
  925. return 0;
  926. if (portp->tx.buf == NULL)
  927. return 0;
  928. head = portp->tx.head;
  929. tail = portp->tx.tail;
  930. return (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1);
  931. }
  932. /*****************************************************************************/
  933. /*
  934. * Return number of chars in the TX buffer. Normally we would just
  935. * calculate the number of chars in the buffer and return that, but if
  936. * the buffer is empty and TX interrupts are still on then we return
  937. * that the buffer still has 1 char in it. This way whoever called us
  938. * will not think that ALL chars have drained - since the UART still
  939. * must have some chars in it (we are busy after all).
  940. */
  941. static int stl_charsinbuffer(struct tty_struct *tty)
  942. {
  943. struct stlport *portp;
  944. unsigned int size;
  945. char *head, *tail;
  946. pr_debug("stl_charsinbuffer(tty=%p)\n", tty);
  947. if (tty == NULL)
  948. return 0;
  949. portp = tty->driver_data;
  950. if (portp == NULL)
  951. return 0;
  952. if (portp->tx.buf == NULL)
  953. return 0;
  954. head = portp->tx.head;
  955. tail = portp->tx.tail;
  956. size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  957. if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
  958. size = 1;
  959. return size;
  960. }
  961. /*****************************************************************************/
  962. /*
  963. * Generate the serial struct info.
  964. */
  965. static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
  966. {
  967. struct serial_struct sio;
  968. struct stlbrd *brdp;
  969. pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp);
  970. memset(&sio, 0, sizeof(struct serial_struct));
  971. sio.line = portp->portnr;
  972. sio.port = portp->ioaddr;
  973. sio.flags = portp->port.flags;
  974. sio.baud_base = portp->baud_base;
  975. sio.close_delay = portp->close_delay;
  976. sio.closing_wait = portp->closing_wait;
  977. sio.custom_divisor = portp->custom_divisor;
  978. sio.hub6 = 0;
  979. if (portp->uartp == &stl_cd1400uart) {
  980. sio.type = PORT_CIRRUS;
  981. sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
  982. } else {
  983. sio.type = PORT_UNKNOWN;
  984. sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
  985. }
  986. brdp = stl_brds[portp->brdnr];
  987. if (brdp != NULL)
  988. sio.irq = brdp->irq;
  989. return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
  990. }
  991. /*****************************************************************************/
  992. /*
  993. * Set port according to the serial struct info.
  994. * At this point we do not do any auto-configure stuff, so we will
  995. * just quietly ignore any requests to change irq, etc.
  996. */
  997. static int stl_setserial(struct stlport *portp, struct serial_struct __user *sp)
  998. {
  999. struct serial_struct sio;
  1000. pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp);
  1001. if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
  1002. return -EFAULT;
  1003. if (!capable(CAP_SYS_ADMIN)) {
  1004. if ((sio.baud_base != portp->baud_base) ||
  1005. (sio.close_delay != portp->close_delay) ||
  1006. ((sio.flags & ~ASYNC_USR_MASK) !=
  1007. (portp->port.flags & ~ASYNC_USR_MASK)))
  1008. return -EPERM;
  1009. }
  1010. portp->port.flags = (portp->port.flags & ~ASYNC_USR_MASK) |
  1011. (sio.flags & ASYNC_USR_MASK);
  1012. portp->baud_base = sio.baud_base;
  1013. portp->close_delay = sio.close_delay;
  1014. portp->closing_wait = sio.closing_wait;
  1015. portp->custom_divisor = sio.custom_divisor;
  1016. stl_setport(portp, portp->port.tty->termios);
  1017. return 0;
  1018. }
  1019. /*****************************************************************************/
  1020. static int stl_tiocmget(struct tty_struct *tty, struct file *file)
  1021. {
  1022. struct stlport *portp;
  1023. if (tty == NULL)
  1024. return -ENODEV;
  1025. portp = tty->driver_data;
  1026. if (portp == NULL)
  1027. return -ENODEV;
  1028. if (tty->flags & (1 << TTY_IO_ERROR))
  1029. return -EIO;
  1030. return stl_getsignals(portp);
  1031. }
  1032. static int stl_tiocmset(struct tty_struct *tty, struct file *file,
  1033. unsigned int set, unsigned int clear)
  1034. {
  1035. struct stlport *portp;
  1036. int rts = -1, dtr = -1;
  1037. if (tty == NULL)
  1038. return -ENODEV;
  1039. portp = tty->driver_data;
  1040. if (portp == NULL)
  1041. return -ENODEV;
  1042. if (tty->flags & (1 << TTY_IO_ERROR))
  1043. return -EIO;
  1044. if (set & TIOCM_RTS)
  1045. rts = 1;
  1046. if (set & TIOCM_DTR)
  1047. dtr = 1;
  1048. if (clear & TIOCM_RTS)
  1049. rts = 0;
  1050. if (clear & TIOCM_DTR)
  1051. dtr = 0;
  1052. stl_setsignals(portp, dtr, rts);
  1053. return 0;
  1054. }
  1055. static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
  1056. {
  1057. struct stlport *portp;
  1058. int rc;
  1059. void __user *argp = (void __user *)arg;
  1060. pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd,
  1061. arg);
  1062. if (tty == NULL)
  1063. return -ENODEV;
  1064. portp = tty->driver_data;
  1065. if (portp == NULL)
  1066. return -ENODEV;
  1067. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1068. (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS))
  1069. if (tty->flags & (1 << TTY_IO_ERROR))
  1070. return -EIO;
  1071. rc = 0;
  1072. lock_kernel();
  1073. switch (cmd) {
  1074. case TIOCGSERIAL:
  1075. rc = stl_getserial(portp, argp);
  1076. break;
  1077. case TIOCSSERIAL:
  1078. rc = stl_setserial(portp, argp);
  1079. break;
  1080. case COM_GETPORTSTATS:
  1081. rc = stl_getportstats(portp, argp);
  1082. break;
  1083. case COM_CLRPORTSTATS:
  1084. rc = stl_clrportstats(portp, argp);
  1085. break;
  1086. case TIOCSERCONFIG:
  1087. case TIOCSERGWILD:
  1088. case TIOCSERSWILD:
  1089. case TIOCSERGETLSR:
  1090. case TIOCSERGSTRUCT:
  1091. case TIOCSERGETMULTI:
  1092. case TIOCSERSETMULTI:
  1093. default:
  1094. rc = -ENOIOCTLCMD;
  1095. break;
  1096. }
  1097. unlock_kernel();
  1098. return rc;
  1099. }
  1100. /*****************************************************************************/
  1101. /*
  1102. * Start the transmitter again. Just turn TX interrupts back on.
  1103. */
  1104. static void stl_start(struct tty_struct *tty)
  1105. {
  1106. struct stlport *portp;
  1107. pr_debug("stl_start(tty=%p)\n", tty);
  1108. if (tty == NULL)
  1109. return;
  1110. portp = tty->driver_data;
  1111. if (portp == NULL)
  1112. return;
  1113. stl_startrxtx(portp, -1, 1);
  1114. }
  1115. /*****************************************************************************/
  1116. static void stl_settermios(struct tty_struct *tty, struct ktermios *old)
  1117. {
  1118. struct stlport *portp;
  1119. struct ktermios *tiosp;
  1120. pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old);
  1121. if (tty == NULL)
  1122. return;
  1123. portp = tty->driver_data;
  1124. if (portp == NULL)
  1125. return;
  1126. tiosp = tty->termios;
  1127. if ((tiosp->c_cflag == old->c_cflag) &&
  1128. (tiosp->c_iflag == old->c_iflag))
  1129. return;
  1130. stl_setport(portp, tiosp);
  1131. stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
  1132. -1);
  1133. if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
  1134. tty->hw_stopped = 0;
  1135. stl_start(tty);
  1136. }
  1137. if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
  1138. wake_up_interruptible(&portp->port.open_wait);
  1139. }
  1140. /*****************************************************************************/
  1141. /*
  1142. * Attempt to flow control who ever is sending us data. Based on termios
  1143. * settings use software or/and hardware flow control.
  1144. */
  1145. static void stl_throttle(struct tty_struct *tty)
  1146. {
  1147. struct stlport *portp;
  1148. pr_debug("stl_throttle(tty=%p)\n", tty);
  1149. if (tty == NULL)
  1150. return;
  1151. portp = tty->driver_data;
  1152. if (portp == NULL)
  1153. return;
  1154. stl_flowctrl(portp, 0);
  1155. }
  1156. /*****************************************************************************/
  1157. /*
  1158. * Unflow control the device sending us data...
  1159. */
  1160. static void stl_unthrottle(struct tty_struct *tty)
  1161. {
  1162. struct stlport *portp;
  1163. pr_debug("stl_unthrottle(tty=%p)\n", tty);
  1164. if (tty == NULL)
  1165. return;
  1166. portp = tty->driver_data;
  1167. if (portp == NULL)
  1168. return;
  1169. stl_flowctrl(portp, 1);
  1170. }
  1171. /*****************************************************************************/
  1172. /*
  1173. * Stop the transmitter. Basically to do this we will just turn TX
  1174. * interrupts off.
  1175. */
  1176. static void stl_stop(struct tty_struct *tty)
  1177. {
  1178. struct stlport *portp;
  1179. pr_debug("stl_stop(tty=%p)\n", tty);
  1180. if (tty == NULL)
  1181. return;
  1182. portp = tty->driver_data;
  1183. if (portp == NULL)
  1184. return;
  1185. stl_startrxtx(portp, -1, 0);
  1186. }
  1187. /*****************************************************************************/
  1188. /*
  1189. * Hangup this port. This is pretty much like closing the port, only
  1190. * a little more brutal. No waiting for data to drain. Shutdown the
  1191. * port and maybe drop signals.
  1192. */
  1193. static void stl_hangup(struct tty_struct *tty)
  1194. {
  1195. struct stlport *portp;
  1196. pr_debug("stl_hangup(tty=%p)\n", tty);
  1197. if (tty == NULL)
  1198. return;
  1199. portp = tty->driver_data;
  1200. if (portp == NULL)
  1201. return;
  1202. portp->port.flags &= ~ASYNC_INITIALIZED;
  1203. stl_disableintrs(portp);
  1204. if (tty->termios->c_cflag & HUPCL)
  1205. stl_setsignals(portp, 0, 0);
  1206. stl_enablerxtx(portp, 0, 0);
  1207. stl_flushbuffer(tty);
  1208. portp->istate = 0;
  1209. set_bit(TTY_IO_ERROR, &tty->flags);
  1210. if (portp->tx.buf != NULL) {
  1211. kfree(portp->tx.buf);
  1212. portp->tx.buf = NULL;
  1213. portp->tx.head = NULL;
  1214. portp->tx.tail = NULL;
  1215. }
  1216. portp->port.tty = NULL;
  1217. portp->port.flags &= ~ASYNC_NORMAL_ACTIVE;
  1218. portp->port.count = 0;
  1219. wake_up_interruptible(&portp->port.open_wait);
  1220. }
  1221. /*****************************************************************************/
  1222. static int stl_breakctl(struct tty_struct *tty, int state)
  1223. {
  1224. struct stlport *portp;
  1225. pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
  1226. if (tty == NULL)
  1227. return -EINVAL;
  1228. portp = tty->driver_data;
  1229. if (portp == NULL)
  1230. return -EINVAL;
  1231. stl_sendbreak(portp, ((state == -1) ? 1 : 2));
  1232. return 0;
  1233. }
  1234. /*****************************************************************************/
  1235. static void stl_sendxchar(struct tty_struct *tty, char ch)
  1236. {
  1237. struct stlport *portp;
  1238. pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch);
  1239. if (tty == NULL)
  1240. return;
  1241. portp = tty->driver_data;
  1242. if (portp == NULL)
  1243. return;
  1244. if (ch == STOP_CHAR(tty))
  1245. stl_sendflow(portp, 0);
  1246. else if (ch == START_CHAR(tty))
  1247. stl_sendflow(portp, 1);
  1248. else
  1249. stl_putchar(tty, ch);
  1250. }
  1251. /*****************************************************************************/
  1252. #define MAXLINE 80
  1253. /*
  1254. * Format info for a specified port. The line is deliberately limited
  1255. * to 80 characters. (If it is too long it will be truncated, if too
  1256. * short then padded with spaces).
  1257. */
  1258. static int stl_portinfo(struct stlport *portp, int portnr, char *pos)
  1259. {
  1260. char *sp;
  1261. int sigs, cnt;
  1262. sp = pos;
  1263. sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
  1264. portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
  1265. (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
  1266. if (portp->stats.rxframing)
  1267. sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
  1268. if (portp->stats.rxparity)
  1269. sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
  1270. if (portp->stats.rxbreaks)
  1271. sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
  1272. if (portp->stats.rxoverrun)
  1273. sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
  1274. sigs = stl_getsignals(portp);
  1275. cnt = sprintf(sp, "%s%s%s%s%s ",
  1276. (sigs & TIOCM_RTS) ? "|RTS" : "",
  1277. (sigs & TIOCM_CTS) ? "|CTS" : "",
  1278. (sigs & TIOCM_DTR) ? "|DTR" : "",
  1279. (sigs & TIOCM_CD) ? "|DCD" : "",
  1280. (sigs & TIOCM_DSR) ? "|DSR" : "");
  1281. *sp = ' ';
  1282. sp += cnt;
  1283. for (cnt = sp - pos; cnt < (MAXLINE - 1); cnt++)
  1284. *sp++ = ' ';
  1285. if (cnt >= MAXLINE)
  1286. pos[(MAXLINE - 2)] = '+';
  1287. pos[(MAXLINE - 1)] = '\n';
  1288. return MAXLINE;
  1289. }
  1290. /*****************************************************************************/
  1291. /*
  1292. * Port info, read from the /proc file system.
  1293. */
  1294. static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
  1295. {
  1296. struct stlbrd *brdp;
  1297. struct stlpanel *panelp;
  1298. struct stlport *portp;
  1299. unsigned int brdnr, panelnr, portnr;
  1300. int totalport, curoff, maxoff;
  1301. char *pos;
  1302. pr_debug("stl_readproc(page=%p,start=%p,off=%lx,count=%d,eof=%p,"
  1303. "data=%p\n", page, start, off, count, eof, data);
  1304. pos = page;
  1305. totalport = 0;
  1306. curoff = 0;
  1307. if (off == 0) {
  1308. pos += sprintf(pos, "%s: version %s", stl_drvtitle,
  1309. stl_drvversion);
  1310. while (pos < (page + MAXLINE - 1))
  1311. *pos++ = ' ';
  1312. *pos++ = '\n';
  1313. }
  1314. curoff = MAXLINE;
  1315. /*
  1316. * We scan through for each board, panel and port. The offset is
  1317. * calculated on the fly, and irrelevant ports are skipped.
  1318. */
  1319. for (brdnr = 0; brdnr < stl_nrbrds; brdnr++) {
  1320. brdp = stl_brds[brdnr];
  1321. if (brdp == NULL)
  1322. continue;
  1323. if (brdp->state == 0)
  1324. continue;
  1325. maxoff = curoff + (brdp->nrports * MAXLINE);
  1326. if (off >= maxoff) {
  1327. curoff = maxoff;
  1328. continue;
  1329. }
  1330. totalport = brdnr * STL_MAXPORTS;
  1331. for (panelnr = 0; panelnr < brdp->nrpanels; panelnr++) {
  1332. panelp = brdp->panels[panelnr];
  1333. if (panelp == NULL)
  1334. continue;
  1335. maxoff = curoff + (panelp->nrports * MAXLINE);
  1336. if (off >= maxoff) {
  1337. curoff = maxoff;
  1338. totalport += panelp->nrports;
  1339. continue;
  1340. }
  1341. for (portnr = 0; portnr < panelp->nrports; portnr++,
  1342. totalport++) {
  1343. portp = panelp->ports[portnr];
  1344. if (portp == NULL)
  1345. continue;
  1346. if (off >= (curoff += MAXLINE))
  1347. continue;
  1348. if ((pos - page + MAXLINE) > count)
  1349. goto stl_readdone;
  1350. pos += stl_portinfo(portp, totalport, pos);
  1351. }
  1352. }
  1353. }
  1354. *eof = 1;
  1355. stl_readdone:
  1356. *start = page;
  1357. return pos - page;
  1358. }
  1359. /*****************************************************************************/
  1360. /*
  1361. * All board interrupts are vectored through here first. This code then
  1362. * calls off to the approrpriate board interrupt handlers.
  1363. */
  1364. static irqreturn_t stl_intr(int irq, void *dev_id)
  1365. {
  1366. struct stlbrd *brdp = dev_id;
  1367. pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp, brdp->irq);
  1368. return IRQ_RETVAL((* brdp->isr)(brdp));
  1369. }
  1370. /*****************************************************************************/
  1371. /*
  1372. * Interrupt service routine for EasyIO board types.
  1373. */
  1374. static int stl_eiointr(struct stlbrd *brdp)
  1375. {
  1376. struct stlpanel *panelp;
  1377. unsigned int iobase;
  1378. int handled = 0;
  1379. spin_lock(&brd_lock);
  1380. panelp = brdp->panels[0];
  1381. iobase = panelp->iobase;
  1382. while (inb(brdp->iostatus) & EIO_INTRPEND) {
  1383. handled = 1;
  1384. (* panelp->isr)(panelp, iobase);
  1385. }
  1386. spin_unlock(&brd_lock);
  1387. return handled;
  1388. }
  1389. /*****************************************************************************/
  1390. /*
  1391. * Interrupt service routine for ECH-AT board types.
  1392. */
  1393. static int stl_echatintr(struct stlbrd *brdp)
  1394. {
  1395. struct stlpanel *panelp;
  1396. unsigned int ioaddr, bnknr;
  1397. int handled = 0;
  1398. outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
  1399. while (inb(brdp->iostatus) & ECH_INTRPEND) {
  1400. handled = 1;
  1401. for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
  1402. ioaddr = brdp->bnkstataddr[bnknr];
  1403. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1404. panelp = brdp->bnk2panel[bnknr];
  1405. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1406. }
  1407. }
  1408. }
  1409. outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
  1410. return handled;
  1411. }
  1412. /*****************************************************************************/
  1413. /*
  1414. * Interrupt service routine for ECH-MCA board types.
  1415. */
  1416. static int stl_echmcaintr(struct stlbrd *brdp)
  1417. {
  1418. struct stlpanel *panelp;
  1419. unsigned int ioaddr, bnknr;
  1420. int handled = 0;
  1421. while (inb(brdp->iostatus) & ECH_INTRPEND) {
  1422. handled = 1;
  1423. for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
  1424. ioaddr = brdp->bnkstataddr[bnknr];
  1425. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1426. panelp = brdp->bnk2panel[bnknr];
  1427. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1428. }
  1429. }
  1430. }
  1431. return handled;
  1432. }
  1433. /*****************************************************************************/
  1434. /*
  1435. * Interrupt service routine for ECH-PCI board types.
  1436. */
  1437. static int stl_echpciintr(struct stlbrd *brdp)
  1438. {
  1439. struct stlpanel *panelp;
  1440. unsigned int ioaddr, bnknr, recheck;
  1441. int handled = 0;
  1442. while (1) {
  1443. recheck = 0;
  1444. for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
  1445. outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
  1446. ioaddr = brdp->bnkstataddr[bnknr];
  1447. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1448. panelp = brdp->bnk2panel[bnknr];
  1449. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1450. recheck++;
  1451. handled = 1;
  1452. }
  1453. }
  1454. if (! recheck)
  1455. break;
  1456. }
  1457. return handled;
  1458. }
  1459. /*****************************************************************************/
  1460. /*
  1461. * Interrupt service routine for ECH-8/64-PCI board types.
  1462. */
  1463. static int stl_echpci64intr(struct stlbrd *brdp)
  1464. {
  1465. struct stlpanel *panelp;
  1466. unsigned int ioaddr, bnknr;
  1467. int handled = 0;
  1468. while (inb(brdp->ioctrl) & 0x1) {
  1469. handled = 1;
  1470. for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
  1471. ioaddr = brdp->bnkstataddr[bnknr];
  1472. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1473. panelp = brdp->bnk2panel[bnknr];
  1474. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1475. }
  1476. }
  1477. }
  1478. return handled;
  1479. }
  1480. /*****************************************************************************/
  1481. /*
  1482. * Initialize all the ports on a panel.
  1483. */
  1484. static int __devinit stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
  1485. {
  1486. struct stlport *portp;
  1487. unsigned int i;
  1488. int chipmask;
  1489. pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp);
  1490. chipmask = stl_panelinit(brdp, panelp);
  1491. /*
  1492. * All UART's are initialized (if found!). Now go through and setup
  1493. * each ports data structures.
  1494. */
  1495. for (i = 0; i < panelp->nrports; i++) {
  1496. portp = kzalloc(sizeof(struct stlport), GFP_KERNEL);
  1497. if (!portp) {
  1498. printk("STALLION: failed to allocate memory "
  1499. "(size=%Zd)\n", sizeof(struct stlport));
  1500. break;
  1501. }
  1502. portp->magic = STL_PORTMAGIC;
  1503. portp->portnr = i;
  1504. portp->brdnr = panelp->brdnr;
  1505. portp->panelnr = panelp->panelnr;
  1506. portp->uartp = panelp->uartp;
  1507. portp->clk = brdp->clk;
  1508. portp->baud_base = STL_BAUDBASE;
  1509. portp->close_delay = STL_CLOSEDELAY;
  1510. portp->closing_wait = 30 * HZ;
  1511. init_waitqueue_head(&portp->port.open_wait);
  1512. init_waitqueue_head(&portp->port.close_wait);
  1513. portp->stats.brd = portp->brdnr;
  1514. portp->stats.panel = portp->panelnr;
  1515. portp->stats.port = portp->portnr;
  1516. panelp->ports[i] = portp;
  1517. stl_portinit(brdp, panelp, portp);
  1518. }
  1519. return 0;
  1520. }
  1521. static void stl_cleanup_panels(struct stlbrd *brdp)
  1522. {
  1523. struct stlpanel *panelp;
  1524. struct stlport *portp;
  1525. unsigned int j, k;
  1526. for (j = 0; j < STL_MAXPANELS; j++) {
  1527. panelp = brdp->panels[j];
  1528. if (panelp == NULL)
  1529. continue;
  1530. for (k = 0; k < STL_PORTSPERPANEL; k++) {
  1531. portp = panelp->ports[k];
  1532. if (portp == NULL)
  1533. continue;
  1534. if (portp->port.tty != NULL)
  1535. stl_hangup(portp->port.tty);
  1536. kfree(portp->tx.buf);
  1537. kfree(portp);
  1538. }
  1539. kfree(panelp);
  1540. }
  1541. }
  1542. /*****************************************************************************/
  1543. /*
  1544. * Try to find and initialize an EasyIO board.
  1545. */
  1546. static int __devinit stl_initeio(struct stlbrd *brdp)
  1547. {
  1548. struct stlpanel *panelp;
  1549. unsigned int status;
  1550. char *name;
  1551. int retval;
  1552. pr_debug("stl_initeio(brdp=%p)\n", brdp);
  1553. brdp->ioctrl = brdp->ioaddr1 + 1;
  1554. brdp->iostatus = brdp->ioaddr1 + 2;
  1555. status = inb(brdp->iostatus);
  1556. if ((status & EIO_IDBITMASK) == EIO_MK3)
  1557. brdp->ioctrl++;
  1558. /*
  1559. * Handle board specific stuff now. The real difference is PCI
  1560. * or not PCI.
  1561. */
  1562. if (brdp->brdtype == BRD_EASYIOPCI) {
  1563. brdp->iosize1 = 0x80;
  1564. brdp->iosize2 = 0x80;
  1565. name = "serial(EIO-PCI)";
  1566. outb(0x41, (brdp->ioaddr2 + 0x4c));
  1567. } else {
  1568. brdp->iosize1 = 8;
  1569. name = "serial(EIO)";
  1570. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  1571. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  1572. printk("STALLION: invalid irq=%d for brd=%d\n",
  1573. brdp->irq, brdp->brdnr);
  1574. retval = -EINVAL;
  1575. goto err;
  1576. }
  1577. outb((stl_vecmap[brdp->irq] | EIO_0WS |
  1578. ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
  1579. brdp->ioctrl);
  1580. }
  1581. retval = -EBUSY;
  1582. if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
  1583. printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
  1584. "%x conflicts with another device\n", brdp->brdnr,
  1585. brdp->ioaddr1);
  1586. goto err;
  1587. }
  1588. if (brdp->iosize2 > 0)
  1589. if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
  1590. printk(KERN_WARNING "STALLION: Warning, board %d I/O "
  1591. "address %x conflicts with another device\n",
  1592. brdp->brdnr, brdp->ioaddr2);
  1593. printk(KERN_WARNING "STALLION: Warning, also "
  1594. "releasing board %d I/O address %x \n",
  1595. brdp->brdnr, brdp->ioaddr1);
  1596. goto err_rel1;
  1597. }
  1598. /*
  1599. * Everything looks OK, so let's go ahead and probe for the hardware.
  1600. */
  1601. brdp->clk = CD1400_CLK;
  1602. brdp->isr = stl_eiointr;
  1603. retval = -ENODEV;
  1604. switch (status & EIO_IDBITMASK) {
  1605. case EIO_8PORTM:
  1606. brdp->clk = CD1400_CLK8M;
  1607. /* fall thru */
  1608. case EIO_8PORTRS:
  1609. case EIO_8PORTDI:
  1610. brdp->nrports = 8;
  1611. break;
  1612. case EIO_4PORTRS:
  1613. brdp->nrports = 4;
  1614. break;
  1615. case EIO_MK3:
  1616. switch (status & EIO_BRDMASK) {
  1617. case ID_BRD4:
  1618. brdp->nrports = 4;
  1619. break;
  1620. case ID_BRD8:
  1621. brdp->nrports = 8;
  1622. break;
  1623. case ID_BRD16:
  1624. brdp->nrports = 16;
  1625. break;
  1626. default:
  1627. goto err_rel2;
  1628. }
  1629. break;
  1630. default:
  1631. goto err_rel2;
  1632. }
  1633. /*
  1634. * We have verified that the board is actually present, so now we
  1635. * can complete the setup.
  1636. */
  1637. panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
  1638. if (!panelp) {
  1639. printk(KERN_WARNING "STALLION: failed to allocate memory "
  1640. "(size=%Zd)\n", sizeof(struct stlpanel));
  1641. retval = -ENOMEM;
  1642. goto err_rel2;
  1643. }
  1644. panelp->magic = STL_PANELMAGIC;
  1645. panelp->brdnr = brdp->brdnr;
  1646. panelp->panelnr = 0;
  1647. panelp->nrports = brdp->nrports;
  1648. panelp->iobase = brdp->ioaddr1;
  1649. panelp->hwid = status;
  1650. if ((status & EIO_IDBITMASK) == EIO_MK3) {
  1651. panelp->uartp = &stl_sc26198uart;
  1652. panelp->isr = stl_sc26198intr;
  1653. } else {
  1654. panelp->uartp = &stl_cd1400uart;
  1655. panelp->isr = stl_cd1400eiointr;
  1656. }
  1657. brdp->panels[0] = panelp;
  1658. brdp->nrpanels = 1;
  1659. brdp->state |= BRD_FOUND;
  1660. brdp->hwid = status;
  1661. if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
  1662. printk("STALLION: failed to register interrupt "
  1663. "routine for %s irq=%d\n", name, brdp->irq);
  1664. retval = -ENODEV;
  1665. goto err_fr;
  1666. }
  1667. return 0;
  1668. err_fr:
  1669. stl_cleanup_panels(brdp);
  1670. err_rel2:
  1671. if (brdp->iosize2 > 0)
  1672. release_region(brdp->ioaddr2, brdp->iosize2);
  1673. err_rel1:
  1674. release_region(brdp->ioaddr1, brdp->iosize1);
  1675. err:
  1676. return retval;
  1677. }
  1678. /*****************************************************************************/
  1679. /*
  1680. * Try to find an ECH board and initialize it. This code is capable of
  1681. * dealing with all types of ECH board.
  1682. */
  1683. static int __devinit stl_initech(struct stlbrd *brdp)
  1684. {
  1685. struct stlpanel *panelp;
  1686. unsigned int status, nxtid, ioaddr, conflict, panelnr, banknr, i;
  1687. int retval;
  1688. char *name;
  1689. pr_debug("stl_initech(brdp=%p)\n", brdp);
  1690. status = 0;
  1691. conflict = 0;
  1692. /*
  1693. * Set up the initial board register contents for boards. This varies a
  1694. * bit between the different board types. So we need to handle each
  1695. * separately. Also do a check that the supplied IRQ is good.
  1696. */
  1697. switch (brdp->brdtype) {
  1698. case BRD_ECH:
  1699. brdp->isr = stl_echatintr;
  1700. brdp->ioctrl = brdp->ioaddr1 + 1;
  1701. brdp->iostatus = brdp->ioaddr1 + 1;
  1702. status = inb(brdp->iostatus);
  1703. if ((status & ECH_IDBITMASK) != ECH_ID) {
  1704. retval = -ENODEV;
  1705. goto err;
  1706. }
  1707. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  1708. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  1709. printk("STALLION: invalid irq=%d for brd=%d\n",
  1710. brdp->irq, brdp->brdnr);
  1711. retval = -EINVAL;
  1712. goto err;
  1713. }
  1714. status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
  1715. status |= (stl_vecmap[brdp->irq] << 1);
  1716. outb((status | ECH_BRDRESET), brdp->ioaddr1);
  1717. brdp->ioctrlval = ECH_INTENABLE |
  1718. ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
  1719. for (i = 0; i < 10; i++)
  1720. outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
  1721. brdp->iosize1 = 2;
  1722. brdp->iosize2 = 32;
  1723. name = "serial(EC8/32)";
  1724. outb(status, brdp->ioaddr1);
  1725. break;
  1726. case BRD_ECHMC:
  1727. brdp->isr = stl_echmcaintr;
  1728. brdp->ioctrl = brdp->ioaddr1 + 0x20;
  1729. brdp->iostatus = brdp->ioctrl;
  1730. status = inb(brdp->iostatus);
  1731. if ((status & ECH_IDBITMASK) != ECH_ID) {
  1732. retval = -ENODEV;
  1733. goto err;
  1734. }
  1735. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  1736. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  1737. printk("STALLION: invalid irq=%d for brd=%d\n",
  1738. brdp->irq, brdp->brdnr);
  1739. retval = -EINVAL;
  1740. goto err;
  1741. }
  1742. outb(ECHMC_BRDRESET, brdp->ioctrl);
  1743. outb(ECHMC_INTENABLE, brdp->ioctrl);
  1744. brdp->iosize1 = 64;
  1745. name = "serial(EC8/32-MC)";
  1746. break;
  1747. case BRD_ECHPCI:
  1748. brdp->isr = stl_echpciintr;
  1749. brdp->ioctrl = brdp->ioaddr1 + 2;
  1750. brdp->iosize1 = 4;
  1751. brdp->iosize2 = 8;
  1752. name = "serial(EC8/32-PCI)";
  1753. break;
  1754. case BRD_ECH64PCI:
  1755. brdp->isr = stl_echpci64intr;
  1756. brdp->ioctrl = brdp->ioaddr2 + 0x40;
  1757. outb(0x43, (brdp->ioaddr1 + 0x4c));
  1758. brdp->iosize1 = 0x80;
  1759. brdp->iosize2 = 0x80;
  1760. name = "serial(EC8/64-PCI)";
  1761. break;
  1762. default:
  1763. printk("STALLION: unknown board type=%d\n", brdp->brdtype);
  1764. retval = -EINVAL;
  1765. goto err;
  1766. }
  1767. /*
  1768. * Check boards for possible IO address conflicts and return fail status
  1769. * if an IO conflict found.
  1770. */
  1771. retval = -EBUSY;
  1772. if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
  1773. printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
  1774. "%x conflicts with another device\n", brdp->brdnr,
  1775. brdp->ioaddr1);
  1776. goto err;
  1777. }
  1778. if (brdp->iosize2 > 0)
  1779. if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
  1780. printk(KERN_WARNING "STALLION: Warning, board %d I/O "
  1781. "address %x conflicts with another device\n",
  1782. brdp->brdnr, brdp->ioaddr2);
  1783. printk(KERN_WARNING "STALLION: Warning, also "
  1784. "releasing board %d I/O address %x \n",
  1785. brdp->brdnr, brdp->ioaddr1);
  1786. goto err_rel1;
  1787. }
  1788. /*
  1789. * Scan through the secondary io address space looking for panels.
  1790. * As we find'em allocate and initialize panel structures for each.
  1791. */
  1792. brdp->clk = CD1400_CLK;
  1793. brdp->hwid = status;
  1794. ioaddr = brdp->ioaddr2;
  1795. banknr = 0;
  1796. panelnr = 0;
  1797. nxtid = 0;
  1798. for (i = 0; i < STL_MAXPANELS; i++) {
  1799. if (brdp->brdtype == BRD_ECHPCI) {
  1800. outb(nxtid, brdp->ioctrl);
  1801. ioaddr = brdp->ioaddr2;
  1802. }
  1803. status = inb(ioaddr + ECH_PNLSTATUS);
  1804. if ((status & ECH_PNLIDMASK) != nxtid)
  1805. break;
  1806. panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
  1807. if (!panelp) {
  1808. printk("STALLION: failed to allocate memory "
  1809. "(size=%Zd)\n", sizeof(struct stlpanel));
  1810. retval = -ENOMEM;
  1811. goto err_fr;
  1812. }
  1813. panelp->magic = STL_PANELMAGIC;
  1814. panelp->brdnr = brdp->brdnr;
  1815. panelp->panelnr = panelnr;
  1816. panelp->iobase = ioaddr;
  1817. panelp->pagenr = nxtid;
  1818. panelp->hwid = status;
  1819. brdp->bnk2panel[banknr] = panelp;
  1820. brdp->bnkpageaddr[banknr] = nxtid;
  1821. brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
  1822. if (status & ECH_PNLXPID) {
  1823. panelp->uartp = &stl_sc26198uart;
  1824. panelp->isr = stl_sc26198intr;
  1825. if (status & ECH_PNL16PORT) {
  1826. panelp->nrports = 16;
  1827. brdp->bnk2panel[banknr] = panelp;
  1828. brdp->bnkpageaddr[banknr] = nxtid;
  1829. brdp->bnkstataddr[banknr++] = ioaddr + 4 +
  1830. ECH_PNLSTATUS;
  1831. } else
  1832. panelp->nrports = 8;
  1833. } else {
  1834. panelp->uartp = &stl_cd1400uart;
  1835. panelp->isr = stl_cd1400echintr;
  1836. if (status & ECH_PNL16PORT) {
  1837. panelp->nrports = 16;
  1838. panelp->ackmask = 0x80;
  1839. if (brdp->brdtype != BRD_ECHPCI)
  1840. ioaddr += EREG_BANKSIZE;
  1841. brdp->bnk2panel[banknr] = panelp;
  1842. brdp->bnkpageaddr[banknr] = ++nxtid;
  1843. brdp->bnkstataddr[banknr++] = ioaddr +
  1844. ECH_PNLSTATUS;
  1845. } else {
  1846. panelp->nrports = 8;
  1847. panelp->ackmask = 0xc0;
  1848. }
  1849. }
  1850. nxtid++;
  1851. ioaddr += EREG_BANKSIZE;
  1852. brdp->nrports += panelp->nrports;
  1853. brdp->panels[panelnr++] = panelp;
  1854. if ((brdp->brdtype != BRD_ECHPCI) &&
  1855. (ioaddr >= (brdp->ioaddr2 + brdp->iosize2))) {
  1856. retval = -EINVAL;
  1857. goto err_fr;
  1858. }
  1859. }
  1860. brdp->nrpanels = panelnr;
  1861. brdp->nrbnks = banknr;
  1862. if (brdp->brdtype == BRD_ECH)
  1863. outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
  1864. brdp->state |= BRD_FOUND;
  1865. if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
  1866. printk("STALLION: failed to register interrupt "
  1867. "routine for %s irq=%d\n", name, brdp->irq);
  1868. retval = -ENODEV;
  1869. goto err_fr;
  1870. }
  1871. return 0;
  1872. err_fr:
  1873. stl_cleanup_panels(brdp);
  1874. if (brdp->iosize2 > 0)
  1875. release_region(brdp->ioaddr2, brdp->iosize2);
  1876. err_rel1:
  1877. release_region(brdp->ioaddr1, brdp->iosize1);
  1878. err:
  1879. return retval;
  1880. }
  1881. /*****************************************************************************/
  1882. /*
  1883. * Initialize and configure the specified board.
  1884. * Scan through all the boards in the configuration and see what we
  1885. * can find. Handle EIO and the ECH boards a little differently here
  1886. * since the initial search and setup is very different.
  1887. */
  1888. static int __devinit stl_brdinit(struct stlbrd *brdp)
  1889. {
  1890. int i, retval;
  1891. pr_debug("stl_brdinit(brdp=%p)\n", brdp);
  1892. switch (brdp->brdtype) {
  1893. case BRD_EASYIO:
  1894. case BRD_EASYIOPCI:
  1895. retval = stl_initeio(brdp);
  1896. if (retval)
  1897. goto err;
  1898. break;
  1899. case BRD_ECH:
  1900. case BRD_ECHMC:
  1901. case BRD_ECHPCI:
  1902. case BRD_ECH64PCI:
  1903. retval = stl_initech(brdp);
  1904. if (retval)
  1905. goto err;
  1906. break;
  1907. default:
  1908. printk("STALLION: board=%d is unknown board type=%d\n",
  1909. brdp->brdnr, brdp->brdtype);
  1910. retval = -ENODEV;
  1911. goto err;
  1912. }
  1913. if ((brdp->state & BRD_FOUND) == 0) {
  1914. printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
  1915. stl_brdnames[brdp->brdtype], brdp->brdnr,
  1916. brdp->ioaddr1, brdp->irq);
  1917. goto err_free;
  1918. }
  1919. for (i = 0; i < STL_MAXPANELS; i++)
  1920. if (brdp->panels[i] != NULL)
  1921. stl_initports(brdp, brdp->panels[i]);
  1922. printk("STALLION: %s found, board=%d io=%x irq=%d "
  1923. "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
  1924. brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
  1925. brdp->nrports);
  1926. return 0;
  1927. err_free:
  1928. free_irq(brdp->irq, brdp);
  1929. stl_cleanup_panels(brdp);
  1930. release_region(brdp->ioaddr1, brdp->iosize1);
  1931. if (brdp->iosize2 > 0)
  1932. release_region(brdp->ioaddr2, brdp->iosize2);
  1933. err:
  1934. return retval;
  1935. }
  1936. /*****************************************************************************/
  1937. /*
  1938. * Find the next available board number that is free.
  1939. */
  1940. static int __devinit stl_getbrdnr(void)
  1941. {
  1942. unsigned int i;
  1943. for (i = 0; i < STL_MAXBRDS; i++)
  1944. if (stl_brds[i] == NULL) {
  1945. if (i >= stl_nrbrds)
  1946. stl_nrbrds = i + 1;
  1947. return i;
  1948. }
  1949. return -1;
  1950. }
  1951. /*****************************************************************************/
  1952. /*
  1953. * We have a Stallion board. Allocate a board structure and
  1954. * initialize it. Read its IO and IRQ resources from PCI
  1955. * configuration space.
  1956. */
  1957. static int __devinit stl_pciprobe(struct pci_dev *pdev,
  1958. const struct pci_device_id *ent)
  1959. {
  1960. struct stlbrd *brdp;
  1961. unsigned int i, brdtype = ent->driver_data;
  1962. int brdnr, retval = -ENODEV;
  1963. if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
  1964. goto err;
  1965. retval = pci_enable_device(pdev);
  1966. if (retval)
  1967. goto err;
  1968. brdp = stl_allocbrd();
  1969. if (brdp == NULL) {
  1970. retval = -ENOMEM;
  1971. goto err;
  1972. }
  1973. mutex_lock(&stl_brdslock);
  1974. brdnr = stl_getbrdnr();
  1975. if (brdnr < 0) {
  1976. dev_err(&pdev->dev, "too many boards found, "
  1977. "maximum supported %d\n", STL_MAXBRDS);
  1978. mutex_unlock(&stl_brdslock);
  1979. retval = -ENODEV;
  1980. goto err_fr;
  1981. }
  1982. brdp->brdnr = (unsigned int)brdnr;
  1983. stl_brds[brdp->brdnr] = brdp;
  1984. mutex_unlock(&stl_brdslock);
  1985. brdp->brdtype = brdtype;
  1986. brdp->state |= STL_PROBED;
  1987. /*
  1988. * We have all resources from the board, so let's setup the actual
  1989. * board structure now.
  1990. */
  1991. switch (brdtype) {
  1992. case BRD_ECHPCI:
  1993. brdp->ioaddr2 = pci_resource_start(pdev, 0);
  1994. brdp->ioaddr1 = pci_resource_start(pdev, 1);
  1995. break;
  1996. case BRD_ECH64PCI:
  1997. brdp->ioaddr2 = pci_resource_start(pdev, 2);
  1998. brdp->ioaddr1 = pci_resource_start(pdev, 1);
  1999. break;
  2000. case BRD_EASYIOPCI:
  2001. brdp->ioaddr1 = pci_resource_start(pdev, 2);
  2002. brdp->ioaddr2 = pci_resource_start(pdev, 1);
  2003. break;
  2004. default:
  2005. dev_err(&pdev->dev, "unknown PCI board type=%u\n", brdtype);
  2006. break;
  2007. }
  2008. brdp->irq = pdev->irq;
  2009. retval = stl_brdinit(brdp);
  2010. if (retval)
  2011. goto err_null;
  2012. pci_set_drvdata(pdev, brdp);
  2013. for (i = 0; i < brdp->nrports; i++)
  2014. tty_register_device(stl_serial,
  2015. brdp->brdnr * STL_MAXPORTS + i, &pdev->dev);
  2016. return 0;
  2017. err_null:
  2018. stl_brds[brdp->brdnr] = NULL;
  2019. err_fr:
  2020. kfree(brdp);
  2021. err:
  2022. return retval;
  2023. }
  2024. static void __devexit stl_pciremove(struct pci_dev *pdev)
  2025. {
  2026. struct stlbrd *brdp = pci_get_drvdata(pdev);
  2027. unsigned int i;
  2028. free_irq(brdp->irq, brdp);
  2029. stl_cleanup_panels(brdp);
  2030. release_region(brdp->ioaddr1, brdp->iosize1);
  2031. if (brdp->iosize2 > 0)
  2032. release_region(brdp->ioaddr2, brdp->iosize2);
  2033. for (i = 0; i < brdp->nrports; i++)
  2034. tty_unregister_device(stl_serial,
  2035. brdp->brdnr * STL_MAXPORTS + i);
  2036. stl_brds[brdp->brdnr] = NULL;
  2037. kfree(brdp);
  2038. }
  2039. static struct pci_driver stl_pcidriver = {
  2040. .name = "stallion",
  2041. .id_table = stl_pcibrds,
  2042. .probe = stl_pciprobe,
  2043. .remove = __devexit_p(stl_pciremove)
  2044. };
  2045. /*****************************************************************************/
  2046. /*
  2047. * Return the board stats structure to user app.
  2048. */
  2049. static int stl_getbrdstats(combrd_t __user *bp)
  2050. {
  2051. combrd_t stl_brdstats;
  2052. struct stlbrd *brdp;
  2053. struct stlpanel *panelp;
  2054. unsigned int i;
  2055. if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
  2056. return -EFAULT;
  2057. if (stl_brdstats.brd >= STL_MAXBRDS)
  2058. return -ENODEV;
  2059. brdp = stl_brds[stl_brdstats.brd];
  2060. if (brdp == NULL)
  2061. return -ENODEV;
  2062. memset(&stl_brdstats, 0, sizeof(combrd_t));
  2063. stl_brdstats.brd = brdp->brdnr;
  2064. stl_brdstats.type = brdp->brdtype;
  2065. stl_brdstats.hwid = brdp->hwid;
  2066. stl_brdstats.state = brdp->state;
  2067. stl_brdstats.ioaddr = brdp->ioaddr1;
  2068. stl_brdstats.ioaddr2 = brdp->ioaddr2;
  2069. stl_brdstats.irq = brdp->irq;
  2070. stl_brdstats.nrpanels = brdp->nrpanels;
  2071. stl_brdstats.nrports = brdp->nrports;
  2072. for (i = 0; i < brdp->nrpanels; i++) {
  2073. panelp = brdp->panels[i];
  2074. stl_brdstats.panels[i].panel = i;
  2075. stl_brdstats.panels[i].hwid = panelp->hwid;
  2076. stl_brdstats.panels[i].nrports = panelp->nrports;
  2077. }
  2078. return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
  2079. }
  2080. /*****************************************************************************/
  2081. /*
  2082. * Resolve the referenced port number into a port struct pointer.
  2083. */
  2084. static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
  2085. {
  2086. struct stlbrd *brdp;
  2087. struct stlpanel *panelp;
  2088. if (brdnr < 0 || brdnr >= STL_MAXBRDS)
  2089. return NULL;
  2090. brdp = stl_brds[brdnr];
  2091. if (brdp == NULL)
  2092. return NULL;
  2093. if (panelnr < 0 || (unsigned int)panelnr >= brdp->nrpanels)
  2094. return NULL;
  2095. panelp = brdp->panels[panelnr];
  2096. if (panelp == NULL)
  2097. return NULL;
  2098. if (portnr < 0 || (unsigned int)portnr >= panelp->nrports)
  2099. return NULL;
  2100. return panelp->ports[portnr];
  2101. }
  2102. /*****************************************************************************/
  2103. /*
  2104. * Return the port stats structure to user app. A NULL port struct
  2105. * pointer passed in means that we need to find out from the app
  2106. * what port to get stats for (used through board control device).
  2107. */
  2108. static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
  2109. {
  2110. comstats_t stl_comstats;
  2111. unsigned char *head, *tail;
  2112. unsigned long flags;
  2113. if (!portp) {
  2114. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  2115. return -EFAULT;
  2116. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  2117. stl_comstats.port);
  2118. if (portp == NULL)
  2119. return -ENODEV;
  2120. }
  2121. portp->stats.state = portp->istate;
  2122. portp->stats.flags = portp->port.flags;
  2123. portp->stats.hwid = portp->hwid;
  2124. portp->stats.ttystate = 0;
  2125. portp->stats.cflags = 0;
  2126. portp->stats.iflags = 0;
  2127. portp->stats.oflags = 0;
  2128. portp->stats.lflags = 0;
  2129. portp->stats.rxbuffered = 0;
  2130. spin_lock_irqsave(&stallion_lock, flags);
  2131. if (portp->port.tty != NULL)
  2132. if (portp->port.tty->driver_data == portp) {
  2133. portp->stats.ttystate = portp->port.tty->flags;
  2134. /* No longer available as a statistic */
  2135. portp->stats.rxbuffered = 1; /*portp->port.tty->flip.count; */
  2136. if (portp->port.tty->termios != NULL) {
  2137. portp->stats.cflags = portp->port.tty->termios->c_cflag;
  2138. portp->stats.iflags = portp->port.tty->termios->c_iflag;
  2139. portp->stats.oflags = portp->port.tty->termios->c_oflag;
  2140. portp->stats.lflags = portp->port.tty->termios->c_lflag;
  2141. }
  2142. }
  2143. spin_unlock_irqrestore(&stallion_lock, flags);
  2144. head = portp->tx.head;
  2145. tail = portp->tx.tail;
  2146. portp->stats.txbuffered = (head >= tail) ? (head - tail) :
  2147. (STL_TXBUFSIZE - (tail - head));
  2148. portp->stats.signals = (unsigned long) stl_getsignals(portp);
  2149. return copy_to_user(cp, &portp->stats,
  2150. sizeof(comstats_t)) ? -EFAULT : 0;
  2151. }
  2152. /*****************************************************************************/
  2153. /*
  2154. * Clear the port stats structure. We also return it zeroed out...
  2155. */
  2156. static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
  2157. {
  2158. comstats_t stl_comstats;
  2159. if (!portp) {
  2160. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  2161. return -EFAULT;
  2162. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  2163. stl_comstats.port);
  2164. if (portp == NULL)
  2165. return -ENODEV;
  2166. }
  2167. memset(&portp->stats, 0, sizeof(comstats_t));
  2168. portp->stats.brd = portp->brdnr;
  2169. portp->stats.panel = portp->panelnr;
  2170. portp->stats.port = portp->portnr;
  2171. return copy_to_user(cp, &portp->stats,
  2172. sizeof(comstats_t)) ? -EFAULT : 0;
  2173. }
  2174. /*****************************************************************************/
  2175. /*
  2176. * Return the entire driver ports structure to a user app.
  2177. */
  2178. static int stl_getportstruct(struct stlport __user *arg)
  2179. {
  2180. struct stlport stl_dummyport;
  2181. struct stlport *portp;
  2182. if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
  2183. return -EFAULT;
  2184. portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
  2185. stl_dummyport.portnr);
  2186. if (!portp)
  2187. return -ENODEV;
  2188. return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0;
  2189. }
  2190. /*****************************************************************************/
  2191. /*
  2192. * Return the entire driver board structure to a user app.
  2193. */
  2194. static int stl_getbrdstruct(struct stlbrd __user *arg)
  2195. {
  2196. struct stlbrd stl_dummybrd;
  2197. struct stlbrd *brdp;
  2198. if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
  2199. return -EFAULT;
  2200. if (stl_dummybrd.brdnr >= STL_MAXBRDS)
  2201. return -ENODEV;
  2202. brdp = stl_brds[stl_dummybrd.brdnr];
  2203. if (!brdp)
  2204. return -ENODEV;
  2205. return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
  2206. }
  2207. /*****************************************************************************/
  2208. /*
  2209. * The "staliomem" device is also required to do some special operations
  2210. * on the board and/or ports. In this driver it is mostly used for stats
  2211. * collection.
  2212. */
  2213. static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
  2214. {
  2215. int brdnr, rc;
  2216. void __user *argp = (void __user *)arg;
  2217. pr_debug("stl_memioctl(ip=%p,fp=%p,cmd=%x,arg=%lx)\n", ip, fp, cmd,arg);
  2218. brdnr = iminor(ip);
  2219. if (brdnr >= STL_MAXBRDS)
  2220. return -ENODEV;
  2221. rc = 0;
  2222. switch (cmd) {
  2223. case COM_GETPORTSTATS:
  2224. rc = stl_getportstats(NULL, argp);
  2225. break;
  2226. case COM_CLRPORTSTATS:
  2227. rc = stl_clrportstats(NULL, argp);
  2228. break;
  2229. case COM_GETBRDSTATS:
  2230. rc = stl_getbrdstats(argp);
  2231. break;
  2232. case COM_READPORT:
  2233. rc = stl_getportstruct(argp);
  2234. break;
  2235. case COM_READBOARD:
  2236. rc = stl_getbrdstruct(argp);
  2237. break;
  2238. default:
  2239. rc = -ENOIOCTLCMD;
  2240. break;
  2241. }
  2242. return rc;
  2243. }
  2244. static const struct tty_operations stl_ops = {
  2245. .open = stl_open,
  2246. .close = stl_close,
  2247. .write = stl_write,
  2248. .put_char = stl_putchar,
  2249. .flush_chars = stl_flushchars,
  2250. .write_room = stl_writeroom,
  2251. .chars_in_buffer = stl_charsinbuffer,
  2252. .ioctl = stl_ioctl,
  2253. .set_termios = stl_settermios,
  2254. .throttle = stl_throttle,
  2255. .unthrottle = stl_unthrottle,
  2256. .stop = stl_stop,
  2257. .start = stl_start,
  2258. .hangup = stl_hangup,
  2259. .flush_buffer = stl_flushbuffer,
  2260. .break_ctl = stl_breakctl,
  2261. .wait_until_sent = stl_waituntilsent,
  2262. .send_xchar = stl_sendxchar,
  2263. .read_proc = stl_readproc,
  2264. .tiocmget = stl_tiocmget,
  2265. .tiocmset = stl_tiocmset,
  2266. };
  2267. /*****************************************************************************/
  2268. /* CD1400 HARDWARE FUNCTIONS */
  2269. /*****************************************************************************/
  2270. /*
  2271. * These functions get/set/update the registers of the cd1400 UARTs.
  2272. * Access to the cd1400 registers is via an address/data io port pair.
  2273. * (Maybe should make this inline...)
  2274. */
  2275. static int stl_cd1400getreg(struct stlport *portp, int regnr)
  2276. {
  2277. outb((regnr + portp->uartaddr), portp->ioaddr);
  2278. return inb(portp->ioaddr + EREG_DATA);
  2279. }
  2280. static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
  2281. {
  2282. outb(regnr + portp->uartaddr, portp->ioaddr);
  2283. outb(value, portp->ioaddr + EREG_DATA);
  2284. }
  2285. static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
  2286. {
  2287. outb(regnr + portp->uartaddr, portp->ioaddr);
  2288. if (inb(portp->ioaddr + EREG_DATA) != value) {
  2289. outb(value, portp->ioaddr + EREG_DATA);
  2290. return 1;
  2291. }
  2292. return 0;
  2293. }
  2294. /*****************************************************************************/
  2295. /*
  2296. * Inbitialize the UARTs in a panel. We don't care what sort of board
  2297. * these ports are on - since the port io registers are almost
  2298. * identical when dealing with ports.
  2299. */
  2300. static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
  2301. {
  2302. unsigned int gfrcr;
  2303. int chipmask, i, j;
  2304. int nrchips, uartaddr, ioaddr;
  2305. unsigned long flags;
  2306. pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
  2307. spin_lock_irqsave(&brd_lock, flags);
  2308. BRDENABLE(panelp->brdnr, panelp->pagenr);
  2309. /*
  2310. * Check that each chip is present and started up OK.
  2311. */
  2312. chipmask = 0;
  2313. nrchips = panelp->nrports / CD1400_PORTS;
  2314. for (i = 0; i < nrchips; i++) {
  2315. if (brdp->brdtype == BRD_ECHPCI) {
  2316. outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
  2317. ioaddr = panelp->iobase;
  2318. } else
  2319. ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
  2320. uartaddr = (i & 0x01) ? 0x080 : 0;
  2321. outb((GFRCR + uartaddr), ioaddr);
  2322. outb(0, (ioaddr + EREG_DATA));
  2323. outb((CCR + uartaddr), ioaddr);
  2324. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  2325. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  2326. outb((GFRCR + uartaddr), ioaddr);
  2327. for (j = 0; j < CCR_MAXWAIT; j++)
  2328. if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
  2329. break;
  2330. if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
  2331. printk("STALLION: cd1400 not responding, "
  2332. "brd=%d panel=%d chip=%d\n",
  2333. panelp->brdnr, panelp->panelnr, i);
  2334. continue;
  2335. }
  2336. chipmask |= (0x1 << i);
  2337. outb((PPR + uartaddr), ioaddr);
  2338. outb(PPR_SCALAR, (ioaddr + EREG_DATA));
  2339. }
  2340. BRDDISABLE(panelp->brdnr);
  2341. spin_unlock_irqrestore(&brd_lock, flags);
  2342. return chipmask;
  2343. }
  2344. /*****************************************************************************/
  2345. /*
  2346. * Initialize hardware specific port registers.
  2347. */
  2348. static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
  2349. {
  2350. unsigned long flags;
  2351. pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
  2352. panelp, portp);
  2353. if ((brdp == NULL) || (panelp == NULL) ||
  2354. (portp == NULL))
  2355. return;
  2356. spin_lock_irqsave(&brd_lock, flags);
  2357. portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
  2358. (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
  2359. portp->uartaddr = (portp->portnr & 0x04) << 5;
  2360. portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
  2361. BRDENABLE(portp->brdnr, portp->pagenr);
  2362. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2363. stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
  2364. portp->hwid = stl_cd1400getreg(portp, GFRCR);
  2365. BRDDISABLE(portp->brdnr);
  2366. spin_unlock_irqrestore(&brd_lock, flags);
  2367. }
  2368. /*****************************************************************************/
  2369. /*
  2370. * Wait for the command register to be ready. We will poll this,
  2371. * since it won't usually take too long to be ready.
  2372. */
  2373. static void stl_cd1400ccrwait(struct stlport *portp)
  2374. {
  2375. int i;
  2376. for (i = 0; i < CCR_MAXWAIT; i++)
  2377. if (stl_cd1400getreg(portp, CCR) == 0)
  2378. return;
  2379. printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
  2380. portp->portnr, portp->panelnr, portp->brdnr);
  2381. }
  2382. /*****************************************************************************/
  2383. /*
  2384. * Set up the cd1400 registers for a port based on the termios port
  2385. * settings.
  2386. */
  2387. static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp)
  2388. {
  2389. struct stlbrd *brdp;
  2390. unsigned long flags;
  2391. unsigned int clkdiv, baudrate;
  2392. unsigned char cor1, cor2, cor3;
  2393. unsigned char cor4, cor5, ccr;
  2394. unsigned char srer, sreron, sreroff;
  2395. unsigned char mcor1, mcor2, rtpr;
  2396. unsigned char clk, div;
  2397. cor1 = 0;
  2398. cor2 = 0;
  2399. cor3 = 0;
  2400. cor4 = 0;
  2401. cor5 = 0;
  2402. ccr = 0;
  2403. rtpr = 0;
  2404. clk = 0;
  2405. div = 0;
  2406. mcor1 = 0;
  2407. mcor2 = 0;
  2408. sreron = 0;
  2409. sreroff = 0;
  2410. brdp = stl_brds[portp->brdnr];
  2411. if (brdp == NULL)
  2412. return;
  2413. /*
  2414. * Set up the RX char ignore mask with those RX error types we
  2415. * can ignore. We can get the cd1400 to help us out a little here,
  2416. * it will ignore parity errors and breaks for us.
  2417. */
  2418. portp->rxignoremsk = 0;
  2419. if (tiosp->c_iflag & IGNPAR) {
  2420. portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
  2421. cor1 |= COR1_PARIGNORE;
  2422. }
  2423. if (tiosp->c_iflag & IGNBRK) {
  2424. portp->rxignoremsk |= ST_BREAK;
  2425. cor4 |= COR4_IGNBRK;
  2426. }
  2427. portp->rxmarkmsk = ST_OVERRUN;
  2428. if (tiosp->c_iflag & (INPCK | PARMRK))
  2429. portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
  2430. if (tiosp->c_iflag & BRKINT)
  2431. portp->rxmarkmsk |= ST_BREAK;
  2432. /*
  2433. * Go through the char size, parity and stop bits and set all the
  2434. * option register appropriately.
  2435. */
  2436. switch (tiosp->c_cflag & CSIZE) {
  2437. case CS5:
  2438. cor1 |= COR1_CHL5;
  2439. break;
  2440. case CS6:
  2441. cor1 |= COR1_CHL6;
  2442. break;
  2443. case CS7:
  2444. cor1 |= COR1_CHL7;
  2445. break;
  2446. default:
  2447. cor1 |= COR1_CHL8;
  2448. break;
  2449. }
  2450. if (tiosp->c_cflag & CSTOPB)
  2451. cor1 |= COR1_STOP2;
  2452. else
  2453. cor1 |= COR1_STOP1;
  2454. if (tiosp->c_cflag & PARENB) {
  2455. if (tiosp->c_cflag & PARODD)
  2456. cor1 |= (COR1_PARENB | COR1_PARODD);
  2457. else
  2458. cor1 |= (COR1_PARENB | COR1_PAREVEN);
  2459. } else {
  2460. cor1 |= COR1_PARNONE;
  2461. }
  2462. /*
  2463. * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
  2464. * space for hardware flow control and the like. This should be set to
  2465. * VMIN. Also here we will set the RX data timeout to 10ms - this should
  2466. * really be based on VTIME.
  2467. */
  2468. cor3 |= FIFO_RXTHRESHOLD;
  2469. rtpr = 2;
  2470. /*
  2471. * Calculate the baud rate timers. For now we will just assume that
  2472. * the input and output baud are the same. Could have used a baud
  2473. * table here, but this way we can generate virtually any baud rate
  2474. * we like!
  2475. */
  2476. baudrate = tiosp->c_cflag & CBAUD;
  2477. if (baudrate & CBAUDEX) {
  2478. baudrate &= ~CBAUDEX;
  2479. if ((baudrate < 1) || (baudrate > 4))
  2480. tiosp->c_cflag &= ~CBAUDEX;
  2481. else
  2482. baudrate += 15;
  2483. }
  2484. baudrate = stl_baudrates[baudrate];
  2485. if ((tiosp->c_cflag & CBAUD) == B38400) {
  2486. if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  2487. baudrate = 57600;
  2488. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  2489. baudrate = 115200;
  2490. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  2491. baudrate = 230400;
  2492. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  2493. baudrate = 460800;
  2494. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  2495. baudrate = (portp->baud_base / portp->custom_divisor);
  2496. }
  2497. if (baudrate > STL_CD1400MAXBAUD)
  2498. baudrate = STL_CD1400MAXBAUD;
  2499. if (baudrate > 0) {
  2500. for (clk = 0; clk < CD1400_NUMCLKS; clk++) {
  2501. clkdiv = (portp->clk / stl_cd1400clkdivs[clk]) / baudrate;
  2502. if (clkdiv < 0x100)
  2503. break;
  2504. }
  2505. div = (unsigned char) clkdiv;
  2506. }
  2507. /*
  2508. * Check what form of modem signaling is required and set it up.
  2509. */
  2510. if ((tiosp->c_cflag & CLOCAL) == 0) {
  2511. mcor1 |= MCOR1_DCD;
  2512. mcor2 |= MCOR2_DCD;
  2513. sreron |= SRER_MODEM;
  2514. portp->port.flags |= ASYNC_CHECK_CD;
  2515. } else
  2516. portp->port.flags &= ~ASYNC_CHECK_CD;
  2517. /*
  2518. * Setup cd1400 enhanced modes if we can. In particular we want to
  2519. * handle as much of the flow control as possible automatically. As
  2520. * well as saving a few CPU cycles it will also greatly improve flow
  2521. * control reliability.
  2522. */
  2523. if (tiosp->c_iflag & IXON) {
  2524. cor2 |= COR2_TXIBE;
  2525. cor3 |= COR3_SCD12;
  2526. if (tiosp->c_iflag & IXANY)
  2527. cor2 |= COR2_IXM;
  2528. }
  2529. if (tiosp->c_cflag & CRTSCTS) {
  2530. cor2 |= COR2_CTSAE;
  2531. mcor1 |= FIFO_RTSTHRESHOLD;
  2532. }
  2533. /*
  2534. * All cd1400 register values calculated so go through and set
  2535. * them all up.
  2536. */
  2537. pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
  2538. portp->portnr, portp->panelnr, portp->brdnr);
  2539. pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
  2540. cor1, cor2, cor3, cor4, cor5);
  2541. pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
  2542. mcor1, mcor2, rtpr, sreron, sreroff);
  2543. pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
  2544. pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
  2545. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  2546. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  2547. spin_lock_irqsave(&brd_lock, flags);
  2548. BRDENABLE(portp->brdnr, portp->pagenr);
  2549. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
  2550. srer = stl_cd1400getreg(portp, SRER);
  2551. stl_cd1400setreg(portp, SRER, 0);
  2552. if (stl_cd1400updatereg(portp, COR1, cor1))
  2553. ccr = 1;
  2554. if (stl_cd1400updatereg(portp, COR2, cor2))
  2555. ccr = 1;
  2556. if (stl_cd1400updatereg(portp, COR3, cor3))
  2557. ccr = 1;
  2558. if (ccr) {
  2559. stl_cd1400ccrwait(portp);
  2560. stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
  2561. }
  2562. stl_cd1400setreg(portp, COR4, cor4);
  2563. stl_cd1400setreg(portp, COR5, cor5);
  2564. stl_cd1400setreg(portp, MCOR1, mcor1);
  2565. stl_cd1400setreg(portp, MCOR2, mcor2);
  2566. if (baudrate > 0) {
  2567. stl_cd1400setreg(portp, TCOR, clk);
  2568. stl_cd1400setreg(portp, TBPR, div);
  2569. stl_cd1400setreg(portp, RCOR, clk);
  2570. stl_cd1400setreg(portp, RBPR, div);
  2571. }
  2572. stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
  2573. stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
  2574. stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
  2575. stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
  2576. stl_cd1400setreg(portp, RTPR, rtpr);
  2577. mcor1 = stl_cd1400getreg(portp, MSVR1);
  2578. if (mcor1 & MSVR1_DCD)
  2579. portp->sigs |= TIOCM_CD;
  2580. else
  2581. portp->sigs &= ~TIOCM_CD;
  2582. stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
  2583. BRDDISABLE(portp->brdnr);
  2584. spin_unlock_irqrestore(&brd_lock, flags);
  2585. }
  2586. /*****************************************************************************/
  2587. /*
  2588. * Set the state of the DTR and RTS signals.
  2589. */
  2590. static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts)
  2591. {
  2592. unsigned char msvr1, msvr2;
  2593. unsigned long flags;
  2594. pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
  2595. portp, dtr, rts);
  2596. msvr1 = 0;
  2597. msvr2 = 0;
  2598. if (dtr > 0)
  2599. msvr1 = MSVR1_DTR;
  2600. if (rts > 0)
  2601. msvr2 = MSVR2_RTS;
  2602. spin_lock_irqsave(&brd_lock, flags);
  2603. BRDENABLE(portp->brdnr, portp->pagenr);
  2604. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2605. if (rts >= 0)
  2606. stl_cd1400setreg(portp, MSVR2, msvr2);
  2607. if (dtr >= 0)
  2608. stl_cd1400setreg(portp, MSVR1, msvr1);
  2609. BRDDISABLE(portp->brdnr);
  2610. spin_unlock_irqrestore(&brd_lock, flags);
  2611. }
  2612. /*****************************************************************************/
  2613. /*
  2614. * Return the state of the signals.
  2615. */
  2616. static int stl_cd1400getsignals(struct stlport *portp)
  2617. {
  2618. unsigned char msvr1, msvr2;
  2619. unsigned long flags;
  2620. int sigs;
  2621. pr_debug("stl_cd1400getsignals(portp=%p)\n", portp);
  2622. spin_lock_irqsave(&brd_lock, flags);
  2623. BRDENABLE(portp->brdnr, portp->pagenr);
  2624. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2625. msvr1 = stl_cd1400getreg(portp, MSVR1);
  2626. msvr2 = stl_cd1400getreg(portp, MSVR2);
  2627. BRDDISABLE(portp->brdnr);
  2628. spin_unlock_irqrestore(&brd_lock, flags);
  2629. sigs = 0;
  2630. sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
  2631. sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
  2632. sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
  2633. sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
  2634. #if 0
  2635. sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
  2636. sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
  2637. #else
  2638. sigs |= TIOCM_DSR;
  2639. #endif
  2640. return sigs;
  2641. }
  2642. /*****************************************************************************/
  2643. /*
  2644. * Enable/Disable the Transmitter and/or Receiver.
  2645. */
  2646. static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx)
  2647. {
  2648. unsigned char ccr;
  2649. unsigned long flags;
  2650. pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
  2651. ccr = 0;
  2652. if (tx == 0)
  2653. ccr |= CCR_TXDISABLE;
  2654. else if (tx > 0)
  2655. ccr |= CCR_TXENABLE;
  2656. if (rx == 0)
  2657. ccr |= CCR_RXDISABLE;
  2658. else if (rx > 0)
  2659. ccr |= CCR_RXENABLE;
  2660. spin_lock_irqsave(&brd_lock, flags);
  2661. BRDENABLE(portp->brdnr, portp->pagenr);
  2662. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2663. stl_cd1400ccrwait(portp);
  2664. stl_cd1400setreg(portp, CCR, ccr);
  2665. stl_cd1400ccrwait(portp);
  2666. BRDDISABLE(portp->brdnr);
  2667. spin_unlock_irqrestore(&brd_lock, flags);
  2668. }
  2669. /*****************************************************************************/
  2670. /*
  2671. * Start/stop the Transmitter and/or Receiver.
  2672. */
  2673. static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx)
  2674. {
  2675. unsigned char sreron, sreroff;
  2676. unsigned long flags;
  2677. pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
  2678. sreron = 0;
  2679. sreroff = 0;
  2680. if (tx == 0)
  2681. sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
  2682. else if (tx == 1)
  2683. sreron |= SRER_TXDATA;
  2684. else if (tx >= 2)
  2685. sreron |= SRER_TXEMPTY;
  2686. if (rx == 0)
  2687. sreroff |= SRER_RXDATA;
  2688. else if (rx > 0)
  2689. sreron |= SRER_RXDATA;
  2690. spin_lock_irqsave(&brd_lock, flags);
  2691. BRDENABLE(portp->brdnr, portp->pagenr);
  2692. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2693. stl_cd1400setreg(portp, SRER,
  2694. ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
  2695. BRDDISABLE(portp->brdnr);
  2696. if (tx > 0)
  2697. set_bit(ASYI_TXBUSY, &portp->istate);
  2698. spin_unlock_irqrestore(&brd_lock, flags);
  2699. }
  2700. /*****************************************************************************/
  2701. /*
  2702. * Disable all interrupts from this port.
  2703. */
  2704. static void stl_cd1400disableintrs(struct stlport *portp)
  2705. {
  2706. unsigned long flags;
  2707. pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp);
  2708. spin_lock_irqsave(&brd_lock, flags);
  2709. BRDENABLE(portp->brdnr, portp->pagenr);
  2710. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2711. stl_cd1400setreg(portp, SRER, 0);
  2712. BRDDISABLE(portp->brdnr);
  2713. spin_unlock_irqrestore(&brd_lock, flags);
  2714. }
  2715. /*****************************************************************************/
  2716. static void stl_cd1400sendbreak(struct stlport *portp, int len)
  2717. {
  2718. unsigned long flags;
  2719. pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len);
  2720. spin_lock_irqsave(&brd_lock, flags);
  2721. BRDENABLE(portp->brdnr, portp->pagenr);
  2722. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2723. stl_cd1400setreg(portp, SRER,
  2724. ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
  2725. SRER_TXEMPTY));
  2726. BRDDISABLE(portp->brdnr);
  2727. portp->brklen = len;
  2728. if (len == 1)
  2729. portp->stats.txbreaks++;
  2730. spin_unlock_irqrestore(&brd_lock, flags);
  2731. }
  2732. /*****************************************************************************/
  2733. /*
  2734. * Take flow control actions...
  2735. */
  2736. static void stl_cd1400flowctrl(struct stlport *portp, int state)
  2737. {
  2738. struct tty_struct *tty;
  2739. unsigned long flags;
  2740. pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state);
  2741. if (portp == NULL)
  2742. return;
  2743. tty = portp->port.tty;
  2744. if (tty == NULL)
  2745. return;
  2746. spin_lock_irqsave(&brd_lock, flags);
  2747. BRDENABLE(portp->brdnr, portp->pagenr);
  2748. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2749. if (state) {
  2750. if (tty->termios->c_iflag & IXOFF) {
  2751. stl_cd1400ccrwait(portp);
  2752. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  2753. portp->stats.rxxon++;
  2754. stl_cd1400ccrwait(portp);
  2755. }
  2756. /*
  2757. * Question: should we return RTS to what it was before? It may
  2758. * have been set by an ioctl... Suppose not, since if you have
  2759. * hardware flow control set then it is pretty silly to go and
  2760. * set the RTS line by hand.
  2761. */
  2762. if (tty->termios->c_cflag & CRTSCTS) {
  2763. stl_cd1400setreg(portp, MCOR1,
  2764. (stl_cd1400getreg(portp, MCOR1) |
  2765. FIFO_RTSTHRESHOLD));
  2766. stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
  2767. portp->stats.rxrtson++;
  2768. }
  2769. } else {
  2770. if (tty->termios->c_iflag & IXOFF) {
  2771. stl_cd1400ccrwait(portp);
  2772. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  2773. portp->stats.rxxoff++;
  2774. stl_cd1400ccrwait(portp);
  2775. }
  2776. if (tty->termios->c_cflag & CRTSCTS) {
  2777. stl_cd1400setreg(portp, MCOR1,
  2778. (stl_cd1400getreg(portp, MCOR1) & 0xf0));
  2779. stl_cd1400setreg(portp, MSVR2, 0);
  2780. portp->stats.rxrtsoff++;
  2781. }
  2782. }
  2783. BRDDISABLE(portp->brdnr);
  2784. spin_unlock_irqrestore(&brd_lock, flags);
  2785. }
  2786. /*****************************************************************************/
  2787. /*
  2788. * Send a flow control character...
  2789. */
  2790. static void stl_cd1400sendflow(struct stlport *portp, int state)
  2791. {
  2792. struct tty_struct *tty;
  2793. unsigned long flags;
  2794. pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state);
  2795. if (portp == NULL)
  2796. return;
  2797. tty = portp->port.tty;
  2798. if (tty == NULL)
  2799. return;
  2800. spin_lock_irqsave(&brd_lock, flags);
  2801. BRDENABLE(portp->brdnr, portp->pagenr);
  2802. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2803. if (state) {
  2804. stl_cd1400ccrwait(portp);
  2805. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  2806. portp->stats.rxxon++;
  2807. stl_cd1400ccrwait(portp);
  2808. } else {
  2809. stl_cd1400ccrwait(portp);
  2810. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  2811. portp->stats.rxxoff++;
  2812. stl_cd1400ccrwait(portp);
  2813. }
  2814. BRDDISABLE(portp->brdnr);
  2815. spin_unlock_irqrestore(&brd_lock, flags);
  2816. }
  2817. /*****************************************************************************/
  2818. static void stl_cd1400flush(struct stlport *portp)
  2819. {
  2820. unsigned long flags;
  2821. pr_debug("stl_cd1400flush(portp=%p)\n", portp);
  2822. if (portp == NULL)
  2823. return;
  2824. spin_lock_irqsave(&brd_lock, flags);
  2825. BRDENABLE(portp->brdnr, portp->pagenr);
  2826. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2827. stl_cd1400ccrwait(portp);
  2828. stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
  2829. stl_cd1400ccrwait(portp);
  2830. portp->tx.tail = portp->tx.head;
  2831. BRDDISABLE(portp->brdnr);
  2832. spin_unlock_irqrestore(&brd_lock, flags);
  2833. }
  2834. /*****************************************************************************/
  2835. /*
  2836. * Return the current state of data flow on this port. This is only
  2837. * really interresting when determining if data has fully completed
  2838. * transmission or not... This is easy for the cd1400, it accurately
  2839. * maintains the busy port flag.
  2840. */
  2841. static int stl_cd1400datastate(struct stlport *portp)
  2842. {
  2843. pr_debug("stl_cd1400datastate(portp=%p)\n", portp);
  2844. if (portp == NULL)
  2845. return 0;
  2846. return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
  2847. }
  2848. /*****************************************************************************/
  2849. /*
  2850. * Interrupt service routine for cd1400 EasyIO boards.
  2851. */
  2852. static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase)
  2853. {
  2854. unsigned char svrtype;
  2855. pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase);
  2856. spin_lock(&brd_lock);
  2857. outb(SVRR, iobase);
  2858. svrtype = inb(iobase + EREG_DATA);
  2859. if (panelp->nrports > 4) {
  2860. outb((SVRR + 0x80), iobase);
  2861. svrtype |= inb(iobase + EREG_DATA);
  2862. }
  2863. if (svrtype & SVRR_RX)
  2864. stl_cd1400rxisr(panelp, iobase);
  2865. else if (svrtype & SVRR_TX)
  2866. stl_cd1400txisr(panelp, iobase);
  2867. else if (svrtype & SVRR_MDM)
  2868. stl_cd1400mdmisr(panelp, iobase);
  2869. spin_unlock(&brd_lock);
  2870. }
  2871. /*****************************************************************************/
  2872. /*
  2873. * Interrupt service routine for cd1400 panels.
  2874. */
  2875. static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase)
  2876. {
  2877. unsigned char svrtype;
  2878. pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase);
  2879. outb(SVRR, iobase);
  2880. svrtype = inb(iobase + EREG_DATA);
  2881. outb((SVRR + 0x80), iobase);
  2882. svrtype |= inb(iobase + EREG_DATA);
  2883. if (svrtype & SVRR_RX)
  2884. stl_cd1400rxisr(panelp, iobase);
  2885. else if (svrtype & SVRR_TX)
  2886. stl_cd1400txisr(panelp, iobase);
  2887. else if (svrtype & SVRR_MDM)
  2888. stl_cd1400mdmisr(panelp, iobase);
  2889. }
  2890. /*****************************************************************************/
  2891. /*
  2892. * Unfortunately we need to handle breaks in the TX data stream, since
  2893. * this is the only way to generate them on the cd1400.
  2894. */
  2895. static int stl_cd1400breakisr(struct stlport *portp, int ioaddr)
  2896. {
  2897. if (portp->brklen == 1) {
  2898. outb((COR2 + portp->uartaddr), ioaddr);
  2899. outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
  2900. (ioaddr + EREG_DATA));
  2901. outb((TDR + portp->uartaddr), ioaddr);
  2902. outb(ETC_CMD, (ioaddr + EREG_DATA));
  2903. outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
  2904. outb((SRER + portp->uartaddr), ioaddr);
  2905. outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
  2906. (ioaddr + EREG_DATA));
  2907. return 1;
  2908. } else if (portp->brklen > 1) {
  2909. outb((TDR + portp->uartaddr), ioaddr);
  2910. outb(ETC_CMD, (ioaddr + EREG_DATA));
  2911. outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
  2912. portp->brklen = -1;
  2913. return 1;
  2914. } else {
  2915. outb((COR2 + portp->uartaddr), ioaddr);
  2916. outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
  2917. (ioaddr + EREG_DATA));
  2918. portp->brklen = 0;
  2919. }
  2920. return 0;
  2921. }
  2922. /*****************************************************************************/
  2923. /*
  2924. * Transmit interrupt handler. This has gotta be fast! Handling TX
  2925. * chars is pretty simple, stuff as many as possible from the TX buffer
  2926. * into the cd1400 FIFO. Must also handle TX breaks here, since they
  2927. * are embedded as commands in the data stream. Oh no, had to use a goto!
  2928. * This could be optimized more, will do when I get time...
  2929. * In practice it is possible that interrupts are enabled but that the
  2930. * port has been hung up. Need to handle not having any TX buffer here,
  2931. * this is done by using the side effect that head and tail will also
  2932. * be NULL if the buffer has been freed.
  2933. */
  2934. static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
  2935. {
  2936. struct stlport *portp;
  2937. int len, stlen;
  2938. char *head, *tail;
  2939. unsigned char ioack, srer;
  2940. pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
  2941. ioack = inb(ioaddr + EREG_TXACK);
  2942. if (((ioack & panelp->ackmask) != 0) ||
  2943. ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
  2944. printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
  2945. return;
  2946. }
  2947. portp = panelp->ports[(ioack >> 3)];
  2948. /*
  2949. * Unfortunately we need to handle breaks in the data stream, since
  2950. * this is the only way to generate them on the cd1400. Do it now if
  2951. * a break is to be sent.
  2952. */
  2953. if (portp->brklen != 0)
  2954. if (stl_cd1400breakisr(portp, ioaddr))
  2955. goto stl_txalldone;
  2956. head = portp->tx.head;
  2957. tail = portp->tx.tail;
  2958. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  2959. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  2960. (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  2961. set_bit(ASYI_TXLOW, &portp->istate);
  2962. if (portp->port.tty)
  2963. tty_wakeup(portp->port.tty);
  2964. }
  2965. if (len == 0) {
  2966. outb((SRER + portp->uartaddr), ioaddr);
  2967. srer = inb(ioaddr + EREG_DATA);
  2968. if (srer & SRER_TXDATA) {
  2969. srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
  2970. } else {
  2971. srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
  2972. clear_bit(ASYI_TXBUSY, &portp->istate);
  2973. }
  2974. outb(srer, (ioaddr + EREG_DATA));
  2975. } else {
  2976. len = min(len, CD1400_TXFIFOSIZE);
  2977. portp->stats.txtotal += len;
  2978. stlen = min_t(unsigned int, len,
  2979. (portp->tx.buf + STL_TXBUFSIZE) - tail);
  2980. outb((TDR + portp->uartaddr), ioaddr);
  2981. outsb((ioaddr + EREG_DATA), tail, stlen);
  2982. len -= stlen;
  2983. tail += stlen;
  2984. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  2985. tail = portp->tx.buf;
  2986. if (len > 0) {
  2987. outsb((ioaddr + EREG_DATA), tail, len);
  2988. tail += len;
  2989. }
  2990. portp->tx.tail = tail;
  2991. }
  2992. stl_txalldone:
  2993. outb((EOSRR + portp->uartaddr), ioaddr);
  2994. outb(0, (ioaddr + EREG_DATA));
  2995. }
  2996. /*****************************************************************************/
  2997. /*
  2998. * Receive character interrupt handler. Determine if we have good chars
  2999. * or bad chars and then process appropriately. Good chars are easy
  3000. * just shove the lot into the RX buffer and set all status byte to 0.
  3001. * If a bad RX char then process as required. This routine needs to be
  3002. * fast! In practice it is possible that we get an interrupt on a port
  3003. * that is closed. This can happen on hangups - since they completely
  3004. * shutdown a port not in user context. Need to handle this case.
  3005. */
  3006. static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
  3007. {
  3008. struct stlport *portp;
  3009. struct tty_struct *tty;
  3010. unsigned int ioack, len, buflen;
  3011. unsigned char status;
  3012. char ch;
  3013. pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
  3014. ioack = inb(ioaddr + EREG_RXACK);
  3015. if ((ioack & panelp->ackmask) != 0) {
  3016. printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
  3017. return;
  3018. }
  3019. portp = panelp->ports[(ioack >> 3)];
  3020. tty = portp->port.tty;
  3021. if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
  3022. outb((RDCR + portp->uartaddr), ioaddr);
  3023. len = inb(ioaddr + EREG_DATA);
  3024. if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
  3025. len = min_t(unsigned int, len, sizeof(stl_unwanted));
  3026. outb((RDSR + portp->uartaddr), ioaddr);
  3027. insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
  3028. portp->stats.rxlost += len;
  3029. portp->stats.rxtotal += len;
  3030. } else {
  3031. len = min(len, buflen);
  3032. if (len > 0) {
  3033. unsigned char *ptr;
  3034. outb((RDSR + portp->uartaddr), ioaddr);
  3035. tty_prepare_flip_string(tty, &ptr, len);
  3036. insb((ioaddr + EREG_DATA), ptr, len);
  3037. tty_schedule_flip(tty);
  3038. portp->stats.rxtotal += len;
  3039. }
  3040. }
  3041. } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
  3042. outb((RDSR + portp->uartaddr), ioaddr);
  3043. status = inb(ioaddr + EREG_DATA);
  3044. ch = inb(ioaddr + EREG_DATA);
  3045. if (status & ST_PARITY)
  3046. portp->stats.rxparity++;
  3047. if (status & ST_FRAMING)
  3048. portp->stats.rxframing++;
  3049. if (status & ST_OVERRUN)
  3050. portp->stats.rxoverrun++;
  3051. if (status & ST_BREAK)
  3052. portp->stats.rxbreaks++;
  3053. if (status & ST_SCHARMASK) {
  3054. if ((status & ST_SCHARMASK) == ST_SCHAR1)
  3055. portp->stats.txxon++;
  3056. if ((status & ST_SCHARMASK) == ST_SCHAR2)
  3057. portp->stats.txxoff++;
  3058. goto stl_rxalldone;
  3059. }
  3060. if (tty != NULL && (portp->rxignoremsk & status) == 0) {
  3061. if (portp->rxmarkmsk & status) {
  3062. if (status & ST_BREAK) {
  3063. status = TTY_BREAK;
  3064. if (portp->port.flags & ASYNC_SAK) {
  3065. do_SAK(tty);
  3066. BRDENABLE(portp->brdnr, portp->pagenr);
  3067. }
  3068. } else if (status & ST_PARITY)
  3069. status = TTY_PARITY;
  3070. else if (status & ST_FRAMING)
  3071. status = TTY_FRAME;
  3072. else if(status & ST_OVERRUN)
  3073. status = TTY_OVERRUN;
  3074. else
  3075. status = 0;
  3076. } else
  3077. status = 0;
  3078. tty_insert_flip_char(tty, ch, status);
  3079. tty_schedule_flip(tty);
  3080. }
  3081. } else {
  3082. printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
  3083. return;
  3084. }
  3085. stl_rxalldone:
  3086. outb((EOSRR + portp->uartaddr), ioaddr);
  3087. outb(0, (ioaddr + EREG_DATA));
  3088. }
  3089. /*****************************************************************************/
  3090. /*
  3091. * Modem interrupt handler. The is called when the modem signal line
  3092. * (DCD) has changed state. Leave most of the work to the off-level
  3093. * processing routine.
  3094. */
  3095. static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr)
  3096. {
  3097. struct stlport *portp;
  3098. unsigned int ioack;
  3099. unsigned char misr;
  3100. pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp);
  3101. ioack = inb(ioaddr + EREG_MDACK);
  3102. if (((ioack & panelp->ackmask) != 0) ||
  3103. ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
  3104. printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
  3105. return;
  3106. }
  3107. portp = panelp->ports[(ioack >> 3)];
  3108. outb((MISR + portp->uartaddr), ioaddr);
  3109. misr = inb(ioaddr + EREG_DATA);
  3110. if (misr & MISR_DCD) {
  3111. stl_cd_change(portp);
  3112. portp->stats.modem++;
  3113. }
  3114. outb((EOSRR + portp->uartaddr), ioaddr);
  3115. outb(0, (ioaddr + EREG_DATA));
  3116. }
  3117. /*****************************************************************************/
  3118. /* SC26198 HARDWARE FUNCTIONS */
  3119. /*****************************************************************************/
  3120. /*
  3121. * These functions get/set/update the registers of the sc26198 UARTs.
  3122. * Access to the sc26198 registers is via an address/data io port pair.
  3123. * (Maybe should make this inline...)
  3124. */
  3125. static int stl_sc26198getreg(struct stlport *portp, int regnr)
  3126. {
  3127. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3128. return inb(portp->ioaddr + XP_DATA);
  3129. }
  3130. static void stl_sc26198setreg(struct stlport *portp, int regnr, int value)
  3131. {
  3132. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3133. outb(value, (portp->ioaddr + XP_DATA));
  3134. }
  3135. static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value)
  3136. {
  3137. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3138. if (inb(portp->ioaddr + XP_DATA) != value) {
  3139. outb(value, (portp->ioaddr + XP_DATA));
  3140. return 1;
  3141. }
  3142. return 0;
  3143. }
  3144. /*****************************************************************************/
  3145. /*
  3146. * Functions to get and set the sc26198 global registers.
  3147. */
  3148. static int stl_sc26198getglobreg(struct stlport *portp, int regnr)
  3149. {
  3150. outb(regnr, (portp->ioaddr + XP_ADDR));
  3151. return inb(portp->ioaddr + XP_DATA);
  3152. }
  3153. #if 0
  3154. static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value)
  3155. {
  3156. outb(regnr, (portp->ioaddr + XP_ADDR));
  3157. outb(value, (portp->ioaddr + XP_DATA));
  3158. }
  3159. #endif
  3160. /*****************************************************************************/
  3161. /*
  3162. * Inbitialize the UARTs in a panel. We don't care what sort of board
  3163. * these ports are on - since the port io registers are almost
  3164. * identical when dealing with ports.
  3165. */
  3166. static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
  3167. {
  3168. int chipmask, i;
  3169. int nrchips, ioaddr;
  3170. pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
  3171. BRDENABLE(panelp->brdnr, panelp->pagenr);
  3172. /*
  3173. * Check that each chip is present and started up OK.
  3174. */
  3175. chipmask = 0;
  3176. nrchips = (panelp->nrports + 4) / SC26198_PORTS;
  3177. if (brdp->brdtype == BRD_ECHPCI)
  3178. outb(panelp->pagenr, brdp->ioctrl);
  3179. for (i = 0; i < nrchips; i++) {
  3180. ioaddr = panelp->iobase + (i * 4);
  3181. outb(SCCR, (ioaddr + XP_ADDR));
  3182. outb(CR_RESETALL, (ioaddr + XP_DATA));
  3183. outb(TSTR, (ioaddr + XP_ADDR));
  3184. if (inb(ioaddr + XP_DATA) != 0) {
  3185. printk("STALLION: sc26198 not responding, "
  3186. "brd=%d panel=%d chip=%d\n",
  3187. panelp->brdnr, panelp->panelnr, i);
  3188. continue;
  3189. }
  3190. chipmask |= (0x1 << i);
  3191. outb(GCCR, (ioaddr + XP_ADDR));
  3192. outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
  3193. outb(WDTRCR, (ioaddr + XP_ADDR));
  3194. outb(0xff, (ioaddr + XP_DATA));
  3195. }
  3196. BRDDISABLE(panelp->brdnr);
  3197. return chipmask;
  3198. }
  3199. /*****************************************************************************/
  3200. /*
  3201. * Initialize hardware specific port registers.
  3202. */
  3203. static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
  3204. {
  3205. pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
  3206. panelp, portp);
  3207. if ((brdp == NULL) || (panelp == NULL) ||
  3208. (portp == NULL))
  3209. return;
  3210. portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
  3211. portp->uartaddr = (portp->portnr & 0x07) << 4;
  3212. portp->pagenr = panelp->pagenr;
  3213. portp->hwid = 0x1;
  3214. BRDENABLE(portp->brdnr, portp->pagenr);
  3215. stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
  3216. BRDDISABLE(portp->brdnr);
  3217. }
  3218. /*****************************************************************************/
  3219. /*
  3220. * Set up the sc26198 registers for a port based on the termios port
  3221. * settings.
  3222. */
  3223. static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp)
  3224. {
  3225. struct stlbrd *brdp;
  3226. unsigned long flags;
  3227. unsigned int baudrate;
  3228. unsigned char mr0, mr1, mr2, clk;
  3229. unsigned char imron, imroff, iopr, ipr;
  3230. mr0 = 0;
  3231. mr1 = 0;
  3232. mr2 = 0;
  3233. clk = 0;
  3234. iopr = 0;
  3235. imron = 0;
  3236. imroff = 0;
  3237. brdp = stl_brds[portp->brdnr];
  3238. if (brdp == NULL)
  3239. return;
  3240. /*
  3241. * Set up the RX char ignore mask with those RX error types we
  3242. * can ignore.
  3243. */
  3244. portp->rxignoremsk = 0;
  3245. if (tiosp->c_iflag & IGNPAR)
  3246. portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
  3247. SR_RXOVERRUN);
  3248. if (tiosp->c_iflag & IGNBRK)
  3249. portp->rxignoremsk |= SR_RXBREAK;
  3250. portp->rxmarkmsk = SR_RXOVERRUN;
  3251. if (tiosp->c_iflag & (INPCK | PARMRK))
  3252. portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
  3253. if (tiosp->c_iflag & BRKINT)
  3254. portp->rxmarkmsk |= SR_RXBREAK;
  3255. /*
  3256. * Go through the char size, parity and stop bits and set all the
  3257. * option register appropriately.
  3258. */
  3259. switch (tiosp->c_cflag & CSIZE) {
  3260. case CS5:
  3261. mr1 |= MR1_CS5;
  3262. break;
  3263. case CS6:
  3264. mr1 |= MR1_CS6;
  3265. break;
  3266. case CS7:
  3267. mr1 |= MR1_CS7;
  3268. break;
  3269. default:
  3270. mr1 |= MR1_CS8;
  3271. break;
  3272. }
  3273. if (tiosp->c_cflag & CSTOPB)
  3274. mr2 |= MR2_STOP2;
  3275. else
  3276. mr2 |= MR2_STOP1;
  3277. if (tiosp->c_cflag & PARENB) {
  3278. if (tiosp->c_cflag & PARODD)
  3279. mr1 |= (MR1_PARENB | MR1_PARODD);
  3280. else
  3281. mr1 |= (MR1_PARENB | MR1_PAREVEN);
  3282. } else
  3283. mr1 |= MR1_PARNONE;
  3284. mr1 |= MR1_ERRBLOCK;
  3285. /*
  3286. * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
  3287. * space for hardware flow control and the like. This should be set to
  3288. * VMIN.
  3289. */
  3290. mr2 |= MR2_RXFIFOHALF;
  3291. /*
  3292. * Calculate the baud rate timers. For now we will just assume that
  3293. * the input and output baud are the same. The sc26198 has a fixed
  3294. * baud rate table, so only discrete baud rates possible.
  3295. */
  3296. baudrate = tiosp->c_cflag & CBAUD;
  3297. if (baudrate & CBAUDEX) {
  3298. baudrate &= ~CBAUDEX;
  3299. if ((baudrate < 1) || (baudrate > 4))
  3300. tiosp->c_cflag &= ~CBAUDEX;
  3301. else
  3302. baudrate += 15;
  3303. }
  3304. baudrate = stl_baudrates[baudrate];
  3305. if ((tiosp->c_cflag & CBAUD) == B38400) {
  3306. if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  3307. baudrate = 57600;
  3308. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  3309. baudrate = 115200;
  3310. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  3311. baudrate = 230400;
  3312. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  3313. baudrate = 460800;
  3314. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  3315. baudrate = (portp->baud_base / portp->custom_divisor);
  3316. }
  3317. if (baudrate > STL_SC26198MAXBAUD)
  3318. baudrate = STL_SC26198MAXBAUD;
  3319. if (baudrate > 0)
  3320. for (clk = 0; clk < SC26198_NRBAUDS; clk++)
  3321. if (baudrate <= sc26198_baudtable[clk])
  3322. break;
  3323. /*
  3324. * Check what form of modem signaling is required and set it up.
  3325. */
  3326. if (tiosp->c_cflag & CLOCAL) {
  3327. portp->port.flags &= ~ASYNC_CHECK_CD;
  3328. } else {
  3329. iopr |= IOPR_DCDCOS;
  3330. imron |= IR_IOPORT;
  3331. portp->port.flags |= ASYNC_CHECK_CD;
  3332. }
  3333. /*
  3334. * Setup sc26198 enhanced modes if we can. In particular we want to
  3335. * handle as much of the flow control as possible automatically. As
  3336. * well as saving a few CPU cycles it will also greatly improve flow
  3337. * control reliability.
  3338. */
  3339. if (tiosp->c_iflag & IXON) {
  3340. mr0 |= MR0_SWFTX | MR0_SWFT;
  3341. imron |= IR_XONXOFF;
  3342. } else
  3343. imroff |= IR_XONXOFF;
  3344. if (tiosp->c_iflag & IXOFF)
  3345. mr0 |= MR0_SWFRX;
  3346. if (tiosp->c_cflag & CRTSCTS) {
  3347. mr2 |= MR2_AUTOCTS;
  3348. mr1 |= MR1_AUTORTS;
  3349. }
  3350. /*
  3351. * All sc26198 register values calculated so go through and set
  3352. * them all up.
  3353. */
  3354. pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
  3355. portp->portnr, portp->panelnr, portp->brdnr);
  3356. pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
  3357. pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
  3358. pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
  3359. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  3360. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  3361. spin_lock_irqsave(&brd_lock, flags);
  3362. BRDENABLE(portp->brdnr, portp->pagenr);
  3363. stl_sc26198setreg(portp, IMR, 0);
  3364. stl_sc26198updatereg(portp, MR0, mr0);
  3365. stl_sc26198updatereg(portp, MR1, mr1);
  3366. stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
  3367. stl_sc26198updatereg(portp, MR2, mr2);
  3368. stl_sc26198updatereg(portp, IOPIOR,
  3369. ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
  3370. if (baudrate > 0) {
  3371. stl_sc26198setreg(portp, TXCSR, clk);
  3372. stl_sc26198setreg(portp, RXCSR, clk);
  3373. }
  3374. stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
  3375. stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
  3376. ipr = stl_sc26198getreg(portp, IPR);
  3377. if (ipr & IPR_DCD)
  3378. portp->sigs &= ~TIOCM_CD;
  3379. else
  3380. portp->sigs |= TIOCM_CD;
  3381. portp->imr = (portp->imr & ~imroff) | imron;
  3382. stl_sc26198setreg(portp, IMR, portp->imr);
  3383. BRDDISABLE(portp->brdnr);
  3384. spin_unlock_irqrestore(&brd_lock, flags);
  3385. }
  3386. /*****************************************************************************/
  3387. /*
  3388. * Set the state of the DTR and RTS signals.
  3389. */
  3390. static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts)
  3391. {
  3392. unsigned char iopioron, iopioroff;
  3393. unsigned long flags;
  3394. pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp,
  3395. dtr, rts);
  3396. iopioron = 0;
  3397. iopioroff = 0;
  3398. if (dtr == 0)
  3399. iopioroff |= IPR_DTR;
  3400. else if (dtr > 0)
  3401. iopioron |= IPR_DTR;
  3402. if (rts == 0)
  3403. iopioroff |= IPR_RTS;
  3404. else if (rts > 0)
  3405. iopioron |= IPR_RTS;
  3406. spin_lock_irqsave(&brd_lock, flags);
  3407. BRDENABLE(portp->brdnr, portp->pagenr);
  3408. stl_sc26198setreg(portp, IOPIOR,
  3409. ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
  3410. BRDDISABLE(portp->brdnr);
  3411. spin_unlock_irqrestore(&brd_lock, flags);
  3412. }
  3413. /*****************************************************************************/
  3414. /*
  3415. * Return the state of the signals.
  3416. */
  3417. static int stl_sc26198getsignals(struct stlport *portp)
  3418. {
  3419. unsigned char ipr;
  3420. unsigned long flags;
  3421. int sigs;
  3422. pr_debug("stl_sc26198getsignals(portp=%p)\n", portp);
  3423. spin_lock_irqsave(&brd_lock, flags);
  3424. BRDENABLE(portp->brdnr, portp->pagenr);
  3425. ipr = stl_sc26198getreg(portp, IPR);
  3426. BRDDISABLE(portp->brdnr);
  3427. spin_unlock_irqrestore(&brd_lock, flags);
  3428. sigs = 0;
  3429. sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
  3430. sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
  3431. sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
  3432. sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
  3433. sigs |= TIOCM_DSR;
  3434. return sigs;
  3435. }
  3436. /*****************************************************************************/
  3437. /*
  3438. * Enable/Disable the Transmitter and/or Receiver.
  3439. */
  3440. static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx)
  3441. {
  3442. unsigned char ccr;
  3443. unsigned long flags;
  3444. pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx);
  3445. ccr = portp->crenable;
  3446. if (tx == 0)
  3447. ccr &= ~CR_TXENABLE;
  3448. else if (tx > 0)
  3449. ccr |= CR_TXENABLE;
  3450. if (rx == 0)
  3451. ccr &= ~CR_RXENABLE;
  3452. else if (rx > 0)
  3453. ccr |= CR_RXENABLE;
  3454. spin_lock_irqsave(&brd_lock, flags);
  3455. BRDENABLE(portp->brdnr, portp->pagenr);
  3456. stl_sc26198setreg(portp, SCCR, ccr);
  3457. BRDDISABLE(portp->brdnr);
  3458. portp->crenable = ccr;
  3459. spin_unlock_irqrestore(&brd_lock, flags);
  3460. }
  3461. /*****************************************************************************/
  3462. /*
  3463. * Start/stop the Transmitter and/or Receiver.
  3464. */
  3465. static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx)
  3466. {
  3467. unsigned char imr;
  3468. unsigned long flags;
  3469. pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
  3470. imr = portp->imr;
  3471. if (tx == 0)
  3472. imr &= ~IR_TXRDY;
  3473. else if (tx == 1)
  3474. imr |= IR_TXRDY;
  3475. if (rx == 0)
  3476. imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
  3477. else if (rx > 0)
  3478. imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
  3479. spin_lock_irqsave(&brd_lock, flags);
  3480. BRDENABLE(portp->brdnr, portp->pagenr);
  3481. stl_sc26198setreg(portp, IMR, imr);
  3482. BRDDISABLE(portp->brdnr);
  3483. portp->imr = imr;
  3484. if (tx > 0)
  3485. set_bit(ASYI_TXBUSY, &portp->istate);
  3486. spin_unlock_irqrestore(&brd_lock, flags);
  3487. }
  3488. /*****************************************************************************/
  3489. /*
  3490. * Disable all interrupts from this port.
  3491. */
  3492. static void stl_sc26198disableintrs(struct stlport *portp)
  3493. {
  3494. unsigned long flags;
  3495. pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp);
  3496. spin_lock_irqsave(&brd_lock, flags);
  3497. BRDENABLE(portp->brdnr, portp->pagenr);
  3498. portp->imr = 0;
  3499. stl_sc26198setreg(portp, IMR, 0);
  3500. BRDDISABLE(portp->brdnr);
  3501. spin_unlock_irqrestore(&brd_lock, flags);
  3502. }
  3503. /*****************************************************************************/
  3504. static void stl_sc26198sendbreak(struct stlport *portp, int len)
  3505. {
  3506. unsigned long flags;
  3507. pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len);
  3508. spin_lock_irqsave(&brd_lock, flags);
  3509. BRDENABLE(portp->brdnr, portp->pagenr);
  3510. if (len == 1) {
  3511. stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
  3512. portp->stats.txbreaks++;
  3513. } else
  3514. stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
  3515. BRDDISABLE(portp->brdnr);
  3516. spin_unlock_irqrestore(&brd_lock, flags);
  3517. }
  3518. /*****************************************************************************/
  3519. /*
  3520. * Take flow control actions...
  3521. */
  3522. static void stl_sc26198flowctrl(struct stlport *portp, int state)
  3523. {
  3524. struct tty_struct *tty;
  3525. unsigned long flags;
  3526. unsigned char mr0;
  3527. pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state);
  3528. if (portp == NULL)
  3529. return;
  3530. tty = portp->port.tty;
  3531. if (tty == NULL)
  3532. return;
  3533. spin_lock_irqsave(&brd_lock, flags);
  3534. BRDENABLE(portp->brdnr, portp->pagenr);
  3535. if (state) {
  3536. if (tty->termios->c_iflag & IXOFF) {
  3537. mr0 = stl_sc26198getreg(portp, MR0);
  3538. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3539. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  3540. mr0 |= MR0_SWFRX;
  3541. portp->stats.rxxon++;
  3542. stl_sc26198wait(portp);
  3543. stl_sc26198setreg(portp, MR0, mr0);
  3544. }
  3545. /*
  3546. * Question: should we return RTS to what it was before? It may
  3547. * have been set by an ioctl... Suppose not, since if you have
  3548. * hardware flow control set then it is pretty silly to go and
  3549. * set the RTS line by hand.
  3550. */
  3551. if (tty->termios->c_cflag & CRTSCTS) {
  3552. stl_sc26198setreg(portp, MR1,
  3553. (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
  3554. stl_sc26198setreg(portp, IOPIOR,
  3555. (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
  3556. portp->stats.rxrtson++;
  3557. }
  3558. } else {
  3559. if (tty->termios->c_iflag & IXOFF) {
  3560. mr0 = stl_sc26198getreg(portp, MR0);
  3561. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3562. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  3563. mr0 &= ~MR0_SWFRX;
  3564. portp->stats.rxxoff++;
  3565. stl_sc26198wait(portp);
  3566. stl_sc26198setreg(portp, MR0, mr0);
  3567. }
  3568. if (tty->termios->c_cflag & CRTSCTS) {
  3569. stl_sc26198setreg(portp, MR1,
  3570. (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
  3571. stl_sc26198setreg(portp, IOPIOR,
  3572. (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
  3573. portp->stats.rxrtsoff++;
  3574. }
  3575. }
  3576. BRDDISABLE(portp->brdnr);
  3577. spin_unlock_irqrestore(&brd_lock, flags);
  3578. }
  3579. /*****************************************************************************/
  3580. /*
  3581. * Send a flow control character.
  3582. */
  3583. static void stl_sc26198sendflow(struct stlport *portp, int state)
  3584. {
  3585. struct tty_struct *tty;
  3586. unsigned long flags;
  3587. unsigned char mr0;
  3588. pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state);
  3589. if (portp == NULL)
  3590. return;
  3591. tty = portp->port.tty;
  3592. if (tty == NULL)
  3593. return;
  3594. spin_lock_irqsave(&brd_lock, flags);
  3595. BRDENABLE(portp->brdnr, portp->pagenr);
  3596. if (state) {
  3597. mr0 = stl_sc26198getreg(portp, MR0);
  3598. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3599. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  3600. mr0 |= MR0_SWFRX;
  3601. portp->stats.rxxon++;
  3602. stl_sc26198wait(portp);
  3603. stl_sc26198setreg(portp, MR0, mr0);
  3604. } else {
  3605. mr0 = stl_sc26198getreg(portp, MR0);
  3606. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3607. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  3608. mr0 &= ~MR0_SWFRX;
  3609. portp->stats.rxxoff++;
  3610. stl_sc26198wait(portp);
  3611. stl_sc26198setreg(portp, MR0, mr0);
  3612. }
  3613. BRDDISABLE(portp->brdnr);
  3614. spin_unlock_irqrestore(&brd_lock, flags);
  3615. }
  3616. /*****************************************************************************/
  3617. static void stl_sc26198flush(struct stlport *portp)
  3618. {
  3619. unsigned long flags;
  3620. pr_debug("stl_sc26198flush(portp=%p)\n", portp);
  3621. if (portp == NULL)
  3622. return;
  3623. spin_lock_irqsave(&brd_lock, flags);
  3624. BRDENABLE(portp->brdnr, portp->pagenr);
  3625. stl_sc26198setreg(portp, SCCR, CR_TXRESET);
  3626. stl_sc26198setreg(portp, SCCR, portp->crenable);
  3627. BRDDISABLE(portp->brdnr);
  3628. portp->tx.tail = portp->tx.head;
  3629. spin_unlock_irqrestore(&brd_lock, flags);
  3630. }
  3631. /*****************************************************************************/
  3632. /*
  3633. * Return the current state of data flow on this port. This is only
  3634. * really interresting when determining if data has fully completed
  3635. * transmission or not... The sc26198 interrupt scheme cannot
  3636. * determine when all data has actually drained, so we need to
  3637. * check the port statusy register to be sure.
  3638. */
  3639. static int stl_sc26198datastate(struct stlport *portp)
  3640. {
  3641. unsigned long flags;
  3642. unsigned char sr;
  3643. pr_debug("stl_sc26198datastate(portp=%p)\n", portp);
  3644. if (portp == NULL)
  3645. return 0;
  3646. if (test_bit(ASYI_TXBUSY, &portp->istate))
  3647. return 1;
  3648. spin_lock_irqsave(&brd_lock, flags);
  3649. BRDENABLE(portp->brdnr, portp->pagenr);
  3650. sr = stl_sc26198getreg(portp, SR);
  3651. BRDDISABLE(portp->brdnr);
  3652. spin_unlock_irqrestore(&brd_lock, flags);
  3653. return (sr & SR_TXEMPTY) ? 0 : 1;
  3654. }
  3655. /*****************************************************************************/
  3656. /*
  3657. * Delay for a small amount of time, to give the sc26198 a chance
  3658. * to process a command...
  3659. */
  3660. static void stl_sc26198wait(struct stlport *portp)
  3661. {
  3662. int i;
  3663. pr_debug("stl_sc26198wait(portp=%p)\n", portp);
  3664. if (portp == NULL)
  3665. return;
  3666. for (i = 0; i < 20; i++)
  3667. stl_sc26198getglobreg(portp, TSTR);
  3668. }
  3669. /*****************************************************************************/
  3670. /*
  3671. * If we are TX flow controlled and in IXANY mode then we may
  3672. * need to unflow control here. We gotta do this because of the
  3673. * automatic flow control modes of the sc26198.
  3674. */
  3675. static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty)
  3676. {
  3677. unsigned char mr0;
  3678. mr0 = stl_sc26198getreg(portp, MR0);
  3679. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3680. stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
  3681. stl_sc26198wait(portp);
  3682. stl_sc26198setreg(portp, MR0, mr0);
  3683. clear_bit(ASYI_TXFLOWED, &portp->istate);
  3684. }
  3685. /*****************************************************************************/
  3686. /*
  3687. * Interrupt service routine for sc26198 panels.
  3688. */
  3689. static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
  3690. {
  3691. struct stlport *portp;
  3692. unsigned int iack;
  3693. spin_lock(&brd_lock);
  3694. /*
  3695. * Work around bug in sc26198 chip... Cannot have A6 address
  3696. * line of UART high, else iack will be returned as 0.
  3697. */
  3698. outb(0, (iobase + 1));
  3699. iack = inb(iobase + XP_IACK);
  3700. portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
  3701. if (iack & IVR_RXDATA)
  3702. stl_sc26198rxisr(portp, iack);
  3703. else if (iack & IVR_TXDATA)
  3704. stl_sc26198txisr(portp);
  3705. else
  3706. stl_sc26198otherisr(portp, iack);
  3707. spin_unlock(&brd_lock);
  3708. }
  3709. /*****************************************************************************/
  3710. /*
  3711. * Transmit interrupt handler. This has gotta be fast! Handling TX
  3712. * chars is pretty simple, stuff as many as possible from the TX buffer
  3713. * into the sc26198 FIFO.
  3714. * In practice it is possible that interrupts are enabled but that the
  3715. * port has been hung up. Need to handle not having any TX buffer here,
  3716. * this is done by using the side effect that head and tail will also
  3717. * be NULL if the buffer has been freed.
  3718. */
  3719. static void stl_sc26198txisr(struct stlport *portp)
  3720. {
  3721. unsigned int ioaddr;
  3722. unsigned char mr0;
  3723. int len, stlen;
  3724. char *head, *tail;
  3725. pr_debug("stl_sc26198txisr(portp=%p)\n", portp);
  3726. ioaddr = portp->ioaddr;
  3727. head = portp->tx.head;
  3728. tail = portp->tx.tail;
  3729. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  3730. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  3731. (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  3732. set_bit(ASYI_TXLOW, &portp->istate);
  3733. if (portp->port.tty)
  3734. tty_wakeup(portp->port.tty);
  3735. }
  3736. if (len == 0) {
  3737. outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
  3738. mr0 = inb(ioaddr + XP_DATA);
  3739. if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
  3740. portp->imr &= ~IR_TXRDY;
  3741. outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
  3742. outb(portp->imr, (ioaddr + XP_DATA));
  3743. clear_bit(ASYI_TXBUSY, &portp->istate);
  3744. } else {
  3745. mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
  3746. outb(mr0, (ioaddr + XP_DATA));
  3747. }
  3748. } else {
  3749. len = min(len, SC26198_TXFIFOSIZE);
  3750. portp->stats.txtotal += len;
  3751. stlen = min_t(unsigned int, len,
  3752. (portp->tx.buf + STL_TXBUFSIZE) - tail);
  3753. outb(GTXFIFO, (ioaddr + XP_ADDR));
  3754. outsb((ioaddr + XP_DATA), tail, stlen);
  3755. len -= stlen;
  3756. tail += stlen;
  3757. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  3758. tail = portp->tx.buf;
  3759. if (len > 0) {
  3760. outsb((ioaddr + XP_DATA), tail, len);
  3761. tail += len;
  3762. }
  3763. portp->tx.tail = tail;
  3764. }
  3765. }
  3766. /*****************************************************************************/
  3767. /*
  3768. * Receive character interrupt handler. Determine if we have good chars
  3769. * or bad chars and then process appropriately. Good chars are easy
  3770. * just shove the lot into the RX buffer and set all status byte to 0.
  3771. * If a bad RX char then process as required. This routine needs to be
  3772. * fast! In practice it is possible that we get an interrupt on a port
  3773. * that is closed. This can happen on hangups - since they completely
  3774. * shutdown a port not in user context. Need to handle this case.
  3775. */
  3776. static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
  3777. {
  3778. struct tty_struct *tty;
  3779. unsigned int len, buflen, ioaddr;
  3780. pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
  3781. tty = portp->port.tty;
  3782. ioaddr = portp->ioaddr;
  3783. outb(GIBCR, (ioaddr + XP_ADDR));
  3784. len = inb(ioaddr + XP_DATA) + 1;
  3785. if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
  3786. if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
  3787. len = min_t(unsigned int, len, sizeof(stl_unwanted));
  3788. outb(GRXFIFO, (ioaddr + XP_ADDR));
  3789. insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
  3790. portp->stats.rxlost += len;
  3791. portp->stats.rxtotal += len;
  3792. } else {
  3793. len = min(len, buflen);
  3794. if (len > 0) {
  3795. unsigned char *ptr;
  3796. outb(GRXFIFO, (ioaddr + XP_ADDR));
  3797. tty_prepare_flip_string(tty, &ptr, len);
  3798. insb((ioaddr + XP_DATA), ptr, len);
  3799. tty_schedule_flip(tty);
  3800. portp->stats.rxtotal += len;
  3801. }
  3802. }
  3803. } else {
  3804. stl_sc26198rxbadchars(portp);
  3805. }
  3806. /*
  3807. * If we are TX flow controlled and in IXANY mode then we may need
  3808. * to unflow control here. We gotta do this because of the automatic
  3809. * flow control modes of the sc26198.
  3810. */
  3811. if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
  3812. if ((tty != NULL) &&
  3813. (tty->termios != NULL) &&
  3814. (tty->termios->c_iflag & IXANY)) {
  3815. stl_sc26198txunflow(portp, tty);
  3816. }
  3817. }
  3818. }
  3819. /*****************************************************************************/
  3820. /*
  3821. * Process an RX bad character.
  3822. */
  3823. static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch)
  3824. {
  3825. struct tty_struct *tty;
  3826. unsigned int ioaddr;
  3827. tty = portp->port.tty;
  3828. ioaddr = portp->ioaddr;
  3829. if (status & SR_RXPARITY)
  3830. portp->stats.rxparity++;
  3831. if (status & SR_RXFRAMING)
  3832. portp->stats.rxframing++;
  3833. if (status & SR_RXOVERRUN)
  3834. portp->stats.rxoverrun++;
  3835. if (status & SR_RXBREAK)
  3836. portp->stats.rxbreaks++;
  3837. if ((tty != NULL) &&
  3838. ((portp->rxignoremsk & status) == 0)) {
  3839. if (portp->rxmarkmsk & status) {
  3840. if (status & SR_RXBREAK) {
  3841. status = TTY_BREAK;
  3842. if (portp->port.flags & ASYNC_SAK) {
  3843. do_SAK(tty);
  3844. BRDENABLE(portp->brdnr, portp->pagenr);
  3845. }
  3846. } else if (status & SR_RXPARITY)
  3847. status = TTY_PARITY;
  3848. else if (status & SR_RXFRAMING)
  3849. status = TTY_FRAME;
  3850. else if(status & SR_RXOVERRUN)
  3851. status = TTY_OVERRUN;
  3852. else
  3853. status = 0;
  3854. } else
  3855. status = 0;
  3856. tty_insert_flip_char(tty, ch, status);
  3857. tty_schedule_flip(tty);
  3858. if (status == 0)
  3859. portp->stats.rxtotal++;
  3860. }
  3861. }
  3862. /*****************************************************************************/
  3863. /*
  3864. * Process all characters in the RX FIFO of the UART. Check all char
  3865. * status bytes as well, and process as required. We need to check
  3866. * all bytes in the FIFO, in case some more enter the FIFO while we
  3867. * are here. To get the exact character error type we need to switch
  3868. * into CHAR error mode (that is why we need to make sure we empty
  3869. * the FIFO).
  3870. */
  3871. static void stl_sc26198rxbadchars(struct stlport *portp)
  3872. {
  3873. unsigned char status, mr1;
  3874. char ch;
  3875. /*
  3876. * To get the precise error type for each character we must switch
  3877. * back into CHAR error mode.
  3878. */
  3879. mr1 = stl_sc26198getreg(portp, MR1);
  3880. stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
  3881. while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
  3882. stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
  3883. ch = stl_sc26198getreg(portp, RXFIFO);
  3884. stl_sc26198rxbadch(portp, status, ch);
  3885. }
  3886. /*
  3887. * To get correct interrupt class we must switch back into BLOCK
  3888. * error mode.
  3889. */
  3890. stl_sc26198setreg(portp, MR1, mr1);
  3891. }
  3892. /*****************************************************************************/
  3893. /*
  3894. * Other interrupt handler. This includes modem signals, flow
  3895. * control actions, etc. Most stuff is left to off-level interrupt
  3896. * processing time.
  3897. */
  3898. static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
  3899. {
  3900. unsigned char cir, ipr, xisr;
  3901. pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack);
  3902. cir = stl_sc26198getglobreg(portp, CIR);
  3903. switch (cir & CIR_SUBTYPEMASK) {
  3904. case CIR_SUBCOS:
  3905. ipr = stl_sc26198getreg(portp, IPR);
  3906. if (ipr & IPR_DCDCHANGE) {
  3907. stl_cd_change(portp);
  3908. portp->stats.modem++;
  3909. }
  3910. break;
  3911. case CIR_SUBXONXOFF:
  3912. xisr = stl_sc26198getreg(portp, XISR);
  3913. if (xisr & XISR_RXXONGOT) {
  3914. set_bit(ASYI_TXFLOWED, &portp->istate);
  3915. portp->stats.txxoff++;
  3916. }
  3917. if (xisr & XISR_RXXOFFGOT) {
  3918. clear_bit(ASYI_TXFLOWED, &portp->istate);
  3919. portp->stats.txxon++;
  3920. }
  3921. break;
  3922. case CIR_SUBBREAK:
  3923. stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
  3924. stl_sc26198rxbadchars(portp);
  3925. break;
  3926. default:
  3927. break;
  3928. }
  3929. }
  3930. static void stl_free_isabrds(void)
  3931. {
  3932. struct stlbrd *brdp;
  3933. unsigned int i;
  3934. for (i = 0; i < stl_nrbrds; i++) {
  3935. if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
  3936. continue;
  3937. free_irq(brdp->irq, brdp);
  3938. stl_cleanup_panels(brdp);
  3939. release_region(brdp->ioaddr1, brdp->iosize1);
  3940. if (brdp->iosize2 > 0)
  3941. release_region(brdp->ioaddr2, brdp->iosize2);
  3942. kfree(brdp);
  3943. stl_brds[i] = NULL;
  3944. }
  3945. }
  3946. /*
  3947. * Loadable module initialization stuff.
  3948. */
  3949. static int __init stallion_module_init(void)
  3950. {
  3951. struct stlbrd *brdp;
  3952. struct stlconf conf;
  3953. unsigned int i, j;
  3954. int retval;
  3955. printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
  3956. spin_lock_init(&stallion_lock);
  3957. spin_lock_init(&brd_lock);
  3958. stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
  3959. if (!stl_serial) {
  3960. retval = -ENOMEM;
  3961. goto err;
  3962. }
  3963. stl_serial->owner = THIS_MODULE;
  3964. stl_serial->driver_name = stl_drvname;
  3965. stl_serial->name = "ttyE";
  3966. stl_serial->major = STL_SERIALMAJOR;
  3967. stl_serial->minor_start = 0;
  3968. stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
  3969. stl_serial->subtype = SERIAL_TYPE_NORMAL;
  3970. stl_serial->init_termios = stl_deftermios;
  3971. stl_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
  3972. tty_set_operations(stl_serial, &stl_ops);
  3973. retval = tty_register_driver(stl_serial);
  3974. if (retval) {
  3975. printk("STALLION: failed to register serial driver\n");
  3976. goto err_frtty;
  3977. }
  3978. /*
  3979. * Find any dynamically supported boards. That is via module load
  3980. * line options.
  3981. */
  3982. for (i = stl_nrbrds; i < stl_nargs; i++) {
  3983. memset(&conf, 0, sizeof(conf));
  3984. if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
  3985. continue;
  3986. if ((brdp = stl_allocbrd()) == NULL)
  3987. continue;
  3988. brdp->brdnr = i;
  3989. brdp->brdtype = conf.brdtype;
  3990. brdp->ioaddr1 = conf.ioaddr1;
  3991. brdp->ioaddr2 = conf.ioaddr2;
  3992. brdp->irq = conf.irq;
  3993. brdp->irqtype = conf.irqtype;
  3994. stl_brds[brdp->brdnr] = brdp;
  3995. if (stl_brdinit(brdp)) {
  3996. stl_brds[brdp->brdnr] = NULL;
  3997. kfree(brdp);
  3998. } else {
  3999. for (j = 0; j < brdp->nrports; j++)
  4000. tty_register_device(stl_serial,
  4001. brdp->brdnr * STL_MAXPORTS + j, NULL);
  4002. stl_nrbrds = i + 1;
  4003. }
  4004. }
  4005. /* this has to be _after_ isa finding because of locking */
  4006. retval = pci_register_driver(&stl_pcidriver);
  4007. if (retval && stl_nrbrds == 0) {
  4008. printk(KERN_ERR "STALLION: can't register pci driver\n");
  4009. goto err_unrtty;
  4010. }
  4011. /*
  4012. * Set up a character driver for per board stuff. This is mainly used
  4013. * to do stats ioctls on the ports.
  4014. */
  4015. if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
  4016. printk("STALLION: failed to register serial board device\n");
  4017. stallion_class = class_create(THIS_MODULE, "staliomem");
  4018. if (IS_ERR(stallion_class))
  4019. printk("STALLION: failed to create class\n");
  4020. for (i = 0; i < 4; i++)
  4021. device_create_drvdata(stallion_class, NULL, MKDEV(STL_SIOMEMMAJOR, i),
  4022. NULL, "staliomem%d", i);
  4023. return 0;
  4024. err_unrtty:
  4025. tty_unregister_driver(stl_serial);
  4026. err_frtty:
  4027. put_tty_driver(stl_serial);
  4028. err:
  4029. return retval;
  4030. }
  4031. static void __exit stallion_module_exit(void)
  4032. {
  4033. struct stlbrd *brdp;
  4034. unsigned int i, j;
  4035. pr_debug("cleanup_module()\n");
  4036. printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
  4037. stl_drvversion);
  4038. /*
  4039. * Free up all allocated resources used by the ports. This includes
  4040. * memory and interrupts. As part of this process we will also do
  4041. * a hangup on every open port - to try to flush out any processes
  4042. * hanging onto ports.
  4043. */
  4044. for (i = 0; i < stl_nrbrds; i++) {
  4045. if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
  4046. continue;
  4047. for (j = 0; j < brdp->nrports; j++)
  4048. tty_unregister_device(stl_serial,
  4049. brdp->brdnr * STL_MAXPORTS + j);
  4050. }
  4051. for (i = 0; i < 4; i++)
  4052. device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
  4053. unregister_chrdev(STL_SIOMEMMAJOR, "staliomem");
  4054. class_destroy(stallion_class);
  4055. pci_unregister_driver(&stl_pcidriver);
  4056. stl_free_isabrds();
  4057. tty_unregister_driver(stl_serial);
  4058. put_tty_driver(stl_serial);
  4059. }
  4060. module_init(stallion_module_init);
  4061. module_exit(stallion_module_exit);
  4062. MODULE_AUTHOR("Greg Ungerer");
  4063. MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
  4064. MODULE_LICENSE("GPL");