2 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * Inki Dae <inki.dae@samsung.com>
5 * Joonyoung Shim <jy0922.shim@samsung.com>
6 * Seung-Woo Kim <sw0312.kim@samsung.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
29 #include "drm_crtc_helper.h"
31 #include <drm/exynos_drm.h>
32 #include "exynos_drm_drv.h"
33 #include "exynos_drm_encoder.h"
36 #define to_exynos_connector(x) container_of(x, struct exynos_drm_connector,\
39 struct exynos_drm_connector
{
40 struct drm_connector drm_connector
;
42 struct exynos_drm_manager
*manager
;
45 /* convert exynos_video_timings to drm_display_mode */
47 convert_to_display_mode(struct drm_display_mode
*mode
,
48 struct exynos_drm_panel_info
*panel
)
50 struct fb_videomode
*timing
= &panel
->timing
;
51 DRM_DEBUG_KMS("%s\n", __FILE__
);
53 mode
->clock
= timing
->pixclock
/ 1000;
54 mode
->vrefresh
= timing
->refresh
;
56 mode
->hdisplay
= timing
->xres
;
57 mode
->hsync_start
= mode
->hdisplay
+ timing
->right_margin
;
58 mode
->hsync_end
= mode
->hsync_start
+ timing
->hsync_len
;
59 mode
->htotal
= mode
->hsync_end
+ timing
->left_margin
;
61 mode
->vdisplay
= timing
->yres
;
62 mode
->vsync_start
= mode
->vdisplay
+ timing
->lower_margin
;
63 mode
->vsync_end
= mode
->vsync_start
+ timing
->vsync_len
;
64 mode
->vtotal
= mode
->vsync_end
+ timing
->upper_margin
;
65 mode
->width_mm
= panel
->width_mm
;
66 mode
->height_mm
= panel
->height_mm
;
68 if (timing
->vmode
& FB_VMODE_INTERLACED
)
69 mode
->flags
|= DRM_MODE_FLAG_INTERLACE
;
71 if (timing
->vmode
& FB_VMODE_DOUBLE
)
72 mode
->flags
|= DRM_MODE_FLAG_DBLSCAN
;
75 /* convert drm_display_mode to exynos_video_timings */
77 convert_to_video_timing(struct fb_videomode
*timing
,
78 struct drm_display_mode
*mode
)
80 DRM_DEBUG_KMS("%s\n", __FILE__
);
82 memset(timing
, 0, sizeof(*timing
));
84 timing
->pixclock
= mode
->clock
* 1000;
85 timing
->refresh
= drm_mode_vrefresh(mode
);
87 timing
->xres
= mode
->hdisplay
;
88 timing
->right_margin
= mode
->hsync_start
- mode
->hdisplay
;
89 timing
->hsync_len
= mode
->hsync_end
- mode
->hsync_start
;
90 timing
->left_margin
= mode
->htotal
- mode
->hsync_end
;
92 timing
->yres
= mode
->vdisplay
;
93 timing
->lower_margin
= mode
->vsync_start
- mode
->vdisplay
;
94 timing
->vsync_len
= mode
->vsync_end
- mode
->vsync_start
;
95 timing
->upper_margin
= mode
->vtotal
- mode
->vsync_end
;
97 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
98 timing
->vmode
= FB_VMODE_INTERLACED
;
100 timing
->vmode
= FB_VMODE_NONINTERLACED
;
102 if (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
)
103 timing
->vmode
|= FB_VMODE_DOUBLE
;
106 static int exynos_drm_connector_get_modes(struct drm_connector
*connector
)
108 struct exynos_drm_connector
*exynos_connector
=
109 to_exynos_connector(connector
);
110 struct exynos_drm_manager
*manager
= exynos_connector
->manager
;
111 struct exynos_drm_display_ops
*display_ops
= manager
->display_ops
;
114 DRM_DEBUG_KMS("%s\n", __FILE__
);
117 DRM_DEBUG_KMS("display_ops is null.\n");
122 * if get_edid() exists then get_edid() callback of hdmi side
123 * is called to get edid data through i2c interface else
124 * get timing from the FIMD driver(display controller).
126 * P.S. in case of lcd panel, count is always 1 if success
127 * because lcd panel has only one mode.
129 if (display_ops
->get_edid
) {
133 edid
= kzalloc(MAX_EDID
, GFP_KERNEL
);
135 DRM_ERROR("failed to allocate edid\n");
139 ret
= display_ops
->get_edid(manager
->dev
, connector
,
142 DRM_ERROR("failed to get edid data.\n");
148 drm_mode_connector_update_edid_property(connector
, edid
);
149 count
= drm_add_edid_modes(connector
, edid
);
151 kfree(connector
->display_info
.raw_edid
);
152 connector
->display_info
.raw_edid
= edid
;
154 struct drm_display_mode
*mode
= drm_mode_create(connector
->dev
);
155 struct exynos_drm_panel_info
*panel
;
157 if (display_ops
->get_panel
)
158 panel
= display_ops
->get_panel(manager
->dev
);
160 drm_mode_destroy(connector
->dev
, mode
);
164 convert_to_display_mode(mode
, panel
);
165 connector
->display_info
.width_mm
= mode
->width_mm
;
166 connector
->display_info
.height_mm
= mode
->height_mm
;
168 mode
->type
= DRM_MODE_TYPE_DRIVER
| DRM_MODE_TYPE_PREFERRED
;
169 drm_mode_set_name(mode
);
170 drm_mode_probed_add(connector
, mode
);
178 static int exynos_drm_connector_mode_valid(struct drm_connector
*connector
,
179 struct drm_display_mode
*mode
)
181 struct exynos_drm_connector
*exynos_connector
=
182 to_exynos_connector(connector
);
183 struct exynos_drm_manager
*manager
= exynos_connector
->manager
;
184 struct exynos_drm_display_ops
*display_ops
= manager
->display_ops
;
185 struct fb_videomode timing
;
188 DRM_DEBUG_KMS("%s\n", __FILE__
);
190 convert_to_video_timing(&timing
, mode
);
192 if (display_ops
&& display_ops
->check_timing
)
193 if (!display_ops
->check_timing(manager
->dev
, (void *)&timing
))
199 struct drm_encoder
*exynos_drm_best_encoder(struct drm_connector
*connector
)
201 struct drm_device
*dev
= connector
->dev
;
202 struct exynos_drm_connector
*exynos_connector
=
203 to_exynos_connector(connector
);
204 struct drm_mode_object
*obj
;
205 struct drm_encoder
*encoder
;
207 DRM_DEBUG_KMS("%s\n", __FILE__
);
209 obj
= drm_mode_object_find(dev
, exynos_connector
->encoder_id
,
210 DRM_MODE_OBJECT_ENCODER
);
212 DRM_DEBUG_KMS("Unknown ENCODER ID %d\n",
213 exynos_connector
->encoder_id
);
217 encoder
= obj_to_encoder(obj
);
222 static struct drm_connector_helper_funcs exynos_connector_helper_funcs
= {
223 .get_modes
= exynos_drm_connector_get_modes
,
224 .mode_valid
= exynos_drm_connector_mode_valid
,
225 .best_encoder
= exynos_drm_best_encoder
,
228 /* get detection status of display device. */
229 static enum drm_connector_status
230 exynos_drm_connector_detect(struct drm_connector
*connector
, bool force
)
232 struct exynos_drm_connector
*exynos_connector
=
233 to_exynos_connector(connector
);
234 struct exynos_drm_manager
*manager
= exynos_connector
->manager
;
235 struct exynos_drm_display_ops
*display_ops
=
236 manager
->display_ops
;
237 enum drm_connector_status status
= connector_status_disconnected
;
239 DRM_DEBUG_KMS("%s\n", __FILE__
);
241 if (display_ops
&& display_ops
->is_connected
) {
242 if (display_ops
->is_connected(manager
->dev
))
243 status
= connector_status_connected
;
245 status
= connector_status_disconnected
;
251 static void exynos_drm_connector_destroy(struct drm_connector
*connector
)
253 struct exynos_drm_connector
*exynos_connector
=
254 to_exynos_connector(connector
);
256 DRM_DEBUG_KMS("%s\n", __FILE__
);
258 drm_sysfs_connector_remove(connector
);
259 drm_connector_cleanup(connector
);
260 kfree(exynos_connector
);
263 static struct drm_connector_funcs exynos_connector_funcs
= {
264 .dpms
= drm_helper_connector_dpms
,
265 .fill_modes
= drm_helper_probe_single_connector_modes
,
266 .detect
= exynos_drm_connector_detect
,
267 .destroy
= exynos_drm_connector_destroy
,
270 struct drm_connector
*exynos_drm_connector_create(struct drm_device
*dev
,
271 struct drm_encoder
*encoder
)
273 struct exynos_drm_connector
*exynos_connector
;
274 struct exynos_drm_manager
*manager
= exynos_drm_get_manager(encoder
);
275 struct drm_connector
*connector
;
279 DRM_DEBUG_KMS("%s\n", __FILE__
);
281 exynos_connector
= kzalloc(sizeof(*exynos_connector
), GFP_KERNEL
);
282 if (!exynos_connector
) {
283 DRM_ERROR("failed to allocate connector\n");
287 connector
= &exynos_connector
->drm_connector
;
289 switch (manager
->display_ops
->type
) {
290 case EXYNOS_DISPLAY_TYPE_HDMI
:
291 type
= DRM_MODE_CONNECTOR_HDMIA
;
292 connector
->interlace_allowed
= true;
293 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
296 type
= DRM_MODE_CONNECTOR_Unknown
;
300 drm_connector_init(dev
, connector
, &exynos_connector_funcs
, type
);
301 drm_connector_helper_add(connector
, &exynos_connector_helper_funcs
);
303 err
= drm_sysfs_connector_add(connector
);
307 exynos_connector
->encoder_id
= encoder
->base
.id
;
308 exynos_connector
->manager
= manager
;
309 connector
->encoder
= encoder
;
311 err
= drm_mode_connector_attach_encoder(connector
, encoder
);
313 DRM_ERROR("failed to attach a connector to a encoder\n");
317 DRM_DEBUG_KMS("connector has been created\n");
322 drm_sysfs_connector_remove(connector
);
324 drm_connector_cleanup(connector
);
325 kfree(exynos_connector
);
329 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
330 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
331 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
332 MODULE_DESCRIPTION("Samsung SoC DRM Connector Driver");
333 MODULE_LICENSE("GPL");