Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: Yoshihiro Kaneko <ykaneko0929@gmail.com>
To: linux-gpio@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Simon Horman <horms@verge.net.au>,
	Magnus Damm <magnus.damm@gmail.com>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	linux-renesas-soc@vger.kernel.org
Subject: [PATCH] gpio: gpio-rcar: Support S2RAM
Date: Thu,  7 Dec 2017 03:48:35 +0900	[thread overview]
Message-ID: <1512586115-4698-1-git-send-email-ykaneko0929@gmail.com> (raw)

From: Hien Dang <hien.dang.eb@renesas.com>

This patch adds an implementation that saves and restores the state of
GPIO configuration on suspend and resume.

Signed-off-by: Hien Dang <hien.dang.eb@renesas.com>
Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
Signed-off-by: Yoshihiro Kaneko <ykaneko0929@gmail.com>
---

This patch is based on the for-next branch of linux-gpio tree.

 drivers/gpio/gpio-rcar.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 89 insertions(+)

diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
index e76de57..c99a2c5 100644
--- a/drivers/gpio/gpio-rcar.c
+++ b/drivers/gpio/gpio-rcar.c
@@ -31,6 +31,16 @@
 #include <linux/spinlock.h>
 #include <linux/slab.h>
 
+struct gpio_rcar_bank_info {
+	bool iointsel;
+	bool inoutsel;
+	bool outdt;
+	bool active_high_rising_edge;
+	bool level_trigger;
+	bool both;
+	bool intmsk;
+};
+
 struct gpio_rcar_priv {
 	void __iomem *base;
 	spinlock_t lock;
@@ -41,6 +51,7 @@ struct gpio_rcar_priv {
 	unsigned int irq_parent;
 	bool has_both_edge_trigger;
 	bool needs_clk;
+	struct gpio_rcar_bank_info bank_info[32];
 };
 
 #define IOINTSEL 0x00	/* General IO/Interrupt Switching Register */
@@ -415,6 +426,83 @@ static int gpio_rcar_parse_dt(struct gpio_rcar_priv *p, unsigned int *npins)
 	return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int gpio_rcar_suspend(struct device *dev)
+{
+	struct gpio_rcar_priv *p = dev_get_drvdata(dev);
+	int offset;
+	u32 bit_mask;
+	struct gpio_rcar_bank_info *bank_info;
+
+	for (offset = 0; offset < p->gpio_chip.ngpio; offset++) {
+		bank_info = &p->bank_info[offset];
+		bit_mask = BIT(offset);
+		bank_info->iointsel = !!(gpio_rcar_read(p, IOINTSEL) &
+					 bit_mask);
+
+		/* I/O pin  */
+		if (!bank_info->iointsel) {
+			bank_info->inoutsel = !!(gpio_rcar_read(p, INOUTSEL) &
+						 bit_mask);
+			bank_info->outdt = !!(gpio_rcar_read(p, OUTDT) &
+					      bit_mask);
+		/* Interrupt pin  */
+		} else {
+			bank_info->intmsk = !!(gpio_rcar_read(p, INTMSK) &
+					       bit_mask);
+			bank_info->active_high_rising_edge =
+				!(!!(gpio_rcar_read(p, POSNEG) & bit_mask));
+			bank_info->level_trigger =
+				!(!!(gpio_rcar_read(p, EDGLEVEL) & bit_mask));
+			bank_info->both = !!(gpio_rcar_read(p, BOTHEDGE) &
+					     bit_mask);
+		}
+	}
+
+	return 0;
+}
+
+static int gpio_rcar_resume(struct device *dev)
+{
+	struct gpio_rcar_priv *p = dev_get_drvdata(dev);
+	int offset;
+	struct gpio_rcar_bank_info *bank_info;
+
+	for (offset = 0; offset < p->gpio_chip.ngpio; offset++) {
+		bank_info = &p->bank_info[offset];
+		/* I/O pin  */
+		if (!bank_info->iointsel) {
+			if (bank_info->inoutsel)
+				gpio_rcar_direction_output(&p->gpio_chip,
+							   offset,
+							   bank_info->outdt);
+			else
+				gpio_rcar_direction_input(&p->gpio_chip,
+							  offset);
+		/* Interrupt pin  */
+		} else {
+			gpio_rcar_config_interrupt_input_mode(
+				p,
+				offset,
+				bank_info->active_high_rising_edge,
+				bank_info->level_trigger,
+				bank_info->both);
+
+			if (bank_info->intmsk)
+				gpio_rcar_write(p, MSKCLR, BIT(offset));
+		}
+	}
+
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(gpio_rcar_pm_ops,
+		gpio_rcar_suspend, gpio_rcar_resume);
+#define DEV_PM_OPS (&gpio_rcar_pm_ops)
+#else
+#define DEV_PM_OPS NULL
+#endif /* CONFIG_PM_SLEEP*/
+
 static int gpio_rcar_probe(struct platform_device *pdev)
 {
 	struct gpio_rcar_priv *p;
@@ -536,6 +624,7 @@ static int gpio_rcar_remove(struct platform_device *pdev)
 	.remove		= gpio_rcar_remove,
 	.driver		= {
 		.name	= "gpio_rcar",
+		.pm     = DEV_PM_OPS,
 		.of_match_table = of_match_ptr(gpio_rcar_of_table),
 	}
 };
-- 
1.9.1

             reply	other threads:[~2017-12-06 18:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-06 18:48 Yoshihiro Kaneko [this message]
2017-12-06 19:01 ` [PATCH] gpio: gpio-rcar: Support S2RAM Geert Uytterhoeven
2017-12-07  9:08   ` Simon Horman
2017-12-07  9:21     ` Geert Uytterhoeven
2017-12-07  9:26       ` Geert Uytterhoeven
2017-12-07 10:27         ` Simon Horman
2017-12-12 18:01           ` Yoshihiro Kaneko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1512586115-4698-1-git-send-email-ykaneko0929@gmail.com \
    --to=ykaneko0929@gmail.com \
    --cc=geert+renesas@glider.be \
    --cc=horms@verge.net.au \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox