From patchwork Thu Aug 30 18:36:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Douglas Anderson X-Patchwork-Id: 10582569 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D8F5A139B for ; Thu, 30 Aug 2018 18:36:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C35982C3DD for ; Thu, 30 Aug 2018 18:36:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B57692C3DF; Thu, 30 Aug 2018 18:36:48 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 38EA32C3DD for ; Thu, 30 Aug 2018 18:36:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728274AbeH3WkK (ORCPT ); Thu, 30 Aug 2018 18:40:10 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:37416 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728231AbeH3WkJ (ORCPT ); Thu, 30 Aug 2018 18:40:09 -0400 Received: by mail-pf1-f195.google.com with SMTP id h69-v6so4276126pfd.4 for ; Thu, 30 Aug 2018 11:36:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fHl6La1thHjcLDvSZRxhc58nWU+jWzOoZMZ+wwZO/SA=; b=SMKOPsInOKImvubYm5SamakJaEdwMKME5j5Xk1GMAI1Vy0TtWVrxstVXH540aFHaJd g0RpiFukF/P0GTsAwYXh/q/lnae3yVwfx83lbQwT8CdjExiKYXY6ekxBAONe8isCJo97 nIuxtPAOGlmEZZSa4/Jxo7S9wbtE50QvoIIZ0= 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:mime-version:content-transfer-encoding; bh=fHl6La1thHjcLDvSZRxhc58nWU+jWzOoZMZ+wwZO/SA=; b=XowrPvgZELQB13IPTNMsWi2EhljZqep8/V/D6itFCaPjzfUP/812hbp7BvpgC51Dj7 cuFEfqr4cYkD/LvXuiTuKOOvnCZr+kFdg9KVtN1BB6JKAJV16T+9Kk6uoOSm38+ZUyMt JjOVWBlRr3J1PzxKXu8NEvL17t0x9UFkxxXoeIz+v3TPoge1Gi36NBVVUolhjw3ERuvn Q2n6ZEfoL7fV6gryWeP6hHcohYCU3Z5yT3GEcQnppDyy9K0h1kXHX4qnfGx6nz9GFUsu F/WhUD2ZEZ8kLHK07MZSkzN9iDnZTykBKE76GZOW32w4fsdEIT2eEcmZxNViiywalO8j oUXA== X-Gm-Message-State: APzg51AS8AvgavLkIwGt4Op+F1nYz3Yindgzfp5tdzpG8o1/Spi6LhD7 7OOg1hzWwd9jqZVD0xnEkwVwDQ== X-Google-Smtp-Source: ANB0Vdb787SsnMIRQnx/MOaEZTOdTeTkoqAQkga+z55P/f/JWgOcQu/W7Ib5oL5xwwQmSlAFzgIZGA== X-Received: by 2002:a63:5fc8:: with SMTP id t191-v6mr10881113pgb.183.1535654200487; Thu, 30 Aug 2018 11:36:40 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:c8e0:70d7:4be7:a36]) by smtp.gmail.com with ESMTPSA id c68-v6sm14470946pfj.51.2018.08.30.11.36.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 11:36:39 -0700 (PDT) From: Douglas Anderson To: Andy Gross , Bjorn Andersson Cc: mka@chromium.org, girishm@codeaurora.org, dkota@codeaurora.org, evgreen@chromium.org, swboyd@chromium.org, Douglas Anderson , linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, David Brown , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] soc: qcom: geni: geni_se_clk_freq_match() should always accept multiples Date: Thu, 30 Aug 2018 11:36:12 -0700 Message-Id: <20180830183612.169572-2-dianders@chromium.org> X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-goog In-Reply-To: <20180830183612.169572-1-dianders@chromium.org> References: <20180830183612.169572-1-dianders@chromium.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The geni_se_clk_freq_match() has some strange semantics. Specifically it is defined with two modes: 1. It can find a clock that's an exact multiple of the requested rate 2. If can find a non-exact match but it can't handle multiples then ...but callers should always be able to handle a clock that is a multiple of the requested clock so mode #2 doesn't really make sense. Let's change the semantics so that the non-exact match can also accept multiples and then change the code to handle that. The only caller of this code is the unlanded SPI driver [1] which currently passes "exact = True", thus it should be safe to change the semantics in this way. ...and, in fact, the SPI driver should likely be modified to pass "exact = False" (with the new semantics) since that will allow it to work with SPI devices that request a clock rate that doesn't exactly match a rate we can make. [1] https://lkml.kernel.org/r/1535107336-2214-1-git-send-email-dkota@codeaurora.org Fixes: eddac5af0654 ("soc: qcom: Add GENI based QUP Wrapper driver") Signed-off-by: Douglas Anderson Reviewed-by: Matthias Kaehlcke --- drivers/soc/qcom/qcom-geni-se.c | 37 ++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c index 1b19b8428c4a..092b32a315c3 100644 --- a/drivers/soc/qcom/qcom-geni-se.c +++ b/drivers/soc/qcom/qcom-geni-se.c @@ -544,16 +544,17 @@ EXPORT_SYMBOL(geni_se_clk_tbl_get); * @se: Pointer to the concerned serial engine. * @req_freq: Requested clock frequency. * @index: Index of the resultant frequency in the table. - * @res_freq: Resultant frequency which matches or is closer to the - * requested frequency. + * @res_freq: Resultant frequency of the source clock. * @exact: Flag to indicate exact multiple requirement of the requested * frequency. * - * This function is called by the protocol drivers to determine the matching - * or exact multiple of the requested frequency, as provided by the serial - * engine clock in order to meet the performance requirements. If there is - * no matching or exact multiple of the requested frequency found, then it - * selects the closest floor frequency, if exact flag is not set. + * This function is called by the protocol drivers to determine the best match + * of the requested frequency as provided by the serial engine clock in order + * to meet the performance requirements. + * + * If we return success: + * - if @exact is true then @res_freq / == @req_freq + * - if @exact is false then @res_freq / <= @req_freq * * Return: 0 on success, standard Linux error codes on failure. */ @@ -564,6 +565,9 @@ int geni_se_clk_freq_match(struct geni_se *se, unsigned long req_freq, unsigned long *tbl; int num_clk_levels; int i; + unsigned long best_delta; + unsigned long new_delta; + unsigned int divider; num_clk_levels = geni_se_clk_tbl_get(se, &tbl); if (num_clk_levels < 0) @@ -572,18 +576,21 @@ int geni_se_clk_freq_match(struct geni_se *se, unsigned long req_freq, if (num_clk_levels == 0) return -EINVAL; - *res_freq = 0; + best_delta = 0; for (i = 0; i < num_clk_levels; i++) { - if (!(tbl[i] % req_freq)) { + divider = DIV_ROUND_UP(tbl[i], req_freq); + new_delta = req_freq - tbl[i] / divider; + if (!best_delta || new_delta < best_delta) { + /* We have a new best! */ *index = i; *res_freq = tbl[i]; - return 0; - } - if (!(*res_freq) || ((tbl[i] > *res_freq) && - (tbl[i] < req_freq))) { - *index = i; - *res_freq = tbl[i]; + /* If the new best is exact then we're done */ + if (new_delta == 0) + return 0; + + /* Record how close we got */ + best_delta = new_delta; } }