mcf.c 19 KB

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