2 * rcar_du_lvdscon.c -- R-Car Display Unit LVDS Connector
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.
15 #include <drm/drm_crtc.h>
16 #include <drm/drm_crtc_helper.h>
18 #include <video/display_timing.h>
19 #include <video/of_display_timing.h>
20 #include <video/videomode.h>
22 #include "rcar_du_drv.h"
23 #include "rcar_du_encoder.h"
24 #include "rcar_du_kms.h"
25 #include "rcar_du_lvdscon.h"
27 struct rcar_du_lvds_connector
{
28 struct rcar_du_connector connector
;
31 unsigned int width_mm
; /* Panel width in mm */
32 unsigned int height_mm
; /* Panel height in mm */
33 struct videomode mode
;
37 #define to_rcar_lvds_connector(c) \
38 container_of(c, struct rcar_du_lvds_connector, connector.connector)
40 static int rcar_du_lvds_connector_get_modes(struct drm_connector
*connector
)
42 struct rcar_du_lvds_connector
*lvdscon
=
43 to_rcar_lvds_connector(connector
);
44 struct drm_display_mode
*mode
;
46 mode
= drm_mode_create(connector
->dev
);
50 mode
->type
= DRM_MODE_TYPE_PREFERRED
| DRM_MODE_TYPE_DRIVER
;
52 drm_display_mode_from_videomode(&lvdscon
->panel
.mode
, mode
);
54 drm_mode_probed_add(connector
, mode
);
59 static const struct drm_connector_helper_funcs connector_helper_funcs
= {
60 .get_modes
= rcar_du_lvds_connector_get_modes
,
61 .best_encoder
= rcar_du_connector_best_encoder
,
64 static void rcar_du_lvds_connector_destroy(struct drm_connector
*connector
)
66 drm_connector_unregister(connector
);
67 drm_connector_cleanup(connector
);
70 static enum drm_connector_status
71 rcar_du_lvds_connector_detect(struct drm_connector
*connector
, bool force
)
73 return connector_status_connected
;
76 static const struct drm_connector_funcs connector_funcs
= {
77 .dpms
= drm_helper_connector_dpms
,
78 .detect
= rcar_du_lvds_connector_detect
,
79 .fill_modes
= drm_helper_probe_single_connector_modes
,
80 .destroy
= rcar_du_lvds_connector_destroy
,
83 int rcar_du_lvds_connector_init(struct rcar_du_device
*rcdu
,
84 struct rcar_du_encoder
*renc
,
85 /* TODO const */ struct device_node
*np
)
87 struct drm_encoder
*encoder
= rcar_encoder_to_drm_encoder(renc
);
88 struct rcar_du_lvds_connector
*lvdscon
;
89 struct drm_connector
*connector
;
90 struct display_timing timing
;
93 lvdscon
= devm_kzalloc(rcdu
->dev
, sizeof(*lvdscon
), GFP_KERNEL
);
97 ret
= of_get_display_timing(np
, "panel-timing", &timing
);
101 videomode_from_timing(&timing
, &lvdscon
->panel
.mode
);
103 of_property_read_u32(np
, "width-mm", &lvdscon
->panel
.width_mm
);
104 of_property_read_u32(np
, "height-mm", &lvdscon
->panel
.height_mm
);
106 connector
= &lvdscon
->connector
.connector
;
107 connector
->display_info
.width_mm
= lvdscon
->panel
.width_mm
;
108 connector
->display_info
.height_mm
= lvdscon
->panel
.height_mm
;
110 ret
= drm_connector_init(rcdu
->ddev
, connector
, &connector_funcs
,
111 DRM_MODE_CONNECTOR_LVDS
);
115 drm_connector_helper_add(connector
, &connector_helper_funcs
);
116 ret
= drm_connector_register(connector
);
120 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_OFF
);
121 drm_object_property_set_value(&connector
->base
,
122 rcdu
->ddev
->mode_config
.dpms_property
, DRM_MODE_DPMS_OFF
);
124 ret
= drm_mode_connector_attach_encoder(connector
, encoder
);
128 connector
->encoder
= encoder
;
129 lvdscon
->connector
.encoder
= renc
;