stallion.c 127 KB

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