From patchwork Thu Dec 21 16:04:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Kochetkov X-Patchwork-Id: 10127927 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4629B6019C for ; Thu, 21 Dec 2017 16:05:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3827729853 for ; Thu, 21 Dec 2017 16:05:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CBAD29BAB; Thu, 21 Dec 2017 16:05:35 +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=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B6FAD29853 for ; Thu, 21 Dec 2017 16:05:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=kZa4cNkIwfqdqeIjIgdlhVOhpSzhS3AON/37Q1Pu+AY=; b=NE7q7su0H/RUjIjp52lgM41Zze HKmx9MgteUztQCeGsR1I65KzmZ4wAagU5BqQvW2ETskomWUqokdjnR4viN3Ayp531nnRkBP5JS1mK iHKA/wJDPeRu74S6kmquoPmcfOTAmNXCaJAS9qLUoAQPRsO9VnLWlZ906VJ07f7MMEu8IlfU4ZFxK WzdOylCli/xI6s4ZL7l2MLrPNLu5KrdyRhk49nYlKDXQiwfsbtyL3mhTAL7e0fdSpZ7Da6SxlNzxW +5srFftPnj/r2EhQ94d6A/P0WIFuX+3wq5NkTyWX5VsbX1C3nfdJfmP4mF9jdFac0BM8dxHZSN6/A aCHfjbSg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eS3Ld-0005Gf-HC; Thu, 21 Dec 2017 16:05:29 +0000 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eS3L8-0004VQ-Sx; Thu, 21 Dec 2017 16:05:00 +0000 Received: by mail-lf0-x241.google.com with SMTP id g80so24046054lfg.0; Thu, 21 Dec 2017 08:04:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8GSSmYE04ba3NhCErIgLVQOhCofVpYmrzpIErKZHdNA=; b=ZXImGEDBljAybb8ykdnjzY2dKpeK5mbUPg0vE8fM8JWW7WY0S2tP3WrVya7yL984Bp jUcIdQA6LYo2/hq+UqjGW1yG6qzVZVmX3k5o2G180zKkAaWz7GefjxVlHXZlxw6qS4rc XAl2KWQh5p7JpiuzZamePyJiitQ9C03qQLuXz85wgNdxHWXAVz+wqrasZtCqz2Sx0aGi QuZjABWHNxzUfdUWDWJuDXUIWqrQmOn6ZBr6yEp15TR/Si/0E6IO9hOaCN61qSe7CPvu 3SuwBQp3KBzTfJVylo46cbGnTUOFxbnaUoerqoGjbwwFusfaKQxGOUH7sgZRxA+u+hgL sfUw== 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; bh=8GSSmYE04ba3NhCErIgLVQOhCofVpYmrzpIErKZHdNA=; b=mLDJnhA6XQoOm6eGwuybMjn8Or/c76at/pjY/b2+Tu2Gfeoxy0cdgFd8Itopju8K2u RQKKriZLcPT8vOVmgbMWDO/DLUYnfUNgdTD49Ul87a27kKUGpmyHGQHxw6cSpdR8rkyA whG5315P9NAXybqWarFozvsVnV8K0d4PINdGpYdMqBXBj4xRGFwCnyuXQz3binJ2ohpl rSmFrgMJ1BBm5/GlePD03KetIZosTx2xTmTyZC5Yo5/Wp1xVlc2rvkQ1URd6nyDW+xaX OviVjQUEPZ8Sa3dIJAkapObncw4NnOOWE/QXPLNgIKBDHywy8d8BNi1PHjDzJwSIblTb q+dA== X-Gm-Message-State: AKGB3mKwXiQVt5IWXPV3q5ajf/AqVD2TzWBJG1cw8xC5mTkdwMIiy8ra 3AwEe/elDUsl09YzCjVJYWU= X-Google-Smtp-Source: ACJfBott4470+gdRMiiecJxRFjG4RThqaG7RSkRfsTOsjAz/Yq0Ipn+OG9bJW26wvzvQQiwmkqI4NQ== X-Received: by 10.46.64.76 with SMTP id n73mr7204881lja.33.1513872288726; Thu, 21 Dec 2017 08:04:48 -0800 (PST) Received: from ubuntu.lintech.local ([185.35.119.87]) by smtp.gmail.com with ESMTPSA id y1sm4091581lja.4.2017.12.21.08.04.47 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 21 Dec 2017 08:04:48 -0800 (PST) From: Alexander Kochetkov To: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org Subject: [PATCH 2/2] clk: rockchip: limit clock rate in the rockchip_fractional_approximation() Date: Thu, 21 Dec 2017 19:04:42 +0300 Message-Id: <1513872282-5370-3-git-send-email-al.kochet@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1513872282-5370-1-git-send-email-al.kochet@gmail.com> References: <1513872282-5370-1-git-send-email-al.kochet@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171221_080459_004966_796FE6EA X-CRM114-Status: UNSURE ( 8.73 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Turquette , Elaine Zhang , Stephen Boyd , Heiko Stuebner , Alexander Kochetkov MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP rockchip_fractional_approximation() can choose clock rate that can be larger than one configured using clk_set_max_rate(). Request to setup correct clock rate whose parent rate will be adjusted to out of range value will fail with -EINVAL. Fixes: commit 5d890c2df900 ("clk: rockchip: add special approximation to fix up fractional clk's jitter"). Signed-off-by: Alexander Kochetkov --- drivers/clk/rockchip/clk.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c index 35dbd63..3c1fb0d 100644 --- a/drivers/clk/rockchip/clk.c +++ b/drivers/clk/rockchip/clk.c @@ -175,6 +175,7 @@ static void rockchip_fractional_approximation(struct clk_hw *hw, { struct clk_fractional_divider *fd = to_clk_fd(hw); unsigned long p_rate, p_parent_rate; + unsigned long min_rate = 0, max_rate = 0; struct clk_hw *p_parent; unsigned long scale; @@ -182,6 +183,12 @@ static void rockchip_fractional_approximation(struct clk_hw *hw, if ((rate * 20 > p_rate) && (p_rate % rate != 0)) { p_parent = clk_hw_get_parent(clk_hw_get_parent(hw)); p_parent_rate = clk_hw_get_rate(p_parent); + clk_hw_get_boundaries(clk_hw_get_parent(hw), + &min_rate, &max_rate); + if (p_parent_rate < min_rate) + p_parent_rate = min_rate; + if (p_parent_rate > max_rate) + p_parent_rate = max_rate; *parent_rate = p_parent_rate; }