From patchwork Thu Oct 19 16:44:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Izard X-Patchwork-Id: 10017727 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 7005B60224 for ; Thu, 19 Oct 2017 16:45:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61B7B28D98 for ; Thu, 19 Oct 2017 16:45:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 563F628DA3; Thu, 19 Oct 2017 16:45:51 +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 DAF8E28D98 for ; Thu, 19 Oct 2017 16:45:50 +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: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:In-Reply-To: References:List-Owner; bh=GeHKnWtjmKRAVuW+8OXllupBJzSTivqCkx/hI5ktmLk=; b=Wpn r59T4+kFV6tffDvX0eL6opFwtszhk+laJKPN0edb4KFgVgk08vh7sseO7oiycxUC5c3JEujJitJ6L mPmwB0TTmVjTKlE9CVu/nO3u/8jcl6XXX3jC6WIE2IunSTeGanlKGWrUg4LIQn/v6agSIPBIBrvk1 6sBYHHXlNAp1QyvIuyfheAIf6PCdP7oPKiWXdTohIeyKu0E2/QbqMd1RciOtR0aroR774qauH2B3H j1lf6NTdhoDuyNzAlWHnRhjFZdLibxOBm3reOJcQZO7pTFbVwDmZgQf17/m7/hckWaQYs/83+MNi3 7T0fwaTgTB01APxaLJlnVGp3pxPWcLg==; 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 1e5Dx8-0001UT-Az; Thu, 19 Oct 2017 16:45:50 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e5DwZ-0008Hz-IF for linux-arm-kernel@lists.infradead.org; Thu, 19 Oct 2017 16:45:40 +0000 Received: by mail-wm0-x241.google.com with SMTP id q132so17594820wmd.2 for ; Thu, 19 Oct 2017 09:44:55 -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; bh=6iNdvxBLUbk+N1wyyqdPIm5Zg2zB1y6AGv0i89TbZok=; b=jgbaXTz/cKKQjgfgunNqJTl3nGtuNigOtvstNcfN5K33j/CQuDAB77tB1Ec99DMSgT PFWVd6ccw6KPlcsD50EIuay5WtabD/Z6cTNvziRDyDz76HjTj0hKISgDSXo2Nqzg+7LN IabidQQTmJP7K+Xz2/0asUbWT/J1fF46cOYIN7DRAEWSjZtcRzsGKqfu3ODHJLMM/GzP 126YHecK9+K/oSnP07Qj/geRJ83+rp1iPl0aMTI69g5Q/RxlsipCKmv0g28e0RRZPJV9 LLEEJ3jsmWaL13wweF5uziEIK9CYAZ59MqNrtapdYFLG2qGtzGcE+e0X53SM5WvgXB5t dT7A== 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=6iNdvxBLUbk+N1wyyqdPIm5Zg2zB1y6AGv0i89TbZok=; b=fJdBr4oWnMk38iI+GLCqIrtkw7hpg6jLcjJ7vzlP9IHDP7g4m3wtJvaX11pPVOWGqQ gCXn0fK3I6OX663CRjP4ch9GwkoczXuQ5TrOUPV0jzSN9HDbU/XgKBXXweQkPxOD0Ckf GlZSuS2oJclgfZb3pQR1kwVXuyUdWyQbtGwow31mQnXPQLKZbs5sWM/bnxClxaBIDkSM ExrUwCJUjjpR3fKWafEkXErAgzoSl0E5So1bCsyCD8XsV6/XcomMPXsIIUG3slzrnWTq hQUlrSR6UbDmwh7ILa6B4jvtEL7BY0Ni8KpkDrQ3iCEVmqBKUvHjHtplnnI1uroKzjAI 7JHQ== X-Gm-Message-State: AMCzsaU/K89OLbAD7zWvjocjCBi9BMqIoDH4/jFWhWU1YKMHhU9+yS4y xdDZ+TfWyvjzy9378ZuxLLfC9A== X-Google-Smtp-Source: ABhQp+RWuhVFTaBw3zh/S+WwuinvI4MCZ0WSOSuDd7KwTI+1nGS8kRBU7bABIthdCv94HByWDhJBtg== X-Received: by 10.28.138.133 with SMTP id m127mr2420714wmd.134.1508431494138; Thu, 19 Oct 2017 09:44:54 -0700 (PDT) Received: from localhost.localdomain (146.187.3.109.rev.sfr.net. [109.3.187.146]) by smtp.gmail.com with ESMTPSA id p13sm7764636wre.24.2017.10.19.09.44.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Oct 2017 09:44:53 -0700 (PDT) From: Romain Izard To: Lee Jones , Alexandre Belloni , Nicolas Ferre Subject: [PATCH v5] atmel_flexcom: Support backup mode Date: Thu, 19 Oct 2017 18:44:43 +0200 Message-Id: <20171019164443.487-1-romain.izard.pro@gmail.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171019_094516_166244_51E39D74 X-CRM114-Status: GOOD ( 15.66 ) 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: Romain Izard , linux-kernel@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 Acked-by: Nicolas Ferre Tested-by: Nicolas Ferre Acked-by: Lee Jones --- Changes in v5: * extract from the patch series, and send as a standalone patch 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, }, };