stallion.c 123 KB

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