samsung.c 46 KB

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