stallion.c 123 KB

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