From patchwork Sun May 21 21:59:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 9739461 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 77CEA6034C for ; Sun, 21 May 2017 22:00:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 674DA285C9 for ; Sun, 21 May 2017 22:00:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C18C285F3; Sun, 21 May 2017 22:00:19 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham 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 072C2285C9 for ; Sun, 21 May 2017 22:00:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756494AbdEUWAS (ORCPT ); Sun, 21 May 2017 18:00:18 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:38660 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755502AbdEUWAS (ORCPT ); Sun, 21 May 2017 18:00:18 -0400 Received: by mail-wm0-f50.google.com with SMTP id e127so14799929wmg.1 for ; Sun, 21 May 2017 15:00:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=H++mFyXjCRxuJgVl/JizGKqguepkso0rnx2hewt6LEU=; b=Z4hKKsVuXl5o2It61hIJtgSXUv1+m9y9+lrvg4aHP7kpRQ55ColY/1vHyl7YUVJotc GMese6pwHikYR6vKwkdPdrbZoRZCuogHtRoO9lIHL2vm6zy7ox7qfi3r+ljIleNoRE/d QL3Chi+YpjE0z3jNKzjmJfCyiA4zeGH+CF2Wg0ANfPQH/t9zdVe8WGvdVVPaYc1Ll64L 9sfArJ0xHDvRxbYd/Hb7/Me+RwZZpgJcZ/DfilkTKhy9Cpsy0V//fFTDz7c0J1bqc+6D CL16+mjxMMSgIedg1cxqEEobiZQOQShoMthuCu9jLI/FGhFY4DzOXzxqo6D8H4Uvu891 +PEg== 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=H++mFyXjCRxuJgVl/JizGKqguepkso0rnx2hewt6LEU=; b=XrMSJz8zW2IZMA9URLaa3VIAxqwdpHrXfoiihTIj63oJhOpblfk+S08IsyXSfQg5QG 3yrNky+ui5pWIv6lYOgE2o3VOH4xu1JLViFF2PszJi4VoZzXA4Gh8uBB3CJSlp+NO7MV g9aJhf7xkuqbxfvF6Rxh8qEOPjOqaYwXgobIHqc06bL1lTDEvflWeZCUok46qCPOAwIf sr70YrXmvDlzVD06uDmt4KISU/ChRchvm3DR+WQ6hA54Q1KR6WaL9rL5hnuvlGd/H9k3 xtr0e6J+F5eRkW3zhkNnAa4NynXkm5DrIvOl+omJ69hKPCfiW7f4g9vCvE52zfQW9I8r pWAQ== X-Gm-Message-State: AODbwcCHGngorLRJ2qVEbKbKk0gGDll3VGzahivVmrgi+cr5IVfEfOG/ zo9XdmoyRbIruIsQ X-Received: by 10.223.133.182 with SMTP id 51mr9815631wrt.86.1495404016717; Sun, 21 May 2017 15:00:16 -0700 (PDT) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id a73sm12812579wrc.58.2017.05.21.15.00.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 May 2017 15:00:16 -0700 (PDT) From: Jerome Brunet To: Michael Turquette , Stephen Boyd , Kevin Hilman Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-amlogic@lists.infradead.org, Linus Walleij , Boris Brezillon Subject: [PATCH v2 04/11] clk: use round rate to bail out early in set_rate Date: Sun, 21 May 2017 23:59:51 +0200 Message-Id: <20170521215958.19743-5-jbrunet@baylibre.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170521215958.19743-1-jbrunet@baylibre.com> References: <20170521215958.19743-1-jbrunet@baylibre.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 current implementation of clk_core_set_rate_nolock bails out early if the requested rate is exactly the same as the one set. It should bail out if the request would not result in rate a change. This important when rate is not exactly what is requested, which is fairly common with PLLs. Ex: provider able to give any rate with steps of 100Hz - 1st consumer request 48000Hz and gets it. - 2nd consumer request 48010Hz as well. If we were to perform the usual mechanism, we would get 48000Hz as well. The clock would not change so there is no point performing any checks to make sure the clock can change, we know it won't. This is important to prepare the addition of the clock protection mechanism Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 100f72472e10..1a8c0d013238 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1570,15 +1570,34 @@ static void clk_change_rate(struct clk_core *core) clk_change_rate(core->new_child); } +static unsigned long clk_core_req_round_rate_nolock(struct clk_core *core, + unsigned long req_rate) +{ + int ret; + struct clk_rate_request req; + + if (!core) + return 0; + + clk_core_get_boundaries(core, &req.min_rate, &req.max_rate); + req.rate = req_rate; + + ret = clk_core_round_rate_nolock(core, &req); + + return ret ? 0 : req.rate; +} + static int clk_core_set_rate_nolock(struct clk_core *core, unsigned long req_rate) { struct clk_core *top, *fail_clk; - unsigned long rate = req_rate; + unsigned long rate; if (!core) return 0; + rate = clk_core_req_round_rate_nolock(core, req_rate); + /* bail early if nothing to do */ if (rate == clk_core_get_rate_nolock(core)) return 0; @@ -1587,7 +1606,7 @@ static int clk_core_set_rate_nolock(struct clk_core *core, return -EBUSY; /* calculate new rates and get the topmost changed clock */ - top = clk_calc_new_rates(core, rate); + top = clk_calc_new_rates(core, req_rate); if (!top) return -EINVAL;