68328serial.c 33 KB

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