sh-sci.c 46 KB

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