Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752141AbcDUNEe (ORCPT ); Thu, 21 Apr 2016 09:04:34 -0400 Received: from mx0a-001ae601.pphosted.com ([67.231.149.25]:45682 "EHLO mx0a-001ae601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751622AbcDUNEc (ORCPT ); Thu, 21 Apr 2016 09:04:32 -0400 Authentication-Results: ppops.net; spf=none smtp.mail=rf@opensource.wolfsonmicro.com From: Richard Fitzgerald To: CC: , , Subject: [PATCH] ASoC: arizona: Prefer lower FRATIO in pseudo-fractional mode Date: Thu, 21 Apr 2016 14:04:14 +0100 Message-ID: <1461243854-31765-1-git-send-email-rf@opensource.wolfsonmicro.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1603290000 definitions=main-1604210212 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1919 Lines: 59 When setting up an FLL in pseudo-fractional mode it is preferred to use a lower FRATIO if possible to give a higher reference clock frequency. This patch swaps the two loops in arizona_calc_fratio() so that lower FRATIOs are tried first. The decrementing loop is also changed to start from init_ratio because the original settings might already give a fractional value for N.K Signed-off-by: Richard Fitzgerald --- sound/soc/codecs/arizona.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c index 0cd27e0..d1e1127 100644 --- a/sound/soc/codecs/arizona.c +++ b/sound/soc/codecs/arizona.c @@ -2039,7 +2039,21 @@ static int arizona_calc_fratio(struct arizona_fll *fll, init_ratio, Fref, refdiv); while (div <= ARIZONA_FLL_MAX_REFDIV) { - for (ratio = init_ratio; ratio <= ARIZONA_FLL_MAX_FRATIO; + /* start from init_ratio because this may already give a + * fractional N.K + */ + for (ratio = init_ratio; ratio > 0; ratio--) { + if (target % (ratio * Fref)) { + cfg->refdiv = refdiv; + cfg->fratio = ratio - 1; + arizona_fll_dbg(fll, + "pseudo: found fref=%u refdiv=%d(%d) ratio=%d\n", + Fref, refdiv, div, ratio); + return ratio; + } + } + + for (ratio = init_ratio + 1; ratio <= ARIZONA_FLL_MAX_FRATIO; ratio++) { if ((ARIZONA_FLL_VCO_CORNER / 2) / (fll->vco_mult * ratio) < Fref) { @@ -2065,17 +2079,6 @@ static int arizona_calc_fratio(struct arizona_fll *fll, } } - for (ratio = init_ratio - 1; ratio > 0; ratio--) { - if (target % (ratio * Fref)) { - cfg->refdiv = refdiv; - cfg->fratio = ratio - 1; - arizona_fll_dbg(fll, - "pseudo: found fref=%u refdiv=%d(%d) ratio=%d\n", - Fref, refdiv, div, ratio); - return ratio; - } - } - div *= 2; Fref /= 2; refdiv++; -- 1.9.1