cyclades.c 155 KB

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