68360serial.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988
  1. /*
  2. * UART driver for 68360 CPM SCC or SMC
  3. * Copyright (c) 2000 D. Jeff Dionne <jeff@uclinux.org>,
  4. * Copyright (c) 2000 Michael Leslie <mleslie@lineo.ca>
  5. * Copyright (c) 1997 Dan Malek <dmalek@jlc.net>
  6. *
  7. * I used the serial.c driver as the framework for this driver.
  8. * Give credit to those guys.
  9. * The original code was written for the MBX860 board. I tried to make
  10. * it generic, but there may be some assumptions in the structures that
  11. * have to be fixed later.
  12. * To save porting time, I did not bother to change any object names
  13. * that are not accessed outside of this file.
  14. * It still needs lots of work........When it was easy, I included code
  15. * to support the SCCs, but this has never been tested, nor is it complete.
  16. * Only the SCCs support modem control, so that is not complete either.
  17. *
  18. * This module exports the following rs232 io functions:
  19. *
  20. * int rs_360_init(void);
  21. */
  22. #include <linux/module.h>
  23. #include <linux/errno.h>
  24. #include <linux/signal.h>
  25. #include <linux/sched.h>
  26. #include <linux/timer.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/tty.h>
  29. #include <linux/tty_flip.h>
  30. #include <linux/serial.h>
  31. #include <linux/serialP.h>
  32. #include <linux/major.h>
  33. #include <linux/string.h>
  34. #include <linux/fcntl.h>
  35. #include <linux/ptrace.h>
  36. #include <linux/mm.h>
  37. #include <linux/init.h>
  38. #include <linux/delay.h>
  39. #include <asm/irq.h>
  40. #include <asm/m68360.h>
  41. #include <asm/commproc.h>
  42. #ifdef CONFIG_KGDB
  43. extern void breakpoint(void);
  44. extern void set_debug_traps(void);
  45. extern int kgdb_output_string (const char* s, unsigned int count);
  46. #endif
  47. /* #ifdef CONFIG_SERIAL_CONSOLE */ /* This seems to be a post 2.0 thing - mles */
  48. #include <linux/console.h>
  49. /* this defines the index into rs_table for the port to use
  50. */
  51. #ifndef CONFIG_SERIAL_CONSOLE_PORT
  52. #define CONFIG_SERIAL_CONSOLE_PORT 1 /* ie SMC2 - note USE_SMC2 must be defined */
  53. #endif
  54. /* #endif */
  55. #if 0
  56. /* SCC2 for console
  57. */
  58. #undef CONFIG_SERIAL_CONSOLE_PORT
  59. #define CONFIG_SERIAL_CONSOLE_PORT 2
  60. #endif
  61. #define TX_WAKEUP ASYNC_SHARE_IRQ
  62. static char *serial_name = "CPM UART driver";
  63. static char *serial_version = "0.03";
  64. static struct tty_driver *serial_driver;
  65. int serial_console_setup(struct console *co, char *options);
  66. /*
  67. * Serial driver configuration section. Here are the various options:
  68. */
  69. #define SERIAL_PARANOIA_CHECK
  70. #define CONFIG_SERIAL_NOPAUSE_IO
  71. #define SERIAL_DO_RESTART
  72. /* Set of debugging defines */
  73. #undef SERIAL_DEBUG_INTR
  74. #undef SERIAL_DEBUG_OPEN
  75. #undef SERIAL_DEBUG_FLOW
  76. #undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
  77. #define _INLINE_ inline
  78. #define DBG_CNT(s)
  79. /* We overload some of the items in the data structure to meet our
  80. * needs. For example, the port address is the CPM parameter ram
  81. * offset for the SCC or SMC. The maximum number of ports is 4 SCCs and
  82. * 2 SMCs. The "hub6" field is used to indicate the channel number, with
  83. * a flag indicating SCC or SMC, and the number is used as an index into
  84. * the CPM parameter area for this device.
  85. * The "type" field is currently set to 0, for PORT_UNKNOWN. It is
  86. * not currently used. I should probably use it to indicate the port
  87. * type of SMC or SCC.
  88. * The SMCs do not support any modem control signals.
  89. */
  90. #define smc_scc_num hub6
  91. #define NUM_IS_SCC ((int)0x00010000)
  92. #define PORT_NUM(P) ((P) & 0x0000ffff)
  93. #if defined (CONFIG_UCQUICC)
  94. volatile extern void *_periph_base;
  95. /* sipex transceiver
  96. * mode bits for are on pins
  97. *
  98. * SCC2 d16..19
  99. * SCC3 d20..23
  100. * SCC4 d24..27
  101. */
  102. #define SIPEX_MODE(n,m) ((m & 0x0f)<<(16+4*(n-1)))
  103. static uint sipex_mode_bits = 0x00000000;
  104. #endif
  105. /* There is no `serial_state' defined back here in 2.0.
  106. * Try to get by with serial_struct
  107. */
  108. /* #define serial_state serial_struct */
  109. /* 2.4 -> 2.0 portability problem: async_icount in 2.4 has a few
  110. * extras: */
  111. #if 0
  112. struct async_icount_24 {
  113. __u32 cts, dsr, rng, dcd, tx, rx;
  114. __u32 frame, parity, overrun, brk;
  115. __u32 buf_overrun;
  116. } icount;
  117. #endif
  118. #if 0
  119. struct serial_state {
  120. int magic;
  121. int baud_base;
  122. unsigned long port;
  123. int irq;
  124. int flags;
  125. int hub6;
  126. int type;
  127. int line;
  128. int revision; /* Chip revision (950) */
  129. int xmit_fifo_size;
  130. int custom_divisor;
  131. int count;
  132. u8 *iomem_base;
  133. u16 iomem_reg_shift;
  134. unsigned short close_delay;
  135. unsigned short closing_wait; /* time to wait before closing */
  136. struct async_icount_24 icount;
  137. int io_type;
  138. struct async_struct *info;
  139. };
  140. #endif
  141. #define SSTATE_MAGIC 0x5302
  142. /* SMC2 is sometimes used for low performance TDM interfaces. Define
  143. * this as 1 if you want SMC2 as a serial port UART managed by this driver.
  144. * Define this as 0 if you wish to use SMC2 for something else.
  145. */
  146. #define USE_SMC2 1
  147. #if 0
  148. /* Define SCC to ttySx mapping. */
  149. #define SCC_NUM_BASE (USE_SMC2 + 1) /* SCC base tty "number" */
  150. /* Define which SCC is the first one to use for a serial port. These
  151. * are 0-based numbers, i.e. this assumes the first SCC (SCC1) is used
  152. * for Ethernet, and the first available SCC for serial UART is SCC2.
  153. * NOTE: IF YOU CHANGE THIS, you have to change the PROFF_xxx and
  154. * interrupt vectors in the table below to match.
  155. */
  156. #define SCC_IDX_BASE 1 /* table index */
  157. #endif
  158. /* Processors other than the 860 only get SMCs configured by default.
  159. * Either they don't have SCCs or they are allocated somewhere else.
  160. * Of course, there are now 860s without some SCCs, so we will need to
  161. * address that someday.
  162. * The Embedded Planet Multimedia I/O cards use TDM interfaces to the
  163. * stereo codec parts, and we use SMC2 to help support that.
  164. */
  165. static struct serial_state rs_table[] = {
  166. /* type line PORT IRQ FLAGS smc_scc_num (F.K.A. hub6) */
  167. { 0, 0, PRSLOT_SMC1, CPMVEC_SMC1, 0, 0 } /* SMC1 ttyS0 */
  168. #if USE_SMC2
  169. ,{ 0, 0, PRSLOT_SMC2, CPMVEC_SMC2, 0, 1 } /* SMC2 ttyS1 */
  170. #endif
  171. #if defined(CONFIG_SERIAL_68360_SCC)
  172. ,{ 0, 0, PRSLOT_SCC2, CPMVEC_SCC2, 0, (NUM_IS_SCC | 1) } /* SCC2 ttyS2 */
  173. ,{ 0, 0, PRSLOT_SCC3, CPMVEC_SCC3, 0, (NUM_IS_SCC | 2) } /* SCC3 ttyS3 */
  174. ,{ 0, 0, PRSLOT_SCC4, CPMVEC_SCC4, 0, (NUM_IS_SCC | 3) } /* SCC4 ttyS4 */
  175. #endif
  176. };
  177. #define NR_PORTS (sizeof(rs_table)/sizeof(struct serial_state))
  178. /* The number of buffer descriptors and their sizes.
  179. */
  180. #define RX_NUM_FIFO 4
  181. #define RX_BUF_SIZE 32
  182. #define TX_NUM_FIFO 4
  183. #define TX_BUF_SIZE 32
  184. #define CONSOLE_NUM_FIFO 2
  185. #define CONSOLE_BUF_SIZE 4
  186. char *console_fifos[CONSOLE_NUM_FIFO * CONSOLE_BUF_SIZE];
  187. /* The async_struct in serial.h does not really give us what we
  188. * need, so define our own here.
  189. */
  190. typedef struct serial_info {
  191. int magic;
  192. int flags;
  193. struct serial_state *state;
  194. /* struct serial_struct *state; */
  195. /* struct async_struct *state; */
  196. struct tty_struct *tty;
  197. int read_status_mask;
  198. int ignore_status_mask;
  199. int timeout;
  200. int line;
  201. int x_char; /* xon/xoff character */
  202. int close_delay;
  203. unsigned short closing_wait;
  204. unsigned short closing_wait2;
  205. unsigned long event;
  206. unsigned long last_active;
  207. int blocked_open; /* # of blocked opens */
  208. struct work_struct tqueue;
  209. struct work_struct tqueue_hangup;
  210. wait_queue_head_t open_wait;
  211. wait_queue_head_t close_wait;
  212. /* CPM Buffer Descriptor pointers.
  213. */
  214. QUICC_BD *rx_bd_base;
  215. QUICC_BD *rx_cur;
  216. QUICC_BD *tx_bd_base;
  217. QUICC_BD *tx_cur;
  218. } ser_info_t;
  219. /* since kmalloc_init() does not get called until much after this initialization: */
  220. static ser_info_t quicc_ser_info[NR_PORTS];
  221. static char rx_buf_pool[NR_PORTS * RX_NUM_FIFO * RX_BUF_SIZE];
  222. static char tx_buf_pool[NR_PORTS * TX_NUM_FIFO * TX_BUF_SIZE];
  223. static void change_speed(ser_info_t *info);
  224. static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout);
  225. static inline int serial_paranoia_check(ser_info_t *info,
  226. char *name, const char *routine)
  227. {
  228. #ifdef SERIAL_PARANOIA_CHECK
  229. static const char *badmagic =
  230. "Warning: bad magic number for serial struct (%s) in %s\n";
  231. static const char *badinfo =
  232. "Warning: null async_struct for (%s) in %s\n";
  233. if (!info) {
  234. printk(badinfo, name, routine);
  235. return 1;
  236. }
  237. if (info->magic != SERIAL_MAGIC) {
  238. printk(badmagic, name, routine);
  239. return 1;
  240. }
  241. #endif
  242. return 0;
  243. }
  244. /*
  245. * This is used to figure out the divisor speeds and the timeouts,
  246. * indexed by the termio value. The generic CPM functions are responsible
  247. * for setting and assigning baud rate generators for us.
  248. */
  249. static int baud_table[] = {
  250. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
  251. 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0 };
  252. /* This sucks. There is a better way: */
  253. #if defined(CONFIG_CONSOLE_9600)
  254. #define CONSOLE_BAUDRATE 9600
  255. #elif defined(CONFIG_CONSOLE_19200)
  256. #define CONSOLE_BAUDRATE 19200
  257. #elif defined(CONFIG_CONSOLE_115200)
  258. #define CONSOLE_BAUDRATE 115200
  259. #else
  260. #warning "console baud rate undefined"
  261. #define CONSOLE_BAUDRATE 9600
  262. #endif
  263. /*
  264. * ------------------------------------------------------------
  265. * rs_stop() and rs_start()
  266. *
  267. * This routines are called before setting or resetting tty->stopped.
  268. * They enable or disable transmitter interrupts, as necessary.
  269. * ------------------------------------------------------------
  270. */
  271. static void rs_360_stop(struct tty_struct *tty)
  272. {
  273. ser_info_t *info = (ser_info_t *)tty->driver_data;
  274. int idx;
  275. unsigned long flags;
  276. volatile struct scc_regs *sccp;
  277. volatile struct smc_regs *smcp;
  278. if (serial_paranoia_check(info, tty->name, "rs_stop"))
  279. return;
  280. local_irq_save(flags);
  281. idx = PORT_NUM(info->state->smc_scc_num);
  282. if (info->state->smc_scc_num & NUM_IS_SCC) {
  283. sccp = &pquicc->scc_regs[idx];
  284. sccp->scc_sccm &= ~UART_SCCM_TX;
  285. } else {
  286. /* smcp = &cpmp->cp_smc[idx]; */
  287. smcp = &pquicc->smc_regs[idx];
  288. smcp->smc_smcm &= ~SMCM_TX;
  289. }
  290. local_irq_restore(flags);
  291. }
  292. static void rs_360_start(struct tty_struct *tty)
  293. {
  294. ser_info_t *info = (ser_info_t *)tty->driver_data;
  295. int idx;
  296. unsigned long flags;
  297. volatile struct scc_regs *sccp;
  298. volatile struct smc_regs *smcp;
  299. if (serial_paranoia_check(info, tty->name, "rs_stop"))
  300. return;
  301. local_irq_save(flags);
  302. idx = PORT_NUM(info->state->smc_scc_num);
  303. if (info->state->smc_scc_num & NUM_IS_SCC) {
  304. sccp = &pquicc->scc_regs[idx];
  305. sccp->scc_sccm |= UART_SCCM_TX;
  306. } else {
  307. smcp = &pquicc->smc_regs[idx];
  308. smcp->smc_smcm |= SMCM_TX;
  309. }
  310. local_irq_restore(flags);
  311. }
  312. /*
  313. * ----------------------------------------------------------------------
  314. *
  315. * Here starts the interrupt handling routines. All of the following
  316. * subroutines are declared as inline and are folded into
  317. * rs_interrupt(). They were separated out for readability's sake.
  318. *
  319. * Note: rs_interrupt() is a "fast" interrupt, which means that it
  320. * runs with interrupts turned off. People who may want to modify
  321. * rs_interrupt() should try to keep the interrupt handler as fast as
  322. * possible. After you are done making modifications, it is not a bad
  323. * idea to do:
  324. *
  325. * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
  326. *
  327. * and look at the resulting assemble code in serial.s.
  328. *
  329. * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
  330. * -----------------------------------------------------------------------
  331. */
  332. static _INLINE_ void receive_chars(ser_info_t *info)
  333. {
  334. struct tty_struct *tty = info->tty;
  335. unsigned char ch, flag, *cp;
  336. /*int ignored = 0;*/
  337. int i;
  338. ushort status;
  339. struct async_icount *icount;
  340. /* struct async_icount_24 *icount; */
  341. volatile QUICC_BD *bdp;
  342. icount = &info->state->icount;
  343. /* Just loop through the closed BDs and copy the characters into
  344. * the buffer.
  345. */
  346. bdp = info->rx_cur;
  347. for (;;) {
  348. if (bdp->status & BD_SC_EMPTY) /* If this one is empty */
  349. break; /* we are all done */
  350. /* The read status mask tell us what we should do with
  351. * incoming characters, especially if errors occur.
  352. * One special case is the use of BD_SC_EMPTY. If
  353. * this is not set, we are supposed to be ignoring
  354. * inputs. In this case, just mark the buffer empty and
  355. * continue.
  356. */
  357. if (!(info->read_status_mask & BD_SC_EMPTY)) {
  358. bdp->status |= BD_SC_EMPTY;
  359. bdp->status &=
  360. ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
  361. if (bdp->status & BD_SC_WRAP)
  362. bdp = info->rx_bd_base;
  363. else
  364. bdp++;
  365. continue;
  366. }
  367. /* Get the number of characters and the buffer pointer.
  368. */
  369. i = bdp->length;
  370. /* cp = (unsigned char *)__va(bdp->buf); */
  371. cp = (char *)bdp->buf;
  372. status = bdp->status;
  373. while (i-- > 0) {
  374. ch = *cp++;
  375. icount->rx++;
  376. #ifdef SERIAL_DEBUG_INTR
  377. printk("DR%02x:%02x...", ch, status);
  378. #endif
  379. flag = TTY_NORMAL;
  380. if (status & (BD_SC_BR | BD_SC_FR |
  381. BD_SC_PR | BD_SC_OV)) {
  382. /*
  383. * For statistics only
  384. */
  385. if (status & BD_SC_BR)
  386. icount->brk++;
  387. else if (status & BD_SC_PR)
  388. icount->parity++;
  389. else if (status & BD_SC_FR)
  390. icount->frame++;
  391. if (status & BD_SC_OV)
  392. icount->overrun++;
  393. /*
  394. * Now check to see if character should be
  395. * ignored, and mask off conditions which
  396. * should be ignored.
  397. if (status & info->ignore_status_mask) {
  398. if (++ignored > 100)
  399. break;
  400. continue;
  401. }
  402. */
  403. status &= info->read_status_mask;
  404. if (status & (BD_SC_BR)) {
  405. #ifdef SERIAL_DEBUG_INTR
  406. printk("handling break....");
  407. #endif
  408. *tty->flip.flag_buf_ptr = TTY_BREAK;
  409. if (info->flags & ASYNC_SAK)
  410. do_SAK(tty);
  411. } else if (status & BD_SC_PR)
  412. flag = TTY_PARITY;
  413. else if (status & BD_SC_FR)
  414. flag = TTY_FRAME;
  415. }
  416. tty_insert_flip_char(tty, ch, flag);
  417. if (status & BD_SC_OV)
  418. /*
  419. * Overrun is special, since it's
  420. * reported immediately, and doesn't
  421. * affect the current character
  422. */
  423. tty_insert_flip_char(tty, 0, TTY_OVERRUN);
  424. }
  425. /* This BD is ready to be used again. Clear status.
  426. * Get next BD.
  427. */
  428. bdp->status |= BD_SC_EMPTY;
  429. bdp->status &= ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
  430. if (bdp->status & BD_SC_WRAP)
  431. bdp = info->rx_bd_base;
  432. else
  433. bdp++;
  434. }
  435. info->rx_cur = (QUICC_BD *)bdp;
  436. tty_schedule_flip(tty);
  437. }
  438. static _INLINE_ void receive_break(ser_info_t *info)
  439. {
  440. struct tty_struct *tty = info->tty;
  441. info->state->icount.brk++;
  442. /* Check to see if there is room in the tty buffer for
  443. * the break. If not, we exit now, losing the break. FIXME
  444. */
  445. tty_insert_flip_char(tty, 0, TTY_BREAK);
  446. tty_schedule_flip(tty);
  447. }
  448. static _INLINE_ void transmit_chars(ser_info_t *info)
  449. {
  450. if ((info->flags & TX_WAKEUP) ||
  451. (info->tty->flags & (1 << TTY_DO_WRITE_WAKEUP))) {
  452. schedule_work(&info->tqueue);
  453. }
  454. #ifdef SERIAL_DEBUG_INTR
  455. printk("THRE...");
  456. #endif
  457. }
  458. #ifdef notdef
  459. /* I need to do this for the SCCs, so it is left as a reminder.
  460. */
  461. static _INLINE_ void check_modem_status(struct async_struct *info)
  462. {
  463. int status;
  464. /* struct async_icount *icount; */
  465. struct async_icount_24 *icount;
  466. status = serial_in(info, UART_MSR);
  467. if (status & UART_MSR_ANY_DELTA) {
  468. icount = &info->state->icount;
  469. /* update input line counters */
  470. if (status & UART_MSR_TERI)
  471. icount->rng++;
  472. if (status & UART_MSR_DDSR)
  473. icount->dsr++;
  474. if (status & UART_MSR_DDCD) {
  475. icount->dcd++;
  476. #ifdef CONFIG_HARD_PPS
  477. if ((info->flags & ASYNC_HARDPPS_CD) &&
  478. (status & UART_MSR_DCD))
  479. hardpps();
  480. #endif
  481. }
  482. if (status & UART_MSR_DCTS)
  483. icount->cts++;
  484. wake_up_interruptible(&info->delta_msr_wait);
  485. }
  486. if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
  487. #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
  488. printk("ttys%d CD now %s...", info->line,
  489. (status & UART_MSR_DCD) ? "on" : "off");
  490. #endif
  491. if (status & UART_MSR_DCD)
  492. wake_up_interruptible(&info->open_wait);
  493. else {
  494. #ifdef SERIAL_DEBUG_OPEN
  495. printk("scheduling hangup...");
  496. #endif
  497. queue_task(&info->tqueue_hangup,
  498. &tq_scheduler);
  499. }
  500. }
  501. if (info->flags & ASYNC_CTS_FLOW) {
  502. if (info->tty->hw_stopped) {
  503. if (status & UART_MSR_CTS) {
  504. #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
  505. printk("CTS tx start...");
  506. #endif
  507. info->tty->hw_stopped = 0;
  508. info->IER |= UART_IER_THRI;
  509. serial_out(info, UART_IER, info->IER);
  510. rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
  511. return;
  512. }
  513. } else {
  514. if (!(status & UART_MSR_CTS)) {
  515. #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
  516. printk("CTS tx stop...");
  517. #endif
  518. info->tty->hw_stopped = 1;
  519. info->IER &= ~UART_IER_THRI;
  520. serial_out(info, UART_IER, info->IER);
  521. }
  522. }
  523. }
  524. }
  525. #endif
  526. /*
  527. * This is the serial driver's interrupt routine for a single port
  528. */
  529. /* static void rs_360_interrupt(void *dev_id) */ /* until and if we start servicing irqs here */
  530. static void rs_360_interrupt(int vec, void *dev_id)
  531. {
  532. u_char events;
  533. int idx;
  534. ser_info_t *info;
  535. volatile struct smc_regs *smcp;
  536. volatile struct scc_regs *sccp;
  537. info = dev_id;
  538. idx = PORT_NUM(info->state->smc_scc_num);
  539. if (info->state->smc_scc_num & NUM_IS_SCC) {
  540. sccp = &pquicc->scc_regs[idx];
  541. events = sccp->scc_scce;
  542. if (events & SCCM_RX)
  543. receive_chars(info);
  544. if (events & SCCM_TX)
  545. transmit_chars(info);
  546. sccp->scc_scce = events;
  547. } else {
  548. smcp = &pquicc->smc_regs[idx];
  549. events = smcp->smc_smce;
  550. if (events & SMCM_BRKE)
  551. receive_break(info);
  552. if (events & SMCM_RX)
  553. receive_chars(info);
  554. if (events & SMCM_TX)
  555. transmit_chars(info);
  556. smcp->smc_smce = events;
  557. }
  558. #ifdef SERIAL_DEBUG_INTR
  559. printk("rs_interrupt_single(%d, %x)...",
  560. info->state->smc_scc_num, events);
  561. #endif
  562. #ifdef modem_control
  563. check_modem_status(info);
  564. #endif
  565. info->last_active = jiffies;
  566. #ifdef SERIAL_DEBUG_INTR
  567. printk("end.\n");
  568. #endif
  569. }
  570. /*
  571. * -------------------------------------------------------------------
  572. * Here ends the serial interrupt routines.
  573. * -------------------------------------------------------------------
  574. */
  575. static void do_softint(void *private_)
  576. {
  577. ser_info_t *info = (ser_info_t *) private_;
  578. struct tty_struct *tty;
  579. tty = info->tty;
  580. if (!tty)
  581. return;
  582. if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event))
  583. tty_wakeup(tty);
  584. }
  585. /*
  586. * This routine is called from the scheduler tqueue when the interrupt
  587. * routine has signalled that a hangup has occurred. The path of
  588. * hangup processing is:
  589. *
  590. * serial interrupt routine -> (scheduler tqueue) ->
  591. * do_serial_hangup() -> tty->hangup() -> rs_hangup()
  592. *
  593. */
  594. static void do_serial_hangup(void *private_)
  595. {
  596. struct async_struct *info = (struct async_struct *) private_;
  597. struct tty_struct *tty;
  598. tty = info->tty;
  599. if (!tty)
  600. return;
  601. tty_hangup(tty);
  602. }
  603. static int startup(ser_info_t *info)
  604. {
  605. unsigned long flags;
  606. int retval=0;
  607. int idx;
  608. /*struct serial_state *state = info->state;*/
  609. volatile struct smc_regs *smcp;
  610. volatile struct scc_regs *sccp;
  611. volatile struct smc_uart_pram *up;
  612. volatile struct uart_pram *scup;
  613. local_irq_save(flags);
  614. if (info->flags & ASYNC_INITIALIZED) {
  615. goto errout;
  616. }
  617. #ifdef maybe
  618. if (!state->port || !state->type) {
  619. if (info->tty)
  620. set_bit(TTY_IO_ERROR, &info->tty->flags);
  621. goto errout;
  622. }
  623. #endif
  624. #ifdef SERIAL_DEBUG_OPEN
  625. printk("starting up ttys%d (irq %d)...", info->line, state->irq);
  626. #endif
  627. #ifdef modem_control
  628. info->MCR = 0;
  629. if (info->tty->termios->c_cflag & CBAUD)
  630. info->MCR = UART_MCR_DTR | UART_MCR_RTS;
  631. #endif
  632. if (info->tty)
  633. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  634. /*
  635. * and set the speed of the serial port
  636. */
  637. change_speed(info);
  638. idx = PORT_NUM(info->state->smc_scc_num);
  639. if (info->state->smc_scc_num & NUM_IS_SCC) {
  640. sccp = &pquicc->scc_regs[idx];
  641. scup = &pquicc->pram[info->state->port].scc.pscc.u;
  642. scup->mrblr = RX_BUF_SIZE;
  643. scup->max_idl = RX_BUF_SIZE;
  644. sccp->scc_sccm |= (UART_SCCM_TX | UART_SCCM_RX);
  645. sccp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  646. } else {
  647. smcp = &pquicc->smc_regs[idx];
  648. /* Enable interrupts and I/O.
  649. */
  650. smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
  651. smcp->smc_smcmr |= (SMCMR_REN | SMCMR_TEN);
  652. /* We can tune the buffer length and idle characters
  653. * to take advantage of the entire incoming buffer size.
  654. * If mrblr is something other than 1, maxidl has to be
  655. * non-zero or we never get an interrupt. The maxidl
  656. * is the number of character times we wait after reception
  657. * of the last character before we decide no more characters
  658. * are coming.
  659. */
  660. /* up = (smc_uart_t *)&pquicc->cp_dparam[state->port]; */
  661. /* holy unionized structures, Batman: */
  662. up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;
  663. up->mrblr = RX_BUF_SIZE;
  664. up->max_idl = RX_BUF_SIZE;
  665. up->brkcr = 1; /* number of break chars */
  666. }
  667. info->flags |= ASYNC_INITIALIZED;
  668. local_irq_restore(flags);
  669. return 0;
  670. errout:
  671. local_irq_restore(flags);
  672. return retval;
  673. }
  674. /*
  675. * This routine will shutdown a serial port; interrupts are disabled, and
  676. * DTR is dropped if the hangup on close termio flag is on.
  677. */
  678. static void shutdown(ser_info_t *info)
  679. {
  680. unsigned long flags;
  681. struct serial_state *state;
  682. int idx;
  683. volatile struct smc_regs *smcp;
  684. volatile struct scc_regs *sccp;
  685. if (!(info->flags & ASYNC_INITIALIZED))
  686. return;
  687. state = info->state;
  688. #ifdef SERIAL_DEBUG_OPEN
  689. printk("Shutting down serial port %d (irq %d)....", info->line,
  690. state->irq);
  691. #endif
  692. local_irq_save(flags);
  693. idx = PORT_NUM(state->smc_scc_num);
  694. if (state->smc_scc_num & NUM_IS_SCC) {
  695. sccp = &pquicc->scc_regs[idx];
  696. sccp->scc_gsmr.w.low &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  697. #ifdef CONFIG_SERIAL_CONSOLE
  698. /* We can't disable the transmitter if this is the
  699. * system console.
  700. */
  701. if ((state - rs_table) != CONFIG_SERIAL_CONSOLE_PORT)
  702. #endif
  703. sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
  704. } else {
  705. smcp = &pquicc->smc_regs[idx];
  706. /* Disable interrupts and I/O.
  707. */
  708. smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
  709. #ifdef CONFIG_SERIAL_CONSOLE
  710. /* We can't disable the transmitter if this is the
  711. * system console.
  712. */
  713. if ((state - rs_table) != CONFIG_SERIAL_CONSOLE_PORT)
  714. #endif
  715. smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  716. }
  717. if (info->tty)
  718. set_bit(TTY_IO_ERROR, &info->tty->flags);
  719. info->flags &= ~ASYNC_INITIALIZED;
  720. local_irq_restore(flags);
  721. }
  722. /*
  723. * This routine is called to set the UART divisor registers to match
  724. * the specified baud rate for a serial port.
  725. */
  726. static void change_speed(ser_info_t *info)
  727. {
  728. int baud_rate;
  729. unsigned cflag, cval, scval, prev_mode;
  730. int i, bits, sbits, idx;
  731. unsigned long flags;
  732. struct serial_state *state;
  733. volatile struct smc_regs *smcp;
  734. volatile struct scc_regs *sccp;
  735. if (!info->tty || !info->tty->termios)
  736. return;
  737. cflag = info->tty->termios->c_cflag;
  738. state = info->state;
  739. /* Character length programmed into the mode register is the
  740. * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
  741. * 1 or 2 stop bits, minus 1.
  742. * The value 'bits' counts this for us.
  743. */
  744. cval = 0;
  745. scval = 0;
  746. /* byte size and parity */
  747. switch (cflag & CSIZE) {
  748. case CS5: bits = 5; break;
  749. case CS6: bits = 6; break;
  750. case CS7: bits = 7; break;
  751. case CS8: bits = 8; break;
  752. /* Never happens, but GCC is too dumb to figure it out */
  753. default: bits = 8; break;
  754. }
  755. sbits = bits - 5;
  756. if (cflag & CSTOPB) {
  757. cval |= SMCMR_SL; /* Two stops */
  758. scval |= SCU_PMSR_SL;
  759. bits++;
  760. }
  761. if (cflag & PARENB) {
  762. cval |= SMCMR_PEN;
  763. scval |= SCU_PMSR_PEN;
  764. bits++;
  765. }
  766. if (!(cflag & PARODD)) {
  767. cval |= SMCMR_PM_EVEN;
  768. scval |= (SCU_PMSR_REVP | SCU_PMSR_TEVP);
  769. }
  770. /* Determine divisor based on baud rate */
  771. i = cflag & CBAUD;
  772. if (i >= (sizeof(baud_table)/sizeof(int)))
  773. baud_rate = 9600;
  774. else
  775. baud_rate = baud_table[i];
  776. info->timeout = (TX_BUF_SIZE*HZ*bits);
  777. info->timeout += HZ/50; /* Add .02 seconds of slop */
  778. #ifdef modem_control
  779. /* CTS flow control flag and modem status interrupts */
  780. info->IER &= ~UART_IER_MSI;
  781. if (info->flags & ASYNC_HARDPPS_CD)
  782. info->IER |= UART_IER_MSI;
  783. if (cflag & CRTSCTS) {
  784. info->flags |= ASYNC_CTS_FLOW;
  785. info->IER |= UART_IER_MSI;
  786. } else
  787. info->flags &= ~ASYNC_CTS_FLOW;
  788. if (cflag & CLOCAL)
  789. info->flags &= ~ASYNC_CHECK_CD;
  790. else {
  791. info->flags |= ASYNC_CHECK_CD;
  792. info->IER |= UART_IER_MSI;
  793. }
  794. serial_out(info, UART_IER, info->IER);
  795. #endif
  796. /*
  797. * Set up parity check flag
  798. */
  799. info->read_status_mask = (BD_SC_EMPTY | BD_SC_OV);
  800. if (I_INPCK(info->tty))
  801. info->read_status_mask |= BD_SC_FR | BD_SC_PR;
  802. if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
  803. info->read_status_mask |= BD_SC_BR;
  804. /*
  805. * Characters to ignore
  806. */
  807. info->ignore_status_mask = 0;
  808. if (I_IGNPAR(info->tty))
  809. info->ignore_status_mask |= BD_SC_PR | BD_SC_FR;
  810. if (I_IGNBRK(info->tty)) {
  811. info->ignore_status_mask |= BD_SC_BR;
  812. /*
  813. * If we're ignore parity and break indicators, ignore
  814. * overruns too. (For real raw support).
  815. */
  816. if (I_IGNPAR(info->tty))
  817. info->ignore_status_mask |= BD_SC_OV;
  818. }
  819. /*
  820. * !!! ignore all characters if CREAD is not set
  821. */
  822. if ((cflag & CREAD) == 0)
  823. info->read_status_mask &= ~BD_SC_EMPTY;
  824. local_irq_save(flags);
  825. /* Start bit has not been added (so don't, because we would just
  826. * subtract it later), and we need to add one for the number of
  827. * stops bits (there is always at least one).
  828. */
  829. bits++;
  830. idx = PORT_NUM(state->smc_scc_num);
  831. if (state->smc_scc_num & NUM_IS_SCC) {
  832. sccp = &pquicc->scc_regs[idx];
  833. sccp->scc_psmr = (sbits << 12) | scval;
  834. } else {
  835. smcp = &pquicc->smc_regs[idx];
  836. /* Set the mode register. We want to keep a copy of the
  837. * enables, because we want to put them back if they were
  838. * present.
  839. */
  840. prev_mode = smcp->smc_smcmr;
  841. smcp->smc_smcmr = smcr_mk_clen(bits) | cval | SMCMR_SM_UART;
  842. smcp->smc_smcmr |= (prev_mode & (SMCMR_REN | SMCMR_TEN));
  843. }
  844. m360_cpm_setbrg((state - rs_table), baud_rate);
  845. local_irq_restore(flags);
  846. }
  847. static void rs_360_put_char(struct tty_struct *tty, unsigned char ch)
  848. {
  849. ser_info_t *info = (ser_info_t *)tty->driver_data;
  850. volatile QUICC_BD *bdp;
  851. if (serial_paranoia_check(info, tty->name, "rs_put_char"))
  852. return;
  853. if (!tty)
  854. return;
  855. bdp = info->tx_cur;
  856. while (bdp->status & BD_SC_READY);
  857. /* *((char *)__va(bdp->buf)) = ch; */
  858. *((char *)bdp->buf) = ch;
  859. bdp->length = 1;
  860. bdp->status |= BD_SC_READY;
  861. /* Get next BD.
  862. */
  863. if (bdp->status & BD_SC_WRAP)
  864. bdp = info->tx_bd_base;
  865. else
  866. bdp++;
  867. info->tx_cur = (QUICC_BD *)bdp;
  868. }
  869. static int rs_360_write(struct tty_struct * tty,
  870. const unsigned char *buf, int count)
  871. {
  872. int c, ret = 0;
  873. ser_info_t *info = (ser_info_t *)tty->driver_data;
  874. volatile QUICC_BD *bdp;
  875. #ifdef CONFIG_KGDB
  876. /* Try to let stub handle output. Returns true if it did. */
  877. if (kgdb_output_string(buf, count))
  878. return ret;
  879. #endif
  880. if (serial_paranoia_check(info, tty->name, "rs_write"))
  881. return 0;
  882. if (!tty)
  883. return 0;
  884. bdp = info->tx_cur;
  885. while (1) {
  886. c = min(count, TX_BUF_SIZE);
  887. if (c <= 0)
  888. break;
  889. if (bdp->status & BD_SC_READY) {
  890. info->flags |= TX_WAKEUP;
  891. break;
  892. }
  893. /* memcpy(__va(bdp->buf), buf, c); */
  894. memcpy((void *)bdp->buf, buf, c);
  895. bdp->length = c;
  896. bdp->status |= BD_SC_READY;
  897. buf += c;
  898. count -= c;
  899. ret += c;
  900. /* Get next BD.
  901. */
  902. if (bdp->status & BD_SC_WRAP)
  903. bdp = info->tx_bd_base;
  904. else
  905. bdp++;
  906. info->tx_cur = (QUICC_BD *)bdp;
  907. }
  908. return ret;
  909. }
  910. static int rs_360_write_room(struct tty_struct *tty)
  911. {
  912. ser_info_t *info = (ser_info_t *)tty->driver_data;
  913. int ret;
  914. if (serial_paranoia_check(info, tty->name, "rs_write_room"))
  915. return 0;
  916. if ((info->tx_cur->status & BD_SC_READY) == 0) {
  917. info->flags &= ~TX_WAKEUP;
  918. ret = TX_BUF_SIZE;
  919. }
  920. else {
  921. info->flags |= TX_WAKEUP;
  922. ret = 0;
  923. }
  924. return ret;
  925. }
  926. /* I could track this with transmit counters....maybe later.
  927. */
  928. static int rs_360_chars_in_buffer(struct tty_struct *tty)
  929. {
  930. ser_info_t *info = (ser_info_t *)tty->driver_data;
  931. if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
  932. return 0;
  933. return 0;
  934. }
  935. static void rs_360_flush_buffer(struct tty_struct *tty)
  936. {
  937. ser_info_t *info = (ser_info_t *)tty->driver_data;
  938. if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
  939. return;
  940. /* There is nothing to "flush", whatever we gave the CPM
  941. * is on its way out.
  942. */
  943. tty_wakeup(tty);
  944. info->flags &= ~TX_WAKEUP;
  945. }
  946. /*
  947. * This function is used to send a high-priority XON/XOFF character to
  948. * the device
  949. */
  950. static void rs_360_send_xchar(struct tty_struct *tty, char ch)
  951. {
  952. volatile QUICC_BD *bdp;
  953. ser_info_t *info = (ser_info_t *)tty->driver_data;
  954. if (serial_paranoia_check(info, tty->name, "rs_send_char"))
  955. return;
  956. bdp = info->tx_cur;
  957. while (bdp->status & BD_SC_READY);
  958. /* *((char *)__va(bdp->buf)) = ch; */
  959. *((char *)bdp->buf) = ch;
  960. bdp->length = 1;
  961. bdp->status |= BD_SC_READY;
  962. /* Get next BD.
  963. */
  964. if (bdp->status & BD_SC_WRAP)
  965. bdp = info->tx_bd_base;
  966. else
  967. bdp++;
  968. info->tx_cur = (QUICC_BD *)bdp;
  969. }
  970. /*
  971. * ------------------------------------------------------------
  972. * rs_throttle()
  973. *
  974. * This routine is called by the upper-layer tty layer to signal that
  975. * incoming characters should be throttled.
  976. * ------------------------------------------------------------
  977. */
  978. static void rs_360_throttle(struct tty_struct * tty)
  979. {
  980. ser_info_t *info = (ser_info_t *)tty->driver_data;
  981. #ifdef SERIAL_DEBUG_THROTTLE
  982. char buf[64];
  983. printk("throttle %s: %d....\n", _tty_name(tty, buf),
  984. tty->ldisc.chars_in_buffer(tty));
  985. #endif
  986. if (serial_paranoia_check(info, tty->name, "rs_throttle"))
  987. return;
  988. if (I_IXOFF(tty))
  989. rs_360_send_xchar(tty, STOP_CHAR(tty));
  990. #ifdef modem_control
  991. if (tty->termios->c_cflag & CRTSCTS)
  992. info->MCR &= ~UART_MCR_RTS;
  993. local_irq_disable();
  994. serial_out(info, UART_MCR, info->MCR);
  995. local_irq_enable();
  996. #endif
  997. }
  998. static void rs_360_unthrottle(struct tty_struct * tty)
  999. {
  1000. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1001. #ifdef SERIAL_DEBUG_THROTTLE
  1002. char buf[64];
  1003. printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
  1004. tty->ldisc.chars_in_buffer(tty));
  1005. #endif
  1006. if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
  1007. return;
  1008. if (I_IXOFF(tty)) {
  1009. if (info->x_char)
  1010. info->x_char = 0;
  1011. else
  1012. rs_360_send_xchar(tty, START_CHAR(tty));
  1013. }
  1014. #ifdef modem_control
  1015. if (tty->termios->c_cflag & CRTSCTS)
  1016. info->MCR |= UART_MCR_RTS;
  1017. local_irq_disable();
  1018. serial_out(info, UART_MCR, info->MCR);
  1019. local_irq_enable();
  1020. #endif
  1021. }
  1022. /*
  1023. * ------------------------------------------------------------
  1024. * rs_ioctl() and friends
  1025. * ------------------------------------------------------------
  1026. */
  1027. #ifdef maybe
  1028. /*
  1029. * get_lsr_info - get line status register info
  1030. *
  1031. * Purpose: Let user call ioctl() to get info when the UART physically
  1032. * is emptied. On bus types like RS485, the transmitter must
  1033. * release the bus after transmitting. This must be done when
  1034. * the transmit shift register is empty, not be done when the
  1035. * transmit holding register is empty. This functionality
  1036. * allows an RS485 driver to be written in user space.
  1037. */
  1038. static int get_lsr_info(struct async_struct * info, unsigned int *value)
  1039. {
  1040. unsigned char status;
  1041. unsigned int result;
  1042. local_irq_disable();
  1043. status = serial_in(info, UART_LSR);
  1044. local_irq_enable();
  1045. result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
  1046. return put_user(result,value);
  1047. }
  1048. #endif
  1049. static int rs_360_tiocmget(struct tty_struct *tty, struct file *file)
  1050. {
  1051. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1052. unsigned int result = 0;
  1053. #ifdef modem_control
  1054. unsigned char control, status;
  1055. if (serial_paranoia_check(info, tty->name, __FUNCTION__))
  1056. return -ENODEV;
  1057. if (tty->flags & (1 << TTY_IO_ERROR))
  1058. return -EIO;
  1059. control = info->MCR;
  1060. local_irq_disable();
  1061. status = serial_in(info, UART_MSR);
  1062. local_irq_enable();
  1063. result = ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
  1064. | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
  1065. #ifdef TIOCM_OUT1
  1066. | ((control & UART_MCR_OUT1) ? TIOCM_OUT1 : 0)
  1067. | ((control & UART_MCR_OUT2) ? TIOCM_OUT2 : 0)
  1068. #endif
  1069. | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
  1070. | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
  1071. | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
  1072. | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
  1073. #endif
  1074. return result;
  1075. }
  1076. static int rs_360_tiocmset(struct tty_struct *tty, struct file *file,
  1077. unsigned int set, unsigned int clear)
  1078. {
  1079. #ifdef modem_control
  1080. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1081. unsigned int arg;
  1082. if (serial_paranoia_check(info, tty->name, __FUNCTION__))
  1083. return -ENODEV;
  1084. if (tty->flags & (1 << TTY_IO_ERROR))
  1085. return -EIO;
  1086. if (set & TIOCM_RTS)
  1087. info->mcr |= UART_MCR_RTS;
  1088. if (set & TIOCM_DTR)
  1089. info->mcr |= UART_MCR_DTR;
  1090. if (clear & TIOCM_RTS)
  1091. info->MCR &= ~UART_MCR_RTS;
  1092. if (clear & TIOCM_DTR)
  1093. info->MCR &= ~UART_MCR_DTR;
  1094. #ifdef TIOCM_OUT1
  1095. if (set & TIOCM_OUT1)
  1096. info->MCR |= UART_MCR_OUT1;
  1097. if (set & TIOCM_OUT2)
  1098. info->MCR |= UART_MCR_OUT2;
  1099. if (clear & TIOCM_OUT1)
  1100. info->MCR &= ~UART_MCR_OUT1;
  1101. if (clear & TIOCM_OUT2)
  1102. info->MCR &= ~UART_MCR_OUT2;
  1103. #endif
  1104. local_irq_disable();
  1105. serial_out(info, UART_MCR, info->MCR);
  1106. local_irq_enable();
  1107. #endif
  1108. return 0;
  1109. }
  1110. /* Sending a break is a two step process on the SMC/SCC. It is accomplished
  1111. * by sending a STOP TRANSMIT command followed by a RESTART TRANSMIT
  1112. * command. We take advantage of the begin/end functions to make this
  1113. * happen.
  1114. */
  1115. static ushort smc_chan_map[] = {
  1116. CPM_CR_CH_SMC1,
  1117. CPM_CR_CH_SMC2
  1118. };
  1119. static ushort scc_chan_map[] = {
  1120. CPM_CR_CH_SCC1,
  1121. CPM_CR_CH_SCC2,
  1122. CPM_CR_CH_SCC3,
  1123. CPM_CR_CH_SCC4
  1124. };
  1125. static void begin_break(ser_info_t *info)
  1126. {
  1127. volatile QUICC *cp;
  1128. ushort chan;
  1129. int idx;
  1130. cp = pquicc;
  1131. idx = PORT_NUM(info->state->smc_scc_num);
  1132. if (info->state->smc_scc_num & NUM_IS_SCC)
  1133. chan = scc_chan_map[idx];
  1134. else
  1135. chan = smc_chan_map[idx];
  1136. cp->cp_cr = mk_cr_cmd(chan, CPM_CR_STOP_TX) | CPM_CR_FLG;
  1137. while (cp->cp_cr & CPM_CR_FLG);
  1138. }
  1139. static void end_break(ser_info_t *info)
  1140. {
  1141. volatile QUICC *cp;
  1142. ushort chan;
  1143. int idx;
  1144. cp = pquicc;
  1145. idx = PORT_NUM(info->state->smc_scc_num);
  1146. if (info->state->smc_scc_num & NUM_IS_SCC)
  1147. chan = scc_chan_map[idx];
  1148. else
  1149. chan = smc_chan_map[idx];
  1150. cp->cp_cr = mk_cr_cmd(chan, CPM_CR_RESTART_TX) | CPM_CR_FLG;
  1151. while (cp->cp_cr & CPM_CR_FLG);
  1152. }
  1153. /*
  1154. * This routine sends a break character out the serial port.
  1155. */
  1156. static void send_break(ser_info_t *info, unsigned int duration)
  1157. {
  1158. #ifdef SERIAL_DEBUG_SEND_BREAK
  1159. printk("rs_send_break(%d) jiff=%lu...", duration, jiffies);
  1160. #endif
  1161. begin_break(info);
  1162. msleep_interruptible(duration);
  1163. end_break(info);
  1164. #ifdef SERIAL_DEBUG_SEND_BREAK
  1165. printk("done jiffies=%lu\n", jiffies);
  1166. #endif
  1167. }
  1168. static int rs_360_ioctl(struct tty_struct *tty, struct file * file,
  1169. unsigned int cmd, unsigned long arg)
  1170. {
  1171. int error;
  1172. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1173. int retval;
  1174. struct async_icount cnow;
  1175. /* struct async_icount_24 cnow;*/ /* kernel counter temps */
  1176. struct serial_icounter_struct *p_cuser; /* user space */
  1177. if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
  1178. return -ENODEV;
  1179. if ((cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
  1180. if (tty->flags & (1 << TTY_IO_ERROR))
  1181. return -EIO;
  1182. }
  1183. switch (cmd) {
  1184. case TCSBRK: /* SVID version: non-zero arg --> no break */
  1185. retval = tty_check_change(tty);
  1186. if (retval)
  1187. return retval;
  1188. tty_wait_until_sent(tty, 0);
  1189. if (signal_pending(current))
  1190. return -EINTR;
  1191. if (!arg) {
  1192. send_break(info, 250); /* 1/4 second */
  1193. if (signal_pending(current))
  1194. return -EINTR;
  1195. }
  1196. return 0;
  1197. case TCSBRKP: /* support for POSIX tcsendbreak() */
  1198. retval = tty_check_change(tty);
  1199. if (retval)
  1200. return retval;
  1201. tty_wait_until_sent(tty, 0);
  1202. if (signal_pending(current))
  1203. return -EINTR;
  1204. send_break(info, arg ? arg*100 : 250);
  1205. if (signal_pending(current))
  1206. return -EINTR;
  1207. return 0;
  1208. case TIOCSBRK:
  1209. retval = tty_check_change(tty);
  1210. if (retval)
  1211. return retval;
  1212. tty_wait_until_sent(tty, 0);
  1213. begin_break(info);
  1214. return 0;
  1215. case TIOCCBRK:
  1216. retval = tty_check_change(tty);
  1217. if (retval)
  1218. return retval;
  1219. end_break(info);
  1220. return 0;
  1221. case TIOCGSOFTCAR:
  1222. /* return put_user(C_CLOCAL(tty) ? 1 : 0, (int *) arg); */
  1223. put_user(C_CLOCAL(tty) ? 1 : 0, (int *) arg);
  1224. return 0;
  1225. case TIOCSSOFTCAR:
  1226. error = get_user(arg, (unsigned int *) arg);
  1227. if (error)
  1228. return error;
  1229. tty->termios->c_cflag =
  1230. ((tty->termios->c_cflag & ~CLOCAL) |
  1231. (arg ? CLOCAL : 0));
  1232. return 0;
  1233. #ifdef maybe
  1234. case TIOCSERGETLSR: /* Get line status register */
  1235. return get_lsr_info(info, (unsigned int *) arg);
  1236. #endif
  1237. /*
  1238. * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
  1239. * - mask passed in arg for lines of interest
  1240. * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
  1241. * Caller should use TIOCGICOUNT to see which one it was
  1242. */
  1243. case TIOCMIWAIT:
  1244. #ifdef modem_control
  1245. local_irq_disable();
  1246. /* note the counters on entry */
  1247. cprev = info->state->icount;
  1248. local_irq_enable();
  1249. while (1) {
  1250. interruptible_sleep_on(&info->delta_msr_wait);
  1251. /* see if a signal did it */
  1252. if (signal_pending(current))
  1253. return -ERESTARTSYS;
  1254. local_irq_disable();
  1255. cnow = info->state->icount; /* atomic copy */
  1256. local_irq_enable();
  1257. if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
  1258. cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
  1259. return -EIO; /* no change => error */
  1260. if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
  1261. ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
  1262. ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
  1263. ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
  1264. return 0;
  1265. }
  1266. cprev = cnow;
  1267. }
  1268. /* NOTREACHED */
  1269. #else
  1270. return 0;
  1271. #endif
  1272. /*
  1273. * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
  1274. * Return: write counters to the user passed counter struct
  1275. * NB: both 1->0 and 0->1 transitions are counted except for
  1276. * RI where only 0->1 is counted.
  1277. */
  1278. case TIOCGICOUNT:
  1279. local_irq_disable();
  1280. cnow = info->state->icount;
  1281. local_irq_enable();
  1282. p_cuser = (struct serial_icounter_struct *) arg;
  1283. /* error = put_user(cnow.cts, &p_cuser->cts); */
  1284. /* if (error) return error; */
  1285. /* error = put_user(cnow.dsr, &p_cuser->dsr); */
  1286. /* if (error) return error; */
  1287. /* error = put_user(cnow.rng, &p_cuser->rng); */
  1288. /* if (error) return error; */
  1289. /* error = put_user(cnow.dcd, &p_cuser->dcd); */
  1290. /* if (error) return error; */
  1291. put_user(cnow.cts, &p_cuser->cts);
  1292. put_user(cnow.dsr, &p_cuser->dsr);
  1293. put_user(cnow.rng, &p_cuser->rng);
  1294. put_user(cnow.dcd, &p_cuser->dcd);
  1295. return 0;
  1296. default:
  1297. return -ENOIOCTLCMD;
  1298. }
  1299. return 0;
  1300. }
  1301. /* FIX UP modem control here someday......
  1302. */
  1303. static void rs_360_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
  1304. {
  1305. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1306. change_speed(info);
  1307. #ifdef modem_control
  1308. /* Handle transition to B0 status */
  1309. if ((old_termios->c_cflag & CBAUD) &&
  1310. !(tty->termios->c_cflag & CBAUD)) {
  1311. info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
  1312. local_irq_disable();
  1313. serial_out(info, UART_MCR, info->MCR);
  1314. local_irq_enable();
  1315. }
  1316. /* Handle transition away from B0 status */
  1317. if (!(old_termios->c_cflag & CBAUD) &&
  1318. (tty->termios->c_cflag & CBAUD)) {
  1319. info->MCR |= UART_MCR_DTR;
  1320. if (!tty->hw_stopped ||
  1321. !(tty->termios->c_cflag & CRTSCTS)) {
  1322. info->MCR |= UART_MCR_RTS;
  1323. }
  1324. local_irq_disable();
  1325. serial_out(info, UART_MCR, info->MCR);
  1326. local_irq_enable();
  1327. }
  1328. /* Handle turning off CRTSCTS */
  1329. if ((old_termios->c_cflag & CRTSCTS) &&
  1330. !(tty->termios->c_cflag & CRTSCTS)) {
  1331. tty->hw_stopped = 0;
  1332. rs_360_start(tty);
  1333. }
  1334. #endif
  1335. #if 0
  1336. /*
  1337. * No need to wake up processes in open wait, since they
  1338. * sample the CLOCAL flag once, and don't recheck it.
  1339. * XXX It's not clear whether the current behavior is correct
  1340. * or not. Hence, this may change.....
  1341. */
  1342. if (!(old_termios->c_cflag & CLOCAL) &&
  1343. (tty->termios->c_cflag & CLOCAL))
  1344. wake_up_interruptible(&info->open_wait);
  1345. #endif
  1346. }
  1347. /*
  1348. * ------------------------------------------------------------
  1349. * rs_close()
  1350. *
  1351. * This routine is called when the serial port gets closed. First, we
  1352. * wait for the last remaining data to be sent. Then, we unlink its
  1353. * async structure from the interrupt chain if necessary, and we free
  1354. * that IRQ if nothing is left in the chain.
  1355. * ------------------------------------------------------------
  1356. */
  1357. static void rs_360_close(struct tty_struct *tty, struct file * filp)
  1358. {
  1359. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1360. /* struct async_state *state; */
  1361. struct serial_state *state;
  1362. unsigned long flags;
  1363. int idx;
  1364. volatile struct smc_regs *smcp;
  1365. volatile struct scc_regs *sccp;
  1366. if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
  1367. return;
  1368. state = info->state;
  1369. local_irq_save(flags);
  1370. if (tty_hung_up_p(filp)) {
  1371. DBG_CNT("before DEC-hung");
  1372. local_irq_restore(flags);
  1373. return;
  1374. }
  1375. #ifdef SERIAL_DEBUG_OPEN
  1376. printk("rs_close ttys%d, count = %d\n", info->line, state->count);
  1377. #endif
  1378. if ((tty->count == 1) && (state->count != 1)) {
  1379. /*
  1380. * Uh, oh. tty->count is 1, which means that the tty
  1381. * structure will be freed. state->count should always
  1382. * be one in these conditions. If it's greater than
  1383. * one, we've got real problems, since it means the
  1384. * serial port won't be shutdown.
  1385. */
  1386. printk("rs_close: bad serial port count; tty->count is 1, "
  1387. "state->count is %d\n", state->count);
  1388. state->count = 1;
  1389. }
  1390. if (--state->count < 0) {
  1391. printk("rs_close: bad serial port count for ttys%d: %d\n",
  1392. info->line, state->count);
  1393. state->count = 0;
  1394. }
  1395. if (state->count) {
  1396. DBG_CNT("before DEC-2");
  1397. local_irq_restore(flags);
  1398. return;
  1399. }
  1400. info->flags |= ASYNC_CLOSING;
  1401. /*
  1402. * Now we wait for the transmit buffer to clear; and we notify
  1403. * the line discipline to only process XON/XOFF characters.
  1404. */
  1405. tty->closing = 1;
  1406. if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  1407. tty_wait_until_sent(tty, info->closing_wait);
  1408. /*
  1409. * At this point we stop accepting input. To do this, we
  1410. * disable the receive line status interrupts, and tell the
  1411. * interrupt driver to stop checking the data ready bit in the
  1412. * line status register.
  1413. */
  1414. info->read_status_mask &= ~BD_SC_EMPTY;
  1415. if (info->flags & ASYNC_INITIALIZED) {
  1416. idx = PORT_NUM(info->state->smc_scc_num);
  1417. if (info->state->smc_scc_num & NUM_IS_SCC) {
  1418. sccp = &pquicc->scc_regs[idx];
  1419. sccp->scc_sccm &= ~UART_SCCM_RX;
  1420. sccp->scc_gsmr.w.low &= ~SCC_GSMRL_ENR;
  1421. } else {
  1422. smcp = &pquicc->smc_regs[idx];
  1423. smcp->smc_smcm &= ~SMCM_RX;
  1424. smcp->smc_smcmr &= ~SMCMR_REN;
  1425. }
  1426. /*
  1427. * Before we drop DTR, make sure the UART transmitter
  1428. * has completely drained; this is especially
  1429. * important if there is a transmit FIFO!
  1430. */
  1431. rs_360_wait_until_sent(tty, info->timeout);
  1432. }
  1433. shutdown(info);
  1434. if (tty->driver->flush_buffer)
  1435. tty->driver->flush_buffer(tty);
  1436. tty_ldisc_flush(tty);
  1437. tty->closing = 0;
  1438. info->event = 0;
  1439. info->tty = 0;
  1440. if (info->blocked_open) {
  1441. if (info->close_delay) {
  1442. msleep_interruptible(jiffies_to_msecs(info->close_delay));
  1443. }
  1444. wake_up_interruptible(&info->open_wait);
  1445. }
  1446. info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  1447. wake_up_interruptible(&info->close_wait);
  1448. local_irq_restore(flags);
  1449. }
  1450. /*
  1451. * rs_wait_until_sent() --- wait until the transmitter is empty
  1452. */
  1453. static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout)
  1454. {
  1455. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1456. unsigned long orig_jiffies, char_time;
  1457. /*int lsr;*/
  1458. volatile QUICC_BD *bdp;
  1459. if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
  1460. return;
  1461. #ifdef maybe
  1462. if (info->state->type == PORT_UNKNOWN)
  1463. return;
  1464. #endif
  1465. orig_jiffies = jiffies;
  1466. /*
  1467. * Set the check interval to be 1/5 of the estimated time to
  1468. * send a single character, and make it at least 1. The check
  1469. * interval should also be less than the timeout.
  1470. *
  1471. * Note: we have to use pretty tight timings here to satisfy
  1472. * the NIST-PCTS.
  1473. */
  1474. char_time = 1;
  1475. if (timeout)
  1476. char_time = min(char_time, (unsigned long)timeout);
  1477. #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
  1478. printk("In rs_wait_until_sent(%d) check=%lu...", timeout, char_time);
  1479. printk("jiff=%lu...", jiffies);
  1480. #endif
  1481. /* We go through the loop at least once because we can't tell
  1482. * exactly when the last character exits the shifter. There can
  1483. * be at least two characters waiting to be sent after the buffers
  1484. * are empty.
  1485. */
  1486. do {
  1487. #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
  1488. printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
  1489. #endif
  1490. /* current->counter = 0; make us low-priority */
  1491. msleep_interruptible(jiffies_to_msecs(char_time));
  1492. if (signal_pending(current))
  1493. break;
  1494. if (timeout && ((orig_jiffies + timeout) < jiffies))
  1495. break;
  1496. /* The 'tx_cur' is really the next buffer to send. We
  1497. * have to back up to the previous BD and wait for it
  1498. * to go. This isn't perfect, because all this indicates
  1499. * is the buffer is available. There are still characters
  1500. * in the CPM FIFO.
  1501. */
  1502. bdp = info->tx_cur;
  1503. if (bdp == info->tx_bd_base)
  1504. bdp += (TX_NUM_FIFO-1);
  1505. else
  1506. bdp--;
  1507. } while (bdp->status & BD_SC_READY);
  1508. current->state = TASK_RUNNING;
  1509. #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
  1510. printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
  1511. #endif
  1512. }
  1513. /*
  1514. * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
  1515. */
  1516. static void rs_360_hangup(struct tty_struct *tty)
  1517. {
  1518. ser_info_t *info = (ser_info_t *)tty->driver_data;
  1519. struct serial_state *state = info->state;
  1520. if (serial_paranoia_check(info, tty->name, "rs_hangup"))
  1521. return;
  1522. state = info->state;
  1523. rs_360_flush_buffer(tty);
  1524. shutdown(info);
  1525. info->event = 0;
  1526. state->count = 0;
  1527. info->flags &= ~ASYNC_NORMAL_ACTIVE;
  1528. info->tty = 0;
  1529. wake_up_interruptible(&info->open_wait);
  1530. }
  1531. /*
  1532. * ------------------------------------------------------------
  1533. * rs_open() and friends
  1534. * ------------------------------------------------------------
  1535. */
  1536. static int block_til_ready(struct tty_struct *tty, struct file * filp,
  1537. ser_info_t *info)
  1538. {
  1539. #ifdef DO_THIS_LATER
  1540. DECLARE_WAITQUEUE(wait, current);
  1541. #endif
  1542. struct serial_state *state = info->state;
  1543. int retval;
  1544. int do_clocal = 0;
  1545. /*
  1546. * If the device is in the middle of being closed, then block
  1547. * until it's done, and then try again.
  1548. */
  1549. if (tty_hung_up_p(filp) ||
  1550. (info->flags & ASYNC_CLOSING)) {
  1551. if (info->flags & ASYNC_CLOSING)
  1552. interruptible_sleep_on(&info->close_wait);
  1553. #ifdef SERIAL_DO_RESTART
  1554. if (info->flags & ASYNC_HUP_NOTIFY)
  1555. return -EAGAIN;
  1556. else
  1557. return -ERESTARTSYS;
  1558. #else
  1559. return -EAGAIN;
  1560. #endif
  1561. }
  1562. /*
  1563. * If non-blocking mode is set, or the port is not enabled,
  1564. * then make the check up front and then exit.
  1565. * If this is an SMC port, we don't have modem control to wait
  1566. * for, so just get out here.
  1567. */
  1568. if ((filp->f_flags & O_NONBLOCK) ||
  1569. (tty->flags & (1 << TTY_IO_ERROR)) ||
  1570. !(info->state->smc_scc_num & NUM_IS_SCC)) {
  1571. info->flags |= ASYNC_NORMAL_ACTIVE;
  1572. return 0;
  1573. }
  1574. if (tty->termios->c_cflag & CLOCAL)
  1575. do_clocal = 1;
  1576. /*
  1577. * Block waiting for the carrier detect and the line to become
  1578. * free (i.e., not in use by the callout). While we are in
  1579. * this loop, state->count is dropped by one, so that
  1580. * rs_close() knows when to free things. We restore it upon
  1581. * exit, either normal or abnormal.
  1582. */
  1583. retval = 0;
  1584. #ifdef DO_THIS_LATER
  1585. add_wait_queue(&info->open_wait, &wait);
  1586. #ifdef SERIAL_DEBUG_OPEN
  1587. printk("block_til_ready before block: ttys%d, count = %d\n",
  1588. state->line, state->count);
  1589. #endif
  1590. local_irq_disable();
  1591. if (!tty_hung_up_p(filp))
  1592. state->count--;
  1593. local_irq_enable();
  1594. info->blocked_open++;
  1595. while (1) {
  1596. local_irq_disable();
  1597. if (tty->termios->c_cflag & CBAUD)
  1598. serial_out(info, UART_MCR,
  1599. serial_inp(info, UART_MCR) |
  1600. (UART_MCR_DTR | UART_MCR_RTS));
  1601. local_irq_enable();
  1602. set_current_state(TASK_INTERRUPTIBLE);
  1603. if (tty_hung_up_p(filp) ||
  1604. !(info->flags & ASYNC_INITIALIZED)) {
  1605. #ifdef SERIAL_DO_RESTART
  1606. if (info->flags & ASYNC_HUP_NOTIFY)
  1607. retval = -EAGAIN;
  1608. else
  1609. retval = -ERESTARTSYS;
  1610. #else
  1611. retval = -EAGAIN;
  1612. #endif
  1613. break;
  1614. }
  1615. if (!(info->flags & ASYNC_CLOSING) &&
  1616. (do_clocal || (serial_in(info, UART_MSR) &
  1617. UART_MSR_DCD)))
  1618. break;
  1619. if (signal_pending(current)) {
  1620. retval = -ERESTARTSYS;
  1621. break;
  1622. }
  1623. #ifdef SERIAL_DEBUG_OPEN
  1624. printk("block_til_ready blocking: ttys%d, count = %d\n",
  1625. info->line, state->count);
  1626. #endif
  1627. schedule();
  1628. }
  1629. current->state = TASK_RUNNING;
  1630. remove_wait_queue(&info->open_wait, &wait);
  1631. if (!tty_hung_up_p(filp))
  1632. state->count++;
  1633. info->blocked_open--;
  1634. #ifdef SERIAL_DEBUG_OPEN
  1635. printk("block_til_ready after blocking: ttys%d, count = %d\n",
  1636. info->line, state->count);
  1637. #endif
  1638. #endif /* DO_THIS_LATER */
  1639. if (retval)
  1640. return retval;
  1641. info->flags |= ASYNC_NORMAL_ACTIVE;
  1642. return 0;
  1643. }
  1644. static int get_async_struct(int line, ser_info_t **ret_info)
  1645. {
  1646. struct serial_state *sstate;
  1647. sstate = rs_table + line;
  1648. if (sstate->info) {
  1649. sstate->count++;
  1650. *ret_info = (ser_info_t *)sstate->info;
  1651. return 0;
  1652. }
  1653. else {
  1654. return -ENOMEM;
  1655. }
  1656. }
  1657. /*
  1658. * This routine is called whenever a serial port is opened. It
  1659. * enables interrupts for a serial port, linking in its async structure into
  1660. * the IRQ chain. It also performs the serial-specific
  1661. * initialization for the tty structure.
  1662. */
  1663. static int rs_360_open(struct tty_struct *tty, struct file * filp)
  1664. {
  1665. ser_info_t *info;
  1666. int retval, line;
  1667. line = tty->index;
  1668. if ((line < 0) || (line >= NR_PORTS))
  1669. return -ENODEV;
  1670. retval = get_async_struct(line, &info);
  1671. if (retval)
  1672. return retval;
  1673. if (serial_paranoia_check(info, tty->name, "rs_open"))
  1674. return -ENODEV;
  1675. #ifdef SERIAL_DEBUG_OPEN
  1676. printk("rs_open %s, count = %d\n", tty->name, info->state->count);
  1677. #endif
  1678. tty->driver_data = info;
  1679. info->tty = tty;
  1680. /*
  1681. * Start up serial port
  1682. */
  1683. retval = startup(info);
  1684. if (retval)
  1685. return retval;
  1686. retval = block_til_ready(tty, filp, info);
  1687. if (retval) {
  1688. #ifdef SERIAL_DEBUG_OPEN
  1689. printk("rs_open returning after block_til_ready with %d\n",
  1690. retval);
  1691. #endif
  1692. return retval;
  1693. }
  1694. #ifdef SERIAL_DEBUG_OPEN
  1695. printk("rs_open %s successful...", tty->name);
  1696. #endif
  1697. return 0;
  1698. }
  1699. /*
  1700. * /proc fs routines....
  1701. */
  1702. static inline int line_info(char *buf, struct serial_state *state)
  1703. {
  1704. #ifdef notdef
  1705. struct async_struct *info = state->info, scr_info;
  1706. char stat_buf[30], control, status;
  1707. #endif
  1708. int ret;
  1709. ret = sprintf(buf, "%d: uart:%s port:%X irq:%d",
  1710. state->line,
  1711. (state->smc_scc_num & NUM_IS_SCC) ? "SCC" : "SMC",
  1712. (unsigned int)(state->port), state->irq);
  1713. if (!state->port || (state->type == PORT_UNKNOWN)) {
  1714. ret += sprintf(buf+ret, "\n");
  1715. return ret;
  1716. }
  1717. #ifdef notdef
  1718. /*
  1719. * Figure out the current RS-232 lines
  1720. */
  1721. if (!info) {
  1722. info = &scr_info; /* This is just for serial_{in,out} */
  1723. info->magic = SERIAL_MAGIC;
  1724. info->port = state->port;
  1725. info->flags = state->flags;
  1726. info->quot = 0;
  1727. info->tty = 0;
  1728. }
  1729. local_irq_disable();
  1730. status = serial_in(info, UART_MSR);
  1731. control = info ? info->MCR : serial_in(info, UART_MCR);
  1732. local_irq_enable();
  1733. stat_buf[0] = 0;
  1734. stat_buf[1] = 0;
  1735. if (control & UART_MCR_RTS)
  1736. strcat(stat_buf, "|RTS");
  1737. if (status & UART_MSR_CTS)
  1738. strcat(stat_buf, "|CTS");
  1739. if (control & UART_MCR_DTR)
  1740. strcat(stat_buf, "|DTR");
  1741. if (status & UART_MSR_DSR)
  1742. strcat(stat_buf, "|DSR");
  1743. if (status & UART_MSR_DCD)
  1744. strcat(stat_buf, "|CD");
  1745. if (status & UART_MSR_RI)
  1746. strcat(stat_buf, "|RI");
  1747. if (info->quot) {
  1748. ret += sprintf(buf+ret, " baud:%d",
  1749. state->baud_base / info->quot);
  1750. }
  1751. ret += sprintf(buf+ret, " tx:%d rx:%d",
  1752. state->icount.tx, state->icount.rx);
  1753. if (state->icount.frame)
  1754. ret += sprintf(buf+ret, " fe:%d", state->icount.frame);
  1755. if (state->icount.parity)
  1756. ret += sprintf(buf+ret, " pe:%d", state->icount.parity);
  1757. if (state->icount.brk)
  1758. ret += sprintf(buf+ret, " brk:%d", state->icount.brk);
  1759. if (state->icount.overrun)
  1760. ret += sprintf(buf+ret, " oe:%d", state->icount.overrun);
  1761. /*
  1762. * Last thing is the RS-232 status lines
  1763. */
  1764. ret += sprintf(buf+ret, " %s\n", stat_buf+1);
  1765. #endif
  1766. return ret;
  1767. }
  1768. int rs_360_read_proc(char *page, char **start, off_t off, int count,
  1769. int *eof, void *data)
  1770. {
  1771. int i, len = 0;
  1772. off_t begin = 0;
  1773. len += sprintf(page, "serinfo:1.0 driver:%s\n", serial_version);
  1774. for (i = 0; i < NR_PORTS && len < 4000; i++) {
  1775. len += line_info(page + len, &rs_table[i]);
  1776. if (len+begin > off+count)
  1777. goto done;
  1778. if (len+begin < off) {
  1779. begin += len;
  1780. len = 0;
  1781. }
  1782. }
  1783. *eof = 1;
  1784. done:
  1785. if (off >= len+begin)
  1786. return 0;
  1787. *start = page + (begin-off);
  1788. return ((count < begin+len-off) ? count : begin+len-off);
  1789. }
  1790. /*
  1791. * ---------------------------------------------------------------------
  1792. * rs_init() and friends
  1793. *
  1794. * rs_init() is called at boot-time to initialize the serial driver.
  1795. * ---------------------------------------------------------------------
  1796. */
  1797. /*
  1798. * This routine prints out the appropriate serial driver version
  1799. * number, and identifies which options were configured into this
  1800. * driver.
  1801. */
  1802. static _INLINE_ void show_serial_version(void)
  1803. {
  1804. printk(KERN_INFO "%s version %s\n", serial_name, serial_version);
  1805. }
  1806. /*
  1807. * The serial console driver used during boot. Note that these names
  1808. * clash with those found in "serial.c", so we currently can't support
  1809. * the 16xxx uarts and these at the same time. I will fix this to become
  1810. * an indirect function call from tty_io.c (or something).
  1811. */
  1812. #ifdef CONFIG_SERIAL_CONSOLE
  1813. /*
  1814. * Print a string to the serial port trying not to disturb any possible
  1815. * real use of the port...
  1816. */
  1817. static void my_console_write(int idx, const char *s,
  1818. unsigned count)
  1819. {
  1820. struct serial_state *ser;
  1821. ser_info_t *info;
  1822. unsigned i;
  1823. QUICC_BD *bdp, *bdbase;
  1824. volatile struct smc_uart_pram *up;
  1825. volatile u_char *cp;
  1826. ser = rs_table + idx;
  1827. /* If the port has been initialized for general use, we have
  1828. * to use the buffer descriptors allocated there. Otherwise,
  1829. * we simply use the single buffer allocated.
  1830. */
  1831. if ((info = (ser_info_t *)ser->info) != NULL) {
  1832. bdp = info->tx_cur;
  1833. bdbase = info->tx_bd_base;
  1834. }
  1835. else {
  1836. /* Pointer to UART in parameter ram.
  1837. */
  1838. /* up = (smc_uart_t *)&cpmp->cp_dparam[ser->port]; */
  1839. up = &pquicc->pram[ser->port].scc.pothers.idma_smc.psmc.u;
  1840. /* Get the address of the host memory buffer.
  1841. */
  1842. bdp = bdbase = (QUICC_BD *)((uint)pquicc + (uint)up->tbase);
  1843. }
  1844. /*
  1845. * We need to gracefully shut down the transmitter, disable
  1846. * interrupts, then send our bytes out.
  1847. */
  1848. /*
  1849. * Now, do each character. This is not as bad as it looks
  1850. * since this is a holding FIFO and not a transmitting FIFO.
  1851. * We could add the complexity of filling the entire transmit
  1852. * buffer, but we would just wait longer between accesses......
  1853. */
  1854. for (i = 0; i < count; i++, s++) {
  1855. /* Wait for transmitter fifo to empty.
  1856. * Ready indicates output is ready, and xmt is doing
  1857. * that, not that it is ready for us to send.
  1858. */
  1859. while (bdp->status & BD_SC_READY);
  1860. /* Send the character out.
  1861. */
  1862. cp = bdp->buf;
  1863. *cp = *s;
  1864. bdp->length = 1;
  1865. bdp->status |= BD_SC_READY;
  1866. if (bdp->status & BD_SC_WRAP)
  1867. bdp = bdbase;
  1868. else
  1869. bdp++;
  1870. /* if a LF, also do CR... */
  1871. if (*s == 10) {
  1872. while (bdp->status & BD_SC_READY);
  1873. /* cp = __va(bdp->buf); */
  1874. cp = bdp->buf;
  1875. *cp = 13;
  1876. bdp->length = 1;
  1877. bdp->status |= BD_SC_READY;
  1878. if (bdp->status & BD_SC_WRAP) {
  1879. bdp = bdbase;
  1880. }
  1881. else {
  1882. bdp++;
  1883. }
  1884. }
  1885. }
  1886. /*
  1887. * Finally, Wait for transmitter & holding register to empty
  1888. * and restore the IER
  1889. */
  1890. while (bdp->status & BD_SC_READY);
  1891. if (info)
  1892. info->tx_cur = (QUICC_BD *)bdp;
  1893. }
  1894. static void serial_console_write(struct console *c, const char *s,
  1895. unsigned count)
  1896. {
  1897. #ifdef CONFIG_KGDB
  1898. /* Try to let stub handle output. Returns true if it did. */
  1899. if (kgdb_output_string(s, count))
  1900. return;
  1901. #endif
  1902. my_console_write(c->index, s, count);
  1903. }
  1904. /*void console_print_68360(const char *p)
  1905. {
  1906. const char *cp = p;
  1907. int i;
  1908. for (i=0;cp[i]!=0;i++);
  1909. serial_console_write (p, i);
  1910. //Comment this if you want to have a strict interrupt-driven output
  1911. //rs_fair_output();
  1912. return;
  1913. }*/
  1914. #ifdef CONFIG_XMON
  1915. int
  1916. xmon_360_write(const char *s, unsigned count)
  1917. {
  1918. my_console_write(0, s, count);
  1919. return(count);
  1920. }
  1921. #endif
  1922. #ifdef CONFIG_KGDB
  1923. void
  1924. putDebugChar(char ch)
  1925. {
  1926. my_console_write(0, &ch, 1);
  1927. }
  1928. #endif
  1929. /*
  1930. * Receive character from the serial port. This only works well
  1931. * before the port is initialized for real use.
  1932. */
  1933. static int my_console_wait_key(int idx, int xmon, char *obuf)
  1934. {
  1935. struct serial_state *ser;
  1936. u_char c, *cp;
  1937. ser_info_t *info;
  1938. QUICC_BD *bdp;
  1939. volatile struct smc_uart_pram *up;
  1940. int i;
  1941. ser = rs_table + idx;
  1942. /* Get the address of the host memory buffer.
  1943. * If the port has been initialized for general use, we must
  1944. * use information from the port structure.
  1945. */
  1946. if ((info = (ser_info_t *)ser->info))
  1947. bdp = info->rx_cur;
  1948. else
  1949. /* bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_rbase]; */
  1950. bdp = (QUICC_BD *)((uint)pquicc + (uint)up->tbase);
  1951. /* Pointer to UART in parameter ram.
  1952. */
  1953. /* up = (smc_uart_t *)&cpmp->cp_dparam[ser->port]; */
  1954. up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;
  1955. /*
  1956. * We need to gracefully shut down the receiver, disable
  1957. * interrupts, then read the input.
  1958. * XMON just wants a poll. If no character, return -1, else
  1959. * return the character.
  1960. */
  1961. if (!xmon) {
  1962. while (bdp->status & BD_SC_EMPTY);
  1963. }
  1964. else {
  1965. if (bdp->status & BD_SC_EMPTY)
  1966. return -1;
  1967. }
  1968. cp = (char *)bdp->buf;
  1969. if (obuf) {
  1970. i = c = bdp->length;
  1971. while (i-- > 0)
  1972. *obuf++ = *cp++;
  1973. }
  1974. else {
  1975. c = *cp;
  1976. }
  1977. bdp->status |= BD_SC_EMPTY;
  1978. if (info) {
  1979. if (bdp->status & BD_SC_WRAP) {
  1980. bdp = info->rx_bd_base;
  1981. }
  1982. else {
  1983. bdp++;
  1984. }
  1985. info->rx_cur = (QUICC_BD *)bdp;
  1986. }
  1987. return((int)c);
  1988. }
  1989. static int serial_console_wait_key(struct console *co)
  1990. {
  1991. return(my_console_wait_key(co->index, 0, NULL));
  1992. }
  1993. #ifdef CONFIG_XMON
  1994. int
  1995. xmon_360_read_poll(void)
  1996. {
  1997. return(my_console_wait_key(0, 1, NULL));
  1998. }
  1999. int
  2000. xmon_360_read_char(void)
  2001. {
  2002. return(my_console_wait_key(0, 0, NULL));
  2003. }
  2004. #endif
  2005. #ifdef CONFIG_KGDB
  2006. static char kgdb_buf[RX_BUF_SIZE], *kgdp;
  2007. static int kgdb_chars;
  2008. unsigned char
  2009. getDebugChar(void)
  2010. {
  2011. if (kgdb_chars <= 0) {
  2012. kgdb_chars = my_console_wait_key(0, 0, kgdb_buf);
  2013. kgdp = kgdb_buf;
  2014. }
  2015. kgdb_chars--;
  2016. return(*kgdp++);
  2017. }
  2018. void kgdb_interruptible(int state)
  2019. {
  2020. }
  2021. void kgdb_map_scc(void)
  2022. {
  2023. struct serial_state *ser;
  2024. uint mem_addr;
  2025. volatile QUICC_BD *bdp;
  2026. volatile smc_uart_t *up;
  2027. cpmp = (cpm360_t *)&(((immap_t *)IMAP_ADDR)->im_cpm);
  2028. /* To avoid data cache CPM DMA coherency problems, allocate a
  2029. * buffer in the CPM DPRAM. This will work until the CPM and
  2030. * serial ports are initialized. At that time a memory buffer
  2031. * will be allocated.
  2032. * The port is already initialized from the boot procedure, all
  2033. * we do here is give it a different buffer and make it a FIFO.
  2034. */
  2035. ser = rs_table;
  2036. /* Right now, assume we are using SMCs.
  2037. */
  2038. up = (smc_uart_t *)&cpmp->cp_dparam[ser->port];
  2039. /* Allocate space for an input FIFO, plus a few bytes for output.
  2040. * Allocate bytes to maintain word alignment.
  2041. */
  2042. mem_addr = (uint)(&cpmp->cp_dpmem[0x1000]);
  2043. /* Set the physical address of the host memory buffers in
  2044. * the buffer descriptors.
  2045. */
  2046. bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_rbase];
  2047. bdp->buf = mem_addr;
  2048. bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_tbase];
  2049. bdp->buf = mem_addr+RX_BUF_SIZE;
  2050. up->smc_mrblr = RX_BUF_SIZE; /* receive buffer length */
  2051. up->smc_maxidl = RX_BUF_SIZE;
  2052. }
  2053. #endif
  2054. static struct tty_struct *serial_console_device(struct console *c, int *index)
  2055. {
  2056. *index = c->index;
  2057. return serial_driver;
  2058. }
  2059. struct console sercons = {
  2060. .name = "ttyS",
  2061. .write = serial_console_write,
  2062. .device = serial_console_device,
  2063. .wait_key = serial_console_wait_key,
  2064. .setup = serial_console_setup,
  2065. .flags = CON_PRINTBUFFER,
  2066. .index = CONFIG_SERIAL_CONSOLE_PORT,
  2067. };
  2068. /*
  2069. * Register console.
  2070. */
  2071. long console_360_init(long kmem_start, long kmem_end)
  2072. {
  2073. register_console(&sercons);
  2074. /*register_console (console_print_68360); - 2.0.38 only required a write
  2075. function pointer. */
  2076. return kmem_start;
  2077. }
  2078. #endif
  2079. /* Index in baud rate table of the default console baud rate.
  2080. */
  2081. static int baud_idx;
  2082. static const struct tty_operations rs_360_ops = {
  2083. .owner = THIS_MODULE,
  2084. .open = rs_360_open,
  2085. .close = rs_360_close,
  2086. .write = rs_360_write,
  2087. .put_char = rs_360_put_char,
  2088. .write_room = rs_360_write_room,
  2089. .chars_in_buffer = rs_360_chars_in_buffer,
  2090. .flush_buffer = rs_360_flush_buffer,
  2091. .ioctl = rs_360_ioctl,
  2092. .throttle = rs_360_throttle,
  2093. .unthrottle = rs_360_unthrottle,
  2094. /* .send_xchar = rs_360_send_xchar, */
  2095. .set_termios = rs_360_set_termios,
  2096. .stop = rs_360_stop,
  2097. .start = rs_360_start,
  2098. .hangup = rs_360_hangup,
  2099. /* .wait_until_sent = rs_360_wait_until_sent, */
  2100. /* .read_proc = rs_360_read_proc, */
  2101. .tiocmget = rs_360_tiocmget,
  2102. .tiocmset = rs_360_tiocmset,
  2103. };
  2104. static int __init rs_360_init(void)
  2105. {
  2106. struct serial_state * state;
  2107. ser_info_t *info;
  2108. void *mem_addr;
  2109. uint dp_addr, iobits;
  2110. int i, j, idx;
  2111. ushort chan;
  2112. QUICC_BD *bdp;
  2113. volatile QUICC *cp;
  2114. volatile struct smc_regs *sp;
  2115. volatile struct smc_uart_pram *up;
  2116. volatile struct scc_regs *scp;
  2117. volatile struct uart_pram *sup;
  2118. /* volatile immap_t *immap; */
  2119. serial_driver = alloc_tty_driver(NR_PORTS);
  2120. if (!serial_driver)
  2121. return -1;
  2122. show_serial_version();
  2123. serial_driver->name = "ttyS";
  2124. serial_driver->major = TTY_MAJOR;
  2125. serial_driver->minor_start = 64;
  2126. serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
  2127. serial_driver->subtype = SERIAL_TYPE_NORMAL;
  2128. serial_driver->init_termios = tty_std_termios;
  2129. serial_driver->init_termios.c_cflag =
  2130. baud_idx | CS8 | CREAD | HUPCL | CLOCAL;
  2131. serial_driver->flags = TTY_DRIVER_REAL_RAW;
  2132. tty_set_operations(serial_driver, &rs_360_ops);
  2133. if (tty_register_driver(serial_driver))
  2134. panic("Couldn't register serial driver\n");
  2135. cp = pquicc; /* Get pointer to Communication Processor */
  2136. /* immap = (immap_t *)IMAP_ADDR; */ /* and to internal registers */
  2137. /* Configure SCC2, SCC3, and SCC4 instead of port A parallel I/O.
  2138. */
  2139. /* The "standard" configuration through the 860.
  2140. */
  2141. /* immap->im_ioport.iop_papar |= 0x00fc; */
  2142. /* immap->im_ioport.iop_padir &= ~0x00fc; */
  2143. /* immap->im_ioport.iop_paodr &= ~0x00fc; */
  2144. cp->pio_papar |= 0x00fc;
  2145. cp->pio_padir &= ~0x00fc;
  2146. /* cp->pio_paodr &= ~0x00fc; */
  2147. /* Since we don't yet do modem control, connect the port C pins
  2148. * as general purpose I/O. This will assert CTS and CD for the
  2149. * SCC ports.
  2150. */
  2151. /* FIXME: see 360um p.7-365 and 860um p.34-12
  2152. * I can't make sense of these bits - mleslie*/
  2153. /* immap->im_ioport.iop_pcdir |= 0x03c6; */
  2154. /* immap->im_ioport.iop_pcpar &= ~0x03c6; */
  2155. /* cp->pio_pcdir |= 0x03c6; */
  2156. /* cp->pio_pcpar &= ~0x03c6; */
  2157. /* Connect SCC2 and SCC3 to NMSI. Connect BRG3 to SCC2 and
  2158. * BRG4 to SCC3.
  2159. */
  2160. cp->si_sicr &= ~0x00ffff00;
  2161. cp->si_sicr |= 0x001b1200;
  2162. #ifdef CONFIG_PP04
  2163. /* Frequentis PP04 forced to RS-232 until we know better.
  2164. * Port C 12 and 13 low enables RS-232 on SCC3 and SCC4.
  2165. */
  2166. immap->im_ioport.iop_pcdir |= 0x000c;
  2167. immap->im_ioport.iop_pcpar &= ~0x000c;
  2168. immap->im_ioport.iop_pcdat &= ~0x000c;
  2169. /* This enables the TX driver.
  2170. */
  2171. cp->cp_pbpar &= ~0x6000;
  2172. cp->cp_pbdat &= ~0x6000;
  2173. #endif
  2174. for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
  2175. state->magic = SSTATE_MAGIC;
  2176. state->line = i;
  2177. state->type = PORT_UNKNOWN;
  2178. state->custom_divisor = 0;
  2179. state->close_delay = 5*HZ/10;
  2180. state->closing_wait = 30*HZ;
  2181. state->icount.cts = state->icount.dsr =
  2182. state->icount.rng = state->icount.dcd = 0;
  2183. state->icount.rx = state->icount.tx = 0;
  2184. state->icount.frame = state->icount.parity = 0;
  2185. state->icount.overrun = state->icount.brk = 0;
  2186. printk(KERN_INFO "ttyS%d at irq 0x%02x is an %s\n",
  2187. i, (unsigned int)(state->irq),
  2188. (state->smc_scc_num & NUM_IS_SCC) ? "SCC" : "SMC");
  2189. #ifdef CONFIG_SERIAL_CONSOLE
  2190. /* If we just printed the message on the console port, and
  2191. * we are about to initialize it for general use, we have
  2192. * to wait a couple of character times for the CR/NL to
  2193. * make it out of the transmit buffer.
  2194. */
  2195. if (i == CONFIG_SERIAL_CONSOLE_PORT)
  2196. mdelay(8);
  2197. /* idx = PORT_NUM(info->state->smc_scc_num); */
  2198. /* if (info->state->smc_scc_num & NUM_IS_SCC) */
  2199. /* chan = scc_chan_map[idx]; */
  2200. /* else */
  2201. /* chan = smc_chan_map[idx]; */
  2202. /* cp->cp_cr = mk_cr_cmd(chan, CPM_CR_STOP_TX) | CPM_CR_FLG; */
  2203. /* while (cp->cp_cr & CPM_CR_FLG); */
  2204. #endif
  2205. /* info = kmalloc(sizeof(ser_info_t), GFP_KERNEL); */
  2206. info = &quicc_ser_info[i];
  2207. if (info) {
  2208. memset (info, 0, sizeof(ser_info_t));
  2209. info->magic = SERIAL_MAGIC;
  2210. info->line = i;
  2211. info->flags = state->flags;
  2212. INIT_WORK(&info->tqueue, do_softint, info);
  2213. INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info);
  2214. init_waitqueue_head(&info->open_wait);
  2215. init_waitqueue_head(&info->close_wait);
  2216. info->state = state;
  2217. state->info = (struct async_struct *)info;
  2218. /* We need to allocate a transmit and receive buffer
  2219. * descriptors from dual port ram, and a character
  2220. * buffer area from host mem.
  2221. */
  2222. dp_addr = m360_cpm_dpalloc(sizeof(QUICC_BD) * RX_NUM_FIFO);
  2223. /* Allocate space for FIFOs in the host memory.
  2224. * (for now this is from a static array of buffers :(
  2225. */
  2226. /* mem_addr = m360_cpm_hostalloc(RX_NUM_FIFO * RX_BUF_SIZE); */
  2227. /* mem_addr = kmalloc (RX_NUM_FIFO * RX_BUF_SIZE, GFP_BUFFER); */
  2228. mem_addr = &rx_buf_pool[i * RX_NUM_FIFO * RX_BUF_SIZE];
  2229. /* Set the physical address of the host memory
  2230. * buffers in the buffer descriptors, and the
  2231. * virtual address for us to work with.
  2232. */
  2233. bdp = (QUICC_BD *)((uint)pquicc + dp_addr);
  2234. info->rx_cur = info->rx_bd_base = bdp;
  2235. /* initialize rx buffer descriptors */
  2236. for (j=0; j<(RX_NUM_FIFO-1); j++) {
  2237. bdp->buf = &rx_buf_pool[(i * RX_NUM_FIFO + j ) * RX_BUF_SIZE];
  2238. bdp->status = BD_SC_EMPTY | BD_SC_INTRPT;
  2239. mem_addr += RX_BUF_SIZE;
  2240. bdp++;
  2241. }
  2242. bdp->buf = &rx_buf_pool[(i * RX_NUM_FIFO + j ) * RX_BUF_SIZE];
  2243. bdp->status = BD_SC_WRAP | BD_SC_EMPTY | BD_SC_INTRPT;
  2244. idx = PORT_NUM(info->state->smc_scc_num);
  2245. if (info->state->smc_scc_num & NUM_IS_SCC) {
  2246. #if defined (CONFIG_UCQUICC) && 1
  2247. /* set the transceiver mode to RS232 */
  2248. sipex_mode_bits &= ~(uint)SIPEX_MODE(idx,0x0f); /* clear current mode */
  2249. sipex_mode_bits |= (uint)SIPEX_MODE(idx,0x02);
  2250. *(uint *)_periph_base = sipex_mode_bits;
  2251. /* printk ("sipex bits = 0x%08x\n", sipex_mode_bits); */
  2252. #endif
  2253. }
  2254. dp_addr = m360_cpm_dpalloc(sizeof(QUICC_BD) * TX_NUM_FIFO);
  2255. /* Allocate space for FIFOs in the host memory.
  2256. */
  2257. /* mem_addr = m360_cpm_hostalloc(TX_NUM_FIFO * TX_BUF_SIZE); */
  2258. /* mem_addr = kmalloc (TX_NUM_FIFO * TX_BUF_SIZE, GFP_BUFFER); */
  2259. mem_addr = &tx_buf_pool[i * TX_NUM_FIFO * TX_BUF_SIZE];
  2260. /* Set the physical address of the host memory
  2261. * buffers in the buffer descriptors, and the
  2262. * virtual address for us to work with.
  2263. */
  2264. /* bdp = (QUICC_BD *)&cp->cp_dpmem[dp_addr]; */
  2265. bdp = (QUICC_BD *)((uint)pquicc + dp_addr);
  2266. info->tx_cur = info->tx_bd_base = (QUICC_BD *)bdp;
  2267. /* initialize tx buffer descriptors */
  2268. for (j=0; j<(TX_NUM_FIFO-1); j++) {
  2269. bdp->buf = &tx_buf_pool[(i * TX_NUM_FIFO + j ) * TX_BUF_SIZE];
  2270. bdp->status = BD_SC_INTRPT;
  2271. mem_addr += TX_BUF_SIZE;
  2272. bdp++;
  2273. }
  2274. bdp->buf = &tx_buf_pool[(i * TX_NUM_FIFO + j ) * TX_BUF_SIZE];
  2275. bdp->status = (BD_SC_WRAP | BD_SC_INTRPT);
  2276. if (info->state->smc_scc_num & NUM_IS_SCC) {
  2277. scp = &pquicc->scc_regs[idx];
  2278. sup = &pquicc->pram[info->state->port].scc.pscc.u;
  2279. sup->rbase = dp_addr;
  2280. sup->tbase = dp_addr;
  2281. /* Set up the uart parameters in the
  2282. * parameter ram.
  2283. */
  2284. sup->rfcr = SMC_EB;
  2285. sup->tfcr = SMC_EB;
  2286. /* Set this to 1 for now, so we get single
  2287. * character interrupts. Using idle charater
  2288. * time requires some additional tuning.
  2289. */
  2290. sup->mrblr = 1;
  2291. sup->max_idl = 0;
  2292. sup->brkcr = 1;
  2293. sup->parec = 0;
  2294. sup->frmer = 0;
  2295. sup->nosec = 0;
  2296. sup->brkec = 0;
  2297. sup->uaddr1 = 0;
  2298. sup->uaddr2 = 0;
  2299. sup->toseq = 0;
  2300. {
  2301. int i;
  2302. for (i=0;i<8;i++)
  2303. sup->cc[i] = 0x8000;
  2304. }
  2305. sup->rccm = 0xc0ff;
  2306. /* Send the CPM an initialize command.
  2307. */
  2308. chan = scc_chan_map[idx];
  2309. /* execute the INIT RX & TX PARAMS command for this channel. */
  2310. cp->cp_cr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  2311. while (cp->cp_cr & CPM_CR_FLG);
  2312. /* Set UART mode, 8 bit, no parity, one stop.
  2313. * Enable receive and transmit.
  2314. */
  2315. scp->scc_gsmr.w.high = 0;
  2316. scp->scc_gsmr.w.low =
  2317. (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
  2318. /* Disable all interrupts and clear all pending
  2319. * events.
  2320. */
  2321. scp->scc_sccm = 0;
  2322. scp->scc_scce = 0xffff;
  2323. scp->scc_dsr = 0x7e7e;
  2324. scp->scc_psmr = 0x3000;
  2325. /* If the port is the console, enable Rx and Tx.
  2326. */
  2327. #ifdef CONFIG_SERIAL_CONSOLE
  2328. if (i == CONFIG_SERIAL_CONSOLE_PORT)
  2329. scp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  2330. #endif
  2331. }
  2332. else {
  2333. /* Configure SMCs Tx/Rx instead of port B
  2334. * parallel I/O.
  2335. */
  2336. up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;
  2337. up->rbase = dp_addr;
  2338. iobits = 0xc0 << (idx * 4);
  2339. cp->pip_pbpar |= iobits;
  2340. cp->pip_pbdir &= ~iobits;
  2341. cp->pip_pbodr &= ~iobits;
  2342. /* Connect the baud rate generator to the
  2343. * SMC based upon index in rs_table. Also
  2344. * make sure it is connected to NMSI.
  2345. */
  2346. cp->si_simode &= ~(0xffff << (idx * 16));
  2347. cp->si_simode |= (i << ((idx * 16) + 12));
  2348. up->tbase = dp_addr;
  2349. /* Set up the uart parameters in the
  2350. * parameter ram.
  2351. */
  2352. up->rfcr = SMC_EB;
  2353. up->tfcr = SMC_EB;
  2354. /* Set this to 1 for now, so we get single
  2355. * character interrupts. Using idle charater
  2356. * time requires some additional tuning.
  2357. */
  2358. up->mrblr = 1;
  2359. up->max_idl = 0;
  2360. up->brkcr = 1;
  2361. /* Send the CPM an initialize command.
  2362. */
  2363. chan = smc_chan_map[idx];
  2364. cp->cp_cr = mk_cr_cmd(chan,
  2365. CPM_CR_INIT_TRX) | CPM_CR_FLG;
  2366. #ifdef CONFIG_SERIAL_CONSOLE
  2367. if (i == CONFIG_SERIAL_CONSOLE_PORT)
  2368. printk("");
  2369. #endif
  2370. while (cp->cp_cr & CPM_CR_FLG);
  2371. /* Set UART mode, 8 bit, no parity, one stop.
  2372. * Enable receive and transmit.
  2373. */
  2374. sp = &cp->smc_regs[idx];
  2375. sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
  2376. /* Disable all interrupts and clear all pending
  2377. * events.
  2378. */
  2379. sp->smc_smcm = 0;
  2380. sp->smc_smce = 0xff;
  2381. /* If the port is the console, enable Rx and Tx.
  2382. */
  2383. #ifdef CONFIG_SERIAL_CONSOLE
  2384. if (i == CONFIG_SERIAL_CONSOLE_PORT)
  2385. sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
  2386. #endif
  2387. }
  2388. /* Install interrupt handler.
  2389. */
  2390. /* cpm_install_handler(IRQ_MACHSPEC | state->irq, rs_360_interrupt, info); */
  2391. /*request_irq(IRQ_MACHSPEC | state->irq, rs_360_interrupt, */
  2392. request_irq(state->irq, rs_360_interrupt,
  2393. IRQ_FLG_LOCK, "ttyS", (void *)info);
  2394. /* Set up the baud rate generator.
  2395. */
  2396. m360_cpm_setbrg(i, baud_table[baud_idx]);
  2397. }
  2398. }
  2399. return 0;
  2400. }
  2401. module_init(rs_360_init);
  2402. /* This must always be called before the rs_360_init() function, otherwise
  2403. * it blows away the port control information.
  2404. */
  2405. //static int __init serial_console_setup( struct console *co, char *options)
  2406. int serial_console_setup( struct console *co, char *options)
  2407. {
  2408. struct serial_state *ser;
  2409. uint mem_addr, dp_addr, bidx, idx, iobits;
  2410. ushort chan;
  2411. QUICC_BD *bdp;
  2412. volatile QUICC *cp;
  2413. volatile struct smc_regs *sp;
  2414. volatile struct scc_regs *scp;
  2415. volatile struct smc_uart_pram *up;
  2416. volatile struct uart_pram *sup;
  2417. /* mleslie TODO:
  2418. * add something to the 68k bootloader to store a desired initial console baud rate */
  2419. /* bd_t *bd; */ /* a board info struct used by EPPC-bug */
  2420. /* bd = (bd_t *)__res; */
  2421. for (bidx = 0; bidx < (sizeof(baud_table) / sizeof(int)); bidx++)
  2422. /* if (bd->bi_baudrate == baud_table[bidx]) */
  2423. if (CONSOLE_BAUDRATE == baud_table[bidx])
  2424. break;
  2425. /* co->cflag = CREAD|CLOCAL|bidx|CS8; */
  2426. baud_idx = bidx;
  2427. ser = rs_table + CONFIG_SERIAL_CONSOLE_PORT;
  2428. cp = pquicc; /* Get pointer to Communication Processor */
  2429. idx = PORT_NUM(ser->smc_scc_num);
  2430. if (ser->smc_scc_num & NUM_IS_SCC) {
  2431. /* TODO: need to set up SCC pin assignment etc. here */
  2432. }
  2433. else {
  2434. iobits = 0xc0 << (idx * 4);
  2435. cp->pip_pbpar |= iobits;
  2436. cp->pip_pbdir &= ~iobits;
  2437. cp->pip_pbodr &= ~iobits;
  2438. /* Connect the baud rate generator to the
  2439. * SMC based upon index in rs_table. Also
  2440. * make sure it is connected to NMSI.
  2441. */
  2442. cp->si_simode &= ~(0xffff << (idx * 16));
  2443. cp->si_simode |= (idx << ((idx * 16) + 12));
  2444. }
  2445. /* When we get here, the CPM has been reset, so we need
  2446. * to configure the port.
  2447. * We need to allocate a transmit and receive buffer descriptor
  2448. * from dual port ram, and a character buffer area from host mem.
  2449. */
  2450. /* Allocate space for two buffer descriptors in the DP ram.
  2451. */
  2452. dp_addr = m360_cpm_dpalloc(sizeof(QUICC_BD) * CONSOLE_NUM_FIFO);
  2453. /* Allocate space for two 2 byte FIFOs in the host memory.
  2454. */
  2455. /* mem_addr = m360_cpm_hostalloc(8); */
  2456. mem_addr = (uint)console_fifos;
  2457. /* Set the physical address of the host memory buffers in
  2458. * the buffer descriptors.
  2459. */
  2460. /* bdp = (QUICC_BD *)&cp->cp_dpmem[dp_addr]; */
  2461. bdp = (QUICC_BD *)((uint)pquicc + dp_addr);
  2462. bdp->buf = (char *)mem_addr;
  2463. (bdp+1)->buf = (char *)(mem_addr+4);
  2464. /* For the receive, set empty and wrap.
  2465. * For transmit, set wrap.
  2466. */
  2467. bdp->status = BD_SC_EMPTY | BD_SC_WRAP;
  2468. (bdp+1)->status = BD_SC_WRAP;
  2469. /* Set up the uart parameters in the parameter ram.
  2470. */
  2471. if (ser->smc_scc_num & NUM_IS_SCC) {
  2472. scp = &cp->scc_regs[idx];
  2473. /* sup = (scc_uart_t *)&cp->cp_dparam[ser->port]; */
  2474. sup = &pquicc->pram[ser->port].scc.pscc.u;
  2475. sup->rbase = dp_addr;
  2476. sup->tbase = dp_addr + sizeof(QUICC_BD);
  2477. /* Set up the uart parameters in the
  2478. * parameter ram.
  2479. */
  2480. sup->rfcr = SMC_EB;
  2481. sup->tfcr = SMC_EB;
  2482. /* Set this to 1 for now, so we get single
  2483. * character interrupts. Using idle charater
  2484. * time requires some additional tuning.
  2485. */
  2486. sup->mrblr = 1;
  2487. sup->max_idl = 0;
  2488. sup->brkcr = 1;
  2489. sup->parec = 0;
  2490. sup->frmer = 0;
  2491. sup->nosec = 0;
  2492. sup->brkec = 0;
  2493. sup->uaddr1 = 0;
  2494. sup->uaddr2 = 0;
  2495. sup->toseq = 0;
  2496. {
  2497. int i;
  2498. for (i=0;i<8;i++)
  2499. sup->cc[i] = 0x8000;
  2500. }
  2501. sup->rccm = 0xc0ff;
  2502. /* Send the CPM an initialize command.
  2503. */
  2504. chan = scc_chan_map[idx];
  2505. cp->cp_cr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  2506. while (cp->cp_cr & CPM_CR_FLG);
  2507. /* Set UART mode, 8 bit, no parity, one stop.
  2508. * Enable receive and transmit.
  2509. */
  2510. scp->scc_gsmr.w.high = 0;
  2511. scp->scc_gsmr.w.low =
  2512. (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
  2513. /* Disable all interrupts and clear all pending
  2514. * events.
  2515. */
  2516. scp->scc_sccm = 0;
  2517. scp->scc_scce = 0xffff;
  2518. scp->scc_dsr = 0x7e7e;
  2519. scp->scc_psmr = 0x3000;
  2520. scp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  2521. }
  2522. else {
  2523. /* up = (smc_uart_t *)&cp->cp_dparam[ser->port]; */
  2524. up = &pquicc->pram[ser->port].scc.pothers.idma_smc.psmc.u;
  2525. up->rbase = dp_addr; /* Base of receive buffer desc. */
  2526. up->tbase = dp_addr+sizeof(QUICC_BD); /* Base of xmt buffer desc. */
  2527. up->rfcr = SMC_EB;
  2528. up->tfcr = SMC_EB;
  2529. /* Set this to 1 for now, so we get single character interrupts.
  2530. */
  2531. up->mrblr = 1; /* receive buffer length */
  2532. up->max_idl = 0; /* wait forever for next char */
  2533. /* Send the CPM an initialize command.
  2534. */
  2535. chan = smc_chan_map[idx];
  2536. cp->cp_cr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
  2537. while (cp->cp_cr & CPM_CR_FLG);
  2538. /* Set UART mode, 8 bit, no parity, one stop.
  2539. * Enable receive and transmit.
  2540. */
  2541. sp = &cp->smc_regs[idx];
  2542. sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
  2543. /* And finally, enable Rx and Tx.
  2544. */
  2545. sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
  2546. }
  2547. /* Set up the baud rate generator.
  2548. */
  2549. /* m360_cpm_setbrg((ser - rs_table), bd->bi_baudrate); */
  2550. m360_cpm_setbrg((ser - rs_table), CONSOLE_BAUDRATE);
  2551. return 0;
  2552. }
  2553. /*
  2554. * Local variables:
  2555. * c-indent-level: 4
  2556. * c-basic-offset: 4
  2557. * tab-width: 4
  2558. * End:
  2559. */