stallion.c 131 KB

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