From patchwork Fri Dec 1 21:51:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 120391 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1678503qgn; Fri, 1 Dec 2017 13:52:37 -0800 (PST) X-Google-Smtp-Source: AGs4zMbVtFRMjkDN2Cdc8zp3tD37ocQIww7Qanjd2i6PPpQFIGGYtfYLkxcyVv75stwe/MXR/wO9 X-Received: by 10.159.252.137 with SMTP id bb9mr3139768plb.184.1512165156966; Fri, 01 Dec 2017 13:52:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512165156; cv=none; d=google.com; s=arc-20160816; b=xXe8/jJhjfbRHcLUYcrmADJPy7qiOCcQRhNDZ6+JgpPQpRI0Pzt6OaTKd87e7BuvpX Z3UZTxt/cXLaK3ble8Ob2hnculD4W+lxYjoxf2jr3pnn+qjGd489WXzbb7Ia4Wlw9g6t /i1xx0H1VB1G1AluH3hHp5F1CH4IT2dcExomo/HVycP0ZxvDkivriBTd0XN23u4H+vNC r+M2ffM2KQFLR+/qocg6ywch21qb+T2uOf4COhJ4cxL1AMYTu27pWikCLT2LucusDQNZ M3Dvyfe/7MshKiceOwudrtO800c2Hn398tqFFGa/BRjEujlPHa3a3ji0CuNVWtSkSkAZ Grkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=oBzmsU2/C3dLtHuMuPFtaLteu8r7z7MLMuxecouCUEw=; b=WK5u7cUU4v1B9p7mJKDPnu5ULT/OPDpciu1zxIeP29XHGCzS4ulNXAzS1UfLtpVuLr X5UB2IeynLgCChhtEbNe9vnd59lCBd9eSquCEz0ASe51WXtYX4X6EMgWJHE95oC5+GDL /ltlwbvitfHVtCt87G++PmrkyoximQIIGwNgpbrIrNeaJfSs668NR9cN4d5Wnl1643ys XifAAoCAMDKaFQTQGKzG7jgMGCpXmKcDutGuEonYFb7FDn6YC+A/u6ytn5FnY5NjPF35 q537hBKL71qPAlOtCKFqXZYiB0m0OvB7EOpIOe+LpI8CXxtz1NVVqP5QpPaL3S0/30kN jA4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=AzSl2Mur; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x13si5422045pgq.460.2017.12.01.13.52.36; Fri, 01 Dec 2017 13:52:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=AzSl2Mur; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751827AbdLAVwW (ORCPT + 28 others); Fri, 1 Dec 2017 16:52:22 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36185 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751607AbdLAVwO (ORCPT ); Fri, 1 Dec 2017 16:52:14 -0500 Received: by mail-wm0-f66.google.com with SMTP id b76so5666146wmg.1 for ; Fri, 01 Dec 2017 13:52:14 -0800 (PST) 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=oBzmsU2/C3dLtHuMuPFtaLteu8r7z7MLMuxecouCUEw=; b=AzSl2Mur6JKONPEj+FY4gfBL6koPFLsza4+SIDKV1L3R1UtA+SdiVc19woPTqoHSBZ Al7Gt3OwEwFh6VO/nBUV+7P8NgRQD0tGgUKTUNRP+lOZO1popt2OD8cMyjNaKPs/mw/n eDbZ+fosGj9cueQyzvADq2fCVwwqEV4oxZtdVmI0LEmNvMT0/BK6xMIiT5E7FLx33JG/ qGoIIj1HkSDRkPC0TOy7EbqylYey7a+ryqvpuqO8+zho9uEhc5RhHNiyRo+0c2H9UZhv 2J5KD+cu4LTVG8y9b5UWGDYt3ptjIvnRIn2ICdKfi34WqQH4O7ttdl4WSeSN9BrEyt7Q 163w== 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=oBzmsU2/C3dLtHuMuPFtaLteu8r7z7MLMuxecouCUEw=; b=MeYhLJCNhBkL1H1MdSUc5yhfrnlVvBRfPz9DN7MIQkOrw3S85RqHkfccoQ3w6sYmpY zazJyPIq+MCrQe0OoLm/OXzx8QdmmFIPNMJkURIbYDBgk8Z9l/0eqC5Nc3m0a0YqB53H MbfFsT/WfgxAmaPcm/V66jO6WvKuJyp5rgbG+N2Px962m2P3fU5dcoppLDRov2knqsHK /yNeoJktbgAqUu7onlyarrcxcjKOSZRR1lx+H9+Re0KbUbx2+R0o+zjrYdnU44ao3PLN NtmP7hIQJ/JvY+BXMOZXR4n3altkFwuc1KhL3qsS3tlemew2R7+lgxSiyGYdVxHpkyAl YcAg== X-Gm-Message-State: AKGB3mKBqUGjsY7/5HPDNVk3ydjUBA/ya/FPnIcFwyhNCW3vyG4VnGLn gJfys/pj6zURt7rt9stOqCKtRA== X-Received: by 10.28.12.18 with SMTP id 18mr2154824wmm.129.1512165133621; Fri, 01 Dec 2017 13:52:13 -0800 (PST) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id m134sm2078804wmg.6.2017.12.01.13.52.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Dec 2017 13:52:13 -0800 (PST) From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Russell King , Linus Walleij , Quentin Schulz , Kevin Hilman , Maxime Ripard Subject: [PATCH v5 05/10] clk: use round rate to bail out early in set_rate Date: Fri, 1 Dec 2017 22:51:55 +0100 Message-Id: <20171201215200.23523-6-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171201215200.23523-1-jbrunet@baylibre.com> References: <20171201215200.23523-1-jbrunet@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 a rate a change. This is important when the 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 Acked-by: Linus Walleij Tested-by: Quentin Schulz Tested-by: Maxime Ripard Acked-by: Michael Turquette Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) -- 2.14.3 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 322d9ba7e5cd..bbe90babdae4 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1658,16 +1658,37 @@ 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; + + lockdep_assert_held(&prepare_lock); + + 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; int ret = 0; 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; @@ -1676,7 +1697,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;