68328serial.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  1. /* 68328serial.c: Serial port driver for 68328 microcontroller
  2. *
  3. * Copyright (C) 1995 David S. Miller <davem@caip.rutgers.edu>
  4. * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>
  5. * Copyright (C) 1998, 1999 D. Jeff Dionne <jeff@uclinux.org>
  6. * Copyright (C) 1999 Vladimir Gurevich <vgurevic@cisco.com>
  7. * Copyright (C) 2002-2003 David McCullough <davidm@snapgear.com>
  8. * Copyright (C) 2002 Greg Ungerer <gerg@snapgear.com>
  9. *
  10. * VZ Support/Fixes Evan Stawnyczy <e@lineo.ca>
  11. * Multiple UART support Daniel Potts <danielp@cse.unsw.edu.au>
  12. * Power management support Daniel Potts <danielp@cse.unsw.edu.au>
  13. * VZ Second Serial Port enable Phil Wilshire
  14. * 2.4/2.5 port David McCullough
  15. */
  16. #include <asm/dbg.h>
  17. #include <linux/module.h>
  18. #include <linux/errno.h>
  19. #include <linux/serial.h>
  20. #include <linux/signal.h>
  21. #include <linux/sched.h>
  22. #include <linux/timer.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/tty.h>
  25. #include <linux/tty_flip.h>
  26. #include <linux/major.h>
  27. #include <linux/string.h>
  28. #include <linux/fcntl.h>
  29. #include <linux/mm.h>
  30. #include <linux/kernel.h>
  31. #include <linux/console.h>
  32. #include <linux/reboot.h>
  33. #include <linux/keyboard.h>
  34. #include <linux/init.h>
  35. #include <linux/pm.h>
  36. #include <linux/bitops.h>
  37. #include <linux/delay.h>
  38. #include <linux/gfp.h>
  39. #include <asm/io.h>
  40. #include <asm/irq.h>
  41. #include <asm/delay.h>
  42. #include <asm/uaccess.h>
  43. /* (es) */
  44. /* note: perhaps we can murge these files, so that you can just
  45. * define 1 of them, and they can sort that out for themselves
  46. */
  47. #if defined(CONFIG_M68EZ328)
  48. #include <asm/MC68EZ328.h>
  49. #else
  50. #if defined(CONFIG_M68VZ328)
  51. #include <asm/MC68VZ328.h>
  52. #else
  53. #include <asm/MC68328.h>
  54. #endif /* CONFIG_M68VZ328 */
  55. #endif /* CONFIG_M68EZ328 */
  56. #include "68328serial.h"
  57. /* Turn off usage of real serial interrupt code, to "support" Copilot */
  58. #ifdef CONFIG_XCOPILOT_BUGS
  59. #undef USE_INTS
  60. #else
  61. #define USE_INTS
  62. #endif
  63. static struct m68k_serial m68k_soft[NR_PORTS];
  64. static unsigned int uart_irqs[NR_PORTS] = UART_IRQ_DEFNS;
  65. /* multiple ports are contiguous in memory */
  66. m68328_uart *uart_addr = (m68328_uart *)USTCNT_ADDR;
  67. struct tty_struct m68k_ttys;
  68. struct m68k_serial *m68k_consinfo = 0;
  69. #define M68K_CLOCK (16667000) /* FIXME: 16MHz is likely wrong */
  70. struct tty_driver *serial_driver;
  71. static void change_speed(struct m68k_serial *info);
  72. /*
  73. * Setup for console. Argument comes from the boot command line.
  74. */
  75. /* note: this is messy, but it works, again, perhaps defined somewhere else?*/
  76. #ifdef CONFIG_M68VZ328
  77. #define CONSOLE_BAUD_RATE 19200
  78. #define DEFAULT_CBAUD B19200
  79. #endif
  80. #ifndef CONSOLE_BAUD_RATE
  81. #define CONSOLE_BAUD_RATE 9600
  82. #define DEFAULT_CBAUD B9600
  83. #endif
  84. static int m68328_console_initted = 0;
  85. static int m68328_console_baud = CONSOLE_BAUD_RATE;
  86. static int m68328_console_cbaud = DEFAULT_CBAUD;
  87. static inline int serial_paranoia_check(struct m68k_serial *info,
  88. char *name, const char *routine)
  89. {
  90. #ifdef SERIAL_PARANOIA_CHECK
  91. static const char *badmagic =
  92. "Warning: bad magic number for serial struct %s in %s\n";
  93. static const char *badinfo =
  94. "Warning: null m68k_serial for %s in %s\n";
  95. if (!info) {
  96. printk(badinfo, name, routine);
  97. return 1;
  98. }
  99. if (info->magic != SERIAL_MAGIC) {
  100. printk(badmagic, name, routine);
  101. return 1;
  102. }
  103. #endif
  104. return 0;
  105. }
  106. /*
  107. * This is used to figure out the divisor speeds and the timeouts
  108. */
  109. static int baud_table[] = {
  110. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
  111. 9600, 19200, 38400, 57600, 115200, 0 };
  112. /* Sets or clears DTR/RTS on the requested line */
  113. static inline void m68k_rtsdtr(struct m68k_serial *ss, int set)
  114. {
  115. if (set) {
  116. /* set the RTS/CTS line */
  117. } else {
  118. /* clear it */
  119. }
  120. return;
  121. }
  122. /* Utility routines */
  123. static inline int get_baud(struct m68k_serial *ss)
  124. {
  125. unsigned long result = 115200;
  126. unsigned short int baud = uart_addr[ss->line].ubaud;
  127. if (GET_FIELD(baud, UBAUD_PRESCALER) == 0x38) result = 38400;
  128. result >>= GET_FIELD(baud, UBAUD_DIVIDE);
  129. return result;
  130. }
  131. /*
  132. * ------------------------------------------------------------
  133. * rs_stop() and rs_start()
  134. *
  135. * This routines are called before setting or resetting tty->stopped.
  136. * They enable or disable transmitter interrupts, as necessary.
  137. * ------------------------------------------------------------
  138. */
  139. static void rs_stop(struct tty_struct *tty)
  140. {
  141. struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
  142. m68328_uart *uart = &uart_addr[info->line];
  143. unsigned long flags;
  144. if (serial_paranoia_check(info, tty->name, "rs_stop"))
  145. return;
  146. local_irq_save(flags);
  147. uart->ustcnt &= ~USTCNT_TXEN;
  148. local_irq_restore(flags);
  149. }
  150. static int rs_put_char(char ch)
  151. {
  152. int flags, loops = 0;
  153. local_irq_save(flags);
  154. while (!(UTX & UTX_TX_AVAIL) && (loops < 1000)) {
  155. loops++;
  156. udelay(5);
  157. }
  158. UTX_TXDATA = ch;
  159. udelay(5);
  160. local_irq_restore(flags);
  161. return 1;
  162. }
  163. static void rs_start(struct tty_struct *tty)
  164. {
  165. struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
  166. m68328_uart *uart = &uart_addr[info->line];
  167. unsigned long flags;
  168. if (serial_paranoia_check(info, tty->name, "rs_start"))
  169. return;
  170. local_irq_save(flags);
  171. if (info->xmit_cnt && info->xmit_buf && !(uart->ustcnt & USTCNT_TXEN)) {
  172. #ifdef USE_INTS
  173. uart->ustcnt |= USTCNT_TXEN | USTCNT_TX_INTR_MASK;
  174. #else
  175. uart->ustcnt |= USTCNT_TXEN;
  176. #endif
  177. }
  178. local_irq_restore(flags);
  179. }
  180. static void receive_chars(struct m68k_serial *info, unsigned short rx)
  181. {
  182. struct tty_struct *tty = info->tty;
  183. m68328_uart *uart = &uart_addr[info->line];
  184. unsigned char ch, flag;
  185. /*
  186. * This do { } while() loop will get ALL chars out of Rx FIFO
  187. */
  188. #ifndef CONFIG_XCOPILOT_BUGS
  189. do {
  190. #endif
  191. ch = GET_FIELD(rx, URX_RXDATA);
  192. if(info->is_cons) {
  193. if(URX_BREAK & rx) { /* whee, break received */
  194. return;
  195. #ifdef CONFIG_MAGIC_SYSRQ
  196. } else if (ch == 0x10) { /* ^P */
  197. show_state();
  198. show_free_areas(0);
  199. show_buffers();
  200. /* show_net_buffers(); */
  201. return;
  202. } else if (ch == 0x12) { /* ^R */
  203. emergency_restart();
  204. return;
  205. #endif /* CONFIG_MAGIC_SYSRQ */
  206. }
  207. }
  208. if(!tty)
  209. goto clear_and_exit;
  210. flag = TTY_NORMAL;
  211. if (rx & URX_PARITY_ERROR)
  212. flag = TTY_PARITY;
  213. else if (rx & URX_OVRUN)
  214. flag = TTY_OVERRUN;
  215. else if (rx & URX_FRAME_ERROR)
  216. flag = TTY_FRAME;
  217. tty_insert_flip_char(tty, ch, flag);
  218. #ifndef CONFIG_XCOPILOT_BUGS
  219. } while((rx = uart->urx.w) & URX_DATA_READY);
  220. #endif
  221. tty_schedule_flip(tty);
  222. clear_and_exit:
  223. return;
  224. }
  225. static void transmit_chars(struct m68k_serial *info)
  226. {
  227. m68328_uart *uart = &uart_addr[info->line];
  228. if (info->x_char) {
  229. /* Send next char */
  230. uart->utx.b.txdata = info->x_char;
  231. info->x_char = 0;
  232. goto clear_and_return;
  233. }
  234. if((info->xmit_cnt <= 0) || info->tty->stopped) {
  235. /* That's peculiar... TX ints off */
  236. uart->ustcnt &= ~USTCNT_TX_INTR_MASK;
  237. goto clear_and_return;
  238. }
  239. /* Send char */
  240. uart->utx.b.txdata = info->xmit_buf[info->xmit_tail++];
  241. info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
  242. info->xmit_cnt--;
  243. if(info->xmit_cnt <= 0) {
  244. /* All done for now... TX ints off */
  245. uart->ustcnt &= ~USTCNT_TX_INTR_MASK;
  246. goto clear_and_return;
  247. }
  248. clear_and_return:
  249. /* Clear interrupt (should be auto)*/
  250. return;
  251. }
  252. /*
  253. * This is the serial driver's generic interrupt routine
  254. */
  255. irqreturn_t rs_interrupt(int irq, void *dev_id)
  256. {
  257. struct m68k_serial *info = dev_id;
  258. m68328_uart *uart;
  259. unsigned short rx;
  260. unsigned short tx;
  261. uart = &uart_addr[info->line];
  262. rx = uart->urx.w;
  263. #ifdef USE_INTS
  264. tx = uart->utx.w;
  265. if (rx & URX_DATA_READY) receive_chars(info, rx);
  266. if (tx & UTX_TX_AVAIL) transmit_chars(info);
  267. #else
  268. receive_chars(info, rx);
  269. #endif
  270. return IRQ_HANDLED;
  271. }
  272. static int startup(struct m68k_serial * info)
  273. {
  274. m68328_uart *uart = &uart_addr[info->line];
  275. unsigned long flags;
  276. if (info->flags & ASYNC_INITIALIZED)
  277. return 0;
  278. if (!info->xmit_buf) {
  279. info->xmit_buf = (unsigned char *) __get_free_page(GFP_KERNEL);
  280. if (!info->xmit_buf)
  281. return -ENOMEM;
  282. }
  283. local_irq_save(flags);
  284. /*
  285. * Clear the FIFO buffers and disable them
  286. * (they will be reenabled in change_speed())
  287. */
  288. uart->ustcnt = USTCNT_UEN;
  289. uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_TXEN;
  290. (void)uart->urx.w;
  291. /*
  292. * Finally, enable sequencing and interrupts
  293. */
  294. #ifdef USE_INTS
  295. uart->ustcnt = USTCNT_UEN | USTCNT_RXEN |
  296. USTCNT_RX_INTR_MASK | USTCNT_TX_INTR_MASK;
  297. #else
  298. uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_RX_INTR_MASK;
  299. #endif
  300. if (info->tty)
  301. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  302. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  303. /*
  304. * and set the speed of the serial port
  305. */
  306. change_speed(info);
  307. info->flags |= ASYNC_INITIALIZED;
  308. local_irq_restore(flags);
  309. return 0;
  310. }
  311. /*
  312. * This routine will shutdown a serial port; interrupts are disabled, and
  313. * DTR is dropped if the hangup on close termio flag is on.
  314. */
  315. static void shutdown(struct m68k_serial * info)
  316. {
  317. m68328_uart *uart = &uart_addr[info->line];
  318. unsigned long flags;
  319. uart->ustcnt = 0; /* All off! */
  320. if (!(info->flags & ASYNC_INITIALIZED))
  321. return;
  322. local_irq_save(flags);
  323. if (info->xmit_buf) {
  324. free_page((unsigned long) info->xmit_buf);
  325. info->xmit_buf = 0;
  326. }
  327. if (info->tty)
  328. set_bit(TTY_IO_ERROR, &info->tty->flags);
  329. info->flags &= ~ASYNC_INITIALIZED;
  330. local_irq_restore(flags);
  331. }
  332. struct {
  333. int divisor, prescale;
  334. }
  335. #ifndef CONFIG_M68VZ328
  336. hw_baud_table[18] = {
  337. {0,0}, /* 0 */
  338. {0,0}, /* 50 */
  339. {0,0}, /* 75 */
  340. {0,0}, /* 110 */
  341. {0,0}, /* 134 */
  342. {0,0}, /* 150 */
  343. {0,0}, /* 200 */
  344. {7,0x26}, /* 300 */
  345. {6,0x26}, /* 600 */
  346. {5,0x26}, /* 1200 */
  347. {0,0}, /* 1800 */
  348. {4,0x26}, /* 2400 */
  349. {3,0x26}, /* 4800 */
  350. {2,0x26}, /* 9600 */
  351. {1,0x26}, /* 19200 */
  352. {0,0x26}, /* 38400 */
  353. {1,0x38}, /* 57600 */
  354. {0,0x38}, /* 115200 */
  355. };
  356. #else
  357. hw_baud_table[18] = {
  358. {0,0}, /* 0 */
  359. {0,0}, /* 50 */
  360. {0,0}, /* 75 */
  361. {0,0}, /* 110 */
  362. {0,0}, /* 134 */
  363. {0,0}, /* 150 */
  364. {0,0}, /* 200 */
  365. {0,0}, /* 300 */
  366. {7,0x26}, /* 600 */
  367. {6,0x26}, /* 1200 */
  368. {0,0}, /* 1800 */
  369. {5,0x26}, /* 2400 */
  370. {4,0x26}, /* 4800 */
  371. {3,0x26}, /* 9600 */
  372. {2,0x26}, /* 19200 */
  373. {1,0x26}, /* 38400 */
  374. {0,0x26}, /* 57600 */
  375. {1,0x38}, /* 115200 */
  376. };
  377. #endif
  378. /* rate = 1036800 / ((65 - prescale) * (1<<divider)) */
  379. /*
  380. * This routine is called to set the UART divisor registers to match
  381. * the specified baud rate for a serial port.
  382. */
  383. static void change_speed(struct m68k_serial *info)
  384. {
  385. m68328_uart *uart = &uart_addr[info->line];
  386. unsigned short port;
  387. unsigned short ustcnt;
  388. unsigned cflag;
  389. int i;
  390. if (!info->tty || !info->tty->termios)
  391. return;
  392. cflag = info->tty->termios->c_cflag;
  393. if (!(port = info->port))
  394. return;
  395. ustcnt = uart->ustcnt;
  396. uart->ustcnt = ustcnt & ~USTCNT_TXEN;
  397. i = cflag & CBAUD;
  398. if (i & CBAUDEX) {
  399. i = (i & ~CBAUDEX) + B38400;
  400. }
  401. uart->ubaud = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) |
  402. PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale);
  403. ustcnt &= ~(USTCNT_PARITYEN | USTCNT_ODD_EVEN | USTCNT_STOP | USTCNT_8_7);
  404. if ((cflag & CSIZE) == CS8)
  405. ustcnt |= USTCNT_8_7;
  406. if (cflag & CSTOPB)
  407. ustcnt |= USTCNT_STOP;
  408. if (cflag & PARENB)
  409. ustcnt |= USTCNT_PARITYEN;
  410. if (cflag & PARODD)
  411. ustcnt |= USTCNT_ODD_EVEN;
  412. #ifdef CONFIG_SERIAL_68328_RTS_CTS
  413. if (cflag & CRTSCTS) {
  414. uart->utx.w &= ~ UTX_NOCTS;
  415. } else {
  416. uart->utx.w |= UTX_NOCTS;
  417. }
  418. #endif
  419. ustcnt |= USTCNT_TXEN;
  420. uart->ustcnt = ustcnt;
  421. return;
  422. }
  423. /*
  424. * Fair output driver allows a process to speak.
  425. */
  426. static void rs_fair_output(void)
  427. {
  428. int left; /* Output no more than that */
  429. unsigned long flags;
  430. struct m68k_serial *info = &m68k_soft[0];
  431. char c;
  432. if (info == 0) return;
  433. if (info->xmit_buf == 0) return;
  434. local_irq_save(flags);
  435. left = info->xmit_cnt;
  436. while (left != 0) {
  437. c = info->xmit_buf[info->xmit_tail];
  438. info->xmit_tail = (info->xmit_tail+1) & (SERIAL_XMIT_SIZE-1);
  439. info->xmit_cnt--;
  440. local_irq_restore(flags);
  441. rs_put_char(c);
  442. local_irq_save(flags);
  443. left = min(info->xmit_cnt, left-1);
  444. }
  445. /* Last character is being transmitted now (hopefully). */
  446. udelay(5);
  447. local_irq_restore(flags);
  448. return;
  449. }
  450. /*
  451. * m68k_console_print is registered for printk.
  452. */
  453. void console_print_68328(const char *p)
  454. {
  455. char c;
  456. while((c=*(p++)) != 0) {
  457. if(c == '\n')
  458. rs_put_char('\r');
  459. rs_put_char(c);
  460. }
  461. /* Comment this if you want to have a strict interrupt-driven output */
  462. rs_fair_output();
  463. return;
  464. }
  465. static void rs_set_ldisc(struct tty_struct *tty)
  466. {
  467. struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
  468. if (serial_paranoia_check(info, tty->name, "rs_set_ldisc"))
  469. return;
  470. info->is_cons = (tty->termios->c_line == N_TTY);
  471. printk("ttyS%d console mode %s\n", info->line, info->is_cons ? "on" : "off");
  472. }
  473. static void rs_flush_chars(struct tty_struct *tty)
  474. {
  475. struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
  476. m68328_uart *uart = &uart_addr[info->line];
  477. unsigned long flags;
  478. if (serial_paranoia_check(info, tty->name, "rs_flush_chars"))
  479. return;
  480. #ifndef USE_INTS
  481. for(;;) {
  482. #endif
  483. /* Enable transmitter */
  484. local_irq_save(flags);
  485. if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
  486. !info->xmit_buf) {
  487. local_irq_restore(flags);
  488. return;
  489. }
  490. #ifdef USE_INTS
  491. uart->ustcnt |= USTCNT_TXEN | USTCNT_TX_INTR_MASK;
  492. #else
  493. uart->ustcnt |= USTCNT_TXEN;
  494. #endif
  495. #ifdef USE_INTS
  496. if (uart->utx.w & UTX_TX_AVAIL) {
  497. #else
  498. if (1) {
  499. #endif
  500. /* Send char */
  501. uart->utx.b.txdata = info->xmit_buf[info->xmit_tail++];
  502. info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
  503. info->xmit_cnt--;
  504. }
  505. #ifndef USE_INTS
  506. while (!(uart->utx.w & UTX_TX_AVAIL)) udelay(5);
  507. }
  508. #endif
  509. local_irq_restore(flags);
  510. }
  511. extern void console_printn(const char * b, int count);
  512. static int rs_write(struct tty_struct * tty,
  513. const unsigned char *buf, int count)
  514. {
  515. int c, total = 0;
  516. struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
  517. m68328_uart *uart = &uart_addr[info->line];
  518. unsigned long flags;
  519. if (serial_paranoia_check(info, tty->name, "rs_write"))
  520. return 0;
  521. if (!tty || !info->xmit_buf)
  522. return 0;
  523. local_save_flags(flags);
  524. while (1) {
  525. local_irq_disable();
  526. c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
  527. SERIAL_XMIT_SIZE - info->xmit_head));
  528. local_irq_restore(flags);
  529. if (c <= 0)
  530. break;
  531. memcpy(info->xmit_buf + info->xmit_head, buf, c);
  532. local_irq_disable();
  533. info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
  534. info->xmit_cnt += c;
  535. local_irq_restore(flags);
  536. buf += c;
  537. count -= c;
  538. total += c;
  539. }
  540. if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
  541. /* Enable transmitter */
  542. local_irq_disable();
  543. #ifndef USE_INTS
  544. while(info->xmit_cnt) {
  545. #endif
  546. uart->ustcnt |= USTCNT_TXEN;
  547. #ifdef USE_INTS
  548. uart->ustcnt |= USTCNT_TX_INTR_MASK;
  549. #else
  550. while (!(uart->utx.w & UTX_TX_AVAIL)) udelay(5);
  551. #endif
  552. if (uart->utx.w & UTX_TX_AVAIL) {
  553. uart->utx.b.txdata = info->xmit_buf[info->xmit_tail++];
  554. info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
  555. info->xmit_cnt--;
  556. }
  557. #ifndef USE_INTS
  558. }
  559. #endif
  560. local_irq_restore(flags);
  561. }
  562. return total;
  563. }
  564. static int rs_write_room(struct tty_struct *tty)
  565. {
  566. struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
  567. int ret;
  568. if (serial_paranoia_check(info, tty->name, "rs_write_room"))
  569. return 0;
  570. ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
  571. if (ret < 0)
  572. ret = 0;
  573. return ret;
  574. }
  575. static int rs_chars_in_buffer(struct tty_struct *tty)
  576. {
  577. struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
  578. if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
  579. return 0;
  580. return info->xmit_cnt;
  581. }
  582. static void rs_flush_buffer(struct tty_struct *tty)
  583. {
  584. struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
  585. unsigned long flags;
  586. if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
  587. return;
  588. local_irq_save(flags);
  589. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  590. local_irq_restore(flags);
  591. tty_wakeup(tty);
  592. }
  593. /*
  594. * ------------------------------------------------------------
  595. * rs_throttle()
  596. *
  597. * This routine is called by the upper-layer tty layer to signal that
  598. * incoming characters should be throttled.
  599. * ------------------------------------------------------------
  600. */
  601. static void rs_throttle(struct tty_struct * tty)
  602. {
  603. struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
  604. if (serial_paranoia_check(info, tty->name, "rs_throttle"))
  605. return;
  606. if (I_IXOFF(tty))
  607. info->x_char = STOP_CHAR(tty);
  608. /* Turn off RTS line (do this atomic) */
  609. }
  610. static void rs_unthrottle(struct tty_struct * tty)
  611. {
  612. struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
  613. if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
  614. return;
  615. if (I_IXOFF(tty)) {
  616. if (info->x_char)
  617. info->x_char = 0;
  618. else
  619. info->x_char = START_CHAR(tty);
  620. }
  621. /* Assert RTS line (do this atomic) */
  622. }
  623. /*
  624. * ------------------------------------------------------------
  625. * rs_ioctl() and friends
  626. * ------------------------------------------------------------
  627. */
  628. static int get_serial_info(struct m68k_serial * info,
  629. struct serial_struct * retinfo)
  630. {
  631. struct serial_struct tmp;
  632. if (!retinfo)
  633. return -EFAULT;
  634. memset(&tmp, 0, sizeof(tmp));
  635. tmp.type = info->type;
  636. tmp.line = info->line;
  637. tmp.port = info->port;
  638. tmp.irq = info->irq;
  639. tmp.flags = info->flags;
  640. tmp.baud_base = info->baud_base;
  641. tmp.close_delay = info->close_delay;
  642. tmp.closing_wait = info->closing_wait;
  643. tmp.custom_divisor = info->custom_divisor;
  644. if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
  645. return -EFAULT;
  646. return 0;
  647. }
  648. static int set_serial_info(struct m68k_serial * info,
  649. struct serial_struct * new_info)
  650. {
  651. struct serial_struct new_serial;
  652. struct m68k_serial old_info;
  653. int retval = 0;
  654. if (!new_info)
  655. return -EFAULT;
  656. if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
  657. return -EFAULT;
  658. old_info = *info;
  659. if (!capable(CAP_SYS_ADMIN)) {
  660. if ((new_serial.baud_base != info->baud_base) ||
  661. (new_serial.type != info->type) ||
  662. (new_serial.close_delay != info->close_delay) ||
  663. ((new_serial.flags & ~ASYNC_USR_MASK) !=
  664. (info->flags & ~ASYNC_USR_MASK)))
  665. return -EPERM;
  666. info->flags = ((info->flags & ~ASYNC_USR_MASK) |
  667. (new_serial.flags & ASYNC_USR_MASK));
  668. info->custom_divisor = new_serial.custom_divisor;
  669. goto check_and_exit;
  670. }
  671. if (info->count > 1)
  672. return -EBUSY;
  673. /*
  674. * OK, past this point, all the error checking has been done.
  675. * At this point, we start making changes.....
  676. */
  677. info->baud_base = new_serial.baud_base;
  678. info->flags = ((info->flags & ~ASYNC_FLAGS) |
  679. (new_serial.flags & ASYNC_FLAGS));
  680. info->type = new_serial.type;
  681. info->close_delay = new_serial.close_delay;
  682. info->closing_wait = new_serial.closing_wait;
  683. check_and_exit:
  684. retval = startup(info);
  685. return retval;
  686. }
  687. /*
  688. * get_lsr_info - get line status register info
  689. *
  690. * Purpose: Let user call ioctl() to get info when the UART physically
  691. * is emptied. On bus types like RS485, the transmitter must
  692. * release the bus after transmitting. This must be done when
  693. * the transmit shift register is empty, not be done when the
  694. * transmit holding register is empty. This functionality
  695. * allows an RS485 driver to be written in user space.
  696. */
  697. static int get_lsr_info(struct m68k_serial * info, unsigned int *value)
  698. {
  699. #ifdef CONFIG_SERIAL_68328_RTS_CTS
  700. m68328_uart *uart = &uart_addr[info->line];
  701. #endif
  702. unsigned char status;
  703. unsigned long flags;
  704. local_irq_save(flags);
  705. #ifdef CONFIG_SERIAL_68328_RTS_CTS
  706. status = (uart->utx.w & UTX_CTS_STAT) ? 1 : 0;
  707. #else
  708. status = 0;
  709. #endif
  710. local_irq_restore(flags);
  711. return put_user(status, value);
  712. }
  713. /*
  714. * This routine sends a break character out the serial port.
  715. */
  716. static void send_break(struct m68k_serial * info, unsigned int duration)
  717. {
  718. m68328_uart *uart = &uart_addr[info->line];
  719. unsigned long flags;
  720. if (!info->port)
  721. return;
  722. local_irq_save(flags);
  723. #ifdef USE_INTS
  724. uart->utx.w |= UTX_SEND_BREAK;
  725. msleep_interruptible(duration);
  726. uart->utx.w &= ~UTX_SEND_BREAK;
  727. #endif
  728. local_irq_restore(flags);
  729. }
  730. static int rs_ioctl(struct tty_struct *tty,
  731. unsigned int cmd, unsigned long arg)
  732. {
  733. struct m68k_serial * info = (struct m68k_serial *)tty->driver_data;
  734. int retval;
  735. if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
  736. return -ENODEV;
  737. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  738. (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
  739. (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {
  740. if (tty->flags & (1 << TTY_IO_ERROR))
  741. return -EIO;
  742. }
  743. switch (cmd) {
  744. case TCSBRK: /* SVID version: non-zero arg --> no break */
  745. retval = tty_check_change(tty);
  746. if (retval)
  747. return retval;
  748. tty_wait_until_sent(tty, 0);
  749. if (!arg)
  750. send_break(info, 250); /* 1/4 second */
  751. return 0;
  752. case TCSBRKP: /* support for POSIX tcsendbreak() */
  753. retval = tty_check_change(tty);
  754. if (retval)
  755. return retval;
  756. tty_wait_until_sent(tty, 0);
  757. send_break(info, arg ? arg*(100) : 250);
  758. return 0;
  759. case TIOCGSERIAL:
  760. return get_serial_info(info,
  761. (struct serial_struct *) arg);
  762. case TIOCSSERIAL:
  763. return set_serial_info(info,
  764. (struct serial_struct *) arg);
  765. case TIOCSERGETLSR: /* Get line status register */
  766. return get_lsr_info(info, (unsigned int *) arg);
  767. case TIOCSERGSTRUCT:
  768. if (copy_to_user((struct m68k_serial *) arg,
  769. info, sizeof(struct m68k_serial)))
  770. return -EFAULT;
  771. return 0;
  772. default:
  773. return -ENOIOCTLCMD;
  774. }
  775. return 0;
  776. }
  777. static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
  778. {
  779. struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
  780. change_speed(info);
  781. if ((old_termios->c_cflag & CRTSCTS) &&
  782. !(tty->termios->c_cflag & CRTSCTS)) {
  783. tty->hw_stopped = 0;
  784. rs_start(tty);
  785. }
  786. }
  787. /*
  788. * ------------------------------------------------------------
  789. * rs_close()
  790. *
  791. * This routine is called when the serial port gets closed. First, we
  792. * wait for the last remaining data to be sent. Then, we unlink its
  793. * S structure from the interrupt chain if necessary, and we free
  794. * that IRQ if nothing is left in the chain.
  795. * ------------------------------------------------------------
  796. */
  797. static void rs_close(struct tty_struct *tty, struct file * filp)
  798. {
  799. struct m68k_serial * info = (struct m68k_serial *)tty->driver_data;
  800. m68328_uart *uart = &uart_addr[info->line];
  801. unsigned long flags;
  802. if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
  803. return;
  804. local_irq_save(flags);
  805. if (tty_hung_up_p(filp)) {
  806. local_irq_restore(flags);
  807. return;
  808. }
  809. if ((tty->count == 1) && (info->count != 1)) {
  810. /*
  811. * Uh, oh. tty->count is 1, which means that the tty
  812. * structure will be freed. Info->count should always
  813. * be one in these conditions. If it's greater than
  814. * one, we've got real problems, since it means the
  815. * serial port won't be shutdown.
  816. */
  817. printk("rs_close: bad serial port count; tty->count is 1, "
  818. "info->count is %d\n", info->count);
  819. info->count = 1;
  820. }
  821. if (--info->count < 0) {
  822. printk("rs_close: bad serial port count for ttyS%d: %d\n",
  823. info->line, info->count);
  824. info->count = 0;
  825. }
  826. if (info->count) {
  827. local_irq_restore(flags);
  828. return;
  829. }
  830. info->flags |= ASYNC_CLOSING;
  831. /*
  832. * Now we wait for the transmit buffer to clear; and we notify
  833. * the line discipline to only process XON/XOFF characters.
  834. */
  835. tty->closing = 1;
  836. if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  837. tty_wait_until_sent(tty, info->closing_wait);
  838. /*
  839. * At this point we stop accepting input. To do this, we
  840. * disable the receive line status interrupts, and tell the
  841. * interrupt driver to stop checking the data ready bit in the
  842. * line status register.
  843. */
  844. uart->ustcnt &= ~USTCNT_RXEN;
  845. uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK);
  846. shutdown(info);
  847. rs_flush_buffer(tty);
  848. tty_ldisc_flush(tty);
  849. tty->closing = 0;
  850. info->tty = NULL;
  851. #warning "This is not and has never been valid so fix it"
  852. #if 0
  853. if (tty->ldisc.num != ldiscs[N_TTY].num) {
  854. if (tty->ldisc.close)
  855. (tty->ldisc.close)(tty);
  856. tty->ldisc = ldiscs[N_TTY];
  857. tty->termios->c_line = N_TTY;
  858. if (tty->ldisc.open)
  859. (tty->ldisc.open)(tty);
  860. }
  861. #endif
  862. if (info->blocked_open) {
  863. if (info->close_delay) {
  864. msleep_interruptible(jiffies_to_msecs(info->close_delay));
  865. }
  866. wake_up_interruptible(&info->open_wait);
  867. }
  868. info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  869. wake_up_interruptible(&info->close_wait);
  870. local_irq_restore(flags);
  871. }
  872. /*
  873. * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
  874. */
  875. void rs_hangup(struct tty_struct *tty)
  876. {
  877. struct m68k_serial * info = (struct m68k_serial *)tty->driver_data;
  878. if (serial_paranoia_check(info, tty->name, "rs_hangup"))
  879. return;
  880. rs_flush_buffer(tty);
  881. shutdown(info);
  882. info->count = 0;
  883. info->flags &= ~ASYNC_NORMAL_ACTIVE;
  884. info->tty = NULL;
  885. wake_up_interruptible(&info->open_wait);
  886. }
  887. /*
  888. * ------------------------------------------------------------
  889. * rs_open() and friends
  890. * ------------------------------------------------------------
  891. */
  892. static int block_til_ready(struct tty_struct *tty, struct file * filp,
  893. struct m68k_serial *info)
  894. {
  895. DECLARE_WAITQUEUE(wait, current);
  896. int retval;
  897. int do_clocal = 0;
  898. /*
  899. * If the device is in the middle of being closed, then block
  900. * until it's done, and then try again.
  901. */
  902. if (info->flags & ASYNC_CLOSING) {
  903. interruptible_sleep_on(&info->close_wait);
  904. #ifdef SERIAL_DO_RESTART
  905. if (info->flags & ASYNC_HUP_NOTIFY)
  906. return -EAGAIN;
  907. else
  908. return -ERESTARTSYS;
  909. #else
  910. return -EAGAIN;
  911. #endif
  912. }
  913. /*
  914. * If non-blocking mode is set, or the port is not enabled,
  915. * then make the check up front and then exit.
  916. */
  917. if ((filp->f_flags & O_NONBLOCK) ||
  918. (tty->flags & (1 << TTY_IO_ERROR))) {
  919. info->flags |= ASYNC_NORMAL_ACTIVE;
  920. return 0;
  921. }
  922. if (tty->termios->c_cflag & CLOCAL)
  923. do_clocal = 1;
  924. /*
  925. * Block waiting for the carrier detect and the line to become
  926. * free (i.e., not in use by the callout). While we are in
  927. * this loop, info->count is dropped by one, so that
  928. * rs_close() knows when to free things. We restore it upon
  929. * exit, either normal or abnormal.
  930. */
  931. retval = 0;
  932. add_wait_queue(&info->open_wait, &wait);
  933. info->count--;
  934. info->blocked_open++;
  935. while (1) {
  936. local_irq_disable();
  937. m68k_rtsdtr(info, 1);
  938. local_irq_enable();
  939. current->state = TASK_INTERRUPTIBLE;
  940. if (tty_hung_up_p(filp) ||
  941. !(info->flags & ASYNC_INITIALIZED)) {
  942. #ifdef SERIAL_DO_RESTART
  943. if (info->flags & ASYNC_HUP_NOTIFY)
  944. retval = -EAGAIN;
  945. else
  946. retval = -ERESTARTSYS;
  947. #else
  948. retval = -EAGAIN;
  949. #endif
  950. break;
  951. }
  952. if (!(info->flags & ASYNC_CLOSING) && do_clocal)
  953. break;
  954. if (signal_pending(current)) {
  955. retval = -ERESTARTSYS;
  956. break;
  957. }
  958. tty_unlock();
  959. schedule();
  960. tty_lock();
  961. }
  962. current->state = TASK_RUNNING;
  963. remove_wait_queue(&info->open_wait, &wait);
  964. if (!tty_hung_up_p(filp))
  965. info->count++;
  966. info->blocked_open--;
  967. if (retval)
  968. return retval;
  969. info->flags |= ASYNC_NORMAL_ACTIVE;
  970. return 0;
  971. }
  972. /*
  973. * This routine is called whenever a serial port is opened. It
  974. * enables interrupts for a serial port, linking in its S structure into
  975. * the IRQ chain. It also performs the serial-specific
  976. * initialization for the tty structure.
  977. */
  978. int rs_open(struct tty_struct *tty, struct file * filp)
  979. {
  980. struct m68k_serial *info;
  981. int retval;
  982. info = &m68k_soft[tty->index];
  983. if (serial_paranoia_check(info, tty->name, "rs_open"))
  984. return -ENODEV;
  985. info->count++;
  986. tty->driver_data = info;
  987. info->tty = tty;
  988. /*
  989. * Start up serial port
  990. */
  991. retval = startup(info);
  992. if (retval)
  993. return retval;
  994. return block_til_ready(tty, filp, info);
  995. }
  996. /* Finally, routines used to initialize the serial driver. */
  997. static void show_serial_version(void)
  998. {
  999. printk("MC68328 serial driver version 1.00\n");
  1000. }
  1001. static const struct tty_operations rs_ops = {
  1002. .open = rs_open,
  1003. .close = rs_close,
  1004. .write = rs_write,
  1005. .flush_chars = rs_flush_chars,
  1006. .write_room = rs_write_room,
  1007. .chars_in_buffer = rs_chars_in_buffer,
  1008. .flush_buffer = rs_flush_buffer,
  1009. .ioctl = rs_ioctl,
  1010. .throttle = rs_throttle,
  1011. .unthrottle = rs_unthrottle,
  1012. .set_termios = rs_set_termios,
  1013. .stop = rs_stop,
  1014. .start = rs_start,
  1015. .hangup = rs_hangup,
  1016. .set_ldisc = rs_set_ldisc,
  1017. };
  1018. /* rs_init inits the driver */
  1019. static int __init
  1020. rs68328_init(void)
  1021. {
  1022. int flags, i;
  1023. struct m68k_serial *info;
  1024. serial_driver = alloc_tty_driver(NR_PORTS);
  1025. if (!serial_driver)
  1026. return -ENOMEM;
  1027. show_serial_version();
  1028. /* Initialize the tty_driver structure */
  1029. /* SPARC: Not all of this is exactly right for us. */
  1030. serial_driver->name = "ttyS";
  1031. serial_driver->major = TTY_MAJOR;
  1032. serial_driver->minor_start = 64;
  1033. serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
  1034. serial_driver->subtype = SERIAL_TYPE_NORMAL;
  1035. serial_driver->init_termios = tty_std_termios;
  1036. serial_driver->init_termios.c_cflag =
  1037. m68328_console_cbaud | CS8 | CREAD | HUPCL | CLOCAL;
  1038. serial_driver->flags = TTY_DRIVER_REAL_RAW;
  1039. tty_set_operations(serial_driver, &rs_ops);
  1040. if (tty_register_driver(serial_driver)) {
  1041. put_tty_driver(serial_driver);
  1042. printk(KERN_ERR "Couldn't register serial driver\n");
  1043. return -ENOMEM;
  1044. }
  1045. local_irq_save(flags);
  1046. for(i=0;i<NR_PORTS;i++) {
  1047. info = &m68k_soft[i];
  1048. info->magic = SERIAL_MAGIC;
  1049. info->port = (int) &uart_addr[i];
  1050. info->tty = NULL;
  1051. info->irq = uart_irqs[i];
  1052. info->custom_divisor = 16;
  1053. info->close_delay = 50;
  1054. info->closing_wait = 3000;
  1055. info->x_char = 0;
  1056. info->count = 0;
  1057. info->blocked_open = 0;
  1058. init_waitqueue_head(&info->open_wait);
  1059. init_waitqueue_head(&info->close_wait);
  1060. info->line = i;
  1061. info->is_cons = 1; /* Means shortcuts work */
  1062. printk("%s%d at 0x%08x (irq = %d)", serial_driver->name, info->line,
  1063. info->port, info->irq);
  1064. printk(" is a builtin MC68328 UART\n");
  1065. #ifdef CONFIG_M68VZ328
  1066. if (i > 0 )
  1067. PJSEL &= 0xCF; /* PSW enable second port output */
  1068. #endif
  1069. if (request_irq(uart_irqs[i],
  1070. rs_interrupt,
  1071. 0,
  1072. "M68328_UART", info))
  1073. panic("Unable to attach 68328 serial interrupt\n");
  1074. }
  1075. local_irq_restore(flags);
  1076. return 0;
  1077. }
  1078. module_init(rs68328_init);
  1079. static void m68328_set_baud(void)
  1080. {
  1081. unsigned short ustcnt;
  1082. int i;
  1083. ustcnt = USTCNT;
  1084. USTCNT = ustcnt & ~USTCNT_TXEN;
  1085. again:
  1086. for (i = 0; i < ARRAY_SIZE(baud_table); i++)
  1087. if (baud_table[i] == m68328_console_baud)
  1088. break;
  1089. if (i >= ARRAY_SIZE(baud_table)) {
  1090. m68328_console_baud = 9600;
  1091. goto again;
  1092. }
  1093. UBAUD = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) |
  1094. PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale);
  1095. ustcnt &= ~(USTCNT_PARITYEN | USTCNT_ODD_EVEN | USTCNT_STOP | USTCNT_8_7);
  1096. ustcnt |= USTCNT_8_7;
  1097. ustcnt |= USTCNT_TXEN;
  1098. USTCNT = ustcnt;
  1099. m68328_console_initted = 1;
  1100. return;
  1101. }
  1102. int m68328_console_setup(struct console *cp, char *arg)
  1103. {
  1104. int i, n = CONSOLE_BAUD_RATE;
  1105. if (!cp)
  1106. return(-1);
  1107. if (arg)
  1108. n = simple_strtoul(arg,NULL,0);
  1109. for (i = 0; i < ARRAY_SIZE(baud_table); i++)
  1110. if (baud_table[i] == n)
  1111. break;
  1112. if (i < ARRAY_SIZE(baud_table)) {
  1113. m68328_console_baud = n;
  1114. m68328_console_cbaud = 0;
  1115. if (i > 15) {
  1116. m68328_console_cbaud |= CBAUDEX;
  1117. i -= 15;
  1118. }
  1119. m68328_console_cbaud |= i;
  1120. }
  1121. m68328_set_baud(); /* make sure baud rate changes */
  1122. return(0);
  1123. }
  1124. static struct tty_driver *m68328_console_device(struct console *c, int *index)
  1125. {
  1126. *index = c->index;
  1127. return serial_driver;
  1128. }
  1129. void m68328_console_write (struct console *co, const char *str,
  1130. unsigned int count)
  1131. {
  1132. if (!m68328_console_initted)
  1133. m68328_set_baud();
  1134. while (count--) {
  1135. if (*str == '\n')
  1136. rs_put_char('\r');
  1137. rs_put_char( *str++ );
  1138. }
  1139. }
  1140. static struct console m68328_driver = {
  1141. .name = "ttyS",
  1142. .write = m68328_console_write,
  1143. .device = m68328_console_device,
  1144. .setup = m68328_console_setup,
  1145. .flags = CON_PRINTBUFFER,
  1146. .index = -1,
  1147. };
  1148. static int __init m68328_console_init(void)
  1149. {
  1150. register_console(&m68328_driver);
  1151. return 0;
  1152. }
  1153. console_initcall(m68328_console_init);