exynos_drm_gsc.c 44 KB

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