samsung.c 33 KB

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