All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pinctrl: mvebu: add suspend/resume support to Armada XP pinctrl driver
@ 2015-03-19 10:30 ` Thomas Petazzoni
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Petazzoni @ 2015-03-19 10:30 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-gpio, Jason Cooper, Andrew Lunn, Sebastian Hesselbarth,
	Gregory Clement, linux-arm-kernel, Thomas Petazzoni

This commit adds suspend/resume support to the Armada XP pinctrl
driver, by simply saving and restoring the MPP registers.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 drivers/pinctrl/mvebu/pinctrl-armada-xp.c | 40 +++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-xp.c b/drivers/pinctrl/mvebu/pinctrl-armada-xp.c
index fc33761..d191c3a 100644
--- a/drivers/pinctrl/mvebu/pinctrl-armada-xp.c
+++ b/drivers/pinctrl/mvebu/pinctrl-armada-xp.c
@@ -34,6 +34,7 @@
 #include "pinctrl-mvebu.h"
 
 static void __iomem *mpp_base;
+static u32 *mpp_saved_regs;
 
 static int armada_xp_mpp_ctrl_get(unsigned pid, unsigned long *config)
 {
@@ -406,12 +407,42 @@ static struct pinctrl_gpio_range mv78460_mpp_gpio_ranges[] = {
 	MPP_GPIO_RANGE(2,  64, 64,  3),
 };
 
+static int armada_xp_pinctrl_suspend(struct platform_device *pdev,
+				     pm_message_t state)
+{
+	struct mvebu_pinctrl_soc_info *soc =
+		platform_get_drvdata(pdev);
+	int i, nregs;
+
+	nregs = DIV_ROUND_UP(soc->nmodes, MVEBU_MPPS_PER_REG);
+
+	for (i = 0; i < nregs; i++)
+		mpp_saved_regs[i] = readl(mpp_base + i * 4);
+
+	return 0;
+}
+
+static int armada_xp_pinctrl_resume(struct platform_device *pdev)
+{
+	struct mvebu_pinctrl_soc_info *soc =
+		platform_get_drvdata(pdev);
+	int i, nregs;
+
+	nregs = DIV_ROUND_UP(soc->nmodes, MVEBU_MPPS_PER_REG);
+
+	for (i = 0; i < nregs; i++)
+		writel(mpp_saved_regs[i], mpp_base + i * 4);
+
+	return 0;
+}
+
 static int armada_xp_pinctrl_probe(struct platform_device *pdev)
 {
 	struct mvebu_pinctrl_soc_info *soc = &armada_xp_pinctrl_info;
 	const struct of_device_id *match =
 		of_match_device(armada_xp_pinctrl_of_match, &pdev->dev);
 	struct resource *res;
+	int nregs;
 
 	if (!match)
 		return -ENODEV;
@@ -459,6 +490,13 @@ static int armada_xp_pinctrl_probe(struct platform_device *pdev)
 		break;
 	}
 
+	nregs = DIV_ROUND_UP(soc->nmodes, MVEBU_MPPS_PER_REG);
+
+	mpp_saved_regs = devm_kmalloc(&pdev->dev, nregs * sizeof(u32),
+				      GFP_KERNEL);
+	if (!mpp_saved_regs)
+		return -ENOMEM;
+
 	pdev->dev.platform_data = soc;
 
 	return mvebu_pinctrl_probe(pdev);
@@ -476,6 +514,8 @@ static struct platform_driver armada_xp_pinctrl_driver = {
 	},
 	.probe = armada_xp_pinctrl_probe,
 	.remove = armada_xp_pinctrl_remove,
+	.suspend = armada_xp_pinctrl_suspend,
+	.resume = armada_xp_pinctrl_resume,
 };
 
 module_platform_driver(armada_xp_pinctrl_driver);
-- 
2.1.0


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

* [PATCH] pinctrl: mvebu: add suspend/resume support to Armada XP pinctrl driver
@ 2015-03-19 10:30 ` Thomas Petazzoni
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Petazzoni @ 2015-03-19 10:30 UTC (permalink / raw)
  To: linux-arm-kernel

