| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Freescale i.MX drm driver | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2011 Sascha Hauer, Pengutronix | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-11-03 11:23:34 +00:00
										 |  |  | #include <linux/component.h>
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | #include <linux/device.h>
 | 
					
						
							| 
									
										
										
										
											2013-11-03 15:38:09 +00:00
										 |  |  | #include <linux/fb.h>
 | 
					
						
							|  |  |  | #include <linux/module.h>
 | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | #include <linux/of_graph.h>
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | #include <linux/platform_device.h>
 | 
					
						
							|  |  |  | #include <drm/drmP.h>
 | 
					
						
							|  |  |  | #include <drm/drm_fb_helper.h>
 | 
					
						
							|  |  |  | #include <drm/drm_crtc_helper.h>
 | 
					
						
							|  |  |  | #include <drm/drm_gem_cma_helper.h>
 | 
					
						
							|  |  |  | #include <drm/drm_fb_cma_helper.h>
 | 
					
						
							| 
									
										
										
										
											2014-10-29 10:03:57 +01:00
										 |  |  | #include <drm/drm_plane_helper.h>
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "imx-drm.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define MAX_CRTC	4
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | struct imx_drm_component { | 
					
						
							|  |  |  | 	struct device_node *of_node; | 
					
						
							|  |  |  | 	struct list_head list; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | struct imx_drm_device { | 
					
						
							|  |  |  | 	struct drm_device			*drm; | 
					
						
							| 
									
										
										
										
											2013-11-24 13:23:17 +00:00
										 |  |  | 	struct imx_drm_crtc			*crtc[MAX_CRTC]; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	int					pipes; | 
					
						
							|  |  |  | 	struct drm_fbdev_cma			*fbhelper; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct imx_drm_crtc { | 
					
						
							|  |  |  | 	struct drm_crtc				*crtc; | 
					
						
							|  |  |  | 	int					pipe; | 
					
						
							|  |  |  | 	struct imx_drm_crtc_helper_funcs	imx_drm_helper_funcs; | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	struct device_node			*port; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 12:13:47 +00:00
										 |  |  | static int legacyfb_depth = 16; | 
					
						
							|  |  |  | module_param(legacyfb_depth, int, 0444); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-10 16:18:45 +02:00
										 |  |  | int imx_drm_crtc_id(struct imx_drm_crtc *crtc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return crtc->pipe; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-11-12 12:15:45 -05:00
										 |  |  | EXPORT_SYMBOL_GPL(imx_drm_crtc_id); | 
					
						
							| 
									
										
										
										
											2013-10-10 16:18:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | static void imx_drm_driver_lastclose(struct drm_device *drm) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-03 12:13:47 +00:00
										 |  |  | #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	struct imx_drm_device *imxdrm = drm->dev_private; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (imxdrm->fbhelper) | 
					
						
							|  |  |  | 		drm_fbdev_cma_restore_mode(imxdrm->fbhelper); | 
					
						
							| 
									
										
										
										
											2013-11-03 12:13:47 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int imx_drm_driver_unload(struct drm_device *drm) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-03 12:13:47 +00:00
										 |  |  | #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	struct imx_drm_device *imxdrm = drm->dev_private; | 
					
						
							| 
									
										
										
										
											2013-11-03 22:18:40 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	drm_kms_helper_poll_fini(drm); | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 22:18:40 +00:00
										 |  |  | #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
 | 
					
						
							| 
									
										
										
										
											2013-11-03 12:13:47 +00:00
										 |  |  | 	if (imxdrm->fbhelper) | 
					
						
							|  |  |  | 		drm_fbdev_cma_fini(imxdrm->fbhelper); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 11:23:34 +00:00
										 |  |  | 	component_unbind_all(drm->dev, drm); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 19:10:47 +00:00
										 |  |  | 	drm_vblank_cleanup(drm); | 
					
						
							|  |  |  | 	drm_mode_config_cleanup(drm); | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-10 22:43:51 +08:00
										 |  |  | 	platform_set_drvdata(drm->platformdev, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-26 20:53:44 -03:00
										 |  |  | static struct imx_drm_crtc *imx_drm_find_crtc(struct drm_crtc *crtc) | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-03 12:26:23 +00:00
										 |  |  | 	struct imx_drm_device *imxdrm = crtc->dev->dev_private; | 
					
						
							| 
									
										
										
										
											2013-11-24 13:23:17 +00:00
										 |  |  | 	unsigned i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < MAX_CRTC; i++) | 
					
						
							|  |  |  | 		if (imxdrm->crtc[i] && imxdrm->crtc[i]->crtc == crtc) | 
					
						
							|  |  |  | 			return imxdrm->crtc[i]; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 15:52:16 +00:00
										 |  |  | int imx_drm_panel_format_pins(struct drm_encoder *encoder, | 
					
						
							| 
									
										
										
										
											2013-04-08 18:04:35 +02:00
										 |  |  | 		u32 interface_pix_fmt, int hsync_pin, int vsync_pin) | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct imx_drm_crtc_helper_funcs *helper; | 
					
						
							| 
									
										
										
										
											2013-11-24 13:23:17 +00:00
										 |  |  | 	struct imx_drm_crtc *imx_crtc; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 15:52:16 +00:00
										 |  |  | 	imx_crtc = imx_drm_find_crtc(encoder->crtc); | 
					
						
							| 
									
										
										
										
											2013-11-24 13:23:17 +00:00
										 |  |  | 	if (!imx_crtc) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	helper = &imx_crtc->imx_drm_helper_funcs; | 
					
						
							|  |  |  | 	if (helper->set_interface_pix_fmt) | 
					
						
							| 
									
										
										
										
											2013-11-03 15:52:16 +00:00
										 |  |  | 		return helper->set_interface_pix_fmt(encoder->crtc, | 
					
						
							|  |  |  | 				encoder->encoder_type, interface_pix_fmt, | 
					
						
							| 
									
										
										
										
											2013-04-08 18:04:35 +02:00
										 |  |  | 				hsync_pin, vsync_pin); | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-11-03 15:52:16 +00:00
										 |  |  | EXPORT_SYMBOL_GPL(imx_drm_panel_format_pins); | 
					
						
							| 
									
										
										
										
											2013-04-08 18:04:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 15:52:16 +00:00
										 |  |  | int imx_drm_panel_format(struct drm_encoder *encoder, u32 interface_pix_fmt) | 
					
						
							| 
									
										
										
										
											2013-04-08 18:04:35 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-03 15:52:16 +00:00
										 |  |  | 	return imx_drm_panel_format_pins(encoder, interface_pix_fmt, 2, 3); | 
					
						
							| 
									
										
										
										
											2013-04-08 18:04:35 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-11-03 15:52:16 +00:00
										 |  |  | EXPORT_SYMBOL_GPL(imx_drm_panel_format); | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | int imx_drm_crtc_vblank_get(struct imx_drm_crtc *imx_drm_crtc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-17 19:10:27 +00:00
										 |  |  | 	return drm_vblank_get(imx_drm_crtc->crtc->dev, imx_drm_crtc->pipe); | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL_GPL(imx_drm_crtc_vblank_get); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void imx_drm_crtc_vblank_put(struct imx_drm_crtc *imx_drm_crtc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-17 19:10:27 +00:00
										 |  |  | 	drm_vblank_put(imx_drm_crtc->crtc->dev, imx_drm_crtc->pipe); | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL_GPL(imx_drm_crtc_vblank_put); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void imx_drm_handle_vblank(struct imx_drm_crtc *imx_drm_crtc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-17 19:10:27 +00:00
										 |  |  | 	drm_handle_vblank(imx_drm_crtc->crtc->dev, imx_drm_crtc->pipe); | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL_GPL(imx_drm_handle_vblank); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int imx_drm_enable_vblank(struct drm_device *drm, int crtc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct imx_drm_device *imxdrm = drm->dev_private; | 
					
						
							| 
									
										
										
										
											2013-11-24 13:23:17 +00:00
										 |  |  | 	struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[crtc]; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!imx_drm_crtc) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!imx_drm_crtc->imx_drm_helper_funcs.enable_vblank) | 
					
						
							|  |  |  | 		return -ENOSYS; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = imx_drm_crtc->imx_drm_helper_funcs.enable_vblank( | 
					
						
							|  |  |  | 			imx_drm_crtc->crtc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void imx_drm_disable_vblank(struct drm_device *drm, int crtc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct imx_drm_device *imxdrm = drm->dev_private; | 
					
						
							| 
									
										
										
										
											2013-11-24 13:23:17 +00:00
										 |  |  | 	struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[crtc]; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!imx_drm_crtc) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!imx_drm_crtc->imx_drm_helper_funcs.disable_vblank) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	imx_drm_crtc->imx_drm_helper_funcs.disable_vblank(imx_drm_crtc->crtc); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-10 16:18:44 +02:00
										 |  |  | static void imx_drm_driver_preclose(struct drm_device *drm, | 
					
						
							|  |  |  | 		struct drm_file *file) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!file->is_master) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-16 12:38:50 +00:00
										 |  |  | 	for (i = 0; i < MAX_CRTC; i++) | 
					
						
							|  |  |  | 		imx_drm_disable_vblank(drm, i); | 
					
						
							| 
									
										
										
										
											2013-10-10 16:18:44 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | static const struct file_operations imx_drm_driver_fops = { | 
					
						
							|  |  |  | 	.owner = THIS_MODULE, | 
					
						
							|  |  |  | 	.open = drm_open, | 
					
						
							|  |  |  | 	.release = drm_release, | 
					
						
							|  |  |  | 	.unlocked_ioctl = drm_ioctl, | 
					
						
							|  |  |  | 	.mmap = drm_gem_cma_mmap, | 
					
						
							|  |  |  | 	.poll = drm_poll, | 
					
						
							|  |  |  | 	.read = drm_read, | 
					
						
							|  |  |  | 	.llseek = noop_llseek, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 13:28:24 +00:00
										 |  |  | void imx_drm_connector_destroy(struct drm_connector *connector) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-29 16:57:41 +01:00
										 |  |  | 	drm_connector_unregister(connector); | 
					
						
							| 
									
										
										
										
											2013-11-03 13:28:24 +00:00
										 |  |  | 	drm_connector_cleanup(connector); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL_GPL(imx_drm_connector_destroy); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void imx_drm_encoder_destroy(struct drm_encoder *encoder) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	drm_encoder_cleanup(encoder); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL_GPL(imx_drm_encoder_destroy); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 22:18:40 +00:00
										 |  |  | static void imx_drm_output_poll_changed(struct drm_device *drm) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
 | 
					
						
							|  |  |  | 	struct imx_drm_device *imxdrm = drm->dev_private; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	drm_fbdev_cma_hotplug_event(imxdrm->fbhelper); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 16:04:48 +00:00
										 |  |  | static struct drm_mode_config_funcs imx_drm_mode_config_funcs = { | 
					
						
							|  |  |  | 	.fb_create = drm_fb_cma_create, | 
					
						
							| 
									
										
										
										
											2013-11-03 22:18:40 +00:00
										 |  |  | 	.output_poll_changed = imx_drm_output_poll_changed, | 
					
						
							| 
									
										
										
										
											2013-11-03 16:04:48 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2013-11-03 11:23:34 +00:00
										 |  |  |  * Main DRM initialisation. This binds, initialises and registers | 
					
						
							|  |  |  |  * with DRM the subcomponents of the driver. | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | static int imx_drm_driver_load(struct drm_device *drm, unsigned long flags) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-03 15:31:22 +00:00
										 |  |  | 	struct imx_drm_device *imxdrm; | 
					
						
							| 
									
										
										
										
											2013-11-03 18:39:29 +00:00
										 |  |  | 	struct drm_connector *connector; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 15:31:22 +00:00
										 |  |  | 	imxdrm = devm_kzalloc(drm->dev, sizeof(*imxdrm), GFP_KERNEL); | 
					
						
							|  |  |  | 	if (!imxdrm) | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	imxdrm->drm = drm; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	drm->dev_private = imxdrm; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * enable drm irq mode. | 
					
						
							| 
									
										
										
										
											2013-10-04 14:53:37 +03:00
										 |  |  | 	 * - with irq_enabled = true, we can use the vblank feature. | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	 * | 
					
						
							|  |  |  | 	 * P.S. note that we wouldn't use drm irq handler but | 
					
						
							|  |  |  | 	 *      just specific driver own one instead because | 
					
						
							|  |  |  | 	 *      drm framework supports only one irq handler and | 
					
						
							|  |  |  | 	 *      drivers can well take care of their interrupts | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2013-10-04 14:53:37 +03:00
										 |  |  | 	drm->irq_enabled = true; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 16:04:48 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * set max width and height as default value(4096x4096). | 
					
						
							|  |  |  | 	 * this value would be used to check framebuffer size limitation | 
					
						
							|  |  |  | 	 * at drm_mode_addfb(). | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	drm->mode_config.min_width = 64; | 
					
						
							|  |  |  | 	drm->mode_config.min_height = 64; | 
					
						
							|  |  |  | 	drm->mode_config.max_width = 4096; | 
					
						
							|  |  |  | 	drm->mode_config.max_height = 4096; | 
					
						
							|  |  |  | 	drm->mode_config.funcs = &imx_drm_mode_config_funcs; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	drm_mode_config_init(drm); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 19:10:47 +00:00
										 |  |  | 	ret = drm_vblank_init(drm, MAX_CRTC); | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	if (ret) | 
					
						
							| 
									
										
										
										
											2013-12-16 11:33:44 +00:00
										 |  |  | 		goto err_kms; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							| 
									
										
										
										
											2013-11-03 15:38:09 +00:00
										 |  |  | 	 * with vblank_disable_allowed = true, vblank interrupt will be | 
					
						
							|  |  |  | 	 * disabled by drm timer once a current process gives up ownership | 
					
						
							|  |  |  | 	 * of vblank event. (after drm_vblank_put function is called) | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2013-12-17 19:10:47 +00:00
										 |  |  | 	drm->vblank_disable_allowed = true; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 14:31:09 +01:00
										 |  |  | 	platform_set_drvdata(drm->platformdev, drm); | 
					
						
							| 
									
										
										
										
											2013-11-03 13:55:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 11:23:34 +00:00
										 |  |  | 	/* Now try and bind all our sub-components */ | 
					
						
							|  |  |  | 	ret = component_bind_all(drm->dev, drm); | 
					
						
							|  |  |  | 	if (ret) | 
					
						
							| 
									
										
										
										
											2013-11-03 15:20:18 +00:00
										 |  |  | 		goto err_vblank; | 
					
						
							| 
									
										
										
										
											2013-11-03 18:39:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * All components are now added, we can publish the connector sysfs | 
					
						
							|  |  |  | 	 * entries to userspace.  This will generate hotplug events and so | 
					
						
							|  |  |  | 	 * userspace will expect to be able to access DRM at this point. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	list_for_each_entry(connector, &drm->mode_config.connector_list, head) { | 
					
						
							| 
									
										
										
										
											2014-05-29 16:57:41 +01:00
										 |  |  | 		ret = drm_connector_register(connector); | 
					
						
							| 
									
										
										
										
											2013-11-03 18:39:29 +00:00
										 |  |  | 		if (ret) { | 
					
						
							|  |  |  | 			dev_err(drm->dev, | 
					
						
							| 
									
										
										
										
											2014-05-29 16:57:41 +01:00
										 |  |  | 				"[CONNECTOR:%d:%s] drm_connector_register failed: %d\n", | 
					
						
							| 
									
										
										
										
											2013-11-03 18:39:29 +00:00
										 |  |  | 				connector->base.id, | 
					
						
							| 
									
										
										
										
											2014-06-03 14:56:16 +03:00
										 |  |  | 				connector->name, ret); | 
					
						
							| 
									
										
										
										
											2013-11-03 18:39:29 +00:00
										 |  |  | 			goto err_unbind; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 12:13:47 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * All components are now initialised, so setup the fb helper. | 
					
						
							|  |  |  | 	 * The fb helper takes copies of key hardware information, so the | 
					
						
							|  |  |  | 	 * crtcs/connectors/encoders must not change after this point. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
 | 
					
						
							|  |  |  | 	if (legacyfb_depth != 16 && legacyfb_depth != 32) { | 
					
						
							|  |  |  | 		dev_warn(drm->dev, "Invalid legacyfb_depth.  Defaulting to 16bpp\n"); | 
					
						
							|  |  |  | 		legacyfb_depth = 16; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	imxdrm->fbhelper = drm_fbdev_cma_init(drm, legacyfb_depth, | 
					
						
							|  |  |  | 				drm->mode_config.num_crtc, MAX_CRTC); | 
					
						
							|  |  |  | 	if (IS_ERR(imxdrm->fbhelper)) { | 
					
						
							|  |  |  | 		ret = PTR_ERR(imxdrm->fbhelper); | 
					
						
							|  |  |  | 		imxdrm->fbhelper = NULL; | 
					
						
							|  |  |  | 		goto err_unbind; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-11-03 22:18:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	drm_kms_helper_poll_init(drm); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-16 11:33:44 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2013-11-03 14:31:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 18:39:29 +00:00
										 |  |  | err_unbind: | 
					
						
							|  |  |  | 	component_unbind_all(drm->dev, drm); | 
					
						
							| 
									
										
										
										
											2013-11-03 15:20:18 +00:00
										 |  |  | err_vblank: | 
					
						
							| 
									
										
										
										
											2013-12-16 11:33:44 +00:00
										 |  |  | 	drm_vblank_cleanup(drm); | 
					
						
							|  |  |  | err_kms: | 
					
						
							|  |  |  | 	drm_mode_config_cleanup(drm); | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * imx_drm_add_crtc - add a new crtc | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-11-03 12:26:23 +00:00
										 |  |  | int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc, | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 		struct imx_drm_crtc **new_crtc, | 
					
						
							|  |  |  | 		const struct imx_drm_crtc_helper_funcs *imx_drm_helper_funcs, | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 		struct device_node *port) | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-03 12:26:23 +00:00
										 |  |  | 	struct imx_drm_device *imxdrm = drm->dev_private; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	struct imx_drm_crtc *imx_drm_crtc; | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-16 12:39:31 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * The vblank arrays are dimensioned by MAX_CRTC - we can't | 
					
						
							|  |  |  | 	 * pass IDs greater than this to those functions. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2013-11-03 15:38:09 +00:00
										 |  |  | 	if (imxdrm->pipes >= MAX_CRTC) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							| 
									
										
										
										
											2013-12-16 12:39:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 15:38:09 +00:00
										 |  |  | 	if (imxdrm->drm->open_count) | 
					
						
							|  |  |  | 		return -EBUSY; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL); | 
					
						
							| 
									
										
										
										
											2013-11-03 15:38:09 +00:00
										 |  |  | 	if (!imx_drm_crtc) | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	imx_drm_crtc->imx_drm_helper_funcs = *imx_drm_helper_funcs; | 
					
						
							|  |  |  | 	imx_drm_crtc->pipe = imxdrm->pipes++; | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	imx_drm_crtc->port = port; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	imx_drm_crtc->crtc = crtc; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-24 13:23:17 +00:00
										 |  |  | 	imxdrm->crtc[imx_drm_crtc->pipe] = imx_drm_crtc; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	*new_crtc = imx_drm_crtc; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 19:11:07 +00:00
										 |  |  | 	ret = drm_mode_crtc_set_gamma_size(imx_drm_crtc->crtc, 256); | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	if (ret) | 
					
						
							|  |  |  | 		goto err_register; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 19:11:07 +00:00
										 |  |  | 	drm_crtc_helper_add(crtc, | 
					
						
							|  |  |  | 			imx_drm_crtc->imx_drm_helper_funcs.crtc_helper_funcs); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 12:26:23 +00:00
										 |  |  | 	drm_crtc_init(drm, crtc, | 
					
						
							| 
									
										
										
										
											2013-12-17 19:11:07 +00:00
										 |  |  | 			imx_drm_crtc->imx_drm_helper_funcs.crtc_funcs); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | err_register: | 
					
						
							| 
									
										
										
										
											2013-11-24 13:23:17 +00:00
										 |  |  | 	imxdrm->crtc[imx_drm_crtc->pipe] = NULL; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	kfree(imx_drm_crtc); | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL_GPL(imx_drm_add_crtc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * imx_drm_remove_crtc - remove a crtc | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | int imx_drm_remove_crtc(struct imx_drm_crtc *imx_drm_crtc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-03 15:20:18 +00:00
										 |  |  | 	struct imx_drm_device *imxdrm = imx_drm_crtc->crtc->dev->dev_private; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	drm_crtc_cleanup(imx_drm_crtc->crtc); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-24 13:23:17 +00:00
										 |  |  | 	imxdrm->crtc[imx_drm_crtc->pipe] = NULL; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	kfree(imx_drm_crtc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL_GPL(imx_drm_remove_crtc); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 14:04:47 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  |  * Find the DRM CRTC possible mask for the connected endpoint. | 
					
						
							| 
									
										
										
										
											2013-11-03 14:04:47 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The encoder possible masks are defined by their position in the | 
					
						
							|  |  |  |  * mode_config crtc_list.  This means that CRTCs must not be added | 
					
						
							|  |  |  |  * or removed once the DRM device has been fully initialised. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static uint32_t imx_drm_find_crtc_mask(struct imx_drm_device *imxdrm, | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	struct device_node *endpoint) | 
					
						
							| 
									
										
										
										
											2013-11-03 14:04:47 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	struct device_node *port; | 
					
						
							| 
									
										
										
										
											2013-11-03 14:04:47 +00:00
										 |  |  | 	unsigned i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	port = of_graph_get_remote_port(endpoint); | 
					
						
							|  |  |  | 	if (!port) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	of_node_put(port); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 14:04:47 +00:00
										 |  |  | 	for (i = 0; i < MAX_CRTC; i++) { | 
					
						
							|  |  |  | 		struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[i]; | 
					
						
							| 
									
										
										
										
											2014-08-04 21:07:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 		if (imx_drm_crtc && imx_drm_crtc->port == port) | 
					
						
							| 
									
										
										
										
											2013-11-03 14:04:47 +00:00
										 |  |  | 			return drm_crtc_mask(imx_drm_crtc->crtc); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | static struct device_node *imx_drm_of_get_next_endpoint( | 
					
						
							|  |  |  | 		const struct device_node *parent, struct device_node *prev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct device_node *node = of_graph_get_next_endpoint(parent, prev); | 
					
						
							| 
									
										
										
										
											2014-08-04 21:07:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	of_node_put(prev); | 
					
						
							|  |  |  | 	return node; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 14:04:47 +00:00
										 |  |  | int imx_drm_encoder_parse_of(struct drm_device *drm, | 
					
						
							|  |  |  | 	struct drm_encoder *encoder, struct device_node *np) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct imx_drm_device *imxdrm = drm->dev_private; | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	struct device_node *ep = NULL; | 
					
						
							| 
									
										
										
										
											2013-11-03 14:04:47 +00:00
										 |  |  | 	uint32_t crtc_mask = 0; | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2013-11-03 14:04:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	for (i = 0; ; i++) { | 
					
						
							|  |  |  | 		u32 mask; | 
					
						
							| 
									
										
										
										
											2013-11-03 14:04:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 		ep = imx_drm_of_get_next_endpoint(np, ep); | 
					
						
							|  |  |  | 		if (!ep) | 
					
						
							| 
									
										
										
										
											2013-11-03 14:04:47 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 		mask = imx_drm_find_crtc_mask(imxdrm, ep); | 
					
						
							| 
									
										
										
										
											2013-11-03 14:04:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * If we failed to find the CRTC(s) which this encoder is | 
					
						
							|  |  |  | 		 * supposed to be connected to, it's because the CRTC has | 
					
						
							|  |  |  | 		 * not been registered yet.  Defer probing, and hope that | 
					
						
							|  |  |  | 		 * the required CRTC is added later. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if (mask == 0) | 
					
						
							|  |  |  | 			return -EPROBE_DEFER; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		crtc_mask |= mask; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-08 12:07:50 +02:00
										 |  |  | 	of_node_put(ep); | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	if (i == 0) | 
					
						
							|  |  |  | 		return -ENOENT; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 14:04:47 +00:00
										 |  |  | 	encoder->possible_crtcs = crtc_mask; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* FIXME: this is the mask of outputs which can clone this output. */ | 
					
						
							|  |  |  | 	encoder->possible_clones = ~0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL_GPL(imx_drm_encoder_parse_of); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * @node: device tree node containing encoder input ports | 
					
						
							|  |  |  |  * @encoder: drm_encoder | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | int imx_drm_encoder_get_mux_id(struct device_node *node, | 
					
						
							|  |  |  | 			       struct drm_encoder *encoder) | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-24 13:23:17 +00:00
										 |  |  | 	struct imx_drm_crtc *imx_crtc = imx_drm_find_crtc(encoder->crtc); | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	struct device_node *ep = NULL; | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:53 +01:00
										 |  |  | 	struct of_endpoint endpoint; | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	struct device_node *port; | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:53 +01:00
										 |  |  | 	int ret; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	if (!node || !imx_crtc) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	do { | 
					
						
							|  |  |  | 		ep = imx_drm_of_get_next_endpoint(node, ep); | 
					
						
							|  |  |  | 		if (!ep) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		port = of_graph_get_remote_port(ep); | 
					
						
							|  |  |  | 		of_node_put(port); | 
					
						
							|  |  |  | 		if (port == imx_crtc->port) { | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:53 +01:00
										 |  |  | 			ret = of_graph_parse_endpoint(ep, &endpoint); | 
					
						
							| 
									
										
										
										
											2014-04-07 10:22:36 +02:00
										 |  |  | 			return ret ? ret : endpoint.port; | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} while (ep); | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	return -EINVAL; | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-06-28 13:55:27 -03:00
										 |  |  | EXPORT_SYMBOL_GPL(imx_drm_encoder_get_mux_id); | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-02 13:27:49 -04:00
										 |  |  | static const struct drm_ioctl_desc imx_drm_ioctls[] = { | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	/* none so far */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct drm_driver imx_drm_driver = { | 
					
						
							| 
									
										
										
										
											2013-10-10 16:18:46 +02:00
										 |  |  | 	.driver_features	= DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME, | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	.load			= imx_drm_driver_load, | 
					
						
							|  |  |  | 	.unload			= imx_drm_driver_unload, | 
					
						
							|  |  |  | 	.lastclose		= imx_drm_driver_lastclose, | 
					
						
							| 
									
										
										
										
											2013-10-10 16:18:44 +02:00
										 |  |  | 	.preclose		= imx_drm_driver_preclose, | 
					
						
							| 
									
										
										
										
											2014-08-29 12:12:43 +02:00
										 |  |  | 	.set_busid		= drm_platform_set_busid, | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	.gem_free_object	= drm_gem_cma_free_object, | 
					
						
							|  |  |  | 	.gem_vm_ops		= &drm_gem_cma_vm_ops, | 
					
						
							|  |  |  | 	.dumb_create		= drm_gem_cma_dumb_create, | 
					
						
							|  |  |  | 	.dumb_map_offset	= drm_gem_cma_dumb_map_offset, | 
					
						
							| 
									
										
										
										
											2013-07-16 09:12:04 +02:00
										 |  |  | 	.dumb_destroy		= drm_gem_dumb_destroy, | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-10 16:18:46 +02:00
										 |  |  | 	.prime_handle_to_fd	= drm_gem_prime_handle_to_fd, | 
					
						
							|  |  |  | 	.prime_fd_to_handle	= drm_gem_prime_fd_to_handle, | 
					
						
							|  |  |  | 	.gem_prime_import	= drm_gem_prime_import, | 
					
						
							|  |  |  | 	.gem_prime_export	= drm_gem_prime_export, | 
					
						
							|  |  |  | 	.gem_prime_get_sg_table	= drm_gem_cma_prime_get_sg_table, | 
					
						
							|  |  |  | 	.gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table, | 
					
						
							|  |  |  | 	.gem_prime_vmap		= drm_gem_cma_prime_vmap, | 
					
						
							|  |  |  | 	.gem_prime_vunmap	= drm_gem_cma_prime_vunmap, | 
					
						
							|  |  |  | 	.gem_prime_mmap		= drm_gem_cma_prime_mmap, | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	.get_vblank_counter	= drm_vblank_count, | 
					
						
							|  |  |  | 	.enable_vblank		= imx_drm_enable_vblank, | 
					
						
							|  |  |  | 	.disable_vblank		= imx_drm_disable_vblank, | 
					
						
							|  |  |  | 	.ioctls			= imx_drm_ioctls, | 
					
						
							|  |  |  | 	.num_ioctls		= ARRAY_SIZE(imx_drm_ioctls), | 
					
						
							|  |  |  | 	.fops			= &imx_drm_driver_fops, | 
					
						
							|  |  |  | 	.name			= "imx-drm", | 
					
						
							|  |  |  | 	.desc			= "i.MX DRM graphics", | 
					
						
							|  |  |  | 	.date			= "20120507", | 
					
						
							|  |  |  | 	.major			= 1, | 
					
						
							|  |  |  | 	.minor			= 0, | 
					
						
							|  |  |  | 	.patchlevel		= 0, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 11:23:34 +00:00
										 |  |  | static int compare_of(struct device *dev, void *data) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	struct device_node *np = data; | 
					
						
							| 
									
										
										
										
											2013-11-03 11:23:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	/* Special case for LDB, one device for two channels */ | 
					
						
							|  |  |  | 	if (of_node_cmp(np->name, "lvds-channel") == 0) { | 
					
						
							|  |  |  | 		np = of_get_parent(np); | 
					
						
							|  |  |  | 		of_node_put(np); | 
					
						
							| 
									
										
										
										
											2013-11-03 11:23:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	return dev->of_node == np; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-11-03 11:23:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int imx_drm_bind(struct device *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return drm_platform_init(&imx_drm_driver, to_platform_device(dev)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void imx_drm_unbind(struct device *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	drm_put_dev(dev_get_drvdata(dev)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const struct component_master_ops imx_drm_ops = { | 
					
						
							|  |  |  | 	.bind = imx_drm_bind, | 
					
						
							|  |  |  | 	.unbind = imx_drm_unbind, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | static int imx_drm_platform_probe(struct platform_device *pdev) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	struct device_node *ep, *port, *remote; | 
					
						
							| 
									
										
										
										
											2014-04-19 11:21:33 +01:00
										 |  |  | 	struct component_match *match = NULL; | 
					
						
							| 
									
										
										
										
											2013-06-10 16:56:16 +01:00
										 |  |  | 	int ret; | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Bind the IPU display interface ports first, so that | 
					
						
							|  |  |  | 	 * imx_drm_encoder_parse_of called from encoder .bind callbacks | 
					
						
							|  |  |  | 	 * works as expected. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	for (i = 0; ; i++) { | 
					
						
							|  |  |  | 		port = of_parse_phandle(pdev->dev.of_node, "ports", i); | 
					
						
							|  |  |  | 		if (!port) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-19 11:21:33 +01:00
										 |  |  | 		component_match_add(&pdev->dev, &match, compare_of, port); | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (i == 0) { | 
					
						
							|  |  |  | 		dev_err(&pdev->dev, "missing 'ports' property\n"); | 
					
						
							|  |  |  | 		return -ENODEV; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Then bind all encoders */ | 
					
						
							|  |  |  | 	for (i = 0; ; i++) { | 
					
						
							|  |  |  | 		port = of_parse_phandle(pdev->dev.of_node, "ports", i); | 
					
						
							|  |  |  | 		if (!port) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for_each_child_of_node(port, ep) { | 
					
						
							|  |  |  | 			remote = of_graph_get_remote_port_parent(ep); | 
					
						
							|  |  |  | 			if (!remote || !of_device_is_available(remote)) { | 
					
						
							|  |  |  | 				of_node_put(remote); | 
					
						
							|  |  |  | 				continue; | 
					
						
							| 
									
										
										
										
											2014-04-14 10:02:26 +08:00
										 |  |  | 			} else if (!of_device_is_available(remote->parent)) { | 
					
						
							|  |  |  | 				dev_warn(&pdev->dev, "parent device of %s is not available\n", | 
					
						
							|  |  |  | 					 remote->full_name); | 
					
						
							|  |  |  | 				of_node_put(remote); | 
					
						
							|  |  |  | 				continue; | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-09 20:29:32 +02:00
										 |  |  | 			component_match_add(&pdev->dev, &match, compare_of, | 
					
						
							|  |  |  | 					    remote); | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 			of_node_put(remote); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		of_node_put(port); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-06-10 16:56:16 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); | 
					
						
							|  |  |  | 	if (ret) | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-19 11:21:33 +01:00
										 |  |  | 	return component_master_add_with_match(&pdev->dev, &imx_drm_ops, match); | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int imx_drm_platform_remove(struct platform_device *pdev) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-03 11:23:34 +00:00
										 |  |  | 	component_master_del(&pdev->dev, &imx_drm_ops); | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-10 22:43:51 +08:00
										 |  |  | #ifdef CONFIG_PM_SLEEP
 | 
					
						
							|  |  |  | static int imx_drm_suspend(struct device *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct drm_device *drm_dev = dev_get_drvdata(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* The drm_dev is NULL before .load hook is called */ | 
					
						
							|  |  |  | 	if (drm_dev == NULL) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	drm_kms_helper_poll_disable(drm_dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int imx_drm_resume(struct device *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct drm_device *drm_dev = dev_get_drvdata(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (drm_dev == NULL) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	drm_helper_resume_force_mode(drm_dev); | 
					
						
							|  |  |  | 	drm_kms_helper_poll_enable(drm_dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static SIMPLE_DEV_PM_OPS(imx_drm_pm_ops, imx_drm_suspend, imx_drm_resume); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 11:23:34 +00:00
										 |  |  | static const struct of_device_id imx_drm_dt_ids[] = { | 
					
						
							| 
									
										
										
										
											2014-03-05 10:20:52 +01:00
										 |  |  | 	{ .compatible = "fsl,imx-display-subsystem", }, | 
					
						
							| 
									
										
										
										
											2013-11-03 11:23:34 +00:00
										 |  |  | 	{ /* sentinel */ }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | MODULE_DEVICE_TABLE(of, imx_drm_dt_ids); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | static struct platform_driver imx_drm_pdrv = { | 
					
						
							|  |  |  | 	.probe		= imx_drm_platform_probe, | 
					
						
							| 
									
										
										
										
											2012-11-19 13:20:51 -05:00
										 |  |  | 	.remove		= imx_drm_platform_remove, | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	.driver		= { | 
					
						
							|  |  |  | 		.name	= "imx-drm", | 
					
						
							| 
									
										
										
										
											2014-09-10 22:43:51 +08:00
										 |  |  | 		.pm	= &imx_drm_pm_ops, | 
					
						
							| 
									
										
										
										
											2013-11-03 11:23:34 +00:00
										 |  |  | 		.of_match_table = imx_drm_dt_ids, | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 	}, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-11-03 15:31:22 +00:00
										 |  |  | module_platform_driver(imx_drm_pdrv); | 
					
						
							| 
									
										
										
										
											2012-09-21 10:07:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); | 
					
						
							|  |  |  | MODULE_DESCRIPTION("i.MX drm driver core"); | 
					
						
							|  |  |  | MODULE_LICENSE("GPL"); |