Correct .gbs.conf settings
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / gpu / drm / rcar-du / rcar_du_lvdscon.c
1 /*
2  * rcar_du_lvdscon.c  --  R-Car Display Unit LVDS Connector
3  *
4  * Copyright (C) 2013-2014 Renesas Electronics Corporation
5  *
6  * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
7  *
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.
12  */
13
14 #include <drm/drmP.h>
15 #include <drm/drm_crtc.h>
16 #include <drm/drm_crtc_helper.h>
17
18 #include <video/display_timing.h>
19 #include <video/of_display_timing.h>
20 #include <video/videomode.h>
21
22 #include "rcar_du_drv.h"
23 #include "rcar_du_encoder.h"
24 #include "rcar_du_kms.h"
25 #include "rcar_du_lvdscon.h"
26
27 struct rcar_du_lvds_connector {
28         struct rcar_du_connector connector;
29
30         struct {
31                 unsigned int width_mm;          /* Panel width in mm */
32                 unsigned int height_mm;         /* Panel height in mm */
33                 struct videomode mode;
34         } panel;
35 };
36
37 #define to_rcar_lvds_connector(c) \
38         container_of(c, struct rcar_du_lvds_connector, connector.connector)
39
40 static int rcar_du_lvds_connector_get_modes(struct drm_connector *connector)
41 {
42         struct rcar_du_lvds_connector *lvdscon =
43                 to_rcar_lvds_connector(connector);
44         struct drm_display_mode *mode;
45
46         mode = drm_mode_create(connector->dev);
47         if (mode == NULL)
48                 return 0;
49
50         mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
51
52         drm_display_mode_from_videomode(&lvdscon->panel.mode, mode);
53
54         drm_mode_probed_add(connector, mode);
55
56         return 1;
57 }
58
59 static int rcar_du_lvds_connector_mode_valid(struct drm_connector *connector,
60                                             struct drm_display_mode *mode)
61 {
62         return MODE_OK;
63 }
64
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,
69 };
70
71 static void rcar_du_lvds_connector_destroy(struct drm_connector *connector)
72 {
73         drm_connector_unregister(connector);
74         drm_connector_cleanup(connector);
75 }
76
77 static enum drm_connector_status
78 rcar_du_lvds_connector_detect(struct drm_connector *connector, bool force)
79 {
80         return connector_status_connected;
81 }
82
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,
88 };
89
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)
93 {
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;
98         int ret;
99
100         lvdscon = devm_kzalloc(rcdu->dev, sizeof(*lvdscon), GFP_KERNEL);
101         if (lvdscon == NULL)
102                 return -ENOMEM;
103
104         ret = of_get_display_timing(np, "panel-timing", &timing);
105         if (ret < 0)
106                 return ret;
107
108         videomode_from_timing(&timing, &lvdscon->panel.mode);
109
110         of_property_read_u32(np, "width-mm", &lvdscon->panel.width_mm);
111         of_property_read_u32(np, "height-mm", &lvdscon->panel.height_mm);
112
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;
116
117         ret = drm_connector_init(rcdu->ddev, connector, &connector_funcs,
118                                  DRM_MODE_CONNECTOR_LVDS);
119         if (ret < 0)
120                 return ret;
121
122         drm_connector_helper_add(connector, &connector_helper_funcs);
123         ret = drm_connector_register(connector);
124         if (ret < 0)
125                 return ret;
126
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);
130
131         ret = drm_mode_connector_attach_encoder(connector, encoder);
132         if (ret < 0)
133                 return ret;
134
135         connector->encoder = encoder;
136         lvdscon->connector.encoder = renc;
137
138         return 0;
139 }