samsung.c 45 KB

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