exynos_drm_gsc.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796
  1. /*
  2. * Copyright (C) 2012 Samsung Electronics Co.Ltd
  3. * Authors:
  4. * Eunchul Kim <chulspro.kim@samsung.com>
  5. * Jinyoung Jeon <jy0.jeon@samsung.com>
  6. * Sangmin Lee <lsmin.lee@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/clk.h>
  17. #include <linux/pm_runtime.h>
  18. #include <plat/map-base.h>
  19. #include <drm/drmP.h>
  20. #include <drm/exynos_drm.h>
  21. #include "regs-gsc.h"
  22. #include "exynos_drm_drv.h"
  23. #include "exynos_drm_ipp.h"
  24. #include "exynos_drm_gsc.h"
  25. /*
  26. * GSC stands for General SCaler and
  27. * supports image scaler/rotator and input/output DMA operations.
  28. * input DMA reads image data from the memory.
  29. * output DMA writes image data to memory.
  30. * GSC supports image rotation and image effect functions.
  31. *
  32. * M2M operation : supports crop/scale/rotation/csc so on.
  33. * Memory ----> GSC H/W ----> Memory.
  34. * Writeback operation : supports cloned screen with FIMD.
  35. * FIMD ----> GSC H/W ----> Memory.
  36. * Output operation : supports direct display using local path.
  37. * Memory ----> GSC H/W ----> FIMD, Mixer.
  38. */
  39. /*
  40. * TODO
  41. * 1. check suspend/resume api if needed.
  42. * 2. need to check use case platform_device_id.
  43. * 3. check src/dst size with, height.
  44. * 4. added check_prepare api for right register.
  45. * 5. need to add supported list in prop_list.
  46. * 6. check prescaler/scaler optimization.
  47. */
  48. #define GSC_MAX_DEVS 4
  49. #define GSC_MAX_SRC 4
  50. #define GSC_MAX_DST 16
  51. #define GSC_RESET_TIMEOUT 50
  52. #define GSC_BUF_STOP 1
  53. #define GSC_BUF_START 2
  54. #define GSC_REG_SZ 16
  55. #define GSC_WIDTH_ITU_709 1280
  56. #define GSC_SC_UP_MAX_RATIO 65536
  57. #define GSC_SC_DOWN_RATIO_7_8 74898
  58. #define GSC_SC_DOWN_RATIO_6_8 87381
  59. #define GSC_SC_DOWN_RATIO_5_8 104857
  60. #define GSC_SC_DOWN_RATIO_4_8 131072
  61. #define GSC_SC_DOWN_RATIO_3_8 174762
  62. #define GSC_SC_DOWN_RATIO_2_8 262144
  63. #define GSC_REFRESH_MIN 12
  64. #define GSC_REFRESH_MAX 60
  65. #define GSC_CROP_MAX 8192
  66. #define GSC_CROP_MIN 32
  67. #define GSC_SCALE_MAX 4224
  68. #define GSC_SCALE_MIN 32
  69. #define GSC_COEF_RATIO 7
  70. #define GSC_COEF_PHASE 9
  71. #define GSC_COEF_ATTR 16
  72. #define GSC_COEF_H_8T 8
  73. #define GSC_COEF_V_4T 4
  74. #define GSC_COEF_DEPTH 3
  75. #define get_gsc_context(dev) platform_get_drvdata(to_platform_device(dev))
  76. #define get_ctx_from_ippdrv(ippdrv) container_of(ippdrv,\
  77. struct gsc_context, ippdrv);
  78. #define gsc_read(offset) readl(ctx->regs + (offset))
  79. #define gsc_write(cfg, offset) writel(cfg, ctx->regs + (offset))
  80. /*
  81. * A structure of scaler.
  82. *
  83. * @range: narrow, wide.
  84. * @pre_shfactor: pre sclaer shift factor.
  85. * @pre_hratio: horizontal ratio of the prescaler.
  86. * @pre_vratio: vertical ratio of the prescaler.
  87. * @main_hratio: the main scaler's horizontal ratio.
  88. * @main_vratio: the main scaler's vertical ratio.
  89. */
  90. struct gsc_scaler {
  91. bool range;
  92. u32 pre_shfactor;
  93. u32 pre_hratio;
  94. u32 pre_vratio;
  95. unsigned long main_hratio;
  96. unsigned long main_vratio;
  97. };
  98. /*
  99. * A structure of scaler capability.
  100. *
  101. * find user manual 49.2 features.
  102. * @tile_w: tile mode or rotation width.
  103. * @tile_h: tile mode or rotation height.
  104. * @w: other cases width.
  105. * @h: other cases height.
  106. */
  107. struct gsc_capability {
  108. /* tile or rotation */
  109. u32 tile_w;
  110. u32 tile_h;
  111. /* other cases */
  112. u32 w;
  113. u32 h;
  114. };
  115. /*
  116. * A structure of gsc context.
  117. *
  118. * @ippdrv: prepare initialization using ippdrv.
  119. * @regs_res: register resources.
  120. * @regs: memory mapped io registers.
  121. * @lock: locking of operations.
  122. * @gsc_clk: gsc gate clock.
  123. * @sc: scaler infomations.
  124. * @id: gsc id.
  125. * @irq: irq number.
  126. * @rotation: supports rotation of src.
  127. * @suspended: qos operations.
  128. */
  129. struct gsc_context {
  130. struct exynos_drm_ippdrv ippdrv;
  131. struct resource *regs_res;
  132. void __iomem *regs;
  133. struct mutex lock;
  134. struct clk *gsc_clk;
  135. struct gsc_scaler sc;
  136. int id;
  137. int irq;
  138. bool rotation;
  139. bool suspended;
  140. };
  141. /* 8-tap Filter Coefficient */
  142. static const int h_coef_8t[GSC_COEF_RATIO][GSC_COEF_ATTR][GSC_COEF_H_8T] = {
  143. { /* Ratio <= 65536 (~8:8) */
  144. { 0, 0, 0, 128, 0, 0, 0, 0 },
  145. { -1, 2, -6, 127, 7, -2, 1, 0 },
  146. { -1, 4, -12, 125, 16, -5, 1, 0 },
  147. { -1, 5, -15, 120, 25, -8, 2, 0 },
  148. { -1, 6, -18, 114, 35, -10, 3, -1 },
  149. { -1, 6, -20, 107, 46, -13, 4, -1 },
  150. { -2, 7, -21, 99, 57, -16, 5, -1 },
  151. { -1, 6, -20, 89, 68, -18, 5, -1 },
  152. { -1, 6, -20, 79, 79, -20, 6, -1 },
  153. { -1, 5, -18, 68, 89, -20, 6, -1 },
  154. { -1, 5, -16, 57, 99, -21, 7, -2 },
  155. { -1, 4, -13, 46, 107, -20, 6, -1 },
  156. { -1, 3, -10, 35, 114, -18, 6, -1 },
  157. { 0, 2, -8, 25, 120, -15, 5, -1 },
  158. { 0, 1, -5, 16, 125, -12, 4, -1 },
  159. { 0, 1, -2, 7, 127, -6, 2, -1 }
  160. }, { /* 65536 < Ratio <= 74898 (~8:7) */
  161. { 3, -8, 14, 111, 13, -8, 3, 0 },
  162. { 2, -6, 7, 112, 21, -10, 3, -1 },
  163. { 2, -4, 1, 110, 28, -12, 4, -1 },
  164. { 1, -2, -3, 106, 36, -13, 4, -1 },
  165. { 1, -1, -7, 103, 44, -15, 4, -1 },
  166. { 1, 1, -11, 97, 53, -16, 4, -1 },
  167. { 0, 2, -13, 91, 61, -16, 4, -1 },
  168. { 0, 3, -15, 85, 69, -17, 4, -1 },
  169. { 0, 3, -16, 77, 77, -16, 3, 0 },
  170. { -1, 4, -17, 69, 85, -15, 3, 0 },
  171. { -1, 4, -16, 61, 91, -13, 2, 0 },
  172. { -1, 4, -16, 53, 97, -11, 1, 1 },
  173. { -1, 4, -15, 44, 103, -7, -1, 1 },
  174. { -1, 4, -13, 36, 106, -3, -2, 1 },
  175. { -1, 4, -12, 28, 110, 1, -4, 2 },
  176. { -1, 3, -10, 21, 112, 7, -6, 2 }
  177. }, { /* 74898 < Ratio <= 87381 (~8:6) */
  178. { 2, -11, 25, 96, 25, -11, 2, 0 },
  179. { 2, -10, 19, 96, 31, -12, 2, 0 },
  180. { 2, -9, 14, 94, 37, -12, 2, 0 },
  181. { 2, -8, 10, 92, 43, -12, 1, 0 },
  182. { 2, -7, 5, 90, 49, -12, 1, 0 },
  183. { 2, -5, 1, 86, 55, -12, 0, 1 },
  184. { 2, -4, -2, 82, 61, -11, -1, 1 },
  185. { 1, -3, -5, 77, 67, -9, -1, 1 },
  186. { 1, -2, -7, 72, 72, -7, -2, 1 },
  187. { 1, -1, -9, 67, 77, -5, -3, 1 },
  188. { 1, -1, -11, 61, 82, -2, -4, 2 },
  189. { 1, 0, -12, 55, 86, 1, -5, 2 },
  190. { 0, 1, -12, 49, 90, 5, -7, 2 },
  191. { 0, 1, -12, 43, 92, 10, -8, 2 },
  192. { 0, 2, -12, 37, 94, 14, -9, 2 },
  193. { 0, 2, -12, 31, 96, 19, -10, 2 }
  194. }, { /* 87381 < Ratio <= 104857 (~8:5) */
  195. { -1, -8, 33, 80, 33, -8, -1, 0 },
  196. { -1, -8, 28, 80, 37, -7, -2, 1 },
  197. { 0, -8, 24, 79, 41, -7, -2, 1 },
  198. { 0, -8, 20, 78, 46, -6, -3, 1 },
  199. { 0, -8, 16, 76, 50, -4, -3, 1 },
  200. { 0, -7, 13, 74, 54, -3, -4, 1 },
  201. { 1, -7, 10, 71, 58, -1, -5, 1 },
  202. { 1, -6, 6, 68, 62, 1, -5, 1 },
  203. { 1, -6, 4, 65, 65, 4, -6, 1 },
  204. { 1, -5, 1, 62, 68, 6, -6, 1 },
  205. { 1, -5, -1, 58, 71, 10, -7, 1 },
  206. { 1, -4, -3, 54, 74, 13, -7, 0 },
  207. { 1, -3, -4, 50, 76, 16, -8, 0 },
  208. { 1, -3, -6, 46, 78, 20, -8, 0 },
  209. { 1, -2, -7, 41, 79, 24, -8, 0 },
  210. { 1, -2, -7, 37, 80, 28, -8, -1 }
  211. }, { /* 104857 < Ratio <= 131072 (~8:4) */
  212. { -3, 0, 35, 64, 35, 0, -3, 0 },
  213. { -3, -1, 32, 64, 38, 1, -3, 0 },
  214. { -2, -2, 29, 63, 41, 2, -3, 0 },
  215. { -2, -3, 27, 63, 43, 4, -4, 0 },
  216. { -2, -3, 24, 61, 46, 6, -4, 0 },
  217. { -2, -3, 21, 60, 49, 7, -4, 0 },
  218. { -1, -4, 19, 59, 51, 9, -4, -1 },
  219. { -1, -4, 16, 57, 53, 12, -4, -1 },
  220. { -1, -4, 14, 55, 55, 14, -4, -1 },
  221. { -1, -4, 12, 53, 57, 16, -4, -1 },
  222. { -1, -4, 9, 51, 59, 19, -4, -1 },
  223. { 0, -4, 7, 49, 60, 21, -3, -2 },
  224. { 0, -4, 6, 46, 61, 24, -3, -2 },
  225. { 0, -4, 4, 43, 63, 27, -3, -2 },
  226. { 0, -3, 2, 41, 63, 29, -2, -2 },
  227. { 0, -3, 1, 38, 64, 32, -1, -3 }
  228. }, { /* 131072 < Ratio <= 174762 (~8:3) */
  229. { -1, 8, 33, 48, 33, 8, -1, 0 },
  230. { -1, 7, 31, 49, 35, 9, -1, -1 },
  231. { -1, 6, 30, 49, 36, 10, -1, -1 },
  232. { -1, 5, 28, 48, 38, 12, -1, -1 },
  233. { -1, 4, 26, 48, 39, 13, 0, -1 },
  234. { -1, 3, 24, 47, 41, 15, 0, -1 },
  235. { -1, 2, 23, 47, 42, 16, 0, -1 },
  236. { -1, 2, 21, 45, 43, 18, 1, -1 },
  237. { -1, 1, 19, 45, 45, 19, 1, -1 },
  238. { -1, 1, 18, 43, 45, 21, 2, -1 },
  239. { -1, 0, 16, 42, 47, 23, 2, -1 },
  240. { -1, 0, 15, 41, 47, 24, 3, -1 },
  241. { -1, 0, 13, 39, 48, 26, 4, -1 },
  242. { -1, -1, 12, 38, 48, 28, 5, -1 },
  243. { -1, -1, 10, 36, 49, 30, 6, -1 },
  244. { -1, -1, 9, 35, 49, 31, 7, -1 }
  245. }, { /* 174762 < Ratio <= 262144 (~8:2) */
  246. { 2, 13, 30, 38, 30, 13, 2, 0 },
  247. { 2, 12, 29, 38, 30, 14, 3, 0 },
  248. { 2, 11, 28, 38, 31, 15, 3, 0 },
  249. { 2, 10, 26, 38, 32, 16, 4, 0 },
  250. { 1, 10, 26, 37, 33, 17, 4, 0 },
  251. { 1, 9, 24, 37, 34, 18, 5, 0 },
  252. { 1, 8, 24, 37, 34, 19, 5, 0 },
  253. { 1, 7, 22, 36, 35, 20, 6, 1 },
  254. { 1, 6, 21, 36, 36, 21, 6, 1 },
  255. { 1, 6, 20, 35, 36, 22, 7, 1 },
  256. { 0, 5, 19, 34, 37, 24, 8, 1 },
  257. { 0, 5, 18, 34, 37, 24, 9, 1 },
  258. { 0, 4, 17, 33, 37, 26, 10, 1 },
  259. { 0, 4, 16, 32, 38, 26, 10, 2 },
  260. { 0, 3, 15, 31, 38, 28, 11, 2 },
  261. { 0, 3, 14, 30, 38, 29, 12, 2 }
  262. }
  263. };
  264. /* 4-tap Filter Coefficient */
  265. static const int v_coef_4t[GSC_COEF_RATIO][GSC_COEF_ATTR][GSC_COEF_V_4T] = {
  266. { /* Ratio <= 65536 (~8:8) */
  267. { 0, 128, 0, 0 },
  268. { -4, 127, 5, 0 },
  269. { -6, 124, 11, -1 },
  270. { -8, 118, 19, -1 },
  271. { -8, 111, 27, -2 },
  272. { -8, 102, 37, -3 },
  273. { -8, 92, 48, -4 },
  274. { -7, 81, 59, -5 },
  275. { -6, 70, 70, -6 },
  276. { -5, 59, 81, -7 },
  277. { -4, 48, 92, -8 },
  278. { -3, 37, 102, -8 },
  279. { -2, 27, 111, -8 },
  280. { -1, 19, 118, -8 },
  281. { -1, 11, 124, -6 },
  282. { 0, 5, 127, -4 }
  283. }, { /* 65536 < Ratio <= 74898 (~8:7) */
  284. { 8, 112, 8, 0 },
  285. { 4, 111, 14, -1 },
  286. { 1, 109, 20, -2 },
  287. { -2, 105, 27, -2 },
  288. { -3, 100, 34, -3 },
  289. { -5, 93, 43, -3 },
  290. { -5, 86, 51, -4 },
  291. { -5, 77, 60, -4 },
  292. { -5, 69, 69, -5 },
  293. { -4, 60, 77, -5 },
  294. { -4, 51, 86, -5 },
  295. { -3, 43, 93, -5 },
  296. { -3, 34, 100, -3 },
  297. { -2, 27, 105, -2 },
  298. { -2, 20, 109, 1 },
  299. { -1, 14, 111, 4 }
  300. }, { /* 74898 < Ratio <= 87381 (~8:6) */
  301. { 16, 96, 16, 0 },
  302. { 12, 97, 21, -2 },
  303. { 8, 96, 26, -2 },
  304. { 5, 93, 32, -2 },
  305. { 2, 89, 39, -2 },
  306. { 0, 84, 46, -2 },
  307. { -1, 79, 53, -3 },
  308. { -2, 73, 59, -2 },
  309. { -2, 66, 66, -2 },
  310. { -2, 59, 73, -2 },
  311. { -3, 53, 79, -1 },
  312. { -2, 46, 84, 0 },
  313. { -2, 39, 89, 2 },
  314. { -2, 32, 93, 5 },
  315. { -2, 26, 96, 8 },
  316. { -2, 21, 97, 12 }
  317. }, { /* 87381 < Ratio <= 104857 (~8:5) */
  318. { 22, 84, 22, 0 },
  319. { 18, 85, 26, -1 },
  320. { 14, 84, 31, -1 },
  321. { 11, 82, 36, -1 },
  322. { 8, 79, 42, -1 },
  323. { 6, 76, 47, -1 },
  324. { 4, 72, 52, 0 },
  325. { 2, 68, 58, 0 },
  326. { 1, 63, 63, 1 },
  327. { 0, 58, 68, 2 },
  328. { 0, 52, 72, 4 },
  329. { -1, 47, 76, 6 },
  330. { -1, 42, 79, 8 },
  331. { -1, 36, 82, 11 },
  332. { -1, 31, 84, 14 },
  333. { -1, 26, 85, 18 }
  334. }, { /* 104857 < Ratio <= 131072 (~8:4) */
  335. { 26, 76, 26, 0 },
  336. { 22, 76, 30, 0 },
  337. { 19, 75, 34, 0 },
  338. { 16, 73, 38, 1 },
  339. { 13, 71, 43, 1 },
  340. { 10, 69, 47, 2 },
  341. { 8, 66, 51, 3 },
  342. { 6, 63, 55, 4 },
  343. { 5, 59, 59, 5 },
  344. { 4, 55, 63, 6 },
  345. { 3, 51, 66, 8 },
  346. { 2, 47, 69, 10 },
  347. { 1, 43, 71, 13 },
  348. { 1, 38, 73, 16 },
  349. { 0, 34, 75, 19 },
  350. { 0, 30, 76, 22 }
  351. }, { /* 131072 < Ratio <= 174762 (~8:3) */
  352. { 29, 70, 29, 0 },
  353. { 26, 68, 32, 2 },
  354. { 23, 67, 36, 2 },
  355. { 20, 66, 39, 3 },
  356. { 17, 65, 43, 3 },
  357. { 15, 63, 46, 4 },
  358. { 12, 61, 50, 5 },
  359. { 10, 58, 53, 7 },
  360. { 8, 56, 56, 8 },
  361. { 7, 53, 58, 10 },
  362. { 5, 50, 61, 12 },
  363. { 4, 46, 63, 15 },
  364. { 3, 43, 65, 17 },
  365. { 3, 39, 66, 20 },
  366. { 2, 36, 67, 23 },
  367. { 2, 32, 68, 26 }
  368. }, { /* 174762 < Ratio <= 262144 (~8:2) */
  369. { 32, 64, 32, 0 },
  370. { 28, 63, 34, 3 },
  371. { 25, 62, 37, 4 },
  372. { 22, 62, 40, 4 },
  373. { 19, 61, 43, 5 },
  374. { 17, 59, 46, 6 },
  375. { 15, 58, 48, 7 },
  376. { 13, 55, 51, 9 },
  377. { 11, 53, 53, 11 },
  378. { 9, 51, 55, 13 },
  379. { 7, 48, 58, 15 },
  380. { 6, 46, 59, 17 },
  381. { 5, 43, 61, 19 },
  382. { 4, 40, 62, 22 },
  383. { 4, 37, 62, 25 },
  384. { 3, 34, 63, 28 }
  385. }
  386. };
  387. static int gsc_sw_reset(struct gsc_context *ctx)
  388. {
  389. u32 cfg;
  390. int count = GSC_RESET_TIMEOUT;
  391. /* s/w reset */
  392. cfg = (GSC_SW_RESET_SRESET);
  393. gsc_write(cfg, GSC_SW_RESET);
  394. /* wait s/w reset complete */
  395. while (count--) {
  396. cfg = gsc_read(GSC_SW_RESET);
  397. if (!cfg)
  398. break;
  399. usleep_range(1000, 2000);
  400. }
  401. if (cfg) {
  402. DRM_ERROR("failed to reset gsc h/w.\n");
  403. return -EBUSY;
  404. }
  405. /* reset sequence */
  406. cfg = gsc_read(GSC_IN_BASE_ADDR_Y_MASK);
  407. cfg |= (GSC_IN_BASE_ADDR_MASK |
  408. GSC_IN_BASE_ADDR_PINGPONG(0));
  409. gsc_write(cfg, GSC_IN_BASE_ADDR_Y_MASK);
  410. gsc_write(cfg, GSC_IN_BASE_ADDR_CB_MASK);
  411. gsc_write(cfg, GSC_IN_BASE_ADDR_CR_MASK);
  412. cfg = gsc_read(GSC_OUT_BASE_ADDR_Y_MASK);
  413. cfg |= (GSC_OUT_BASE_ADDR_MASK |
  414. GSC_OUT_BASE_ADDR_PINGPONG(0));
  415. gsc_write(cfg, GSC_OUT_BASE_ADDR_Y_MASK);
  416. gsc_write(cfg, GSC_OUT_BASE_ADDR_CB_MASK);
  417. gsc_write(cfg, GSC_OUT_BASE_ADDR_CR_MASK);
  418. return 0;
  419. }
  420. static void gsc_set_gscblk_fimd_wb(struct gsc_context *ctx, bool enable)
  421. {
  422. u32 gscblk_cfg;
  423. gscblk_cfg = readl(SYSREG_GSCBLK_CFG1);
  424. if (enable)
  425. gscblk_cfg |= GSC_BLK_DISP1WB_DEST(ctx->id) |
  426. GSC_BLK_GSCL_WB_IN_SRC_SEL(ctx->id) |
  427. GSC_BLK_SW_RESET_WB_DEST(ctx->id);
  428. else
  429. gscblk_cfg |= GSC_BLK_PXLASYNC_LO_MASK_WB(ctx->id);
  430. writel(gscblk_cfg, SYSREG_GSCBLK_CFG1);
  431. }
  432. static void gsc_handle_irq(struct gsc_context *ctx, bool enable,
  433. bool overflow, bool done)
  434. {
  435. u32 cfg;
  436. DRM_DEBUG_KMS("enable[%d]overflow[%d]level[%d]\n",
  437. enable, overflow, done);
  438. cfg = gsc_read(GSC_IRQ);
  439. cfg |= (GSC_IRQ_OR_MASK | GSC_IRQ_FRMDONE_MASK);
  440. if (enable)
  441. cfg |= GSC_IRQ_ENABLE;
  442. else
  443. cfg &= ~GSC_IRQ_ENABLE;
  444. if (overflow)
  445. cfg &= ~GSC_IRQ_OR_MASK;
  446. else
  447. cfg |= GSC_IRQ_OR_MASK;
  448. if (done)
  449. cfg &= ~GSC_IRQ_FRMDONE_MASK;
  450. else
  451. cfg |= GSC_IRQ_FRMDONE_MASK;
  452. gsc_write(cfg, GSC_IRQ);
  453. }
  454. static int gsc_src_set_fmt(struct device *dev, u32 fmt)
  455. {
  456. struct gsc_context *ctx = get_gsc_context(dev);
  457. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  458. u32 cfg;
  459. DRM_DEBUG_KMS("fmt[0x%x]\n", fmt);
  460. cfg = gsc_read(GSC_IN_CON);
  461. cfg &= ~(GSC_IN_RGB_TYPE_MASK | GSC_IN_YUV422_1P_ORDER_MASK |
  462. GSC_IN_CHROMA_ORDER_MASK | GSC_IN_FORMAT_MASK |
  463. GSC_IN_TILE_TYPE_MASK | GSC_IN_TILE_MODE |
  464. GSC_IN_CHROM_STRIDE_SEL_MASK | GSC_IN_RB_SWAP_MASK);
  465. switch (fmt) {
  466. case DRM_FORMAT_RGB565:
  467. cfg |= GSC_IN_RGB565;
  468. break;
  469. case DRM_FORMAT_XRGB8888:
  470. cfg |= GSC_IN_XRGB8888;
  471. break;
  472. case DRM_FORMAT_BGRX8888:
  473. cfg |= (GSC_IN_XRGB8888 | GSC_IN_RB_SWAP);
  474. break;
  475. case DRM_FORMAT_YUYV:
  476. cfg |= (GSC_IN_YUV422_1P |
  477. GSC_IN_YUV422_1P_ORDER_LSB_Y |
  478. GSC_IN_CHROMA_ORDER_CBCR);
  479. break;
  480. case DRM_FORMAT_YVYU:
  481. cfg |= (GSC_IN_YUV422_1P |
  482. GSC_IN_YUV422_1P_ORDER_LSB_Y |
  483. GSC_IN_CHROMA_ORDER_CRCB);
  484. break;
  485. case DRM_FORMAT_UYVY:
  486. cfg |= (GSC_IN_YUV422_1P |
  487. GSC_IN_YUV422_1P_OEDER_LSB_C |
  488. GSC_IN_CHROMA_ORDER_CBCR);
  489. break;
  490. case DRM_FORMAT_VYUY:
  491. cfg |= (GSC_IN_YUV422_1P |
  492. GSC_IN_YUV422_1P_OEDER_LSB_C |
  493. GSC_IN_CHROMA_ORDER_CRCB);
  494. break;
  495. case DRM_FORMAT_NV21:
  496. case DRM_FORMAT_NV61:
  497. cfg |= (GSC_IN_CHROMA_ORDER_CRCB |
  498. GSC_IN_YUV420_2P);
  499. break;
  500. case DRM_FORMAT_YUV422:
  501. cfg |= GSC_IN_YUV422_3P;
  502. break;
  503. case DRM_FORMAT_YUV420:
  504. case DRM_FORMAT_YVU420:
  505. cfg |= GSC_IN_YUV420_3P;
  506. break;
  507. case DRM_FORMAT_NV12:
  508. case DRM_FORMAT_NV16:
  509. cfg |= (GSC_IN_CHROMA_ORDER_CBCR |
  510. GSC_IN_YUV420_2P);
  511. break;
  512. default:
  513. dev_err(ippdrv->dev, "inavlid target yuv order 0x%x.\n", fmt);
  514. return -EINVAL;
  515. }
  516. gsc_write(cfg, GSC_IN_CON);
  517. return 0;
  518. }
  519. static int gsc_src_set_transf(struct device *dev,
  520. enum drm_exynos_degree degree,
  521. enum drm_exynos_flip flip, bool *swap)
  522. {
  523. struct gsc_context *ctx = get_gsc_context(dev);
  524. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  525. u32 cfg;
  526. DRM_DEBUG_KMS("degree[%d]flip[0x%x]\n", degree, flip);
  527. cfg = gsc_read(GSC_IN_CON);
  528. cfg &= ~GSC_IN_ROT_MASK;
  529. switch (degree) {
  530. case EXYNOS_DRM_DEGREE_0:
  531. if (flip & EXYNOS_DRM_FLIP_VERTICAL)
  532. cfg |= GSC_IN_ROT_XFLIP;
  533. if (flip & EXYNOS_DRM_FLIP_HORIZONTAL)
  534. cfg |= GSC_IN_ROT_YFLIP;
  535. break;
  536. case EXYNOS_DRM_DEGREE_90:
  537. if (flip & EXYNOS_DRM_FLIP_VERTICAL)
  538. cfg |= GSC_IN_ROT_90_XFLIP;
  539. else if (flip & EXYNOS_DRM_FLIP_HORIZONTAL)
  540. cfg |= GSC_IN_ROT_90_YFLIP;
  541. else
  542. cfg |= GSC_IN_ROT_90;
  543. break;
  544. case EXYNOS_DRM_DEGREE_180:
  545. cfg |= GSC_IN_ROT_180;
  546. break;
  547. case EXYNOS_DRM_DEGREE_270:
  548. cfg |= GSC_IN_ROT_270;
  549. break;
  550. default:
  551. dev_err(ippdrv->dev, "inavlid degree value %d.\n", degree);
  552. return -EINVAL;
  553. }
  554. gsc_write(cfg, GSC_IN_CON);
  555. ctx->rotation = cfg &
  556. (GSC_IN_ROT_90 | GSC_IN_ROT_270) ? 1 : 0;
  557. *swap = ctx->rotation;
  558. return 0;
  559. }
  560. static int gsc_src_set_size(struct device *dev, int swap,
  561. struct drm_exynos_pos *pos, struct drm_exynos_sz *sz)
  562. {
  563. struct gsc_context *ctx = get_gsc_context(dev);
  564. struct drm_exynos_pos img_pos = *pos;
  565. struct gsc_scaler *sc = &ctx->sc;
  566. u32 cfg;
  567. DRM_DEBUG_KMS("swap[%d]x[%d]y[%d]w[%d]h[%d]\n",
  568. swap, pos->x, pos->y, pos->w, pos->h);
  569. if (swap) {
  570. img_pos.w = pos->h;
  571. img_pos.h = pos->w;
  572. }
  573. /* pixel offset */
  574. cfg = (GSC_SRCIMG_OFFSET_X(img_pos.x) |
  575. GSC_SRCIMG_OFFSET_Y(img_pos.y));
  576. gsc_write(cfg, GSC_SRCIMG_OFFSET);
  577. /* cropped size */
  578. cfg = (GSC_CROPPED_WIDTH(img_pos.w) |
  579. GSC_CROPPED_HEIGHT(img_pos.h));
  580. gsc_write(cfg, GSC_CROPPED_SIZE);
  581. DRM_DEBUG_KMS("hsize[%d]vsize[%d]\n", sz->hsize, sz->vsize);
  582. /* original size */
  583. cfg = gsc_read(GSC_SRCIMG_SIZE);
  584. cfg &= ~(GSC_SRCIMG_HEIGHT_MASK |
  585. GSC_SRCIMG_WIDTH_MASK);
  586. cfg |= (GSC_SRCIMG_WIDTH(sz->hsize) |
  587. GSC_SRCIMG_HEIGHT(sz->vsize));
  588. gsc_write(cfg, GSC_SRCIMG_SIZE);
  589. cfg = gsc_read(GSC_IN_CON);
  590. cfg &= ~GSC_IN_RGB_TYPE_MASK;
  591. DRM_DEBUG_KMS("width[%d]range[%d]\n", pos->w, sc->range);
  592. if (pos->w >= GSC_WIDTH_ITU_709)
  593. if (sc->range)
  594. cfg |= GSC_IN_RGB_HD_WIDE;
  595. else
  596. cfg |= GSC_IN_RGB_HD_NARROW;
  597. else
  598. if (sc->range)
  599. cfg |= GSC_IN_RGB_SD_WIDE;
  600. else
  601. cfg |= GSC_IN_RGB_SD_NARROW;
  602. gsc_write(cfg, GSC_IN_CON);
  603. return 0;
  604. }
  605. static int gsc_src_set_buf_seq(struct gsc_context *ctx, u32 buf_id,
  606. enum drm_exynos_ipp_buf_type buf_type)
  607. {
  608. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  609. bool masked;
  610. u32 cfg;
  611. u32 mask = 0x00000001 << buf_id;
  612. DRM_DEBUG_KMS("buf_id[%d]buf_type[%d]\n", buf_id, buf_type);
  613. /* mask register set */
  614. cfg = gsc_read(GSC_IN_BASE_ADDR_Y_MASK);
  615. switch (buf_type) {
  616. case IPP_BUF_ENQUEUE:
  617. masked = false;
  618. break;
  619. case IPP_BUF_DEQUEUE:
  620. masked = true;
  621. break;
  622. default:
  623. dev_err(ippdrv->dev, "invalid buf ctrl parameter.\n");
  624. return -EINVAL;
  625. }
  626. /* sequence id */
  627. cfg &= ~mask;
  628. cfg |= masked << buf_id;
  629. gsc_write(cfg, GSC_IN_BASE_ADDR_Y_MASK);
  630. gsc_write(cfg, GSC_IN_BASE_ADDR_CB_MASK);
  631. gsc_write(cfg, GSC_IN_BASE_ADDR_CR_MASK);
  632. return 0;
  633. }
  634. static int gsc_src_set_addr(struct device *dev,
  635. struct drm_exynos_ipp_buf_info *buf_info, u32 buf_id,
  636. enum drm_exynos_ipp_buf_type buf_type)
  637. {
  638. struct gsc_context *ctx = get_gsc_context(dev);
  639. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  640. struct drm_exynos_ipp_cmd_node *c_node = ippdrv->c_node;
  641. struct drm_exynos_ipp_property *property;
  642. if (!c_node) {
  643. DRM_ERROR("failed to get c_node.\n");
  644. return -EFAULT;
  645. }
  646. property = &c_node->property;
  647. DRM_DEBUG_KMS("prop_id[%d]buf_id[%d]buf_type[%d]\n",
  648. property->prop_id, buf_id, buf_type);
  649. if (buf_id > GSC_MAX_SRC) {
  650. dev_info(ippdrv->dev, "inavlid buf_id %d.\n", buf_id);
  651. return -EINVAL;
  652. }
  653. /* address register set */
  654. switch (buf_type) {
  655. case IPP_BUF_ENQUEUE:
  656. gsc_write(buf_info->base[EXYNOS_DRM_PLANAR_Y],
  657. GSC_IN_BASE_ADDR_Y(buf_id));
  658. gsc_write(buf_info->base[EXYNOS_DRM_PLANAR_CB],
  659. GSC_IN_BASE_ADDR_CB(buf_id));
  660. gsc_write(buf_info->base[EXYNOS_DRM_PLANAR_CR],
  661. GSC_IN_BASE_ADDR_CR(buf_id));
  662. break;
  663. case IPP_BUF_DEQUEUE:
  664. gsc_write(0x0, GSC_IN_BASE_ADDR_Y(buf_id));
  665. gsc_write(0x0, GSC_IN_BASE_ADDR_CB(buf_id));
  666. gsc_write(0x0, GSC_IN_BASE_ADDR_CR(buf_id));
  667. break;
  668. default:
  669. /* bypass */
  670. break;
  671. }
  672. return gsc_src_set_buf_seq(ctx, buf_id, buf_type);
  673. }
  674. static struct exynos_drm_ipp_ops gsc_src_ops = {
  675. .set_fmt = gsc_src_set_fmt,
  676. .set_transf = gsc_src_set_transf,
  677. .set_size = gsc_src_set_size,
  678. .set_addr = gsc_src_set_addr,
  679. };
  680. static int gsc_dst_set_fmt(struct device *dev, u32 fmt)
  681. {
  682. struct gsc_context *ctx = get_gsc_context(dev);
  683. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  684. u32 cfg;
  685. DRM_DEBUG_KMS("fmt[0x%x]\n", fmt);
  686. cfg = gsc_read(GSC_OUT_CON);
  687. cfg &= ~(GSC_OUT_RGB_TYPE_MASK | GSC_OUT_YUV422_1P_ORDER_MASK |
  688. GSC_OUT_CHROMA_ORDER_MASK | GSC_OUT_FORMAT_MASK |
  689. GSC_OUT_CHROM_STRIDE_SEL_MASK | GSC_OUT_RB_SWAP_MASK |
  690. GSC_OUT_GLOBAL_ALPHA_MASK);
  691. switch (fmt) {
  692. case DRM_FORMAT_RGB565:
  693. cfg |= GSC_OUT_RGB565;
  694. break;
  695. case DRM_FORMAT_XRGB8888:
  696. cfg |= GSC_OUT_XRGB8888;
  697. break;
  698. case DRM_FORMAT_BGRX8888:
  699. cfg |= (GSC_OUT_XRGB8888 | GSC_OUT_RB_SWAP);
  700. break;
  701. case DRM_FORMAT_YUYV:
  702. cfg |= (GSC_OUT_YUV422_1P |
  703. GSC_OUT_YUV422_1P_ORDER_LSB_Y |
  704. GSC_OUT_CHROMA_ORDER_CBCR);
  705. break;
  706. case DRM_FORMAT_YVYU:
  707. cfg |= (GSC_OUT_YUV422_1P |
  708. GSC_OUT_YUV422_1P_ORDER_LSB_Y |
  709. GSC_OUT_CHROMA_ORDER_CRCB);
  710. break;
  711. case DRM_FORMAT_UYVY:
  712. cfg |= (GSC_OUT_YUV422_1P |
  713. GSC_OUT_YUV422_1P_OEDER_LSB_C |
  714. GSC_OUT_CHROMA_ORDER_CBCR);
  715. break;
  716. case DRM_FORMAT_VYUY:
  717. cfg |= (GSC_OUT_YUV422_1P |
  718. GSC_OUT_YUV422_1P_OEDER_LSB_C |
  719. GSC_OUT_CHROMA_ORDER_CRCB);
  720. break;
  721. case DRM_FORMAT_NV21:
  722. case DRM_FORMAT_NV61:
  723. cfg |= (GSC_OUT_CHROMA_ORDER_CRCB | GSC_OUT_YUV420_2P);
  724. break;
  725. case DRM_FORMAT_YUV422:
  726. case DRM_FORMAT_YUV420:
  727. case DRM_FORMAT_YVU420:
  728. cfg |= GSC_OUT_YUV420_3P;
  729. break;
  730. case DRM_FORMAT_NV12:
  731. case DRM_FORMAT_NV16:
  732. cfg |= (GSC_OUT_CHROMA_ORDER_CBCR |
  733. GSC_OUT_YUV420_2P);
  734. break;
  735. default:
  736. dev_err(ippdrv->dev, "inavlid target yuv order 0x%x.\n", fmt);
  737. return -EINVAL;
  738. }
  739. gsc_write(cfg, GSC_OUT_CON);
  740. return 0;
  741. }
  742. static int gsc_dst_set_transf(struct device *dev,
  743. enum drm_exynos_degree degree,
  744. enum drm_exynos_flip flip, bool *swap)
  745. {
  746. struct gsc_context *ctx = get_gsc_context(dev);
  747. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  748. u32 cfg;
  749. DRM_DEBUG_KMS("degree[%d]flip[0x%x]\n", degree, flip);
  750. cfg = gsc_read(GSC_IN_CON);
  751. cfg &= ~GSC_IN_ROT_MASK;
  752. switch (degree) {
  753. case EXYNOS_DRM_DEGREE_0:
  754. if (flip & EXYNOS_DRM_FLIP_VERTICAL)
  755. cfg |= GSC_IN_ROT_XFLIP;
  756. if (flip & EXYNOS_DRM_FLIP_HORIZONTAL)
  757. cfg |= GSC_IN_ROT_YFLIP;
  758. break;
  759. case EXYNOS_DRM_DEGREE_90:
  760. if (flip & EXYNOS_DRM_FLIP_VERTICAL)
  761. cfg |= GSC_IN_ROT_90_XFLIP;
  762. else if (flip & EXYNOS_DRM_FLIP_HORIZONTAL)
  763. cfg |= GSC_IN_ROT_90_YFLIP;
  764. else
  765. cfg |= GSC_IN_ROT_90;
  766. break;
  767. case EXYNOS_DRM_DEGREE_180:
  768. cfg |= GSC_IN_ROT_180;
  769. break;
  770. case EXYNOS_DRM_DEGREE_270:
  771. cfg |= GSC_IN_ROT_270;
  772. break;
  773. default:
  774. dev_err(ippdrv->dev, "inavlid degree value %d.\n", degree);
  775. return -EINVAL;
  776. }
  777. gsc_write(cfg, GSC_IN_CON);
  778. ctx->rotation = cfg &
  779. (GSC_IN_ROT_90 | GSC_IN_ROT_270) ? 1 : 0;
  780. *swap = ctx->rotation;
  781. return 0;
  782. }
  783. static int gsc_get_ratio_shift(u32 src, u32 dst, u32 *ratio)
  784. {
  785. DRM_DEBUG_KMS("src[%d]dst[%d]\n", src, dst);
  786. if (src >= dst * 8) {
  787. DRM_ERROR("failed to make ratio and shift.\n");
  788. return -EINVAL;
  789. } else if (src >= dst * 4)
  790. *ratio = 4;
  791. else if (src >= dst * 2)
  792. *ratio = 2;
  793. else
  794. *ratio = 1;
  795. return 0;
  796. }
  797. static void gsc_get_prescaler_shfactor(u32 hratio, u32 vratio, u32 *shfactor)
  798. {
  799. if (hratio == 4 && vratio == 4)
  800. *shfactor = 4;
  801. else if ((hratio == 4 && vratio == 2) ||
  802. (hratio == 2 && vratio == 4))
  803. *shfactor = 3;
  804. else if ((hratio == 4 && vratio == 1) ||
  805. (hratio == 1 && vratio == 4) ||
  806. (hratio == 2 && vratio == 2))
  807. *shfactor = 2;
  808. else if (hratio == 1 && vratio == 1)
  809. *shfactor = 0;
  810. else
  811. *shfactor = 1;
  812. }
  813. static int gsc_set_prescaler(struct gsc_context *ctx, struct gsc_scaler *sc,
  814. struct drm_exynos_pos *src, struct drm_exynos_pos *dst)
  815. {
  816. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  817. u32 cfg;
  818. u32 src_w, src_h, dst_w, dst_h;
  819. int ret = 0;
  820. src_w = src->w;
  821. src_h = src->h;
  822. if (ctx->rotation) {
  823. dst_w = dst->h;
  824. dst_h = dst->w;
  825. } else {
  826. dst_w = dst->w;
  827. dst_h = dst->h;
  828. }
  829. ret = gsc_get_ratio_shift(src_w, dst_w, &sc->pre_hratio);
  830. if (ret) {
  831. dev_err(ippdrv->dev, "failed to get ratio horizontal.\n");
  832. return ret;
  833. }
  834. ret = gsc_get_ratio_shift(src_h, dst_h, &sc->pre_vratio);
  835. if (ret) {
  836. dev_err(ippdrv->dev, "failed to get ratio vertical.\n");
  837. return ret;
  838. }
  839. DRM_DEBUG_KMS("pre_hratio[%d]pre_vratio[%d]\n",
  840. sc->pre_hratio, sc->pre_vratio);
  841. sc->main_hratio = (src_w << 16) / dst_w;
  842. sc->main_vratio = (src_h << 16) / dst_h;
  843. DRM_DEBUG_KMS("main_hratio[%ld]main_vratio[%ld]\n",
  844. sc->main_hratio, sc->main_vratio);
  845. gsc_get_prescaler_shfactor(sc->pre_hratio, sc->pre_vratio,
  846. &sc->pre_shfactor);
  847. DRM_DEBUG_KMS("pre_shfactor[%d]\n", sc->pre_shfactor);
  848. cfg = (GSC_PRESC_SHFACTOR(sc->pre_shfactor) |
  849. GSC_PRESC_H_RATIO(sc->pre_hratio) |
  850. GSC_PRESC_V_RATIO(sc->pre_vratio));
  851. gsc_write(cfg, GSC_PRE_SCALE_RATIO);
  852. return ret;
  853. }
  854. static void gsc_set_h_coef(struct gsc_context *ctx, unsigned long main_hratio)
  855. {
  856. int i, j, k, sc_ratio;
  857. if (main_hratio <= GSC_SC_UP_MAX_RATIO)
  858. sc_ratio = 0;
  859. else if (main_hratio <= GSC_SC_DOWN_RATIO_7_8)
  860. sc_ratio = 1;
  861. else if (main_hratio <= GSC_SC_DOWN_RATIO_6_8)
  862. sc_ratio = 2;
  863. else if (main_hratio <= GSC_SC_DOWN_RATIO_5_8)
  864. sc_ratio = 3;
  865. else if (main_hratio <= GSC_SC_DOWN_RATIO_4_8)
  866. sc_ratio = 4;
  867. else if (main_hratio <= GSC_SC_DOWN_RATIO_3_8)
  868. sc_ratio = 5;
  869. else
  870. sc_ratio = 6;
  871. for (i = 0; i < GSC_COEF_PHASE; i++)
  872. for (j = 0; j < GSC_COEF_H_8T; j++)
  873. for (k = 0; k < GSC_COEF_DEPTH; k++)
  874. gsc_write(h_coef_8t[sc_ratio][i][j],
  875. GSC_HCOEF(i, j, k));
  876. }
  877. static void gsc_set_v_coef(struct gsc_context *ctx, unsigned long main_vratio)
  878. {
  879. int i, j, k, sc_ratio;
  880. if (main_vratio <= GSC_SC_UP_MAX_RATIO)
  881. sc_ratio = 0;
  882. else if (main_vratio <= GSC_SC_DOWN_RATIO_7_8)
  883. sc_ratio = 1;
  884. else if (main_vratio <= GSC_SC_DOWN_RATIO_6_8)
  885. sc_ratio = 2;
  886. else if (main_vratio <= GSC_SC_DOWN_RATIO_5_8)
  887. sc_ratio = 3;
  888. else if (main_vratio <= GSC_SC_DOWN_RATIO_4_8)
  889. sc_ratio = 4;
  890. else if (main_vratio <= GSC_SC_DOWN_RATIO_3_8)
  891. sc_ratio = 5;
  892. else
  893. sc_ratio = 6;
  894. for (i = 0; i < GSC_COEF_PHASE; i++)
  895. for (j = 0; j < GSC_COEF_V_4T; j++)
  896. for (k = 0; k < GSC_COEF_DEPTH; k++)
  897. gsc_write(v_coef_4t[sc_ratio][i][j],
  898. GSC_VCOEF(i, j, k));
  899. }
  900. static void gsc_set_scaler(struct gsc_context *ctx, struct gsc_scaler *sc)
  901. {
  902. u32 cfg;
  903. DRM_DEBUG_KMS("main_hratio[%ld]main_vratio[%ld]\n",
  904. sc->main_hratio, sc->main_vratio);
  905. gsc_set_h_coef(ctx, sc->main_hratio);
  906. cfg = GSC_MAIN_H_RATIO_VALUE(sc->main_hratio);
  907. gsc_write(cfg, GSC_MAIN_H_RATIO);
  908. gsc_set_v_coef(ctx, sc->main_vratio);
  909. cfg = GSC_MAIN_V_RATIO_VALUE(sc->main_vratio);
  910. gsc_write(cfg, GSC_MAIN_V_RATIO);
  911. }
  912. static int gsc_dst_set_size(struct device *dev, int swap,
  913. struct drm_exynos_pos *pos, struct drm_exynos_sz *sz)
  914. {
  915. struct gsc_context *ctx = get_gsc_context(dev);
  916. struct drm_exynos_pos img_pos = *pos;
  917. struct gsc_scaler *sc = &ctx->sc;
  918. u32 cfg;
  919. DRM_DEBUG_KMS("swap[%d]x[%d]y[%d]w[%d]h[%d]\n",
  920. swap, pos->x, pos->y, pos->w, pos->h);
  921. if (swap) {
  922. img_pos.w = pos->h;
  923. img_pos.h = pos->w;
  924. }
  925. /* pixel offset */
  926. cfg = (GSC_DSTIMG_OFFSET_X(pos->x) |
  927. GSC_DSTIMG_OFFSET_Y(pos->y));
  928. gsc_write(cfg, GSC_DSTIMG_OFFSET);
  929. /* scaled size */
  930. cfg = (GSC_SCALED_WIDTH(img_pos.w) | GSC_SCALED_HEIGHT(img_pos.h));
  931. gsc_write(cfg, GSC_SCALED_SIZE);
  932. DRM_DEBUG_KMS("hsize[%d]vsize[%d]\n", sz->hsize, sz->vsize);
  933. /* original size */
  934. cfg = gsc_read(GSC_DSTIMG_SIZE);
  935. cfg &= ~(GSC_DSTIMG_HEIGHT_MASK |
  936. GSC_DSTIMG_WIDTH_MASK);
  937. cfg |= (GSC_DSTIMG_WIDTH(sz->hsize) |
  938. GSC_DSTIMG_HEIGHT(sz->vsize));
  939. gsc_write(cfg, GSC_DSTIMG_SIZE);
  940. cfg = gsc_read(GSC_OUT_CON);
  941. cfg &= ~GSC_OUT_RGB_TYPE_MASK;
  942. DRM_DEBUG_KMS("width[%d]range[%d]\n", pos->w, sc->range);
  943. if (pos->w >= GSC_WIDTH_ITU_709)
  944. if (sc->range)
  945. cfg |= GSC_OUT_RGB_HD_WIDE;
  946. else
  947. cfg |= GSC_OUT_RGB_HD_NARROW;
  948. else
  949. if (sc->range)
  950. cfg |= GSC_OUT_RGB_SD_WIDE;
  951. else
  952. cfg |= GSC_OUT_RGB_SD_NARROW;
  953. gsc_write(cfg, GSC_OUT_CON);
  954. return 0;
  955. }
  956. static int gsc_dst_get_buf_seq(struct gsc_context *ctx)
  957. {
  958. u32 cfg, i, buf_num = GSC_REG_SZ;
  959. u32 mask = 0x00000001;
  960. cfg = gsc_read(GSC_OUT_BASE_ADDR_Y_MASK);
  961. for (i = 0; i < GSC_REG_SZ; i++)
  962. if (cfg & (mask << i))
  963. buf_num--;
  964. DRM_DEBUG_KMS("buf_num[%d]\n", buf_num);
  965. return buf_num;
  966. }
  967. static int gsc_dst_set_buf_seq(struct gsc_context *ctx, u32 buf_id,
  968. enum drm_exynos_ipp_buf_type buf_type)
  969. {
  970. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  971. bool masked;
  972. u32 cfg;
  973. u32 mask = 0x00000001 << buf_id;
  974. int ret = 0;
  975. DRM_DEBUG_KMS("buf_id[%d]buf_type[%d]\n", buf_id, buf_type);
  976. mutex_lock(&ctx->lock);
  977. /* mask register set */
  978. cfg = gsc_read(GSC_OUT_BASE_ADDR_Y_MASK);
  979. switch (buf_type) {
  980. case IPP_BUF_ENQUEUE:
  981. masked = false;
  982. break;
  983. case IPP_BUF_DEQUEUE:
  984. masked = true;
  985. break;
  986. default:
  987. dev_err(ippdrv->dev, "invalid buf ctrl parameter.\n");
  988. ret = -EINVAL;
  989. goto err_unlock;
  990. }
  991. /* sequence id */
  992. cfg &= ~mask;
  993. cfg |= masked << buf_id;
  994. gsc_write(cfg, GSC_OUT_BASE_ADDR_Y_MASK);
  995. gsc_write(cfg, GSC_OUT_BASE_ADDR_CB_MASK);
  996. gsc_write(cfg, GSC_OUT_BASE_ADDR_CR_MASK);
  997. /* interrupt enable */
  998. if (buf_type == IPP_BUF_ENQUEUE &&
  999. gsc_dst_get_buf_seq(ctx) >= GSC_BUF_START)
  1000. gsc_handle_irq(ctx, true, false, true);
  1001. /* interrupt disable */
  1002. if (buf_type == IPP_BUF_DEQUEUE &&
  1003. gsc_dst_get_buf_seq(ctx) <= GSC_BUF_STOP)
  1004. gsc_handle_irq(ctx, false, false, true);
  1005. err_unlock:
  1006. mutex_unlock(&ctx->lock);
  1007. return ret;
  1008. }
  1009. static int gsc_dst_set_addr(struct device *dev,
  1010. struct drm_exynos_ipp_buf_info *buf_info, u32 buf_id,
  1011. enum drm_exynos_ipp_buf_type buf_type)
  1012. {
  1013. struct gsc_context *ctx = get_gsc_context(dev);
  1014. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  1015. struct drm_exynos_ipp_cmd_node *c_node = ippdrv->c_node;
  1016. struct drm_exynos_ipp_property *property;
  1017. if (!c_node) {
  1018. DRM_ERROR("failed to get c_node.\n");
  1019. return -EFAULT;
  1020. }
  1021. property = &c_node->property;
  1022. DRM_DEBUG_KMS("prop_id[%d]buf_id[%d]buf_type[%d]\n",
  1023. property->prop_id, buf_id, buf_type);
  1024. if (buf_id > GSC_MAX_DST) {
  1025. dev_info(ippdrv->dev, "inavlid buf_id %d.\n", buf_id);
  1026. return -EINVAL;
  1027. }
  1028. /* address register set */
  1029. switch (buf_type) {
  1030. case IPP_BUF_ENQUEUE:
  1031. gsc_write(buf_info->base[EXYNOS_DRM_PLANAR_Y],
  1032. GSC_OUT_BASE_ADDR_Y(buf_id));
  1033. gsc_write(buf_info->base[EXYNOS_DRM_PLANAR_CB],
  1034. GSC_OUT_BASE_ADDR_CB(buf_id));
  1035. gsc_write(buf_info->base[EXYNOS_DRM_PLANAR_CR],
  1036. GSC_OUT_BASE_ADDR_CR(buf_id));
  1037. break;
  1038. case IPP_BUF_DEQUEUE:
  1039. gsc_write(0x0, GSC_OUT_BASE_ADDR_Y(buf_id));
  1040. gsc_write(0x0, GSC_OUT_BASE_ADDR_CB(buf_id));
  1041. gsc_write(0x0, GSC_OUT_BASE_ADDR_CR(buf_id));
  1042. break;
  1043. default:
  1044. /* bypass */
  1045. break;
  1046. }
  1047. return gsc_dst_set_buf_seq(ctx, buf_id, buf_type);
  1048. }
  1049. static struct exynos_drm_ipp_ops gsc_dst_ops = {
  1050. .set_fmt = gsc_dst_set_fmt,
  1051. .set_transf = gsc_dst_set_transf,
  1052. .set_size = gsc_dst_set_size,
  1053. .set_addr = gsc_dst_set_addr,
  1054. };
  1055. static int gsc_clk_ctrl(struct gsc_context *ctx, bool enable)
  1056. {
  1057. DRM_DEBUG_KMS("enable[%d]\n", enable);
  1058. if (enable) {
  1059. clk_enable(ctx->gsc_clk);
  1060. ctx->suspended = false;
  1061. } else {
  1062. clk_disable(ctx->gsc_clk);
  1063. ctx->suspended = true;
  1064. }
  1065. return 0;
  1066. }
  1067. static int gsc_get_src_buf_index(struct gsc_context *ctx)
  1068. {
  1069. u32 cfg, curr_index, i;
  1070. u32 buf_id = GSC_MAX_SRC;
  1071. int ret;
  1072. DRM_DEBUG_KMS("gsc id[%d]\n", ctx->id);
  1073. cfg = gsc_read(GSC_IN_BASE_ADDR_Y_MASK);
  1074. curr_index = GSC_IN_CURR_GET_INDEX(cfg);
  1075. for (i = curr_index; i < GSC_MAX_SRC; i++) {
  1076. if (!((cfg >> i) & 0x1)) {
  1077. buf_id = i;
  1078. break;
  1079. }
  1080. }
  1081. if (buf_id == GSC_MAX_SRC) {
  1082. DRM_ERROR("failed to get in buffer index.\n");
  1083. return -EINVAL;
  1084. }
  1085. ret = gsc_src_set_buf_seq(ctx, buf_id, IPP_BUF_DEQUEUE);
  1086. if (ret < 0) {
  1087. DRM_ERROR("failed to dequeue.\n");
  1088. return ret;
  1089. }
  1090. DRM_DEBUG_KMS("cfg[0x%x]curr_index[%d]buf_id[%d]\n", cfg,
  1091. curr_index, buf_id);
  1092. return buf_id;
  1093. }
  1094. static int gsc_get_dst_buf_index(struct gsc_context *ctx)
  1095. {
  1096. u32 cfg, curr_index, i;
  1097. u32 buf_id = GSC_MAX_DST;
  1098. int ret;
  1099. DRM_DEBUG_KMS("gsc id[%d]\n", ctx->id);
  1100. cfg = gsc_read(GSC_OUT_BASE_ADDR_Y_MASK);
  1101. curr_index = GSC_OUT_CURR_GET_INDEX(cfg);
  1102. for (i = curr_index; i < GSC_MAX_DST; i++) {
  1103. if (!((cfg >> i) & 0x1)) {
  1104. buf_id = i;
  1105. break;
  1106. }
  1107. }
  1108. if (buf_id == GSC_MAX_DST) {
  1109. DRM_ERROR("failed to get out buffer index.\n");
  1110. return -EINVAL;
  1111. }
  1112. ret = gsc_dst_set_buf_seq(ctx, buf_id, IPP_BUF_DEQUEUE);
  1113. if (ret < 0) {
  1114. DRM_ERROR("failed to dequeue.\n");
  1115. return ret;
  1116. }
  1117. DRM_DEBUG_KMS("cfg[0x%x]curr_index[%d]buf_id[%d]\n", cfg,
  1118. curr_index, buf_id);
  1119. return buf_id;
  1120. }
  1121. static irqreturn_t gsc_irq_handler(int irq, void *dev_id)
  1122. {
  1123. struct gsc_context *ctx = dev_id;
  1124. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  1125. struct drm_exynos_ipp_cmd_node *c_node = ippdrv->c_node;
  1126. struct drm_exynos_ipp_event_work *event_work =
  1127. c_node->event_work;
  1128. u32 status;
  1129. int buf_id[EXYNOS_DRM_OPS_MAX];
  1130. DRM_DEBUG_KMS("gsc id[%d]\n", ctx->id);
  1131. status = gsc_read(GSC_IRQ);
  1132. if (status & GSC_IRQ_STATUS_OR_IRQ) {
  1133. dev_err(ippdrv->dev, "occurred overflow at %d, status 0x%x.\n",
  1134. ctx->id, status);
  1135. return IRQ_NONE;
  1136. }
  1137. if (status & GSC_IRQ_STATUS_OR_FRM_DONE) {
  1138. dev_dbg(ippdrv->dev, "occurred frame done at %d, status 0x%x.\n",
  1139. ctx->id, status);
  1140. buf_id[EXYNOS_DRM_OPS_SRC] = gsc_get_src_buf_index(ctx);
  1141. if (buf_id[EXYNOS_DRM_OPS_SRC] < 0)
  1142. return IRQ_HANDLED;
  1143. buf_id[EXYNOS_DRM_OPS_DST] = gsc_get_dst_buf_index(ctx);
  1144. if (buf_id[EXYNOS_DRM_OPS_DST] < 0)
  1145. return IRQ_HANDLED;
  1146. DRM_DEBUG_KMS("buf_id_src[%d]buf_id_dst[%d]\n",
  1147. buf_id[EXYNOS_DRM_OPS_SRC], buf_id[EXYNOS_DRM_OPS_DST]);
  1148. event_work->ippdrv = ippdrv;
  1149. event_work->buf_id[EXYNOS_DRM_OPS_SRC] =
  1150. buf_id[EXYNOS_DRM_OPS_SRC];
  1151. event_work->buf_id[EXYNOS_DRM_OPS_DST] =
  1152. buf_id[EXYNOS_DRM_OPS_DST];
  1153. queue_work(ippdrv->event_workq, &event_work->work);
  1154. }
  1155. return IRQ_HANDLED;
  1156. }
  1157. static int gsc_init_prop_list(struct exynos_drm_ippdrv *ippdrv)
  1158. {
  1159. struct drm_exynos_ipp_prop_list *prop_list = &ippdrv->prop_list;
  1160. prop_list->version = 1;
  1161. prop_list->writeback = 1;
  1162. prop_list->refresh_min = GSC_REFRESH_MIN;
  1163. prop_list->refresh_max = GSC_REFRESH_MAX;
  1164. prop_list->flip = (1 << EXYNOS_DRM_FLIP_VERTICAL) |
  1165. (1 << EXYNOS_DRM_FLIP_HORIZONTAL);
  1166. prop_list->degree = (1 << EXYNOS_DRM_DEGREE_0) |
  1167. (1 << EXYNOS_DRM_DEGREE_90) |
  1168. (1 << EXYNOS_DRM_DEGREE_180) |
  1169. (1 << EXYNOS_DRM_DEGREE_270);
  1170. prop_list->csc = 1;
  1171. prop_list->crop = 1;
  1172. prop_list->crop_max.hsize = GSC_CROP_MAX;
  1173. prop_list->crop_max.vsize = GSC_CROP_MAX;
  1174. prop_list->crop_min.hsize = GSC_CROP_MIN;
  1175. prop_list->crop_min.vsize = GSC_CROP_MIN;
  1176. prop_list->scale = 1;
  1177. prop_list->scale_max.hsize = GSC_SCALE_MAX;
  1178. prop_list->scale_max.vsize = GSC_SCALE_MAX;
  1179. prop_list->scale_min.hsize = GSC_SCALE_MIN;
  1180. prop_list->scale_min.vsize = GSC_SCALE_MIN;
  1181. return 0;
  1182. }
  1183. static inline bool gsc_check_drm_flip(enum drm_exynos_flip flip)
  1184. {
  1185. switch (flip) {
  1186. case EXYNOS_DRM_FLIP_NONE:
  1187. case EXYNOS_DRM_FLIP_VERTICAL:
  1188. case EXYNOS_DRM_FLIP_HORIZONTAL:
  1189. case EXYNOS_DRM_FLIP_BOTH:
  1190. return true;
  1191. default:
  1192. DRM_DEBUG_KMS("invalid flip\n");
  1193. return false;
  1194. }
  1195. }
  1196. static int gsc_ippdrv_check_property(struct device *dev,
  1197. struct drm_exynos_ipp_property *property)
  1198. {
  1199. struct gsc_context *ctx = get_gsc_context(dev);
  1200. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  1201. struct drm_exynos_ipp_prop_list *pp = &ippdrv->prop_list;
  1202. struct drm_exynos_ipp_config *config;
  1203. struct drm_exynos_pos *pos;
  1204. struct drm_exynos_sz *sz;
  1205. bool swap;
  1206. int i;
  1207. for_each_ipp_ops(i) {
  1208. if ((i == EXYNOS_DRM_OPS_SRC) &&
  1209. (property->cmd == IPP_CMD_WB))
  1210. continue;
  1211. config = &property->config[i];
  1212. pos = &config->pos;
  1213. sz = &config->sz;
  1214. /* check for flip */
  1215. if (!gsc_check_drm_flip(config->flip)) {
  1216. DRM_ERROR("invalid flip.\n");
  1217. goto err_property;
  1218. }
  1219. /* check for degree */
  1220. switch (config->degree) {
  1221. case EXYNOS_DRM_DEGREE_90:
  1222. case EXYNOS_DRM_DEGREE_270:
  1223. swap = true;
  1224. break;
  1225. case EXYNOS_DRM_DEGREE_0:
  1226. case EXYNOS_DRM_DEGREE_180:
  1227. swap = false;
  1228. break;
  1229. default:
  1230. DRM_ERROR("invalid degree.\n");
  1231. goto err_property;
  1232. }
  1233. /* check for buffer bound */
  1234. if ((pos->x + pos->w > sz->hsize) ||
  1235. (pos->y + pos->h > sz->vsize)) {
  1236. DRM_ERROR("out of buf bound.\n");
  1237. goto err_property;
  1238. }
  1239. /* check for crop */
  1240. if ((i == EXYNOS_DRM_OPS_SRC) && (pp->crop)) {
  1241. if (swap) {
  1242. if ((pos->h < pp->crop_min.hsize) ||
  1243. (sz->vsize > pp->crop_max.hsize) ||
  1244. (pos->w < pp->crop_min.vsize) ||
  1245. (sz->hsize > pp->crop_max.vsize)) {
  1246. DRM_ERROR("out of crop size.\n");
  1247. goto err_property;
  1248. }
  1249. } else {
  1250. if ((pos->w < pp->crop_min.hsize) ||
  1251. (sz->hsize > pp->crop_max.hsize) ||
  1252. (pos->h < pp->crop_min.vsize) ||
  1253. (sz->vsize > pp->crop_max.vsize)) {
  1254. DRM_ERROR("out of crop size.\n");
  1255. goto err_property;
  1256. }
  1257. }
  1258. }
  1259. /* check for scale */
  1260. if ((i == EXYNOS_DRM_OPS_DST) && (pp->scale)) {
  1261. if (swap) {
  1262. if ((pos->h < pp->scale_min.hsize) ||
  1263. (sz->vsize > pp->scale_max.hsize) ||
  1264. (pos->w < pp->scale_min.vsize) ||
  1265. (sz->hsize > pp->scale_max.vsize)) {
  1266. DRM_ERROR("out of scale size.\n");
  1267. goto err_property;
  1268. }
  1269. } else {
  1270. if ((pos->w < pp->scale_min.hsize) ||
  1271. (sz->hsize > pp->scale_max.hsize) ||
  1272. (pos->h < pp->scale_min.vsize) ||
  1273. (sz->vsize > pp->scale_max.vsize)) {
  1274. DRM_ERROR("out of scale size.\n");
  1275. goto err_property;
  1276. }
  1277. }
  1278. }
  1279. }
  1280. return 0;
  1281. err_property:
  1282. for_each_ipp_ops(i) {
  1283. if ((i == EXYNOS_DRM_OPS_SRC) &&
  1284. (property->cmd == IPP_CMD_WB))
  1285. continue;
  1286. config = &property->config[i];
  1287. pos = &config->pos;
  1288. sz = &config->sz;
  1289. DRM_ERROR("[%s]f[%d]r[%d]pos[%d %d %d %d]sz[%d %d]\n",
  1290. i ? "dst" : "src", config->flip, config->degree,
  1291. pos->x, pos->y, pos->w, pos->h,
  1292. sz->hsize, sz->vsize);
  1293. }
  1294. return -EINVAL;
  1295. }
  1296. static int gsc_ippdrv_reset(struct device *dev)
  1297. {
  1298. struct gsc_context *ctx = get_gsc_context(dev);
  1299. struct gsc_scaler *sc = &ctx->sc;
  1300. int ret;
  1301. /* reset h/w block */
  1302. ret = gsc_sw_reset(ctx);
  1303. if (ret < 0) {
  1304. dev_err(dev, "failed to reset hardware.\n");
  1305. return ret;
  1306. }
  1307. /* scaler setting */
  1308. memset(&ctx->sc, 0x0, sizeof(ctx->sc));
  1309. sc->range = true;
  1310. return 0;
  1311. }
  1312. static int gsc_ippdrv_start(struct device *dev, enum drm_exynos_ipp_cmd cmd)
  1313. {
  1314. struct gsc_context *ctx = get_gsc_context(dev);
  1315. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  1316. struct drm_exynos_ipp_cmd_node *c_node = ippdrv->c_node;
  1317. struct drm_exynos_ipp_property *property;
  1318. struct drm_exynos_ipp_config *config;
  1319. struct drm_exynos_pos img_pos[EXYNOS_DRM_OPS_MAX];
  1320. struct drm_exynos_ipp_set_wb set_wb;
  1321. u32 cfg;
  1322. int ret, i;
  1323. DRM_DEBUG_KMS("cmd[%d]\n", cmd);
  1324. if (!c_node) {
  1325. DRM_ERROR("failed to get c_node.\n");
  1326. return -EINVAL;
  1327. }
  1328. property = &c_node->property;
  1329. gsc_handle_irq(ctx, true, false, true);
  1330. for_each_ipp_ops(i) {
  1331. config = &property->config[i];
  1332. img_pos[i] = config->pos;
  1333. }
  1334. switch (cmd) {
  1335. case IPP_CMD_M2M:
  1336. /* enable one shot */
  1337. cfg = gsc_read(GSC_ENABLE);
  1338. cfg &= ~(GSC_ENABLE_ON_CLEAR_MASK |
  1339. GSC_ENABLE_CLK_GATE_MODE_MASK);
  1340. cfg |= GSC_ENABLE_ON_CLEAR_ONESHOT;
  1341. gsc_write(cfg, GSC_ENABLE);
  1342. /* src dma memory */
  1343. cfg = gsc_read(GSC_IN_CON);
  1344. cfg &= ~(GSC_IN_PATH_MASK | GSC_IN_LOCAL_SEL_MASK);
  1345. cfg |= GSC_IN_PATH_MEMORY;
  1346. gsc_write(cfg, GSC_IN_CON);
  1347. /* dst dma memory */
  1348. cfg = gsc_read(GSC_OUT_CON);
  1349. cfg |= GSC_OUT_PATH_MEMORY;
  1350. gsc_write(cfg, GSC_OUT_CON);
  1351. break;
  1352. case IPP_CMD_WB:
  1353. set_wb.enable = 1;
  1354. set_wb.refresh = property->refresh_rate;
  1355. gsc_set_gscblk_fimd_wb(ctx, set_wb.enable);
  1356. exynos_drm_ippnb_send_event(IPP_SET_WRITEBACK, (void *)&set_wb);
  1357. /* src local path */
  1358. cfg = gsc_read(GSC_IN_CON);
  1359. cfg &= ~(GSC_IN_PATH_MASK | GSC_IN_LOCAL_SEL_MASK);
  1360. cfg |= (GSC_IN_PATH_LOCAL | GSC_IN_LOCAL_FIMD_WB);
  1361. gsc_write(cfg, GSC_IN_CON);
  1362. /* dst dma memory */
  1363. cfg = gsc_read(GSC_OUT_CON);
  1364. cfg |= GSC_OUT_PATH_MEMORY;
  1365. gsc_write(cfg, GSC_OUT_CON);
  1366. break;
  1367. case IPP_CMD_OUTPUT:
  1368. /* src dma memory */
  1369. cfg = gsc_read(GSC_IN_CON);
  1370. cfg &= ~(GSC_IN_PATH_MASK | GSC_IN_LOCAL_SEL_MASK);
  1371. cfg |= GSC_IN_PATH_MEMORY;
  1372. gsc_write(cfg, GSC_IN_CON);
  1373. /* dst local path */
  1374. cfg = gsc_read(GSC_OUT_CON);
  1375. cfg |= GSC_OUT_PATH_MEMORY;
  1376. gsc_write(cfg, GSC_OUT_CON);
  1377. break;
  1378. default:
  1379. ret = -EINVAL;
  1380. dev_err(dev, "invalid operations.\n");
  1381. return ret;
  1382. }
  1383. ret = gsc_set_prescaler(ctx, &ctx->sc,
  1384. &img_pos[EXYNOS_DRM_OPS_SRC],
  1385. &img_pos[EXYNOS_DRM_OPS_DST]);
  1386. if (ret) {
  1387. dev_err(dev, "failed to set precalser.\n");
  1388. return ret;
  1389. }
  1390. gsc_set_scaler(ctx, &ctx->sc);
  1391. cfg = gsc_read(GSC_ENABLE);
  1392. cfg |= GSC_ENABLE_ON;
  1393. gsc_write(cfg, GSC_ENABLE);
  1394. return 0;
  1395. }
  1396. static void gsc_ippdrv_stop(struct device *dev, enum drm_exynos_ipp_cmd cmd)
  1397. {
  1398. struct gsc_context *ctx = get_gsc_context(dev);
  1399. struct drm_exynos_ipp_set_wb set_wb = {0, 0};
  1400. u32 cfg;
  1401. DRM_DEBUG_KMS("cmd[%d]\n", cmd);
  1402. switch (cmd) {
  1403. case IPP_CMD_M2M:
  1404. /* bypass */
  1405. break;
  1406. case IPP_CMD_WB:
  1407. gsc_set_gscblk_fimd_wb(ctx, set_wb.enable);
  1408. exynos_drm_ippnb_send_event(IPP_SET_WRITEBACK, (void *)&set_wb);
  1409. break;
  1410. case IPP_CMD_OUTPUT:
  1411. default:
  1412. dev_err(dev, "invalid operations.\n");
  1413. break;
  1414. }
  1415. gsc_handle_irq(ctx, false, false, true);
  1416. /* reset sequence */
  1417. gsc_write(0xff, GSC_OUT_BASE_ADDR_Y_MASK);
  1418. gsc_write(0xff, GSC_OUT_BASE_ADDR_CB_MASK);
  1419. gsc_write(0xff, GSC_OUT_BASE_ADDR_CR_MASK);
  1420. cfg = gsc_read(GSC_ENABLE);
  1421. cfg &= ~GSC_ENABLE_ON;
  1422. gsc_write(cfg, GSC_ENABLE);
  1423. }
  1424. static int gsc_probe(struct platform_device *pdev)
  1425. {
  1426. struct device *dev = &pdev->dev;
  1427. struct gsc_context *ctx;
  1428. struct resource *res;
  1429. struct exynos_drm_ippdrv *ippdrv;
  1430. int ret;
  1431. ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  1432. if (!ctx)
  1433. return -ENOMEM;
  1434. /* clock control */
  1435. ctx->gsc_clk = devm_clk_get(dev, "gscl");
  1436. if (IS_ERR(ctx->gsc_clk)) {
  1437. dev_err(dev, "failed to get gsc clock.\n");
  1438. return PTR_ERR(ctx->gsc_clk);
  1439. }
  1440. /* resource memory */
  1441. ctx->regs_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1442. ctx->regs = devm_ioremap_resource(dev, ctx->regs_res);
  1443. if (IS_ERR(ctx->regs))
  1444. return PTR_ERR(ctx->regs);
  1445. /* resource irq */
  1446. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1447. if (!res) {
  1448. dev_err(dev, "failed to request irq resource.\n");
  1449. return -ENOENT;
  1450. }
  1451. ctx->irq = res->start;
  1452. ret = devm_request_threaded_irq(dev, ctx->irq, NULL, gsc_irq_handler,
  1453. IRQF_ONESHOT, "drm_gsc", ctx);
  1454. if (ret < 0) {
  1455. dev_err(dev, "failed to request irq.\n");
  1456. return ret;
  1457. }
  1458. /* context initailization */
  1459. ctx->id = pdev->id;
  1460. ippdrv = &ctx->ippdrv;
  1461. ippdrv->dev = dev;
  1462. ippdrv->ops[EXYNOS_DRM_OPS_SRC] = &gsc_src_ops;
  1463. ippdrv->ops[EXYNOS_DRM_OPS_DST] = &gsc_dst_ops;
  1464. ippdrv->check_property = gsc_ippdrv_check_property;
  1465. ippdrv->reset = gsc_ippdrv_reset;
  1466. ippdrv->start = gsc_ippdrv_start;
  1467. ippdrv->stop = gsc_ippdrv_stop;
  1468. ret = gsc_init_prop_list(ippdrv);
  1469. if (ret < 0) {
  1470. dev_err(dev, "failed to init property list.\n");
  1471. return ret;
  1472. }
  1473. DRM_DEBUG_KMS("id[%d]ippdrv[0x%x]\n", ctx->id, (int)ippdrv);
  1474. mutex_init(&ctx->lock);
  1475. platform_set_drvdata(pdev, ctx);
  1476. pm_runtime_set_active(dev);
  1477. pm_runtime_enable(dev);
  1478. ret = exynos_drm_ippdrv_register(ippdrv);
  1479. if (ret < 0) {
  1480. dev_err(dev, "failed to register drm gsc device.\n");
  1481. goto err_ippdrv_register;
  1482. }
  1483. dev_info(dev, "drm gsc registered successfully.\n");
  1484. return 0;
  1485. err_ippdrv_register:
  1486. pm_runtime_disable(dev);
  1487. return ret;
  1488. }
  1489. static int gsc_remove(struct platform_device *pdev)
  1490. {
  1491. struct device *dev = &pdev->dev;
  1492. struct gsc_context *ctx = get_gsc_context(dev);
  1493. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  1494. exynos_drm_ippdrv_unregister(ippdrv);
  1495. mutex_destroy(&ctx->lock);
  1496. pm_runtime_set_suspended(dev);
  1497. pm_runtime_disable(dev);
  1498. return 0;
  1499. }
  1500. #ifdef CONFIG_PM_SLEEP
  1501. static int gsc_suspend(struct device *dev)
  1502. {
  1503. struct gsc_context *ctx = get_gsc_context(dev);
  1504. DRM_DEBUG_KMS("id[%d]\n", ctx->id);
  1505. if (pm_runtime_suspended(dev))
  1506. return 0;
  1507. return gsc_clk_ctrl(ctx, false);
  1508. }
  1509. static int gsc_resume(struct device *dev)
  1510. {
  1511. struct gsc_context *ctx = get_gsc_context(dev);
  1512. DRM_DEBUG_KMS("id[%d]\n", ctx->id);
  1513. if (!pm_runtime_suspended(dev))
  1514. return gsc_clk_ctrl(ctx, true);
  1515. return 0;
  1516. }
  1517. #endif
  1518. #ifdef CONFIG_PM
  1519. static int gsc_runtime_suspend(struct device *dev)
  1520. {
  1521. struct gsc_context *ctx = get_gsc_context(dev);
  1522. DRM_DEBUG_KMS("id[%d]\n", ctx->id);
  1523. return gsc_clk_ctrl(ctx, false);
  1524. }
  1525. static int gsc_runtime_resume(struct device *dev)
  1526. {
  1527. struct gsc_context *ctx = get_gsc_context(dev);
  1528. DRM_DEBUG_KMS("id[%d]\n", ctx->id);
  1529. return gsc_clk_ctrl(ctx, true);
  1530. }
  1531. #endif
  1532. static const struct dev_pm_ops gsc_pm_ops = {
  1533. SET_SYSTEM_SLEEP_PM_OPS(gsc_suspend, gsc_resume)
  1534. SET_RUNTIME_PM_OPS(gsc_runtime_suspend, gsc_runtime_resume, NULL)
  1535. };
  1536. struct platform_driver gsc_driver = {
  1537. .probe = gsc_probe,
  1538. .remove = gsc_remove,
  1539. .driver = {
  1540. .name = "exynos-drm-gsc",
  1541. .owner = THIS_MODULE,
  1542. .pm = &gsc_pm_ops,
  1543. },
  1544. };