cyclades.c 169 KB

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