2012-09-21 16:07:47 +08: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 19:23:34 +08:00
|
|
|
#include <linux/component.h>
|
2012-09-21 16:07:47 +08:00
|
|
|
#include <linux/device.h>
|
2016-07-08 17:40:59 +08:00
|
|
|
#include <linux/dma-buf.h>
|
2013-11-03 23:38:09 +08:00
|
|
|
#include <linux/module.h>
|
2012-09-21 16:07:47 +08:00
|
|
|
#include <linux/platform_device.h>
|
2016-07-08 17:40:59 +08:00
|
|
|
#include <linux/reservation.h>
|
2012-09-21 16:07:47 +08:00
|
|
|
#include <drm/drmP.h>
|
2016-07-08 17:40:59 +08:00
|
|
|
#include <drm/drm_atomic.h>
|
|
|
|
#include <drm/drm_atomic_helper.h>
|
2012-09-21 16:07:47 +08:00
|
|
|
#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 17:03:57 +08:00
|
|
|
#include <drm/drm_plane_helper.h>
|
2014-07-04 00:52:57 +08:00
|
|
|
#include <drm/drm_of.h>
|
2016-05-12 21:00:44 +08:00
|
|
|
#include <video/imx-ipu-v3.h>
|
2012-09-21 16:07:47 +08:00
|
|
|
|
|
|
|
#include "imx-drm.h"
|
|
|
|
|
|
|
|
#define MAX_CRTC 4
|
|
|
|
|
2014-03-05 17:20:52 +08:00
|
|
|
struct imx_drm_component {
|
|
|
|
struct device_node *of_node;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
2012-09-21 16:07:47 +08:00
|
|
|
struct imx_drm_device {
|
|
|
|
struct drm_device *drm;
|
2013-11-24 21:23:17 +08:00
|
|
|
struct imx_drm_crtc *crtc[MAX_CRTC];
|
2015-12-15 19:20:51 +08:00
|
|
|
unsigned int pipes;
|
2012-09-21 16:07:47 +08:00
|
|
|
struct drm_fbdev_cma *fbhelper;
|
2016-07-08 17:40:59 +08:00
|
|
|
struct drm_atomic_state *state;
|
2012-09-21 16:07:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct imx_drm_crtc {
|
|
|
|
struct drm_crtc *crtc;
|
|
|
|
struct imx_drm_crtc_helper_funcs imx_drm_helper_funcs;
|
|
|
|
};
|
|
|
|
|
2015-10-27 16:10:57 +08:00
|
|
|
#if IS_ENABLED(CONFIG_DRM_FBDEV_EMULATION)
|
2013-11-03 20:13:47 +08:00
|
|
|
static int legacyfb_depth = 16;
|
|
|
|
module_param(legacyfb_depth, int, 0444);
|
2015-10-27 16:10:57 +08:00
|
|
|
#endif
|
2013-11-03 20:13:47 +08:00
|
|
|
|
2012-09-21 16:07:47 +08:00
|
|
|
static void imx_drm_driver_lastclose(struct drm_device *drm)
|
|
|
|
{
|
|
|
|
struct imx_drm_device *imxdrm = drm->dev_private;
|
|
|
|
|
2015-07-06 04:45:23 +08:00
|
|
|
drm_fbdev_cma_restore_mode(imxdrm->fbhelper);
|
2012-09-21 16:07:47 +08:00
|
|
|
}
|
|
|
|
|
2015-09-25 00:35:31 +08:00
|
|
|
static int imx_drm_enable_vblank(struct drm_device *drm, unsigned int pipe)
|
2012-09-21 16:07:47 +08:00
|
|
|
{
|
|
|
|
struct imx_drm_device *imxdrm = drm->dev_private;
|
2015-09-25 00:35:31 +08:00
|
|
|
struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[pipe];
|
2012-09-21 16:07:47 +08: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;
|
|
|
|
}
|
|
|
|
|
2015-09-25 00:35:31 +08:00
|
|
|
static void imx_drm_disable_vblank(struct drm_device *drm, unsigned int pipe)
|
2012-09-21 16:07:47 +08:00
|
|
|
{
|
|
|
|
struct imx_drm_device *imxdrm = drm->dev_private;
|
2015-09-25 00:35:31 +08:00
|
|
|
struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[pipe];
|
2012-09-21 16:07:47 +08: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 21:28:24 +08:00
|
|
|
void imx_drm_connector_destroy(struct drm_connector *connector)
|
|
|
|
{
|
2014-05-29 23:57:41 +08:00
|
|
|
drm_connector_unregister(connector);
|
2013-11-03 21:28:24 +08: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-04 06:18:40 +08:00
|
|
|
static void imx_drm_output_poll_changed(struct drm_device *drm)
|
|
|
|
{
|
|
|
|
struct imx_drm_device *imxdrm = drm->dev_private;
|
|
|
|
|
|
|
|
drm_fbdev_cma_hotplug_event(imxdrm->fbhelper);
|
|
|
|
}
|
|
|
|
|
2016-08-26 15:30:44 +08:00
|
|
|
static int imx_drm_atomic_check(struct drm_device *dev,
|
|
|
|
struct drm_atomic_state *state)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = drm_atomic_helper_check_modeset(dev, state);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = drm_atomic_helper_check_planes(dev, state);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check modeset again in case crtc_state->mode_changed is
|
|
|
|
* updated in plane's ->atomic_check callback.
|
|
|
|
*/
|
|
|
|
ret = drm_atomic_helper_check_modeset(dev, state);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-08-11 17:18:51 +08:00
|
|
|
static int imx_drm_atomic_commit(struct drm_device *dev,
|
|
|
|
struct drm_atomic_state *state,
|
|
|
|
bool nonblock)
|
|
|
|
{
|
|
|
|
struct drm_plane_state *plane_state;
|
|
|
|
struct drm_plane *plane;
|
|
|
|
struct dma_buf *dma_buf;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the plane fb has an dma-buf attached, fish out the exclusive
|
|
|
|
* fence for the atomic helper to wait on.
|
|
|
|
*/
|
|
|
|
for_each_plane_in_state(state, plane, plane_state, i) {
|
|
|
|
if ((plane->state->fb != plane_state->fb) && plane_state->fb) {
|
|
|
|
dma_buf = drm_fb_cma_get_gem_obj(plane_state->fb,
|
|
|
|
0)->base.dma_buf;
|
|
|
|
if (!dma_buf)
|
|
|
|
continue;
|
|
|
|
plane_state->fence =
|
|
|
|
reservation_object_get_excl_rcu(dma_buf->resv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return drm_atomic_helper_commit(dev, state, nonblock);
|
|
|
|
}
|
|
|
|
|
2015-12-15 19:21:09 +08:00
|
|
|
static const struct drm_mode_config_funcs imx_drm_mode_config_funcs = {
|
2013-11-04 00:04:48 +08:00
|
|
|
.fb_create = drm_fb_cma_create,
|
2013-11-04 06:18:40 +08:00
|
|
|
.output_poll_changed = imx_drm_output_poll_changed,
|
2016-08-26 15:30:44 +08:00
|
|
|
.atomic_check = imx_drm_atomic_check,
|
2016-08-11 17:18:51 +08:00
|
|
|
.atomic_commit = imx_drm_atomic_commit,
|
2016-07-08 17:40:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void imx_drm_atomic_commit_tail(struct drm_atomic_state *state)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = state->dev;
|
|
|
|
|
|
|
|
drm_atomic_helper_commit_modeset_disables(dev, state);
|
|
|
|
|
2016-08-29 17:12:03 +08:00
|
|
|
drm_atomic_helper_commit_planes(dev, state,
|
2016-08-26 15:30:43 +08:00
|
|
|
DRM_PLANE_COMMIT_ACTIVE_ONLY |
|
|
|
|
DRM_PLANE_COMMIT_NO_DISABLE_AFTER_MODESET);
|
2016-07-08 17:40:59 +08:00
|
|
|
|
|
|
|
drm_atomic_helper_commit_modeset_enables(dev, state);
|
|
|
|
|
|
|
|
drm_atomic_helper_commit_hw_done(state);
|
|
|
|
|
|
|
|
drm_atomic_helper_wait_for_vblanks(dev, state);
|
|
|
|
|
|
|
|
drm_atomic_helper_cleanup_planes(dev, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct drm_mode_config_helper_funcs imx_drm_mode_config_helpers = {
|
|
|
|
.atomic_commit_tail = imx_drm_atomic_commit_tail,
|
2013-11-04 00:04:48 +08:00
|
|
|
};
|
|
|
|
|
2012-09-21 16:07:47 +08:00
|
|
|
/*
|
|
|
|
* imx_drm_add_crtc - add a new crtc
|
|
|
|
*/
|
2013-11-03 20:26:23 +08:00
|
|
|
int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
|
2015-11-06 18:08:02 +08:00
|
|
|
struct imx_drm_crtc **new_crtc, struct drm_plane *primary_plane,
|
2012-09-21 16:07:47 +08:00
|
|
|
const struct imx_drm_crtc_helper_funcs *imx_drm_helper_funcs,
|
2014-03-05 17:20:52 +08:00
|
|
|
struct device_node *port)
|
2012-09-21 16:07:47 +08:00
|
|
|
{
|
2013-11-03 20:26:23 +08:00
|
|
|
struct imx_drm_device *imxdrm = drm->dev_private;
|
2012-09-21 16:07:47 +08:00
|
|
|
struct imx_drm_crtc *imx_drm_crtc;
|
|
|
|
|
2013-12-16 20:39:31 +08:00
|
|
|
/*
|
|
|
|
* The vblank arrays are dimensioned by MAX_CRTC - we can't
|
|
|
|
* pass IDs greater than this to those functions.
|
|
|
|
*/
|
2013-11-03 23:38:09 +08:00
|
|
|
if (imxdrm->pipes >= MAX_CRTC)
|
|
|
|
return -EINVAL;
|
2013-12-16 20:39:31 +08:00
|
|
|
|
2013-11-03 23:38:09 +08:00
|
|
|
if (imxdrm->drm->open_count)
|
|
|
|
return -EBUSY;
|
2012-09-21 16:07:47 +08:00
|
|
|
|
|
|
|
imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
|
2013-11-03 23:38:09 +08:00
|
|
|
if (!imx_drm_crtc)
|
|
|
|
return -ENOMEM;
|
2012-09-21 16:07:47 +08:00
|
|
|
|
|
|
|
imx_drm_crtc->imx_drm_helper_funcs = *imx_drm_helper_funcs;
|
|
|
|
imx_drm_crtc->crtc = crtc;
|
|
|
|
|
2014-07-04 00:52:57 +08:00
|
|
|
crtc->port = port;
|
|
|
|
|
2015-12-15 19:20:52 +08:00
|
|
|
imxdrm->crtc[imxdrm->pipes++] = imx_drm_crtc;
|
2012-09-21 16:07:47 +08:00
|
|
|
|
|
|
|
*new_crtc = imx_drm_crtc;
|
|
|
|
|
2013-12-18 03:11:07 +08:00
|
|
|
drm_crtc_helper_add(crtc,
|
|
|
|
imx_drm_crtc->imx_drm_helper_funcs.crtc_helper_funcs);
|
|
|
|
|
2015-11-06 18:08:02 +08:00
|
|
|
drm_crtc_init_with_planes(drm, crtc, primary_plane, NULL,
|
drm: Pass 'name' to drm_crtc_init_with_planes()
Done with coccinelle for the most part. However, it thinks '...' is
part of the semantic patch, so I put an 'int DOTDOTDOT' placeholder
in its place and got rid of it with sed afterwards.
I didn't convert drm_crtc_init() since passing the varargs through
would mean either cpp macros or va_list, and I figured we don't
care about these legacy functions enough to warrant the extra pain.
@@
identifier dev, crtc, primary, cursor, funcs;
@@
int drm_crtc_init_with_planes(struct drm_device *dev,
struct drm_crtc *crtc,
struct drm_plane *primary, struct drm_plane *cursor,
const struct drm_crtc_funcs *funcs
+ ,const char *name, int DOTDOTDOT
)
{ ... }
@@
identifier dev, crtc, primary, cursor, funcs;
@@
int drm_crtc_init_with_planes(struct drm_device *dev,
struct drm_crtc *crtc,
struct drm_plane *primary, struct drm_plane *cursor,
const struct drm_crtc_funcs *funcs
+ ,const char *name, int DOTDOTDOT
);
@@
expression E1, E2, E3, E4, E5;
@@
drm_crtc_init_with_planes(E1, E2, E3, E4, E5
+ ,NULL
)
v2: Split crtc and plane changes apart
Pass NULL for no-name instead of ""
Leave drm_crtc_init() alone
v3: Add ', or NULL...' to @name kernel doc (Jani)
Annotate the function with __printf() attribute (Jani)
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1449670771-2751-1-git-send-email-ville.syrjala@linux.intel.com
2015-12-09 22:19:31 +08:00
|
|
|
imx_drm_crtc->imx_drm_helper_funcs.crtc_funcs, NULL);
|
2013-12-18 03:11:07 +08:00
|
|
|
|
2012-09-21 16:07:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
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 23:20:18 +08:00
|
|
|
struct imx_drm_device *imxdrm = imx_drm_crtc->crtc->dev->dev_private;
|
2015-12-15 19:20:52 +08:00
|
|
|
unsigned int pipe = drm_crtc_index(imx_drm_crtc->crtc);
|
2012-09-21 16:07:47 +08:00
|
|
|
|
|
|
|
drm_crtc_cleanup(imx_drm_crtc->crtc);
|
|
|
|
|
2015-12-15 19:20:52 +08:00
|
|
|
imxdrm->crtc[pipe] = NULL;
|
2012-09-21 16:07:47 +08:00
|
|
|
|
|
|
|
kfree(imx_drm_crtc);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(imx_drm_remove_crtc);
|
|
|
|
|
2014-07-04 00:52:57 +08:00
|
|
|
int imx_drm_encoder_parse_of(struct drm_device *drm,
|
|
|
|
struct drm_encoder *encoder, struct device_node *np)
|
2013-11-03 22:04:47 +08:00
|
|
|
{
|
2014-07-04 00:52:57 +08:00
|
|
|
uint32_t crtc_mask = drm_of_find_possible_crtcs(drm, np);
|
2013-11-03 22:04:47 +08:00
|
|
|
|
2014-07-04 00:52:57 +08: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 (crtc_mask == 0)
|
|
|
|
return -EPROBE_DEFER;
|
2014-03-05 17:20:52 +08:00
|
|
|
|
2014-07-04 00:52:57 +08:00
|
|
|
encoder->possible_crtcs = crtc_mask;
|
2014-08-05 03:07:07 +08:00
|
|
|
|
2014-07-04 00:52:57 +08:00
|
|
|
/* FIXME: this is the mask of outputs which can clone this output. */
|
|
|
|
encoder->possible_clones = ~0;
|
2013-11-03 22:04:47 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-07-04 00:52:57 +08:00
|
|
|
EXPORT_SYMBOL_GPL(imx_drm_encoder_parse_of);
|
2013-11-03 22:04:47 +08:00
|
|
|
|
2013-08-03 01:27:49 +08:00
|
|
|
static const struct drm_ioctl_desc imx_drm_ioctls[] = {
|
2012-09-21 16:07:47 +08:00
|
|
|
/* none so far */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct drm_driver imx_drm_driver = {
|
2016-07-08 17:41:02 +08:00
|
|
|
.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME |
|
|
|
|
DRIVER_ATOMIC,
|
2012-09-21 16:07:47 +08:00
|
|
|
.lastclose = imx_drm_driver_lastclose,
|
2016-04-27 01:29:52 +08:00
|
|
|
.gem_free_object_unlocked = drm_gem_cma_free_object,
|
2012-09-21 16:07:47 +08:00
|
|
|
.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 15:12:04 +08:00
|
|
|
.dumb_destroy = drm_gem_dumb_destroy,
|
2012-09-21 16:07:47 +08:00
|
|
|
|
2013-10-10 22:18:46 +08: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,
|
2015-09-30 21:46:48 +08:00
|
|
|
.get_vblank_counter = drm_vblank_no_hw_counter,
|
2012-09-21 16:07:47 +08:00
|
|
|
.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 19:23:34 +08:00
|
|
|
static int compare_of(struct device *dev, void *data)
|
|
|
|
{
|
2014-03-05 17:20:52 +08:00
|
|
|
struct device_node *np = data;
|
2013-11-03 19:23:34 +08:00
|
|
|
|
2016-05-12 21:00:44 +08:00
|
|
|
/* Special case for DI, dev->of_node may not be set yet */
|
|
|
|
if (strcmp(dev->driver->name, "imx-ipuv3-crtc") == 0) {
|
|
|
|
struct ipu_client_platformdata *pdata = dev->platform_data;
|
|
|
|
|
|
|
|
return pdata->of_node == np;
|
|
|
|
}
|
|
|
|
|
2014-03-05 17:20:52 +08: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 19:23:34 +08:00
|
|
|
}
|
|
|
|
|
2014-03-05 17:20:52 +08:00
|
|
|
return dev->of_node == np;
|
|
|
|
}
|
2013-11-03 19:23:34 +08:00
|
|
|
|
|
|
|
static int imx_drm_bind(struct device *dev)
|
|
|
|
{
|
2016-08-11 17:18:48 +08:00
|
|
|
struct drm_device *drm;
|
|
|
|
struct imx_drm_device *imxdrm;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
drm = drm_dev_alloc(&imx_drm_driver, dev);
|
|
|
|
if (!drm)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
imxdrm = devm_kzalloc(dev, sizeof(*imxdrm), GFP_KERNEL);
|
|
|
|
if (!imxdrm) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_unref;
|
|
|
|
}
|
|
|
|
|
|
|
|
imxdrm->drm = drm;
|
|
|
|
drm->dev_private = imxdrm;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* enable drm irq mode.
|
|
|
|
* - with irq_enabled = true, we can use the vblank feature.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
drm->irq_enabled = true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
drm->mode_config.helper_private = &imx_drm_mode_config_helpers;
|
|
|
|
|
|
|
|
drm_mode_config_init(drm);
|
|
|
|
|
|
|
|
ret = drm_vblank_init(drm, MAX_CRTC);
|
|
|
|
if (ret)
|
|
|
|
goto err_kms;
|
|
|
|
|
|
|
|
dev_set_drvdata(dev, drm);
|
|
|
|
|
|
|
|
/* Now try and bind all our sub-components */
|
|
|
|
ret = component_bind_all(dev, drm);
|
|
|
|
if (ret)
|
|
|
|
goto err_vblank;
|
|
|
|
|
|
|
|
drm_mode_config_reset(drm);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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_FBDEV_EMULATION)
|
|
|
|
if (legacyfb_depth != 16 && legacyfb_depth != 32) {
|
|
|
|
dev_warn(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
|
|
|
|
|
|
|
|
drm_kms_helper_poll_init(drm);
|
|
|
|
|
|
|
|
ret = drm_dev_register(drm, 0);
|
|
|
|
if (ret)
|
|
|
|
goto err_fbhelper;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_fbhelper:
|
|
|
|
drm_kms_helper_poll_fini(drm);
|
2016-09-22 17:50:52 +08:00
|
|
|
#if IS_ENABLED(CONFIG_DRM_FBDEV_EMULATION)
|
2016-08-11 17:18:48 +08:00
|
|
|
if (imxdrm->fbhelper)
|
|
|
|
drm_fbdev_cma_fini(imxdrm->fbhelper);
|
|
|
|
err_unbind:
|
2016-09-22 17:50:52 +08:00
|
|
|
#endif
|
2016-08-11 17:18:48 +08:00
|
|
|
component_unbind_all(drm->dev, drm);
|
|
|
|
err_vblank:
|
|
|
|
drm_vblank_cleanup(drm);
|
|
|
|
err_kms:
|
|
|
|
drm_mode_config_cleanup(drm);
|
|
|
|
err_unref:
|
|
|
|
drm_dev_unref(drm);
|
|
|
|
|
|
|
|
return ret;
|
2013-11-03 19:23:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void imx_drm_unbind(struct device *dev)
|
|
|
|
{
|
2016-08-11 17:18:48 +08:00
|
|
|
struct drm_device *drm = dev_get_drvdata(dev);
|
|
|
|
struct imx_drm_device *imxdrm = drm->dev_private;
|
|
|
|
|
|
|
|
drm_dev_unregister(drm);
|
|
|
|
|
|
|
|
drm_kms_helper_poll_fini(drm);
|
|
|
|
|
|
|
|
if (imxdrm->fbhelper)
|
|
|
|
drm_fbdev_cma_fini(imxdrm->fbhelper);
|
|
|
|
|
2016-08-11 17:18:49 +08:00
|
|
|
drm_mode_config_cleanup(drm);
|
|
|
|
|
2016-08-11 17:18:48 +08:00
|
|
|
component_unbind_all(drm->dev, drm);
|
|
|
|
dev_set_drvdata(dev, NULL);
|
|
|
|
|
|
|
|
drm_dev_unref(drm);
|
2013-11-03 19:23:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct component_master_ops imx_drm_ops = {
|
|
|
|
.bind = imx_drm_bind,
|
|
|
|
.unbind = imx_drm_unbind,
|
|
|
|
};
|
|
|
|
|
2012-09-21 16:07:47 +08:00
|
|
|
static int imx_drm_platform_probe(struct platform_device *pdev)
|
|
|
|
{
|
2015-10-20 17:23:13 +08:00
|
|
|
int ret = drm_of_component_probe(&pdev->dev, compare_of, &imx_drm_ops);
|
2014-03-05 17:20:52 +08:00
|
|
|
|
2015-10-20 17:23:13 +08:00
|
|
|
if (!ret)
|
|
|
|
ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
|
2014-03-05 17:20:52 +08:00
|
|
|
|
2015-10-20 17:23:13 +08:00
|
|
|
return ret;
|
2012-09-21 16:07:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_drm_platform_remove(struct platform_device *pdev)
|
|
|
|
{
|
2013-11-03 19:23:34 +08:00
|
|
|
component_master_del(&pdev->dev, &imx_drm_ops);
|
2012-09-21 16:07:47 +08: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);
|
2016-07-08 17:40:59 +08:00
|
|
|
struct imx_drm_device *imxdrm;
|
2014-09-10 22:43:51 +08:00
|
|
|
|
|
|
|
/* The drm_dev is NULL before .load hook is called */
|
|
|
|
if (drm_dev == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
drm_kms_helper_poll_disable(drm_dev);
|
|
|
|
|
2016-07-08 17:40:59 +08:00
|
|
|
imxdrm = drm_dev->dev_private;
|
|
|
|
imxdrm->state = drm_atomic_helper_suspend(drm_dev);
|
|
|
|
if (IS_ERR(imxdrm->state)) {
|
|
|
|
drm_kms_helper_poll_enable(drm_dev);
|
|
|
|
return PTR_ERR(imxdrm->state);
|
|
|
|
}
|
|
|
|
|
2014-09-10 22:43:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_drm_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct drm_device *drm_dev = dev_get_drvdata(dev);
|
2016-07-08 17:40:59 +08:00
|
|
|
struct imx_drm_device *imx_drm;
|
2014-09-10 22:43:51 +08:00
|
|
|
|
|
|
|
if (drm_dev == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2016-07-08 17:40:59 +08:00
|
|
|
imx_drm = drm_dev->dev_private;
|
|
|
|
drm_atomic_helper_resume(drm_dev, imx_drm->state);
|
2014-09-10 22:43:51 +08:00
|
|
|
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 19:23:34 +08:00
|
|
|
static const struct of_device_id imx_drm_dt_ids[] = {
|
2014-03-05 17:20:52 +08:00
|
|
|
{ .compatible = "fsl,imx-display-subsystem", },
|
2013-11-03 19:23:34 +08:00
|
|
|
{ /* sentinel */ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, imx_drm_dt_ids);
|
|
|
|
|
2012-09-21 16:07:47 +08:00
|
|
|
static struct platform_driver imx_drm_pdrv = {
|
|
|
|
.probe = imx_drm_platform_probe,
|
2012-11-20 02:20:51 +08:00
|
|
|
.remove = imx_drm_platform_remove,
|
2012-09-21 16:07:47 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "imx-drm",
|
2014-09-10 22:43:51 +08:00
|
|
|
.pm = &imx_drm_pm_ops,
|
2013-11-03 19:23:34 +08:00
|
|
|
.of_match_table = imx_drm_dt_ids,
|
2012-09-21 16:07:47 +08:00
|
|
|
},
|
|
|
|
};
|
2013-11-03 23:31:22 +08:00
|
|
|
module_platform_driver(imx_drm_pdrv);
|
2012-09-21 16:07:47 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
|
|
|
|
MODULE_DESCRIPTION("i.MX drm driver core");
|
|
|
|
MODULE_LICENSE("GPL");
|