stallion.c 126 KB

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