stallion.c 126 KB

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