2 * R-Car Display Unit HDMI Connector
4 * Copyright (C) 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.
15 #include <drm/drm_crtc.h>
16 #include <drm/drm_crtc_helper.h>
17 #include <drm/drm_encoder_slave.h>
19 #include "rcar_du_drv.h"
20 #include "rcar_du_encoder.h"
21 #include "rcar_du_hdmicon.h"
22 #include "rcar_du_kms.h"
24 #define to_slave_funcs(e) (to_rcar_encoder(e)->slave.slave_funcs)
26 static int rcar_du_hdmi_connector_get_modes(struct drm_connector
*connector
)
28 struct rcar_du_connector
*con
= to_rcar_connector(connector
);
29 struct drm_encoder
*encoder
= rcar_encoder_to_drm_encoder(con
->encoder
);
30 struct drm_encoder_slave_funcs
*sfuncs
= to_slave_funcs(encoder
);
32 if (sfuncs
->get_modes
== NULL
)
35 return sfuncs
->get_modes(encoder
, connector
);
38 static int rcar_du_hdmi_connector_mode_valid(struct drm_connector
*connector
,
39 struct drm_display_mode
*mode
)
41 struct rcar_du_connector
*con
= to_rcar_connector(connector
);
42 struct drm_encoder
*encoder
= rcar_encoder_to_drm_encoder(con
->encoder
);
43 struct drm_encoder_slave_funcs
*sfuncs
= to_slave_funcs(encoder
);
45 if (sfuncs
->mode_valid
== NULL
)
48 return sfuncs
->mode_valid(encoder
, mode
);
51 static const struct drm_connector_helper_funcs connector_helper_funcs
= {
52 .get_modes
= rcar_du_hdmi_connector_get_modes
,
53 .mode_valid
= rcar_du_hdmi_connector_mode_valid
,
54 .best_encoder
= rcar_du_connector_best_encoder
,
57 static void rcar_du_hdmi_connector_destroy(struct drm_connector
*connector
)
59 drm_connector_unregister(connector
);
60 drm_connector_cleanup(connector
);
63 static enum drm_connector_status
64 rcar_du_hdmi_connector_detect(struct drm_connector
*connector
, bool force
)
66 struct rcar_du_connector
*con
= to_rcar_connector(connector
);
67 struct drm_encoder
*encoder
= rcar_encoder_to_drm_encoder(con
->encoder
);
68 struct drm_encoder_slave_funcs
*sfuncs
= to_slave_funcs(encoder
);
70 if (sfuncs
->detect
== NULL
)
71 return connector_status_unknown
;
73 return sfuncs
->detect(encoder
, connector
);
76 static const struct drm_connector_funcs connector_funcs
= {
77 .dpms
= drm_helper_connector_dpms
,
78 .detect
= rcar_du_hdmi_connector_detect
,
79 .fill_modes
= drm_helper_probe_single_connector_modes
,
80 .destroy
= rcar_du_hdmi_connector_destroy
,
83 int rcar_du_hdmi_connector_init(struct rcar_du_device
*rcdu
,
84 struct rcar_du_encoder
*renc
)
86 struct drm_encoder
*encoder
= rcar_encoder_to_drm_encoder(renc
);
87 struct rcar_du_connector
*rcon
;
88 struct drm_connector
*connector
;
91 rcon
= devm_kzalloc(rcdu
->dev
, sizeof(*rcon
), GFP_KERNEL
);
95 connector
= &rcon
->connector
;
96 connector
->display_info
.width_mm
= 0;
97 connector
->display_info
.height_mm
= 0;
98 connector
->interlace_allowed
= true;
99 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
101 ret
= drm_connector_init(rcdu
->ddev
, connector
, &connector_funcs
,
102 DRM_MODE_CONNECTOR_HDMIA
);
106 drm_connector_helper_add(connector
, &connector_helper_funcs
);
107 ret
= drm_connector_register(connector
);
111 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_OFF
);
112 drm_object_property_set_value(&connector
->base
,
113 rcdu
->ddev
->mode_config
.dpms_property
, DRM_MODE_DPMS_OFF
);
115 ret
= drm_mode_connector_attach_encoder(connector
, encoder
);
119 connector
->encoder
= encoder
;
120 rcon
->encoder
= renc
;