mcf.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /****************************************************************************/
  2. /*
  3. * mcf.c -- Freescale ColdFire UART driver
  4. *
  5. * (C) Copyright 2003-2007, Greg Ungerer <gerg@snapgear.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. /****************************************************************************/
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/module.h>
  17. #include <linux/console.h>
  18. #include <linux/tty.h>
  19. #include <linux/tty_flip.h>
  20. #include <linux/serial.h>
  21. #include <linux/serial_core.h>
  22. #include <linux/io.h>
  23. #include <linux/uaccess.h>
  24. #include <linux/platform_device.h>
  25. #include <asm/coldfire.h>
  26. #include <asm/mcfsim.h>
  27. #include <asm/mcfuart.h>
  28. #include <asm/nettel.h>
  29. /****************************************************************************/
  30. /*
  31. * Some boards implement the DTR/DCD lines using GPIO lines, most
  32. * don't. Dummy out the access macros for those that don't. Those
  33. * that do should define these macros somewhere in there board
  34. * specific inlude files.
  35. */
  36. #if !defined(mcf_getppdcd)
  37. #define mcf_getppdcd(p) (1)
  38. #endif
  39. #if !defined(mcf_getppdtr)
  40. #define mcf_getppdtr(p) (1)
  41. #endif
  42. #if !defined(mcf_setppdtr)
  43. #define mcf_setppdtr(p, v) do { } while (0)
  44. #endif
  45. /****************************************************************************/
  46. /*
  47. * Local per-uart structure.
  48. */
  49. struct mcf_uart {
  50. struct uart_port port;
  51. unsigned int sigs; /* Local copy of line sigs */
  52. unsigned char imr; /* Local IMR mirror */
  53. struct serial_rs485 rs485; /* RS485 settings */
  54. };
  55. /****************************************************************************/
  56. static unsigned int mcf_tx_empty(struct uart_port *port)
  57. {
  58. return (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXEMPTY) ?
  59. TIOCSER_TEMT : 0;
  60. }
  61. /****************************************************************************/
  62. static unsigned int mcf_get_mctrl(struct uart_port *port)
  63. {
  64. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  65. unsigned int sigs;
  66. sigs = (readb(port->membase + MCFUART_UIPR) & MCFUART_UIPR_CTS) ?
  67. 0 : TIOCM_CTS;
  68. sigs |= (pp->sigs & TIOCM_RTS);
  69. sigs |= (mcf_getppdcd(port->line) ? TIOCM_CD : 0);
  70. sigs |= (mcf_getppdtr(port->line) ? TIOCM_DTR : 0);
  71. return sigs;
  72. }
  73. /****************************************************************************/
  74. static void mcf_set_mctrl(struct uart_port *port, unsigned int sigs)
  75. {
  76. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  77. pp->sigs = sigs;
  78. mcf_setppdtr(port->line, (sigs & TIOCM_DTR));
  79. if (sigs & TIOCM_RTS)
  80. writeb(MCFUART_UOP_RTS, port->membase + MCFUART_UOP1);
  81. else
  82. writeb(MCFUART_UOP_RTS, port->membase + MCFUART_UOP0);
  83. }
  84. /****************************************************************************/
  85. static void mcf_start_tx(struct uart_port *port)
  86. {
  87. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  88. if (pp->rs485.flags & SER_RS485_ENABLED) {
  89. /* Enable Transmitter */
  90. writeb(MCFUART_UCR_TXENABLE, port->membase + MCFUART_UCR);
  91. /* Manually assert RTS */
  92. writeb(MCFUART_UOP_RTS, port->membase + MCFUART_UOP1);
  93. }
  94. pp->imr |= MCFUART_UIR_TXREADY;
  95. writeb(pp->imr, port->membase + MCFUART_UIMR);
  96. }
  97. /****************************************************************************/
  98. static void mcf_stop_tx(struct uart_port *port)
  99. {
  100. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  101. pp->imr &= ~MCFUART_UIR_TXREADY;
  102. writeb(pp->imr, port->membase + MCFUART_UIMR);
  103. }
  104. /****************************************************************************/
  105. static void mcf_stop_rx(struct uart_port *port)
  106. {
  107. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  108. pp->imr &= ~MCFUART_UIR_RXREADY;
  109. writeb(pp->imr, port->membase + MCFUART_UIMR);
  110. }
  111. /****************************************************************************/
  112. static void mcf_break_ctl(struct uart_port *port, int break_state)
  113. {
  114. unsigned long flags;
  115. spin_lock_irqsave(&port->lock, flags);
  116. if (break_state == -1)
  117. writeb(MCFUART_UCR_CMDBREAKSTART, port->membase + MCFUART_UCR);
  118. else
  119. writeb(MCFUART_UCR_CMDBREAKSTOP, port->membase + MCFUART_UCR);
  120. spin_unlock_irqrestore(&port->lock, flags);
  121. }
  122. /****************************************************************************/
  123. static void mcf_enable_ms(struct uart_port *port)
  124. {
  125. }
  126. /****************************************************************************/
  127. static int mcf_startup(struct uart_port *port)
  128. {
  129. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  130. unsigned long flags;
  131. spin_lock_irqsave(&port->lock, flags);
  132. /* Reset UART, get it into known state... */
  133. writeb(MCFUART_UCR_CMDRESETRX, port->membase + MCFUART_UCR);
  134. writeb(MCFUART_UCR_CMDRESETTX, port->membase + MCFUART_UCR);
  135. /* Enable the UART transmitter and receiver */
  136. writeb(MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE,
  137. port->membase + MCFUART_UCR);
  138. /* Enable RX interrupts now */
  139. pp->imr = MCFUART_UIR_RXREADY;
  140. writeb(pp->imr, port->membase + MCFUART_UIMR);
  141. spin_unlock_irqrestore(&port->lock, flags);
  142. return 0;
  143. }
  144. /****************************************************************************/
  145. static void mcf_shutdown(struct uart_port *port)
  146. {
  147. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  148. unsigned long flags;
  149. spin_lock_irqsave(&port->lock, flags);
  150. /* Disable all interrupts now */
  151. pp->imr = 0;
  152. writeb(pp->imr, port->membase + MCFUART_UIMR);
  153. /* Disable UART transmitter and receiver */
  154. writeb(MCFUART_UCR_CMDRESETRX, port->membase + MCFUART_UCR);
  155. writeb(MCFUART_UCR_CMDRESETTX, port->membase + MCFUART_UCR);
  156. spin_unlock_irqrestore(&port->lock, flags);
  157. }
  158. /****************************************************************************/
  159. static void mcf_set_termios(struct uart_port *port, struct ktermios *termios,
  160. struct ktermios *old)
  161. {
  162. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  163. unsigned long flags;
  164. unsigned int baud, baudclk;
  165. #if defined(CONFIG_M5272)
  166. unsigned int baudfr;
  167. #endif
  168. unsigned char mr1, mr2;
  169. baud = uart_get_baud_rate(port, termios, old, 0, 230400);
  170. #if defined(CONFIG_M5272)
  171. baudclk = (MCF_BUSCLK / baud) / 32;
  172. baudfr = (((MCF_BUSCLK / baud) + 1) / 2) % 16;
  173. #else
  174. baudclk = ((MCF_BUSCLK / baud) + 16) / 32;
  175. #endif
  176. mr1 = MCFUART_MR1_RXIRQRDY | MCFUART_MR1_RXERRCHAR;
  177. mr2 = 0;
  178. switch (termios->c_cflag & CSIZE) {
  179. case CS5: mr1 |= MCFUART_MR1_CS5; break;
  180. case CS6: mr1 |= MCFUART_MR1_CS6; break;
  181. case CS7: mr1 |= MCFUART_MR1_CS7; break;
  182. case CS8:
  183. default: mr1 |= MCFUART_MR1_CS8; break;
  184. }
  185. if (termios->c_cflag & PARENB) {
  186. if (termios->c_cflag & CMSPAR) {
  187. if (termios->c_cflag & PARODD)
  188. mr1 |= MCFUART_MR1_PARITYMARK;
  189. else
  190. mr1 |= MCFUART_MR1_PARITYSPACE;
  191. } else {
  192. if (termios->c_cflag & PARODD)
  193. mr1 |= MCFUART_MR1_PARITYODD;
  194. else
  195. mr1 |= MCFUART_MR1_PARITYEVEN;
  196. }
  197. } else {
  198. mr1 |= MCFUART_MR1_PARITYNONE;
  199. }
  200. /*
  201. * FIXME: port->read_status_mask and port->ignore_status_mask
  202. * need to be initialized based on termios settings for
  203. * INPCK, IGNBRK, IGNPAR, PARMRK, BRKINT
  204. */
  205. if (termios->c_cflag & CSTOPB)
  206. mr2 |= MCFUART_MR2_STOP2;
  207. else
  208. mr2 |= MCFUART_MR2_STOP1;
  209. if (termios->c_cflag & CRTSCTS) {
  210. mr1 |= MCFUART_MR1_RXRTS;
  211. mr2 |= MCFUART_MR2_TXCTS;
  212. }
  213. if (pp->rs485.flags & SER_RS485_ENABLED) {
  214. dev_dbg(port->dev, "Setting UART to RS485\n");
  215. mr2 |= MCFUART_MR2_TXRTS;
  216. }
  217. spin_lock_irqsave(&port->lock, flags);
  218. uart_update_timeout(port, termios->c_cflag, baud);
  219. writeb(MCFUART_UCR_CMDRESETRX, port->membase + MCFUART_UCR);
  220. writeb(MCFUART_UCR_CMDRESETTX, port->membase + MCFUART_UCR);
  221. writeb(MCFUART_UCR_CMDRESETMRPTR, port->membase + MCFUART_UCR);
  222. writeb(mr1, port->membase + MCFUART_UMR);
  223. writeb(mr2, port->membase + MCFUART_UMR);
  224. writeb((baudclk & 0xff00) >> 8, port->membase + MCFUART_UBG1);
  225. writeb((baudclk & 0xff), port->membase + MCFUART_UBG2);
  226. #if defined(CONFIG_M5272)
  227. writeb((baudfr & 0x0f), port->membase + MCFUART_UFPD);
  228. #endif
  229. writeb(MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER,
  230. port->membase + MCFUART_UCSR);
  231. writeb(MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE,
  232. port->membase + MCFUART_UCR);
  233. spin_unlock_irqrestore(&port->lock, flags);
  234. }
  235. /****************************************************************************/
  236. static void mcf_rx_chars(struct mcf_uart *pp)
  237. {
  238. struct uart_port *port = &pp->port;
  239. unsigned char status, ch, flag;
  240. while ((status = readb(port->membase + MCFUART_USR)) & MCFUART_USR_RXREADY) {
  241. ch = readb(port->membase + MCFUART_URB);
  242. flag = TTY_NORMAL;
  243. port->icount.rx++;
  244. if (status & MCFUART_USR_RXERR) {
  245. writeb(MCFUART_UCR_CMDRESETERR,
  246. port->membase + MCFUART_UCR);
  247. if (status & MCFUART_USR_RXBREAK) {
  248. port->icount.brk++;
  249. if (uart_handle_break(port))
  250. continue;
  251. } else if (status & MCFUART_USR_RXPARITY) {
  252. port->icount.parity++;
  253. } else if (status & MCFUART_USR_RXOVERRUN) {
  254. port->icount.overrun++;
  255. } else if (status & MCFUART_USR_RXFRAMING) {
  256. port->icount.frame++;
  257. }
  258. status &= port->read_status_mask;
  259. if (status & MCFUART_USR_RXBREAK)
  260. flag = TTY_BREAK;
  261. else if (status & MCFUART_USR_RXPARITY)
  262. flag = TTY_PARITY;
  263. else if (status & MCFUART_USR_RXFRAMING)
  264. flag = TTY_FRAME;
  265. }
  266. if (uart_handle_sysrq_char(port, ch))
  267. continue;
  268. uart_insert_char(port, status, MCFUART_USR_RXOVERRUN, ch, flag);
  269. }
  270. spin_unlock(&port->lock);
  271. tty_flip_buffer_push(&port->state->port);
  272. spin_lock(&port->lock);
  273. }
  274. /****************************************************************************/
  275. static void mcf_tx_chars(struct mcf_uart *pp)
  276. {
  277. struct uart_port *port = &pp->port;
  278. struct circ_buf *xmit = &port->state->xmit;
  279. if (port->x_char) {
  280. /* Send special char - probably flow control */
  281. writeb(port->x_char, port->membase + MCFUART_UTB);
  282. port->x_char = 0;
  283. port->icount.tx++;
  284. return;
  285. }
  286. while (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXREADY) {
  287. if (xmit->head == xmit->tail)
  288. break;
  289. writeb(xmit->buf[xmit->tail], port->membase + MCFUART_UTB);
  290. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE -1);
  291. port->icount.tx++;
  292. }
  293. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  294. uart_write_wakeup(port);
  295. if (xmit->head == xmit->tail) {
  296. pp->imr &= ~MCFUART_UIR_TXREADY;
  297. writeb(pp->imr, port->membase + MCFUART_UIMR);
  298. /* Disable TX to negate RTS automatically */
  299. if (pp->rs485.flags & SER_RS485_ENABLED)
  300. writeb(MCFUART_UCR_TXDISABLE,
  301. port->membase + MCFUART_UCR);
  302. }
  303. }
  304. /****************************************************************************/
  305. static irqreturn_t mcf_interrupt(int irq, void *data)
  306. {
  307. struct uart_port *port = data;
  308. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  309. unsigned int isr;
  310. irqreturn_t ret = IRQ_NONE;
  311. isr = readb(port->membase + MCFUART_UISR) & pp->imr;
  312. spin_lock(&port->lock);
  313. if (isr & MCFUART_UIR_RXREADY) {
  314. mcf_rx_chars(pp);
  315. ret = IRQ_HANDLED;
  316. }
  317. if (isr & MCFUART_UIR_TXREADY) {
  318. mcf_tx_chars(pp);
  319. ret = IRQ_HANDLED;
  320. }
  321. spin_unlock(&port->lock);
  322. return ret;
  323. }
  324. /****************************************************************************/
  325. static void mcf_config_port(struct uart_port *port, int flags)
  326. {
  327. port->type = PORT_MCF;
  328. port->fifosize = MCFUART_TXFIFOSIZE;
  329. /* Clear mask, so no surprise interrupts. */
  330. writeb(0, port->membase + MCFUART_UIMR);
  331. if (request_irq(port->irq, mcf_interrupt, 0, "UART", port))
  332. printk(KERN_ERR "MCF: unable to attach ColdFire UART %d "
  333. "interrupt vector=%d\n", port->line, port->irq);
  334. }
  335. /****************************************************************************/
  336. static const char *mcf_type(struct uart_port *port)
  337. {
  338. return (port->type == PORT_MCF) ? "ColdFire UART" : NULL;
  339. }
  340. /****************************************************************************/
  341. static int mcf_request_port(struct uart_port *port)
  342. {
  343. /* UARTs always present */
  344. return 0;
  345. }
  346. /****************************************************************************/
  347. static void mcf_release_port(struct uart_port *port)
  348. {
  349. /* Nothing to release... */
  350. }
  351. /****************************************************************************/
  352. static int mcf_verify_port(struct uart_port *port, struct serial_struct *ser)
  353. {
  354. if ((ser->type != PORT_UNKNOWN) && (ser->type != PORT_MCF))
  355. return -EINVAL;
  356. return 0;
  357. }
  358. /****************************************************************************/
  359. /* Enable or disable the RS485 support */
  360. static void mcf_config_rs485(struct uart_port *port, struct serial_rs485 *rs485)
  361. {
  362. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  363. unsigned long flags;
  364. unsigned char mr1, mr2;
  365. spin_lock_irqsave(&port->lock, flags);
  366. /* Get mode registers */
  367. mr1 = readb(port->membase + MCFUART_UMR);
  368. mr2 = readb(port->membase + MCFUART_UMR);
  369. if (rs485->flags & SER_RS485_ENABLED) {
  370. dev_dbg(port->dev, "Setting UART to RS485\n");
  371. /* Automatically negate RTS after TX completes */
  372. mr2 |= MCFUART_MR2_TXRTS;
  373. } else {
  374. dev_dbg(port->dev, "Setting UART to RS232\n");
  375. mr2 &= ~MCFUART_MR2_TXRTS;
  376. }
  377. writeb(mr1, port->membase + MCFUART_UMR);
  378. writeb(mr2, port->membase + MCFUART_UMR);
  379. pp->rs485 = *rs485;
  380. spin_unlock_irqrestore(&port->lock, flags);
  381. }
  382. static int mcf_ioctl(struct uart_port *port, unsigned int cmd,
  383. unsigned long arg)
  384. {
  385. switch (cmd) {
  386. case TIOCSRS485: {
  387. struct serial_rs485 rs485;
  388. if (copy_from_user(&rs485, (struct serial_rs485 *)arg,
  389. sizeof(struct serial_rs485)))
  390. return -EFAULT;
  391. mcf_config_rs485(port, &rs485);
  392. break;
  393. }
  394. case TIOCGRS485: {
  395. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  396. if (copy_to_user((struct serial_rs485 *)arg, &pp->rs485,
  397. sizeof(struct serial_rs485)))
  398. return -EFAULT;
  399. break;
  400. }
  401. default:
  402. return -ENOIOCTLCMD;
  403. }
  404. return 0;
  405. }
  406. /****************************************************************************/
  407. /*
  408. * Define the basic serial functions we support.
  409. */
  410. static const struct uart_ops mcf_uart_ops = {
  411. .tx_empty = mcf_tx_empty,
  412. .get_mctrl = mcf_get_mctrl,
  413. .set_mctrl = mcf_set_mctrl,
  414. .start_tx = mcf_start_tx,
  415. .stop_tx = mcf_stop_tx,
  416. .stop_rx = mcf_stop_rx,
  417. .enable_ms = mcf_enable_ms,
  418. .break_ctl = mcf_break_ctl,
  419. .startup = mcf_startup,
  420. .shutdown = mcf_shutdown,
  421. .set_termios = mcf_set_termios,
  422. .type = mcf_type,
  423. .request_port = mcf_request_port,
  424. .release_port = mcf_release_port,
  425. .config_port = mcf_config_port,
  426. .verify_port = mcf_verify_port,
  427. .ioctl = mcf_ioctl,
  428. };
  429. static struct mcf_uart mcf_ports[4];
  430. #define MCF_MAXPORTS ARRAY_SIZE(mcf_ports)
  431. /****************************************************************************/
  432. #if defined(CONFIG_SERIAL_MCF_CONSOLE)
  433. /****************************************************************************/
  434. int __init early_mcf_setup(struct mcf_platform_uart *platp)
  435. {
  436. struct uart_port *port;
  437. int i;
  438. for (i = 0; ((i < MCF_MAXPORTS) && (platp[i].mapbase)); i++) {
  439. port = &mcf_ports[i].port;
  440. port->line = i;
  441. port->type = PORT_MCF;
  442. port->mapbase = platp[i].mapbase;
  443. port->membase = (platp[i].membase) ? platp[i].membase :
  444. (unsigned char __iomem *) port->mapbase;
  445. port->iotype = SERIAL_IO_MEM;
  446. port->irq = platp[i].irq;
  447. port->uartclk = MCF_BUSCLK;
  448. port->flags = ASYNC_BOOT_AUTOCONF;
  449. port->ops = &mcf_uart_ops;
  450. }
  451. return 0;
  452. }
  453. /****************************************************************************/
  454. static void mcf_console_putc(struct console *co, const char c)
  455. {
  456. struct uart_port *port = &(mcf_ports + co->index)->port;
  457. int i;
  458. for (i = 0; (i < 0x10000); i++) {
  459. if (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXREADY)
  460. break;
  461. }
  462. writeb(c, port->membase + MCFUART_UTB);
  463. for (i = 0; (i < 0x10000); i++) {
  464. if (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXREADY)
  465. break;
  466. }
  467. }
  468. /****************************************************************************/
  469. static void mcf_console_write(struct console *co, const char *s, unsigned int count)
  470. {
  471. for (; (count); count--, s++) {
  472. mcf_console_putc(co, *s);
  473. if (*s == '\n')
  474. mcf_console_putc(co, '\r');
  475. }
  476. }
  477. /****************************************************************************/
  478. static int __init mcf_console_setup(struct console *co, char *options)
  479. {
  480. struct uart_port *port;
  481. int baud = CONFIG_SERIAL_MCF_BAUDRATE;
  482. int bits = 8;
  483. int parity = 'n';
  484. int flow = 'n';
  485. if ((co->index < 0) || (co->index >= MCF_MAXPORTS))
  486. co->index = 0;
  487. port = &mcf_ports[co->index].port;
  488. if (port->membase == 0)
  489. return -ENODEV;
  490. if (options)
  491. uart_parse_options(options, &baud, &parity, &bits, &flow);
  492. return uart_set_options(port, co, baud, parity, bits, flow);
  493. }
  494. /****************************************************************************/
  495. static struct uart_driver mcf_driver;
  496. static struct console mcf_console = {
  497. .name = "ttyS",
  498. .write = mcf_console_write,
  499. .device = uart_console_device,
  500. .setup = mcf_console_setup,
  501. .flags = CON_PRINTBUFFER,
  502. .index = -1,
  503. .data = &mcf_driver,
  504. };
  505. static int __init mcf_console_init(void)
  506. {
  507. register_console(&mcf_console);
  508. return 0;
  509. }
  510. console_initcall(mcf_console_init);
  511. #define MCF_CONSOLE &mcf_console
  512. /****************************************************************************/
  513. #else
  514. /****************************************************************************/
  515. #define MCF_CONSOLE NULL
  516. /****************************************************************************/
  517. #endif /* CONFIG_MCF_CONSOLE */
  518. /****************************************************************************/
  519. /*
  520. * Define the mcf UART driver structure.
  521. */
  522. static struct uart_driver mcf_driver = {
  523. .owner = THIS_MODULE,
  524. .driver_name = "mcf",
  525. .dev_name = "ttyS",
  526. .major = TTY_MAJOR,
  527. .minor = 64,
  528. .nr = MCF_MAXPORTS,
  529. .cons = MCF_CONSOLE,
  530. };
  531. /****************************************************************************/
  532. static int mcf_probe(struct platform_device *pdev)
  533. {
  534. struct mcf_platform_uart *platp = dev_get_platdata(&pdev->dev);
  535. struct uart_port *port;
  536. int i;
  537. for (i = 0; ((i < MCF_MAXPORTS) && (platp[i].mapbase)); i++) {
  538. port = &mcf_ports[i].port;
  539. port->line = i;
  540. port->type = PORT_MCF;
  541. port->mapbase = platp[i].mapbase;
  542. port->membase = (platp[i].membase) ? platp[i].membase :
  543. (unsigned char __iomem *) platp[i].mapbase;
  544. port->iotype = SERIAL_IO_MEM;
  545. port->irq = platp[i].irq;
  546. port->uartclk = MCF_BUSCLK;
  547. port->ops = &mcf_uart_ops;
  548. port->flags = ASYNC_BOOT_AUTOCONF;
  549. uart_add_one_port(&mcf_driver, port);
  550. }
  551. return 0;
  552. }
  553. /****************************************************************************/
  554. static int mcf_remove(struct platform_device *pdev)
  555. {
  556. struct uart_port *port;
  557. int i;
  558. for (i = 0; (i < MCF_MAXPORTS); i++) {
  559. port = &mcf_ports[i].port;
  560. if (port)
  561. uart_remove_one_port(&mcf_driver, port);
  562. }
  563. return 0;
  564. }
  565. /****************************************************************************/
  566. static struct platform_driver mcf_platform_driver = {
  567. .probe = mcf_probe,
  568. .remove = mcf_remove,
  569. .driver = {
  570. .name = "mcfuart",
  571. .owner = THIS_MODULE,
  572. },
  573. };
  574. /****************************************************************************/
  575. static int __init mcf_init(void)
  576. {
  577. int rc;
  578. printk("ColdFire internal UART serial driver\n");
  579. rc = uart_register_driver(&mcf_driver);
  580. if (rc)
  581. return rc;
  582. rc = platform_driver_register(&mcf_platform_driver);
  583. if (rc) {
  584. uart_unregister_driver(&mcf_driver);
  585. return rc;
  586. }
  587. return 0;
  588. }
  589. /****************************************************************************/
  590. static void __exit mcf_exit(void)
  591. {
  592. platform_driver_unregister(&mcf_platform_driver);
  593. uart_unregister_driver(&mcf_driver);
  594. }
  595. /****************************************************************************/
  596. module_init(mcf_init);
  597. module_exit(mcf_exit);
  598. MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
  599. MODULE_DESCRIPTION("Freescale ColdFire UART driver");
  600. MODULE_LICENSE("GPL");
  601. MODULE_ALIAS("platform:mcfuart");
  602. /****************************************************************************/