netx-serial.c 17 KB

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