sh-sci.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476
  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 - 2006 Paul Mundt
  7. *
  8. * based off of the old drivers/char/sh-sci.c by:
  9. *
  10. * Copyright (C) 1999, 2000 Niibe Yutaka
  11. * Copyright (C) 2000 Sugioka Toshinobu
  12. * Modified to support multiple serial ports. Stuart Menefy (May 2000).
  13. * Modified to support SecureEdge. David McCullough (2002)
  14. * Modified to support SH7300 SCIF. Takashi Kusuda (Jun 2003).
  15. *
  16. * This file is subject to the terms and conditions of the GNU General Public
  17. * License. See the file "COPYING" in the main directory of this archive
  18. * for more details.
  19. */
  20. #undef DEBUG
  21. #include <linux/module.h>
  22. #include <linux/errno.h>
  23. #include <linux/timer.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/tty.h>
  26. #include <linux/tty_flip.h>
  27. #include <linux/serial.h>
  28. #include <linux/major.h>
  29. #include <linux/string.h>
  30. #include <linux/sysrq.h>
  31. #include <linux/ioport.h>
  32. #include <linux/mm.h>
  33. #include <linux/init.h>
  34. #include <linux/delay.h>
  35. #include <linux/console.h>
  36. #include <linux/platform_device.h>
  37. #ifdef CONFIG_CPU_FREQ
  38. #include <linux/notifier.h>
  39. #include <linux/cpufreq.h>
  40. #endif
  41. #if defined(CONFIG_SUPERH) && !defined(CONFIG_SUPERH64)
  42. #include <asm/clock.h>
  43. #include <asm/sh_bios.h>
  44. #include <asm/kgdb.h>
  45. #endif
  46. #include <asm/sci.h>
  47. #if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  48. #define SUPPORT_SYSRQ
  49. #endif
  50. #include "sh-sci.h"
  51. struct sci_port {
  52. struct uart_port port;
  53. /* Port type */
  54. unsigned int type;
  55. /* Port IRQs: ERI, RXI, TXI, BRI (optional) */
  56. unsigned int irqs[SCIx_NR_IRQS];
  57. /* Port pin configuration */
  58. void (*init_pins)(struct uart_port *port,
  59. unsigned int cflag);
  60. /* Port enable callback */
  61. void (*enable)(struct uart_port *port);
  62. /* Port disable callback */
  63. void (*disable)(struct uart_port *port);
  64. /* Break timer */
  65. struct timer_list break_timer;
  66. int break_flag;
  67. };
  68. #ifdef CONFIG_SH_KGDB
  69. static struct sci_port *kgdb_sci_port;
  70. #endif
  71. #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
  72. static struct sci_port *serial_console_port;
  73. #endif
  74. /* Function prototypes */
  75. static void sci_stop_tx(struct uart_port *port);
  76. #define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS
  77. static struct sci_port sci_ports[SCI_NPORTS];
  78. static struct uart_driver sci_uart_driver;
  79. #if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) && \
  80. defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
  81. static inline void handle_error(struct uart_port *port)
  82. {
  83. /* Clear error flags */
  84. sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
  85. }
  86. static int get_char(struct uart_port *port)
  87. {
  88. unsigned long flags;
  89. unsigned short status;
  90. int c;
  91. spin_lock_irqsave(&port->lock, flags);
  92. do {
  93. status = sci_in(port, SCxSR);
  94. if (status & SCxSR_ERRORS(port)) {
  95. handle_error(port);
  96. continue;
  97. }
  98. } while (!(status & SCxSR_RDxF(port)));
  99. c = sci_in(port, SCxRDR);
  100. sci_in(port, SCxSR); /* Dummy read */
  101. sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
  102. spin_unlock_irqrestore(&port->lock, flags);
  103. return c;
  104. }
  105. #endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */
  106. #if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) || defined(CONFIG_SH_KGDB)
  107. static void put_char(struct uart_port *port, char c)
  108. {
  109. unsigned long flags;
  110. unsigned short status;
  111. spin_lock_irqsave(&port->lock, flags);
  112. do {
  113. status = sci_in(port, SCxSR);
  114. } while (!(status & SCxSR_TDxE(port)));
  115. sci_out(port, SCxTDR, c);
  116. sci_in(port, SCxSR); /* Dummy read */
  117. sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
  118. spin_unlock_irqrestore(&port->lock, flags);
  119. }
  120. #endif
  121. #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
  122. static void put_string(struct sci_port *sci_port, const char *buffer, int count)
  123. {
  124. struct uart_port *port = &sci_port->port;
  125. const unsigned char *p = buffer;
  126. int i;
  127. #if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
  128. int checksum;
  129. int usegdb=0;
  130. #ifdef CONFIG_SH_STANDARD_BIOS
  131. /* This call only does a trap the first time it is
  132. * called, and so is safe to do here unconditionally
  133. */
  134. usegdb |= sh_bios_in_gdb_mode();
  135. #endif
  136. #ifdef CONFIG_SH_KGDB
  137. usegdb |= (kgdb_in_gdb_mode && (port == kgdb_sci_port));
  138. #endif
  139. if (usegdb) {
  140. /* $<packet info>#<checksum>. */
  141. do {
  142. unsigned char c;
  143. put_char(port, '$');
  144. put_char(port, 'O'); /* 'O'utput to console */
  145. checksum = 'O';
  146. for (i=0; i<count; i++) { /* Don't use run length encoding */
  147. int h, l;
  148. c = *p++;
  149. h = highhex(c);
  150. l = lowhex(c);
  151. put_char(port, h);
  152. put_char(port, l);
  153. checksum += h + l;
  154. }
  155. put_char(port, '#');
  156. put_char(port, highhex(checksum));
  157. put_char(port, lowhex(checksum));
  158. } while (get_char(port) != '+');
  159. } else
  160. #endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */
  161. for (i=0; i<count; i++) {
  162. if (*p == 10)
  163. put_char(port, '\r');
  164. put_char(port, *p++);
  165. }
  166. }
  167. #endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */
  168. #ifdef CONFIG_SH_KGDB
  169. static int kgdb_sci_getchar(void)
  170. {
  171. int c;
  172. /* Keep trying to read a character, this could be neater */
  173. while ((c = get_char(kgdb_sci_port)) < 0)
  174. cpu_relax();
  175. return c;
  176. }
  177. static inline void kgdb_sci_putchar(int c)
  178. {
  179. put_char(kgdb_sci_port, c);
  180. }
  181. #endif /* CONFIG_SH_KGDB */
  182. #if defined(__H8300S__)
  183. enum { sci_disable, sci_enable };
  184. static void h8300_sci_config(struct uart_port* port, unsigned int ctrl)
  185. {
  186. volatile unsigned char *mstpcrl=(volatile unsigned char *)MSTPCRL;
  187. int ch = (port->mapbase - SMR0) >> 3;
  188. unsigned char mask = 1 << (ch+1);
  189. if (ctrl == sci_disable) {
  190. *mstpcrl |= mask;
  191. } else {
  192. *mstpcrl &= ~mask;
  193. }
  194. }
  195. static inline void h8300_sci_enable(struct uart_port *port)
  196. {
  197. h8300_sci_config(port, sci_enable);
  198. }
  199. static inline void h8300_sci_disable(struct uart_port *port)
  200. {
  201. h8300_sci_config(port, sci_disable);
  202. }
  203. #endif
  204. #if defined(SCI_ONLY) || defined(SCI_AND_SCIF) && \
  205. defined(__H8300H__) || defined(__H8300S__)
  206. static void sci_init_pins_sci(struct uart_port* port, unsigned int cflag)
  207. {
  208. int ch = (port->mapbase - SMR0) >> 3;
  209. /* set DDR regs */
  210. H8300_GPIO_DDR(h8300_sci_pins[ch].port,
  211. h8300_sci_pins[ch].rx,
  212. H8300_GPIO_INPUT);
  213. H8300_GPIO_DDR(h8300_sci_pins[ch].port,
  214. h8300_sci_pins[ch].tx,
  215. H8300_GPIO_OUTPUT);
  216. /* tx mark output*/
  217. H8300_SCI_DR(ch) |= h8300_sci_pins[ch].tx;
  218. }
  219. #else
  220. #define sci_init_pins_sci NULL
  221. #endif
  222. #if defined(CONFIG_CPU_SUBTYPE_SH7707) || defined(CONFIG_CPU_SUBTYPE_SH7709)
  223. static void sci_init_pins_irda(struct uart_port *port, unsigned int cflag)
  224. {
  225. unsigned int fcr_val = 0;
  226. if (cflag & CRTSCTS)
  227. fcr_val |= SCFCR_MCE;
  228. sci_out(port, SCFCR, fcr_val);
  229. }
  230. #else
  231. #define sci_init_pins_irda NULL
  232. #endif
  233. #ifdef SCI_ONLY
  234. #define sci_init_pins_scif NULL
  235. #endif
  236. #if defined(SCIF_ONLY) || defined(SCI_AND_SCIF)
  237. #if defined(CONFIG_CPU_SUBTYPE_SH7300) || defined(CONFIG_CPU_SUBTYPE_SH7710)
  238. /* SH7300 doesn't use RTS/CTS */
  239. static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag)
  240. {
  241. sci_out(port, SCFCR, 0);
  242. }
  243. #elif defined(CONFIG_CPU_SH3)
  244. /* For SH7705, SH7706, SH7707, SH7709, SH7709A, SH7729 */
  245. static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag)
  246. {
  247. unsigned int fcr_val = 0;
  248. unsigned short data;
  249. /* We need to set SCPCR to enable RTS/CTS */
  250. data = ctrl_inw(SCPCR);
  251. /* Clear out SCP7MD1,0, SCP6MD1,0, SCP4MD1,0*/
  252. ctrl_outw(data & 0x0fcf, SCPCR);
  253. if (cflag & CRTSCTS)
  254. fcr_val |= SCFCR_MCE;
  255. else {
  256. /* We need to set SCPCR to enable RTS/CTS */
  257. data = ctrl_inw(SCPCR);
  258. /* Clear out SCP7MD1,0, SCP4MD1,0,
  259. Set SCP6MD1,0 = {01} (output) */
  260. ctrl_outw((data & 0x0fcf) | 0x1000, SCPCR);
  261. data = ctrl_inb(SCPDR);
  262. /* Set /RTS2 (bit6) = 0 */
  263. ctrl_outb(data & 0xbf, SCPDR);
  264. }
  265. sci_out(port, SCFCR, fcr_val);
  266. }
  267. #elif defined(CONFIG_CPU_SUBTYPE_SH7722)
  268. static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag)
  269. {
  270. unsigned int fcr_val = 0;
  271. if (cflag & CRTSCTS) {
  272. fcr_val |= SCFCR_MCE;
  273. ctrl_outw(0x0000, PORT_PSCR);
  274. } else {
  275. unsigned short data;
  276. data = ctrl_inw(PORT_PSCR);
  277. data &= 0x033f;
  278. data |= 0x0400;
  279. ctrl_outw(data, PORT_PSCR);
  280. ctrl_outw(ctrl_inw(SCSPTR0) & 0x17, SCSPTR0);
  281. }
  282. sci_out(port, SCFCR, fcr_val);
  283. }
  284. #else
  285. /* For SH7750 */
  286. static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag)
  287. {
  288. unsigned int fcr_val = 0;
  289. if (cflag & CRTSCTS) {
  290. fcr_val |= SCFCR_MCE;
  291. } else {
  292. #ifdef CONFIG_CPU_SUBTYPE_SH7343
  293. /* Nothing */
  294. #elif defined(CONFIG_CPU_SUBTYPE_SH7780)
  295. ctrl_outw(0x0080, SCSPTR0); /* Set RTS = 1 */
  296. #else
  297. ctrl_outw(0x0080, SCSPTR2); /* Set RTS = 1 */
  298. #endif
  299. }
  300. sci_out(port, SCFCR, fcr_val);
  301. }
  302. #endif
  303. #if defined(CONFIG_CPU_SUBTYPE_SH7760) || defined(CONFIG_CPU_SUBTYPE_SH7780)
  304. static inline int scif_txroom(struct uart_port *port)
  305. {
  306. return SCIF_TXROOM_MAX - (sci_in(port, SCTFDR) & 0x7f);
  307. }
  308. static inline int scif_rxroom(struct uart_port *port)
  309. {
  310. return sci_in(port, SCRFDR) & 0x7f;
  311. }
  312. #else
  313. static inline int scif_txroom(struct uart_port *port)
  314. {
  315. return SCIF_TXROOM_MAX - (sci_in(port, SCFDR) >> 8);
  316. }
  317. static inline int scif_rxroom(struct uart_port *port)
  318. {
  319. return sci_in(port, SCFDR) & SCIF_RFDC_MASK;
  320. }
  321. #endif
  322. #endif /* SCIF_ONLY || SCI_AND_SCIF */
  323. static inline int sci_txroom(struct uart_port *port)
  324. {
  325. return ((sci_in(port, SCxSR) & SCI_TDRE) != 0);
  326. }
  327. static inline int sci_rxroom(struct uart_port *port)
  328. {
  329. return ((sci_in(port, SCxSR) & SCxSR_RDxF(port)) != 0);
  330. }
  331. /* ********************************************************************** *
  332. * the interrupt related routines *
  333. * ********************************************************************** */
  334. static void sci_transmit_chars(struct uart_port *port)
  335. {
  336. struct circ_buf *xmit = &port->info->xmit;
  337. unsigned int stopped = uart_tx_stopped(port);
  338. unsigned short status;
  339. unsigned short ctrl;
  340. int count;
  341. status = sci_in(port, SCxSR);
  342. if (!(status & SCxSR_TDxE(port))) {
  343. ctrl = sci_in(port, SCSCR);
  344. if (uart_circ_empty(xmit)) {
  345. ctrl &= ~SCI_CTRL_FLAGS_TIE;
  346. } else {
  347. ctrl |= SCI_CTRL_FLAGS_TIE;
  348. }
  349. sci_out(port, SCSCR, ctrl);
  350. return;
  351. }
  352. #ifndef SCI_ONLY
  353. if (port->type == PORT_SCIF)
  354. count = scif_txroom(port);
  355. else
  356. #endif
  357. count = sci_txroom(port);
  358. do {
  359. unsigned char c;
  360. if (port->x_char) {
  361. c = port->x_char;
  362. port->x_char = 0;
  363. } else if (!uart_circ_empty(xmit) && !stopped) {
  364. c = xmit->buf[xmit->tail];
  365. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  366. } else {
  367. break;
  368. }
  369. sci_out(port, SCxTDR, c);
  370. port->icount.tx++;
  371. } while (--count > 0);
  372. sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
  373. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  374. uart_write_wakeup(port);
  375. if (uart_circ_empty(xmit)) {
  376. sci_stop_tx(port);
  377. } else {
  378. ctrl = sci_in(port, SCSCR);
  379. #if !defined(SCI_ONLY)
  380. if (port->type == PORT_SCIF) {
  381. sci_in(port, SCxSR); /* Dummy read */
  382. sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
  383. }
  384. #endif
  385. ctrl |= SCI_CTRL_FLAGS_TIE;
  386. sci_out(port, SCSCR, ctrl);
  387. }
  388. }
  389. /* On SH3, SCIF may read end-of-break as a space->mark char */
  390. #define STEPFN(c) ({int __c=(c); (((__c-1)|(__c)) == -1); })
  391. static inline void sci_receive_chars(struct uart_port *port)
  392. {
  393. struct sci_port *sci_port = (struct sci_port *)port;
  394. struct tty_struct *tty = port->info->tty;
  395. int i, count, copied = 0;
  396. unsigned short status;
  397. unsigned char flag;
  398. status = sci_in(port, SCxSR);
  399. if (!(status & SCxSR_RDxF(port)))
  400. return;
  401. while (1) {
  402. #if !defined(SCI_ONLY)
  403. if (port->type == PORT_SCIF)
  404. count = scif_rxroom(port);
  405. else
  406. #endif
  407. count = sci_rxroom(port);
  408. /* Don't copy more bytes than there is room for in the buffer */
  409. count = tty_buffer_request_room(tty, count);
  410. /* If for any reason we can't copy more data, we're done! */
  411. if (count == 0)
  412. break;
  413. if (port->type == PORT_SCI) {
  414. char c = sci_in(port, SCxRDR);
  415. if (uart_handle_sysrq_char(port, c) || sci_port->break_flag)
  416. count = 0;
  417. else {
  418. tty_insert_flip_char(tty, c, TTY_NORMAL);
  419. }
  420. } else {
  421. for (i=0; i<count; i++) {
  422. char c = sci_in(port, SCxRDR);
  423. status = sci_in(port, SCxSR);
  424. #if defined(CONFIG_CPU_SH3)
  425. /* Skip "chars" during break */
  426. if (sci_port->break_flag) {
  427. if ((c == 0) &&
  428. (status & SCxSR_FER(port))) {
  429. count--; i--;
  430. continue;
  431. }
  432. /* Nonzero => end-of-break */
  433. pr_debug("scif: debounce<%02x>\n", c);
  434. sci_port->break_flag = 0;
  435. if (STEPFN(c)) {
  436. count--; i--;
  437. continue;
  438. }
  439. }
  440. #endif /* CONFIG_CPU_SH3 */
  441. if (uart_handle_sysrq_char(port, c)) {
  442. count--; i--;
  443. continue;
  444. }
  445. /* Store data and status */
  446. if (status&SCxSR_FER(port)) {
  447. flag = TTY_FRAME;
  448. pr_debug("sci: frame error\n");
  449. } else if (status&SCxSR_PER(port)) {
  450. flag = TTY_PARITY;
  451. pr_debug("sci: parity error\n");
  452. } else
  453. flag = TTY_NORMAL;
  454. tty_insert_flip_char(tty, c, flag);
  455. }
  456. }
  457. sci_in(port, SCxSR); /* dummy read */
  458. sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
  459. copied += count;
  460. port->icount.rx += count;
  461. }
  462. if (copied) {
  463. /* Tell the rest of the system the news. New characters! */
  464. tty_flip_buffer_push(tty);
  465. } else {
  466. sci_in(port, SCxSR); /* dummy read */
  467. sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
  468. }
  469. }
  470. #define SCI_BREAK_JIFFIES (HZ/20)
  471. /* The sci generates interrupts during the break,
  472. * 1 per millisecond or so during the break period, for 9600 baud.
  473. * So dont bother disabling interrupts.
  474. * But dont want more than 1 break event.
  475. * Use a kernel timer to periodically poll the rx line until
  476. * the break is finished.
  477. */
  478. static void sci_schedule_break_timer(struct sci_port *port)
  479. {
  480. port->break_timer.expires = jiffies + SCI_BREAK_JIFFIES;
  481. add_timer(&port->break_timer);
  482. }
  483. /* Ensure that two consecutive samples find the break over. */
  484. static void sci_break_timer(unsigned long data)
  485. {
  486. struct sci_port *port = (struct sci_port *)data;
  487. if (sci_rxd_in(&port->port) == 0) {
  488. port->break_flag = 1;
  489. sci_schedule_break_timer(port);
  490. } else if (port->break_flag == 1) {
  491. /* break is over. */
  492. port->break_flag = 2;
  493. sci_schedule_break_timer(port);
  494. } else
  495. port->break_flag = 0;
  496. }
  497. static inline int sci_handle_errors(struct uart_port *port)
  498. {
  499. int copied = 0;
  500. unsigned short status = sci_in(port, SCxSR);
  501. struct tty_struct *tty = port->info->tty;
  502. if (status & SCxSR_ORER(port)) {
  503. /* overrun error */
  504. if (tty_insert_flip_char(tty, 0, TTY_OVERRUN))
  505. copied++;
  506. pr_debug("sci: overrun error\n");
  507. }
  508. if (status & SCxSR_FER(port)) {
  509. if (sci_rxd_in(port) == 0) {
  510. /* Notify of BREAK */
  511. struct sci_port *sci_port = (struct sci_port *)port;
  512. if (!sci_port->break_flag) {
  513. sci_port->break_flag = 1;
  514. sci_schedule_break_timer(sci_port);
  515. /* Do sysrq handling. */
  516. if (uart_handle_break(port))
  517. return 0;
  518. pr_debug("sci: BREAK detected\n");
  519. if (tty_insert_flip_char(tty, 0, TTY_BREAK))
  520. copied++;
  521. }
  522. } else {
  523. /* frame error */
  524. if (tty_insert_flip_char(tty, 0, TTY_FRAME))
  525. copied++;
  526. pr_debug("sci: frame error\n");
  527. }
  528. }
  529. if (status & SCxSR_PER(port)) {
  530. /* parity error */
  531. if (tty_insert_flip_char(tty, 0, TTY_PARITY))
  532. copied++;
  533. pr_debug("sci: parity error\n");
  534. }
  535. if (copied)
  536. tty_flip_buffer_push(tty);
  537. return copied;
  538. }
  539. static inline int sci_handle_breaks(struct uart_port *port)
  540. {
  541. int copied = 0;
  542. unsigned short status = sci_in(port, SCxSR);
  543. struct tty_struct *tty = port->info->tty;
  544. struct sci_port *s = &sci_ports[port->line];
  545. if (!s->break_flag && status & SCxSR_BRK(port)) {
  546. #if defined(CONFIG_CPU_SH3)
  547. /* Debounce break */
  548. s->break_flag = 1;
  549. #endif
  550. /* Notify of BREAK */
  551. if (tty_insert_flip_char(tty, 0, TTY_BREAK))
  552. copied++;
  553. pr_debug("sci: BREAK detected\n");
  554. }
  555. #if defined(SCIF_ORER)
  556. /* XXX: Handle SCIF overrun error */
  557. if (port->type == PORT_SCIF && (sci_in(port, SCLSR) & SCIF_ORER) != 0) {
  558. sci_out(port, SCLSR, 0);
  559. if (tty_insert_flip_char(tty, 0, TTY_OVERRUN)) {
  560. copied++;
  561. pr_debug("sci: overrun error\n");
  562. }
  563. }
  564. #endif
  565. if (copied)
  566. tty_flip_buffer_push(tty);
  567. return copied;
  568. }
  569. static irqreturn_t sci_rx_interrupt(int irq, void *port)
  570. {
  571. /* I think sci_receive_chars has to be called irrespective
  572. * of whether the I_IXOFF is set, otherwise, how is the interrupt
  573. * to be disabled?
  574. */
  575. sci_receive_chars(port);
  576. return IRQ_HANDLED;
  577. }
  578. static irqreturn_t sci_tx_interrupt(int irq, void *ptr)
  579. {
  580. struct uart_port *port = ptr;
  581. spin_lock_irq(&port->lock);
  582. sci_transmit_chars(port);
  583. spin_unlock_irq(&port->lock);
  584. return IRQ_HANDLED;
  585. }
  586. static irqreturn_t sci_er_interrupt(int irq, void *ptr)
  587. {
  588. struct uart_port *port = ptr;
  589. /* Handle errors */
  590. if (port->type == PORT_SCI) {
  591. if (sci_handle_errors(port)) {
  592. /* discard character in rx buffer */
  593. sci_in(port, SCxSR);
  594. sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
  595. }
  596. } else {
  597. #if defined(SCIF_ORER)
  598. if((sci_in(port, SCLSR) & SCIF_ORER) != 0) {
  599. struct tty_struct *tty = port->info->tty;
  600. sci_out(port, SCLSR, 0);
  601. tty_insert_flip_char(tty, 0, TTY_OVERRUN);
  602. tty_flip_buffer_push(tty);
  603. pr_debug("scif: overrun error\n");
  604. }
  605. #endif
  606. sci_rx_interrupt(irq, ptr);
  607. }
  608. sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
  609. /* Kick the transmission */
  610. sci_tx_interrupt(irq, ptr);
  611. return IRQ_HANDLED;
  612. }
  613. static irqreturn_t sci_br_interrupt(int irq, void *ptr)
  614. {
  615. struct uart_port *port = ptr;
  616. /* Handle BREAKs */
  617. sci_handle_breaks(port);
  618. #ifdef CONFIG_SH_KGDB
  619. /* Break into the debugger if a break is detected */
  620. BREAKPOINT();
  621. #endif
  622. sci_out(port, SCxSR, SCxSR_BREAK_CLEAR(port));
  623. return IRQ_HANDLED;
  624. }
  625. static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr)
  626. {
  627. unsigned short ssr_status, scr_status;
  628. struct uart_port *port = ptr;
  629. ssr_status = sci_in(port,SCxSR);
  630. scr_status = sci_in(port,SCSCR);
  631. /* Tx Interrupt */
  632. if ((ssr_status & 0x0020) && (scr_status & 0x0080))
  633. sci_tx_interrupt(irq, ptr);
  634. /* Rx Interrupt */
  635. if ((ssr_status & 0x0002) && (scr_status & 0x0040))
  636. sci_rx_interrupt(irq, ptr);
  637. /* Error Interrupt */
  638. if ((ssr_status & 0x0080) && (scr_status & 0x0400))
  639. sci_er_interrupt(irq, ptr);
  640. /* Break Interrupt */
  641. if ((ssr_status & 0x0010) && (scr_status & 0x0200))
  642. sci_br_interrupt(irq, ptr);
  643. return IRQ_HANDLED;
  644. }
  645. #ifdef CONFIG_CPU_FREQ
  646. /*
  647. * Here we define a transistion notifier so that we can update all of our
  648. * ports' baud rate when the peripheral clock changes.
  649. */
  650. static int sci_notifier(struct notifier_block *self,
  651. unsigned long phase, void *p)
  652. {
  653. struct cpufreq_freqs *freqs = p;
  654. int i;
  655. if ((phase == CPUFREQ_POSTCHANGE) ||
  656. (phase == CPUFREQ_RESUMECHANGE)){
  657. for (i = 0; i < SCI_NPORTS; i++) {
  658. struct uart_port *port = &sci_ports[i].port;
  659. struct clk *clk;
  660. /*
  661. * Update the uartclk per-port if frequency has
  662. * changed, since it will no longer necessarily be
  663. * consistent with the old frequency.
  664. *
  665. * Really we want to be able to do something like
  666. * uart_change_speed() or something along those lines
  667. * here to implicitly reset the per-port baud rate..
  668. *
  669. * Clean this up later..
  670. */
  671. clk = clk_get(NULL, "module_clk");
  672. port->uartclk = clk_get_rate(clk) * 16;
  673. clk_put(clk);
  674. }
  675. printk(KERN_INFO "%s: got a postchange notification "
  676. "for cpu %d (old %d, new %d)\n",
  677. __FUNCTION__, freqs->cpu, freqs->old, freqs->new);
  678. }
  679. return NOTIFY_OK;
  680. }
  681. static struct notifier_block sci_nb = { &sci_notifier, NULL, 0 };
  682. #endif /* CONFIG_CPU_FREQ */
  683. static int sci_request_irq(struct sci_port *port)
  684. {
  685. int i;
  686. irqreturn_t (*handlers[4])(int irq, void *ptr) = {
  687. sci_er_interrupt, sci_rx_interrupt, sci_tx_interrupt,
  688. sci_br_interrupt,
  689. };
  690. const char *desc[] = { "SCI Receive Error", "SCI Receive Data Full",
  691. "SCI Transmit Data Empty", "SCI Break" };
  692. if (port->irqs[0] == port->irqs[1]) {
  693. if (!port->irqs[0]) {
  694. printk(KERN_ERR "sci: Cannot allocate irq.(IRQ=0)\n");
  695. return -ENODEV;
  696. }
  697. if (request_irq(port->irqs[0], sci_mpxed_interrupt,
  698. IRQF_DISABLED, "sci", port)) {
  699. printk(KERN_ERR "sci: Cannot allocate irq.\n");
  700. return -ENODEV;
  701. }
  702. } else {
  703. for (i = 0; i < ARRAY_SIZE(handlers); i++) {
  704. if (!port->irqs[i])
  705. continue;
  706. if (request_irq(port->irqs[i], handlers[i],
  707. IRQF_DISABLED, desc[i], port)) {
  708. printk(KERN_ERR "sci: Cannot allocate irq.\n");
  709. return -ENODEV;
  710. }
  711. }
  712. }
  713. return 0;
  714. }
  715. static void sci_free_irq(struct sci_port *port)
  716. {
  717. int i;
  718. if (port->irqs[0] == port->irqs[1]) {
  719. if (!port->irqs[0])
  720. printk("sci: sci_free_irq error\n");
  721. else
  722. free_irq(port->irqs[0], port);
  723. } else {
  724. for (i = 0; i < ARRAY_SIZE(port->irqs); i++) {
  725. if (!port->irqs[i])
  726. continue;
  727. free_irq(port->irqs[i], port);
  728. }
  729. }
  730. }
  731. static unsigned int sci_tx_empty(struct uart_port *port)
  732. {
  733. /* Can't detect */
  734. return TIOCSER_TEMT;
  735. }
  736. static void sci_set_mctrl(struct uart_port *port, unsigned int mctrl)
  737. {
  738. /* This routine is used for seting signals of: DTR, DCD, CTS/RTS */
  739. /* We use SCIF's hardware for CTS/RTS, so don't need any for that. */
  740. /* If you have signals for DTR and DCD, please implement here. */
  741. }
  742. static unsigned int sci_get_mctrl(struct uart_port *port)
  743. {
  744. /* This routine is used for geting signals of: DTR, DCD, DSR, RI,
  745. and CTS/RTS */
  746. return TIOCM_DTR | TIOCM_RTS | TIOCM_DSR;
  747. }
  748. static void sci_start_tx(struct uart_port *port)
  749. {
  750. unsigned short ctrl;
  751. /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */
  752. ctrl = sci_in(port, SCSCR);
  753. ctrl |= SCI_CTRL_FLAGS_TIE;
  754. sci_out(port, SCSCR, ctrl);
  755. }
  756. static void sci_stop_tx(struct uart_port *port)
  757. {
  758. unsigned short ctrl;
  759. /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */
  760. ctrl = sci_in(port, SCSCR);
  761. ctrl &= ~SCI_CTRL_FLAGS_TIE;
  762. sci_out(port, SCSCR, ctrl);
  763. }
  764. static void sci_start_rx(struct uart_port *port, unsigned int tty_start)
  765. {
  766. unsigned short ctrl;
  767. /* Set RIE (Receive Interrupt Enable) bit in SCSCR */
  768. ctrl = sci_in(port, SCSCR);
  769. ctrl |= SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE;
  770. sci_out(port, SCSCR, ctrl);
  771. }
  772. static void sci_stop_rx(struct uart_port *port)
  773. {
  774. unsigned short ctrl;
  775. /* Clear RIE (Receive Interrupt Enable) bit in SCSCR */
  776. ctrl = sci_in(port, SCSCR);
  777. ctrl &= ~(SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE);
  778. sci_out(port, SCSCR, ctrl);
  779. }
  780. static void sci_enable_ms(struct uart_port *port)
  781. {
  782. /* Nothing here yet .. */
  783. }
  784. static void sci_break_ctl(struct uart_port *port, int break_state)
  785. {
  786. /* Nothing here yet .. */
  787. }
  788. static int sci_startup(struct uart_port *port)
  789. {
  790. struct sci_port *s = &sci_ports[port->line];
  791. if (s->enable)
  792. s->enable(port);
  793. sci_request_irq(s);
  794. sci_start_tx(port);
  795. sci_start_rx(port, 1);
  796. return 0;
  797. }
  798. static void sci_shutdown(struct uart_port *port)
  799. {
  800. struct sci_port *s = &sci_ports[port->line];
  801. sci_stop_rx(port);
  802. sci_stop_tx(port);
  803. sci_free_irq(s);
  804. if (s->disable)
  805. s->disable(port);
  806. }
  807. static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
  808. struct ktermios *old)
  809. {
  810. struct sci_port *s = &sci_ports[port->line];
  811. unsigned int status, baud, smr_val;
  812. unsigned long flags;
  813. int t;
  814. baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
  815. switch (baud) {
  816. case 0:
  817. t = -1;
  818. break;
  819. default:
  820. {
  821. #if defined(CONFIG_SUPERH) && !defined(CONFIG_SUPERH64)
  822. struct clk *clk = clk_get(NULL, "module_clk");
  823. t = SCBRR_VALUE(baud, clk_get_rate(clk));
  824. clk_put(clk);
  825. #else
  826. t = SCBRR_VALUE(baud);
  827. #endif
  828. }
  829. break;
  830. }
  831. spin_lock_irqsave(&port->lock, flags);
  832. do {
  833. status = sci_in(port, SCxSR);
  834. } while (!(status & SCxSR_TEND(port)));
  835. sci_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */
  836. #if !defined(SCI_ONLY)
  837. if (port->type == PORT_SCIF)
  838. sci_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST);
  839. #endif
  840. smr_val = sci_in(port, SCSMR) & 3;
  841. if ((termios->c_cflag & CSIZE) == CS7)
  842. smr_val |= 0x40;
  843. if (termios->c_cflag & PARENB)
  844. smr_val |= 0x20;
  845. if (termios->c_cflag & PARODD)
  846. smr_val |= 0x30;
  847. if (termios->c_cflag & CSTOPB)
  848. smr_val |= 0x08;
  849. uart_update_timeout(port, termios->c_cflag, baud);
  850. sci_out(port, SCSMR, smr_val);
  851. if (t > 0) {
  852. if(t >= 256) {
  853. sci_out(port, SCSMR, (sci_in(port, SCSMR) & ~3) | 1);
  854. t >>= 2;
  855. } else {
  856. sci_out(port, SCSMR, sci_in(port, SCSMR) & ~3);
  857. }
  858. sci_out(port, SCBRR, t);
  859. udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */
  860. }
  861. if (likely(s->init_pins))
  862. s->init_pins(port, termios->c_cflag);
  863. sci_out(port, SCSCR, SCSCR_INIT(port));
  864. if ((termios->c_cflag & CREAD) != 0)
  865. sci_start_rx(port,0);
  866. spin_unlock_irqrestore(&port->lock, flags);
  867. }
  868. static const char *sci_type(struct uart_port *port)
  869. {
  870. switch (port->type) {
  871. case PORT_SCI: return "sci";
  872. case PORT_SCIF: return "scif";
  873. case PORT_IRDA: return "irda";
  874. }
  875. return 0;
  876. }
  877. static void sci_release_port(struct uart_port *port)
  878. {
  879. /* Nothing here yet .. */
  880. }
  881. static int sci_request_port(struct uart_port *port)
  882. {
  883. /* Nothing here yet .. */
  884. return 0;
  885. }
  886. static void sci_config_port(struct uart_port *port, int flags)
  887. {
  888. struct sci_port *s = &sci_ports[port->line];
  889. port->type = s->type;
  890. switch (port->type) {
  891. case PORT_SCI:
  892. s->init_pins = sci_init_pins_sci;
  893. break;
  894. case PORT_SCIF:
  895. s->init_pins = sci_init_pins_scif;
  896. break;
  897. case PORT_IRDA:
  898. s->init_pins = sci_init_pins_irda;
  899. break;
  900. }
  901. #if defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
  902. if (port->mapbase == 0)
  903. port->mapbase = onchip_remap(SCIF_ADDR_SH5, 1024, "SCIF");
  904. port->membase = (void __iomem *)port->mapbase;
  905. #endif
  906. }
  907. static int sci_verify_port(struct uart_port *port, struct serial_struct *ser)
  908. {
  909. struct sci_port *s = &sci_ports[port->line];
  910. if (ser->irq != s->irqs[SCIx_TXI_IRQ] || ser->irq > NR_IRQS)
  911. return -EINVAL;
  912. if (ser->baud_base < 2400)
  913. /* No paper tape reader for Mitch.. */
  914. return -EINVAL;
  915. return 0;
  916. }
  917. static struct uart_ops sci_uart_ops = {
  918. .tx_empty = sci_tx_empty,
  919. .set_mctrl = sci_set_mctrl,
  920. .get_mctrl = sci_get_mctrl,
  921. .start_tx = sci_start_tx,
  922. .stop_tx = sci_stop_tx,
  923. .stop_rx = sci_stop_rx,
  924. .enable_ms = sci_enable_ms,
  925. .break_ctl = sci_break_ctl,
  926. .startup = sci_startup,
  927. .shutdown = sci_shutdown,
  928. .set_termios = sci_set_termios,
  929. .type = sci_type,
  930. .release_port = sci_release_port,
  931. .request_port = sci_request_port,
  932. .config_port = sci_config_port,
  933. .verify_port = sci_verify_port,
  934. };
  935. static void __init sci_init_ports(void)
  936. {
  937. static int first = 1;
  938. int i;
  939. if (!first)
  940. return;
  941. first = 0;
  942. for (i = 0; i < SCI_NPORTS; i++) {
  943. sci_ports[i].port.ops = &sci_uart_ops;
  944. sci_ports[i].port.iotype = UPIO_MEM;
  945. sci_ports[i].port.line = i;
  946. sci_ports[i].port.fifosize = 1;
  947. #if defined(__H8300H__) || defined(__H8300S__)
  948. #ifdef __H8300S__
  949. sci_ports[i].enable = h8300_sci_enable;
  950. sci_ports[i].disable = h8300_sci_disable;
  951. #endif
  952. sci_ports[i].port.uartclk = CONFIG_CPU_CLOCK;
  953. #elif defined(CONFIG_SUPERH64)
  954. sci_ports[i].port.uartclk = current_cpu_data.module_clock * 16;
  955. #else
  956. /*
  957. * XXX: We should use a proper SCI/SCIF clock
  958. */
  959. {
  960. struct clk *clk = clk_get(NULL, "module_clk");
  961. sci_ports[i].port.uartclk = clk_get_rate(clk) * 16;
  962. clk_put(clk);
  963. }
  964. #endif
  965. sci_ports[i].break_timer.data = (unsigned long)&sci_ports[i];
  966. sci_ports[i].break_timer.function = sci_break_timer;
  967. init_timer(&sci_ports[i].break_timer);
  968. }
  969. }
  970. int __init early_sci_setup(struct uart_port *port)
  971. {
  972. if (unlikely(port->line > SCI_NPORTS))
  973. return -ENODEV;
  974. sci_init_ports();
  975. sci_ports[port->line].port.membase = port->membase;
  976. sci_ports[port->line].port.mapbase = port->mapbase;
  977. sci_ports[port->line].port.type = port->type;
  978. return 0;
  979. }
  980. #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
  981. /*
  982. * Print a string to the serial port trying not to disturb
  983. * any possible real use of the port...
  984. */
  985. static void serial_console_write(struct console *co, const char *s,
  986. unsigned count)
  987. {
  988. put_string(serial_console_port, s, count);
  989. }
  990. static int __init serial_console_setup(struct console *co, char *options)
  991. {
  992. struct uart_port *port;
  993. int baud = 115200;
  994. int bits = 8;
  995. int parity = 'n';
  996. int flow = 'n';
  997. int ret;
  998. /*
  999. * Check whether an invalid uart number has been specified, and
  1000. * if so, search for the first available port that does have
  1001. * console support.
  1002. */
  1003. if (co->index >= SCI_NPORTS)
  1004. co->index = 0;
  1005. serial_console_port = &sci_ports[co->index];
  1006. port = &serial_console_port->port;
  1007. /*
  1008. * Also need to check port->type, we don't actually have any
  1009. * UPIO_PORT ports, but uart_report_port() handily misreports
  1010. * it anyways if we don't have a port available by the time this is
  1011. * called.
  1012. */
  1013. if (!port->type)
  1014. return -ENODEV;
  1015. if (!port->membase || !port->mapbase)
  1016. return -ENODEV;
  1017. spin_lock_init(&port->lock);
  1018. port->type = serial_console_port->type;
  1019. if (port->flags & UPF_IOREMAP)
  1020. sci_config_port(port, 0);
  1021. if (serial_console_port->enable)
  1022. serial_console_port->enable(port);
  1023. if (options)
  1024. uart_parse_options(options, &baud, &parity, &bits, &flow);
  1025. ret = uart_set_options(port, co, baud, parity, bits, flow);
  1026. #if defined(__H8300H__) || defined(__H8300S__)
  1027. /* disable rx interrupt */
  1028. if (ret == 0)
  1029. sci_stop_rx(port);
  1030. #endif
  1031. return ret;
  1032. }
  1033. static struct console serial_console = {
  1034. .name = "ttySC",
  1035. .device = uart_console_device,
  1036. .write = serial_console_write,
  1037. .setup = serial_console_setup,
  1038. .flags = CON_PRINTBUFFER,
  1039. .index = -1,
  1040. .data = &sci_uart_driver,
  1041. };
  1042. static int __init sci_console_init(void)
  1043. {
  1044. sci_init_ports();
  1045. register_console(&serial_console);
  1046. return 0;
  1047. }
  1048. console_initcall(sci_console_init);
  1049. #endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */
  1050. #ifdef CONFIG_SH_KGDB
  1051. /*
  1052. * FIXME: Most of this can go away.. at the moment, we rely on
  1053. * arch/sh/kernel/setup.c to do the command line parsing for kgdb, though
  1054. * most of that can easily be done here instead.
  1055. *
  1056. * For the time being, just accept the values that were parsed earlier..
  1057. */
  1058. static void __init kgdb_console_get_options(struct uart_port *port, int *baud,
  1059. int *parity, int *bits)
  1060. {
  1061. *baud = kgdb_baud;
  1062. *parity = tolower(kgdb_parity);
  1063. *bits = kgdb_bits - '0';
  1064. }
  1065. /*
  1066. * The naming here is somewhat misleading, since kgdb_console_setup() takes
  1067. * care of the early-on initialization for kgdb, regardless of whether we
  1068. * actually use kgdb as a console or not.
  1069. *
  1070. * On the plus side, this lets us kill off the old kgdb_sci_setup() nonsense.
  1071. */
  1072. int __init kgdb_console_setup(struct console *co, char *options)
  1073. {
  1074. struct uart_port *port = &sci_ports[kgdb_portnum].port;
  1075. int baud = 38400;
  1076. int bits = 8;
  1077. int parity = 'n';
  1078. int flow = 'n';
  1079. spin_lock_init(&port->lock);
  1080. if (co->index != kgdb_portnum)
  1081. co->index = kgdb_portnum;
  1082. if (options)
  1083. uart_parse_options(options, &baud, &parity, &bits, &flow);
  1084. else
  1085. kgdb_console_get_options(port, &baud, &parity, &bits);
  1086. kgdb_getchar = kgdb_sci_getchar;
  1087. kgdb_putchar = kgdb_sci_putchar;
  1088. return uart_set_options(port, co, baud, parity, bits, flow);
  1089. }
  1090. #endif /* CONFIG_SH_KGDB */
  1091. #ifdef CONFIG_SH_KGDB_CONSOLE
  1092. static struct console kgdb_console = {
  1093. .name = "ttySC",
  1094. .write = kgdb_console_write,
  1095. .setup = kgdb_console_setup,
  1096. .flags = CON_PRINTBUFFER | CON_ENABLED,
  1097. .index = -1,
  1098. .data = &sci_uart_driver,
  1099. };
  1100. /* Register the KGDB console so we get messages (d'oh!) */
  1101. static int __init kgdb_console_init(void)
  1102. {
  1103. sci_init_ports();
  1104. register_console(&kgdb_console);
  1105. return 0;
  1106. }
  1107. console_initcall(kgdb_console_init);
  1108. #endif /* CONFIG_SH_KGDB_CONSOLE */
  1109. #if defined(CONFIG_SH_KGDB_CONSOLE)
  1110. #define SCI_CONSOLE &kgdb_console
  1111. #elif defined(CONFIG_SERIAL_SH_SCI_CONSOLE)
  1112. #define SCI_CONSOLE &serial_console
  1113. #else
  1114. #define SCI_CONSOLE 0
  1115. #endif
  1116. static char banner[] __initdata =
  1117. KERN_INFO "SuperH SCI(F) driver initialized\n";
  1118. static struct uart_driver sci_uart_driver = {
  1119. .owner = THIS_MODULE,
  1120. .driver_name = "sci",
  1121. .dev_name = "ttySC",
  1122. .major = SCI_MAJOR,
  1123. .minor = SCI_MINOR_START,
  1124. .nr = SCI_NPORTS,
  1125. .cons = SCI_CONSOLE,
  1126. };
  1127. /*
  1128. * Register a set of serial devices attached to a platform device. The
  1129. * list is terminated with a zero flags entry, which means we expect
  1130. * all entries to have at least UPF_BOOT_AUTOCONF set. Platforms that need
  1131. * remapping (such as sh64) should also set UPF_IOREMAP.
  1132. */
  1133. static int __devinit sci_probe(struct platform_device *dev)
  1134. {
  1135. struct plat_sci_port *p = dev->dev.platform_data;
  1136. int i;
  1137. for (i = 0; p && p->flags != 0 && i < SCI_NPORTS; p++, i++) {
  1138. struct sci_port *sciport = &sci_ports[i];
  1139. sciport->port.mapbase = p->mapbase;
  1140. /*
  1141. * For the simple (and majority of) cases where we don't need
  1142. * to do any remapping, just cast the cookie directly.
  1143. */
  1144. if (p->mapbase && !p->membase && !(p->flags & UPF_IOREMAP))
  1145. p->membase = (void __iomem *)p->mapbase;
  1146. sciport->port.membase = p->membase;
  1147. sciport->port.irq = p->irqs[SCIx_TXI_IRQ];
  1148. sciport->port.flags = p->flags;
  1149. sciport->port.dev = &dev->dev;
  1150. sciport->type = sciport->port.type = p->type;
  1151. memcpy(&sciport->irqs, &p->irqs, sizeof(p->irqs));
  1152. uart_add_one_port(&sci_uart_driver, &sciport->port);
  1153. }
  1154. #ifdef CONFIG_CPU_FREQ
  1155. cpufreq_register_notifier(&sci_nb, CPUFREQ_TRANSITION_NOTIFIER);
  1156. dev_info(&dev->dev, "sci: CPU frequency notifier registered\n");
  1157. #endif
  1158. #ifdef CONFIG_SH_STANDARD_BIOS
  1159. sh_bios_gdb_detach();
  1160. #endif
  1161. return 0;
  1162. }
  1163. static int __devexit sci_remove(struct platform_device *dev)
  1164. {
  1165. int i;
  1166. for (i = 0; i < SCI_NPORTS; i++)
  1167. uart_remove_one_port(&sci_uart_driver, &sci_ports[i].port);
  1168. return 0;
  1169. }
  1170. static int sci_suspend(struct platform_device *dev, pm_message_t state)
  1171. {
  1172. int i;
  1173. for (i = 0; i < SCI_NPORTS; i++) {
  1174. struct sci_port *p = &sci_ports[i];
  1175. if (p->type != PORT_UNKNOWN && p->port.dev == &dev->dev)
  1176. uart_suspend_port(&sci_uart_driver, &p->port);
  1177. }
  1178. return 0;
  1179. }
  1180. static int sci_resume(struct platform_device *dev)
  1181. {
  1182. int i;
  1183. for (i = 0; i < SCI_NPORTS; i++) {
  1184. struct sci_port *p = &sci_ports[i];
  1185. if (p->type != PORT_UNKNOWN && p->port.dev == &dev->dev)
  1186. uart_resume_port(&sci_uart_driver, &p->port);
  1187. }
  1188. return 0;
  1189. }
  1190. static struct platform_driver sci_driver = {
  1191. .probe = sci_probe,
  1192. .remove = __devexit_p(sci_remove),
  1193. .suspend = sci_suspend,
  1194. .resume = sci_resume,
  1195. .driver = {
  1196. .name = "sh-sci",
  1197. .owner = THIS_MODULE,
  1198. },
  1199. };
  1200. static int __init sci_init(void)
  1201. {
  1202. int ret;
  1203. printk(banner);
  1204. sci_init_ports();
  1205. ret = uart_register_driver(&sci_uart_driver);
  1206. if (likely(ret == 0)) {
  1207. ret = platform_driver_register(&sci_driver);
  1208. if (unlikely(ret))
  1209. uart_unregister_driver(&sci_uart_driver);
  1210. }
  1211. return ret;
  1212. }
  1213. static void __exit sci_exit(void)
  1214. {
  1215. platform_driver_unregister(&sci_driver);
  1216. uart_unregister_driver(&sci_uart_driver);
  1217. }
  1218. module_init(sci_init);
  1219. module_exit(sci_exit);
  1220. MODULE_LICENSE("GPL");