exynos_drm_gsc.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820
  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. cfg |= (GSC_IN_CHROMA_ORDER_CRCB | GSC_IN_YUV420_2P);
  497. break;
  498. case DRM_FORMAT_NV61:
  499. cfg |= (GSC_IN_CHROMA_ORDER_CRCB | GSC_IN_YUV422_2P);
  500. break;
  501. case DRM_FORMAT_YUV422:
  502. cfg |= GSC_IN_YUV422_3P;
  503. break;
  504. case DRM_FORMAT_YUV420:
  505. cfg |= (GSC_IN_CHROMA_ORDER_CBCR | GSC_IN_YUV420_3P);
  506. break;
  507. case DRM_FORMAT_YVU420:
  508. cfg |= (GSC_IN_CHROMA_ORDER_CRCB | GSC_IN_YUV420_3P);
  509. break;
  510. case DRM_FORMAT_NV12:
  511. cfg |= (GSC_IN_CHROMA_ORDER_CBCR | GSC_IN_YUV420_2P);
  512. break;
  513. case DRM_FORMAT_NV16:
  514. cfg |= (GSC_IN_CHROMA_ORDER_CBCR | GSC_IN_YUV422_2P);
  515. break;
  516. default:
  517. dev_err(ippdrv->dev, "invalid target yuv order 0x%x.\n", fmt);
  518. return -EINVAL;
  519. }
  520. gsc_write(cfg, GSC_IN_CON);
  521. return 0;
  522. }
  523. static int gsc_src_set_transf(struct device *dev,
  524. enum drm_exynos_degree degree,
  525. enum drm_exynos_flip flip, bool *swap)
  526. {
  527. struct gsc_context *ctx = get_gsc_context(dev);
  528. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  529. u32 cfg;
  530. DRM_DEBUG_KMS("degree[%d]flip[0x%x]\n", degree, flip);
  531. cfg = gsc_read(GSC_IN_CON);
  532. cfg &= ~GSC_IN_ROT_MASK;
  533. switch (degree) {
  534. case EXYNOS_DRM_DEGREE_0:
  535. if (flip & EXYNOS_DRM_FLIP_VERTICAL)
  536. cfg |= GSC_IN_ROT_XFLIP;
  537. if (flip & EXYNOS_DRM_FLIP_HORIZONTAL)
  538. cfg |= GSC_IN_ROT_YFLIP;
  539. break;
  540. case EXYNOS_DRM_DEGREE_90:
  541. if (flip & EXYNOS_DRM_FLIP_VERTICAL)
  542. cfg |= GSC_IN_ROT_90_XFLIP;
  543. else if (flip & EXYNOS_DRM_FLIP_HORIZONTAL)
  544. cfg |= GSC_IN_ROT_90_YFLIP;
  545. else
  546. cfg |= GSC_IN_ROT_90;
  547. break;
  548. case EXYNOS_DRM_DEGREE_180:
  549. cfg |= GSC_IN_ROT_180;
  550. if (flip & EXYNOS_DRM_FLIP_VERTICAL)
  551. cfg &= ~GSC_IN_ROT_XFLIP;
  552. if (flip & EXYNOS_DRM_FLIP_HORIZONTAL)
  553. cfg &= ~GSC_IN_ROT_YFLIP;
  554. break;
  555. case EXYNOS_DRM_DEGREE_270:
  556. cfg |= GSC_IN_ROT_270;
  557. if (flip & EXYNOS_DRM_FLIP_VERTICAL)
  558. cfg &= ~GSC_IN_ROT_XFLIP;
  559. if (flip & EXYNOS_DRM_FLIP_HORIZONTAL)
  560. cfg &= ~GSC_IN_ROT_YFLIP;
  561. break;
  562. default:
  563. dev_err(ippdrv->dev, "invalid degree value %d.\n", degree);
  564. return -EINVAL;
  565. }
  566. gsc_write(cfg, GSC_IN_CON);
  567. ctx->rotation = (cfg & GSC_IN_ROT_90) ? 1 : 0;
  568. *swap = ctx->rotation;
  569. return 0;
  570. }
  571. static int gsc_src_set_size(struct device *dev, int swap,
  572. struct drm_exynos_pos *pos, struct drm_exynos_sz *sz)
  573. {
  574. struct gsc_context *ctx = get_gsc_context(dev);
  575. struct drm_exynos_pos img_pos = *pos;
  576. struct gsc_scaler *sc = &ctx->sc;
  577. u32 cfg;
  578. DRM_DEBUG_KMS("swap[%d]x[%d]y[%d]w[%d]h[%d]\n",
  579. swap, pos->x, pos->y, pos->w, pos->h);
  580. if (swap) {
  581. img_pos.w = pos->h;
  582. img_pos.h = pos->w;
  583. }
  584. /* pixel offset */
  585. cfg = (GSC_SRCIMG_OFFSET_X(img_pos.x) |
  586. GSC_SRCIMG_OFFSET_Y(img_pos.y));
  587. gsc_write(cfg, GSC_SRCIMG_OFFSET);
  588. /* cropped size */
  589. cfg = (GSC_CROPPED_WIDTH(img_pos.w) |
  590. GSC_CROPPED_HEIGHT(img_pos.h));
  591. gsc_write(cfg, GSC_CROPPED_SIZE);
  592. DRM_DEBUG_KMS("hsize[%d]vsize[%d]\n", sz->hsize, sz->vsize);
  593. /* original size */
  594. cfg = gsc_read(GSC_SRCIMG_SIZE);
  595. cfg &= ~(GSC_SRCIMG_HEIGHT_MASK |
  596. GSC_SRCIMG_WIDTH_MASK);
  597. cfg |= (GSC_SRCIMG_WIDTH(sz->hsize) |
  598. GSC_SRCIMG_HEIGHT(sz->vsize));
  599. gsc_write(cfg, GSC_SRCIMG_SIZE);
  600. cfg = gsc_read(GSC_IN_CON);
  601. cfg &= ~GSC_IN_RGB_TYPE_MASK;
  602. DRM_DEBUG_KMS("width[%d]range[%d]\n", pos->w, sc->range);
  603. if (pos->w >= GSC_WIDTH_ITU_709)
  604. if (sc->range)
  605. cfg |= GSC_IN_RGB_HD_WIDE;
  606. else
  607. cfg |= GSC_IN_RGB_HD_NARROW;
  608. else
  609. if (sc->range)
  610. cfg |= GSC_IN_RGB_SD_WIDE;
  611. else
  612. cfg |= GSC_IN_RGB_SD_NARROW;
  613. gsc_write(cfg, GSC_IN_CON);
  614. return 0;
  615. }
  616. static int gsc_src_set_buf_seq(struct gsc_context *ctx, u32 buf_id,
  617. enum drm_exynos_ipp_buf_type buf_type)
  618. {
  619. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  620. bool masked;
  621. u32 cfg;
  622. u32 mask = 0x00000001 << buf_id;
  623. DRM_DEBUG_KMS("buf_id[%d]buf_type[%d]\n", buf_id, buf_type);
  624. /* mask register set */
  625. cfg = gsc_read(GSC_IN_BASE_ADDR_Y_MASK);
  626. switch (buf_type) {
  627. case IPP_BUF_ENQUEUE:
  628. masked = false;
  629. break;
  630. case IPP_BUF_DEQUEUE:
  631. masked = true;
  632. break;
  633. default:
  634. dev_err(ippdrv->dev, "invalid buf ctrl parameter.\n");
  635. return -EINVAL;
  636. }
  637. /* sequence id */
  638. cfg &= ~mask;
  639. cfg |= masked << buf_id;
  640. gsc_write(cfg, GSC_IN_BASE_ADDR_Y_MASK);
  641. gsc_write(cfg, GSC_IN_BASE_ADDR_CB_MASK);
  642. gsc_write(cfg, GSC_IN_BASE_ADDR_CR_MASK);
  643. return 0;
  644. }
  645. static int gsc_src_set_addr(struct device *dev,
  646. struct drm_exynos_ipp_buf_info *buf_info, u32 buf_id,
  647. enum drm_exynos_ipp_buf_type buf_type)
  648. {
  649. struct gsc_context *ctx = get_gsc_context(dev);
  650. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  651. struct drm_exynos_ipp_cmd_node *c_node = ippdrv->c_node;
  652. struct drm_exynos_ipp_property *property;
  653. if (!c_node) {
  654. DRM_ERROR("failed to get c_node.\n");
  655. return -EFAULT;
  656. }
  657. property = &c_node->property;
  658. DRM_DEBUG_KMS("prop_id[%d]buf_id[%d]buf_type[%d]\n",
  659. property->prop_id, buf_id, buf_type);
  660. if (buf_id > GSC_MAX_SRC) {
  661. dev_info(ippdrv->dev, "invalid buf_id %d.\n", buf_id);
  662. return -EINVAL;
  663. }
  664. /* address register set */
  665. switch (buf_type) {
  666. case IPP_BUF_ENQUEUE:
  667. gsc_write(buf_info->base[EXYNOS_DRM_PLANAR_Y],
  668. GSC_IN_BASE_ADDR_Y(buf_id));
  669. gsc_write(buf_info->base[EXYNOS_DRM_PLANAR_CB],
  670. GSC_IN_BASE_ADDR_CB(buf_id));
  671. gsc_write(buf_info->base[EXYNOS_DRM_PLANAR_CR],
  672. GSC_IN_BASE_ADDR_CR(buf_id));
  673. break;
  674. case IPP_BUF_DEQUEUE:
  675. gsc_write(0x0, GSC_IN_BASE_ADDR_Y(buf_id));
  676. gsc_write(0x0, GSC_IN_BASE_ADDR_CB(buf_id));
  677. gsc_write(0x0, GSC_IN_BASE_ADDR_CR(buf_id));
  678. break;
  679. default:
  680. /* bypass */
  681. break;
  682. }
  683. return gsc_src_set_buf_seq(ctx, buf_id, buf_type);
  684. }
  685. static struct exynos_drm_ipp_ops gsc_src_ops = {
  686. .set_fmt = gsc_src_set_fmt,
  687. .set_transf = gsc_src_set_transf,
  688. .set_size = gsc_src_set_size,
  689. .set_addr = gsc_src_set_addr,
  690. };
  691. static int gsc_dst_set_fmt(struct device *dev, u32 fmt)
  692. {
  693. struct gsc_context *ctx = get_gsc_context(dev);
  694. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  695. u32 cfg;
  696. DRM_DEBUG_KMS("fmt[0x%x]\n", fmt);
  697. cfg = gsc_read(GSC_OUT_CON);
  698. cfg &= ~(GSC_OUT_RGB_TYPE_MASK | GSC_OUT_YUV422_1P_ORDER_MASK |
  699. GSC_OUT_CHROMA_ORDER_MASK | GSC_OUT_FORMAT_MASK |
  700. GSC_OUT_CHROM_STRIDE_SEL_MASK | GSC_OUT_RB_SWAP_MASK |
  701. GSC_OUT_GLOBAL_ALPHA_MASK);
  702. switch (fmt) {
  703. case DRM_FORMAT_RGB565:
  704. cfg |= GSC_OUT_RGB565;
  705. break;
  706. case DRM_FORMAT_XRGB8888:
  707. cfg |= GSC_OUT_XRGB8888;
  708. break;
  709. case DRM_FORMAT_BGRX8888:
  710. cfg |= (GSC_OUT_XRGB8888 | GSC_OUT_RB_SWAP);
  711. break;
  712. case DRM_FORMAT_YUYV:
  713. cfg |= (GSC_OUT_YUV422_1P |
  714. GSC_OUT_YUV422_1P_ORDER_LSB_Y |
  715. GSC_OUT_CHROMA_ORDER_CBCR);
  716. break;
  717. case DRM_FORMAT_YVYU:
  718. cfg |= (GSC_OUT_YUV422_1P |
  719. GSC_OUT_YUV422_1P_ORDER_LSB_Y |
  720. GSC_OUT_CHROMA_ORDER_CRCB);
  721. break;
  722. case DRM_FORMAT_UYVY:
  723. cfg |= (GSC_OUT_YUV422_1P |
  724. GSC_OUT_YUV422_1P_OEDER_LSB_C |
  725. GSC_OUT_CHROMA_ORDER_CBCR);
  726. break;
  727. case DRM_FORMAT_VYUY:
  728. cfg |= (GSC_OUT_YUV422_1P |
  729. GSC_OUT_YUV422_1P_OEDER_LSB_C |
  730. GSC_OUT_CHROMA_ORDER_CRCB);
  731. break;
  732. case DRM_FORMAT_NV21:
  733. cfg |= (GSC_OUT_CHROMA_ORDER_CRCB | GSC_OUT_YUV420_2P);
  734. break;
  735. case DRM_FORMAT_NV61:
  736. cfg |= (GSC_OUT_CHROMA_ORDER_CRCB | GSC_OUT_YUV422_2P);
  737. break;
  738. case DRM_FORMAT_YUV422:
  739. cfg |= GSC_OUT_YUV422_3P;
  740. break;
  741. case DRM_FORMAT_YUV420:
  742. cfg |= (GSC_OUT_CHROMA_ORDER_CBCR | GSC_OUT_YUV420_3P);
  743. break;
  744. case DRM_FORMAT_YVU420:
  745. cfg |= (GSC_OUT_CHROMA_ORDER_CRCB | GSC_OUT_YUV420_3P);
  746. break;
  747. case DRM_FORMAT_NV12:
  748. cfg |= (GSC_OUT_CHROMA_ORDER_CBCR | GSC_OUT_YUV420_2P);
  749. break;
  750. case DRM_FORMAT_NV16:
  751. cfg |= (GSC_OUT_CHROMA_ORDER_CBCR | GSC_OUT_YUV422_2P);
  752. break;
  753. default:
  754. dev_err(ippdrv->dev, "invalid target yuv order 0x%x.\n", fmt);
  755. return -EINVAL;
  756. }
  757. gsc_write(cfg, GSC_OUT_CON);
  758. return 0;
  759. }
  760. static int gsc_dst_set_transf(struct device *dev,
  761. enum drm_exynos_degree degree,
  762. enum drm_exynos_flip flip, bool *swap)
  763. {
  764. struct gsc_context *ctx = get_gsc_context(dev);
  765. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  766. u32 cfg;
  767. DRM_DEBUG_KMS("degree[%d]flip[0x%x]\n", degree, flip);
  768. cfg = gsc_read(GSC_IN_CON);
  769. cfg &= ~GSC_IN_ROT_MASK;
  770. switch (degree) {
  771. case EXYNOS_DRM_DEGREE_0:
  772. if (flip & EXYNOS_DRM_FLIP_VERTICAL)
  773. cfg |= GSC_IN_ROT_XFLIP;
  774. if (flip & EXYNOS_DRM_FLIP_HORIZONTAL)
  775. cfg |= GSC_IN_ROT_YFLIP;
  776. break;
  777. case EXYNOS_DRM_DEGREE_90:
  778. if (flip & EXYNOS_DRM_FLIP_VERTICAL)
  779. cfg |= GSC_IN_ROT_90_XFLIP;
  780. else if (flip & EXYNOS_DRM_FLIP_HORIZONTAL)
  781. cfg |= GSC_IN_ROT_90_YFLIP;
  782. else
  783. cfg |= GSC_IN_ROT_90;
  784. break;
  785. case EXYNOS_DRM_DEGREE_180:
  786. cfg |= GSC_IN_ROT_180;
  787. if (flip & EXYNOS_DRM_FLIP_VERTICAL)
  788. cfg &= ~GSC_IN_ROT_XFLIP;
  789. if (flip & EXYNOS_DRM_FLIP_HORIZONTAL)
  790. cfg &= ~GSC_IN_ROT_YFLIP;
  791. break;
  792. case EXYNOS_DRM_DEGREE_270:
  793. cfg |= GSC_IN_ROT_270;
  794. if (flip & EXYNOS_DRM_FLIP_VERTICAL)
  795. cfg &= ~GSC_IN_ROT_XFLIP;
  796. if (flip & EXYNOS_DRM_FLIP_HORIZONTAL)
  797. cfg &= ~GSC_IN_ROT_YFLIP;
  798. break;
  799. default:
  800. dev_err(ippdrv->dev, "invalid degree value %d.\n", degree);
  801. return -EINVAL;
  802. }
  803. gsc_write(cfg, GSC_IN_CON);
  804. ctx->rotation = (cfg & GSC_IN_ROT_90) ? 1 : 0;
  805. *swap = ctx->rotation;
  806. return 0;
  807. }
  808. static int gsc_get_ratio_shift(u32 src, u32 dst, u32 *ratio)
  809. {
  810. DRM_DEBUG_KMS("src[%d]dst[%d]\n", src, dst);
  811. if (src >= dst * 8) {
  812. DRM_ERROR("failed to make ratio and shift.\n");
  813. return -EINVAL;
  814. } else if (src >= dst * 4)
  815. *ratio = 4;
  816. else if (src >= dst * 2)
  817. *ratio = 2;
  818. else
  819. *ratio = 1;
  820. return 0;
  821. }
  822. static void gsc_get_prescaler_shfactor(u32 hratio, u32 vratio, u32 *shfactor)
  823. {
  824. if (hratio == 4 && vratio == 4)
  825. *shfactor = 4;
  826. else if ((hratio == 4 && vratio == 2) ||
  827. (hratio == 2 && vratio == 4))
  828. *shfactor = 3;
  829. else if ((hratio == 4 && vratio == 1) ||
  830. (hratio == 1 && vratio == 4) ||
  831. (hratio == 2 && vratio == 2))
  832. *shfactor = 2;
  833. else if (hratio == 1 && vratio == 1)
  834. *shfactor = 0;
  835. else
  836. *shfactor = 1;
  837. }
  838. static int gsc_set_prescaler(struct gsc_context *ctx, struct gsc_scaler *sc,
  839. struct drm_exynos_pos *src, struct drm_exynos_pos *dst)
  840. {
  841. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  842. u32 cfg;
  843. u32 src_w, src_h, dst_w, dst_h;
  844. int ret = 0;
  845. src_w = src->w;
  846. src_h = src->h;
  847. if (ctx->rotation) {
  848. dst_w = dst->h;
  849. dst_h = dst->w;
  850. } else {
  851. dst_w = dst->w;
  852. dst_h = dst->h;
  853. }
  854. ret = gsc_get_ratio_shift(src_w, dst_w, &sc->pre_hratio);
  855. if (ret) {
  856. dev_err(ippdrv->dev, "failed to get ratio horizontal.\n");
  857. return ret;
  858. }
  859. ret = gsc_get_ratio_shift(src_h, dst_h, &sc->pre_vratio);
  860. if (ret) {
  861. dev_err(ippdrv->dev, "failed to get ratio vertical.\n");
  862. return ret;
  863. }
  864. DRM_DEBUG_KMS("pre_hratio[%d]pre_vratio[%d]\n",
  865. sc->pre_hratio, sc->pre_vratio);
  866. sc->main_hratio = (src_w << 16) / dst_w;
  867. sc->main_vratio = (src_h << 16) / dst_h;
  868. DRM_DEBUG_KMS("main_hratio[%ld]main_vratio[%ld]\n",
  869. sc->main_hratio, sc->main_vratio);
  870. gsc_get_prescaler_shfactor(sc->pre_hratio, sc->pre_vratio,
  871. &sc->pre_shfactor);
  872. DRM_DEBUG_KMS("pre_shfactor[%d]\n", sc->pre_shfactor);
  873. cfg = (GSC_PRESC_SHFACTOR(sc->pre_shfactor) |
  874. GSC_PRESC_H_RATIO(sc->pre_hratio) |
  875. GSC_PRESC_V_RATIO(sc->pre_vratio));
  876. gsc_write(cfg, GSC_PRE_SCALE_RATIO);
  877. return ret;
  878. }
  879. static void gsc_set_h_coef(struct gsc_context *ctx, unsigned long main_hratio)
  880. {
  881. int i, j, k, sc_ratio;
  882. if (main_hratio <= GSC_SC_UP_MAX_RATIO)
  883. sc_ratio = 0;
  884. else if (main_hratio <= GSC_SC_DOWN_RATIO_7_8)
  885. sc_ratio = 1;
  886. else if (main_hratio <= GSC_SC_DOWN_RATIO_6_8)
  887. sc_ratio = 2;
  888. else if (main_hratio <= GSC_SC_DOWN_RATIO_5_8)
  889. sc_ratio = 3;
  890. else if (main_hratio <= GSC_SC_DOWN_RATIO_4_8)
  891. sc_ratio = 4;
  892. else if (main_hratio <= GSC_SC_DOWN_RATIO_3_8)
  893. sc_ratio = 5;
  894. else
  895. sc_ratio = 6;
  896. for (i = 0; i < GSC_COEF_PHASE; i++)
  897. for (j = 0; j < GSC_COEF_H_8T; j++)
  898. for (k = 0; k < GSC_COEF_DEPTH; k++)
  899. gsc_write(h_coef_8t[sc_ratio][i][j],
  900. GSC_HCOEF(i, j, k));
  901. }
  902. static void gsc_set_v_coef(struct gsc_context *ctx, unsigned long main_vratio)
  903. {
  904. int i, j, k, sc_ratio;
  905. if (main_vratio <= GSC_SC_UP_MAX_RATIO)
  906. sc_ratio = 0;
  907. else if (main_vratio <= GSC_SC_DOWN_RATIO_7_8)
  908. sc_ratio = 1;
  909. else if (main_vratio <= GSC_SC_DOWN_RATIO_6_8)
  910. sc_ratio = 2;
  911. else if (main_vratio <= GSC_SC_DOWN_RATIO_5_8)
  912. sc_ratio = 3;
  913. else if (main_vratio <= GSC_SC_DOWN_RATIO_4_8)
  914. sc_ratio = 4;
  915. else if (main_vratio <= GSC_SC_DOWN_RATIO_3_8)
  916. sc_ratio = 5;
  917. else
  918. sc_ratio = 6;
  919. for (i = 0; i < GSC_COEF_PHASE; i++)
  920. for (j = 0; j < GSC_COEF_V_4T; j++)
  921. for (k = 0; k < GSC_COEF_DEPTH; k++)
  922. gsc_write(v_coef_4t[sc_ratio][i][j],
  923. GSC_VCOEF(i, j, k));
  924. }
  925. static void gsc_set_scaler(struct gsc_context *ctx, struct gsc_scaler *sc)
  926. {
  927. u32 cfg;
  928. DRM_DEBUG_KMS("main_hratio[%ld]main_vratio[%ld]\n",
  929. sc->main_hratio, sc->main_vratio);
  930. gsc_set_h_coef(ctx, sc->main_hratio);
  931. cfg = GSC_MAIN_H_RATIO_VALUE(sc->main_hratio);
  932. gsc_write(cfg, GSC_MAIN_H_RATIO);
  933. gsc_set_v_coef(ctx, sc->main_vratio);
  934. cfg = GSC_MAIN_V_RATIO_VALUE(sc->main_vratio);
  935. gsc_write(cfg, GSC_MAIN_V_RATIO);
  936. }
  937. static int gsc_dst_set_size(struct device *dev, int swap,
  938. struct drm_exynos_pos *pos, struct drm_exynos_sz *sz)
  939. {
  940. struct gsc_context *ctx = get_gsc_context(dev);
  941. struct drm_exynos_pos img_pos = *pos;
  942. struct gsc_scaler *sc = &ctx->sc;
  943. u32 cfg;
  944. DRM_DEBUG_KMS("swap[%d]x[%d]y[%d]w[%d]h[%d]\n",
  945. swap, pos->x, pos->y, pos->w, pos->h);
  946. if (swap) {
  947. img_pos.w = pos->h;
  948. img_pos.h = pos->w;
  949. }
  950. /* pixel offset */
  951. cfg = (GSC_DSTIMG_OFFSET_X(pos->x) |
  952. GSC_DSTIMG_OFFSET_Y(pos->y));
  953. gsc_write(cfg, GSC_DSTIMG_OFFSET);
  954. /* scaled size */
  955. cfg = (GSC_SCALED_WIDTH(img_pos.w) | GSC_SCALED_HEIGHT(img_pos.h));
  956. gsc_write(cfg, GSC_SCALED_SIZE);
  957. DRM_DEBUG_KMS("hsize[%d]vsize[%d]\n", sz->hsize, sz->vsize);
  958. /* original size */
  959. cfg = gsc_read(GSC_DSTIMG_SIZE);
  960. cfg &= ~(GSC_DSTIMG_HEIGHT_MASK |
  961. GSC_DSTIMG_WIDTH_MASK);
  962. cfg |= (GSC_DSTIMG_WIDTH(sz->hsize) |
  963. GSC_DSTIMG_HEIGHT(sz->vsize));
  964. gsc_write(cfg, GSC_DSTIMG_SIZE);
  965. cfg = gsc_read(GSC_OUT_CON);
  966. cfg &= ~GSC_OUT_RGB_TYPE_MASK;
  967. DRM_DEBUG_KMS("width[%d]range[%d]\n", pos->w, sc->range);
  968. if (pos->w >= GSC_WIDTH_ITU_709)
  969. if (sc->range)
  970. cfg |= GSC_OUT_RGB_HD_WIDE;
  971. else
  972. cfg |= GSC_OUT_RGB_HD_NARROW;
  973. else
  974. if (sc->range)
  975. cfg |= GSC_OUT_RGB_SD_WIDE;
  976. else
  977. cfg |= GSC_OUT_RGB_SD_NARROW;
  978. gsc_write(cfg, GSC_OUT_CON);
  979. return 0;
  980. }
  981. static int gsc_dst_get_buf_seq(struct gsc_context *ctx)
  982. {
  983. u32 cfg, i, buf_num = GSC_REG_SZ;
  984. u32 mask = 0x00000001;
  985. cfg = gsc_read(GSC_OUT_BASE_ADDR_Y_MASK);
  986. for (i = 0; i < GSC_REG_SZ; i++)
  987. if (cfg & (mask << i))
  988. buf_num--;
  989. DRM_DEBUG_KMS("buf_num[%d]\n", buf_num);
  990. return buf_num;
  991. }
  992. static int gsc_dst_set_buf_seq(struct gsc_context *ctx, u32 buf_id,
  993. enum drm_exynos_ipp_buf_type buf_type)
  994. {
  995. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  996. bool masked;
  997. u32 cfg;
  998. u32 mask = 0x00000001 << buf_id;
  999. int ret = 0;
  1000. DRM_DEBUG_KMS("buf_id[%d]buf_type[%d]\n", buf_id, buf_type);
  1001. mutex_lock(&ctx->lock);
  1002. /* mask register set */
  1003. cfg = gsc_read(GSC_OUT_BASE_ADDR_Y_MASK);
  1004. switch (buf_type) {
  1005. case IPP_BUF_ENQUEUE:
  1006. masked = false;
  1007. break;
  1008. case IPP_BUF_DEQUEUE:
  1009. masked = true;
  1010. break;
  1011. default:
  1012. dev_err(ippdrv->dev, "invalid buf ctrl parameter.\n");
  1013. ret = -EINVAL;
  1014. goto err_unlock;
  1015. }
  1016. /* sequence id */
  1017. cfg &= ~mask;
  1018. cfg |= masked << buf_id;
  1019. gsc_write(cfg, GSC_OUT_BASE_ADDR_Y_MASK);
  1020. gsc_write(cfg, GSC_OUT_BASE_ADDR_CB_MASK);
  1021. gsc_write(cfg, GSC_OUT_BASE_ADDR_CR_MASK);
  1022. /* interrupt enable */
  1023. if (buf_type == IPP_BUF_ENQUEUE &&
  1024. gsc_dst_get_buf_seq(ctx) >= GSC_BUF_START)
  1025. gsc_handle_irq(ctx, true, false, true);
  1026. /* interrupt disable */
  1027. if (buf_type == IPP_BUF_DEQUEUE &&
  1028. gsc_dst_get_buf_seq(ctx) <= GSC_BUF_STOP)
  1029. gsc_handle_irq(ctx, false, false, true);
  1030. err_unlock:
  1031. mutex_unlock(&ctx->lock);
  1032. return ret;
  1033. }
  1034. static int gsc_dst_set_addr(struct device *dev,
  1035. struct drm_exynos_ipp_buf_info *buf_info, u32 buf_id,
  1036. enum drm_exynos_ipp_buf_type buf_type)
  1037. {
  1038. struct gsc_context *ctx = get_gsc_context(dev);
  1039. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  1040. struct drm_exynos_ipp_cmd_node *c_node = ippdrv->c_node;
  1041. struct drm_exynos_ipp_property *property;
  1042. if (!c_node) {
  1043. DRM_ERROR("failed to get c_node.\n");
  1044. return -EFAULT;
  1045. }
  1046. property = &c_node->property;
  1047. DRM_DEBUG_KMS("prop_id[%d]buf_id[%d]buf_type[%d]\n",
  1048. property->prop_id, buf_id, buf_type);
  1049. if (buf_id > GSC_MAX_DST) {
  1050. dev_info(ippdrv->dev, "invalid buf_id %d.\n", buf_id);
  1051. return -EINVAL;
  1052. }
  1053. /* address register set */
  1054. switch (buf_type) {
  1055. case IPP_BUF_ENQUEUE:
  1056. gsc_write(buf_info->base[EXYNOS_DRM_PLANAR_Y],
  1057. GSC_OUT_BASE_ADDR_Y(buf_id));
  1058. gsc_write(buf_info->base[EXYNOS_DRM_PLANAR_CB],
  1059. GSC_OUT_BASE_ADDR_CB(buf_id));
  1060. gsc_write(buf_info->base[EXYNOS_DRM_PLANAR_CR],
  1061. GSC_OUT_BASE_ADDR_CR(buf_id));
  1062. break;
  1063. case IPP_BUF_DEQUEUE:
  1064. gsc_write(0x0, GSC_OUT_BASE_ADDR_Y(buf_id));
  1065. gsc_write(0x0, GSC_OUT_BASE_ADDR_CB(buf_id));
  1066. gsc_write(0x0, GSC_OUT_BASE_ADDR_CR(buf_id));
  1067. break;
  1068. default:
  1069. /* bypass */
  1070. break;
  1071. }
  1072. return gsc_dst_set_buf_seq(ctx, buf_id, buf_type);
  1073. }
  1074. static struct exynos_drm_ipp_ops gsc_dst_ops = {
  1075. .set_fmt = gsc_dst_set_fmt,
  1076. .set_transf = gsc_dst_set_transf,
  1077. .set_size = gsc_dst_set_size,
  1078. .set_addr = gsc_dst_set_addr,
  1079. };
  1080. static int gsc_clk_ctrl(struct gsc_context *ctx, bool enable)
  1081. {
  1082. DRM_DEBUG_KMS("enable[%d]\n", enable);
  1083. if (enable) {
  1084. clk_enable(ctx->gsc_clk);
  1085. ctx->suspended = false;
  1086. } else {
  1087. clk_disable(ctx->gsc_clk);
  1088. ctx->suspended = true;
  1089. }
  1090. return 0;
  1091. }
  1092. static int gsc_get_src_buf_index(struct gsc_context *ctx)
  1093. {
  1094. u32 cfg, curr_index, i;
  1095. u32 buf_id = GSC_MAX_SRC;
  1096. int ret;
  1097. DRM_DEBUG_KMS("gsc id[%d]\n", ctx->id);
  1098. cfg = gsc_read(GSC_IN_BASE_ADDR_Y_MASK);
  1099. curr_index = GSC_IN_CURR_GET_INDEX(cfg);
  1100. for (i = curr_index; i < GSC_MAX_SRC; i++) {
  1101. if (!((cfg >> i) & 0x1)) {
  1102. buf_id = i;
  1103. break;
  1104. }
  1105. }
  1106. if (buf_id == GSC_MAX_SRC) {
  1107. DRM_ERROR("failed to get in buffer index.\n");
  1108. return -EINVAL;
  1109. }
  1110. ret = gsc_src_set_buf_seq(ctx, buf_id, IPP_BUF_DEQUEUE);
  1111. if (ret < 0) {
  1112. DRM_ERROR("failed to dequeue.\n");
  1113. return ret;
  1114. }
  1115. DRM_DEBUG_KMS("cfg[0x%x]curr_index[%d]buf_id[%d]\n", cfg,
  1116. curr_index, buf_id);
  1117. return buf_id;
  1118. }
  1119. static int gsc_get_dst_buf_index(struct gsc_context *ctx)
  1120. {
  1121. u32 cfg, curr_index, i;
  1122. u32 buf_id = GSC_MAX_DST;
  1123. int ret;
  1124. DRM_DEBUG_KMS("gsc id[%d]\n", ctx->id);
  1125. cfg = gsc_read(GSC_OUT_BASE_ADDR_Y_MASK);
  1126. curr_index = GSC_OUT_CURR_GET_INDEX(cfg);
  1127. for (i = curr_index; i < GSC_MAX_DST; i++) {
  1128. if (!((cfg >> i) & 0x1)) {
  1129. buf_id = i;
  1130. break;
  1131. }
  1132. }
  1133. if (buf_id == GSC_MAX_DST) {
  1134. DRM_ERROR("failed to get out buffer index.\n");
  1135. return -EINVAL;
  1136. }
  1137. ret = gsc_dst_set_buf_seq(ctx, buf_id, IPP_BUF_DEQUEUE);
  1138. if (ret < 0) {
  1139. DRM_ERROR("failed to dequeue.\n");
  1140. return ret;
  1141. }
  1142. DRM_DEBUG_KMS("cfg[0x%x]curr_index[%d]buf_id[%d]\n", cfg,
  1143. curr_index, buf_id);
  1144. return buf_id;
  1145. }
  1146. static irqreturn_t gsc_irq_handler(int irq, void *dev_id)
  1147. {
  1148. struct gsc_context *ctx = dev_id;
  1149. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  1150. struct drm_exynos_ipp_cmd_node *c_node = ippdrv->c_node;
  1151. struct drm_exynos_ipp_event_work *event_work =
  1152. c_node->event_work;
  1153. u32 status;
  1154. int buf_id[EXYNOS_DRM_OPS_MAX];
  1155. DRM_DEBUG_KMS("gsc id[%d]\n", ctx->id);
  1156. status = gsc_read(GSC_IRQ);
  1157. if (status & GSC_IRQ_STATUS_OR_IRQ) {
  1158. dev_err(ippdrv->dev, "occurred overflow at %d, status 0x%x.\n",
  1159. ctx->id, status);
  1160. return IRQ_NONE;
  1161. }
  1162. if (status & GSC_IRQ_STATUS_OR_FRM_DONE) {
  1163. dev_dbg(ippdrv->dev, "occurred frame done at %d, status 0x%x.\n",
  1164. ctx->id, status);
  1165. buf_id[EXYNOS_DRM_OPS_SRC] = gsc_get_src_buf_index(ctx);
  1166. if (buf_id[EXYNOS_DRM_OPS_SRC] < 0)
  1167. return IRQ_HANDLED;
  1168. buf_id[EXYNOS_DRM_OPS_DST] = gsc_get_dst_buf_index(ctx);
  1169. if (buf_id[EXYNOS_DRM_OPS_DST] < 0)
  1170. return IRQ_HANDLED;
  1171. DRM_DEBUG_KMS("buf_id_src[%d]buf_id_dst[%d]\n",
  1172. buf_id[EXYNOS_DRM_OPS_SRC], buf_id[EXYNOS_DRM_OPS_DST]);
  1173. event_work->ippdrv = ippdrv;
  1174. event_work->buf_id[EXYNOS_DRM_OPS_SRC] =
  1175. buf_id[EXYNOS_DRM_OPS_SRC];
  1176. event_work->buf_id[EXYNOS_DRM_OPS_DST] =
  1177. buf_id[EXYNOS_DRM_OPS_DST];
  1178. queue_work(ippdrv->event_workq, &event_work->work);
  1179. }
  1180. return IRQ_HANDLED;
  1181. }
  1182. static int gsc_init_prop_list(struct exynos_drm_ippdrv *ippdrv)
  1183. {
  1184. struct drm_exynos_ipp_prop_list *prop_list = &ippdrv->prop_list;
  1185. prop_list->version = 1;
  1186. prop_list->writeback = 1;
  1187. prop_list->refresh_min = GSC_REFRESH_MIN;
  1188. prop_list->refresh_max = GSC_REFRESH_MAX;
  1189. prop_list->flip = (1 << EXYNOS_DRM_FLIP_VERTICAL) |
  1190. (1 << EXYNOS_DRM_FLIP_HORIZONTAL);
  1191. prop_list->degree = (1 << EXYNOS_DRM_DEGREE_0) |
  1192. (1 << EXYNOS_DRM_DEGREE_90) |
  1193. (1 << EXYNOS_DRM_DEGREE_180) |
  1194. (1 << EXYNOS_DRM_DEGREE_270);
  1195. prop_list->csc = 1;
  1196. prop_list->crop = 1;
  1197. prop_list->crop_max.hsize = GSC_CROP_MAX;
  1198. prop_list->crop_max.vsize = GSC_CROP_MAX;
  1199. prop_list->crop_min.hsize = GSC_CROP_MIN;
  1200. prop_list->crop_min.vsize = GSC_CROP_MIN;
  1201. prop_list->scale = 1;
  1202. prop_list->scale_max.hsize = GSC_SCALE_MAX;
  1203. prop_list->scale_max.vsize = GSC_SCALE_MAX;
  1204. prop_list->scale_min.hsize = GSC_SCALE_MIN;
  1205. prop_list->scale_min.vsize = GSC_SCALE_MIN;
  1206. return 0;
  1207. }
  1208. static inline bool gsc_check_drm_flip(enum drm_exynos_flip flip)
  1209. {
  1210. switch (flip) {
  1211. case EXYNOS_DRM_FLIP_NONE:
  1212. case EXYNOS_DRM_FLIP_VERTICAL:
  1213. case EXYNOS_DRM_FLIP_HORIZONTAL:
  1214. case EXYNOS_DRM_FLIP_BOTH:
  1215. return true;
  1216. default:
  1217. DRM_DEBUG_KMS("invalid flip\n");
  1218. return false;
  1219. }
  1220. }
  1221. static int gsc_ippdrv_check_property(struct device *dev,
  1222. struct drm_exynos_ipp_property *property)
  1223. {
  1224. struct gsc_context *ctx = get_gsc_context(dev);
  1225. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  1226. struct drm_exynos_ipp_prop_list *pp = &ippdrv->prop_list;
  1227. struct drm_exynos_ipp_config *config;
  1228. struct drm_exynos_pos *pos;
  1229. struct drm_exynos_sz *sz;
  1230. bool swap;
  1231. int i;
  1232. for_each_ipp_ops(i) {
  1233. if ((i == EXYNOS_DRM_OPS_SRC) &&
  1234. (property->cmd == IPP_CMD_WB))
  1235. continue;
  1236. config = &property->config[i];
  1237. pos = &config->pos;
  1238. sz = &config->sz;
  1239. /* check for flip */
  1240. if (!gsc_check_drm_flip(config->flip)) {
  1241. DRM_ERROR("invalid flip.\n");
  1242. goto err_property;
  1243. }
  1244. /* check for degree */
  1245. switch (config->degree) {
  1246. case EXYNOS_DRM_DEGREE_90:
  1247. case EXYNOS_DRM_DEGREE_270:
  1248. swap = true;
  1249. break;
  1250. case EXYNOS_DRM_DEGREE_0:
  1251. case EXYNOS_DRM_DEGREE_180:
  1252. swap = false;
  1253. break;
  1254. default:
  1255. DRM_ERROR("invalid degree.\n");
  1256. goto err_property;
  1257. }
  1258. /* check for buffer bound */
  1259. if ((pos->x + pos->w > sz->hsize) ||
  1260. (pos->y + pos->h > sz->vsize)) {
  1261. DRM_ERROR("out of buf bound.\n");
  1262. goto err_property;
  1263. }
  1264. /* check for crop */
  1265. if ((i == EXYNOS_DRM_OPS_SRC) && (pp->crop)) {
  1266. if (swap) {
  1267. if ((pos->h < pp->crop_min.hsize) ||
  1268. (sz->vsize > pp->crop_max.hsize) ||
  1269. (pos->w < pp->crop_min.vsize) ||
  1270. (sz->hsize > pp->crop_max.vsize)) {
  1271. DRM_ERROR("out of crop size.\n");
  1272. goto err_property;
  1273. }
  1274. } else {
  1275. if ((pos->w < pp->crop_min.hsize) ||
  1276. (sz->hsize > pp->crop_max.hsize) ||
  1277. (pos->h < pp->crop_min.vsize) ||
  1278. (sz->vsize > pp->crop_max.vsize)) {
  1279. DRM_ERROR("out of crop size.\n");
  1280. goto err_property;
  1281. }
  1282. }
  1283. }
  1284. /* check for scale */
  1285. if ((i == EXYNOS_DRM_OPS_DST) && (pp->scale)) {
  1286. if (swap) {
  1287. if ((pos->h < pp->scale_min.hsize) ||
  1288. (sz->vsize > pp->scale_max.hsize) ||
  1289. (pos->w < pp->scale_min.vsize) ||
  1290. (sz->hsize > pp->scale_max.vsize)) {
  1291. DRM_ERROR("out of scale size.\n");
  1292. goto err_property;
  1293. }
  1294. } else {
  1295. if ((pos->w < pp->scale_min.hsize) ||
  1296. (sz->hsize > pp->scale_max.hsize) ||
  1297. (pos->h < pp->scale_min.vsize) ||
  1298. (sz->vsize > pp->scale_max.vsize)) {
  1299. DRM_ERROR("out of scale size.\n");
  1300. goto err_property;
  1301. }
  1302. }
  1303. }
  1304. }
  1305. return 0;
  1306. err_property:
  1307. for_each_ipp_ops(i) {
  1308. if ((i == EXYNOS_DRM_OPS_SRC) &&
  1309. (property->cmd == IPP_CMD_WB))
  1310. continue;
  1311. config = &property->config[i];
  1312. pos = &config->pos;
  1313. sz = &config->sz;
  1314. DRM_ERROR("[%s]f[%d]r[%d]pos[%d %d %d %d]sz[%d %d]\n",
  1315. i ? "dst" : "src", config->flip, config->degree,
  1316. pos->x, pos->y, pos->w, pos->h,
  1317. sz->hsize, sz->vsize);
  1318. }
  1319. return -EINVAL;
  1320. }
  1321. static int gsc_ippdrv_reset(struct device *dev)
  1322. {
  1323. struct gsc_context *ctx = get_gsc_context(dev);
  1324. struct gsc_scaler *sc = &ctx->sc;
  1325. int ret;
  1326. /* reset h/w block */
  1327. ret = gsc_sw_reset(ctx);
  1328. if (ret < 0) {
  1329. dev_err(dev, "failed to reset hardware.\n");
  1330. return ret;
  1331. }
  1332. /* scaler setting */
  1333. memset(&ctx->sc, 0x0, sizeof(ctx->sc));
  1334. sc->range = true;
  1335. return 0;
  1336. }
  1337. static int gsc_ippdrv_start(struct device *dev, enum drm_exynos_ipp_cmd cmd)
  1338. {
  1339. struct gsc_context *ctx = get_gsc_context(dev);
  1340. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  1341. struct drm_exynos_ipp_cmd_node *c_node = ippdrv->c_node;
  1342. struct drm_exynos_ipp_property *property;
  1343. struct drm_exynos_ipp_config *config;
  1344. struct drm_exynos_pos img_pos[EXYNOS_DRM_OPS_MAX];
  1345. struct drm_exynos_ipp_set_wb set_wb;
  1346. u32 cfg;
  1347. int ret, i;
  1348. DRM_DEBUG_KMS("cmd[%d]\n", cmd);
  1349. if (!c_node) {
  1350. DRM_ERROR("failed to get c_node.\n");
  1351. return -EINVAL;
  1352. }
  1353. property = &c_node->property;
  1354. gsc_handle_irq(ctx, true, false, true);
  1355. for_each_ipp_ops(i) {
  1356. config = &property->config[i];
  1357. img_pos[i] = config->pos;
  1358. }
  1359. switch (cmd) {
  1360. case IPP_CMD_M2M:
  1361. /* enable one shot */
  1362. cfg = gsc_read(GSC_ENABLE);
  1363. cfg &= ~(GSC_ENABLE_ON_CLEAR_MASK |
  1364. GSC_ENABLE_CLK_GATE_MODE_MASK);
  1365. cfg |= GSC_ENABLE_ON_CLEAR_ONESHOT;
  1366. gsc_write(cfg, GSC_ENABLE);
  1367. /* src dma memory */
  1368. cfg = gsc_read(GSC_IN_CON);
  1369. cfg &= ~(GSC_IN_PATH_MASK | GSC_IN_LOCAL_SEL_MASK);
  1370. cfg |= GSC_IN_PATH_MEMORY;
  1371. gsc_write(cfg, GSC_IN_CON);
  1372. /* dst dma memory */
  1373. cfg = gsc_read(GSC_OUT_CON);
  1374. cfg |= GSC_OUT_PATH_MEMORY;
  1375. gsc_write(cfg, GSC_OUT_CON);
  1376. break;
  1377. case IPP_CMD_WB:
  1378. set_wb.enable = 1;
  1379. set_wb.refresh = property->refresh_rate;
  1380. gsc_set_gscblk_fimd_wb(ctx, set_wb.enable);
  1381. exynos_drm_ippnb_send_event(IPP_SET_WRITEBACK, (void *)&set_wb);
  1382. /* src local path */
  1383. cfg = gsc_read(GSC_IN_CON);
  1384. cfg &= ~(GSC_IN_PATH_MASK | GSC_IN_LOCAL_SEL_MASK);
  1385. cfg |= (GSC_IN_PATH_LOCAL | GSC_IN_LOCAL_FIMD_WB);
  1386. gsc_write(cfg, GSC_IN_CON);
  1387. /* dst dma memory */
  1388. cfg = gsc_read(GSC_OUT_CON);
  1389. cfg |= GSC_OUT_PATH_MEMORY;
  1390. gsc_write(cfg, GSC_OUT_CON);
  1391. break;
  1392. case IPP_CMD_OUTPUT:
  1393. /* src dma memory */
  1394. cfg = gsc_read(GSC_IN_CON);
  1395. cfg &= ~(GSC_IN_PATH_MASK | GSC_IN_LOCAL_SEL_MASK);
  1396. cfg |= GSC_IN_PATH_MEMORY;
  1397. gsc_write(cfg, GSC_IN_CON);
  1398. /* dst local path */
  1399. cfg = gsc_read(GSC_OUT_CON);
  1400. cfg |= GSC_OUT_PATH_MEMORY;
  1401. gsc_write(cfg, GSC_OUT_CON);
  1402. break;
  1403. default:
  1404. ret = -EINVAL;
  1405. dev_err(dev, "invalid operations.\n");
  1406. return ret;
  1407. }
  1408. ret = gsc_set_prescaler(ctx, &ctx->sc,
  1409. &img_pos[EXYNOS_DRM_OPS_SRC],
  1410. &img_pos[EXYNOS_DRM_OPS_DST]);
  1411. if (ret) {
  1412. dev_err(dev, "failed to set precalser.\n");
  1413. return ret;
  1414. }
  1415. gsc_set_scaler(ctx, &ctx->sc);
  1416. cfg = gsc_read(GSC_ENABLE);
  1417. cfg |= GSC_ENABLE_ON;
  1418. gsc_write(cfg, GSC_ENABLE);
  1419. return 0;
  1420. }
  1421. static void gsc_ippdrv_stop(struct device *dev, enum drm_exynos_ipp_cmd cmd)
  1422. {
  1423. struct gsc_context *ctx = get_gsc_context(dev);
  1424. struct drm_exynos_ipp_set_wb set_wb = {0, 0};
  1425. u32 cfg;
  1426. DRM_DEBUG_KMS("cmd[%d]\n", cmd);
  1427. switch (cmd) {
  1428. case IPP_CMD_M2M:
  1429. /* bypass */
  1430. break;
  1431. case IPP_CMD_WB:
  1432. gsc_set_gscblk_fimd_wb(ctx, set_wb.enable);
  1433. exynos_drm_ippnb_send_event(IPP_SET_WRITEBACK, (void *)&set_wb);
  1434. break;
  1435. case IPP_CMD_OUTPUT:
  1436. default:
  1437. dev_err(dev, "invalid operations.\n");
  1438. break;
  1439. }
  1440. gsc_handle_irq(ctx, false, false, true);
  1441. /* reset sequence */
  1442. gsc_write(0xff, GSC_OUT_BASE_ADDR_Y_MASK);
  1443. gsc_write(0xff, GSC_OUT_BASE_ADDR_CB_MASK);
  1444. gsc_write(0xff, GSC_OUT_BASE_ADDR_CR_MASK);
  1445. cfg = gsc_read(GSC_ENABLE);
  1446. cfg &= ~GSC_ENABLE_ON;
  1447. gsc_write(cfg, GSC_ENABLE);
  1448. }
  1449. static int gsc_probe(struct platform_device *pdev)
  1450. {
  1451. struct device *dev = &pdev->dev;
  1452. struct gsc_context *ctx;
  1453. struct resource *res;
  1454. struct exynos_drm_ippdrv *ippdrv;
  1455. int ret;
  1456. ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  1457. if (!ctx)
  1458. return -ENOMEM;
  1459. /* clock control */
  1460. ctx->gsc_clk = devm_clk_get(dev, "gscl");
  1461. if (IS_ERR(ctx->gsc_clk)) {
  1462. dev_err(dev, "failed to get gsc clock.\n");
  1463. return PTR_ERR(ctx->gsc_clk);
  1464. }
  1465. /* resource memory */
  1466. ctx->regs_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1467. ctx->regs = devm_ioremap_resource(dev, ctx->regs_res);
  1468. if (IS_ERR(ctx->regs))
  1469. return PTR_ERR(ctx->regs);
  1470. /* resource irq */
  1471. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1472. if (!res) {
  1473. dev_err(dev, "failed to request irq resource.\n");
  1474. return -ENOENT;
  1475. }
  1476. ctx->irq = res->start;
  1477. ret = devm_request_threaded_irq(dev, ctx->irq, NULL, gsc_irq_handler,
  1478. IRQF_ONESHOT, "drm_gsc", ctx);
  1479. if (ret < 0) {
  1480. dev_err(dev, "failed to request irq.\n");
  1481. return ret;
  1482. }
  1483. /* context initailization */
  1484. ctx->id = pdev->id;
  1485. ippdrv = &ctx->ippdrv;
  1486. ippdrv->dev = dev;
  1487. ippdrv->ops[EXYNOS_DRM_OPS_SRC] = &gsc_src_ops;
  1488. ippdrv->ops[EXYNOS_DRM_OPS_DST] = &gsc_dst_ops;
  1489. ippdrv->check_property = gsc_ippdrv_check_property;
  1490. ippdrv->reset = gsc_ippdrv_reset;
  1491. ippdrv->start = gsc_ippdrv_start;
  1492. ippdrv->stop = gsc_ippdrv_stop;
  1493. ret = gsc_init_prop_list(ippdrv);
  1494. if (ret < 0) {
  1495. dev_err(dev, "failed to init property list.\n");
  1496. return ret;
  1497. }
  1498. DRM_DEBUG_KMS("id[%d]ippdrv[0x%x]\n", ctx->id, (int)ippdrv);
  1499. mutex_init(&ctx->lock);
  1500. platform_set_drvdata(pdev, ctx);
  1501. pm_runtime_set_active(dev);
  1502. pm_runtime_enable(dev);
  1503. ret = exynos_drm_ippdrv_register(ippdrv);
  1504. if (ret < 0) {
  1505. dev_err(dev, "failed to register drm gsc device.\n");
  1506. goto err_ippdrv_register;
  1507. }
  1508. dev_info(dev, "drm gsc registered successfully.\n");
  1509. return 0;
  1510. err_ippdrv_register:
  1511. pm_runtime_disable(dev);
  1512. return ret;
  1513. }
  1514. static int gsc_remove(struct platform_device *pdev)
  1515. {
  1516. struct device *dev = &pdev->dev;
  1517. struct gsc_context *ctx = get_gsc_context(dev);
  1518. struct exynos_drm_ippdrv *ippdrv = &ctx->ippdrv;
  1519. exynos_drm_ippdrv_unregister(ippdrv);
  1520. mutex_destroy(&ctx->lock);
  1521. pm_runtime_set_suspended(dev);
  1522. pm_runtime_disable(dev);
  1523. return 0;
  1524. }
  1525. #ifdef CONFIG_PM_SLEEP
  1526. static int gsc_suspend(struct device *dev)
  1527. {
  1528. struct gsc_context *ctx = get_gsc_context(dev);
  1529. DRM_DEBUG_KMS("id[%d]\n", ctx->id);
  1530. if (pm_runtime_suspended(dev))
  1531. return 0;
  1532. return gsc_clk_ctrl(ctx, false);
  1533. }
  1534. static int gsc_resume(struct device *dev)
  1535. {
  1536. struct gsc_context *ctx = get_gsc_context(dev);
  1537. DRM_DEBUG_KMS("id[%d]\n", ctx->id);
  1538. if (!pm_runtime_suspended(dev))
  1539. return gsc_clk_ctrl(ctx, true);
  1540. return 0;
  1541. }
  1542. #endif
  1543. #ifdef CONFIG_PM
  1544. static int gsc_runtime_suspend(struct device *dev)
  1545. {
  1546. struct gsc_context *ctx = get_gsc_context(dev);
  1547. DRM_DEBUG_KMS("id[%d]\n", ctx->id);
  1548. return gsc_clk_ctrl(ctx, false);
  1549. }
  1550. static int gsc_runtime_resume(struct device *dev)
  1551. {
  1552. struct gsc_context *ctx = get_gsc_context(dev);
  1553. DRM_DEBUG_KMS("id[%d]\n", ctx->id);
  1554. return gsc_clk_ctrl(ctx, true);
  1555. }
  1556. #endif
  1557. static const struct dev_pm_ops gsc_pm_ops = {
  1558. SET_SYSTEM_SLEEP_PM_OPS(gsc_suspend, gsc_resume)
  1559. SET_RUNTIME_PM_OPS(gsc_runtime_suspend, gsc_runtime_resume, NULL)
  1560. };
  1561. struct platform_driver gsc_driver = {
  1562. .probe = gsc_probe,
  1563. .remove = gsc_remove,
  1564. .driver = {
  1565. .name = "exynos-drm-gsc",
  1566. .owner = THIS_MODULE,
  1567. .pm = &gsc_pm_ops,
  1568. },
  1569. };