From patchwork Sat Feb 4 21:03:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9555763 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 DA918602B5 for ; Sat, 4 Feb 2017 21:06:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC9982582C for ; Sat, 4 Feb 2017 21:06:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C152426E51; Sat, 4 Feb 2017 21:06:40 +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=-1.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=no 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 7C8322582C for ; Sat, 4 Feb 2017 21:06:40 +0000 (UTC) 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 1ca7XU-0003zR-6x; Sat, 04 Feb 2017 21:06:32 +0000 Received: from mail-wm0-f68.google.com ([74.125.82.68]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ca7XP-0003vp-CV; Sat, 04 Feb 2017 21:06:29 +0000 Received: by mail-wm0-f68.google.com with SMTP id u63so13047954wmu.2; Sat, 04 Feb 2017 13:06:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:references:cc:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=yiYjx+4yhP+zc3Q3QK4/jMI9jky67syKBZrq8yjA028=; b=OrWWFRDPGNSUAEP7cWi5qP3qhgr8nHWMLzhD2dkfapxlA490j53LEMzABPhxPOojVl 0DohLE21h0LaoyEpeNrYNNFXSRQLzD68vaqevsVUM6hxVXubSwBFj/YeZKnlHdFP8470 +feR7mPf04BYKxW6V/jy2exWffpYuJTPcBtosf/yZLnBb+KFX4VBE+hxH+yXrFlI8Nru j0UslS8PfIZdrgts2zfrOzjjEFr7ViMVN2raLL3HrmDBH574wWHwdWR+CLzHavxYsv8C T1IWcuqVJ9mujnKQcU7F8uaVWjL84i8nQXdXLBslLj7uXpGRyWOJ+oD7xC1eC1T6urF4 z+Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:references:cc:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=yiYjx+4yhP+zc3Q3QK4/jMI9jky67syKBZrq8yjA028=; b=aV2GzzKav4uTaq1ki4FuLjT4QDkNAW1mwFqM+9FFIzVGIayeu/tz9ZeSSAN5p8HDWk vuTB+zDA4HR6MvFxgJD3TtbEVrCFu2MVsZDrmUCAWfJci2ikGzcGEgz5ycHtOCdk4hJL XuAnl1VFggljzy4J7VVg/WbHusLEZUXKZ+AD9BT5jj5YzsInB8wp+bGGjv5q2eyxJMBg UqHL+4D7jQHPNTH7vMWTMgaY8BIkAsa13ODd2bbQ9It6XLJ32Gnw/5jWr5EmoQN7oyeD iQKVvweK3Z4n6nftfxJpykjo0ixShEFy6/8cyaQbDVvmorNVOSdzMbUtTk9DQigK4Gwt PkBA== X-Gm-Message-State: AIkVDXICJVHVQR+KKvWHoaIA8tMIp+DgLjt3jbzKw2jHHINd3Pmp4IBlSx2CnE8c8bLB5g== X-Received: by 10.223.160.180 with SMTP id m49mr3038052wrm.160.1486242305655; Sat, 04 Feb 2017 13:05:05 -0800 (PST) Received: from ?IPv6:2003:c6:ebce:1e00:2171:4d5:b787:b5ce? (p200300C6EBCE1E00217104D5B787B5CE.dip0.t-ipconnect.de. [2003:c6:ebce:1e00:2171:4d5:b787:b5ce]) by smtp.googlemail.com with ESMTPSA id 36sm51733815wrz.8.2017.02.04.13.05.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Feb 2017 13:05:05 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 1/2] clk: scpi: RfC - Allow to ignore invalid SCPI DVFS clock rates To: Sudeep Holla References: <3b60654a-88b6-6262-396e-a058ade1c586@gmail.com> Message-ID: Date: Sat, 4 Feb 2017 22:03:55 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: <3b60654a-88b6-6262-396e-a058ade1c586@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170204_130627_583485_61DA9600 X-CRM114-Status: GOOD ( 10.08 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-amlogic@lists.infradead.org, "linux-arm-kernel@lists.infradead.org" , Kevin Hilman Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce an optional property "clock-max-frequency" for SCPI DVFS clocks. All frequencies for the respective clock exceeding this threshold will be ignored. This is useful on systems where the firmware offers too optimistic clock rates causing instabilities and crashes. Signed-off-by: Heiner Kallweit --- Documentation/devicetree/bindings/arm/arm,scpi.txt | 7 +++++++ drivers/clk/clk-scpi.c | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/arm/arm,scpi.txt b/Documentation/devicetree/bindings/arm/arm,scpi.txt index 40183197..7582dd2e 100644 --- a/Documentation/devicetree/bindings/arm/arm,scpi.txt +++ b/Documentation/devicetree/bindings/arm/arm,scpi.txt @@ -56,6 +56,13 @@ Other required properties for all clocks(all from common clock binding): node. It can be non linear and hence provide the mapping of identifiers into the clock-output-names array. +For DVFS SCPI clocks a further optional property is supported to deal with +SCPI DVFS clocks where some firmware-provided clocks rates are too optimistic +and cause stability issues. + +- clock-max-frequency : Ignore all firmware-provided frequencies above this + threshold. Value 0 means no threshold. + SRAM and Shared Memory for SCPI ------------------------------- diff --git a/drivers/clk/clk-scpi.c b/drivers/clk/clk-scpi.c index 96d37175..fc99bb6e 100644 --- a/drivers/clk/clk-scpi.c +++ b/drivers/clk/clk-scpi.c @@ -27,6 +27,7 @@ struct scpi_clk { u32 id; + u32 max_freq; struct clk_hw hw; struct scpi_dvfs_info *info; struct scpi_ops *scpi_ops; @@ -36,6 +37,11 @@ struct scpi_clk { static struct platform_device *cpufreq_dev; +static inline bool invalid_freq(struct scpi_clk *clk, u32 freq) +{ + return clk->max_freq && freq > clk->max_freq; +} + static unsigned long scpi_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { @@ -79,6 +85,8 @@ static int __scpi_dvfs_round_rate(struct scpi_clk *clk, unsigned long rate) for (idx = 0; idx < clk->info->count; idx++, opp++) { ftmp = opp->freq; + if (invalid_freq(clk, ftmp)) + continue; if (ftmp >= (u32)rate) { if (ftmp <= fmax) fmax = ftmp; @@ -118,7 +126,7 @@ static int __scpi_find_dvfs_index(struct scpi_clk *clk, unsigned long rate) const struct scpi_opp *opp = clk->info->opps; for (idx = 0; idx < max_opp; idx++, opp++) - if (opp->freq == rate) + if (opp->freq == rate && !invalid_freq(clk, opp->freq)) return idx; return -EINVAL; } @@ -165,6 +173,7 @@ scpi_clk_ops_init(struct device *dev, const struct of_device_id *match, sclk->info = sclk->scpi_ops->dvfs_get_info(sclk->id); if (IS_ERR(sclk->info)) return PTR_ERR(sclk->info); + max = sclk->max_freq; } else if (init.ops == &scpi_clk_ops) { if (sclk->scpi_ops->clk_get_range(sclk->id, &min, &max) || !max) return -EINVAL; @@ -244,6 +253,10 @@ static int scpi_clk_add(struct device *dev, struct device_node *np, sclk->id = val; + if (match->data == &scpi_dvfs_ops) + of_property_read_u32_index(np, "clock-max-frequency", + idx, &sclk->max_freq); + err = scpi_clk_ops_init(dev, match, sclk, name); if (err) dev_err(dev, "failed to register clock '%s'\n", name);