sh-sci.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936
  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. WARN_ONCE(ret == IRQ_NONE,
  660. "%s: %d IRQ %d, status %x, control %x\n", __func__,
  661. irq, port->line, ssr_status, scr_status);
  662. return ret;
  663. }
  664. /*
  665. * Here we define a transistion notifier so that we can update all of our
  666. * ports' baud rate when the peripheral clock changes.
  667. */
  668. static int sci_notifier(struct notifier_block *self,
  669. unsigned long phase, void *p)
  670. {
  671. struct sh_sci_priv *priv = container_of(self,
  672. struct sh_sci_priv, clk_nb);
  673. struct sci_port *sci_port;
  674. unsigned long flags;
  675. if ((phase == CPUFREQ_POSTCHANGE) ||
  676. (phase == CPUFREQ_RESUMECHANGE)) {
  677. spin_lock_irqsave(&priv->lock, flags);
  678. list_for_each_entry(sci_port, &priv->ports, node)
  679. sci_port->port.uartclk = clk_get_rate(sci_port->dclk);
  680. spin_unlock_irqrestore(&priv->lock, flags);
  681. }
  682. return NOTIFY_OK;
  683. }
  684. static void sci_clk_enable(struct uart_port *port)
  685. {
  686. struct sci_port *sci_port = to_sci_port(port);
  687. clk_enable(sci_port->dclk);
  688. sci_port->port.uartclk = clk_get_rate(sci_port->dclk);
  689. if (sci_port->iclk)
  690. clk_enable(sci_port->iclk);
  691. }
  692. static void sci_clk_disable(struct uart_port *port)
  693. {
  694. struct sci_port *sci_port = to_sci_port(port);
  695. if (sci_port->iclk)
  696. clk_disable(sci_port->iclk);
  697. clk_disable(sci_port->dclk);
  698. }
  699. static int sci_request_irq(struct sci_port *port)
  700. {
  701. int i;
  702. irqreturn_t (*handlers[4])(int irq, void *ptr) = {
  703. sci_er_interrupt, sci_rx_interrupt, sci_tx_interrupt,
  704. sci_br_interrupt,
  705. };
  706. const char *desc[] = { "SCI Receive Error", "SCI Receive Data Full",
  707. "SCI Transmit Data Empty", "SCI Break" };
  708. if (port->irqs[0] == port->irqs[1]) {
  709. if (unlikely(!port->irqs[0]))
  710. return -ENODEV;
  711. if (request_irq(port->irqs[0], sci_mpxed_interrupt,
  712. IRQF_DISABLED, "sci", port)) {
  713. dev_err(port->port.dev, "Can't allocate IRQ\n");
  714. return -ENODEV;
  715. }
  716. } else {
  717. for (i = 0; i < ARRAY_SIZE(handlers); i++) {
  718. if (unlikely(!port->irqs[i]))
  719. continue;
  720. if (request_irq(port->irqs[i], handlers[i],
  721. IRQF_DISABLED, desc[i], port)) {
  722. dev_err(port->port.dev, "Can't allocate IRQ\n");
  723. return -ENODEV;
  724. }
  725. }
  726. }
  727. return 0;
  728. }
  729. static void sci_free_irq(struct sci_port *port)
  730. {
  731. int i;
  732. if (port->irqs[0] == port->irqs[1])
  733. free_irq(port->irqs[0], port);
  734. else {
  735. for (i = 0; i < ARRAY_SIZE(port->irqs); i++) {
  736. if (!port->irqs[i])
  737. continue;
  738. free_irq(port->irqs[i], port);
  739. }
  740. }
  741. }
  742. static unsigned int sci_tx_empty(struct uart_port *port)
  743. {
  744. unsigned short status = sci_in(port, SCxSR);
  745. unsigned short in_tx_fifo = scif_txfill(port);
  746. return (status & SCxSR_TEND(port)) && !in_tx_fifo ? TIOCSER_TEMT : 0;
  747. }
  748. static void sci_set_mctrl(struct uart_port *port, unsigned int mctrl)
  749. {
  750. /* This routine is used for seting signals of: DTR, DCD, CTS/RTS */
  751. /* We use SCIF's hardware for CTS/RTS, so don't need any for that. */
  752. /* If you have signals for DTR and DCD, please implement here. */
  753. }
  754. static unsigned int sci_get_mctrl(struct uart_port *port)
  755. {
  756. /* This routine is used for getting signals of: DTR, DCD, DSR, RI,
  757. and CTS/RTS */
  758. return TIOCM_DTR | TIOCM_RTS | TIOCM_DSR;
  759. }
  760. #ifdef CONFIG_SERIAL_SH_SCI_DMA
  761. static void sci_dma_tx_complete(void *arg)
  762. {
  763. struct sci_port *s = arg;
  764. struct uart_port *port = &s->port;
  765. struct circ_buf *xmit = &port->state->xmit;
  766. unsigned long flags;
  767. dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
  768. spin_lock_irqsave(&port->lock, flags);
  769. xmit->tail += s->sg_tx.length;
  770. xmit->tail &= UART_XMIT_SIZE - 1;
  771. port->icount.tx += s->sg_tx.length;
  772. async_tx_ack(s->desc_tx);
  773. s->cookie_tx = -EINVAL;
  774. s->desc_tx = NULL;
  775. spin_unlock_irqrestore(&port->lock, flags);
  776. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  777. uart_write_wakeup(port);
  778. if (uart_circ_chars_pending(xmit))
  779. schedule_work(&s->work_tx);
  780. }
  781. /* Locking: called with port lock held */
  782. static int sci_dma_rx_push(struct sci_port *s, struct tty_struct *tty,
  783. size_t count)
  784. {
  785. struct uart_port *port = &s->port;
  786. int i, active, room;
  787. room = tty_buffer_request_room(tty, count);
  788. if (s->active_rx == s->cookie_rx[0]) {
  789. active = 0;
  790. } else if (s->active_rx == s->cookie_rx[1]) {
  791. active = 1;
  792. } else {
  793. dev_err(port->dev, "cookie %d not found!\n", s->active_rx);
  794. return 0;
  795. }
  796. if (room < count)
  797. dev_warn(port->dev, "Rx overrun: dropping %u bytes\n",
  798. count - room);
  799. if (!room)
  800. return room;
  801. for (i = 0; i < room; i++)
  802. tty_insert_flip_char(tty, ((u8 *)sg_virt(&s->sg_rx[active]))[i],
  803. TTY_NORMAL);
  804. port->icount.rx += room;
  805. return room;
  806. }
  807. static void sci_dma_rx_complete(void *arg)
  808. {
  809. struct sci_port *s = arg;
  810. struct uart_port *port = &s->port;
  811. struct tty_struct *tty = port->state->port.tty;
  812. unsigned long flags;
  813. int count;
  814. dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
  815. spin_lock_irqsave(&port->lock, flags);
  816. count = sci_dma_rx_push(s, tty, s->buf_len_rx);
  817. mod_timer(&s->rx_timer, jiffies + msecs_to_jiffies(5));
  818. spin_unlock_irqrestore(&port->lock, flags);
  819. if (count)
  820. tty_flip_buffer_push(tty);
  821. schedule_work(&s->work_rx);
  822. }
  823. static void sci_start_rx(struct uart_port *port);
  824. static void sci_start_tx(struct uart_port *port);
  825. static void sci_rx_dma_release(struct sci_port *s, bool enable_pio)
  826. {
  827. struct dma_chan *chan = s->chan_rx;
  828. struct uart_port *port = &s->port;
  829. s->chan_rx = NULL;
  830. s->cookie_rx[0] = s->cookie_rx[1] = -EINVAL;
  831. dma_release_channel(chan);
  832. dma_free_coherent(port->dev, s->buf_len_rx * 2,
  833. sg_virt(&s->sg_rx[0]), sg_dma_address(&s->sg_rx[0]));
  834. if (enable_pio)
  835. sci_start_rx(port);
  836. }
  837. static void sci_tx_dma_release(struct sci_port *s, bool enable_pio)
  838. {
  839. struct dma_chan *chan = s->chan_tx;
  840. struct uart_port *port = &s->port;
  841. s->chan_tx = NULL;
  842. s->cookie_tx = -EINVAL;
  843. dma_release_channel(chan);
  844. if (enable_pio)
  845. sci_start_tx(port);
  846. }
  847. static void sci_submit_rx(struct sci_port *s)
  848. {
  849. struct dma_chan *chan = s->chan_rx;
  850. int i;
  851. for (i = 0; i < 2; i++) {
  852. struct scatterlist *sg = &s->sg_rx[i];
  853. struct dma_async_tx_descriptor *desc;
  854. desc = chan->device->device_prep_slave_sg(chan,
  855. sg, 1, DMA_FROM_DEVICE, DMA_PREP_INTERRUPT);
  856. if (desc) {
  857. s->desc_rx[i] = desc;
  858. desc->callback = sci_dma_rx_complete;
  859. desc->callback_param = s;
  860. s->cookie_rx[i] = desc->tx_submit(desc);
  861. }
  862. if (!desc || s->cookie_rx[i] < 0) {
  863. if (i) {
  864. async_tx_ack(s->desc_rx[0]);
  865. s->cookie_rx[0] = -EINVAL;
  866. }
  867. if (desc) {
  868. async_tx_ack(desc);
  869. s->cookie_rx[i] = -EINVAL;
  870. }
  871. dev_warn(s->port.dev,
  872. "failed to re-start DMA, using PIO\n");
  873. sci_rx_dma_release(s, true);
  874. return;
  875. }
  876. }
  877. s->active_rx = s->cookie_rx[0];
  878. dma_async_issue_pending(chan);
  879. }
  880. static void work_fn_rx(struct work_struct *work)
  881. {
  882. struct sci_port *s = container_of(work, struct sci_port, work_rx);
  883. struct uart_port *port = &s->port;
  884. struct dma_async_tx_descriptor *desc;
  885. int new;
  886. if (s->active_rx == s->cookie_rx[0]) {
  887. new = 0;
  888. } else if (s->active_rx == s->cookie_rx[1]) {
  889. new = 1;
  890. } else {
  891. dev_err(port->dev, "cookie %d not found!\n", s->active_rx);
  892. return;
  893. }
  894. desc = s->desc_rx[new];
  895. if (dma_async_is_tx_complete(s->chan_rx, s->active_rx, NULL, NULL) !=
  896. DMA_SUCCESS) {
  897. /* Handle incomplete DMA receive */
  898. struct tty_struct *tty = port->state->port.tty;
  899. struct dma_chan *chan = s->chan_rx;
  900. struct sh_desc *sh_desc = container_of(desc, struct sh_desc,
  901. async_tx);
  902. unsigned long flags;
  903. int count;
  904. chan->device->device_control(chan, DMA_TERMINATE_ALL, 0);
  905. dev_dbg(port->dev, "Read %u bytes with cookie %d\n",
  906. sh_desc->partial, sh_desc->cookie);
  907. spin_lock_irqsave(&port->lock, flags);
  908. count = sci_dma_rx_push(s, tty, sh_desc->partial);
  909. spin_unlock_irqrestore(&port->lock, flags);
  910. if (count)
  911. tty_flip_buffer_push(tty);
  912. sci_submit_rx(s);
  913. return;
  914. }
  915. s->cookie_rx[new] = desc->tx_submit(desc);
  916. if (s->cookie_rx[new] < 0) {
  917. dev_warn(port->dev, "Failed submitting Rx DMA descriptor\n");
  918. sci_rx_dma_release(s, true);
  919. return;
  920. }
  921. dev_dbg(port->dev, "%s: cookie %d #%d\n", __func__,
  922. s->cookie_rx[new], new);
  923. s->active_rx = s->cookie_rx[!new];
  924. }
  925. static void work_fn_tx(struct work_struct *work)
  926. {
  927. struct sci_port *s = container_of(work, struct sci_port, work_tx);
  928. struct dma_async_tx_descriptor *desc;
  929. struct dma_chan *chan = s->chan_tx;
  930. struct uart_port *port = &s->port;
  931. struct circ_buf *xmit = &port->state->xmit;
  932. struct scatterlist *sg = &s->sg_tx;
  933. /*
  934. * DMA is idle now.
  935. * Port xmit buffer is already mapped, and it is one page... Just adjust
  936. * offsets and lengths. Since it is a circular buffer, we have to
  937. * transmit till the end, and then the rest. Take the port lock to get a
  938. * consistent xmit buffer state.
  939. */
  940. spin_lock_irq(&port->lock);
  941. sg->offset = xmit->tail & (UART_XMIT_SIZE - 1);
  942. sg->dma_address = (sg_dma_address(sg) & ~(UART_XMIT_SIZE - 1)) +
  943. sg->offset;
  944. sg->length = min((int)CIRC_CNT(xmit->head, xmit->tail, UART_XMIT_SIZE),
  945. CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE));
  946. sg->dma_length = sg->length;
  947. spin_unlock_irq(&port->lock);
  948. BUG_ON(!sg->length);
  949. desc = chan->device->device_prep_slave_sg(chan,
  950. sg, s->sg_len_tx, DMA_TO_DEVICE,
  951. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  952. if (!desc) {
  953. /* switch to PIO */
  954. sci_tx_dma_release(s, true);
  955. return;
  956. }
  957. dma_sync_sg_for_device(port->dev, sg, 1, DMA_TO_DEVICE);
  958. spin_lock_irq(&port->lock);
  959. s->desc_tx = desc;
  960. desc->callback = sci_dma_tx_complete;
  961. desc->callback_param = s;
  962. spin_unlock_irq(&port->lock);
  963. s->cookie_tx = desc->tx_submit(desc);
  964. if (s->cookie_tx < 0) {
  965. dev_warn(port->dev, "Failed submitting Tx DMA descriptor\n");
  966. /* switch to PIO */
  967. sci_tx_dma_release(s, true);
  968. return;
  969. }
  970. dev_dbg(port->dev, "%s: %p: %d...%d, cookie %d\n", __func__,
  971. xmit->buf, xmit->tail, xmit->head, s->cookie_tx);
  972. dma_async_issue_pending(chan);
  973. }
  974. #endif
  975. static void sci_start_tx(struct uart_port *port)
  976. {
  977. unsigned short ctrl;
  978. #ifdef CONFIG_SERIAL_SH_SCI_DMA
  979. struct sci_port *s = to_sci_port(port);
  980. if (s->chan_tx) {
  981. if (!uart_circ_empty(&s->port.state->xmit) && s->cookie_tx < 0)
  982. schedule_work(&s->work_tx);
  983. return;
  984. }
  985. #endif
  986. /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */
  987. ctrl = sci_in(port, SCSCR);
  988. ctrl |= SCI_CTRL_FLAGS_TIE;
  989. sci_out(port, SCSCR, ctrl);
  990. }
  991. static void sci_stop_tx(struct uart_port *port)
  992. {
  993. unsigned short ctrl;
  994. /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */
  995. ctrl = sci_in(port, SCSCR);
  996. ctrl &= ~SCI_CTRL_FLAGS_TIE;
  997. sci_out(port, SCSCR, ctrl);
  998. }
  999. static void sci_start_rx(struct uart_port *port)
  1000. {
  1001. unsigned short ctrl = SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE;
  1002. /* Set RIE (Receive Interrupt Enable) bit in SCSCR */
  1003. ctrl |= sci_in(port, SCSCR);
  1004. sci_out(port, SCSCR, ctrl);
  1005. }
  1006. static void sci_stop_rx(struct uart_port *port)
  1007. {
  1008. unsigned short ctrl;
  1009. /* Clear RIE (Receive Interrupt Enable) bit in SCSCR */
  1010. ctrl = sci_in(port, SCSCR);
  1011. ctrl &= ~(SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE);
  1012. sci_out(port, SCSCR, ctrl);
  1013. }
  1014. static void sci_enable_ms(struct uart_port *port)
  1015. {
  1016. /* Nothing here yet .. */
  1017. }
  1018. static void sci_break_ctl(struct uart_port *port, int break_state)
  1019. {
  1020. /* Nothing here yet .. */
  1021. }
  1022. #ifdef CONFIG_SERIAL_SH_SCI_DMA
  1023. static bool filter(struct dma_chan *chan, void *slave)
  1024. {
  1025. struct sh_dmae_slave *param = slave;
  1026. dev_dbg(chan->device->dev, "%s: slave ID %d\n", __func__,
  1027. param->slave_id);
  1028. if (param->dma_dev == chan->device->dev) {
  1029. chan->private = param;
  1030. return true;
  1031. } else {
  1032. return false;
  1033. }
  1034. }
  1035. static void rx_timer_fn(unsigned long arg)
  1036. {
  1037. struct sci_port *s = (struct sci_port *)arg;
  1038. struct uart_port *port = &s->port;
  1039. u16 scr = sci_in(port, SCSCR);
  1040. sci_out(port, SCSCR, scr | SCI_CTRL_FLAGS_RIE);
  1041. dev_dbg(port->dev, "DMA Rx timed out\n");
  1042. schedule_work(&s->work_rx);
  1043. }
  1044. static void sci_request_dma(struct uart_port *port)
  1045. {
  1046. struct sci_port *s = to_sci_port(port);
  1047. struct sh_dmae_slave *param;
  1048. struct dma_chan *chan;
  1049. dma_cap_mask_t mask;
  1050. int nent;
  1051. dev_dbg(port->dev, "%s: port %d DMA %p\n", __func__,
  1052. port->line, s->dma_dev);
  1053. if (!s->dma_dev)
  1054. return;
  1055. dma_cap_zero(mask);
  1056. dma_cap_set(DMA_SLAVE, mask);
  1057. param = &s->param_tx;
  1058. /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_TX */
  1059. param->slave_id = s->slave_tx;
  1060. param->dma_dev = s->dma_dev;
  1061. s->cookie_tx = -EINVAL;
  1062. chan = dma_request_channel(mask, filter, param);
  1063. dev_dbg(port->dev, "%s: TX: got channel %p\n", __func__, chan);
  1064. if (chan) {
  1065. s->chan_tx = chan;
  1066. sg_init_table(&s->sg_tx, 1);
  1067. /* UART circular tx buffer is an aligned page. */
  1068. BUG_ON((int)port->state->xmit.buf & ~PAGE_MASK);
  1069. sg_set_page(&s->sg_tx, virt_to_page(port->state->xmit.buf),
  1070. UART_XMIT_SIZE, (int)port->state->xmit.buf & ~PAGE_MASK);
  1071. nent = dma_map_sg(port->dev, &s->sg_tx, 1, DMA_TO_DEVICE);
  1072. if (!nent)
  1073. sci_tx_dma_release(s, false);
  1074. else
  1075. dev_dbg(port->dev, "%s: mapped %d@%p to %x\n", __func__,
  1076. sg_dma_len(&s->sg_tx),
  1077. port->state->xmit.buf, sg_dma_address(&s->sg_tx));
  1078. s->sg_len_tx = nent;
  1079. INIT_WORK(&s->work_tx, work_fn_tx);
  1080. }
  1081. param = &s->param_rx;
  1082. /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_RX */
  1083. param->slave_id = s->slave_rx;
  1084. param->dma_dev = s->dma_dev;
  1085. chan = dma_request_channel(mask, filter, param);
  1086. dev_dbg(port->dev, "%s: RX: got channel %p\n", __func__, chan);
  1087. if (chan) {
  1088. dma_addr_t dma[2];
  1089. void *buf[2];
  1090. int i;
  1091. s->chan_rx = chan;
  1092. s->buf_len_rx = 2 * max(16, (int)port->fifosize);
  1093. buf[0] = dma_alloc_coherent(port->dev, s->buf_len_rx * 2,
  1094. &dma[0], GFP_KERNEL);
  1095. if (!buf[0]) {
  1096. dev_warn(port->dev,
  1097. "failed to allocate dma buffer, using PIO\n");
  1098. sci_rx_dma_release(s, true);
  1099. return;
  1100. }
  1101. buf[1] = buf[0] + s->buf_len_rx;
  1102. dma[1] = dma[0] + s->buf_len_rx;
  1103. for (i = 0; i < 2; i++) {
  1104. struct scatterlist *sg = &s->sg_rx[i];
  1105. sg_init_table(sg, 1);
  1106. sg_set_page(sg, virt_to_page(buf[i]), s->buf_len_rx,
  1107. (int)buf[i] & ~PAGE_MASK);
  1108. sg->dma_address = dma[i];
  1109. sg->dma_length = sg->length;
  1110. }
  1111. INIT_WORK(&s->work_rx, work_fn_rx);
  1112. setup_timer(&s->rx_timer, rx_timer_fn, (unsigned long)s);
  1113. sci_submit_rx(s);
  1114. }
  1115. }
  1116. static void sci_free_dma(struct uart_port *port)
  1117. {
  1118. struct sci_port *s = to_sci_port(port);
  1119. if (!s->dma_dev)
  1120. return;
  1121. if (s->chan_tx)
  1122. sci_tx_dma_release(s, false);
  1123. if (s->chan_rx)
  1124. sci_rx_dma_release(s, false);
  1125. }
  1126. #endif
  1127. static int sci_startup(struct uart_port *port)
  1128. {
  1129. struct sci_port *s = to_sci_port(port);
  1130. dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
  1131. if (s->enable)
  1132. s->enable(port);
  1133. sci_request_irq(s);
  1134. #ifdef CONFIG_SERIAL_SH_SCI_DMA
  1135. sci_request_dma(port);
  1136. #endif
  1137. sci_start_tx(port);
  1138. sci_start_rx(port);
  1139. return 0;
  1140. }
  1141. static void sci_shutdown(struct uart_port *port)
  1142. {
  1143. struct sci_port *s = to_sci_port(port);
  1144. dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
  1145. sci_stop_rx(port);
  1146. sci_stop_tx(port);
  1147. #ifdef CONFIG_SERIAL_SH_SCI_DMA
  1148. sci_free_dma(port);
  1149. #endif
  1150. sci_free_irq(s);
  1151. if (s->disable)
  1152. s->disable(port);
  1153. }
  1154. static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
  1155. struct ktermios *old)
  1156. {
  1157. unsigned int status, baud, smr_val, max_baud;
  1158. int t = -1;
  1159. /*
  1160. * earlyprintk comes here early on with port->uartclk set to zero.
  1161. * the clock framework is not up and running at this point so here
  1162. * we assume that 115200 is the maximum baud rate. please note that
  1163. * the baud rate is not programmed during earlyprintk - it is assumed
  1164. * that the previous boot loader has enabled required clocks and
  1165. * setup the baud rate generator hardware for us already.
  1166. */
  1167. max_baud = port->uartclk ? port->uartclk / 16 : 115200;
  1168. baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
  1169. if (likely(baud && port->uartclk))
  1170. t = SCBRR_VALUE(baud, port->uartclk);
  1171. do {
  1172. status = sci_in(port, SCxSR);
  1173. } while (!(status & SCxSR_TEND(port)));
  1174. sci_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */
  1175. if (port->type != PORT_SCI)
  1176. sci_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST);
  1177. smr_val = sci_in(port, SCSMR) & 3;
  1178. if ((termios->c_cflag & CSIZE) == CS7)
  1179. smr_val |= 0x40;
  1180. if (termios->c_cflag & PARENB)
  1181. smr_val |= 0x20;
  1182. if (termios->c_cflag & PARODD)
  1183. smr_val |= 0x30;
  1184. if (termios->c_cflag & CSTOPB)
  1185. smr_val |= 0x08;
  1186. uart_update_timeout(port, termios->c_cflag, baud);
  1187. sci_out(port, SCSMR, smr_val);
  1188. dev_dbg(port->dev, "%s: SMR %x, t %x, SCSCR %x\n", __func__, smr_val, t,
  1189. SCSCR_INIT(port));
  1190. if (t > 0) {
  1191. if (t >= 256) {
  1192. sci_out(port, SCSMR, (sci_in(port, SCSMR) & ~3) | 1);
  1193. t >>= 2;
  1194. } else
  1195. sci_out(port, SCSMR, sci_in(port, SCSMR) & ~3);
  1196. sci_out(port, SCBRR, t);
  1197. udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */
  1198. }
  1199. sci_init_pins(port, termios->c_cflag);
  1200. sci_out(port, SCFCR, (termios->c_cflag & CRTSCTS) ? SCFCR_MCE : 0);
  1201. sci_out(port, SCSCR, SCSCR_INIT(port));
  1202. if ((termios->c_cflag & CREAD) != 0)
  1203. sci_start_rx(port);
  1204. }
  1205. static const char *sci_type(struct uart_port *port)
  1206. {
  1207. switch (port->type) {
  1208. case PORT_IRDA:
  1209. return "irda";
  1210. case PORT_SCI:
  1211. return "sci";
  1212. case PORT_SCIF:
  1213. return "scif";
  1214. case PORT_SCIFA:
  1215. return "scifa";
  1216. }
  1217. return NULL;
  1218. }
  1219. static void sci_release_port(struct uart_port *port)
  1220. {
  1221. /* Nothing here yet .. */
  1222. }
  1223. static int sci_request_port(struct uart_port *port)
  1224. {
  1225. /* Nothing here yet .. */
  1226. return 0;
  1227. }
  1228. static void sci_config_port(struct uart_port *port, int flags)
  1229. {
  1230. struct sci_port *s = to_sci_port(port);
  1231. port->type = s->type;
  1232. if (port->membase)
  1233. return;
  1234. if (port->flags & UPF_IOREMAP) {
  1235. port->membase = ioremap_nocache(port->mapbase, 0x40);
  1236. if (IS_ERR(port->membase))
  1237. dev_err(port->dev, "can't remap port#%d\n", port->line);
  1238. } else {
  1239. /*
  1240. * For the simple (and majority of) cases where we don't
  1241. * need to do any remapping, just cast the cookie
  1242. * directly.
  1243. */
  1244. port->membase = (void __iomem *)port->mapbase;
  1245. }
  1246. }
  1247. static int sci_verify_port(struct uart_port *port, struct serial_struct *ser)
  1248. {
  1249. struct sci_port *s = to_sci_port(port);
  1250. if (ser->irq != s->irqs[SCIx_TXI_IRQ] || ser->irq > nr_irqs)
  1251. return -EINVAL;
  1252. if (ser->baud_base < 2400)
  1253. /* No paper tape reader for Mitch.. */
  1254. return -EINVAL;
  1255. return 0;
  1256. }
  1257. static struct uart_ops sci_uart_ops = {
  1258. .tx_empty = sci_tx_empty,
  1259. .set_mctrl = sci_set_mctrl,
  1260. .get_mctrl = sci_get_mctrl,
  1261. .start_tx = sci_start_tx,
  1262. .stop_tx = sci_stop_tx,
  1263. .stop_rx = sci_stop_rx,
  1264. .enable_ms = sci_enable_ms,
  1265. .break_ctl = sci_break_ctl,
  1266. .startup = sci_startup,
  1267. .shutdown = sci_shutdown,
  1268. .set_termios = sci_set_termios,
  1269. .type = sci_type,
  1270. .release_port = sci_release_port,
  1271. .request_port = sci_request_port,
  1272. .config_port = sci_config_port,
  1273. .verify_port = sci_verify_port,
  1274. #ifdef CONFIG_CONSOLE_POLL
  1275. .poll_get_char = sci_poll_get_char,
  1276. .poll_put_char = sci_poll_put_char,
  1277. #endif
  1278. };
  1279. static void __devinit sci_init_single(struct platform_device *dev,
  1280. struct sci_port *sci_port,
  1281. unsigned int index,
  1282. struct plat_sci_port *p)
  1283. {
  1284. struct uart_port *port = &sci_port->port;
  1285. port->ops = &sci_uart_ops;
  1286. port->iotype = UPIO_MEM;
  1287. port->line = index;
  1288. switch (p->type) {
  1289. case PORT_SCIFA:
  1290. port->fifosize = 64;
  1291. break;
  1292. case PORT_SCIF:
  1293. port->fifosize = 16;
  1294. break;
  1295. default:
  1296. port->fifosize = 1;
  1297. break;
  1298. }
  1299. if (dev) {
  1300. sci_port->iclk = p->clk ? clk_get(&dev->dev, p->clk) : NULL;
  1301. sci_port->dclk = clk_get(&dev->dev, "peripheral_clk");
  1302. sci_port->enable = sci_clk_enable;
  1303. sci_port->disable = sci_clk_disable;
  1304. port->dev = &dev->dev;
  1305. }
  1306. sci_port->break_timer.data = (unsigned long)sci_port;
  1307. sci_port->break_timer.function = sci_break_timer;
  1308. init_timer(&sci_port->break_timer);
  1309. port->mapbase = p->mapbase;
  1310. port->membase = p->membase;
  1311. port->irq = p->irqs[SCIx_TXI_IRQ];
  1312. port->flags = p->flags;
  1313. sci_port->type = port->type = p->type;
  1314. #ifdef CONFIG_SERIAL_SH_SCI_DMA
  1315. sci_port->dma_dev = p->dma_dev;
  1316. sci_port->slave_tx = p->dma_slave_tx;
  1317. sci_port->slave_rx = p->dma_slave_rx;
  1318. dev_dbg(port->dev, "%s: DMA device %p, tx %d, rx %d\n", __func__,
  1319. p->dma_dev, p->dma_slave_tx, p->dma_slave_rx);
  1320. #endif
  1321. memcpy(&sci_port->irqs, &p->irqs, sizeof(p->irqs));
  1322. }
  1323. #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
  1324. static struct tty_driver *serial_console_device(struct console *co, int *index)
  1325. {
  1326. struct uart_driver *p = &sci_uart_driver;
  1327. *index = co->index;
  1328. return p->tty_driver;
  1329. }
  1330. static void serial_console_putchar(struct uart_port *port, int ch)
  1331. {
  1332. sci_poll_put_char(port, ch);
  1333. }
  1334. /*
  1335. * Print a string to the serial port trying not to disturb
  1336. * any possible real use of the port...
  1337. */
  1338. static void serial_console_write(struct console *co, const char *s,
  1339. unsigned count)
  1340. {
  1341. struct uart_port *port = co->data;
  1342. struct sci_port *sci_port = to_sci_port(port);
  1343. unsigned short bits;
  1344. if (sci_port->enable)
  1345. sci_port->enable(port);
  1346. uart_console_write(port, s, count, serial_console_putchar);
  1347. /* wait until fifo is empty and last bit has been transmitted */
  1348. bits = SCxSR_TDxE(port) | SCxSR_TEND(port);
  1349. while ((sci_in(port, SCxSR) & bits) != bits)
  1350. cpu_relax();
  1351. if (sci_port->disable)
  1352. sci_port->disable(port);
  1353. }
  1354. static int __devinit serial_console_setup(struct console *co, char *options)
  1355. {
  1356. struct sci_port *sci_port;
  1357. struct uart_port *port;
  1358. int baud = 115200;
  1359. int bits = 8;
  1360. int parity = 'n';
  1361. int flow = 'n';
  1362. int ret;
  1363. /*
  1364. * Check whether an invalid uart number has been specified, and
  1365. * if so, search for the first available port that does have
  1366. * console support.
  1367. */
  1368. if (co->index >= SCI_NPORTS)
  1369. co->index = 0;
  1370. if (co->data) {
  1371. port = co->data;
  1372. sci_port = to_sci_port(port);
  1373. } else {
  1374. sci_port = &sci_ports[co->index];
  1375. port = &sci_port->port;
  1376. co->data = port;
  1377. }
  1378. /*
  1379. * Also need to check port->type, we don't actually have any
  1380. * UPIO_PORT ports, but uart_report_port() handily misreports
  1381. * it anyways if we don't have a port available by the time this is
  1382. * called.
  1383. */
  1384. if (!port->type)
  1385. return -ENODEV;
  1386. sci_config_port(port, 0);
  1387. if (sci_port->enable)
  1388. sci_port->enable(port);
  1389. if (options)
  1390. uart_parse_options(options, &baud, &parity, &bits, &flow);
  1391. ret = uart_set_options(port, co, baud, parity, bits, flow);
  1392. #if defined(__H8300H__) || defined(__H8300S__)
  1393. /* disable rx interrupt */
  1394. if (ret == 0)
  1395. sci_stop_rx(port);
  1396. #endif
  1397. /* TODO: disable clock */
  1398. return ret;
  1399. }
  1400. static struct console serial_console = {
  1401. .name = "ttySC",
  1402. .device = serial_console_device,
  1403. .write = serial_console_write,
  1404. .setup = serial_console_setup,
  1405. .flags = CON_PRINTBUFFER,
  1406. .index = -1,
  1407. };
  1408. static int __init sci_console_init(void)
  1409. {
  1410. register_console(&serial_console);
  1411. return 0;
  1412. }
  1413. console_initcall(sci_console_init);
  1414. static struct sci_port early_serial_port;
  1415. static struct console early_serial_console = {
  1416. .name = "early_ttySC",
  1417. .write = serial_console_write,
  1418. .flags = CON_PRINTBUFFER,
  1419. };
  1420. static char early_serial_buf[32];
  1421. #endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */
  1422. #if defined(CONFIG_SERIAL_SH_SCI_CONSOLE)
  1423. #define SCI_CONSOLE (&serial_console)
  1424. #else
  1425. #define SCI_CONSOLE 0
  1426. #endif
  1427. static char banner[] __initdata =
  1428. KERN_INFO "SuperH SCI(F) driver initialized\n";
  1429. static struct uart_driver sci_uart_driver = {
  1430. .owner = THIS_MODULE,
  1431. .driver_name = "sci",
  1432. .dev_name = "ttySC",
  1433. .major = SCI_MAJOR,
  1434. .minor = SCI_MINOR_START,
  1435. .nr = SCI_NPORTS,
  1436. .cons = SCI_CONSOLE,
  1437. };
  1438. static int sci_remove(struct platform_device *dev)
  1439. {
  1440. struct sh_sci_priv *priv = platform_get_drvdata(dev);
  1441. struct sci_port *p;
  1442. unsigned long flags;
  1443. cpufreq_unregister_notifier(&priv->clk_nb, CPUFREQ_TRANSITION_NOTIFIER);
  1444. spin_lock_irqsave(&priv->lock, flags);
  1445. list_for_each_entry(p, &priv->ports, node)
  1446. uart_remove_one_port(&sci_uart_driver, &p->port);
  1447. spin_unlock_irqrestore(&priv->lock, flags);
  1448. kfree(priv);
  1449. return 0;
  1450. }
  1451. static int __devinit sci_probe_single(struct platform_device *dev,
  1452. unsigned int index,
  1453. struct plat_sci_port *p,
  1454. struct sci_port *sciport)
  1455. {
  1456. struct sh_sci_priv *priv = platform_get_drvdata(dev);
  1457. unsigned long flags;
  1458. int ret;
  1459. /* Sanity check */
  1460. if (unlikely(index >= SCI_NPORTS)) {
  1461. dev_notice(&dev->dev, "Attempting to register port "
  1462. "%d when only %d are available.\n",
  1463. index+1, SCI_NPORTS);
  1464. dev_notice(&dev->dev, "Consider bumping "
  1465. "CONFIG_SERIAL_SH_SCI_NR_UARTS!\n");
  1466. return 0;
  1467. }
  1468. sci_init_single(dev, sciport, index, p);
  1469. ret = uart_add_one_port(&sci_uart_driver, &sciport->port);
  1470. if (ret)
  1471. return ret;
  1472. INIT_LIST_HEAD(&sciport->node);
  1473. spin_lock_irqsave(&priv->lock, flags);
  1474. list_add(&sciport->node, &priv->ports);
  1475. spin_unlock_irqrestore(&priv->lock, flags);
  1476. return 0;
  1477. }
  1478. /*
  1479. * Register a set of serial devices attached to a platform device. The
  1480. * list is terminated with a zero flags entry, which means we expect
  1481. * all entries to have at least UPF_BOOT_AUTOCONF set. Platforms that need
  1482. * remapping (such as sh64) should also set UPF_IOREMAP.
  1483. */
  1484. static int __devinit sci_probe(struct platform_device *dev)
  1485. {
  1486. struct plat_sci_port *p = dev->dev.platform_data;
  1487. struct sh_sci_priv *priv;
  1488. int i, ret = -EINVAL;
  1489. #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
  1490. if (is_early_platform_device(dev)) {
  1491. if (dev->id == -1)
  1492. return -ENOTSUPP;
  1493. early_serial_console.index = dev->id;
  1494. early_serial_console.data = &early_serial_port.port;
  1495. sci_init_single(NULL, &early_serial_port, dev->id, p);
  1496. serial_console_setup(&early_serial_console, early_serial_buf);
  1497. if (!strstr(early_serial_buf, "keep"))
  1498. early_serial_console.flags |= CON_BOOT;
  1499. register_console(&early_serial_console);
  1500. return 0;
  1501. }
  1502. #endif
  1503. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  1504. if (!priv)
  1505. return -ENOMEM;
  1506. INIT_LIST_HEAD(&priv->ports);
  1507. spin_lock_init(&priv->lock);
  1508. platform_set_drvdata(dev, priv);
  1509. priv->clk_nb.notifier_call = sci_notifier;
  1510. cpufreq_register_notifier(&priv->clk_nb, CPUFREQ_TRANSITION_NOTIFIER);
  1511. if (dev->id != -1) {
  1512. ret = sci_probe_single(dev, dev->id, p, &sci_ports[dev->id]);
  1513. if (ret)
  1514. goto err_unreg;
  1515. } else {
  1516. for (i = 0; p && p->flags != 0; p++, i++) {
  1517. ret = sci_probe_single(dev, i, p, &sci_ports[i]);
  1518. if (ret)
  1519. goto err_unreg;
  1520. }
  1521. }
  1522. #ifdef CONFIG_SH_STANDARD_BIOS
  1523. sh_bios_gdb_detach();
  1524. #endif
  1525. return 0;
  1526. err_unreg:
  1527. sci_remove(dev);
  1528. return ret;
  1529. }
  1530. static int sci_suspend(struct device *dev)
  1531. {
  1532. struct sh_sci_priv *priv = dev_get_drvdata(dev);
  1533. struct sci_port *p;
  1534. unsigned long flags;
  1535. spin_lock_irqsave(&priv->lock, flags);
  1536. list_for_each_entry(p, &priv->ports, node)
  1537. uart_suspend_port(&sci_uart_driver, &p->port);
  1538. spin_unlock_irqrestore(&priv->lock, flags);
  1539. return 0;
  1540. }
  1541. static int sci_resume(struct device *dev)
  1542. {
  1543. struct sh_sci_priv *priv = dev_get_drvdata(dev);
  1544. struct sci_port *p;
  1545. unsigned long flags;
  1546. spin_lock_irqsave(&priv->lock, flags);
  1547. list_for_each_entry(p, &priv->ports, node)
  1548. uart_resume_port(&sci_uart_driver, &p->port);
  1549. spin_unlock_irqrestore(&priv->lock, flags);
  1550. return 0;
  1551. }
  1552. static const struct dev_pm_ops sci_dev_pm_ops = {
  1553. .suspend = sci_suspend,
  1554. .resume = sci_resume,
  1555. };
  1556. static struct platform_driver sci_driver = {
  1557. .probe = sci_probe,
  1558. .remove = sci_remove,
  1559. .driver = {
  1560. .name = "sh-sci",
  1561. .owner = THIS_MODULE,
  1562. .pm = &sci_dev_pm_ops,
  1563. },
  1564. };
  1565. static int __init sci_init(void)
  1566. {
  1567. int ret;
  1568. printk(banner);
  1569. ret = uart_register_driver(&sci_uart_driver);
  1570. if (likely(ret == 0)) {
  1571. ret = platform_driver_register(&sci_driver);
  1572. if (unlikely(ret))
  1573. uart_unregister_driver(&sci_uart_driver);
  1574. }
  1575. return ret;
  1576. }
  1577. static void __exit sci_exit(void)
  1578. {
  1579. platform_driver_unregister(&sci_driver);
  1580. uart_unregister_driver(&sci_uart_driver);
  1581. }
  1582. #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
  1583. early_platform_init_buffer("earlyprintk", &sci_driver,
  1584. early_serial_buf, ARRAY_SIZE(early_serial_buf));
  1585. #endif
  1586. module_init(sci_init);
  1587. module_exit(sci_exit);
  1588. MODULE_LICENSE("GPL");
  1589. MODULE_ALIAS("platform:sh-sci");