stallion.c 121 KB

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