stallion.c 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894
  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 ktermios stl_deftermios = {
  128. .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
  129. .c_cc = INIT_C_CC,
  130. .c_ispeed = 9600,
  131. .c_ospeed = 9600,
  132. };
  133. /*
  134. * Define global stats structures. Not used often, and can be
  135. * re-used for each stats call.
  136. */
  137. static comstats_t stl_comstats;
  138. static combrd_t stl_brdstats;
  139. static struct stlbrd stl_dummybrd;
  140. static struct stlport stl_dummyport;
  141. /*
  142. * Define global place to put buffer overflow characters.
  143. */
  144. static char stl_unwanted[SC26198_RXFIFOSIZE];
  145. /*****************************************************************************/
  146. static struct stlbrd *stl_brds[STL_MAXBRDS];
  147. /*
  148. * Per board state flags. Used with the state field of the board struct.
  149. * Not really much here!
  150. */
  151. #define BRD_FOUND 0x1
  152. /*
  153. * Define the port structure istate flags. These set of flags are
  154. * modified at interrupt time - so setting and reseting them needs
  155. * to be atomic. Use the bit clear/setting routines for this.
  156. */
  157. #define ASYI_TXBUSY 1
  158. #define ASYI_TXLOW 2
  159. #define ASYI_DCDCHANGE 3
  160. #define ASYI_TXFLOWED 4
  161. /*
  162. * Define an array of board names as printable strings. Handy for
  163. * referencing boards when printing trace and stuff.
  164. */
  165. static char *stl_brdnames[] = {
  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. NULL,
  185. NULL,
  186. "EasyIO",
  187. "EC8/32-AT",
  188. "EC8/32-MC",
  189. NULL,
  190. NULL,
  191. NULL,
  192. "EC8/32-PCI",
  193. "EC8/64-PCI",
  194. "EasyIO-PCI",
  195. };
  196. /*****************************************************************************/
  197. /*
  198. * Define some string labels for arguments passed from the module
  199. * load line. These allow for easy board definitions, and easy
  200. * modification of the io, memory and irq resoucres.
  201. */
  202. static int stl_nargs = 0;
  203. static char *board0[4];
  204. static char *board1[4];
  205. static char *board2[4];
  206. static char *board3[4];
  207. static char **stl_brdsp[] = {
  208. (char **) &board0,
  209. (char **) &board1,
  210. (char **) &board2,
  211. (char **) &board3
  212. };
  213. /*
  214. * Define a set of common board names, and types. This is used to
  215. * parse any module arguments.
  216. */
  217. static struct {
  218. char *name;
  219. int type;
  220. } stl_brdstr[] = {
  221. { "easyio", BRD_EASYIO },
  222. { "eio", BRD_EASYIO },
  223. { "20", BRD_EASYIO },
  224. { "ec8/32", BRD_ECH },
  225. { "ec8/32-at", BRD_ECH },
  226. { "ec8/32-isa", BRD_ECH },
  227. { "ech", BRD_ECH },
  228. { "echat", BRD_ECH },
  229. { "21", BRD_ECH },
  230. { "ec8/32-mc", BRD_ECHMC },
  231. { "ec8/32-mca", BRD_ECHMC },
  232. { "echmc", BRD_ECHMC },
  233. { "echmca", BRD_ECHMC },
  234. { "22", BRD_ECHMC },
  235. { "ec8/32-pc", BRD_ECHPCI },
  236. { "ec8/32-pci", BRD_ECHPCI },
  237. { "26", BRD_ECHPCI },
  238. { "ec8/64-pc", BRD_ECH64PCI },
  239. { "ec8/64-pci", BRD_ECH64PCI },
  240. { "ech-pci", BRD_ECH64PCI },
  241. { "echpci", BRD_ECH64PCI },
  242. { "echpc", BRD_ECH64PCI },
  243. { "27", BRD_ECH64PCI },
  244. { "easyio-pc", BRD_EASYIOPCI },
  245. { "easyio-pci", BRD_EASYIOPCI },
  246. { "eio-pci", BRD_EASYIOPCI },
  247. { "eiopci", BRD_EASYIOPCI },
  248. { "28", BRD_EASYIOPCI },
  249. };
  250. /*
  251. * Define the module agruments.
  252. */
  253. module_param_array(board0, charp, &stl_nargs, 0);
  254. MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
  255. module_param_array(board1, charp, &stl_nargs, 0);
  256. MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
  257. module_param_array(board2, charp, &stl_nargs, 0);
  258. MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
  259. module_param_array(board3, charp, &stl_nargs, 0);
  260. MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
  261. /*****************************************************************************/
  262. /*
  263. * Hardware ID bits for the EasyIO and ECH boards. These defines apply
  264. * to the directly accessible io ports of these boards (not the uarts -
  265. * they are in cd1400.h and sc26198.h).
  266. */
  267. #define EIO_8PORTRS 0x04
  268. #define EIO_4PORTRS 0x05
  269. #define EIO_8PORTDI 0x00
  270. #define EIO_8PORTM 0x06
  271. #define EIO_MK3 0x03
  272. #define EIO_IDBITMASK 0x07
  273. #define EIO_BRDMASK 0xf0
  274. #define ID_BRD4 0x10
  275. #define ID_BRD8 0x20
  276. #define ID_BRD16 0x30
  277. #define EIO_INTRPEND 0x08
  278. #define EIO_INTEDGE 0x00
  279. #define EIO_INTLEVEL 0x08
  280. #define EIO_0WS 0x10
  281. #define ECH_ID 0xa0
  282. #define ECH_IDBITMASK 0xe0
  283. #define ECH_BRDENABLE 0x08
  284. #define ECH_BRDDISABLE 0x00
  285. #define ECH_INTENABLE 0x01
  286. #define ECH_INTDISABLE 0x00
  287. #define ECH_INTLEVEL 0x02
  288. #define ECH_INTEDGE 0x00
  289. #define ECH_INTRPEND 0x01
  290. #define ECH_BRDRESET 0x01
  291. #define ECHMC_INTENABLE 0x01
  292. #define ECHMC_BRDRESET 0x02
  293. #define ECH_PNLSTATUS 2
  294. #define ECH_PNL16PORT 0x20
  295. #define ECH_PNLIDMASK 0x07
  296. #define ECH_PNLXPID 0x40
  297. #define ECH_PNLINTRPEND 0x80
  298. #define ECH_ADDR2MASK 0x1e0
  299. /*
  300. * Define the vector mapping bits for the programmable interrupt board
  301. * hardware. These bits encode the interrupt for the board to use - it
  302. * is software selectable (except the EIO-8M).
  303. */
  304. static unsigned char stl_vecmap[] = {
  305. 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
  306. 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
  307. };
  308. /*
  309. * Lock ordering is that you may not take stallion_lock holding
  310. * brd_lock.
  311. */
  312. static spinlock_t brd_lock; /* Guard the board mapping */
  313. static spinlock_t stallion_lock; /* Guard the tty driver */
  314. /*
  315. * Set up enable and disable macros for the ECH boards. They require
  316. * the secondary io address space to be activated and deactivated.
  317. * This way all ECH boards can share their secondary io region.
  318. * If this is an ECH-PCI board then also need to set the page pointer
  319. * to point to the correct page.
  320. */
  321. #define BRDENABLE(brdnr,pagenr) \
  322. if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
  323. outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
  324. stl_brds[(brdnr)]->ioctrl); \
  325. else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
  326. outb((pagenr), stl_brds[(brdnr)]->ioctrl);
  327. #define BRDDISABLE(brdnr) \
  328. if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
  329. outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
  330. stl_brds[(brdnr)]->ioctrl);
  331. #define STL_CD1400MAXBAUD 230400
  332. #define STL_SC26198MAXBAUD 460800
  333. #define STL_BAUDBASE 115200
  334. #define STL_CLOSEDELAY (5 * HZ / 10)
  335. /*****************************************************************************/
  336. /*
  337. * Define the Stallion PCI vendor and device IDs.
  338. */
  339. #ifndef PCI_VENDOR_ID_STALLION
  340. #define PCI_VENDOR_ID_STALLION 0x124d
  341. #endif
  342. #ifndef PCI_DEVICE_ID_ECHPCI832
  343. #define PCI_DEVICE_ID_ECHPCI832 0x0000
  344. #endif
  345. #ifndef PCI_DEVICE_ID_ECHPCI864
  346. #define PCI_DEVICE_ID_ECHPCI864 0x0002
  347. #endif
  348. #ifndef PCI_DEVICE_ID_EIOPCI
  349. #define PCI_DEVICE_ID_EIOPCI 0x0003
  350. #endif
  351. /*
  352. * Define structure to hold all Stallion PCI boards.
  353. */
  354. static struct pci_device_id stl_pcibrds[] = {
  355. { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864),
  356. .driver_data = BRD_ECH64PCI },
  357. { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI),
  358. .driver_data = BRD_EASYIOPCI },
  359. { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832),
  360. .driver_data = BRD_ECHPCI },
  361. { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410),
  362. .driver_data = BRD_ECHPCI },
  363. { }
  364. };
  365. MODULE_DEVICE_TABLE(pci, stl_pcibrds);
  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 ktermios *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 ktermios *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 ktermios *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 ktermios *old)
  1210. {
  1211. struct stlport *portp;
  1212. struct ktermios *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. static void stl_cleanup_panels(struct stlbrd *brdp)
  2022. {
  2023. struct stlpanel *panelp;
  2024. struct stlport *portp;
  2025. unsigned int j, k;
  2026. for (j = 0; j < STL_MAXPANELS; j++) {
  2027. panelp = brdp->panels[j];
  2028. if (panelp == NULL)
  2029. continue;
  2030. for (k = 0; k < STL_PORTSPERPANEL; k++) {
  2031. portp = panelp->ports[k];
  2032. if (portp == NULL)
  2033. continue;
  2034. if (portp->tty != NULL)
  2035. stl_hangup(portp->tty);
  2036. kfree(portp->tx.buf);
  2037. kfree(portp);
  2038. }
  2039. kfree(panelp);
  2040. }
  2041. }
  2042. /*****************************************************************************/
  2043. /*
  2044. * We have a Stallion board. Allocate a board structure and
  2045. * initialize it. Read its IO and IRQ resources from PCI
  2046. * configuration space.
  2047. */
  2048. static int __devinit stl_pciprobe(struct pci_dev *pdev,
  2049. const struct pci_device_id *ent)
  2050. {
  2051. struct stlbrd *brdp;
  2052. unsigned int brdtype = ent->driver_data;
  2053. pr_debug("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
  2054. pdev->bus->number, pdev->devfn);
  2055. if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
  2056. return -ENODEV;
  2057. dev_info(&pdev->dev, "please, report this to LKML: %x/%x/%x\n",
  2058. pdev->vendor, pdev->device, pdev->class);
  2059. if (pci_enable_device(pdev))
  2060. return(-EIO);
  2061. if ((brdp = stl_allocbrd()) == NULL)
  2062. return(-ENOMEM);
  2063. if ((brdp->brdnr = stl_getbrdnr()) < 0) {
  2064. printk("STALLION: too many boards found, "
  2065. "maximum supported %d\n", STL_MAXBRDS);
  2066. return(0);
  2067. }
  2068. brdp->brdtype = brdtype;
  2069. /*
  2070. * Different Stallion boards use the BAR registers in different ways,
  2071. * so set up io addresses based on board type.
  2072. */
  2073. pr_debug("%s(%d): BAR[]=%Lx,%Lx,%Lx,%Lx IRQ=%x\n", __FILE__, __LINE__,
  2074. pci_resource_start(pdev, 0), pci_resource_start(pdev, 1),
  2075. pci_resource_start(pdev, 2), pci_resource_start(pdev, 3), pdev->irq);
  2076. /*
  2077. * We have all resources from the board, so let's setup the actual
  2078. * board structure now.
  2079. */
  2080. switch (brdtype) {
  2081. case BRD_ECHPCI:
  2082. brdp->ioaddr2 = pci_resource_start(pdev, 0);
  2083. brdp->ioaddr1 = pci_resource_start(pdev, 1);
  2084. break;
  2085. case BRD_ECH64PCI:
  2086. brdp->ioaddr2 = pci_resource_start(pdev, 2);
  2087. brdp->ioaddr1 = pci_resource_start(pdev, 1);
  2088. break;
  2089. case BRD_EASYIOPCI:
  2090. brdp->ioaddr1 = pci_resource_start(pdev, 2);
  2091. brdp->ioaddr2 = pci_resource_start(pdev, 1);
  2092. break;
  2093. default:
  2094. printk("STALLION: unknown PCI board type=%d\n", brdtype);
  2095. break;
  2096. }
  2097. brdp->irq = pdev->irq;
  2098. stl_brdinit(brdp);
  2099. pci_set_drvdata(pdev, brdp);
  2100. return(0);
  2101. }
  2102. static void __devexit stl_pciremove(struct pci_dev *pdev)
  2103. {
  2104. struct stlbrd *brdp = pci_get_drvdata(pdev);
  2105. free_irq(brdp->irq, brdp);
  2106. stl_cleanup_panels(brdp);
  2107. release_region(brdp->ioaddr1, brdp->iosize1);
  2108. if (brdp->iosize2 > 0)
  2109. release_region(brdp->ioaddr2, brdp->iosize2);
  2110. stl_brds[brdp->brdnr] = NULL;
  2111. kfree(brdp);
  2112. }
  2113. static struct pci_driver stl_pcidriver = {
  2114. .name = "stallion",
  2115. .id_table = stl_pcibrds,
  2116. .probe = stl_pciprobe,
  2117. .remove = __devexit_p(stl_pciremove)
  2118. };
  2119. /*****************************************************************************/
  2120. /*
  2121. * Scan through all the boards in the configuration and see what we
  2122. * can find. Handle EIO and the ECH boards a little differently here
  2123. * since the initial search and setup is too different.
  2124. */
  2125. static int __init stl_initbrds(void)
  2126. {
  2127. struct stlbrd *brdp;
  2128. struct stlconf *confp;
  2129. int i;
  2130. pr_debug("stl_initbrds()\n");
  2131. if (stl_nrbrds > STL_MAXBRDS) {
  2132. printk("STALLION: too many boards in configuration table, "
  2133. "truncating to %d\n", STL_MAXBRDS);
  2134. stl_nrbrds = STL_MAXBRDS;
  2135. }
  2136. /*
  2137. * Firstly scan the list of static boards configured. Allocate
  2138. * resources and initialize the boards as found.
  2139. */
  2140. for (i = 0; (i < stl_nrbrds); i++) {
  2141. confp = &stl_brdconf[i];
  2142. stl_parsebrd(confp, stl_brdsp[i]);
  2143. if ((brdp = stl_allocbrd()) == NULL)
  2144. return(-ENOMEM);
  2145. brdp->brdnr = i;
  2146. brdp->brdtype = confp->brdtype;
  2147. brdp->ioaddr1 = confp->ioaddr1;
  2148. brdp->ioaddr2 = confp->ioaddr2;
  2149. brdp->irq = confp->irq;
  2150. brdp->irqtype = confp->irqtype;
  2151. stl_brdinit(brdp);
  2152. }
  2153. /*
  2154. * Find any dynamically supported boards. That is via module load
  2155. * line options or auto-detected on the PCI bus.
  2156. */
  2157. stl_argbrds();
  2158. return(0);
  2159. }
  2160. /*****************************************************************************/
  2161. /*
  2162. * Return the board stats structure to user app.
  2163. */
  2164. static int stl_getbrdstats(combrd_t __user *bp)
  2165. {
  2166. struct stlbrd *brdp;
  2167. struct stlpanel *panelp;
  2168. int i;
  2169. if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
  2170. return -EFAULT;
  2171. if (stl_brdstats.brd >= STL_MAXBRDS)
  2172. return(-ENODEV);
  2173. brdp = stl_brds[stl_brdstats.brd];
  2174. if (brdp == NULL)
  2175. return(-ENODEV);
  2176. memset(&stl_brdstats, 0, sizeof(combrd_t));
  2177. stl_brdstats.brd = brdp->brdnr;
  2178. stl_brdstats.type = brdp->brdtype;
  2179. stl_brdstats.hwid = brdp->hwid;
  2180. stl_brdstats.state = brdp->state;
  2181. stl_brdstats.ioaddr = brdp->ioaddr1;
  2182. stl_brdstats.ioaddr2 = brdp->ioaddr2;
  2183. stl_brdstats.irq = brdp->irq;
  2184. stl_brdstats.nrpanels = brdp->nrpanels;
  2185. stl_brdstats.nrports = brdp->nrports;
  2186. for (i = 0; (i < brdp->nrpanels); i++) {
  2187. panelp = brdp->panels[i];
  2188. stl_brdstats.panels[i].panel = i;
  2189. stl_brdstats.panels[i].hwid = panelp->hwid;
  2190. stl_brdstats.panels[i].nrports = panelp->nrports;
  2191. }
  2192. return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
  2193. }
  2194. /*****************************************************************************/
  2195. /*
  2196. * Resolve the referenced port number into a port struct pointer.
  2197. */
  2198. static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
  2199. {
  2200. struct stlbrd *brdp;
  2201. struct stlpanel *panelp;
  2202. if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
  2203. return(NULL);
  2204. brdp = stl_brds[brdnr];
  2205. if (brdp == NULL)
  2206. return(NULL);
  2207. if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
  2208. return(NULL);
  2209. panelp = brdp->panels[panelnr];
  2210. if (panelp == NULL)
  2211. return(NULL);
  2212. if ((portnr < 0) || (portnr >= panelp->nrports))
  2213. return(NULL);
  2214. return(panelp->ports[portnr]);
  2215. }
  2216. /*****************************************************************************/
  2217. /*
  2218. * Return the port stats structure to user app. A NULL port struct
  2219. * pointer passed in means that we need to find out from the app
  2220. * what port to get stats for (used through board control device).
  2221. */
  2222. static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
  2223. {
  2224. unsigned char *head, *tail;
  2225. unsigned long flags;
  2226. if (!portp) {
  2227. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  2228. return -EFAULT;
  2229. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  2230. stl_comstats.port);
  2231. if (portp == NULL)
  2232. return(-ENODEV);
  2233. }
  2234. portp->stats.state = portp->istate;
  2235. portp->stats.flags = portp->flags;
  2236. portp->stats.hwid = portp->hwid;
  2237. portp->stats.ttystate = 0;
  2238. portp->stats.cflags = 0;
  2239. portp->stats.iflags = 0;
  2240. portp->stats.oflags = 0;
  2241. portp->stats.lflags = 0;
  2242. portp->stats.rxbuffered = 0;
  2243. spin_lock_irqsave(&stallion_lock, flags);
  2244. if (portp->tty != NULL) {
  2245. if (portp->tty->driver_data == portp) {
  2246. portp->stats.ttystate = portp->tty->flags;
  2247. /* No longer available as a statistic */
  2248. portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
  2249. if (portp->tty->termios != NULL) {
  2250. portp->stats.cflags = portp->tty->termios->c_cflag;
  2251. portp->stats.iflags = portp->tty->termios->c_iflag;
  2252. portp->stats.oflags = portp->tty->termios->c_oflag;
  2253. portp->stats.lflags = portp->tty->termios->c_lflag;
  2254. }
  2255. }
  2256. }
  2257. spin_unlock_irqrestore(&stallion_lock, flags);
  2258. head = portp->tx.head;
  2259. tail = portp->tx.tail;
  2260. portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
  2261. (STL_TXBUFSIZE - (tail - head)));
  2262. portp->stats.signals = (unsigned long) stl_getsignals(portp);
  2263. return copy_to_user(cp, &portp->stats,
  2264. sizeof(comstats_t)) ? -EFAULT : 0;
  2265. }
  2266. /*****************************************************************************/
  2267. /*
  2268. * Clear the port stats structure. We also return it zeroed out...
  2269. */
  2270. static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
  2271. {
  2272. if (!portp) {
  2273. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  2274. return -EFAULT;
  2275. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  2276. stl_comstats.port);
  2277. if (portp == NULL)
  2278. return(-ENODEV);
  2279. }
  2280. memset(&portp->stats, 0, sizeof(comstats_t));
  2281. portp->stats.brd = portp->brdnr;
  2282. portp->stats.panel = portp->panelnr;
  2283. portp->stats.port = portp->portnr;
  2284. return copy_to_user(cp, &portp->stats,
  2285. sizeof(comstats_t)) ? -EFAULT : 0;
  2286. }
  2287. /*****************************************************************************/
  2288. /*
  2289. * Return the entire driver ports structure to a user app.
  2290. */
  2291. static int stl_getportstruct(struct stlport __user *arg)
  2292. {
  2293. struct stlport *portp;
  2294. if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
  2295. return -EFAULT;
  2296. portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
  2297. stl_dummyport.portnr);
  2298. if (!portp)
  2299. return -ENODEV;
  2300. return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0;
  2301. }
  2302. /*****************************************************************************/
  2303. /*
  2304. * Return the entire driver board structure to a user app.
  2305. */
  2306. static int stl_getbrdstruct(struct stlbrd __user *arg)
  2307. {
  2308. struct stlbrd *brdp;
  2309. if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
  2310. return -EFAULT;
  2311. if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
  2312. return -ENODEV;
  2313. brdp = stl_brds[stl_dummybrd.brdnr];
  2314. if (!brdp)
  2315. return(-ENODEV);
  2316. return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
  2317. }
  2318. /*****************************************************************************/
  2319. /*
  2320. * The "staliomem" device is also required to do some special operations
  2321. * on the board and/or ports. In this driver it is mostly used for stats
  2322. * collection.
  2323. */
  2324. static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
  2325. {
  2326. int brdnr, rc;
  2327. void __user *argp = (void __user *)arg;
  2328. pr_debug("stl_memioctl(ip=%p,fp=%p,cmd=%x,arg=%lx)\n", ip, fp, cmd,arg);
  2329. brdnr = iminor(ip);
  2330. if (brdnr >= STL_MAXBRDS)
  2331. return(-ENODEV);
  2332. rc = 0;
  2333. switch (cmd) {
  2334. case COM_GETPORTSTATS:
  2335. rc = stl_getportstats(NULL, argp);
  2336. break;
  2337. case COM_CLRPORTSTATS:
  2338. rc = stl_clrportstats(NULL, argp);
  2339. break;
  2340. case COM_GETBRDSTATS:
  2341. rc = stl_getbrdstats(argp);
  2342. break;
  2343. case COM_READPORT:
  2344. rc = stl_getportstruct(argp);
  2345. break;
  2346. case COM_READBOARD:
  2347. rc = stl_getbrdstruct(argp);
  2348. break;
  2349. default:
  2350. rc = -ENOIOCTLCMD;
  2351. break;
  2352. }
  2353. return(rc);
  2354. }
  2355. static const struct tty_operations stl_ops = {
  2356. .open = stl_open,
  2357. .close = stl_close,
  2358. .write = stl_write,
  2359. .put_char = stl_putchar,
  2360. .flush_chars = stl_flushchars,
  2361. .write_room = stl_writeroom,
  2362. .chars_in_buffer = stl_charsinbuffer,
  2363. .ioctl = stl_ioctl,
  2364. .set_termios = stl_settermios,
  2365. .throttle = stl_throttle,
  2366. .unthrottle = stl_unthrottle,
  2367. .stop = stl_stop,
  2368. .start = stl_start,
  2369. .hangup = stl_hangup,
  2370. .flush_buffer = stl_flushbuffer,
  2371. .break_ctl = stl_breakctl,
  2372. .wait_until_sent = stl_waituntilsent,
  2373. .send_xchar = stl_sendxchar,
  2374. .read_proc = stl_readproc,
  2375. .tiocmget = stl_tiocmget,
  2376. .tiocmset = stl_tiocmset,
  2377. };
  2378. /*****************************************************************************/
  2379. /* CD1400 HARDWARE FUNCTIONS */
  2380. /*****************************************************************************/
  2381. /*
  2382. * These functions get/set/update the registers of the cd1400 UARTs.
  2383. * Access to the cd1400 registers is via an address/data io port pair.
  2384. * (Maybe should make this inline...)
  2385. */
  2386. static int stl_cd1400getreg(struct stlport *portp, int regnr)
  2387. {
  2388. outb((regnr + portp->uartaddr), portp->ioaddr);
  2389. return inb(portp->ioaddr + EREG_DATA);
  2390. }
  2391. static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
  2392. {
  2393. outb((regnr + portp->uartaddr), portp->ioaddr);
  2394. outb(value, portp->ioaddr + EREG_DATA);
  2395. }
  2396. static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
  2397. {
  2398. outb((regnr + portp->uartaddr), portp->ioaddr);
  2399. if (inb(portp->ioaddr + EREG_DATA) != value) {
  2400. outb(value, portp->ioaddr + EREG_DATA);
  2401. return 1;
  2402. }
  2403. return 0;
  2404. }
  2405. /*****************************************************************************/
  2406. /*
  2407. * Inbitialize the UARTs in a panel. We don't care what sort of board
  2408. * these ports are on - since the port io registers are almost
  2409. * identical when dealing with ports.
  2410. */
  2411. static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
  2412. {
  2413. unsigned int gfrcr;
  2414. int chipmask, i, j;
  2415. int nrchips, uartaddr, ioaddr;
  2416. unsigned long flags;
  2417. pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
  2418. spin_lock_irqsave(&brd_lock, flags);
  2419. BRDENABLE(panelp->brdnr, panelp->pagenr);
  2420. /*
  2421. * Check that each chip is present and started up OK.
  2422. */
  2423. chipmask = 0;
  2424. nrchips = panelp->nrports / CD1400_PORTS;
  2425. for (i = 0; (i < nrchips); i++) {
  2426. if (brdp->brdtype == BRD_ECHPCI) {
  2427. outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
  2428. ioaddr = panelp->iobase;
  2429. } else {
  2430. ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
  2431. }
  2432. uartaddr = (i & 0x01) ? 0x080 : 0;
  2433. outb((GFRCR + uartaddr), ioaddr);
  2434. outb(0, (ioaddr + EREG_DATA));
  2435. outb((CCR + uartaddr), ioaddr);
  2436. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  2437. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  2438. outb((GFRCR + uartaddr), ioaddr);
  2439. for (j = 0; (j < CCR_MAXWAIT); j++) {
  2440. if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
  2441. break;
  2442. }
  2443. if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
  2444. printk("STALLION: cd1400 not responding, "
  2445. "brd=%d panel=%d chip=%d\n",
  2446. panelp->brdnr, panelp->panelnr, i);
  2447. continue;
  2448. }
  2449. chipmask |= (0x1 << i);
  2450. outb((PPR + uartaddr), ioaddr);
  2451. outb(PPR_SCALAR, (ioaddr + EREG_DATA));
  2452. }
  2453. BRDDISABLE(panelp->brdnr);
  2454. spin_unlock_irqrestore(&brd_lock, flags);
  2455. return chipmask;
  2456. }
  2457. /*****************************************************************************/
  2458. /*
  2459. * Initialize hardware specific port registers.
  2460. */
  2461. static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
  2462. {
  2463. unsigned long flags;
  2464. pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
  2465. panelp, portp);
  2466. if ((brdp == NULL) || (panelp == NULL) ||
  2467. (portp == NULL))
  2468. return;
  2469. spin_lock_irqsave(&brd_lock, flags);
  2470. portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
  2471. (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
  2472. portp->uartaddr = (portp->portnr & 0x04) << 5;
  2473. portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
  2474. BRDENABLE(portp->brdnr, portp->pagenr);
  2475. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2476. stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
  2477. portp->hwid = stl_cd1400getreg(portp, GFRCR);
  2478. BRDDISABLE(portp->brdnr);
  2479. spin_unlock_irqrestore(&brd_lock, flags);
  2480. }
  2481. /*****************************************************************************/
  2482. /*
  2483. * Wait for the command register to be ready. We will poll this,
  2484. * since it won't usually take too long to be ready.
  2485. */
  2486. static void stl_cd1400ccrwait(struct stlport *portp)
  2487. {
  2488. int i;
  2489. for (i = 0; (i < CCR_MAXWAIT); i++) {
  2490. if (stl_cd1400getreg(portp, CCR) == 0) {
  2491. return;
  2492. }
  2493. }
  2494. printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
  2495. portp->portnr, portp->panelnr, portp->brdnr);
  2496. }
  2497. /*****************************************************************************/
  2498. /*
  2499. * Set up the cd1400 registers for a port based on the termios port
  2500. * settings.
  2501. */
  2502. static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp)
  2503. {
  2504. struct stlbrd *brdp;
  2505. unsigned long flags;
  2506. unsigned int clkdiv, baudrate;
  2507. unsigned char cor1, cor2, cor3;
  2508. unsigned char cor4, cor5, ccr;
  2509. unsigned char srer, sreron, sreroff;
  2510. unsigned char mcor1, mcor2, rtpr;
  2511. unsigned char clk, div;
  2512. cor1 = 0;
  2513. cor2 = 0;
  2514. cor3 = 0;
  2515. cor4 = 0;
  2516. cor5 = 0;
  2517. ccr = 0;
  2518. rtpr = 0;
  2519. clk = 0;
  2520. div = 0;
  2521. mcor1 = 0;
  2522. mcor2 = 0;
  2523. sreron = 0;
  2524. sreroff = 0;
  2525. brdp = stl_brds[portp->brdnr];
  2526. if (brdp == NULL)
  2527. return;
  2528. /*
  2529. * Set up the RX char ignore mask with those RX error types we
  2530. * can ignore. We can get the cd1400 to help us out a little here,
  2531. * it will ignore parity errors and breaks for us.
  2532. */
  2533. portp->rxignoremsk = 0;
  2534. if (tiosp->c_iflag & IGNPAR) {
  2535. portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
  2536. cor1 |= COR1_PARIGNORE;
  2537. }
  2538. if (tiosp->c_iflag & IGNBRK) {
  2539. portp->rxignoremsk |= ST_BREAK;
  2540. cor4 |= COR4_IGNBRK;
  2541. }
  2542. portp->rxmarkmsk = ST_OVERRUN;
  2543. if (tiosp->c_iflag & (INPCK | PARMRK))
  2544. portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
  2545. if (tiosp->c_iflag & BRKINT)
  2546. portp->rxmarkmsk |= ST_BREAK;
  2547. /*
  2548. * Go through the char size, parity and stop bits and set all the
  2549. * option register appropriately.
  2550. */
  2551. switch (tiosp->c_cflag & CSIZE) {
  2552. case CS5:
  2553. cor1 |= COR1_CHL5;
  2554. break;
  2555. case CS6:
  2556. cor1 |= COR1_CHL6;
  2557. break;
  2558. case CS7:
  2559. cor1 |= COR1_CHL7;
  2560. break;
  2561. default:
  2562. cor1 |= COR1_CHL8;
  2563. break;
  2564. }
  2565. if (tiosp->c_cflag & CSTOPB)
  2566. cor1 |= COR1_STOP2;
  2567. else
  2568. cor1 |= COR1_STOP1;
  2569. if (tiosp->c_cflag & PARENB) {
  2570. if (tiosp->c_cflag & PARODD)
  2571. cor1 |= (COR1_PARENB | COR1_PARODD);
  2572. else
  2573. cor1 |= (COR1_PARENB | COR1_PAREVEN);
  2574. } else {
  2575. cor1 |= COR1_PARNONE;
  2576. }
  2577. /*
  2578. * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
  2579. * space for hardware flow control and the like. This should be set to
  2580. * VMIN. Also here we will set the RX data timeout to 10ms - this should
  2581. * really be based on VTIME.
  2582. */
  2583. cor3 |= FIFO_RXTHRESHOLD;
  2584. rtpr = 2;
  2585. /*
  2586. * Calculate the baud rate timers. For now we will just assume that
  2587. * the input and output baud are the same. Could have used a baud
  2588. * table here, but this way we can generate virtually any baud rate
  2589. * we like!
  2590. */
  2591. baudrate = tiosp->c_cflag & CBAUD;
  2592. if (baudrate & CBAUDEX) {
  2593. baudrate &= ~CBAUDEX;
  2594. if ((baudrate < 1) || (baudrate > 4))
  2595. tiosp->c_cflag &= ~CBAUDEX;
  2596. else
  2597. baudrate += 15;
  2598. }
  2599. baudrate = stl_baudrates[baudrate];
  2600. if ((tiosp->c_cflag & CBAUD) == B38400) {
  2601. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  2602. baudrate = 57600;
  2603. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  2604. baudrate = 115200;
  2605. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  2606. baudrate = 230400;
  2607. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  2608. baudrate = 460800;
  2609. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  2610. baudrate = (portp->baud_base / portp->custom_divisor);
  2611. }
  2612. if (baudrate > STL_CD1400MAXBAUD)
  2613. baudrate = STL_CD1400MAXBAUD;
  2614. if (baudrate > 0) {
  2615. for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
  2616. clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
  2617. if (clkdiv < 0x100)
  2618. break;
  2619. }
  2620. div = (unsigned char) clkdiv;
  2621. }
  2622. /*
  2623. * Check what form of modem signaling is required and set it up.
  2624. */
  2625. if ((tiosp->c_cflag & CLOCAL) == 0) {
  2626. mcor1 |= MCOR1_DCD;
  2627. mcor2 |= MCOR2_DCD;
  2628. sreron |= SRER_MODEM;
  2629. portp->flags |= ASYNC_CHECK_CD;
  2630. } else {
  2631. portp->flags &= ~ASYNC_CHECK_CD;
  2632. }
  2633. /*
  2634. * Setup cd1400 enhanced modes if we can. In particular we want to
  2635. * handle as much of the flow control as possible automatically. As
  2636. * well as saving a few CPU cycles it will also greatly improve flow
  2637. * control reliability.
  2638. */
  2639. if (tiosp->c_iflag & IXON) {
  2640. cor2 |= COR2_TXIBE;
  2641. cor3 |= COR3_SCD12;
  2642. if (tiosp->c_iflag & IXANY)
  2643. cor2 |= COR2_IXM;
  2644. }
  2645. if (tiosp->c_cflag & CRTSCTS) {
  2646. cor2 |= COR2_CTSAE;
  2647. mcor1 |= FIFO_RTSTHRESHOLD;
  2648. }
  2649. /*
  2650. * All cd1400 register values calculated so go through and set
  2651. * them all up.
  2652. */
  2653. pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
  2654. portp->portnr, portp->panelnr, portp->brdnr);
  2655. pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
  2656. cor1, cor2, cor3, cor4, cor5);
  2657. pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
  2658. mcor1, mcor2, rtpr, sreron, sreroff);
  2659. pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
  2660. pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
  2661. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  2662. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  2663. spin_lock_irqsave(&brd_lock, flags);
  2664. BRDENABLE(portp->brdnr, portp->pagenr);
  2665. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
  2666. srer = stl_cd1400getreg(portp, SRER);
  2667. stl_cd1400setreg(portp, SRER, 0);
  2668. if (stl_cd1400updatereg(portp, COR1, cor1))
  2669. ccr = 1;
  2670. if (stl_cd1400updatereg(portp, COR2, cor2))
  2671. ccr = 1;
  2672. if (stl_cd1400updatereg(portp, COR3, cor3))
  2673. ccr = 1;
  2674. if (ccr) {
  2675. stl_cd1400ccrwait(portp);
  2676. stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
  2677. }
  2678. stl_cd1400setreg(portp, COR4, cor4);
  2679. stl_cd1400setreg(portp, COR5, cor5);
  2680. stl_cd1400setreg(portp, MCOR1, mcor1);
  2681. stl_cd1400setreg(portp, MCOR2, mcor2);
  2682. if (baudrate > 0) {
  2683. stl_cd1400setreg(portp, TCOR, clk);
  2684. stl_cd1400setreg(portp, TBPR, div);
  2685. stl_cd1400setreg(portp, RCOR, clk);
  2686. stl_cd1400setreg(portp, RBPR, div);
  2687. }
  2688. stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
  2689. stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
  2690. stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
  2691. stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
  2692. stl_cd1400setreg(portp, RTPR, rtpr);
  2693. mcor1 = stl_cd1400getreg(portp, MSVR1);
  2694. if (mcor1 & MSVR1_DCD)
  2695. portp->sigs |= TIOCM_CD;
  2696. else
  2697. portp->sigs &= ~TIOCM_CD;
  2698. stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
  2699. BRDDISABLE(portp->brdnr);
  2700. spin_unlock_irqrestore(&brd_lock, flags);
  2701. }
  2702. /*****************************************************************************/
  2703. /*
  2704. * Set the state of the DTR and RTS signals.
  2705. */
  2706. static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts)
  2707. {
  2708. unsigned char msvr1, msvr2;
  2709. unsigned long flags;
  2710. pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
  2711. portp, dtr, rts);
  2712. msvr1 = 0;
  2713. msvr2 = 0;
  2714. if (dtr > 0)
  2715. msvr1 = MSVR1_DTR;
  2716. if (rts > 0)
  2717. msvr2 = MSVR2_RTS;
  2718. spin_lock_irqsave(&brd_lock, flags);
  2719. BRDENABLE(portp->brdnr, portp->pagenr);
  2720. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2721. if (rts >= 0)
  2722. stl_cd1400setreg(portp, MSVR2, msvr2);
  2723. if (dtr >= 0)
  2724. stl_cd1400setreg(portp, MSVR1, msvr1);
  2725. BRDDISABLE(portp->brdnr);
  2726. spin_unlock_irqrestore(&brd_lock, flags);
  2727. }
  2728. /*****************************************************************************/
  2729. /*
  2730. * Return the state of the signals.
  2731. */
  2732. static int stl_cd1400getsignals(struct stlport *portp)
  2733. {
  2734. unsigned char msvr1, msvr2;
  2735. unsigned long flags;
  2736. int sigs;
  2737. pr_debug("stl_cd1400getsignals(portp=%p)\n", portp);
  2738. spin_lock_irqsave(&brd_lock, flags);
  2739. BRDENABLE(portp->brdnr, portp->pagenr);
  2740. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2741. msvr1 = stl_cd1400getreg(portp, MSVR1);
  2742. msvr2 = stl_cd1400getreg(portp, MSVR2);
  2743. BRDDISABLE(portp->brdnr);
  2744. spin_unlock_irqrestore(&brd_lock, flags);
  2745. sigs = 0;
  2746. sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
  2747. sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
  2748. sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
  2749. sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
  2750. #if 0
  2751. sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
  2752. sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
  2753. #else
  2754. sigs |= TIOCM_DSR;
  2755. #endif
  2756. return sigs;
  2757. }
  2758. /*****************************************************************************/
  2759. /*
  2760. * Enable/Disable the Transmitter and/or Receiver.
  2761. */
  2762. static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx)
  2763. {
  2764. unsigned char ccr;
  2765. unsigned long flags;
  2766. pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
  2767. ccr = 0;
  2768. if (tx == 0)
  2769. ccr |= CCR_TXDISABLE;
  2770. else if (tx > 0)
  2771. ccr |= CCR_TXENABLE;
  2772. if (rx == 0)
  2773. ccr |= CCR_RXDISABLE;
  2774. else if (rx > 0)
  2775. ccr |= CCR_RXENABLE;
  2776. spin_lock_irqsave(&brd_lock, flags);
  2777. BRDENABLE(portp->brdnr, portp->pagenr);
  2778. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2779. stl_cd1400ccrwait(portp);
  2780. stl_cd1400setreg(portp, CCR, ccr);
  2781. stl_cd1400ccrwait(portp);
  2782. BRDDISABLE(portp->brdnr);
  2783. spin_unlock_irqrestore(&brd_lock, flags);
  2784. }
  2785. /*****************************************************************************/
  2786. /*
  2787. * Start/stop the Transmitter and/or Receiver.
  2788. */
  2789. static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx)
  2790. {
  2791. unsigned char sreron, sreroff;
  2792. unsigned long flags;
  2793. pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
  2794. sreron = 0;
  2795. sreroff = 0;
  2796. if (tx == 0)
  2797. sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
  2798. else if (tx == 1)
  2799. sreron |= SRER_TXDATA;
  2800. else if (tx >= 2)
  2801. sreron |= SRER_TXEMPTY;
  2802. if (rx == 0)
  2803. sreroff |= SRER_RXDATA;
  2804. else if (rx > 0)
  2805. sreron |= SRER_RXDATA;
  2806. spin_lock_irqsave(&brd_lock, flags);
  2807. BRDENABLE(portp->brdnr, portp->pagenr);
  2808. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2809. stl_cd1400setreg(portp, SRER,
  2810. ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
  2811. BRDDISABLE(portp->brdnr);
  2812. if (tx > 0)
  2813. set_bit(ASYI_TXBUSY, &portp->istate);
  2814. spin_unlock_irqrestore(&brd_lock, flags);
  2815. }
  2816. /*****************************************************************************/
  2817. /*
  2818. * Disable all interrupts from this port.
  2819. */
  2820. static void stl_cd1400disableintrs(struct stlport *portp)
  2821. {
  2822. unsigned long flags;
  2823. pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp);
  2824. spin_lock_irqsave(&brd_lock, flags);
  2825. BRDENABLE(portp->brdnr, portp->pagenr);
  2826. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2827. stl_cd1400setreg(portp, SRER, 0);
  2828. BRDDISABLE(portp->brdnr);
  2829. spin_unlock_irqrestore(&brd_lock, flags);
  2830. }
  2831. /*****************************************************************************/
  2832. static void stl_cd1400sendbreak(struct stlport *portp, int len)
  2833. {
  2834. unsigned long flags;
  2835. pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len);
  2836. spin_lock_irqsave(&brd_lock, flags);
  2837. BRDENABLE(portp->brdnr, portp->pagenr);
  2838. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2839. stl_cd1400setreg(portp, SRER,
  2840. ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
  2841. SRER_TXEMPTY));
  2842. BRDDISABLE(portp->brdnr);
  2843. portp->brklen = len;
  2844. if (len == 1)
  2845. portp->stats.txbreaks++;
  2846. spin_unlock_irqrestore(&brd_lock, flags);
  2847. }
  2848. /*****************************************************************************/
  2849. /*
  2850. * Take flow control actions...
  2851. */
  2852. static void stl_cd1400flowctrl(struct stlport *portp, int state)
  2853. {
  2854. struct tty_struct *tty;
  2855. unsigned long flags;
  2856. pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state);
  2857. if (portp == NULL)
  2858. return;
  2859. tty = portp->tty;
  2860. if (tty == NULL)
  2861. return;
  2862. spin_lock_irqsave(&brd_lock, flags);
  2863. BRDENABLE(portp->brdnr, portp->pagenr);
  2864. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2865. if (state) {
  2866. if (tty->termios->c_iflag & IXOFF) {
  2867. stl_cd1400ccrwait(portp);
  2868. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  2869. portp->stats.rxxon++;
  2870. stl_cd1400ccrwait(portp);
  2871. }
  2872. /*
  2873. * Question: should we return RTS to what it was before? It may
  2874. * have been set by an ioctl... Suppose not, since if you have
  2875. * hardware flow control set then it is pretty silly to go and
  2876. * set the RTS line by hand.
  2877. */
  2878. if (tty->termios->c_cflag & CRTSCTS) {
  2879. stl_cd1400setreg(portp, MCOR1,
  2880. (stl_cd1400getreg(portp, MCOR1) |
  2881. FIFO_RTSTHRESHOLD));
  2882. stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
  2883. portp->stats.rxrtson++;
  2884. }
  2885. } else {
  2886. if (tty->termios->c_iflag & IXOFF) {
  2887. stl_cd1400ccrwait(portp);
  2888. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  2889. portp->stats.rxxoff++;
  2890. stl_cd1400ccrwait(portp);
  2891. }
  2892. if (tty->termios->c_cflag & CRTSCTS) {
  2893. stl_cd1400setreg(portp, MCOR1,
  2894. (stl_cd1400getreg(portp, MCOR1) & 0xf0));
  2895. stl_cd1400setreg(portp, MSVR2, 0);
  2896. portp->stats.rxrtsoff++;
  2897. }
  2898. }
  2899. BRDDISABLE(portp->brdnr);
  2900. spin_unlock_irqrestore(&brd_lock, flags);
  2901. }
  2902. /*****************************************************************************/
  2903. /*
  2904. * Send a flow control character...
  2905. */
  2906. static void stl_cd1400sendflow(struct stlport *portp, int state)
  2907. {
  2908. struct tty_struct *tty;
  2909. unsigned long flags;
  2910. pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state);
  2911. if (portp == NULL)
  2912. return;
  2913. tty = portp->tty;
  2914. if (tty == NULL)
  2915. return;
  2916. spin_lock_irqsave(&brd_lock, flags);
  2917. BRDENABLE(portp->brdnr, portp->pagenr);
  2918. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2919. if (state) {
  2920. stl_cd1400ccrwait(portp);
  2921. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  2922. portp->stats.rxxon++;
  2923. stl_cd1400ccrwait(portp);
  2924. } else {
  2925. stl_cd1400ccrwait(portp);
  2926. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  2927. portp->stats.rxxoff++;
  2928. stl_cd1400ccrwait(portp);
  2929. }
  2930. BRDDISABLE(portp->brdnr);
  2931. spin_unlock_irqrestore(&brd_lock, flags);
  2932. }
  2933. /*****************************************************************************/
  2934. static void stl_cd1400flush(struct stlport *portp)
  2935. {
  2936. unsigned long flags;
  2937. pr_debug("stl_cd1400flush(portp=%p)\n", portp);
  2938. if (portp == NULL)
  2939. return;
  2940. spin_lock_irqsave(&brd_lock, flags);
  2941. BRDENABLE(portp->brdnr, portp->pagenr);
  2942. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2943. stl_cd1400ccrwait(portp);
  2944. stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
  2945. stl_cd1400ccrwait(portp);
  2946. portp->tx.tail = portp->tx.head;
  2947. BRDDISABLE(portp->brdnr);
  2948. spin_unlock_irqrestore(&brd_lock, flags);
  2949. }
  2950. /*****************************************************************************/
  2951. /*
  2952. * Return the current state of data flow on this port. This is only
  2953. * really interresting when determining if data has fully completed
  2954. * transmission or not... This is easy for the cd1400, it accurately
  2955. * maintains the busy port flag.
  2956. */
  2957. static int stl_cd1400datastate(struct stlport *portp)
  2958. {
  2959. pr_debug("stl_cd1400datastate(portp=%p)\n", portp);
  2960. if (portp == NULL)
  2961. return 0;
  2962. return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
  2963. }
  2964. /*****************************************************************************/
  2965. /*
  2966. * Interrupt service routine for cd1400 EasyIO boards.
  2967. */
  2968. static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase)
  2969. {
  2970. unsigned char svrtype;
  2971. pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase);
  2972. spin_lock(&brd_lock);
  2973. outb(SVRR, iobase);
  2974. svrtype = inb(iobase + EREG_DATA);
  2975. if (panelp->nrports > 4) {
  2976. outb((SVRR + 0x80), iobase);
  2977. svrtype |= inb(iobase + EREG_DATA);
  2978. }
  2979. if (svrtype & SVRR_RX)
  2980. stl_cd1400rxisr(panelp, iobase);
  2981. else if (svrtype & SVRR_TX)
  2982. stl_cd1400txisr(panelp, iobase);
  2983. else if (svrtype & SVRR_MDM)
  2984. stl_cd1400mdmisr(panelp, iobase);
  2985. spin_unlock(&brd_lock);
  2986. }
  2987. /*****************************************************************************/
  2988. /*
  2989. * Interrupt service routine for cd1400 panels.
  2990. */
  2991. static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase)
  2992. {
  2993. unsigned char svrtype;
  2994. pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase);
  2995. outb(SVRR, iobase);
  2996. svrtype = inb(iobase + EREG_DATA);
  2997. outb((SVRR + 0x80), iobase);
  2998. svrtype |= inb(iobase + EREG_DATA);
  2999. if (svrtype & SVRR_RX)
  3000. stl_cd1400rxisr(panelp, iobase);
  3001. else if (svrtype & SVRR_TX)
  3002. stl_cd1400txisr(panelp, iobase);
  3003. else if (svrtype & SVRR_MDM)
  3004. stl_cd1400mdmisr(panelp, iobase);
  3005. }
  3006. /*****************************************************************************/
  3007. /*
  3008. * Unfortunately we need to handle breaks in the TX data stream, since
  3009. * this is the only way to generate them on the cd1400.
  3010. */
  3011. static int stl_cd1400breakisr(struct stlport *portp, int ioaddr)
  3012. {
  3013. if (portp->brklen == 1) {
  3014. outb((COR2 + portp->uartaddr), ioaddr);
  3015. outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
  3016. (ioaddr + EREG_DATA));
  3017. outb((TDR + portp->uartaddr), ioaddr);
  3018. outb(ETC_CMD, (ioaddr + EREG_DATA));
  3019. outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
  3020. outb((SRER + portp->uartaddr), ioaddr);
  3021. outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
  3022. (ioaddr + EREG_DATA));
  3023. return 1;
  3024. } else if (portp->brklen > 1) {
  3025. outb((TDR + portp->uartaddr), ioaddr);
  3026. outb(ETC_CMD, (ioaddr + EREG_DATA));
  3027. outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
  3028. portp->brklen = -1;
  3029. return 1;
  3030. } else {
  3031. outb((COR2 + portp->uartaddr), ioaddr);
  3032. outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
  3033. (ioaddr + EREG_DATA));
  3034. portp->brklen = 0;
  3035. }
  3036. return 0;
  3037. }
  3038. /*****************************************************************************/
  3039. /*
  3040. * Transmit interrupt handler. This has gotta be fast! Handling TX
  3041. * chars is pretty simple, stuff as many as possible from the TX buffer
  3042. * into the cd1400 FIFO. Must also handle TX breaks here, since they
  3043. * are embedded as commands in the data stream. Oh no, had to use a goto!
  3044. * This could be optimized more, will do when I get time...
  3045. * In practice it is possible that interrupts are enabled but that the
  3046. * port has been hung up. Need to handle not having any TX buffer here,
  3047. * this is done by using the side effect that head and tail will also
  3048. * be NULL if the buffer has been freed.
  3049. */
  3050. static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
  3051. {
  3052. struct stlport *portp;
  3053. int len, stlen;
  3054. char *head, *tail;
  3055. unsigned char ioack, srer;
  3056. pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
  3057. ioack = inb(ioaddr + EREG_TXACK);
  3058. if (((ioack & panelp->ackmask) != 0) ||
  3059. ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
  3060. printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
  3061. return;
  3062. }
  3063. portp = panelp->ports[(ioack >> 3)];
  3064. /*
  3065. * Unfortunately we need to handle breaks in the data stream, since
  3066. * this is the only way to generate them on the cd1400. Do it now if
  3067. * a break is to be sent.
  3068. */
  3069. if (portp->brklen != 0)
  3070. if (stl_cd1400breakisr(portp, ioaddr))
  3071. goto stl_txalldone;
  3072. head = portp->tx.head;
  3073. tail = portp->tx.tail;
  3074. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  3075. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  3076. (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  3077. set_bit(ASYI_TXLOW, &portp->istate);
  3078. schedule_work(&portp->tqueue);
  3079. }
  3080. if (len == 0) {
  3081. outb((SRER + portp->uartaddr), ioaddr);
  3082. srer = inb(ioaddr + EREG_DATA);
  3083. if (srer & SRER_TXDATA) {
  3084. srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
  3085. } else {
  3086. srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
  3087. clear_bit(ASYI_TXBUSY, &portp->istate);
  3088. }
  3089. outb(srer, (ioaddr + EREG_DATA));
  3090. } else {
  3091. len = MIN(len, CD1400_TXFIFOSIZE);
  3092. portp->stats.txtotal += len;
  3093. stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
  3094. outb((TDR + portp->uartaddr), ioaddr);
  3095. outsb((ioaddr + EREG_DATA), tail, stlen);
  3096. len -= stlen;
  3097. tail += stlen;
  3098. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  3099. tail = portp->tx.buf;
  3100. if (len > 0) {
  3101. outsb((ioaddr + EREG_DATA), tail, len);
  3102. tail += len;
  3103. }
  3104. portp->tx.tail = tail;
  3105. }
  3106. stl_txalldone:
  3107. outb((EOSRR + portp->uartaddr), ioaddr);
  3108. outb(0, (ioaddr + EREG_DATA));
  3109. }
  3110. /*****************************************************************************/
  3111. /*
  3112. * Receive character interrupt handler. Determine if we have good chars
  3113. * or bad chars and then process appropriately. Good chars are easy
  3114. * just shove the lot into the RX buffer and set all status byte to 0.
  3115. * If a bad RX char then process as required. This routine needs to be
  3116. * fast! In practice it is possible that we get an interrupt on a port
  3117. * that is closed. This can happen on hangups - since they completely
  3118. * shutdown a port not in user context. Need to handle this case.
  3119. */
  3120. static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
  3121. {
  3122. struct stlport *portp;
  3123. struct tty_struct *tty;
  3124. unsigned int ioack, len, buflen;
  3125. unsigned char status;
  3126. char ch;
  3127. pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
  3128. ioack = inb(ioaddr + EREG_RXACK);
  3129. if ((ioack & panelp->ackmask) != 0) {
  3130. printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
  3131. return;
  3132. }
  3133. portp = panelp->ports[(ioack >> 3)];
  3134. tty = portp->tty;
  3135. if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
  3136. outb((RDCR + portp->uartaddr), ioaddr);
  3137. len = inb(ioaddr + EREG_DATA);
  3138. if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
  3139. len = MIN(len, sizeof(stl_unwanted));
  3140. outb((RDSR + portp->uartaddr), ioaddr);
  3141. insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
  3142. portp->stats.rxlost += len;
  3143. portp->stats.rxtotal += len;
  3144. } else {
  3145. len = MIN(len, buflen);
  3146. if (len > 0) {
  3147. unsigned char *ptr;
  3148. outb((RDSR + portp->uartaddr), ioaddr);
  3149. tty_prepare_flip_string(tty, &ptr, len);
  3150. insb((ioaddr + EREG_DATA), ptr, len);
  3151. tty_schedule_flip(tty);
  3152. portp->stats.rxtotal += len;
  3153. }
  3154. }
  3155. } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
  3156. outb((RDSR + portp->uartaddr), ioaddr);
  3157. status = inb(ioaddr + EREG_DATA);
  3158. ch = inb(ioaddr + EREG_DATA);
  3159. if (status & ST_PARITY)
  3160. portp->stats.rxparity++;
  3161. if (status & ST_FRAMING)
  3162. portp->stats.rxframing++;
  3163. if (status & ST_OVERRUN)
  3164. portp->stats.rxoverrun++;
  3165. if (status & ST_BREAK)
  3166. portp->stats.rxbreaks++;
  3167. if (status & ST_SCHARMASK) {
  3168. if ((status & ST_SCHARMASK) == ST_SCHAR1)
  3169. portp->stats.txxon++;
  3170. if ((status & ST_SCHARMASK) == ST_SCHAR2)
  3171. portp->stats.txxoff++;
  3172. goto stl_rxalldone;
  3173. }
  3174. if (tty != NULL && (portp->rxignoremsk & status) == 0) {
  3175. if (portp->rxmarkmsk & status) {
  3176. if (status & ST_BREAK) {
  3177. status = TTY_BREAK;
  3178. if (portp->flags & ASYNC_SAK) {
  3179. do_SAK(tty);
  3180. BRDENABLE(portp->brdnr, portp->pagenr);
  3181. }
  3182. } else if (status & ST_PARITY) {
  3183. status = TTY_PARITY;
  3184. } else if (status & ST_FRAMING) {
  3185. status = TTY_FRAME;
  3186. } else if(status & ST_OVERRUN) {
  3187. status = TTY_OVERRUN;
  3188. } else {
  3189. status = 0;
  3190. }
  3191. } else {
  3192. status = 0;
  3193. }
  3194. tty_insert_flip_char(tty, ch, status);
  3195. tty_schedule_flip(tty);
  3196. }
  3197. } else {
  3198. printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
  3199. return;
  3200. }
  3201. stl_rxalldone:
  3202. outb((EOSRR + portp->uartaddr), ioaddr);
  3203. outb(0, (ioaddr + EREG_DATA));
  3204. }
  3205. /*****************************************************************************/
  3206. /*
  3207. * Modem interrupt handler. The is called when the modem signal line
  3208. * (DCD) has changed state. Leave most of the work to the off-level
  3209. * processing routine.
  3210. */
  3211. static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr)
  3212. {
  3213. struct stlport *portp;
  3214. unsigned int ioack;
  3215. unsigned char misr;
  3216. pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp);
  3217. ioack = inb(ioaddr + EREG_MDACK);
  3218. if (((ioack & panelp->ackmask) != 0) ||
  3219. ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
  3220. printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
  3221. return;
  3222. }
  3223. portp = panelp->ports[(ioack >> 3)];
  3224. outb((MISR + portp->uartaddr), ioaddr);
  3225. misr = inb(ioaddr + EREG_DATA);
  3226. if (misr & MISR_DCD) {
  3227. set_bit(ASYI_DCDCHANGE, &portp->istate);
  3228. schedule_work(&portp->tqueue);
  3229. portp->stats.modem++;
  3230. }
  3231. outb((EOSRR + portp->uartaddr), ioaddr);
  3232. outb(0, (ioaddr + EREG_DATA));
  3233. }
  3234. /*****************************************************************************/
  3235. /* SC26198 HARDWARE FUNCTIONS */
  3236. /*****************************************************************************/
  3237. /*
  3238. * These functions get/set/update the registers of the sc26198 UARTs.
  3239. * Access to the sc26198 registers is via an address/data io port pair.
  3240. * (Maybe should make this inline...)
  3241. */
  3242. static int stl_sc26198getreg(struct stlport *portp, int regnr)
  3243. {
  3244. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3245. return inb(portp->ioaddr + XP_DATA);
  3246. }
  3247. static void stl_sc26198setreg(struct stlport *portp, int regnr, int value)
  3248. {
  3249. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3250. outb(value, (portp->ioaddr + XP_DATA));
  3251. }
  3252. static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value)
  3253. {
  3254. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3255. if (inb(portp->ioaddr + XP_DATA) != value) {
  3256. outb(value, (portp->ioaddr + XP_DATA));
  3257. return 1;
  3258. }
  3259. return 0;
  3260. }
  3261. /*****************************************************************************/
  3262. /*
  3263. * Functions to get and set the sc26198 global registers.
  3264. */
  3265. static int stl_sc26198getglobreg(struct stlport *portp, int regnr)
  3266. {
  3267. outb(regnr, (portp->ioaddr + XP_ADDR));
  3268. return inb(portp->ioaddr + XP_DATA);
  3269. }
  3270. #if 0
  3271. static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value)
  3272. {
  3273. outb(regnr, (portp->ioaddr + XP_ADDR));
  3274. outb(value, (portp->ioaddr + XP_DATA));
  3275. }
  3276. #endif
  3277. /*****************************************************************************/
  3278. /*
  3279. * Inbitialize the UARTs in a panel. We don't care what sort of board
  3280. * these ports are on - since the port io registers are almost
  3281. * identical when dealing with ports.
  3282. */
  3283. static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
  3284. {
  3285. int chipmask, i;
  3286. int nrchips, ioaddr;
  3287. pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
  3288. BRDENABLE(panelp->brdnr, panelp->pagenr);
  3289. /*
  3290. * Check that each chip is present and started up OK.
  3291. */
  3292. chipmask = 0;
  3293. nrchips = (panelp->nrports + 4) / SC26198_PORTS;
  3294. if (brdp->brdtype == BRD_ECHPCI)
  3295. outb(panelp->pagenr, brdp->ioctrl);
  3296. for (i = 0; (i < nrchips); i++) {
  3297. ioaddr = panelp->iobase + (i * 4);
  3298. outb(SCCR, (ioaddr + XP_ADDR));
  3299. outb(CR_RESETALL, (ioaddr + XP_DATA));
  3300. outb(TSTR, (ioaddr + XP_ADDR));
  3301. if (inb(ioaddr + XP_DATA) != 0) {
  3302. printk("STALLION: sc26198 not responding, "
  3303. "brd=%d panel=%d chip=%d\n",
  3304. panelp->brdnr, panelp->panelnr, i);
  3305. continue;
  3306. }
  3307. chipmask |= (0x1 << i);
  3308. outb(GCCR, (ioaddr + XP_ADDR));
  3309. outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
  3310. outb(WDTRCR, (ioaddr + XP_ADDR));
  3311. outb(0xff, (ioaddr + XP_DATA));
  3312. }
  3313. BRDDISABLE(panelp->brdnr);
  3314. return chipmask;
  3315. }
  3316. /*****************************************************************************/
  3317. /*
  3318. * Initialize hardware specific port registers.
  3319. */
  3320. static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
  3321. {
  3322. pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
  3323. panelp, portp);
  3324. if ((brdp == NULL) || (panelp == NULL) ||
  3325. (portp == NULL))
  3326. return;
  3327. portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
  3328. portp->uartaddr = (portp->portnr & 0x07) << 4;
  3329. portp->pagenr = panelp->pagenr;
  3330. portp->hwid = 0x1;
  3331. BRDENABLE(portp->brdnr, portp->pagenr);
  3332. stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
  3333. BRDDISABLE(portp->brdnr);
  3334. }
  3335. /*****************************************************************************/
  3336. /*
  3337. * Set up the sc26198 registers for a port based on the termios port
  3338. * settings.
  3339. */
  3340. static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp)
  3341. {
  3342. struct stlbrd *brdp;
  3343. unsigned long flags;
  3344. unsigned int baudrate;
  3345. unsigned char mr0, mr1, mr2, clk;
  3346. unsigned char imron, imroff, iopr, ipr;
  3347. mr0 = 0;
  3348. mr1 = 0;
  3349. mr2 = 0;
  3350. clk = 0;
  3351. iopr = 0;
  3352. imron = 0;
  3353. imroff = 0;
  3354. brdp = stl_brds[portp->brdnr];
  3355. if (brdp == NULL)
  3356. return;
  3357. /*
  3358. * Set up the RX char ignore mask with those RX error types we
  3359. * can ignore.
  3360. */
  3361. portp->rxignoremsk = 0;
  3362. if (tiosp->c_iflag & IGNPAR)
  3363. portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
  3364. SR_RXOVERRUN);
  3365. if (tiosp->c_iflag & IGNBRK)
  3366. portp->rxignoremsk |= SR_RXBREAK;
  3367. portp->rxmarkmsk = SR_RXOVERRUN;
  3368. if (tiosp->c_iflag & (INPCK | PARMRK))
  3369. portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
  3370. if (tiosp->c_iflag & BRKINT)
  3371. portp->rxmarkmsk |= SR_RXBREAK;
  3372. /*
  3373. * Go through the char size, parity and stop bits and set all the
  3374. * option register appropriately.
  3375. */
  3376. switch (tiosp->c_cflag & CSIZE) {
  3377. case CS5:
  3378. mr1 |= MR1_CS5;
  3379. break;
  3380. case CS6:
  3381. mr1 |= MR1_CS6;
  3382. break;
  3383. case CS7:
  3384. mr1 |= MR1_CS7;
  3385. break;
  3386. default:
  3387. mr1 |= MR1_CS8;
  3388. break;
  3389. }
  3390. if (tiosp->c_cflag & CSTOPB)
  3391. mr2 |= MR2_STOP2;
  3392. else
  3393. mr2 |= MR2_STOP1;
  3394. if (tiosp->c_cflag & PARENB) {
  3395. if (tiosp->c_cflag & PARODD)
  3396. mr1 |= (MR1_PARENB | MR1_PARODD);
  3397. else
  3398. mr1 |= (MR1_PARENB | MR1_PAREVEN);
  3399. } else {
  3400. mr1 |= MR1_PARNONE;
  3401. }
  3402. mr1 |= MR1_ERRBLOCK;
  3403. /*
  3404. * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
  3405. * space for hardware flow control and the like. This should be set to
  3406. * VMIN.
  3407. */
  3408. mr2 |= MR2_RXFIFOHALF;
  3409. /*
  3410. * Calculate the baud rate timers. For now we will just assume that
  3411. * the input and output baud are the same. The sc26198 has a fixed
  3412. * baud rate table, so only discrete baud rates possible.
  3413. */
  3414. baudrate = tiosp->c_cflag & CBAUD;
  3415. if (baudrate & CBAUDEX) {
  3416. baudrate &= ~CBAUDEX;
  3417. if ((baudrate < 1) || (baudrate > 4))
  3418. tiosp->c_cflag &= ~CBAUDEX;
  3419. else
  3420. baudrate += 15;
  3421. }
  3422. baudrate = stl_baudrates[baudrate];
  3423. if ((tiosp->c_cflag & CBAUD) == B38400) {
  3424. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  3425. baudrate = 57600;
  3426. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  3427. baudrate = 115200;
  3428. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  3429. baudrate = 230400;
  3430. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  3431. baudrate = 460800;
  3432. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  3433. baudrate = (portp->baud_base / portp->custom_divisor);
  3434. }
  3435. if (baudrate > STL_SC26198MAXBAUD)
  3436. baudrate = STL_SC26198MAXBAUD;
  3437. if (baudrate > 0) {
  3438. for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
  3439. if (baudrate <= sc26198_baudtable[clk])
  3440. break;
  3441. }
  3442. }
  3443. /*
  3444. * Check what form of modem signaling is required and set it up.
  3445. */
  3446. if (tiosp->c_cflag & CLOCAL) {
  3447. portp->flags &= ~ASYNC_CHECK_CD;
  3448. } else {
  3449. iopr |= IOPR_DCDCOS;
  3450. imron |= IR_IOPORT;
  3451. portp->flags |= ASYNC_CHECK_CD;
  3452. }
  3453. /*
  3454. * Setup sc26198 enhanced modes if we can. In particular we want to
  3455. * handle as much of the flow control as possible automatically. As
  3456. * well as saving a few CPU cycles it will also greatly improve flow
  3457. * control reliability.
  3458. */
  3459. if (tiosp->c_iflag & IXON) {
  3460. mr0 |= MR0_SWFTX | MR0_SWFT;
  3461. imron |= IR_XONXOFF;
  3462. } else {
  3463. imroff |= IR_XONXOFF;
  3464. }
  3465. if (tiosp->c_iflag & IXOFF)
  3466. mr0 |= MR0_SWFRX;
  3467. if (tiosp->c_cflag & CRTSCTS) {
  3468. mr2 |= MR2_AUTOCTS;
  3469. mr1 |= MR1_AUTORTS;
  3470. }
  3471. /*
  3472. * All sc26198 register values calculated so go through and set
  3473. * them all up.
  3474. */
  3475. pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
  3476. portp->portnr, portp->panelnr, portp->brdnr);
  3477. pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
  3478. pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
  3479. pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
  3480. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  3481. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  3482. spin_lock_irqsave(&brd_lock, flags);
  3483. BRDENABLE(portp->brdnr, portp->pagenr);
  3484. stl_sc26198setreg(portp, IMR, 0);
  3485. stl_sc26198updatereg(portp, MR0, mr0);
  3486. stl_sc26198updatereg(portp, MR1, mr1);
  3487. stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
  3488. stl_sc26198updatereg(portp, MR2, mr2);
  3489. stl_sc26198updatereg(portp, IOPIOR,
  3490. ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
  3491. if (baudrate > 0) {
  3492. stl_sc26198setreg(portp, TXCSR, clk);
  3493. stl_sc26198setreg(portp, RXCSR, clk);
  3494. }
  3495. stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
  3496. stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
  3497. ipr = stl_sc26198getreg(portp, IPR);
  3498. if (ipr & IPR_DCD)
  3499. portp->sigs &= ~TIOCM_CD;
  3500. else
  3501. portp->sigs |= TIOCM_CD;
  3502. portp->imr = (portp->imr & ~imroff) | imron;
  3503. stl_sc26198setreg(portp, IMR, portp->imr);
  3504. BRDDISABLE(portp->brdnr);
  3505. spin_unlock_irqrestore(&brd_lock, flags);
  3506. }
  3507. /*****************************************************************************/
  3508. /*
  3509. * Set the state of the DTR and RTS signals.
  3510. */
  3511. static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts)
  3512. {
  3513. unsigned char iopioron, iopioroff;
  3514. unsigned long flags;
  3515. pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp,
  3516. dtr, rts);
  3517. iopioron = 0;
  3518. iopioroff = 0;
  3519. if (dtr == 0)
  3520. iopioroff |= IPR_DTR;
  3521. else if (dtr > 0)
  3522. iopioron |= IPR_DTR;
  3523. if (rts == 0)
  3524. iopioroff |= IPR_RTS;
  3525. else if (rts > 0)
  3526. iopioron |= IPR_RTS;
  3527. spin_lock_irqsave(&brd_lock, flags);
  3528. BRDENABLE(portp->brdnr, portp->pagenr);
  3529. stl_sc26198setreg(portp, IOPIOR,
  3530. ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
  3531. BRDDISABLE(portp->brdnr);
  3532. spin_unlock_irqrestore(&brd_lock, flags);
  3533. }
  3534. /*****************************************************************************/
  3535. /*
  3536. * Return the state of the signals.
  3537. */
  3538. static int stl_sc26198getsignals(struct stlport *portp)
  3539. {
  3540. unsigned char ipr;
  3541. unsigned long flags;
  3542. int sigs;
  3543. pr_debug("stl_sc26198getsignals(portp=%p)\n", portp);
  3544. spin_lock_irqsave(&brd_lock, flags);
  3545. BRDENABLE(portp->brdnr, portp->pagenr);
  3546. ipr = stl_sc26198getreg(portp, IPR);
  3547. BRDDISABLE(portp->brdnr);
  3548. spin_unlock_irqrestore(&brd_lock, flags);
  3549. sigs = 0;
  3550. sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
  3551. sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
  3552. sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
  3553. sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
  3554. sigs |= TIOCM_DSR;
  3555. return sigs;
  3556. }
  3557. /*****************************************************************************/
  3558. /*
  3559. * Enable/Disable the Transmitter and/or Receiver.
  3560. */
  3561. static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx)
  3562. {
  3563. unsigned char ccr;
  3564. unsigned long flags;
  3565. pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx);
  3566. ccr = portp->crenable;
  3567. if (tx == 0)
  3568. ccr &= ~CR_TXENABLE;
  3569. else if (tx > 0)
  3570. ccr |= CR_TXENABLE;
  3571. if (rx == 0)
  3572. ccr &= ~CR_RXENABLE;
  3573. else if (rx > 0)
  3574. ccr |= CR_RXENABLE;
  3575. spin_lock_irqsave(&brd_lock, flags);
  3576. BRDENABLE(portp->brdnr, portp->pagenr);
  3577. stl_sc26198setreg(portp, SCCR, ccr);
  3578. BRDDISABLE(portp->brdnr);
  3579. portp->crenable = ccr;
  3580. spin_unlock_irqrestore(&brd_lock, flags);
  3581. }
  3582. /*****************************************************************************/
  3583. /*
  3584. * Start/stop the Transmitter and/or Receiver.
  3585. */
  3586. static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx)
  3587. {
  3588. unsigned char imr;
  3589. unsigned long flags;
  3590. pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
  3591. imr = portp->imr;
  3592. if (tx == 0)
  3593. imr &= ~IR_TXRDY;
  3594. else if (tx == 1)
  3595. imr |= IR_TXRDY;
  3596. if (rx == 0)
  3597. imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
  3598. else if (rx > 0)
  3599. imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
  3600. spin_lock_irqsave(&brd_lock, flags);
  3601. BRDENABLE(portp->brdnr, portp->pagenr);
  3602. stl_sc26198setreg(portp, IMR, imr);
  3603. BRDDISABLE(portp->brdnr);
  3604. portp->imr = imr;
  3605. if (tx > 0)
  3606. set_bit(ASYI_TXBUSY, &portp->istate);
  3607. spin_unlock_irqrestore(&brd_lock, flags);
  3608. }
  3609. /*****************************************************************************/
  3610. /*
  3611. * Disable all interrupts from this port.
  3612. */
  3613. static void stl_sc26198disableintrs(struct stlport *portp)
  3614. {
  3615. unsigned long flags;
  3616. pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp);
  3617. spin_lock_irqsave(&brd_lock, flags);
  3618. BRDENABLE(portp->brdnr, portp->pagenr);
  3619. portp->imr = 0;
  3620. stl_sc26198setreg(portp, IMR, 0);
  3621. BRDDISABLE(portp->brdnr);
  3622. spin_unlock_irqrestore(&brd_lock, flags);
  3623. }
  3624. /*****************************************************************************/
  3625. static void stl_sc26198sendbreak(struct stlport *portp, int len)
  3626. {
  3627. unsigned long flags;
  3628. pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len);
  3629. spin_lock_irqsave(&brd_lock, flags);
  3630. BRDENABLE(portp->brdnr, portp->pagenr);
  3631. if (len == 1) {
  3632. stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
  3633. portp->stats.txbreaks++;
  3634. } else {
  3635. stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
  3636. }
  3637. BRDDISABLE(portp->brdnr);
  3638. spin_unlock_irqrestore(&brd_lock, flags);
  3639. }
  3640. /*****************************************************************************/
  3641. /*
  3642. * Take flow control actions...
  3643. */
  3644. static void stl_sc26198flowctrl(struct stlport *portp, int state)
  3645. {
  3646. struct tty_struct *tty;
  3647. unsigned long flags;
  3648. unsigned char mr0;
  3649. pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state);
  3650. if (portp == NULL)
  3651. return;
  3652. tty = portp->tty;
  3653. if (tty == NULL)
  3654. return;
  3655. spin_lock_irqsave(&brd_lock, flags);
  3656. BRDENABLE(portp->brdnr, portp->pagenr);
  3657. if (state) {
  3658. if (tty->termios->c_iflag & IXOFF) {
  3659. mr0 = stl_sc26198getreg(portp, MR0);
  3660. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3661. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  3662. mr0 |= MR0_SWFRX;
  3663. portp->stats.rxxon++;
  3664. stl_sc26198wait(portp);
  3665. stl_sc26198setreg(portp, MR0, mr0);
  3666. }
  3667. /*
  3668. * Question: should we return RTS to what it was before? It may
  3669. * have been set by an ioctl... Suppose not, since if you have
  3670. * hardware flow control set then it is pretty silly to go and
  3671. * set the RTS line by hand.
  3672. */
  3673. if (tty->termios->c_cflag & CRTSCTS) {
  3674. stl_sc26198setreg(portp, MR1,
  3675. (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
  3676. stl_sc26198setreg(portp, IOPIOR,
  3677. (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
  3678. portp->stats.rxrtson++;
  3679. }
  3680. } else {
  3681. if (tty->termios->c_iflag & IXOFF) {
  3682. mr0 = stl_sc26198getreg(portp, MR0);
  3683. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3684. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  3685. mr0 &= ~MR0_SWFRX;
  3686. portp->stats.rxxoff++;
  3687. stl_sc26198wait(portp);
  3688. stl_sc26198setreg(portp, MR0, mr0);
  3689. }
  3690. if (tty->termios->c_cflag & CRTSCTS) {
  3691. stl_sc26198setreg(portp, MR1,
  3692. (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
  3693. stl_sc26198setreg(portp, IOPIOR,
  3694. (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
  3695. portp->stats.rxrtsoff++;
  3696. }
  3697. }
  3698. BRDDISABLE(portp->brdnr);
  3699. spin_unlock_irqrestore(&brd_lock, flags);
  3700. }
  3701. /*****************************************************************************/
  3702. /*
  3703. * Send a flow control character.
  3704. */
  3705. static void stl_sc26198sendflow(struct stlport *portp, int state)
  3706. {
  3707. struct tty_struct *tty;
  3708. unsigned long flags;
  3709. unsigned char mr0;
  3710. pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state);
  3711. if (portp == NULL)
  3712. return;
  3713. tty = portp->tty;
  3714. if (tty == NULL)
  3715. return;
  3716. spin_lock_irqsave(&brd_lock, flags);
  3717. BRDENABLE(portp->brdnr, portp->pagenr);
  3718. if (state) {
  3719. mr0 = stl_sc26198getreg(portp, MR0);
  3720. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3721. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  3722. mr0 |= MR0_SWFRX;
  3723. portp->stats.rxxon++;
  3724. stl_sc26198wait(portp);
  3725. stl_sc26198setreg(portp, MR0, mr0);
  3726. } else {
  3727. mr0 = stl_sc26198getreg(portp, MR0);
  3728. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3729. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  3730. mr0 &= ~MR0_SWFRX;
  3731. portp->stats.rxxoff++;
  3732. stl_sc26198wait(portp);
  3733. stl_sc26198setreg(portp, MR0, mr0);
  3734. }
  3735. BRDDISABLE(portp->brdnr);
  3736. spin_unlock_irqrestore(&brd_lock, flags);
  3737. }
  3738. /*****************************************************************************/
  3739. static void stl_sc26198flush(struct stlport *portp)
  3740. {
  3741. unsigned long flags;
  3742. pr_debug("stl_sc26198flush(portp=%p)\n", portp);
  3743. if (portp == NULL)
  3744. return;
  3745. spin_lock_irqsave(&brd_lock, flags);
  3746. BRDENABLE(portp->brdnr, portp->pagenr);
  3747. stl_sc26198setreg(portp, SCCR, CR_TXRESET);
  3748. stl_sc26198setreg(portp, SCCR, portp->crenable);
  3749. BRDDISABLE(portp->brdnr);
  3750. portp->tx.tail = portp->tx.head;
  3751. spin_unlock_irqrestore(&brd_lock, flags);
  3752. }
  3753. /*****************************************************************************/
  3754. /*
  3755. * Return the current state of data flow on this port. This is only
  3756. * really interresting when determining if data has fully completed
  3757. * transmission or not... The sc26198 interrupt scheme cannot
  3758. * determine when all data has actually drained, so we need to
  3759. * check the port statusy register to be sure.
  3760. */
  3761. static int stl_sc26198datastate(struct stlport *portp)
  3762. {
  3763. unsigned long flags;
  3764. unsigned char sr;
  3765. pr_debug("stl_sc26198datastate(portp=%p)\n", portp);
  3766. if (portp == NULL)
  3767. return 0;
  3768. if (test_bit(ASYI_TXBUSY, &portp->istate))
  3769. return 1;
  3770. spin_lock_irqsave(&brd_lock, flags);
  3771. BRDENABLE(portp->brdnr, portp->pagenr);
  3772. sr = stl_sc26198getreg(portp, SR);
  3773. BRDDISABLE(portp->brdnr);
  3774. spin_unlock_irqrestore(&brd_lock, flags);
  3775. return (sr & SR_TXEMPTY) ? 0 : 1;
  3776. }
  3777. /*****************************************************************************/
  3778. /*
  3779. * Delay for a small amount of time, to give the sc26198 a chance
  3780. * to process a command...
  3781. */
  3782. static void stl_sc26198wait(struct stlport *portp)
  3783. {
  3784. int i;
  3785. pr_debug("stl_sc26198wait(portp=%p)\n", portp);
  3786. if (portp == NULL)
  3787. return;
  3788. for (i = 0; (i < 20); i++)
  3789. stl_sc26198getglobreg(portp, TSTR);
  3790. }
  3791. /*****************************************************************************/
  3792. /*
  3793. * If we are TX flow controlled and in IXANY mode then we may
  3794. * need to unflow control here. We gotta do this because of the
  3795. * automatic flow control modes of the sc26198.
  3796. */
  3797. static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty)
  3798. {
  3799. unsigned char mr0;
  3800. mr0 = stl_sc26198getreg(portp, MR0);
  3801. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3802. stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
  3803. stl_sc26198wait(portp);
  3804. stl_sc26198setreg(portp, MR0, mr0);
  3805. clear_bit(ASYI_TXFLOWED, &portp->istate);
  3806. }
  3807. /*****************************************************************************/
  3808. /*
  3809. * Interrupt service routine for sc26198 panels.
  3810. */
  3811. static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
  3812. {
  3813. struct stlport *portp;
  3814. unsigned int iack;
  3815. spin_lock(&brd_lock);
  3816. /*
  3817. * Work around bug in sc26198 chip... Cannot have A6 address
  3818. * line of UART high, else iack will be returned as 0.
  3819. */
  3820. outb(0, (iobase + 1));
  3821. iack = inb(iobase + XP_IACK);
  3822. portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
  3823. if (iack & IVR_RXDATA)
  3824. stl_sc26198rxisr(portp, iack);
  3825. else if (iack & IVR_TXDATA)
  3826. stl_sc26198txisr(portp);
  3827. else
  3828. stl_sc26198otherisr(portp, iack);
  3829. spin_unlock(&brd_lock);
  3830. }
  3831. /*****************************************************************************/
  3832. /*
  3833. * Transmit interrupt handler. This has gotta be fast! Handling TX
  3834. * chars is pretty simple, stuff as many as possible from the TX buffer
  3835. * into the sc26198 FIFO.
  3836. * In practice it is possible that interrupts are enabled but that the
  3837. * port has been hung up. Need to handle not having any TX buffer here,
  3838. * this is done by using the side effect that head and tail will also
  3839. * be NULL if the buffer has been freed.
  3840. */
  3841. static void stl_sc26198txisr(struct stlport *portp)
  3842. {
  3843. unsigned int ioaddr;
  3844. unsigned char mr0;
  3845. int len, stlen;
  3846. char *head, *tail;
  3847. pr_debug("stl_sc26198txisr(portp=%p)\n", portp);
  3848. ioaddr = portp->ioaddr;
  3849. head = portp->tx.head;
  3850. tail = portp->tx.tail;
  3851. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  3852. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  3853. (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  3854. set_bit(ASYI_TXLOW, &portp->istate);
  3855. schedule_work(&portp->tqueue);
  3856. }
  3857. if (len == 0) {
  3858. outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
  3859. mr0 = inb(ioaddr + XP_DATA);
  3860. if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
  3861. portp->imr &= ~IR_TXRDY;
  3862. outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
  3863. outb(portp->imr, (ioaddr + XP_DATA));
  3864. clear_bit(ASYI_TXBUSY, &portp->istate);
  3865. } else {
  3866. mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
  3867. outb(mr0, (ioaddr + XP_DATA));
  3868. }
  3869. } else {
  3870. len = MIN(len, SC26198_TXFIFOSIZE);
  3871. portp->stats.txtotal += len;
  3872. stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
  3873. outb(GTXFIFO, (ioaddr + XP_ADDR));
  3874. outsb((ioaddr + XP_DATA), tail, stlen);
  3875. len -= stlen;
  3876. tail += stlen;
  3877. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  3878. tail = portp->tx.buf;
  3879. if (len > 0) {
  3880. outsb((ioaddr + XP_DATA), tail, len);
  3881. tail += len;
  3882. }
  3883. portp->tx.tail = tail;
  3884. }
  3885. }
  3886. /*****************************************************************************/
  3887. /*
  3888. * Receive character interrupt handler. Determine if we have good chars
  3889. * or bad chars and then process appropriately. Good chars are easy
  3890. * just shove the lot into the RX buffer and set all status byte to 0.
  3891. * If a bad RX char then process as required. This routine needs to be
  3892. * fast! In practice it is possible that we get an interrupt on a port
  3893. * that is closed. This can happen on hangups - since they completely
  3894. * shutdown a port not in user context. Need to handle this case.
  3895. */
  3896. static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
  3897. {
  3898. struct tty_struct *tty;
  3899. unsigned int len, buflen, ioaddr;
  3900. pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
  3901. tty = portp->tty;
  3902. ioaddr = portp->ioaddr;
  3903. outb(GIBCR, (ioaddr + XP_ADDR));
  3904. len = inb(ioaddr + XP_DATA) + 1;
  3905. if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
  3906. if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
  3907. len = MIN(len, sizeof(stl_unwanted));
  3908. outb(GRXFIFO, (ioaddr + XP_ADDR));
  3909. insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
  3910. portp->stats.rxlost += len;
  3911. portp->stats.rxtotal += len;
  3912. } else {
  3913. len = MIN(len, buflen);
  3914. if (len > 0) {
  3915. unsigned char *ptr;
  3916. outb(GRXFIFO, (ioaddr + XP_ADDR));
  3917. tty_prepare_flip_string(tty, &ptr, len);
  3918. insb((ioaddr + XP_DATA), ptr, len);
  3919. tty_schedule_flip(tty);
  3920. portp->stats.rxtotal += len;
  3921. }
  3922. }
  3923. } else {
  3924. stl_sc26198rxbadchars(portp);
  3925. }
  3926. /*
  3927. * If we are TX flow controlled and in IXANY mode then we may need
  3928. * to unflow control here. We gotta do this because of the automatic
  3929. * flow control modes of the sc26198.
  3930. */
  3931. if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
  3932. if ((tty != NULL) &&
  3933. (tty->termios != NULL) &&
  3934. (tty->termios->c_iflag & IXANY)) {
  3935. stl_sc26198txunflow(portp, tty);
  3936. }
  3937. }
  3938. }
  3939. /*****************************************************************************/
  3940. /*
  3941. * Process an RX bad character.
  3942. */
  3943. static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch)
  3944. {
  3945. struct tty_struct *tty;
  3946. unsigned int ioaddr;
  3947. tty = portp->tty;
  3948. ioaddr = portp->ioaddr;
  3949. if (status & SR_RXPARITY)
  3950. portp->stats.rxparity++;
  3951. if (status & SR_RXFRAMING)
  3952. portp->stats.rxframing++;
  3953. if (status & SR_RXOVERRUN)
  3954. portp->stats.rxoverrun++;
  3955. if (status & SR_RXBREAK)
  3956. portp->stats.rxbreaks++;
  3957. if ((tty != NULL) &&
  3958. ((portp->rxignoremsk & status) == 0)) {
  3959. if (portp->rxmarkmsk & status) {
  3960. if (status & SR_RXBREAK) {
  3961. status = TTY_BREAK;
  3962. if (portp->flags & ASYNC_SAK) {
  3963. do_SAK(tty);
  3964. BRDENABLE(portp->brdnr, portp->pagenr);
  3965. }
  3966. } else if (status & SR_RXPARITY) {
  3967. status = TTY_PARITY;
  3968. } else if (status & SR_RXFRAMING) {
  3969. status = TTY_FRAME;
  3970. } else if(status & SR_RXOVERRUN) {
  3971. status = TTY_OVERRUN;
  3972. } else {
  3973. status = 0;
  3974. }
  3975. } else {
  3976. status = 0;
  3977. }
  3978. tty_insert_flip_char(tty, ch, status);
  3979. tty_schedule_flip(tty);
  3980. if (status == 0)
  3981. portp->stats.rxtotal++;
  3982. }
  3983. }
  3984. /*****************************************************************************/
  3985. /*
  3986. * Process all characters in the RX FIFO of the UART. Check all char
  3987. * status bytes as well, and process as required. We need to check
  3988. * all bytes in the FIFO, in case some more enter the FIFO while we
  3989. * are here. To get the exact character error type we need to switch
  3990. * into CHAR error mode (that is why we need to make sure we empty
  3991. * the FIFO).
  3992. */
  3993. static void stl_sc26198rxbadchars(struct stlport *portp)
  3994. {
  3995. unsigned char status, mr1;
  3996. char ch;
  3997. /*
  3998. * To get the precise error type for each character we must switch
  3999. * back into CHAR error mode.
  4000. */
  4001. mr1 = stl_sc26198getreg(portp, MR1);
  4002. stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
  4003. while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
  4004. stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
  4005. ch = stl_sc26198getreg(portp, RXFIFO);
  4006. stl_sc26198rxbadch(portp, status, ch);
  4007. }
  4008. /*
  4009. * To get correct interrupt class we must switch back into BLOCK
  4010. * error mode.
  4011. */
  4012. stl_sc26198setreg(portp, MR1, mr1);
  4013. }
  4014. /*****************************************************************************/
  4015. /*
  4016. * Other interrupt handler. This includes modem signals, flow
  4017. * control actions, etc. Most stuff is left to off-level interrupt
  4018. * processing time.
  4019. */
  4020. static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
  4021. {
  4022. unsigned char cir, ipr, xisr;
  4023. pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack);
  4024. cir = stl_sc26198getglobreg(portp, CIR);
  4025. switch (cir & CIR_SUBTYPEMASK) {
  4026. case CIR_SUBCOS:
  4027. ipr = stl_sc26198getreg(portp, IPR);
  4028. if (ipr & IPR_DCDCHANGE) {
  4029. set_bit(ASYI_DCDCHANGE, &portp->istate);
  4030. schedule_work(&portp->tqueue);
  4031. portp->stats.modem++;
  4032. }
  4033. break;
  4034. case CIR_SUBXONXOFF:
  4035. xisr = stl_sc26198getreg(portp, XISR);
  4036. if (xisr & XISR_RXXONGOT) {
  4037. set_bit(ASYI_TXFLOWED, &portp->istate);
  4038. portp->stats.txxoff++;
  4039. }
  4040. if (xisr & XISR_RXXOFFGOT) {
  4041. clear_bit(ASYI_TXFLOWED, &portp->istate);
  4042. portp->stats.txxon++;
  4043. }
  4044. break;
  4045. case CIR_SUBBREAK:
  4046. stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
  4047. stl_sc26198rxbadchars(portp);
  4048. break;
  4049. default:
  4050. break;
  4051. }
  4052. }
  4053. /*
  4054. * Loadable module initialization stuff.
  4055. */
  4056. static int __init stallion_module_init(void)
  4057. {
  4058. unsigned int i, retval;
  4059. printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
  4060. spin_lock_init(&stallion_lock);
  4061. spin_lock_init(&brd_lock);
  4062. stl_initbrds();
  4063. retval = pci_register_driver(&stl_pcidriver);
  4064. if (retval)
  4065. goto err;
  4066. stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
  4067. if (!stl_serial)
  4068. return -1;
  4069. /*
  4070. * Set up a character driver for per board stuff. This is mainly used
  4071. * to do stats ioctls on the ports.
  4072. */
  4073. if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
  4074. printk("STALLION: failed to register serial board device\n");
  4075. stallion_class = class_create(THIS_MODULE, "staliomem");
  4076. for (i = 0; i < 4; i++)
  4077. class_device_create(stallion_class, NULL,
  4078. MKDEV(STL_SIOMEMMAJOR, i), NULL,
  4079. "staliomem%d", i);
  4080. stl_serial->owner = THIS_MODULE;
  4081. stl_serial->driver_name = stl_drvname;
  4082. stl_serial->name = "ttyE";
  4083. stl_serial->major = STL_SERIALMAJOR;
  4084. stl_serial->minor_start = 0;
  4085. stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
  4086. stl_serial->subtype = SERIAL_TYPE_NORMAL;
  4087. stl_serial->init_termios = stl_deftermios;
  4088. stl_serial->flags = TTY_DRIVER_REAL_RAW;
  4089. tty_set_operations(stl_serial, &stl_ops);
  4090. if (tty_register_driver(stl_serial)) {
  4091. put_tty_driver(stl_serial);
  4092. printk("STALLION: failed to register serial driver\n");
  4093. return -1;
  4094. }
  4095. return 0;
  4096. err:
  4097. return retval;
  4098. }
  4099. static void __exit stallion_module_exit(void)
  4100. {
  4101. struct stlbrd *brdp;
  4102. int i;
  4103. pr_debug("cleanup_module()\n");
  4104. printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
  4105. stl_drvversion);
  4106. /*
  4107. * Free up all allocated resources used by the ports. This includes
  4108. * memory and interrupts. As part of this process we will also do
  4109. * a hangup on every open port - to try to flush out any processes
  4110. * hanging onto ports.
  4111. */
  4112. i = tty_unregister_driver(stl_serial);
  4113. put_tty_driver(stl_serial);
  4114. if (i) {
  4115. printk("STALLION: failed to un-register tty driver, "
  4116. "errno=%d\n", -i);
  4117. return;
  4118. }
  4119. for (i = 0; i < 4; i++)
  4120. class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
  4121. if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
  4122. printk("STALLION: failed to un-register serial memory device, "
  4123. "errno=%d\n", -i);
  4124. class_destroy(stallion_class);
  4125. pci_unregister_driver(&stl_pcidriver);
  4126. for (i = 0; (i < stl_nrbrds); i++) {
  4127. if ((brdp = stl_brds[i]) == NULL)
  4128. continue;
  4129. free_irq(brdp->irq, brdp);
  4130. stl_cleanup_panels(brdp);
  4131. release_region(brdp->ioaddr1, brdp->iosize1);
  4132. if (brdp->iosize2 > 0)
  4133. release_region(brdp->ioaddr2, brdp->iosize2);
  4134. kfree(brdp);
  4135. stl_brds[i] = NULL;
  4136. }
  4137. }
  4138. module_init(stallion_module_init);
  4139. module_exit(stallion_module_exit);
  4140. MODULE_AUTHOR("Greg Ungerer");
  4141. MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
  4142. MODULE_LICENSE("GPL");