From patchwork Thu Sep 28 09:46:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Izard X-Patchwork-Id: 9975603 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 B3BFA6034B for ; Thu, 28 Sep 2017 09:47:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4A242953C for ; Thu, 28 Sep 2017 09:47:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9957B29544; Thu, 28 Sep 2017 09:47:23 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable 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 10BA52953C for ; Thu, 28 Sep 2017 09:47:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752797AbdI1JrK (ORCPT ); Thu, 28 Sep 2017 05:47:10 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:37814 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752376AbdI1Jqt (ORCPT ); Thu, 28 Sep 2017 05:46:49 -0400 Received: by mail-wr0-f195.google.com with SMTP id u48so1477916wrf.4; Thu, 28 Sep 2017 02:46:47 -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=DYO+ppTxC9gCfPpg2w/pl8TnhNlCr/mYGjXJz2lkQOQ=; b=J9GFVGDZXnZURnWkSIqp3uXXw+0MZue1tcSe/cxMxwpMPqoRaijKQWkBmXF3BVBRBw xw+aUlubeitymUtgeEqOXCAPS1d56loKhRwAVs65/+3twAfL03mp92ACLqwUOuzyHq4d BtErtxP7W1NrevaUfpwJciZtL4AwLykbTqBsavaiqE3IaYMX/3Zs+bjhh0Q/LroKN17Z QAcTfwZKCwLWQWSmfd7TsGy12kVWdfXEI1R6ujrE0lNj9dhNKIaXogk23dqRMTB9Q5vv ODgVQEazqTFWAh6wTXR0VlNlSxPjgpTwN0n5DPo7xAvM5m2KtFoKLfcm0dTd8qbVZlIq Kg1w== 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=DYO+ppTxC9gCfPpg2w/pl8TnhNlCr/mYGjXJz2lkQOQ=; b=ihDz4pr6YTS647b/Bz3s4s5kiq5rcJ5bZNjnFxhi/ptJTSAN+l9tCbBdHVTv8edpDu ycdYW4mrPBXhtRvDV4beaJOorq7BReDFmod2gLB9hCuKZjNkvhMwcoPhD4veXQiu5hAL AQGDSKy7jES80czwbRJRh0RZtOPcE8THKBOOLRPi1d+J1uH1xorcNvhIydvYycXuXUmR jim/AAnbFirrznn2pB0ppf290zaELwOEuj9QwylGgp/Z/5Sp6nbH2XJ92EsTJfyaer2Q 6cyMozRHgjSaH2PIS2UQDYD8n5qEQah6zt4Ppea9uj0lbKlhVVwblnrFvQqb6pwlKx95 DLNg== X-Gm-Message-State: AHPjjUjdz1NzTWnOdEY9OnY6tT4lLfM21CBpfyKSYIG8CMU7LZHwrsOt tkZZRQp6QHe82dHntsHB8hw= X-Google-Smtp-Source: AOwi7QBn7ngLbKtJg0fnyN1NGRfv5L7NcSHOM/PJY5tqELhSYx+XC0SWV2dK0hJWUJT/v73RKbDstw== X-Received: by 10.223.166.196 with SMTP id t62mr3939653wrc.251.1506592007376; Thu, 28 Sep 2017 02:46:47 -0700 (PDT) Received: from localhost.localdomain (146.187.3.109.rev.sfr.net. [109.3.187.146]) by smtp.gmail.com with ESMTPSA id z10sm3272395wre.6.2017.09.28.02.46.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Sep 2017 02:46:46 -0700 (PDT) From: Romain Izard To: Boris Brezillon , Michael Turquette , Stephen Boyd , Lee Jones , Wenyou Yang , Josh Wu , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Cyrille Pitchen , Thierry Reding , Richard Genoud , Greg Kroah-Hartman , Jiri Slaby , Alan Stern , Ludovic Desroches , Nicolas Ferre , Alexandre Belloni Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-pwm@vger.kernel.org, linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, Romain Izard Subject: [PATCH v4 7/8] atmel_flexcom: Support backup mode Date: Thu, 28 Sep 2017 11:46:26 +0200 Message-Id: <20170928094627.31017-8-romain.izard.pro@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170928094627.31017-1-romain.izard.pro@gmail.com> References: <20170928094627.31017-1-romain.izard.pro@gmail.com> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.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 --- 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, }, };