68328serial.c 33 KB

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