head507d.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * Copyright 2018 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #include "head.h"
  23. #include "core.h"
  24. void
  25. head507d_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
  26. {
  27. struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
  28. u32 *push;
  29. if ((push = evo_wait(core, 2))) {
  30. evo_mthd(push, 0x08a8 + (head->base.index * 0x400), 1);
  31. evo_data(push, asyh->procamp.sat.sin << 20 |
  32. asyh->procamp.sat.cos << 8);
  33. evo_kick(push, core);
  34. }
  35. }
  36. void
  37. head507d_dither(struct nv50_head *head, struct nv50_head_atom *asyh)
  38. {
  39. struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
  40. u32 *push;
  41. if ((push = evo_wait(core, 2))) {
  42. evo_mthd(push, 0x08a0 + (head->base.index * 0x0400), 1);
  43. evo_data(push, asyh->dither.mode << 3 |
  44. asyh->dither.bits << 1 |
  45. asyh->dither.enable);
  46. evo_kick(push, core);
  47. }
  48. }
  49. void
  50. head507d_ovly(struct nv50_head *head, struct nv50_head_atom *asyh)
  51. {
  52. struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
  53. u32 bounds = 0;
  54. u32 *push;
  55. if (asyh->ovly.cpp) {
  56. switch (asyh->ovly.cpp) {
  57. case 4: bounds |= 0x00000300; break;
  58. case 2: bounds |= 0x00000100; break;
  59. default:
  60. WARN_ON(1);
  61. break;
  62. }
  63. bounds |= 0x00000001;
  64. } else {
  65. bounds |= 0x00000100;
  66. }
  67. if ((push = evo_wait(core, 2))) {
  68. evo_mthd(push, 0x0904 + head->base.index * 0x400, 1);
  69. evo_data(push, bounds);
  70. evo_kick(push, core);
  71. }
  72. }
  73. void
  74. head507d_base(struct nv50_head *head, struct nv50_head_atom *asyh)
  75. {
  76. struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
  77. u32 bounds = 0;
  78. u32 *push;
  79. if (asyh->base.cpp) {
  80. switch (asyh->base.cpp) {
  81. case 8: bounds |= 0x00000500; break;
  82. case 4: bounds |= 0x00000300; break;
  83. case 2: bounds |= 0x00000100; break;
  84. case 1: bounds |= 0x00000000; break;
  85. default:
  86. WARN_ON(1);
  87. break;
  88. }
  89. bounds |= 0x00000001;
  90. }
  91. if ((push = evo_wait(core, 2))) {
  92. evo_mthd(push, 0x0900 + head->base.index * 0x400, 1);
  93. evo_data(push, bounds);
  94. evo_kick(push, core);
  95. }
  96. }
  97. static void
  98. head507d_curs_clr(struct nv50_head *head)
  99. {
  100. struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
  101. u32 *push;
  102. if ((push = evo_wait(core, 2))) {
  103. evo_mthd(push, 0x0880 + head->base.index * 0x400, 1);
  104. evo_data(push, 0x05000000);
  105. evo_kick(push, core);
  106. }
  107. }
  108. static void
  109. head507d_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh)
  110. {
  111. struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
  112. u32 *push;
  113. if ((push = evo_wait(core, 3))) {
  114. evo_mthd(push, 0x0880 + head->base.index * 0x400, 2);
  115. evo_data(push, 0x80000000 | asyh->curs.layout << 26 |
  116. asyh->curs.format << 24);
  117. evo_data(push, asyh->curs.offset >> 8);
  118. evo_kick(push, core);
  119. }
  120. }
  121. int
  122. head507d_curs_format(struct nv50_head *head, struct nv50_wndw_atom *asyw,
  123. struct nv50_head_atom *asyh)
  124. {
  125. switch (asyw->image.format) {
  126. case 0xcf: asyh->curs.format = 1; break;
  127. default:
  128. WARN_ON(1);
  129. return -EINVAL;
  130. }
  131. return 0;
  132. }
  133. int
  134. head507d_curs_layout(struct nv50_head *head, struct nv50_wndw_atom *asyw,
  135. struct nv50_head_atom *asyh)
  136. {
  137. switch (asyw->image.w) {
  138. case 32: asyh->curs.layout = 0; break;
  139. case 64: asyh->curs.layout = 1; break;
  140. default:
  141. return -EINVAL;
  142. }
  143. return 0;
  144. }
  145. void
  146. head507d_core_clr(struct nv50_head *head)
  147. {
  148. struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
  149. u32 *push;
  150. if ((push = evo_wait(core, 2))) {
  151. evo_mthd(push, 0x0874 + head->base.index * 0x400, 1);
  152. evo_data(push, 0x00000000);
  153. evo_kick(push, core);
  154. }
  155. }
  156. static void
  157. head507d_core_set(struct nv50_head *head, struct nv50_head_atom *asyh)
  158. {
  159. struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
  160. u32 *push;
  161. if ((push = evo_wait(core, 9))) {
  162. evo_mthd(push, 0x0860 + head->base.index * 0x400, 1);
  163. evo_data(push, asyh->core.offset >> 8);
  164. evo_mthd(push, 0x0868 + head->base.index * 0x400, 4);
  165. evo_data(push, asyh->core.h << 16 | asyh->core.w);
  166. evo_data(push, asyh->core.layout << 20 |
  167. (asyh->core.pitch >> 8) << 8 |
  168. asyh->core.blocks << 8 |
  169. asyh->core.blockh);
  170. evo_data(push, asyh->core.kind << 16 |
  171. asyh->core.format << 8);
  172. evo_data(push, asyh->core.handle);
  173. evo_mthd(push, 0x08c0 + head->base.index * 0x400, 1);
  174. evo_data(push, asyh->core.y << 16 | asyh->core.x);
  175. evo_kick(push, core);
  176. /* EVO will complain with INVALID_STATE if we have an
  177. * active cursor and (re)specify HeadSetContextDmaIso
  178. * without also updating HeadSetOffsetCursor.
  179. */
  180. asyh->set.curs = asyh->curs.visible;
  181. asyh->set.olut = asyh->olut.handle != 0;
  182. }
  183. }
  184. void
  185. head507d_core_calc(struct nv50_head *head, struct nv50_head_atom *asyh)
  186. {
  187. struct nv50_disp *disp = nv50_disp(head->base.base.dev);
  188. if ((asyh->core.visible = (asyh->base.cpp != 0))) {
  189. asyh->core.x = asyh->base.x;
  190. asyh->core.y = asyh->base.y;
  191. asyh->core.w = asyh->base.w;
  192. asyh->core.h = asyh->base.h;
  193. } else
  194. if ((asyh->core.visible = (asyh->ovly.cpp != 0)) ||
  195. (asyh->core.visible = asyh->curs.visible)) {
  196. /*XXX: We need to either find some way of having the
  197. * primary base layer appear black, while still
  198. * being able to display the other layers, or we
  199. * need to allocate a dummy black surface here.
  200. */
  201. asyh->core.x = 0;
  202. asyh->core.y = 0;
  203. asyh->core.w = asyh->state.mode.hdisplay;
  204. asyh->core.h = asyh->state.mode.vdisplay;
  205. }
  206. asyh->core.handle = disp->core->chan.vram.handle;
  207. asyh->core.offset = 0;
  208. asyh->core.format = 0xcf;
  209. asyh->core.kind = 0;
  210. asyh->core.layout = 1;
  211. asyh->core.blockh = 0;
  212. asyh->core.blocks = 0;
  213. asyh->core.pitch = ALIGN(asyh->core.w, 64) * 4;
  214. }
  215. static void
  216. head507d_olut_clr(struct nv50_head *head)
  217. {
  218. struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
  219. u32 *push;
  220. if ((push = evo_wait(core, 2))) {
  221. evo_mthd(push, 0x0840 + (head->base.index * 0x400), 1);
  222. evo_data(push, 0x00000000);
  223. evo_kick(push, core);
  224. }
  225. }
  226. static void
  227. head507d_olut_set(struct nv50_head *head, struct nv50_head_atom *asyh)
  228. {
  229. struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
  230. u32 *push;
  231. if ((push = evo_wait(core, 3))) {
  232. evo_mthd(push, 0x0840 + (head->base.index * 0x400), 2);
  233. evo_data(push, 0x80000000 | asyh->olut.mode << 30);
  234. evo_data(push, asyh->olut.offset >> 8);
  235. evo_kick(push, core);
  236. }
  237. }
  238. void
  239. head507d_olut(struct nv50_head *head, struct nv50_head_atom *asyh)
  240. {
  241. if (asyh->base.cpp == 1)
  242. asyh->olut.mode = 0;
  243. else
  244. asyh->olut.mode = 1;
  245. }
  246. void
  247. head507d_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
  248. {
  249. struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
  250. struct nv50_head_mode *m = &asyh->mode;
  251. u32 *push;
  252. if ((push = evo_wait(core, 13))) {
  253. evo_mthd(push, 0x0804 + (head->base.index * 0x400), 2);
  254. evo_data(push, 0x00800000 | m->clock);
  255. evo_data(push, m->interlace ? 0x00000002 : 0x00000000);
  256. evo_mthd(push, 0x0810 + (head->base.index * 0x400), 7);
  257. evo_data(push, 0x00000000);
  258. evo_data(push, m->v.active << 16 | m->h.active );
  259. evo_data(push, m->v.synce << 16 | m->h.synce );
  260. evo_data(push, m->v.blanke << 16 | m->h.blanke );
  261. evo_data(push, m->v.blanks << 16 | m->h.blanks );
  262. evo_data(push, m->v.blank2e << 16 | m->v.blank2s);
  263. evo_data(push, asyh->mode.v.blankus);
  264. evo_mthd(push, 0x082c + (head->base.index * 0x400), 1);
  265. evo_data(push, 0x00000000);
  266. evo_kick(push, core);
  267. }
  268. }
  269. void
  270. head507d_view(struct nv50_head *head, struct nv50_head_atom *asyh)
  271. {
  272. struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
  273. u32 *push;
  274. if ((push = evo_wait(core, 7))) {
  275. evo_mthd(push, 0x08a4 + (head->base.index * 0x400), 1);
  276. evo_data(push, 0x00000000);
  277. evo_mthd(push, 0x08c8 + (head->base.index * 0x400), 1);
  278. evo_data(push, asyh->view.iH << 16 | asyh->view.iW);
  279. evo_mthd(push, 0x08d8 + (head->base.index * 0x400), 2);
  280. evo_data(push, asyh->view.oH << 16 | asyh->view.oW);
  281. evo_data(push, asyh->view.oH << 16 | asyh->view.oW);
  282. evo_kick(push, core);
  283. }
  284. }
  285. const struct nv50_head_func
  286. head507d = {
  287. .view = head507d_view,
  288. .mode = head507d_mode,
  289. .olut = head507d_olut,
  290. .olut_set = head507d_olut_set,
  291. .olut_clr = head507d_olut_clr,
  292. .core_calc = head507d_core_calc,
  293. .core_set = head507d_core_set,
  294. .core_clr = head507d_core_clr,
  295. .curs_layout = head507d_curs_layout,
  296. .curs_format = head507d_curs_format,
  297. .curs_set = head507d_curs_set,
  298. .curs_clr = head507d_curs_clr,
  299. .base = head507d_base,
  300. .ovly = head507d_ovly,
  301. .dither = head507d_dither,
  302. .procamp = head507d_procamp,
  303. };