From patchwork Tue Dec 17 15:43:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 13912052 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CC6E8E77187 for ; Tue, 17 Dec 2024 15:44:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EF3A710EA05; Tue, 17 Dec 2024 15:44:38 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="Q9XXjkMh"; dkim-atps=neutral Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id DE0FD10E9EF for ; Tue, 17 Dec 2024 15:44:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1734450269; bh=bnjmOBi//RTidCVEyibDlK+PfzzVLK3Nk4xJn62Ei1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q9XXjkMhiHw3e1faduPavLk7tfdLGncnFpWf5hwynyeIxFAIWUfRqwY9iKFYaZwNp 6YLYyP1h2JWU20mEUfGOU3gxYpTx42krlOZ4te4GXQsZvNysTUpay+kpXkRqYiIu2A +74bimrQf8K9r7rYSgIfyu9+/QZDdCfQSmqg3Pvucr0GnsWJTk2c5v8XdNo1JxU9Yz uRn5ZvjBxbwiwTlDBH9bSLvWHg0TeYN2SMtiNFFC2OUyfEOmOzxFdq8tA2dWOErH1P FuHR2Yc5YYR89oyZm/VvyxvgzkGSu3QQ9xYw6+HVGNwX1X4eMEEy8ADpd5h+3idWO8 FUToyu1Go362Q== Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (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 bali.collaboradmins.com (Postfix) with ESMTPSA id 39E9D17E37C0; Tue, 17 Dec 2024 16:44:28 +0100 (CET) From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Cc: p.zabel@pengutronix.de, airlied@gmail.com, simona@ffwll.ch, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, ck.hu@mediatek.com, jitao.shi@mediatek.com, jie.qiu@mediatek.com, junzhi.zhao@mediatek.com, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@collabora.com, dmitry.baryshkov@linaro.org Subject: [PATCH v3 27/33] drm/mediatek: mtk_hdmi: Improve mtk_hdmi_get_all_clk() flexibility Date: Tue, 17 Dec 2024 16:43:39 +0100 Message-ID: <20241217154345.276919-28-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241217154345.276919-1-angelogioacchino.delregno@collabora.com> References: <20241217154345.276919-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In preparation for splitting common bits of this driver and for introducing a new version of the MediaTek HDMI Encoder IP, improve the flexibility of function mtk_hdmi_get_all_clk() by adding a pointer to the clock names array and size of it to its parameters. Also change the array of struct clock pointers in the mtk_hdmi structure to be dynamically allocated, and allocate it in probe. Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/mediatek/mtk_hdmi.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c b/drivers/gpu/drm/mediatek/mtk_hdmi.c index 6c9d046809b2..4dc7113fee10 100644 --- a/drivers/gpu/drm/mediatek/mtk_hdmi.c +++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c @@ -159,7 +159,7 @@ struct mtk_hdmi { struct phy *phy; struct device *cec_dev; struct i2c_adapter *ddc_adpt; - struct clk *clk[MTK_HDMI_CLK_COUNT]; + struct clk **clk; struct drm_display_mode mode; bool dvi_mode; struct regmap *sys_regmap; @@ -1072,17 +1072,18 @@ static const char * const mtk_hdmi_clk_names[MTK_HDMI_CLK_COUNT] = { [MTK_HDMI_CLK_AUD_SPDIF] = "spdif", }; -static int mtk_hdmi_get_all_clk(struct mtk_hdmi *hdmi, - struct device_node *np) +static int mtk_hdmi_get_all_clk(struct mtk_hdmi *hdmi, struct device_node *np, + const char * const *clock_names, size_t num_clocks) { int i; - for (i = 0; i < ARRAY_SIZE(mtk_hdmi_clk_names); i++) { - hdmi->clk[i] = of_clk_get_by_name(np, - mtk_hdmi_clk_names[i]); + for (i = 0; i < num_clocks; i++) { + hdmi->clk[i] = of_clk_get_by_name(np, clock_names[i]); + if (IS_ERR(hdmi->clk[i])) return PTR_ERR(hdmi->clk[i]); } + return 0; } @@ -1381,15 +1382,15 @@ static int mtk_hdmi_get_cec_dev(struct mtk_hdmi *hdmi, struct device *dev, struc return 0; } -static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi, - struct platform_device *pdev) +static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi, struct platform_device *pdev, + const char * const *clk_names, size_t num_clocks) { struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; struct device_node *remote, *i2c_np; int ret; - ret = mtk_hdmi_get_all_clk(hdmi, np); + ret = mtk_hdmi_get_all_clk(hdmi, np, clk_names, num_clocks); if (ret) return dev_err_probe(dev, ret, "Failed to get clocks\n"); @@ -1640,6 +1641,7 @@ static int mtk_hdmi_probe(struct platform_device *pdev) { struct mtk_hdmi *hdmi; struct device *dev = &pdev->dev; + const int num_clocks = MTK_HDMI_CLK_COUNT; int ret; hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); @@ -1649,7 +1651,11 @@ static int mtk_hdmi_probe(struct platform_device *pdev) hdmi->dev = dev; hdmi->conf = of_device_get_match_data(dev); - ret = mtk_hdmi_dt_parse_pdata(hdmi, pdev); + hdmi->clk = devm_kcalloc(dev, num_clocks, sizeof(*hdmi->clk), GFP_KERNEL); + if (!hdmi->clk) + return -ENOMEM; + + ret = mtk_hdmi_dt_parse_pdata(hdmi, pdev, mtk_hdmi_clk_names, num_clocks); if (ret) return ret;