mcf.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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 <asm/coldfire.h>
  25. #include <asm/mcfsim.h>
  26. #include <asm/mcfuart.h>
  27. #include <asm/nettel.h>
  28. /****************************************************************************/
  29. /*
  30. * Some boards implement the DTR/DCD lines using GPIO lines, most
  31. * don't. Dummy out the access macros for those that don't. Those
  32. * that do should define these macros somewhere in there board
  33. * specific inlude files.
  34. */
  35. #if !defined(mcf_getppdcd)
  36. #define mcf_getppdcd(p) (1)
  37. #endif
  38. #if !defined(mcf_getppdtr)
  39. #define mcf_getppdtr(p) (1)
  40. #endif
  41. #if !defined(mcf_setppdtr)
  42. #define mcf_setppdtr(p, v) do { } while (0)
  43. #endif
  44. /****************************************************************************/
  45. /*
  46. * Local per-uart structure.
  47. */
  48. struct mcf_uart {
  49. struct uart_port port;
  50. unsigned int sigs; /* Local copy of line sigs */
  51. unsigned char imr; /* Local IMR mirror */
  52. struct serial_rs485 rs485; /* RS485 settings */
  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 (pp->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 void mcf_enable_ms(struct uart_port *port)
  123. {
  124. }
  125. /****************************************************************************/
  126. static int mcf_startup(struct uart_port *port)
  127. {
  128. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  129. unsigned long flags;
  130. spin_lock_irqsave(&port->lock, flags);
  131. /* Reset UART, get it into known state... */
  132. writeb(MCFUART_UCR_CMDRESETRX, port->membase + MCFUART_UCR);
  133. writeb(MCFUART_UCR_CMDRESETTX, port->membase + MCFUART_UCR);
  134. /* Enable the UART transmitter and receiver */
  135. writeb(MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE,
  136. port->membase + MCFUART_UCR);
  137. /* Enable RX interrupts now */
  138. pp->imr = MCFUART_UIR_RXREADY;
  139. writeb(pp->imr, port->membase + MCFUART_UIMR);
  140. spin_unlock_irqrestore(&port->lock, flags);
  141. return 0;
  142. }
  143. /****************************************************************************/
  144. static void mcf_shutdown(struct uart_port *port)
  145. {
  146. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  147. unsigned long flags;
  148. spin_lock_irqsave(&port->lock, flags);
  149. /* Disable all interrupts now */
  150. pp->imr = 0;
  151. writeb(pp->imr, port->membase + MCFUART_UIMR);
  152. /* Disable UART transmitter and receiver */
  153. writeb(MCFUART_UCR_CMDRESETRX, port->membase + MCFUART_UCR);
  154. writeb(MCFUART_UCR_CMDRESETTX, port->membase + MCFUART_UCR);
  155. spin_unlock_irqrestore(&port->lock, flags);
  156. }
  157. /****************************************************************************/
  158. static void mcf_set_termios(struct uart_port *port, struct ktermios *termios,
  159. struct ktermios *old)
  160. {
  161. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  162. unsigned long flags;
  163. unsigned int baud, baudclk;
  164. #if defined(CONFIG_M5272)
  165. unsigned int baudfr;
  166. #endif
  167. unsigned char mr1, mr2;
  168. baud = uart_get_baud_rate(port, termios, old, 0, 230400);
  169. #if defined(CONFIG_M5272)
  170. baudclk = (MCF_BUSCLK / baud) / 32;
  171. baudfr = (((MCF_BUSCLK / baud) + 1) / 2) % 16;
  172. #else
  173. baudclk = ((MCF_BUSCLK / baud) + 16) / 32;
  174. #endif
  175. mr1 = MCFUART_MR1_RXIRQRDY | MCFUART_MR1_RXERRCHAR;
  176. mr2 = 0;
  177. switch (termios->c_cflag & CSIZE) {
  178. case CS5: mr1 |= MCFUART_MR1_CS5; break;
  179. case CS6: mr1 |= MCFUART_MR1_CS6; break;
  180. case CS7: mr1 |= MCFUART_MR1_CS7; break;
  181. case CS8:
  182. default: mr1 |= MCFUART_MR1_CS8; break;
  183. }
  184. if (termios->c_cflag & PARENB) {
  185. if (termios->c_cflag & CMSPAR) {
  186. if (termios->c_cflag & PARODD)
  187. mr1 |= MCFUART_MR1_PARITYMARK;
  188. else
  189. mr1 |= MCFUART_MR1_PARITYSPACE;
  190. } else {
  191. if (termios->c_cflag & PARODD)
  192. mr1 |= MCFUART_MR1_PARITYODD;
  193. else
  194. mr1 |= MCFUART_MR1_PARITYEVEN;
  195. }
  196. } else {
  197. mr1 |= MCFUART_MR1_PARITYNONE;
  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. if (pp->rs485.flags & SER_RS485_ENABLED) {
  208. dev_dbg(port->dev, "Setting UART to RS485\n");
  209. mr2 |= MCFUART_MR2_TXRTS;
  210. }
  211. spin_lock_irqsave(&port->lock, flags);
  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. tty_flip_buffer_push(&port->state->port);
  265. }
  266. /****************************************************************************/
  267. static void mcf_tx_chars(struct mcf_uart *pp)
  268. {
  269. struct uart_port *port = &pp->port;
  270. struct circ_buf *xmit = &port->state->xmit;
  271. if (port->x_char) {
  272. /* Send special char - probably flow control */
  273. writeb(port->x_char, port->membase + MCFUART_UTB);
  274. port->x_char = 0;
  275. port->icount.tx++;
  276. return;
  277. }
  278. while (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXREADY) {
  279. if (xmit->head == xmit->tail)
  280. break;
  281. writeb(xmit->buf[xmit->tail], port->membase + MCFUART_UTB);
  282. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE -1);
  283. port->icount.tx++;
  284. }
  285. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  286. uart_write_wakeup(port);
  287. if (xmit->head == xmit->tail) {
  288. pp->imr &= ~MCFUART_UIR_TXREADY;
  289. writeb(pp->imr, port->membase + MCFUART_UIMR);
  290. /* Disable TX to negate RTS automatically */
  291. if (pp->rs485.flags & SER_RS485_ENABLED)
  292. writeb(MCFUART_UCR_TXDISABLE,
  293. port->membase + MCFUART_UCR);
  294. }
  295. }
  296. /****************************************************************************/
  297. static irqreturn_t mcf_interrupt(int irq, void *data)
  298. {
  299. struct uart_port *port = data;
  300. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  301. unsigned int isr;
  302. irqreturn_t ret = IRQ_NONE;
  303. isr = readb(port->membase + MCFUART_UISR) & pp->imr;
  304. spin_lock(&port->lock);
  305. if (isr & MCFUART_UIR_RXREADY) {
  306. mcf_rx_chars(pp);
  307. ret = IRQ_HANDLED;
  308. }
  309. if (isr & MCFUART_UIR_TXREADY) {
  310. mcf_tx_chars(pp);
  311. ret = IRQ_HANDLED;
  312. }
  313. spin_unlock(&port->lock);
  314. return ret;
  315. }
  316. /****************************************************************************/
  317. static void mcf_config_port(struct uart_port *port, int flags)
  318. {
  319. port->type = PORT_MCF;
  320. port->fifosize = MCFUART_TXFIFOSIZE;
  321. /* Clear mask, so no surprise interrupts. */
  322. writeb(0, port->membase + MCFUART_UIMR);
  323. if (request_irq(port->irq, mcf_interrupt, 0, "UART", port))
  324. printk(KERN_ERR "MCF: unable to attach ColdFire UART %d "
  325. "interrupt vector=%d\n", port->line, port->irq);
  326. }
  327. /****************************************************************************/
  328. static const char *mcf_type(struct uart_port *port)
  329. {
  330. return (port->type == PORT_MCF) ? "ColdFire UART" : NULL;
  331. }
  332. /****************************************************************************/
  333. static int mcf_request_port(struct uart_port *port)
  334. {
  335. /* UARTs always present */
  336. return 0;
  337. }
  338. /****************************************************************************/
  339. static void mcf_release_port(struct uart_port *port)
  340. {
  341. /* Nothing to release... */
  342. }
  343. /****************************************************************************/
  344. static int mcf_verify_port(struct uart_port *port, struct serial_struct *ser)
  345. {
  346. if ((ser->type != PORT_UNKNOWN) && (ser->type != PORT_MCF))
  347. return -EINVAL;
  348. return 0;
  349. }
  350. /****************************************************************************/
  351. /* Enable or disable the RS485 support */
  352. static void mcf_config_rs485(struct uart_port *port, struct serial_rs485 *rs485)
  353. {
  354. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  355. unsigned long flags;
  356. unsigned char mr1, mr2;
  357. spin_lock_irqsave(&port->lock, flags);
  358. /* Get mode registers */
  359. mr1 = readb(port->membase + MCFUART_UMR);
  360. mr2 = readb(port->membase + MCFUART_UMR);
  361. if (rs485->flags & SER_RS485_ENABLED) {
  362. dev_dbg(port->dev, "Setting UART to RS485\n");
  363. /* Automatically negate RTS after TX completes */
  364. mr2 |= MCFUART_MR2_TXRTS;
  365. } else {
  366. dev_dbg(port->dev, "Setting UART to RS232\n");
  367. mr2 &= ~MCFUART_MR2_TXRTS;
  368. }
  369. writeb(mr1, port->membase + MCFUART_UMR);
  370. writeb(mr2, port->membase + MCFUART_UMR);
  371. pp->rs485 = *rs485;
  372. spin_unlock_irqrestore(&port->lock, flags);
  373. }
  374. static int mcf_ioctl(struct uart_port *port, unsigned int cmd,
  375. unsigned long arg)
  376. {
  377. switch (cmd) {
  378. case TIOCSRS485: {
  379. struct serial_rs485 rs485;
  380. if (copy_from_user(&rs485, (struct serial_rs485 *)arg,
  381. sizeof(struct serial_rs485)))
  382. return -EFAULT;
  383. mcf_config_rs485(port, &rs485);
  384. break;
  385. }
  386. case TIOCGRS485: {
  387. struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
  388. if (copy_to_user((struct serial_rs485 *)arg, &pp->rs485,
  389. sizeof(struct serial_rs485)))
  390. return -EFAULT;
  391. break;
  392. }
  393. default:
  394. return -ENOIOCTLCMD;
  395. }
  396. return 0;
  397. }
  398. /****************************************************************************/
  399. /*
  400. * Define the basic serial functions we support.
  401. */
  402. static const struct uart_ops mcf_uart_ops = {
  403. .tx_empty = mcf_tx_empty,
  404. .get_mctrl = mcf_get_mctrl,
  405. .set_mctrl = mcf_set_mctrl,
  406. .start_tx = mcf_start_tx,
  407. .stop_tx = mcf_stop_tx,
  408. .stop_rx = mcf_stop_rx,
  409. .enable_ms = mcf_enable_ms,
  410. .break_ctl = mcf_break_ctl,
  411. .startup = mcf_startup,
  412. .shutdown = mcf_shutdown,
  413. .set_termios = mcf_set_termios,
  414. .type = mcf_type,
  415. .request_port = mcf_request_port,
  416. .release_port = mcf_release_port,
  417. .config_port = mcf_config_port,
  418. .verify_port = mcf_verify_port,
  419. .ioctl = mcf_ioctl,
  420. };
  421. static struct mcf_uart mcf_ports[4];
  422. #define MCF_MAXPORTS ARRAY_SIZE(mcf_ports)
  423. /****************************************************************************/
  424. #if defined(CONFIG_SERIAL_MCF_CONSOLE)
  425. /****************************************************************************/
  426. int __init early_mcf_setup(struct mcf_platform_uart *platp)
  427. {
  428. struct uart_port *port;
  429. int i;
  430. for (i = 0; ((i < MCF_MAXPORTS) && (platp[i].mapbase)); i++) {
  431. port = &mcf_ports[i].port;
  432. port->line = i;
  433. port->type = PORT_MCF;
  434. port->mapbase = platp[i].mapbase;
  435. port->membase = (platp[i].membase) ? platp[i].membase :
  436. (unsigned char __iomem *) port->mapbase;
  437. port->iotype = SERIAL_IO_MEM;
  438. port->irq = platp[i].irq;
  439. port->uartclk = MCF_BUSCLK;
  440. port->flags = ASYNC_BOOT_AUTOCONF;
  441. port->ops = &mcf_uart_ops;
  442. }
  443. return 0;
  444. }
  445. /****************************************************************************/
  446. static void mcf_console_putc(struct console *co, const char c)
  447. {
  448. struct uart_port *port = &(mcf_ports + co->index)->port;
  449. int i;
  450. for (i = 0; (i < 0x10000); i++) {
  451. if (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXREADY)
  452. break;
  453. }
  454. writeb(c, port->membase + MCFUART_UTB);
  455. for (i = 0; (i < 0x10000); i++) {
  456. if (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXREADY)
  457. break;
  458. }
  459. }
  460. /****************************************************************************/
  461. static void mcf_console_write(struct console *co, const char *s, unsigned int count)
  462. {
  463. for (; (count); count--, s++) {
  464. mcf_console_putc(co, *s);
  465. if (*s == '\n')
  466. mcf_console_putc(co, '\r');
  467. }
  468. }
  469. /****************************************************************************/
  470. static int __init mcf_console_setup(struct console *co, char *options)
  471. {
  472. struct uart_port *port;
  473. int baud = CONFIG_SERIAL_MCF_BAUDRATE;
  474. int bits = 8;
  475. int parity = 'n';
  476. int flow = 'n';
  477. if ((co->index < 0) || (co->index >= MCF_MAXPORTS))
  478. co->index = 0;
  479. port = &mcf_ports[co->index].port;
  480. if (port->membase == 0)
  481. return -ENODEV;
  482. if (options)
  483. uart_parse_options(options, &baud, &parity, &bits, &flow);
  484. return uart_set_options(port, co, baud, parity, bits, flow);
  485. }
  486. /****************************************************************************/
  487. static struct uart_driver mcf_driver;
  488. static struct console mcf_console = {
  489. .name = "ttyS",
  490. .write = mcf_console_write,
  491. .device = uart_console_device,
  492. .setup = mcf_console_setup,
  493. .flags = CON_PRINTBUFFER,
  494. .index = -1,
  495. .data = &mcf_driver,
  496. };
  497. static int __init mcf_console_init(void)
  498. {
  499. register_console(&mcf_console);
  500. return 0;
  501. }
  502. console_initcall(mcf_console_init);
  503. #define MCF_CONSOLE &mcf_console
  504. /****************************************************************************/
  505. #else
  506. /****************************************************************************/
  507. #define MCF_CONSOLE NULL
  508. /****************************************************************************/
  509. #endif /* CONFIG_MCF_CONSOLE */
  510. /****************************************************************************/
  511. /*
  512. * Define the mcf UART driver structure.
  513. */
  514. static struct uart_driver mcf_driver = {
  515. .owner = THIS_MODULE,
  516. .driver_name = "mcf",
  517. .dev_name = "ttyS",
  518. .major = TTY_MAJOR,
  519. .minor = 64,
  520. .nr = MCF_MAXPORTS,
  521. .cons = MCF_CONSOLE,
  522. };
  523. /****************************************************************************/
  524. static int mcf_probe(struct platform_device *pdev)
  525. {
  526. struct mcf_platform_uart *platp = pdev->dev.platform_data;
  527. struct uart_port *port;
  528. int i;
  529. for (i = 0; ((i < MCF_MAXPORTS) && (platp[i].mapbase)); i++) {
  530. port = &mcf_ports[i].port;
  531. port->line = i;
  532. port->type = PORT_MCF;
  533. port->mapbase = platp[i].mapbase;
  534. port->membase = (platp[i].membase) ? platp[i].membase :
  535. (unsigned char __iomem *) platp[i].mapbase;
  536. port->iotype = SERIAL_IO_MEM;
  537. port->irq = platp[i].irq;
  538. port->uartclk = MCF_BUSCLK;
  539. port->ops = &mcf_uart_ops;
  540. port->flags = ASYNC_BOOT_AUTOCONF;
  541. uart_add_one_port(&mcf_driver, port);
  542. }
  543. return 0;
  544. }
  545. /****************************************************************************/
  546. static int mcf_remove(struct platform_device *pdev)
  547. {
  548. struct uart_port *port;
  549. int i;
  550. for (i = 0; (i < MCF_MAXPORTS); i++) {
  551. port = &mcf_ports[i].port;
  552. if (port)
  553. uart_remove_one_port(&mcf_driver, port);
  554. }
  555. return 0;
  556. }
  557. /****************************************************************************/
  558. static struct platform_driver mcf_platform_driver = {
  559. .probe = mcf_probe,
  560. .remove = mcf_remove,
  561. .driver = {
  562. .name = "mcfuart",
  563. .owner = THIS_MODULE,
  564. },
  565. };
  566. /****************************************************************************/
  567. static int __init mcf_init(void)
  568. {
  569. int rc;
  570. printk("ColdFire internal UART serial driver\n");
  571. rc = uart_register_driver(&mcf_driver);
  572. if (rc)
  573. return rc;
  574. rc = platform_driver_register(&mcf_platform_driver);
  575. if (rc)
  576. return rc;
  577. return 0;
  578. }
  579. /****************************************************************************/
  580. static void __exit mcf_exit(void)
  581. {
  582. platform_driver_unregister(&mcf_platform_driver);
  583. uart_unregister_driver(&mcf_driver);
  584. }
  585. /****************************************************************************/
  586. module_init(mcf_init);
  587. module_exit(mcf_exit);
  588. MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
  589. MODULE_DESCRIPTION("Freescale ColdFire UART driver");
  590. MODULE_LICENSE("GPL");
  591. MODULE_ALIAS("platform:mcfuart");
  592. /****************************************************************************/