stallion.c 121 KB

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