From patchwork Mon Jan 15 18:20:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Kaneko X-Patchwork-Id: 10165169 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0D72260245 for ; Mon, 15 Jan 2018 18:21:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07F75201B1 for ; Mon, 15 Jan 2018 18:21:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F06DB205AF; Mon, 15 Jan 2018 18:21:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C922201B1 for ; Mon, 15 Jan 2018 18:21:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750784AbeAOSV2 (ORCPT ); Mon, 15 Jan 2018 13:21:28 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:34725 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750773AbeAOSV1 (ORCPT ); Mon, 15 Jan 2018 13:21:27 -0500 Received: by mail-pl0-f68.google.com with SMTP id d21so4261896pll.1; Mon, 15 Jan 2018 10:21:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=eNQadqGdZTSW4kKhy0uD70+Pc86/E03Sj/V/lxDPE4w=; b=Xhb2pbCuDKVfzKZolAnlQaLJTsAVQqB0TE4T1FhL7/wIeSyCWZHaWuRhXjjpl2zAa/ IXFvyRl759JpuNHvXnXaFHzub7sldou9C+5ZNaR/HryiRIWgO1LWxpsqRKaNSIaMWnDu FIkK5XZNsC+bAit7+otS1wjP2WL/1o+HwzIpPq7WWLZFKTdGapSeASSzmO3HawSfx9YV o7SASejnPkviR38c9xev/8KC/RF2NxMK9qXsQhtitcOLCRpl/Q7FoC13ITKO34NMLncm q37PYtL9T9KLtoCNXobeT+csR6ov8bfK3T/cEJcUm4ns9Ue2T2azLsTIWcNZBvGoiEy4 21uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=eNQadqGdZTSW4kKhy0uD70+Pc86/E03Sj/V/lxDPE4w=; b=VpLdPL5a5drJkpMbfMjp2lP9iRd0hEHJVjWVNuwNz5OoPFiFzQnVjMicVHJ9WXA5xD xbWjmoK77Vmriw0xi4QJS2QQOpfDoOEtKRRN2ZwLw4bynnm/bpYFAUR5Htbq7vOB1N3y 2CskBrN786CuP+5PukRASoyM/ymainLn7u2bfG7+6/J/xC1nqgDpAQWDDGNF6UgQaJds Kn63vMxH93+3QV6iA/GE/n3qFZLfAnyqtOHHTJp0dZa5OpfL9TuXi/tvqsvSJ89y2g7e oB+DYFyT89xsO7SxQsE0bVwrSEiGvEU/BxFj8vRWyBZNGts2i6IRsjZ0NS+qg6J2ZNke hpNQ== X-Gm-Message-State: AKwxytdhNOxSMjO334vMcgGv5FV1B87atp/4jTMyxypFw3pB8pcsYCYO bKNHqrRo3AcGhv6jSuX3EIpv4A== X-Google-Smtp-Source: ACJfBouQVqJiXLEiMlfrti14UxwMiL+onEWk30dH0rTmXgxBCPbnK8jreR3ksPq3FKAE4PnfpSnjKQ== X-Received: by 10.159.214.134 with SMTP id n6mr3776734plp.333.1516040486872; Mon, 15 Jan 2018 10:21:26 -0800 (PST) Received: from localhost.localdomain (KD118152108246.ppp-bb.dion.ne.jp. [118.152.108.246]) by smtp.gmail.com with ESMTPSA id o25sm226678pgc.75.2018.01.15.10.21.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Jan 2018 10:21:26 -0800 (PST) From: Yoshihiro Kaneko To: linux-gpio@vger.kernel.org Cc: Linus Walleij , Simon Horman , Magnus Damm , Geert Uytterhoeven , linux-renesas-soc@vger.kernel.org Subject: [PATCH/RFT v3] gpio: gpio-rcar: Support S2RAM Date: Tue, 16 Jan 2018 03:20:26 +0900 Message-Id: <1516040426-15507-1-git-send-email-ykaneko0929@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Hien Dang This patch adds an implementation that saves and restores the state of GPIO configuration on suspend and resume. Signed-off-by: Hien Dang Signed-off-by: Takeshi Kihara [Modify structure of the bank info to simplify a saving registers] [Remove DEV_PM_OPS macro] Signed-off-by: Yoshihiro Kaneko --- This patch is based on the for-next branch of linux-gpio tree. v2 [Yoshihiro Kaneko] * Modify structure of the bank info as suggested by Geert Uytterhoeven v3 [Yoshihiro Kaneko] * Remove DEV_PM_OPS macro as suggested by Vladimir Zapolskiy drivers/gpio/gpio-rcar.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c index e76de57..88fbb3e 100644 --- a/drivers/gpio/gpio-rcar.c +++ b/drivers/gpio/gpio-rcar.c @@ -31,6 +31,16 @@ #include #include +struct gpio_rcar_bank_info { + u32 iointsel; + u32 inoutsel; + u32 outdt; + u32 active_high_rising_edge; + u32 level_trigger; + u32 both; + u32 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; }; #define IOINTSEL 0x00 /* General IO/Interrupt Switching Register */ @@ -531,11 +542,65 @@ static int gpio_rcar_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_PM_SLEEP +static int gpio_rcar_suspend(struct device *dev) +{ + struct gpio_rcar_priv *p = dev_get_drvdata(dev); + + p->bank_info.iointsel = gpio_rcar_read(p, IOINTSEL); + p->bank_info.inoutsel = gpio_rcar_read(p, INOUTSEL); + p->bank_info.outdt = gpio_rcar_read(p, OUTDT); + p->bank_info.intmsk = gpio_rcar_read(p, INTMSK); + p->bank_info.active_high_rising_edge = gpio_rcar_read(p, POSNEG); + p->bank_info.level_trigger = gpio_rcar_read(p, EDGLEVEL); + p->bank_info.both = gpio_rcar_read(p, BOTHEDGE); + + return 0; +} + +static int gpio_rcar_resume(struct device *dev) +{ + struct gpio_rcar_priv *p = dev_get_drvdata(dev); + int offset; + u32 mask; + + for (offset = 0; offset < p->gpio_chip.ngpio; offset++) { + mask = BIT(offset); + /* I/O pin */ + if (!(p->bank_info.iointsel & mask)) { + if (p->bank_info.inoutsel & mask) + gpio_rcar_direction_output( + &p->gpio_chip, offset, + !!(p->bank_info.outdt & mask)); + else + gpio_rcar_direction_input(&p->gpio_chip, + offset); + /* Interrupt pin */ + } else { + gpio_rcar_config_interrupt_input_mode( + p, + offset, + !(p->bank_info.active_high_rising_edge & mask), + !!(p->bank_info.level_trigger & mask), + !!(p->bank_info.both & mask)); + + if (p->bank_info.intmsk & mask) + gpio_rcar_write(p, MSKCLR, mask); + } + } + + return 0; +} +#endif /* CONFIG_PM_SLEEP*/ + +static SIMPLE_DEV_PM_OPS(gpio_rcar_pm_ops, gpio_rcar_suspend, gpio_rcar_resume); + static struct platform_driver gpio_rcar_device_driver = { .probe = gpio_rcar_probe, .remove = gpio_rcar_remove, .driver = { .name = "gpio_rcar", + .pm = &gpio_rcar_pm_ops, .of_match_table = of_match_ptr(gpio_rcar_of_table), } };