This commit adds suspend/resume support to the Armada XP pinctrl
driver, by simply saving and restoring the MPP registers.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 drivers/pinctrl/mvebu/pinctrl-armada-xp.c | 40 +++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-xp.c b/drivers/pinctrl/mvebu/pinctrl-armada-xp.c
index fc33761..d191c3a 100644
--- a/drivers/pinctrl/mvebu/pinctrl-armada-xp.c
+++ b/drivers/pinctrl/mvebu/pinctrl-armada-xp.c
@@ -34,6 +34,7 @@
 #include "pinctrl-mvebu.h"
 
 static void __iomem *mpp_base;
+static u32 *mpp_saved_regs;
 
 static int armada_xp_mpp_ctrl_get(unsigned pid, unsigned long *config)
 {
@@ -406,12 +407,42 @@ static struct pinctrl_gpio_range mv78460_mpp_gpio_ranges[] = {
 	MPP_GPIO_RANGE(2,  64, 64,  3),
 };
 
+static int armada_xp_pinctrl_suspend(struct platform_device *pdev,
+				     pm_message_t state)
+{
+	struct mvebu_pinctrl_soc_info *soc =
+		platform_get_drvdata(pdev);
+	int i, nregs;
+
+	nregs = DIV_ROUND_UP(soc->nmodes, MVEBU_MPPS_PER_REG);
+
+	for (i = 0; i < nregs; i++)
+		mpp_saved_regs[i] = readl(mpp_base + i * 4);
+
+	return 0;
+}
+
+static int armada_xp_pinctrl_resume(struct platform_device *pdev)
+{
+	struct mvebu_pinctrl_soc_info *soc =
+		platform_get_drvdata(pdev);
+	int i, nregs;
+
+	nregs = DIV_ROUND_UP(soc->nmodes, MVEBU_MPPS_PER_REG);
+
+	for (i = 0; i < nregs; i++)
+		writel(mpp_saved_regs[i], mpp_base + i * 4);
+
+	return 0;
+}
+
 static int armada_xp_pinctrl_probe(struct platform_device *pdev)
 {
 	struct mvebu_pinctrl_soc_info *soc = &armada_xp_pinctrl_info;
 	const struct of_device_id *match =
 		of_match_device(armada_xp_pinctrl_of_match, &pdev->dev);
 	struct resource *res;
+	int nregs;
 
 	if (!match)
 		return -ENODEV;
@@ -459,6 +490,13 @@ static int armada_xp_pinctrl_probe(struct platform_device *pdev)
 		break;
 	}
 
+	nregs = DIV_ROUND_UP(soc->nmodes, MVEBU_MPPS_PER_REG);
+
+	mpp_saved_regs = devm_kmalloc(&pdev->dev, nregs * sizeof(u32),
+				      GFP_KERNEL);
+	if (!mpp_saved_regs)
+		return -ENOMEM;
+
 	pdev->dev.platform_data = soc;
 
 	return mvebu_pinctrl_probe(pdev);
@@ -476,6 +514,8 @@ static struct platform_driver armada_xp_pinctrl_driver = {
 	},
 	.probe = armada_xp_pinctrl_probe,
 	.remove = armada_xp_pinctrl_remove,
+	.suspend = armada_xp_pinctrl_suspend,
+	.resume = armada_xp_pinctrl_resume,
 };
 
 module_platform_driver(armada_xp_pinctrl_driver);
-- 
2.1.0

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

* Re: [PATCH] pinctrl: mvebu: add suspend/resume support to Armada XP pinctrl driver
  2015-03-19 10:30 ` Thomas Petazzoni
@ 2015-03-27  8:37   ` Linus Walleij
  -1 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2015-03-27  8:37 UTC (permalink / raw)
  To: Thomas Petazzoni
  Cc: linux-gpio, Jason Cooper, Andrew Lunn, Sebastian Hesselbarth,
	Gregory Clement, linux-arm-kernel

