sh-sci.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932
  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. #include <linux/list.h>
  49. #include <linux/dmaengine.h>
  50. #include <linux/scatterlist.h>
  51. #ifdef CONFIG_SUPERH
  52. #include <asm/sh_bios.h>
  53. #endif
  54. #ifdef CONFIG_H8300
  55. #include <asm/gpio.h>
  56. #endif
  57. #include "sh-sci.h"
  58. struct sci_port {
  59. struct uart_port port;
  60. /* Port type */
  61. unsigned int type;
  62. /* Port IRQs: ERI, RXI, TXI, BRI (optional) */
  63. unsigned int irqs[SCIx_NR_IRQS];
  64. /* Port enable callback */
  65. void (*enable)(struct uart_port *port);
  66. /* Port disable callback */
  67. void (*disable)(struct uart_port *port);
  68. /* Break timer */
  69. struct timer_list break_timer;
  70. int break_flag;
  71. /* Interface clock */
  72. struct clk *iclk;
  73. /* Data clock */
  74. struct clk *dclk;
  75. struct list_head node;
  76. struct dma_chan *chan_tx;
  77. struct dma_chan *chan_rx;
  78. #ifdef CONFIG_SERIAL_SH_SCI_DMA
  79. struct device *dma_dev;
  80. enum sh_dmae_slave_chan_id slave_tx;
  81. enum sh_dmae_slave_chan_id slave_rx;
  82. struct dma_async_tx_descriptor *desc_tx;
  83. struct dma_async_tx_descriptor *desc_rx[2];
  84. dma_cookie_t cookie_tx;
  85. dma_cookie_t cookie_rx[2];
  86. dma_cookie_t active_rx;
  87. struct scatterlist sg_tx;
  88. unsigned int sg_len_tx;
  89. struct scatterlist sg_rx[2];
  90. size_t buf_len_rx;
  91. struct sh_dmae_slave param_tx;
  92. struct sh_dmae_slave param_rx;
  93. struct work_struct work_tx;
  94. struct work_struct work_rx;
  95. struct timer_list rx_timer;
  96. #endif
  97. };
  98. struct sh_sci_priv {
  99. spinlock_t lock;
  100. struct list_head ports;
  101. struct notifier_block clk_nb;
  102. };
  103. /* Function prototypes */
  104. static void sci_stop_tx(struct uart_port *port);
  105. #define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS
  106. static struct sci_port sci_ports[SCI_NPORTS];
  107. static struct uart_driver sci_uart_driver;
  108. static inline struct sci_port *
  109. to_sci_port(struct uart_port *uart)
  110. {
  111. return container_of(uart, struct sci_port, port);
  112. }
  113. #if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_SH_SCI_CONSOLE)
  114. #ifdef CONFIG_CONSOLE_POLL
  115. static inline void handle_error(struct uart_port *port)
  116. {
  117. /* Clear error flags */
  118. sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
  119. }
  120. static int sci_poll_get_char(struct uart_port *port)
  121. {
  122. unsigned short status;
  123. int c;
  124. do {
  125. status = sci_in(port, SCxSR);
  126. if (status & SCxSR_ERRORS(port)) {
  127. handle_error(port);
  128. continue;
  129. }
  130. } while (!(status & SCxSR_RDxF(port)));
  131. c = sci_in(port, SCxRDR);
  132. /* Dummy read */
  133. sci_in(port, SCxSR);
  134. sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
  135. return c;
  136. }
  137. #endif
  138. static void sci_poll_put_char(struct uart_port *port, unsigned char c)
  139. {
  140. unsigned short status;
  141. do {
  142. status = sci_in(port, SCxSR);
  143. } while (!(status & SCxSR_TDxE(port)));
  144. sci_out(port, SCxTDR, c);
  145. sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port));
  146. }
  147. #endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */
  148. #if defined(__H8300H__) || defined(__H8300S__)
  149. static void sci_init_pins(struct uart_port *port, unsigned int cflag)
  150. {
  151. int ch = (port->mapbase - SMR0) >> 3;
  152. /* set DDR regs */
  153. H8300_GPIO_DDR(h8300_sci_pins[ch].port,
  154. h8300_sci_pins[ch].rx,
  155. H8300_GPIO_INPUT);
  156. H8300_GPIO_DDR(h8300_sci_pins[ch].port,
  157. h8300_sci_pins[ch].tx,
  158. H8300_GPIO_OUTPUT);
  159. /* tx mark output*/
  160. H8300_SCI_DR(ch) |= h8300_sci_pins[ch].tx;
  161. }
  162. #elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
  163. static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
  164. {
  165. if (port->mapbase == 0xA4400000) {
  166. __raw_writew(__raw_readw(PACR) & 0xffc0, PACR);
  167. __raw_writew(__raw_readw(PBCR) & 0x0fff, PBCR);
  168. } else if (port->mapbase == 0xA4410000)
  169. __raw_writew(__raw_readw(PBCR) & 0xf003, PBCR);
  170. }
  171. #elif defined(CONFIG_CPU_SUBTYPE_SH7720) || defined(CONFIG_CPU_SUBTYPE_SH7721)
  172. static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
  173. {
  174. unsigned short data;
  175. if (cflag & CRTSCTS) {
  176. /* enable RTS/CTS */
  177. if (port->mapbase == 0xa4430000) { /* SCIF0 */
  178. /* Clear PTCR bit 9-2; enable all scif pins but sck */
  179. data = __raw_readw(PORT_PTCR);
  180. __raw_writew((data & 0xfc03), PORT_PTCR);
  181. } else if (port->mapbase == 0xa4438000) { /* SCIF1 */
  182. /* Clear PVCR bit 9-2 */
  183. data = __raw_readw(PORT_PVCR);
  184. __raw_writew((data & 0xfc03), PORT_PVCR);
  185. }
  186. } else {
  187. if (port->mapbase == 0xa4430000) { /* SCIF0 */
  188. /* Clear PTCR bit 5-2; enable only tx and rx */
  189. data = __raw_readw(PORT_PTCR);
  190. __raw_writew((data & 0xffc3), PORT_PTCR);
  191. } else if (port->mapbase == 0xa4438000) { /* SCIF1 */
  192. /* Clear PVCR bit 5-2 */
  193. data = __raw_readw(PORT_PVCR);
  194. __raw_writew((data & 0xffc3), PORT_PVCR);
  195. }
  196. }
  197. }
  198. #elif defined(CONFIG_CPU_SH3)
  199. /* For SH7705, SH7706, SH7707, SH7709, SH7709A, SH7729 */
  200. static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
  201. {
  202. unsigned short data;
  203. /* We need to set SCPCR to enable RTS/CTS */
  204. data = __raw_readw(SCPCR);
  205. /* Clear out SCP7MD1,0, SCP6MD1,0, SCP4MD1,0*/
  206. __raw_writew(data & 0x0fcf, SCPCR);
  207. if (!(cflag & CRTSCTS)) {
  208. /* We need to set SCPCR to enable RTS/CTS */
  209. data = __raw_readw(SCPCR);
  210. /* Clear out SCP7MD1,0, SCP4MD1,0,
  211. Set SCP6MD1,0 = {01} (output) */
  212. __raw_writew((data & 0x0fcf) | 0x1000, SCPCR);
  213. data = __raw_readb(SCPDR);
  214. /* Set /RTS2 (bit6) = 0 */
  215. __raw_writeb(data & 0xbf, SCPDR);
  216. }
  217. }
  218. #elif defined(CONFIG_CPU_SUBTYPE_SH7722)
  219. static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
  220. {
  221. unsigned short data;
  222. if (port->mapbase == 0xffe00000) {
  223. data = __raw_readw(PSCR);
  224. data &= ~0x03cf;
  225. if (!(cflag & CRTSCTS))
  226. data |= 0x0340;
  227. __raw_writew(data, PSCR);
  228. }
  229. }
  230. #elif defined(CONFIG_CPU_SUBTYPE_SH7757) || \
  231. defined(CONFIG_CPU_SUBTYPE_SH7763) || \
  232. defined(CONFIG_CPU_SUBTYPE_SH7780) || \
  233. defined(CONFIG_CPU_SUBTYPE_SH7785) || \
  234. defined(CONFIG_CPU_SUBTYPE_SH7786) || \
  235. defined(CONFIG_CPU_SUBTYPE_SHX3)
  236. static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
  237. {
  238. if (!(cflag & CRTSCTS))
  239. __raw_writew(0x0080, SCSPTR0); /* Set RTS = 1 */
  240. }
  241. #elif defined(CONFIG_CPU_SH4) && !defined(CONFIG_CPU_SH4A)
  242. static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
  243. {
  244. if (!(cflag & CRTSCTS))
  245. __raw_writew(0x0080, SCSPTR2); /* Set RTS = 1 */
  246. }
  247. #else
  248. static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
  249. {
  250. /* Nothing to do */
  251. }
  252. #endif
  253. #if defined(CONFIG_CPU_SUBTYPE_SH7760) || \
  254. defined(CONFIG_CPU_SUBTYPE_SH7780) || \
  255. defined(CONFIG_CPU_SUBTYPE_SH7785) || \
  256. defined(CONFIG_CPU_SUBTYPE_SH7786)
  257. static int scif_txfill(struct uart_port *port)
  258. {
  259. return sci_in(port, SCTFDR) & 0xff;
  260. }
  261. static int scif_txroom(struct uart_port *port)
  262. {
  263. return SCIF_TXROOM_MAX - scif_txfill(port);
  264. }
  265. static int scif_rxfill(struct uart_port *port)
  266. {
  267. return sci_in(port, SCRFDR) & 0xff;
  268. }
  269. #elif defined(CONFIG_CPU_SUBTYPE_SH7763)
  270. static int scif_txfill(struct uart_port *port)
  271. {
  272. if (port->mapbase == 0xffe00000 ||
  273. port->mapbase == 0xffe08000)
  274. /* SCIF0/1*/
  275. return sci_in(port, SCTFDR) & 0xff;
  276. else
  277. /* SCIF2 */
  278. return sci_in(port, SCFDR) >> 8;
  279. }
  280. static int scif_txroom(struct uart_port *port)
  281. {
  282. if (port->mapbase == 0xffe00000 ||
  283. port->mapbase == 0xffe08000)
  284. /* SCIF0/1*/
  285. return SCIF_TXROOM_MAX - scif_txfill(port);
  286. else
  287. /* SCIF2 */
  288. return SCIF2_TXROOM_MAX - scif_txfill(port);
  289. }
  290. static int scif_rxfill(struct uart_port *port)
  291. {
  292. if ((port->mapbase == 0xffe00000) ||
  293. (port->mapbase == 0xffe08000)) {
  294. /* SCIF0/1*/
  295. return sci_in(port, SCRFDR) & 0xff;
  296. } else {
  297. /* SCIF2 */
  298. return sci_in(port, SCFDR) & SCIF2_RFDC_MASK;
  299. }
  300. }
  301. #else
  302. static int scif_txfill(struct uart_port *port)
  303. {
  304. return sci_in(port, SCFDR) >> 8;
  305. }
  306. static int scif_txroom(struct uart_port *port)
  307. {
  308. return SCIF_TXROOM_MAX - scif_txfill(port);
  309. }
  310. static int scif_rxfill(struct uart_port *port)
  311. {
  312. return sci_in(port, SCFDR) & SCIF_RFDC_MASK;
  313. }
  314. #endif
  315. static int sci_txfill(struct uart_port *port)
  316. {
  317. return !(sci_in(port, SCxSR) & SCI_TDRE);
  318. }
  319. static int sci_txroom(struct uart_port *port)
  320. {
  321. return !sci_txfill(port);
  322. }
  323. static int sci_rxfill(struct uart_port *port)
  324. {
  325. return (sci_in(port, SCxSR) & SCxSR_RDxF(port)) != 0;
  326. }
  327. /* ********************************************************************** *
  328. * the interrupt related routines *
  329. * ********************************************************************** */
  330. static void sci_transmit_chars(struct uart_port *port)
  331. {
  332. struct circ_buf *xmit = &port->state->xmit;
  333. unsigned int stopped = uart_tx_stopped(port);
  334. unsigned short status;
  335. unsigned short ctrl;
  336. int count;
  337. status = sci_in(port, SCxSR);
  338. if (!(status & SCxSR_TDxE(port))) {
  339. ctrl = sci_in(port, SCSCR);
  340. if (uart_circ_empty(xmit))
  341. ctrl &= ~SCI_CTRL_FLAGS_TIE;
  342. else
  343. ctrl |= SCI_CTRL_FLAGS_TIE;
  344. sci_out(port, SCSCR, ctrl);
  345. return;
  346. }
  347. if (port->type == PORT_SCI)
  348. count = sci_txroom(port);
  349. else
  350. count = scif_txroom(port);
  351. do {
  352. unsigned char c;
  353. if (port->x_char) {
  354. c = port->x_char;
  355. port->x_char = 0;
  356. } else if (!uart_circ_empty(xmit) && !stopped) {
  357. c = xmit->buf[xmit->tail];
  358. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  359. } else {
  360. break;
  361. }
  362. sci_out(port, SCxTDR, c);
  363. port->icount.tx++;
  364. } while (--count > 0);
  365. sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
  366. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  367. uart_write_wakeup(port);
  368. if (uart_circ_empty(xmit)) {
  369. sci_stop_tx(port);
  370. } else {
  371. ctrl = sci_in(port, SCSCR);
  372. if (port->type != PORT_SCI) {
  373. sci_in(port, SCxSR); /* Dummy read */
  374. sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
  375. }
  376. ctrl |= SCI_CTRL_FLAGS_TIE;
  377. sci_out(port, SCSCR, ctrl);
  378. }
  379. }
  380. /* On SH3, SCIF may read end-of-break as a space->mark char */
  381. #define STEPFN(c) ({int __c = (c); (((__c-1)|(__c)) == -1); })
  382. static inline void sci_receive_chars(struct uart_port *port)
  383. {
  384. struct sci_port *sci_port = to_sci_port(port);
  385. struct tty_struct *tty = port->state->port.tty;
  386. int i, count, copied = 0;
  387. unsigned short status;
  388. unsigned char flag;
  389. status = sci_in(port, SCxSR);
  390. if (!(status & SCxSR_RDxF(port)))
  391. return;
  392. while (1) {
  393. if (port->type == PORT_SCI)
  394. count = sci_rxfill(port);
  395. else
  396. count = scif_rxfill(port);
  397. /* Don't copy more bytes than there is room for in the buffer */
  398. count = tty_buffer_request_room(tty, count);
  399. /* If for any reason we can't copy more data, we're done! */
  400. if (count == 0)
  401. break;
  402. if (port->type == PORT_SCI) {
  403. char c = sci_in(port, SCxRDR);
  404. if (uart_handle_sysrq_char(port, c) ||
  405. sci_port->break_flag)
  406. count = 0;
  407. else
  408. tty_insert_flip_char(tty, c, TTY_NORMAL);
  409. } else {
  410. for (i = 0; i < count; i++) {
  411. char c = sci_in(port, SCxRDR);
  412. status = sci_in(port, SCxSR);
  413. #if defined(CONFIG_CPU_SH3)
  414. /* Skip "chars" during break */
  415. if (sci_port->break_flag) {
  416. if ((c == 0) &&
  417. (status & SCxSR_FER(port))) {
  418. count--; i--;
  419. continue;
  420. }
  421. /* Nonzero => end-of-break */
  422. dev_dbg(port->dev, "debounce<%02x>\n", c);
  423. sci_port->break_flag = 0;
  424. if (STEPFN(c)) {
  425. count--; i--;
  426. continue;
  427. }
  428. }
  429. #endif /* CONFIG_CPU_SH3 */
  430. if (uart_handle_sysrq_char(port, c)) {
  431. count--; i--;
  432. continue;
  433. }
  434. /* Store data and status */
  435. if (status & SCxSR_FER(port)) {
  436. flag = TTY_FRAME;
  437. dev_notice(port->dev, "frame error\n");
  438. } else if (status & SCxSR_PER(port)) {
  439. flag = TTY_PARITY;
  440. dev_notice(port->dev, "parity error\n");
  441. } else
  442. flag = TTY_NORMAL;
  443. tty_insert_flip_char(tty, c, flag);
  444. }
  445. }
  446. sci_in(port, SCxSR); /* dummy read */
  447. sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
  448. copied += count;
  449. port->icount.rx += count;
  450. }
  451. if (copied) {
  452. /* Tell the rest of the system the news. New characters! */
  453. tty_flip_buffer_push(tty);
  454. } else {
  455. sci_in(port, SCxSR); /* dummy read */
  456. sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
  457. }
  458. }
  459. #define SCI_BREAK_JIFFIES (HZ/20)
  460. /* The sci generates interrupts during the break,
  461. * 1 per millisecond or so during the break period, for 9600 baud.
  462. * So dont bother disabling interrupts.
  463. * But dont want more than 1 break event.
  464. * Use a kernel timer to periodically poll the rx line until
  465. * the break is finished.
  466. */
  467. static void sci_schedule_break_timer(struct sci_port *port)
  468. {
  469. port->break_timer.expires = jiffies + SCI_BREAK_JIFFIES;
  470. add_timer(&port->break_timer);
  471. }
  472. /* Ensure that two consecutive samples find the break over. */
  473. static void sci_break_timer(unsigned long data)
  474. {
  475. struct sci_port *port = (struct sci_port *)data;
  476. if (sci_rxd_in(&port->port) == 0) {
  477. port->break_flag = 1;
  478. sci_schedule_break_timer(port);
  479. } else if (port->break_flag == 1) {
  480. /* break is over. */
  481. port->break_flag = 2;
  482. sci_schedule_break_timer(port);
  483. } else
  484. port->break_flag = 0;
  485. }
  486. static inline int sci_handle_errors(struct uart_port *port)
  487. {
  488. int copied = 0;
  489. unsigned short status = sci_in(port, SCxSR);
  490. struct tty_struct *tty = port->state->port.tty;
  491. if (status & SCxSR_ORER(port)) {
  492. /* overrun error */
  493. if (tty_insert_flip_char(tty, 0, TTY_OVERRUN))
  494. copied++;
  495. dev_notice(port->dev, "overrun error");
  496. }
  497. if (status & SCxSR_FER(port)) {
  498. if (sci_rxd_in(port) == 0) {
  499. /* Notify of BREAK */
  500. struct sci_port *sci_port = to_sci_port(port);
  501. if (!sci_port->break_flag) {
  502. sci_port->break_flag = 1;
  503. sci_schedule_break_timer(sci_port);
  504. /* Do sysrq handling. */
  505. if (uart_handle_break(port))
  506. return 0;
  507. dev_dbg(port->dev, "BREAK detected\n");
  508. if (tty_insert_flip_char(tty, 0, TTY_BREAK))
  509. copied++;
  510. }
  511. } else {
  512. /* frame error */
  513. if (tty_insert_flip_char(tty, 0, TTY_FRAME))
  514. copied++;
  515. dev_notice(port->dev, "frame error\n");
  516. }
  517. }
  518. if (status & SCxSR_PER(port)) {
  519. /* parity error */
  520. if (tty_insert_flip_char(tty, 0, TTY_PARITY))
  521. copied++;
  522. dev_notice(port->dev, "parity error");
  523. }
  524. if (copied)
  525. tty_flip_buffer_push(tty);
  526. return copied;
  527. }
  528. static inline int sci_handle_fifo_overrun(struct uart_port *port)
  529. {
  530. struct tty_struct *tty = port->state->port.tty;
  531. int copied = 0;
  532. if (port->type != PORT_SCIF)
  533. return 0;
  534. if ((sci_in(port, SCLSR) & SCIF_ORER) != 0) {
  535. sci_out(port, SCLSR, 0);
  536. tty_insert_flip_char(tty, 0, TTY_OVERRUN);
  537. tty_flip_buffer_push(tty);
  538. dev_notice(port->dev, "overrun error\n");
  539. copied++;
  540. }
  541. return copied;
  542. }
  543. static inline int sci_handle_breaks(struct uart_port *port)
  544. {
  545. int copied = 0;
  546. unsigned short status = sci_in(port, SCxSR);
  547. struct tty_struct *tty = port->state->port.tty;
  548. struct sci_port *s = to_sci_port(port);
  549. if (uart_handle_break(port))
  550. return 0;
  551. if (!s->break_flag && status & SCxSR_BRK(port)) {
  552. #if defined(CONFIG_CPU_SH3)
  553. /* Debounce break */
  554. s->break_flag = 1;
  555. #endif
  556. /* Notify of BREAK */
  557. if (tty_insert_flip_char(tty, 0, TTY_BREAK))
  558. copied++;
  559. dev_dbg(port->dev, "BREAK detected\n");
  560. }
  561. if (copied)
  562. tty_flip_buffer_push(tty);
  563. copied += sci_handle_fifo_overrun(port);
  564. return copied;
  565. }
  566. static irqreturn_t sci_rx_interrupt(int irq, void *ptr)
  567. {
  568. #ifdef CONFIG_SERIAL_SH_SCI_DMA
  569. struct uart_port *port = ptr;
  570. struct sci_port *s = to_sci_port(port);
  571. if (s->chan_rx) {
  572. unsigned long tout;
  573. u16 scr = sci_in(port, SCSCR);
  574. u16 ssr = sci_in(port, SCxSR);
  575. /* Disable future Rx interrupts */
  576. sci_out(port, SCSCR, scr & ~SCI_CTRL_FLAGS_RIE);
  577. /* Clear current interrupt */
  578. sci_out(port, SCxSR, ssr & ~(1 | SCxSR_RDxF(port)));
  579. /* Calculate delay for 1.5 DMA buffers */
  580. tout = (port->timeout - HZ / 50) * s->buf_len_rx * 3 /
  581. port->fifosize / 2;
  582. dev_dbg(port->dev, "Rx IRQ: setup timeout in %lu ms\n",
  583. tout * 1000 / HZ);
  584. if (tout < 2)
  585. tout = 2;
  586. mod_timer(&s->rx_timer, jiffies + tout);
  587. return IRQ_HANDLED;
  588. }
  589. #endif
  590. /* I think sci_receive_chars has to be called irrespective
  591. * of whether the I_IXOFF is set, otherwise, how is the interrupt
  592. * to be disabled?
  593. */
  594. sci_receive_chars(ptr);
  595. return IRQ_HANDLED;
  596. }
  597. static irqreturn_t sci_tx_interrupt(int irq, void *ptr)
  598. {
  599. struct uart_port *port = ptr;
  600. unsigned long flags;
  601. spin_lock_irqsave(&port->lock, flags);
  602. sci_transmit_chars(port);
  603. spin_unlock_irqrestore(&port->lock, flags);
  604. return IRQ_HANDLED;
  605. }
  606. static irqreturn_t sci_er_interrupt(int irq, void *ptr)
  607. {
  608. struct uart_port *port = ptr;
  609. /* Handle errors */
  610. if (port->type == PORT_SCI) {
  611. if (sci_handle_errors(port)) {
  612. /* discard character in rx buffer */
  613. sci_in(port, SCxSR);
  614. sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
  615. }
  616. } else {
  617. sci_handle_fifo_overrun(port);
  618. sci_rx_interrupt(irq, ptr);
  619. }
  620. sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
  621. /* Kick the transmission */
  622. sci_tx_interrupt(irq, ptr);
  623. return IRQ_HANDLED;
  624. }
  625. static irqreturn_t sci_br_interrupt(int irq, void *ptr)
  626. {
  627. struct uart_port *port = ptr;
  628. /* Handle BREAKs */
  629. sci_handle_breaks(port);
  630. sci_out(port, SCxSR, SCxSR_BREAK_CLEAR(port));
  631. return IRQ_HANDLED;
  632. }
  633. static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr)
  634. {
  635. unsigned short ssr_status, scr_status, err_enabled;
  636. struct uart_port *port = ptr;
  637. struct sci_port *s = to_sci_port(port);
  638. irqreturn_t ret = IRQ_NONE;
  639. ssr_status = sci_in(port, SCxSR);
  640. scr_status = sci_in(port, SCSCR);
  641. err_enabled = scr_status & (SCI_CTRL_FLAGS_REIE | SCI_CTRL_FLAGS_RIE);
  642. /* Tx Interrupt */
  643. if ((ssr_status & SCxSR_TDxE(port)) && (scr_status & SCI_CTRL_FLAGS_TIE) &&
  644. !s->chan_tx)
  645. ret = sci_tx_interrupt(irq, ptr);
  646. /*
  647. * Rx Interrupt: if we're using DMA, the DMA controller clears RDF /
  648. * DR flags
  649. */
  650. if (((ssr_status & SCxSR_RDxF(port)) || s->chan_rx) &&
  651. (scr_status & SCI_CTRL_FLAGS_RIE))
  652. ret = sci_rx_interrupt(irq, ptr);
  653. /* Error Interrupt */
  654. if ((ssr_status & SCxSR_ERRORS(port)) && err_enabled)
  655. ret = sci_er_interrupt(irq, ptr);
  656. /* Break Interrupt */
  657. if ((ssr_status & SCxSR_BRK(port)) && err_enabled)
  658. ret = sci_br_interrupt(irq, ptr);
  659. return ret;
  660. }
  661. /*
  662. * Here we define a transistion notifier so that we can update all of our
  663. * ports' baud rate when the peripheral clock changes.
  664. */
  665. static int sci_notifier(struct notifier_block *self,
  666. unsigned long phase, void *p)
  667. {
  668. struct sh_sci_priv *priv = container_of(self,
  669. struct sh_sci_priv, clk_nb);
  670. struct sci_port *sci_port;
  671. unsigned long flags;
  672. if ((phase == CPUFREQ_POSTCHANGE) ||
  673. (phase == CPUFREQ_RESUMECHANGE)) {
  674. spin_lock_irqsave(&priv->lock, flags);
  675. list_for_each_entry(sci_port, &priv->ports, node)
  676. sci_port->port.uartclk = clk_get_rate(sci_port->dclk);
  677. spin_unlock_irqrestore(&priv->lock, flags);
  678. }
  679. return NOTIFY_OK;
  680. }
  681. static void sci_clk_enable(struct uart_port *port)
  682. {
  683. struct sci_port *sci_port = to_sci_port(port);
  684. clk_enable(sci_port->dclk);
  685. sci_port->port.uartclk = clk_get_rate(sci_port->dclk);
  686. if (sci_port->iclk)
  687. clk_enable(sci_port->iclk);
  688. }
  689. static void sci_clk_disable(struct uart_port *port)
  690. {
  691. struct sci_port *sci_port = to_sci_port(port);
  692. if (sci_port->iclk)
  693. clk_disable(sci_port->iclk);
  694. clk_disable(sci_port->dclk);
  695. }
  696. static int sci_request_irq(struct sci_port *port)
  697. {
  698. int i;
  699. irqreturn_t (*handlers[4])(int irq, void *ptr) = {
  700. sci_er_interrupt, sci_rx_interrupt, sci_tx_interrupt,
  701. sci_br_interrupt,
  702. };
  703. const char *desc[] = { "SCI Receive Error", "SCI Receive Data Full",
  704. "SCI Transmit Data Empty", "SCI Break" };
  705. if (port->irqs[0] == port->irqs[1]) {
  706. if (unlikely(!port->irqs[0]))
  707. return -ENODEV;
  708. if (request_irq(port->irqs[0], sci_mpxed_interrupt,
  709. IRQF_DISABLED, "sci", port)) {
  710. dev_err(port->port.dev, "Can't allocate IRQ\n");
  711. return -ENODEV;
  712. }
  713. } else {
  714. for (i = 0; i < ARRAY_SIZE(handlers); i++) {
  715. if (unlikely(!port->irqs[i]))
  716. continue;
  717. if (request_irq(port->irqs[i], handlers[i],
  718. IRQF_DISABLED, desc[i], port)) {
  719. dev_err(port->port.dev, "Can't allocate IRQ\n");
  720. return -ENODEV;
  721. }
  722. }
  723. }
  724. return 0;
  725. }
  726. static void sci_free_irq(struct sci_port *port)
  727. {
  728. int i;
  729. if (port->irqs[0] == port->irqs[1])
  730. free_irq(port->irqs[0], port);
  731. else {
  732. for (i = 0; i < ARRAY_SIZE(port->irqs); i++) {
  733. if (!port->irqs[i])
  734. continue;
  735. free_irq(port->irqs[i], port);
  736. }
  737. }
  738. }
  739. static unsigned int sci_tx_empty(struct uart_port *port)
  740. {
  741. unsigned short status = sci_in(port, SCxSR);
  742. unsigned short in_tx_fifo = scif_txfill(port);
  743. return (status & SCxSR_TEND(port)) && !in_tx_fifo ? TIOCSER_TEMT : 0;
  744. }
  745. static void sci_set_mctrl(struct uart_port *port, unsigned int mctrl)
  746. {
  747. /* This routine is used for seting signals of: DTR, DCD, CTS/RTS */
  748. /* We use SCIF's hardware for CTS/RTS, so don't need any for that. */
  749. /* If you have signals for DTR and DCD, please implement here. */
  750. }
  751. static unsigned int sci_get_mctrl(struct uart_port *port)
  752. {
  753. /* This routine is used for getting signals of: DTR, DCD, DSR, RI,
  754. and CTS/RTS */
  755. return TIOCM_DTR | TIOCM_RTS | TIOCM_DSR;
  756. }
  757. #ifdef CONFIG_SERIAL_SH_SCI_DMA
  758. static void sci_dma_tx_complete(void *arg)
  759. {
  760. struct sci_port *s = arg;
  761. struct uart_port *port = &s->port;
  762. struct circ_buf *xmit = &port->state->xmit;
  763. unsigned long flags;
  764. dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
  765. spin_lock_irqsave(&port->lock, flags);
  766. xmit->tail += s->sg_tx.length;
  767. xmit->tail &= UART_XMIT_SIZE - 1;
  768. port->icount.tx += s->sg_tx.length;
  769. async_tx_ack(s->desc_tx);
  770. s->cookie_tx = -EINVAL;
  771. s->desc_tx = NULL;
  772. spin_unlock_irqrestore(&port->lock, flags);
  773. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  774. uart_write_wakeup(port);
  775. if (uart_circ_chars_pending(xmit))
  776. schedule_work(&s->work_tx);
  777. }
  778. /* Locking: called with port lock held */
  779. static int sci_dma_rx_push(struct sci_port *s, struct tty_struct *tty,
  780. size_t count)
  781. {
  782. struct uart_port *port = &s->port;
  783. int i, active, room;
  784. room = tty_buffer_request_room(tty, count);
  785. if (s->active_rx == s->cookie_rx[0]) {
  786. active = 0;
  787. } else if (s->active_rx == s->cookie_rx[1]) {
  788. active = 1;
  789. } else {
  790. dev_err(port->dev, "cookie %d not found!\n", s->active_rx);
  791. return 0;
  792. }
  793. if (room < count)
  794. dev_warn(port->dev, "Rx overrun: dropping %u bytes\n",
  795. count - room);
  796. if (!room)
  797. return room;
  798. for (i = 0; i < room; i++)
  799. tty_insert_flip_char(tty, ((u8 *)sg_virt(&s->sg_rx[active]))[i],
  800. TTY_NORMAL);
  801. port->icount.rx += room;
  802. return room;
  803. }
  804. static void sci_dma_rx_complete(void *arg)
  805. {
  806. struct sci_port *s = arg;
  807. struct uart_port *port = &s->port;
  808. struct tty_struct *tty = port->state->port.tty;
  809. unsigned long flags;
  810. int count;
  811. dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
  812. spin_lock_irqsave(&port->lock, flags);
  813. count = sci_dma_rx_push(s, tty, s->buf_len_rx);
  814. mod_timer(&s->rx_timer, jiffies + msecs_to_jiffies(5));
  815. spin_unlock_irqrestore(&port->lock, flags);
  816. if (count)
  817. tty_flip_buffer_push(tty);
  818. schedule_work(&s->work_rx);
  819. }
  820. static void sci_start_rx(struct uart_port *port);
  821. static void sci_start_tx(struct uart_port *port);
  822. static void sci_rx_dma_release(struct sci_port *s, bool enable_pio)
  823. {
  824. struct dma_chan *chan = s->chan_rx;
  825. struct uart_port *port = &s->port;
  826. s->chan_rx = NULL;
  827. s->cookie_rx[0] = s->cookie_rx[1] = -EINVAL;
  828. dma_release_channel(chan);
  829. dma_free_coherent(port->dev, s->buf_len_rx * 2,
  830. sg_virt(&s->sg_rx[0]), sg_dma_address(&s->sg_rx[0]));
  831. if (enable_pio)
  832. sci_start_rx(port);
  833. }
  834. static void sci_tx_dma_release(struct sci_port *s, bool enable_pio)
  835. {
  836. struct dma_chan *chan = s->chan_tx;
  837. struct uart_port *port = &s->port;
  838. s->chan_tx = NULL;
  839. s->cookie_tx = -EINVAL;
  840. dma_release_channel(chan);
  841. if (enable_pio)
  842. sci_start_tx(port);
  843. }
  844. static void sci_submit_rx(struct sci_port *s)
  845. {
  846. struct dma_chan *chan = s->chan_rx;
  847. int i;
  848. for (i = 0; i < 2; i++) {
  849. struct scatterlist *sg = &s->sg_rx[i];
  850. struct dma_async_tx_descriptor *desc;
  851. desc = chan->device->device_prep_slave_sg(chan,
  852. sg, 1, DMA_FROM_DEVICE, DMA_PREP_INTERRUPT);
  853. if (desc) {
  854. s->desc_rx[i] = desc;
  855. desc->callback = sci_dma_rx_complete;
  856. desc->callback_param = s;
  857. s->cookie_rx[i] = desc->tx_submit(desc);
  858. }
  859. if (!desc || s->cookie_rx[i] < 0) {
  860. if (i) {
  861. async_tx_ack(s->desc_rx[0]);
  862. s->cookie_rx[0] = -EINVAL;
  863. }
  864. if (desc) {
  865. async_tx_ack(desc);
  866. s->cookie_rx[i] = -EINVAL;
  867. }
  868. dev_warn(s->port.dev,
  869. "failed to re-start DMA, using PIO\n");
  870. sci_rx_dma_release(s, true);
  871. return;
  872. }
  873. }
  874. s->active_rx = s->cookie_rx[0];
  875. dma_async_issue_pending(chan);
  876. }
  877. static void work_fn_rx(struct work_struct *work)
  878. {
  879. struct sci_port *s = container_of(work, struct sci_port, work_rx);
  880. struct uart_port *port = &s->port;
  881. struct dma_async_tx_descriptor *desc;
  882. int new;
  883. if (s->active_rx == s->cookie_rx[0]) {
  884. new = 0;
  885. } else if (s->active_rx == s->cookie_rx[1]) {
  886. new = 1;
  887. } else {
  888. dev_err(port->dev, "cookie %d not found!\n", s->active_rx);
  889. return;
  890. }
  891. desc = s->desc_rx[new];
  892. if (dma_async_is_tx_complete(s->chan_rx, s->active_rx, NULL, NULL) !=
  893. DMA_SUCCESS) {
  894. /* Handle incomplete DMA receive */
  895. struct tty_struct *tty = port->state->port.tty;
  896. struct dma_chan *chan = s->chan_rx;
  897. struct sh_desc *sh_desc = container_of(desc, struct sh_desc,
  898. async_tx);
  899. unsigned long flags;
  900. int count;
  901. chan->device->device_terminate_all(chan);
  902. dev_dbg(port->dev, "Read %u bytes with cookie %d\n",
  903. sh_desc->partial, sh_desc->cookie);
  904. spin_lock_irqsave(&port->lock, flags);
  905. count = sci_dma_rx_push(s, tty, sh_desc->partial);
  906. spin_unlock_irqrestore(&port->lock, flags);
  907. if (count)
  908. tty_flip_buffer_push(tty);
  909. sci_submit_rx(s);
  910. return;
  911. }
  912. s->cookie_rx[new] = desc->tx_submit(desc);
  913. if (s->cookie_rx[new] < 0) {
  914. dev_warn(port->dev, "Failed submitting Rx DMA descriptor\n");
  915. sci_rx_dma_release(s, true);
  916. return;
  917. }
  918. dev_dbg(port->dev, "%s: cookie %d #%d\n", __func__,
  919. s->cookie_rx[new], new);
  920. s->active_rx = s->cookie_rx[!new];
  921. }
  922. static void work_fn_tx(struct work_struct *work)
  923. {
  924. struct sci_port *s = container_of(work, struct sci_port, work_tx);
  925. struct dma_async_tx_descriptor *desc;
  926. struct dma_chan *chan = s->chan_tx;
  927. struct uart_port *port = &s->port;
  928. struct circ_buf *xmit = &port->state->xmit;
  929. struct scatterlist *sg = &s->sg_tx;
  930. /*
  931. * DMA is idle now.
  932. * Port xmit buffer is already mapped, and it is one page... Just adjust
  933. * offsets and lengths. Since it is a circular buffer, we have to
  934. * transmit till the end, and then the rest. Take the port lock to get a
  935. * consistent xmit buffer state.
  936. */
  937. spin_lock_irq(&port->lock);
  938. sg->offset = xmit->tail & (UART_XMIT_SIZE - 1);
  939. sg->dma_address = (sg_dma_address(sg) & ~(UART_XMIT_SIZE - 1)) +
  940. sg->offset;
  941. sg->length = min((int)CIRC_CNT(xmit->head, xmit->tail, UART_XMIT_SIZE),
  942. CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE));
  943. sg->dma_length = sg->length;
  944. spin_unlock_irq(&port->lock);
  945. BUG_ON(!sg->length);
  946. desc = chan->device->device_prep_slave_sg(chan,
  947. sg, s->sg_len_tx, DMA_TO_DEVICE,
  948. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  949. if (!desc) {
  950. /* switch to PIO */
  951. sci_tx_dma_release(s, true);
  952. return;
  953. }
  954. dma_sync_sg_for_device(port->dev, sg, 1, DMA_TO_DEVICE);
  955. spin_lock_irq(&port->lock);
  956. s->desc_tx = desc;
  957. desc->callback = sci_dma_tx_complete;
  958. desc->callback_param = s;
  959. spin_unlock_irq(&port->lock);
  960. s->cookie_tx = desc->tx_submit(desc);
  961. if (s->cookie_tx < 0) {
  962. dev_warn(port->dev, "Failed submitting Tx DMA descriptor\n");
  963. /* switch to PIO */
  964. sci_tx_dma_release(s, true);
  965. return;
  966. }
  967. dev_dbg(port->dev, "%s: %p: %d...%d, cookie %d\n", __func__,
  968. xmit->buf, xmit->tail, xmit->head, s->cookie_tx);
  969. dma_async_issue_pending(chan);
  970. }
  971. #endif
  972. static void sci_start_tx(struct uart_port *port)
  973. {
  974. unsigned short ctrl;
  975. #ifdef CONFIG_SERIAL_SH_SCI_DMA
  976. struct sci_port *s = to_sci_port(port);
  977. if (s->chan_tx) {
  978. if (!uart_circ_empty(&s->port.state->xmit) && s->cookie_tx < 0)
  979. schedule_work(&s->work_tx);
  980. return;
  981. }
  982. #endif
  983. /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */
  984. ctrl = sci_in(port, SCSCR);
  985. ctrl |= SCI_CTRL_FLAGS_TIE;
  986. sci_out(port, SCSCR, ctrl);
  987. }
  988. static void sci_stop_tx(struct uart_port *port)
  989. {
  990. unsigned short ctrl;
  991. /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */
  992. ctrl = sci_in(port, SCSCR);
  993. ctrl &= ~SCI_CTRL_FLAGS_TIE;
  994. sci_out(port, SCSCR, ctrl);
  995. }
  996. static void sci_start_rx(struct uart_port *port)
  997. {
  998. unsigned short ctrl = SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE;
  999. /* Set RIE (Receive Interrupt Enable) bit in SCSCR */
  1000. ctrl |= sci_in(port, SCSCR);
  1001. sci_out(port, SCSCR, ctrl);
  1002. }
  1003. static void sci_stop_rx(struct uart_port *port)
  1004. {
  1005. unsigned short ctrl;
  1006. /* Clear RIE (Receive Interrupt Enable) bit in SCSCR */
  1007. ctrl = sci_in(port, SCSCR);
  1008. ctrl &= ~(SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE);
  1009. sci_out(port, SCSCR, ctrl);
  1010. }
  1011. static void sci_enable_ms(struct uart_port *port)
  1012. {
  1013. /* Nothing here yet .. */
  1014. }
  1015. static void sci_break_ctl(struct uart_port *port, int break_state)
  1016. {
  1017. /* Nothing here yet .. */
  1018. }
  1019. #ifdef CONFIG_SERIAL_SH_SCI_DMA
  1020. static bool filter(struct dma_chan *chan, void *slave)
  1021. {
  1022. struct sh_dmae_slave *param = slave;
  1023. dev_dbg(chan->device->dev, "%s: slave ID %d\n", __func__,
  1024. param->slave_id);
  1025. if (param->dma_dev == chan->device->dev) {
  1026. chan->private = param;
  1027. return true;
  1028. } else {
  1029. return false;
  1030. }
  1031. }
  1032. static void rx_timer_fn(unsigned long arg)
  1033. {
  1034. struct sci_port *s = (struct sci_port *)arg;
  1035. struct uart_port *port = &s->port;
  1036. u16 scr = sci_in(port, SCSCR);
  1037. sci_out(port, SCSCR, scr | SCI_CTRL_FLAGS_RIE);
  1038. dev_dbg(port->dev, "DMA Rx timed out\n");
  1039. schedule_work(&s->work_rx);
  1040. }
  1041. static void sci_request_dma(struct uart_port *port)
  1042. {
  1043. struct sci_port *s = to_sci_port(port);
  1044. struct sh_dmae_slave *param;
  1045. struct dma_chan *chan;
  1046. dma_cap_mask_t mask;
  1047. int nent;
  1048. dev_dbg(port->dev, "%s: port %d DMA %p\n", __func__,
  1049. port->line, s->dma_dev);
  1050. if (!s->dma_dev)
  1051. return;
  1052. dma_cap_zero(mask);
  1053. dma_cap_set(DMA_SLAVE, mask);
  1054. param = &s->param_tx;
  1055. /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_TX */
  1056. param->slave_id = s->slave_tx;
  1057. param->dma_dev = s->dma_dev;
  1058. s->cookie_tx = -EINVAL;
  1059. chan = dma_request_channel(mask, filter, param);
  1060. dev_dbg(port->dev, "%s: TX: got channel %p\n", __func__, chan);
  1061. if (chan) {
  1062. s->chan_tx = chan;
  1063. sg_init_table(&s->sg_tx, 1);
  1064. /* UART circular tx buffer is an aligned page. */
  1065. BUG_ON((int)port->state->xmit.buf & ~PAGE_MASK);
  1066. sg_set_page(&s->sg_tx, virt_to_page(port->state->xmit.buf),
  1067. UART_XMIT_SIZE, (int)port->state->xmit.buf & ~PAGE_MASK);
  1068. nent = dma_map_sg(port->dev, &s->sg_tx, 1, DMA_TO_DEVICE);
  1069. if (!nent)
  1070. sci_tx_dma_release(s, false);
  1071. else
  1072. dev_dbg(port->dev, "%s: mapped %d@%p to %x\n", __func__,
  1073. sg_dma_len(&s->sg_tx),
  1074. port->state->xmit.buf, sg_dma_address(&s->sg_tx));
  1075. s->sg_len_tx = nent;
  1076. INIT_WORK(&s->work_tx, work_fn_tx);
  1077. }
  1078. param = &s->param_rx;
  1079. /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_RX */
  1080. param->slave_id = s->slave_rx;
  1081. param->dma_dev = s->dma_dev;
  1082. chan = dma_request_channel(mask, filter, param);
  1083. dev_dbg(port->dev, "%s: RX: got channel %p\n", __func__, chan);
  1084. if (chan) {
  1085. dma_addr_t dma[2];
  1086. void *buf[2];
  1087. int i;
  1088. s->chan_rx = chan;
  1089. s->buf_len_rx = 2 * max(16, (int)port->fifosize);
  1090. buf[0] = dma_alloc_coherent(port->dev, s->buf_len_rx * 2,
  1091. &dma[0], GFP_KERNEL);
  1092. if (!buf[0]) {
  1093. dev_warn(port->dev,
  1094. "failed to allocate dma buffer, using PIO\n");
  1095. sci_rx_dma_release(s, true);
  1096. return;
  1097. }
  1098. buf[1] = buf[0] + s->buf_len_rx;
  1099. dma[1] = dma[0] + s->buf_len_rx;
  1100. for (i = 0; i < 2; i++) {
  1101. struct scatterlist *sg = &s->sg_rx[i];
  1102. sg_init_table(sg, 1);
  1103. sg_set_page(sg, virt_to_page(buf[i]), s->buf_len_rx,
  1104. (int)buf[i] & ~PAGE_MASK);
  1105. sg->dma_address = dma[i];
  1106. sg->dma_length = sg->length;
  1107. }
  1108. INIT_WORK(&s->work_rx, work_fn_rx);
  1109. setup_timer(&s->rx_timer, rx_timer_fn, (unsigned long)s);
  1110. sci_submit_rx(s);
  1111. }
  1112. }
  1113. static void sci_free_dma(struct uart_port *port)
  1114. {
  1115. struct sci_port *s = to_sci_port(port);
  1116. if (!s->dma_dev)
  1117. return;
  1118. if (s->chan_tx)
  1119. sci_tx_dma_release(s, false);
  1120. if (s->chan_rx)
  1121. sci_rx_dma_release(s, false);
  1122. }
  1123. #endif
  1124. static int sci_startup(struct uart_port *port)
  1125. {
  1126. struct sci_port *s = to_sci_port(port);
  1127. dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
  1128. if (s->enable)
  1129. s->enable(port);
  1130. sci_request_irq(s);
  1131. #ifdef CONFIG_SERIAL_SH_SCI_DMA
  1132. sci_request_dma(port);
  1133. #endif
  1134. sci_start_tx(port);
  1135. sci_start_rx(port);
  1136. return 0;
  1137. }
  1138. static void sci_shutdown(struct uart_port *port)
  1139. {
  1140. struct sci_port *s = to_sci_port(port);
  1141. dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
  1142. sci_stop_rx(port);
  1143. sci_stop_tx(port);
  1144. #ifdef CONFIG_SERIAL_SH_SCI_DMA
  1145. sci_free_dma(port);
  1146. #endif
  1147. sci_free_irq(s);
  1148. if (s->disable)
  1149. s->disable(port);
  1150. }
  1151. static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
  1152. struct ktermios *old)
  1153. {
  1154. unsigned int status, baud, smr_val, max_baud;
  1155. int t = -1;
  1156. /*
  1157. * earlyprintk comes here early on with port->uartclk set to zero.
  1158. * the clock framework is not up and running at this point so here
  1159. * we assume that 115200 is the maximum baud rate. please note that
  1160. * the baud rate is not programmed during earlyprintk - it is assumed
  1161. * that the previous boot loader has enabled required clocks and
  1162. * setup the baud rate generator hardware for us already.
  1163. */
  1164. max_baud = port->uartclk ? port->uartclk / 16 : 115200;
  1165. baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
  1166. if (likely(baud && port->uartclk))
  1167. t = SCBRR_VALUE(baud, port->uartclk);
  1168. do {
  1169. status = sci_in(port, SCxSR);
  1170. } while (!(status & SCxSR_TEND(port)));
  1171. sci_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */
  1172. if (port->type != PORT_SCI)
  1173. sci_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST);
  1174. smr_val = sci_in(port, SCSMR) & 3;
  1175. if ((termios->c_cflag & CSIZE) == CS7)
  1176. smr_val |= 0x40;
  1177. if (termios->c_cflag & PARENB)
  1178. smr_val |= 0x20;
  1179. if (termios->c_cflag & PARODD)
  1180. smr_val |= 0x30;
  1181. if (termios->c_cflag & CSTOPB)
  1182. smr_val |= 0x08;
  1183. uart_update_timeout(port, termios->c_cflag, baud);
  1184. sci_out(port, SCSMR, smr_val);
  1185. dev_dbg(port->dev, "%s: SMR %x, t %x, SCSCR %x\n", __func__, smr_val, t,
  1186. SCSCR_INIT(port));
  1187. if (t > 0) {
  1188. if (t >= 256) {
  1189. sci_out(port, SCSMR, (sci_in(port, SCSMR) & ~3) | 1);
  1190. t >>= 2;
  1191. } else
  1192. sci_out(port, SCSMR, sci_in(port, SCSMR) & ~3);
  1193. sci_out(port, SCBRR, t);
  1194. udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */
  1195. }
  1196. sci_init_pins(port, termios->c_cflag);
  1197. sci_out(port, SCFCR, (termios->c_cflag & CRTSCTS) ? SCFCR_MCE : 0);
  1198. sci_out(port, SCSCR, SCSCR_INIT(port));
  1199. if ((termios->c_cflag & CREAD) != 0)
  1200. sci_start_rx(port);
  1201. }
  1202. static const char *sci_type(struct uart_port *port)
  1203. {
  1204. switch (port->type) {
  1205. case PORT_IRDA:
  1206. return "irda";
  1207. case PORT_SCI:
  1208. return "sci";
  1209. case PORT_SCIF:
  1210. return "scif";
  1211. case PORT_SCIFA:
  1212. return "scifa";
  1213. }
  1214. return NULL;
  1215. }
  1216. static void sci_release_port(struct uart_port *port)
  1217. {
  1218. /* Nothing here yet .. */
  1219. }
  1220. static int sci_request_port(struct uart_port *port)
  1221. {
  1222. /* Nothing here yet .. */
  1223. return 0;
  1224. }
  1225. static void sci_config_port(struct uart_port *port, int flags)
  1226. {
  1227. struct sci_port *s = to_sci_port(port);
  1228. port->type = s->type;
  1229. if (port->membase)
  1230. return;
  1231. if (port->flags & UPF_IOREMAP) {
  1232. port->membase = ioremap_nocache(port->mapbase, 0x40);
  1233. if (IS_ERR(port->membase))
  1234. dev_err(port->dev, "can't remap port#%d\n", port->line);
  1235. } else {
  1236. /*
  1237. * For the simple (and majority of) cases where we don't
  1238. * need to do any remapping, just cast the cookie
  1239. * directly.
  1240. */
  1241. port->membase = (void __iomem *)port->mapbase;
  1242. }
  1243. }
  1244. static int sci_verify_port(struct uart_port *port, struct serial_struct *ser)
  1245. {
  1246. struct sci_port *s = to_sci_port(port);
  1247. if (ser->irq != s->irqs[SCIx_TXI_IRQ] || ser->irq > nr_irqs)
  1248. return -EINVAL;
  1249. if (ser->baud_base < 2400)
  1250. /* No paper tape reader for Mitch.. */
  1251. return -EINVAL;
  1252. return 0;
  1253. }
  1254. static struct uart_ops sci_uart_ops = {
  1255. .tx_empty = sci_tx_empty,
  1256. .set_mctrl = sci_set_mctrl,
  1257. .get_mctrl = sci_get_mctrl,
  1258. .start_tx = sci_start_tx,
  1259. .stop_tx = sci_stop_tx,
  1260. .stop_rx = sci_stop_rx,
  1261. .enable_ms = sci_enable_ms,
  1262. .break_ctl = sci_break_ctl,
  1263. .startup = sci_startup,
  1264. .shutdown = sci_shutdown,
  1265. .set_termios = sci_set_termios,
  1266. .type = sci_type,
  1267. .release_port = sci_release_port,
  1268. .request_port = sci_request_port,
  1269. .config_port = sci_config_port,
  1270. .verify_port = sci_verify_port,
  1271. #ifdef CONFIG_CONSOLE_POLL
  1272. .poll_get_char = sci_poll_get_char,
  1273. .poll_put_char = sci_poll_put_char,
  1274. #endif
  1275. };
  1276. static void __devinit sci_init_single(struct platform_device *dev,
  1277. struct sci_port *sci_port,
  1278. unsigned int index,
  1279. struct plat_sci_port *p)
  1280. {
  1281. struct uart_port *port = &sci_port->port;
  1282. port->ops = &sci_uart_ops;
  1283. port->iotype = UPIO_MEM;
  1284. port->line = index;
  1285. switch (p->type) {
  1286. case PORT_SCIFA:
  1287. port->fifosize = 64;
  1288. break;
  1289. case PORT_SCIF:
  1290. port->fifosize = 16;
  1291. break;
  1292. default:
  1293. port->fifosize = 1;
  1294. break;
  1295. }
  1296. if (dev) {
  1297. sci_port->iclk = p->clk ? clk_get(&dev->dev, p->clk) : NULL;
  1298. sci_port->dclk = clk_get(&dev->dev, "peripheral_clk");
  1299. sci_port->enable = sci_clk_enable;
  1300. sci_port->disable = sci_clk_disable;
  1301. port->dev = &dev->dev;
  1302. }
  1303. sci_port->break_timer.data = (unsigned long)sci_port;
  1304. sci_port->break_timer.function = sci_break_timer;
  1305. init_timer(&sci_port->break_timer);
  1306. port->mapbase = p->mapbase;
  1307. port->membase = p->membase;
  1308. port->irq = p->irqs[SCIx_TXI_IRQ];
  1309. port->flags = p->flags;
  1310. sci_port->type = port->type = p->type;
  1311. #ifdef CONFIG_SERIAL_SH_SCI_DMA
  1312. sci_port->dma_dev = p->dma_dev;
  1313. sci_port->slave_tx = p->dma_slave_tx;
  1314. sci_port->slave_rx = p->dma_slave_rx;
  1315. dev_dbg(port->dev, "%s: DMA device %p, tx %d, rx %d\n", __func__,
  1316. p->dma_dev, p->dma_slave_tx, p->dma_slave_rx);
  1317. #endif
  1318. memcpy(&sci_port->irqs, &p->irqs, sizeof(p->irqs));
  1319. }
  1320. #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
  1321. static struct tty_driver *serial_console_device(struct console *co, int *index)
  1322. {
  1323. struct uart_driver *p = &sci_uart_driver;
  1324. *index = co->index;
  1325. return p->tty_driver;
  1326. }
  1327. static void serial_console_putchar(struct uart_port *port, int ch)
  1328. {
  1329. sci_poll_put_char(port, ch);
  1330. }
  1331. /*
  1332. * Print a string to the serial port trying not to disturb
  1333. * any possible real use of the port...
  1334. */
  1335. static void serial_console_write(struct console *co, const char *s,
  1336. unsigned count)
  1337. {
  1338. struct uart_port *port = co->data;
  1339. struct sci_port *sci_port = to_sci_port(port);
  1340. unsigned short bits;
  1341. if (sci_port->enable)
  1342. sci_port->enable(port);
  1343. uart_console_write(port, s, count, serial_console_putchar);
  1344. /* wait until fifo is empty and last bit has been transmitted */
  1345. bits = SCxSR_TDxE(port) | SCxSR_TEND(port);
  1346. while ((sci_in(port, SCxSR) & bits) != bits)
  1347. cpu_relax();
  1348. if (sci_port->disable)
  1349. sci_port->disable(port);
  1350. }
  1351. static int __devinit serial_console_setup(struct console *co, char *options)
  1352. {
  1353. struct sci_port *sci_port;
  1354. struct uart_port *port;
  1355. int baud = 115200;
  1356. int bits = 8;
  1357. int parity = 'n';
  1358. int flow = 'n';
  1359. int ret;
  1360. /*
  1361. * Check whether an invalid uart number has been specified, and
  1362. * if so, search for the first available port that does have
  1363. * console support.
  1364. */
  1365. if (co->index >= SCI_NPORTS)
  1366. co->index = 0;
  1367. if (co->data) {
  1368. port = co->data;
  1369. sci_port = to_sci_port(port);
  1370. } else {
  1371. sci_port = &sci_ports[co->index];
  1372. port = &sci_port->port;
  1373. co->data = port;
  1374. }
  1375. /*
  1376. * Also need to check port->type, we don't actually have any
  1377. * UPIO_PORT ports, but uart_report_port() handily misreports
  1378. * it anyways if we don't have a port available by the time this is
  1379. * called.
  1380. */
  1381. if (!port->type)
  1382. return -ENODEV;
  1383. sci_config_port(port, 0);
  1384. if (sci_port->enable)
  1385. sci_port->enable(port);
  1386. if (options)
  1387. uart_parse_options(options, &baud, &parity, &bits, &flow);
  1388. ret = uart_set_options(port, co, baud, parity, bits, flow);
  1389. #if defined(__H8300H__) || defined(__H8300S__)
  1390. /* disable rx interrupt */
  1391. if (ret == 0)
  1392. sci_stop_rx(port);
  1393. #endif
  1394. /* TODO: disable clock */
  1395. return ret;
  1396. }
  1397. static struct console serial_console = {
  1398. .name = "ttySC",
  1399. .device = serial_console_device,
  1400. .write = serial_console_write,
  1401. .setup = serial_console_setup,
  1402. .flags = CON_PRINTBUFFER,
  1403. .index = -1,
  1404. };
  1405. static int __init sci_console_init(void)
  1406. {
  1407. register_console(&serial_console);
  1408. return 0;
  1409. }
  1410. console_initcall(sci_console_init);
  1411. static struct sci_port early_serial_port;
  1412. static struct console early_serial_console = {
  1413. .name = "early_ttySC",
  1414. .write = serial_console_write,
  1415. .flags = CON_PRINTBUFFER,
  1416. };
  1417. static char early_serial_buf[32];
  1418. #endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */
  1419. #if defined(CONFIG_SERIAL_SH_SCI_CONSOLE)
  1420. #define SCI_CONSOLE (&serial_console)
  1421. #else
  1422. #define SCI_CONSOLE 0
  1423. #endif
  1424. static char banner[] __initdata =
  1425. KERN_INFO "SuperH SCI(F) driver initialized\n";
  1426. static struct uart_driver sci_uart_driver = {
  1427. .owner = THIS_MODULE,
  1428. .driver_name = "sci",
  1429. .dev_name = "ttySC",
  1430. .major = SCI_MAJOR,
  1431. .minor = SCI_MINOR_START,
  1432. .nr = SCI_NPORTS,
  1433. .cons = SCI_CONSOLE,
  1434. };
  1435. static int sci_remove(struct platform_device *dev)
  1436. {
  1437. struct sh_sci_priv *priv = platform_get_drvdata(dev);
  1438. struct sci_port *p;
  1439. unsigned long flags;
  1440. cpufreq_unregister_notifier(&priv->clk_nb, CPUFREQ_TRANSITION_NOTIFIER);
  1441. spin_lock_irqsave(&priv->lock, flags);
  1442. list_for_each_entry(p, &priv->ports, node)
  1443. uart_remove_one_port(&sci_uart_driver, &p->port);
  1444. spin_unlock_irqrestore(&priv->lock, flags);
  1445. kfree(priv);
  1446. return 0;
  1447. }
  1448. static int __devinit sci_probe_single(struct platform_device *dev,
  1449. unsigned int index,
  1450. struct plat_sci_port *p,
  1451. struct sci_port *sciport)
  1452. {
  1453. struct sh_sci_priv *priv = platform_get_drvdata(dev);
  1454. unsigned long flags;
  1455. int ret;
  1456. /* Sanity check */
  1457. if (unlikely(index >= SCI_NPORTS)) {
  1458. dev_notice(&dev->dev, "Attempting to register port "
  1459. "%d when only %d are available.\n",
  1460. index+1, SCI_NPORTS);
  1461. dev_notice(&dev->dev, "Consider bumping "
  1462. "CONFIG_SERIAL_SH_SCI_NR_UARTS!\n");
  1463. return 0;
  1464. }
  1465. sci_init_single(dev, sciport, index, p);
  1466. ret = uart_add_one_port(&sci_uart_driver, &sciport->port);
  1467. if (ret)
  1468. return ret;
  1469. INIT_LIST_HEAD(&sciport->node);
  1470. spin_lock_irqsave(&priv->lock, flags);
  1471. list_add(&sciport->node, &priv->ports);
  1472. spin_unlock_irqrestore(&priv->lock, flags);
  1473. return 0;
  1474. }
  1475. /*
  1476. * Register a set of serial devices attached to a platform device. The
  1477. * list is terminated with a zero flags entry, which means we expect
  1478. * all entries to have at least UPF_BOOT_AUTOCONF set. Platforms that need
  1479. * remapping (such as sh64) should also set UPF_IOREMAP.
  1480. */
  1481. static int __devinit sci_probe(struct platform_device *dev)
  1482. {
  1483. struct plat_sci_port *p = dev->dev.platform_data;
  1484. struct sh_sci_priv *priv;
  1485. int i, ret = -EINVAL;
  1486. #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
  1487. if (is_early_platform_device(dev)) {
  1488. if (dev->id == -1)
  1489. return -ENOTSUPP;
  1490. early_serial_console.index = dev->id;
  1491. early_serial_console.data = &early_serial_port.port;
  1492. sci_init_single(NULL, &early_serial_port, dev->id, p);
  1493. serial_console_setup(&early_serial_console, early_serial_buf);
  1494. if (!strstr(early_serial_buf, "keep"))
  1495. early_serial_console.flags |= CON_BOOT;
  1496. register_console(&early_serial_console);
  1497. return 0;
  1498. }
  1499. #endif
  1500. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  1501. if (!priv)
  1502. return -ENOMEM;
  1503. INIT_LIST_HEAD(&priv->ports);
  1504. spin_lock_init(&priv->lock);
  1505. platform_set_drvdata(dev, priv);
  1506. priv->clk_nb.notifier_call = sci_notifier;
  1507. cpufreq_register_notifier(&priv->clk_nb, CPUFREQ_TRANSITION_NOTIFIER);
  1508. if (dev->id != -1) {
  1509. ret = sci_probe_single(dev, dev->id, p, &sci_ports[dev->id]);
  1510. if (ret)
  1511. goto err_unreg;
  1512. } else {
  1513. for (i = 0; p && p->flags != 0; p++, i++) {
  1514. ret = sci_probe_single(dev, i, p, &sci_ports[i]);
  1515. if (ret)
  1516. goto err_unreg;
  1517. }
  1518. }
  1519. #ifdef CONFIG_SH_STANDARD_BIOS
  1520. sh_bios_gdb_detach();
  1521. #endif
  1522. return 0;
  1523. err_unreg:
  1524. sci_remove(dev);
  1525. return ret;
  1526. }
  1527. static int sci_suspend(struct device *dev)
  1528. {
  1529. struct sh_sci_priv *priv = dev_get_drvdata(dev);
  1530. struct sci_port *p;
  1531. unsigned long flags;
  1532. spin_lock_irqsave(&priv->lock, flags);
  1533. list_for_each_entry(p, &priv->ports, node)
  1534. uart_suspend_port(&sci_uart_driver, &p->port);
  1535. spin_unlock_irqrestore(&priv->lock, flags);
  1536. return 0;
  1537. }
  1538. static int sci_resume(struct device *dev)
  1539. {
  1540. struct sh_sci_priv *priv = dev_get_drvdata(dev);
  1541. struct sci_port *p;
  1542. unsigned long flags;
  1543. spin_lock_irqsave(&priv->lock, flags);
  1544. list_for_each_entry(p, &priv->ports, node)
  1545. uart_resume_port(&sci_uart_driver, &p->port);
  1546. spin_unlock_irqrestore(&priv->lock, flags);
  1547. return 0;
  1548. }
  1549. static const struct dev_pm_ops sci_dev_pm_ops = {
  1550. .suspend = sci_suspend,
  1551. .resume = sci_resume,
  1552. };
  1553. static struct platform_driver sci_driver = {
  1554. .probe = sci_probe,
  1555. .remove = sci_remove,
  1556. .driver = {
  1557. .name = "sh-sci",
  1558. .owner = THIS_MODULE,
  1559. .pm = &sci_dev_pm_ops,
  1560. },
  1561. };
  1562. static int __init sci_init(void)
  1563. {
  1564. int ret;
  1565. printk(banner);
  1566. ret = uart_register_driver(&sci_uart_driver);
  1567. if (likely(ret == 0)) {
  1568. ret = platform_driver_register(&sci_driver);
  1569. if (unlikely(ret))
  1570. uart_unregister_driver(&sci_uart_driver);
  1571. }
  1572. return ret;
  1573. }
  1574. static void __exit sci_exit(void)
  1575. {
  1576. platform_driver_unregister(&sci_driver);
  1577. uart_unregister_driver(&sci_uart_driver);
  1578. }
  1579. #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
  1580. early_platform_init_buffer("earlyprintk", &sci_driver,
  1581. early_serial_buf, ARRAY_SIZE(early_serial_buf));
  1582. #endif
  1583. module_init(sci_init);
  1584. module_exit(sci_exit);
  1585. MODULE_LICENSE("GPL");
  1586. MODULE_ALIAS("platform:sh-sci");