exynos_drm_gsc.c 45 KB

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