stallion.c 124 KB

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