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>
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 /* -----------------------------------------------------------------------------
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
;
56 renc
= devm_kzalloc(rcdu
->dev
, sizeof(*renc
), GFP_KERNEL
);
60 renc
->output
= output
;
61 encoder
= rcar_encoder_to_drm_encoder(renc
);
63 dev_dbg(rcdu
->dev
, "initializing encoder %pOF for output %u\n",
66 /* Locate the DRM bridge from the encoder DT node. */
67 bridge
= of_drm_find_bridge(enc_node
);
73 ret
= drm_encoder_init(rcdu
->ddev
, encoder
, &encoder_funcs
,
74 DRM_MODE_ENCODER_NONE
, NULL
);
78 drm_encoder_helper_add(encoder
, &encoder_helper_funcs
);
81 * Attach the bridge to the encoder. The bridge will create the
84 ret
= drm_bridge_attach(encoder
, bridge
, NULL
);
86 drm_encoder_cleanup(encoder
);
93 encoder
->funcs
->destroy(encoder
);
94 devm_kfree(rcdu
->dev
, renc
);