mcf.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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. };
  54. /****************************************************************************/
  55. static unsigned int mcf_tx_empty(struct uart_port *port)
  56. {
  57. return (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXEMPTY) ?
  58. TIOCSER_TEMT : 0;
  59. }
  60. /****************************************************************************/
  61. static unsigned int mcf_get_mctrl(struct uart_port *port)
  62. {
  63. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  64. unsigned int sigs;
  65. sigs = (readb(port->membase + MCFUART_UIPR) & MCFUART_UIPR_CTS) ?
  66. 0 : TIOCM_CTS;
  67. sigs |= (pp->sigs & TIOCM_RTS);
  68. sigs |= (mcf_getppdcd(port->line) ? TIOCM_CD : 0);
  69. sigs |= (mcf_getppdtr(port->line) ? TIOCM_DTR : 0);
  70. return sigs;
  71. }
  72. /****************************************************************************/
  73. static void mcf_set_mctrl(struct uart_port *port, unsigned int sigs)
  74. {
  75. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  76. pp->sigs = sigs;
  77. mcf_setppdtr(port->line, (sigs & TIOCM_DTR));
  78. if (sigs & TIOCM_RTS)
  79. writeb(MCFUART_UOP_RTS, port->membase + MCFUART_UOP1);
  80. else
  81. writeb(MCFUART_UOP_RTS, port->membase + MCFUART_UOP0);
  82. }
  83. /****************************************************************************/
  84. static void mcf_start_tx(struct uart_port *port)
  85. {
  86. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  87. if (port->rs485.flags & SER_RS485_ENABLED) {
  88. /* Enable Transmitter */
  89. writeb(MCFUART_UCR_TXENABLE, port->membase + MCFUART_UCR);
  90. /* Manually assert RTS */
  91. writeb(MCFUART_UOP_RTS, port->membase + MCFUART_UOP1);
  92. }
  93. pp->imr |= MCFUART_UIR_TXREADY;
  94. writeb(pp->imr, port->membase + MCFUART_UIMR);
  95. }
  96. /****************************************************************************/
  97. static void mcf_stop_tx(struct uart_port *port)
  98. {
  99. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  100. pp->imr &= ~MCFUART_UIR_TXREADY;
  101. writeb(pp->imr, port->membase + MCFUART_UIMR);
  102. }
  103. /****************************************************************************/
  104. static void mcf_stop_rx(struct uart_port *port)
  105. {
  106. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  107. pp->imr &= ~MCFUART_UIR_RXREADY;
  108. writeb(pp->imr, port->membase + MCFUART_UIMR);
  109. }
  110. /****************************************************************************/
  111. static void mcf_break_ctl(struct uart_port *port, int break_state)
  112. {
  113. unsigned long flags;
  114. spin_lock_irqsave(&port->lock, flags);
  115. if (break_state == -1)
  116. writeb(MCFUART_UCR_CMDBREAKSTART, port->membase + MCFUART_UCR);
  117. else
  118. writeb(MCFUART_UCR_CMDBREAKSTOP, port->membase + MCFUART_UCR);
  119. spin_unlock_irqrestore(&port->lock, flags);
  120. }
  121. /****************************************************************************/
  122. static int mcf_startup(struct uart_port *port)
  123. {
  124. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  125. unsigned long flags;
  126. spin_lock_irqsave(&port->lock, flags);
  127. /* Reset UART, get it into known state... */
  128. writeb(MCFUART_UCR_CMDRESETRX, port->membase + MCFUART_UCR);
  129. writeb(MCFUART_UCR_CMDRESETTX, port->membase + MCFUART_UCR);
  130. /* Enable the UART transmitter and receiver */
  131. writeb(MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE,
  132. port->membase + MCFUART_UCR);
  133. /* Enable RX interrupts now */
  134. pp->imr = MCFUART_UIR_RXREADY;
  135. writeb(pp->imr, port->membase + MCFUART_UIMR);
  136. spin_unlock_irqrestore(&port->lock, flags);
  137. return 0;
  138. }
  139. /****************************************************************************/
  140. static void mcf_shutdown(struct uart_port *port)
  141. {
  142. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  143. unsigned long flags;
  144. spin_lock_irqsave(&port->lock, flags);
  145. /* Disable all interrupts now */
  146. pp->imr = 0;
  147. writeb(pp->imr, port->membase + MCFUART_UIMR);
  148. /* Disable UART transmitter and receiver */
  149. writeb(MCFUART_UCR_CMDRESETRX, port->membase + MCFUART_UCR);
  150. writeb(MCFUART_UCR_CMDRESETTX, port->membase + MCFUART_UCR);
  151. spin_unlock_irqrestore(&port->lock, flags);
  152. }
  153. /****************************************************************************/
  154. static void mcf_set_termios(struct uart_port *port, struct ktermios *termios,
  155. struct ktermios *old)
  156. {
  157. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  158. unsigned long flags;
  159. unsigned int baud, baudclk;
  160. #if defined(CONFIG_M5272)
  161. unsigned int baudfr;
  162. #endif
  163. unsigned char mr1, mr2;
  164. baud = uart_get_baud_rate(port, termios, old, 0, 230400);
  165. #if defined(CONFIG_M5272)
  166. baudclk = (MCF_BUSCLK / baud) / 32;
  167. baudfr = (((MCF_BUSCLK / baud) + 1) / 2) % 16;
  168. #else
  169. baudclk = ((MCF_BUSCLK / baud) + 16) / 32;
  170. #endif
  171. mr1 = MCFUART_MR1_RXIRQRDY | MCFUART_MR1_RXERRCHAR;
  172. mr2 = 0;
  173. switch (termios->c_cflag & CSIZE) {
  174. case CS5: mr1 |= MCFUART_MR1_CS5; break;
  175. case CS6: mr1 |= MCFUART_MR1_CS6; break;
  176. case CS7: mr1 |= MCFUART_MR1_CS7; break;
  177. case CS8:
  178. default: mr1 |= MCFUART_MR1_CS8; break;
  179. }
  180. if (termios->c_cflag & PARENB) {
  181. if (termios->c_cflag & CMSPAR) {
  182. if (termios->c_cflag & PARODD)
  183. mr1 |= MCFUART_MR1_PARITYMARK;
  184. else
  185. mr1 |= MCFUART_MR1_PARITYSPACE;
  186. } else {
  187. if (termios->c_cflag & PARODD)
  188. mr1 |= MCFUART_MR1_PARITYODD;
  189. else
  190. mr1 |= MCFUART_MR1_PARITYEVEN;
  191. }
  192. } else {
  193. mr1 |= MCFUART_MR1_PARITYNONE;
  194. }
  195. /*
  196. * FIXME: port->read_status_mask and port->ignore_status_mask
  197. * need to be initialized based on termios settings for
  198. * INPCK, IGNBRK, IGNPAR, PARMRK, BRKINT
  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. spin_lock_irqsave(&port->lock, flags);
  209. if (port->rs485.flags & SER_RS485_ENABLED) {
  210. dev_dbg(port->dev, "Setting UART to RS485\n");
  211. mr2 |= MCFUART_MR2_TXRTS;
  212. }
  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 (port->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 int 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 char mr1, mr2;
  359. /* Get mode registers */
  360. mr1 = readb(port->membase + MCFUART_UMR);
  361. mr2 = readb(port->membase + MCFUART_UMR);
  362. if (rs485->flags & SER_RS485_ENABLED) {
  363. dev_dbg(port->dev, "Setting UART to RS485\n");
  364. /* Automatically negate RTS after TX completes */
  365. mr2 |= MCFUART_MR2_TXRTS;
  366. } else {
  367. dev_dbg(port->dev, "Setting UART to RS232\n");
  368. mr2 &= ~MCFUART_MR2_TXRTS;
  369. }
  370. writeb(mr1, port->membase + MCFUART_UMR);
  371. writeb(mr2, port->membase + MCFUART_UMR);
  372. port->rs485 = *rs485;
  373. return 0;
  374. }
  375. /****************************************************************************/
  376. /*
  377. * Define the basic serial functions we support.
  378. */
  379. static const struct uart_ops mcf_uart_ops = {
  380. .tx_empty = mcf_tx_empty,
  381. .get_mctrl = mcf_get_mctrl,
  382. .set_mctrl = mcf_set_mctrl,
  383. .start_tx = mcf_start_tx,
  384. .stop_tx = mcf_stop_tx,
  385. .stop_rx = mcf_stop_rx,
  386. .break_ctl = mcf_break_ctl,
  387. .startup = mcf_startup,
  388. .shutdown = mcf_shutdown,
  389. .set_termios = mcf_set_termios,
  390. .type = mcf_type,
  391. .request_port = mcf_request_port,
  392. .release_port = mcf_release_port,
  393. .config_port = mcf_config_port,
  394. .verify_port = mcf_verify_port,
  395. };
  396. static struct mcf_uart mcf_ports[4];
  397. #define MCF_MAXPORTS ARRAY_SIZE(mcf_ports)
  398. /****************************************************************************/
  399. #if defined(CONFIG_SERIAL_MCF_CONSOLE)
  400. /****************************************************************************/
  401. int __init early_mcf_setup(struct mcf_platform_uart *platp)
  402. {
  403. struct uart_port *port;
  404. int i;
  405. for (i = 0; ((i < MCF_MAXPORTS) && (platp[i].mapbase)); i++) {
  406. port = &mcf_ports[i].port;
  407. port->line = i;
  408. port->type = PORT_MCF;
  409. port->mapbase = platp[i].mapbase;
  410. port->membase = (platp[i].membase) ? platp[i].membase :
  411. (unsigned char __iomem *) port->mapbase;
  412. port->iotype = SERIAL_IO_MEM;
  413. port->irq = platp[i].irq;
  414. port->uartclk = MCF_BUSCLK;
  415. port->flags = UPF_BOOT_AUTOCONF;
  416. port->rs485_config = mcf_config_rs485;
  417. port->ops = &mcf_uart_ops;
  418. }
  419. return 0;
  420. }
  421. /****************************************************************************/
  422. static void mcf_console_putc(struct console *co, const char c)
  423. {
  424. struct uart_port *port = &(mcf_ports + co->index)->port;
  425. int i;
  426. for (i = 0; (i < 0x10000); i++) {
  427. if (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXREADY)
  428. break;
  429. }
  430. writeb(c, port->membase + MCFUART_UTB);
  431. for (i = 0; (i < 0x10000); i++) {
  432. if (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXREADY)
  433. break;
  434. }
  435. }
  436. /****************************************************************************/
  437. static void mcf_console_write(struct console *co, const char *s, unsigned int count)
  438. {
  439. for (; (count); count--, s++) {
  440. mcf_console_putc(co, *s);
  441. if (*s == '\n')
  442. mcf_console_putc(co, '\r');
  443. }
  444. }
  445. /****************************************************************************/
  446. static int __init mcf_console_setup(struct console *co, char *options)
  447. {
  448. struct uart_port *port;
  449. int baud = CONFIG_SERIAL_MCF_BAUDRATE;
  450. int bits = 8;
  451. int parity = 'n';
  452. int flow = 'n';
  453. if ((co->index < 0) || (co->index >= MCF_MAXPORTS))
  454. co->index = 0;
  455. port = &mcf_ports[co->index].port;
  456. if (port->membase == 0)
  457. return -ENODEV;
  458. if (options)
  459. uart_parse_options(options, &baud, &parity, &bits, &flow);
  460. return uart_set_options(port, co, baud, parity, bits, flow);
  461. }
  462. /****************************************************************************/
  463. static struct uart_driver mcf_driver;
  464. static struct console mcf_console = {
  465. .name = "ttyS",
  466. .write = mcf_console_write,
  467. .device = uart_console_device,
  468. .setup = mcf_console_setup,
  469. .flags = CON_PRINTBUFFER,
  470. .index = -1,
  471. .data = &mcf_driver,
  472. };
  473. static int __init mcf_console_init(void)
  474. {
  475. register_console(&mcf_console);
  476. return 0;
  477. }
  478. console_initcall(mcf_console_init);
  479. #define MCF_CONSOLE &mcf_console
  480. /****************************************************************************/
  481. #else
  482. /****************************************************************************/
  483. #define MCF_CONSOLE NULL
  484. /****************************************************************************/
  485. #endif /* CONFIG_MCF_CONSOLE */
  486. /****************************************************************************/
  487. /*
  488. * Define the mcf UART driver structure.
  489. */
  490. static struct uart_driver mcf_driver = {
  491. .owner = THIS_MODULE,
  492. .driver_name = "mcf",
  493. .dev_name = "ttyS",
  494. .major = TTY_MAJOR,
  495. .minor = 64,
  496. .nr = MCF_MAXPORTS,
  497. .cons = MCF_CONSOLE,
  498. };
  499. /****************************************************************************/
  500. static int mcf_probe(struct platform_device *pdev)
  501. {
  502. struct mcf_platform_uart *platp = dev_get_platdata(&pdev->dev);
  503. struct uart_port *port;
  504. int i;
  505. for (i = 0; ((i < MCF_MAXPORTS) && (platp[i].mapbase)); i++) {
  506. port = &mcf_ports[i].port;
  507. port->line = i;
  508. port->type = PORT_MCF;
  509. port->mapbase = platp[i].mapbase;
  510. port->membase = (platp[i].membase) ? platp[i].membase :
  511. (unsigned char __iomem *) platp[i].mapbase;
  512. port->iotype = SERIAL_IO_MEM;
  513. port->irq = platp[i].irq;
  514. port->uartclk = MCF_BUSCLK;
  515. port->ops = &mcf_uart_ops;
  516. port->flags = UPF_BOOT_AUTOCONF;
  517. port->rs485_config = mcf_config_rs485;
  518. uart_add_one_port(&mcf_driver, port);
  519. }
  520. return 0;
  521. }
  522. /****************************************************************************/
  523. static int mcf_remove(struct platform_device *pdev)
  524. {
  525. struct uart_port *port;
  526. int i;
  527. for (i = 0; (i < MCF_MAXPORTS); i++) {
  528. port = &mcf_ports[i].port;
  529. if (port)
  530. uart_remove_one_port(&mcf_driver, port);
  531. }
  532. return 0;
  533. }
  534. /****************************************************************************/
  535. static struct platform_driver mcf_platform_driver = {
  536. .probe = mcf_probe,
  537. .remove = mcf_remove,
  538. .driver = {
  539. .name = "mcfuart",
  540. },
  541. };
  542. /****************************************************************************/
  543. static int __init mcf_init(void)
  544. {
  545. int rc;
  546. printk("ColdFire internal UART serial driver\n");
  547. rc = uart_register_driver(&mcf_driver);
  548. if (rc)
  549. return rc;
  550. rc = platform_driver_register(&mcf_platform_driver);
  551. if (rc) {
  552. uart_unregister_driver(&mcf_driver);
  553. return rc;
  554. }
  555. return 0;
  556. }
  557. /****************************************************************************/
  558. static void __exit mcf_exit(void)
  559. {
  560. platform_driver_unregister(&mcf_platform_driver);
  561. uart_unregister_driver(&mcf_driver);
  562. }
  563. /****************************************************************************/
  564. module_init(mcf_init);
  565. module_exit(mcf_exit);
  566. MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
  567. MODULE_DESCRIPTION("Freescale ColdFire UART driver");
  568. MODULE_LICENSE("GPL");
  569. MODULE_ALIAS("platform:mcfuart");
  570. /****************************************************************************/