1024436650c2a88a79685decadc02f4de16b6001
[linux-2.6-microblaze.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 void
61 headc57d_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
62 {
63         struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
64         u32 *push;
65         if ((push = evo_wait(core, 2))) {
66                 evo_mthd(push, 0x2000 + (head->base.index * 0x400), 1);
67 #if 0
68                 evo_data(push, 0x80000000 |
69                                asyh->procamp.sat.sin << 16 |
70                                asyh->procamp.sat.cos << 4);
71 #else
72                 evo_data(push, 0);
73 #endif
74                 evo_kick(push, core);
75         }
76 }
77
78 void
79 headc57d_olut_clr(struct nv50_head *head)
80 {
81         struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
82         u32 *push;
83         if ((push = evo_wait(core, 2))) {
84                 evo_mthd(push, 0x2288 + (head->base.index * 0x400), 1);
85                 evo_data(push, 0x00000000);
86                 evo_kick(push, core);
87         }
88 }
89
90 void
91 headc57d_olut_set(struct nv50_head *head, struct nv50_head_atom *asyh)
92 {
93         struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
94         u32 *push;
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);
104         }
105 }
106
107 static void
108 headc57d_olut_load_8(struct drm_color_lut *in, int size, void __iomem *mem)
109 {
110         memset_io(mem, 0x00, 0x20); /* VSS header. */
111         mem += 0x20;
112
113         while (size--) {
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;
118
119                 if (in++, size) {
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;
123                 }
124
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);
129                 }
130         }
131
132         /* INTERPOLATE modes require a "next" entry to interpolate with,
133          * so we replicate the last entry to deal with this for now.
134          */
135         writew(readw(mem - 8), mem + 0);
136         writew(readw(mem - 6), mem + 2);
137         writew(readw(mem - 4), mem + 4);
138 }
139
140 static void
141 headc57d_olut_load(struct drm_color_lut *in, int size, void __iomem *mem)
142 {
143         memset_io(mem, 0x00, 0x20); /* VSS header. */
144         mem += 0x20;
145
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);
150         }
151
152         /* INTERPOLATE modes require a "next" entry to interpolate with,
153          * so we replicate the last entry to deal with this for now.
154          */
155         writew(readw(mem - 8), mem + 0);
156         writew(readw(mem - 6), mem + 2);
157         writew(readw(mem - 4), mem + 4);
158 }
159
160 bool
161 headc57d_olut(struct nv50_head *head, struct nv50_head_atom *asyh, int size)
162 {
163         if (size != 0 && size != 256 && size != 1024)
164                 return false;
165
166         asyh->olut.mode = 2; /* DIRECT10 */
167         asyh->olut.size = 4 /* VSS header. */ + 1024 + 1 /* Entries. */;
168         asyh->olut.output_mode = 1; /* INTERPOLATE_ENABLE. */
169         if (size == 256)
170                 asyh->olut.load = headc57d_olut_load_8;
171         else
172                 asyh->olut.load = headc57d_olut_load;
173         return true;
174 }
175
176 static int
177 headc57d_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
178 {
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;
182         int ret;
183
184         if ((ret = PUSH_WAIT(push, 13)))
185                 return ret;
186
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);
195
196         /*XXX: HEAD_USAGE_BOUNDS, doesn't belong here. */
197         PUSH_NVSQ(push, NVC57D, 0x2030 + (i * 0x400), 0x00001114);
198         return 0;
199 }
200
201 const struct nv50_head_func
202 headc57d = {
203         .view = headc37d_view,
204         .mode = headc57d_mode,
205         .olut = headc57d_olut,
206         .olut_identity = true,
207         .olut_size = 1024,
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,
216         .or = headc57d_or,
217         /* TODO: flexible window mappings */
218         .static_wndw_map = headc37d_static_wndw_map,
219 };