From patchwork Sun Apr 16 12:08:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Icenowy Zheng X-Patchwork-Id: 9683955 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 3A957602C2 for ; Mon, 17 Apr 2017 16:53:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A97425EF7 for ; Mon, 17 Apr 2017 16:53:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EF2C26B39; Mon, 17 Apr 2017 16:53:17 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable 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 4A6D225EF7 for ; Mon, 17 Apr 2017 16:53:16 +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=Rz6d0oLgZSnuT8zrFsIKOLJ9nptC61VLmgKlfB5KslI=; b=g+UgwIwYMUe1UCcIwll8D6PYRk f0H3LmYmzpq3+09g+aa1KZjaTJCTpT8ltGeOrfVj5Q2f6JUMl1maVlZM/3AGOm9zS7J50eNqlGsxA quYLKyQOcPIZq2a+kdQYu41G5MsGUcj6776seY4JPID+ZMOikIrE5vdUPlfvxl3V1IlASJzN6xtj2 xQRqlhLLgnUF8GlwjcIFyx7cYpax8V4XE4eJ47Tzu1y+TJ/VEaiy/8Dz1bHvqPGUWajPLvsfydrIA 2+0Ivl7MdO4EAqmnK+Fi13V4vPBiGrdsJKlx+DFVQvIgudkIamOZSyteVH84vtXC/N2dVopRmXWSO SkyhtxUg==; 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 1d09tr-00068U-Hw; Mon, 17 Apr 2017 16:53:15 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d09tY-0005dc-0Q for linux-arm-kernel@bombadil.infradead.org; Mon, 17 Apr 2017 16:52:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=lIo1qRt/cdJXHzTXSEgogs+O2TBtr6Ash6OURS0npRA=; b=vE0WulAduf14atzskdU7OucH4 UmP1GcsuB09o+N7JUb1nWVeNpR2lW0Ff77GhX1vCbDPZt1/ephGtDudukSWyiDH83j1ZT173rexUT uyvDyujaF2FCmscTzO4DE7doCSPipiQtiN15yiI9vdHRL6v25MlMbaMU9fHB3vUksHuLjW2/Jsq8Y tIZzrk2KfImYPjFLVHBPFaJPR+GtEjMlVSHWWjtKj8wRFL270REBb1SGua/N+TVojQVnFo27nIqge kRPb6p98efpohVIlINBnzY3UXNAOaeCiYcTogOwmXBpbeI19xIpaFpDJSDNU5/e5Jq/CbAKGPL+aN sMSTszE0w==; Received: from dragonfly.birch.relay.mailchannels.net ([23.83.209.51]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1czj1F-0001UU-Rt for linux-arm-kernel@lists.infradead.org; Sun, 16 Apr 2017 12:12:06 +0000 X-Sender-Id: lmn-tzduiowcrqmw|x-authsender|icenowy@aosc.io Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 96185203008; Sun, 16 Apr 2017 12:10:33 +0000 (UTC) Received: from hermes.aosc.io (unknown [100.96.129.119]) by relay.mailchannels.net (Postfix) with ESMTPA id 75E78203C59; Sun, 16 Apr 2017 12:10:32 +0000 (UTC) X-Sender-Id: lmn-tzduiowcrqmw|x-authsender|icenowy@aosc.io Received: from hermes.aosc.io (hermes.aosc.io [172.20.107.195]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.7.37); Sun, 16 Apr 2017 12:10:33 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: lmn-tzduiowcrqmw|x-authsender|icenowy@aosc.io X-MailChannels-Auth-Id: lmn-TZDUIOWCRQMW X-Oafish-Squirrel: 6f8c2c4033cdc04d_1492344633447_4282434478 X-MC-Loop-Signature: 1492344633447:788075881 X-MC-Ingress-Time: 1492344633447 Received: from localhost (localhost [127.0.0.1]) (Authenticated sender: icenowy@aosc.io) by hermes.aosc.io (Postfix) with ESMTPSA id DFCF846C75; Sun, 16 Apr 2017 12:10:23 +0000 (UTC) From: Icenowy Zheng To: Rob Herring , Maxime Ripard , Chen-Yu Tsai , David Airlie , Jernej Skrabec Subject: [PATCH v4 05/11] drm/sun4i: abstract a engine type Date: Sun, 16 Apr 2017 20:08:43 +0800 Message-Id: <20170416120849.54542-6-icenowy@aosc.io> In-Reply-To: <20170416120849.54542-1-icenowy@aosc.io> References: <20170416120849.54542-1-icenowy@aosc.io> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170416_131112_570229_03A72BE6 X-CRM114-Status: GOOD ( 29.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-sunxi@googlegroups.com, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Icenowy Zheng MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP As we are going to add support for the Allwinner DE2 engine in sun4i-drm driver, we will finally have two types of display engines -- the DE1 backend and the DE2 mixer. They both do some display blending and feed graphics data to TCON, so I choose to call them both "engine" here. Abstract the engine type to void * and a ops struct, which contains functions that should be called outside the engine-specified code (in TCON, CRTC or TV Encoder code). A dedicated Kconfig option is also added to control whether sun4i-backend-specified code (sun4i_backend.c and sun4i_layer.c) should be built. As we removed the codes in CRTC code that directly call the layer code, we can now extract the layer part and combine it with the backend part into a new module, sun4i-backend.ko. Signed-off-by: Icenowy Zheng --- Changes in v4: - Comments to tag the color correction functions as optional. - Check before calling the optional functions. - Change layers_init to satisfy new PATCH v4 04/11. drivers/gpu/drm/sun4i/Kconfig | 10 ++++++++++ drivers/gpu/drm/sun4i/Makefile | 6 ++++-- drivers/gpu/drm/sun4i/sun4i_backend.c | 26 +++++++++++++++++++------- drivers/gpu/drm/sun4i/sun4i_backend.h | 5 ----- drivers/gpu/drm/sun4i/sun4i_crtc.c | 14 +++++++------- drivers/gpu/drm/sun4i/sun4i_crtc.h | 7 ++++--- drivers/gpu/drm/sun4i/sun4i_drv.h | 3 ++- drivers/gpu/drm/sun4i/sun4i_layer.c | 2 +- drivers/gpu/drm/sun4i/sun4i_layer.h | 3 ++- drivers/gpu/drm/sun4i/sun4i_tcon.c | 2 +- drivers/gpu/drm/sun4i/sun4i_tv.c | 11 ++++++----- drivers/gpu/drm/sun4i/sunxi_engine.h | 35 +++++++++++++++++++++++++++++++++++ 12 files changed, 91 insertions(+), 33 deletions(-) create mode 100644 drivers/gpu/drm/sun4i/sunxi_engine.h diff --git a/drivers/gpu/drm/sun4i/Kconfig b/drivers/gpu/drm/sun4i/Kconfig index a4b357db8856..5a8227f37cc4 100644 --- a/drivers/gpu/drm/sun4i/Kconfig +++ b/drivers/gpu/drm/sun4i/Kconfig @@ -12,3 +12,13 @@ config DRM_SUN4I Choose this option if you have an Allwinner SoC with a Display Engine. If M is selected the module will be called sun4i-drm. + +config DRM_SUN4I_BACKEND + tristate "Support for Allwinner A10 Display Engine Backend" + depends on DRM_SUN4I + default DRM_SUN4I + help + Choose this option if you have an Allwinner SoC with the + original Allwinner Display Engine, which has a backend to + do some alpha blending and feed graphics to TCON. If M is + selected the module will be called sun4i-backend. diff --git a/drivers/gpu/drm/sun4i/Makefile b/drivers/gpu/drm/sun4i/Makefile index 59b757350a1f..1db1068b9be1 100644 --- a/drivers/gpu/drm/sun4i/Makefile +++ b/drivers/gpu/drm/sun4i/Makefile @@ -5,9 +5,11 @@ sun4i-tcon-y += sun4i_tcon.o sun4i-tcon-y += sun4i_rgb.o sun4i-tcon-y += sun4i_dotclock.o sun4i-tcon-y += sun4i_crtc.o -sun4i-tcon-y += sun4i_layer.o + +sun4i-backend-y += sun4i_layer.o +sun4i-backend-y += sun4i_backend.o obj-$(CONFIG_DRM_SUN4I) += sun4i-drm.o sun4i-tcon.o -obj-$(CONFIG_DRM_SUN4I) += sun4i_backend.o +obj-$(CONFIG_DRM_SUN4I_BACKEND) += sun4i-backend.o obj-$(CONFIG_DRM_SUN4I) += sun6i_drc.o obj-$(CONFIG_DRM_SUN4I) += sun4i_tv.o diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c b/drivers/gpu/drm/sun4i/sun4i_backend.c index d660741ba475..a16c96a002a4 100644 --- a/drivers/gpu/drm/sun4i/sun4i_backend.c +++ b/drivers/gpu/drm/sun4i/sun4i_backend.c @@ -23,6 +23,8 @@ #include "sun4i_backend.h" #include "sun4i_drv.h" +#include "sun4i_layer.h" +#include "sunxi_engine.h" static const u32 sunxi_rgb2yuv_coef[12] = { 0x00000107, 0x00000204, 0x00000064, 0x00000108, @@ -30,9 +32,10 @@ static const u32 sunxi_rgb2yuv_coef[12] = { 0x000001c1, 0x00003e88, 0x00003fb8, 0x00000808 }; -void sun4i_backend_apply_color_correction(struct sun4i_backend *backend) +static void sun4i_backend_apply_color_correction(void *engine) { int i; + struct sun4i_backend *backend = engine; DRM_DEBUG_DRIVER("Applying RGB to YUV color correction\n"); @@ -44,27 +47,28 @@ void sun4i_backend_apply_color_correction(struct sun4i_backend *backend) regmap_write(backend->regs, SUN4I_BACKEND_OCRCOEF_REG(i), sunxi_rgb2yuv_coef[i]); } -EXPORT_SYMBOL(sun4i_backend_apply_color_correction); -void sun4i_backend_disable_color_correction(struct sun4i_backend *backend) +static void sun4i_backend_disable_color_correction(void *engine) { + struct sun4i_backend *backend = engine; + DRM_DEBUG_DRIVER("Disabling color correction\n"); /* Disable color correction */ regmap_update_bits(backend->regs, SUN4I_BACKEND_OCCTL_REG, SUN4I_BACKEND_OCCTL_ENABLE, 0); } -EXPORT_SYMBOL(sun4i_backend_disable_color_correction); -void sun4i_backend_commit(struct sun4i_backend *backend) +static void sun4i_backend_commit(void *engine) { + struct sun4i_backend *backend = engine; + DRM_DEBUG_DRIVER("Committing changes\n"); regmap_write(backend->regs, SUN4I_BACKEND_REGBUFFCTL_REG, SUN4I_BACKEND_REGBUFFCTL_AUTOLOAD_DIS | SUN4I_BACKEND_REGBUFFCTL_LOADCTL); } -EXPORT_SYMBOL(sun4i_backend_commit); void sun4i_backend_layer_enable(struct sun4i_backend *backend, int layer, bool enable) @@ -288,6 +292,13 @@ static int sun4i_backend_free_sat(struct device *dev) { return 0; } +static const struct sunxi_engine_ops sun4i_backend_engine_ops = { + .commit = sun4i_backend_commit, + .layers_init = sun4i_layers_init, + .apply_color_correction = sun4i_backend_apply_color_correction, + .disable_color_correction = sun4i_backend_disable_color_correction, +}; + static struct regmap_config sun4i_backend_regmap_config = { .reg_bits = 32, .val_bits = 32, @@ -310,7 +321,8 @@ static int sun4i_backend_bind(struct device *dev, struct device *master, if (!backend) return -ENOMEM; dev_set_drvdata(dev, backend); - drv->backend = backend; + drv->engine = backend; + drv->engine_ops = &sun4i_backend_engine_ops; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); regs = devm_ioremap_resource(dev, res); diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.h b/drivers/gpu/drm/sun4i/sun4i_backend.h index 83e63cc702b4..65ef521de7d2 100644 --- a/drivers/gpu/drm/sun4i/sun4i_backend.h +++ b/drivers/gpu/drm/sun4i/sun4i_backend.h @@ -151,11 +151,6 @@ struct sun4i_backend { struct reset_control *sat_reset; }; -void sun4i_backend_apply_color_correction(struct sun4i_backend *backend); -void sun4i_backend_disable_color_correction(struct sun4i_backend *backend); - -void sun4i_backend_commit(struct sun4i_backend *backend); - void sun4i_backend_layer_enable(struct sun4i_backend *backend, int layer, bool enable); int sun4i_backend_update_layer_coord(struct sun4i_backend *backend, diff --git a/drivers/gpu/drm/sun4i/sun4i_crtc.c b/drivers/gpu/drm/sun4i/sun4i_crtc.c index 708b3543d4e9..942428bee4f0 100644 --- a/drivers/gpu/drm/sun4i/sun4i_crtc.c +++ b/drivers/gpu/drm/sun4i/sun4i_crtc.c @@ -25,10 +25,9 @@ #include