stallion.c 124 KB

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