sh-sci.c 31 KB

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