From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9B5EC636C9 for ; Wed, 21 Jul 2021 11:56:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AFDA060E08 for ; Wed, 21 Jul 2021 11:56:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238983AbhGULPm (ORCPT ); Wed, 21 Jul 2021 07:15:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239643AbhGULFU (ORCPT ); Wed, 21 Jul 2021 07:05:20 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C0BBC0613E7 for ; Wed, 21 Jul 2021 04:44:07 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d12so2042953pfj.2 for ; Wed, 21 Jul 2021 04:44:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4eOE5oXt0Te/GnUqshzOeQhr7DeyqOGjYygIrkfQGGA=; b=KdQI6LuD8Wmsu8sCpYBmVNr4uqXouJd6KbQ3iYRLn2UXIAxs+TuEUbZye6F9L7aj1V ZAgxxPSOUOm+s48Q3N1vGWUj2UI5ovvKG0zNnKpAZ+Y4nQZHgOrkuO2NxaUrVYYpljXg lyBhu/YTGUcqASeyyy69yxEUAvWHEkFO5P9HA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4eOE5oXt0Te/GnUqshzOeQhr7DeyqOGjYygIrkfQGGA=; b=TQnupXIE+a/cXRuNC04PA7QlauOZ7t92nNzkWdmlpsa4qgvWjOmFmtL7yIEhFSajWQ UTK+kHXX6C09lu9/q98BSpTSAW4+asQ4poaTZrdRvhwIi4t3l4f4wG4T8K4oE/QBONXY ReRYJWkj7dqdRvfUfZLBrkIDBLPvw/SN6+xj+oQXachwd0TscxJSR7L3Xkgao2xh8ppp R1ivM7l7mpT0h9XQWiao6PSJtcBS4sn2OS3HyTHx+udz2N7HZotac99tTGwxmp+31Vkp PnaVArJK1I1XDJcyEikSrwMTKuxSDoRNW4FAojI5oD9YwUExlcyI7XNPFvRBmG1l5RfP yFtg== X-Gm-Message-State: AOAM5312cjwviH9csBpL4JnAeI4bZOmWM0fj94alyhwGYxUCGkHjmF45 APIGRXukQL0LPvfZEwWwiGSu7nL2HZJaGZMfZvy58A== X-Google-Smtp-Source: ABdhPJwOBnuO9cyF8OBviJSYN7tjfT+V3IKi0eKLRcwtLf+HGoO48XKeVyIURCRqP1SfZkP8A4tRfzpBVnepdhLBrCI= X-Received: by 2002:a05:6a00:2407:b029:341:185e:8674 with SMTP id z7-20020a056a002407b0290341185e8674mr20738643pfh.42.1626867846555; Wed, 21 Jul 2021 04:44:06 -0700 (PDT) MIME-Version: 1.0 References: <20210715121209.31024-1-yong.wu@mediatek.com> <20210715121209.31024-8-yong.wu@mediatek.com> In-Reply-To: <20210715121209.31024-8-yong.wu@mediatek.com> From: Ikjoon Jang Date: Wed, 21 Jul 2021 19:43:55 +0800 Message-ID: Subject: Re: [PATCH v2 07/11] memory: mtk-smi: Add smi sub common support To: Yong Wu Cc: Krzysztof Kozlowski , Rob Herring , Matthias Brugger , Krzysztof Kozlowski , Joerg Roedel , Will Deacon , Robin Murphy , Tomasz Figa , "moderated list:ARM/Mediatek SoC support" , srv_heupstream , open list , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , "moderated list:ARM/Mediatek SoC support" , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 15, 2021 at 8:25 PM Yong Wu wrote: > > In mt8195, there are some larbs connect with the smi-sub-common, then > connect with smi-common. Not critical but I suggest to describe what is smi-sub-common. e.g. "some larbs are not directly connected to smi-common, they are connected to smi-sub-common which is a bridge(?) interface to..." > > Before we create device link between smi-larb with smi-common. If we have > sub-common, we should use device link the smi-larb and smi-sub-common, > then use device link between the smi-sub-common with smi-common. This is > for enabling clock/power automatically. > > Move the device link code to a new interface for reusing. > > There is no SW extra setting for smi-sub-common. > > Signed-off-by: Yong Wu Reviewed-by: Ikjoon Jang > --- > drivers/memory/mtk-smi.c | 75 +++++++++++++++++++++++++++------------- > 1 file changed, 51 insertions(+), 24 deletions(-) > > diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c > index e68cbb51dd12..ee49bb50f5f5 100644 > --- a/drivers/memory/mtk-smi.c > +++ b/drivers/memory/mtk-smi.c > @@ -60,7 +60,8 @@ > > enum mtk_smi_type { > MTK_SMI_GEN1, > - MTK_SMI_GEN2 > + MTK_SMI_GEN2, /* gen2 smi common */ > + MTK_SMI_GEN2_SUB_COMM, /* gen2 smi sub common */ > }; > > #define MTK_SMI_CLK_NR_MAX 4 > @@ -90,13 +91,14 @@ struct mtk_smi { > void __iomem *smi_ao_base; /* only for gen1 */ > void __iomem *base; /* only for gen2 */ > }; > + struct device *smi_common_dev; /* for sub common */ > const struct mtk_smi_common_plat *plat; > }; > > struct mtk_smi_larb { /* larb: local arbiter */ > struct mtk_smi smi; > void __iomem *base; > - struct device *smi_common_dev; > + struct device *smi_common_dev; /* common or sub-common dev */ > const struct mtk_smi_larb_gen *larb_gen; > int larbid; > u32 *mmu; > @@ -259,6 +261,38 @@ static const struct of_device_id mtk_smi_larb_of_ids[] = { > {} > }; > > +static int mtk_smi_device_link_common(struct device *dev, struct device **com_dev) > +{ > + struct platform_device *smi_com_pdev; > + struct device_node *smi_com_node; > + struct device *smi_com_dev; > + struct device_link *link; > + > + smi_com_node = of_parse_phandle(dev->of_node, "mediatek,smi", 0); > + if (!smi_com_node) > + return -EINVAL; > + > + smi_com_pdev = of_find_device_by_node(smi_com_node); > + of_node_put(smi_com_node); > + if (smi_com_pdev) { > + /* smi common is the supplier, Make sure it is ready before */ > + if (!platform_get_drvdata(smi_com_pdev)) > + return -EPROBE_DEFER; > + smi_com_dev = &smi_com_pdev->dev; > + link = device_link_add(dev, smi_com_dev, > + DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS); > + if (!link) { > + dev_err(dev, "Unable to link smi-common dev\n"); > + return -ENODEV; > + } > + *com_dev = smi_com_dev; > + } else { > + dev_err(dev, "Failed to get the smi_common device\n"); > + return -EINVAL; > + } > + return 0; > +} > + > static int mtk_smi_dts_clk_init(struct device *dev, struct mtk_smi *smi, > unsigned int clk_nr_optional, > const char * const clk_optional[]) > @@ -285,9 +319,6 @@ static int mtk_smi_larb_probe(struct platform_device *pdev) > struct mtk_smi_larb *larb; > struct resource *res; > struct device *dev = &pdev->dev; > - struct device_node *smi_node; > - struct platform_device *smi_pdev; > - struct device_link *link; > int ret; > > larb = devm_kzalloc(dev, sizeof(*larb), GFP_KERNEL); > @@ -307,26 +338,10 @@ static int mtk_smi_larb_probe(struct platform_device *pdev) > return ret; > > larb->smi.dev = dev; > - smi_node = of_parse_phandle(dev->of_node, "mediatek,smi", 0); > - if (!smi_node) > - return -EINVAL; > > - smi_pdev = of_find_device_by_node(smi_node); > - of_node_put(smi_node); > - if (smi_pdev) { > - if (!platform_get_drvdata(smi_pdev)) > - return -EPROBE_DEFER; > - larb->smi_common_dev = &smi_pdev->dev; > - link = device_link_add(dev, larb->smi_common_dev, > - DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS); > - if (!link) { > - dev_err(dev, "Unable to link smi-common dev\n"); > - return -ENODEV; > - } > - } else { > - dev_err(dev, "Failed to get the smi_common device\n"); > - return -EINVAL; > - } > + ret = mtk_smi_device_link_common(dev, &larb->smi_common_dev); > + if (ret < 0) > + return ret; > > pm_runtime_enable(dev); > platform_set_drvdata(pdev, larb); > @@ -471,6 +486,14 @@ static int mtk_smi_common_probe(struct platform_device *pdev) > if (IS_ERR(common->base)) > return PTR_ERR(common->base); > } > + > + /* link its smi-common if this is smi-sub-common */ > + if (common->plat->type == MTK_SMI_GEN2_SUB_COMM) { > + ret = mtk_smi_device_link_common(dev, &common->smi_common_dev); > + if (ret < 0) > + return ret; > + } > + > pm_runtime_enable(dev); > platform_set_drvdata(pdev, common); > return 0; > @@ -478,6 +501,10 @@ static int mtk_smi_common_probe(struct platform_device *pdev) > > static int mtk_smi_common_remove(struct platform_device *pdev) > { > + struct mtk_smi *common = dev_get_drvdata(&pdev->dev); > + > + if (common->plat->type == MTK_SMI_GEN2_SUB_COMM) > + device_link_remove(&pdev->dev, common->smi_common_dev); > pm_runtime_disable(&pdev->dev); > return 0; > } > -- > 2.18.0 > _______________________________________________ > Linux-mediatek mailing list > Linux-mediatek@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-mediatek From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 642D4C636C9 for ; Wed, 21 Jul 2021 11:44:13 +0000 (UTC) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 08AA56109F for ; Wed, 21 Jul 2021 11:44:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 08AA56109F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id C0273404E2; Wed, 21 Jul 2021 11:44:12 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4EfGaxKJ1PSd; Wed, 21 Jul 2021 11:44:11 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 651F5400C3; Wed, 21 Jul 2021 11:44:11 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3C646C001A; Wed, 21 Jul 2021 11:44:11 +0000 (UTC) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3077DC000E for ; Wed, 21 Jul 2021 11:44:10 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 1123C402CB for ; Wed, 21 Jul 2021 11:44:10 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZukD-bZUSSkU for ; Wed, 21 Jul 2021 11:44:07 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by smtp2.osuosl.org (Postfix) with ESMTPS id 3F9F2404DA for ; Wed, 21 Jul 2021 11:44:07 +0000 (UTC) Received: by mail-pg1-x52d.google.com with SMTP id s18so1598052pgg.8 for ; Wed, 21 Jul 2021 04:44:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4eOE5oXt0Te/GnUqshzOeQhr7DeyqOGjYygIrkfQGGA=; b=KdQI6LuD8Wmsu8sCpYBmVNr4uqXouJd6KbQ3iYRLn2UXIAxs+TuEUbZye6F9L7aj1V ZAgxxPSOUOm+s48Q3N1vGWUj2UI5ovvKG0zNnKpAZ+Y4nQZHgOrkuO2NxaUrVYYpljXg lyBhu/YTGUcqASeyyy69yxEUAvWHEkFO5P9HA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4eOE5oXt0Te/GnUqshzOeQhr7DeyqOGjYygIrkfQGGA=; b=Y8AVvYbXPXJUdqp6S8qf0GRRfaPBykbWy1TRJrC7VJ5hIBBXCOJCDPwZF24TlHDiLQ Sn2Le4H1jWKlmglgc/cnqgEO3s2kxQV6tuvx30HekG2P5FFg4XnxRvbsQm64oj6b90Xh 5BsRdw+GK4r4c1jwRFFH1iLsm9osNV6Mp81WHQCP+taSzitkM/NsRJ5niSzqdLPq7czf K+6UHi7B7M5EVzR+yAV2WIPKtS/5TAyiWOQuzJcmZUb4hog+FdaMPOLrsvU7Vg9k93kv /lVAdbZ5CrxD7uFAscnQQVzYhgcwKJtO/njCfaxx64RRbaLTPCNlc0cbTZ7dnCt14SPg XReg== X-Gm-Message-State: AOAM532Ss6vGlIhTGcoB9vNBnVGnEUdFy4RG7XcdQKaIE/hEoJHOBTaX +r66+aByFSZOE/a9vqdFCbKg6PYc+nZVBp8YUQSdOw== X-Google-Smtp-Source: ABdhPJwOBnuO9cyF8OBviJSYN7tjfT+V3IKi0eKLRcwtLf+HGoO48XKeVyIURCRqP1SfZkP8A4tRfzpBVnepdhLBrCI= X-Received: by 2002:a05:6a00:2407:b029:341:185e:8674 with SMTP id z7-20020a056a002407b0290341185e8674mr20738643pfh.42.1626867846555; Wed, 21 Jul 2021 04:44:06 -0700 (PDT) MIME-Version: 1.0 References: <20210715121209.31024-1-yong.wu@mediatek.com> <20210715121209.31024-8-yong.wu@mediatek.com> In-Reply-To: <20210715121209.31024-8-yong.wu@mediatek.com> From: Ikjoon Jang Date: Wed, 21 Jul 2021 19:43:55 +0800 Message-ID: Subject: Re: [PATCH v2 07/11] memory: mtk-smi: Add smi sub common support To: Yong Wu Cc: youlin.pei@mediatek.com, "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , yi.kuo@mediatek.com, srv_heupstream , Krzysztof Kozlowski , Robin Murphy , open list , Krzysztof Kozlowski , iommu@lists.linux-foundation.org, Rob Herring , "moderated list:ARM/Mediatek SoC support" , Matthias Brugger , anthony.huang@mediatek.com, ming-fan.chen@mediatek.com, anan.sun@mediatek.com, Will Deacon , "moderated list:ARM/Mediatek SoC support" X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" On Thu, Jul 15, 2021 at 8:25 PM Yong Wu wrote: > > In mt8195, there are some larbs connect with the smi-sub-common, then > connect with smi-common. Not critical but I suggest to describe what is smi-sub-common. e.g. "some larbs are not directly connected to smi-common, they are connected to smi-sub-common which is a bridge(?) interface to..." > > Before we create device link between smi-larb with smi-common. If we have > sub-common, we should use device link the smi-larb and smi-sub-common, > then use device link between the smi-sub-common with smi-common. This is > for enabling clock/power automatically. > > Move the device link code to a new interface for reusing. > > There is no SW extra setting for smi-sub-common. > > Signed-off-by: Yong Wu Reviewed-by: Ikjoon Jang > --- > drivers/memory/mtk-smi.c | 75 +++++++++++++++++++++++++++------------- > 1 file changed, 51 insertions(+), 24 deletions(-) > > diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c > index e68cbb51dd12..ee49bb50f5f5 100644 > --- a/drivers/memory/mtk-smi.c > +++ b/drivers/memory/mtk-smi.c > @@ -60,7 +60,8 @@ > > enum mtk_smi_type { > MTK_SMI_GEN1, > - MTK_SMI_GEN2 > + MTK_SMI_GEN2, /* gen2 smi common */ > + MTK_SMI_GEN2_SUB_COMM, /* gen2 smi sub common */ > }; > > #define MTK_SMI_CLK_NR_MAX 4 > @@ -90,13 +91,14 @@ struct mtk_smi { > void __iomem *smi_ao_base; /* only for gen1 */ > void __iomem *base; /* only for gen2 */ > }; > + struct device *smi_common_dev; /* for sub common */ > const struct mtk_smi_common_plat *plat; > }; > > struct mtk_smi_larb { /* larb: local arbiter */ > struct mtk_smi smi; > void __iomem *base; > - struct device *smi_common_dev; > + struct device *smi_common_dev; /* common or sub-common dev */ > const struct mtk_smi_larb_gen *larb_gen; > int larbid; > u32 *mmu; > @@ -259,6 +261,38 @@ static const struct of_device_id mtk_smi_larb_of_ids[] = { > {} > }; > > +static int mtk_smi_device_link_common(struct device *dev, struct device **com_dev) > +{ > + struct platform_device *smi_com_pdev; > + struct device_node *smi_com_node; > + struct device *smi_com_dev; > + struct device_link *link; > + > + smi_com_node = of_parse_phandle(dev->of_node, "mediatek,smi", 0); > + if (!smi_com_node) > + return -EINVAL; > + > + smi_com_pdev = of_find_device_by_node(smi_com_node); > + of_node_put(smi_com_node); > + if (smi_com_pdev) { > + /* smi common is the supplier, Make sure it is ready before */ > + if (!platform_get_drvdata(smi_com_pdev)) > + return -EPROBE_DEFER; > + smi_com_dev = &smi_com_pdev->dev; > + link = device_link_add(dev, smi_com_dev, > + DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS); > + if (!link) { > + dev_err(dev, "Unable to link smi-common dev\n"); > + return -ENODEV; > + } > + *com_dev = smi_com_dev; > + } else { > + dev_err(dev, "Failed to get the smi_common device\n"); > + return -EINVAL; > + } > + return 0; > +} > + > static int mtk_smi_dts_clk_init(struct device *dev, struct mtk_smi *smi, > unsigned int clk_nr_optional, > const char * const clk_optional[]) > @@ -285,9 +319,6 @@ static int mtk_smi_larb_probe(struct platform_device *pdev) > struct mtk_smi_larb *larb; > struct resource *res; > struct device *dev = &pdev->dev; > - struct device_node *smi_node; > - struct platform_device *smi_pdev; > - struct device_link *link; > int ret; > > larb = devm_kzalloc(dev, sizeof(*larb), GFP_KERNEL); > @@ -307,26 +338,10 @@ static int mtk_smi_larb_probe(struct platform_device *pdev) > return ret; > > larb->smi.dev = dev; > - smi_node = of_parse_phandle(dev->of_node, "mediatek,smi", 0); > - if (!smi_node) > - return -EINVAL; > > - smi_pdev = of_find_device_by_node(smi_node); > - of_node_put(smi_node); > - if (smi_pdev) { > - if (!platform_get_drvdata(smi_pdev)) > - return -EPROBE_DEFER; > - larb->smi_common_dev = &smi_pdev->dev; > - link = device_link_add(dev, larb->smi_common_dev, > - DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS); > - if (!link) { > - dev_err(dev, "Unable to link smi-common dev\n"); > - return -ENODEV; > - } > - } else { > - dev_err(dev, "Failed to get the smi_common device\n"); > - return -EINVAL; > - } > + ret = mtk_smi_device_link_common(dev, &larb->smi_common_dev); > + if (ret < 0) > + return ret; > > pm_runtime_enable(dev); > platform_set_drvdata(pdev, larb); > @@ -471,6 +486,14 @@ static int mtk_smi_common_probe(struct platform_device *pdev) > if (IS_ERR(common->base)) > return PTR_ERR(common->base); > } > + > + /* link its smi-common if this is smi-sub-common */ > + if (common->plat->type == MTK_SMI_GEN2_SUB_COMM) { > + ret = mtk_smi_device_link_common(dev, &common->smi_common_dev); > + if (ret < 0) > + return ret; > + } > + > pm_runtime_enable(dev); > platform_set_drvdata(pdev, common); > return 0; > @@ -478,6 +501,10 @@ static int mtk_smi_common_probe(struct platform_device *pdev) > > static int mtk_smi_common_remove(struct platform_device *pdev) > { > + struct mtk_smi *common = dev_get_drvdata(&pdev->dev); > + > + if (common->plat->type == MTK_SMI_GEN2_SUB_COMM) > + device_link_remove(&pdev->dev, common->smi_common_dev); > pm_runtime_disable(&pdev->dev); > return 0; > } > -- > 2.18.0 > _______________________________________________ > Linux-mediatek mailing list > Linux-mediatek@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-mediatek _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9683C636C9 for ; Wed, 21 Jul 2021 11:44:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A5E206113C for ; Wed, 21 Jul 2021 11:44:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A5E206113C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dPkh4MJdOv6wCa0/u5b6iD03Uhyk3hS7p8EqjzjhTts=; b=u10GxY4afPxr2k rvMz4mJLClS0J8KrxHGHMAlXTiHPFt+sU5O6g97MaHi6wE48MtlMW3mp4l1/jH/2kGFsTtb4r9Wvy maL11V19U2j/h17fQquTRrvq20u9K992JzpQ0zND9AZng66nv83Xrd8EMz32GwfKN5H4PFrxRSN74 BSB65edZLKQYVQokj8rqBaoHBgx6IqpxIqf8ouAzSOcX9zvPfvhrfjwoJ+fgxlI0ITUt3UgoIqdmz 18sz9V/EwWX4+i3SzWwP0DWE2KrwqVcPs4ISTTfZhP16EsOunLI3x6sptjPWbLr26tM9pwxK7I3UY 8iqTuOhOC5YYcOlI8etQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6AeR-00FUaB-G7; Wed, 21 Jul 2021 11:44:35 +0000 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6Adz-00FUQQ-O0 for linux-mediatek@lists.infradead.org; Wed, 21 Jul 2021 11:44:09 +0000 Received: by mail-pg1-x536.google.com with SMTP id a6so1624275pgw.3 for ; Wed, 21 Jul 2021 04:44:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4eOE5oXt0Te/GnUqshzOeQhr7DeyqOGjYygIrkfQGGA=; b=KdQI6LuD8Wmsu8sCpYBmVNr4uqXouJd6KbQ3iYRLn2UXIAxs+TuEUbZye6F9L7aj1V ZAgxxPSOUOm+s48Q3N1vGWUj2UI5ovvKG0zNnKpAZ+Y4nQZHgOrkuO2NxaUrVYYpljXg lyBhu/YTGUcqASeyyy69yxEUAvWHEkFO5P9HA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4eOE5oXt0Te/GnUqshzOeQhr7DeyqOGjYygIrkfQGGA=; b=s9P9toOqx99PQwKPurhnQqZbRcNCKPrwwAEWHKFaSjo5EZ+lvGA0815qfi+nyIHkVF X5zuiBgynq6H6/Mf6Pv7GVsYTIiD2B8HcKBXoyCmod8OQmIZE3KnxBXWZCYVGiQ4YMgX Iyyk3s52YalHUGN3m/xF5efcABCwogKdIbbcYuVQq2GQGAY2oc2wM7FkwPKp4MzmZ2LE hIuLO1D4QKB1BmD0pREVeGRaVp6nuaG7upeKTrmyeH542By+8RbeCEViAq9gaWETz5f4 rxh9EX6dLFJ7fr0PPzKcxmFgr2J80zSbu9PtpLZ28kXwj5ibTqP2v0/bRlujRij/S4ES XCMw== X-Gm-Message-State: AOAM533/wURzDEPF2pV6DHNAGaVYMQuQKH0yJVe4MCPlUwBUArj9m9nk x82iYA6q+Wmjniz9IhdF5EUQvT890xWT/mPVl3Y15Q== X-Google-Smtp-Source: ABdhPJwOBnuO9cyF8OBviJSYN7tjfT+V3IKi0eKLRcwtLf+HGoO48XKeVyIURCRqP1SfZkP8A4tRfzpBVnepdhLBrCI= X-Received: by 2002:a05:6a00:2407:b029:341:185e:8674 with SMTP id z7-20020a056a002407b0290341185e8674mr20738643pfh.42.1626867846555; Wed, 21 Jul 2021 04:44:06 -0700 (PDT) MIME-Version: 1.0 References: <20210715121209.31024-1-yong.wu@mediatek.com> <20210715121209.31024-8-yong.wu@mediatek.com> In-Reply-To: <20210715121209.31024-8-yong.wu@mediatek.com> From: Ikjoon Jang Date: Wed, 21 Jul 2021 19:43:55 +0800 Message-ID: Subject: Re: [PATCH v2 07/11] memory: mtk-smi: Add smi sub common support To: Yong Wu Cc: Krzysztof Kozlowski , Rob Herring , Matthias Brugger , Krzysztof Kozlowski , Joerg Roedel , Will Deacon , Robin Murphy , Tomasz Figa , "moderated list:ARM/Mediatek SoC support" , srv_heupstream , open list , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , "moderated list:ARM/Mediatek SoC support" , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210721_044407_835452_48A096D6 X-CRM114-Status: GOOD ( 36.38 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org On Thu, Jul 15, 2021 at 8:25 PM Yong Wu wrote: > > In mt8195, there are some larbs connect with the smi-sub-common, then > connect with smi-common. Not critical but I suggest to describe what is smi-sub-common. e.g. "some larbs are not directly connected to smi-common, they are connected to smi-sub-common which is a bridge(?) interface to..." > > Before we create device link between smi-larb with smi-common. If we have > sub-common, we should use device link the smi-larb and smi-sub-common, > then use device link between the smi-sub-common with smi-common. This is > for enabling clock/power automatically. > > Move the device link code to a new interface for reusing. > > There is no SW extra setting for smi-sub-common. > > Signed-off-by: Yong Wu Reviewed-by: Ikjoon Jang > --- > drivers/memory/mtk-smi.c | 75 +++++++++++++++++++++++++++------------- > 1 file changed, 51 insertions(+), 24 deletions(-) > > diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c > index e68cbb51dd12..ee49bb50f5f5 100644 > --- a/drivers/memory/mtk-smi.c > +++ b/drivers/memory/mtk-smi.c > @@ -60,7 +60,8 @@ > > enum mtk_smi_type { > MTK_SMI_GEN1, > - MTK_SMI_GEN2 > + MTK_SMI_GEN2, /* gen2 smi common */ > + MTK_SMI_GEN2_SUB_COMM, /* gen2 smi sub common */ > }; > > #define MTK_SMI_CLK_NR_MAX 4 > @@ -90,13 +91,14 @@ struct mtk_smi { > void __iomem *smi_ao_base; /* only for gen1 */ > void __iomem *base; /* only for gen2 */ > }; > + struct device *smi_common_dev; /* for sub common */ > const struct mtk_smi_common_plat *plat; > }; > > struct mtk_smi_larb { /* larb: local arbiter */ > struct mtk_smi smi; > void __iomem *base; > - struct device *smi_common_dev; > + struct device *smi_common_dev; /* common or sub-common dev */ > const struct mtk_smi_larb_gen *larb_gen; > int larbid; > u32 *mmu; > @@ -259,6 +261,38 @@ static const struct of_device_id mtk_smi_larb_of_ids[] = { > {} > }; > > +static int mtk_smi_device_link_common(struct device *dev, struct device **com_dev) > +{ > + struct platform_device *smi_com_pdev; > + struct device_node *smi_com_node; > + struct device *smi_com_dev; > + struct device_link *link; > + > + smi_com_node = of_parse_phandle(dev->of_node, "mediatek,smi", 0); > + if (!smi_com_node) > + return -EINVAL; > + > + smi_com_pdev = of_find_device_by_node(smi_com_node); > + of_node_put(smi_com_node); > + if (smi_com_pdev) { > + /* smi common is the supplier, Make sure it is ready before */ > + if (!platform_get_drvdata(smi_com_pdev)) > + return -EPROBE_DEFER; > + smi_com_dev = &smi_com_pdev->dev; > + link = device_link_add(dev, smi_com_dev, > + DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS); > + if (!link) { > + dev_err(dev, "Unable to link smi-common dev\n"); > + return -ENODEV; > + } > + *com_dev = smi_com_dev; > + } else { > + dev_err(dev, "Failed to get the smi_common device\n"); > + return -EINVAL; > + } > + return 0; > +} > + > static int mtk_smi_dts_clk_init(struct device *dev, struct mtk_smi *smi, > unsigned int clk_nr_optional, > const char * const clk_optional[]) > @@ -285,9 +319,6 @@ static int mtk_smi_larb_probe(struct platform_device *pdev) > struct mtk_smi_larb *larb; > struct resource *res; > struct device *dev = &pdev->dev; > - struct device_node *smi_node; > - struct platform_device *smi_pdev; > - struct device_link *link; > int ret; > > larb = devm_kzalloc(dev, sizeof(*larb), GFP_KERNEL); > @@ -307,26 +338,10 @@ static int mtk_smi_larb_probe(struct platform_device *pdev) > return ret; > > larb->smi.dev = dev; > - smi_node = of_parse_phandle(dev->of_node, "mediatek,smi", 0); > - if (!smi_node) > - return -EINVAL; > > - smi_pdev = of_find_device_by_node(smi_node); > - of_node_put(smi_node); > - if (smi_pdev) { > - if (!platform_get_drvdata(smi_pdev)) > - return -EPROBE_DEFER; > - larb->smi_common_dev = &smi_pdev->dev; > - link = device_link_add(dev, larb->smi_common_dev, > - DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS); > - if (!link) { > - dev_err(dev, "Unable to link smi-common dev\n"); > - return -ENODEV; > - } > - } else { > - dev_err(dev, "Failed to get the smi_common device\n"); > - return -EINVAL; > - } > + ret = mtk_smi_device_link_common(dev, &larb->smi_common_dev); > + if (ret < 0) > + return ret; > > pm_runtime_enable(dev); > platform_set_drvdata(pdev, larb); > @@ -471,6 +486,14 @@ static int mtk_smi_common_probe(struct platform_device *pdev) > if (IS_ERR(common->base)) > return PTR_ERR(common->base); > } > + > + /* link its smi-common if this is smi-sub-common */ > + if (common->plat->type == MTK_SMI_GEN2_SUB_COMM) { > + ret = mtk_smi_device_link_common(dev, &common->smi_common_dev); > + if (ret < 0) > + return ret; > + } > + > pm_runtime_enable(dev); > platform_set_drvdata(pdev, common); > return 0; > @@ -478,6 +501,10 @@ static int mtk_smi_common_probe(struct platform_device *pdev) > > static int mtk_smi_common_remove(struct platform_device *pdev) > { > + struct mtk_smi *common = dev_get_drvdata(&pdev->dev); > + > + if (common->plat->type == MTK_SMI_GEN2_SUB_COMM) > + device_link_remove(&pdev->dev, common->smi_common_dev); > pm_runtime_disable(&pdev->dev); > return 0; > } > -- > 2.18.0 > _______________________________________________ > Linux-mediatek mailing list > Linux-mediatek@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-mediatek _______________________________________________ Linux-mediatek mailing list Linux-mediatek@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-mediatek From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E0F5C636CA for ; Wed, 21 Jul 2021 11:46:01 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 50178610D2 for ; Wed, 21 Jul 2021 11:46:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 50178610D2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vGJucQKA/XtQ8FICVmyXg7ubk6T/QFMmaWGNqdObKfE=; b=WgZein78YX8FzL OOQ92WjCvdam0tPaiOQwWqTda2W43H2s686vz5WsB4OjF4LAdRFl9+VK4KWNdqGjQFcH67v2a2zKd SGxfNiKlHAaW8fKr43lE5rnrarCZcy1rD9nd6vcsbwhCRMWRXXoGtNN9RR/O8U4/4ngxgRzDG8RFI /YsxkTyBoz0lLXqc6p07ZQ1BcJMgc6UjYaJi3WnQnpUFr/hj53QveSNIXoS03gic7oTl5y/TzGlTa 5+kbk2j+kKRpJPvzLBLq/Atz3FC3E61eN7p3As9lkvmGt4uKRpITwfge8HE9D6u2jkFM0Pj9sVk8W wsXz9yAeAPA2FmNtbijA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6Ae5-00FUSO-JL; Wed, 21 Jul 2021 11:44:14 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6Adz-00FUQP-N3 for linux-arm-kernel@lists.infradead.org; Wed, 21 Jul 2021 11:44:09 +0000 Received: by mail-pg1-x52d.google.com with SMTP id y17so1582943pgf.12 for ; Wed, 21 Jul 2021 04:44:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4eOE5oXt0Te/GnUqshzOeQhr7DeyqOGjYygIrkfQGGA=; b=KdQI6LuD8Wmsu8sCpYBmVNr4uqXouJd6KbQ3iYRLn2UXIAxs+TuEUbZye6F9L7aj1V ZAgxxPSOUOm+s48Q3N1vGWUj2UI5ovvKG0zNnKpAZ+Y4nQZHgOrkuO2NxaUrVYYpljXg lyBhu/YTGUcqASeyyy69yxEUAvWHEkFO5P9HA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4eOE5oXt0Te/GnUqshzOeQhr7DeyqOGjYygIrkfQGGA=; b=mUGKIRg/z2tVVW6ndO94602v6SV71fS0aZX2QWlTbYy7fvPKpr5t7QmPdCQg0FLhpQ ASBeDaaWyYyhsnDuAtgC6LV6X0WJ7/JcHWKiNIm8fBF4k37X86bis/o/QntDwVlybG4u en+ovBlNp6JQCEXHK7rH1SLUFGWsFO9i2tJiu8SXWvkEi9HmNgV1AAmT7MGxq1D5ktOa wU3xVbBa4aPt5t2hbOH7hSh643SiHZ08L2FlZhIMFxDJ/EzZ5oeseK18pEIvB/P7F/l9 3zRWhMmXXH/+n3ZE9NB5D/Baxalp7n9ZBp9aNQntVAh+JEc1uMxNQ1a/J9msRwNZu/Ff J2nA== X-Gm-Message-State: AOAM532uLBmOnsxic5Vs/GNdkjmVSR1DxnxaoaiRxV0ydmRO8wACE1Jr eXmfi3m2DSOpYxVMGHHo3xIF30UoS/TDwD7rXpgdcA== X-Google-Smtp-Source: ABdhPJwOBnuO9cyF8OBviJSYN7tjfT+V3IKi0eKLRcwtLf+HGoO48XKeVyIURCRqP1SfZkP8A4tRfzpBVnepdhLBrCI= X-Received: by 2002:a05:6a00:2407:b029:341:185e:8674 with SMTP id z7-20020a056a002407b0290341185e8674mr20738643pfh.42.1626867846555; Wed, 21 Jul 2021 04:44:06 -0700 (PDT) MIME-Version: 1.0 References: <20210715121209.31024-1-yong.wu@mediatek.com> <20210715121209.31024-8-yong.wu@mediatek.com> In-Reply-To: <20210715121209.31024-8-yong.wu@mediatek.com> From: Ikjoon Jang Date: Wed, 21 Jul 2021 19:43:55 +0800 Message-ID: Subject: Re: [PATCH v2 07/11] memory: mtk-smi: Add smi sub common support To: Yong Wu Cc: Krzysztof Kozlowski , Rob Herring , Matthias Brugger , Krzysztof Kozlowski , Joerg Roedel , Will Deacon , Robin Murphy , Tomasz Figa , "moderated list:ARM/Mediatek SoC support" , srv_heupstream , open list , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , "moderated list:ARM/Mediatek SoC support" , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210721_044407_814686_8FDD62F6 X-CRM114-Status: GOOD ( 37.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Jul 15, 2021 at 8:25 PM Yong Wu wrote: > > In mt8195, there are some larbs connect with the smi-sub-common, then > connect with smi-common. Not critical but I suggest to describe what is smi-sub-common. e.g. "some larbs are not directly connected to smi-common, they are connected to smi-sub-common which is a bridge(?) interface to..." > > Before we create device link between smi-larb with smi-common. If we have > sub-common, we should use device link the smi-larb and smi-sub-common, > then use device link between the smi-sub-common with smi-common. This is > for enabling clock/power automatically. > > Move the device link code to a new interface for reusing. > > There is no SW extra setting for smi-sub-common. > > Signed-off-by: Yong Wu Reviewed-by: Ikjoon Jang > --- > drivers/memory/mtk-smi.c | 75 +++++++++++++++++++++++++++------------- > 1 file changed, 51 insertions(+), 24 deletions(-) > > diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c > index e68cbb51dd12..ee49bb50f5f5 100644 > --- a/drivers/memory/mtk-smi.c > +++ b/drivers/memory/mtk-smi.c > @@ -60,7 +60,8 @@ > > enum mtk_smi_type { > MTK_SMI_GEN1, > - MTK_SMI_GEN2 > + MTK_SMI_GEN2, /* gen2 smi common */ > + MTK_SMI_GEN2_SUB_COMM, /* gen2 smi sub common */ > }; > > #define MTK_SMI_CLK_NR_MAX 4 > @@ -90,13 +91,14 @@ struct mtk_smi { > void __iomem *smi_ao_base; /* only for gen1 */ > void __iomem *base; /* only for gen2 */ > }; > + struct device *smi_common_dev; /* for sub common */ > const struct mtk_smi_common_plat *plat; > }; > > struct mtk_smi_larb { /* larb: local arbiter */ > struct mtk_smi smi; > void __iomem *base; > - struct device *smi_common_dev; > + struct device *smi_common_dev; /* common or sub-common dev */ > const struct mtk_smi_larb_gen *larb_gen; > int larbid; > u32 *mmu; > @@ -259,6 +261,38 @@ static const struct of_device_id mtk_smi_larb_of_ids[] = { > {} > }; > > +static int mtk_smi_device_link_common(struct device *dev, struct device **com_dev) > +{ > + struct platform_device *smi_com_pdev; > + struct device_node *smi_com_node; > + struct device *smi_com_dev; > + struct device_link *link; > + > + smi_com_node = of_parse_phandle(dev->of_node, "mediatek,smi", 0); > + if (!smi_com_node) > + return -EINVAL; > + > + smi_com_pdev = of_find_device_by_node(smi_com_node); > + of_node_put(smi_com_node); > + if (smi_com_pdev) { > + /* smi common is the supplier, Make sure it is ready before */ > + if (!platform_get_drvdata(smi_com_pdev)) > + return -EPROBE_DEFER; > + smi_com_dev = &smi_com_pdev->dev; > + link = device_link_add(dev, smi_com_dev, > + DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS); > + if (!link) { > + dev_err(dev, "Unable to link smi-common dev\n"); > + return -ENODEV; > + } > + *com_dev = smi_com_dev; > + } else { > + dev_err(dev, "Failed to get the smi_common device\n"); > + return -EINVAL; > + } > + return 0; > +} > + > static int mtk_smi_dts_clk_init(struct device *dev, struct mtk_smi *smi, > unsigned int clk_nr_optional, > const char * const clk_optional[]) > @@ -285,9 +319,6 @@ static int mtk_smi_larb_probe(struct platform_device *pdev) > struct mtk_smi_larb *larb; > struct resource *res; > struct device *dev = &pdev->dev; > - struct device_node *smi_node; > - struct platform_device *smi_pdev; > - struct device_link *link; > int ret; > > larb = devm_kzalloc(dev, sizeof(*larb), GFP_KERNEL); > @@ -307,26 +338,10 @@ static int mtk_smi_larb_probe(struct platform_device *pdev) > return ret; > > larb->smi.dev = dev; > - smi_node = of_parse_phandle(dev->of_node, "mediatek,smi", 0); > - if (!smi_node) > - return -EINVAL; > > - smi_pdev = of_find_device_by_node(smi_node); > - of_node_put(smi_node); > - if (smi_pdev) { > - if (!platform_get_drvdata(smi_pdev)) > - return -EPROBE_DEFER; > - larb->smi_common_dev = &smi_pdev->dev; > - link = device_link_add(dev, larb->smi_common_dev, > - DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS); > - if (!link) { > - dev_err(dev, "Unable to link smi-common dev\n"); > - return -ENODEV; > - } > - } else { > - dev_err(dev, "Failed to get the smi_common device\n"); > - return -EINVAL; > - } > + ret = mtk_smi_device_link_common(dev, &larb->smi_common_dev); > + if (ret < 0) > + return ret; > > pm_runtime_enable(dev); > platform_set_drvdata(pdev, larb); > @@ -471,6 +486,14 @@ static int mtk_smi_common_probe(struct platform_device *pdev) > if (IS_ERR(common->base)) > return PTR_ERR(common->base); > } > + > + /* link its smi-common if this is smi-sub-common */ > + if (common->plat->type == MTK_SMI_GEN2_SUB_COMM) { > + ret = mtk_smi_device_link_common(dev, &common->smi_common_dev); > + if (ret < 0) > + return ret; > + } > + > pm_runtime_enable(dev); > platform_set_drvdata(pdev, common); > return 0; > @@ -478,6 +501,10 @@ static int mtk_smi_common_probe(struct platform_device *pdev) > > static int mtk_smi_common_remove(struct platform_device *pdev) > { > + struct mtk_smi *common = dev_get_drvdata(&pdev->dev); > + > + if (common->plat->type == MTK_SMI_GEN2_SUB_COMM) > + device_link_remove(&pdev->dev, common->smi_common_dev); > pm_runtime_disable(&pdev->dev); > return 0; > } > -- > 2.18.0 > _______________________________________________ > Linux-mediatek mailing list > Linux-mediatek@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-mediatek _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel