mcfserial.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887
  1. /*
  2. * mcfserial.c -- serial driver for ColdFire internal UARTS.
  3. *
  4. * Copyright (C) 1999-2003 Greg Ungerer <gerg@snapgear.com>
  5. * Copyright (c) 2000-2001 Lineo, Inc. <www.lineo.com>
  6. * Copyright (C) 2001-2002 SnapGear Inc. <www.snapgear.com>
  7. *
  8. * Based on code from 68332serial.c which was:
  9. *
  10. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  11. * Copyright (C) 1998 TSHG
  12. * Copyright (c) 1999 Rt-Control Inc. <jeff@uclinux.org>
  13. *
  14. * Changes:
  15. * 08/07/2003 Daniele Bellucci <bellucda@tiscali.it>
  16. * some cleanups in mcfrs_write.
  17. *
  18. */
  19. #include <linux/module.h>
  20. #include <linux/errno.h>
  21. #include <linux/signal.h>
  22. #include <linux/sched.h>
  23. #include <linux/timer.h>
  24. #include <linux/wait.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/tty.h>
  27. #include <linux/tty_flip.h>
  28. #include <linux/string.h>
  29. #include <linux/fcntl.h>
  30. #include <linux/mm.h>
  31. #include <linux/kernel.h>
  32. #include <linux/serial.h>
  33. #include <linux/serialP.h>
  34. #include <linux/console.h>
  35. #include <linux/init.h>
  36. #include <linux/bitops.h>
  37. #include <linux/delay.h>
  38. #include <asm/io.h>
  39. #include <asm/irq.h>
  40. #include <asm/system.h>
  41. #include <asm/semaphore.h>
  42. #include <asm/delay.h>
  43. #include <asm/coldfire.h>
  44. #include <asm/mcfsim.h>
  45. #include <asm/mcfuart.h>
  46. #include <asm/nettel.h>
  47. #include <asm/uaccess.h>
  48. #include "mcfserial.h"
  49. struct timer_list mcfrs_timer_struct;
  50. /*
  51. * Default console baud rate, we use this as the default
  52. * for all ports so init can just open /dev/console and
  53. * keep going. Perhaps one day the cflag settings for the
  54. * console can be used instead.
  55. */
  56. #if defined(CONFIG_ARNEWSH) || defined(CONFIG_MOTOROLA) || defined(CONFIG_senTec) || defined(CONFIG_SNEHA)
  57. #define CONSOLE_BAUD_RATE 19200
  58. #define DEFAULT_CBAUD B19200
  59. #endif
  60. #if defined(CONFIG_HW_FEITH)
  61. #define CONSOLE_BAUD_RATE 38400
  62. #define DEFAULT_CBAUD B38400
  63. #endif
  64. #if defined(CONFIG_MOD5272)
  65. #define CONSOLE_BAUD_RATE 115200
  66. #define DEFAULT_CBAUD B115200
  67. #endif
  68. #ifndef CONSOLE_BAUD_RATE
  69. #define CONSOLE_BAUD_RATE 9600
  70. #define DEFAULT_CBAUD B9600
  71. #endif
  72. int mcfrs_console_inited = 0;
  73. int mcfrs_console_port = -1;
  74. int mcfrs_console_baud = CONSOLE_BAUD_RATE;
  75. int mcfrs_console_cbaud = DEFAULT_CBAUD;
  76. /*
  77. * Driver data structures.
  78. */
  79. static struct tty_driver *mcfrs_serial_driver;
  80. /* number of characters left in xmit buffer before we ask for more */
  81. #define WAKEUP_CHARS 256
  82. /* Debugging...
  83. */
  84. #undef SERIAL_DEBUG_OPEN
  85. #undef SERIAL_DEBUG_FLOW
  86. #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
  87. #define IRQBASE (MCFINT_VECBASE+MCFINT_UART0)
  88. #else
  89. #define IRQBASE 73
  90. #endif
  91. /*
  92. * Configuration table, UARTs to look for at startup.
  93. */
  94. static struct mcf_serial mcfrs_table[] = {
  95. { /* ttyS0 */
  96. .magic = 0,
  97. .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE1),
  98. .irq = IRQBASE,
  99. .flags = ASYNC_BOOT_AUTOCONF,
  100. },
  101. { /* ttyS1 */
  102. .magic = 0,
  103. .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE2),
  104. .irq = IRQBASE+1,
  105. .flags = ASYNC_BOOT_AUTOCONF,
  106. },
  107. };
  108. #define NR_PORTS (sizeof(mcfrs_table) / sizeof(struct mcf_serial))
  109. /*
  110. * This is used to figure out the divisor speeds and the timeouts.
  111. */
  112. static int mcfrs_baud_table[] = {
  113. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
  114. 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0
  115. };
  116. #define MCFRS_BAUD_TABLE_SIZE \
  117. (sizeof(mcfrs_baud_table)/sizeof(mcfrs_baud_table[0]))
  118. #ifdef CONFIG_MAGIC_SYSRQ
  119. /*
  120. * Magic system request keys. Used for debugging...
  121. */
  122. extern int magic_sysrq_key(int ch);
  123. #endif
  124. /*
  125. * Forware declarations...
  126. */
  127. static void mcfrs_change_speed(struct mcf_serial *info);
  128. static void mcfrs_wait_until_sent(struct tty_struct *tty, int timeout);
  129. static inline int serial_paranoia_check(struct mcf_serial *info,
  130. char *name, const char *routine)
  131. {
  132. #ifdef SERIAL_PARANOIA_CHECK
  133. static const char badmagic[] =
  134. "MCFRS(warning): bad magic number for serial struct %s in %s\n";
  135. static const char badinfo[] =
  136. "MCFRS(warning): null mcf_serial for %s in %s\n";
  137. if (!info) {
  138. printk(badinfo, name, routine);
  139. return 1;
  140. }
  141. if (info->magic != SERIAL_MAGIC) {
  142. printk(badmagic, name, routine);
  143. return 1;
  144. }
  145. #endif
  146. return 0;
  147. }
  148. /*
  149. * Sets or clears DTR and RTS on the requested line.
  150. */
  151. static void mcfrs_setsignals(struct mcf_serial *info, int dtr, int rts)
  152. {
  153. volatile unsigned char *uartp;
  154. unsigned long flags;
  155. #if 0
  156. printk("%s(%d): mcfrs_setsignals(info=%x,dtr=%d,rts=%d)\n",
  157. __FILE__, __LINE__, info, dtr, rts);
  158. #endif
  159. local_irq_save(flags);
  160. if (dtr >= 0) {
  161. #ifdef MCFPP_DTR0
  162. if (info->line)
  163. mcf_setppdata(MCFPP_DTR1, (dtr ? 0 : MCFPP_DTR1));
  164. else
  165. mcf_setppdata(MCFPP_DTR0, (dtr ? 0 : MCFPP_DTR0));
  166. #endif
  167. }
  168. if (rts >= 0) {
  169. uartp = info->addr;
  170. if (rts) {
  171. info->sigs |= TIOCM_RTS;
  172. uartp[MCFUART_UOP1] = MCFUART_UOP_RTS;
  173. } else {
  174. info->sigs &= ~TIOCM_RTS;
  175. uartp[MCFUART_UOP0] = MCFUART_UOP_RTS;
  176. }
  177. }
  178. local_irq_restore(flags);
  179. return;
  180. }
  181. /*
  182. * Gets values of serial signals.
  183. */
  184. static int mcfrs_getsignals(struct mcf_serial *info)
  185. {
  186. volatile unsigned char *uartp;
  187. unsigned long flags;
  188. int sigs;
  189. #if defined(CONFIG_NETtel) && defined(CONFIG_M5307)
  190. unsigned short ppdata;
  191. #endif
  192. #if 0
  193. printk("%s(%d): mcfrs_getsignals(info=%x)\n", __FILE__, __LINE__);
  194. #endif
  195. local_irq_save(flags);
  196. uartp = info->addr;
  197. sigs = (uartp[MCFUART_UIPR] & MCFUART_UIPR_CTS) ? 0 : TIOCM_CTS;
  198. sigs |= (info->sigs & TIOCM_RTS);
  199. #ifdef MCFPP_DCD0
  200. {
  201. unsigned int ppdata;
  202. ppdata = mcf_getppdata();
  203. if (info->line == 0) {
  204. sigs |= (ppdata & MCFPP_DCD0) ? 0 : TIOCM_CD;
  205. sigs |= (ppdata & MCFPP_DTR0) ? 0 : TIOCM_DTR;
  206. } else if (info->line == 1) {
  207. sigs |= (ppdata & MCFPP_DCD1) ? 0 : TIOCM_CD;
  208. sigs |= (ppdata & MCFPP_DTR1) ? 0 : TIOCM_DTR;
  209. }
  210. }
  211. #endif
  212. local_irq_restore(flags);
  213. return(sigs);
  214. }
  215. /*
  216. * ------------------------------------------------------------
  217. * mcfrs_stop() and mcfrs_start()
  218. *
  219. * This routines are called before setting or resetting tty->stopped.
  220. * They enable or disable transmitter interrupts, as necessary.
  221. * ------------------------------------------------------------
  222. */
  223. static void mcfrs_stop(struct tty_struct *tty)
  224. {
  225. volatile unsigned char *uartp;
  226. struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
  227. unsigned long flags;
  228. if (serial_paranoia_check(info, tty->name, "mcfrs_stop"))
  229. return;
  230. local_irq_save(flags);
  231. uartp = info->addr;
  232. info->imr &= ~MCFUART_UIR_TXREADY;
  233. uartp[MCFUART_UIMR] = info->imr;
  234. local_irq_restore(flags);
  235. }
  236. static void mcfrs_start(struct tty_struct *tty)
  237. {
  238. volatile unsigned char *uartp;
  239. struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
  240. unsigned long flags;
  241. if (serial_paranoia_check(info, tty->name, "mcfrs_start"))
  242. return;
  243. local_irq_save(flags);
  244. if (info->xmit_cnt && info->xmit_buf) {
  245. uartp = info->addr;
  246. info->imr |= MCFUART_UIR_TXREADY;
  247. uartp[MCFUART_UIMR] = info->imr;
  248. }
  249. local_irq_restore(flags);
  250. }
  251. /*
  252. * ----------------------------------------------------------------------
  253. *
  254. * Here starts the interrupt handling routines. All of the following
  255. * subroutines are declared as inline and are folded into
  256. * mcfrs_interrupt(). They were separated out for readability's sake.
  257. *
  258. * Note: mcfrs_interrupt() is a "fast" interrupt, which means that it
  259. * runs with interrupts turned off. People who may want to modify
  260. * mcfrs_interrupt() should try to keep the interrupt handler as fast as
  261. * possible. After you are done making modifications, it is not a bad
  262. * idea to do:
  263. *
  264. * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
  265. *
  266. * and look at the resulting assemble code in serial.s.
  267. *
  268. * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
  269. * -----------------------------------------------------------------------
  270. */
  271. static inline void receive_chars(struct mcf_serial *info)
  272. {
  273. volatile unsigned char *uartp;
  274. struct tty_struct *tty = info->tty;
  275. unsigned char status, ch;
  276. if (!tty)
  277. return;
  278. uartp = info->addr;
  279. while ((status = uartp[MCFUART_USR]) & MCFUART_USR_RXREADY) {
  280. if (tty->flip.count >= TTY_FLIPBUF_SIZE)
  281. break;
  282. ch = uartp[MCFUART_URB];
  283. info->stats.rx++;
  284. #ifdef CONFIG_MAGIC_SYSRQ
  285. if (mcfrs_console_inited && (info->line == mcfrs_console_port)) {
  286. if (magic_sysrq_key(ch))
  287. continue;
  288. }
  289. #endif
  290. tty->flip.count++;
  291. if (status & MCFUART_USR_RXERR) {
  292. uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETERR;
  293. if (status & MCFUART_USR_RXBREAK) {
  294. info->stats.rxbreak++;
  295. *tty->flip.flag_buf_ptr++ = TTY_BREAK;
  296. } else if (status & MCFUART_USR_RXPARITY) {
  297. info->stats.rxparity++;
  298. *tty->flip.flag_buf_ptr++ = TTY_PARITY;
  299. } else if (status & MCFUART_USR_RXOVERRUN) {
  300. info->stats.rxoverrun++;
  301. *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
  302. } else if (status & MCFUART_USR_RXFRAMING) {
  303. info->stats.rxframing++;
  304. *tty->flip.flag_buf_ptr++ = TTY_FRAME;
  305. } else {
  306. /* This should never happen... */
  307. *tty->flip.flag_buf_ptr++ = 0;
  308. }
  309. } else {
  310. *tty->flip.flag_buf_ptr++ = 0;
  311. }
  312. *tty->flip.char_buf_ptr++ = ch;
  313. }
  314. schedule_work(&tty->flip.work);
  315. return;
  316. }
  317. static inline void transmit_chars(struct mcf_serial *info)
  318. {
  319. volatile unsigned char *uartp;
  320. uartp = info->addr;
  321. if (info->x_char) {
  322. /* Send special char - probably flow control */
  323. uartp[MCFUART_UTB] = info->x_char;
  324. info->x_char = 0;
  325. info->stats.tx++;
  326. }
  327. if ((info->xmit_cnt <= 0) || info->tty->stopped) {
  328. info->imr &= ~MCFUART_UIR_TXREADY;
  329. uartp[MCFUART_UIMR] = info->imr;
  330. return;
  331. }
  332. while (uartp[MCFUART_USR] & MCFUART_USR_TXREADY) {
  333. uartp[MCFUART_UTB] = info->xmit_buf[info->xmit_tail++];
  334. info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
  335. info->stats.tx++;
  336. if (--info->xmit_cnt <= 0)
  337. break;
  338. }
  339. if (info->xmit_cnt < WAKEUP_CHARS)
  340. schedule_work(&info->tqueue);
  341. return;
  342. }
  343. /*
  344. * This is the serial driver's generic interrupt routine
  345. */
  346. irqreturn_t mcfrs_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  347. {
  348. struct mcf_serial *info;
  349. unsigned char isr;
  350. info = &mcfrs_table[(irq - IRQBASE)];
  351. isr = info->addr[MCFUART_UISR] & info->imr;
  352. if (isr & MCFUART_UIR_RXREADY)
  353. receive_chars(info);
  354. if (isr & MCFUART_UIR_TXREADY)
  355. transmit_chars(info);
  356. return IRQ_HANDLED;
  357. }
  358. /*
  359. * -------------------------------------------------------------------
  360. * Here ends the serial interrupt routines.
  361. * -------------------------------------------------------------------
  362. */
  363. static void mcfrs_offintr(void *private)
  364. {
  365. struct mcf_serial *info = (struct mcf_serial *) private;
  366. struct tty_struct *tty;
  367. tty = info->tty;
  368. if (!tty)
  369. return;
  370. tty_wakeup(tty);
  371. }
  372. /*
  373. * Change of state on a DCD line.
  374. */
  375. void mcfrs_modem_change(struct mcf_serial *info, int dcd)
  376. {
  377. if (info->count == 0)
  378. return;
  379. if (info->flags & ASYNC_CHECK_CD) {
  380. if (dcd)
  381. wake_up_interruptible(&info->open_wait);
  382. else
  383. schedule_work(&info->tqueue_hangup);
  384. }
  385. }
  386. #ifdef MCFPP_DCD0
  387. unsigned short mcfrs_ppstatus;
  388. /*
  389. * This subroutine is called when the RS_TIMER goes off. It is used
  390. * to monitor the state of the DCD lines - since they have no edge
  391. * sensors and interrupt generators.
  392. */
  393. static void mcfrs_timer(void)
  394. {
  395. unsigned int ppstatus, dcdval, i;
  396. ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1);
  397. if (ppstatus != mcfrs_ppstatus) {
  398. for (i = 0; (i < 2); i++) {
  399. dcdval = (i ? MCFPP_DCD1 : MCFPP_DCD0);
  400. if ((ppstatus & dcdval) != (mcfrs_ppstatus & dcdval)) {
  401. mcfrs_modem_change(&mcfrs_table[i],
  402. ((ppstatus & dcdval) ? 0 : 1));
  403. }
  404. }
  405. }
  406. mcfrs_ppstatus = ppstatus;
  407. /* Re-arm timer */
  408. mcfrs_timer_struct.expires = jiffies + HZ/25;
  409. add_timer(&mcfrs_timer_struct);
  410. }
  411. #endif /* MCFPP_DCD0 */
  412. /*
  413. * This routine is called from the scheduler tqueue when the interrupt
  414. * routine has signalled that a hangup has occurred. The path of
  415. * hangup processing is:
  416. *
  417. * serial interrupt routine -> (scheduler tqueue) ->
  418. * do_serial_hangup() -> tty->hangup() -> mcfrs_hangup()
  419. *
  420. */
  421. static void do_serial_hangup(void *private)
  422. {
  423. struct mcf_serial *info = (struct mcf_serial *) private;
  424. struct tty_struct *tty;
  425. tty = info->tty;
  426. if (!tty)
  427. return;
  428. tty_hangup(tty);
  429. }
  430. static int startup(struct mcf_serial * info)
  431. {
  432. volatile unsigned char *uartp;
  433. unsigned long flags;
  434. if (info->flags & ASYNC_INITIALIZED)
  435. return 0;
  436. if (!info->xmit_buf) {
  437. info->xmit_buf = (unsigned char *) __get_free_page(GFP_KERNEL);
  438. if (!info->xmit_buf)
  439. return -ENOMEM;
  440. }
  441. local_irq_save(flags);
  442. #ifdef SERIAL_DEBUG_OPEN
  443. printk("starting up ttyS%d (irq %d)...\n", info->line, info->irq);
  444. #endif
  445. /*
  446. * Reset UART, get it into known state...
  447. */
  448. uartp = info->addr;
  449. uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
  450. uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
  451. mcfrs_setsignals(info, 1, 1);
  452. if (info->tty)
  453. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  454. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  455. /*
  456. * and set the speed of the serial port
  457. */
  458. mcfrs_change_speed(info);
  459. /*
  460. * Lastly enable the UART transmitter and receiver, and
  461. * interrupt enables.
  462. */
  463. info->imr = MCFUART_UIR_RXREADY;
  464. uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
  465. uartp[MCFUART_UIMR] = info->imr;
  466. info->flags |= ASYNC_INITIALIZED;
  467. local_irq_restore(flags);
  468. return 0;
  469. }
  470. /*
  471. * This routine will shutdown a serial port; interrupts are disabled, and
  472. * DTR is dropped if the hangup on close termio flag is on.
  473. */
  474. static void shutdown(struct mcf_serial * info)
  475. {
  476. volatile unsigned char *uartp;
  477. unsigned long flags;
  478. if (!(info->flags & ASYNC_INITIALIZED))
  479. return;
  480. #ifdef SERIAL_DEBUG_OPEN
  481. printk("Shutting down serial port %d (irq %d)....\n", info->line,
  482. info->irq);
  483. #endif
  484. local_irq_save(flags);
  485. uartp = info->addr;
  486. uartp[MCFUART_UIMR] = 0; /* mask all interrupts */
  487. uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
  488. uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
  489. if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
  490. mcfrs_setsignals(info, 0, 0);
  491. if (info->xmit_buf) {
  492. free_page((unsigned long) info->xmit_buf);
  493. info->xmit_buf = 0;
  494. }
  495. if (info->tty)
  496. set_bit(TTY_IO_ERROR, &info->tty->flags);
  497. info->flags &= ~ASYNC_INITIALIZED;
  498. local_irq_restore(flags);
  499. }
  500. /*
  501. * This routine is called to set the UART divisor registers to match
  502. * the specified baud rate for a serial port.
  503. */
  504. static void mcfrs_change_speed(struct mcf_serial *info)
  505. {
  506. volatile unsigned char *uartp;
  507. unsigned int baudclk, cflag;
  508. unsigned long flags;
  509. unsigned char mr1, mr2;
  510. int i;
  511. #ifdef CONFIG_M5272
  512. unsigned int fraction;
  513. #endif
  514. if (!info->tty || !info->tty->termios)
  515. return;
  516. cflag = info->tty->termios->c_cflag;
  517. if (info->addr == 0)
  518. return;
  519. #if 0
  520. printk("%s(%d): mcfrs_change_speed()\n", __FILE__, __LINE__);
  521. #endif
  522. i = cflag & CBAUD;
  523. if (i & CBAUDEX) {
  524. i &= ~CBAUDEX;
  525. if (i < 1 || i > 4)
  526. info->tty->termios->c_cflag &= ~CBAUDEX;
  527. else
  528. i += 15;
  529. }
  530. if (i == 0) {
  531. mcfrs_setsignals(info, 0, -1);
  532. return;
  533. }
  534. /* compute the baudrate clock */
  535. #ifdef CONFIG_M5272
  536. /*
  537. * For the MCF5272, also compute the baudrate fraction.
  538. */
  539. baudclk = (MCF_BUSCLK / mcfrs_baud_table[i]) / 32;
  540. fraction = MCF_BUSCLK - (baudclk * 32 * mcfrs_baud_table[i]);
  541. fraction *= 16;
  542. fraction /= (32 * mcfrs_baud_table[i]);
  543. #else
  544. baudclk = ((MCF_BUSCLK / mcfrs_baud_table[i]) + 16) / 32;
  545. #endif
  546. info->baud = mcfrs_baud_table[i];
  547. mr1 = MCFUART_MR1_RXIRQRDY | MCFUART_MR1_RXERRCHAR;
  548. mr2 = 0;
  549. switch (cflag & CSIZE) {
  550. case CS5: mr1 |= MCFUART_MR1_CS5; break;
  551. case CS6: mr1 |= MCFUART_MR1_CS6; break;
  552. case CS7: mr1 |= MCFUART_MR1_CS7; break;
  553. case CS8:
  554. default: mr1 |= MCFUART_MR1_CS8; break;
  555. }
  556. if (cflag & PARENB) {
  557. if (cflag & CMSPAR) {
  558. if (cflag & PARODD)
  559. mr1 |= MCFUART_MR1_PARITYMARK;
  560. else
  561. mr1 |= MCFUART_MR1_PARITYSPACE;
  562. } else {
  563. if (cflag & PARODD)
  564. mr1 |= MCFUART_MR1_PARITYODD;
  565. else
  566. mr1 |= MCFUART_MR1_PARITYEVEN;
  567. }
  568. } else {
  569. mr1 |= MCFUART_MR1_PARITYNONE;
  570. }
  571. if (cflag & CSTOPB)
  572. mr2 |= MCFUART_MR2_STOP2;
  573. else
  574. mr2 |= MCFUART_MR2_STOP1;
  575. if (cflag & CRTSCTS) {
  576. mr1 |= MCFUART_MR1_RXRTS;
  577. mr2 |= MCFUART_MR2_TXCTS;
  578. }
  579. if (cflag & CLOCAL)
  580. info->flags &= ~ASYNC_CHECK_CD;
  581. else
  582. info->flags |= ASYNC_CHECK_CD;
  583. uartp = info->addr;
  584. local_irq_save(flags);
  585. #if 0
  586. printk("%s(%d): mr1=%x mr2=%x baudclk=%x\n", __FILE__, __LINE__,
  587. mr1, mr2, baudclk);
  588. #endif
  589. /*
  590. Note: pg 12-16 of MCF5206e User's Manual states that a
  591. software reset should be performed prior to changing
  592. UMR1,2, UCSR, UACR, bit 7
  593. */
  594. uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
  595. uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
  596. uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
  597. uartp[MCFUART_UMR] = mr1;
  598. uartp[MCFUART_UMR] = mr2;
  599. uartp[MCFUART_UBG1] = (baudclk & 0xff00) >> 8; /* set msb byte */
  600. uartp[MCFUART_UBG2] = (baudclk & 0xff); /* set lsb byte */
  601. #ifdef CONFIG_M5272
  602. uartp[MCFUART_UFPD] = (fraction & 0xf); /* set fraction */
  603. #endif
  604. uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
  605. uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
  606. mcfrs_setsignals(info, 1, -1);
  607. local_irq_restore(flags);
  608. return;
  609. }
  610. static void mcfrs_flush_chars(struct tty_struct *tty)
  611. {
  612. volatile unsigned char *uartp;
  613. struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
  614. unsigned long flags;
  615. if (serial_paranoia_check(info, tty->name, "mcfrs_flush_chars"))
  616. return;
  617. uartp = (volatile unsigned char *) info->addr;
  618. /*
  619. * re-enable receiver interrupt
  620. */
  621. local_irq_save(flags);
  622. if ((!(info->imr & MCFUART_UIR_RXREADY)) &&
  623. (info->flags & ASYNC_INITIALIZED) ) {
  624. info->imr |= MCFUART_UIR_RXREADY;
  625. uartp[MCFUART_UIMR] = info->imr;
  626. }
  627. local_irq_restore(flags);
  628. if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
  629. !info->xmit_buf)
  630. return;
  631. /* Enable transmitter */
  632. local_irq_save(flags);
  633. info->imr |= MCFUART_UIR_TXREADY;
  634. uartp[MCFUART_UIMR] = info->imr;
  635. local_irq_restore(flags);
  636. }
  637. static int mcfrs_write(struct tty_struct * tty,
  638. const unsigned char *buf, int count)
  639. {
  640. volatile unsigned char *uartp;
  641. struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
  642. unsigned long flags;
  643. int c, total = 0;
  644. #if 0
  645. printk("%s(%d): mcfrs_write(tty=%x,buf=%x,count=%d)\n",
  646. __FILE__, __LINE__, (int)tty, (int)buf, count);
  647. #endif
  648. if (serial_paranoia_check(info, tty->name, "mcfrs_write"))
  649. return 0;
  650. if (!tty || !info->xmit_buf)
  651. return 0;
  652. local_save_flags(flags);
  653. while (1) {
  654. local_irq_disable();
  655. c = min(count, (int) min(((int)SERIAL_XMIT_SIZE) - info->xmit_cnt - 1,
  656. ((int)SERIAL_XMIT_SIZE) - info->xmit_head));
  657. local_irq_restore(flags);
  658. if (c <= 0)
  659. break;
  660. memcpy(info->xmit_buf + info->xmit_head, buf, c);
  661. local_irq_disable();
  662. info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
  663. info->xmit_cnt += c;
  664. local_irq_restore(flags);
  665. buf += c;
  666. count -= c;
  667. total += c;
  668. }
  669. local_irq_disable();
  670. uartp = info->addr;
  671. info->imr |= MCFUART_UIR_TXREADY;
  672. uartp[MCFUART_UIMR] = info->imr;
  673. local_irq_restore(flags);
  674. return total;
  675. }
  676. static int mcfrs_write_room(struct tty_struct *tty)
  677. {
  678. struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
  679. int ret;
  680. if (serial_paranoia_check(info, tty->name, "mcfrs_write_room"))
  681. return 0;
  682. ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
  683. if (ret < 0)
  684. ret = 0;
  685. return ret;
  686. }
  687. static int mcfrs_chars_in_buffer(struct tty_struct *tty)
  688. {
  689. struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
  690. if (serial_paranoia_check(info, tty->name, "mcfrs_chars_in_buffer"))
  691. return 0;
  692. return info->xmit_cnt;
  693. }
  694. static void mcfrs_flush_buffer(struct tty_struct *tty)
  695. {
  696. struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
  697. unsigned long flags;
  698. if (serial_paranoia_check(info, tty->name, "mcfrs_flush_buffer"))
  699. return;
  700. local_irq_save(flags);
  701. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  702. local_irq_restore(flags);
  703. tty_wakeup(tty);
  704. }
  705. /*
  706. * ------------------------------------------------------------
  707. * mcfrs_throttle()
  708. *
  709. * This routine is called by the upper-layer tty layer to signal that
  710. * incoming characters should be throttled.
  711. * ------------------------------------------------------------
  712. */
  713. static void mcfrs_throttle(struct tty_struct * tty)
  714. {
  715. struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
  716. #ifdef SERIAL_DEBUG_THROTTLE
  717. char buf[64];
  718. printk("throttle %s: %d....\n", _tty_name(tty, buf),
  719. tty->ldisc.chars_in_buffer(tty));
  720. #endif
  721. if (serial_paranoia_check(info, tty->name, "mcfrs_throttle"))
  722. return;
  723. if (I_IXOFF(tty))
  724. info->x_char = STOP_CHAR(tty);
  725. /* Turn off RTS line (do this atomic) */
  726. }
  727. static void mcfrs_unthrottle(struct tty_struct * tty)
  728. {
  729. struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
  730. #ifdef SERIAL_DEBUG_THROTTLE
  731. char buf[64];
  732. printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
  733. tty->ldisc.chars_in_buffer(tty));
  734. #endif
  735. if (serial_paranoia_check(info, tty->name, "mcfrs_unthrottle"))
  736. return;
  737. if (I_IXOFF(tty)) {
  738. if (info->x_char)
  739. info->x_char = 0;
  740. else
  741. info->x_char = START_CHAR(tty);
  742. }
  743. /* Assert RTS line (do this atomic) */
  744. }
  745. /*
  746. * ------------------------------------------------------------
  747. * mcfrs_ioctl() and friends
  748. * ------------------------------------------------------------
  749. */
  750. static int get_serial_info(struct mcf_serial * info,
  751. struct serial_struct * retinfo)
  752. {
  753. struct serial_struct tmp;
  754. if (!retinfo)
  755. return -EFAULT;
  756. memset(&tmp, 0, sizeof(tmp));
  757. tmp.type = info->type;
  758. tmp.line = info->line;
  759. tmp.port = (unsigned int) info->addr;
  760. tmp.irq = info->irq;
  761. tmp.flags = info->flags;
  762. tmp.baud_base = info->baud_base;
  763. tmp.close_delay = info->close_delay;
  764. tmp.closing_wait = info->closing_wait;
  765. tmp.custom_divisor = info->custom_divisor;
  766. return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0;
  767. }
  768. static int set_serial_info(struct mcf_serial * info,
  769. struct serial_struct * new_info)
  770. {
  771. struct serial_struct new_serial;
  772. struct mcf_serial old_info;
  773. int retval = 0;
  774. if (!new_info)
  775. return -EFAULT;
  776. if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
  777. return -EFAULT;
  778. old_info = *info;
  779. if (!capable(CAP_SYS_ADMIN)) {
  780. if ((new_serial.baud_base != info->baud_base) ||
  781. (new_serial.type != info->type) ||
  782. (new_serial.close_delay != info->close_delay) ||
  783. ((new_serial.flags & ~ASYNC_USR_MASK) !=
  784. (info->flags & ~ASYNC_USR_MASK)))
  785. return -EPERM;
  786. info->flags = ((info->flags & ~ASYNC_USR_MASK) |
  787. (new_serial.flags & ASYNC_USR_MASK));
  788. info->custom_divisor = new_serial.custom_divisor;
  789. goto check_and_exit;
  790. }
  791. if (info->count > 1)
  792. return -EBUSY;
  793. /*
  794. * OK, past this point, all the error checking has been done.
  795. * At this point, we start making changes.....
  796. */
  797. info->baud_base = new_serial.baud_base;
  798. info->flags = ((info->flags & ~ASYNC_FLAGS) |
  799. (new_serial.flags & ASYNC_FLAGS));
  800. info->type = new_serial.type;
  801. info->close_delay = new_serial.close_delay;
  802. info->closing_wait = new_serial.closing_wait;
  803. check_and_exit:
  804. retval = startup(info);
  805. return retval;
  806. }
  807. /*
  808. * get_lsr_info - get line status register info
  809. *
  810. * Purpose: Let user call ioctl() to get info when the UART physically
  811. * is emptied. On bus types like RS485, the transmitter must
  812. * release the bus after transmitting. This must be done when
  813. * the transmit shift register is empty, not be done when the
  814. * transmit holding register is empty. This functionality
  815. * allows an RS485 driver to be written in user space.
  816. */
  817. static int get_lsr_info(struct mcf_serial * info, unsigned int *value)
  818. {
  819. volatile unsigned char *uartp;
  820. unsigned long flags;
  821. unsigned char status;
  822. local_irq_save(flags);
  823. uartp = info->addr;
  824. status = (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY) ? TIOCSER_TEMT : 0;
  825. local_irq_restore(flags);
  826. return put_user(status,value);
  827. }
  828. /*
  829. * This routine sends a break character out the serial port.
  830. */
  831. static void send_break( struct mcf_serial * info, int duration)
  832. {
  833. volatile unsigned char *uartp;
  834. unsigned long flags;
  835. if (!info->addr)
  836. return;
  837. set_current_state(TASK_INTERRUPTIBLE);
  838. uartp = info->addr;
  839. local_irq_save(flags);
  840. uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTART;
  841. schedule_timeout(duration);
  842. uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTOP;
  843. local_irq_restore(flags);
  844. }
  845. static int mcfrs_tiocmget(struct tty_struct *tty, struct file *file)
  846. {
  847. struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
  848. if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
  849. return -ENODEV;
  850. if (tty->flags & (1 << TTY_IO_ERROR))
  851. return -EIO;
  852. return mcfrs_getsignals(info);
  853. }
  854. static int mcfrs_tiocmset(struct tty_struct *tty, struct file *file,
  855. unsigned int set, unsigned int clear)
  856. {
  857. struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
  858. int rts = -1, dtr = -1;
  859. if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
  860. return -ENODEV;
  861. if (tty->flags & (1 << TTY_IO_ERROR))
  862. return -EIO;
  863. if (set & TIOCM_RTS)
  864. rts = 1;
  865. if (set & TIOCM_DTR)
  866. dtr = 1;
  867. if (clear & TIOCM_RTS)
  868. rts = 0;
  869. if (clear & TIOCM_DTR)
  870. dtr = 0;
  871. mcfrs_setsignals(info, dtr, rts);
  872. return 0;
  873. }
  874. static int mcfrs_ioctl(struct tty_struct *tty, struct file * file,
  875. unsigned int cmd, unsigned long arg)
  876. {
  877. struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
  878. int retval, error;
  879. if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
  880. return -ENODEV;
  881. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  882. (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
  883. (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {
  884. if (tty->flags & (1 << TTY_IO_ERROR))
  885. return -EIO;
  886. }
  887. switch (cmd) {
  888. case TCSBRK: /* SVID version: non-zero arg --> no break */
  889. retval = tty_check_change(tty);
  890. if (retval)
  891. return retval;
  892. tty_wait_until_sent(tty, 0);
  893. if (!arg)
  894. send_break(info, HZ/4); /* 1/4 second */
  895. return 0;
  896. case TCSBRKP: /* support for POSIX tcsendbreak() */
  897. retval = tty_check_change(tty);
  898. if (retval)
  899. return retval;
  900. tty_wait_until_sent(tty, 0);
  901. send_break(info, arg ? arg*(HZ/10) : HZ/4);
  902. return 0;
  903. case TIOCGSOFTCAR:
  904. error = put_user(C_CLOCAL(tty) ? 1 : 0,
  905. (unsigned long *) arg);
  906. if (error)
  907. return error;
  908. return 0;
  909. case TIOCSSOFTCAR:
  910. get_user(arg, (unsigned long *) arg);
  911. tty->termios->c_cflag =
  912. ((tty->termios->c_cflag & ~CLOCAL) |
  913. (arg ? CLOCAL : 0));
  914. return 0;
  915. case TIOCGSERIAL:
  916. if (access_ok(VERIFY_WRITE, (void *) arg,
  917. sizeof(struct serial_struct)))
  918. return get_serial_info(info,
  919. (struct serial_struct *) arg);
  920. return -EFAULT;
  921. case TIOCSSERIAL:
  922. return set_serial_info(info,
  923. (struct serial_struct *) arg);
  924. case TIOCSERGETLSR: /* Get line status register */
  925. if (access_ok(VERIFY_WRITE, (void *) arg,
  926. sizeof(unsigned int)))
  927. return get_lsr_info(info, (unsigned int *) arg);
  928. return -EFAULT;
  929. case TIOCSERGSTRUCT:
  930. error = copy_to_user((struct mcf_serial *) arg,
  931. info, sizeof(struct mcf_serial));
  932. if (error)
  933. return -EFAULT;
  934. return 0;
  935. #ifdef TIOCSET422
  936. case TIOCSET422: {
  937. unsigned int val;
  938. get_user(val, (unsigned int *) arg);
  939. mcf_setpa(MCFPP_PA11, (val ? 0 : MCFPP_PA11));
  940. break;
  941. }
  942. case TIOCGET422: {
  943. unsigned int val;
  944. val = (mcf_getpa() & MCFPP_PA11) ? 0 : 1;
  945. put_user(val, (unsigned int *) arg);
  946. break;
  947. }
  948. #endif
  949. default:
  950. return -ENOIOCTLCMD;
  951. }
  952. return 0;
  953. }
  954. static void mcfrs_set_termios(struct tty_struct *tty, struct termios *old_termios)
  955. {
  956. struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
  957. if (tty->termios->c_cflag == old_termios->c_cflag)
  958. return;
  959. mcfrs_change_speed(info);
  960. if ((old_termios->c_cflag & CRTSCTS) &&
  961. !(tty->termios->c_cflag & CRTSCTS)) {
  962. tty->hw_stopped = 0;
  963. mcfrs_setsignals(info, -1, 1);
  964. #if 0
  965. mcfrs_start(tty);
  966. #endif
  967. }
  968. }
  969. /*
  970. * ------------------------------------------------------------
  971. * mcfrs_close()
  972. *
  973. * This routine is called when the serial port gets closed. First, we
  974. * wait for the last remaining data to be sent. Then, we unlink its
  975. * S structure from the interrupt chain if necessary, and we free
  976. * that IRQ if nothing is left in the chain.
  977. * ------------------------------------------------------------
  978. */
  979. static void mcfrs_close(struct tty_struct *tty, struct file * filp)
  980. {
  981. volatile unsigned char *uartp;
  982. struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
  983. unsigned long flags;
  984. if (!info || serial_paranoia_check(info, tty->name, "mcfrs_close"))
  985. return;
  986. local_irq_save(flags);
  987. if (tty_hung_up_p(filp)) {
  988. local_irq_restore(flags);
  989. return;
  990. }
  991. #ifdef SERIAL_DEBUG_OPEN
  992. printk("mcfrs_close ttyS%d, count = %d\n", info->line, info->count);
  993. #endif
  994. if ((tty->count == 1) && (info->count != 1)) {
  995. /*
  996. * Uh, oh. tty->count is 1, which means that the tty
  997. * structure will be freed. Info->count should always
  998. * be one in these conditions. If it's greater than
  999. * one, we've got real problems, since it means the
  1000. * serial port won't be shutdown.
  1001. */
  1002. printk("MCFRS: bad serial port count; tty->count is 1, "
  1003. "info->count is %d\n", info->count);
  1004. info->count = 1;
  1005. }
  1006. if (--info->count < 0) {
  1007. printk("MCFRS: bad serial port count for ttyS%d: %d\n",
  1008. info->line, info->count);
  1009. info->count = 0;
  1010. }
  1011. if (info->count) {
  1012. local_irq_restore(flags);
  1013. return;
  1014. }
  1015. info->flags |= ASYNC_CLOSING;
  1016. /*
  1017. * Now we wait for the transmit buffer to clear; and we notify
  1018. * the line discipline to only process XON/XOFF characters.
  1019. */
  1020. tty->closing = 1;
  1021. if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  1022. tty_wait_until_sent(tty, info->closing_wait);
  1023. /*
  1024. * At this point we stop accepting input. To do this, we
  1025. * disable the receive line status interrupts, and tell the
  1026. * interrupt driver to stop checking the data ready bit in the
  1027. * line status register.
  1028. */
  1029. info->imr &= ~MCFUART_UIR_RXREADY;
  1030. uartp = info->addr;
  1031. uartp[MCFUART_UIMR] = info->imr;
  1032. #if 0
  1033. /* FIXME: do we need to keep this enabled for console?? */
  1034. if (mcfrs_console_inited && (mcfrs_console_port == info->line)) {
  1035. /* Do not disable the UART */ ;
  1036. } else
  1037. #endif
  1038. shutdown(info);
  1039. if (tty->driver->flush_buffer)
  1040. tty->driver->flush_buffer(tty);
  1041. tty_ldisc_flush(tty);
  1042. tty->closing = 0;
  1043. info->event = 0;
  1044. info->tty = 0;
  1045. #if 0
  1046. if (tty->ldisc.num != ldiscs[N_TTY].num) {
  1047. if (tty->ldisc.close)
  1048. (tty->ldisc.close)(tty);
  1049. tty->ldisc = ldiscs[N_TTY];
  1050. tty->termios->c_line = N_TTY;
  1051. if (tty->ldisc.open)
  1052. (tty->ldisc.open)(tty);
  1053. }
  1054. #endif
  1055. if (info->blocked_open) {
  1056. if (info->close_delay) {
  1057. msleep_interruptible(jiffies_to_msecs(info->close_delay));
  1058. }
  1059. wake_up_interruptible(&info->open_wait);
  1060. }
  1061. info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  1062. wake_up_interruptible(&info->close_wait);
  1063. local_irq_restore(flags);
  1064. }
  1065. /*
  1066. * mcfrs_wait_until_sent() --- wait until the transmitter is empty
  1067. */
  1068. static void
  1069. mcfrs_wait_until_sent(struct tty_struct *tty, int timeout)
  1070. {
  1071. #ifdef CONFIG_M5272
  1072. #define MCF5272_FIFO_SIZE 25 /* fifo size + shift reg */
  1073. struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
  1074. volatile unsigned char *uartp;
  1075. unsigned long orig_jiffies, fifo_time, char_time, fifo_cnt;
  1076. if (serial_paranoia_check(info, tty->name, "mcfrs_wait_until_sent"))
  1077. return;
  1078. orig_jiffies = jiffies;
  1079. /*
  1080. * Set the check interval to be 1/5 of the approximate time
  1081. * to send the entire fifo, and make it at least 1. The check
  1082. * interval should also be less than the timeout.
  1083. *
  1084. * Note: we have to use pretty tight timings here to satisfy
  1085. * the NIST-PCTS.
  1086. */
  1087. fifo_time = (MCF5272_FIFO_SIZE * HZ * 10) / info->baud;
  1088. char_time = fifo_time / 5;
  1089. if (char_time == 0)
  1090. char_time = 1;
  1091. if (timeout && timeout < char_time)
  1092. char_time = timeout;
  1093. /*
  1094. * Clamp the timeout period at 2 * the time to empty the
  1095. * fifo. Just to be safe, set the minimum at .5 seconds.
  1096. */
  1097. fifo_time *= 2;
  1098. if (fifo_time < (HZ/2))
  1099. fifo_time = HZ/2;
  1100. if (!timeout || timeout > fifo_time)
  1101. timeout = fifo_time;
  1102. /*
  1103. * Account for the number of bytes in the UART
  1104. * transmitter FIFO plus any byte being shifted out.
  1105. */
  1106. uartp = (volatile unsigned char *) info->addr;
  1107. for (;;) {
  1108. fifo_cnt = (uartp[MCFUART_UTF] & MCFUART_UTF_TXB);
  1109. if ((uartp[MCFUART_USR] & (MCFUART_USR_TXREADY|
  1110. MCFUART_USR_TXEMPTY)) ==
  1111. MCFUART_USR_TXREADY)
  1112. fifo_cnt++;
  1113. if (fifo_cnt == 0)
  1114. break;
  1115. msleep_interruptible(jiffies_to_msecs(char_time));
  1116. if (signal_pending(current))
  1117. break;
  1118. if (timeout && time_after(jiffies, orig_jiffies + timeout))
  1119. break;
  1120. }
  1121. #else
  1122. /*
  1123. * For the other coldfire models, assume all data has been sent
  1124. */
  1125. #endif
  1126. }
  1127. /*
  1128. * mcfrs_hangup() --- called by tty_hangup() when a hangup is signaled.
  1129. */
  1130. void mcfrs_hangup(struct tty_struct *tty)
  1131. {
  1132. struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
  1133. if (serial_paranoia_check(info, tty->name, "mcfrs_hangup"))
  1134. return;
  1135. mcfrs_flush_buffer(tty);
  1136. shutdown(info);
  1137. info->event = 0;
  1138. info->count = 0;
  1139. info->flags &= ~ASYNC_NORMAL_ACTIVE;
  1140. info->tty = 0;
  1141. wake_up_interruptible(&info->open_wait);
  1142. }
  1143. /*
  1144. * ------------------------------------------------------------
  1145. * mcfrs_open() and friends
  1146. * ------------------------------------------------------------
  1147. */
  1148. static int block_til_ready(struct tty_struct *tty, struct file * filp,
  1149. struct mcf_serial *info)
  1150. {
  1151. DECLARE_WAITQUEUE(wait, current);
  1152. int retval;
  1153. int do_clocal = 0;
  1154. /*
  1155. * If the device is in the middle of being closed, then block
  1156. * until it's done, and then try again.
  1157. */
  1158. if (info->flags & ASYNC_CLOSING) {
  1159. interruptible_sleep_on(&info->close_wait);
  1160. #ifdef SERIAL_DO_RESTART
  1161. if (info->flags & ASYNC_HUP_NOTIFY)
  1162. return -EAGAIN;
  1163. else
  1164. return -ERESTARTSYS;
  1165. #else
  1166. return -EAGAIN;
  1167. #endif
  1168. }
  1169. /*
  1170. * If non-blocking mode is set, or the port is not enabled,
  1171. * then make the check up front and then exit.
  1172. */
  1173. if ((filp->f_flags & O_NONBLOCK) ||
  1174. (tty->flags & (1 << TTY_IO_ERROR))) {
  1175. info->flags |= ASYNC_NORMAL_ACTIVE;
  1176. return 0;
  1177. }
  1178. if (tty->termios->c_cflag & CLOCAL)
  1179. do_clocal = 1;
  1180. /*
  1181. * Block waiting for the carrier detect and the line to become
  1182. * free (i.e., not in use by the callout). While we are in
  1183. * this loop, info->count is dropped by one, so that
  1184. * mcfrs_close() knows when to free things. We restore it upon
  1185. * exit, either normal or abnormal.
  1186. */
  1187. retval = 0;
  1188. add_wait_queue(&info->open_wait, &wait);
  1189. #ifdef SERIAL_DEBUG_OPEN
  1190. printk("block_til_ready before block: ttyS%d, count = %d\n",
  1191. info->line, info->count);
  1192. #endif
  1193. info->count--;
  1194. info->blocked_open++;
  1195. while (1) {
  1196. local_irq_disable();
  1197. mcfrs_setsignals(info, 1, 1);
  1198. local_irq_enable();
  1199. current->state = TASK_INTERRUPTIBLE;
  1200. if (tty_hung_up_p(filp) ||
  1201. !(info->flags & ASYNC_INITIALIZED)) {
  1202. #ifdef SERIAL_DO_RESTART
  1203. if (info->flags & ASYNC_HUP_NOTIFY)
  1204. retval = -EAGAIN;
  1205. else
  1206. retval = -ERESTARTSYS;
  1207. #else
  1208. retval = -EAGAIN;
  1209. #endif
  1210. break;
  1211. }
  1212. if (!(info->flags & ASYNC_CLOSING) &&
  1213. (do_clocal || (mcfrs_getsignals(info) & TIOCM_CD)))
  1214. break;
  1215. if (signal_pending(current)) {
  1216. retval = -ERESTARTSYS;
  1217. break;
  1218. }
  1219. #ifdef SERIAL_DEBUG_OPEN
  1220. printk("block_til_ready blocking: ttyS%d, count = %d\n",
  1221. info->line, info->count);
  1222. #endif
  1223. schedule();
  1224. }
  1225. current->state = TASK_RUNNING;
  1226. remove_wait_queue(&info->open_wait, &wait);
  1227. if (!tty_hung_up_p(filp))
  1228. info->count++;
  1229. info->blocked_open--;
  1230. #ifdef SERIAL_DEBUG_OPEN
  1231. printk("block_til_ready after blocking: ttyS%d, count = %d\n",
  1232. info->line, info->count);
  1233. #endif
  1234. if (retval)
  1235. return retval;
  1236. info->flags |= ASYNC_NORMAL_ACTIVE;
  1237. return 0;
  1238. }
  1239. /*
  1240. * This routine is called whenever a serial port is opened. It
  1241. * enables interrupts for a serial port, linking in its structure into
  1242. * the IRQ chain. It also performs the serial-specific
  1243. * initialization for the tty structure.
  1244. */
  1245. int mcfrs_open(struct tty_struct *tty, struct file * filp)
  1246. {
  1247. struct mcf_serial *info;
  1248. int retval, line;
  1249. line = tty->index;
  1250. if ((line < 0) || (line >= NR_PORTS))
  1251. return -ENODEV;
  1252. info = mcfrs_table + line;
  1253. if (serial_paranoia_check(info, tty->name, "mcfrs_open"))
  1254. return -ENODEV;
  1255. #ifdef SERIAL_DEBUG_OPEN
  1256. printk("mcfrs_open %s, count = %d\n", tty->name, info->count);
  1257. #endif
  1258. info->count++;
  1259. tty->driver_data = info;
  1260. info->tty = tty;
  1261. /*
  1262. * Start up serial port
  1263. */
  1264. retval = startup(info);
  1265. if (retval)
  1266. return retval;
  1267. retval = block_til_ready(tty, filp, info);
  1268. if (retval) {
  1269. #ifdef SERIAL_DEBUG_OPEN
  1270. printk("mcfrs_open returning after block_til_ready with %d\n",
  1271. retval);
  1272. #endif
  1273. return retval;
  1274. }
  1275. #ifdef SERIAL_DEBUG_OPEN
  1276. printk("mcfrs_open %s successful...\n", tty->name);
  1277. #endif
  1278. return 0;
  1279. }
  1280. /*
  1281. * Based on the line number set up the internal interrupt stuff.
  1282. */
  1283. static void mcfrs_irqinit(struct mcf_serial *info)
  1284. {
  1285. #if defined(CONFIG_M5272)
  1286. volatile unsigned long *icrp;
  1287. volatile unsigned long *portp;
  1288. volatile unsigned char *uartp;
  1289. uartp = info->addr;
  1290. icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR2);
  1291. switch (info->line) {
  1292. case 0:
  1293. *icrp = 0xe0000000;
  1294. break;
  1295. case 1:
  1296. *icrp = 0x0e000000;
  1297. break;
  1298. default:
  1299. printk("MCFRS: don't know how to handle UART %d interrupt?\n",
  1300. info->line);
  1301. return;
  1302. }
  1303. /* Enable the output lines for the serial ports */
  1304. portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PBCNT);
  1305. *portp = (*portp & ~0x000000ff) | 0x00000055;
  1306. portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PDCNT);
  1307. *portp = (*portp & ~0x000003fc) | 0x000002a8;
  1308. #elif defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
  1309. volatile unsigned char *icrp, *uartp;
  1310. volatile unsigned long *imrp;
  1311. uartp = info->addr;
  1312. icrp = (volatile unsigned char *) (MCF_MBAR + MCFICM_INTC0 +
  1313. MCFINTC_ICR0 + MCFINT_UART0 + info->line);
  1314. *icrp = 0x33; /* UART0 with level 6, priority 3 */
  1315. imrp = (volatile unsigned long *) (MCF_MBAR + MCFICM_INTC0 +
  1316. MCFINTC_IMRL);
  1317. *imrp &= ~((1 << (info->irq - MCFINT_VECBASE)) | 1);
  1318. #else
  1319. volatile unsigned char *icrp, *uartp;
  1320. switch (info->line) {
  1321. case 0:
  1322. icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART1ICR);
  1323. *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 |
  1324. MCFSIM_ICR_PRI1;
  1325. mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART1);
  1326. break;
  1327. case 1:
  1328. icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART2ICR);
  1329. *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 |
  1330. MCFSIM_ICR_PRI2;
  1331. mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART2);
  1332. break;
  1333. default:
  1334. printk("MCFRS: don't know how to handle UART %d interrupt?\n",
  1335. info->line);
  1336. return;
  1337. }
  1338. uartp = info->addr;
  1339. uartp[MCFUART_UIVR] = info->irq;
  1340. #endif
  1341. /* Clear mask, so no surprise interrupts. */
  1342. uartp[MCFUART_UIMR] = 0;
  1343. if (request_irq(info->irq, mcfrs_interrupt, SA_INTERRUPT,
  1344. "ColdFire UART", NULL)) {
  1345. printk("MCFRS: Unable to attach ColdFire UART %d interrupt "
  1346. "vector=%d\n", info->line, info->irq);
  1347. }
  1348. return;
  1349. }
  1350. char *mcfrs_drivername = "ColdFire internal UART serial driver version 1.00\n";
  1351. /*
  1352. * Serial stats reporting...
  1353. */
  1354. int mcfrs_readproc(char *page, char **start, off_t off, int count,
  1355. int *eof, void *data)
  1356. {
  1357. struct mcf_serial *info;
  1358. char str[20];
  1359. int len, sigs, i;
  1360. len = sprintf(page, mcfrs_drivername);
  1361. for (i = 0; (i < NR_PORTS); i++) {
  1362. info = &mcfrs_table[i];
  1363. len += sprintf((page + len), "%d: port:%x irq=%d baud:%d ",
  1364. i, (unsigned int) info->addr, info->irq, info->baud);
  1365. if (info->stats.rx || info->stats.tx)
  1366. len += sprintf((page + len), "tx:%d rx:%d ",
  1367. info->stats.tx, info->stats.rx);
  1368. if (info->stats.rxframing)
  1369. len += sprintf((page + len), "fe:%d ",
  1370. info->stats.rxframing);
  1371. if (info->stats.rxparity)
  1372. len += sprintf((page + len), "pe:%d ",
  1373. info->stats.rxparity);
  1374. if (info->stats.rxbreak)
  1375. len += sprintf((page + len), "brk:%d ",
  1376. info->stats.rxbreak);
  1377. if (info->stats.rxoverrun)
  1378. len += sprintf((page + len), "oe:%d ",
  1379. info->stats.rxoverrun);
  1380. str[0] = str[1] = 0;
  1381. if ((sigs = mcfrs_getsignals(info))) {
  1382. if (sigs & TIOCM_RTS)
  1383. strcat(str, "|RTS");
  1384. if (sigs & TIOCM_CTS)
  1385. strcat(str, "|CTS");
  1386. if (sigs & TIOCM_DTR)
  1387. strcat(str, "|DTR");
  1388. if (sigs & TIOCM_CD)
  1389. strcat(str, "|CD");
  1390. }
  1391. len += sprintf((page + len), "%s\n", &str[1]);
  1392. }
  1393. return(len);
  1394. }
  1395. /* Finally, routines used to initialize the serial driver. */
  1396. static void show_serial_version(void)
  1397. {
  1398. printk(mcfrs_drivername);
  1399. }
  1400. static struct tty_operations mcfrs_ops = {
  1401. .open = mcfrs_open,
  1402. .close = mcfrs_close,
  1403. .write = mcfrs_write,
  1404. .flush_chars = mcfrs_flush_chars,
  1405. .write_room = mcfrs_write_room,
  1406. .chars_in_buffer = mcfrs_chars_in_buffer,
  1407. .flush_buffer = mcfrs_flush_buffer,
  1408. .ioctl = mcfrs_ioctl,
  1409. .throttle = mcfrs_throttle,
  1410. .unthrottle = mcfrs_unthrottle,
  1411. .set_termios = mcfrs_set_termios,
  1412. .stop = mcfrs_stop,
  1413. .start = mcfrs_start,
  1414. .hangup = mcfrs_hangup,
  1415. .read_proc = mcfrs_readproc,
  1416. .wait_until_sent = mcfrs_wait_until_sent,
  1417. .tiocmget = mcfrs_tiocmget,
  1418. .tiocmset = mcfrs_tiocmset,
  1419. };
  1420. /* mcfrs_init inits the driver */
  1421. static int __init
  1422. mcfrs_init(void)
  1423. {
  1424. struct mcf_serial *info;
  1425. unsigned long flags;
  1426. int i;
  1427. /* Setup base handler, and timer table. */
  1428. #ifdef MCFPP_DCD0
  1429. init_timer(&mcfrs_timer_struct);
  1430. mcfrs_timer_struct.function = mcfrs_timer;
  1431. mcfrs_timer_struct.data = 0;
  1432. mcfrs_timer_struct.expires = jiffies + HZ/25;
  1433. add_timer(&mcfrs_timer_struct);
  1434. mcfrs_ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1);
  1435. #endif
  1436. mcfrs_serial_driver = alloc_tty_driver(NR_PORTS);
  1437. if (!mcfrs_serial_driver)
  1438. return -ENOMEM;
  1439. show_serial_version();
  1440. /* Initialize the tty_driver structure */
  1441. mcfrs_serial_driver->owner = THIS_MODULE;
  1442. mcfrs_serial_driver->name = "ttyS";
  1443. mcfrs_serial_driver->devfs_name = "ttys/";
  1444. mcfrs_serial_driver->driver_name = "serial";
  1445. mcfrs_serial_driver->major = TTY_MAJOR;
  1446. mcfrs_serial_driver->minor_start = 64;
  1447. mcfrs_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
  1448. mcfrs_serial_driver->subtype = SERIAL_TYPE_NORMAL;
  1449. mcfrs_serial_driver->init_termios = tty_std_termios;
  1450. mcfrs_serial_driver->init_termios.c_cflag =
  1451. mcfrs_console_cbaud | CS8 | CREAD | HUPCL | CLOCAL;
  1452. mcfrs_serial_driver->flags = TTY_DRIVER_REAL_RAW;
  1453. tty_set_operations(mcfrs_serial_driver, &mcfrs_ops);
  1454. if (tty_register_driver(mcfrs_serial_driver)) {
  1455. printk("MCFRS: Couldn't register serial driver\n");
  1456. put_tty_driver(mcfrs_serial_driver);
  1457. return(-EBUSY);
  1458. }
  1459. local_irq_save(flags);
  1460. /*
  1461. * Configure all the attached serial ports.
  1462. */
  1463. for (i = 0, info = mcfrs_table; (i < NR_PORTS); i++, info++) {
  1464. info->magic = SERIAL_MAGIC;
  1465. info->line = i;
  1466. info->tty = 0;
  1467. info->custom_divisor = 16;
  1468. info->close_delay = 50;
  1469. info->closing_wait = 3000;
  1470. info->x_char = 0;
  1471. info->event = 0;
  1472. info->count = 0;
  1473. info->blocked_open = 0;
  1474. INIT_WORK(&info->tqueue, mcfrs_offintr, info);
  1475. INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info);
  1476. init_waitqueue_head(&info->open_wait);
  1477. init_waitqueue_head(&info->close_wait);
  1478. info->imr = 0;
  1479. mcfrs_setsignals(info, 0, 0);
  1480. mcfrs_irqinit(info);
  1481. printk("ttyS%d at 0x%04x (irq = %d)", info->line,
  1482. (unsigned int) info->addr, info->irq);
  1483. printk(" is a builtin ColdFire UART\n");
  1484. }
  1485. local_irq_restore(flags);
  1486. return 0;
  1487. }
  1488. module_init(mcfrs_init);
  1489. /****************************************************************************/
  1490. /* Serial Console */
  1491. /****************************************************************************/
  1492. /*
  1493. * Quick and dirty UART initialization, for console output.
  1494. */
  1495. void mcfrs_init_console(void)
  1496. {
  1497. volatile unsigned char *uartp;
  1498. unsigned int clk;
  1499. /*
  1500. * Reset UART, get it into known state...
  1501. */
  1502. uartp = (volatile unsigned char *) (MCF_MBAR +
  1503. (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1));
  1504. uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
  1505. uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
  1506. uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
  1507. /*
  1508. * Set port for defined baud , 8 data bits, 1 stop bit, no parity.
  1509. */
  1510. uartp[MCFUART_UMR] = MCFUART_MR1_PARITYNONE | MCFUART_MR1_CS8;
  1511. uartp[MCFUART_UMR] = MCFUART_MR2_STOP1;
  1512. clk = ((MCF_BUSCLK / mcfrs_console_baud) + 16) / 32; /* set baud */
  1513. uartp[MCFUART_UBG1] = (clk & 0xff00) >> 8; /* set msb baud */
  1514. uartp[MCFUART_UBG2] = (clk & 0xff); /* set lsb baud */
  1515. uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
  1516. uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
  1517. mcfrs_console_inited++;
  1518. return;
  1519. }
  1520. /*
  1521. * Setup for console. Argument comes from the boot command line.
  1522. */
  1523. int mcfrs_console_setup(struct console *cp, char *arg)
  1524. {
  1525. int i, n = CONSOLE_BAUD_RATE;
  1526. if (!cp)
  1527. return(-1);
  1528. if (!strncmp(cp->name, "ttyS", 4))
  1529. mcfrs_console_port = cp->index;
  1530. else if (!strncmp(cp->name, "cua", 3))
  1531. mcfrs_console_port = cp->index;
  1532. else
  1533. return(-1);
  1534. if (arg)
  1535. n = simple_strtoul(arg,NULL,0);
  1536. for (i = 0; i < MCFRS_BAUD_TABLE_SIZE; i++)
  1537. if (mcfrs_baud_table[i] == n)
  1538. break;
  1539. if (i < MCFRS_BAUD_TABLE_SIZE) {
  1540. mcfrs_console_baud = n;
  1541. mcfrs_console_cbaud = 0;
  1542. if (i > 15) {
  1543. mcfrs_console_cbaud |= CBAUDEX;
  1544. i -= 15;
  1545. }
  1546. mcfrs_console_cbaud |= i;
  1547. }
  1548. mcfrs_init_console(); /* make sure baud rate changes */
  1549. return(0);
  1550. }
  1551. static struct tty_driver *mcfrs_console_device(struct console *c, int *index)
  1552. {
  1553. *index = c->index;
  1554. return mcfrs_serial_driver;
  1555. }
  1556. /*
  1557. * Output a single character, using UART polled mode.
  1558. * This is used for console output.
  1559. */
  1560. void mcfrs_put_char(char ch)
  1561. {
  1562. volatile unsigned char *uartp;
  1563. unsigned long flags;
  1564. int i;
  1565. uartp = (volatile unsigned char *) (MCF_MBAR +
  1566. (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1));
  1567. local_irq_save(flags);
  1568. for (i = 0; (i < 0x10000); i++) {
  1569. if (uartp[MCFUART_USR] & MCFUART_USR_TXREADY)
  1570. break;
  1571. }
  1572. if (i < 0x10000) {
  1573. uartp[MCFUART_UTB] = ch;
  1574. for (i = 0; (i < 0x10000); i++)
  1575. if (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY)
  1576. break;
  1577. }
  1578. if (i >= 0x10000)
  1579. mcfrs_init_console(); /* try and get it back */
  1580. local_irq_restore(flags);
  1581. return;
  1582. }
  1583. /*
  1584. * rs_console_write is registered for printk output.
  1585. */
  1586. void mcfrs_console_write(struct console *cp, const char *p, unsigned len)
  1587. {
  1588. if (!mcfrs_console_inited)
  1589. mcfrs_init_console();
  1590. while (len-- > 0) {
  1591. if (*p == '\n')
  1592. mcfrs_put_char('\r');
  1593. mcfrs_put_char(*p++);
  1594. }
  1595. }
  1596. /*
  1597. * declare our consoles
  1598. */
  1599. struct console mcfrs_console = {
  1600. .name = "ttyS",
  1601. .write = mcfrs_console_write,
  1602. .device = mcfrs_console_device,
  1603. .setup = mcfrs_console_setup,
  1604. .flags = CON_PRINTBUFFER,
  1605. .index = -1,
  1606. };
  1607. static int __init mcfrs_console_init(void)
  1608. {
  1609. register_console(&mcfrs_console);
  1610. return 0;
  1611. }
  1612. console_initcall(mcfrs_console_init);
  1613. /****************************************************************************/