Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5650227img; Wed, 27 Mar 2019 12:26:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxdFz1izPBeZAGZbsL+JzG5C/CZRrhkXWJ45e1VWkB7hiCKkOA5iHNX6G+u/sH4xbOZEN+Y X-Received: by 2002:a17:902:e3:: with SMTP id a90mr37662181pla.45.1553714803314; Wed, 27 Mar 2019 12:26:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714803; cv=none; d=google.com; s=arc-20160816; b=nqNePJAEy46BonsEuZ5wXgh/OqKadZL8NJBTI5RZK+HAu8BS3ZfqCipSnrxW0/Ns/I oCrakuCI0FQkDBh5f54tbHB/tswAmCY9lc5Y4SpStIb4VWqp70BDz/XaGuNP78+cuOcV 9k8l7G12JPOmKZU4qD82S+Q2MeTP4F/a3xrQl070emgoZDlLSW593odMNx4nCvvdThpL sp/pwVa1Xh96EJlPLpLMYKjdTl4TYC9hjRFngdhr1yK/xTD/PqV+gk4r9/mp70+4NJ55 bDILuCSK2NuYnu29r4JlFnc79h7lziehjYEreUX7omwltqQVGmdwpQu09Fs2asjhQ+KZ TQZA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vlUXwZ7q1fo0oHdPh+Fq9beUaa+mkvsCuNxhU696H2g=; b=D9Ixz/Ib3oqre/eXCfvMsbE6eu9HmRNfUdyd5OSwC4V7pbjsHmN06xV5yaeHFRq012 XxF6b1Hk/35rGP/FsPYl9gSGqpmNQsrxduGiqXDI6mqHLHsqMpyJKR5PPremSYPEZtdG NZJYaPvSNLLVTZABjFTQyHgkE0jIxj8GXIazXRKxbqR/0yD4CndEDr6Ee1/mDx8BAcKX +ypMkkUfDMPhX+TrCAzctg1ZW6KoPvvG4EnPIDvzKQ7rx1RNKfYrGZYMCi/4Ku2YtHTL RHGS3y0gJ2ZQvItxNuhrFAIX6+eRkXlXMSejcyh1OZuIJs45/Pm2tP8wRy3n8ztUtMgE UL6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ctrU0wKt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a61si14616652pla.178.2019.03.27.12.26.28; Wed, 27 Mar 2019 12:26:43 -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=ctrU0wKt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387614AbfC0SFM (ORCPT + 99 others); Wed, 27 Mar 2019 14:05:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:46148 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731950AbfC0SFI (ORCPT ); Wed, 27 Mar 2019 14:05:08 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 66686218D9; Wed, 27 Mar 2019 18:05:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709907; bh=zlw0UccfFZnuPav6pLKsJ6QMtiJdSdnO1wqwCPqPk7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ctrU0wKtscCLC1dnbpJVfyLimUndnzMIsfcCkL4KQDTOLxL8nLB6ZUOAqjCe5RbRV uwGLN6flxhMsRhzJGWqcE0ZHd1cHYHpTg3EXNH3J6HPQ2VWAdW+TvJKwCYiRDmJ2UA vmus0PPewsf7dPG/TsZjHYzo1dzd/8anSBHuHdHo= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Katsuhiro Suzuki , Stephen Boyd , Sasha Levin , linux-clk@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 104/262] clk: fractional-divider: check parent rate only if flag is set Date: Wed, 27 Mar 2019 13:59:19 -0400 Message-Id: <20190327180158.10245-104-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Katsuhiro Suzuki [ 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 545dceec0bbf..fdfe2e423d15 100644 --- a/drivers/clk/clk-fractional-divider.c +++ b/drivers/clk/clk-fractional-divider.c @@ -79,7 +79,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 e443fa9fa859..b7cf80a71293 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -792,6 +792,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_rate_is_protected(const struct clk_hw *hw); bool clk_hw_is_enabled(const struct clk_hw *hw); -- 2.19.1