cyclades.c 174 KB

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