diff mbox series

[05/13] memory: mtk-smi: Add device-link between smi-larb and smi-common

Message ID 1546318276-18993-6-git-send-email-yong.wu@mediatek.com (mailing list archive)
State New, archived
Headers show
Series Clean up "mediatek,larb" after adding device_link | expand

Commit Message

Yong Wu (吴勇) Jan. 1, 2019, 4:51 a.m. UTC
Normally, If the smi-larb HW need work, we should enable the smi-common
HW power and clock firstly.
This patch adds device-link between the smi-larb dev and the smi-common
dev. then If pm_runtime_get_sync(smi-larb-dev), the pm_runtime_get_sync
(smi-common-dev) will be called automatically.

Since smi is built-in driver like IOMMU and never unbound,
DL_FLAG_AUTOREMOVE_* is not needed.

CC: Matthias Brugger <matthias.bgg@gmail.com>
Suggested-by: Tomasz Figa <tfiga@chromium.org>
Signed-off-by: Yong Wu <yong.wu@mediatek.com>
---
 drivers/memory/mtk-smi.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

Comments

Evan Green Feb. 25, 2019, 11:54 p.m. UTC | #1
On Mon, Dec 31, 2018 at 8:52 PM Yong Wu <yong.wu@mediatek.com> wrote:
>
> Normally, If the smi-larb HW need work, we should enable the smi-common
> HW power and clock firstly.
> This patch adds device-link between the smi-larb dev and the smi-common
> dev. then If pm_runtime_get_sync(smi-larb-dev), the pm_runtime_get_sync
> (smi-common-dev) will be called automatically.
>
> Since smi is built-in driver like IOMMU and never unbound,
> DL_FLAG_AUTOREMOVE_* is not needed.
>
> CC: Matthias Brugger <matthias.bgg@gmail.com>
> Suggested-by: Tomasz Figa <tfiga@chromium.org>
> Signed-off-by: Yong Wu <yong.wu@mediatek.com>
> ---
>  drivers/memory/mtk-smi.c | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c
> index 9688341..30930e4 100644
> --- a/drivers/memory/mtk-smi.c
> +++ b/drivers/memory/mtk-smi.c
> @@ -271,6 +271,7 @@ static int mtk_smi_larb_probe(struct platform_device *pdev)
>         struct device *dev = &pdev->dev;
>         struct device_node *smi_node;
>         struct platform_device *smi_pdev;
> +       struct device_link *link;
>
>         larb = devm_kzalloc(dev, sizeof(*larb), GFP_KERNEL);
>         if (!larb)
> @@ -310,6 +311,12 @@ static int mtk_smi_larb_probe(struct platform_device *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);

Doesn't this need to be torn down in remove()? You mention that it's
built-in and never removed, but it does seem to have a remove()
function that tears down everything else, so it seemed a shame to
start leaking now. Maybe the AUTOREMOVE flag would do it.
Yong Wu (吴勇) Feb. 27, 2019, 2:33 p.m. UTC | #2
On Mon, 2019-02-25 at 15:54 -0800, Evan Green wrote:
> On Mon, Dec 31, 2018 at 8:52 PM Yong Wu <yong.wu@mediatek.com> wrote:
> >
> > Normally, If the smi-larb HW need work, we should enable the smi-common
> > HW power and clock firstly.
> > This patch adds device-link between the smi-larb dev and the smi-common
> > dev. then If pm_runtime_get_sync(smi-larb-dev), the pm_runtime_get_sync
> > (smi-common-dev) will be called automatically.
> >
> > Since smi is built-in driver like IOMMU and never unbound,
> > DL_FLAG_AUTOREMOVE_* is not needed.
> >
> > CC: Matthias Brugger <matthias.bgg@gmail.com>
> > Suggested-by: Tomasz Figa <tfiga@chromium.org>
> > Signed-off-by: Yong Wu <yong.wu@mediatek.com>
> > ---
> >  drivers/memory/mtk-smi.c | 16 +++++++---------
> >  1 file changed, 7 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c
> > index 9688341..30930e4 100644
> > --- a/drivers/memory/mtk-smi.c
> > +++ b/drivers/memory/mtk-smi.c
> > @@ -271,6 +271,7 @@ static int mtk_smi_larb_probe(struct platform_device *pdev)
> >         struct device *dev = &pdev->dev;
> >         struct device_node *smi_node;
> >         struct platform_device *smi_pdev;
> > +       struct device_link *link;
> >
> >         larb = devm_kzalloc(dev, sizeof(*larb), GFP_KERNEL);
> >         if (!larb)
> > @@ -310,6 +311,12 @@ static int mtk_smi_larb_probe(struct platform_device *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);
> 
> Doesn't this need to be torn down in remove()? You mention that it's
> built-in and never removed, but it does seem to have a remove()

