x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / gpu / drm / exynos / exynos_drm_connector.c
blobe082efb2fece3d7174592194f155946efcee03fe
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 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
14 #include <drm/drmP.h>
15 #include <drm/drm_crtc_helper.h>
17 #include <drm/exynos_drm.h>
18 #include "exynos_drm_drv.h"
19 #include "exynos_drm_encoder.h"
20 #include "exynos_drm_connector.h"
22 #define to_exynos_connector(x) container_of(x, struct exynos_drm_connector,\
23 drm_connector)
25 struct exynos_drm_connector {
26 struct drm_connector drm_connector;
27 uint32_t encoder_id;
28 struct exynos_drm_manager *manager;
29 uint32_t dpms;
32 static int exynos_drm_connector_get_modes(struct drm_connector *connector)
34 struct exynos_drm_connector *exynos_connector =
35 to_exynos_connector(connector);
36 struct exynos_drm_manager *manager = exynos_connector->manager;
37 struct exynos_drm_display_ops *display_ops = manager->display_ops;
38 struct edid *edid = NULL;
39 unsigned int count = 0;
40 int ret;
42 if (!display_ops) {
43 DRM_DEBUG_KMS("display_ops is null.\n");
44 return 0;
48 * if get_edid() exists then get_edid() callback of hdmi side
49 * is called to get edid data through i2c interface else
50 * get timing from the FIMD driver(display controller).
52 * P.S. in case of lcd panel, count is always 1 if success
53 * because lcd panel has only one mode.
55 if (display_ops->get_edid) {
56 edid = display_ops->get_edid(manager->dev, connector);
57 if (IS_ERR_OR_NULL(edid)) {
58 ret = PTR_ERR(edid);
59 edid = NULL;
60 DRM_ERROR("Panel operation get_edid failed %d\n", ret);
61 goto out;
64 count = drm_add_edid_modes(connector, edid);
65 if (!count) {
66 DRM_ERROR("Add edid modes failed %d\n", count);
67 goto out;
70 drm_mode_connector_update_edid_property(connector, edid);
71 } else {
72 struct exynos_drm_panel_info *panel;
73 struct drm_display_mode *mode = drm_mode_create(connector->dev);
74 if (!mode) {
75 DRM_ERROR("failed to create a new display mode.\n");
76 return 0;
79 if (display_ops->get_panel)
80 panel = display_ops->get_panel(manager->dev);
81 else {
82 drm_mode_destroy(connector->dev, mode);
83 return 0;
86 drm_display_mode_from_videomode(&panel->vm, mode);
87 mode->width_mm = panel->width_mm;
88 mode->height_mm = panel->height_mm;
89 connector->display_info.width_mm = mode->width_mm;
90 connector->display_info.height_mm = mode->height_mm;
92 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
93 drm_mode_set_name(mode);
94 drm_mode_probed_add(connector, mode);
96 count = 1;
99 out:
100 kfree(edid);
101 return count;
104 static int exynos_drm_connector_mode_valid(struct drm_connector *connector,
105 struct drm_display_mode *mode)
107 struct exynos_drm_connector *exynos_connector =
108 to_exynos_connector(connector);
109 struct exynos_drm_manager *manager = exynos_connector->manager;
110 struct exynos_drm_display_ops *display_ops = manager->display_ops;
111 int ret = MODE_BAD;
113 DRM_DEBUG_KMS("%s\n", __FILE__);
115 if (display_ops && display_ops->check_mode)
116 if (!display_ops->check_mode(manager->dev, mode))
117 ret = MODE_OK;
119 return ret;
122 struct drm_encoder *exynos_drm_best_encoder(struct drm_connector *connector)
124 struct drm_device *dev = connector->dev;
125 struct exynos_drm_connector *exynos_connector =
126 to_exynos_connector(connector);
127 struct drm_mode_object *obj;
128 struct drm_encoder *encoder;
130 obj = drm_mode_object_find(dev, exynos_connector->encoder_id,
131 DRM_MODE_OBJECT_ENCODER);
132 if (!obj) {
133 DRM_DEBUG_KMS("Unknown ENCODER ID %d\n",
134 exynos_connector->encoder_id);
135 return NULL;
138 encoder = obj_to_encoder(obj);
140 return encoder;
143 static struct drm_connector_helper_funcs exynos_connector_helper_funcs = {
144 .get_modes = exynos_drm_connector_get_modes,
145 .mode_valid = exynos_drm_connector_mode_valid,
146 .best_encoder = exynos_drm_best_encoder,
149 void exynos_drm_display_power(struct drm_connector *connector, int mode)
151 struct drm_encoder *encoder = exynos_drm_best_encoder(connector);
152 struct exynos_drm_connector *exynos_connector;
153 struct exynos_drm_manager *manager = exynos_drm_get_manager(encoder);
154 struct exynos_drm_display_ops *display_ops = manager->display_ops;
156 exynos_connector = to_exynos_connector(connector);
158 if (exynos_connector->dpms == mode) {
159 DRM_DEBUG_KMS("desired dpms mode is same as previous one.\n");
160 return;
163 if (display_ops && display_ops->power_on)
164 display_ops->power_on(manager->dev, mode);
166 exynos_connector->dpms = mode;
169 static void exynos_drm_connector_dpms(struct drm_connector *connector,
170 int mode)
173 * in case that drm_crtc_helper_set_mode() is called,
174 * encoder/crtc->funcs->dpms() will be just returned
175 * because they already were DRM_MODE_DPMS_ON so only
176 * exynos_drm_display_power() will be called.
178 drm_helper_connector_dpms(connector, mode);
180 exynos_drm_display_power(connector, mode);
184 static int exynos_drm_connector_fill_modes(struct drm_connector *connector,
185 unsigned int max_width, unsigned int max_height)
187 struct exynos_drm_connector *exynos_connector =
188 to_exynos_connector(connector);
189 struct exynos_drm_manager *manager = exynos_connector->manager;
190 struct exynos_drm_manager_ops *ops = manager->ops;
191 unsigned int width, height;
193 width = max_width;
194 height = max_height;
197 * if specific driver want to find desired_mode using maxmum
198 * resolution then get max width and height from that driver.
200 if (ops && ops->get_max_resol)
201 ops->get_max_resol(manager->dev, &width, &height);
203 return drm_helper_probe_single_connector_modes(connector, width,
204 height);
207 /* get detection status of display device. */
208 static enum drm_connector_status
209 exynos_drm_connector_detect(struct drm_connector *connector, bool force)
211 struct exynos_drm_connector *exynos_connector =
212 to_exynos_connector(connector);
213 struct exynos_drm_manager *manager = exynos_connector->manager;
214 struct exynos_drm_display_ops *display_ops =
215 manager->display_ops;
216 enum drm_connector_status status = connector_status_disconnected;
218 if (display_ops && display_ops->is_connected) {
219 if (display_ops->is_connected(manager->dev))
220 status = connector_status_connected;
221 else
222 status = connector_status_disconnected;
225 return status;
228 static void exynos_drm_connector_destroy(struct drm_connector *connector)
230 struct exynos_drm_connector *exynos_connector =
231 to_exynos_connector(connector);
233 drm_sysfs_connector_remove(connector);
234 drm_connector_cleanup(connector);
235 kfree(exynos_connector);
238 static struct drm_connector_funcs exynos_connector_funcs = {
239 .dpms = exynos_drm_connector_dpms,
240 .fill_modes = exynos_drm_connector_fill_modes,
241 .detect = exynos_drm_connector_detect,
242 .destroy = exynos_drm_connector_destroy,
245 struct drm_connector *exynos_drm_connector_create(struct drm_device *dev,
246 struct drm_encoder *encoder)
248 struct exynos_drm_connector *exynos_connector;
249 struct exynos_drm_manager *manager = exynos_drm_get_manager(encoder);
250 struct drm_connector *connector;
251 int type;
252 int err;
254 exynos_connector = kzalloc(sizeof(*exynos_connector), GFP_KERNEL);
255 if (!exynos_connector)
256 return NULL;
258 connector = &exynos_connector->drm_connector;
260 switch (manager->display_ops->type) {
261 case EXYNOS_DISPLAY_TYPE_HDMI:
262 type = DRM_MODE_CONNECTOR_HDMIA;
263 connector->interlace_allowed = true;
264 connector->polled = DRM_CONNECTOR_POLL_HPD;
265 break;
266 case EXYNOS_DISPLAY_TYPE_VIDI:
267 type = DRM_MODE_CONNECTOR_VIRTUAL;
268 connector->polled = DRM_CONNECTOR_POLL_HPD;
269 break;
270 default:
271 type = DRM_MODE_CONNECTOR_Unknown;
272 break;
275 drm_connector_init(dev, connector, &exynos_connector_funcs, type);
276 drm_connector_helper_add(connector, &exynos_connector_helper_funcs);
278 err = drm_sysfs_connector_add(connector);
279 if (err)
280 goto err_connector;
282 exynos_connector->encoder_id = encoder->base.id;
283 exynos_connector->manager = manager;
284 exynos_connector->dpms = DRM_MODE_DPMS_OFF;
285 connector->dpms = DRM_MODE_DPMS_OFF;
286 connector->encoder = encoder;
288 err = drm_mode_connector_attach_encoder(connector, encoder);
289 if (err) {
290 DRM_ERROR("failed to attach a connector to a encoder\n");
291 goto err_sysfs;
294 DRM_DEBUG_KMS("connector has been created\n");
296 return connector;
298 err_sysfs:
299 drm_sysfs_connector_remove(connector);
300 err_connector:
301 drm_connector_cleanup(connector);
302 kfree(exynos_connector);
303 return NULL;