All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] clk: mvebu: armada-37xx-periph: save the IP base address in the driver data
@ 2018-04-21 14:23 Miquel Raynal
  2018-04-21 14:23 ` [PATCH 2/2] clk: mvebu: armada-37xx-periph: add suspend/resume support Miquel Raynal
  0 siblings, 1 reply; 6+ messages in thread
From: Miquel Raynal @ 2018-04-21 14:23 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd
  Cc: Thomas Petazzoni, Antoine Tenart, Gregory Clement,
	Maxime Chevallier, Nadav Haklai, linux-clk, linux-pm,
	Miquel Raynal

Prepare the introduction of suspend/resume hooks by having an easy way
to access all the registers in one go just from a device: add the IP
base address in the driver data.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/clk/mvebu/armada-37xx-periph.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mvebu/armada-37xx-periph.c
index 87213ea7fc84..723bb7f6cea1 100644
--- a/drivers/clk/mvebu/armada-37xx-periph.c
+++ b/drivers/clk/mvebu/armada-37xx-periph.c
@@ -58,6 +58,7 @@
 struct clk_periph_driver_data {
 	struct clk_hw_onecell_data *hw_data;
 	spinlock_t lock;
+	void __iomem *reg;
 };
 
 struct clk_double_div {
@@ -649,7 +650,6 @@ static int armada_3700_periph_clock_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	int num_periph = 0, i, ret;
 	struct resource *res;
-	void __iomem *reg;
 
 	data = of_device_get_match_data(dev);
 	if (!data)
@@ -658,11 +658,6 @@ static int armada_3700_periph_clock_probe(struct platform_device *pdev)
 	while (data[num_periph].name)
 		num_periph++;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	reg = devm_ioremap_resource(dev, res);
-	if (IS_ERR(reg))
-		return PTR_ERR(reg);
-
 	driver_data = devm_kzalloc(dev, sizeof(*driver_data), GFP_KERNEL);
 	if (!driver_data)
 		return -ENOMEM;
@@ -674,12 +669,16 @@ static int armada_3700_periph_clock_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	driver_data->hw_data->num = num_periph;
 
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	driver_data->reg = devm_ioremap_resource(dev, res);
+	if (IS_ERR(driver_data->reg))
+		return PTR_ERR(driver_data->reg);
+
 	spin_lock_init(&driver_data->lock);
 
 	for (i = 0; i < num_periph; i++) {
 		struct clk_hw **hw = &driver_data->hw_data->hws[i];
-
-		if (armada_3700_add_composite_clk(&data[i], reg,
+		if (armada_3700_add_composite_clk(&data[i], driver_data->reg,
 						  &driver_data->lock, dev, hw))
 			dev_err(dev, "Can't register periph clock %s\n",
 				data[i].name);
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] clk: mvebu: armada-37xx-periph: add suspend/resume support
  2018-04-21 14:23 [PATCH 1/2] clk: mvebu: armada-37xx-periph: save the IP base address in the driver data Miquel Raynal
@ 2018-04-21 14:23 ` Miquel Raynal
  2018-05-02 16:18   ` Gregory CLEMENT
  0 siblings, 1 reply; 6+ messages in thread
From: Miquel Raynal @ 2018-04-21 14:23 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd
  Cc: Thomas Petazzoni, Antoine Tenart, Gregory Clement,
	Maxime Chevallier, Nadav Haklai, linux-clk, linux-pm,
	Miquel Raynal

Add suspend/resume hooks in Armada 37xx peripheral clocks driver to
handle S2RAM operations.

One can think that these hooks are useless by comparing the register
values before and after a suspend/resume cycle: they will look the same
anyway. This is because of some scripts executed by the Cortex-M3 core
during ATF operations to init both the clocks and the DDR. These values
could be modified by the BL33 stage or by Linux itself and should be
preserved.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/clk/mvebu/armada-37xx-periph.c | 48 ++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mvebu/armada-37xx-periph.c
index 723bb7f6cea1..cd560bdcb8a9 100644
--- a/drivers/clk/mvebu/armada-37xx-periph.c
+++ b/drivers/clk/mvebu/armada-37xx-periph.c
@@ -59,6 +59,15 @@ struct clk_periph_driver_data {
 	struct clk_hw_onecell_data *hw_data;
 	spinlock_t lock;
 	void __iomem *reg;
+#if defined(CONFIG_PM)
+	/* Storage registers for suspend/resume operations */
+	u32 tbg_sel;
+	u32 div_sel0;
+	u32 div_sel1;
+	u32 div_sel2;
+	u32 clk_sel;
+	u32 clk_dis;
+#endif /* CONFIG_PM */
 };
 
 struct clk_double_div {
@@ -642,6 +651,42 @@ static int armada_3700_add_composite_clk(const struct clk_periph_data *data,
 	return PTR_ERR_OR_ZERO(*hw);
 }
 
+#if defined(CONFIG_PM)
+static int armada_3700_periph_clock_suspend(struct device *dev)
+{
+	struct clk_periph_driver_data *data = dev_get_drvdata(dev);
+
+	data->tbg_sel = readl(data->reg + TBG_SEL);
+	data->div_sel0 = readl(data->reg + DIV_SEL0);
+	data->div_sel1 = readl(data->reg + DIV_SEL1);
+	data->div_sel2 = readl(data->reg + DIV_SEL2);
+	data->clk_sel = readl(data->reg + CLK_SEL);
+	data->clk_dis = readl(data->reg + CLK_DIS);
+
+	return 0;
+}
+
+static int armada_3700_periph_clock_resume(struct device *dev)
+{
+	struct clk_periph_driver_data *data = dev_get_drvdata(dev);
+
+	/* Follow the same order than what the Cortex-M3 does (ATF code) */
+	writel(data->clk_dis, data->reg + CLK_DIS);
+	writel(data->div_sel0, data->reg + DIV_SEL0);
+	writel(data->div_sel1, data->reg + DIV_SEL1);
+	writel(data->div_sel2, data->reg + DIV_SEL2);
+	writel(data->tbg_sel, data->reg + TBG_SEL);
+	writel(data->clk_sel, data->reg + CLK_SEL);
+
+	return 0;
+}
+
+static const struct dev_pm_ops armada_3700_periph_clock_pm_ops = {
+	.suspend        = armada_3700_periph_clock_suspend,
+	.resume         = armada_3700_periph_clock_resume,
+};
+#endif /* CONFIG_PM */
+
 static int armada_3700_periph_clock_probe(struct platform_device *pdev)
 {
 	struct clk_periph_driver_data *driver_data;
@@ -716,6 +761,9 @@ static struct platform_driver armada_3700_periph_clock_driver = {
 	.driver		= {
 		.name	= "marvell-armada-3700-periph-clock",
 		.of_match_table = armada_3700_periph_clock_of_match,
+#if defined(CONFIG_PM)
+		.pm	= &armada_3700_periph_clock_pm_ops,
+#endif /* CONFIG_PM */
 	},
 };
 
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] clk: mvebu: armada-37xx-periph: add suspend/resume support
  2018-04-21 14:23 ` [PATCH 2/2] clk: mvebu: armada-37xx-periph: add suspend/resume support Miquel Raynal
