sh-sci.c 31 KB

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