stallion.c 119 KB

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