From patchwork Tue May 20 13:24:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 30449 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f72.google.com (mail-pb0-f72.google.com [209.85.160.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7A83A20671 for ; Tue, 20 May 2014 13:25:10 +0000 (UTC) Received: by mail-pb0-f72.google.com with SMTP id ma3sf1291696pbc.7 for ; Tue, 20 May 2014 06:25:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=RvBRoxC/Qub7XAc5jMFMKkUM96SI+dmJNmuX9xL5wy4=; b=YYYLn99jFPfhPf0dQLk0BQsdfc7BkR1Cbcbpyjnky61nYerNCdUlY1XFRP7ybPvpBB huNNfIWU1I/3q74KhsYUNFfr9dAsaX3iBX4aJhW6EXotWOKXit/fWtTsNRIVgY06J7Vj d7wDal6RlhVx2OkPv1vIvxUi2XSpfBVlFJZi+ACNrwjRLnqoZYcmZHJwNKGf6oVR6G// dUDNpkoFnnKf/zby4oyM+uscDuGRl0YZ2NZ7BlLvsxuSMFKSN60//nDDabBqfPPzc6W3 n9Ij4TOTPVBfnwOkhX6xsKcwfnYWCTri4F6nYzpIGrQkVV8upnCWkedd7dP58pzmWCbP RHMQ== X-Gm-Message-State: ALoCoQn3mLuKmXLJBVi3CPCrnbMW4AReYjg/NXu7l63+qXXuQ9z9R8gCwJQYaEYu1WRXLYyg2nEC X-Received: by 10.66.144.228 with SMTP id sp4mr19006486pab.5.1400592309558; Tue, 20 May 2014 06:25:09 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.41.166 with SMTP id z35ls255576qgz.93.gmail; Tue, 20 May 2014 06:25:09 -0700 (PDT) X-Received: by 10.58.50.137 with SMTP id c9mr428186veo.62.1400592309280; Tue, 20 May 2014 06:25:09 -0700 (PDT) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id oh5si638288vcb.6.2014.05.20.06.25.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 20 May 2014 06:25:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.182 as permitted sender) client-ip=209.85.128.182; Received: by mail-ve0-f182.google.com with SMTP id sa20so577505veb.13 for ; Tue, 20 May 2014 06:25:09 -0700 (PDT) X-Received: by 10.53.13.133 with SMTP id ey5mr3153439vdd.8.1400592309152; Tue, 20 May 2014 06:25:09 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp30503vcb; Tue, 20 May 2014 06:25:08 -0700 (PDT) X-Received: by 10.66.153.80 with SMTP id ve16mr51007075pab.143.1400592308331; Tue, 20 May 2014 06:25:08 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id of4si1798733pbb.9.2014.05.20.06.25.07; Tue, 20 May 2014 06:25:07 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754038AbaETNY7 (ORCPT + 27 others); Tue, 20 May 2014 09:24:59 -0400 Received: from mail-ig0-f174.google.com ([209.85.213.174]:42816 "EHLO mail-ig0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752893AbaETNY5 (ORCPT ); Tue, 20 May 2014 09:24:57 -0400 Received: by mail-ig0-f174.google.com with SMTP id h3so4820870igd.13 for ; Tue, 20 May 2014 06:24:57 -0700 (PDT) X-Received: by 10.50.129.97 with SMTP id nv1mr4877336igb.32.1400592297190; Tue, 20 May 2014 06:24:57 -0700 (PDT) Received: from localhost.localdomain (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPSA id w4sm28956063igl.7.2014.05.20.06.24.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 May 2014 06:24:56 -0700 (PDT) From: Alex Elder To: mturquette@linaro.org, mporter@linaro.org, bcm@fixthebug.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] clk: bcm/kona: implement determine_rate() Date: Tue, 20 May 2014 08:24:57 -0500 Message-Id: <1400592297-22171-1-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: elder@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Implement the clk->determine_rate method for Broadcom Kona peripheral clocks. This allows a peripheral clock to be re-parented in order to satisfy a rate change request. This takes the place of the previous kona_peri_clk_round_rate() functionality, though that function remains because it is used by the new one. The parent clock that allows the peripheral clock to produce a rate closest to the one requested is the one selected, though the current parent is used by default. Signed-off-by: Alex Elder --- This patch is based on Mike Turquette's current "clk-next" branch. 6ed8eb5 Merge tag 'clk-hisi-for-v3.16' of https://git.kern... It is available here: http://git.linaro.org/landing-teams/working/broadcom/kernel.git Branch review/bcm-determine-rate drivers/clk/bcm/clk-kona.c | 53 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/drivers/clk/bcm/clk-kona.c b/drivers/clk/bcm/clk-kona.c index d603c4e..1a4eccc 100644 --- a/drivers/clk/bcm/clk-kona.c +++ b/drivers/clk/bcm/clk-kona.c @@ -1031,6 +1031,57 @@ static long kona_peri_clk_round_rate(struct clk_hw *hw, unsigned long rate, rate ? rate : 1, *parent_rate, NULL); } +static long kona_peri_clk_determine_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *best_parent_rate, struct clk **best_parent) +{ + struct kona_clk *bcm_clk = to_kona_clk(hw); + struct clk *clk = hw->clk; + struct clk *current_parent; + unsigned long parent_rate; + unsigned long best_delta; + unsigned long best_rate; + u32 parent_count; + u32 which; + + /* + * If there is no other parent to choose, use the current one. + * Note: We don't honor (or use) CLK_SET_RATE_NO_REPARENT. + */ + parent_count = (u32)bcm_clk->init_data.num_parents; + if (parent_count < 2) + return kona_peri_clk_round_rate(hw, rate, best_parent_rate); + + /* Unless we can do better, stick with current parent */ + current_parent = clk_get_parent(clk); + parent_rate = __clk_get_rate(current_parent); + best_rate = kona_peri_clk_round_rate(hw, rate, &parent_rate); + best_delta = abs(best_rate - rate); + + /* Check whether any other parent clock can produce a better result */ + for (which = 0; which < parent_count; which++) { + struct clk *parent = clk_get_parent_by_index(clk, which); + unsigned long delta; + unsigned long other_rate; + + BUG_ON(!parent); + if (parent == current_parent) + continue; + + /* We don't support CLK_SET_RATE_PARENT */ + parent_rate = __clk_get_rate(parent); + other_rate = kona_peri_clk_round_rate(hw, rate, &parent_rate); + delta = abs(other_rate - rate); + if (delta < best_delta) { + best_delta = delta; + best_rate = other_rate; + *best_parent = parent; + *best_parent_rate = parent_rate; + } + } + + return best_rate; +} + static int kona_peri_clk_set_parent(struct clk_hw *hw, u8 index) { struct kona_clk *bcm_clk = to_kona_clk(hw); @@ -1135,7 +1186,7 @@ struct clk_ops kona_peri_clk_ops = { .disable = kona_peri_clk_disable, .is_enabled = kona_peri_clk_is_enabled, .recalc_rate = kona_peri_clk_recalc_rate, - .round_rate = kona_peri_clk_round_rate, + .determine_rate = kona_peri_clk_determine_rate, .set_parent = kona_peri_clk_set_parent, .get_parent = kona_peri_clk_get_parent, .set_rate = kona_peri_clk_set_rate,