netx-serial.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. /*
  2. * Copyright (c) 2005 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #if defined(CONFIG_SERIAL_NETX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  18. #define SUPPORT_SYSRQ
  19. #endif
  20. #include <linux/device.h>
  21. #include <linux/module.h>
  22. #include <linux/ioport.h>
  23. #include <linux/init.h>
  24. #include <linux/console.h>
  25. #include <linux/sysrq.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/tty.h>
  28. #include <linux/tty_flip.h>
  29. #include <linux/serial_core.h>
  30. #include <linux/serial.h>
  31. #include <asm/io.h>
  32. #include <asm/irq.h>
  33. #include <mach/hardware.h>
  34. #include <mach/netx-regs.h>
  35. /* We've been assigned a range on the "Low-density serial ports" major */
  36. #define SERIAL_NX_MAJOR 204
  37. #define MINOR_START 170
  38. enum uart_regs {
  39. UART_DR = 0x00,
  40. UART_SR = 0x04,
  41. UART_LINE_CR = 0x08,
  42. UART_BAUDDIV_MSB = 0x0c,
  43. UART_BAUDDIV_LSB = 0x10,
  44. UART_CR = 0x14,
  45. UART_FR = 0x18,
  46. UART_IIR = 0x1c,
  47. UART_ILPR = 0x20,
  48. UART_RTS_CR = 0x24,
  49. UART_RTS_LEAD = 0x28,
  50. UART_RTS_TRAIL = 0x2c,
  51. UART_DRV_ENABLE = 0x30,
  52. UART_BRM_CR = 0x34,
  53. UART_RXFIFO_IRQLEVEL = 0x38,
  54. UART_TXFIFO_IRQLEVEL = 0x3c,
  55. };
  56. #define SR_FE (1<<0)
  57. #define SR_PE (1<<1)
  58. #define SR_BE (1<<2)
  59. #define SR_OE (1<<3)
  60. #define LINE_CR_BRK (1<<0)
  61. #define LINE_CR_PEN (1<<1)
  62. #define LINE_CR_EPS (1<<2)
  63. #define LINE_CR_STP2 (1<<3)
  64. #define LINE_CR_FEN (1<<4)
  65. #define LINE_CR_5BIT (0<<5)
  66. #define LINE_CR_6BIT (1<<5)
  67. #define LINE_CR_7BIT (2<<5)
  68. #define LINE_CR_8BIT (3<<5)
  69. #define LINE_CR_BITS_MASK (3<<5)
  70. #define CR_UART_EN (1<<0)
  71. #define CR_SIREN (1<<1)
  72. #define CR_SIRLP (1<<2)
  73. #define CR_MSIE (1<<3)
  74. #define CR_RIE (1<<4)
  75. #define CR_TIE (1<<5)
  76. #define CR_RTIE (1<<6)
  77. #define CR_LBE (1<<7)
  78. #define FR_CTS (1<<0)
  79. #define FR_DSR (1<<1)
  80. #define FR_DCD (1<<2)
  81. #define FR_BUSY (1<<3)
  82. #define FR_RXFE (1<<4)
  83. #define FR_TXFF (1<<5)
  84. #define FR_RXFF (1<<6)
  85. #define FR_TXFE (1<<7)
  86. #define IIR_MIS (1<<0)
  87. #define IIR_RIS (1<<1)
  88. #define IIR_TIS (1<<2)
  89. #define IIR_RTIS (1<<3)
  90. #define IIR_MASK 0xf
  91. #define RTS_CR_AUTO (1<<0)
  92. #define RTS_CR_RTS (1<<1)
  93. #define RTS_CR_COUNT (1<<2)
  94. #define RTS_CR_MOD2 (1<<3)
  95. #define RTS_CR_RTS_POL (1<<4)
  96. #define RTS_CR_CTS_CTR (1<<5)
  97. #define RTS_CR_CTS_POL (1<<6)
  98. #define RTS_CR_STICK (1<<7)
  99. #define UART_PORT_SIZE 0x40
  100. #define DRIVER_NAME "netx-uart"
  101. struct netx_port {
  102. struct uart_port port;
  103. };
  104. static void netx_stop_tx(struct uart_port *port)
  105. {
  106. unsigned int val;
  107. val = readl(port->membase + UART_CR);
  108. writel(val & ~CR_TIE, port->membase + UART_CR);
  109. }
  110. static void netx_stop_rx(struct uart_port *port)
  111. {
  112. unsigned int val;
  113. val = readl(port->membase + UART_CR);
  114. writel(val & ~CR_RIE, port->membase + UART_CR);
  115. }
  116. static void netx_enable_ms(struct uart_port *port)
  117. {
  118. unsigned int val;
  119. val = readl(port->membase + UART_CR);
  120. writel(val | CR_MSIE, port->membase + UART_CR);
  121. }
  122. static inline void netx_transmit_buffer(struct uart_port *port)
  123. {
  124. struct circ_buf *xmit = &port->state->xmit;
  125. if (port->x_char) {
  126. writel(port->x_char, port->membase + UART_DR);
  127. port->icount.tx++;
  128. port->x_char = 0;
  129. return;
  130. }
  131. if (uart_tx_stopped(port) || uart_circ_empty(xmit)) {
  132. netx_stop_tx(port);
  133. return;
  134. }
  135. do {
  136. /* send xmit->buf[xmit->tail]
  137. * out the port here */
  138. writel(xmit->buf[xmit->tail], port->membase + UART_DR);
  139. xmit->tail = (xmit->tail + 1) &
  140. (UART_XMIT_SIZE - 1);
  141. port->icount.tx++;
  142. if (uart_circ_empty(xmit))
  143. break;
  144. } while (!(readl(port->membase + UART_FR) & FR_TXFF));
  145. if (uart_circ_empty(xmit))
  146. netx_stop_tx(port);
  147. }
  148. static void netx_start_tx(struct uart_port *port)
  149. {
  150. writel(
  151. readl(port->membase + UART_CR) | CR_TIE, port->membase + UART_CR);
  152. if (!(readl(port->membase + UART_FR) & FR_TXFF))
  153. netx_transmit_buffer(port);
  154. }
  155. static unsigned int netx_tx_empty(struct uart_port *port)
  156. {
  157. return readl(port->membase + UART_FR) & FR_BUSY ? 0 : TIOCSER_TEMT;
  158. }
  159. static void netx_txint(struct uart_port *port)
  160. {
  161. struct circ_buf *xmit = &port->state->xmit;
  162. if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
  163. netx_stop_tx(port);
  164. return;
  165. }
  166. netx_transmit_buffer(port);
  167. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  168. uart_write_wakeup(port);
  169. }
  170. static void netx_rxint(struct uart_port *port)
  171. {
  172. unsigned char rx, flg, status;
  173. struct tty_struct *tty = port->state->port.tty;
  174. while (!(readl(port->membase + UART_FR) & FR_RXFE)) {
  175. rx = readl(port->membase + UART_DR);
  176. flg = TTY_NORMAL;
  177. port->icount.rx++;
  178. status = readl(port->membase + UART_SR);
  179. if (status & SR_BE) {
  180. writel(0, port->membase + UART_SR);
  181. if (uart_handle_break(port))
  182. continue;
  183. }
  184. if (unlikely(status & (SR_FE | SR_PE | SR_OE))) {
  185. if (status & SR_PE)
  186. port->icount.parity++;
  187. else if (status & SR_FE)
  188. port->icount.frame++;
  189. if (status & SR_OE)
  190. port->icount.overrun++;
  191. status &= port->read_status_mask;
  192. if (status & SR_BE)
  193. flg = TTY_BREAK;
  194. else if (status & SR_PE)
  195. flg = TTY_PARITY;
  196. else if (status & SR_FE)
  197. flg = TTY_FRAME;
  198. }
  199. if (uart_handle_sysrq_char(port, rx))
  200. continue;
  201. uart_insert_char(port, status, SR_OE, rx, flg);
  202. }
  203. tty_flip_buffer_push(tty);
  204. return;
  205. }
  206. static irqreturn_t netx_int(int irq, void *dev_id)
  207. {
  208. struct uart_port *port = dev_id;
  209. unsigned long flags;
  210. unsigned char status;
  211. spin_lock_irqsave(&port->lock,flags);
  212. status = readl(port->membase + UART_IIR) & IIR_MASK;
  213. while (status) {
  214. if (status & IIR_RIS)
  215. netx_rxint(port);
  216. if (status & IIR_TIS)
  217. netx_txint(port);
  218. if (status & IIR_MIS) {
  219. if (readl(port->membase + UART_FR) & FR_CTS)
  220. uart_handle_cts_change(port, 1);
  221. else
  222. uart_handle_cts_change(port, 0);
  223. }
  224. writel(0, port->membase + UART_IIR);
  225. status = readl(port->membase + UART_IIR) & IIR_MASK;
  226. }
  227. spin_unlock_irqrestore(&port->lock,flags);
  228. return IRQ_HANDLED;
  229. }
  230. static unsigned int netx_get_mctrl(struct uart_port *port)
  231. {
  232. unsigned int ret = TIOCM_DSR | TIOCM_CAR;
  233. if (readl(port->membase + UART_FR) & FR_CTS)
  234. ret |= TIOCM_CTS;
  235. return ret;
  236. }
  237. static void netx_set_mctrl(struct uart_port *port, unsigned int mctrl)
  238. {
  239. unsigned int val;
  240. /* FIXME: Locking needed ? */
  241. if (mctrl & TIOCM_RTS) {
  242. val = readl(port->membase + UART_RTS_CR);
  243. writel(val | RTS_CR_RTS, port->membase + UART_RTS_CR);
  244. }
  245. }
  246. static void netx_break_ctl(struct uart_port *port, int break_state)
  247. {
  248. unsigned int line_cr;
  249. spin_lock_irq(&port->lock);
  250. line_cr = readl(port->membase + UART_LINE_CR);
  251. if (break_state != 0)
  252. line_cr |= LINE_CR_BRK;
  253. else
  254. line_cr &= ~LINE_CR_BRK;
  255. writel(line_cr, port->membase + UART_LINE_CR);
  256. spin_unlock_irq(&port->lock);
  257. }
  258. static int netx_startup(struct uart_port *port)
  259. {
  260. int ret;
  261. ret = request_irq(port->irq, netx_int, 0,
  262. DRIVER_NAME, port);
  263. if (ret) {
  264. dev_err(port->dev, "unable to grab irq%d\n",port->irq);
  265. goto exit;
  266. }
  267. writel(readl(port->membase + UART_LINE_CR) | LINE_CR_FEN,
  268. port->membase + UART_LINE_CR);
  269. writel(CR_MSIE | CR_RIE | CR_TIE | CR_RTIE | CR_UART_EN,
  270. port->membase + UART_CR);
  271. exit:
  272. return ret;
  273. }
  274. static void netx_shutdown(struct uart_port *port)
  275. {
  276. writel(0, port->membase + UART_CR) ;
  277. free_irq(port->irq, port);
  278. }
  279. static void
  280. netx_set_termios(struct uart_port *port, struct ktermios *termios,
  281. struct ktermios *old)
  282. {
  283. unsigned int baud, quot;
  284. unsigned char old_cr;
  285. unsigned char line_cr = LINE_CR_FEN;
  286. unsigned char rts_cr = 0;
  287. switch (termios->c_cflag & CSIZE) {
  288. case CS5:
  289. line_cr |= LINE_CR_5BIT;
  290. break;
  291. case CS6:
  292. line_cr |= LINE_CR_6BIT;
  293. break;
  294. case CS7:
  295. line_cr |= LINE_CR_7BIT;
  296. break;
  297. case CS8:
  298. line_cr |= LINE_CR_8BIT;
  299. break;
  300. }
  301. if (termios->c_cflag & CSTOPB)
  302. line_cr |= LINE_CR_STP2;
  303. if (termios->c_cflag & PARENB) {
  304. line_cr |= LINE_CR_PEN;
  305. if (!(termios->c_cflag & PARODD))
  306. line_cr |= LINE_CR_EPS;
  307. }
  308. if (termios->c_cflag & CRTSCTS)
  309. rts_cr = RTS_CR_AUTO | RTS_CR_CTS_CTR | RTS_CR_RTS_POL;
  310. baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
  311. quot = baud * 4096;
  312. quot /= 1000;
  313. quot *= 256;
  314. quot /= 100000;
  315. spin_lock_irq(&port->lock);
  316. uart_update_timeout(port, termios->c_cflag, baud);
  317. old_cr = readl(port->membase + UART_CR);
  318. /* disable interrupts */
  319. writel(old_cr & ~(CR_MSIE | CR_RIE | CR_TIE | CR_RTIE),
  320. port->membase + UART_CR);
  321. /* drain transmitter */
  322. while (readl(port->membase + UART_FR) & FR_BUSY);
  323. /* disable UART */
  324. writel(old_cr & ~CR_UART_EN, port->membase + UART_CR);
  325. /* modem status interrupts */
  326. old_cr &= ~CR_MSIE;
  327. if (UART_ENABLE_MS(port, termios->c_cflag))
  328. old_cr |= CR_MSIE;
  329. writel((quot>>8) & 0xff, port->membase + UART_BAUDDIV_MSB);
  330. writel(quot & 0xff, port->membase + UART_BAUDDIV_LSB);
  331. writel(line_cr, port->membase + UART_LINE_CR);
  332. writel(rts_cr, port->membase + UART_RTS_CR);
  333. /*
  334. * Characters to ignore
  335. */
  336. port->ignore_status_mask = 0;
  337. if (termios->c_iflag & IGNPAR)
  338. port->ignore_status_mask |= SR_PE;
  339. if (termios->c_iflag & IGNBRK) {
  340. port->ignore_status_mask |= SR_BE;
  341. /*
  342. * If we're ignoring parity and break indicators,
  343. * ignore overruns too (for real raw support).
  344. */
  345. if (termios->c_iflag & IGNPAR)
  346. port->ignore_status_mask |= SR_PE;
  347. }
  348. port->read_status_mask = 0;
  349. if (termios->c_iflag & (BRKINT | PARMRK))
  350. port->read_status_mask |= SR_BE;
  351. if (termios->c_iflag & INPCK)
  352. port->read_status_mask |= SR_PE | SR_FE;
  353. writel(old_cr, port->membase + UART_CR);
  354. spin_unlock_irq(&port->lock);
  355. }
  356. static const char *netx_type(struct uart_port *port)
  357. {
  358. return port->type == PORT_NETX ? "NETX" : NULL;
  359. }
  360. static void netx_release_port(struct uart_port *port)
  361. {
  362. release_mem_region(port->mapbase, UART_PORT_SIZE);
  363. }
  364. static int netx_request_port(struct uart_port *port)
  365. {
  366. return request_mem_region(port->mapbase, UART_PORT_SIZE,
  367. DRIVER_NAME) != NULL ? 0 : -EBUSY;
  368. }
  369. static void netx_config_port(struct uart_port *port, int flags)
  370. {
  371. if (flags & UART_CONFIG_TYPE && netx_request_port(port) == 0)
  372. port->type = PORT_NETX;
  373. }
  374. static int
  375. netx_verify_port(struct uart_port *port, struct serial_struct *ser)
  376. {
  377. int ret = 0;
  378. if (ser->type != PORT_UNKNOWN && ser->type != PORT_NETX)
  379. ret = -EINVAL;
  380. return ret;
  381. }
  382. static struct uart_ops netx_pops = {
  383. .tx_empty = netx_tx_empty,
  384. .set_mctrl = netx_set_mctrl,
  385. .get_mctrl = netx_get_mctrl,
  386. .stop_tx = netx_stop_tx,
  387. .start_tx = netx_start_tx,
  388. .stop_rx = netx_stop_rx,
  389. .enable_ms = netx_enable_ms,
  390. .break_ctl = netx_break_ctl,
  391. .startup = netx_startup,
  392. .shutdown = netx_shutdown,
  393. .set_termios = netx_set_termios,
  394. .type = netx_type,
  395. .release_port = netx_release_port,
  396. .request_port = netx_request_port,
  397. .config_port = netx_config_port,
  398. .verify_port = netx_verify_port,
  399. };
  400. static struct netx_port netx_ports[] = {
  401. {
  402. .port = {
  403. .type = PORT_NETX,
  404. .iotype = UPIO_MEM,
  405. .membase = (char __iomem *)io_p2v(NETX_PA_UART0),
  406. .mapbase = NETX_PA_UART0,
  407. .irq = NETX_IRQ_UART0,
  408. .uartclk = 100000000,
  409. .fifosize = 16,
  410. .flags = UPF_BOOT_AUTOCONF,
  411. .ops = &netx_pops,
  412. .line = 0,
  413. },
  414. }, {
  415. .port = {
  416. .type = PORT_NETX,
  417. .iotype = UPIO_MEM,
  418. .membase = (char __iomem *)io_p2v(NETX_PA_UART1),
  419. .mapbase = NETX_PA_UART1,
  420. .irq = NETX_IRQ_UART1,
  421. .uartclk = 100000000,
  422. .fifosize = 16,
  423. .flags = UPF_BOOT_AUTOCONF,
  424. .ops = &netx_pops,
  425. .line = 1,
  426. },
  427. }, {
  428. .port = {
  429. .type = PORT_NETX,
  430. .iotype = UPIO_MEM,
  431. .membase = (char __iomem *)io_p2v(NETX_PA_UART2),
  432. .mapbase = NETX_PA_UART2,
  433. .irq = NETX_IRQ_UART2,
  434. .uartclk = 100000000,
  435. .fifosize = 16,
  436. .flags = UPF_BOOT_AUTOCONF,
  437. .ops = &netx_pops,
  438. .line = 2,
  439. },
  440. }
  441. };
  442. #ifdef CONFIG_SERIAL_NETX_CONSOLE
  443. static void netx_console_putchar(struct uart_port *port, int ch)
  444. {
  445. while (readl(port->membase + UART_FR) & FR_BUSY);
  446. writel(ch, port->membase + UART_DR);
  447. }
  448. static void
  449. netx_console_write(struct console *co, const char *s, unsigned int count)
  450. {
  451. struct uart_port *port = &netx_ports[co->index].port;
  452. unsigned char cr_save;
  453. cr_save = readl(port->membase + UART_CR);
  454. writel(cr_save | CR_UART_EN, port->membase + UART_CR);
  455. uart_console_write(port, s, count, netx_console_putchar);
  456. while (readl(port->membase + UART_FR) & FR_BUSY);
  457. writel(cr_save, port->membase + UART_CR);
  458. }
  459. static void __init
  460. netx_console_get_options(struct uart_port *port, int *baud,
  461. int *parity, int *bits, int *flow)
  462. {
  463. unsigned char line_cr;
  464. *baud = (readl(port->membase + UART_BAUDDIV_MSB) << 8) |
  465. readl(port->membase + UART_BAUDDIV_LSB);
  466. *baud *= 1000;
  467. *baud /= 4096;
  468. *baud *= 1000;
  469. *baud /= 256;
  470. *baud *= 100;
  471. line_cr = readl(port->membase + UART_LINE_CR);
  472. *parity = 'n';
  473. if (line_cr & LINE_CR_PEN) {
  474. if (line_cr & LINE_CR_EPS)
  475. *parity = 'e';
  476. else
  477. *parity = 'o';
  478. }
  479. switch (line_cr & LINE_CR_BITS_MASK) {
  480. case LINE_CR_8BIT:
  481. *bits = 8;
  482. break;
  483. case LINE_CR_7BIT:
  484. *bits = 7;
  485. break;
  486. case LINE_CR_6BIT:
  487. *bits = 6;
  488. break;
  489. case LINE_CR_5BIT:
  490. *bits = 5;
  491. break;
  492. }
  493. if (readl(port->membase + UART_RTS_CR) & RTS_CR_AUTO)
  494. *flow = 'r';
  495. }
  496. static int __init
  497. netx_console_setup(struct console *co, char *options)
  498. {
  499. struct netx_port *sport;
  500. int baud = 9600;
  501. int bits = 8;
  502. int parity = 'n';
  503. int flow = 'n';
  504. /*
  505. * Check whether an invalid uart number has been specified, and
  506. * if so, search for the first available port that does have
  507. * console support.
  508. */
  509. if (co->index == -1 || co->index >= ARRAY_SIZE(netx_ports))
  510. co->index = 0;
  511. sport = &netx_ports[co->index];
  512. if (options) {
  513. uart_parse_options(options, &baud, &parity, &bits, &flow);
  514. } else {
  515. /* if the UART is enabled, assume it has been correctly setup
  516. * by the bootloader and get the options
  517. */
  518. if (readl(sport->port.membase + UART_CR) & CR_UART_EN) {
  519. netx_console_get_options(&sport->port, &baud,
  520. &parity, &bits, &flow);
  521. }
  522. }
  523. return uart_set_options(&sport->port, co, baud, parity, bits, flow);
  524. }
  525. static struct uart_driver netx_reg;
  526. static struct console netx_console = {
  527. .name = "ttyNX",
  528. .write = netx_console_write,
  529. .device = uart_console_device,
  530. .setup = netx_console_setup,
  531. .flags = CON_PRINTBUFFER,
  532. .index = -1,
  533. .data = &netx_reg,
  534. };
  535. static int __init netx_console_init(void)
  536. {
  537. register_console(&netx_console);
  538. return 0;
  539. }
  540. console_initcall(netx_console_init);
  541. #define NETX_CONSOLE &netx_console
  542. #else
  543. #define NETX_CONSOLE NULL
  544. #endif
  545. static struct uart_driver netx_reg = {
  546. .owner = THIS_MODULE,
  547. .driver_name = DRIVER_NAME,
  548. .dev_name = "ttyNX",
  549. .major = SERIAL_NX_MAJOR,
  550. .minor = MINOR_START,
  551. .nr = ARRAY_SIZE(netx_ports),
  552. .cons = NETX_CONSOLE,
  553. };
  554. static int serial_netx_suspend(struct platform_device *pdev, pm_message_t state)
  555. {
  556. struct netx_port *sport = platform_get_drvdata(pdev);
  557. if (sport)
  558. uart_suspend_port(&netx_reg, &sport->port);
  559. return 0;
  560. }
  561. static int serial_netx_resume(struct platform_device *pdev)
  562. {
  563. struct netx_port *sport = platform_get_drvdata(pdev);
  564. if (sport)
  565. uart_resume_port(&netx_reg, &sport->port);
  566. return 0;
  567. }
  568. static int serial_netx_probe(struct platform_device *pdev)
  569. {
  570. struct uart_port *port = &netx_ports[pdev->id].port;
  571. dev_info(&pdev->dev, "initialising\n");
  572. port->dev = &pdev->dev;
  573. writel(1, port->membase + UART_RXFIFO_IRQLEVEL);
  574. uart_add_one_port(&netx_reg, &netx_ports[pdev->id].port);
  575. platform_set_drvdata(pdev, &netx_ports[pdev->id]);
  576. return 0;
  577. }
  578. static int serial_netx_remove(struct platform_device *pdev)
  579. {
  580. struct netx_port *sport = platform_get_drvdata(pdev);
  581. platform_set_drvdata(pdev, NULL);
  582. if (sport)
  583. uart_remove_one_port(&netx_reg, &sport->port);
  584. return 0;
  585. }
  586. static struct platform_driver serial_netx_driver = {
  587. .probe = serial_netx_probe,
  588. .remove = serial_netx_remove,
  589. .suspend = serial_netx_suspend,
  590. .resume = serial_netx_resume,
  591. .driver = {
  592. .name = DRIVER_NAME,
  593. .owner = THIS_MODULE,
  594. },
  595. };
  596. static int __init netx_serial_init(void)
  597. {
  598. int ret;
  599. printk(KERN_INFO "Serial: NetX driver\n");
  600. ret = uart_register_driver(&netx_reg);
  601. if (ret)
  602. return ret;
  603. ret = platform_driver_register(&serial_netx_driver);
  604. if (ret != 0)
  605. uart_unregister_driver(&netx_reg);
  606. return 0;
  607. }
  608. static void __exit netx_serial_exit(void)
  609. {
  610. platform_driver_unregister(&serial_netx_driver);
  611. uart_unregister_driver(&netx_reg);
  612. }
  613. module_init(netx_serial_init);
  614. module_exit(netx_serial_exit);
  615. MODULE_AUTHOR("Sascha Hauer");
  616. MODULE_DESCRIPTION("NetX serial port driver");
  617. MODULE_LICENSE("GPL");
  618. MODULE_ALIAS("platform:" DRIVER_NAME);