sh-sci.c 34 KB

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