From patchwork Fri Sep 8 15:36:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Izard X-Patchwork-Id: 9944605 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 0407960224 for ; Fri, 8 Sep 2017 15:52:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2B2328516 for ; Fri, 8 Sep 2017 15:52:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C74BA28814; Fri, 8 Sep 2017 15:52:01 +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=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5294128516 for ; Fri, 8 Sep 2017 15:52:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=KZQ9m0FHJgT5pvLZyaJhO6qt7zD5xYvyh0LZM4IB7UI=; b=eSYqwPCJLgY/e1M5QjpeJgEjh8 hE1BfACjFY3HndJLdJlO212J/HAgOfu5f1O/TsB0AkGxepmB8I490Sq3NCuL1VFLb/g/5dwJYEbjn O3uYx27eDB6Y89lSIzTQuUmTpUiYVceAeO9pR40NuueShdd+Y7Dlh6iDHa/e+RFBnwGWvosDDZXyu GpOfNPQxmogh/5Jr14Zmwd+3za2uD+mUbzBf7HVPdyPzy5lXMtQHLObPbSBukzZz8y7kjld5BtwOa zsYaZSSCNqJ0sGdQayCwQR9r6QkPc0QEmhkkJ3FfAWI5N+6BS2MuZ2ZPaaj+3KXVAQSF+l5HmVHiC zc7RTzhA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dqLZY-0000rZ-Dy; Fri, 08 Sep 2017 15:52:00 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dqLKr-00068v-OL; Fri, 08 Sep 2017 15:36:57 +0000 Received: by mail-wr0-x243.google.com with SMTP id b9so1418764wra.0; Fri, 08 Sep 2017 08:36:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ODEsLfkb3lvipUolMLb7ScB3ja2VrqHu5R+0EqPP1yQ=; b=kQlJKNEOAJMGPm/b6tnfxUlVl2kT6QoNOIRe5QWkqQqCxB9FfRN7t+V9bY8rvDE2H1 EFhXSyYLHX8BeOXM0j1GWFn+SvSGFe2zzXYVxnmJZ4S18sDK/W5DHggP6pS0W+RFWgxX 9FH4Q8iOGOjwk3CBvvPOFL89UK6lm7cSpCOLens3ciAbUTHnvW1frRW5ZD631hWQMKk/ qfLnFagoIiAPK4fVSqLaCVNWDs+mBOAco04yxKJLuHeZ7M7mLvPJDyKzbj6fk9B5b4Df 8od2rk4gjn/oh1E3bedRfkgjF8gEKviKh00GNMcDoG7++AT+oyzFbQdm5gC87L0xU0J+ Ro3w== 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:in-reply-to :references; bh=ODEsLfkb3lvipUolMLb7ScB3ja2VrqHu5R+0EqPP1yQ=; b=WgKZjR6sXF8M57iOeonv7BgeI5EH5OpFgfNP7aDRmAhPi4fWO/hBv5vjEJTPBU96ng fYQXDe+X/ny+0WvJHy6QBUVUbz1CUW8EOB45aAv/aQy3hKDvPg52hyYphncrtHyavr0j 17bzxFT+nDdalbe7avONzu+Cghhn5Bsj1Tgr8P+jE9kE6Uj3J1Cwzismy8bd+B9kbNc8 wzB7oDMoazed5eotuXRX/EX9r+JX/M3tGNyYjE1ixULvawHuJ2BfuDHoPtWYW7zA10xp HXn8mPTjdtJ5TyVMnLBex/MpgQoIH/lN7VcZQsQHDxNzlDh1pFudeOF1QPy/h2/wuzK5 S/iw== X-Gm-Message-State: AHPjjUjwxK/0xcyH/jupEtAqVlO14sftToouVb48xaPterAAbdPCKg2a Nwo8aTyBq1Fy/w== X-Google-Smtp-Source: ADKCNb7h6mmGG+LclTSLdoGtlEcr/ag/nvgWL/WEteUruwWBbuJoERN9oSXBzzmou6krUjyx1tllDw== X-Received: by 10.223.157.3 with SMTP id k3mr2436226wre.122.1504884988002; Fri, 08 Sep 2017 08:36:28 -0700 (PDT) Received: from localhost.localdomain (146.187.3.109.rev.sfr.net. [109.3.187.146]) by smtp.gmail.com with ESMTPSA id p199sm1689224wmb.28.2017.09.08.08.36.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Sep 2017 08:36:27 -0700 (PDT) From: Romain Izard To: Nicolas Ferre , Boris Brezillon , Michael Turquette , Stephen Boyd , Ludovic Desroches , Jonathan Cameron , Wenyou Yang , Josh Wu , David Woodhouse , Brian Norris , Marek Vasut , Cyrille Pitchen , Thierry Reding , Richard Genoud , Greg Kroah-Hartman , Alan Stern Subject: [PATCH v1 09/10] atmel_flexcom: Support backup mode Date: Fri, 8 Sep 2017 17:36:03 +0200 Message-Id: <20170908153604.28383-10-romain.izard.pro@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170908153604.28383-1-romain.izard.pro@gmail.com> References: <20170908153604.28383-1-romain.izard.pro@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170908_083650_292664_453948F6 X-CRM114-Status: GOOD ( 14.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, linux-iio@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-serial@vger.kernel.org, Romain Izard , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The controller used by a flexcom module is configured at boot, and left alone after this. As the configuration will be lost after backup mode, restore the state of the flexcom driver on resume. Signed-off-by: Romain Izard --- drivers/mfd/atmel-flexcom.c | 65 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/drivers/mfd/atmel-flexcom.c b/drivers/mfd/atmel-flexcom.c index 064bde9cff5a..ef1235c4a179 100644 --- a/drivers/mfd/atmel-flexcom.c +++ b/drivers/mfd/atmel-flexcom.c @@ -39,34 +39,44 @@ #define FLEX_MR_OPMODE(opmode) (((opmode) << FLEX_MR_OPMODE_OFFSET) & \ FLEX_MR_OPMODE_MASK) +struct atmel_flexcom { + void __iomem *base; + u32 opmode; + struct clk *clk; +}; static int atmel_flexcom_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; - struct clk *clk; struct resource *res; - void __iomem *base; - u32 opmode; + struct atmel_flexcom *afc; int err; + u32 val; + + afc = devm_kzalloc(&pdev->dev, sizeof(*afc), GFP_KERNEL); + if (!afc) + return -ENOMEM; - err = of_property_read_u32(np, "atmel,flexcom-mode", &opmode); + platform_set_drvdata(pdev, afc); + + err = of_property_read_u32(np, "atmel,flexcom-mode", &afc->opmode); if (err) return err; - if (opmode < ATMEL_FLEXCOM_MODE_USART || - opmode > ATMEL_FLEXCOM_MODE_TWI) + if (afc->opmode < ATMEL_FLEXCOM_MODE_USART || + afc->opmode > ATMEL_FLEXCOM_MODE_TWI) return -EINVAL; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - base = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(base)) - return PTR_ERR(base); + afc->base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(afc->base)) + return PTR_ERR(afc->base); - clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(clk)) - return PTR_ERR(clk); + afc->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(afc->clk)) + return PTR_ERR(afc->clk); - err = clk_prepare_enable(clk); + err = clk_prepare_enable(afc->clk); if (err) return err; @@ -76,9 +86,10 @@ static int atmel_flexcom_probe(struct platform_device *pdev) * inaccessible and are read as zero. Also the external I/O lines of the * Flexcom are muxed to reach the selected device. */ - writel(FLEX_MR_OPMODE(opmode), base + FLEX_MR); + val = FLEX_MR_OPMODE(afc->opmode); + writel(val, afc->base + FLEX_MR); - clk_disable_unprepare(clk); + clk_disable_unprepare(afc->clk); return devm_of_platform_populate(&pdev->dev); } @@ -89,10 +100,34 @@ static const struct of_device_id atmel_flexcom_of_match[] = { }; MODULE_DEVICE_TABLE(of, atmel_flexcom_of_match); +#ifdef CONFIG_PM_SLEEP +static int atmel_flexcom_resume(struct device *dev) +{ + struct atmel_flexcom *afc = dev_get_drvdata(dev); + int err; + u32 val; + + err = clk_prepare_enable(afc->clk); + if (err) + return err; + + val = FLEX_MR_OPMODE(afc->opmode), + writel(val, afc->base + FLEX_MR); + + clk_disable_unprepare(afc->clk); + + return 0; +} +#endif + +static SIMPLE_DEV_PM_OPS(atmel_flexcom_pm_ops, NULL, + atmel_flexcom_resume); + static struct platform_driver atmel_flexcom_driver = { .probe = atmel_flexcom_probe, .driver = { .name = "atmel_flexcom", + .pm = &atmel_flexcom_pm_ops, .of_match_table = atmel_flexcom_of_match, }, };