headc37d.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 "atom.h"
  24. #include "core.h"
  25. #include <nvif/pushc37b.h>
  26. #include <nvhw/class/clc37d.h>
  27. static int
  28. headc37d_or(struct nv50_head *head, struct nv50_head_atom *asyh)
  29. {
  30. struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
  31. const int i = head->base.index;
  32. u8 depth;
  33. int ret;
  34. /*XXX: This is a dirty hack until OR depth handling is
  35. * improved later for deep colour etc.
  36. */
  37. switch (asyh->or.depth) {
  38. case 6: depth = 5; break;
  39. case 5: depth = 4; break;
  40. case 2: depth = 1; break;
  41. case 0: depth = 4; break;
  42. default:
  43. depth = asyh->or.depth;
  44. WARN_ON(1);
  45. break;
  46. }
  47. if ((ret = PUSH_WAIT(push, 2)))
  48. return ret;
  49. PUSH_MTHD(push, NVC37D, HEAD_SET_CONTROL_OUTPUT_RESOURCE(i),
  50. NVVAL(NVC37D, HEAD_SET_CONTROL_OUTPUT_RESOURCE, CRC_MODE, asyh->or.crc_raster) |
  51. NVVAL(NVC37D, HEAD_SET_CONTROL_OUTPUT_RESOURCE, HSYNC_POLARITY, asyh->or.nhsync) |
  52. NVVAL(NVC37D, HEAD_SET_CONTROL_OUTPUT_RESOURCE, VSYNC_POLARITY, asyh->or.nvsync) |
  53. NVVAL(NVC37D, HEAD_SET_CONTROL_OUTPUT_RESOURCE, PIXEL_DEPTH, depth) |
  54. NVDEF(NVC37D, HEAD_SET_CONTROL_OUTPUT_RESOURCE, COLOR_SPACE_OVERRIDE, DISABLE));
  55. return 0;
  56. }
  57. static int
  58. headc37d_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
  59. {
  60. struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
  61. const int i = head->base.index;
  62. int ret;
  63. if ((ret = PUSH_WAIT(push, 2)))
  64. return ret;
  65. PUSH_MTHD(push, NVC37D, HEAD_SET_PROCAMP(i),
  66. NVDEF(NVC37D, HEAD_SET_PROCAMP, COLOR_SPACE, RGB) |
  67. NVDEF(NVC37D, HEAD_SET_PROCAMP, CHROMA_LPF, DISABLE) |
  68. NVVAL(NVC37D, HEAD_SET_PROCAMP, SAT_COS, asyh->procamp.sat.cos) |
  69. NVVAL(NVC37D, HEAD_SET_PROCAMP, SAT_SINE, asyh->procamp.sat.sin) |
  70. NVDEF(NVC37D, HEAD_SET_PROCAMP, DYNAMIC_RANGE, VESA) |
  71. NVDEF(NVC37D, HEAD_SET_PROCAMP, RANGE_COMPRESSION, DISABLE) |
  72. NVDEF(NVC37D, HEAD_SET_PROCAMP, BLACK_LEVEL, GRAPHICS));
  73. return 0;
  74. }
  75. int
  76. headc37d_dither(struct nv50_head *head, struct nv50_head_atom *asyh)
  77. {
  78. struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
  79. const int i = head->base.index;
  80. int ret;
  81. if ((ret = PUSH_WAIT(push, 2)))
  82. return ret;
  83. PUSH_MTHD(push, NVC37D, HEAD_SET_DITHER_CONTROL(i),
  84. NVVAL(NVC37D, HEAD_SET_DITHER_CONTROL, ENABLE, asyh->dither.enable) |
  85. NVVAL(NVC37D, HEAD_SET_DITHER_CONTROL, BITS, asyh->dither.bits) |
  86. NVDEF(NVC37D, HEAD_SET_DITHER_CONTROL, OFFSET_ENABLE, DISABLE) |
  87. NVVAL(NVC37D, HEAD_SET_DITHER_CONTROL, MODE, asyh->dither.mode) |
  88. NVVAL(NVC37D, HEAD_SET_DITHER_CONTROL, PHASE, 0));
  89. return 0;
  90. }
  91. int
  92. headc37d_curs_clr(struct nv50_head *head)
  93. {
  94. struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
  95. const int i = head->base.index;
  96. int ret;
  97. if ((ret = PUSH_WAIT(push, 4)))
  98. return ret;
  99. PUSH_MTHD(push, NVC37D, HEAD_SET_CONTROL_CURSOR(i),
  100. NVDEF(NVC37D, HEAD_SET_CONTROL_CURSOR, ENABLE, DISABLE) |
  101. NVDEF(NVC37D, HEAD_SET_CONTROL_CURSOR, FORMAT, A8R8G8B8));
  102. PUSH_MTHD(push, NVC37D, HEAD_SET_CONTEXT_DMA_CURSOR(i, 0), 0x00000000);
  103. return 0;
  104. }
  105. int
  106. headc37d_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh)
  107. {
  108. struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
  109. const int i = head->base.index;
  110. int ret;
  111. if ((ret = PUSH_WAIT(push, 7)))
  112. return ret;
  113. PUSH_MTHD(push, NVC37D, HEAD_SET_CONTROL_CURSOR(i),
  114. NVDEF(NVC37D, HEAD_SET_CONTROL_CURSOR, ENABLE, ENABLE) |
  115. NVVAL(NVC37D, HEAD_SET_CONTROL_CURSOR, FORMAT, asyh->curs.format) |
  116. NVVAL(NVC37D, HEAD_SET_CONTROL_CURSOR, SIZE, asyh->curs.layout) |
  117. NVVAL(NVC37D, HEAD_SET_CONTROL_CURSOR, HOT_SPOT_X, 0) |
  118. NVVAL(NVC37D, HEAD_SET_CONTROL_CURSOR, HOT_SPOT_Y, 0) |
  119. NVDEF(NVC37D, HEAD_SET_CONTROL_CURSOR, DE_GAMMA, NONE),
  120. HEAD_SET_CONTROL_CURSOR_COMPOSITION(i),
  121. NVVAL(NVC37D, HEAD_SET_CONTROL_CURSOR_COMPOSITION, K1, 0xff) |
  122. NVDEF(NVC37D, HEAD_SET_CONTROL_CURSOR_COMPOSITION, CURSOR_COLOR_FACTOR_SELECT,
  123. K1) |
  124. NVDEF(NVC37D, HEAD_SET_CONTROL_CURSOR_COMPOSITION, VIEWPORT_COLOR_FACTOR_SELECT,
  125. NEG_K1_TIMES_SRC) |
  126. NVDEF(NVC37D, HEAD_SET_CONTROL_CURSOR_COMPOSITION, MODE, BLEND));
  127. PUSH_MTHD(push, NVC37D, HEAD_SET_CONTEXT_DMA_CURSOR(i, 0), asyh->curs.handle);
  128. PUSH_MTHD(push, NVC37D, HEAD_SET_OFFSET_CURSOR(i, 0), asyh->curs.offset >> 8);
  129. return 0;
  130. }
  131. int
  132. headc37d_curs_format(struct nv50_head *head, struct nv50_wndw_atom *asyw,
  133. struct nv50_head_atom *asyh)
  134. {
  135. asyh->curs.format = asyw->image.format;
  136. return 0;
  137. }
  138. static int
  139. headc37d_olut_clr(struct nv50_head *head)
  140. {
  141. struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
  142. const int i = head->base.index;
  143. int ret;
  144. if ((ret = PUSH_WAIT(push, 2)))
  145. return ret;
  146. PUSH_MTHD(push, NVC37D, HEAD_SET_CONTEXT_DMA_OUTPUT_LUT(i), 0x00000000);
  147. return 0;
  148. }
  149. static int
  150. headc37d_olut_set(struct nv50_head *head, struct nv50_head_atom *asyh)
  151. {
  152. struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
  153. const int i = head->base.index;
  154. int ret;
  155. if ((ret = PUSH_WAIT(push, 4)))
  156. return ret;
  157. PUSH_MTHD(push, NVC37D, HEAD_SET_CONTROL_OUTPUT_LUT(i),
  158. NVVAL(NVC37D, HEAD_SET_CONTROL_OUTPUT_LUT, SIZE, asyh->olut.size) |
  159. NVVAL(NVC37D, HEAD_SET_CONTROL_OUTPUT_LUT, RANGE, asyh->olut.range) |
  160. NVVAL(NVC37D, HEAD_SET_CONTROL_OUTPUT_LUT, OUTPUT_MODE, asyh->olut.output_mode),
  161. HEAD_SET_OFFSET_OUTPUT_LUT(i), asyh->olut.offset >> 8,
  162. HEAD_SET_CONTEXT_DMA_OUTPUT_LUT(i), asyh->olut.handle);
  163. return 0;
  164. }
  165. static bool
  166. headc37d_olut(struct nv50_head *head, struct nv50_head_atom *asyh, int size)
  167. {
  168. if (size != 256 && size != 1024)
  169. return false;
  170. asyh->olut.size = size == 1024 ? NVC37D_HEAD_SET_CONTROL_OUTPUT_LUT_SIZE_SIZE_1025 :
  171. NVC37D_HEAD_SET_CONTROL_OUTPUT_LUT_SIZE_SIZE_257;
  172. asyh->olut.range = NVC37D_HEAD_SET_CONTROL_OUTPUT_LUT_RANGE_UNITY;
  173. asyh->olut.output_mode = NVC37D_HEAD_SET_CONTROL_OUTPUT_LUT_OUTPUT_MODE_INTERPOLATE;
  174. asyh->olut.load = head907d_olut_load;
  175. return true;
  176. }
  177. static int
  178. headc37d_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
  179. {
  180. struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
  181. struct nv50_head_mode *m = &asyh->mode;
  182. const int i = head->base.index;
  183. int ret;
  184. if ((ret = PUSH_WAIT(push, 15)))
  185. return ret;
  186. PUSH_MTHD(push, NVC37D, HEAD_SET_RASTER_SIZE(i),
  187. NVVAL(NVC37D, HEAD_SET_RASTER_SIZE, WIDTH, m->h.active) |
  188. NVVAL(NVC37D, HEAD_SET_RASTER_SIZE, HEIGHT, m->v.active),
  189. HEAD_SET_RASTER_SYNC_END(i),
  190. NVVAL(NVC37D, HEAD_SET_RASTER_SYNC_END, X, m->h.synce) |
  191. NVVAL(NVC37D, HEAD_SET_RASTER_SYNC_END, Y, m->v.synce),
  192. HEAD_SET_RASTER_BLANK_END(i),
  193. NVVAL(NVC37D, HEAD_SET_RASTER_BLANK_END, X, m->h.blanke) |
  194. NVVAL(NVC37D, HEAD_SET_RASTER_BLANK_END, Y, m->v.blanke),
  195. HEAD_SET_RASTER_BLANK_START(i),
  196. NVVAL(NVC37D, HEAD_SET_RASTER_BLANK_START, X, m->h.blanks) |
  197. NVVAL(NVC37D, HEAD_SET_RASTER_BLANK_START, Y, m->v.blanks));
  198. //XXX:
  199. PUSH_NVSQ(push, NVC37D, 0x2074 + (i * 0x400), m->v.blank2e << 16 | m->v.blank2s);
  200. PUSH_NVSQ(push, NVC37D, 0x2008 + (i * 0x400), m->interlace);
  201. PUSH_MTHD(push, NVC37D, HEAD_SET_PIXEL_CLOCK_FREQUENCY(i),
  202. NVVAL(NVC37D, HEAD_SET_PIXEL_CLOCK_FREQUENCY, HERTZ, m->clock * 1000));
  203. PUSH_MTHD(push, NVC37D, HEAD_SET_PIXEL_CLOCK_FREQUENCY_MAX(i),
  204. NVVAL(NVC37D, HEAD_SET_PIXEL_CLOCK_FREQUENCY_MAX, HERTZ, m->clock * 1000));
  205. /*XXX: HEAD_USAGE_BOUNDS, doesn't belong here. */
  206. PUSH_MTHD(push, NVC37D, HEAD_SET_HEAD_USAGE_BOUNDS(i),
  207. NVDEF(NVC37D, HEAD_SET_HEAD_USAGE_BOUNDS, CURSOR, USAGE_W256_H256) |
  208. NVDEF(NVC37D, HEAD_SET_HEAD_USAGE_BOUNDS, OUTPUT_LUT, USAGE_1025) |
  209. NVDEF(NVC37D, HEAD_SET_HEAD_USAGE_BOUNDS, UPSCALING_ALLOWED, TRUE));
  210. return 0;
  211. }
  212. int
  213. headc37d_view(struct nv50_head *head, struct nv50_head_atom *asyh)
  214. {
  215. struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
  216. const int i = head->base.index;
  217. int ret;
  218. if ((ret = PUSH_WAIT(push, 4)))
  219. return ret;
  220. PUSH_MTHD(push, NVC37D, HEAD_SET_VIEWPORT_SIZE_IN(i),
  221. NVVAL(NVC37D, HEAD_SET_VIEWPORT_SIZE_IN, WIDTH, asyh->view.iW) |
  222. NVVAL(NVC37D, HEAD_SET_VIEWPORT_SIZE_IN, HEIGHT, asyh->view.iH));
  223. PUSH_MTHD(push, NVC37D, HEAD_SET_VIEWPORT_SIZE_OUT(i),
  224. NVVAL(NVC37D, HEAD_SET_VIEWPORT_SIZE_OUT, WIDTH, asyh->view.oW) |
  225. NVVAL(NVC37D, HEAD_SET_VIEWPORT_SIZE_OUT, HEIGHT, asyh->view.oH));
  226. return 0;
  227. }
  228. void
  229. headc37d_static_wndw_map(struct nv50_head *head, struct nv50_head_atom *asyh)
  230. {
  231. int i, end;
  232. for (i = head->base.index * 2, end = i + 2; i < end; i++)
  233. asyh->wndw.owned |= BIT(i);
  234. }
  235. const struct nv50_head_func
  236. headc37d = {
  237. .view = headc37d_view,
  238. .mode = headc37d_mode,
  239. .olut = headc37d_olut,
  240. .ilut_check = head907d_ilut_check,
  241. .olut_size = 1024,
  242. .olut_set = headc37d_olut_set,
  243. .olut_clr = headc37d_olut_clr,
  244. .curs_layout = head917d_curs_layout,
  245. .curs_format = headc37d_curs_format,
  246. .curs_set = headc37d_curs_set,
  247. .curs_clr = headc37d_curs_clr,
  248. .dither = headc37d_dither,
  249. .procamp = headc37d_procamp,
  250. .or = headc37d_or,
  251. .static_wndw_map = headc37d_static_wndw_map,
  252. };