stallion.c 120 KB

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