18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2018 Red Hat Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_ci#include "head.h" 238c2ecf20Sopenharmony_ci#include "core.h" 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#include "nvif/push.h" 268c2ecf20Sopenharmony_ci#include <nvif/push507c.h> 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#include <nvhw/class/cl917d.h> 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistatic int 318c2ecf20Sopenharmony_cihead917d_dither(struct nv50_head *head, struct nv50_head_atom *asyh) 328c2ecf20Sopenharmony_ci{ 338c2ecf20Sopenharmony_ci struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push; 348c2ecf20Sopenharmony_ci const int i = head->base.index; 358c2ecf20Sopenharmony_ci int ret; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci if ((ret = PUSH_WAIT(push, 2))) 388c2ecf20Sopenharmony_ci return ret; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci PUSH_MTHD(push, NV917D, HEAD_SET_DITHER_CONTROL(i), 418c2ecf20Sopenharmony_ci NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, ENABLE, asyh->dither.enable) | 428c2ecf20Sopenharmony_ci NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, BITS, asyh->dither.bits) | 438c2ecf20Sopenharmony_ci NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, MODE, asyh->dither.mode) | 448c2ecf20Sopenharmony_ci NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, PHASE, 0)); 458c2ecf20Sopenharmony_ci return 0; 468c2ecf20Sopenharmony_ci} 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_cistatic int 498c2ecf20Sopenharmony_cihead917d_base(struct nv50_head *head, struct nv50_head_atom *asyh) 508c2ecf20Sopenharmony_ci{ 518c2ecf20Sopenharmony_ci struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push; 528c2ecf20Sopenharmony_ci const int i = head->base.index; 538c2ecf20Sopenharmony_ci u32 bounds = 0; 548c2ecf20Sopenharmony_ci int ret; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci if (asyh->base.cpp) { 578c2ecf20Sopenharmony_ci switch (asyh->base.cpp) { 588c2ecf20Sopenharmony_ci case 8: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_64); break; 598c2ecf20Sopenharmony_ci case 4: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_32); break; 608c2ecf20Sopenharmony_ci case 2: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_16); break; 618c2ecf20Sopenharmony_ci case 1: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_8); break; 628c2ecf20Sopenharmony_ci default: 638c2ecf20Sopenharmony_ci WARN_ON(1); 648c2ecf20Sopenharmony_ci break; 658c2ecf20Sopenharmony_ci } 668c2ecf20Sopenharmony_ci bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, USABLE, TRUE); 678c2ecf20Sopenharmony_ci bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, BASE_LUT, USAGE_1025); 688c2ecf20Sopenharmony_ci } 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci if ((ret = PUSH_WAIT(push, 2))) 718c2ecf20Sopenharmony_ci return ret; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci PUSH_MTHD(push, NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS(i), bounds); 748c2ecf20Sopenharmony_ci return 0; 758c2ecf20Sopenharmony_ci} 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic int 788c2ecf20Sopenharmony_cihead917d_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push; 818c2ecf20Sopenharmony_ci const int i = head->base.index; 828c2ecf20Sopenharmony_ci int ret; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci ret = PUSH_WAIT(push, 5); 858c2ecf20Sopenharmony_ci if (ret) 868c2ecf20Sopenharmony_ci return ret; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci PUSH_MTHD(push, NV917D, HEAD_SET_CONTROL_CURSOR(i), 898c2ecf20Sopenharmony_ci NVDEF(NV917D, HEAD_SET_CONTROL_CURSOR, ENABLE, ENABLE) | 908c2ecf20Sopenharmony_ci NVVAL(NV917D, HEAD_SET_CONTROL_CURSOR, FORMAT, asyh->curs.format) | 918c2ecf20Sopenharmony_ci NVVAL(NV917D, HEAD_SET_CONTROL_CURSOR, SIZE, asyh->curs.layout) | 928c2ecf20Sopenharmony_ci NVVAL(NV917D, HEAD_SET_CONTROL_CURSOR, HOT_SPOT_X, 0) | 938c2ecf20Sopenharmony_ci NVVAL(NV917D, HEAD_SET_CONTROL_CURSOR, HOT_SPOT_Y, 0) | 948c2ecf20Sopenharmony_ci NVDEF(NV917D, HEAD_SET_CONTROL_CURSOR, COMPOSITION, ALPHA_BLEND), 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci HEAD_SET_OFFSET_CURSOR(i), asyh->curs.offset >> 8); 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci PUSH_MTHD(push, NV917D, HEAD_SET_CONTEXT_DMA_CURSOR(i), asyh->curs.handle); 998c2ecf20Sopenharmony_ci return 0; 1008c2ecf20Sopenharmony_ci} 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ciint 1038c2ecf20Sopenharmony_cihead917d_curs_layout(struct nv50_head *head, struct nv50_wndw_atom *asyw, 1048c2ecf20Sopenharmony_ci struct nv50_head_atom *asyh) 1058c2ecf20Sopenharmony_ci{ 1068c2ecf20Sopenharmony_ci switch (asyw->state.fb->width) { 1078c2ecf20Sopenharmony_ci case 32: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W32_H32; break; 1088c2ecf20Sopenharmony_ci case 64: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W64_H64; break; 1098c2ecf20Sopenharmony_ci case 128: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W128_H128; break; 1108c2ecf20Sopenharmony_ci case 256: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W256_H256; break; 1118c2ecf20Sopenharmony_ci default: 1128c2ecf20Sopenharmony_ci return -EINVAL; 1138c2ecf20Sopenharmony_ci } 1148c2ecf20Sopenharmony_ci return 0; 1158c2ecf20Sopenharmony_ci} 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ciconst struct nv50_head_func 1188c2ecf20Sopenharmony_cihead917d = { 1198c2ecf20Sopenharmony_ci .view = head907d_view, 1208c2ecf20Sopenharmony_ci .mode = head907d_mode, 1218c2ecf20Sopenharmony_ci .olut = head907d_olut, 1228c2ecf20Sopenharmony_ci .olut_size = 1024, 1238c2ecf20Sopenharmony_ci .olut_set = head907d_olut_set, 1248c2ecf20Sopenharmony_ci .olut_clr = head907d_olut_clr, 1258c2ecf20Sopenharmony_ci .core_calc = head507d_core_calc, 1268c2ecf20Sopenharmony_ci .core_set = head907d_core_set, 1278c2ecf20Sopenharmony_ci .core_clr = head907d_core_clr, 1288c2ecf20Sopenharmony_ci .curs_layout = head917d_curs_layout, 1298c2ecf20Sopenharmony_ci .curs_format = head507d_curs_format, 1308c2ecf20Sopenharmony_ci .curs_set = head917d_curs_set, 1318c2ecf20Sopenharmony_ci .curs_clr = head907d_curs_clr, 1328c2ecf20Sopenharmony_ci .base = head917d_base, 1338c2ecf20Sopenharmony_ci .ovly = head907d_ovly, 1348c2ecf20Sopenharmony_ci .dither = head917d_dither, 1358c2ecf20Sopenharmony_ci .procamp = head907d_procamp, 1368c2ecf20Sopenharmony_ci .or = head907d_or, 1378c2ecf20Sopenharmony_ci}; 138