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_color_mgmt.h>
26 #include <drm/drm_mode.h>
27 #include <drm/drm_property.h>
29 #include <nvif/class.h>
32 nv50_lut_load(struct nv50_lut *lut, bool legacy, int buffer,
33 struct drm_property_blob *blob)
35 struct drm_color_lut *in = (struct drm_color_lut *)blob->data;
36 void __iomem *mem = lut->mem[buffer].object.map.ptr;
37 const int size = blob->length / sizeof(*in);
40 u32 addr = lut->mem[buffer].addr;
42 /* This can't happen.. But it shuts the compiler up. */
43 if (WARN_ON(size != 256))
56 for (i = 0; i < size; i++) {
57 r = (drm_color_lut_extract(in[i]. red, bits) + zero) << shift;
58 g = (drm_color_lut_extract(in[i].green, bits) + zero) << shift;
59 b = (drm_color_lut_extract(in[i]. blue, bits) + zero) << shift;
60 writew(r, mem + (i * 0x08) + 0);
61 writew(g, mem + (i * 0x08) + 2);
62 writew(b, mem + (i * 0x08) + 4);
65 /* INTERPOLATE modes require a "next" entry to interpolate with,
66 * so we replicate the last entry to deal with this for now.
68 writew(r, mem + (i * 0x08) + 0);
69 writew(g, mem + (i * 0x08) + 2);
70 writew(b, mem + (i * 0x08) + 4);
75 nv50_lut_fini(struct nv50_lut *lut)
78 for (i = 0; i < ARRAY_SIZE(lut->mem); i++)
79 nvif_mem_fini(&lut->mem[i]);
83 nv50_lut_init(struct nv50_disp *disp, struct nvif_mmu *mmu,
86 const u32 size = disp->disp->object.oclass < GF110_DISP ? 257 : 1025;
88 for (i = 0; i < ARRAY_SIZE(lut->mem); i++) {
89 int ret = nvif_mem_init_map(mmu, NVIF_MEM_VRAM, size * 8,