samsung.c 46 KB

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