@ 2018-05-02 16:18   ` Gregory CLEMENT
  2018-06-26  9:09     ` Miquel Raynal
  0 siblings, 1 reply; 6+ messages in thread
From: Gregory CLEMENT @ 2018-05-02 16:18 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Michael Turquette, Stephen Boyd, Thomas Petazzoni,
	Antoine Tenart, Maxime Chevallier, Nadav Haklai, linux-clk,
	linux-pm

Hi Miquel,
 
 On sam., avril 21 2018, Miquel Raynal <miquel.raynal@bootlin.com> wrote:

> Add suspend/resume hooks in Armada 37xx peripheral clocks driver to
> handle S2RAM operations.
>
> One can think that these hooks are useless by comparing the register
> values before and after a suspend/resume cycle: they will look the same
> anyway. This is because of some scripts executed by the Cortex-M3 core
> during ATF operations to init both the clocks and the DDR. These values
> could be modified by the BL33 stage or by Linux itself and should be
> preserved.
>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  drivers/clk/mvebu/armada-37xx-periph.c | 48 ++++++++++++++++++++++++++++++++++
>  1 file changed, 48 insertions(+)
>
> diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mvebu/armada-37xx-periph.c
> index 723bb7f6cea1..cd560bdcb8a9 100644
> --- a/drivers/clk/mvebu/armada-37xx-periph.c
> +++ b/drivers/clk/mvebu/armada-37xx-periph.c
> @@ -59,6 +59,15 @@ struct clk_periph_driver_data {
>  	struct clk_hw_onecell_data *hw_data;
>  	spinlock_t lock;
>  	void __iomem *reg;
> +#if defined(CONFIG_PM)
> +	/* Storage registers for suspend/resume operations */
> +	u32 tbg_sel;
> +	u32 div_sel0;
> +	u32 div_sel1;
> +	u32 div_sel2;
> +	u32 clk_sel;
> +	u32 clk_dis;
> +#endif /* CONFIG_PM */
>  };
>  
>  struct clk_double_div {
> @@ -642,6 +651,42 @@ static int armada_3700_add_composite_clk(const struct clk_periph_data *data,
>  	return PTR_ERR_OR_ZERO(*hw);
>  }
>  
> +#if defined(CONFIG_PM)

I think you could get rid of this conditional code. Have a look on what
is done in others drivers around DEV_PM_OPS and __maybe_unused.

Gregory


> +static int armada_3700_periph_clock_suspend(struct device *dev)
> +{
> +	struct clk_periph_driver_data *data = dev_get_drvdata(dev);
> +
> +	data->tbg_sel = readl(data->reg + TBG_SEL);
> +	data->div_sel0 = readl(data->reg + DIV_SEL0);
> +	data->div_sel1 = readl(data->reg + DIV_SEL1);
> +	data->div_sel2 = readl(data->reg + DIV_SEL2);
> +	data->clk_sel = readl(data->reg + CLK_SEL);
> +	data->clk_dis = readl(data->reg + CLK_DIS);
> +
> +	return 0;
> +}
> +
> +static int armada_3700_periph_clock_resume(struct device *dev)
> +{
> +	struct clk_periph_driver_data *data = dev_get_drvdata(dev);
> +
> +	/* Follow the same order than what the Cortex-M3 does (ATF code) */
> +	writel(data->clk_dis, data->reg + CLK_DIS);
> +	writel(data->div_sel0, data->reg + DIV_SEL0);
> +	writel(data->div_sel1, data->reg + DIV_SEL1);
> +	writel(data->div_sel2, data->reg + DIV_SEL2);
> +	writel(data->tbg_sel, data->reg + TBG_SEL);
> +	writel(data->clk_sel, data->reg + CLK_SEL);
> +
> +	return 0;
> +}
> +
> +static const struct dev_pm_ops armada_3700_periph_clock_pm_ops = {
> +	.suspend        = armada_3700_periph_clock_suspend,
> +	.resume         = armada_3700_periph_clock_resume,
> +};
> +#endif /* CONFIG_PM */
> +
>  static int armada_3700_periph_clock_probe(struct platform_device *pdev)
>  {
>  	struct clk_periph_driver_data *driver_data;
> @@ -716,6 +761,9 @@ static struct platform_driver armada_3700_periph_clock_driver = {
>  	.driver		= {
>  		.name	= "marvell-armada-3700-periph-clock",
>  		.of_match_table = armada_3700_periph_clock_of_match,
> +#if defined(CONFIG_PM)
> +		.pm	= &armada_3700_periph_clock_pm_ops,
> +#endif /* CONFIG_PM */
>  	},
>  };
>  
> -- 
> 2.14.1
>

-- 
Gregory Clement, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
http://bootlin.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] clk: mvebu: armada-37xx-periph: add suspend/resume support
  2018-05-02 16:18   ` Gregory CLEMENT
@ 2018-06-26  9:09     ` Miquel Raynal
  2018-07-06 15:58       ` Stephen Boyd
  0 siblings, 1 reply; 6+ messages in thread
From: Miquel Raynal @ 2018-06-26  9:09 UTC (permalink / raw)
  To: Gregory CLEMENT
  Cc: Michael Turquette, Stephen Boyd, Thomas Petazzoni,
	Antoine Tenart, Maxime Chevallier, Nadav Haklai, linux-clk,
	linux-pm

Hi Gregory,

On Wed, 02 May 2018 18:18:37 +0200, Gregory CLEMENT
<gregory.clement@bootlin.com> wrote:

> Hi Miquel,
> =20
>  On sam., avril 21 2018, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>=20
> > Add suspend/resume hooks in Armada 37xx peripheral clocks driver to
> > handle S2RAM operations.
> >
> > One can think that these hooks are useless by comparing the register
> > values before and after a suspend/resume cycle: they will look the same
> > anyway. This is because of some scripts executed by the Cortex-M3 core
> > during ATF operations to init both the clocks and the DDR. These values
> > could be modified by the BL33 stage or by Linux itself and should be
> > preserved.
> >
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > ---
> >  drivers/clk/mvebu/armada-37xx-periph.c | 48 ++++++++++++++++++++++++++=
++++++++
> >  1 file changed, 48 insertions(+)
> >
> > diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mvebu=
/armada-37xx-periph.c
> > index 723bb7f6cea1..cd560bdcb8a9 100644
> > --- a/drivers/clk/mvebu/armada-37xx-periph.c
> > +++ b/drivers/clk/mvebu/armada-37xx-periph.c
> > @@ -59,6 +59,15 @@ struct clk_periph_driver_data {
> >  	struct clk_hw_onecell_data *hw_data;
> >  	spinlock_t lock;
> >  	void __iomem *reg;
> > +#if defined(CONFIG_PM)
> > +	/* Storage registers for suspend/resume operations */
> > +	u32 tbg_sel;
> > +	u32 div_sel0;
> > +	u32 div_sel1;
> > +	u32 div_sel2;
> > +	u32 clk_sel;
> > +	u32 clk_dis;
> > +#endif /* CONFIG_PM */
> >  };
> > =20
> >  struct clk_double_div {
> > @@ -642,6 +651,42 @@ static int armada_3700_add_composite_clk(const str=
uct clk_periph_data *data,
> >  	return PTR_ERR_OR_ZERO(*hw);
> >  }
> > =20
> > +#if defined(CONFIG_PM) =20
>=20
> I think you could get rid of this conditional code. Have a look on what
> is done in others drivers around DEV_PM_OPS and __maybe_unused.

Thanks for pointing it.

Actually most implementations do not use __maybe_unused but do
something like:

#if defined(CONFIG_PM)

static int xxx_pm_suspend() { ... }

static void xxx_pm_resume() { ... }

static struct pm_ops ops;
#define XXX_DEV_PM_OPS &ops
#else
#define XXX_DEV_PM_OPS NULL
#endif /* CONFIG_PM */=20

And then in the platform_driver structure:

        .pm =3D XXX_DEV_PM_OPS,

This way, the only #if/#endif is "out" of the current code and the
".pm =3D" line is free of preprocessor macros.

Thanks,
Miqu=C3=A8l

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] clk: mvebu: armada-37xx-periph: add suspend/resume support
  2018-06-26  9:09     ` Miquel Raynal
@ 2018-07-06 15:58       ` Stephen Boyd
  2018-07-06 16:03         ` Miquel Raynal
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Boyd @ 2018-07-06 15:58 UTC (permalink / raw)
  To: Gregory CLEMENT, Miquel Raynal
  Cc: Michael Turquette, Thomas Petazzoni, Antoine Tenart,
	Maxime Chevallier, Nadav Haklai, linux-clk, linux-pm

Quoting Miquel Raynal (2018-06-26 02:09:18)
> Hi Gregory,
> =

> On Wed, 02 May 2018 18:18:37 +0200, Gregory CLEMENT
> <gregory.clement@bootlin.com> wrote:
> >  On sam., avril 21 2018, Miquel Raynal <miquel.raynal@bootlin.com> wrot=
e:
> > >  =

> > > +#if defined(CONFIG_PM)  =

> > =

> > I think you could get rid of this conditional code. Have a look on what
> > is done in others drivers around DEV_PM_OPS and __maybe_unused.
> =

> Thanks for pointing it.
> =

> Actually most implementations do not use __maybe_unused but do
> something like:
> =

> #if defined(CONFIG_PM)
> =

> static int xxx_pm_suspend() { ... }
> =

> static void xxx_pm_resume() { ... }
> =

> static struct pm_ops ops;
> #define XXX_DEV_PM_OPS &ops
> #else
> #define XXX_DEV_PM_OPS NULL
> #endif /* CONFIG_PM */ =

> =

> And then in the platform_driver structure:
> =

>         .pm =3D XXX_DEV_PM_OPS,
> =

> This way, the only #if/#endif is "out" of the current code and the
> ".pm =3D" line is free of preprocessor macros.
> =


Yes, less preprocessor conditionals throughout the code is better for
code readability and maintainability. Please remove the conditionals and
use __maybe_unused instead. Sadly, we'll waste 48 bytes on the
save/restore registers, but that's OK.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] clk: mvebu: armada-37xx-periph: add suspend/resume support
  2018-07-06 15:58       ` Stephen Boyd
@ 2018-07-06 16:03         ` Miquel Raynal
  0 siblings, 0 replies; 6+ messages in thread
From: Miquel Raynal @ 2018-07-06 16:03 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Gregory CLEMENT, Michael Turquette, Thomas Petazzoni,
	Antoine Tenart, Maxime Chevallier, Nadav Haklai, linux-clk,
	linux-pm

Hi Stephen,

Stephen Boyd <sboyd@kernel.org> wrote on Fri, 06 Jul 2018 08:58:38
-0700:

> Quoting Miquel Raynal (2018-06-26 02:09:18)
> > Hi Gregory,
> >=20
> > On Wed, 02 May 2018 18:18:37 +0200, Gregory CLEMENT
> > <gregory.clement@bootlin.com> wrote: =20
> > >  On sam., avril 21 2018, Miquel Raynal <miquel.raynal@bootlin.com> wr=
ote: =20
> > > > =20
> > > > +#if defined(CONFIG_PM)   =20
> > >=20
> > > I think you could get rid of this conditional code. Have a look on wh=
at
> > > is done in others drivers around DEV_PM_OPS and __maybe_unused. =20
> >=20
> > Thanks for pointing it.
> >=20
> > Actually most implementations do not use __maybe_unused but do
> > something like:
> >=20
> > #if defined(CONFIG_PM)
> >=20
> > static int xxx_pm_suspend() { ... }
> >=20
> > static void xxx_pm_resume() { ... }
> >=20
> > static struct pm_ops ops;
> > #define XXX_DEV_PM_OPS &ops
> > #else
> > #define XXX_DEV_PM_OPS NULL
> > #endif /* CONFIG_PM */=20
> >=20
> > And then in the platform_driver structure:
> >=20
> >         .pm =3D XXX_DEV_PM_OPS,
> >=20
> > This way, the only #if/#endif is "out" of the current code and the
> > ".pm =3D" line is free of preprocessor macros.
> >  =20
>=20
> Yes, less preprocessor conditionals throughout the code is better for
> code readability and maintainability. Please remove the conditionals and
> use __maybe_unused instead. Sadly, we'll waste 48 bytes on the
> save/restore registers, but that's OK.
>=20

Mmmh. Looking at current code I thought the above was the preferred
way. Ok then, I'll repost with the conditionals removed and
__maybe_unused on the suspend/resume functions as initially suggested
by Gregory.

Thanks,
Miqu=C3=A8l

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-07-06 16:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-21 14:23 [PATCH 1/2] clk: mvebu: armada-37xx-periph: save the IP base address in the driver data Miquel Raynal
2018-04-21 14:23 ` [PATCH 2/2] clk: mvebu: armada-37xx-periph: add suspend/resume support Miquel Raynal
2018-05-02 16:18   ` Gregory CLEMENT
2018-06-26  9:09     ` Miquel Raynal
2018-07-06 15:58       ` Stephen Boyd
2018-07-06 16:03         ` Miquel Raynal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.