From nobody Thu Nov 14 04:50:32 2024 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B85BC45970 for ; Thu, 4 Apr 2024 07:58:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712217482; cv=none; b=XxtHmw9daQYDGU+ifTpR1shhNVgMeUxqXgph/Yx8cuk+H3PL7awD2OPjkkR4V7auhU2j/hi9jFll6fDWrgI34lIyBDUMZ9NKzyF2o1prCLK+5c0BgxccGzSC6/DHoEOqdINC7Fp3F/6lFlL91WPRbE0gXg4gRxJyn7vfTYmyDIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712217482; c=relaxed/simple; bh=3XsaGUfHbyKfT+rCEWbrx+o2Wnvb76/WaYQW9y+coRI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qAu2neUdWapmD+QHctNbmuorpkC0JXuvVwW3Qo/xWTIyiDCDU+ktZ/gGrYO380jO5VYlXSf6NsTCN3HPw46lPe0h404LgjJM+u/3JW/6TYO/yVrQU2k9nsshRzxqKV/ifIqwlszlgmlwt1TuzmNvIjWv2XglHkZQHsK+0SMO4uI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=tRqKoJZl; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="tRqKoJZl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1712217478; bh=3XsaGUfHbyKfT+rCEWbrx+o2Wnvb76/WaYQW9y+coRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tRqKoJZlIxZCuMghnJ/64FPr6v7Kq9trDuOiSl5+ST70yRVIqMOpQUzo9rk1ytADO Mc6efyeeN63rIgSnWFjRK1W1DSVy9Ig9fRjhOjrHYTvcMxSjREfg1lPEuSvHe/X8e/ vzIH9xzDCr/w5WDlqqNz+glf5Qh3hnmlwchOOAD5uXpcPQzl5Nr3wVyPYDKxMCsKRT AchEv+JZn5F3BcPZvSurhFjyx7czK21qlkLK02/oLqQee9B0ev9sutFvTb98cJcmKU /UqavQB0ohBcigEXOodwim/BkqpbA4zpUmV/3+QH9qg+TT1yXYPMA9AhPxeBy8707B X1DO/Jfq7b5Qg== Received: from IcarusMOD.eternityproject.eu (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madrid.collaboradmins.com (Postfix) with ESMTPSA id F3D663782128; Thu, 4 Apr 2024 07:57:57 +0000 (UTC) From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Cc: p.zabel@pengutronix.de, airlied@gmail.com, daniel@ffwll.ch, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, ck.hu@mediatek.com, nancy.lin@mediatek.com, nathan.lu@mediatek.com, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@collabora.com, wenst@chromium.org Subject: [PATCH v2 1/3] drm/mediatek: drm_ddp_comp: Fix and cleanup DDP component CRTC search Date: Thu, 4 Apr 2024 09:57:52 +0200 Message-ID: <20240404075754.83455-2-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240404075754.83455-1-angelogioacchino.delregno@collabora.com> References: <20240404075754.83455-1-angelogioacchino.delregno@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Finding a possible CRTC by DDP component is done by first checking static routes in three paths (main, external, third/extra path) and then, if not found, we check for dynamic connection on a per-route basis because, for example, on some SoCs the main route may output to either a DSI display or DisplayPort and this is finally done by assigning a CRTC mask to `possible_crtcs`, found with function mtk_drm_find_comp_in_ddp_conn_path(): being that a mask the possible values are BIT(x) and, if no CRTC is possible, zero. Problem is, both mtk_drm_find_possible_crtc_by_comp() and the aforementioned function are trying to return a negative error value (but it's unsigned int, so the value is never negative!) if no CRTC was found, which is wrong for multiple obvious reasons. Cleanup both functions, so that: - mtk_drm_find_comp_in_ddp_conn_path() returns a signed integer with a negative number for error, or a bit/bitmask of the found possible CRTC; and - mtk_drm_find_possible_crtc_by_comp() always returns either a bitmask of the possible CRTC, or zero if none available. Fixes: 01389b324c97 ("drm/mediatek: Add connector dynamic selection capabil= ity") Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 44 ++++++++++----------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/= mediatek/mtk_drm_ddp_comp.c index a515e96cfefc..82d7a6887f44 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c @@ -514,29 +514,25 @@ static bool mtk_drm_find_comp_in_ddp(struct device *d= ev, return false; } =20 -static unsigned int mtk_drm_find_comp_in_ddp_conn_path(struct device *dev, - const struct mtk_drm_route *routes, - unsigned int num_routes, - struct mtk_ddp_comp *ddp_comp) +static int mtk_drm_find_comp_in_ddp_conn_path(struct device *dev, + const struct mtk_drm_route *routes, + unsigned int num_routes, + struct mtk_ddp_comp *ddp_comp) { - int ret; - unsigned int i; + int i; =20 - if (!routes) { - ret =3D -EINVAL; - goto err; + if (!routes || !num_routes) { + DRM_ERROR("No connection routes specified!\n"); + return -EINVAL; } =20 for (i =3D 0; i < num_routes; i++) if (dev =3D=3D ddp_comp[routes[i].route_ddp].dev) return BIT(routes[i].crtc_id); =20 - ret =3D -ENODEV; -err: - - DRM_INFO("Failed to find comp in ddp table, ret =3D %d\n", ret); + DRM_ERROR("Failed to find component in ddp table\n"); =20 - return 0; + return -ENODEV; } =20 int mtk_ddp_comp_get_id(struct device_node *node, @@ -558,22 +554,24 @@ unsigned int mtk_drm_find_possible_crtc_by_comp(struc= t drm_device *drm, struct device *dev) { struct mtk_drm_private *private =3D drm->dev_private; - unsigned int ret =3D 0; + int ret; =20 if (mtk_drm_find_comp_in_ddp(dev, private->data->main_path, private->data= ->main_len, private->ddp_comp)) - ret =3D BIT(0); + return BIT(0); else if (mtk_drm_find_comp_in_ddp(dev, private->data->ext_path, private->data->ext_len, private->ddp_comp)) - ret =3D BIT(1); + return BIT(1); else if (mtk_drm_find_comp_in_ddp(dev, private->data->third_path, private->data->third_len, private->ddp_comp)) - ret =3D BIT(2); - else - ret =3D mtk_drm_find_comp_in_ddp_conn_path(dev, - private->data->conn_routes, - private->data->num_conn_routes, - private->ddp_comp); + return BIT(2); + + ret =3D mtk_drm_find_comp_in_ddp_conn_path(dev, private->data->conn_route= s, + private->data->num_conn_routes, + private->ddp_comp); + /* No CRTC is available: return a zero mask */ + if (ret < 0) + return 0; =20 return ret; } --=20 2.44.0 From nobody Thu Nov 14 04:50:32 2024 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD7695D724 for ; Thu, 4 Apr 2024 07:58:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712217483; cv=none; b=qZ8lJPn5DEbBJw8XlaQr4SU5aFiqWHo+UFUlOjX566KqE5s03CFf8x1VryBQejtVMdo/RY+ATXbycpJYByi2uiF8CGWXac/vtOgJZ0eUitrks3PMebjPpwPBGFIiPGhkFr0eCs0qAQf5tJcPloS+fCmTe/yAr7QKffsir70v+O8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712217483; c=relaxed/simple; bh=KoiSh/u/4BD9iAcBgjvWczlcgOlHoosLFr6MB3Jm8Xs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZJY3Xx0Q+IbPs4opU9rovmm7n2zGnvKLgpST/povSj1XBoPNL0xKpftx2OjzHk9ZBGTJQ2EXlDD9Fm3fYPGlqcAjx7dQjWhhauB25zNQvMxZM/yEPF//yElVOz5DTyOV1hK3eWLwsZrJsyDgFFBKRLkfL8TQ4hD0eVRBNV7dxHo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=FOu5bJCt; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="FOu5bJCt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1712217480; bh=KoiSh/u/4BD9iAcBgjvWczlcgOlHoosLFr6MB3Jm8Xs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FOu5bJCtAyMzxdyr8jDNAhgQn9IKDDnH1uRykOEPX0qZKiHPoXewXk1vwIpt4S0eT Ympln2QU6MvpjNaVYVOcQ/nxpubzcFM8tpC33KfydDSK9znFhR741BEflS3SmDfl5S uZGcPPN8Oiw7kqmWiHOKGcnxUTMP3M/XWvmqRFGcZAAimGst9OqB3r9evoLeiyPFLr dCkcs7u8HUMprfS3Lfe9qJgR+0tqg5yqdp+N3DlWzVRqkFMndK1ItMWp5bHMIOrNf3 F9seAaunCjMunY7GLDEm6ytNHZp/8ABpu0aHiAKrCZ33ynRTjoTo6GNWhBuiuUp0M6 xUponJyRAtm1A== Received: from IcarusMOD.eternityproject.eu (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 15D003782129; Thu, 4 Apr 2024 07:57:59 +0000 (UTC) From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Cc: p.zabel@pengutronix.de, airlied@gmail.com, daniel@ffwll.ch, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, ck.hu@mediatek.com, nancy.lin@mediatek.com, nathan.lu@mediatek.com, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@collabora.com, wenst@chromium.org Subject: [PATCH v2 2/3] drm/mediatek: Perform iounmap on simple DDP component destruction Date: Thu, 4 Apr 2024 09:57:53 +0200 Message-ID: <20240404075754.83455-3-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240404075754.83455-1-angelogioacchino.delregno@collabora.com> References: <20240404075754.83455-1-angelogioacchino.delregno@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a new mtk_ddp_comp_destroy() function and call it in the teardown path of mtk_drm_drv to make sure that we unmap the iospace of the simple DDP components. While at it, also fix iounmapping on mtk_ddp_comp_init() error path. Fixes: ff1395609e20 ("drm/mediatek: Move mtk_ddp_comp_init() from sub drive= r to DRM driver") Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: CK Hu --- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 38 ++++++++++++++++++++- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 1 + drivers/gpu/drm/mediatek/mtk_drm_drv.c | 4 ++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/= mediatek/mtk_drm_ddp_comp.c index 82d7a6887f44..477fc1950a0e 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c @@ -627,8 +627,11 @@ int mtk_ddp_comp_init(struct device_node *node, struct= mtk_ddp_comp *comp, =20 priv->regs =3D of_iomap(node, 0); priv->clk =3D of_clk_get(node, 0); - if (IS_ERR(priv->clk)) + if (IS_ERR(priv->clk)) { + iounmap(priv->regs); + priv->regs =3D NULL; return PTR_ERR(priv->clk); + } =20 #if IS_REACHABLE(CONFIG_MTK_CMDQ) ret =3D cmdq_dev_get_client_reg(comp->dev, &priv->cmdq_reg, 0); @@ -640,3 +643,36 @@ int mtk_ddp_comp_init(struct device_node *node, struct= mtk_ddp_comp *comp, =20 return 0; } + +void mtk_ddp_comp_destroy(struct mtk_ddp_comp *comp) +{ + struct mtk_ddp_comp_dev *priv; + + if (!comp || !comp->dev) + return; + + /* Complex components are destroyed with their own remove callback */ + if (mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_AAL || + mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_BLS || + mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_CCORR || + mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_COLOR || + mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_GAMMA || + mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_MERGE || + mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_OVL || + mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_OVL_2L || + mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_PWM || + mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_RDMA || + mtk_ddp_matches[comp->id].type =3D=3D MTK_DPI || + mtk_ddp_matches[comp->id].type =3D=3D MTK_DP_INTF || + mtk_ddp_matches[comp->id].type =3D=3D MTK_DSI) + return; + + priv =3D dev_get_drvdata(comp->dev); + if (!priv) + return; + + if (priv->regs) { + iounmap(priv->regs); + priv->regs =3D NULL; + } +} diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h b/drivers/gpu/drm/= mediatek/mtk_drm_ddp_comp.h index 93d79a1366e9..3d147217caa4 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h @@ -330,6 +330,7 @@ unsigned int mtk_drm_find_possible_crtc_by_comp(struct = drm_device *drm, struct device *dev); int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *= comp, unsigned int comp_id); +void mtk_ddp_comp_destroy(struct mtk_ddp_comp *comp); enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id); void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value, struct cmdq_client_reg *cmdq_reg, void __iomem *regs, diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/media= tek/mtk_drm_drv.c index 74832c213092..7e240d16d3e5 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c @@ -946,8 +946,10 @@ static void mtk_drm_remove(struct platform_device *pde= v) component_master_del(&pdev->dev, &mtk_drm_ops); pm_runtime_disable(&pdev->dev); of_node_put(private->mutex_node); - for (i =3D 0; i < DDP_COMPONENT_DRM_ID_MAX; i++) + for (i =3D 0; i < DDP_COMPONENT_DRM_ID_MAX; i++) { + mtk_ddp_comp_destroy(&private->ddp_comp[i]); of_node_put(private->comp_node[i]); + } } =20 static int mtk_drm_sys_prepare(struct device *dev) --=20 2.44.0 From nobody Thu Nov 14 04:50:32 2024 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEDC95E07E for ; Thu, 4 Apr 2024 07:58:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712217484; cv=none; b=Ycj2GryP5gRSo0XCGVKZU6BsyLwby9iRMgFW8Rp9iPEcVtG5bbPiZEyxsjApuBYtOOOSTLclxRJC4JqOEHRfTsN4ZnWJU170MY++FfEwdwGGSxjkBMaHD7r+roDoahP3Zk3bTX0cLCQf73at7hheOXQMaBRPBVbKpmUsAX2/Tzs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712217484; c=relaxed/simple; bh=91LD58avnRzxuTR+zgR6nRtCYpKIsz1H4g5/SZOkKwg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EJIpqZEjxSTqPFhl5Z5+1Nea/QN5BNaW77UXNJNjgHnqtAMRie4cv7BP6a5xHPgqCqDUI5th75PN4JLJfn+UYy2V7FM6e83T3q7YP0nWgEDeTBU8IGwPkHBzWvouBWvSwsbPo9OTwMLJde4Z17Zr9Kk5j5u7Ur3mVzRDJCRGLxU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=0d8LCh7C; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="0d8LCh7C" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1712217481; bh=91LD58avnRzxuTR+zgR6nRtCYpKIsz1H4g5/SZOkKwg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0d8LCh7CqmqBKxae4zvzP7kHfKBt66Je/wOdytq86ZfN/ZU+QYUjnG9uBCm9DaedO 2/ryyht8UR5L779RenbBXb/U4nhu4mQ4gj2xaUcmBAhaccXIH1XnblbNc11z4cpA/E CH4G+CcCtI55wdVim+Ao9rLEzG+3AQxloITitp5437x1av6QPW+Yw/thp+7u0n4vyO QkFmOXCJy0k/DuxaLTsOHFpILB1Ei5bwxXFod40AcybdjGXbsU18iGnt9/trJjnaO3 BX31mPHMjR6JIqwIDmWJ2eUrHGaBBvdslslPpdnEUpN8LfI1ajeJsOErsEW9Y1UtmV UvwNLgh9o2qGw== Received: from IcarusMOD.eternityproject.eu (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 2ACF3378212E; Thu, 4 Apr 2024 07:58:00 +0000 (UTC) From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Cc: p.zabel@pengutronix.de, airlied@gmail.com, daniel@ffwll.ch, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, ck.hu@mediatek.com, nancy.lin@mediatek.com, nathan.lu@mediatek.com, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@collabora.com, wenst@chromium.org Subject: [PATCH v2 3/3] drm/mediatek: drm_ddp_comp: Add mtk_ddp_is_simple_comp() internal helper Date: Thu, 4 Apr 2024 09:57:54 +0200 Message-ID: <20240404075754.83455-4-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240404075754.83455-1-angelogioacchino.delregno@collabora.com> References: <20240404075754.83455-1-angelogioacchino.delregno@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the simple component check to a new mtk_ddp_is_simple_comp() internal helper to reduce code duplication. Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: CK Hu --- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 57 +++++++++++---------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/= mediatek/mtk_drm_ddp_comp.c index 477fc1950a0e..d760285761b9 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c @@ -576,6 +576,29 @@ unsigned int mtk_drm_find_possible_crtc_by_comp(struct= drm_device *drm, return ret; } =20 +static bool mtk_ddp_is_simple_comp(enum mtk_ddp_comp_type type) +{ + switch (type) { + case MTK_DISP_AAL: + case MTK_DISP_BLS: + case MTK_DISP_CCORR: + case MTK_DISP_COLOR: + case MTK_DISP_GAMMA: + case MTK_DISP_MERGE: + case MTK_DISP_OVL: + case MTK_DISP_OVL_2L: + case MTK_DISP_OVL_ADAPTOR: + case MTK_DISP_PWM: + case MTK_DISP_RDMA: + case MTK_DP_INTF: + case MTK_DPI: + case MTK_DSI: + return false; + default: + return true; + } +} + int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp, unsigned int comp_id) { @@ -606,19 +629,13 @@ int mtk_ddp_comp_init(struct device_node *node, struc= t mtk_ddp_comp *comp, } comp->dev =3D &comp_pdev->dev; =20 - if (type =3D=3D MTK_DISP_AAL || - type =3D=3D MTK_DISP_BLS || - type =3D=3D MTK_DISP_CCORR || - type =3D=3D MTK_DISP_COLOR || - type =3D=3D MTK_DISP_GAMMA || - type =3D=3D MTK_DISP_MERGE || - type =3D=3D MTK_DISP_OVL || - type =3D=3D MTK_DISP_OVL_2L || - type =3D=3D MTK_DISP_PWM || - type =3D=3D MTK_DISP_RDMA || - type =3D=3D MTK_DPI || - type =3D=3D MTK_DP_INTF || - type =3D=3D MTK_DSI) + /* + * Resources for simple components are retrieved here as those are + * managed in here without the need of more complex drivers; for + * the latter, their respective probe function will do the job, so + * we must avoid getting their resources here. + */ + if (!mtk_ddp_is_simple_comp(type)) return 0; =20 priv =3D devm_kzalloc(comp->dev, sizeof(*priv), GFP_KERNEL); @@ -652,19 +669,7 @@ void mtk_ddp_comp_destroy(struct mtk_ddp_comp *comp) return; =20 /* Complex components are destroyed with their own remove callback */ - if (mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_AAL || - mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_BLS || - mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_CCORR || - mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_COLOR || - mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_GAMMA || - mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_MERGE || - mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_OVL || - mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_OVL_2L || - mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_PWM || - mtk_ddp_matches[comp->id].type =3D=3D MTK_DISP_RDMA || - mtk_ddp_matches[comp->id].type =3D=3D MTK_DPI || - mtk_ddp_matches[comp->id].type =3D=3D MTK_DP_INTF || - mtk_ddp_matches[comp->id].type =3D=3D MTK_DSI) + if (!mtk_ddp_is_simple_comp(mtk_ddp_matches[comp->id].type)) return; =20 priv =3D dev_get_drvdata(comp->dev); --=20 2.44.0