The MTK IOMMU driver need depend on this SMI driver. the IOMMU is a
builtin driver, thus the SMI also should be a builtin driver.

Technically, If the driver is builtin, then the "remove" function can be
removed? If yes, I could use a new patch do it.

It looks the MACRO(builtin_platform_driver) only support one driver, but
we have two driver(smi-common and smi-larb) here.

> function that tears down everything else, so it seemed a shame to
> start leaking now. Maybe the AUTOREMOVE flag would do it.
Evan Green March 5, 2019, 7:02 p.m. UTC | #3
On Wed, Feb 27, 2019 at 6:33 AM Yong Wu <yong.wu@mediatek.com> wrote:
>
> On Mon, 2019-02-25 at 15:54 -0800, Evan Green wrote:
> > On Mon, Dec 31, 2018 at 8:52 PM Yong Wu <yong.wu@mediatek.com> wrote:
> > >
> > > Normally, If the smi-larb HW need work, we should enable the smi-common
> > > HW power and clock firstly.
> > > This patch adds device-link between the smi-larb dev and the smi-common
> > > dev. then If pm_runtime_get_sync(smi-larb-dev), the pm_runtime_get_sync
> > > (smi-common-dev) will be called automatically.
> > >
> > > Since smi is built-in driver like IOMMU and never unbound,
> > > DL_FLAG_AUTOREMOVE_* is not needed.
> > >
> > > CC: Matthias Brugger <matthias.bgg@gmail.com>
> > > Suggested-by: Tomasz Figa <tfiga@chromium.org>
> > > Signed-off-by: Yong Wu <yong.wu@mediatek.com>
> > > ---
> > >  drivers/memory/mtk-smi.c | 16 +++++++---------
> > >  1 file changed, 7 insertions(+), 9 deletions(-)
> > >
> > > diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c
> > > index 9688341..30930e4 100644
> > > --- a/drivers/memory/mtk-smi.c
> > > +++ b/drivers/memory/mtk-smi.c
> > > @@ -271,6 +271,7 @@ static int mtk_smi_larb_probe(struct platform_device *pdev)
> > >         struct device *dev = &pdev->dev;
> > >         struct device_node *smi_node;
> > >         struct platform_device *smi_pdev;
> > > +       struct device_link *link;
> > >
> > >         larb = devm_kzalloc(dev, sizeof(*larb), GFP_KERNEL);
> > >         if (!larb)
> > > @@ -310,6 +311,12 @@ static int mtk_smi_larb_probe(struct platform_device *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);
> >
> > Doesn't this need to be torn down in remove()? You mention that it's
> > built-in and never removed, but it does seem to have a remove()
>
> The MTK IOMMU driver need depend on this SMI driver. the IOMMU is a
> builtin driver, thus the SMI also should be a builtin driver.
>
> Technically, If the driver is builtin, then the "remove" function can be
> removed? If yes, I could use a new patch do it.

Yeah, I guess so. It's always sad to see cleanup code getting removed,
but it makes sense to me.


>
> It looks the MACRO(builtin_platform_driver) only support one driver, but
> we have two driver(smi-common and smi-larb) here.
>
> > function that tears down everything else, so it seemed a shame to
> > start leaking now. Maybe the AUTOREMOVE flag would do it.
>
>
diff mbox series

Patch

diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c
index 9688341..30930e4 100644
--- a/drivers/memory/mtk-smi.c
+++ b/drivers/memory/mtk-smi.c
@@ -271,6 +271,7 @@  static int mtk_smi_larb_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct device_node *smi_node;
 	struct platform_device *smi_pdev;
+	struct device_link *link;
 
 	larb = devm_kzalloc(dev, sizeof(*larb), GFP_KERNEL);
 	if (!larb)
@@ -310,6 +311,12 @@  static int mtk_smi_larb_probe(struct platform_device *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);
+		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;
@@ -333,17 +340,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;
 
-	/* Power on smi-common. */
-	ret = pm_runtime_get_sync(larb->smi_common_dev);
-	if (ret < 0) {
-		dev_err(dev, "Failed to pm get for smi-common(%d).\n", ret);
-		return ret;
-	}
-
 	ret = mtk_smi_clk_enable(&larb->smi);
 	if (ret < 0) {
 		dev_err(dev, "Failed to enable clock(%d).\n", ret);
-		pm_runtime_put_sync(larb->smi_common_dev);
 		return ret;
 	}
 
@@ -358,7 +357,6 @@  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);
-	pm_runtime_put_sync(larb->smi_common_dev);
 	return 0;
 }