From patchwork Sat Feb 24 20:20:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 13570583 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 66469C54E49 for ; Sat, 24 Feb 2024 20:21:33 +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:References:In-Reply-To: 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: List-Owner; bh=OcXxnmIlz7q+EMANtsMsY0JTl3yjds+dWUup4GBmOMI=; b=gVDsnOXzrsMb33 TQJsHU0vwo9qjvu1+2oU2zAXd8CeqG7NsYYRrJ76peCOl534Nzun42mI1clspat9xSYKtaK0ZSZuQ IkxKC7enXiYZi6W7/tSqEL1msoZ+6ULY7unEgmBQqIZB9fiyfDxVr+lGEdaejeuZ71QUHgl8Kr62K Q4iqhilMJinF8+iKJHOR0E5/7pJSOvLKqitzb9Z6T4PZUPsjWBTE7KbaYa4cB9uLyUzlGLj0SSH69 AXWku9Am3DupDuM2JqxX2LaEED2K/XDDN5E+d7iFLPkUybqMK591Kn4RdWnW0aJXf+1hMlNNyqwNo lYfxFCXidPjnxxFLwZQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rdyWN-0000000DaZg-0oh4; Sat, 24 Feb 2024 20:21:19 +0000 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rdyW6-0000000DaPz-1qZc for linux-arm-kernel@lists.infradead.org; Sat, 24 Feb 2024 20:21:04 +0000 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-3c02adddb8eso1512799b6e.0 for ; Sat, 24 Feb 2024 12:21:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708806061; x=1709410861; darn=lists.infradead.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=S7KoDUleWCo5UKlQBGeeXR+YMlhweLkGTgyZVq03PTg=; b=eszohKSPapVqQ1NCR+yPNz7PrEvzY+PMFzzRHcqhnWb/0QvSWK2J//kgeUpQ3j6Cfv tNBF+Pj3tDzvxSQI7fnfi24G7AOJmqVgNK10ry9FYC7mGAUW5yFwBjCWKxzWVgNIWXZF 022YaljqU43MSZapkYk+urkPBGU0yJKKG3fe8wUMpobKbO2bbKkm6yOu/gBLnEblvGkb R7GUrGVUOkoxoCc6qt/zO7KctwvxdC+hhKBjvI1OZmcAIa3i20czv2Pa+U+7B07LCp/g w91GEmEJofNlD5IySeIKdadfrz6TTIBFoas8JIzZiVmdgf6M1AeONffT4qU9iuBI9TxV lWWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708806061; x=1709410861; 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=S7KoDUleWCo5UKlQBGeeXR+YMlhweLkGTgyZVq03PTg=; b=krYLTRXjB7qILWAve7bi0cJOprf9qWllCbu7cJeFw/wGB7/C5m13wnEoLZTDvipUrE eKvvPx+SVheIeNTxio5/9s6TpoUdrmD+80MoxzdCXp3GHTUWY8jPldg5MwTmp3TL2Dad JaBFxfnXu/tMoWgnbg75O1ddnfbaXyl0ERDy7jJ76DEkrm951IwCpUIrYRZO3ex0Df+C 0o58fxnVTtN6vYQKXej+eIxSGLYhLmskj2qVuzLSRIg6ftOLUypAACZQ8UGPs0RhlqO6 491IYufNiiAktsqpcT9FrmBGRwTZqLy6am/LV1zgh9mKVFGpj0qhj5N4lwIkNmPAdSkb Pp3w== X-Forwarded-Encrypted: i=1; AJvYcCX8mblg7NN4TMxO8gRoWa+TQCTz0jseZuxUAs65Jx7glncVPGNEDSB9QXatQ5NMbpgPyHUArQIHAfNkHC3rG1MhI4PKdBNaxDc2jvtMgDvxhvXNDkg= X-Gm-Message-State: AOJu0YzSSFIv63z+p9NaJj69Z+IRD8R4HDabhZHhUXOgwSUPunIgRmPB eR1fCCFVDq2T9UBpKWjR3CINqqgGQvJHgAe1fbAiikHkMfB6lmRU1F1TLZ2jp1Q= X-Google-Smtp-Source: AGHT+IENaAaBEvjJseobNlvF+eiZDk+l+seaHD0oo3sk7o+f/hO5ZUaGaS5Q1MrGsUHlW0icJeudIw== X-Received: by 2002:a05:6808:f88:b0:3c1:9c5b:74a7 with SMTP id o8-20020a0568080f8800b003c19c5b74a7mr119158oiw.17.1708806061101; Sat, 24 Feb 2024 12:21:01 -0800 (PST) Received: from localhost ([136.62.192.75]) by smtp.gmail.com with ESMTPSA id 22-20020aca0916000000b003c150705429sm382420oij.12.2024.02.24.12.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 12:21:00 -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 v3 09/15] clk: samsung: Keep CPU clock chip specific data in a dedicated struct Date: Sat, 24 Feb 2024 14:20:47 -0600 Message-Id: <20240224202053.25313-10-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240224202053.25313-1-semen.protsenko@linaro.org> References: <20240224202053.25313-1-semen.protsenko@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240224_122102_676543_289515B3 X-CRM114-Status: GOOD ( 19.41 ) 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 Keep chip specific data in the data structure, don't mix it with code. It makes it easier to add more chip specific data further. Having all chip specific data in the table eliminates possible code bloat when adding more rate handlers for new chips, and also makes it possible to keep some other chip related data in that array. No functional change. Signed-off-by: Sam Protsenko --- Changes in v3: - none Changes in v2: - Improved the commit message: explained why it's beneficial for new chips to keep chip-specific data in one table drivers/clk/samsung/clk-cpu.c | 40 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/drivers/clk/samsung/clk-cpu.c b/drivers/clk/samsung/clk-cpu.c index 635ab8cc54a2..eb2b67d08f89 100644 --- a/drivers/clk/samsung/clk-cpu.c +++ b/drivers/clk/samsung/clk-cpu.c @@ -43,6 +43,16 @@ struct exynos_cpuclk; typedef int (*exynos_rate_change_fn_t)(struct clk_notifier_data *ndata, struct exynos_cpuclk *cpuclk); +/** + * struct exynos_cpuclk_chip - Chip specific data for CPU clock + * @pre_rate_cb: callback to run before CPU clock rate change + * @post_rate_cb: callback to run after CPU clock rate change + */ +struct exynos_cpuclk_chip { + exynos_rate_change_fn_t pre_rate_cb; + exynos_rate_change_fn_t post_rate_cb; +}; + /** * struct exynos_cpuclk - information about clock supplied to a CPU core * @hw: handle between CCF and CPU clock @@ -55,8 +65,7 @@ typedef int (*exynos_rate_change_fn_t)(struct clk_notifier_data *ndata, * @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 + * @chip: chip-specific data for the CPU clock * * This structure holds information required for programming the CPU clock for * various clock speeds. @@ -70,9 +79,7 @@ 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; + const struct exynos_cpuclk_chip *chip; }; /* ---- Common code --------------------------------------------------------- */ @@ -420,13 +427,24 @@ static int exynos_cpuclk_notifier_cb(struct notifier_block *nb, cpuclk = container_of(nb, struct exynos_cpuclk, clk_nb); if (event == PRE_RATE_CHANGE) - err = cpuclk->pre_rate_cb(ndata, cpuclk); + err = cpuclk->chip->pre_rate_cb(ndata, cpuclk); else if (event == POST_RATE_CHANGE) - err = cpuclk->post_rate_cb(ndata, cpuclk); + err = cpuclk->chip->post_rate_cb(ndata, cpuclk); return notifier_from_errno(err); } +static const struct exynos_cpuclk_chip exynos_clkcpu_chips[] = { + [CPUCLK_LAYOUT_E4210] = { + .pre_rate_cb = exynos_cpuclk_pre_rate_change, + .post_rate_cb = exynos_cpuclk_post_rate_change, + }, + [CPUCLK_LAYOUT_E5433] = { + .pre_rate_cb = exynos5433_cpuclk_pre_rate_change, + .post_rate_cb = exynos5433_cpuclk_post_rate_change, + }, +}; + /* helper function to register a CPU clock */ static int __init exynos_register_cpu_clock(struct samsung_clk_provider *ctx, const struct samsung_cpu_clock *clk_data) @@ -465,13 +483,7 @@ static int __init exynos_register_cpu_clock(struct samsung_clk_provider *ctx, cpuclk->lock = &ctx->lock; cpuclk->flags = clk_data->flags; cpuclk->clk_nb.notifier_call = exynos_cpuclk_notifier_cb; - if (clk_data->reg_layout == CPUCLK_LAYOUT_E5433) { - 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; - } + cpuclk->chip = &exynos_clkcpu_chips[clk_data->reg_layout]; ret = clk_notifier_register(parent->clk, &cpuclk->clk_nb); if (ret) {