sc26xx.c 16 KB

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