drm/nouveau/kms/nv50-: convert core head_procamp() to new push macros
[sfrench/cifs-2.6.git] / drivers / gpu / drm / nouveau / dispnv50 / headc57d.c
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 "atom.h"
24 #include "core.h"
25
26 #include <nvif/pushc37b.h>
27
28 static void
29 headc57d_or(struct nv50_head *head, struct nv50_head_atom *asyh)
30 {
31         struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
32         u8 depth;
33         u32 *push;
34
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.
38                  */
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;
44                 default:
45                         depth = asyh->or.depth;
46                         WARN_ON(1);
47                         break;
48                 }
49
50                 evo_mthd(push, 0x2004 + (head->base.index * 0x400), 1);
51                 evo_data(push, 0xfc000000 |
52                                depth << 4 |
53                                asyh->or.nvsync << 3 |
54                                asyh->or.nhsync << 2 |
55                                asyh->or.crc_raster);
56                 evo_kick(push, core);
57         }
58 }
59
60 static int
61 headc57d_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
62 {
63         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
64         const int i = head->base.index;
65         int ret;
66
67         if ((ret = PUSH_WAIT(push, 2)))
68                 return ret;
69
70         //TODO:
71         PUSH_NVSQ(push, NVC57D, 0x2000 + (i * 0x400), 0x00000000);
72         return 0;
73 }
74
75 static int
76 headc57d_olut_clr(struct nv50_head *head)
77 {
78         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
79         const int i = head->base.index;
80         int ret;
81
82         if ((ret = PUSH_WAIT(push, 2)))
83                 return ret;
84
85         PUSH_NVSQ(push, NVC57D, 0x2288 + (i * 0x400), 0x00000000);
86         return 0;
87 }
88
89 static int
90 headc57d_olut_set(struct nv50_head *head, struct nv50_head_atom *asyh)
91 {
92         struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
93         const int i = head->base.index;
94         int ret;
95
96         if ((ret = PUSH_WAIT(push, 5)))
97                 return ret;
98
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);
105         return 0;
106 }
107
108 static void
109 headc57d_olut_load_8(struct drm_color_lut *in, int size, void __iomem *mem)
110 {
111         memset_io(mem, 0x00, 0x20); /* VSS header. */
112         mem += 0x20;
113
114         while (size--) {
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;
119
120                 if (in++, size) {
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;
124                 }
125
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);
130                 }
131         }
132
133         /* INTERPOLATE modes require a "next" entry to interpolate with,
134          * so we replicate the last entry to deal with this for now.
135          */
136         writew(readw(mem - 8), mem + 0);
137         writew(readw(mem - 6), mem + 2);
138         writew(readw(mem - 4), mem + 4);
139 }
140
141 static void
142 headc57d_olut_load(struct drm_color_lut *in, int size, void __iomem *mem)
143 {
144         memset_io(mem, 0x00, 0x20); /* VSS header. */
145         mem += 0x20;
146
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);
151         }
152
153         /* INTERPOLATE modes require a "next" entry to interpolate with,
154          * so we replicate the last entry to deal with this for now.
155          */
156         writew(readw(mem - 8), mem + 0);
157         writew(readw(mem - 6), mem + 2);
158         writew(readw(mem - 4), mem + 4);
159 }
160
161 bool
162 headc57d_olut(struct nv50_head *head, struct nv50_head_atom *asyh, int size)
163 {
164         if (size != 0 && size != 256 && size != 1024)
165                 return false;
166
167         asyh->olut.mode = 2; /* DIRECT10 */
168         asyh->olut.size = 4 /* VSS header. */ + 1024 + 1 /* Entries. */;
169         asyh->olut.output_mode = 1; /* INTERPOLATE_ENABLE. */
170         if (size == 256)
171                 asyh->olut.load = headc57d_olut_load_8;
172         else
173                 asyh->olut.load = headc57d_olut_load;
174         return true;
175 }
176
177 static int
178 headc57d_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
179 {
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;
183         int ret;
184
185         if ((ret = PUSH_WAIT(push, 13)))
186                 return ret;
187
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);
196
197         /*XXX: HEAD_USAGE_BOUNDS, doesn't belong here. */
198         PUSH_NVSQ(push, NVC57D, 0x2030 + (i * 0x400), 0x00001114);
199         return 0;
200 }
201
202 const struct nv50_head_func
203 headc57d = {
204         .view = headc37d_view,
205         .mode = headc57d_mode,
206         .olut = headc57d_olut,
207         .olut_identity = true,
208         .olut_size = 1024,
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,
217         .or = headc57d_or,
218         /* TODO: flexible window mappings */
219         .static_wndw_map = headc37d_static_wndw_map,
220 };