On Thu, Mar 19, 2015 at 11:30 AM, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:

> This commit adds suspend/resume support to the Armada XP pinctrl
> driver, by simply saving and restoring the MPP registers.
>
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>

Patch applied, but:

>  static void __iomem *mpp_base;
> +static u32 *mpp_saved_regs;

I didn't notice this singleton design pattern in this driver before :(
I see the legacy Dove driver have a few more.

Can we have a mvebu refactoring patch bringing these things into a state
container? Like a per-subdriver kmalloc:ed struct foo_state {}?

Yours,
Linus Walleij

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

* [PATCH] pinctrl: mvebu: add suspend/resume support to Armada XP pinctrl driver
@ 2015-03-27  8:37   ` Linus Walleij
  0 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2015-03-27  8:37 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Mar 19, 2015 at 11:30 AM, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:

> This commit adds suspend/resume support to the Armada XP pinctrl
> driver, by simply saving and restoring the MPP registers.
>
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>

Patch applied, but:

>  static void __iomem *mpp_base;
> +static u32 *mpp_saved_regs;

I didn't notice this singleton design pattern in this driver before :(
I see the legacy Dove driver have a few more.

Can we have a mvebu refactoring patch bringing these things into a state
container? Like a per-subdriver kmalloc:ed struct foo_state {}?

Yours,
Linus Walleij

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

* Re: [PATCH] pinctrl: mvebu: add suspend/resume support to Armada XP pinctrl driver
  2015-03-27  8:37   ` Linus Walleij
@ 2015-03-27 13:52     ` Thomas Petazzoni
  -1 siblings, 0 replies; 6+ messages in thread
From: Thomas Petazzoni @ 2015-03-27 13:52 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-gpio, Jason Cooper, Andrew Lunn, Sebastian Hesselbarth,
	Gregory Clement, linux-arm-kernel

Linus,

On Fri, 27 Mar 2015 09:37:19 +0100, Linus Walleij wrote:

> Patch applied, but:
> 
> >  static void __iomem *mpp_base;
> > +static u32 *mpp_saved_regs;
> 
> I didn't notice this singleton design pattern in this driver before :(
> I see the legacy Dove driver have a few more.
> 
> Can we have a mvebu refactoring patch bringing these things into a state
> container? Like a per-subdriver kmalloc:ed struct foo_state {}?

Yes, I agree this isn't nice. I'll try to nice what I can come up with
and propose a patch.

Thanks a lot!

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

* [PATCH] pinctrl: mvebu: add suspend/resume support to Armada XP pinctrl driver
@ 2015-03-27 13:52     ` Thomas Petazzoni
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Petazzoni @ 2015-03-27 13:52 UTC (permalink / raw)
  To: linux-arm-kernel

Linus,

On Fri, 27 Mar 2015 09:37:19 +0100, Linus Walleij wrote:

> Patch applied, but:
> 
> >  static void __iomem *mpp_base;
> > +static u32 *mpp_saved_regs;
> 
> I didn't notice this singleton design pattern in this driver before :(
> I see the legacy Dove driver have a few more.
> 
> Can we have a mvebu refactoring patch bringing these things into a state
> container? Like a per-subdriver kmalloc:ed struct foo_state {}?

Yes, I agree this isn't nice. I'll try to nice what I can come up with
and propose a patch.

Thanks a lot!

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

end of thread, other threads:[~2015-03-27 13:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-19 10:30 [PATCH] pinctrl: mvebu: add suspend/resume support to Armada XP pinctrl driver Thomas Petazzoni
2015-03-19 10:30 ` Thomas Petazzoni
2015-03-27  8:37 ` Linus Walleij
2015-03-27  8:37   ` Linus Walleij
2015-03-27 13:52   ` Thomas Petazzoni
2015-03-27 13:52     ` Thomas Petazzoni

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.