68360serial.c 76 KB

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