Received: by 10.192.165.148 with SMTP id m20csp3418208imm; Sun, 29 Apr 2018 22:59:17 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrTyaBz9ZVjW6O+CdmlNcrCsdw/dCCjwfObhQ1RD21UW9OMGoF+x56DPmoBAvFUyjvW/1DQ X-Received: by 10.98.245.91 with SMTP id n88mr3152682pfh.208.1525067957927; Sun, 29 Apr 2018 22:59:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525067957; cv=none; d=google.com; s=arc-20160816; b=H6dRNGhkfE69OCMYA/NQknJGh5DFvtVzEpAFOMqaBlmmbav+fux0w4/i79U4HVP5cc GR2AM0Gg73uOuMGUiYs71u0nuf6IJLcdky19hj16m6m0SEFW7d5n7aDzodu+rh2yrpC2 suOpWNRoj2HBq9729+PapDrzYFs5aSJivzADU4b1eBjcggHVMryQIZG3RIfcALIn3S10 n2RlztwKCdShHlJ1CAGmeYUOkirzdvfceLe2sfgIQerj7tRtEpNiHYgYuvUtNKo6uNQf sTTNNsVQrFQXtUuy0LdGykHJQEpFXVQDfRdjHUDOcLjEB4ODYy7yFYwk7ZHjUyYOtOtI sQJg== 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:subject:cc:to:from:date :arc-authentication-results; bh=7/jTZ6O+Sz7EY1tWwENVaNbfmAfyBLt0R811opPMk2A=; b=jVHgYOyUsRzcInCw8UhR4AUm1q8KoVk42dGItTlm7s2WFifsVpCXyRpIvyQawteEaL uzp0VuoFl3wNBbl5JII9AfMbFZwrw7+mhSFv1Ot5QUjEcje4Ae1zfQGXDi8haod93lun 2+9cRtddGJGAxkymPwgVT597gJNQHsr7F4cZckBa5oGSJMc/z1bkFFwi4HmPQce2XxP5 IJ1DYB9Qo8uwAm3AYuTxSInnKtcNTkZnSmK2UMK0PY80ZzHJeDHTHZ8jgNs9n/P99WOK 5DhKIVAtpS8XyzoczAdtHrERuJyu5z1E5aTk2enRudDIvKdtjksBvLOy1aWl3ynb5zGY HsEA== ARC-Authentication-Results: i=1; mx.google.com; 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 v6-v6si5643958pgs.399.2018.04.29.22.59.03; Sun, 29 Apr 2018 22:59:17 -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; 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 S1751729AbeD3F6x (ORCPT + 99 others); Mon, 30 Apr 2018 01:58:53 -0400 Received: from mail.bootlin.com ([62.4.15.54]:50942 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751589AbeD3F6w (ORCPT ); Mon, 30 Apr 2018 01:58:52 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 1F6BC2072C; Mon, 30 Apr 2018 07:58:49 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_RED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (91-160-177-164.subs.proxad.net [91.160.177.164]) by mail.bootlin.com (Postfix) with ESMTPSA id C2F992036F; Mon, 30 Apr 2018 07:58:48 +0200 (CEST) Date: Mon, 30 Apr 2018 07:58:47 +0200 From: Boris Brezillon To: Marcin Ziemianowicz Cc: Boris Brezillon , Nicolas Ferre , Alexandre Belloni , Greg Kroah-Hartman , stable@vger.kernel.org, Michael Turquette , Stephen Boyd , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH V4] clk: at91: PLL recalc_rate() now using cached MUL and DIV values Message-ID: <20180430075847.29706679@bbrezillon> In-Reply-To: <20180429190111.14247-1-marcin@ziemianowicz.com> References: <20180429190111.14247-1-marcin@ziemianowicz.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 29 Apr 2018 15:01:11 -0400 Marcin Ziemianowicz wrote: > When a USB device is connected to the USB host port on the SAM9N12 then > you get "-62" error which seems to indicate USB replies from the device > are timing out. Based on a logic sniffer, I saw the USB bus was running > at half speed. > > The PLL code uses cached MUL and DIV values which get set in set_rate() > and applied in prepare(), but the recalc_rate() function instead > queries the hardware instead of using these cached values. Therefore, > if recalc_rate() is called between a set_rate() and prepare(), the > wrong frequency is calculated and later the USB clock divider for the > SAM9N12 SOC will be configured for an incorrect clock. > > In my case, the PLL hardware was set to 96 Mhz before the OHCI > driver loads, and therefore the usb clock divider was being set > to /2 even though the OHCI driver set the PLL to 48 Mhz. > > As an alternative explanation, I noticed this was fixed in the past by > 87e2ed338f1b ("clk: at91: fix recalc_rate implementation of PLL > driver") but the bug was later re-introduced by 1bdf02326b71 ("clk: > at91: make use of syscon/regmap internally"). > > Fixes: 1bdf02326b71 ("clk: at91: make use of syscon/regmap internally) > Cc: > Signed-off-by: Marcin Ziemianowicz Acked-by: Boris Brezillon > --- > Thank you for bearing with me about this Boris. > > Changes since V3: > Fix for double returns found by kbluild test robot > > Comments by Boris Brezillon about email formatting issues > Changes since V2: > Removed all logging/debug messages I added > > Comment by Boris Brezillon about my fix being wrong addressed > Changes since V1: > Added patch set cover letter > Shortened lines which were over >80 characters long > > Comment by Greg Kroah-Hartman about "from" field in email addressed > > Comment by Alan Stern about redundant debug lines addressed > > drivers/clk/at91/clk-pll.c | 13 +------------ > 1 file changed, 1 insertion(+), 12 deletions(-) > > diff --git a/drivers/clk/at91/clk-pll.c b/drivers/clk/at91/clk-pll.c > index 7d3223fc..72b6091e 100644 > --- a/drivers/clk/at91/clk-pll.c > +++ b/drivers/clk/at91/clk-pll.c > @@ -132,19 +132,8 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hw, > unsigned long parent_rate) > { > struct clk_pll *pll = to_clk_pll(hw); > - unsigned int pllr; > - u16 mul; > - u8 div; > - > - regmap_read(pll->regmap, PLL_REG(pll->id), &pllr); > - > - div = PLL_DIV(pllr); > - mul = PLL_MUL(pllr, pll->layout); > - > - if (!div || !mul) > - return 0; > > - return (parent_rate / div) * (mul + 1); > + return (parent_rate / pll->div) * (pll->mul + 1); > } > > static long clk_pll_get_best_div_mul(struct clk_pll *pll, unsigned long rate,