68360serial.c 75 KB

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