stallion.c 120 KB

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