From patchwork Wed Oct 21 16:38:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 11849445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B073C55179 for ; Wed, 21 Oct 2020 16:38:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9CD321D7B for ; Wed, 21 Oct 2020 16:38:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="GEMLmHMc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503037AbgJUQi6 (ORCPT ); Wed, 21 Oct 2020 12:38:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503029AbgJUQi4 (ORCPT ); Wed, 21 Oct 2020 12:38:56 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD9D1C0613CE for ; Wed, 21 Oct 2020 09:38:54 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id dn5so3199734edb.10 for ; Wed, 21 Oct 2020 09:38:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ohk60Lc9axvVM7bujOFXofpFFhnugPw9JS+9Z6gwq/w=; b=GEMLmHMccDitjDiVntpcbZF4/ew82oBOAS/eJriDByqKp2mIvoV8csZuJ7ElVfET9c PcaD8VqWlzbIRSW7GeMKFmipRdrjfP9P5SkTvHYbvBqJNuLrh/fpgiCp6PuNPthlU6qb K+GSVliaw3BAKJrjsM8UPy1GTY3Ja1KGuxWg4+ir3SE6hlUH7Y3OUV7O0Rnyqdws/kU0 vtjpHpbFYF9HcXDDD2n7+hrmmu3KE3i+LFQYFw3hae/6G7U3Md+xFv+3afEd1aBsC77v eL7fL6EIdwgZ6qg/5wHkXPLJhFsaXsxBUWI5rkrZTGJZYGy2N2izaxPvYtDFKUEVeKjs gc4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ohk60Lc9axvVM7bujOFXofpFFhnugPw9JS+9Z6gwq/w=; b=K7ef0yuU2aFJiqhxPyWHeCCta9Wq9fgHHgmEOQCMdVzyyGfZUwuFqEK80HGKsWsrOu 44G0Ao6w3Mjmqw+yhla+8lRKj6xXf3E8RFMffe90fb2NkHNE2HksiCHf4KOyoRROzqSM Zw/FR1OoXtYJLD3d1VugmYHXIHfkVXC6Hg7VUUGwkiQlcNP3hxN/yAOxSbqpzjvFIQP8 PMKZ2ncm0wDCBV20LyctT1oFZaQ6Zw9mdnWpGvc1REdgxFq0+7I6enLZjWiaxocCwLnx H/o8Tb+hX2dOztZE7+bAmGKgEfui+OutNor0fLe1QrAMob3L7II9evEBVBnlNPZ20DbL /8mA== X-Gm-Message-State: AOAM532sARrZC0IEVe1/CrSIr1+nPgpaAtH86mruMt8qUAjRgJFX/Djh mhquofS52ZOOjj5lgqndb9Ayu67PJCElQg== X-Google-Smtp-Source: ABdhPJz/xI5mua9UlK4b08PjCq49mDh1kU1oEbpF6dQ0ewYrgkI8rTu2uFdxP/IyjaR8K1h8hzrHCA== X-Received: by 2002:a05:6402:22e3:: with SMTP id dn3mr2970696edb.205.1603298333562; Wed, 21 Oct 2020 09:38:53 -0700 (PDT) Received: from starbuck.lan (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id f26sm2549747ejx.23.2020.10.21.09.38.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 09:38:53 -0700 (PDT) From: Jerome Brunet To: Stephen Boyd Cc: Jerome Brunet , Russell King , linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Kevin Hilman Subject: [PATCH 1/2] clk: add devm variant of clk_notifier_register Date: Wed, 21 Oct 2020 18:38:46 +0200 Message-Id: <20201021163847.595189-2-jbrunet@baylibre.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20201021163847.595189-1-jbrunet@baylibre.com> References: <20201021163847.595189-1-jbrunet@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Add a memory managed variant of clk_notifier_register() to make life easier on clock consumers using notifiers Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/clk.h | 10 ++++++++++ 2 files changed, 46 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index d27153f26fa9..e9fdd1d9b3f5 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -4395,6 +4395,42 @@ int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb) } EXPORT_SYMBOL_GPL(clk_notifier_unregister); +struct clk_notifier_devres { + struct clk *clk; + struct notifier_block *nb; +}; + +static void devm_clk_notifier_release(struct device *dev, void *res) +{ + struct clk_notifier_devres *devres = res; + + clk_notifier_unregister(devres->clk, devres->nb); +} + +int devm_clk_notifier_register(struct device *dev, struct clk *clk, + struct notifier_block *nb) +{ + struct clk_notifier_devres *devres; + int ret; + + devres = devres_alloc(devm_clk_notifier_release, + sizeof(*devres), GFP_KERNEL); + + if (!devres) + return -ENOMEM; + + ret = clk_notifier_register(clk, nb); + if (!ret) { + devres->clk = clk; + devres->nb = nb; + } else { + devres_free(devres); + } + + return ret; +} +EXPORT_SYMBOL_GPL(devm_clk_notifier_register); + #ifdef CONFIG_OF static void clk_core_reparent_orphans(void) { diff --git a/include/linux/clk.h b/include/linux/clk.h index 7fd6a1febcf4..79fb52f93053 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -109,6 +109,16 @@ int clk_notifier_register(struct clk *clk, struct notifier_block *nb); */ int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb); +/** + * devm_clk_notifier_register: register a managed rate-change notifier callback + * @dev: device for clock "consumer" + * @clk: clock whose rate we are interested in + * @nb: notifier block with callback function pointer + * + * Returns 0 on success, -EERROR otherwise + */ +int devm_clk_notifier_register(struct device *dev, struct clk *clk, struct notifier_block *nb); + /** * clk_get_accuracy - obtain the clock accuracy in ppb (parts per billion) * for a clock source. From patchwork Wed Oct 21 16:38:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 11849447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF10FC5DF9E for ; Wed, 21 Oct 2020 16:39:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5EEBF21D7B for ; Wed, 21 Oct 2020 16:39:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="lPxbJARn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2409018AbgJUQi5 (ORCPT ); Wed, 21 Oct 2020 12:38:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503031AbgJUQi4 (ORCPT ); Wed, 21 Oct 2020 12:38:56 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06E1AC0613D2 for ; Wed, 21 Oct 2020 09:38:56 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id t25so4124933ejd.13 for ; Wed, 21 Oct 2020 09:38:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4bmUTvMmlGLQ9tv2GMEVx5tSGz9QfWz+dgoSRCgpsLM=; b=lPxbJARnZj8JhrahTb3CjQMfx4CZRZOYvvm8mjwTYwa8kdX0yMwbt7TCZZYwkXfp6d 4uBWD01DtroiklOaL04FsnIhXq4U0IbcH3ijPSWYpFKzVXi12Lhkd9zjFHa6ED8pLTPR 1NENAgPG0doUEG1O3YMt7Zs2Lp1qruYCDiwG8Gq1E4r0cy9SsKTjud5/ALTHjvmhe7Eb PB2EK9lVlIcQBRYJLyqBdXf6AeRZVc794I1sMVm5D1kY8amgYLr9VIMe1kDGRgucd+tD jt3dHTd0k5W1YObSv6pV2AOK2KKBTXZ0ClPwkJ4AMOaGrLUaGrXlRgqrccLQec9IXSNg k0Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4bmUTvMmlGLQ9tv2GMEVx5tSGz9QfWz+dgoSRCgpsLM=; b=oUGS8G2aUXTudAOCjRM6Eyxb0V9FOgF3QXYPAx4u4bzf3CmKN1v54ScYFxV51IhYEH /693a4oKE1QB1vu4KEATWNWmwOrPyjJEI4w+JpwqUS4ahjCIDer+9blR10bbyjlxQfrK C8IZbNU5fQbAYce6e4k9/RdynMbx0ipeW/bkPsosOTBBEIDL+7R6p6oyKBiR/t3RjSnk VGIbKT14+ayZYHHxgP3m+n4DxqXEPUrK57pgGrLskmdh2mOcDRjzlBS7/FusOtpmAzXS UReCwnWHZtXOR3lt4bV4V89vKVvlODWEmXcKig3lkchnNWYJ4L5qlVr23Iu6mO3IBYVB mxRg== X-Gm-Message-State: AOAM5318t0gf/PSgHmFiaYaZVnVX6MyyMmJfDEFLQCnwjaS0HZFiaRp/ cXjfpeEa+rKke/CpsI90vjqYqw== X-Google-Smtp-Source: ABdhPJziCr8SmylxJQYZgyuvCkU84PCcMSnmPqhvy6/7Z6BFqIqIijfs88QhRpuWwaRtfMv4imMi6A== X-Received: by 2002:a17:906:5594:: with SMTP id y20mr3928287ejp.196.1603298334729; Wed, 21 Oct 2020 09:38:54 -0700 (PDT) Received: from starbuck.lan (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id f26sm2549747ejx.23.2020.10.21.09.38.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 09:38:54 -0700 (PDT) From: Jerome Brunet To: Stephen Boyd Cc: Jerome Brunet , linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Kevin Hilman Subject: [PATCH 2/2] clk: meson: g12: use devm variant to register notifiers Date: Wed, 21 Oct 2020 18:38:47 +0200 Message-Id: <20201021163847.595189-3-jbrunet@baylibre.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20201021163847.595189-1-jbrunet@baylibre.com> References: <20201021163847.595189-1-jbrunet@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Until now, nothing was done to unregister the dvfs clock notifiers of the Amlogic g12 SoC family. This is not great but this driver was not really expected to be unloaded. With the ongoing effort to build everything as module for this platform, this needs to be cleanly handled. Signed-off-by: Jerome Brunet --- This clean application of this patch depends on https://lore.kernel.org/r/20201021162147.563655-4-jbrunet@baylibre.com drivers/clk/meson/g12a.c | 34 ++++++++++++++++++++-------------- include/linux/clk.h | 10 +++++++++- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/drivers/clk/meson/g12a.c b/drivers/clk/meson/g12a.c index bbb75541dad9..bb4fa19442be 100644 --- a/drivers/clk/meson/g12a.c +++ b/drivers/clk/meson/g12a.c @@ -5171,8 +5171,8 @@ static int meson_g12a_dvfs_setup_common(struct device *dev, g12a_cpu_clk_postmux0_nb_data.xtal = xtal; notifier_clk = devm_clk_hw_get_clk(dev, &g12a_cpu_clk_postmux0.hw, DVFS_CON_ID); - ret = clk_notifier_register(notifier_clk, - &g12a_cpu_clk_postmux0_nb_data.nb); + ret = devm_clk_notifier_register(dev, notifier_clk, + &g12a_cpu_clk_postmux0_nb_data.nb); if (ret) { dev_err(dev, "failed to register the cpu_clk_postmux0 notifier\n"); return ret; @@ -5181,7 +5181,8 @@ static int meson_g12a_dvfs_setup_common(struct device *dev, /* Setup clock notifier for cpu_clk_dyn mux */ notifier_clk = devm_clk_hw_get_clk(dev, &g12a_cpu_clk_dyn.hw, DVFS_CON_ID); - ret = clk_notifier_register(notifier_clk, &g12a_cpu_clk_mux_nb); + ret = devm_clk_notifier_register(dev, notifier_clk, + &g12a_cpu_clk_mux_nb); if (ret) { dev_err(dev, "failed to register the cpu_clk_dyn notifier\n"); return ret; @@ -5207,7 +5208,8 @@ static int meson_g12b_dvfs_setup(struct platform_device *pdev) /* Setup clock notifier for cpu_clk mux */ notifier_clk = devm_clk_hw_get_clk(dev, &g12b_cpu_clk.hw, DVFS_CON_ID); - ret = clk_notifier_register(notifier_clk, &g12a_cpu_clk_mux_nb); + ret = devm_clk_notifier_register(dev, notifier_clk, + &g12a_cpu_clk_mux_nb); if (ret) { dev_err(dev, "failed to register the cpu_clk notifier\n"); return ret; @@ -5216,8 +5218,8 @@ static int meson_g12b_dvfs_setup(struct platform_device *pdev) /* Setup clock notifier for sys1_pll */ notifier_clk = devm_clk_hw_get_clk(dev, &g12b_sys1_pll.hw, DVFS_CON_ID); - ret = clk_notifier_register(notifier_clk, - &g12b_cpu_clk_sys1_pll_nb_data.nb); + ret = devm_clk_notifier_register(dev, notifier_clk, + &g12b_cpu_clk_sys1_pll_nb_data.nb); if (ret) { dev_err(dev, "failed to register the sys1_pll notifier\n"); return ret; @@ -5229,8 +5231,8 @@ static int meson_g12b_dvfs_setup(struct platform_device *pdev) g12b_cpub_clk_postmux0_nb_data.xtal = xtal; notifier_clk = devm_clk_hw_get_clk(dev, &g12b_cpub_clk_postmux0.hw, DVFS_CON_ID); - ret = clk_notifier_register(notifier_clk, - &g12b_cpub_clk_postmux0_nb_data.nb); + ret = devm_clk_notifier_register(dev, notifier_clk, + &g12b_cpub_clk_postmux0_nb_data.nb); if (ret) { dev_err(dev, "failed to register the cpub_clk_postmux0 notifier\n"); return ret; @@ -5238,7 +5240,8 @@ static int meson_g12b_dvfs_setup(struct platform_device *pdev) /* Setup clock notifier for cpub_clk_dyn mux */ notifier_clk = devm_clk_hw_get_clk(dev, &g12b_cpub_clk_dyn.hw, "dvfs"); - ret = clk_notifier_register(notifier_clk, &g12a_cpu_clk_mux_nb); + ret = devm_clk_notifier_register(dev, notifier_clk, + &g12a_cpu_clk_mux_nb); if (ret) { dev_err(dev, "failed to register the cpub_clk_dyn notifier\n"); return ret; @@ -5246,7 +5249,8 @@ static int meson_g12b_dvfs_setup(struct platform_device *pdev) /* Setup clock notifier for cpub_clk mux */ notifier_clk = devm_clk_hw_get_clk(dev, &g12b_cpub_clk.hw, DVFS_CON_ID); - ret = clk_notifier_register(notifier_clk, &g12a_cpu_clk_mux_nb); + ret = devm_clk_notifier_register(dev, notifier_clk, + &g12a_cpu_clk_mux_nb); if (ret) { dev_err(dev, "failed to register the cpub_clk notifier\n"); return ret; @@ -5254,8 +5258,8 @@ static int meson_g12b_dvfs_setup(struct platform_device *pdev) /* Setup clock notifier for sys_pll */ notifier_clk = devm_clk_hw_get_clk(dev, &g12a_sys_pll.hw, DVFS_CON_ID); - ret = clk_notifier_register(notifier_clk, - &g12b_cpub_clk_sys_pll_nb_data.nb); + ret = devm_clk_notifier_register(dev, notifier_clk, + &g12b_cpub_clk_sys_pll_nb_data.nb); if (ret) { dev_err(dev, "failed to register the sys_pll notifier\n"); return ret; @@ -5277,7 +5281,8 @@ static int meson_g12a_dvfs_setup(struct platform_device *pdev) /* Setup clock notifier for cpu_clk mux */ notifier_clk = devm_clk_hw_get_clk(dev, &g12a_cpu_clk.hw, DVFS_CON_ID); - ret = clk_notifier_register(notifier_clk, &g12a_cpu_clk_mux_nb); + ret = devm_clk_notifier_register(dev, notifier_clk, + &g12a_cpu_clk_mux_nb); if (ret) { dev_err(dev, "failed to register the cpu_clk notifier\n"); return ret; @@ -5285,7 +5290,8 @@ static int meson_g12a_dvfs_setup(struct platform_device *pdev) /* Setup clock notifier for sys_pll */ notifier_clk = devm_clk_hw_get_clk(dev, &g12a_sys_pll.hw, DVFS_CON_ID); - ret = clk_notifier_register(notifier_clk, &g12a_sys_pll_nb_data.nb); + ret = devm_clk_notifier_register(dev, notifier_clk, + &g12a_sys_pll_nb_data.nb); if (ret) { dev_err(dev, "failed to register the sys_pll notifier\n"); return ret; diff --git a/include/linux/clk.h b/include/linux/clk.h index 79fb52f93053..db113495d315 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -117,7 +117,8 @@ int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb); * * Returns 0 on success, -EERROR otherwise */ -int devm_clk_notifier_register(struct device *dev, struct clk *clk, struct notifier_block *nb); +int devm_clk_notifier_register(struct device *dev, struct clk *clk, + struct notifier_block *nb); /** * clk_get_accuracy - obtain the clock accuracy in ppb (parts per billion) @@ -196,6 +197,13 @@ static inline int clk_notifier_unregister(struct clk *clk, return -ENOTSUPP; } +static inline int devm_clk_notifier_register(struct device *dev, + struct clk *clk, + struct notifier_block *nb) +{ + return -ENOTSUPP; +} + static inline long clk_get_accuracy(struct clk *clk) { return -ENOTSUPP;