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