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 "exynos_drm_drv.h"
32 #include "exynos_drm_encoder.h"
35 #define to_exynos_connector(x) container_of(x, struct exynos_drm_connector,\
38 struct exynos_drm_connector
{
39 struct drm_connector drm_connector
;
42 /* convert exynos_video_timings to drm_display_mode */
44 convert_to_display_mode(struct drm_display_mode
*mode
,
45 struct fb_videomode
*timing
)
47 DRM_DEBUG_KMS("%s\n", __FILE__
);
49 mode
->clock
= timing
->pixclock
/ 1000;
51 mode
->hdisplay
= timing
->xres
;
52 mode
->hsync_start
= mode
->hdisplay
+ timing
->left_margin
;
53 mode
->hsync_end
= mode
->hsync_start
+ timing
->hsync_len
;
54 mode
->htotal
= mode
->hsync_end
+ timing
->right_margin
;
56 mode
->vdisplay
= timing
->yres
;
57 mode
->vsync_start
= mode
->vdisplay
+ timing
->upper_margin
;
58 mode
->vsync_end
= mode
->vsync_start
+ timing
->vsync_len
;
59 mode
->vtotal
= mode
->vsync_end
+ timing
->lower_margin
;
62 /* convert drm_display_mode to exynos_video_timings */
64 convert_to_video_timing(struct fb_videomode
*timing
,
65 struct drm_display_mode
*mode
)
67 DRM_DEBUG_KMS("%s\n", __FILE__
);
69 memset(timing
, 0, sizeof(*timing
));
71 timing
->pixclock
= mode
->clock
* 1000;
72 timing
->refresh
= mode
->vrefresh
;
74 timing
->xres
= mode
->hdisplay
;
75 timing
->left_margin
= mode
->hsync_start
- mode
->hdisplay
;
76 timing
->hsync_len
= mode
->hsync_end
- mode
->hsync_start
;
77 timing
->right_margin
= mode
->htotal
- mode
->hsync_end
;
79 timing
->yres
= mode
->vdisplay
;
80 timing
->upper_margin
= mode
->vsync_start
- mode
->vdisplay
;
81 timing
->vsync_len
= mode
->vsync_end
- mode
->vsync_start
;
82 timing
->lower_margin
= mode
->vtotal
- mode
->vsync_end
;
84 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
85 timing
->vmode
= FB_VMODE_INTERLACED
;
87 timing
->vmode
= FB_VMODE_NONINTERLACED
;
89 if (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
)
90 timing
->vmode
|= FB_VMODE_DOUBLE
;
93 static int exynos_drm_connector_get_modes(struct drm_connector
*connector
)
95 struct exynos_drm_manager
*manager
=
96 exynos_drm_get_manager(connector
->encoder
);
97 struct exynos_drm_display
*display
= manager
->display
;
100 DRM_DEBUG_KMS("%s\n", __FILE__
);
103 DRM_DEBUG_KMS("display is null.\n");
108 * if get_edid() exists then get_edid() callback of hdmi side
109 * is called to get edid data through i2c interface else
110 * get timing from the FIMD driver(display controller).
112 * P.S. in case of lcd panel, count is always 1 if success
113 * because lcd panel has only one mode.
115 if (display
->get_edid
) {
119 edid
= kzalloc(MAX_EDID
, GFP_KERNEL
);
121 DRM_ERROR("failed to allocate edid\n");
125 ret
= display
->get_edid(manager
->dev
, connector
,
128 DRM_ERROR("failed to get edid data.\n");
134 drm_mode_connector_update_edid_property(connector
, edid
);
135 count
= drm_add_edid_modes(connector
, edid
);
137 kfree(connector
->display_info
.raw_edid
);
138 connector
->display_info
.raw_edid
= edid
;
140 struct drm_display_mode
*mode
= drm_mode_create(connector
->dev
);
141 struct fb_videomode
*timing
;
143 if (display
->get_timing
)
144 timing
= display
->get_timing(manager
->dev
);
146 drm_mode_destroy(connector
->dev
, mode
);
150 convert_to_display_mode(mode
, timing
);
152 mode
->type
= DRM_MODE_TYPE_DRIVER
| DRM_MODE_TYPE_PREFERRED
;
153 drm_mode_set_name(mode
);
154 drm_mode_probed_add(connector
, mode
);
162 static int exynos_drm_connector_mode_valid(struct drm_connector
*connector
,
163 struct drm_display_mode
*mode
)
165 struct exynos_drm_manager
*manager
=
166 exynos_drm_get_manager(connector
->encoder
);
167 struct exynos_drm_display
*display
= manager
->display
;
168 struct fb_videomode timing
;
171 DRM_DEBUG_KMS("%s\n", __FILE__
);
173 convert_to_video_timing(&timing
, mode
);
175 if (display
&& display
->check_timing
)
176 if (!display
->check_timing(manager
->dev
, (void *)&timing
))
182 struct drm_encoder
*exynos_drm_best_encoder(struct drm_connector
*connector
)
184 DRM_DEBUG_KMS("%s\n", __FILE__
);
186 return connector
->encoder
;
189 static struct drm_connector_helper_funcs exynos_connector_helper_funcs
= {
190 .get_modes
= exynos_drm_connector_get_modes
,
191 .mode_valid
= exynos_drm_connector_mode_valid
,
192 .best_encoder
= exynos_drm_best_encoder
,
195 /* get detection status of display device. */
196 static enum drm_connector_status
197 exynos_drm_connector_detect(struct drm_connector
*connector
, bool force
)
199 struct exynos_drm_manager
*manager
=
200 exynos_drm_get_manager(connector
->encoder
);
201 struct exynos_drm_display
*display
= manager
->display
;
202 enum drm_connector_status status
= connector_status_disconnected
;
204 DRM_DEBUG_KMS("%s\n", __FILE__
);
206 if (display
&& display
->is_connected
) {
207 if (display
->is_connected(manager
->dev
))
208 status
= connector_status_connected
;
210 status
= connector_status_disconnected
;
216 static void exynos_drm_connector_destroy(struct drm_connector
*connector
)
218 struct exynos_drm_connector
*exynos_connector
=
219 to_exynos_connector(connector
);
221 DRM_DEBUG_KMS("%s\n", __FILE__
);
223 drm_sysfs_connector_remove(connector
);
224 drm_connector_cleanup(connector
);
225 kfree(exynos_connector
);
228 static struct drm_connector_funcs exynos_connector_funcs
= {
229 .dpms
= drm_helper_connector_dpms
,
230 .fill_modes
= drm_helper_probe_single_connector_modes
,
231 .detect
= exynos_drm_connector_detect
,
232 .destroy
= exynos_drm_connector_destroy
,
235 struct drm_connector
*exynos_drm_connector_create(struct drm_device
*dev
,
236 struct drm_encoder
*encoder
)
238 struct exynos_drm_connector
*exynos_connector
;
239 struct exynos_drm_manager
*manager
= exynos_drm_get_manager(encoder
);
240 struct drm_connector
*connector
;
244 DRM_DEBUG_KMS("%s\n", __FILE__
);
246 exynos_connector
= kzalloc(sizeof(*exynos_connector
), GFP_KERNEL
);
247 if (!exynos_connector
) {
248 DRM_ERROR("failed to allocate connector\n");
252 connector
= &exynos_connector
->drm_connector
;
254 switch (manager
->display
->type
) {
255 case EXYNOS_DISPLAY_TYPE_HDMI
:
256 type
= DRM_MODE_CONNECTOR_HDMIA
;
259 type
= DRM_MODE_CONNECTOR_Unknown
;
263 drm_connector_init(dev
, connector
, &exynos_connector_funcs
, type
);
264 drm_connector_helper_add(connector
, &exynos_connector_helper_funcs
);
266 err
= drm_sysfs_connector_add(connector
);
270 connector
->encoder
= encoder
;
271 err
= drm_mode_connector_attach_encoder(connector
, encoder
);
273 DRM_ERROR("failed to attach a connector to a encoder\n");
277 DRM_DEBUG_KMS("connector has been created\n");
282 drm_sysfs_connector_remove(connector
);
284 drm_connector_cleanup(connector
);
285 kfree(exynos_connector
);
289 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
290 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
291 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
292 MODULE_DESCRIPTION("Samsung SoC DRM Connector Driver");
293 MODULE_LICENSE("GPL");