From: Hyun Kwon <hyun.k...@xilinx.com>

Signed-off-by: Hyun Kwon <hyun.k...@xilinx.com>
Signed-off-by: Quanyang Wang <quanyang.w...@windriver.com>
---
 drivers/gpu/drm/xlnx/xlnx_fb.c | 56 ++++++++++++++++++++++++++++++++--
 1 file changed, 54 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/xlnx/xlnx_fb.c b/drivers/gpu/drm/xlnx/xlnx_fb.c
index dfe769d4788c..58c5d1d17ae9 100644
--- a/drivers/gpu/drm/xlnx/xlnx_fb.c
+++ b/drivers/gpu/drm/xlnx/xlnx_fb.c
@@ -90,6 +90,58 @@ static struct fb_ops xlnx_fbdev_ops = {
        .fb_ioctl       = xlnx_fb_ioctl,
 };
 
+static struct drm_framebuffer *
+xlnx_fb_gem_fb_alloc(struct drm_device *drm,
+                    const struct drm_mode_fb_cmd2 *mode_cmd,
+                    struct drm_gem_object **obj, unsigned int num_planes,
+                    const struct drm_framebuffer_funcs *funcs)
+{
+       struct drm_framebuffer *fb;
+       int ret, i;
+
+       fb = kzalloc(sizeof(*fb), GFP_KERNEL);
+       if (!fb)
+               return ERR_PTR(-ENOMEM);
+
+       drm_helper_mode_fill_fb_struct(drm, fb, mode_cmd);
+
+       for (i = 0; i < num_planes; i++)
+               fb->obj[i] = obj[i];
+
+       ret = drm_framebuffer_init(drm, fb, funcs);
+       if (ret) {
+               dev_err(drm->dev, "Failed to init framebuffer: %d\n", ret);
+               kfree(fb);
+               return ERR_PTR(ret);
+       }
+
+       return fb;
+}
+
+static struct drm_framebuffer *
+xlnx_fb_gem_fbdev_fb_create(struct drm_device *drm,
+                       struct drm_fb_helper_surface_size *size,
+                       unsigned int pitch_align, struct drm_gem_object *obj,
+                       const struct drm_framebuffer_funcs *funcs)
+{
+       struct drm_mode_fb_cmd2 mode_cmd = { 0 };
+
+       mode_cmd.width = size->surface_width;
+       mode_cmd.height = size->surface_height;
+       mode_cmd.pitches[0] = size->surface_width *
+                             DIV_ROUND_UP(size->surface_bpp, 8);
+       if (pitch_align)
+               mode_cmd.pitches[0] = roundup(mode_cmd.pitches[0],
+                                             pitch_align);
+       mode_cmd.pixel_format = drm_driver_legacy_fb_format(drm,
+                                                           size->surface_bpp,
+                                                           
size->surface_depth);
+       if (obj->size < mode_cmd.pitches[0] * mode_cmd.height)
+               return ERR_PTR(-EINVAL);
+
+       return xlnx_fb_gem_fb_alloc(drm, &mode_cmd, &obj, 1, funcs);
+}
+
 /**
  * xlnx_fbdev_create - Create the fbdev with a framebuffer
  * @fb_helper: fb helper structure
@@ -139,8 +191,8 @@ static int xlnx_fbdev_create(struct drm_fb_helper 
*fb_helper,
        if (size->surface_bpp == info->cpp[0] * 8)
                size->surface_depth = info->depth;
 
-       fbdev->fb = drm_gem_fbdev_fb_create(drm, size, fbdev->align, &obj->base,
-                                           &xlnx_fb_funcs);
+       fbdev->fb = xlnx_fb_gem_fbdev_fb_create(drm, size, fbdev->align,
+                                               &obj->base, &xlnx_fb_funcs);
        if (IS_ERR(fbdev->fb)) {
                dev_err(drm->dev, "Failed to allocate DRM framebuffer.\n");
                ret = PTR_ERR(fbdev->fb);
-- 
2.17.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#8222): 
https://lists.yoctoproject.org/g/linux-yocto/message/8222
Mute This Topic: https://lists.yoctoproject.org/mt/68719914/21656
Group Owner: linux-yocto+ow...@lists.yoctoproject.org
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub  
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to