stallion.c 123 KB

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