[01/10] drm: Initialize a linear gamma table by default
diff mbox

Message ID 1459331485-28376-2-git-send-email-daniel.vetter@ffwll.ch
State New
Headers show

Commit Message

Daniel Vetter March 30, 2016, 9:51 a.m. UTC
Code stolen from gma500.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 drivers/gpu/drm/drm_crtc.c                 | 13 +++++++++++++
 drivers/gpu/drm/gma500/psb_intel_display.c |  7 -------
 2 files changed, 13 insertions(+), 7 deletions(-)

Comments

Maarten Lankhorst May 31, 2016, 1:05 p.m. UTC | #1
Op 30-03-16 om 11:51 schreef Daniel Vetter:
> Code stolen from gma500.
It would be useful to mention why this is done. :)

But even with this patch it seems the legacy gamma in gamma_get is not very reliable.
A failed call to gamma_set could leave wrong values in crtc->gamma_store either by calling the ioctl with lut.blue set to NULL, or call gamma_set and interrupt with a signal.
For atomic color management get_gamma won't be accurate at all if mixed with new color management.

~Maarten
Daniel Vetter May 31, 2016, 1:24 p.m. UTC | #2
On Tue, May 31, 2016 at 03:05:32PM +0200, Maarten Lankhorst wrote:
> Op 30-03-16 om 11:51 schreef Daniel Vetter:
> > Code stolen from gma500.
> It would be useful to mention why this is done. :)
> 
> But even with this patch it seems the legacy gamma in gamma_get is not very reliable.
> A failed call to gamma_set could leave wrong values in crtc->gamma_store either by calling the ioctl with lut.blue set to NULL, or call gamma_set and interrupt with a signal.
> For atomic color management get_gamma won't be accurate at all if mixed with new color management.

Hm, it's just some safety code I found laying around, and figured that
looks like a good idea. You think it's worth it with some improved commit
message added?
-Daniel
Maarten Lankhorst May 31, 2016, 1:30 p.m. UTC | #3
Op 31-05-16 om 15:24 schreef Daniel Vetter:
> On Tue, May 31, 2016 at 03:05:32PM +0200, Maarten Lankhorst wrote:
>> Op 30-03-16 om 11:51 schreef Daniel Vetter:
>>> Code stolen from gma500.
>> It would be useful to mention why this is done. :)
>>
>> But even with this patch it seems the legacy gamma in gamma_get is not very reliable.
>> A failed call to gamma_set could leave wrong values in crtc->gamma_store either by calling the ioctl with lut.blue set to NULL, or call gamma_set and interrupt with a signal.
>> For atomic color management get_gamma won't be accurate at all if mixed with new color management.
> Hm, it's just some safety code I found laying around, and figured that
> looks like a good idea. You think it's worth it with some improved commit
> message added?
Might as well. It makes gamma_get ioctl slightly more reliable, but for reliable gamma should probably use crtc properties or atomic. :)

Patch
diff mbox

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 55ffde5a3a4a..a5bba9f023e9 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -5138,6 +5138,9 @@  EXPORT_SYMBOL(drm_mode_connector_attach_encoder);
 int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
 				 int gamma_size)
 {
+	uint16_t *r_base, *g_base, *b_base;
+	int i;
+
 	crtc->gamma_size = gamma_size;
 
 	crtc->gamma_store = kcalloc(gamma_size, sizeof(uint16_t) * 3,
@@ -5147,6 +5150,16 @@  int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
 		return -ENOMEM;
 	}
 
+	r_base = crtc->gamma_store;
+	g_base = r_base + gamma_size;
+	b_base = g_base + gamma_size;
+	for (i = 0; i < gamma_size; i++) {
+		r_base[i] = i << 8;
+		g_base[i] = i << 8;
+		b_base[i] = i << 8;
+	}
+
+
 	return 0;
 }
 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size);
diff --git a/drivers/gpu/drm/gma500/psb_intel_display.c b/drivers/gpu/drm/gma500/psb_intel_display.c
index 398015be87e4..7b6c84925098 100644
--- a/drivers/gpu/drm/gma500/psb_intel_display.c
+++ b/drivers/gpu/drm/gma500/psb_intel_display.c
@@ -491,7 +491,6 @@  void psb_intel_crtc_init(struct drm_device *dev, int pipe,
 	struct drm_psb_private *dev_priv = dev->dev_private;
 	struct gma_crtc *gma_crtc;
 	int i;
-	uint16_t *r_base, *g_base, *b_base;
 
 	/* We allocate a extra array of drm_connector pointers
 	 * for fbdev after the crtc */
@@ -519,16 +518,10 @@  void psb_intel_crtc_init(struct drm_device *dev, int pipe,
 	gma_crtc->pipe = pipe;
 	gma_crtc->plane = pipe;
 
-	r_base = gma_crtc->base.gamma_store;
-	g_base = r_base + 256;
-	b_base = g_base + 256;
 	for (i = 0; i < 256; i++) {
 		gma_crtc->lut_r[i] = i;
 		gma_crtc->lut_g[i] = i;
 		gma_crtc->lut_b[i] = i;
-		r_base[i] = i << 8;
-		g_base[i] = i << 8;
-		b_base[i] = i << 8;
 
 		gma_crtc->lut_adj[i] = 0;
 	}