From patchwork Tue Dec 12 16:21:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Izard X-Patchwork-Id: 10107831 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 35D9C602C2 for ; Tue, 12 Dec 2017 16:27:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27A2929A41 for ; Tue, 12 Dec 2017 16:27:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B38929A67; Tue, 12 Dec 2017 16:27:50 +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 A122E29A41 for ; Tue, 12 Dec 2017 16:27:49 +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=SADI6kQ0w9VaSQrJawU35KyhxKExbFmp2jrL5/f84iQ=; b=m8t tvTFGYGDAeh0w9PSmBX89AEQSM0ppRRoIJsC0C6yZlJmi+6VfMBZEZ3lIxGAL/+ESVITGRRjXuI+c 0NTnuGBGKHo7jgsBBWYQIUcv+xnq0ZNbhuHROZns6KLEAh4oyFP433rUOBiKY0IT+vth/0ayBNxiH 9at99Ada0LQU8Z7nysiyJsi4T1V2IhJkTojYZDjXIUwF/uNbdSWXjGFRq8gwjTzjmm4cI+Eo5WZAK NofL5nwVTZLFeX+mY9+7OzXEI4CCWAk//H3aIytFK8bo8jipkf/CKOaAjpMgEwhWp99EX0OdaceWJ dkLjeLnV76zUWQt49TuqJGc5Uf8DQtw==; 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 1eOnPJ-0002Ik-8t; Tue, 12 Dec 2017 16:27:49 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eOnPG-0002Ei-4G for linux-arm-kernel@lists.infradead.org; Tue, 12 Dec 2017 16:27:48 +0000 Received: by mail-wm0-x244.google.com with SMTP id 64so21352318wme.3 for ; Tue, 12 Dec 2017 08:27:25 -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=ZBCbsjdaOb/mhAp9eZTg2dvuresiEyOo8Upbsb7kpt0=; b=pQmDOwV8JFPgozqmWgN0bN5UERwsyf9x8XPhajgc41antB2WfRiqgt6Rf3r1izaBlL 9qAW6EkClK+dWWYnCrdvpLAmEHO+Xhh39PXOiTnztw4OyoKt9Sobo5gsa4FUOjI/cU7D IEd7mSkwQUXOCNcUA1zDuMxLNZKRfK3ahTvnqNN/QoKOAEWLp2rJDNOjvoRlkt45C/uX GoRVaGfAceoQDxQSGERt0qMYGibW7Kuks0biB9RADB/npDqtLWle8bxY04nn2ipbQoGD OLaHmuSluBBpBPONPNdUJiinh8b5GUkszDLGrl987YdHk9HTTn2N8IZJM2Zwt3F7kNjE vhAQ== 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=ZBCbsjdaOb/mhAp9eZTg2dvuresiEyOo8Upbsb7kpt0=; b=HvD487YWeFcS0/jYBVmKqlBfJuas8oiYG37IAPs5Vg8s+TvtnMy4h5/ANKJpU8XWbC fK80yy/wcwjpWlj/6eW1p/aVn47EoCkZBQE11QP/scdHOdrYqA0XnbZm/6GiQqAzsFYa 1Ts3l7kZlUBdWhl9sjy839Ecvmj8c5lwnL6bfsfY3C2ezFgVpVEfQKVbAh9PRaI/yPjT TCTtXR9D7ys+85V8d4Z1mJThlLV5/EG9FzGhsjUPa/u/sX1QtY/PGBs+Lg7529MBWj9q OZ8JB7M1Is4f0CVaS9aJpg686EOUwtJpNNGeGMivbjzoWbhiIfJFNOAzTMhY8u9Kt+na vY4w== X-Gm-Message-State: AKGB3mJn9oNilF1/NP4SOjod6dXjl7zRirenFf4Thm5kHgHFsdDLZ+Mv ZFj2lOhojG1Nux0fGcjDhcHSdg== X-Google-Smtp-Source: ACJfBovDzUAQFKhLlp56rK7EgIPSzZGac4H32eubkX95y7Pj/LHTt6mUiuO0ZJxRNUKVCqdVGRbyPA== X-Received: by 10.28.154.7 with SMTP id c7mr2100060wme.80.1513096044199; Tue, 12 Dec 2017 08:27:24 -0800 (PST) Received: from localhost.localdomain (146.187.3.109.rev.sfr.net. [109.3.187.146]) by smtp.gmail.com with ESMTPSA id q74sm13125513wmg.22.2017.12.12.08.27.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 08:27:23 -0800 (PST) From: Romain Izard To: Lee Jones , Alexandre Belloni , Nicolas Ferre Subject: [PATCH v6] atmel_flexcom: Support resuming after a chip reset Date: Tue, 12 Dec 2017 17:21:19 +0100 Message-Id: <20171212162119.32138-1-romain.izard.pro@gmail.com> X-Mailer: git-send-email 2.14.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171212_082746_333614_6F148333 X-CRM114-Status: GOOD ( 15.86 ) 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. In the suspend mode called "backup with self-refresh" available on SAMA5D2, the chip will resume with most of its registers reset. In this case, we need to restore the state of the flexcom driver on resume. Signed-off-by: Romain Izard Acked-by: Alexandre Belloni Acked-by: Nicolas Ferre Tested-by: Nicolas Ferre --- Changes in v5: * extract from the patch series, and send as a standalone patch Changes in v6: * Reword the patch title and description * Rename the internal structure to ddata drivers/mfd/atmel-flexcom.c | 63 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/drivers/mfd/atmel-flexcom.c b/drivers/mfd/atmel-flexcom.c index 064bde9cff5a..f684a93a3340 100644 --- a/drivers/mfd/atmel-flexcom.c +++ b/drivers/mfd/atmel-flexcom.c @@ -39,34 +39,43 @@ #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 *ddata; int err; - err = of_property_read_u32(np, "atmel,flexcom-mode", &opmode); + ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); + if (!ddata) + return -ENOMEM; + + platform_set_drvdata(pdev, ddata); + + err = of_property_read_u32(np, "atmel,flexcom-mode", &ddata->opmode); if (err) return err; - if (opmode < ATMEL_FLEXCOM_MODE_USART || - opmode > ATMEL_FLEXCOM_MODE_TWI) + if (ddata->opmode < ATMEL_FLEXCOM_MODE_USART || + ddata->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); + ddata->base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(ddata->base)) + return PTR_ERR(ddata->base); - clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(clk)) - return PTR_ERR(clk); + ddata->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(ddata->clk)) + return PTR_ERR(ddata->clk); - err = clk_prepare_enable(clk); + err = clk_prepare_enable(ddata->clk); if (err) return err; @@ -76,9 +85,9 @@ 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); + writel(FLEX_MR_OPMODE(ddata->opmode), ddata->base + FLEX_MR); - clk_disable_unprepare(clk); + clk_disable_unprepare(ddata->clk); return devm_of_platform_populate(&pdev->dev); } @@ -89,10 +98,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 *ddata = dev_get_drvdata(dev); + int err; + u32 val; + + err = clk_prepare_enable(ddata->clk); + if (err) + return err; + + val = FLEX_MR_OPMODE(ddata->opmode), + writel(val, ddata->base + FLEX_MR); + + clk_disable_unprepare(ddata->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, }, };