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. #ifdef CONFIG_SERIAL_NETX_CONSOLE
  41. enum uart_regs {
  42. UART_DR = 0x00,
  43. UART_SR = 0x04,
  44. UART_LINE_CR = 0x08,
  45. UART_BAUDDIV_MSB = 0x0c,
  46. UART_BAUDDIV_LSB = 0x10,
  47. UART_CR = 0x14,
  48. UART_FR = 0x18,
  49. UART_IIR = 0x1c,
  50. UART_ILPR = 0x20,
  51. UART_RTS_CR = 0x24,
  52. UART_RTS_LEAD = 0x28,
  53. UART_RTS_TRAIL = 0x2c,
  54. UART_DRV_ENABLE = 0x30,
  55. UART_BRM_CR = 0x34,
  56. UART_RXFIFO_IRQLEVEL = 0x38,
  57. UART_TXFIFO_IRQLEVEL = 0x3c,
  58. };
  59. #define SR_FE (1<<0)
  60. #define SR_PE (1<<1)
  61. #define SR_BE (1<<2)
  62. #define SR_OE (1<<3)
  63. #define LINE_CR_BRK (1<<0)
  64. #define LINE_CR_PEN (1<<1)
  65. #define LINE_CR_EPS (1<<2)
  66. #define LINE_CR_STP2 (1<<3)
  67. #define LINE_CR_FEN (1<<4)
  68. #define LINE_CR_5BIT (0<<5)
  69. #define LINE_CR_6BIT (1<<5)
  70. #define LINE_CR_7BIT (2<<5)
  71. #define LINE_CR_8BIT (3<<5)
  72. #define LINE_CR_BITS_MASK (3<<5)
  73. #define CR_UART_EN (1<<0)
  74. #define CR_SIREN (1<<1)
  75. #define CR_SIRLP (1<<2)
  76. #define CR_MSIE (1<<3)
  77. #define CR_RIE (1<<4)
  78. #define CR_TIE (1<<5)
  79. #define CR_RTIE (1<<6)
  80. #define CR_LBE (1<<7)
  81. #define FR_CTS (1<<0)
  82. #define FR_DSR (1<<1)
  83. #define FR_DCD (1<<2)
  84. #define FR_BUSY (1<<3)
  85. #define FR_RXFE (1<<4)
  86. #define FR_TXFF (1<<5)
  87. #define FR_RXFF (1<<6)
  88. #define FR_TXFE (1<<7)
  89. #define IIR_MIS (1<<0)
  90. #define IIR_RIS (1<<1)
  91. #define IIR_TIS (1<<2)
  92. #define IIR_RTIS (1<<3)
  93. #define IIR_MASK 0xf
  94. #define RTS_CR_AUTO (1<<0)
  95. #define RTS_CR_RTS (1<<1)
  96. #define RTS_CR_COUNT (1<<2)
  97. #define RTS_CR_MOD2 (1<<3)
  98. #define RTS_CR_RTS_POL (1<<4)
  99. #define RTS_CR_CTS_CTR (1<<5)
  100. #define RTS_CR_CTS_POL (1<<6)
  101. #define RTS_CR_STICK (1<<7)
  102. #define UART_PORT_SIZE 0x40
  103. #define DRIVER_NAME "netx-uart"
  104. struct netx_port {
  105. struct uart_port port;
  106. };
  107. static void netx_stop_tx(struct uart_port *port)
  108. {
  109. unsigned int val;
  110. val = readl(port->membase + UART_CR);
  111. writel(val & ~CR_TIE, port->membase + UART_CR);
  112. }
  113. static void netx_stop_rx(struct uart_port *port)
  114. {
  115. unsigned int val;
  116. val = readl(port->membase + UART_CR);
  117. writel(val & ~CR_RIE, port->membase + UART_CR);
  118. }
  119. static void netx_enable_ms(struct uart_port *port)
  120. {
  121. unsigned int val;
  122. val = readl(port->membase + UART_CR);
  123. writel(val | CR_MSIE, port->membase + UART_CR);
  124. }
  125. static inline void netx_transmit_buffer(struct uart_port *port)
  126. {
  127. struct circ_buf *xmit = &port->info->xmit;
  128. if (port->x_char) {
  129. writel(port->x_char, port->membase + UART_DR);
  130. port->icount.tx++;
  131. port->x_char = 0;
  132. return;
  133. }
  134. if (uart_tx_stopped(port) || uart_circ_empty(xmit)) {
  135. netx_stop_tx(port);
  136. return;
  137. }
  138. do {
  139. /* send xmit->buf[xmit->tail]
  140. * out the port here */
  141. writel(xmit->buf[xmit->tail], port->membase + UART_DR);
  142. xmit->tail = (xmit->tail + 1) &
  143. (UART_XMIT_SIZE - 1);
  144. port->icount.tx++;
  145. if (uart_circ_empty(xmit))
  146. break;
  147. } while (!(readl(port->membase + UART_FR) & FR_TXFF));
  148. if (uart_circ_empty(xmit))
  149. netx_stop_tx(port);
  150. }
  151. static void netx_start_tx(struct uart_port *port)
  152. {
  153. writel(
  154. readl(port->membase + UART_CR) | CR_TIE, port->membase + UART_CR);
  155. if (!(readl(port->membase + UART_FR) & FR_TXFF))
  156. netx_transmit_buffer(port);
  157. }
  158. static unsigned int netx_tx_empty(struct uart_port *port)
  159. {
  160. return readl(port->membase + UART_FR) & FR_BUSY ? 0 : TIOCSER_TEMT;
  161. }
  162. static void netx_txint(struct uart_port *port)
  163. {
  164. struct circ_buf *xmit = &port->info->xmit;
  165. if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
  166. netx_stop_tx(port);
  167. return;
  168. }
  169. netx_transmit_buffer(port);
  170. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  171. uart_write_wakeup(port);
  172. }
  173. static void netx_rxint(struct uart_port *port)
  174. {
  175. unsigned char rx, flg, status;
  176. struct tty_struct *tty = port->info->port.tty;
  177. while (!(readl(port->membase + UART_FR) & FR_RXFE)) {
  178. rx = readl(port->membase + UART_DR);
  179. flg = TTY_NORMAL;
  180. port->icount.rx++;
  181. status = readl(port->membase + UART_SR);
  182. if (status & SR_BE) {
  183. writel(0, port->membase + UART_SR);
  184. if (uart_handle_break(port))
  185. continue;
  186. }
  187. if (unlikely(status & (SR_FE | SR_PE | SR_OE))) {
  188. if (status & SR_PE)
  189. port->icount.parity++;
  190. else if (status & SR_FE)
  191. port->icount.frame++;
  192. if (status & SR_OE)
  193. port->icount.overrun++;
  194. status &= port->read_status_mask;
  195. if (status & SR_BE)
  196. flg = TTY_BREAK;
  197. else if (status & SR_PE)
  198. flg = TTY_PARITY;
  199. else if (status & SR_FE)
  200. flg = TTY_FRAME;
  201. }
  202. if (uart_handle_sysrq_char(port, rx))
  203. continue;
  204. uart_insert_char(port, status, SR_OE, rx, flg);
  205. }
  206. tty_flip_buffer_push(tty);
  207. return;
  208. }
  209. static irqreturn_t netx_int(int irq, void *dev_id)
  210. {
  211. struct uart_port *port = dev_id;
  212. unsigned long flags;
  213. unsigned char status;
  214. spin_lock_irqsave(&port->lock,flags);
  215. status = readl(port->membase + UART_IIR) & IIR_MASK;
  216. while (status) {
  217. if (status & IIR_RIS)
  218. netx_rxint(port);
  219. if (status & IIR_TIS)
  220. netx_txint(port);
  221. if (status & IIR_MIS) {
  222. if (readl(port->membase + UART_FR) & FR_CTS)
  223. uart_handle_cts_change(port, 1);
  224. else
  225. uart_handle_cts_change(port, 0);
  226. }
  227. writel(0, port->membase + UART_IIR);
  228. status = readl(port->membase + UART_IIR) & IIR_MASK;
  229. }
  230. spin_unlock_irqrestore(&port->lock,flags);
  231. return IRQ_HANDLED;
  232. }
  233. static unsigned int netx_get_mctrl(struct uart_port *port)
  234. {
  235. unsigned int ret = TIOCM_DSR | TIOCM_CAR;
  236. if (readl(port->membase + UART_FR) & FR_CTS)
  237. ret |= TIOCM_CTS;
  238. return ret;
  239. }
  240. static void netx_set_mctrl(struct uart_port *port, unsigned int mctrl)
  241. {
  242. unsigned int val;
  243. /* FIXME: Locking needed ? */
  244. if (mctrl & TIOCM_RTS) {
  245. val = readl(port->membase + UART_RTS_CR);
  246. writel(val | RTS_CR_RTS, port->membase + UART_RTS_CR);
  247. }
  248. }
  249. static void netx_break_ctl(struct uart_port *port, int break_state)
  250. {
  251. unsigned int line_cr;
  252. spin_lock_irq(&port->lock);
  253. line_cr = readl(port->membase + UART_LINE_CR);
  254. if (break_state != 0)
  255. line_cr |= LINE_CR_BRK;
  256. else
  257. line_cr &= ~LINE_CR_BRK;
  258. writel(line_cr, port->membase + UART_LINE_CR);
  259. spin_unlock_irq(&port->lock);
  260. }
  261. static int netx_startup(struct uart_port *port)
  262. {
  263. int ret;
  264. ret = request_irq(port->irq, netx_int, 0,
  265. DRIVER_NAME, port);
  266. if (ret) {
  267. dev_err(port->dev, "unable to grab irq%d\n",port->irq);
  268. goto exit;
  269. }
  270. writel(readl(port->membase + UART_LINE_CR) | LINE_CR_FEN,
  271. port->membase + UART_LINE_CR);
  272. writel(CR_MSIE | CR_RIE | CR_TIE | CR_RTIE | CR_UART_EN,
  273. port->membase + UART_CR);
  274. exit:
  275. return ret;
  276. }
  277. static void netx_shutdown(struct uart_port *port)
  278. {
  279. writel(0, port->membase + UART_CR) ;
  280. free_irq(port->irq, port);
  281. }
  282. static void
  283. netx_set_termios(struct uart_port *port, struct ktermios *termios,
  284. struct ktermios *old)
  285. {
  286. unsigned int baud, quot;
  287. unsigned char old_cr;
  288. unsigned char line_cr = LINE_CR_FEN;
  289. unsigned char rts_cr = 0;
  290. switch (termios->c_cflag & CSIZE) {
  291. case CS5:
  292. line_cr |= LINE_CR_5BIT;
  293. break;
  294. case CS6:
  295. line_cr |= LINE_CR_6BIT;
  296. break;
  297. case CS7:
  298. line_cr |= LINE_CR_7BIT;
  299. break;
  300. case CS8:
  301. line_cr |= LINE_CR_8BIT;
  302. break;
  303. }
  304. if (termios->c_cflag & CSTOPB)
  305. line_cr |= LINE_CR_STP2;
  306. if (termios->c_cflag & PARENB) {
  307. line_cr |= LINE_CR_PEN;
  308. if (!(termios->c_cflag & PARODD))
  309. line_cr |= LINE_CR_EPS;
  310. }
  311. if (termios->c_cflag & CRTSCTS)
  312. rts_cr = RTS_CR_AUTO | RTS_CR_CTS_CTR | RTS_CR_RTS_POL;
  313. baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
  314. quot = baud * 4096;
  315. quot /= 1000;
  316. quot *= 256;
  317. quot /= 100000;
  318. spin_lock_irq(&port->lock);
  319. uart_update_timeout(port, termios->c_cflag, baud);
  320. old_cr = readl(port->membase + UART_CR);
  321. /* disable interrupts */
  322. writel(old_cr & ~(CR_MSIE | CR_RIE | CR_TIE | CR_RTIE),
  323. port->membase + UART_CR);
  324. /* drain transmitter */
  325. while (readl(port->membase + UART_FR) & FR_BUSY);
  326. /* disable UART */
  327. writel(old_cr & ~CR_UART_EN, port->membase + UART_CR);
  328. /* modem status interrupts */
  329. old_cr &= ~CR_MSIE;
  330. if (UART_ENABLE_MS(port, termios->c_cflag))
  331. old_cr |= CR_MSIE;
  332. writel((quot>>8) & 0xff, port->membase + UART_BAUDDIV_MSB);
  333. writel(quot & 0xff, port->membase + UART_BAUDDIV_LSB);
  334. writel(line_cr, port->membase + UART_LINE_CR);
  335. writel(rts_cr, port->membase + UART_RTS_CR);
  336. /*
  337. * Characters to ignore
  338. */
  339. port->ignore_status_mask = 0;
  340. if (termios->c_iflag & IGNPAR)
  341. port->ignore_status_mask |= SR_PE;
  342. if (termios->c_iflag & IGNBRK) {
  343. port->ignore_status_mask |= SR_BE;
  344. /*
  345. * If we're ignoring parity and break indicators,
  346. * ignore overruns too (for real raw support).
  347. */
  348. if (termios->c_iflag & IGNPAR)
  349. port->ignore_status_mask |= SR_PE;
  350. }
  351. port->read_status_mask = 0;
  352. if (termios->c_iflag & (BRKINT | PARMRK))
  353. port->read_status_mask |= SR_BE;
  354. if (termios->c_iflag & INPCK)
  355. port->read_status_mask |= SR_PE | SR_FE;
  356. writel(old_cr, port->membase + UART_CR);
  357. spin_unlock_irq(&port->lock);
  358. }
  359. static const char *netx_type(struct uart_port *port)
  360. {
  361. return port->type == PORT_NETX ? "NETX" : NULL;
  362. }
  363. static void netx_release_port(struct uart_port *port)
  364. {
  365. release_mem_region(port->mapbase, UART_PORT_SIZE);
  366. }
  367. static int netx_request_port(struct uart_port *port)
  368. {
  369. return request_mem_region(port->mapbase, UART_PORT_SIZE,
  370. DRIVER_NAME) != NULL ? 0 : -EBUSY;
  371. }
  372. static void netx_config_port(struct uart_port *port, int flags)
  373. {
  374. if (flags & UART_CONFIG_TYPE && netx_request_port(port) == 0)
  375. port->type = PORT_NETX;
  376. }
  377. static int
  378. netx_verify_port(struct uart_port *port, struct serial_struct *ser)
  379. {
  380. int ret = 0;
  381. if (ser->type != PORT_UNKNOWN && ser->type != PORT_NETX)
  382. ret = -EINVAL;
  383. return ret;
  384. }
  385. static struct uart_ops netx_pops = {
  386. .tx_empty = netx_tx_empty,
  387. .set_mctrl = netx_set_mctrl,
  388. .get_mctrl = netx_get_mctrl,
  389. .stop_tx = netx_stop_tx,
  390. .start_tx = netx_start_tx,
  391. .stop_rx = netx_stop_rx,
  392. .enable_ms = netx_enable_ms,
  393. .break_ctl = netx_break_ctl,
  394. .startup = netx_startup,
  395. .shutdown = netx_shutdown,
  396. .set_termios = netx_set_termios,
  397. .type = netx_type,
  398. .release_port = netx_release_port,
  399. .request_port = netx_request_port,
  400. .config_port = netx_config_port,
  401. .verify_port = netx_verify_port,
  402. };
  403. static struct netx_port netx_ports[] = {
  404. {
  405. .port = {
  406. .type = PORT_NETX,
  407. .iotype = UPIO_MEM,
  408. .membase = (char __iomem *)io_p2v(NETX_PA_UART0),
  409. .mapbase = NETX_PA_UART0,
  410. .irq = NETX_IRQ_UART0,
  411. .uartclk = 100000000,
  412. .fifosize = 16,
  413. .flags = UPF_BOOT_AUTOCONF,
  414. .ops = &netx_pops,
  415. .line = 0,
  416. },
  417. }, {
  418. .port = {
  419. .type = PORT_NETX,
  420. .iotype = UPIO_MEM,
  421. .membase = (char __iomem *)io_p2v(NETX_PA_UART1),
  422. .mapbase = NETX_PA_UART1,
  423. .irq = NETX_IRQ_UART1,
  424. .uartclk = 100000000,
  425. .fifosize = 16,
  426. .flags = UPF_BOOT_AUTOCONF,
  427. .ops = &netx_pops,
  428. .line = 1,
  429. },
  430. }, {
  431. .port = {
  432. .type = PORT_NETX,
  433. .iotype = UPIO_MEM,
  434. .membase = (char __iomem *)io_p2v(NETX_PA_UART2),
  435. .mapbase = NETX_PA_UART2,
  436. .irq = NETX_IRQ_UART2,
  437. .uartclk = 100000000,
  438. .fifosize = 16,
  439. .flags = UPF_BOOT_AUTOCONF,
  440. .ops = &netx_pops,
  441. .line = 2,
  442. },
  443. }
  444. };
  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);