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