From patchwork Mon Jun 12 19:44:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 9782675 X-Patchwork-Delegate: sboyd@codeaurora.org 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 1C9516038F for ; Mon, 12 Jun 2017 19:44:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F1AA284EE for ; Mon, 12 Jun 2017 19:44:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0412B286B7; Mon, 12 Jun 2017 19:44:56 +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 94B9E284EE for ; Mon, 12 Jun 2017 19:44:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752658AbdFLToy (ORCPT ); Mon, 12 Jun 2017 15:44:54 -0400 Received: from mail-wr0-f174.google.com ([209.85.128.174]:35954 "EHLO mail-wr0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752619AbdFLTow (ORCPT ); Mon, 12 Jun 2017 15:44:52 -0400 Received: by mail-wr0-f174.google.com with SMTP id v111so110850935wrc.3 for ; Mon, 12 Jun 2017 12:44:52 -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=9ZtDRLCdIYqQS5bxAU+BwYaGGlG91iLP8T/13TEEjZ4=; b=Go9kqlpQLFJlr0eTpj7LsqWO2ph+dR3KPzpadEKyUMLUeYFUKXhn3hAKYmotZ5wW7O C5HAdcH7KOFPIeszIFvF5XYanNIAPf8dFnsCBWHewDROydLiNEmcEnRUQm9ah3m39G8s ER48SEUsno7xJu5W4dY/or7ORwo3fiaNFpuea5AL3y0q5Xc7PMi+lhCLJhv8zdcg2CuS MTwZHvCBW9zmGPrVMVqTfIvCUCODidZJV9OpiJMldYOBTzwPRby3HhH9YVe+9Ovw/iXx GD3d50qo3NrI+tQRhMkRzL+5eG2bKTVg3hkHMamyzEtD3tx1HsF9j1O4bt847dyGZll6 dYNQ== 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=9ZtDRLCdIYqQS5bxAU+BwYaGGlG91iLP8T/13TEEjZ4=; b=CECQquR4w+gwoIsSq0I60Jr4JbGRwfWhl4C+z6qSQQF7IN+IeK8kTtetxdGSJEI++z 0A1kKfjAhXlaBNDR44E5x3Qt/rth8VqjymE0/TX+fqrdhWuhUr8s2Oi63q9nvRgXPha1 pdwJFi8tEKhNz2VcjsnVI9ygcC/hpo9T0mEHJbdjl9Rl2m7WoIbILWZwPVMOYuL3l4yI pckJBJ3wtNXW8M3LC8rCrWad2q3ocaeNaHFDxgBVjdXG5+dMGIRI86Qb3AS0bgK4/X7e EO2TggplzWQbvsQhHQDbViiBLWu09JgucOVtHmLOVxClBoMgLLczRhyNGfRU+qQHN3gD FCcw== X-Gm-Message-State: AKS2vOx3ezeCZlZmrMVYCQx+tErqjCxcvwg+5fGSbgjad9ngb1XKcZGT eCENZdUNxCwH05FaopQ= X-Received: by 10.28.19.11 with SMTP id 11mr8845863wmt.123.1497296691140; Mon, 12 Jun 2017 12:44:51 -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 70sm13250797wmu.28.2017.06.12.12.44.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jun 2017 12:44:50 -0700 (PDT) From: Jerome Brunet To: Michael Turquette , Stephen Boyd , linux-clk@vger.kernel.org Cc: Jerome Brunet , Kevin Hilman , linux-amlogic@lists.infradead.org, Russell King , Linus Walleij , Boris Brezillon Subject: [PATCH v3 04/10] clk: use round rate to bail out early in set_rate Date: Mon, 12 Jun 2017 21:44:32 +0200 Message-Id: <20170612194438.12298-5-jbrunet@baylibre.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170612194438.12298-1-jbrunet@baylibre.com> References: <20170612194438.12298-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 8cc4672414be..163cb9832f10 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;