* [PATCH] GPIO/pl061: Add suspend resume capability
@ 2011-11-17 11:15 Viresh Kumar
2011-11-17 13:54 ` Baruch Siach
2011-11-17 20:34 ` Rafael J. Wysocki
0 siblings, 2 replies; 5+ messages in thread
From: Viresh Kumar @ 2011-11-17 11:15 UTC (permalink / raw)
To: baruch, grant.likely
Cc: linux-kernel, armando.visconti, shiraz.hashim, vipin.kumar,
rajeev-dlh.kumar, deepak.sikri, vipulkumar.samar, amit.virdi,
viresh.kumar, pratyush.anand, bhupesh.sharma, viresh.linux,
bhavna.yadav, vincenzo.frascino, mirko.gardi
From: Deepak Sikri <deepak.sikri@st.com>
This patch adds the suspend and resume operations in the driver. The patch
ensures the data save and restore for the device registers during the
suspend and resume operations respectively.
Signed-off-by: Deepak Sikri <deepak.sikri@st.com>
---
drivers/gpio/gpio-pl061.c | 73 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 73 insertions(+), 0 deletions(-)
diff --git a/drivers/gpio/gpio-pl061.c b/drivers/gpio/gpio-pl061.c
index 093c90b..d64dc1c 100644
--- a/drivers/gpio/gpio-pl061.c
+++ b/drivers/gpio/gpio-pl061.c
@@ -23,6 +23,7 @@
#include <linux/amba/bus.h>
#include <linux/amba/pl061.h>
#include <linux/slab.h>
+#include <linux/pm.h>
#define GPIODIR 0x400
#define GPIOIS 0x404
@@ -35,6 +36,17 @@
#define PL061_GPIO_NR 8
+#ifdef CONFIG_PM
+struct gpio_context_save_regs {
+ u8 gpio_data;
+ u8 gpio_dir;
+ u8 gpio_is;
+ u8 gpio_ibe;
+ u8 gpio_iev;
+ u8 gpio_ie;
+};
+#endif
+
struct pl061_gpio {
/* We use a list of pl061_gpio structs for each trigger IRQ in the main
* interrupts controller of the system. We need this to support systems
@@ -54,6 +66,10 @@ struct pl061_gpio {
void __iomem *base;
unsigned irq_base;
struct gpio_chip gc;
+
+#ifdef CONFIG_PM
+ struct gpio_context_save_regs csave_regs;
+#endif
};
static int pl061_direction_input(struct gpio_chip *gc, unsigned offset)
@@ -330,6 +346,8 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
irq_set_chip_data(i + chip->irq_base, chip);
}
+ amba_set_drvdata(dev, chip);
+
return 0;
iounmap:
@@ -342,6 +360,60 @@ free_mem:
return ret;
}
+#ifdef CONFIG_PM
+static int pl061_suspend(struct device *dev)
+{
+ struct pl061_gpio *chip = dev_get_drvdata(dev);
+ int offset;
+
+ chip->csave_regs.gpio_data = 0;
+ chip->csave_regs.gpio_dir = readb(chip->base + GPIODIR);
+ chip->csave_regs.gpio_is = readb(chip->base + GPIOIS);
+ chip->csave_regs.gpio_ibe = readb(chip->base + GPIOIBE);
+ chip->csave_regs.gpio_iev = readb(chip->base + GPIOIEV);
+ chip->csave_regs.gpio_ie = readb(chip->base + GPIOIE);
+
+ for (offset = 0; offset < PL061_GPIO_NR; offset++) {
+ if (chip->csave_regs.gpio_dir & (1 << offset))
+ chip->csave_regs.gpio_data |=
+ pl061_get_value(&chip->gc, offset) << offset;
+ }
+
+ return 0;
+}
+
+static int pl061_resume(struct device *dev)
+{
+ struct pl061_gpio *chip = dev_get_drvdata(dev);
+ int offset;
+
+ for (offset = 0; offset < PL061_GPIO_NR; offset++) {
+ if (chip->csave_regs.gpio_dir & (1 << offset))
+ pl061_direction_output(&chip->gc, offset,
+ chip->csave_regs.gpio_data &
+ (1 << offset));
+ else
+ pl061_direction_input(&chip->gc, offset);
+ }
+
+ writeb(chip->csave_regs.gpio_is, chip->base + GPIOIS);
+ writeb(chip->csave_regs.gpio_ibe, chip->base + GPIOIBE);
+ writeb(chip->csave_regs.gpio_iev, chip->base + GPIOIEV);
+ writeb(chip->csave_regs.gpio_ie, chip->base + GPIOIE);
+
+ return 0;
+}
+
+static const struct dev_pm_ops pl061_dev_pm_ops = {
+ .suspend = pl061_suspend,
+ .resume = pl061_resume,
+};
+
+#define PL061_DEV_PM_OPS (&pl061_dev_pm_ops)
+#else
+#define PL061_DEV_PM_OPS NULL
+#endif
+
static struct amba_id pl061_ids[] = {
{
.id = 0x00041061,
@@ -353,6 +425,7 @@ static struct amba_id pl061_ids[] = {
static struct amba_driver pl061_gpio_driver = {
.drv = {
.name = "pl061_gpio",
+ .pm = PL061_DEV_PM_OPS,
},
.id_table = pl061_ids,
.probe = pl061_probe,
--
1.7.2.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] GPIO/pl061: Add suspend resume capability
2011-11-17 11:15 [PATCH] GPIO/pl061: Add suspend resume capability Viresh Kumar
@ 2011-11-17 13:54 ` Baruch Siach
2011-11-18 3:30 ` Viresh Kumar
2011-11-17 20:34 ` Rafael J. Wysocki
1 sibling, 1 reply; 5+ messages in thread
From: Baruch Siach @ 2011-11-17 13:54 UTC (permalink / raw)
To: Viresh Kumar
Cc: grant.likely, linux-kernel, armando.visconti, shiraz.hashim,
vipin.kumar, rajeev-dlh.kumar, deepak.sikri, vipulkumar.samar,
amit.virdi, pratyush.anand, bhupesh.sharma, viresh.linux,
bhavna.yadav, vincenzo.frascino, mirko.gardi
Hi Viresh,
On Thu, Nov 17, 2011 at 04:45:35PM +0530, Viresh Kumar wrote:
> From: Deepak Sikri <deepak.sikri@st.com>
>
> This patch adds the suspend and resume operations in the driver. The patch
> ensures the data save and restore for the device registers during the
> suspend and resume operations respectively.
>
> Signed-off-by: Deepak Sikri <deepak.sikri@st.com>
> ---
> drivers/gpio/gpio-pl061.c | 73 +++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 73 insertions(+), 0 deletions(-)
[snip]
> +#ifdef CONFIG_PM
> +struct gpio_context_save_regs {
Nit: I think pl061_context_save_regs is a better name.
Other then that:
Acked-by: Baruch Siach <baruch@tkos.co.il>
baruch
> + u8 gpio_data;
> + u8 gpio_dir;
> + u8 gpio_is;
> + u8 gpio_ibe;
> + u8 gpio_iev;
> + u8 gpio_ie;
> +};
> +#endif
> +
> struct pl061_gpio {
> /* We use a list of pl061_gpio structs for each trigger IRQ in the main
> * interrupts controller of the system. We need this to support systems
> @@ -54,6 +66,10 @@ struct pl061_gpio {
> void __iomem *base;
> unsigned irq_base;
> struct gpio_chip gc;
> +
> +#ifdef CONFIG_PM
> + struct gpio_context_save_regs csave_regs;
> +#endif
> };
>
> static int pl061_direction_input(struct gpio_chip *gc, unsigned offset)
> @@ -330,6 +346,8 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
> irq_set_chip_data(i + chip->irq_base, chip);
> }
>
> + amba_set_drvdata(dev, chip);
> +
> return 0;
>
> iounmap:
> @@ -342,6 +360,60 @@ free_mem:
> return ret;
> }
>
> +#ifdef CONFIG_PM
> +static int pl061_suspend(struct device *dev)
> +{
> + struct pl061_gpio *chip = dev_get_drvdata(dev);
> + int offset;
> +
> + chip->csave_regs.gpio_data = 0;
> + chip->csave_regs.gpio_dir = readb(chip->base + GPIODIR);
> + chip->csave_regs.gpio_is = readb(chip->base + GPIOIS);
> + chip->csave_regs.gpio_ibe = readb(chip->base + GPIOIBE);
> + chip->csave_regs.gpio_iev = readb(chip->base + GPIOIEV);
> + chip->csave_regs.gpio_ie = readb(chip->base + GPIOIE);
> +
> + for (offset = 0; offset < PL061_GPIO_NR; offset++) {
> + if (chip->csave_regs.gpio_dir & (1 << offset))
> + chip->csave_regs.gpio_data |=
> + pl061_get_value(&chip->gc, offset) << offset;
> + }
> +
> + return 0;
> +}
> +
> +static int pl061_resume(struct device *dev)
> +{
> + struct pl061_gpio *chip = dev_get_drvdata(dev);
> + int offset;
> +
> + for (offset = 0; offset < PL061_GPIO_NR; offset++) {
> + if (chip->csave_regs.gpio_dir & (1 << offset))
> + pl061_direction_output(&chip->gc, offset,
> + chip->csave_regs.gpio_data &
> + (1 << offset));
> + else
> + pl061_direction_input(&chip->gc, offset);
> + }
> +
> + writeb(chip->csave_regs.gpio_is, chip->base + GPIOIS);
> + writeb(chip->csave_regs.gpio_ibe, chip->base + GPIOIBE);
> + writeb(chip->csave_regs.gpio_iev, chip->base + GPIOIEV);
> + writeb(chip->csave_regs.gpio_ie, chip->base + GPIOIE);
> +
> + return 0;
> +}
> +
> +static const struct dev_pm_ops pl061_dev_pm_ops = {
> + .suspend = pl061_suspend,
> + .resume = pl061_resume,
> +};
> +
> +#define PL061_DEV_PM_OPS (&pl061_dev_pm_ops)
> +#else
> +#define PL061_DEV_PM_OPS NULL
> +#endif
> +
> static struct amba_id pl061_ids[] = {
> {
> .id = 0x00041061,
> @@ -353,6 +425,7 @@ static struct amba_id pl061_ids[] = {
> static struct amba_driver pl061_gpio_driver = {
> .drv = {
> .name = "pl061_gpio",
> + .pm = PL061_DEV_PM_OPS,
> },
> .id_table = pl061_ids,
> .probe = pl061_probe,
--
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] GPIO/pl061: Add suspend resume capability
2011-11-17 13:54 ` Baruch Siach
@ 2011-11-18 3:30 ` Viresh Kumar
0 siblings, 0 replies; 5+ messages in thread
From: Viresh Kumar @ 2011-11-18 3:30 UTC (permalink / raw)
To: Baruch Siach
Cc: grant.likely@secretlab.ca, linux-kernel@vger.kernel.org,
Armando VISCONTI, Shiraz HASHIM, Vipin KUMAR, Rajeev KUMAR,
Deepak SIKRI, Vipul Kumar SAMAR, Amit VIRDI, Pratyush ANAND,
Bhupesh SHARMA, viresh.linux@gmail.com, Bhavna YADAV,
Vincenzo FRASCINO, Mirko GARDI
On 11/17/2011 7:24 PM, Baruch Siach wrote:
>> > +struct gpio_context_save_regs {
> Nit: I think pl061_context_save_regs is a better name.
>
Sure.
> Other then that:
>
> Acked-by: Baruch Siach <baruch@tkos.co.il>
Thanks.
--
viresh
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] GPIO/pl061: Add suspend resume capability
2011-11-17 11:15 [PATCH] GPIO/pl061: Add suspend resume capability Viresh Kumar
2011-11-17 13:54 ` Baruch Siach
@ 2011-11-17 20:34 ` Rafael J. Wysocki
2011-11-18 4:02 ` Viresh Kumar
1 sibling, 1 reply; 5+ messages in thread
From: Rafael J. Wysocki @ 2011-11-17 20:34 UTC (permalink / raw)
To: Viresh Kumar
Cc: baruch, grant.likely, linux-kernel, armando.visconti,
shiraz.hashim, vipin.kumar, rajeev-dlh.kumar, deepak.sikri,
vipulkumar.samar, amit.virdi, pratyush.anand, bhupesh.sharma,
viresh.linux, bhavna.yadav, vincenzo.frascino, mirko.gardi
On Thursday, November 17, 2011, Viresh Kumar wrote:
> From: Deepak Sikri <deepak.sikri@st.com>
>
> This patch adds the suspend and resume operations in the driver. The patch
> ensures the data save and restore for the device registers during the
> suspend and resume operations respectively.
>
> Signed-off-by: Deepak Sikri <deepak.sikri@st.com>
> ---
> drivers/gpio/gpio-pl061.c | 73 +++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 73 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/gpio/gpio-pl061.c b/drivers/gpio/gpio-pl061.c
> index 093c90b..d64dc1c 100644
> --- a/drivers/gpio/gpio-pl061.c
> +++ b/drivers/gpio/gpio-pl061.c
> @@ -23,6 +23,7 @@
> #include <linux/amba/bus.h>
> #include <linux/amba/pl061.h>
> #include <linux/slab.h>
> +#include <linux/pm.h>
>
> #define GPIODIR 0x400
> #define GPIOIS 0x404
> @@ -35,6 +36,17 @@
>
> #define PL061_GPIO_NR 8
>
> +#ifdef CONFIG_PM
> +struct gpio_context_save_regs {
> + u8 gpio_data;
> + u8 gpio_dir;
> + u8 gpio_is;
> + u8 gpio_ibe;
> + u8 gpio_iev;
> + u8 gpio_ie;
> +};
> +#endif
> +
> struct pl061_gpio {
> /* We use a list of pl061_gpio structs for each trigger IRQ in the main
> * interrupts controller of the system. We need this to support systems
> @@ -54,6 +66,10 @@ struct pl061_gpio {
> void __iomem *base;
> unsigned irq_base;
> struct gpio_chip gc;
> +
> +#ifdef CONFIG_PM
> + struct gpio_context_save_regs csave_regs;
> +#endif
> };
>
> static int pl061_direction_input(struct gpio_chip *gc, unsigned offset)
> @@ -330,6 +346,8 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
> irq_set_chip_data(i + chip->irq_base, chip);
> }
>
> + amba_set_drvdata(dev, chip);
> +
> return 0;
>
> iounmap:
> @@ -342,6 +360,60 @@ free_mem:
> return ret;
> }
>
> +#ifdef CONFIG_PM
> +static int pl061_suspend(struct device *dev)
> +{
> + struct pl061_gpio *chip = dev_get_drvdata(dev);
> + int offset;
> +
> + chip->csave_regs.gpio_data = 0;
> + chip->csave_regs.gpio_dir = readb(chip->base + GPIODIR);
> + chip->csave_regs.gpio_is = readb(chip->base + GPIOIS);
> + chip->csave_regs.gpio_ibe = readb(chip->base + GPIOIBE);
> + chip->csave_regs.gpio_iev = readb(chip->base + GPIOIEV);
> + chip->csave_regs.gpio_ie = readb(chip->base + GPIOIE);
> +
> + for (offset = 0; offset < PL061_GPIO_NR; offset++) {
> + if (chip->csave_regs.gpio_dir & (1 << offset))
> + chip->csave_regs.gpio_data |=
> + pl061_get_value(&chip->gc, offset) << offset;
> + }
> +
> + return 0;
> +}
> +
> +static int pl061_resume(struct device *dev)
> +{
> + struct pl061_gpio *chip = dev_get_drvdata(dev);
> + int offset;
> +
> + for (offset = 0; offset < PL061_GPIO_NR; offset++) {
> + if (chip->csave_regs.gpio_dir & (1 << offset))
> + pl061_direction_output(&chip->gc, offset,
> + chip->csave_regs.gpio_data &
> + (1 << offset));
> + else
> + pl061_direction_input(&chip->gc, offset);
> + }
> +
> + writeb(chip->csave_regs.gpio_is, chip->base + GPIOIS);
> + writeb(chip->csave_regs.gpio_ibe, chip->base + GPIOIBE);
> + writeb(chip->csave_regs.gpio_iev, chip->base + GPIOIEV);
> + writeb(chip->csave_regs.gpio_ie, chip->base + GPIOIE);
> +
> + return 0;
> +}
> +
> +static const struct dev_pm_ops pl061_dev_pm_ops = {
> + .suspend = pl061_suspend,
> + .resume = pl061_resume,
Please also include hibernation callbacks here, otherwise your code will
break systems with hibernation enabled.
There are convenience macros for that in linux/pm.h, please use one of them.
Thanks,
Rafael
> +};
> +
> +#define PL061_DEV_PM_OPS (&pl061_dev_pm_ops)
> +#else
> +#define PL061_DEV_PM_OPS NULL
> +#endif
> +
> static struct amba_id pl061_ids[] = {
> {
> .id = 0x00041061,
> @@ -353,6 +425,7 @@ static struct amba_id pl061_ids[] = {
> static struct amba_driver pl061_gpio_driver = {
> .drv = {
> .name = "pl061_gpio",
> + .pm = PL061_DEV_PM_OPS,
> },
> .id_table = pl061_ids,
> .probe = pl061_probe,
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] GPIO/pl061: Add suspend resume capability
2011-11-17 20:34 ` Rafael J. Wysocki
@ 2011-11-18 4:02 ` Viresh Kumar
0 siblings, 0 replies; 5+ messages in thread
From: Viresh Kumar @ 2011-11-18 4:02 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: baruch@tkos.co.il, grant.likely@secretlab.ca,
linux-kernel@vger.kernel.org, Armando VISCONTI, Shiraz HASHIM,
Vipin KUMAR, Rajeev KUMAR, Deepak SIKRI, Vipul Kumar SAMAR,
Amit VIRDI, Pratyush ANAND, Bhupesh SHARMA,
viresh.linux@gmail.com, Bhavna YADAV, Vincenzo FRASCINO,
Mirko GARDI
On 11/18/2011 2:04 AM, Rafael J. Wysocki wrote:
>> > +static const struct dev_pm_ops pl061_dev_pm_ops = {
>> > + .suspend = pl061_suspend,
>> > + .resume = pl061_resume,
> Please also include hibernation callbacks here, otherwise your code will
> break systems with hibernation enabled.
>
> There are convenience macros for that in linux/pm.h, please use one of them.
Sure. Thanx.
--
viresh
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-11-18 4:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-17 11:15 [PATCH] GPIO/pl061: Add suspend resume capability Viresh Kumar
2011-11-17 13:54 ` Baruch Siach
2011-11-18 3:30 ` Viresh Kumar
2011-11-17 20:34 ` Rafael J. Wysocki
2011-11-18 4:02 ` Viresh Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).