uartlite.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * uartlite.c: Serial driver for Xilinx uartlite serial controller
  4. *
  5. * Copyright (C) 2006 Peter Korsgaard <jacmet@sunsite.dk>
  6. * Copyright (C) 2007 Secret Lab Technologies Ltd.
  7. */
  8. #include <linux/platform_device.h>
  9. #include <linux/module.h>
  10. #include <linux/console.h>
  11. #include <linux/serial.h>
  12. #include <linux/serial_core.h>
  13. #include <linux/tty.h>
  14. #include <linux/tty_flip.h>
  15. #include <linux/delay.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/init.h>
  18. #include <linux/io.h>
  19. #include <linux/of.h>
  20. #include <linux/of_address.h>
  21. #include <linux/of_device.h>
  22. #include <linux/of_platform.h>
  23. #define ULITE_NAME "ttyUL"
  24. #define ULITE_MAJOR 204
  25. #define ULITE_MINOR 187
  26. #define ULITE_NR_UARTS CONFIG_SERIAL_UARTLITE_NR_UARTS
  27. /* ---------------------------------------------------------------------
  28. * Register definitions
  29. *
  30. * For register details see datasheet:
  31. * http://www.xilinx.com/support/documentation/ip_documentation/opb_uartlite.pdf
  32. */
  33. #define ULITE_RX 0x00
  34. #define ULITE_TX 0x04
  35. #define ULITE_STATUS 0x08
  36. #define ULITE_CONTROL 0x0c
  37. #define ULITE_REGION 16
  38. #define ULITE_STATUS_RXVALID 0x01
  39. #define ULITE_STATUS_RXFULL 0x02
  40. #define ULITE_STATUS_TXEMPTY 0x04
  41. #define ULITE_STATUS_TXFULL 0x08
  42. #define ULITE_STATUS_IE 0x10
  43. #define ULITE_STATUS_OVERRUN 0x20
  44. #define ULITE_STATUS_FRAME 0x40
  45. #define ULITE_STATUS_PARITY 0x80
  46. #define ULITE_CONTROL_RST_TX 0x01
  47. #define ULITE_CONTROL_RST_RX 0x02
  48. #define ULITE_CONTROL_IE 0x10
  49. struct uartlite_reg_ops {
  50. u32 (*in)(void __iomem *addr);
  51. void (*out)(u32 val, void __iomem *addr);
  52. };
  53. static u32 uartlite_inbe32(void __iomem *addr)
  54. {
  55. return ioread32be(addr);
  56. }
  57. static void uartlite_outbe32(u32 val, void __iomem *addr)
  58. {
  59. iowrite32be(val, addr);
  60. }
  61. static const struct uartlite_reg_ops uartlite_be = {
  62. .in = uartlite_inbe32,
  63. .out = uartlite_outbe32,
  64. };
  65. static u32 uartlite_inle32(void __iomem *addr)
  66. {
  67. return ioread32(addr);
  68. }
  69. static void uartlite_outle32(u32 val, void __iomem *addr)
  70. {
  71. iowrite32(val, addr);
  72. }
  73. static const struct uartlite_reg_ops uartlite_le = {
  74. .in = uartlite_inle32,
  75. .out = uartlite_outle32,
  76. };
  77. static inline u32 uart_in32(u32 offset, struct uart_port *port)
  78. {
  79. const struct uartlite_reg_ops *reg_ops = port->private_data;
  80. return reg_ops->in(port->membase + offset);
  81. }
  82. static inline void uart_out32(u32 val, u32 offset, struct uart_port *port)
  83. {
  84. const struct uartlite_reg_ops *reg_ops = port->private_data;
  85. reg_ops->out(val, port->membase + offset);
  86. }
  87. static struct uart_port ulite_ports[ULITE_NR_UARTS];
  88. /* ---------------------------------------------------------------------
  89. * Core UART driver operations
  90. */
  91. static int ulite_receive(struct uart_port *port, int stat)
  92. {
  93. struct tty_port *tport = &port->state->port;
  94. unsigned char ch = 0;
  95. char flag = TTY_NORMAL;
  96. if ((stat & (ULITE_STATUS_RXVALID | ULITE_STATUS_OVERRUN
  97. | ULITE_STATUS_FRAME)) == 0)
  98. return 0;
  99. /* stats */
  100. if (stat & ULITE_STATUS_RXVALID) {
  101. port->icount.rx++;
  102. ch = uart_in32(ULITE_RX, port);
  103. if (stat & ULITE_STATUS_PARITY)
  104. port->icount.parity++;
  105. }
  106. if (stat & ULITE_STATUS_OVERRUN)
  107. port->icount.overrun++;
  108. if (stat & ULITE_STATUS_FRAME)
  109. port->icount.frame++;
  110. /* drop byte with parity error if IGNPAR specificed */
  111. if (stat & port->ignore_status_mask & ULITE_STATUS_PARITY)
  112. stat &= ~ULITE_STATUS_RXVALID;
  113. stat &= port->read_status_mask;
  114. if (stat & ULITE_STATUS_PARITY)
  115. flag = TTY_PARITY;
  116. stat &= ~port->ignore_status_mask;
  117. if (stat & ULITE_STATUS_RXVALID)
  118. tty_insert_flip_char(tport, ch, flag);
  119. if (stat & ULITE_STATUS_FRAME)
  120. tty_insert_flip_char(tport, 0, TTY_FRAME);
  121. if (stat & ULITE_STATUS_OVERRUN)
  122. tty_insert_flip_char(tport, 0, TTY_OVERRUN);
  123. return 1;
  124. }
  125. static int ulite_transmit(struct uart_port *port, int stat)
  126. {
  127. struct circ_buf *xmit = &port->state->xmit;
  128. if (stat & ULITE_STATUS_TXFULL)
  129. return 0;
  130. if (port->x_char) {
  131. uart_out32(port->x_char, ULITE_TX, port);
  132. port->x_char = 0;
  133. port->icount.tx++;
  134. return 1;
  135. }
  136. if (uart_circ_empty(xmit) || uart_tx_stopped(port))
  137. return 0;
  138. uart_out32(xmit->buf[xmit->tail], ULITE_TX, port);
  139. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE-1);
  140. port->icount.tx++;
  141. /* wake up */
  142. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  143. uart_write_wakeup(port);
  144. return 1;
  145. }
  146. static irqreturn_t ulite_isr(int irq, void *dev_id)
  147. {
  148. struct uart_port *port = dev_id;
  149. int stat, busy, n = 0;
  150. unsigned long flags;
  151. do {
  152. spin_lock_irqsave(&port->lock, flags);
  153. stat = uart_in32(ULITE_STATUS, port);
  154. busy = ulite_receive(port, stat);
  155. busy |= ulite_transmit(port, stat);
  156. spin_unlock_irqrestore(&port->lock, flags);
  157. n++;
  158. } while (busy);
  159. /* work done? */
  160. if (n > 1) {
  161. tty_flip_buffer_push(&port->state->port);
  162. return IRQ_HANDLED;
  163. } else {
  164. return IRQ_NONE;
  165. }
  166. }
  167. static unsigned int ulite_tx_empty(struct uart_port *port)
  168. {
  169. unsigned long flags;
  170. unsigned int ret;
  171. spin_lock_irqsave(&port->lock, flags);
  172. ret = uart_in32(ULITE_STATUS, port);
  173. spin_unlock_irqrestore(&port->lock, flags);
  174. return ret & ULITE_STATUS_TXEMPTY ? TIOCSER_TEMT : 0;
  175. }
  176. static unsigned int ulite_get_mctrl(struct uart_port *port)
  177. {
  178. return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
  179. }
  180. static void ulite_set_mctrl(struct uart_port *port, unsigned int mctrl)
  181. {
  182. /* N/A */
  183. }
  184. static void ulite_stop_tx(struct uart_port *port)
  185. {
  186. /* N/A */
  187. }
  188. static void ulite_start_tx(struct uart_port *port)
  189. {
  190. ulite_transmit(port, uart_in32(ULITE_STATUS, port));
  191. }
  192. static void ulite_stop_rx(struct uart_port *port)
  193. {
  194. /* don't forward any more data (like !CREAD) */
  195. port->ignore_status_mask = ULITE_STATUS_RXVALID | ULITE_STATUS_PARITY
  196. | ULITE_STATUS_FRAME | ULITE_STATUS_OVERRUN;
  197. }
  198. static void ulite_break_ctl(struct uart_port *port, int ctl)
  199. {
  200. /* N/A */
  201. }
  202. static int ulite_startup(struct uart_port *port)
  203. {
  204. int ret;
  205. ret = request_irq(port->irq, ulite_isr, IRQF_SHARED | IRQF_TRIGGER_RISING,
  206. "uartlite", port);
  207. if (ret)
  208. return ret;
  209. uart_out32(ULITE_CONTROL_RST_RX | ULITE_CONTROL_RST_TX,
  210. ULITE_CONTROL, port);
  211. uart_out32(ULITE_CONTROL_IE, ULITE_CONTROL, port);
  212. return 0;
  213. }
  214. static void ulite_shutdown(struct uart_port *port)
  215. {
  216. uart_out32(0, ULITE_CONTROL, port);
  217. uart_in32(ULITE_CONTROL, port); /* dummy */
  218. free_irq(port->irq, port);
  219. }
  220. static void ulite_set_termios(struct uart_port *port, struct ktermios *termios,
  221. struct ktermios *old)
  222. {
  223. unsigned long flags;
  224. unsigned int baud;
  225. spin_lock_irqsave(&port->lock, flags);
  226. port->read_status_mask = ULITE_STATUS_RXVALID | ULITE_STATUS_OVERRUN
  227. | ULITE_STATUS_TXFULL;
  228. if (termios->c_iflag & INPCK)
  229. port->read_status_mask |=
  230. ULITE_STATUS_PARITY | ULITE_STATUS_FRAME;
  231. port->ignore_status_mask = 0;
  232. if (termios->c_iflag & IGNPAR)
  233. port->ignore_status_mask |= ULITE_STATUS_PARITY
  234. | ULITE_STATUS_FRAME | ULITE_STATUS_OVERRUN;
  235. /* ignore all characters if CREAD is not set */
  236. if ((termios->c_cflag & CREAD) == 0)
  237. port->ignore_status_mask |=
  238. ULITE_STATUS_RXVALID | ULITE_STATUS_PARITY
  239. | ULITE_STATUS_FRAME | ULITE_STATUS_OVERRUN;
  240. /* update timeout */
  241. baud = uart_get_baud_rate(port, termios, old, 0, 460800);
  242. uart_update_timeout(port, termios->c_cflag, baud);
  243. spin_unlock_irqrestore(&port->lock, flags);
  244. }
  245. static const char *ulite_type(struct uart_port *port)
  246. {
  247. return port->type == PORT_UARTLITE ? "uartlite" : NULL;
  248. }
  249. static void ulite_release_port(struct uart_port *port)
  250. {
  251. release_mem_region(port->mapbase, ULITE_REGION);
  252. iounmap(port->membase);
  253. port->membase = NULL;
  254. }
  255. static int ulite_request_port(struct uart_port *port)
  256. {
  257. int ret;
  258. pr_debug("ulite console: port=%p; port->mapbase=%llx\n",
  259. port, (unsigned long long) port->mapbase);
  260. if (!request_mem_region(port->mapbase, ULITE_REGION, "uartlite")) {
  261. dev_err(port->dev, "Memory region busy\n");
  262. return -EBUSY;
  263. }
  264. port->membase = ioremap(port->mapbase, ULITE_REGION);
  265. if (!port->membase) {
  266. dev_err(port->dev, "Unable to map registers\n");
  267. release_mem_region(port->mapbase, ULITE_REGION);
  268. return -EBUSY;
  269. }
  270. port->private_data = (void *)&uartlite_be;
  271. ret = uart_in32(ULITE_CONTROL, port);
  272. uart_out32(ULITE_CONTROL_RST_TX, ULITE_CONTROL, port);
  273. ret = uart_in32(ULITE_STATUS, port);
  274. /* Endianess detection */
  275. if ((ret & ULITE_STATUS_TXEMPTY) != ULITE_STATUS_TXEMPTY)
  276. port->private_data = (void *)&uartlite_le;
  277. return 0;
  278. }
  279. static void ulite_config_port(struct uart_port *port, int flags)
  280. {
  281. if (!ulite_request_port(port))
  282. port->type = PORT_UARTLITE;
  283. }
  284. static int ulite_verify_port(struct uart_port *port, struct serial_struct *ser)
  285. {
  286. /* we don't want the core code to modify any port params */
  287. return -EINVAL;
  288. }
  289. #ifdef CONFIG_CONSOLE_POLL
  290. static int ulite_get_poll_char(struct uart_port *port)
  291. {
  292. if (!(uart_in32(ULITE_STATUS, port) & ULITE_STATUS_RXVALID))
  293. return NO_POLL_CHAR;
  294. return uart_in32(ULITE_RX, port);
  295. }
  296. static void ulite_put_poll_char(struct uart_port *port, unsigned char ch)
  297. {
  298. while (uart_in32(ULITE_STATUS, port) & ULITE_STATUS_TXFULL)
  299. cpu_relax();
  300. /* write char to device */
  301. uart_out32(ch, ULITE_TX, port);
  302. }
  303. #endif
  304. static const struct uart_ops ulite_ops = {
  305. .tx_empty = ulite_tx_empty,
  306. .set_mctrl = ulite_set_mctrl,
  307. .get_mctrl = ulite_get_mctrl,
  308. .stop_tx = ulite_stop_tx,
  309. .start_tx = ulite_start_tx,
  310. .stop_rx = ulite_stop_rx,
  311. .break_ctl = ulite_break_ctl,
  312. .startup = ulite_startup,
  313. .shutdown = ulite_shutdown,
  314. .set_termios = ulite_set_termios,
  315. .type = ulite_type,
  316. .release_port = ulite_release_port,
  317. .request_port = ulite_request_port,
  318. .config_port = ulite_config_port,
  319. .verify_port = ulite_verify_port,
  320. #ifdef CONFIG_CONSOLE_POLL
  321. .poll_get_char = ulite_get_poll_char,
  322. .poll_put_char = ulite_put_poll_char,
  323. #endif
  324. };
  325. /* ---------------------------------------------------------------------
  326. * Console driver operations
  327. */
  328. #ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
  329. static void ulite_console_wait_tx(struct uart_port *port)
  330. {
  331. u8 val;
  332. unsigned long timeout;
  333. /*
  334. * Spin waiting for TX fifo to have space available.
  335. * When using the Microblaze Debug Module this can take up to 1s
  336. */
  337. timeout = jiffies + msecs_to_jiffies(1000);
  338. while (1) {
  339. val = uart_in32(ULITE_STATUS, port);
  340. if ((val & ULITE_STATUS_TXFULL) == 0)
  341. break;
  342. if (time_after(jiffies, timeout)) {
  343. dev_warn(port->dev,
  344. "timeout waiting for TX buffer empty\n");
  345. break;
  346. }
  347. cpu_relax();
  348. }
  349. }
  350. static void ulite_console_putchar(struct uart_port *port, int ch)
  351. {
  352. ulite_console_wait_tx(port);
  353. uart_out32(ch, ULITE_TX, port);
  354. }
  355. static void ulite_console_write(struct console *co, const char *s,
  356. unsigned int count)
  357. {
  358. struct uart_port *port = &ulite_ports[co->index];
  359. unsigned long flags;
  360. unsigned int ier;
  361. int locked = 1;
  362. if (oops_in_progress) {
  363. locked = spin_trylock_irqsave(&port->lock, flags);
  364. } else
  365. spin_lock_irqsave(&port->lock, flags);
  366. /* save and disable interrupt */
  367. ier = uart_in32(ULITE_STATUS, port) & ULITE_STATUS_IE;
  368. uart_out32(0, ULITE_CONTROL, port);
  369. uart_console_write(port, s, count, ulite_console_putchar);
  370. ulite_console_wait_tx(port);
  371. /* restore interrupt state */
  372. if (ier)
  373. uart_out32(ULITE_CONTROL_IE, ULITE_CONTROL, port);
  374. if (locked)
  375. spin_unlock_irqrestore(&port->lock, flags);
  376. }
  377. static int ulite_console_setup(struct console *co, char *options)
  378. {
  379. struct uart_port *port;
  380. int baud = 9600;
  381. int bits = 8;
  382. int parity = 'n';
  383. int flow = 'n';
  384. if (co->index < 0 || co->index >= ULITE_NR_UARTS)
  385. return -EINVAL;
  386. port = &ulite_ports[co->index];
  387. /* Has the device been initialized yet? */
  388. if (!port->mapbase) {
  389. pr_debug("console on ttyUL%i not present\n", co->index);
  390. return -ENODEV;
  391. }
  392. /* not initialized yet? */
  393. if (!port->membase) {
  394. if (ulite_request_port(port))
  395. return -ENODEV;
  396. }
  397. if (options)
  398. uart_parse_options(options, &baud, &parity, &bits, &flow);
  399. return uart_set_options(port, co, baud, parity, bits, flow);
  400. }
  401. static struct uart_driver ulite_uart_driver;
  402. static struct console ulite_console = {
  403. .name = ULITE_NAME,
  404. .write = ulite_console_write,
  405. .device = uart_console_device,
  406. .setup = ulite_console_setup,
  407. .flags = CON_PRINTBUFFER,
  408. .index = -1, /* Specified on the cmdline (e.g. console=ttyUL0 ) */
  409. .data = &ulite_uart_driver,
  410. };
  411. static int __init ulite_console_init(void)
  412. {
  413. register_console(&ulite_console);
  414. return 0;
  415. }
  416. console_initcall(ulite_console_init);
  417. static void early_uartlite_putc(struct uart_port *port, int c)
  418. {
  419. /*
  420. * Limit how many times we'll spin waiting for TX FIFO status.
  421. * This will prevent lockups if the base address is incorrectly
  422. * set, or any other issue on the UARTLITE.
  423. * This limit is pretty arbitrary, unless we are at about 10 baud
  424. * we'll never timeout on a working UART.
  425. */
  426. unsigned retries = 1000000;
  427. /* read status bit - 0x8 offset */
  428. while (--retries && (readl(port->membase + 8) & (1 << 3)))
  429. ;
  430. /* Only attempt the iowrite if we didn't timeout */
  431. /* write to TX_FIFO - 0x4 offset */
  432. if (retries)
  433. writel(c & 0xff, port->membase + 4);
  434. }
  435. static void early_uartlite_write(struct console *console,
  436. const char *s, unsigned n)
  437. {
  438. struct earlycon_device *device = console->data;
  439. uart_console_write(&device->port, s, n, early_uartlite_putc);
  440. }
  441. static int __init early_uartlite_setup(struct earlycon_device *device,
  442. const char *options)
  443. {
  444. if (!device->port.membase)
  445. return -ENODEV;
  446. device->con->write = early_uartlite_write;
  447. return 0;
  448. }
  449. EARLYCON_DECLARE(uartlite, early_uartlite_setup);
  450. OF_EARLYCON_DECLARE(uartlite_b, "xlnx,opb-uartlite-1.00.b", early_uartlite_setup);
  451. OF_EARLYCON_DECLARE(uartlite_a, "xlnx,xps-uartlite-1.00.a", early_uartlite_setup);
  452. #endif /* CONFIG_SERIAL_UARTLITE_CONSOLE */
  453. static struct uart_driver ulite_uart_driver = {
  454. .owner = THIS_MODULE,
  455. .driver_name = "uartlite",
  456. .dev_name = ULITE_NAME,
  457. .major = ULITE_MAJOR,
  458. .minor = ULITE_MINOR,
  459. .nr = ULITE_NR_UARTS,
  460. #ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
  461. .cons = &ulite_console,
  462. #endif
  463. };
  464. /* ---------------------------------------------------------------------
  465. * Port assignment functions (mapping devices to uart_port structures)
  466. */
  467. /** ulite_assign: register a uartlite device with the driver
  468. *
  469. * @dev: pointer to device structure
  470. * @id: requested id number. Pass -1 for automatic port assignment
  471. * @base: base address of uartlite registers
  472. * @irq: irq number for uartlite
  473. *
  474. * Returns: 0 on success, <0 otherwise
  475. */
  476. static int ulite_assign(struct device *dev, int id, u32 base, int irq)
  477. {
  478. struct uart_port *port;
  479. int rc;
  480. /* if id = -1; then scan for a free id and use that */
  481. if (id < 0) {
  482. for (id = 0; id < ULITE_NR_UARTS; id++)
  483. if (ulite_ports[id].mapbase == 0)
  484. break;
  485. }
  486. if (id < 0 || id >= ULITE_NR_UARTS) {
  487. dev_err(dev, "%s%i too large\n", ULITE_NAME, id);
  488. return -EINVAL;
  489. }
  490. if ((ulite_ports[id].mapbase) && (ulite_ports[id].mapbase != base)) {
  491. dev_err(dev, "cannot assign to %s%i; it is already in use\n",
  492. ULITE_NAME, id);
  493. return -EBUSY;
  494. }
  495. port = &ulite_ports[id];
  496. spin_lock_init(&port->lock);
  497. port->fifosize = 16;
  498. port->regshift = 2;
  499. port->iotype = UPIO_MEM;
  500. port->iobase = 1; /* mark port in use */
  501. port->mapbase = base;
  502. port->membase = NULL;
  503. port->ops = &ulite_ops;
  504. port->irq = irq;
  505. port->flags = UPF_BOOT_AUTOCONF;
  506. port->dev = dev;
  507. port->type = PORT_UNKNOWN;
  508. port->line = id;
  509. dev_set_drvdata(dev, port);
  510. /* Register the port */
  511. rc = uart_add_one_port(&ulite_uart_driver, port);
  512. if (rc) {
  513. dev_err(dev, "uart_add_one_port() failed; err=%i\n", rc);
  514. port->mapbase = 0;
  515. dev_set_drvdata(dev, NULL);
  516. return rc;
  517. }
  518. return 0;
  519. }
  520. /** ulite_release: register a uartlite device with the driver
  521. *
  522. * @dev: pointer to device structure
  523. */
  524. static int ulite_release(struct device *dev)
  525. {
  526. struct uart_port *port = dev_get_drvdata(dev);
  527. int rc = 0;
  528. if (port) {
  529. rc = uart_remove_one_port(&ulite_uart_driver, port);
  530. dev_set_drvdata(dev, NULL);
  531. port->mapbase = 0;
  532. }
  533. return rc;
  534. }
  535. /* ---------------------------------------------------------------------
  536. * Platform bus binding
  537. */
  538. #if defined(CONFIG_OF)
  539. /* Match table for of_platform binding */
  540. static const struct of_device_id ulite_of_match[] = {
  541. { .compatible = "xlnx,opb-uartlite-1.00.b", },
  542. { .compatible = "xlnx,xps-uartlite-1.00.a", },
  543. {}
  544. };
  545. MODULE_DEVICE_TABLE(of, ulite_of_match);
  546. #endif /* CONFIG_OF */
  547. static int ulite_probe(struct platform_device *pdev)
  548. {
  549. struct resource *res;
  550. int irq;
  551. int id = pdev->id;
  552. #ifdef CONFIG_OF
  553. const __be32 *prop;
  554. prop = of_get_property(pdev->dev.of_node, "port-number", NULL);
  555. if (prop)
  556. id = be32_to_cpup(prop);
  557. #endif
  558. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  559. if (!res)
  560. return -ENODEV;
  561. irq = platform_get_irq(pdev, 0);
  562. if (irq <= 0)
  563. return -ENXIO;
  564. return ulite_assign(&pdev->dev, id, res->start, irq);
  565. }
  566. static int ulite_remove(struct platform_device *pdev)
  567. {
  568. return ulite_release(&pdev->dev);
  569. }
  570. /* work with hotplug and coldplug */
  571. MODULE_ALIAS("platform:uartlite");
  572. static struct platform_driver ulite_platform_driver = {
  573. .probe = ulite_probe,
  574. .remove = ulite_remove,
  575. .driver = {
  576. .name = "uartlite",
  577. .of_match_table = of_match_ptr(ulite_of_match),
  578. },
  579. };
  580. /* ---------------------------------------------------------------------
  581. * Module setup/teardown
  582. */
  583. static int __init ulite_init(void)
  584. {
  585. int ret;
  586. pr_debug("uartlite: calling uart_register_driver()\n");
  587. ret = uart_register_driver(&ulite_uart_driver);
  588. if (ret)
  589. goto err_uart;
  590. pr_debug("uartlite: calling platform_driver_register()\n");
  591. ret = platform_driver_register(&ulite_platform_driver);
  592. if (ret)
  593. goto err_plat;
  594. return 0;
  595. err_plat:
  596. uart_unregister_driver(&ulite_uart_driver);
  597. err_uart:
  598. pr_err("registering uartlite driver failed: err=%i\n", ret);
  599. return ret;
  600. }
  601. static void __exit ulite_exit(void)
  602. {
  603. platform_driver_unregister(&ulite_platform_driver);
  604. uart_unregister_driver(&ulite_uart_driver);
  605. }
  606. module_init(ulite_init);
  607. module_exit(ulite_exit);
  608. MODULE_AUTHOR("Peter Korsgaard <jacmet@sunsite.dk>");
  609. MODULE_DESCRIPTION("Xilinx uartlite serial driver");
  610. MODULE_LICENSE("GPL");