stallion.c 131 KB

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