68328serial.c 33 KB

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