cyclades.c 176 KB

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