cyclades.c 151 KB

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