]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/staging/imx-drm/imx-drm-core.c
imx-drm: imx-drm-core: Fix circular locking dependency
[mirror_ubuntu-artful-kernel.git] / drivers / staging / imx-drm / imx-drm-core.c
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 */
16
17 #include <linux/device.h>
18 #include <linux/platform_device.h>
19 #include <drm/drmP.h>
20 #include <drm/drm_fb_helper.h>
21 #include <drm/drm_crtc_helper.h>
22 #include <linux/fb.h>
23 #include <linux/module.h>
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
31 struct crtc_cookie {
32 void *cookie;
33 int id;
34 struct list_head list;
35 };
36
37 struct imx_drm_device {
38 struct drm_device *drm;
39 struct device *dev;
40 struct list_head crtc_list;
41 struct list_head encoder_list;
42 struct list_head connector_list;
43 struct mutex mutex;
44 int pipes;
45 struct drm_fbdev_cma *fbhelper;
46 };
47
48 struct imx_drm_crtc {
49 struct drm_crtc *crtc;
50 struct list_head list;
51 struct imx_drm_device *imxdrm;
52 int pipe;
53 struct imx_drm_crtc_helper_funcs imx_drm_helper_funcs;
54 struct module *owner;
55 struct crtc_cookie cookie;
56 };
57
58 struct imx_drm_encoder {
59 struct drm_encoder *encoder;
60 struct list_head list;
61 struct module *owner;
62 struct list_head possible_crtcs;
63 };
64
65 struct imx_drm_connector {
66 struct drm_connector *connector;
67 struct list_head list;
68 struct module *owner;
69 };
70
71 static void imx_drm_driver_lastclose(struct drm_device *drm)
72 {
73 struct imx_drm_device *imxdrm = drm->dev_private;
74
75 if (imxdrm->fbhelper)
76 drm_fbdev_cma_restore_mode(imxdrm->fbhelper);
77 }
78
79 static int imx_drm_driver_unload(struct drm_device *drm)
80 {
81 struct imx_drm_device *imxdrm = drm->dev_private;
82
83 imx_drm_device_put();
84
85 drm_mode_config_cleanup(imxdrm->drm);
86 drm_kms_helper_poll_fini(imxdrm->drm);
87
88 return 0;
89 }
90
91 /*
92 * We don't care at all for crtc numbers, but the core expects the
93 * crtcs to be numbered
94 */
95 static struct imx_drm_crtc *imx_drm_crtc_by_num(struct imx_drm_device *imxdrm,
96 int num)
97 {
98 struct imx_drm_crtc *imx_drm_crtc;
99
100 list_for_each_entry(imx_drm_crtc, &imxdrm->crtc_list, list)
101 if (imx_drm_crtc->pipe == num)
102 return imx_drm_crtc;
103 return NULL;
104 }
105
106 int imx_drm_crtc_panel_format_pins(struct drm_crtc *crtc, u32 encoder_type,
107 u32 interface_pix_fmt, int hsync_pin, int vsync_pin)
108 {
109 struct imx_drm_device *imxdrm = crtc->dev->dev_private;
110 struct imx_drm_crtc *imx_crtc;
111 struct imx_drm_crtc_helper_funcs *helper;
112
113 list_for_each_entry(imx_crtc, &imxdrm->crtc_list, list)
114 if (imx_crtc->crtc == crtc)
115 goto found;
116
117 return -EINVAL;
118 found:
119 helper = &imx_crtc->imx_drm_helper_funcs;
120 if (helper->set_interface_pix_fmt)
121 return helper->set_interface_pix_fmt(crtc,
122 encoder_type, interface_pix_fmt,
123 hsync_pin, vsync_pin);
124 return 0;
125 }
126 EXPORT_SYMBOL_GPL(imx_drm_crtc_panel_format_pins);
127
128 int imx_drm_crtc_panel_format(struct drm_crtc *crtc, u32 encoder_type,
129 u32 interface_pix_fmt)
130 {
131 return imx_drm_crtc_panel_format_pins(crtc, encoder_type,
132 interface_pix_fmt, 2, 3);
133 }
134 EXPORT_SYMBOL_GPL(imx_drm_crtc_panel_format);
135
136 int imx_drm_crtc_vblank_get(struct imx_drm_crtc *imx_drm_crtc)
137 {
138 return drm_vblank_get(imx_drm_crtc->imxdrm->drm, imx_drm_crtc->pipe);
139 }
140 EXPORT_SYMBOL_GPL(imx_drm_crtc_vblank_get);
141
142 void imx_drm_crtc_vblank_put(struct imx_drm_crtc *imx_drm_crtc)
143 {
144 drm_vblank_put(imx_drm_crtc->imxdrm->drm, imx_drm_crtc->pipe);
145 }
146 EXPORT_SYMBOL_GPL(imx_drm_crtc_vblank_put);
147
148 void imx_drm_handle_vblank(struct imx_drm_crtc *imx_drm_crtc)
149 {
150 drm_handle_vblank(imx_drm_crtc->imxdrm->drm, imx_drm_crtc->pipe);
151 }
152 EXPORT_SYMBOL_GPL(imx_drm_handle_vblank);
153
154 static int imx_drm_enable_vblank(struct drm_device *drm, int crtc)
155 {
156 struct imx_drm_device *imxdrm = drm->dev_private;
157 struct imx_drm_crtc *imx_drm_crtc;
158 int ret;
159
160 imx_drm_crtc = imx_drm_crtc_by_num(imxdrm, crtc);
161 if (!imx_drm_crtc)
162 return -EINVAL;
163
164 if (!imx_drm_crtc->imx_drm_helper_funcs.enable_vblank)
165 return -ENOSYS;
166
167 ret = imx_drm_crtc->imx_drm_helper_funcs.enable_vblank(
168 imx_drm_crtc->crtc);
169
170 return ret;
171 }
172
173 static void imx_drm_disable_vblank(struct drm_device *drm, int crtc)
174 {
175 struct imx_drm_device *imxdrm = drm->dev_private;
176 struct imx_drm_crtc *imx_drm_crtc;
177
178 imx_drm_crtc = imx_drm_crtc_by_num(imxdrm, crtc);
179 if (!imx_drm_crtc)
180 return;
181
182 if (!imx_drm_crtc->imx_drm_helper_funcs.disable_vblank)
183 return;
184
185 imx_drm_crtc->imx_drm_helper_funcs.disable_vblank(imx_drm_crtc->crtc);
186 }
187
188 static const struct file_operations imx_drm_driver_fops = {
189 .owner = THIS_MODULE,
190 .open = drm_open,
191 .release = drm_release,
192 .unlocked_ioctl = drm_ioctl,
193 .mmap = drm_gem_cma_mmap,
194 .poll = drm_poll,
195 .read = drm_read,
196 .llseek = noop_llseek,
197 };
198
199 static struct imx_drm_device *imx_drm_device;
200
201 static struct imx_drm_device *__imx_drm_device(void)
202 {
203 return imx_drm_device;
204 }
205
206 struct drm_device *imx_drm_device_get(void)
207 {
208 struct imx_drm_device *imxdrm = __imx_drm_device();
209 struct imx_drm_encoder *enc;
210 struct imx_drm_connector *con;
211 struct imx_drm_crtc *crtc;
212
213 list_for_each_entry(enc, &imxdrm->encoder_list, list) {
214 if (!try_module_get(enc->owner)) {
215 dev_err(imxdrm->dev, "could not get module %s\n",
216 module_name(enc->owner));
217 goto unwind_enc;
218 }
219 }
220
221 list_for_each_entry(con, &imxdrm->connector_list, list) {
222 if (!try_module_get(con->owner)) {
223 dev_err(imxdrm->dev, "could not get module %s\n",
224 module_name(con->owner));
225 goto unwind_con;
226 }
227 }
228
229 list_for_each_entry(crtc, &imxdrm->crtc_list, list) {
230 if (!try_module_get(crtc->owner)) {
231 dev_err(imxdrm->dev, "could not get module %s\n",
232 module_name(crtc->owner));
233 goto unwind_crtc;
234 }
235 }
236
237 return imxdrm->drm;
238
239 unwind_crtc:
240 list_for_each_entry_continue_reverse(crtc, &imxdrm->crtc_list, list)
241 module_put(crtc->owner);
242 unwind_con:
243 list_for_each_entry_continue_reverse(con, &imxdrm->connector_list, list)
244 module_put(con->owner);
245 unwind_enc:
246 list_for_each_entry_continue_reverse(enc, &imxdrm->encoder_list, list)
247 module_put(enc->owner);
248
249 mutex_unlock(&imxdrm->mutex);
250
251 return NULL;
252
253 }
254 EXPORT_SYMBOL_GPL(imx_drm_device_get);
255
256 void imx_drm_device_put(void)
257 {
258 struct imx_drm_device *imxdrm = __imx_drm_device();
259 struct imx_drm_encoder *enc;
260 struct imx_drm_connector *con;
261 struct imx_drm_crtc *crtc;
262
263 mutex_lock(&imxdrm->mutex);
264
265 list_for_each_entry(crtc, &imxdrm->crtc_list, list)
266 module_put(crtc->owner);
267
268 list_for_each_entry(con, &imxdrm->connector_list, list)
269 module_put(con->owner);
270
271 list_for_each_entry(enc, &imxdrm->encoder_list, list)
272 module_put(enc->owner);
273
274 mutex_unlock(&imxdrm->mutex);
275 }
276 EXPORT_SYMBOL_GPL(imx_drm_device_put);
277
278 static int drm_mode_group_reinit(struct drm_device *dev)
279 {
280 struct drm_mode_group *group = &dev->primary->mode_group;
281 uint32_t *id_list = group->id_list;
282 int ret;
283
284 ret = drm_mode_group_init_legacy_group(dev, group);
285 if (ret < 0)
286 return ret;
287
288 kfree(id_list);
289 return 0;
290 }
291
292 /*
293 * register an encoder to the drm core
294 */
295 static int imx_drm_encoder_register(struct imx_drm_encoder *imx_drm_encoder)
296 {
297 struct imx_drm_device *imxdrm = __imx_drm_device();
298
299 INIT_LIST_HEAD(&imx_drm_encoder->possible_crtcs);
300
301 drm_encoder_init(imxdrm->drm, imx_drm_encoder->encoder,
302 imx_drm_encoder->encoder->funcs,
303 imx_drm_encoder->encoder->encoder_type);
304
305 drm_mode_group_reinit(imxdrm->drm);
306
307 return 0;
308 }
309
310 /*
311 * unregister an encoder from the drm core
312 */
313 static void imx_drm_encoder_unregister(struct imx_drm_encoder
314 *imx_drm_encoder)
315 {
316 struct imx_drm_device *imxdrm = __imx_drm_device();
317
318 drm_encoder_cleanup(imx_drm_encoder->encoder);
319
320 drm_mode_group_reinit(imxdrm->drm);
321 }
322
323 /*
324 * register a connector to the drm core
325 */
326 static int imx_drm_connector_register(
327 struct imx_drm_connector *imx_drm_connector)
328 {
329 struct imx_drm_device *imxdrm = __imx_drm_device();
330
331 drm_connector_init(imxdrm->drm, imx_drm_connector->connector,
332 imx_drm_connector->connector->funcs,
333 imx_drm_connector->connector->connector_type);
334 drm_mode_group_reinit(imxdrm->drm);
335
336 return drm_sysfs_connector_add(imx_drm_connector->connector);
337 }
338
339 /*
340 * unregister a connector from the drm core
341 */
342 static void imx_drm_connector_unregister(
343 struct imx_drm_connector *imx_drm_connector)
344 {
345 struct imx_drm_device *imxdrm = __imx_drm_device();
346
347 drm_sysfs_connector_remove(imx_drm_connector->connector);
348 drm_connector_cleanup(imx_drm_connector->connector);
349
350 drm_mode_group_reinit(imxdrm->drm);
351 }
352
353 /*
354 * register a crtc to the drm core
355 */
356 static int imx_drm_crtc_register(struct imx_drm_crtc *imx_drm_crtc)
357 {
358 struct imx_drm_device *imxdrm = __imx_drm_device();
359 int ret;
360
361 drm_crtc_init(imxdrm->drm, imx_drm_crtc->crtc,
362 imx_drm_crtc->imx_drm_helper_funcs.crtc_funcs);
363 ret = drm_mode_crtc_set_gamma_size(imx_drm_crtc->crtc, 256);
364 if (ret)
365 return ret;
366
367 drm_crtc_helper_add(imx_drm_crtc->crtc,
368 imx_drm_crtc->imx_drm_helper_funcs.crtc_helper_funcs);
369
370 drm_mode_group_reinit(imxdrm->drm);
371
372 return 0;
373 }
374
375 /*
376 * Called by the CRTC driver when all CRTCs are registered. This
377 * puts all the pieces together and initializes the driver.
378 * Once this is called no more CRTCs can be registered since
379 * the drm core has hardcoded the number of crtcs in several
380 * places.
381 */
382 static int imx_drm_driver_load(struct drm_device *drm, unsigned long flags)
383 {
384 struct imx_drm_device *imxdrm = __imx_drm_device();
385 int ret;
386
387 imxdrm->drm = drm;
388
389 drm->dev_private = imxdrm;
390
391 /*
392 * enable drm irq mode.
393 * - with irq_enabled = 1, we can use the vblank feature.
394 *
395 * P.S. note that we wouldn't use drm irq handler but
396 * just specific driver own one instead because
397 * drm framework supports only one irq handler and
398 * drivers can well take care of their interrupts
399 */
400 drm->irq_enabled = 1;
401
402 drm_mode_config_init(drm);
403 imx_drm_mode_config_init(drm);
404
405 mutex_lock(&imxdrm->mutex);
406
407 drm_kms_helper_poll_init(imxdrm->drm);
408
409 /* setup the grouping for the legacy output */
410 ret = drm_mode_group_init_legacy_group(imxdrm->drm,
411 &imxdrm->drm->primary->mode_group);
412 if (ret)
413 goto err_init;
414
415 ret = drm_vblank_init(imxdrm->drm, MAX_CRTC);
416 if (ret)
417 goto err_init;
418
419 /*
420 * with vblank_disable_allowed = 1, vblank interrupt will be disabled
421 * by drm timer once a current process gives up ownership of
422 * vblank event.(after drm_vblank_put function is called)
423 */
424 imxdrm->drm->vblank_disable_allowed = 1;
425
426 if (!imx_drm_device_get())
427 ret = -EINVAL;
428
429 ret = 0;
430
431 err_init:
432 mutex_unlock(&imxdrm->mutex);
433
434 return ret;
435 }
436
437 static void imx_drm_update_possible_crtcs(void)
438 {
439 struct imx_drm_device *imxdrm = __imx_drm_device();
440 struct imx_drm_crtc *imx_drm_crtc;
441 struct imx_drm_encoder *enc;
442 struct crtc_cookie *cookie;
443
444 list_for_each_entry(enc, &imxdrm->encoder_list, list) {
445 u32 possible_crtcs = 0;
446
447 list_for_each_entry(cookie, &enc->possible_crtcs, list) {
448 list_for_each_entry(imx_drm_crtc, &imxdrm->crtc_list, list) {
449 if (imx_drm_crtc->cookie.cookie == cookie->cookie &&
450 imx_drm_crtc->cookie.id == cookie->id) {
451 possible_crtcs |= 1 << imx_drm_crtc->pipe;
452 }
453 }
454 }
455 enc->encoder->possible_crtcs = possible_crtcs;
456 enc->encoder->possible_clones = possible_crtcs;
457 }
458 }
459
460 /*
461 * imx_drm_add_crtc - add a new crtc
462 *
463 * The return value if !NULL is a cookie for the caller to pass to
464 * imx_drm_remove_crtc later.
465 */
466 int imx_drm_add_crtc(struct drm_crtc *crtc,
467 struct imx_drm_crtc **new_crtc,
468 const struct imx_drm_crtc_helper_funcs *imx_drm_helper_funcs,
469 struct module *owner, void *cookie, int id)
470 {
471 struct imx_drm_device *imxdrm = __imx_drm_device();
472 struct imx_drm_crtc *imx_drm_crtc;
473 int ret;
474
475 mutex_lock(&imxdrm->mutex);
476
477 if (imxdrm->drm->open_count) {
478 ret = -EBUSY;
479 goto err_busy;
480 }
481
482 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
483 if (!imx_drm_crtc) {
484 ret = -ENOMEM;
485 goto err_alloc;
486 }
487
488 imx_drm_crtc->imx_drm_helper_funcs = *imx_drm_helper_funcs;
489 imx_drm_crtc->pipe = imxdrm->pipes++;
490 imx_drm_crtc->cookie.cookie = cookie;
491 imx_drm_crtc->cookie.id = id;
492
493 imx_drm_crtc->crtc = crtc;
494 imx_drm_crtc->imxdrm = imxdrm;
495
496 imx_drm_crtc->owner = owner;
497
498 list_add_tail(&imx_drm_crtc->list, &imxdrm->crtc_list);
499
500 *new_crtc = imx_drm_crtc;
501
502 ret = imx_drm_crtc_register(imx_drm_crtc);
503 if (ret)
504 goto err_register;
505
506 imx_drm_update_possible_crtcs();
507
508 mutex_unlock(&imxdrm->mutex);
509
510 return 0;
511
512 err_register:
513 kfree(imx_drm_crtc);
514 err_alloc:
515 err_busy:
516 mutex_unlock(&imxdrm->mutex);
517 return ret;
518 }
519 EXPORT_SYMBOL_GPL(imx_drm_add_crtc);
520
521 /*
522 * imx_drm_remove_crtc - remove a crtc
523 */
524 int imx_drm_remove_crtc(struct imx_drm_crtc *imx_drm_crtc)
525 {
526 struct imx_drm_device *imxdrm = imx_drm_crtc->imxdrm;
527
528 mutex_lock(&imxdrm->mutex);
529
530 drm_crtc_cleanup(imx_drm_crtc->crtc);
531
532 list_del(&imx_drm_crtc->list);
533
534 drm_mode_group_reinit(imxdrm->drm);
535
536 mutex_unlock(&imxdrm->mutex);
537
538 kfree(imx_drm_crtc);
539
540 return 0;
541 }
542 EXPORT_SYMBOL_GPL(imx_drm_remove_crtc);
543
544 /*
545 * imx_drm_add_encoder - add a new encoder
546 */
547 int imx_drm_add_encoder(struct drm_encoder *encoder,
548 struct imx_drm_encoder **newenc, struct module *owner)
549 {
550 struct imx_drm_device *imxdrm = __imx_drm_device();
551 struct imx_drm_encoder *imx_drm_encoder;
552 int ret;
553
554 mutex_lock(&imxdrm->mutex);
555
556 if (imxdrm->drm->open_count) {
557 ret = -EBUSY;
558 goto err_busy;
559 }
560
561 imx_drm_encoder = kzalloc(sizeof(*imx_drm_encoder), GFP_KERNEL);
562 if (!imx_drm_encoder) {
563 ret = -ENOMEM;
564 goto err_alloc;
565 }
566
567 imx_drm_encoder->encoder = encoder;
568 imx_drm_encoder->owner = owner;
569
570 ret = imx_drm_encoder_register(imx_drm_encoder);
571 if (ret) {
572 ret = -ENOMEM;
573 goto err_register;
574 }
575
576 list_add_tail(&imx_drm_encoder->list, &imxdrm->encoder_list);
577
578 *newenc = imx_drm_encoder;
579
580 mutex_unlock(&imxdrm->mutex);
581
582 return 0;
583
584 err_register:
585 kfree(imx_drm_encoder);
586 err_alloc:
587 err_busy:
588 mutex_unlock(&imxdrm->mutex);
589
590 return ret;
591 }
592 EXPORT_SYMBOL_GPL(imx_drm_add_encoder);
593
594 int imx_drm_encoder_add_possible_crtcs(
595 struct imx_drm_encoder *imx_drm_encoder,
596 struct device_node *np)
597 {
598 struct imx_drm_device *imxdrm = __imx_drm_device();
599 struct of_phandle_args args;
600 struct crtc_cookie *c;
601 int ret = 0;
602 int i;
603
604 if (!list_empty(&imx_drm_encoder->possible_crtcs))
605 return -EBUSY;
606
607 for (i = 0; !ret; i++) {
608 ret = of_parse_phandle_with_args(np, "crtcs",
609 "#crtc-cells", i, &args);
610 if (ret < 0)
611 break;
612
613 c = kzalloc(sizeof(*c), GFP_KERNEL);
614 if (!c) {
615 of_node_put(args.np);
616 return -ENOMEM;
617 }
618
619 c->cookie = args.np;
620 c->id = args.args_count > 0 ? args.args[0] : 0;
621
622 of_node_put(args.np);
623
624 mutex_lock(&imxdrm->mutex);
625
626 list_add_tail(&c->list, &imx_drm_encoder->possible_crtcs);
627
628 mutex_unlock(&imxdrm->mutex);
629 }
630
631 imx_drm_update_possible_crtcs();
632
633 return 0;
634 }
635 EXPORT_SYMBOL_GPL(imx_drm_encoder_add_possible_crtcs);
636
637 int imx_drm_encoder_get_mux_id(struct imx_drm_encoder *imx_drm_encoder,
638 struct drm_crtc *crtc)
639 {
640 struct imx_drm_device *imxdrm = __imx_drm_device();
641 struct imx_drm_crtc *imx_crtc;
642 int i = 0;
643
644 list_for_each_entry(imx_crtc, &imxdrm->crtc_list, list) {
645 if (imx_crtc->crtc == crtc)
646 goto found;
647 i++;
648 }
649
650 return -EINVAL;
651 found:
652 return i;
653 }
654 EXPORT_SYMBOL_GPL(imx_drm_encoder_get_mux_id);
655
656 /*
657 * imx_drm_remove_encoder - remove an encoder
658 */
659 int imx_drm_remove_encoder(struct imx_drm_encoder *imx_drm_encoder)
660 {
661 struct imx_drm_device *imxdrm = __imx_drm_device();
662 struct crtc_cookie *c, *tmp;
663
664 mutex_lock(&imxdrm->mutex);
665
666 imx_drm_encoder_unregister(imx_drm_encoder);
667
668 list_del(&imx_drm_encoder->list);
669
670 list_for_each_entry_safe(c, tmp, &imx_drm_encoder->possible_crtcs,
671 list)
672 kfree(c);
673
674 mutex_unlock(&imxdrm->mutex);
675
676 kfree(imx_drm_encoder);
677
678 return 0;
679 }
680 EXPORT_SYMBOL_GPL(imx_drm_remove_encoder);
681
682 /*
683 * imx_drm_add_connector - add a connector
684 */
685 int imx_drm_add_connector(struct drm_connector *connector,
686 struct imx_drm_connector **new_con,
687 struct module *owner)
688 {
689 struct imx_drm_device *imxdrm = __imx_drm_device();
690 struct imx_drm_connector *imx_drm_connector;
691 int ret;
692
693 mutex_lock(&imxdrm->mutex);
694
695 if (imxdrm->drm->open_count) {
696 ret = -EBUSY;
697 goto err_busy;
698 }
699
700 imx_drm_connector = kzalloc(sizeof(*imx_drm_connector), GFP_KERNEL);
701 if (!imx_drm_connector) {
702 ret = -ENOMEM;
703 goto err_alloc;
704 }
705
706 imx_drm_connector->connector = connector;
707 imx_drm_connector->owner = owner;
708
709 ret = imx_drm_connector_register(imx_drm_connector);
710 if (ret)
711 goto err_register;
712
713 list_add_tail(&imx_drm_connector->list, &imxdrm->connector_list);
714
715 *new_con = imx_drm_connector;
716
717 mutex_unlock(&imxdrm->mutex);
718
719 return 0;
720
721 err_register:
722 kfree(imx_drm_connector);
723 err_alloc:
724 err_busy:
725 mutex_unlock(&imxdrm->mutex);
726
727 return ret;
728 }
729 EXPORT_SYMBOL_GPL(imx_drm_add_connector);
730
731 void imx_drm_fb_helper_set(struct drm_fbdev_cma *fbdev_helper)
732 {
733 struct imx_drm_device *imxdrm = __imx_drm_device();
734
735 imxdrm->fbhelper = fbdev_helper;
736 }
737 EXPORT_SYMBOL_GPL(imx_drm_fb_helper_set);
738
739 /*
740 * imx_drm_remove_connector - remove a connector
741 */
742 int imx_drm_remove_connector(struct imx_drm_connector *imx_drm_connector)
743 {
744 struct imx_drm_device *imxdrm = __imx_drm_device();
745
746 mutex_lock(&imxdrm->mutex);
747
748 imx_drm_connector_unregister(imx_drm_connector);
749
750 list_del(&imx_drm_connector->list);
751
752 mutex_unlock(&imxdrm->mutex);
753
754 kfree(imx_drm_connector);
755
756 return 0;
757 }
758 EXPORT_SYMBOL_GPL(imx_drm_remove_connector);
759
760 static const struct drm_ioctl_desc imx_drm_ioctls[] = {
761 /* none so far */
762 };
763
764 static struct drm_driver imx_drm_driver = {
765 .driver_features = DRIVER_MODESET | DRIVER_GEM,
766 .load = imx_drm_driver_load,
767 .unload = imx_drm_driver_unload,
768 .lastclose = imx_drm_driver_lastclose,
769 .gem_free_object = drm_gem_cma_free_object,
770 .gem_vm_ops = &drm_gem_cma_vm_ops,
771 .dumb_create = drm_gem_cma_dumb_create,
772 .dumb_map_offset = drm_gem_cma_dumb_map_offset,
773 .dumb_destroy = drm_gem_dumb_destroy,
774
775 .get_vblank_counter = drm_vblank_count,
776 .enable_vblank = imx_drm_enable_vblank,
777 .disable_vblank = imx_drm_disable_vblank,
778 .ioctls = imx_drm_ioctls,
779 .num_ioctls = ARRAY_SIZE(imx_drm_ioctls),
780 .fops = &imx_drm_driver_fops,
781 .name = "imx-drm",
782 .desc = "i.MX DRM graphics",
783 .date = "20120507",
784 .major = 1,
785 .minor = 0,
786 .patchlevel = 0,
787 };
788
789 static int imx_drm_platform_probe(struct platform_device *pdev)
790 {
791 imx_drm_device->dev = &pdev->dev;
792
793 return drm_platform_init(&imx_drm_driver, pdev);
794 }
795
796 static int imx_drm_platform_remove(struct platform_device *pdev)
797 {
798 drm_platform_exit(&imx_drm_driver, pdev);
799
800 return 0;
801 }
802
803 static struct platform_driver imx_drm_pdrv = {
804 .probe = imx_drm_platform_probe,
805 .remove = imx_drm_platform_remove,
806 .driver = {
807 .owner = THIS_MODULE,
808 .name = "imx-drm",
809 },
810 };
811
812 static struct platform_device *imx_drm_pdev;
813
814 static int __init imx_drm_init(void)
815 {
816 int ret;
817
818 imx_drm_device = kzalloc(sizeof(*imx_drm_device), GFP_KERNEL);
819 if (!imx_drm_device)
820 return -ENOMEM;
821
822 mutex_init(&imx_drm_device->mutex);
823 INIT_LIST_HEAD(&imx_drm_device->crtc_list);
824 INIT_LIST_HEAD(&imx_drm_device->connector_list);
825 INIT_LIST_HEAD(&imx_drm_device->encoder_list);
826
827 imx_drm_pdev = platform_device_register_simple("imx-drm", -1, NULL, 0);
828 if (!imx_drm_pdev) {
829 ret = -EINVAL;
830 goto err_pdev;
831 }
832
833 imx_drm_pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32),
834
835 ret = platform_driver_register(&imx_drm_pdrv);
836 if (ret)
837 goto err_pdrv;
838
839 return 0;
840
841 err_pdrv:
842 platform_device_unregister(imx_drm_pdev);
843 err_pdev:
844 kfree(imx_drm_device);
845
846 return ret;
847 }
848
849 static void __exit imx_drm_exit(void)
850 {
851 platform_device_unregister(imx_drm_pdev);
852 platform_driver_unregister(&imx_drm_pdrv);
853
854 kfree(imx_drm_device);
855 }
856
857 module_init(imx_drm_init);
858 module_exit(imx_drm_exit);
859
860 MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
861 MODULE_DESCRIPTION("i.MX drm driver core");
862 MODULE_LICENSE("GPL");