drivers/gpu/drm/drm_color_mgmt.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_color_mgmt.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/drm_color_mgmt.c
Extension
.c
Size
28420 bytes
Lines
920
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (tests & DRM_COLOR_LUT_EQUAL_CHANNELS) {
			if (entry[i].red != entry[i].blue ||
			    entry[i].red != entry[i].green) {
				DRM_DEBUG_KMS("All LUT entries must have equal r/g/b\n");
				return -EINVAL;
			}
		}

		if (i > 0 && tests & DRM_COLOR_LUT_NON_DECREASING) {
			if (entry[i].red < entry[i - 1].red ||
			    entry[i].green < entry[i - 1].green ||
			    entry[i].blue < entry[i - 1].blue) {
				DRM_DEBUG_KMS("LUT entries must never decrease.\n");
				return -EINVAL;
			}
		}
	}

	return 0;
}
EXPORT_SYMBOL(drm_color_lut_check);

/*
 * Gamma-LUT programming
 */

/**
 * drm_crtc_load_gamma_888 - Programs gamma ramp for RGB888-like formats
 * @crtc: The displaying CRTC
 * @lut: The gamma ramp to program
 * @set_gamma: Callback for programming the hardware gamma LUT
 *
 * Programs the gamma ramp specified in @lut to hardware. The input gamma
 * ramp must have 256 entries per color component.
 */
void drm_crtc_load_gamma_888(struct drm_crtc *crtc, const struct drm_color_lut *lut,
			     drm_crtc_set_lut_func set_gamma)
{
	unsigned int i;

	for (i = 0; i < 256; ++i)
		set_gamma(crtc, i, lut[i].red, lut[i].green, lut[i].blue);
}
EXPORT_SYMBOL(drm_crtc_load_gamma_888);

/**
 * drm_crtc_load_gamma_565_from_888 - Programs gamma ramp for RGB565-like formats
 * @crtc: The displaying CRTC
 * @lut: The gamma ramp to program
 * @set_gamma: Callback for programming the hardware gamma LUT
 *
 * Programs the gamma ramp specified in @lut to hardware. The input gamma
 * ramp must have 256 entries per color component. The helper interpolates
 * the individual color components to reduce the number of entries to 5/6/5.
 */
void drm_crtc_load_gamma_565_from_888(struct drm_crtc *crtc, const struct drm_color_lut *lut,
				      drm_crtc_set_lut_func set_gamma)
{
	unsigned int i;
	u16 r, g, b;

	for (i = 0; i < 32; ++i) {
		r = lut[i * 8 + i / 4].red;
		g = lut[i * 4 + i / 16].green;
		b = lut[i * 8 + i / 4].blue;
		set_gamma(crtc, i, r, g, b);
	}
	/* Green has one more bit, so add padding with 0 for red and blue. */
	for (i = 32; i < 64; ++i) {
		g = lut[i * 4 + i / 16].green;
		set_gamma(crtc, i, 0, g, 0);
	}
}
EXPORT_SYMBOL(drm_crtc_load_gamma_565_from_888);

/**
 * drm_crtc_load_gamma_555_from_888 - Programs gamma ramp for RGB555-like formats
 * @crtc: The displaying CRTC
 * @lut: The gamma ramp to program
 * @set_gamma: Callback for programming the hardware gamma LUT
 *
 * Programs the gamma ramp specified in @lut to hardware. The input gamma
 * ramp must have 256 entries per color component. The helper interpolates
 * the individual color components to reduce the number of entries to 5/5/5.
 */
void drm_crtc_load_gamma_555_from_888(struct drm_crtc *crtc, const struct drm_color_lut *lut,
				      drm_crtc_set_lut_func set_gamma)
{
	unsigned int i;
	u16 r, g, b;

Annotation

Implementation Notes