samsung.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815
  1. /*
  2. * Driver core for Samsung SoC onboard UARTs.
  3. *
  4. * Ben Dooks, Copyright (c) 2003-2008 Simtec Electronics
  5. * http://armlinux.simtec.co.uk/
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. /* Hote on 2410 error handling
  12. *
  13. * The s3c2410 manual has a love/hate affair with the contents of the
  14. * UERSTAT register in the UART blocks, and keeps marking some of the
  15. * error bits as reserved. Having checked with the s3c2410x01,
  16. * it copes with BREAKs properly, so I am happy to ignore the RESERVED
  17. * feature from the latter versions of the manual.
  18. *
  19. * If it becomes aparrent that latter versions of the 2410 remove these
  20. * bits, then action will have to be taken to differentiate the versions
  21. * and change the policy on BREAK
  22. *
  23. * BJD, 04-Nov-2004
  24. */
  25. #if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  26. #define SUPPORT_SYSRQ
  27. #endif
  28. #include <linux/module.h>
  29. #include <linux/ioport.h>
  30. #include <linux/io.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/init.h>
  33. #include <linux/sysrq.h>
  34. #include <linux/console.h>
  35. #include <linux/tty.h>
  36. #include <linux/tty_flip.h>
  37. #include <linux/serial_core.h>
  38. #include <linux/serial.h>
  39. #include <linux/delay.h>
  40. #include <linux/clk.h>
  41. #include <linux/cpufreq.h>
  42. #include <linux/of.h>
  43. #include <asm/irq.h>
  44. #include <mach/hardware.h>
  45. #include <plat/regs-serial.h>
  46. #include <plat/clock.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 coming 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. /*
  71. * s3c64xx and later SoC's include the interrupt mask and status registers in
  72. * the controller itself, unlike the s3c24xx SoC's which have these registers
  73. * in the interrupt controller. Check if the port type is s3c64xx or higher.
  74. */
  75. static int s3c24xx_serial_has_interrupt_mask(struct uart_port *port)
  76. {
  77. return to_ourport(port)->info->type == PORT_S3C6400;
  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. struct s3c24xx_uart_port *ourport = to_ourport(port);
  110. if (tx_enabled(port)) {
  111. if (s3c24xx_serial_has_interrupt_mask(port))
  112. __set_bit(S3C64XX_UINTM_TXD,
  113. portaddrl(port, S3C64XX_UINTM));
  114. else
  115. disable_irq_nosync(ourport->tx_irq);
  116. tx_enabled(port) = 0;
  117. if (port->flags & UPF_CONS_FLOW)
  118. s3c24xx_serial_rx_enable(port);
  119. }
  120. }
  121. static void s3c24xx_serial_start_tx(struct uart_port *port)
  122. {
  123. struct s3c24xx_uart_port *ourport = to_ourport(port);
  124. if (!tx_enabled(port)) {
  125. if (port->flags & UPF_CONS_FLOW)
  126. s3c24xx_serial_rx_disable(port);
  127. if (s3c24xx_serial_has_interrupt_mask(port))
  128. __clear_bit(S3C64XX_UINTM_TXD,
  129. portaddrl(port, S3C64XX_UINTM));
  130. else
  131. enable_irq(ourport->tx_irq);
  132. tx_enabled(port) = 1;
  133. }
  134. }
  135. static void s3c24xx_serial_stop_rx(struct uart_port *port)
  136. {
  137. struct s3c24xx_uart_port *ourport = to_ourport(port);
  138. if (rx_enabled(port)) {
  139. dbg("s3c24xx_serial_stop_rx: port=%p\n", port);
  140. if (s3c24xx_serial_has_interrupt_mask(port))
  141. __set_bit(S3C64XX_UINTM_RXD,
  142. portaddrl(port, S3C64XX_UINTM));
  143. else
  144. disable_irq_nosync(ourport->rx_irq);
  145. rx_enabled(port) = 0;
  146. }
  147. }
  148. static void s3c24xx_serial_enable_ms(struct uart_port *port)
  149. {
  150. }
  151. static inline struct s3c24xx_uart_info *s3c24xx_port_to_info(struct uart_port *port)
  152. {
  153. return to_ourport(port)->info;
  154. }
  155. static inline struct s3c2410_uartcfg *s3c24xx_port_to_cfg(struct uart_port *port)
  156. {
  157. struct s3c24xx_uart_port *ourport;
  158. if (port->dev == NULL)
  159. return NULL;
  160. ourport = container_of(port, struct s3c24xx_uart_port, port);
  161. return ourport->cfg;
  162. }
  163. static int s3c24xx_serial_rx_fifocnt(struct s3c24xx_uart_port *ourport,
  164. unsigned long ufstat)
  165. {
  166. struct s3c24xx_uart_info *info = ourport->info;
  167. if (ufstat & info->rx_fifofull)
  168. return ourport->port.fifosize;
  169. return (ufstat & info->rx_fifomask) >> info->rx_fifoshift;
  170. }
  171. /* ? - where has parity gone?? */
  172. #define S3C2410_UERSTAT_PARITY (0x1000)
  173. static irqreturn_t
  174. s3c24xx_serial_rx_chars(int irq, void *dev_id)
  175. {
  176. struct s3c24xx_uart_port *ourport = dev_id;
  177. struct uart_port *port = &ourport->port;
  178. unsigned int ufcon, ch, flag, ufstat, uerstat;
  179. unsigned long flags;
  180. int max_count = 64;
  181. spin_lock_irqsave(&port->lock, flags);
  182. while (max_count-- > 0) {
  183. ufcon = rd_regl(port, S3C2410_UFCON);
  184. ufstat = rd_regl(port, S3C2410_UFSTAT);
  185. if (s3c24xx_serial_rx_fifocnt(ourport, ufstat) == 0)
  186. break;
  187. uerstat = rd_regl(port, S3C2410_UERSTAT);
  188. ch = rd_regb(port, S3C2410_URXH);
  189. if (port->flags & UPF_CONS_FLOW) {
  190. int txe = s3c24xx_serial_txempty_nofifo(port);
  191. if (rx_enabled(port)) {
  192. if (!txe) {
  193. rx_enabled(port) = 0;
  194. continue;
  195. }
  196. } else {
  197. if (txe) {
  198. ufcon |= S3C2410_UFCON_RESETRX;
  199. wr_regl(port, S3C2410_UFCON, ufcon);
  200. rx_enabled(port) = 1;
  201. goto out;
  202. }
  203. continue;
  204. }
  205. }
  206. /* insert the character into the buffer */
  207. flag = TTY_NORMAL;
  208. port->icount.rx++;
  209. if (unlikely(uerstat & S3C2410_UERSTAT_ANY)) {
  210. dbg("rxerr: port ch=0x%02x, rxs=0x%08x\n",
  211. ch, uerstat);
  212. /* check for break */
  213. if (uerstat & S3C2410_UERSTAT_BREAK) {
  214. dbg("break!\n");
  215. port->icount.brk++;
  216. if (uart_handle_break(port))
  217. goto ignore_char;
  218. }
  219. if (uerstat & S3C2410_UERSTAT_FRAME)
  220. port->icount.frame++;
  221. if (uerstat & S3C2410_UERSTAT_OVERRUN)
  222. port->icount.overrun++;
  223. uerstat &= port->read_status_mask;
  224. if (uerstat & S3C2410_UERSTAT_BREAK)
  225. flag = TTY_BREAK;
  226. else if (uerstat & S3C2410_UERSTAT_PARITY)
  227. flag = TTY_PARITY;
  228. else if (uerstat & (S3C2410_UERSTAT_FRAME |
  229. S3C2410_UERSTAT_OVERRUN))
  230. flag = TTY_FRAME;
  231. }
  232. if (uart_handle_sysrq_char(port, ch))
  233. goto ignore_char;
  234. uart_insert_char(port, uerstat, S3C2410_UERSTAT_OVERRUN,
  235. ch, flag);
  236. ignore_char:
  237. continue;
  238. }
  239. tty_flip_buffer_push(&port->state->port);
  240. out:
  241. spin_unlock_irqrestore(&port->lock, flags);
  242. return IRQ_HANDLED;
  243. }
  244. static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id)
  245. {
  246. struct s3c24xx_uart_port *ourport = id;
  247. struct uart_port *port = &ourport->port;
  248. struct circ_buf *xmit = &port->state->xmit;
  249. unsigned long flags;
  250. int count = 256;
  251. spin_lock_irqsave(&port->lock, flags);
  252. if (port->x_char) {
  253. wr_regb(port, S3C2410_UTXH, port->x_char);
  254. port->icount.tx++;
  255. port->x_char = 0;
  256. goto out;
  257. }
  258. /* if there isn't anything more to transmit, or the uart is now
  259. * stopped, disable the uart and exit
  260. */
  261. if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
  262. s3c24xx_serial_stop_tx(port);
  263. goto out;
  264. }
  265. /* try and drain the buffer... */
  266. while (!uart_circ_empty(xmit) && count-- > 0) {
  267. if (rd_regl(port, S3C2410_UFSTAT) & ourport->info->tx_fifofull)
  268. break;
  269. wr_regb(port, S3C2410_UTXH, xmit->buf[xmit->tail]);
  270. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  271. port->icount.tx++;
  272. }
  273. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) {
  274. spin_unlock(&port->lock);
  275. uart_write_wakeup(port);
  276. spin_lock(&port->lock);
  277. }
  278. if (uart_circ_empty(xmit))
  279. s3c24xx_serial_stop_tx(port);
  280. out:
  281. spin_unlock_irqrestore(&port->lock, flags);
  282. return IRQ_HANDLED;
  283. }
  284. /* interrupt handler for s3c64xx and later SoC's.*/
  285. static irqreturn_t s3c64xx_serial_handle_irq(int irq, void *id)
  286. {
  287. struct s3c24xx_uart_port *ourport = id;
  288. struct uart_port *port = &ourport->port;
  289. unsigned int pend = rd_regl(port, S3C64XX_UINTP);
  290. irqreturn_t ret = IRQ_HANDLED;
  291. if (pend & S3C64XX_UINTM_RXD_MSK) {
  292. ret = s3c24xx_serial_rx_chars(irq, id);
  293. wr_regl(port, S3C64XX_UINTP, S3C64XX_UINTM_RXD_MSK);
  294. }
  295. if (pend & S3C64XX_UINTM_TXD_MSK) {
  296. ret = s3c24xx_serial_tx_chars(irq, id);
  297. wr_regl(port, S3C64XX_UINTP, S3C64XX_UINTM_TXD_MSK);
  298. }
  299. return ret;
  300. }
  301. static unsigned int s3c24xx_serial_tx_empty(struct uart_port *port)
  302. {
  303. struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
  304. unsigned long ufstat = rd_regl(port, S3C2410_UFSTAT);
  305. unsigned long ufcon = rd_regl(port, S3C2410_UFCON);
  306. if (ufcon & S3C2410_UFCON_FIFOMODE) {
  307. if ((ufstat & info->tx_fifomask) != 0 ||
  308. (ufstat & info->tx_fifofull))
  309. return 0;
  310. return 1;
  311. }
  312. return s3c24xx_serial_txempty_nofifo(port);
  313. }
  314. /* no modem control lines */
  315. static unsigned int s3c24xx_serial_get_mctrl(struct uart_port *port)
  316. {
  317. unsigned int umstat = rd_regb(port, S3C2410_UMSTAT);
  318. if (umstat & S3C2410_UMSTAT_CTS)
  319. return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
  320. else
  321. return TIOCM_CAR | TIOCM_DSR;
  322. }
  323. static void s3c24xx_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
  324. {
  325. /* todo - possibly remove AFC and do manual CTS */
  326. }
  327. static void s3c24xx_serial_break_ctl(struct uart_port *port, int break_state)
  328. {
  329. unsigned long flags;
  330. unsigned int ucon;
  331. spin_lock_irqsave(&port->lock, flags);
  332. ucon = rd_regl(port, S3C2410_UCON);
  333. if (break_state)
  334. ucon |= S3C2410_UCON_SBREAK;
  335. else
  336. ucon &= ~S3C2410_UCON_SBREAK;
  337. wr_regl(port, S3C2410_UCON, ucon);
  338. spin_unlock_irqrestore(&port->lock, flags);
  339. }
  340. static void s3c24xx_serial_shutdown(struct uart_port *port)
  341. {
  342. struct s3c24xx_uart_port *ourport = to_ourport(port);
  343. if (ourport->tx_claimed) {
  344. if (!s3c24xx_serial_has_interrupt_mask(port))
  345. free_irq(ourport->tx_irq, ourport);
  346. tx_enabled(port) = 0;
  347. ourport->tx_claimed = 0;
  348. }
  349. if (ourport->rx_claimed) {
  350. if (!s3c24xx_serial_has_interrupt_mask(port))
  351. free_irq(ourport->rx_irq, ourport);
  352. ourport->rx_claimed = 0;
  353. rx_enabled(port) = 0;
  354. }
  355. /* Clear pending interrupts and mask all interrupts */
  356. if (s3c24xx_serial_has_interrupt_mask(port)) {
  357. free_irq(port->irq, ourport);
  358. wr_regl(port, S3C64XX_UINTP, 0xf);
  359. wr_regl(port, S3C64XX_UINTM, 0xf);
  360. }
  361. }
  362. static int s3c24xx_serial_startup(struct uart_port *port)
  363. {
  364. struct s3c24xx_uart_port *ourport = to_ourport(port);
  365. int ret;
  366. dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
  367. port->mapbase, port->membase);
  368. rx_enabled(port) = 1;
  369. ret = request_irq(ourport->rx_irq, s3c24xx_serial_rx_chars, 0,
  370. s3c24xx_serial_portname(port), ourport);
  371. if (ret != 0) {
  372. dev_err(port->dev, "cannot get irq %d\n", ourport->rx_irq);
  373. return ret;
  374. }
  375. ourport->rx_claimed = 1;
  376. dbg("requesting tx irq...\n");
  377. tx_enabled(port) = 1;
  378. ret = request_irq(ourport->tx_irq, s3c24xx_serial_tx_chars, 0,
  379. s3c24xx_serial_portname(port), ourport);
  380. if (ret) {
  381. dev_err(port->dev, "cannot get irq %d\n", ourport->tx_irq);
  382. goto err;
  383. }
  384. ourport->tx_claimed = 1;
  385. dbg("s3c24xx_serial_startup ok\n");
  386. /* the port reset code should have done the correct
  387. * register setup for the port controls */
  388. return ret;
  389. err:
  390. s3c24xx_serial_shutdown(port);
  391. return ret;
  392. }
  393. static int s3c64xx_serial_startup(struct uart_port *port)
  394. {
  395. struct s3c24xx_uart_port *ourport = to_ourport(port);
  396. int ret;
  397. dbg("s3c64xx_serial_startup: port=%p (%08lx,%p)\n",
  398. port->mapbase, port->membase);
  399. wr_regl(port, S3C64XX_UINTM, 0xf);
  400. ret = request_irq(port->irq, s3c64xx_serial_handle_irq, IRQF_SHARED,
  401. s3c24xx_serial_portname(port), ourport);
  402. if (ret) {
  403. dev_err(port->dev, "cannot get irq %d\n", port->irq);
  404. return ret;
  405. }
  406. /* For compatibility with s3c24xx Soc's */
  407. rx_enabled(port) = 1;
  408. ourport->rx_claimed = 1;
  409. tx_enabled(port) = 0;
  410. ourport->tx_claimed = 1;
  411. /* Enable Rx Interrupt */
  412. __clear_bit(S3C64XX_UINTM_RXD, portaddrl(port, S3C64XX_UINTM));
  413. dbg("s3c64xx_serial_startup ok\n");
  414. return ret;
  415. }
  416. /* power power management control */
  417. static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
  418. unsigned int old)
  419. {
  420. struct s3c24xx_uart_port *ourport = to_ourport(port);
  421. ourport->pm_level = level;
  422. switch (level) {
  423. case 3:
  424. if (!IS_ERR(ourport->baudclk))
  425. clk_disable_unprepare(ourport->baudclk);
  426. clk_disable_unprepare(ourport->clk);
  427. break;
  428. case 0:
  429. clk_prepare_enable(ourport->clk);
  430. if (!IS_ERR(ourport->baudclk))
  431. clk_prepare_enable(ourport->baudclk);
  432. break;
  433. default:
  434. dev_err(port->dev, "s3c24xx_serial: unknown pm %d\n", level);
  435. }
  436. }
  437. /* baud rate calculation
  438. *
  439. * The UARTs on the S3C2410/S3C2440 can take their clocks from a number
  440. * of different sources, including the peripheral clock ("pclk") and an
  441. * external clock ("uclk"). The S3C2440 also adds the core clock ("fclk")
  442. * with a programmable extra divisor.
  443. *
  444. * The following code goes through the clock sources, and calculates the
  445. * baud clocks (and the resultant actual baud rates) and then tries to
  446. * pick the closest one and select that.
  447. *
  448. */
  449. #define MAX_CLK_NAME_LENGTH 15
  450. static inline int s3c24xx_serial_getsource(struct uart_port *port)
  451. {
  452. struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
  453. unsigned int ucon;
  454. if (info->num_clks == 1)
  455. return 0;
  456. ucon = rd_regl(port, S3C2410_UCON);
  457. ucon &= info->clksel_mask;
  458. return ucon >> info->clksel_shift;
  459. }
  460. static void s3c24xx_serial_setsource(struct uart_port *port,
  461. unsigned int clk_sel)
  462. {
  463. struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
  464. unsigned int ucon;
  465. if (info->num_clks == 1)
  466. return;
  467. ucon = rd_regl(port, S3C2410_UCON);
  468. if ((ucon & info->clksel_mask) >> info->clksel_shift == clk_sel)
  469. return;
  470. ucon &= ~info->clksel_mask;
  471. ucon |= clk_sel << info->clksel_shift;
  472. wr_regl(port, S3C2410_UCON, ucon);
  473. }
  474. static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
  475. unsigned int req_baud, struct clk **best_clk,
  476. unsigned int *clk_num)
  477. {
  478. struct s3c24xx_uart_info *info = ourport->info;
  479. struct clk *clk;
  480. unsigned long rate;
  481. unsigned int cnt, baud, quot, clk_sel, best_quot = 0;
  482. char clkname[MAX_CLK_NAME_LENGTH];
  483. int calc_deviation, deviation = (1 << 30) - 1;
  484. clk_sel = (ourport->cfg->clk_sel) ? ourport->cfg->clk_sel :
  485. ourport->info->def_clk_sel;
  486. for (cnt = 0; cnt < info->num_clks; cnt++) {
  487. if (!(clk_sel & (1 << cnt)))
  488. continue;
  489. sprintf(clkname, "clk_uart_baud%d", cnt);
  490. clk = clk_get(ourport->port.dev, clkname);
  491. if (IS_ERR(clk))
  492. continue;
  493. rate = clk_get_rate(clk);
  494. if (!rate)
  495. continue;
  496. if (ourport->info->has_divslot) {
  497. unsigned long div = rate / req_baud;
  498. /* The UDIVSLOT register on the newer UARTs allows us to
  499. * get a divisor adjustment of 1/16th on the baud clock.
  500. *
  501. * We don't keep the UDIVSLOT value (the 16ths we
  502. * calculated by not multiplying the baud by 16) as it
  503. * is easy enough to recalculate.
  504. */
  505. quot = div / 16;
  506. baud = rate / div;
  507. } else {
  508. quot = (rate + (8 * req_baud)) / (16 * req_baud);
  509. baud = rate / (quot * 16);
  510. }
  511. quot--;
  512. calc_deviation = req_baud - baud;
  513. if (calc_deviation < 0)
  514. calc_deviation = -calc_deviation;
  515. if (calc_deviation < deviation) {
  516. *best_clk = clk;
  517. best_quot = quot;
  518. *clk_num = cnt;
  519. deviation = calc_deviation;
  520. }
  521. }
  522. return best_quot;
  523. }
  524. /* udivslot_table[]
  525. *
  526. * This table takes the fractional value of the baud divisor and gives
  527. * the recommended setting for the UDIVSLOT register.
  528. */
  529. static u16 udivslot_table[16] = {
  530. [0] = 0x0000,
  531. [1] = 0x0080,
  532. [2] = 0x0808,
  533. [3] = 0x0888,
  534. [4] = 0x2222,
  535. [5] = 0x4924,
  536. [6] = 0x4A52,
  537. [7] = 0x54AA,
  538. [8] = 0x5555,
  539. [9] = 0xD555,
  540. [10] = 0xD5D5,
  541. [11] = 0xDDD5,
  542. [12] = 0xDDDD,
  543. [13] = 0xDFDD,
  544. [14] = 0xDFDF,
  545. [15] = 0xFFDF,
  546. };
  547. static void s3c24xx_serial_set_termios(struct uart_port *port,
  548. struct ktermios *termios,
  549. struct ktermios *old)
  550. {
  551. struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
  552. struct s3c24xx_uart_port *ourport = to_ourport(port);
  553. struct clk *clk = ERR_PTR(-EINVAL);
  554. unsigned long flags;
  555. unsigned int baud, quot, clk_sel = 0;
  556. unsigned int ulcon;
  557. unsigned int umcon;
  558. unsigned int udivslot = 0;
  559. /*
  560. * We don't support modem control lines.
  561. */
  562. termios->c_cflag &= ~(HUPCL | CMSPAR);
  563. termios->c_cflag |= CLOCAL;
  564. /*
  565. * Ask the core to calculate the divisor for us.
  566. */
  567. baud = uart_get_baud_rate(port, termios, old, 0, 115200*8);
  568. quot = s3c24xx_serial_getclk(ourport, baud, &clk, &clk_sel);
  569. if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
  570. quot = port->custom_divisor;
  571. if (IS_ERR(clk))
  572. return;
  573. /* check to see if we need to change clock source */
  574. if (ourport->baudclk != clk) {
  575. s3c24xx_serial_setsource(port, clk_sel);
  576. if (!IS_ERR(ourport->baudclk)) {
  577. clk_disable_unprepare(ourport->baudclk);
  578. ourport->baudclk = ERR_PTR(-EINVAL);
  579. }
  580. clk_prepare_enable(clk);
  581. ourport->baudclk = clk;
  582. ourport->baudclk_rate = clk ? clk_get_rate(clk) : 0;
  583. }
  584. if (ourport->info->has_divslot) {
  585. unsigned int div = ourport->baudclk_rate / baud;
  586. if (cfg->has_fracval) {
  587. udivslot = (div & 15);
  588. dbg("fracval = %04x\n", udivslot);
  589. } else {
  590. udivslot = udivslot_table[div & 15];
  591. dbg("udivslot = %04x (div %d)\n", udivslot, div & 15);
  592. }
  593. }
  594. switch (termios->c_cflag & CSIZE) {
  595. case CS5:
  596. dbg("config: 5bits/char\n");
  597. ulcon = S3C2410_LCON_CS5;
  598. break;
  599. case CS6:
  600. dbg("config: 6bits/char\n");
  601. ulcon = S3C2410_LCON_CS6;
  602. break;
  603. case CS7:
  604. dbg("config: 7bits/char\n");
  605. ulcon = S3C2410_LCON_CS7;
  606. break;
  607. case CS8:
  608. default:
  609. dbg("config: 8bits/char\n");
  610. ulcon = S3C2410_LCON_CS8;
  611. break;
  612. }
  613. /* preserve original lcon IR settings */
  614. ulcon |= (cfg->ulcon & S3C2410_LCON_IRM);
  615. if (termios->c_cflag & CSTOPB)
  616. ulcon |= S3C2410_LCON_STOPB;
  617. umcon = (termios->c_cflag & CRTSCTS) ? S3C2410_UMCOM_AFC : 0;
  618. if (termios->c_cflag & PARENB) {
  619. if (termios->c_cflag & PARODD)
  620. ulcon |= S3C2410_LCON_PODD;
  621. else
  622. ulcon |= S3C2410_LCON_PEVEN;
  623. } else {
  624. ulcon |= S3C2410_LCON_PNONE;
  625. }
  626. spin_lock_irqsave(&port->lock, flags);
  627. dbg("setting ulcon to %08x, brddiv to %d, udivslot %08x\n",
  628. ulcon, quot, udivslot);
  629. wr_regl(port, S3C2410_ULCON, ulcon);
  630. wr_regl(port, S3C2410_UBRDIV, quot);
  631. wr_regl(port, S3C2410_UMCON, umcon);
  632. if (ourport->info->has_divslot)
  633. wr_regl(port, S3C2443_DIVSLOT, udivslot);
  634. dbg("uart: ulcon = 0x%08x, ucon = 0x%08x, ufcon = 0x%08x\n",
  635. rd_regl(port, S3C2410_ULCON),
  636. rd_regl(port, S3C2410_UCON),
  637. rd_regl(port, S3C2410_UFCON));
  638. /*
  639. * Update the per-port timeout.
  640. */
  641. uart_update_timeout(port, termios->c_cflag, baud);
  642. /*
  643. * Which character status flags are we interested in?
  644. */
  645. port->read_status_mask = S3C2410_UERSTAT_OVERRUN;
  646. if (termios->c_iflag & INPCK)
  647. port->read_status_mask |= S3C2410_UERSTAT_FRAME | S3C2410_UERSTAT_PARITY;
  648. /*
  649. * Which character status flags should we ignore?
  650. */
  651. port->ignore_status_mask = 0;
  652. if (termios->c_iflag & IGNPAR)
  653. port->ignore_status_mask |= S3C2410_UERSTAT_OVERRUN;
  654. if (termios->c_iflag & IGNBRK && termios->c_iflag & IGNPAR)
  655. port->ignore_status_mask |= S3C2410_UERSTAT_FRAME;
  656. /*
  657. * Ignore all characters if CREAD is not set.
  658. */
  659. if ((termios->c_cflag & CREAD) == 0)
  660. port->ignore_status_mask |= RXSTAT_DUMMY_READ;
  661. spin_unlock_irqrestore(&port->lock, flags);
  662. }
  663. static const char *s3c24xx_serial_type(struct uart_port *port)
  664. {
  665. switch (port->type) {
  666. case PORT_S3C2410:
  667. return "S3C2410";
  668. case PORT_S3C2440:
  669. return "S3C2440";
  670. case PORT_S3C2412:
  671. return "S3C2412";
  672. case PORT_S3C6400:
  673. return "S3C6400/10";
  674. default:
  675. return NULL;
  676. }
  677. }
  678. #define MAP_SIZE (0x100)
  679. static void s3c24xx_serial_release_port(struct uart_port *port)
  680. {
  681. release_mem_region(port->mapbase, MAP_SIZE);
  682. }
  683. static int s3c24xx_serial_request_port(struct uart_port *port)
  684. {
  685. const char *name = s3c24xx_serial_portname(port);
  686. return request_mem_region(port->mapbase, MAP_SIZE, name) ? 0 : -EBUSY;
  687. }
  688. static void s3c24xx_serial_config_port(struct uart_port *port, int flags)
  689. {
  690. struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
  691. if (flags & UART_CONFIG_TYPE &&
  692. s3c24xx_serial_request_port(port) == 0)
  693. port->type = info->type;
  694. }
  695. /*
  696. * verify the new serial_struct (for TIOCSSERIAL).
  697. */
  698. static int
  699. s3c24xx_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
  700. {
  701. struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
  702. if (ser->type != PORT_UNKNOWN && ser->type != info->type)
  703. return -EINVAL;
  704. return 0;
  705. }
  706. #ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
  707. static struct console s3c24xx_serial_console;
  708. static int __init s3c24xx_serial_console_init(void)
  709. {
  710. register_console(&s3c24xx_serial_console);
  711. return 0;
  712. }
  713. console_initcall(s3c24xx_serial_console_init);
  714. #define S3C24XX_SERIAL_CONSOLE &s3c24xx_serial_console
  715. #else
  716. #define S3C24XX_SERIAL_CONSOLE NULL
  717. #endif
  718. #ifdef CONFIG_CONSOLE_POLL
  719. static int s3c24xx_serial_get_poll_char(struct uart_port *port);
  720. static void s3c24xx_serial_put_poll_char(struct uart_port *port,
  721. unsigned char c);
  722. #endif
  723. static struct uart_ops s3c24xx_serial_ops = {
  724. .pm = s3c24xx_serial_pm,
  725. .tx_empty = s3c24xx_serial_tx_empty,
  726. .get_mctrl = s3c24xx_serial_get_mctrl,
  727. .set_mctrl = s3c24xx_serial_set_mctrl,
  728. .stop_tx = s3c24xx_serial_stop_tx,
  729. .start_tx = s3c24xx_serial_start_tx,
  730. .stop_rx = s3c24xx_serial_stop_rx,
  731. .enable_ms = s3c24xx_serial_enable_ms,
  732. .break_ctl = s3c24xx_serial_break_ctl,
  733. .startup = s3c24xx_serial_startup,
  734. .shutdown = s3c24xx_serial_shutdown,
  735. .set_termios = s3c24xx_serial_set_termios,
  736. .type = s3c24xx_serial_type,
  737. .release_port = s3c24xx_serial_release_port,
  738. .request_port = s3c24xx_serial_request_port,
  739. .config_port = s3c24xx_serial_config_port,
  740. .verify_port = s3c24xx_serial_verify_port,
  741. #ifdef CONFIG_CONSOLE_POLL
  742. .poll_get_char = s3c24xx_serial_get_poll_char,
  743. .poll_put_char = s3c24xx_serial_put_poll_char,
  744. #endif
  745. };
  746. static struct uart_driver s3c24xx_uart_drv = {
  747. .owner = THIS_MODULE,
  748. .driver_name = "s3c2410_serial",
  749. .nr = CONFIG_SERIAL_SAMSUNG_UARTS,
  750. .cons = S3C24XX_SERIAL_CONSOLE,
  751. .dev_name = S3C24XX_SERIAL_NAME,
  752. .major = S3C24XX_SERIAL_MAJOR,
  753. .minor = S3C24XX_SERIAL_MINOR,
  754. };
  755. static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS] = {
  756. [0] = {
  757. .port = {
  758. .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[0].port.lock),
  759. .iotype = UPIO_MEM,
  760. .uartclk = 0,
  761. .fifosize = 16,
  762. .ops = &s3c24xx_serial_ops,
  763. .flags = UPF_BOOT_AUTOCONF,
  764. .line = 0,
  765. }
  766. },
  767. [1] = {
  768. .port = {
  769. .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[1].port.lock),
  770. .iotype = UPIO_MEM,
  771. .uartclk = 0,
  772. .fifosize = 16,
  773. .ops = &s3c24xx_serial_ops,
  774. .flags = UPF_BOOT_AUTOCONF,
  775. .line = 1,
  776. }
  777. },
  778. #if CONFIG_SERIAL_SAMSUNG_UARTS > 2
  779. [2] = {
  780. .port = {
  781. .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[2].port.lock),
  782. .iotype = UPIO_MEM,
  783. .uartclk = 0,
  784. .fifosize = 16,
  785. .ops = &s3c24xx_serial_ops,
  786. .flags = UPF_BOOT_AUTOCONF,
  787. .line = 2,
  788. }
  789. },
  790. #endif
  791. #if CONFIG_SERIAL_SAMSUNG_UARTS > 3
  792. [3] = {
  793. .port = {
  794. .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[3].port.lock),
  795. .iotype = UPIO_MEM,
  796. .uartclk = 0,
  797. .fifosize = 16,
  798. .ops = &s3c24xx_serial_ops,
  799. .flags = UPF_BOOT_AUTOCONF,
  800. .line = 3,
  801. }
  802. }
  803. #endif
  804. };
  805. /* s3c24xx_serial_resetport
  806. *
  807. * reset the fifos and other the settings.
  808. */
  809. static void s3c24xx_serial_resetport(struct uart_port *port,
  810. struct s3c2410_uartcfg *cfg)
  811. {
  812. struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
  813. unsigned long ucon = rd_regl(port, S3C2410_UCON);
  814. unsigned int ucon_mask;
  815. ucon_mask = info->clksel_mask;
  816. if (info->type == PORT_S3C2440)
  817. ucon_mask |= S3C2440_UCON0_DIVMASK;
  818. ucon &= ucon_mask;
  819. wr_regl(port, S3C2410_UCON, ucon | cfg->ucon);
  820. /* reset both fifos */
  821. wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
  822. wr_regl(port, S3C2410_UFCON, cfg->ufcon);
  823. /* some delay is required after fifo reset */
  824. udelay(1);
  825. }
  826. #ifdef CONFIG_CPU_FREQ
  827. static int s3c24xx_serial_cpufreq_transition(struct notifier_block *nb,
  828. unsigned long val, void *data)
  829. {
  830. struct s3c24xx_uart_port *port;
  831. struct uart_port *uport;
  832. port = container_of(nb, struct s3c24xx_uart_port, freq_transition);
  833. uport = &port->port;
  834. /* check to see if port is enabled */
  835. if (port->pm_level != 0)
  836. return 0;
  837. /* try and work out if the baudrate is changing, we can detect
  838. * a change in rate, but we do not have support for detecting
  839. * a disturbance in the clock-rate over the change.
  840. */
  841. if (IS_ERR(port->baudclk))
  842. goto exit;
  843. if (port->baudclk_rate == clk_get_rate(port->baudclk))
  844. goto exit;
  845. if (val == CPUFREQ_PRECHANGE) {
  846. /* we should really shut the port down whilst the
  847. * frequency change is in progress. */
  848. } else if (val == CPUFREQ_POSTCHANGE) {
  849. struct ktermios *termios;
  850. struct tty_struct *tty;
  851. if (uport->state == NULL)
  852. goto exit;
  853. tty = uport->state->port.tty;
  854. if (tty == NULL)
  855. goto exit;
  856. termios = &tty->termios;
  857. if (termios == NULL) {
  858. dev_warn(uport->dev, "%s: no termios?\n", __func__);
  859. goto exit;
  860. }
  861. s3c24xx_serial_set_termios(uport, termios, NULL);
  862. }
  863. exit:
  864. return 0;
  865. }
  866. static inline int s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port)
  867. {
  868. port->freq_transition.notifier_call = s3c24xx_serial_cpufreq_transition;
  869. return cpufreq_register_notifier(&port->freq_transition,
  870. CPUFREQ_TRANSITION_NOTIFIER);
  871. }
  872. static inline void s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port)
  873. {
  874. cpufreq_unregister_notifier(&port->freq_transition,
  875. CPUFREQ_TRANSITION_NOTIFIER);
  876. }
  877. #else
  878. static inline int s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port)
  879. {
  880. return 0;
  881. }
  882. static inline void s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port)
  883. {
  884. }
  885. #endif
  886. /* s3c24xx_serial_init_port
  887. *
  888. * initialise a single serial port from the platform device given
  889. */
  890. static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
  891. struct platform_device *platdev)
  892. {
  893. struct uart_port *port = &ourport->port;
  894. struct s3c2410_uartcfg *cfg = ourport->cfg;
  895. struct resource *res;
  896. int ret;
  897. dbg("s3c24xx_serial_init_port: port=%p, platdev=%p\n", port, platdev);
  898. if (platdev == NULL)
  899. return -ENODEV;
  900. if (port->mapbase != 0)
  901. return 0;
  902. /* setup info for port */
  903. port->dev = &platdev->dev;
  904. /* Startup sequence is different for s3c64xx and higher SoC's */
  905. if (s3c24xx_serial_has_interrupt_mask(port))
  906. s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
  907. port->uartclk = 1;
  908. if (cfg->uart_flags & UPF_CONS_FLOW) {
  909. dbg("s3c24xx_serial_init_port: enabling flow control\n");
  910. port->flags |= UPF_CONS_FLOW;
  911. }
  912. /* sort our the physical and virtual addresses for each UART */
  913. res = platform_get_resource(platdev, IORESOURCE_MEM, 0);
  914. if (res == NULL) {
  915. dev_err(port->dev, "failed to find memory resource for uart\n");
  916. return -EINVAL;
  917. }
  918. dbg("resource %p (%lx..%lx)\n", res, res->start, res->end);
  919. port->membase = devm_ioremap(port->dev, res->start, resource_size(res));
  920. if (!port->membase) {
  921. dev_err(port->dev, "failed to remap controller address\n");
  922. return -EBUSY;
  923. }
  924. port->mapbase = res->start;
  925. ret = platform_get_irq(platdev, 0);
  926. if (ret < 0)
  927. port->irq = 0;
  928. else {
  929. port->irq = ret;
  930. ourport->rx_irq = ret;
  931. ourport->tx_irq = ret + 1;
  932. }
  933. ret = platform_get_irq(platdev, 1);
  934. if (ret > 0)
  935. ourport->tx_irq = ret;
  936. ourport->clk = clk_get(&platdev->dev, "uart");
  937. /* Keep all interrupts masked and cleared */
  938. if (s3c24xx_serial_has_interrupt_mask(port)) {
  939. wr_regl(port, S3C64XX_UINTM, 0xf);
  940. wr_regl(port, S3C64XX_UINTP, 0xf);
  941. wr_regl(port, S3C64XX_UINTSP, 0xf);
  942. }
  943. dbg("port: map=%08x, mem=%08x, irq=%d (%d,%d), clock=%ld\n",
  944. port->mapbase, port->membase, port->irq,
  945. ourport->rx_irq, ourport->tx_irq, port->uartclk);
  946. /* reset the fifos (and setup the uart) */
  947. s3c24xx_serial_resetport(port, cfg);
  948. return 0;
  949. }
  950. #ifdef CONFIG_SAMSUNG_CLOCK
  951. static ssize_t s3c24xx_serial_show_clksrc(struct device *dev,
  952. struct device_attribute *attr,
  953. char *buf)
  954. {
  955. struct uart_port *port = s3c24xx_dev_to_port(dev);
  956. struct s3c24xx_uart_port *ourport = to_ourport(port);
  957. if (IS_ERR(ourport->baudclk))
  958. return -EINVAL;
  959. return snprintf(buf, PAGE_SIZE, "* %s\n",
  960. ourport->baudclk->name ?: "(null)");
  961. }
  962. static DEVICE_ATTR(clock_source, S_IRUGO, s3c24xx_serial_show_clksrc, NULL);
  963. #endif
  964. /* Device driver serial port probe */
  965. static const struct of_device_id s3c24xx_uart_dt_match[];
  966. static int probe_index;
  967. static inline struct s3c24xx_serial_drv_data *s3c24xx_get_driver_data(
  968. struct platform_device *pdev)
  969. {
  970. #ifdef CONFIG_OF
  971. if (pdev->dev.of_node) {
  972. const struct of_device_id *match;
  973. match = of_match_node(s3c24xx_uart_dt_match, pdev->dev.of_node);
  974. return (struct s3c24xx_serial_drv_data *)match->data;
  975. }
  976. #endif
  977. return (struct s3c24xx_serial_drv_data *)
  978. platform_get_device_id(pdev)->driver_data;
  979. }
  980. static int s3c24xx_serial_probe(struct platform_device *pdev)
  981. {
  982. struct s3c24xx_uart_port *ourport;
  983. int ret;
  984. dbg("s3c24xx_serial_probe(%p) %d\n", pdev, probe_index);
  985. ourport = &s3c24xx_serial_ports[probe_index];
  986. ourport->drv_data = s3c24xx_get_driver_data(pdev);
  987. if (!ourport->drv_data) {
  988. dev_err(&pdev->dev, "could not find driver data\n");
  989. return -ENODEV;
  990. }
  991. ourport->baudclk = ERR_PTR(-EINVAL);
  992. ourport->info = ourport->drv_data->info;
  993. ourport->cfg = (pdev->dev.platform_data) ?
  994. (struct s3c2410_uartcfg *)pdev->dev.platform_data :
  995. ourport->drv_data->def_cfg;
  996. ourport->port.fifosize = (ourport->info->fifosize) ?
  997. ourport->info->fifosize :
  998. ourport->drv_data->fifosize[probe_index];
  999. probe_index++;
  1000. dbg("%s: initialising port %p...\n", __func__, ourport);
  1001. ret = s3c24xx_serial_init_port(ourport, pdev);
  1002. if (ret < 0)
  1003. goto probe_err;
  1004. dbg("%s: adding port\n", __func__);
  1005. uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
  1006. platform_set_drvdata(pdev, &ourport->port);
  1007. #ifdef CONFIG_SAMSUNG_CLOCK
  1008. ret = device_create_file(&pdev->dev, &dev_attr_clock_source);
  1009. if (ret < 0)
  1010. dev_err(&pdev->dev, "failed to add clock source attr.\n");
  1011. #endif
  1012. ret = s3c24xx_serial_cpufreq_register(ourport);
  1013. if (ret < 0)
  1014. dev_err(&pdev->dev, "failed to add cpufreq notifier\n");
  1015. return 0;
  1016. probe_err:
  1017. return ret;
  1018. }
  1019. static int s3c24xx_serial_remove(struct platform_device *dev)
  1020. {
  1021. struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
  1022. if (port) {
  1023. s3c24xx_serial_cpufreq_deregister(to_ourport(port));
  1024. #ifdef CONFIG_SAMSUNG_CLOCK
  1025. device_remove_file(&dev->dev, &dev_attr_clock_source);
  1026. #endif
  1027. uart_remove_one_port(&s3c24xx_uart_drv, port);
  1028. }
  1029. return 0;
  1030. }
  1031. /* UART power management code */
  1032. #ifdef CONFIG_PM_SLEEP
  1033. static int s3c24xx_serial_suspend(struct device *dev)
  1034. {
  1035. struct uart_port *port = s3c24xx_dev_to_port(dev);
  1036. if (port)
  1037. uart_suspend_port(&s3c24xx_uart_drv, port);
  1038. return 0;
  1039. }
  1040. static int s3c24xx_serial_resume(struct device *dev)
  1041. {
  1042. struct uart_port *port = s3c24xx_dev_to_port(dev);
  1043. struct s3c24xx_uart_port *ourport = to_ourport(port);
  1044. if (port) {
  1045. clk_prepare_enable(ourport->clk);
  1046. s3c24xx_serial_resetport(port, s3c24xx_port_to_cfg(port));
  1047. clk_disable_unprepare(ourport->clk);
  1048. uart_resume_port(&s3c24xx_uart_drv, port);
  1049. }
  1050. return 0;
  1051. }
  1052. static int s3c24xx_serial_resume_noirq(struct device *dev)
  1053. {
  1054. struct uart_port *port = s3c24xx_dev_to_port(dev);
  1055. if (port) {
  1056. /* restore IRQ mask */
  1057. if (s3c24xx_serial_has_interrupt_mask(port)) {
  1058. unsigned int uintm = 0xf;
  1059. if (tx_enabled(port))
  1060. uintm &= ~S3C64XX_UINTM_TXD_MSK;
  1061. if (rx_enabled(port))
  1062. uintm &= ~S3C64XX_UINTM_RXD_MSK;
  1063. wr_regl(port, S3C64XX_UINTM, uintm);
  1064. }
  1065. }
  1066. return 0;
  1067. }
  1068. static const struct dev_pm_ops s3c24xx_serial_pm_ops = {
  1069. .suspend = s3c24xx_serial_suspend,
  1070. .resume = s3c24xx_serial_resume,
  1071. .resume_noirq = s3c24xx_serial_resume_noirq,
  1072. };
  1073. #define SERIAL_SAMSUNG_PM_OPS (&s3c24xx_serial_pm_ops)
  1074. #else /* !CONFIG_PM_SLEEP */
  1075. #define SERIAL_SAMSUNG_PM_OPS NULL
  1076. #endif /* CONFIG_PM_SLEEP */
  1077. /* Console code */
  1078. #ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
  1079. static struct uart_port *cons_uart;
  1080. static int
  1081. s3c24xx_serial_console_txrdy(struct uart_port *port, unsigned int ufcon)
  1082. {
  1083. struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
  1084. unsigned long ufstat, utrstat;
  1085. if (ufcon & S3C2410_UFCON_FIFOMODE) {
  1086. /* fifo mode - check amount of data in fifo registers... */
  1087. ufstat = rd_regl(port, S3C2410_UFSTAT);
  1088. return (ufstat & info->tx_fifofull) ? 0 : 1;
  1089. }
  1090. /* in non-fifo mode, we go and use the tx buffer empty */
  1091. utrstat = rd_regl(port, S3C2410_UTRSTAT);
  1092. return (utrstat & S3C2410_UTRSTAT_TXE) ? 1 : 0;
  1093. }
  1094. static bool
  1095. s3c24xx_port_configured(unsigned int ucon)
  1096. {
  1097. /* consider the serial port configured if the tx/rx mode set */
  1098. return (ucon & 0xf) != 0;
  1099. }
  1100. #ifdef CONFIG_CONSOLE_POLL
  1101. /*
  1102. * Console polling routines for writing and reading from the uart while
  1103. * in an interrupt or debug context.
  1104. */
  1105. static int s3c24xx_serial_get_poll_char(struct uart_port *port)
  1106. {
  1107. struct s3c24xx_uart_port *ourport = to_ourport(port);
  1108. unsigned int ufstat;
  1109. ufstat = rd_regl(port, S3C2410_UFSTAT);
  1110. if (s3c24xx_serial_rx_fifocnt(ourport, ufstat) == 0)
  1111. return NO_POLL_CHAR;
  1112. return rd_regb(port, S3C2410_URXH);
  1113. }
  1114. static void s3c24xx_serial_put_poll_char(struct uart_port *port,
  1115. unsigned char c)
  1116. {
  1117. unsigned int ufcon = rd_regl(cons_uart, S3C2410_UFCON);
  1118. unsigned int ucon = rd_regl(cons_uart, S3C2410_UCON);
  1119. /* not possible to xmit on unconfigured port */
  1120. if (!s3c24xx_port_configured(ucon))
  1121. return;
  1122. while (!s3c24xx_serial_console_txrdy(port, ufcon))
  1123. cpu_relax();
  1124. wr_regb(cons_uart, S3C2410_UTXH, c);
  1125. }
  1126. #endif /* CONFIG_CONSOLE_POLL */
  1127. static void
  1128. s3c24xx_serial_console_putchar(struct uart_port *port, int ch)
  1129. {
  1130. unsigned int ufcon = rd_regl(cons_uart, S3C2410_UFCON);
  1131. unsigned int ucon = rd_regl(cons_uart, S3C2410_UCON);
  1132. /* not possible to xmit on unconfigured port */
  1133. if (!s3c24xx_port_configured(ucon))
  1134. return;
  1135. while (!s3c24xx_serial_console_txrdy(port, ufcon))
  1136. barrier();
  1137. wr_regb(cons_uart, S3C2410_UTXH, ch);
  1138. }
  1139. static void
  1140. s3c24xx_serial_console_write(struct console *co, const char *s,
  1141. unsigned int count)
  1142. {
  1143. uart_console_write(cons_uart, s, count, s3c24xx_serial_console_putchar);
  1144. }
  1145. static void __init
  1146. s3c24xx_serial_get_options(struct uart_port *port, int *baud,
  1147. int *parity, int *bits)
  1148. {
  1149. struct clk *clk;
  1150. unsigned int ulcon;
  1151. unsigned int ucon;
  1152. unsigned int ubrdiv;
  1153. unsigned long rate;
  1154. unsigned int clk_sel;
  1155. char clk_name[MAX_CLK_NAME_LENGTH];
  1156. ulcon = rd_regl(port, S3C2410_ULCON);
  1157. ucon = rd_regl(port, S3C2410_UCON);
  1158. ubrdiv = rd_regl(port, S3C2410_UBRDIV);
  1159. dbg("s3c24xx_serial_get_options: port=%p\n"
  1160. "registers: ulcon=%08x, ucon=%08x, ubdriv=%08x\n",
  1161. port, ulcon, ucon, ubrdiv);
  1162. if (s3c24xx_port_configured(ucon)) {
  1163. switch (ulcon & S3C2410_LCON_CSMASK) {
  1164. case S3C2410_LCON_CS5:
  1165. *bits = 5;
  1166. break;
  1167. case S3C2410_LCON_CS6:
  1168. *bits = 6;
  1169. break;
  1170. case S3C2410_LCON_CS7:
  1171. *bits = 7;
  1172. break;
  1173. default:
  1174. case S3C2410_LCON_CS8:
  1175. *bits = 8;
  1176. break;
  1177. }
  1178. switch (ulcon & S3C2410_LCON_PMASK) {
  1179. case S3C2410_LCON_PEVEN:
  1180. *parity = 'e';
  1181. break;
  1182. case S3C2410_LCON_PODD:
  1183. *parity = 'o';
  1184. break;
  1185. case S3C2410_LCON_PNONE:
  1186. default:
  1187. *parity = 'n';
  1188. }
  1189. /* now calculate the baud rate */
  1190. clk_sel = s3c24xx_serial_getsource(port);
  1191. sprintf(clk_name, "clk_uart_baud%d", clk_sel);
  1192. clk = clk_get(port->dev, clk_name);
  1193. if (!IS_ERR(clk))
  1194. rate = clk_get_rate(clk);
  1195. else
  1196. rate = 1;
  1197. *baud = rate / (16 * (ubrdiv + 1));
  1198. dbg("calculated baud %d\n", *baud);
  1199. }
  1200. }
  1201. static int __init
  1202. s3c24xx_serial_console_setup(struct console *co, char *options)
  1203. {
  1204. struct uart_port *port;
  1205. int baud = 9600;
  1206. int bits = 8;
  1207. int parity = 'n';
  1208. int flow = 'n';
  1209. dbg("s3c24xx_serial_console_setup: co=%p (%d), %s\n",
  1210. co, co->index, options);
  1211. /* is this a valid port */
  1212. if (co->index == -1 || co->index >= CONFIG_SERIAL_SAMSUNG_UARTS)
  1213. co->index = 0;
  1214. port = &s3c24xx_serial_ports[co->index].port;
  1215. /* is the port configured? */
  1216. if (port->mapbase == 0x0)
  1217. return -ENODEV;
  1218. cons_uart = port;
  1219. dbg("s3c24xx_serial_console_setup: port=%p (%d)\n", port, co->index);
  1220. /*
  1221. * Check whether an invalid uart number has been specified, and
  1222. * if so, search for the first available port that does have
  1223. * console support.
  1224. */
  1225. if (options)
  1226. uart_parse_options(options, &baud, &parity, &bits, &flow);
  1227. else
  1228. s3c24xx_serial_get_options(port, &baud, &parity, &bits);
  1229. dbg("s3c24xx_serial_console_setup: baud %d\n", baud);
  1230. return uart_set_options(port, co, baud, parity, bits, flow);
  1231. }
  1232. static struct console s3c24xx_serial_console = {
  1233. .name = S3C24XX_SERIAL_NAME,
  1234. .device = uart_console_device,
  1235. .flags = CON_PRINTBUFFER,
  1236. .index = -1,
  1237. .write = s3c24xx_serial_console_write,
  1238. .setup = s3c24xx_serial_console_setup,
  1239. .data = &s3c24xx_uart_drv,
  1240. };
  1241. #endif /* CONFIG_SERIAL_SAMSUNG_CONSOLE */
  1242. #ifdef CONFIG_CPU_S3C2410
  1243. static struct s3c24xx_serial_drv_data s3c2410_serial_drv_data = {
  1244. .info = &(struct s3c24xx_uart_info) {
  1245. .name = "Samsung S3C2410 UART",
  1246. .type = PORT_S3C2410,
  1247. .fifosize = 16,
  1248. .rx_fifomask = S3C2410_UFSTAT_RXMASK,
  1249. .rx_fifoshift = S3C2410_UFSTAT_RXSHIFT,
  1250. .rx_fifofull = S3C2410_UFSTAT_RXFULL,
  1251. .tx_fifofull = S3C2410_UFSTAT_TXFULL,
  1252. .tx_fifomask = S3C2410_UFSTAT_TXMASK,
  1253. .tx_fifoshift = S3C2410_UFSTAT_TXSHIFT,
  1254. .def_clk_sel = S3C2410_UCON_CLKSEL0,
  1255. .num_clks = 2,
  1256. .clksel_mask = S3C2410_UCON_CLKMASK,
  1257. .clksel_shift = S3C2410_UCON_CLKSHIFT,
  1258. },
  1259. .def_cfg = &(struct s3c2410_uartcfg) {
  1260. .ucon = S3C2410_UCON_DEFAULT,
  1261. .ufcon = S3C2410_UFCON_DEFAULT,
  1262. },
  1263. };
  1264. #define S3C2410_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c2410_serial_drv_data)
  1265. #else
  1266. #define S3C2410_SERIAL_DRV_DATA (kernel_ulong_t)NULL
  1267. #endif
  1268. #ifdef CONFIG_CPU_S3C2412
  1269. static struct s3c24xx_serial_drv_data s3c2412_serial_drv_data = {
  1270. .info = &(struct s3c24xx_uart_info) {
  1271. .name = "Samsung S3C2412 UART",
  1272. .type = PORT_S3C2412,
  1273. .fifosize = 64,
  1274. .has_divslot = 1,
  1275. .rx_fifomask = S3C2440_UFSTAT_RXMASK,
  1276. .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
  1277. .rx_fifofull = S3C2440_UFSTAT_RXFULL,
  1278. .tx_fifofull = S3C2440_UFSTAT_TXFULL,
  1279. .tx_fifomask = S3C2440_UFSTAT_TXMASK,
  1280. .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
  1281. .def_clk_sel = S3C2410_UCON_CLKSEL2,
  1282. .num_clks = 4,
  1283. .clksel_mask = S3C2412_UCON_CLKMASK,
  1284. .clksel_shift = S3C2412_UCON_CLKSHIFT,
  1285. },
  1286. .def_cfg = &(struct s3c2410_uartcfg) {
  1287. .ucon = S3C2410_UCON_DEFAULT,
  1288. .ufcon = S3C2410_UFCON_DEFAULT,
  1289. },
  1290. };
  1291. #define S3C2412_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c2412_serial_drv_data)
  1292. #else
  1293. #define S3C2412_SERIAL_DRV_DATA (kernel_ulong_t)NULL
  1294. #endif
  1295. #if defined(CONFIG_CPU_S3C2440) || defined(CONFIG_CPU_S3C2416) || \
  1296. defined(CONFIG_CPU_S3C2443) || defined(CONFIG_CPU_S3C2442)
  1297. static struct s3c24xx_serial_drv_data s3c2440_serial_drv_data = {
  1298. .info = &(struct s3c24xx_uart_info) {
  1299. .name = "Samsung S3C2440 UART",
  1300. .type = PORT_S3C2440,
  1301. .fifosize = 64,
  1302. .has_divslot = 1,
  1303. .rx_fifomask = S3C2440_UFSTAT_RXMASK,
  1304. .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
  1305. .rx_fifofull = S3C2440_UFSTAT_RXFULL,
  1306. .tx_fifofull = S3C2440_UFSTAT_TXFULL,
  1307. .tx_fifomask = S3C2440_UFSTAT_TXMASK,
  1308. .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
  1309. .def_clk_sel = S3C2410_UCON_CLKSEL2,
  1310. .num_clks = 4,
  1311. .clksel_mask = S3C2412_UCON_CLKMASK,
  1312. .clksel_shift = S3C2412_UCON_CLKSHIFT,
  1313. },
  1314. .def_cfg = &(struct s3c2410_uartcfg) {
  1315. .ucon = S3C2410_UCON_DEFAULT,
  1316. .ufcon = S3C2410_UFCON_DEFAULT,
  1317. },
  1318. };
  1319. #define S3C2440_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c2440_serial_drv_data)
  1320. #else
  1321. #define S3C2440_SERIAL_DRV_DATA (kernel_ulong_t)NULL
  1322. #endif
  1323. #if defined(CONFIG_CPU_S3C6400) || defined(CONFIG_CPU_S3C6410) || \
  1324. defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450) || \
  1325. defined(CONFIG_CPU_S5PC100)
  1326. static struct s3c24xx_serial_drv_data s3c6400_serial_drv_data = {
  1327. .info = &(struct s3c24xx_uart_info) {
  1328. .name = "Samsung S3C6400 UART",
  1329. .type = PORT_S3C6400,
  1330. .fifosize = 64,
  1331. .has_divslot = 1,
  1332. .rx_fifomask = S3C2440_UFSTAT_RXMASK,
  1333. .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
  1334. .rx_fifofull = S3C2440_UFSTAT_RXFULL,
  1335. .tx_fifofull = S3C2440_UFSTAT_TXFULL,
  1336. .tx_fifomask = S3C2440_UFSTAT_TXMASK,
  1337. .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
  1338. .def_clk_sel = S3C2410_UCON_CLKSEL2,
  1339. .num_clks = 4,
  1340. .clksel_mask = S3C6400_UCON_CLKMASK,
  1341. .clksel_shift = S3C6400_UCON_CLKSHIFT,
  1342. },
  1343. .def_cfg = &(struct s3c2410_uartcfg) {
  1344. .ucon = S3C2410_UCON_DEFAULT,
  1345. .ufcon = S3C2410_UFCON_DEFAULT,
  1346. },
  1347. };
  1348. #define S3C6400_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c6400_serial_drv_data)
  1349. #else
  1350. #define S3C6400_SERIAL_DRV_DATA (kernel_ulong_t)NULL
  1351. #endif
  1352. #ifdef CONFIG_CPU_S5PV210
  1353. static struct s3c24xx_serial_drv_data s5pv210_serial_drv_data = {
  1354. .info = &(struct s3c24xx_uart_info) {
  1355. .name = "Samsung S5PV210 UART",
  1356. .type = PORT_S3C6400,
  1357. .has_divslot = 1,
  1358. .rx_fifomask = S5PV210_UFSTAT_RXMASK,
  1359. .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT,
  1360. .rx_fifofull = S5PV210_UFSTAT_RXFULL,
  1361. .tx_fifofull = S5PV210_UFSTAT_TXFULL,
  1362. .tx_fifomask = S5PV210_UFSTAT_TXMASK,
  1363. .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT,
  1364. .def_clk_sel = S3C2410_UCON_CLKSEL0,
  1365. .num_clks = 2,
  1366. .clksel_mask = S5PV210_UCON_CLKMASK,
  1367. .clksel_shift = S5PV210_UCON_CLKSHIFT,
  1368. },
  1369. .def_cfg = &(struct s3c2410_uartcfg) {
  1370. .ucon = S5PV210_UCON_DEFAULT,
  1371. .ufcon = S5PV210_UFCON_DEFAULT,
  1372. },
  1373. .fifosize = { 256, 64, 16, 16 },
  1374. };
  1375. #define S5PV210_SERIAL_DRV_DATA ((kernel_ulong_t)&s5pv210_serial_drv_data)
  1376. #else
  1377. #define S5PV210_SERIAL_DRV_DATA (kernel_ulong_t)NULL
  1378. #endif
  1379. #if defined(CONFIG_CPU_EXYNOS4210) || defined(CONFIG_SOC_EXYNOS4212) || \
  1380. defined(CONFIG_SOC_EXYNOS4412) || defined(CONFIG_SOC_EXYNOS5250) || \
  1381. defined(CONFIG_SOC_EXYNOS5440)
  1382. static struct s3c24xx_serial_drv_data exynos4210_serial_drv_data = {
  1383. .info = &(struct s3c24xx_uart_info) {
  1384. .name = "Samsung Exynos4 UART",
  1385. .type = PORT_S3C6400,
  1386. .has_divslot = 1,
  1387. .rx_fifomask = S5PV210_UFSTAT_RXMASK,
  1388. .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT,
  1389. .rx_fifofull = S5PV210_UFSTAT_RXFULL,
  1390. .tx_fifofull = S5PV210_UFSTAT_TXFULL,
  1391. .tx_fifomask = S5PV210_UFSTAT_TXMASK,
  1392. .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT,
  1393. .def_clk_sel = S3C2410_UCON_CLKSEL0,
  1394. .num_clks = 1,
  1395. .clksel_mask = 0,
  1396. .clksel_shift = 0,
  1397. },
  1398. .def_cfg = &(struct s3c2410_uartcfg) {
  1399. .ucon = S5PV210_UCON_DEFAULT,
  1400. .ufcon = S5PV210_UFCON_DEFAULT,
  1401. .has_fracval = 1,
  1402. },
  1403. .fifosize = { 256, 64, 16, 16 },
  1404. };
  1405. #define EXYNOS4210_SERIAL_DRV_DATA ((kernel_ulong_t)&exynos4210_serial_drv_data)
  1406. #else
  1407. #define EXYNOS4210_SERIAL_DRV_DATA (kernel_ulong_t)NULL
  1408. #endif
  1409. static struct platform_device_id s3c24xx_serial_driver_ids[] = {
  1410. {
  1411. .name = "s3c2410-uart",
  1412. .driver_data = S3C2410_SERIAL_DRV_DATA,
  1413. }, {
  1414. .name = "s3c2412-uart",
  1415. .driver_data = S3C2412_SERIAL_DRV_DATA,
  1416. }, {
  1417. .name = "s3c2440-uart",
  1418. .driver_data = S3C2440_SERIAL_DRV_DATA,
  1419. }, {
  1420. .name = "s3c6400-uart",
  1421. .driver_data = S3C6400_SERIAL_DRV_DATA,
  1422. }, {
  1423. .name = "s5pv210-uart",
  1424. .driver_data = S5PV210_SERIAL_DRV_DATA,
  1425. }, {
  1426. .name = "exynos4210-uart",
  1427. .driver_data = EXYNOS4210_SERIAL_DRV_DATA,
  1428. },
  1429. { },
  1430. };
  1431. MODULE_DEVICE_TABLE(platform, s3c24xx_serial_driver_ids);
  1432. #ifdef CONFIG_OF
  1433. static const struct of_device_id s3c24xx_uart_dt_match[] = {
  1434. { .compatible = "samsung,s3c2410-uart",
  1435. .data = (void *)S3C2410_SERIAL_DRV_DATA },
  1436. { .compatible = "samsung,s3c2412-uart",
  1437. .data = (void *)S3C2412_SERIAL_DRV_DATA },
  1438. { .compatible = "samsung,s3c2440-uart",
  1439. .data = (void *)S3C2440_SERIAL_DRV_DATA },
  1440. { .compatible = "samsung,s3c6400-uart",
  1441. .data = (void *)S3C6400_SERIAL_DRV_DATA },
  1442. { .compatible = "samsung,s5pv210-uart",
  1443. .data = (void *)S5PV210_SERIAL_DRV_DATA },
  1444. { .compatible = "samsung,exynos4210-uart",
  1445. .data = (void *)EXYNOS4210_SERIAL_DRV_DATA },
  1446. {},
  1447. };
  1448. MODULE_DEVICE_TABLE(of, s3c24xx_uart_dt_match);
  1449. #endif
  1450. static struct platform_driver samsung_serial_driver = {
  1451. .probe = s3c24xx_serial_probe,
  1452. .remove = s3c24xx_serial_remove,
  1453. .id_table = s3c24xx_serial_driver_ids,
  1454. .driver = {
  1455. .name = "samsung-uart",
  1456. .owner = THIS_MODULE,
  1457. .pm = SERIAL_SAMSUNG_PM_OPS,
  1458. .of_match_table = of_match_ptr(s3c24xx_uart_dt_match),
  1459. },
  1460. };
  1461. /* module initialisation code */
  1462. static int __init s3c24xx_serial_modinit(void)
  1463. {
  1464. int ret;
  1465. ret = uart_register_driver(&s3c24xx_uart_drv);
  1466. if (ret < 0) {
  1467. pr_err("Failed to register Samsung UART driver\n");
  1468. return ret;
  1469. }
  1470. return platform_driver_register(&samsung_serial_driver);
  1471. }
  1472. static void __exit s3c24xx_serial_modexit(void)
  1473. {
  1474. uart_unregister_driver(&s3c24xx_uart_drv);
  1475. }
  1476. module_init(s3c24xx_serial_modinit);
  1477. module_exit(s3c24xx_serial_modexit);
  1478. MODULE_ALIAS("platform:samsung-uart");
  1479. MODULE_DESCRIPTION("Samsung SoC Serial port driver");
  1480. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  1481. MODULE_LICENSE("GPL v2");