mcf.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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. if (termios->c_cflag & CSTOPB)
  201. mr2 |= MCFUART_MR2_STOP2;
  202. else
  203. mr2 |= MCFUART_MR2_STOP1;
  204. if (termios->c_cflag & CRTSCTS) {
  205. mr1 |= MCFUART_MR1_RXRTS;
  206. mr2 |= MCFUART_MR2_TXCTS;
  207. }
  208. if (pp->rs485.flags & SER_RS485_ENABLED) {
  209. dev_dbg(port->dev, "Setting UART to RS485\n");
  210. mr2 |= MCFUART_MR2_TXRTS;
  211. }
  212. spin_lock_irqsave(&port->lock, flags);
  213. uart_update_timeout(port, termios->c_cflag, baud);
  214. writeb(MCFUART_UCR_CMDRESETRX, port->membase + MCFUART_UCR);
  215. writeb(MCFUART_UCR_CMDRESETTX, port->membase + MCFUART_UCR);
  216. writeb(MCFUART_UCR_CMDRESETMRPTR, port->membase + MCFUART_UCR);
  217. writeb(mr1, port->membase + MCFUART_UMR);
  218. writeb(mr2, port->membase + MCFUART_UMR);
  219. writeb((baudclk & 0xff00) >> 8, port->membase + MCFUART_UBG1);
  220. writeb((baudclk & 0xff), port->membase + MCFUART_UBG2);
  221. #if defined(CONFIG_M5272)
  222. writeb((baudfr & 0x0f), port->membase + MCFUART_UFPD);
  223. #endif
  224. writeb(MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER,
  225. port->membase + MCFUART_UCSR);
  226. writeb(MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE,
  227. port->membase + MCFUART_UCR);
  228. spin_unlock_irqrestore(&port->lock, flags);
  229. }
  230. /****************************************************************************/
  231. static void mcf_rx_chars(struct mcf_uart *pp)
  232. {
  233. struct uart_port *port = &pp->port;
  234. unsigned char status, ch, flag;
  235. while ((status = readb(port->membase + MCFUART_USR)) & MCFUART_USR_RXREADY) {
  236. ch = readb(port->membase + MCFUART_URB);
  237. flag = TTY_NORMAL;
  238. port->icount.rx++;
  239. if (status & MCFUART_USR_RXERR) {
  240. writeb(MCFUART_UCR_CMDRESETERR,
  241. port->membase + MCFUART_UCR);
  242. if (status & MCFUART_USR_RXBREAK) {
  243. port->icount.brk++;
  244. if (uart_handle_break(port))
  245. continue;
  246. } else if (status & MCFUART_USR_RXPARITY) {
  247. port->icount.parity++;
  248. } else if (status & MCFUART_USR_RXOVERRUN) {
  249. port->icount.overrun++;
  250. } else if (status & MCFUART_USR_RXFRAMING) {
  251. port->icount.frame++;
  252. }
  253. status &= port->read_status_mask;
  254. if (status & MCFUART_USR_RXBREAK)
  255. flag = TTY_BREAK;
  256. else if (status & MCFUART_USR_RXPARITY)
  257. flag = TTY_PARITY;
  258. else if (status & MCFUART_USR_RXFRAMING)
  259. flag = TTY_FRAME;
  260. }
  261. if (uart_handle_sysrq_char(port, ch))
  262. continue;
  263. uart_insert_char(port, status, MCFUART_USR_RXOVERRUN, ch, flag);
  264. }
  265. spin_unlock(&port->lock);
  266. tty_flip_buffer_push(&port->state->port);
  267. spin_lock(&port->lock);
  268. }
  269. /****************************************************************************/
  270. static void mcf_tx_chars(struct mcf_uart *pp)
  271. {
  272. struct uart_port *port = &pp->port;
  273. struct circ_buf *xmit = &port->state->xmit;
  274. if (port->x_char) {
  275. /* Send special char - probably flow control */
  276. writeb(port->x_char, port->membase + MCFUART_UTB);
  277. port->x_char = 0;
  278. port->icount.tx++;
  279. return;
  280. }
  281. while (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXREADY) {
  282. if (xmit->head == xmit->tail)
  283. break;
  284. writeb(xmit->buf[xmit->tail], port->membase + MCFUART_UTB);
  285. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE -1);
  286. port->icount.tx++;
  287. }
  288. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  289. uart_write_wakeup(port);
  290. if (xmit->head == xmit->tail) {
  291. pp->imr &= ~MCFUART_UIR_TXREADY;
  292. writeb(pp->imr, port->membase + MCFUART_UIMR);
  293. /* Disable TX to negate RTS automatically */
  294. if (pp->rs485.flags & SER_RS485_ENABLED)
  295. writeb(MCFUART_UCR_TXDISABLE,
  296. port->membase + MCFUART_UCR);
  297. }
  298. }
  299. /****************************************************************************/
  300. static irqreturn_t mcf_interrupt(int irq, void *data)
  301. {
  302. struct uart_port *port = data;
  303. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  304. unsigned int isr;
  305. irqreturn_t ret = IRQ_NONE;
  306. isr = readb(port->membase + MCFUART_UISR) & pp->imr;
  307. spin_lock(&port->lock);
  308. if (isr & MCFUART_UIR_RXREADY) {
  309. mcf_rx_chars(pp);
  310. ret = IRQ_HANDLED;
  311. }
  312. if (isr & MCFUART_UIR_TXREADY) {
  313. mcf_tx_chars(pp);
  314. ret = IRQ_HANDLED;
  315. }
  316. spin_unlock(&port->lock);
  317. return ret;
  318. }
  319. /****************************************************************************/
  320. static void mcf_config_port(struct uart_port *port, int flags)
  321. {
  322. port->type = PORT_MCF;
  323. port->fifosize = MCFUART_TXFIFOSIZE;
  324. /* Clear mask, so no surprise interrupts. */
  325. writeb(0, port->membase + MCFUART_UIMR);
  326. if (request_irq(port->irq, mcf_interrupt, 0, "UART", port))
  327. printk(KERN_ERR "MCF: unable to attach ColdFire UART %d "
  328. "interrupt vector=%d\n", port->line, port->irq);
  329. }
  330. /****************************************************************************/
  331. static const char *mcf_type(struct uart_port *port)
  332. {
  333. return (port->type == PORT_MCF) ? "ColdFire UART" : NULL;
  334. }
  335. /****************************************************************************/
  336. static int mcf_request_port(struct uart_port *port)
  337. {
  338. /* UARTs always present */
  339. return 0;
  340. }
  341. /****************************************************************************/
  342. static void mcf_release_port(struct uart_port *port)
  343. {
  344. /* Nothing to release... */
  345. }
  346. /****************************************************************************/
  347. static int mcf_verify_port(struct uart_port *port, struct serial_struct *ser)
  348. {
  349. if ((ser->type != PORT_UNKNOWN) && (ser->type != PORT_MCF))
  350. return -EINVAL;
  351. return 0;
  352. }
  353. /****************************************************************************/
  354. /* Enable or disable the RS485 support */
  355. static void mcf_config_rs485(struct uart_port *port, struct serial_rs485 *rs485)
  356. {
  357. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  358. unsigned long flags;
  359. unsigned char mr1, mr2;
  360. spin_lock_irqsave(&port->lock, flags);
  361. /* Get mode registers */
  362. mr1 = readb(port->membase + MCFUART_UMR);
  363. mr2 = readb(port->membase + MCFUART_UMR);
  364. if (rs485->flags & SER_RS485_ENABLED) {
  365. dev_dbg(port->dev, "Setting UART to RS485\n");
  366. /* Automatically negate RTS after TX completes */
  367. mr2 |= MCFUART_MR2_TXRTS;
  368. } else {
  369. dev_dbg(port->dev, "Setting UART to RS232\n");
  370. mr2 &= ~MCFUART_MR2_TXRTS;
  371. }
  372. writeb(mr1, port->membase + MCFUART_UMR);
  373. writeb(mr2, port->membase + MCFUART_UMR);
  374. pp->rs485 = *rs485;
  375. spin_unlock_irqrestore(&port->lock, flags);
  376. }
  377. static int mcf_ioctl(struct uart_port *port, unsigned int cmd,
  378. unsigned long arg)
  379. {
  380. switch (cmd) {
  381. case TIOCSRS485: {
  382. struct serial_rs485 rs485;
  383. if (copy_from_user(&rs485, (struct serial_rs485 *)arg,
  384. sizeof(struct serial_rs485)))
  385. return -EFAULT;
  386. mcf_config_rs485(port, &rs485);
  387. break;
  388. }
  389. case TIOCGRS485: {
  390. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  391. if (copy_to_user((struct serial_rs485 *)arg, &pp->rs485,
  392. sizeof(struct serial_rs485)))
  393. return -EFAULT;
  394. break;
  395. }
  396. default:
  397. return -ENOIOCTLCMD;
  398. }
  399. return 0;
  400. }
  401. /****************************************************************************/
  402. /*
  403. * Define the basic serial functions we support.
  404. */
  405. static const struct uart_ops mcf_uart_ops = {
  406. .tx_empty = mcf_tx_empty,
  407. .get_mctrl = mcf_get_mctrl,
  408. .set_mctrl = mcf_set_mctrl,
  409. .start_tx = mcf_start_tx,
  410. .stop_tx = mcf_stop_tx,
  411. .stop_rx = mcf_stop_rx,
  412. .enable_ms = mcf_enable_ms,
  413. .break_ctl = mcf_break_ctl,
  414. .startup = mcf_startup,
  415. .shutdown = mcf_shutdown,
  416. .set_termios = mcf_set_termios,
  417. .type = mcf_type,
  418. .request_port = mcf_request_port,
  419. .release_port = mcf_release_port,
  420. .config_port = mcf_config_port,
  421. .verify_port = mcf_verify_port,
  422. .ioctl = mcf_ioctl,
  423. };
  424. static struct mcf_uart mcf_ports[4];
  425. #define MCF_MAXPORTS ARRAY_SIZE(mcf_ports)
  426. /****************************************************************************/
  427. #if defined(CONFIG_SERIAL_MCF_CONSOLE)
  428. /****************************************************************************/
  429. int __init early_mcf_setup(struct mcf_platform_uart *platp)
  430. {
  431. struct uart_port *port;
  432. int i;
  433. for (i = 0; ((i < MCF_MAXPORTS) && (platp[i].mapbase)); i++) {
  434. port = &mcf_ports[i].port;
  435. port->line = i;
  436. port->type = PORT_MCF;
  437. port->mapbase = platp[i].mapbase;
  438. port->membase = (platp[i].membase) ? platp[i].membase :
  439. (unsigned char __iomem *) port->mapbase;
  440. port->iotype = SERIAL_IO_MEM;
  441. port->irq = platp[i].irq;
  442. port->uartclk = MCF_BUSCLK;
  443. port->flags = ASYNC_BOOT_AUTOCONF;
  444. port->ops = &mcf_uart_ops;
  445. }
  446. return 0;
  447. }
  448. /****************************************************************************/
  449. static void mcf_console_putc(struct console *co, const char c)
  450. {
  451. struct uart_port *port = &(mcf_ports + co->index)->port;
  452. int i;
  453. for (i = 0; (i < 0x10000); i++) {
  454. if (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXREADY)
  455. break;
  456. }
  457. writeb(c, port->membase + MCFUART_UTB);
  458. for (i = 0; (i < 0x10000); i++) {
  459. if (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXREADY)
  460. break;
  461. }
  462. }
  463. /****************************************************************************/
  464. static void mcf_console_write(struct console *co, const char *s, unsigned int count)
  465. {
  466. for (; (count); count--, s++) {
  467. mcf_console_putc(co, *s);
  468. if (*s == '\n')
  469. mcf_console_putc(co, '\r');
  470. }
  471. }
  472. /****************************************************************************/
  473. static int __init mcf_console_setup(struct console *co, char *options)
  474. {
  475. struct uart_port *port;
  476. int baud = CONFIG_SERIAL_MCF_BAUDRATE;
  477. int bits = 8;
  478. int parity = 'n';
  479. int flow = 'n';
  480. if ((co->index < 0) || (co->index >= MCF_MAXPORTS))
  481. co->index = 0;
  482. port = &mcf_ports[co->index].port;
  483. if (port->membase == 0)
  484. return -ENODEV;
  485. if (options)
  486. uart_parse_options(options, &baud, &parity, &bits, &flow);
  487. return uart_set_options(port, co, baud, parity, bits, flow);
  488. }
  489. /****************************************************************************/
  490. static struct uart_driver mcf_driver;
  491. static struct console mcf_console = {
  492. .name = "ttyS",
  493. .write = mcf_console_write,
  494. .device = uart_console_device,
  495. .setup = mcf_console_setup,
  496. .flags = CON_PRINTBUFFER,
  497. .index = -1,
  498. .data = &mcf_driver,
  499. };
  500. static int __init mcf_console_init(void)
  501. {
  502. register_console(&mcf_console);
  503. return 0;
  504. }
  505. console_initcall(mcf_console_init);
  506. #define MCF_CONSOLE &mcf_console
  507. /****************************************************************************/
  508. #else
  509. /****************************************************************************/
  510. #define MCF_CONSOLE NULL
  511. /****************************************************************************/
  512. #endif /* CONFIG_MCF_CONSOLE */
  513. /****************************************************************************/
  514. /*
  515. * Define the mcf UART driver structure.
  516. */
  517. static struct uart_driver mcf_driver = {
  518. .owner = THIS_MODULE,
  519. .driver_name = "mcf",
  520. .dev_name = "ttyS",
  521. .major = TTY_MAJOR,
  522. .minor = 64,
  523. .nr = MCF_MAXPORTS,
  524. .cons = MCF_CONSOLE,
  525. };
  526. /****************************************************************************/
  527. static int mcf_probe(struct platform_device *pdev)
  528. {
  529. struct mcf_platform_uart *platp = dev_get_platdata(&pdev->dev);
  530. struct uart_port *port;
  531. int i;
  532. for (i = 0; ((i < MCF_MAXPORTS) && (platp[i].mapbase)); i++) {
  533. port = &mcf_ports[i].port;
  534. port->line = i;
  535. port->type = PORT_MCF;
  536. port->mapbase = platp[i].mapbase;
  537. port->membase = (platp[i].membase) ? platp[i].membase :
  538. (unsigned char __iomem *) platp[i].mapbase;
  539. port->iotype = SERIAL_IO_MEM;
  540. port->irq = platp[i].irq;
  541. port->uartclk = MCF_BUSCLK;
  542. port->ops = &mcf_uart_ops;
  543. port->flags = ASYNC_BOOT_AUTOCONF;
  544. uart_add_one_port(&mcf_driver, port);
  545. }
  546. return 0;
  547. }
  548. /****************************************************************************/
  549. static int mcf_remove(struct platform_device *pdev)
  550. {
  551. struct uart_port *port;
  552. int i;
  553. for (i = 0; (i < MCF_MAXPORTS); i++) {
  554. port = &mcf_ports[i].port;
  555. if (port)
  556. uart_remove_one_port(&mcf_driver, port);
  557. }
  558. return 0;
  559. }
  560. /****************************************************************************/
  561. static struct platform_driver mcf_platform_driver = {
  562. .probe = mcf_probe,
  563. .remove = mcf_remove,
  564. .driver = {
  565. .name = "mcfuart",
  566. .owner = THIS_MODULE,
  567. },
  568. };
  569. /****************************************************************************/
  570. static int __init mcf_init(void)
  571. {
  572. int rc;
  573. printk("ColdFire internal UART serial driver\n");
  574. rc = uart_register_driver(&mcf_driver);
  575. if (rc)
  576. return rc;
  577. rc = platform_driver_register(&mcf_platform_driver);
  578. if (rc) {
  579. uart_unregister_driver(&mcf_driver);
  580. return rc;
  581. }
  582. return 0;
  583. }
  584. /****************************************************************************/
  585. static void __exit mcf_exit(void)
  586. {
  587. platform_driver_unregister(&mcf_platform_driver);
  588. uart_unregister_driver(&mcf_driver);
  589. }
  590. /****************************************************************************/
  591. module_init(mcf_init);
  592. module_exit(mcf_exit);
  593. MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
  594. MODULE_DESCRIPTION("Freescale ColdFire UART driver");
  595. MODULE_LICENSE("GPL");
  596. MODULE_ALIAS("platform:mcfuart");
  597. /****************************************************************************/