From patchwork Mon Mar 6 14:04:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 64694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1868379wrd; Mon, 6 Mar 2023 06:22:04 -0800 (PST) X-Google-Smtp-Source: AK7set+iy2BFSjzf+PlhMInZP5xZErL/C1dtxItnLN+HJ0w92gjJAb2VF1ehxZ1hsoaDhj4O66E2 X-Received: by 2002:a05:6402:205c:b0:4cf:350e:344c with SMTP id bc28-20020a056402205c00b004cf350e344cmr9186950edb.28.1678112523970; Mon, 06 Mar 2023 06:22:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678112523; cv=none; d=google.com; s=arc-20160816; b=h6ewXogBi+pWna/Xf3N7m4NLYnQ3YDUTJXVyjT7XkQihJTUn8TPXQ7s2Ftp2ShgFFW +ngp1P+K8nvivMMSXLNf2gBK92ZE9WXgThAQDQM7oLYYKavYVBVjCAnH8udEKoQ7HSl0 YeaFgQxLZRkt4NRT3H3yGI7piRu8sblBD6KettbWs1Is4rF2WBn+rtAKricL3YCvKkDw qgyIreLUk28tqsY0Vh/N+jc2nHKjrztwaN+6+0MB9YqxMU/053c8Qqe9PJtT//o5xYKJ Crl0H9M6QWXxJVAB/zBVugALKt0Ww5oPsYFoc73DuLi+3PzK5yUGg1rZp2EGAA0XYZTW NUWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rAQEfpH7EU8GhYaBHeXGjVDRe+yjxsE7IRyKTIfUPDw=; b=CPrPNcvB1k9xzvuuQap4G0qNgm+GYuuVTZ0A4L/BZng0djQk7mNhjaEta2mPDZGMfo 581Oh7IGpl//El3uINtzeeFWM0+Yl9hwHLfs2hw6t3yQ0SV3l2oBBqCZRcXdGznAp9nq 1yAiPAPWQL+XziQbFUATEuOdlCYvNZH10utJ5wREPfGo3H6bbxqmrXfPi9nkC7UtNO7Q CNTaRyuPxn3GYEvTv5upQf9Wz6hps/UeTDZTAKJQV/S7T29EUfhoVtS08BiTRT/VPdCF 4MALDlVUILBHAM1s/Fzh+l8ARENVMWJvRQf6iZY12FoZiyK6nsBk+26Yu5S5ujXzxHu3 GQaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="Tfijg3Y/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w14-20020a056402128e00b004cfc2f60ca2si8745583edv.450.2023.03.06.06.21.40; Mon, 06 Mar 2023 06:22:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="Tfijg3Y/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230297AbjCFOG1 (ORCPT + 99 others); Mon, 6 Mar 2023 09:06:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229579AbjCFOGS (ORCPT ); Mon, 6 Mar 2023 09:06:18 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AB972E0E8; Mon, 6 Mar 2023 06:05:53 -0800 (PST) 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 madras.collabora.co.uk (Postfix) with ESMTPSA id 8D5FC6602EB0; Mon, 6 Mar 2023 14:05:50 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1678111551; bh=9i/8Ogc625ptZfLpH008pUkGxEfdtF85H6GNNpiSoQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tfijg3Y/6hjvwlxoTQsH9zvam0IdKNmHOtBfYpn0f1IeSqy7evESnk/wfOkZglrhz 1piZPY637MoJBOHKUQf3oKShBF0K/xzu0yhQIKpXcGpPYjnYUamu4wIYicTePtsXaI J9qEp6gIuMaE6haQ0N/0eYcZ0McjFXsic7xG2i+tXdlaf4OjH6/LptorfwNu/dmuaj 1bWsIF+3WkZ9oAHTdKkKaKBs2vpd759+B3x2pCuD+0cIIo+GrMRjZs/7vVeCkZgvRr IB0C0SrQAVB535HRrQrdFGhP8tPpFsa+OEBNqzf9pO506ypkGtCkAhfZYNHMuv9ljg ihchuOSbWX9YQ== From: AngeloGioacchino Del Regno To: mturquette@baylibre.com Cc: sboyd@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, wenst@chromium.org, johnson.wang@mediatek.com, miles.chen@mediatek.com, chun-jie.chen@mediatek.com, daniel@makrotopia.org, fparent@baylibre.com, msp@baylibre.com, nfraprado@collabora.com, rex-bc.chen@mediatek.com, zhaojh329@gmail.com, sam.shih@mediatek.com, edward-jw.yang@mediatek.com, yangyingliang@huawei.com, granquet@baylibre.com, pablo.sun@mediatek.com, sean.wang@mediatek.com, chen.zhong@mediatek.com, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel@collabora.com Subject: [PATCH v6 02/54] clk: mediatek: clk-mtk: Introduce clk_mtk_pdev_{probe,remove}() Date: Mon, 6 Mar 2023 15:04:51 +0100 Message-Id: <20230306140543.1813621-3-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230306140543.1813621-1-angelogioacchino.delregno@collabora.com> References: <20230306140543.1813621-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759628517918693964?= X-GMAIL-MSGID: =?utf-8?q?1759628517918693964?= Introduce functions clk_mtk_pdev_probe() and clk_mtk_pdev_remove(): these will be useful to commonize the probe and remove handlers for multimedia (clk-mtxxxx-mm) drivers as these are registered by the mtk-mmsys driver instead of having their own devicetree compatible. In order to do this, the main logic of clk_mtk_simple{probe,remove}() was moved to new static __clk_mtk_simple_{probe,remove}() functions that take as parameter a pointer to struct device_node because when registering the clocks from mtk-mmsys we want to pass a pointer to the clock driver's parent (which is, obviously, mtk-mmsys) struct device_node instead. As for the clock driver's platform data: for the devicetree case, we keep using the standard match_data mechanism, else we retrieve it from an id_table. Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Chen-Yu Tsai Tested-by: Miles Chen Tested-by: Chen-Yu Tsai --- drivers/clk/mediatek/clk-mtk.c | 54 +++++++++++++++++++++++++++++----- drivers/clk/mediatek/clk-mtk.h | 2 ++ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index f0b723372b52..990be3d62db2 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -462,17 +462,25 @@ void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num, } EXPORT_SYMBOL_GPL(mtk_clk_unregister_dividers); -int mtk_clk_simple_probe(struct platform_device *pdev) +static int __mtk_clk_simple_probe(struct platform_device *pdev, + struct device_node *node) { + const struct platform_device_id *id; const struct mtk_clk_desc *mcd; struct clk_hw_onecell_data *clk_data; - struct device_node *node = pdev->dev.of_node; void __iomem *base; int num_clks, r; mcd = device_get_match_data(&pdev->dev); - if (!mcd) - return -EINVAL; + if (!mcd) { + /* Clock driver wasn't registered from devicetree */ + id = platform_get_device_id(pdev); + if (id) + mcd = (const struct mtk_clk_desc *)id->driver_data; + + if (!mcd) + return -EINVAL; + } /* Composite clocks needs us to pass iomem pointer */ if (mcd->composite_clks) { @@ -581,13 +589,12 @@ int mtk_clk_simple_probe(struct platform_device *pdev) iounmap(base); return r; } -EXPORT_SYMBOL_GPL(mtk_clk_simple_probe); -int mtk_clk_simple_remove(struct platform_device *pdev) +static int __mtk_clk_simple_remove(struct platform_device *pdev, + struct device_node *node) { - const struct mtk_clk_desc *mcd = device_get_match_data(&pdev->dev); struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev); - struct device_node *node = pdev->dev.of_node; + const struct mtk_clk_desc *mcd = device_get_match_data(&pdev->dev); of_clk_del_provider(node); if (mcd->clks) @@ -608,6 +615,37 @@ int mtk_clk_simple_remove(struct platform_device *pdev) return 0; } + +int mtk_clk_pdev_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *node = dev->parent->of_node; + + return __mtk_clk_simple_probe(pdev, node); +} +EXPORT_SYMBOL_GPL(mtk_clk_pdev_probe); + +int mtk_clk_simple_probe(struct platform_device *pdev) +{ + struct device_node *node = pdev->dev.of_node; + + return __mtk_clk_simple_probe(pdev, node); +} +EXPORT_SYMBOL_GPL(mtk_clk_simple_probe); + +int mtk_clk_pdev_remove(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *node = dev->parent->of_node; + + return __mtk_clk_simple_remove(pdev, node); +} +EXPORT_SYMBOL_GPL(mtk_clk_pdev_remove); + +int mtk_clk_simple_remove(struct platform_device *pdev) +{ + return __mtk_clk_simple_remove(pdev, pdev->dev.of_node); +} EXPORT_SYMBOL_GPL(mtk_clk_simple_remove); MODULE_LICENSE("GPL"); diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h index 41f4fa3b0c21..b8e0ff8f52fa 100644 --- a/drivers/clk/mediatek/clk-mtk.h +++ b/drivers/clk/mediatek/clk-mtk.h @@ -236,6 +236,8 @@ struct mtk_clk_desc { unsigned int mfg_clk_idx; }; +int mtk_clk_pdev_probe(struct platform_device *pdev); +int mtk_clk_pdev_remove(struct platform_device *pdev); int mtk_clk_simple_probe(struct platform_device *pdev); int mtk_clk_simple_remove(struct platform_device *pdev);