From patchwork Fri Feb 16 22:32:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 202389 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp28100dyc; Fri, 16 Feb 2024 14:35:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWbtgGgzNBhmzgwSeMoyOsLuFoWC0LMYSjb5fempTTp5eKJU1+qsTRodjPSsfvhroVp+kdVordRe1/lQoaGcWn9Q48MAA== X-Google-Smtp-Source: AGHT+IFYxN7G0ePowJgAghrfva0SgAhL/+N+yEvkCJUNYGauuiEJjkGdFCjrOfppHMCX5o5M6P2/ X-Received: by 2002:a17:906:af09:b0:a3d:3aef:2311 with SMTP id lx9-20020a170906af0900b00a3d3aef2311mr4938900ejb.35.1708122918134; Fri, 16 Feb 2024 14:35:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708122918; cv=pass; d=google.com; s=arc-20160816; b=hnV4R1cx2Ho7Q9deR7Yjy7UE4TJezVNBZEl7zVRTR8B1poCh7HvTH0a93vwsw+tiVm 6dTyNzn6xTHzsw/FrXm4C4NDp7rCPz9Zjl7otViRyk7seg5I4+/+KXcxxftW/LzLr3AV rIrI9d+ZtZgTKzjlAJiqRmWyMWgk32hlgaZ5st9vDd9tc/r3v61ZeWUzpp6VzkBWc57T kTFQ7GrZPaWP/AVr+tSu/vTR/BdNeMrn3TPDfG5Tsc78U0eYm0g90N5Gd5Ut51U5Mza5 OKi7NYhOF3jqsog8MWfeSK+f+Lm8HhABA6iRsWiaDcAuGQdzsSUgYO7qm5Vaic/ABKou UQJA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Cx1pe3dvuwBHZD5HJSTuBK3OcEfxD8vb8RyVZ6GAHCM=; fh=x2b+KMDPIooLKs89rm8VmTqr9zcrrkHg24dkWI5Zk1U=; b=T+U0ASYvipsHfXVvG0evEPEihQo3eMDLXLkfQivDufHRdwus2RXAGXKmGtHG8l2ilI 5621u0tCf61xK+PNi8Nnw3MXFYc++8o/V1S/65ZH4DNvQmFB/xuXvHR6cToaCo5Cfm+8 LbcBaZWbw2+FGNKR1qj+w0UeXZhQ1wVxUK4WkQFs/G7qDgg/Mxean2U1MIUwX/gw0rVS y/E1fsQkAsezNp8IjL2J6zwSYfL8VEyYQNbVnjqZ/d+b0x+qb6TuyKgYd+eV8QiX/sil 1Bi1r0AwXJ0JwBvHsr2bAqkGax491UbQCGDkBkiKv6NX0/O9njHJMVzpTot//fVNB8hd NTqw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O4mXHuMq; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-69411-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69411-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l20-20020a17090612d400b00a3d6382a307si320119ejb.830.2024.02.16.14.35.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 14:35:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69411-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O4mXHuMq; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-69411-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69411-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 930471F25C27 for ; Fri, 16 Feb 2024 22:35:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7655414C58E; Fri, 16 Feb 2024 22:33:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="O4mXHuMq" Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB89C1487E0 for ; Fri, 16 Feb 2024 22:32:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708122773; cv=none; b=dRrUbQ0DBRBB4lt8LN3SvM2Q4k4dsViaXfdK5m+jjGsx8UzIJTSmP2ecCTIrQ1zHqhqdUKa/0Ehd8n4JXjgqM4A3NZCcLFRrB7Y5lH/THYhvNIQfdEFp3ZYudOVdqcLPgy6UjwxR6kyvPM+44j/obLhUu5M6Fc6XSLa1E8AFiMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708122773; c=relaxed/simple; bh=EENDe8i/hIP1jaiAMmy2hIQ5Oop2tfzV0CgfTOHuWhQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jNdNYed1j1R+9lU5JBBCI7d+lqRttu8fUreqRLiGiXpw+em5dyOLjdUmJVV9QIG3opHJmOb3UeJ4rmTdb19SIXdqm/ljxF6UjkG/xK5hDZx5lJXV3Jypt5rquFk6fm/mr3v199ZWq3ZWMvSqqbiPT1Wc4o1isrbXWVy8tpiW86A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=O4mXHuMq; arc=none smtp.client-ip=209.85.167.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-3c0d59a219dso1523137b6e.0 for ; Fri, 16 Feb 2024 14:32:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708122770; x=1708727570; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Cx1pe3dvuwBHZD5HJSTuBK3OcEfxD8vb8RyVZ6GAHCM=; b=O4mXHuMqabKAVCvrsY+CQ+q/5OJcYY3h5RHafCq3TYkYrZ84WuHK00bN+c0n75Pk8x +a7w5FH+YeeVaS3dsUpALcDSuI3SdCQWTSgfcjccIQpyaNvx3rSdzUC7nmYd/OE7B0Cd QwgTTuwlzlrIS3DZB7DTbBcng9/pZ/W158gfRSS69yXsRnbQzWsKE3FjBN7DroMT6f4w vOSOPBCWwTn3HdTkcyUcVd2th8Fln3Uho1j4CqI8iwMERGhyAspHXgSwymaQocBd38YW iBfAnBpeXFOAi8Wpkpsr3LmL8vZ+viU6xCof7YJ1uhdkMLkaJ+axHY9QYsF6DVDP1599 id9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708122770; x=1708727570; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cx1pe3dvuwBHZD5HJSTuBK3OcEfxD8vb8RyVZ6GAHCM=; b=vrjQFSFZcGmtPrThbz7u0vTa5tlKrkCA9jYQcZXDqcsWEulQFiYFXerHGtxL7GgZKT XffsY6EP+qH0tS8JIFQOIbPy5b7zerO/nenVBOIs4JaaXMQcLFaDjlgCZTjb9mx206x7 bzW3VTJ/ZZSKC5jcsCdirCGppWfLXLgPqS8k8oa7F95aQITbRIJCx+1WXX4Ac8bfRWsL dppglMIhqengNbHuSCE/RfLs6IfgRugbuQN2SmsiPiA7t5P1PkQ3aXUSkDkHUx5+KFTN x028BgRJaT/QI3BJkvQNyAhbN1Cy1pd2V9b9vMvmEUXxP6K0mwvMW/E5EBPtum7eYlz6 tmMg== X-Forwarded-Encrypted: i=1; AJvYcCW+3AsOCYn1JTKiS0h4cy++3kV/8hWQgmSMGhRdFODdlF1mn5iKqqjqDptE/Rs4PAzw4ldotYbMbGUCi9iOmmiE3+0t/gq/VneY9U64 X-Gm-Message-State: AOJu0YwdaH7C2tnqzK0scAvgR9stoaJASxCYLGbMrYVLZnGp40iHEVW1 t84WEdln/ho5pxAxw3jS7u6flfj/DGkg9lrM0BF9jthDvIiTar90p3IxfYosFnc= X-Received: by 2002:a05:6808:118b:b0:3c0:32d7:b93b with SMTP id j11-20020a056808118b00b003c032d7b93bmr6891732oil.50.1708122769980; Fri, 16 Feb 2024 14:32:49 -0800 (PST) Received: from localhost ([136.62.192.75]) by smtp.gmail.com with ESMTPSA id y16-20020a056808131000b003c046fa43d7sm127176oiv.19.2024.02.16.14.32.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 14:32:49 -0800 (PST) From: Sam Protsenko To: Krzysztof Kozlowski , Sylwester Nawrocki , Chanwoo Choi Cc: Alim Akhtar , Michael Turquette , Stephen Boyd , Rob Herring , Conor Dooley , Tomasz Figa , linux-samsung-soc@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/16] clk: samsung: Use single CPU clock notifier callback for all chips Date: Fri, 16 Feb 2024 16:32:34 -0600 Message-Id: <20240216223245.12273-6-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240216223245.12273-1-semen.protsenko@linaro.org> References: <20240216223245.12273-1-semen.protsenko@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791096697228000621 X-GMAIL-MSGID: 1791096697228000621 Reduce the code duplication by making all chips use a single version of exynos_cpuclk_notifier_cb() function. That will prevent the code bloat when adding new chips support too. Also don't pass base address to pre/post rate change functions, as it can be easily derived from already passed cpuclk param. No functional change. Signed-off-by: Sam Protsenko --- drivers/clk/samsung/clk-cpu.c | 63 ++++++++++++++++------------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/drivers/clk/samsung/clk-cpu.c b/drivers/clk/samsung/clk-cpu.c index 7b6fd331a7ec..427018e8dd8c 100644 --- a/drivers/clk/samsung/clk-cpu.c +++ b/drivers/clk/samsung/clk-cpu.c @@ -66,6 +66,11 @@ #define DIV_MASK_ALL GENMASK(31, 0) #define MUX_MASK GENMASK(2, 0) +struct exynos_cpuclk; + +typedef int (*exynos_rate_change_fn_t)(struct clk_notifier_data *ndata, + struct exynos_cpuclk *cpuclk); + /** * struct exynos_cpuclk - information about clock supplied to a CPU core * @hw: handle between CCF and CPU clock @@ -78,6 +83,8 @@ * @clk_nb: clock notifier registered for changes in clock speed of the * primary parent clock * @flags: configuration flags for the CPU clock + * @pre_rate_cb: callback to run before CPU clock rate change + * @post_rate_cb: callback to run after CPU clock rate change * * This structure holds information required for programming the CPU clock for * various clock speeds. @@ -91,6 +98,9 @@ struct exynos_cpuclk { const unsigned long num_cfgs; struct notifier_block clk_nb; unsigned long flags; + + exynos_rate_change_fn_t pre_rate_cb; + exynos_rate_change_fn_t post_rate_cb; }; /* @@ -178,9 +188,10 @@ static void exynos_set_safe_div(void __iomem *base, unsigned long div, /* handler for pre-rate change notification from parent clock */ static int exynos_cpuclk_pre_rate_change(struct clk_notifier_data *ndata, - struct exynos_cpuclk *cpuclk, void __iomem *base) + struct exynos_cpuclk *cpuclk) { const struct exynos_cpuclk_cfg_data *cfg_data = cpuclk->cfg; + void __iomem *base = cpuclk->ctrl_base; unsigned long alt_prate = clk_hw_get_rate(cpuclk->alt_parent); unsigned long div0, div1 = 0, mux_reg; unsigned long flags; @@ -255,9 +266,10 @@ static int exynos_cpuclk_pre_rate_change(struct clk_notifier_data *ndata, /* handler for post-rate change notification from parent clock */ static int exynos_cpuclk_post_rate_change(struct clk_notifier_data *ndata, - struct exynos_cpuclk *cpuclk, void __iomem *base) + struct exynos_cpuclk *cpuclk) { const struct exynos_cpuclk_cfg_data *cfg_data = cpuclk->cfg; + void __iomem *base = cpuclk->ctrl_base; unsigned long div = 0, div_mask = DIV_MASK; unsigned long mux_reg; unsigned long flags; @@ -306,9 +318,10 @@ static void exynos5433_set_safe_div(void __iomem *base, unsigned long div, /* handler for pre-rate change notification from parent clock */ static int exynos5433_cpuclk_pre_rate_change(struct clk_notifier_data *ndata, - struct exynos_cpuclk *cpuclk, void __iomem *base) + struct exynos_cpuclk *cpuclk) { const struct exynos_cpuclk_cfg_data *cfg_data = cpuclk->cfg; + void __iomem *base = cpuclk->ctrl_base; unsigned long alt_prate = clk_hw_get_rate(cpuclk->alt_parent); unsigned long div0, div1 = 0, mux_reg; unsigned long flags; @@ -366,8 +379,9 @@ static int exynos5433_cpuclk_pre_rate_change(struct clk_notifier_data *ndata, /* handler for post-rate change notification from parent clock */ static int exynos5433_cpuclk_post_rate_change(struct clk_notifier_data *ndata, - struct exynos_cpuclk *cpuclk, void __iomem *base) + struct exynos_cpuclk *cpuclk) { + void __iomem *base = cpuclk->ctrl_base; unsigned long div = 0, div_mask = DIV_MASK; unsigned long mux_reg; unsigned long flags; @@ -393,39 +407,14 @@ static int exynos_cpuclk_notifier_cb(struct notifier_block *nb, { struct clk_notifier_data *ndata = data; struct exynos_cpuclk *cpuclk; - void __iomem *base; int err = 0; cpuclk = container_of(nb, struct exynos_cpuclk, clk_nb); - base = cpuclk->ctrl_base; if (event == PRE_RATE_CHANGE) - err = exynos_cpuclk_pre_rate_change(ndata, cpuclk, base); + err = cpuclk->pre_rate_cb(ndata, cpuclk); else if (event == POST_RATE_CHANGE) - err = exynos_cpuclk_post_rate_change(ndata, cpuclk, base); - - return notifier_from_errno(err); -} - -/* - * This notifier function is called for the pre-rate and post-rate change - * notifications of the parent clock of cpuclk. - */ -static int exynos5433_cpuclk_notifier_cb(struct notifier_block *nb, - unsigned long event, void *data) -{ - struct clk_notifier_data *ndata = data; - struct exynos_cpuclk *cpuclk; - void __iomem *base; - int err = 0; - - cpuclk = container_of(nb, struct exynos_cpuclk, clk_nb); - base = cpuclk->ctrl_base; - - if (event == PRE_RATE_CHANGE) - err = exynos5433_cpuclk_pre_rate_change(ndata, cpuclk, base); - else if (event == POST_RATE_CHANGE) - err = exynos5433_cpuclk_post_rate_change(ndata, cpuclk, base); + err = cpuclk->post_rate_cb(ndata, cpuclk); return notifier_from_errno(err); } @@ -467,10 +456,14 @@ static int __init exynos_register_cpu_clock(struct samsung_clk_provider *ctx, cpuclk->ctrl_base = ctx->reg_base + clk_data->offset; cpuclk->lock = &ctx->lock; cpuclk->flags = clk_data->flags; - if (clk_data->flags & CLK_CPU_HAS_E5433_REGS_LAYOUT) - cpuclk->clk_nb.notifier_call = exynos5433_cpuclk_notifier_cb; - else - cpuclk->clk_nb.notifier_call = exynos_cpuclk_notifier_cb; + cpuclk->clk_nb.notifier_call = exynos_cpuclk_notifier_cb; + if (clk_data->flags & CLK_CPU_HAS_E5433_REGS_LAYOUT) { + cpuclk->pre_rate_cb = exynos5433_cpuclk_pre_rate_change; + cpuclk->post_rate_cb = exynos5433_cpuclk_post_rate_change; + } else { + cpuclk->pre_rate_cb = exynos_cpuclk_pre_rate_change; + cpuclk->post_rate_cb = exynos_cpuclk_post_rate_change; + } ret = clk_notifier_register(parent->clk, &cpuclk->clk_nb); if (ret) {