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 25 #include <nvif/push507c.h> 26 27 #include <nvhw/class/cl917d.h> 28 29 static int 30 head917d_dither(struct nv50_head *head, struct nv50_head_atom *asyh) 31 { 32 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push; 33 const int i = head->base.index; 34 int ret; 35 36 if ((ret = PUSH_WAIT(push, 2))) 37 return ret; 38 39 PUSH_NVSQ(push, NV917D, 0x04a0 + (i * 0x300), asyh->dither.mode << 3 | 40 asyh->dither.bits << 1 | 41 asyh->dither.enable); 42 return 0; 43 } 44 45 static int 46 head917d_base(struct nv50_head *head, struct nv50_head_atom *asyh) 47 { 48 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push; 49 const int i = head->base.index; 50 u32 bounds = 0; 51 int ret; 52 53 if (asyh->base.cpp) { 54 switch (asyh->base.cpp) { 55 case 8: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_64); break; 56 case 4: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_32); break; 57 case 2: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_16); break; 58 case 1: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_8); break; 59 default: 60 WARN_ON(1); 61 break; 62 } 63 bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, USABLE, TRUE); 64 bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, BASE_LUT, USAGE_1025); 65 } 66 67 if ((ret = PUSH_WAIT(push, 2))) 68 return ret; 69 70 PUSH_MTHD(push, NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS(i), bounds); 71 return 0; 72 } 73 74 int 75 head917d_curs_layout(struct nv50_head *head, struct nv50_wndw_atom *asyw, 76 struct nv50_head_atom *asyh) 77 { 78 switch (asyw->state.fb->width) { 79 case 32: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W32_H32; break; 80 case 64: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W64_H64; break; 81 case 128: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W128_H128; break; 82 case 256: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W256_H256; break; 83 default: 84 return -EINVAL; 85 } 86 return 0; 87 } 88 89 const struct nv50_head_func 90 head917d = { 91 .view = head907d_view, 92 .mode = head907d_mode, 93 .olut = head907d_olut, 94 .olut_size = 1024, 95 .olut_set = head907d_olut_set, 96 .olut_clr = head907d_olut_clr, 97 .core_calc = head507d_core_calc, 98 .core_set = head907d_core_set, 99 .core_clr = head907d_core_clr, 100 .curs_layout = head917d_curs_layout, 101 .curs_format = head507d_curs_format, 102 .curs_set = head907d_curs_set, 103 .curs_clr = head907d_curs_clr, 104 .base = head917d_base, 105 .ovly = head907d_ovly, 106 .dither = head917d_dither, 107 .procamp = head907d_procamp, 108 .or = head907d_or, 109 }; 110