]>
Commit | Line | Data |
---|---|---|
1c248b7d ID |
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> | |
7 | * | |
d81aecb5 ID |
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. | |
1c248b7d ID |
12 | */ |
13 | ||
760285e7 DH |
14 | #include <drm/drmP.h> |
15 | #include <drm/drm_crtc_helper.h> | |
1c248b7d | 16 | |
607c50d4 | 17 | #include <drm/exynos_drm.h> |
1c248b7d ID |
18 | #include "exynos_drm_drv.h" |
19 | #include "exynos_drm_encoder.h" | |
e30655d0 | 20 | #include "exynos_drm_connector.h" |
1c248b7d | 21 | |
1c248b7d ID |
22 | #define to_exynos_connector(x) container_of(x, struct exynos_drm_connector,\ |
23 | drm_connector) | |
24 | ||
25 | struct exynos_drm_connector { | |
080be03d SP |
26 | struct drm_connector drm_connector; |
27 | uint32_t encoder_id; | |
28 | struct exynos_drm_display *display; | |
1c248b7d ID |
29 | }; |
30 | ||
1c248b7d ID |
31 | static int exynos_drm_connector_get_modes(struct drm_connector *connector) |
32 | { | |
adb6b159 ID |
33 | struct exynos_drm_connector *exynos_connector = |
34 | to_exynos_connector(connector); | |
080be03d | 35 | struct exynos_drm_display *display = exynos_connector->display; |
9c08e4ba RS |
36 | struct edid *edid = NULL; |
37 | unsigned int count = 0; | |
38 | int ret; | |
1c248b7d | 39 | |
1c248b7d ID |
40 | /* |
41 | * if get_edid() exists then get_edid() callback of hdmi side | |
42 | * is called to get edid data through i2c interface else | |
43 | * get timing from the FIMD driver(display controller). | |
44 | * | |
45 | * P.S. in case of lcd panel, count is always 1 if success | |
46 | * because lcd panel has only one mode. | |
47 | */ | |
080be03d SP |
48 | if (display->ops->get_edid) { |
49 | edid = display->ops->get_edid(display, connector); | |
9c08e4ba RS |
50 | if (IS_ERR_OR_NULL(edid)) { |
51 | ret = PTR_ERR(edid); | |
52 | edid = NULL; | |
53 | DRM_ERROR("Panel operation get_edid failed %d\n", ret); | |
54 | goto out; | |
1c248b7d ID |
55 | } |
56 | ||
9c08e4ba | 57 | count = drm_add_edid_modes(connector, edid); |
81ed7039 | 58 | if (!count) { |
9c08e4ba RS |
59 | DRM_ERROR("Add edid modes failed %d\n", count); |
60 | goto out; | |
1c248b7d ID |
61 | } |
62 | ||
63 | drm_mode_connector_update_edid_property(connector, edid); | |
1c248b7d | 64 | } else { |
607c50d4 | 65 | struct exynos_drm_panel_info *panel; |
53bd5556 SK |
66 | struct drm_display_mode *mode = drm_mode_create(connector->dev); |
67 | if (!mode) { | |
68 | DRM_ERROR("failed to create a new display mode.\n"); | |
69 | return 0; | |
70 | } | |
1c248b7d | 71 | |
080be03d SP |
72 | if (display->ops->get_panel) |
73 | panel = display->ops->get_panel(display); | |
1c248b7d ID |
74 | else { |
75 | drm_mode_destroy(connector->dev, mode); | |
76 | return 0; | |
77 | } | |
78 | ||
111e6055 AH |
79 | drm_display_mode_from_videomode(&panel->vm, mode); |
80 | mode->width_mm = panel->width_mm; | |
81 | mode->height_mm = panel->height_mm; | |
607c50d4 ECK |
82 | connector->display_info.width_mm = mode->width_mm; |
83 | connector->display_info.height_mm = mode->height_mm; | |
1c248b7d ID |
84 | |
85 | mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; | |
86 | drm_mode_set_name(mode); | |
87 | drm_mode_probed_add(connector, mode); | |
88 | ||
89 | count = 1; | |
90 | } | |
91 | ||
9c08e4ba RS |
92 | out: |
93 | kfree(edid); | |
1c248b7d ID |
94 | return count; |
95 | } | |
96 | ||
97 | static int exynos_drm_connector_mode_valid(struct drm_connector *connector, | |
98 | struct drm_display_mode *mode) | |
99 | { | |
adb6b159 ID |
100 | struct exynos_drm_connector *exynos_connector = |
101 | to_exynos_connector(connector); | |
080be03d | 102 | struct exynos_drm_display *display = exynos_connector->display; |
1c248b7d ID |
103 | int ret = MODE_BAD; |
104 | ||
105 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
106 | ||
080be03d SP |
107 | if (display->ops->check_mode) |
108 | if (!display->ops->check_mode(display, mode)) | |
1c248b7d ID |
109 | ret = MODE_OK; |
110 | ||
111 | return ret; | |
112 | } | |
113 | ||
e5b89916 SP |
114 | static struct drm_encoder *exynos_drm_best_encoder( |
115 | struct drm_connector *connector) | |
1c248b7d | 116 | { |
adb6b159 ID |
117 | struct drm_device *dev = connector->dev; |
118 | struct exynos_drm_connector *exynos_connector = | |
119 | to_exynos_connector(connector); | |
4726f1ff | 120 | return drm_encoder_find(dev, exynos_connector->encoder_id); |
1c248b7d ID |
121 | } |
122 | ||
123 | static struct drm_connector_helper_funcs exynos_connector_helper_funcs = { | |
124 | .get_modes = exynos_drm_connector_get_modes, | |
125 | .mode_valid = exynos_drm_connector_mode_valid, | |
126 | .best_encoder = exynos_drm_best_encoder, | |
127 | }; | |
128 | ||
1de425b0 ID |
129 | static int exynos_drm_connector_fill_modes(struct drm_connector *connector, |
130 | unsigned int max_width, unsigned int max_height) | |
131 | { | |
132 | struct exynos_drm_connector *exynos_connector = | |
133 | to_exynos_connector(connector); | |
080be03d | 134 | struct exynos_drm_display *display = exynos_connector->display; |
1de425b0 ID |
135 | unsigned int width, height; |
136 | ||
137 | width = max_width; | |
138 | height = max_height; | |
139 | ||
140 | /* | |
141 | * if specific driver want to find desired_mode using maxmum | |
142 | * resolution then get max width and height from that driver. | |
143 | */ | |
080be03d SP |
144 | if (display->ops->get_max_resol) |
145 | display->ops->get_max_resol(display, &width, &height); | |
1de425b0 ID |
146 | |
147 | return drm_helper_probe_single_connector_modes(connector, width, | |
148 | height); | |
149 | } | |
150 | ||
1c248b7d ID |
151 | /* get detection status of display device. */ |
152 | static enum drm_connector_status | |
153 | exynos_drm_connector_detect(struct drm_connector *connector, bool force) | |
154 | { | |
adb6b159 ID |
155 | struct exynos_drm_connector *exynos_connector = |
156 | to_exynos_connector(connector); | |
080be03d | 157 | struct exynos_drm_display *display = exynos_connector->display; |
1c248b7d ID |
158 | enum drm_connector_status status = connector_status_disconnected; |
159 | ||
080be03d SP |
160 | if (display->ops->is_connected) { |
161 | if (display->ops->is_connected(display)) | |
1c248b7d ID |
162 | status = connector_status_connected; |
163 | else | |
164 | status = connector_status_disconnected; | |
165 | } | |
166 | ||
167 | return status; | |
168 | } | |
169 | ||
170 | static void exynos_drm_connector_destroy(struct drm_connector *connector) | |
171 | { | |
172 | struct exynos_drm_connector *exynos_connector = | |
173 | to_exynos_connector(connector); | |
174 | ||
34ea3d38 | 175 | drm_connector_unregister(connector); |
1c248b7d ID |
176 | drm_connector_cleanup(connector); |
177 | kfree(exynos_connector); | |
178 | } | |
179 | ||
180 | static struct drm_connector_funcs exynos_connector_funcs = { | |
e5b89916 | 181 | .dpms = drm_helper_connector_dpms, |
1de425b0 | 182 | .fill_modes = exynos_drm_connector_fill_modes, |
1c248b7d ID |
183 | .detect = exynos_drm_connector_detect, |
184 | .destroy = exynos_drm_connector_destroy, | |
185 | }; | |
186 | ||
187 | struct drm_connector *exynos_drm_connector_create(struct drm_device *dev, | |
188 | struct drm_encoder *encoder) | |
189 | { | |
190 | struct exynos_drm_connector *exynos_connector; | |
080be03d | 191 | struct exynos_drm_display *display = exynos_drm_get_display(encoder); |
1c248b7d ID |
192 | struct drm_connector *connector; |
193 | int type; | |
194 | int err; | |
195 | ||
1c248b7d | 196 | exynos_connector = kzalloc(sizeof(*exynos_connector), GFP_KERNEL); |
38bb5253 | 197 | if (!exynos_connector) |
1c248b7d | 198 | return NULL; |
1c248b7d ID |
199 | |
200 | connector = &exynos_connector->drm_connector; | |
201 | ||
080be03d | 202 | switch (display->type) { |
1c248b7d ID |
203 | case EXYNOS_DISPLAY_TYPE_HDMI: |
204 | type = DRM_MODE_CONNECTOR_HDMIA; | |
1b17b206 SWK |
205 | connector->interlace_allowed = true; |
206 | connector->polled = DRM_CONNECTOR_POLL_HPD; | |
1c248b7d | 207 | break; |
b73d1230 ID |
208 | case EXYNOS_DISPLAY_TYPE_VIDI: |
209 | type = DRM_MODE_CONNECTOR_VIRTUAL; | |
210 | connector->polled = DRM_CONNECTOR_POLL_HPD; | |
211 | break; | |
1c248b7d ID |
212 | default: |
213 | type = DRM_MODE_CONNECTOR_Unknown; | |
214 | break; | |
215 | } | |
216 | ||
217 | drm_connector_init(dev, connector, &exynos_connector_funcs, type); | |
218 | drm_connector_helper_add(connector, &exynos_connector_helper_funcs); | |
219 | ||
34ea3d38 | 220 | err = drm_connector_register(connector); |
1c248b7d ID |
221 | if (err) |
222 | goto err_connector; | |
223 | ||
adb6b159 | 224 | exynos_connector->encoder_id = encoder->base.id; |
080be03d | 225 | exynos_connector->display = display; |
44c91697 | 226 | connector->dpms = DRM_MODE_DPMS_OFF; |
1c248b7d | 227 | connector->encoder = encoder; |
adb6b159 | 228 | |
1c248b7d ID |
229 | err = drm_mode_connector_attach_encoder(connector, encoder); |
230 | if (err) { | |
231 | DRM_ERROR("failed to attach a connector to a encoder\n"); | |
232 | goto err_sysfs; | |
233 | } | |
234 | ||
235 | DRM_DEBUG_KMS("connector has been created\n"); | |
236 | ||
237 | return connector; | |
238 | ||
239 | err_sysfs: | |
34ea3d38 | 240 | drm_connector_unregister(connector); |
1c248b7d ID |
241 | err_connector: |
242 | drm_connector_cleanup(connector); | |
243 | kfree(exynos_connector); | |
244 | return NULL; | |
245 | } |