From patchwork Mon Oct 16 15:31:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Hecht X-Patchwork-Id: 10009037 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 710A960235 for ; Mon, 16 Oct 2017 15:49:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60D33285CD for ; Mon, 16 Oct 2017 15:49:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54F1E285D9; Mon, 16 Oct 2017 15:49:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 698C0285CD for ; Mon, 16 Oct 2017 15:49:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=m6seNA5XTeHDloqgefANQKo9w18annItr5ih7agrzy0=; b=EKZBGxxk7RXEmN/hGdoDsgE7QM HrLCNQBv0rXnRVOu8BCyA71c9bZuLEA92vkTGGB/7W0HIrQp3clV6txI3f7lQJOgCmJy+3CK35MbR uc5yN3IZCYZ1/obqeSwrK5dQ7b5Ff4BI3XksxV64f3141IdGV+abi/G7p+B9R7EOKT6ua16CLTEyp 2MjIyhCoWNHOAhkYfVZXPddKf03n2svmtUHSDHtmzeIcwVd5agSlZmwDCNVbajSQ2/ICqkFvXTVqv yEJARRcyiriF4WYWFmHansLEsrb+ptzZ6WxVUa2gF9lA9wDUVnK//JBM9Ca7fKR3rMbM0Qrv6/5xU pcLob20Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e47dh-00073L-Ud; Mon, 16 Oct 2017 15:49:13 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e47dg-00071O-Ho; Mon, 16 Oct 2017 15:49:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=wDJL6dBUxBH8GVONkn6pAPm90MDVy/YimO8yWEqXZ8A=; b=n0BRnfS+mjXlfkeK2YxD/vWMe qd2AJ4UkREYF79XfWuNedNClaMA7eJ15nSxEogZp9/n4/rlKPKZgnxERk69yaHYS1MK2LXQdTJHUD irSEwXLSmOCh9Ai902q6VA26csTRLcns5a0DkYGd3egm7ACH93JlYRMuYo09rHQql1M2eTPLkSiG6 QUSUGg72HKphBr1PegKgtECoEFadhANqgU424IzX5SkEVLwE93uLngZRzmzTMC/JKMA3q4TUnRhi/ MpJyTpgKMlizsbn9yNZDZyGxoW0w1C4aMHVp3QkXqzTM0jK4M29PF3VyW8yrLdS1FFS1o0dx6P8h4 uMkWs0seg==; Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e47NT-0004Ro-UF; Mon, 16 Oct 2017 15:32:29 +0000 Received: by mail-wm0-x243.google.com with SMTP id f4so4618908wme.0; Mon, 16 Oct 2017 08:32:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=wDJL6dBUxBH8GVONkn6pAPm90MDVy/YimO8yWEqXZ8A=; b=LWPg3fiN7pJKPVYxul08TaPaM2jVvG81Yobx+QwQyta5L9ET8Y9oUNfhW9yGYEOO14 5AzoTMPXKlKJXuAGfx66QzPdZs1oIRxaJaHQGTkACdPxJKRXI40EUNFK/6Ae+fQMipL2 R5CNxVE61QPwA+2k96MWR+Ma8YGeygtzvYR+h7QLZQkXKi+O8HuJHAAaSnF7WdREIEW+ hcyWifw0dWC470VL96KXT6a2Co8Wv8ha9PVHBVQUs2GM4BLk6TIHAn8ZxDW/heXlp+QK LMUozSulCUWGbu2jdo79ExSdF3xahHN+uMuJMXOAuCa6r//lM7xF0iivilRde+2A3vXR FekA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=wDJL6dBUxBH8GVONkn6pAPm90MDVy/YimO8yWEqXZ8A=; b=fYBUvHY0+fAAKQCbs8JKwEBwXPA01m3BgipDSVucMKAZUNdcnvhAYdw9TVRZw76zIW vXRlB3xZL3HOENa89shutV5TNIsufjbIFH/wsklESxjwuNRhhh75jGN9pbu/R8mmK0hY 6+HDXYokDiBrr6Z53DoUP/8pdWH7x55WNqLiD+Um4cL2d1ayc/p39DlcrwiEFe+TB9gW UfcEM/MpTOHoCg9FZdisbOTbxtp9aOrxlec91/wFOs6MKldXuLImrqXPWGnuOxEragUR APFuGXBTAGRYXsqF3DF/o7z/4rCfxTlj+dFcRH+fGPODvo1e1DlD6F1hiEksHW4ik61b YDPQ== X-Gm-Message-State: AMCzsaVMbl1yVvQGxc+eyVPgh8AWYWcm028222tFSvzmRCpekhtAL3+U GxUMlzsYWXQs73ZCtXRQ8IWI/Qk= X-Google-Smtp-Source: ABhQp+Sj2sYdWFbO8rcrXTnHyT2r3cikxIZIsV14Eq8fdkAxi8ekf+XlI2M5XdE53EyL+hezYFbXWg== X-Received: by 10.28.230.77 with SMTP id d74mr1142968wmh.75.1508167922565; Mon, 16 Oct 2017 08:32:02 -0700 (PDT) Received: from groucho.site (ipbcc0ce42.dynamic.kabel-deutschland.de. [188.192.206.66]) by smtp.gmail.com with ESMTPSA id v2sm6897751wmf.40.2017.10.16.08.32.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Oct 2017 08:32:01 -0700 (PDT) From: Ulrich Hecht To: linux-mediatek@lists.infradead.org Subject: [RFC v2 7/8] drm/mediatek: Add DRM-based framebuffer device Date: Mon, 16 Oct 2017 17:31:39 +0200 Message-Id: <1508167900-27415-8-git-send-email-ulrich.hecht+renesas@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508167900-27415-1-git-send-email-ulrich.hecht+renesas@gmail.com> References: <1508167900-27415-1-git-send-email-ulrich.hecht+renesas@gmail.com> X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jacopo@jmondi.org, magnus.damm@gmail.com, dri-devel@lists.freedesktop.org, Ulrich Hecht , laurent.pinchart@ideasonboard.com, Philipp Zabel , ck.hu@mediatek.com, robin.murphy@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add fbdev support to the Mediatek DRM driver. Signed-off-by: CK Hu Signed-off-by: YT Shen Signed-off-by: Philipp Zabel Signed-off-by: Daniel Kurtz [uli: Forward-ported from chromeos-3.18 vendor kernel.] Signed-off-by: Ulrich Hecht --- drivers/gpu/drm/mediatek/Makefile | 2 + drivers/gpu/drm/mediatek/mtk_drm_drv.c | 8 ++ drivers/gpu/drm/mediatek/mtk_drm_drv.h | 4 +- drivers/gpu/drm/mediatek/mtk_drm_fb.c | 13 +++ drivers/gpu/drm/mediatek/mtk_drm_fb.h | 3 + drivers/gpu/drm/mediatek/mtk_drm_fbdev.c | 181 +++++++++++++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_drm_fbdev.h | 32 ++++++ 7 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/mediatek/mtk_drm_fbdev.c create mode 100644 drivers/gpu/drm/mediatek/mtk_drm_fbdev.h diff --git a/drivers/gpu/drm/mediatek/Makefile b/drivers/gpu/drm/mediatek/Makefile index e37b55a..8306fb5 100644 --- a/drivers/gpu/drm/mediatek/Makefile +++ b/drivers/gpu/drm/mediatek/Makefile @@ -12,6 +12,8 @@ mediatek-drm-y := mtk_disp_color.o \ mtk_mipi_tx.o \ mtk_dpi.o +mediatek-drm-$(CONFIG_DRM_FBDEV_EMULATION) += mtk_drm_fbdev.o + obj-$(CONFIG_DRM_MEDIATEK) += mediatek-drm.o mediatek-drm-hdmi-objs := mtk_cec.o \ diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c index ce99921..636b8db 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c @@ -30,6 +30,7 @@ #include "mtk_drm_ddp_comp.h" #include "mtk_drm_drv.h" #include "mtk_drm_fb.h" +#include "mtk_drm_fbdev.h" #include "mtk_drm_gem.h" #define DRIVER_NAME "mediatek" @@ -257,8 +258,14 @@ static int mtk_drm_kms_init(struct drm_device *drm) drm_kms_helper_poll_init(drm); drm_mode_config_reset(drm); + ret = mtk_fbdev_init(drm); + if (ret) + goto err_kms_helper_poll_fini; + return 0; +err_kms_helper_poll_fini: + drm_kms_helper_poll_fini(drm); err_component_unbind: component_unbind_all(drm->dev, drm); err_config_cleanup: @@ -269,6 +276,7 @@ static int mtk_drm_kms_init(struct drm_device *drm) static void mtk_drm_kms_deinit(struct drm_device *drm) { + mtk_fbdev_fini(drm); drm_kms_helper_poll_fini(drm); component_unbind_all(drm->dev, drm); diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.h b/drivers/gpu/drm/mediatek/mtk_drm_drv.h index c3378c4..4edc002 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.h +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.h @@ -14,6 +14,7 @@ #ifndef MTK_DRM_DRV_H #define MTK_DRM_DRV_H +#include #include #include "mtk_drm_ddp_comp.h" @@ -24,7 +25,6 @@ struct device; struct device_node; struct drm_crtc; struct drm_device; -struct drm_fb_helper; struct drm_property; struct regmap; @@ -56,6 +56,8 @@ struct mtk_drm_private { } commit; struct drm_atomic_state *suspend_state; + struct drm_fb_helper fb_helper; + struct drm_gem_object *fbdev_bo; }; extern struct platform_driver mtk_ddp_driver; diff --git a/drivers/gpu/drm/mediatek/mtk_drm_fb.c b/drivers/gpu/drm/mediatek/mtk_drm_fb.c index 0d8d506..ac8561d 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_fb.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_fb.c @@ -96,6 +96,19 @@ static struct mtk_drm_fb *mtk_drm_framebuffer_init(struct drm_device *dev, return mtk_fb; } +struct drm_framebuffer *mtk_drm_framebuffer_create(struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode, + struct drm_gem_object *obj) +{ + struct mtk_drm_fb *mtk_fb; + + mtk_fb = mtk_drm_framebuffer_init(dev, mode, obj); + if (IS_ERR(mtk_fb)) + return ERR_CAST(mtk_fb); + + return &mtk_fb->base; +} + /* * Wait for any exclusive fence in fb's gem object's reservation object. * diff --git a/drivers/gpu/drm/mediatek/mtk_drm_fb.h b/drivers/gpu/drm/mediatek/mtk_drm_fb.h index 9b2ae34..9ee1ac2 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_fb.h +++ b/drivers/gpu/drm/mediatek/mtk_drm_fb.h @@ -19,5 +19,8 @@ int mtk_fb_wait(struct drm_framebuffer *fb); struct drm_framebuffer *mtk_drm_mode_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *cmd); +struct drm_framebuffer *mtk_drm_framebuffer_create(struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode, + struct drm_gem_object *obj); #endif /* MTK_DRM_FB_H */ diff --git a/drivers/gpu/drm/mediatek/mtk_drm_fbdev.c b/drivers/gpu/drm/mediatek/mtk_drm_fbdev.c new file mode 100644 index 0000000..9193647 --- /dev/null +++ b/drivers/gpu/drm/mediatek/mtk_drm_fbdev.c @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2016 MediaTek Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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. + */ + +#include +#include +#include +#include + +#include "mtk_drm_drv.h" +#include "mtk_drm_fb.h" +#include "mtk_drm_gem.h" + +#define to_drm_private(x) \ + container_of(x, struct mtk_drm_private, fb_helper) + +#if 1 +static int mtk_drm_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma) +{ + struct drm_fb_helper *helper = info->par; + struct mtk_drm_private *private = helper->dev->dev_private; + + return mtk_drm_gem_mmap_buf(private->fbdev_bo, vma); +} +#endif + +static struct fb_ops mtk_fbdev_ops = { + .owner = THIS_MODULE, + .fb_fillrect = drm_fb_helper_cfb_fillrect, + .fb_copyarea = drm_fb_helper_cfb_copyarea, + .fb_imageblit = drm_fb_helper_cfb_imageblit, + .fb_check_var = drm_fb_helper_check_var, + .fb_set_par = drm_fb_helper_set_par, + .fb_blank = drm_fb_helper_blank, + .fb_pan_display = drm_fb_helper_pan_display, + .fb_setcmap = drm_fb_helper_setcmap, + .fb_mmap = mtk_drm_fbdev_mmap, +}; + +static int mtk_fbdev_probe(struct drm_fb_helper *helper, + struct drm_fb_helper_surface_size *sizes) +{ + struct drm_device *dev = helper->dev; + struct mtk_drm_private *private = helper->dev->dev_private; + struct drm_mode_fb_cmd2 mode = { 0 }; + struct mtk_drm_gem_obj *mtk_gem; + struct fb_info *info; + struct drm_framebuffer *fb; + unsigned int bytes_per_pixel; + unsigned long offset; + size_t size; + int err; + + bytes_per_pixel = DIV_ROUND_UP(sizes->surface_bpp, 8); + + mode.width = sizes->surface_width; + mode.height = sizes->surface_height; + mode.pitches[0] = sizes->surface_width * bytes_per_pixel; + mode.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, + sizes->surface_depth); + + size = mode.pitches[0] * mode.height; + + mtk_gem = mtk_drm_gem_create(dev, size, true); + if (IS_ERR(mtk_gem)) + return PTR_ERR(mtk_gem); + + private->fbdev_bo = &mtk_gem->base; + + info = drm_fb_helper_alloc_fbi(helper); + if (IS_ERR(info)) { + err = PTR_ERR(info); + dev_err(dev->dev, "failed to allocate framebuffer info, %d\n", + err); + goto err_gem_free_object; + } + + fb = mtk_drm_framebuffer_create(dev, &mode, private->fbdev_bo); + if (IS_ERR(fb)) { + err = PTR_ERR(fb); + dev_err(dev->dev, "failed to allocate DRM framebuffer, %d\n", + err); + goto err_release_fbi; + } + helper->fb = fb; + + info->par = helper; + info->flags = FBINFO_FLAG_DEFAULT; + info->fbops = &mtk_fbdev_ops; + + drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth); + drm_fb_helper_fill_var(info, helper, sizes->fb_width, sizes->fb_height); + + offset = info->var.xoffset * bytes_per_pixel; + offset += info->var.yoffset * fb->pitches[0]; + + dev->mode_config.fb_base = 0; + info->screen_base = mtk_gem->kvaddr + offset; + info->screen_size = size; + info->fix.smem_len = size; + + DRM_DEBUG_KMS("FB [%ux%u]-%u offset=%lu size=%zd\n", + fb->width, fb->height, fb->format->depth, offset, size); + + info->skip_vt_switch = true; + + return 0; + +err_release_fbi: +err_gem_free_object: + mtk_drm_gem_free_object(&mtk_gem->base); + return err; +} + +static const struct drm_fb_helper_funcs mtk_drm_fb_helper_funcs = { + .fb_probe = mtk_fbdev_probe, +}; + +int mtk_fbdev_init(struct drm_device *dev) +{ + struct mtk_drm_private *priv = dev->dev_private; + struct drm_fb_helper *helper = &priv->fb_helper; + int ret; + + if (!dev->mode_config.num_crtc || !dev->mode_config.num_connector) + return -EINVAL; + + drm_fb_helper_prepare(dev, helper, &mtk_drm_fb_helper_funcs); + + ret = drm_fb_helper_init(dev, helper, + dev->mode_config.num_connector); + if (ret) { + dev_err(dev->dev, "failed to initialize DRM FB helper, %d\n", + ret); + goto fini; + } + + ret = drm_fb_helper_single_add_all_connectors(helper); + if (ret) { + dev_err(dev->dev, "failed to add connectors, %d\n", ret); + goto fini; + } + + ret = drm_fb_helper_initial_config(helper, 32); + if (ret) { + dev_err(dev->dev, "failed to set initial configuration, %d\n", + ret); + goto fini; + } + + return 0; + +fini: + drm_fb_helper_fini(helper); + + return ret; +} + +void mtk_fbdev_fini(struct drm_device *dev) +{ + struct mtk_drm_private *priv = dev->dev_private; + struct drm_fb_helper *helper = &priv->fb_helper; + + drm_fb_helper_unregister_fbi(helper); + + if (helper->fb) { + drm_framebuffer_unregister_private(helper->fb); + drm_framebuffer_remove(helper->fb); + } + + drm_fb_helper_fini(helper); +} diff --git a/drivers/gpu/drm/mediatek/mtk_drm_fbdev.h b/drivers/gpu/drm/mediatek/mtk_drm_fbdev.h new file mode 100644 index 0000000..f3e0949 --- /dev/null +++ b/drivers/gpu/drm/mediatek/mtk_drm_fbdev.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016 MediaTek Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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. + */ + +#ifndef MTK_DRM_FBDEV_H +#define MTK_DRM_FBDEV_H + +#ifdef CONFIG_DRM_FBDEV_EMULATION +int mtk_fbdev_init(struct drm_device *dev); +void mtk_fbdev_fini(struct drm_device *dev); +#else +int mtk_fbdev_init(struct drm_device *dev) +{ + return 0; +} + +void mtk_fbdev_fini(struct drm_device *dev) +{ + +} +#endif /* CONFIG_DRM_FBDEV_EMULATION */ + +#endif /* MTK_DRM_FBDEV_H */