2 * Copyright 2018 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
26 #include <nvif/pushc37b.h>
29 headc57d_or(struct nv50_head *head, struct nv50_head_atom *asyh)
31 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
35 if ((push = evo_wait(core, 2))) {
36 /*XXX: This is a dirty hack until OR depth handling is
37 * improved later for deep colour etc.
39 switch (asyh->or.depth) {
40 case 6: depth = 5; break;
41 case 5: depth = 4; break;
42 case 2: depth = 1; break;
43 case 0: depth = 4; break;
45 depth = asyh->or.depth;
50 evo_mthd(push, 0x2004 + (head->base.index * 0x400), 1);
51 evo_data(push, 0xfc000000 |
53 asyh->or.nvsync << 3 |
54 asyh->or.nhsync << 2 |
61 headc57d_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
63 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
64 const int i = head->base.index;
67 if ((ret = PUSH_WAIT(push, 2)))
71 PUSH_NVSQ(push, NVC57D, 0x2000 + (i * 0x400), 0x00000000);
76 headc57d_olut_clr(struct nv50_head *head)
78 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
79 const int i = head->base.index;
82 if ((ret = PUSH_WAIT(push, 2)))
85 PUSH_NVSQ(push, NVC57D, 0x2288 + (i * 0x400), 0x00000000);
90 headc57d_olut_set(struct nv50_head *head, struct nv50_head_atom *asyh)
92 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
93 const int i = head->base.index;
96 if ((ret = PUSH_WAIT(push, 5)))
99 PUSH_NVSQ(push, NVC57D, 0x2280 + (i * 0x400), asyh->olut.size << 8 |
100 asyh->olut.mode << 2 |
101 asyh->olut.output_mode,
102 0x2284 + (i * 0x400), 0xffffffff,
103 0x2288 + (i * 0x400), asyh->olut.handle,
104 0x228c + (i * 0x400), asyh->olut.offset >> 8);
109 headc57d_olut_load_8(struct drm_color_lut *in, int size, void __iomem *mem)
111 memset_io(mem, 0x00, 0x20); /* VSS header. */
115 u16 r = drm_color_lut_extract(in-> red + 0, 16);
116 u16 g = drm_color_lut_extract(in->green + 0, 16);
117 u16 b = drm_color_lut_extract(in-> blue + 0, 16);
118 u16 ri = 0, gi = 0, bi = 0, i;
121 ri = (drm_color_lut_extract(in-> red, 16) - r) / 4;
122 gi = (drm_color_lut_extract(in->green, 16) - g) / 4;
123 bi = (drm_color_lut_extract(in-> blue, 16) - b) / 4;
126 for (i = 0; i < 4; i++, mem += 8) {
127 writew(r + ri * i, mem + 0);
128 writew(g + gi * i, mem + 2);
129 writew(b + bi * i, mem + 4);
133 /* INTERPOLATE modes require a "next" entry to interpolate with,
134 * so we replicate the last entry to deal with this for now.
136 writew(readw(mem - 8), mem + 0);
137 writew(readw(mem - 6), mem + 2);
138 writew(readw(mem - 4), mem + 4);
142 headc57d_olut_load(struct drm_color_lut *in, int size, void __iomem *mem)
144 memset_io(mem, 0x00, 0x20); /* VSS header. */
147 for (; size--; in++, mem += 0x08) {
148 writew(drm_color_lut_extract(in-> red, 16), mem + 0);
149 writew(drm_color_lut_extract(in->green, 16), mem + 2);
150 writew(drm_color_lut_extract(in-> blue, 16), mem + 4);
153 /* INTERPOLATE modes require a "next" entry to interpolate with,
154 * so we replicate the last entry to deal with this for now.
156 writew(readw(mem - 8), mem + 0);
157 writew(readw(mem - 6), mem + 2);
158 writew(readw(mem - 4), mem + 4);
162 headc57d_olut(struct nv50_head *head, struct nv50_head_atom *asyh, int size)
164 if (size != 0 && size != 256 && size != 1024)
167 asyh->olut.mode = 2; /* DIRECT10 */
168 asyh->olut.size = 4 /* VSS header. */ + 1024 + 1 /* Entries. */;
169 asyh->olut.output_mode = 1; /* INTERPOLATE_ENABLE. */
171 asyh->olut.load = headc57d_olut_load_8;
173 asyh->olut.load = headc57d_olut_load;
178 headc57d_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
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;
185 if ((ret = PUSH_WAIT(push, 13)))
188 PUSH_NVSQ(push, NVC57D, 0x2064 + (i * 0x400), m->v.active << 16 | m->h.active,
189 0x2068 + (i * 0x400), m->v.synce << 16 | m->h.synce,
190 0x206c + (i * 0x400), m->v.blanke << 16 | m->h.blanke,
191 0x2070 + (i * 0x400), m->v.blanks << 16 | m->h.blanks,
192 0x2074 + (i * 0x400), m->v.blank2e << 16 | m->v.blank2s);
193 PUSH_NVSQ(push, NVC57D, 0x2008 + (i * 0x400), m->interlace,
194 0x200c + (i * 0x400), m->clock * 1000);
195 PUSH_NVSQ(push, NVC57D, 0x2028 + (i * 0x400), m->clock * 1000);
197 /*XXX: HEAD_USAGE_BOUNDS, doesn't belong here. */
198 PUSH_NVSQ(push, NVC57D, 0x2030 + (i * 0x400), 0x00001114);
202 const struct nv50_head_func
204 .view = headc37d_view,
205 .mode = headc57d_mode,
206 .olut = headc57d_olut,
207 .olut_identity = true,
209 .olut_set = headc57d_olut_set,
210 .olut_clr = headc57d_olut_clr,
211 .curs_layout = head917d_curs_layout,
212 .curs_format = headc37d_curs_format,
213 .curs_set = headc37d_curs_set,
214 .curs_clr = headc37d_curs_clr,
215 .dither = headc37d_dither,
216 .procamp = headc57d_procamp,
218 /* TODO: flexible window mappings */
219 .static_wndw_map = headc37d_static_wndw_map,