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: 10127935 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 492226019C for ; Thu, 21 Dec 2017 16:06:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C08229D2E for ; Thu, 21 Dec 2017 16:06:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3082E29D31; Thu, 21 Dec 2017 16:06:04 +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 A648E29D20 for ; Thu, 21 Dec 2017 16:06:03 +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=NAiIpVjNBqQ2X779WA3+yr064nQ3jHM9TJVLu89wuKY=; b=l33l9iWHL7dHKxcftsOFLWki6g nZptrJn6wNQT18bV0zAgFKkOMIzQNxj+z9wVLKp3ekiMsxYlxbhQcRy6Dybe6r8TZWiKq2osEdMMF uz/KzXyFB+SeO3lLxuFhSVAsgXQAri/JxwXXB08826OFe8/sqC75NPv2umldfVCyyy+mZamP+JynX tqUSlhgYHPI00Rvr9KmHL2zR+cePSXuZI+Uvrz57e5fcfegBckjPvYHgfBggVF2e+3EfZWRwbzNZK eoz/hnSv3ZOwj8uGDrlVb4vctr4faekDOQXAtgEsCZI7Xa9/GomynkN/zCpf+dIFDgNI8Y10QZcZ1 0DZBu0RQ==; 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 1eS3M6-0005lR-LA; Thu, 21 Dec 2017 16:05:58 +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-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms 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-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=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; }