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