stallion.c 121 KB

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