Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2493105rwb; Mon, 3 Oct 2022 01:15:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4X4ywR5eyS+ZxUKtMSl3qo11SkWf7s9YIm5p+uJ8sjldKuTsMqLZTwUtU0LWTvefSZgSM5 X-Received: by 2002:a17:902:e751:b0:178:2976:41a0 with SMTP id p17-20020a170902e75100b00178297641a0mr20843213plf.12.1664784916337; Mon, 03 Oct 2022 01:15:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664784916; cv=none; d=google.com; s=arc-20160816; b=lw99hYhTV1zKYap1yjwbVEcorW6s42ZrCkoKqu4ZZd1aLZC1XqkkV/EDYXQRrosjGs VkhipCUP/FfVNznwNZoOyFDKHSzUR7a4f/K59T8zkMhJEgfU2j3LdcOVyv2QiHQs3UwW /gRHWHwL9ep2C1vbvk43ZiAuJqZY+THXKik+tbq13G7nIciHbXk/uS+Zepmob8A2MRQN VcUj/19Xh3CaKNK5hs7eEnaPlGcbTNFalli/1MRgmMJU1dn0ztC14l5YI2DhOlPJfjka DCab0Zo6yqQD2tqloYl6z+j/Iq2iurOMJF8LaDoCuhrZ3Hp4nCj2jHPU6Hx4vwQp9iZk CTxg== 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=Ub/TAkRtfaL2k1Xpa4TQthAO0y5oobU0uwQqNexnOzA=; b=xHb/2KFqi0UiLsfn4uDLJIuPUJGlujWRMLHNblEzRcynPXdvNFvQMn+PTyocZP4y2C IstlHVwHTLSlWai8hbd1hwge+uNitLxSHS8IKE8NxTkvqflM58yaCGTamDYy7as1QVhO D0XMYbMmW5nvaHw0xHypZdX48ceA8OoYNp5mKKed2lcNDg8CS/sDNRBW5+W3Hk/muSfu XvVWSBRQgeQC1XnyRP7NutPpC6JnPe+RjStUvogTZEKXN14Xz0Lku6gkScc9Oer1nYPR zgIN/RmNGNXO6wX7SgTJjS6fSV+7qWhjgIEb/AZEKf0AnybeZSn04AA5E10OTZ1K8yiO pAig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ss063P/E"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a10-20020a63d40a000000b0044029600311si9518322pgh.553.2022.10.03.01.15.04; Mon, 03 Oct 2022 01:15:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ss063P/E"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231700AbiJCHgb (ORCPT + 99 others); Mon, 3 Oct 2022 03:36:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231874AbiJCHes (ORCPT ); Mon, 3 Oct 2022 03:34:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78A424A12E; Mon, 3 Oct 2022 00:22:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4C453B80E6B; Mon, 3 Oct 2022 07:20:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3BA5C433C1; Mon, 3 Oct 2022 07:20:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664781653; bh=ZpKjv/MqU+BVENNAyJSrumUBGjzF0RDQDNmlN6qablY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ss063P/ExmHm9E/ZbawBhNbgISKhPYs65rRbU51uak7TkPEjxui9kkduSMeJccZxK 9x6F/Ycaz51zd8GQoCeetsfxNOrcLkBjr389uUyTkkvBPaXoUZX0OnvLpOAB2ck3Z/ a2B4Cw9UV4ViedxfyqJt4FFLarH7jVTfHzAPzUGs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paul Cercueil , Aidan MacDonald , Stephen Boyd Subject: [PATCH 5.10 15/52] clk: ingenic-tcu: Properly enable registers before accessing timers Date: Mon, 3 Oct 2022 09:11:22 +0200 Message-Id: <20221003070719.179858559@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003070718.687440096@linuxfoundation.org> References: <20221003070718.687440096@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Aidan MacDonald commit 6726d552a6912e88cf63fe2bda87b2efa0efc7d0 upstream. Access to registers is guarded by ingenic_tcu_{enable,disable}_regs() so the stop bit can be cleared before accessing a timer channel, but those functions did not clear the stop bit on SoCs with a global TCU clock gate. Testing on the X1000 has revealed that the stop bits must be cleared _and_ the global TCU clock must be ungated to access timer registers. This appears to be the norm on Ingenic SoCs, and is specified in the documentation for the X1000 and numerous JZ47xx SoCs. If the stop bit isn't cleared, register writes don't take effect and the system can be left in a broken state, eg. the watchdog timer may not run. The bug probably went unnoticed because stop bits are zeroed when the SoC is reset, and the kernel does not set them unless a timer gets disabled at runtime. However, it is possible that a bootloader or a previous kernel (if using kexec) leaves the stop bits set and we should not rely on them being cleared. Fixing this is easy: have ingenic_tcu_{enable,disable}_regs() always clear the stop bit, regardless of the presence of a global TCU gate. Reviewed-by: Paul Cercueil Tested-by: Paul Cercueil Fixes: 4f89e4b8f121 ("clk: ingenic: Add driver for the TCU clocks") Cc: stable@vger.kernel.org Signed-off-by: Aidan MacDonald Link: https://lore.kernel.org/r/20220617122254.738900-1-aidanmacdonald.0x0@gmail.com Signed-off-by: Stephen Boyd Signed-off-by: Greg Kroah-Hartman --- drivers/clk/ingenic/tcu.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) --- a/drivers/clk/ingenic/tcu.c +++ b/drivers/clk/ingenic/tcu.c @@ -100,15 +100,11 @@ static bool ingenic_tcu_enable_regs(stru bool enabled = false; /* - * If the SoC has no global TCU clock, we must ungate the channel's - * clock to be able to access its registers. - * If we have a TCU clock, it will be enabled automatically as it has - * been attached to the regmap. + * According to the programming manual, a timer channel's registers can + * only be accessed when the channel's stop bit is clear. */ - if (!tcu->clk) { - enabled = !!ingenic_tcu_is_enabled(hw); - regmap_write(tcu->map, TCU_REG_TSCR, BIT(info->gate_bit)); - } + enabled = !!ingenic_tcu_is_enabled(hw); + regmap_write(tcu->map, TCU_REG_TSCR, BIT(info->gate_bit)); return enabled; } @@ -119,8 +115,7 @@ static void ingenic_tcu_disable_regs(str const struct ingenic_tcu_clk_info *info = tcu_clk->info; struct ingenic_tcu *tcu = tcu_clk->tcu; - if (!tcu->clk) - regmap_write(tcu->map, TCU_REG_TSSR, BIT(info->gate_bit)); + regmap_write(tcu->map, TCU_REG_TSSR, BIT(info->gate_bit)); } static u8 ingenic_tcu_get_parent(struct clk_hw *hw)