mcfserial.c 46 KB

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