samsung.c 45 KB

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