17 #include <linux/device.h>
23 #include <linux/module.h>
72 static int imx_drm_driver_firstopen(
struct drm_device *drm)
80 static void imx_drm_driver_lastclose(
struct drm_device *drm)
90 static int imx_drm_driver_unload(
struct drm_device *drm)
110 if (imx_drm_crtc->
pipe == num)
116 u32 interface_pix_fmt)
119 struct imx_drm_crtc *imx_crtc;
125 if (imx_crtc->
crtc == crtc)
137 encoder_type, interface_pix_fmt);
160 static int imx_drm_enable_vblank(
struct drm_device *drm,
int crtc)
163 struct imx_drm_crtc *imx_drm_crtc;
166 imx_drm_crtc = imx_drm_crtc_by_num(imxdrm, crtc);
179 static void imx_drm_disable_vblank(
struct drm_device *drm,
int crtc)
182 struct imx_drm_crtc *imx_drm_crtc;
184 imx_drm_crtc = imx_drm_crtc_by_num(imxdrm, crtc);
208 static struct imx_drm_device *__imx_drm_device(
void)
210 return imx_drm_device;
215 struct imx_drm_device *imxdrm = __imx_drm_device();
218 struct imx_drm_crtc *
crtc;
223 if (!try_module_get(enc->
owner)) {
224 dev_err(imxdrm->
dev,
"could not get module %s\n",
231 if (!try_module_get(con->
owner)) {
232 dev_err(imxdrm->
dev,
"could not get module %s\n",
239 if (!try_module_get(crtc->
owner)) {
240 dev_err(imxdrm->
dev,
"could not get module %s\n",
254 module_put(crtc->
owner);
257 module_put(con->
owner);
260 module_put(enc->
owner);
271 struct imx_drm_device *imxdrm = __imx_drm_device();
274 struct imx_drm_crtc *
crtc;
279 module_put(crtc->
owner);
282 module_put(con->
owner);
285 module_put(enc->
owner);
312 struct imx_drm_device *imxdrm = __imx_drm_device();
317 imx_drm_encoder->
encoder->funcs,
318 imx_drm_encoder->
encoder->encoder_type);
320 drm_mode_group_reinit(imxdrm->
drm);
331 struct imx_drm_device *imxdrm = __imx_drm_device();
335 drm_mode_group_reinit(imxdrm->
drm);
341 static int imx_drm_connector_register(
344 struct imx_drm_device *imxdrm = __imx_drm_device();
348 imx_drm_connector->
connector->connector_type);
349 drm_mode_group_reinit(imxdrm->
drm);
357 static void imx_drm_connector_unregister(
360 struct imx_drm_device *imxdrm = __imx_drm_device();
365 drm_mode_group_reinit(imxdrm->
drm);
371 static int imx_drm_crtc_register(
struct imx_drm_crtc *imx_drm_crtc)
373 struct imx_drm_device *imxdrm = __imx_drm_device();
382 drm_crtc_helper_add(imx_drm_crtc->
crtc,
385 drm_mode_group_reinit(imxdrm->
drm);
397 static int imx_drm_driver_load(
struct drm_device *drm,
unsigned long flags)
399 struct imx_drm_device *imxdrm = __imx_drm_device();
404 drm->dev_private = imxdrm;
415 drm->irq_enabled = 1;
426 &imxdrm->
drm->primary->mode_group);
439 imxdrm->
drm->vblank_disable_allowed = 1;
449 static void imx_drm_update_possible_crtcs(
void)
451 struct imx_drm_device *imxdrm = __imx_drm_device();
452 struct imx_drm_crtc *imx_drm_crtc;
457 u32 possible_crtcs = 0;
462 imx_drm_crtc->
cookie.id == cookie->
id) {
463 possible_crtcs |= 1 << imx_drm_crtc->
pipe;
467 enc->
encoder->possible_crtcs = possible_crtcs;
468 enc->
encoder->possible_clones = possible_crtcs;
479 struct imx_drm_crtc **new_crtc,
483 struct imx_drm_device *imxdrm = __imx_drm_device();
484 struct imx_drm_crtc *imx_drm_crtc;
495 imx_drm_crtc = kzalloc(
sizeof(*imx_drm_crtc),
GFP_KERNEL);
506 crtc_funcs = imx_drm_helper_funcs->
crtc_funcs;
508 imx_drm_crtc->
crtc = crtc;
509 imx_drm_crtc->
imxdrm = imxdrm;
515 *new_crtc = imx_drm_crtc;
517 ret = imx_drm_crtc_register(imx_drm_crtc);
521 imx_drm_update_possible_crtcs();
541 struct imx_drm_device *imxdrm = imx_drm_crtc->
imxdrm;
549 drm_mode_group_reinit(imxdrm->
drm);
565 struct imx_drm_device *imxdrm = __imx_drm_device();
576 imx_drm_encoder = kzalloc(
sizeof(*imx_drm_encoder),
GFP_KERNEL);
577 if (!imx_drm_encoder) {
585 ret = imx_drm_encoder_register(imx_drm_encoder);
587 kfree(imx_drm_encoder);
594 *newenc = imx_drm_encoder;
601 kfree(imx_drm_encoder);
614 struct imx_drm_device *imxdrm = __imx_drm_device();
623 for (i = 0; !
ret; i++) {
625 "#crtc-cells", i, &args);
631 of_node_put(args.
np);
638 of_node_put(args.
np);
647 imx_drm_update_possible_crtcs();
656 struct imx_drm_device *imxdrm = __imx_drm_device();
657 struct imx_drm_crtc *imx_crtc;
663 if (imx_crtc->
crtc == crtc)
682 struct imx_drm_device *imxdrm = __imx_drm_device();
687 imx_drm_encoder_unregister(imx_drm_encoder);
697 kfree(imx_drm_encoder);
710 struct imx_drm_device *imxdrm = __imx_drm_device();
721 imx_drm_connector = kzalloc(
sizeof(*imx_drm_connector),
GFP_KERNEL);
722 if (!imx_drm_connector) {
730 ret = imx_drm_connector_register(imx_drm_connector);
736 *new_con = imx_drm_connector;
743 kfree(imx_drm_connector);
754 struct imx_drm_device *imxdrm = __imx_drm_device();
765 struct imx_drm_device *imxdrm = __imx_drm_device();
769 imx_drm_connector_unregister(imx_drm_connector);
775 kfree(imx_drm_connector);
781 static struct drm_ioctl_desc imx_drm_ioctls[] = {
785 static struct drm_driver imx_drm_driver = {
786 .driver_features = DRIVER_MODESET | DRIVER_GEM,
787 .load = imx_drm_driver_load,
788 .unload = imx_drm_driver_unload,
789 .firstopen = imx_drm_driver_firstopen,
790 .lastclose = imx_drm_driver_lastclose,
798 .enable_vblank = imx_drm_enable_vblank,
799 .disable_vblank = imx_drm_disable_vblank,
800 .ioctls = imx_drm_ioctls,
802 .fops = &imx_drm_driver_fops,
804 .desc =
"i.MX DRM graphics",
813 imx_drm_device->
dev = &pdev->
dev;
826 .probe = imx_drm_platform_probe,
836 static int __init imx_drm_init(
void)
840 imx_drm_device = kzalloc(
sizeof(*imx_drm_device),
GFP_KERNEL);
845 INIT_LIST_HEAD(&imx_drm_device->
crtc_list);
849 imx_drm_pdev = platform_device_register_simple(
"imx-drm", -1,
NULL, 0);
866 kfree(imx_drm_device);
871 static void __exit imx_drm_exit(
void)
876 kfree(imx_drm_device);