vt8500_serial.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. /*
  2. * Copyright (C) 2010 Alexey Charkov <alchark@gmail.com>
  3. *
  4. * Based on msm_serial.c, which is:
  5. * Copyright (C) 2007 Google, Inc.
  6. * Author: Robert Love <rlove@google.com>
  7. *
  8. * This software is licensed under the terms of the GNU General Public
  9. * License version 2, as published by the Free Software Foundation, and
  10. * may be copied, distributed, and modified under those terms.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #if defined(CONFIG_SERIAL_VT8500_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  18. # define SUPPORT_SYSRQ
  19. #endif
  20. #include <linux/hrtimer.h>
  21. #include <linux/delay.h>
  22. #include <linux/module.h>
  23. #include <linux/io.h>
  24. #include <linux/ioport.h>
  25. #include <linux/irq.h>
  26. #include <linux/init.h>
  27. #include <linux/console.h>
  28. #include <linux/tty.h>
  29. #include <linux/tty_flip.h>
  30. #include <linux/serial_core.h>
  31. #include <linux/serial.h>
  32. #include <linux/slab.h>
  33. #include <linux/clk.h>
  34. #include <linux/platform_device.h>
  35. #include <linux/of.h>
  36. /*
  37. * UART Register offsets
  38. */
  39. #define VT8500_URTDR 0x0000 /* Transmit data */
  40. #define VT8500_URRDR 0x0004 /* Receive data */
  41. #define VT8500_URDIV 0x0008 /* Clock/Baud rate divisor */
  42. #define VT8500_URLCR 0x000C /* Line control */
  43. #define VT8500_URICR 0x0010 /* IrDA control */
  44. #define VT8500_URIER 0x0014 /* Interrupt enable */
  45. #define VT8500_URISR 0x0018 /* Interrupt status */
  46. #define VT8500_URUSR 0x001c /* UART status */
  47. #define VT8500_URFCR 0x0020 /* FIFO control */
  48. #define VT8500_URFIDX 0x0024 /* FIFO index */
  49. #define VT8500_URBKR 0x0028 /* Break signal count */
  50. #define VT8500_URTOD 0x002c /* Time out divisor */
  51. #define VT8500_TXFIFO 0x1000 /* Transmit FIFO (16x8) */
  52. #define VT8500_RXFIFO 0x1020 /* Receive FIFO (16x10) */
  53. /*
  54. * Interrupt enable and status bits
  55. */
  56. #define TXDE (1 << 0) /* Tx Data empty */
  57. #define RXDF (1 << 1) /* Rx Data full */
  58. #define TXFAE (1 << 2) /* Tx FIFO almost empty */
  59. #define TXFE (1 << 3) /* Tx FIFO empty */
  60. #define RXFAF (1 << 4) /* Rx FIFO almost full */
  61. #define RXFF (1 << 5) /* Rx FIFO full */
  62. #define TXUDR (1 << 6) /* Tx underrun */
  63. #define RXOVER (1 << 7) /* Rx overrun */
  64. #define PER (1 << 8) /* Parity error */
  65. #define FER (1 << 9) /* Frame error */
  66. #define TCTS (1 << 10) /* Toggle of CTS */
  67. #define RXTOUT (1 << 11) /* Rx timeout */
  68. #define BKDONE (1 << 12) /* Break signal done */
  69. #define ERR (1 << 13) /* AHB error response */
  70. #define RX_FIFO_INTS (RXFAF | RXFF | RXOVER | PER | FER | RXTOUT)
  71. #define TX_FIFO_INTS (TXFAE | TXFE | TXUDR)
  72. #define VT8500_MAX_PORTS 6
  73. struct vt8500_port {
  74. struct uart_port uart;
  75. char name[16];
  76. struct clk *clk;
  77. unsigned int ier;
  78. };
  79. /*
  80. * we use this variable to keep track of which ports
  81. * have been allocated as we can't use pdev->id in
  82. * devicetree
  83. */
  84. static unsigned long vt8500_ports_in_use;
  85. static inline void vt8500_write(struct uart_port *port, unsigned int val,
  86. unsigned int off)
  87. {
  88. writel(val, port->membase + off);
  89. }
  90. static inline unsigned int vt8500_read(struct uart_port *port, unsigned int off)
  91. {
  92. return readl(port->membase + off);
  93. }
  94. static void vt8500_stop_tx(struct uart_port *port)
  95. {
  96. struct vt8500_port *vt8500_port = container_of(port,
  97. struct vt8500_port,
  98. uart);
  99. vt8500_port->ier &= ~TX_FIFO_INTS;
  100. vt8500_write(port, vt8500_port->ier, VT8500_URIER);
  101. }
  102. static void vt8500_stop_rx(struct uart_port *port)
  103. {
  104. struct vt8500_port *vt8500_port = container_of(port,
  105. struct vt8500_port,
  106. uart);
  107. vt8500_port->ier &= ~RX_FIFO_INTS;
  108. vt8500_write(port, vt8500_port->ier, VT8500_URIER);
  109. }
  110. static void vt8500_enable_ms(struct uart_port *port)
  111. {
  112. struct vt8500_port *vt8500_port = container_of(port,
  113. struct vt8500_port,
  114. uart);
  115. vt8500_port->ier |= TCTS;
  116. vt8500_write(port, vt8500_port->ier, VT8500_URIER);
  117. }
  118. static void handle_rx(struct uart_port *port)
  119. {
  120. struct tty_struct *tty = tty_port_tty_get(&port->state->port);
  121. if (!tty) {
  122. /* Discard data: no tty available */
  123. int count = (vt8500_read(port, VT8500_URFIDX) & 0x1f00) >> 8;
  124. u16 ch;
  125. while (count--)
  126. ch = readw(port->membase + VT8500_RXFIFO);
  127. return;
  128. }
  129. /*
  130. * Handle overrun
  131. */
  132. if ((vt8500_read(port, VT8500_URISR) & RXOVER)) {
  133. port->icount.overrun++;
  134. tty_insert_flip_char(tty, 0, TTY_OVERRUN);
  135. }
  136. /* and now the main RX loop */
  137. while (vt8500_read(port, VT8500_URFIDX) & 0x1f00) {
  138. unsigned int c;
  139. char flag = TTY_NORMAL;
  140. c = readw(port->membase + VT8500_RXFIFO) & 0x3ff;
  141. /* Mask conditions we're ignorning. */
  142. c &= ~port->read_status_mask;
  143. if (c & FER) {
  144. port->icount.frame++;
  145. flag = TTY_FRAME;
  146. } else if (c & PER) {
  147. port->icount.parity++;
  148. flag = TTY_PARITY;
  149. }
  150. port->icount.rx++;
  151. if (!uart_handle_sysrq_char(port, c))
  152. tty_insert_flip_char(tty, c, flag);
  153. }
  154. tty_flip_buffer_push(tty);
  155. tty_kref_put(tty);
  156. }
  157. static void handle_tx(struct uart_port *port)
  158. {
  159. struct circ_buf *xmit = &port->state->xmit;
  160. if (port->x_char) {
  161. writeb(port->x_char, port->membase + VT8500_TXFIFO);
  162. port->icount.tx++;
  163. port->x_char = 0;
  164. }
  165. if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
  166. vt8500_stop_tx(port);
  167. return;
  168. }
  169. while ((vt8500_read(port, VT8500_URFIDX) & 0x1f) < 16) {
  170. if (uart_circ_empty(xmit))
  171. break;
  172. writeb(xmit->buf[xmit->tail], port->membase + VT8500_TXFIFO);
  173. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  174. port->icount.tx++;
  175. }
  176. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  177. uart_write_wakeup(port);
  178. if (uart_circ_empty(xmit))
  179. vt8500_stop_tx(port);
  180. }
  181. static void vt8500_start_tx(struct uart_port *port)
  182. {
  183. struct vt8500_port *vt8500_port = container_of(port,
  184. struct vt8500_port,
  185. uart);
  186. vt8500_port->ier &= ~TX_FIFO_INTS;
  187. vt8500_write(port, vt8500_port->ier, VT8500_URIER);
  188. handle_tx(port);
  189. vt8500_port->ier |= TX_FIFO_INTS;
  190. vt8500_write(port, vt8500_port->ier, VT8500_URIER);
  191. }
  192. static void handle_delta_cts(struct uart_port *port)
  193. {
  194. port->icount.cts++;
  195. wake_up_interruptible(&port->state->port.delta_msr_wait);
  196. }
  197. static irqreturn_t vt8500_irq(int irq, void *dev_id)
  198. {
  199. struct uart_port *port = dev_id;
  200. unsigned long isr;
  201. spin_lock(&port->lock);
  202. isr = vt8500_read(port, VT8500_URISR);
  203. /* Acknowledge active status bits */
  204. vt8500_write(port, isr, VT8500_URISR);
  205. if (isr & RX_FIFO_INTS)
  206. handle_rx(port);
  207. if (isr & TX_FIFO_INTS)
  208. handle_tx(port);
  209. if (isr & TCTS)
  210. handle_delta_cts(port);
  211. spin_unlock(&port->lock);
  212. return IRQ_HANDLED;
  213. }
  214. static unsigned int vt8500_tx_empty(struct uart_port *port)
  215. {
  216. return (vt8500_read(port, VT8500_URFIDX) & 0x1f) < 16 ?
  217. TIOCSER_TEMT : 0;
  218. }
  219. static unsigned int vt8500_get_mctrl(struct uart_port *port)
  220. {
  221. unsigned int usr;
  222. usr = vt8500_read(port, VT8500_URUSR);
  223. if (usr & (1 << 4))
  224. return TIOCM_CTS;
  225. else
  226. return 0;
  227. }
  228. static void vt8500_set_mctrl(struct uart_port *port, unsigned int mctrl)
  229. {
  230. }
  231. static void vt8500_break_ctl(struct uart_port *port, int break_ctl)
  232. {
  233. if (break_ctl)
  234. vt8500_write(port, vt8500_read(port, VT8500_URLCR) | (1 << 9),
  235. VT8500_URLCR);
  236. }
  237. static int vt8500_set_baud_rate(struct uart_port *port, unsigned int baud)
  238. {
  239. unsigned long div;
  240. unsigned int loops = 1000;
  241. div = vt8500_read(port, VT8500_URDIV) & ~(0x3ff);
  242. if (unlikely((baud < 900) || (baud > 921600)))
  243. div |= 7;
  244. else
  245. div |= (921600 / baud) - 1;
  246. while ((vt8500_read(port, VT8500_URUSR) & (1 << 5)) && --loops)
  247. cpu_relax();
  248. vt8500_write(port, div, VT8500_URDIV);
  249. return baud;
  250. }
  251. static int vt8500_startup(struct uart_port *port)
  252. {
  253. struct vt8500_port *vt8500_port =
  254. container_of(port, struct vt8500_port, uart);
  255. int ret;
  256. snprintf(vt8500_port->name, sizeof(vt8500_port->name),
  257. "vt8500_serial%d", port->line);
  258. ret = request_irq(port->irq, vt8500_irq, IRQF_TRIGGER_HIGH,
  259. vt8500_port->name, port);
  260. if (unlikely(ret))
  261. return ret;
  262. vt8500_write(port, 0x03, VT8500_URLCR); /* enable TX & RX */
  263. return 0;
  264. }
  265. static void vt8500_shutdown(struct uart_port *port)
  266. {
  267. struct vt8500_port *vt8500_port =
  268. container_of(port, struct vt8500_port, uart);
  269. vt8500_port->ier = 0;
  270. /* disable interrupts and FIFOs */
  271. vt8500_write(&vt8500_port->uart, 0, VT8500_URIER);
  272. vt8500_write(&vt8500_port->uart, 0x880, VT8500_URFCR);
  273. free_irq(port->irq, port);
  274. }
  275. static void vt8500_set_termios(struct uart_port *port,
  276. struct ktermios *termios,
  277. struct ktermios *old)
  278. {
  279. struct vt8500_port *vt8500_port =
  280. container_of(port, struct vt8500_port, uart);
  281. unsigned long flags;
  282. unsigned int baud, lcr;
  283. unsigned int loops = 1000;
  284. spin_lock_irqsave(&port->lock, flags);
  285. /* calculate and set baud rate */
  286. baud = uart_get_baud_rate(port, termios, old, 900, 921600);
  287. baud = vt8500_set_baud_rate(port, baud);
  288. if (tty_termios_baud_rate(termios))
  289. tty_termios_encode_baud_rate(termios, baud, baud);
  290. /* calculate parity */
  291. lcr = vt8500_read(&vt8500_port->uart, VT8500_URLCR);
  292. lcr &= ~((1 << 5) | (1 << 4));
  293. if (termios->c_cflag & PARENB) {
  294. lcr |= (1 << 4);
  295. termios->c_cflag &= ~CMSPAR;
  296. if (termios->c_cflag & PARODD)
  297. lcr |= (1 << 5);
  298. }
  299. /* calculate bits per char */
  300. lcr &= ~(1 << 2);
  301. switch (termios->c_cflag & CSIZE) {
  302. case CS7:
  303. break;
  304. case CS8:
  305. default:
  306. lcr |= (1 << 2);
  307. termios->c_cflag &= ~CSIZE;
  308. termios->c_cflag |= CS8;
  309. break;
  310. }
  311. /* calculate stop bits */
  312. lcr &= ~(1 << 3);
  313. if (termios->c_cflag & CSTOPB)
  314. lcr |= (1 << 3);
  315. /* set parity, bits per char, and stop bit */
  316. vt8500_write(&vt8500_port->uart, lcr, VT8500_URLCR);
  317. /* Configure status bits to ignore based on termio flags. */
  318. port->read_status_mask = 0;
  319. if (termios->c_iflag & IGNPAR)
  320. port->read_status_mask = FER | PER;
  321. uart_update_timeout(port, termios->c_cflag, baud);
  322. /* Reset FIFOs */
  323. vt8500_write(&vt8500_port->uart, 0x88c, VT8500_URFCR);
  324. while ((vt8500_read(&vt8500_port->uart, VT8500_URFCR) & 0xc)
  325. && --loops)
  326. cpu_relax();
  327. /* Every possible FIFO-related interrupt */
  328. vt8500_port->ier = RX_FIFO_INTS | TX_FIFO_INTS;
  329. /*
  330. * CTS flow control
  331. */
  332. if (UART_ENABLE_MS(&vt8500_port->uart, termios->c_cflag))
  333. vt8500_port->ier |= TCTS;
  334. vt8500_write(&vt8500_port->uart, 0x881, VT8500_URFCR);
  335. vt8500_write(&vt8500_port->uart, vt8500_port->ier, VT8500_URIER);
  336. spin_unlock_irqrestore(&port->lock, flags);
  337. }
  338. static const char *vt8500_type(struct uart_port *port)
  339. {
  340. struct vt8500_port *vt8500_port =
  341. container_of(port, struct vt8500_port, uart);
  342. return vt8500_port->name;
  343. }
  344. static void vt8500_release_port(struct uart_port *port)
  345. {
  346. }
  347. static int vt8500_request_port(struct uart_port *port)
  348. {
  349. return 0;
  350. }
  351. static void vt8500_config_port(struct uart_port *port, int flags)
  352. {
  353. port->type = PORT_VT8500;
  354. }
  355. static int vt8500_verify_port(struct uart_port *port,
  356. struct serial_struct *ser)
  357. {
  358. if (unlikely(ser->type != PORT_UNKNOWN && ser->type != PORT_VT8500))
  359. return -EINVAL;
  360. if (unlikely(port->irq != ser->irq))
  361. return -EINVAL;
  362. return 0;
  363. }
  364. static struct vt8500_port *vt8500_uart_ports[VT8500_MAX_PORTS];
  365. static struct uart_driver vt8500_uart_driver;
  366. #ifdef CONFIG_SERIAL_VT8500_CONSOLE
  367. static inline void wait_for_xmitr(struct uart_port *port)
  368. {
  369. unsigned int status, tmout = 10000;
  370. /* Wait up to 10ms for the character(s) to be sent. */
  371. do {
  372. status = vt8500_read(port, VT8500_URFIDX);
  373. if (--tmout == 0)
  374. break;
  375. udelay(1);
  376. } while (status & 0x10);
  377. }
  378. static void vt8500_console_putchar(struct uart_port *port, int c)
  379. {
  380. wait_for_xmitr(port);
  381. writeb(c, port->membase + VT8500_TXFIFO);
  382. }
  383. static void vt8500_console_write(struct console *co, const char *s,
  384. unsigned int count)
  385. {
  386. struct vt8500_port *vt8500_port = vt8500_uart_ports[co->index];
  387. unsigned long ier;
  388. BUG_ON(co->index < 0 || co->index >= vt8500_uart_driver.nr);
  389. ier = vt8500_read(&vt8500_port->uart, VT8500_URIER);
  390. vt8500_write(&vt8500_port->uart, VT8500_URIER, 0);
  391. uart_console_write(&vt8500_port->uart, s, count,
  392. vt8500_console_putchar);
  393. /*
  394. * Finally, wait for transmitter to become empty
  395. * and switch back to FIFO
  396. */
  397. wait_for_xmitr(&vt8500_port->uart);
  398. vt8500_write(&vt8500_port->uart, VT8500_URIER, ier);
  399. }
  400. static int __init vt8500_console_setup(struct console *co, char *options)
  401. {
  402. struct vt8500_port *vt8500_port;
  403. int baud = 9600;
  404. int bits = 8;
  405. int parity = 'n';
  406. int flow = 'n';
  407. if (unlikely(co->index >= vt8500_uart_driver.nr || co->index < 0))
  408. return -ENXIO;
  409. vt8500_port = vt8500_uart_ports[co->index];
  410. if (!vt8500_port)
  411. return -ENODEV;
  412. if (options)
  413. uart_parse_options(options, &baud, &parity, &bits, &flow);
  414. return uart_set_options(&vt8500_port->uart,
  415. co, baud, parity, bits, flow);
  416. }
  417. static struct console vt8500_console = {
  418. .name = "ttyWMT",
  419. .write = vt8500_console_write,
  420. .device = uart_console_device,
  421. .setup = vt8500_console_setup,
  422. .flags = CON_PRINTBUFFER,
  423. .index = -1,
  424. .data = &vt8500_uart_driver,
  425. };
  426. #define VT8500_CONSOLE (&vt8500_console)
  427. #else
  428. #define VT8500_CONSOLE NULL
  429. #endif
  430. static struct uart_ops vt8500_uart_pops = {
  431. .tx_empty = vt8500_tx_empty,
  432. .set_mctrl = vt8500_set_mctrl,
  433. .get_mctrl = vt8500_get_mctrl,
  434. .stop_tx = vt8500_stop_tx,
  435. .start_tx = vt8500_start_tx,
  436. .stop_rx = vt8500_stop_rx,
  437. .enable_ms = vt8500_enable_ms,
  438. .break_ctl = vt8500_break_ctl,
  439. .startup = vt8500_startup,
  440. .shutdown = vt8500_shutdown,
  441. .set_termios = vt8500_set_termios,
  442. .type = vt8500_type,
  443. .release_port = vt8500_release_port,
  444. .request_port = vt8500_request_port,
  445. .config_port = vt8500_config_port,
  446. .verify_port = vt8500_verify_port,
  447. };
  448. static struct uart_driver vt8500_uart_driver = {
  449. .owner = THIS_MODULE,
  450. .driver_name = "vt8500_serial",
  451. .dev_name = "ttyWMT",
  452. .nr = 6,
  453. .cons = VT8500_CONSOLE,
  454. };
  455. static int vt8500_serial_probe(struct platform_device *pdev)
  456. {
  457. struct vt8500_port *vt8500_port;
  458. struct resource *mmres, *irqres;
  459. struct device_node *np = pdev->dev.of_node;
  460. int ret;
  461. int port;
  462. mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  463. irqres = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  464. if (!mmres || !irqres)
  465. return -ENODEV;
  466. if (np)
  467. port = of_alias_get_id(np, "serial");
  468. if (port > VT8500_MAX_PORTS)
  469. port = -1;
  470. else
  471. port = -1;
  472. if (port < 0) {
  473. /* calculate the port id */
  474. port = find_first_zero_bit(&vt8500_ports_in_use,
  475. sizeof(vt8500_ports_in_use));
  476. }
  477. if (port > VT8500_MAX_PORTS)
  478. return -ENODEV;
  479. /* reserve the port id */
  480. if (test_and_set_bit(port, &vt8500_ports_in_use)) {
  481. /* port already in use - shouldn't really happen */
  482. return -EBUSY;
  483. }
  484. vt8500_port = kzalloc(sizeof(struct vt8500_port), GFP_KERNEL);
  485. if (!vt8500_port)
  486. return -ENOMEM;
  487. vt8500_port->uart.type = PORT_VT8500;
  488. vt8500_port->uart.iotype = UPIO_MEM;
  489. vt8500_port->uart.mapbase = mmres->start;
  490. vt8500_port->uart.irq = irqres->start;
  491. vt8500_port->uart.fifosize = 16;
  492. vt8500_port->uart.ops = &vt8500_uart_pops;
  493. vt8500_port->uart.line = port;
  494. vt8500_port->uart.dev = &pdev->dev;
  495. vt8500_port->uart.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF;
  496. vt8500_port->clk = of_clk_get(pdev->dev.of_node, 0);
  497. if (vt8500_port->clk) {
  498. vt8500_port->uart.uartclk = clk_get_rate(vt8500_port->clk);
  499. } else {
  500. /* use the default of 24Mhz if not specified and warn */
  501. pr_warn("%s: serial clock source not specified\n", __func__);
  502. vt8500_port->uart.uartclk = 24000000;
  503. }
  504. snprintf(vt8500_port->name, sizeof(vt8500_port->name),
  505. "VT8500 UART%d", pdev->id);
  506. vt8500_port->uart.membase = ioremap(mmres->start, resource_size(mmres));
  507. if (!vt8500_port->uart.membase) {
  508. ret = -ENOMEM;
  509. goto err;
  510. }
  511. vt8500_uart_ports[port] = vt8500_port;
  512. uart_add_one_port(&vt8500_uart_driver, &vt8500_port->uart);
  513. platform_set_drvdata(pdev, vt8500_port);
  514. return 0;
  515. err:
  516. kfree(vt8500_port);
  517. return ret;
  518. }
  519. static int vt8500_serial_remove(struct platform_device *pdev)
  520. {
  521. struct vt8500_port *vt8500_port = platform_get_drvdata(pdev);
  522. platform_set_drvdata(pdev, NULL);
  523. uart_remove_one_port(&vt8500_uart_driver, &vt8500_port->uart);
  524. kfree(vt8500_port);
  525. return 0;
  526. }
  527. static const struct of_device_id wmt_dt_ids[] = {
  528. { .compatible = "via,vt8500-uart", },
  529. {}
  530. };
  531. static struct platform_driver vt8500_platform_driver = {
  532. .probe = vt8500_serial_probe,
  533. .remove = vt8500_serial_remove,
  534. .driver = {
  535. .name = "vt8500_serial",
  536. .owner = THIS_MODULE,
  537. .of_match_table = of_match_ptr(wmt_dt_ids),
  538. },
  539. };
  540. static int __init vt8500_serial_init(void)
  541. {
  542. int ret;
  543. ret = uart_register_driver(&vt8500_uart_driver);
  544. if (unlikely(ret))
  545. return ret;
  546. ret = platform_driver_register(&vt8500_platform_driver);
  547. if (unlikely(ret))
  548. uart_unregister_driver(&vt8500_uart_driver);
  549. return ret;
  550. }
  551. static void __exit vt8500_serial_exit(void)
  552. {
  553. #ifdef CONFIG_SERIAL_VT8500_CONSOLE
  554. unregister_console(&vt8500_console);
  555. #endif
  556. platform_driver_unregister(&vt8500_platform_driver);
  557. uart_unregister_driver(&vt8500_uart_driver);
  558. }
  559. module_init(vt8500_serial_init);
  560. module_exit(vt8500_serial_exit);
  561. MODULE_AUTHOR("Alexey Charkov <alchark@gmail.com>");
  562. MODULE_DESCRIPTION("Driver for vt8500 serial device");
  563. MODULE_LICENSE("GPL v2");