drivers/gpu/drm/imx/dc/dc-kms.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/imx/dc/dc-kms.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/imx/dc/dc-kms.c
Extension
.c
Size
3189 bytes
Lines
138
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: implementation source
Status
source 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

// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright 2024 NXP
 */

#include <linux/of.h>
#include <linux/of_graph.h>

#include <drm/drm_atomic_helper.h>
#include <drm/drm_bridge.h>
#include <drm/drm_bridge_connector.h>
#include <drm/drm_connector.h>
#include <drm/drm_crtc.h>
#include <drm/drm_device.h>
#include <drm/drm_encoder.h>
#include <drm/drm_gem_framebuffer_helper.h>
#include <drm/drm_mode_config.h>
#include <drm/drm_print.h>
#include <drm/drm_probe_helper.h>
#include <drm/drm_simple_kms_helper.h>
#include <drm/drm_vblank.h>

#include "dc-de.h"
#include "dc-drv.h"
#include "dc-kms.h"

static const struct drm_mode_config_funcs dc_drm_mode_config_funcs = {
	.fb_create = drm_gem_fb_create,
	.atomic_check = drm_atomic_helper_check,
	.atomic_commit = drm_atomic_helper_commit,
};

static int dc_kms_init_encoder_per_crtc(struct dc_drm_device *dc_drm,
					int crtc_index)
{
	struct dc_crtc *dc_crtc = &dc_drm->dc_crtc[crtc_index];
	struct drm_device *drm = &dc_drm->base;
	struct drm_crtc *crtc = &dc_crtc->base;
	struct drm_connector *connector;
	struct device *dev = drm->dev;
	struct drm_encoder *encoder;
	struct drm_bridge *bridge;
	int ret;

	bridge = devm_drm_of_get_bridge(dev, dc_crtc->de->tc->dev->of_node,
					0, 0);
	if (IS_ERR(bridge)) {
		ret = PTR_ERR(bridge);
		if (ret == -ENODEV)
			return 0;

		return dev_err_probe(dev, ret,
				     "failed to find bridge for CRTC%u\n",
				     crtc->index);
	}

	encoder = &dc_drm->encoder[crtc_index];
	ret = drm_simple_encoder_init(drm, encoder, DRM_MODE_ENCODER_NONE);
	if (ret) {
		dev_err(dev, "failed to initialize encoder for CRTC%u: %d\n",
			crtc->index, ret);
		return ret;
	}

	encoder->possible_crtcs = drm_crtc_mask(crtc);

	ret = drm_bridge_attach(encoder, bridge, NULL,
				DRM_BRIDGE_ATTACH_NO_CONNECTOR);
	if (ret) {
		dev_err(dev,
			"failed to attach bridge to encoder for CRTC%u: %d\n",
			crtc->index, ret);
		return ret;
	}

	connector = drm_bridge_connector_init(drm, encoder);
	if (IS_ERR(connector)) {
		ret = PTR_ERR(connector);
		dev_err(dev, "failed to init bridge connector for CRTC%u: %d\n",
			crtc->index, ret);
		return ret;
	}

	return 0;
}

int dc_kms_init(struct dc_drm_device *dc_drm)
{
	struct drm_device *drm = &dc_drm->base;
	int ret, i;

Annotation

Implementation Notes