sc26xx.c 16 KB

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