mcf.c 19 KB

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