mcf.c 19 KB

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