Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp96433rdb; Wed, 21 Feb 2024 19:03:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV7tB1zR8TU6gbGYOxuEivVH7cjskyWuLeahf6JODTC0HV83bxs6r7Ma/uOArJYH01OBb/KqQAtZnS2ZtrBSrM/5Y4tWP0s8guwepgw5g== X-Google-Smtp-Source: AGHT+IFMhT3WKmpm7psFDhlnVKp1Q+MEgm9+aWbGccSUo3p5l8AVCO9ENve8gelCILRwtoNEqDcM X-Received: by 2002:a17:906:702:b0:a3d:482f:3fc4 with SMTP id y2-20020a170906070200b00a3d482f3fc4mr13110689ejb.70.1708571028002; Wed, 21 Feb 2024 19:03:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708571027; cv=pass; d=google.com; s=arc-20160816; b=ny2Y510S3gJ9hChLe7YDn61q4AsxOxTh0+R9nLyB1Vyq0bz7MbKMxIZrEo0aqlRYUB qV5JDQ06Tp2UdlqW6Ja5+z2oiiOMBkpLleCFsQ/PfhfgH2HWJe+nDAn/mOO8vqfzA3xB ayWSwvtirT4JBiSJmF69ygGCM9iQpnrQ5ZNeJiC/VmgH80cpBC+P+0FHsLiAaQbocekL VAKj4bTYpfgWUkG3kdVlHaVOKkB6Nd0sOzA75XnmsA+eiamBlwNPG9yWaXqfmNjPTiq0 ec5haeZ3ZV8+eyB8UBFnU4jB9MLF31xSu4pGtpTB4Y1g9qVyZxReqh2nS8wV9bBeWIum tfqQ== 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=jx74Vmc3ML2VKaMboMxLRhlCDqHuQQbgCrU7etXbl0w=; fh=ckbZAtkgqksM5JRY1OJtA1yPt75Jqb9334fSo5pJOxk=; b=oZp3ZGFNd385C98mXfomq2KNd4/LqosW28SKlTl8IOIQuPh697HFkbhIqjERofxde2 XWw//RLCB6a0MhgXohmbwJEwW07V5ez2HXr8lVKF5WS/D5oB04qAUY+YAzmrasF+Jb2P F8kB/UmvD/cGcw//bjzI8q5+Ps/+Wo1/Yu3wjWRphEi/T6hQwEVSMOxwX2++UIlni4ip 6/umVb8707WRVUkxgw1mBH8f++JBp0dg+dlXIfBVpQ1zhQqSVA/GU/Xgji/cHjrk7Xrh qKtvGsmyH0jcy0QqzPryHFhmFlPcgrBloREtc9G46Mn8k70P8v1c8QbqEIcZKAdcowaS /HNA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hfg3ig04; 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-75820-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75820-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dt6-20020a170906b78600b00a3e461d3e4dsi3958333ejb.979.2024.02.21.19.03.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 19:03:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75820-linux.lists.archive=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=Hfg3ig04; 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-75820-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75820-linux.lists.archive=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 95C361F2348D for ; Thu, 22 Feb 2024 03:03:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3876220313; Thu, 22 Feb 2024 03:02:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Hfg3ig04" Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (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 3034E1775B for ; Thu, 22 Feb 2024 03:02:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708570963; cv=none; b=qkYiBoGV83D5HO5qzjiEsWrpzQPoutmZrIRsdIb3r8Ft7ZqS6LvZCaK1cNN3a5nCh0SOgDv36fO2epEQejQGOTSKzXPVPq+f1N9aEstcGlKZo3LK9WjzOnYOMbyEjC3DpT9SQLI3gul+ZIe88WGDFBIo5lhHkuUm0+c8YlXbxqs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708570963; c=relaxed/simple; bh=ZeQpNOZaOFhBj3Qo7EtzgtgWzlTZFZ59RF36ZOVeZuA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gQUlfCdcarVwA5Op9dBK5QuG3U15jR3aG5/c4XOCUaq7z0YDyYk+cgXb3hd75SPd030JEJC9uX272b4Em8ZDNBl84eQN1saMNXclxbp7NOSEN8yWfD958HOBklY7VB+fxzTcH1yTCao86f0ljJlcDoEFevUbzAQB2oc2IdU9YWY= 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=Hfg3ig04; arc=none smtp.client-ip=209.85.167.176 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-f176.google.com with SMTP id 5614622812f47-3c15d67b83cso1560944b6e.0 for ; Wed, 21 Feb 2024 19:02:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708570960; x=1709175760; 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=jx74Vmc3ML2VKaMboMxLRhlCDqHuQQbgCrU7etXbl0w=; b=Hfg3ig04CVMIEq0PLfbQAGYQ30I3UeloBA3AiBLRMGvyRrdNq7BcJpQ/Z2dDp+A3hp AR23rf7DMdeSgKRJYBWSOONL7qddexiNyS+eZPtZjezJ85bvPKkkr8dAmPBRCSCmApJs udfKYcdCfyIX9HtbsWiyGJkqtCIwQSyFjfRPgJqZl4SN4WAyknefIpdkczgH7myecVnK zoGP9+8l75luSIY3nIeiqzSOWBTolNiGAvAN89a13cK5c1fUQfoYQ3HR+yC/2Yzr8YXR M7WZAjiVFWxYXZRZg04gcj2ZXddxDR2sRyivRdkGG+tNvfr6AaZUsgmWDu9yZ4uQ53o9 EQyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708570960; x=1709175760; 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=jx74Vmc3ML2VKaMboMxLRhlCDqHuQQbgCrU7etXbl0w=; b=nYkvio+cnOkDh/0KnK4hCJ1wAR5wIzyhtt7REmpnofQREkskyE3hdz4yesZhp14qTe QUfsBRmuz9HBRHcBX+IzeP53JCKl4zQ598BA1mrFgH0tx2ko4FsCVSLq9I2A5LJaX/bn AtCAnBmAsYq9HcST8t//MfFMehF0YH0WkU7vpGMVoHI1+2vQ+ysAXLYM4kBG6n2sLLT+ 4w2YBKzs7TfD1Hh8PCqadfAxBLdOOYF/TXLPB5AaJY7PfQJ2DDloSDq/MSCO/W06sgAa udWTkdLyrxLrIaDh22RyT/fEGk8XFuE9jpcxBVltD5NdhJGtfuXaj7m69/0S+0Mrbh20 jt3w== X-Forwarded-Encrypted: i=1; AJvYcCUnCYhnDCbqC7NQTd3GY6i8dmcxizIAN+m6HRonp3iRbL5QD38jk/Nj6mg87j3MRcSpdhEdl3wW2frqa+As0my8XMh+EwnZLQlMfp6C X-Gm-Message-State: AOJu0YzbXXs9rCD+5QTa4brOKduUOjFBkMsFvtJ/P3xwOludfl/hJr2/ 2iqUCVaZNJB4o9VgF66M+moTDSEiABAyeBr/HKcSneRQhBIbtCbCHhT5J/6YVlnlD58/T1ert8O f X-Received: by 2002:a05:6808:3c4d:b0:3c1:783e:7825 with SMTP id gl13-20020a0568083c4d00b003c1783e7825mr1058478oib.33.1708570960250; Wed, 21 Feb 2024 19:02:40 -0800 (PST) Received: from localhost ([136.62.192.75]) by smtp.gmail.com with ESMTPSA id u19-20020a056808001300b003c14520c78csm1794602oic.54.2024.02.21.19.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 19:02:39 -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 v2 05/15] clk: samsung: Use single CPU clock notifier callback for all chips Date: Wed, 21 Feb 2024 21:02:25 -0600 Message-Id: <20240222030235.27815-6-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240222030235.27815-1-semen.protsenko@linaro.org> References: <20240222030235.27815-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 Content-Transfer-Encoding: 8bit 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 --- Changes in v2: - none 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) { -- 2.39.2