From patchwork Fri Nov 3 01:58:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Troy Kisky X-Patchwork-Id: 833608 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ySlyL51Gxz9sPs for ; Fri, 3 Nov 2017 13:19:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934717AbdKCCTW (ORCPT ); Thu, 2 Nov 2017 22:19:22 -0400 Received: from wsip-98-189-142-135.oc.oc.cox.net ([98.189.142.135]:64712 "EHLO office-server2" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934715AbdKCCTW (ORCPT ); Thu, 2 Nov 2017 22:19:22 -0400 Received: from tkisky by office-server2 with local (Exim 4.88) (envelope-from ) id 1eARFT-0004QZ-Dc; Thu, 02 Nov 2017 18:58:19 -0700 From: Troy Kisky To: a.zummo@towertech.it, alexandre.belloni@free-electrons.com Cc: gary.bisson@boundarydevices.com, linux-rtc@vger.kernel.org, Troy Kisky Subject: [PATCH v1 2/5] rtc: m41t80: fix m41t80_sqw_round_rate return value Date: Thu, 2 Nov 2017 18:58:13 -0700 Message-Id: <20171103015816.16972-2-troy.kisky@boundarydevices.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171103015816.16972-1-troy.kisky@boundarydevices.com> References: <20171103015816.16972-1-troy.kisky@boundarydevices.com> Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org Previously it was returning the best of 32768, 8192, 1024, 64, 2, 0 Now, best of 32768, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0 Signed-off-by: Troy Kisky --- drivers/rtc/rtc-m41t80.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c index 8f5843169dc2..42fc735a5446 100644 --- a/drivers/rtc/rtc-m41t80.c +++ b/drivers/rtc/rtc-m41t80.c @@ -468,18 +468,13 @@ static unsigned long m41t80_sqw_recalc_rate(struct clk_hw *hw, static long m41t80_sqw_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { - int i, freq = M41T80_SQW_MAX_FREQ; - - if (freq <= rate) - return freq; - - for (i = 2; i <= ilog2(M41T80_SQW_MAX_FREQ); i++) { - freq /= 1 << i; - if (freq <= rate) - return freq; - } - - return 0; + if (rate >= M41T80_SQW_MAX_FREQ) + return M41T80_SQW_MAX_FREQ; + if (rate >= M41T80_SQW_MAX_FREQ / 4) + return M41T80_SQW_MAX_FREQ / 4; + if (!rate) + return 0; + return 1 << ilog2(rate); } static int m41t80_sqw_set_rate(struct clk_hw *hw, unsigned long rate,