samsung.c 46 KB

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