From patchwork Tue Oct 17 06:47:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?U2hhd24gU3VuZyAo5a6L5a2d6KyZKQ==?= X-Patchwork-Id: 153937 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3941820vqb; Mon, 16 Oct 2023 23:48:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKjhNLcJRHQO6TFbHlFhxHLI4oR8zpSpLx8/Ta9GwSBxfQgKdlGCjfsv3uWNXCzYtyu3Yk X-Received: by 2002:a05:6870:6b9b:b0:1ea:7463:1b8f with SMTP id ms27-20020a0568706b9b00b001ea74631b8fmr1569394oab.0.1697525308206; Mon, 16 Oct 2023 23:48:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697525308; cv=none; d=google.com; s=arc-20160816; b=TafCAdUFt5XKohonhTtaj+c8WOavF/kdD+KXGQoHSgquelUVVcQrEG0lBEw3+9c+s+ 9TjG0VNgkF73O4mfQoYCQw0+uBqmqeF8Bjca9R8LPUu0+Yh3VBSFWYAk+MOzNrur2VnL NdLkrbWI5R25znkFS4U4pJa562hDFmWjwkD0D+b0/G4fC/aXSfQuw6Yc2hOZkVZid7l2 XtdA8pZ3cpJbRoJgqBV2Atm+SG4Op6j0uFS9UfLwVfXVYRtZA2/l9azkOkd+jTa+6M5x 0qnxXAk0UqA4WqFRKV53XRHctmG6Pu95B6ysi9Xq3KRZm6mobiwUzGf6/oH06fyS72Mp hYgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=C/hHtKyIgOB37NkGUiMEgmm5qd2W6DQwFbHNe1iREac=; fh=LsFoaGySu0ehlpBAbbjqTnZPNWvefanEoueL/ZpNhfU=; b=RHonOpELBn8Qdorz+pRchoGX+0YKuJNW7wGC0hgakmLKWn+y6+Zw/OBkYVKmnKU5rx iNYkQewJM3M8eVLh+V3b5Pk+eYOwb67VpvTt1RBfozLfz6Vh8id8B5CwmzGwMdT+saUH xmzfFt4lawGdJilxO1lB+OcYY171BJHLlnMKo1Qe9J3ofodXLmtH1gBflBkhf/fL8RiY SzMh8yFDu35SoNPDMGWhC4ve/C2xTB2qRxBKTTJEShaSdCNv7GpuZiN81WV+nms5Rg2T F+rhPxuRK7I9a6wAZjAGa2RM8nlBrDTuoVDomTGvHZhtGa7Fkf27N8oNKyz7TTv62BhH Av1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=PfZyWq7e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id s1-20020a635e01000000b005aa6c0aa22dsi1115118pgb.724.2023.10.16.23.48.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 23:48:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=PfZyWq7e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D4BA8803111C; Mon, 16 Oct 2023 23:48:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234684AbjJQGsO (ORCPT + 19 others); Tue, 17 Oct 2023 02:48:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234611AbjJQGro (ORCPT ); Tue, 17 Oct 2023 02:47:44 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F052BF9; Mon, 16 Oct 2023 23:47:37 -0700 (PDT) X-UUID: 058d57e66cb911ee8051498923ad61e6-20231017 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=C/hHtKyIgOB37NkGUiMEgmm5qd2W6DQwFbHNe1iREac=; b=PfZyWq7esZFaUp99sYpJcG+Q1eOxsnu0AmKC1S7sm3lY7zrbXdKTRhwvnetYtJvoqR1h7KgFFcVCMmfOPLaU7r0p+UKIaceSoRnoW1U46m5rM9KdyTCW2INO6mPWsqiyYmiami44AGisGVxqBjHblEE3YnPzwBzPl8TTm/yDo8o=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.32,REQID:698df349-33b6-4033-b149-092477cd461b,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:5f78ec9,CLOUDID:d9b905c0-14cc-44ca-b657-2d2783296e72,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR: NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-UUID: 058d57e66cb911ee8051498923ad61e6-20231017 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1080256243; Tue, 17 Oct 2023 14:47:21 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by MTKMBS14N1.mediatek.inc (172.21.101.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 17 Oct 2023 14:47:19 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 17 Oct 2023 14:47:19 +0800 From: Hsiao Chien Sung To: AngeloGioacchino Del Regno , Chun-Kuang Hu , Krzysztof Kozlowski , Matthias Brugger CC: Philipp Zabel , David Airlie , Daniel Vetter , Rob Herring , "Chen-Yu Tsai" , Sean Paul , , , , , , Singo Chang , Nancy Lin , Jason-JH Lin , Hsiao Chien Sung Subject: [PATCH v3 10/11] drm/mediatek: Support CRC in VDOSYS0 Date: Tue, 17 Oct 2023 14:47:16 +0800 Message-ID: <20231017064717.21616-11-shawn.sung@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20231017064717.21616-1-shawn.sung@mediatek.com> References: <20231017064717.21616-1-shawn.sung@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--11.669000-8.000000 X-TMASE-MatchedRID: HqqZ39pjvSi/gdQC9NfM37dQIb8hCnY+Xru95hSuhjTFHcwKL6UE/8CS 2AMm1nQC2xDStkOROV9uXpR8O0I9A+BX8Ypq0C8lj2FGM19l45eUNBZ1nwIVNEDIf3ubt7Y1BgH mCxujQvwZB0R4cFpbTeKOmN63egZIZ28ZQS4q9JwVglQa/gMvfHnUZqRb3abm1yGUyFK3oV4wKY tIU69m3cy2kfzaZ5ik5uxxxxIslOWeHTkwQi/s15fOGL7sa1Cy7f6JAS2hKPjjud2x7TPVtzFaT Rf5dTetI8xfD3DjNcUiiPRXRdfDOlsMw6s/MEEasQpfTaytNchl0qH7/7HRjkdmDSBYfnJRkOkX 3BpY1o8ULfbRmZ/onPVTqzK3F0T1Ig67HHizFeHKl4yJoI+fG47u1T4G/rnNmyiLZetSf8mfop0 ytGwvXiq2rl3dzGQ15mYVuB2ZklKG9CjyZTMuz61XIzjF142iao3lHPvMHGhaFJH3C2TwKg== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--11.669000-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 3F26785F73EF3C325E62D9D178492F318D77C9CEB3306B31B8122EC34AFADDCC2000:8 X-MTK: N X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 16 Oct 2023 23:48:24 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779984297653808689 X-GMAIL-MSGID: 1779984297653808689 We choose OVL as CRC generator from other hardware components that are also capable of calculating CRCs, since its frame done event triggers vblanks, it can be used as a signal to know when is safe to retrieve CRC of the frame. Please note that position of the hardware component that is chosen as CRC generator in the display path is significant. For example, while OVL is the first module in VDOSYS0, its CRC won't be affected by the modules after it, which means effects applied by PQ, Gamma, Dither or any other components after OVL won't be calculated in CRC generation. Signed-off-by: Hsiao Chien Sung --- drivers/gpu/drm/mediatek/mtk_disp_drv.h | 3 + drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 111 ++++++++++++++++++-- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 3 + 3 files changed, 109 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_disp_drv.h b/drivers/gpu/drm/mediatek/mtk_disp_drv.h index c44f5b31bab5..08cc2d2fef9f 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_drv.h +++ b/drivers/gpu/drm/mediatek/mtk_disp_drv.h @@ -102,6 +102,9 @@ void mtk_ovl_enable_vblank(struct device *dev); void mtk_ovl_disable_vblank(struct device *dev); const u32 *mtk_ovl_get_formats(struct device *dev); size_t mtk_ovl_get_num_formats(struct device *dev); +size_t mtk_ovl_crc_cnt(struct device *dev); +u32 *mtk_ovl_crc_entry(struct device *dev); +void mtk_ovl_crc_read(struct device *dev); void mtk_ovl_adaptor_add_comp(struct device *dev, struct mtk_mutex *mutex); void mtk_ovl_adaptor_remove_comp(struct device *dev, struct mtk_mutex *mutex); diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c index 75de1350e337..ecc38932fd44 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c @@ -25,6 +25,13 @@ #define OVL_FME_CPL_INT BIT(1) #define DISP_REG_OVL_INTSTA 0x0008 #define DISP_REG_OVL_EN 0x000c +#define OVL_EN BIT(0) +#define OVL_OP_8BIT_MODE BIT(4) +#define OVL_HG_FOVL_CK_ON BIT(8) +#define OVL_HF_FOVL_CK_ON BIT(10) +#define DISP_REG_OVL_TRIG 0x0010 +#define OVL_CRC_EN BIT(8) +#define OVL_CRC_CLR BIT(9) #define DISP_REG_OVL_RST 0x0014 #define DISP_REG_OVL_ROI_SIZE 0x0020 #define DISP_REG_OVL_DATAPATH_CON 0x0024 @@ -44,6 +51,8 @@ #define DISP_REG_OVL_RDMA_CTRL(n) (0x00c0 + 0x20 * (n)) #define DISP_REG_OVL_RDMA_GMC(n) (0x00c8 + 0x20 * (n)) #define DISP_REG_OVL_ADDR_MT2701 0x0040 +#define DISP_REG_OVL_CRC 0x0270 +#define OVL_CRC_OUT_MASK GENMASK(30, 0) #define DISP_REG_OVL_CLRFMT_EXT 0x02D0 #define DISP_REG_OVL_CLRFMT_EXT1 0x02D8 #define OVL_CLRFMT_EXT1_CSC_EN(n) (1 << (((n) * 4) + 1)) @@ -151,6 +160,24 @@ static const u32 mt8195_formats[] = { DRM_FORMAT_YUYV, }; +static const u32 mt8195_ovl_crc_ofs[] = { + DISP_REG_OVL_CRC, +}; + +/** + * struct mtk_disp_ovl_data - ovl driver data + * @addr: offset of the first layer (layer-0) + * @gmc_bits: gmc (gating memory clock) bit masks for adjusting positivity for ovl + * @layer_nr: layer numbers that ovl supports + * @fmt_rgb565_is_0: whether or not rgb565 is represented as 0 + * @smi_id_en: determine if smi needs to be enabled + * @supports_afbc: determine if ovl supports afbc + * @formats: format table that ovl supports + * @num_formats: number of formats that ovl supports + * @supports_clrfmt_ext: whether the ovl supports clear format (for alpha blend) + * @crc_ofs: crc offset table + * @crc_cnt: count of crc registers (could be more than one bank) + */ struct mtk_disp_ovl_data { unsigned int addr; unsigned int gmc_bits; @@ -161,12 +188,20 @@ struct mtk_disp_ovl_data { const u32 *formats; size_t num_formats; bool supports_clrfmt_ext; + const u32 *crc_ofs; + size_t crc_cnt; }; -/* +/** * struct mtk_disp_ovl - DISP_OVL driver structure * @crtc: associated crtc to report vblank events to + * @clk: clock of the ovl + * @regs: base address of the ovl register that can be accessed by cpu + * @cmdq_reg: register related info for cmdq (subsys, offset ...etc.) * @data: platform data + * @vblank_cb: callback function when vblank irq happened + * @vblank_cb_data: data to the callback function + * @crc: crc related information */ struct mtk_disp_ovl { struct drm_crtc *crtc; @@ -176,8 +211,30 @@ struct mtk_disp_ovl { const struct mtk_disp_ovl_data *data; void (*vblank_cb)(void *data); void *vblank_cb_data; + struct mtk_drm_crc crc; }; +size_t mtk_ovl_crc_cnt(struct device *dev) +{ + struct mtk_disp_ovl *ovl = dev_get_drvdata(dev); + + return ovl->crc.cnt; +} + +u32 *mtk_ovl_crc_entry(struct device *dev) +{ + struct mtk_disp_ovl *ovl = dev_get_drvdata(dev); + + return ovl->crc.va; +} + +void mtk_ovl_crc_read(struct device *dev) +{ + struct mtk_disp_ovl *ovl = dev_get_drvdata(dev); + + mtk_drm_crc_read(&ovl->crc, ovl->regs); +} + static irqreturn_t mtk_disp_ovl_irq_handler(int irq, void *dev_id) { struct mtk_disp_ovl *priv = dev_id; @@ -216,7 +273,7 @@ void mtk_ovl_enable_vblank(struct device *dev) struct mtk_disp_ovl *ovl = dev_get_drvdata(dev); writel(0x0, ovl->regs + DISP_REG_OVL_INTSTA); - writel_relaxed(OVL_FME_CPL_INT, ovl->regs + DISP_REG_OVL_INTEN); + writel(OVL_FME_CPL_INT, ovl->regs + DISP_REG_OVL_INTEN); } void mtk_ovl_disable_vblank(struct device *dev) @@ -269,14 +326,30 @@ void mtk_ovl_start(struct device *dev) */ reg |= OVL_OUTPUT_CLAMP; - writel_relaxed(reg, ovl->regs + DISP_REG_OVL_DATAPATH_CON); - writel_relaxed(0x1, ovl->regs + DISP_REG_OVL_EN); + writel(reg, ovl->regs + DISP_REG_OVL_DATAPATH_CON); + + reg = OVL_EN; + + if (ovl->data->crc_cnt) { + /* enable crc */ + writel(OVL_CRC_EN, ovl->regs + DISP_REG_OVL_TRIG); + /* enable crc related clocks */ + reg |= OVL_OP_8BIT_MODE | OVL_HG_FOVL_CK_ON | OVL_HF_FOVL_CK_ON; + } + writel(reg, ovl->regs + DISP_REG_OVL_EN); + +#if IS_REACHABLE(CONFIG_MTK_CMDQ) + mtk_drm_crc_cmdq_start(&ovl->crc); +#endif } void mtk_ovl_stop(struct device *dev) { struct mtk_disp_ovl *ovl = dev_get_drvdata(dev); +#if IS_REACHABLE(CONFIG_MTK_CMDQ) + mtk_drm_crc_cmdq_stop(&ovl->crc); +#endif writel_relaxed(0x0, ovl->regs + DISP_REG_OVL_EN); if (ovl->data->smi_id_en) { unsigned int reg; @@ -689,15 +762,31 @@ static int mtk_disp_ovl_probe(struct platform_device *pdev) dev_err(dev, "failed to ioremap ovl\n"); return PTR_ERR(priv->regs); } + + priv->data = of_device_get_match_data(dev); + platform_set_drvdata(pdev, priv); + + if (priv->data->crc_cnt) { + mtk_drm_crc_init(&priv->crc, + priv->data->crc_ofs, priv->data->crc_cnt, + DISP_REG_OVL_TRIG, OVL_CRC_CLR); + } + #if IS_REACHABLE(CONFIG_MTK_CMDQ) ret = cmdq_dev_get_client_reg(dev, &priv->cmdq_reg, 0); if (ret) dev_dbg(dev, "get mediatek,gce-client-reg fail!\n"); -#endif - - priv->data = of_device_get_match_data(dev); - platform_set_drvdata(pdev, priv); + if (priv->data->crc_cnt) { + if (of_property_read_u32_index(dev->of_node, + "mediatek,gce-events", 0, + &priv->crc.cmdq_event)) { + dev_warn(dev, "failed to get gce-events for crc\n"); + } + priv->crc.cmdq_reg = &priv->cmdq_reg; + mtk_drm_crc_cmdq_create(dev, &priv->crc); + } +#endif ret = devm_request_irq(dev, irq, mtk_disp_ovl_irq_handler, IRQF_TRIGGER_NONE, dev_name(dev), priv); if (ret < 0) { @@ -718,6 +807,10 @@ static int mtk_disp_ovl_probe(struct platform_device *pdev) static void mtk_disp_ovl_remove(struct platform_device *pdev) { + struct device *dev = &pdev->dev; + struct mtk_disp_ovl *ovl = dev_get_drvdata(dev); + + mtk_drm_crc_destroy(&ovl->crc); component_del(&pdev->dev, &mtk_disp_ovl_component_ops); pm_runtime_disable(&pdev->dev); } @@ -788,6 +881,8 @@ static const struct mtk_disp_ovl_data mt8195_ovl_driver_data = { .formats = mt8195_formats, .num_formats = ARRAY_SIZE(mt8195_formats), .supports_clrfmt_ext = true, + .crc_ofs = mt8195_ovl_crc_ofs, + .crc_cnt = ARRAY_SIZE(mt8195_ovl_crc_ofs), }; static const struct of_device_id mtk_disp_ovl_driver_dt_match[] = { diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c index 9940909c7435..1118efcde98a 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c @@ -349,6 +349,9 @@ static const struct mtk_ddp_comp_funcs ddp_ovl = { .clk_enable = mtk_ovl_clk_enable, .clk_disable = mtk_ovl_clk_disable, .config = mtk_ovl_config, + .crc_cnt = mtk_ovl_crc_cnt, + .crc_entry = mtk_ovl_crc_entry, + .crc_read = mtk_ovl_crc_read, .start = mtk_ovl_start, .stop = mtk_ovl_stop, .register_vblank_cb = mtk_ovl_register_vblank_cb,