Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp287555pxv; Thu, 8 Jul 2021 02:33:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfRPZM+gUuc9Y0lvv1u2tDDIchJWBrNC92qUobeNGUQU0JNzh/fhROlHvxSeftovwZ2tPU X-Received: by 2002:a17:907:7285:: with SMTP id dt5mr25680983ejc.215.1625736823086; Thu, 08 Jul 2021 02:33:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625736823; cv=none; d=google.com; s=arc-20160816; b=eDps8Ve3AJdsQqCcDw9xokr534lRwFhI4jXIcEELHKSfGq213/fP9Xykbiwv59OqNi EKIDYpyCAjF2YzRv8hnMBddfCXIaoXUzkaYaTfTlKXRGVL62h85CbdHqD2wxev3tnwUw FrVe3ezlInkjwNFBcouYQrT6Y2iZg2+NzFFvVBMjaEf/uE/st6f/rvW5Ty71r+GJcPvT GNROJuUWO3r0LTAV1w7pqCUFiNJVF+yYsBPngjsm+YgttGeFA61LPNZIlBL51eCWgaaF b1phwRcYELyJboMIUTB5qinJJ3379SMPuWvGBXPue7/KIs1NnzFpJQpiQ2H0SIqBRBfx Ja2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=hivxADq7n4rAof/nBtodbPp1gcTG2fZwZu7ibesuf2Q=; b=Mi+6i7ae89UmpN3F6u3dt8MaoAdJonGygCCLCPBxnlOrDYq/0tR1wn+zLP/knYWa8K g4QgatUUI1l7IHah3Au2C1dfxLjokRR0cUbGjCNdzH2O3JT4zIZHnCebbRGhWBi+q0c4 rSm9oIvW8Kmy2SyYJ5efz4BMliaAUlRFO3HLbjFhxUhoSuaSR+QWurmBxFz+hbfoKvhA Jvmr8tOKZFIREwYdU+hwIxaeEczEW1UQ7xUfimc4k/RLP703sK+thQtptXZ7WD3rq1tO W0o/8V8qIiFNd1MFI0K0ppK1IuOcOd91+fUoTPeT3DHFY13eMFta+onN209s6HOhycUv 6AYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ar26si2143892ejc.427.2021.07.08.02.33.19; Thu, 08 Jul 2021 02:33:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231305AbhGHJfG (ORCPT + 99 others); Thu, 8 Jul 2021 05:35:06 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:34728 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231286AbhGHJfF (ORCPT ); Thu, 8 Jul 2021 05:35:05 -0400 Received: from mail-wr1-f71.google.com ([209.85.221.71]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1m1QOM-0006Xq-Rj for linux-kernel@vger.kernel.org; Thu, 08 Jul 2021 09:32:22 +0000 Received: by mail-wr1-f71.google.com with SMTP id 32-20020adf82a30000b029013b21c75294so500217wrc.14 for ; Thu, 08 Jul 2021 02:32:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=hivxADq7n4rAof/nBtodbPp1gcTG2fZwZu7ibesuf2Q=; b=lCn2BzBtxVR0ijLAqXRocd47ysvlJ0tq+wNrR/IB4/FjhP0/dIw9YCrzo5h5cf95FS Dpk3SJNg/1BqTXQQ4XPxfsGkUR36Jx7jR1nSdHtdfdUlJu9jVpVKkJMA/WRAROv+bYdL 74aRU+SREQZOEHViSVs3gNjUrtPVJZHNWA+y9a693no0aJAQb0kJ1esFG2t9P1SRV8z9 x4COTL+R9K3Rdwmn3cHBBGNsvBbEya7kue91rZS/dI8vAh5BIaH4avVENzz+qcc0J7VG w3ubP26SReZATfVW6cByPm1F9axAcjsWrZNiPc0/nX/phYbhz1fLH6sjfflawDuvQhBP e/Aw== X-Gm-Message-State: AOAM533EM3prUa87EPAS9hWVzdhmBdnp+Yusr8jajZzouFYl3iQODXrq QV703ZoHEj5IaI3lmk0d+6QcCTxHaF7n9VRe80zth3bGRtk3j9iAJR7qsfaB2hdfyfAY6jlS4mE 8gvT+TRlrq1l4ygkGudRJhcD4cCxNmIeJWQkfv0MfAQ== X-Received: by 2002:adf:8bc9:: with SMTP id w9mr32448632wra.378.1625736739767; Thu, 08 Jul 2021 02:32:19 -0700 (PDT) X-Received: by 2002:adf:8bc9:: with SMTP id w9mr32448601wra.378.1625736739535; Thu, 08 Jul 2021 02:32:19 -0700 (PDT) Received: from [192.168.3.211] (xdsl-188-155-177-222.adslplus.ch. [188.155.177.222]) by smtp.gmail.com with ESMTPSA id h14sm1918435wro.32.2021.07.08.02.32.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Jul 2021 02:32:19 -0700 (PDT) Subject: Re: [PATCH 3/9] memory: mtk-smi: Use clk_bulk instead of the clk ops To: Yong Wu , Rob Herring , Matthias Brugger Cc: Krzysztof Kozlowski , Joerg Roedel , Will Deacon , Robin Murphy , Tomasz Figa , linux-mediatek@lists.infradead.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, youlin.pei@mediatek.com, anan.sun@mediatek.com, ming-fan.chen@mediatek.com, yi.kuo@mediatek.com, anthony.huang@mediatek.com References: <20210616114346.18812-1-yong.wu@mediatek.com> <20210616114346.18812-4-yong.wu@mediatek.com> From: Krzysztof Kozlowski Message-ID: <4047dfaf-f2f8-b6b2-52fd-41821475b162@canonical.com> Date: Thu, 8 Jul 2021 11:32:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210616114346.18812-4-yong.wu@mediatek.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/06/2021 13:43, Yong Wu wrote: > smi have many clocks: apb/smi/gals. > This patch use clk_bulk interface instead of the orginal one to simply > the code. > > gals is optional clk(some larbs may don't have gals). use clk_bulk_optional > instead. and then remove the has_gals flag. > > Also remove clk fail logs since bulk interface already output fail log. > > Signed-off-by: Yong Wu > --- > drivers/memory/mtk-smi.c | 124 +++++++++++---------------------------- > 1 file changed, 34 insertions(+), 90 deletions(-) > > diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c > index c5fb51f73b34..bcd2bf130655 100644 > --- a/drivers/memory/mtk-smi.c > +++ b/drivers/memory/mtk-smi.c > @@ -60,9 +60,18 @@ enum mtk_smi_gen { > MTK_SMI_GEN2 > }; > > +#define MTK_SMI_CLK_NR_MAX 4 > + > +static const char * const mtk_smi_common_clocks[] = { > + "apb", "smi", "gals0", "gals1", /* glas is optional */ Typo here - glas. > +}; > + > +static const char * const mtk_smi_larb_clocks[] = { > + "apb", "smi", "gals" > +}; > + > struct mtk_smi_common_plat { > enum mtk_smi_gen gen; > - bool has_gals; > u32 bus_sel; /* Balance some larbs to enter mmu0 or mmu1 */ > }; > > @@ -70,13 +79,12 @@ struct mtk_smi_larb_gen { > int port_in_larb[MTK_LARB_NR_MAX + 1]; > void (*config_port)(struct device *dev); > unsigned int larb_direct_to_common_mask; > - bool has_gals; > }; > > struct mtk_smi { > struct device *dev; > - struct clk *clk_apb, *clk_smi; > - struct clk *clk_gals0, *clk_gals1; > + unsigned int clk_num; > + struct clk_bulk_data clks[MTK_SMI_CLK_NR_MAX]; > struct clk *clk_async; /*only needed by mt2701*/ > union { > void __iomem *smi_ao_base; /* only for gen1 */ > @@ -95,45 +103,6 @@ struct mtk_smi_larb { /* larb: local arbiter */ > unsigned char *bank; > }; > > -static int mtk_smi_clk_enable(const struct mtk_smi *smi) > -{ > - int ret; > - > - ret = clk_prepare_enable(smi->clk_apb); > - if (ret) > - return ret; > - > - ret = clk_prepare_enable(smi->clk_smi); > - if (ret) > - goto err_disable_apb; > - > - ret = clk_prepare_enable(smi->clk_gals0); > - if (ret) > - goto err_disable_smi; > - > - ret = clk_prepare_enable(smi->clk_gals1); > - if (ret) > - goto err_disable_gals0; > - > - return 0; > - > -err_disable_gals0: > - clk_disable_unprepare(smi->clk_gals0); > -err_disable_smi: > - clk_disable_unprepare(smi->clk_smi); > -err_disable_apb: > - clk_disable_unprepare(smi->clk_apb); > - return ret; > -} > - > -static void mtk_smi_clk_disable(const struct mtk_smi *smi) > -{ > - clk_disable_unprepare(smi->clk_gals1); > - clk_disable_unprepare(smi->clk_gals0); > - clk_disable_unprepare(smi->clk_smi); > - clk_disable_unprepare(smi->clk_apb); > -} > - > int mtk_smi_larb_get(struct device *larbdev) > { > int ret = pm_runtime_resume_and_get(larbdev); > @@ -270,7 +239,6 @@ static const struct mtk_smi_larb_gen mtk_smi_larb_mt6779 = { > }; > > static const struct mtk_smi_larb_gen mtk_smi_larb_mt8183 = { > - .has_gals = true, > .config_port = mtk_smi_larb_config_port_gen2_general, > .larb_direct_to_common_mask = BIT(2) | BIT(3) | BIT(7), > /* IPU0 | IPU1 | CCU */ > @@ -320,6 +288,7 @@ static int mtk_smi_larb_probe(struct platform_device *pdev) > struct device_node *smi_node; > struct platform_device *smi_pdev; > struct device_link *link; > + int i, ret; > > larb = devm_kzalloc(dev, sizeof(*larb), GFP_KERNEL); > if (!larb) > @@ -331,22 +300,14 @@ static int mtk_smi_larb_probe(struct platform_device *pdev) > if (IS_ERR(larb->base)) > return PTR_ERR(larb->base); > > - larb->smi.clk_apb = devm_clk_get(dev, "apb"); > - if (IS_ERR(larb->smi.clk_apb)) > - return PTR_ERR(larb->smi.clk_apb); > - > - larb->smi.clk_smi = devm_clk_get(dev, "smi"); > - if (IS_ERR(larb->smi.clk_smi)) > - return PTR_ERR(larb->smi.clk_smi); > - > - if (larb->larb_gen->has_gals) { > - /* The larbs may still haven't gals even if the SoC support.*/ > - larb->smi.clk_gals0 = devm_clk_get(dev, "gals"); > - if (PTR_ERR(larb->smi.clk_gals0) == -ENOENT) > - larb->smi.clk_gals0 = NULL; > - else if (IS_ERR(larb->smi.clk_gals0)) > - return PTR_ERR(larb->smi.clk_gals0); > - } > + larb->smi.clk_num = ARRAY_SIZE(mtk_smi_larb_clocks); > + for (i = 0; i < larb->smi.clk_num; i++) > + larb->smi.clks[i].id = mtk_smi_larb_clocks[i]; > + > + ret = devm_clk_bulk_get_optional(dev, larb->smi.clk_num, larb->smi.clks); > + if (ret) > + return ret; > + > larb->smi.dev = dev; > > smi_node = of_parse_phandle(dev->of_node, "mediatek,smi", 0); > @@ -391,11 +352,9 @@ static int __maybe_unused mtk_smi_larb_resume(struct device *dev) > const struct mtk_smi_larb_gen *larb_gen = larb->larb_gen; > int ret; > > - ret = mtk_smi_clk_enable(&larb->smi); > - if (ret < 0) { > - dev_err(dev, "Failed to enable clock(%d).\n", ret); > + ret = clk_bulk_prepare_enable(larb->smi.clk_num, larb->smi.clks); > + if (ret < 0) > return ret; > - } > > /* Configure the basic setting for this larb */ > larb_gen->config_port(dev); > @@ -407,7 +366,7 @@ static int __maybe_unused mtk_smi_larb_suspend(struct device *dev) > { > struct mtk_smi_larb *larb = dev_get_drvdata(dev); > > - mtk_smi_clk_disable(&larb->smi); > + clk_bulk_disable_unprepare(larb->smi.clk_num, larb->smi.clks); > return 0; > } > > @@ -437,21 +396,18 @@ static const struct mtk_smi_common_plat mtk_smi_common_gen2 = { > > static const struct mtk_smi_common_plat mtk_smi_common_mt6779 = { > .gen = MTK_SMI_GEN2, > - .has_gals = true, > .bus_sel = F_MMU1_LARB(1) | F_MMU1_LARB(2) | F_MMU1_LARB(4) | > F_MMU1_LARB(5) | F_MMU1_LARB(6) | F_MMU1_LARB(7), > }; > > static const struct mtk_smi_common_plat mtk_smi_common_mt8183 = { > .gen = MTK_SMI_GEN2, > - .has_gals = true, > .bus_sel = F_MMU1_LARB(1) | F_MMU1_LARB(2) | F_MMU1_LARB(5) | > F_MMU1_LARB(7), > }; > > static const struct mtk_smi_common_plat mtk_smi_common_mt8192 = { > .gen = MTK_SMI_GEN2, > - .has_gals = true, > .bus_sel = F_MMU1_LARB(1) | F_MMU1_LARB(2) | F_MMU1_LARB(5) | > F_MMU1_LARB(6), > }; > @@ -493,7 +449,7 @@ static int mtk_smi_common_probe(struct platform_device *pdev) > struct device *dev = &pdev->dev; > struct mtk_smi *common; > struct resource *res; > - int ret; > + int i, ret; > > common = devm_kzalloc(dev, sizeof(*common), GFP_KERNEL); > if (!common) > @@ -501,23 +457,13 @@ static int mtk_smi_common_probe(struct platform_device *pdev) > common->dev = dev; > common->plat = of_device_get_match_data(dev); > > - common->clk_apb = devm_clk_get(dev, "apb"); > - if (IS_ERR(common->clk_apb)) > - return PTR_ERR(common->clk_apb); > - > - common->clk_smi = devm_clk_get(dev, "smi"); > - if (IS_ERR(common->clk_smi)) > - return PTR_ERR(common->clk_smi); > + common->clk_num = ARRAY_SIZE(mtk_smi_common_clocks); > + for (i = 0; i < common->clk_num; i++) > + common->clks[i].id = mtk_smi_common_clocks[i]; > > - if (common->plat->has_gals) { > - common->clk_gals0 = devm_clk_get(dev, "gals0"); > - if (IS_ERR(common->clk_gals0)) > - return PTR_ERR(common->clk_gals0); > - > - common->clk_gals1 = devm_clk_get(dev, "gals1"); > - if (IS_ERR(common->clk_gals1)) > - return PTR_ERR(common->clk_gals1); > - } > + ret = devm_clk_bulk_get_optional(dev, common->clk_num, common->clks); > + if (ret) > + return ret; How do you handle now missing required clocks? > > /* > * for mtk smi gen 1, we need to get the ao(always on) base to config > @@ -561,11 +507,9 @@ static int __maybe_unused mtk_smi_common_resume(struct device *dev) > u32 bus_sel = common->plat->bus_sel; > int ret; > > - ret = mtk_smi_clk_enable(common); > - if (ret) { > - dev_err(common->dev, "Failed to enable clock(%d).\n", ret); > + ret = clk_bulk_prepare_enable(common->clk_num, common->clks); > + if (ret) > return ret; > - } > > if (common->plat->gen == MTK_SMI_GEN2 && bus_sel) > writel(bus_sel, common->base + SMI_BUS_SEL); > @@ -576,7 +520,7 @@ static int __maybe_unused mtk_smi_common_suspend(struct device *dev) > { > struct mtk_smi *common = dev_get_drvdata(dev); > > - mtk_smi_clk_disable(common); > + clk_bulk_disable_unprepare(common->clk_num, common->clks); > return 0; > } > > Best regards, Krzysztof