lut.c (c74a7469f97c0f40b46e82ee979f9fb1bb6e847c) lut.c (cb55cd0c66a16fd965a44e2634755b060dc64bd7)
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

--- 15 unchanged lines hidden (view full) ---

24
25#include <drm/drm_color_mgmt.h>
26#include <drm/drm_mode.h>
27#include <drm/drm_property.h>
28
29#include <nvif/class.h>
30
31u32
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

--- 15 unchanged lines hidden (view full) ---

24
25#include <drm/drm_color_mgmt.h>
26#include <drm/drm_mode.h>
27#include <drm/drm_property.h>
28
29#include <nvif/class.h>
30
31u32
32nv50_lut_load(struct nv50_lut *lut, bool legacy, int buffer,
33 struct drm_property_blob *blob)
32nv50_lut_load(struct nv50_lut *lut, int buffer, struct drm_property_blob *blob,
33 void (*load)(struct drm_color_lut *, int, void __iomem *))
34{
34{
35 struct drm_color_lut *in = (struct drm_color_lut *)blob->data;
35 struct drm_color_lut *in = blob ? blob->data : NULL;
36 void __iomem *mem = lut->mem[buffer].object.map.ptr;
36 void __iomem *mem = lut->mem[buffer].object.map.ptr;
37 const int size = blob->length / sizeof(*in);
38 int bits, shift, i;
39 u16 zero, r, g, b;
40 u32 addr = lut->mem[buffer].addr;
37 const u32 addr = lut->mem[buffer].addr;
38 int i;
41
39
42 /* This can't happen.. But it shuts the compiler up. */
43 if (WARN_ON(size != 256))
44 return 0;
45
46 if (legacy) {
47 bits = 11;
48 shift = 3;
49 zero = 0x0000;
40 if (!in) {
41 in = kvmalloc_array(1024, sizeof(*in), GFP_KERNEL);
42 if (!WARN_ON(!in)) {
43 for (i = 0; i < 1024; i++) {
44 in[i].red =
45 in[i].green =
46 in[i].blue = (i << 16) >> 10;
47 }
48 load(in, 1024, mem);
49 kvfree(in);
50 }
50 } else {
51 } else {
51 bits = 14;
52 shift = 0;
53 zero = 0x6000;
52 load(in, blob->length / sizeof(*in), mem);
54 }
55
53 }
54
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);
63 }
64
65 /* INTERPOLATE modes require a "next" entry to interpolate with,
66 * so we replicate the last entry to deal with this for now.
67 */
68 writew(r, mem + (i * 0x08) + 0);
69 writew(g, mem + (i * 0x08) + 2);
70 writew(b, mem + (i * 0x08) + 4);
71 return addr;
72}
73
74void
75nv50_lut_fini(struct nv50_lut *lut)
76{
77 int i;
78 for (i = 0; i < ARRAY_SIZE(lut->mem); i++)

--- 17 unchanged lines hidden ---
55 return addr;
56}
57
58void
59nv50_lut_fini(struct nv50_lut *lut)
60{
61 int i;
62 for (i = 0; i < ARRAY_SIZE(lut->mem); i++)

--- 17 unchanged lines hidden ---