Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4716498pxj; Wed, 12 May 2021 11:34:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrLnpklmnxXK8eY2kYhD5zGx8cKNhFmS5OeS8tmXqf8ZDwOZi5M2GTnOvE8/O5Q8vm1ldE X-Received: by 2002:a17:907:960b:: with SMTP id gb11mr38543850ejc.123.1620844384798; Wed, 12 May 2021 11:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620844384; cv=none; d=google.com; s=arc-20160816; b=bsIfzVVZoKKBOmVhyeFGuyvrGuNlPQxbzOXPYbMX0H8ocO8aH0hz1vUq6yQskvJ3TU RC/G5eg8jOhkGkVJMeH0B/rt07EyBpTPMsgD79ZU7AAgBIhzr/BhJCPQq6UyvWY2LGCQ RdvlOTvqNqvOABnOL34FpKAsoAKyf++tmXqR8SzKT1ACzxPAeBaPkcbHpbxNarcDBkT4 vMLMyyE6n7oor7SrIOJj6lMP9Jnns75gf91A7GsTZy0I/8nmKKH0/ShMpa6S/QU1URAH Jq9dGqDLcQbWyNX7i9vfojiu0EvXF4qfMJeV/QGsabp2qVrKV6LSOB3CUPLTpyTvFH0A ngJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VMKE8psC4HbiWM8sJOrbwX62G+8w/zvOZvFqyRASSJk=; b=EFNCI/I25bCLYEoy+IENqj/my4EYPcekQMEkiiKvFZO2d/I4CrBRZxyqrwlYO8ZEyq va6mvvF5+x4utvWgtFBOp0rNnXdLM1hP57IvKgkUMe5vysHmKwhtbr8gSbNyoIydDZDj cjPjTe/hMkfpNWC+6ycl2q/Vx+fXRt6myzPWnJtqOvN7CIegWNsLQ4+KZi2HK1Upiup8 EuvSPCd/moAyTkMQriZaofr59wwzSG3e0uCUFtY9QBUhCujyMGK8L6NcCnWL4yNU1YyA 0AY9tOALo5AHpYG0zzEBk0hUdwZ4I5EGaF3AQwULjkJAWztSOs3RYPFQ9fB2jkp9iKlG dRVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rrRMmJZj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g24si679086ejd.476.2021.05.12.11.32.40; Wed, 12 May 2021 11:33:04 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rrRMmJZj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232496AbhELScw (ORCPT + 99 others); Wed, 12 May 2021 14:32:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:57038 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243252AbhELQhA (ORCPT ); Wed, 12 May 2021 12:37:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2D51B61E1E; Wed, 12 May 2021 16:01:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620835306; bh=p0lCA4VYdh3J0t8dpCyjPcKjvOAbvI8fFEaW1B1W15U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rrRMmJZj8ajLVen0mImOMvVqtTPx9v2/Cj/b42d59iaKuNnrKvz1TftiGXmYWG0pg MkxRfQOrJmJfNKpypFgXI9fE3uvQg3uRbSo4HRhclsw4qxFoG3g7tI0SF20EDSgvWc CDAgPpvTOA0f1eEbbAG/QYIUcBW4FQPFSB6ooY8Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Marek=20Beh=C3=BAn?= , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Stephen Boyd , Gregory CLEMENT , Tomasz Maciej Nowak , Anders Trier Olesen , Philip Soares , Viresh Kumar , Sasha Levin Subject: [PATCH 5.12 290/677] clk: mvebu: armada-37xx-periph: Fix workaround for switching from L1 to L0 Date: Wed, 12 May 2021 16:45:36 +0200 Message-Id: <20210512144846.854945868@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pali Rohár [ Upstream commit e93033aff684641f71a436ca7a9d2a742126baaf ] When CPU frequency is at 250 MHz and set_rate() is called with 500 MHz (L1) quickly followed by a call with 1 GHz (L0), the CPU does not necessarily stay in L1 for at least 20ms as is required by Marvell errata. This situation happens frequently with the ondemand cpufreq governor and can be also reproduced with userspace governor. In most cases it causes CPU to crash. This change fixes the above issue and ensures that the CPU always stays in L1 for at least 20ms when switching from any state to L0. Signed-off-by: Marek Behún Signed-off-by: Pali Rohár Acked-by: Stephen Boyd Acked-by: Gregory CLEMENT Tested-by: Tomasz Maciej Nowak Tested-by: Anders Trier Olesen Tested-by: Philip Soares Fixes: 61c40f35f5cd ("clk: mvebu: armada-37xx-periph: Fix switching CPU rate from 300Mhz to 1.2GHz") Signed-off-by: Viresh Kumar Signed-off-by: Sasha Levin --- drivers/clk/mvebu/armada-37xx-periph.c | 45 ++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mvebu/armada-37xx-periph.c index b15e177bea7e..32ac6b6b7530 100644 --- a/drivers/clk/mvebu/armada-37xx-periph.c +++ b/drivers/clk/mvebu/armada-37xx-periph.c @@ -84,6 +84,7 @@ struct clk_pm_cpu { void __iomem *reg_div; u8 shift_div; struct regmap *nb_pm_base; + unsigned long l1_expiration; }; #define to_clk_double_div(_hw) container_of(_hw, struct clk_double_div, hw) @@ -504,22 +505,52 @@ static long clk_pm_cpu_round_rate(struct clk_hw *hw, unsigned long rate, * 2. Sleep 20ms for stabling VDD voltage * 3. Then switch from L1 (500/600 MHz) to L0 (1000/1200 MHz). */ -static void clk_pm_cpu_set_rate_wa(unsigned long rate, struct regmap *base) +static void clk_pm_cpu_set_rate_wa(struct clk_pm_cpu *pm_cpu, + unsigned int new_level, unsigned long rate, + struct regmap *base) { unsigned int cur_level; - if (rate < 1000 * 1000 * 1000) - return; - regmap_read(base, ARMADA_37XX_NB_CPU_LOAD, &cur_level); cur_level &= ARMADA_37XX_NB_CPU_LOAD_MASK; - if (cur_level <= ARMADA_37XX_DVFS_LOAD_1) + + if (cur_level == new_level) + return; + + /* + * System wants to go to L1 on its own. If we are going from L2/L3, + * remember when 20ms will expire. If from L0, set the value so that + * next switch to L0 won't have to wait. + */ + if (new_level == ARMADA_37XX_DVFS_LOAD_1) { + if (cur_level == ARMADA_37XX_DVFS_LOAD_0) + pm_cpu->l1_expiration = jiffies; + else + pm_cpu->l1_expiration = jiffies + msecs_to_jiffies(20); return; + } + + /* + * If we are setting to L2/L3, just invalidate L1 expiration time, + * sleeping is not needed. + */ + if (rate < 1000*1000*1000) + goto invalidate_l1_exp; + + /* + * We are going to L0 with rate >= 1GHz. Check whether we have been at + * L1 for long enough time. If not, go to L1 for 20ms. + */ + if (pm_cpu->l1_expiration && jiffies >= pm_cpu->l1_expiration) + goto invalidate_l1_exp; regmap_update_bits(base, ARMADA_37XX_NB_CPU_LOAD, ARMADA_37XX_NB_CPU_LOAD_MASK, ARMADA_37XX_DVFS_LOAD_1); msleep(20); + +invalidate_l1_exp: + pm_cpu->l1_expiration = 0; } static int clk_pm_cpu_set_rate(struct clk_hw *hw, unsigned long rate, @@ -553,7 +584,9 @@ static int clk_pm_cpu_set_rate(struct clk_hw *hw, unsigned long rate, reg = ARMADA_37XX_NB_CPU_LOAD; mask = ARMADA_37XX_NB_CPU_LOAD_MASK; - clk_pm_cpu_set_rate_wa(rate, base); + /* Apply workaround when base CPU frequency is 1000 or 1200 MHz */ + if (parent_rate >= 1000*1000*1000) + clk_pm_cpu_set_rate_wa(pm_cpu, load_level, rate, base); regmap_update_bits(base, reg, mask, load_level); -- 2.30.2