stallion.c 123 KB

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