cyclades.c 161 KB

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