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