From patchwork Fri Oct 13 18:17:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jernej_=C5=A0krabec?= X-Patchwork-Id: 13421557 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2D0DECDB47E for ; Fri, 13 Oct 2023 18:18:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=w1FsXHmtXKBnCpuWhO9LV0qAr/E0ef2mIHhCMUK3vpI=; b=2CgsDb+oLVKmQv W14c/5bbxXbYC3EtU8KBmRXym/hQqUvTgFGSznQJKc64/HbxIXfs/V/NIYL4wWKGBNrScZe5MJgl9 rApD68Ft2CCa3ouhnF1Xq+pH8DswYi8MDTWkWAsm1XOX012YQoyXrr3X0BbzMj6WdxoDxafx0o3/T mFg/YIecLtZB+0OzmSv9xTI8n4/KDlEHK/aW5MZV7V/y6PVxyeSz6gGv3Q+T7drgFkgyQKRZyiCNe xV74o55yuZvjpz0ODDQI4iep6GGQTGVl6yvUW0bvvfJooVas/QMiL74BwCDhmPc6e8Wt6WTkbEL5p uph7TSoi6V3pZKAaP+QQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qrMj9-0042Rk-2c; Fri, 13 Oct 2023 18:17:35 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qrMj6-0042Qo-2m for linux-arm-kernel@lists.infradead.org; Fri, 13 Oct 2023 18:17:34 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-40776b200e5so3767195e9.2 for ; Fri, 13 Oct 2023 11:17:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697221050; x=1697825850; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=U9nTHaFndFfh4gMEpmSZ2pg3B4FHQG8rnUIGTQ2gc1Q=; b=J08k3jWuZEWTXaJ6KLXIGEaatOYBG468SbhXfQeo9KTcbdjta8ZDViG2lBEnq6bX+K 5t8nenhStfysuOqPdyTwnPDLo8X6tXR9AHhrs7D7CjFmzZbdlmiU6KbVkF86iJoaHI0L tRqcxi882KsJjr8/TW0da8f7uN9sdoNS+CT5eL7Vv536jNhvU7TvyrWQ6hlET+0paMFy fy1M3fFXW73OBRapP7maOgr88mOpRkmPdpsDnr6GUi+pOFp+pFO8z6XCUuQvB2zlAb/p Xr/t8eqNWOe8nkNujSmA5oGAU9Ke2rBWk8jvjUT/BU8skQrtHzv3Tl2/64LQB7YiSndK kX+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697221050; x=1697825850; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=U9nTHaFndFfh4gMEpmSZ2pg3B4FHQG8rnUIGTQ2gc1Q=; b=n5eiRQUUFHuw4n107vxodvdrvfbLUSwAiBPk2TWo7PbCml/S8y/g+gTa2KAvUPydvp t0Rbs5oxI+fzxwWjdMEPq0Po4kqjmJT1nHk3eHcRyrQvNJIe51kGysL9wqLykBQpXCK4 Lcf7YHQ1XRvJPx7w/aSx6gY015LBFEndN9MHVrNVbihRKXQdIRh8XCFDcw2ZQucacUs9 wFCuXmpVK/4BpaIKI8aOxOwA5gqg4ipDD3NUKe7Obx7446qqAyL8Pj87MhApTHcWunfy PVItIoKuh91ma3Y2taLPbWtNADYglL6UV9fRBBDrdOlHYlT56qOQKLPfdJykFxGjBtpd l5+g== X-Gm-Message-State: AOJu0YxZs9QWeKbQYdmF5EJ8oaZGjZezpB9iqDMkuVf6UUys5PJbGOD7 LQysaTYOKUMD/8iNd4RjsbQ= X-Google-Smtp-Source: AGHT+IEMQY+8CQG2bWBaKCxftHAZJe3ebRiK21zhKCFBNlUyZOjkFnTF7uZ1aniwLQKOsBk9CH5xOA== X-Received: by 2002:a05:600c:3586:b0:406:849c:52c3 with SMTP id p6-20020a05600c358600b00406849c52c3mr23139477wmq.22.1697221049878; Fri, 13 Oct 2023 11:17:29 -0700 (PDT) Received: from localhost.localdomain ([188.159.248.16]) by smtp.gmail.com with ESMTPSA id r8-20020a05600c458800b004064cd71aa8sm800127wmo.34.2023.10.13.11.17.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 11:17:29 -0700 (PDT) From: Jernej Skrabec To: wens@csie.org, samuel@sholland.org Cc: sboyd@kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Jernej Skrabec , Chad Wagner Subject: [PATCH] clk: sunxi-ng: h6: Reparent CPUX during PLL CPUX rate change Date: Fri, 13 Oct 2023 20:17:12 +0200 Message-ID: <20231013181712.2128037-1-jernej.skrabec@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231013_111732_897705_D309D0C2 X-CRM114-Status: GOOD ( 14.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org While PLL CPUX clock rate change when CPU is running from it works in vast majority of cases, now and then it causes instability. This leads to system crashes and other undefined behaviour. After a lot of testing (30+ hours) while also doing a lot of frequency switches, we can't observe any instability issues anymore when doing reparenting to stable clock like 24 MHz oscillator. Fixes: 524353ea480b ("clk: sunxi-ng: add support for the Allwinner H6 CCU") Reported-by: Chad Wagner Link: https://forum.libreelec.tv/thread/27295-orange-pi-3-lts-freezes/ Tested-by: Chad Wagner Signed-off-by: Jernej Skrabec Reviewed-by: Chen-Yu Tsai --- drivers/clk/sunxi-ng/ccu-sun50i-h6.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu-sun50i-h6.c b/drivers/clk/sunxi-ng/ccu-sun50i-h6.c index 42568c616181..892df807275c 100644 --- a/drivers/clk/sunxi-ng/ccu-sun50i-h6.c +++ b/drivers/clk/sunxi-ng/ccu-sun50i-h6.c @@ -1181,11 +1181,18 @@ static const u32 usb2_clk_regs[] = { SUN50I_H6_USB3_CLK_REG, }; +static struct ccu_mux_nb sun50i_h6_cpu_nb = { + .common = &cpux_clk.common, + .cm = &cpux_clk.mux, + .delay_us = 1, + .bypass_index = 0, /* index of 24 MHz oscillator */ +}; + static int sun50i_h6_ccu_probe(struct platform_device *pdev) { void __iomem *reg; + int i, ret; u32 val; - int i; reg = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(reg)) @@ -1252,7 +1259,15 @@ static int sun50i_h6_ccu_probe(struct platform_device *pdev) val |= BIT(24); writel(val, reg + SUN50I_H6_HDMI_CEC_CLK_REG); - return devm_sunxi_ccu_probe(&pdev->dev, reg, &sun50i_h6_ccu_desc); + ret = devm_sunxi_ccu_probe(&pdev->dev, reg, &sun50i_h6_ccu_desc); + if (ret) + return ret; + + /* Reparent CPU during PLL CPUX rate changes */ + ccu_mux_notifier_register(pll_cpux_clk.common.hw.clk, + &sun50i_h6_cpu_nb); + + return 0; } static const struct of_device_id sun50i_h6_ccu_ids[] = {