stallion.c 123 KB

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