stallion.c 128 KB

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