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.
25 #include <drm/drm_atomic_helper.h>
26 #include <drm/drm_plane_helper.h>
27 #include <nouveau_bo.h>
29 #include <nvif/clc37e.h>
32 wndwc57e_ilut_clr(struct nv50_wndw *wndw)
35 if ((push = evo_wait(&wndw->wndw, 2))) {
36 evo_mthd(push, 0x0444, 1);
37 evo_data(push, 0x00000000);
38 evo_kick(push, &wndw->wndw);
43 wndwc57e_ilut_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
46 if ((push = evo_wait(&wndw->wndw, 4))) {
47 evo_mthd(push, 0x0440, 3);
48 evo_data(push, asyw->xlut.i.size << 8 |
49 asyw->xlut.i.mode << 2 |
50 asyw->xlut.i.output_mode);
51 evo_data(push, asyw->xlut.handle);
52 evo_data(push, asyw->xlut.i.offset >> 8);
53 evo_kick(push, &wndw->wndw);
58 fixedU0_16_FP16(u16 fixed)
60 int sign = 0, exp = 0, man = 0;
62 while (--exp && !(fixed & 0x8000))
64 man = ((fixed << 1) & 0xffc0) >> 6;
67 return (sign << 15) | (exp << 10) | man;
71 wndwc57e_ilut_load(struct drm_color_lut *in, int size, void __iomem *mem)
73 memset_io(mem, 0x00, 0x20); /* VSS header. */
76 for (; size--; in++, mem += 0x08) {
77 u16 r = fixedU0_16_FP16(drm_color_lut_extract(in-> red, 16));
78 u16 g = fixedU0_16_FP16(drm_color_lut_extract(in->green, 16));
79 u16 b = fixedU0_16_FP16(drm_color_lut_extract(in-> blue, 16));
85 /* INTERPOLATE modes require a "next" entry to interpolate with,
86 * so we replicate the last entry to deal with this for now.
88 writew(readw(mem - 8), mem + 0);
89 writew(readw(mem - 6), mem + 2);
90 writew(readw(mem - 4), mem + 4);
94 wndwc57e_ilut(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
96 u16 size = asyw->ilut->length / sizeof(struct drm_color_lut);
98 asyw->xlut.i.mode = 1; /* DIRECT8. */
100 asyw->xlut.i.mode = 2; /* DIRECT10. */
103 asyw->xlut.i.size = 4 /* VSS header. */ + size + 1 /* Entries. */;
104 asyw->xlut.i.output_mode = 0; /* INTERPOLATE_DISABLE. */
105 asyw->xlut.i.load = wndwc57e_ilut_load;
108 static const struct nv50_wndw_func
110 .acquire = wndwc37e_acquire,
111 .release = wndwc37e_release,
112 .sema_set = wndwc37e_sema_set,
113 .sema_clr = wndwc37e_sema_clr,
114 .ntfy_set = wndwc37e_ntfy_set,
115 .ntfy_clr = wndwc37e_ntfy_clr,
116 .ntfy_reset = corec37d_ntfy_init,
117 .ntfy_wait_begun = base507c_ntfy_wait_begun,
118 .ilut = wndwc57e_ilut,
119 .ilut_identity = true,
120 .xlut_set = wndwc57e_ilut_set,
121 .xlut_clr = wndwc57e_ilut_clr,
122 .image_set = wndwc37e_image_set,
123 .image_clr = wndwc37e_image_clr,
124 .update = wndwc37e_update,
128 wndwc57e_new(struct nouveau_drm *drm, enum drm_plane_type type, int index,
129 s32 oclass, struct nv50_wndw **pwndw)
131 return wndwc37e_new_(&wndwc57e, drm, type, index, oclass,
132 BIT(index >> 1), pwndw);