cyclades.c 175 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505
  1. #undef BLOCKMOVE
  2. #define Z_WAKE
  3. #undef Z_EXT_CHARS_IN_BUFFER
  4. static char rcsid[] =
  5. "$Revision: 2.3.2.20 $$Date: 2004/02/25 18:14:16 $";
  6. /*
  7. * linux/drivers/char/cyclades.c
  8. *
  9. * This file contains the driver for the Cyclades async multiport
  10. * serial boards.
  11. *
  12. * Initially written by Randolph Bentson <bentson@grieg.seaslug.org>.
  13. * Modified and maintained by Marcio Saito <marcio@cyclades.com>.
  14. * Currently maintained by Cyclades team <async@cyclades.com>.
  15. *
  16. * For Technical support and installation problems, please send e-mail
  17. * to support@cyclades.com.
  18. *
  19. * Much of the design and some of the code came from serial.c
  20. * which was copyright (C) 1991, 1992 Linus Torvalds. It was
  21. * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92,
  22. * and then fixed as suggested by Michael K. Johnson 12/12/92.
  23. *
  24. * This version supports shared IRQ's (only for PCI boards).
  25. *
  26. * $Log: cyclades.c,v $
  27. * Prevent users from opening non-existing Z ports.
  28. *
  29. * Revision 2.3.2.8 2000/07/06 18:14:16 ivan
  30. * Fixed the PCI detection function to work properly on Alpha systems.
  31. * Implemented support for TIOCSERGETLSR ioctl.
  32. * Implemented full support for non-standard baud rates.
  33. *
  34. * Revision 2.3.2.7 2000/06/01 18:26:34 ivan
  35. * Request PLX I/O region, although driver doesn't use it, to avoid
  36. * problems with other drivers accessing it.
  37. * Removed count for on-board buffer characters in cy_chars_in_buffer
  38. * (Cyclades-Z only).
  39. *
  40. * Revision 2.3.2.6 2000/05/05 13:56:05 ivan
  41. * Driver now reports physical instead of virtual memory addresses.
  42. * Masks were added to some Cyclades-Z read accesses.
  43. * Implemented workaround for PLX9050 bug that would cause a system lockup
  44. * in certain systems, depending on the MMIO addresses allocated to the
  45. * board.
  46. * Changed the Tx interrupt programming in the CD1400 chips to boost up
  47. * performance (Cyclom-Y only).
  48. * Code is now compliant with the new module interface (module_[init|exit]).
  49. * Make use of the PCI helper functions to access PCI resources.
  50. * Did some code "housekeeping".
  51. *
  52. * Revision 2.3.2.5 2000/01/19 14:35:33 ivan
  53. * Fixed bug in cy_set_termios on CRTSCTS flag turnoff.
  54. *
  55. * Revision 2.3.2.4 2000/01/17 09:19:40 ivan
  56. * Fixed SMP locking in Cyclom-Y interrupt handler.
  57. *
  58. * Revision 2.3.2.3 1999/12/28 12:11:39 ivan
  59. * Added a new cyclades_card field called nports to allow the driver to
  60. * know the exact number of ports found by the Z firmware after its load;
  61. * RX buffer contention prevention logic on interrupt op mode revisited
  62. * (Cyclades-Z only);
  63. * Revisited printk's for Z debug;
  64. * Driver now makes sure that the constant SERIAL_XMIT_SIZE is defined;
  65. *
  66. * Revision 2.3.2.2 1999/10/01 11:27:43 ivan
  67. * Fixed bug in cyz_poll that would make all ports but port 0
  68. * unable to transmit/receive data (Cyclades-Z only);
  69. * Implemented logic to prevent the RX buffer from being stuck with data
  70. * due to a driver / firmware race condition in interrupt op mode
  71. * (Cyclades-Z only);
  72. * Fixed bug in block_til_ready logic that would lead to a system crash;
  73. * Revisited cy_close spinlock usage;
  74. *
  75. * Revision 2.3.2.1 1999/09/28 11:01:22 ivan
  76. * Revisited CONFIG_PCI conditional compilation for PCI board support;
  77. * Implemented TIOCGICOUNT and TIOCMIWAIT ioctl support;
  78. * _Major_ cleanup on the Cyclades-Z interrupt support code / logic;
  79. * Removed CTS handling from the driver -- this is now completely handled
  80. * by the firmware (Cyclades-Z only);
  81. * Flush RX on-board buffers on a port open (Cyclades-Z only);
  82. * Fixed handling of ASYNC_SPD_* TTY flags;
  83. * Module unload now unmaps all memory area allocated by ioremap;
  84. *
  85. * Revision 2.3.1.1 1999/07/15 16:45:53 ivan
  86. * Removed CY_PROC conditional compilation;
  87. * Implemented SMP-awareness for the driver;
  88. * Implemented a new ISA IRQ autoprobe that uses the irq_probe_[on|off]
  89. * functions;
  90. * The driver now accepts memory addresses (maddr=0xMMMMM) and IRQs
  91. * (irq=NN) as parameters (only for ISA boards);
  92. * Fixed bug in set_line_char that would prevent the Cyclades-Z
  93. * ports from being configured at speeds above 115.2Kbps;
  94. * Fixed bug in cy_set_termios that would prevent XON/XOFF flow control
  95. * switching from working properly;
  96. * The driver now only prints IRQ info for the Cyclades-Z if it's
  97. * configured to work in interrupt mode;
  98. *
  99. * Revision 2.2.2.3 1999/06/28 11:13:29 ivan
  100. * Added support for interrupt mode operation for the Z cards;
  101. * Removed the driver inactivity control for the Z;
  102. * Added a missing MOD_DEC_USE_COUNT in the cy_open function for when
  103. * the Z firmware is not loaded yet;
  104. * Replaced the "manual" Z Tx flush buffer by a call to a FW command of
  105. * same functionality;
  106. * Implemented workaround for IRQ setting loss on the PCI configuration
  107. * registers after a PCI bridge EEPROM reload (affects PLX9060 only);
  108. *
  109. * Revision 2.2.2.2 1999/05/14 17:18:15 ivan
  110. * /proc entry location changed to /proc/tty/driver/cyclades;
  111. * Added support to shared IRQ's (only for PCI boards);
  112. * Added support for Cobalt Qube2 systems;
  113. * IRQ [de]allocation scheme revisited;
  114. * BREAK implementation changed in order to make use of the 'break_ctl'
  115. * TTY facility;
  116. * Fixed typo in TTY structure field 'driver_name';
  117. * Included a PCI bridge reset and EEPROM reload in the board
  118. * initialization code (for both Y and Z series).
  119. *
  120. * Revision 2.2.2.1 1999/04/08 16:17:43 ivan
  121. * Fixed a bug in cy_wait_until_sent that was preventing the port to be
  122. * closed properly after a SIGINT;
  123. * Module usage counter scheme revisited;
  124. * Added support to the upcoming Y PCI boards (i.e., support to additional
  125. * PCI Device ID's).
  126. *
  127. * Revision 2.2.1.10 1999/01/20 16:14:29 ivan
  128. * Removed all unnecessary page-alignement operations in ioremap calls
  129. * (ioremap is currently safe for these operations).
  130. *
  131. * Revision 2.2.1.9 1998/12/30 18:18:30 ivan
  132. * Changed access to PLX PCI bridge registers from I/O to MMIO, in
  133. * order to make PLX9050-based boards work with certain motherboards.
  134. *
  135. * Revision 2.2.1.8 1998/11/13 12:46:20 ivan
  136. * cy_close function now resets (correctly) the tty->closing flag;
  137. * JIFFIES_DIFF macro fixed.
  138. *
  139. * Revision 2.2.1.7 1998/09/03 12:07:28 ivan
  140. * Fixed bug in cy_close function, which was not informing HW of
  141. * which port should have the reception disabled before doing so;
  142. * fixed Cyclom-8YoP hardware detection bug.
  143. *
  144. * Revision 2.2.1.6 1998/08/20 17:15:39 ivan
  145. * Fixed bug in cy_close function, which causes malfunction
  146. * of one of the first 4 ports when a higher port is closed
  147. * (Cyclom-Y only).
  148. *
  149. * Revision 2.2.1.5 1998/08/10 18:10:28 ivan
  150. * Fixed Cyclom-4Yo hardware detection bug.
  151. *
  152. * Revision 2.2.1.4 1998/08/04 11:02:50 ivan
  153. * /proc/cyclades implementation with great collaboration of
  154. * Marc Lewis <marc@blarg.net>;
  155. * cyy_interrupt was changed to avoid occurrence of kernel oopses
  156. * during PPP operation.
  157. *
  158. * Revision 2.2.1.3 1998/06/01 12:09:10 ivan
  159. * General code review in order to comply with 2.1 kernel standards;
  160. * data loss prevention for slow devices revisited (cy_wait_until_sent
  161. * was created);
  162. * removed conditional compilation for new/old PCI structure support
  163. * (now the driver only supports the new PCI structure).
  164. *
  165. * Revision 2.2.1.1 1998/03/19 16:43:12 ivan
  166. * added conditional compilation for new/old PCI structure support;
  167. * removed kernel series (2.0.x / 2.1.x) conditional compilation.
  168. *
  169. * Revision 2.1.1.3 1998/03/16 18:01:12 ivan
  170. * cleaned up the data loss fix;
  171. * fixed XON/XOFF handling once more (Cyclades-Z);
  172. * general review of the driver routines;
  173. * introduction of a mechanism to prevent data loss with slow
  174. * printers, by forcing a delay before closing the port.
  175. *
  176. * Revision 2.1.1.2 1998/02/17 16:50:00 ivan
  177. * fixed detection/handling of new CD1400 in Ye boards;
  178. * fixed XON/XOFF handling (Cyclades-Z);
  179. * fixed data loss caused by a premature port close;
  180. * introduction of a flag that holds the CD1400 version ID per port
  181. * (used by the CYGETCD1400VER new ioctl).
  182. *
  183. * Revision 2.1.1.1 1997/12/03 17:31:19 ivan
  184. * Code review for the module cleanup routine;
  185. * fixed RTS and DTR status report for new CD1400's in get_modem_info;
  186. * includes anonymous changes regarding signal_pending.
  187. *
  188. * Revision 2.1 1997/11/01 17:42:41 ivan
  189. * Changes in the driver to support Alpha systems (except 8Zo V_1);
  190. * BREAK fix for the Cyclades-Z boards;
  191. * driver inactivity control by FW implemented;
  192. * introduction of flag that allows driver to take advantage of
  193. * a special CD1400 feature related to HW flow control;
  194. * added support for the CD1400 rev. J (Cyclom-Y boards);
  195. * introduction of ioctls to:
  196. * - control the rtsdtr_inv flag (Cyclom-Y);
  197. * - control the rflow flag (Cyclom-Y);
  198. * - adjust the polling interval (Cyclades-Z);
  199. *
  200. * Revision 1.36.4.33 1997/06/27 19:00:00 ivan
  201. * Fixes related to kernel version conditional
  202. * compilation.
  203. *
  204. * Revision 1.36.4.32 1997/06/14 19:30:00 ivan
  205. * Compatibility issues between kernels 2.0.x and
  206. * 2.1.x (mainly related to clear_bit function).
  207. *
  208. * Revision 1.36.4.31 1997/06/03 15:30:00 ivan
  209. * Changes to define the memory window according to the
  210. * board type.
  211. *
  212. * Revision 1.36.4.30 1997/05/16 15:30:00 daniel
  213. * Changes to support new cycladesZ boards.
  214. *
  215. * Revision 1.36.4.29 1997/05/12 11:30:00 daniel
  216. * Merge of Bentson's and Daniel's version 1.36.4.28.
  217. * Corrects bug in cy_detect_pci: check if there are more
  218. * ports than the number of static structs allocated.
  219. * Warning message during initialization if this driver is
  220. * used with the new generation of cycladesZ boards. Those
  221. * will be supported only in next release of the driver.
  222. * Corrects bug in cy_detect_pci and cy_detect_isa that
  223. * returned wrong number of VALID boards, when a cyclomY
  224. * was found with no serial modules connected.
  225. * Changes to use current (2.1.x) kernel subroutine names
  226. * and created macros for compilation with 2.0.x kernel,
  227. * instead of the other way around.
  228. *
  229. * Revision 1.36.4.28 1997/05/?? ??:00:00 bentson
  230. * Change queue_task_irq_off to queue_task_irq.
  231. * The inline function queue_task_irq_off (tqueue.h)
  232. * was removed from latest releases of 2.1.x kernel.
  233. * Use of macro __init to mark the initialization
  234. * routines, so memory can be reused.
  235. * Also incorporate implementation of critical region
  236. * in function cleanup_module() created by anonymous
  237. * linuxer.
  238. *
  239. * Revision 1.36.4.28 1997/04/25 16:00:00 daniel
  240. * Change to support new firmware that solves DCD problem:
  241. * application could fail to receive SIGHUP signal when DCD
  242. * varying too fast.
  243. *
  244. * Revision 1.36.4.27 1997/03/26 10:30:00 daniel
  245. * Changed for support linux versions 2.1.X.
  246. * Backward compatible with linux versions 2.0.X.
  247. * Corrected illegal use of filler field in
  248. * CH_CTRL struct.
  249. * Deleted some debug messages.
  250. *
  251. * Revision 1.36.4.26 1997/02/27 12:00:00 daniel
  252. * Included check for NULL tty pointer in cyz_poll.
  253. *
  254. * Revision 1.36.4.25 1997/02/26 16:28:30 bentson
  255. * Bill Foster at Blarg! Online services noticed that
  256. * some of the switch elements of -Z modem control
  257. * lacked a closing "break;"
  258. *
  259. * Revision 1.36.4.24 1997/02/24 11:00:00 daniel
  260. * Changed low water threshold for buffer xmit_buf
  261. *
  262. * Revision 1.36.4.23 1996/12/02 21:50:16 bentson
  263. * Marcio provided fix to modem status fetch for -Z
  264. *
  265. * Revision 1.36.4.22 1996/10/28 22:41:17 bentson
  266. * improve mapping of -Z control page (thanks to Steve
  267. * Price <stevep@fa.tdktca.com> for help on this)
  268. *
  269. * Revision 1.36.4.21 1996/09/10 17:00:10 bentson
  270. * shift from CPU-bound to memcopy in cyz_polling operation
  271. *
  272. * Revision 1.36.4.20 1996/09/09 18:30:32 Bentson
  273. * Added support to set and report higher speeds.
  274. *
  275. * Revision 1.36.4.19c 1996/08/09 10:00:00 Marcio Saito
  276. * Some fixes in the HW flow control for the BETA release.
  277. * Don't try to register the IRQ.
  278. *
  279. * Revision 1.36.4.19 1996/08/08 16:23:18 Bentson
  280. * make sure "cyc" appears in all kernel messages; all soft interrupts
  281. * handled by same routine; recognize out-of-band reception; comment
  282. * out some diagnostic messages; leave RTS/CTS flow control to hardware;
  283. * fix race condition in -Z buffer management; only -Y needs to explicitly
  284. * flush chars; tidy up some startup messages;
  285. *
  286. * Revision 1.36.4.18 1996/07/25 18:57:31 bentson
  287. * shift MOD_INC_USE_COUNT location to match
  288. * serial.c; purge some diagnostic messages;
  289. *
  290. * Revision 1.36.4.17 1996/07/25 18:01:08 bentson
  291. * enable modem status messages and fetch & process them; note
  292. * time of last activity type for each port; set_line_char now
  293. * supports more than line 0 and treats 0 baud correctly;
  294. * get_modem_info senses rs_status;
  295. *
  296. * Revision 1.36.4.16 1996/07/20 08:43:15 bentson
  297. * barely works--now's time to turn on
  298. * more features 'til it breaks
  299. *
  300. * Revision 1.36.4.15 1996/07/19 22:30:06 bentson
  301. * check more -Z board status; shorten boot message
  302. *
  303. * Revision 1.36.4.14 1996/07/19 22:20:37 bentson
  304. * fix reference to ch_ctrl in startup; verify return
  305. * values from cyz_issue_cmd and cyz_update_channel;
  306. * more stuff to get modem control correct;
  307. *
  308. * Revision 1.36.4.13 1996/07/11 19:53:33 bentson
  309. * more -Z stuff folded in; re-order changes to put -Z stuff
  310. * after -Y stuff (to make changes clearer)
  311. *
  312. * Revision 1.36.4.12 1996/07/11 15:40:55 bentson
  313. * Add code to poll Cyclades-Z. Add code to get & set RS-232 control.
  314. * Add code to send break. Clear firmware ID word at startup (so
  315. * that other code won't talk to inactive board).
  316. *
  317. * Revision 1.36.4.11 1996/07/09 05:28:29 bentson
  318. * add code for -Z in set_line_char
  319. *
  320. * Revision 1.36.4.10 1996/07/08 19:28:37 bentson
  321. * fold more -Z stuff (or in some cases, error messages)
  322. * into driver; add text to "don't know what to do" messages.
  323. *
  324. * Revision 1.36.4.9 1996/07/08 18:38:38 bentson
  325. * moved compile-time flags near top of file; cosmetic changes
  326. * to narrow text (to allow 2-up printing); changed many declarations
  327. * to "static" to limit external symbols; shuffled code order to
  328. * coalesce -Y and -Z specific code, also to put internal functions
  329. * in order of tty_driver structure; added code to recognize -Z
  330. * ports (and for moment, do nothing or report error); add cy_startup
  331. * to parse boot command line for extra base addresses for ISA probes;
  332. *
  333. * Revision 1.36.4.8 1996/06/25 17:40:19 bentson
  334. * reorder some code, fix types of some vars (int vs. long),
  335. * add cy_setup to support user declared ISA addresses
  336. *
  337. * Revision 1.36.4.7 1996/06/21 23:06:18 bentson
  338. * dump ioctl based firmware load (it's now a user level
  339. * program); ensure uninitialzed ports cannot be used
  340. *
  341. * Revision 1.36.4.6 1996/06/20 23:17:19 bentson
  342. * rename vars and restructure some code
  343. *
  344. * Revision 1.36.4.5 1996/06/14 15:09:44 bentson
  345. * get right status back after boot load
  346. *
  347. * Revision 1.36.4.4 1996/06/13 19:51:44 bentson
  348. * successfully loads firmware
  349. *
  350. * Revision 1.36.4.3 1996/06/13 06:08:33 bentson
  351. * add more of the code for the boot/load ioctls
  352. *
  353. * Revision 1.36.4.2 1996/06/11 21:00:51 bentson
  354. * start to add Z functionality--starting with ioctl
  355. * for loading firmware
  356. *
  357. * Revision 1.36.4.1 1996/06/10 18:03:02 bentson
  358. * added code to recognize Z/PCI card at initialization; report
  359. * presence, but card is not initialized (because firmware needs
  360. * to be loaded)
  361. *
  362. * Revision 1.36.3.8 1996/06/07 16:29:00 bentson
  363. * starting minor number at zero; added missing verify_area
  364. * as noted by Heiko Eissfeldt <heiko@colossus.escape.de>
  365. *
  366. * Revision 1.36.3.7 1996/04/19 21:06:18 bentson
  367. * remove unneeded boot message & fix CLOCAL hardware flow
  368. * control (Miquel van Smoorenburg <miquels@Q.cistron.nl>);
  369. * remove unused diagnostic statements; minor 0 is first;
  370. *
  371. * Revision 1.36.3.6 1996/03/13 13:21:17 marcio
  372. * The kernel function vremap (available only in later 1.3.xx kernels)
  373. * allows the access to memory addresses above the RAM. This revision
  374. * of the driver supports PCI boards below 1Mb (device id 0x100) and
  375. * above 1Mb (device id 0x101).
  376. *
  377. * Revision 1.36.3.5 1996/03/07 15:20:17 bentson
  378. * Some global changes to interrupt handling spilled into
  379. * this driver--mostly unused arguments in system function
  380. * calls. Also added change by Marcio Saito which should
  381. * reduce lost interrupts at startup by fast processors.
  382. *
  383. * Revision 1.36.3.4 1995/11/13 20:45:10 bentson
  384. * Changes by Corey Minyard <minyard@wf-rch.cirr.com> distributed
  385. * in 1.3.41 kernel to remove a possible race condition, extend
  386. * some error messages, and let the driver run as a loadable module
  387. * Change by Alan Wendt <alan@ez0.ezlink.com> to remove a
  388. * possible race condition.
  389. * Change by Marcio Saito <marcio@cyclades.com> to fix PCI addressing.
  390. *
  391. * Revision 1.36.3.3 1995/11/13 19:44:48 bentson
  392. * Changes by Linus Torvalds in 1.3.33 kernel distribution
  393. * required due to reordering of driver initialization.
  394. * Drivers are now initialized *after* memory management.
  395. *
  396. * Revision 1.36.3.2 1995/09/08 22:07:14 bentson
  397. * remove printk from ISR; fix typo
  398. *
  399. * Revision 1.36.3.1 1995/09/01 12:00:42 marcio
  400. * Minor fixes in the PCI board support. PCI function calls in
  401. * conditional compilation (CONFIG_PCI). Thanks to Jim Duncan
  402. * <duncan@okay.com>. "bad serial count" message removed.
  403. *
  404. * Revision 1.36.3 1995/08/22 09:19:42 marcio
  405. * Cyclom-Y/PCI support added. Changes in the cy_init routine and
  406. * board initialization. Changes in the boot messages. The driver
  407. * supports up to 4 boards and 64 ports by default.
  408. *
  409. * Revision 1.36.1.4 1995/03/29 06:14:14 bentson
  410. * disambiguate between Cyclom-16Y and Cyclom-32Ye;
  411. *
  412. * Revision 1.36.1.3 1995/03/23 22:15:35 bentson
  413. * add missing break in modem control block in ioctl switch statement
  414. * (discovered by Michael Edward Chastain <mec@jobe.shell.portal.com>);
  415. *
  416. * Revision 1.36.1.2 1995/03/22 19:16:22 bentson
  417. * make sure CTS flow control is set as soon as possible (thanks
  418. * to note from David Lambert <lambert@chesapeake.rps.slb.com>);
  419. *
  420. * Revision 1.36.1.1 1995/03/13 15:44:43 bentson
  421. * initialize defaults for receive threshold and stale data timeout;
  422. * cosmetic changes;
  423. *
  424. * Revision 1.36 1995/03/10 23:33:53 bentson
  425. * added support of chips 4-7 in 32 port Cyclom-Ye;
  426. * fix cy_interrupt pointer dereference problem
  427. * (Joe Portman <baron@aa.net>);
  428. * give better error response if open is attempted on non-existent port
  429. * (Zachariah Vaum <jchryslr@netcom.com>);
  430. * correct command timeout (Kenneth Lerman <lerman@@seltd.newnet.com>);
  431. * conditional compilation for -16Y on systems with fast, noisy bus;
  432. * comment out diagnostic print function;
  433. * cleaned up table of base addresses;
  434. * set receiver time-out period register to correct value,
  435. * set receive threshold to better default values,
  436. * set chip timer to more accurate 200 Hz ticking,
  437. * add code to monitor and modify receive parameters
  438. * (Rik Faith <faith@cs.unc.edu> Nick Simicich
  439. * <njs@scifi.emi.net>);
  440. *
  441. * Revision 1.35 1994/12/16 13:54:18 steffen
  442. * additional patch by Marcio Saito for board detection
  443. * Accidently left out in 1.34
  444. *
  445. * Revision 1.34 1994/12/10 12:37:12 steffen
  446. * This is the corrected version as suggested by Marcio Saito
  447. *
  448. * Revision 1.33 1994/12/01 22:41:18 bentson
  449. * add hooks to support more high speeds directly; add tytso
  450. * patch regarding CLOCAL wakeups
  451. *
  452. * Revision 1.32 1994/11/23 19:50:04 bentson
  453. * allow direct kernel control of higher signalling rates;
  454. * look for cards at additional locations
  455. *
  456. * Revision 1.31 1994/11/16 04:33:28 bentson
  457. * ANOTHER fix from Corey Minyard, minyard@wf-rch.cirr.com--
  458. * a problem in chars_in_buffer has been resolved by some
  459. * small changes; this should yield smoother output
  460. *
  461. * Revision 1.30 1994/11/16 04:28:05 bentson
  462. * Fix from Corey Minyard, Internet: minyard@metronet.com,
  463. * UUCP: minyard@wf-rch.cirr.com, WORK: minyardbnr.ca, to
  464. * cy_hangup that appears to clear up much (all?) of the
  465. * DTR glitches; also he's added/cleaned-up diagnostic messages
  466. *
  467. * Revision 1.29 1994/11/16 04:16:07 bentson
  468. * add change proposed by Ralph Sims, ralphs@halcyon.com, to
  469. * operate higher speeds in same way as other serial ports;
  470. * add more serial ports (for up to two 16-port muxes).
  471. *
  472. * Revision 1.28 1994/11/04 00:13:16 root
  473. * turn off diagnostic messages
  474. *
  475. * Revision 1.27 1994/11/03 23:46:37 root
  476. * bunch of changes to bring driver into greater conformance
  477. * with the serial.c driver (looking for missed fixes)
  478. *
  479. * Revision 1.26 1994/11/03 22:40:36 root
  480. * automatic interrupt probing fixed.
  481. *
  482. * Revision 1.25 1994/11/03 20:17:02 root
  483. * start to implement auto-irq
  484. *
  485. * Revision 1.24 1994/11/03 18:01:55 root
  486. * still working on modem signals--trying not to drop DTR
  487. * during the getty/login processes
  488. *
  489. * Revision 1.23 1994/11/03 17:51:36 root
  490. * extend baud rate support; set receive threshold as function
  491. * of baud rate; fix some problems with RTS/CTS;
  492. *
  493. * Revision 1.22 1994/11/02 18:05:35 root
  494. * changed arguments to udelay to type long to get
  495. * delays to be of correct duration
  496. *
  497. * Revision 1.21 1994/11/02 17:37:30 root
  498. * employ udelay (after calibrating loops_per_second earlier
  499. * in init/main.c) instead of using home-grown delay routines
  500. *
  501. * Revision 1.20 1994/11/02 03:11:38 root
  502. * cy_chars_in_buffer forces a return value of 0 to let
  503. * login work (don't know why it does); some functions
  504. * that were returning EFAULT, now executes the code;
  505. * more work on deciding when to disable xmit interrupts;
  506. *
  507. * Revision 1.19 1994/11/01 20:10:14 root
  508. * define routine to start transmission interrupts (by enabling
  509. * transmit interrupts); directly enable/disable modem interrupts;
  510. *
  511. * Revision 1.18 1994/11/01 18:40:45 bentson
  512. * Don't always enable transmit interrupts in startup; interrupt on
  513. * TxMpty instead of TxRdy to help characters get out before shutdown;
  514. * restructure xmit interrupt to check for chars first and quit if
  515. * none are ready to go; modem status (MXVRx) is upright, _not_ inverted
  516. * (to my view);
  517. *
  518. * Revision 1.17 1994/10/30 04:39:45 bentson
  519. * rename serial_driver and callout_driver to cy_serial_driver and
  520. * cy_callout_driver to avoid linkage interference; initialize
  521. * info->type to PORT_CIRRUS; ruggedize paranoia test; elide ->port
  522. * from cyclades_port structure; add paranoia check to cy_close;
  523. *
  524. * Revision 1.16 1994/10/30 01:14:33 bentson
  525. * change major numbers; add some _early_ return statements;
  526. *
  527. * Revision 1.15 1994/10/29 06:43:15 bentson
  528. * final tidying up for clean compile; enable some error reporting
  529. *
  530. * Revision 1.14 1994/10/28 20:30:22 Bentson
  531. * lots of changes to drag the driver towards the new tty_io
  532. * structures and operation. not expected to work, but may
  533. * compile cleanly.
  534. *
  535. * Revision 1.13 1994/07/21 23:08:57 Bentson
  536. * add some diagnostic cruft; support 24 lines (for testing
  537. * both -8Y and -16Y cards; be more thorough in servicing all
  538. * chips during interrupt; add "volatile" a few places to
  539. * circumvent compiler optimizations; fix base & offset
  540. * computations in block_til_ready (was causing chip 0 to
  541. * stop operation)
  542. *
  543. * Revision 1.12 1994/07/19 16:42:11 Bentson
  544. * add some hackery for kernel version 1.1.8; expand
  545. * error messages; refine timing for delay loops and
  546. * declare loop params volatile
  547. *
  548. * Revision 1.11 1994/06/11 21:53:10 bentson
  549. * get use of save_car right in transmit interrupt service
  550. *
  551. * Revision 1.10.1.1 1994/06/11 21:31:18 bentson
  552. * add some diagnostic printing; try to fix save_car stuff
  553. *
  554. * Revision 1.10 1994/06/11 20:36:08 bentson
  555. * clean up compiler warnings
  556. *
  557. * Revision 1.9 1994/06/11 19:42:46 bentson
  558. * added a bunch of code to support modem signalling
  559. *
  560. * Revision 1.8 1994/06/11 17:57:07 bentson
  561. * recognize break & parity error
  562. *
  563. * Revision 1.7 1994/06/05 05:51:34 bentson
  564. * Reorder baud table to be monotonic; add cli to CP; discard
  565. * incoming characters and status if the line isn't open; start to
  566. * fold code into cy_throttle; start to port get_serial_info,
  567. * set_serial_info, get_modem_info, set_modem_info, and send_break
  568. * from serial.c; expand cy_ioctl; relocate and expand config_setup;
  569. * get flow control characters from tty struct; invalidate ports w/o
  570. * hardware;
  571. *
  572. * Revision 1.6 1994/05/31 18:42:21 bentson
  573. * add a loop-breaker in the interrupt service routine;
  574. * note when port is initialized so that it can be shut
  575. * down under the right conditions; receive works without
  576. * any obvious errors
  577. *
  578. * Revision 1.5 1994/05/30 00:55:02 bentson
  579. * transmit works without obvious errors
  580. *
  581. * Revision 1.4 1994/05/27 18:46:27 bentson
  582. * incorporated more code from lib_y.c; can now print short
  583. * strings under interrupt control to port zero; seems to
  584. * select ports/channels/lines correctly
  585. *
  586. * Revision 1.3 1994/05/25 22:12:44 bentson
  587. * shifting from multi-port on a card to proper multiplexor
  588. * data structures; added skeletons of most routines
  589. *
  590. * Revision 1.2 1994/05/19 13:21:43 bentson
  591. * start to crib from other sources
  592. *
  593. */
  594. /* If you need to install more boards than NR_CARDS, change the constant
  595. in the definition below. No other change is necessary to support up to
  596. eight boards. Beyond that you'll have to extend cy_isa_addresses. */
  597. #define NR_CARDS 4
  598. /*
  599. If the total number of ports is larger than NR_PORTS, change this
  600. constant in the definition below. No other change is necessary to
  601. support more boards/ports. */
  602. #define NR_PORTS 256
  603. #define ZE_V1_NPORTS 64
  604. #define ZO_V1 0
  605. #define ZO_V2 1
  606. #define ZE_V1 2
  607. #define SERIAL_PARANOIA_CHECK
  608. #undef CY_DEBUG_OPEN
  609. #undef CY_DEBUG_THROTTLE
  610. #undef CY_DEBUG_OTHER
  611. #undef CY_DEBUG_IO
  612. #undef CY_DEBUG_COUNT
  613. #undef CY_DEBUG_DTR
  614. #undef CY_DEBUG_WAIT_UNTIL_SENT
  615. #undef CY_DEBUG_INTERRUPTS
  616. #undef CY_16Y_HACK
  617. #undef CY_ENABLE_MONITORING
  618. #undef CY_PCI_DEBUG
  619. #if 0
  620. #define PAUSE __asm__("nop");
  621. #else
  622. #define PAUSE ;
  623. #endif
  624. /*
  625. * Include section
  626. */
  627. #include <linux/config.h>
  628. #include <linux/module.h>
  629. #include <linux/errno.h>
  630. #include <linux/signal.h>
  631. #include <linux/sched.h>
  632. #include <linux/timer.h>
  633. #include <linux/interrupt.h>
  634. #include <linux/tty.h>
  635. #include <linux/tty_flip.h>
  636. #include <linux/serial.h>
  637. #include <linux/major.h>
  638. #include <linux/string.h>
  639. #include <linux/fcntl.h>
  640. #include <linux/ptrace.h>
  641. #include <linux/cyclades.h>
  642. #include <linux/mm.h>
  643. #include <linux/ioport.h>
  644. #include <linux/init.h>
  645. #include <linux/delay.h>
  646. #include <linux/spinlock.h>
  647. #include <linux/bitops.h>
  648. #include <asm/system.h>
  649. #include <asm/io.h>
  650. #include <asm/irq.h>
  651. #include <asm/uaccess.h>
  652. #define CY_LOCK(info,flags) \
  653. do { \
  654. spin_lock_irqsave(&cy_card[info->card].card_lock, flags); \
  655. } while (0)
  656. #define CY_UNLOCK(info,flags) \
  657. do { \
  658. spin_unlock_irqrestore(&cy_card[info->card].card_lock, flags); \
  659. } while (0)
  660. #include <linux/types.h>
  661. #include <linux/kernel.h>
  662. #include <linux/pci.h>
  663. #include <linux/stat.h>
  664. #include <linux/proc_fs.h>
  665. static void cy_throttle (struct tty_struct *tty);
  666. static void cy_send_xchar (struct tty_struct *tty, char ch);
  667. #define IS_CYC_Z(card) ((card).num_chips == -1)
  668. #define Z_FPGA_CHECK(card) \
  669. ((cy_readl(&((struct RUNTIME_9060 __iomem *) \
  670. ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0)
  671. #define ISZLOADED(card) (((ZO_V1==cy_readl(&((struct RUNTIME_9060 __iomem *) \
  672. ((card).ctl_addr))->mail_box_0)) || \
  673. Z_FPGA_CHECK(card)) && \
  674. (ZFIRM_ID==cy_readl(&((struct FIRM_ID __iomem *) \
  675. ((card).base_addr+ID_ADDRESS))->signature)))
  676. #ifndef SERIAL_XMIT_SIZE
  677. #define SERIAL_XMIT_SIZE (min(PAGE_SIZE, 4096))
  678. #endif
  679. #define WAKEUP_CHARS 256
  680. #define STD_COM_FLAGS (0)
  681. #define JIFFIES_DIFF(n, j) ((j) - (n))
  682. static struct tty_driver *cy_serial_driver;
  683. #ifdef CONFIG_ISA
  684. /* This is the address lookup table. The driver will probe for
  685. Cyclom-Y/ISA boards at all addresses in here. If you want the
  686. driver to probe addresses at a different address, add it to
  687. this table. If the driver is probing some other board and
  688. causing problems, remove the offending address from this table.
  689. The cy_setup function extracts additional addresses from the
  690. boot options line. The form is "cyclades=address,address..."
  691. */
  692. static unsigned int cy_isa_addresses[] = {
  693. 0xD0000,
  694. 0xD2000,
  695. 0xD4000,
  696. 0xD6000,
  697. 0xD8000,
  698. 0xDA000,
  699. 0xDC000,
  700. 0xDE000,
  701. 0,0,0,0,0,0,0,0
  702. };
  703. #define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses)
  704. #ifdef MODULE
  705. static long maddr[NR_CARDS] = { 0, };
  706. static int irq[NR_CARDS] = { 0, };
  707. module_param_array(maddr, long, NULL, 0);
  708. module_param_array(irq, int, NULL, 0);
  709. #endif
  710. #endif /* CONFIG_ISA */
  711. /* This is the per-card data structure containing address, irq, number of
  712. channels, etc. This driver supports a maximum of NR_CARDS cards.
  713. */
  714. static struct cyclades_card cy_card[NR_CARDS];
  715. /* This is the per-channel data structure containing pointers, flags
  716. and variables for the port. This driver supports a maximum of NR_PORTS.
  717. */
  718. static struct cyclades_port cy_port[NR_PORTS];
  719. static int cy_next_channel; /* next minor available */
  720. /*
  721. * tmp_buf is used as a temporary buffer by serial_write. We need to
  722. * lock it in case the copy_from_user blocks while swapping in a page,
  723. * and some other program tries to do a serial write at the same time.
  724. * Since the lock will only come under contention when the system is
  725. * swapping and available memory is low, it makes sense to share one
  726. * buffer across all the serial ports, since it significantly saves
  727. * memory if large numbers of serial ports are open. This buffer is
  728. * allocated when the first cy_open occurs.
  729. */
  730. static unsigned char *tmp_buf;
  731. /*
  732. * This is used to look up the divisor speeds and the timeouts
  733. * We're normally limited to 15 distinct baud rates. The extra
  734. * are accessed via settings in info->flags.
  735. * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  736. * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  737. * HI VHI
  738. * 20
  739. */
  740. static int baud_table[] = {
  741. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
  742. 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000,
  743. 230400, 0};
  744. static char baud_co_25[] = { /* 25 MHz clock option table */
  745. /* value => 00 01 02 03 04 */
  746. /* divide by 8 32 128 512 2048 */
  747. 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
  748. 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  749. static char baud_bpr_25[] = { /* 25 MHz baud rate period table */
  750. 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
  751. 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15};
  752. static char baud_co_60[] = { /* 60 MHz clock option table (CD1400 J) */
  753. /* value => 00 01 02 03 04 */
  754. /* divide by 8 32 128 512 2048 */
  755. 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03,
  756. 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  757. 0x00};
  758. static char baud_bpr_60[] = { /* 60 MHz baud rate period table (CD1400 J) */
  759. 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62,
  760. 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32,
  761. 0x21};
  762. static char baud_cor3[] = { /* receive threshold */
  763. 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  764. 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07,
  765. 0x07};
  766. /*
  767. * The Cyclades driver implements HW flow control as any serial driver.
  768. * The cyclades_port structure member rflow and the vector rflow_thr
  769. * allows us to take advantage of a special feature in the CD1400 to avoid
  770. * data loss even when the system interrupt latency is too high. These flags
  771. * are to be used only with very special applications. Setting these flags
  772. * requires the use of a special cable (DTR and RTS reversed). In the new
  773. * CD1400-based boards (rev. 6.00 or later), there is no need for special
  774. * cables.
  775. */
  776. static char rflow_thr[] = { /* rflow threshold */
  777. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  778. 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  779. 0x0a};
  780. /* The Cyclom-Ye has placed the sequential chips in non-sequential
  781. * address order. This look-up table overcomes that problem.
  782. */
  783. static int cy_chip_offset [] =
  784. { 0x0000,
  785. 0x0400,
  786. 0x0800,
  787. 0x0C00,
  788. 0x0200,
  789. 0x0600,
  790. 0x0A00,
  791. 0x0E00
  792. };
  793. /* PCI related definitions */
  794. static unsigned short cy_pci_nboard;
  795. static unsigned short cy_isa_nboard;
  796. static unsigned short cy_nboard;
  797. #ifdef CONFIG_PCI
  798. static unsigned short cy_pci_dev_id[] = {
  799. PCI_DEVICE_ID_CYCLOM_Y_Lo, /* PCI < 1Mb */
  800. PCI_DEVICE_ID_CYCLOM_Y_Hi, /* PCI > 1Mb */
  801. PCI_DEVICE_ID_CYCLOM_4Y_Lo, /* 4Y PCI < 1Mb */
  802. PCI_DEVICE_ID_CYCLOM_4Y_Hi, /* 4Y PCI > 1Mb */
  803. PCI_DEVICE_ID_CYCLOM_8Y_Lo, /* 8Y PCI < 1Mb */
  804. PCI_DEVICE_ID_CYCLOM_8Y_Hi, /* 8Y PCI > 1Mb */
  805. PCI_DEVICE_ID_CYCLOM_Z_Lo, /* Z PCI < 1Mb */
  806. PCI_DEVICE_ID_CYCLOM_Z_Hi, /* Z PCI > 1Mb */
  807. 0 /* end of table */
  808. };
  809. #endif
  810. static void cy_start(struct tty_struct *);
  811. static void set_line_char(struct cyclades_port *);
  812. static int cyz_issue_cmd(struct cyclades_card *, uclong, ucchar, uclong);
  813. #ifdef CONFIG_ISA
  814. static unsigned detect_isa_irq(void __iomem *);
  815. #endif /* CONFIG_ISA */
  816. static int cyclades_get_proc_info(char *, char **, off_t , int , int *, void *);
  817. #ifndef CONFIG_CYZ_INTR
  818. static void cyz_poll(unsigned long);
  819. /* The Cyclades-Z polling cycle is defined by this variable */
  820. static long cyz_polling_cycle = CZ_DEF_POLL;
  821. static int cyz_timeron = 0;
  822. static DEFINE_TIMER(cyz_timerlist, cyz_poll, 0, 0);
  823. #else /* CONFIG_CYZ_INTR */
  824. static void cyz_rx_restart(unsigned long);
  825. static struct timer_list cyz_rx_full_timer[NR_PORTS];
  826. #endif /* CONFIG_CYZ_INTR */
  827. static inline int
  828. serial_paranoia_check(struct cyclades_port *info,
  829. char *name, const char *routine)
  830. {
  831. #ifdef SERIAL_PARANOIA_CHECK
  832. static const char *badmagic =
  833. "cyc Warning: bad magic number for serial struct (%s) in %s\n";
  834. static const char *badinfo =
  835. "cyc Warning: null cyclades_port for (%s) in %s\n";
  836. static const char *badrange =
  837. "cyc Warning: cyclades_port out of range for (%s) in %s\n";
  838. if (!info) {
  839. printk(badinfo, name, routine);
  840. return 1;
  841. }
  842. if( (long)info < (long)(&cy_port[0])
  843. || (long)(&cy_port[NR_PORTS]) < (long)info ){
  844. printk(badrange, name, routine);
  845. return 1;
  846. }
  847. if (info->magic != CYCLADES_MAGIC) {
  848. printk(badmagic, name, routine);
  849. return 1;
  850. }
  851. #endif
  852. return 0;
  853. } /* serial_paranoia_check */
  854. /*
  855. * This routine is used by the interrupt handler to schedule
  856. * processing in the software interrupt portion of the driver
  857. * (also known as the "bottom half"). This can be called any
  858. * number of times for any channel without harm.
  859. */
  860. static inline void
  861. cy_sched_event(struct cyclades_port *info, int event)
  862. {
  863. info->event |= 1 << event; /* remember what kind of event and who */
  864. schedule_work(&info->tqueue);
  865. } /* cy_sched_event */
  866. /*
  867. * This routine is used to handle the "bottom half" processing for the
  868. * serial driver, known also the "software interrupt" processing.
  869. * This processing is done at the kernel interrupt level, after the
  870. * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
  871. * is where time-consuming activities which can not be done in the
  872. * interrupt driver proper are done; the interrupt driver schedules
  873. * them using cy_sched_event(), and they get done here.
  874. *
  875. * This is done through one level of indirection--the task queue.
  876. * When a hardware interrupt service routine wants service by the
  877. * driver's bottom half, it enqueues the appropriate tq_struct (one
  878. * per port) to the keventd work queue and sets a request flag
  879. * that the work queue be processed.
  880. *
  881. * Although this may seem unwieldy, it gives the system a way to
  882. * pass an argument (in this case the pointer to the cyclades_port
  883. * structure) to the bottom half of the driver. Previous kernels
  884. * had to poll every port to see if that port needed servicing.
  885. */
  886. static void
  887. do_softint(void *private_)
  888. {
  889. struct cyclades_port *info = (struct cyclades_port *) private_;
  890. struct tty_struct *tty;
  891. tty = info->tty;
  892. if (!tty)
  893. return;
  894. if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
  895. tty_hangup(info->tty);
  896. wake_up_interruptible(&info->open_wait);
  897. info->flags &= ~ASYNC_NORMAL_ACTIVE;
  898. }
  899. if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) {
  900. wake_up_interruptible(&info->open_wait);
  901. }
  902. #ifdef CONFIG_CYZ_INTR
  903. if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL, &info->event)) {
  904. if (cyz_rx_full_timer[info->line].function == NULL) {
  905. cyz_rx_full_timer[info->line].expires = jiffies + 1;
  906. cyz_rx_full_timer[info->line].function = cyz_rx_restart;
  907. cyz_rx_full_timer[info->line].data = (unsigned long)info;
  908. add_timer(&cyz_rx_full_timer[info->line]);
  909. }
  910. }
  911. #endif
  912. if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP, &info->event)) {
  913. wake_up_interruptible(&info->delta_msr_wait);
  914. }
  915. if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
  916. tty_wakeup(tty);
  917. wake_up_interruptible(&tty->write_wait);
  918. }
  919. #ifdef Z_WAKE
  920. if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP, &info->event)) {
  921. wake_up_interruptible(&info->shutdown_wait);
  922. }
  923. #endif
  924. } /* do_softint */
  925. /***********************************************************/
  926. /********* Start of block of Cyclom-Y specific code ********/
  927. /* This routine waits up to 1000 micro-seconds for the previous
  928. command to the Cirrus chip to complete and then issues the
  929. new command. An error is returned if the previous command
  930. didn't finish within the time limit.
  931. This function is only called from inside spinlock-protected code.
  932. */
  933. static int
  934. cyy_issue_cmd(void __iomem *base_addr, u_char cmd, int index)
  935. {
  936. volatile int i;
  937. /* Check to see that the previous command has completed */
  938. for(i = 0 ; i < 100 ; i++){
  939. if (cy_readb(base_addr+(CyCCR<<index)) == 0){
  940. break;
  941. }
  942. udelay(10L);
  943. }
  944. /* if the CCR never cleared, the previous command
  945. didn't finish within the "reasonable time" */
  946. if (i == 100) return (-1);
  947. /* Issue the new command */
  948. cy_writeb(base_addr+(CyCCR<<index), cmd);
  949. return(0);
  950. } /* cyy_issue_cmd */
  951. #ifdef CONFIG_ISA
  952. /* ISA interrupt detection code */
  953. static unsigned
  954. detect_isa_irq(void __iomem *address)
  955. {
  956. int irq;
  957. unsigned long irqs, flags;
  958. int save_xir, save_car;
  959. int index = 0; /* IRQ probing is only for ISA */
  960. /* forget possible initially masked and pending IRQ */
  961. irq = probe_irq_off(probe_irq_on());
  962. /* Clear interrupts on the board first */
  963. cy_writeb(address + (Cy_ClrIntr<<index), 0);
  964. /* Cy_ClrIntr is 0x1800 */
  965. irqs = probe_irq_on();
  966. /* Wait ... */
  967. udelay(5000L);
  968. /* Enable the Tx interrupts on the CD1400 */
  969. local_irq_save(flags);
  970. cy_writeb(address + (CyCAR<<index), 0);
  971. cyy_issue_cmd(address, CyCHAN_CTL|CyENB_XMTR, index);
  972. cy_writeb(address + (CyCAR<<index), 0);
  973. cy_writeb(address + (CySRER<<index),
  974. cy_readb(address + (CySRER<<index)) | CyTxRdy);
  975. local_irq_restore(flags);
  976. /* Wait ... */
  977. udelay(5000L);
  978. /* Check which interrupt is in use */
  979. irq = probe_irq_off(irqs);
  980. /* Clean up */
  981. save_xir = (u_char) cy_readb(address + (CyTIR<<index));
  982. save_car = cy_readb(address + (CyCAR<<index));
  983. cy_writeb(address + (CyCAR<<index), (save_xir & 0x3));
  984. cy_writeb(address + (CySRER<<index),
  985. cy_readb(address + (CySRER<<index)) & ~CyTxRdy);
  986. cy_writeb(address + (CyTIR<<index), (save_xir & 0x3f));
  987. cy_writeb(address + (CyCAR<<index), (save_car));
  988. cy_writeb(address + (Cy_ClrIntr<<index), 0);
  989. /* Cy_ClrIntr is 0x1800 */
  990. return (irq > 0)? irq : 0;
  991. }
  992. #endif /* CONFIG_ISA */
  993. /* The real interrupt service routine is called
  994. whenever the card wants its hand held--chars
  995. received, out buffer empty, modem change, etc.
  996. */
  997. static irqreturn_t
  998. cyy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  999. {
  1000. struct tty_struct *tty;
  1001. int status;
  1002. struct cyclades_card *cinfo;
  1003. struct cyclades_port *info;
  1004. void __iomem *base_addr, *card_base_addr;
  1005. int chip;
  1006. int save_xir, channel, save_car;
  1007. char data;
  1008. volatile int char_count;
  1009. int outch;
  1010. int i,j,index;
  1011. int too_many;
  1012. int had_work;
  1013. int mdm_change;
  1014. int mdm_status;
  1015. int len;
  1016. if((cinfo = (struct cyclades_card *)dev_id) == 0){
  1017. #ifdef CY_DEBUG_INTERRUPTS
  1018. printk("cyy_interrupt: spurious interrupt %d\n\r", irq);
  1019. #endif
  1020. return IRQ_NONE; /* spurious interrupt */
  1021. }
  1022. card_base_addr = cinfo->base_addr;
  1023. index = cinfo->bus_index;
  1024. /* This loop checks all chips in the card. Make a note whenever
  1025. _any_ chip had some work to do, as this is considered an
  1026. indication that there will be more to do. Only when no chip
  1027. has any work does this outermost loop exit.
  1028. */
  1029. do{
  1030. had_work = 0;
  1031. for ( chip = 0 ; chip < cinfo->num_chips ; chip ++) {
  1032. base_addr = cinfo->base_addr + (cy_chip_offset[chip]<<index);
  1033. too_many = 0;
  1034. while ( (status = cy_readb(base_addr+(CySVRR<<index))) != 0x00) {
  1035. had_work++;
  1036. /* The purpose of the following test is to ensure that
  1037. no chip can monopolize the driver. This forces the
  1038. chips to be checked in a round-robin fashion (after
  1039. draining each of a bunch (1000) of characters).
  1040. */
  1041. if(1000<too_many++){
  1042. break;
  1043. }
  1044. if (status & CySRReceive) { /* reception interrupt */
  1045. #ifdef CY_DEBUG_INTERRUPTS
  1046. printk("cyy_interrupt: rcvd intr, chip %d\n\r", chip);
  1047. #endif
  1048. /* determine the channel & change to that context */
  1049. spin_lock(&cinfo->card_lock);
  1050. save_xir = (u_char) cy_readb(base_addr+(CyRIR<<index));
  1051. channel = (u_short ) (save_xir & CyIRChannel);
  1052. i = channel + chip * 4 + cinfo->first_line;
  1053. info = &cy_port[i];
  1054. info->last_active = jiffies;
  1055. save_car = cy_readb(base_addr+(CyCAR<<index));
  1056. cy_writeb(base_addr+(CyCAR<<index), save_xir);
  1057. /* if there is nowhere to put the data, discard it */
  1058. if(info->tty == 0){
  1059. j = (cy_readb(base_addr+(CyRIVR<<index)) & CyIVRMask);
  1060. if ( j == CyIVRRxEx ) { /* exception */
  1061. data = cy_readb(base_addr+(CyRDSR<<index));
  1062. } else { /* normal character reception */
  1063. char_count = cy_readb(base_addr+(CyRDCR<<index));
  1064. while(char_count--){
  1065. data = cy_readb(base_addr+(CyRDSR<<index));
  1066. }
  1067. }
  1068. }else{ /* there is an open port for this data */
  1069. tty = info->tty;
  1070. j = (cy_readb(base_addr+(CyRIVR<<index)) & CyIVRMask);
  1071. if ( j == CyIVRRxEx ) { /* exception */
  1072. data = cy_readb(base_addr+(CyRDSR<<index));
  1073. /* For statistics only */
  1074. if (data & CyBREAK)
  1075. info->icount.brk++;
  1076. else if(data & CyFRAME)
  1077. info->icount.frame++;
  1078. else if(data & CyPARITY)
  1079. info->icount.parity++;
  1080. else if(data & CyOVERRUN)
  1081. info->icount.overrun++;
  1082. if(data & info->ignore_status_mask){
  1083. info->icount.rx++;
  1084. continue;
  1085. }
  1086. if (tty_buffer_request_room(tty, 1)) {
  1087. if (data & info->read_status_mask){
  1088. if(data & CyBREAK){
  1089. tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_BREAK);
  1090. info->icount.rx++;
  1091. if (info->flags & ASYNC_SAK){
  1092. do_SAK(tty);
  1093. }
  1094. }else if(data & CyFRAME){
  1095. tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_FRAME);
  1096. info->icount.rx++;
  1097. info->idle_stats.frame_errs++;
  1098. }else if(data & CyPARITY){
  1099. /* Pieces of seven... */
  1100. tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_PARITY);
  1101. info->icount.rx++;
  1102. info->idle_stats.parity_errs++;
  1103. }else if(data & CyOVERRUN){
  1104. tty_insert_flip_char(tty, 0, TTY_OVERRUN);
  1105. info->icount.rx++;
  1106. /* If the flip buffer itself is
  1107. overflowing, we still lose
  1108. the next incoming character.
  1109. */
  1110. tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_FRAME);
  1111. info->icount.rx++;
  1112. info->idle_stats.overruns++;
  1113. /* These two conditions may imply */
  1114. /* a normal read should be done. */
  1115. /* }else if(data & CyTIMEOUT){ */
  1116. /* }else if(data & CySPECHAR){ */
  1117. }else {
  1118. tty_insert_flip_char(tty, 0, TTY_NORMAL);
  1119. info->icount.rx++;
  1120. }
  1121. }else{
  1122. tty_insert_flip_char(tty, 0, TTY_NORMAL);
  1123. info->icount.rx++;
  1124. }
  1125. }else{
  1126. /* there was a software buffer
  1127. overrun and nothing could be
  1128. done about it!!! */
  1129. info->icount.buf_overrun++;
  1130. info->idle_stats.overruns++;
  1131. }
  1132. } else { /* normal character reception */
  1133. /* load # chars available from the chip */
  1134. char_count = cy_readb(base_addr+(CyRDCR<<index));
  1135. #ifdef CY_ENABLE_MONITORING
  1136. ++info->mon.int_count;
  1137. info->mon.char_count += char_count;
  1138. if (char_count > info->mon.char_max)
  1139. info->mon.char_max = char_count;
  1140. info->mon.char_last = char_count;
  1141. #endif
  1142. len = tty_buffer_request_room(tty, char_count);
  1143. while(len--){
  1144. data = cy_readb(base_addr+(CyRDSR<<index));
  1145. tty_insert_flip_char(tty, data, TTY_NORMAL);
  1146. info->idle_stats.recv_bytes++;
  1147. info->icount.rx++;
  1148. #ifdef CY_16Y_HACK
  1149. udelay(10L);
  1150. #endif
  1151. }
  1152. info->idle_stats.recv_idle = jiffies;
  1153. }
  1154. tty_schedule_flip(tty);
  1155. }
  1156. /* end of service */
  1157. cy_writeb(base_addr+(CyRIR<<index), (save_xir & 0x3f));
  1158. cy_writeb(base_addr+(CyCAR<<index), (save_car));
  1159. spin_unlock(&cinfo->card_lock);
  1160. }
  1161. if (status & CySRTransmit) { /* transmission interrupt */
  1162. /* Since we only get here when the transmit buffer
  1163. is empty, we know we can always stuff a dozen
  1164. characters. */
  1165. #ifdef CY_DEBUG_INTERRUPTS
  1166. printk("cyy_interrupt: xmit intr, chip %d\n\r", chip);
  1167. #endif
  1168. /* determine the channel & change to that context */
  1169. spin_lock(&cinfo->card_lock);
  1170. save_xir = (u_char) cy_readb(base_addr+(CyTIR<<index));
  1171. channel = (u_short ) (save_xir & CyIRChannel);
  1172. i = channel + chip * 4 + cinfo->first_line;
  1173. save_car = cy_readb(base_addr+(CyCAR<<index));
  1174. cy_writeb(base_addr+(CyCAR<<index), save_xir);
  1175. /* validate the port# (as configured and open) */
  1176. if( (i < 0) || (NR_PORTS <= i) ){
  1177. cy_writeb(base_addr+(CySRER<<index),
  1178. cy_readb(base_addr+(CySRER<<index)) & ~CyTxRdy);
  1179. goto txend;
  1180. }
  1181. info = &cy_port[i];
  1182. info->last_active = jiffies;
  1183. if(info->tty == 0){
  1184. cy_writeb(base_addr+(CySRER<<index),
  1185. cy_readb(base_addr+(CySRER<<index)) & ~CyTxRdy);
  1186. goto txdone;
  1187. }
  1188. /* load the on-chip space for outbound data */
  1189. char_count = info->xmit_fifo_size;
  1190. if(info->x_char) { /* send special char */
  1191. outch = info->x_char;
  1192. cy_writeb(base_addr+(CyTDR<<index), outch);
  1193. char_count--;
  1194. info->icount.tx++;
  1195. info->x_char = 0;
  1196. }
  1197. if (info->breakon || info->breakoff) {
  1198. if (info->breakon) {
  1199. cy_writeb(base_addr + (CyTDR<<index), 0);
  1200. cy_writeb(base_addr + (CyTDR<<index), 0x81);
  1201. info->breakon = 0;
  1202. char_count -= 2;
  1203. }
  1204. if (info->breakoff) {
  1205. cy_writeb(base_addr + (CyTDR<<index), 0);
  1206. cy_writeb(base_addr + (CyTDR<<index), 0x83);
  1207. info->breakoff = 0;
  1208. char_count -= 2;
  1209. }
  1210. }
  1211. while (char_count-- > 0){
  1212. if (!info->xmit_cnt){
  1213. if (cy_readb(base_addr+(CySRER<<index))&CyTxMpty) {
  1214. cy_writeb(base_addr+(CySRER<<index),
  1215. cy_readb(base_addr+(CySRER<<index)) &
  1216. ~CyTxMpty);
  1217. } else {
  1218. cy_writeb(base_addr+(CySRER<<index),
  1219. ((cy_readb(base_addr+(CySRER<<index))
  1220. & ~CyTxRdy)
  1221. | CyTxMpty));
  1222. }
  1223. goto txdone;
  1224. }
  1225. if (info->xmit_buf == 0){
  1226. cy_writeb(base_addr+(CySRER<<index),
  1227. cy_readb(base_addr+(CySRER<<index)) &
  1228. ~CyTxRdy);
  1229. goto txdone;
  1230. }
  1231. if (info->tty->stopped || info->tty->hw_stopped){
  1232. cy_writeb(base_addr+(CySRER<<index),
  1233. cy_readb(base_addr+(CySRER<<index)) &
  1234. ~CyTxRdy);
  1235. goto txdone;
  1236. }
  1237. /* Because the Embedded Transmit Commands have
  1238. been enabled, we must check to see if the
  1239. escape character, NULL, is being sent. If it
  1240. is, we must ensure that there is room for it
  1241. to be doubled in the output stream. Therefore
  1242. we no longer advance the pointer when the
  1243. character is fetched, but rather wait until
  1244. after the check for a NULL output character.
  1245. This is necessary because there may not be
  1246. room for the two chars needed to send a NULL.)
  1247. */
  1248. outch = info->xmit_buf[info->xmit_tail];
  1249. if( outch ){
  1250. info->xmit_cnt--;
  1251. info->xmit_tail = (info->xmit_tail + 1)
  1252. & (SERIAL_XMIT_SIZE - 1);
  1253. cy_writeb(base_addr+(CyTDR<<index), outch);
  1254. info->icount.tx++;
  1255. }else{
  1256. if(char_count > 1){
  1257. info->xmit_cnt--;
  1258. info->xmit_tail = (info->xmit_tail + 1)
  1259. & (SERIAL_XMIT_SIZE - 1);
  1260. cy_writeb(base_addr+(CyTDR<<index),
  1261. outch);
  1262. cy_writeb(base_addr+(CyTDR<<index), 0);
  1263. info->icount.tx++;
  1264. char_count--;
  1265. }else{
  1266. }
  1267. }
  1268. }
  1269. txdone:
  1270. if (info->xmit_cnt < WAKEUP_CHARS) {
  1271. cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
  1272. }
  1273. txend:
  1274. /* end of service */
  1275. cy_writeb(base_addr+(CyTIR<<index),
  1276. (save_xir & 0x3f));
  1277. cy_writeb(base_addr+(CyCAR<<index), (save_car));
  1278. spin_unlock(&cinfo->card_lock);
  1279. }
  1280. if (status & CySRModem) { /* modem interrupt */
  1281. /* determine the channel & change to that context */
  1282. spin_lock(&cinfo->card_lock);
  1283. save_xir = (u_char) cy_readb(base_addr+(CyMIR<<index));
  1284. channel = (u_short ) (save_xir & CyIRChannel);
  1285. info = &cy_port[channel + chip * 4
  1286. + cinfo->first_line];
  1287. info->last_active = jiffies;
  1288. save_car = cy_readb(base_addr+(CyCAR<<index));
  1289. cy_writeb(base_addr+(CyCAR<<index), save_xir);
  1290. mdm_change = cy_readb(base_addr+(CyMISR<<index));
  1291. mdm_status = cy_readb(base_addr+(CyMSVR1<<index));
  1292. if(info->tty == 0){/* no place for data, ignore it*/
  1293. ;
  1294. }else{
  1295. if (mdm_change & CyANY_DELTA) {
  1296. /* For statistics only */
  1297. if (mdm_change & CyDCD) info->icount.dcd++;
  1298. if (mdm_change & CyCTS) info->icount.cts++;
  1299. if (mdm_change & CyDSR) info->icount.dsr++;
  1300. if (mdm_change & CyRI) info->icount.rng++;
  1301. cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
  1302. }
  1303. if((mdm_change & CyDCD)
  1304. && (info->flags & ASYNC_CHECK_CD)){
  1305. if(mdm_status & CyDCD){
  1306. cy_sched_event(info,
  1307. Cy_EVENT_OPEN_WAKEUP);
  1308. }else{
  1309. cy_sched_event(info,
  1310. Cy_EVENT_HANGUP);
  1311. }
  1312. }
  1313. if((mdm_change & CyCTS)
  1314. && (info->flags & ASYNC_CTS_FLOW)){
  1315. if(info->tty->hw_stopped){
  1316. if(mdm_status & CyCTS){
  1317. /* cy_start isn't used
  1318. because... !!! */
  1319. info->tty->hw_stopped = 0;
  1320. cy_writeb(base_addr+(CySRER<<index),
  1321. cy_readb(base_addr+(CySRER<<index)) |
  1322. CyTxRdy);
  1323. cy_sched_event(info,
  1324. Cy_EVENT_WRITE_WAKEUP);
  1325. }
  1326. }else{
  1327. if(!(mdm_status & CyCTS)){
  1328. /* cy_stop isn't used
  1329. because ... !!! */
  1330. info->tty->hw_stopped = 1;
  1331. cy_writeb(base_addr+(CySRER<<index),
  1332. cy_readb(base_addr+(CySRER<<index)) &
  1333. ~CyTxRdy);
  1334. }
  1335. }
  1336. }
  1337. if(mdm_change & CyDSR){
  1338. }
  1339. if(mdm_change & CyRI){
  1340. }
  1341. }
  1342. /* end of service */
  1343. cy_writeb(base_addr+(CyMIR<<index),
  1344. (save_xir & 0x3f));
  1345. cy_writeb(base_addr+(CyCAR<<index), save_car);
  1346. spin_unlock(&cinfo->card_lock);
  1347. }
  1348. } /* end while status != 0 */
  1349. } /* end loop for chips... */
  1350. } while(had_work);
  1351. /* clear interrupts */
  1352. spin_lock(&cinfo->card_lock);
  1353. cy_writeb(card_base_addr + (Cy_ClrIntr<<index), 0);
  1354. /* Cy_ClrIntr is 0x1800 */
  1355. spin_unlock(&cinfo->card_lock);
  1356. return IRQ_HANDLED;
  1357. } /* cyy_interrupt */
  1358. /***********************************************************/
  1359. /********* End of block of Cyclom-Y specific code **********/
  1360. /******** Start of block of Cyclades-Z specific code *********/
  1361. /***********************************************************/
  1362. static int
  1363. cyz_fetch_msg( struct cyclades_card *cinfo,
  1364. uclong *channel, ucchar *cmd, uclong *param)
  1365. {
  1366. struct FIRM_ID __iomem *firm_id;
  1367. struct ZFW_CTRL __iomem *zfw_ctrl;
  1368. struct BOARD_CTRL __iomem *board_ctrl;
  1369. unsigned long loc_doorbell;
  1370. firm_id = cinfo->base_addr + ID_ADDRESS;
  1371. if (!ISZLOADED(*cinfo)){
  1372. return (-1);
  1373. }
  1374. zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
  1375. board_ctrl = &zfw_ctrl->board_ctrl;
  1376. loc_doorbell = cy_readl(&((struct RUNTIME_9060 __iomem *)
  1377. (cinfo->ctl_addr))->loc_doorbell);
  1378. if (loc_doorbell){
  1379. *cmd = (char)(0xff & loc_doorbell);
  1380. *channel = cy_readl(&board_ctrl->fwcmd_channel);
  1381. *param = (uclong)cy_readl(&board_ctrl->fwcmd_param);
  1382. cy_writel(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->loc_doorbell,
  1383. 0xffffffff);
  1384. return 1;
  1385. }
  1386. return 0;
  1387. } /* cyz_fetch_msg */
  1388. static int
  1389. cyz_issue_cmd( struct cyclades_card *cinfo,
  1390. uclong channel, ucchar cmd, uclong param)
  1391. {
  1392. struct FIRM_ID __iomem *firm_id;
  1393. struct ZFW_CTRL __iomem *zfw_ctrl;
  1394. struct BOARD_CTRL __iomem *board_ctrl;
  1395. unsigned long __iomem *pci_doorbell;
  1396. int index;
  1397. firm_id = cinfo->base_addr + ID_ADDRESS;
  1398. if (!ISZLOADED(*cinfo)){
  1399. return (-1);
  1400. }
  1401. zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
  1402. board_ctrl = &zfw_ctrl->board_ctrl;
  1403. index = 0;
  1404. pci_doorbell = &((struct RUNTIME_9060 __iomem *) (cinfo->ctl_addr))->pci_doorbell;
  1405. while( (cy_readl(pci_doorbell) & 0xff) != 0){
  1406. if (index++ == 1000){
  1407. return((int)(cy_readl(pci_doorbell) & 0xff));
  1408. }
  1409. udelay(50L);
  1410. }
  1411. cy_writel(&board_ctrl->hcmd_channel, channel);
  1412. cy_writel(&board_ctrl->hcmd_param , param);
  1413. cy_writel(pci_doorbell, (long)cmd);
  1414. return(0);
  1415. } /* cyz_issue_cmd */
  1416. static void
  1417. cyz_handle_rx(struct cyclades_port *info,
  1418. volatile struct CH_CTRL __iomem *ch_ctrl,
  1419. volatile struct BUF_CTRL __iomem *buf_ctrl)
  1420. {
  1421. struct cyclades_card *cinfo = &cy_card[info->card];
  1422. struct tty_struct *tty = info->tty;
  1423. volatile int char_count;
  1424. int len;
  1425. #ifdef BLOCKMOVE
  1426. int small_count;
  1427. #else
  1428. char data;
  1429. #endif
  1430. volatile uclong rx_put, rx_get, new_rx_get, rx_bufsize, rx_bufaddr;
  1431. rx_get = new_rx_get = cy_readl(&buf_ctrl->rx_get);
  1432. rx_put = cy_readl(&buf_ctrl->rx_put);
  1433. rx_bufsize = cy_readl(&buf_ctrl->rx_bufsize);
  1434. rx_bufaddr = cy_readl(&buf_ctrl->rx_bufaddr);
  1435. if (rx_put >= rx_get)
  1436. char_count = rx_put - rx_get;
  1437. else
  1438. char_count = rx_put - rx_get + rx_bufsize;
  1439. if ( char_count ) {
  1440. info->last_active = jiffies;
  1441. info->jiffies[1] = jiffies;
  1442. #ifdef CY_ENABLE_MONITORING
  1443. info->mon.int_count++;
  1444. info->mon.char_count += char_count;
  1445. if (char_count > info->mon.char_max)
  1446. info->mon.char_max = char_count;
  1447. info->mon.char_last = char_count;
  1448. #endif
  1449. if(tty == 0){
  1450. /* flush received characters */
  1451. new_rx_get = (new_rx_get + char_count) & (rx_bufsize - 1);
  1452. info->rflush_count++;
  1453. }else{
  1454. #ifdef BLOCKMOVE
  1455. /* we'd like to use memcpy(t, f, n) and memset(s, c, count)
  1456. for performance, but because of buffer boundaries, there
  1457. may be several steps to the operation */
  1458. while(0 < (small_count =
  1459. min_t(unsigned int, (rx_bufsize - new_rx_get),
  1460. min_t(unsigned int, (TTY_FLIPBUF_SIZE - tty->flip.count), char_count))
  1461. )) {
  1462. memcpy_fromio(tty->flip.char_buf_ptr,
  1463. (char *)(cinfo->base_addr
  1464. + rx_bufaddr + new_rx_get),
  1465. small_count);
  1466. tty->flip.char_buf_ptr += small_count;
  1467. memset(tty->flip.flag_buf_ptr, TTY_NORMAL, small_count);
  1468. tty->flip.flag_buf_ptr += small_count;
  1469. new_rx_get = (new_rx_get + small_count) & (rx_bufsize - 1);
  1470. char_count -= small_count;
  1471. info->icount.rx += small_count;
  1472. info->idle_stats.recv_bytes += small_count;
  1473. tty->flip.count += small_count;
  1474. }
  1475. #else
  1476. len = tty_buffer_request_room(tty, char_count);
  1477. while(len--){
  1478. data = cy_readb(cinfo->base_addr + rx_bufaddr + new_rx_get);
  1479. new_rx_get = (new_rx_get + 1) & (rx_bufsize - 1);
  1480. tty_insert_flip_char(tty, data, TTY_NORMAL);
  1481. info->idle_stats.recv_bytes++;
  1482. info->icount.rx++;
  1483. }
  1484. #endif
  1485. #ifdef CONFIG_CYZ_INTR
  1486. /* Recalculate the number of chars in the RX buffer and issue
  1487. a cmd in case it's higher than the RX high water mark */
  1488. rx_put = cy_readl(&buf_ctrl->rx_put);
  1489. if (rx_put >= rx_get)
  1490. char_count = rx_put - rx_get;
  1491. else
  1492. char_count = rx_put - rx_get + rx_bufsize;
  1493. if(char_count >= cy_readl(&buf_ctrl->rx_threshold)) {
  1494. cy_sched_event(info, Cy_EVENT_Z_RX_FULL);
  1495. }
  1496. #endif
  1497. info->idle_stats.recv_idle = jiffies;
  1498. tty_schedule_flip(tty);
  1499. }
  1500. /* Update rx_get */
  1501. cy_writel(&buf_ctrl->rx_get, new_rx_get);
  1502. }
  1503. }
  1504. static void
  1505. cyz_handle_tx(struct cyclades_port *info,
  1506. volatile struct CH_CTRL __iomem *ch_ctrl,
  1507. volatile struct BUF_CTRL __iomem *buf_ctrl)
  1508. {
  1509. struct cyclades_card *cinfo = &cy_card[info->card];
  1510. struct tty_struct *tty = info->tty;
  1511. char data;
  1512. volatile int char_count;
  1513. #ifdef BLOCKMOVE
  1514. int small_count;
  1515. #endif
  1516. volatile uclong tx_put, tx_get, tx_bufsize, tx_bufaddr;
  1517. if (info->xmit_cnt <= 0) /* Nothing to transmit */
  1518. return;
  1519. tx_get = cy_readl(&buf_ctrl->tx_get);
  1520. tx_put = cy_readl(&buf_ctrl->tx_put);
  1521. tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize);
  1522. tx_bufaddr = cy_readl(&buf_ctrl->tx_bufaddr);
  1523. if (tx_put >= tx_get)
  1524. char_count = tx_get - tx_put - 1 + tx_bufsize;
  1525. else
  1526. char_count = tx_get - tx_put - 1;
  1527. if ( char_count ) {
  1528. if( tty == 0 ){
  1529. goto ztxdone;
  1530. }
  1531. if(info->x_char) { /* send special char */
  1532. data = info->x_char;
  1533. cy_writeb((cinfo->base_addr + tx_bufaddr + tx_put), data);
  1534. tx_put = (tx_put + 1) & (tx_bufsize - 1);
  1535. info->x_char = 0;
  1536. char_count--;
  1537. info->icount.tx++;
  1538. info->last_active = jiffies;
  1539. info->jiffies[2] = jiffies;
  1540. }
  1541. #ifdef BLOCKMOVE
  1542. while(0 < (small_count =
  1543. min_t(unsigned int, (tx_bufsize - tx_put),
  1544. min_t(unsigned int, (SERIAL_XMIT_SIZE - info->xmit_tail),
  1545. min_t(unsigned int, info->xmit_cnt, char_count))))) {
  1546. memcpy_toio((char *)(cinfo->base_addr + tx_bufaddr + tx_put),
  1547. &info->xmit_buf[info->xmit_tail],
  1548. small_count);
  1549. tx_put = (tx_put + small_count) & (tx_bufsize - 1);
  1550. char_count -= small_count;
  1551. info->icount.tx += small_count;
  1552. info->xmit_cnt -= small_count;
  1553. info->xmit_tail =
  1554. (info->xmit_tail + small_count) & (SERIAL_XMIT_SIZE - 1);
  1555. info->last_active = jiffies;
  1556. info->jiffies[2] = jiffies;
  1557. }
  1558. #else
  1559. while (info->xmit_cnt && char_count){
  1560. data = info->xmit_buf[info->xmit_tail];
  1561. info->xmit_cnt--;
  1562. info->xmit_tail = (info->xmit_tail + 1) & (SERIAL_XMIT_SIZE - 1);
  1563. cy_writeb(cinfo->base_addr + tx_bufaddr + tx_put, data);
  1564. tx_put = (tx_put + 1) & (tx_bufsize - 1);
  1565. char_count--;
  1566. info->icount.tx++;
  1567. info->last_active = jiffies;
  1568. info->jiffies[2] = jiffies;
  1569. }
  1570. #endif
  1571. ztxdone:
  1572. if (info->xmit_cnt < WAKEUP_CHARS) {
  1573. cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
  1574. }
  1575. /* Update tx_put */
  1576. cy_writel(&buf_ctrl->tx_put, tx_put);
  1577. }
  1578. }
  1579. static void
  1580. cyz_handle_cmd(struct cyclades_card *cinfo)
  1581. {
  1582. struct tty_struct *tty;
  1583. struct cyclades_port *info;
  1584. static volatile struct FIRM_ID __iomem *firm_id;
  1585. static volatile struct ZFW_CTRL __iomem *zfw_ctrl;
  1586. static volatile struct BOARD_CTRL __iomem *board_ctrl;
  1587. static volatile struct CH_CTRL __iomem *ch_ctrl;
  1588. static volatile struct BUF_CTRL __iomem *buf_ctrl;
  1589. uclong channel;
  1590. ucchar cmd;
  1591. uclong param;
  1592. uclong hw_ver, fw_ver;
  1593. int special_count;
  1594. int delta_count;
  1595. firm_id = cinfo->base_addr + ID_ADDRESS;
  1596. zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
  1597. board_ctrl = &zfw_ctrl->board_ctrl;
  1598. fw_ver = cy_readl(&board_ctrl->fw_version);
  1599. hw_ver = cy_readl(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->mail_box_0);
  1600. while(cyz_fetch_msg(cinfo, &channel, &cmd, &param) == 1) {
  1601. special_count = 0;
  1602. delta_count = 0;
  1603. info = &cy_port[channel + cinfo->first_line];
  1604. if((tty = info->tty) == 0) {
  1605. continue;
  1606. }
  1607. ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
  1608. buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
  1609. switch(cmd) {
  1610. case C_CM_PR_ERROR:
  1611. tty_insert_flip_char(tty, 0, TTY_PARITY);
  1612. info->icount.rx++;
  1613. special_count++;
  1614. break;
  1615. case C_CM_FR_ERROR:
  1616. tty_insert_flip_char(tty, 0, TTY_FRAME);
  1617. info->icount.rx++;
  1618. special_count++;
  1619. break;
  1620. case C_CM_RXBRK:
  1621. tty_insert_flip_char(tty, 0, TTY_BREAK);
  1622. info->icount.rx++;
  1623. special_count++;
  1624. break;
  1625. case C_CM_MDCD:
  1626. info->icount.dcd++;
  1627. delta_count++;
  1628. if (info->flags & ASYNC_CHECK_CD){
  1629. if ((fw_ver > 241 ?
  1630. ((u_long)param) :
  1631. cy_readl(&ch_ctrl->rs_status)) & C_RS_DCD) {
  1632. cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP);
  1633. }else{
  1634. cy_sched_event(info, Cy_EVENT_HANGUP);
  1635. }
  1636. }
  1637. break;
  1638. case C_CM_MCTS:
  1639. info->icount.cts++;
  1640. delta_count++;
  1641. break;
  1642. case C_CM_MRI:
  1643. info->icount.rng++;
  1644. delta_count++;
  1645. break;
  1646. case C_CM_MDSR:
  1647. info->icount.dsr++;
  1648. delta_count++;
  1649. break;
  1650. #ifdef Z_WAKE
  1651. case C_CM_IOCTLW:
  1652. cy_sched_event(info, Cy_EVENT_SHUTDOWN_WAKEUP);
  1653. break;
  1654. #endif
  1655. #ifdef CONFIG_CYZ_INTR
  1656. case C_CM_RXHIWM:
  1657. case C_CM_RXNNDT:
  1658. case C_CM_INTBACK2:
  1659. /* Reception Interrupt */
  1660. #ifdef CY_DEBUG_INTERRUPTS
  1661. printk("cyz_interrupt: rcvd intr, card %d, port %ld\n\r",
  1662. info->card, channel);
  1663. #endif
  1664. cyz_handle_rx(info, ch_ctrl, buf_ctrl);
  1665. break;
  1666. case C_CM_TXBEMPTY:
  1667. case C_CM_TXLOWWM:
  1668. case C_CM_INTBACK:
  1669. /* Transmission Interrupt */
  1670. #ifdef CY_DEBUG_INTERRUPTS
  1671. printk("cyz_interrupt: xmit intr, card %d, port %ld\n\r",
  1672. info->card, channel);
  1673. #endif
  1674. cyz_handle_tx(info, ch_ctrl, buf_ctrl);
  1675. break;
  1676. #endif /* CONFIG_CYZ_INTR */
  1677. case C_CM_FATAL:
  1678. /* should do something with this !!! */
  1679. break;
  1680. default:
  1681. break;
  1682. }
  1683. if(delta_count)
  1684. cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
  1685. if(special_count)
  1686. tty_schedule_flip(tty);
  1687. }
  1688. }
  1689. #ifdef CONFIG_CYZ_INTR
  1690. static irqreturn_t
  1691. cyz_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1692. {
  1693. struct cyclades_card *cinfo;
  1694. if((cinfo = (struct cyclades_card *)dev_id) == 0){
  1695. #ifdef CY_DEBUG_INTERRUPTS
  1696. printk("cyz_interrupt: spurious interrupt %d\n\r", irq);
  1697. #endif
  1698. return IRQ_NONE; /* spurious interrupt */
  1699. }
  1700. if (!ISZLOADED(*cinfo)) {
  1701. #ifdef CY_DEBUG_INTERRUPTS
  1702. printk("cyz_interrupt: board not yet loaded (IRQ%d).\n\r", irq);
  1703. #endif
  1704. return IRQ_NONE;
  1705. }
  1706. /* Handle the interrupts */
  1707. cyz_handle_cmd(cinfo);
  1708. return IRQ_HANDLED;
  1709. } /* cyz_interrupt */
  1710. static void
  1711. cyz_rx_restart(unsigned long arg)
  1712. {
  1713. struct cyclades_port *info = (struct cyclades_port *)arg;
  1714. int retval;
  1715. int card = info->card;
  1716. uclong channel = (info->line) - (cy_card[card].first_line);
  1717. unsigned long flags;
  1718. CY_LOCK(info, flags);
  1719. retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK2, 0L);
  1720. if (retval != 0){
  1721. printk("cyc:cyz_rx_restart retval on ttyC%d was %x\n",
  1722. info->line, retval);
  1723. }
  1724. cyz_rx_full_timer[info->line].function = NULL;
  1725. CY_UNLOCK(info, flags);
  1726. }
  1727. #else /* CONFIG_CYZ_INTR */
  1728. static void
  1729. cyz_poll(unsigned long arg)
  1730. {
  1731. struct cyclades_card *cinfo;
  1732. struct cyclades_port *info;
  1733. struct tty_struct *tty;
  1734. static volatile struct FIRM_ID *firm_id;
  1735. static volatile struct ZFW_CTRL *zfw_ctrl;
  1736. static volatile struct BOARD_CTRL *board_ctrl;
  1737. static volatile struct CH_CTRL *ch_ctrl;
  1738. static volatile struct BUF_CTRL *buf_ctrl;
  1739. int card, port;
  1740. cyz_timerlist.expires = jiffies + (HZ);
  1741. for (card = 0 ; card < NR_CARDS ; card++){
  1742. cinfo = &cy_card[card];
  1743. if (!IS_CYC_Z(*cinfo)) continue;
  1744. if (!ISZLOADED(*cinfo)) continue;
  1745. firm_id = cinfo->base_addr + ID_ADDRESS;
  1746. zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
  1747. board_ctrl = &(zfw_ctrl->board_ctrl);
  1748. /* Skip first polling cycle to avoid racing conditions with the FW */
  1749. if (!cinfo->intr_enabled) {
  1750. cinfo->nports = (int) cy_readl(&board_ctrl->n_channel);
  1751. cinfo->intr_enabled = 1;
  1752. continue;
  1753. }
  1754. cyz_handle_cmd(cinfo);
  1755. for (port = 0 ; port < cinfo->nports ; port++) {
  1756. info = &cy_port[ port + cinfo->first_line ];
  1757. tty = info->tty;
  1758. ch_ctrl = &(zfw_ctrl->ch_ctrl[port]);
  1759. buf_ctrl = &(zfw_ctrl->buf_ctrl[port]);
  1760. if (!info->throttle)
  1761. cyz_handle_rx(info, ch_ctrl, buf_ctrl);
  1762. cyz_handle_tx(info, ch_ctrl, buf_ctrl);
  1763. }
  1764. /* poll every 'cyz_polling_cycle' period */
  1765. cyz_timerlist.expires = jiffies + cyz_polling_cycle;
  1766. }
  1767. add_timer(&cyz_timerlist);
  1768. return;
  1769. } /* cyz_poll */
  1770. #endif /* CONFIG_CYZ_INTR */
  1771. /********** End of block of Cyclades-Z specific code *********/
  1772. /***********************************************************/
  1773. /* This is called whenever a port becomes active;
  1774. interrupts are enabled and DTR & RTS are turned on.
  1775. */
  1776. static int
  1777. startup(struct cyclades_port * info)
  1778. {
  1779. unsigned long flags;
  1780. int retval = 0;
  1781. void __iomem *base_addr;
  1782. int card,chip,channel,index;
  1783. unsigned long page;
  1784. card = info->card;
  1785. channel = (info->line) - (cy_card[card].first_line);
  1786. page = get_zeroed_page(GFP_KERNEL);
  1787. if (!page)
  1788. return -ENOMEM;
  1789. CY_LOCK(info, flags);
  1790. if (info->flags & ASYNC_INITIALIZED){
  1791. free_page(page);
  1792. goto errout;
  1793. }
  1794. if (!info->type){
  1795. if (info->tty){
  1796. set_bit(TTY_IO_ERROR, &info->tty->flags);
  1797. }
  1798. free_page(page);
  1799. goto errout;
  1800. }
  1801. if (info->xmit_buf)
  1802. free_page(page);
  1803. else
  1804. info->xmit_buf = (unsigned char *) page;
  1805. CY_UNLOCK(info, flags);
  1806. set_line_char(info);
  1807. if (!IS_CYC_Z(cy_card[card])) {
  1808. chip = channel>>2;
  1809. channel &= 0x03;
  1810. index = cy_card[card].bus_index;
  1811. base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
  1812. #ifdef CY_DEBUG_OPEN
  1813. printk("cyc startup card %d, chip %d, channel %d, base_addr %lx\n",
  1814. card, chip, channel, (long)base_addr);/**/
  1815. #endif
  1816. CY_LOCK(info, flags);
  1817. cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
  1818. cy_writeb(base_addr+(CyRTPR<<index), (info->default_timeout
  1819. ? info->default_timeout : 0x02)); /* 10ms rx timeout */
  1820. cyy_issue_cmd(base_addr,CyCHAN_CTL|CyENB_RCVR|CyENB_XMTR,index);
  1821. cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
  1822. cy_writeb(base_addr+(CyMSVR1<<index), CyRTS);
  1823. cy_writeb(base_addr+(CyMSVR2<<index), CyDTR);
  1824. #ifdef CY_DEBUG_DTR
  1825. printk("cyc:startup raising DTR\n");
  1826. printk(" status: 0x%x, 0x%x\n",
  1827. cy_readb(base_addr+(CyMSVR1<<index)),
  1828. cy_readb(base_addr+(CyMSVR2<<index)));
  1829. #endif
  1830. cy_writeb(base_addr+(CySRER<<index),
  1831. cy_readb(base_addr+(CySRER<<index)) | CyRxData);
  1832. info->flags |= ASYNC_INITIALIZED;
  1833. if (info->tty){
  1834. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  1835. }
  1836. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  1837. info->breakon = info->breakoff = 0;
  1838. memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
  1839. info->idle_stats.in_use =
  1840. info->idle_stats.recv_idle =
  1841. info->idle_stats.xmit_idle = jiffies;
  1842. CY_UNLOCK(info, flags);
  1843. } else {
  1844. struct FIRM_ID __iomem *firm_id;
  1845. struct ZFW_CTRL __iomem *zfw_ctrl;
  1846. struct BOARD_CTRL __iomem *board_ctrl;
  1847. struct CH_CTRL __iomem *ch_ctrl;
  1848. int retval;
  1849. base_addr = cy_card[card].base_addr;
  1850. firm_id = base_addr + ID_ADDRESS;
  1851. if (!ISZLOADED(cy_card[card])){
  1852. return -ENODEV;
  1853. }
  1854. zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
  1855. board_ctrl = &zfw_ctrl->board_ctrl;
  1856. ch_ctrl = zfw_ctrl->ch_ctrl;
  1857. #ifdef CY_DEBUG_OPEN
  1858. printk("cyc startup Z card %d, channel %d, base_addr %lx\n",
  1859. card, channel, (long)base_addr);/**/
  1860. #endif
  1861. CY_LOCK(info, flags);
  1862. cy_writel(&ch_ctrl[channel].op_mode, C_CH_ENABLE);
  1863. #ifdef Z_WAKE
  1864. #ifdef CONFIG_CYZ_INTR
  1865. cy_writel(&ch_ctrl[channel].intr_enable,
  1866. C_IN_TXBEMPTY|C_IN_TXLOWWM|C_IN_RXHIWM|C_IN_RXNNDT|
  1867. C_IN_IOCTLW|
  1868. C_IN_MDCD);
  1869. #else
  1870. cy_writel(&ch_ctrl[channel].intr_enable,
  1871. C_IN_IOCTLW|
  1872. C_IN_MDCD);
  1873. #endif /* CONFIG_CYZ_INTR */
  1874. #else
  1875. #ifdef CONFIG_CYZ_INTR
  1876. cy_writel(&ch_ctrl[channel].intr_enable,
  1877. C_IN_TXBEMPTY|C_IN_TXLOWWM|C_IN_RXHIWM|C_IN_RXNNDT|
  1878. C_IN_MDCD);
  1879. #else
  1880. cy_writel(&ch_ctrl[channel].intr_enable,
  1881. C_IN_MDCD);
  1882. #endif /* CONFIG_CYZ_INTR */
  1883. #endif /* Z_WAKE */
  1884. retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L);
  1885. if (retval != 0){
  1886. printk("cyc:startup(1) retval on ttyC%d was %x\n",
  1887. info->line, retval);
  1888. }
  1889. /* Flush RX buffers before raising DTR and RTS */
  1890. retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_RX, 0L);
  1891. if (retval != 0){
  1892. printk("cyc:startup(2) retval on ttyC%d was %x\n",
  1893. info->line, retval);
  1894. }
  1895. /* set timeout !!! */
  1896. /* set RTS and DTR !!! */
  1897. cy_writel(&ch_ctrl[channel].rs_control,
  1898. cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS | C_RS_DTR) ;
  1899. retval = cyz_issue_cmd(&cy_card[info->card],
  1900. channel, C_CM_IOCTLM, 0L);
  1901. if (retval != 0){
  1902. printk("cyc:startup(3) retval on ttyC%d was %x\n",
  1903. info->line, retval);
  1904. }
  1905. #ifdef CY_DEBUG_DTR
  1906. printk("cyc:startup raising Z DTR\n");
  1907. #endif
  1908. /* enable send, recv, modem !!! */
  1909. info->flags |= ASYNC_INITIALIZED;
  1910. if (info->tty){
  1911. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  1912. }
  1913. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  1914. info->breakon = info->breakoff = 0;
  1915. memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
  1916. info->idle_stats.in_use =
  1917. info->idle_stats.recv_idle =
  1918. info->idle_stats.xmit_idle = jiffies;
  1919. CY_UNLOCK(info, flags);
  1920. }
  1921. #ifdef CY_DEBUG_OPEN
  1922. printk(" cyc startup done\n");
  1923. #endif
  1924. return 0;
  1925. errout:
  1926. CY_UNLOCK(info, flags);
  1927. return retval;
  1928. } /* startup */
  1929. static void
  1930. start_xmit( struct cyclades_port *info )
  1931. {
  1932. unsigned long flags;
  1933. void __iomem *base_addr;
  1934. int card,chip,channel,index;
  1935. card = info->card;
  1936. channel = (info->line) - (cy_card[card].first_line);
  1937. if (!IS_CYC_Z(cy_card[card])) {
  1938. chip = channel>>2;
  1939. channel &= 0x03;
  1940. index = cy_card[card].bus_index;
  1941. base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
  1942. CY_LOCK(info, flags);
  1943. cy_writeb(base_addr+(CyCAR<<index), channel);
  1944. cy_writeb(base_addr+(CySRER<<index),
  1945. cy_readb(base_addr+(CySRER<<index)) | CyTxRdy);
  1946. CY_UNLOCK(info, flags);
  1947. } else {
  1948. #ifdef CONFIG_CYZ_INTR
  1949. int retval;
  1950. CY_LOCK(info, flags);
  1951. retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK, 0L);
  1952. if (retval != 0){
  1953. printk("cyc:start_xmit retval on ttyC%d was %x\n",
  1954. info->line, retval);
  1955. }
  1956. CY_UNLOCK(info, flags);
  1957. #else /* CONFIG_CYZ_INTR */
  1958. /* Don't have to do anything at this time */
  1959. #endif /* CONFIG_CYZ_INTR */
  1960. }
  1961. } /* start_xmit */
  1962. /*
  1963. * This routine shuts down a serial port; interrupts are disabled,
  1964. * and DTR is dropped if the hangup on close termio flag is on.
  1965. */
  1966. static void
  1967. shutdown(struct cyclades_port * info)
  1968. {
  1969. unsigned long flags;
  1970. void __iomem *base_addr;
  1971. int card,chip,channel,index;
  1972. if (!(info->flags & ASYNC_INITIALIZED)){
  1973. return;
  1974. }
  1975. card = info->card;
  1976. channel = info->line - cy_card[card].first_line;
  1977. if (!IS_CYC_Z(cy_card[card])) {
  1978. chip = channel>>2;
  1979. channel &= 0x03;
  1980. index = cy_card[card].bus_index;
  1981. base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
  1982. #ifdef CY_DEBUG_OPEN
  1983. printk("cyc shutdown Y card %d, chip %d, channel %d, base_addr %lx\n",
  1984. card, chip, channel, (long)base_addr);
  1985. #endif
  1986. CY_LOCK(info, flags);
  1987. /* Clear delta_msr_wait queue to avoid mem leaks. */
  1988. wake_up_interruptible(&info->delta_msr_wait);
  1989. if (info->xmit_buf){
  1990. unsigned char * temp;
  1991. temp = info->xmit_buf;
  1992. info->xmit_buf = NULL;
  1993. free_page((unsigned long) temp);
  1994. }
  1995. cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
  1996. if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
  1997. cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS);
  1998. cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR);
  1999. #ifdef CY_DEBUG_DTR
  2000. printk("cyc shutdown dropping DTR\n");
  2001. printk(" status: 0x%x, 0x%x\n",
  2002. cy_readb(base_addr+(CyMSVR1<<index)),
  2003. cy_readb(base_addr+(CyMSVR2<<index)));
  2004. #endif
  2005. }
  2006. cyy_issue_cmd(base_addr,CyCHAN_CTL|CyDIS_RCVR,index);
  2007. /* it may be appropriate to clear _XMIT at
  2008. some later date (after testing)!!! */
  2009. if (info->tty){
  2010. set_bit(TTY_IO_ERROR, &info->tty->flags);
  2011. }
  2012. info->flags &= ~ASYNC_INITIALIZED;
  2013. CY_UNLOCK(info, flags);
  2014. } else {
  2015. struct FIRM_ID __iomem *firm_id;
  2016. struct ZFW_CTRL __iomem *zfw_ctrl;
  2017. struct BOARD_CTRL __iomem *board_ctrl;
  2018. struct CH_CTRL __iomem *ch_ctrl;
  2019. int retval;
  2020. base_addr = cy_card[card].base_addr;
  2021. #ifdef CY_DEBUG_OPEN
  2022. printk("cyc shutdown Z card %d, channel %d, base_addr %lx\n",
  2023. card, channel, (long)base_addr);
  2024. #endif
  2025. firm_id = base_addr + ID_ADDRESS;
  2026. if (!ISZLOADED(cy_card[card])) {
  2027. return;
  2028. }
  2029. zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
  2030. board_ctrl = &zfw_ctrl->board_ctrl;
  2031. ch_ctrl = zfw_ctrl->ch_ctrl;
  2032. CY_LOCK(info, flags);
  2033. if (info->xmit_buf){
  2034. unsigned char * temp;
  2035. temp = info->xmit_buf;
  2036. info->xmit_buf = NULL;
  2037. free_page((unsigned long) temp);
  2038. }
  2039. if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
  2040. cy_writel(&ch_ctrl[channel].rs_control,
  2041. (uclong)(cy_readl(&ch_ctrl[channel].rs_control) &
  2042. ~(C_RS_RTS | C_RS_DTR)));
  2043. retval = cyz_issue_cmd(&cy_card[info->card],
  2044. channel, C_CM_IOCTLM, 0L);
  2045. if (retval != 0){
  2046. printk("cyc:shutdown retval on ttyC%d was %x\n",
  2047. info->line, retval);
  2048. }
  2049. #ifdef CY_DEBUG_DTR
  2050. printk("cyc:shutdown dropping Z DTR\n");
  2051. #endif
  2052. }
  2053. if (info->tty){
  2054. set_bit(TTY_IO_ERROR, &info->tty->flags);
  2055. }
  2056. info->flags &= ~ASYNC_INITIALIZED;
  2057. CY_UNLOCK(info, flags);
  2058. }
  2059. #ifdef CY_DEBUG_OPEN
  2060. printk(" cyc shutdown done\n");
  2061. #endif
  2062. return;
  2063. } /* shutdown */
  2064. /*
  2065. * ------------------------------------------------------------
  2066. * cy_open() and friends
  2067. * ------------------------------------------------------------
  2068. */
  2069. static int
  2070. block_til_ready(struct tty_struct *tty, struct file * filp,
  2071. struct cyclades_port *info)
  2072. {
  2073. DECLARE_WAITQUEUE(wait, current);
  2074. struct cyclades_card *cinfo;
  2075. unsigned long flags;
  2076. int chip, channel,index;
  2077. int retval;
  2078. void __iomem *base_addr;
  2079. cinfo = &cy_card[info->card];
  2080. channel = info->line - cinfo->first_line;
  2081. /*
  2082. * If the device is in the middle of being closed, then block
  2083. * until it's done, and then try again.
  2084. */
  2085. if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
  2086. if (info->flags & ASYNC_CLOSING) {
  2087. interruptible_sleep_on(&info->close_wait);
  2088. }
  2089. return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
  2090. }
  2091. /*
  2092. * If non-blocking mode is set, then make the check up front
  2093. * and then exit.
  2094. */
  2095. if ((filp->f_flags & O_NONBLOCK) ||
  2096. (tty->flags & (1 << TTY_IO_ERROR))) {
  2097. info->flags |= ASYNC_NORMAL_ACTIVE;
  2098. return 0;
  2099. }
  2100. /*
  2101. * Block waiting for the carrier detect and the line to become
  2102. * free (i.e., not in use by the callout). While we are in
  2103. * this loop, info->count is dropped by one, so that
  2104. * cy_close() knows when to free things. We restore it upon
  2105. * exit, either normal or abnormal.
  2106. */
  2107. retval = 0;
  2108. add_wait_queue(&info->open_wait, &wait);
  2109. #ifdef CY_DEBUG_OPEN
  2110. printk("cyc block_til_ready before block: ttyC%d, count = %d\n",
  2111. info->line, info->count);/**/
  2112. #endif
  2113. CY_LOCK(info, flags);
  2114. if (!tty_hung_up_p(filp))
  2115. info->count--;
  2116. CY_UNLOCK(info, flags);
  2117. #ifdef CY_DEBUG_COUNT
  2118. printk("cyc block_til_ready: (%d): decrementing count to %d\n",
  2119. current->pid, info->count);
  2120. #endif
  2121. info->blocked_open++;
  2122. if (!IS_CYC_Z(*cinfo)) {
  2123. chip = channel>>2;
  2124. channel &= 0x03;
  2125. index = cinfo->bus_index;
  2126. base_addr = cinfo->base_addr + (cy_chip_offset[chip]<<index);
  2127. while (1) {
  2128. CY_LOCK(info, flags);
  2129. if ((tty->termios->c_cflag & CBAUD)){
  2130. cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
  2131. cy_writeb(base_addr+(CyMSVR1<<index), CyRTS);
  2132. cy_writeb(base_addr+(CyMSVR2<<index), CyDTR);
  2133. #ifdef CY_DEBUG_DTR
  2134. printk("cyc:block_til_ready raising DTR\n");
  2135. printk(" status: 0x%x, 0x%x\n",
  2136. cy_readb(base_addr+(CyMSVR1<<index)),
  2137. cy_readb(base_addr+(CyMSVR2<<index)));
  2138. #endif
  2139. }
  2140. CY_UNLOCK(info, flags);
  2141. set_current_state(TASK_INTERRUPTIBLE);
  2142. if (tty_hung_up_p(filp)
  2143. || !(info->flags & ASYNC_INITIALIZED) ){
  2144. retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
  2145. -EAGAIN : -ERESTARTSYS);
  2146. break;
  2147. }
  2148. CY_LOCK(info, flags);
  2149. cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
  2150. if (!(info->flags & ASYNC_CLOSING)
  2151. && (C_CLOCAL(tty)
  2152. || (cy_readb(base_addr+(CyMSVR1<<index)) & CyDCD))) {
  2153. CY_UNLOCK(info, flags);
  2154. break;
  2155. }
  2156. CY_UNLOCK(info, flags);
  2157. if (signal_pending(current)) {
  2158. retval = -ERESTARTSYS;
  2159. break;
  2160. }
  2161. #ifdef CY_DEBUG_OPEN
  2162. printk("cyc block_til_ready blocking: ttyC%d, count = %d\n",
  2163. info->line, info->count);/**/
  2164. #endif
  2165. schedule();
  2166. }
  2167. } else {
  2168. struct FIRM_ID __iomem *firm_id;
  2169. struct ZFW_CTRL __iomem *zfw_ctrl;
  2170. struct BOARD_CTRL __iomem *board_ctrl;
  2171. struct CH_CTRL __iomem *ch_ctrl;
  2172. int retval;
  2173. base_addr = cinfo->base_addr;
  2174. firm_id = base_addr + ID_ADDRESS;
  2175. if (!ISZLOADED(*cinfo)){
  2176. current->state = TASK_RUNNING;
  2177. remove_wait_queue(&info->open_wait, &wait);
  2178. return -EINVAL;
  2179. }
  2180. zfw_ctrl = base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
  2181. board_ctrl = &zfw_ctrl->board_ctrl;
  2182. ch_ctrl = zfw_ctrl->ch_ctrl;
  2183. while (1) {
  2184. if ((tty->termios->c_cflag & CBAUD)){
  2185. cy_writel(&ch_ctrl[channel].rs_control,
  2186. cy_readl(&ch_ctrl[channel].rs_control) |
  2187. (C_RS_RTS | C_RS_DTR));
  2188. retval = cyz_issue_cmd(&cy_card[info->card],
  2189. channel, C_CM_IOCTLM, 0L);
  2190. if (retval != 0){
  2191. printk("cyc:block_til_ready retval on ttyC%d was %x\n",
  2192. info->line, retval);
  2193. }
  2194. #ifdef CY_DEBUG_DTR
  2195. printk("cyc:block_til_ready raising Z DTR\n");
  2196. #endif
  2197. }
  2198. set_current_state(TASK_INTERRUPTIBLE);
  2199. if (tty_hung_up_p(filp)
  2200. || !(info->flags & ASYNC_INITIALIZED) ){
  2201. retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
  2202. -EAGAIN : -ERESTARTSYS);
  2203. break;
  2204. }
  2205. if (!(info->flags & ASYNC_CLOSING)
  2206. && (C_CLOCAL(tty)
  2207. || (cy_readl(&ch_ctrl[channel].rs_status) & C_RS_DCD))) {
  2208. break;
  2209. }
  2210. if (signal_pending(current)) {
  2211. retval = -ERESTARTSYS;
  2212. break;
  2213. }
  2214. #ifdef CY_DEBUG_OPEN
  2215. printk("cyc block_til_ready blocking: ttyC%d, count = %d\n",
  2216. info->line, info->count);/**/
  2217. #endif
  2218. schedule();
  2219. }
  2220. }
  2221. current->state = TASK_RUNNING;
  2222. remove_wait_queue(&info->open_wait, &wait);
  2223. if (!tty_hung_up_p(filp)){
  2224. info->count++;
  2225. #ifdef CY_DEBUG_COUNT
  2226. printk("cyc:block_til_ready (%d): incrementing count to %d\n",
  2227. current->pid, info->count);
  2228. #endif
  2229. }
  2230. info->blocked_open--;
  2231. #ifdef CY_DEBUG_OPEN
  2232. printk("cyc:block_til_ready after blocking: ttyC%d, count = %d\n",
  2233. info->line, info->count);/**/
  2234. #endif
  2235. if (retval)
  2236. return retval;
  2237. info->flags |= ASYNC_NORMAL_ACTIVE;
  2238. return 0;
  2239. } /* block_til_ready */
  2240. /*
  2241. * This routine is called whenever a serial port is opened. It
  2242. * performs the serial-specific initialization for the tty structure.
  2243. */
  2244. static int
  2245. cy_open(struct tty_struct *tty, struct file * filp)
  2246. {
  2247. struct cyclades_port *info;
  2248. int retval, line;
  2249. unsigned long page;
  2250. line = tty->index;
  2251. if ((line < 0) || (NR_PORTS <= line)){
  2252. return -ENODEV;
  2253. }
  2254. info = &cy_port[line];
  2255. if (info->line < 0){
  2256. return -ENODEV;
  2257. }
  2258. /* If the card's firmware hasn't been loaded,
  2259. treat it as absent from the system. This
  2260. will make the user pay attention.
  2261. */
  2262. if (IS_CYC_Z(cy_card[info->card])) {
  2263. struct cyclades_card *cinfo = &cy_card[info->card];
  2264. struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS;
  2265. if (!ISZLOADED(*cinfo)) {
  2266. if (((ZE_V1 ==cy_readl(&((struct RUNTIME_9060 __iomem *)
  2267. (cinfo->ctl_addr))->mail_box_0)) &&
  2268. Z_FPGA_CHECK (*cinfo)) &&
  2269. (ZFIRM_HLT == cy_readl (&firm_id->signature)))
  2270. {
  2271. printk ("cyc:Cyclades-Z Error: you need an external power supply for this number of ports.\n\rFirmware halted.\r\n");
  2272. } else {
  2273. printk("cyc:Cyclades-Z firmware not yet loaded\n");
  2274. }
  2275. return -ENODEV;
  2276. }
  2277. #ifdef CONFIG_CYZ_INTR
  2278. else {
  2279. /* In case this Z board is operating in interrupt mode, its
  2280. interrupts should be enabled as soon as the first open happens
  2281. to one of its ports. */
  2282. if (!cinfo->intr_enabled) {
  2283. struct ZFW_CTRL __iomem *zfw_ctrl;
  2284. struct BOARD_CTRL __iomem *board_ctrl;
  2285. zfw_ctrl = cinfo->base_addr + (cy_readl (&firm_id->zfwctrl_addr) & 0xfffff);
  2286. board_ctrl = &zfw_ctrl->board_ctrl;
  2287. /* Enable interrupts on the PLX chip */
  2288. cy_writew(cinfo->ctl_addr+0x68,
  2289. cy_readw(cinfo->ctl_addr+0x68)|0x0900);
  2290. /* Enable interrupts on the FW */
  2291. retval = cyz_issue_cmd(cinfo,
  2292. 0, C_CM_IRQ_ENBL, 0L);
  2293. if (retval != 0){
  2294. printk("cyc:IRQ enable retval was %x\n", retval);
  2295. }
  2296. cinfo->nports = (int) cy_readl (&board_ctrl->n_channel);
  2297. cinfo->intr_enabled = 1;
  2298. }
  2299. }
  2300. #endif /* CONFIG_CYZ_INTR */
  2301. /* Make sure this Z port really exists in hardware */
  2302. if (info->line > (cinfo->first_line + cinfo->nports - 1))
  2303. return -ENODEV;
  2304. }
  2305. #ifdef CY_DEBUG_OTHER
  2306. printk("cyc:cy_open ttyC%d\n", info->line); /* */
  2307. #endif
  2308. tty->driver_data = info;
  2309. info->tty = tty;
  2310. if (serial_paranoia_check(info, tty->name, "cy_open")){
  2311. return -ENODEV;
  2312. }
  2313. #ifdef CY_DEBUG_OPEN
  2314. printk("cyc:cy_open ttyC%d, count = %d\n",
  2315. info->line, info->count);/**/
  2316. #endif
  2317. info->count++;
  2318. #ifdef CY_DEBUG_COUNT
  2319. printk("cyc:cy_open (%d): incrementing count to %d\n",
  2320. current->pid, info->count);
  2321. #endif
  2322. if (!tmp_buf) {
  2323. page = get_zeroed_page(GFP_KERNEL);
  2324. if (!page)
  2325. return -ENOMEM;
  2326. if (tmp_buf)
  2327. free_page(page);
  2328. else
  2329. tmp_buf = (unsigned char *) page;
  2330. }
  2331. /*
  2332. * If the port is the middle of closing, bail out now
  2333. */
  2334. if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
  2335. if (info->flags & ASYNC_CLOSING)
  2336. interruptible_sleep_on(&info->close_wait);
  2337. return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
  2338. }
  2339. /*
  2340. * Start up serial port
  2341. */
  2342. retval = startup(info);
  2343. if (retval){
  2344. return retval;
  2345. }
  2346. retval = block_til_ready(tty, filp, info);
  2347. if (retval) {
  2348. #ifdef CY_DEBUG_OPEN
  2349. printk("cyc:cy_open returning after block_til_ready with %d\n",
  2350. retval);
  2351. #endif
  2352. return retval;
  2353. }
  2354. info->throttle = 0;
  2355. #ifdef CY_DEBUG_OPEN
  2356. printk(" cyc:cy_open done\n");/**/
  2357. #endif
  2358. return 0;
  2359. } /* cy_open */
  2360. /*
  2361. * cy_wait_until_sent() --- wait until the transmitter is empty
  2362. */
  2363. static void
  2364. cy_wait_until_sent(struct tty_struct *tty, int timeout)
  2365. {
  2366. struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
  2367. void __iomem *base_addr;
  2368. int card,chip,channel,index;
  2369. unsigned long orig_jiffies;
  2370. int char_time;
  2371. if (serial_paranoia_check(info, tty->name, "cy_wait_until_sent"))
  2372. return;
  2373. if (info->xmit_fifo_size == 0)
  2374. return; /* Just in case.... */
  2375. orig_jiffies = jiffies;
  2376. /*
  2377. * Set the check interval to be 1/5 of the estimated time to
  2378. * send a single character, and make it at least 1. The check
  2379. * interval should also be less than the timeout.
  2380. *
  2381. * Note: we have to use pretty tight timings here to satisfy
  2382. * the NIST-PCTS.
  2383. */
  2384. char_time = (info->timeout - HZ/50) / info->xmit_fifo_size;
  2385. char_time = char_time / 5;
  2386. if (char_time <= 0)
  2387. char_time = 1;
  2388. if (timeout < 0)
  2389. timeout = 0;
  2390. if (timeout)
  2391. char_time = min(char_time, timeout);
  2392. /*
  2393. * If the transmitter hasn't cleared in twice the approximate
  2394. * amount of time to send the entire FIFO, it probably won't
  2395. * ever clear. This assumes the UART isn't doing flow
  2396. * control, which is currently the case. Hence, if it ever
  2397. * takes longer than info->timeout, this is probably due to a
  2398. * UART bug of some kind. So, we clamp the timeout parameter at
  2399. * 2*info->timeout.
  2400. */
  2401. if (!timeout || timeout > 2*info->timeout)
  2402. timeout = 2*info->timeout;
  2403. #ifdef CY_DEBUG_WAIT_UNTIL_SENT
  2404. printk("In cy_wait_until_sent(%d) check=%lu...", timeout, char_time);
  2405. printk("jiff=%lu...", jiffies);
  2406. #endif
  2407. card = info->card;
  2408. channel = (info->line) - (cy_card[card].first_line);
  2409. if (!IS_CYC_Z(cy_card[card])) {
  2410. chip = channel>>2;
  2411. channel &= 0x03;
  2412. index = cy_card[card].bus_index;
  2413. base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
  2414. while (cy_readb(base_addr+(CySRER<<index)) & CyTxRdy) {
  2415. #ifdef CY_DEBUG_WAIT_UNTIL_SENT
  2416. printk("Not clean (jiff=%lu)...", jiffies);
  2417. #endif
  2418. if (msleep_interruptible(jiffies_to_msecs(char_time)))
  2419. break;
  2420. if (timeout && time_after(jiffies, orig_jiffies + timeout))
  2421. break;
  2422. }
  2423. } else {
  2424. // Nothing to do!
  2425. }
  2426. /* Run one more char cycle */
  2427. msleep_interruptible(jiffies_to_msecs(char_time * 5));
  2428. #ifdef CY_DEBUG_WAIT_UNTIL_SENT
  2429. printk("Clean (jiff=%lu)...done\n", jiffies);
  2430. #endif
  2431. }
  2432. /*
  2433. * This routine is called when a particular tty device is closed.
  2434. */
  2435. static void
  2436. cy_close(struct tty_struct *tty, struct file *filp)
  2437. {
  2438. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  2439. unsigned long flags;
  2440. #ifdef CY_DEBUG_OTHER
  2441. printk("cyc:cy_close ttyC%d\n", info->line);
  2442. #endif
  2443. if (!info || serial_paranoia_check(info, tty->name, "cy_close")){
  2444. return;
  2445. }
  2446. CY_LOCK(info, flags);
  2447. /* If the TTY is being hung up, nothing to do */
  2448. if (tty_hung_up_p(filp)) {
  2449. CY_UNLOCK(info, flags);
  2450. return;
  2451. }
  2452. #ifdef CY_DEBUG_OPEN
  2453. printk("cyc:cy_close ttyC%d, count = %d\n", info->line, info->count);
  2454. #endif
  2455. if ((tty->count == 1) && (info->count != 1)) {
  2456. /*
  2457. * Uh, oh. tty->count is 1, which means that the tty
  2458. * structure will be freed. Info->count should always
  2459. * be one in these conditions. If it's greater than
  2460. * one, we've got real problems, since it means the
  2461. * serial port won't be shutdown.
  2462. */
  2463. printk("cyc:cy_close: bad serial port count; tty->count is 1, "
  2464. "info->count is %d\n", info->count);
  2465. info->count = 1;
  2466. }
  2467. #ifdef CY_DEBUG_COUNT
  2468. printk("cyc:cy_close at (%d): decrementing count to %d\n",
  2469. current->pid, info->count - 1);
  2470. #endif
  2471. if (--info->count < 0) {
  2472. #ifdef CY_DEBUG_COUNT
  2473. printk("cyc:cyc_close setting count to 0\n");
  2474. #endif
  2475. info->count = 0;
  2476. }
  2477. if (info->count) {
  2478. CY_UNLOCK(info, flags);
  2479. return;
  2480. }
  2481. info->flags |= ASYNC_CLOSING;
  2482. /*
  2483. * Now we wait for the transmit buffer to clear; and we notify
  2484. * the line discipline to only process XON/XOFF characters.
  2485. */
  2486. tty->closing = 1;
  2487. CY_UNLOCK(info, flags);
  2488. if (info->closing_wait != CY_CLOSING_WAIT_NONE) {
  2489. tty_wait_until_sent(tty, info->closing_wait);
  2490. }
  2491. CY_LOCK(info, flags);
  2492. if (!IS_CYC_Z(cy_card[info->card])) {
  2493. int channel = info->line - cy_card[info->card].first_line;
  2494. int index = cy_card[info->card].bus_index;
  2495. void __iomem *base_addr = cy_card[info->card].base_addr + (cy_chip_offset[channel>>2] << index);
  2496. /* Stop accepting input */
  2497. channel &= 0x03;
  2498. cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
  2499. cy_writeb(base_addr+(CySRER<<index),
  2500. cy_readb(base_addr+(CySRER<<index)) & ~CyRxData);
  2501. if (info->flags & ASYNC_INITIALIZED) {
  2502. /* Waiting for on-board buffers to be empty before closing
  2503. the port */
  2504. CY_UNLOCK(info, flags);
  2505. cy_wait_until_sent(tty, info->timeout);
  2506. CY_LOCK(info, flags);
  2507. }
  2508. } else {
  2509. #ifdef Z_WAKE
  2510. /* Waiting for on-board buffers to be empty before closing the port */
  2511. void __iomem *base_addr = cy_card[info->card].base_addr;
  2512. struct FIRM_ID __iomem *firm_id = base_addr + ID_ADDRESS;
  2513. struct ZFW_CTRL __iomem *zfw_ctrl = base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
  2514. struct CH_CTRL __iomem *ch_ctrl = zfw_ctrl->ch_ctrl;
  2515. int channel = info->line - cy_card[info->card].first_line;
  2516. int retval;
  2517. if (cy_readl(&ch_ctrl[channel].flow_status) != C_FS_TXIDLE) {
  2518. retval = cyz_issue_cmd(&cy_card[info->card], channel,
  2519. C_CM_IOCTLW, 0L);
  2520. if (retval != 0){
  2521. printk("cyc:cy_close retval on ttyC%d was %x\n",
  2522. info->line, retval);
  2523. }
  2524. CY_UNLOCK(info, flags);
  2525. interruptible_sleep_on(&info->shutdown_wait);
  2526. CY_LOCK(info, flags);
  2527. }
  2528. #endif
  2529. }
  2530. CY_UNLOCK(info, flags);
  2531. shutdown(info);
  2532. if (tty->driver->flush_buffer)
  2533. tty->driver->flush_buffer(tty);
  2534. tty_ldisc_flush(tty);
  2535. CY_LOCK(info, flags);
  2536. tty->closing = 0;
  2537. info->event = 0;
  2538. info->tty = NULL;
  2539. if (info->blocked_open) {
  2540. CY_UNLOCK(info, flags);
  2541. if (info->close_delay) {
  2542. msleep_interruptible(jiffies_to_msecs(info->close_delay));
  2543. }
  2544. wake_up_interruptible(&info->open_wait);
  2545. CY_LOCK(info, flags);
  2546. }
  2547. info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  2548. wake_up_interruptible(&info->close_wait);
  2549. #ifdef CY_DEBUG_OTHER
  2550. printk(" cyc:cy_close done\n");
  2551. #endif
  2552. CY_UNLOCK(info, flags);
  2553. return;
  2554. } /* cy_close */
  2555. /* This routine gets called when tty_write has put something into
  2556. * the write_queue. The characters may come from user space or
  2557. * kernel space.
  2558. *
  2559. * This routine will return the number of characters actually
  2560. * accepted for writing.
  2561. *
  2562. * If the port is not already transmitting stuff, start it off by
  2563. * enabling interrupts. The interrupt service routine will then
  2564. * ensure that the characters are sent.
  2565. * If the port is already active, there is no need to kick it.
  2566. *
  2567. */
  2568. static int
  2569. cy_write(struct tty_struct * tty, const unsigned char *buf, int count)
  2570. {
  2571. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  2572. unsigned long flags;
  2573. int c, ret = 0;
  2574. #ifdef CY_DEBUG_IO
  2575. printk("cyc:cy_write ttyC%d\n", info->line); /* */
  2576. #endif
  2577. if (serial_paranoia_check(info, tty->name, "cy_write")){
  2578. return 0;
  2579. }
  2580. if (!tty || !info->xmit_buf || !tmp_buf){
  2581. return 0;
  2582. }
  2583. CY_LOCK(info, flags);
  2584. while (1) {
  2585. c = min(count, min((int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1),
  2586. (int)(SERIAL_XMIT_SIZE - info->xmit_head)));
  2587. if (c <= 0)
  2588. break;
  2589. memcpy(info->xmit_buf + info->xmit_head, buf, c);
  2590. info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
  2591. info->xmit_cnt += c;
  2592. buf += c;
  2593. count -= c;
  2594. ret += c;
  2595. }
  2596. CY_UNLOCK(info, flags);
  2597. info->idle_stats.xmit_bytes += ret;
  2598. info->idle_stats.xmit_idle = jiffies;
  2599. if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
  2600. start_xmit(info);
  2601. }
  2602. return ret;
  2603. } /* cy_write */
  2604. /*
  2605. * This routine is called by the kernel to write a single
  2606. * character to the tty device. If the kernel uses this routine,
  2607. * it must call the flush_chars() routine (if defined) when it is
  2608. * done stuffing characters into the driver. If there is no room
  2609. * in the queue, the character is ignored.
  2610. */
  2611. static void
  2612. cy_put_char(struct tty_struct *tty, unsigned char ch)
  2613. {
  2614. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  2615. unsigned long flags;
  2616. #ifdef CY_DEBUG_IO
  2617. printk("cyc:cy_put_char ttyC%d\n", info->line);
  2618. #endif
  2619. if (serial_paranoia_check(info, tty->name, "cy_put_char"))
  2620. return;
  2621. if (!tty || !info->xmit_buf)
  2622. return;
  2623. CY_LOCK(info, flags);
  2624. if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
  2625. CY_UNLOCK(info, flags);
  2626. return;
  2627. }
  2628. info->xmit_buf[info->xmit_head++] = ch;
  2629. info->xmit_head &= SERIAL_XMIT_SIZE - 1;
  2630. info->xmit_cnt++;
  2631. info->idle_stats.xmit_bytes++;
  2632. info->idle_stats.xmit_idle = jiffies;
  2633. CY_UNLOCK(info, flags);
  2634. } /* cy_put_char */
  2635. /*
  2636. * This routine is called by the kernel after it has written a
  2637. * series of characters to the tty device using put_char().
  2638. */
  2639. static void
  2640. cy_flush_chars(struct tty_struct *tty)
  2641. {
  2642. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  2643. #ifdef CY_DEBUG_IO
  2644. printk("cyc:cy_flush_chars ttyC%d\n", info->line); /* */
  2645. #endif
  2646. if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
  2647. return;
  2648. if (info->xmit_cnt <= 0 || tty->stopped
  2649. || tty->hw_stopped || !info->xmit_buf)
  2650. return;
  2651. start_xmit(info);
  2652. } /* cy_flush_chars */
  2653. /*
  2654. * This routine returns the numbers of characters the tty driver
  2655. * will accept for queuing to be written. This number is subject
  2656. * to change as output buffers get emptied, or if the output flow
  2657. * control is activated.
  2658. */
  2659. static int
  2660. cy_write_room(struct tty_struct *tty)
  2661. {
  2662. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  2663. int ret;
  2664. #ifdef CY_DEBUG_IO
  2665. printk("cyc:cy_write_room ttyC%d\n", info->line); /* */
  2666. #endif
  2667. if (serial_paranoia_check(info, tty->name, "cy_write_room"))
  2668. return 0;
  2669. ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
  2670. if (ret < 0)
  2671. ret = 0;
  2672. return ret;
  2673. } /* cy_write_room */
  2674. static int
  2675. cy_chars_in_buffer(struct tty_struct *tty)
  2676. {
  2677. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  2678. int card, channel;
  2679. if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
  2680. return 0;
  2681. card = info->card;
  2682. channel = (info->line) - (cy_card[card].first_line);
  2683. #ifdef Z_EXT_CHARS_IN_BUFFER
  2684. if (!IS_CYC_Z(cy_card[card])) {
  2685. #endif /* Z_EXT_CHARS_IN_BUFFER */
  2686. #ifdef CY_DEBUG_IO
  2687. printk("cyc:cy_chars_in_buffer ttyC%d %d\n",
  2688. info->line, info->xmit_cnt); /* */
  2689. #endif
  2690. return info->xmit_cnt;
  2691. #ifdef Z_EXT_CHARS_IN_BUFFER
  2692. } else {
  2693. static volatile struct FIRM_ID *firm_id;
  2694. static volatile struct ZFW_CTRL *zfw_ctrl;
  2695. static volatile struct CH_CTRL *ch_ctrl;
  2696. static volatile struct BUF_CTRL *buf_ctrl;
  2697. int char_count;
  2698. volatile uclong tx_put, tx_get, tx_bufsize;
  2699. firm_id = cy_card[card].base_addr + ID_ADDRESS;
  2700. zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
  2701. ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
  2702. buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
  2703. tx_get = cy_readl(&buf_ctrl->tx_get);
  2704. tx_put = cy_readl(&buf_ctrl->tx_put);
  2705. tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize);
  2706. if (tx_put >= tx_get)
  2707. char_count = tx_put - tx_get;
  2708. else
  2709. char_count = tx_put - tx_get + tx_bufsize;
  2710. #ifdef CY_DEBUG_IO
  2711. printk("cyc:cy_chars_in_buffer ttyC%d %d\n",
  2712. info->line, info->xmit_cnt + char_count); /* */
  2713. #endif
  2714. return (info->xmit_cnt + char_count);
  2715. }
  2716. #endif /* Z_EXT_CHARS_IN_BUFFER */
  2717. } /* cy_chars_in_buffer */
  2718. /*
  2719. * ------------------------------------------------------------
  2720. * cy_ioctl() and friends
  2721. * ------------------------------------------------------------
  2722. */
  2723. static void
  2724. cyy_baud_calc(struct cyclades_port *info, uclong baud)
  2725. {
  2726. int co, co_val, bpr;
  2727. uclong cy_clock = ((info->chip_rev >= CD1400_REV_J) ? 60000000 : 25000000);
  2728. if (baud == 0) {
  2729. info->tbpr = info->tco = info->rbpr = info->rco = 0;
  2730. return;
  2731. }
  2732. /* determine which prescaler to use */
  2733. for (co = 4, co_val = 2048; co; co--, co_val >>= 2) {
  2734. if (cy_clock / co_val / baud > 63)
  2735. break;
  2736. }
  2737. bpr = (cy_clock / co_val * 2 / baud + 1) / 2;
  2738. if (bpr > 255)
  2739. bpr = 255;
  2740. info->tbpr = info->rbpr = bpr;
  2741. info->tco = info->rco = co;
  2742. }
  2743. /*
  2744. * This routine finds or computes the various line characteristics.
  2745. * It used to be called config_setup
  2746. */
  2747. static void
  2748. set_line_char(struct cyclades_port * info)
  2749. {
  2750. unsigned long flags;
  2751. void __iomem *base_addr;
  2752. int card,chip,channel,index;
  2753. unsigned cflag, iflag;
  2754. unsigned short chip_number;
  2755. int baud, baud_rate = 0;
  2756. int i;
  2757. if (!info->tty || !info->tty->termios){
  2758. return;
  2759. }
  2760. if (info->line == -1){
  2761. return;
  2762. }
  2763. cflag = info->tty->termios->c_cflag;
  2764. iflag = info->tty->termios->c_iflag;
  2765. /*
  2766. * Set up the tty->alt_speed kludge
  2767. */
  2768. if (info->tty) {
  2769. if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  2770. info->tty->alt_speed = 57600;
  2771. if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  2772. info->tty->alt_speed = 115200;
  2773. if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  2774. info->tty->alt_speed = 230400;
  2775. if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  2776. info->tty->alt_speed = 460800;
  2777. }
  2778. card = info->card;
  2779. channel = (info->line) - (cy_card[card].first_line);
  2780. chip_number = channel / 4;
  2781. if (!IS_CYC_Z(cy_card[card])) {
  2782. index = cy_card[card].bus_index;
  2783. /* baud rate */
  2784. baud = tty_get_baud_rate(info->tty);
  2785. if ((baud == 38400) &&
  2786. ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
  2787. if (info->custom_divisor)
  2788. baud_rate = info->baud / info->custom_divisor;
  2789. else
  2790. baud_rate = info->baud;
  2791. } else if (baud > CD1400_MAX_SPEED) {
  2792. baud = CD1400_MAX_SPEED;
  2793. }
  2794. /* find the baud index */
  2795. for (i = 0; i < 20; i++) {
  2796. if (baud == baud_table[i]) {
  2797. break;
  2798. }
  2799. }
  2800. if (i == 20) {
  2801. i = 19; /* CD1400_MAX_SPEED */
  2802. }
  2803. if ((baud == 38400) &&
  2804. ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
  2805. cyy_baud_calc(info, baud_rate);
  2806. } else {
  2807. if(info->chip_rev >= CD1400_REV_J) {
  2808. /* It is a CD1400 rev. J or later */
  2809. info->tbpr = baud_bpr_60[i]; /* Tx BPR */
  2810. info->tco = baud_co_60[i]; /* Tx CO */
  2811. info->rbpr = baud_bpr_60[i]; /* Rx BPR */
  2812. info->rco = baud_co_60[i]; /* Rx CO */
  2813. } else {
  2814. info->tbpr = baud_bpr_25[i]; /* Tx BPR */
  2815. info->tco = baud_co_25[i]; /* Tx CO */
  2816. info->rbpr = baud_bpr_25[i]; /* Rx BPR */
  2817. info->rco = baud_co_25[i]; /* Rx CO */
  2818. }
  2819. }
  2820. if (baud_table[i] == 134) {
  2821. /* get it right for 134.5 baud */
  2822. info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
  2823. } else if ((baud == 38400) &&
  2824. ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
  2825. info->timeout = (info->xmit_fifo_size*HZ*15/baud_rate) + 2;
  2826. } else if (baud_table[i]) {
  2827. info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2;
  2828. /* this needs to be propagated into the card info */
  2829. } else {
  2830. info->timeout = 0;
  2831. }
  2832. /* By tradition (is it a standard?) a baud rate of zero
  2833. implies the line should be/has been closed. A bit
  2834. later in this routine such a test is performed. */
  2835. /* byte size and parity */
  2836. info->cor5 = 0;
  2837. info->cor4 = 0;
  2838. info->cor3 = (info->default_threshold
  2839. ? info->default_threshold
  2840. : baud_cor3[i]); /* receive threshold */
  2841. info->cor2 = CyETC;
  2842. switch(cflag & CSIZE){
  2843. case CS5:
  2844. info->cor1 = Cy_5_BITS;
  2845. break;
  2846. case CS6:
  2847. info->cor1 = Cy_6_BITS;
  2848. break;
  2849. case CS7:
  2850. info->cor1 = Cy_7_BITS;
  2851. break;
  2852. case CS8:
  2853. info->cor1 = Cy_8_BITS;
  2854. break;
  2855. }
  2856. if(cflag & CSTOPB){
  2857. info->cor1 |= Cy_2_STOP;
  2858. }
  2859. if (cflag & PARENB){
  2860. if (cflag & PARODD){
  2861. info->cor1 |= CyPARITY_O;
  2862. }else{
  2863. info->cor1 |= CyPARITY_E;
  2864. }
  2865. }else{
  2866. info->cor1 |= CyPARITY_NONE;
  2867. }
  2868. /* CTS flow control flag */
  2869. if (cflag & CRTSCTS){
  2870. info->flags |= ASYNC_CTS_FLOW;
  2871. info->cor2 |= CyCtsAE;
  2872. }else{
  2873. info->flags &= ~ASYNC_CTS_FLOW;
  2874. info->cor2 &= ~CyCtsAE;
  2875. }
  2876. if (cflag & CLOCAL)
  2877. info->flags &= ~ASYNC_CHECK_CD;
  2878. else
  2879. info->flags |= ASYNC_CHECK_CD;
  2880. /***********************************************
  2881. The hardware option, CyRtsAO, presents RTS when
  2882. the chip has characters to send. Since most modems
  2883. use RTS as reverse (inbound) flow control, this
  2884. option is not used. If inbound flow control is
  2885. necessary, DTR can be programmed to provide the
  2886. appropriate signals for use with a non-standard
  2887. cable. Contact Marcio Saito for details.
  2888. ***********************************************/
  2889. chip = channel>>2;
  2890. channel &= 0x03;
  2891. base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
  2892. CY_LOCK(info, flags);
  2893. cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
  2894. /* tx and rx baud rate */
  2895. cy_writeb(base_addr+(CyTCOR<<index), info->tco);
  2896. cy_writeb(base_addr+(CyTBPR<<index), info->tbpr);
  2897. cy_writeb(base_addr+(CyRCOR<<index), info->rco);
  2898. cy_writeb(base_addr+(CyRBPR<<index), info->rbpr);
  2899. /* set line characteristics according configuration */
  2900. cy_writeb(base_addr+(CySCHR1<<index),
  2901. START_CHAR(info->tty));
  2902. cy_writeb(base_addr+(CySCHR2<<index),
  2903. STOP_CHAR(info->tty));
  2904. cy_writeb(base_addr+(CyCOR1<<index), info->cor1);
  2905. cy_writeb(base_addr+(CyCOR2<<index), info->cor2);
  2906. cy_writeb(base_addr+(CyCOR3<<index), info->cor3);
  2907. cy_writeb(base_addr+(CyCOR4<<index), info->cor4);
  2908. cy_writeb(base_addr+(CyCOR5<<index), info->cor5);
  2909. cyy_issue_cmd(base_addr,
  2910. CyCOR_CHANGE|CyCOR1ch|CyCOR2ch|CyCOR3ch,index);
  2911. cy_writeb(base_addr+(CyCAR<<index),
  2912. (u_char)channel); /* !!! Is this needed? */
  2913. cy_writeb(base_addr+(CyRTPR<<index), (info->default_timeout
  2914. ? info->default_timeout
  2915. : 0x02)); /* 10ms rx timeout */
  2916. if (C_CLOCAL(info->tty)) {
  2917. /* without modem intr */
  2918. cy_writeb(base_addr+(CySRER<<index),
  2919. cy_readb(base_addr+(CySRER<<index)) | CyMdmCh);
  2920. /* act on 1->0 modem transitions */
  2921. if ((cflag & CRTSCTS) && info->rflow) {
  2922. cy_writeb(base_addr+(CyMCOR1<<index),
  2923. (CyCTS|rflow_thr[i]));
  2924. } else {
  2925. cy_writeb(base_addr+(CyMCOR1<<index), CyCTS);
  2926. }
  2927. /* act on 0->1 modem transitions */
  2928. cy_writeb(base_addr+(CyMCOR2<<index), CyCTS);
  2929. } else {
  2930. /* without modem intr */
  2931. cy_writeb(base_addr+(CySRER<<index),
  2932. cy_readb(base_addr+(CySRER<<index)) | CyMdmCh);
  2933. /* act on 1->0 modem transitions */
  2934. if ((cflag & CRTSCTS) && info->rflow) {
  2935. cy_writeb(base_addr+(CyMCOR1<<index),
  2936. (CyDSR|CyCTS|CyRI|CyDCD|rflow_thr[i]));
  2937. } else {
  2938. cy_writeb(base_addr+(CyMCOR1<<index),
  2939. CyDSR|CyCTS|CyRI|CyDCD);
  2940. }
  2941. /* act on 0->1 modem transitions */
  2942. cy_writeb(base_addr+(CyMCOR2<<index),
  2943. CyDSR|CyCTS|CyRI|CyDCD);
  2944. }
  2945. if(i == 0){ /* baud rate is zero, turn off line */
  2946. if (info->rtsdtr_inv) {
  2947. cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS);
  2948. } else {
  2949. cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR);
  2950. }
  2951. #ifdef CY_DEBUG_DTR
  2952. printk("cyc:set_line_char dropping DTR\n");
  2953. printk(" status: 0x%x, 0x%x\n",
  2954. cy_readb(base_addr+(CyMSVR1<<index)),
  2955. cy_readb(base_addr+(CyMSVR2<<index)));
  2956. #endif
  2957. }else{
  2958. if (info->rtsdtr_inv) {
  2959. cy_writeb(base_addr+(CyMSVR1<<index), CyRTS);
  2960. } else {
  2961. cy_writeb(base_addr+(CyMSVR2<<index), CyDTR);
  2962. }
  2963. #ifdef CY_DEBUG_DTR
  2964. printk("cyc:set_line_char raising DTR\n");
  2965. printk(" status: 0x%x, 0x%x\n",
  2966. cy_readb(base_addr+(CyMSVR1<<index)),
  2967. cy_readb(base_addr+(CyMSVR2<<index)));
  2968. #endif
  2969. }
  2970. if (info->tty){
  2971. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  2972. }
  2973. CY_UNLOCK(info, flags);
  2974. } else {
  2975. struct FIRM_ID __iomem *firm_id;
  2976. struct ZFW_CTRL __iomem *zfw_ctrl;
  2977. struct BOARD_CTRL __iomem *board_ctrl;
  2978. struct CH_CTRL __iomem *ch_ctrl;
  2979. struct BUF_CTRL __iomem *buf_ctrl;
  2980. uclong sw_flow;
  2981. int retval;
  2982. firm_id = cy_card[card].base_addr + ID_ADDRESS;
  2983. if (!ISZLOADED(cy_card[card])) {
  2984. return;
  2985. }
  2986. zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
  2987. board_ctrl = &zfw_ctrl->board_ctrl;
  2988. ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
  2989. buf_ctrl = &zfw_ctrl->buf_ctrl[channel];
  2990. /* baud rate */
  2991. baud = tty_get_baud_rate(info->tty);
  2992. if ((baud == 38400) &&
  2993. ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
  2994. if (info->custom_divisor)
  2995. baud_rate = info->baud / info->custom_divisor;
  2996. else
  2997. baud_rate = info->baud;
  2998. } else if (baud > CYZ_MAX_SPEED) {
  2999. baud = CYZ_MAX_SPEED;
  3000. }
  3001. cy_writel(&ch_ctrl->comm_baud , baud);
  3002. if (baud == 134) {
  3003. /* get it right for 134.5 baud */
  3004. info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
  3005. } else if ((baud == 38400) &&
  3006. ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
  3007. info->timeout = (info->xmit_fifo_size*HZ*15/baud_rate) + 2;
  3008. } else if (baud) {
  3009. info->timeout = (info->xmit_fifo_size*HZ*15/baud) + 2;
  3010. /* this needs to be propagated into the card info */
  3011. } else {
  3012. info->timeout = 0;
  3013. }
  3014. /* byte size and parity */
  3015. switch(cflag & CSIZE){
  3016. case CS5: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS5); break;
  3017. case CS6: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS6); break;
  3018. case CS7: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS7); break;
  3019. case CS8: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS8); break;
  3020. }
  3021. if(cflag & CSTOPB){
  3022. cy_writel(&ch_ctrl->comm_data_l,
  3023. cy_readl(&ch_ctrl->comm_data_l) | C_DL_2STOP);
  3024. }else{
  3025. cy_writel(&ch_ctrl->comm_data_l,
  3026. cy_readl(&ch_ctrl->comm_data_l) | C_DL_1STOP);
  3027. }
  3028. if (cflag & PARENB){
  3029. if (cflag & PARODD){
  3030. cy_writel(&ch_ctrl->comm_parity , C_PR_ODD);
  3031. }else{
  3032. cy_writel(&ch_ctrl->comm_parity , C_PR_EVEN);
  3033. }
  3034. }else{
  3035. cy_writel(&ch_ctrl->comm_parity , C_PR_NONE);
  3036. }
  3037. /* CTS flow control flag */
  3038. if (cflag & CRTSCTS){
  3039. cy_writel(&ch_ctrl->hw_flow,
  3040. cy_readl(&ch_ctrl->hw_flow) | C_RS_CTS | C_RS_RTS);
  3041. }else{
  3042. cy_writel(&ch_ctrl->hw_flow,
  3043. cy_readl(&ch_ctrl->hw_flow) & ~(C_RS_CTS | C_RS_RTS));
  3044. }
  3045. /* As the HW flow control is done in firmware, the driver doesn't
  3046. need to care about it */
  3047. info->flags &= ~ASYNC_CTS_FLOW;
  3048. /* XON/XOFF/XANY flow control flags */
  3049. sw_flow = 0;
  3050. if (iflag & IXON){
  3051. sw_flow |= C_FL_OXX;
  3052. if (iflag & IXANY)
  3053. sw_flow |= C_FL_OIXANY;
  3054. }
  3055. cy_writel(&ch_ctrl->sw_flow, sw_flow);
  3056. retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L);
  3057. if (retval != 0){
  3058. printk("cyc:set_line_char retval on ttyC%d was %x\n",
  3059. info->line, retval);
  3060. }
  3061. /* CD sensitivity */
  3062. if (cflag & CLOCAL){
  3063. info->flags &= ~ASYNC_CHECK_CD;
  3064. }else{
  3065. info->flags |= ASYNC_CHECK_CD;
  3066. }
  3067. if(baud == 0){ /* baud rate is zero, turn off line */
  3068. cy_writel(&ch_ctrl->rs_control,
  3069. cy_readl(&ch_ctrl->rs_control) & ~C_RS_DTR);
  3070. #ifdef CY_DEBUG_DTR
  3071. printk("cyc:set_line_char dropping Z DTR\n");
  3072. #endif
  3073. }else{
  3074. cy_writel(&ch_ctrl->rs_control,
  3075. cy_readl(&ch_ctrl->rs_control) | C_RS_DTR);
  3076. #ifdef CY_DEBUG_DTR
  3077. printk("cyc:set_line_char raising Z DTR\n");
  3078. #endif
  3079. }
  3080. retval = cyz_issue_cmd( &cy_card[card], channel, C_CM_IOCTLM, 0L);
  3081. if (retval != 0){
  3082. printk("cyc:set_line_char(2) retval on ttyC%d was %x\n",
  3083. info->line, retval);
  3084. }
  3085. if (info->tty){
  3086. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  3087. }
  3088. }
  3089. } /* set_line_char */
  3090. static int
  3091. get_serial_info(struct cyclades_port * info,
  3092. struct serial_struct __user * retinfo)
  3093. {
  3094. struct serial_struct tmp;
  3095. struct cyclades_card *cinfo = &cy_card[info->card];
  3096. if (!retinfo)
  3097. return -EFAULT;
  3098. memset(&tmp, 0, sizeof(tmp));
  3099. tmp.type = info->type;
  3100. tmp.line = info->line;
  3101. tmp.port = info->card * 0x100 + info->line - cinfo->first_line;
  3102. tmp.irq = cinfo->irq;
  3103. tmp.flags = info->flags;
  3104. tmp.close_delay = info->close_delay;
  3105. tmp.baud_base = info->baud;
  3106. tmp.custom_divisor = info->custom_divisor;
  3107. tmp.hub6 = 0; /*!!!*/
  3108. return copy_to_user(retinfo,&tmp,sizeof(*retinfo))?-EFAULT:0;
  3109. } /* get_serial_info */
  3110. static int
  3111. set_serial_info(struct cyclades_port * info,
  3112. struct serial_struct __user * new_info)
  3113. {
  3114. struct serial_struct new_serial;
  3115. struct cyclades_port old_info;
  3116. if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
  3117. return -EFAULT;
  3118. old_info = *info;
  3119. if (!capable(CAP_SYS_ADMIN)) {
  3120. if ((new_serial.close_delay != info->close_delay) ||
  3121. (new_serial.baud_base != info->baud) ||
  3122. ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) !=
  3123. (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)))
  3124. return -EPERM;
  3125. info->flags = ((info->flags & ~ASYNC_USR_MASK) |
  3126. (new_serial.flags & ASYNC_USR_MASK));
  3127. info->baud = new_serial.baud_base;
  3128. info->custom_divisor = new_serial.custom_divisor;
  3129. goto check_and_exit;
  3130. }
  3131. /*
  3132. * OK, past this point, all the error checking has been done.
  3133. * At this point, we start making changes.....
  3134. */
  3135. info->baud = new_serial.baud_base;
  3136. info->custom_divisor = new_serial.custom_divisor;
  3137. info->flags = ((info->flags & ~ASYNC_FLAGS) |
  3138. (new_serial.flags & ASYNC_FLAGS));
  3139. info->close_delay = new_serial.close_delay * HZ/100;
  3140. info->closing_wait = new_serial.closing_wait * HZ/100;
  3141. check_and_exit:
  3142. if (info->flags & ASYNC_INITIALIZED){
  3143. set_line_char(info);
  3144. return 0;
  3145. }else{
  3146. return startup(info);
  3147. }
  3148. } /* set_serial_info */
  3149. /*
  3150. * get_lsr_info - get line status register info
  3151. *
  3152. * Purpose: Let user call ioctl() to get info when the UART physically
  3153. * is emptied. On bus types like RS485, the transmitter must
  3154. * release the bus after transmitting. This must be done when
  3155. * the transmit shift register is empty, not be done when the
  3156. * transmit holding register is empty. This functionality
  3157. * allows an RS485 driver to be written in user space.
  3158. */
  3159. static int get_lsr_info(struct cyclades_port *info, unsigned int __user *value)
  3160. {
  3161. int card, chip, channel, index;
  3162. unsigned char status;
  3163. unsigned int result;
  3164. unsigned long flags;
  3165. void __iomem *base_addr;
  3166. card = info->card;
  3167. channel = (info->line) - (cy_card[card].first_line);
  3168. if (!IS_CYC_Z(cy_card[card])) {
  3169. chip = channel>>2;
  3170. channel &= 0x03;
  3171. index = cy_card[card].bus_index;
  3172. base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
  3173. CY_LOCK(info, flags);
  3174. status = cy_readb(base_addr+(CySRER<<index)) & (CyTxRdy|CyTxMpty);
  3175. CY_UNLOCK(info, flags);
  3176. result = (status ? 0 : TIOCSER_TEMT);
  3177. } else {
  3178. /* Not supported yet */
  3179. return -EINVAL;
  3180. }
  3181. return put_user(result, (unsigned long __user *) value);
  3182. }
  3183. static int
  3184. cy_tiocmget(struct tty_struct *tty, struct file *file)
  3185. {
  3186. struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
  3187. int card,chip,channel,index;
  3188. void __iomem *base_addr;
  3189. unsigned long flags;
  3190. unsigned char status;
  3191. unsigned long lstatus;
  3192. unsigned int result;
  3193. struct FIRM_ID __iomem *firm_id;
  3194. struct ZFW_CTRL __iomem *zfw_ctrl;
  3195. struct BOARD_CTRL __iomem *board_ctrl;
  3196. struct CH_CTRL __iomem *ch_ctrl;
  3197. if (serial_paranoia_check(info, tty->name, __FUNCTION__))
  3198. return -ENODEV;
  3199. card = info->card;
  3200. channel = (info->line) - (cy_card[card].first_line);
  3201. if (!IS_CYC_Z(cy_card[card])) {
  3202. chip = channel>>2;
  3203. channel &= 0x03;
  3204. index = cy_card[card].bus_index;
  3205. base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
  3206. CY_LOCK(info, flags);
  3207. cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
  3208. status = cy_readb(base_addr+(CyMSVR1<<index));
  3209. status |= cy_readb(base_addr+(CyMSVR2<<index));
  3210. CY_UNLOCK(info, flags);
  3211. if (info->rtsdtr_inv) {
  3212. result = ((status & CyRTS) ? TIOCM_DTR : 0)
  3213. | ((status & CyDTR) ? TIOCM_RTS : 0);
  3214. } else {
  3215. result = ((status & CyRTS) ? TIOCM_RTS : 0)
  3216. | ((status & CyDTR) ? TIOCM_DTR : 0);
  3217. }
  3218. result |= ((status & CyDCD) ? TIOCM_CAR : 0)
  3219. | ((status & CyRI) ? TIOCM_RNG : 0)
  3220. | ((status & CyDSR) ? TIOCM_DSR : 0)
  3221. | ((status & CyCTS) ? TIOCM_CTS : 0);
  3222. } else {
  3223. base_addr = cy_card[card].base_addr;
  3224. if (cy_card[card].num_chips != -1){
  3225. return -EINVAL;
  3226. }
  3227. firm_id = cy_card[card].base_addr + ID_ADDRESS;
  3228. if (ISZLOADED(cy_card[card])) {
  3229. zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
  3230. board_ctrl = &zfw_ctrl->board_ctrl;
  3231. ch_ctrl = zfw_ctrl->ch_ctrl;
  3232. lstatus = cy_readl(&ch_ctrl[channel].rs_status);
  3233. result = ((lstatus & C_RS_RTS) ? TIOCM_RTS : 0)
  3234. | ((lstatus & C_RS_DTR) ? TIOCM_DTR : 0)
  3235. | ((lstatus & C_RS_DCD) ? TIOCM_CAR : 0)
  3236. | ((lstatus & C_RS_RI) ? TIOCM_RNG : 0)
  3237. | ((lstatus & C_RS_DSR) ? TIOCM_DSR : 0)
  3238. | ((lstatus & C_RS_CTS) ? TIOCM_CTS : 0);
  3239. }else{
  3240. result = 0;
  3241. return -ENODEV;
  3242. }
  3243. }
  3244. return result;
  3245. } /* cy_tiomget */
  3246. static int
  3247. cy_tiocmset(struct tty_struct *tty, struct file *file,
  3248. unsigned int set, unsigned int clear)
  3249. {
  3250. struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
  3251. int card,chip,channel,index;
  3252. void __iomem *base_addr;
  3253. unsigned long flags;
  3254. struct FIRM_ID __iomem *firm_id;
  3255. struct ZFW_CTRL __iomem *zfw_ctrl;
  3256. struct BOARD_CTRL __iomem *board_ctrl;
  3257. struct CH_CTRL __iomem *ch_ctrl;
  3258. int retval;
  3259. if (serial_paranoia_check(info, tty->name, __FUNCTION__))
  3260. return -ENODEV;
  3261. card = info->card;
  3262. channel = (info->line) - (cy_card[card].first_line);
  3263. if (!IS_CYC_Z(cy_card[card])) {
  3264. chip = channel>>2;
  3265. channel &= 0x03;
  3266. index = cy_card[card].bus_index;
  3267. base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
  3268. if (set & TIOCM_RTS){
  3269. CY_LOCK(info, flags);
  3270. cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
  3271. if (info->rtsdtr_inv) {
  3272. cy_writeb(base_addr+(CyMSVR2<<index), CyDTR);
  3273. } else {
  3274. cy_writeb(base_addr+(CyMSVR1<<index), CyRTS);
  3275. }
  3276. CY_UNLOCK(info, flags);
  3277. }
  3278. if (clear & TIOCM_RTS) {
  3279. CY_LOCK(info, flags);
  3280. cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
  3281. if (info->rtsdtr_inv) {
  3282. cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR);
  3283. } else {
  3284. cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS);
  3285. }
  3286. CY_UNLOCK(info, flags);
  3287. }
  3288. if (set & TIOCM_DTR){
  3289. CY_LOCK(info, flags);
  3290. cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
  3291. if (info->rtsdtr_inv) {
  3292. cy_writeb(base_addr+(CyMSVR1<<index), CyRTS);
  3293. } else {
  3294. cy_writeb(base_addr+(CyMSVR2<<index), CyDTR);
  3295. }
  3296. #ifdef CY_DEBUG_DTR
  3297. printk("cyc:set_modem_info raising DTR\n");
  3298. printk(" status: 0x%x, 0x%x\n",
  3299. cy_readb(base_addr+(CyMSVR1<<index)),
  3300. cy_readb(base_addr+(CyMSVR2<<index)));
  3301. #endif
  3302. CY_UNLOCK(info, flags);
  3303. }
  3304. if (clear & TIOCM_DTR) {
  3305. CY_LOCK(info, flags);
  3306. cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
  3307. if (info->rtsdtr_inv) {
  3308. cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS);
  3309. } else {
  3310. cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR);
  3311. }
  3312. #ifdef CY_DEBUG_DTR
  3313. printk("cyc:set_modem_info dropping DTR\n");
  3314. printk(" status: 0x%x, 0x%x\n",
  3315. cy_readb(base_addr+(CyMSVR1<<index)),
  3316. cy_readb(base_addr+(CyMSVR2<<index)));
  3317. #endif
  3318. CY_UNLOCK(info, flags);
  3319. }
  3320. } else {
  3321. base_addr = cy_card[card].base_addr;
  3322. firm_id = cy_card[card].base_addr + ID_ADDRESS;
  3323. if (ISZLOADED(cy_card[card])) {
  3324. zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
  3325. board_ctrl = &zfw_ctrl->board_ctrl;
  3326. ch_ctrl = zfw_ctrl->ch_ctrl;
  3327. if (set & TIOCM_RTS){
  3328. CY_LOCK(info, flags);
  3329. cy_writel(&ch_ctrl[channel].rs_control,
  3330. cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS);
  3331. CY_UNLOCK(info, flags);
  3332. }
  3333. if (clear & TIOCM_RTS) {
  3334. CY_LOCK(info, flags);
  3335. cy_writel(&ch_ctrl[channel].rs_control,
  3336. cy_readl(&ch_ctrl[channel].rs_control) & ~C_RS_RTS);
  3337. CY_UNLOCK(info, flags);
  3338. }
  3339. if (set & TIOCM_DTR){
  3340. CY_LOCK(info, flags);
  3341. cy_writel(&ch_ctrl[channel].rs_control,
  3342. cy_readl(&ch_ctrl[channel].rs_control) | C_RS_DTR);
  3343. #ifdef CY_DEBUG_DTR
  3344. printk("cyc:set_modem_info raising Z DTR\n");
  3345. #endif
  3346. CY_UNLOCK(info, flags);
  3347. }
  3348. if (clear & TIOCM_DTR) {
  3349. CY_LOCK(info, flags);
  3350. cy_writel(&ch_ctrl[channel].rs_control,
  3351. cy_readl(&ch_ctrl[channel].rs_control) & ~C_RS_DTR);
  3352. #ifdef CY_DEBUG_DTR
  3353. printk("cyc:set_modem_info clearing Z DTR\n");
  3354. #endif
  3355. CY_UNLOCK(info, flags);
  3356. }
  3357. }else{
  3358. return -ENODEV;
  3359. }
  3360. CY_LOCK(info, flags);
  3361. retval = cyz_issue_cmd(&cy_card[info->card],
  3362. channel, C_CM_IOCTLM,0L);
  3363. if (retval != 0){
  3364. printk("cyc:set_modem_info retval on ttyC%d was %x\n",
  3365. info->line, retval);
  3366. }
  3367. CY_UNLOCK(info, flags);
  3368. }
  3369. return 0;
  3370. } /* cy_tiocmset */
  3371. /*
  3372. * cy_break() --- routine which turns the break handling on or off
  3373. */
  3374. static void
  3375. cy_break(struct tty_struct *tty, int break_state)
  3376. {
  3377. struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
  3378. unsigned long flags;
  3379. if (serial_paranoia_check(info, tty->name, "cy_break"))
  3380. return;
  3381. CY_LOCK(info, flags);
  3382. if (!IS_CYC_Z(cy_card[info->card])) {
  3383. /* Let the transmit ISR take care of this (since it
  3384. requires stuffing characters into the output stream).
  3385. */
  3386. if (break_state == -1) {
  3387. if (!info->breakon) {
  3388. info->breakon = 1;
  3389. if (!info->xmit_cnt) {
  3390. CY_UNLOCK(info, flags);
  3391. start_xmit(info);
  3392. CY_LOCK(info, flags);
  3393. }
  3394. }
  3395. } else {
  3396. if (!info->breakoff) {
  3397. info->breakoff = 1;
  3398. if (!info->xmit_cnt) {
  3399. CY_UNLOCK(info, flags);
  3400. start_xmit(info);
  3401. CY_LOCK(info, flags);
  3402. }
  3403. }
  3404. }
  3405. } else {
  3406. int retval;
  3407. if (break_state == -1) {
  3408. retval = cyz_issue_cmd(&cy_card[info->card],
  3409. (info->line) - (cy_card[info->card].first_line),
  3410. C_CM_SET_BREAK, 0L);
  3411. if (retval != 0) {
  3412. printk("cyc:cy_break (set) retval on ttyC%d was %x\n",
  3413. info->line, retval);
  3414. }
  3415. } else {
  3416. retval = cyz_issue_cmd(&cy_card[info->card],
  3417. (info->line) - (cy_card[info->card].first_line),
  3418. C_CM_CLR_BREAK, 0L);
  3419. if (retval != 0) {
  3420. printk("cyc:cy_break (clr) retval on ttyC%d was %x\n",
  3421. info->line, retval);
  3422. }
  3423. }
  3424. }
  3425. CY_UNLOCK(info, flags);
  3426. } /* cy_break */
  3427. static int
  3428. get_mon_info(struct cyclades_port * info, struct cyclades_monitor __user * mon)
  3429. {
  3430. if(copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
  3431. return -EFAULT;
  3432. info->mon.int_count = 0;
  3433. info->mon.char_count = 0;
  3434. info->mon.char_max = 0;
  3435. info->mon.char_last = 0;
  3436. return 0;
  3437. }/* get_mon_info */
  3438. static int
  3439. set_threshold(struct cyclades_port * info, unsigned long value)
  3440. {
  3441. void __iomem *base_addr;
  3442. int card,channel,chip,index;
  3443. unsigned long flags;
  3444. card = info->card;
  3445. channel = info->line - cy_card[card].first_line;
  3446. if (!IS_CYC_Z(cy_card[card])) {
  3447. chip = channel>>2;
  3448. channel &= 0x03;
  3449. index = cy_card[card].bus_index;
  3450. base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
  3451. info->cor3 &= ~CyREC_FIFO;
  3452. info->cor3 |= value & CyREC_FIFO;
  3453. CY_LOCK(info, flags);
  3454. cy_writeb(base_addr+(CyCOR3<<index), info->cor3);
  3455. cyy_issue_cmd(base_addr,CyCOR_CHANGE|CyCOR3ch,index);
  3456. CY_UNLOCK(info, flags);
  3457. } else {
  3458. // Nothing to do!
  3459. }
  3460. return 0;
  3461. }/* set_threshold */
  3462. static int
  3463. get_threshold(struct cyclades_port * info, unsigned long __user *value)
  3464. {
  3465. void __iomem *base_addr;
  3466. int card,channel,chip,index;
  3467. unsigned long tmp;
  3468. card = info->card;
  3469. channel = info->line - cy_card[card].first_line;
  3470. if (!IS_CYC_Z(cy_card[card])) {
  3471. chip = channel>>2;
  3472. channel &= 0x03;
  3473. index = cy_card[card].bus_index;
  3474. base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
  3475. tmp = cy_readb(base_addr+(CyCOR3<<index)) & CyREC_FIFO;
  3476. return put_user(tmp,value);
  3477. } else {
  3478. // Nothing to do!
  3479. return 0;
  3480. }
  3481. }/* get_threshold */
  3482. static int
  3483. set_default_threshold(struct cyclades_port * info, unsigned long value)
  3484. {
  3485. info->default_threshold = value & 0x0f;
  3486. return 0;
  3487. }/* set_default_threshold */
  3488. static int
  3489. get_default_threshold(struct cyclades_port * info, unsigned long __user *value)
  3490. {
  3491. return put_user(info->default_threshold,value);
  3492. }/* get_default_threshold */
  3493. static int
  3494. set_timeout(struct cyclades_port * info, unsigned long value)
  3495. {
  3496. void __iomem *base_addr;
  3497. int card,channel,chip,index;
  3498. unsigned long flags;
  3499. card = info->card;
  3500. channel = info->line - cy_card[card].first_line;
  3501. if (!IS_CYC_Z(cy_card[card])) {
  3502. chip = channel>>2;
  3503. channel &= 0x03;
  3504. index = cy_card[card].bus_index;
  3505. base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
  3506. CY_LOCK(info, flags);
  3507. cy_writeb(base_addr+(CyRTPR<<index), value & 0xff);
  3508. CY_UNLOCK(info, flags);
  3509. } else {
  3510. // Nothing to do!
  3511. }
  3512. return 0;
  3513. }/* set_timeout */
  3514. static int
  3515. get_timeout(struct cyclades_port * info, unsigned long __user *value)
  3516. {
  3517. void __iomem *base_addr;
  3518. int card,channel,chip,index;
  3519. unsigned long tmp;
  3520. card = info->card;
  3521. channel = info->line - cy_card[card].first_line;
  3522. if (!IS_CYC_Z(cy_card[card])) {
  3523. chip = channel>>2;
  3524. channel &= 0x03;
  3525. index = cy_card[card].bus_index;
  3526. base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
  3527. tmp = cy_readb(base_addr+(CyRTPR<<index));
  3528. return put_user(tmp,value);
  3529. } else {
  3530. // Nothing to do!
  3531. return 0;
  3532. }
  3533. }/* get_timeout */
  3534. static int
  3535. set_default_timeout(struct cyclades_port * info, unsigned long value)
  3536. {
  3537. info->default_timeout = value & 0xff;
  3538. return 0;
  3539. }/* set_default_timeout */
  3540. static int
  3541. get_default_timeout(struct cyclades_port * info, unsigned long __user *value)
  3542. {
  3543. return put_user(info->default_timeout,value);
  3544. }/* get_default_timeout */
  3545. /*
  3546. * This routine allows the tty driver to implement device-
  3547. * specific ioctl's. If the ioctl number passed in cmd is
  3548. * not recognized by the driver, it should return ENOIOCTLCMD.
  3549. */
  3550. static int
  3551. cy_ioctl(struct tty_struct *tty, struct file * file,
  3552. unsigned int cmd, unsigned long arg)
  3553. {
  3554. struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
  3555. struct cyclades_icount cprev, cnow; /* kernel counter temps */
  3556. struct serial_icounter_struct __user *p_cuser; /* user space */
  3557. int ret_val = 0;
  3558. unsigned long flags;
  3559. void __user *argp = (void __user *)arg;
  3560. if (serial_paranoia_check(info, tty->name, "cy_ioctl"))
  3561. return -ENODEV;
  3562. #ifdef CY_DEBUG_OTHER
  3563. printk("cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n",
  3564. info->line, cmd, arg); /* */
  3565. #endif
  3566. switch (cmd) {
  3567. case CYGETMON:
  3568. ret_val = get_mon_info(info, argp);
  3569. break;
  3570. case CYGETTHRESH:
  3571. ret_val = get_threshold(info, argp);
  3572. break;
  3573. case CYSETTHRESH:
  3574. ret_val = set_threshold(info, arg);
  3575. break;
  3576. case CYGETDEFTHRESH:
  3577. ret_val = get_default_threshold(info, argp);
  3578. break;
  3579. case CYSETDEFTHRESH:
  3580. ret_val = set_default_threshold(info, arg);
  3581. break;
  3582. case CYGETTIMEOUT:
  3583. ret_val = get_timeout(info, argp);
  3584. break;
  3585. case CYSETTIMEOUT:
  3586. ret_val = set_timeout(info, arg);
  3587. break;
  3588. case CYGETDEFTIMEOUT:
  3589. ret_val = get_default_timeout(info, argp);
  3590. break;
  3591. case CYSETDEFTIMEOUT:
  3592. ret_val = set_default_timeout(info, arg);
  3593. break;
  3594. case CYSETRFLOW:
  3595. info->rflow = (int)arg;
  3596. ret_val = 0;
  3597. break;
  3598. case CYGETRFLOW:
  3599. ret_val = info->rflow;
  3600. break;
  3601. case CYSETRTSDTR_INV:
  3602. info->rtsdtr_inv = (int)arg;
  3603. ret_val = 0;
  3604. break;
  3605. case CYGETRTSDTR_INV:
  3606. ret_val = info->rtsdtr_inv;
  3607. break;
  3608. case CYGETCARDINFO:
  3609. if (copy_to_user(argp, &cy_card[info->card],
  3610. sizeof (struct cyclades_card))) {
  3611. ret_val = -EFAULT;
  3612. break;
  3613. }
  3614. ret_val = 0;
  3615. break;
  3616. case CYGETCD1400VER:
  3617. ret_val = info->chip_rev;
  3618. break;
  3619. #ifndef CONFIG_CYZ_INTR
  3620. case CYZSETPOLLCYCLE:
  3621. cyz_polling_cycle = (arg * HZ) / 1000;
  3622. ret_val = 0;
  3623. break;
  3624. case CYZGETPOLLCYCLE:
  3625. ret_val = (cyz_polling_cycle * 1000) / HZ;
  3626. break;
  3627. #endif /* CONFIG_CYZ_INTR */
  3628. case CYSETWAIT:
  3629. info->closing_wait = (unsigned short)arg * HZ/100;
  3630. ret_val = 0;
  3631. break;
  3632. case CYGETWAIT:
  3633. ret_val = info->closing_wait / (HZ/100);
  3634. break;
  3635. case TIOCGSERIAL:
  3636. ret_val = get_serial_info(info, argp);
  3637. break;
  3638. case TIOCSSERIAL:
  3639. ret_val = set_serial_info(info, argp);
  3640. break;
  3641. case TIOCSERGETLSR: /* Get line status register */
  3642. ret_val = get_lsr_info(info, argp);
  3643. break;
  3644. /*
  3645. * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
  3646. * - mask passed in arg for lines of interest
  3647. * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
  3648. * Caller should use TIOCGICOUNT to see which one it was
  3649. */
  3650. case TIOCMIWAIT:
  3651. CY_LOCK(info, flags);
  3652. /* note the counters on entry */
  3653. cprev = info->icount;
  3654. CY_UNLOCK(info, flags);
  3655. while (1) {
  3656. interruptible_sleep_on(&info->delta_msr_wait);
  3657. /* see if a signal did it */
  3658. if (signal_pending(current)) {
  3659. return -ERESTARTSYS;
  3660. }
  3661. CY_LOCK(info, flags);
  3662. cnow = info->icount; /* atomic copy */
  3663. CY_UNLOCK(info, flags);
  3664. if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
  3665. cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
  3666. return -EIO; /* no change => error */
  3667. }
  3668. if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
  3669. ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
  3670. ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
  3671. ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
  3672. return 0;
  3673. }
  3674. cprev = cnow;
  3675. }
  3676. /* NOTREACHED */
  3677. /*
  3678. * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
  3679. * Return: write counters to the user passed counter struct
  3680. * NB: both 1->0 and 0->1 transitions are counted except for
  3681. * RI where only 0->1 is counted.
  3682. */
  3683. case TIOCGICOUNT:
  3684. CY_LOCK(info, flags);
  3685. cnow = info->icount;
  3686. CY_UNLOCK(info, flags);
  3687. p_cuser = argp;
  3688. ret_val = put_user(cnow.cts, &p_cuser->cts);
  3689. if (ret_val) return ret_val;
  3690. ret_val = put_user(cnow.dsr, &p_cuser->dsr);
  3691. if (ret_val) return ret_val;
  3692. ret_val = put_user(cnow.rng, &p_cuser->rng);
  3693. if (ret_val) return ret_val;
  3694. ret_val = put_user(cnow.dcd, &p_cuser->dcd);
  3695. if (ret_val) return ret_val;
  3696. ret_val = put_user(cnow.rx, &p_cuser->rx);
  3697. if (ret_val) return ret_val;
  3698. ret_val = put_user(cnow.tx, &p_cuser->tx);
  3699. if (ret_val) return ret_val;
  3700. ret_val = put_user(cnow.frame, &p_cuser->frame);
  3701. if (ret_val) return ret_val;
  3702. ret_val = put_user(cnow.overrun, &p_cuser->overrun);
  3703. if (ret_val) return ret_val;
  3704. ret_val = put_user(cnow.parity, &p_cuser->parity);
  3705. if (ret_val) return ret_val;
  3706. ret_val = put_user(cnow.brk, &p_cuser->brk);
  3707. if (ret_val) return ret_val;
  3708. ret_val = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
  3709. if (ret_val) return ret_val;
  3710. ret_val = 0;
  3711. break;
  3712. default:
  3713. ret_val = -ENOIOCTLCMD;
  3714. }
  3715. #ifdef CY_DEBUG_OTHER
  3716. printk(" cyc:cy_ioctl done\n");
  3717. #endif
  3718. return ret_val;
  3719. } /* cy_ioctl */
  3720. /*
  3721. * This routine allows the tty driver to be notified when
  3722. * device's termios settings have changed. Note that a
  3723. * well-designed tty driver should be prepared to accept the case
  3724. * where old == NULL, and try to do something rational.
  3725. */
  3726. static void
  3727. cy_set_termios(struct tty_struct *tty, struct termios * old_termios)
  3728. {
  3729. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  3730. #ifdef CY_DEBUG_OTHER
  3731. printk("cyc:cy_set_termios ttyC%d\n", info->line);
  3732. #endif
  3733. if ((tty->termios->c_cflag == old_termios->c_cflag) &&
  3734. ((tty->termios->c_iflag & (IXON|IXANY)) ==
  3735. (old_termios->c_iflag & (IXON|IXANY))))
  3736. return;
  3737. set_line_char(info);
  3738. if ((old_termios->c_cflag & CRTSCTS) &&
  3739. !(tty->termios->c_cflag & CRTSCTS)) {
  3740. tty->hw_stopped = 0;
  3741. cy_start(tty);
  3742. }
  3743. #if 0
  3744. /*
  3745. * No need to wake up processes in open wait, since they
  3746. * sample the CLOCAL flag once, and don't recheck it.
  3747. * XXX It's not clear whether the current behavior is correct
  3748. * or not. Hence, this may change.....
  3749. */
  3750. if (!(old_termios->c_cflag & CLOCAL) &&
  3751. (tty->termios->c_cflag & CLOCAL))
  3752. wake_up_interruptible(&info->open_wait);
  3753. #endif
  3754. return;
  3755. } /* cy_set_termios */
  3756. /* This function is used to send a high-priority XON/XOFF character to
  3757. the device.
  3758. */
  3759. static void
  3760. cy_send_xchar (struct tty_struct *tty, char ch)
  3761. {
  3762. struct cyclades_port *info = (struct cyclades_port *) tty->driver_data;
  3763. int card, channel;
  3764. if (serial_paranoia_check (info, tty->name, "cy_send_xchar"))
  3765. return;
  3766. info->x_char = ch;
  3767. if (ch)
  3768. cy_start (tty);
  3769. card = info->card;
  3770. channel = info->line - cy_card[card].first_line;
  3771. if (IS_CYC_Z (cy_card[card])) {
  3772. if (ch == STOP_CHAR (tty))
  3773. cyz_issue_cmd (&cy_card[card], channel, C_CM_SENDXOFF, 0L);
  3774. else if (ch == START_CHAR (tty))
  3775. cyz_issue_cmd (&cy_card[card], channel, C_CM_SENDXON, 0L);
  3776. }
  3777. }
  3778. /* This routine is called by the upper-layer tty layer to signal
  3779. that incoming characters should be throttled because the input
  3780. buffers are close to full.
  3781. */
  3782. static void
  3783. cy_throttle(struct tty_struct * tty)
  3784. {
  3785. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  3786. unsigned long flags;
  3787. void __iomem *base_addr;
  3788. int card,chip,channel,index;
  3789. #ifdef CY_DEBUG_THROTTLE
  3790. char buf[64];
  3791. printk("cyc:throttle %s: %d....ttyC%d\n",
  3792. tty_name(tty, buf),
  3793. tty->ldisc.chars_in_buffer(tty), info->line);
  3794. #endif
  3795. if (serial_paranoia_check(info, tty->name, "cy_throttle")){
  3796. return;
  3797. }
  3798. card = info->card;
  3799. if (I_IXOFF(tty)) {
  3800. if (!IS_CYC_Z (cy_card[card]))
  3801. cy_send_xchar (tty, STOP_CHAR (tty));
  3802. else
  3803. info->throttle = 1;
  3804. }
  3805. if (tty->termios->c_cflag & CRTSCTS) {
  3806. channel = info->line - cy_card[card].first_line;
  3807. if (!IS_CYC_Z(cy_card[card])) {
  3808. chip = channel>>2;
  3809. channel &= 0x03;
  3810. index = cy_card[card].bus_index;
  3811. base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
  3812. CY_LOCK(info, flags);
  3813. cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
  3814. if (info->rtsdtr_inv) {
  3815. cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR);
  3816. } else {
  3817. cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS);
  3818. }
  3819. CY_UNLOCK(info, flags);
  3820. } else {
  3821. info->throttle = 1;
  3822. }
  3823. }
  3824. return;
  3825. } /* cy_throttle */
  3826. /*
  3827. * This routine notifies the tty driver that it should signal
  3828. * that characters can now be sent to the tty without fear of
  3829. * overrunning the input buffers of the line disciplines.
  3830. */
  3831. static void
  3832. cy_unthrottle(struct tty_struct * tty)
  3833. {
  3834. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  3835. unsigned long flags;
  3836. void __iomem *base_addr;
  3837. int card,chip,channel,index;
  3838. #ifdef CY_DEBUG_THROTTLE
  3839. char buf[64];
  3840. printk("cyc:unthrottle %s: %d....ttyC%d\n",
  3841. tty_name(tty, buf),
  3842. tty->ldisc.chars_in_buffer(tty), info->line);
  3843. #endif
  3844. if (serial_paranoia_check(info, tty->name, "cy_unthrottle")){
  3845. return;
  3846. }
  3847. if (I_IXOFF(tty)) {
  3848. if (info->x_char)
  3849. info->x_char = 0;
  3850. else
  3851. cy_send_xchar (tty, START_CHAR (tty));
  3852. }
  3853. if (tty->termios->c_cflag & CRTSCTS) {
  3854. card = info->card;
  3855. channel = info->line - cy_card[card].first_line;
  3856. if (!IS_CYC_Z(cy_card[card])) {
  3857. chip = channel>>2;
  3858. channel &= 0x03;
  3859. index = cy_card[card].bus_index;
  3860. base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
  3861. CY_LOCK(info, flags);
  3862. cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
  3863. if (info->rtsdtr_inv) {
  3864. cy_writeb(base_addr+(CyMSVR2<<index), CyDTR);
  3865. } else {
  3866. cy_writeb(base_addr+(CyMSVR1<<index), CyRTS);
  3867. }
  3868. CY_UNLOCK(info, flags);
  3869. } else {
  3870. info->throttle = 0;
  3871. }
  3872. }
  3873. return;
  3874. } /* cy_unthrottle */
  3875. /* cy_start and cy_stop provide software output flow control as a
  3876. function of XON/XOFF, software CTS, and other such stuff.
  3877. */
  3878. static void
  3879. cy_stop(struct tty_struct *tty)
  3880. {
  3881. struct cyclades_card *cinfo;
  3882. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  3883. void __iomem *base_addr;
  3884. int chip,channel,index;
  3885. unsigned long flags;
  3886. #ifdef CY_DEBUG_OTHER
  3887. printk("cyc:cy_stop ttyC%d\n", info->line); /* */
  3888. #endif
  3889. if (serial_paranoia_check(info, tty->name, "cy_stop"))
  3890. return;
  3891. cinfo = &cy_card[info->card];
  3892. channel = info->line - cinfo->first_line;
  3893. if (!IS_CYC_Z(*cinfo)) {
  3894. index = cinfo->bus_index;
  3895. chip = channel>>2;
  3896. channel &= 0x03;
  3897. base_addr = cy_card[info->card].base_addr + (cy_chip_offset[chip]<<index);
  3898. CY_LOCK(info, flags);
  3899. cy_writeb(base_addr+(CyCAR<<index),
  3900. (u_char)(channel & 0x0003)); /* index channel */
  3901. cy_writeb(base_addr+(CySRER<<index),
  3902. cy_readb(base_addr+(CySRER<<index)) & ~CyTxRdy);
  3903. CY_UNLOCK(info, flags);
  3904. } else {
  3905. // Nothing to do!
  3906. }
  3907. return;
  3908. } /* cy_stop */
  3909. static void
  3910. cy_start(struct tty_struct *tty)
  3911. {
  3912. struct cyclades_card *cinfo;
  3913. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  3914. void __iomem *base_addr;
  3915. int chip,channel,index;
  3916. unsigned long flags;
  3917. #ifdef CY_DEBUG_OTHER
  3918. printk("cyc:cy_start ttyC%d\n", info->line); /* */
  3919. #endif
  3920. if (serial_paranoia_check(info, tty->name, "cy_start"))
  3921. return;
  3922. cinfo = &cy_card[info->card];
  3923. channel = info->line - cinfo->first_line;
  3924. index = cinfo->bus_index;
  3925. if (!IS_CYC_Z(*cinfo)) {
  3926. chip = channel>>2;
  3927. channel &= 0x03;
  3928. base_addr = cy_card[info->card].base_addr + (cy_chip_offset[chip]<<index);
  3929. CY_LOCK(info, flags);
  3930. cy_writeb(base_addr+(CyCAR<<index),
  3931. (u_char)(channel & 0x0003)); /* index channel */
  3932. cy_writeb(base_addr+(CySRER<<index),
  3933. cy_readb(base_addr+(CySRER<<index)) | CyTxRdy);
  3934. CY_UNLOCK(info, flags);
  3935. } else {
  3936. // Nothing to do!
  3937. }
  3938. return;
  3939. } /* cy_start */
  3940. static void
  3941. cy_flush_buffer(struct tty_struct *tty)
  3942. {
  3943. struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
  3944. int card, channel, retval;
  3945. unsigned long flags;
  3946. #ifdef CY_DEBUG_IO
  3947. printk("cyc:cy_flush_buffer ttyC%d\n", info->line); /* */
  3948. #endif
  3949. if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
  3950. return;
  3951. card = info->card;
  3952. channel = (info->line) - (cy_card[card].first_line);
  3953. CY_LOCK(info, flags);
  3954. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  3955. CY_UNLOCK(info, flags);
  3956. if (IS_CYC_Z(cy_card[card])) { /* If it is a Z card, flush the on-board
  3957. buffers as well */
  3958. CY_LOCK(info, flags);
  3959. retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_TX, 0L);
  3960. if (retval != 0) {
  3961. printk("cyc: flush_buffer retval on ttyC%d was %x\n",
  3962. info->line, retval);
  3963. }
  3964. CY_UNLOCK(info, flags);
  3965. }
  3966. tty_wakeup(tty);
  3967. wake_up_interruptible(&tty->write_wait);
  3968. } /* cy_flush_buffer */
  3969. /*
  3970. * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
  3971. */
  3972. static void
  3973. cy_hangup(struct tty_struct *tty)
  3974. {
  3975. struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
  3976. #ifdef CY_DEBUG_OTHER
  3977. printk("cyc:cy_hangup ttyC%d\n", info->line); /* */
  3978. #endif
  3979. if (serial_paranoia_check(info, tty->name, "cy_hangup"))
  3980. return;
  3981. cy_flush_buffer(tty);
  3982. shutdown(info);
  3983. info->event = 0;
  3984. info->count = 0;
  3985. #ifdef CY_DEBUG_COUNT
  3986. printk("cyc:cy_hangup (%d): setting count to 0\n", current->pid);
  3987. #endif
  3988. info->tty = NULL;
  3989. info->flags &= ~ASYNC_NORMAL_ACTIVE;
  3990. wake_up_interruptible(&info->open_wait);
  3991. } /* cy_hangup */
  3992. /*
  3993. * ---------------------------------------------------------------------
  3994. * cy_init() and friends
  3995. *
  3996. * cy_init() is called at boot-time to initialize the serial driver.
  3997. * ---------------------------------------------------------------------
  3998. */
  3999. /* initialize chips on Cyclom-Y card -- return number of valid
  4000. chips (which is number of ports/4) */
  4001. static unsigned short __init
  4002. cyy_init_card(void __iomem *true_base_addr,int index)
  4003. {
  4004. unsigned int chip_number;
  4005. void __iomem *base_addr;
  4006. cy_writeb(true_base_addr+(Cy_HwReset<<index), 0);
  4007. /* Cy_HwReset is 0x1400 */
  4008. cy_writeb(true_base_addr+(Cy_ClrIntr<<index), 0);
  4009. /* Cy_ClrIntr is 0x1800 */
  4010. udelay(500L);
  4011. for(chip_number=0; chip_number<CyMAX_CHIPS_PER_CARD; chip_number++){
  4012. base_addr = true_base_addr + (cy_chip_offset[chip_number]<<index);
  4013. mdelay(1);
  4014. if(cy_readb(base_addr+(CyCCR<<index)) != 0x00){
  4015. /*************
  4016. printk(" chip #%d at %#6lx is never idle (CCR != 0)\n",
  4017. chip_number, (unsigned long)base_addr);
  4018. *************/
  4019. return chip_number;
  4020. }
  4021. cy_writeb(base_addr+(CyGFRCR<<index), 0);
  4022. udelay(10L);
  4023. /* The Cyclom-16Y does not decode address bit 9 and therefore
  4024. cannot distinguish between references to chip 0 and a non-
  4025. existent chip 4. If the preceding clearing of the supposed
  4026. chip 4 GFRCR register appears at chip 0, there is no chip 4
  4027. and this must be a Cyclom-16Y, not a Cyclom-32Ye.
  4028. */
  4029. if (chip_number == 4
  4030. && cy_readb(true_base_addr
  4031. + (cy_chip_offset[0]<<index)
  4032. + (CyGFRCR<<index)) == 0){
  4033. return chip_number;
  4034. }
  4035. cy_writeb(base_addr+(CyCCR<<index), CyCHIP_RESET);
  4036. mdelay(1);
  4037. if(cy_readb(base_addr+(CyGFRCR<<index)) == 0x00){
  4038. /*
  4039. printk(" chip #%d at %#6lx is not responding ",
  4040. chip_number, (unsigned long)base_addr);
  4041. printk("(GFRCR stayed 0)\n",
  4042. */
  4043. return chip_number;
  4044. }
  4045. if((0xf0 & (cy_readb(base_addr+(CyGFRCR<<index)))) != 0x40){
  4046. /*
  4047. printk(" chip #%d at %#6lx is not valid (GFRCR == %#2x)\n",
  4048. chip_number, (unsigned long)base_addr,
  4049. base_addr[CyGFRCR<<index]);
  4050. */
  4051. return chip_number;
  4052. }
  4053. cy_writeb(base_addr+(CyGCR<<index), CyCH0_SERIAL);
  4054. if (cy_readb(base_addr+(CyGFRCR<<index)) >= CD1400_REV_J){
  4055. /* It is a CD1400 rev. J or later */
  4056. /* Impossible to reach 5ms with this chip.
  4057. Changed to 2ms instead (f = 500 Hz). */
  4058. cy_writeb(base_addr+(CyPPR<<index), CyCLOCK_60_2MS);
  4059. } else {
  4060. /* f = 200 Hz */
  4061. cy_writeb(base_addr+(CyPPR<<index), CyCLOCK_25_5MS);
  4062. }
  4063. /*
  4064. printk(" chip #%d at %#6lx is rev 0x%2x\n",
  4065. chip_number, (unsigned long)base_addr,
  4066. cy_readb(base_addr+(CyGFRCR<<index)));
  4067. */
  4068. }
  4069. return chip_number;
  4070. } /* cyy_init_card */
  4071. /*
  4072. * ---------------------------------------------------------------------
  4073. * cy_detect_isa() - Probe for Cyclom-Y/ISA boards.
  4074. * sets global variables and return the number of ISA boards found.
  4075. * ---------------------------------------------------------------------
  4076. */
  4077. static int __init
  4078. cy_detect_isa(void)
  4079. {
  4080. #ifdef CONFIG_ISA
  4081. unsigned short cy_isa_irq,nboard;
  4082. void __iomem *cy_isa_address;
  4083. unsigned short i,j,cy_isa_nchan;
  4084. #ifdef MODULE
  4085. int isparam = 0;
  4086. #endif
  4087. nboard = 0;
  4088. #ifdef MODULE
  4089. /* Check for module parameters */
  4090. for(i = 0 ; i < NR_CARDS; i++) {
  4091. if (maddr[i] || i) {
  4092. isparam = 1;
  4093. cy_isa_addresses[i] = maddr[i];
  4094. }
  4095. if (!maddr[i])
  4096. break;
  4097. }
  4098. #endif
  4099. /* scan the address table probing for Cyclom-Y/ISA boards */
  4100. for (i = 0 ; i < NR_ISA_ADDRS ; i++) {
  4101. unsigned int isa_address = cy_isa_addresses[i];
  4102. if (isa_address == 0x0000) {
  4103. return(nboard);
  4104. }
  4105. /* probe for CD1400... */
  4106. cy_isa_address = ioremap(isa_address, CyISA_Ywin);
  4107. cy_isa_nchan = CyPORTS_PER_CHIP *
  4108. cyy_init_card(cy_isa_address,0);
  4109. if (cy_isa_nchan == 0) {
  4110. continue;
  4111. }
  4112. #ifdef MODULE
  4113. if (isparam && irq[i])
  4114. cy_isa_irq = irq[i];
  4115. else
  4116. #endif
  4117. /* find out the board's irq by probing */
  4118. cy_isa_irq = detect_isa_irq(cy_isa_address);
  4119. if (cy_isa_irq == 0) {
  4120. printk("Cyclom-Y/ISA found at 0x%lx ",
  4121. (unsigned long) cy_isa_address);
  4122. printk("but the IRQ could not be detected.\n");
  4123. continue;
  4124. }
  4125. if((cy_next_channel+cy_isa_nchan) > NR_PORTS) {
  4126. printk("Cyclom-Y/ISA found at 0x%lx ",
  4127. (unsigned long) cy_isa_address);
  4128. printk("but no more channels are available.\n");
  4129. printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
  4130. return(nboard);
  4131. }
  4132. /* fill the next cy_card structure available */
  4133. for (j = 0 ; j < NR_CARDS ; j++) {
  4134. if (cy_card[j].base_addr == 0) break;
  4135. }
  4136. if (j == NR_CARDS) { /* no more cy_cards available */
  4137. printk("Cyclom-Y/ISA found at 0x%lx ",
  4138. (unsigned long) cy_isa_address);
  4139. printk("but no more cards can be used .\n");
  4140. printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
  4141. return(nboard);
  4142. }
  4143. /* allocate IRQ */
  4144. if(request_irq(cy_isa_irq, cyy_interrupt,
  4145. SA_INTERRUPT, "Cyclom-Y", &cy_card[j]))
  4146. {
  4147. printk("Cyclom-Y/ISA found at 0x%lx ",
  4148. (unsigned long) cy_isa_address);
  4149. printk("but could not allocate IRQ#%d.\n",
  4150. cy_isa_irq);
  4151. return(nboard);
  4152. }
  4153. /* set cy_card */
  4154. cy_card[j].base_addr = cy_isa_address;
  4155. cy_card[j].ctl_addr = NULL;
  4156. cy_card[j].irq = (int) cy_isa_irq;
  4157. cy_card[j].bus_index = 0;
  4158. cy_card[j].first_line = cy_next_channel;
  4159. cy_card[j].num_chips = cy_isa_nchan/4;
  4160. nboard++;
  4161. /* print message */
  4162. printk("Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d, ",
  4163. j+1, (unsigned long) cy_isa_address,
  4164. (unsigned long)(cy_isa_address + (CyISA_Ywin - 1)),
  4165. cy_isa_irq);
  4166. printk("%d channels starting from port %d.\n",
  4167. cy_isa_nchan, cy_next_channel);
  4168. cy_next_channel += cy_isa_nchan;
  4169. }
  4170. return(nboard);
  4171. #else
  4172. return(0);
  4173. #endif /* CONFIG_ISA */
  4174. } /* cy_detect_isa */
  4175. static void
  4176. plx_init(void __iomem *addr, uclong initctl)
  4177. {
  4178. /* Reset PLX */
  4179. cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x40000000);
  4180. udelay(100L);
  4181. cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x40000000);
  4182. /* Reload Config. Registers from EEPROM */
  4183. cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x20000000);
  4184. udelay(100L);
  4185. cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x20000000);
  4186. }
  4187. /*
  4188. * ---------------------------------------------------------------------
  4189. * cy_detect_pci() - Test PCI bus presence and Cyclom-Ye/PCI.
  4190. * sets global variables and return the number of PCI boards found.
  4191. * ---------------------------------------------------------------------
  4192. */
  4193. static int __init
  4194. cy_detect_pci(void)
  4195. {
  4196. #ifdef CONFIG_PCI
  4197. struct pci_dev *pdev = NULL;
  4198. unsigned char cyy_rev_id;
  4199. unsigned char cy_pci_irq = 0;
  4200. uclong cy_pci_phys0, cy_pci_phys2;
  4201. void __iomem *cy_pci_addr0, *cy_pci_addr2;
  4202. unsigned short i,j,cy_pci_nchan, plx_ver;
  4203. unsigned short device_id,dev_index = 0;
  4204. uclong mailbox;
  4205. uclong ZeIndex = 0;
  4206. void __iomem *Ze_addr0[NR_CARDS], *Ze_addr2[NR_CARDS];
  4207. uclong Ze_phys0[NR_CARDS], Ze_phys2[NR_CARDS];
  4208. unsigned char Ze_irq[NR_CARDS];
  4209. struct pci_dev *Ze_pdev[NR_CARDS];
  4210. for (i = 0; i < NR_CARDS; i++) {
  4211. /* look for a Cyclades card by vendor and device id */
  4212. while((device_id = cy_pci_dev_id[dev_index]) != 0) {
  4213. if((pdev = pci_get_device(PCI_VENDOR_ID_CYCLADES,
  4214. device_id, pdev)) == NULL) {
  4215. dev_index++; /* try next device id */
  4216. } else {
  4217. break; /* found a board */
  4218. }
  4219. }
  4220. if (device_id == 0)
  4221. break;
  4222. if (pci_enable_device(pdev))
  4223. continue;
  4224. /* read PCI configuration area */
  4225. cy_pci_irq = pdev->irq;
  4226. cy_pci_phys0 = pci_resource_start(pdev, 0);
  4227. cy_pci_phys2 = pci_resource_start(pdev, 2);
  4228. pci_read_config_byte(pdev, PCI_REVISION_ID, &cyy_rev_id);
  4229. device_id &= ~PCI_DEVICE_ID_MASK;
  4230. if ((device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo)
  4231. || (device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi)){
  4232. #ifdef CY_PCI_DEBUG
  4233. printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
  4234. pdev->bus->number, pdev->devfn);
  4235. printk("rev_id=%d) IRQ%d\n",
  4236. cyy_rev_id, (int)cy_pci_irq);
  4237. printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n",
  4238. (ulong)cy_pci_phys2, (ulong)cy_pci_phys0);
  4239. #endif
  4240. if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) {
  4241. printk(" Warning: PCI I/O bit incorrectly set. "
  4242. "Ignoring it...\n");
  4243. pdev->resource[2].flags &= ~IORESOURCE_IO;
  4244. }
  4245. /* Although we don't use this I/O region, we should
  4246. request it from the kernel anyway, to avoid problems
  4247. with other drivers accessing it. */
  4248. if (pci_request_regions(pdev, "Cyclom-Y") != 0) {
  4249. printk(KERN_ERR "cyclades: failed to reserve PCI resources\n");
  4250. continue;
  4251. }
  4252. #if defined(__alpha__)
  4253. if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) { /* below 1M? */
  4254. printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
  4255. pdev->bus->number, pdev->devfn);
  4256. printk("rev_id=%d) IRQ%d\n",
  4257. cyy_rev_id, (int)cy_pci_irq);
  4258. printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n",
  4259. (ulong)cy_pci_phys2, (ulong)cy_pci_phys0);
  4260. printk("Cyclom-Y/PCI not supported for low addresses in "
  4261. "Alpha systems.\n");
  4262. i--;
  4263. continue;
  4264. }
  4265. #endif
  4266. cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Yctl);
  4267. cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Ywin);
  4268. #ifdef CY_PCI_DEBUG
  4269. printk("Cyclom-Y/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
  4270. (u_long)cy_pci_addr2, (u_long)cy_pci_addr0);
  4271. #endif
  4272. cy_pci_nchan = (unsigned short)(CyPORTS_PER_CHIP *
  4273. cyy_init_card(cy_pci_addr2, 1));
  4274. if(cy_pci_nchan == 0) {
  4275. printk("Cyclom-Y PCI host card with ");
  4276. printk("no Serial-Modules at 0x%lx.\n",
  4277. (ulong) cy_pci_phys2);
  4278. i--;
  4279. continue;
  4280. }
  4281. if((cy_next_channel+cy_pci_nchan) > NR_PORTS) {
  4282. printk("Cyclom-Y/PCI found at 0x%lx ",
  4283. (ulong) cy_pci_phys2);
  4284. printk("but no channels are available.\n");
  4285. printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
  4286. return(i);
  4287. }
  4288. /* fill the next cy_card structure available */
  4289. for (j = 0 ; j < NR_CARDS ; j++) {
  4290. if (cy_card[j].base_addr == 0) break;
  4291. }
  4292. if (j == NR_CARDS) { /* no more cy_cards available */
  4293. printk("Cyclom-Y/PCI found at 0x%lx ",
  4294. (ulong) cy_pci_phys2);
  4295. printk("but no more cards can be used.\n");
  4296. printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
  4297. return(i);
  4298. }
  4299. /* allocate IRQ */
  4300. if(request_irq(cy_pci_irq, cyy_interrupt,
  4301. SA_SHIRQ, "Cyclom-Y", &cy_card[j]))
  4302. {
  4303. printk("Cyclom-Y/PCI found at 0x%lx ",
  4304. (ulong) cy_pci_phys2);
  4305. printk("but could not allocate IRQ%d.\n",
  4306. cy_pci_irq);
  4307. return(i);
  4308. }
  4309. /* set cy_card */
  4310. cy_card[j].base_phys = (ulong)cy_pci_phys2;
  4311. cy_card[j].ctl_phys = (ulong)cy_pci_phys0;
  4312. cy_card[j].base_addr = cy_pci_addr2;
  4313. cy_card[j].ctl_addr = cy_pci_addr0;
  4314. cy_card[j].irq = (int) cy_pci_irq;
  4315. cy_card[j].bus_index = 1;
  4316. cy_card[j].first_line = cy_next_channel;
  4317. cy_card[j].num_chips = cy_pci_nchan/4;
  4318. cy_card[j].pdev = pdev;
  4319. /* enable interrupts in the PCI interface */
  4320. plx_ver = cy_readb(cy_pci_addr2 + CyPLX_VER) & 0x0f;
  4321. switch (plx_ver) {
  4322. case PLX_9050:
  4323. cy_writeb(cy_pci_addr0+0x4c, 0x43);
  4324. break;
  4325. case PLX_9060:
  4326. case PLX_9080:
  4327. default: /* Old boards, use PLX_9060 */
  4328. plx_init(cy_pci_addr0, 0x6c);
  4329. /* For some yet unknown reason, once the PLX9060 reloads
  4330. the EEPROM, the IRQ is lost and, thus, we have to
  4331. re-write it to the PCI config. registers.
  4332. This will remain here until we find a permanent fix. */
  4333. pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, cy_pci_irq);
  4334. cy_writew(cy_pci_addr0+0x68,
  4335. cy_readw(cy_pci_addr0+0x68)|0x0900);
  4336. break;
  4337. }
  4338. /* print message */
  4339. printk("Cyclom-Y/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
  4340. j+1,
  4341. (ulong)cy_pci_phys2,
  4342. (ulong)(cy_pci_phys2 + CyPCI_Ywin - 1),
  4343. (int)cy_pci_irq);
  4344. printk("%d channels starting from port %d.\n",
  4345. cy_pci_nchan, cy_next_channel);
  4346. cy_next_channel += cy_pci_nchan;
  4347. }else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Lo){
  4348. /* print message */
  4349. printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
  4350. pdev->bus->number, pdev->devfn);
  4351. printk("rev_id=%d) IRQ%d\n",
  4352. cyy_rev_id, (int)cy_pci_irq);
  4353. printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n",
  4354. (ulong)cy_pci_phys2, (ulong)cy_pci_phys0);
  4355. printk("Cyclades-Z/PCI not supported for low addresses\n");
  4356. break;
  4357. }else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi){
  4358. #ifdef CY_PCI_DEBUG
  4359. printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
  4360. pdev->bus->number, pdev->devfn);
  4361. printk("rev_id=%d) IRQ%d\n",
  4362. cyy_rev_id, (int)cy_pci_irq);
  4363. printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n",
  4364. (ulong)cy_pci_phys2, (ulong)cy_pci_phys0);
  4365. #endif
  4366. cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Zctl);
  4367. /* Disable interrupts on the PLX before resetting it */
  4368. cy_writew(cy_pci_addr0+0x68,
  4369. cy_readw(cy_pci_addr0+0x68) & ~0x0900);
  4370. plx_init(cy_pci_addr0, 0x6c);
  4371. /* For some yet unknown reason, once the PLX9060 reloads
  4372. the EEPROM, the IRQ is lost and, thus, we have to
  4373. re-write it to the PCI config. registers.
  4374. This will remain here until we find a permanent fix. */
  4375. pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, cy_pci_irq);
  4376. mailbox = (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *)
  4377. cy_pci_addr0)->mail_box_0);
  4378. if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) {
  4379. printk(" Warning: PCI I/O bit incorrectly set. "
  4380. "Ignoring it...\n");
  4381. pdev->resource[2].flags &= ~IORESOURCE_IO;
  4382. }
  4383. /* Although we don't use this I/O region, we should
  4384. request it from the kernel anyway, to avoid problems
  4385. with other drivers accessing it. */
  4386. if (pci_request_regions(pdev, "Cyclades-Z") != 0) {
  4387. printk(KERN_ERR "cyclades: failed to reserve PCI resources\n");
  4388. continue;
  4389. }
  4390. if (mailbox == ZE_V1) {
  4391. cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Ze_win);
  4392. if (ZeIndex == NR_CARDS) {
  4393. printk("Cyclades-Ze/PCI found at 0x%lx ",
  4394. (ulong)cy_pci_phys2);
  4395. printk("but no more cards can be used.\n");
  4396. printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
  4397. } else {
  4398. Ze_phys0[ZeIndex] = cy_pci_phys0;
  4399. Ze_phys2[ZeIndex] = cy_pci_phys2;
  4400. Ze_addr0[ZeIndex] = cy_pci_addr0;
  4401. Ze_addr2[ZeIndex] = cy_pci_addr2;
  4402. Ze_irq[ZeIndex] = cy_pci_irq;
  4403. Ze_pdev[ZeIndex] = pdev;
  4404. ZeIndex++;
  4405. }
  4406. i--;
  4407. continue;
  4408. } else {
  4409. cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Zwin);
  4410. }
  4411. #ifdef CY_PCI_DEBUG
  4412. printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
  4413. (ulong)cy_pci_addr2, (ulong)cy_pci_addr0);
  4414. if (mailbox == ZO_V1) {
  4415. cy_writel(&((struct RUNTIME_9060 *)
  4416. (cy_pci_addr0))->loc_addr_base, WIN_CREG);
  4417. PAUSE
  4418. printk("Cyclades-8Zo/PCI: FPGA id %lx, ver %lx\n",
  4419. (ulong)(0xff & cy_readl(&((struct CUSTOM_REG *)
  4420. (cy_pci_addr2))->fpga_id)),
  4421. (ulong)(0xff & cy_readl(&((struct CUSTOM_REG *)
  4422. (cy_pci_addr2))->fpga_version)));
  4423. cy_writel(&((struct RUNTIME_9060 *)
  4424. (cy_pci_addr0))->loc_addr_base, WIN_RAM);
  4425. } else {
  4426. printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n");
  4427. }
  4428. #endif
  4429. /* The following clears the firmware id word. This ensures
  4430. that the driver will not attempt to talk to the board
  4431. until it has been properly initialized.
  4432. */
  4433. PAUSE
  4434. if ((mailbox == ZO_V1) || (mailbox == ZO_V2))
  4435. cy_writel(cy_pci_addr2 + ID_ADDRESS, 0L);
  4436. /* This must be a Cyclades-8Zo/PCI. The extendable
  4437. version will have a different device_id and will
  4438. be allocated its maximum number of ports. */
  4439. cy_pci_nchan = 8;
  4440. if((cy_next_channel+cy_pci_nchan) > NR_PORTS) {
  4441. printk("Cyclades-8Zo/PCI found at 0x%lx ",
  4442. (ulong)cy_pci_phys2);
  4443. printk("but no channels are available.\n");
  4444. printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
  4445. return(i);
  4446. }
  4447. /* fill the next cy_card structure available */
  4448. for (j = 0 ; j < NR_CARDS ; j++) {
  4449. if (cy_card[j].base_addr == 0) break;
  4450. }
  4451. if (j == NR_CARDS) { /* no more cy_cards available */
  4452. printk("Cyclades-8Zo/PCI found at 0x%lx ",
  4453. (ulong)cy_pci_phys2);
  4454. printk("but no more cards can be used.\n");
  4455. printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
  4456. return(i);
  4457. }
  4458. #ifdef CONFIG_CYZ_INTR
  4459. /* allocate IRQ only if board has an IRQ */
  4460. if( (cy_pci_irq != 0) && (cy_pci_irq != 255) ) {
  4461. if(request_irq(cy_pci_irq, cyz_interrupt,
  4462. SA_SHIRQ, "Cyclades-Z", &cy_card[j]))
  4463. {
  4464. printk("Cyclom-8Zo/PCI found at 0x%lx ",
  4465. (ulong) cy_pci_phys2);
  4466. printk("but could not allocate IRQ%d.\n",
  4467. cy_pci_irq);
  4468. return(i);
  4469. }
  4470. }
  4471. #endif /* CONFIG_CYZ_INTR */
  4472. /* set cy_card */
  4473. cy_card[j].base_phys = cy_pci_phys2;
  4474. cy_card[j].ctl_phys = cy_pci_phys0;
  4475. cy_card[j].base_addr = cy_pci_addr2;
  4476. cy_card[j].ctl_addr = cy_pci_addr0;
  4477. cy_card[j].irq = (int) cy_pci_irq;
  4478. cy_card[j].bus_index = 1;
  4479. cy_card[j].first_line = cy_next_channel;
  4480. cy_card[j].num_chips = -1;
  4481. cy_card[j].pdev = pdev;
  4482. /* print message */
  4483. #ifdef CONFIG_CYZ_INTR
  4484. /* don't report IRQ if board is no IRQ */
  4485. if( (cy_pci_irq != 0) && (cy_pci_irq != 255) )
  4486. printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
  4487. j+1,(ulong)cy_pci_phys2,
  4488. (ulong)(cy_pci_phys2 + CyPCI_Zwin - 1),
  4489. (int)cy_pci_irq);
  4490. else
  4491. #endif /* CONFIG_CYZ_INTR */
  4492. printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, ",
  4493. j+1,(ulong)cy_pci_phys2,
  4494. (ulong)(cy_pci_phys2 + CyPCI_Zwin - 1));
  4495. printk("%d channels starting from port %d.\n",
  4496. cy_pci_nchan,cy_next_channel);
  4497. cy_next_channel += cy_pci_nchan;
  4498. }
  4499. }
  4500. for (; ZeIndex != 0 && i < NR_CARDS; i++) {
  4501. cy_pci_phys0 = Ze_phys0[0];
  4502. cy_pci_phys2 = Ze_phys2[0];
  4503. cy_pci_addr0 = Ze_addr0[0];
  4504. cy_pci_addr2 = Ze_addr2[0];
  4505. cy_pci_irq = Ze_irq[0];
  4506. pdev = Ze_pdev[0];
  4507. for (j = 0 ; j < ZeIndex-1 ; j++) {
  4508. Ze_phys0[j] = Ze_phys0[j+1];
  4509. Ze_phys2[j] = Ze_phys2[j+1];
  4510. Ze_addr0[j] = Ze_addr0[j+1];
  4511. Ze_addr2[j] = Ze_addr2[j+1];
  4512. Ze_irq[j] = Ze_irq[j+1];
  4513. Ze_pdev[j] = Ze_pdev[j+1];
  4514. }
  4515. ZeIndex--;
  4516. mailbox = (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *)
  4517. cy_pci_addr0)->mail_box_0);
  4518. #ifdef CY_PCI_DEBUG
  4519. printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
  4520. (ulong)cy_pci_addr2, (ulong)cy_pci_addr0);
  4521. printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n");
  4522. #endif
  4523. PAUSE
  4524. /* This must be the new Cyclades-Ze/PCI. */
  4525. cy_pci_nchan = ZE_V1_NPORTS;
  4526. if((cy_next_channel+cy_pci_nchan) > NR_PORTS) {
  4527. printk("Cyclades-Ze/PCI found at 0x%lx ",
  4528. (ulong)cy_pci_phys2);
  4529. printk("but no channels are available.\n");
  4530. printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
  4531. return(i);
  4532. }
  4533. /* fill the next cy_card structure available */
  4534. for (j = 0 ; j < NR_CARDS ; j++) {
  4535. if (cy_card[j].base_addr == 0) break;
  4536. }
  4537. if (j == NR_CARDS) { /* no more cy_cards available */
  4538. printk("Cyclades-Ze/PCI found at 0x%lx ",
  4539. (ulong)cy_pci_phys2);
  4540. printk("but no more cards can be used.\n");
  4541. printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
  4542. return(i);
  4543. }
  4544. #ifdef CONFIG_CYZ_INTR
  4545. /* allocate IRQ only if board has an IRQ */
  4546. if( (cy_pci_irq != 0) && (cy_pci_irq != 255) ) {
  4547. if(request_irq(cy_pci_irq, cyz_interrupt,
  4548. SA_SHIRQ, "Cyclades-Z", &cy_card[j]))
  4549. {
  4550. printk("Cyclom-Ze/PCI found at 0x%lx ",
  4551. (ulong) cy_pci_phys2);
  4552. printk("but could not allocate IRQ%d.\n",
  4553. cy_pci_irq);
  4554. return(i);
  4555. }
  4556. }
  4557. #endif /* CONFIG_CYZ_INTR */
  4558. /* set cy_card */
  4559. cy_card[j].base_phys = cy_pci_phys2;
  4560. cy_card[j].ctl_phys = cy_pci_phys0;
  4561. cy_card[j].base_addr = cy_pci_addr2;
  4562. cy_card[j].ctl_addr = cy_pci_addr0;
  4563. cy_card[j].irq = (int) cy_pci_irq;
  4564. cy_card[j].bus_index = 1;
  4565. cy_card[j].first_line = cy_next_channel;
  4566. cy_card[j].num_chips = -1;
  4567. cy_card[j].pdev = pdev;
  4568. /* print message */
  4569. #ifdef CONFIG_CYZ_INTR
  4570. /* don't report IRQ if board is no IRQ */
  4571. if( (cy_pci_irq != 0) && (cy_pci_irq != 255) )
  4572. printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
  4573. j+1,(ulong)cy_pci_phys2,
  4574. (ulong)(cy_pci_phys2 + CyPCI_Ze_win - 1),
  4575. (int)cy_pci_irq);
  4576. else
  4577. #endif /* CONFIG_CYZ_INTR */
  4578. printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, ",
  4579. j+1,(ulong)cy_pci_phys2,
  4580. (ulong)(cy_pci_phys2 + CyPCI_Ze_win - 1));
  4581. printk("%d channels starting from port %d.\n",
  4582. cy_pci_nchan,cy_next_channel);
  4583. cy_next_channel += cy_pci_nchan;
  4584. }
  4585. if (ZeIndex != 0) {
  4586. printk("Cyclades-Ze/PCI found at 0x%x ",
  4587. (unsigned int) Ze_phys2[0]);
  4588. printk("but no more cards can be used.\n");
  4589. printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
  4590. }
  4591. return(i);
  4592. #else
  4593. return(0);
  4594. #endif /* ifdef CONFIG_PCI */
  4595. } /* cy_detect_pci */
  4596. /*
  4597. * This routine prints out the appropriate serial driver version number
  4598. * and identifies which options were configured into this driver.
  4599. */
  4600. static inline void
  4601. show_version(void)
  4602. {
  4603. char *rcsvers, *rcsdate, *tmp;
  4604. rcsvers = strchr(rcsid, ' '); rcsvers++;
  4605. tmp = strchr(rcsvers, ' '); *tmp++ = '\0';
  4606. rcsdate = strchr(tmp, ' '); rcsdate++;
  4607. tmp = strrchr(rcsdate, ' '); *tmp = '\0';
  4608. printk("Cyclades driver %s %s\n",
  4609. rcsvers, rcsdate);
  4610. printk(" built %s %s\n",
  4611. __DATE__, __TIME__);
  4612. } /* show_version */
  4613. static int
  4614. cyclades_get_proc_info(char *buf, char **start, off_t offset, int length,
  4615. int *eof, void *data)
  4616. {
  4617. struct cyclades_port *info;
  4618. int i;
  4619. int len=0;
  4620. off_t begin=0;
  4621. off_t pos=0;
  4622. int size;
  4623. __u32 cur_jifs = jiffies;
  4624. size = sprintf(buf, "Dev TimeOpen BytesOut IdleOut BytesIn IdleIn Overruns Ldisc\n");
  4625. pos += size;
  4626. len += size;
  4627. /* Output one line for each known port */
  4628. for (i = 0; i < NR_PORTS && cy_port[i].line >= 0; i++) {
  4629. info = &cy_port[i];
  4630. if (info->count)
  4631. size = sprintf(buf+len,
  4632. "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
  4633. info->line,
  4634. JIFFIES_DIFF(info->idle_stats.in_use, cur_jifs) / HZ,
  4635. info->idle_stats.xmit_bytes,
  4636. JIFFIES_DIFF(info->idle_stats.xmit_idle, cur_jifs) / HZ,
  4637. info->idle_stats.recv_bytes,
  4638. JIFFIES_DIFF(info->idle_stats.recv_idle, cur_jifs) / HZ,
  4639. info->idle_stats.overruns,
  4640. (long) info->tty->ldisc.num);
  4641. else
  4642. size = sprintf(buf+len,
  4643. "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
  4644. info->line, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
  4645. len += size;
  4646. pos = begin + len;
  4647. if (pos < offset) {
  4648. len = 0;
  4649. begin = pos;
  4650. }
  4651. if (pos > offset + length)
  4652. goto done;
  4653. }
  4654. *eof = 1;
  4655. done:
  4656. *start = buf + (offset - begin); /* Start of wanted data */
  4657. len -= (offset - begin); /* Start slop */
  4658. if (len > length)
  4659. len = length; /* Ending slop */
  4660. if (len < 0)
  4661. len = 0;
  4662. return len;
  4663. }
  4664. /* The serial driver boot-time initialization code!
  4665. Hardware I/O ports are mapped to character special devices on a
  4666. first found, first allocated manner. That is, this code searches
  4667. for Cyclom cards in the system. As each is found, it is probed
  4668. to discover how many chips (and thus how many ports) are present.
  4669. These ports are mapped to the tty ports 32 and upward in monotonic
  4670. fashion. If an 8-port card is replaced with a 16-port card, the
  4671. port mapping on a following card will shift.
  4672. This approach is different from what is used in the other serial
  4673. device driver because the Cyclom is more properly a multiplexer,
  4674. not just an aggregation of serial ports on one card.
  4675. If there are more cards with more ports than have been
  4676. statically allocated above, a warning is printed and the
  4677. extra ports are ignored.
  4678. */
  4679. static struct tty_operations cy_ops = {
  4680. .open = cy_open,
  4681. .close = cy_close,
  4682. .write = cy_write,
  4683. .put_char = cy_put_char,
  4684. .flush_chars = cy_flush_chars,
  4685. .write_room = cy_write_room,
  4686. .chars_in_buffer = cy_chars_in_buffer,
  4687. .flush_buffer = cy_flush_buffer,
  4688. .ioctl = cy_ioctl,
  4689. .throttle = cy_throttle,
  4690. .unthrottle = cy_unthrottle,
  4691. .set_termios = cy_set_termios,
  4692. .stop = cy_stop,
  4693. .start = cy_start,
  4694. .hangup = cy_hangup,
  4695. .break_ctl = cy_break,
  4696. .wait_until_sent = cy_wait_until_sent,
  4697. .read_proc = cyclades_get_proc_info,
  4698. .tiocmget = cy_tiocmget,
  4699. .tiocmset = cy_tiocmset,
  4700. };
  4701. static int __init
  4702. cy_init(void)
  4703. {
  4704. struct cyclades_port *info;
  4705. struct cyclades_card *cinfo;
  4706. int number_z_boards = 0;
  4707. int board,port,i,index;
  4708. unsigned long mailbox;
  4709. unsigned short chip_number;
  4710. int nports;
  4711. cy_serial_driver = alloc_tty_driver(NR_PORTS);
  4712. if (!cy_serial_driver)
  4713. return -ENOMEM;
  4714. show_version();
  4715. /* Initialize the tty_driver structure */
  4716. cy_serial_driver->owner = THIS_MODULE;
  4717. cy_serial_driver->driver_name = "cyclades";
  4718. cy_serial_driver->name = "ttyC";
  4719. cy_serial_driver->devfs_name = "tts/C";
  4720. cy_serial_driver->major = CYCLADES_MAJOR;
  4721. cy_serial_driver->minor_start = 0;
  4722. cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
  4723. cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
  4724. cy_serial_driver->init_termios = tty_std_termios;
  4725. cy_serial_driver->init_termios.c_cflag =
  4726. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  4727. cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
  4728. tty_set_operations(cy_serial_driver, &cy_ops);
  4729. if (tty_register_driver(cy_serial_driver))
  4730. panic("Couldn't register Cyclades serial driver\n");
  4731. for (i = 0; i < NR_CARDS; i++) {
  4732. /* base_addr=0 indicates board not found */
  4733. cy_card[i].base_addr = NULL;
  4734. }
  4735. /* the code below is responsible to find the boards. Each different
  4736. type of board has its own detection routine. If a board is found,
  4737. the next cy_card structure available is set by the detection
  4738. routine. These functions are responsible for checking the
  4739. availability of cy_card and cy_port data structures and updating
  4740. the cy_next_channel. */
  4741. /* look for isa boards */
  4742. cy_isa_nboard = cy_detect_isa();
  4743. /* look for pci boards */
  4744. cy_pci_nboard = cy_detect_pci();
  4745. cy_nboard = cy_isa_nboard + cy_pci_nboard;
  4746. /* invalidate remaining cy_card structures */
  4747. for (i = 0 ; i < NR_CARDS ; i++) {
  4748. if (cy_card[i].base_addr == 0) {
  4749. cy_card[i].first_line = -1;
  4750. cy_card[i].ctl_addr = NULL;
  4751. cy_card[i].irq = 0;
  4752. cy_card[i].bus_index = 0;
  4753. cy_card[i].first_line = 0;
  4754. cy_card[i].num_chips = 0;
  4755. }
  4756. }
  4757. /* invalidate remaining cy_port structures */
  4758. for (i = cy_next_channel ; i < NR_PORTS ; i++) {
  4759. cy_port[i].line = -1;
  4760. cy_port[i].magic = -1;
  4761. }
  4762. /* initialize per-port data structures for each valid board found */
  4763. for (board = 0 ; board < cy_nboard ; board++) {
  4764. cinfo = &cy_card[board];
  4765. if (cinfo->num_chips == -1) { /* Cyclades-Z */
  4766. number_z_boards++;
  4767. mailbox = cy_readl(&((struct RUNTIME_9060 __iomem *)
  4768. cy_card[board].ctl_addr)->mail_box_0);
  4769. nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8;
  4770. cinfo->intr_enabled = 0;
  4771. cinfo->nports = 0; /* Will be correctly set later, after
  4772. Z FW is loaded */
  4773. spin_lock_init(&cinfo->card_lock);
  4774. for (port = cinfo->first_line ;
  4775. port < cinfo->first_line + nports;
  4776. port++)
  4777. {
  4778. info = &cy_port[port];
  4779. info->magic = CYCLADES_MAGIC;
  4780. info->type = PORT_STARTECH;
  4781. info->card = board;
  4782. info->line = port;
  4783. info->chip_rev = 0;
  4784. info->flags = STD_COM_FLAGS;
  4785. info->tty = NULL;
  4786. if (mailbox == ZO_V1)
  4787. info->xmit_fifo_size = CYZ_FIFO_SIZE;
  4788. else
  4789. info->xmit_fifo_size = 4 * CYZ_FIFO_SIZE;
  4790. info->cor1 = 0;
  4791. info->cor2 = 0;
  4792. info->cor3 = 0;
  4793. info->cor4 = 0;
  4794. info->cor5 = 0;
  4795. info->tbpr = 0;
  4796. info->tco = 0;
  4797. info->rbpr = 0;
  4798. info->rco = 0;
  4799. info->custom_divisor = 0;
  4800. info->close_delay = 5*HZ/10;
  4801. info->closing_wait = CLOSING_WAIT_DELAY;
  4802. info->icount.cts = info->icount.dsr =
  4803. info->icount.rng = info->icount.dcd = 0;
  4804. info->icount.rx = info->icount.tx = 0;
  4805. info->icount.frame = info->icount.parity = 0;
  4806. info->icount.overrun = info->icount.brk = 0;
  4807. info->x_char = 0;
  4808. info->event = 0;
  4809. info->count = 0;
  4810. info->blocked_open = 0;
  4811. info->default_threshold = 0;
  4812. info->default_timeout = 0;
  4813. INIT_WORK(&info->tqueue, do_softint, info);
  4814. init_waitqueue_head(&info->open_wait);
  4815. init_waitqueue_head(&info->close_wait);
  4816. init_waitqueue_head(&info->shutdown_wait);
  4817. init_waitqueue_head(&info->delta_msr_wait);
  4818. /* info->session */
  4819. /* info->pgrp */
  4820. info->read_status_mask = 0;
  4821. /* info->timeout */
  4822. /* Bentson's vars */
  4823. info->jiffies[0] = 0;
  4824. info->jiffies[1] = 0;
  4825. info->jiffies[2] = 0;
  4826. info->rflush_count = 0;
  4827. #ifdef CONFIG_CYZ_INTR
  4828. init_timer(&cyz_rx_full_timer[port]);
  4829. cyz_rx_full_timer[port].function = NULL;
  4830. #endif
  4831. }
  4832. continue;
  4833. }else{ /* Cyclom-Y of some kind*/
  4834. index = cinfo->bus_index;
  4835. spin_lock_init(&cinfo->card_lock);
  4836. cinfo->nports = CyPORTS_PER_CHIP * cinfo->num_chips;
  4837. for (port = cinfo->first_line ;
  4838. port < cinfo->first_line + cinfo->nports ;
  4839. port++)
  4840. {
  4841. info = &cy_port[port];
  4842. info->magic = CYCLADES_MAGIC;
  4843. info->type = PORT_CIRRUS;
  4844. info->card = board;
  4845. info->line = port;
  4846. info->flags = STD_COM_FLAGS;
  4847. info->tty = NULL;
  4848. info->xmit_fifo_size = CyMAX_CHAR_FIFO;
  4849. info->cor1 = CyPARITY_NONE|Cy_1_STOP|Cy_8_BITS;
  4850. info->cor2 = CyETC;
  4851. info->cor3 = 0x08; /* _very_ small rcv threshold */
  4852. info->cor4 = 0;
  4853. info->cor5 = 0;
  4854. info->custom_divisor = 0;
  4855. info->close_delay = 5*HZ/10;
  4856. info->closing_wait = CLOSING_WAIT_DELAY;
  4857. info->icount.cts = info->icount.dsr =
  4858. info->icount.rng = info->icount.dcd = 0;
  4859. info->icount.rx = info->icount.tx = 0;
  4860. info->icount.frame = info->icount.parity = 0;
  4861. info->icount.overrun = info->icount.brk = 0;
  4862. chip_number = (port - cinfo->first_line) / 4;
  4863. if ((info->chip_rev =
  4864. cy_readb(cinfo->base_addr +
  4865. (cy_chip_offset[chip_number]<<index) +
  4866. (CyGFRCR<<index))) >= CD1400_REV_J) {
  4867. /* It is a CD1400 rev. J or later */
  4868. info->tbpr = baud_bpr_60[13]; /* Tx BPR */
  4869. info->tco = baud_co_60[13]; /* Tx CO */
  4870. info->rbpr = baud_bpr_60[13]; /* Rx BPR */
  4871. info->rco = baud_co_60[13]; /* Rx CO */
  4872. info->rflow = 0;
  4873. info->rtsdtr_inv = 1;
  4874. } else {
  4875. info->tbpr = baud_bpr_25[13]; /* Tx BPR */
  4876. info->tco = baud_co_25[13]; /* Tx CO */
  4877. info->rbpr = baud_bpr_25[13]; /* Rx BPR */
  4878. info->rco = baud_co_25[13]; /* Rx CO */
  4879. info->rflow = 0;
  4880. info->rtsdtr_inv = 0;
  4881. }
  4882. info->x_char = 0;
  4883. info->event = 0;
  4884. info->count = 0;
  4885. info->blocked_open = 0;
  4886. info->default_threshold = 0;
  4887. info->default_timeout = 0;
  4888. INIT_WORK(&info->tqueue, do_softint, info);
  4889. init_waitqueue_head(&info->open_wait);
  4890. init_waitqueue_head(&info->close_wait);
  4891. init_waitqueue_head(&info->shutdown_wait);
  4892. init_waitqueue_head(&info->delta_msr_wait);
  4893. /* info->session */
  4894. /* info->pgrp */
  4895. info->read_status_mask =
  4896. CyTIMEOUT| CySPECHAR| CyBREAK
  4897. | CyPARITY| CyFRAME| CyOVERRUN;
  4898. /* info->timeout */
  4899. }
  4900. }
  4901. }
  4902. #ifndef CONFIG_CYZ_INTR
  4903. if (number_z_boards && !cyz_timeron){
  4904. cyz_timeron++;
  4905. cyz_timerlist.expires = jiffies + 1;
  4906. add_timer(&cyz_timerlist);
  4907. #ifdef CY_PCI_DEBUG
  4908. printk("Cyclades-Z polling initialized\n");
  4909. #endif
  4910. }
  4911. #endif /* CONFIG_CYZ_INTR */
  4912. return 0;
  4913. } /* cy_init */
  4914. static void __exit
  4915. cy_cleanup_module(void)
  4916. {
  4917. int i, e1;
  4918. #ifndef CONFIG_CYZ_INTR
  4919. if (cyz_timeron){
  4920. cyz_timeron = 0;
  4921. del_timer(&cyz_timerlist);
  4922. }
  4923. #endif /* CONFIG_CYZ_INTR */
  4924. if ((e1 = tty_unregister_driver(cy_serial_driver)))
  4925. printk("cyc: failed to unregister Cyclades serial driver(%d)\n",
  4926. e1);
  4927. put_tty_driver(cy_serial_driver);
  4928. for (i = 0; i < NR_CARDS; i++) {
  4929. if (cy_card[i].base_addr) {
  4930. iounmap(cy_card[i].base_addr);
  4931. if (cy_card[i].ctl_addr)
  4932. iounmap(cy_card[i].ctl_addr);
  4933. if (cy_card[i].irq
  4934. #ifndef CONFIG_CYZ_INTR
  4935. && cy_card[i].num_chips != -1 /* not a Z card */
  4936. #endif /* CONFIG_CYZ_INTR */
  4937. )
  4938. free_irq(cy_card[i].irq, &cy_card[i]);
  4939. #ifdef CONFIG_PCI
  4940. if (cy_card[i].pdev)
  4941. pci_release_regions(cy_card[i].pdev);
  4942. #endif
  4943. }
  4944. }
  4945. if (tmp_buf) {
  4946. free_page((unsigned long) tmp_buf);
  4947. tmp_buf = NULL;
  4948. }
  4949. } /* cy_cleanup_module */
  4950. module_init(cy_init);
  4951. module_exit(cy_cleanup_module);
  4952. MODULE_LICENSE("GPL");