cyclades.c 155 KB

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