From patchwork Thu Dec 4 10:21:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 417698 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 38E521400D5 for ; Thu, 4 Dec 2014 21:25:28 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XwTZz-0005Gb-9d; Thu, 04 Dec 2014 10:24:11 +0000 Received: from mail-yk0-f169.google.com ([209.85.160.169]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XwTYK-00041N-PC for linux-mtd@lists.infradead.org; Thu, 04 Dec 2014 10:22:30 +0000 Received: by mail-yk0-f169.google.com with SMTP id 79so7813979ykr.14 for ; Thu, 04 Dec 2014 02:22:06 -0800 (PST) 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=EZboNS2DdtwQr9yN4DENPG4XES4TTZPh0co6too1anY=; b=KzfB80hMU0tvZ42pTJT0sORLZRvQEFi4GPFSgc7CbatSeqImy+/1uEHvX3Xvh0THAl TtlfRHNZc/MhS/H4lKzS35cFJq3vAso6o0nDF5IRFH7PZrXU5RJd4PlJzn4TX8fil3iS eZlWT0bzEJqr2Hdyz3z3QY3wE2YVQEDdnoKrF1srO82FZ27q11e1KO1F9K5vsd9F1xiB s+QRZ6U4SvpEoUqLkNLwxUs+mQlTbTFyQ5k4Eil0fgbUASw8+z406rsskTdPQGoF1UDa ypH9dISs/4Sr0bSPoXZRz2TR9KZYPQIa4g0tklnF+9xWDDCrRygzrPZ4my8e0N2Mn+4t fTuQ== X-Gm-Message-State: ALoCoQnNDJnJa+beHjNY/9anjR05nqKF1CNd1e00ofD7L4oXzzIFI99c7agogkO32MYoVfNpMcQE X-Received: by 10.236.38.234 with SMTP id a70mr11694666yhb.63.1417688526823; Thu, 04 Dec 2014 02:22:06 -0800 (PST) Received: from localhost.localdomain (host109-148-232-11.range109-148.btcentralplus.com. [109.148.232.11]) by mx.google.com with ESMTPSA id y67sm16089929yhc.11.2014.12.04.02.22.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Dec 2014 02:22:06 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 RESEND 02/11] mtd: st_spi_fsm: Obtain and use EMI clock if provided Date: Thu, 4 Dec 2014 10:21:43 +0000 Message-Id: <1417688512-7644-3-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1417688512-7644-1-git-send-email-lee.jones@linaro.org> References: <1417688512-7644-1-git-send-email-lee.jones@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141204_022228_996659_D613C38F X-CRM114-Status: GOOD ( 14.40 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.169 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.160.169 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: linux-mtd@lists.infradead.org, computersforpeace@gmail.com, lee.jones@linaro.org, kernel@stlinux.com X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.18-1 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 6e4d3bfe..ddb659f 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "serial_flash_cmds.h" @@ -262,6 +263,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; @@ -1906,8 +1908,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 @@ -2057,6 +2064,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); @@ -2121,6 +2137,30 @@ static int stfsm_remove(struct platform_device *pdev) return mtd_device_unregister(&fsm->mtd); } +#ifdef CONFIG_PM_SLEEP +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 const struct of_device_id stfsm_match[] = { { .compatible = "st,spi-fsm", }, {}, @@ -2134,6 +2174,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);