Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp992261yba; Thu, 4 Apr 2019 01:57:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqzK6zqqzGCWfWhEP/QdbkCbNHF6EoJYqKrpWsc1H3uMnC4comF1LCH3kClvaYSu1kmoTfLd X-Received: by 2002:a62:3047:: with SMTP id w68mr4728658pfw.17.1554368228662; Thu, 04 Apr 2019 01:57:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554368228; cv=none; d=google.com; s=arc-20160816; b=HyULTl6xezUY19s8k7kF38afA/ZZZdJJAJMaBN8TGDDMQffpZXfakwdqrJ7hJbg6E6 Tm3h0u2GAcE6qNmwkzhXyIAIfZ3gCTayxOZL8FKZhc9EZwyBecUhcZTZe8zhjL2tobOq 45omxAoN7NMBYYFtLx2lw4q9oaKve8kCnU74Avq8cPA6W/uR0NvrI/REeUet8xIfEbOk YQJRLso8z0yL04jTRaY3wDgGeWIEjQHh+nopF6AShlRuUVvVaHtUW2W9f72pJLadLGlx ZGoizAoI0irQk6nXuknjtLPJCJmQ7h6XCvn/L12U7h7m3S8ZDUgJlXrduQLiEoW5GgzS pGIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=R0up8FlEndGwnfm8p2Md4SigIE8tHFXG9+sgTzag3AQ=; b=BX605RqUBDDbfSs+5Lfh0/gphsXtRAVQqdDDVeIUKsiDuqQpcNUD9cfrJ1p3y82+tZ sNKGR7XlYjJTSlQSJsfU0BJN2hcNiHA5CBZCb3NbedUpIZQ2zskRcdUmuivIYiEwj72y VPCaaYdzz0krJZa0ftlQbPHGCFe8FPe9laUaBJYEJm/1eoQWdjS5i1rWNVnSfK/nssmO kHRQpiO7cJFJ1YTnwd4/5hS7gcw1bczZkbavGnWOR6QU1SxKv0vbkUs/SeHH7ElGe+P4 ldffmcBJo2474rvq4Mg+pZDIHQaeIaPXAjG9SyxXsrNzfl5wIu53EvxnIN1H93ICDcx9 Bfew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rMOg7IXj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l62si7953518pgd.168.2019.04.04.01.56.53; Thu, 04 Apr 2019 01:57:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rMOg7IXj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730347AbfDDIzp (ORCPT + 99 others); Thu, 4 Apr 2019 04:55:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:58722 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729581AbfDDIzm (ORCPT ); Thu, 4 Apr 2019 04:55:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2E78921738; Thu, 4 Apr 2019 08:55:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368141; bh=nBCghCJs2oxezPUJSJLbW9HkdKldw+llrwr2IrmC/Dg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rMOg7IXj033IU6q6xoAncE8zHM8bKPsnCVYR9dqWW52+NqMvVXnwX5+gGw4aDQEM+ 2qQquNZFzf8IS9A1pnY6H1E/YbIRBUjiMHJcqnXsVgytWQid8eSB8Te7cmK2Dy+siU 7+vrdXZvst98NzHoZB+3r903kKU+XNuagzxO039E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Katsuhiro Suzuki , Heiko Stuebner , Stephen Boyd , Sasha Levin Subject: [PATCH 4.14 052/121] clk: fractional-divider: check parent rate only if flag is set Date: Thu, 4 Apr 2019 10:47:20 +0200 Message-Id: <20190404084548.076099791@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084545.245659903@linuxfoundation.org> References: <20190404084545.245659903@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit d13501a2bedfbea0983cc868d3f1dc692627f60d ] Custom approximation of fractional-divider may not need parent clock rate checking. For example Rockchip SoCs work fine using grand parent clock rate even if target rate is greater than parent. This patch checks parent clock rate only if CLK_SET_RATE_PARENT flag is set. For detailed example, clock tree of Rockchip I2S audio hardware. - Clock rate of CPLL is 1.2GHz, GPLL is 491.52MHz. - i2s1_div is integer divider can divide N (N is 1~128). Input clock is CPLL or GPLL. Initial divider value is N = 1. Ex) PLL = CPLL, N = 10, i2s1_div output rate is CPLL / 10 = 1.2GHz / 10 = 120MHz - i2s1_frac is fractional divider can divide input to x/y, x and y are 16bit integer. CPLL --> | selector | ---> i2s1_div -+--> | selector | --> I2S1 MCLK GPLL --> | | ,--------------' | | `--> i2s1_frac ---> | | Clock mux system try to choose suitable one from i2s1_div and i2s1_frac for master clock (MCLK) of I2S1. Bad scenario as follows: - Try to set MCLK to 8.192MHz (32kHz audio replay) Candidate setting is - i2s1_div: GPLL / 60 = 8.192MHz i2s1_div candidate is exactly same as target clock rate, so mux choose this clock source. i2s1_div output rate is changed 491.52MHz -> 8.192MHz - After that try to set to 11.2896MHz (44.1kHz audio replay) Candidate settings are - i2s1_div : CPLL / 107 = 11.214945MHz - i2s1_frac: i2s1_div = 8.192MHz This is because clk_fd_round_rate() thinks target rate (11.2896MHz) is higher than parent rate (i2s1_div = 8.192MHz) and returns parent clock rate. Above is current upstreamed behavior. Clock mux system choose i2s1_div, but this clock rate is not acceptable for I2S driver, so users cannot replay audio. Expected behavior is: - Try to set master clock to 11.2896MHz (44.1kHz audio replay) Candidate settings are - i2s1_div : CPLL / 107 = 11.214945MHz - i2s1_frac: i2s1_div * 147/6400 = 11.2896MHz Change i2s1_div to GPLL / 1 = 491.52MHz at same time. If apply this commit, clk_fd_round_rate() calls custom approximate function of Rockchip even if target rate is higher than parent. Custom function changes both grand parent (i2s1_div) and parent (i2s_frac) settings at same time. Clock mux system can choose i2s1_frac and audio works fine. Signed-off-by: Katsuhiro Suzuki Reviewed-by: Heiko Stuebner [sboyd@kernel.org: Make function into a macro instead] Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- drivers/clk/clk-fractional-divider.c | 2 +- include/linux/clk-provider.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c index fdf625fb10fa..083daa293280 100644 --- a/drivers/clk/clk-fractional-divider.c +++ b/drivers/clk/clk-fractional-divider.c @@ -77,7 +77,7 @@ static long clk_fd_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long m, n; u64 ret; - if (!rate || rate >= *parent_rate) + if (!rate || (!clk_hw_can_set_rate_parent(hw) && rate >= *parent_rate)) return *parent_rate; if (fd->approximation) diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 2f4e79fe7b86..3eb3376f1cc8 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -743,6 +743,9 @@ unsigned int __clk_get_enable_count(struct clk *clk); unsigned long clk_hw_get_rate(const struct clk_hw *hw); unsigned long __clk_get_flags(struct clk *clk); unsigned long clk_hw_get_flags(const struct clk_hw *hw); +#define clk_hw_can_set_rate_parent(hw) \ + (clk_hw_get_flags((hw)) & CLK_SET_RATE_PARENT) + bool clk_hw_is_prepared(const struct clk_hw *hw); bool clk_hw_is_enabled(const struct clk_hw *hw); bool __clk_is_enabled(struct clk *clk); -- 2.19.1