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 nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
65 if ((push = evo_wait(core, 2))) {
66 evo_mthd(push, 0x2000 + (head->base.index * 0x400), 1);
68 evo_data(push, 0x80000000 |
69 asyh->procamp.sat.sin << 16 |
70 asyh->procamp.sat.cos << 4);
79 headc57d_olut_clr(struct nv50_head *head)
81 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
83 if ((push = evo_wait(core, 2))) {
84 evo_mthd(push, 0x2288 + (head->base.index * 0x400), 1);
85 evo_data(push, 0x00000000);
91 headc57d_olut_set(struct nv50_head *head, struct nv50_head_atom *asyh)
93 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
95 if ((push = evo_wait(core, 4))) {
96 evo_mthd(push, 0x2280 + (head->base.index * 0x400), 4);
97 evo_data(push, asyh->olut.size << 8 |
98 asyh->olut.mode << 2 |
99 asyh->olut.output_mode);
100 evo_data(push, 0xffffffff); /* FP_NORM_SCALE. */
101 evo_data(push, asyh->olut.handle);
102 evo_data(push, asyh->olut.offset >> 8);
103 evo_kick(push, core);
108 headc57d_olut_load_8(struct drm_color_lut *in, int size, void __iomem *mem)
110 memset_io(mem, 0x00, 0x20); /* VSS header. */
114 u16 r = drm_color_lut_extract(in-> red + 0, 16);
115 u16 g = drm_color_lut_extract(in->green + 0, 16);
116 u16 b = drm_color_lut_extract(in-> blue + 0, 16);
117 u16 ri = 0, gi = 0, bi = 0, i;
120 ri = (drm_color_lut_extract(in-> red, 16) - r) / 4;
121 gi = (drm_color_lut_extract(in->green, 16) - g) / 4;
122 bi = (drm_color_lut_extract(in-> blue, 16) - b) / 4;
125 for (i = 0; i < 4; i++, mem += 8) {
126 writew(r + ri * i, mem + 0);
127 writew(g + gi * i, mem + 2);
128 writew(b + bi * i, mem + 4);
132 /* INTERPOLATE modes require a "next" entry to interpolate with,
133 * so we replicate the last entry to deal with this for now.
135 writew(readw(mem - 8), mem + 0);
136 writew(readw(mem - 6), mem + 2);
137 writew(readw(mem - 4), mem + 4);
141 headc57d_olut_load(struct drm_color_lut *in, int size, void __iomem *mem)
143 memset_io(mem, 0x00, 0x20); /* VSS header. */
146 for (; size--; in++, mem += 0x08) {
147 writew(drm_color_lut_extract(in-> red, 16), mem + 0);
148 writew(drm_color_lut_extract(in->green, 16), mem + 2);
149 writew(drm_color_lut_extract(in-> blue, 16), mem + 4);
152 /* INTERPOLATE modes require a "next" entry to interpolate with,
153 * so we replicate the last entry to deal with this for now.
155 writew(readw(mem - 8), mem + 0);
156 writew(readw(mem - 6), mem + 2);
157 writew(readw(mem - 4), mem + 4);
161 headc57d_olut(struct nv50_head *head, struct nv50_head_atom *asyh, int size)
163 if (size != 0 && size != 256 && size != 1024)
166 asyh->olut.mode = 2; /* DIRECT10 */
167 asyh->olut.size = 4 /* VSS header. */ + 1024 + 1 /* Entries. */;
168 asyh->olut.output_mode = 1; /* INTERPOLATE_ENABLE. */
170 asyh->olut.load = headc57d_olut_load_8;
172 asyh->olut.load = headc57d_olut_load;
177 headc57d_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
179 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
180 struct nv50_head_mode *m = &asyh->mode;
181 const int i = head->base.index;
184 if ((ret = PUSH_WAIT(push, 13)))
187 PUSH_NVSQ(push, NVC57D, 0x2064 + (i * 0x400), m->v.active << 16 | m->h.active,
188 0x2068 + (i * 0x400), m->v.synce << 16 | m->h.synce,
189 0x206c + (i * 0x400), m->v.blanke << 16 | m->h.blanke,
190 0x2070 + (i * 0x400), m->v.blanks << 16 | m->h.blanks,
191 0x2074 + (i * 0x400), m->v.blank2e << 16 | m->v.blank2s);
192 PUSH_NVSQ(push, NVC57D, 0x2008 + (i * 0x400), m->interlace,
193 0x200c + (i * 0x400), m->clock * 1000);
194 PUSH_NVSQ(push, NVC57D, 0x2028 + (i * 0x400), m->clock * 1000);
196 /*XXX: HEAD_USAGE_BOUNDS, doesn't belong here. */
197 PUSH_NVSQ(push, NVC57D, 0x2030 + (i * 0x400), 0x00001114);
201 const struct nv50_head_func
203 .view = headc37d_view,
204 .mode = headc57d_mode,
205 .olut = headc57d_olut,
206 .olut_identity = true,
208 .olut_set = headc57d_olut_set,
209 .olut_clr = headc57d_olut_clr,
210 .curs_layout = head917d_curs_layout,
211 .curs_format = headc37d_curs_format,
212 .curs_set = headc37d_curs_set,
213 .curs_clr = headc37d_curs_clr,
214 .dither = headc37d_dither,
215 .procamp = headc57d_procamp,
217 /* TODO: flexible window mappings */
218 .static_wndw_map = headc37d_static_wndw_map,