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