From patchwork Fri Jan 29 14:26:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Neeli X-Patchwork-Id: 12055973 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11705C433E0 for ; Fri, 29 Jan 2021 14:29:09 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AE52064DF1 for ; Fri, 29 Jan 2021 14:29:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE52064DF1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2ELpJZzT1tqKzz3SQ9aNrWYMVaf5WYLeNr8ECxd6gjY=; b=vr6Z+Dm6MaAFPGvuIIGVADCDB fEU8PZmblQvftVQagoRsHMRe/+1ruFGa73de6PPetJGs9rR+OIfoRIT4hSXcGXxBKaRK/ieJLAEeo /HfQuSV/z9gzUaJ27uH4mmWcfEbKIWj70HuUfsaOhzu96bboNQtXqyVGpPoLtbI3voWp50rO+XMyB b1uvjraobXyIc/fTFX1tdqcwEULBCNLi+PVO4hLn0KgUlonVk/cub7bMh69bjYMX2t5HoR28OYJbN GE4ZFc6VOvm5JtV+lD6xqmBU0cL/o8YAZD4loRuvQQ07GRLNZK+frjxw4TZr9VpEvewRH8TN/fimA 5ttJOc4CQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l5UkR-0006uO-Bn; Fri, 29 Jan 2021 14:27:43 +0000 Received: from mail-mw2nam12on2066.outbound.protection.outlook.com ([40.107.244.66] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l5UkL-0006t1-Gb for linux-arm-kernel@lists.infradead.org; Fri, 29 Jan 2021 14:27:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZtBpygQH9Igkf7uniVKlvDWLJJUQO57/1pYPd0yvRako9MSGYHFN8IIou40b4fezu/ffamYMNU67urxz4E28R1WFHoAKbM4QhGQoH30y4mR7K84v8zRDUTJe5G6sz5j1nc5dfvngtdPz4mtKK+SeGqvRER6GG2L95YlFGOaENqQzNFN6SqM0iBi68HOeALpSvJJtzojN7ZJ3Pd3Mq5PZUCCMUH1VFKpWYSzpqyXGqLx/kFQSXpUoeE3j6qVgmO+VUGp8XAOU7THbd/ZoSrKJEDZWz556EqB5MPasAlfnUJSe4PK3r8jkrt2LO103yBE3CiTRXdBigzmPXWC8ifYb1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yHB/ZOYHM4o04THjf6hn8/QAL0vR0QBlIauRkZ/2Ri0=; b=A2EDcOS5rrd1hIsohUd/tsVV6PVn2HUD6wjRZ1GCsUi9N4II7TRpH9QbtUWPIOpepkUINDkb95y3a0ShnH6Jt5KbbsWLEpyWc4cXCUZmcMYEYI3vRZz1EqRBlSvb9ItguJ80d0bd2Raf3R5gaHSxpdp6YH3SCzbBtp5T3FiXHJ4dpGJsEL8fgRauUL5e7BaK1Q65leI05bmjozmrT3U2plsrk+GsDWuHKjBiKep4rKO/Tz3wAqTow9LuTIcHfjJUoFXaj8M/yE2g+9nLoJohxEm4l9WKFd/bX6b629zpMjtl/TTJiERGHqgrlkQiG9L9uw6meCyE/1SJYUC9ZOBPDQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=linaro.org smtp.mailfrom=xilinx.com; dmarc=bestguesspass action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yHB/ZOYHM4o04THjf6hn8/QAL0vR0QBlIauRkZ/2Ri0=; b=SKAXE7jxM/Ho5MDX5baaBF5oeXacED117V8X3v2mic4YF9yKaqcCVJKsNHFUm1CJ9WRM9dJt5xCgsYQSIPYW6ImQf0CvVSQLohQo/aowoMfBhwzdfFwtxxMfMUYYeiGcInUSiijG1ag/MlNjyXi+oXj/lSVU0CCvWTv1qUhNNyU= Received: from SN7PR04CA0067.namprd04.prod.outlook.com (2603:10b6:806:121::12) by DM6PR02MB5849.namprd02.prod.outlook.com (2603:10b6:5:156::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.17; Fri, 29 Jan 2021 14:27:34 +0000 Received: from SN1NAM02FT004.eop-nam02.prod.protection.outlook.com (2603:10b6:806:121:cafe::ce) by SN7PR04CA0067.outlook.office365.com (2603:10b6:806:121::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.17 via Frontend Transport; Fri, 29 Jan 2021 14:27:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=bestguesspass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT004.mail.protection.outlook.com (10.152.72.175) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3784.12 via Frontend Transport; Fri, 29 Jan 2021 14:27:33 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1913.5; Fri, 29 Jan 2021 06:27:13 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.1913.5 via Frontend Transport; Fri, 29 Jan 2021 06:27:13 -0800 Received: from [10.140.6.6] (port=56658 helo=xhdappanad40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1l5Ujw-00005L-PX; Fri, 29 Jan 2021 06:27:13 -0800 From: Srinivas Neeli To: , , , , , , Subject: [PATCH V5 4/5] gpio: gpio-xilinx: Add support for suspend and resume Date: Fri, 29 Jan 2021 19:56:49 +0530 Message-ID: <1611930410-25747-5-git-send-email-srinivas.neeli@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1611930410-25747-1-git-send-email-srinivas.neeli@xilinx.com> References: <1611930410-25747-1-git-send-email-srinivas.neeli@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 06f13bcc-d00e-4504-bd36-08d8c46204c7 X-MS-TrafficTypeDiagnostic: DM6PR02MB5849: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vD8568F0Bj/pxgkWea5P/81ARsUTk7OQ4Rg+9fOOCs9Pco4XIAWZ/FTdXw2AcC5+4ZeuKPnnu1wA/qllBDwb/qXJbMAAehxr9BkFRuGm1vuDr3ben0H9IBabxz2Ldfay2SSweH/g2p6zD/4+fHZu2hs7vRrV0LU8ZugJxVF2XEwiMz7vkSD6LOiR0dIhQMpG/5jw92oT798wohUgnI5tmpXu4wEdPzi1jjFo1hDpGlyc95n5XNUA/EBoTU9t0tkDQeV0i0fFHE47YJsSt5uvInd7rVTrmqzFsDfeb92PCrEXW8wZJvkdwLGTuvchYnEXFPrsXQoLE29Bh1Xvt3QF2u/Dok1R+rFBVp0ZRfUAYi5XAT9rQkj/KiYv8+mOK+ByPquQpUwujDG223O03h0BEoJGhxw6pOg0LD/hcb7CEQVhKRu4MudEH0+ORaXTsbnfrnjdzaqtkuV8/is3Bt/2dXmC2lurJLSAFk38jDi63Aw1UKO4ekmUXwdPy6EiNSIuEHuXWXl67aEouRaJ2FniNorYHmdos4bPMnF54UXuLCnxx+OMcsIXECMsHx4fMbTB6LlN1Fhg02s48erKxCtLAR41cuPA4skqdI4HKDgFkPeSzTQtVfiDwVm6DHL86I6z X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch02.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(136003)(396003)(376002)(39860400002)(346002)(46966006)(478600001)(82310400003)(107886003)(2906002)(9786002)(54906003)(8936002)(4326008)(6666004)(8676002)(7636003)(336012)(2616005)(82740400003)(70586007)(15650500001)(70206006)(36906005)(47076005)(356005)(26005)(186003)(36756003)(110136005)(83380400001)(7696005)(426003)(316002)(44832011)(5660300002)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2021 14:27:33.8093 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 06f13bcc-d00e-4504-bd36-08d8c46204c7 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT004.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR02MB5849 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210129_092737_600655_FC22FEF1 X-CRM114-Status: GOOD ( 21.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-gpio@vger.kernel.org, Srinivas Neeli , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, git@xilinx.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add support for suspend and resume, pm runtime suspend and resume. Added free and request calls. Signed-off-by: Srinivas Neeli Reviewed-by: Linus Walleij --- Changes in V5: -Updated xgpio_remove function with review comments. -The normal sequence for remove function is: pm_runtime_get_sync(dev); pm_runtime_put_noidle(dev); pm_runtime_disable(dev); Changes in V4: -Adjust code to remove conflicts. Changes in V3: -Created new patch for suspend and resume. --- drivers/gpio/gpio-xilinx.c | 92 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c index 62deb755f910..acd574779ca6 100644 --- a/drivers/gpio/gpio-xilinx.c +++ b/drivers/gpio/gpio-xilinx.c @@ -16,6 +16,7 @@ #include #include #include +#include #include /* Register Offset Definitions */ @@ -278,6 +279,39 @@ static void xgpio_save_regs(struct xgpio_instance *chip) chip->gpio_dir[1]); } +static int xgpio_request(struct gpio_chip *chip, unsigned int offset) +{ + int ret; + + ret = pm_runtime_get_sync(chip->parent); + /* + * If the device is already active pm_runtime_get() will return 1 on + * success, but gpio_request still needs to return 0. + */ + return ret < 0 ? ret : 0; +} + +static void xgpio_free(struct gpio_chip *chip, unsigned int offset) +{ + pm_runtime_put(chip->parent); +} + +static int __maybe_unused xgpio_suspend(struct device *dev) +{ + struct xgpio_instance *gpio = dev_get_drvdata(dev); + struct irq_data *data = irq_get_irq_data(gpio->irq); + + if (!data) { + dev_err(dev, "irq_get_irq_data() failed\n"); + return -EINVAL; + } + + if (!irqd_is_wakeup_set(data)) + return pm_runtime_force_suspend(dev); + + return 0; +} + /** * xgpio_remove - Remove method for the GPIO device. * @pdev: pointer to the platform device @@ -290,6 +324,9 @@ static int xgpio_remove(struct platform_device *pdev) { struct xgpio_instance *gpio = platform_get_drvdata(pdev); + pm_runtime_get_sync(&pdev->dev); + pm_runtime_put_noidle(&pdev->dev); + pm_runtime_disable(&pdev->dev); clk_disable_unprepare(gpio->clk); return 0; @@ -305,6 +342,46 @@ static void xgpio_irq_ack(struct irq_data *irq_data) { } +static int __maybe_unused xgpio_resume(struct device *dev) +{ + struct xgpio_instance *gpio = dev_get_drvdata(dev); + struct irq_data *data = irq_get_irq_data(gpio->irq); + + if (!data) { + dev_err(dev, "irq_get_irq_data() failed\n"); + return -EINVAL; + } + + if (!irqd_is_wakeup_set(data)) + return pm_runtime_force_resume(dev); + + return 0; +} + +static int __maybe_unused xgpio_runtime_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct xgpio_instance *gpio = platform_get_drvdata(pdev); + + clk_disable(gpio->clk); + + return 0; +} + +static int __maybe_unused xgpio_runtime_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct xgpio_instance *gpio = platform_get_drvdata(pdev); + + return clk_enable(gpio->clk); +} + +static const struct dev_pm_ops xgpio_dev_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(xgpio_suspend, xgpio_resume) + SET_RUNTIME_PM_OPS(xgpio_runtime_suspend, + xgpio_runtime_resume, NULL) +}; + /** * xgpio_irq_mask - Write the specified signal of the GPIO device. * @irq_data: per IRQ and chip data passed down to chip functions @@ -546,6 +623,8 @@ static int xgpio_probe(struct platform_device *pdev) chip->gc.of_gpio_n_cells = cells; chip->gc.get = xgpio_get; chip->gc.set = xgpio_set; + chip->gc.request = xgpio_request; + chip->gc.free = xgpio_free; chip->gc.set_multiple = xgpio_set_multiple; chip->gc.label = dev_name(&pdev->dev); @@ -565,6 +644,9 @@ static int xgpio_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Failed to prepare clk\n"); return status; } + pm_runtime_get_noresume(&pdev->dev); + pm_runtime_set_active(&pdev->dev); + pm_runtime_enable(&pdev->dev); xgpio_save_regs(chip); @@ -595,7 +677,7 @@ static int xgpio_probe(struct platform_device *pdev) GFP_KERNEL); if (!girq->parents) { status = -ENOMEM; - goto err_unprepare_clk; + goto err_pm_put; } girq->parents[0] = chip->irq; girq->default_type = IRQ_TYPE_NONE; @@ -605,12 +687,15 @@ static int xgpio_probe(struct platform_device *pdev) status = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip); if (status) { dev_err(&pdev->dev, "failed to add GPIO chip\n"); - goto err_unprepare_clk; + goto err_pm_put; } + pm_runtime_put(&pdev->dev); return 0; -err_unprepare_clk: +err_pm_put: + pm_runtime_disable(&pdev->dev); + pm_runtime_put_noidle(&pdev->dev); clk_disable_unprepare(chip->clk); return status; } @@ -628,6 +713,7 @@ static struct platform_driver xgpio_plat_driver = { .driver = { .name = "gpio-xilinx", .of_match_table = xgpio_of_match, + .pm = &xgpio_dev_pm_ops, }, };