sc26xx.c 16 KB

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