stallion.c 128 KB

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