109e1b78aSBen Skeggs /* 209e1b78aSBen Skeggs * Copyright 2018 Red Hat Inc. 309e1b78aSBen Skeggs * 409e1b78aSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a 509e1b78aSBen Skeggs * copy of this software and associated documentation files (the "Software"), 609e1b78aSBen Skeggs * to deal in the Software without restriction, including without limitation 709e1b78aSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense, 809e1b78aSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the 909e1b78aSBen Skeggs * Software is furnished to do so, subject to the following conditions: 1009e1b78aSBen Skeggs * 1109e1b78aSBen Skeggs * The above copyright notice and this permission notice shall be included in 1209e1b78aSBen Skeggs * all copies or substantial portions of the Software. 1309e1b78aSBen Skeggs * 1409e1b78aSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1509e1b78aSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1609e1b78aSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1709e1b78aSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 1809e1b78aSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 1909e1b78aSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2009e1b78aSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE. 2109e1b78aSBen Skeggs */ 2209e1b78aSBen Skeggs #include "head.h" 2309e1b78aSBen Skeggs #include "core.h" 2409e1b78aSBen Skeggs 25*ba839b75SLyude Paul #include "nvif/push.h" 2693f7f054SBen Skeggs #include <nvif/push507c.h> 2793f7f054SBen Skeggs 28ed0b86a9SBen Skeggs #include <nvhw/class/cl917d.h> 29ed0b86a9SBen Skeggs 302f819f2bSBen Skeggs static int 3109e1b78aSBen Skeggs head917d_dither(struct nv50_head *head, struct nv50_head_atom *asyh) 3209e1b78aSBen Skeggs { 332f819f2bSBen Skeggs struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push; 342f819f2bSBen Skeggs const int i = head->base.index; 352f819f2bSBen Skeggs int ret; 362f819f2bSBen Skeggs 372f819f2bSBen Skeggs if ((ret = PUSH_WAIT(push, 2))) 382f819f2bSBen Skeggs return ret; 392f819f2bSBen Skeggs 40f801efb1SBen Skeggs PUSH_MTHD(push, NV917D, HEAD_SET_DITHER_CONTROL(i), 41f801efb1SBen Skeggs NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, ENABLE, asyh->dither.enable) | 42f801efb1SBen Skeggs NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, BITS, asyh->dither.bits) | 43f801efb1SBen Skeggs NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, MODE, asyh->dither.mode) | 44f801efb1SBen Skeggs NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, PHASE, 0)); 452f819f2bSBen Skeggs return 0; 4609e1b78aSBen Skeggs } 4709e1b78aSBen Skeggs 4893f7f054SBen Skeggs static int 49119608a7SBen Skeggs head917d_base(struct nv50_head *head, struct nv50_head_atom *asyh) 50119608a7SBen Skeggs { 5193f7f054SBen Skeggs struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push; 5293f7f054SBen Skeggs const int i = head->base.index; 53119608a7SBen Skeggs u32 bounds = 0; 5493f7f054SBen Skeggs int ret; 55119608a7SBen Skeggs 56119608a7SBen Skeggs if (asyh->base.cpp) { 57119608a7SBen Skeggs switch (asyh->base.cpp) { 582aa934caSBen Skeggs case 8: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_64); break; 592aa934caSBen Skeggs case 4: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_32); break; 602aa934caSBen Skeggs case 2: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_16); break; 612aa934caSBen Skeggs case 1: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_8); break; 62119608a7SBen Skeggs default: 63119608a7SBen Skeggs WARN_ON(1); 64119608a7SBen Skeggs break; 65119608a7SBen Skeggs } 662aa934caSBen Skeggs bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, USABLE, TRUE); 672aa934caSBen Skeggs bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, BASE_LUT, USAGE_1025); 68119608a7SBen Skeggs } 69119608a7SBen Skeggs 7093f7f054SBen Skeggs if ((ret = PUSH_WAIT(push, 2))) 7193f7f054SBen Skeggs return ret; 7293f7f054SBen Skeggs 732aa934caSBen Skeggs PUSH_MTHD(push, NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS(i), bounds); 7493f7f054SBen Skeggs return 0; 75119608a7SBen Skeggs } 76119608a7SBen Skeggs 77*ba839b75SLyude Paul static int 78*ba839b75SLyude Paul head917d_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh) 79*ba839b75SLyude Paul { 80*ba839b75SLyude Paul struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push; 81*ba839b75SLyude Paul const int i = head->base.index; 82*ba839b75SLyude Paul int ret; 83*ba839b75SLyude Paul 84*ba839b75SLyude Paul ret = PUSH_WAIT(push, 5); 85*ba839b75SLyude Paul if (ret) 86*ba839b75SLyude Paul return ret; 87*ba839b75SLyude Paul 88*ba839b75SLyude Paul PUSH_MTHD(push, NV917D, HEAD_SET_CONTROL_CURSOR(i), 89*ba839b75SLyude Paul NVDEF(NV917D, HEAD_SET_CONTROL_CURSOR, ENABLE, ENABLE) | 90*ba839b75SLyude Paul NVVAL(NV917D, HEAD_SET_CONTROL_CURSOR, FORMAT, asyh->curs.format) | 91*ba839b75SLyude Paul NVVAL(NV917D, HEAD_SET_CONTROL_CURSOR, SIZE, asyh->curs.layout) | 92*ba839b75SLyude Paul NVVAL(NV917D, HEAD_SET_CONTROL_CURSOR, HOT_SPOT_X, 0) | 93*ba839b75SLyude Paul NVVAL(NV917D, HEAD_SET_CONTROL_CURSOR, HOT_SPOT_Y, 0) | 94*ba839b75SLyude Paul NVDEF(NV917D, HEAD_SET_CONTROL_CURSOR, COMPOSITION, ALPHA_BLEND), 95*ba839b75SLyude Paul 96*ba839b75SLyude Paul HEAD_SET_OFFSET_CURSOR(i), asyh->curs.offset >> 8); 97*ba839b75SLyude Paul 98*ba839b75SLyude Paul PUSH_MTHD(push, NV917D, HEAD_SET_CONTEXT_DMA_CURSOR(i), asyh->curs.handle); 99*ba839b75SLyude Paul return 0; 100*ba839b75SLyude Paul } 101*ba839b75SLyude Paul 102facaed62SBen Skeggs int 10301d380abSBen Skeggs head917d_curs_layout(struct nv50_head *head, struct nv50_wndw_atom *asyw, 10401d380abSBen Skeggs struct nv50_head_atom *asyh) 10501d380abSBen Skeggs { 10601d380abSBen Skeggs switch (asyw->state.fb->width) { 107ed0b86a9SBen Skeggs case 32: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W32_H32; break; 108ed0b86a9SBen Skeggs case 64: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W64_H64; break; 109ed0b86a9SBen Skeggs case 128: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W128_H128; break; 110ed0b86a9SBen Skeggs case 256: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W256_H256; break; 11101d380abSBen Skeggs default: 11201d380abSBen Skeggs return -EINVAL; 11301d380abSBen Skeggs } 11401d380abSBen Skeggs return 0; 11501d380abSBen Skeggs } 11601d380abSBen Skeggs 11709e1b78aSBen Skeggs const struct nv50_head_func 11809e1b78aSBen Skeggs head917d = { 11909e1b78aSBen Skeggs .view = head907d_view, 12009e1b78aSBen Skeggs .mode = head907d_mode, 121119608a7SBen Skeggs .olut = head907d_olut, 12213199270SIlia Mirkin .olut_size = 1024, 123119608a7SBen Skeggs .olut_set = head907d_olut_set, 124119608a7SBen Skeggs .olut_clr = head907d_olut_clr, 12509e1b78aSBen Skeggs .core_calc = head507d_core_calc, 12609e1b78aSBen Skeggs .core_set = head907d_core_set, 12709e1b78aSBen Skeggs .core_clr = head907d_core_clr, 12801d380abSBen Skeggs .curs_layout = head917d_curs_layout, 12901d380abSBen Skeggs .curs_format = head507d_curs_format, 130*ba839b75SLyude Paul .curs_set = head917d_curs_set, 13109e1b78aSBen Skeggs .curs_clr = head907d_curs_clr, 132119608a7SBen Skeggs .base = head917d_base, 13309e1b78aSBen Skeggs .ovly = head907d_ovly, 13409e1b78aSBen Skeggs .dither = head917d_dither, 13509e1b78aSBen Skeggs .procamp = head907d_procamp, 13609e1b78aSBen Skeggs .or = head907d_or, 13709e1b78aSBen Skeggs }; 138