sc26xx.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. /*
  2. * SC268xx.c: Serial driver for Philiphs SC2681/SC2692 devices.
  3. *
  4. * Copyright (C) 2006,2007 Thomas Bogendörfer (tsbogend@alpha.franken.de)
  5. */
  6. #include <linux/module.h>
  7. #include <linux/kernel.h>
  8. #include <linux/errno.h>
  9. #include <linux/tty.h>
  10. #include <linux/tty_flip.h>
  11. #include <linux/major.h>
  12. #include <linux/circ_buf.h>
  13. #include <linux/serial.h>
  14. #include <linux/sysrq.h>
  15. #include <linux/console.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/slab.h>
  18. #include <linux/delay.h>
  19. #include <linux/init.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/irq.h>
  22. #include <linux/io.h>
  23. #if defined(CONFIG_MAGIC_SYSRQ)
  24. #define SUPPORT_SYSRQ
  25. #endif
  26. #include <linux/serial_core.h>
  27. #define SC26XX_MAJOR 204
  28. #define SC26XX_MINOR_START 205
  29. #define SC26XX_NR 2
  30. struct uart_sc26xx_port {
  31. struct uart_port port[2];
  32. u8 dsr_mask[2];
  33. u8 cts_mask[2];
  34. u8 dcd_mask[2];
  35. u8 ri_mask[2];
  36. u8 dtr_mask[2];
  37. u8 rts_mask[2];
  38. u8 imr;
  39. };
  40. /* register common to both ports */
  41. #define RD_ISR 0x14
  42. #define RD_IPR 0x34
  43. #define WR_ACR 0x10
  44. #define WR_IMR 0x14
  45. #define WR_OPCR 0x34
  46. #define WR_OPR_SET 0x38
  47. #define WR_OPR_CLR 0x3C
  48. /* access common register */
  49. #define READ_SC(p, r) readb((p)->membase + RD_##r)
  50. #define WRITE_SC(p, r, v) writeb((v), (p)->membase + WR_##r)
  51. /* register per port */
  52. #define RD_PORT_MRx 0x00
  53. #define RD_PORT_SR 0x04
  54. #define RD_PORT_RHR 0x0c
  55. #define WR_PORT_MRx 0x00
  56. #define WR_PORT_CSR 0x04
  57. #define WR_PORT_CR 0x08
  58. #define WR_PORT_THR 0x0c
  59. /* SR bits */
  60. #define SR_BREAK (1 << 7)
  61. #define SR_FRAME (1 << 6)
  62. #define SR_PARITY (1 << 5)
  63. #define SR_OVERRUN (1 << 4)
  64. #define SR_TXRDY (1 << 2)
  65. #define SR_RXRDY (1 << 0)
  66. #define CR_RES_MR (1 << 4)
  67. #define CR_RES_RX (2 << 4)
  68. #define CR_RES_TX (3 << 4)
  69. #define CR_STRT_BRK (6 << 4)
  70. #define CR_STOP_BRK (7 << 4)
  71. #define CR_DIS_TX (1 << 3)
  72. #define CR_ENA_TX (1 << 2)
  73. #define CR_DIS_RX (1 << 1)
  74. #define CR_ENA_RX (1 << 0)
  75. /* ISR bits */
  76. #define ISR_RXRDYB (1 << 5)
  77. #define ISR_TXRDYB (1 << 4)
  78. #define ISR_RXRDYA (1 << 1)
  79. #define ISR_TXRDYA (1 << 0)
  80. /* IMR bits */
  81. #define IMR_RXRDY (1 << 1)
  82. #define IMR_TXRDY (1 << 0)
  83. /* access port register */
  84. static inline u8 read_sc_port(struct uart_port *p, u8 reg)
  85. {
  86. return readb(p->membase + p->line * 0x20 + reg);
  87. }
  88. static inline void write_sc_port(struct uart_port *p, u8 reg, u8 val)
  89. {
  90. writeb(val, p->membase + p->line * 0x20 + reg);
  91. }
  92. #define READ_SC_PORT(p, r) read_sc_port(p, RD_PORT_##r)
  93. #define WRITE_SC_PORT(p, r, v) write_sc_port(p, WR_PORT_##r, v)
  94. static void sc26xx_enable_irq(struct uart_port *port, int mask)
  95. {
  96. struct uart_sc26xx_port *up;
  97. int line = port->line;
  98. port -= line;
  99. up = container_of(port, struct uart_sc26xx_port, port[0]);
  100. up->imr |= mask << (line * 4);
  101. WRITE_SC(port, IMR, up->imr);
  102. }
  103. static void sc26xx_disable_irq(struct uart_port *port, int mask)
  104. {
  105. struct uart_sc26xx_port *up;
  106. int line = port->line;
  107. port -= line;
  108. up = container_of(port, struct uart_sc26xx_port, port[0]);
  109. up->imr &= ~(mask << (line * 4));
  110. WRITE_SC(port, IMR, up->imr);
  111. }
  112. static struct tty_struct *receive_chars(struct uart_port *port)
  113. {
  114. struct tty_struct *tty = NULL;
  115. int limit = 10000;
  116. unsigned char ch;
  117. char flag;
  118. u8 status;
  119. if (port->state != NULL) /* Unopened serial console */
  120. tty = port->state->port.tty;
  121. while (limit-- > 0) {
  122. status = READ_SC_PORT(port, SR);
  123. if (!(status & SR_RXRDY))
  124. break;
  125. ch = READ_SC_PORT(port, RHR);
  126. flag = TTY_NORMAL;
  127. port->icount.rx++;
  128. if (unlikely(status & (SR_BREAK | SR_FRAME |
  129. SR_PARITY | SR_OVERRUN))) {
  130. if (status & SR_BREAK) {
  131. status &= ~(SR_PARITY | SR_FRAME);
  132. port->icount.brk++;
  133. if (uart_handle_break(port))
  134. continue;
  135. } else if (status & SR_PARITY)
  136. port->icount.parity++;
  137. else if (status & SR_FRAME)
  138. port->icount.frame++;
  139. if (status & SR_OVERRUN)
  140. port->icount.overrun++;
  141. status &= port->read_status_mask;
  142. if (status & SR_BREAK)
  143. flag = TTY_BREAK;
  144. else if (status & SR_PARITY)
  145. flag = TTY_PARITY;
  146. else if (status & SR_FRAME)
  147. flag = TTY_FRAME;
  148. }
  149. if (uart_handle_sysrq_char(port, ch))
  150. continue;
  151. if (status & port->ignore_status_mask)
  152. continue;
  153. tty_insert_flip_char(tty, ch, flag);
  154. }
  155. return tty;
  156. }
  157. static void transmit_chars(struct uart_port *port)
  158. {
  159. struct circ_buf *xmit;
  160. if (!port->state)
  161. return;
  162. xmit = &port->state->xmit;
  163. if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
  164. sc26xx_disable_irq(port, IMR_TXRDY);
  165. return;
  166. }
  167. while (!uart_circ_empty(xmit)) {
  168. if (!(READ_SC_PORT(port, SR) & SR_TXRDY))
  169. break;
  170. WRITE_SC_PORT(port, THR, xmit->buf[xmit->tail]);
  171. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  172. port->icount.tx++;
  173. }
  174. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  175. uart_write_wakeup(port);
  176. }
  177. static irqreturn_t sc26xx_interrupt(int irq, void *dev_id)
  178. {
  179. struct uart_sc26xx_port *up = dev_id;
  180. struct tty_struct *tty;
  181. unsigned long flags;
  182. u8 isr;
  183. spin_lock_irqsave(&up->port[0].lock, flags);
  184. tty = NULL;
  185. isr = READ_SC(&up->port[0], ISR);
  186. if (isr & ISR_TXRDYA)
  187. transmit_chars(&up->port[0]);
  188. if (isr & ISR_RXRDYA)
  189. tty = receive_chars(&up->port[0]);
  190. spin_unlock(&up->port[0].lock);
  191. if (tty)
  192. tty_flip_buffer_push(tty);
  193. spin_lock(&up->port[1].lock);
  194. tty = NULL;
  195. if (isr & ISR_TXRDYB)
  196. transmit_chars(&up->port[1]);
  197. if (isr & ISR_RXRDYB)
  198. tty = receive_chars(&up->port[1]);
  199. spin_unlock_irqrestore(&up->port[1].lock, flags);
  200. if (tty)
  201. tty_flip_buffer_push(tty);
  202. return IRQ_HANDLED;
  203. }
  204. /* port->lock is not held. */
  205. static unsigned int sc26xx_tx_empty(struct uart_port *port)
  206. {
  207. return (READ_SC_PORT(port, SR) & SR_TXRDY) ? TIOCSER_TEMT : 0;
  208. }
  209. /* port->lock held by caller. */
  210. static void sc26xx_set_mctrl(struct uart_port *port, unsigned int mctrl)
  211. {
  212. struct uart_sc26xx_port *up;
  213. int line = port->line;
  214. port -= line;
  215. up = container_of(port, struct uart_sc26xx_port, port[0]);
  216. if (up->dtr_mask[line]) {
  217. if (mctrl & TIOCM_DTR)
  218. WRITE_SC(port, OPR_SET, up->dtr_mask[line]);
  219. else
  220. WRITE_SC(port, OPR_CLR, up->dtr_mask[line]);
  221. }
  222. if (up->rts_mask[line]) {
  223. if (mctrl & TIOCM_RTS)
  224. WRITE_SC(port, OPR_SET, up->rts_mask[line]);
  225. else
  226. WRITE_SC(port, OPR_CLR, up->rts_mask[line]);
  227. }
  228. }
  229. /* port->lock is held by caller and interrupts are disabled. */
  230. static unsigned int sc26xx_get_mctrl(struct uart_port *port)
  231. {
  232. struct uart_sc26xx_port *up;
  233. int line = port->line;
  234. unsigned int mctrl = TIOCM_DSR | TIOCM_CTS | TIOCM_CAR;
  235. u8 ipr;
  236. port -= line;
  237. up = container_of(port, struct uart_sc26xx_port, port[0]);
  238. ipr = READ_SC(port, IPR) ^ 0xff;
  239. if (up->dsr_mask[line]) {
  240. mctrl &= ~TIOCM_DSR;
  241. mctrl |= ipr & up->dsr_mask[line] ? TIOCM_DSR : 0;
  242. }
  243. if (up->cts_mask[line]) {
  244. mctrl &= ~TIOCM_CTS;
  245. mctrl |= ipr & up->cts_mask[line] ? TIOCM_CTS : 0;
  246. }
  247. if (up->dcd_mask[line]) {
  248. mctrl &= ~TIOCM_CAR;
  249. mctrl |= ipr & up->dcd_mask[line] ? TIOCM_CAR : 0;
  250. }
  251. if (up->ri_mask[line]) {
  252. mctrl &= ~TIOCM_RNG;
  253. mctrl |= ipr & up->ri_mask[line] ? TIOCM_RNG : 0;
  254. }
  255. return mctrl;
  256. }
  257. /* port->lock held by caller. */
  258. static void sc26xx_stop_tx(struct uart_port *port)
  259. {
  260. return;
  261. }
  262. /* port->lock held by caller. */
  263. static void sc26xx_start_tx(struct uart_port *port)
  264. {
  265. struct circ_buf *xmit = &port->state->xmit;
  266. while (!uart_circ_empty(xmit)) {
  267. if (!(READ_SC_PORT(port, SR) & SR_TXRDY)) {
  268. sc26xx_enable_irq(port, IMR_TXRDY);
  269. break;
  270. }
  271. WRITE_SC_PORT(port, THR, xmit->buf[xmit->tail]);
  272. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  273. port->icount.tx++;
  274. }
  275. }
  276. /* port->lock held by caller. */
  277. static void sc26xx_stop_rx(struct uart_port *port)
  278. {
  279. }
  280. /* port->lock held by caller. */
  281. static void sc26xx_enable_ms(struct uart_port *port)
  282. {
  283. }
  284. /* port->lock is not held. */
  285. static void sc26xx_break_ctl(struct uart_port *port, int break_state)
  286. {
  287. if (break_state == -1)
  288. WRITE_SC_PORT(port, CR, CR_STRT_BRK);
  289. else
  290. WRITE_SC_PORT(port, CR, CR_STOP_BRK);
  291. }
  292. /* port->lock is not held. */
  293. static int sc26xx_startup(struct uart_port *port)
  294. {
  295. sc26xx_disable_irq(port, IMR_TXRDY | IMR_RXRDY);
  296. WRITE_SC(port, OPCR, 0);
  297. /* reset tx and rx */
  298. WRITE_SC_PORT(port, CR, CR_RES_RX);
  299. WRITE_SC_PORT(port, CR, CR_RES_TX);
  300. /* start rx/tx */
  301. WRITE_SC_PORT(port, CR, CR_ENA_TX | CR_ENA_RX);
  302. /* enable irqs */
  303. sc26xx_enable_irq(port, IMR_RXRDY);
  304. return 0;
  305. }
  306. /* port->lock is not held. */
  307. static void sc26xx_shutdown(struct uart_port *port)
  308. {
  309. /* disable interrupst */
  310. sc26xx_disable_irq(port, IMR_TXRDY | IMR_RXRDY);
  311. /* stop tx/rx */
  312. WRITE_SC_PORT(port, CR, CR_DIS_TX | CR_DIS_RX);
  313. }
  314. /* port->lock is not held. */
  315. static void sc26xx_set_termios(struct uart_port *port, struct ktermios *termios,
  316. struct ktermios *old)
  317. {
  318. unsigned int baud = uart_get_baud_rate(port, termios, old, 0, 4000000);
  319. unsigned int quot = uart_get_divisor(port, baud);
  320. unsigned int iflag, cflag;
  321. unsigned long flags;
  322. u8 mr1, mr2, csr;
  323. spin_lock_irqsave(&port->lock, flags);
  324. while ((READ_SC_PORT(port, SR) & ((1 << 3) | (1 << 2))) != 0xc)
  325. udelay(2);
  326. WRITE_SC_PORT(port, CR, CR_DIS_TX | CR_DIS_RX);
  327. iflag = termios->c_iflag;
  328. cflag = termios->c_cflag;
  329. port->read_status_mask = SR_OVERRUN;
  330. if (iflag & INPCK)
  331. port->read_status_mask |= SR_PARITY | SR_FRAME;
  332. if (iflag & (BRKINT | PARMRK))
  333. port->read_status_mask |= SR_BREAK;
  334. port->ignore_status_mask = 0;
  335. if (iflag & IGNBRK)
  336. port->ignore_status_mask |= SR_BREAK;
  337. if ((cflag & CREAD) == 0)
  338. port->ignore_status_mask |= SR_BREAK | SR_FRAME |
  339. SR_PARITY | SR_OVERRUN;
  340. switch (cflag & CSIZE) {
  341. case CS5:
  342. mr1 = 0x00;
  343. break;
  344. case CS6:
  345. mr1 = 0x01;
  346. break;
  347. case CS7:
  348. mr1 = 0x02;
  349. break;
  350. default:
  351. case CS8:
  352. mr1 = 0x03;
  353. break;
  354. }
  355. mr2 = 0x07;
  356. if (cflag & CSTOPB)
  357. mr2 = 0x0f;
  358. if (cflag & PARENB) {
  359. if (cflag & PARODD)
  360. mr1 |= (1 << 2);
  361. } else
  362. mr1 |= (2 << 3);
  363. switch (baud) {
  364. case 50:
  365. csr = 0x00;
  366. break;
  367. case 110:
  368. csr = 0x11;
  369. break;
  370. case 134:
  371. csr = 0x22;
  372. break;
  373. case 200:
  374. csr = 0x33;
  375. break;
  376. case 300:
  377. csr = 0x44;
  378. break;
  379. case 600:
  380. csr = 0x55;
  381. break;
  382. case 1200:
  383. csr = 0x66;
  384. break;
  385. case 2400:
  386. csr = 0x88;
  387. break;
  388. case 4800:
  389. csr = 0x99;
  390. break;
  391. default:
  392. case 9600:
  393. csr = 0xbb;
  394. break;
  395. case 19200:
  396. csr = 0xcc;
  397. break;
  398. }
  399. WRITE_SC_PORT(port, CR, CR_RES_MR);
  400. WRITE_SC_PORT(port, MRx, mr1);
  401. WRITE_SC_PORT(port, MRx, mr2);
  402. WRITE_SC(port, ACR, 0x80);
  403. WRITE_SC_PORT(port, CSR, csr);
  404. /* reset tx and rx */
  405. WRITE_SC_PORT(port, CR, CR_RES_RX);
  406. WRITE_SC_PORT(port, CR, CR_RES_TX);
  407. WRITE_SC_PORT(port, CR, CR_ENA_TX | CR_ENA_RX);
  408. while ((READ_SC_PORT(port, SR) & ((1 << 3) | (1 << 2))) != 0xc)
  409. udelay(2);
  410. /* XXX */
  411. uart_update_timeout(port, cflag,
  412. (port->uartclk / (16 * quot)));
  413. spin_unlock_irqrestore(&port->lock, flags);
  414. }
  415. static const char *sc26xx_type(struct uart_port *port)
  416. {
  417. return "SC26XX";
  418. }
  419. static void sc26xx_release_port(struct uart_port *port)
  420. {
  421. }
  422. static int sc26xx_request_port(struct uart_port *port)
  423. {
  424. return 0;
  425. }
  426. static void sc26xx_config_port(struct uart_port *port, int flags)
  427. {
  428. }
  429. static int sc26xx_verify_port(struct uart_port *port, struct serial_struct *ser)
  430. {
  431. return -EINVAL;
  432. }
  433. static struct uart_ops sc26xx_ops = {
  434. .tx_empty = sc26xx_tx_empty,
  435. .set_mctrl = sc26xx_set_mctrl,
  436. .get_mctrl = sc26xx_get_mctrl,
  437. .stop_tx = sc26xx_stop_tx,
  438. .start_tx = sc26xx_start_tx,
  439. .stop_rx = sc26xx_stop_rx,
  440. .enable_ms = sc26xx_enable_ms,
  441. .break_ctl = sc26xx_break_ctl,
  442. .startup = sc26xx_startup,
  443. .shutdown = sc26xx_shutdown,
  444. .set_termios = sc26xx_set_termios,
  445. .type = sc26xx_type,
  446. .release_port = sc26xx_release_port,
  447. .request_port = sc26xx_request_port,
  448. .config_port = sc26xx_config_port,
  449. .verify_port = sc26xx_verify_port,
  450. };
  451. static struct uart_port *sc26xx_port;
  452. #ifdef CONFIG_SERIAL_SC26XX_CONSOLE
  453. static void sc26xx_console_putchar(struct uart_port *port, char c)
  454. {
  455. unsigned long flags;
  456. int limit = 1000000;
  457. spin_lock_irqsave(&port->lock, flags);
  458. while (limit-- > 0) {
  459. if (READ_SC_PORT(port, SR) & SR_TXRDY) {
  460. WRITE_SC_PORT(port, THR, c);
  461. break;
  462. }
  463. udelay(2);
  464. }
  465. spin_unlock_irqrestore(&port->lock, flags);
  466. }
  467. static void sc26xx_console_write(struct console *con, const char *s, unsigned n)
  468. {
  469. struct uart_port *port = sc26xx_port;
  470. int i;
  471. for (i = 0; i < n; i++) {
  472. if (*s == '\n')
  473. sc26xx_console_putchar(port, '\r');
  474. sc26xx_console_putchar(port, *s++);
  475. }
  476. }
  477. static int __init sc26xx_console_setup(struct console *con, char *options)
  478. {
  479. struct uart_port *port = sc26xx_port;
  480. int baud = 9600;
  481. int bits = 8;
  482. int parity = 'n';
  483. int flow = 'n';
  484. if (port->type != PORT_SC26XX)
  485. return -1;
  486. printk(KERN_INFO "Console: ttySC%d (SC26XX)\n", con->index);
  487. if (options)
  488. uart_parse_options(options, &baud, &parity, &bits, &flow);
  489. return uart_set_options(port, con, baud, parity, bits, flow);
  490. }
  491. static struct uart_driver sc26xx_reg;
  492. static struct console sc26xx_console = {
  493. .name = "ttySC",
  494. .write = sc26xx_console_write,
  495. .device = uart_console_device,
  496. .setup = sc26xx_console_setup,
  497. .flags = CON_PRINTBUFFER,
  498. .index = -1,
  499. .data = &sc26xx_reg,
  500. };
  501. #define SC26XX_CONSOLE &sc26xx_console
  502. #else
  503. #define SC26XX_CONSOLE NULL
  504. #endif
  505. static struct uart_driver sc26xx_reg = {
  506. .owner = THIS_MODULE,
  507. .driver_name = "SC26xx",
  508. .dev_name = "ttySC",
  509. .major = SC26XX_MAJOR,
  510. .minor = SC26XX_MINOR_START,
  511. .nr = SC26XX_NR,
  512. .cons = SC26XX_CONSOLE,
  513. };
  514. static u8 sc26xx_flags2mask(unsigned int flags, unsigned int bitpos)
  515. {
  516. unsigned int bit = (flags >> bitpos) & 15;
  517. return bit ? (1 << (bit - 1)) : 0;
  518. }
  519. static void __devinit sc26xx_init_masks(struct uart_sc26xx_port *up,
  520. int line, unsigned int data)
  521. {
  522. up->dtr_mask[line] = sc26xx_flags2mask(data, 0);
  523. up->rts_mask[line] = sc26xx_flags2mask(data, 4);
  524. up->dsr_mask[line] = sc26xx_flags2mask(data, 8);
  525. up->cts_mask[line] = sc26xx_flags2mask(data, 12);
  526. up->dcd_mask[line] = sc26xx_flags2mask(data, 16);
  527. up->ri_mask[line] = sc26xx_flags2mask(data, 20);
  528. }
  529. static int __devinit sc26xx_probe(struct platform_device *dev)
  530. {
  531. struct resource *res;
  532. struct uart_sc26xx_port *up;
  533. unsigned int *sc26xx_data = dev->dev.platform_data;
  534. int err;
  535. res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  536. if (!res)
  537. return -ENODEV;
  538. up = kzalloc(sizeof *up, GFP_KERNEL);
  539. if (unlikely(!up))
  540. return -ENOMEM;
  541. up->port[0].line = 0;
  542. up->port[0].ops = &sc26xx_ops;
  543. up->port[0].type = PORT_SC26XX;
  544. up->port[0].uartclk = (29491200 / 16); /* arbitrary */
  545. up->port[0].mapbase = res->start;
  546. up->port[0].membase = ioremap_nocache(up->port[0].mapbase, 0x40);
  547. up->port[0].iotype = UPIO_MEM;
  548. up->port[0].irq = platform_get_irq(dev, 0);
  549. up->port[0].dev = &dev->dev;
  550. sc26xx_init_masks(up, 0, sc26xx_data[0]);
  551. sc26xx_port = &up->port[0];
  552. up->port[1].line = 1;
  553. up->port[1].ops = &sc26xx_ops;
  554. up->port[1].type = PORT_SC26XX;
  555. up->port[1].uartclk = (29491200 / 16); /* arbitrary */
  556. up->port[1].mapbase = up->port[0].mapbase;
  557. up->port[1].membase = up->port[0].membase;
  558. up->port[1].iotype = UPIO_MEM;
  559. up->port[1].irq = up->port[0].irq;
  560. up->port[1].dev = &dev->dev;
  561. sc26xx_init_masks(up, 1, sc26xx_data[1]);
  562. err = uart_register_driver(&sc26xx_reg);
  563. if (err)
  564. goto out_free_port;
  565. sc26xx_reg.tty_driver->name_base = sc26xx_reg.minor;
  566. err = uart_add_one_port(&sc26xx_reg, &up->port[0]);
  567. if (err)
  568. goto out_unregister_driver;
  569. err = uart_add_one_port(&sc26xx_reg, &up->port[1]);
  570. if (err)
  571. goto out_remove_port0;
  572. err = request_irq(up->port[0].irq, sc26xx_interrupt, 0, "sc26xx", up);
  573. if (err)
  574. goto out_remove_ports;
  575. dev_set_drvdata(&dev->dev, up);
  576. return 0;
  577. out_remove_ports:
  578. uart_remove_one_port(&sc26xx_reg, &up->port[1]);
  579. out_remove_port0:
  580. uart_remove_one_port(&sc26xx_reg, &up->port[0]);
  581. out_unregister_driver:
  582. uart_unregister_driver(&sc26xx_reg);
  583. out_free_port:
  584. kfree(up);
  585. sc26xx_port = NULL;
  586. return err;
  587. }
  588. static int __exit sc26xx_driver_remove(struct platform_device *dev)
  589. {
  590. struct uart_sc26xx_port *up = dev_get_drvdata(&dev->dev);
  591. free_irq(up->port[0].irq, up);
  592. uart_remove_one_port(&sc26xx_reg, &up->port[0]);
  593. uart_remove_one_port(&sc26xx_reg, &up->port[1]);
  594. uart_unregister_driver(&sc26xx_reg);
  595. kfree(up);
  596. sc26xx_port = NULL;
  597. dev_set_drvdata(&dev->dev, NULL);
  598. return 0;
  599. }
  600. static struct platform_driver sc26xx_driver = {
  601. .probe = sc26xx_probe,
  602. .remove = __devexit_p(sc26xx_driver_remove),
  603. .driver = {
  604. .name = "SC26xx",
  605. .owner = THIS_MODULE,
  606. },
  607. };
  608. module_platform_driver(sc26xx_driver);
  609. MODULE_AUTHOR("Thomas Bogendörfer");
  610. MODULE_DESCRIPTION("SC681/SC2692 serial driver");
  611. MODULE_VERSION("1.0");
  612. MODULE_LICENSE("GPL");
  613. MODULE_ALIAS("platform:SC26xx");