samsung.c 45 KB

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