Skip to content

Commit b706a25

Browse files
pcornuBenjamin-Gaignard
authored andcommitted
drm/stm: ltdc: add clut mode support
Add the 8-bit clut mode support at crtc level. Useful for low memory footprint user interfaces but also for 8-bit old games (including color shifting visual effects). Tested with fbdev FBIOPUTCMAP & drm DRM_IOCTL_MODE_SETGAMMA ioctls. Signed-off-by: Philippe Cornu <[email protected]> Signed-off-by: Benjamin Gaignard <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent c4712f2 commit b706a25

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

drivers/gpu/drm/stm/ltdc.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@
175175

176176
#define LXCFBLNR_CFBLN GENMASK(10, 0) /* Color Frame Buffer Line Number */
177177

178+
#define CLUT_SIZE 256
179+
178180
#define CONSTA_MAX 0xFF /* CONSTant Alpha MAX= 1.0 */
179181
#define BF1_PAXCA 0x600 /* Pixel Alpha x Constant Alpha */
180182
#define BF1_CA 0x400 /* Constant Alpha */
@@ -363,6 +365,28 @@ static irqreturn_t ltdc_irq(int irq, void *arg)
363365
* DRM_CRTC
364366
*/
365367

368+
static void ltdc_crtc_update_clut(struct drm_crtc *crtc)
369+
{
370+
struct ltdc_device *ldev = crtc_to_ltdc(crtc);
371+
struct drm_color_lut *lut;
372+
u32 val;
373+
int i;
374+
375+
if (!crtc || !crtc->state)
376+
return;
377+
378+
if (!crtc->state->color_mgmt_changed || !crtc->state->gamma_lut)
379+
return;
380+
381+
lut = (struct drm_color_lut *)crtc->state->gamma_lut->data;
382+
383+
for (i = 0; i < CLUT_SIZE; i++, lut++) {
384+
val = ((lut->red << 8) & 0xff0000) | (lut->green & 0xff00) |
385+
(lut->blue >> 8) | (i << 24);
386+
reg_write(ldev->regs, LTDC_L1CLUTWR, val);
387+
}
388+
}
389+
366390
static void ltdc_crtc_atomic_enable(struct drm_crtc *crtc,
367391
struct drm_crtc_state *old_state)
368392
{
@@ -486,6 +510,8 @@ static void ltdc_crtc_atomic_flush(struct drm_crtc *crtc,
486510

487511
DRM_DEBUG_ATOMIC("\n");
488512

513+
ltdc_crtc_update_clut(crtc);
514+
489515
/* Commit shadow registers = update planes at next vblank */
490516
reg_set(ldev->regs, LTDC_SRCR, SRCR_VBR);
491517

@@ -533,6 +559,7 @@ static const struct drm_crtc_funcs ltdc_crtc_funcs = {
533559
.reset = drm_atomic_helper_crtc_reset,
534560
.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
535561
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
562+
.gamma_set = drm_atomic_helper_legacy_gamma_set,
536563
};
537564

538565
/*
@@ -765,6 +792,9 @@ static int ltdc_crtc_init(struct drm_device *ddev, struct drm_crtc *crtc)
765792

766793
drm_crtc_helper_add(crtc, &ltdc_crtc_helper_funcs);
767794

795+
drm_mode_crtc_set_gamma_size(crtc, CLUT_SIZE);
796+
drm_crtc_enable_color_mgmt(crtc, 0, false, CLUT_SIZE);
797+
768798
DRM_DEBUG_DRIVER("CRTC:%d created\n", crtc->base.id);
769799

770800
/* Add planes. Note : the first layer is used by primary plane */

0 commit comments

Comments
 (0)