From patchwork Thu Feb 22 03:02:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 204533 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp505dyb; Wed, 21 Feb 2024 19:04:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWKL3ZkmJuvGYumRJ3RclC1VuzerDWmmEcg23LrCvHbe5BYdWzWM9YxYibPt7/0JMNTB3J94AA2ZonqXpD2krMtZfJWdw== X-Google-Smtp-Source: AGHT+IF2FhzXC3tGdw4K+jhxFPXR3n0KGeLpRGebrA2H1LOs7LYWEFbMuuExq4vKZ9ZsLB0EvWRD X-Received: by 2002:aa7:90c6:0:b0:6e1:44ec:8e9e with SMTP id k6-20020aa790c6000000b006e144ec8e9emr13529514pfk.21.1708571078647; Wed, 21 Feb 2024 19:04:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708571078; cv=pass; d=google.com; s=arc-20160816; b=bC7zTWohybEaBAyM1k762rt67kwARMDG2OBT8ywx1o5s8h70VzEcfwudxBi3PwMFU9 FX3nFO1D3kDyLpBdimfL0t4JLkhciB3e/cbb/ASqXexkXzr/Zg1PsS53mifK/+u3ks5/ UgTrLScggtuXFCioeUJHbjbHxrsmXhEtgeWi9ojoZpfom/859mazyG4berEnVzr2W/XG WP934advy07zXcTH7lGDfX8PXe++GITY6UorqRbDyJQgqBX6akxfiT37jjgDei8rZ831 juhMVsUzDi/B41x69jGjuBCy9fnOcnjmiJ8pNTMAZUEpX/Q+J+j02BtEPwKQvh/WJytM VJ6A== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75820-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o5-20020a635a05000000b005cecbe69c23si9478026pgb.43.2024.02.21.19.04.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 19:04:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75820-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75820-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 6377828454B for ; Thu, 22 Feb 2024 03:04:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91AA32421F; Thu, 22 Feb 2024 03:02:50 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791566626840488964 X-GMAIL-MSGID: 1791566626840488964 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) {