stallion.c 123 KB

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