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 int rcar_du_lvds_connector_mode_valid(struct drm_connector *connector,
60 struct drm_display_mode *mode)
65 static const struct drm_connector_helper_funcs connector_helper_funcs = {
66 .get_modes = rcar_du_lvds_connector_get_modes,
67 .mode_valid = rcar_du_lvds_connector_mode_valid,
68 .best_encoder = rcar_du_connector_best_encoder,
71 static void rcar_du_lvds_connector_destroy(struct drm_connector *connector)
73 drm_connector_unregister(connector);
74 drm_connector_cleanup(connector);
77 static enum drm_connector_status
78 rcar_du_lvds_connector_detect(struct drm_connector *connector, bool force)
80 return connector_status_connected;
83 static const struct drm_connector_funcs connector_funcs = {
84 .dpms = drm_helper_connector_dpms,
85 .detect = rcar_du_lvds_connector_detect,
86 .fill_modes = drm_helper_probe_single_connector_modes,
87 .destroy = rcar_du_lvds_connector_destroy,
90 int rcar_du_lvds_connector_init(struct rcar_du_device *rcdu,
91 struct rcar_du_encoder *renc,
92 /* TODO const */ struct device_node *np)
94 struct drm_encoder *encoder = rcar_encoder_to_drm_encoder(renc);
95 struct rcar_du_lvds_connector *lvdscon;
96 struct drm_connector *connector;
97 struct display_timing timing;
100 lvdscon = devm_kzalloc(rcdu->dev, sizeof(*lvdscon), GFP_KERNEL);
104 ret = of_get_display_timing(np, "panel-timing", &timing);
108 videomode_from_timing(&timing, &lvdscon->panel.mode);
110 of_property_read_u32(np, "width-mm", &lvdscon->panel.width_mm);
111 of_property_read_u32(np, "height-mm", &lvdscon->panel.height_mm);
113 connector = &lvdscon->connector.connector;
114 connector->display_info.width_mm = lvdscon->panel.width_mm;
115 connector->display_info.height_mm = lvdscon->panel.height_mm;
117 ret = drm_connector_init(rcdu->ddev, connector, &connector_funcs,
118 DRM_MODE_CONNECTOR_LVDS);
122 drm_connector_helper_add(connector, &connector_helper_funcs);
123 ret = drm_connector_register(connector);
127 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
128 drm_object_property_set_value(&connector->base,
129 rcdu->ddev->mode_config.dpms_property, DRM_MODE_DPMS_OFF);
131 ret = drm_mode_connector_attach_encoder(connector, encoder);
135 connector->encoder = encoder;
136 lvdscon->connector.encoder = renc;