rocket.c 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184
  1. /*
  2. * RocketPort device driver for Linux
  3. *
  4. * Written by Theodore Ts'o, 1995, 1996, 1997, 1998, 1999, 2000.
  5. *
  6. * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2003 by Comtrol, Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. /*
  23. * Kernel Synchronization:
  24. *
  25. * This driver has 2 kernel control paths - exception handlers (calls into the driver
  26. * from user mode) and the timer bottom half (tasklet). This is a polled driver, interrupts
  27. * are not used.
  28. *
  29. * Critical data:
  30. * - rp_table[], accessed through passed "info" pointers, is a global (static) array of
  31. * serial port state information and the xmit_buf circular buffer. Protected by
  32. * a per port spinlock.
  33. * - xmit_flags[], an array of ints indexed by line (port) number, indicating that there
  34. * is data to be transmitted. Protected by atomic bit operations.
  35. * - rp_num_ports, int indicating number of open ports, protected by atomic operations.
  36. *
  37. * rp_write() and rp_write_char() functions use a per port semaphore to protect against
  38. * simultaneous access to the same port by more than one process.
  39. */
  40. /****** Defines ******/
  41. #define ROCKET_PARANOIA_CHECK
  42. #define ROCKET_DISABLE_SIMUSAGE
  43. #undef ROCKET_SOFT_FLOW
  44. #undef ROCKET_DEBUG_OPEN
  45. #undef ROCKET_DEBUG_INTR
  46. #undef ROCKET_DEBUG_WRITE
  47. #undef ROCKET_DEBUG_FLOW
  48. #undef ROCKET_DEBUG_THROTTLE
  49. #undef ROCKET_DEBUG_WAIT_UNTIL_SENT
  50. #undef ROCKET_DEBUG_RECEIVE
  51. #undef ROCKET_DEBUG_HANGUP
  52. #undef REV_PCI_ORDER
  53. #undef ROCKET_DEBUG_IO
  54. #define POLL_PERIOD HZ/100 /* Polling period .01 seconds (10ms) */
  55. /****** Kernel includes ******/
  56. #include <linux/module.h>
  57. #include <linux/errno.h>
  58. #include <linux/major.h>
  59. #include <linux/kernel.h>
  60. #include <linux/signal.h>
  61. #include <linux/slab.h>
  62. #include <linux/mm.h>
  63. #include <linux/sched.h>
  64. #include <linux/timer.h>
  65. #include <linux/interrupt.h>
  66. #include <linux/tty.h>
  67. #include <linux/tty_driver.h>
  68. #include <linux/tty_flip.h>
  69. #include <linux/serial.h>
  70. #include <linux/string.h>
  71. #include <linux/fcntl.h>
  72. #include <linux/ptrace.h>
  73. #include <linux/mutex.h>
  74. #include <linux/ioport.h>
  75. #include <linux/delay.h>
  76. #include <linux/completion.h>
  77. #include <linux/wait.h>
  78. #include <linux/pci.h>
  79. #include <linux/uaccess.h>
  80. #include <asm/atomic.h>
  81. #include <asm/unaligned.h>
  82. #include <linux/bitops.h>
  83. #include <linux/spinlock.h>
  84. #include <linux/init.h>
  85. /****** RocketPort includes ******/
  86. #include "rocket_int.h"
  87. #include "rocket.h"
  88. #define ROCKET_VERSION "2.09"
  89. #define ROCKET_DATE "12-June-2003"
  90. /****** RocketPort Local Variables ******/
  91. static void rp_do_poll(unsigned long dummy);
  92. static struct tty_driver *rocket_driver;
  93. static struct rocket_version driver_version = {
  94. ROCKET_VERSION, ROCKET_DATE
  95. };
  96. static struct r_port *rp_table[MAX_RP_PORTS]; /* The main repository of serial port state information. */
  97. static unsigned int xmit_flags[NUM_BOARDS]; /* Bit significant, indicates port had data to transmit. */
  98. /* eg. Bit 0 indicates port 0 has xmit data, ... */
  99. static atomic_t rp_num_ports_open; /* Number of serial ports open */
  100. static DEFINE_TIMER(rocket_timer, rp_do_poll, 0, 0);
  101. static unsigned long board1; /* ISA addresses, retrieved from rocketport.conf */
  102. static unsigned long board2;
  103. static unsigned long board3;
  104. static unsigned long board4;
  105. static unsigned long controller;
  106. static int support_low_speed;
  107. static unsigned long modem1;
  108. static unsigned long modem2;
  109. static unsigned long modem3;
  110. static unsigned long modem4;
  111. static unsigned long pc104_1[8];
  112. static unsigned long pc104_2[8];
  113. static unsigned long pc104_3[8];
  114. static unsigned long pc104_4[8];
  115. static unsigned long *pc104[4] = { pc104_1, pc104_2, pc104_3, pc104_4 };
  116. static int rp_baud_base[NUM_BOARDS]; /* Board config info (Someday make a per-board structure) */
  117. static unsigned long rcktpt_io_addr[NUM_BOARDS];
  118. static int rcktpt_type[NUM_BOARDS];
  119. static int is_PCI[NUM_BOARDS];
  120. static rocketModel_t rocketModel[NUM_BOARDS];
  121. static int max_board;
  122. static const struct tty_port_operations rocket_port_ops;
  123. /*
  124. * The following arrays define the interrupt bits corresponding to each AIOP.
  125. * These bits are different between the ISA and regular PCI boards and the
  126. * Universal PCI boards.
  127. */
  128. static Word_t aiop_intr_bits[AIOP_CTL_SIZE] = {
  129. AIOP_INTR_BIT_0,
  130. AIOP_INTR_BIT_1,
  131. AIOP_INTR_BIT_2,
  132. AIOP_INTR_BIT_3
  133. };
  134. static Word_t upci_aiop_intr_bits[AIOP_CTL_SIZE] = {
  135. UPCI_AIOP_INTR_BIT_0,
  136. UPCI_AIOP_INTR_BIT_1,
  137. UPCI_AIOP_INTR_BIT_2,
  138. UPCI_AIOP_INTR_BIT_3
  139. };
  140. static Byte_t RData[RDATASIZE] = {
  141. 0x00, 0x09, 0xf6, 0x82,
  142. 0x02, 0x09, 0x86, 0xfb,
  143. 0x04, 0x09, 0x00, 0x0a,
  144. 0x06, 0x09, 0x01, 0x0a,
  145. 0x08, 0x09, 0x8a, 0x13,
  146. 0x0a, 0x09, 0xc5, 0x11,
  147. 0x0c, 0x09, 0x86, 0x85,
  148. 0x0e, 0x09, 0x20, 0x0a,
  149. 0x10, 0x09, 0x21, 0x0a,
  150. 0x12, 0x09, 0x41, 0xff,
  151. 0x14, 0x09, 0x82, 0x00,
  152. 0x16, 0x09, 0x82, 0x7b,
  153. 0x18, 0x09, 0x8a, 0x7d,
  154. 0x1a, 0x09, 0x88, 0x81,
  155. 0x1c, 0x09, 0x86, 0x7a,
  156. 0x1e, 0x09, 0x84, 0x81,
  157. 0x20, 0x09, 0x82, 0x7c,
  158. 0x22, 0x09, 0x0a, 0x0a
  159. };
  160. static Byte_t RRegData[RREGDATASIZE] = {
  161. 0x00, 0x09, 0xf6, 0x82, /* 00: Stop Rx processor */
  162. 0x08, 0x09, 0x8a, 0x13, /* 04: Tx software flow control */
  163. 0x0a, 0x09, 0xc5, 0x11, /* 08: XON char */
  164. 0x0c, 0x09, 0x86, 0x85, /* 0c: XANY */
  165. 0x12, 0x09, 0x41, 0xff, /* 10: Rx mask char */
  166. 0x14, 0x09, 0x82, 0x00, /* 14: Compare/Ignore #0 */
  167. 0x16, 0x09, 0x82, 0x7b, /* 18: Compare #1 */
  168. 0x18, 0x09, 0x8a, 0x7d, /* 1c: Compare #2 */
  169. 0x1a, 0x09, 0x88, 0x81, /* 20: Interrupt #1 */
  170. 0x1c, 0x09, 0x86, 0x7a, /* 24: Ignore/Replace #1 */
  171. 0x1e, 0x09, 0x84, 0x81, /* 28: Interrupt #2 */
  172. 0x20, 0x09, 0x82, 0x7c, /* 2c: Ignore/Replace #2 */
  173. 0x22, 0x09, 0x0a, 0x0a /* 30: Rx FIFO Enable */
  174. };
  175. static CONTROLLER_T sController[CTL_SIZE] = {
  176. {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
  177. {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}},
  178. {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
  179. {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}},
  180. {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
  181. {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}},
  182. {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
  183. {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}}
  184. };
  185. static Byte_t sBitMapClrTbl[8] = {
  186. 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f
  187. };
  188. static Byte_t sBitMapSetTbl[8] = {
  189. 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
  190. };
  191. static int sClockPrescale = 0x14;
  192. /*
  193. * Line number is the ttySIx number (x), the Minor number. We
  194. * assign them sequentially, starting at zero. The following
  195. * array keeps track of the line number assigned to a given board/aiop/channel.
  196. */
  197. static unsigned char lineNumbers[MAX_RP_PORTS];
  198. static unsigned long nextLineNumber;
  199. /***** RocketPort Static Prototypes *********/
  200. static int __init init_ISA(int i);
  201. static void rp_wait_until_sent(struct tty_struct *tty, int timeout);
  202. static void rp_flush_buffer(struct tty_struct *tty);
  203. static void rmSpeakerReset(CONTROLLER_T * CtlP, unsigned long model);
  204. static unsigned char GetLineNumber(int ctrl, int aiop, int ch);
  205. static unsigned char SetLineNumber(int ctrl, int aiop, int ch);
  206. static void rp_start(struct tty_struct *tty);
  207. static int sInitChan(CONTROLLER_T * CtlP, CHANNEL_T * ChP, int AiopNum,
  208. int ChanNum);
  209. static void sSetInterfaceMode(CHANNEL_T * ChP, Byte_t mode);
  210. static void sFlushRxFIFO(CHANNEL_T * ChP);
  211. static void sFlushTxFIFO(CHANNEL_T * ChP);
  212. static void sEnInterrupts(CHANNEL_T * ChP, Word_t Flags);
  213. static void sDisInterrupts(CHANNEL_T * ChP, Word_t Flags);
  214. static void sModemReset(CONTROLLER_T * CtlP, int chan, int on);
  215. static void sPCIModemReset(CONTROLLER_T * CtlP, int chan, int on);
  216. static int sWriteTxPrioByte(CHANNEL_T * ChP, Byte_t Data);
  217. static int sPCIInitController(CONTROLLER_T * CtlP, int CtlNum,
  218. ByteIO_t * AiopIOList, int AiopIOListSize,
  219. WordIO_t ConfigIO, int IRQNum, Byte_t Frequency,
  220. int PeriodicOnly, int altChanRingIndicator,
  221. int UPCIRingInd);
  222. static int sInitController(CONTROLLER_T * CtlP, int CtlNum, ByteIO_t MudbacIO,
  223. ByteIO_t * AiopIOList, int AiopIOListSize,
  224. int IRQNum, Byte_t Frequency, int PeriodicOnly);
  225. static int sReadAiopID(ByteIO_t io);
  226. static int sReadAiopNumChan(WordIO_t io);
  227. MODULE_AUTHOR("Theodore Ts'o");
  228. MODULE_DESCRIPTION("Comtrol RocketPort driver");
  229. module_param(board1, ulong, 0);
  230. MODULE_PARM_DESC(board1, "I/O port for (ISA) board #1");
  231. module_param(board2, ulong, 0);
  232. MODULE_PARM_DESC(board2, "I/O port for (ISA) board #2");
  233. module_param(board3, ulong, 0);
  234. MODULE_PARM_DESC(board3, "I/O port for (ISA) board #3");
  235. module_param(board4, ulong, 0);
  236. MODULE_PARM_DESC(board4, "I/O port for (ISA) board #4");
  237. module_param(controller, ulong, 0);
  238. MODULE_PARM_DESC(controller, "I/O port for (ISA) rocketport controller");
  239. module_param(support_low_speed, bool, 0);
  240. MODULE_PARM_DESC(support_low_speed, "1 means support 50 baud, 0 means support 460400 baud");
  241. module_param(modem1, ulong, 0);
  242. MODULE_PARM_DESC(modem1, "1 means (ISA) board #1 is a RocketModem");
  243. module_param(modem2, ulong, 0);
  244. MODULE_PARM_DESC(modem2, "1 means (ISA) board #2 is a RocketModem");
  245. module_param(modem3, ulong, 0);
  246. MODULE_PARM_DESC(modem3, "1 means (ISA) board #3 is a RocketModem");
  247. module_param(modem4, ulong, 0);
  248. MODULE_PARM_DESC(modem4, "1 means (ISA) board #4 is a RocketModem");
  249. module_param_array(pc104_1, ulong, NULL, 0);
  250. MODULE_PARM_DESC(pc104_1, "set interface types for ISA(PC104) board #1 (e.g. pc104_1=232,232,485,485,...");
  251. module_param_array(pc104_2, ulong, NULL, 0);
  252. MODULE_PARM_DESC(pc104_2, "set interface types for ISA(PC104) board #2 (e.g. pc104_2=232,232,485,485,...");
  253. module_param_array(pc104_3, ulong, NULL, 0);
  254. MODULE_PARM_DESC(pc104_3, "set interface types for ISA(PC104) board #3 (e.g. pc104_3=232,232,485,485,...");
  255. module_param_array(pc104_4, ulong, NULL, 0);
  256. MODULE_PARM_DESC(pc104_4, "set interface types for ISA(PC104) board #4 (e.g. pc104_4=232,232,485,485,...");
  257. static int rp_init(void);
  258. static void rp_cleanup_module(void);
  259. module_init(rp_init);
  260. module_exit(rp_cleanup_module);
  261. MODULE_LICENSE("Dual BSD/GPL");
  262. /*************************************************************************/
  263. /* Module code starts here */
  264. static inline int rocket_paranoia_check(struct r_port *info,
  265. const char *routine)
  266. {
  267. #ifdef ROCKET_PARANOIA_CHECK
  268. if (!info)
  269. return 1;
  270. if (info->magic != RPORT_MAGIC) {
  271. printk(KERN_WARNING "Warning: bad magic number for rocketport "
  272. "struct in %s\n", routine);
  273. return 1;
  274. }
  275. #endif
  276. return 0;
  277. }
  278. /* Serial port receive data function. Called (from timer poll) when an AIOPIC signals
  279. * that receive data is present on a serial port. Pulls data from FIFO, moves it into the
  280. * tty layer.
  281. */
  282. static void rp_do_receive(struct r_port *info,
  283. struct tty_struct *tty,
  284. CHANNEL_t * cp, unsigned int ChanStatus)
  285. {
  286. unsigned int CharNStat;
  287. int ToRecv, wRecv, space;
  288. unsigned char *cbuf;
  289. ToRecv = sGetRxCnt(cp);
  290. #ifdef ROCKET_DEBUG_INTR
  291. printk(KERN_INFO "rp_do_receive(%d)...\n", ToRecv);
  292. #endif
  293. if (ToRecv == 0)
  294. return;
  295. /*
  296. * if status indicates there are errored characters in the
  297. * FIFO, then enter status mode (a word in FIFO holds
  298. * character and status).
  299. */
  300. if (ChanStatus & (RXFOVERFL | RXBREAK | RXFRAME | RXPARITY)) {
  301. if (!(ChanStatus & STATMODE)) {
  302. #ifdef ROCKET_DEBUG_RECEIVE
  303. printk(KERN_INFO "Entering STATMODE...\n");
  304. #endif
  305. ChanStatus |= STATMODE;
  306. sEnRxStatusMode(cp);
  307. }
  308. }
  309. /*
  310. * if we previously entered status mode, then read down the
  311. * FIFO one word at a time, pulling apart the character and
  312. * the status. Update error counters depending on status
  313. */
  314. if (ChanStatus & STATMODE) {
  315. #ifdef ROCKET_DEBUG_RECEIVE
  316. printk(KERN_INFO "Ignore %x, read %x...\n",
  317. info->ignore_status_mask, info->read_status_mask);
  318. #endif
  319. while (ToRecv) {
  320. char flag;
  321. CharNStat = sInW(sGetTxRxDataIO(cp));
  322. #ifdef ROCKET_DEBUG_RECEIVE
  323. printk(KERN_INFO "%x...\n", CharNStat);
  324. #endif
  325. if (CharNStat & STMBREAKH)
  326. CharNStat &= ~(STMFRAMEH | STMPARITYH);
  327. if (CharNStat & info->ignore_status_mask) {
  328. ToRecv--;
  329. continue;
  330. }
  331. CharNStat &= info->read_status_mask;
  332. if (CharNStat & STMBREAKH)
  333. flag = TTY_BREAK;
  334. else if (CharNStat & STMPARITYH)
  335. flag = TTY_PARITY;
  336. else if (CharNStat & STMFRAMEH)
  337. flag = TTY_FRAME;
  338. else if (CharNStat & STMRCVROVRH)
  339. flag = TTY_OVERRUN;
  340. else
  341. flag = TTY_NORMAL;
  342. tty_insert_flip_char(tty, CharNStat & 0xff, flag);
  343. ToRecv--;
  344. }
  345. /*
  346. * after we've emptied the FIFO in status mode, turn
  347. * status mode back off
  348. */
  349. if (sGetRxCnt(cp) == 0) {
  350. #ifdef ROCKET_DEBUG_RECEIVE
  351. printk(KERN_INFO "Status mode off.\n");
  352. #endif
  353. sDisRxStatusMode(cp);
  354. }
  355. } else {
  356. /*
  357. * we aren't in status mode, so read down the FIFO two
  358. * characters at time by doing repeated word IO
  359. * transfer.
  360. */
  361. space = tty_prepare_flip_string(tty, &cbuf, ToRecv);
  362. if (space < ToRecv) {
  363. #ifdef ROCKET_DEBUG_RECEIVE
  364. printk(KERN_INFO "rp_do_receive:insufficient space ToRecv=%d space=%d\n", ToRecv, space);
  365. #endif
  366. if (space <= 0)
  367. return;
  368. ToRecv = space;
  369. }
  370. wRecv = ToRecv >> 1;
  371. if (wRecv)
  372. sInStrW(sGetTxRxDataIO(cp), (unsigned short *) cbuf, wRecv);
  373. if (ToRecv & 1)
  374. cbuf[ToRecv - 1] = sInB(sGetTxRxDataIO(cp));
  375. }
  376. /* Push the data up to the tty layer */
  377. tty_flip_buffer_push(tty);
  378. }
  379. /*
  380. * Serial port transmit data function. Called from the timer polling loop as a
  381. * result of a bit set in xmit_flags[], indicating data (from the tty layer) is ready
  382. * to be sent out the serial port. Data is buffered in rp_table[line].xmit_buf, it is
  383. * moved to the port's xmit FIFO. *info is critical data, protected by spinlocks.
  384. */
  385. static void rp_do_transmit(struct r_port *info)
  386. {
  387. int c;
  388. CHANNEL_t *cp = &info->channel;
  389. struct tty_struct *tty;
  390. unsigned long flags;
  391. #ifdef ROCKET_DEBUG_INTR
  392. printk(KERN_DEBUG "%s\n", __func__);
  393. #endif
  394. if (!info)
  395. return;
  396. tty = tty_port_tty_get(&info->port);
  397. if (tty == NULL) {
  398. printk(KERN_WARNING "rp: WARNING %s called with tty==NULL\n", __func__);
  399. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  400. return;
  401. }
  402. spin_lock_irqsave(&info->slock, flags);
  403. info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp);
  404. /* Loop sending data to FIFO until done or FIFO full */
  405. while (1) {
  406. if (tty->stopped || tty->hw_stopped)
  407. break;
  408. c = min(info->xmit_fifo_room, info->xmit_cnt);
  409. c = min(c, XMIT_BUF_SIZE - info->xmit_tail);
  410. if (c <= 0 || info->xmit_fifo_room <= 0)
  411. break;
  412. sOutStrW(sGetTxRxDataIO(cp), (unsigned short *) (info->xmit_buf + info->xmit_tail), c / 2);
  413. if (c & 1)
  414. sOutB(sGetTxRxDataIO(cp), info->xmit_buf[info->xmit_tail + c - 1]);
  415. info->xmit_tail += c;
  416. info->xmit_tail &= XMIT_BUF_SIZE - 1;
  417. info->xmit_cnt -= c;
  418. info->xmit_fifo_room -= c;
  419. #ifdef ROCKET_DEBUG_INTR
  420. printk(KERN_INFO "tx %d chars...\n", c);
  421. #endif
  422. }
  423. if (info->xmit_cnt == 0)
  424. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  425. if (info->xmit_cnt < WAKEUP_CHARS) {
  426. tty_wakeup(tty);
  427. #ifdef ROCKETPORT_HAVE_POLL_WAIT
  428. wake_up_interruptible(&tty->poll_wait);
  429. #endif
  430. }
  431. spin_unlock_irqrestore(&info->slock, flags);
  432. tty_kref_put(tty);
  433. #ifdef ROCKET_DEBUG_INTR
  434. printk(KERN_DEBUG "(%d,%d,%d,%d)...\n", info->xmit_cnt, info->xmit_head,
  435. info->xmit_tail, info->xmit_fifo_room);
  436. #endif
  437. }
  438. /*
  439. * Called when a serial port signals it has read data in it's RX FIFO.
  440. * It checks what interrupts are pending and services them, including
  441. * receiving serial data.
  442. */
  443. static void rp_handle_port(struct r_port *info)
  444. {
  445. CHANNEL_t *cp;
  446. struct tty_struct *tty;
  447. unsigned int IntMask, ChanStatus;
  448. if (!info)
  449. return;
  450. if ((info->port.flags & ASYNC_INITIALIZED) == 0) {
  451. printk(KERN_WARNING "rp: WARNING: rp_handle_port called with "
  452. "info->flags & NOT_INIT\n");
  453. return;
  454. }
  455. tty = tty_port_tty_get(&info->port);
  456. if (!tty) {
  457. printk(KERN_WARNING "rp: WARNING: rp_handle_port called with "
  458. "tty==NULL\n");
  459. return;
  460. }
  461. cp = &info->channel;
  462. IntMask = sGetChanIntID(cp) & info->intmask;
  463. #ifdef ROCKET_DEBUG_INTR
  464. printk(KERN_INFO "rp_interrupt %02x...\n", IntMask);
  465. #endif
  466. ChanStatus = sGetChanStatus(cp);
  467. if (IntMask & RXF_TRIG) { /* Rx FIFO trigger level */
  468. rp_do_receive(info, tty, cp, ChanStatus);
  469. }
  470. if (IntMask & DELTA_CD) { /* CD change */
  471. #if (defined(ROCKET_DEBUG_OPEN) || defined(ROCKET_DEBUG_INTR) || defined(ROCKET_DEBUG_HANGUP))
  472. printk(KERN_INFO "ttyR%d CD now %s...\n", info->line,
  473. (ChanStatus & CD_ACT) ? "on" : "off");
  474. #endif
  475. if (!(ChanStatus & CD_ACT) && info->cd_status) {
  476. #ifdef ROCKET_DEBUG_HANGUP
  477. printk(KERN_INFO "CD drop, calling hangup.\n");
  478. #endif
  479. tty_hangup(tty);
  480. }
  481. info->cd_status = (ChanStatus & CD_ACT) ? 1 : 0;
  482. wake_up_interruptible(&info->port.open_wait);
  483. }
  484. #ifdef ROCKET_DEBUG_INTR
  485. if (IntMask & DELTA_CTS) { /* CTS change */
  486. printk(KERN_INFO "CTS change...\n");
  487. }
  488. if (IntMask & DELTA_DSR) { /* DSR change */
  489. printk(KERN_INFO "DSR change...\n");
  490. }
  491. #endif
  492. tty_kref_put(tty);
  493. }
  494. /*
  495. * The top level polling routine. Repeats every 1/100 HZ (10ms).
  496. */
  497. static void rp_do_poll(unsigned long dummy)
  498. {
  499. CONTROLLER_t *ctlp;
  500. int ctrl, aiop, ch, line;
  501. unsigned int xmitmask, i;
  502. unsigned int CtlMask;
  503. unsigned char AiopMask;
  504. Word_t bit;
  505. /* Walk through all the boards (ctrl's) */
  506. for (ctrl = 0; ctrl < max_board; ctrl++) {
  507. if (rcktpt_io_addr[ctrl] <= 0)
  508. continue;
  509. /* Get a ptr to the board's control struct */
  510. ctlp = sCtlNumToCtlPtr(ctrl);
  511. /* Get the interrupt status from the board */
  512. #ifdef CONFIG_PCI
  513. if (ctlp->BusType == isPCI)
  514. CtlMask = sPCIGetControllerIntStatus(ctlp);
  515. else
  516. #endif
  517. CtlMask = sGetControllerIntStatus(ctlp);
  518. /* Check if any AIOP read bits are set */
  519. for (aiop = 0; CtlMask; aiop++) {
  520. bit = ctlp->AiopIntrBits[aiop];
  521. if (CtlMask & bit) {
  522. CtlMask &= ~bit;
  523. AiopMask = sGetAiopIntStatus(ctlp, aiop);
  524. /* Check if any port read bits are set */
  525. for (ch = 0; AiopMask; AiopMask >>= 1, ch++) {
  526. if (AiopMask & 1) {
  527. /* Get the line number (/dev/ttyRx number). */
  528. /* Read the data from the port. */
  529. line = GetLineNumber(ctrl, aiop, ch);
  530. rp_handle_port(rp_table[line]);
  531. }
  532. }
  533. }
  534. }
  535. xmitmask = xmit_flags[ctrl];
  536. /*
  537. * xmit_flags contains bit-significant flags, indicating there is data
  538. * to xmit on the port. Bit 0 is port 0 on this board, bit 1 is port
  539. * 1, ... (32 total possible). The variable i has the aiop and ch
  540. * numbers encoded in it (port 0-7 are aiop0, 8-15 are aiop1, etc).
  541. */
  542. if (xmitmask) {
  543. for (i = 0; i < rocketModel[ctrl].numPorts; i++) {
  544. if (xmitmask & (1 << i)) {
  545. aiop = (i & 0x18) >> 3;
  546. ch = i & 0x07;
  547. line = GetLineNumber(ctrl, aiop, ch);
  548. rp_do_transmit(rp_table[line]);
  549. }
  550. }
  551. }
  552. }
  553. /*
  554. * Reset the timer so we get called at the next clock tick (10ms).
  555. */
  556. if (atomic_read(&rp_num_ports_open))
  557. mod_timer(&rocket_timer, jiffies + POLL_PERIOD);
  558. }
  559. /*
  560. * Initializes the r_port structure for a port, as well as enabling the port on
  561. * the board.
  562. * Inputs: board, aiop, chan numbers
  563. */
  564. static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
  565. {
  566. unsigned rocketMode;
  567. struct r_port *info;
  568. int line;
  569. CONTROLLER_T *ctlp;
  570. /* Get the next available line number */
  571. line = SetLineNumber(board, aiop, chan);
  572. ctlp = sCtlNumToCtlPtr(board);
  573. /* Get a r_port struct for the port, fill it in and save it globally, indexed by line number */
  574. info = kzalloc(sizeof (struct r_port), GFP_KERNEL);
  575. if (!info) {
  576. printk(KERN_ERR "Couldn't allocate info struct for line #%d\n",
  577. line);
  578. return;
  579. }
  580. info->magic = RPORT_MAGIC;
  581. info->line = line;
  582. info->ctlp = ctlp;
  583. info->board = board;
  584. info->aiop = aiop;
  585. info->chan = chan;
  586. tty_port_init(&info->port);
  587. info->port.ops = &rocket_port_ops;
  588. init_completion(&info->close_wait);
  589. info->flags &= ~ROCKET_MODE_MASK;
  590. switch (pc104[board][line]) {
  591. case 422:
  592. info->flags |= ROCKET_MODE_RS422;
  593. break;
  594. case 485:
  595. info->flags |= ROCKET_MODE_RS485;
  596. break;
  597. case 232:
  598. default:
  599. info->flags |= ROCKET_MODE_RS232;
  600. break;
  601. }
  602. info->intmask = RXF_TRIG | TXFIFO_MT | SRC_INT | DELTA_CD | DELTA_CTS | DELTA_DSR;
  603. if (sInitChan(ctlp, &info->channel, aiop, chan) == 0) {
  604. printk(KERN_ERR "RocketPort sInitChan(%d, %d, %d) failed!\n",
  605. board, aiop, chan);
  606. kfree(info);
  607. return;
  608. }
  609. rocketMode = info->flags & ROCKET_MODE_MASK;
  610. if ((info->flags & ROCKET_RTS_TOGGLE) || (rocketMode == ROCKET_MODE_RS485))
  611. sEnRTSToggle(&info->channel);
  612. else
  613. sDisRTSToggle(&info->channel);
  614. if (ctlp->boardType == ROCKET_TYPE_PC104) {
  615. switch (rocketMode) {
  616. case ROCKET_MODE_RS485:
  617. sSetInterfaceMode(&info->channel, InterfaceModeRS485);
  618. break;
  619. case ROCKET_MODE_RS422:
  620. sSetInterfaceMode(&info->channel, InterfaceModeRS422);
  621. break;
  622. case ROCKET_MODE_RS232:
  623. default:
  624. if (info->flags & ROCKET_RTS_TOGGLE)
  625. sSetInterfaceMode(&info->channel, InterfaceModeRS232T);
  626. else
  627. sSetInterfaceMode(&info->channel, InterfaceModeRS232);
  628. break;
  629. }
  630. }
  631. spin_lock_init(&info->slock);
  632. mutex_init(&info->write_mtx);
  633. rp_table[line] = info;
  634. tty_register_device(rocket_driver, line, pci_dev ? &pci_dev->dev :
  635. NULL);
  636. }
  637. /*
  638. * Configures a rocketport port according to its termio settings. Called from
  639. * user mode into the driver (exception handler). *info CD manipulation is spinlock protected.
  640. */
  641. static void configure_r_port(struct tty_struct *tty, struct r_port *info,
  642. struct ktermios *old_termios)
  643. {
  644. unsigned cflag;
  645. unsigned long flags;
  646. unsigned rocketMode;
  647. int bits, baud, divisor;
  648. CHANNEL_t *cp;
  649. struct ktermios *t = tty->termios;
  650. cp = &info->channel;
  651. cflag = t->c_cflag;
  652. /* Byte size and parity */
  653. if ((cflag & CSIZE) == CS8) {
  654. sSetData8(cp);
  655. bits = 10;
  656. } else {
  657. sSetData7(cp);
  658. bits = 9;
  659. }
  660. if (cflag & CSTOPB) {
  661. sSetStop2(cp);
  662. bits++;
  663. } else {
  664. sSetStop1(cp);
  665. }
  666. if (cflag & PARENB) {
  667. sEnParity(cp);
  668. bits++;
  669. if (cflag & PARODD) {
  670. sSetOddParity(cp);
  671. } else {
  672. sSetEvenParity(cp);
  673. }
  674. } else {
  675. sDisParity(cp);
  676. }
  677. /* baud rate */
  678. baud = tty_get_baud_rate(tty);
  679. if (!baud)
  680. baud = 9600;
  681. divisor = ((rp_baud_base[info->board] + (baud >> 1)) / baud) - 1;
  682. if ((divisor >= 8192 || divisor < 0) && old_termios) {
  683. baud = tty_termios_baud_rate(old_termios);
  684. if (!baud)
  685. baud = 9600;
  686. divisor = (rp_baud_base[info->board] / baud) - 1;
  687. }
  688. if (divisor >= 8192 || divisor < 0) {
  689. baud = 9600;
  690. divisor = (rp_baud_base[info->board] / baud) - 1;
  691. }
  692. info->cps = baud / bits;
  693. sSetBaud(cp, divisor);
  694. /* FIXME: Should really back compute a baud rate from the divisor */
  695. tty_encode_baud_rate(tty, baud, baud);
  696. if (cflag & CRTSCTS) {
  697. info->intmask |= DELTA_CTS;
  698. sEnCTSFlowCtl(cp);
  699. } else {
  700. info->intmask &= ~DELTA_CTS;
  701. sDisCTSFlowCtl(cp);
  702. }
  703. if (cflag & CLOCAL) {
  704. info->intmask &= ~DELTA_CD;
  705. } else {
  706. spin_lock_irqsave(&info->slock, flags);
  707. if (sGetChanStatus(cp) & CD_ACT)
  708. info->cd_status = 1;
  709. else
  710. info->cd_status = 0;
  711. info->intmask |= DELTA_CD;
  712. spin_unlock_irqrestore(&info->slock, flags);
  713. }
  714. /*
  715. * Handle software flow control in the board
  716. */
  717. #ifdef ROCKET_SOFT_FLOW
  718. if (I_IXON(tty)) {
  719. sEnTxSoftFlowCtl(cp);
  720. if (I_IXANY(tty)) {
  721. sEnIXANY(cp);
  722. } else {
  723. sDisIXANY(cp);
  724. }
  725. sSetTxXONChar(cp, START_CHAR(tty));
  726. sSetTxXOFFChar(cp, STOP_CHAR(tty));
  727. } else {
  728. sDisTxSoftFlowCtl(cp);
  729. sDisIXANY(cp);
  730. sClrTxXOFF(cp);
  731. }
  732. #endif
  733. /*
  734. * Set up ignore/read mask words
  735. */
  736. info->read_status_mask = STMRCVROVRH | 0xFF;
  737. if (I_INPCK(tty))
  738. info->read_status_mask |= STMFRAMEH | STMPARITYH;
  739. if (I_BRKINT(tty) || I_PARMRK(tty))
  740. info->read_status_mask |= STMBREAKH;
  741. /*
  742. * Characters to ignore
  743. */
  744. info->ignore_status_mask = 0;
  745. if (I_IGNPAR(tty))
  746. info->ignore_status_mask |= STMFRAMEH | STMPARITYH;
  747. if (I_IGNBRK(tty)) {
  748. info->ignore_status_mask |= STMBREAKH;
  749. /*
  750. * If we're ignoring parity and break indicators,
  751. * ignore overruns too. (For real raw support).
  752. */
  753. if (I_IGNPAR(tty))
  754. info->ignore_status_mask |= STMRCVROVRH;
  755. }
  756. rocketMode = info->flags & ROCKET_MODE_MASK;
  757. if ((info->flags & ROCKET_RTS_TOGGLE)
  758. || (rocketMode == ROCKET_MODE_RS485))
  759. sEnRTSToggle(cp);
  760. else
  761. sDisRTSToggle(cp);
  762. sSetRTS(&info->channel);
  763. if (cp->CtlP->boardType == ROCKET_TYPE_PC104) {
  764. switch (rocketMode) {
  765. case ROCKET_MODE_RS485:
  766. sSetInterfaceMode(cp, InterfaceModeRS485);
  767. break;
  768. case ROCKET_MODE_RS422:
  769. sSetInterfaceMode(cp, InterfaceModeRS422);
  770. break;
  771. case ROCKET_MODE_RS232:
  772. default:
  773. if (info->flags & ROCKET_RTS_TOGGLE)
  774. sSetInterfaceMode(cp, InterfaceModeRS232T);
  775. else
  776. sSetInterfaceMode(cp, InterfaceModeRS232);
  777. break;
  778. }
  779. }
  780. }
  781. static int carrier_raised(struct tty_port *port)
  782. {
  783. struct r_port *info = container_of(port, struct r_port, port);
  784. return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0;
  785. }
  786. static void dtr_rts(struct tty_port *port, int on)
  787. {
  788. struct r_port *info = container_of(port, struct r_port, port);
  789. if (on) {
  790. sSetDTR(&info->channel);
  791. sSetRTS(&info->channel);
  792. } else {
  793. sClrDTR(&info->channel);
  794. sClrRTS(&info->channel);
  795. }
  796. }
  797. /*
  798. * Exception handler that opens a serial port. Creates xmit_buf storage, fills in
  799. * port's r_port struct. Initializes the port hardware.
  800. */
  801. static int rp_open(struct tty_struct *tty, struct file *filp)
  802. {
  803. struct r_port *info;
  804. struct tty_port *port;
  805. int line = 0, retval;
  806. CHANNEL_t *cp;
  807. unsigned long page;
  808. line = tty->index;
  809. if (line < 0 || line >= MAX_RP_PORTS || ((info = rp_table[line]) == NULL))
  810. return -ENXIO;
  811. port = &info->port;
  812. page = __get_free_page(GFP_KERNEL);
  813. if (!page)
  814. return -ENOMEM;
  815. if (port->flags & ASYNC_CLOSING) {
  816. retval = wait_for_completion_interruptible(&info->close_wait);
  817. free_page(page);
  818. if (retval)
  819. return retval;
  820. return ((port->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
  821. }
  822. /*
  823. * We must not sleep from here until the port is marked fully in use.
  824. */
  825. if (info->xmit_buf)
  826. free_page(page);
  827. else
  828. info->xmit_buf = (unsigned char *) page;
  829. tty->driver_data = info;
  830. tty_port_tty_set(port, tty);
  831. if (port->count++ == 0) {
  832. atomic_inc(&rp_num_ports_open);
  833. #ifdef ROCKET_DEBUG_OPEN
  834. printk(KERN_INFO "rocket mod++ = %d...\n",
  835. atomic_read(&rp_num_ports_open));
  836. #endif
  837. }
  838. #ifdef ROCKET_DEBUG_OPEN
  839. printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
  840. #endif
  841. /*
  842. * Info->count is now 1; so it's safe to sleep now.
  843. */
  844. if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) {
  845. cp = &info->channel;
  846. sSetRxTrigger(cp, TRIG_1);
  847. if (sGetChanStatus(cp) & CD_ACT)
  848. info->cd_status = 1;
  849. else
  850. info->cd_status = 0;
  851. sDisRxStatusMode(cp);
  852. sFlushRxFIFO(cp);
  853. sFlushTxFIFO(cp);
  854. sEnInterrupts(cp, (TXINT_EN | MCINT_EN | RXINT_EN | SRCINT_EN | CHANINT_EN));
  855. sSetRxTrigger(cp, TRIG_1);
  856. sGetChanStatus(cp);
  857. sDisRxStatusMode(cp);
  858. sClrTxXOFF(cp);
  859. sDisCTSFlowCtl(cp);
  860. sDisTxSoftFlowCtl(cp);
  861. sEnRxFIFO(cp);
  862. sEnTransmit(cp);
  863. set_bit(ASYNCB_INITIALIZED, &info->port.flags);
  864. /*
  865. * Set up the tty->alt_speed kludge
  866. */
  867. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI)
  868. tty->alt_speed = 57600;
  869. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI)
  870. tty->alt_speed = 115200;
  871. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI)
  872. tty->alt_speed = 230400;
  873. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP)
  874. tty->alt_speed = 460800;
  875. configure_r_port(tty, info, NULL);
  876. if (tty->termios->c_cflag & CBAUD) {
  877. sSetDTR(cp);
  878. sSetRTS(cp);
  879. }
  880. }
  881. /* Starts (or resets) the maint polling loop */
  882. mod_timer(&rocket_timer, jiffies + POLL_PERIOD);
  883. retval = tty_port_block_til_ready(port, tty, filp);
  884. if (retval) {
  885. #ifdef ROCKET_DEBUG_OPEN
  886. printk(KERN_INFO "rp_open returning after block_til_ready with %d\n", retval);
  887. #endif
  888. return retval;
  889. }
  890. return 0;
  891. }
  892. /*
  893. * Exception handler that closes a serial port. info->port.count is considered critical.
  894. */
  895. static void rp_close(struct tty_struct *tty, struct file *filp)
  896. {
  897. struct r_port *info = tty->driver_data;
  898. struct tty_port *port = &info->port;
  899. int timeout;
  900. CHANNEL_t *cp;
  901. if (rocket_paranoia_check(info, "rp_close"))
  902. return;
  903. #ifdef ROCKET_DEBUG_OPEN
  904. printk(KERN_INFO "rp_close ttyR%d, count = %d\n", info->line, info->port.count);
  905. #endif
  906. if (tty_port_close_start(port, tty, filp) == 0)
  907. return;
  908. cp = &info->channel;
  909. /*
  910. * Before we drop DTR, make sure the UART transmitter
  911. * has completely drained; this is especially
  912. * important if there is a transmit FIFO!
  913. */
  914. timeout = (sGetTxCnt(cp) + 1) * HZ / info->cps;
  915. if (timeout == 0)
  916. timeout = 1;
  917. rp_wait_until_sent(tty, timeout);
  918. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  919. sDisTransmit(cp);
  920. sDisInterrupts(cp, (TXINT_EN | MCINT_EN | RXINT_EN | SRCINT_EN | CHANINT_EN));
  921. sDisCTSFlowCtl(cp);
  922. sDisTxSoftFlowCtl(cp);
  923. sClrTxXOFF(cp);
  924. sFlushRxFIFO(cp);
  925. sFlushTxFIFO(cp);
  926. sClrRTS(cp);
  927. if (C_HUPCL(tty))
  928. sClrDTR(cp);
  929. rp_flush_buffer(tty);
  930. tty_ldisc_flush(tty);
  931. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  932. /* We can't yet use tty_port_close_end as the buffer handling in this
  933. driver is a bit different to the usual */
  934. if (port->blocked_open) {
  935. if (port->close_delay) {
  936. msleep_interruptible(jiffies_to_msecs(port->close_delay));
  937. }
  938. wake_up_interruptible(&port->open_wait);
  939. } else {
  940. if (info->xmit_buf) {
  941. free_page((unsigned long) info->xmit_buf);
  942. info->xmit_buf = NULL;
  943. }
  944. }
  945. info->port.flags &= ~(ASYNC_INITIALIZED | ASYNC_CLOSING | ASYNC_NORMAL_ACTIVE);
  946. tty->closing = 0;
  947. tty_port_tty_set(port, NULL);
  948. wake_up_interruptible(&port->close_wait);
  949. complete_all(&info->close_wait);
  950. atomic_dec(&rp_num_ports_open);
  951. #ifdef ROCKET_DEBUG_OPEN
  952. printk(KERN_INFO "rocket mod-- = %d...\n",
  953. atomic_read(&rp_num_ports_open));
  954. printk(KERN_INFO "rp_close ttyR%d complete shutdown\n", info->line);
  955. #endif
  956. }
  957. static void rp_set_termios(struct tty_struct *tty,
  958. struct ktermios *old_termios)
  959. {
  960. struct r_port *info = tty->driver_data;
  961. CHANNEL_t *cp;
  962. unsigned cflag;
  963. if (rocket_paranoia_check(info, "rp_set_termios"))
  964. return;
  965. cflag = tty->termios->c_cflag;
  966. /*
  967. * This driver doesn't support CS5 or CS6
  968. */
  969. if (((cflag & CSIZE) == CS5) || ((cflag & CSIZE) == CS6))
  970. tty->termios->c_cflag =
  971. ((cflag & ~CSIZE) | (old_termios->c_cflag & CSIZE));
  972. /* Or CMSPAR */
  973. tty->termios->c_cflag &= ~CMSPAR;
  974. configure_r_port(tty, info, old_termios);
  975. cp = &info->channel;
  976. /* Handle transition to B0 status */
  977. if ((old_termios->c_cflag & CBAUD) && !(tty->termios->c_cflag & CBAUD)) {
  978. sClrDTR(cp);
  979. sClrRTS(cp);
  980. }
  981. /* Handle transition away from B0 status */
  982. if (!(old_termios->c_cflag & CBAUD) && (tty->termios->c_cflag & CBAUD)) {
  983. if (!tty->hw_stopped || !(tty->termios->c_cflag & CRTSCTS))
  984. sSetRTS(cp);
  985. sSetDTR(cp);
  986. }
  987. if ((old_termios->c_cflag & CRTSCTS) && !(tty->termios->c_cflag & CRTSCTS)) {
  988. tty->hw_stopped = 0;
  989. rp_start(tty);
  990. }
  991. }
  992. static int rp_break(struct tty_struct *tty, int break_state)
  993. {
  994. struct r_port *info = tty->driver_data;
  995. unsigned long flags;
  996. if (rocket_paranoia_check(info, "rp_break"))
  997. return -EINVAL;
  998. spin_lock_irqsave(&info->slock, flags);
  999. if (break_state == -1)
  1000. sSendBreak(&info->channel);
  1001. else
  1002. sClrBreak(&info->channel);
  1003. spin_unlock_irqrestore(&info->slock, flags);
  1004. return 0;
  1005. }
  1006. /*
  1007. * sGetChanRI used to be a macro in rocket_int.h. When the functionality for
  1008. * the UPCI boards was added, it was decided to make this a function because
  1009. * the macro was getting too complicated. All cases except the first one
  1010. * (UPCIRingInd) are taken directly from the original macro.
  1011. */
  1012. static int sGetChanRI(CHANNEL_T * ChP)
  1013. {
  1014. CONTROLLER_t *CtlP = ChP->CtlP;
  1015. int ChanNum = ChP->ChanNum;
  1016. int RingInd = 0;
  1017. if (CtlP->UPCIRingInd)
  1018. RingInd = !(sInB(CtlP->UPCIRingInd) & sBitMapSetTbl[ChanNum]);
  1019. else if (CtlP->AltChanRingIndicator)
  1020. RingInd = sInB((ByteIO_t) (ChP->ChanStat + 8)) & DSR_ACT;
  1021. else if (CtlP->boardType == ROCKET_TYPE_PC104)
  1022. RingInd = !(sInB(CtlP->AiopIO[3]) & sBitMapSetTbl[ChanNum]);
  1023. return RingInd;
  1024. }
  1025. /********************************************************************************************/
  1026. /* Here are the routines used by rp_ioctl. These are all called from exception handlers. */
  1027. /*
  1028. * Returns the state of the serial modem control lines. These next 2 functions
  1029. * are the way kernel versions > 2.5 handle modem control lines rather than IOCTLs.
  1030. */
  1031. static int rp_tiocmget(struct tty_struct *tty, struct file *file)
  1032. {
  1033. struct r_port *info = tty->driver_data;
  1034. unsigned int control, result, ChanStatus;
  1035. ChanStatus = sGetChanStatusLo(&info->channel);
  1036. control = info->channel.TxControl[3];
  1037. result = ((control & SET_RTS) ? TIOCM_RTS : 0) |
  1038. ((control & SET_DTR) ? TIOCM_DTR : 0) |
  1039. ((ChanStatus & CD_ACT) ? TIOCM_CAR : 0) |
  1040. (sGetChanRI(&info->channel) ? TIOCM_RNG : 0) |
  1041. ((ChanStatus & DSR_ACT) ? TIOCM_DSR : 0) |
  1042. ((ChanStatus & CTS_ACT) ? TIOCM_CTS : 0);
  1043. return result;
  1044. }
  1045. /*
  1046. * Sets the modem control lines
  1047. */
  1048. static int rp_tiocmset(struct tty_struct *tty, struct file *file,
  1049. unsigned int set, unsigned int clear)
  1050. {
  1051. struct r_port *info = tty->driver_data;
  1052. if (set & TIOCM_RTS)
  1053. info->channel.TxControl[3] |= SET_RTS;
  1054. if (set & TIOCM_DTR)
  1055. info->channel.TxControl[3] |= SET_DTR;
  1056. if (clear & TIOCM_RTS)
  1057. info->channel.TxControl[3] &= ~SET_RTS;
  1058. if (clear & TIOCM_DTR)
  1059. info->channel.TxControl[3] &= ~SET_DTR;
  1060. out32(info->channel.IndexAddr, info->channel.TxControl);
  1061. return 0;
  1062. }
  1063. static int get_config(struct r_port *info, struct rocket_config __user *retinfo)
  1064. {
  1065. struct rocket_config tmp;
  1066. if (!retinfo)
  1067. return -EFAULT;
  1068. memset(&tmp, 0, sizeof (tmp));
  1069. tmp.line = info->line;
  1070. tmp.flags = info->flags;
  1071. tmp.close_delay = info->port.close_delay;
  1072. tmp.closing_wait = info->port.closing_wait;
  1073. tmp.port = rcktpt_io_addr[(info->line >> 5) & 3];
  1074. if (copy_to_user(retinfo, &tmp, sizeof (*retinfo)))
  1075. return -EFAULT;
  1076. return 0;
  1077. }
  1078. static int set_config(struct tty_struct *tty, struct r_port *info,
  1079. struct rocket_config __user *new_info)
  1080. {
  1081. struct rocket_config new_serial;
  1082. if (copy_from_user(&new_serial, new_info, sizeof (new_serial)))
  1083. return -EFAULT;
  1084. if (!capable(CAP_SYS_ADMIN))
  1085. {
  1086. if ((new_serial.flags & ~ROCKET_USR_MASK) != (info->flags & ~ROCKET_USR_MASK))
  1087. return -EPERM;
  1088. info->flags = ((info->flags & ~ROCKET_USR_MASK) | (new_serial.flags & ROCKET_USR_MASK));
  1089. configure_r_port(tty, info, NULL);
  1090. return 0;
  1091. }
  1092. info->flags = ((info->flags & ~ROCKET_FLAGS) | (new_serial.flags & ROCKET_FLAGS));
  1093. info->port.close_delay = new_serial.close_delay;
  1094. info->port.closing_wait = new_serial.closing_wait;
  1095. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI)
  1096. tty->alt_speed = 57600;
  1097. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI)
  1098. tty->alt_speed = 115200;
  1099. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI)
  1100. tty->alt_speed = 230400;
  1101. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP)
  1102. tty->alt_speed = 460800;
  1103. configure_r_port(tty, info, NULL);
  1104. return 0;
  1105. }
  1106. /*
  1107. * This function fills in a rocket_ports struct with information
  1108. * about what boards/ports are in the system. This info is passed
  1109. * to user space. See setrocket.c where the info is used to create
  1110. * the /dev/ttyRx ports.
  1111. */
  1112. static int get_ports(struct r_port *info, struct rocket_ports __user *retports)
  1113. {
  1114. struct rocket_ports tmp;
  1115. int board;
  1116. if (!retports)
  1117. return -EFAULT;
  1118. memset(&tmp, 0, sizeof (tmp));
  1119. tmp.tty_major = rocket_driver->major;
  1120. for (board = 0; board < 4; board++) {
  1121. tmp.rocketModel[board].model = rocketModel[board].model;
  1122. strcpy(tmp.rocketModel[board].modelString, rocketModel[board].modelString);
  1123. tmp.rocketModel[board].numPorts = rocketModel[board].numPorts;
  1124. tmp.rocketModel[board].loadrm2 = rocketModel[board].loadrm2;
  1125. tmp.rocketModel[board].startingPortNumber = rocketModel[board].startingPortNumber;
  1126. }
  1127. if (copy_to_user(retports, &tmp, sizeof (*retports)))
  1128. return -EFAULT;
  1129. return 0;
  1130. }
  1131. static int reset_rm2(struct r_port *info, void __user *arg)
  1132. {
  1133. int reset;
  1134. if (!capable(CAP_SYS_ADMIN))
  1135. return -EPERM;
  1136. if (copy_from_user(&reset, arg, sizeof (int)))
  1137. return -EFAULT;
  1138. if (reset)
  1139. reset = 1;
  1140. if (rcktpt_type[info->board] != ROCKET_TYPE_MODEMII &&
  1141. rcktpt_type[info->board] != ROCKET_TYPE_MODEMIII)
  1142. return -EINVAL;
  1143. if (info->ctlp->BusType == isISA)
  1144. sModemReset(info->ctlp, info->chan, reset);
  1145. else
  1146. sPCIModemReset(info->ctlp, info->chan, reset);
  1147. return 0;
  1148. }
  1149. static int get_version(struct r_port *info, struct rocket_version __user *retvers)
  1150. {
  1151. if (copy_to_user(retvers, &driver_version, sizeof (*retvers)))
  1152. return -EFAULT;
  1153. return 0;
  1154. }
  1155. /* IOCTL call handler into the driver */
  1156. static int rp_ioctl(struct tty_struct *tty, struct file *file,
  1157. unsigned int cmd, unsigned long arg)
  1158. {
  1159. struct r_port *info = tty->driver_data;
  1160. void __user *argp = (void __user *)arg;
  1161. int ret = 0;
  1162. if (cmd != RCKP_GET_PORTS && rocket_paranoia_check(info, "rp_ioctl"))
  1163. return -ENXIO;
  1164. lock_kernel();
  1165. switch (cmd) {
  1166. case RCKP_GET_STRUCT:
  1167. if (copy_to_user(argp, info, sizeof (struct r_port)))
  1168. ret = -EFAULT;
  1169. break;
  1170. case RCKP_GET_CONFIG:
  1171. ret = get_config(info, argp);
  1172. break;
  1173. case RCKP_SET_CONFIG:
  1174. ret = set_config(tty, info, argp);
  1175. break;
  1176. case RCKP_GET_PORTS:
  1177. ret = get_ports(info, argp);
  1178. break;
  1179. case RCKP_RESET_RM2:
  1180. ret = reset_rm2(info, argp);
  1181. break;
  1182. case RCKP_GET_VERSION:
  1183. ret = get_version(info, argp);
  1184. break;
  1185. default:
  1186. ret = -ENOIOCTLCMD;
  1187. }
  1188. unlock_kernel();
  1189. return ret;
  1190. }
  1191. static void rp_send_xchar(struct tty_struct *tty, char ch)
  1192. {
  1193. struct r_port *info = tty->driver_data;
  1194. CHANNEL_t *cp;
  1195. if (rocket_paranoia_check(info, "rp_send_xchar"))
  1196. return;
  1197. cp = &info->channel;
  1198. if (sGetTxCnt(cp))
  1199. sWriteTxPrioByte(cp, ch);
  1200. else
  1201. sWriteTxByte(sGetTxRxDataIO(cp), ch);
  1202. }
  1203. static void rp_throttle(struct tty_struct *tty)
  1204. {
  1205. struct r_port *info = tty->driver_data;
  1206. CHANNEL_t *cp;
  1207. #ifdef ROCKET_DEBUG_THROTTLE
  1208. printk(KERN_INFO "throttle %s: %d....\n", tty->name,
  1209. tty->ldisc.chars_in_buffer(tty));
  1210. #endif
  1211. if (rocket_paranoia_check(info, "rp_throttle"))
  1212. return;
  1213. cp = &info->channel;
  1214. if (I_IXOFF(tty))
  1215. rp_send_xchar(tty, STOP_CHAR(tty));
  1216. sClrRTS(&info->channel);
  1217. }
  1218. static void rp_unthrottle(struct tty_struct *tty)
  1219. {
  1220. struct r_port *info = tty->driver_data;
  1221. CHANNEL_t *cp;
  1222. #ifdef ROCKET_DEBUG_THROTTLE
  1223. printk(KERN_INFO "unthrottle %s: %d....\n", tty->name,
  1224. tty->ldisc.chars_in_buffer(tty));
  1225. #endif
  1226. if (rocket_paranoia_check(info, "rp_throttle"))
  1227. return;
  1228. cp = &info->channel;
  1229. if (I_IXOFF(tty))
  1230. rp_send_xchar(tty, START_CHAR(tty));
  1231. sSetRTS(&info->channel);
  1232. }
  1233. /*
  1234. * ------------------------------------------------------------
  1235. * rp_stop() and rp_start()
  1236. *
  1237. * This routines are called before setting or resetting tty->stopped.
  1238. * They enable or disable transmitter interrupts, as necessary.
  1239. * ------------------------------------------------------------
  1240. */
  1241. static void rp_stop(struct tty_struct *tty)
  1242. {
  1243. struct r_port *info = tty->driver_data;
  1244. #ifdef ROCKET_DEBUG_FLOW
  1245. printk(KERN_INFO "stop %s: %d %d....\n", tty->name,
  1246. info->xmit_cnt, info->xmit_fifo_room);
  1247. #endif
  1248. if (rocket_paranoia_check(info, "rp_stop"))
  1249. return;
  1250. if (sGetTxCnt(&info->channel))
  1251. sDisTransmit(&info->channel);
  1252. }
  1253. static void rp_start(struct tty_struct *tty)
  1254. {
  1255. struct r_port *info = tty->driver_data;
  1256. #ifdef ROCKET_DEBUG_FLOW
  1257. printk(KERN_INFO "start %s: %d %d....\n", tty->name,
  1258. info->xmit_cnt, info->xmit_fifo_room);
  1259. #endif
  1260. if (rocket_paranoia_check(info, "rp_stop"))
  1261. return;
  1262. sEnTransmit(&info->channel);
  1263. set_bit((info->aiop * 8) + info->chan,
  1264. (void *) &xmit_flags[info->board]);
  1265. }
  1266. /*
  1267. * rp_wait_until_sent() --- wait until the transmitter is empty
  1268. */
  1269. static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
  1270. {
  1271. struct r_port *info = tty->driver_data;
  1272. CHANNEL_t *cp;
  1273. unsigned long orig_jiffies;
  1274. int check_time, exit_time;
  1275. int txcnt;
  1276. if (rocket_paranoia_check(info, "rp_wait_until_sent"))
  1277. return;
  1278. cp = &info->channel;
  1279. orig_jiffies = jiffies;
  1280. #ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT
  1281. printk(KERN_INFO "In RP_wait_until_sent(%d) (jiff=%lu)...\n", timeout,
  1282. jiffies);
  1283. printk(KERN_INFO "cps=%d...\n", info->cps);
  1284. #endif
  1285. lock_kernel();
  1286. while (1) {
  1287. txcnt = sGetTxCnt(cp);
  1288. if (!txcnt) {
  1289. if (sGetChanStatusLo(cp) & TXSHRMT)
  1290. break;
  1291. check_time = (HZ / info->cps) / 5;
  1292. } else {
  1293. check_time = HZ * txcnt / info->cps;
  1294. }
  1295. if (timeout) {
  1296. exit_time = orig_jiffies + timeout - jiffies;
  1297. if (exit_time <= 0)
  1298. break;
  1299. if (exit_time < check_time)
  1300. check_time = exit_time;
  1301. }
  1302. if (check_time == 0)
  1303. check_time = 1;
  1304. #ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT
  1305. printk(KERN_INFO "txcnt = %d (jiff=%lu,check=%d)...\n", txcnt,
  1306. jiffies, check_time);
  1307. #endif
  1308. msleep_interruptible(jiffies_to_msecs(check_time));
  1309. if (signal_pending(current))
  1310. break;
  1311. }
  1312. __set_current_state(TASK_RUNNING);
  1313. unlock_kernel();
  1314. #ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT
  1315. printk(KERN_INFO "txcnt = %d (jiff=%lu)...done\n", txcnt, jiffies);
  1316. #endif
  1317. }
  1318. /*
  1319. * rp_hangup() --- called by tty_hangup() when a hangup is signaled.
  1320. */
  1321. static void rp_hangup(struct tty_struct *tty)
  1322. {
  1323. CHANNEL_t *cp;
  1324. struct r_port *info = tty->driver_data;
  1325. if (rocket_paranoia_check(info, "rp_hangup"))
  1326. return;
  1327. #if (defined(ROCKET_DEBUG_OPEN) || defined(ROCKET_DEBUG_HANGUP))
  1328. printk(KERN_INFO "rp_hangup of ttyR%d...\n", info->line);
  1329. #endif
  1330. rp_flush_buffer(tty);
  1331. if (info->port.flags & ASYNC_CLOSING)
  1332. return;
  1333. if (info->port.count)
  1334. atomic_dec(&rp_num_ports_open);
  1335. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  1336. tty_port_hangup(&info->port);
  1337. cp = &info->channel;
  1338. sDisRxFIFO(cp);
  1339. sDisTransmit(cp);
  1340. sDisInterrupts(cp, (TXINT_EN | MCINT_EN | RXINT_EN | SRCINT_EN | CHANINT_EN));
  1341. sDisCTSFlowCtl(cp);
  1342. sDisTxSoftFlowCtl(cp);
  1343. sClrTxXOFF(cp);
  1344. info->port.flags &= ~ASYNC_INITIALIZED;
  1345. wake_up_interruptible(&info->port.open_wait);
  1346. }
  1347. /*
  1348. * Exception handler - write char routine. The RocketPort driver uses a
  1349. * double-buffering strategy, with the twist that if the in-memory CPU
  1350. * buffer is empty, and there's space in the transmit FIFO, the
  1351. * writing routines will write directly to transmit FIFO.
  1352. * Write buffer and counters protected by spinlocks
  1353. */
  1354. static int rp_put_char(struct tty_struct *tty, unsigned char ch)
  1355. {
  1356. struct r_port *info = tty->driver_data;
  1357. CHANNEL_t *cp;
  1358. unsigned long flags;
  1359. if (rocket_paranoia_check(info, "rp_put_char"))
  1360. return 0;
  1361. /*
  1362. * Grab the port write mutex, locking out other processes that try to
  1363. * write to this port
  1364. */
  1365. mutex_lock(&info->write_mtx);
  1366. #ifdef ROCKET_DEBUG_WRITE
  1367. printk(KERN_INFO "rp_put_char %c...\n", ch);
  1368. #endif
  1369. spin_lock_irqsave(&info->slock, flags);
  1370. cp = &info->channel;
  1371. if (!tty->stopped && !tty->hw_stopped && info->xmit_fifo_room == 0)
  1372. info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp);
  1373. if (tty->stopped || tty->hw_stopped || info->xmit_fifo_room == 0 || info->xmit_cnt != 0) {
  1374. info->xmit_buf[info->xmit_head++] = ch;
  1375. info->xmit_head &= XMIT_BUF_SIZE - 1;
  1376. info->xmit_cnt++;
  1377. set_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  1378. } else {
  1379. sOutB(sGetTxRxDataIO(cp), ch);
  1380. info->xmit_fifo_room--;
  1381. }
  1382. spin_unlock_irqrestore(&info->slock, flags);
  1383. mutex_unlock(&info->write_mtx);
  1384. return 1;
  1385. }
  1386. /*
  1387. * Exception handler - write routine, called when user app writes to the device.
  1388. * A per port write mutex is used to protect from another process writing to
  1389. * this port at the same time. This other process could be running on the other CPU
  1390. * or get control of the CPU if the copy_from_user() blocks due to a page fault (swapped out).
  1391. * Spinlocks protect the info xmit members.
  1392. */
  1393. static int rp_write(struct tty_struct *tty,
  1394. const unsigned char *buf, int count)
  1395. {
  1396. struct r_port *info = tty->driver_data;
  1397. CHANNEL_t *cp;
  1398. const unsigned char *b;
  1399. int c, retval = 0;
  1400. unsigned long flags;
  1401. if (count <= 0 || rocket_paranoia_check(info, "rp_write"))
  1402. return 0;
  1403. if (mutex_lock_interruptible(&info->write_mtx))
  1404. return -ERESTARTSYS;
  1405. #ifdef ROCKET_DEBUG_WRITE
  1406. printk(KERN_INFO "rp_write %d chars...\n", count);
  1407. #endif
  1408. cp = &info->channel;
  1409. if (!tty->stopped && !tty->hw_stopped && info->xmit_fifo_room < count)
  1410. info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp);
  1411. /*
  1412. * If the write queue for the port is empty, and there is FIFO space, stuff bytes
  1413. * into FIFO. Use the write queue for temp storage.
  1414. */
  1415. if (!tty->stopped && !tty->hw_stopped && info->xmit_cnt == 0 && info->xmit_fifo_room > 0) {
  1416. c = min(count, info->xmit_fifo_room);
  1417. b = buf;
  1418. /* Push data into FIFO, 2 bytes at a time */
  1419. sOutStrW(sGetTxRxDataIO(cp), (unsigned short *) b, c / 2);
  1420. /* If there is a byte remaining, write it */
  1421. if (c & 1)
  1422. sOutB(sGetTxRxDataIO(cp), b[c - 1]);
  1423. retval += c;
  1424. buf += c;
  1425. count -= c;
  1426. spin_lock_irqsave(&info->slock, flags);
  1427. info->xmit_fifo_room -= c;
  1428. spin_unlock_irqrestore(&info->slock, flags);
  1429. }
  1430. /* If count is zero, we wrote it all and are done */
  1431. if (!count)
  1432. goto end;
  1433. /* Write remaining data into the port's xmit_buf */
  1434. while (1) {
  1435. /* Hung up ? */
  1436. if (!test_bit(ASYNCB_NORMAL_ACTIVE, &info->port.flags))
  1437. goto end;
  1438. c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1);
  1439. c = min(c, XMIT_BUF_SIZE - info->xmit_head);
  1440. if (c <= 0)
  1441. break;
  1442. b = buf;
  1443. memcpy(info->xmit_buf + info->xmit_head, b, c);
  1444. spin_lock_irqsave(&info->slock, flags);
  1445. info->xmit_head =
  1446. (info->xmit_head + c) & (XMIT_BUF_SIZE - 1);
  1447. info->xmit_cnt += c;
  1448. spin_unlock_irqrestore(&info->slock, flags);
  1449. buf += c;
  1450. count -= c;
  1451. retval += c;
  1452. }
  1453. if ((retval > 0) && !tty->stopped && !tty->hw_stopped)
  1454. set_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  1455. end:
  1456. if (info->xmit_cnt < WAKEUP_CHARS) {
  1457. tty_wakeup(tty);
  1458. #ifdef ROCKETPORT_HAVE_POLL_WAIT
  1459. wake_up_interruptible(&tty->poll_wait);
  1460. #endif
  1461. }
  1462. mutex_unlock(&info->write_mtx);
  1463. return retval;
  1464. }
  1465. /*
  1466. * Return the number of characters that can be sent. We estimate
  1467. * only using the in-memory transmit buffer only, and ignore the
  1468. * potential space in the transmit FIFO.
  1469. */
  1470. static int rp_write_room(struct tty_struct *tty)
  1471. {
  1472. struct r_port *info = tty->driver_data;
  1473. int ret;
  1474. if (rocket_paranoia_check(info, "rp_write_room"))
  1475. return 0;
  1476. ret = XMIT_BUF_SIZE - info->xmit_cnt - 1;
  1477. if (ret < 0)
  1478. ret = 0;
  1479. #ifdef ROCKET_DEBUG_WRITE
  1480. printk(KERN_INFO "rp_write_room returns %d...\n", ret);
  1481. #endif
  1482. return ret;
  1483. }
  1484. /*
  1485. * Return the number of characters in the buffer. Again, this only
  1486. * counts those characters in the in-memory transmit buffer.
  1487. */
  1488. static int rp_chars_in_buffer(struct tty_struct *tty)
  1489. {
  1490. struct r_port *info = tty->driver_data;
  1491. CHANNEL_t *cp;
  1492. if (rocket_paranoia_check(info, "rp_chars_in_buffer"))
  1493. return 0;
  1494. cp = &info->channel;
  1495. #ifdef ROCKET_DEBUG_WRITE
  1496. printk(KERN_INFO "rp_chars_in_buffer returns %d...\n", info->xmit_cnt);
  1497. #endif
  1498. return info->xmit_cnt;
  1499. }
  1500. /*
  1501. * Flushes the TX fifo for a port, deletes data in the xmit_buf stored in the
  1502. * r_port struct for the port. Note that spinlock are used to protect info members,
  1503. * do not call this function if the spinlock is already held.
  1504. */
  1505. static void rp_flush_buffer(struct tty_struct *tty)
  1506. {
  1507. struct r_port *info = tty->driver_data;
  1508. CHANNEL_t *cp;
  1509. unsigned long flags;
  1510. if (rocket_paranoia_check(info, "rp_flush_buffer"))
  1511. return;
  1512. spin_lock_irqsave(&info->slock, flags);
  1513. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  1514. spin_unlock_irqrestore(&info->slock, flags);
  1515. #ifdef ROCKETPORT_HAVE_POLL_WAIT
  1516. wake_up_interruptible(&tty->poll_wait);
  1517. #endif
  1518. tty_wakeup(tty);
  1519. cp = &info->channel;
  1520. sFlushTxFIFO(cp);
  1521. }
  1522. #ifdef CONFIG_PCI
  1523. static struct pci_device_id __devinitdata rocket_pci_ids[] = {
  1524. { PCI_DEVICE(PCI_VENDOR_ID_RP, PCI_ANY_ID) },
  1525. { }
  1526. };
  1527. MODULE_DEVICE_TABLE(pci, rocket_pci_ids);
  1528. /*
  1529. * Called when a PCI card is found. Retrieves and stores model information,
  1530. * init's aiopic and serial port hardware.
  1531. * Inputs: i is the board number (0-n)
  1532. */
  1533. static __init int register_PCI(int i, struct pci_dev *dev)
  1534. {
  1535. int num_aiops, aiop, max_num_aiops, num_chan, chan;
  1536. unsigned int aiopio[MAX_AIOPS_PER_BOARD];
  1537. char *str, *board_type;
  1538. CONTROLLER_t *ctlp;
  1539. int fast_clock = 0;
  1540. int altChanRingIndicator = 0;
  1541. int ports_per_aiop = 8;
  1542. WordIO_t ConfigIO = 0;
  1543. ByteIO_t UPCIRingInd = 0;
  1544. if (!dev || pci_enable_device(dev))
  1545. return 0;
  1546. rcktpt_io_addr[i] = pci_resource_start(dev, 0);
  1547. rcktpt_type[i] = ROCKET_TYPE_NORMAL;
  1548. rocketModel[i].loadrm2 = 0;
  1549. rocketModel[i].startingPortNumber = nextLineNumber;
  1550. /* Depending on the model, set up some config variables */
  1551. switch (dev->device) {
  1552. case PCI_DEVICE_ID_RP4QUAD:
  1553. str = "Quadcable";
  1554. max_num_aiops = 1;
  1555. ports_per_aiop = 4;
  1556. rocketModel[i].model = MODEL_RP4QUAD;
  1557. strcpy(rocketModel[i].modelString, "RocketPort 4 port w/quad cable");
  1558. rocketModel[i].numPorts = 4;
  1559. break;
  1560. case PCI_DEVICE_ID_RP8OCTA:
  1561. str = "Octacable";
  1562. max_num_aiops = 1;
  1563. rocketModel[i].model = MODEL_RP8OCTA;
  1564. strcpy(rocketModel[i].modelString, "RocketPort 8 port w/octa cable");
  1565. rocketModel[i].numPorts = 8;
  1566. break;
  1567. case PCI_DEVICE_ID_URP8OCTA:
  1568. str = "Octacable";
  1569. max_num_aiops = 1;
  1570. rocketModel[i].model = MODEL_UPCI_RP8OCTA;
  1571. strcpy(rocketModel[i].modelString, "RocketPort UPCI 8 port w/octa cable");
  1572. rocketModel[i].numPorts = 8;
  1573. break;
  1574. case PCI_DEVICE_ID_RP8INTF:
  1575. str = "8";
  1576. max_num_aiops = 1;
  1577. rocketModel[i].model = MODEL_RP8INTF;
  1578. strcpy(rocketModel[i].modelString, "RocketPort 8 port w/external I/F");
  1579. rocketModel[i].numPorts = 8;
  1580. break;
  1581. case PCI_DEVICE_ID_URP8INTF:
  1582. str = "8";
  1583. max_num_aiops = 1;
  1584. rocketModel[i].model = MODEL_UPCI_RP8INTF;
  1585. strcpy(rocketModel[i].modelString, "RocketPort UPCI 8 port w/external I/F");
  1586. rocketModel[i].numPorts = 8;
  1587. break;
  1588. case PCI_DEVICE_ID_RP8J:
  1589. str = "8J";
  1590. max_num_aiops = 1;
  1591. rocketModel[i].model = MODEL_RP8J;
  1592. strcpy(rocketModel[i].modelString, "RocketPort 8 port w/RJ11 connectors");
  1593. rocketModel[i].numPorts = 8;
  1594. break;
  1595. case PCI_DEVICE_ID_RP4J:
  1596. str = "4J";
  1597. max_num_aiops = 1;
  1598. ports_per_aiop = 4;
  1599. rocketModel[i].model = MODEL_RP4J;
  1600. strcpy(rocketModel[i].modelString, "RocketPort 4 port w/RJ45 connectors");
  1601. rocketModel[i].numPorts = 4;
  1602. break;
  1603. case PCI_DEVICE_ID_RP8SNI:
  1604. str = "8 (DB78 Custom)";
  1605. max_num_aiops = 1;
  1606. rocketModel[i].model = MODEL_RP8SNI;
  1607. strcpy(rocketModel[i].modelString, "RocketPort 8 port w/ custom DB78");
  1608. rocketModel[i].numPorts = 8;
  1609. break;
  1610. case PCI_DEVICE_ID_RP16SNI:
  1611. str = "16 (DB78 Custom)";
  1612. max_num_aiops = 2;
  1613. rocketModel[i].model = MODEL_RP16SNI;
  1614. strcpy(rocketModel[i].modelString, "RocketPort 16 port w/ custom DB78");
  1615. rocketModel[i].numPorts = 16;
  1616. break;
  1617. case PCI_DEVICE_ID_RP16INTF:
  1618. str = "16";
  1619. max_num_aiops = 2;
  1620. rocketModel[i].model = MODEL_RP16INTF;
  1621. strcpy(rocketModel[i].modelString, "RocketPort 16 port w/external I/F");
  1622. rocketModel[i].numPorts = 16;
  1623. break;
  1624. case PCI_DEVICE_ID_URP16INTF:
  1625. str = "16";
  1626. max_num_aiops = 2;
  1627. rocketModel[i].model = MODEL_UPCI_RP16INTF;
  1628. strcpy(rocketModel[i].modelString, "RocketPort UPCI 16 port w/external I/F");
  1629. rocketModel[i].numPorts = 16;
  1630. break;
  1631. case PCI_DEVICE_ID_CRP16INTF:
  1632. str = "16";
  1633. max_num_aiops = 2;
  1634. rocketModel[i].model = MODEL_CPCI_RP16INTF;
  1635. strcpy(rocketModel[i].modelString, "RocketPort Compact PCI 16 port w/external I/F");
  1636. rocketModel[i].numPorts = 16;
  1637. break;
  1638. case PCI_DEVICE_ID_RP32INTF:
  1639. str = "32";
  1640. max_num_aiops = 4;
  1641. rocketModel[i].model = MODEL_RP32INTF;
  1642. strcpy(rocketModel[i].modelString, "RocketPort 32 port w/external I/F");
  1643. rocketModel[i].numPorts = 32;
  1644. break;
  1645. case PCI_DEVICE_ID_URP32INTF:
  1646. str = "32";
  1647. max_num_aiops = 4;
  1648. rocketModel[i].model = MODEL_UPCI_RP32INTF;
  1649. strcpy(rocketModel[i].modelString, "RocketPort UPCI 32 port w/external I/F");
  1650. rocketModel[i].numPorts = 32;
  1651. break;
  1652. case PCI_DEVICE_ID_RPP4:
  1653. str = "Plus Quadcable";
  1654. max_num_aiops = 1;
  1655. ports_per_aiop = 4;
  1656. altChanRingIndicator++;
  1657. fast_clock++;
  1658. rocketModel[i].model = MODEL_RPP4;
  1659. strcpy(rocketModel[i].modelString, "RocketPort Plus 4 port");
  1660. rocketModel[i].numPorts = 4;
  1661. break;
  1662. case PCI_DEVICE_ID_RPP8:
  1663. str = "Plus Octacable";
  1664. max_num_aiops = 2;
  1665. ports_per_aiop = 4;
  1666. altChanRingIndicator++;
  1667. fast_clock++;
  1668. rocketModel[i].model = MODEL_RPP8;
  1669. strcpy(rocketModel[i].modelString, "RocketPort Plus 8 port");
  1670. rocketModel[i].numPorts = 8;
  1671. break;
  1672. case PCI_DEVICE_ID_RP2_232:
  1673. str = "Plus 2 (RS-232)";
  1674. max_num_aiops = 1;
  1675. ports_per_aiop = 2;
  1676. altChanRingIndicator++;
  1677. fast_clock++;
  1678. rocketModel[i].model = MODEL_RP2_232;
  1679. strcpy(rocketModel[i].modelString, "RocketPort Plus 2 port RS232");
  1680. rocketModel[i].numPorts = 2;
  1681. break;
  1682. case PCI_DEVICE_ID_RP2_422:
  1683. str = "Plus 2 (RS-422)";
  1684. max_num_aiops = 1;
  1685. ports_per_aiop = 2;
  1686. altChanRingIndicator++;
  1687. fast_clock++;
  1688. rocketModel[i].model = MODEL_RP2_422;
  1689. strcpy(rocketModel[i].modelString, "RocketPort Plus 2 port RS422");
  1690. rocketModel[i].numPorts = 2;
  1691. break;
  1692. case PCI_DEVICE_ID_RP6M:
  1693. max_num_aiops = 1;
  1694. ports_per_aiop = 6;
  1695. str = "6-port";
  1696. /* If revision is 1, the rocketmodem flash must be loaded.
  1697. * If it is 2 it is a "socketed" version. */
  1698. if (dev->revision == 1) {
  1699. rcktpt_type[i] = ROCKET_TYPE_MODEMII;
  1700. rocketModel[i].loadrm2 = 1;
  1701. } else {
  1702. rcktpt_type[i] = ROCKET_TYPE_MODEM;
  1703. }
  1704. rocketModel[i].model = MODEL_RP6M;
  1705. strcpy(rocketModel[i].modelString, "RocketModem 6 port");
  1706. rocketModel[i].numPorts = 6;
  1707. break;
  1708. case PCI_DEVICE_ID_RP4M:
  1709. max_num_aiops = 1;
  1710. ports_per_aiop = 4;
  1711. str = "4-port";
  1712. if (dev->revision == 1) {
  1713. rcktpt_type[i] = ROCKET_TYPE_MODEMII;
  1714. rocketModel[i].loadrm2 = 1;
  1715. } else {
  1716. rcktpt_type[i] = ROCKET_TYPE_MODEM;
  1717. }
  1718. rocketModel[i].model = MODEL_RP4M;
  1719. strcpy(rocketModel[i].modelString, "RocketModem 4 port");
  1720. rocketModel[i].numPorts = 4;
  1721. break;
  1722. default:
  1723. str = "(unknown/unsupported)";
  1724. max_num_aiops = 0;
  1725. break;
  1726. }
  1727. /*
  1728. * Check for UPCI boards.
  1729. */
  1730. switch (dev->device) {
  1731. case PCI_DEVICE_ID_URP32INTF:
  1732. case PCI_DEVICE_ID_URP8INTF:
  1733. case PCI_DEVICE_ID_URP16INTF:
  1734. case PCI_DEVICE_ID_CRP16INTF:
  1735. case PCI_DEVICE_ID_URP8OCTA:
  1736. rcktpt_io_addr[i] = pci_resource_start(dev, 2);
  1737. ConfigIO = pci_resource_start(dev, 1);
  1738. if (dev->device == PCI_DEVICE_ID_URP8OCTA) {
  1739. UPCIRingInd = rcktpt_io_addr[i] + _PCI_9030_RING_IND;
  1740. /*
  1741. * Check for octa or quad cable.
  1742. */
  1743. if (!
  1744. (sInW(ConfigIO + _PCI_9030_GPIO_CTRL) &
  1745. PCI_GPIO_CTRL_8PORT)) {
  1746. str = "Quadcable";
  1747. ports_per_aiop = 4;
  1748. rocketModel[i].numPorts = 4;
  1749. }
  1750. }
  1751. break;
  1752. case PCI_DEVICE_ID_UPCI_RM3_8PORT:
  1753. str = "8 ports";
  1754. max_num_aiops = 1;
  1755. rocketModel[i].model = MODEL_UPCI_RM3_8PORT;
  1756. strcpy(rocketModel[i].modelString, "RocketModem III 8 port");
  1757. rocketModel[i].numPorts = 8;
  1758. rcktpt_io_addr[i] = pci_resource_start(dev, 2);
  1759. UPCIRingInd = rcktpt_io_addr[i] + _PCI_9030_RING_IND;
  1760. ConfigIO = pci_resource_start(dev, 1);
  1761. rcktpt_type[i] = ROCKET_TYPE_MODEMIII;
  1762. break;
  1763. case PCI_DEVICE_ID_UPCI_RM3_4PORT:
  1764. str = "4 ports";
  1765. max_num_aiops = 1;
  1766. rocketModel[i].model = MODEL_UPCI_RM3_4PORT;
  1767. strcpy(rocketModel[i].modelString, "RocketModem III 4 port");
  1768. rocketModel[i].numPorts = 4;
  1769. rcktpt_io_addr[i] = pci_resource_start(dev, 2);
  1770. UPCIRingInd = rcktpt_io_addr[i] + _PCI_9030_RING_IND;
  1771. ConfigIO = pci_resource_start(dev, 1);
  1772. rcktpt_type[i] = ROCKET_TYPE_MODEMIII;
  1773. break;
  1774. default:
  1775. break;
  1776. }
  1777. switch (rcktpt_type[i]) {
  1778. case ROCKET_TYPE_MODEM:
  1779. board_type = "RocketModem";
  1780. break;
  1781. case ROCKET_TYPE_MODEMII:
  1782. board_type = "RocketModem II";
  1783. break;
  1784. case ROCKET_TYPE_MODEMIII:
  1785. board_type = "RocketModem III";
  1786. break;
  1787. default:
  1788. board_type = "RocketPort";
  1789. break;
  1790. }
  1791. if (fast_clock) {
  1792. sClockPrescale = 0x12; /* mod 2 (divide by 3) */
  1793. rp_baud_base[i] = 921600;
  1794. } else {
  1795. /*
  1796. * If support_low_speed is set, use the slow clock
  1797. * prescale, which supports 50 bps
  1798. */
  1799. if (support_low_speed) {
  1800. /* mod 9 (divide by 10) prescale */
  1801. sClockPrescale = 0x19;
  1802. rp_baud_base[i] = 230400;
  1803. } else {
  1804. /* mod 4 (devide by 5) prescale */
  1805. sClockPrescale = 0x14;
  1806. rp_baud_base[i] = 460800;
  1807. }
  1808. }
  1809. for (aiop = 0; aiop < max_num_aiops; aiop++)
  1810. aiopio[aiop] = rcktpt_io_addr[i] + (aiop * 0x40);
  1811. ctlp = sCtlNumToCtlPtr(i);
  1812. num_aiops = sPCIInitController(ctlp, i, aiopio, max_num_aiops, ConfigIO, 0, FREQ_DIS, 0, altChanRingIndicator, UPCIRingInd);
  1813. for (aiop = 0; aiop < max_num_aiops; aiop++)
  1814. ctlp->AiopNumChan[aiop] = ports_per_aiop;
  1815. dev_info(&dev->dev, "comtrol PCI controller #%d found at "
  1816. "address %04lx, %d AIOP(s) (%s), creating ttyR%d - %ld\n",
  1817. i, rcktpt_io_addr[i], num_aiops, rocketModel[i].modelString,
  1818. rocketModel[i].startingPortNumber,
  1819. rocketModel[i].startingPortNumber + rocketModel[i].numPorts-1);
  1820. if (num_aiops <= 0) {
  1821. rcktpt_io_addr[i] = 0;
  1822. return (0);
  1823. }
  1824. is_PCI[i] = 1;
  1825. /* Reset the AIOPIC, init the serial ports */
  1826. for (aiop = 0; aiop < num_aiops; aiop++) {
  1827. sResetAiopByNum(ctlp, aiop);
  1828. num_chan = ports_per_aiop;
  1829. for (chan = 0; chan < num_chan; chan++)
  1830. init_r_port(i, aiop, chan, dev);
  1831. }
  1832. /* Rocket modems must be reset */
  1833. if ((rcktpt_type[i] == ROCKET_TYPE_MODEM) ||
  1834. (rcktpt_type[i] == ROCKET_TYPE_MODEMII) ||
  1835. (rcktpt_type[i] == ROCKET_TYPE_MODEMIII)) {
  1836. num_chan = ports_per_aiop;
  1837. for (chan = 0; chan < num_chan; chan++)
  1838. sPCIModemReset(ctlp, chan, 1);
  1839. msleep(500);
  1840. for (chan = 0; chan < num_chan; chan++)
  1841. sPCIModemReset(ctlp, chan, 0);
  1842. msleep(500);
  1843. rmSpeakerReset(ctlp, rocketModel[i].model);
  1844. }
  1845. return (1);
  1846. }
  1847. /*
  1848. * Probes for PCI cards, inits them if found
  1849. * Input: board_found = number of ISA boards already found, or the
  1850. * starting board number
  1851. * Returns: Number of PCI boards found
  1852. */
  1853. static int __init init_PCI(int boards_found)
  1854. {
  1855. struct pci_dev *dev = NULL;
  1856. int count = 0;
  1857. /* Work through the PCI device list, pulling out ours */
  1858. while ((dev = pci_get_device(PCI_VENDOR_ID_RP, PCI_ANY_ID, dev))) {
  1859. if (register_PCI(count + boards_found, dev))
  1860. count++;
  1861. }
  1862. return (count);
  1863. }
  1864. #endif /* CONFIG_PCI */
  1865. /*
  1866. * Probes for ISA cards
  1867. * Input: i = the board number to look for
  1868. * Returns: 1 if board found, 0 else
  1869. */
  1870. static int __init init_ISA(int i)
  1871. {
  1872. int num_aiops, num_chan = 0, total_num_chan = 0;
  1873. int aiop, chan;
  1874. unsigned int aiopio[MAX_AIOPS_PER_BOARD];
  1875. CONTROLLER_t *ctlp;
  1876. char *type_string;
  1877. /* If io_addr is zero, no board configured */
  1878. if (rcktpt_io_addr[i] == 0)
  1879. return (0);
  1880. /* Reserve the IO region */
  1881. if (!request_region(rcktpt_io_addr[i], 64, "Comtrol RocketPort")) {
  1882. printk(KERN_ERR "Unable to reserve IO region for configured "
  1883. "ISA RocketPort at address 0x%lx, board not "
  1884. "installed...\n", rcktpt_io_addr[i]);
  1885. rcktpt_io_addr[i] = 0;
  1886. return (0);
  1887. }
  1888. ctlp = sCtlNumToCtlPtr(i);
  1889. ctlp->boardType = rcktpt_type[i];
  1890. switch (rcktpt_type[i]) {
  1891. case ROCKET_TYPE_PC104:
  1892. type_string = "(PC104)";
  1893. break;
  1894. case ROCKET_TYPE_MODEM:
  1895. type_string = "(RocketModem)";
  1896. break;
  1897. case ROCKET_TYPE_MODEMII:
  1898. type_string = "(RocketModem II)";
  1899. break;
  1900. default:
  1901. type_string = "";
  1902. break;
  1903. }
  1904. /*
  1905. * If support_low_speed is set, use the slow clock prescale,
  1906. * which supports 50 bps
  1907. */
  1908. if (support_low_speed) {
  1909. sClockPrescale = 0x19; /* mod 9 (divide by 10) prescale */
  1910. rp_baud_base[i] = 230400;
  1911. } else {
  1912. sClockPrescale = 0x14; /* mod 4 (devide by 5) prescale */
  1913. rp_baud_base[i] = 460800;
  1914. }
  1915. for (aiop = 0; aiop < MAX_AIOPS_PER_BOARD; aiop++)
  1916. aiopio[aiop] = rcktpt_io_addr[i] + (aiop * 0x400);
  1917. num_aiops = sInitController(ctlp, i, controller + (i * 0x400), aiopio, MAX_AIOPS_PER_BOARD, 0, FREQ_DIS, 0);
  1918. if (ctlp->boardType == ROCKET_TYPE_PC104) {
  1919. sEnAiop(ctlp, 2); /* only one AIOPIC, but these */
  1920. sEnAiop(ctlp, 3); /* CSels used for other stuff */
  1921. }
  1922. /* If something went wrong initing the AIOP's release the ISA IO memory */
  1923. if (num_aiops <= 0) {
  1924. release_region(rcktpt_io_addr[i], 64);
  1925. rcktpt_io_addr[i] = 0;
  1926. return (0);
  1927. }
  1928. rocketModel[i].startingPortNumber = nextLineNumber;
  1929. for (aiop = 0; aiop < num_aiops; aiop++) {
  1930. sResetAiopByNum(ctlp, aiop);
  1931. sEnAiop(ctlp, aiop);
  1932. num_chan = sGetAiopNumChan(ctlp, aiop);
  1933. total_num_chan += num_chan;
  1934. for (chan = 0; chan < num_chan; chan++)
  1935. init_r_port(i, aiop, chan, NULL);
  1936. }
  1937. is_PCI[i] = 0;
  1938. if ((rcktpt_type[i] == ROCKET_TYPE_MODEM) || (rcktpt_type[i] == ROCKET_TYPE_MODEMII)) {
  1939. num_chan = sGetAiopNumChan(ctlp, 0);
  1940. total_num_chan = num_chan;
  1941. for (chan = 0; chan < num_chan; chan++)
  1942. sModemReset(ctlp, chan, 1);
  1943. msleep(500);
  1944. for (chan = 0; chan < num_chan; chan++)
  1945. sModemReset(ctlp, chan, 0);
  1946. msleep(500);
  1947. strcpy(rocketModel[i].modelString, "RocketModem ISA");
  1948. } else {
  1949. strcpy(rocketModel[i].modelString, "RocketPort ISA");
  1950. }
  1951. rocketModel[i].numPorts = total_num_chan;
  1952. rocketModel[i].model = MODEL_ISA;
  1953. printk(KERN_INFO "RocketPort ISA card #%d found at 0x%lx - %d AIOPs %s\n",
  1954. i, rcktpt_io_addr[i], num_aiops, type_string);
  1955. printk(KERN_INFO "Installing %s, creating /dev/ttyR%d - %ld\n",
  1956. rocketModel[i].modelString,
  1957. rocketModel[i].startingPortNumber,
  1958. rocketModel[i].startingPortNumber +
  1959. rocketModel[i].numPorts - 1);
  1960. return (1);
  1961. }
  1962. static const struct tty_operations rocket_ops = {
  1963. .open = rp_open,
  1964. .close = rp_close,
  1965. .write = rp_write,
  1966. .put_char = rp_put_char,
  1967. .write_room = rp_write_room,
  1968. .chars_in_buffer = rp_chars_in_buffer,
  1969. .flush_buffer = rp_flush_buffer,
  1970. .ioctl = rp_ioctl,
  1971. .throttle = rp_throttle,
  1972. .unthrottle = rp_unthrottle,
  1973. .set_termios = rp_set_termios,
  1974. .stop = rp_stop,
  1975. .start = rp_start,
  1976. .hangup = rp_hangup,
  1977. .break_ctl = rp_break,
  1978. .send_xchar = rp_send_xchar,
  1979. .wait_until_sent = rp_wait_until_sent,
  1980. .tiocmget = rp_tiocmget,
  1981. .tiocmset = rp_tiocmset,
  1982. };
  1983. static const struct tty_port_operations rocket_port_ops = {
  1984. .carrier_raised = carrier_raised,
  1985. .dtr_rts = dtr_rts,
  1986. };
  1987. /*
  1988. * The module "startup" routine; it's run when the module is loaded.
  1989. */
  1990. static int __init rp_init(void)
  1991. {
  1992. int ret = -ENOMEM, pci_boards_found, isa_boards_found, i;
  1993. printk(KERN_INFO "RocketPort device driver module, version %s, %s\n",
  1994. ROCKET_VERSION, ROCKET_DATE);
  1995. rocket_driver = alloc_tty_driver(MAX_RP_PORTS);
  1996. if (!rocket_driver)
  1997. goto err;
  1998. /*
  1999. * If board 1 is non-zero, there is at least one ISA configured. If controller is
  2000. * zero, use the default controller IO address of board1 + 0x40.
  2001. */
  2002. if (board1) {
  2003. if (controller == 0)
  2004. controller = board1 + 0x40;
  2005. } else {
  2006. controller = 0; /* Used as a flag, meaning no ISA boards */
  2007. }
  2008. /* If an ISA card is configured, reserve the 4 byte IO space for the Mudbac controller */
  2009. if (controller && (!request_region(controller, 4, "Comtrol RocketPort"))) {
  2010. printk(KERN_ERR "Unable to reserve IO region for first "
  2011. "configured ISA RocketPort controller 0x%lx. "
  2012. "Driver exiting\n", controller);
  2013. ret = -EBUSY;
  2014. goto err_tty;
  2015. }
  2016. /* Store ISA variable retrieved from command line or .conf file. */
  2017. rcktpt_io_addr[0] = board1;
  2018. rcktpt_io_addr[1] = board2;
  2019. rcktpt_io_addr[2] = board3;
  2020. rcktpt_io_addr[3] = board4;
  2021. rcktpt_type[0] = modem1 ? ROCKET_TYPE_MODEM : ROCKET_TYPE_NORMAL;
  2022. rcktpt_type[0] = pc104_1[0] ? ROCKET_TYPE_PC104 : rcktpt_type[0];
  2023. rcktpt_type[1] = modem2 ? ROCKET_TYPE_MODEM : ROCKET_TYPE_NORMAL;
  2024. rcktpt_type[1] = pc104_2[0] ? ROCKET_TYPE_PC104 : rcktpt_type[1];
  2025. rcktpt_type[2] = modem3 ? ROCKET_TYPE_MODEM : ROCKET_TYPE_NORMAL;
  2026. rcktpt_type[2] = pc104_3[0] ? ROCKET_TYPE_PC104 : rcktpt_type[2];
  2027. rcktpt_type[3] = modem4 ? ROCKET_TYPE_MODEM : ROCKET_TYPE_NORMAL;
  2028. rcktpt_type[3] = pc104_4[0] ? ROCKET_TYPE_PC104 : rcktpt_type[3];
  2029. /*
  2030. * Set up the tty driver structure and then register this
  2031. * driver with the tty layer.
  2032. */
  2033. rocket_driver->owner = THIS_MODULE;
  2034. rocket_driver->flags = TTY_DRIVER_DYNAMIC_DEV;
  2035. rocket_driver->name = "ttyR";
  2036. rocket_driver->driver_name = "Comtrol RocketPort";
  2037. rocket_driver->major = TTY_ROCKET_MAJOR;
  2038. rocket_driver->minor_start = 0;
  2039. rocket_driver->type = TTY_DRIVER_TYPE_SERIAL;
  2040. rocket_driver->subtype = SERIAL_TYPE_NORMAL;
  2041. rocket_driver->init_termios = tty_std_termios;
  2042. rocket_driver->init_termios.c_cflag =
  2043. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  2044. rocket_driver->init_termios.c_ispeed = 9600;
  2045. rocket_driver->init_termios.c_ospeed = 9600;
  2046. #ifdef ROCKET_SOFT_FLOW
  2047. rocket_driver->flags |= TTY_DRIVER_REAL_RAW;
  2048. #endif
  2049. tty_set_operations(rocket_driver, &rocket_ops);
  2050. ret = tty_register_driver(rocket_driver);
  2051. if (ret < 0) {
  2052. printk(KERN_ERR "Couldn't install tty RocketPort driver\n");
  2053. goto err_tty;
  2054. }
  2055. #ifdef ROCKET_DEBUG_OPEN
  2056. printk(KERN_INFO "RocketPort driver is major %d\n", rocket_driver.major);
  2057. #endif
  2058. /*
  2059. * OK, let's probe each of the controllers looking for boards. Any boards found
  2060. * will be initialized here.
  2061. */
  2062. isa_boards_found = 0;
  2063. pci_boards_found = 0;
  2064. for (i = 0; i < NUM_BOARDS; i++) {
  2065. if (init_ISA(i))
  2066. isa_boards_found++;
  2067. }
  2068. #ifdef CONFIG_PCI
  2069. if (isa_boards_found < NUM_BOARDS)
  2070. pci_boards_found = init_PCI(isa_boards_found);
  2071. #endif
  2072. max_board = pci_boards_found + isa_boards_found;
  2073. if (max_board == 0) {
  2074. printk(KERN_ERR "No rocketport ports found; unloading driver\n");
  2075. ret = -ENXIO;
  2076. goto err_ttyu;
  2077. }
  2078. return 0;
  2079. err_ttyu:
  2080. tty_unregister_driver(rocket_driver);
  2081. err_tty:
  2082. put_tty_driver(rocket_driver);
  2083. err:
  2084. return ret;
  2085. }
  2086. static void rp_cleanup_module(void)
  2087. {
  2088. int retval;
  2089. int i;
  2090. del_timer_sync(&rocket_timer);
  2091. retval = tty_unregister_driver(rocket_driver);
  2092. if (retval)
  2093. printk(KERN_ERR "Error %d while trying to unregister "
  2094. "rocketport driver\n", -retval);
  2095. for (i = 0; i < MAX_RP_PORTS; i++)
  2096. if (rp_table[i]) {
  2097. tty_unregister_device(rocket_driver, i);
  2098. kfree(rp_table[i]);
  2099. }
  2100. put_tty_driver(rocket_driver);
  2101. for (i = 0; i < NUM_BOARDS; i++) {
  2102. if (rcktpt_io_addr[i] <= 0 || is_PCI[i])
  2103. continue;
  2104. release_region(rcktpt_io_addr[i], 64);
  2105. }
  2106. if (controller)
  2107. release_region(controller, 4);
  2108. }
  2109. /***************************************************************************
  2110. Function: sInitController
  2111. Purpose: Initialization of controller global registers and controller
  2112. structure.
  2113. Call: sInitController(CtlP,CtlNum,MudbacIO,AiopIOList,AiopIOListSize,
  2114. IRQNum,Frequency,PeriodicOnly)
  2115. CONTROLLER_T *CtlP; Ptr to controller structure
  2116. int CtlNum; Controller number
  2117. ByteIO_t MudbacIO; Mudbac base I/O address.
  2118. ByteIO_t *AiopIOList; List of I/O addresses for each AIOP.
  2119. This list must be in the order the AIOPs will be found on the
  2120. controller. Once an AIOP in the list is not found, it is
  2121. assumed that there are no more AIOPs on the controller.
  2122. int AiopIOListSize; Number of addresses in AiopIOList
  2123. int IRQNum; Interrupt Request number. Can be any of the following:
  2124. 0: Disable global interrupts
  2125. 3: IRQ 3
  2126. 4: IRQ 4
  2127. 5: IRQ 5
  2128. 9: IRQ 9
  2129. 10: IRQ 10
  2130. 11: IRQ 11
  2131. 12: IRQ 12
  2132. 15: IRQ 15
  2133. Byte_t Frequency: A flag identifying the frequency
  2134. of the periodic interrupt, can be any one of the following:
  2135. FREQ_DIS - periodic interrupt disabled
  2136. FREQ_137HZ - 137 Hertz
  2137. FREQ_69HZ - 69 Hertz
  2138. FREQ_34HZ - 34 Hertz
  2139. FREQ_17HZ - 17 Hertz
  2140. FREQ_9HZ - 9 Hertz
  2141. FREQ_4HZ - 4 Hertz
  2142. If IRQNum is set to 0 the Frequency parameter is
  2143. overidden, it is forced to a value of FREQ_DIS.
  2144. int PeriodicOnly: 1 if all interrupts except the periodic
  2145. interrupt are to be blocked.
  2146. 0 is both the periodic interrupt and
  2147. other channel interrupts are allowed.
  2148. If IRQNum is set to 0 the PeriodicOnly parameter is
  2149. overidden, it is forced to a value of 0.
  2150. Return: int: Number of AIOPs on the controller, or CTLID_NULL if controller
  2151. initialization failed.
  2152. Comments:
  2153. If periodic interrupts are to be disabled but AIOP interrupts
  2154. are allowed, set Frequency to FREQ_DIS and PeriodicOnly to 0.
  2155. If interrupts are to be completely disabled set IRQNum to 0.
  2156. Setting Frequency to FREQ_DIS and PeriodicOnly to 1 is an
  2157. invalid combination.
  2158. This function performs initialization of global interrupt modes,
  2159. but it does not actually enable global interrupts. To enable
  2160. and disable global interrupts use functions sEnGlobalInt() and
  2161. sDisGlobalInt(). Enabling of global interrupts is normally not
  2162. done until all other initializations are complete.
  2163. Even if interrupts are globally enabled, they must also be
  2164. individually enabled for each channel that is to generate
  2165. interrupts.
  2166. Warnings: No range checking on any of the parameters is done.
  2167. No context switches are allowed while executing this function.
  2168. After this function all AIOPs on the controller are disabled,
  2169. they can be enabled with sEnAiop().
  2170. */
  2171. static int sInitController(CONTROLLER_T * CtlP, int CtlNum, ByteIO_t MudbacIO,
  2172. ByteIO_t * AiopIOList, int AiopIOListSize,
  2173. int IRQNum, Byte_t Frequency, int PeriodicOnly)
  2174. {
  2175. int i;
  2176. ByteIO_t io;
  2177. int done;
  2178. CtlP->AiopIntrBits = aiop_intr_bits;
  2179. CtlP->AltChanRingIndicator = 0;
  2180. CtlP->CtlNum = CtlNum;
  2181. CtlP->CtlID = CTLID_0001; /* controller release 1 */
  2182. CtlP->BusType = isISA;
  2183. CtlP->MBaseIO = MudbacIO;
  2184. CtlP->MReg1IO = MudbacIO + 1;
  2185. CtlP->MReg2IO = MudbacIO + 2;
  2186. CtlP->MReg3IO = MudbacIO + 3;
  2187. #if 1
  2188. CtlP->MReg2 = 0; /* interrupt disable */
  2189. CtlP->MReg3 = 0; /* no periodic interrupts */
  2190. #else
  2191. if (sIRQMap[IRQNum] == 0) { /* interrupts globally disabled */
  2192. CtlP->MReg2 = 0; /* interrupt disable */
  2193. CtlP->MReg3 = 0; /* no periodic interrupts */
  2194. } else {
  2195. CtlP->MReg2 = sIRQMap[IRQNum]; /* set IRQ number */
  2196. CtlP->MReg3 = Frequency; /* set frequency */
  2197. if (PeriodicOnly) { /* periodic interrupt only */
  2198. CtlP->MReg3 |= PERIODIC_ONLY;
  2199. }
  2200. }
  2201. #endif
  2202. sOutB(CtlP->MReg2IO, CtlP->MReg2);
  2203. sOutB(CtlP->MReg3IO, CtlP->MReg3);
  2204. sControllerEOI(CtlP); /* clear EOI if warm init */
  2205. /* Init AIOPs */
  2206. CtlP->NumAiop = 0;
  2207. for (i = done = 0; i < AiopIOListSize; i++) {
  2208. io = AiopIOList[i];
  2209. CtlP->AiopIO[i] = (WordIO_t) io;
  2210. CtlP->AiopIntChanIO[i] = io + _INT_CHAN;
  2211. sOutB(CtlP->MReg2IO, CtlP->MReg2 | (i & 0x03)); /* AIOP index */
  2212. sOutB(MudbacIO, (Byte_t) (io >> 6)); /* set up AIOP I/O in MUDBAC */
  2213. if (done)
  2214. continue;
  2215. sEnAiop(CtlP, i); /* enable the AIOP */
  2216. CtlP->AiopID[i] = sReadAiopID(io); /* read AIOP ID */
  2217. if (CtlP->AiopID[i] == AIOPID_NULL) /* if AIOP does not exist */
  2218. done = 1; /* done looking for AIOPs */
  2219. else {
  2220. CtlP->AiopNumChan[i] = sReadAiopNumChan((WordIO_t) io); /* num channels in AIOP */
  2221. sOutW((WordIO_t) io + _INDX_ADDR, _CLK_PRE); /* clock prescaler */
  2222. sOutB(io + _INDX_DATA, sClockPrescale);
  2223. CtlP->NumAiop++; /* bump count of AIOPs */
  2224. }
  2225. sDisAiop(CtlP, i); /* disable AIOP */
  2226. }
  2227. if (CtlP->NumAiop == 0)
  2228. return (-1);
  2229. else
  2230. return (CtlP->NumAiop);
  2231. }
  2232. /***************************************************************************
  2233. Function: sPCIInitController
  2234. Purpose: Initialization of controller global registers and controller
  2235. structure.
  2236. Call: sPCIInitController(CtlP,CtlNum,AiopIOList,AiopIOListSize,
  2237. IRQNum,Frequency,PeriodicOnly)
  2238. CONTROLLER_T *CtlP; Ptr to controller structure
  2239. int CtlNum; Controller number
  2240. ByteIO_t *AiopIOList; List of I/O addresses for each AIOP.
  2241. This list must be in the order the AIOPs will be found on the
  2242. controller. Once an AIOP in the list is not found, it is
  2243. assumed that there are no more AIOPs on the controller.
  2244. int AiopIOListSize; Number of addresses in AiopIOList
  2245. int IRQNum; Interrupt Request number. Can be any of the following:
  2246. 0: Disable global interrupts
  2247. 3: IRQ 3
  2248. 4: IRQ 4
  2249. 5: IRQ 5
  2250. 9: IRQ 9
  2251. 10: IRQ 10
  2252. 11: IRQ 11
  2253. 12: IRQ 12
  2254. 15: IRQ 15
  2255. Byte_t Frequency: A flag identifying the frequency
  2256. of the periodic interrupt, can be any one of the following:
  2257. FREQ_DIS - periodic interrupt disabled
  2258. FREQ_137HZ - 137 Hertz
  2259. FREQ_69HZ - 69 Hertz
  2260. FREQ_34HZ - 34 Hertz
  2261. FREQ_17HZ - 17 Hertz
  2262. FREQ_9HZ - 9 Hertz
  2263. FREQ_4HZ - 4 Hertz
  2264. If IRQNum is set to 0 the Frequency parameter is
  2265. overidden, it is forced to a value of FREQ_DIS.
  2266. int PeriodicOnly: 1 if all interrupts except the periodic
  2267. interrupt are to be blocked.
  2268. 0 is both the periodic interrupt and
  2269. other channel interrupts are allowed.
  2270. If IRQNum is set to 0 the PeriodicOnly parameter is
  2271. overidden, it is forced to a value of 0.
  2272. Return: int: Number of AIOPs on the controller, or CTLID_NULL if controller
  2273. initialization failed.
  2274. Comments:
  2275. If periodic interrupts are to be disabled but AIOP interrupts
  2276. are allowed, set Frequency to FREQ_DIS and PeriodicOnly to 0.
  2277. If interrupts are to be completely disabled set IRQNum to 0.
  2278. Setting Frequency to FREQ_DIS and PeriodicOnly to 1 is an
  2279. invalid combination.
  2280. This function performs initialization of global interrupt modes,
  2281. but it does not actually enable global interrupts. To enable
  2282. and disable global interrupts use functions sEnGlobalInt() and
  2283. sDisGlobalInt(). Enabling of global interrupts is normally not
  2284. done until all other initializations are complete.
  2285. Even if interrupts are globally enabled, they must also be
  2286. individually enabled for each channel that is to generate
  2287. interrupts.
  2288. Warnings: No range checking on any of the parameters is done.
  2289. No context switches are allowed while executing this function.
  2290. After this function all AIOPs on the controller are disabled,
  2291. they can be enabled with sEnAiop().
  2292. */
  2293. static int sPCIInitController(CONTROLLER_T * CtlP, int CtlNum,
  2294. ByteIO_t * AiopIOList, int AiopIOListSize,
  2295. WordIO_t ConfigIO, int IRQNum, Byte_t Frequency,
  2296. int PeriodicOnly, int altChanRingIndicator,
  2297. int UPCIRingInd)
  2298. {
  2299. int i;
  2300. ByteIO_t io;
  2301. CtlP->AltChanRingIndicator = altChanRingIndicator;
  2302. CtlP->UPCIRingInd = UPCIRingInd;
  2303. CtlP->CtlNum = CtlNum;
  2304. CtlP->CtlID = CTLID_0001; /* controller release 1 */
  2305. CtlP->BusType = isPCI; /* controller release 1 */
  2306. if (ConfigIO) {
  2307. CtlP->isUPCI = 1;
  2308. CtlP->PCIIO = ConfigIO + _PCI_9030_INT_CTRL;
  2309. CtlP->PCIIO2 = ConfigIO + _PCI_9030_GPIO_CTRL;
  2310. CtlP->AiopIntrBits = upci_aiop_intr_bits;
  2311. } else {
  2312. CtlP->isUPCI = 0;
  2313. CtlP->PCIIO =
  2314. (WordIO_t) ((ByteIO_t) AiopIOList[0] + _PCI_INT_FUNC);
  2315. CtlP->AiopIntrBits = aiop_intr_bits;
  2316. }
  2317. sPCIControllerEOI(CtlP); /* clear EOI if warm init */
  2318. /* Init AIOPs */
  2319. CtlP->NumAiop = 0;
  2320. for (i = 0; i < AiopIOListSize; i++) {
  2321. io = AiopIOList[i];
  2322. CtlP->AiopIO[i] = (WordIO_t) io;
  2323. CtlP->AiopIntChanIO[i] = io + _INT_CHAN;
  2324. CtlP->AiopID[i] = sReadAiopID(io); /* read AIOP ID */
  2325. if (CtlP->AiopID[i] == AIOPID_NULL) /* if AIOP does not exist */
  2326. break; /* done looking for AIOPs */
  2327. CtlP->AiopNumChan[i] = sReadAiopNumChan((WordIO_t) io); /* num channels in AIOP */
  2328. sOutW((WordIO_t) io + _INDX_ADDR, _CLK_PRE); /* clock prescaler */
  2329. sOutB(io + _INDX_DATA, sClockPrescale);
  2330. CtlP->NumAiop++; /* bump count of AIOPs */
  2331. }
  2332. if (CtlP->NumAiop == 0)
  2333. return (-1);
  2334. else
  2335. return (CtlP->NumAiop);
  2336. }
  2337. /***************************************************************************
  2338. Function: sReadAiopID
  2339. Purpose: Read the AIOP idenfication number directly from an AIOP.
  2340. Call: sReadAiopID(io)
  2341. ByteIO_t io: AIOP base I/O address
  2342. Return: int: Flag AIOPID_XXXX if a valid AIOP is found, where X
  2343. is replace by an identifying number.
  2344. Flag AIOPID_NULL if no valid AIOP is found
  2345. Warnings: No context switches are allowed while executing this function.
  2346. */
  2347. static int sReadAiopID(ByteIO_t io)
  2348. {
  2349. Byte_t AiopID; /* ID byte from AIOP */
  2350. sOutB(io + _CMD_REG, RESET_ALL); /* reset AIOP */
  2351. sOutB(io + _CMD_REG, 0x0);
  2352. AiopID = sInW(io + _CHN_STAT0) & 0x07;
  2353. if (AiopID == 0x06)
  2354. return (1);
  2355. else /* AIOP does not exist */
  2356. return (-1);
  2357. }
  2358. /***************************************************************************
  2359. Function: sReadAiopNumChan
  2360. Purpose: Read the number of channels available in an AIOP directly from
  2361. an AIOP.
  2362. Call: sReadAiopNumChan(io)
  2363. WordIO_t io: AIOP base I/O address
  2364. Return: int: The number of channels available
  2365. Comments: The number of channels is determined by write/reads from identical
  2366. offsets within the SRAM address spaces for channels 0 and 4.
  2367. If the channel 4 space is mirrored to channel 0 it is a 4 channel
  2368. AIOP, otherwise it is an 8 channel.
  2369. Warnings: No context switches are allowed while executing this function.
  2370. */
  2371. static int sReadAiopNumChan(WordIO_t io)
  2372. {
  2373. Word_t x;
  2374. static Byte_t R[4] = { 0x00, 0x00, 0x34, 0x12 };
  2375. /* write to chan 0 SRAM */
  2376. out32((DWordIO_t) io + _INDX_ADDR, R);
  2377. sOutW(io + _INDX_ADDR, 0); /* read from SRAM, chan 0 */
  2378. x = sInW(io + _INDX_DATA);
  2379. sOutW(io + _INDX_ADDR, 0x4000); /* read from SRAM, chan 4 */
  2380. if (x != sInW(io + _INDX_DATA)) /* if different must be 8 chan */
  2381. return (8);
  2382. else
  2383. return (4);
  2384. }
  2385. /***************************************************************************
  2386. Function: sInitChan
  2387. Purpose: Initialization of a channel and channel structure
  2388. Call: sInitChan(CtlP,ChP,AiopNum,ChanNum)
  2389. CONTROLLER_T *CtlP; Ptr to controller structure
  2390. CHANNEL_T *ChP; Ptr to channel structure
  2391. int AiopNum; AIOP number within controller
  2392. int ChanNum; Channel number within AIOP
  2393. Return: int: 1 if initialization succeeded, 0 if it fails because channel
  2394. number exceeds number of channels available in AIOP.
  2395. Comments: This function must be called before a channel can be used.
  2396. Warnings: No range checking on any of the parameters is done.
  2397. No context switches are allowed while executing this function.
  2398. */
  2399. static int sInitChan(CONTROLLER_T * CtlP, CHANNEL_T * ChP, int AiopNum,
  2400. int ChanNum)
  2401. {
  2402. int i;
  2403. WordIO_t AiopIO;
  2404. WordIO_t ChIOOff;
  2405. Byte_t *ChR;
  2406. Word_t ChOff;
  2407. static Byte_t R[4];
  2408. int brd9600;
  2409. if (ChanNum >= CtlP->AiopNumChan[AiopNum])
  2410. return 0; /* exceeds num chans in AIOP */
  2411. /* Channel, AIOP, and controller identifiers */
  2412. ChP->CtlP = CtlP;
  2413. ChP->ChanID = CtlP->AiopID[AiopNum];
  2414. ChP->AiopNum = AiopNum;
  2415. ChP->ChanNum = ChanNum;
  2416. /* Global direct addresses */
  2417. AiopIO = CtlP->AiopIO[AiopNum];
  2418. ChP->Cmd = (ByteIO_t) AiopIO + _CMD_REG;
  2419. ChP->IntChan = (ByteIO_t) AiopIO + _INT_CHAN;
  2420. ChP->IntMask = (ByteIO_t) AiopIO + _INT_MASK;
  2421. ChP->IndexAddr = (DWordIO_t) AiopIO + _INDX_ADDR;
  2422. ChP->IndexData = AiopIO + _INDX_DATA;
  2423. /* Channel direct addresses */
  2424. ChIOOff = AiopIO + ChP->ChanNum * 2;
  2425. ChP->TxRxData = ChIOOff + _TD0;
  2426. ChP->ChanStat = ChIOOff + _CHN_STAT0;
  2427. ChP->TxRxCount = ChIOOff + _FIFO_CNT0;
  2428. ChP->IntID = (ByteIO_t) AiopIO + ChP->ChanNum + _INT_ID0;
  2429. /* Initialize the channel from the RData array */
  2430. for (i = 0; i < RDATASIZE; i += 4) {
  2431. R[0] = RData[i];
  2432. R[1] = RData[i + 1] + 0x10 * ChanNum;
  2433. R[2] = RData[i + 2];
  2434. R[3] = RData[i + 3];
  2435. out32(ChP->IndexAddr, R);
  2436. }
  2437. ChR = ChP->R;
  2438. for (i = 0; i < RREGDATASIZE; i += 4) {
  2439. ChR[i] = RRegData[i];
  2440. ChR[i + 1] = RRegData[i + 1] + 0x10 * ChanNum;
  2441. ChR[i + 2] = RRegData[i + 2];
  2442. ChR[i + 3] = RRegData[i + 3];
  2443. }
  2444. /* Indexed registers */
  2445. ChOff = (Word_t) ChanNum *0x1000;
  2446. if (sClockPrescale == 0x14)
  2447. brd9600 = 47;
  2448. else
  2449. brd9600 = 23;
  2450. ChP->BaudDiv[0] = (Byte_t) (ChOff + _BAUD);
  2451. ChP->BaudDiv[1] = (Byte_t) ((ChOff + _BAUD) >> 8);
  2452. ChP->BaudDiv[2] = (Byte_t) brd9600;
  2453. ChP->BaudDiv[3] = (Byte_t) (brd9600 >> 8);
  2454. out32(ChP->IndexAddr, ChP->BaudDiv);
  2455. ChP->TxControl[0] = (Byte_t) (ChOff + _TX_CTRL);
  2456. ChP->TxControl[1] = (Byte_t) ((ChOff + _TX_CTRL) >> 8);
  2457. ChP->TxControl[2] = 0;
  2458. ChP->TxControl[3] = 0;
  2459. out32(ChP->IndexAddr, ChP->TxControl);
  2460. ChP->RxControl[0] = (Byte_t) (ChOff + _RX_CTRL);
  2461. ChP->RxControl[1] = (Byte_t) ((ChOff + _RX_CTRL) >> 8);
  2462. ChP->RxControl[2] = 0;
  2463. ChP->RxControl[3] = 0;
  2464. out32(ChP->IndexAddr, ChP->RxControl);
  2465. ChP->TxEnables[0] = (Byte_t) (ChOff + _TX_ENBLS);
  2466. ChP->TxEnables[1] = (Byte_t) ((ChOff + _TX_ENBLS) >> 8);
  2467. ChP->TxEnables[2] = 0;
  2468. ChP->TxEnables[3] = 0;
  2469. out32(ChP->IndexAddr, ChP->TxEnables);
  2470. ChP->TxCompare[0] = (Byte_t) (ChOff + _TXCMP1);
  2471. ChP->TxCompare[1] = (Byte_t) ((ChOff + _TXCMP1) >> 8);
  2472. ChP->TxCompare[2] = 0;
  2473. ChP->TxCompare[3] = 0;
  2474. out32(ChP->IndexAddr, ChP->TxCompare);
  2475. ChP->TxReplace1[0] = (Byte_t) (ChOff + _TXREP1B1);
  2476. ChP->TxReplace1[1] = (Byte_t) ((ChOff + _TXREP1B1) >> 8);
  2477. ChP->TxReplace1[2] = 0;
  2478. ChP->TxReplace1[3] = 0;
  2479. out32(ChP->IndexAddr, ChP->TxReplace1);
  2480. ChP->TxReplace2[0] = (Byte_t) (ChOff + _TXREP2);
  2481. ChP->TxReplace2[1] = (Byte_t) ((ChOff + _TXREP2) >> 8);
  2482. ChP->TxReplace2[2] = 0;
  2483. ChP->TxReplace2[3] = 0;
  2484. out32(ChP->IndexAddr, ChP->TxReplace2);
  2485. ChP->TxFIFOPtrs = ChOff + _TXF_OUTP;
  2486. ChP->TxFIFO = ChOff + _TX_FIFO;
  2487. sOutB(ChP->Cmd, (Byte_t) ChanNum | RESTXFCNT); /* apply reset Tx FIFO count */
  2488. sOutB(ChP->Cmd, (Byte_t) ChanNum); /* remove reset Tx FIFO count */
  2489. sOutW((WordIO_t) ChP->IndexAddr, ChP->TxFIFOPtrs); /* clear Tx in/out ptrs */
  2490. sOutW(ChP->IndexData, 0);
  2491. ChP->RxFIFOPtrs = ChOff + _RXF_OUTP;
  2492. ChP->RxFIFO = ChOff + _RX_FIFO;
  2493. sOutB(ChP->Cmd, (Byte_t) ChanNum | RESRXFCNT); /* apply reset Rx FIFO count */
  2494. sOutB(ChP->Cmd, (Byte_t) ChanNum); /* remove reset Rx FIFO count */
  2495. sOutW((WordIO_t) ChP->IndexAddr, ChP->RxFIFOPtrs); /* clear Rx out ptr */
  2496. sOutW(ChP->IndexData, 0);
  2497. sOutW((WordIO_t) ChP->IndexAddr, ChP->RxFIFOPtrs + 2); /* clear Rx in ptr */
  2498. sOutW(ChP->IndexData, 0);
  2499. ChP->TxPrioCnt = ChOff + _TXP_CNT;
  2500. sOutW((WordIO_t) ChP->IndexAddr, ChP->TxPrioCnt);
  2501. sOutB(ChP->IndexData, 0);
  2502. ChP->TxPrioPtr = ChOff + _TXP_PNTR;
  2503. sOutW((WordIO_t) ChP->IndexAddr, ChP->TxPrioPtr);
  2504. sOutB(ChP->IndexData, 0);
  2505. ChP->TxPrioBuf = ChOff + _TXP_BUF;
  2506. sEnRxProcessor(ChP); /* start the Rx processor */
  2507. return 1;
  2508. }
  2509. /***************************************************************************
  2510. Function: sStopRxProcessor
  2511. Purpose: Stop the receive processor from processing a channel.
  2512. Call: sStopRxProcessor(ChP)
  2513. CHANNEL_T *ChP; Ptr to channel structure
  2514. Comments: The receive processor can be started again with sStartRxProcessor().
  2515. This function causes the receive processor to skip over the
  2516. stopped channel. It does not stop it from processing other channels.
  2517. Warnings: No context switches are allowed while executing this function.
  2518. Do not leave the receive processor stopped for more than one
  2519. character time.
  2520. After calling this function a delay of 4 uS is required to ensure
  2521. that the receive processor is no longer processing this channel.
  2522. */
  2523. static void sStopRxProcessor(CHANNEL_T * ChP)
  2524. {
  2525. Byte_t R[4];
  2526. R[0] = ChP->R[0];
  2527. R[1] = ChP->R[1];
  2528. R[2] = 0x0a;
  2529. R[3] = ChP->R[3];
  2530. out32(ChP->IndexAddr, R);
  2531. }
  2532. /***************************************************************************
  2533. Function: sFlushRxFIFO
  2534. Purpose: Flush the Rx FIFO
  2535. Call: sFlushRxFIFO(ChP)
  2536. CHANNEL_T *ChP; Ptr to channel structure
  2537. Return: void
  2538. Comments: To prevent data from being enqueued or dequeued in the Tx FIFO
  2539. while it is being flushed the receive processor is stopped
  2540. and the transmitter is disabled. After these operations a
  2541. 4 uS delay is done before clearing the pointers to allow
  2542. the receive processor to stop. These items are handled inside
  2543. this function.
  2544. Warnings: No context switches are allowed while executing this function.
  2545. */
  2546. static void sFlushRxFIFO(CHANNEL_T * ChP)
  2547. {
  2548. int i;
  2549. Byte_t Ch; /* channel number within AIOP */
  2550. int RxFIFOEnabled; /* 1 if Rx FIFO enabled */
  2551. if (sGetRxCnt(ChP) == 0) /* Rx FIFO empty */
  2552. return; /* don't need to flush */
  2553. RxFIFOEnabled = 0;
  2554. if (ChP->R[0x32] == 0x08) { /* Rx FIFO is enabled */
  2555. RxFIFOEnabled = 1;
  2556. sDisRxFIFO(ChP); /* disable it */
  2557. for (i = 0; i < 2000 / 200; i++) /* delay 2 uS to allow proc to disable FIFO */
  2558. sInB(ChP->IntChan); /* depends on bus i/o timing */
  2559. }
  2560. sGetChanStatus(ChP); /* clear any pending Rx errors in chan stat */
  2561. Ch = (Byte_t) sGetChanNum(ChP);
  2562. sOutB(ChP->Cmd, Ch | RESRXFCNT); /* apply reset Rx FIFO count */
  2563. sOutB(ChP->Cmd, Ch); /* remove reset Rx FIFO count */
  2564. sOutW((WordIO_t) ChP->IndexAddr, ChP->RxFIFOPtrs); /* clear Rx out ptr */
  2565. sOutW(ChP->IndexData, 0);
  2566. sOutW((WordIO_t) ChP->IndexAddr, ChP->RxFIFOPtrs + 2); /* clear Rx in ptr */
  2567. sOutW(ChP->IndexData, 0);
  2568. if (RxFIFOEnabled)
  2569. sEnRxFIFO(ChP); /* enable Rx FIFO */
  2570. }
  2571. /***************************************************************************
  2572. Function: sFlushTxFIFO
  2573. Purpose: Flush the Tx FIFO
  2574. Call: sFlushTxFIFO(ChP)
  2575. CHANNEL_T *ChP; Ptr to channel structure
  2576. Return: void
  2577. Comments: To prevent data from being enqueued or dequeued in the Tx FIFO
  2578. while it is being flushed the receive processor is stopped
  2579. and the transmitter is disabled. After these operations a
  2580. 4 uS delay is done before clearing the pointers to allow
  2581. the receive processor to stop. These items are handled inside
  2582. this function.
  2583. Warnings: No context switches are allowed while executing this function.
  2584. */
  2585. static void sFlushTxFIFO(CHANNEL_T * ChP)
  2586. {
  2587. int i;
  2588. Byte_t Ch; /* channel number within AIOP */
  2589. int TxEnabled; /* 1 if transmitter enabled */
  2590. if (sGetTxCnt(ChP) == 0) /* Tx FIFO empty */
  2591. return; /* don't need to flush */
  2592. TxEnabled = 0;
  2593. if (ChP->TxControl[3] & TX_ENABLE) {
  2594. TxEnabled = 1;
  2595. sDisTransmit(ChP); /* disable transmitter */
  2596. }
  2597. sStopRxProcessor(ChP); /* stop Rx processor */
  2598. for (i = 0; i < 4000 / 200; i++) /* delay 4 uS to allow proc to stop */
  2599. sInB(ChP->IntChan); /* depends on bus i/o timing */
  2600. Ch = (Byte_t) sGetChanNum(ChP);
  2601. sOutB(ChP->Cmd, Ch | RESTXFCNT); /* apply reset Tx FIFO count */
  2602. sOutB(ChP->Cmd, Ch); /* remove reset Tx FIFO count */
  2603. sOutW((WordIO_t) ChP->IndexAddr, ChP->TxFIFOPtrs); /* clear Tx in/out ptrs */
  2604. sOutW(ChP->IndexData, 0);
  2605. if (TxEnabled)
  2606. sEnTransmit(ChP); /* enable transmitter */
  2607. sStartRxProcessor(ChP); /* restart Rx processor */
  2608. }
  2609. /***************************************************************************
  2610. Function: sWriteTxPrioByte
  2611. Purpose: Write a byte of priority transmit data to a channel
  2612. Call: sWriteTxPrioByte(ChP,Data)
  2613. CHANNEL_T *ChP; Ptr to channel structure
  2614. Byte_t Data; The transmit data byte
  2615. Return: int: 1 if the bytes is successfully written, otherwise 0.
  2616. Comments: The priority byte is transmitted before any data in the Tx FIFO.
  2617. Warnings: No context switches are allowed while executing this function.
  2618. */
  2619. static int sWriteTxPrioByte(CHANNEL_T * ChP, Byte_t Data)
  2620. {
  2621. Byte_t DWBuf[4]; /* buffer for double word writes */
  2622. Word_t *WordPtr; /* must be far because Win SS != DS */
  2623. register DWordIO_t IndexAddr;
  2624. if (sGetTxCnt(ChP) > 1) { /* write it to Tx priority buffer */
  2625. IndexAddr = ChP->IndexAddr;
  2626. sOutW((WordIO_t) IndexAddr, ChP->TxPrioCnt); /* get priority buffer status */
  2627. if (sInB((ByteIO_t) ChP->IndexData) & PRI_PEND) /* priority buffer busy */
  2628. return (0); /* nothing sent */
  2629. WordPtr = (Word_t *) (&DWBuf[0]);
  2630. *WordPtr = ChP->TxPrioBuf; /* data byte address */
  2631. DWBuf[2] = Data; /* data byte value */
  2632. out32(IndexAddr, DWBuf); /* write it out */
  2633. *WordPtr = ChP->TxPrioCnt; /* Tx priority count address */
  2634. DWBuf[2] = PRI_PEND + 1; /* indicate 1 byte pending */
  2635. DWBuf[3] = 0; /* priority buffer pointer */
  2636. out32(IndexAddr, DWBuf); /* write it out */
  2637. } else { /* write it to Tx FIFO */
  2638. sWriteTxByte(sGetTxRxDataIO(ChP), Data);
  2639. }
  2640. return (1); /* 1 byte sent */
  2641. }
  2642. /***************************************************************************
  2643. Function: sEnInterrupts
  2644. Purpose: Enable one or more interrupts for a channel
  2645. Call: sEnInterrupts(ChP,Flags)
  2646. CHANNEL_T *ChP; Ptr to channel structure
  2647. Word_t Flags: Interrupt enable flags, can be any combination
  2648. of the following flags:
  2649. TXINT_EN: Interrupt on Tx FIFO empty
  2650. RXINT_EN: Interrupt on Rx FIFO at trigger level (see
  2651. sSetRxTrigger())
  2652. SRCINT_EN: Interrupt on SRC (Special Rx Condition)
  2653. MCINT_EN: Interrupt on modem input change
  2654. CHANINT_EN: Allow channel interrupt signal to the AIOP's
  2655. Interrupt Channel Register.
  2656. Return: void
  2657. Comments: If an interrupt enable flag is set in Flags, that interrupt will be
  2658. enabled. If an interrupt enable flag is not set in Flags, that
  2659. interrupt will not be changed. Interrupts can be disabled with
  2660. function sDisInterrupts().
  2661. This function sets the appropriate bit for the channel in the AIOP's
  2662. Interrupt Mask Register if the CHANINT_EN flag is set. This allows
  2663. this channel's bit to be set in the AIOP's Interrupt Channel Register.
  2664. Interrupts must also be globally enabled before channel interrupts
  2665. will be passed on to the host. This is done with function
  2666. sEnGlobalInt().
  2667. In some cases it may be desirable to disable interrupts globally but
  2668. enable channel interrupts. This would allow the global interrupt
  2669. status register to be used to determine which AIOPs need service.
  2670. */
  2671. static void sEnInterrupts(CHANNEL_T * ChP, Word_t Flags)
  2672. {
  2673. Byte_t Mask; /* Interrupt Mask Register */
  2674. ChP->RxControl[2] |=
  2675. ((Byte_t) Flags & (RXINT_EN | SRCINT_EN | MCINT_EN));
  2676. out32(ChP->IndexAddr, ChP->RxControl);
  2677. ChP->TxControl[2] |= ((Byte_t) Flags & TXINT_EN);
  2678. out32(ChP->IndexAddr, ChP->TxControl);
  2679. if (Flags & CHANINT_EN) {
  2680. Mask = sInB(ChP->IntMask) | sBitMapSetTbl[ChP->ChanNum];
  2681. sOutB(ChP->IntMask, Mask);
  2682. }
  2683. }
  2684. /***************************************************************************
  2685. Function: sDisInterrupts
  2686. Purpose: Disable one or more interrupts for a channel
  2687. Call: sDisInterrupts(ChP,Flags)
  2688. CHANNEL_T *ChP; Ptr to channel structure
  2689. Word_t Flags: Interrupt flags, can be any combination
  2690. of the following flags:
  2691. TXINT_EN: Interrupt on Tx FIFO empty
  2692. RXINT_EN: Interrupt on Rx FIFO at trigger level (see
  2693. sSetRxTrigger())
  2694. SRCINT_EN: Interrupt on SRC (Special Rx Condition)
  2695. MCINT_EN: Interrupt on modem input change
  2696. CHANINT_EN: Disable channel interrupt signal to the
  2697. AIOP's Interrupt Channel Register.
  2698. Return: void
  2699. Comments: If an interrupt flag is set in Flags, that interrupt will be
  2700. disabled. If an interrupt flag is not set in Flags, that
  2701. interrupt will not be changed. Interrupts can be enabled with
  2702. function sEnInterrupts().
  2703. This function clears the appropriate bit for the channel in the AIOP's
  2704. Interrupt Mask Register if the CHANINT_EN flag is set. This blocks
  2705. this channel's bit from being set in the AIOP's Interrupt Channel
  2706. Register.
  2707. */
  2708. static void sDisInterrupts(CHANNEL_T * ChP, Word_t Flags)
  2709. {
  2710. Byte_t Mask; /* Interrupt Mask Register */
  2711. ChP->RxControl[2] &=
  2712. ~((Byte_t) Flags & (RXINT_EN | SRCINT_EN | MCINT_EN));
  2713. out32(ChP->IndexAddr, ChP->RxControl);
  2714. ChP->TxControl[2] &= ~((Byte_t) Flags & TXINT_EN);
  2715. out32(ChP->IndexAddr, ChP->TxControl);
  2716. if (Flags & CHANINT_EN) {
  2717. Mask = sInB(ChP->IntMask) & sBitMapClrTbl[ChP->ChanNum];
  2718. sOutB(ChP->IntMask, Mask);
  2719. }
  2720. }
  2721. static void sSetInterfaceMode(CHANNEL_T * ChP, Byte_t mode)
  2722. {
  2723. sOutB(ChP->CtlP->AiopIO[2], (mode & 0x18) | ChP->ChanNum);
  2724. }
  2725. /*
  2726. * Not an official SSCI function, but how to reset RocketModems.
  2727. * ISA bus version
  2728. */
  2729. static void sModemReset(CONTROLLER_T * CtlP, int chan, int on)
  2730. {
  2731. ByteIO_t addr;
  2732. Byte_t val;
  2733. addr = CtlP->AiopIO[0] + 0x400;
  2734. val = sInB(CtlP->MReg3IO);
  2735. /* if AIOP[1] is not enabled, enable it */
  2736. if ((val & 2) == 0) {
  2737. val = sInB(CtlP->MReg2IO);
  2738. sOutB(CtlP->MReg2IO, (val & 0xfc) | (1 & 0x03));
  2739. sOutB(CtlP->MBaseIO, (unsigned char) (addr >> 6));
  2740. }
  2741. sEnAiop(CtlP, 1);
  2742. if (!on)
  2743. addr += 8;
  2744. sOutB(addr + chan, 0); /* apply or remove reset */
  2745. sDisAiop(CtlP, 1);
  2746. }
  2747. /*
  2748. * Not an official SSCI function, but how to reset RocketModems.
  2749. * PCI bus version
  2750. */
  2751. static void sPCIModemReset(CONTROLLER_T * CtlP, int chan, int on)
  2752. {
  2753. ByteIO_t addr;
  2754. addr = CtlP->AiopIO[0] + 0x40; /* 2nd AIOP */
  2755. if (!on)
  2756. addr += 8;
  2757. sOutB(addr + chan, 0); /* apply or remove reset */
  2758. }
  2759. /* Resets the speaker controller on RocketModem II and III devices */
  2760. static void rmSpeakerReset(CONTROLLER_T * CtlP, unsigned long model)
  2761. {
  2762. ByteIO_t addr;
  2763. /* RocketModem II speaker control is at the 8th port location of offset 0x40 */
  2764. if ((model == MODEL_RP4M) || (model == MODEL_RP6M)) {
  2765. addr = CtlP->AiopIO[0] + 0x4F;
  2766. sOutB(addr, 0);
  2767. }
  2768. /* RocketModem III speaker control is at the 1st port location of offset 0x80 */
  2769. if ((model == MODEL_UPCI_RM3_8PORT)
  2770. || (model == MODEL_UPCI_RM3_4PORT)) {
  2771. addr = CtlP->AiopIO[0] + 0x88;
  2772. sOutB(addr, 0);
  2773. }
  2774. }
  2775. /* Returns the line number given the controller (board), aiop and channel number */
  2776. static unsigned char GetLineNumber(int ctrl, int aiop, int ch)
  2777. {
  2778. return lineNumbers[(ctrl << 5) | (aiop << 3) | ch];
  2779. }
  2780. /*
  2781. * Stores the line number associated with a given controller (board), aiop
  2782. * and channel number.
  2783. * Returns: The line number assigned
  2784. */
  2785. static unsigned char SetLineNumber(int ctrl, int aiop, int ch)
  2786. {
  2787. lineNumbers[(ctrl << 5) | (aiop << 3) | ch] = nextLineNumber++;
  2788. return (nextLineNumber - 1);
  2789. }