istallion.c 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755
  1. /*****************************************************************************/
  2. /*
  3. * istallion.c -- stallion intelligent 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/cdk.h>
  34. #include <linux/comstats.h>
  35. #include <linux/istallion.h>
  36. #include <linux/ioport.h>
  37. #include <linux/delay.h>
  38. #include <linux/init.h>
  39. #include <linux/device.h>
  40. #include <linux/wait.h>
  41. #include <linux/eisa.h>
  42. #include <asm/io.h>
  43. #include <asm/uaccess.h>
  44. #include <linux/pci.h>
  45. /*****************************************************************************/
  46. /*
  47. * Define different board types. Not all of the following board types
  48. * are supported by this driver. But I will use the standard "assigned"
  49. * board numbers. Currently supported boards are abbreviated as:
  50. * ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and
  51. * STAL = Stallion.
  52. */
  53. #define BRD_UNKNOWN 0
  54. #define BRD_STALLION 1
  55. #define BRD_BRUMBY4 2
  56. #define BRD_ONBOARD2 3
  57. #define BRD_ONBOARD 4
  58. #define BRD_BRUMBY8 5
  59. #define BRD_BRUMBY16 6
  60. #define BRD_ONBOARDE 7
  61. #define BRD_ONBOARD32 9
  62. #define BRD_ONBOARD2_32 10
  63. #define BRD_ONBOARDRS 11
  64. #define BRD_EASYIO 20
  65. #define BRD_ECH 21
  66. #define BRD_ECHMC 22
  67. #define BRD_ECP 23
  68. #define BRD_ECPE 24
  69. #define BRD_ECPMC 25
  70. #define BRD_ECHPCI 26
  71. #define BRD_ECH64PCI 27
  72. #define BRD_EASYIOPCI 28
  73. #define BRD_ECPPCI 29
  74. #define BRD_BRUMBY BRD_BRUMBY4
  75. /*
  76. * Define a configuration structure to hold the board configuration.
  77. * Need to set this up in the code (for now) with the boards that are
  78. * to be configured into the system. This is what needs to be modified
  79. * when adding/removing/modifying boards. Each line entry in the
  80. * stli_brdconf[] array is a board. Each line contains io/irq/memory
  81. * ranges for that board (as well as what type of board it is).
  82. * Some examples:
  83. * { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
  84. * This line will configure an EasyConnection 8/64 at io address 2a0,
  85. * and shared memory address of cc000. Multiple EasyConnection 8/64
  86. * boards can share the same shared memory address space. No interrupt
  87. * is required for this board type.
  88. * Another example:
  89. * { BRD_ECPE, 0x5000, 0, 0x80000000, 0, 0 },
  90. * This line will configure an EasyConnection 8/64 EISA in slot 5 and
  91. * shared memory address of 0x80000000 (2 GByte). Multiple
  92. * EasyConnection 8/64 EISA boards can share the same shared memory
  93. * address space. No interrupt is required for this board type.
  94. * Another example:
  95. * { BRD_ONBOARD, 0x240, 0, 0xd0000, 0, 0 },
  96. * This line will configure an ONboard (ISA type) at io address 240,
  97. * and shared memory address of d0000. Multiple ONboards can share
  98. * the same shared memory address space. No interrupt required.
  99. * Another example:
  100. * { BRD_BRUMBY4, 0x360, 0, 0xc8000, 0, 0 },
  101. * This line will configure a Brumby board (any number of ports!) at
  102. * io address 360 and shared memory address of c8000. All Brumby boards
  103. * configured into a system must have their own separate io and memory
  104. * addresses. No interrupt is required.
  105. * Another example:
  106. * { BRD_STALLION, 0x330, 0, 0xd0000, 0, 0 },
  107. * This line will configure an original Stallion board at io address 330
  108. * and shared memory address d0000 (this would only be valid for a "V4.0"
  109. * or Rev.O Stallion board). All Stallion boards configured into the
  110. * system must have their own separate io and memory addresses. No
  111. * interrupt is required.
  112. */
  113. typedef struct {
  114. int brdtype;
  115. int ioaddr1;
  116. int ioaddr2;
  117. unsigned long memaddr;
  118. int irq;
  119. int irqtype;
  120. } stlconf_t;
  121. static stlconf_t stli_brdconf[] = {
  122. /*{ BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },*/
  123. };
  124. static int stli_nrbrds = ARRAY_SIZE(stli_brdconf);
  125. /* stli_lock must NOT be taken holding brd_lock */
  126. static spinlock_t stli_lock; /* TTY logic lock */
  127. static spinlock_t brd_lock; /* Board logic lock */
  128. /*
  129. * There is some experimental EISA board detection code in this driver.
  130. * By default it is disabled, but for those that want to try it out,
  131. * then set the define below to be 1.
  132. */
  133. #define STLI_EISAPROBE 0
  134. /*****************************************************************************/
  135. /*
  136. * Define some important driver characteristics. Device major numbers
  137. * allocated as per Linux Device Registry.
  138. */
  139. #ifndef STL_SIOMEMMAJOR
  140. #define STL_SIOMEMMAJOR 28
  141. #endif
  142. #ifndef STL_SERIALMAJOR
  143. #define STL_SERIALMAJOR 24
  144. #endif
  145. #ifndef STL_CALLOUTMAJOR
  146. #define STL_CALLOUTMAJOR 25
  147. #endif
  148. /*****************************************************************************/
  149. /*
  150. * Define our local driver identity first. Set up stuff to deal with
  151. * all the local structures required by a serial tty driver.
  152. */
  153. static char *stli_drvtitle = "Stallion Intelligent Multiport Serial Driver";
  154. static char *stli_drvname = "istallion";
  155. static char *stli_drvversion = "5.6.0";
  156. static char *stli_serialname = "ttyE";
  157. static struct tty_driver *stli_serial;
  158. #define STLI_TXBUFSIZE 4096
  159. /*
  160. * Use a fast local buffer for cooked characters. Typically a whole
  161. * bunch of cooked characters come in for a port, 1 at a time. So we
  162. * save those up into a local buffer, then write out the whole lot
  163. * with a large memcpy. Just use 1 buffer for all ports, since its
  164. * use it is only need for short periods of time by each port.
  165. */
  166. static char *stli_txcookbuf;
  167. static int stli_txcooksize;
  168. static int stli_txcookrealsize;
  169. static struct tty_struct *stli_txcooktty;
  170. /*
  171. * Define a local default termios struct. All ports will be created
  172. * with this termios initially. Basically all it defines is a raw port
  173. * at 9600 baud, 8 data bits, no parity, 1 stop bit.
  174. */
  175. static struct termios stli_deftermios = {
  176. .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
  177. .c_cc = INIT_C_CC,
  178. };
  179. /*
  180. * Define global stats structures. Not used often, and can be
  181. * re-used for each stats call.
  182. */
  183. static comstats_t stli_comstats;
  184. static combrd_t stli_brdstats;
  185. static asystats_t stli_cdkstats;
  186. static stlibrd_t stli_dummybrd;
  187. static stliport_t stli_dummyport;
  188. /*****************************************************************************/
  189. static stlibrd_t *stli_brds[STL_MAXBRDS];
  190. static int stli_shared;
  191. /*
  192. * Per board state flags. Used with the state field of the board struct.
  193. * Not really much here... All we need to do is keep track of whether
  194. * the board has been detected, and whether it is actually running a slave
  195. * or not.
  196. */
  197. #define BST_FOUND 0x1
  198. #define BST_STARTED 0x2
  199. /*
  200. * Define the set of port state flags. These are marked for internal
  201. * state purposes only, usually to do with the state of communications
  202. * with the slave. Most of them need to be updated atomically, so always
  203. * use the bit setting operations (unless protected by cli/sti).
  204. */
  205. #define ST_INITIALIZING 1
  206. #define ST_OPENING 2
  207. #define ST_CLOSING 3
  208. #define ST_CMDING 4
  209. #define ST_TXBUSY 5
  210. #define ST_RXING 6
  211. #define ST_DOFLUSHRX 7
  212. #define ST_DOFLUSHTX 8
  213. #define ST_DOSIGS 9
  214. #define ST_RXSTOP 10
  215. #define ST_GETSIGS 11
  216. /*
  217. * Define an array of board names as printable strings. Handy for
  218. * referencing boards when printing trace and stuff.
  219. */
  220. static char *stli_brdnames[] = {
  221. "Unknown",
  222. "Stallion",
  223. "Brumby",
  224. "ONboard-MC",
  225. "ONboard",
  226. "Brumby",
  227. "Brumby",
  228. "ONboard-EI",
  229. (char *) NULL,
  230. "ONboard",
  231. "ONboard-MC",
  232. "ONboard-MC",
  233. (char *) NULL,
  234. (char *) NULL,
  235. (char *) NULL,
  236. (char *) NULL,
  237. (char *) NULL,
  238. (char *) NULL,
  239. (char *) NULL,
  240. (char *) NULL,
  241. "EasyIO",
  242. "EC8/32-AT",
  243. "EC8/32-MC",
  244. "EC8/64-AT",
  245. "EC8/64-EI",
  246. "EC8/64-MC",
  247. "EC8/32-PCI",
  248. "EC8/64-PCI",
  249. "EasyIO-PCI",
  250. "EC/RA-PCI",
  251. };
  252. /*****************************************************************************/
  253. #ifdef MODULE
  254. /*
  255. * Define some string labels for arguments passed from the module
  256. * load line. These allow for easy board definitions, and easy
  257. * modification of the io, memory and irq resoucres.
  258. */
  259. static char *board0[8];
  260. static char *board1[8];
  261. static char *board2[8];
  262. static char *board3[8];
  263. static char **stli_brdsp[] = {
  264. (char **) &board0,
  265. (char **) &board1,
  266. (char **) &board2,
  267. (char **) &board3
  268. };
  269. /*
  270. * Define a set of common board names, and types. This is used to
  271. * parse any module arguments.
  272. */
  273. typedef struct stlibrdtype {
  274. char *name;
  275. int type;
  276. } stlibrdtype_t;
  277. static stlibrdtype_t stli_brdstr[] = {
  278. { "stallion", BRD_STALLION },
  279. { "1", BRD_STALLION },
  280. { "brumby", BRD_BRUMBY },
  281. { "brumby4", BRD_BRUMBY },
  282. { "brumby/4", BRD_BRUMBY },
  283. { "brumby-4", BRD_BRUMBY },
  284. { "brumby8", BRD_BRUMBY },
  285. { "brumby/8", BRD_BRUMBY },
  286. { "brumby-8", BRD_BRUMBY },
  287. { "brumby16", BRD_BRUMBY },
  288. { "brumby/16", BRD_BRUMBY },
  289. { "brumby-16", BRD_BRUMBY },
  290. { "2", BRD_BRUMBY },
  291. { "onboard2", BRD_ONBOARD2 },
  292. { "onboard-2", BRD_ONBOARD2 },
  293. { "onboard/2", BRD_ONBOARD2 },
  294. { "onboard-mc", BRD_ONBOARD2 },
  295. { "onboard/mc", BRD_ONBOARD2 },
  296. { "onboard-mca", BRD_ONBOARD2 },
  297. { "onboard/mca", BRD_ONBOARD2 },
  298. { "3", BRD_ONBOARD2 },
  299. { "onboard", BRD_ONBOARD },
  300. { "onboardat", BRD_ONBOARD },
  301. { "4", BRD_ONBOARD },
  302. { "onboarde", BRD_ONBOARDE },
  303. { "onboard-e", BRD_ONBOARDE },
  304. { "onboard/e", BRD_ONBOARDE },
  305. { "onboard-ei", BRD_ONBOARDE },
  306. { "onboard/ei", BRD_ONBOARDE },
  307. { "7", BRD_ONBOARDE },
  308. { "ecp", BRD_ECP },
  309. { "ecpat", BRD_ECP },
  310. { "ec8/64", BRD_ECP },
  311. { "ec8/64-at", BRD_ECP },
  312. { "ec8/64-isa", BRD_ECP },
  313. { "23", BRD_ECP },
  314. { "ecpe", BRD_ECPE },
  315. { "ecpei", BRD_ECPE },
  316. { "ec8/64-e", BRD_ECPE },
  317. { "ec8/64-ei", BRD_ECPE },
  318. { "24", BRD_ECPE },
  319. { "ecpmc", BRD_ECPMC },
  320. { "ec8/64-mc", BRD_ECPMC },
  321. { "ec8/64-mca", BRD_ECPMC },
  322. { "25", BRD_ECPMC },
  323. { "ecppci", BRD_ECPPCI },
  324. { "ec/ra", BRD_ECPPCI },
  325. { "ec/ra-pc", BRD_ECPPCI },
  326. { "ec/ra-pci", BRD_ECPPCI },
  327. { "29", BRD_ECPPCI },
  328. };
  329. /*
  330. * Define the module agruments.
  331. */
  332. MODULE_AUTHOR("Greg Ungerer");
  333. MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
  334. MODULE_LICENSE("GPL");
  335. module_param_array(board0, charp, NULL, 0);
  336. MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
  337. module_param_array(board1, charp, NULL, 0);
  338. MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
  339. module_param_array(board2, charp, NULL, 0);
  340. MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
  341. module_param_array(board3, charp, NULL, 0);
  342. MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
  343. #endif
  344. /*
  345. * Set up a default memory address table for EISA board probing.
  346. * The default addresses are all bellow 1Mbyte, which has to be the
  347. * case anyway. They should be safe, since we only read values from
  348. * them, and interrupts are disabled while we do it. If the higher
  349. * memory support is compiled in then we also try probing around
  350. * the 1Gb, 2Gb and 3Gb areas as well...
  351. */
  352. static unsigned long stli_eisamemprobeaddrs[] = {
  353. 0xc0000, 0xd0000, 0xe0000, 0xf0000,
  354. 0x80000000, 0x80010000, 0x80020000, 0x80030000,
  355. 0x40000000, 0x40010000, 0x40020000, 0x40030000,
  356. 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
  357. 0xff000000, 0xff010000, 0xff020000, 0xff030000,
  358. };
  359. static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
  360. /*
  361. * Define the Stallion PCI vendor and device IDs.
  362. */
  363. #ifdef CONFIG_PCI
  364. #ifndef PCI_VENDOR_ID_STALLION
  365. #define PCI_VENDOR_ID_STALLION 0x124d
  366. #endif
  367. #ifndef PCI_DEVICE_ID_ECRA
  368. #define PCI_DEVICE_ID_ECRA 0x0004
  369. #endif
  370. static struct pci_device_id istallion_pci_tbl[] = {
  371. { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA), },
  372. { 0 }
  373. };
  374. MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
  375. #endif /* CONFIG_PCI */
  376. /*****************************************************************************/
  377. /*
  378. * Hardware configuration info for ECP boards. These defines apply
  379. * to the directly accessible io ports of the ECP. There is a set of
  380. * defines for each ECP board type, ISA, EISA, MCA and PCI.
  381. */
  382. #define ECP_IOSIZE 4
  383. #define ECP_MEMSIZE (128 * 1024)
  384. #define ECP_PCIMEMSIZE (256 * 1024)
  385. #define ECP_ATPAGESIZE (4 * 1024)
  386. #define ECP_MCPAGESIZE (4 * 1024)
  387. #define ECP_EIPAGESIZE (64 * 1024)
  388. #define ECP_PCIPAGESIZE (64 * 1024)
  389. #define STL_EISAID 0x8c4e
  390. /*
  391. * Important defines for the ISA class of ECP board.
  392. */
  393. #define ECP_ATIREG 0
  394. #define ECP_ATCONFR 1
  395. #define ECP_ATMEMAR 2
  396. #define ECP_ATMEMPR 3
  397. #define ECP_ATSTOP 0x1
  398. #define ECP_ATINTENAB 0x10
  399. #define ECP_ATENABLE 0x20
  400. #define ECP_ATDISABLE 0x00
  401. #define ECP_ATADDRMASK 0x3f000
  402. #define ECP_ATADDRSHFT 12
  403. /*
  404. * Important defines for the EISA class of ECP board.
  405. */
  406. #define ECP_EIIREG 0
  407. #define ECP_EIMEMARL 1
  408. #define ECP_EICONFR 2
  409. #define ECP_EIMEMARH 3
  410. #define ECP_EIENABLE 0x1
  411. #define ECP_EIDISABLE 0x0
  412. #define ECP_EISTOP 0x4
  413. #define ECP_EIEDGE 0x00
  414. #define ECP_EILEVEL 0x80
  415. #define ECP_EIADDRMASKL 0x00ff0000
  416. #define ECP_EIADDRSHFTL 16
  417. #define ECP_EIADDRMASKH 0xff000000
  418. #define ECP_EIADDRSHFTH 24
  419. #define ECP_EIBRDENAB 0xc84
  420. #define ECP_EISAID 0x4
  421. /*
  422. * Important defines for the Micro-channel class of ECP board.
  423. * (It has a lot in common with the ISA boards.)
  424. */
  425. #define ECP_MCIREG 0
  426. #define ECP_MCCONFR 1
  427. #define ECP_MCSTOP 0x20
  428. #define ECP_MCENABLE 0x80
  429. #define ECP_MCDISABLE 0x00
  430. /*
  431. * Important defines for the PCI class of ECP board.
  432. * (It has a lot in common with the other ECP boards.)
  433. */
  434. #define ECP_PCIIREG 0
  435. #define ECP_PCICONFR 1
  436. #define ECP_PCISTOP 0x01
  437. /*
  438. * Hardware configuration info for ONboard and Brumby boards. These
  439. * defines apply to the directly accessible io ports of these boards.
  440. */
  441. #define ONB_IOSIZE 16
  442. #define ONB_MEMSIZE (64 * 1024)
  443. #define ONB_ATPAGESIZE (64 * 1024)
  444. #define ONB_MCPAGESIZE (64 * 1024)
  445. #define ONB_EIMEMSIZE (128 * 1024)
  446. #define ONB_EIPAGESIZE (64 * 1024)
  447. /*
  448. * Important defines for the ISA class of ONboard board.
  449. */
  450. #define ONB_ATIREG 0
  451. #define ONB_ATMEMAR 1
  452. #define ONB_ATCONFR 2
  453. #define ONB_ATSTOP 0x4
  454. #define ONB_ATENABLE 0x01
  455. #define ONB_ATDISABLE 0x00
  456. #define ONB_ATADDRMASK 0xff0000
  457. #define ONB_ATADDRSHFT 16
  458. #define ONB_MEMENABLO 0
  459. #define ONB_MEMENABHI 0x02
  460. /*
  461. * Important defines for the EISA class of ONboard board.
  462. */
  463. #define ONB_EIIREG 0
  464. #define ONB_EIMEMARL 1
  465. #define ONB_EICONFR 2
  466. #define ONB_EIMEMARH 3
  467. #define ONB_EIENABLE 0x1
  468. #define ONB_EIDISABLE 0x0
  469. #define ONB_EISTOP 0x4
  470. #define ONB_EIEDGE 0x00
  471. #define ONB_EILEVEL 0x80
  472. #define ONB_EIADDRMASKL 0x00ff0000
  473. #define ONB_EIADDRSHFTL 16
  474. #define ONB_EIADDRMASKH 0xff000000
  475. #define ONB_EIADDRSHFTH 24
  476. #define ONB_EIBRDENAB 0xc84
  477. #define ONB_EISAID 0x1
  478. /*
  479. * Important defines for the Brumby boards. They are pretty simple,
  480. * there is not much that is programmably configurable.
  481. */
  482. #define BBY_IOSIZE 16
  483. #define BBY_MEMSIZE (64 * 1024)
  484. #define BBY_PAGESIZE (16 * 1024)
  485. #define BBY_ATIREG 0
  486. #define BBY_ATCONFR 1
  487. #define BBY_ATSTOP 0x4
  488. /*
  489. * Important defines for the Stallion boards. They are pretty simple,
  490. * there is not much that is programmably configurable.
  491. */
  492. #define STAL_IOSIZE 16
  493. #define STAL_MEMSIZE (64 * 1024)
  494. #define STAL_PAGESIZE (64 * 1024)
  495. /*
  496. * Define the set of status register values for EasyConnection panels.
  497. * The signature will return with the status value for each panel. From
  498. * this we can determine what is attached to the board - before we have
  499. * actually down loaded any code to it.
  500. */
  501. #define ECH_PNLSTATUS 2
  502. #define ECH_PNL16PORT 0x20
  503. #define ECH_PNLIDMASK 0x07
  504. #define ECH_PNLXPID 0x40
  505. #define ECH_PNLINTRPEND 0x80
  506. /*
  507. * Define some macros to do things to the board. Even those these boards
  508. * are somewhat related there is often significantly different ways of
  509. * doing some operation on it (like enable, paging, reset, etc). So each
  510. * board class has a set of functions which do the commonly required
  511. * operations. The macros below basically just call these functions,
  512. * generally checking for a NULL function - which means that the board
  513. * needs nothing done to it to achieve this operation!
  514. */
  515. #define EBRDINIT(brdp) \
  516. if (brdp->init != NULL) \
  517. (* brdp->init)(brdp)
  518. #define EBRDENABLE(brdp) \
  519. if (brdp->enable != NULL) \
  520. (* brdp->enable)(brdp);
  521. #define EBRDDISABLE(brdp) \
  522. if (brdp->disable != NULL) \
  523. (* brdp->disable)(brdp);
  524. #define EBRDINTR(brdp) \
  525. if (brdp->intr != NULL) \
  526. (* brdp->intr)(brdp);
  527. #define EBRDRESET(brdp) \
  528. if (brdp->reset != NULL) \
  529. (* brdp->reset)(brdp);
  530. #define EBRDGETMEMPTR(brdp,offset) \
  531. (* brdp->getmemptr)(brdp, offset, __LINE__)
  532. /*
  533. * Define the maximal baud rate, and the default baud base for ports.
  534. */
  535. #define STL_MAXBAUD 460800
  536. #define STL_BAUDBASE 115200
  537. #define STL_CLOSEDELAY (5 * HZ / 10)
  538. /*****************************************************************************/
  539. /*
  540. * Define macros to extract a brd or port number from a minor number.
  541. */
  542. #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
  543. #define MINOR2PORT(min) ((min) & 0x3f)
  544. /*
  545. * Define a baud rate table that converts termios baud rate selector
  546. * into the actual baud rate value. All baud rate calculations are based
  547. * on the actual baud rate required.
  548. */
  549. static unsigned int stli_baudrates[] = {
  550. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
  551. 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
  552. };
  553. /*****************************************************************************/
  554. /*
  555. * Define some handy local macros...
  556. */
  557. #undef MIN
  558. #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
  559. #undef TOLOWER
  560. #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
  561. /*****************************************************************************/
  562. /*
  563. * Prototype all functions in this driver!
  564. */
  565. #ifdef MODULE
  566. static void stli_argbrds(void);
  567. static int stli_parsebrd(stlconf_t *confp, char **argp);
  568. static unsigned long stli_atol(char *str);
  569. #endif
  570. int stli_init(void);
  571. static int stli_open(struct tty_struct *tty, struct file *filp);
  572. static void stli_close(struct tty_struct *tty, struct file *filp);
  573. static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
  574. static void stli_putchar(struct tty_struct *tty, unsigned char ch);
  575. static void stli_flushchars(struct tty_struct *tty);
  576. static int stli_writeroom(struct tty_struct *tty);
  577. static int stli_charsinbuffer(struct tty_struct *tty);
  578. static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
  579. static void stli_settermios(struct tty_struct *tty, struct termios *old);
  580. static void stli_throttle(struct tty_struct *tty);
  581. static void stli_unthrottle(struct tty_struct *tty);
  582. static void stli_stop(struct tty_struct *tty);
  583. static void stli_start(struct tty_struct *tty);
  584. static void stli_flushbuffer(struct tty_struct *tty);
  585. static void stli_breakctl(struct tty_struct *tty, int state);
  586. static void stli_waituntilsent(struct tty_struct *tty, int timeout);
  587. static void stli_sendxchar(struct tty_struct *tty, char ch);
  588. static void stli_hangup(struct tty_struct *tty);
  589. static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos);
  590. static int stli_brdinit(stlibrd_t *brdp);
  591. static int stli_startbrd(stlibrd_t *brdp);
  592. static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
  593. static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
  594. static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
  595. static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp);
  596. static void stli_poll(unsigned long arg);
  597. static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
  598. static int stli_initopen(stlibrd_t *brdp, stliport_t *portp);
  599. static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
  600. static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
  601. static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp);
  602. static void stli_dohangup(void *arg);
  603. static int stli_setport(stliport_t *portp);
  604. static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
  605. static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
  606. static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
  607. static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp);
  608. static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
  609. static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
  610. static long stli_mktiocm(unsigned long sigvalue);
  611. static void stli_read(stlibrd_t *brdp, stliport_t *portp);
  612. static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp);
  613. static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp);
  614. static int stli_getbrdstats(combrd_t __user *bp);
  615. static int stli_getportstats(stliport_t *portp, comstats_t __user *cp);
  616. static int stli_portcmdstats(stliport_t *portp);
  617. static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp);
  618. static int stli_getportstruct(stliport_t __user *arg);
  619. static int stli_getbrdstruct(stlibrd_t __user *arg);
  620. static stlibrd_t *stli_allocbrd(void);
  621. static void stli_ecpinit(stlibrd_t *brdp);
  622. static void stli_ecpenable(stlibrd_t *brdp);
  623. static void stli_ecpdisable(stlibrd_t *brdp);
  624. static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  625. static void stli_ecpreset(stlibrd_t *brdp);
  626. static void stli_ecpintr(stlibrd_t *brdp);
  627. static void stli_ecpeiinit(stlibrd_t *brdp);
  628. static void stli_ecpeienable(stlibrd_t *brdp);
  629. static void stli_ecpeidisable(stlibrd_t *brdp);
  630. static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  631. static void stli_ecpeireset(stlibrd_t *brdp);
  632. static void stli_ecpmcenable(stlibrd_t *brdp);
  633. static void stli_ecpmcdisable(stlibrd_t *brdp);
  634. static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  635. static void stli_ecpmcreset(stlibrd_t *brdp);
  636. static void stli_ecppciinit(stlibrd_t *brdp);
  637. static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  638. static void stli_ecppcireset(stlibrd_t *brdp);
  639. static void stli_onbinit(stlibrd_t *brdp);
  640. static void stli_onbenable(stlibrd_t *brdp);
  641. static void stli_onbdisable(stlibrd_t *brdp);
  642. static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  643. static void stli_onbreset(stlibrd_t *brdp);
  644. static void stli_onbeinit(stlibrd_t *brdp);
  645. static void stli_onbeenable(stlibrd_t *brdp);
  646. static void stli_onbedisable(stlibrd_t *brdp);
  647. static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  648. static void stli_onbereset(stlibrd_t *brdp);
  649. static void stli_bbyinit(stlibrd_t *brdp);
  650. static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  651. static void stli_bbyreset(stlibrd_t *brdp);
  652. static void stli_stalinit(stlibrd_t *brdp);
  653. static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  654. static void stli_stalreset(stlibrd_t *brdp);
  655. static stliport_t *stli_getport(int brdnr, int panelnr, int portnr);
  656. static int stli_initecp(stlibrd_t *brdp);
  657. static int stli_initonb(stlibrd_t *brdp);
  658. static int stli_eisamemprobe(stlibrd_t *brdp);
  659. static int stli_initports(stlibrd_t *brdp);
  660. #ifdef CONFIG_PCI
  661. static int stli_initpcibrd(int brdtype, struct pci_dev *devp);
  662. #endif
  663. /*****************************************************************************/
  664. /*
  665. * Define the driver info for a user level shared memory device. This
  666. * device will work sort of like the /dev/kmem device - except that it
  667. * will give access to the shared memory on the Stallion intelligent
  668. * board. This is also a very useful debugging tool.
  669. */
  670. static struct file_operations stli_fsiomem = {
  671. .owner = THIS_MODULE,
  672. .read = stli_memread,
  673. .write = stli_memwrite,
  674. .ioctl = stli_memioctl,
  675. };
  676. /*****************************************************************************/
  677. /*
  678. * Define a timer_list entry for our poll routine. The slave board
  679. * is polled every so often to see if anything needs doing. This is
  680. * much cheaper on host cpu than using interrupts. It turns out to
  681. * not increase character latency by much either...
  682. */
  683. static DEFINE_TIMER(stli_timerlist, stli_poll, 0, 0);
  684. static int stli_timeron;
  685. /*
  686. * Define the calculation for the timeout routine.
  687. */
  688. #define STLI_TIMEOUT (jiffies + 1)
  689. /*****************************************************************************/
  690. static struct class *istallion_class;
  691. #ifdef MODULE
  692. /*
  693. * Loadable module initialization stuff.
  694. */
  695. static int __init istallion_module_init(void)
  696. {
  697. stli_init();
  698. return 0;
  699. }
  700. /*****************************************************************************/
  701. static void __exit istallion_module_exit(void)
  702. {
  703. stlibrd_t *brdp;
  704. stliport_t *portp;
  705. int i, j;
  706. printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
  707. stli_drvversion);
  708. /*
  709. * Free up all allocated resources used by the ports. This includes
  710. * memory and interrupts.
  711. */
  712. if (stli_timeron) {
  713. stli_timeron = 0;
  714. del_timer_sync(&stli_timerlist);
  715. }
  716. i = tty_unregister_driver(stli_serial);
  717. if (i) {
  718. printk("STALLION: failed to un-register tty driver, "
  719. "errno=%d\n", -i);
  720. return;
  721. }
  722. put_tty_driver(stli_serial);
  723. for (i = 0; i < 4; i++)
  724. class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, i));
  725. class_destroy(istallion_class);
  726. if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
  727. printk("STALLION: failed to un-register serial memory device, "
  728. "errno=%d\n", -i);
  729. kfree(stli_txcookbuf);
  730. for (i = 0; (i < stli_nrbrds); i++) {
  731. if ((brdp = stli_brds[i]) == NULL)
  732. continue;
  733. for (j = 0; (j < STL_MAXPORTS); j++) {
  734. portp = brdp->ports[j];
  735. if (portp != NULL) {
  736. if (portp->tty != NULL)
  737. tty_hangup(portp->tty);
  738. kfree(portp);
  739. }
  740. }
  741. iounmap(brdp->membase);
  742. if (brdp->iosize > 0)
  743. release_region(brdp->iobase, brdp->iosize);
  744. kfree(brdp);
  745. stli_brds[i] = NULL;
  746. }
  747. }
  748. module_init(istallion_module_init);
  749. module_exit(istallion_module_exit);
  750. /*****************************************************************************/
  751. /*
  752. * Check for any arguments passed in on the module load command line.
  753. */
  754. static void stli_argbrds(void)
  755. {
  756. stlconf_t conf;
  757. stlibrd_t *brdp;
  758. int i;
  759. for (i = stli_nrbrds; i < ARRAY_SIZE(stli_brdsp); i++) {
  760. memset(&conf, 0, sizeof(conf));
  761. if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
  762. continue;
  763. if ((brdp = stli_allocbrd()) == NULL)
  764. continue;
  765. stli_nrbrds = i + 1;
  766. brdp->brdnr = i;
  767. brdp->brdtype = conf.brdtype;
  768. brdp->iobase = conf.ioaddr1;
  769. brdp->memaddr = conf.memaddr;
  770. stli_brdinit(brdp);
  771. }
  772. }
  773. /*****************************************************************************/
  774. /*
  775. * Convert an ascii string number into an unsigned long.
  776. */
  777. static unsigned long stli_atol(char *str)
  778. {
  779. unsigned long val;
  780. int base, c;
  781. char *sp;
  782. val = 0;
  783. sp = str;
  784. if ((*sp == '0') && (*(sp+1) == 'x')) {
  785. base = 16;
  786. sp += 2;
  787. } else if (*sp == '0') {
  788. base = 8;
  789. sp++;
  790. } else {
  791. base = 10;
  792. }
  793. for (; (*sp != 0); sp++) {
  794. c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
  795. if ((c < 0) || (c >= base)) {
  796. printk("STALLION: invalid argument %s\n", str);
  797. val = 0;
  798. break;
  799. }
  800. val = (val * base) + c;
  801. }
  802. return(val);
  803. }
  804. /*****************************************************************************/
  805. /*
  806. * Parse the supplied argument string, into the board conf struct.
  807. */
  808. static int stli_parsebrd(stlconf_t *confp, char **argp)
  809. {
  810. char *sp;
  811. int i;
  812. if (argp[0] == NULL || *argp[0] == 0)
  813. return 0;
  814. for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
  815. *sp = TOLOWER(*sp);
  816. for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) {
  817. if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
  818. break;
  819. }
  820. if (i == ARRAY_SIZE(stli_brdstr)) {
  821. printk("STALLION: unknown board name, %s?\n", argp[0]);
  822. return 0;
  823. }
  824. confp->brdtype = stli_brdstr[i].type;
  825. if (argp[1] != NULL && *argp[1] != 0)
  826. confp->ioaddr1 = stli_atol(argp[1]);
  827. if (argp[2] != NULL && *argp[2] != 0)
  828. confp->memaddr = stli_atol(argp[2]);
  829. return(1);
  830. }
  831. #endif
  832. /*****************************************************************************/
  833. static int stli_open(struct tty_struct *tty, struct file *filp)
  834. {
  835. stlibrd_t *brdp;
  836. stliport_t *portp;
  837. unsigned int minordev;
  838. int brdnr, portnr, rc;
  839. minordev = tty->index;
  840. brdnr = MINOR2BRD(minordev);
  841. if (brdnr >= stli_nrbrds)
  842. return -ENODEV;
  843. brdp = stli_brds[brdnr];
  844. if (brdp == NULL)
  845. return -ENODEV;
  846. if ((brdp->state & BST_STARTED) == 0)
  847. return -ENODEV;
  848. portnr = MINOR2PORT(minordev);
  849. if ((portnr < 0) || (portnr > brdp->nrports))
  850. return -ENODEV;
  851. portp = brdp->ports[portnr];
  852. if (portp == NULL)
  853. return -ENODEV;
  854. if (portp->devnr < 1)
  855. return -ENODEV;
  856. /*
  857. * Check if this port is in the middle of closing. If so then wait
  858. * until it is closed then return error status based on flag settings.
  859. * The sleep here does not need interrupt protection since the wakeup
  860. * for it is done with the same context.
  861. */
  862. if (portp->flags & ASYNC_CLOSING) {
  863. interruptible_sleep_on(&portp->close_wait);
  864. if (portp->flags & ASYNC_HUP_NOTIFY)
  865. return -EAGAIN;
  866. return -ERESTARTSYS;
  867. }
  868. /*
  869. * On the first open of the device setup the port hardware, and
  870. * initialize the per port data structure. Since initializing the port
  871. * requires several commands to the board we will need to wait for any
  872. * other open that is already initializing the port.
  873. */
  874. portp->tty = tty;
  875. tty->driver_data = portp;
  876. portp->refcount++;
  877. wait_event_interruptible(portp->raw_wait,
  878. !test_bit(ST_INITIALIZING, &portp->state));
  879. if (signal_pending(current))
  880. return -ERESTARTSYS;
  881. if ((portp->flags & ASYNC_INITIALIZED) == 0) {
  882. set_bit(ST_INITIALIZING, &portp->state);
  883. if ((rc = stli_initopen(brdp, portp)) >= 0) {
  884. portp->flags |= ASYNC_INITIALIZED;
  885. clear_bit(TTY_IO_ERROR, &tty->flags);
  886. }
  887. clear_bit(ST_INITIALIZING, &portp->state);
  888. wake_up_interruptible(&portp->raw_wait);
  889. if (rc < 0)
  890. return rc;
  891. }
  892. /*
  893. * Check if this port is in the middle of closing. If so then wait
  894. * until it is closed then return error status, based on flag settings.
  895. * The sleep here does not need interrupt protection since the wakeup
  896. * for it is done with the same context.
  897. */
  898. if (portp->flags & ASYNC_CLOSING) {
  899. interruptible_sleep_on(&portp->close_wait);
  900. if (portp->flags & ASYNC_HUP_NOTIFY)
  901. return -EAGAIN;
  902. return -ERESTARTSYS;
  903. }
  904. /*
  905. * Based on type of open being done check if it can overlap with any
  906. * previous opens still in effect. If we are a normal serial device
  907. * then also we might have to wait for carrier.
  908. */
  909. if (!(filp->f_flags & O_NONBLOCK)) {
  910. if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
  911. return rc;
  912. }
  913. portp->flags |= ASYNC_NORMAL_ACTIVE;
  914. return 0;
  915. }
  916. /*****************************************************************************/
  917. static void stli_close(struct tty_struct *tty, struct file *filp)
  918. {
  919. stlibrd_t *brdp;
  920. stliport_t *portp;
  921. unsigned long flags;
  922. portp = tty->driver_data;
  923. if (portp == NULL)
  924. return;
  925. spin_lock_irqsave(&stli_lock, flags);
  926. if (tty_hung_up_p(filp)) {
  927. spin_unlock_irqrestore(&stli_lock, flags);
  928. return;
  929. }
  930. if ((tty->count == 1) && (portp->refcount != 1))
  931. portp->refcount = 1;
  932. if (portp->refcount-- > 1) {
  933. spin_unlock_irqrestore(&stli_lock, flags);
  934. return;
  935. }
  936. portp->flags |= ASYNC_CLOSING;
  937. /*
  938. * May want to wait for data to drain before closing. The BUSY flag
  939. * keeps track of whether we are still transmitting or not. It is
  940. * updated by messages from the slave - indicating when all chars
  941. * really have drained.
  942. */
  943. if (tty == stli_txcooktty)
  944. stli_flushchars(tty);
  945. tty->closing = 1;
  946. spin_unlock_irqrestore(&stli_lock, flags);
  947. if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  948. tty_wait_until_sent(tty, portp->closing_wait);
  949. portp->flags &= ~ASYNC_INITIALIZED;
  950. brdp = stli_brds[portp->brdnr];
  951. stli_rawclose(brdp, portp, 0, 0);
  952. if (tty->termios->c_cflag & HUPCL) {
  953. stli_mkasysigs(&portp->asig, 0, 0);
  954. if (test_bit(ST_CMDING, &portp->state))
  955. set_bit(ST_DOSIGS, &portp->state);
  956. else
  957. stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
  958. sizeof(asysigs_t), 0);
  959. }
  960. clear_bit(ST_TXBUSY, &portp->state);
  961. clear_bit(ST_RXSTOP, &portp->state);
  962. set_bit(TTY_IO_ERROR, &tty->flags);
  963. if (tty->ldisc.flush_buffer)
  964. (tty->ldisc.flush_buffer)(tty);
  965. set_bit(ST_DOFLUSHRX, &portp->state);
  966. stli_flushbuffer(tty);
  967. tty->closing = 0;
  968. portp->tty = NULL;
  969. if (portp->openwaitcnt) {
  970. if (portp->close_delay)
  971. msleep_interruptible(jiffies_to_msecs(portp->close_delay));
  972. wake_up_interruptible(&portp->open_wait);
  973. }
  974. portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  975. wake_up_interruptible(&portp->close_wait);
  976. }
  977. /*****************************************************************************/
  978. /*
  979. * Carry out first open operations on a port. This involves a number of
  980. * commands to be sent to the slave. We need to open the port, set the
  981. * notification events, set the initial port settings, get and set the
  982. * initial signal values. We sleep and wait in between each one. But
  983. * this still all happens pretty quickly.
  984. */
  985. static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
  986. {
  987. struct tty_struct *tty;
  988. asynotify_t nt;
  989. asyport_t aport;
  990. int rc;
  991. if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
  992. return rc;
  993. memset(&nt, 0, sizeof(asynotify_t));
  994. nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
  995. nt.signal = SG_DCD;
  996. if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
  997. sizeof(asynotify_t), 0)) < 0)
  998. return rc;
  999. tty = portp->tty;
  1000. if (tty == NULL)
  1001. return -ENODEV;
  1002. stli_mkasyport(portp, &aport, tty->termios);
  1003. if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
  1004. sizeof(asyport_t), 0)) < 0)
  1005. return rc;
  1006. set_bit(ST_GETSIGS, &portp->state);
  1007. if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
  1008. sizeof(asysigs_t), 1)) < 0)
  1009. return rc;
  1010. if (test_and_clear_bit(ST_GETSIGS, &portp->state))
  1011. portp->sigs = stli_mktiocm(portp->asig.sigvalue);
  1012. stli_mkasysigs(&portp->asig, 1, 1);
  1013. if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1014. sizeof(asysigs_t), 0)) < 0)
  1015. return rc;
  1016. return 0;
  1017. }
  1018. /*****************************************************************************/
  1019. /*
  1020. * Send an open message to the slave. This will sleep waiting for the
  1021. * acknowledgement, so must have user context. We need to co-ordinate
  1022. * with close events here, since we don't want open and close events
  1023. * to overlap.
  1024. */
  1025. static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
  1026. {
  1027. cdkhdr_t __iomem *hdrp;
  1028. cdkctrl_t __iomem *cp;
  1029. unsigned char __iomem *bits;
  1030. unsigned long flags;
  1031. int rc;
  1032. /*
  1033. * Send a message to the slave to open this port.
  1034. */
  1035. /*
  1036. * Slave is already closing this port. This can happen if a hangup
  1037. * occurs on this port. So we must wait until it is complete. The
  1038. * order of opens and closes may not be preserved across shared
  1039. * memory, so we must wait until it is complete.
  1040. */
  1041. wait_event_interruptible(portp->raw_wait,
  1042. !test_bit(ST_CLOSING, &portp->state));
  1043. if (signal_pending(current)) {
  1044. return -ERESTARTSYS;
  1045. }
  1046. /*
  1047. * Everything is ready now, so write the open message into shared
  1048. * memory. Once the message is in set the service bits to say that
  1049. * this port wants service.
  1050. */
  1051. spin_lock_irqsave(&brd_lock, flags);
  1052. EBRDENABLE(brdp);
  1053. cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  1054. writel(arg, &cp->openarg);
  1055. writeb(1, &cp->open);
  1056. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1057. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  1058. portp->portidx;
  1059. writeb(readb(bits) | portp->portbit, bits);
  1060. EBRDDISABLE(brdp);
  1061. if (wait == 0) {
  1062. spin_unlock_irqrestore(&brd_lock, flags);
  1063. return 0;
  1064. }
  1065. /*
  1066. * Slave is in action, so now we must wait for the open acknowledgment
  1067. * to come back.
  1068. */
  1069. rc = 0;
  1070. set_bit(ST_OPENING, &portp->state);
  1071. spin_unlock_irqrestore(&brd_lock, flags);
  1072. wait_event_interruptible(portp->raw_wait,
  1073. !test_bit(ST_OPENING, &portp->state));
  1074. if (signal_pending(current))
  1075. rc = -ERESTARTSYS;
  1076. if ((rc == 0) && (portp->rc != 0))
  1077. rc = -EIO;
  1078. return rc;
  1079. }
  1080. /*****************************************************************************/
  1081. /*
  1082. * Send a close message to the slave. Normally this will sleep waiting
  1083. * for the acknowledgement, but if wait parameter is 0 it will not. If
  1084. * wait is true then must have user context (to sleep).
  1085. */
  1086. static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
  1087. {
  1088. cdkhdr_t __iomem *hdrp;
  1089. cdkctrl_t __iomem *cp;
  1090. unsigned char __iomem *bits;
  1091. unsigned long flags;
  1092. int rc;
  1093. /*
  1094. * Slave is already closing this port. This can happen if a hangup
  1095. * occurs on this port.
  1096. */
  1097. if (wait) {
  1098. wait_event_interruptible(portp->raw_wait,
  1099. !test_bit(ST_CLOSING, &portp->state));
  1100. if (signal_pending(current)) {
  1101. return -ERESTARTSYS;
  1102. }
  1103. }
  1104. /*
  1105. * Write the close command into shared memory.
  1106. */
  1107. spin_lock_irqsave(&brd_lock, flags);
  1108. EBRDENABLE(brdp);
  1109. cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  1110. writel(arg, &cp->closearg);
  1111. writeb(1, &cp->close);
  1112. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1113. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  1114. portp->portidx;
  1115. writeb(readb(bits) |portp->portbit, bits);
  1116. EBRDDISABLE(brdp);
  1117. set_bit(ST_CLOSING, &portp->state);
  1118. spin_unlock_irqrestore(&brd_lock, flags);
  1119. if (wait == 0)
  1120. return 0;
  1121. /*
  1122. * Slave is in action, so now we must wait for the open acknowledgment
  1123. * to come back.
  1124. */
  1125. rc = 0;
  1126. wait_event_interruptible(portp->raw_wait,
  1127. !test_bit(ST_CLOSING, &portp->state));
  1128. if (signal_pending(current))
  1129. rc = -ERESTARTSYS;
  1130. if ((rc == 0) && (portp->rc != 0))
  1131. rc = -EIO;
  1132. return rc;
  1133. }
  1134. /*****************************************************************************/
  1135. /*
  1136. * Send a command to the slave and wait for the response. This must
  1137. * have user context (it sleeps). This routine is generic in that it
  1138. * can send any type of command. Its purpose is to wait for that command
  1139. * to complete (as opposed to initiating the command then returning).
  1140. */
  1141. static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
  1142. {
  1143. wait_event_interruptible(portp->raw_wait,
  1144. !test_bit(ST_CMDING, &portp->state));
  1145. if (signal_pending(current))
  1146. return -ERESTARTSYS;
  1147. stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
  1148. wait_event_interruptible(portp->raw_wait,
  1149. !test_bit(ST_CMDING, &portp->state));
  1150. if (signal_pending(current))
  1151. return -ERESTARTSYS;
  1152. if (portp->rc != 0)
  1153. return -EIO;
  1154. return 0;
  1155. }
  1156. /*****************************************************************************/
  1157. /*
  1158. * Send the termios settings for this port to the slave. This sleeps
  1159. * waiting for the command to complete - so must have user context.
  1160. */
  1161. static int stli_setport(stliport_t *portp)
  1162. {
  1163. stlibrd_t *brdp;
  1164. asyport_t aport;
  1165. if (portp == NULL)
  1166. return -ENODEV;
  1167. if (portp->tty == NULL)
  1168. return -ENODEV;
  1169. if (portp->brdnr < 0 && portp->brdnr >= stli_nrbrds)
  1170. return -ENODEV;
  1171. brdp = stli_brds[portp->brdnr];
  1172. if (brdp == NULL)
  1173. return -ENODEV;
  1174. stli_mkasyport(portp, &aport, portp->tty->termios);
  1175. return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
  1176. }
  1177. /*****************************************************************************/
  1178. /*
  1179. * Possibly need to wait for carrier (DCD signal) to come high. Say
  1180. * maybe because if we are clocal then we don't need to wait...
  1181. */
  1182. static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
  1183. {
  1184. unsigned long flags;
  1185. int rc, doclocal;
  1186. rc = 0;
  1187. doclocal = 0;
  1188. if (portp->tty->termios->c_cflag & CLOCAL)
  1189. doclocal++;
  1190. spin_lock_irqsave(&stli_lock, flags);
  1191. portp->openwaitcnt++;
  1192. if (! tty_hung_up_p(filp))
  1193. portp->refcount--;
  1194. spin_unlock_irqrestore(&stli_lock, flags);
  1195. for (;;) {
  1196. stli_mkasysigs(&portp->asig, 1, 1);
  1197. if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
  1198. &portp->asig, sizeof(asysigs_t), 0)) < 0)
  1199. break;
  1200. if (tty_hung_up_p(filp) ||
  1201. ((portp->flags & ASYNC_INITIALIZED) == 0)) {
  1202. if (portp->flags & ASYNC_HUP_NOTIFY)
  1203. rc = -EBUSY;
  1204. else
  1205. rc = -ERESTARTSYS;
  1206. break;
  1207. }
  1208. if (((portp->flags & ASYNC_CLOSING) == 0) &&
  1209. (doclocal || (portp->sigs & TIOCM_CD))) {
  1210. break;
  1211. }
  1212. if (signal_pending(current)) {
  1213. rc = -ERESTARTSYS;
  1214. break;
  1215. }
  1216. interruptible_sleep_on(&portp->open_wait);
  1217. }
  1218. spin_lock_irqsave(&stli_lock, flags);
  1219. if (! tty_hung_up_p(filp))
  1220. portp->refcount++;
  1221. portp->openwaitcnt--;
  1222. spin_unlock_irqrestore(&stli_lock, flags);
  1223. return rc;
  1224. }
  1225. /*****************************************************************************/
  1226. /*
  1227. * Write routine. Take the data and put it in the shared memory ring
  1228. * queue. If port is not already sending chars then need to mark the
  1229. * service bits for this port.
  1230. */
  1231. static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
  1232. {
  1233. cdkasy_t __iomem *ap;
  1234. cdkhdr_t __iomem *hdrp;
  1235. unsigned char __iomem *bits;
  1236. unsigned char __iomem *shbuf;
  1237. unsigned char *chbuf;
  1238. stliport_t *portp;
  1239. stlibrd_t *brdp;
  1240. unsigned int len, stlen, head, tail, size;
  1241. unsigned long flags;
  1242. if (tty == stli_txcooktty)
  1243. stli_flushchars(tty);
  1244. portp = tty->driver_data;
  1245. if (portp == NULL)
  1246. return 0;
  1247. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1248. return 0;
  1249. brdp = stli_brds[portp->brdnr];
  1250. if (brdp == NULL)
  1251. return 0;
  1252. chbuf = (unsigned char *) buf;
  1253. /*
  1254. * All data is now local, shove as much as possible into shared memory.
  1255. */
  1256. spin_lock_irqsave(&brd_lock, flags);
  1257. EBRDENABLE(brdp);
  1258. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1259. head = (unsigned int) readw(&ap->txq.head);
  1260. tail = (unsigned int) readw(&ap->txq.tail);
  1261. if (tail != ((unsigned int) readw(&ap->txq.tail)))
  1262. tail = (unsigned int) readw(&ap->txq.tail);
  1263. size = portp->txsize;
  1264. if (head >= tail) {
  1265. len = size - (head - tail) - 1;
  1266. stlen = size - head;
  1267. } else {
  1268. len = tail - head - 1;
  1269. stlen = len;
  1270. }
  1271. len = MIN(len, count);
  1272. count = 0;
  1273. shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
  1274. while (len > 0) {
  1275. stlen = MIN(len, stlen);
  1276. memcpy_toio(shbuf + head, chbuf, stlen);
  1277. chbuf += stlen;
  1278. len -= stlen;
  1279. count += stlen;
  1280. head += stlen;
  1281. if (head >= size) {
  1282. head = 0;
  1283. stlen = tail;
  1284. }
  1285. }
  1286. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1287. writew(head, &ap->txq.head);
  1288. if (test_bit(ST_TXBUSY, &portp->state)) {
  1289. if (readl(&ap->changed.data) & DT_TXEMPTY)
  1290. writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
  1291. }
  1292. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1293. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  1294. portp->portidx;
  1295. writeb(readb(bits) | portp->portbit, bits);
  1296. set_bit(ST_TXBUSY, &portp->state);
  1297. EBRDDISABLE(brdp);
  1298. spin_unlock_irqrestore(&brd_lock, flags);
  1299. return(count);
  1300. }
  1301. /*****************************************************************************/
  1302. /*
  1303. * Output a single character. We put it into a temporary local buffer
  1304. * (for speed) then write out that buffer when the flushchars routine
  1305. * is called. There is a safety catch here so that if some other port
  1306. * writes chars before the current buffer has been, then we write them
  1307. * first them do the new ports.
  1308. */
  1309. static void stli_putchar(struct tty_struct *tty, unsigned char ch)
  1310. {
  1311. if (tty != stli_txcooktty) {
  1312. if (stli_txcooktty != NULL)
  1313. stli_flushchars(stli_txcooktty);
  1314. stli_txcooktty = tty;
  1315. }
  1316. stli_txcookbuf[stli_txcooksize++] = ch;
  1317. }
  1318. /*****************************************************************************/
  1319. /*
  1320. * Transfer characters from the local TX cooking buffer to the board.
  1321. * We sort of ignore the tty that gets passed in here. We rely on the
  1322. * info stored with the TX cook buffer to tell us which port to flush
  1323. * the data on. In any case we clean out the TX cook buffer, for re-use
  1324. * by someone else.
  1325. */
  1326. static void stli_flushchars(struct tty_struct *tty)
  1327. {
  1328. cdkhdr_t __iomem *hdrp;
  1329. unsigned char __iomem *bits;
  1330. cdkasy_t __iomem *ap;
  1331. struct tty_struct *cooktty;
  1332. stliport_t *portp;
  1333. stlibrd_t *brdp;
  1334. unsigned int len, stlen, head, tail, size, count, cooksize;
  1335. unsigned char *buf;
  1336. unsigned char __iomem *shbuf;
  1337. unsigned long flags;
  1338. cooksize = stli_txcooksize;
  1339. cooktty = stli_txcooktty;
  1340. stli_txcooksize = 0;
  1341. stli_txcookrealsize = 0;
  1342. stli_txcooktty = NULL;
  1343. if (tty == NULL)
  1344. return;
  1345. if (cooktty == NULL)
  1346. return;
  1347. if (tty != cooktty)
  1348. tty = cooktty;
  1349. if (cooksize == 0)
  1350. return;
  1351. portp = tty->driver_data;
  1352. if (portp == NULL)
  1353. return;
  1354. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1355. return;
  1356. brdp = stli_brds[portp->brdnr];
  1357. if (brdp == NULL)
  1358. return;
  1359. spin_lock_irqsave(&brd_lock, flags);
  1360. EBRDENABLE(brdp);
  1361. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1362. head = (unsigned int) readw(&ap->txq.head);
  1363. tail = (unsigned int) readw(&ap->txq.tail);
  1364. if (tail != ((unsigned int) readw(&ap->txq.tail)))
  1365. tail = (unsigned int) readw(&ap->txq.tail);
  1366. size = portp->txsize;
  1367. if (head >= tail) {
  1368. len = size - (head - tail) - 1;
  1369. stlen = size - head;
  1370. } else {
  1371. len = tail - head - 1;
  1372. stlen = len;
  1373. }
  1374. len = MIN(len, cooksize);
  1375. count = 0;
  1376. shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
  1377. buf = stli_txcookbuf;
  1378. while (len > 0) {
  1379. stlen = MIN(len, stlen);
  1380. memcpy_toio(shbuf + head, buf, stlen);
  1381. buf += stlen;
  1382. len -= stlen;
  1383. count += stlen;
  1384. head += stlen;
  1385. if (head >= size) {
  1386. head = 0;
  1387. stlen = tail;
  1388. }
  1389. }
  1390. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1391. writew(head, &ap->txq.head);
  1392. if (test_bit(ST_TXBUSY, &portp->state)) {
  1393. if (readl(&ap->changed.data) & DT_TXEMPTY)
  1394. writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
  1395. }
  1396. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1397. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  1398. portp->portidx;
  1399. writeb(readb(bits) | portp->portbit, bits);
  1400. set_bit(ST_TXBUSY, &portp->state);
  1401. EBRDDISABLE(brdp);
  1402. spin_unlock_irqrestore(&brd_lock, flags);
  1403. }
  1404. /*****************************************************************************/
  1405. static int stli_writeroom(struct tty_struct *tty)
  1406. {
  1407. cdkasyrq_t __iomem *rp;
  1408. stliport_t *portp;
  1409. stlibrd_t *brdp;
  1410. unsigned int head, tail, len;
  1411. unsigned long flags;
  1412. if (tty == stli_txcooktty) {
  1413. if (stli_txcookrealsize != 0) {
  1414. len = stli_txcookrealsize - stli_txcooksize;
  1415. return len;
  1416. }
  1417. }
  1418. portp = tty->driver_data;
  1419. if (portp == NULL)
  1420. return 0;
  1421. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1422. return 0;
  1423. brdp = stli_brds[portp->brdnr];
  1424. if (brdp == NULL)
  1425. return 0;
  1426. spin_lock_irqsave(&brd_lock, flags);
  1427. EBRDENABLE(brdp);
  1428. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
  1429. head = (unsigned int) readw(&rp->head);
  1430. tail = (unsigned int) readw(&rp->tail);
  1431. if (tail != ((unsigned int) readw(&rp->tail)))
  1432. tail = (unsigned int) readw(&rp->tail);
  1433. len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
  1434. len--;
  1435. EBRDDISABLE(brdp);
  1436. spin_unlock_irqrestore(&brd_lock, flags);
  1437. if (tty == stli_txcooktty) {
  1438. stli_txcookrealsize = len;
  1439. len -= stli_txcooksize;
  1440. }
  1441. return len;
  1442. }
  1443. /*****************************************************************************/
  1444. /*
  1445. * Return the number of characters in the transmit buffer. Normally we
  1446. * will return the number of chars in the shared memory ring queue.
  1447. * We need to kludge around the case where the shared memory buffer is
  1448. * empty but not all characters have drained yet, for this case just
  1449. * return that there is 1 character in the buffer!
  1450. */
  1451. static int stli_charsinbuffer(struct tty_struct *tty)
  1452. {
  1453. cdkasyrq_t __iomem *rp;
  1454. stliport_t *portp;
  1455. stlibrd_t *brdp;
  1456. unsigned int head, tail, len;
  1457. unsigned long flags;
  1458. if (tty == stli_txcooktty)
  1459. stli_flushchars(tty);
  1460. portp = tty->driver_data;
  1461. if (portp == NULL)
  1462. return 0;
  1463. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1464. return 0;
  1465. brdp = stli_brds[portp->brdnr];
  1466. if (brdp == NULL)
  1467. return 0;
  1468. spin_lock_irqsave(&brd_lock, flags);
  1469. EBRDENABLE(brdp);
  1470. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
  1471. head = (unsigned int) readw(&rp->head);
  1472. tail = (unsigned int) readw(&rp->tail);
  1473. if (tail != ((unsigned int) readw(&rp->tail)))
  1474. tail = (unsigned int) readw(&rp->tail);
  1475. len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
  1476. if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
  1477. len = 1;
  1478. EBRDDISABLE(brdp);
  1479. spin_unlock_irqrestore(&brd_lock, flags);
  1480. return len;
  1481. }
  1482. /*****************************************************************************/
  1483. /*
  1484. * Generate the serial struct info.
  1485. */
  1486. static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
  1487. {
  1488. struct serial_struct sio;
  1489. stlibrd_t *brdp;
  1490. memset(&sio, 0, sizeof(struct serial_struct));
  1491. sio.type = PORT_UNKNOWN;
  1492. sio.line = portp->portnr;
  1493. sio.irq = 0;
  1494. sio.flags = portp->flags;
  1495. sio.baud_base = portp->baud_base;
  1496. sio.close_delay = portp->close_delay;
  1497. sio.closing_wait = portp->closing_wait;
  1498. sio.custom_divisor = portp->custom_divisor;
  1499. sio.xmit_fifo_size = 0;
  1500. sio.hub6 = 0;
  1501. brdp = stli_brds[portp->brdnr];
  1502. if (brdp != NULL)
  1503. sio.port = brdp->iobase;
  1504. return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
  1505. -EFAULT : 0;
  1506. }
  1507. /*****************************************************************************/
  1508. /*
  1509. * Set port according to the serial struct info.
  1510. * At this point we do not do any auto-configure stuff, so we will
  1511. * just quietly ignore any requests to change irq, etc.
  1512. */
  1513. static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
  1514. {
  1515. struct serial_struct sio;
  1516. int rc;
  1517. if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
  1518. return -EFAULT;
  1519. if (!capable(CAP_SYS_ADMIN)) {
  1520. if ((sio.baud_base != portp->baud_base) ||
  1521. (sio.close_delay != portp->close_delay) ||
  1522. ((sio.flags & ~ASYNC_USR_MASK) !=
  1523. (portp->flags & ~ASYNC_USR_MASK)))
  1524. return -EPERM;
  1525. }
  1526. portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
  1527. (sio.flags & ASYNC_USR_MASK);
  1528. portp->baud_base = sio.baud_base;
  1529. portp->close_delay = sio.close_delay;
  1530. portp->closing_wait = sio.closing_wait;
  1531. portp->custom_divisor = sio.custom_divisor;
  1532. if ((rc = stli_setport(portp)) < 0)
  1533. return rc;
  1534. return 0;
  1535. }
  1536. /*****************************************************************************/
  1537. static int stli_tiocmget(struct tty_struct *tty, struct file *file)
  1538. {
  1539. stliport_t *portp = tty->driver_data;
  1540. stlibrd_t *brdp;
  1541. int rc;
  1542. if (portp == NULL)
  1543. return -ENODEV;
  1544. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1545. return 0;
  1546. brdp = stli_brds[portp->brdnr];
  1547. if (brdp == NULL)
  1548. return 0;
  1549. if (tty->flags & (1 << TTY_IO_ERROR))
  1550. return -EIO;
  1551. if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
  1552. &portp->asig, sizeof(asysigs_t), 1)) < 0)
  1553. return rc;
  1554. return stli_mktiocm(portp->asig.sigvalue);
  1555. }
  1556. static int stli_tiocmset(struct tty_struct *tty, struct file *file,
  1557. unsigned int set, unsigned int clear)
  1558. {
  1559. stliport_t *portp = tty->driver_data;
  1560. stlibrd_t *brdp;
  1561. int rts = -1, dtr = -1;
  1562. if (portp == NULL)
  1563. return -ENODEV;
  1564. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1565. return 0;
  1566. brdp = stli_brds[portp->brdnr];
  1567. if (brdp == NULL)
  1568. return 0;
  1569. if (tty->flags & (1 << TTY_IO_ERROR))
  1570. return -EIO;
  1571. if (set & TIOCM_RTS)
  1572. rts = 1;
  1573. if (set & TIOCM_DTR)
  1574. dtr = 1;
  1575. if (clear & TIOCM_RTS)
  1576. rts = 0;
  1577. if (clear & TIOCM_DTR)
  1578. dtr = 0;
  1579. stli_mkasysigs(&portp->asig, dtr, rts);
  1580. return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1581. sizeof(asysigs_t), 0);
  1582. }
  1583. static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
  1584. {
  1585. stliport_t *portp;
  1586. stlibrd_t *brdp;
  1587. unsigned int ival;
  1588. int rc;
  1589. void __user *argp = (void __user *)arg;
  1590. portp = tty->driver_data;
  1591. if (portp == NULL)
  1592. return -ENODEV;
  1593. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1594. return 0;
  1595. brdp = stli_brds[portp->brdnr];
  1596. if (brdp == NULL)
  1597. return 0;
  1598. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1599. (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
  1600. if (tty->flags & (1 << TTY_IO_ERROR))
  1601. return -EIO;
  1602. }
  1603. rc = 0;
  1604. switch (cmd) {
  1605. case TIOCGSOFTCAR:
  1606. rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
  1607. (unsigned __user *) arg);
  1608. break;
  1609. case TIOCSSOFTCAR:
  1610. if ((rc = get_user(ival, (unsigned __user *) arg)) == 0)
  1611. tty->termios->c_cflag =
  1612. (tty->termios->c_cflag & ~CLOCAL) |
  1613. (ival ? CLOCAL : 0);
  1614. break;
  1615. case TIOCGSERIAL:
  1616. rc = stli_getserial(portp, argp);
  1617. break;
  1618. case TIOCSSERIAL:
  1619. rc = stli_setserial(portp, argp);
  1620. break;
  1621. case STL_GETPFLAG:
  1622. rc = put_user(portp->pflag, (unsigned __user *)argp);
  1623. break;
  1624. case STL_SETPFLAG:
  1625. if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0)
  1626. stli_setport(portp);
  1627. break;
  1628. case COM_GETPORTSTATS:
  1629. rc = stli_getportstats(portp, argp);
  1630. break;
  1631. case COM_CLRPORTSTATS:
  1632. rc = stli_clrportstats(portp, argp);
  1633. break;
  1634. case TIOCSERCONFIG:
  1635. case TIOCSERGWILD:
  1636. case TIOCSERSWILD:
  1637. case TIOCSERGETLSR:
  1638. case TIOCSERGSTRUCT:
  1639. case TIOCSERGETMULTI:
  1640. case TIOCSERSETMULTI:
  1641. default:
  1642. rc = -ENOIOCTLCMD;
  1643. break;
  1644. }
  1645. return rc;
  1646. }
  1647. /*****************************************************************************/
  1648. /*
  1649. * This routine assumes that we have user context and can sleep.
  1650. * Looks like it is true for the current ttys implementation..!!
  1651. */
  1652. static void stli_settermios(struct tty_struct *tty, struct termios *old)
  1653. {
  1654. stliport_t *portp;
  1655. stlibrd_t *brdp;
  1656. struct termios *tiosp;
  1657. asyport_t aport;
  1658. if (tty == NULL)
  1659. return;
  1660. portp = tty->driver_data;
  1661. if (portp == NULL)
  1662. return;
  1663. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1664. return;
  1665. brdp = stli_brds[portp->brdnr];
  1666. if (brdp == NULL)
  1667. return;
  1668. tiosp = tty->termios;
  1669. if ((tiosp->c_cflag == old->c_cflag) &&
  1670. (tiosp->c_iflag == old->c_iflag))
  1671. return;
  1672. stli_mkasyport(portp, &aport, tiosp);
  1673. stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
  1674. stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
  1675. stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1676. sizeof(asysigs_t), 0);
  1677. if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
  1678. tty->hw_stopped = 0;
  1679. if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
  1680. wake_up_interruptible(&portp->open_wait);
  1681. }
  1682. /*****************************************************************************/
  1683. /*
  1684. * Attempt to flow control who ever is sending us data. We won't really
  1685. * do any flow control action here. We can't directly, and even if we
  1686. * wanted to we would have to send a command to the slave. The slave
  1687. * knows how to flow control, and will do so when its buffers reach its
  1688. * internal high water marks. So what we will do is set a local state
  1689. * bit that will stop us sending any RX data up from the poll routine
  1690. * (which is the place where RX data from the slave is handled).
  1691. */
  1692. static void stli_throttle(struct tty_struct *tty)
  1693. {
  1694. stliport_t *portp = tty->driver_data;
  1695. if (portp == NULL)
  1696. return;
  1697. set_bit(ST_RXSTOP, &portp->state);
  1698. }
  1699. /*****************************************************************************/
  1700. /*
  1701. * Unflow control the device sending us data... That means that all
  1702. * we have to do is clear the RXSTOP state bit. The next poll call
  1703. * will then be able to pass the RX data back up.
  1704. */
  1705. static void stli_unthrottle(struct tty_struct *tty)
  1706. {
  1707. stliport_t *portp = tty->driver_data;
  1708. if (portp == NULL)
  1709. return;
  1710. clear_bit(ST_RXSTOP, &portp->state);
  1711. }
  1712. /*****************************************************************************/
  1713. /*
  1714. * Stop the transmitter.
  1715. */
  1716. static void stli_stop(struct tty_struct *tty)
  1717. {
  1718. }
  1719. /*****************************************************************************/
  1720. /*
  1721. * Start the transmitter again.
  1722. */
  1723. static void stli_start(struct tty_struct *tty)
  1724. {
  1725. }
  1726. /*****************************************************************************/
  1727. /*
  1728. * Scheduler called hang up routine. This is called from the scheduler,
  1729. * not direct from the driver "poll" routine. We can't call it there
  1730. * since the real local hangup code will enable/disable the board and
  1731. * other things that we can't do while handling the poll. Much easier
  1732. * to deal with it some time later (don't really care when, hangups
  1733. * aren't that time critical).
  1734. */
  1735. static void stli_dohangup(void *arg)
  1736. {
  1737. stliport_t *portp = (stliport_t *) arg;
  1738. if (portp->tty != NULL) {
  1739. tty_hangup(portp->tty);
  1740. }
  1741. }
  1742. /*****************************************************************************/
  1743. /*
  1744. * Hangup this port. This is pretty much like closing the port, only
  1745. * a little more brutal. No waiting for data to drain. Shutdown the
  1746. * port and maybe drop signals. This is rather tricky really. We want
  1747. * to close the port as well.
  1748. */
  1749. static void stli_hangup(struct tty_struct *tty)
  1750. {
  1751. stliport_t *portp;
  1752. stlibrd_t *brdp;
  1753. unsigned long flags;
  1754. portp = tty->driver_data;
  1755. if (portp == NULL)
  1756. return;
  1757. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1758. return;
  1759. brdp = stli_brds[portp->brdnr];
  1760. if (brdp == NULL)
  1761. return;
  1762. portp->flags &= ~ASYNC_INITIALIZED;
  1763. if (!test_bit(ST_CLOSING, &portp->state))
  1764. stli_rawclose(brdp, portp, 0, 0);
  1765. spin_lock_irqsave(&stli_lock, flags);
  1766. if (tty->termios->c_cflag & HUPCL) {
  1767. stli_mkasysigs(&portp->asig, 0, 0);
  1768. if (test_bit(ST_CMDING, &portp->state)) {
  1769. set_bit(ST_DOSIGS, &portp->state);
  1770. set_bit(ST_DOFLUSHTX, &portp->state);
  1771. set_bit(ST_DOFLUSHRX, &portp->state);
  1772. } else {
  1773. stli_sendcmd(brdp, portp, A_SETSIGNALSF,
  1774. &portp->asig, sizeof(asysigs_t), 0);
  1775. }
  1776. }
  1777. clear_bit(ST_TXBUSY, &portp->state);
  1778. clear_bit(ST_RXSTOP, &portp->state);
  1779. set_bit(TTY_IO_ERROR, &tty->flags);
  1780. portp->tty = NULL;
  1781. portp->flags &= ~ASYNC_NORMAL_ACTIVE;
  1782. portp->refcount = 0;
  1783. spin_unlock_irqrestore(&stli_lock, flags);
  1784. wake_up_interruptible(&portp->open_wait);
  1785. }
  1786. /*****************************************************************************/
  1787. /*
  1788. * Flush characters from the lower buffer. We may not have user context
  1789. * so we cannot sleep waiting for it to complete. Also we need to check
  1790. * if there is chars for this port in the TX cook buffer, and flush them
  1791. * as well.
  1792. */
  1793. static void stli_flushbuffer(struct tty_struct *tty)
  1794. {
  1795. stliport_t *portp;
  1796. stlibrd_t *brdp;
  1797. unsigned long ftype, flags;
  1798. portp = tty->driver_data;
  1799. if (portp == NULL)
  1800. return;
  1801. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1802. return;
  1803. brdp = stli_brds[portp->brdnr];
  1804. if (brdp == NULL)
  1805. return;
  1806. spin_lock_irqsave(&brd_lock, flags);
  1807. if (tty == stli_txcooktty) {
  1808. stli_txcooktty = NULL;
  1809. stli_txcooksize = 0;
  1810. stli_txcookrealsize = 0;
  1811. }
  1812. if (test_bit(ST_CMDING, &portp->state)) {
  1813. set_bit(ST_DOFLUSHTX, &portp->state);
  1814. } else {
  1815. ftype = FLUSHTX;
  1816. if (test_bit(ST_DOFLUSHRX, &portp->state)) {
  1817. ftype |= FLUSHRX;
  1818. clear_bit(ST_DOFLUSHRX, &portp->state);
  1819. }
  1820. __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
  1821. }
  1822. spin_unlock_irqrestore(&brd_lock, flags);
  1823. tty_wakeup(tty);
  1824. }
  1825. /*****************************************************************************/
  1826. static void stli_breakctl(struct tty_struct *tty, int state)
  1827. {
  1828. stlibrd_t *brdp;
  1829. stliport_t *portp;
  1830. long arg;
  1831. portp = tty->driver_data;
  1832. if (portp == NULL)
  1833. return;
  1834. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1835. return;
  1836. brdp = stli_brds[portp->brdnr];
  1837. if (brdp == NULL)
  1838. return;
  1839. arg = (state == -1) ? BREAKON : BREAKOFF;
  1840. stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
  1841. }
  1842. /*****************************************************************************/
  1843. static void stli_waituntilsent(struct tty_struct *tty, int timeout)
  1844. {
  1845. stliport_t *portp;
  1846. unsigned long tend;
  1847. if (tty == NULL)
  1848. return;
  1849. portp = tty->driver_data;
  1850. if (portp == NULL)
  1851. return;
  1852. if (timeout == 0)
  1853. timeout = HZ;
  1854. tend = jiffies + timeout;
  1855. while (test_bit(ST_TXBUSY, &portp->state)) {
  1856. if (signal_pending(current))
  1857. break;
  1858. msleep_interruptible(20);
  1859. if (time_after_eq(jiffies, tend))
  1860. break;
  1861. }
  1862. }
  1863. /*****************************************************************************/
  1864. static void stli_sendxchar(struct tty_struct *tty, char ch)
  1865. {
  1866. stlibrd_t *brdp;
  1867. stliport_t *portp;
  1868. asyctrl_t actrl;
  1869. portp = tty->driver_data;
  1870. if (portp == NULL)
  1871. return;
  1872. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1873. return;
  1874. brdp = stli_brds[portp->brdnr];
  1875. if (brdp == NULL)
  1876. return;
  1877. memset(&actrl, 0, sizeof(asyctrl_t));
  1878. if (ch == STOP_CHAR(tty)) {
  1879. actrl.rxctrl = CT_STOPFLOW;
  1880. } else if (ch == START_CHAR(tty)) {
  1881. actrl.rxctrl = CT_STARTFLOW;
  1882. } else {
  1883. actrl.txctrl = CT_SENDCHR;
  1884. actrl.tximdch = ch;
  1885. }
  1886. stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
  1887. }
  1888. /*****************************************************************************/
  1889. #define MAXLINE 80
  1890. /*
  1891. * Format info for a specified port. The line is deliberately limited
  1892. * to 80 characters. (If it is too long it will be truncated, if too
  1893. * short then padded with spaces).
  1894. */
  1895. static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos)
  1896. {
  1897. char *sp, *uart;
  1898. int rc, cnt;
  1899. rc = stli_portcmdstats(portp);
  1900. uart = "UNKNOWN";
  1901. if (brdp->state & BST_STARTED) {
  1902. switch (stli_comstats.hwid) {
  1903. case 0: uart = "2681"; break;
  1904. case 1: uart = "SC26198"; break;
  1905. default:uart = "CD1400"; break;
  1906. }
  1907. }
  1908. sp = pos;
  1909. sp += sprintf(sp, "%d: uart:%s ", portnr, uart);
  1910. if ((brdp->state & BST_STARTED) && (rc >= 0)) {
  1911. sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal,
  1912. (int) stli_comstats.rxtotal);
  1913. if (stli_comstats.rxframing)
  1914. sp += sprintf(sp, " fe:%d",
  1915. (int) stli_comstats.rxframing);
  1916. if (stli_comstats.rxparity)
  1917. sp += sprintf(sp, " pe:%d",
  1918. (int) stli_comstats.rxparity);
  1919. if (stli_comstats.rxbreaks)
  1920. sp += sprintf(sp, " brk:%d",
  1921. (int) stli_comstats.rxbreaks);
  1922. if (stli_comstats.rxoverrun)
  1923. sp += sprintf(sp, " oe:%d",
  1924. (int) stli_comstats.rxoverrun);
  1925. cnt = sprintf(sp, "%s%s%s%s%s ",
  1926. (stli_comstats.signals & TIOCM_RTS) ? "|RTS" : "",
  1927. (stli_comstats.signals & TIOCM_CTS) ? "|CTS" : "",
  1928. (stli_comstats.signals & TIOCM_DTR) ? "|DTR" : "",
  1929. (stli_comstats.signals & TIOCM_CD) ? "|DCD" : "",
  1930. (stli_comstats.signals & TIOCM_DSR) ? "|DSR" : "");
  1931. *sp = ' ';
  1932. sp += cnt;
  1933. }
  1934. for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
  1935. *sp++ = ' ';
  1936. if (cnt >= MAXLINE)
  1937. pos[(MAXLINE - 2)] = '+';
  1938. pos[(MAXLINE - 1)] = '\n';
  1939. return(MAXLINE);
  1940. }
  1941. /*****************************************************************************/
  1942. /*
  1943. * Port info, read from the /proc file system.
  1944. */
  1945. static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
  1946. {
  1947. stlibrd_t *brdp;
  1948. stliport_t *portp;
  1949. int brdnr, portnr, totalport;
  1950. int curoff, maxoff;
  1951. char *pos;
  1952. pos = page;
  1953. totalport = 0;
  1954. curoff = 0;
  1955. if (off == 0) {
  1956. pos += sprintf(pos, "%s: version %s", stli_drvtitle,
  1957. stli_drvversion);
  1958. while (pos < (page + MAXLINE - 1))
  1959. *pos++ = ' ';
  1960. *pos++ = '\n';
  1961. }
  1962. curoff = MAXLINE;
  1963. /*
  1964. * We scan through for each board, panel and port. The offset is
  1965. * calculated on the fly, and irrelevant ports are skipped.
  1966. */
  1967. for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
  1968. brdp = stli_brds[brdnr];
  1969. if (brdp == NULL)
  1970. continue;
  1971. if (brdp->state == 0)
  1972. continue;
  1973. maxoff = curoff + (brdp->nrports * MAXLINE);
  1974. if (off >= maxoff) {
  1975. curoff = maxoff;
  1976. continue;
  1977. }
  1978. totalport = brdnr * STL_MAXPORTS;
  1979. for (portnr = 0; (portnr < brdp->nrports); portnr++,
  1980. totalport++) {
  1981. portp = brdp->ports[portnr];
  1982. if (portp == NULL)
  1983. continue;
  1984. if (off >= (curoff += MAXLINE))
  1985. continue;
  1986. if ((pos - page + MAXLINE) > count)
  1987. goto stli_readdone;
  1988. pos += stli_portinfo(brdp, portp, totalport, pos);
  1989. }
  1990. }
  1991. *eof = 1;
  1992. stli_readdone:
  1993. *start = page;
  1994. return(pos - page);
  1995. }
  1996. /*****************************************************************************/
  1997. /*
  1998. * Generic send command routine. This will send a message to the slave,
  1999. * of the specified type with the specified argument. Must be very
  2000. * careful of data that will be copied out from shared memory -
  2001. * containing command results. The command completion is all done from
  2002. * a poll routine that does not have user context. Therefore you cannot
  2003. * copy back directly into user space, or to the kernel stack of a
  2004. * process. This routine does not sleep, so can be called from anywhere.
  2005. *
  2006. * The caller must hold the brd_lock (see also stli_sendcmd the usual
  2007. * entry point)
  2008. */
  2009. static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
  2010. {
  2011. cdkhdr_t __iomem *hdrp;
  2012. cdkctrl_t __iomem *cp;
  2013. unsigned char __iomem *bits;
  2014. unsigned long flags;
  2015. spin_lock_irqsave(&brd_lock, flags);
  2016. if (test_bit(ST_CMDING, &portp->state)) {
  2017. printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
  2018. (int) cmd);
  2019. spin_unlock_irqrestore(&brd_lock, flags);
  2020. return;
  2021. }
  2022. EBRDENABLE(brdp);
  2023. cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  2024. if (size > 0) {
  2025. memcpy_toio((void __iomem *) &(cp->args[0]), arg, size);
  2026. if (copyback) {
  2027. portp->argp = arg;
  2028. portp->argsize = size;
  2029. }
  2030. }
  2031. writel(0, &cp->status);
  2032. writel(cmd, &cp->cmd);
  2033. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2034. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  2035. portp->portidx;
  2036. writeb(readb(bits) | portp->portbit, bits);
  2037. set_bit(ST_CMDING, &portp->state);
  2038. EBRDDISABLE(brdp);
  2039. spin_unlock_irqrestore(&brd_lock, flags);
  2040. }
  2041. static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
  2042. {
  2043. unsigned long flags;
  2044. spin_lock_irqsave(&brd_lock, flags);
  2045. __stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
  2046. spin_unlock_irqrestore(&brd_lock, flags);
  2047. }
  2048. /*****************************************************************************/
  2049. /*
  2050. * Read data from shared memory. This assumes that the shared memory
  2051. * is enabled and that interrupts are off. Basically we just empty out
  2052. * the shared memory buffer into the tty buffer. Must be careful to
  2053. * handle the case where we fill up the tty buffer, but still have
  2054. * more chars to unload.
  2055. */
  2056. static void stli_read(stlibrd_t *brdp, stliport_t *portp)
  2057. {
  2058. cdkasyrq_t __iomem *rp;
  2059. char __iomem *shbuf;
  2060. struct tty_struct *tty;
  2061. unsigned int head, tail, size;
  2062. unsigned int len, stlen;
  2063. if (test_bit(ST_RXSTOP, &portp->state))
  2064. return;
  2065. tty = portp->tty;
  2066. if (tty == NULL)
  2067. return;
  2068. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
  2069. head = (unsigned int) readw(&rp->head);
  2070. if (head != ((unsigned int) readw(&rp->head)))
  2071. head = (unsigned int) readw(&rp->head);
  2072. tail = (unsigned int) readw(&rp->tail);
  2073. size = portp->rxsize;
  2074. if (head >= tail) {
  2075. len = head - tail;
  2076. stlen = len;
  2077. } else {
  2078. len = size - (tail - head);
  2079. stlen = size - tail;
  2080. }
  2081. len = tty_buffer_request_room(tty, len);
  2082. shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset);
  2083. while (len > 0) {
  2084. unsigned char *cptr;
  2085. stlen = MIN(len, stlen);
  2086. tty_prepare_flip_string(tty, &cptr, stlen);
  2087. memcpy_fromio(cptr, shbuf + tail, stlen);
  2088. len -= stlen;
  2089. tail += stlen;
  2090. if (tail >= size) {
  2091. tail = 0;
  2092. stlen = head;
  2093. }
  2094. }
  2095. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
  2096. writew(tail, &rp->tail);
  2097. if (head != tail)
  2098. set_bit(ST_RXING, &portp->state);
  2099. tty_schedule_flip(tty);
  2100. }
  2101. /*****************************************************************************/
  2102. /*
  2103. * Set up and carry out any delayed commands. There is only a small set
  2104. * of slave commands that can be done "off-level". So it is not too
  2105. * difficult to deal with them here.
  2106. */
  2107. static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp)
  2108. {
  2109. int cmd;
  2110. if (test_bit(ST_DOSIGS, &portp->state)) {
  2111. if (test_bit(ST_DOFLUSHTX, &portp->state) &&
  2112. test_bit(ST_DOFLUSHRX, &portp->state))
  2113. cmd = A_SETSIGNALSF;
  2114. else if (test_bit(ST_DOFLUSHTX, &portp->state))
  2115. cmd = A_SETSIGNALSFTX;
  2116. else if (test_bit(ST_DOFLUSHRX, &portp->state))
  2117. cmd = A_SETSIGNALSFRX;
  2118. else
  2119. cmd = A_SETSIGNALS;
  2120. clear_bit(ST_DOFLUSHTX, &portp->state);
  2121. clear_bit(ST_DOFLUSHRX, &portp->state);
  2122. clear_bit(ST_DOSIGS, &portp->state);
  2123. memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig,
  2124. sizeof(asysigs_t));
  2125. writel(0, &cp->status);
  2126. writel(cmd, &cp->cmd);
  2127. set_bit(ST_CMDING, &portp->state);
  2128. } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
  2129. test_bit(ST_DOFLUSHRX, &portp->state)) {
  2130. cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
  2131. cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
  2132. clear_bit(ST_DOFLUSHTX, &portp->state);
  2133. clear_bit(ST_DOFLUSHRX, &portp->state);
  2134. memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int));
  2135. writel(0, &cp->status);
  2136. writel(A_FLUSH, &cp->cmd);
  2137. set_bit(ST_CMDING, &portp->state);
  2138. }
  2139. }
  2140. /*****************************************************************************/
  2141. /*
  2142. * Host command service checking. This handles commands or messages
  2143. * coming from the slave to the host. Must have board shared memory
  2144. * enabled and interrupts off when called. Notice that by servicing the
  2145. * read data last we don't need to change the shared memory pointer
  2146. * during processing (which is a slow IO operation).
  2147. * Return value indicates if this port is still awaiting actions from
  2148. * the slave (like open, command, or even TX data being sent). If 0
  2149. * then port is still busy, otherwise no longer busy.
  2150. */
  2151. static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
  2152. {
  2153. cdkasy_t __iomem *ap;
  2154. cdkctrl_t __iomem *cp;
  2155. struct tty_struct *tty;
  2156. asynotify_t nt;
  2157. unsigned long oldsigs;
  2158. int rc, donerx;
  2159. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  2160. cp = &ap->ctrl;
  2161. /*
  2162. * Check if we are waiting for an open completion message.
  2163. */
  2164. if (test_bit(ST_OPENING, &portp->state)) {
  2165. rc = readl(&cp->openarg);
  2166. if (readb(&cp->open) == 0 && rc != 0) {
  2167. if (rc > 0)
  2168. rc--;
  2169. writel(0, &cp->openarg);
  2170. portp->rc = rc;
  2171. clear_bit(ST_OPENING, &portp->state);
  2172. wake_up_interruptible(&portp->raw_wait);
  2173. }
  2174. }
  2175. /*
  2176. * Check if we are waiting for a close completion message.
  2177. */
  2178. if (test_bit(ST_CLOSING, &portp->state)) {
  2179. rc = (int) readl(&cp->closearg);
  2180. if (readb(&cp->close) == 0 && rc != 0) {
  2181. if (rc > 0)
  2182. rc--;
  2183. writel(0, &cp->closearg);
  2184. portp->rc = rc;
  2185. clear_bit(ST_CLOSING, &portp->state);
  2186. wake_up_interruptible(&portp->raw_wait);
  2187. }
  2188. }
  2189. /*
  2190. * Check if we are waiting for a command completion message. We may
  2191. * need to copy out the command results associated with this command.
  2192. */
  2193. if (test_bit(ST_CMDING, &portp->state)) {
  2194. rc = readl(&cp->status);
  2195. if (readl(&cp->cmd) == 0 && rc != 0) {
  2196. if (rc > 0)
  2197. rc--;
  2198. if (portp->argp != NULL) {
  2199. memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]),
  2200. portp->argsize);
  2201. portp->argp = NULL;
  2202. }
  2203. writel(0, &cp->status);
  2204. portp->rc = rc;
  2205. clear_bit(ST_CMDING, &portp->state);
  2206. stli_dodelaycmd(portp, cp);
  2207. wake_up_interruptible(&portp->raw_wait);
  2208. }
  2209. }
  2210. /*
  2211. * Check for any notification messages ready. This includes lots of
  2212. * different types of events - RX chars ready, RX break received,
  2213. * TX data low or empty in the slave, modem signals changed state.
  2214. */
  2215. donerx = 0;
  2216. if (ap->notify) {
  2217. nt = ap->changed;
  2218. ap->notify = 0;
  2219. tty = portp->tty;
  2220. if (nt.signal & SG_DCD) {
  2221. oldsigs = portp->sigs;
  2222. portp->sigs = stli_mktiocm(nt.sigvalue);
  2223. clear_bit(ST_GETSIGS, &portp->state);
  2224. if ((portp->sigs & TIOCM_CD) &&
  2225. ((oldsigs & TIOCM_CD) == 0))
  2226. wake_up_interruptible(&portp->open_wait);
  2227. if ((oldsigs & TIOCM_CD) &&
  2228. ((portp->sigs & TIOCM_CD) == 0)) {
  2229. if (portp->flags & ASYNC_CHECK_CD) {
  2230. if (tty)
  2231. schedule_work(&portp->tqhangup);
  2232. }
  2233. }
  2234. }
  2235. if (nt.data & DT_TXEMPTY)
  2236. clear_bit(ST_TXBUSY, &portp->state);
  2237. if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
  2238. if (tty != NULL) {
  2239. tty_wakeup(tty);
  2240. EBRDENABLE(brdp);
  2241. wake_up_interruptible(&tty->write_wait);
  2242. }
  2243. }
  2244. if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
  2245. if (tty != NULL) {
  2246. tty_insert_flip_char(tty, 0, TTY_BREAK);
  2247. if (portp->flags & ASYNC_SAK) {
  2248. do_SAK(tty);
  2249. EBRDENABLE(brdp);
  2250. }
  2251. tty_schedule_flip(tty);
  2252. }
  2253. }
  2254. if (nt.data & DT_RXBUSY) {
  2255. donerx++;
  2256. stli_read(brdp, portp);
  2257. }
  2258. }
  2259. /*
  2260. * It might seem odd that we are checking for more RX chars here.
  2261. * But, we need to handle the case where the tty buffer was previously
  2262. * filled, but we had more characters to pass up. The slave will not
  2263. * send any more RX notify messages until the RX buffer has been emptied.
  2264. * But it will leave the service bits on (since the buffer is not empty).
  2265. * So from here we can try to process more RX chars.
  2266. */
  2267. if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
  2268. clear_bit(ST_RXING, &portp->state);
  2269. stli_read(brdp, portp);
  2270. }
  2271. return((test_bit(ST_OPENING, &portp->state) ||
  2272. test_bit(ST_CLOSING, &portp->state) ||
  2273. test_bit(ST_CMDING, &portp->state) ||
  2274. test_bit(ST_TXBUSY, &portp->state) ||
  2275. test_bit(ST_RXING, &portp->state)) ? 0 : 1);
  2276. }
  2277. /*****************************************************************************/
  2278. /*
  2279. * Service all ports on a particular board. Assumes that the boards
  2280. * shared memory is enabled, and that the page pointer is pointed
  2281. * at the cdk header structure.
  2282. */
  2283. static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp)
  2284. {
  2285. stliport_t *portp;
  2286. unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
  2287. unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
  2288. unsigned char __iomem *slavep;
  2289. int bitpos, bitat, bitsize;
  2290. int channr, nrdevs, slavebitchange;
  2291. bitsize = brdp->bitsize;
  2292. nrdevs = brdp->nrdevs;
  2293. /*
  2294. * Check if slave wants any service. Basically we try to do as
  2295. * little work as possible here. There are 2 levels of service
  2296. * bits. So if there is nothing to do we bail early. We check
  2297. * 8 service bits at a time in the inner loop, so we can bypass
  2298. * the lot if none of them want service.
  2299. */
  2300. memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset),
  2301. bitsize);
  2302. memset(&slavebits[0], 0, bitsize);
  2303. slavebitchange = 0;
  2304. for (bitpos = 0; (bitpos < bitsize); bitpos++) {
  2305. if (hostbits[bitpos] == 0)
  2306. continue;
  2307. channr = bitpos * 8;
  2308. for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
  2309. if (hostbits[bitpos] & bitat) {
  2310. portp = brdp->ports[(channr - 1)];
  2311. if (stli_hostcmd(brdp, portp)) {
  2312. slavebitchange++;
  2313. slavebits[bitpos] |= bitat;
  2314. }
  2315. }
  2316. }
  2317. }
  2318. /*
  2319. * If any of the ports are no longer busy then update them in the
  2320. * slave request bits. We need to do this after, since a host port
  2321. * service may initiate more slave requests.
  2322. */
  2323. if (slavebitchange) {
  2324. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2325. slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset;
  2326. for (bitpos = 0; (bitpos < bitsize); bitpos++) {
  2327. if (readb(slavebits + bitpos))
  2328. writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos);
  2329. }
  2330. }
  2331. }
  2332. /*****************************************************************************/
  2333. /*
  2334. * Driver poll routine. This routine polls the boards in use and passes
  2335. * messages back up to host when necessary. This is actually very
  2336. * CPU efficient, since we will always have the kernel poll clock, it
  2337. * adds only a few cycles when idle (since board service can be
  2338. * determined very easily), but when loaded generates no interrupts
  2339. * (with their expensive associated context change).
  2340. */
  2341. static void stli_poll(unsigned long arg)
  2342. {
  2343. cdkhdr_t __iomem *hdrp;
  2344. stlibrd_t *brdp;
  2345. int brdnr;
  2346. stli_timerlist.expires = STLI_TIMEOUT;
  2347. add_timer(&stli_timerlist);
  2348. /*
  2349. * Check each board and do any servicing required.
  2350. */
  2351. for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
  2352. brdp = stli_brds[brdnr];
  2353. if (brdp == NULL)
  2354. continue;
  2355. if ((brdp->state & BST_STARTED) == 0)
  2356. continue;
  2357. spin_lock(&brd_lock);
  2358. EBRDENABLE(brdp);
  2359. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2360. if (readb(&hdrp->hostreq))
  2361. stli_brdpoll(brdp, hdrp);
  2362. EBRDDISABLE(brdp);
  2363. spin_unlock(&brd_lock);
  2364. }
  2365. }
  2366. /*****************************************************************************/
  2367. /*
  2368. * Translate the termios settings into the port setting structure of
  2369. * the slave.
  2370. */
  2371. static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
  2372. {
  2373. memset(pp, 0, sizeof(asyport_t));
  2374. /*
  2375. * Start of by setting the baud, char size, parity and stop bit info.
  2376. */
  2377. pp->baudout = tiosp->c_cflag & CBAUD;
  2378. if (pp->baudout & CBAUDEX) {
  2379. pp->baudout &= ~CBAUDEX;
  2380. if ((pp->baudout < 1) || (pp->baudout > 4))
  2381. tiosp->c_cflag &= ~CBAUDEX;
  2382. else
  2383. pp->baudout += 15;
  2384. }
  2385. pp->baudout = stli_baudrates[pp->baudout];
  2386. if ((tiosp->c_cflag & CBAUD) == B38400) {
  2387. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  2388. pp->baudout = 57600;
  2389. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  2390. pp->baudout = 115200;
  2391. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  2392. pp->baudout = 230400;
  2393. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  2394. pp->baudout = 460800;
  2395. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  2396. pp->baudout = (portp->baud_base / portp->custom_divisor);
  2397. }
  2398. if (pp->baudout > STL_MAXBAUD)
  2399. pp->baudout = STL_MAXBAUD;
  2400. pp->baudin = pp->baudout;
  2401. switch (tiosp->c_cflag & CSIZE) {
  2402. case CS5:
  2403. pp->csize = 5;
  2404. break;
  2405. case CS6:
  2406. pp->csize = 6;
  2407. break;
  2408. case CS7:
  2409. pp->csize = 7;
  2410. break;
  2411. default:
  2412. pp->csize = 8;
  2413. break;
  2414. }
  2415. if (tiosp->c_cflag & CSTOPB)
  2416. pp->stopbs = PT_STOP2;
  2417. else
  2418. pp->stopbs = PT_STOP1;
  2419. if (tiosp->c_cflag & PARENB) {
  2420. if (tiosp->c_cflag & PARODD)
  2421. pp->parity = PT_ODDPARITY;
  2422. else
  2423. pp->parity = PT_EVENPARITY;
  2424. } else {
  2425. pp->parity = PT_NOPARITY;
  2426. }
  2427. /*
  2428. * Set up any flow control options enabled.
  2429. */
  2430. if (tiosp->c_iflag & IXON) {
  2431. pp->flow |= F_IXON;
  2432. if (tiosp->c_iflag & IXANY)
  2433. pp->flow |= F_IXANY;
  2434. }
  2435. if (tiosp->c_cflag & CRTSCTS)
  2436. pp->flow |= (F_RTSFLOW | F_CTSFLOW);
  2437. pp->startin = tiosp->c_cc[VSTART];
  2438. pp->stopin = tiosp->c_cc[VSTOP];
  2439. pp->startout = tiosp->c_cc[VSTART];
  2440. pp->stopout = tiosp->c_cc[VSTOP];
  2441. /*
  2442. * Set up the RX char marking mask with those RX error types we must
  2443. * catch. We can get the slave to help us out a little here, it will
  2444. * ignore parity errors and breaks for us, and mark parity errors in
  2445. * the data stream.
  2446. */
  2447. if (tiosp->c_iflag & IGNPAR)
  2448. pp->iflag |= FI_IGNRXERRS;
  2449. if (tiosp->c_iflag & IGNBRK)
  2450. pp->iflag |= FI_IGNBREAK;
  2451. portp->rxmarkmsk = 0;
  2452. if (tiosp->c_iflag & (INPCK | PARMRK))
  2453. pp->iflag |= FI_1MARKRXERRS;
  2454. if (tiosp->c_iflag & BRKINT)
  2455. portp->rxmarkmsk |= BRKINT;
  2456. /*
  2457. * Set up clocal processing as required.
  2458. */
  2459. if (tiosp->c_cflag & CLOCAL)
  2460. portp->flags &= ~ASYNC_CHECK_CD;
  2461. else
  2462. portp->flags |= ASYNC_CHECK_CD;
  2463. /*
  2464. * Transfer any persistent flags into the asyport structure.
  2465. */
  2466. pp->pflag = (portp->pflag & 0xffff);
  2467. pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
  2468. pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
  2469. pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
  2470. }
  2471. /*****************************************************************************/
  2472. /*
  2473. * Construct a slave signals structure for setting the DTR and RTS
  2474. * signals as specified.
  2475. */
  2476. static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
  2477. {
  2478. memset(sp, 0, sizeof(asysigs_t));
  2479. if (dtr >= 0) {
  2480. sp->signal |= SG_DTR;
  2481. sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
  2482. }
  2483. if (rts >= 0) {
  2484. sp->signal |= SG_RTS;
  2485. sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
  2486. }
  2487. }
  2488. /*****************************************************************************/
  2489. /*
  2490. * Convert the signals returned from the slave into a local TIOCM type
  2491. * signals value. We keep them locally in TIOCM format.
  2492. */
  2493. static long stli_mktiocm(unsigned long sigvalue)
  2494. {
  2495. long tiocm = 0;
  2496. tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
  2497. tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
  2498. tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
  2499. tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
  2500. tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
  2501. tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
  2502. return(tiocm);
  2503. }
  2504. /*****************************************************************************/
  2505. /*
  2506. * All panels and ports actually attached have been worked out. All
  2507. * we need to do here is set up the appropriate per port data structures.
  2508. */
  2509. static int stli_initports(stlibrd_t *brdp)
  2510. {
  2511. stliport_t *portp;
  2512. int i, panelnr, panelport;
  2513. for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
  2514. portp = kzalloc(sizeof(stliport_t), GFP_KERNEL);
  2515. if (!portp) {
  2516. printk("STALLION: failed to allocate port structure\n");
  2517. continue;
  2518. }
  2519. portp->magic = STLI_PORTMAGIC;
  2520. portp->portnr = i;
  2521. portp->brdnr = brdp->brdnr;
  2522. portp->panelnr = panelnr;
  2523. portp->baud_base = STL_BAUDBASE;
  2524. portp->close_delay = STL_CLOSEDELAY;
  2525. portp->closing_wait = 30 * HZ;
  2526. INIT_WORK(&portp->tqhangup, stli_dohangup, portp);
  2527. init_waitqueue_head(&portp->open_wait);
  2528. init_waitqueue_head(&portp->close_wait);
  2529. init_waitqueue_head(&portp->raw_wait);
  2530. panelport++;
  2531. if (panelport >= brdp->panels[panelnr]) {
  2532. panelport = 0;
  2533. panelnr++;
  2534. }
  2535. brdp->ports[i] = portp;
  2536. }
  2537. return 0;
  2538. }
  2539. /*****************************************************************************/
  2540. /*
  2541. * All the following routines are board specific hardware operations.
  2542. */
  2543. static void stli_ecpinit(stlibrd_t *brdp)
  2544. {
  2545. unsigned long memconf;
  2546. outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
  2547. udelay(10);
  2548. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2549. udelay(100);
  2550. memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
  2551. outb(memconf, (brdp->iobase + ECP_ATMEMAR));
  2552. }
  2553. /*****************************************************************************/
  2554. static void stli_ecpenable(stlibrd_t *brdp)
  2555. {
  2556. outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
  2557. }
  2558. /*****************************************************************************/
  2559. static void stli_ecpdisable(stlibrd_t *brdp)
  2560. {
  2561. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2562. }
  2563. /*****************************************************************************/
  2564. static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2565. {
  2566. void *ptr;
  2567. unsigned char val;
  2568. if (offset > brdp->memsize) {
  2569. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2570. "range at line=%d(%d), brd=%d\n",
  2571. (int) offset, line, __LINE__, brdp->brdnr);
  2572. ptr = NULL;
  2573. val = 0;
  2574. } else {
  2575. ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
  2576. val = (unsigned char) (offset / ECP_ATPAGESIZE);
  2577. }
  2578. outb(val, (brdp->iobase + ECP_ATMEMPR));
  2579. return(ptr);
  2580. }
  2581. /*****************************************************************************/
  2582. static void stli_ecpreset(stlibrd_t *brdp)
  2583. {
  2584. outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
  2585. udelay(10);
  2586. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2587. udelay(500);
  2588. }
  2589. /*****************************************************************************/
  2590. static void stli_ecpintr(stlibrd_t *brdp)
  2591. {
  2592. outb(0x1, brdp->iobase);
  2593. }
  2594. /*****************************************************************************/
  2595. /*
  2596. * The following set of functions act on ECP EISA boards.
  2597. */
  2598. static void stli_ecpeiinit(stlibrd_t *brdp)
  2599. {
  2600. unsigned long memconf;
  2601. outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
  2602. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  2603. udelay(10);
  2604. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2605. udelay(500);
  2606. memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
  2607. outb(memconf, (brdp->iobase + ECP_EIMEMARL));
  2608. memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
  2609. outb(memconf, (brdp->iobase + ECP_EIMEMARH));
  2610. }
  2611. /*****************************************************************************/
  2612. static void stli_ecpeienable(stlibrd_t *brdp)
  2613. {
  2614. outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
  2615. }
  2616. /*****************************************************************************/
  2617. static void stli_ecpeidisable(stlibrd_t *brdp)
  2618. {
  2619. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2620. }
  2621. /*****************************************************************************/
  2622. static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2623. {
  2624. void *ptr;
  2625. unsigned char val;
  2626. if (offset > brdp->memsize) {
  2627. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2628. "range at line=%d(%d), brd=%d\n",
  2629. (int) offset, line, __LINE__, brdp->brdnr);
  2630. ptr = NULL;
  2631. val = 0;
  2632. } else {
  2633. ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
  2634. if (offset < ECP_EIPAGESIZE)
  2635. val = ECP_EIENABLE;
  2636. else
  2637. val = ECP_EIENABLE | 0x40;
  2638. }
  2639. outb(val, (brdp->iobase + ECP_EICONFR));
  2640. return(ptr);
  2641. }
  2642. /*****************************************************************************/
  2643. static void stli_ecpeireset(stlibrd_t *brdp)
  2644. {
  2645. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  2646. udelay(10);
  2647. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2648. udelay(500);
  2649. }
  2650. /*****************************************************************************/
  2651. /*
  2652. * The following set of functions act on ECP MCA boards.
  2653. */
  2654. static void stli_ecpmcenable(stlibrd_t *brdp)
  2655. {
  2656. outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
  2657. }
  2658. /*****************************************************************************/
  2659. static void stli_ecpmcdisable(stlibrd_t *brdp)
  2660. {
  2661. outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
  2662. }
  2663. /*****************************************************************************/
  2664. static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2665. {
  2666. void *ptr;
  2667. unsigned char val;
  2668. if (offset > brdp->memsize) {
  2669. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2670. "range at line=%d(%d), brd=%d\n",
  2671. (int) offset, line, __LINE__, brdp->brdnr);
  2672. ptr = NULL;
  2673. val = 0;
  2674. } else {
  2675. ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
  2676. val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
  2677. }
  2678. outb(val, (brdp->iobase + ECP_MCCONFR));
  2679. return(ptr);
  2680. }
  2681. /*****************************************************************************/
  2682. static void stli_ecpmcreset(stlibrd_t *brdp)
  2683. {
  2684. outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
  2685. udelay(10);
  2686. outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
  2687. udelay(500);
  2688. }
  2689. /*****************************************************************************/
  2690. /*
  2691. * The following set of functions act on ECP PCI boards.
  2692. */
  2693. static void stli_ecppciinit(stlibrd_t *brdp)
  2694. {
  2695. outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
  2696. udelay(10);
  2697. outb(0, (brdp->iobase + ECP_PCICONFR));
  2698. udelay(500);
  2699. }
  2700. /*****************************************************************************/
  2701. static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2702. {
  2703. void *ptr;
  2704. unsigned char val;
  2705. if (offset > brdp->memsize) {
  2706. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2707. "range at line=%d(%d), board=%d\n",
  2708. (int) offset, line, __LINE__, brdp->brdnr);
  2709. ptr = NULL;
  2710. val = 0;
  2711. } else {
  2712. ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
  2713. val = (offset / ECP_PCIPAGESIZE) << 1;
  2714. }
  2715. outb(val, (brdp->iobase + ECP_PCICONFR));
  2716. return(ptr);
  2717. }
  2718. /*****************************************************************************/
  2719. static void stli_ecppcireset(stlibrd_t *brdp)
  2720. {
  2721. outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
  2722. udelay(10);
  2723. outb(0, (brdp->iobase + ECP_PCICONFR));
  2724. udelay(500);
  2725. }
  2726. /*****************************************************************************/
  2727. /*
  2728. * The following routines act on ONboards.
  2729. */
  2730. static void stli_onbinit(stlibrd_t *brdp)
  2731. {
  2732. unsigned long memconf;
  2733. outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
  2734. udelay(10);
  2735. outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
  2736. mdelay(1000);
  2737. memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
  2738. outb(memconf, (brdp->iobase + ONB_ATMEMAR));
  2739. outb(0x1, brdp->iobase);
  2740. mdelay(1);
  2741. }
  2742. /*****************************************************************************/
  2743. static void stli_onbenable(stlibrd_t *brdp)
  2744. {
  2745. outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
  2746. }
  2747. /*****************************************************************************/
  2748. static void stli_onbdisable(stlibrd_t *brdp)
  2749. {
  2750. outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
  2751. }
  2752. /*****************************************************************************/
  2753. static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2754. {
  2755. void *ptr;
  2756. if (offset > brdp->memsize) {
  2757. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2758. "range at line=%d(%d), brd=%d\n",
  2759. (int) offset, line, __LINE__, brdp->brdnr);
  2760. ptr = NULL;
  2761. } else {
  2762. ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
  2763. }
  2764. return(ptr);
  2765. }
  2766. /*****************************************************************************/
  2767. static void stli_onbreset(stlibrd_t *brdp)
  2768. {
  2769. outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
  2770. udelay(10);
  2771. outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
  2772. mdelay(1000);
  2773. }
  2774. /*****************************************************************************/
  2775. /*
  2776. * The following routines act on ONboard EISA.
  2777. */
  2778. static void stli_onbeinit(stlibrd_t *brdp)
  2779. {
  2780. unsigned long memconf;
  2781. outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
  2782. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  2783. udelay(10);
  2784. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  2785. mdelay(1000);
  2786. memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
  2787. outb(memconf, (brdp->iobase + ONB_EIMEMARL));
  2788. memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
  2789. outb(memconf, (brdp->iobase + ONB_EIMEMARH));
  2790. outb(0x1, brdp->iobase);
  2791. mdelay(1);
  2792. }
  2793. /*****************************************************************************/
  2794. static void stli_onbeenable(stlibrd_t *brdp)
  2795. {
  2796. outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
  2797. }
  2798. /*****************************************************************************/
  2799. static void stli_onbedisable(stlibrd_t *brdp)
  2800. {
  2801. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  2802. }
  2803. /*****************************************************************************/
  2804. static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2805. {
  2806. void *ptr;
  2807. unsigned char val;
  2808. if (offset > brdp->memsize) {
  2809. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2810. "range at line=%d(%d), brd=%d\n",
  2811. (int) offset, line, __LINE__, brdp->brdnr);
  2812. ptr = NULL;
  2813. val = 0;
  2814. } else {
  2815. ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
  2816. if (offset < ONB_EIPAGESIZE)
  2817. val = ONB_EIENABLE;
  2818. else
  2819. val = ONB_EIENABLE | 0x40;
  2820. }
  2821. outb(val, (brdp->iobase + ONB_EICONFR));
  2822. return(ptr);
  2823. }
  2824. /*****************************************************************************/
  2825. static void stli_onbereset(stlibrd_t *brdp)
  2826. {
  2827. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  2828. udelay(10);
  2829. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  2830. mdelay(1000);
  2831. }
  2832. /*****************************************************************************/
  2833. /*
  2834. * The following routines act on Brumby boards.
  2835. */
  2836. static void stli_bbyinit(stlibrd_t *brdp)
  2837. {
  2838. outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
  2839. udelay(10);
  2840. outb(0, (brdp->iobase + BBY_ATCONFR));
  2841. mdelay(1000);
  2842. outb(0x1, brdp->iobase);
  2843. mdelay(1);
  2844. }
  2845. /*****************************************************************************/
  2846. static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2847. {
  2848. void *ptr;
  2849. unsigned char val;
  2850. BUG_ON(offset > brdp->memsize);
  2851. ptr = brdp->membase + (offset % BBY_PAGESIZE);
  2852. val = (unsigned char) (offset / BBY_PAGESIZE);
  2853. outb(val, (brdp->iobase + BBY_ATCONFR));
  2854. return(ptr);
  2855. }
  2856. /*****************************************************************************/
  2857. static void stli_bbyreset(stlibrd_t *brdp)
  2858. {
  2859. outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
  2860. udelay(10);
  2861. outb(0, (brdp->iobase + BBY_ATCONFR));
  2862. mdelay(1000);
  2863. }
  2864. /*****************************************************************************/
  2865. /*
  2866. * The following routines act on original old Stallion boards.
  2867. */
  2868. static void stli_stalinit(stlibrd_t *brdp)
  2869. {
  2870. outb(0x1, brdp->iobase);
  2871. mdelay(1000);
  2872. }
  2873. /*****************************************************************************/
  2874. static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2875. {
  2876. BUG_ON(offset > brdp->memsize);
  2877. return brdp->membase + (offset % STAL_PAGESIZE);
  2878. }
  2879. /*****************************************************************************/
  2880. static void stli_stalreset(stlibrd_t *brdp)
  2881. {
  2882. u32 __iomem *vecp;
  2883. vecp = (u32 __iomem *) (brdp->membase + 0x30);
  2884. writel(0xffff0000, vecp);
  2885. outb(0, brdp->iobase);
  2886. mdelay(1000);
  2887. }
  2888. /*****************************************************************************/
  2889. /*
  2890. * Try to find an ECP board and initialize it. This handles only ECP
  2891. * board types.
  2892. */
  2893. static int stli_initecp(stlibrd_t *brdp)
  2894. {
  2895. cdkecpsig_t sig;
  2896. cdkecpsig_t __iomem *sigsp;
  2897. unsigned int status, nxtid;
  2898. char *name;
  2899. int panelnr, nrports;
  2900. if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
  2901. return -EIO;
  2902. if ((brdp->iobase == 0) || (brdp->memaddr == 0))
  2903. {
  2904. release_region(brdp->iobase, brdp->iosize);
  2905. return -ENODEV;
  2906. }
  2907. brdp->iosize = ECP_IOSIZE;
  2908. /*
  2909. * Based on the specific board type setup the common vars to access
  2910. * and enable shared memory. Set all board specific information now
  2911. * as well.
  2912. */
  2913. switch (brdp->brdtype) {
  2914. case BRD_ECP:
  2915. brdp->membase = (void *) brdp->memaddr;
  2916. brdp->memsize = ECP_MEMSIZE;
  2917. brdp->pagesize = ECP_ATPAGESIZE;
  2918. brdp->init = stli_ecpinit;
  2919. brdp->enable = stli_ecpenable;
  2920. brdp->reenable = stli_ecpenable;
  2921. brdp->disable = stli_ecpdisable;
  2922. brdp->getmemptr = stli_ecpgetmemptr;
  2923. brdp->intr = stli_ecpintr;
  2924. brdp->reset = stli_ecpreset;
  2925. name = "serial(EC8/64)";
  2926. break;
  2927. case BRD_ECPE:
  2928. brdp->membase = (void *) brdp->memaddr;
  2929. brdp->memsize = ECP_MEMSIZE;
  2930. brdp->pagesize = ECP_EIPAGESIZE;
  2931. brdp->init = stli_ecpeiinit;
  2932. brdp->enable = stli_ecpeienable;
  2933. brdp->reenable = stli_ecpeienable;
  2934. brdp->disable = stli_ecpeidisable;
  2935. brdp->getmemptr = stli_ecpeigetmemptr;
  2936. brdp->intr = stli_ecpintr;
  2937. brdp->reset = stli_ecpeireset;
  2938. name = "serial(EC8/64-EI)";
  2939. break;
  2940. case BRD_ECPMC:
  2941. brdp->membase = (void *) brdp->memaddr;
  2942. brdp->memsize = ECP_MEMSIZE;
  2943. brdp->pagesize = ECP_MCPAGESIZE;
  2944. brdp->init = NULL;
  2945. brdp->enable = stli_ecpmcenable;
  2946. brdp->reenable = stli_ecpmcenable;
  2947. brdp->disable = stli_ecpmcdisable;
  2948. brdp->getmemptr = stli_ecpmcgetmemptr;
  2949. brdp->intr = stli_ecpintr;
  2950. brdp->reset = stli_ecpmcreset;
  2951. name = "serial(EC8/64-MCA)";
  2952. break;
  2953. case BRD_ECPPCI:
  2954. brdp->membase = (void *) brdp->memaddr;
  2955. brdp->memsize = ECP_PCIMEMSIZE;
  2956. brdp->pagesize = ECP_PCIPAGESIZE;
  2957. brdp->init = stli_ecppciinit;
  2958. brdp->enable = NULL;
  2959. brdp->reenable = NULL;
  2960. brdp->disable = NULL;
  2961. brdp->getmemptr = stli_ecppcigetmemptr;
  2962. brdp->intr = stli_ecpintr;
  2963. brdp->reset = stli_ecppcireset;
  2964. name = "serial(EC/RA-PCI)";
  2965. break;
  2966. default:
  2967. release_region(brdp->iobase, brdp->iosize);
  2968. return -EINVAL;
  2969. }
  2970. /*
  2971. * The per-board operations structure is all set up, so now let's go
  2972. * and get the board operational. Firstly initialize board configuration
  2973. * registers. Set the memory mapping info so we can get at the boards
  2974. * shared memory.
  2975. */
  2976. EBRDINIT(brdp);
  2977. brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
  2978. if (brdp->membase == NULL)
  2979. {
  2980. release_region(brdp->iobase, brdp->iosize);
  2981. return -ENOMEM;
  2982. }
  2983. /*
  2984. * Now that all specific code is set up, enable the shared memory and
  2985. * look for the a signature area that will tell us exactly what board
  2986. * this is, and what it is connected to it.
  2987. */
  2988. EBRDENABLE(brdp);
  2989. sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
  2990. memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
  2991. EBRDDISABLE(brdp);
  2992. if (sig.magic != cpu_to_le32(ECP_MAGIC))
  2993. {
  2994. release_region(brdp->iobase, brdp->iosize);
  2995. return -ENODEV;
  2996. }
  2997. /*
  2998. * Scan through the signature looking at the panels connected to the
  2999. * board. Calculate the total number of ports as we go.
  3000. */
  3001. for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
  3002. status = sig.panelid[nxtid];
  3003. if ((status & ECH_PNLIDMASK) != nxtid)
  3004. break;
  3005. brdp->panelids[panelnr] = status;
  3006. nrports = (status & ECH_PNL16PORT) ? 16 : 8;
  3007. if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
  3008. nxtid++;
  3009. brdp->panels[panelnr] = nrports;
  3010. brdp->nrports += nrports;
  3011. nxtid++;
  3012. brdp->nrpanels++;
  3013. }
  3014. brdp->state |= BST_FOUND;
  3015. return 0;
  3016. }
  3017. /*****************************************************************************/
  3018. /*
  3019. * Try to find an ONboard, Brumby or Stallion board and initialize it.
  3020. * This handles only these board types.
  3021. */
  3022. static int stli_initonb(stlibrd_t *brdp)
  3023. {
  3024. cdkonbsig_t sig;
  3025. cdkonbsig_t __iomem *sigsp;
  3026. char *name;
  3027. int i;
  3028. /*
  3029. * Do a basic sanity check on the IO and memory addresses.
  3030. */
  3031. if (brdp->iobase == 0 || brdp->memaddr == 0)
  3032. return -ENODEV;
  3033. brdp->iosize = ONB_IOSIZE;
  3034. if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
  3035. return -EIO;
  3036. /*
  3037. * Based on the specific board type setup the common vars to access
  3038. * and enable shared memory. Set all board specific information now
  3039. * as well.
  3040. */
  3041. switch (brdp->brdtype) {
  3042. case BRD_ONBOARD:
  3043. case BRD_ONBOARD32:
  3044. case BRD_ONBOARD2:
  3045. case BRD_ONBOARD2_32:
  3046. case BRD_ONBOARDRS:
  3047. brdp->memsize = ONB_MEMSIZE;
  3048. brdp->pagesize = ONB_ATPAGESIZE;
  3049. brdp->init = stli_onbinit;
  3050. brdp->enable = stli_onbenable;
  3051. brdp->reenable = stli_onbenable;
  3052. brdp->disable = stli_onbdisable;
  3053. brdp->getmemptr = stli_onbgetmemptr;
  3054. brdp->intr = stli_ecpintr;
  3055. brdp->reset = stli_onbreset;
  3056. if (brdp->memaddr > 0x100000)
  3057. brdp->enabval = ONB_MEMENABHI;
  3058. else
  3059. brdp->enabval = ONB_MEMENABLO;
  3060. name = "serial(ONBoard)";
  3061. break;
  3062. case BRD_ONBOARDE:
  3063. brdp->memsize = ONB_EIMEMSIZE;
  3064. brdp->pagesize = ONB_EIPAGESIZE;
  3065. brdp->init = stli_onbeinit;
  3066. brdp->enable = stli_onbeenable;
  3067. brdp->reenable = stli_onbeenable;
  3068. brdp->disable = stli_onbedisable;
  3069. brdp->getmemptr = stli_onbegetmemptr;
  3070. brdp->intr = stli_ecpintr;
  3071. brdp->reset = stli_onbereset;
  3072. name = "serial(ONBoard/E)";
  3073. break;
  3074. case BRD_BRUMBY4:
  3075. case BRD_BRUMBY8:
  3076. case BRD_BRUMBY16:
  3077. brdp->memsize = BBY_MEMSIZE;
  3078. brdp->pagesize = BBY_PAGESIZE;
  3079. brdp->init = stli_bbyinit;
  3080. brdp->enable = NULL;
  3081. brdp->reenable = NULL;
  3082. brdp->disable = NULL;
  3083. brdp->getmemptr = stli_bbygetmemptr;
  3084. brdp->intr = stli_ecpintr;
  3085. brdp->reset = stli_bbyreset;
  3086. name = "serial(Brumby)";
  3087. break;
  3088. case BRD_STALLION:
  3089. brdp->memsize = STAL_MEMSIZE;
  3090. brdp->pagesize = STAL_PAGESIZE;
  3091. brdp->init = stli_stalinit;
  3092. brdp->enable = NULL;
  3093. brdp->reenable = NULL;
  3094. brdp->disable = NULL;
  3095. brdp->getmemptr = stli_stalgetmemptr;
  3096. brdp->intr = stli_ecpintr;
  3097. brdp->reset = stli_stalreset;
  3098. name = "serial(Stallion)";
  3099. break;
  3100. default:
  3101. release_region(brdp->iobase, brdp->iosize);
  3102. return -EINVAL;
  3103. }
  3104. /*
  3105. * The per-board operations structure is all set up, so now let's go
  3106. * and get the board operational. Firstly initialize board configuration
  3107. * registers. Set the memory mapping info so we can get at the boards
  3108. * shared memory.
  3109. */
  3110. EBRDINIT(brdp);
  3111. brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
  3112. if (brdp->membase == NULL)
  3113. {
  3114. release_region(brdp->iobase, brdp->iosize);
  3115. return -ENOMEM;
  3116. }
  3117. /*
  3118. * Now that all specific code is set up, enable the shared memory and
  3119. * look for the a signature area that will tell us exactly what board
  3120. * this is, and how many ports.
  3121. */
  3122. EBRDENABLE(brdp);
  3123. sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
  3124. memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t));
  3125. EBRDDISABLE(brdp);
  3126. if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
  3127. sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
  3128. sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
  3129. sig.magic3 != cpu_to_le16(ONB_MAGIC3))
  3130. {
  3131. release_region(brdp->iobase, brdp->iosize);
  3132. return -ENODEV;
  3133. }
  3134. /*
  3135. * Scan through the signature alive mask and calculate how many ports
  3136. * there are on this board.
  3137. */
  3138. brdp->nrpanels = 1;
  3139. if (sig.amask1) {
  3140. brdp->nrports = 32;
  3141. } else {
  3142. for (i = 0; (i < 16); i++) {
  3143. if (((sig.amask0 << i) & 0x8000) == 0)
  3144. break;
  3145. }
  3146. brdp->nrports = i;
  3147. }
  3148. brdp->panels[0] = brdp->nrports;
  3149. brdp->state |= BST_FOUND;
  3150. return 0;
  3151. }
  3152. /*****************************************************************************/
  3153. /*
  3154. * Start up a running board. This routine is only called after the
  3155. * code has been down loaded to the board and is operational. It will
  3156. * read in the memory map, and get the show on the road...
  3157. */
  3158. static int stli_startbrd(stlibrd_t *brdp)
  3159. {
  3160. cdkhdr_t __iomem *hdrp;
  3161. cdkmem_t __iomem *memp;
  3162. cdkasy_t __iomem *ap;
  3163. unsigned long flags;
  3164. stliport_t *portp;
  3165. int portnr, nrdevs, i, rc = 0;
  3166. u32 memoff;
  3167. spin_lock_irqsave(&brd_lock, flags);
  3168. EBRDENABLE(brdp);
  3169. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  3170. nrdevs = hdrp->nrdevs;
  3171. #if 0
  3172. printk("%s(%d): CDK version %d.%d.%d --> "
  3173. "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
  3174. __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification),
  3175. readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp),
  3176. readl(&hdrp->slavep));
  3177. #endif
  3178. if (nrdevs < (brdp->nrports + 1)) {
  3179. printk(KERN_ERR "STALLION: slave failed to allocate memory for "
  3180. "all devices, devices=%d\n", nrdevs);
  3181. brdp->nrports = nrdevs - 1;
  3182. }
  3183. brdp->nrdevs = nrdevs;
  3184. brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
  3185. brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
  3186. brdp->bitsize = (nrdevs + 7) / 8;
  3187. memoff = readl(&hdrp->memp);
  3188. if (memoff > brdp->memsize) {
  3189. printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
  3190. rc = -EIO;
  3191. goto stli_donestartup;
  3192. }
  3193. memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
  3194. if (readw(&memp->dtype) != TYP_ASYNCTRL) {
  3195. printk(KERN_ERR "STALLION: no slave control device found\n");
  3196. goto stli_donestartup;
  3197. }
  3198. memp++;
  3199. /*
  3200. * Cycle through memory allocation of each port. We are guaranteed to
  3201. * have all ports inside the first page of slave window, so no need to
  3202. * change pages while reading memory map.
  3203. */
  3204. for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
  3205. if (readw(&memp->dtype) != TYP_ASYNC)
  3206. break;
  3207. portp = brdp->ports[portnr];
  3208. if (portp == NULL)
  3209. break;
  3210. portp->devnr = i;
  3211. portp->addr = readl(&memp->offset);
  3212. portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
  3213. portp->portidx = (unsigned char) (i / 8);
  3214. portp->portbit = (unsigned char) (0x1 << (i % 8));
  3215. }
  3216. writeb(0xff, &hdrp->slavereq);
  3217. /*
  3218. * For each port setup a local copy of the RX and TX buffer offsets
  3219. * and sizes. We do this separate from the above, because we need to
  3220. * move the shared memory page...
  3221. */
  3222. for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
  3223. portp = brdp->ports[portnr];
  3224. if (portp == NULL)
  3225. break;
  3226. if (portp->addr == 0)
  3227. break;
  3228. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  3229. if (ap != NULL) {
  3230. portp->rxsize = readw(&ap->rxq.size);
  3231. portp->txsize = readw(&ap->txq.size);
  3232. portp->rxoffset = readl(&ap->rxq.offset);
  3233. portp->txoffset = readl(&ap->txq.offset);
  3234. }
  3235. }
  3236. stli_donestartup:
  3237. EBRDDISABLE(brdp);
  3238. spin_unlock_irqrestore(&brd_lock, flags);
  3239. if (rc == 0)
  3240. brdp->state |= BST_STARTED;
  3241. if (! stli_timeron) {
  3242. stli_timeron++;
  3243. stli_timerlist.expires = STLI_TIMEOUT;
  3244. add_timer(&stli_timerlist);
  3245. }
  3246. return rc;
  3247. }
  3248. /*****************************************************************************/
  3249. /*
  3250. * Probe and initialize the specified board.
  3251. */
  3252. static int __init stli_brdinit(stlibrd_t *brdp)
  3253. {
  3254. stli_brds[brdp->brdnr] = brdp;
  3255. switch (brdp->brdtype) {
  3256. case BRD_ECP:
  3257. case BRD_ECPE:
  3258. case BRD_ECPMC:
  3259. case BRD_ECPPCI:
  3260. stli_initecp(brdp);
  3261. break;
  3262. case BRD_ONBOARD:
  3263. case BRD_ONBOARDE:
  3264. case BRD_ONBOARD2:
  3265. case BRD_ONBOARD32:
  3266. case BRD_ONBOARD2_32:
  3267. case BRD_ONBOARDRS:
  3268. case BRD_BRUMBY4:
  3269. case BRD_BRUMBY8:
  3270. case BRD_BRUMBY16:
  3271. case BRD_STALLION:
  3272. stli_initonb(brdp);
  3273. break;
  3274. case BRD_EASYIO:
  3275. case BRD_ECH:
  3276. case BRD_ECHMC:
  3277. case BRD_ECHPCI:
  3278. printk(KERN_ERR "STALLION: %s board type not supported in "
  3279. "this driver\n", stli_brdnames[brdp->brdtype]);
  3280. return -ENODEV;
  3281. default:
  3282. printk(KERN_ERR "STALLION: board=%d is unknown board "
  3283. "type=%d\n", brdp->brdnr, brdp->brdtype);
  3284. return -ENODEV;
  3285. }
  3286. if ((brdp->state & BST_FOUND) == 0) {
  3287. printk(KERN_ERR "STALLION: %s board not found, board=%d "
  3288. "io=%x mem=%x\n",
  3289. stli_brdnames[brdp->brdtype], brdp->brdnr,
  3290. brdp->iobase, (int) brdp->memaddr);
  3291. return -ENODEV;
  3292. }
  3293. stli_initports(brdp);
  3294. printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
  3295. "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
  3296. brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
  3297. brdp->nrpanels, brdp->nrports);
  3298. return 0;
  3299. }
  3300. /*****************************************************************************/
  3301. /*
  3302. * Probe around trying to find where the EISA boards shared memory
  3303. * might be. This is a bit if hack, but it is the best we can do.
  3304. */
  3305. static int stli_eisamemprobe(stlibrd_t *brdp)
  3306. {
  3307. cdkecpsig_t ecpsig, __iomem *ecpsigp;
  3308. cdkonbsig_t onbsig, __iomem *onbsigp;
  3309. int i, foundit;
  3310. /*
  3311. * First up we reset the board, to get it into a known state. There
  3312. * is only 2 board types here we need to worry about. Don;t use the
  3313. * standard board init routine here, it programs up the shared
  3314. * memory address, and we don't know it yet...
  3315. */
  3316. if (brdp->brdtype == BRD_ECPE) {
  3317. outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
  3318. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  3319. udelay(10);
  3320. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  3321. udelay(500);
  3322. stli_ecpeienable(brdp);
  3323. } else if (brdp->brdtype == BRD_ONBOARDE) {
  3324. outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
  3325. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  3326. udelay(10);
  3327. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  3328. mdelay(100);
  3329. outb(0x1, brdp->iobase);
  3330. mdelay(1);
  3331. stli_onbeenable(brdp);
  3332. } else {
  3333. return -ENODEV;
  3334. }
  3335. foundit = 0;
  3336. brdp->memsize = ECP_MEMSIZE;
  3337. /*
  3338. * Board shared memory is enabled, so now we have a poke around and
  3339. * see if we can find it.
  3340. */
  3341. for (i = 0; (i < stli_eisamempsize); i++) {
  3342. brdp->memaddr = stli_eisamemprobeaddrs[i];
  3343. brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
  3344. if (brdp->membase == NULL)
  3345. continue;
  3346. if (brdp->brdtype == BRD_ECPE) {
  3347. ecpsigp = (cdkecpsig_t __iomem *) stli_ecpeigetmemptr(brdp,
  3348. CDK_SIGADDR, __LINE__);
  3349. memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
  3350. if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
  3351. foundit = 1;
  3352. } else {
  3353. onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp,
  3354. CDK_SIGADDR, __LINE__);
  3355. memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t));
  3356. if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) &&
  3357. (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) &&
  3358. (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) &&
  3359. (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3)))
  3360. foundit = 1;
  3361. }
  3362. iounmap(brdp->membase);
  3363. if (foundit)
  3364. break;
  3365. }
  3366. /*
  3367. * Regardless of whether we found the shared memory or not we must
  3368. * disable the region. After that return success or failure.
  3369. */
  3370. if (brdp->brdtype == BRD_ECPE)
  3371. stli_ecpeidisable(brdp);
  3372. else
  3373. stli_onbedisable(brdp);
  3374. if (! foundit) {
  3375. brdp->memaddr = 0;
  3376. brdp->membase = NULL;
  3377. printk(KERN_ERR "STALLION: failed to probe shared memory "
  3378. "region for %s in EISA slot=%d\n",
  3379. stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
  3380. return -ENODEV;
  3381. }
  3382. return 0;
  3383. }
  3384. static int stli_getbrdnr(void)
  3385. {
  3386. int i;
  3387. for (i = 0; i < STL_MAXBRDS; i++) {
  3388. if (!stli_brds[i]) {
  3389. if (i >= stli_nrbrds)
  3390. stli_nrbrds = i + 1;
  3391. return i;
  3392. }
  3393. }
  3394. return -1;
  3395. }
  3396. /*****************************************************************************/
  3397. /*
  3398. * Probe around and try to find any EISA boards in system. The biggest
  3399. * problem here is finding out what memory address is associated with
  3400. * an EISA board after it is found. The registers of the ECPE and
  3401. * ONboardE are not readable - so we can't read them from there. We
  3402. * don't have access to the EISA CMOS (or EISA BIOS) so we don't
  3403. * actually have any way to find out the real value. The best we can
  3404. * do is go probing around in the usual places hoping we can find it.
  3405. */
  3406. static int stli_findeisabrds(void)
  3407. {
  3408. stlibrd_t *brdp;
  3409. unsigned int iobase, eid;
  3410. int i;
  3411. /*
  3412. * Firstly check if this is an EISA system. If this is not an EISA system then
  3413. * don't bother going any further!
  3414. */
  3415. if (EISA_bus)
  3416. return 0;
  3417. /*
  3418. * Looks like an EISA system, so go searching for EISA boards.
  3419. */
  3420. for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
  3421. outb(0xff, (iobase + 0xc80));
  3422. eid = inb(iobase + 0xc80);
  3423. eid |= inb(iobase + 0xc81) << 8;
  3424. if (eid != STL_EISAID)
  3425. continue;
  3426. /*
  3427. * We have found a board. Need to check if this board was
  3428. * statically configured already (just in case!).
  3429. */
  3430. for (i = 0; (i < STL_MAXBRDS); i++) {
  3431. brdp = stli_brds[i];
  3432. if (brdp == NULL)
  3433. continue;
  3434. if (brdp->iobase == iobase)
  3435. break;
  3436. }
  3437. if (i < STL_MAXBRDS)
  3438. continue;
  3439. /*
  3440. * We have found a Stallion board and it is not configured already.
  3441. * Allocate a board structure and initialize it.
  3442. */
  3443. if ((brdp = stli_allocbrd()) == NULL)
  3444. return -ENOMEM;
  3445. if ((brdp->brdnr = stli_getbrdnr()) < 0)
  3446. return -ENOMEM;
  3447. eid = inb(iobase + 0xc82);
  3448. if (eid == ECP_EISAID)
  3449. brdp->brdtype = BRD_ECPE;
  3450. else if (eid == ONB_EISAID)
  3451. brdp->brdtype = BRD_ONBOARDE;
  3452. else
  3453. brdp->brdtype = BRD_UNKNOWN;
  3454. brdp->iobase = iobase;
  3455. outb(0x1, (iobase + 0xc84));
  3456. if (stli_eisamemprobe(brdp))
  3457. outb(0, (iobase + 0xc84));
  3458. stli_brdinit(brdp);
  3459. }
  3460. return 0;
  3461. }
  3462. /*****************************************************************************/
  3463. /*
  3464. * Find the next available board number that is free.
  3465. */
  3466. /*****************************************************************************/
  3467. #ifdef CONFIG_PCI
  3468. /*
  3469. * We have a Stallion board. Allocate a board structure and
  3470. * initialize it. Read its IO and MEMORY resources from PCI
  3471. * configuration space.
  3472. */
  3473. static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
  3474. {
  3475. stlibrd_t *brdp;
  3476. if (pci_enable_device(devp))
  3477. return -EIO;
  3478. if ((brdp = stli_allocbrd()) == NULL)
  3479. return -ENOMEM;
  3480. if ((brdp->brdnr = stli_getbrdnr()) < 0) {
  3481. printk(KERN_INFO "STALLION: too many boards found, "
  3482. "maximum supported %d\n", STL_MAXBRDS);
  3483. return 0;
  3484. }
  3485. brdp->brdtype = brdtype;
  3486. /*
  3487. * We have all resources from the board, so lets setup the actual
  3488. * board structure now.
  3489. */
  3490. brdp->iobase = pci_resource_start(devp, 3);
  3491. brdp->memaddr = pci_resource_start(devp, 2);
  3492. stli_brdinit(brdp);
  3493. return 0;
  3494. }
  3495. /*****************************************************************************/
  3496. /*
  3497. * Find all Stallion PCI boards that might be installed. Initialize each
  3498. * one as it is found.
  3499. */
  3500. static int stli_findpcibrds(void)
  3501. {
  3502. struct pci_dev *dev = NULL;
  3503. while ((dev = pci_get_device(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, dev))) {
  3504. stli_initpcibrd(BRD_ECPPCI, dev);
  3505. }
  3506. return 0;
  3507. }
  3508. #endif
  3509. /*****************************************************************************/
  3510. /*
  3511. * Allocate a new board structure. Fill out the basic info in it.
  3512. */
  3513. static stlibrd_t *stli_allocbrd(void)
  3514. {
  3515. stlibrd_t *brdp;
  3516. brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL);
  3517. if (!brdp) {
  3518. printk(KERN_ERR "STALLION: failed to allocate memory "
  3519. "(size=%Zd)\n", sizeof(stlibrd_t));
  3520. return NULL;
  3521. }
  3522. brdp->magic = STLI_BOARDMAGIC;
  3523. return brdp;
  3524. }
  3525. /*****************************************************************************/
  3526. /*
  3527. * Scan through all the boards in the configuration and see what we
  3528. * can find.
  3529. */
  3530. static int stli_initbrds(void)
  3531. {
  3532. stlibrd_t *brdp, *nxtbrdp;
  3533. stlconf_t *confp;
  3534. int i, j;
  3535. if (stli_nrbrds > STL_MAXBRDS) {
  3536. printk(KERN_INFO "STALLION: too many boards in configuration "
  3537. "table, truncating to %d\n", STL_MAXBRDS);
  3538. stli_nrbrds = STL_MAXBRDS;
  3539. }
  3540. /*
  3541. * Firstly scan the list of static boards configured. Allocate
  3542. * resources and initialize the boards as found. If this is a
  3543. * module then let the module args override static configuration.
  3544. */
  3545. for (i = 0; (i < stli_nrbrds); i++) {
  3546. confp = &stli_brdconf[i];
  3547. stli_parsebrd(confp, stli_brdsp[i]);
  3548. if ((brdp = stli_allocbrd()) == NULL)
  3549. return -ENOMEM;
  3550. brdp->brdnr = i;
  3551. brdp->brdtype = confp->brdtype;
  3552. brdp->iobase = confp->ioaddr1;
  3553. brdp->memaddr = confp->memaddr;
  3554. stli_brdinit(brdp);
  3555. }
  3556. /*
  3557. * Static configuration table done, so now use dynamic methods to
  3558. * see if any more boards should be configured.
  3559. */
  3560. stli_argbrds();
  3561. if (STLI_EISAPROBE)
  3562. stli_findeisabrds();
  3563. #ifdef CONFIG_PCI
  3564. stli_findpcibrds();
  3565. #endif
  3566. /*
  3567. * All found boards are initialized. Now for a little optimization, if
  3568. * no boards are sharing the "shared memory" regions then we can just
  3569. * leave them all enabled. This is in fact the usual case.
  3570. */
  3571. stli_shared = 0;
  3572. if (stli_nrbrds > 1) {
  3573. for (i = 0; (i < stli_nrbrds); i++) {
  3574. brdp = stli_brds[i];
  3575. if (brdp == NULL)
  3576. continue;
  3577. for (j = i + 1; (j < stli_nrbrds); j++) {
  3578. nxtbrdp = stli_brds[j];
  3579. if (nxtbrdp == NULL)
  3580. continue;
  3581. if ((brdp->membase >= nxtbrdp->membase) &&
  3582. (brdp->membase <= (nxtbrdp->membase +
  3583. nxtbrdp->memsize - 1))) {
  3584. stli_shared++;
  3585. break;
  3586. }
  3587. }
  3588. }
  3589. }
  3590. if (stli_shared == 0) {
  3591. for (i = 0; (i < stli_nrbrds); i++) {
  3592. brdp = stli_brds[i];
  3593. if (brdp == NULL)
  3594. continue;
  3595. if (brdp->state & BST_FOUND) {
  3596. EBRDENABLE(brdp);
  3597. brdp->enable = NULL;
  3598. brdp->disable = NULL;
  3599. }
  3600. }
  3601. }
  3602. return 0;
  3603. }
  3604. /*****************************************************************************/
  3605. /*
  3606. * Code to handle an "staliomem" read operation. This device is the
  3607. * contents of the board shared memory. It is used for down loading
  3608. * the slave image (and debugging :-)
  3609. */
  3610. static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
  3611. {
  3612. unsigned long flags;
  3613. void *memptr;
  3614. stlibrd_t *brdp;
  3615. int brdnr, size, n;
  3616. void *p;
  3617. loff_t off = *offp;
  3618. brdnr = iminor(fp->f_dentry->d_inode);
  3619. if (brdnr >= stli_nrbrds)
  3620. return -ENODEV;
  3621. brdp = stli_brds[brdnr];
  3622. if (brdp == NULL)
  3623. return -ENODEV;
  3624. if (brdp->state == 0)
  3625. return -ENODEV;
  3626. if (off >= brdp->memsize || off + count < off)
  3627. return 0;
  3628. size = MIN(count, (brdp->memsize - off));
  3629. /*
  3630. * Copy the data a page at a time
  3631. */
  3632. p = (void *)__get_free_page(GFP_KERNEL);
  3633. if(p == NULL)
  3634. return -ENOMEM;
  3635. while (size > 0) {
  3636. spin_lock_irqsave(&brd_lock, flags);
  3637. EBRDENABLE(brdp);
  3638. memptr = (void *) EBRDGETMEMPTR(brdp, off);
  3639. n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
  3640. n = MIN(n, PAGE_SIZE);
  3641. memcpy_fromio(p, memptr, n);
  3642. EBRDDISABLE(brdp);
  3643. spin_unlock_irqrestore(&brd_lock, flags);
  3644. if (copy_to_user(buf, p, n)) {
  3645. count = -EFAULT;
  3646. goto out;
  3647. }
  3648. off += n;
  3649. buf += n;
  3650. size -= n;
  3651. }
  3652. out:
  3653. *offp = off;
  3654. free_page((unsigned long)p);
  3655. return count;
  3656. }
  3657. /*****************************************************************************/
  3658. /*
  3659. * Code to handle an "staliomem" write operation. This device is the
  3660. * contents of the board shared memory. It is used for down loading
  3661. * the slave image (and debugging :-)
  3662. *
  3663. * FIXME: copy under lock
  3664. */
  3665. static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
  3666. {
  3667. unsigned long flags;
  3668. void *memptr;
  3669. stlibrd_t *brdp;
  3670. char __user *chbuf;
  3671. int brdnr, size, n;
  3672. void *p;
  3673. loff_t off = *offp;
  3674. brdnr = iminor(fp->f_dentry->d_inode);
  3675. if (brdnr >= stli_nrbrds)
  3676. return -ENODEV;
  3677. brdp = stli_brds[brdnr];
  3678. if (brdp == NULL)
  3679. return -ENODEV;
  3680. if (brdp->state == 0)
  3681. return -ENODEV;
  3682. if (off >= brdp->memsize || off + count < off)
  3683. return 0;
  3684. chbuf = (char __user *) buf;
  3685. size = MIN(count, (brdp->memsize - off));
  3686. /*
  3687. * Copy the data a page at a time
  3688. */
  3689. p = (void *)__get_free_page(GFP_KERNEL);
  3690. if(p == NULL)
  3691. return -ENOMEM;
  3692. while (size > 0) {
  3693. n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
  3694. n = MIN(n, PAGE_SIZE);
  3695. if (copy_from_user(p, chbuf, n)) {
  3696. if (count == 0)
  3697. count = -EFAULT;
  3698. goto out;
  3699. }
  3700. spin_lock_irqsave(&brd_lock, flags);
  3701. EBRDENABLE(brdp);
  3702. memptr = (void *) EBRDGETMEMPTR(brdp, off);
  3703. memcpy_toio(memptr, p, n);
  3704. EBRDDISABLE(brdp);
  3705. spin_unlock_irqrestore(&brd_lock, flags);
  3706. off += n;
  3707. chbuf += n;
  3708. size -= n;
  3709. }
  3710. out:
  3711. free_page((unsigned long) p);
  3712. *offp = off;
  3713. return count;
  3714. }
  3715. /*****************************************************************************/
  3716. /*
  3717. * Return the board stats structure to user app.
  3718. */
  3719. static int stli_getbrdstats(combrd_t __user *bp)
  3720. {
  3721. stlibrd_t *brdp;
  3722. int i;
  3723. if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
  3724. return -EFAULT;
  3725. if (stli_brdstats.brd >= STL_MAXBRDS)
  3726. return -ENODEV;
  3727. brdp = stli_brds[stli_brdstats.brd];
  3728. if (brdp == NULL)
  3729. return -ENODEV;
  3730. memset(&stli_brdstats, 0, sizeof(combrd_t));
  3731. stli_brdstats.brd = brdp->brdnr;
  3732. stli_brdstats.type = brdp->brdtype;
  3733. stli_brdstats.hwid = 0;
  3734. stli_brdstats.state = brdp->state;
  3735. stli_brdstats.ioaddr = brdp->iobase;
  3736. stli_brdstats.memaddr = brdp->memaddr;
  3737. stli_brdstats.nrpanels = brdp->nrpanels;
  3738. stli_brdstats.nrports = brdp->nrports;
  3739. for (i = 0; (i < brdp->nrpanels); i++) {
  3740. stli_brdstats.panels[i].panel = i;
  3741. stli_brdstats.panels[i].hwid = brdp->panelids[i];
  3742. stli_brdstats.panels[i].nrports = brdp->panels[i];
  3743. }
  3744. if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
  3745. return -EFAULT;
  3746. return 0;
  3747. }
  3748. /*****************************************************************************/
  3749. /*
  3750. * Resolve the referenced port number into a port struct pointer.
  3751. */
  3752. static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
  3753. {
  3754. stlibrd_t *brdp;
  3755. int i;
  3756. if (brdnr < 0 || brdnr >= STL_MAXBRDS)
  3757. return NULL;
  3758. brdp = stli_brds[brdnr];
  3759. if (brdp == NULL)
  3760. return NULL;
  3761. for (i = 0; (i < panelnr); i++)
  3762. portnr += brdp->panels[i];
  3763. if ((portnr < 0) || (portnr >= brdp->nrports))
  3764. return NULL;
  3765. return brdp->ports[portnr];
  3766. }
  3767. /*****************************************************************************/
  3768. /*
  3769. * Return the port stats structure to user app. A NULL port struct
  3770. * pointer passed in means that we need to find out from the app
  3771. * what port to get stats for (used through board control device).
  3772. */
  3773. static int stli_portcmdstats(stliport_t *portp)
  3774. {
  3775. unsigned long flags;
  3776. stlibrd_t *brdp;
  3777. int rc;
  3778. memset(&stli_comstats, 0, sizeof(comstats_t));
  3779. if (portp == NULL)
  3780. return -ENODEV;
  3781. brdp = stli_brds[portp->brdnr];
  3782. if (brdp == NULL)
  3783. return -ENODEV;
  3784. if (brdp->state & BST_STARTED) {
  3785. if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
  3786. &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
  3787. return rc;
  3788. } else {
  3789. memset(&stli_cdkstats, 0, sizeof(asystats_t));
  3790. }
  3791. stli_comstats.brd = portp->brdnr;
  3792. stli_comstats.panel = portp->panelnr;
  3793. stli_comstats.port = portp->portnr;
  3794. stli_comstats.state = portp->state;
  3795. stli_comstats.flags = portp->flags;
  3796. spin_lock_irqsave(&brd_lock, flags);
  3797. if (portp->tty != NULL) {
  3798. if (portp->tty->driver_data == portp) {
  3799. stli_comstats.ttystate = portp->tty->flags;
  3800. stli_comstats.rxbuffered = -1;
  3801. if (portp->tty->termios != NULL) {
  3802. stli_comstats.cflags = portp->tty->termios->c_cflag;
  3803. stli_comstats.iflags = portp->tty->termios->c_iflag;
  3804. stli_comstats.oflags = portp->tty->termios->c_oflag;
  3805. stli_comstats.lflags = portp->tty->termios->c_lflag;
  3806. }
  3807. }
  3808. }
  3809. spin_unlock_irqrestore(&brd_lock, flags);
  3810. stli_comstats.txtotal = stli_cdkstats.txchars;
  3811. stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
  3812. stli_comstats.txbuffered = stli_cdkstats.txringq;
  3813. stli_comstats.rxbuffered += stli_cdkstats.rxringq;
  3814. stli_comstats.rxoverrun = stli_cdkstats.overruns;
  3815. stli_comstats.rxparity = stli_cdkstats.parity;
  3816. stli_comstats.rxframing = stli_cdkstats.framing;
  3817. stli_comstats.rxlost = stli_cdkstats.ringover;
  3818. stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
  3819. stli_comstats.txbreaks = stli_cdkstats.txbreaks;
  3820. stli_comstats.txxon = stli_cdkstats.txstart;
  3821. stli_comstats.txxoff = stli_cdkstats.txstop;
  3822. stli_comstats.rxxon = stli_cdkstats.rxstart;
  3823. stli_comstats.rxxoff = stli_cdkstats.rxstop;
  3824. stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
  3825. stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
  3826. stli_comstats.modem = stli_cdkstats.dcdcnt;
  3827. stli_comstats.hwid = stli_cdkstats.hwid;
  3828. stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
  3829. return 0;
  3830. }
  3831. /*****************************************************************************/
  3832. /*
  3833. * Return the port stats structure to user app. A NULL port struct
  3834. * pointer passed in means that we need to find out from the app
  3835. * what port to get stats for (used through board control device).
  3836. */
  3837. static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
  3838. {
  3839. stlibrd_t *brdp;
  3840. int rc;
  3841. if (!portp) {
  3842. if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
  3843. return -EFAULT;
  3844. portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
  3845. stli_comstats.port);
  3846. if (!portp)
  3847. return -ENODEV;
  3848. }
  3849. brdp = stli_brds[portp->brdnr];
  3850. if (!brdp)
  3851. return -ENODEV;
  3852. if ((rc = stli_portcmdstats(portp)) < 0)
  3853. return rc;
  3854. return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
  3855. -EFAULT : 0;
  3856. }
  3857. /*****************************************************************************/
  3858. /*
  3859. * Clear the port stats structure. We also return it zeroed out...
  3860. */
  3861. static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
  3862. {
  3863. stlibrd_t *brdp;
  3864. int rc;
  3865. if (!portp) {
  3866. if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
  3867. return -EFAULT;
  3868. portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
  3869. stli_comstats.port);
  3870. if (!portp)
  3871. return -ENODEV;
  3872. }
  3873. brdp = stli_brds[portp->brdnr];
  3874. if (!brdp)
  3875. return -ENODEV;
  3876. if (brdp->state & BST_STARTED) {
  3877. if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0)
  3878. return rc;
  3879. }
  3880. memset(&stli_comstats, 0, sizeof(comstats_t));
  3881. stli_comstats.brd = portp->brdnr;
  3882. stli_comstats.panel = portp->panelnr;
  3883. stli_comstats.port = portp->portnr;
  3884. if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
  3885. return -EFAULT;
  3886. return 0;
  3887. }
  3888. /*****************************************************************************/
  3889. /*
  3890. * Return the entire driver ports structure to a user app.
  3891. */
  3892. static int stli_getportstruct(stliport_t __user *arg)
  3893. {
  3894. stliport_t *portp;
  3895. if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t)))
  3896. return -EFAULT;
  3897. portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
  3898. stli_dummyport.portnr);
  3899. if (!portp)
  3900. return -ENODEV;
  3901. if (copy_to_user(arg, portp, sizeof(stliport_t)))
  3902. return -EFAULT;
  3903. return 0;
  3904. }
  3905. /*****************************************************************************/
  3906. /*
  3907. * Return the entire driver board structure to a user app.
  3908. */
  3909. static int stli_getbrdstruct(stlibrd_t __user *arg)
  3910. {
  3911. stlibrd_t *brdp;
  3912. if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t)))
  3913. return -EFAULT;
  3914. if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS))
  3915. return -ENODEV;
  3916. brdp = stli_brds[stli_dummybrd.brdnr];
  3917. if (!brdp)
  3918. return -ENODEV;
  3919. if (copy_to_user(arg, brdp, sizeof(stlibrd_t)))
  3920. return -EFAULT;
  3921. return 0;
  3922. }
  3923. /*****************************************************************************/
  3924. /*
  3925. * The "staliomem" device is also required to do some special operations on
  3926. * the board. We need to be able to send an interrupt to the board,
  3927. * reset it, and start/stop it.
  3928. */
  3929. static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
  3930. {
  3931. stlibrd_t *brdp;
  3932. int brdnr, rc, done;
  3933. void __user *argp = (void __user *)arg;
  3934. /*
  3935. * First up handle the board independent ioctls.
  3936. */
  3937. done = 0;
  3938. rc = 0;
  3939. switch (cmd) {
  3940. case COM_GETPORTSTATS:
  3941. rc = stli_getportstats(NULL, argp);
  3942. done++;
  3943. break;
  3944. case COM_CLRPORTSTATS:
  3945. rc = stli_clrportstats(NULL, argp);
  3946. done++;
  3947. break;
  3948. case COM_GETBRDSTATS:
  3949. rc = stli_getbrdstats(argp);
  3950. done++;
  3951. break;
  3952. case COM_READPORT:
  3953. rc = stli_getportstruct(argp);
  3954. done++;
  3955. break;
  3956. case COM_READBOARD:
  3957. rc = stli_getbrdstruct(argp);
  3958. done++;
  3959. break;
  3960. }
  3961. if (done)
  3962. return rc;
  3963. /*
  3964. * Now handle the board specific ioctls. These all depend on the
  3965. * minor number of the device they were called from.
  3966. */
  3967. brdnr = iminor(ip);
  3968. if (brdnr >= STL_MAXBRDS)
  3969. return -ENODEV;
  3970. brdp = stli_brds[brdnr];
  3971. if (!brdp)
  3972. return -ENODEV;
  3973. if (brdp->state == 0)
  3974. return -ENODEV;
  3975. switch (cmd) {
  3976. case STL_BINTR:
  3977. EBRDINTR(brdp);
  3978. break;
  3979. case STL_BSTART:
  3980. rc = stli_startbrd(brdp);
  3981. break;
  3982. case STL_BSTOP:
  3983. brdp->state &= ~BST_STARTED;
  3984. break;
  3985. case STL_BRESET:
  3986. brdp->state &= ~BST_STARTED;
  3987. EBRDRESET(brdp);
  3988. if (stli_shared == 0) {
  3989. if (brdp->reenable != NULL)
  3990. (* brdp->reenable)(brdp);
  3991. }
  3992. break;
  3993. default:
  3994. rc = -ENOIOCTLCMD;
  3995. break;
  3996. }
  3997. return rc;
  3998. }
  3999. static struct tty_operations stli_ops = {
  4000. .open = stli_open,
  4001. .close = stli_close,
  4002. .write = stli_write,
  4003. .put_char = stli_putchar,
  4004. .flush_chars = stli_flushchars,
  4005. .write_room = stli_writeroom,
  4006. .chars_in_buffer = stli_charsinbuffer,
  4007. .ioctl = stli_ioctl,
  4008. .set_termios = stli_settermios,
  4009. .throttle = stli_throttle,
  4010. .unthrottle = stli_unthrottle,
  4011. .stop = stli_stop,
  4012. .start = stli_start,
  4013. .hangup = stli_hangup,
  4014. .flush_buffer = stli_flushbuffer,
  4015. .break_ctl = stli_breakctl,
  4016. .wait_until_sent = stli_waituntilsent,
  4017. .send_xchar = stli_sendxchar,
  4018. .read_proc = stli_readproc,
  4019. .tiocmget = stli_tiocmget,
  4020. .tiocmset = stli_tiocmset,
  4021. };
  4022. /*****************************************************************************/
  4023. int __init stli_init(void)
  4024. {
  4025. int i;
  4026. printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
  4027. spin_lock_init(&stli_lock);
  4028. spin_lock_init(&brd_lock);
  4029. stli_initbrds();
  4030. stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
  4031. if (!stli_serial)
  4032. return -ENOMEM;
  4033. /*
  4034. * Allocate a temporary write buffer.
  4035. */
  4036. stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
  4037. if (!stli_txcookbuf)
  4038. printk(KERN_ERR "STALLION: failed to allocate memory "
  4039. "(size=%d)\n", STLI_TXBUFSIZE);
  4040. /*
  4041. * Set up a character driver for the shared memory region. We need this
  4042. * to down load the slave code image. Also it is a useful debugging tool.
  4043. */
  4044. if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
  4045. printk(KERN_ERR "STALLION: failed to register serial memory "
  4046. "device\n");
  4047. istallion_class = class_create(THIS_MODULE, "staliomem");
  4048. for (i = 0; i < 4; i++)
  4049. class_device_create(istallion_class, NULL,
  4050. MKDEV(STL_SIOMEMMAJOR, i),
  4051. NULL, "staliomem%d", i);
  4052. /*
  4053. * Set up the tty driver structure and register us as a driver.
  4054. */
  4055. stli_serial->owner = THIS_MODULE;
  4056. stli_serial->driver_name = stli_drvname;
  4057. stli_serial->name = stli_serialname;
  4058. stli_serial->major = STL_SERIALMAJOR;
  4059. stli_serial->minor_start = 0;
  4060. stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
  4061. stli_serial->subtype = SERIAL_TYPE_NORMAL;
  4062. stli_serial->init_termios = stli_deftermios;
  4063. stli_serial->flags = TTY_DRIVER_REAL_RAW;
  4064. tty_set_operations(stli_serial, &stli_ops);
  4065. if (tty_register_driver(stli_serial)) {
  4066. put_tty_driver(stli_serial);
  4067. printk(KERN_ERR "STALLION: failed to register serial driver\n");
  4068. return -EBUSY;
  4069. }
  4070. return 0;
  4071. }
  4072. /*****************************************************************************/