drivers/gpu/drm/renesas/rcar-du/rcar_cmm.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/renesas/rcar-du/rcar_cmm.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/renesas/rcar-du/rcar_cmm.c
Extension
.c
Size
5392 bytes
Lines
211
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

struct rcar_cmm {
	void __iomem *base;

	/*
	 * @lut:		1D-LUT state
	 * @lut.enabled:	1D-LUT enabled flag
	 */
	struct {
		bool enabled;
	} lut;
};

static inline void rcar_cmm_write(struct rcar_cmm *rcmm, u32 reg, u32 data)
{
	iowrite32(data, rcmm->base + reg);
}

/*
 * rcar_cmm_lut_write() - Scale the DRM LUT table entries to hardware precision
 *			  and write to the CMM registers
 * @rcmm: Pointer to the CMM device
 * @drm_lut: Pointer to the DRM LUT table
 */
static void rcar_cmm_lut_write(struct rcar_cmm *rcmm,
			       const struct drm_color_lut *drm_lut)
{
	unsigned int i;

	for (i = 0; i < CM2_LUT_SIZE; ++i) {
		u32 entry = drm_color_lut_extract(drm_lut[i].red, 8) << 16
			  | drm_color_lut_extract(drm_lut[i].green, 8) << 8
			  | drm_color_lut_extract(drm_lut[i].blue, 8);

		rcar_cmm_write(rcmm, CM2_LUT_TBL(i), entry);
	}
}

/*
 * rcar_cmm_setup() - Configure the CMM unit
 * @dev: The device associated with the CMM instance
 * @config: The CMM unit configuration
 *
 * Configure the CMM unit with the given configuration. Currently enabling,
 * disabling and programming of the 1-D LUT unit is supported.
 *
 * As rcar_cmm_setup() accesses the CMM registers the unit should be powered
 * and its functional clock enabled. To guarantee this, before any call to
 * this function is made, the CMM unit has to be enabled by calling
 * rcar_cmm_enable() first.
 *
 * TODO: Add support for LUT double buffer operations to avoid updating the
 * LUT table entries while a frame is being displayed.
 */
int rcar_cmm_setup(struct device *dev,
		   const struct rcar_cmm_config *config)
{
	struct rcar_cmm *rcmm = dev_get_drvdata(dev);

	/* Disable LUT if no table is provided. */
	if (!config->lut.table) {
		if (rcmm->lut.enabled) {
			rcar_cmm_write(rcmm, CM2_LUT_CTRL, 0);
			rcmm->lut.enabled = false;
		}

		return 0;
	}

	/* Enable LUT and program the new gamma table values. */
	if (!rcmm->lut.enabled) {
		rcar_cmm_write(rcmm, CM2_LUT_CTRL, CM2_LUT_CTRL_LUT_EN);
		rcmm->lut.enabled = true;
	}

	rcar_cmm_lut_write(rcmm, config->lut.table);

	return 0;
}
EXPORT_SYMBOL_GPL(rcar_cmm_setup);

/*
 * rcar_cmm_enable() - Enable the CMM unit
 * @dev: The device associated with the CMM instance
 *
 * When the output of the corresponding DU channel is routed to the CMM unit,
 * the unit shall be enabled before the DU channel is started, and remain
 * enabled until the channel is stopped. The CMM unit shall be disabled with
 * rcar_cmm_disable().
 *
 * Calls to rcar_cmm_enable() and rcar_cmm_disable() are not reference-counted.

Annotation

Implementation Notes