[S390] Remove error checking from copy_oldmem_page()
[linux/fpc-iii.git] / drivers / gpu / drm / exynos / exynos_drm_connector.c
blob985d9e7687287d915c6a76e2b7219f9e7840e7f8
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
3 * Authors:
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
17 * Software.
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.
28 #include "drmP.h"
29 #include "drm_crtc_helper.h"
31 #include "exynos_drm_drv.h"
32 #include "exynos_drm_encoder.h"
34 #define MAX_EDID 256
35 #define to_exynos_connector(x) container_of(x, struct exynos_drm_connector,\
36 drm_connector)
38 struct exynos_drm_connector {
39 struct drm_connector drm_connector;
42 /* convert exynos_video_timings to drm_display_mode */
43 static inline void
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 */
63 static inline void
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;
86 else
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;
98 unsigned int count;
100 DRM_DEBUG_KMS("%s\n", __FILE__);
102 if (!display) {
103 DRM_DEBUG_KMS("display is null.\n");
104 return 0;
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) {
116 int ret;
117 void *edid;
119 edid = kzalloc(MAX_EDID, GFP_KERNEL);
120 if (!edid) {
121 DRM_ERROR("failed to allocate edid\n");
122 return 0;
125 ret = display->get_edid(manager->dev, connector,
126 edid, MAX_EDID);
127 if (ret < 0) {
128 DRM_ERROR("failed to get edid data.\n");
129 kfree(edid);
130 edid = NULL;
131 return 0;
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;
139 } else {
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);
145 else {
146 drm_mode_destroy(connector->dev, mode);
147 return 0;
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);
156 count = 1;
159 return count;
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;
169 int ret = MODE_BAD;
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))
177 ret = MODE_OK;
179 return ret;
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;
209 else
210 status = connector_status_disconnected;
213 return status;
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;
241 int type;
242 int err;
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");
249 return NULL;
252 connector = &exynos_connector->drm_connector;
254 switch (manager->display->type) {
255 case EXYNOS_DISPLAY_TYPE_HDMI:
256 type = DRM_MODE_CONNECTOR_HDMIA;
257 break;
258 default:
259 type = DRM_MODE_CONNECTOR_Unknown;
260 break;
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);
267 if (err)
268 goto err_connector;
270 connector->encoder = encoder;
271 err = drm_mode_connector_attach_encoder(connector, encoder);
272 if (err) {
273 DRM_ERROR("failed to attach a connector to a encoder\n");
274 goto err_sysfs;
277 DRM_DEBUG_KMS("connector has been created\n");
279 return connector;
281 err_sysfs:
282 drm_sysfs_connector_remove(connector);
283 err_connector:
284 drm_connector_cleanup(connector);
285 kfree(exynos_connector);
286 return NULL;
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");