Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2146628ybg; Thu, 30 Jul 2020 11:28:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymCFPq+HQtLE9UrU9ox1u2EhapWiZyuTrlpFHheQyCe7cgBvpR6OQo0luAB+spx9Fx/KW2 X-Received: by 2002:a05:6402:1a26:: with SMTP id be6mr310459edb.162.1596133680372; Thu, 30 Jul 2020 11:28:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596133680; cv=none; d=google.com; s=arc-20160816; b=IMlUTg12bePuh4Pxds/Jy+FWugkp2R1Vzk0h9mm5qt6nYmpAPC9PkjrrIhYWwibOyA JTRms22Vn8157lj0PSRwlDaNnJmxma9AjS8RAZD6UbrRUd0jFvi+eMFecn3rKwScru5I OM+qO95xAchPq/mvcE9Pymo7oru1kQjPJADeg0hjQw+weX1b11y1mXxvd5TI69tRCynf eYUiCBL1Pg6g9u4BLnLme9sxm1KoDY2WCPrsG8CJb01vmnXaOE57ix7gY/6gMEKVCCC9 EELqVQpSJIqprtm80GUY24SZh6msPE2JqODRKTxicdCVq0XA9RpRbVPEva6Hi6phr6o8 XcNw== 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 :message-id:date:subject:cc:to:from; bh=1WvmFNSkKjgnoRl5WXYuoymfnfsTyJzhhSfZIOICBGc=; b=z3yOtM26HAiKk5J5FmpqHoP9uhbZXvXtGEarHGZ2ExXGDnPGmA0BcDWWDP7QdAliJI veUddmMjC0VmVmUNY8HB/kVjeSzbfMwCL3A4jw8f7Vz3YYeNO62SB9VBi7ZRd60X0wKV h6/WleQdhj29U6meaxKWCUtxjSBSBFXnVDdPZR6KH7lV5HeInkPbT6Y4z9pLW9jUhPMc zGVw6naxieEZ77ZiB7yw/t3JgCBUuNcl+akcaY6KekTef54JW9EGm4lSVmLyC7u+oxHp dIjwKCYxCdKi3/WQ+S4ma2GGGGzUYJV068aNUAXjWLB4HIXkdWEiI3ct57sWQbrVXWsf kirg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x23si1290295eju.37.2020.07.30.11.27.38; Thu, 30 Jul 2020 11:28:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730126AbgG3S0f (ORCPT + 99 others); Thu, 30 Jul 2020 14:26:35 -0400 Received: from mx2.suse.de ([195.135.220.15]:50562 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726343AbgG3S0e (ORCPT ); Thu, 30 Jul 2020 14:26:34 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DF4CDABCE; Thu, 30 Jul 2020 18:26:44 +0000 (UTC) From: Nicolas Saenz Julienne To: Nicolas Saenz Julienne , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Eric Anholt , Stefan Wahren , Matthias Brugger Cc: pbrobinson@gmail.com, kernel-list@raspberrypi.com, Nathan Chancellor , Michael Turquette , Stephen Boyd , linux-clk@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] clk: bcm2835: Do not use prediv with bcm2711's PLLs Date: Thu, 30 Jul 2020 20:26:19 +0200 Message-Id: <20200730182619.23246-1-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Contrary to previous SoCs, bcm2711 doesn't have a prescaler in the PLL feedback loop. Bypass it by zeroing fb_prediv_mask when running on bcm2711. Note that, since the prediv configuration bits were re-purposed, this was triggering miscalculations on all clocks hanging from the VPU clock, notably the aux UART, making its output unintelligible. Fixes: 42de9ad400af ("clk: bcm2835: Add BCM2711_CLOCK_EMMC2 support") Reported-by: Nathan Chancellor Signed-off-by: Nicolas Saenz Julienne --- Changes since v1: - Previous approach broken. Check if running on bcm2711 upon using fb_prediv_mask. FYI relevant discussion with RPi engineers: https://github.com/raspberrypi/firmware/issues/1435#issuecomment-666242077 drivers/clk/bcm/clk-bcm2835.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c index 027eba31f793..3439bc65bb4e 100644 --- a/drivers/clk/bcm/clk-bcm2835.c +++ b/drivers/clk/bcm/clk-bcm2835.c @@ -314,6 +314,7 @@ struct bcm2835_cprman { struct device *dev; void __iomem *regs; spinlock_t regs_lock; /* spinlock for all clocks */ + unsigned int soc; /* * Real names of cprman clock parents looked up through @@ -526,6 +527,20 @@ static int bcm2835_pll_is_on(struct clk_hw *hw) A2W_PLL_CTRL_PRST_DISABLE; } +static u32 bcm2835_pll_get_prediv_mask(struct bcm2835_cprman *cprman, + const struct bcm2835_pll_data *data) +{ + /* + * On BCM2711 there isn't a pre-divisor available in the PLL feedback + * loop. Bits 13:14 of ANA1 (PLLA,PLLB,PLLC,PLLD) have been re-purposed + * for to for VCO RANGE bits. + */ + if (cprman->soc & SOC_BCM2711) + return 0; + + return data->ana->fb_prediv_mask; +} + static void bcm2835_pll_choose_ndiv_and_fdiv(unsigned long rate, unsigned long parent_rate, u32 *ndiv, u32 *fdiv) @@ -583,7 +598,7 @@ static unsigned long bcm2835_pll_get_rate(struct clk_hw *hw, ndiv = (a2wctrl & A2W_PLL_CTRL_NDIV_MASK) >> A2W_PLL_CTRL_NDIV_SHIFT; pdiv = (a2wctrl & A2W_PLL_CTRL_PDIV_MASK) >> A2W_PLL_CTRL_PDIV_SHIFT; using_prediv = cprman_read(cprman, data->ana_reg_base + 4) & - data->ana->fb_prediv_mask; + bcm2835_pll_get_prediv_mask(cprman, data); if (using_prediv) { ndiv *= 2; @@ -666,6 +681,7 @@ static int bcm2835_pll_set_rate(struct clk_hw *hw, struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw); struct bcm2835_cprman *cprman = pll->cprman; const struct bcm2835_pll_data *data = pll->data; + u32 prediv_mask = bcm2835_pll_get_prediv_mask(cprman, data); bool was_using_prediv, use_fb_prediv, do_ana_setup_first; u32 ndiv, fdiv, a2w_ctl; u32 ana[4]; @@ -683,7 +699,7 @@ static int bcm2835_pll_set_rate(struct clk_hw *hw, for (i = 3; i >= 0; i--) ana[i] = cprman_read(cprman, data->ana_reg_base + i * 4); - was_using_prediv = ana[1] & data->ana->fb_prediv_mask; + was_using_prediv = ana[1] & prediv_mask; ana[0] &= ~data->ana->mask0; ana[0] |= data->ana->set0; @@ -693,10 +709,10 @@ static int bcm2835_pll_set_rate(struct clk_hw *hw, ana[3] |= data->ana->set3; if (was_using_prediv && !use_fb_prediv) { - ana[1] &= ~data->ana->fb_prediv_mask; + ana[1] &= ~prediv_mask; do_ana_setup_first = true; } else if (!was_using_prediv && use_fb_prediv) { - ana[1] |= data->ana->fb_prediv_mask; + ana[1] |= prediv_mask; do_ana_setup_first = false; } else { do_ana_setup_first = true; @@ -2262,6 +2278,7 @@ static int bcm2835_clk_probe(struct platform_device *pdev) platform_set_drvdata(pdev, cprman); cprman->onecell.num = asize; + cprman->soc = pdata->soc; hws = cprman->onecell.hws; for (i = 0; i < asize; i++) { -- 2.27.0