crisv10.c 119 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293
  1. /*
  2. * Serial port driver for the ETRAX 100LX chip
  3. *
  4. * Copyright (C) 1998-2007 Axis Communications AB
  5. *
  6. * Many, many authors. Based once upon a time on serial.c for 16x50.
  7. *
  8. */
  9. static char *serial_version = "$Revision: 1.25 $";
  10. #include <linux/types.h>
  11. #include <linux/errno.h>
  12. #include <linux/signal.h>
  13. #include <linux/sched.h>
  14. #include <linux/timer.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/tty.h>
  17. #include <linux/tty_flip.h>
  18. #include <linux/major.h>
  19. #include <linux/string.h>
  20. #include <linux/fcntl.h>
  21. #include <linux/mm.h>
  22. #include <linux/slab.h>
  23. #include <linux/init.h>
  24. #include <linux/kernel.h>
  25. #include <linux/mutex.h>
  26. #include <linux/bitops.h>
  27. #include <linux/seq_file.h>
  28. #include <linux/delay.h>
  29. #include <linux/module.h>
  30. #include <linux/uaccess.h>
  31. #include <linux/io.h>
  32. #include <asm/irq.h>
  33. #include <asm/dma.h>
  34. #include <arch/svinto.h>
  35. #include <arch/system.h>
  36. /* non-arch dependent serial structures are in linux/serial.h */
  37. #include <linux/serial.h>
  38. /* while we keep our own stuff (struct e100_serial) in a local .h file */
  39. #include "crisv10.h"
  40. #include <asm/fasttimer.h>
  41. #include <arch/io_interface_mux.h>
  42. #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER
  43. #ifndef CONFIG_ETRAX_FAST_TIMER
  44. #error "Enable FAST_TIMER to use SERIAL_FAST_TIMER"
  45. #endif
  46. #endif
  47. #if defined(CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS) && \
  48. (CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS == 0)
  49. #error "RX_TIMEOUT_TICKS == 0 not allowed, use 1"
  50. #endif
  51. /*
  52. * All of the compatibilty code so we can compile serial.c against
  53. * older kernels is hidden in serial_compat.h
  54. */
  55. #if defined(LOCAL_HEADERS)
  56. #include "serial_compat.h"
  57. #endif
  58. struct tty_driver *serial_driver;
  59. /* number of characters left in xmit buffer before we ask for more */
  60. #define WAKEUP_CHARS 256
  61. //#define SERIAL_DEBUG_INTR
  62. //#define SERIAL_DEBUG_OPEN
  63. //#define SERIAL_DEBUG_FLOW
  64. //#define SERIAL_DEBUG_DATA
  65. //#define SERIAL_DEBUG_THROTTLE
  66. //#define SERIAL_DEBUG_IO /* Debug for Extra control and status pins */
  67. //#define SERIAL_DEBUG_LINE 0 /* What serport we want to debug */
  68. /* Enable this to use serial interrupts to handle when you
  69. expect the first received event on the serial port to
  70. be an error, break or similar. Used to be able to flash IRMA
  71. from eLinux */
  72. #define SERIAL_HANDLE_EARLY_ERRORS
  73. /* Currently 16 descriptors x 128 bytes = 2048 bytes */
  74. #define SERIAL_DESCR_BUF_SIZE 256
  75. #define SERIAL_PRESCALE_BASE 3125000 /* 3.125MHz */
  76. #define DEF_BAUD_BASE SERIAL_PRESCALE_BASE
  77. /* We don't want to load the system with massive fast timer interrupt
  78. * on high baudrates so limit it to 250 us (4kHz) */
  79. #define MIN_FLUSH_TIME_USEC 250
  80. /* Add an x here to log a lot of timer stuff */
  81. #define TIMERD(x)
  82. /* Debug details of interrupt handling */
  83. #define DINTR1(x) /* irq on/off, errors */
  84. #define DINTR2(x) /* tx and rx */
  85. /* Debug flip buffer stuff */
  86. #define DFLIP(x)
  87. /* Debug flow control and overview of data flow */
  88. #define DFLOW(x)
  89. #define DBAUD(x)
  90. #define DLOG_INT_TRIG(x)
  91. //#define DEBUG_LOG_INCLUDED
  92. #ifndef DEBUG_LOG_INCLUDED
  93. #define DEBUG_LOG(line, string, value)
  94. #else
  95. struct debug_log_info
  96. {
  97. unsigned long time;
  98. unsigned long timer_data;
  99. // int line;
  100. const char *string;
  101. int value;
  102. };
  103. #define DEBUG_LOG_SIZE 4096
  104. struct debug_log_info debug_log[DEBUG_LOG_SIZE];
  105. int debug_log_pos = 0;
  106. #define DEBUG_LOG(_line, _string, _value) do { \
  107. if ((_line) == SERIAL_DEBUG_LINE) {\
  108. debug_log_func(_line, _string, _value); \
  109. }\
  110. }while(0)
  111. void debug_log_func(int line, const char *string, int value)
  112. {
  113. if (debug_log_pos < DEBUG_LOG_SIZE) {
  114. debug_log[debug_log_pos].time = jiffies;
  115. debug_log[debug_log_pos].timer_data = *R_TIMER_DATA;
  116. // debug_log[debug_log_pos].line = line;
  117. debug_log[debug_log_pos].string = string;
  118. debug_log[debug_log_pos].value = value;
  119. debug_log_pos++;
  120. }
  121. /*printk(string, value);*/
  122. }
  123. #endif
  124. #ifndef CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS
  125. /* Default number of timer ticks before flushing rx fifo
  126. * When using "little data, low latency applications: use 0
  127. * When using "much data applications (PPP)" use ~5
  128. */
  129. #define CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS 5
  130. #endif
  131. unsigned long timer_data_to_ns(unsigned long timer_data);
  132. static void change_speed(struct e100_serial *info);
  133. static void rs_throttle(struct tty_struct * tty);
  134. static void rs_wait_until_sent(struct tty_struct *tty, int timeout);
  135. static int rs_write(struct tty_struct *tty,
  136. const unsigned char *buf, int count);
  137. #ifdef CONFIG_ETRAX_RS485
  138. static int e100_write_rs485(struct tty_struct *tty,
  139. const unsigned char *buf, int count);
  140. #endif
  141. static int get_lsr_info(struct e100_serial *info, unsigned int *value);
  142. #define DEF_BAUD 115200 /* 115.2 kbit/s */
  143. #define DEF_RX 0x20 /* or SERIAL_CTRL_W >> 8 */
  144. /* Default value of tx_ctrl register: has txd(bit 7)=1 (idle) as default */
  145. #define DEF_TX 0x80 /* or SERIAL_CTRL_B */
  146. /* offsets from R_SERIALx_CTRL */
  147. #define REG_DATA 0
  148. #define REG_DATA_STATUS32 0 /* this is the 32 bit register R_SERIALx_READ */
  149. #define REG_TR_DATA 0
  150. #define REG_STATUS 1
  151. #define REG_TR_CTRL 1
  152. #define REG_REC_CTRL 2
  153. #define REG_BAUD 3
  154. #define REG_XOFF 4 /* this is a 32 bit register */
  155. /* The bitfields are the same for all serial ports */
  156. #define SER_RXD_MASK IO_MASK(R_SERIAL0_STATUS, rxd)
  157. #define SER_DATA_AVAIL_MASK IO_MASK(R_SERIAL0_STATUS, data_avail)
  158. #define SER_FRAMING_ERR_MASK IO_MASK(R_SERIAL0_STATUS, framing_err)
  159. #define SER_PAR_ERR_MASK IO_MASK(R_SERIAL0_STATUS, par_err)
  160. #define SER_OVERRUN_MASK IO_MASK(R_SERIAL0_STATUS, overrun)
  161. #define SER_ERROR_MASK (SER_OVERRUN_MASK | SER_PAR_ERR_MASK | SER_FRAMING_ERR_MASK)
  162. /* Values for info->errorcode */
  163. #define ERRCODE_SET_BREAK (TTY_BREAK)
  164. #define ERRCODE_INSERT 0x100
  165. #define ERRCODE_INSERT_BREAK (ERRCODE_INSERT | TTY_BREAK)
  166. #define FORCE_EOP(info) *R_SET_EOP = 1U << info->iseteop;
  167. /*
  168. * General note regarding the use of IO_* macros in this file:
  169. *
  170. * We will use the bits defined for DMA channel 6 when using various
  171. * IO_* macros (e.g. IO_STATE, IO_MASK, IO_EXTRACT) and _assume_ they are
  172. * the same for all channels (which of course they are).
  173. *
  174. * We will also use the bits defined for serial port 0 when writing commands
  175. * to the different ports, as these bits too are the same for all ports.
  176. */
  177. /* Mask for the irqs possibly enabled in R_IRQ_MASK1_RD etc. */
  178. static const unsigned long e100_ser_int_mask = 0
  179. #ifdef CONFIG_ETRAX_SERIAL_PORT0
  180. | IO_MASK(R_IRQ_MASK1_RD, ser0_data) | IO_MASK(R_IRQ_MASK1_RD, ser0_ready)
  181. #endif
  182. #ifdef CONFIG_ETRAX_SERIAL_PORT1
  183. | IO_MASK(R_IRQ_MASK1_RD, ser1_data) | IO_MASK(R_IRQ_MASK1_RD, ser1_ready)
  184. #endif
  185. #ifdef CONFIG_ETRAX_SERIAL_PORT2
  186. | IO_MASK(R_IRQ_MASK1_RD, ser2_data) | IO_MASK(R_IRQ_MASK1_RD, ser2_ready)
  187. #endif
  188. #ifdef CONFIG_ETRAX_SERIAL_PORT3
  189. | IO_MASK(R_IRQ_MASK1_RD, ser3_data) | IO_MASK(R_IRQ_MASK1_RD, ser3_ready)
  190. #endif
  191. ;
  192. unsigned long r_alt_ser_baudrate_shadow = 0;
  193. /* this is the data for the four serial ports in the etrax100 */
  194. /* DMA2(ser2), DMA4(ser3), DMA6(ser0) or DMA8(ser1) */
  195. /* R_DMA_CHx_CLR_INTR, R_DMA_CHx_FIRST, R_DMA_CHx_CMD */
  196. static struct e100_serial rs_table[] = {
  197. { .baud = DEF_BAUD,
  198. .ioport = (unsigned char *)R_SERIAL0_CTRL,
  199. .irq = 1U << 12, /* uses DMA 6 and 7 */
  200. .oclrintradr = R_DMA_CH6_CLR_INTR,
  201. .ofirstadr = R_DMA_CH6_FIRST,
  202. .ocmdadr = R_DMA_CH6_CMD,
  203. .ostatusadr = R_DMA_CH6_STATUS,
  204. .iclrintradr = R_DMA_CH7_CLR_INTR,
  205. .ifirstadr = R_DMA_CH7_FIRST,
  206. .icmdadr = R_DMA_CH7_CMD,
  207. .idescradr = R_DMA_CH7_DESCR,
  208. .rx_ctrl = DEF_RX,
  209. .tx_ctrl = DEF_TX,
  210. .iseteop = 2,
  211. .dma_owner = dma_ser0,
  212. .io_if = if_serial_0,
  213. #ifdef CONFIG_ETRAX_SERIAL_PORT0
  214. .enabled = 1,
  215. #ifdef CONFIG_ETRAX_SERIAL_PORT0_DMA6_OUT
  216. .dma_out_enabled = 1,
  217. .dma_out_nbr = SER0_TX_DMA_NBR,
  218. .dma_out_irq_nbr = SER0_DMA_TX_IRQ_NBR,
  219. .dma_out_irq_flags = 0,
  220. .dma_out_irq_description = "serial 0 dma tr",
  221. #else
  222. .dma_out_enabled = 0,
  223. .dma_out_nbr = UINT_MAX,
  224. .dma_out_irq_nbr = 0,
  225. .dma_out_irq_flags = 0,
  226. .dma_out_irq_description = NULL,
  227. #endif
  228. #ifdef CONFIG_ETRAX_SERIAL_PORT0_DMA7_IN
  229. .dma_in_enabled = 1,
  230. .dma_in_nbr = SER0_RX_DMA_NBR,
  231. .dma_in_irq_nbr = SER0_DMA_RX_IRQ_NBR,
  232. .dma_in_irq_flags = 0,
  233. .dma_in_irq_description = "serial 0 dma rec",
  234. #else
  235. .dma_in_enabled = 0,
  236. .dma_in_nbr = UINT_MAX,
  237. .dma_in_irq_nbr = 0,
  238. .dma_in_irq_flags = 0,
  239. .dma_in_irq_description = NULL,
  240. #endif
  241. #else
  242. .enabled = 0,
  243. .io_if_description = NULL,
  244. .dma_out_enabled = 0,
  245. .dma_in_enabled = 0
  246. #endif
  247. }, /* ttyS0 */
  248. { .baud = DEF_BAUD,
  249. .ioport = (unsigned char *)R_SERIAL1_CTRL,
  250. .irq = 1U << 16, /* uses DMA 8 and 9 */
  251. .oclrintradr = R_DMA_CH8_CLR_INTR,
  252. .ofirstadr = R_DMA_CH8_FIRST,
  253. .ocmdadr = R_DMA_CH8_CMD,
  254. .ostatusadr = R_DMA_CH8_STATUS,
  255. .iclrintradr = R_DMA_CH9_CLR_INTR,
  256. .ifirstadr = R_DMA_CH9_FIRST,
  257. .icmdadr = R_DMA_CH9_CMD,
  258. .idescradr = R_DMA_CH9_DESCR,
  259. .rx_ctrl = DEF_RX,
  260. .tx_ctrl = DEF_TX,
  261. .iseteop = 3,
  262. .dma_owner = dma_ser1,
  263. .io_if = if_serial_1,
  264. #ifdef CONFIG_ETRAX_SERIAL_PORT1
  265. .enabled = 1,
  266. .io_if_description = "ser1",
  267. #ifdef CONFIG_ETRAX_SERIAL_PORT1_DMA8_OUT
  268. .dma_out_enabled = 1,
  269. .dma_out_nbr = SER1_TX_DMA_NBR,
  270. .dma_out_irq_nbr = SER1_DMA_TX_IRQ_NBR,
  271. .dma_out_irq_flags = 0,
  272. .dma_out_irq_description = "serial 1 dma tr",
  273. #else
  274. .dma_out_enabled = 0,
  275. .dma_out_nbr = UINT_MAX,
  276. .dma_out_irq_nbr = 0,
  277. .dma_out_irq_flags = 0,
  278. .dma_out_irq_description = NULL,
  279. #endif
  280. #ifdef CONFIG_ETRAX_SERIAL_PORT1_DMA9_IN
  281. .dma_in_enabled = 1,
  282. .dma_in_nbr = SER1_RX_DMA_NBR,
  283. .dma_in_irq_nbr = SER1_DMA_RX_IRQ_NBR,
  284. .dma_in_irq_flags = 0,
  285. .dma_in_irq_description = "serial 1 dma rec",
  286. #else
  287. .dma_in_enabled = 0,
  288. .dma_in_enabled = 0,
  289. .dma_in_nbr = UINT_MAX,
  290. .dma_in_irq_nbr = 0,
  291. .dma_in_irq_flags = 0,
  292. .dma_in_irq_description = NULL,
  293. #endif
  294. #else
  295. .enabled = 0,
  296. .io_if_description = NULL,
  297. .dma_in_irq_nbr = 0,
  298. .dma_out_enabled = 0,
  299. .dma_in_enabled = 0
  300. #endif
  301. }, /* ttyS1 */
  302. { .baud = DEF_BAUD,
  303. .ioport = (unsigned char *)R_SERIAL2_CTRL,
  304. .irq = 1U << 4, /* uses DMA 2 and 3 */
  305. .oclrintradr = R_DMA_CH2_CLR_INTR,
  306. .ofirstadr = R_DMA_CH2_FIRST,
  307. .ocmdadr = R_DMA_CH2_CMD,
  308. .ostatusadr = R_DMA_CH2_STATUS,
  309. .iclrintradr = R_DMA_CH3_CLR_INTR,
  310. .ifirstadr = R_DMA_CH3_FIRST,
  311. .icmdadr = R_DMA_CH3_CMD,
  312. .idescradr = R_DMA_CH3_DESCR,
  313. .rx_ctrl = DEF_RX,
  314. .tx_ctrl = DEF_TX,
  315. .iseteop = 0,
  316. .dma_owner = dma_ser2,
  317. .io_if = if_serial_2,
  318. #ifdef CONFIG_ETRAX_SERIAL_PORT2
  319. .enabled = 1,
  320. .io_if_description = "ser2",
  321. #ifdef CONFIG_ETRAX_SERIAL_PORT2_DMA2_OUT
  322. .dma_out_enabled = 1,
  323. .dma_out_nbr = SER2_TX_DMA_NBR,
  324. .dma_out_irq_nbr = SER2_DMA_TX_IRQ_NBR,
  325. .dma_out_irq_flags = 0,
  326. .dma_out_irq_description = "serial 2 dma tr",
  327. #else
  328. .dma_out_enabled = 0,
  329. .dma_out_nbr = UINT_MAX,
  330. .dma_out_irq_nbr = 0,
  331. .dma_out_irq_flags = 0,
  332. .dma_out_irq_description = NULL,
  333. #endif
  334. #ifdef CONFIG_ETRAX_SERIAL_PORT2_DMA3_IN
  335. .dma_in_enabled = 1,
  336. .dma_in_nbr = SER2_RX_DMA_NBR,
  337. .dma_in_irq_nbr = SER2_DMA_RX_IRQ_NBR,
  338. .dma_in_irq_flags = 0,
  339. .dma_in_irq_description = "serial 2 dma rec",
  340. #else
  341. .dma_in_enabled = 0,
  342. .dma_in_nbr = UINT_MAX,
  343. .dma_in_irq_nbr = 0,
  344. .dma_in_irq_flags = 0,
  345. .dma_in_irq_description = NULL,
  346. #endif
  347. #else
  348. .enabled = 0,
  349. .io_if_description = NULL,
  350. .dma_out_enabled = 0,
  351. .dma_in_enabled = 0
  352. #endif
  353. }, /* ttyS2 */
  354. { .baud = DEF_BAUD,
  355. .ioport = (unsigned char *)R_SERIAL3_CTRL,
  356. .irq = 1U << 8, /* uses DMA 4 and 5 */
  357. .oclrintradr = R_DMA_CH4_CLR_INTR,
  358. .ofirstadr = R_DMA_CH4_FIRST,
  359. .ocmdadr = R_DMA_CH4_CMD,
  360. .ostatusadr = R_DMA_CH4_STATUS,
  361. .iclrintradr = R_DMA_CH5_CLR_INTR,
  362. .ifirstadr = R_DMA_CH5_FIRST,
  363. .icmdadr = R_DMA_CH5_CMD,
  364. .idescradr = R_DMA_CH5_DESCR,
  365. .rx_ctrl = DEF_RX,
  366. .tx_ctrl = DEF_TX,
  367. .iseteop = 1,
  368. .dma_owner = dma_ser3,
  369. .io_if = if_serial_3,
  370. #ifdef CONFIG_ETRAX_SERIAL_PORT3
  371. .enabled = 1,
  372. .io_if_description = "ser3",
  373. #ifdef CONFIG_ETRAX_SERIAL_PORT3_DMA4_OUT
  374. .dma_out_enabled = 1,
  375. .dma_out_nbr = SER3_TX_DMA_NBR,
  376. .dma_out_irq_nbr = SER3_DMA_TX_IRQ_NBR,
  377. .dma_out_irq_flags = 0,
  378. .dma_out_irq_description = "serial 3 dma tr",
  379. #else
  380. .dma_out_enabled = 0,
  381. .dma_out_nbr = UINT_MAX,
  382. .dma_out_irq_nbr = 0,
  383. .dma_out_irq_flags = 0,
  384. .dma_out_irq_description = NULL,
  385. #endif
  386. #ifdef CONFIG_ETRAX_SERIAL_PORT3_DMA5_IN
  387. .dma_in_enabled = 1,
  388. .dma_in_nbr = SER3_RX_DMA_NBR,
  389. .dma_in_irq_nbr = SER3_DMA_RX_IRQ_NBR,
  390. .dma_in_irq_flags = 0,
  391. .dma_in_irq_description = "serial 3 dma rec",
  392. #else
  393. .dma_in_enabled = 0,
  394. .dma_in_nbr = UINT_MAX,
  395. .dma_in_irq_nbr = 0,
  396. .dma_in_irq_flags = 0,
  397. .dma_in_irq_description = NULL
  398. #endif
  399. #else
  400. .enabled = 0,
  401. .io_if_description = NULL,
  402. .dma_out_enabled = 0,
  403. .dma_in_enabled = 0
  404. #endif
  405. } /* ttyS3 */
  406. };
  407. #define NR_PORTS (sizeof(rs_table)/sizeof(struct e100_serial))
  408. #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER
  409. static struct fast_timer fast_timers[NR_PORTS];
  410. #endif
  411. /* RS-485 */
  412. #if defined(CONFIG_ETRAX_RS485)
  413. #ifdef CONFIG_ETRAX_FAST_TIMER
  414. static struct fast_timer fast_timers_rs485[NR_PORTS];
  415. #endif
  416. #if defined(CONFIG_ETRAX_RS485_ON_PA)
  417. static int rs485_pa_bit = CONFIG_ETRAX_RS485_ON_PA_BIT;
  418. #endif
  419. #endif
  420. /* Info and macros needed for each ports extra control/status signals. */
  421. #define E100_STRUCT_PORT(line, pinname) \
  422. ((CONFIG_ETRAX_SER##line##_##pinname##_ON_PA_BIT >= 0)? \
  423. (R_PORT_PA_DATA): ( \
  424. (CONFIG_ETRAX_SER##line##_##pinname##_ON_PB_BIT >= 0)? \
  425. (R_PORT_PB_DATA):&dummy_ser[line]))
  426. #define E100_STRUCT_SHADOW(line, pinname) \
  427. ((CONFIG_ETRAX_SER##line##_##pinname##_ON_PA_BIT >= 0)? \
  428. (&port_pa_data_shadow): ( \
  429. (CONFIG_ETRAX_SER##line##_##pinname##_ON_PB_BIT >= 0)? \
  430. (&port_pb_data_shadow):&dummy_ser[line]))
  431. #define E100_STRUCT_MASK(line, pinname) \
  432. ((CONFIG_ETRAX_SER##line##_##pinname##_ON_PA_BIT >= 0)? \
  433. (1<<CONFIG_ETRAX_SER##line##_##pinname##_ON_PA_BIT): ( \
  434. (CONFIG_ETRAX_SER##line##_##pinname##_ON_PB_BIT >= 0)? \
  435. (1<<CONFIG_ETRAX_SER##line##_##pinname##_ON_PB_BIT):DUMMY_##pinname##_MASK))
  436. #define DUMMY_DTR_MASK 1
  437. #define DUMMY_RI_MASK 2
  438. #define DUMMY_DSR_MASK 4
  439. #define DUMMY_CD_MASK 8
  440. static unsigned char dummy_ser[NR_PORTS] = {0xFF, 0xFF, 0xFF,0xFF};
  441. /* If not all status pins are used or disabled, use mixed mode */
  442. #ifdef CONFIG_ETRAX_SERIAL_PORT0
  443. #define SER0_PA_BITSUM (CONFIG_ETRAX_SER0_DTR_ON_PA_BIT+CONFIG_ETRAX_SER0_RI_ON_PA_BIT+CONFIG_ETRAX_SER0_DSR_ON_PA_BIT+CONFIG_ETRAX_SER0_CD_ON_PA_BIT)
  444. #if SER0_PA_BITSUM != -4
  445. # if CONFIG_ETRAX_SER0_DTR_ON_PA_BIT == -1
  446. # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
  447. # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
  448. # endif
  449. # endif
  450. # if CONFIG_ETRAX_SER0_RI_ON_PA_BIT == -1
  451. # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
  452. # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
  453. # endif
  454. # endif
  455. # if CONFIG_ETRAX_SER0_DSR_ON_PA_BIT == -1
  456. # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
  457. # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
  458. # endif
  459. # endif
  460. # if CONFIG_ETRAX_SER0_CD_ON_PA_BIT == -1
  461. # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
  462. # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
  463. # endif
  464. # endif
  465. #endif
  466. #define SER0_PB_BITSUM (CONFIG_ETRAX_SER0_DTR_ON_PB_BIT+CONFIG_ETRAX_SER0_RI_ON_PB_BIT+CONFIG_ETRAX_SER0_DSR_ON_PB_BIT+CONFIG_ETRAX_SER0_CD_ON_PB_BIT)
  467. #if SER0_PB_BITSUM != -4
  468. # if CONFIG_ETRAX_SER0_DTR_ON_PB_BIT == -1
  469. # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
  470. # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
  471. # endif
  472. # endif
  473. # if CONFIG_ETRAX_SER0_RI_ON_PB_BIT == -1
  474. # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
  475. # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
  476. # endif
  477. # endif
  478. # if CONFIG_ETRAX_SER0_DSR_ON_PB_BIT == -1
  479. # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
  480. # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
  481. # endif
  482. # endif
  483. # if CONFIG_ETRAX_SER0_CD_ON_PB_BIT == -1
  484. # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
  485. # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
  486. # endif
  487. # endif
  488. #endif
  489. #endif /* PORT0 */
  490. #ifdef CONFIG_ETRAX_SERIAL_PORT1
  491. #define SER1_PA_BITSUM (CONFIG_ETRAX_SER1_DTR_ON_PA_BIT+CONFIG_ETRAX_SER1_RI_ON_PA_BIT+CONFIG_ETRAX_SER1_DSR_ON_PA_BIT+CONFIG_ETRAX_SER1_CD_ON_PA_BIT)
  492. #if SER1_PA_BITSUM != -4
  493. # if CONFIG_ETRAX_SER1_DTR_ON_PA_BIT == -1
  494. # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
  495. # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
  496. # endif
  497. # endif
  498. # if CONFIG_ETRAX_SER1_RI_ON_PA_BIT == -1
  499. # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
  500. # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
  501. # endif
  502. # endif
  503. # if CONFIG_ETRAX_SER1_DSR_ON_PA_BIT == -1
  504. # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
  505. # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
  506. # endif
  507. # endif
  508. # if CONFIG_ETRAX_SER1_CD_ON_PA_BIT == -1
  509. # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
  510. # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
  511. # endif
  512. # endif
  513. #endif
  514. #define SER1_PB_BITSUM (CONFIG_ETRAX_SER1_DTR_ON_PB_BIT+CONFIG_ETRAX_SER1_RI_ON_PB_BIT+CONFIG_ETRAX_SER1_DSR_ON_PB_BIT+CONFIG_ETRAX_SER1_CD_ON_PB_BIT)
  515. #if SER1_PB_BITSUM != -4
  516. # if CONFIG_ETRAX_SER1_DTR_ON_PB_BIT == -1
  517. # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
  518. # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
  519. # endif
  520. # endif
  521. # if CONFIG_ETRAX_SER1_RI_ON_PB_BIT == -1
  522. # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
  523. # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
  524. # endif
  525. # endif
  526. # if CONFIG_ETRAX_SER1_DSR_ON_PB_BIT == -1
  527. # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
  528. # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
  529. # endif
  530. # endif
  531. # if CONFIG_ETRAX_SER1_CD_ON_PB_BIT == -1
  532. # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
  533. # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
  534. # endif
  535. # endif
  536. #endif
  537. #endif /* PORT1 */
  538. #ifdef CONFIG_ETRAX_SERIAL_PORT2
  539. #define SER2_PA_BITSUM (CONFIG_ETRAX_SER2_DTR_ON_PA_BIT+CONFIG_ETRAX_SER2_RI_ON_PA_BIT+CONFIG_ETRAX_SER2_DSR_ON_PA_BIT+CONFIG_ETRAX_SER2_CD_ON_PA_BIT)
  540. #if SER2_PA_BITSUM != -4
  541. # if CONFIG_ETRAX_SER2_DTR_ON_PA_BIT == -1
  542. # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
  543. # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
  544. # endif
  545. # endif
  546. # if CONFIG_ETRAX_SER2_RI_ON_PA_BIT == -1
  547. # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
  548. # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
  549. # endif
  550. # endif
  551. # if CONFIG_ETRAX_SER2_DSR_ON_PA_BIT == -1
  552. # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
  553. # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
  554. # endif
  555. # endif
  556. # if CONFIG_ETRAX_SER2_CD_ON_PA_BIT == -1
  557. # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
  558. # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
  559. # endif
  560. # endif
  561. #endif
  562. #define SER2_PB_BITSUM (CONFIG_ETRAX_SER2_DTR_ON_PB_BIT+CONFIG_ETRAX_SER2_RI_ON_PB_BIT+CONFIG_ETRAX_SER2_DSR_ON_PB_BIT+CONFIG_ETRAX_SER2_CD_ON_PB_BIT)
  563. #if SER2_PB_BITSUM != -4
  564. # if CONFIG_ETRAX_SER2_DTR_ON_PB_BIT == -1
  565. # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
  566. # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
  567. # endif
  568. # endif
  569. # if CONFIG_ETRAX_SER2_RI_ON_PB_BIT == -1
  570. # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
  571. # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
  572. # endif
  573. # endif
  574. # if CONFIG_ETRAX_SER2_DSR_ON_PB_BIT == -1
  575. # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
  576. # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
  577. # endif
  578. # endif
  579. # if CONFIG_ETRAX_SER2_CD_ON_PB_BIT == -1
  580. # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
  581. # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
  582. # endif
  583. # endif
  584. #endif
  585. #endif /* PORT2 */
  586. #ifdef CONFIG_ETRAX_SERIAL_PORT3
  587. #define SER3_PA_BITSUM (CONFIG_ETRAX_SER3_DTR_ON_PA_BIT+CONFIG_ETRAX_SER3_RI_ON_PA_BIT+CONFIG_ETRAX_SER3_DSR_ON_PA_BIT+CONFIG_ETRAX_SER3_CD_ON_PA_BIT)
  588. #if SER3_PA_BITSUM != -4
  589. # if CONFIG_ETRAX_SER3_DTR_ON_PA_BIT == -1
  590. # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
  591. # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
  592. # endif
  593. # endif
  594. # if CONFIG_ETRAX_SER3_RI_ON_PA_BIT == -1
  595. # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
  596. # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
  597. # endif
  598. # endif
  599. # if CONFIG_ETRAX_SER3_DSR_ON_PA_BIT == -1
  600. # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
  601. # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
  602. # endif
  603. # endif
  604. # if CONFIG_ETRAX_SER3_CD_ON_PA_BIT == -1
  605. # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
  606. # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
  607. # endif
  608. # endif
  609. #endif
  610. #define SER3_PB_BITSUM (CONFIG_ETRAX_SER3_DTR_ON_PB_BIT+CONFIG_ETRAX_SER3_RI_ON_PB_BIT+CONFIG_ETRAX_SER3_DSR_ON_PB_BIT+CONFIG_ETRAX_SER3_CD_ON_PB_BIT)
  611. #if SER3_PB_BITSUM != -4
  612. # if CONFIG_ETRAX_SER3_DTR_ON_PB_BIT == -1
  613. # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
  614. # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
  615. # endif
  616. # endif
  617. # if CONFIG_ETRAX_SER3_RI_ON_PB_BIT == -1
  618. # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
  619. # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
  620. # endif
  621. # endif
  622. # if CONFIG_ETRAX_SER3_DSR_ON_PB_BIT == -1
  623. # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
  624. # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
  625. # endif
  626. # endif
  627. # if CONFIG_ETRAX_SER3_CD_ON_PB_BIT == -1
  628. # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
  629. # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
  630. # endif
  631. # endif
  632. #endif
  633. #endif /* PORT3 */
  634. #if defined(CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED) || \
  635. defined(CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED) || \
  636. defined(CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED) || \
  637. defined(CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED)
  638. #define ETRAX_SERX_DTR_RI_DSR_CD_MIXED
  639. #endif
  640. #ifdef ETRAX_SERX_DTR_RI_DSR_CD_MIXED
  641. /* The pins can be mixed on PA and PB */
  642. #define CONTROL_PINS_PORT_NOT_USED(line) \
  643. &dummy_ser[line], &dummy_ser[line], \
  644. &dummy_ser[line], &dummy_ser[line], \
  645. &dummy_ser[line], &dummy_ser[line], \
  646. &dummy_ser[line], &dummy_ser[line], \
  647. DUMMY_DTR_MASK, DUMMY_RI_MASK, DUMMY_DSR_MASK, DUMMY_CD_MASK
  648. struct control_pins
  649. {
  650. volatile unsigned char *dtr_port;
  651. unsigned char *dtr_shadow;
  652. volatile unsigned char *ri_port;
  653. unsigned char *ri_shadow;
  654. volatile unsigned char *dsr_port;
  655. unsigned char *dsr_shadow;
  656. volatile unsigned char *cd_port;
  657. unsigned char *cd_shadow;
  658. unsigned char dtr_mask;
  659. unsigned char ri_mask;
  660. unsigned char dsr_mask;
  661. unsigned char cd_mask;
  662. };
  663. static const struct control_pins e100_modem_pins[NR_PORTS] =
  664. {
  665. /* Ser 0 */
  666. {
  667. #ifdef CONFIG_ETRAX_SERIAL_PORT0
  668. E100_STRUCT_PORT(0,DTR), E100_STRUCT_SHADOW(0,DTR),
  669. E100_STRUCT_PORT(0,RI), E100_STRUCT_SHADOW(0,RI),
  670. E100_STRUCT_PORT(0,DSR), E100_STRUCT_SHADOW(0,DSR),
  671. E100_STRUCT_PORT(0,CD), E100_STRUCT_SHADOW(0,CD),
  672. E100_STRUCT_MASK(0,DTR),
  673. E100_STRUCT_MASK(0,RI),
  674. E100_STRUCT_MASK(0,DSR),
  675. E100_STRUCT_MASK(0,CD)
  676. #else
  677. CONTROL_PINS_PORT_NOT_USED(0)
  678. #endif
  679. },
  680. /* Ser 1 */
  681. {
  682. #ifdef CONFIG_ETRAX_SERIAL_PORT1
  683. E100_STRUCT_PORT(1,DTR), E100_STRUCT_SHADOW(1,DTR),
  684. E100_STRUCT_PORT(1,RI), E100_STRUCT_SHADOW(1,RI),
  685. E100_STRUCT_PORT(1,DSR), E100_STRUCT_SHADOW(1,DSR),
  686. E100_STRUCT_PORT(1,CD), E100_STRUCT_SHADOW(1,CD),
  687. E100_STRUCT_MASK(1,DTR),
  688. E100_STRUCT_MASK(1,RI),
  689. E100_STRUCT_MASK(1,DSR),
  690. E100_STRUCT_MASK(1,CD)
  691. #else
  692. CONTROL_PINS_PORT_NOT_USED(1)
  693. #endif
  694. },
  695. /* Ser 2 */
  696. {
  697. #ifdef CONFIG_ETRAX_SERIAL_PORT2
  698. E100_STRUCT_PORT(2,DTR), E100_STRUCT_SHADOW(2,DTR),
  699. E100_STRUCT_PORT(2,RI), E100_STRUCT_SHADOW(2,RI),
  700. E100_STRUCT_PORT(2,DSR), E100_STRUCT_SHADOW(2,DSR),
  701. E100_STRUCT_PORT(2,CD), E100_STRUCT_SHADOW(2,CD),
  702. E100_STRUCT_MASK(2,DTR),
  703. E100_STRUCT_MASK(2,RI),
  704. E100_STRUCT_MASK(2,DSR),
  705. E100_STRUCT_MASK(2,CD)
  706. #else
  707. CONTROL_PINS_PORT_NOT_USED(2)
  708. #endif
  709. },
  710. /* Ser 3 */
  711. {
  712. #ifdef CONFIG_ETRAX_SERIAL_PORT3
  713. E100_STRUCT_PORT(3,DTR), E100_STRUCT_SHADOW(3,DTR),
  714. E100_STRUCT_PORT(3,RI), E100_STRUCT_SHADOW(3,RI),
  715. E100_STRUCT_PORT(3,DSR), E100_STRUCT_SHADOW(3,DSR),
  716. E100_STRUCT_PORT(3,CD), E100_STRUCT_SHADOW(3,CD),
  717. E100_STRUCT_MASK(3,DTR),
  718. E100_STRUCT_MASK(3,RI),
  719. E100_STRUCT_MASK(3,DSR),
  720. E100_STRUCT_MASK(3,CD)
  721. #else
  722. CONTROL_PINS_PORT_NOT_USED(3)
  723. #endif
  724. }
  725. };
  726. #else /* ETRAX_SERX_DTR_RI_DSR_CD_MIXED */
  727. /* All pins are on either PA or PB for each serial port */
  728. #define CONTROL_PINS_PORT_NOT_USED(line) \
  729. &dummy_ser[line], &dummy_ser[line], \
  730. DUMMY_DTR_MASK, DUMMY_RI_MASK, DUMMY_DSR_MASK, DUMMY_CD_MASK
  731. struct control_pins
  732. {
  733. volatile unsigned char *port;
  734. unsigned char *shadow;
  735. unsigned char dtr_mask;
  736. unsigned char ri_mask;
  737. unsigned char dsr_mask;
  738. unsigned char cd_mask;
  739. };
  740. #define dtr_port port
  741. #define dtr_shadow shadow
  742. #define ri_port port
  743. #define ri_shadow shadow
  744. #define dsr_port port
  745. #define dsr_shadow shadow
  746. #define cd_port port
  747. #define cd_shadow shadow
  748. static const struct control_pins e100_modem_pins[NR_PORTS] =
  749. {
  750. /* Ser 0 */
  751. {
  752. #ifdef CONFIG_ETRAX_SERIAL_PORT0
  753. E100_STRUCT_PORT(0,DTR), E100_STRUCT_SHADOW(0,DTR),
  754. E100_STRUCT_MASK(0,DTR),
  755. E100_STRUCT_MASK(0,RI),
  756. E100_STRUCT_MASK(0,DSR),
  757. E100_STRUCT_MASK(0,CD)
  758. #else
  759. CONTROL_PINS_PORT_NOT_USED(0)
  760. #endif
  761. },
  762. /* Ser 1 */
  763. {
  764. #ifdef CONFIG_ETRAX_SERIAL_PORT1
  765. E100_STRUCT_PORT(1,DTR), E100_STRUCT_SHADOW(1,DTR),
  766. E100_STRUCT_MASK(1,DTR),
  767. E100_STRUCT_MASK(1,RI),
  768. E100_STRUCT_MASK(1,DSR),
  769. E100_STRUCT_MASK(1,CD)
  770. #else
  771. CONTROL_PINS_PORT_NOT_USED(1)
  772. #endif
  773. },
  774. /* Ser 2 */
  775. {
  776. #ifdef CONFIG_ETRAX_SERIAL_PORT2
  777. E100_STRUCT_PORT(2,DTR), E100_STRUCT_SHADOW(2,DTR),
  778. E100_STRUCT_MASK(2,DTR),
  779. E100_STRUCT_MASK(2,RI),
  780. E100_STRUCT_MASK(2,DSR),
  781. E100_STRUCT_MASK(2,CD)
  782. #else
  783. CONTROL_PINS_PORT_NOT_USED(2)
  784. #endif
  785. },
  786. /* Ser 3 */
  787. {
  788. #ifdef CONFIG_ETRAX_SERIAL_PORT3
  789. E100_STRUCT_PORT(3,DTR), E100_STRUCT_SHADOW(3,DTR),
  790. E100_STRUCT_MASK(3,DTR),
  791. E100_STRUCT_MASK(3,RI),
  792. E100_STRUCT_MASK(3,DSR),
  793. E100_STRUCT_MASK(3,CD)
  794. #else
  795. CONTROL_PINS_PORT_NOT_USED(3)
  796. #endif
  797. }
  798. };
  799. #endif /* !ETRAX_SERX_DTR_RI_DSR_CD_MIXED */
  800. #define E100_RTS_MASK 0x20
  801. #define E100_CTS_MASK 0x40
  802. /* All serial port signals are active low:
  803. * active = 0 -> 3.3V to RS-232 driver -> -12V on RS-232 level
  804. * inactive = 1 -> 0V to RS-232 driver -> +12V on RS-232 level
  805. *
  806. * These macros returns the pin value: 0=0V, >=1 = 3.3V on ETRAX chip
  807. */
  808. /* Output */
  809. #define E100_RTS_GET(info) ((info)->rx_ctrl & E100_RTS_MASK)
  810. /* Input */
  811. #define E100_CTS_GET(info) ((info)->ioport[REG_STATUS] & E100_CTS_MASK)
  812. /* These are typically PA or PB and 0 means 0V, 1 means 3.3V */
  813. /* Is an output */
  814. #define E100_DTR_GET(info) ((*e100_modem_pins[(info)->line].dtr_shadow) & e100_modem_pins[(info)->line].dtr_mask)
  815. /* Normally inputs */
  816. #define E100_RI_GET(info) ((*e100_modem_pins[(info)->line].ri_port) & e100_modem_pins[(info)->line].ri_mask)
  817. #define E100_CD_GET(info) ((*e100_modem_pins[(info)->line].cd_port) & e100_modem_pins[(info)->line].cd_mask)
  818. /* Input */
  819. #define E100_DSR_GET(info) ((*e100_modem_pins[(info)->line].dsr_port) & e100_modem_pins[(info)->line].dsr_mask)
  820. /* Calculate the chartime depending on baudrate, numbor of bits etc. */
  821. static void update_char_time(struct e100_serial * info)
  822. {
  823. tcflag_t cflags = info->port.tty->termios.c_cflag;
  824. int bits;
  825. /* calc. number of bits / data byte */
  826. /* databits + startbit and 1 stopbit */
  827. if ((cflags & CSIZE) == CS7)
  828. bits = 9;
  829. else
  830. bits = 10;
  831. if (cflags & CSTOPB) /* 2 stopbits ? */
  832. bits++;
  833. if (cflags & PARENB) /* parity bit ? */
  834. bits++;
  835. /* calc timeout */
  836. info->char_time_usec = ((bits * 1000000) / info->baud) + 1;
  837. info->flush_time_usec = 4*info->char_time_usec;
  838. if (info->flush_time_usec < MIN_FLUSH_TIME_USEC)
  839. info->flush_time_usec = MIN_FLUSH_TIME_USEC;
  840. }
  841. /*
  842. * This function maps from the Bxxxx defines in asm/termbits.h into real
  843. * baud rates.
  844. */
  845. static int
  846. cflag_to_baud(unsigned int cflag)
  847. {
  848. static int baud_table[] = {
  849. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,
  850. 4800, 9600, 19200, 38400 };
  851. static int ext_baud_table[] = {
  852. 0, 57600, 115200, 230400, 460800, 921600, 1843200, 6250000,
  853. 0, 0, 0, 0, 0, 0, 0, 0 };
  854. if (cflag & CBAUDEX)
  855. return ext_baud_table[(cflag & CBAUD) & ~CBAUDEX];
  856. else
  857. return baud_table[cflag & CBAUD];
  858. }
  859. /* and this maps to an etrax100 hardware baud constant */
  860. static unsigned char
  861. cflag_to_etrax_baud(unsigned int cflag)
  862. {
  863. char retval;
  864. static char baud_table[] = {
  865. -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, -1, 3, 4, 5, 6, 7 };
  866. static char ext_baud_table[] = {
  867. -1, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, -1 };
  868. if (cflag & CBAUDEX)
  869. retval = ext_baud_table[(cflag & CBAUD) & ~CBAUDEX];
  870. else
  871. retval = baud_table[cflag & CBAUD];
  872. if (retval < 0) {
  873. printk(KERN_WARNING "serdriver tried setting invalid baud rate, flags %x.\n", cflag);
  874. retval = 5; /* choose default 9600 instead */
  875. }
  876. return retval | (retval << 4); /* choose same for both TX and RX */
  877. }
  878. /* Various static support functions */
  879. /* Functions to set or clear DTR/RTS on the requested line */
  880. /* It is complicated by the fact that RTS is a serial port register, while
  881. * DTR might not be implemented in the HW at all, and if it is, it can be on
  882. * any general port.
  883. */
  884. static inline void
  885. e100_dtr(struct e100_serial *info, int set)
  886. {
  887. unsigned char mask = e100_modem_pins[info->line].dtr_mask;
  888. #ifdef SERIAL_DEBUG_IO
  889. printk("ser%i dtr %i mask: 0x%02X\n", info->line, set, mask);
  890. printk("ser%i shadow before 0x%02X get: %i\n",
  891. info->line, *e100_modem_pins[info->line].dtr_shadow,
  892. E100_DTR_GET(info));
  893. #endif
  894. /* DTR is active low */
  895. {
  896. unsigned long flags;
  897. local_irq_save(flags);
  898. *e100_modem_pins[info->line].dtr_shadow &= ~mask;
  899. *e100_modem_pins[info->line].dtr_shadow |= (set ? 0 : mask);
  900. *e100_modem_pins[info->line].dtr_port = *e100_modem_pins[info->line].dtr_shadow;
  901. local_irq_restore(flags);
  902. }
  903. #ifdef SERIAL_DEBUG_IO
  904. printk("ser%i shadow after 0x%02X get: %i\n",
  905. info->line, *e100_modem_pins[info->line].dtr_shadow,
  906. E100_DTR_GET(info));
  907. #endif
  908. }
  909. /* set = 0 means 3.3V on the pin, bitvalue: 0=active, 1=inactive
  910. * 0=0V , 1=3.3V
  911. */
  912. static inline void
  913. e100_rts(struct e100_serial *info, int set)
  914. {
  915. unsigned long flags;
  916. local_irq_save(flags);
  917. info->rx_ctrl &= ~E100_RTS_MASK;
  918. info->rx_ctrl |= (set ? 0 : E100_RTS_MASK); /* RTS is active low */
  919. info->ioport[REG_REC_CTRL] = info->rx_ctrl;
  920. local_irq_restore(flags);
  921. #ifdef SERIAL_DEBUG_IO
  922. printk("ser%i rts %i\n", info->line, set);
  923. #endif
  924. }
  925. /* If this behaves as a modem, RI and CD is an output */
  926. static inline void
  927. e100_ri_out(struct e100_serial *info, int set)
  928. {
  929. /* RI is active low */
  930. {
  931. unsigned char mask = e100_modem_pins[info->line].ri_mask;
  932. unsigned long flags;
  933. local_irq_save(flags);
  934. *e100_modem_pins[info->line].ri_shadow &= ~mask;
  935. *e100_modem_pins[info->line].ri_shadow |= (set ? 0 : mask);
  936. *e100_modem_pins[info->line].ri_port = *e100_modem_pins[info->line].ri_shadow;
  937. local_irq_restore(flags);
  938. }
  939. }
  940. static inline void
  941. e100_cd_out(struct e100_serial *info, int set)
  942. {
  943. /* CD is active low */
  944. {
  945. unsigned char mask = e100_modem_pins[info->line].cd_mask;
  946. unsigned long flags;
  947. local_irq_save(flags);
  948. *e100_modem_pins[info->line].cd_shadow &= ~mask;
  949. *e100_modem_pins[info->line].cd_shadow |= (set ? 0 : mask);
  950. *e100_modem_pins[info->line].cd_port = *e100_modem_pins[info->line].cd_shadow;
  951. local_irq_restore(flags);
  952. }
  953. }
  954. static inline void
  955. e100_disable_rx(struct e100_serial *info)
  956. {
  957. /* disable the receiver */
  958. info->ioport[REG_REC_CTRL] =
  959. (info->rx_ctrl &= ~IO_MASK(R_SERIAL0_REC_CTRL, rec_enable));
  960. }
  961. static inline void
  962. e100_enable_rx(struct e100_serial *info)
  963. {
  964. /* enable the receiver */
  965. info->ioport[REG_REC_CTRL] =
  966. (info->rx_ctrl |= IO_MASK(R_SERIAL0_REC_CTRL, rec_enable));
  967. }
  968. /* the rx DMA uses both the dma_descr and the dma_eop interrupts */
  969. static inline void
  970. e100_disable_rxdma_irq(struct e100_serial *info)
  971. {
  972. #ifdef SERIAL_DEBUG_INTR
  973. printk("rxdma_irq(%d): 0\n",info->line);
  974. #endif
  975. DINTR1(DEBUG_LOG(info->line,"IRQ disable_rxdma_irq %i\n", info->line));
  976. *R_IRQ_MASK2_CLR = (info->irq << 2) | (info->irq << 3);
  977. }
  978. static inline void
  979. e100_enable_rxdma_irq(struct e100_serial *info)
  980. {
  981. #ifdef SERIAL_DEBUG_INTR
  982. printk("rxdma_irq(%d): 1\n",info->line);
  983. #endif
  984. DINTR1(DEBUG_LOG(info->line,"IRQ enable_rxdma_irq %i\n", info->line));
  985. *R_IRQ_MASK2_SET = (info->irq << 2) | (info->irq << 3);
  986. }
  987. /* the tx DMA uses only dma_descr interrupt */
  988. static void e100_disable_txdma_irq(struct e100_serial *info)
  989. {
  990. #ifdef SERIAL_DEBUG_INTR
  991. printk("txdma_irq(%d): 0\n",info->line);
  992. #endif
  993. DINTR1(DEBUG_LOG(info->line,"IRQ disable_txdma_irq %i\n", info->line));
  994. *R_IRQ_MASK2_CLR = info->irq;
  995. }
  996. static void e100_enable_txdma_irq(struct e100_serial *info)
  997. {
  998. #ifdef SERIAL_DEBUG_INTR
  999. printk("txdma_irq(%d): 1\n",info->line);
  1000. #endif
  1001. DINTR1(DEBUG_LOG(info->line,"IRQ enable_txdma_irq %i\n", info->line));
  1002. *R_IRQ_MASK2_SET = info->irq;
  1003. }
  1004. static void e100_disable_txdma_channel(struct e100_serial *info)
  1005. {
  1006. unsigned long flags;
  1007. /* Disable output DMA channel for the serial port in question
  1008. * ( set to something other than serialX)
  1009. */
  1010. local_irq_save(flags);
  1011. DFLOW(DEBUG_LOG(info->line, "disable_txdma_channel %i\n", info->line));
  1012. if (info->line == 0) {
  1013. if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma6)) ==
  1014. IO_STATE(R_GEN_CONFIG, dma6, serial0)) {
  1015. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma6);
  1016. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma6, unused);
  1017. }
  1018. } else if (info->line == 1) {
  1019. if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma8)) ==
  1020. IO_STATE(R_GEN_CONFIG, dma8, serial1)) {
  1021. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma8);
  1022. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma8, usb);
  1023. }
  1024. } else if (info->line == 2) {
  1025. if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma2)) ==
  1026. IO_STATE(R_GEN_CONFIG, dma2, serial2)) {
  1027. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma2);
  1028. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma2, par0);
  1029. }
  1030. } else if (info->line == 3) {
  1031. if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma4)) ==
  1032. IO_STATE(R_GEN_CONFIG, dma4, serial3)) {
  1033. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma4);
  1034. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma4, par1);
  1035. }
  1036. }
  1037. *R_GEN_CONFIG = genconfig_shadow;
  1038. local_irq_restore(flags);
  1039. }
  1040. static void e100_enable_txdma_channel(struct e100_serial *info)
  1041. {
  1042. unsigned long flags;
  1043. local_irq_save(flags);
  1044. DFLOW(DEBUG_LOG(info->line, "enable_txdma_channel %i\n", info->line));
  1045. /* Enable output DMA channel for the serial port in question */
  1046. if (info->line == 0) {
  1047. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma6);
  1048. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma6, serial0);
  1049. } else if (info->line == 1) {
  1050. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma8);
  1051. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma8, serial1);
  1052. } else if (info->line == 2) {
  1053. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma2);
  1054. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma2, serial2);
  1055. } else if (info->line == 3) {
  1056. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma4);
  1057. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma4, serial3);
  1058. }
  1059. *R_GEN_CONFIG = genconfig_shadow;
  1060. local_irq_restore(flags);
  1061. }
  1062. static void e100_disable_rxdma_channel(struct e100_serial *info)
  1063. {
  1064. unsigned long flags;
  1065. /* Disable input DMA channel for the serial port in question
  1066. * ( set to something other than serialX)
  1067. */
  1068. local_irq_save(flags);
  1069. if (info->line == 0) {
  1070. if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma7)) ==
  1071. IO_STATE(R_GEN_CONFIG, dma7, serial0)) {
  1072. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma7);
  1073. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma7, unused);
  1074. }
  1075. } else if (info->line == 1) {
  1076. if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma9)) ==
  1077. IO_STATE(R_GEN_CONFIG, dma9, serial1)) {
  1078. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma9);
  1079. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma9, usb);
  1080. }
  1081. } else if (info->line == 2) {
  1082. if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma3)) ==
  1083. IO_STATE(R_GEN_CONFIG, dma3, serial2)) {
  1084. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma3);
  1085. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma3, par0);
  1086. }
  1087. } else if (info->line == 3) {
  1088. if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma5)) ==
  1089. IO_STATE(R_GEN_CONFIG, dma5, serial3)) {
  1090. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma5);
  1091. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma5, par1);
  1092. }
  1093. }
  1094. *R_GEN_CONFIG = genconfig_shadow;
  1095. local_irq_restore(flags);
  1096. }
  1097. static void e100_enable_rxdma_channel(struct e100_serial *info)
  1098. {
  1099. unsigned long flags;
  1100. local_irq_save(flags);
  1101. /* Enable input DMA channel for the serial port in question */
  1102. if (info->line == 0) {
  1103. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma7);
  1104. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma7, serial0);
  1105. } else if (info->line == 1) {
  1106. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma9);
  1107. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma9, serial1);
  1108. } else if (info->line == 2) {
  1109. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma3);
  1110. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma3, serial2);
  1111. } else if (info->line == 3) {
  1112. genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma5);
  1113. genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma5, serial3);
  1114. }
  1115. *R_GEN_CONFIG = genconfig_shadow;
  1116. local_irq_restore(flags);
  1117. }
  1118. #ifdef SERIAL_HANDLE_EARLY_ERRORS
  1119. /* in order to detect and fix errors on the first byte
  1120. we have to use the serial interrupts as well. */
  1121. static inline void
  1122. e100_disable_serial_data_irq(struct e100_serial *info)
  1123. {
  1124. #ifdef SERIAL_DEBUG_INTR
  1125. printk("ser_irq(%d): 0\n",info->line);
  1126. #endif
  1127. DINTR1(DEBUG_LOG(info->line,"IRQ disable data_irq %i\n", info->line));
  1128. *R_IRQ_MASK1_CLR = (1U << (8+2*info->line));
  1129. }
  1130. static inline void
  1131. e100_enable_serial_data_irq(struct e100_serial *info)
  1132. {
  1133. #ifdef SERIAL_DEBUG_INTR
  1134. printk("ser_irq(%d): 1\n",info->line);
  1135. printk("**** %d = %d\n",
  1136. (8+2*info->line),
  1137. (1U << (8+2*info->line)));
  1138. #endif
  1139. DINTR1(DEBUG_LOG(info->line,"IRQ enable data_irq %i\n", info->line));
  1140. *R_IRQ_MASK1_SET = (1U << (8+2*info->line));
  1141. }
  1142. #endif
  1143. static inline void
  1144. e100_disable_serial_tx_ready_irq(struct e100_serial *info)
  1145. {
  1146. #ifdef SERIAL_DEBUG_INTR
  1147. printk("ser_tx_irq(%d): 0\n",info->line);
  1148. #endif
  1149. DINTR1(DEBUG_LOG(info->line,"IRQ disable ready_irq %i\n", info->line));
  1150. *R_IRQ_MASK1_CLR = (1U << (8+1+2*info->line));
  1151. }
  1152. static inline void
  1153. e100_enable_serial_tx_ready_irq(struct e100_serial *info)
  1154. {
  1155. #ifdef SERIAL_DEBUG_INTR
  1156. printk("ser_tx_irq(%d): 1\n",info->line);
  1157. printk("**** %d = %d\n",
  1158. (8+1+2*info->line),
  1159. (1U << (8+1+2*info->line)));
  1160. #endif
  1161. DINTR2(DEBUG_LOG(info->line,"IRQ enable ready_irq %i\n", info->line));
  1162. *R_IRQ_MASK1_SET = (1U << (8+1+2*info->line));
  1163. }
  1164. static inline void e100_enable_rx_irq(struct e100_serial *info)
  1165. {
  1166. if (info->uses_dma_in)
  1167. e100_enable_rxdma_irq(info);
  1168. else
  1169. e100_enable_serial_data_irq(info);
  1170. }
  1171. static inline void e100_disable_rx_irq(struct e100_serial *info)
  1172. {
  1173. if (info->uses_dma_in)
  1174. e100_disable_rxdma_irq(info);
  1175. else
  1176. e100_disable_serial_data_irq(info);
  1177. }
  1178. #if defined(CONFIG_ETRAX_RS485)
  1179. /* Enable RS-485 mode on selected port. This is UGLY. */
  1180. static int
  1181. e100_enable_rs485(struct tty_struct *tty, struct serial_rs485 *r)
  1182. {
  1183. struct e100_serial * info = (struct e100_serial *)tty->driver_data;
  1184. #if defined(CONFIG_ETRAX_RS485_ON_PA)
  1185. *R_PORT_PA_DATA = port_pa_data_shadow |= (1 << rs485_pa_bit);
  1186. #endif
  1187. info->rs485 = *r;
  1188. /* Maximum delay before RTS equal to 1000 */
  1189. if (info->rs485.delay_rts_before_send >= 1000)
  1190. info->rs485.delay_rts_before_send = 1000;
  1191. /* printk("rts: on send = %i, after = %i, enabled = %i",
  1192. info->rs485.rts_on_send,
  1193. info->rs485.rts_after_sent,
  1194. info->rs485.enabled
  1195. );
  1196. */
  1197. return 0;
  1198. }
  1199. static int
  1200. e100_write_rs485(struct tty_struct *tty,
  1201. const unsigned char *buf, int count)
  1202. {
  1203. struct e100_serial * info = (struct e100_serial *)tty->driver_data;
  1204. int old_value = (info->rs485.flags) & SER_RS485_ENABLED;
  1205. /* rs485 is always implicitly enabled if we're using the ioctl()
  1206. * but it doesn't have to be set in the serial_rs485
  1207. * (to be backward compatible with old apps)
  1208. * So we store, set and restore it.
  1209. */
  1210. info->rs485.flags |= SER_RS485_ENABLED;
  1211. /* rs_write now deals with RS485 if enabled */
  1212. count = rs_write(tty, buf, count);
  1213. if (!old_value)
  1214. info->rs485.flags &= ~(SER_RS485_ENABLED);
  1215. return count;
  1216. }
  1217. #ifdef CONFIG_ETRAX_FAST_TIMER
  1218. /* Timer function to toggle RTS when using FAST_TIMER */
  1219. static void rs485_toggle_rts_timer_function(unsigned long data)
  1220. {
  1221. struct e100_serial *info = (struct e100_serial *)data;
  1222. fast_timers_rs485[info->line].function = NULL;
  1223. e100_rts(info, (info->rs485.flags & SER_RS485_RTS_AFTER_SEND));
  1224. #if defined(CONFIG_ETRAX_RS485_DISABLE_RECEIVER)
  1225. e100_enable_rx(info);
  1226. e100_enable_rx_irq(info);
  1227. #endif
  1228. }
  1229. #endif
  1230. #endif /* CONFIG_ETRAX_RS485 */
  1231. /*
  1232. * ------------------------------------------------------------
  1233. * rs_stop() and rs_start()
  1234. *
  1235. * This routines are called before setting or resetting tty->stopped.
  1236. * They enable or disable transmitter using the XOFF registers, as necessary.
  1237. * ------------------------------------------------------------
  1238. */
  1239. static void
  1240. rs_stop(struct tty_struct *tty)
  1241. {
  1242. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  1243. if (info) {
  1244. unsigned long flags;
  1245. unsigned long xoff;
  1246. local_irq_save(flags);
  1247. DFLOW(DEBUG_LOG(info->line, "XOFF rs_stop xmit %i\n",
  1248. CIRC_CNT(info->xmit.head,
  1249. info->xmit.tail,SERIAL_XMIT_SIZE)));
  1250. xoff = IO_FIELD(R_SERIAL0_XOFF, xoff_char,
  1251. STOP_CHAR(info->port.tty));
  1252. xoff |= IO_STATE(R_SERIAL0_XOFF, tx_stop, stop);
  1253. if (tty->termios.c_iflag & IXON ) {
  1254. xoff |= IO_STATE(R_SERIAL0_XOFF, auto_xoff, enable);
  1255. }
  1256. *((unsigned long *)&info->ioport[REG_XOFF]) = xoff;
  1257. local_irq_restore(flags);
  1258. }
  1259. }
  1260. static void
  1261. rs_start(struct tty_struct *tty)
  1262. {
  1263. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  1264. if (info) {
  1265. unsigned long flags;
  1266. unsigned long xoff;
  1267. local_irq_save(flags);
  1268. DFLOW(DEBUG_LOG(info->line, "XOFF rs_start xmit %i\n",
  1269. CIRC_CNT(info->xmit.head,
  1270. info->xmit.tail,SERIAL_XMIT_SIZE)));
  1271. xoff = IO_FIELD(R_SERIAL0_XOFF, xoff_char, STOP_CHAR(tty));
  1272. xoff |= IO_STATE(R_SERIAL0_XOFF, tx_stop, enable);
  1273. if (tty->termios.c_iflag & IXON ) {
  1274. xoff |= IO_STATE(R_SERIAL0_XOFF, auto_xoff, enable);
  1275. }
  1276. *((unsigned long *)&info->ioport[REG_XOFF]) = xoff;
  1277. if (!info->uses_dma_out &&
  1278. info->xmit.head != info->xmit.tail && info->xmit.buf)
  1279. e100_enable_serial_tx_ready_irq(info);
  1280. local_irq_restore(flags);
  1281. }
  1282. }
  1283. /*
  1284. * ----------------------------------------------------------------------
  1285. *
  1286. * Here starts the interrupt handling routines. All of the following
  1287. * subroutines are declared as inline and are folded into
  1288. * rs_interrupt(). They were separated out for readability's sake.
  1289. *
  1290. * Note: rs_interrupt() is a "fast" interrupt, which means that it
  1291. * runs with interrupts turned off. People who may want to modify
  1292. * rs_interrupt() should try to keep the interrupt handler as fast as
  1293. * possible. After you are done making modifications, it is not a bad
  1294. * idea to do:
  1295. *
  1296. * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
  1297. *
  1298. * and look at the resulting assemble code in serial.s.
  1299. *
  1300. * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
  1301. * -----------------------------------------------------------------------
  1302. */
  1303. /*
  1304. * This routine is used by the interrupt handler to schedule
  1305. * processing in the software interrupt portion of the driver.
  1306. */
  1307. static void rs_sched_event(struct e100_serial *info, int event)
  1308. {
  1309. if (info->event & (1 << event))
  1310. return;
  1311. info->event |= 1 << event;
  1312. schedule_work(&info->work);
  1313. }
  1314. /* The output DMA channel is free - use it to send as many chars as possible
  1315. * NOTES:
  1316. * We don't pay attention to info->x_char, which means if the TTY wants to
  1317. * use XON/XOFF it will set info->x_char but we won't send any X char!
  1318. *
  1319. * To implement this, we'd just start a DMA send of 1 byte pointing at a
  1320. * buffer containing the X char, and skip updating xmit. We'd also have to
  1321. * check if the last sent char was the X char when we enter this function
  1322. * the next time, to avoid updating xmit with the sent X value.
  1323. */
  1324. static void
  1325. transmit_chars_dma(struct e100_serial *info)
  1326. {
  1327. unsigned int c, sentl;
  1328. struct etrax_dma_descr *descr;
  1329. /* acknowledge both dma_descr and dma_eop irq in R_DMA_CHx_CLR_INTR */
  1330. *info->oclrintradr =
  1331. IO_STATE(R_DMA_CH6_CLR_INTR, clr_descr, do) |
  1332. IO_STATE(R_DMA_CH6_CLR_INTR, clr_eop, do);
  1333. #ifdef SERIAL_DEBUG_INTR
  1334. if (info->line == SERIAL_DEBUG_LINE)
  1335. printk("tc\n");
  1336. #endif
  1337. if (!info->tr_running) {
  1338. /* weirdo... we shouldn't get here! */
  1339. printk(KERN_WARNING "Achtung: transmit_chars_dma with !tr_running\n");
  1340. return;
  1341. }
  1342. descr = &info->tr_descr;
  1343. /* first get the amount of bytes sent during the last DMA transfer,
  1344. and update xmit accordingly */
  1345. /* if the stop bit was not set, all data has been sent */
  1346. if (!(descr->status & d_stop)) {
  1347. sentl = descr->sw_len;
  1348. } else
  1349. /* otherwise we find the amount of data sent here */
  1350. sentl = descr->hw_len;
  1351. DFLOW(DEBUG_LOG(info->line, "TX %i done\n", sentl));
  1352. /* update stats */
  1353. info->icount.tx += sentl;
  1354. /* update xmit buffer */
  1355. info->xmit.tail = (info->xmit.tail + sentl) & (SERIAL_XMIT_SIZE - 1);
  1356. /* if there is only a few chars left in the buf, wake up the blocked
  1357. write if any */
  1358. if (CIRC_CNT(info->xmit.head,
  1359. info->xmit.tail,
  1360. SERIAL_XMIT_SIZE) < WAKEUP_CHARS)
  1361. rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
  1362. /* find out the largest amount of consecutive bytes we want to send now */
  1363. c = CIRC_CNT_TO_END(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
  1364. /* Don't send all in one DMA transfer - divide it so we wake up
  1365. * application before all is sent
  1366. */
  1367. if (c >= 4*WAKEUP_CHARS)
  1368. c = c/2;
  1369. if (c <= 0) {
  1370. /* our job here is done, don't schedule any new DMA transfer */
  1371. info->tr_running = 0;
  1372. #if defined(CONFIG_ETRAX_RS485) && defined(CONFIG_ETRAX_FAST_TIMER)
  1373. if (info->rs485.flags & SER_RS485_ENABLED) {
  1374. /* Set a short timer to toggle RTS */
  1375. start_one_shot_timer(&fast_timers_rs485[info->line],
  1376. rs485_toggle_rts_timer_function,
  1377. (unsigned long)info,
  1378. info->char_time_usec*2,
  1379. "RS-485");
  1380. }
  1381. #endif /* RS485 */
  1382. return;
  1383. }
  1384. /* ok we can schedule a dma send of c chars starting at info->xmit.tail */
  1385. /* set up the descriptor correctly for output */
  1386. DFLOW(DEBUG_LOG(info->line, "TX %i\n", c));
  1387. descr->ctrl = d_int | d_eol | d_wait; /* Wait needed for tty_wait_until_sent() */
  1388. descr->sw_len = c;
  1389. descr->buf = virt_to_phys(info->xmit.buf + info->xmit.tail);
  1390. descr->status = 0;
  1391. *info->ofirstadr = virt_to_phys(descr); /* write to R_DMAx_FIRST */
  1392. *info->ocmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, start);
  1393. /* DMA is now running (hopefully) */
  1394. } /* transmit_chars_dma */
  1395. static void
  1396. start_transmit(struct e100_serial *info)
  1397. {
  1398. #if 0
  1399. if (info->line == SERIAL_DEBUG_LINE)
  1400. printk("x\n");
  1401. #endif
  1402. info->tr_descr.sw_len = 0;
  1403. info->tr_descr.hw_len = 0;
  1404. info->tr_descr.status = 0;
  1405. info->tr_running = 1;
  1406. if (info->uses_dma_out)
  1407. transmit_chars_dma(info);
  1408. else
  1409. e100_enable_serial_tx_ready_irq(info);
  1410. } /* start_transmit */
  1411. #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER
  1412. static int serial_fast_timer_started = 0;
  1413. static int serial_fast_timer_expired = 0;
  1414. static void flush_timeout_function(unsigned long data);
  1415. #define START_FLUSH_FAST_TIMER_TIME(info, string, usec) {\
  1416. unsigned long timer_flags; \
  1417. local_irq_save(timer_flags); \
  1418. if (fast_timers[info->line].function == NULL) { \
  1419. serial_fast_timer_started++; \
  1420. TIMERD(DEBUG_LOG(info->line, "start_timer %i ", info->line)); \
  1421. TIMERD(DEBUG_LOG(info->line, "num started: %i\n", serial_fast_timer_started)); \
  1422. start_one_shot_timer(&fast_timers[info->line], \
  1423. flush_timeout_function, \
  1424. (unsigned long)info, \
  1425. (usec), \
  1426. string); \
  1427. } \
  1428. else { \
  1429. TIMERD(DEBUG_LOG(info->line, "timer %i already running\n", info->line)); \
  1430. } \
  1431. local_irq_restore(timer_flags); \
  1432. }
  1433. #define START_FLUSH_FAST_TIMER(info, string) START_FLUSH_FAST_TIMER_TIME(info, string, info->flush_time_usec)
  1434. #else
  1435. #define START_FLUSH_FAST_TIMER_TIME(info, string, usec)
  1436. #define START_FLUSH_FAST_TIMER(info, string)
  1437. #endif
  1438. static struct etrax_recv_buffer *
  1439. alloc_recv_buffer(unsigned int size)
  1440. {
  1441. struct etrax_recv_buffer *buffer;
  1442. buffer = kmalloc(sizeof *buffer + size, GFP_ATOMIC);
  1443. if (!buffer)
  1444. return NULL;
  1445. buffer->next = NULL;
  1446. buffer->length = 0;
  1447. buffer->error = TTY_NORMAL;
  1448. return buffer;
  1449. }
  1450. static void
  1451. append_recv_buffer(struct e100_serial *info, struct etrax_recv_buffer *buffer)
  1452. {
  1453. unsigned long flags;
  1454. local_irq_save(flags);
  1455. if (!info->first_recv_buffer)
  1456. info->first_recv_buffer = buffer;
  1457. else
  1458. info->last_recv_buffer->next = buffer;
  1459. info->last_recv_buffer = buffer;
  1460. info->recv_cnt += buffer->length;
  1461. if (info->recv_cnt > info->max_recv_cnt)
  1462. info->max_recv_cnt = info->recv_cnt;
  1463. local_irq_restore(flags);
  1464. }
  1465. static int
  1466. add_char_and_flag(struct e100_serial *info, unsigned char data, unsigned char flag)
  1467. {
  1468. struct etrax_recv_buffer *buffer;
  1469. if (info->uses_dma_in) {
  1470. buffer = alloc_recv_buffer(4);
  1471. if (!buffer)
  1472. return 0;
  1473. buffer->length = 1;
  1474. buffer->error = flag;
  1475. buffer->buffer[0] = data;
  1476. append_recv_buffer(info, buffer);
  1477. info->icount.rx++;
  1478. } else {
  1479. tty_insert_flip_char(&info->port, data, flag);
  1480. info->icount.rx++;
  1481. }
  1482. return 1;
  1483. }
  1484. static unsigned int handle_descr_data(struct e100_serial *info,
  1485. struct etrax_dma_descr *descr,
  1486. unsigned int recvl)
  1487. {
  1488. struct etrax_recv_buffer *buffer = phys_to_virt(descr->buf) - sizeof *buffer;
  1489. if (info->recv_cnt + recvl > 65536) {
  1490. printk(KERN_WARNING
  1491. "%s: Too much pending incoming serial data! Dropping %u bytes.\n", __func__, recvl);
  1492. return 0;
  1493. }
  1494. buffer->length = recvl;
  1495. if (info->errorcode == ERRCODE_SET_BREAK)
  1496. buffer->error = TTY_BREAK;
  1497. info->errorcode = 0;
  1498. append_recv_buffer(info, buffer);
  1499. buffer = alloc_recv_buffer(SERIAL_DESCR_BUF_SIZE);
  1500. if (!buffer)
  1501. panic("%s: Failed to allocate memory for receive buffer!\n", __func__);
  1502. descr->buf = virt_to_phys(buffer->buffer);
  1503. return recvl;
  1504. }
  1505. static unsigned int handle_all_descr_data(struct e100_serial *info)
  1506. {
  1507. struct etrax_dma_descr *descr;
  1508. unsigned int recvl;
  1509. unsigned int ret = 0;
  1510. while (1)
  1511. {
  1512. descr = &info->rec_descr[info->cur_rec_descr];
  1513. if (descr == phys_to_virt(*info->idescradr))
  1514. break;
  1515. if (++info->cur_rec_descr == SERIAL_RECV_DESCRIPTORS)
  1516. info->cur_rec_descr = 0;
  1517. /* find out how many bytes were read */
  1518. /* if the eop bit was not set, all data has been received */
  1519. if (!(descr->status & d_eop)) {
  1520. recvl = descr->sw_len;
  1521. } else {
  1522. /* otherwise we find the amount of data received here */
  1523. recvl = descr->hw_len;
  1524. }
  1525. /* Reset the status information */
  1526. descr->status = 0;
  1527. DFLOW( DEBUG_LOG(info->line, "RX %lu\n", recvl);
  1528. if (info->port.tty->stopped) {
  1529. unsigned char *buf = phys_to_virt(descr->buf);
  1530. DEBUG_LOG(info->line, "rx 0x%02X\n", buf[0]);
  1531. DEBUG_LOG(info->line, "rx 0x%02X\n", buf[1]);
  1532. DEBUG_LOG(info->line, "rx 0x%02X\n", buf[2]);
  1533. }
  1534. );
  1535. /* update stats */
  1536. info->icount.rx += recvl;
  1537. ret += handle_descr_data(info, descr, recvl);
  1538. }
  1539. return ret;
  1540. }
  1541. static void receive_chars_dma(struct e100_serial *info)
  1542. {
  1543. struct tty_struct *tty;
  1544. unsigned char rstat;
  1545. /* Acknowledge both dma_descr and dma_eop irq in R_DMA_CHx_CLR_INTR */
  1546. *info->iclrintradr =
  1547. IO_STATE(R_DMA_CH6_CLR_INTR, clr_descr, do) |
  1548. IO_STATE(R_DMA_CH6_CLR_INTR, clr_eop, do);
  1549. tty = info->port.tty;
  1550. if (!tty) /* Something wrong... */
  1551. return;
  1552. #ifdef SERIAL_HANDLE_EARLY_ERRORS
  1553. if (info->uses_dma_in)
  1554. e100_enable_serial_data_irq(info);
  1555. #endif
  1556. if (info->errorcode == ERRCODE_INSERT_BREAK)
  1557. add_char_and_flag(info, '\0', TTY_BREAK);
  1558. handle_all_descr_data(info);
  1559. /* Read the status register to detect errors */
  1560. rstat = info->ioport[REG_STATUS];
  1561. if (rstat & IO_MASK(R_SERIAL0_STATUS, xoff_detect) ) {
  1562. DFLOW(DEBUG_LOG(info->line, "XOFF detect stat %x\n", rstat));
  1563. }
  1564. if (rstat & SER_ERROR_MASK) {
  1565. /* If we got an error, we must reset it by reading the
  1566. * data_in field
  1567. */
  1568. unsigned char data = info->ioport[REG_DATA];
  1569. DEBUG_LOG(info->line, "#dERR: s d 0x%04X\n",
  1570. ((rstat & SER_ERROR_MASK) << 8) | data);
  1571. if (rstat & SER_PAR_ERR_MASK)
  1572. add_char_and_flag(info, data, TTY_PARITY);
  1573. else if (rstat & SER_OVERRUN_MASK)
  1574. add_char_and_flag(info, data, TTY_OVERRUN);
  1575. else if (rstat & SER_FRAMING_ERR_MASK)
  1576. add_char_and_flag(info, data, TTY_FRAME);
  1577. }
  1578. START_FLUSH_FAST_TIMER(info, "receive_chars");
  1579. /* Restart the receiving DMA */
  1580. *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, restart);
  1581. }
  1582. static int start_recv_dma(struct e100_serial *info)
  1583. {
  1584. struct etrax_dma_descr *descr = info->rec_descr;
  1585. struct etrax_recv_buffer *buffer;
  1586. int i;
  1587. /* Set up the receiving descriptors */
  1588. for (i = 0; i < SERIAL_RECV_DESCRIPTORS; i++) {
  1589. buffer = alloc_recv_buffer(SERIAL_DESCR_BUF_SIZE);
  1590. if (!buffer)
  1591. panic("%s: Failed to allocate memory for receive buffer!\n", __func__);
  1592. descr[i].ctrl = d_int;
  1593. descr[i].buf = virt_to_phys(buffer->buffer);
  1594. descr[i].sw_len = SERIAL_DESCR_BUF_SIZE;
  1595. descr[i].hw_len = 0;
  1596. descr[i].status = 0;
  1597. descr[i].next = virt_to_phys(&descr[i+1]);
  1598. }
  1599. /* Link the last descriptor to the first */
  1600. descr[i-1].next = virt_to_phys(&descr[0]);
  1601. /* Start with the first descriptor in the list */
  1602. info->cur_rec_descr = 0;
  1603. /* Start the DMA */
  1604. *info->ifirstadr = virt_to_phys(&descr[info->cur_rec_descr]);
  1605. *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, start);
  1606. /* Input DMA should be running now */
  1607. return 1;
  1608. }
  1609. static void
  1610. start_receive(struct e100_serial *info)
  1611. {
  1612. if (info->uses_dma_in) {
  1613. /* reset the input dma channel to be sure it works */
  1614. *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, reset);
  1615. while (IO_EXTRACT(R_DMA_CH6_CMD, cmd, *info->icmdadr) ==
  1616. IO_STATE_VALUE(R_DMA_CH6_CMD, cmd, reset));
  1617. start_recv_dma(info);
  1618. }
  1619. }
  1620. /* the bits in the MASK2 register are laid out like this:
  1621. DMAI_EOP DMAI_DESCR DMAO_EOP DMAO_DESCR
  1622. where I is the input channel and O is the output channel for the port.
  1623. info->irq is the bit number for the DMAO_DESCR so to check the others we
  1624. shift info->irq to the left.
  1625. */
  1626. /* dma output channel interrupt handler
  1627. this interrupt is called from DMA2(ser2), DMA4(ser3), DMA6(ser0) or
  1628. DMA8(ser1) when they have finished a descriptor with the intr flag set.
  1629. */
  1630. static irqreturn_t
  1631. tr_interrupt(int irq, void *dev_id)
  1632. {
  1633. struct e100_serial *info;
  1634. unsigned long ireg;
  1635. int i;
  1636. int handled = 0;
  1637. /* find out the line that caused this irq and get it from rs_table */
  1638. ireg = *R_IRQ_MASK2_RD; /* get the active irq bits for the dma channels */
  1639. for (i = 0; i < NR_PORTS; i++) {
  1640. info = rs_table + i;
  1641. if (!info->enabled || !info->uses_dma_out)
  1642. continue;
  1643. /* check for dma_descr (don't need to check for dma_eop in output dma for serial */
  1644. if (ireg & info->irq) {
  1645. handled = 1;
  1646. /* we can send a new dma bunch. make it so. */
  1647. DINTR2(DEBUG_LOG(info->line, "tr_interrupt %i\n", i));
  1648. /* Read jiffies_usec first,
  1649. * we want this time to be as late as possible
  1650. */
  1651. info->last_tx_active_usec = GET_JIFFIES_USEC();
  1652. info->last_tx_active = jiffies;
  1653. transmit_chars_dma(info);
  1654. }
  1655. /* FIXME: here we should really check for a change in the
  1656. status lines and if so call status_handle(info) */
  1657. }
  1658. return IRQ_RETVAL(handled);
  1659. } /* tr_interrupt */
  1660. /* dma input channel interrupt handler */
  1661. static irqreturn_t
  1662. rec_interrupt(int irq, void *dev_id)
  1663. {
  1664. struct e100_serial *info;
  1665. unsigned long ireg;
  1666. int i;
  1667. int handled = 0;
  1668. /* find out the line that caused this irq and get it from rs_table */
  1669. ireg = *R_IRQ_MASK2_RD; /* get the active irq bits for the dma channels */
  1670. for (i = 0; i < NR_PORTS; i++) {
  1671. info = rs_table + i;
  1672. if (!info->enabled || !info->uses_dma_in)
  1673. continue;
  1674. /* check for both dma_eop and dma_descr for the input dma channel */
  1675. if (ireg & ((info->irq << 2) | (info->irq << 3))) {
  1676. handled = 1;
  1677. /* we have received something */
  1678. receive_chars_dma(info);
  1679. }
  1680. /* FIXME: here we should really check for a change in the
  1681. status lines and if so call status_handle(info) */
  1682. }
  1683. return IRQ_RETVAL(handled);
  1684. } /* rec_interrupt */
  1685. static int force_eop_if_needed(struct e100_serial *info)
  1686. {
  1687. /* We check data_avail bit to determine if data has
  1688. * arrived since last time
  1689. */
  1690. unsigned char rstat = info->ioport[REG_STATUS];
  1691. /* error or datavail? */
  1692. if (rstat & SER_ERROR_MASK) {
  1693. /* Some error has occurred. If there has been valid data, an
  1694. * EOP interrupt will be made automatically. If no data, the
  1695. * normal ser_interrupt should be enabled and handle it.
  1696. * So do nothing!
  1697. */
  1698. DEBUG_LOG(info->line, "timeout err: rstat 0x%03X\n",
  1699. rstat | (info->line << 8));
  1700. return 0;
  1701. }
  1702. if (rstat & SER_DATA_AVAIL_MASK) {
  1703. /* Ok data, no error, count it */
  1704. TIMERD(DEBUG_LOG(info->line, "timeout: rstat 0x%03X\n",
  1705. rstat | (info->line << 8)));
  1706. /* Read data to clear status flags */
  1707. (void)info->ioport[REG_DATA];
  1708. info->forced_eop = 0;
  1709. START_FLUSH_FAST_TIMER(info, "magic");
  1710. return 0;
  1711. }
  1712. /* hit the timeout, force an EOP for the input
  1713. * dma channel if we haven't already
  1714. */
  1715. if (!info->forced_eop) {
  1716. info->forced_eop = 1;
  1717. TIMERD(DEBUG_LOG(info->line, "timeout EOP %i\n", info->line));
  1718. FORCE_EOP(info);
  1719. }
  1720. return 1;
  1721. }
  1722. static void flush_to_flip_buffer(struct e100_serial *info)
  1723. {
  1724. struct etrax_recv_buffer *buffer;
  1725. unsigned long flags;
  1726. local_irq_save(flags);
  1727. while ((buffer = info->first_recv_buffer) != NULL) {
  1728. unsigned int count = buffer->length;
  1729. tty_insert_flip_string(&info->port, buffer->buffer, count);
  1730. info->recv_cnt -= count;
  1731. if (count == buffer->length) {
  1732. info->first_recv_buffer = buffer->next;
  1733. kfree(buffer);
  1734. } else {
  1735. buffer->length -= count;
  1736. memmove(buffer->buffer, buffer->buffer + count, buffer->length);
  1737. buffer->error = TTY_NORMAL;
  1738. }
  1739. }
  1740. if (!info->first_recv_buffer)
  1741. info->last_recv_buffer = NULL;
  1742. local_irq_restore(flags);
  1743. /* This includes a check for low-latency */
  1744. tty_flip_buffer_push(&info->port);
  1745. }
  1746. static void check_flush_timeout(struct e100_serial *info)
  1747. {
  1748. /* Flip what we've got (if we can) */
  1749. flush_to_flip_buffer(info);
  1750. /* We might need to flip later, but not to fast
  1751. * since the system is busy processing input... */
  1752. if (info->first_recv_buffer)
  1753. START_FLUSH_FAST_TIMER_TIME(info, "flip", 2000);
  1754. /* Force eop last, since data might have come while we're processing
  1755. * and if we started the slow timer above, we won't start a fast
  1756. * below.
  1757. */
  1758. force_eop_if_needed(info);
  1759. }
  1760. #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER
  1761. static void flush_timeout_function(unsigned long data)
  1762. {
  1763. struct e100_serial *info = (struct e100_serial *)data;
  1764. fast_timers[info->line].function = NULL;
  1765. serial_fast_timer_expired++;
  1766. TIMERD(DEBUG_LOG(info->line, "flush_timeout %i ", info->line));
  1767. TIMERD(DEBUG_LOG(info->line, "num expired: %i\n", serial_fast_timer_expired));
  1768. check_flush_timeout(info);
  1769. }
  1770. #else
  1771. /* dma fifo/buffer timeout handler
  1772. forces an end-of-packet for the dma input channel if no chars
  1773. have been received for CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS/100 s.
  1774. */
  1775. static struct timer_list flush_timer;
  1776. static void
  1777. timed_flush_handler(unsigned long ptr)
  1778. {
  1779. struct e100_serial *info;
  1780. int i;
  1781. for (i = 0; i < NR_PORTS; i++) {
  1782. info = rs_table + i;
  1783. if (info->uses_dma_in)
  1784. check_flush_timeout(info);
  1785. }
  1786. /* restart flush timer */
  1787. mod_timer(&flush_timer, jiffies + CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS);
  1788. }
  1789. #endif
  1790. #ifdef SERIAL_HANDLE_EARLY_ERRORS
  1791. /* If there is an error (ie break) when the DMA is running and
  1792. * there are no bytes in the fifo the DMA is stopped and we get no
  1793. * eop interrupt. Thus we have to monitor the first bytes on a DMA
  1794. * transfer, and if it is without error we can turn the serial
  1795. * interrupts off.
  1796. */
  1797. /*
  1798. BREAK handling on ETRAX 100:
  1799. ETRAX will generate interrupt although there is no stop bit between the
  1800. characters.
  1801. Depending on how long the break sequence is, the end of the breaksequence
  1802. will look differently:
  1803. | indicates start/end of a character.
  1804. B= Break character (0x00) with framing error.
  1805. E= Error byte with parity error received after B characters.
  1806. F= "Faked" valid byte received immediately after B characters.
  1807. V= Valid byte
  1808. 1.
  1809. B BL ___________________________ V
  1810. .._|__________|__________| |valid data |
  1811. Multiple frame errors with data == 0x00 (B),
  1812. the timing matches up "perfectly" so no extra ending char is detected.
  1813. The RXD pin is 1 in the last interrupt, in that case
  1814. we set info->errorcode = ERRCODE_INSERT_BREAK, but we can't really
  1815. know if another byte will come and this really is case 2. below
  1816. (e.g F=0xFF or 0xFE)
  1817. If RXD pin is 0 we can expect another character (see 2. below).
  1818. 2.
  1819. B B E or F__________________..__ V
  1820. .._|__________|__________|______ | |valid data
  1821. "valid" or
  1822. parity error
  1823. Multiple frame errors with data == 0x00 (B),
  1824. but the part of the break trigs is interpreted as a start bit (and possibly
  1825. some 0 bits followed by a number of 1 bits and a stop bit).
  1826. Depending on parity settings etc. this last character can be either
  1827. a fake "valid" char (F) or have a parity error (E).
  1828. If the character is valid it will be put in the buffer,
  1829. we set info->errorcode = ERRCODE_SET_BREAK so the receive interrupt
  1830. will set the flags so the tty will handle it,
  1831. if it's an error byte it will not be put in the buffer
  1832. and we set info->errorcode = ERRCODE_INSERT_BREAK.
  1833. To distinguish a V byte in 1. from an F byte in 2. we keep a timestamp
  1834. of the last faulty char (B) and compares it with the current time:
  1835. If the time elapsed time is less then 2*char_time_usec we will assume
  1836. it's a faked F char and not a Valid char and set
  1837. info->errorcode = ERRCODE_SET_BREAK.
  1838. Flaws in the above solution:
  1839. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1840. We use the timer to distinguish a F character from a V character,
  1841. if a V character is to close after the break we might make the wrong decision.
  1842. TODO: The break will be delayed until an F or V character is received.
  1843. */
  1844. static void handle_ser_rx_interrupt_no_dma(struct e100_serial *info)
  1845. {
  1846. unsigned long data_read;
  1847. /* Read data and status at the same time */
  1848. data_read = *((unsigned long *)&info->ioport[REG_DATA_STATUS32]);
  1849. more_data:
  1850. if (data_read & IO_MASK(R_SERIAL0_READ, xoff_detect) ) {
  1851. DFLOW(DEBUG_LOG(info->line, "XOFF detect\n", 0));
  1852. }
  1853. DINTR2(DEBUG_LOG(info->line, "ser_rx %c\n", IO_EXTRACT(R_SERIAL0_READ, data_in, data_read)));
  1854. if (data_read & ( IO_MASK(R_SERIAL0_READ, framing_err) |
  1855. IO_MASK(R_SERIAL0_READ, par_err) |
  1856. IO_MASK(R_SERIAL0_READ, overrun) )) {
  1857. /* An error */
  1858. info->last_rx_active_usec = GET_JIFFIES_USEC();
  1859. info->last_rx_active = jiffies;
  1860. DINTR1(DEBUG_LOG(info->line, "ser_rx err stat_data %04X\n", data_read));
  1861. DLOG_INT_TRIG(
  1862. if (!log_int_trig1_pos) {
  1863. log_int_trig1_pos = log_int_pos;
  1864. log_int(rdpc(), 0, 0);
  1865. }
  1866. );
  1867. if ( ((data_read & IO_MASK(R_SERIAL0_READ, data_in)) == 0) &&
  1868. (data_read & IO_MASK(R_SERIAL0_READ, framing_err)) ) {
  1869. /* Most likely a break, but we get interrupts over and
  1870. * over again.
  1871. */
  1872. if (!info->break_detected_cnt) {
  1873. DEBUG_LOG(info->line, "#BRK start\n", 0);
  1874. }
  1875. if (data_read & IO_MASK(R_SERIAL0_READ, rxd)) {
  1876. /* The RX pin is high now, so the break
  1877. * must be over, but....
  1878. * we can't really know if we will get another
  1879. * last byte ending the break or not.
  1880. * And we don't know if the byte (if any) will
  1881. * have an error or look valid.
  1882. */
  1883. DEBUG_LOG(info->line, "# BL BRK\n", 0);
  1884. info->errorcode = ERRCODE_INSERT_BREAK;
  1885. }
  1886. info->break_detected_cnt++;
  1887. } else {
  1888. /* The error does not look like a break, but could be
  1889. * the end of one
  1890. */
  1891. if (info->break_detected_cnt) {
  1892. DEBUG_LOG(info->line, "EBRK %i\n", info->break_detected_cnt);
  1893. info->errorcode = ERRCODE_INSERT_BREAK;
  1894. } else {
  1895. unsigned char data = IO_EXTRACT(R_SERIAL0_READ,
  1896. data_in, data_read);
  1897. char flag = TTY_NORMAL;
  1898. if (info->errorcode == ERRCODE_INSERT_BREAK) {
  1899. tty_insert_flip_char(&info->port, 0, flag);
  1900. info->icount.rx++;
  1901. }
  1902. if (data_read & IO_MASK(R_SERIAL0_READ, par_err)) {
  1903. info->icount.parity++;
  1904. flag = TTY_PARITY;
  1905. } else if (data_read & IO_MASK(R_SERIAL0_READ, overrun)) {
  1906. info->icount.overrun++;
  1907. flag = TTY_OVERRUN;
  1908. } else if (data_read & IO_MASK(R_SERIAL0_READ, framing_err)) {
  1909. info->icount.frame++;
  1910. flag = TTY_FRAME;
  1911. }
  1912. tty_insert_flip_char(&info->port, data, flag);
  1913. info->errorcode = 0;
  1914. }
  1915. info->break_detected_cnt = 0;
  1916. }
  1917. } else if (data_read & IO_MASK(R_SERIAL0_READ, data_avail)) {
  1918. /* No error */
  1919. DLOG_INT_TRIG(
  1920. if (!log_int_trig1_pos) {
  1921. if (log_int_pos >= log_int_size) {
  1922. log_int_pos = 0;
  1923. }
  1924. log_int_trig0_pos = log_int_pos;
  1925. log_int(rdpc(), 0, 0);
  1926. }
  1927. );
  1928. tty_insert_flip_char(&info->port,
  1929. IO_EXTRACT(R_SERIAL0_READ, data_in, data_read),
  1930. TTY_NORMAL);
  1931. } else {
  1932. DEBUG_LOG(info->line, "ser_rx int but no data_avail %08lX\n", data_read);
  1933. }
  1934. info->icount.rx++;
  1935. data_read = *((unsigned long *)&info->ioport[REG_DATA_STATUS32]);
  1936. if (data_read & IO_MASK(R_SERIAL0_READ, data_avail)) {
  1937. DEBUG_LOG(info->line, "ser_rx %c in loop\n", IO_EXTRACT(R_SERIAL0_READ, data_in, data_read));
  1938. goto more_data;
  1939. }
  1940. tty_flip_buffer_push(&info->port);
  1941. }
  1942. static void handle_ser_rx_interrupt(struct e100_serial *info)
  1943. {
  1944. unsigned char rstat;
  1945. #ifdef SERIAL_DEBUG_INTR
  1946. printk("Interrupt from serport %d\n", i);
  1947. #endif
  1948. /* DEBUG_LOG(info->line, "ser_interrupt stat %03X\n", rstat | (i << 8)); */
  1949. if (!info->uses_dma_in) {
  1950. handle_ser_rx_interrupt_no_dma(info);
  1951. return;
  1952. }
  1953. /* DMA is used */
  1954. rstat = info->ioport[REG_STATUS];
  1955. if (rstat & IO_MASK(R_SERIAL0_STATUS, xoff_detect) ) {
  1956. DFLOW(DEBUG_LOG(info->line, "XOFF detect\n", 0));
  1957. }
  1958. if (rstat & SER_ERROR_MASK) {
  1959. unsigned char data;
  1960. info->last_rx_active_usec = GET_JIFFIES_USEC();
  1961. info->last_rx_active = jiffies;
  1962. /* If we got an error, we must reset it by reading the
  1963. * data_in field
  1964. */
  1965. data = info->ioport[REG_DATA];
  1966. DINTR1(DEBUG_LOG(info->line, "ser_rx! %c\n", data));
  1967. DINTR1(DEBUG_LOG(info->line, "ser_rx err stat %02X\n", rstat));
  1968. if (!data && (rstat & SER_FRAMING_ERR_MASK)) {
  1969. /* Most likely a break, but we get interrupts over and
  1970. * over again.
  1971. */
  1972. if (!info->break_detected_cnt) {
  1973. DEBUG_LOG(info->line, "#BRK start\n", 0);
  1974. }
  1975. if (rstat & SER_RXD_MASK) {
  1976. /* The RX pin is high now, so the break
  1977. * must be over, but....
  1978. * we can't really know if we will get another
  1979. * last byte ending the break or not.
  1980. * And we don't know if the byte (if any) will
  1981. * have an error or look valid.
  1982. */
  1983. DEBUG_LOG(info->line, "# BL BRK\n", 0);
  1984. info->errorcode = ERRCODE_INSERT_BREAK;
  1985. }
  1986. info->break_detected_cnt++;
  1987. } else {
  1988. /* The error does not look like a break, but could be
  1989. * the end of one
  1990. */
  1991. if (info->break_detected_cnt) {
  1992. DEBUG_LOG(info->line, "EBRK %i\n", info->break_detected_cnt);
  1993. info->errorcode = ERRCODE_INSERT_BREAK;
  1994. } else {
  1995. if (info->errorcode == ERRCODE_INSERT_BREAK) {
  1996. info->icount.brk++;
  1997. add_char_and_flag(info, '\0', TTY_BREAK);
  1998. }
  1999. if (rstat & SER_PAR_ERR_MASK) {
  2000. info->icount.parity++;
  2001. add_char_and_flag(info, data, TTY_PARITY);
  2002. } else if (rstat & SER_OVERRUN_MASK) {
  2003. info->icount.overrun++;
  2004. add_char_and_flag(info, data, TTY_OVERRUN);
  2005. } else if (rstat & SER_FRAMING_ERR_MASK) {
  2006. info->icount.frame++;
  2007. add_char_and_flag(info, data, TTY_FRAME);
  2008. }
  2009. info->errorcode = 0;
  2010. }
  2011. info->break_detected_cnt = 0;
  2012. DEBUG_LOG(info->line, "#iERR s d %04X\n",
  2013. ((rstat & SER_ERROR_MASK) << 8) | data);
  2014. }
  2015. } else { /* It was a valid byte, now let the DMA do the rest */
  2016. unsigned long curr_time_u = GET_JIFFIES_USEC();
  2017. unsigned long curr_time = jiffies;
  2018. if (info->break_detected_cnt) {
  2019. /* Detect if this character is a new valid char or the
  2020. * last char in a break sequence: If LSBits are 0 and
  2021. * MSBits are high AND the time is close to the
  2022. * previous interrupt we should discard it.
  2023. */
  2024. long elapsed_usec =
  2025. (curr_time - info->last_rx_active) * (1000000/HZ) +
  2026. curr_time_u - info->last_rx_active_usec;
  2027. if (elapsed_usec < 2*info->char_time_usec) {
  2028. DEBUG_LOG(info->line, "FBRK %i\n", info->line);
  2029. /* Report as BREAK (error) and let
  2030. * receive_chars_dma() handle it
  2031. */
  2032. info->errorcode = ERRCODE_SET_BREAK;
  2033. } else {
  2034. DEBUG_LOG(info->line, "Not end of BRK (V)%i\n", info->line);
  2035. }
  2036. DEBUG_LOG(info->line, "num brk %i\n", info->break_detected_cnt);
  2037. }
  2038. #ifdef SERIAL_DEBUG_INTR
  2039. printk("** OK, disabling ser_interrupts\n");
  2040. #endif
  2041. e100_disable_serial_data_irq(info);
  2042. DINTR2(DEBUG_LOG(info->line, "ser_rx OK %d\n", info->line));
  2043. info->break_detected_cnt = 0;
  2044. }
  2045. /* Restarting the DMA never hurts */
  2046. *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, restart);
  2047. START_FLUSH_FAST_TIMER(info, "ser_int");
  2048. } /* handle_ser_rx_interrupt */
  2049. static void handle_ser_tx_interrupt(struct e100_serial *info)
  2050. {
  2051. unsigned long flags;
  2052. if (info->x_char) {
  2053. unsigned char rstat;
  2054. DFLOW(DEBUG_LOG(info->line, "tx_int: xchar 0x%02X\n", info->x_char));
  2055. local_irq_save(flags);
  2056. rstat = info->ioport[REG_STATUS];
  2057. DFLOW(DEBUG_LOG(info->line, "stat %x\n", rstat));
  2058. info->ioport[REG_TR_DATA] = info->x_char;
  2059. info->icount.tx++;
  2060. info->x_char = 0;
  2061. /* We must enable since it is disabled in ser_interrupt */
  2062. e100_enable_serial_tx_ready_irq(info);
  2063. local_irq_restore(flags);
  2064. return;
  2065. }
  2066. if (info->uses_dma_out) {
  2067. unsigned char rstat;
  2068. int i;
  2069. /* We only use normal tx interrupt when sending x_char */
  2070. DFLOW(DEBUG_LOG(info->line, "tx_int: xchar sent\n", 0));
  2071. local_irq_save(flags);
  2072. rstat = info->ioport[REG_STATUS];
  2073. DFLOW(DEBUG_LOG(info->line, "stat %x\n", rstat));
  2074. e100_disable_serial_tx_ready_irq(info);
  2075. if (info->port.tty->stopped)
  2076. rs_stop(info->port.tty);
  2077. /* Enable the DMA channel and tell it to continue */
  2078. e100_enable_txdma_channel(info);
  2079. /* Wait 12 cycles before doing the DMA command */
  2080. for(i = 6; i > 0; i--)
  2081. nop();
  2082. *info->ocmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, continue);
  2083. local_irq_restore(flags);
  2084. return;
  2085. }
  2086. /* Normal char-by-char interrupt */
  2087. if (info->xmit.head == info->xmit.tail
  2088. || info->port.tty->stopped) {
  2089. DFLOW(DEBUG_LOG(info->line, "tx_int: stopped %i\n",
  2090. info->port.tty->stopped));
  2091. e100_disable_serial_tx_ready_irq(info);
  2092. info->tr_running = 0;
  2093. return;
  2094. }
  2095. DINTR2(DEBUG_LOG(info->line, "tx_int %c\n", info->xmit.buf[info->xmit.tail]));
  2096. /* Send a byte, rs485 timing is critical so turn of ints */
  2097. local_irq_save(flags);
  2098. info->ioport[REG_TR_DATA] = info->xmit.buf[info->xmit.tail];
  2099. info->xmit.tail = (info->xmit.tail + 1) & (SERIAL_XMIT_SIZE-1);
  2100. info->icount.tx++;
  2101. if (info->xmit.head == info->xmit.tail) {
  2102. #if defined(CONFIG_ETRAX_RS485) && defined(CONFIG_ETRAX_FAST_TIMER)
  2103. if (info->rs485.flags & SER_RS485_ENABLED) {
  2104. /* Set a short timer to toggle RTS */
  2105. start_one_shot_timer(&fast_timers_rs485[info->line],
  2106. rs485_toggle_rts_timer_function,
  2107. (unsigned long)info,
  2108. info->char_time_usec*2,
  2109. "RS-485");
  2110. }
  2111. #endif /* RS485 */
  2112. info->last_tx_active_usec = GET_JIFFIES_USEC();
  2113. info->last_tx_active = jiffies;
  2114. e100_disable_serial_tx_ready_irq(info);
  2115. info->tr_running = 0;
  2116. DFLOW(DEBUG_LOG(info->line, "tx_int: stop2\n", 0));
  2117. } else {
  2118. /* We must enable since it is disabled in ser_interrupt */
  2119. e100_enable_serial_tx_ready_irq(info);
  2120. }
  2121. local_irq_restore(flags);
  2122. if (CIRC_CNT(info->xmit.head,
  2123. info->xmit.tail,
  2124. SERIAL_XMIT_SIZE) < WAKEUP_CHARS)
  2125. rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
  2126. } /* handle_ser_tx_interrupt */
  2127. /* result of time measurements:
  2128. * RX duration 54-60 us when doing something, otherwise 6-9 us
  2129. * ser_int duration: just sending: 8-15 us normally, up to 73 us
  2130. */
  2131. static irqreturn_t
  2132. ser_interrupt(int irq, void *dev_id)
  2133. {
  2134. static volatile int tx_started = 0;
  2135. struct e100_serial *info;
  2136. int i;
  2137. unsigned long flags;
  2138. unsigned long irq_mask1_rd;
  2139. unsigned long data_mask = (1 << (8+2*0)); /* ser0 data_avail */
  2140. int handled = 0;
  2141. static volatile unsigned long reentered_ready_mask = 0;
  2142. local_irq_save(flags);
  2143. irq_mask1_rd = *R_IRQ_MASK1_RD;
  2144. /* First handle all rx interrupts with ints disabled */
  2145. info = rs_table;
  2146. irq_mask1_rd &= e100_ser_int_mask;
  2147. for (i = 0; i < NR_PORTS; i++) {
  2148. /* Which line caused the data irq? */
  2149. if (irq_mask1_rd & data_mask) {
  2150. handled = 1;
  2151. handle_ser_rx_interrupt(info);
  2152. }
  2153. info += 1;
  2154. data_mask <<= 2;
  2155. }
  2156. /* Handle tx interrupts with interrupts enabled so we
  2157. * can take care of new data interrupts while transmitting
  2158. * We protect the tx part with the tx_started flag.
  2159. * We disable the tr_ready interrupts we are about to handle and
  2160. * unblock the serial interrupt so new serial interrupts may come.
  2161. *
  2162. * If we get a new interrupt:
  2163. * - it migth be due to synchronous serial ports.
  2164. * - serial irq will be blocked by general irq handler.
  2165. * - async data will be handled above (sync will be ignored).
  2166. * - tx_started flag will prevent us from trying to send again and
  2167. * we will exit fast - no need to unblock serial irq.
  2168. * - Next (sync) serial interrupt handler will be runned with
  2169. * disabled interrupt due to restore_flags() at end of function,
  2170. * so sync handler will not be preempted or reentered.
  2171. */
  2172. if (!tx_started) {
  2173. unsigned long ready_mask;
  2174. unsigned long
  2175. tx_started = 1;
  2176. /* Only the tr_ready interrupts left */
  2177. irq_mask1_rd &= (IO_MASK(R_IRQ_MASK1_RD, ser0_ready) |
  2178. IO_MASK(R_IRQ_MASK1_RD, ser1_ready) |
  2179. IO_MASK(R_IRQ_MASK1_RD, ser2_ready) |
  2180. IO_MASK(R_IRQ_MASK1_RD, ser3_ready));
  2181. while (irq_mask1_rd) {
  2182. /* Disable those we are about to handle */
  2183. *R_IRQ_MASK1_CLR = irq_mask1_rd;
  2184. /* Unblock the serial interrupt */
  2185. *R_VECT_MASK_SET = IO_STATE(R_VECT_MASK_SET, serial, set);
  2186. local_irq_enable();
  2187. ready_mask = (1 << (8+1+2*0)); /* ser0 tr_ready */
  2188. info = rs_table;
  2189. for (i = 0; i < NR_PORTS; i++) {
  2190. /* Which line caused the ready irq? */
  2191. if (irq_mask1_rd & ready_mask) {
  2192. handled = 1;
  2193. handle_ser_tx_interrupt(info);
  2194. }
  2195. info += 1;
  2196. ready_mask <<= 2;
  2197. }
  2198. /* handle_ser_tx_interrupt enables tr_ready interrupts */
  2199. local_irq_disable();
  2200. /* Handle reentered TX interrupt */
  2201. irq_mask1_rd = reentered_ready_mask;
  2202. }
  2203. local_irq_disable();
  2204. tx_started = 0;
  2205. } else {
  2206. unsigned long ready_mask;
  2207. ready_mask = irq_mask1_rd & (IO_MASK(R_IRQ_MASK1_RD, ser0_ready) |
  2208. IO_MASK(R_IRQ_MASK1_RD, ser1_ready) |
  2209. IO_MASK(R_IRQ_MASK1_RD, ser2_ready) |
  2210. IO_MASK(R_IRQ_MASK1_RD, ser3_ready));
  2211. if (ready_mask) {
  2212. reentered_ready_mask |= ready_mask;
  2213. /* Disable those we are about to handle */
  2214. *R_IRQ_MASK1_CLR = ready_mask;
  2215. DFLOW(DEBUG_LOG(SERIAL_DEBUG_LINE, "ser_int reentered with TX %X\n", ready_mask));
  2216. }
  2217. }
  2218. local_irq_restore(flags);
  2219. return IRQ_RETVAL(handled);
  2220. } /* ser_interrupt */
  2221. #endif
  2222. /*
  2223. * -------------------------------------------------------------------
  2224. * Here ends the serial interrupt routines.
  2225. * -------------------------------------------------------------------
  2226. */
  2227. /*
  2228. * This routine is used to handle the "bottom half" processing for the
  2229. * serial driver, known also the "software interrupt" processing.
  2230. * This processing is done at the kernel interrupt level, after the
  2231. * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
  2232. * is where time-consuming activities which can not be done in the
  2233. * interrupt driver proper are done; the interrupt driver schedules
  2234. * them using rs_sched_event(), and they get done here.
  2235. */
  2236. static void
  2237. do_softint(struct work_struct *work)
  2238. {
  2239. struct e100_serial *info;
  2240. struct tty_struct *tty;
  2241. info = container_of(work, struct e100_serial, work);
  2242. tty = info->port.tty;
  2243. if (!tty)
  2244. return;
  2245. if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event))
  2246. tty_wakeup(tty);
  2247. }
  2248. static int
  2249. startup(struct e100_serial * info)
  2250. {
  2251. unsigned long flags;
  2252. unsigned long xmit_page;
  2253. int i;
  2254. xmit_page = get_zeroed_page(GFP_KERNEL);
  2255. if (!xmit_page)
  2256. return -ENOMEM;
  2257. local_irq_save(flags);
  2258. /* if it was already initialized, skip this */
  2259. if (info->port.flags & ASYNC_INITIALIZED) {
  2260. local_irq_restore(flags);
  2261. free_page(xmit_page);
  2262. return 0;
  2263. }
  2264. if (info->xmit.buf)
  2265. free_page(xmit_page);
  2266. else
  2267. info->xmit.buf = (unsigned char *) xmit_page;
  2268. #ifdef SERIAL_DEBUG_OPEN
  2269. printk("starting up ttyS%d (xmit_buf 0x%p)...\n", info->line, info->xmit.buf);
  2270. #endif
  2271. /*
  2272. * Clear the FIFO buffers and disable them
  2273. * (they will be reenabled in change_speed())
  2274. */
  2275. /*
  2276. * Reset the DMA channels and make sure their interrupts are cleared
  2277. */
  2278. if (info->dma_in_enabled) {
  2279. info->uses_dma_in = 1;
  2280. e100_enable_rxdma_channel(info);
  2281. *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, reset);
  2282. /* Wait until reset cycle is complete */
  2283. while (IO_EXTRACT(R_DMA_CH6_CMD, cmd, *info->icmdadr) ==
  2284. IO_STATE_VALUE(R_DMA_CH6_CMD, cmd, reset));
  2285. /* Make sure the irqs are cleared */
  2286. *info->iclrintradr =
  2287. IO_STATE(R_DMA_CH6_CLR_INTR, clr_descr, do) |
  2288. IO_STATE(R_DMA_CH6_CLR_INTR, clr_eop, do);
  2289. } else {
  2290. e100_disable_rxdma_channel(info);
  2291. }
  2292. if (info->dma_out_enabled) {
  2293. info->uses_dma_out = 1;
  2294. e100_enable_txdma_channel(info);
  2295. *info->ocmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, reset);
  2296. while (IO_EXTRACT(R_DMA_CH6_CMD, cmd, *info->ocmdadr) ==
  2297. IO_STATE_VALUE(R_DMA_CH6_CMD, cmd, reset));
  2298. /* Make sure the irqs are cleared */
  2299. *info->oclrintradr =
  2300. IO_STATE(R_DMA_CH6_CLR_INTR, clr_descr, do) |
  2301. IO_STATE(R_DMA_CH6_CLR_INTR, clr_eop, do);
  2302. } else {
  2303. e100_disable_txdma_channel(info);
  2304. }
  2305. if (info->port.tty)
  2306. clear_bit(TTY_IO_ERROR, &info->port.tty->flags);
  2307. info->xmit.head = info->xmit.tail = 0;
  2308. info->first_recv_buffer = info->last_recv_buffer = NULL;
  2309. info->recv_cnt = info->max_recv_cnt = 0;
  2310. for (i = 0; i < SERIAL_RECV_DESCRIPTORS; i++)
  2311. info->rec_descr[i].buf = 0;
  2312. /*
  2313. * and set the speed and other flags of the serial port
  2314. * this will start the rx/tx as well
  2315. */
  2316. #ifdef SERIAL_HANDLE_EARLY_ERRORS
  2317. e100_enable_serial_data_irq(info);
  2318. #endif
  2319. change_speed(info);
  2320. /* dummy read to reset any serial errors */
  2321. (void)info->ioport[REG_DATA];
  2322. /* enable the interrupts */
  2323. if (info->uses_dma_out)
  2324. e100_enable_txdma_irq(info);
  2325. e100_enable_rx_irq(info);
  2326. info->tr_running = 0; /* to be sure we don't lock up the transmitter */
  2327. /* setup the dma input descriptor and start dma */
  2328. start_receive(info);
  2329. /* for safety, make sure the descriptors last result is 0 bytes written */
  2330. info->tr_descr.sw_len = 0;
  2331. info->tr_descr.hw_len = 0;
  2332. info->tr_descr.status = 0;
  2333. /* enable RTS/DTR last */
  2334. e100_rts(info, 1);
  2335. e100_dtr(info, 1);
  2336. info->port.flags |= ASYNC_INITIALIZED;
  2337. local_irq_restore(flags);
  2338. return 0;
  2339. }
  2340. /*
  2341. * This routine will shutdown a serial port; interrupts are disabled, and
  2342. * DTR is dropped if the hangup on close termio flag is on.
  2343. */
  2344. static void
  2345. shutdown(struct e100_serial * info)
  2346. {
  2347. unsigned long flags;
  2348. struct etrax_dma_descr *descr = info->rec_descr;
  2349. struct etrax_recv_buffer *buffer;
  2350. int i;
  2351. /* shut down the transmitter and receiver */
  2352. DFLOW(DEBUG_LOG(info->line, "shutdown %i\n", info->line));
  2353. e100_disable_rx(info);
  2354. info->ioport[REG_TR_CTRL] = (info->tx_ctrl &= ~0x40);
  2355. /* disable interrupts, reset dma channels */
  2356. if (info->uses_dma_in) {
  2357. e100_disable_rxdma_irq(info);
  2358. *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, reset);
  2359. info->uses_dma_in = 0;
  2360. } else {
  2361. e100_disable_serial_data_irq(info);
  2362. }
  2363. if (info->uses_dma_out) {
  2364. e100_disable_txdma_irq(info);
  2365. info->tr_running = 0;
  2366. *info->ocmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, reset);
  2367. info->uses_dma_out = 0;
  2368. } else {
  2369. e100_disable_serial_tx_ready_irq(info);
  2370. info->tr_running = 0;
  2371. }
  2372. if (!(info->port.flags & ASYNC_INITIALIZED))
  2373. return;
  2374. #ifdef SERIAL_DEBUG_OPEN
  2375. printk("Shutting down serial port %d (irq %d)....\n", info->line,
  2376. info->irq);
  2377. #endif
  2378. local_irq_save(flags);
  2379. if (info->xmit.buf) {
  2380. free_page((unsigned long)info->xmit.buf);
  2381. info->xmit.buf = NULL;
  2382. }
  2383. for (i = 0; i < SERIAL_RECV_DESCRIPTORS; i++)
  2384. if (descr[i].buf) {
  2385. buffer = phys_to_virt(descr[i].buf) - sizeof *buffer;
  2386. kfree(buffer);
  2387. descr[i].buf = 0;
  2388. }
  2389. if (!info->port.tty || (info->port.tty->termios.c_cflag & HUPCL)) {
  2390. /* hang up DTR and RTS if HUPCL is enabled */
  2391. e100_dtr(info, 0);
  2392. e100_rts(info, 0); /* could check CRTSCTS before doing this */
  2393. }
  2394. if (info->port.tty)
  2395. set_bit(TTY_IO_ERROR, &info->port.tty->flags);
  2396. info->port.flags &= ~ASYNC_INITIALIZED;
  2397. local_irq_restore(flags);
  2398. }
  2399. /* change baud rate and other assorted parameters */
  2400. static void
  2401. change_speed(struct e100_serial *info)
  2402. {
  2403. unsigned int cflag;
  2404. unsigned long xoff;
  2405. unsigned long flags;
  2406. /* first some safety checks */
  2407. if (!info->port.tty)
  2408. return;
  2409. if (!info->ioport)
  2410. return;
  2411. cflag = info->port.tty->termios.c_cflag;
  2412. /* possibly, the tx/rx should be disabled first to do this safely */
  2413. /* change baud-rate and write it to the hardware */
  2414. if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) {
  2415. /* Special baudrate */
  2416. u32 mask = 0xFF << (info->line*8); /* Each port has 8 bits */
  2417. unsigned long alt_source =
  2418. IO_STATE(R_ALT_SER_BAUDRATE, ser0_rec, normal) |
  2419. IO_STATE(R_ALT_SER_BAUDRATE, ser0_tr, normal);
  2420. /* R_ALT_SER_BAUDRATE selects the source */
  2421. DBAUD(printk("Custom baudrate: baud_base/divisor %lu/%i\n",
  2422. (unsigned long)info->baud_base, info->custom_divisor));
  2423. if (info->baud_base == SERIAL_PRESCALE_BASE) {
  2424. /* 0, 2-65535 (0=65536) */
  2425. u16 divisor = info->custom_divisor;
  2426. /* R_SERIAL_PRESCALE (upper 16 bits of R_CLOCK_PRESCALE) */
  2427. /* baudrate is 3.125MHz/custom_divisor */
  2428. alt_source =
  2429. IO_STATE(R_ALT_SER_BAUDRATE, ser0_rec, prescale) |
  2430. IO_STATE(R_ALT_SER_BAUDRATE, ser0_tr, prescale);
  2431. alt_source = 0x11;
  2432. DBAUD(printk("Writing SERIAL_PRESCALE: divisor %i\n", divisor));
  2433. *R_SERIAL_PRESCALE = divisor;
  2434. info->baud = SERIAL_PRESCALE_BASE/divisor;
  2435. }
  2436. else
  2437. {
  2438. /* Bad baudbase, we don't support using timer0
  2439. * for baudrate.
  2440. */
  2441. printk(KERN_WARNING "Bad baud_base/custom_divisor: %lu/%i\n",
  2442. (unsigned long)info->baud_base, info->custom_divisor);
  2443. }
  2444. r_alt_ser_baudrate_shadow &= ~mask;
  2445. r_alt_ser_baudrate_shadow |= (alt_source << (info->line*8));
  2446. *R_ALT_SER_BAUDRATE = r_alt_ser_baudrate_shadow;
  2447. } else {
  2448. /* Normal baudrate */
  2449. /* Make sure we use normal baudrate */
  2450. u32 mask = 0xFF << (info->line*8); /* Each port has 8 bits */
  2451. unsigned long alt_source =
  2452. IO_STATE(R_ALT_SER_BAUDRATE, ser0_rec, normal) |
  2453. IO_STATE(R_ALT_SER_BAUDRATE, ser0_tr, normal);
  2454. r_alt_ser_baudrate_shadow &= ~mask;
  2455. r_alt_ser_baudrate_shadow |= (alt_source << (info->line*8));
  2456. *R_ALT_SER_BAUDRATE = r_alt_ser_baudrate_shadow;
  2457. info->baud = cflag_to_baud(cflag);
  2458. info->ioport[REG_BAUD] = cflag_to_etrax_baud(cflag);
  2459. }
  2460. /* start with default settings and then fill in changes */
  2461. local_irq_save(flags);
  2462. /* 8 bit, no/even parity */
  2463. info->rx_ctrl &= ~(IO_MASK(R_SERIAL0_REC_CTRL, rec_bitnr) |
  2464. IO_MASK(R_SERIAL0_REC_CTRL, rec_par_en) |
  2465. IO_MASK(R_SERIAL0_REC_CTRL, rec_par));
  2466. /* 8 bit, no/even parity, 1 stop bit, no cts */
  2467. info->tx_ctrl &= ~(IO_MASK(R_SERIAL0_TR_CTRL, tr_bitnr) |
  2468. IO_MASK(R_SERIAL0_TR_CTRL, tr_par_en) |
  2469. IO_MASK(R_SERIAL0_TR_CTRL, tr_par) |
  2470. IO_MASK(R_SERIAL0_TR_CTRL, stop_bits) |
  2471. IO_MASK(R_SERIAL0_TR_CTRL, auto_cts));
  2472. if ((cflag & CSIZE) == CS7) {
  2473. /* set 7 bit mode */
  2474. info->tx_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_bitnr, tr_7bit);
  2475. info->rx_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_bitnr, rec_7bit);
  2476. }
  2477. if (cflag & CSTOPB) {
  2478. /* set 2 stop bit mode */
  2479. info->tx_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, stop_bits, two_bits);
  2480. }
  2481. if (cflag & PARENB) {
  2482. /* enable parity */
  2483. info->tx_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_par_en, enable);
  2484. info->rx_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_par_en, enable);
  2485. }
  2486. if (cflag & CMSPAR) {
  2487. /* enable stick parity, PARODD mean Mark which matches ETRAX */
  2488. info->tx_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_stick_par, stick);
  2489. info->rx_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_stick_par, stick);
  2490. }
  2491. if (cflag & PARODD) {
  2492. /* set odd parity (or Mark if CMSPAR) */
  2493. info->tx_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_par, odd);
  2494. info->rx_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_par, odd);
  2495. }
  2496. if (cflag & CRTSCTS) {
  2497. /* enable automatic CTS handling */
  2498. DFLOW(DEBUG_LOG(info->line, "FLOW auto_cts enabled\n", 0));
  2499. info->tx_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, auto_cts, active);
  2500. }
  2501. /* make sure the tx and rx are enabled */
  2502. info->tx_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_enable, enable);
  2503. info->rx_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_enable, enable);
  2504. /* actually write the control regs to the hardware */
  2505. info->ioport[REG_TR_CTRL] = info->tx_ctrl;
  2506. info->ioport[REG_REC_CTRL] = info->rx_ctrl;
  2507. xoff = IO_FIELD(R_SERIAL0_XOFF, xoff_char, STOP_CHAR(info->port.tty));
  2508. xoff |= IO_STATE(R_SERIAL0_XOFF, tx_stop, enable);
  2509. if (info->port.tty->termios.c_iflag & IXON ) {
  2510. DFLOW(DEBUG_LOG(info->line, "FLOW XOFF enabled 0x%02X\n",
  2511. STOP_CHAR(info->port.tty)));
  2512. xoff |= IO_STATE(R_SERIAL0_XOFF, auto_xoff, enable);
  2513. }
  2514. *((unsigned long *)&info->ioport[REG_XOFF]) = xoff;
  2515. local_irq_restore(flags);
  2516. update_char_time(info);
  2517. } /* change_speed */
  2518. /* start transmitting chars NOW */
  2519. static void
  2520. rs_flush_chars(struct tty_struct *tty)
  2521. {
  2522. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  2523. unsigned long flags;
  2524. if (info->tr_running ||
  2525. info->xmit.head == info->xmit.tail ||
  2526. tty->stopped ||
  2527. !info->xmit.buf)
  2528. return;
  2529. #ifdef SERIAL_DEBUG_FLOW
  2530. printk("rs_flush_chars\n");
  2531. #endif
  2532. /* this protection might not exactly be necessary here */
  2533. local_irq_save(flags);
  2534. start_transmit(info);
  2535. local_irq_restore(flags);
  2536. }
  2537. static int rs_raw_write(struct tty_struct *tty,
  2538. const unsigned char *buf, int count)
  2539. {
  2540. int c, ret = 0;
  2541. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  2542. unsigned long flags;
  2543. /* first some sanity checks */
  2544. if (!info->xmit.buf)
  2545. return 0;
  2546. #ifdef SERIAL_DEBUG_DATA
  2547. if (info->line == SERIAL_DEBUG_LINE)
  2548. printk("rs_raw_write (%d), status %d\n",
  2549. count, info->ioport[REG_STATUS]);
  2550. #endif
  2551. local_save_flags(flags);
  2552. DFLOW(DEBUG_LOG(info->line, "write count %i ", count));
  2553. DFLOW(DEBUG_LOG(info->line, "ldisc %i\n", tty->ldisc.chars_in_buffer(tty)));
  2554. /* The local_irq_disable/restore_flags pairs below are needed
  2555. * because the DMA interrupt handler moves the info->xmit values.
  2556. * the memcpy needs to be in the critical region unfortunately,
  2557. * because we need to read xmit values, memcpy, write xmit values
  2558. * in one atomic operation... this could perhaps be avoided by
  2559. * more clever design.
  2560. */
  2561. local_irq_disable();
  2562. while (count) {
  2563. c = CIRC_SPACE_TO_END(info->xmit.head,
  2564. info->xmit.tail,
  2565. SERIAL_XMIT_SIZE);
  2566. if (count < c)
  2567. c = count;
  2568. if (c <= 0)
  2569. break;
  2570. memcpy(info->xmit.buf + info->xmit.head, buf, c);
  2571. info->xmit.head = (info->xmit.head + c) &
  2572. (SERIAL_XMIT_SIZE-1);
  2573. buf += c;
  2574. count -= c;
  2575. ret += c;
  2576. }
  2577. local_irq_restore(flags);
  2578. /* enable transmitter if not running, unless the tty is stopped
  2579. * this does not need IRQ protection since if tr_running == 0
  2580. * the IRQ's are not running anyway for this port.
  2581. */
  2582. DFLOW(DEBUG_LOG(info->line, "write ret %i\n", ret));
  2583. if (info->xmit.head != info->xmit.tail &&
  2584. !tty->stopped &&
  2585. !info->tr_running) {
  2586. start_transmit(info);
  2587. }
  2588. return ret;
  2589. } /* raw_raw_write() */
  2590. static int
  2591. rs_write(struct tty_struct *tty,
  2592. const unsigned char *buf, int count)
  2593. {
  2594. #if defined(CONFIG_ETRAX_RS485)
  2595. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  2596. if (info->rs485.flags & SER_RS485_ENABLED)
  2597. {
  2598. /* If we are in RS-485 mode, we need to toggle RTS and disable
  2599. * the receiver before initiating a DMA transfer
  2600. */
  2601. #ifdef CONFIG_ETRAX_FAST_TIMER
  2602. /* Abort any started timer */
  2603. fast_timers_rs485[info->line].function = NULL;
  2604. del_fast_timer(&fast_timers_rs485[info->line]);
  2605. #endif
  2606. e100_rts(info, (info->rs485.flags & SER_RS485_RTS_ON_SEND));
  2607. #if defined(CONFIG_ETRAX_RS485_DISABLE_RECEIVER)
  2608. e100_disable_rx(info);
  2609. e100_enable_rx_irq(info);
  2610. #endif
  2611. if (info->rs485.delay_rts_before_send > 0)
  2612. msleep(info->rs485.delay_rts_before_send);
  2613. }
  2614. #endif /* CONFIG_ETRAX_RS485 */
  2615. count = rs_raw_write(tty, buf, count);
  2616. #if defined(CONFIG_ETRAX_RS485)
  2617. if (info->rs485.flags & SER_RS485_ENABLED)
  2618. {
  2619. unsigned int val;
  2620. /* If we are in RS-485 mode the following has to be done:
  2621. * wait until DMA is ready
  2622. * wait on transmit shift register
  2623. * toggle RTS
  2624. * enable the receiver
  2625. */
  2626. /* Sleep until all sent */
  2627. tty_wait_until_sent(tty, 0);
  2628. #ifdef CONFIG_ETRAX_FAST_TIMER
  2629. /* Now sleep a little more so that shift register is empty */
  2630. schedule_usleep(info->char_time_usec * 2);
  2631. #endif
  2632. /* wait on transmit shift register */
  2633. do{
  2634. get_lsr_info(info, &val);
  2635. }while (!(val & TIOCSER_TEMT));
  2636. e100_rts(info, (info->rs485.flags & SER_RS485_RTS_AFTER_SEND));
  2637. #if defined(CONFIG_ETRAX_RS485_DISABLE_RECEIVER)
  2638. e100_enable_rx(info);
  2639. e100_enable_rxdma_irq(info);
  2640. #endif
  2641. }
  2642. #endif /* CONFIG_ETRAX_RS485 */
  2643. return count;
  2644. } /* rs_write */
  2645. /* how much space is available in the xmit buffer? */
  2646. static int
  2647. rs_write_room(struct tty_struct *tty)
  2648. {
  2649. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  2650. return CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
  2651. }
  2652. /* How many chars are in the xmit buffer?
  2653. * This does not include any chars in the transmitter FIFO.
  2654. * Use wait_until_sent for waiting for FIFO drain.
  2655. */
  2656. static int
  2657. rs_chars_in_buffer(struct tty_struct *tty)
  2658. {
  2659. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  2660. return CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
  2661. }
  2662. /* discard everything in the xmit buffer */
  2663. static void
  2664. rs_flush_buffer(struct tty_struct *tty)
  2665. {
  2666. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  2667. unsigned long flags;
  2668. local_irq_save(flags);
  2669. info->xmit.head = info->xmit.tail = 0;
  2670. local_irq_restore(flags);
  2671. tty_wakeup(tty);
  2672. }
  2673. /*
  2674. * This function is used to send a high-priority XON/XOFF character to
  2675. * the device
  2676. *
  2677. * Since we use DMA we don't check for info->x_char in transmit_chars_dma(),
  2678. * but we do it in handle_ser_tx_interrupt().
  2679. * We disable DMA channel and enable tx ready interrupt and write the
  2680. * character when possible.
  2681. */
  2682. static void rs_send_xchar(struct tty_struct *tty, char ch)
  2683. {
  2684. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  2685. unsigned long flags;
  2686. local_irq_save(flags);
  2687. if (info->uses_dma_out) {
  2688. /* Put the DMA on hold and disable the channel */
  2689. *info->ocmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, hold);
  2690. while (IO_EXTRACT(R_DMA_CH6_CMD, cmd, *info->ocmdadr) !=
  2691. IO_STATE_VALUE(R_DMA_CH6_CMD, cmd, hold));
  2692. e100_disable_txdma_channel(info);
  2693. }
  2694. /* Must make sure transmitter is not stopped before we can transmit */
  2695. if (tty->stopped)
  2696. rs_start(tty);
  2697. /* Enable manual transmit interrupt and send from there */
  2698. DFLOW(DEBUG_LOG(info->line, "rs_send_xchar 0x%02X\n", ch));
  2699. info->x_char = ch;
  2700. e100_enable_serial_tx_ready_irq(info);
  2701. local_irq_restore(flags);
  2702. }
  2703. /*
  2704. * ------------------------------------------------------------
  2705. * rs_throttle()
  2706. *
  2707. * This routine is called by the upper-layer tty layer to signal that
  2708. * incoming characters should be throttled.
  2709. * ------------------------------------------------------------
  2710. */
  2711. static void
  2712. rs_throttle(struct tty_struct * tty)
  2713. {
  2714. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  2715. #ifdef SERIAL_DEBUG_THROTTLE
  2716. printk("throttle %s: %lu....\n", tty_name(tty),
  2717. (unsigned long)tty->ldisc.chars_in_buffer(tty));
  2718. #endif
  2719. DFLOW(DEBUG_LOG(info->line,"rs_throttle %lu\n", tty->ldisc.chars_in_buffer(tty)));
  2720. /* Do RTS before XOFF since XOFF might take some time */
  2721. if (tty->termios.c_cflag & CRTSCTS) {
  2722. /* Turn off RTS line */
  2723. e100_rts(info, 0);
  2724. }
  2725. if (I_IXOFF(tty))
  2726. rs_send_xchar(tty, STOP_CHAR(tty));
  2727. }
  2728. static void
  2729. rs_unthrottle(struct tty_struct * tty)
  2730. {
  2731. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  2732. #ifdef SERIAL_DEBUG_THROTTLE
  2733. printk("unthrottle %s: %lu....\n", tty_name(tty),
  2734. (unsigned long)tty->ldisc.chars_in_buffer(tty));
  2735. #endif
  2736. DFLOW(DEBUG_LOG(info->line,"rs_unthrottle ldisc %d\n", tty->ldisc.chars_in_buffer(tty)));
  2737. DFLOW(DEBUG_LOG(info->line,"rs_unthrottle flip.count: %i\n", tty->flip.count));
  2738. /* Do RTS before XOFF since XOFF might take some time */
  2739. if (tty->termios.c_cflag & CRTSCTS) {
  2740. /* Assert RTS line */
  2741. e100_rts(info, 1);
  2742. }
  2743. if (I_IXOFF(tty)) {
  2744. if (info->x_char)
  2745. info->x_char = 0;
  2746. else
  2747. rs_send_xchar(tty, START_CHAR(tty));
  2748. }
  2749. }
  2750. /*
  2751. * ------------------------------------------------------------
  2752. * rs_ioctl() and friends
  2753. * ------------------------------------------------------------
  2754. */
  2755. static int
  2756. get_serial_info(struct e100_serial * info,
  2757. struct serial_struct * retinfo)
  2758. {
  2759. struct serial_struct tmp;
  2760. /* this is all probably wrong, there are a lot of fields
  2761. * here that we don't have in e100_serial and maybe we
  2762. * should set them to something else than 0.
  2763. */
  2764. if (!retinfo)
  2765. return -EFAULT;
  2766. memset(&tmp, 0, sizeof(tmp));
  2767. tmp.type = info->type;
  2768. tmp.line = info->line;
  2769. tmp.port = (int)info->ioport;
  2770. tmp.irq = info->irq;
  2771. tmp.flags = info->port.flags;
  2772. tmp.baud_base = info->baud_base;
  2773. tmp.close_delay = info->port.close_delay;
  2774. tmp.closing_wait = info->port.closing_wait;
  2775. tmp.custom_divisor = info->custom_divisor;
  2776. if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
  2777. return -EFAULT;
  2778. return 0;
  2779. }
  2780. static int
  2781. set_serial_info(struct e100_serial *info,
  2782. struct serial_struct *new_info)
  2783. {
  2784. struct serial_struct new_serial;
  2785. struct e100_serial old_info;
  2786. int retval = 0;
  2787. if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
  2788. return -EFAULT;
  2789. old_info = *info;
  2790. if (!capable(CAP_SYS_ADMIN)) {
  2791. if ((new_serial.type != info->type) ||
  2792. (new_serial.close_delay != info->port.close_delay) ||
  2793. ((new_serial.flags & ~ASYNC_USR_MASK) !=
  2794. (info->port.flags & ~ASYNC_USR_MASK)))
  2795. return -EPERM;
  2796. info->port.flags = ((info->port.flags & ~ASYNC_USR_MASK) |
  2797. (new_serial.flags & ASYNC_USR_MASK));
  2798. goto check_and_exit;
  2799. }
  2800. if (info->port.count > 1)
  2801. return -EBUSY;
  2802. /*
  2803. * OK, past this point, all the error checking has been done.
  2804. * At this point, we start making changes.....
  2805. */
  2806. info->baud_base = new_serial.baud_base;
  2807. info->port.flags = ((info->port.flags & ~ASYNC_FLAGS) |
  2808. (new_serial.flags & ASYNC_FLAGS));
  2809. info->custom_divisor = new_serial.custom_divisor;
  2810. info->type = new_serial.type;
  2811. info->port.close_delay = new_serial.close_delay;
  2812. info->port.closing_wait = new_serial.closing_wait;
  2813. info->port.low_latency = (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
  2814. check_and_exit:
  2815. if (info->port.flags & ASYNC_INITIALIZED) {
  2816. change_speed(info);
  2817. } else
  2818. retval = startup(info);
  2819. return retval;
  2820. }
  2821. /*
  2822. * get_lsr_info - get line status register info
  2823. *
  2824. * Purpose: Let user call ioctl() to get info when the UART physically
  2825. * is emptied. On bus types like RS485, the transmitter must
  2826. * release the bus after transmitting. This must be done when
  2827. * the transmit shift register is empty, not be done when the
  2828. * transmit holding register is empty. This functionality
  2829. * allows an RS485 driver to be written in user space.
  2830. */
  2831. static int
  2832. get_lsr_info(struct e100_serial * info, unsigned int *value)
  2833. {
  2834. unsigned int result = TIOCSER_TEMT;
  2835. unsigned long curr_time = jiffies;
  2836. unsigned long curr_time_usec = GET_JIFFIES_USEC();
  2837. unsigned long elapsed_usec =
  2838. (curr_time - info->last_tx_active) * 1000000/HZ +
  2839. curr_time_usec - info->last_tx_active_usec;
  2840. if (info->xmit.head != info->xmit.tail ||
  2841. elapsed_usec < 2*info->char_time_usec) {
  2842. result = 0;
  2843. }
  2844. if (copy_to_user(value, &result, sizeof(int)))
  2845. return -EFAULT;
  2846. return 0;
  2847. }
  2848. #ifdef SERIAL_DEBUG_IO
  2849. struct state_str
  2850. {
  2851. int state;
  2852. const char *str;
  2853. };
  2854. const struct state_str control_state_str[] = {
  2855. {TIOCM_DTR, "DTR" },
  2856. {TIOCM_RTS, "RTS"},
  2857. {TIOCM_ST, "ST?" },
  2858. {TIOCM_SR, "SR?" },
  2859. {TIOCM_CTS, "CTS" },
  2860. {TIOCM_CD, "CD" },
  2861. {TIOCM_RI, "RI" },
  2862. {TIOCM_DSR, "DSR" },
  2863. {0, NULL }
  2864. };
  2865. char *get_control_state_str(int MLines, char *s)
  2866. {
  2867. int i = 0;
  2868. s[0]='\0';
  2869. while (control_state_str[i].str != NULL) {
  2870. if (MLines & control_state_str[i].state) {
  2871. if (s[0] != '\0') {
  2872. strcat(s, ", ");
  2873. }
  2874. strcat(s, control_state_str[i].str);
  2875. }
  2876. i++;
  2877. }
  2878. return s;
  2879. }
  2880. #endif
  2881. static int
  2882. rs_break(struct tty_struct *tty, int break_state)
  2883. {
  2884. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  2885. unsigned long flags;
  2886. if (!info->ioport)
  2887. return -EIO;
  2888. local_irq_save(flags);
  2889. if (break_state == -1) {
  2890. /* Go to manual mode and set the txd pin to 0 */
  2891. /* Clear bit 7 (txd) and 6 (tr_enable) */
  2892. info->tx_ctrl &= 0x3F;
  2893. } else {
  2894. /* Set bit 7 (txd) and 6 (tr_enable) */
  2895. info->tx_ctrl |= (0x80 | 0x40);
  2896. }
  2897. info->ioport[REG_TR_CTRL] = info->tx_ctrl;
  2898. local_irq_restore(flags);
  2899. return 0;
  2900. }
  2901. static int
  2902. rs_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear)
  2903. {
  2904. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  2905. unsigned long flags;
  2906. local_irq_save(flags);
  2907. if (clear & TIOCM_RTS)
  2908. e100_rts(info, 0);
  2909. if (clear & TIOCM_DTR)
  2910. e100_dtr(info, 0);
  2911. /* Handle FEMALE behaviour */
  2912. if (clear & TIOCM_RI)
  2913. e100_ri_out(info, 0);
  2914. if (clear & TIOCM_CD)
  2915. e100_cd_out(info, 0);
  2916. if (set & TIOCM_RTS)
  2917. e100_rts(info, 1);
  2918. if (set & TIOCM_DTR)
  2919. e100_dtr(info, 1);
  2920. /* Handle FEMALE behaviour */
  2921. if (set & TIOCM_RI)
  2922. e100_ri_out(info, 1);
  2923. if (set & TIOCM_CD)
  2924. e100_cd_out(info, 1);
  2925. local_irq_restore(flags);
  2926. return 0;
  2927. }
  2928. static int
  2929. rs_tiocmget(struct tty_struct *tty)
  2930. {
  2931. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  2932. unsigned int result;
  2933. unsigned long flags;
  2934. local_irq_save(flags);
  2935. result =
  2936. (!E100_RTS_GET(info) ? TIOCM_RTS : 0)
  2937. | (!E100_DTR_GET(info) ? TIOCM_DTR : 0)
  2938. | (!E100_RI_GET(info) ? TIOCM_RNG : 0)
  2939. | (!E100_DSR_GET(info) ? TIOCM_DSR : 0)
  2940. | (!E100_CD_GET(info) ? TIOCM_CAR : 0)
  2941. | (!E100_CTS_GET(info) ? TIOCM_CTS : 0);
  2942. local_irq_restore(flags);
  2943. #ifdef SERIAL_DEBUG_IO
  2944. printk(KERN_DEBUG "ser%i: modem state: %i 0x%08X\n",
  2945. info->line, result, result);
  2946. {
  2947. char s[100];
  2948. get_control_state_str(result, s);
  2949. printk(KERN_DEBUG "state: %s\n", s);
  2950. }
  2951. #endif
  2952. return result;
  2953. }
  2954. static int
  2955. rs_ioctl(struct tty_struct *tty,
  2956. unsigned int cmd, unsigned long arg)
  2957. {
  2958. struct e100_serial * info = (struct e100_serial *)tty->driver_data;
  2959. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  2960. (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
  2961. (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {
  2962. if (tty->flags & (1 << TTY_IO_ERROR))
  2963. return -EIO;
  2964. }
  2965. switch (cmd) {
  2966. case TIOCGSERIAL:
  2967. return get_serial_info(info,
  2968. (struct serial_struct *) arg);
  2969. case TIOCSSERIAL:
  2970. return set_serial_info(info,
  2971. (struct serial_struct *) arg);
  2972. case TIOCSERGETLSR: /* Get line status register */
  2973. return get_lsr_info(info, (unsigned int *) arg);
  2974. case TIOCSERGSTRUCT:
  2975. if (copy_to_user((struct e100_serial *) arg,
  2976. info, sizeof(struct e100_serial)))
  2977. return -EFAULT;
  2978. return 0;
  2979. #if defined(CONFIG_ETRAX_RS485)
  2980. case TIOCSERSETRS485:
  2981. {
  2982. /* In this ioctl we still use the old structure
  2983. * rs485_control for backward compatibility
  2984. * (if we use serial_rs485, then old user-level code
  2985. * wouldn't work anymore...).
  2986. * The use of this ioctl is deprecated: use TIOCSRS485
  2987. * instead.*/
  2988. struct rs485_control rs485ctrl;
  2989. struct serial_rs485 rs485data;
  2990. printk(KERN_DEBUG "The use of this ioctl is deprecated. Use TIOCSRS485 instead\n");
  2991. if (copy_from_user(&rs485ctrl, (struct rs485_control *)arg,
  2992. sizeof(rs485ctrl)))
  2993. return -EFAULT;
  2994. rs485data.delay_rts_before_send = rs485ctrl.delay_rts_before_send;
  2995. rs485data.flags = 0;
  2996. if (rs485ctrl.enabled)
  2997. rs485data.flags |= SER_RS485_ENABLED;
  2998. else
  2999. rs485data.flags &= ~(SER_RS485_ENABLED);
  3000. if (rs485ctrl.rts_on_send)
  3001. rs485data.flags |= SER_RS485_RTS_ON_SEND;
  3002. else
  3003. rs485data.flags &= ~(SER_RS485_RTS_ON_SEND);
  3004. if (rs485ctrl.rts_after_sent)
  3005. rs485data.flags |= SER_RS485_RTS_AFTER_SEND;
  3006. else
  3007. rs485data.flags &= ~(SER_RS485_RTS_AFTER_SEND);
  3008. return e100_enable_rs485(tty, &rs485data);
  3009. }
  3010. case TIOCSRS485:
  3011. {
  3012. /* This is the new version of TIOCSRS485, with new
  3013. * data structure serial_rs485 */
  3014. struct serial_rs485 rs485data;
  3015. if (copy_from_user(&rs485data, (struct rs485_control *)arg,
  3016. sizeof(rs485data)))
  3017. return -EFAULT;
  3018. return e100_enable_rs485(tty, &rs485data);
  3019. }
  3020. case TIOCGRS485:
  3021. {
  3022. struct serial_rs485 *rs485data =
  3023. &(((struct e100_serial *)tty->driver_data)->rs485);
  3024. /* This is the ioctl to get RS485 data from user-space */
  3025. if (copy_to_user((struct serial_rs485 *) arg,
  3026. rs485data,
  3027. sizeof(struct serial_rs485)))
  3028. return -EFAULT;
  3029. break;
  3030. }
  3031. case TIOCSERWRRS485:
  3032. {
  3033. struct rs485_write rs485wr;
  3034. if (copy_from_user(&rs485wr, (struct rs485_write *)arg,
  3035. sizeof(rs485wr)))
  3036. return -EFAULT;
  3037. return e100_write_rs485(tty, rs485wr.outc, rs485wr.outc_size);
  3038. }
  3039. #endif
  3040. default:
  3041. return -ENOIOCTLCMD;
  3042. }
  3043. return 0;
  3044. }
  3045. static void
  3046. rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
  3047. {
  3048. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  3049. change_speed(info);
  3050. /* Handle turning off CRTSCTS */
  3051. if ((old_termios->c_cflag & CRTSCTS) &&
  3052. !(tty->termios.c_cflag & CRTSCTS))
  3053. rs_start(tty);
  3054. }
  3055. /*
  3056. * ------------------------------------------------------------
  3057. * rs_close()
  3058. *
  3059. * This routine is called when the serial port gets closed. First, we
  3060. * wait for the last remaining data to be sent. Then, we unlink its
  3061. * S structure from the interrupt chain if necessary, and we free
  3062. * that IRQ if nothing is left in the chain.
  3063. * ------------------------------------------------------------
  3064. */
  3065. static void
  3066. rs_close(struct tty_struct *tty, struct file * filp)
  3067. {
  3068. struct e100_serial * info = (struct e100_serial *)tty->driver_data;
  3069. unsigned long flags;
  3070. if (!info)
  3071. return;
  3072. /* interrupts are disabled for this entire function */
  3073. local_irq_save(flags);
  3074. if (tty_hung_up_p(filp)) {
  3075. local_irq_restore(flags);
  3076. return;
  3077. }
  3078. #ifdef SERIAL_DEBUG_OPEN
  3079. printk("[%d] rs_close ttyS%d, count = %d\n", current->pid,
  3080. info->line, info->count);
  3081. #endif
  3082. if ((tty->count == 1) && (info->port.count != 1)) {
  3083. /*
  3084. * Uh, oh. tty->count is 1, which means that the tty
  3085. * structure will be freed. Info->count should always
  3086. * be one in these conditions. If it's greater than
  3087. * one, we've got real problems, since it means the
  3088. * serial port won't be shutdown.
  3089. */
  3090. printk(KERN_ERR
  3091. "rs_close: bad serial port count; tty->count is 1, "
  3092. "info->count is %d\n", info->port.count);
  3093. info->port.count = 1;
  3094. }
  3095. if (--info->port.count < 0) {
  3096. printk(KERN_ERR "rs_close: bad serial port count for ttyS%d: %d\n",
  3097. info->line, info->port.count);
  3098. info->port.count = 0;
  3099. }
  3100. if (info->port.count) {
  3101. local_irq_restore(flags);
  3102. return;
  3103. }
  3104. info->port.flags |= ASYNC_CLOSING;
  3105. /*
  3106. * Now we wait for the transmit buffer to clear; and we notify
  3107. * the line discipline to only process XON/XOFF characters.
  3108. */
  3109. tty->closing = 1;
  3110. if (info->port.closing_wait != ASYNC_CLOSING_WAIT_NONE)
  3111. tty_wait_until_sent(tty, info->port.closing_wait);
  3112. /*
  3113. * At this point we stop accepting input. To do this, we
  3114. * disable the serial receiver and the DMA receive interrupt.
  3115. */
  3116. #ifdef SERIAL_HANDLE_EARLY_ERRORS
  3117. e100_disable_serial_data_irq(info);
  3118. #endif
  3119. e100_disable_rx(info);
  3120. e100_disable_rx_irq(info);
  3121. if (info->port.flags & ASYNC_INITIALIZED) {
  3122. /*
  3123. * Before we drop DTR, make sure the UART transmitter
  3124. * has completely drained; this is especially
  3125. * important as we have a transmit FIFO!
  3126. */
  3127. rs_wait_until_sent(tty, HZ);
  3128. }
  3129. shutdown(info);
  3130. rs_flush_buffer(tty);
  3131. tty_ldisc_flush(tty);
  3132. tty->closing = 0;
  3133. info->event = 0;
  3134. info->port.tty = NULL;
  3135. if (info->port.blocked_open) {
  3136. if (info->port.close_delay)
  3137. schedule_timeout_interruptible(info->port.close_delay);
  3138. wake_up_interruptible(&info->port.open_wait);
  3139. }
  3140. info->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  3141. wake_up_interruptible(&info->port.close_wait);
  3142. local_irq_restore(flags);
  3143. /* port closed */
  3144. #if defined(CONFIG_ETRAX_RS485)
  3145. if (info->rs485.flags & SER_RS485_ENABLED) {
  3146. info->rs485.flags &= ~(SER_RS485_ENABLED);
  3147. #if defined(CONFIG_ETRAX_RS485_ON_PA)
  3148. *R_PORT_PA_DATA = port_pa_data_shadow &= ~(1 << rs485_pa_bit);
  3149. #endif
  3150. }
  3151. #endif
  3152. /*
  3153. * Release any allocated DMA irq's.
  3154. */
  3155. if (info->dma_in_enabled) {
  3156. free_irq(info->dma_in_irq_nbr, info);
  3157. cris_free_dma(info->dma_in_nbr, info->dma_in_irq_description);
  3158. info->uses_dma_in = 0;
  3159. #ifdef SERIAL_DEBUG_OPEN
  3160. printk(KERN_DEBUG "DMA irq '%s' freed\n",
  3161. info->dma_in_irq_description);
  3162. #endif
  3163. }
  3164. if (info->dma_out_enabled) {
  3165. free_irq(info->dma_out_irq_nbr, info);
  3166. cris_free_dma(info->dma_out_nbr, info->dma_out_irq_description);
  3167. info->uses_dma_out = 0;
  3168. #ifdef SERIAL_DEBUG_OPEN
  3169. printk(KERN_DEBUG "DMA irq '%s' freed\n",
  3170. info->dma_out_irq_description);
  3171. #endif
  3172. }
  3173. }
  3174. /*
  3175. * rs_wait_until_sent() --- wait until the transmitter is empty
  3176. */
  3177. static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
  3178. {
  3179. unsigned long orig_jiffies;
  3180. struct e100_serial *info = (struct e100_serial *)tty->driver_data;
  3181. unsigned long curr_time = jiffies;
  3182. unsigned long curr_time_usec = GET_JIFFIES_USEC();
  3183. long elapsed_usec =
  3184. (curr_time - info->last_tx_active) * (1000000/HZ) +
  3185. curr_time_usec - info->last_tx_active_usec;
  3186. /*
  3187. * Check R_DMA_CHx_STATUS bit 0-6=number of available bytes in FIFO
  3188. * R_DMA_CHx_HWSW bit 31-16=nbr of bytes left in DMA buffer (0=64k)
  3189. */
  3190. orig_jiffies = jiffies;
  3191. while (info->xmit.head != info->xmit.tail || /* More in send queue */
  3192. (*info->ostatusadr & 0x007f) || /* more in FIFO */
  3193. (elapsed_usec < 2*info->char_time_usec)) {
  3194. schedule_timeout_interruptible(1);
  3195. if (signal_pending(current))
  3196. break;
  3197. if (timeout && time_after(jiffies, orig_jiffies + timeout))
  3198. break;
  3199. curr_time = jiffies;
  3200. curr_time_usec = GET_JIFFIES_USEC();
  3201. elapsed_usec =
  3202. (curr_time - info->last_tx_active) * (1000000/HZ) +
  3203. curr_time_usec - info->last_tx_active_usec;
  3204. }
  3205. set_current_state(TASK_RUNNING);
  3206. }
  3207. /*
  3208. * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
  3209. */
  3210. void
  3211. rs_hangup(struct tty_struct *tty)
  3212. {
  3213. struct e100_serial * info = (struct e100_serial *)tty->driver_data;
  3214. rs_flush_buffer(tty);
  3215. shutdown(info);
  3216. info->event = 0;
  3217. info->port.count = 0;
  3218. info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
  3219. info->port.tty = NULL;
  3220. wake_up_interruptible(&info->port.open_wait);
  3221. }
  3222. /*
  3223. * ------------------------------------------------------------
  3224. * rs_open() and friends
  3225. * ------------------------------------------------------------
  3226. */
  3227. static int
  3228. block_til_ready(struct tty_struct *tty, struct file * filp,
  3229. struct e100_serial *info)
  3230. {
  3231. DECLARE_WAITQUEUE(wait, current);
  3232. unsigned long flags;
  3233. int retval;
  3234. int do_clocal = 0;
  3235. /*
  3236. * If the device is in the middle of being closed, then block
  3237. * until it's done, and then try again.
  3238. */
  3239. if (info->port.flags & ASYNC_CLOSING) {
  3240. wait_event_interruptible_tty(tty, info->port.close_wait,
  3241. !(info->port.flags & ASYNC_CLOSING));
  3242. #ifdef SERIAL_DO_RESTART
  3243. if (info->port.flags & ASYNC_HUP_NOTIFY)
  3244. return -EAGAIN;
  3245. else
  3246. return -ERESTARTSYS;
  3247. #else
  3248. return -EAGAIN;
  3249. #endif
  3250. }
  3251. /*
  3252. * If non-blocking mode is set, or the port is not enabled,
  3253. * then make the check up front and then exit.
  3254. */
  3255. if ((filp->f_flags & O_NONBLOCK) ||
  3256. (tty->flags & (1 << TTY_IO_ERROR))) {
  3257. info->port.flags |= ASYNC_NORMAL_ACTIVE;
  3258. return 0;
  3259. }
  3260. if (tty->termios.c_cflag & CLOCAL) {
  3261. do_clocal = 1;
  3262. }
  3263. /*
  3264. * Block waiting for the carrier detect and the line to become
  3265. * free (i.e., not in use by the callout). While we are in
  3266. * this loop, info->port.count is dropped by one, so that
  3267. * rs_close() knows when to free things. We restore it upon
  3268. * exit, either normal or abnormal.
  3269. */
  3270. retval = 0;
  3271. add_wait_queue(&info->port.open_wait, &wait);
  3272. #ifdef SERIAL_DEBUG_OPEN
  3273. printk("block_til_ready before block: ttyS%d, count = %d\n",
  3274. info->line, info->port.count);
  3275. #endif
  3276. local_irq_save(flags);
  3277. info->port.count--;
  3278. local_irq_restore(flags);
  3279. info->port.blocked_open++;
  3280. while (1) {
  3281. local_irq_save(flags);
  3282. /* assert RTS and DTR */
  3283. e100_rts(info, 1);
  3284. e100_dtr(info, 1);
  3285. local_irq_restore(flags);
  3286. set_current_state(TASK_INTERRUPTIBLE);
  3287. if (tty_hung_up_p(filp) ||
  3288. !(info->port.flags & ASYNC_INITIALIZED)) {
  3289. #ifdef SERIAL_DO_RESTART
  3290. if (info->port.flags & ASYNC_HUP_NOTIFY)
  3291. retval = -EAGAIN;
  3292. else
  3293. retval = -ERESTARTSYS;
  3294. #else
  3295. retval = -EAGAIN;
  3296. #endif
  3297. break;
  3298. }
  3299. if (!(info->port.flags & ASYNC_CLOSING) && do_clocal)
  3300. /* && (do_clocal || DCD_IS_ASSERTED) */
  3301. break;
  3302. if (signal_pending(current)) {
  3303. retval = -ERESTARTSYS;
  3304. break;
  3305. }
  3306. #ifdef SERIAL_DEBUG_OPEN
  3307. printk("block_til_ready blocking: ttyS%d, count = %d\n",
  3308. info->line, info->port.count);
  3309. #endif
  3310. tty_unlock(tty);
  3311. schedule();
  3312. tty_lock(tty);
  3313. }
  3314. set_current_state(TASK_RUNNING);
  3315. remove_wait_queue(&info->port.open_wait, &wait);
  3316. if (!tty_hung_up_p(filp))
  3317. info->port.count++;
  3318. info->port.blocked_open--;
  3319. #ifdef SERIAL_DEBUG_OPEN
  3320. printk("block_til_ready after blocking: ttyS%d, count = %d\n",
  3321. info->line, info->port.count);
  3322. #endif
  3323. if (retval)
  3324. return retval;
  3325. info->port.flags |= ASYNC_NORMAL_ACTIVE;
  3326. return 0;
  3327. }
  3328. static void
  3329. deinit_port(struct e100_serial *info)
  3330. {
  3331. if (info->dma_out_enabled) {
  3332. cris_free_dma(info->dma_out_nbr, info->dma_out_irq_description);
  3333. free_irq(info->dma_out_irq_nbr, info);
  3334. }
  3335. if (info->dma_in_enabled) {
  3336. cris_free_dma(info->dma_in_nbr, info->dma_in_irq_description);
  3337. free_irq(info->dma_in_irq_nbr, info);
  3338. }
  3339. }
  3340. /*
  3341. * This routine is called whenever a serial port is opened.
  3342. * It performs the serial-specific initialization for the tty structure.
  3343. */
  3344. static int
  3345. rs_open(struct tty_struct *tty, struct file * filp)
  3346. {
  3347. struct e100_serial *info;
  3348. int retval;
  3349. int allocated_resources = 0;
  3350. info = rs_table + tty->index;
  3351. if (!info->enabled)
  3352. return -ENODEV;
  3353. #ifdef SERIAL_DEBUG_OPEN
  3354. printk("[%d] rs_open %s, count = %d\n", current->pid, tty->name,
  3355. info->port.count);
  3356. #endif
  3357. info->port.count++;
  3358. tty->driver_data = info;
  3359. info->port.tty = tty;
  3360. info->port.low_latency = !!(info->port.flags & ASYNC_LOW_LATENCY);
  3361. /*
  3362. * If the port is in the middle of closing, bail out now
  3363. */
  3364. if (info->port.flags & ASYNC_CLOSING) {
  3365. wait_event_interruptible_tty(tty, info->port.close_wait,
  3366. !(info->port.flags & ASYNC_CLOSING));
  3367. #ifdef SERIAL_DO_RESTART
  3368. return ((info->port.flags & ASYNC_HUP_NOTIFY) ?
  3369. -EAGAIN : -ERESTARTSYS);
  3370. #else
  3371. return -EAGAIN;
  3372. #endif
  3373. }
  3374. /*
  3375. * If DMA is enabled try to allocate the irq's.
  3376. */
  3377. if (info->port.count == 1) {
  3378. allocated_resources = 1;
  3379. if (info->dma_in_enabled) {
  3380. if (request_irq(info->dma_in_irq_nbr,
  3381. rec_interrupt,
  3382. info->dma_in_irq_flags,
  3383. info->dma_in_irq_description,
  3384. info)) {
  3385. printk(KERN_WARNING "DMA irq '%s' busy; "
  3386. "falling back to non-DMA mode\n",
  3387. info->dma_in_irq_description);
  3388. /* Make sure we never try to use DMA in */
  3389. /* for the port again. */
  3390. info->dma_in_enabled = 0;
  3391. } else if (cris_request_dma(info->dma_in_nbr,
  3392. info->dma_in_irq_description,
  3393. DMA_VERBOSE_ON_ERROR,
  3394. info->dma_owner)) {
  3395. free_irq(info->dma_in_irq_nbr, info);
  3396. printk(KERN_WARNING "DMA '%s' busy; "
  3397. "falling back to non-DMA mode\n",
  3398. info->dma_in_irq_description);
  3399. /* Make sure we never try to use DMA in */
  3400. /* for the port again. */
  3401. info->dma_in_enabled = 0;
  3402. }
  3403. #ifdef SERIAL_DEBUG_OPEN
  3404. else
  3405. printk(KERN_DEBUG "DMA irq '%s' allocated\n",
  3406. info->dma_in_irq_description);
  3407. #endif
  3408. }
  3409. if (info->dma_out_enabled) {
  3410. if (request_irq(info->dma_out_irq_nbr,
  3411. tr_interrupt,
  3412. info->dma_out_irq_flags,
  3413. info->dma_out_irq_description,
  3414. info)) {
  3415. printk(KERN_WARNING "DMA irq '%s' busy; "
  3416. "falling back to non-DMA mode\n",
  3417. info->dma_out_irq_description);
  3418. /* Make sure we never try to use DMA out */
  3419. /* for the port again. */
  3420. info->dma_out_enabled = 0;
  3421. } else if (cris_request_dma(info->dma_out_nbr,
  3422. info->dma_out_irq_description,
  3423. DMA_VERBOSE_ON_ERROR,
  3424. info->dma_owner)) {
  3425. free_irq(info->dma_out_irq_nbr, info);
  3426. printk(KERN_WARNING "DMA '%s' busy; "
  3427. "falling back to non-DMA mode\n",
  3428. info->dma_out_irq_description);
  3429. /* Make sure we never try to use DMA out */
  3430. /* for the port again. */
  3431. info->dma_out_enabled = 0;
  3432. }
  3433. #ifdef SERIAL_DEBUG_OPEN
  3434. else
  3435. printk(KERN_DEBUG "DMA irq '%s' allocated\n",
  3436. info->dma_out_irq_description);
  3437. #endif
  3438. }
  3439. }
  3440. /*
  3441. * Start up the serial port
  3442. */
  3443. retval = startup(info);
  3444. if (retval) {
  3445. if (allocated_resources)
  3446. deinit_port(info);
  3447. /* FIXME Decrease count info->port.count here too? */
  3448. return retval;
  3449. }
  3450. retval = block_til_ready(tty, filp, info);
  3451. if (retval) {
  3452. #ifdef SERIAL_DEBUG_OPEN
  3453. printk("rs_open returning after block_til_ready with %d\n",
  3454. retval);
  3455. #endif
  3456. if (allocated_resources)
  3457. deinit_port(info);
  3458. return retval;
  3459. }
  3460. #ifdef SERIAL_DEBUG_OPEN
  3461. printk("rs_open ttyS%d successful...\n", info->line);
  3462. #endif
  3463. DLOG_INT_TRIG( log_int_pos = 0);
  3464. DFLIP( if (info->line == SERIAL_DEBUG_LINE) {
  3465. info->icount.rx = 0;
  3466. } );
  3467. return 0;
  3468. }
  3469. #ifdef CONFIG_PROC_FS
  3470. /*
  3471. * /proc fs routines....
  3472. */
  3473. static void seq_line_info(struct seq_file *m, struct e100_serial *info)
  3474. {
  3475. unsigned long tmp;
  3476. seq_printf(m, "%d: uart:E100 port:%lX irq:%d",
  3477. info->line, (unsigned long)info->ioport, info->irq);
  3478. if (!info->ioport || (info->type == PORT_UNKNOWN)) {
  3479. seq_printf(m, "\n");
  3480. return;
  3481. }
  3482. seq_printf(m, " baud:%d", info->baud);
  3483. seq_printf(m, " tx:%lu rx:%lu",
  3484. (unsigned long)info->icount.tx,
  3485. (unsigned long)info->icount.rx);
  3486. tmp = CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
  3487. if (tmp)
  3488. seq_printf(m, " tx_pend:%lu/%lu",
  3489. (unsigned long)tmp,
  3490. (unsigned long)SERIAL_XMIT_SIZE);
  3491. seq_printf(m, " rx_pend:%lu/%lu",
  3492. (unsigned long)info->recv_cnt,
  3493. (unsigned long)info->max_recv_cnt);
  3494. #if 1
  3495. if (info->port.tty) {
  3496. if (info->port.tty->stopped)
  3497. seq_printf(m, " stopped:%i",
  3498. (int)info->port.tty->stopped);
  3499. }
  3500. {
  3501. unsigned char rstat = info->ioport[REG_STATUS];
  3502. if (rstat & IO_MASK(R_SERIAL0_STATUS, xoff_detect))
  3503. seq_printf(m, " xoff_detect:1");
  3504. }
  3505. #endif
  3506. if (info->icount.frame)
  3507. seq_printf(m, " fe:%lu", (unsigned long)info->icount.frame);
  3508. if (info->icount.parity)
  3509. seq_printf(m, " pe:%lu", (unsigned long)info->icount.parity);
  3510. if (info->icount.brk)
  3511. seq_printf(m, " brk:%lu", (unsigned long)info->icount.brk);
  3512. if (info->icount.overrun)
  3513. seq_printf(m, " oe:%lu", (unsigned long)info->icount.overrun);
  3514. /*
  3515. * Last thing is the RS-232 status lines
  3516. */
  3517. if (!E100_RTS_GET(info))
  3518. seq_puts(m, "|RTS");
  3519. if (!E100_CTS_GET(info))
  3520. seq_puts(m, "|CTS");
  3521. if (!E100_DTR_GET(info))
  3522. seq_puts(m, "|DTR");
  3523. if (!E100_DSR_GET(info))
  3524. seq_puts(m, "|DSR");
  3525. if (!E100_CD_GET(info))
  3526. seq_puts(m, "|CD");
  3527. if (!E100_RI_GET(info))
  3528. seq_puts(m, "|RI");
  3529. seq_puts(m, "\n");
  3530. }
  3531. static int crisv10_proc_show(struct seq_file *m, void *v)
  3532. {
  3533. int i;
  3534. seq_printf(m, "serinfo:1.0 driver:%s\n", serial_version);
  3535. for (i = 0; i < NR_PORTS; i++) {
  3536. if (!rs_table[i].enabled)
  3537. continue;
  3538. seq_line_info(m, &rs_table[i]);
  3539. }
  3540. #ifdef DEBUG_LOG_INCLUDED
  3541. for (i = 0; i < debug_log_pos; i++) {
  3542. seq_printf(m, "%-4i %lu.%lu ",
  3543. i, debug_log[i].time,
  3544. timer_data_to_ns(debug_log[i].timer_data));
  3545. seq_printf(m, debug_log[i].string, debug_log[i].value);
  3546. }
  3547. seq_printf(m, "debug_log %i/%i\n", i, DEBUG_LOG_SIZE);
  3548. debug_log_pos = 0;
  3549. #endif
  3550. return 0;
  3551. }
  3552. static int crisv10_proc_open(struct inode *inode, struct file *file)
  3553. {
  3554. return single_open(file, crisv10_proc_show, NULL);
  3555. }
  3556. static const struct file_operations crisv10_proc_fops = {
  3557. .owner = THIS_MODULE,
  3558. .open = crisv10_proc_open,
  3559. .read = seq_read,
  3560. .llseek = seq_lseek,
  3561. .release = single_release,
  3562. };
  3563. #endif
  3564. /* Finally, routines used to initialize the serial driver. */
  3565. static void show_serial_version(void)
  3566. {
  3567. printk(KERN_INFO
  3568. "ETRAX 100LX serial-driver %s, "
  3569. "(c) 2000-2004 Axis Communications AB\r\n",
  3570. &serial_version[11]); /* "$Revision: x.yy" */
  3571. }
  3572. /* rs_init inits the driver at boot (using the module_init chain) */
  3573. static const struct tty_operations rs_ops = {
  3574. .open = rs_open,
  3575. .close = rs_close,
  3576. .write = rs_write,
  3577. .flush_chars = rs_flush_chars,
  3578. .write_room = rs_write_room,
  3579. .chars_in_buffer = rs_chars_in_buffer,
  3580. .flush_buffer = rs_flush_buffer,
  3581. .ioctl = rs_ioctl,
  3582. .throttle = rs_throttle,
  3583. .unthrottle = rs_unthrottle,
  3584. .set_termios = rs_set_termios,
  3585. .stop = rs_stop,
  3586. .start = rs_start,
  3587. .hangup = rs_hangup,
  3588. .break_ctl = rs_break,
  3589. .send_xchar = rs_send_xchar,
  3590. .wait_until_sent = rs_wait_until_sent,
  3591. .tiocmget = rs_tiocmget,
  3592. .tiocmset = rs_tiocmset,
  3593. #ifdef CONFIG_PROC_FS
  3594. .proc_fops = &crisv10_proc_fops,
  3595. #endif
  3596. };
  3597. static int __init rs_init(void)
  3598. {
  3599. int i;
  3600. struct e100_serial *info;
  3601. struct tty_driver *driver = alloc_tty_driver(NR_PORTS);
  3602. if (!driver)
  3603. return -ENOMEM;
  3604. show_serial_version();
  3605. /* Setup the timed flush handler system */
  3606. #if !defined(CONFIG_ETRAX_SERIAL_FAST_TIMER)
  3607. setup_timer(&flush_timer, timed_flush_handler, 0);
  3608. mod_timer(&flush_timer, jiffies + 5);
  3609. #endif
  3610. #if defined(CONFIG_ETRAX_RS485)
  3611. #if defined(CONFIG_ETRAX_RS485_ON_PA)
  3612. if (cris_io_interface_allocate_pins(if_serial_0, 'a', rs485_pa_bit,
  3613. rs485_pa_bit)) {
  3614. printk(KERN_ERR "ETRAX100LX serial: Could not allocate "
  3615. "RS485 pin\n");
  3616. put_tty_driver(driver);
  3617. return -EBUSY;
  3618. }
  3619. #endif
  3620. #endif
  3621. /* Initialize the tty_driver structure */
  3622. driver->driver_name = "serial";
  3623. driver->name = "ttyS";
  3624. driver->major = TTY_MAJOR;
  3625. driver->minor_start = 64;
  3626. driver->type = TTY_DRIVER_TYPE_SERIAL;
  3627. driver->subtype = SERIAL_TYPE_NORMAL;
  3628. driver->init_termios = tty_std_termios;
  3629. driver->init_termios.c_cflag =
  3630. B115200 | CS8 | CREAD | HUPCL | CLOCAL; /* is normally B9600 default... */
  3631. driver->init_termios.c_ispeed = 115200;
  3632. driver->init_termios.c_ospeed = 115200;
  3633. driver->flags = TTY_DRIVER_REAL_RAW;
  3634. tty_set_operations(driver, &rs_ops);
  3635. serial_driver = driver;
  3636. /* do some initializing for the separate ports */
  3637. for (i = 0, info = rs_table; i < NR_PORTS; i++,info++) {
  3638. if (info->enabled) {
  3639. if (cris_request_io_interface(info->io_if,
  3640. info->io_if_description)) {
  3641. printk(KERN_ERR "ETRAX100LX async serial: "
  3642. "Could not allocate IO pins for "
  3643. "%s, port %d\n",
  3644. info->io_if_description, i);
  3645. info->enabled = 0;
  3646. }
  3647. }
  3648. tty_port_init(&info->port);
  3649. info->uses_dma_in = 0;
  3650. info->uses_dma_out = 0;
  3651. info->line = i;
  3652. info->port.tty = NULL;
  3653. info->type = PORT_ETRAX;
  3654. info->tr_running = 0;
  3655. info->forced_eop = 0;
  3656. info->baud_base = DEF_BAUD_BASE;
  3657. info->custom_divisor = 0;
  3658. info->x_char = 0;
  3659. info->event = 0;
  3660. info->xmit.buf = NULL;
  3661. info->xmit.tail = info->xmit.head = 0;
  3662. info->first_recv_buffer = info->last_recv_buffer = NULL;
  3663. info->recv_cnt = info->max_recv_cnt = 0;
  3664. info->last_tx_active_usec = 0;
  3665. info->last_tx_active = 0;
  3666. #if defined(CONFIG_ETRAX_RS485)
  3667. /* Set sane defaults */
  3668. info->rs485.flags &= ~(SER_RS485_RTS_ON_SEND);
  3669. info->rs485.flags |= SER_RS485_RTS_AFTER_SEND;
  3670. info->rs485.delay_rts_before_send = 0;
  3671. info->rs485.flags &= ~(SER_RS485_ENABLED);
  3672. #endif
  3673. INIT_WORK(&info->work, do_softint);
  3674. if (info->enabled) {
  3675. printk(KERN_INFO "%s%d at %p is a builtin UART with DMA\n",
  3676. serial_driver->name, info->line, info->ioport);
  3677. }
  3678. tty_port_link_device(&info->port, driver, i);
  3679. }
  3680. if (tty_register_driver(driver))
  3681. panic("Couldn't register serial driver\n");
  3682. #ifdef CONFIG_ETRAX_FAST_TIMER
  3683. #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER
  3684. memset(fast_timers, 0, sizeof(fast_timers));
  3685. #endif
  3686. #ifdef CONFIG_ETRAX_RS485
  3687. memset(fast_timers_rs485, 0, sizeof(fast_timers_rs485));
  3688. #endif
  3689. fast_timer_init();
  3690. #endif
  3691. #ifndef CONFIG_ETRAX_KGDB
  3692. /* Not needed in simulator. May only complicate stuff. */
  3693. /* hook the irq's for DMA channel 6 and 7, serial output and input, and some more... */
  3694. if (request_irq(SERIAL_IRQ_NBR, ser_interrupt,
  3695. IRQF_SHARED, "serial ", driver))
  3696. panic("%s: Failed to request irq8", __func__);
  3697. #endif
  3698. return 0;
  3699. }
  3700. /* this makes sure that rs_init is called during kernel boot */
  3701. module_init(rs_init);