2019-05-29 21:17:56 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2014-08-22 17:36:26 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
|
|
|
|
* Author:Mark Yao <mark.yao@rock-chips.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <drm/drm.h>
|
|
|
|
#include <drm/drm_fb_helper.h>
|
2019-07-16 13:42:19 +07:00
|
|
|
#include <drm/drm_fourcc.h>
|
2019-01-18 04:03:34 +07:00
|
|
|
#include <drm/drm_probe_helper.h>
|
2014-08-22 17:36:26 +07:00
|
|
|
|
|
|
|
#include "rockchip_drm_drv.h"
|
|
|
|
#include "rockchip_drm_gem.h"
|
|
|
|
#include "rockchip_drm_fb.h"
|
2016-09-25 14:38:28 +07:00
|
|
|
#include "rockchip_drm_fbdev.h"
|
2014-08-22 17:36:26 +07:00
|
|
|
|
|
|
|
#define PREFERRED_BPP 32
|
|
|
|
#define to_drm_private(x) \
|
|
|
|
container_of(x, struct rockchip_drm_private, fbdev_helper)
|
|
|
|
|
|
|
|
static int rockchip_fbdev_mmap(struct fb_info *info,
|
|
|
|
struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct drm_fb_helper *helper = info->par;
|
|
|
|
struct rockchip_drm_private *private = to_drm_private(helper);
|
|
|
|
|
|
|
|
return rockchip_gem_mmap_buf(private->fbdev_bo, vma);
|
|
|
|
}
|
|
|
|
|
2019-12-03 23:38:48 +07:00
|
|
|
static const struct fb_ops rockchip_drm_fbdev_ops = {
|
2014-08-22 17:36:26 +07:00
|
|
|
.owner = THIS_MODULE,
|
2016-11-14 06:03:20 +07:00
|
|
|
DRM_FB_HELPER_DEFAULT_OPS,
|
2014-08-22 17:36:26 +07:00
|
|
|
.fb_mmap = rockchip_fbdev_mmap,
|
2015-07-22 16:28:03 +07:00
|
|
|
.fb_fillrect = drm_fb_helper_cfb_fillrect,
|
|
|
|
.fb_copyarea = drm_fb_helper_cfb_copyarea,
|
|
|
|
.fb_imageblit = drm_fb_helper_cfb_imageblit,
|
2014-08-22 17:36:26 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static int rockchip_drm_fbdev_create(struct drm_fb_helper *helper,
|
|
|
|
struct drm_fb_helper_surface_size *sizes)
|
|
|
|
{
|
|
|
|
struct rockchip_drm_private *private = to_drm_private(helper);
|
|
|
|
struct drm_mode_fb_cmd2 mode_cmd = { 0 };
|
|
|
|
struct drm_device *dev = helper->dev;
|
|
|
|
struct rockchip_gem_object *rk_obj;
|
|
|
|
struct drm_framebuffer *fb;
|
|
|
|
unsigned int bytes_per_pixel;
|
|
|
|
unsigned long offset;
|
|
|
|
struct fb_info *fbi;
|
|
|
|
size_t size;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
bytes_per_pixel = DIV_ROUND_UP(sizes->surface_bpp, 8);
|
|
|
|
|
|
|
|
mode_cmd.width = sizes->surface_width;
|
|
|
|
mode_cmd.height = sizes->surface_height;
|
|
|
|
mode_cmd.pitches[0] = sizes->surface_width * bytes_per_pixel;
|
|
|
|
mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
|
|
|
|
sizes->surface_depth);
|
|
|
|
|
|
|
|
size = mode_cmd.pitches[0] * mode_cmd.height;
|
|
|
|
|
2015-01-12 13:58:23 +07:00
|
|
|
rk_obj = rockchip_gem_create_object(dev, size, true);
|
2014-08-22 17:36:26 +07:00
|
|
|
if (IS_ERR(rk_obj))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
private->fbdev_bo = &rk_obj->base;
|
|
|
|
|
2015-07-22 16:28:03 +07:00
|
|
|
fbi = drm_fb_helper_alloc_fbi(helper);
|
|
|
|
if (IS_ERR(fbi)) {
|
2017-09-15 15:36:03 +07:00
|
|
|
DRM_DEV_ERROR(dev->dev, "Failed to create framebuffer info.\n");
|
2015-07-22 16:28:03 +07:00
|
|
|
ret = PTR_ERR(fbi);
|
2017-02-07 23:16:03 +07:00
|
|
|
goto out;
|
2014-08-22 17:36:26 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
helper->fb = rockchip_drm_framebuffer_init(dev, &mode_cmd,
|
|
|
|
private->fbdev_bo);
|
|
|
|
if (IS_ERR(helper->fb)) {
|
2017-09-15 15:36:03 +07:00
|
|
|
DRM_DEV_ERROR(dev->dev,
|
|
|
|
"Failed to allocate DRM framebuffer.\n");
|
2014-08-22 17:36:26 +07:00
|
|
|
ret = PTR_ERR(helper->fb);
|
2017-02-07 23:16:03 +07:00
|
|
|
goto out;
|
2014-08-22 17:36:26 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
fbi->fbops = &rockchip_drm_fbdev_ops;
|
|
|
|
|
|
|
|
fb = helper->fb;
|
2019-03-26 20:20:04 +07:00
|
|
|
drm_fb_helper_fill_info(fbi, helper, sizes);
|
2014-08-22 17:36:26 +07:00
|
|
|
|
|
|
|
offset = fbi->var.xoffset * bytes_per_pixel;
|
|
|
|
offset += fbi->var.yoffset * fb->pitches[0];
|
|
|
|
|
|
|
|
dev->mode_config.fb_base = 0;
|
|
|
|
fbi->screen_base = rk_obj->kvaddr + offset;
|
|
|
|
fbi->screen_size = rk_obj->base.size;
|
|
|
|
fbi->fix.smem_len = rk_obj->base.size;
|
|
|
|
|
2016-06-10 00:46:32 +07:00
|
|
|
DRM_DEBUG_KMS("FB [%dx%d]-%d kvaddr=%p offset=%ld size=%zu\n",
|
2016-12-15 04:31:35 +07:00
|
|
|
fb->width, fb->height, fb->format->depth,
|
|
|
|
rk_obj->kvaddr,
|
2014-08-22 17:36:26 +07:00
|
|
|
offset, size);
|
2015-03-31 17:22:50 +07:00
|
|
|
|
2014-08-22 17:36:26 +07:00
|
|
|
return 0;
|
|
|
|
|
2017-02-07 23:16:03 +07:00
|
|
|
out:
|
2014-08-22 17:36:26 +07:00
|
|
|
rockchip_gem_free_object(&rk_obj->base);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_fb_helper_funcs rockchip_drm_fb_helper_funcs = {
|
|
|
|
.fb_probe = rockchip_drm_fbdev_create,
|
|
|
|
};
|
|
|
|
|
|
|
|
int rockchip_drm_fbdev_init(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct rockchip_drm_private *private = dev->dev_private;
|
|
|
|
struct drm_fb_helper *helper;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!dev->mode_config.num_crtc || !dev->mode_config.num_connector)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
helper = &private->fbdev_helper;
|
|
|
|
|
|
|
|
drm_fb_helper_prepare(dev, helper, &rockchip_drm_fb_helper_funcs);
|
|
|
|
|
drm: Rely on mode_config data for fb_helper initialization
Instead of receiving the num_crts as a parameter, we can read it
directly from the mode_config structure. I audited the drivers that
invoke this helper and I believe all of them initialize the mode_config
struct accordingly, prior to calling the fb_helper.
I used the following coccinelle hack to make this transformation, except
for the function headers and comment updates. The first and second
rules are split because I couldn't find a way to remove the unused
temporary variables at the same time I removed the parameter.
// <smpl>
@r@
expression A,B,D,E;
identifier C;
@@
(
- drm_fb_helper_init(A,B,C,D)
+ drm_fb_helper_init(A,B,D)
|
- drm_fbdev_cma_init_with_funcs(A,B,C,D,E)
+ drm_fbdev_cma_init_with_funcs(A,B,D,E)
|
- drm_fbdev_cma_init(A,B,C,D)
+ drm_fbdev_cma_init(A,B,D)
)
@@
expression A,B,C,D,E;
@@
(
- drm_fb_helper_init(A,B,C,D)
+ drm_fb_helper_init(A,B,D)
|
- drm_fbdev_cma_init_with_funcs(A,B,C,D,E)
+ drm_fbdev_cma_init_with_funcs(A,B,D,E)
|
- drm_fbdev_cma_init(A,B,C,D)
+ drm_fbdev_cma_init(A,B,D)
)
@@
identifier r.C;
type T;
expression V;
@@
- T C;
<...
when != C
- C = V;
...>
// </smpl>
Changes since v1:
- Rebased on top of the tip of drm-misc-next.
- Remove mention to sti since a proper fix got merged.
Suggested-by: Daniel Vetter <daniel.vetter@intel.com>
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.co.uk>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20170202162640.27261-1-krisman@collabora.co.uk
2017-02-02 23:26:40 +07:00
|
|
|
ret = drm_fb_helper_init(dev, helper, ROCKCHIP_MAX_CONNECTOR);
|
2014-08-22 17:36:26 +07:00
|
|
|
if (ret < 0) {
|
2017-09-15 15:36:03 +07:00
|
|
|
DRM_DEV_ERROR(dev->dev,
|
|
|
|
"Failed to initialize drm fb helper - %d.\n",
|
|
|
|
ret);
|
2014-08-22 17:36:26 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = drm_fb_helper_single_add_all_connectors(helper);
|
|
|
|
if (ret < 0) {
|
2017-09-15 15:36:03 +07:00
|
|
|
DRM_DEV_ERROR(dev->dev,
|
|
|
|
"Failed to add connectors - %d.\n", ret);
|
2014-08-22 17:36:26 +07:00
|
|
|
goto err_drm_fb_helper_fini;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = drm_fb_helper_initial_config(helper, PREFERRED_BPP);
|
|
|
|
if (ret < 0) {
|
2017-09-15 15:36:03 +07:00
|
|
|
DRM_DEV_ERROR(dev->dev,
|
|
|
|
"Failed to set initial hw config - %d.\n",
|
|
|
|
ret);
|
2014-08-22 17:36:26 +07:00
|
|
|
goto err_drm_fb_helper_fini;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_drm_fb_helper_fini:
|
|
|
|
drm_fb_helper_fini(helper);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rockchip_drm_fbdev_fini(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct rockchip_drm_private *private = dev->dev_private;
|
|
|
|
struct drm_fb_helper *helper;
|
|
|
|
|
|
|
|
helper = &private->fbdev_helper;
|
|
|
|
|
2015-07-22 16:28:03 +07:00
|
|
|
drm_fb_helper_unregister_fbi(helper);
|
2014-08-22 17:36:26 +07:00
|
|
|
|
|
|
|
if (helper->fb)
|
2017-08-11 19:33:06 +07:00
|
|
|
drm_framebuffer_put(helper->fb);
|
2014-08-22 17:36:26 +07:00
|
|
|
|
|
|
|
drm_fb_helper_fini(helper);
|
|
|
|
}
|