netx-serial.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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. while (!(readl(port->membase + UART_FR) & FR_RXFE)) {
  174. rx = readl(port->membase + UART_DR);
  175. flg = TTY_NORMAL;
  176. port->icount.rx++;
  177. status = readl(port->membase + UART_SR);
  178. if (status & SR_BE) {
  179. writel(0, port->membase + UART_SR);
  180. if (uart_handle_break(port))
  181. continue;
  182. }
  183. if (unlikely(status & (SR_FE | SR_PE | SR_OE))) {
  184. if (status & SR_PE)
  185. port->icount.parity++;
  186. else if (status & SR_FE)
  187. port->icount.frame++;
  188. if (status & SR_OE)
  189. port->icount.overrun++;
  190. status &= port->read_status_mask;
  191. if (status & SR_BE)
  192. flg = TTY_BREAK;
  193. else if (status & SR_PE)
  194. flg = TTY_PARITY;
  195. else if (status & SR_FE)
  196. flg = TTY_FRAME;
  197. }
  198. if (uart_handle_sysrq_char(port, rx))
  199. continue;
  200. uart_insert_char(port, status, SR_OE, rx, flg);
  201. }
  202. tty_flip_buffer_push(&port->state->port);
  203. }
  204. static irqreturn_t netx_int(int irq, void *dev_id)
  205. {
  206. struct uart_port *port = dev_id;
  207. unsigned long flags;
  208. unsigned char status;
  209. spin_lock_irqsave(&port->lock,flags);
  210. status = readl(port->membase + UART_IIR) & IIR_MASK;
  211. while (status) {
  212. if (status & IIR_RIS)
  213. netx_rxint(port);
  214. if (status & IIR_TIS)
  215. netx_txint(port);
  216. if (status & IIR_MIS) {
  217. if (readl(port->membase + UART_FR) & FR_CTS)
  218. uart_handle_cts_change(port, 1);
  219. else
  220. uart_handle_cts_change(port, 0);
  221. }
  222. writel(0, port->membase + UART_IIR);
  223. status = readl(port->membase + UART_IIR) & IIR_MASK;
  224. }
  225. spin_unlock_irqrestore(&port->lock,flags);
  226. return IRQ_HANDLED;
  227. }
  228. static unsigned int netx_get_mctrl(struct uart_port *port)
  229. {
  230. unsigned int ret = TIOCM_DSR | TIOCM_CAR;
  231. if (readl(port->membase + UART_FR) & FR_CTS)
  232. ret |= TIOCM_CTS;
  233. return ret;
  234. }
  235. static void netx_set_mctrl(struct uart_port *port, unsigned int mctrl)
  236. {
  237. unsigned int val;
  238. /* FIXME: Locking needed ? */
  239. if (mctrl & TIOCM_RTS) {
  240. val = readl(port->membase + UART_RTS_CR);
  241. writel(val | RTS_CR_RTS, port->membase + UART_RTS_CR);
  242. }
  243. }
  244. static void netx_break_ctl(struct uart_port *port, int break_state)
  245. {
  246. unsigned int line_cr;
  247. spin_lock_irq(&port->lock);
  248. line_cr = readl(port->membase + UART_LINE_CR);
  249. if (break_state != 0)
  250. line_cr |= LINE_CR_BRK;
  251. else
  252. line_cr &= ~LINE_CR_BRK;
  253. writel(line_cr, port->membase + UART_LINE_CR);
  254. spin_unlock_irq(&port->lock);
  255. }
  256. static int netx_startup(struct uart_port *port)
  257. {
  258. int ret;
  259. ret = request_irq(port->irq, netx_int, 0,
  260. DRIVER_NAME, port);
  261. if (ret) {
  262. dev_err(port->dev, "unable to grab irq%d\n",port->irq);
  263. goto exit;
  264. }
  265. writel(readl(port->membase + UART_LINE_CR) | LINE_CR_FEN,
  266. port->membase + UART_LINE_CR);
  267. writel(CR_MSIE | CR_RIE | CR_TIE | CR_RTIE | CR_UART_EN,
  268. port->membase + UART_CR);
  269. exit:
  270. return ret;
  271. }
  272. static void netx_shutdown(struct uart_port *port)
  273. {
  274. writel(0, port->membase + UART_CR) ;
  275. free_irq(port->irq, port);
  276. }
  277. static void
  278. netx_set_termios(struct uart_port *port, struct ktermios *termios,
  279. struct ktermios *old)
  280. {
  281. unsigned int baud, quot;
  282. unsigned char old_cr;
  283. unsigned char line_cr = LINE_CR_FEN;
  284. unsigned char rts_cr = 0;
  285. switch (termios->c_cflag & CSIZE) {
  286. case CS5:
  287. line_cr |= LINE_CR_5BIT;
  288. break;
  289. case CS6:
  290. line_cr |= LINE_CR_6BIT;
  291. break;
  292. case CS7:
  293. line_cr |= LINE_CR_7BIT;
  294. break;
  295. case CS8:
  296. line_cr |= LINE_CR_8BIT;
  297. break;
  298. }
  299. if (termios->c_cflag & CSTOPB)
  300. line_cr |= LINE_CR_STP2;
  301. if (termios->c_cflag & PARENB) {
  302. line_cr |= LINE_CR_PEN;
  303. if (!(termios->c_cflag & PARODD))
  304. line_cr |= LINE_CR_EPS;
  305. }
  306. if (termios->c_cflag & CRTSCTS)
  307. rts_cr = RTS_CR_AUTO | RTS_CR_CTS_CTR | RTS_CR_RTS_POL;
  308. baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
  309. quot = baud * 4096;
  310. quot /= 1000;
  311. quot *= 256;
  312. quot /= 100000;
  313. spin_lock_irq(&port->lock);
  314. uart_update_timeout(port, termios->c_cflag, baud);
  315. old_cr = readl(port->membase + UART_CR);
  316. /* disable interrupts */
  317. writel(old_cr & ~(CR_MSIE | CR_RIE | CR_TIE | CR_RTIE),
  318. port->membase + UART_CR);
  319. /* drain transmitter */
  320. while (readl(port->membase + UART_FR) & FR_BUSY);
  321. /* disable UART */
  322. writel(old_cr & ~CR_UART_EN, port->membase + UART_CR);
  323. /* modem status interrupts */
  324. old_cr &= ~CR_MSIE;
  325. if (UART_ENABLE_MS(port, termios->c_cflag))
  326. old_cr |= CR_MSIE;
  327. writel((quot>>8) & 0xff, port->membase + UART_BAUDDIV_MSB);
  328. writel(quot & 0xff, port->membase + UART_BAUDDIV_LSB);
  329. writel(line_cr, port->membase + UART_LINE_CR);
  330. writel(rts_cr, port->membase + UART_RTS_CR);
  331. /*
  332. * Characters to ignore
  333. */
  334. port->ignore_status_mask = 0;
  335. if (termios->c_iflag & IGNPAR)
  336. port->ignore_status_mask |= SR_PE;
  337. if (termios->c_iflag & IGNBRK) {
  338. port->ignore_status_mask |= SR_BE;
  339. /*
  340. * If we're ignoring parity and break indicators,
  341. * ignore overruns too (for real raw support).
  342. */
  343. if (termios->c_iflag & IGNPAR)
  344. port->ignore_status_mask |= SR_PE;
  345. }
  346. port->read_status_mask = 0;
  347. if (termios->c_iflag & (BRKINT | PARMRK))
  348. port->read_status_mask |= SR_BE;
  349. if (termios->c_iflag & INPCK)
  350. port->read_status_mask |= SR_PE | SR_FE;
  351. writel(old_cr, port->membase + UART_CR);
  352. spin_unlock_irq(&port->lock);
  353. }
  354. static const char *netx_type(struct uart_port *port)
  355. {
  356. return port->type == PORT_NETX ? "NETX" : NULL;
  357. }
  358. static void netx_release_port(struct uart_port *port)
  359. {
  360. release_mem_region(port->mapbase, UART_PORT_SIZE);
  361. }
  362. static int netx_request_port(struct uart_port *port)
  363. {
  364. return request_mem_region(port->mapbase, UART_PORT_SIZE,
  365. DRIVER_NAME) != NULL ? 0 : -EBUSY;
  366. }
  367. static void netx_config_port(struct uart_port *port, int flags)
  368. {
  369. if (flags & UART_CONFIG_TYPE && netx_request_port(port) == 0)
  370. port->type = PORT_NETX;
  371. }
  372. static int
  373. netx_verify_port(struct uart_port *port, struct serial_struct *ser)
  374. {
  375. int ret = 0;
  376. if (ser->type != PORT_UNKNOWN && ser->type != PORT_NETX)
  377. ret = -EINVAL;
  378. return ret;
  379. }
  380. static struct uart_ops netx_pops = {
  381. .tx_empty = netx_tx_empty,
  382. .set_mctrl = netx_set_mctrl,
  383. .get_mctrl = netx_get_mctrl,
  384. .stop_tx = netx_stop_tx,
  385. .start_tx = netx_start_tx,
  386. .stop_rx = netx_stop_rx,
  387. .enable_ms = netx_enable_ms,
  388. .break_ctl = netx_break_ctl,
  389. .startup = netx_startup,
  390. .shutdown = netx_shutdown,
  391. .set_termios = netx_set_termios,
  392. .type = netx_type,
  393. .release_port = netx_release_port,
  394. .request_port = netx_request_port,
  395. .config_port = netx_config_port,
  396. .verify_port = netx_verify_port,
  397. };
  398. static struct netx_port netx_ports[] = {
  399. {
  400. .port = {
  401. .type = PORT_NETX,
  402. .iotype = UPIO_MEM,
  403. .membase = (char __iomem *)io_p2v(NETX_PA_UART0),
  404. .mapbase = NETX_PA_UART0,
  405. .irq = NETX_IRQ_UART0,
  406. .uartclk = 100000000,
  407. .fifosize = 16,
  408. .flags = UPF_BOOT_AUTOCONF,
  409. .ops = &netx_pops,
  410. .line = 0,
  411. },
  412. }, {
  413. .port = {
  414. .type = PORT_NETX,
  415. .iotype = UPIO_MEM,
  416. .membase = (char __iomem *)io_p2v(NETX_PA_UART1),
  417. .mapbase = NETX_PA_UART1,
  418. .irq = NETX_IRQ_UART1,
  419. .uartclk = 100000000,
  420. .fifosize = 16,
  421. .flags = UPF_BOOT_AUTOCONF,
  422. .ops = &netx_pops,
  423. .line = 1,
  424. },
  425. }, {
  426. .port = {
  427. .type = PORT_NETX,
  428. .iotype = UPIO_MEM,
  429. .membase = (char __iomem *)io_p2v(NETX_PA_UART2),
  430. .mapbase = NETX_PA_UART2,
  431. .irq = NETX_IRQ_UART2,
  432. .uartclk = 100000000,
  433. .fifosize = 16,
  434. .flags = UPF_BOOT_AUTOCONF,
  435. .ops = &netx_pops,
  436. .line = 2,
  437. },
  438. }
  439. };
  440. #ifdef CONFIG_SERIAL_NETX_CONSOLE
  441. static void netx_console_putchar(struct uart_port *port, int ch)
  442. {
  443. while (readl(port->membase + UART_FR) & FR_BUSY);
  444. writel(ch, port->membase + UART_DR);
  445. }
  446. static void
  447. netx_console_write(struct console *co, const char *s, unsigned int count)
  448. {
  449. struct uart_port *port = &netx_ports[co->index].port;
  450. unsigned char cr_save;
  451. cr_save = readl(port->membase + UART_CR);
  452. writel(cr_save | CR_UART_EN, port->membase + UART_CR);
  453. uart_console_write(port, s, count, netx_console_putchar);
  454. while (readl(port->membase + UART_FR) & FR_BUSY);
  455. writel(cr_save, port->membase + UART_CR);
  456. }
  457. static void __init
  458. netx_console_get_options(struct uart_port *port, int *baud,
  459. int *parity, int *bits, int *flow)
  460. {
  461. unsigned char line_cr;
  462. *baud = (readl(port->membase + UART_BAUDDIV_MSB) << 8) |
  463. readl(port->membase + UART_BAUDDIV_LSB);
  464. *baud *= 1000;
  465. *baud /= 4096;
  466. *baud *= 1000;
  467. *baud /= 256;
  468. *baud *= 100;
  469. line_cr = readl(port->membase + UART_LINE_CR);
  470. *parity = 'n';
  471. if (line_cr & LINE_CR_PEN) {
  472. if (line_cr & LINE_CR_EPS)
  473. *parity = 'e';
  474. else
  475. *parity = 'o';
  476. }
  477. switch (line_cr & LINE_CR_BITS_MASK) {
  478. case LINE_CR_8BIT:
  479. *bits = 8;
  480. break;
  481. case LINE_CR_7BIT:
  482. *bits = 7;
  483. break;
  484. case LINE_CR_6BIT:
  485. *bits = 6;
  486. break;
  487. case LINE_CR_5BIT:
  488. *bits = 5;
  489. break;
  490. }
  491. if (readl(port->membase + UART_RTS_CR) & RTS_CR_AUTO)
  492. *flow = 'r';
  493. }
  494. static int __init
  495. netx_console_setup(struct console *co, char *options)
  496. {
  497. struct netx_port *sport;
  498. int baud = 9600;
  499. int bits = 8;
  500. int parity = 'n';
  501. int flow = 'n';
  502. /*
  503. * Check whether an invalid uart number has been specified, and
  504. * if so, search for the first available port that does have
  505. * console support.
  506. */
  507. if (co->index == -1 || co->index >= ARRAY_SIZE(netx_ports))
  508. co->index = 0;
  509. sport = &netx_ports[co->index];
  510. if (options) {
  511. uart_parse_options(options, &baud, &parity, &bits, &flow);
  512. } else {
  513. /* if the UART is enabled, assume it has been correctly setup
  514. * by the bootloader and get the options
  515. */
  516. if (readl(sport->port.membase + UART_CR) & CR_UART_EN) {
  517. netx_console_get_options(&sport->port, &baud,
  518. &parity, &bits, &flow);
  519. }
  520. }
  521. return uart_set_options(&sport->port, co, baud, parity, bits, flow);
  522. }
  523. static struct uart_driver netx_reg;
  524. static struct console netx_console = {
  525. .name = "ttyNX",
  526. .write = netx_console_write,
  527. .device = uart_console_device,
  528. .setup = netx_console_setup,
  529. .flags = CON_PRINTBUFFER,
  530. .index = -1,
  531. .data = &netx_reg,
  532. };
  533. static int __init netx_console_init(void)
  534. {
  535. register_console(&netx_console);
  536. return 0;
  537. }
  538. console_initcall(netx_console_init);
  539. #define NETX_CONSOLE &netx_console
  540. #else
  541. #define NETX_CONSOLE NULL
  542. #endif
  543. static struct uart_driver netx_reg = {
  544. .owner = THIS_MODULE,
  545. .driver_name = DRIVER_NAME,
  546. .dev_name = "ttyNX",
  547. .major = SERIAL_NX_MAJOR,
  548. .minor = MINOR_START,
  549. .nr = ARRAY_SIZE(netx_ports),
  550. .cons = NETX_CONSOLE,
  551. };
  552. static int serial_netx_suspend(struct platform_device *pdev, pm_message_t state)
  553. {
  554. struct netx_port *sport = platform_get_drvdata(pdev);
  555. if (sport)
  556. uart_suspend_port(&netx_reg, &sport->port);
  557. return 0;
  558. }
  559. static int serial_netx_resume(struct platform_device *pdev)
  560. {
  561. struct netx_port *sport = platform_get_drvdata(pdev);
  562. if (sport)
  563. uart_resume_port(&netx_reg, &sport->port);
  564. return 0;
  565. }
  566. static int serial_netx_probe(struct platform_device *pdev)
  567. {
  568. struct uart_port *port = &netx_ports[pdev->id].port;
  569. dev_info(&pdev->dev, "initialising\n");
  570. port->dev = &pdev->dev;
  571. writel(1, port->membase + UART_RXFIFO_IRQLEVEL);
  572. uart_add_one_port(&netx_reg, &netx_ports[pdev->id].port);
  573. platform_set_drvdata(pdev, &netx_ports[pdev->id]);
  574. return 0;
  575. }
  576. static int serial_netx_remove(struct platform_device *pdev)
  577. {
  578. struct netx_port *sport = platform_get_drvdata(pdev);
  579. platform_set_drvdata(pdev, NULL);
  580. if (sport)
  581. uart_remove_one_port(&netx_reg, &sport->port);
  582. return 0;
  583. }
  584. static struct platform_driver serial_netx_driver = {
  585. .probe = serial_netx_probe,
  586. .remove = serial_netx_remove,
  587. .suspend = serial_netx_suspend,
  588. .resume = serial_netx_resume,
  589. .driver = {
  590. .name = DRIVER_NAME,
  591. .owner = THIS_MODULE,
  592. },
  593. };
  594. static int __init netx_serial_init(void)
  595. {
  596. int ret;
  597. printk(KERN_INFO "Serial: NetX driver\n");
  598. ret = uart_register_driver(&netx_reg);
  599. if (ret)
  600. return ret;
  601. ret = platform_driver_register(&serial_netx_driver);
  602. if (ret != 0)
  603. uart_unregister_driver(&netx_reg);
  604. return 0;
  605. }
  606. static void __exit netx_serial_exit(void)
  607. {
  608. platform_driver_unregister(&serial_netx_driver);
  609. uart_unregister_driver(&netx_reg);
  610. }
  611. module_init(netx_serial_init);
  612. module_exit(netx_serial_exit);
  613. MODULE_AUTHOR("Sascha Hauer");
  614. MODULE_DESCRIPTION("NetX serial port driver");
  615. MODULE_LICENSE("GPL");
  616. MODULE_ALIAS("platform:" DRIVER_NAME);