rcar_du_encoder.c 1.8 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0+
2
/*
3
 * rcar_du_encoder.c  --  R-Car Display Unit Encoder
4
 *
5
 * Copyright (C) 2013-2014 Renesas Electronics Corporation
6 7 8 9
 *
 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
 */

10 11
#include <linux/export.h>

12
#include <drm/drm_crtc.h>
13
#include <drm/drm_modeset_helper_vtables.h>
14
#include <drm/drm_panel.h>
15 16

#include "rcar_du_drv.h"
17
#include "rcar_du_encoder.h"
18 19
#include "rcar_du_kms.h"

20 21 22 23
/* -----------------------------------------------------------------------------
 * Encoder
 */

24 25 26 27 28 29 30
static const struct drm_encoder_helper_funcs encoder_helper_funcs = {
};

static const struct drm_encoder_funcs encoder_funcs = {
	.destroy = drm_encoder_cleanup,
};

31
int rcar_du_encoder_init(struct rcar_du_device *rcdu,
32
			 enum rcar_du_output output,
33
			 struct device_node *enc_node)
34 35
{
	struct rcar_du_encoder *renc;
36
	struct drm_encoder *encoder;
37
	struct drm_bridge *bridge = NULL;
38 39 40 41 42 43 44
	int ret;

	renc = devm_kzalloc(rcdu->dev, sizeof(*renc), GFP_KERNEL);
	if (renc == NULL)
		return -ENOMEM;

	renc->output = output;
45
	encoder = rcar_encoder_to_drm_encoder(renc);
46

47 48
	dev_dbg(rcdu->dev, "initializing encoder %pOF for output %u\n",
		enc_node, output);
49

50 51 52 53 54
	/* Locate the DRM bridge from the encoder DT node. */
	bridge = of_drm_find_bridge(enc_node);
	if (!bridge) {
		ret = -EPROBE_DEFER;
		goto done;
55 56
	}

57
	ret = drm_encoder_init(rcdu->ddev, encoder, &encoder_funcs,
58
			       DRM_MODE_ENCODER_NONE, NULL);
59 60
	if (ret < 0)
		goto done;
61

62
	drm_encoder_helper_add(encoder, &encoder_helper_funcs);
63

64 65 66 67 68 69 70 71
	/*
	 * Attach the bridge to the encoder. The bridge will create the
	 * connector.
	 */
	ret = drm_bridge_attach(encoder, bridge, NULL);
	if (ret) {
		drm_encoder_cleanup(encoder);
		return ret;
72
	}
73 74 75 76 77 78 79 80 81

done:
	if (ret < 0) {
		if (encoder->name)
			encoder->funcs->destroy(encoder);
		devm_kfree(rcdu->dev, renc);
	}

	return ret;
82
}