From patchwork Wed Mar 26 16:39:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 334016 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 21AA114007E for ; Thu, 27 Mar 2014 04:13:40 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSr8z-0005sE-Oj; Wed, 26 Mar 2014 16:57:38 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSquH-0004oV-9s; Wed, 26 Mar 2014 16:42:25 +0000 Received: from mail-wi0-f179.google.com ([209.85.212.179]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSqsM-0004Yi-KB for linux-mtd@lists.infradead.org; Wed, 26 Mar 2014 16:40:40 +0000 Received: by mail-wi0-f179.google.com with SMTP id f8so2043425wiw.12 for ; Wed, 26 Mar 2014 09:40:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=z3YAxJ4i1RTF2u7MguyWn85uuWwHQ3i4nHWf9ySXQb8=; b=L4tQlaE7nz0O9GPinnxK9OPP8Q30zNZPVw8e0uUWqDGOX0q9OhCuGz2/AkupgJrjOo L5VGYxLoSw1hBXH88qFPJsWrIxvobjVm17paL0KgYIZFRMGNtyzmsfM+HoG6Pej2iQSb sQCgOMgi67CoP5gIKc7KVSmYmKxtWD1DVmAwkc17ED4Jci6fBHkMUnpGQKi13qpmhXW2 tqcbl3b+839/IIGQ3+OdnIhsH9vCjIKKUlFGZn0dXuCBrEiT8fNd5K7mZnlFCRg6zTcl N1g43rFemffQ/JoBc/xfJ4g65uQSwsy8E2BXoZ4Q6deKoIjTeWrWgkHD/Pa+3j+BFxHM XWKg== X-Gm-Message-State: ALoCoQmegElfLi0Q0IMxFOIjfD8H/eM4ncVpH9toaf1LLmydiPU00bN86Q2PE/Ll2N6/FSD4vBFQ X-Received: by 10.180.96.66 with SMTP id dq2mr30775204wib.54.1395852005107; Wed, 26 Mar 2014 09:40:05 -0700 (PDT) Received: from lee--X1.home (host109-148-113-193.range109-148.btcentralplus.com. [109.148.113.193]) by mx.google.com with ESMTPSA id gp10sm3913806wib.13.2014.03.26.09.40.03 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 26 Mar 2014 09:40:04 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/15] mtd: st_spi_fsm: Obtain and use EMI clock if provided Date: Wed, 26 Mar 2014 16:39:22 +0000 Message-Id: <1395851969-13520-9-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1395851969-13520-1-git-send-email-lee.jones@linaro.org> References: <1395851969-13520-1-git-send-email-lee.jones@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140326_124026_866569_B85FE72F X-CRM114-Status: GOOD ( 15.56 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.179 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-mtd@lists.infradead.org, computersforpeace@gmail.com, lee.jones@linaro.org, kernel@stlinux.com, angus.clark@st.com X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org ST's Common Clk Framework is now available. This patch ensures the FSM makes use of it by obtaining and enabling the EMI clock if provided. If system fails to provide the EMI clock FSM uses its original default rate. Signed-off-by: Lee Jones --- drivers/mtd/devices/st_spi_fsm.c | 45 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index 9df59e7..2443757 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "serial_flash_cmds.h" @@ -297,6 +298,7 @@ struct stfsm { struct mtd_info mtd; struct mutex lock; struct flash_info *info; + struct clk *clk; uint32_t configuration; uint32_t fifo_dir_delay; @@ -1941,8 +1943,13 @@ static void stfsm_set_freq(struct stfsm *fsm, uint32_t spi_freq) uint32_t emi_freq; uint32_t clk_div; - /* TODO: Make this dynamic */ - emi_freq = STFSM_DEFAULT_EMI_FREQ; + if (!fsm->clk) { + dev_warn(fsm->dev, + "No EMI clock available. Using default 100MHz.\n"); + + emi_freq = STFSM_DEFAULT_EMI_FREQ; + } else + emi_freq = clk_get_rate(fsm->clk); /* * Calculate clk_div - values between 2 and 128 @@ -2092,6 +2099,15 @@ static int stfsm_probe(struct platform_device *pdev) return PTR_ERR(fsm->base); } + fsm->clk = devm_clk_get(&pdev->dev, "emi_clk"); + if (IS_ERR(fsm->clk)) { + dev_warn(fsm->dev, "Couldn't find EMI clock.\n"); + fsm->clk = NULL; + } else if (clk_prepare_enable(fsm->clk)) { + dev_warn(fsm->dev, "Failed to enable EMI clock.\n"); + fsm->clk = NULL; + } + mutex_init(&fsm->lock); ret = stfsm_init(fsm); @@ -2156,6 +2172,30 @@ static int stfsm_remove(struct platform_device *pdev) return mtd_device_unregister(&fsm->mtd); } +#ifdef CONFIG_PM +static int stfsmfsm_suspend(struct device *dev) +{ + struct stfsm *fsm = dev_get_drvdata(dev); + + if (fsm->clk) + clk_disable_unprepare(fsm->clk); + + return 0; +} + +static int stfsmfsm_resume(struct device *dev) +{ + struct stfsm *fsm = dev_get_drvdata(dev); + + if (fsm->clk) + clk_prepare_enable(fsm->clk); + + return 0; +} +#endif + +static SIMPLE_DEV_PM_OPS(stfsm_pm_ops, stfsmfsm_suspend, stfsmfsm_resume); + static struct of_device_id stfsm_match[] = { { .compatible = "st,spi-fsm", }, {}, @@ -2169,6 +2209,7 @@ static struct platform_driver stfsm_driver = { .name = "st-spi-fsm", .owner = THIS_MODULE, .of_match_table = stfsm_match, + .pm = &stfsm_pm_ops, }, }; module_platform_driver(stfsm_driver);