samsung.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  1. /* linux/drivers/serial/samsuing.c
  2. *
  3. * Driver core for Samsung SoC onboard UARTs.
  4. *
  5. * Ben Dooks, Copyright (c) 2003-2005,2008 Simtec Electronics
  6. * http://armlinux.simtec.co.uk/
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. /* Hote on 2410 error handling
  13. *
  14. * The s3c2410 manual has a love/hate affair with the contents of the
  15. * UERSTAT register in the UART blocks, and keeps marking some of the
  16. * error bits as reserved. Having checked with the s3c2410x01,
  17. * it copes with BREAKs properly, so I am happy to ignore the RESERVED
  18. * feature from the latter versions of the manual.
  19. *
  20. * If it becomes aparrent that latter versions of the 2410 remove these
  21. * bits, then action will have to be taken to differentiate the versions
  22. * and change the policy on BREAK
  23. *
  24. * BJD, 04-Nov-2004
  25. */
  26. #if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  27. #define SUPPORT_SYSRQ
  28. #endif
  29. #include <linux/module.h>
  30. #include <linux/ioport.h>
  31. #include <linux/io.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/init.h>
  34. #include <linux/sysrq.h>
  35. #include <linux/console.h>
  36. #include <linux/tty.h>
  37. #include <linux/tty_flip.h>
  38. #include <linux/serial_core.h>
  39. #include <linux/serial.h>
  40. #include <linux/delay.h>
  41. #include <linux/clk.h>
  42. #include <linux/cpufreq.h>
  43. #include <asm/irq.h>
  44. #include <mach/hardware.h>
  45. #include <plat/regs-serial.h>
  46. #include <mach/regs-gpio.h>
  47. #include "samsung.h"
  48. /* UART name and device definitions */
  49. #define S3C24XX_SERIAL_NAME "ttySAC"
  50. #define S3C24XX_SERIAL_MAJOR 204
  51. #define S3C24XX_SERIAL_MINOR 64
  52. /* we can support 3 uarts, but not always use them */
  53. #ifdef CONFIG_CPU_S3C2400
  54. #define NR_PORTS (2)
  55. #else
  56. #define NR_PORTS (3)
  57. #endif
  58. /* port irq numbers */
  59. #define TX_IRQ(port) ((port)->irq + 1)
  60. #define RX_IRQ(port) ((port)->irq)
  61. /* macros to change one thing to another */
  62. #define tx_enabled(port) ((port)->unused[0])
  63. #define rx_enabled(port) ((port)->unused[1])
  64. /* flag to ignore all characters comming in */
  65. #define RXSTAT_DUMMY_READ (0x10000000)
  66. static inline struct s3c24xx_uart_port *to_ourport(struct uart_port *port)
  67. {
  68. return container_of(port, struct s3c24xx_uart_port, port);
  69. }
  70. /* translate a port to the device name */
  71. static inline const char *s3c24xx_serial_portname(struct uart_port *port)
  72. {
  73. return to_platform_device(port->dev)->name;
  74. }
  75. static int s3c24xx_serial_txempty_nofifo(struct uart_port *port)
  76. {
  77. return (rd_regl(port, S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE);
  78. }
  79. static void s3c24xx_serial_rx_enable(struct uart_port *port)
  80. {
  81. unsigned long flags;
  82. unsigned int ucon, ufcon;
  83. int count = 10000;
  84. spin_lock_irqsave(&port->lock, flags);
  85. while (--count && !s3c24xx_serial_txempty_nofifo(port))
  86. udelay(100);
  87. ufcon = rd_regl(port, S3C2410_UFCON);
  88. ufcon |= S3C2410_UFCON_RESETRX;
  89. wr_regl(port, S3C2410_UFCON, ufcon);
  90. ucon = rd_regl(port, S3C2410_UCON);
  91. ucon |= S3C2410_UCON_RXIRQMODE;
  92. wr_regl(port, S3C2410_UCON, ucon);
  93. rx_enabled(port) = 1;
  94. spin_unlock_irqrestore(&port->lock, flags);
  95. }
  96. static void s3c24xx_serial_rx_disable(struct uart_port *port)
  97. {
  98. unsigned long flags;
  99. unsigned int ucon;
  100. spin_lock_irqsave(&port->lock, flags);
  101. ucon = rd_regl(port, S3C2410_UCON);
  102. ucon &= ~S3C2410_UCON_RXIRQMODE;
  103. wr_regl(port, S3C2410_UCON, ucon);
  104. rx_enabled(port) = 0;
  105. spin_unlock_irqrestore(&port->lock, flags);
  106. }
  107. static void s3c24xx_serial_stop_tx(struct uart_port *port)
  108. {
  109. if (tx_enabled(port)) {
  110. disable_irq(TX_IRQ(port));
  111. tx_enabled(port) = 0;
  112. if (port->flags & UPF_CONS_FLOW)
  113. s3c24xx_serial_rx_enable(port);
  114. }
  115. }
  116. static void s3c24xx_serial_start_tx(struct uart_port *port)
  117. {
  118. if (!tx_enabled(port)) {
  119. if (port->flags & UPF_CONS_FLOW)
  120. s3c24xx_serial_rx_disable(port);
  121. enable_irq(TX_IRQ(port));
  122. tx_enabled(port) = 1;
  123. }
  124. }
  125. static void s3c24xx_serial_stop_rx(struct uart_port *port)
  126. {
  127. if (rx_enabled(port)) {
  128. dbg("s3c24xx_serial_stop_rx: port=%p\n", port);
  129. disable_irq(RX_IRQ(port));
  130. rx_enabled(port) = 0;
  131. }
  132. }
  133. static void s3c24xx_serial_enable_ms(struct uart_port *port)
  134. {
  135. }
  136. static inline struct s3c24xx_uart_info *s3c24xx_port_to_info(struct uart_port *port)
  137. {
  138. return to_ourport(port)->info;
  139. }
  140. static inline struct s3c2410_uartcfg *s3c24xx_port_to_cfg(struct uart_port *port)
  141. {
  142. if (port->dev == NULL)
  143. return NULL;
  144. return (struct s3c2410_uartcfg *)port->dev->platform_data;
  145. }
  146. static int s3c24xx_serial_rx_fifocnt(struct s3c24xx_uart_port *ourport,
  147. unsigned long ufstat)
  148. {
  149. struct s3c24xx_uart_info *info = ourport->info;
  150. if (ufstat & info->rx_fifofull)
  151. return info->fifosize;
  152. return (ufstat & info->rx_fifomask) >> info->rx_fifoshift;
  153. }
  154. /* ? - where has parity gone?? */
  155. #define S3C2410_UERSTAT_PARITY (0x1000)
  156. static irqreturn_t
  157. s3c24xx_serial_rx_chars(int irq, void *dev_id)
  158. {
  159. struct s3c24xx_uart_port *ourport = dev_id;
  160. struct uart_port *port = &ourport->port;
  161. struct tty_struct *tty = port->info->port.tty;
  162. unsigned int ufcon, ch, flag, ufstat, uerstat;
  163. int max_count = 64;
  164. while (max_count-- > 0) {
  165. ufcon = rd_regl(port, S3C2410_UFCON);
  166. ufstat = rd_regl(port, S3C2410_UFSTAT);
  167. if (s3c24xx_serial_rx_fifocnt(ourport, ufstat) == 0)
  168. break;
  169. uerstat = rd_regl(port, S3C2410_UERSTAT);
  170. ch = rd_regb(port, S3C2410_URXH);
  171. if (port->flags & UPF_CONS_FLOW) {
  172. int txe = s3c24xx_serial_txempty_nofifo(port);
  173. if (rx_enabled(port)) {
  174. if (!txe) {
  175. rx_enabled(port) = 0;
  176. continue;
  177. }
  178. } else {
  179. if (txe) {
  180. ufcon |= S3C2410_UFCON_RESETRX;
  181. wr_regl(port, S3C2410_UFCON, ufcon);
  182. rx_enabled(port) = 1;
  183. goto out;
  184. }
  185. continue;
  186. }
  187. }
  188. /* insert the character into the buffer */
  189. flag = TTY_NORMAL;
  190. port->icount.rx++;
  191. if (unlikely(uerstat & S3C2410_UERSTAT_ANY)) {
  192. dbg("rxerr: port ch=0x%02x, rxs=0x%08x\n",
  193. ch, uerstat);
  194. /* check for break */
  195. if (uerstat & S3C2410_UERSTAT_BREAK) {
  196. dbg("break!\n");
  197. port->icount.brk++;
  198. if (uart_handle_break(port))
  199. goto ignore_char;
  200. }
  201. if (uerstat & S3C2410_UERSTAT_FRAME)
  202. port->icount.frame++;
  203. if (uerstat & S3C2410_UERSTAT_OVERRUN)
  204. port->icount.overrun++;
  205. uerstat &= port->read_status_mask;
  206. if (uerstat & S3C2410_UERSTAT_BREAK)
  207. flag = TTY_BREAK;
  208. else if (uerstat & S3C2410_UERSTAT_PARITY)
  209. flag = TTY_PARITY;
  210. else if (uerstat & (S3C2410_UERSTAT_FRAME |
  211. S3C2410_UERSTAT_OVERRUN))
  212. flag = TTY_FRAME;
  213. }
  214. if (uart_handle_sysrq_char(port, ch))
  215. goto ignore_char;
  216. uart_insert_char(port, uerstat, S3C2410_UERSTAT_OVERRUN,
  217. ch, flag);
  218. ignore_char:
  219. continue;
  220. }
  221. tty_flip_buffer_push(tty);
  222. out:
  223. return IRQ_HANDLED;
  224. }
  225. static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id)
  226. {
  227. struct s3c24xx_uart_port *ourport = id;
  228. struct uart_port *port = &ourport->port;
  229. struct circ_buf *xmit = &port->info->xmit;
  230. int count = 256;
  231. if (port->x_char) {
  232. wr_regb(port, S3C2410_UTXH, port->x_char);
  233. port->icount.tx++;
  234. port->x_char = 0;
  235. goto out;
  236. }
  237. /* if there isnt anything more to transmit, or the uart is now
  238. * stopped, disable the uart and exit
  239. */
  240. if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
  241. s3c24xx_serial_stop_tx(port);
  242. goto out;
  243. }
  244. /* try and drain the buffer... */
  245. while (!uart_circ_empty(xmit) && count-- > 0) {
  246. if (rd_regl(port, S3C2410_UFSTAT) & ourport->info->tx_fifofull)
  247. break;
  248. wr_regb(port, S3C2410_UTXH, xmit->buf[xmit->tail]);
  249. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  250. port->icount.tx++;
  251. }
  252. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  253. uart_write_wakeup(port);
  254. if (uart_circ_empty(xmit))
  255. s3c24xx_serial_stop_tx(port);
  256. out:
  257. return IRQ_HANDLED;
  258. }
  259. static unsigned int s3c24xx_serial_tx_empty(struct uart_port *port)
  260. {
  261. struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
  262. unsigned long ufstat = rd_regl(port, S3C2410_UFSTAT);
  263. unsigned long ufcon = rd_regl(port, S3C2410_UFCON);
  264. if (ufcon & S3C2410_UFCON_FIFOMODE) {
  265. if ((ufstat & info->tx_fifomask) != 0 ||
  266. (ufstat & info->tx_fifofull))
  267. return 0;
  268. return 1;
  269. }
  270. return s3c24xx_serial_txempty_nofifo(port);
  271. }
  272. /* no modem control lines */
  273. static unsigned int s3c24xx_serial_get_mctrl(struct uart_port *port)
  274. {
  275. unsigned int umstat = rd_regb(port, S3C2410_UMSTAT);
  276. if (umstat & S3C2410_UMSTAT_CTS)
  277. return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
  278. else
  279. return TIOCM_CAR | TIOCM_DSR;
  280. }
  281. static void s3c24xx_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
  282. {
  283. /* todo - possibly remove AFC and do manual CTS */
  284. }
  285. static void s3c24xx_serial_break_ctl(struct uart_port *port, int break_state)
  286. {
  287. unsigned long flags;
  288. unsigned int ucon;
  289. spin_lock_irqsave(&port->lock, flags);
  290. ucon = rd_regl(port, S3C2410_UCON);
  291. if (break_state)
  292. ucon |= S3C2410_UCON_SBREAK;
  293. else
  294. ucon &= ~S3C2410_UCON_SBREAK;
  295. wr_regl(port, S3C2410_UCON, ucon);
  296. spin_unlock_irqrestore(&port->lock, flags);
  297. }
  298. static void s3c24xx_serial_shutdown(struct uart_port *port)
  299. {
  300. struct s3c24xx_uart_port *ourport = to_ourport(port);
  301. if (ourport->tx_claimed) {
  302. free_irq(TX_IRQ(port), ourport);
  303. tx_enabled(port) = 0;
  304. ourport->tx_claimed = 0;
  305. }
  306. if (ourport->rx_claimed) {
  307. free_irq(RX_IRQ(port), ourport);
  308. ourport->rx_claimed = 0;
  309. rx_enabled(port) = 0;
  310. }
  311. }
  312. static int s3c24xx_serial_startup(struct uart_port *port)
  313. {
  314. struct s3c24xx_uart_port *ourport = to_ourport(port);
  315. int ret;
  316. dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
  317. port->mapbase, port->membase);
  318. rx_enabled(port) = 1;
  319. ret = request_irq(RX_IRQ(port),
  320. s3c24xx_serial_rx_chars, 0,
  321. s3c24xx_serial_portname(port), ourport);
  322. if (ret != 0) {
  323. printk(KERN_ERR "cannot get irq %d\n", RX_IRQ(port));
  324. return ret;
  325. }
  326. ourport->rx_claimed = 1;
  327. dbg("requesting tx irq...\n");
  328. tx_enabled(port) = 1;
  329. ret = request_irq(TX_IRQ(port),
  330. s3c24xx_serial_tx_chars, 0,
  331. s3c24xx_serial_portname(port), ourport);
  332. if (ret) {
  333. printk(KERN_ERR "cannot get irq %d\n", TX_IRQ(port));
  334. goto err;
  335. }
  336. ourport->tx_claimed = 1;
  337. dbg("s3c24xx_serial_startup ok\n");
  338. /* the port reset code should have done the correct
  339. * register setup for the port controls */
  340. return ret;
  341. err:
  342. s3c24xx_serial_shutdown(port);
  343. return ret;
  344. }
  345. /* power power management control */
  346. static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
  347. unsigned int old)
  348. {
  349. struct s3c24xx_uart_port *ourport = to_ourport(port);
  350. ourport->pm_level = level;
  351. switch (level) {
  352. case 3:
  353. if (!IS_ERR(ourport->baudclk) && ourport->baudclk != NULL)
  354. clk_disable(ourport->baudclk);
  355. clk_disable(ourport->clk);
  356. break;
  357. case 0:
  358. clk_enable(ourport->clk);
  359. if (!IS_ERR(ourport->baudclk) && ourport->baudclk != NULL)
  360. clk_enable(ourport->baudclk);
  361. break;
  362. default:
  363. printk(KERN_ERR "s3c24xx_serial: unknown pm %d\n", level);
  364. }
  365. }
  366. /* baud rate calculation
  367. *
  368. * The UARTs on the S3C2410/S3C2440 can take their clocks from a number
  369. * of different sources, including the peripheral clock ("pclk") and an
  370. * external clock ("uclk"). The S3C2440 also adds the core clock ("fclk")
  371. * with a programmable extra divisor.
  372. *
  373. * The following code goes through the clock sources, and calculates the
  374. * baud clocks (and the resultant actual baud rates) and then tries to
  375. * pick the closest one and select that.
  376. *
  377. */
  378. #define MAX_CLKS (8)
  379. static struct s3c24xx_uart_clksrc tmp_clksrc = {
  380. .name = "pclk",
  381. .min_baud = 0,
  382. .max_baud = 0,
  383. .divisor = 1,
  384. };
  385. static inline int
  386. s3c24xx_serial_getsource(struct uart_port *port, struct s3c24xx_uart_clksrc *c)
  387. {
  388. struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
  389. return (info->get_clksrc)(port, c);
  390. }
  391. static inline int
  392. s3c24xx_serial_setsource(struct uart_port *port, struct s3c24xx_uart_clksrc *c)
  393. {
  394. struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
  395. return (info->set_clksrc)(port, c);
  396. }
  397. struct baud_calc {
  398. struct s3c24xx_uart_clksrc *clksrc;
  399. unsigned int calc;
  400. unsigned int quot;
  401. struct clk *src;
  402. };
  403. static int s3c24xx_serial_calcbaud(struct baud_calc *calc,
  404. struct uart_port *port,
  405. struct s3c24xx_uart_clksrc *clksrc,
  406. unsigned int baud)
  407. {
  408. unsigned long rate;
  409. calc->src = clk_get(port->dev, clksrc->name);
  410. if (calc->src == NULL || IS_ERR(calc->src))
  411. return 0;
  412. rate = clk_get_rate(calc->src);
  413. rate /= clksrc->divisor;
  414. calc->clksrc = clksrc;
  415. calc->quot = (rate + (8 * baud)) / (16 * baud);
  416. calc->calc = (rate / (calc->quot * 16));
  417. calc->quot--;
  418. return 1;
  419. }
  420. static unsigned int s3c24xx_serial_getclk(struct uart_port *port,
  421. struct s3c24xx_uart_clksrc **clksrc,
  422. struct clk **clk,
  423. unsigned int baud)
  424. {
  425. struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
  426. struct s3c24xx_uart_clksrc *clkp;
  427. struct baud_calc res[MAX_CLKS];
  428. struct baud_calc *resptr, *best, *sptr;
  429. int i;
  430. clkp = cfg->clocks;
  431. best = NULL;
  432. if (cfg->clocks_size < 2) {
  433. if (cfg->clocks_size == 0)
  434. clkp = &tmp_clksrc;
  435. /* check to see if we're sourcing fclk, and if so we're
  436. * going to have to update the clock source
  437. */
  438. if (strcmp(clkp->name, "fclk") == 0) {
  439. struct s3c24xx_uart_clksrc src;
  440. s3c24xx_serial_getsource(port, &src);
  441. /* check that the port already using fclk, and if
  442. * not, then re-select fclk
  443. */
  444. if (strcmp(src.name, clkp->name) == 0) {
  445. s3c24xx_serial_setsource(port, clkp);
  446. s3c24xx_serial_getsource(port, &src);
  447. }
  448. clkp->divisor = src.divisor;
  449. }
  450. s3c24xx_serial_calcbaud(res, port, clkp, baud);
  451. best = res;
  452. resptr = best + 1;
  453. } else {
  454. resptr = res;
  455. for (i = 0; i < cfg->clocks_size; i++, clkp++) {
  456. if (s3c24xx_serial_calcbaud(resptr, port, clkp, baud))
  457. resptr++;
  458. }
  459. }
  460. /* ok, we now need to select the best clock we found */
  461. if (!best) {
  462. unsigned int deviation = (1<<30)|((1<<30)-1);
  463. int calc_deviation;
  464. for (sptr = res; sptr < resptr; sptr++) {
  465. calc_deviation = baud - sptr->calc;
  466. if (calc_deviation < 0)
  467. calc_deviation = -calc_deviation;
  468. if (calc_deviation < deviation) {
  469. best = sptr;
  470. deviation = calc_deviation;
  471. }
  472. }
  473. }
  474. /* store results to pass back */
  475. *clksrc = best->clksrc;
  476. *clk = best->src;
  477. return best->quot;
  478. }
  479. static void s3c24xx_serial_set_termios(struct uart_port *port,
  480. struct ktermios *termios,
  481. struct ktermios *old)
  482. {
  483. struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
  484. struct s3c24xx_uart_port *ourport = to_ourport(port);
  485. struct s3c24xx_uart_clksrc *clksrc = NULL;
  486. struct clk *clk = NULL;
  487. unsigned long flags;
  488. unsigned int baud, quot;
  489. unsigned int ulcon;
  490. unsigned int umcon;
  491. /*
  492. * We don't support modem control lines.
  493. */
  494. termios->c_cflag &= ~(HUPCL | CMSPAR);
  495. termios->c_cflag |= CLOCAL;
  496. /*
  497. * Ask the core to calculate the divisor for us.
  498. */
  499. baud = uart_get_baud_rate(port, termios, old, 0, 115200*8);
  500. if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
  501. quot = port->custom_divisor;
  502. else
  503. quot = s3c24xx_serial_getclk(port, &clksrc, &clk, baud);
  504. /* check to see if we need to change clock source */
  505. if (ourport->clksrc != clksrc || ourport->baudclk != clk) {
  506. s3c24xx_serial_setsource(port, clksrc);
  507. if (ourport->baudclk != NULL && !IS_ERR(ourport->baudclk)) {
  508. clk_disable(ourport->baudclk);
  509. ourport->baudclk = NULL;
  510. }
  511. clk_enable(clk);
  512. ourport->clksrc = clksrc;
  513. ourport->baudclk = clk;
  514. ourport->baudclk_rate = clk ? clk_get_rate(clk) : 0;
  515. }
  516. switch (termios->c_cflag & CSIZE) {
  517. case CS5:
  518. dbg("config: 5bits/char\n");
  519. ulcon = S3C2410_LCON_CS5;
  520. break;
  521. case CS6:
  522. dbg("config: 6bits/char\n");
  523. ulcon = S3C2410_LCON_CS6;
  524. break;
  525. case CS7:
  526. dbg("config: 7bits/char\n");
  527. ulcon = S3C2410_LCON_CS7;
  528. break;
  529. case CS8:
  530. default:
  531. dbg("config: 8bits/char\n");
  532. ulcon = S3C2410_LCON_CS8;
  533. break;
  534. }
  535. /* preserve original lcon IR settings */
  536. ulcon |= (cfg->ulcon & S3C2410_LCON_IRM);
  537. if (termios->c_cflag & CSTOPB)
  538. ulcon |= S3C2410_LCON_STOPB;
  539. umcon = (termios->c_cflag & CRTSCTS) ? S3C2410_UMCOM_AFC : 0;
  540. if (termios->c_cflag & PARENB) {
  541. if (termios->c_cflag & PARODD)
  542. ulcon |= S3C2410_LCON_PODD;
  543. else
  544. ulcon |= S3C2410_LCON_PEVEN;
  545. } else {
  546. ulcon |= S3C2410_LCON_PNONE;
  547. }
  548. spin_lock_irqsave(&port->lock, flags);
  549. dbg("setting ulcon to %08x, brddiv to %d\n", ulcon, quot);
  550. wr_regl(port, S3C2410_ULCON, ulcon);
  551. wr_regl(port, S3C2410_UBRDIV, quot);
  552. wr_regl(port, S3C2410_UMCON, umcon);
  553. dbg("uart: ulcon = 0x%08x, ucon = 0x%08x, ufcon = 0x%08x\n",
  554. rd_regl(port, S3C2410_ULCON),
  555. rd_regl(port, S3C2410_UCON),
  556. rd_regl(port, S3C2410_UFCON));
  557. /*
  558. * Update the per-port timeout.
  559. */
  560. uart_update_timeout(port, termios->c_cflag, baud);
  561. /*
  562. * Which character status flags are we interested in?
  563. */
  564. port->read_status_mask = S3C2410_UERSTAT_OVERRUN;
  565. if (termios->c_iflag & INPCK)
  566. port->read_status_mask |= S3C2410_UERSTAT_FRAME | S3C2410_UERSTAT_PARITY;
  567. /*
  568. * Which character status flags should we ignore?
  569. */
  570. port->ignore_status_mask = 0;
  571. if (termios->c_iflag & IGNPAR)
  572. port->ignore_status_mask |= S3C2410_UERSTAT_OVERRUN;
  573. if (termios->c_iflag & IGNBRK && termios->c_iflag & IGNPAR)
  574. port->ignore_status_mask |= S3C2410_UERSTAT_FRAME;
  575. /*
  576. * Ignore all characters if CREAD is not set.
  577. */
  578. if ((termios->c_cflag & CREAD) == 0)
  579. port->ignore_status_mask |= RXSTAT_DUMMY_READ;
  580. spin_unlock_irqrestore(&port->lock, flags);
  581. }
  582. static const char *s3c24xx_serial_type(struct uart_port *port)
  583. {
  584. switch (port->type) {
  585. case PORT_S3C2410:
  586. return "S3C2410";
  587. case PORT_S3C2440:
  588. return "S3C2440";
  589. case PORT_S3C2412:
  590. return "S3C2412";
  591. default:
  592. return NULL;
  593. }
  594. }
  595. #define MAP_SIZE (0x100)
  596. static void s3c24xx_serial_release_port(struct uart_port *port)
  597. {
  598. release_mem_region(port->mapbase, MAP_SIZE);
  599. }
  600. static int s3c24xx_serial_request_port(struct uart_port *port)
  601. {
  602. const char *name = s3c24xx_serial_portname(port);
  603. return request_mem_region(port->mapbase, MAP_SIZE, name) ? 0 : -EBUSY;
  604. }
  605. static void s3c24xx_serial_config_port(struct uart_port *port, int flags)
  606. {
  607. struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
  608. if (flags & UART_CONFIG_TYPE &&
  609. s3c24xx_serial_request_port(port) == 0)
  610. port->type = info->type;
  611. }
  612. /*
  613. * verify the new serial_struct (for TIOCSSERIAL).
  614. */
  615. static int
  616. s3c24xx_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
  617. {
  618. struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
  619. if (ser->type != PORT_UNKNOWN && ser->type != info->type)
  620. return -EINVAL;
  621. return 0;
  622. }
  623. #ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
  624. static struct console s3c24xx_serial_console;
  625. #define S3C24XX_SERIAL_CONSOLE &s3c24xx_serial_console
  626. #else
  627. #define S3C24XX_SERIAL_CONSOLE NULL
  628. #endif
  629. static struct uart_ops s3c24xx_serial_ops = {
  630. .pm = s3c24xx_serial_pm,
  631. .tx_empty = s3c24xx_serial_tx_empty,
  632. .get_mctrl = s3c24xx_serial_get_mctrl,
  633. .set_mctrl = s3c24xx_serial_set_mctrl,
  634. .stop_tx = s3c24xx_serial_stop_tx,
  635. .start_tx = s3c24xx_serial_start_tx,
  636. .stop_rx = s3c24xx_serial_stop_rx,
  637. .enable_ms = s3c24xx_serial_enable_ms,
  638. .break_ctl = s3c24xx_serial_break_ctl,
  639. .startup = s3c24xx_serial_startup,
  640. .shutdown = s3c24xx_serial_shutdown,
  641. .set_termios = s3c24xx_serial_set_termios,
  642. .type = s3c24xx_serial_type,
  643. .release_port = s3c24xx_serial_release_port,
  644. .request_port = s3c24xx_serial_request_port,
  645. .config_port = s3c24xx_serial_config_port,
  646. .verify_port = s3c24xx_serial_verify_port,
  647. };
  648. static struct uart_driver s3c24xx_uart_drv = {
  649. .owner = THIS_MODULE,
  650. .dev_name = "s3c2410_serial",
  651. .nr = 3,
  652. .cons = S3C24XX_SERIAL_CONSOLE,
  653. .driver_name = S3C24XX_SERIAL_NAME,
  654. .major = S3C24XX_SERIAL_MAJOR,
  655. .minor = S3C24XX_SERIAL_MINOR,
  656. };
  657. static struct s3c24xx_uart_port s3c24xx_serial_ports[NR_PORTS] = {
  658. [0] = {
  659. .port = {
  660. .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[0].port.lock),
  661. .iotype = UPIO_MEM,
  662. .irq = IRQ_S3CUART_RX0,
  663. .uartclk = 0,
  664. .fifosize = 16,
  665. .ops = &s3c24xx_serial_ops,
  666. .flags = UPF_BOOT_AUTOCONF,
  667. .line = 0,
  668. }
  669. },
  670. [1] = {
  671. .port = {
  672. .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[1].port.lock),
  673. .iotype = UPIO_MEM,
  674. .irq = IRQ_S3CUART_RX1,
  675. .uartclk = 0,
  676. .fifosize = 16,
  677. .ops = &s3c24xx_serial_ops,
  678. .flags = UPF_BOOT_AUTOCONF,
  679. .line = 1,
  680. }
  681. },
  682. #if NR_PORTS > 2
  683. [2] = {
  684. .port = {
  685. .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[2].port.lock),
  686. .iotype = UPIO_MEM,
  687. .irq = IRQ_S3CUART_RX2,
  688. .uartclk = 0,
  689. .fifosize = 16,
  690. .ops = &s3c24xx_serial_ops,
  691. .flags = UPF_BOOT_AUTOCONF,
  692. .line = 2,
  693. }
  694. }
  695. #endif
  696. };
  697. /* s3c24xx_serial_resetport
  698. *
  699. * wrapper to call the specific reset for this port (reset the fifos
  700. * and the settings)
  701. */
  702. static inline int s3c24xx_serial_resetport(struct uart_port *port,
  703. struct s3c2410_uartcfg *cfg)
  704. {
  705. struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
  706. return (info->reset_port)(port, cfg);
  707. }
  708. #ifdef CONFIG_CPU_FREQ
  709. static int s3c24xx_serial_cpufreq_transition(struct notifier_block *nb,
  710. unsigned long val, void *data)
  711. {
  712. struct s3c24xx_uart_port *port;
  713. struct uart_port *uport;
  714. port = container_of(nb, struct s3c24xx_uart_port, freq_transition);
  715. uport = &port->port;
  716. /* check to see if port is enabled */
  717. if (port->pm_level != 0)
  718. return 0;
  719. /* try and work out if the baudrate is changing, we can detect
  720. * a change in rate, but we do not have support for detecting
  721. * a disturbance in the clock-rate over the change.
  722. */
  723. if (IS_ERR(port->clk))
  724. goto exit;
  725. if (port->baudclk_rate == clk_get_rate(port->clk))
  726. goto exit;
  727. if (val == CPUFREQ_PRECHANGE) {
  728. /* we should really shut the port down whilst the
  729. * frequency change is in progress. */
  730. } else if (val == CPUFREQ_POSTCHANGE) {
  731. struct ktermios *termios;
  732. struct tty_struct *tty;
  733. if (uport->info == NULL) {
  734. printk(KERN_WARNING "%s: info NULL\n", __func__);
  735. goto exit;
  736. }
  737. tty = uport->info->port.tty;
  738. if (tty == NULL) {
  739. printk(KERN_WARNING "%s: tty is NULL\n", __func__);
  740. goto exit;
  741. }
  742. termios = tty->termios;
  743. if (termios == NULL) {
  744. printk(KERN_WARNING "%s: no termios?\n", __func__);
  745. goto exit;
  746. }
  747. s3c24xx_serial_set_termios(uport, termios, NULL);
  748. }
  749. exit:
  750. return 0;
  751. }
  752. static inline int s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port)
  753. {
  754. port->freq_transition.notifier_call = s3c24xx_serial_cpufreq_transition;
  755. return cpufreq_register_notifier(&port->freq_transition,
  756. CPUFREQ_TRANSITION_NOTIFIER);
  757. }
  758. static inline void s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port)
  759. {
  760. cpufreq_unregister_notifier(&port->freq_transition,
  761. CPUFREQ_TRANSITION_NOTIFIER);
  762. }
  763. #else
  764. static inline int s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port)
  765. {
  766. return 0;
  767. }
  768. static inline void s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port)
  769. {
  770. }
  771. #endif
  772. /* s3c24xx_serial_init_port
  773. *
  774. * initialise a single serial port from the platform device given
  775. */
  776. static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
  777. struct s3c24xx_uart_info *info,
  778. struct platform_device *platdev)
  779. {
  780. struct uart_port *port = &ourport->port;
  781. struct s3c2410_uartcfg *cfg;
  782. struct resource *res;
  783. int ret;
  784. dbg("s3c24xx_serial_init_port: port=%p, platdev=%p\n", port, platdev);
  785. if (platdev == NULL)
  786. return -ENODEV;
  787. cfg = s3c24xx_dev_to_cfg(&platdev->dev);
  788. if (port->mapbase != 0)
  789. return 0;
  790. if (cfg->hwport > 3)
  791. return -EINVAL;
  792. /* setup info for port */
  793. port->dev = &platdev->dev;
  794. ourport->info = info;
  795. /* copy the info in from provided structure */
  796. ourport->port.fifosize = info->fifosize;
  797. dbg("s3c24xx_serial_init_port: %p (hw %d)...\n", port, cfg->hwport);
  798. port->uartclk = 1;
  799. if (cfg->uart_flags & UPF_CONS_FLOW) {
  800. dbg("s3c24xx_serial_init_port: enabling flow control\n");
  801. port->flags |= UPF_CONS_FLOW;
  802. }
  803. /* sort our the physical and virtual addresses for each UART */
  804. res = platform_get_resource(platdev, IORESOURCE_MEM, 0);
  805. if (res == NULL) {
  806. printk(KERN_ERR "failed to find memory resource for uart\n");
  807. return -EINVAL;
  808. }
  809. dbg("resource %p (%lx..%lx)\n", res, res->start, res->end);
  810. port->mapbase = res->start;
  811. port->membase = S3C24XX_VA_UART + (res->start - S3C24XX_PA_UART);
  812. ret = platform_get_irq(platdev, 0);
  813. if (ret < 0)
  814. port->irq = 0;
  815. else
  816. port->irq = ret;
  817. ourport->clk = clk_get(&platdev->dev, "uart");
  818. dbg("port: map=%08x, mem=%08x, irq=%d, clock=%ld\n",
  819. port->mapbase, port->membase, port->irq, port->uartclk);
  820. /* reset the fifos (and setup the uart) */
  821. s3c24xx_serial_resetport(port, cfg);
  822. return 0;
  823. }
  824. static ssize_t s3c24xx_serial_show_clksrc(struct device *dev,
  825. struct device_attribute *attr,
  826. char *buf)
  827. {
  828. struct uart_port *port = s3c24xx_dev_to_port(dev);
  829. struct s3c24xx_uart_port *ourport = to_ourport(port);
  830. return snprintf(buf, PAGE_SIZE, "* %s\n", ourport->clksrc->name);
  831. }
  832. static DEVICE_ATTR(clock_source, S_IRUGO, s3c24xx_serial_show_clksrc, NULL);
  833. /* Device driver serial port probe */
  834. static int probe_index;
  835. int s3c24xx_serial_probe(struct platform_device *dev,
  836. struct s3c24xx_uart_info *info)
  837. {
  838. struct s3c24xx_uart_port *ourport;
  839. int ret;
  840. dbg("s3c24xx_serial_probe(%p, %p) %d\n", dev, info, probe_index);
  841. ourport = &s3c24xx_serial_ports[probe_index];
  842. probe_index++;
  843. dbg("%s: initialising port %p...\n", __func__, ourport);
  844. ret = s3c24xx_serial_init_port(ourport, info, dev);
  845. if (ret < 0)
  846. goto probe_err;
  847. dbg("%s: adding port\n", __func__);
  848. uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
  849. platform_set_drvdata(dev, &ourport->port);
  850. ret = device_create_file(&dev->dev, &dev_attr_clock_source);
  851. if (ret < 0)
  852. printk(KERN_ERR "%s: failed to add clksrc attr.\n", __func__);
  853. ret = s3c24xx_serial_cpufreq_register(ourport);
  854. if (ret < 0)
  855. dev_err(&dev->dev, "failed to add cpufreq notifier\n");
  856. return 0;
  857. probe_err:
  858. return ret;
  859. }
  860. EXPORT_SYMBOL_GPL(s3c24xx_serial_probe);
  861. int s3c24xx_serial_remove(struct platform_device *dev)
  862. {
  863. struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
  864. if (port) {
  865. s3c24xx_serial_cpufreq_deregister(to_ourport(port));
  866. device_remove_file(&dev->dev, &dev_attr_clock_source);
  867. uart_remove_one_port(&s3c24xx_uart_drv, port);
  868. }
  869. return 0;
  870. }
  871. EXPORT_SYMBOL_GPL(s3c24xx_serial_remove);
  872. /* UART power management code */
  873. #ifdef CONFIG_PM
  874. static int s3c24xx_serial_suspend(struct platform_device *dev, pm_message_t state)
  875. {
  876. struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
  877. if (port)
  878. uart_suspend_port(&s3c24xx_uart_drv, port);
  879. return 0;
  880. }
  881. static int s3c24xx_serial_resume(struct platform_device *dev)
  882. {
  883. struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
  884. struct s3c24xx_uart_port *ourport = to_ourport(port);
  885. if (port) {
  886. clk_enable(ourport->clk);
  887. s3c24xx_serial_resetport(port, s3c24xx_port_to_cfg(port));
  888. clk_disable(ourport->clk);
  889. uart_resume_port(&s3c24xx_uart_drv, port);
  890. }
  891. return 0;
  892. }
  893. #endif
  894. int s3c24xx_serial_init(struct platform_driver *drv,
  895. struct s3c24xx_uart_info *info)
  896. {
  897. dbg("s3c24xx_serial_init(%p,%p)\n", drv, info);
  898. #ifdef CONFIG_PM
  899. drv->suspend = s3c24xx_serial_suspend;
  900. drv->resume = s3c24xx_serial_resume;
  901. #endif
  902. return platform_driver_register(drv);
  903. }
  904. EXPORT_SYMBOL_GPL(s3c24xx_serial_init);
  905. /* module initialisation code */
  906. static int __init s3c24xx_serial_modinit(void)
  907. {
  908. int ret;
  909. ret = uart_register_driver(&s3c24xx_uart_drv);
  910. if (ret < 0) {
  911. printk(KERN_ERR "failed to register UART driver\n");
  912. return -1;
  913. }
  914. return 0;
  915. }
  916. static void __exit s3c24xx_serial_modexit(void)
  917. {
  918. uart_unregister_driver(&s3c24xx_uart_drv);
  919. }
  920. module_init(s3c24xx_serial_modinit);
  921. module_exit(s3c24xx_serial_modexit);
  922. /* Console code */
  923. #ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
  924. static struct uart_port *cons_uart;
  925. static int
  926. s3c24xx_serial_console_txrdy(struct uart_port *port, unsigned int ufcon)
  927. {
  928. struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
  929. unsigned long ufstat, utrstat;
  930. if (ufcon & S3C2410_UFCON_FIFOMODE) {
  931. /* fifo mode - check ammount of data in fifo registers... */
  932. ufstat = rd_regl(port, S3C2410_UFSTAT);
  933. return (ufstat & info->tx_fifofull) ? 0 : 1;
  934. }
  935. /* in non-fifo mode, we go and use the tx buffer empty */
  936. utrstat = rd_regl(port, S3C2410_UTRSTAT);
  937. return (utrstat & S3C2410_UTRSTAT_TXE) ? 1 : 0;
  938. }
  939. static void
  940. s3c24xx_serial_console_putchar(struct uart_port *port, int ch)
  941. {
  942. unsigned int ufcon = rd_regl(cons_uart, S3C2410_UFCON);
  943. while (!s3c24xx_serial_console_txrdy(port, ufcon))
  944. barrier();
  945. wr_regb(cons_uart, S3C2410_UTXH, ch);
  946. }
  947. static void
  948. s3c24xx_serial_console_write(struct console *co, const char *s,
  949. unsigned int count)
  950. {
  951. uart_console_write(cons_uart, s, count, s3c24xx_serial_console_putchar);
  952. }
  953. static void __init
  954. s3c24xx_serial_get_options(struct uart_port *port, int *baud,
  955. int *parity, int *bits)
  956. {
  957. struct s3c24xx_uart_clksrc clksrc;
  958. struct clk *clk;
  959. unsigned int ulcon;
  960. unsigned int ucon;
  961. unsigned int ubrdiv;
  962. unsigned long rate;
  963. ulcon = rd_regl(port, S3C2410_ULCON);
  964. ucon = rd_regl(port, S3C2410_UCON);
  965. ubrdiv = rd_regl(port, S3C2410_UBRDIV);
  966. dbg("s3c24xx_serial_get_options: port=%p\n"
  967. "registers: ulcon=%08x, ucon=%08x, ubdriv=%08x\n",
  968. port, ulcon, ucon, ubrdiv);
  969. if ((ucon & 0xf) != 0) {
  970. /* consider the serial port configured if the tx/rx mode set */
  971. switch (ulcon & S3C2410_LCON_CSMASK) {
  972. case S3C2410_LCON_CS5:
  973. *bits = 5;
  974. break;
  975. case S3C2410_LCON_CS6:
  976. *bits = 6;
  977. break;
  978. case S3C2410_LCON_CS7:
  979. *bits = 7;
  980. break;
  981. default:
  982. case S3C2410_LCON_CS8:
  983. *bits = 8;
  984. break;
  985. }
  986. switch (ulcon & S3C2410_LCON_PMASK) {
  987. case S3C2410_LCON_PEVEN:
  988. *parity = 'e';
  989. break;
  990. case S3C2410_LCON_PODD:
  991. *parity = 'o';
  992. break;
  993. case S3C2410_LCON_PNONE:
  994. default:
  995. *parity = 'n';
  996. }
  997. /* now calculate the baud rate */
  998. s3c24xx_serial_getsource(port, &clksrc);
  999. clk = clk_get(port->dev, clksrc.name);
  1000. if (!IS_ERR(clk) && clk != NULL)
  1001. rate = clk_get_rate(clk) / clksrc.divisor;
  1002. else
  1003. rate = 1;
  1004. *baud = rate / (16 * (ubrdiv + 1));
  1005. dbg("calculated baud %d\n", *baud);
  1006. }
  1007. }
  1008. /* s3c24xx_serial_init_ports
  1009. *
  1010. * initialise the serial ports from the machine provided initialisation
  1011. * data.
  1012. */
  1013. static int s3c24xx_serial_init_ports(struct s3c24xx_uart_info *info)
  1014. {
  1015. struct s3c24xx_uart_port *ptr = s3c24xx_serial_ports;
  1016. struct platform_device **platdev_ptr;
  1017. int i;
  1018. dbg("s3c24xx_serial_init_ports: initialising ports...\n");
  1019. platdev_ptr = s3c24xx_uart_devs;
  1020. for (i = 0; i < NR_PORTS; i++, ptr++, platdev_ptr++) {
  1021. s3c24xx_serial_init_port(ptr, info, *platdev_ptr);
  1022. }
  1023. return 0;
  1024. }
  1025. static int __init
  1026. s3c24xx_serial_console_setup(struct console *co, char *options)
  1027. {
  1028. struct uart_port *port;
  1029. int baud = 9600;
  1030. int bits = 8;
  1031. int parity = 'n';
  1032. int flow = 'n';
  1033. dbg("s3c24xx_serial_console_setup: co=%p (%d), %s\n",
  1034. co, co->index, options);
  1035. /* is this a valid port */
  1036. if (co->index == -1 || co->index >= NR_PORTS)
  1037. co->index = 0;
  1038. port = &s3c24xx_serial_ports[co->index].port;
  1039. /* is the port configured? */
  1040. if (port->mapbase == 0x0) {
  1041. co->index = 0;
  1042. port = &s3c24xx_serial_ports[co->index].port;
  1043. }
  1044. cons_uart = port;
  1045. dbg("s3c24xx_serial_console_setup: port=%p (%d)\n", port, co->index);
  1046. /*
  1047. * Check whether an invalid uart number has been specified, and
  1048. * if so, search for the first available port that does have
  1049. * console support.
  1050. */
  1051. if (options)
  1052. uart_parse_options(options, &baud, &parity, &bits, &flow);
  1053. else
  1054. s3c24xx_serial_get_options(port, &baud, &parity, &bits);
  1055. dbg("s3c24xx_serial_console_setup: baud %d\n", baud);
  1056. return uart_set_options(port, co, baud, parity, bits, flow);
  1057. }
  1058. /* s3c24xx_serial_initconsole
  1059. *
  1060. * initialise the console from one of the uart drivers
  1061. */
  1062. static struct console s3c24xx_serial_console = {
  1063. .name = S3C24XX_SERIAL_NAME,
  1064. .device = uart_console_device,
  1065. .flags = CON_PRINTBUFFER,
  1066. .index = -1,
  1067. .write = s3c24xx_serial_console_write,
  1068. .setup = s3c24xx_serial_console_setup
  1069. };
  1070. int s3c24xx_serial_initconsole(struct platform_driver *drv,
  1071. struct s3c24xx_uart_info *info)
  1072. {
  1073. struct platform_device *dev = s3c24xx_uart_devs[0];
  1074. dbg("s3c24xx_serial_initconsole\n");
  1075. /* select driver based on the cpu */
  1076. if (dev == NULL) {
  1077. printk(KERN_ERR "s3c24xx: no devices for console init\n");
  1078. return 0;
  1079. }
  1080. if (strcmp(dev->name, drv->driver.name) != 0)
  1081. return 0;
  1082. s3c24xx_serial_console.data = &s3c24xx_uart_drv;
  1083. s3c24xx_serial_init_ports(info);
  1084. register_console(&s3c24xx_serial_console);
  1085. return 0;
  1086. }
  1087. #endif /* CONFIG_SERIAL_SAMSUNG_CONSOLE */
  1088. MODULE_DESCRIPTION("Samsung SoC Serial port driver");
  1089. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  1090. MODULE_LICENSE("GPL v2");