stallion.c 124 KB

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