drm/msm/hdmi: Enable HPD after HDMI IRQ is set up
[linux/fpc-iii.git] / drivers / gpu / drm / rcar-du / rcar_du_encoder.c
blobf9c933d3bae6aeee44859c8ab8a7ccb62889c551
1 /*
2 * rcar_du_encoder.c -- R-Car Display Unit Encoder
4 * Copyright (C) 2013-2014 Renesas Electronics Corporation
6 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include <linux/export.h>
16 #include <drm/drmP.h>
17 #include <drm/drm_crtc.h>
18 #include <drm/drm_crtc_helper.h>
19 #include <drm/drm_panel.h>
21 #include "rcar_du_drv.h"
22 #include "rcar_du_encoder.h"
23 #include "rcar_du_kms.h"
25 /* -----------------------------------------------------------------------------
26 * Encoder
29 static void rcar_du_encoder_mode_set(struct drm_encoder *encoder,
30 struct drm_crtc_state *crtc_state,
31 struct drm_connector_state *conn_state)
33 struct rcar_du_encoder *renc = to_rcar_encoder(encoder);
35 rcar_du_crtc_route_output(crtc_state->crtc, renc->output);
38 static const struct drm_encoder_helper_funcs encoder_helper_funcs = {
39 .atomic_mode_set = rcar_du_encoder_mode_set,
42 static const struct drm_encoder_funcs encoder_funcs = {
43 .destroy = drm_encoder_cleanup,
46 int rcar_du_encoder_init(struct rcar_du_device *rcdu,
47 enum rcar_du_output output,
48 struct device_node *enc_node,
49 struct device_node *con_node)
51 struct rcar_du_encoder *renc;
52 struct drm_encoder *encoder;
53 struct drm_bridge *bridge = NULL;
54 int ret;
56 renc = devm_kzalloc(rcdu->dev, sizeof(*renc), GFP_KERNEL);
57 if (renc == NULL)
58 return -ENOMEM;
60 renc->output = output;
61 encoder = rcar_encoder_to_drm_encoder(renc);
63 dev_dbg(rcdu->dev, "initializing encoder %pOF for output %u\n",
64 enc_node, output);
66 /* Locate the DRM bridge from the encoder DT node. */
67 bridge = of_drm_find_bridge(enc_node);
68 if (!bridge) {
69 ret = -EPROBE_DEFER;
70 goto done;
73 ret = drm_encoder_init(rcdu->ddev, encoder, &encoder_funcs,
74 DRM_MODE_ENCODER_NONE, NULL);
75 if (ret < 0)
76 goto done;
78 drm_encoder_helper_add(encoder, &encoder_helper_funcs);
81 * Attach the bridge to the encoder. The bridge will create the
82 * connector.
84 ret = drm_bridge_attach(encoder, bridge, NULL);
85 if (ret) {
86 drm_encoder_cleanup(encoder);
87 return ret;
90 done:
91 if (ret < 0) {
92 if (encoder->name)
93 encoder->funcs->destroy(encoder);
94 devm_kfree(rcdu->dev, renc);
97 return ret;