istallion.c 125 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741
  1. /*****************************************************************************/
  2. /*
  3. * istallion.c -- stallion intelligent 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/cdk.h>
  33. #include <linux/comstats.h>
  34. #include <linux/istallion.h>
  35. #include <linux/ioport.h>
  36. #include <linux/delay.h>
  37. #include <linux/init.h>
  38. #include <linux/device.h>
  39. #include <linux/wait.h>
  40. #include <linux/eisa.h>
  41. #include <asm/io.h>
  42. #include <asm/uaccess.h>
  43. #include <linux/pci.h>
  44. /*****************************************************************************/
  45. /*
  46. * Define different board types. Not all of the following board types
  47. * are supported by this driver. But I will use the standard "assigned"
  48. * board numbers. Currently supported boards are abbreviated as:
  49. * ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and
  50. * STAL = Stallion.
  51. */
  52. #define BRD_UNKNOWN 0
  53. #define BRD_STALLION 1
  54. #define BRD_BRUMBY4 2
  55. #define BRD_ONBOARD2 3
  56. #define BRD_ONBOARD 4
  57. #define BRD_BRUMBY8 5
  58. #define BRD_BRUMBY16 6
  59. #define BRD_ONBOARDE 7
  60. #define BRD_ONBOARD32 9
  61. #define BRD_ONBOARD2_32 10
  62. #define BRD_ONBOARDRS 11
  63. #define BRD_EASYIO 20
  64. #define BRD_ECH 21
  65. #define BRD_ECHMC 22
  66. #define BRD_ECP 23
  67. #define BRD_ECPE 24
  68. #define BRD_ECPMC 25
  69. #define BRD_ECHPCI 26
  70. #define BRD_ECH64PCI 27
  71. #define BRD_EASYIOPCI 28
  72. #define BRD_ECPPCI 29
  73. #define BRD_BRUMBY BRD_BRUMBY4
  74. /*
  75. * Define a configuration structure to hold the board configuration.
  76. * Need to set this up in the code (for now) with the boards that are
  77. * to be configured into the system. This is what needs to be modified
  78. * when adding/removing/modifying boards. Each line entry in the
  79. * stli_brdconf[] array is a board. Each line contains io/irq/memory
  80. * ranges for that board (as well as what type of board it is).
  81. * Some examples:
  82. * { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
  83. * This line will configure an EasyConnection 8/64 at io address 2a0,
  84. * and shared memory address of cc000. Multiple EasyConnection 8/64
  85. * boards can share the same shared memory address space. No interrupt
  86. * is required for this board type.
  87. * Another example:
  88. * { BRD_ECPE, 0x5000, 0, 0x80000000, 0, 0 },
  89. * This line will configure an EasyConnection 8/64 EISA in slot 5 and
  90. * shared memory address of 0x80000000 (2 GByte). Multiple
  91. * EasyConnection 8/64 EISA boards can share the same shared memory
  92. * address space. No interrupt is required for this board type.
  93. * Another example:
  94. * { BRD_ONBOARD, 0x240, 0, 0xd0000, 0, 0 },
  95. * This line will configure an ONboard (ISA type) at io address 240,
  96. * and shared memory address of d0000. Multiple ONboards can share
  97. * the same shared memory address space. No interrupt required.
  98. * Another example:
  99. * { BRD_BRUMBY4, 0x360, 0, 0xc8000, 0, 0 },
  100. * This line will configure a Brumby board (any number of ports!) at
  101. * io address 360 and shared memory address of c8000. All Brumby boards
  102. * configured into a system must have their own separate io and memory
  103. * addresses. No interrupt is required.
  104. * Another example:
  105. * { BRD_STALLION, 0x330, 0, 0xd0000, 0, 0 },
  106. * This line will configure an original Stallion board at io address 330
  107. * and shared memory address d0000 (this would only be valid for a "V4.0"
  108. * or Rev.O Stallion board). All Stallion boards configured into the
  109. * system must have their own separate io and memory addresses. No
  110. * interrupt is required.
  111. */
  112. typedef struct {
  113. int brdtype;
  114. int ioaddr1;
  115. int ioaddr2;
  116. unsigned long memaddr;
  117. int irq;
  118. int irqtype;
  119. } stlconf_t;
  120. static stlconf_t stli_brdconf[] = {
  121. /*{ BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },*/
  122. };
  123. static int stli_nrbrds = ARRAY_SIZE(stli_brdconf);
  124. /* stli_lock must NOT be taken holding brd_lock */
  125. static spinlock_t stli_lock; /* TTY logic lock */
  126. static spinlock_t brd_lock; /* Board logic lock */
  127. /*
  128. * There is some experimental EISA board detection code in this driver.
  129. * By default it is disabled, but for those that want to try it out,
  130. * then set the define below to be 1.
  131. */
  132. #define STLI_EISAPROBE 0
  133. /*****************************************************************************/
  134. /*
  135. * Define some important driver characteristics. Device major numbers
  136. * allocated as per Linux Device Registry.
  137. */
  138. #ifndef STL_SIOMEMMAJOR
  139. #define STL_SIOMEMMAJOR 28
  140. #endif
  141. #ifndef STL_SERIALMAJOR
  142. #define STL_SERIALMAJOR 24
  143. #endif
  144. #ifndef STL_CALLOUTMAJOR
  145. #define STL_CALLOUTMAJOR 25
  146. #endif
  147. /*****************************************************************************/
  148. /*
  149. * Define our local driver identity first. Set up stuff to deal with
  150. * all the local structures required by a serial tty driver.
  151. */
  152. static char *stli_drvtitle = "Stallion Intelligent Multiport Serial Driver";
  153. static char *stli_drvname = "istallion";
  154. static char *stli_drvversion = "5.6.0";
  155. static char *stli_serialname = "ttyE";
  156. static struct tty_driver *stli_serial;
  157. #define STLI_TXBUFSIZE 4096
  158. /*
  159. * Use a fast local buffer for cooked characters. Typically a whole
  160. * bunch of cooked characters come in for a port, 1 at a time. So we
  161. * save those up into a local buffer, then write out the whole lot
  162. * with a large memcpy. Just use 1 buffer for all ports, since its
  163. * use it is only need for short periods of time by each port.
  164. */
  165. static char *stli_txcookbuf;
  166. static int stli_txcooksize;
  167. static int stli_txcookrealsize;
  168. static struct tty_struct *stli_txcooktty;
  169. /*
  170. * Define a local default termios struct. All ports will be created
  171. * with this termios initially. Basically all it defines is a raw port
  172. * at 9600 baud, 8 data bits, no parity, 1 stop bit.
  173. */
  174. static struct termios stli_deftermios = {
  175. .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
  176. .c_cc = INIT_C_CC,
  177. };
  178. /*
  179. * Define global stats structures. Not used often, and can be
  180. * re-used for each stats call.
  181. */
  182. static comstats_t stli_comstats;
  183. static combrd_t stli_brdstats;
  184. static asystats_t stli_cdkstats;
  185. static stlibrd_t stli_dummybrd;
  186. static stliport_t stli_dummyport;
  187. /*****************************************************************************/
  188. static stlibrd_t *stli_brds[STL_MAXBRDS];
  189. static int stli_shared;
  190. /*
  191. * Per board state flags. Used with the state field of the board struct.
  192. * Not really much here... All we need to do is keep track of whether
  193. * the board has been detected, and whether it is actually running a slave
  194. * or not.
  195. */
  196. #define BST_FOUND 0x1
  197. #define BST_STARTED 0x2
  198. /*
  199. * Define the set of port state flags. These are marked for internal
  200. * state purposes only, usually to do with the state of communications
  201. * with the slave. Most of them need to be updated atomically, so always
  202. * use the bit setting operations (unless protected by cli/sti).
  203. */
  204. #define ST_INITIALIZING 1
  205. #define ST_OPENING 2
  206. #define ST_CLOSING 3
  207. #define ST_CMDING 4
  208. #define ST_TXBUSY 5
  209. #define ST_RXING 6
  210. #define ST_DOFLUSHRX 7
  211. #define ST_DOFLUSHTX 8
  212. #define ST_DOSIGS 9
  213. #define ST_RXSTOP 10
  214. #define ST_GETSIGS 11
  215. /*
  216. * Define an array of board names as printable strings. Handy for
  217. * referencing boards when printing trace and stuff.
  218. */
  219. static char *stli_brdnames[] = {
  220. "Unknown",
  221. "Stallion",
  222. "Brumby",
  223. "ONboard-MC",
  224. "ONboard",
  225. "Brumby",
  226. "Brumby",
  227. "ONboard-EI",
  228. (char *) NULL,
  229. "ONboard",
  230. "ONboard-MC",
  231. "ONboard-MC",
  232. (char *) NULL,
  233. (char *) NULL,
  234. (char *) NULL,
  235. (char *) NULL,
  236. (char *) NULL,
  237. (char *) NULL,
  238. (char *) NULL,
  239. (char *) NULL,
  240. "EasyIO",
  241. "EC8/32-AT",
  242. "EC8/32-MC",
  243. "EC8/64-AT",
  244. "EC8/64-EI",
  245. "EC8/64-MC",
  246. "EC8/32-PCI",
  247. "EC8/64-PCI",
  248. "EasyIO-PCI",
  249. "EC/RA-PCI",
  250. };
  251. /*****************************************************************************/
  252. /*
  253. * Define some string labels for arguments passed from the module
  254. * load line. These allow for easy board definitions, and easy
  255. * modification of the io, memory and irq resoucres.
  256. */
  257. static char *board0[8];
  258. static char *board1[8];
  259. static char *board2[8];
  260. static char *board3[8];
  261. static char **stli_brdsp[] = {
  262. (char **) &board0,
  263. (char **) &board1,
  264. (char **) &board2,
  265. (char **) &board3
  266. };
  267. /*
  268. * Define a set of common board names, and types. This is used to
  269. * parse any module arguments.
  270. */
  271. typedef struct stlibrdtype {
  272. char *name;
  273. int type;
  274. } stlibrdtype_t;
  275. static stlibrdtype_t stli_brdstr[] = {
  276. { "stallion", BRD_STALLION },
  277. { "1", BRD_STALLION },
  278. { "brumby", BRD_BRUMBY },
  279. { "brumby4", BRD_BRUMBY },
  280. { "brumby/4", BRD_BRUMBY },
  281. { "brumby-4", BRD_BRUMBY },
  282. { "brumby8", BRD_BRUMBY },
  283. { "brumby/8", BRD_BRUMBY },
  284. { "brumby-8", BRD_BRUMBY },
  285. { "brumby16", BRD_BRUMBY },
  286. { "brumby/16", BRD_BRUMBY },
  287. { "brumby-16", BRD_BRUMBY },
  288. { "2", BRD_BRUMBY },
  289. { "onboard2", BRD_ONBOARD2 },
  290. { "onboard-2", BRD_ONBOARD2 },
  291. { "onboard/2", BRD_ONBOARD2 },
  292. { "onboard-mc", BRD_ONBOARD2 },
  293. { "onboard/mc", BRD_ONBOARD2 },
  294. { "onboard-mca", BRD_ONBOARD2 },
  295. { "onboard/mca", BRD_ONBOARD2 },
  296. { "3", BRD_ONBOARD2 },
  297. { "onboard", BRD_ONBOARD },
  298. { "onboardat", BRD_ONBOARD },
  299. { "4", BRD_ONBOARD },
  300. { "onboarde", BRD_ONBOARDE },
  301. { "onboard-e", BRD_ONBOARDE },
  302. { "onboard/e", BRD_ONBOARDE },
  303. { "onboard-ei", BRD_ONBOARDE },
  304. { "onboard/ei", BRD_ONBOARDE },
  305. { "7", BRD_ONBOARDE },
  306. { "ecp", BRD_ECP },
  307. { "ecpat", BRD_ECP },
  308. { "ec8/64", BRD_ECP },
  309. { "ec8/64-at", BRD_ECP },
  310. { "ec8/64-isa", BRD_ECP },
  311. { "23", BRD_ECP },
  312. { "ecpe", BRD_ECPE },
  313. { "ecpei", BRD_ECPE },
  314. { "ec8/64-e", BRD_ECPE },
  315. { "ec8/64-ei", BRD_ECPE },
  316. { "24", BRD_ECPE },
  317. { "ecpmc", BRD_ECPMC },
  318. { "ec8/64-mc", BRD_ECPMC },
  319. { "ec8/64-mca", BRD_ECPMC },
  320. { "25", BRD_ECPMC },
  321. { "ecppci", BRD_ECPPCI },
  322. { "ec/ra", BRD_ECPPCI },
  323. { "ec/ra-pc", BRD_ECPPCI },
  324. { "ec/ra-pci", BRD_ECPPCI },
  325. { "29", BRD_ECPPCI },
  326. };
  327. /*
  328. * Define the module agruments.
  329. */
  330. MODULE_AUTHOR("Greg Ungerer");
  331. MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
  332. MODULE_LICENSE("GPL");
  333. module_param_array(board0, charp, NULL, 0);
  334. MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
  335. module_param_array(board1, charp, NULL, 0);
  336. MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
  337. module_param_array(board2, charp, NULL, 0);
  338. MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
  339. module_param_array(board3, charp, NULL, 0);
  340. MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
  341. /*
  342. * Set up a default memory address table for EISA board probing.
  343. * The default addresses are all bellow 1Mbyte, which has to be the
  344. * case anyway. They should be safe, since we only read values from
  345. * them, and interrupts are disabled while we do it. If the higher
  346. * memory support is compiled in then we also try probing around
  347. * the 1Gb, 2Gb and 3Gb areas as well...
  348. */
  349. static unsigned long stli_eisamemprobeaddrs[] = {
  350. 0xc0000, 0xd0000, 0xe0000, 0xf0000,
  351. 0x80000000, 0x80010000, 0x80020000, 0x80030000,
  352. 0x40000000, 0x40010000, 0x40020000, 0x40030000,
  353. 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
  354. 0xff000000, 0xff010000, 0xff020000, 0xff030000,
  355. };
  356. static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
  357. /*
  358. * Define the Stallion PCI vendor and device IDs.
  359. */
  360. #ifdef CONFIG_PCI
  361. #ifndef PCI_VENDOR_ID_STALLION
  362. #define PCI_VENDOR_ID_STALLION 0x124d
  363. #endif
  364. #ifndef PCI_DEVICE_ID_ECRA
  365. #define PCI_DEVICE_ID_ECRA 0x0004
  366. #endif
  367. static struct pci_device_id istallion_pci_tbl[] = {
  368. { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA), },
  369. { 0 }
  370. };
  371. MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
  372. #endif /* CONFIG_PCI */
  373. /*****************************************************************************/
  374. /*
  375. * Hardware configuration info for ECP boards. These defines apply
  376. * to the directly accessible io ports of the ECP. There is a set of
  377. * defines for each ECP board type, ISA, EISA, MCA and PCI.
  378. */
  379. #define ECP_IOSIZE 4
  380. #define ECP_MEMSIZE (128 * 1024)
  381. #define ECP_PCIMEMSIZE (256 * 1024)
  382. #define ECP_ATPAGESIZE (4 * 1024)
  383. #define ECP_MCPAGESIZE (4 * 1024)
  384. #define ECP_EIPAGESIZE (64 * 1024)
  385. #define ECP_PCIPAGESIZE (64 * 1024)
  386. #define STL_EISAID 0x8c4e
  387. /*
  388. * Important defines for the ISA class of ECP board.
  389. */
  390. #define ECP_ATIREG 0
  391. #define ECP_ATCONFR 1
  392. #define ECP_ATMEMAR 2
  393. #define ECP_ATMEMPR 3
  394. #define ECP_ATSTOP 0x1
  395. #define ECP_ATINTENAB 0x10
  396. #define ECP_ATENABLE 0x20
  397. #define ECP_ATDISABLE 0x00
  398. #define ECP_ATADDRMASK 0x3f000
  399. #define ECP_ATADDRSHFT 12
  400. /*
  401. * Important defines for the EISA class of ECP board.
  402. */
  403. #define ECP_EIIREG 0
  404. #define ECP_EIMEMARL 1
  405. #define ECP_EICONFR 2
  406. #define ECP_EIMEMARH 3
  407. #define ECP_EIENABLE 0x1
  408. #define ECP_EIDISABLE 0x0
  409. #define ECP_EISTOP 0x4
  410. #define ECP_EIEDGE 0x00
  411. #define ECP_EILEVEL 0x80
  412. #define ECP_EIADDRMASKL 0x00ff0000
  413. #define ECP_EIADDRSHFTL 16
  414. #define ECP_EIADDRMASKH 0xff000000
  415. #define ECP_EIADDRSHFTH 24
  416. #define ECP_EIBRDENAB 0xc84
  417. #define ECP_EISAID 0x4
  418. /*
  419. * Important defines for the Micro-channel class of ECP board.
  420. * (It has a lot in common with the ISA boards.)
  421. */
  422. #define ECP_MCIREG 0
  423. #define ECP_MCCONFR 1
  424. #define ECP_MCSTOP 0x20
  425. #define ECP_MCENABLE 0x80
  426. #define ECP_MCDISABLE 0x00
  427. /*
  428. * Important defines for the PCI class of ECP board.
  429. * (It has a lot in common with the other ECP boards.)
  430. */
  431. #define ECP_PCIIREG 0
  432. #define ECP_PCICONFR 1
  433. #define ECP_PCISTOP 0x01
  434. /*
  435. * Hardware configuration info for ONboard and Brumby boards. These
  436. * defines apply to the directly accessible io ports of these boards.
  437. */
  438. #define ONB_IOSIZE 16
  439. #define ONB_MEMSIZE (64 * 1024)
  440. #define ONB_ATPAGESIZE (64 * 1024)
  441. #define ONB_MCPAGESIZE (64 * 1024)
  442. #define ONB_EIMEMSIZE (128 * 1024)
  443. #define ONB_EIPAGESIZE (64 * 1024)
  444. /*
  445. * Important defines for the ISA class of ONboard board.
  446. */
  447. #define ONB_ATIREG 0
  448. #define ONB_ATMEMAR 1
  449. #define ONB_ATCONFR 2
  450. #define ONB_ATSTOP 0x4
  451. #define ONB_ATENABLE 0x01
  452. #define ONB_ATDISABLE 0x00
  453. #define ONB_ATADDRMASK 0xff0000
  454. #define ONB_ATADDRSHFT 16
  455. #define ONB_MEMENABLO 0
  456. #define ONB_MEMENABHI 0x02
  457. /*
  458. * Important defines for the EISA class of ONboard board.
  459. */
  460. #define ONB_EIIREG 0
  461. #define ONB_EIMEMARL 1
  462. #define ONB_EICONFR 2
  463. #define ONB_EIMEMARH 3
  464. #define ONB_EIENABLE 0x1
  465. #define ONB_EIDISABLE 0x0
  466. #define ONB_EISTOP 0x4
  467. #define ONB_EIEDGE 0x00
  468. #define ONB_EILEVEL 0x80
  469. #define ONB_EIADDRMASKL 0x00ff0000
  470. #define ONB_EIADDRSHFTL 16
  471. #define ONB_EIADDRMASKH 0xff000000
  472. #define ONB_EIADDRSHFTH 24
  473. #define ONB_EIBRDENAB 0xc84
  474. #define ONB_EISAID 0x1
  475. /*
  476. * Important defines for the Brumby boards. They are pretty simple,
  477. * there is not much that is programmably configurable.
  478. */
  479. #define BBY_IOSIZE 16
  480. #define BBY_MEMSIZE (64 * 1024)
  481. #define BBY_PAGESIZE (16 * 1024)
  482. #define BBY_ATIREG 0
  483. #define BBY_ATCONFR 1
  484. #define BBY_ATSTOP 0x4
  485. /*
  486. * Important defines for the Stallion boards. They are pretty simple,
  487. * there is not much that is programmably configurable.
  488. */
  489. #define STAL_IOSIZE 16
  490. #define STAL_MEMSIZE (64 * 1024)
  491. #define STAL_PAGESIZE (64 * 1024)
  492. /*
  493. * Define the set of status register values for EasyConnection panels.
  494. * The signature will return with the status value for each panel. From
  495. * this we can determine what is attached to the board - before we have
  496. * actually down loaded any code to it.
  497. */
  498. #define ECH_PNLSTATUS 2
  499. #define ECH_PNL16PORT 0x20
  500. #define ECH_PNLIDMASK 0x07
  501. #define ECH_PNLXPID 0x40
  502. #define ECH_PNLINTRPEND 0x80
  503. /*
  504. * Define some macros to do things to the board. Even those these boards
  505. * are somewhat related there is often significantly different ways of
  506. * doing some operation on it (like enable, paging, reset, etc). So each
  507. * board class has a set of functions which do the commonly required
  508. * operations. The macros below basically just call these functions,
  509. * generally checking for a NULL function - which means that the board
  510. * needs nothing done to it to achieve this operation!
  511. */
  512. #define EBRDINIT(brdp) \
  513. if (brdp->init != NULL) \
  514. (* brdp->init)(brdp)
  515. #define EBRDENABLE(brdp) \
  516. if (brdp->enable != NULL) \
  517. (* brdp->enable)(brdp);
  518. #define EBRDDISABLE(brdp) \
  519. if (brdp->disable != NULL) \
  520. (* brdp->disable)(brdp);
  521. #define EBRDINTR(brdp) \
  522. if (brdp->intr != NULL) \
  523. (* brdp->intr)(brdp);
  524. #define EBRDRESET(brdp) \
  525. if (brdp->reset != NULL) \
  526. (* brdp->reset)(brdp);
  527. #define EBRDGETMEMPTR(brdp,offset) \
  528. (* brdp->getmemptr)(brdp, offset, __LINE__)
  529. /*
  530. * Define the maximal baud rate, and the default baud base for ports.
  531. */
  532. #define STL_MAXBAUD 460800
  533. #define STL_BAUDBASE 115200
  534. #define STL_CLOSEDELAY (5 * HZ / 10)
  535. /*****************************************************************************/
  536. /*
  537. * Define macros to extract a brd or port number from a minor number.
  538. */
  539. #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
  540. #define MINOR2PORT(min) ((min) & 0x3f)
  541. /*
  542. * Define a baud rate table that converts termios baud rate selector
  543. * into the actual baud rate value. All baud rate calculations are based
  544. * on the actual baud rate required.
  545. */
  546. static unsigned int stli_baudrates[] = {
  547. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
  548. 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
  549. };
  550. /*****************************************************************************/
  551. /*
  552. * Define some handy local macros...
  553. */
  554. #undef MIN
  555. #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
  556. #undef TOLOWER
  557. #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
  558. /*****************************************************************************/
  559. /*
  560. * Prototype all functions in this driver!
  561. */
  562. static int stli_parsebrd(stlconf_t *confp, char **argp);
  563. static int stli_init(void);
  564. static int stli_open(struct tty_struct *tty, struct file *filp);
  565. static void stli_close(struct tty_struct *tty, struct file *filp);
  566. static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
  567. static void stli_putchar(struct tty_struct *tty, unsigned char ch);
  568. static void stli_flushchars(struct tty_struct *tty);
  569. static int stli_writeroom(struct tty_struct *tty);
  570. static int stli_charsinbuffer(struct tty_struct *tty);
  571. static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
  572. static void stli_settermios(struct tty_struct *tty, struct termios *old);
  573. static void stli_throttle(struct tty_struct *tty);
  574. static void stli_unthrottle(struct tty_struct *tty);
  575. static void stli_stop(struct tty_struct *tty);
  576. static void stli_start(struct tty_struct *tty);
  577. static void stli_flushbuffer(struct tty_struct *tty);
  578. static void stli_breakctl(struct tty_struct *tty, int state);
  579. static void stli_waituntilsent(struct tty_struct *tty, int timeout);
  580. static void stli_sendxchar(struct tty_struct *tty, char ch);
  581. static void stli_hangup(struct tty_struct *tty);
  582. static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos);
  583. static int stli_brdinit(stlibrd_t *brdp);
  584. static int stli_startbrd(stlibrd_t *brdp);
  585. static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
  586. static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
  587. static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
  588. static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp);
  589. static void stli_poll(unsigned long arg);
  590. static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
  591. static int stli_initopen(stlibrd_t *brdp, stliport_t *portp);
  592. static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
  593. static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
  594. static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp);
  595. static void stli_dohangup(void *arg);
  596. static int stli_setport(stliport_t *portp);
  597. static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
  598. static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
  599. static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
  600. static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp);
  601. static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
  602. static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
  603. static long stli_mktiocm(unsigned long sigvalue);
  604. static void stli_read(stlibrd_t *brdp, stliport_t *portp);
  605. static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp);
  606. static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp);
  607. static int stli_getbrdstats(combrd_t __user *bp);
  608. static int stli_getportstats(stliport_t *portp, comstats_t __user *cp);
  609. static int stli_portcmdstats(stliport_t *portp);
  610. static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp);
  611. static int stli_getportstruct(stliport_t __user *arg);
  612. static int stli_getbrdstruct(stlibrd_t __user *arg);
  613. static stlibrd_t *stli_allocbrd(void);
  614. static void stli_ecpinit(stlibrd_t *brdp);
  615. static void stli_ecpenable(stlibrd_t *brdp);
  616. static void stli_ecpdisable(stlibrd_t *brdp);
  617. static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  618. static void stli_ecpreset(stlibrd_t *brdp);
  619. static void stli_ecpintr(stlibrd_t *brdp);
  620. static void stli_ecpeiinit(stlibrd_t *brdp);
  621. static void stli_ecpeienable(stlibrd_t *brdp);
  622. static void stli_ecpeidisable(stlibrd_t *brdp);
  623. static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  624. static void stli_ecpeireset(stlibrd_t *brdp);
  625. static void stli_ecpmcenable(stlibrd_t *brdp);
  626. static void stli_ecpmcdisable(stlibrd_t *brdp);
  627. static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  628. static void stli_ecpmcreset(stlibrd_t *brdp);
  629. static void stli_ecppciinit(stlibrd_t *brdp);
  630. static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  631. static void stli_ecppcireset(stlibrd_t *brdp);
  632. static void stli_onbinit(stlibrd_t *brdp);
  633. static void stli_onbenable(stlibrd_t *brdp);
  634. static void stli_onbdisable(stlibrd_t *brdp);
  635. static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  636. static void stli_onbreset(stlibrd_t *brdp);
  637. static void stli_onbeinit(stlibrd_t *brdp);
  638. static void stli_onbeenable(stlibrd_t *brdp);
  639. static void stli_onbedisable(stlibrd_t *brdp);
  640. static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  641. static void stli_onbereset(stlibrd_t *brdp);
  642. static void stli_bbyinit(stlibrd_t *brdp);
  643. static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  644. static void stli_bbyreset(stlibrd_t *brdp);
  645. static void stli_stalinit(stlibrd_t *brdp);
  646. static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  647. static void stli_stalreset(stlibrd_t *brdp);
  648. static stliport_t *stli_getport(int brdnr, int panelnr, int portnr);
  649. static int stli_initecp(stlibrd_t *brdp);
  650. static int stli_initonb(stlibrd_t *brdp);
  651. static int stli_eisamemprobe(stlibrd_t *brdp);
  652. static int stli_initports(stlibrd_t *brdp);
  653. #ifdef CONFIG_PCI
  654. static int stli_initpcibrd(int brdtype, struct pci_dev *devp);
  655. #endif
  656. /*****************************************************************************/
  657. /*
  658. * Define the driver info for a user level shared memory device. This
  659. * device will work sort of like the /dev/kmem device - except that it
  660. * will give access to the shared memory on the Stallion intelligent
  661. * board. This is also a very useful debugging tool.
  662. */
  663. static const struct file_operations stli_fsiomem = {
  664. .owner = THIS_MODULE,
  665. .read = stli_memread,
  666. .write = stli_memwrite,
  667. .ioctl = stli_memioctl,
  668. };
  669. /*****************************************************************************/
  670. /*
  671. * Define a timer_list entry for our poll routine. The slave board
  672. * is polled every so often to see if anything needs doing. This is
  673. * much cheaper on host cpu than using interrupts. It turns out to
  674. * not increase character latency by much either...
  675. */
  676. static DEFINE_TIMER(stli_timerlist, stli_poll, 0, 0);
  677. static int stli_timeron;
  678. /*
  679. * Define the calculation for the timeout routine.
  680. */
  681. #define STLI_TIMEOUT (jiffies + 1)
  682. /*****************************************************************************/
  683. static struct class *istallion_class;
  684. /*
  685. * Loadable module initialization stuff.
  686. */
  687. static int __init istallion_module_init(void)
  688. {
  689. stli_init();
  690. return 0;
  691. }
  692. /*****************************************************************************/
  693. static void __exit istallion_module_exit(void)
  694. {
  695. stlibrd_t *brdp;
  696. stliport_t *portp;
  697. int i, j;
  698. printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
  699. stli_drvversion);
  700. /*
  701. * Free up all allocated resources used by the ports. This includes
  702. * memory and interrupts.
  703. */
  704. if (stli_timeron) {
  705. stli_timeron = 0;
  706. del_timer_sync(&stli_timerlist);
  707. }
  708. i = tty_unregister_driver(stli_serial);
  709. if (i) {
  710. printk("STALLION: failed to un-register tty driver, "
  711. "errno=%d\n", -i);
  712. return;
  713. }
  714. put_tty_driver(stli_serial);
  715. for (i = 0; i < 4; i++)
  716. class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, i));
  717. class_destroy(istallion_class);
  718. if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
  719. printk("STALLION: failed to un-register serial memory device, "
  720. "errno=%d\n", -i);
  721. kfree(stli_txcookbuf);
  722. for (i = 0; (i < stli_nrbrds); i++) {
  723. if ((brdp = stli_brds[i]) == NULL)
  724. continue;
  725. for (j = 0; (j < STL_MAXPORTS); j++) {
  726. portp = brdp->ports[j];
  727. if (portp != NULL) {
  728. if (portp->tty != NULL)
  729. tty_hangup(portp->tty);
  730. kfree(portp);
  731. }
  732. }
  733. iounmap(brdp->membase);
  734. if (brdp->iosize > 0)
  735. release_region(brdp->iobase, brdp->iosize);
  736. kfree(brdp);
  737. stli_brds[i] = NULL;
  738. }
  739. }
  740. module_init(istallion_module_init);
  741. module_exit(istallion_module_exit);
  742. /*****************************************************************************/
  743. /*
  744. * Check for any arguments passed in on the module load command line.
  745. */
  746. static void stli_argbrds(void)
  747. {
  748. stlconf_t conf;
  749. stlibrd_t *brdp;
  750. int i;
  751. for (i = stli_nrbrds; i < ARRAY_SIZE(stli_brdsp); i++) {
  752. memset(&conf, 0, sizeof(conf));
  753. if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
  754. continue;
  755. if ((brdp = stli_allocbrd()) == NULL)
  756. continue;
  757. stli_nrbrds = i + 1;
  758. brdp->brdnr = i;
  759. brdp->brdtype = conf.brdtype;
  760. brdp->iobase = conf.ioaddr1;
  761. brdp->memaddr = conf.memaddr;
  762. stli_brdinit(brdp);
  763. }
  764. }
  765. /*****************************************************************************/
  766. /*
  767. * Convert an ascii string number into an unsigned long.
  768. */
  769. static unsigned long stli_atol(char *str)
  770. {
  771. unsigned long val;
  772. int base, c;
  773. char *sp;
  774. val = 0;
  775. sp = str;
  776. if ((*sp == '0') && (*(sp+1) == 'x')) {
  777. base = 16;
  778. sp += 2;
  779. } else if (*sp == '0') {
  780. base = 8;
  781. sp++;
  782. } else {
  783. base = 10;
  784. }
  785. for (; (*sp != 0); sp++) {
  786. c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
  787. if ((c < 0) || (c >= base)) {
  788. printk("STALLION: invalid argument %s\n", str);
  789. val = 0;
  790. break;
  791. }
  792. val = (val * base) + c;
  793. }
  794. return(val);
  795. }
  796. /*****************************************************************************/
  797. /*
  798. * Parse the supplied argument string, into the board conf struct.
  799. */
  800. static int stli_parsebrd(stlconf_t *confp, char **argp)
  801. {
  802. char *sp;
  803. int i;
  804. if (argp[0] == NULL || *argp[0] == 0)
  805. return 0;
  806. for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
  807. *sp = TOLOWER(*sp);
  808. for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) {
  809. if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
  810. break;
  811. }
  812. if (i == ARRAY_SIZE(stli_brdstr)) {
  813. printk("STALLION: unknown board name, %s?\n", argp[0]);
  814. return 0;
  815. }
  816. confp->brdtype = stli_brdstr[i].type;
  817. if (argp[1] != NULL && *argp[1] != 0)
  818. confp->ioaddr1 = stli_atol(argp[1]);
  819. if (argp[2] != NULL && *argp[2] != 0)
  820. confp->memaddr = stli_atol(argp[2]);
  821. return(1);
  822. }
  823. /*****************************************************************************/
  824. static int stli_open(struct tty_struct *tty, struct file *filp)
  825. {
  826. stlibrd_t *brdp;
  827. stliport_t *portp;
  828. unsigned int minordev;
  829. int brdnr, portnr, rc;
  830. minordev = tty->index;
  831. brdnr = MINOR2BRD(minordev);
  832. if (brdnr >= stli_nrbrds)
  833. return -ENODEV;
  834. brdp = stli_brds[brdnr];
  835. if (brdp == NULL)
  836. return -ENODEV;
  837. if ((brdp->state & BST_STARTED) == 0)
  838. return -ENODEV;
  839. portnr = MINOR2PORT(minordev);
  840. if ((portnr < 0) || (portnr > brdp->nrports))
  841. return -ENODEV;
  842. portp = brdp->ports[portnr];
  843. if (portp == NULL)
  844. return -ENODEV;
  845. if (portp->devnr < 1)
  846. return -ENODEV;
  847. /*
  848. * Check if this port is in the middle of closing. If so then wait
  849. * until it is closed then return error status based on flag settings.
  850. * The sleep here does not need interrupt protection since the wakeup
  851. * for it is done with the same context.
  852. */
  853. if (portp->flags & ASYNC_CLOSING) {
  854. interruptible_sleep_on(&portp->close_wait);
  855. if (portp->flags & ASYNC_HUP_NOTIFY)
  856. return -EAGAIN;
  857. return -ERESTARTSYS;
  858. }
  859. /*
  860. * On the first open of the device setup the port hardware, and
  861. * initialize the per port data structure. Since initializing the port
  862. * requires several commands to the board we will need to wait for any
  863. * other open that is already initializing the port.
  864. */
  865. portp->tty = tty;
  866. tty->driver_data = portp;
  867. portp->refcount++;
  868. wait_event_interruptible(portp->raw_wait,
  869. !test_bit(ST_INITIALIZING, &portp->state));
  870. if (signal_pending(current))
  871. return -ERESTARTSYS;
  872. if ((portp->flags & ASYNC_INITIALIZED) == 0) {
  873. set_bit(ST_INITIALIZING, &portp->state);
  874. if ((rc = stli_initopen(brdp, portp)) >= 0) {
  875. portp->flags |= ASYNC_INITIALIZED;
  876. clear_bit(TTY_IO_ERROR, &tty->flags);
  877. }
  878. clear_bit(ST_INITIALIZING, &portp->state);
  879. wake_up_interruptible(&portp->raw_wait);
  880. if (rc < 0)
  881. return rc;
  882. }
  883. /*
  884. * Check if this port is in the middle of closing. If so then wait
  885. * until it is closed then return error status, based on flag settings.
  886. * The sleep here does not need interrupt protection since the wakeup
  887. * for it is done with the same context.
  888. */
  889. if (portp->flags & ASYNC_CLOSING) {
  890. interruptible_sleep_on(&portp->close_wait);
  891. if (portp->flags & ASYNC_HUP_NOTIFY)
  892. return -EAGAIN;
  893. return -ERESTARTSYS;
  894. }
  895. /*
  896. * Based on type of open being done check if it can overlap with any
  897. * previous opens still in effect. If we are a normal serial device
  898. * then also we might have to wait for carrier.
  899. */
  900. if (!(filp->f_flags & O_NONBLOCK)) {
  901. if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
  902. return rc;
  903. }
  904. portp->flags |= ASYNC_NORMAL_ACTIVE;
  905. return 0;
  906. }
  907. /*****************************************************************************/
  908. static void stli_close(struct tty_struct *tty, struct file *filp)
  909. {
  910. stlibrd_t *brdp;
  911. stliport_t *portp;
  912. unsigned long flags;
  913. portp = tty->driver_data;
  914. if (portp == NULL)
  915. return;
  916. spin_lock_irqsave(&stli_lock, flags);
  917. if (tty_hung_up_p(filp)) {
  918. spin_unlock_irqrestore(&stli_lock, flags);
  919. return;
  920. }
  921. if ((tty->count == 1) && (portp->refcount != 1))
  922. portp->refcount = 1;
  923. if (portp->refcount-- > 1) {
  924. spin_unlock_irqrestore(&stli_lock, flags);
  925. return;
  926. }
  927. portp->flags |= ASYNC_CLOSING;
  928. /*
  929. * May want to wait for data to drain before closing. The BUSY flag
  930. * keeps track of whether we are still transmitting or not. It is
  931. * updated by messages from the slave - indicating when all chars
  932. * really have drained.
  933. */
  934. if (tty == stli_txcooktty)
  935. stli_flushchars(tty);
  936. tty->closing = 1;
  937. spin_unlock_irqrestore(&stli_lock, flags);
  938. if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  939. tty_wait_until_sent(tty, portp->closing_wait);
  940. portp->flags &= ~ASYNC_INITIALIZED;
  941. brdp = stli_brds[portp->brdnr];
  942. stli_rawclose(brdp, portp, 0, 0);
  943. if (tty->termios->c_cflag & HUPCL) {
  944. stli_mkasysigs(&portp->asig, 0, 0);
  945. if (test_bit(ST_CMDING, &portp->state))
  946. set_bit(ST_DOSIGS, &portp->state);
  947. else
  948. stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
  949. sizeof(asysigs_t), 0);
  950. }
  951. clear_bit(ST_TXBUSY, &portp->state);
  952. clear_bit(ST_RXSTOP, &portp->state);
  953. set_bit(TTY_IO_ERROR, &tty->flags);
  954. if (tty->ldisc.flush_buffer)
  955. (tty->ldisc.flush_buffer)(tty);
  956. set_bit(ST_DOFLUSHRX, &portp->state);
  957. stli_flushbuffer(tty);
  958. tty->closing = 0;
  959. portp->tty = NULL;
  960. if (portp->openwaitcnt) {
  961. if (portp->close_delay)
  962. msleep_interruptible(jiffies_to_msecs(portp->close_delay));
  963. wake_up_interruptible(&portp->open_wait);
  964. }
  965. portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  966. wake_up_interruptible(&portp->close_wait);
  967. }
  968. /*****************************************************************************/
  969. /*
  970. * Carry out first open operations on a port. This involves a number of
  971. * commands to be sent to the slave. We need to open the port, set the
  972. * notification events, set the initial port settings, get and set the
  973. * initial signal values. We sleep and wait in between each one. But
  974. * this still all happens pretty quickly.
  975. */
  976. static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
  977. {
  978. struct tty_struct *tty;
  979. asynotify_t nt;
  980. asyport_t aport;
  981. int rc;
  982. if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
  983. return rc;
  984. memset(&nt, 0, sizeof(asynotify_t));
  985. nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
  986. nt.signal = SG_DCD;
  987. if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
  988. sizeof(asynotify_t), 0)) < 0)
  989. return rc;
  990. tty = portp->tty;
  991. if (tty == NULL)
  992. return -ENODEV;
  993. stli_mkasyport(portp, &aport, tty->termios);
  994. if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
  995. sizeof(asyport_t), 0)) < 0)
  996. return rc;
  997. set_bit(ST_GETSIGS, &portp->state);
  998. if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
  999. sizeof(asysigs_t), 1)) < 0)
  1000. return rc;
  1001. if (test_and_clear_bit(ST_GETSIGS, &portp->state))
  1002. portp->sigs = stli_mktiocm(portp->asig.sigvalue);
  1003. stli_mkasysigs(&portp->asig, 1, 1);
  1004. if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1005. sizeof(asysigs_t), 0)) < 0)
  1006. return rc;
  1007. return 0;
  1008. }
  1009. /*****************************************************************************/
  1010. /*
  1011. * Send an open message to the slave. This will sleep waiting for the
  1012. * acknowledgement, so must have user context. We need to co-ordinate
  1013. * with close events here, since we don't want open and close events
  1014. * to overlap.
  1015. */
  1016. static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
  1017. {
  1018. cdkhdr_t __iomem *hdrp;
  1019. cdkctrl_t __iomem *cp;
  1020. unsigned char __iomem *bits;
  1021. unsigned long flags;
  1022. int rc;
  1023. /*
  1024. * Send a message to the slave to open this port.
  1025. */
  1026. /*
  1027. * Slave is already closing this port. This can happen if a hangup
  1028. * occurs on this port. So we must wait until it is complete. The
  1029. * order of opens and closes may not be preserved across shared
  1030. * memory, so we must wait until it is complete.
  1031. */
  1032. wait_event_interruptible(portp->raw_wait,
  1033. !test_bit(ST_CLOSING, &portp->state));
  1034. if (signal_pending(current)) {
  1035. return -ERESTARTSYS;
  1036. }
  1037. /*
  1038. * Everything is ready now, so write the open message into shared
  1039. * memory. Once the message is in set the service bits to say that
  1040. * this port wants service.
  1041. */
  1042. spin_lock_irqsave(&brd_lock, flags);
  1043. EBRDENABLE(brdp);
  1044. cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  1045. writel(arg, &cp->openarg);
  1046. writeb(1, &cp->open);
  1047. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1048. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  1049. portp->portidx;
  1050. writeb(readb(bits) | portp->portbit, bits);
  1051. EBRDDISABLE(brdp);
  1052. if (wait == 0) {
  1053. spin_unlock_irqrestore(&brd_lock, flags);
  1054. return 0;
  1055. }
  1056. /*
  1057. * Slave is in action, so now we must wait for the open acknowledgment
  1058. * to come back.
  1059. */
  1060. rc = 0;
  1061. set_bit(ST_OPENING, &portp->state);
  1062. spin_unlock_irqrestore(&brd_lock, flags);
  1063. wait_event_interruptible(portp->raw_wait,
  1064. !test_bit(ST_OPENING, &portp->state));
  1065. if (signal_pending(current))
  1066. rc = -ERESTARTSYS;
  1067. if ((rc == 0) && (portp->rc != 0))
  1068. rc = -EIO;
  1069. return rc;
  1070. }
  1071. /*****************************************************************************/
  1072. /*
  1073. * Send a close message to the slave. Normally this will sleep waiting
  1074. * for the acknowledgement, but if wait parameter is 0 it will not. If
  1075. * wait is true then must have user context (to sleep).
  1076. */
  1077. static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
  1078. {
  1079. cdkhdr_t __iomem *hdrp;
  1080. cdkctrl_t __iomem *cp;
  1081. unsigned char __iomem *bits;
  1082. unsigned long flags;
  1083. int rc;
  1084. /*
  1085. * Slave is already closing this port. This can happen if a hangup
  1086. * occurs on this port.
  1087. */
  1088. if (wait) {
  1089. wait_event_interruptible(portp->raw_wait,
  1090. !test_bit(ST_CLOSING, &portp->state));
  1091. if (signal_pending(current)) {
  1092. return -ERESTARTSYS;
  1093. }
  1094. }
  1095. /*
  1096. * Write the close command into shared memory.
  1097. */
  1098. spin_lock_irqsave(&brd_lock, flags);
  1099. EBRDENABLE(brdp);
  1100. cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  1101. writel(arg, &cp->closearg);
  1102. writeb(1, &cp->close);
  1103. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1104. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  1105. portp->portidx;
  1106. writeb(readb(bits) |portp->portbit, bits);
  1107. EBRDDISABLE(brdp);
  1108. set_bit(ST_CLOSING, &portp->state);
  1109. spin_unlock_irqrestore(&brd_lock, flags);
  1110. if (wait == 0)
  1111. return 0;
  1112. /*
  1113. * Slave is in action, so now we must wait for the open acknowledgment
  1114. * to come back.
  1115. */
  1116. rc = 0;
  1117. wait_event_interruptible(portp->raw_wait,
  1118. !test_bit(ST_CLOSING, &portp->state));
  1119. if (signal_pending(current))
  1120. rc = -ERESTARTSYS;
  1121. if ((rc == 0) && (portp->rc != 0))
  1122. rc = -EIO;
  1123. return rc;
  1124. }
  1125. /*****************************************************************************/
  1126. /*
  1127. * Send a command to the slave and wait for the response. This must
  1128. * have user context (it sleeps). This routine is generic in that it
  1129. * can send any type of command. Its purpose is to wait for that command
  1130. * to complete (as opposed to initiating the command then returning).
  1131. */
  1132. static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
  1133. {
  1134. wait_event_interruptible(portp->raw_wait,
  1135. !test_bit(ST_CMDING, &portp->state));
  1136. if (signal_pending(current))
  1137. return -ERESTARTSYS;
  1138. stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
  1139. wait_event_interruptible(portp->raw_wait,
  1140. !test_bit(ST_CMDING, &portp->state));
  1141. if (signal_pending(current))
  1142. return -ERESTARTSYS;
  1143. if (portp->rc != 0)
  1144. return -EIO;
  1145. return 0;
  1146. }
  1147. /*****************************************************************************/
  1148. /*
  1149. * Send the termios settings for this port to the slave. This sleeps
  1150. * waiting for the command to complete - so must have user context.
  1151. */
  1152. static int stli_setport(stliport_t *portp)
  1153. {
  1154. stlibrd_t *brdp;
  1155. asyport_t aport;
  1156. if (portp == NULL)
  1157. return -ENODEV;
  1158. if (portp->tty == NULL)
  1159. return -ENODEV;
  1160. if (portp->brdnr < 0 && portp->brdnr >= stli_nrbrds)
  1161. return -ENODEV;
  1162. brdp = stli_brds[portp->brdnr];
  1163. if (brdp == NULL)
  1164. return -ENODEV;
  1165. stli_mkasyport(portp, &aport, portp->tty->termios);
  1166. return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
  1167. }
  1168. /*****************************************************************************/
  1169. /*
  1170. * Possibly need to wait for carrier (DCD signal) to come high. Say
  1171. * maybe because if we are clocal then we don't need to wait...
  1172. */
  1173. static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
  1174. {
  1175. unsigned long flags;
  1176. int rc, doclocal;
  1177. rc = 0;
  1178. doclocal = 0;
  1179. if (portp->tty->termios->c_cflag & CLOCAL)
  1180. doclocal++;
  1181. spin_lock_irqsave(&stli_lock, flags);
  1182. portp->openwaitcnt++;
  1183. if (! tty_hung_up_p(filp))
  1184. portp->refcount--;
  1185. spin_unlock_irqrestore(&stli_lock, flags);
  1186. for (;;) {
  1187. stli_mkasysigs(&portp->asig, 1, 1);
  1188. if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
  1189. &portp->asig, sizeof(asysigs_t), 0)) < 0)
  1190. break;
  1191. if (tty_hung_up_p(filp) ||
  1192. ((portp->flags & ASYNC_INITIALIZED) == 0)) {
  1193. if (portp->flags & ASYNC_HUP_NOTIFY)
  1194. rc = -EBUSY;
  1195. else
  1196. rc = -ERESTARTSYS;
  1197. break;
  1198. }
  1199. if (((portp->flags & ASYNC_CLOSING) == 0) &&
  1200. (doclocal || (portp->sigs & TIOCM_CD))) {
  1201. break;
  1202. }
  1203. if (signal_pending(current)) {
  1204. rc = -ERESTARTSYS;
  1205. break;
  1206. }
  1207. interruptible_sleep_on(&portp->open_wait);
  1208. }
  1209. spin_lock_irqsave(&stli_lock, flags);
  1210. if (! tty_hung_up_p(filp))
  1211. portp->refcount++;
  1212. portp->openwaitcnt--;
  1213. spin_unlock_irqrestore(&stli_lock, flags);
  1214. return rc;
  1215. }
  1216. /*****************************************************************************/
  1217. /*
  1218. * Write routine. Take the data and put it in the shared memory ring
  1219. * queue. If port is not already sending chars then need to mark the
  1220. * service bits for this port.
  1221. */
  1222. static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
  1223. {
  1224. cdkasy_t __iomem *ap;
  1225. cdkhdr_t __iomem *hdrp;
  1226. unsigned char __iomem *bits;
  1227. unsigned char __iomem *shbuf;
  1228. unsigned char *chbuf;
  1229. stliport_t *portp;
  1230. stlibrd_t *brdp;
  1231. unsigned int len, stlen, head, tail, size;
  1232. unsigned long flags;
  1233. if (tty == stli_txcooktty)
  1234. stli_flushchars(tty);
  1235. portp = tty->driver_data;
  1236. if (portp == NULL)
  1237. return 0;
  1238. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1239. return 0;
  1240. brdp = stli_brds[portp->brdnr];
  1241. if (brdp == NULL)
  1242. return 0;
  1243. chbuf = (unsigned char *) buf;
  1244. /*
  1245. * All data is now local, shove as much as possible into shared memory.
  1246. */
  1247. spin_lock_irqsave(&brd_lock, flags);
  1248. EBRDENABLE(brdp);
  1249. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1250. head = (unsigned int) readw(&ap->txq.head);
  1251. tail = (unsigned int) readw(&ap->txq.tail);
  1252. if (tail != ((unsigned int) readw(&ap->txq.tail)))
  1253. tail = (unsigned int) readw(&ap->txq.tail);
  1254. size = portp->txsize;
  1255. if (head >= tail) {
  1256. len = size - (head - tail) - 1;
  1257. stlen = size - head;
  1258. } else {
  1259. len = tail - head - 1;
  1260. stlen = len;
  1261. }
  1262. len = MIN(len, count);
  1263. count = 0;
  1264. shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
  1265. while (len > 0) {
  1266. stlen = MIN(len, stlen);
  1267. memcpy_toio(shbuf + head, chbuf, stlen);
  1268. chbuf += stlen;
  1269. len -= stlen;
  1270. count += stlen;
  1271. head += stlen;
  1272. if (head >= size) {
  1273. head = 0;
  1274. stlen = tail;
  1275. }
  1276. }
  1277. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1278. writew(head, &ap->txq.head);
  1279. if (test_bit(ST_TXBUSY, &portp->state)) {
  1280. if (readl(&ap->changed.data) & DT_TXEMPTY)
  1281. writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
  1282. }
  1283. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1284. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  1285. portp->portidx;
  1286. writeb(readb(bits) | portp->portbit, bits);
  1287. set_bit(ST_TXBUSY, &portp->state);
  1288. EBRDDISABLE(brdp);
  1289. spin_unlock_irqrestore(&brd_lock, flags);
  1290. return(count);
  1291. }
  1292. /*****************************************************************************/
  1293. /*
  1294. * Output a single character. We put it into a temporary local buffer
  1295. * (for speed) then write out that buffer when the flushchars routine
  1296. * is called. There is a safety catch here so that if some other port
  1297. * writes chars before the current buffer has been, then we write them
  1298. * first them do the new ports.
  1299. */
  1300. static void stli_putchar(struct tty_struct *tty, unsigned char ch)
  1301. {
  1302. if (tty != stli_txcooktty) {
  1303. if (stli_txcooktty != NULL)
  1304. stli_flushchars(stli_txcooktty);
  1305. stli_txcooktty = tty;
  1306. }
  1307. stli_txcookbuf[stli_txcooksize++] = ch;
  1308. }
  1309. /*****************************************************************************/
  1310. /*
  1311. * Transfer characters from the local TX cooking buffer to the board.
  1312. * We sort of ignore the tty that gets passed in here. We rely on the
  1313. * info stored with the TX cook buffer to tell us which port to flush
  1314. * the data on. In any case we clean out the TX cook buffer, for re-use
  1315. * by someone else.
  1316. */
  1317. static void stli_flushchars(struct tty_struct *tty)
  1318. {
  1319. cdkhdr_t __iomem *hdrp;
  1320. unsigned char __iomem *bits;
  1321. cdkasy_t __iomem *ap;
  1322. struct tty_struct *cooktty;
  1323. stliport_t *portp;
  1324. stlibrd_t *brdp;
  1325. unsigned int len, stlen, head, tail, size, count, cooksize;
  1326. unsigned char *buf;
  1327. unsigned char __iomem *shbuf;
  1328. unsigned long flags;
  1329. cooksize = stli_txcooksize;
  1330. cooktty = stli_txcooktty;
  1331. stli_txcooksize = 0;
  1332. stli_txcookrealsize = 0;
  1333. stli_txcooktty = NULL;
  1334. if (tty == NULL)
  1335. return;
  1336. if (cooktty == NULL)
  1337. return;
  1338. if (tty != cooktty)
  1339. tty = cooktty;
  1340. if (cooksize == 0)
  1341. return;
  1342. portp = tty->driver_data;
  1343. if (portp == NULL)
  1344. return;
  1345. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1346. return;
  1347. brdp = stli_brds[portp->brdnr];
  1348. if (brdp == NULL)
  1349. return;
  1350. spin_lock_irqsave(&brd_lock, flags);
  1351. EBRDENABLE(brdp);
  1352. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1353. head = (unsigned int) readw(&ap->txq.head);
  1354. tail = (unsigned int) readw(&ap->txq.tail);
  1355. if (tail != ((unsigned int) readw(&ap->txq.tail)))
  1356. tail = (unsigned int) readw(&ap->txq.tail);
  1357. size = portp->txsize;
  1358. if (head >= tail) {
  1359. len = size - (head - tail) - 1;
  1360. stlen = size - head;
  1361. } else {
  1362. len = tail - head - 1;
  1363. stlen = len;
  1364. }
  1365. len = MIN(len, cooksize);
  1366. count = 0;
  1367. shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
  1368. buf = stli_txcookbuf;
  1369. while (len > 0) {
  1370. stlen = MIN(len, stlen);
  1371. memcpy_toio(shbuf + head, buf, stlen);
  1372. buf += stlen;
  1373. len -= stlen;
  1374. count += stlen;
  1375. head += stlen;
  1376. if (head >= size) {
  1377. head = 0;
  1378. stlen = tail;
  1379. }
  1380. }
  1381. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1382. writew(head, &ap->txq.head);
  1383. if (test_bit(ST_TXBUSY, &portp->state)) {
  1384. if (readl(&ap->changed.data) & DT_TXEMPTY)
  1385. writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
  1386. }
  1387. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1388. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  1389. portp->portidx;
  1390. writeb(readb(bits) | portp->portbit, bits);
  1391. set_bit(ST_TXBUSY, &portp->state);
  1392. EBRDDISABLE(brdp);
  1393. spin_unlock_irqrestore(&brd_lock, flags);
  1394. }
  1395. /*****************************************************************************/
  1396. static int stli_writeroom(struct tty_struct *tty)
  1397. {
  1398. cdkasyrq_t __iomem *rp;
  1399. stliport_t *portp;
  1400. stlibrd_t *brdp;
  1401. unsigned int head, tail, len;
  1402. unsigned long flags;
  1403. if (tty == stli_txcooktty) {
  1404. if (stli_txcookrealsize != 0) {
  1405. len = stli_txcookrealsize - stli_txcooksize;
  1406. return len;
  1407. }
  1408. }
  1409. portp = tty->driver_data;
  1410. if (portp == NULL)
  1411. return 0;
  1412. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1413. return 0;
  1414. brdp = stli_brds[portp->brdnr];
  1415. if (brdp == NULL)
  1416. return 0;
  1417. spin_lock_irqsave(&brd_lock, flags);
  1418. EBRDENABLE(brdp);
  1419. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
  1420. head = (unsigned int) readw(&rp->head);
  1421. tail = (unsigned int) readw(&rp->tail);
  1422. if (tail != ((unsigned int) readw(&rp->tail)))
  1423. tail = (unsigned int) readw(&rp->tail);
  1424. len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
  1425. len--;
  1426. EBRDDISABLE(brdp);
  1427. spin_unlock_irqrestore(&brd_lock, flags);
  1428. if (tty == stli_txcooktty) {
  1429. stli_txcookrealsize = len;
  1430. len -= stli_txcooksize;
  1431. }
  1432. return len;
  1433. }
  1434. /*****************************************************************************/
  1435. /*
  1436. * Return the number of characters in the transmit buffer. Normally we
  1437. * will return the number of chars in the shared memory ring queue.
  1438. * We need to kludge around the case where the shared memory buffer is
  1439. * empty but not all characters have drained yet, for this case just
  1440. * return that there is 1 character in the buffer!
  1441. */
  1442. static int stli_charsinbuffer(struct tty_struct *tty)
  1443. {
  1444. cdkasyrq_t __iomem *rp;
  1445. stliport_t *portp;
  1446. stlibrd_t *brdp;
  1447. unsigned int head, tail, len;
  1448. unsigned long flags;
  1449. if (tty == stli_txcooktty)
  1450. stli_flushchars(tty);
  1451. portp = tty->driver_data;
  1452. if (portp == NULL)
  1453. return 0;
  1454. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1455. return 0;
  1456. brdp = stli_brds[portp->brdnr];
  1457. if (brdp == NULL)
  1458. return 0;
  1459. spin_lock_irqsave(&brd_lock, flags);
  1460. EBRDENABLE(brdp);
  1461. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
  1462. head = (unsigned int) readw(&rp->head);
  1463. tail = (unsigned int) readw(&rp->tail);
  1464. if (tail != ((unsigned int) readw(&rp->tail)))
  1465. tail = (unsigned int) readw(&rp->tail);
  1466. len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
  1467. if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
  1468. len = 1;
  1469. EBRDDISABLE(brdp);
  1470. spin_unlock_irqrestore(&brd_lock, flags);
  1471. return len;
  1472. }
  1473. /*****************************************************************************/
  1474. /*
  1475. * Generate the serial struct info.
  1476. */
  1477. static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
  1478. {
  1479. struct serial_struct sio;
  1480. stlibrd_t *brdp;
  1481. memset(&sio, 0, sizeof(struct serial_struct));
  1482. sio.type = PORT_UNKNOWN;
  1483. sio.line = portp->portnr;
  1484. sio.irq = 0;
  1485. sio.flags = portp->flags;
  1486. sio.baud_base = portp->baud_base;
  1487. sio.close_delay = portp->close_delay;
  1488. sio.closing_wait = portp->closing_wait;
  1489. sio.custom_divisor = portp->custom_divisor;
  1490. sio.xmit_fifo_size = 0;
  1491. sio.hub6 = 0;
  1492. brdp = stli_brds[portp->brdnr];
  1493. if (brdp != NULL)
  1494. sio.port = brdp->iobase;
  1495. return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
  1496. -EFAULT : 0;
  1497. }
  1498. /*****************************************************************************/
  1499. /*
  1500. * Set port according to the serial struct info.
  1501. * At this point we do not do any auto-configure stuff, so we will
  1502. * just quietly ignore any requests to change irq, etc.
  1503. */
  1504. static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
  1505. {
  1506. struct serial_struct sio;
  1507. int rc;
  1508. if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
  1509. return -EFAULT;
  1510. if (!capable(CAP_SYS_ADMIN)) {
  1511. if ((sio.baud_base != portp->baud_base) ||
  1512. (sio.close_delay != portp->close_delay) ||
  1513. ((sio.flags & ~ASYNC_USR_MASK) !=
  1514. (portp->flags & ~ASYNC_USR_MASK)))
  1515. return -EPERM;
  1516. }
  1517. portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
  1518. (sio.flags & ASYNC_USR_MASK);
  1519. portp->baud_base = sio.baud_base;
  1520. portp->close_delay = sio.close_delay;
  1521. portp->closing_wait = sio.closing_wait;
  1522. portp->custom_divisor = sio.custom_divisor;
  1523. if ((rc = stli_setport(portp)) < 0)
  1524. return rc;
  1525. return 0;
  1526. }
  1527. /*****************************************************************************/
  1528. static int stli_tiocmget(struct tty_struct *tty, struct file *file)
  1529. {
  1530. stliport_t *portp = tty->driver_data;
  1531. stlibrd_t *brdp;
  1532. int rc;
  1533. if (portp == NULL)
  1534. return -ENODEV;
  1535. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1536. return 0;
  1537. brdp = stli_brds[portp->brdnr];
  1538. if (brdp == NULL)
  1539. return 0;
  1540. if (tty->flags & (1 << TTY_IO_ERROR))
  1541. return -EIO;
  1542. if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
  1543. &portp->asig, sizeof(asysigs_t), 1)) < 0)
  1544. return rc;
  1545. return stli_mktiocm(portp->asig.sigvalue);
  1546. }
  1547. static int stli_tiocmset(struct tty_struct *tty, struct file *file,
  1548. unsigned int set, unsigned int clear)
  1549. {
  1550. stliport_t *portp = tty->driver_data;
  1551. stlibrd_t *brdp;
  1552. int rts = -1, dtr = -1;
  1553. if (portp == NULL)
  1554. return -ENODEV;
  1555. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1556. return 0;
  1557. brdp = stli_brds[portp->brdnr];
  1558. if (brdp == NULL)
  1559. return 0;
  1560. if (tty->flags & (1 << TTY_IO_ERROR))
  1561. return -EIO;
  1562. if (set & TIOCM_RTS)
  1563. rts = 1;
  1564. if (set & TIOCM_DTR)
  1565. dtr = 1;
  1566. if (clear & TIOCM_RTS)
  1567. rts = 0;
  1568. if (clear & TIOCM_DTR)
  1569. dtr = 0;
  1570. stli_mkasysigs(&portp->asig, dtr, rts);
  1571. return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1572. sizeof(asysigs_t), 0);
  1573. }
  1574. static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
  1575. {
  1576. stliport_t *portp;
  1577. stlibrd_t *brdp;
  1578. unsigned int ival;
  1579. int rc;
  1580. void __user *argp = (void __user *)arg;
  1581. portp = tty->driver_data;
  1582. if (portp == NULL)
  1583. return -ENODEV;
  1584. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1585. return 0;
  1586. brdp = stli_brds[portp->brdnr];
  1587. if (brdp == NULL)
  1588. return 0;
  1589. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1590. (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
  1591. if (tty->flags & (1 << TTY_IO_ERROR))
  1592. return -EIO;
  1593. }
  1594. rc = 0;
  1595. switch (cmd) {
  1596. case TIOCGSOFTCAR:
  1597. rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
  1598. (unsigned __user *) arg);
  1599. break;
  1600. case TIOCSSOFTCAR:
  1601. if ((rc = get_user(ival, (unsigned __user *) arg)) == 0)
  1602. tty->termios->c_cflag =
  1603. (tty->termios->c_cflag & ~CLOCAL) |
  1604. (ival ? CLOCAL : 0);
  1605. break;
  1606. case TIOCGSERIAL:
  1607. rc = stli_getserial(portp, argp);
  1608. break;
  1609. case TIOCSSERIAL:
  1610. rc = stli_setserial(portp, argp);
  1611. break;
  1612. case STL_GETPFLAG:
  1613. rc = put_user(portp->pflag, (unsigned __user *)argp);
  1614. break;
  1615. case STL_SETPFLAG:
  1616. if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0)
  1617. stli_setport(portp);
  1618. break;
  1619. case COM_GETPORTSTATS:
  1620. rc = stli_getportstats(portp, argp);
  1621. break;
  1622. case COM_CLRPORTSTATS:
  1623. rc = stli_clrportstats(portp, argp);
  1624. break;
  1625. case TIOCSERCONFIG:
  1626. case TIOCSERGWILD:
  1627. case TIOCSERSWILD:
  1628. case TIOCSERGETLSR:
  1629. case TIOCSERGSTRUCT:
  1630. case TIOCSERGETMULTI:
  1631. case TIOCSERSETMULTI:
  1632. default:
  1633. rc = -ENOIOCTLCMD;
  1634. break;
  1635. }
  1636. return rc;
  1637. }
  1638. /*****************************************************************************/
  1639. /*
  1640. * This routine assumes that we have user context and can sleep.
  1641. * Looks like it is true for the current ttys implementation..!!
  1642. */
  1643. static void stli_settermios(struct tty_struct *tty, struct termios *old)
  1644. {
  1645. stliport_t *portp;
  1646. stlibrd_t *brdp;
  1647. struct termios *tiosp;
  1648. asyport_t aport;
  1649. if (tty == NULL)
  1650. return;
  1651. portp = tty->driver_data;
  1652. if (portp == NULL)
  1653. return;
  1654. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1655. return;
  1656. brdp = stli_brds[portp->brdnr];
  1657. if (brdp == NULL)
  1658. return;
  1659. tiosp = tty->termios;
  1660. if ((tiosp->c_cflag == old->c_cflag) &&
  1661. (tiosp->c_iflag == old->c_iflag))
  1662. return;
  1663. stli_mkasyport(portp, &aport, tiosp);
  1664. stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
  1665. stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
  1666. stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1667. sizeof(asysigs_t), 0);
  1668. if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
  1669. tty->hw_stopped = 0;
  1670. if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
  1671. wake_up_interruptible(&portp->open_wait);
  1672. }
  1673. /*****************************************************************************/
  1674. /*
  1675. * Attempt to flow control who ever is sending us data. We won't really
  1676. * do any flow control action here. We can't directly, and even if we
  1677. * wanted to we would have to send a command to the slave. The slave
  1678. * knows how to flow control, and will do so when its buffers reach its
  1679. * internal high water marks. So what we will do is set a local state
  1680. * bit that will stop us sending any RX data up from the poll routine
  1681. * (which is the place where RX data from the slave is handled).
  1682. */
  1683. static void stli_throttle(struct tty_struct *tty)
  1684. {
  1685. stliport_t *portp = tty->driver_data;
  1686. if (portp == NULL)
  1687. return;
  1688. set_bit(ST_RXSTOP, &portp->state);
  1689. }
  1690. /*****************************************************************************/
  1691. /*
  1692. * Unflow control the device sending us data... That means that all
  1693. * we have to do is clear the RXSTOP state bit. The next poll call
  1694. * will then be able to pass the RX data back up.
  1695. */
  1696. static void stli_unthrottle(struct tty_struct *tty)
  1697. {
  1698. stliport_t *portp = tty->driver_data;
  1699. if (portp == NULL)
  1700. return;
  1701. clear_bit(ST_RXSTOP, &portp->state);
  1702. }
  1703. /*****************************************************************************/
  1704. /*
  1705. * Stop the transmitter.
  1706. */
  1707. static void stli_stop(struct tty_struct *tty)
  1708. {
  1709. }
  1710. /*****************************************************************************/
  1711. /*
  1712. * Start the transmitter again.
  1713. */
  1714. static void stli_start(struct tty_struct *tty)
  1715. {
  1716. }
  1717. /*****************************************************************************/
  1718. /*
  1719. * Scheduler called hang up routine. This is called from the scheduler,
  1720. * not direct from the driver "poll" routine. We can't call it there
  1721. * since the real local hangup code will enable/disable the board and
  1722. * other things that we can't do while handling the poll. Much easier
  1723. * to deal with it some time later (don't really care when, hangups
  1724. * aren't that time critical).
  1725. */
  1726. static void stli_dohangup(void *arg)
  1727. {
  1728. stliport_t *portp = (stliport_t *) arg;
  1729. if (portp->tty != NULL) {
  1730. tty_hangup(portp->tty);
  1731. }
  1732. }
  1733. /*****************************************************************************/
  1734. /*
  1735. * Hangup this port. This is pretty much like closing the port, only
  1736. * a little more brutal. No waiting for data to drain. Shutdown the
  1737. * port and maybe drop signals. This is rather tricky really. We want
  1738. * to close the port as well.
  1739. */
  1740. static void stli_hangup(struct tty_struct *tty)
  1741. {
  1742. stliport_t *portp;
  1743. stlibrd_t *brdp;
  1744. unsigned long flags;
  1745. portp = tty->driver_data;
  1746. if (portp == NULL)
  1747. return;
  1748. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1749. return;
  1750. brdp = stli_brds[portp->brdnr];
  1751. if (brdp == NULL)
  1752. return;
  1753. portp->flags &= ~ASYNC_INITIALIZED;
  1754. if (!test_bit(ST_CLOSING, &portp->state))
  1755. stli_rawclose(brdp, portp, 0, 0);
  1756. spin_lock_irqsave(&stli_lock, flags);
  1757. if (tty->termios->c_cflag & HUPCL) {
  1758. stli_mkasysigs(&portp->asig, 0, 0);
  1759. if (test_bit(ST_CMDING, &portp->state)) {
  1760. set_bit(ST_DOSIGS, &portp->state);
  1761. set_bit(ST_DOFLUSHTX, &portp->state);
  1762. set_bit(ST_DOFLUSHRX, &portp->state);
  1763. } else {
  1764. stli_sendcmd(brdp, portp, A_SETSIGNALSF,
  1765. &portp->asig, sizeof(asysigs_t), 0);
  1766. }
  1767. }
  1768. clear_bit(ST_TXBUSY, &portp->state);
  1769. clear_bit(ST_RXSTOP, &portp->state);
  1770. set_bit(TTY_IO_ERROR, &tty->flags);
  1771. portp->tty = NULL;
  1772. portp->flags &= ~ASYNC_NORMAL_ACTIVE;
  1773. portp->refcount = 0;
  1774. spin_unlock_irqrestore(&stli_lock, flags);
  1775. wake_up_interruptible(&portp->open_wait);
  1776. }
  1777. /*****************************************************************************/
  1778. /*
  1779. * Flush characters from the lower buffer. We may not have user context
  1780. * so we cannot sleep waiting for it to complete. Also we need to check
  1781. * if there is chars for this port in the TX cook buffer, and flush them
  1782. * as well.
  1783. */
  1784. static void stli_flushbuffer(struct tty_struct *tty)
  1785. {
  1786. stliport_t *portp;
  1787. stlibrd_t *brdp;
  1788. unsigned long ftype, flags;
  1789. portp = tty->driver_data;
  1790. if (portp == NULL)
  1791. return;
  1792. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1793. return;
  1794. brdp = stli_brds[portp->brdnr];
  1795. if (brdp == NULL)
  1796. return;
  1797. spin_lock_irqsave(&brd_lock, flags);
  1798. if (tty == stli_txcooktty) {
  1799. stli_txcooktty = NULL;
  1800. stli_txcooksize = 0;
  1801. stli_txcookrealsize = 0;
  1802. }
  1803. if (test_bit(ST_CMDING, &portp->state)) {
  1804. set_bit(ST_DOFLUSHTX, &portp->state);
  1805. } else {
  1806. ftype = FLUSHTX;
  1807. if (test_bit(ST_DOFLUSHRX, &portp->state)) {
  1808. ftype |= FLUSHRX;
  1809. clear_bit(ST_DOFLUSHRX, &portp->state);
  1810. }
  1811. __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
  1812. }
  1813. spin_unlock_irqrestore(&brd_lock, flags);
  1814. tty_wakeup(tty);
  1815. }
  1816. /*****************************************************************************/
  1817. static void stli_breakctl(struct tty_struct *tty, int state)
  1818. {
  1819. stlibrd_t *brdp;
  1820. stliport_t *portp;
  1821. long arg;
  1822. portp = tty->driver_data;
  1823. if (portp == NULL)
  1824. return;
  1825. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1826. return;
  1827. brdp = stli_brds[portp->brdnr];
  1828. if (brdp == NULL)
  1829. return;
  1830. arg = (state == -1) ? BREAKON : BREAKOFF;
  1831. stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
  1832. }
  1833. /*****************************************************************************/
  1834. static void stli_waituntilsent(struct tty_struct *tty, int timeout)
  1835. {
  1836. stliport_t *portp;
  1837. unsigned long tend;
  1838. if (tty == NULL)
  1839. return;
  1840. portp = tty->driver_data;
  1841. if (portp == NULL)
  1842. return;
  1843. if (timeout == 0)
  1844. timeout = HZ;
  1845. tend = jiffies + timeout;
  1846. while (test_bit(ST_TXBUSY, &portp->state)) {
  1847. if (signal_pending(current))
  1848. break;
  1849. msleep_interruptible(20);
  1850. if (time_after_eq(jiffies, tend))
  1851. break;
  1852. }
  1853. }
  1854. /*****************************************************************************/
  1855. static void stli_sendxchar(struct tty_struct *tty, char ch)
  1856. {
  1857. stlibrd_t *brdp;
  1858. stliport_t *portp;
  1859. asyctrl_t actrl;
  1860. portp = tty->driver_data;
  1861. if (portp == NULL)
  1862. return;
  1863. if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
  1864. return;
  1865. brdp = stli_brds[portp->brdnr];
  1866. if (brdp == NULL)
  1867. return;
  1868. memset(&actrl, 0, sizeof(asyctrl_t));
  1869. if (ch == STOP_CHAR(tty)) {
  1870. actrl.rxctrl = CT_STOPFLOW;
  1871. } else if (ch == START_CHAR(tty)) {
  1872. actrl.rxctrl = CT_STARTFLOW;
  1873. } else {
  1874. actrl.txctrl = CT_SENDCHR;
  1875. actrl.tximdch = ch;
  1876. }
  1877. stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
  1878. }
  1879. /*****************************************************************************/
  1880. #define MAXLINE 80
  1881. /*
  1882. * Format info for a specified port. The line is deliberately limited
  1883. * to 80 characters. (If it is too long it will be truncated, if too
  1884. * short then padded with spaces).
  1885. */
  1886. static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos)
  1887. {
  1888. char *sp, *uart;
  1889. int rc, cnt;
  1890. rc = stli_portcmdstats(portp);
  1891. uart = "UNKNOWN";
  1892. if (brdp->state & BST_STARTED) {
  1893. switch (stli_comstats.hwid) {
  1894. case 0: uart = "2681"; break;
  1895. case 1: uart = "SC26198"; break;
  1896. default:uart = "CD1400"; break;
  1897. }
  1898. }
  1899. sp = pos;
  1900. sp += sprintf(sp, "%d: uart:%s ", portnr, uart);
  1901. if ((brdp->state & BST_STARTED) && (rc >= 0)) {
  1902. sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal,
  1903. (int) stli_comstats.rxtotal);
  1904. if (stli_comstats.rxframing)
  1905. sp += sprintf(sp, " fe:%d",
  1906. (int) stli_comstats.rxframing);
  1907. if (stli_comstats.rxparity)
  1908. sp += sprintf(sp, " pe:%d",
  1909. (int) stli_comstats.rxparity);
  1910. if (stli_comstats.rxbreaks)
  1911. sp += sprintf(sp, " brk:%d",
  1912. (int) stli_comstats.rxbreaks);
  1913. if (stli_comstats.rxoverrun)
  1914. sp += sprintf(sp, " oe:%d",
  1915. (int) stli_comstats.rxoverrun);
  1916. cnt = sprintf(sp, "%s%s%s%s%s ",
  1917. (stli_comstats.signals & TIOCM_RTS) ? "|RTS" : "",
  1918. (stli_comstats.signals & TIOCM_CTS) ? "|CTS" : "",
  1919. (stli_comstats.signals & TIOCM_DTR) ? "|DTR" : "",
  1920. (stli_comstats.signals & TIOCM_CD) ? "|DCD" : "",
  1921. (stli_comstats.signals & TIOCM_DSR) ? "|DSR" : "");
  1922. *sp = ' ';
  1923. sp += cnt;
  1924. }
  1925. for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
  1926. *sp++ = ' ';
  1927. if (cnt >= MAXLINE)
  1928. pos[(MAXLINE - 2)] = '+';
  1929. pos[(MAXLINE - 1)] = '\n';
  1930. return(MAXLINE);
  1931. }
  1932. /*****************************************************************************/
  1933. /*
  1934. * Port info, read from the /proc file system.
  1935. */
  1936. static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
  1937. {
  1938. stlibrd_t *brdp;
  1939. stliport_t *portp;
  1940. int brdnr, portnr, totalport;
  1941. int curoff, maxoff;
  1942. char *pos;
  1943. pos = page;
  1944. totalport = 0;
  1945. curoff = 0;
  1946. if (off == 0) {
  1947. pos += sprintf(pos, "%s: version %s", stli_drvtitle,
  1948. stli_drvversion);
  1949. while (pos < (page + MAXLINE - 1))
  1950. *pos++ = ' ';
  1951. *pos++ = '\n';
  1952. }
  1953. curoff = MAXLINE;
  1954. /*
  1955. * We scan through for each board, panel and port. The offset is
  1956. * calculated on the fly, and irrelevant ports are skipped.
  1957. */
  1958. for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
  1959. brdp = stli_brds[brdnr];
  1960. if (brdp == NULL)
  1961. continue;
  1962. if (brdp->state == 0)
  1963. continue;
  1964. maxoff = curoff + (brdp->nrports * MAXLINE);
  1965. if (off >= maxoff) {
  1966. curoff = maxoff;
  1967. continue;
  1968. }
  1969. totalport = brdnr * STL_MAXPORTS;
  1970. for (portnr = 0; (portnr < brdp->nrports); portnr++,
  1971. totalport++) {
  1972. portp = brdp->ports[portnr];
  1973. if (portp == NULL)
  1974. continue;
  1975. if (off >= (curoff += MAXLINE))
  1976. continue;
  1977. if ((pos - page + MAXLINE) > count)
  1978. goto stli_readdone;
  1979. pos += stli_portinfo(brdp, portp, totalport, pos);
  1980. }
  1981. }
  1982. *eof = 1;
  1983. stli_readdone:
  1984. *start = page;
  1985. return(pos - page);
  1986. }
  1987. /*****************************************************************************/
  1988. /*
  1989. * Generic send command routine. This will send a message to the slave,
  1990. * of the specified type with the specified argument. Must be very
  1991. * careful of data that will be copied out from shared memory -
  1992. * containing command results. The command completion is all done from
  1993. * a poll routine that does not have user context. Therefore you cannot
  1994. * copy back directly into user space, or to the kernel stack of a
  1995. * process. This routine does not sleep, so can be called from anywhere.
  1996. *
  1997. * The caller must hold the brd_lock (see also stli_sendcmd the usual
  1998. * entry point)
  1999. */
  2000. static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
  2001. {
  2002. cdkhdr_t __iomem *hdrp;
  2003. cdkctrl_t __iomem *cp;
  2004. unsigned char __iomem *bits;
  2005. unsigned long flags;
  2006. spin_lock_irqsave(&brd_lock, flags);
  2007. if (test_bit(ST_CMDING, &portp->state)) {
  2008. printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
  2009. (int) cmd);
  2010. spin_unlock_irqrestore(&brd_lock, flags);
  2011. return;
  2012. }
  2013. EBRDENABLE(brdp);
  2014. cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  2015. if (size > 0) {
  2016. memcpy_toio((void __iomem *) &(cp->args[0]), arg, size);
  2017. if (copyback) {
  2018. portp->argp = arg;
  2019. portp->argsize = size;
  2020. }
  2021. }
  2022. writel(0, &cp->status);
  2023. writel(cmd, &cp->cmd);
  2024. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2025. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  2026. portp->portidx;
  2027. writeb(readb(bits) | portp->portbit, bits);
  2028. set_bit(ST_CMDING, &portp->state);
  2029. EBRDDISABLE(brdp);
  2030. spin_unlock_irqrestore(&brd_lock, flags);
  2031. }
  2032. static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
  2033. {
  2034. unsigned long flags;
  2035. spin_lock_irqsave(&brd_lock, flags);
  2036. __stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
  2037. spin_unlock_irqrestore(&brd_lock, flags);
  2038. }
  2039. /*****************************************************************************/
  2040. /*
  2041. * Read data from shared memory. This assumes that the shared memory
  2042. * is enabled and that interrupts are off. Basically we just empty out
  2043. * the shared memory buffer into the tty buffer. Must be careful to
  2044. * handle the case where we fill up the tty buffer, but still have
  2045. * more chars to unload.
  2046. */
  2047. static void stli_read(stlibrd_t *brdp, stliport_t *portp)
  2048. {
  2049. cdkasyrq_t __iomem *rp;
  2050. char __iomem *shbuf;
  2051. struct tty_struct *tty;
  2052. unsigned int head, tail, size;
  2053. unsigned int len, stlen;
  2054. if (test_bit(ST_RXSTOP, &portp->state))
  2055. return;
  2056. tty = portp->tty;
  2057. if (tty == NULL)
  2058. return;
  2059. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
  2060. head = (unsigned int) readw(&rp->head);
  2061. if (head != ((unsigned int) readw(&rp->head)))
  2062. head = (unsigned int) readw(&rp->head);
  2063. tail = (unsigned int) readw(&rp->tail);
  2064. size = portp->rxsize;
  2065. if (head >= tail) {
  2066. len = head - tail;
  2067. stlen = len;
  2068. } else {
  2069. len = size - (tail - head);
  2070. stlen = size - tail;
  2071. }
  2072. len = tty_buffer_request_room(tty, len);
  2073. shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset);
  2074. while (len > 0) {
  2075. unsigned char *cptr;
  2076. stlen = MIN(len, stlen);
  2077. tty_prepare_flip_string(tty, &cptr, stlen);
  2078. memcpy_fromio(cptr, shbuf + tail, stlen);
  2079. len -= stlen;
  2080. tail += stlen;
  2081. if (tail >= size) {
  2082. tail = 0;
  2083. stlen = head;
  2084. }
  2085. }
  2086. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
  2087. writew(tail, &rp->tail);
  2088. if (head != tail)
  2089. set_bit(ST_RXING, &portp->state);
  2090. tty_schedule_flip(tty);
  2091. }
  2092. /*****************************************************************************/
  2093. /*
  2094. * Set up and carry out any delayed commands. There is only a small set
  2095. * of slave commands that can be done "off-level". So it is not too
  2096. * difficult to deal with them here.
  2097. */
  2098. static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp)
  2099. {
  2100. int cmd;
  2101. if (test_bit(ST_DOSIGS, &portp->state)) {
  2102. if (test_bit(ST_DOFLUSHTX, &portp->state) &&
  2103. test_bit(ST_DOFLUSHRX, &portp->state))
  2104. cmd = A_SETSIGNALSF;
  2105. else if (test_bit(ST_DOFLUSHTX, &portp->state))
  2106. cmd = A_SETSIGNALSFTX;
  2107. else if (test_bit(ST_DOFLUSHRX, &portp->state))
  2108. cmd = A_SETSIGNALSFRX;
  2109. else
  2110. cmd = A_SETSIGNALS;
  2111. clear_bit(ST_DOFLUSHTX, &portp->state);
  2112. clear_bit(ST_DOFLUSHRX, &portp->state);
  2113. clear_bit(ST_DOSIGS, &portp->state);
  2114. memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig,
  2115. sizeof(asysigs_t));
  2116. writel(0, &cp->status);
  2117. writel(cmd, &cp->cmd);
  2118. set_bit(ST_CMDING, &portp->state);
  2119. } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
  2120. test_bit(ST_DOFLUSHRX, &portp->state)) {
  2121. cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
  2122. cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
  2123. clear_bit(ST_DOFLUSHTX, &portp->state);
  2124. clear_bit(ST_DOFLUSHRX, &portp->state);
  2125. memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int));
  2126. writel(0, &cp->status);
  2127. writel(A_FLUSH, &cp->cmd);
  2128. set_bit(ST_CMDING, &portp->state);
  2129. }
  2130. }
  2131. /*****************************************************************************/
  2132. /*
  2133. * Host command service checking. This handles commands or messages
  2134. * coming from the slave to the host. Must have board shared memory
  2135. * enabled and interrupts off when called. Notice that by servicing the
  2136. * read data last we don't need to change the shared memory pointer
  2137. * during processing (which is a slow IO operation).
  2138. * Return value indicates if this port is still awaiting actions from
  2139. * the slave (like open, command, or even TX data being sent). If 0
  2140. * then port is still busy, otherwise no longer busy.
  2141. */
  2142. static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
  2143. {
  2144. cdkasy_t __iomem *ap;
  2145. cdkctrl_t __iomem *cp;
  2146. struct tty_struct *tty;
  2147. asynotify_t nt;
  2148. unsigned long oldsigs;
  2149. int rc, donerx;
  2150. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  2151. cp = &ap->ctrl;
  2152. /*
  2153. * Check if we are waiting for an open completion message.
  2154. */
  2155. if (test_bit(ST_OPENING, &portp->state)) {
  2156. rc = readl(&cp->openarg);
  2157. if (readb(&cp->open) == 0 && rc != 0) {
  2158. if (rc > 0)
  2159. rc--;
  2160. writel(0, &cp->openarg);
  2161. portp->rc = rc;
  2162. clear_bit(ST_OPENING, &portp->state);
  2163. wake_up_interruptible(&portp->raw_wait);
  2164. }
  2165. }
  2166. /*
  2167. * Check if we are waiting for a close completion message.
  2168. */
  2169. if (test_bit(ST_CLOSING, &portp->state)) {
  2170. rc = (int) readl(&cp->closearg);
  2171. if (readb(&cp->close) == 0 && rc != 0) {
  2172. if (rc > 0)
  2173. rc--;
  2174. writel(0, &cp->closearg);
  2175. portp->rc = rc;
  2176. clear_bit(ST_CLOSING, &portp->state);
  2177. wake_up_interruptible(&portp->raw_wait);
  2178. }
  2179. }
  2180. /*
  2181. * Check if we are waiting for a command completion message. We may
  2182. * need to copy out the command results associated with this command.
  2183. */
  2184. if (test_bit(ST_CMDING, &portp->state)) {
  2185. rc = readl(&cp->status);
  2186. if (readl(&cp->cmd) == 0 && rc != 0) {
  2187. if (rc > 0)
  2188. rc--;
  2189. if (portp->argp != NULL) {
  2190. memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]),
  2191. portp->argsize);
  2192. portp->argp = NULL;
  2193. }
  2194. writel(0, &cp->status);
  2195. portp->rc = rc;
  2196. clear_bit(ST_CMDING, &portp->state);
  2197. stli_dodelaycmd(portp, cp);
  2198. wake_up_interruptible(&portp->raw_wait);
  2199. }
  2200. }
  2201. /*
  2202. * Check for any notification messages ready. This includes lots of
  2203. * different types of events - RX chars ready, RX break received,
  2204. * TX data low or empty in the slave, modem signals changed state.
  2205. */
  2206. donerx = 0;
  2207. if (ap->notify) {
  2208. nt = ap->changed;
  2209. ap->notify = 0;
  2210. tty = portp->tty;
  2211. if (nt.signal & SG_DCD) {
  2212. oldsigs = portp->sigs;
  2213. portp->sigs = stli_mktiocm(nt.sigvalue);
  2214. clear_bit(ST_GETSIGS, &portp->state);
  2215. if ((portp->sigs & TIOCM_CD) &&
  2216. ((oldsigs & TIOCM_CD) == 0))
  2217. wake_up_interruptible(&portp->open_wait);
  2218. if ((oldsigs & TIOCM_CD) &&
  2219. ((portp->sigs & TIOCM_CD) == 0)) {
  2220. if (portp->flags & ASYNC_CHECK_CD) {
  2221. if (tty)
  2222. schedule_work(&portp->tqhangup);
  2223. }
  2224. }
  2225. }
  2226. if (nt.data & DT_TXEMPTY)
  2227. clear_bit(ST_TXBUSY, &portp->state);
  2228. if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
  2229. if (tty != NULL) {
  2230. tty_wakeup(tty);
  2231. EBRDENABLE(brdp);
  2232. wake_up_interruptible(&tty->write_wait);
  2233. }
  2234. }
  2235. if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
  2236. if (tty != NULL) {
  2237. tty_insert_flip_char(tty, 0, TTY_BREAK);
  2238. if (portp->flags & ASYNC_SAK) {
  2239. do_SAK(tty);
  2240. EBRDENABLE(brdp);
  2241. }
  2242. tty_schedule_flip(tty);
  2243. }
  2244. }
  2245. if (nt.data & DT_RXBUSY) {
  2246. donerx++;
  2247. stli_read(brdp, portp);
  2248. }
  2249. }
  2250. /*
  2251. * It might seem odd that we are checking for more RX chars here.
  2252. * But, we need to handle the case where the tty buffer was previously
  2253. * filled, but we had more characters to pass up. The slave will not
  2254. * send any more RX notify messages until the RX buffer has been emptied.
  2255. * But it will leave the service bits on (since the buffer is not empty).
  2256. * So from here we can try to process more RX chars.
  2257. */
  2258. if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
  2259. clear_bit(ST_RXING, &portp->state);
  2260. stli_read(brdp, portp);
  2261. }
  2262. return((test_bit(ST_OPENING, &portp->state) ||
  2263. test_bit(ST_CLOSING, &portp->state) ||
  2264. test_bit(ST_CMDING, &portp->state) ||
  2265. test_bit(ST_TXBUSY, &portp->state) ||
  2266. test_bit(ST_RXING, &portp->state)) ? 0 : 1);
  2267. }
  2268. /*****************************************************************************/
  2269. /*
  2270. * Service all ports on a particular board. Assumes that the boards
  2271. * shared memory is enabled, and that the page pointer is pointed
  2272. * at the cdk header structure.
  2273. */
  2274. static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp)
  2275. {
  2276. stliport_t *portp;
  2277. unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
  2278. unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
  2279. unsigned char __iomem *slavep;
  2280. int bitpos, bitat, bitsize;
  2281. int channr, nrdevs, slavebitchange;
  2282. bitsize = brdp->bitsize;
  2283. nrdevs = brdp->nrdevs;
  2284. /*
  2285. * Check if slave wants any service. Basically we try to do as
  2286. * little work as possible here. There are 2 levels of service
  2287. * bits. So if there is nothing to do we bail early. We check
  2288. * 8 service bits at a time in the inner loop, so we can bypass
  2289. * the lot if none of them want service.
  2290. */
  2291. memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset),
  2292. bitsize);
  2293. memset(&slavebits[0], 0, bitsize);
  2294. slavebitchange = 0;
  2295. for (bitpos = 0; (bitpos < bitsize); bitpos++) {
  2296. if (hostbits[bitpos] == 0)
  2297. continue;
  2298. channr = bitpos * 8;
  2299. for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
  2300. if (hostbits[bitpos] & bitat) {
  2301. portp = brdp->ports[(channr - 1)];
  2302. if (stli_hostcmd(brdp, portp)) {
  2303. slavebitchange++;
  2304. slavebits[bitpos] |= bitat;
  2305. }
  2306. }
  2307. }
  2308. }
  2309. /*
  2310. * If any of the ports are no longer busy then update them in the
  2311. * slave request bits. We need to do this after, since a host port
  2312. * service may initiate more slave requests.
  2313. */
  2314. if (slavebitchange) {
  2315. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2316. slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset;
  2317. for (bitpos = 0; (bitpos < bitsize); bitpos++) {
  2318. if (readb(slavebits + bitpos))
  2319. writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos);
  2320. }
  2321. }
  2322. }
  2323. /*****************************************************************************/
  2324. /*
  2325. * Driver poll routine. This routine polls the boards in use and passes
  2326. * messages back up to host when necessary. This is actually very
  2327. * CPU efficient, since we will always have the kernel poll clock, it
  2328. * adds only a few cycles when idle (since board service can be
  2329. * determined very easily), but when loaded generates no interrupts
  2330. * (with their expensive associated context change).
  2331. */
  2332. static void stli_poll(unsigned long arg)
  2333. {
  2334. cdkhdr_t __iomem *hdrp;
  2335. stlibrd_t *brdp;
  2336. int brdnr;
  2337. stli_timerlist.expires = STLI_TIMEOUT;
  2338. add_timer(&stli_timerlist);
  2339. /*
  2340. * Check each board and do any servicing required.
  2341. */
  2342. for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
  2343. brdp = stli_brds[brdnr];
  2344. if (brdp == NULL)
  2345. continue;
  2346. if ((brdp->state & BST_STARTED) == 0)
  2347. continue;
  2348. spin_lock(&brd_lock);
  2349. EBRDENABLE(brdp);
  2350. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2351. if (readb(&hdrp->hostreq))
  2352. stli_brdpoll(brdp, hdrp);
  2353. EBRDDISABLE(brdp);
  2354. spin_unlock(&brd_lock);
  2355. }
  2356. }
  2357. /*****************************************************************************/
  2358. /*
  2359. * Translate the termios settings into the port setting structure of
  2360. * the slave.
  2361. */
  2362. static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
  2363. {
  2364. memset(pp, 0, sizeof(asyport_t));
  2365. /*
  2366. * Start of by setting the baud, char size, parity and stop bit info.
  2367. */
  2368. pp->baudout = tiosp->c_cflag & CBAUD;
  2369. if (pp->baudout & CBAUDEX) {
  2370. pp->baudout &= ~CBAUDEX;
  2371. if ((pp->baudout < 1) || (pp->baudout > 4))
  2372. tiosp->c_cflag &= ~CBAUDEX;
  2373. else
  2374. pp->baudout += 15;
  2375. }
  2376. pp->baudout = stli_baudrates[pp->baudout];
  2377. if ((tiosp->c_cflag & CBAUD) == B38400) {
  2378. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  2379. pp->baudout = 57600;
  2380. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  2381. pp->baudout = 115200;
  2382. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  2383. pp->baudout = 230400;
  2384. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  2385. pp->baudout = 460800;
  2386. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  2387. pp->baudout = (portp->baud_base / portp->custom_divisor);
  2388. }
  2389. if (pp->baudout > STL_MAXBAUD)
  2390. pp->baudout = STL_MAXBAUD;
  2391. pp->baudin = pp->baudout;
  2392. switch (tiosp->c_cflag & CSIZE) {
  2393. case CS5:
  2394. pp->csize = 5;
  2395. break;
  2396. case CS6:
  2397. pp->csize = 6;
  2398. break;
  2399. case CS7:
  2400. pp->csize = 7;
  2401. break;
  2402. default:
  2403. pp->csize = 8;
  2404. break;
  2405. }
  2406. if (tiosp->c_cflag & CSTOPB)
  2407. pp->stopbs = PT_STOP2;
  2408. else
  2409. pp->stopbs = PT_STOP1;
  2410. if (tiosp->c_cflag & PARENB) {
  2411. if (tiosp->c_cflag & PARODD)
  2412. pp->parity = PT_ODDPARITY;
  2413. else
  2414. pp->parity = PT_EVENPARITY;
  2415. } else {
  2416. pp->parity = PT_NOPARITY;
  2417. }
  2418. /*
  2419. * Set up any flow control options enabled.
  2420. */
  2421. if (tiosp->c_iflag & IXON) {
  2422. pp->flow |= F_IXON;
  2423. if (tiosp->c_iflag & IXANY)
  2424. pp->flow |= F_IXANY;
  2425. }
  2426. if (tiosp->c_cflag & CRTSCTS)
  2427. pp->flow |= (F_RTSFLOW | F_CTSFLOW);
  2428. pp->startin = tiosp->c_cc[VSTART];
  2429. pp->stopin = tiosp->c_cc[VSTOP];
  2430. pp->startout = tiosp->c_cc[VSTART];
  2431. pp->stopout = tiosp->c_cc[VSTOP];
  2432. /*
  2433. * Set up the RX char marking mask with those RX error types we must
  2434. * catch. We can get the slave to help us out a little here, it will
  2435. * ignore parity errors and breaks for us, and mark parity errors in
  2436. * the data stream.
  2437. */
  2438. if (tiosp->c_iflag & IGNPAR)
  2439. pp->iflag |= FI_IGNRXERRS;
  2440. if (tiosp->c_iflag & IGNBRK)
  2441. pp->iflag |= FI_IGNBREAK;
  2442. portp->rxmarkmsk = 0;
  2443. if (tiosp->c_iflag & (INPCK | PARMRK))
  2444. pp->iflag |= FI_1MARKRXERRS;
  2445. if (tiosp->c_iflag & BRKINT)
  2446. portp->rxmarkmsk |= BRKINT;
  2447. /*
  2448. * Set up clocal processing as required.
  2449. */
  2450. if (tiosp->c_cflag & CLOCAL)
  2451. portp->flags &= ~ASYNC_CHECK_CD;
  2452. else
  2453. portp->flags |= ASYNC_CHECK_CD;
  2454. /*
  2455. * Transfer any persistent flags into the asyport structure.
  2456. */
  2457. pp->pflag = (portp->pflag & 0xffff);
  2458. pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
  2459. pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
  2460. pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
  2461. }
  2462. /*****************************************************************************/
  2463. /*
  2464. * Construct a slave signals structure for setting the DTR and RTS
  2465. * signals as specified.
  2466. */
  2467. static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
  2468. {
  2469. memset(sp, 0, sizeof(asysigs_t));
  2470. if (dtr >= 0) {
  2471. sp->signal |= SG_DTR;
  2472. sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
  2473. }
  2474. if (rts >= 0) {
  2475. sp->signal |= SG_RTS;
  2476. sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
  2477. }
  2478. }
  2479. /*****************************************************************************/
  2480. /*
  2481. * Convert the signals returned from the slave into a local TIOCM type
  2482. * signals value. We keep them locally in TIOCM format.
  2483. */
  2484. static long stli_mktiocm(unsigned long sigvalue)
  2485. {
  2486. long tiocm = 0;
  2487. tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
  2488. tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
  2489. tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
  2490. tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
  2491. tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
  2492. tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
  2493. return(tiocm);
  2494. }
  2495. /*****************************************************************************/
  2496. /*
  2497. * All panels and ports actually attached have been worked out. All
  2498. * we need to do here is set up the appropriate per port data structures.
  2499. */
  2500. static int stli_initports(stlibrd_t *brdp)
  2501. {
  2502. stliport_t *portp;
  2503. int i, panelnr, panelport;
  2504. for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
  2505. portp = kzalloc(sizeof(stliport_t), GFP_KERNEL);
  2506. if (!portp) {
  2507. printk("STALLION: failed to allocate port structure\n");
  2508. continue;
  2509. }
  2510. portp->magic = STLI_PORTMAGIC;
  2511. portp->portnr = i;
  2512. portp->brdnr = brdp->brdnr;
  2513. portp->panelnr = panelnr;
  2514. portp->baud_base = STL_BAUDBASE;
  2515. portp->close_delay = STL_CLOSEDELAY;
  2516. portp->closing_wait = 30 * HZ;
  2517. INIT_WORK(&portp->tqhangup, stli_dohangup, portp);
  2518. init_waitqueue_head(&portp->open_wait);
  2519. init_waitqueue_head(&portp->close_wait);
  2520. init_waitqueue_head(&portp->raw_wait);
  2521. panelport++;
  2522. if (panelport >= brdp->panels[panelnr]) {
  2523. panelport = 0;
  2524. panelnr++;
  2525. }
  2526. brdp->ports[i] = portp;
  2527. }
  2528. return 0;
  2529. }
  2530. /*****************************************************************************/
  2531. /*
  2532. * All the following routines are board specific hardware operations.
  2533. */
  2534. static void stli_ecpinit(stlibrd_t *brdp)
  2535. {
  2536. unsigned long memconf;
  2537. outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
  2538. udelay(10);
  2539. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2540. udelay(100);
  2541. memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
  2542. outb(memconf, (brdp->iobase + ECP_ATMEMAR));
  2543. }
  2544. /*****************************************************************************/
  2545. static void stli_ecpenable(stlibrd_t *brdp)
  2546. {
  2547. outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
  2548. }
  2549. /*****************************************************************************/
  2550. static void stli_ecpdisable(stlibrd_t *brdp)
  2551. {
  2552. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2553. }
  2554. /*****************************************************************************/
  2555. static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2556. {
  2557. void *ptr;
  2558. unsigned char val;
  2559. if (offset > brdp->memsize) {
  2560. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2561. "range at line=%d(%d), brd=%d\n",
  2562. (int) offset, line, __LINE__, brdp->brdnr);
  2563. ptr = NULL;
  2564. val = 0;
  2565. } else {
  2566. ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
  2567. val = (unsigned char) (offset / ECP_ATPAGESIZE);
  2568. }
  2569. outb(val, (brdp->iobase + ECP_ATMEMPR));
  2570. return(ptr);
  2571. }
  2572. /*****************************************************************************/
  2573. static void stli_ecpreset(stlibrd_t *brdp)
  2574. {
  2575. outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
  2576. udelay(10);
  2577. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2578. udelay(500);
  2579. }
  2580. /*****************************************************************************/
  2581. static void stli_ecpintr(stlibrd_t *brdp)
  2582. {
  2583. outb(0x1, brdp->iobase);
  2584. }
  2585. /*****************************************************************************/
  2586. /*
  2587. * The following set of functions act on ECP EISA boards.
  2588. */
  2589. static void stli_ecpeiinit(stlibrd_t *brdp)
  2590. {
  2591. unsigned long memconf;
  2592. outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
  2593. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  2594. udelay(10);
  2595. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2596. udelay(500);
  2597. memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
  2598. outb(memconf, (brdp->iobase + ECP_EIMEMARL));
  2599. memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
  2600. outb(memconf, (brdp->iobase + ECP_EIMEMARH));
  2601. }
  2602. /*****************************************************************************/
  2603. static void stli_ecpeienable(stlibrd_t *brdp)
  2604. {
  2605. outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
  2606. }
  2607. /*****************************************************************************/
  2608. static void stli_ecpeidisable(stlibrd_t *brdp)
  2609. {
  2610. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2611. }
  2612. /*****************************************************************************/
  2613. static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2614. {
  2615. void *ptr;
  2616. unsigned char val;
  2617. if (offset > brdp->memsize) {
  2618. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2619. "range at line=%d(%d), brd=%d\n",
  2620. (int) offset, line, __LINE__, brdp->brdnr);
  2621. ptr = NULL;
  2622. val = 0;
  2623. } else {
  2624. ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
  2625. if (offset < ECP_EIPAGESIZE)
  2626. val = ECP_EIENABLE;
  2627. else
  2628. val = ECP_EIENABLE | 0x40;
  2629. }
  2630. outb(val, (brdp->iobase + ECP_EICONFR));
  2631. return(ptr);
  2632. }
  2633. /*****************************************************************************/
  2634. static void stli_ecpeireset(stlibrd_t *brdp)
  2635. {
  2636. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  2637. udelay(10);
  2638. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2639. udelay(500);
  2640. }
  2641. /*****************************************************************************/
  2642. /*
  2643. * The following set of functions act on ECP MCA boards.
  2644. */
  2645. static void stli_ecpmcenable(stlibrd_t *brdp)
  2646. {
  2647. outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
  2648. }
  2649. /*****************************************************************************/
  2650. static void stli_ecpmcdisable(stlibrd_t *brdp)
  2651. {
  2652. outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
  2653. }
  2654. /*****************************************************************************/
  2655. static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2656. {
  2657. void *ptr;
  2658. unsigned char val;
  2659. if (offset > brdp->memsize) {
  2660. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2661. "range at line=%d(%d), brd=%d\n",
  2662. (int) offset, line, __LINE__, brdp->brdnr);
  2663. ptr = NULL;
  2664. val = 0;
  2665. } else {
  2666. ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
  2667. val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
  2668. }
  2669. outb(val, (brdp->iobase + ECP_MCCONFR));
  2670. return(ptr);
  2671. }
  2672. /*****************************************************************************/
  2673. static void stli_ecpmcreset(stlibrd_t *brdp)
  2674. {
  2675. outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
  2676. udelay(10);
  2677. outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
  2678. udelay(500);
  2679. }
  2680. /*****************************************************************************/
  2681. /*
  2682. * The following set of functions act on ECP PCI boards.
  2683. */
  2684. static void stli_ecppciinit(stlibrd_t *brdp)
  2685. {
  2686. outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
  2687. udelay(10);
  2688. outb(0, (brdp->iobase + ECP_PCICONFR));
  2689. udelay(500);
  2690. }
  2691. /*****************************************************************************/
  2692. static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2693. {
  2694. void *ptr;
  2695. unsigned char val;
  2696. if (offset > brdp->memsize) {
  2697. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2698. "range at line=%d(%d), board=%d\n",
  2699. (int) offset, line, __LINE__, brdp->brdnr);
  2700. ptr = NULL;
  2701. val = 0;
  2702. } else {
  2703. ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
  2704. val = (offset / ECP_PCIPAGESIZE) << 1;
  2705. }
  2706. outb(val, (brdp->iobase + ECP_PCICONFR));
  2707. return(ptr);
  2708. }
  2709. /*****************************************************************************/
  2710. static void stli_ecppcireset(stlibrd_t *brdp)
  2711. {
  2712. outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
  2713. udelay(10);
  2714. outb(0, (brdp->iobase + ECP_PCICONFR));
  2715. udelay(500);
  2716. }
  2717. /*****************************************************************************/
  2718. /*
  2719. * The following routines act on ONboards.
  2720. */
  2721. static void stli_onbinit(stlibrd_t *brdp)
  2722. {
  2723. unsigned long memconf;
  2724. outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
  2725. udelay(10);
  2726. outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
  2727. mdelay(1000);
  2728. memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
  2729. outb(memconf, (brdp->iobase + ONB_ATMEMAR));
  2730. outb(0x1, brdp->iobase);
  2731. mdelay(1);
  2732. }
  2733. /*****************************************************************************/
  2734. static void stli_onbenable(stlibrd_t *brdp)
  2735. {
  2736. outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
  2737. }
  2738. /*****************************************************************************/
  2739. static void stli_onbdisable(stlibrd_t *brdp)
  2740. {
  2741. outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
  2742. }
  2743. /*****************************************************************************/
  2744. static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2745. {
  2746. void *ptr;
  2747. if (offset > brdp->memsize) {
  2748. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2749. "range at line=%d(%d), brd=%d\n",
  2750. (int) offset, line, __LINE__, brdp->brdnr);
  2751. ptr = NULL;
  2752. } else {
  2753. ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
  2754. }
  2755. return(ptr);
  2756. }
  2757. /*****************************************************************************/
  2758. static void stli_onbreset(stlibrd_t *brdp)
  2759. {
  2760. outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
  2761. udelay(10);
  2762. outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
  2763. mdelay(1000);
  2764. }
  2765. /*****************************************************************************/
  2766. /*
  2767. * The following routines act on ONboard EISA.
  2768. */
  2769. static void stli_onbeinit(stlibrd_t *brdp)
  2770. {
  2771. unsigned long memconf;
  2772. outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
  2773. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  2774. udelay(10);
  2775. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  2776. mdelay(1000);
  2777. memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
  2778. outb(memconf, (brdp->iobase + ONB_EIMEMARL));
  2779. memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
  2780. outb(memconf, (brdp->iobase + ONB_EIMEMARH));
  2781. outb(0x1, brdp->iobase);
  2782. mdelay(1);
  2783. }
  2784. /*****************************************************************************/
  2785. static void stli_onbeenable(stlibrd_t *brdp)
  2786. {
  2787. outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
  2788. }
  2789. /*****************************************************************************/
  2790. static void stli_onbedisable(stlibrd_t *brdp)
  2791. {
  2792. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  2793. }
  2794. /*****************************************************************************/
  2795. static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2796. {
  2797. void *ptr;
  2798. unsigned char val;
  2799. if (offset > brdp->memsize) {
  2800. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2801. "range at line=%d(%d), brd=%d\n",
  2802. (int) offset, line, __LINE__, brdp->brdnr);
  2803. ptr = NULL;
  2804. val = 0;
  2805. } else {
  2806. ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
  2807. if (offset < ONB_EIPAGESIZE)
  2808. val = ONB_EIENABLE;
  2809. else
  2810. val = ONB_EIENABLE | 0x40;
  2811. }
  2812. outb(val, (brdp->iobase + ONB_EICONFR));
  2813. return(ptr);
  2814. }
  2815. /*****************************************************************************/
  2816. static void stli_onbereset(stlibrd_t *brdp)
  2817. {
  2818. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  2819. udelay(10);
  2820. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  2821. mdelay(1000);
  2822. }
  2823. /*****************************************************************************/
  2824. /*
  2825. * The following routines act on Brumby boards.
  2826. */
  2827. static void stli_bbyinit(stlibrd_t *brdp)
  2828. {
  2829. outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
  2830. udelay(10);
  2831. outb(0, (brdp->iobase + BBY_ATCONFR));
  2832. mdelay(1000);
  2833. outb(0x1, brdp->iobase);
  2834. mdelay(1);
  2835. }
  2836. /*****************************************************************************/
  2837. static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2838. {
  2839. void *ptr;
  2840. unsigned char val;
  2841. BUG_ON(offset > brdp->memsize);
  2842. ptr = brdp->membase + (offset % BBY_PAGESIZE);
  2843. val = (unsigned char) (offset / BBY_PAGESIZE);
  2844. outb(val, (brdp->iobase + BBY_ATCONFR));
  2845. return(ptr);
  2846. }
  2847. /*****************************************************************************/
  2848. static void stli_bbyreset(stlibrd_t *brdp)
  2849. {
  2850. outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
  2851. udelay(10);
  2852. outb(0, (brdp->iobase + BBY_ATCONFR));
  2853. mdelay(1000);
  2854. }
  2855. /*****************************************************************************/
  2856. /*
  2857. * The following routines act on original old Stallion boards.
  2858. */
  2859. static void stli_stalinit(stlibrd_t *brdp)
  2860. {
  2861. outb(0x1, brdp->iobase);
  2862. mdelay(1000);
  2863. }
  2864. /*****************************************************************************/
  2865. static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2866. {
  2867. BUG_ON(offset > brdp->memsize);
  2868. return brdp->membase + (offset % STAL_PAGESIZE);
  2869. }
  2870. /*****************************************************************************/
  2871. static void stli_stalreset(stlibrd_t *brdp)
  2872. {
  2873. u32 __iomem *vecp;
  2874. vecp = (u32 __iomem *) (brdp->membase + 0x30);
  2875. writel(0xffff0000, vecp);
  2876. outb(0, brdp->iobase);
  2877. mdelay(1000);
  2878. }
  2879. /*****************************************************************************/
  2880. /*
  2881. * Try to find an ECP board and initialize it. This handles only ECP
  2882. * board types.
  2883. */
  2884. static int stli_initecp(stlibrd_t *brdp)
  2885. {
  2886. cdkecpsig_t sig;
  2887. cdkecpsig_t __iomem *sigsp;
  2888. unsigned int status, nxtid;
  2889. char *name;
  2890. int panelnr, nrports;
  2891. if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
  2892. return -EIO;
  2893. if ((brdp->iobase == 0) || (brdp->memaddr == 0))
  2894. {
  2895. release_region(brdp->iobase, brdp->iosize);
  2896. return -ENODEV;
  2897. }
  2898. brdp->iosize = ECP_IOSIZE;
  2899. /*
  2900. * Based on the specific board type setup the common vars to access
  2901. * and enable shared memory. Set all board specific information now
  2902. * as well.
  2903. */
  2904. switch (brdp->brdtype) {
  2905. case BRD_ECP:
  2906. brdp->membase = (void *) brdp->memaddr;
  2907. brdp->memsize = ECP_MEMSIZE;
  2908. brdp->pagesize = ECP_ATPAGESIZE;
  2909. brdp->init = stli_ecpinit;
  2910. brdp->enable = stli_ecpenable;
  2911. brdp->reenable = stli_ecpenable;
  2912. brdp->disable = stli_ecpdisable;
  2913. brdp->getmemptr = stli_ecpgetmemptr;
  2914. brdp->intr = stli_ecpintr;
  2915. brdp->reset = stli_ecpreset;
  2916. name = "serial(EC8/64)";
  2917. break;
  2918. case BRD_ECPE:
  2919. brdp->membase = (void *) brdp->memaddr;
  2920. brdp->memsize = ECP_MEMSIZE;
  2921. brdp->pagesize = ECP_EIPAGESIZE;
  2922. brdp->init = stli_ecpeiinit;
  2923. brdp->enable = stli_ecpeienable;
  2924. brdp->reenable = stli_ecpeienable;
  2925. brdp->disable = stli_ecpeidisable;
  2926. brdp->getmemptr = stli_ecpeigetmemptr;
  2927. brdp->intr = stli_ecpintr;
  2928. brdp->reset = stli_ecpeireset;
  2929. name = "serial(EC8/64-EI)";
  2930. break;
  2931. case BRD_ECPMC:
  2932. brdp->membase = (void *) brdp->memaddr;
  2933. brdp->memsize = ECP_MEMSIZE;
  2934. brdp->pagesize = ECP_MCPAGESIZE;
  2935. brdp->init = NULL;
  2936. brdp->enable = stli_ecpmcenable;
  2937. brdp->reenable = stli_ecpmcenable;
  2938. brdp->disable = stli_ecpmcdisable;
  2939. brdp->getmemptr = stli_ecpmcgetmemptr;
  2940. brdp->intr = stli_ecpintr;
  2941. brdp->reset = stli_ecpmcreset;
  2942. name = "serial(EC8/64-MCA)";
  2943. break;
  2944. case BRD_ECPPCI:
  2945. brdp->membase = (void *) brdp->memaddr;
  2946. brdp->memsize = ECP_PCIMEMSIZE;
  2947. brdp->pagesize = ECP_PCIPAGESIZE;
  2948. brdp->init = stli_ecppciinit;
  2949. brdp->enable = NULL;
  2950. brdp->reenable = NULL;
  2951. brdp->disable = NULL;
  2952. brdp->getmemptr = stli_ecppcigetmemptr;
  2953. brdp->intr = stli_ecpintr;
  2954. brdp->reset = stli_ecppcireset;
  2955. name = "serial(EC/RA-PCI)";
  2956. break;
  2957. default:
  2958. release_region(brdp->iobase, brdp->iosize);
  2959. return -EINVAL;
  2960. }
  2961. /*
  2962. * The per-board operations structure is all set up, so now let's go
  2963. * and get the board operational. Firstly initialize board configuration
  2964. * registers. Set the memory mapping info so we can get at the boards
  2965. * shared memory.
  2966. */
  2967. EBRDINIT(brdp);
  2968. brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
  2969. if (brdp->membase == NULL)
  2970. {
  2971. release_region(brdp->iobase, brdp->iosize);
  2972. return -ENOMEM;
  2973. }
  2974. /*
  2975. * Now that all specific code is set up, enable the shared memory and
  2976. * look for the a signature area that will tell us exactly what board
  2977. * this is, and what it is connected to it.
  2978. */
  2979. EBRDENABLE(brdp);
  2980. sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
  2981. memcpy_fromio(&sig, sigsp, sizeof(cdkecpsig_t));
  2982. EBRDDISABLE(brdp);
  2983. if (sig.magic != cpu_to_le32(ECP_MAGIC))
  2984. {
  2985. release_region(brdp->iobase, brdp->iosize);
  2986. return -ENODEV;
  2987. }
  2988. /*
  2989. * Scan through the signature looking at the panels connected to the
  2990. * board. Calculate the total number of ports as we go.
  2991. */
  2992. for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
  2993. status = sig.panelid[nxtid];
  2994. if ((status & ECH_PNLIDMASK) != nxtid)
  2995. break;
  2996. brdp->panelids[panelnr] = status;
  2997. nrports = (status & ECH_PNL16PORT) ? 16 : 8;
  2998. if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
  2999. nxtid++;
  3000. brdp->panels[panelnr] = nrports;
  3001. brdp->nrports += nrports;
  3002. nxtid++;
  3003. brdp->nrpanels++;
  3004. }
  3005. brdp->state |= BST_FOUND;
  3006. return 0;
  3007. }
  3008. /*****************************************************************************/
  3009. /*
  3010. * Try to find an ONboard, Brumby or Stallion board and initialize it.
  3011. * This handles only these board types.
  3012. */
  3013. static int stli_initonb(stlibrd_t *brdp)
  3014. {
  3015. cdkonbsig_t sig;
  3016. cdkonbsig_t __iomem *sigsp;
  3017. char *name;
  3018. int i;
  3019. /*
  3020. * Do a basic sanity check on the IO and memory addresses.
  3021. */
  3022. if (brdp->iobase == 0 || brdp->memaddr == 0)
  3023. return -ENODEV;
  3024. brdp->iosize = ONB_IOSIZE;
  3025. if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
  3026. return -EIO;
  3027. /*
  3028. * Based on the specific board type setup the common vars to access
  3029. * and enable shared memory. Set all board specific information now
  3030. * as well.
  3031. */
  3032. switch (brdp->brdtype) {
  3033. case BRD_ONBOARD:
  3034. case BRD_ONBOARD32:
  3035. case BRD_ONBOARD2:
  3036. case BRD_ONBOARD2_32:
  3037. case BRD_ONBOARDRS:
  3038. brdp->memsize = ONB_MEMSIZE;
  3039. brdp->pagesize = ONB_ATPAGESIZE;
  3040. brdp->init = stli_onbinit;
  3041. brdp->enable = stli_onbenable;
  3042. brdp->reenable = stli_onbenable;
  3043. brdp->disable = stli_onbdisable;
  3044. brdp->getmemptr = stli_onbgetmemptr;
  3045. brdp->intr = stli_ecpintr;
  3046. brdp->reset = stli_onbreset;
  3047. if (brdp->memaddr > 0x100000)
  3048. brdp->enabval = ONB_MEMENABHI;
  3049. else
  3050. brdp->enabval = ONB_MEMENABLO;
  3051. name = "serial(ONBoard)";
  3052. break;
  3053. case BRD_ONBOARDE:
  3054. brdp->memsize = ONB_EIMEMSIZE;
  3055. brdp->pagesize = ONB_EIPAGESIZE;
  3056. brdp->init = stli_onbeinit;
  3057. brdp->enable = stli_onbeenable;
  3058. brdp->reenable = stli_onbeenable;
  3059. brdp->disable = stli_onbedisable;
  3060. brdp->getmemptr = stli_onbegetmemptr;
  3061. brdp->intr = stli_ecpintr;
  3062. brdp->reset = stli_onbereset;
  3063. name = "serial(ONBoard/E)";
  3064. break;
  3065. case BRD_BRUMBY4:
  3066. case BRD_BRUMBY8:
  3067. case BRD_BRUMBY16:
  3068. brdp->memsize = BBY_MEMSIZE;
  3069. brdp->pagesize = BBY_PAGESIZE;
  3070. brdp->init = stli_bbyinit;
  3071. brdp->enable = NULL;
  3072. brdp->reenable = NULL;
  3073. brdp->disable = NULL;
  3074. brdp->getmemptr = stli_bbygetmemptr;
  3075. brdp->intr = stli_ecpintr;
  3076. brdp->reset = stli_bbyreset;
  3077. name = "serial(Brumby)";
  3078. break;
  3079. case BRD_STALLION:
  3080. brdp->memsize = STAL_MEMSIZE;
  3081. brdp->pagesize = STAL_PAGESIZE;
  3082. brdp->init = stli_stalinit;
  3083. brdp->enable = NULL;
  3084. brdp->reenable = NULL;
  3085. brdp->disable = NULL;
  3086. brdp->getmemptr = stli_stalgetmemptr;
  3087. brdp->intr = stli_ecpintr;
  3088. brdp->reset = stli_stalreset;
  3089. name = "serial(Stallion)";
  3090. break;
  3091. default:
  3092. release_region(brdp->iobase, brdp->iosize);
  3093. return -EINVAL;
  3094. }
  3095. /*
  3096. * The per-board operations structure is all set up, so now let's go
  3097. * and get the board operational. Firstly initialize board configuration
  3098. * registers. Set the memory mapping info so we can get at the boards
  3099. * shared memory.
  3100. */
  3101. EBRDINIT(brdp);
  3102. brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
  3103. if (brdp->membase == NULL)
  3104. {
  3105. release_region(brdp->iobase, brdp->iosize);
  3106. return -ENOMEM;
  3107. }
  3108. /*
  3109. * Now that all specific code is set up, enable the shared memory and
  3110. * look for the a signature area that will tell us exactly what board
  3111. * this is, and how many ports.
  3112. */
  3113. EBRDENABLE(brdp);
  3114. sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
  3115. memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t));
  3116. EBRDDISABLE(brdp);
  3117. if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
  3118. sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
  3119. sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
  3120. sig.magic3 != cpu_to_le16(ONB_MAGIC3))
  3121. {
  3122. release_region(brdp->iobase, brdp->iosize);
  3123. return -ENODEV;
  3124. }
  3125. /*
  3126. * Scan through the signature alive mask and calculate how many ports
  3127. * there are on this board.
  3128. */
  3129. brdp->nrpanels = 1;
  3130. if (sig.amask1) {
  3131. brdp->nrports = 32;
  3132. } else {
  3133. for (i = 0; (i < 16); i++) {
  3134. if (((sig.amask0 << i) & 0x8000) == 0)
  3135. break;
  3136. }
  3137. brdp->nrports = i;
  3138. }
  3139. brdp->panels[0] = brdp->nrports;
  3140. brdp->state |= BST_FOUND;
  3141. return 0;
  3142. }
  3143. /*****************************************************************************/
  3144. /*
  3145. * Start up a running board. This routine is only called after the
  3146. * code has been down loaded to the board and is operational. It will
  3147. * read in the memory map, and get the show on the road...
  3148. */
  3149. static int stli_startbrd(stlibrd_t *brdp)
  3150. {
  3151. cdkhdr_t __iomem *hdrp;
  3152. cdkmem_t __iomem *memp;
  3153. cdkasy_t __iomem *ap;
  3154. unsigned long flags;
  3155. stliport_t *portp;
  3156. int portnr, nrdevs, i, rc = 0;
  3157. u32 memoff;
  3158. spin_lock_irqsave(&brd_lock, flags);
  3159. EBRDENABLE(brdp);
  3160. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  3161. nrdevs = hdrp->nrdevs;
  3162. #if 0
  3163. printk("%s(%d): CDK version %d.%d.%d --> "
  3164. "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
  3165. __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification),
  3166. readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp),
  3167. readl(&hdrp->slavep));
  3168. #endif
  3169. if (nrdevs < (brdp->nrports + 1)) {
  3170. printk(KERN_ERR "STALLION: slave failed to allocate memory for "
  3171. "all devices, devices=%d\n", nrdevs);
  3172. brdp->nrports = nrdevs - 1;
  3173. }
  3174. brdp->nrdevs = nrdevs;
  3175. brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
  3176. brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
  3177. brdp->bitsize = (nrdevs + 7) / 8;
  3178. memoff = readl(&hdrp->memp);
  3179. if (memoff > brdp->memsize) {
  3180. printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
  3181. rc = -EIO;
  3182. goto stli_donestartup;
  3183. }
  3184. memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
  3185. if (readw(&memp->dtype) != TYP_ASYNCTRL) {
  3186. printk(KERN_ERR "STALLION: no slave control device found\n");
  3187. goto stli_donestartup;
  3188. }
  3189. memp++;
  3190. /*
  3191. * Cycle through memory allocation of each port. We are guaranteed to
  3192. * have all ports inside the first page of slave window, so no need to
  3193. * change pages while reading memory map.
  3194. */
  3195. for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
  3196. if (readw(&memp->dtype) != TYP_ASYNC)
  3197. break;
  3198. portp = brdp->ports[portnr];
  3199. if (portp == NULL)
  3200. break;
  3201. portp->devnr = i;
  3202. portp->addr = readl(&memp->offset);
  3203. portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
  3204. portp->portidx = (unsigned char) (i / 8);
  3205. portp->portbit = (unsigned char) (0x1 << (i % 8));
  3206. }
  3207. writeb(0xff, &hdrp->slavereq);
  3208. /*
  3209. * For each port setup a local copy of the RX and TX buffer offsets
  3210. * and sizes. We do this separate from the above, because we need to
  3211. * move the shared memory page...
  3212. */
  3213. for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
  3214. portp = brdp->ports[portnr];
  3215. if (portp == NULL)
  3216. break;
  3217. if (portp->addr == 0)
  3218. break;
  3219. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  3220. if (ap != NULL) {
  3221. portp->rxsize = readw(&ap->rxq.size);
  3222. portp->txsize = readw(&ap->txq.size);
  3223. portp->rxoffset = readl(&ap->rxq.offset);
  3224. portp->txoffset = readl(&ap->txq.offset);
  3225. }
  3226. }
  3227. stli_donestartup:
  3228. EBRDDISABLE(brdp);
  3229. spin_unlock_irqrestore(&brd_lock, flags);
  3230. if (rc == 0)
  3231. brdp->state |= BST_STARTED;
  3232. if (! stli_timeron) {
  3233. stli_timeron++;
  3234. stli_timerlist.expires = STLI_TIMEOUT;
  3235. add_timer(&stli_timerlist);
  3236. }
  3237. return rc;
  3238. }
  3239. /*****************************************************************************/
  3240. /*
  3241. * Probe and initialize the specified board.
  3242. */
  3243. static int __init stli_brdinit(stlibrd_t *brdp)
  3244. {
  3245. stli_brds[brdp->brdnr] = brdp;
  3246. switch (brdp->brdtype) {
  3247. case BRD_ECP:
  3248. case BRD_ECPE:
  3249. case BRD_ECPMC:
  3250. case BRD_ECPPCI:
  3251. stli_initecp(brdp);
  3252. break;
  3253. case BRD_ONBOARD:
  3254. case BRD_ONBOARDE:
  3255. case BRD_ONBOARD2:
  3256. case BRD_ONBOARD32:
  3257. case BRD_ONBOARD2_32:
  3258. case BRD_ONBOARDRS:
  3259. case BRD_BRUMBY4:
  3260. case BRD_BRUMBY8:
  3261. case BRD_BRUMBY16:
  3262. case BRD_STALLION:
  3263. stli_initonb(brdp);
  3264. break;
  3265. case BRD_EASYIO:
  3266. case BRD_ECH:
  3267. case BRD_ECHMC:
  3268. case BRD_ECHPCI:
  3269. printk(KERN_ERR "STALLION: %s board type not supported in "
  3270. "this driver\n", stli_brdnames[brdp->brdtype]);
  3271. return -ENODEV;
  3272. default:
  3273. printk(KERN_ERR "STALLION: board=%d is unknown board "
  3274. "type=%d\n", brdp->brdnr, brdp->brdtype);
  3275. return -ENODEV;
  3276. }
  3277. if ((brdp->state & BST_FOUND) == 0) {
  3278. printk(KERN_ERR "STALLION: %s board not found, board=%d "
  3279. "io=%x mem=%x\n",
  3280. stli_brdnames[brdp->brdtype], brdp->brdnr,
  3281. brdp->iobase, (int) brdp->memaddr);
  3282. return -ENODEV;
  3283. }
  3284. stli_initports(brdp);
  3285. printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
  3286. "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
  3287. brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
  3288. brdp->nrpanels, brdp->nrports);
  3289. return 0;
  3290. }
  3291. /*****************************************************************************/
  3292. /*
  3293. * Probe around trying to find where the EISA boards shared memory
  3294. * might be. This is a bit if hack, but it is the best we can do.
  3295. */
  3296. static int stli_eisamemprobe(stlibrd_t *brdp)
  3297. {
  3298. cdkecpsig_t ecpsig, __iomem *ecpsigp;
  3299. cdkonbsig_t onbsig, __iomem *onbsigp;
  3300. int i, foundit;
  3301. /*
  3302. * First up we reset the board, to get it into a known state. There
  3303. * is only 2 board types here we need to worry about. Don;t use the
  3304. * standard board init routine here, it programs up the shared
  3305. * memory address, and we don't know it yet...
  3306. */
  3307. if (brdp->brdtype == BRD_ECPE) {
  3308. outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
  3309. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  3310. udelay(10);
  3311. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  3312. udelay(500);
  3313. stli_ecpeienable(brdp);
  3314. } else if (brdp->brdtype == BRD_ONBOARDE) {
  3315. outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
  3316. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  3317. udelay(10);
  3318. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  3319. mdelay(100);
  3320. outb(0x1, brdp->iobase);
  3321. mdelay(1);
  3322. stli_onbeenable(brdp);
  3323. } else {
  3324. return -ENODEV;
  3325. }
  3326. foundit = 0;
  3327. brdp->memsize = ECP_MEMSIZE;
  3328. /*
  3329. * Board shared memory is enabled, so now we have a poke around and
  3330. * see if we can find it.
  3331. */
  3332. for (i = 0; (i < stli_eisamempsize); i++) {
  3333. brdp->memaddr = stli_eisamemprobeaddrs[i];
  3334. brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
  3335. if (brdp->membase == NULL)
  3336. continue;
  3337. if (brdp->brdtype == BRD_ECPE) {
  3338. ecpsigp = (cdkecpsig_t __iomem *) stli_ecpeigetmemptr(brdp,
  3339. CDK_SIGADDR, __LINE__);
  3340. memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
  3341. if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
  3342. foundit = 1;
  3343. } else {
  3344. onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp,
  3345. CDK_SIGADDR, __LINE__);
  3346. memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t));
  3347. if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) &&
  3348. (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) &&
  3349. (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) &&
  3350. (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3)))
  3351. foundit = 1;
  3352. }
  3353. iounmap(brdp->membase);
  3354. if (foundit)
  3355. break;
  3356. }
  3357. /*
  3358. * Regardless of whether we found the shared memory or not we must
  3359. * disable the region. After that return success or failure.
  3360. */
  3361. if (brdp->brdtype == BRD_ECPE)
  3362. stli_ecpeidisable(brdp);
  3363. else
  3364. stli_onbedisable(brdp);
  3365. if (! foundit) {
  3366. brdp->memaddr = 0;
  3367. brdp->membase = NULL;
  3368. printk(KERN_ERR "STALLION: failed to probe shared memory "
  3369. "region for %s in EISA slot=%d\n",
  3370. stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
  3371. return -ENODEV;
  3372. }
  3373. return 0;
  3374. }
  3375. static int stli_getbrdnr(void)
  3376. {
  3377. int i;
  3378. for (i = 0; i < STL_MAXBRDS; i++) {
  3379. if (!stli_brds[i]) {
  3380. if (i >= stli_nrbrds)
  3381. stli_nrbrds = i + 1;
  3382. return i;
  3383. }
  3384. }
  3385. return -1;
  3386. }
  3387. /*****************************************************************************/
  3388. /*
  3389. * Probe around and try to find any EISA boards in system. The biggest
  3390. * problem here is finding out what memory address is associated with
  3391. * an EISA board after it is found. The registers of the ECPE and
  3392. * ONboardE are not readable - so we can't read them from there. We
  3393. * don't have access to the EISA CMOS (or EISA BIOS) so we don't
  3394. * actually have any way to find out the real value. The best we can
  3395. * do is go probing around in the usual places hoping we can find it.
  3396. */
  3397. static int stli_findeisabrds(void)
  3398. {
  3399. stlibrd_t *brdp;
  3400. unsigned int iobase, eid;
  3401. int i;
  3402. /*
  3403. * Firstly check if this is an EISA system. If this is not an EISA system then
  3404. * don't bother going any further!
  3405. */
  3406. if (EISA_bus)
  3407. return 0;
  3408. /*
  3409. * Looks like an EISA system, so go searching for EISA boards.
  3410. */
  3411. for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
  3412. outb(0xff, (iobase + 0xc80));
  3413. eid = inb(iobase + 0xc80);
  3414. eid |= inb(iobase + 0xc81) << 8;
  3415. if (eid != STL_EISAID)
  3416. continue;
  3417. /*
  3418. * We have found a board. Need to check if this board was
  3419. * statically configured already (just in case!).
  3420. */
  3421. for (i = 0; (i < STL_MAXBRDS); i++) {
  3422. brdp = stli_brds[i];
  3423. if (brdp == NULL)
  3424. continue;
  3425. if (brdp->iobase == iobase)
  3426. break;
  3427. }
  3428. if (i < STL_MAXBRDS)
  3429. continue;
  3430. /*
  3431. * We have found a Stallion board and it is not configured already.
  3432. * Allocate a board structure and initialize it.
  3433. */
  3434. if ((brdp = stli_allocbrd()) == NULL)
  3435. return -ENOMEM;
  3436. if ((brdp->brdnr = stli_getbrdnr()) < 0)
  3437. return -ENOMEM;
  3438. eid = inb(iobase + 0xc82);
  3439. if (eid == ECP_EISAID)
  3440. brdp->brdtype = BRD_ECPE;
  3441. else if (eid == ONB_EISAID)
  3442. brdp->brdtype = BRD_ONBOARDE;
  3443. else
  3444. brdp->brdtype = BRD_UNKNOWN;
  3445. brdp->iobase = iobase;
  3446. outb(0x1, (iobase + 0xc84));
  3447. if (stli_eisamemprobe(brdp))
  3448. outb(0, (iobase + 0xc84));
  3449. stli_brdinit(brdp);
  3450. }
  3451. return 0;
  3452. }
  3453. /*****************************************************************************/
  3454. /*
  3455. * Find the next available board number that is free.
  3456. */
  3457. /*****************************************************************************/
  3458. #ifdef CONFIG_PCI
  3459. /*
  3460. * We have a Stallion board. Allocate a board structure and
  3461. * initialize it. Read its IO and MEMORY resources from PCI
  3462. * configuration space.
  3463. */
  3464. static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
  3465. {
  3466. stlibrd_t *brdp;
  3467. if (pci_enable_device(devp))
  3468. return -EIO;
  3469. if ((brdp = stli_allocbrd()) == NULL)
  3470. return -ENOMEM;
  3471. if ((brdp->brdnr = stli_getbrdnr()) < 0) {
  3472. printk(KERN_INFO "STALLION: too many boards found, "
  3473. "maximum supported %d\n", STL_MAXBRDS);
  3474. return 0;
  3475. }
  3476. brdp->brdtype = brdtype;
  3477. /*
  3478. * We have all resources from the board, so lets setup the actual
  3479. * board structure now.
  3480. */
  3481. brdp->iobase = pci_resource_start(devp, 3);
  3482. brdp->memaddr = pci_resource_start(devp, 2);
  3483. stli_brdinit(brdp);
  3484. return 0;
  3485. }
  3486. /*****************************************************************************/
  3487. /*
  3488. * Find all Stallion PCI boards that might be installed. Initialize each
  3489. * one as it is found.
  3490. */
  3491. static int stli_findpcibrds(void)
  3492. {
  3493. struct pci_dev *dev = NULL;
  3494. while ((dev = pci_get_device(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, dev))) {
  3495. stli_initpcibrd(BRD_ECPPCI, dev);
  3496. }
  3497. return 0;
  3498. }
  3499. #endif
  3500. /*****************************************************************************/
  3501. /*
  3502. * Allocate a new board structure. Fill out the basic info in it.
  3503. */
  3504. static stlibrd_t *stli_allocbrd(void)
  3505. {
  3506. stlibrd_t *brdp;
  3507. brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL);
  3508. if (!brdp) {
  3509. printk(KERN_ERR "STALLION: failed to allocate memory "
  3510. "(size=%Zd)\n", sizeof(stlibrd_t));
  3511. return NULL;
  3512. }
  3513. brdp->magic = STLI_BOARDMAGIC;
  3514. return brdp;
  3515. }
  3516. /*****************************************************************************/
  3517. /*
  3518. * Scan through all the boards in the configuration and see what we
  3519. * can find.
  3520. */
  3521. static int stli_initbrds(void)
  3522. {
  3523. stlibrd_t *brdp, *nxtbrdp;
  3524. stlconf_t *confp;
  3525. int i, j;
  3526. if (stli_nrbrds > STL_MAXBRDS) {
  3527. printk(KERN_INFO "STALLION: too many boards in configuration "
  3528. "table, truncating to %d\n", STL_MAXBRDS);
  3529. stli_nrbrds = STL_MAXBRDS;
  3530. }
  3531. /*
  3532. * Firstly scan the list of static boards configured. Allocate
  3533. * resources and initialize the boards as found. If this is a
  3534. * module then let the module args override static configuration.
  3535. */
  3536. for (i = 0; (i < stli_nrbrds); i++) {
  3537. confp = &stli_brdconf[i];
  3538. stli_parsebrd(confp, stli_brdsp[i]);
  3539. if ((brdp = stli_allocbrd()) == NULL)
  3540. return -ENOMEM;
  3541. brdp->brdnr = i;
  3542. brdp->brdtype = confp->brdtype;
  3543. brdp->iobase = confp->ioaddr1;
  3544. brdp->memaddr = confp->memaddr;
  3545. stli_brdinit(brdp);
  3546. }
  3547. /*
  3548. * Static configuration table done, so now use dynamic methods to
  3549. * see if any more boards should be configured.
  3550. */
  3551. stli_argbrds();
  3552. if (STLI_EISAPROBE)
  3553. stli_findeisabrds();
  3554. #ifdef CONFIG_PCI
  3555. stli_findpcibrds();
  3556. #endif
  3557. /*
  3558. * All found boards are initialized. Now for a little optimization, if
  3559. * no boards are sharing the "shared memory" regions then we can just
  3560. * leave them all enabled. This is in fact the usual case.
  3561. */
  3562. stli_shared = 0;
  3563. if (stli_nrbrds > 1) {
  3564. for (i = 0; (i < stli_nrbrds); i++) {
  3565. brdp = stli_brds[i];
  3566. if (brdp == NULL)
  3567. continue;
  3568. for (j = i + 1; (j < stli_nrbrds); j++) {
  3569. nxtbrdp = stli_brds[j];
  3570. if (nxtbrdp == NULL)
  3571. continue;
  3572. if ((brdp->membase >= nxtbrdp->membase) &&
  3573. (brdp->membase <= (nxtbrdp->membase +
  3574. nxtbrdp->memsize - 1))) {
  3575. stli_shared++;
  3576. break;
  3577. }
  3578. }
  3579. }
  3580. }
  3581. if (stli_shared == 0) {
  3582. for (i = 0; (i < stli_nrbrds); i++) {
  3583. brdp = stli_brds[i];
  3584. if (brdp == NULL)
  3585. continue;
  3586. if (brdp->state & BST_FOUND) {
  3587. EBRDENABLE(brdp);
  3588. brdp->enable = NULL;
  3589. brdp->disable = NULL;
  3590. }
  3591. }
  3592. }
  3593. return 0;
  3594. }
  3595. /*****************************************************************************/
  3596. /*
  3597. * Code to handle an "staliomem" read operation. This device is the
  3598. * contents of the board shared memory. It is used for down loading
  3599. * the slave image (and debugging :-)
  3600. */
  3601. static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
  3602. {
  3603. unsigned long flags;
  3604. void *memptr;
  3605. stlibrd_t *brdp;
  3606. int brdnr, size, n;
  3607. void *p;
  3608. loff_t off = *offp;
  3609. brdnr = iminor(fp->f_dentry->d_inode);
  3610. if (brdnr >= stli_nrbrds)
  3611. return -ENODEV;
  3612. brdp = stli_brds[brdnr];
  3613. if (brdp == NULL)
  3614. return -ENODEV;
  3615. if (brdp->state == 0)
  3616. return -ENODEV;
  3617. if (off >= brdp->memsize || off + count < off)
  3618. return 0;
  3619. size = MIN(count, (brdp->memsize - off));
  3620. /*
  3621. * Copy the data a page at a time
  3622. */
  3623. p = (void *)__get_free_page(GFP_KERNEL);
  3624. if(p == NULL)
  3625. return -ENOMEM;
  3626. while (size > 0) {
  3627. spin_lock_irqsave(&brd_lock, flags);
  3628. EBRDENABLE(brdp);
  3629. memptr = (void *) EBRDGETMEMPTR(brdp, off);
  3630. n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
  3631. n = MIN(n, PAGE_SIZE);
  3632. memcpy_fromio(p, memptr, n);
  3633. EBRDDISABLE(brdp);
  3634. spin_unlock_irqrestore(&brd_lock, flags);
  3635. if (copy_to_user(buf, p, n)) {
  3636. count = -EFAULT;
  3637. goto out;
  3638. }
  3639. off += n;
  3640. buf += n;
  3641. size -= n;
  3642. }
  3643. out:
  3644. *offp = off;
  3645. free_page((unsigned long)p);
  3646. return count;
  3647. }
  3648. /*****************************************************************************/
  3649. /*
  3650. * Code to handle an "staliomem" write operation. This device is the
  3651. * contents of the board shared memory. It is used for down loading
  3652. * the slave image (and debugging :-)
  3653. *
  3654. * FIXME: copy under lock
  3655. */
  3656. static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
  3657. {
  3658. unsigned long flags;
  3659. void *memptr;
  3660. stlibrd_t *brdp;
  3661. char __user *chbuf;
  3662. int brdnr, size, n;
  3663. void *p;
  3664. loff_t off = *offp;
  3665. brdnr = iminor(fp->f_dentry->d_inode);
  3666. if (brdnr >= stli_nrbrds)
  3667. return -ENODEV;
  3668. brdp = stli_brds[brdnr];
  3669. if (brdp == NULL)
  3670. return -ENODEV;
  3671. if (brdp->state == 0)
  3672. return -ENODEV;
  3673. if (off >= brdp->memsize || off + count < off)
  3674. return 0;
  3675. chbuf = (char __user *) buf;
  3676. size = MIN(count, (brdp->memsize - off));
  3677. /*
  3678. * Copy the data a page at a time
  3679. */
  3680. p = (void *)__get_free_page(GFP_KERNEL);
  3681. if(p == NULL)
  3682. return -ENOMEM;
  3683. while (size > 0) {
  3684. n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
  3685. n = MIN(n, PAGE_SIZE);
  3686. if (copy_from_user(p, chbuf, n)) {
  3687. if (count == 0)
  3688. count = -EFAULT;
  3689. goto out;
  3690. }
  3691. spin_lock_irqsave(&brd_lock, flags);
  3692. EBRDENABLE(brdp);
  3693. memptr = (void *) EBRDGETMEMPTR(brdp, off);
  3694. memcpy_toio(memptr, p, n);
  3695. EBRDDISABLE(brdp);
  3696. spin_unlock_irqrestore(&brd_lock, flags);
  3697. off += n;
  3698. chbuf += n;
  3699. size -= n;
  3700. }
  3701. out:
  3702. free_page((unsigned long) p);
  3703. *offp = off;
  3704. return count;
  3705. }
  3706. /*****************************************************************************/
  3707. /*
  3708. * Return the board stats structure to user app.
  3709. */
  3710. static int stli_getbrdstats(combrd_t __user *bp)
  3711. {
  3712. stlibrd_t *brdp;
  3713. int i;
  3714. if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
  3715. return -EFAULT;
  3716. if (stli_brdstats.brd >= STL_MAXBRDS)
  3717. return -ENODEV;
  3718. brdp = stli_brds[stli_brdstats.brd];
  3719. if (brdp == NULL)
  3720. return -ENODEV;
  3721. memset(&stli_brdstats, 0, sizeof(combrd_t));
  3722. stli_brdstats.brd = brdp->brdnr;
  3723. stli_brdstats.type = brdp->brdtype;
  3724. stli_brdstats.hwid = 0;
  3725. stli_brdstats.state = brdp->state;
  3726. stli_brdstats.ioaddr = brdp->iobase;
  3727. stli_brdstats.memaddr = brdp->memaddr;
  3728. stli_brdstats.nrpanels = brdp->nrpanels;
  3729. stli_brdstats.nrports = brdp->nrports;
  3730. for (i = 0; (i < brdp->nrpanels); i++) {
  3731. stli_brdstats.panels[i].panel = i;
  3732. stli_brdstats.panels[i].hwid = brdp->panelids[i];
  3733. stli_brdstats.panels[i].nrports = brdp->panels[i];
  3734. }
  3735. if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
  3736. return -EFAULT;
  3737. return 0;
  3738. }
  3739. /*****************************************************************************/
  3740. /*
  3741. * Resolve the referenced port number into a port struct pointer.
  3742. */
  3743. static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
  3744. {
  3745. stlibrd_t *brdp;
  3746. int i;
  3747. if (brdnr < 0 || brdnr >= STL_MAXBRDS)
  3748. return NULL;
  3749. brdp = stli_brds[brdnr];
  3750. if (brdp == NULL)
  3751. return NULL;
  3752. for (i = 0; (i < panelnr); i++)
  3753. portnr += brdp->panels[i];
  3754. if ((portnr < 0) || (portnr >= brdp->nrports))
  3755. return NULL;
  3756. return brdp->ports[portnr];
  3757. }
  3758. /*****************************************************************************/
  3759. /*
  3760. * Return the port stats structure to user app. A NULL port struct
  3761. * pointer passed in means that we need to find out from the app
  3762. * what port to get stats for (used through board control device).
  3763. */
  3764. static int stli_portcmdstats(stliport_t *portp)
  3765. {
  3766. unsigned long flags;
  3767. stlibrd_t *brdp;
  3768. int rc;
  3769. memset(&stli_comstats, 0, sizeof(comstats_t));
  3770. if (portp == NULL)
  3771. return -ENODEV;
  3772. brdp = stli_brds[portp->brdnr];
  3773. if (brdp == NULL)
  3774. return -ENODEV;
  3775. if (brdp->state & BST_STARTED) {
  3776. if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
  3777. &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
  3778. return rc;
  3779. } else {
  3780. memset(&stli_cdkstats, 0, sizeof(asystats_t));
  3781. }
  3782. stli_comstats.brd = portp->brdnr;
  3783. stli_comstats.panel = portp->panelnr;
  3784. stli_comstats.port = portp->portnr;
  3785. stli_comstats.state = portp->state;
  3786. stli_comstats.flags = portp->flags;
  3787. spin_lock_irqsave(&brd_lock, flags);
  3788. if (portp->tty != NULL) {
  3789. if (portp->tty->driver_data == portp) {
  3790. stli_comstats.ttystate = portp->tty->flags;
  3791. stli_comstats.rxbuffered = -1;
  3792. if (portp->tty->termios != NULL) {
  3793. stli_comstats.cflags = portp->tty->termios->c_cflag;
  3794. stli_comstats.iflags = portp->tty->termios->c_iflag;
  3795. stli_comstats.oflags = portp->tty->termios->c_oflag;
  3796. stli_comstats.lflags = portp->tty->termios->c_lflag;
  3797. }
  3798. }
  3799. }
  3800. spin_unlock_irqrestore(&brd_lock, flags);
  3801. stli_comstats.txtotal = stli_cdkstats.txchars;
  3802. stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
  3803. stli_comstats.txbuffered = stli_cdkstats.txringq;
  3804. stli_comstats.rxbuffered += stli_cdkstats.rxringq;
  3805. stli_comstats.rxoverrun = stli_cdkstats.overruns;
  3806. stli_comstats.rxparity = stli_cdkstats.parity;
  3807. stli_comstats.rxframing = stli_cdkstats.framing;
  3808. stli_comstats.rxlost = stli_cdkstats.ringover;
  3809. stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
  3810. stli_comstats.txbreaks = stli_cdkstats.txbreaks;
  3811. stli_comstats.txxon = stli_cdkstats.txstart;
  3812. stli_comstats.txxoff = stli_cdkstats.txstop;
  3813. stli_comstats.rxxon = stli_cdkstats.rxstart;
  3814. stli_comstats.rxxoff = stli_cdkstats.rxstop;
  3815. stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
  3816. stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
  3817. stli_comstats.modem = stli_cdkstats.dcdcnt;
  3818. stli_comstats.hwid = stli_cdkstats.hwid;
  3819. stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
  3820. return 0;
  3821. }
  3822. /*****************************************************************************/
  3823. /*
  3824. * Return the port stats structure to user app. A NULL port struct
  3825. * pointer passed in means that we need to find out from the app
  3826. * what port to get stats for (used through board control device).
  3827. */
  3828. static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
  3829. {
  3830. stlibrd_t *brdp;
  3831. int rc;
  3832. if (!portp) {
  3833. if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
  3834. return -EFAULT;
  3835. portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
  3836. stli_comstats.port);
  3837. if (!portp)
  3838. return -ENODEV;
  3839. }
  3840. brdp = stli_brds[portp->brdnr];
  3841. if (!brdp)
  3842. return -ENODEV;
  3843. if ((rc = stli_portcmdstats(portp)) < 0)
  3844. return rc;
  3845. return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
  3846. -EFAULT : 0;
  3847. }
  3848. /*****************************************************************************/
  3849. /*
  3850. * Clear the port stats structure. We also return it zeroed out...
  3851. */
  3852. static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
  3853. {
  3854. stlibrd_t *brdp;
  3855. int rc;
  3856. if (!portp) {
  3857. if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
  3858. return -EFAULT;
  3859. portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
  3860. stli_comstats.port);
  3861. if (!portp)
  3862. return -ENODEV;
  3863. }
  3864. brdp = stli_brds[portp->brdnr];
  3865. if (!brdp)
  3866. return -ENODEV;
  3867. if (brdp->state & BST_STARTED) {
  3868. if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0)
  3869. return rc;
  3870. }
  3871. memset(&stli_comstats, 0, sizeof(comstats_t));
  3872. stli_comstats.brd = portp->brdnr;
  3873. stli_comstats.panel = portp->panelnr;
  3874. stli_comstats.port = portp->portnr;
  3875. if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
  3876. return -EFAULT;
  3877. return 0;
  3878. }
  3879. /*****************************************************************************/
  3880. /*
  3881. * Return the entire driver ports structure to a user app.
  3882. */
  3883. static int stli_getportstruct(stliport_t __user *arg)
  3884. {
  3885. stliport_t *portp;
  3886. if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t)))
  3887. return -EFAULT;
  3888. portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
  3889. stli_dummyport.portnr);
  3890. if (!portp)
  3891. return -ENODEV;
  3892. if (copy_to_user(arg, portp, sizeof(stliport_t)))
  3893. return -EFAULT;
  3894. return 0;
  3895. }
  3896. /*****************************************************************************/
  3897. /*
  3898. * Return the entire driver board structure to a user app.
  3899. */
  3900. static int stli_getbrdstruct(stlibrd_t __user *arg)
  3901. {
  3902. stlibrd_t *brdp;
  3903. if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t)))
  3904. return -EFAULT;
  3905. if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS))
  3906. return -ENODEV;
  3907. brdp = stli_brds[stli_dummybrd.brdnr];
  3908. if (!brdp)
  3909. return -ENODEV;
  3910. if (copy_to_user(arg, brdp, sizeof(stlibrd_t)))
  3911. return -EFAULT;
  3912. return 0;
  3913. }
  3914. /*****************************************************************************/
  3915. /*
  3916. * The "staliomem" device is also required to do some special operations on
  3917. * the board. We need to be able to send an interrupt to the board,
  3918. * reset it, and start/stop it.
  3919. */
  3920. static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
  3921. {
  3922. stlibrd_t *brdp;
  3923. int brdnr, rc, done;
  3924. void __user *argp = (void __user *)arg;
  3925. /*
  3926. * First up handle the board independent ioctls.
  3927. */
  3928. done = 0;
  3929. rc = 0;
  3930. switch (cmd) {
  3931. case COM_GETPORTSTATS:
  3932. rc = stli_getportstats(NULL, argp);
  3933. done++;
  3934. break;
  3935. case COM_CLRPORTSTATS:
  3936. rc = stli_clrportstats(NULL, argp);
  3937. done++;
  3938. break;
  3939. case COM_GETBRDSTATS:
  3940. rc = stli_getbrdstats(argp);
  3941. done++;
  3942. break;
  3943. case COM_READPORT:
  3944. rc = stli_getportstruct(argp);
  3945. done++;
  3946. break;
  3947. case COM_READBOARD:
  3948. rc = stli_getbrdstruct(argp);
  3949. done++;
  3950. break;
  3951. }
  3952. if (done)
  3953. return rc;
  3954. /*
  3955. * Now handle the board specific ioctls. These all depend on the
  3956. * minor number of the device they were called from.
  3957. */
  3958. brdnr = iminor(ip);
  3959. if (brdnr >= STL_MAXBRDS)
  3960. return -ENODEV;
  3961. brdp = stli_brds[brdnr];
  3962. if (!brdp)
  3963. return -ENODEV;
  3964. if (brdp->state == 0)
  3965. return -ENODEV;
  3966. switch (cmd) {
  3967. case STL_BINTR:
  3968. EBRDINTR(brdp);
  3969. break;
  3970. case STL_BSTART:
  3971. rc = stli_startbrd(brdp);
  3972. break;
  3973. case STL_BSTOP:
  3974. brdp->state &= ~BST_STARTED;
  3975. break;
  3976. case STL_BRESET:
  3977. brdp->state &= ~BST_STARTED;
  3978. EBRDRESET(brdp);
  3979. if (stli_shared == 0) {
  3980. if (brdp->reenable != NULL)
  3981. (* brdp->reenable)(brdp);
  3982. }
  3983. break;
  3984. default:
  3985. rc = -ENOIOCTLCMD;
  3986. break;
  3987. }
  3988. return rc;
  3989. }
  3990. static struct tty_operations stli_ops = {
  3991. .open = stli_open,
  3992. .close = stli_close,
  3993. .write = stli_write,
  3994. .put_char = stli_putchar,
  3995. .flush_chars = stli_flushchars,
  3996. .write_room = stli_writeroom,
  3997. .chars_in_buffer = stli_charsinbuffer,
  3998. .ioctl = stli_ioctl,
  3999. .set_termios = stli_settermios,
  4000. .throttle = stli_throttle,
  4001. .unthrottle = stli_unthrottle,
  4002. .stop = stli_stop,
  4003. .start = stli_start,
  4004. .hangup = stli_hangup,
  4005. .flush_buffer = stli_flushbuffer,
  4006. .break_ctl = stli_breakctl,
  4007. .wait_until_sent = stli_waituntilsent,
  4008. .send_xchar = stli_sendxchar,
  4009. .read_proc = stli_readproc,
  4010. .tiocmget = stli_tiocmget,
  4011. .tiocmset = stli_tiocmset,
  4012. };
  4013. /*****************************************************************************/
  4014. static int __init stli_init(void)
  4015. {
  4016. int i;
  4017. printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
  4018. spin_lock_init(&stli_lock);
  4019. spin_lock_init(&brd_lock);
  4020. stli_initbrds();
  4021. stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
  4022. if (!stli_serial)
  4023. return -ENOMEM;
  4024. /*
  4025. * Allocate a temporary write buffer.
  4026. */
  4027. stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
  4028. if (!stli_txcookbuf)
  4029. printk(KERN_ERR "STALLION: failed to allocate memory "
  4030. "(size=%d)\n", STLI_TXBUFSIZE);
  4031. /*
  4032. * Set up a character driver for the shared memory region. We need this
  4033. * to down load the slave code image. Also it is a useful debugging tool.
  4034. */
  4035. if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
  4036. printk(KERN_ERR "STALLION: failed to register serial memory "
  4037. "device\n");
  4038. istallion_class = class_create(THIS_MODULE, "staliomem");
  4039. for (i = 0; i < 4; i++)
  4040. class_device_create(istallion_class, NULL,
  4041. MKDEV(STL_SIOMEMMAJOR, i),
  4042. NULL, "staliomem%d", i);
  4043. /*
  4044. * Set up the tty driver structure and register us as a driver.
  4045. */
  4046. stli_serial->owner = THIS_MODULE;
  4047. stli_serial->driver_name = stli_drvname;
  4048. stli_serial->name = stli_serialname;
  4049. stli_serial->major = STL_SERIALMAJOR;
  4050. stli_serial->minor_start = 0;
  4051. stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
  4052. stli_serial->subtype = SERIAL_TYPE_NORMAL;
  4053. stli_serial->init_termios = stli_deftermios;
  4054. stli_serial->flags = TTY_DRIVER_REAL_RAW;
  4055. tty_set_operations(stli_serial, &stli_ops);
  4056. if (tty_register_driver(stli_serial)) {
  4057. put_tty_driver(stli_serial);
  4058. printk(KERN_ERR "STALLION: failed to register serial driver\n");
  4059. return -EBUSY;
  4060. }
  4061. return 0;
  4062. }
  4063. /*****************************************************************************/