cyclades.c 155 KB

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