Commit | Line | Data |
---|---|---|
e692da4d SH |
1 | /* |
2 | * Freescale i.MX drm driver | |
3 | * | |
4 | * Copyright (C) 2011 Sascha Hauer, Pengutronix | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version 2 | |
9 | * of the License, or (at your option) any later version. | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | */ | |
17b5001b | 16 | #include <linux/component.h> |
e692da4d | 17 | #include <linux/device.h> |
e7d6231e RK |
18 | #include <linux/fb.h> |
19 | #include <linux/module.h> | |
655b43cc | 20 | #include <linux/of_graph.h> |
e692da4d SH |
21 | #include <linux/platform_device.h> |
22 | #include <drm/drmP.h> | |
23 | #include <drm/drm_fb_helper.h> | |
24 | #include <drm/drm_crtc_helper.h> | |
e692da4d SH |
25 | #include <drm/drm_gem_cma_helper.h> |
26 | #include <drm/drm_fb_cma_helper.h> | |
3cb9ae4f | 27 | #include <drm/drm_plane_helper.h> |
6457b971 | 28 | #include <drm/drm_of.h> |
e692da4d SH |
29 | |
30 | #include "imx-drm.h" | |
31 | ||
32 | #define MAX_CRTC 4 | |
33 | ||
655b43cc PZ |
34 | struct imx_drm_component { |
35 | struct device_node *of_node; | |
36 | struct list_head list; | |
37 | }; | |
38 | ||
e692da4d SH |
39 | struct imx_drm_device { |
40 | struct drm_device *drm; | |
887eceac | 41 | struct imx_drm_crtc *crtc[MAX_CRTC]; |
e692da4d SH |
42 | int pipes; |
43 | struct drm_fbdev_cma *fbhelper; | |
44 | }; | |
45 | ||
46 | struct imx_drm_crtc { | |
47 | struct drm_crtc *crtc; | |
e692da4d SH |
48 | int pipe; |
49 | struct imx_drm_crtc_helper_funcs imx_drm_helper_funcs; | |
e692da4d SH |
50 | }; |
51 | ||
8acba02f RK |
52 | static int legacyfb_depth = 16; |
53 | module_param(legacyfb_depth, int, 0444); | |
54 | ||
b8d181e4 PZ |
55 | int imx_drm_crtc_id(struct imx_drm_crtc *crtc) |
56 | { | |
57 | return crtc->pipe; | |
58 | } | |
9c74360f | 59 | EXPORT_SYMBOL_GPL(imx_drm_crtc_id); |
b8d181e4 | 60 | |
e692da4d SH |
61 | static void imx_drm_driver_lastclose(struct drm_device *drm) |
62 | { | |
8acba02f | 63 | #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER) |
e692da4d SH |
64 | struct imx_drm_device *imxdrm = drm->dev_private; |
65 | ||
66 | if (imxdrm->fbhelper) | |
67 | drm_fbdev_cma_restore_mode(imxdrm->fbhelper); | |
8acba02f | 68 | #endif |
e692da4d SH |
69 | } |
70 | ||
71 | static int imx_drm_driver_unload(struct drm_device *drm) | |
72 | { | |
8acba02f | 73 | #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER) |
e692da4d | 74 | struct imx_drm_device *imxdrm = drm->dev_private; |
3e68439b RK |
75 | #endif |
76 | ||
77 | drm_kms_helper_poll_fini(drm); | |
e692da4d | 78 | |
3e68439b | 79 | #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER) |
8acba02f RK |
80 | if (imxdrm->fbhelper) |
81 | drm_fbdev_cma_fini(imxdrm->fbhelper); | |
82 | #endif | |
83 | ||
17b5001b RK |
84 | component_unbind_all(drm->dev, drm); |
85 | ||
020a9ea7 | 86 | drm_vblank_cleanup(drm); |
020a9ea7 | 87 | drm_mode_config_cleanup(drm); |
e692da4d | 88 | |
bfe945c8 SG |
89 | platform_set_drvdata(drm->platformdev, NULL); |
90 | ||
e692da4d SH |
91 | return 0; |
92 | } | |
93 | ||
fdffa6f2 | 94 | static struct imx_drm_crtc *imx_drm_find_crtc(struct drm_crtc *crtc) |
e692da4d | 95 | { |
32266b45 | 96 | struct imx_drm_device *imxdrm = crtc->dev->dev_private; |
887eceac RK |
97 | unsigned i; |
98 | ||
99 | for (i = 0; i < MAX_CRTC; i++) | |
100 | if (imxdrm->crtc[i] && imxdrm->crtc[i]->crtc == crtc) | |
101 | return imxdrm->crtc[i]; | |
e692da4d | 102 | |
e692da4d SH |
103 | return NULL; |
104 | } | |
105 | ||
f2d66aad | 106 | int imx_drm_panel_format_pins(struct drm_encoder *encoder, |
2ea42608 | 107 | u32 interface_pix_fmt, int hsync_pin, int vsync_pin) |
e692da4d | 108 | { |
e692da4d | 109 | struct imx_drm_crtc_helper_funcs *helper; |
887eceac | 110 | struct imx_drm_crtc *imx_crtc; |
e692da4d | 111 | |
f2d66aad | 112 | imx_crtc = imx_drm_find_crtc(encoder->crtc); |
887eceac RK |
113 | if (!imx_crtc) |
114 | return -EINVAL; | |
e692da4d | 115 | |
e692da4d SH |
116 | helper = &imx_crtc->imx_drm_helper_funcs; |
117 | if (helper->set_interface_pix_fmt) | |
f2d66aad | 118 | return helper->set_interface_pix_fmt(encoder->crtc, |
d50141d8 | 119 | interface_pix_fmt, hsync_pin, vsync_pin); |
e692da4d SH |
120 | return 0; |
121 | } | |
f2d66aad | 122 | EXPORT_SYMBOL_GPL(imx_drm_panel_format_pins); |
2ea42608 | 123 | |
f2d66aad | 124 | int imx_drm_panel_format(struct drm_encoder *encoder, u32 interface_pix_fmt) |
2ea42608 | 125 | { |
f2d66aad | 126 | return imx_drm_panel_format_pins(encoder, interface_pix_fmt, 2, 3); |
2ea42608 | 127 | } |
f2d66aad | 128 | EXPORT_SYMBOL_GPL(imx_drm_panel_format); |
e692da4d SH |
129 | |
130 | int imx_drm_crtc_vblank_get(struct imx_drm_crtc *imx_drm_crtc) | |
131 | { | |
b5ea1492 | 132 | return drm_vblank_get(imx_drm_crtc->crtc->dev, imx_drm_crtc->pipe); |
e692da4d SH |
133 | } |
134 | EXPORT_SYMBOL_GPL(imx_drm_crtc_vblank_get); | |
135 | ||
136 | void imx_drm_crtc_vblank_put(struct imx_drm_crtc *imx_drm_crtc) | |
137 | { | |
b5ea1492 | 138 | drm_vblank_put(imx_drm_crtc->crtc->dev, imx_drm_crtc->pipe); |
e692da4d SH |
139 | } |
140 | EXPORT_SYMBOL_GPL(imx_drm_crtc_vblank_put); | |
141 | ||
142 | void imx_drm_handle_vblank(struct imx_drm_crtc *imx_drm_crtc) | |
143 | { | |
b5ea1492 | 144 | drm_handle_vblank(imx_drm_crtc->crtc->dev, imx_drm_crtc->pipe); |
e692da4d SH |
145 | } |
146 | EXPORT_SYMBOL_GPL(imx_drm_handle_vblank); | |
147 | ||
148 | static int imx_drm_enable_vblank(struct drm_device *drm, int crtc) | |
149 | { | |
150 | struct imx_drm_device *imxdrm = drm->dev_private; | |
887eceac | 151 | struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[crtc]; |
e692da4d SH |
152 | int ret; |
153 | ||
e692da4d SH |
154 | if (!imx_drm_crtc) |
155 | return -EINVAL; | |
156 | ||
157 | if (!imx_drm_crtc->imx_drm_helper_funcs.enable_vblank) | |
158 | return -ENOSYS; | |
159 | ||
160 | ret = imx_drm_crtc->imx_drm_helper_funcs.enable_vblank( | |
161 | imx_drm_crtc->crtc); | |
162 | ||
163 | return ret; | |
164 | } | |
165 | ||
166 | static void imx_drm_disable_vblank(struct drm_device *drm, int crtc) | |
167 | { | |
168 | struct imx_drm_device *imxdrm = drm->dev_private; | |
887eceac | 169 | struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[crtc]; |
e692da4d | 170 | |
e692da4d SH |
171 | if (!imx_drm_crtc) |
172 | return; | |
173 | ||
174 | if (!imx_drm_crtc->imx_drm_helper_funcs.disable_vblank) | |
175 | return; | |
176 | ||
177 | imx_drm_crtc->imx_drm_helper_funcs.disable_vblank(imx_drm_crtc->crtc); | |
178 | } | |
179 | ||
6ee4d7fe SH |
180 | static void imx_drm_driver_preclose(struct drm_device *drm, |
181 | struct drm_file *file) | |
182 | { | |
183 | int i; | |
184 | ||
185 | if (!file->is_master) | |
186 | return; | |
187 | ||
942325c8 RK |
188 | for (i = 0; i < MAX_CRTC; i++) |
189 | imx_drm_disable_vblank(drm, i); | |
6ee4d7fe SH |
190 | } |
191 | ||
e692da4d SH |
192 | static const struct file_operations imx_drm_driver_fops = { |
193 | .owner = THIS_MODULE, | |
194 | .open = drm_open, | |
195 | .release = drm_release, | |
196 | .unlocked_ioctl = drm_ioctl, | |
197 | .mmap = drm_gem_cma_mmap, | |
198 | .poll = drm_poll, | |
e692da4d SH |
199 | .read = drm_read, |
200 | .llseek = noop_llseek, | |
201 | }; | |
202 | ||
8a51a33b RK |
203 | void imx_drm_connector_destroy(struct drm_connector *connector) |
204 | { | |
34ea3d38 | 205 | drm_connector_unregister(connector); |
8a51a33b RK |
206 | drm_connector_cleanup(connector); |
207 | } | |
208 | EXPORT_SYMBOL_GPL(imx_drm_connector_destroy); | |
209 | ||
210 | void imx_drm_encoder_destroy(struct drm_encoder *encoder) | |
211 | { | |
212 | drm_encoder_cleanup(encoder); | |
213 | } | |
214 | EXPORT_SYMBOL_GPL(imx_drm_encoder_destroy); | |
215 | ||
3e68439b RK |
216 | static void imx_drm_output_poll_changed(struct drm_device *drm) |
217 | { | |
218 | #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER) | |
219 | struct imx_drm_device *imxdrm = drm->dev_private; | |
220 | ||
221 | drm_fbdev_cma_hotplug_event(imxdrm->fbhelper); | |
222 | #endif | |
223 | } | |
224 | ||
1df8b530 RK |
225 | static struct drm_mode_config_funcs imx_drm_mode_config_funcs = { |
226 | .fb_create = drm_fb_cma_create, | |
3e68439b | 227 | .output_poll_changed = imx_drm_output_poll_changed, |
1df8b530 RK |
228 | }; |
229 | ||
e692da4d | 230 | /* |
17b5001b RK |
231 | * Main DRM initialisation. This binds, initialises and registers |
232 | * with DRM the subcomponents of the driver. | |
e692da4d SH |
233 | */ |
234 | static int imx_drm_driver_load(struct drm_device *drm, unsigned long flags) | |
235 | { | |
b85f2b5d | 236 | struct imx_drm_device *imxdrm; |
e355e7dd | 237 | struct drm_connector *connector; |
e692da4d SH |
238 | int ret; |
239 | ||
b85f2b5d RK |
240 | imxdrm = devm_kzalloc(drm->dev, sizeof(*imxdrm), GFP_KERNEL); |
241 | if (!imxdrm) | |
242 | return -ENOMEM; | |
243 | ||
e692da4d SH |
244 | imxdrm->drm = drm; |
245 | ||
246 | drm->dev_private = imxdrm; | |
247 | ||
248 | /* | |
249 | * enable drm irq mode. | |
4423843c | 250 | * - with irq_enabled = true, we can use the vblank feature. |
e692da4d SH |
251 | * |
252 | * P.S. note that we wouldn't use drm irq handler but | |
253 | * just specific driver own one instead because | |
254 | * drm framework supports only one irq handler and | |
255 | * drivers can well take care of their interrupts | |
256 | */ | |
4423843c | 257 | drm->irq_enabled = true; |
e692da4d | 258 | |
1df8b530 RK |
259 | /* |
260 | * set max width and height as default value(4096x4096). | |
261 | * this value would be used to check framebuffer size limitation | |
262 | * at drm_mode_addfb(). | |
263 | */ | |
264 | drm->mode_config.min_width = 64; | |
265 | drm->mode_config.min_height = 64; | |
266 | drm->mode_config.max_width = 4096; | |
267 | drm->mode_config.max_height = 4096; | |
268 | drm->mode_config.funcs = &imx_drm_mode_config_funcs; | |
269 | ||
e692da4d | 270 | drm_mode_config_init(drm); |
e692da4d | 271 | |
020a9ea7 | 272 | ret = drm_vblank_init(drm, MAX_CRTC); |
e692da4d | 273 | if (ret) |
8007875f | 274 | goto err_kms; |
e692da4d SH |
275 | |
276 | /* | |
e7d6231e RK |
277 | * with vblank_disable_allowed = true, vblank interrupt will be |
278 | * disabled by drm timer once a current process gives up ownership | |
279 | * of vblank event. (after drm_vblank_put function is called) | |
e692da4d | 280 | */ |
020a9ea7 | 281 | drm->vblank_disable_allowed = true; |
e692da4d | 282 | |
a72f8bee | 283 | platform_set_drvdata(drm->platformdev, drm); |
8d71de61 | 284 | |
17b5001b RK |
285 | /* Now try and bind all our sub-components */ |
286 | ret = component_bind_all(drm->dev, drm); | |
287 | if (ret) | |
ccec7f62 | 288 | goto err_vblank; |
e355e7dd RK |
289 | |
290 | /* | |
291 | * All components are now added, we can publish the connector sysfs | |
292 | * entries to userspace. This will generate hotplug events and so | |
293 | * userspace will expect to be able to access DRM at this point. | |
294 | */ | |
295 | list_for_each_entry(connector, &drm->mode_config.connector_list, head) { | |
34ea3d38 | 296 | ret = drm_connector_register(connector); |
e355e7dd RK |
297 | if (ret) { |
298 | dev_err(drm->dev, | |
34ea3d38 | 299 | "[CONNECTOR:%d:%s] drm_connector_register failed: %d\n", |
e355e7dd | 300 | connector->base.id, |
4a2a450f | 301 | connector->name, ret); |
e355e7dd RK |
302 | goto err_unbind; |
303 | } | |
304 | } | |
305 | ||
8acba02f RK |
306 | /* |
307 | * All components are now initialised, so setup the fb helper. | |
308 | * The fb helper takes copies of key hardware information, so the | |
309 | * crtcs/connectors/encoders must not change after this point. | |
310 | */ | |
311 | #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER) | |
312 | if (legacyfb_depth != 16 && legacyfb_depth != 32) { | |
313 | dev_warn(drm->dev, "Invalid legacyfb_depth. Defaulting to 16bpp\n"); | |
314 | legacyfb_depth = 16; | |
315 | } | |
316 | imxdrm->fbhelper = drm_fbdev_cma_init(drm, legacyfb_depth, | |
317 | drm->mode_config.num_crtc, MAX_CRTC); | |
318 | if (IS_ERR(imxdrm->fbhelper)) { | |
319 | ret = PTR_ERR(imxdrm->fbhelper); | |
320 | imxdrm->fbhelper = NULL; | |
321 | goto err_unbind; | |
322 | } | |
323 | #endif | |
3e68439b RK |
324 | |
325 | drm_kms_helper_poll_init(drm); | |
326 | ||
8007875f | 327 | return 0; |
a72f8bee | 328 | |
e355e7dd RK |
329 | err_unbind: |
330 | component_unbind_all(drm->dev, drm); | |
ccec7f62 | 331 | err_vblank: |
8007875f RK |
332 | drm_vblank_cleanup(drm); |
333 | err_kms: | |
8007875f | 334 | drm_mode_config_cleanup(drm); |
e692da4d SH |
335 | |
336 | return ret; | |
337 | } | |
338 | ||
e692da4d SH |
339 | /* |
340 | * imx_drm_add_crtc - add a new crtc | |
e692da4d | 341 | */ |
32266b45 | 342 | int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc, |
e692da4d SH |
343 | struct imx_drm_crtc **new_crtc, |
344 | const struct imx_drm_crtc_helper_funcs *imx_drm_helper_funcs, | |
655b43cc | 345 | struct device_node *port) |
e692da4d | 346 | { |
32266b45 | 347 | struct imx_drm_device *imxdrm = drm->dev_private; |
e692da4d | 348 | struct imx_drm_crtc *imx_drm_crtc; |
e692da4d SH |
349 | int ret; |
350 | ||
fd6040ed RK |
351 | /* |
352 | * The vblank arrays are dimensioned by MAX_CRTC - we can't | |
353 | * pass IDs greater than this to those functions. | |
354 | */ | |
e7d6231e RK |
355 | if (imxdrm->pipes >= MAX_CRTC) |
356 | return -EINVAL; | |
fd6040ed | 357 | |
e7d6231e RK |
358 | if (imxdrm->drm->open_count) |
359 | return -EBUSY; | |
e692da4d SH |
360 | |
361 | imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL); | |
e7d6231e RK |
362 | if (!imx_drm_crtc) |
363 | return -ENOMEM; | |
e692da4d SH |
364 | |
365 | imx_drm_crtc->imx_drm_helper_funcs = *imx_drm_helper_funcs; | |
366 | imx_drm_crtc->pipe = imxdrm->pipes++; | |
e692da4d | 367 | imx_drm_crtc->crtc = crtc; |
e692da4d | 368 | |
6457b971 RK |
369 | crtc->port = port; |
370 | ||
887eceac | 371 | imxdrm->crtc[imx_drm_crtc->pipe] = imx_drm_crtc; |
e692da4d SH |
372 | |
373 | *new_crtc = imx_drm_crtc; | |
374 | ||
ec9557d7 | 375 | ret = drm_mode_crtc_set_gamma_size(imx_drm_crtc->crtc, 256); |
e692da4d SH |
376 | if (ret) |
377 | goto err_register; | |
378 | ||
ec9557d7 RK |
379 | drm_crtc_helper_add(crtc, |
380 | imx_drm_crtc->imx_drm_helper_funcs.crtc_helper_funcs); | |
381 | ||
32266b45 | 382 | drm_crtc_init(drm, crtc, |
ec9557d7 RK |
383 | imx_drm_crtc->imx_drm_helper_funcs.crtc_funcs); |
384 | ||
e692da4d SH |
385 | return 0; |
386 | ||
387 | err_register: | |
887eceac | 388 | imxdrm->crtc[imx_drm_crtc->pipe] = NULL; |
e692da4d | 389 | kfree(imx_drm_crtc); |
e692da4d SH |
390 | return ret; |
391 | } | |
392 | EXPORT_SYMBOL_GPL(imx_drm_add_crtc); | |
393 | ||
394 | /* | |
395 | * imx_drm_remove_crtc - remove a crtc | |
396 | */ | |
397 | int imx_drm_remove_crtc(struct imx_drm_crtc *imx_drm_crtc) | |
398 | { | |
ccec7f62 | 399 | struct imx_drm_device *imxdrm = imx_drm_crtc->crtc->dev->dev_private; |
e692da4d SH |
400 | |
401 | drm_crtc_cleanup(imx_drm_crtc->crtc); | |
402 | ||
887eceac | 403 | imxdrm->crtc[imx_drm_crtc->pipe] = NULL; |
e692da4d | 404 | |
e692da4d SH |
405 | kfree(imx_drm_crtc); |
406 | ||
407 | return 0; | |
408 | } | |
409 | EXPORT_SYMBOL_GPL(imx_drm_remove_crtc); | |
410 | ||
6457b971 RK |
411 | int imx_drm_encoder_parse_of(struct drm_device *drm, |
412 | struct drm_encoder *encoder, struct device_node *np) | |
9e2d410d | 413 | { |
6457b971 | 414 | uint32_t crtc_mask = drm_of_find_possible_crtcs(drm, np); |
9e2d410d | 415 | |
6457b971 RK |
416 | /* |
417 | * If we failed to find the CRTC(s) which this encoder is | |
418 | * supposed to be connected to, it's because the CRTC has | |
419 | * not been registered yet. Defer probing, and hope that | |
420 | * the required CRTC is added later. | |
421 | */ | |
422 | if (crtc_mask == 0) | |
423 | return -EPROBE_DEFER; | |
655b43cc | 424 | |
6457b971 | 425 | encoder->possible_crtcs = crtc_mask; |
63bc5164 | 426 | |
6457b971 RK |
427 | /* FIXME: this is the mask of outputs which can clone this output. */ |
428 | encoder->possible_clones = ~0; | |
9e2d410d RK |
429 | |
430 | return 0; | |
431 | } | |
6457b971 | 432 | EXPORT_SYMBOL_GPL(imx_drm_encoder_parse_of); |
9e2d410d | 433 | |
655b43cc PZ |
434 | /* |
435 | * @node: device tree node containing encoder input ports | |
436 | * @encoder: drm_encoder | |
437 | */ | |
438 | int imx_drm_encoder_get_mux_id(struct device_node *node, | |
439 | struct drm_encoder *encoder) | |
e692da4d | 440 | { |
887eceac | 441 | struct imx_drm_crtc *imx_crtc = imx_drm_find_crtc(encoder->crtc); |
655b43cc | 442 | struct device_node *ep = NULL; |
b6babdd9 | 443 | struct of_endpoint endpoint; |
655b43cc | 444 | struct device_node *port; |
b6babdd9 | 445 | int ret; |
e692da4d | 446 | |
655b43cc PZ |
447 | if (!node || !imx_crtc) |
448 | return -EINVAL; | |
449 | ||
450 | do { | |
f033c0bc | 451 | ep = of_graph_get_next_endpoint(node, ep); |
655b43cc PZ |
452 | if (!ep) |
453 | break; | |
454 | ||
455 | port = of_graph_get_remote_port(ep); | |
456 | of_node_put(port); | |
6457b971 | 457 | if (port == imx_crtc->crtc->port) { |
b6babdd9 | 458 | ret = of_graph_parse_endpoint(ep, &endpoint); |
c509bdc2 | 459 | return ret ? ret : endpoint.port; |
655b43cc PZ |
460 | } |
461 | } while (ep); | |
e692da4d | 462 | |
655b43cc | 463 | return -EINVAL; |
e692da4d | 464 | } |
ea8d1583 | 465 | EXPORT_SYMBOL_GPL(imx_drm_encoder_get_mux_id); |
e692da4d | 466 | |
baa70943 | 467 | static const struct drm_ioctl_desc imx_drm_ioctls[] = { |
e692da4d SH |
468 | /* none so far */ |
469 | }; | |
470 | ||
471 | static struct drm_driver imx_drm_driver = { | |
bd3665c9 | 472 | .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME, |
e692da4d SH |
473 | .load = imx_drm_driver_load, |
474 | .unload = imx_drm_driver_unload, | |
e692da4d | 475 | .lastclose = imx_drm_driver_lastclose, |
6ee4d7fe | 476 | .preclose = imx_drm_driver_preclose, |
915b4d11 | 477 | .set_busid = drm_platform_set_busid, |
e692da4d SH |
478 | .gem_free_object = drm_gem_cma_free_object, |
479 | .gem_vm_ops = &drm_gem_cma_vm_ops, | |
480 | .dumb_create = drm_gem_cma_dumb_create, | |
481 | .dumb_map_offset = drm_gem_cma_dumb_map_offset, | |
43387b37 | 482 | .dumb_destroy = drm_gem_dumb_destroy, |
e692da4d | 483 | |
bd3665c9 PZ |
484 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
485 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, | |
486 | .gem_prime_import = drm_gem_prime_import, | |
487 | .gem_prime_export = drm_gem_prime_export, | |
488 | .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table, | |
489 | .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table, | |
490 | .gem_prime_vmap = drm_gem_cma_prime_vmap, | |
491 | .gem_prime_vunmap = drm_gem_cma_prime_vunmap, | |
492 | .gem_prime_mmap = drm_gem_cma_prime_mmap, | |
e692da4d SH |
493 | .get_vblank_counter = drm_vblank_count, |
494 | .enable_vblank = imx_drm_enable_vblank, | |
495 | .disable_vblank = imx_drm_disable_vblank, | |
496 | .ioctls = imx_drm_ioctls, | |
497 | .num_ioctls = ARRAY_SIZE(imx_drm_ioctls), | |
498 | .fops = &imx_drm_driver_fops, | |
499 | .name = "imx-drm", | |
500 | .desc = "i.MX DRM graphics", | |
501 | .date = "20120507", | |
502 | .major = 1, | |
503 | .minor = 0, | |
504 | .patchlevel = 0, | |
505 | }; | |
506 | ||
17b5001b RK |
507 | static int compare_of(struct device *dev, void *data) |
508 | { | |
655b43cc | 509 | struct device_node *np = data; |
17b5001b | 510 | |
655b43cc PZ |
511 | /* Special case for LDB, one device for two channels */ |
512 | if (of_node_cmp(np->name, "lvds-channel") == 0) { | |
513 | np = of_get_parent(np); | |
514 | of_node_put(np); | |
17b5001b RK |
515 | } |
516 | ||
655b43cc PZ |
517 | return dev->of_node == np; |
518 | } | |
17b5001b | 519 | |
17b5001b RK |
520 | static int imx_drm_bind(struct device *dev) |
521 | { | |
522 | return drm_platform_init(&imx_drm_driver, to_platform_device(dev)); | |
523 | } | |
524 | ||
525 | static void imx_drm_unbind(struct device *dev) | |
526 | { | |
527 | drm_put_dev(dev_get_drvdata(dev)); | |
528 | } | |
529 | ||
530 | static const struct component_master_ops imx_drm_ops = { | |
17b5001b RK |
531 | .bind = imx_drm_bind, |
532 | .unbind = imx_drm_unbind, | |
533 | }; | |
534 | ||
e692da4d SH |
535 | static int imx_drm_platform_probe(struct platform_device *pdev) |
536 | { | |
655b43cc | 537 | struct device_node *ep, *port, *remote; |
9e5e2ffd | 538 | struct component_match *match = NULL; |
4cdbb4ff | 539 | int ret; |
655b43cc PZ |
540 | int i; |
541 | ||
542 | /* | |
543 | * Bind the IPU display interface ports first, so that | |
544 | * imx_drm_encoder_parse_of called from encoder .bind callbacks | |
545 | * works as expected. | |
546 | */ | |
547 | for (i = 0; ; i++) { | |
548 | port = of_parse_phandle(pdev->dev.of_node, "ports", i); | |
549 | if (!port) | |
550 | break; | |
551 | ||
9e5e2ffd | 552 | component_match_add(&pdev->dev, &match, compare_of, port); |
655b43cc PZ |
553 | } |
554 | ||
555 | if (i == 0) { | |
556 | dev_err(&pdev->dev, "missing 'ports' property\n"); | |
557 | return -ENODEV; | |
558 | } | |
559 | ||
560 | /* Then bind all encoders */ | |
561 | for (i = 0; ; i++) { | |
562 | port = of_parse_phandle(pdev->dev.of_node, "ports", i); | |
563 | if (!port) | |
564 | break; | |
565 | ||
566 | for_each_child_of_node(port, ep) { | |
567 | remote = of_graph_get_remote_port_parent(ep); | |
568 | if (!remote || !of_device_is_available(remote)) { | |
569 | of_node_put(remote); | |
570 | continue; | |
1c236629 SG |
571 | } else if (!of_device_is_available(remote->parent)) { |
572 | dev_warn(&pdev->dev, "parent device of %s is not available\n", | |
573 | remote->full_name); | |
574 | of_node_put(remote); | |
575 | continue; | |
655b43cc PZ |
576 | } |
577 | ||
f582d9a8 RK |
578 | component_match_add(&pdev->dev, &match, compare_of, |
579 | remote); | |
655b43cc | 580 | of_node_put(remote); |
655b43cc PZ |
581 | } |
582 | of_node_put(port); | |
583 | } | |
4cdbb4ff RK |
584 | |
585 | ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); | |
586 | if (ret) | |
587 | return ret; | |
588 | ||
9e5e2ffd | 589 | return component_master_add_with_match(&pdev->dev, &imx_drm_ops, match); |
e692da4d SH |
590 | } |
591 | ||
592 | static int imx_drm_platform_remove(struct platform_device *pdev) | |
593 | { | |
17b5001b | 594 | component_master_del(&pdev->dev, &imx_drm_ops); |
e692da4d SH |
595 | return 0; |
596 | } | |
597 | ||
bfe945c8 SG |
598 | #ifdef CONFIG_PM_SLEEP |
599 | static int imx_drm_suspend(struct device *dev) | |
600 | { | |
601 | struct drm_device *drm_dev = dev_get_drvdata(dev); | |
602 | ||
603 | /* The drm_dev is NULL before .load hook is called */ | |
604 | if (drm_dev == NULL) | |
605 | return 0; | |
606 | ||
607 | drm_kms_helper_poll_disable(drm_dev); | |
608 | ||
609 | return 0; | |
610 | } | |
611 | ||
612 | static int imx_drm_resume(struct device *dev) | |
613 | { | |
614 | struct drm_device *drm_dev = dev_get_drvdata(dev); | |
615 | ||
616 | if (drm_dev == NULL) | |
617 | return 0; | |
618 | ||
619 | drm_helper_resume_force_mode(drm_dev); | |
620 | drm_kms_helper_poll_enable(drm_dev); | |
621 | ||
622 | return 0; | |
623 | } | |
624 | #endif | |
625 | ||
626 | static SIMPLE_DEV_PM_OPS(imx_drm_pm_ops, imx_drm_suspend, imx_drm_resume); | |
627 | ||
17b5001b | 628 | static const struct of_device_id imx_drm_dt_ids[] = { |
655b43cc | 629 | { .compatible = "fsl,imx-display-subsystem", }, |
17b5001b RK |
630 | { /* sentinel */ }, |
631 | }; | |
632 | MODULE_DEVICE_TABLE(of, imx_drm_dt_ids); | |
633 | ||
e692da4d SH |
634 | static struct platform_driver imx_drm_pdrv = { |
635 | .probe = imx_drm_platform_probe, | |
99c28f10 | 636 | .remove = imx_drm_platform_remove, |
e692da4d | 637 | .driver = { |
e692da4d | 638 | .name = "imx-drm", |
bfe945c8 | 639 | .pm = &imx_drm_pm_ops, |
17b5001b | 640 | .of_match_table = imx_drm_dt_ids, |
e692da4d SH |
641 | }, |
642 | }; | |
b85f2b5d | 643 | module_platform_driver(imx_drm_pdrv); |
e692da4d SH |
644 | |
645 | MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); | |
646 | MODULE_DESCRIPTION("i.MX drm driver core"); | |
647 | MODULE_LICENSE("GPL"); |