Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3729101pxb; Mon, 24 Jan 2022 16:31:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJz75eoKlrGFK1NFA1CR5sx7ZUHl5ao/lZtyv11dsG1qOlF0RZV9yz9QL5t3bl3eoWx5FsH1 X-Received: by 2002:a17:902:7148:b0:14b:650c:4ce7 with SMTP id u8-20020a170902714800b0014b650c4ce7mr3366802plm.4.1643070703144; Mon, 24 Jan 2022 16:31:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643070703; cv=none; d=google.com; s=arc-20160816; b=VgNNPGZh0kyAT7Hr/p5gKjGz938r1HwFxZxp9Gap9a+3ppMBR9eaFtYgH7VqK6rEQo 9L6jYSyR/VhB4+uKvOC6MdR+tk46A6JMVwl+bcpH1E9ptM2LJDFvWCtCiooO7HhFHhJK h702a6HbLVjP+kscg6q+5OL09Lh9pgVj/oBxL6Lr1ErufnluFd6WGQOF/6cLM0Bso6JR T3d76g5+NXaLpJ0uC4UeAlCYeQTcFk7qVdcrPsr+qg2MBtVAP35Nnj39nQxHoUc2m5wb cSqJCIX2kYdxK8CQxnB6E8pD3FXx1zizV8jNMbXu0bbOsdbgFs0qd5ifKoVYmT+Dnnst uGfQ== 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=IeVBvH8w9aMZ2bz+yawfVsKVbeZ465lgYXUDnDZC0N4=; b=Icp7YnAaJi05UFONAtqOb/3BymXDq9gMiyBLDfqYA1ESjLDshn9LFHn8ZDOYQ9mTNV 0IaRtm81XkjYNXPwQlpo9TXXgmvID1kQQMHA1HEVqpRw0l3gT93KghEwPnjlFl1gj7M2 ELWtA/3Ho0/Rx4v4pMIcsO9LR1gzcyd8NzvSJ2DN6RSt9RVih1iAlcOzf1smgycPftZi 9NJ1dSL5uDXfR9BcOasLNnNNLY9/vFYYXY5C9TKLzDS5M8USvqCnebeHJcKMIcH67qbZ 5oJzq1D0oi/p0hIyHU9xPIGnpBFrAm9HY7lkrHczd87iWDAYhj6PGTe1IQ2FB4YuT9jw VgeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C1iIRh4a; 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 pf5si861021pjb.10.2022.01.24.16.31.30; Mon, 24 Jan 2022 16:31:43 -0800 (PST) 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=C1iIRh4a; 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 S2374095AbiAYAQK (ORCPT + 99 others); Mon, 24 Jan 2022 19:16:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382508AbiAXX2E (ORCPT ); Mon, 24 Jan 2022 18:28:04 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73851C01D7F2; Mon, 24 Jan 2022 13:31:23 -0800 (PST) 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 30823B81142; Mon, 24 Jan 2022 21:31:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AC05C340E4; Mon, 24 Jan 2022 21:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059881; bh=yXNyj5w8WPn/dUWK5qhdWXLoj5pVBSY3hqJPXa2z4tY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C1iIRh4avFjF9wnxFq3Q24y9mSOwrA2KpE5juBvr6b7OYofqY4ZJnw61guiE2VmEs Xx1hKwmLBnlD7Pw4irZhplA2FSApxtM8wSR9v439RT+2oUbZdwNTdr7PrDUlZULcUB ZeWU+vz9Kxu+Qw5TLygbdem+ZJlQ0wUeexS0wl9I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sam Protsenko , Sylwester Nawrocki , Krzysztof Kozlowski , Sasha Levin Subject: [PATCH 5.16 0733/1039] clk: samsung: exynos850: Register clocks early Date: Mon, 24 Jan 2022 19:42:02 +0100 Message-Id: <20220124184149.962049672@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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: Sam Protsenko [ Upstream commit bcda841f9bf2cddcf2f000cba96f2e27f6f2bdbf ] Some clocks must be registered before init calls. For example MCT clock (from CMU_PERI) is needed for MCT timer driver, which is registered with TIMER_OF_DECLARE(). By the time we get to core_initcall() used for clk-exynos850 platform driver init, it's already too late. Inability to get "mct" clock in MCT driver leads to kernel panic, as functions registered with *_OF_DECLARE() can't do deferred calls. MCT timer driver can't be fixed either, as it's acting as a clock source and it's essential to register it in start_kernel() -> time_init(). Let's register CMU_PERI clocks early, using CLK_OF_DECLARE(). CMU_TOP generates clocks needed for CMU_PERI, but it's already registered early. While at it, let's cleanup the code a bit, by extracting everything related to CMU initialization and registration to the separate function. Similar issue was discussed at [1] and addressed in commit 1f7db7bbf031 ("clk: renesas: cpg-mssr: Add early clock support"), as well as in drivers/clk/mediatek/clk-mt2712.c. [1] https://patchwork.kernel.org/project/linux-renesas-soc/patch/20180829132954.64862-2-chris.brandt@renesas.com/ Signed-off-by: Sam Protsenko Signed-off-by: Sylwester Nawrocki Reviewed-by: Krzysztof Kozlowski Link: https://lore.kernel.org/r/20211122144206.23134-1-semen.protsenko@linaro.org Signed-off-by: Sasha Levin --- drivers/clk/samsung/clk-exynos850.c | 70 ++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 21 deletions(-) diff --git a/drivers/clk/samsung/clk-exynos850.c b/drivers/clk/samsung/clk-exynos850.c index 2294989e244c5..79cce8ba88831 100644 --- a/drivers/clk/samsung/clk-exynos850.c +++ b/drivers/clk/samsung/clk-exynos850.c @@ -60,6 +60,43 @@ static void __init exynos850_init_clocks(struct device_node *np, iounmap(reg_base); } +/** + * exynos850_register_cmu - Register specified Exynos850 CMU domain + * @dev: Device object; may be NULL if this function is not being + * called from platform driver probe function + * @np: CMU device tree node + * @cmu: CMU data + * + * Register specified CMU domain, which includes next steps: + * + * 1. Enable parent clock of @cmu CMU + * 2. Set initial registers configuration for @cmu CMU clocks + * 3. Register @cmu CMU clocks using Samsung clock framework API + */ +static void __init exynos850_register_cmu(struct device *dev, + struct device_node *np, const struct samsung_cmu_info *cmu) +{ + /* Keep CMU parent clock running (needed for CMU registers access) */ + if (cmu->clk_name) { + struct clk *parent_clk; + + if (dev) + parent_clk = clk_get(dev, cmu->clk_name); + else + parent_clk = of_clk_get_by_name(np, cmu->clk_name); + + if (IS_ERR(parent_clk)) { + pr_err("%s: could not find bus clock %s; err = %ld\n", + __func__, cmu->clk_name, PTR_ERR(parent_clk)); + } else { + clk_prepare_enable(parent_clk); + } + } + + exynos850_init_clocks(np, cmu->clk_regs, cmu->nr_clk_regs); + samsung_cmu_register_one(np, cmu); +} + /* ---- CMU_TOP ------------------------------------------------------------- */ /* Register Offset definitions for CMU_TOP (0x120e0000) */ @@ -347,10 +384,10 @@ static const struct samsung_cmu_info top_cmu_info __initconst = { static void __init exynos850_cmu_top_init(struct device_node *np) { - exynos850_init_clocks(np, top_clk_regs, ARRAY_SIZE(top_clk_regs)); - samsung_cmu_register_one(np, &top_cmu_info); + exynos850_register_cmu(NULL, np, &top_cmu_info); } +/* Register CMU_TOP early, as it's a dependency for other early domains */ CLK_OF_DECLARE(exynos850_cmu_top, "samsung,exynos850-cmu-top", exynos850_cmu_top_init); @@ -615,6 +652,15 @@ static const struct samsung_cmu_info peri_cmu_info __initconst = { .clk_name = "dout_peri_bus", }; +static void __init exynos850_cmu_peri_init(struct device_node *np) +{ + exynos850_register_cmu(NULL, np, &peri_cmu_info); +} + +/* Register CMU_PERI early, as it's needed for MCT timer */ +CLK_OF_DECLARE(exynos850_cmu_peri, "samsung,exynos850-cmu-peri", + exynos850_cmu_peri_init); + /* ---- CMU_CORE ------------------------------------------------------------ */ /* Register Offset definitions for CMU_CORE (0x12000000) */ @@ -779,24 +825,9 @@ static int __init exynos850_cmu_probe(struct platform_device *pdev) { const struct samsung_cmu_info *info; struct device *dev = &pdev->dev; - struct device_node *np = dev->of_node; info = of_device_get_match_data(dev); - exynos850_init_clocks(np, info->clk_regs, info->nr_clk_regs); - samsung_cmu_register_one(np, info); - - /* Keep bus clock running, so it's possible to access CMU registers */ - if (info->clk_name) { - struct clk *bus_clk; - - bus_clk = clk_get(dev, info->clk_name); - if (IS_ERR(bus_clk)) { - pr_err("%s: could not find bus clock %s; err = %ld\n", - __func__, info->clk_name, PTR_ERR(bus_clk)); - } else { - clk_prepare_enable(bus_clk); - } - } + exynos850_register_cmu(dev, dev->of_node, info); return 0; } @@ -806,9 +837,6 @@ static const struct of_device_id exynos850_cmu_of_match[] = { { .compatible = "samsung,exynos850-cmu-hsi", .data = &hsi_cmu_info, - }, { - .compatible = "samsung,exynos850-cmu-peri", - .data = &peri_cmu_info, }, { .compatible = "samsung,exynos850-cmu-core", .data = &core_cmu_info, -- 2.34.1