Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2931029ybk; Mon, 18 May 2020 11:23:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsnoZALWSc2NjfNBok+dfodnmjaW5pCIErhUU27c3CCcEZQMMux9JueqpqepCFm+aGD5j2 X-Received: by 2002:a50:fe06:: with SMTP id f6mr13298365edt.125.1589826196502; Mon, 18 May 2020 11:23:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589826196; cv=none; d=google.com; s=arc-20160816; b=pTC35uTqi2OggViosaEH7NTE6JKakIrusRU//hEfFbGTpbNvhqH4PZ3rSPWOioi34u MT40goO1APomUh01dYuXQsZQl2O/Jeg4fXD+Rt7PmGzZ30x+6CMSoG0rsKSEwdAAKQg9 y2ELbQqxMGeDrNWrU02ZU6/oVSdKAbQmUoe1soznMtThdIu5JDDrhGg8z1vPOT6sTBJR 4WLJfhYX4GS0Hkb1Cl3uju6IBmLwIone0egljNxJ2y+PhEGpRBjPlf5h5NPs1vrLzHo1 h15LPq62FDzkRd7TxDjNeT5KDicJ3+g3myBHAbBUFQtpbm0p/zC7Eu+ncj8eNwsK+pls UqDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=stGkoHZ5bZAzHpLr3No9QfMs9tBe36zfoyIU6nQI9A4=; b=DlqgBfLDc0X18EAlIZG+230gzrBDmtBcYzhQ0zrMimt++x3hcbIlD0Xcd0ydqtHzGn LiQTRMB3TX0GgDlzvDqJm52rEiWE3ONrmikWDYWUIUmOauAhvzRfD2RAd0DeQFQKJ+WG BqDckpxIk2Hc6rwUbtY3ouBkDf3tj7ZPdT5epl5ALM5cqR+WCTFO14neBi2DBOld/xDj K/e0Te8WGPDG6V+DWdmRien2E1yno/WI1n5igps5SVCA6WY+ICYeLTFSmy91EgoqND1F 7TZDV58m0NV79O8NSU8zcrbKo9+a31u1FwX15CDq1sG02lR69P6eB6wdvW87s+Z3votL oRGw== 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=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j14si6222448ejk.164.2020.05.18.11.22.52; Mon, 18 May 2020 11:23:16 -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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731880AbgERSUm (ORCPT + 99 others); Mon, 18 May 2020 14:20:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730997AbgERRwe (ORCPT ); Mon, 18 May 2020 13:52:34 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0DADC061A0C for ; Mon, 18 May 2020 10:52:33 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id CF53F2A10C9 Subject: Re: [PATCH v14 03/11] soc: mediatek: Add basic_clk_name to scp_power_data To: Weiyi Lu Cc: Enric Balletbo Serra , Matthias Brugger , Nicolas Boichat , Rob Herring , Sascha Hauer , James Liao , srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, Fan Chen , linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org References: <1588752963-19934-1-git-send-email-weiyi.lu@mediatek.com> <1588752963-19934-4-git-send-email-weiyi.lu@mediatek.com> <7ad67855-a3f8-f979-8849-3765bd8289d3@collabora.com> <1589176947.21832.9.camel@mtksdaap41> <1589513724.16252.3.camel@mtksdaap41> From: Enric Balletbo i Serra Message-ID: Date: Mon, 18 May 2020 19:52:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <1589513724.16252.3.camel@mtksdaap41> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Weiyi, On 15/5/20 5:35, Weiyi Lu wrote: > On Mon, 2020-05-11 at 14:02 +0800, Weiyi Lu wrote: >> On Wed, 2020-05-06 at 23:01 +0200, Enric Balletbo i Serra wrote: >>> Hi Weiyi, >>> >>> Thank you for your patch. >>> >>> On 6/5/20 10:15, Weiyi Lu wrote: >>>> Try to stop extending the clk_id or clk_names if there are >>>> more and more new BASIC clocks. To get its own clocks by the >>>> basic_clk_name of each power domain. >>>> And then use basic_clk_name strings for all compatibles, instead of >>>> mixing clk_id and clk_name. >>>> >>>> Signed-off-by: Weiyi Lu >>>> Reviewed-by: Nicolas Boichat >>>> --- >>>> drivers/soc/mediatek/mtk-scpsys.c | 134 ++++++++++++-------------------------- >>>> 1 file changed, 41 insertions(+), 93 deletions(-) >>>> >>>> diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c >>>> index f669d37..c9c3cf7 100644 >>>> --- a/drivers/soc/mediatek/mtk-scpsys.c >>>> +++ b/drivers/soc/mediatek/mtk-scpsys.c >>>> @@ -78,34 +78,6 @@ >>>> #define PWR_STATUS_HIF1 BIT(26) /* MT7622 */ >>>> #define PWR_STATUS_WB BIT(27) /* MT7622 */ >>>> >>>> -enum clk_id { >>>> - CLK_NONE, >>>> - CLK_MM, >>>> - CLK_MFG, >>>> - CLK_VENC, >>>> - CLK_VENC_LT, >>>> - CLK_ETHIF, >>>> - CLK_VDEC, >>>> - CLK_HIFSEL, >>>> - CLK_JPGDEC, >>>> - CLK_AUDIO, >>>> - CLK_MAX, >>>> -}; >>>> - >>>> -static const char * const clk_names[] = { >>>> - NULL, >>>> - "mm", >>>> - "mfg", >>>> - "venc", >>>> - "venc_lt", >>>> - "ethif", >>>> - "vdec", >>>> - "hif_sel", >>>> - "jpgdec", >>>> - "audio", >>>> - NULL, >>>> -}; >>>> - >>>> #define MAX_CLKS 3 >>>> >>>> /** >>>> @@ -116,7 +88,7 @@ enum clk_id { >>>> * @sram_pdn_bits: The mask for sram power control bits. >>>> * @sram_pdn_ack_bits: The mask for sram power control acked bits. >>>> * @bus_prot_mask: The mask for single step bus protection. >>>> - * @clk_id: The basic clocks required by this power domain. >>>> + * @basic_clk_name: The basic clocks required by this power domain. >>>> * @caps: The flag for active wake-up action. >>>> */ >>>> struct scp_domain_data { >>>> @@ -126,7 +98,7 @@ struct scp_domain_data { >>>> u32 sram_pdn_bits; >>>> u32 sram_pdn_ack_bits; >>>> u32 bus_prot_mask; >>>> - enum clk_id clk_id[MAX_CLKS]; >>>> + const char *basic_clk_name[MAX_CLKS]; >>> >>> I only reviewed v13, so sorry if this was already discussed. I am wondering if >>> would be better take advantage of the devm_clk_bulk_get() function instead of >>> kind of reimplementing the same, something like this >>> >>> const struct clk_bulk_data *basic_clocks; >>> >> >> I thought it should be const struct clk_bulk_data >> basic_clocks[MAX_CLKS]; instead of const struct clk_bulk_data >> *basic_clocks; in struct scp_domain_data data type >> >>>> u8 caps; >>>> }; >>>> >>>> @@ -411,12 +383,19 @@ static int scpsys_power_off(struct generic_pm_domain *genpd) >>>> return ret; >>>> } >>>> >>>> -static void init_clks(struct platform_device *pdev, struct clk **clk) >>>> +static int init_basic_clks(struct platform_device *pdev, struct clk **clk, >>>> + const char * const *name) >>>> { >>>> int i; >>>> >>>> - for (i = CLK_NONE + 1; i < CLK_MAX; i++) >>>> - clk[i] = devm_clk_get(&pdev->dev, clk_names[i]); >>>> + for (i = 0; i < MAX_CLKS && name[i]; i++) { >>>> + clk[i] = devm_clk_get(&pdev->dev, name[i]); >>>> + >>>> + if (IS_ERR(clk[i])) >>>> + return PTR_ERR(clk[i]); >>>> + } >>> >>> You will be able to remove this function, see below ... >>> >>>> + >>>> + return 0; >>>> } >>>> >>>> static struct scp *init_scp(struct platform_device *pdev, >>>> @@ -426,9 +405,8 @@ static struct scp *init_scp(struct platform_device *pdev, >>>> { >>>> struct genpd_onecell_data *pd_data; >>>> struct resource *res; >>>> - int i, j; >>>> + int i, ret; >>>> struct scp *scp; >>>> - struct clk *clk[CLK_MAX]; >>>> >>>> scp = devm_kzalloc(&pdev->dev, sizeof(*scp), GFP_KERNEL); >>>> if (!scp) >>>> @@ -481,8 +459,6 @@ static struct scp *init_scp(struct platform_device *pdev, >>>> >>>> pd_data->num_domains = num; >>>> >>>> - init_clks(pdev, clk); >>>> - >>>> for (i = 0; i < num; i++) { >>>> struct scp_domain *scpd = &scp->domains[i]; >>>> struct generic_pm_domain *genpd = &scpd->genpd; >>>> @@ -493,17 +469,9 @@ static struct scp *init_scp(struct platform_device *pdev, >>>> >>>> scpd->data = data; >>>> >>>> - for (j = 0; j < MAX_CLKS && data->clk_id[j]; j++) { >>>> - struct clk *c = clk[data->clk_id[j]]; >>>> - >>>> - if (IS_ERR(c)) { >>>> - dev_err(&pdev->dev, "%s: clk unavailable\n", >>>> - data->name); >>>> - return ERR_CAST(c); >>>> - } >>>> - >>>> - scpd->clk[j] = c; >>>> - } >>>> + ret = init_basic_clks(pdev, scpd->clk, data->basic_clk_name); >>>> + if (ret) >>>> + return ERR_PTR(ret); >>> >>> Just call: >>> >>> ret = devm_clk_bulk_get(&pdev->dev, ARRAY_SIZE(basic_clocks), >>> data->basic_clocks); >>> if (ret) >>> return ERR_PTR(ret); >>> >>>> >>>> genpd->name = data->name; >>>> genpd->power_off = scpsys_power_off; >>>> @@ -560,7 +528,6 @@ static void mtk_register_power_domains(struct platform_device *pdev, >>>> .ctl_offs = SPM_CONN_PWR_CON, >>>> .bus_prot_mask = MT2701_TOP_AXI_PROT_EN_CONN_M | >>>> MT2701_TOP_AXI_PROT_EN_CONN_S, >>>> - .clk_id = {CLK_NONE}, >>>> .caps = MTK_SCPD_ACTIVE_WAKEUP, >>>> }, >>>> [MT2701_POWER_DOMAIN_DISP] = { >>>> @@ -568,7 +535,7 @@ static void mtk_register_power_domains(struct platform_device *pdev, >>>> .sta_mask = PWR_STATUS_DISP, >>>> .ctl_offs = SPM_DIS_PWR_CON, >>>> .sram_pdn_bits = GENMASK(11, 8), >>>> - .clk_id = {CLK_MM}, >>>> + .basic_clk_name = {"mm"}, >>> >>> .basic_clocks[] = { >>> { .id = "mm" }, >>> }; >>> >> >> Those basic clocks without given a name (name: null) would get incorrect >> clock via clk_bulk_get(...) due to >> >> /** >> * of_parse_clkspec() - Parse a DT clock specifier for a given device >> node >> * @np: device node to parse clock specifier from >> * @index: index of phandle to parse clock out of. If index < 0, @name >> is used >> * @name: clock name to find and parse. If name is NULL, the index is >> used >> >> And the index is 0 here in this callstack >> >> I guess something need to be improved before we use the clk_bulk_ APIs. >> > > Hi Enric, > > According to the result above, is it necessary to change the APIs or > maybe I should send the next version v15 first to fix other problems you > mentioned? Many thanks. > It is fine to send a next version without changing the APIs, it depends on the extra work if you are fine with the change. To be honest I didn't see the problem above but I think can be fixed. Cheers, Enric >> >>>> .bus_prot_mask = MT2701_TOP_AXI_PROT_EN_MM_M0, >>>> .caps = MTK_SCPD_ACTIVE_WAKEUP, >>>> }, >>>> @@ -578,7 +545,7 @@ static void mtk_register_power_domains(struct platform_device *pdev, >>>> .ctl_offs = SPM_MFG_PWR_CON, >>>> .sram_pdn_bits = GENMASK(11, 8), >>>> .sram_pdn_ack_bits = GENMASK(12, 12), >>>> - .clk_id = {CLK_MFG}, >>>> + .basic_clk_name = {"mfg"}, >>> >>> .basic_clocks[] = { >>> { .id = "mfg" }, >>> }; >>> >>>> .caps = MTK_SCPD_ACTIVE_WAKEUP, >>>> }, >>>> [MT2701_POWER_DOMAIN_VDEC] = { >>>> @@ -587,7 +554,7 @@ static void mtk_register_power_domains(struct platform_device *pdev, >>>> .ctl_offs = SPM_VDE_PWR_CON, >>>> .sram_pdn_bits = GENMASK(11, 8), >>>> .sram_pdn_ack_bits = GENMASK(12, 12), >>>> - .clk_id = {CLK_MM}, >>>> + .basic_clk_name = {"mm"}, >>> >>> ... >>> >>> [snip] >> >> >