stallion.c 125 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891
  1. /*****************************************************************************/
  2. /*
  3. * stallion.c -- stallion multiport serial driver.
  4. *
  5. * Copyright (C) 1996-1999 Stallion Technologies
  6. * Copyright (C) 1994-1996 Greg Ungerer.
  7. *
  8. * This code is loosely based on the Linux serial driver, written by
  9. * Linus Torvalds, Theodore T'so and others.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. /*****************************************************************************/
  26. #include <linux/module.h>
  27. #include <linux/slab.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/tty.h>
  30. #include <linux/tty_flip.h>
  31. #include <linux/serial.h>
  32. #include <linux/cd1400.h>
  33. #include <linux/sc26198.h>
  34. #include <linux/comstats.h>
  35. #include <linux/stallion.h>
  36. #include <linux/ioport.h>
  37. #include <linux/init.h>
  38. #include <linux/smp_lock.h>
  39. #include <linux/device.h>
  40. #include <linux/delay.h>
  41. #include <asm/io.h>
  42. #include <asm/uaccess.h>
  43. #ifdef CONFIG_PCI
  44. #include <linux/pci.h>
  45. #endif
  46. /*****************************************************************************/
  47. /*
  48. * Define different board types. Use the standard Stallion "assigned"
  49. * board numbers. Boards supported in this driver are abbreviated as
  50. * EIO = EasyIO and ECH = EasyConnection 8/32.
  51. */
  52. #define BRD_EASYIO 20
  53. #define BRD_ECH 21
  54. #define BRD_ECHMC 22
  55. #define BRD_ECHPCI 26
  56. #define BRD_ECH64PCI 27
  57. #define BRD_EASYIOPCI 28
  58. /*
  59. * Define a configuration structure to hold the board configuration.
  60. * Need to set this up in the code (for now) with the boards that are
  61. * to be configured into the system. This is what needs to be modified
  62. * when adding/removing/modifying boards. Each line entry in the
  63. * stl_brdconf[] array is a board. Each line contains io/irq/memory
  64. * ranges for that board (as well as what type of board it is).
  65. * Some examples:
  66. * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
  67. * This line would configure an EasyIO board (4 or 8, no difference),
  68. * at io address 2a0 and irq 10.
  69. * Another example:
  70. * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
  71. * This line will configure an EasyConnection 8/32 board at primary io
  72. * address 2a8, secondary io address 280 and irq 12.
  73. * Enter as many lines into this array as you want (only the first 4
  74. * will actually be used!). Any combination of EasyIO and EasyConnection
  75. * boards can be specified. EasyConnection 8/32 boards can share their
  76. * secondary io addresses between each other.
  77. *
  78. * NOTE: there is no need to put any entries in this table for PCI
  79. * boards. They will be found automatically by the driver - provided
  80. * PCI BIOS32 support is compiled into the kernel.
  81. */
  82. static struct stlconf {
  83. int brdtype;
  84. int ioaddr1;
  85. int ioaddr2;
  86. unsigned long memaddr;
  87. int irq;
  88. int irqtype;
  89. } stl_brdconf[] = {
  90. /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
  91. };
  92. static int stl_nrbrds = ARRAY_SIZE(stl_brdconf);
  93. /*****************************************************************************/
  94. /*
  95. * Define some important driver characteristics. Device major numbers
  96. * allocated as per Linux Device Registry.
  97. */
  98. #ifndef STL_SIOMEMMAJOR
  99. #define STL_SIOMEMMAJOR 28
  100. #endif
  101. #ifndef STL_SERIALMAJOR
  102. #define STL_SERIALMAJOR 24
  103. #endif
  104. #ifndef STL_CALLOUTMAJOR
  105. #define STL_CALLOUTMAJOR 25
  106. #endif
  107. /*
  108. * Set the TX buffer size. Bigger is better, but we don't want
  109. * to chew too much memory with buffers!
  110. */
  111. #define STL_TXBUFLOW 512
  112. #define STL_TXBUFSIZE 4096
  113. /*****************************************************************************/
  114. /*
  115. * Define our local driver identity first. Set up stuff to deal with
  116. * all the local structures required by a serial tty driver.
  117. */
  118. static char *stl_drvtitle = "Stallion Multiport Serial Driver";
  119. static char *stl_drvname = "stallion";
  120. static char *stl_drvversion = "5.6.0";
  121. static struct tty_driver *stl_serial;
  122. /*
  123. * Define a local default termios struct. All ports will be created
  124. * with this termios initially. Basically all it defines is a raw port
  125. * at 9600, 8 data bits, 1 stop bit.
  126. */
  127. static struct termios stl_deftermios = {
  128. .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
  129. .c_cc = INIT_C_CC,
  130. };
  131. /*
  132. * Define global stats structures. Not used often, and can be
  133. * re-used for each stats call.
  134. */
  135. static comstats_t stl_comstats;
  136. static combrd_t stl_brdstats;
  137. static struct stlbrd stl_dummybrd;
  138. static struct stlport stl_dummyport;
  139. /*
  140. * Define global place to put buffer overflow characters.
  141. */
  142. static char stl_unwanted[SC26198_RXFIFOSIZE];
  143. /*****************************************************************************/
  144. static struct stlbrd *stl_brds[STL_MAXBRDS];
  145. /*
  146. * Per board state flags. Used with the state field of the board struct.
  147. * Not really much here!
  148. */
  149. #define BRD_FOUND 0x1
  150. /*
  151. * Define the port structure istate flags. These set of flags are
  152. * modified at interrupt time - so setting and reseting them needs
  153. * to be atomic. Use the bit clear/setting routines for this.
  154. */
  155. #define ASYI_TXBUSY 1
  156. #define ASYI_TXLOW 2
  157. #define ASYI_DCDCHANGE 3
  158. #define ASYI_TXFLOWED 4
  159. /*
  160. * Define an array of board names as printable strings. Handy for
  161. * referencing boards when printing trace and stuff.
  162. */
  163. static char *stl_brdnames[] = {
  164. NULL,
  165. NULL,
  166. NULL,
  167. NULL,
  168. NULL,
  169. NULL,
  170. NULL,
  171. NULL,
  172. NULL,
  173. NULL,
  174. NULL,
  175. NULL,
  176. NULL,
  177. NULL,
  178. NULL,
  179. NULL,
  180. NULL,
  181. NULL,
  182. NULL,
  183. NULL,
  184. "EasyIO",
  185. "EC8/32-AT",
  186. "EC8/32-MC",
  187. NULL,
  188. NULL,
  189. NULL,
  190. "EC8/32-PCI",
  191. "EC8/64-PCI",
  192. "EasyIO-PCI",
  193. };
  194. /*****************************************************************************/
  195. /*
  196. * Define some string labels for arguments passed from the module
  197. * load line. These allow for easy board definitions, and easy
  198. * modification of the io, memory and irq resoucres.
  199. */
  200. static int stl_nargs = 0;
  201. static char *board0[4];
  202. static char *board1[4];
  203. static char *board2[4];
  204. static char *board3[4];
  205. static char **stl_brdsp[] = {
  206. (char **) &board0,
  207. (char **) &board1,
  208. (char **) &board2,
  209. (char **) &board3
  210. };
  211. /*
  212. * Define a set of common board names, and types. This is used to
  213. * parse any module arguments.
  214. */
  215. static struct {
  216. char *name;
  217. int type;
  218. } stl_brdstr[] = {
  219. { "easyio", BRD_EASYIO },
  220. { "eio", BRD_EASYIO },
  221. { "20", BRD_EASYIO },
  222. { "ec8/32", BRD_ECH },
  223. { "ec8/32-at", BRD_ECH },
  224. { "ec8/32-isa", BRD_ECH },
  225. { "ech", BRD_ECH },
  226. { "echat", BRD_ECH },
  227. { "21", BRD_ECH },
  228. { "ec8/32-mc", BRD_ECHMC },
  229. { "ec8/32-mca", BRD_ECHMC },
  230. { "echmc", BRD_ECHMC },
  231. { "echmca", BRD_ECHMC },
  232. { "22", BRD_ECHMC },
  233. { "ec8/32-pc", BRD_ECHPCI },
  234. { "ec8/32-pci", BRD_ECHPCI },
  235. { "26", BRD_ECHPCI },
  236. { "ec8/64-pc", BRD_ECH64PCI },
  237. { "ec8/64-pci", BRD_ECH64PCI },
  238. { "ech-pci", BRD_ECH64PCI },
  239. { "echpci", BRD_ECH64PCI },
  240. { "echpc", BRD_ECH64PCI },
  241. { "27", BRD_ECH64PCI },
  242. { "easyio-pc", BRD_EASYIOPCI },
  243. { "easyio-pci", BRD_EASYIOPCI },
  244. { "eio-pci", BRD_EASYIOPCI },
  245. { "eiopci", BRD_EASYIOPCI },
  246. { "28", BRD_EASYIOPCI },
  247. };
  248. /*
  249. * Define the module agruments.
  250. */
  251. module_param_array(board0, charp, &stl_nargs, 0);
  252. MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
  253. module_param_array(board1, charp, &stl_nargs, 0);
  254. MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
  255. module_param_array(board2, charp, &stl_nargs, 0);
  256. MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
  257. module_param_array(board3, charp, &stl_nargs, 0);
  258. MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
  259. /*****************************************************************************/
  260. /*
  261. * Hardware ID bits for the EasyIO and ECH boards. These defines apply
  262. * to the directly accessible io ports of these boards (not the uarts -
  263. * they are in cd1400.h and sc26198.h).
  264. */
  265. #define EIO_8PORTRS 0x04
  266. #define EIO_4PORTRS 0x05
  267. #define EIO_8PORTDI 0x00
  268. #define EIO_8PORTM 0x06
  269. #define EIO_MK3 0x03
  270. #define EIO_IDBITMASK 0x07
  271. #define EIO_BRDMASK 0xf0
  272. #define ID_BRD4 0x10
  273. #define ID_BRD8 0x20
  274. #define ID_BRD16 0x30
  275. #define EIO_INTRPEND 0x08
  276. #define EIO_INTEDGE 0x00
  277. #define EIO_INTLEVEL 0x08
  278. #define EIO_0WS 0x10
  279. #define ECH_ID 0xa0
  280. #define ECH_IDBITMASK 0xe0
  281. #define ECH_BRDENABLE 0x08
  282. #define ECH_BRDDISABLE 0x00
  283. #define ECH_INTENABLE 0x01
  284. #define ECH_INTDISABLE 0x00
  285. #define ECH_INTLEVEL 0x02
  286. #define ECH_INTEDGE 0x00
  287. #define ECH_INTRPEND 0x01
  288. #define ECH_BRDRESET 0x01
  289. #define ECHMC_INTENABLE 0x01
  290. #define ECHMC_BRDRESET 0x02
  291. #define ECH_PNLSTATUS 2
  292. #define ECH_PNL16PORT 0x20
  293. #define ECH_PNLIDMASK 0x07
  294. #define ECH_PNLXPID 0x40
  295. #define ECH_PNLINTRPEND 0x80
  296. #define ECH_ADDR2MASK 0x1e0
  297. /*
  298. * Define the vector mapping bits for the programmable interrupt board
  299. * hardware. These bits encode the interrupt for the board to use - it
  300. * is software selectable (except the EIO-8M).
  301. */
  302. static unsigned char stl_vecmap[] = {
  303. 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
  304. 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
  305. };
  306. /*
  307. * Lock ordering is that you may not take stallion_lock holding
  308. * brd_lock.
  309. */
  310. static spinlock_t brd_lock; /* Guard the board mapping */
  311. static spinlock_t stallion_lock; /* Guard the tty driver */
  312. /*
  313. * Set up enable and disable macros for the ECH boards. They require
  314. * the secondary io address space to be activated and deactivated.
  315. * This way all ECH boards can share their secondary io region.
  316. * If this is an ECH-PCI board then also need to set the page pointer
  317. * to point to the correct page.
  318. */
  319. #define BRDENABLE(brdnr,pagenr) \
  320. if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
  321. outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
  322. stl_brds[(brdnr)]->ioctrl); \
  323. else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
  324. outb((pagenr), stl_brds[(brdnr)]->ioctrl);
  325. #define BRDDISABLE(brdnr) \
  326. if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
  327. outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
  328. stl_brds[(brdnr)]->ioctrl);
  329. #define STL_CD1400MAXBAUD 230400
  330. #define STL_SC26198MAXBAUD 460800
  331. #define STL_BAUDBASE 115200
  332. #define STL_CLOSEDELAY (5 * HZ / 10)
  333. /*****************************************************************************/
  334. #ifdef CONFIG_PCI
  335. /*
  336. * Define the Stallion PCI vendor and device IDs.
  337. */
  338. #ifndef PCI_VENDOR_ID_STALLION
  339. #define PCI_VENDOR_ID_STALLION 0x124d
  340. #endif
  341. #ifndef PCI_DEVICE_ID_ECHPCI832
  342. #define PCI_DEVICE_ID_ECHPCI832 0x0000
  343. #endif
  344. #ifndef PCI_DEVICE_ID_ECHPCI864
  345. #define PCI_DEVICE_ID_ECHPCI864 0x0002
  346. #endif
  347. #ifndef PCI_DEVICE_ID_EIOPCI
  348. #define PCI_DEVICE_ID_EIOPCI 0x0003
  349. #endif
  350. /*
  351. * Define structure to hold all Stallion PCI boards.
  352. */
  353. typedef struct stlpcibrd {
  354. unsigned short vendid;
  355. unsigned short devid;
  356. int brdtype;
  357. } stlpcibrd_t;
  358. static stlpcibrd_t stl_pcibrds[] = {
  359. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
  360. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
  361. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
  362. { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
  363. };
  364. static int stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds);
  365. #endif
  366. /*****************************************************************************/
  367. /*
  368. * Define macros to extract a brd/port number from a minor number.
  369. */
  370. #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
  371. #define MINOR2PORT(min) ((min) & 0x3f)
  372. /*
  373. * Define a baud rate table that converts termios baud rate selector
  374. * into the actual baud rate value. All baud rate calculations are
  375. * based on the actual baud rate required.
  376. */
  377. static unsigned int stl_baudrates[] = {
  378. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
  379. 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
  380. };
  381. /*
  382. * Define some handy local macros...
  383. */
  384. #undef MIN
  385. #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
  386. #undef TOLOWER
  387. #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
  388. /*****************************************************************************/
  389. /*
  390. * Declare all those functions in this driver!
  391. */
  392. static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
  393. static int stl_brdinit(struct stlbrd *brdp);
  394. static int stl_getportstats(struct stlport *portp, comstats_t __user *cp);
  395. static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp);
  396. static int stl_waitcarrier(struct stlport *portp, struct file *filp);
  397. /*
  398. * CD1400 uart specific handling functions.
  399. */
  400. static void stl_cd1400setreg(struct stlport *portp, int regnr, int value);
  401. static int stl_cd1400getreg(struct stlport *portp, int regnr);
  402. static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value);
  403. static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
  404. static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
  405. static void stl_cd1400setport(struct stlport *portp, struct termios *tiosp);
  406. static int stl_cd1400getsignals(struct stlport *portp);
  407. static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts);
  408. static void stl_cd1400ccrwait(struct stlport *portp);
  409. static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx);
  410. static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx);
  411. static void stl_cd1400disableintrs(struct stlport *portp);
  412. static void stl_cd1400sendbreak(struct stlport *portp, int len);
  413. static void stl_cd1400flowctrl(struct stlport *portp, int state);
  414. static void stl_cd1400sendflow(struct stlport *portp, int state);
  415. static void stl_cd1400flush(struct stlport *portp);
  416. static int stl_cd1400datastate(struct stlport *portp);
  417. static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase);
  418. static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase);
  419. static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr);
  420. static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr);
  421. static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr);
  422. static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr);
  423. /*
  424. * SC26198 uart specific handling functions.
  425. */
  426. static void stl_sc26198setreg(struct stlport *portp, int regnr, int value);
  427. static int stl_sc26198getreg(struct stlport *portp, int regnr);
  428. static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value);
  429. static int stl_sc26198getglobreg(struct stlport *portp, int regnr);
  430. static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
  431. static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
  432. static void stl_sc26198setport(struct stlport *portp, struct termios *tiosp);
  433. static int stl_sc26198getsignals(struct stlport *portp);
  434. static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts);
  435. static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx);
  436. static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx);
  437. static void stl_sc26198disableintrs(struct stlport *portp);
  438. static void stl_sc26198sendbreak(struct stlport *portp, int len);
  439. static void stl_sc26198flowctrl(struct stlport *portp, int state);
  440. static void stl_sc26198sendflow(struct stlport *portp, int state);
  441. static void stl_sc26198flush(struct stlport *portp);
  442. static int stl_sc26198datastate(struct stlport *portp);
  443. static void stl_sc26198wait(struct stlport *portp);
  444. static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty);
  445. static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase);
  446. static void stl_sc26198txisr(struct stlport *port);
  447. static void stl_sc26198rxisr(struct stlport *port, unsigned int iack);
  448. static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch);
  449. static void stl_sc26198rxbadchars(struct stlport *portp);
  450. static void stl_sc26198otherisr(struct stlport *port, unsigned int iack);
  451. /*****************************************************************************/
  452. /*
  453. * Generic UART support structure.
  454. */
  455. typedef struct uart {
  456. int (*panelinit)(struct stlbrd *brdp, struct stlpanel *panelp);
  457. void (*portinit)(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
  458. void (*setport)(struct stlport *portp, struct termios *tiosp);
  459. int (*getsignals)(struct stlport *portp);
  460. void (*setsignals)(struct stlport *portp, int dtr, int rts);
  461. void (*enablerxtx)(struct stlport *portp, int rx, int tx);
  462. void (*startrxtx)(struct stlport *portp, int rx, int tx);
  463. void (*disableintrs)(struct stlport *portp);
  464. void (*sendbreak)(struct stlport *portp, int len);
  465. void (*flowctrl)(struct stlport *portp, int state);
  466. void (*sendflow)(struct stlport *portp, int state);
  467. void (*flush)(struct stlport *portp);
  468. int (*datastate)(struct stlport *portp);
  469. void (*intr)(struct stlpanel *panelp, unsigned int iobase);
  470. } uart_t;
  471. /*
  472. * Define some macros to make calling these functions nice and clean.
  473. */
  474. #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
  475. #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
  476. #define stl_setport (* ((uart_t *) portp->uartp)->setport)
  477. #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
  478. #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
  479. #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
  480. #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
  481. #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
  482. #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
  483. #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
  484. #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
  485. #define stl_flush (* ((uart_t *) portp->uartp)->flush)
  486. #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
  487. /*****************************************************************************/
  488. /*
  489. * CD1400 UART specific data initialization.
  490. */
  491. static uart_t stl_cd1400uart = {
  492. stl_cd1400panelinit,
  493. stl_cd1400portinit,
  494. stl_cd1400setport,
  495. stl_cd1400getsignals,
  496. stl_cd1400setsignals,
  497. stl_cd1400enablerxtx,
  498. stl_cd1400startrxtx,
  499. stl_cd1400disableintrs,
  500. stl_cd1400sendbreak,
  501. stl_cd1400flowctrl,
  502. stl_cd1400sendflow,
  503. stl_cd1400flush,
  504. stl_cd1400datastate,
  505. stl_cd1400eiointr
  506. };
  507. /*
  508. * Define the offsets within the register bank of a cd1400 based panel.
  509. * These io address offsets are common to the EasyIO board as well.
  510. */
  511. #define EREG_ADDR 0
  512. #define EREG_DATA 4
  513. #define EREG_RXACK 5
  514. #define EREG_TXACK 6
  515. #define EREG_MDACK 7
  516. #define EREG_BANKSIZE 8
  517. #define CD1400_CLK 25000000
  518. #define CD1400_CLK8M 20000000
  519. /*
  520. * Define the cd1400 baud rate clocks. These are used when calculating
  521. * what clock and divisor to use for the required baud rate. Also
  522. * define the maximum baud rate allowed, and the default base baud.
  523. */
  524. static int stl_cd1400clkdivs[] = {
  525. CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
  526. };
  527. /*****************************************************************************/
  528. /*
  529. * SC26198 UART specific data initization.
  530. */
  531. static uart_t stl_sc26198uart = {
  532. stl_sc26198panelinit,
  533. stl_sc26198portinit,
  534. stl_sc26198setport,
  535. stl_sc26198getsignals,
  536. stl_sc26198setsignals,
  537. stl_sc26198enablerxtx,
  538. stl_sc26198startrxtx,
  539. stl_sc26198disableintrs,
  540. stl_sc26198sendbreak,
  541. stl_sc26198flowctrl,
  542. stl_sc26198sendflow,
  543. stl_sc26198flush,
  544. stl_sc26198datastate,
  545. stl_sc26198intr
  546. };
  547. /*
  548. * Define the offsets within the register bank of a sc26198 based panel.
  549. */
  550. #define XP_DATA 0
  551. #define XP_ADDR 1
  552. #define XP_MODID 2
  553. #define XP_STATUS 2
  554. #define XP_IACK 3
  555. #define XP_BANKSIZE 4
  556. /*
  557. * Define the sc26198 baud rate table. Offsets within the table
  558. * represent the actual baud rate selector of sc26198 registers.
  559. */
  560. static unsigned int sc26198_baudtable[] = {
  561. 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
  562. 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
  563. 230400, 460800, 921600
  564. };
  565. #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
  566. /*****************************************************************************/
  567. /*
  568. * Define the driver info for a user level control device. Used mainly
  569. * to get at port stats - only not using the port device itself.
  570. */
  571. static const struct file_operations stl_fsiomem = {
  572. .owner = THIS_MODULE,
  573. .ioctl = stl_memioctl,
  574. };
  575. static struct class *stallion_class;
  576. /*
  577. * Check for any arguments passed in on the module load command line.
  578. */
  579. /*****************************************************************************/
  580. /*
  581. * Convert an ascii string number into an unsigned long.
  582. */
  583. static unsigned long stl_atol(char *str)
  584. {
  585. unsigned long val;
  586. int base, c;
  587. char *sp;
  588. val = 0;
  589. sp = str;
  590. if ((*sp == '0') && (*(sp+1) == 'x')) {
  591. base = 16;
  592. sp += 2;
  593. } else if (*sp == '0') {
  594. base = 8;
  595. sp++;
  596. } else {
  597. base = 10;
  598. }
  599. for (; (*sp != 0); sp++) {
  600. c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
  601. if ((c < 0) || (c >= base)) {
  602. printk("STALLION: invalid argument %s\n", str);
  603. val = 0;
  604. break;
  605. }
  606. val = (val * base) + c;
  607. }
  608. return val;
  609. }
  610. /*****************************************************************************/
  611. /*
  612. * Parse the supplied argument string, into the board conf struct.
  613. */
  614. static int __init stl_parsebrd(struct stlconf *confp, char **argp)
  615. {
  616. char *sp;
  617. int i;
  618. pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp, argp);
  619. if ((argp[0] == NULL) || (*argp[0] == 0))
  620. return 0;
  621. for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
  622. *sp = TOLOWER(*sp);
  623. for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
  624. if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
  625. break;
  626. }
  627. if (i == ARRAY_SIZE(stl_brdstr)) {
  628. printk("STALLION: unknown board name, %s?\n", argp[0]);
  629. return 0;
  630. }
  631. confp->brdtype = stl_brdstr[i].type;
  632. i = 1;
  633. if ((argp[i] != NULL) && (*argp[i] != 0))
  634. confp->ioaddr1 = stl_atol(argp[i]);
  635. i++;
  636. if (confp->brdtype == BRD_ECH) {
  637. if ((argp[i] != NULL) && (*argp[i] != 0))
  638. confp->ioaddr2 = stl_atol(argp[i]);
  639. i++;
  640. }
  641. if ((argp[i] != NULL) && (*argp[i] != 0))
  642. confp->irq = stl_atol(argp[i]);
  643. return 1;
  644. }
  645. /*****************************************************************************/
  646. /*
  647. * Allocate a new board structure. Fill out the basic info in it.
  648. */
  649. static struct stlbrd *stl_allocbrd(void)
  650. {
  651. struct stlbrd *brdp;
  652. brdp = kzalloc(sizeof(struct stlbrd), GFP_KERNEL);
  653. if (!brdp) {
  654. printk("STALLION: failed to allocate memory (size=%Zd)\n",
  655. sizeof(struct stlbrd));
  656. return NULL;
  657. }
  658. brdp->magic = STL_BOARDMAGIC;
  659. return brdp;
  660. }
  661. static void __init stl_argbrds(void)
  662. {
  663. struct stlconf conf;
  664. struct stlbrd *brdp;
  665. int i;
  666. pr_debug("stl_argbrds()\n");
  667. for (i = stl_nrbrds; (i < stl_nargs); i++) {
  668. memset(&conf, 0, sizeof(conf));
  669. if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
  670. continue;
  671. if ((brdp = stl_allocbrd()) == NULL)
  672. continue;
  673. stl_nrbrds = i + 1;
  674. brdp->brdnr = i;
  675. brdp->brdtype = conf.brdtype;
  676. brdp->ioaddr1 = conf.ioaddr1;
  677. brdp->ioaddr2 = conf.ioaddr2;
  678. brdp->irq = conf.irq;
  679. brdp->irqtype = conf.irqtype;
  680. stl_brdinit(brdp);
  681. }
  682. }
  683. /*****************************************************************************/
  684. static int stl_open(struct tty_struct *tty, struct file *filp)
  685. {
  686. struct stlport *portp;
  687. struct stlbrd *brdp;
  688. unsigned int minordev;
  689. int brdnr, panelnr, portnr, rc;
  690. pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
  691. minordev = tty->index;
  692. brdnr = MINOR2BRD(minordev);
  693. if (brdnr >= stl_nrbrds)
  694. return -ENODEV;
  695. brdp = stl_brds[brdnr];
  696. if (brdp == NULL)
  697. return -ENODEV;
  698. minordev = MINOR2PORT(minordev);
  699. for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
  700. if (brdp->panels[panelnr] == NULL)
  701. break;
  702. if (minordev < brdp->panels[panelnr]->nrports) {
  703. portnr = minordev;
  704. break;
  705. }
  706. minordev -= brdp->panels[panelnr]->nrports;
  707. }
  708. if (portnr < 0)
  709. return -ENODEV;
  710. portp = brdp->panels[panelnr]->ports[portnr];
  711. if (portp == NULL)
  712. return -ENODEV;
  713. /*
  714. * On the first open of the device setup the port hardware, and
  715. * initialize the per port data structure.
  716. */
  717. portp->tty = tty;
  718. tty->driver_data = portp;
  719. portp->refcount++;
  720. if ((portp->flags & ASYNC_INITIALIZED) == 0) {
  721. if (!portp->tx.buf) {
  722. portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
  723. if (!portp->tx.buf)
  724. return -ENOMEM;
  725. portp->tx.head = portp->tx.buf;
  726. portp->tx.tail = portp->tx.buf;
  727. }
  728. stl_setport(portp, tty->termios);
  729. portp->sigs = stl_getsignals(portp);
  730. stl_setsignals(portp, 1, 1);
  731. stl_enablerxtx(portp, 1, 1);
  732. stl_startrxtx(portp, 1, 0);
  733. clear_bit(TTY_IO_ERROR, &tty->flags);
  734. portp->flags |= ASYNC_INITIALIZED;
  735. }
  736. /*
  737. * Check if this port is in the middle of closing. If so then wait
  738. * until it is closed then return error status, based on flag settings.
  739. * The sleep here does not need interrupt protection since the wakeup
  740. * for it is done with the same context.
  741. */
  742. if (portp->flags & ASYNC_CLOSING) {
  743. interruptible_sleep_on(&portp->close_wait);
  744. if (portp->flags & ASYNC_HUP_NOTIFY)
  745. return -EAGAIN;
  746. return -ERESTARTSYS;
  747. }
  748. /*
  749. * Based on type of open being done check if it can overlap with any
  750. * previous opens still in effect. If we are a normal serial device
  751. * then also we might have to wait for carrier.
  752. */
  753. if (!(filp->f_flags & O_NONBLOCK)) {
  754. if ((rc = stl_waitcarrier(portp, filp)) != 0)
  755. return rc;
  756. }
  757. portp->flags |= ASYNC_NORMAL_ACTIVE;
  758. return 0;
  759. }
  760. /*****************************************************************************/
  761. /*
  762. * Possibly need to wait for carrier (DCD signal) to come high. Say
  763. * maybe because if we are clocal then we don't need to wait...
  764. */
  765. static int stl_waitcarrier(struct stlport *portp, struct file *filp)
  766. {
  767. unsigned long flags;
  768. int rc, doclocal;
  769. pr_debug("stl_waitcarrier(portp=%p,filp=%p)\n", portp, filp);
  770. rc = 0;
  771. doclocal = 0;
  772. spin_lock_irqsave(&stallion_lock, flags);
  773. if (portp->tty->termios->c_cflag & CLOCAL)
  774. doclocal++;
  775. portp->openwaitcnt++;
  776. if (! tty_hung_up_p(filp))
  777. portp->refcount--;
  778. for (;;) {
  779. /* Takes brd_lock internally */
  780. stl_setsignals(portp, 1, 1);
  781. if (tty_hung_up_p(filp) ||
  782. ((portp->flags & ASYNC_INITIALIZED) == 0)) {
  783. if (portp->flags & ASYNC_HUP_NOTIFY)
  784. rc = -EBUSY;
  785. else
  786. rc = -ERESTARTSYS;
  787. break;
  788. }
  789. if (((portp->flags & ASYNC_CLOSING) == 0) &&
  790. (doclocal || (portp->sigs & TIOCM_CD))) {
  791. break;
  792. }
  793. if (signal_pending(current)) {
  794. rc = -ERESTARTSYS;
  795. break;
  796. }
  797. /* FIXME */
  798. interruptible_sleep_on(&portp->open_wait);
  799. }
  800. if (! tty_hung_up_p(filp))
  801. portp->refcount++;
  802. portp->openwaitcnt--;
  803. spin_unlock_irqrestore(&stallion_lock, flags);
  804. return rc;
  805. }
  806. /*****************************************************************************/
  807. static void stl_flushbuffer(struct tty_struct *tty)
  808. {
  809. struct stlport *portp;
  810. pr_debug("stl_flushbuffer(tty=%p)\n", tty);
  811. if (tty == NULL)
  812. return;
  813. portp = tty->driver_data;
  814. if (portp == NULL)
  815. return;
  816. stl_flush(portp);
  817. tty_wakeup(tty);
  818. }
  819. /*****************************************************************************/
  820. static void stl_waituntilsent(struct tty_struct *tty, int timeout)
  821. {
  822. struct stlport *portp;
  823. unsigned long tend;
  824. pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout);
  825. if (tty == NULL)
  826. return;
  827. portp = tty->driver_data;
  828. if (portp == NULL)
  829. return;
  830. if (timeout == 0)
  831. timeout = HZ;
  832. tend = jiffies + timeout;
  833. while (stl_datastate(portp)) {
  834. if (signal_pending(current))
  835. break;
  836. msleep_interruptible(20);
  837. if (time_after_eq(jiffies, tend))
  838. break;
  839. }
  840. }
  841. /*****************************************************************************/
  842. static void stl_close(struct tty_struct *tty, struct file *filp)
  843. {
  844. struct stlport *portp;
  845. unsigned long flags;
  846. pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
  847. portp = tty->driver_data;
  848. if (portp == NULL)
  849. return;
  850. spin_lock_irqsave(&stallion_lock, flags);
  851. if (tty_hung_up_p(filp)) {
  852. spin_unlock_irqrestore(&stallion_lock, flags);
  853. return;
  854. }
  855. if ((tty->count == 1) && (portp->refcount != 1))
  856. portp->refcount = 1;
  857. if (portp->refcount-- > 1) {
  858. spin_unlock_irqrestore(&stallion_lock, flags);
  859. return;
  860. }
  861. portp->refcount = 0;
  862. portp->flags |= ASYNC_CLOSING;
  863. /*
  864. * May want to wait for any data to drain before closing. The BUSY
  865. * flag keeps track of whether we are still sending or not - it is
  866. * very accurate for the cd1400, not quite so for the sc26198.
  867. * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
  868. */
  869. tty->closing = 1;
  870. spin_unlock_irqrestore(&stallion_lock, flags);
  871. if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  872. tty_wait_until_sent(tty, portp->closing_wait);
  873. stl_waituntilsent(tty, (HZ / 2));
  874. spin_lock_irqsave(&stallion_lock, flags);
  875. portp->flags &= ~ASYNC_INITIALIZED;
  876. spin_unlock_irqrestore(&stallion_lock, flags);
  877. stl_disableintrs(portp);
  878. if (tty->termios->c_cflag & HUPCL)
  879. stl_setsignals(portp, 0, 0);
  880. stl_enablerxtx(portp, 0, 0);
  881. stl_flushbuffer(tty);
  882. portp->istate = 0;
  883. if (portp->tx.buf != NULL) {
  884. kfree(portp->tx.buf);
  885. portp->tx.buf = NULL;
  886. portp->tx.head = NULL;
  887. portp->tx.tail = NULL;
  888. }
  889. set_bit(TTY_IO_ERROR, &tty->flags);
  890. tty_ldisc_flush(tty);
  891. tty->closing = 0;
  892. portp->tty = NULL;
  893. if (portp->openwaitcnt) {
  894. if (portp->close_delay)
  895. msleep_interruptible(jiffies_to_msecs(portp->close_delay));
  896. wake_up_interruptible(&portp->open_wait);
  897. }
  898. portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  899. wake_up_interruptible(&portp->close_wait);
  900. }
  901. /*****************************************************************************/
  902. /*
  903. * Write routine. Take data and stuff it in to the TX ring queue.
  904. * If transmit interrupts are not running then start them.
  905. */
  906. static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
  907. {
  908. struct stlport *portp;
  909. unsigned int len, stlen;
  910. unsigned char *chbuf;
  911. char *head, *tail;
  912. pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty, buf, count);
  913. portp = tty->driver_data;
  914. if (portp == NULL)
  915. return 0;
  916. if (portp->tx.buf == NULL)
  917. return 0;
  918. /*
  919. * If copying direct from user space we must cater for page faults,
  920. * causing us to "sleep" here for a while. To handle this copy in all
  921. * the data we need now, into a local buffer. Then when we got it all
  922. * copy it into the TX buffer.
  923. */
  924. chbuf = (unsigned char *) buf;
  925. head = portp->tx.head;
  926. tail = portp->tx.tail;
  927. if (head >= tail) {
  928. len = STL_TXBUFSIZE - (head - tail) - 1;
  929. stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
  930. } else {
  931. len = tail - head - 1;
  932. stlen = len;
  933. }
  934. len = MIN(len, count);
  935. count = 0;
  936. while (len > 0) {
  937. stlen = MIN(len, stlen);
  938. memcpy(head, chbuf, stlen);
  939. len -= stlen;
  940. chbuf += stlen;
  941. count += stlen;
  942. head += stlen;
  943. if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
  944. head = portp->tx.buf;
  945. stlen = tail - head;
  946. }
  947. }
  948. portp->tx.head = head;
  949. clear_bit(ASYI_TXLOW, &portp->istate);
  950. stl_startrxtx(portp, -1, 1);
  951. return count;
  952. }
  953. /*****************************************************************************/
  954. static void stl_putchar(struct tty_struct *tty, unsigned char ch)
  955. {
  956. struct stlport *portp;
  957. unsigned int len;
  958. char *head, *tail;
  959. pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
  960. if (tty == NULL)
  961. return;
  962. portp = tty->driver_data;
  963. if (portp == NULL)
  964. return;
  965. if (portp->tx.buf == NULL)
  966. return;
  967. head = portp->tx.head;
  968. tail = portp->tx.tail;
  969. len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
  970. len--;
  971. if (len > 0) {
  972. *head++ = ch;
  973. if (head >= (portp->tx.buf + STL_TXBUFSIZE))
  974. head = portp->tx.buf;
  975. }
  976. portp->tx.head = head;
  977. }
  978. /*****************************************************************************/
  979. /*
  980. * If there are any characters in the buffer then make sure that TX
  981. * interrupts are on and get'em out. Normally used after the putchar
  982. * routine has been called.
  983. */
  984. static void stl_flushchars(struct tty_struct *tty)
  985. {
  986. struct stlport *portp;
  987. pr_debug("stl_flushchars(tty=%p)\n", tty);
  988. if (tty == NULL)
  989. return;
  990. portp = tty->driver_data;
  991. if (portp == NULL)
  992. return;
  993. if (portp->tx.buf == NULL)
  994. return;
  995. stl_startrxtx(portp, -1, 1);
  996. }
  997. /*****************************************************************************/
  998. static int stl_writeroom(struct tty_struct *tty)
  999. {
  1000. struct stlport *portp;
  1001. char *head, *tail;
  1002. pr_debug("stl_writeroom(tty=%p)\n", tty);
  1003. if (tty == NULL)
  1004. return 0;
  1005. portp = tty->driver_data;
  1006. if (portp == NULL)
  1007. return 0;
  1008. if (portp->tx.buf == NULL)
  1009. return 0;
  1010. head = portp->tx.head;
  1011. tail = portp->tx.tail;
  1012. return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
  1013. }
  1014. /*****************************************************************************/
  1015. /*
  1016. * Return number of chars in the TX buffer. Normally we would just
  1017. * calculate the number of chars in the buffer and return that, but if
  1018. * the buffer is empty and TX interrupts are still on then we return
  1019. * that the buffer still has 1 char in it. This way whoever called us
  1020. * will not think that ALL chars have drained - since the UART still
  1021. * must have some chars in it (we are busy after all).
  1022. */
  1023. static int stl_charsinbuffer(struct tty_struct *tty)
  1024. {
  1025. struct stlport *portp;
  1026. unsigned int size;
  1027. char *head, *tail;
  1028. pr_debug("stl_charsinbuffer(tty=%p)\n", tty);
  1029. if (tty == NULL)
  1030. return 0;
  1031. portp = tty->driver_data;
  1032. if (portp == NULL)
  1033. return 0;
  1034. if (portp->tx.buf == NULL)
  1035. return 0;
  1036. head = portp->tx.head;
  1037. tail = portp->tx.tail;
  1038. size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  1039. if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
  1040. size = 1;
  1041. return size;
  1042. }
  1043. /*****************************************************************************/
  1044. /*
  1045. * Generate the serial struct info.
  1046. */
  1047. static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
  1048. {
  1049. struct serial_struct sio;
  1050. struct stlbrd *brdp;
  1051. pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp);
  1052. memset(&sio, 0, sizeof(struct serial_struct));
  1053. sio.line = portp->portnr;
  1054. sio.port = portp->ioaddr;
  1055. sio.flags = portp->flags;
  1056. sio.baud_base = portp->baud_base;
  1057. sio.close_delay = portp->close_delay;
  1058. sio.closing_wait = portp->closing_wait;
  1059. sio.custom_divisor = portp->custom_divisor;
  1060. sio.hub6 = 0;
  1061. if (portp->uartp == &stl_cd1400uart) {
  1062. sio.type = PORT_CIRRUS;
  1063. sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
  1064. } else {
  1065. sio.type = PORT_UNKNOWN;
  1066. sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
  1067. }
  1068. brdp = stl_brds[portp->brdnr];
  1069. if (brdp != NULL)
  1070. sio.irq = brdp->irq;
  1071. return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
  1072. }
  1073. /*****************************************************************************/
  1074. /*
  1075. * Set port according to the serial struct info.
  1076. * At this point we do not do any auto-configure stuff, so we will
  1077. * just quietly ignore any requests to change irq, etc.
  1078. */
  1079. static int stl_setserial(struct stlport *portp, struct serial_struct __user *sp)
  1080. {
  1081. struct serial_struct sio;
  1082. pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp);
  1083. if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
  1084. return -EFAULT;
  1085. if (!capable(CAP_SYS_ADMIN)) {
  1086. if ((sio.baud_base != portp->baud_base) ||
  1087. (sio.close_delay != portp->close_delay) ||
  1088. ((sio.flags & ~ASYNC_USR_MASK) !=
  1089. (portp->flags & ~ASYNC_USR_MASK)))
  1090. return -EPERM;
  1091. }
  1092. portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
  1093. (sio.flags & ASYNC_USR_MASK);
  1094. portp->baud_base = sio.baud_base;
  1095. portp->close_delay = sio.close_delay;
  1096. portp->closing_wait = sio.closing_wait;
  1097. portp->custom_divisor = sio.custom_divisor;
  1098. stl_setport(portp, portp->tty->termios);
  1099. return 0;
  1100. }
  1101. /*****************************************************************************/
  1102. static int stl_tiocmget(struct tty_struct *tty, struct file *file)
  1103. {
  1104. struct stlport *portp;
  1105. if (tty == NULL)
  1106. return -ENODEV;
  1107. portp = tty->driver_data;
  1108. if (portp == NULL)
  1109. return -ENODEV;
  1110. if (tty->flags & (1 << TTY_IO_ERROR))
  1111. return -EIO;
  1112. return stl_getsignals(portp);
  1113. }
  1114. static int stl_tiocmset(struct tty_struct *tty, struct file *file,
  1115. unsigned int set, unsigned int clear)
  1116. {
  1117. struct stlport *portp;
  1118. int rts = -1, dtr = -1;
  1119. if (tty == NULL)
  1120. return -ENODEV;
  1121. portp = tty->driver_data;
  1122. if (portp == NULL)
  1123. return -ENODEV;
  1124. if (tty->flags & (1 << TTY_IO_ERROR))
  1125. return -EIO;
  1126. if (set & TIOCM_RTS)
  1127. rts = 1;
  1128. if (set & TIOCM_DTR)
  1129. dtr = 1;
  1130. if (clear & TIOCM_RTS)
  1131. rts = 0;
  1132. if (clear & TIOCM_DTR)
  1133. dtr = 0;
  1134. stl_setsignals(portp, dtr, rts);
  1135. return 0;
  1136. }
  1137. static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
  1138. {
  1139. struct stlport *portp;
  1140. unsigned int ival;
  1141. int rc;
  1142. void __user *argp = (void __user *)arg;
  1143. pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd,
  1144. arg);
  1145. if (tty == NULL)
  1146. return -ENODEV;
  1147. portp = tty->driver_data;
  1148. if (portp == NULL)
  1149. return -ENODEV;
  1150. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1151. (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
  1152. if (tty->flags & (1 << TTY_IO_ERROR))
  1153. return -EIO;
  1154. }
  1155. rc = 0;
  1156. switch (cmd) {
  1157. case TIOCGSOFTCAR:
  1158. rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
  1159. (unsigned __user *) argp);
  1160. break;
  1161. case TIOCSSOFTCAR:
  1162. if (get_user(ival, (unsigned int __user *) arg))
  1163. return -EFAULT;
  1164. tty->termios->c_cflag =
  1165. (tty->termios->c_cflag & ~CLOCAL) |
  1166. (ival ? CLOCAL : 0);
  1167. break;
  1168. case TIOCGSERIAL:
  1169. rc = stl_getserial(portp, argp);
  1170. break;
  1171. case TIOCSSERIAL:
  1172. rc = stl_setserial(portp, argp);
  1173. break;
  1174. case COM_GETPORTSTATS:
  1175. rc = stl_getportstats(portp, argp);
  1176. break;
  1177. case COM_CLRPORTSTATS:
  1178. rc = stl_clrportstats(portp, argp);
  1179. break;
  1180. case TIOCSERCONFIG:
  1181. case TIOCSERGWILD:
  1182. case TIOCSERSWILD:
  1183. case TIOCSERGETLSR:
  1184. case TIOCSERGSTRUCT:
  1185. case TIOCSERGETMULTI:
  1186. case TIOCSERSETMULTI:
  1187. default:
  1188. rc = -ENOIOCTLCMD;
  1189. break;
  1190. }
  1191. return rc;
  1192. }
  1193. /*****************************************************************************/
  1194. /*
  1195. * Start the transmitter again. Just turn TX interrupts back on.
  1196. */
  1197. static void stl_start(struct tty_struct *tty)
  1198. {
  1199. struct stlport *portp;
  1200. pr_debug("stl_start(tty=%p)\n", tty);
  1201. if (tty == NULL)
  1202. return;
  1203. portp = tty->driver_data;
  1204. if (portp == NULL)
  1205. return;
  1206. stl_startrxtx(portp, -1, 1);
  1207. }
  1208. /*****************************************************************************/
  1209. static void stl_settermios(struct tty_struct *tty, struct termios *old)
  1210. {
  1211. struct stlport *portp;
  1212. struct termios *tiosp;
  1213. pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old);
  1214. if (tty == NULL)
  1215. return;
  1216. portp = tty->driver_data;
  1217. if (portp == NULL)
  1218. return;
  1219. tiosp = tty->termios;
  1220. if ((tiosp->c_cflag == old->c_cflag) &&
  1221. (tiosp->c_iflag == old->c_iflag))
  1222. return;
  1223. stl_setport(portp, tiosp);
  1224. stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
  1225. -1);
  1226. if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
  1227. tty->hw_stopped = 0;
  1228. stl_start(tty);
  1229. }
  1230. if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
  1231. wake_up_interruptible(&portp->open_wait);
  1232. }
  1233. /*****************************************************************************/
  1234. /*
  1235. * Attempt to flow control who ever is sending us data. Based on termios
  1236. * settings use software or/and hardware flow control.
  1237. */
  1238. static void stl_throttle(struct tty_struct *tty)
  1239. {
  1240. struct stlport *portp;
  1241. pr_debug("stl_throttle(tty=%p)\n", tty);
  1242. if (tty == NULL)
  1243. return;
  1244. portp = tty->driver_data;
  1245. if (portp == NULL)
  1246. return;
  1247. stl_flowctrl(portp, 0);
  1248. }
  1249. /*****************************************************************************/
  1250. /*
  1251. * Unflow control the device sending us data...
  1252. */
  1253. static void stl_unthrottle(struct tty_struct *tty)
  1254. {
  1255. struct stlport *portp;
  1256. pr_debug("stl_unthrottle(tty=%p)\n", tty);
  1257. if (tty == NULL)
  1258. return;
  1259. portp = tty->driver_data;
  1260. if (portp == NULL)
  1261. return;
  1262. stl_flowctrl(portp, 1);
  1263. }
  1264. /*****************************************************************************/
  1265. /*
  1266. * Stop the transmitter. Basically to do this we will just turn TX
  1267. * interrupts off.
  1268. */
  1269. static void stl_stop(struct tty_struct *tty)
  1270. {
  1271. struct stlport *portp;
  1272. pr_debug("stl_stop(tty=%p)\n", tty);
  1273. if (tty == NULL)
  1274. return;
  1275. portp = tty->driver_data;
  1276. if (portp == NULL)
  1277. return;
  1278. stl_startrxtx(portp, -1, 0);
  1279. }
  1280. /*****************************************************************************/
  1281. /*
  1282. * Hangup this port. This is pretty much like closing the port, only
  1283. * a little more brutal. No waiting for data to drain. Shutdown the
  1284. * port and maybe drop signals.
  1285. */
  1286. static void stl_hangup(struct tty_struct *tty)
  1287. {
  1288. struct stlport *portp;
  1289. pr_debug("stl_hangup(tty=%p)\n", tty);
  1290. if (tty == NULL)
  1291. return;
  1292. portp = tty->driver_data;
  1293. if (portp == NULL)
  1294. return;
  1295. portp->flags &= ~ASYNC_INITIALIZED;
  1296. stl_disableintrs(portp);
  1297. if (tty->termios->c_cflag & HUPCL)
  1298. stl_setsignals(portp, 0, 0);
  1299. stl_enablerxtx(portp, 0, 0);
  1300. stl_flushbuffer(tty);
  1301. portp->istate = 0;
  1302. set_bit(TTY_IO_ERROR, &tty->flags);
  1303. if (portp->tx.buf != NULL) {
  1304. kfree(portp->tx.buf);
  1305. portp->tx.buf = NULL;
  1306. portp->tx.head = NULL;
  1307. portp->tx.tail = NULL;
  1308. }
  1309. portp->tty = NULL;
  1310. portp->flags &= ~ASYNC_NORMAL_ACTIVE;
  1311. portp->refcount = 0;
  1312. wake_up_interruptible(&portp->open_wait);
  1313. }
  1314. /*****************************************************************************/
  1315. static void stl_breakctl(struct tty_struct *tty, int state)
  1316. {
  1317. struct stlport *portp;
  1318. pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
  1319. if (tty == NULL)
  1320. return;
  1321. portp = tty->driver_data;
  1322. if (portp == NULL)
  1323. return;
  1324. stl_sendbreak(portp, ((state == -1) ? 1 : 2));
  1325. }
  1326. /*****************************************************************************/
  1327. static void stl_sendxchar(struct tty_struct *tty, char ch)
  1328. {
  1329. struct stlport *portp;
  1330. pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch);
  1331. if (tty == NULL)
  1332. return;
  1333. portp = tty->driver_data;
  1334. if (portp == NULL)
  1335. return;
  1336. if (ch == STOP_CHAR(tty))
  1337. stl_sendflow(portp, 0);
  1338. else if (ch == START_CHAR(tty))
  1339. stl_sendflow(portp, 1);
  1340. else
  1341. stl_putchar(tty, ch);
  1342. }
  1343. /*****************************************************************************/
  1344. #define MAXLINE 80
  1345. /*
  1346. * Format info for a specified port. The line is deliberately limited
  1347. * to 80 characters. (If it is too long it will be truncated, if too
  1348. * short then padded with spaces).
  1349. */
  1350. static int stl_portinfo(struct stlport *portp, int portnr, char *pos)
  1351. {
  1352. char *sp;
  1353. int sigs, cnt;
  1354. sp = pos;
  1355. sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
  1356. portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
  1357. (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
  1358. if (portp->stats.rxframing)
  1359. sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
  1360. if (portp->stats.rxparity)
  1361. sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
  1362. if (portp->stats.rxbreaks)
  1363. sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
  1364. if (portp->stats.rxoverrun)
  1365. sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
  1366. sigs = stl_getsignals(portp);
  1367. cnt = sprintf(sp, "%s%s%s%s%s ",
  1368. (sigs & TIOCM_RTS) ? "|RTS" : "",
  1369. (sigs & TIOCM_CTS) ? "|CTS" : "",
  1370. (sigs & TIOCM_DTR) ? "|DTR" : "",
  1371. (sigs & TIOCM_CD) ? "|DCD" : "",
  1372. (sigs & TIOCM_DSR) ? "|DSR" : "");
  1373. *sp = ' ';
  1374. sp += cnt;
  1375. for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
  1376. *sp++ = ' ';
  1377. if (cnt >= MAXLINE)
  1378. pos[(MAXLINE - 2)] = '+';
  1379. pos[(MAXLINE - 1)] = '\n';
  1380. return MAXLINE;
  1381. }
  1382. /*****************************************************************************/
  1383. /*
  1384. * Port info, read from the /proc file system.
  1385. */
  1386. static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
  1387. {
  1388. struct stlbrd *brdp;
  1389. struct stlpanel *panelp;
  1390. struct stlport *portp;
  1391. int brdnr, panelnr, portnr, totalport;
  1392. int curoff, maxoff;
  1393. char *pos;
  1394. pr_debug("stl_readproc(page=%p,start=%p,off=%lx,count=%d,eof=%p,"
  1395. "data=%p\n", page, start, off, count, eof, data);
  1396. pos = page;
  1397. totalport = 0;
  1398. curoff = 0;
  1399. if (off == 0) {
  1400. pos += sprintf(pos, "%s: version %s", stl_drvtitle,
  1401. stl_drvversion);
  1402. while (pos < (page + MAXLINE - 1))
  1403. *pos++ = ' ';
  1404. *pos++ = '\n';
  1405. }
  1406. curoff = MAXLINE;
  1407. /*
  1408. * We scan through for each board, panel and port. The offset is
  1409. * calculated on the fly, and irrelevant ports are skipped.
  1410. */
  1411. for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
  1412. brdp = stl_brds[brdnr];
  1413. if (brdp == NULL)
  1414. continue;
  1415. if (brdp->state == 0)
  1416. continue;
  1417. maxoff = curoff + (brdp->nrports * MAXLINE);
  1418. if (off >= maxoff) {
  1419. curoff = maxoff;
  1420. continue;
  1421. }
  1422. totalport = brdnr * STL_MAXPORTS;
  1423. for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
  1424. panelp = brdp->panels[panelnr];
  1425. if (panelp == NULL)
  1426. continue;
  1427. maxoff = curoff + (panelp->nrports * MAXLINE);
  1428. if (off >= maxoff) {
  1429. curoff = maxoff;
  1430. totalport += panelp->nrports;
  1431. continue;
  1432. }
  1433. for (portnr = 0; (portnr < panelp->nrports); portnr++,
  1434. totalport++) {
  1435. portp = panelp->ports[portnr];
  1436. if (portp == NULL)
  1437. continue;
  1438. if (off >= (curoff += MAXLINE))
  1439. continue;
  1440. if ((pos - page + MAXLINE) > count)
  1441. goto stl_readdone;
  1442. pos += stl_portinfo(portp, totalport, pos);
  1443. }
  1444. }
  1445. }
  1446. *eof = 1;
  1447. stl_readdone:
  1448. *start = page;
  1449. return (pos - page);
  1450. }
  1451. /*****************************************************************************/
  1452. /*
  1453. * All board interrupts are vectored through here first. This code then
  1454. * calls off to the approrpriate board interrupt handlers.
  1455. */
  1456. static irqreturn_t stl_intr(int irq, void *dev_id)
  1457. {
  1458. struct stlbrd *brdp = dev_id;
  1459. pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp, irq);
  1460. return IRQ_RETVAL((* brdp->isr)(brdp));
  1461. }
  1462. /*****************************************************************************/
  1463. /*
  1464. * Interrupt service routine for EasyIO board types.
  1465. */
  1466. static int stl_eiointr(struct stlbrd *brdp)
  1467. {
  1468. struct stlpanel *panelp;
  1469. unsigned int iobase;
  1470. int handled = 0;
  1471. spin_lock(&brd_lock);
  1472. panelp = brdp->panels[0];
  1473. iobase = panelp->iobase;
  1474. while (inb(brdp->iostatus) & EIO_INTRPEND) {
  1475. handled = 1;
  1476. (* panelp->isr)(panelp, iobase);
  1477. }
  1478. spin_unlock(&brd_lock);
  1479. return handled;
  1480. }
  1481. /*****************************************************************************/
  1482. /*
  1483. * Interrupt service routine for ECH-AT board types.
  1484. */
  1485. static int stl_echatintr(struct stlbrd *brdp)
  1486. {
  1487. struct stlpanel *panelp;
  1488. unsigned int ioaddr;
  1489. int bnknr;
  1490. int handled = 0;
  1491. outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
  1492. while (inb(brdp->iostatus) & ECH_INTRPEND) {
  1493. handled = 1;
  1494. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1495. ioaddr = brdp->bnkstataddr[bnknr];
  1496. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1497. panelp = brdp->bnk2panel[bnknr];
  1498. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1499. }
  1500. }
  1501. }
  1502. outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
  1503. return handled;
  1504. }
  1505. /*****************************************************************************/
  1506. /*
  1507. * Interrupt service routine for ECH-MCA board types.
  1508. */
  1509. static int stl_echmcaintr(struct stlbrd *brdp)
  1510. {
  1511. struct stlpanel *panelp;
  1512. unsigned int ioaddr;
  1513. int bnknr;
  1514. int handled = 0;
  1515. while (inb(brdp->iostatus) & ECH_INTRPEND) {
  1516. handled = 1;
  1517. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1518. ioaddr = brdp->bnkstataddr[bnknr];
  1519. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1520. panelp = brdp->bnk2panel[bnknr];
  1521. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1522. }
  1523. }
  1524. }
  1525. return handled;
  1526. }
  1527. /*****************************************************************************/
  1528. /*
  1529. * Interrupt service routine for ECH-PCI board types.
  1530. */
  1531. static int stl_echpciintr(struct stlbrd *brdp)
  1532. {
  1533. struct stlpanel *panelp;
  1534. unsigned int ioaddr;
  1535. int bnknr, recheck;
  1536. int handled = 0;
  1537. while (1) {
  1538. recheck = 0;
  1539. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1540. outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
  1541. ioaddr = brdp->bnkstataddr[bnknr];
  1542. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1543. panelp = brdp->bnk2panel[bnknr];
  1544. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1545. recheck++;
  1546. handled = 1;
  1547. }
  1548. }
  1549. if (! recheck)
  1550. break;
  1551. }
  1552. return handled;
  1553. }
  1554. /*****************************************************************************/
  1555. /*
  1556. * Interrupt service routine for ECH-8/64-PCI board types.
  1557. */
  1558. static int stl_echpci64intr(struct stlbrd *brdp)
  1559. {
  1560. struct stlpanel *panelp;
  1561. unsigned int ioaddr;
  1562. int bnknr;
  1563. int handled = 0;
  1564. while (inb(brdp->ioctrl) & 0x1) {
  1565. handled = 1;
  1566. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1567. ioaddr = brdp->bnkstataddr[bnknr];
  1568. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1569. panelp = brdp->bnk2panel[bnknr];
  1570. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1571. }
  1572. }
  1573. }
  1574. return handled;
  1575. }
  1576. /*****************************************************************************/
  1577. /*
  1578. * Service an off-level request for some channel.
  1579. */
  1580. static void stl_offintr(struct work_struct *work)
  1581. {
  1582. struct stlport *portp = container_of(work, struct stlport, tqueue);
  1583. struct tty_struct *tty;
  1584. unsigned int oldsigs;
  1585. pr_debug("stl_offintr(portp=%p)\n", portp);
  1586. if (portp == NULL)
  1587. return;
  1588. tty = portp->tty;
  1589. if (tty == NULL)
  1590. return;
  1591. lock_kernel();
  1592. if (test_bit(ASYI_TXLOW, &portp->istate)) {
  1593. tty_wakeup(tty);
  1594. }
  1595. if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
  1596. clear_bit(ASYI_DCDCHANGE, &portp->istate);
  1597. oldsigs = portp->sigs;
  1598. portp->sigs = stl_getsignals(portp);
  1599. if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
  1600. wake_up_interruptible(&portp->open_wait);
  1601. if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
  1602. if (portp->flags & ASYNC_CHECK_CD)
  1603. tty_hangup(tty); /* FIXME: module removal race here - AKPM */
  1604. }
  1605. }
  1606. unlock_kernel();
  1607. }
  1608. /*****************************************************************************/
  1609. /*
  1610. * Initialize all the ports on a panel.
  1611. */
  1612. static int __init stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
  1613. {
  1614. struct stlport *portp;
  1615. int chipmask, i;
  1616. pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp);
  1617. chipmask = stl_panelinit(brdp, panelp);
  1618. /*
  1619. * All UART's are initialized (if found!). Now go through and setup
  1620. * each ports data structures.
  1621. */
  1622. for (i = 0; (i < panelp->nrports); i++) {
  1623. portp = kzalloc(sizeof(struct stlport), GFP_KERNEL);
  1624. if (!portp) {
  1625. printk("STALLION: failed to allocate memory "
  1626. "(size=%Zd)\n", sizeof(struct stlport));
  1627. break;
  1628. }
  1629. portp->magic = STL_PORTMAGIC;
  1630. portp->portnr = i;
  1631. portp->brdnr = panelp->brdnr;
  1632. portp->panelnr = panelp->panelnr;
  1633. portp->uartp = panelp->uartp;
  1634. portp->clk = brdp->clk;
  1635. portp->baud_base = STL_BAUDBASE;
  1636. portp->close_delay = STL_CLOSEDELAY;
  1637. portp->closing_wait = 30 * HZ;
  1638. INIT_WORK(&portp->tqueue, stl_offintr);
  1639. init_waitqueue_head(&portp->open_wait);
  1640. init_waitqueue_head(&portp->close_wait);
  1641. portp->stats.brd = portp->brdnr;
  1642. portp->stats.panel = portp->panelnr;
  1643. portp->stats.port = portp->portnr;
  1644. panelp->ports[i] = portp;
  1645. stl_portinit(brdp, panelp, portp);
  1646. }
  1647. return(0);
  1648. }
  1649. /*****************************************************************************/
  1650. /*
  1651. * Try to find and initialize an EasyIO board.
  1652. */
  1653. static int __init stl_initeio(struct stlbrd *brdp)
  1654. {
  1655. struct stlpanel *panelp;
  1656. unsigned int status;
  1657. char *name;
  1658. int rc;
  1659. pr_debug("stl_initeio(brdp=%p)\n", brdp);
  1660. brdp->ioctrl = brdp->ioaddr1 + 1;
  1661. brdp->iostatus = brdp->ioaddr1 + 2;
  1662. status = inb(brdp->iostatus);
  1663. if ((status & EIO_IDBITMASK) == EIO_MK3)
  1664. brdp->ioctrl++;
  1665. /*
  1666. * Handle board specific stuff now. The real difference is PCI
  1667. * or not PCI.
  1668. */
  1669. if (brdp->brdtype == BRD_EASYIOPCI) {
  1670. brdp->iosize1 = 0x80;
  1671. brdp->iosize2 = 0x80;
  1672. name = "serial(EIO-PCI)";
  1673. outb(0x41, (brdp->ioaddr2 + 0x4c));
  1674. } else {
  1675. brdp->iosize1 = 8;
  1676. name = "serial(EIO)";
  1677. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  1678. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  1679. printk("STALLION: invalid irq=%d for brd=%d\n",
  1680. brdp->irq, brdp->brdnr);
  1681. return(-EINVAL);
  1682. }
  1683. outb((stl_vecmap[brdp->irq] | EIO_0WS |
  1684. ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
  1685. brdp->ioctrl);
  1686. }
  1687. if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
  1688. printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
  1689. "%x conflicts with another device\n", brdp->brdnr,
  1690. brdp->ioaddr1);
  1691. return(-EBUSY);
  1692. }
  1693. if (brdp->iosize2 > 0)
  1694. if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
  1695. printk(KERN_WARNING "STALLION: Warning, board %d I/O "
  1696. "address %x conflicts with another device\n",
  1697. brdp->brdnr, brdp->ioaddr2);
  1698. printk(KERN_WARNING "STALLION: Warning, also "
  1699. "releasing board %d I/O address %x \n",
  1700. brdp->brdnr, brdp->ioaddr1);
  1701. release_region(brdp->ioaddr1, brdp->iosize1);
  1702. return(-EBUSY);
  1703. }
  1704. /*
  1705. * Everything looks OK, so let's go ahead and probe for the hardware.
  1706. */
  1707. brdp->clk = CD1400_CLK;
  1708. brdp->isr = stl_eiointr;
  1709. switch (status & EIO_IDBITMASK) {
  1710. case EIO_8PORTM:
  1711. brdp->clk = CD1400_CLK8M;
  1712. /* fall thru */
  1713. case EIO_8PORTRS:
  1714. case EIO_8PORTDI:
  1715. brdp->nrports = 8;
  1716. break;
  1717. case EIO_4PORTRS:
  1718. brdp->nrports = 4;
  1719. break;
  1720. case EIO_MK3:
  1721. switch (status & EIO_BRDMASK) {
  1722. case ID_BRD4:
  1723. brdp->nrports = 4;
  1724. break;
  1725. case ID_BRD8:
  1726. brdp->nrports = 8;
  1727. break;
  1728. case ID_BRD16:
  1729. brdp->nrports = 16;
  1730. break;
  1731. default:
  1732. return(-ENODEV);
  1733. }
  1734. break;
  1735. default:
  1736. return(-ENODEV);
  1737. }
  1738. /*
  1739. * We have verified that the board is actually present, so now we
  1740. * can complete the setup.
  1741. */
  1742. panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
  1743. if (!panelp) {
  1744. printk(KERN_WARNING "STALLION: failed to allocate memory "
  1745. "(size=%Zd)\n", sizeof(struct stlpanel));
  1746. return -ENOMEM;
  1747. }
  1748. panelp->magic = STL_PANELMAGIC;
  1749. panelp->brdnr = brdp->brdnr;
  1750. panelp->panelnr = 0;
  1751. panelp->nrports = brdp->nrports;
  1752. panelp->iobase = brdp->ioaddr1;
  1753. panelp->hwid = status;
  1754. if ((status & EIO_IDBITMASK) == EIO_MK3) {
  1755. panelp->uartp = &stl_sc26198uart;
  1756. panelp->isr = stl_sc26198intr;
  1757. } else {
  1758. panelp->uartp = &stl_cd1400uart;
  1759. panelp->isr = stl_cd1400eiointr;
  1760. }
  1761. brdp->panels[0] = panelp;
  1762. brdp->nrpanels = 1;
  1763. brdp->state |= BRD_FOUND;
  1764. brdp->hwid = status;
  1765. if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
  1766. printk("STALLION: failed to register interrupt "
  1767. "routine for %s irq=%d\n", name, brdp->irq);
  1768. rc = -ENODEV;
  1769. } else {
  1770. rc = 0;
  1771. }
  1772. return rc;
  1773. }
  1774. /*****************************************************************************/
  1775. /*
  1776. * Try to find an ECH board and initialize it. This code is capable of
  1777. * dealing with all types of ECH board.
  1778. */
  1779. static int __init stl_initech(struct stlbrd *brdp)
  1780. {
  1781. struct stlpanel *panelp;
  1782. unsigned int status, nxtid, ioaddr, conflict;
  1783. int panelnr, banknr, i;
  1784. char *name;
  1785. pr_debug("stl_initech(brdp=%p)\n", brdp);
  1786. status = 0;
  1787. conflict = 0;
  1788. /*
  1789. * Set up the initial board register contents for boards. This varies a
  1790. * bit between the different board types. So we need to handle each
  1791. * separately. Also do a check that the supplied IRQ is good.
  1792. */
  1793. switch (brdp->brdtype) {
  1794. case BRD_ECH:
  1795. brdp->isr = stl_echatintr;
  1796. brdp->ioctrl = brdp->ioaddr1 + 1;
  1797. brdp->iostatus = brdp->ioaddr1 + 1;
  1798. status = inb(brdp->iostatus);
  1799. if ((status & ECH_IDBITMASK) != ECH_ID)
  1800. return(-ENODEV);
  1801. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  1802. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  1803. printk("STALLION: invalid irq=%d for brd=%d\n",
  1804. brdp->irq, brdp->brdnr);
  1805. return(-EINVAL);
  1806. }
  1807. status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
  1808. status |= (stl_vecmap[brdp->irq] << 1);
  1809. outb((status | ECH_BRDRESET), brdp->ioaddr1);
  1810. brdp->ioctrlval = ECH_INTENABLE |
  1811. ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
  1812. for (i = 0; (i < 10); i++)
  1813. outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
  1814. brdp->iosize1 = 2;
  1815. brdp->iosize2 = 32;
  1816. name = "serial(EC8/32)";
  1817. outb(status, brdp->ioaddr1);
  1818. break;
  1819. case BRD_ECHMC:
  1820. brdp->isr = stl_echmcaintr;
  1821. brdp->ioctrl = brdp->ioaddr1 + 0x20;
  1822. brdp->iostatus = brdp->ioctrl;
  1823. status = inb(brdp->iostatus);
  1824. if ((status & ECH_IDBITMASK) != ECH_ID)
  1825. return(-ENODEV);
  1826. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  1827. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  1828. printk("STALLION: invalid irq=%d for brd=%d\n",
  1829. brdp->irq, brdp->brdnr);
  1830. return(-EINVAL);
  1831. }
  1832. outb(ECHMC_BRDRESET, brdp->ioctrl);
  1833. outb(ECHMC_INTENABLE, brdp->ioctrl);
  1834. brdp->iosize1 = 64;
  1835. name = "serial(EC8/32-MC)";
  1836. break;
  1837. case BRD_ECHPCI:
  1838. brdp->isr = stl_echpciintr;
  1839. brdp->ioctrl = brdp->ioaddr1 + 2;
  1840. brdp->iosize1 = 4;
  1841. brdp->iosize2 = 8;
  1842. name = "serial(EC8/32-PCI)";
  1843. break;
  1844. case BRD_ECH64PCI:
  1845. brdp->isr = stl_echpci64intr;
  1846. brdp->ioctrl = brdp->ioaddr2 + 0x40;
  1847. outb(0x43, (brdp->ioaddr1 + 0x4c));
  1848. brdp->iosize1 = 0x80;
  1849. brdp->iosize2 = 0x80;
  1850. name = "serial(EC8/64-PCI)";
  1851. break;
  1852. default:
  1853. printk("STALLION: unknown board type=%d\n", brdp->brdtype);
  1854. return(-EINVAL);
  1855. break;
  1856. }
  1857. /*
  1858. * Check boards for possible IO address conflicts and return fail status
  1859. * if an IO conflict found.
  1860. */
  1861. if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
  1862. printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
  1863. "%x conflicts with another device\n", brdp->brdnr,
  1864. brdp->ioaddr1);
  1865. return(-EBUSY);
  1866. }
  1867. if (brdp->iosize2 > 0)
  1868. if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
  1869. printk(KERN_WARNING "STALLION: Warning, board %d I/O "
  1870. "address %x conflicts with another device\n",
  1871. brdp->brdnr, brdp->ioaddr2);
  1872. printk(KERN_WARNING "STALLION: Warning, also "
  1873. "releasing board %d I/O address %x \n",
  1874. brdp->brdnr, brdp->ioaddr1);
  1875. release_region(brdp->ioaddr1, brdp->iosize1);
  1876. return(-EBUSY);
  1877. }
  1878. /*
  1879. * Scan through the secondary io address space looking for panels.
  1880. * As we find'em allocate and initialize panel structures for each.
  1881. */
  1882. brdp->clk = CD1400_CLK;
  1883. brdp->hwid = status;
  1884. ioaddr = brdp->ioaddr2;
  1885. banknr = 0;
  1886. panelnr = 0;
  1887. nxtid = 0;
  1888. for (i = 0; (i < STL_MAXPANELS); i++) {
  1889. if (brdp->brdtype == BRD_ECHPCI) {
  1890. outb(nxtid, brdp->ioctrl);
  1891. ioaddr = brdp->ioaddr2;
  1892. }
  1893. status = inb(ioaddr + ECH_PNLSTATUS);
  1894. if ((status & ECH_PNLIDMASK) != nxtid)
  1895. break;
  1896. panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
  1897. if (!panelp) {
  1898. printk("STALLION: failed to allocate memory "
  1899. "(size=%Zd)\n", sizeof(struct stlpanel));
  1900. break;
  1901. }
  1902. panelp->magic = STL_PANELMAGIC;
  1903. panelp->brdnr = brdp->brdnr;
  1904. panelp->panelnr = panelnr;
  1905. panelp->iobase = ioaddr;
  1906. panelp->pagenr = nxtid;
  1907. panelp->hwid = status;
  1908. brdp->bnk2panel[banknr] = panelp;
  1909. brdp->bnkpageaddr[banknr] = nxtid;
  1910. brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
  1911. if (status & ECH_PNLXPID) {
  1912. panelp->uartp = &stl_sc26198uart;
  1913. panelp->isr = stl_sc26198intr;
  1914. if (status & ECH_PNL16PORT) {
  1915. panelp->nrports = 16;
  1916. brdp->bnk2panel[banknr] = panelp;
  1917. brdp->bnkpageaddr[banknr] = nxtid;
  1918. brdp->bnkstataddr[banknr++] = ioaddr + 4 +
  1919. ECH_PNLSTATUS;
  1920. } else {
  1921. panelp->nrports = 8;
  1922. }
  1923. } else {
  1924. panelp->uartp = &stl_cd1400uart;
  1925. panelp->isr = stl_cd1400echintr;
  1926. if (status & ECH_PNL16PORT) {
  1927. panelp->nrports = 16;
  1928. panelp->ackmask = 0x80;
  1929. if (brdp->brdtype != BRD_ECHPCI)
  1930. ioaddr += EREG_BANKSIZE;
  1931. brdp->bnk2panel[banknr] = panelp;
  1932. brdp->bnkpageaddr[banknr] = ++nxtid;
  1933. brdp->bnkstataddr[banknr++] = ioaddr +
  1934. ECH_PNLSTATUS;
  1935. } else {
  1936. panelp->nrports = 8;
  1937. panelp->ackmask = 0xc0;
  1938. }
  1939. }
  1940. nxtid++;
  1941. ioaddr += EREG_BANKSIZE;
  1942. brdp->nrports += panelp->nrports;
  1943. brdp->panels[panelnr++] = panelp;
  1944. if ((brdp->brdtype != BRD_ECHPCI) &&
  1945. (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
  1946. break;
  1947. }
  1948. brdp->nrpanels = panelnr;
  1949. brdp->nrbnks = banknr;
  1950. if (brdp->brdtype == BRD_ECH)
  1951. outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
  1952. brdp->state |= BRD_FOUND;
  1953. if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
  1954. printk("STALLION: failed to register interrupt "
  1955. "routine for %s irq=%d\n", name, brdp->irq);
  1956. i = -ENODEV;
  1957. } else {
  1958. i = 0;
  1959. }
  1960. return(i);
  1961. }
  1962. /*****************************************************************************/
  1963. /*
  1964. * Initialize and configure the specified board.
  1965. * Scan through all the boards in the configuration and see what we
  1966. * can find. Handle EIO and the ECH boards a little differently here
  1967. * since the initial search and setup is very different.
  1968. */
  1969. static int __init stl_brdinit(struct stlbrd *brdp)
  1970. {
  1971. int i;
  1972. pr_debug("stl_brdinit(brdp=%p)\n", brdp);
  1973. switch (brdp->brdtype) {
  1974. case BRD_EASYIO:
  1975. case BRD_EASYIOPCI:
  1976. stl_initeio(brdp);
  1977. break;
  1978. case BRD_ECH:
  1979. case BRD_ECHMC:
  1980. case BRD_ECHPCI:
  1981. case BRD_ECH64PCI:
  1982. stl_initech(brdp);
  1983. break;
  1984. default:
  1985. printk("STALLION: board=%d is unknown board type=%d\n",
  1986. brdp->brdnr, brdp->brdtype);
  1987. return(ENODEV);
  1988. }
  1989. stl_brds[brdp->brdnr] = brdp;
  1990. if ((brdp->state & BRD_FOUND) == 0) {
  1991. printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
  1992. stl_brdnames[brdp->brdtype], brdp->brdnr,
  1993. brdp->ioaddr1, brdp->irq);
  1994. return(ENODEV);
  1995. }
  1996. for (i = 0; (i < STL_MAXPANELS); i++)
  1997. if (brdp->panels[i] != NULL)
  1998. stl_initports(brdp, brdp->panels[i]);
  1999. printk("STALLION: %s found, board=%d io=%x irq=%d "
  2000. "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
  2001. brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
  2002. brdp->nrports);
  2003. return(0);
  2004. }
  2005. /*****************************************************************************/
  2006. /*
  2007. * Find the next available board number that is free.
  2008. */
  2009. static int __init stl_getbrdnr(void)
  2010. {
  2011. int i;
  2012. for (i = 0; (i < STL_MAXBRDS); i++) {
  2013. if (stl_brds[i] == NULL) {
  2014. if (i >= stl_nrbrds)
  2015. stl_nrbrds = i + 1;
  2016. return(i);
  2017. }
  2018. }
  2019. return(-1);
  2020. }
  2021. /*****************************************************************************/
  2022. #ifdef CONFIG_PCI
  2023. /*
  2024. * We have a Stallion board. Allocate a board structure and
  2025. * initialize it. Read its IO and IRQ resources from PCI
  2026. * configuration space.
  2027. */
  2028. static int __init stl_initpcibrd(int brdtype, struct pci_dev *devp)
  2029. {
  2030. struct stlbrd *brdp;
  2031. pr_debug("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
  2032. devp->bus->number, devp->devfn);
  2033. if (pci_enable_device(devp))
  2034. return(-EIO);
  2035. if ((brdp = stl_allocbrd()) == NULL)
  2036. return(-ENOMEM);
  2037. if ((brdp->brdnr = stl_getbrdnr()) < 0) {
  2038. printk("STALLION: too many boards found, "
  2039. "maximum supported %d\n", STL_MAXBRDS);
  2040. return(0);
  2041. }
  2042. brdp->brdtype = brdtype;
  2043. /*
  2044. * Different Stallion boards use the BAR registers in different ways,
  2045. * so set up io addresses based on board type.
  2046. */
  2047. pr_debug("%s(%d): BAR[]=%Lx,%Lx,%Lx,%Lx IRQ=%x\n", __FILE__, __LINE__,
  2048. pci_resource_start(devp, 0), pci_resource_start(devp, 1),
  2049. pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
  2050. /*
  2051. * We have all resources from the board, so let's setup the actual
  2052. * board structure now.
  2053. */
  2054. switch (brdtype) {
  2055. case BRD_ECHPCI:
  2056. brdp->ioaddr2 = pci_resource_start(devp, 0);
  2057. brdp->ioaddr1 = pci_resource_start(devp, 1);
  2058. break;
  2059. case BRD_ECH64PCI:
  2060. brdp->ioaddr2 = pci_resource_start(devp, 2);
  2061. brdp->ioaddr1 = pci_resource_start(devp, 1);
  2062. break;
  2063. case BRD_EASYIOPCI:
  2064. brdp->ioaddr1 = pci_resource_start(devp, 2);
  2065. brdp->ioaddr2 = pci_resource_start(devp, 1);
  2066. break;
  2067. default:
  2068. printk("STALLION: unknown PCI board type=%d\n", brdtype);
  2069. break;
  2070. }
  2071. brdp->irq = devp->irq;
  2072. stl_brdinit(brdp);
  2073. return(0);
  2074. }
  2075. /*****************************************************************************/
  2076. /*
  2077. * Find all Stallion PCI boards that might be installed. Initialize each
  2078. * one as it is found.
  2079. */
  2080. static int __init stl_findpcibrds(void)
  2081. {
  2082. struct pci_dev *dev = NULL;
  2083. int i, rc;
  2084. pr_debug("stl_findpcibrds()\n");
  2085. for (i = 0; (i < stl_nrpcibrds); i++)
  2086. while ((dev = pci_find_device(stl_pcibrds[i].vendid,
  2087. stl_pcibrds[i].devid, dev))) {
  2088. /*
  2089. * Found a device on the PCI bus that has our vendor and
  2090. * device ID. Need to check now that it is really us.
  2091. */
  2092. if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
  2093. continue;
  2094. rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
  2095. if (rc)
  2096. return(rc);
  2097. }
  2098. return(0);
  2099. }
  2100. #endif
  2101. /*****************************************************************************/
  2102. /*
  2103. * Scan through all the boards in the configuration and see what we
  2104. * can find. Handle EIO and the ECH boards a little differently here
  2105. * since the initial search and setup is too different.
  2106. */
  2107. static int __init stl_initbrds(void)
  2108. {
  2109. struct stlbrd *brdp;
  2110. struct stlconf *confp;
  2111. int i;
  2112. pr_debug("stl_initbrds()\n");
  2113. if (stl_nrbrds > STL_MAXBRDS) {
  2114. printk("STALLION: too many boards in configuration table, "
  2115. "truncating to %d\n", STL_MAXBRDS);
  2116. stl_nrbrds = STL_MAXBRDS;
  2117. }
  2118. /*
  2119. * Firstly scan the list of static boards configured. Allocate
  2120. * resources and initialize the boards as found.
  2121. */
  2122. for (i = 0; (i < stl_nrbrds); i++) {
  2123. confp = &stl_brdconf[i];
  2124. stl_parsebrd(confp, stl_brdsp[i]);
  2125. if ((brdp = stl_allocbrd()) == NULL)
  2126. return(-ENOMEM);
  2127. brdp->brdnr = i;
  2128. brdp->brdtype = confp->brdtype;
  2129. brdp->ioaddr1 = confp->ioaddr1;
  2130. brdp->ioaddr2 = confp->ioaddr2;
  2131. brdp->irq = confp->irq;
  2132. brdp->irqtype = confp->irqtype;
  2133. stl_brdinit(brdp);
  2134. }
  2135. /*
  2136. * Find any dynamically supported boards. That is via module load
  2137. * line options or auto-detected on the PCI bus.
  2138. */
  2139. stl_argbrds();
  2140. #ifdef CONFIG_PCI
  2141. stl_findpcibrds();
  2142. #endif
  2143. return(0);
  2144. }
  2145. /*****************************************************************************/
  2146. /*
  2147. * Return the board stats structure to user app.
  2148. */
  2149. static int stl_getbrdstats(combrd_t __user *bp)
  2150. {
  2151. struct stlbrd *brdp;
  2152. struct stlpanel *panelp;
  2153. int i;
  2154. if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
  2155. return -EFAULT;
  2156. if (stl_brdstats.brd >= STL_MAXBRDS)
  2157. return(-ENODEV);
  2158. brdp = stl_brds[stl_brdstats.brd];
  2159. if (brdp == NULL)
  2160. return(-ENODEV);
  2161. memset(&stl_brdstats, 0, sizeof(combrd_t));
  2162. stl_brdstats.brd = brdp->brdnr;
  2163. stl_brdstats.type = brdp->brdtype;
  2164. stl_brdstats.hwid = brdp->hwid;
  2165. stl_brdstats.state = brdp->state;
  2166. stl_brdstats.ioaddr = brdp->ioaddr1;
  2167. stl_brdstats.ioaddr2 = brdp->ioaddr2;
  2168. stl_brdstats.irq = brdp->irq;
  2169. stl_brdstats.nrpanels = brdp->nrpanels;
  2170. stl_brdstats.nrports = brdp->nrports;
  2171. for (i = 0; (i < brdp->nrpanels); i++) {
  2172. panelp = brdp->panels[i];
  2173. stl_brdstats.panels[i].panel = i;
  2174. stl_brdstats.panels[i].hwid = panelp->hwid;
  2175. stl_brdstats.panels[i].nrports = panelp->nrports;
  2176. }
  2177. return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
  2178. }
  2179. /*****************************************************************************/
  2180. /*
  2181. * Resolve the referenced port number into a port struct pointer.
  2182. */
  2183. static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
  2184. {
  2185. struct stlbrd *brdp;
  2186. struct stlpanel *panelp;
  2187. if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
  2188. return(NULL);
  2189. brdp = stl_brds[brdnr];
  2190. if (brdp == NULL)
  2191. return(NULL);
  2192. if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
  2193. return(NULL);
  2194. panelp = brdp->panels[panelnr];
  2195. if (panelp == NULL)
  2196. return(NULL);
  2197. if ((portnr < 0) || (portnr >= panelp->nrports))
  2198. return(NULL);
  2199. return(panelp->ports[portnr]);
  2200. }
  2201. /*****************************************************************************/
  2202. /*
  2203. * Return the port stats structure to user app. A NULL port struct
  2204. * pointer passed in means that we need to find out from the app
  2205. * what port to get stats for (used through board control device).
  2206. */
  2207. static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
  2208. {
  2209. unsigned char *head, *tail;
  2210. unsigned long flags;
  2211. if (!portp) {
  2212. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  2213. return -EFAULT;
  2214. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  2215. stl_comstats.port);
  2216. if (portp == NULL)
  2217. return(-ENODEV);
  2218. }
  2219. portp->stats.state = portp->istate;
  2220. portp->stats.flags = portp->flags;
  2221. portp->stats.hwid = portp->hwid;
  2222. portp->stats.ttystate = 0;
  2223. portp->stats.cflags = 0;
  2224. portp->stats.iflags = 0;
  2225. portp->stats.oflags = 0;
  2226. portp->stats.lflags = 0;
  2227. portp->stats.rxbuffered = 0;
  2228. spin_lock_irqsave(&stallion_lock, flags);
  2229. if (portp->tty != NULL) {
  2230. if (portp->tty->driver_data == portp) {
  2231. portp->stats.ttystate = portp->tty->flags;
  2232. /* No longer available as a statistic */
  2233. portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
  2234. if (portp->tty->termios != NULL) {
  2235. portp->stats.cflags = portp->tty->termios->c_cflag;
  2236. portp->stats.iflags = portp->tty->termios->c_iflag;
  2237. portp->stats.oflags = portp->tty->termios->c_oflag;
  2238. portp->stats.lflags = portp->tty->termios->c_lflag;
  2239. }
  2240. }
  2241. }
  2242. spin_unlock_irqrestore(&stallion_lock, flags);
  2243. head = portp->tx.head;
  2244. tail = portp->tx.tail;
  2245. portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
  2246. (STL_TXBUFSIZE - (tail - head)));
  2247. portp->stats.signals = (unsigned long) stl_getsignals(portp);
  2248. return copy_to_user(cp, &portp->stats,
  2249. sizeof(comstats_t)) ? -EFAULT : 0;
  2250. }
  2251. /*****************************************************************************/
  2252. /*
  2253. * Clear the port stats structure. We also return it zeroed out...
  2254. */
  2255. static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
  2256. {
  2257. if (!portp) {
  2258. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  2259. return -EFAULT;
  2260. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  2261. stl_comstats.port);
  2262. if (portp == NULL)
  2263. return(-ENODEV);
  2264. }
  2265. memset(&portp->stats, 0, sizeof(comstats_t));
  2266. portp->stats.brd = portp->brdnr;
  2267. portp->stats.panel = portp->panelnr;
  2268. portp->stats.port = portp->portnr;
  2269. return copy_to_user(cp, &portp->stats,
  2270. sizeof(comstats_t)) ? -EFAULT : 0;
  2271. }
  2272. /*****************************************************************************/
  2273. /*
  2274. * Return the entire driver ports structure to a user app.
  2275. */
  2276. static int stl_getportstruct(struct stlport __user *arg)
  2277. {
  2278. struct stlport *portp;
  2279. if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
  2280. return -EFAULT;
  2281. portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
  2282. stl_dummyport.portnr);
  2283. if (!portp)
  2284. return -ENODEV;
  2285. return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0;
  2286. }
  2287. /*****************************************************************************/
  2288. /*
  2289. * Return the entire driver board structure to a user app.
  2290. */
  2291. static int stl_getbrdstruct(struct stlbrd __user *arg)
  2292. {
  2293. struct stlbrd *brdp;
  2294. if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
  2295. return -EFAULT;
  2296. if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
  2297. return -ENODEV;
  2298. brdp = stl_brds[stl_dummybrd.brdnr];
  2299. if (!brdp)
  2300. return(-ENODEV);
  2301. return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
  2302. }
  2303. /*****************************************************************************/
  2304. /*
  2305. * The "staliomem" device is also required to do some special operations
  2306. * on the board and/or ports. In this driver it is mostly used for stats
  2307. * collection.
  2308. */
  2309. static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
  2310. {
  2311. int brdnr, rc;
  2312. void __user *argp = (void __user *)arg;
  2313. pr_debug("stl_memioctl(ip=%p,fp=%p,cmd=%x,arg=%lx)\n", ip, fp, cmd,arg);
  2314. brdnr = iminor(ip);
  2315. if (brdnr >= STL_MAXBRDS)
  2316. return(-ENODEV);
  2317. rc = 0;
  2318. switch (cmd) {
  2319. case COM_GETPORTSTATS:
  2320. rc = stl_getportstats(NULL, argp);
  2321. break;
  2322. case COM_CLRPORTSTATS:
  2323. rc = stl_clrportstats(NULL, argp);
  2324. break;
  2325. case COM_GETBRDSTATS:
  2326. rc = stl_getbrdstats(argp);
  2327. break;
  2328. case COM_READPORT:
  2329. rc = stl_getportstruct(argp);
  2330. break;
  2331. case COM_READBOARD:
  2332. rc = stl_getbrdstruct(argp);
  2333. break;
  2334. default:
  2335. rc = -ENOIOCTLCMD;
  2336. break;
  2337. }
  2338. return(rc);
  2339. }
  2340. static const struct tty_operations stl_ops = {
  2341. .open = stl_open,
  2342. .close = stl_close,
  2343. .write = stl_write,
  2344. .put_char = stl_putchar,
  2345. .flush_chars = stl_flushchars,
  2346. .write_room = stl_writeroom,
  2347. .chars_in_buffer = stl_charsinbuffer,
  2348. .ioctl = stl_ioctl,
  2349. .set_termios = stl_settermios,
  2350. .throttle = stl_throttle,
  2351. .unthrottle = stl_unthrottle,
  2352. .stop = stl_stop,
  2353. .start = stl_start,
  2354. .hangup = stl_hangup,
  2355. .flush_buffer = stl_flushbuffer,
  2356. .break_ctl = stl_breakctl,
  2357. .wait_until_sent = stl_waituntilsent,
  2358. .send_xchar = stl_sendxchar,
  2359. .read_proc = stl_readproc,
  2360. .tiocmget = stl_tiocmget,
  2361. .tiocmset = stl_tiocmset,
  2362. };
  2363. /*****************************************************************************/
  2364. /* CD1400 HARDWARE FUNCTIONS */
  2365. /*****************************************************************************/
  2366. /*
  2367. * These functions get/set/update the registers of the cd1400 UARTs.
  2368. * Access to the cd1400 registers is via an address/data io port pair.
  2369. * (Maybe should make this inline...)
  2370. */
  2371. static int stl_cd1400getreg(struct stlport *portp, int regnr)
  2372. {
  2373. outb((regnr + portp->uartaddr), portp->ioaddr);
  2374. return inb(portp->ioaddr + EREG_DATA);
  2375. }
  2376. static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
  2377. {
  2378. outb((regnr + portp->uartaddr), portp->ioaddr);
  2379. outb(value, portp->ioaddr + EREG_DATA);
  2380. }
  2381. static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
  2382. {
  2383. outb((regnr + portp->uartaddr), portp->ioaddr);
  2384. if (inb(portp->ioaddr + EREG_DATA) != value) {
  2385. outb(value, portp->ioaddr + EREG_DATA);
  2386. return 1;
  2387. }
  2388. return 0;
  2389. }
  2390. /*****************************************************************************/
  2391. /*
  2392. * Inbitialize the UARTs in a panel. We don't care what sort of board
  2393. * these ports are on - since the port io registers are almost
  2394. * identical when dealing with ports.
  2395. */
  2396. static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
  2397. {
  2398. unsigned int gfrcr;
  2399. int chipmask, i, j;
  2400. int nrchips, uartaddr, ioaddr;
  2401. unsigned long flags;
  2402. pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
  2403. spin_lock_irqsave(&brd_lock, flags);
  2404. BRDENABLE(panelp->brdnr, panelp->pagenr);
  2405. /*
  2406. * Check that each chip is present and started up OK.
  2407. */
  2408. chipmask = 0;
  2409. nrchips = panelp->nrports / CD1400_PORTS;
  2410. for (i = 0; (i < nrchips); i++) {
  2411. if (brdp->brdtype == BRD_ECHPCI) {
  2412. outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
  2413. ioaddr = panelp->iobase;
  2414. } else {
  2415. ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
  2416. }
  2417. uartaddr = (i & 0x01) ? 0x080 : 0;
  2418. outb((GFRCR + uartaddr), ioaddr);
  2419. outb(0, (ioaddr + EREG_DATA));
  2420. outb((CCR + uartaddr), ioaddr);
  2421. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  2422. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  2423. outb((GFRCR + uartaddr), ioaddr);
  2424. for (j = 0; (j < CCR_MAXWAIT); j++) {
  2425. if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
  2426. break;
  2427. }
  2428. if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
  2429. printk("STALLION: cd1400 not responding, "
  2430. "brd=%d panel=%d chip=%d\n",
  2431. panelp->brdnr, panelp->panelnr, i);
  2432. continue;
  2433. }
  2434. chipmask |= (0x1 << i);
  2435. outb((PPR + uartaddr), ioaddr);
  2436. outb(PPR_SCALAR, (ioaddr + EREG_DATA));
  2437. }
  2438. BRDDISABLE(panelp->brdnr);
  2439. spin_unlock_irqrestore(&brd_lock, flags);
  2440. return chipmask;
  2441. }
  2442. /*****************************************************************************/
  2443. /*
  2444. * Initialize hardware specific port registers.
  2445. */
  2446. static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
  2447. {
  2448. unsigned long flags;
  2449. pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
  2450. panelp, portp);
  2451. if ((brdp == NULL) || (panelp == NULL) ||
  2452. (portp == NULL))
  2453. return;
  2454. spin_lock_irqsave(&brd_lock, flags);
  2455. portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
  2456. (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
  2457. portp->uartaddr = (portp->portnr & 0x04) << 5;
  2458. portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
  2459. BRDENABLE(portp->brdnr, portp->pagenr);
  2460. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2461. stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
  2462. portp->hwid = stl_cd1400getreg(portp, GFRCR);
  2463. BRDDISABLE(portp->brdnr);
  2464. spin_unlock_irqrestore(&brd_lock, flags);
  2465. }
  2466. /*****************************************************************************/
  2467. /*
  2468. * Wait for the command register to be ready. We will poll this,
  2469. * since it won't usually take too long to be ready.
  2470. */
  2471. static void stl_cd1400ccrwait(struct stlport *portp)
  2472. {
  2473. int i;
  2474. for (i = 0; (i < CCR_MAXWAIT); i++) {
  2475. if (stl_cd1400getreg(portp, CCR) == 0) {
  2476. return;
  2477. }
  2478. }
  2479. printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
  2480. portp->portnr, portp->panelnr, portp->brdnr);
  2481. }
  2482. /*****************************************************************************/
  2483. /*
  2484. * Set up the cd1400 registers for a port based on the termios port
  2485. * settings.
  2486. */
  2487. static void stl_cd1400setport(struct stlport *portp, struct termios *tiosp)
  2488. {
  2489. struct stlbrd *brdp;
  2490. unsigned long flags;
  2491. unsigned int clkdiv, baudrate;
  2492. unsigned char cor1, cor2, cor3;
  2493. unsigned char cor4, cor5, ccr;
  2494. unsigned char srer, sreron, sreroff;
  2495. unsigned char mcor1, mcor2, rtpr;
  2496. unsigned char clk, div;
  2497. cor1 = 0;
  2498. cor2 = 0;
  2499. cor3 = 0;
  2500. cor4 = 0;
  2501. cor5 = 0;
  2502. ccr = 0;
  2503. rtpr = 0;
  2504. clk = 0;
  2505. div = 0;
  2506. mcor1 = 0;
  2507. mcor2 = 0;
  2508. sreron = 0;
  2509. sreroff = 0;
  2510. brdp = stl_brds[portp->brdnr];
  2511. if (brdp == NULL)
  2512. return;
  2513. /*
  2514. * Set up the RX char ignore mask with those RX error types we
  2515. * can ignore. We can get the cd1400 to help us out a little here,
  2516. * it will ignore parity errors and breaks for us.
  2517. */
  2518. portp->rxignoremsk = 0;
  2519. if (tiosp->c_iflag & IGNPAR) {
  2520. portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
  2521. cor1 |= COR1_PARIGNORE;
  2522. }
  2523. if (tiosp->c_iflag & IGNBRK) {
  2524. portp->rxignoremsk |= ST_BREAK;
  2525. cor4 |= COR4_IGNBRK;
  2526. }
  2527. portp->rxmarkmsk = ST_OVERRUN;
  2528. if (tiosp->c_iflag & (INPCK | PARMRK))
  2529. portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
  2530. if (tiosp->c_iflag & BRKINT)
  2531. portp->rxmarkmsk |= ST_BREAK;
  2532. /*
  2533. * Go through the char size, parity and stop bits and set all the
  2534. * option register appropriately.
  2535. */
  2536. switch (tiosp->c_cflag & CSIZE) {
  2537. case CS5:
  2538. cor1 |= COR1_CHL5;
  2539. break;
  2540. case CS6:
  2541. cor1 |= COR1_CHL6;
  2542. break;
  2543. case CS7:
  2544. cor1 |= COR1_CHL7;
  2545. break;
  2546. default:
  2547. cor1 |= COR1_CHL8;
  2548. break;
  2549. }
  2550. if (tiosp->c_cflag & CSTOPB)
  2551. cor1 |= COR1_STOP2;
  2552. else
  2553. cor1 |= COR1_STOP1;
  2554. if (tiosp->c_cflag & PARENB) {
  2555. if (tiosp->c_cflag & PARODD)
  2556. cor1 |= (COR1_PARENB | COR1_PARODD);
  2557. else
  2558. cor1 |= (COR1_PARENB | COR1_PAREVEN);
  2559. } else {
  2560. cor1 |= COR1_PARNONE;
  2561. }
  2562. /*
  2563. * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
  2564. * space for hardware flow control and the like. This should be set to
  2565. * VMIN. Also here we will set the RX data timeout to 10ms - this should
  2566. * really be based on VTIME.
  2567. */
  2568. cor3 |= FIFO_RXTHRESHOLD;
  2569. rtpr = 2;
  2570. /*
  2571. * Calculate the baud rate timers. For now we will just assume that
  2572. * the input and output baud are the same. Could have used a baud
  2573. * table here, but this way we can generate virtually any baud rate
  2574. * we like!
  2575. */
  2576. baudrate = tiosp->c_cflag & CBAUD;
  2577. if (baudrate & CBAUDEX) {
  2578. baudrate &= ~CBAUDEX;
  2579. if ((baudrate < 1) || (baudrate > 4))
  2580. tiosp->c_cflag &= ~CBAUDEX;
  2581. else
  2582. baudrate += 15;
  2583. }
  2584. baudrate = stl_baudrates[baudrate];
  2585. if ((tiosp->c_cflag & CBAUD) == B38400) {
  2586. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  2587. baudrate = 57600;
  2588. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  2589. baudrate = 115200;
  2590. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  2591. baudrate = 230400;
  2592. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  2593. baudrate = 460800;
  2594. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  2595. baudrate = (portp->baud_base / portp->custom_divisor);
  2596. }
  2597. if (baudrate > STL_CD1400MAXBAUD)
  2598. baudrate = STL_CD1400MAXBAUD;
  2599. if (baudrate > 0) {
  2600. for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
  2601. clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
  2602. if (clkdiv < 0x100)
  2603. break;
  2604. }
  2605. div = (unsigned char) clkdiv;
  2606. }
  2607. /*
  2608. * Check what form of modem signaling is required and set it up.
  2609. */
  2610. if ((tiosp->c_cflag & CLOCAL) == 0) {
  2611. mcor1 |= MCOR1_DCD;
  2612. mcor2 |= MCOR2_DCD;
  2613. sreron |= SRER_MODEM;
  2614. portp->flags |= ASYNC_CHECK_CD;
  2615. } else {
  2616. portp->flags &= ~ASYNC_CHECK_CD;
  2617. }
  2618. /*
  2619. * Setup cd1400 enhanced modes if we can. In particular we want to
  2620. * handle as much of the flow control as possible automatically. As
  2621. * well as saving a few CPU cycles it will also greatly improve flow
  2622. * control reliability.
  2623. */
  2624. if (tiosp->c_iflag & IXON) {
  2625. cor2 |= COR2_TXIBE;
  2626. cor3 |= COR3_SCD12;
  2627. if (tiosp->c_iflag & IXANY)
  2628. cor2 |= COR2_IXM;
  2629. }
  2630. if (tiosp->c_cflag & CRTSCTS) {
  2631. cor2 |= COR2_CTSAE;
  2632. mcor1 |= FIFO_RTSTHRESHOLD;
  2633. }
  2634. /*
  2635. * All cd1400 register values calculated so go through and set
  2636. * them all up.
  2637. */
  2638. pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
  2639. portp->portnr, portp->panelnr, portp->brdnr);
  2640. pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
  2641. cor1, cor2, cor3, cor4, cor5);
  2642. pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
  2643. mcor1, mcor2, rtpr, sreron, sreroff);
  2644. pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
  2645. pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
  2646. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  2647. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  2648. spin_lock_irqsave(&brd_lock, flags);
  2649. BRDENABLE(portp->brdnr, portp->pagenr);
  2650. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
  2651. srer = stl_cd1400getreg(portp, SRER);
  2652. stl_cd1400setreg(portp, SRER, 0);
  2653. if (stl_cd1400updatereg(portp, COR1, cor1))
  2654. ccr = 1;
  2655. if (stl_cd1400updatereg(portp, COR2, cor2))
  2656. ccr = 1;
  2657. if (stl_cd1400updatereg(portp, COR3, cor3))
  2658. ccr = 1;
  2659. if (ccr) {
  2660. stl_cd1400ccrwait(portp);
  2661. stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
  2662. }
  2663. stl_cd1400setreg(portp, COR4, cor4);
  2664. stl_cd1400setreg(portp, COR5, cor5);
  2665. stl_cd1400setreg(portp, MCOR1, mcor1);
  2666. stl_cd1400setreg(portp, MCOR2, mcor2);
  2667. if (baudrate > 0) {
  2668. stl_cd1400setreg(portp, TCOR, clk);
  2669. stl_cd1400setreg(portp, TBPR, div);
  2670. stl_cd1400setreg(portp, RCOR, clk);
  2671. stl_cd1400setreg(portp, RBPR, div);
  2672. }
  2673. stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
  2674. stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
  2675. stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
  2676. stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
  2677. stl_cd1400setreg(portp, RTPR, rtpr);
  2678. mcor1 = stl_cd1400getreg(portp, MSVR1);
  2679. if (mcor1 & MSVR1_DCD)
  2680. portp->sigs |= TIOCM_CD;
  2681. else
  2682. portp->sigs &= ~TIOCM_CD;
  2683. stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
  2684. BRDDISABLE(portp->brdnr);
  2685. spin_unlock_irqrestore(&brd_lock, flags);
  2686. }
  2687. /*****************************************************************************/
  2688. /*
  2689. * Set the state of the DTR and RTS signals.
  2690. */
  2691. static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts)
  2692. {
  2693. unsigned char msvr1, msvr2;
  2694. unsigned long flags;
  2695. pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
  2696. portp, dtr, rts);
  2697. msvr1 = 0;
  2698. msvr2 = 0;
  2699. if (dtr > 0)
  2700. msvr1 = MSVR1_DTR;
  2701. if (rts > 0)
  2702. msvr2 = MSVR2_RTS;
  2703. spin_lock_irqsave(&brd_lock, flags);
  2704. BRDENABLE(portp->brdnr, portp->pagenr);
  2705. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2706. if (rts >= 0)
  2707. stl_cd1400setreg(portp, MSVR2, msvr2);
  2708. if (dtr >= 0)
  2709. stl_cd1400setreg(portp, MSVR1, msvr1);
  2710. BRDDISABLE(portp->brdnr);
  2711. spin_unlock_irqrestore(&brd_lock, flags);
  2712. }
  2713. /*****************************************************************************/
  2714. /*
  2715. * Return the state of the signals.
  2716. */
  2717. static int stl_cd1400getsignals(struct stlport *portp)
  2718. {
  2719. unsigned char msvr1, msvr2;
  2720. unsigned long flags;
  2721. int sigs;
  2722. pr_debug("stl_cd1400getsignals(portp=%p)\n", portp);
  2723. spin_lock_irqsave(&brd_lock, flags);
  2724. BRDENABLE(portp->brdnr, portp->pagenr);
  2725. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2726. msvr1 = stl_cd1400getreg(portp, MSVR1);
  2727. msvr2 = stl_cd1400getreg(portp, MSVR2);
  2728. BRDDISABLE(portp->brdnr);
  2729. spin_unlock_irqrestore(&brd_lock, flags);
  2730. sigs = 0;
  2731. sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
  2732. sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
  2733. sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
  2734. sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
  2735. #if 0
  2736. sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
  2737. sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
  2738. #else
  2739. sigs |= TIOCM_DSR;
  2740. #endif
  2741. return sigs;
  2742. }
  2743. /*****************************************************************************/
  2744. /*
  2745. * Enable/Disable the Transmitter and/or Receiver.
  2746. */
  2747. static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx)
  2748. {
  2749. unsigned char ccr;
  2750. unsigned long flags;
  2751. pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
  2752. ccr = 0;
  2753. if (tx == 0)
  2754. ccr |= CCR_TXDISABLE;
  2755. else if (tx > 0)
  2756. ccr |= CCR_TXENABLE;
  2757. if (rx == 0)
  2758. ccr |= CCR_RXDISABLE;
  2759. else if (rx > 0)
  2760. ccr |= CCR_RXENABLE;
  2761. spin_lock_irqsave(&brd_lock, flags);
  2762. BRDENABLE(portp->brdnr, portp->pagenr);
  2763. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2764. stl_cd1400ccrwait(portp);
  2765. stl_cd1400setreg(portp, CCR, ccr);
  2766. stl_cd1400ccrwait(portp);
  2767. BRDDISABLE(portp->brdnr);
  2768. spin_unlock_irqrestore(&brd_lock, flags);
  2769. }
  2770. /*****************************************************************************/
  2771. /*
  2772. * Start/stop the Transmitter and/or Receiver.
  2773. */
  2774. static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx)
  2775. {
  2776. unsigned char sreron, sreroff;
  2777. unsigned long flags;
  2778. pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
  2779. sreron = 0;
  2780. sreroff = 0;
  2781. if (tx == 0)
  2782. sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
  2783. else if (tx == 1)
  2784. sreron |= SRER_TXDATA;
  2785. else if (tx >= 2)
  2786. sreron |= SRER_TXEMPTY;
  2787. if (rx == 0)
  2788. sreroff |= SRER_RXDATA;
  2789. else if (rx > 0)
  2790. sreron |= SRER_RXDATA;
  2791. spin_lock_irqsave(&brd_lock, flags);
  2792. BRDENABLE(portp->brdnr, portp->pagenr);
  2793. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2794. stl_cd1400setreg(portp, SRER,
  2795. ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
  2796. BRDDISABLE(portp->brdnr);
  2797. if (tx > 0)
  2798. set_bit(ASYI_TXBUSY, &portp->istate);
  2799. spin_unlock_irqrestore(&brd_lock, flags);
  2800. }
  2801. /*****************************************************************************/
  2802. /*
  2803. * Disable all interrupts from this port.
  2804. */
  2805. static void stl_cd1400disableintrs(struct stlport *portp)
  2806. {
  2807. unsigned long flags;
  2808. pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp);
  2809. spin_lock_irqsave(&brd_lock, flags);
  2810. BRDENABLE(portp->brdnr, portp->pagenr);
  2811. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2812. stl_cd1400setreg(portp, SRER, 0);
  2813. BRDDISABLE(portp->brdnr);
  2814. spin_unlock_irqrestore(&brd_lock, flags);
  2815. }
  2816. /*****************************************************************************/
  2817. static void stl_cd1400sendbreak(struct stlport *portp, int len)
  2818. {
  2819. unsigned long flags;
  2820. pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len);
  2821. spin_lock_irqsave(&brd_lock, flags);
  2822. BRDENABLE(portp->brdnr, portp->pagenr);
  2823. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2824. stl_cd1400setreg(portp, SRER,
  2825. ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
  2826. SRER_TXEMPTY));
  2827. BRDDISABLE(portp->brdnr);
  2828. portp->brklen = len;
  2829. if (len == 1)
  2830. portp->stats.txbreaks++;
  2831. spin_unlock_irqrestore(&brd_lock, flags);
  2832. }
  2833. /*****************************************************************************/
  2834. /*
  2835. * Take flow control actions...
  2836. */
  2837. static void stl_cd1400flowctrl(struct stlport *portp, int state)
  2838. {
  2839. struct tty_struct *tty;
  2840. unsigned long flags;
  2841. pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state);
  2842. if (portp == NULL)
  2843. return;
  2844. tty = portp->tty;
  2845. if (tty == NULL)
  2846. return;
  2847. spin_lock_irqsave(&brd_lock, flags);
  2848. BRDENABLE(portp->brdnr, portp->pagenr);
  2849. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2850. if (state) {
  2851. if (tty->termios->c_iflag & IXOFF) {
  2852. stl_cd1400ccrwait(portp);
  2853. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  2854. portp->stats.rxxon++;
  2855. stl_cd1400ccrwait(portp);
  2856. }
  2857. /*
  2858. * Question: should we return RTS to what it was before? It may
  2859. * have been set by an ioctl... Suppose not, since if you have
  2860. * hardware flow control set then it is pretty silly to go and
  2861. * set the RTS line by hand.
  2862. */
  2863. if (tty->termios->c_cflag & CRTSCTS) {
  2864. stl_cd1400setreg(portp, MCOR1,
  2865. (stl_cd1400getreg(portp, MCOR1) |
  2866. FIFO_RTSTHRESHOLD));
  2867. stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
  2868. portp->stats.rxrtson++;
  2869. }
  2870. } else {
  2871. if (tty->termios->c_iflag & IXOFF) {
  2872. stl_cd1400ccrwait(portp);
  2873. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  2874. portp->stats.rxxoff++;
  2875. stl_cd1400ccrwait(portp);
  2876. }
  2877. if (tty->termios->c_cflag & CRTSCTS) {
  2878. stl_cd1400setreg(portp, MCOR1,
  2879. (stl_cd1400getreg(portp, MCOR1) & 0xf0));
  2880. stl_cd1400setreg(portp, MSVR2, 0);
  2881. portp->stats.rxrtsoff++;
  2882. }
  2883. }
  2884. BRDDISABLE(portp->brdnr);
  2885. spin_unlock_irqrestore(&brd_lock, flags);
  2886. }
  2887. /*****************************************************************************/
  2888. /*
  2889. * Send a flow control character...
  2890. */
  2891. static void stl_cd1400sendflow(struct stlport *portp, int state)
  2892. {
  2893. struct tty_struct *tty;
  2894. unsigned long flags;
  2895. pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state);
  2896. if (portp == NULL)
  2897. return;
  2898. tty = portp->tty;
  2899. if (tty == NULL)
  2900. return;
  2901. spin_lock_irqsave(&brd_lock, flags);
  2902. BRDENABLE(portp->brdnr, portp->pagenr);
  2903. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2904. if (state) {
  2905. stl_cd1400ccrwait(portp);
  2906. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  2907. portp->stats.rxxon++;
  2908. stl_cd1400ccrwait(portp);
  2909. } else {
  2910. stl_cd1400ccrwait(portp);
  2911. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  2912. portp->stats.rxxoff++;
  2913. stl_cd1400ccrwait(portp);
  2914. }
  2915. BRDDISABLE(portp->brdnr);
  2916. spin_unlock_irqrestore(&brd_lock, flags);
  2917. }
  2918. /*****************************************************************************/
  2919. static void stl_cd1400flush(struct stlport *portp)
  2920. {
  2921. unsigned long flags;
  2922. pr_debug("stl_cd1400flush(portp=%p)\n", portp);
  2923. if (portp == NULL)
  2924. return;
  2925. spin_lock_irqsave(&brd_lock, flags);
  2926. BRDENABLE(portp->brdnr, portp->pagenr);
  2927. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2928. stl_cd1400ccrwait(portp);
  2929. stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
  2930. stl_cd1400ccrwait(portp);
  2931. portp->tx.tail = portp->tx.head;
  2932. BRDDISABLE(portp->brdnr);
  2933. spin_unlock_irqrestore(&brd_lock, flags);
  2934. }
  2935. /*****************************************************************************/
  2936. /*
  2937. * Return the current state of data flow on this port. This is only
  2938. * really interresting when determining if data has fully completed
  2939. * transmission or not... This is easy for the cd1400, it accurately
  2940. * maintains the busy port flag.
  2941. */
  2942. static int stl_cd1400datastate(struct stlport *portp)
  2943. {
  2944. pr_debug("stl_cd1400datastate(portp=%p)\n", portp);
  2945. if (portp == NULL)
  2946. return 0;
  2947. return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
  2948. }
  2949. /*****************************************************************************/
  2950. /*
  2951. * Interrupt service routine for cd1400 EasyIO boards.
  2952. */
  2953. static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase)
  2954. {
  2955. unsigned char svrtype;
  2956. pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase);
  2957. spin_lock(&brd_lock);
  2958. outb(SVRR, iobase);
  2959. svrtype = inb(iobase + EREG_DATA);
  2960. if (panelp->nrports > 4) {
  2961. outb((SVRR + 0x80), iobase);
  2962. svrtype |= inb(iobase + EREG_DATA);
  2963. }
  2964. if (svrtype & SVRR_RX)
  2965. stl_cd1400rxisr(panelp, iobase);
  2966. else if (svrtype & SVRR_TX)
  2967. stl_cd1400txisr(panelp, iobase);
  2968. else if (svrtype & SVRR_MDM)
  2969. stl_cd1400mdmisr(panelp, iobase);
  2970. spin_unlock(&brd_lock);
  2971. }
  2972. /*****************************************************************************/
  2973. /*
  2974. * Interrupt service routine for cd1400 panels.
  2975. */
  2976. static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase)
  2977. {
  2978. unsigned char svrtype;
  2979. pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase);
  2980. outb(SVRR, iobase);
  2981. svrtype = inb(iobase + EREG_DATA);
  2982. outb((SVRR + 0x80), iobase);
  2983. svrtype |= inb(iobase + EREG_DATA);
  2984. if (svrtype & SVRR_RX)
  2985. stl_cd1400rxisr(panelp, iobase);
  2986. else if (svrtype & SVRR_TX)
  2987. stl_cd1400txisr(panelp, iobase);
  2988. else if (svrtype & SVRR_MDM)
  2989. stl_cd1400mdmisr(panelp, iobase);
  2990. }
  2991. /*****************************************************************************/
  2992. /*
  2993. * Unfortunately we need to handle breaks in the TX data stream, since
  2994. * this is the only way to generate them on the cd1400.
  2995. */
  2996. static int stl_cd1400breakisr(struct stlport *portp, int ioaddr)
  2997. {
  2998. if (portp->brklen == 1) {
  2999. outb((COR2 + portp->uartaddr), ioaddr);
  3000. outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
  3001. (ioaddr + EREG_DATA));
  3002. outb((TDR + portp->uartaddr), ioaddr);
  3003. outb(ETC_CMD, (ioaddr + EREG_DATA));
  3004. outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
  3005. outb((SRER + portp->uartaddr), ioaddr);
  3006. outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
  3007. (ioaddr + EREG_DATA));
  3008. return 1;
  3009. } else if (portp->brklen > 1) {
  3010. outb((TDR + portp->uartaddr), ioaddr);
  3011. outb(ETC_CMD, (ioaddr + EREG_DATA));
  3012. outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
  3013. portp->brklen = -1;
  3014. return 1;
  3015. } else {
  3016. outb((COR2 + portp->uartaddr), ioaddr);
  3017. outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
  3018. (ioaddr + EREG_DATA));
  3019. portp->brklen = 0;
  3020. }
  3021. return 0;
  3022. }
  3023. /*****************************************************************************/
  3024. /*
  3025. * Transmit interrupt handler. This has gotta be fast! Handling TX
  3026. * chars is pretty simple, stuff as many as possible from the TX buffer
  3027. * into the cd1400 FIFO. Must also handle TX breaks here, since they
  3028. * are embedded as commands in the data stream. Oh no, had to use a goto!
  3029. * This could be optimized more, will do when I get time...
  3030. * In practice it is possible that interrupts are enabled but that the
  3031. * port has been hung up. Need to handle not having any TX buffer here,
  3032. * this is done by using the side effect that head and tail will also
  3033. * be NULL if the buffer has been freed.
  3034. */
  3035. static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
  3036. {
  3037. struct stlport *portp;
  3038. int len, stlen;
  3039. char *head, *tail;
  3040. unsigned char ioack, srer;
  3041. pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
  3042. ioack = inb(ioaddr + EREG_TXACK);
  3043. if (((ioack & panelp->ackmask) != 0) ||
  3044. ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
  3045. printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
  3046. return;
  3047. }
  3048. portp = panelp->ports[(ioack >> 3)];
  3049. /*
  3050. * Unfortunately we need to handle breaks in the data stream, since
  3051. * this is the only way to generate them on the cd1400. Do it now if
  3052. * a break is to be sent.
  3053. */
  3054. if (portp->brklen != 0)
  3055. if (stl_cd1400breakisr(portp, ioaddr))
  3056. goto stl_txalldone;
  3057. head = portp->tx.head;
  3058. tail = portp->tx.tail;
  3059. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  3060. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  3061. (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  3062. set_bit(ASYI_TXLOW, &portp->istate);
  3063. schedule_work(&portp->tqueue);
  3064. }
  3065. if (len == 0) {
  3066. outb((SRER + portp->uartaddr), ioaddr);
  3067. srer = inb(ioaddr + EREG_DATA);
  3068. if (srer & SRER_TXDATA) {
  3069. srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
  3070. } else {
  3071. srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
  3072. clear_bit(ASYI_TXBUSY, &portp->istate);
  3073. }
  3074. outb(srer, (ioaddr + EREG_DATA));
  3075. } else {
  3076. len = MIN(len, CD1400_TXFIFOSIZE);
  3077. portp->stats.txtotal += len;
  3078. stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
  3079. outb((TDR + portp->uartaddr), ioaddr);
  3080. outsb((ioaddr + EREG_DATA), tail, stlen);
  3081. len -= stlen;
  3082. tail += stlen;
  3083. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  3084. tail = portp->tx.buf;
  3085. if (len > 0) {
  3086. outsb((ioaddr + EREG_DATA), tail, len);
  3087. tail += len;
  3088. }
  3089. portp->tx.tail = tail;
  3090. }
  3091. stl_txalldone:
  3092. outb((EOSRR + portp->uartaddr), ioaddr);
  3093. outb(0, (ioaddr + EREG_DATA));
  3094. }
  3095. /*****************************************************************************/
  3096. /*
  3097. * Receive character interrupt handler. Determine if we have good chars
  3098. * or bad chars and then process appropriately. Good chars are easy
  3099. * just shove the lot into the RX buffer and set all status byte to 0.
  3100. * If a bad RX char then process as required. This routine needs to be
  3101. * fast! In practice it is possible that we get an interrupt on a port
  3102. * that is closed. This can happen on hangups - since they completely
  3103. * shutdown a port not in user context. Need to handle this case.
  3104. */
  3105. static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
  3106. {
  3107. struct stlport *portp;
  3108. struct tty_struct *tty;
  3109. unsigned int ioack, len, buflen;
  3110. unsigned char status;
  3111. char ch;
  3112. pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
  3113. ioack = inb(ioaddr + EREG_RXACK);
  3114. if ((ioack & panelp->ackmask) != 0) {
  3115. printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
  3116. return;
  3117. }
  3118. portp = panelp->ports[(ioack >> 3)];
  3119. tty = portp->tty;
  3120. if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
  3121. outb((RDCR + portp->uartaddr), ioaddr);
  3122. len = inb(ioaddr + EREG_DATA);
  3123. if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
  3124. len = MIN(len, sizeof(stl_unwanted));
  3125. outb((RDSR + portp->uartaddr), ioaddr);
  3126. insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
  3127. portp->stats.rxlost += len;
  3128. portp->stats.rxtotal += len;
  3129. } else {
  3130. len = MIN(len, buflen);
  3131. if (len > 0) {
  3132. unsigned char *ptr;
  3133. outb((RDSR + portp->uartaddr), ioaddr);
  3134. tty_prepare_flip_string(tty, &ptr, len);
  3135. insb((ioaddr + EREG_DATA), ptr, len);
  3136. tty_schedule_flip(tty);
  3137. portp->stats.rxtotal += len;
  3138. }
  3139. }
  3140. } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
  3141. outb((RDSR + portp->uartaddr), ioaddr);
  3142. status = inb(ioaddr + EREG_DATA);
  3143. ch = inb(ioaddr + EREG_DATA);
  3144. if (status & ST_PARITY)
  3145. portp->stats.rxparity++;
  3146. if (status & ST_FRAMING)
  3147. portp->stats.rxframing++;
  3148. if (status & ST_OVERRUN)
  3149. portp->stats.rxoverrun++;
  3150. if (status & ST_BREAK)
  3151. portp->stats.rxbreaks++;
  3152. if (status & ST_SCHARMASK) {
  3153. if ((status & ST_SCHARMASK) == ST_SCHAR1)
  3154. portp->stats.txxon++;
  3155. if ((status & ST_SCHARMASK) == ST_SCHAR2)
  3156. portp->stats.txxoff++;
  3157. goto stl_rxalldone;
  3158. }
  3159. if (tty != NULL && (portp->rxignoremsk & status) == 0) {
  3160. if (portp->rxmarkmsk & status) {
  3161. if (status & ST_BREAK) {
  3162. status = TTY_BREAK;
  3163. if (portp->flags & ASYNC_SAK) {
  3164. do_SAK(tty);
  3165. BRDENABLE(portp->brdnr, portp->pagenr);
  3166. }
  3167. } else if (status & ST_PARITY) {
  3168. status = TTY_PARITY;
  3169. } else if (status & ST_FRAMING) {
  3170. status = TTY_FRAME;
  3171. } else if(status & ST_OVERRUN) {
  3172. status = TTY_OVERRUN;
  3173. } else {
  3174. status = 0;
  3175. }
  3176. } else {
  3177. status = 0;
  3178. }
  3179. tty_insert_flip_char(tty, ch, status);
  3180. tty_schedule_flip(tty);
  3181. }
  3182. } else {
  3183. printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
  3184. return;
  3185. }
  3186. stl_rxalldone:
  3187. outb((EOSRR + portp->uartaddr), ioaddr);
  3188. outb(0, (ioaddr + EREG_DATA));
  3189. }
  3190. /*****************************************************************************/
  3191. /*
  3192. * Modem interrupt handler. The is called when the modem signal line
  3193. * (DCD) has changed state. Leave most of the work to the off-level
  3194. * processing routine.
  3195. */
  3196. static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr)
  3197. {
  3198. struct stlport *portp;
  3199. unsigned int ioack;
  3200. unsigned char misr;
  3201. pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp);
  3202. ioack = inb(ioaddr + EREG_MDACK);
  3203. if (((ioack & panelp->ackmask) != 0) ||
  3204. ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
  3205. printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
  3206. return;
  3207. }
  3208. portp = panelp->ports[(ioack >> 3)];
  3209. outb((MISR + portp->uartaddr), ioaddr);
  3210. misr = inb(ioaddr + EREG_DATA);
  3211. if (misr & MISR_DCD) {
  3212. set_bit(ASYI_DCDCHANGE, &portp->istate);
  3213. schedule_work(&portp->tqueue);
  3214. portp->stats.modem++;
  3215. }
  3216. outb((EOSRR + portp->uartaddr), ioaddr);
  3217. outb(0, (ioaddr + EREG_DATA));
  3218. }
  3219. /*****************************************************************************/
  3220. /* SC26198 HARDWARE FUNCTIONS */
  3221. /*****************************************************************************/
  3222. /*
  3223. * These functions get/set/update the registers of the sc26198 UARTs.
  3224. * Access to the sc26198 registers is via an address/data io port pair.
  3225. * (Maybe should make this inline...)
  3226. */
  3227. static int stl_sc26198getreg(struct stlport *portp, int regnr)
  3228. {
  3229. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3230. return inb(portp->ioaddr + XP_DATA);
  3231. }
  3232. static void stl_sc26198setreg(struct stlport *portp, int regnr, int value)
  3233. {
  3234. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3235. outb(value, (portp->ioaddr + XP_DATA));
  3236. }
  3237. static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value)
  3238. {
  3239. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3240. if (inb(portp->ioaddr + XP_DATA) != value) {
  3241. outb(value, (portp->ioaddr + XP_DATA));
  3242. return 1;
  3243. }
  3244. return 0;
  3245. }
  3246. /*****************************************************************************/
  3247. /*
  3248. * Functions to get and set the sc26198 global registers.
  3249. */
  3250. static int stl_sc26198getglobreg(struct stlport *portp, int regnr)
  3251. {
  3252. outb(regnr, (portp->ioaddr + XP_ADDR));
  3253. return inb(portp->ioaddr + XP_DATA);
  3254. }
  3255. #if 0
  3256. static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value)
  3257. {
  3258. outb(regnr, (portp->ioaddr + XP_ADDR));
  3259. outb(value, (portp->ioaddr + XP_DATA));
  3260. }
  3261. #endif
  3262. /*****************************************************************************/
  3263. /*
  3264. * Inbitialize the UARTs in a panel. We don't care what sort of board
  3265. * these ports are on - since the port io registers are almost
  3266. * identical when dealing with ports.
  3267. */
  3268. static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
  3269. {
  3270. int chipmask, i;
  3271. int nrchips, ioaddr;
  3272. pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
  3273. BRDENABLE(panelp->brdnr, panelp->pagenr);
  3274. /*
  3275. * Check that each chip is present and started up OK.
  3276. */
  3277. chipmask = 0;
  3278. nrchips = (panelp->nrports + 4) / SC26198_PORTS;
  3279. if (brdp->brdtype == BRD_ECHPCI)
  3280. outb(panelp->pagenr, brdp->ioctrl);
  3281. for (i = 0; (i < nrchips); i++) {
  3282. ioaddr = panelp->iobase + (i * 4);
  3283. outb(SCCR, (ioaddr + XP_ADDR));
  3284. outb(CR_RESETALL, (ioaddr + XP_DATA));
  3285. outb(TSTR, (ioaddr + XP_ADDR));
  3286. if (inb(ioaddr + XP_DATA) != 0) {
  3287. printk("STALLION: sc26198 not responding, "
  3288. "brd=%d panel=%d chip=%d\n",
  3289. panelp->brdnr, panelp->panelnr, i);
  3290. continue;
  3291. }
  3292. chipmask |= (0x1 << i);
  3293. outb(GCCR, (ioaddr + XP_ADDR));
  3294. outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
  3295. outb(WDTRCR, (ioaddr + XP_ADDR));
  3296. outb(0xff, (ioaddr + XP_DATA));
  3297. }
  3298. BRDDISABLE(panelp->brdnr);
  3299. return chipmask;
  3300. }
  3301. /*****************************************************************************/
  3302. /*
  3303. * Initialize hardware specific port registers.
  3304. */
  3305. static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
  3306. {
  3307. pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
  3308. panelp, portp);
  3309. if ((brdp == NULL) || (panelp == NULL) ||
  3310. (portp == NULL))
  3311. return;
  3312. portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
  3313. portp->uartaddr = (portp->portnr & 0x07) << 4;
  3314. portp->pagenr = panelp->pagenr;
  3315. portp->hwid = 0x1;
  3316. BRDENABLE(portp->brdnr, portp->pagenr);
  3317. stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
  3318. BRDDISABLE(portp->brdnr);
  3319. }
  3320. /*****************************************************************************/
  3321. /*
  3322. * Set up the sc26198 registers for a port based on the termios port
  3323. * settings.
  3324. */
  3325. static void stl_sc26198setport(struct stlport *portp, struct termios *tiosp)
  3326. {
  3327. struct stlbrd *brdp;
  3328. unsigned long flags;
  3329. unsigned int baudrate;
  3330. unsigned char mr0, mr1, mr2, clk;
  3331. unsigned char imron, imroff, iopr, ipr;
  3332. mr0 = 0;
  3333. mr1 = 0;
  3334. mr2 = 0;
  3335. clk = 0;
  3336. iopr = 0;
  3337. imron = 0;
  3338. imroff = 0;
  3339. brdp = stl_brds[portp->brdnr];
  3340. if (brdp == NULL)
  3341. return;
  3342. /*
  3343. * Set up the RX char ignore mask with those RX error types we
  3344. * can ignore.
  3345. */
  3346. portp->rxignoremsk = 0;
  3347. if (tiosp->c_iflag & IGNPAR)
  3348. portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
  3349. SR_RXOVERRUN);
  3350. if (tiosp->c_iflag & IGNBRK)
  3351. portp->rxignoremsk |= SR_RXBREAK;
  3352. portp->rxmarkmsk = SR_RXOVERRUN;
  3353. if (tiosp->c_iflag & (INPCK | PARMRK))
  3354. portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
  3355. if (tiosp->c_iflag & BRKINT)
  3356. portp->rxmarkmsk |= SR_RXBREAK;
  3357. /*
  3358. * Go through the char size, parity and stop bits and set all the
  3359. * option register appropriately.
  3360. */
  3361. switch (tiosp->c_cflag & CSIZE) {
  3362. case CS5:
  3363. mr1 |= MR1_CS5;
  3364. break;
  3365. case CS6:
  3366. mr1 |= MR1_CS6;
  3367. break;
  3368. case CS7:
  3369. mr1 |= MR1_CS7;
  3370. break;
  3371. default:
  3372. mr1 |= MR1_CS8;
  3373. break;
  3374. }
  3375. if (tiosp->c_cflag & CSTOPB)
  3376. mr2 |= MR2_STOP2;
  3377. else
  3378. mr2 |= MR2_STOP1;
  3379. if (tiosp->c_cflag & PARENB) {
  3380. if (tiosp->c_cflag & PARODD)
  3381. mr1 |= (MR1_PARENB | MR1_PARODD);
  3382. else
  3383. mr1 |= (MR1_PARENB | MR1_PAREVEN);
  3384. } else {
  3385. mr1 |= MR1_PARNONE;
  3386. }
  3387. mr1 |= MR1_ERRBLOCK;
  3388. /*
  3389. * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
  3390. * space for hardware flow control and the like. This should be set to
  3391. * VMIN.
  3392. */
  3393. mr2 |= MR2_RXFIFOHALF;
  3394. /*
  3395. * Calculate the baud rate timers. For now we will just assume that
  3396. * the input and output baud are the same. The sc26198 has a fixed
  3397. * baud rate table, so only discrete baud rates possible.
  3398. */
  3399. baudrate = tiosp->c_cflag & CBAUD;
  3400. if (baudrate & CBAUDEX) {
  3401. baudrate &= ~CBAUDEX;
  3402. if ((baudrate < 1) || (baudrate > 4))
  3403. tiosp->c_cflag &= ~CBAUDEX;
  3404. else
  3405. baudrate += 15;
  3406. }
  3407. baudrate = stl_baudrates[baudrate];
  3408. if ((tiosp->c_cflag & CBAUD) == B38400) {
  3409. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  3410. baudrate = 57600;
  3411. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  3412. baudrate = 115200;
  3413. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  3414. baudrate = 230400;
  3415. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  3416. baudrate = 460800;
  3417. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  3418. baudrate = (portp->baud_base / portp->custom_divisor);
  3419. }
  3420. if (baudrate > STL_SC26198MAXBAUD)
  3421. baudrate = STL_SC26198MAXBAUD;
  3422. if (baudrate > 0) {
  3423. for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
  3424. if (baudrate <= sc26198_baudtable[clk])
  3425. break;
  3426. }
  3427. }
  3428. /*
  3429. * Check what form of modem signaling is required and set it up.
  3430. */
  3431. if (tiosp->c_cflag & CLOCAL) {
  3432. portp->flags &= ~ASYNC_CHECK_CD;
  3433. } else {
  3434. iopr |= IOPR_DCDCOS;
  3435. imron |= IR_IOPORT;
  3436. portp->flags |= ASYNC_CHECK_CD;
  3437. }
  3438. /*
  3439. * Setup sc26198 enhanced modes if we can. In particular we want to
  3440. * handle as much of the flow control as possible automatically. As
  3441. * well as saving a few CPU cycles it will also greatly improve flow
  3442. * control reliability.
  3443. */
  3444. if (tiosp->c_iflag & IXON) {
  3445. mr0 |= MR0_SWFTX | MR0_SWFT;
  3446. imron |= IR_XONXOFF;
  3447. } else {
  3448. imroff |= IR_XONXOFF;
  3449. }
  3450. if (tiosp->c_iflag & IXOFF)
  3451. mr0 |= MR0_SWFRX;
  3452. if (tiosp->c_cflag & CRTSCTS) {
  3453. mr2 |= MR2_AUTOCTS;
  3454. mr1 |= MR1_AUTORTS;
  3455. }
  3456. /*
  3457. * All sc26198 register values calculated so go through and set
  3458. * them all up.
  3459. */
  3460. pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
  3461. portp->portnr, portp->panelnr, portp->brdnr);
  3462. pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
  3463. pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
  3464. pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
  3465. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  3466. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  3467. spin_lock_irqsave(&brd_lock, flags);
  3468. BRDENABLE(portp->brdnr, portp->pagenr);
  3469. stl_sc26198setreg(portp, IMR, 0);
  3470. stl_sc26198updatereg(portp, MR0, mr0);
  3471. stl_sc26198updatereg(portp, MR1, mr1);
  3472. stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
  3473. stl_sc26198updatereg(portp, MR2, mr2);
  3474. stl_sc26198updatereg(portp, IOPIOR,
  3475. ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
  3476. if (baudrate > 0) {
  3477. stl_sc26198setreg(portp, TXCSR, clk);
  3478. stl_sc26198setreg(portp, RXCSR, clk);
  3479. }
  3480. stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
  3481. stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
  3482. ipr = stl_sc26198getreg(portp, IPR);
  3483. if (ipr & IPR_DCD)
  3484. portp->sigs &= ~TIOCM_CD;
  3485. else
  3486. portp->sigs |= TIOCM_CD;
  3487. portp->imr = (portp->imr & ~imroff) | imron;
  3488. stl_sc26198setreg(portp, IMR, portp->imr);
  3489. BRDDISABLE(portp->brdnr);
  3490. spin_unlock_irqrestore(&brd_lock, flags);
  3491. }
  3492. /*****************************************************************************/
  3493. /*
  3494. * Set the state of the DTR and RTS signals.
  3495. */
  3496. static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts)
  3497. {
  3498. unsigned char iopioron, iopioroff;
  3499. unsigned long flags;
  3500. pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp,
  3501. dtr, rts);
  3502. iopioron = 0;
  3503. iopioroff = 0;
  3504. if (dtr == 0)
  3505. iopioroff |= IPR_DTR;
  3506. else if (dtr > 0)
  3507. iopioron |= IPR_DTR;
  3508. if (rts == 0)
  3509. iopioroff |= IPR_RTS;
  3510. else if (rts > 0)
  3511. iopioron |= IPR_RTS;
  3512. spin_lock_irqsave(&brd_lock, flags);
  3513. BRDENABLE(portp->brdnr, portp->pagenr);
  3514. stl_sc26198setreg(portp, IOPIOR,
  3515. ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
  3516. BRDDISABLE(portp->brdnr);
  3517. spin_unlock_irqrestore(&brd_lock, flags);
  3518. }
  3519. /*****************************************************************************/
  3520. /*
  3521. * Return the state of the signals.
  3522. */
  3523. static int stl_sc26198getsignals(struct stlport *portp)
  3524. {
  3525. unsigned char ipr;
  3526. unsigned long flags;
  3527. int sigs;
  3528. pr_debug("stl_sc26198getsignals(portp=%p)\n", portp);
  3529. spin_lock_irqsave(&brd_lock, flags);
  3530. BRDENABLE(portp->brdnr, portp->pagenr);
  3531. ipr = stl_sc26198getreg(portp, IPR);
  3532. BRDDISABLE(portp->brdnr);
  3533. spin_unlock_irqrestore(&brd_lock, flags);
  3534. sigs = 0;
  3535. sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
  3536. sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
  3537. sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
  3538. sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
  3539. sigs |= TIOCM_DSR;
  3540. return sigs;
  3541. }
  3542. /*****************************************************************************/
  3543. /*
  3544. * Enable/Disable the Transmitter and/or Receiver.
  3545. */
  3546. static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx)
  3547. {
  3548. unsigned char ccr;
  3549. unsigned long flags;
  3550. pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx);
  3551. ccr = portp->crenable;
  3552. if (tx == 0)
  3553. ccr &= ~CR_TXENABLE;
  3554. else if (tx > 0)
  3555. ccr |= CR_TXENABLE;
  3556. if (rx == 0)
  3557. ccr &= ~CR_RXENABLE;
  3558. else if (rx > 0)
  3559. ccr |= CR_RXENABLE;
  3560. spin_lock_irqsave(&brd_lock, flags);
  3561. BRDENABLE(portp->brdnr, portp->pagenr);
  3562. stl_sc26198setreg(portp, SCCR, ccr);
  3563. BRDDISABLE(portp->brdnr);
  3564. portp->crenable = ccr;
  3565. spin_unlock_irqrestore(&brd_lock, flags);
  3566. }
  3567. /*****************************************************************************/
  3568. /*
  3569. * Start/stop the Transmitter and/or Receiver.
  3570. */
  3571. static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx)
  3572. {
  3573. unsigned char imr;
  3574. unsigned long flags;
  3575. pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
  3576. imr = portp->imr;
  3577. if (tx == 0)
  3578. imr &= ~IR_TXRDY;
  3579. else if (tx == 1)
  3580. imr |= IR_TXRDY;
  3581. if (rx == 0)
  3582. imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
  3583. else if (rx > 0)
  3584. imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
  3585. spin_lock_irqsave(&brd_lock, flags);
  3586. BRDENABLE(portp->brdnr, portp->pagenr);
  3587. stl_sc26198setreg(portp, IMR, imr);
  3588. BRDDISABLE(portp->brdnr);
  3589. portp->imr = imr;
  3590. if (tx > 0)
  3591. set_bit(ASYI_TXBUSY, &portp->istate);
  3592. spin_unlock_irqrestore(&brd_lock, flags);
  3593. }
  3594. /*****************************************************************************/
  3595. /*
  3596. * Disable all interrupts from this port.
  3597. */
  3598. static void stl_sc26198disableintrs(struct stlport *portp)
  3599. {
  3600. unsigned long flags;
  3601. pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp);
  3602. spin_lock_irqsave(&brd_lock, flags);
  3603. BRDENABLE(portp->brdnr, portp->pagenr);
  3604. portp->imr = 0;
  3605. stl_sc26198setreg(portp, IMR, 0);
  3606. BRDDISABLE(portp->brdnr);
  3607. spin_unlock_irqrestore(&brd_lock, flags);
  3608. }
  3609. /*****************************************************************************/
  3610. static void stl_sc26198sendbreak(struct stlport *portp, int len)
  3611. {
  3612. unsigned long flags;
  3613. pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len);
  3614. spin_lock_irqsave(&brd_lock, flags);
  3615. BRDENABLE(portp->brdnr, portp->pagenr);
  3616. if (len == 1) {
  3617. stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
  3618. portp->stats.txbreaks++;
  3619. } else {
  3620. stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
  3621. }
  3622. BRDDISABLE(portp->brdnr);
  3623. spin_unlock_irqrestore(&brd_lock, flags);
  3624. }
  3625. /*****************************************************************************/
  3626. /*
  3627. * Take flow control actions...
  3628. */
  3629. static void stl_sc26198flowctrl(struct stlport *portp, int state)
  3630. {
  3631. struct tty_struct *tty;
  3632. unsigned long flags;
  3633. unsigned char mr0;
  3634. pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state);
  3635. if (portp == NULL)
  3636. return;
  3637. tty = portp->tty;
  3638. if (tty == NULL)
  3639. return;
  3640. spin_lock_irqsave(&brd_lock, flags);
  3641. BRDENABLE(portp->brdnr, portp->pagenr);
  3642. if (state) {
  3643. if (tty->termios->c_iflag & IXOFF) {
  3644. mr0 = stl_sc26198getreg(portp, MR0);
  3645. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3646. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  3647. mr0 |= MR0_SWFRX;
  3648. portp->stats.rxxon++;
  3649. stl_sc26198wait(portp);
  3650. stl_sc26198setreg(portp, MR0, mr0);
  3651. }
  3652. /*
  3653. * Question: should we return RTS to what it was before? It may
  3654. * have been set by an ioctl... Suppose not, since if you have
  3655. * hardware flow control set then it is pretty silly to go and
  3656. * set the RTS line by hand.
  3657. */
  3658. if (tty->termios->c_cflag & CRTSCTS) {
  3659. stl_sc26198setreg(portp, MR1,
  3660. (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
  3661. stl_sc26198setreg(portp, IOPIOR,
  3662. (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
  3663. portp->stats.rxrtson++;
  3664. }
  3665. } else {
  3666. if (tty->termios->c_iflag & IXOFF) {
  3667. mr0 = stl_sc26198getreg(portp, MR0);
  3668. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3669. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  3670. mr0 &= ~MR0_SWFRX;
  3671. portp->stats.rxxoff++;
  3672. stl_sc26198wait(portp);
  3673. stl_sc26198setreg(portp, MR0, mr0);
  3674. }
  3675. if (tty->termios->c_cflag & CRTSCTS) {
  3676. stl_sc26198setreg(portp, MR1,
  3677. (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
  3678. stl_sc26198setreg(portp, IOPIOR,
  3679. (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
  3680. portp->stats.rxrtsoff++;
  3681. }
  3682. }
  3683. BRDDISABLE(portp->brdnr);
  3684. spin_unlock_irqrestore(&brd_lock, flags);
  3685. }
  3686. /*****************************************************************************/
  3687. /*
  3688. * Send a flow control character.
  3689. */
  3690. static void stl_sc26198sendflow(struct stlport *portp, int state)
  3691. {
  3692. struct tty_struct *tty;
  3693. unsigned long flags;
  3694. unsigned char mr0;
  3695. pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state);
  3696. if (portp == NULL)
  3697. return;
  3698. tty = portp->tty;
  3699. if (tty == NULL)
  3700. return;
  3701. spin_lock_irqsave(&brd_lock, flags);
  3702. BRDENABLE(portp->brdnr, portp->pagenr);
  3703. if (state) {
  3704. mr0 = stl_sc26198getreg(portp, MR0);
  3705. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3706. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  3707. mr0 |= MR0_SWFRX;
  3708. portp->stats.rxxon++;
  3709. stl_sc26198wait(portp);
  3710. stl_sc26198setreg(portp, MR0, mr0);
  3711. } else {
  3712. mr0 = stl_sc26198getreg(portp, MR0);
  3713. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3714. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  3715. mr0 &= ~MR0_SWFRX;
  3716. portp->stats.rxxoff++;
  3717. stl_sc26198wait(portp);
  3718. stl_sc26198setreg(portp, MR0, mr0);
  3719. }
  3720. BRDDISABLE(portp->brdnr);
  3721. spin_unlock_irqrestore(&brd_lock, flags);
  3722. }
  3723. /*****************************************************************************/
  3724. static void stl_sc26198flush(struct stlport *portp)
  3725. {
  3726. unsigned long flags;
  3727. pr_debug("stl_sc26198flush(portp=%p)\n", portp);
  3728. if (portp == NULL)
  3729. return;
  3730. spin_lock_irqsave(&brd_lock, flags);
  3731. BRDENABLE(portp->brdnr, portp->pagenr);
  3732. stl_sc26198setreg(portp, SCCR, CR_TXRESET);
  3733. stl_sc26198setreg(portp, SCCR, portp->crenable);
  3734. BRDDISABLE(portp->brdnr);
  3735. portp->tx.tail = portp->tx.head;
  3736. spin_unlock_irqrestore(&brd_lock, flags);
  3737. }
  3738. /*****************************************************************************/
  3739. /*
  3740. * Return the current state of data flow on this port. This is only
  3741. * really interresting when determining if data has fully completed
  3742. * transmission or not... The sc26198 interrupt scheme cannot
  3743. * determine when all data has actually drained, so we need to
  3744. * check the port statusy register to be sure.
  3745. */
  3746. static int stl_sc26198datastate(struct stlport *portp)
  3747. {
  3748. unsigned long flags;
  3749. unsigned char sr;
  3750. pr_debug("stl_sc26198datastate(portp=%p)\n", portp);
  3751. if (portp == NULL)
  3752. return 0;
  3753. if (test_bit(ASYI_TXBUSY, &portp->istate))
  3754. return 1;
  3755. spin_lock_irqsave(&brd_lock, flags);
  3756. BRDENABLE(portp->brdnr, portp->pagenr);
  3757. sr = stl_sc26198getreg(portp, SR);
  3758. BRDDISABLE(portp->brdnr);
  3759. spin_unlock_irqrestore(&brd_lock, flags);
  3760. return (sr & SR_TXEMPTY) ? 0 : 1;
  3761. }
  3762. /*****************************************************************************/
  3763. /*
  3764. * Delay for a small amount of time, to give the sc26198 a chance
  3765. * to process a command...
  3766. */
  3767. static void stl_sc26198wait(struct stlport *portp)
  3768. {
  3769. int i;
  3770. pr_debug("stl_sc26198wait(portp=%p)\n", portp);
  3771. if (portp == NULL)
  3772. return;
  3773. for (i = 0; (i < 20); i++)
  3774. stl_sc26198getglobreg(portp, TSTR);
  3775. }
  3776. /*****************************************************************************/
  3777. /*
  3778. * If we are TX flow controlled and in IXANY mode then we may
  3779. * need to unflow control here. We gotta do this because of the
  3780. * automatic flow control modes of the sc26198.
  3781. */
  3782. static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty)
  3783. {
  3784. unsigned char mr0;
  3785. mr0 = stl_sc26198getreg(portp, MR0);
  3786. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3787. stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
  3788. stl_sc26198wait(portp);
  3789. stl_sc26198setreg(portp, MR0, mr0);
  3790. clear_bit(ASYI_TXFLOWED, &portp->istate);
  3791. }
  3792. /*****************************************************************************/
  3793. /*
  3794. * Interrupt service routine for sc26198 panels.
  3795. */
  3796. static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
  3797. {
  3798. struct stlport *portp;
  3799. unsigned int iack;
  3800. spin_lock(&brd_lock);
  3801. /*
  3802. * Work around bug in sc26198 chip... Cannot have A6 address
  3803. * line of UART high, else iack will be returned as 0.
  3804. */
  3805. outb(0, (iobase + 1));
  3806. iack = inb(iobase + XP_IACK);
  3807. portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
  3808. if (iack & IVR_RXDATA)
  3809. stl_sc26198rxisr(portp, iack);
  3810. else if (iack & IVR_TXDATA)
  3811. stl_sc26198txisr(portp);
  3812. else
  3813. stl_sc26198otherisr(portp, iack);
  3814. spin_unlock(&brd_lock);
  3815. }
  3816. /*****************************************************************************/
  3817. /*
  3818. * Transmit interrupt handler. This has gotta be fast! Handling TX
  3819. * chars is pretty simple, stuff as many as possible from the TX buffer
  3820. * into the sc26198 FIFO.
  3821. * In practice it is possible that interrupts are enabled but that the
  3822. * port has been hung up. Need to handle not having any TX buffer here,
  3823. * this is done by using the side effect that head and tail will also
  3824. * be NULL if the buffer has been freed.
  3825. */
  3826. static void stl_sc26198txisr(struct stlport *portp)
  3827. {
  3828. unsigned int ioaddr;
  3829. unsigned char mr0;
  3830. int len, stlen;
  3831. char *head, *tail;
  3832. pr_debug("stl_sc26198txisr(portp=%p)\n", portp);
  3833. ioaddr = portp->ioaddr;
  3834. head = portp->tx.head;
  3835. tail = portp->tx.tail;
  3836. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  3837. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  3838. (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  3839. set_bit(ASYI_TXLOW, &portp->istate);
  3840. schedule_work(&portp->tqueue);
  3841. }
  3842. if (len == 0) {
  3843. outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
  3844. mr0 = inb(ioaddr + XP_DATA);
  3845. if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
  3846. portp->imr &= ~IR_TXRDY;
  3847. outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
  3848. outb(portp->imr, (ioaddr + XP_DATA));
  3849. clear_bit(ASYI_TXBUSY, &portp->istate);
  3850. } else {
  3851. mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
  3852. outb(mr0, (ioaddr + XP_DATA));
  3853. }
  3854. } else {
  3855. len = MIN(len, SC26198_TXFIFOSIZE);
  3856. portp->stats.txtotal += len;
  3857. stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
  3858. outb(GTXFIFO, (ioaddr + XP_ADDR));
  3859. outsb((ioaddr + XP_DATA), tail, stlen);
  3860. len -= stlen;
  3861. tail += stlen;
  3862. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  3863. tail = portp->tx.buf;
  3864. if (len > 0) {
  3865. outsb((ioaddr + XP_DATA), tail, len);
  3866. tail += len;
  3867. }
  3868. portp->tx.tail = tail;
  3869. }
  3870. }
  3871. /*****************************************************************************/
  3872. /*
  3873. * Receive character interrupt handler. Determine if we have good chars
  3874. * or bad chars and then process appropriately. Good chars are easy
  3875. * just shove the lot into the RX buffer and set all status byte to 0.
  3876. * If a bad RX char then process as required. This routine needs to be
  3877. * fast! In practice it is possible that we get an interrupt on a port
  3878. * that is closed. This can happen on hangups - since they completely
  3879. * shutdown a port not in user context. Need to handle this case.
  3880. */
  3881. static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
  3882. {
  3883. struct tty_struct *tty;
  3884. unsigned int len, buflen, ioaddr;
  3885. pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
  3886. tty = portp->tty;
  3887. ioaddr = portp->ioaddr;
  3888. outb(GIBCR, (ioaddr + XP_ADDR));
  3889. len = inb(ioaddr + XP_DATA) + 1;
  3890. if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
  3891. if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
  3892. len = MIN(len, sizeof(stl_unwanted));
  3893. outb(GRXFIFO, (ioaddr + XP_ADDR));
  3894. insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
  3895. portp->stats.rxlost += len;
  3896. portp->stats.rxtotal += len;
  3897. } else {
  3898. len = MIN(len, buflen);
  3899. if (len > 0) {
  3900. unsigned char *ptr;
  3901. outb(GRXFIFO, (ioaddr + XP_ADDR));
  3902. tty_prepare_flip_string(tty, &ptr, len);
  3903. insb((ioaddr + XP_DATA), ptr, len);
  3904. tty_schedule_flip(tty);
  3905. portp->stats.rxtotal += len;
  3906. }
  3907. }
  3908. } else {
  3909. stl_sc26198rxbadchars(portp);
  3910. }
  3911. /*
  3912. * If we are TX flow controlled and in IXANY mode then we may need
  3913. * to unflow control here. We gotta do this because of the automatic
  3914. * flow control modes of the sc26198.
  3915. */
  3916. if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
  3917. if ((tty != NULL) &&
  3918. (tty->termios != NULL) &&
  3919. (tty->termios->c_iflag & IXANY)) {
  3920. stl_sc26198txunflow(portp, tty);
  3921. }
  3922. }
  3923. }
  3924. /*****************************************************************************/
  3925. /*
  3926. * Process an RX bad character.
  3927. */
  3928. static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch)
  3929. {
  3930. struct tty_struct *tty;
  3931. unsigned int ioaddr;
  3932. tty = portp->tty;
  3933. ioaddr = portp->ioaddr;
  3934. if (status & SR_RXPARITY)
  3935. portp->stats.rxparity++;
  3936. if (status & SR_RXFRAMING)
  3937. portp->stats.rxframing++;
  3938. if (status & SR_RXOVERRUN)
  3939. portp->stats.rxoverrun++;
  3940. if (status & SR_RXBREAK)
  3941. portp->stats.rxbreaks++;
  3942. if ((tty != NULL) &&
  3943. ((portp->rxignoremsk & status) == 0)) {
  3944. if (portp->rxmarkmsk & status) {
  3945. if (status & SR_RXBREAK) {
  3946. status = TTY_BREAK;
  3947. if (portp->flags & ASYNC_SAK) {
  3948. do_SAK(tty);
  3949. BRDENABLE(portp->brdnr, portp->pagenr);
  3950. }
  3951. } else if (status & SR_RXPARITY) {
  3952. status = TTY_PARITY;
  3953. } else if (status & SR_RXFRAMING) {
  3954. status = TTY_FRAME;
  3955. } else if(status & SR_RXOVERRUN) {
  3956. status = TTY_OVERRUN;
  3957. } else {
  3958. status = 0;
  3959. }
  3960. } else {
  3961. status = 0;
  3962. }
  3963. tty_insert_flip_char(tty, ch, status);
  3964. tty_schedule_flip(tty);
  3965. if (status == 0)
  3966. portp->stats.rxtotal++;
  3967. }
  3968. }
  3969. /*****************************************************************************/
  3970. /*
  3971. * Process all characters in the RX FIFO of the UART. Check all char
  3972. * status bytes as well, and process as required. We need to check
  3973. * all bytes in the FIFO, in case some more enter the FIFO while we
  3974. * are here. To get the exact character error type we need to switch
  3975. * into CHAR error mode (that is why we need to make sure we empty
  3976. * the FIFO).
  3977. */
  3978. static void stl_sc26198rxbadchars(struct stlport *portp)
  3979. {
  3980. unsigned char status, mr1;
  3981. char ch;
  3982. /*
  3983. * To get the precise error type for each character we must switch
  3984. * back into CHAR error mode.
  3985. */
  3986. mr1 = stl_sc26198getreg(portp, MR1);
  3987. stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
  3988. while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
  3989. stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
  3990. ch = stl_sc26198getreg(portp, RXFIFO);
  3991. stl_sc26198rxbadch(portp, status, ch);
  3992. }
  3993. /*
  3994. * To get correct interrupt class we must switch back into BLOCK
  3995. * error mode.
  3996. */
  3997. stl_sc26198setreg(portp, MR1, mr1);
  3998. }
  3999. /*****************************************************************************/
  4000. /*
  4001. * Other interrupt handler. This includes modem signals, flow
  4002. * control actions, etc. Most stuff is left to off-level interrupt
  4003. * processing time.
  4004. */
  4005. static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
  4006. {
  4007. unsigned char cir, ipr, xisr;
  4008. pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack);
  4009. cir = stl_sc26198getglobreg(portp, CIR);
  4010. switch (cir & CIR_SUBTYPEMASK) {
  4011. case CIR_SUBCOS:
  4012. ipr = stl_sc26198getreg(portp, IPR);
  4013. if (ipr & IPR_DCDCHANGE) {
  4014. set_bit(ASYI_DCDCHANGE, &portp->istate);
  4015. schedule_work(&portp->tqueue);
  4016. portp->stats.modem++;
  4017. }
  4018. break;
  4019. case CIR_SUBXONXOFF:
  4020. xisr = stl_sc26198getreg(portp, XISR);
  4021. if (xisr & XISR_RXXONGOT) {
  4022. set_bit(ASYI_TXFLOWED, &portp->istate);
  4023. portp->stats.txxoff++;
  4024. }
  4025. if (xisr & XISR_RXXOFFGOT) {
  4026. clear_bit(ASYI_TXFLOWED, &portp->istate);
  4027. portp->stats.txxon++;
  4028. }
  4029. break;
  4030. case CIR_SUBBREAK:
  4031. stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
  4032. stl_sc26198rxbadchars(portp);
  4033. break;
  4034. default:
  4035. break;
  4036. }
  4037. }
  4038. /*
  4039. * Loadable module initialization stuff.
  4040. */
  4041. static int __init stallion_module_init(void)
  4042. {
  4043. unsigned int i;
  4044. printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
  4045. spin_lock_init(&stallion_lock);
  4046. spin_lock_init(&brd_lock);
  4047. stl_initbrds();
  4048. stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
  4049. if (!stl_serial)
  4050. return -1;
  4051. /*
  4052. * Set up a character driver for per board stuff. This is mainly used
  4053. * to do stats ioctls on the ports.
  4054. */
  4055. if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
  4056. printk("STALLION: failed to register serial board device\n");
  4057. stallion_class = class_create(THIS_MODULE, "staliomem");
  4058. for (i = 0; i < 4; i++)
  4059. class_device_create(stallion_class, NULL,
  4060. MKDEV(STL_SIOMEMMAJOR, i), NULL,
  4061. "staliomem%d", i);
  4062. stl_serial->owner = THIS_MODULE;
  4063. stl_serial->driver_name = stl_drvname;
  4064. stl_serial->name = "ttyE";
  4065. stl_serial->major = STL_SERIALMAJOR;
  4066. stl_serial->minor_start = 0;
  4067. stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
  4068. stl_serial->subtype = SERIAL_TYPE_NORMAL;
  4069. stl_serial->init_termios = stl_deftermios;
  4070. stl_serial->flags = TTY_DRIVER_REAL_RAW;
  4071. tty_set_operations(stl_serial, &stl_ops);
  4072. if (tty_register_driver(stl_serial)) {
  4073. put_tty_driver(stl_serial);
  4074. printk("STALLION: failed to register serial driver\n");
  4075. return -1;
  4076. }
  4077. return 0;
  4078. }
  4079. static void __exit stallion_module_exit(void)
  4080. {
  4081. struct stlbrd *brdp;
  4082. struct stlpanel *panelp;
  4083. struct stlport *portp;
  4084. int i, j, k;
  4085. pr_debug("cleanup_module()\n");
  4086. printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
  4087. stl_drvversion);
  4088. /*
  4089. * Free up all allocated resources used by the ports. This includes
  4090. * memory and interrupts. As part of this process we will also do
  4091. * a hangup on every open port - to try to flush out any processes
  4092. * hanging onto ports.
  4093. */
  4094. i = tty_unregister_driver(stl_serial);
  4095. put_tty_driver(stl_serial);
  4096. if (i) {
  4097. printk("STALLION: failed to un-register tty driver, "
  4098. "errno=%d\n", -i);
  4099. return;
  4100. }
  4101. for (i = 0; i < 4; i++)
  4102. class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
  4103. if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
  4104. printk("STALLION: failed to un-register serial memory device, "
  4105. "errno=%d\n", -i);
  4106. class_destroy(stallion_class);
  4107. for (i = 0; (i < stl_nrbrds); i++) {
  4108. if ((brdp = stl_brds[i]) == NULL)
  4109. continue;
  4110. free_irq(brdp->irq, brdp);
  4111. for (j = 0; (j < STL_MAXPANELS); j++) {
  4112. panelp = brdp->panels[j];
  4113. if (panelp == NULL)
  4114. continue;
  4115. for (k = 0; (k < STL_PORTSPERPANEL); k++) {
  4116. portp = panelp->ports[k];
  4117. if (portp == NULL)
  4118. continue;
  4119. if (portp->tty != NULL)
  4120. stl_hangup(portp->tty);
  4121. kfree(portp->tx.buf);
  4122. kfree(portp);
  4123. }
  4124. kfree(panelp);
  4125. }
  4126. release_region(brdp->ioaddr1, brdp->iosize1);
  4127. if (brdp->iosize2 > 0)
  4128. release_region(brdp->ioaddr2, brdp->iosize2);
  4129. kfree(brdp);
  4130. stl_brds[i] = NULL;
  4131. }
  4132. }
  4133. module_init(stallion_module_init);
  4134. module_exit(stallion_module_exit);
  4135. MODULE_AUTHOR("Greg Ungerer");
  4136. MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
  4137. MODULE_LICENSE("GPL");