sh-sci.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  1. /*
  2. * drivers/serial/sh-sci.c
  3. *
  4. * SuperH on-chip serial module support. (SCI with no FIFO / with FIFO)
  5. *
  6. * Copyright (C) 2002 - 2008 Paul Mundt
  7. * Modified to support SH7720 SCIF. Markus Brunner, Mark Jonas (Jul 2007).
  8. *
  9. * based off of the old drivers/char/sh-sci.c by:
  10. *
  11. * Copyright (C) 1999, 2000 Niibe Yutaka
  12. * Copyright (C) 2000 Sugioka Toshinobu
  13. * Modified to support multiple serial ports. Stuart Menefy (May 2000).
  14. * Modified to support SecureEdge. David McCullough (2002)
  15. * Modified to support SH7300 SCIF. Takashi Kusuda (Jun 2003).
  16. * Removed SH7300 support (Jul 2007).
  17. *
  18. * This file is subject to the terms and conditions of the GNU General Public
  19. * License. See the file "COPYING" in the main directory of this archive
  20. * for more details.
  21. */
  22. #if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  23. #define SUPPORT_SYSRQ
  24. #endif
  25. #undef DEBUG
  26. #include <linux/module.h>
  27. #include <linux/errno.h>
  28. #include <linux/timer.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/tty.h>
  31. #include <linux/tty_flip.h>
  32. #include <linux/serial.h>
  33. #include <linux/major.h>
  34. #include <linux/string.h>
  35. #include <linux/sysrq.h>
  36. #include <linux/ioport.h>
  37. #include <linux/mm.h>
  38. #include <linux/init.h>
  39. #include <linux/delay.h>
  40. #include <linux/console.h>
  41. #include <linux/platform_device.h>
  42. #include <linux/serial_sci.h>
  43. #include <linux/notifier.h>
  44. #include <linux/cpufreq.h>
  45. #include <linux/clk.h>
  46. #include <linux/ctype.h>
  47. #include <linux/err.h>
  48. #ifdef CONFIG_SUPERH
  49. #include <asm/clock.h>
  50. #include <asm/sh_bios.h>
  51. #endif
  52. #include "sh-sci.h"
  53. struct sci_port {
  54. struct uart_port port;
  55. /* Port type */
  56. unsigned int type;
  57. /* Port IRQs: ERI, RXI, TXI, BRI (optional) */
  58. unsigned int irqs[SCIx_NR_IRQS];
  59. /* Port enable callback */
  60. void (*enable)(struct uart_port *port);
  61. /* Port disable callback */
  62. void (*disable)(struct uart_port *port);
  63. /* Break timer */
  64. struct timer_list break_timer;
  65. int break_flag;
  66. #ifdef CONFIG_HAVE_CLK
  67. /* Port clock */
  68. struct clk *clk;
  69. #endif
  70. };
  71. #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
  72. static struct sci_port *serial_console_port;
  73. #endif
  74. /* Function prototypes */
  75. static void sci_stop_tx(struct uart_port *port);
  76. #define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS
  77. static struct sci_port sci_ports[SCI_NPORTS];
  78. static struct uart_driver sci_uart_driver;
  79. static inline struct sci_port *
  80. to_sci_port(struct uart_port *uart)
  81. {
  82. return container_of(uart, struct sci_port, port);
  83. }
  84. #if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_SH_SCI_CONSOLE)
  85. #ifdef CONFIG_CONSOLE_POLL
  86. static inline void handle_error(struct uart_port *port)
  87. {
  88. /* Clear error flags */
  89. sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
  90. }
  91. static int sci_poll_get_char(struct uart_port *port)
  92. {
  93. unsigned short status;
  94. int c;
  95. do {
  96. status = sci_in(port, SCxSR);
  97. if (status & SCxSR_ERRORS(port)) {
  98. handle_error(port);
  99. continue;
  100. }
  101. } while (!(status & SCxSR_RDxF(port)));
  102. c = sci_in(port, SCxRDR);
  103. /* Dummy read */
  104. sci_in(port, SCxSR);
  105. sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
  106. return c;
  107. }
  108. #endif
  109. static void sci_poll_put_char(struct uart_port *port, unsigned char c)
  110. {
  111. unsigned short status;
  112. do {
  113. status = sci_in(port, SCxSR);
  114. } while (!(status & SCxSR_TDxE(port)));
  115. sci_in(port, SCxSR); /* Dummy read */
  116. sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
  117. sci_out(port, SCxTDR, c);
  118. }
  119. #endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */
  120. #if defined(__H8300S__)
  121. enum { sci_disable, sci_enable };
  122. static void h8300_sci_config(struct uart_port *port, unsigned int ctrl)
  123. {
  124. volatile unsigned char *mstpcrl = (volatile unsigned char *)MSTPCRL;
  125. int ch = (port->mapbase - SMR0) >> 3;
  126. unsigned char mask = 1 << (ch+1);
  127. if (ctrl == sci_disable)
  128. *mstpcrl |= mask;
  129. else
  130. *mstpcrl &= ~mask;
  131. }
  132. static inline void h8300_sci_enable(struct uart_port *port)
  133. {
  134. h8300_sci_config(port, sci_enable);
  135. }
  136. static inline void h8300_sci_disable(struct uart_port *port)
  137. {
  138. h8300_sci_config(port, sci_disable);
  139. }
  140. #endif
  141. #if defined(__H8300H__) || defined(__H8300S__)
  142. static void sci_init_pins(struct uart_port *port, unsigned int cflag)
  143. {
  144. int ch = (port->mapbase - SMR0) >> 3;
  145. /* set DDR regs */
  146. H8300_GPIO_DDR(h8300_sci_pins[ch].port,
  147. h8300_sci_pins[ch].rx,
  148. H8300_GPIO_INPUT);
  149. H8300_GPIO_DDR(h8300_sci_pins[ch].port,
  150. h8300_sci_pins[ch].tx,
  151. H8300_GPIO_OUTPUT);
  152. /* tx mark output*/
  153. H8300_SCI_DR(ch) |= h8300_sci_pins[ch].tx;
  154. }
  155. #elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
  156. static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
  157. {
  158. if (port->mapbase == 0xA4400000) {
  159. __raw_writew(__raw_readw(PACR) & 0xffc0, PACR);
  160. __raw_writew(__raw_readw(PBCR) & 0x0fff, PBCR);
  161. } else if (port->mapbase == 0xA4410000)
  162. __raw_writew(__raw_readw(PBCR) & 0xf003, PBCR);
  163. }
  164. #elif defined(CONFIG_CPU_SUBTYPE_SH7720) || defined(CONFIG_CPU_SUBTYPE_SH7721)
  165. static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
  166. {
  167. unsigned short data;
  168. if (cflag & CRTSCTS) {
  169. /* enable RTS/CTS */
  170. if (port->mapbase == 0xa4430000) { /* SCIF0 */
  171. /* Clear PTCR bit 9-2; enable all scif pins but sck */
  172. data = __raw_readw(PORT_PTCR);
  173. __raw_writew((data & 0xfc03), PORT_PTCR);
  174. } else if (port->mapbase == 0xa4438000) { /* SCIF1 */
  175. /* Clear PVCR bit 9-2 */
  176. data = __raw_readw(PORT_PVCR);
  177. __raw_writew((data & 0xfc03), PORT_PVCR);
  178. }
  179. } else {
  180. if (port->mapbase == 0xa4430000) { /* SCIF0 */
  181. /* Clear PTCR bit 5-2; enable only tx and rx */
  182. data = __raw_readw(PORT_PTCR);
  183. __raw_writew((data & 0xffc3), PORT_PTCR);
  184. } else if (port->mapbase == 0xa4438000) { /* SCIF1 */
  185. /* Clear PVCR bit 5-2 */
  186. data = __raw_readw(PORT_PVCR);
  187. __raw_writew((data & 0xffc3), PORT_PVCR);
  188. }
  189. }
  190. }
  191. #elif defined(CONFIG_CPU_SH3)
  192. /* For SH7705, SH7706, SH7707, SH7709, SH7709A, SH7729 */
  193. static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
  194. {
  195. unsigned short data;
  196. /* We need to set SCPCR to enable RTS/CTS */
  197. data = __raw_readw(SCPCR);
  198. /* Clear out SCP7MD1,0, SCP6MD1,0, SCP4MD1,0*/
  199. __raw_writew(data & 0x0fcf, SCPCR);
  200. if (!(cflag & CRTSCTS)) {
  201. /* We need to set SCPCR to enable RTS/CTS */
  202. data = __raw_readw(SCPCR);
  203. /* Clear out SCP7MD1,0, SCP4MD1,0,
  204. Set SCP6MD1,0 = {01} (output) */
  205. __raw_writew((data & 0x0fcf) | 0x1000, SCPCR);
  206. data = ctrl_inb(SCPDR);
  207. /* Set /RTS2 (bit6) = 0 */
  208. ctrl_outb(data & 0xbf, SCPDR);
  209. }
  210. }
  211. #elif defined(CONFIG_CPU_SUBTYPE_SH7722)
  212. static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
  213. {
  214. unsigned short data;
  215. if (port->mapbase == 0xffe00000) {
  216. data = __raw_readw(PSCR);
  217. data &= ~0x03cf;
  218. if (!(cflag & CRTSCTS))
  219. data |= 0x0340;
  220. __raw_writew(data, PSCR);
  221. }
  222. }
  223. #elif defined(CONFIG_CPU_SUBTYPE_SH7763) || \
  224. defined(CONFIG_CPU_SUBTYPE_SH7780) || \
  225. defined(CONFIG_CPU_SUBTYPE_SH7785) || \
  226. defined(CONFIG_CPU_SUBTYPE_SHX3)
  227. static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
  228. {
  229. if (!(cflag & CRTSCTS))
  230. __raw_writew(0x0080, SCSPTR0); /* Set RTS = 1 */
  231. }
  232. #elif defined(CONFIG_CPU_SH4) && !defined(CONFIG_CPU_SH4A)
  233. static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
  234. {
  235. if (!(cflag & CRTSCTS))
  236. __raw_writew(0x0080, SCSPTR2); /* Set RTS = 1 */
  237. }
  238. #else
  239. static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
  240. {
  241. /* Nothing to do */
  242. }
  243. #endif
  244. #if defined(CONFIG_CPU_SUBTYPE_SH7760) || \
  245. defined(CONFIG_CPU_SUBTYPE_SH7780) || \
  246. defined(CONFIG_CPU_SUBTYPE_SH7785)
  247. static inline int scif_txroom(struct uart_port *port)
  248. {
  249. return SCIF_TXROOM_MAX - (sci_in(port, SCTFDR) & 0xff);
  250. }
  251. static inline int scif_rxroom(struct uart_port *port)
  252. {
  253. return sci_in(port, SCRFDR) & 0xff;
  254. }
  255. #elif defined(CONFIG_CPU_SUBTYPE_SH7763)
  256. static inline int scif_txroom(struct uart_port *port)
  257. {
  258. if ((port->mapbase == 0xffe00000) ||
  259. (port->mapbase == 0xffe08000)) {
  260. /* SCIF0/1*/
  261. return SCIF_TXROOM_MAX - (sci_in(port, SCTFDR) & 0xff);
  262. } else {
  263. /* SCIF2 */
  264. return SCIF2_TXROOM_MAX - (sci_in(port, SCFDR) >> 8);
  265. }
  266. }
  267. static inline int scif_rxroom(struct uart_port *port)
  268. {
  269. if ((port->mapbase == 0xffe00000) ||
  270. (port->mapbase == 0xffe08000)) {
  271. /* SCIF0/1*/
  272. return sci_in(port, SCRFDR) & 0xff;
  273. } else {
  274. /* SCIF2 */
  275. return sci_in(port, SCFDR) & SCIF2_RFDC_MASK;
  276. }
  277. }
  278. #else
  279. static inline int scif_txroom(struct uart_port *port)
  280. {
  281. return SCIF_TXROOM_MAX - (sci_in(port, SCFDR) >> 8);
  282. }
  283. static inline int scif_rxroom(struct uart_port *port)
  284. {
  285. return sci_in(port, SCFDR) & SCIF_RFDC_MASK;
  286. }
  287. #endif
  288. static inline int sci_txroom(struct uart_port *port)
  289. {
  290. return (sci_in(port, SCxSR) & SCI_TDRE) != 0;
  291. }
  292. static inline int sci_rxroom(struct uart_port *port)
  293. {
  294. return (sci_in(port, SCxSR) & SCxSR_RDxF(port)) != 0;
  295. }
  296. /* ********************************************************************** *
  297. * the interrupt related routines *
  298. * ********************************************************************** */
  299. static void sci_transmit_chars(struct uart_port *port)
  300. {
  301. struct circ_buf *xmit = &port->info->xmit;
  302. unsigned int stopped = uart_tx_stopped(port);
  303. unsigned short status;
  304. unsigned short ctrl;
  305. int count;
  306. status = sci_in(port, SCxSR);
  307. if (!(status & SCxSR_TDxE(port))) {
  308. ctrl = sci_in(port, SCSCR);
  309. if (uart_circ_empty(xmit))
  310. ctrl &= ~SCI_CTRL_FLAGS_TIE;
  311. else
  312. ctrl |= SCI_CTRL_FLAGS_TIE;
  313. sci_out(port, SCSCR, ctrl);
  314. return;
  315. }
  316. if (port->type == PORT_SCI)
  317. count = sci_txroom(port);
  318. else
  319. count = scif_txroom(port);
  320. do {
  321. unsigned char c;
  322. if (port->x_char) {
  323. c = port->x_char;
  324. port->x_char = 0;
  325. } else if (!uart_circ_empty(xmit) && !stopped) {
  326. c = xmit->buf[xmit->tail];
  327. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  328. } else {
  329. break;
  330. }
  331. sci_out(port, SCxTDR, c);
  332. port->icount.tx++;
  333. } while (--count > 0);
  334. sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
  335. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  336. uart_write_wakeup(port);
  337. if (uart_circ_empty(xmit)) {
  338. sci_stop_tx(port);
  339. } else {
  340. ctrl = sci_in(port, SCSCR);
  341. if (port->type != PORT_SCI) {
  342. sci_in(port, SCxSR); /* Dummy read */
  343. sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
  344. }
  345. ctrl |= SCI_CTRL_FLAGS_TIE;
  346. sci_out(port, SCSCR, ctrl);
  347. }
  348. }
  349. /* On SH3, SCIF may read end-of-break as a space->mark char */
  350. #define STEPFN(c) ({int __c = (c); (((__c-1)|(__c)) == -1); })
  351. static inline void sci_receive_chars(struct uart_port *port)
  352. {
  353. struct sci_port *sci_port = to_sci_port(port);
  354. struct tty_struct *tty = port->info->port.tty;
  355. int i, count, copied = 0;
  356. unsigned short status;
  357. unsigned char flag;
  358. status = sci_in(port, SCxSR);
  359. if (!(status & SCxSR_RDxF(port)))
  360. return;
  361. while (1) {
  362. if (port->type == PORT_SCI)
  363. count = sci_rxroom(port);
  364. else
  365. count = scif_rxroom(port);
  366. /* Don't copy more bytes than there is room for in the buffer */
  367. count = tty_buffer_request_room(tty, count);
  368. /* If for any reason we can't copy more data, we're done! */
  369. if (count == 0)
  370. break;
  371. if (port->type == PORT_SCI) {
  372. char c = sci_in(port, SCxRDR);
  373. if (uart_handle_sysrq_char(port, c) ||
  374. sci_port->break_flag)
  375. count = 0;
  376. else
  377. tty_insert_flip_char(tty, c, TTY_NORMAL);
  378. } else {
  379. for (i = 0; i < count; i++) {
  380. char c = sci_in(port, SCxRDR);
  381. status = sci_in(port, SCxSR);
  382. #if defined(CONFIG_CPU_SH3)
  383. /* Skip "chars" during break */
  384. if (sci_port->break_flag) {
  385. if ((c == 0) &&
  386. (status & SCxSR_FER(port))) {
  387. count--; i--;
  388. continue;
  389. }
  390. /* Nonzero => end-of-break */
  391. dev_dbg(port->dev, "debounce<%02x>\n", c);
  392. sci_port->break_flag = 0;
  393. if (STEPFN(c)) {
  394. count--; i--;
  395. continue;
  396. }
  397. }
  398. #endif /* CONFIG_CPU_SH3 */
  399. if (uart_handle_sysrq_char(port, c)) {
  400. count--; i--;
  401. continue;
  402. }
  403. /* Store data and status */
  404. if (status&SCxSR_FER(port)) {
  405. flag = TTY_FRAME;
  406. dev_notice(port->dev, "frame error\n");
  407. } else if (status&SCxSR_PER(port)) {
  408. flag = TTY_PARITY;
  409. dev_notice(port->dev, "parity error\n");
  410. } else
  411. flag = TTY_NORMAL;
  412. tty_insert_flip_char(tty, c, flag);
  413. }
  414. }
  415. sci_in(port, SCxSR); /* dummy read */
  416. sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
  417. copied += count;
  418. port->icount.rx += count;
  419. }
  420. if (copied) {
  421. /* Tell the rest of the system the news. New characters! */
  422. tty_flip_buffer_push(tty);
  423. } else {
  424. sci_in(port, SCxSR); /* dummy read */
  425. sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
  426. }
  427. }
  428. #define SCI_BREAK_JIFFIES (HZ/20)
  429. /* The sci generates interrupts during the break,
  430. * 1 per millisecond or so during the break period, for 9600 baud.
  431. * So dont bother disabling interrupts.
  432. * But dont want more than 1 break event.
  433. * Use a kernel timer to periodically poll the rx line until
  434. * the break is finished.
  435. */
  436. static void sci_schedule_break_timer(struct sci_port *port)
  437. {
  438. port->break_timer.expires = jiffies + SCI_BREAK_JIFFIES;
  439. add_timer(&port->break_timer);
  440. }
  441. /* Ensure that two consecutive samples find the break over. */
  442. static void sci_break_timer(unsigned long data)
  443. {
  444. struct sci_port *port = (struct sci_port *)data;
  445. if (sci_rxd_in(&port->port) == 0) {
  446. port->break_flag = 1;
  447. sci_schedule_break_timer(port);
  448. } else if (port->break_flag == 1) {
  449. /* break is over. */
  450. port->break_flag = 2;
  451. sci_schedule_break_timer(port);
  452. } else
  453. port->break_flag = 0;
  454. }
  455. static inline int sci_handle_errors(struct uart_port *port)
  456. {
  457. int copied = 0;
  458. unsigned short status = sci_in(port, SCxSR);
  459. struct tty_struct *tty = port->info->port.tty;
  460. if (status & SCxSR_ORER(port)) {
  461. /* overrun error */
  462. if (tty_insert_flip_char(tty, 0, TTY_OVERRUN))
  463. copied++;
  464. dev_notice(port->dev, "overrun error");
  465. }
  466. if (status & SCxSR_FER(port)) {
  467. if (sci_rxd_in(port) == 0) {
  468. /* Notify of BREAK */
  469. struct sci_port *sci_port = to_sci_port(port);
  470. if (!sci_port->break_flag) {
  471. sci_port->break_flag = 1;
  472. sci_schedule_break_timer(sci_port);
  473. /* Do sysrq handling. */
  474. if (uart_handle_break(port))
  475. return 0;
  476. dev_dbg(port->dev, "BREAK detected\n");
  477. if (tty_insert_flip_char(tty, 0, TTY_BREAK))
  478. copied++;
  479. }
  480. } else {
  481. /* frame error */
  482. if (tty_insert_flip_char(tty, 0, TTY_FRAME))
  483. copied++;
  484. dev_notice(port->dev, "frame error\n");
  485. }
  486. }
  487. if (status & SCxSR_PER(port)) {
  488. /* parity error */
  489. if (tty_insert_flip_char(tty, 0, TTY_PARITY))
  490. copied++;
  491. dev_notice(port->dev, "parity error");
  492. }
  493. if (copied)
  494. tty_flip_buffer_push(tty);
  495. return copied;
  496. }
  497. static inline int sci_handle_fifo_overrun(struct uart_port *port)
  498. {
  499. struct tty_struct *tty = port->info->port.tty;
  500. int copied = 0;
  501. if (port->type != PORT_SCIF)
  502. return 0;
  503. if ((sci_in(port, SCLSR) & SCIF_ORER) != 0) {
  504. sci_out(port, SCLSR, 0);
  505. tty_insert_flip_char(tty, 0, TTY_OVERRUN);
  506. tty_flip_buffer_push(tty);
  507. dev_notice(port->dev, "overrun error\n");
  508. copied++;
  509. }
  510. return copied;
  511. }
  512. static inline int sci_handle_breaks(struct uart_port *port)
  513. {
  514. int copied = 0;
  515. unsigned short status = sci_in(port, SCxSR);
  516. struct tty_struct *tty = port->info->port.tty;
  517. struct sci_port *s = &sci_ports[port->line];
  518. if (uart_handle_break(port))
  519. return 0;
  520. if (!s->break_flag && status & SCxSR_BRK(port)) {
  521. #if defined(CONFIG_CPU_SH3)
  522. /* Debounce break */
  523. s->break_flag = 1;
  524. #endif
  525. /* Notify of BREAK */
  526. if (tty_insert_flip_char(tty, 0, TTY_BREAK))
  527. copied++;
  528. dev_dbg(port->dev, "BREAK detected\n");
  529. }
  530. if (copied)
  531. tty_flip_buffer_push(tty);
  532. copied += sci_handle_fifo_overrun(port);
  533. return copied;
  534. }
  535. static irqreturn_t sci_rx_interrupt(int irq, void *port)
  536. {
  537. /* I think sci_receive_chars has to be called irrespective
  538. * of whether the I_IXOFF is set, otherwise, how is the interrupt
  539. * to be disabled?
  540. */
  541. sci_receive_chars(port);
  542. return IRQ_HANDLED;
  543. }
  544. static irqreturn_t sci_tx_interrupt(int irq, void *ptr)
  545. {
  546. struct uart_port *port = ptr;
  547. spin_lock_irq(&port->lock);
  548. sci_transmit_chars(port);
  549. spin_unlock_irq(&port->lock);
  550. return IRQ_HANDLED;
  551. }
  552. static irqreturn_t sci_er_interrupt(int irq, void *ptr)
  553. {
  554. struct uart_port *port = ptr;
  555. /* Handle errors */
  556. if (port->type == PORT_SCI) {
  557. if (sci_handle_errors(port)) {
  558. /* discard character in rx buffer */
  559. sci_in(port, SCxSR);
  560. sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
  561. }
  562. } else {
  563. sci_handle_fifo_overrun(port);
  564. sci_rx_interrupt(irq, ptr);
  565. }
  566. sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
  567. /* Kick the transmission */
  568. sci_tx_interrupt(irq, ptr);
  569. return IRQ_HANDLED;
  570. }
  571. static irqreturn_t sci_br_interrupt(int irq, void *ptr)
  572. {
  573. struct uart_port *port = ptr;
  574. /* Handle BREAKs */
  575. sci_handle_breaks(port);
  576. sci_out(port, SCxSR, SCxSR_BREAK_CLEAR(port));
  577. return IRQ_HANDLED;
  578. }
  579. static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr)
  580. {
  581. unsigned short ssr_status, scr_status;
  582. struct uart_port *port = ptr;
  583. irqreturn_t ret = IRQ_NONE;
  584. ssr_status = sci_in(port, SCxSR);
  585. scr_status = sci_in(port, SCSCR);
  586. /* Tx Interrupt */
  587. if ((ssr_status & 0x0020) && (scr_status & SCI_CTRL_FLAGS_TIE))
  588. ret = sci_tx_interrupt(irq, ptr);
  589. /* Rx Interrupt */
  590. if ((ssr_status & 0x0002) && (scr_status & SCI_CTRL_FLAGS_RIE))
  591. ret = sci_rx_interrupt(irq, ptr);
  592. /* Error Interrupt */
  593. if ((ssr_status & 0x0080) && (scr_status & SCI_CTRL_FLAGS_REIE))
  594. ret = sci_er_interrupt(irq, ptr);
  595. /* Break Interrupt */
  596. if ((ssr_status & 0x0010) && (scr_status & SCI_CTRL_FLAGS_REIE))
  597. ret = sci_br_interrupt(irq, ptr);
  598. return ret;
  599. }
  600. #ifdef CONFIG_HAVE_CLK
  601. /*
  602. * Here we define a transistion notifier so that we can update all of our
  603. * ports' baud rate when the peripheral clock changes.
  604. */
  605. static int sci_notifier(struct notifier_block *self,
  606. unsigned long phase, void *p)
  607. {
  608. int i;
  609. if ((phase == CPUFREQ_POSTCHANGE) ||
  610. (phase == CPUFREQ_RESUMECHANGE))
  611. for (i = 0; i < SCI_NPORTS; i++) {
  612. struct sci_port *s = &sci_ports[i];
  613. s->port.uartclk = clk_get_rate(s->clk);
  614. }
  615. return NOTIFY_OK;
  616. }
  617. static struct notifier_block sci_nb = { &sci_notifier, NULL, 0 };
  618. #endif
  619. static int sci_request_irq(struct sci_port *port)
  620. {
  621. int i;
  622. irqreturn_t (*handlers[4])(int irq, void *ptr) = {
  623. sci_er_interrupt, sci_rx_interrupt, sci_tx_interrupt,
  624. sci_br_interrupt,
  625. };
  626. const char *desc[] = { "SCI Receive Error", "SCI Receive Data Full",
  627. "SCI Transmit Data Empty", "SCI Break" };
  628. if (port->irqs[0] == port->irqs[1]) {
  629. if (unlikely(!port->irqs[0]))
  630. return -ENODEV;
  631. if (request_irq(port->irqs[0], sci_mpxed_interrupt,
  632. IRQF_DISABLED, "sci", port)) {
  633. dev_err(port->port.dev, "Can't allocate IRQ\n");
  634. return -ENODEV;
  635. }
  636. } else {
  637. for (i = 0; i < ARRAY_SIZE(handlers); i++) {
  638. if (unlikely(!port->irqs[i]))
  639. continue;
  640. if (request_irq(port->irqs[i], handlers[i],
  641. IRQF_DISABLED, desc[i], port)) {
  642. dev_err(port->port.dev, "Can't allocate IRQ\n");
  643. return -ENODEV;
  644. }
  645. }
  646. }
  647. return 0;
  648. }
  649. static void sci_free_irq(struct sci_port *port)
  650. {
  651. int i;
  652. if (port->irqs[0] == port->irqs[1])
  653. free_irq(port->irqs[0], port);
  654. else {
  655. for (i = 0; i < ARRAY_SIZE(port->irqs); i++) {
  656. if (!port->irqs[i])
  657. continue;
  658. free_irq(port->irqs[i], port);
  659. }
  660. }
  661. }
  662. static unsigned int sci_tx_empty(struct uart_port *port)
  663. {
  664. /* Can't detect */
  665. return TIOCSER_TEMT;
  666. }
  667. static void sci_set_mctrl(struct uart_port *port, unsigned int mctrl)
  668. {
  669. /* This routine is used for seting signals of: DTR, DCD, CTS/RTS */
  670. /* We use SCIF's hardware for CTS/RTS, so don't need any for that. */
  671. /* If you have signals for DTR and DCD, please implement here. */
  672. }
  673. static unsigned int sci_get_mctrl(struct uart_port *port)
  674. {
  675. /* This routine is used for geting signals of: DTR, DCD, DSR, RI,
  676. and CTS/RTS */
  677. return TIOCM_DTR | TIOCM_RTS | TIOCM_DSR;
  678. }
  679. static void sci_start_tx(struct uart_port *port)
  680. {
  681. unsigned short ctrl;
  682. /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */
  683. ctrl = sci_in(port, SCSCR);
  684. ctrl |= SCI_CTRL_FLAGS_TIE;
  685. sci_out(port, SCSCR, ctrl);
  686. }
  687. static void sci_stop_tx(struct uart_port *port)
  688. {
  689. unsigned short ctrl;
  690. /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */
  691. ctrl = sci_in(port, SCSCR);
  692. ctrl &= ~SCI_CTRL_FLAGS_TIE;
  693. sci_out(port, SCSCR, ctrl);
  694. }
  695. static void sci_start_rx(struct uart_port *port, unsigned int tty_start)
  696. {
  697. unsigned short ctrl;
  698. /* Set RIE (Receive Interrupt Enable) bit in SCSCR */
  699. ctrl = sci_in(port, SCSCR);
  700. ctrl |= SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE;
  701. sci_out(port, SCSCR, ctrl);
  702. }
  703. static void sci_stop_rx(struct uart_port *port)
  704. {
  705. unsigned short ctrl;
  706. /* Clear RIE (Receive Interrupt Enable) bit in SCSCR */
  707. ctrl = sci_in(port, SCSCR);
  708. ctrl &= ~(SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE);
  709. sci_out(port, SCSCR, ctrl);
  710. }
  711. static void sci_enable_ms(struct uart_port *port)
  712. {
  713. /* Nothing here yet .. */
  714. }
  715. static void sci_break_ctl(struct uart_port *port, int break_state)
  716. {
  717. /* Nothing here yet .. */
  718. }
  719. static int sci_startup(struct uart_port *port)
  720. {
  721. struct sci_port *s = &sci_ports[port->line];
  722. if (s->enable)
  723. s->enable(port);
  724. #ifdef CONFIG_HAVE_CLK
  725. s->clk = clk_get(NULL, "module_clk");
  726. #endif
  727. sci_request_irq(s);
  728. sci_start_tx(port);
  729. sci_start_rx(port, 1);
  730. return 0;
  731. }
  732. static void sci_shutdown(struct uart_port *port)
  733. {
  734. struct sci_port *s = &sci_ports[port->line];
  735. sci_stop_rx(port);
  736. sci_stop_tx(port);
  737. sci_free_irq(s);
  738. if (s->disable)
  739. s->disable(port);
  740. #ifdef CONFIG_HAVE_CLK
  741. clk_put(s->clk);
  742. s->clk = NULL;
  743. #endif
  744. }
  745. static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
  746. struct ktermios *old)
  747. {
  748. unsigned int status, baud, smr_val;
  749. int t = -1;
  750. baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
  751. if (likely(baud))
  752. t = SCBRR_VALUE(baud, port->uartclk);
  753. do {
  754. status = sci_in(port, SCxSR);
  755. } while (!(status & SCxSR_TEND(port)));
  756. sci_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */
  757. if (port->type != PORT_SCI)
  758. sci_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST);
  759. smr_val = sci_in(port, SCSMR) & 3;
  760. if ((termios->c_cflag & CSIZE) == CS7)
  761. smr_val |= 0x40;
  762. if (termios->c_cflag & PARENB)
  763. smr_val |= 0x20;
  764. if (termios->c_cflag & PARODD)
  765. smr_val |= 0x30;
  766. if (termios->c_cflag & CSTOPB)
  767. smr_val |= 0x08;
  768. uart_update_timeout(port, termios->c_cflag, baud);
  769. sci_out(port, SCSMR, smr_val);
  770. if (t > 0) {
  771. if (t >= 256) {
  772. sci_out(port, SCSMR, (sci_in(port, SCSMR) & ~3) | 1);
  773. t >>= 2;
  774. } else
  775. sci_out(port, SCSMR, sci_in(port, SCSMR) & ~3);
  776. sci_out(port, SCBRR, t);
  777. udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */
  778. }
  779. sci_init_pins(port, termios->c_cflag);
  780. sci_out(port, SCFCR, (termios->c_cflag & CRTSCTS) ? SCFCR_MCE : 0);
  781. sci_out(port, SCSCR, SCSCR_INIT(port));
  782. if ((termios->c_cflag & CREAD) != 0)
  783. sci_start_rx(port, 0);
  784. }
  785. static const char *sci_type(struct uart_port *port)
  786. {
  787. switch (port->type) {
  788. case PORT_IRDA:
  789. return "irda";
  790. case PORT_SCI:
  791. return "sci";
  792. case PORT_SCIF:
  793. return "scif";
  794. case PORT_SCIFA:
  795. return "scifa";
  796. }
  797. return NULL;
  798. }
  799. static void sci_release_port(struct uart_port *port)
  800. {
  801. /* Nothing here yet .. */
  802. }
  803. static int sci_request_port(struct uart_port *port)
  804. {
  805. /* Nothing here yet .. */
  806. return 0;
  807. }
  808. static void sci_config_port(struct uart_port *port, int flags)
  809. {
  810. struct sci_port *s = &sci_ports[port->line];
  811. port->type = s->type;
  812. if (port->flags & UPF_IOREMAP && !port->membase) {
  813. #if defined(CONFIG_SUPERH64)
  814. port->mapbase = onchip_remap(SCIF_ADDR_SH5, 1024, "SCIF");
  815. port->membase = (void __iomem *)port->mapbase;
  816. #else
  817. port->membase = ioremap_nocache(port->mapbase, 0x40);
  818. #endif
  819. dev_err(port->dev, "can't remap port#%d\n", port->line);
  820. }
  821. }
  822. static int sci_verify_port(struct uart_port *port, struct serial_struct *ser)
  823. {
  824. struct sci_port *s = &sci_ports[port->line];
  825. if (ser->irq != s->irqs[SCIx_TXI_IRQ] || ser->irq > nr_irqs)
  826. return -EINVAL;
  827. if (ser->baud_base < 2400)
  828. /* No paper tape reader for Mitch.. */
  829. return -EINVAL;
  830. return 0;
  831. }
  832. static struct uart_ops sci_uart_ops = {
  833. .tx_empty = sci_tx_empty,
  834. .set_mctrl = sci_set_mctrl,
  835. .get_mctrl = sci_get_mctrl,
  836. .start_tx = sci_start_tx,
  837. .stop_tx = sci_stop_tx,
  838. .stop_rx = sci_stop_rx,
  839. .enable_ms = sci_enable_ms,
  840. .break_ctl = sci_break_ctl,
  841. .startup = sci_startup,
  842. .shutdown = sci_shutdown,
  843. .set_termios = sci_set_termios,
  844. .type = sci_type,
  845. .release_port = sci_release_port,
  846. .request_port = sci_request_port,
  847. .config_port = sci_config_port,
  848. .verify_port = sci_verify_port,
  849. #ifdef CONFIG_CONSOLE_POLL
  850. .poll_get_char = sci_poll_get_char,
  851. .poll_put_char = sci_poll_put_char,
  852. #endif
  853. };
  854. static void __init sci_init_ports(void)
  855. {
  856. static int first = 1;
  857. int i;
  858. if (!first)
  859. return;
  860. first = 0;
  861. for (i = 0; i < SCI_NPORTS; i++) {
  862. sci_ports[i].port.ops = &sci_uart_ops;
  863. sci_ports[i].port.iotype = UPIO_MEM;
  864. sci_ports[i].port.line = i;
  865. sci_ports[i].port.fifosize = 1;
  866. #if defined(__H8300H__) || defined(__H8300S__)
  867. #ifdef __H8300S__
  868. sci_ports[i].enable = h8300_sci_enable;
  869. sci_ports[i].disable = h8300_sci_disable;
  870. #endif
  871. sci_ports[i].port.uartclk = CONFIG_CPU_CLOCK;
  872. #elif defined(CONFIG_HAVE_CLK)
  873. /*
  874. * XXX: We should use a proper SCI/SCIF clock
  875. */
  876. {
  877. struct clk *clk = clk_get(NULL, "module_clk");
  878. sci_ports[i].port.uartclk = clk_get_rate(clk);
  879. clk_put(clk);
  880. }
  881. #else
  882. #error "Need a valid uartclk"
  883. #endif
  884. sci_ports[i].break_timer.data = (unsigned long)&sci_ports[i];
  885. sci_ports[i].break_timer.function = sci_break_timer;
  886. init_timer(&sci_ports[i].break_timer);
  887. }
  888. }
  889. int __init early_sci_setup(struct uart_port *port)
  890. {
  891. if (unlikely(port->line > SCI_NPORTS))
  892. return -ENODEV;
  893. sci_init_ports();
  894. sci_ports[port->line].port.membase = port->membase;
  895. sci_ports[port->line].port.mapbase = port->mapbase;
  896. sci_ports[port->line].port.type = port->type;
  897. return 0;
  898. }
  899. #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
  900. /*
  901. * Print a string to the serial port trying not to disturb
  902. * any possible real use of the port...
  903. */
  904. static void serial_console_write(struct console *co, const char *s,
  905. unsigned count)
  906. {
  907. struct uart_port *port = &serial_console_port->port;
  908. int i;
  909. for (i = 0; i < count; i++) {
  910. if (*s == 10)
  911. sci_poll_put_char(port, '\r');
  912. sci_poll_put_char(port, *s++);
  913. }
  914. }
  915. static int __init serial_console_setup(struct console *co, char *options)
  916. {
  917. struct uart_port *port;
  918. int baud = 115200;
  919. int bits = 8;
  920. int parity = 'n';
  921. int flow = 'n';
  922. int ret;
  923. /*
  924. * Check whether an invalid uart number has been specified, and
  925. * if so, search for the first available port that does have
  926. * console support.
  927. */
  928. if (co->index >= SCI_NPORTS)
  929. co->index = 0;
  930. serial_console_port = &sci_ports[co->index];
  931. port = &serial_console_port->port;
  932. /*
  933. * Also need to check port->type, we don't actually have any
  934. * UPIO_PORT ports, but uart_report_port() handily misreports
  935. * it anyways if we don't have a port available by the time this is
  936. * called.
  937. */
  938. if (!port->type)
  939. return -ENODEV;
  940. if (!port->membase || !port->mapbase)
  941. return -ENODEV;
  942. port->type = serial_console_port->type;
  943. #ifdef CONFIG_HAVE_CLK
  944. if (!serial_console_port->clk)
  945. serial_console_port->clk = clk_get(NULL, "module_clk");
  946. #endif
  947. if (port->flags & UPF_IOREMAP)
  948. sci_config_port(port, 0);
  949. if (serial_console_port->enable)
  950. serial_console_port->enable(port);
  951. if (options)
  952. uart_parse_options(options, &baud, &parity, &bits, &flow);
  953. ret = uart_set_options(port, co, baud, parity, bits, flow);
  954. #if defined(__H8300H__) || defined(__H8300S__)
  955. /* disable rx interrupt */
  956. if (ret == 0)
  957. sci_stop_rx(port);
  958. #endif
  959. return ret;
  960. }
  961. static struct console serial_console = {
  962. .name = "ttySC",
  963. .device = uart_console_device,
  964. .write = serial_console_write,
  965. .setup = serial_console_setup,
  966. .flags = CON_PRINTBUFFER,
  967. .index = -1,
  968. .data = &sci_uart_driver,
  969. };
  970. static int __init sci_console_init(void)
  971. {
  972. sci_init_ports();
  973. register_console(&serial_console);
  974. return 0;
  975. }
  976. console_initcall(sci_console_init);
  977. #endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */
  978. #if defined(CONFIG_SERIAL_SH_SCI_CONSOLE)
  979. #define SCI_CONSOLE (&serial_console)
  980. #else
  981. #define SCI_CONSOLE 0
  982. #endif
  983. static char banner[] __initdata =
  984. KERN_INFO "SuperH SCI(F) driver initialized\n";
  985. static struct uart_driver sci_uart_driver = {
  986. .owner = THIS_MODULE,
  987. .driver_name = "sci",
  988. .dev_name = "ttySC",
  989. .major = SCI_MAJOR,
  990. .minor = SCI_MINOR_START,
  991. .nr = SCI_NPORTS,
  992. .cons = SCI_CONSOLE,
  993. };
  994. /*
  995. * Register a set of serial devices attached to a platform device. The
  996. * list is terminated with a zero flags entry, which means we expect
  997. * all entries to have at least UPF_BOOT_AUTOCONF set. Platforms that need
  998. * remapping (such as sh64) should also set UPF_IOREMAP.
  999. */
  1000. static int __devinit sci_probe(struct platform_device *dev)
  1001. {
  1002. struct plat_sci_port *p = dev->dev.platform_data;
  1003. int i, ret = -EINVAL;
  1004. for (i = 0; p && p->flags != 0; p++, i++) {
  1005. struct sci_port *sciport = &sci_ports[i];
  1006. /* Sanity check */
  1007. if (unlikely(i == SCI_NPORTS)) {
  1008. dev_notice(&dev->dev, "Attempting to register port "
  1009. "%d when only %d are available.\n",
  1010. i+1, SCI_NPORTS);
  1011. dev_notice(&dev->dev, "Consider bumping "
  1012. "CONFIG_SERIAL_SH_SCI_NR_UARTS!\n");
  1013. break;
  1014. }
  1015. sciport->port.mapbase = p->mapbase;
  1016. if (p->mapbase && !p->membase) {
  1017. if (p->flags & UPF_IOREMAP) {
  1018. p->membase = ioremap_nocache(p->mapbase, 0x40);
  1019. if (IS_ERR(p->membase)) {
  1020. ret = PTR_ERR(p->membase);
  1021. goto err_unreg;
  1022. }
  1023. } else {
  1024. /*
  1025. * For the simple (and majority of) cases
  1026. * where we don't need to do any remapping,
  1027. * just cast the cookie directly.
  1028. */
  1029. p->membase = (void __iomem *)p->mapbase;
  1030. }
  1031. }
  1032. sciport->port.membase = p->membase;
  1033. sciport->port.irq = p->irqs[SCIx_TXI_IRQ];
  1034. sciport->port.flags = p->flags;
  1035. sciport->port.dev = &dev->dev;
  1036. sciport->type = sciport->port.type = p->type;
  1037. memcpy(&sciport->irqs, &p->irqs, sizeof(p->irqs));
  1038. uart_add_one_port(&sci_uart_driver, &sciport->port);
  1039. }
  1040. #ifdef CONFIG_HAVE_CLK
  1041. cpufreq_register_notifier(&sci_nb, CPUFREQ_TRANSITION_NOTIFIER);
  1042. #endif
  1043. #ifdef CONFIG_SH_STANDARD_BIOS
  1044. sh_bios_gdb_detach();
  1045. #endif
  1046. return 0;
  1047. err_unreg:
  1048. for (i = i - 1; i >= 0; i--)
  1049. uart_remove_one_port(&sci_uart_driver, &sci_ports[i].port);
  1050. return ret;
  1051. }
  1052. static int __devexit sci_remove(struct platform_device *dev)
  1053. {
  1054. int i;
  1055. #ifdef CONFIG_HAVE_CLK
  1056. cpufreq_unregister_notifier(&sci_nb, CPUFREQ_TRANSITION_NOTIFIER);
  1057. #endif
  1058. for (i = 0; i < SCI_NPORTS; i++)
  1059. uart_remove_one_port(&sci_uart_driver, &sci_ports[i].port);
  1060. return 0;
  1061. }
  1062. static int sci_suspend(struct platform_device *dev, pm_message_t state)
  1063. {
  1064. int i;
  1065. for (i = 0; i < SCI_NPORTS; i++) {
  1066. struct sci_port *p = &sci_ports[i];
  1067. if (p->type != PORT_UNKNOWN && p->port.dev == &dev->dev)
  1068. uart_suspend_port(&sci_uart_driver, &p->port);
  1069. }
  1070. return 0;
  1071. }
  1072. static int sci_resume(struct platform_device *dev)
  1073. {
  1074. int i;
  1075. for (i = 0; i < SCI_NPORTS; i++) {
  1076. struct sci_port *p = &sci_ports[i];
  1077. if (p->type != PORT_UNKNOWN && p->port.dev == &dev->dev)
  1078. uart_resume_port(&sci_uart_driver, &p->port);
  1079. }
  1080. return 0;
  1081. }
  1082. static struct platform_driver sci_driver = {
  1083. .probe = sci_probe,
  1084. .remove = __devexit_p(sci_remove),
  1085. .suspend = sci_suspend,
  1086. .resume = sci_resume,
  1087. .driver = {
  1088. .name = "sh-sci",
  1089. .owner = THIS_MODULE,
  1090. },
  1091. };
  1092. static int __init sci_init(void)
  1093. {
  1094. int ret;
  1095. printk(banner);
  1096. sci_init_ports();
  1097. ret = uart_register_driver(&sci_uart_driver);
  1098. if (likely(ret == 0)) {
  1099. ret = platform_driver_register(&sci_driver);
  1100. if (unlikely(ret))
  1101. uart_unregister_driver(&sci_uart_driver);
  1102. }
  1103. return ret;
  1104. }
  1105. static void __exit sci_exit(void)
  1106. {
  1107. platform_driver_unregister(&sci_driver);
  1108. uart_unregister_driver(&sci_uart_driver);
  1109. }
  1110. module_init(sci_init);
  1111. module_exit(sci_exit);
  1112. MODULE_LICENSE("GPL");
  1113. MODULE_ALIAS("platform:sh-sci");