mcfserial.c 46 KB

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