aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Anderson <dianders@chromium.org>2018-09-06 18:49:06 -0400
committerAndy Gross <andy.gross@linaro.org>2018-09-13 16:54:21 -0400
commit867d4aa7013fdee8b962cde1711f96c8dd86d926 (patch)
tree305f799c80c3e3fcbcf485069f16047511f2b892
parente11bbcedecae85ce60a5d99ea03528c2d6f867e0 (diff)
soc: qcom: geni: geni_se_clk_freq_match() should always accept multiples
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. It 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 <dianders@chromium.org> Reviewed-by: Matthias Kaehlcke <mka@chromium.org> Signed-off-by: Andy Gross <andy.gross@linaro.org>
-rw-r--r--drivers/soc/qcom/qcom-geni-se.c37
1 files 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..ee89ffb6dde8 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);
544 * @se: Pointer to the concerned serial engine. 544 * @se: Pointer to the concerned serial engine.
545 * @req_freq: Requested clock frequency. 545 * @req_freq: Requested clock frequency.
546 * @index: Index of the resultant frequency in the table. 546 * @index: Index of the resultant frequency in the table.
547 * @res_freq: Resultant frequency which matches or is closer to the 547 * @res_freq: Resultant frequency of the source clock.
548 * requested frequency.
549 * @exact: Flag to indicate exact multiple requirement of the requested 548 * @exact: Flag to indicate exact multiple requirement of the requested
550 * frequency. 549 * frequency.
551 * 550 *
552 * This function is called by the protocol drivers to determine the matching 551 * This function is called by the protocol drivers to determine the best match
553 * or exact multiple of the requested frequency, as provided by the serial 552 * of the requested frequency as provided by the serial engine clock in order
554 * engine clock in order to meet the performance requirements. If there is 553 * to meet the performance requirements.
555 * no matching or exact multiple of the requested frequency found, then it 554 *
556 * selects the closest floor frequency, if exact flag is not set. 555 * If we return success:
556 * - if @exact is true then @res_freq / <an_integer> == @req_freq
557 * - if @exact is false then @res_freq / <an_integer> <= @req_freq
557 * 558 *
558 * Return: 0 on success, standard Linux error codes on failure. 559 * Return: 0 on success, standard Linux error codes on failure.
559 */ 560 */
@@ -564,6 +565,9 @@ int geni_se_clk_freq_match(struct geni_se *se, unsigned long req_freq,
564 unsigned long *tbl; 565 unsigned long *tbl;
565 int num_clk_levels; 566 int num_clk_levels;
566 int i; 567 int i;
568 unsigned long best_delta;
569 unsigned long new_delta;
570 unsigned int divider;
567 571
568 num_clk_levels = geni_se_clk_tbl_get(se, &tbl); 572 num_clk_levels = geni_se_clk_tbl_get(se, &tbl);
569 if (num_clk_levels < 0) 573 if (num_clk_levels < 0)
@@ -572,18 +576,21 @@ int geni_se_clk_freq_match(struct geni_se *se, unsigned long req_freq,
572 if (num_clk_levels == 0) 576 if (num_clk_levels == 0)
573 return -EINVAL; 577 return -EINVAL;
574 578
575 *res_freq = 0; 579 best_delta = ULONG_MAX;
576 for (i = 0; i < num_clk_levels; i++) { 580 for (i = 0; i < num_clk_levels; i++) {
577 if (!(tbl[i] % req_freq)) { 581 divider = DIV_ROUND_UP(tbl[i], req_freq);
582 new_delta = req_freq - tbl[i] / divider;
583 if (new_delta < best_delta) {
584 /* We have a new best! */
578 *index = i; 585 *index = i;
579 *res_freq = tbl[i]; 586 *res_freq = tbl[i];
580 return 0;
581 }
582 587
583 if (!(*res_freq) || ((tbl[i] > *res_freq) && 588 /* If the new best is exact then we're done */
584 (tbl[i] < req_freq))) { 589 if (new_delta == 0)
585 *index = i; 590 return 0;
586 *res_freq = tbl[i]; 591
592 /* Record how close we got */
593 best_delta = new_delta;
587 } 594 }
588 } 595 }
589 596