From patchwork Tue Jan 25 17:18:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 537468 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2D1AC433F5 for ; Tue, 25 Jan 2022 17:20:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1587922AbiAYRUl (ORCPT ); Tue, 25 Jan 2022 12:20:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1587611AbiAYRSc (ORCPT ); Tue, 25 Jan 2022 12:18:32 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C1E7C0613DE for ; Tue, 25 Jan 2022 09:18:31 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id k18so21174505wrg.11 for ; Tue, 25 Jan 2022 09:18:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oPK1edLyJrRFFEyWcyiec8UXIbfSrQa/ueeEQUG7KDE=; b=RBU/1hiKjmlJ/Dsr3f5tqnVKDSzIfG098aUQFPkk8pdvkwB9NxZ9fq978c+MJXXa9/ zVgVf1bmsirhIaK0aosP+k8kVheG0uePIBt2bXmWmJRAazGxqVRqhNNdpJlJDy7JANVf Q63Y/moYNAdGodSAJcMXeoYipauvf5OicgkYR87blsbq5ItgeusS0XkJbd/sl+9A2R2U +CNv3ki9rKVXRCpMe2+lmnJnXEdNAFXqDbZ1A1TBL++/iIRFY0aqYTEg2BgkW04HDGvh WfPCtqkyNSoqU/nSkvCbR093D4fDEHRktLYmUjnBMx7Iq0BETJ+TbZAp4lsvT7Lwgrct DbEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oPK1edLyJrRFFEyWcyiec8UXIbfSrQa/ueeEQUG7KDE=; b=cNG/fce7zpDFx+vbjtPjeMcYyeprfFfvE8JAz9z1up7Lvzthv9XheL6gpqv7pPR+kO zl0/z8EyC+B3MlItZuXKTu8S1PM/IPssFsgWPzO3SrBmoADzHpt7Ef+8/noVqAos8Tdu UbDvRnVBTwCMrhmhd1IJf007A8iI63iy8r9/3ButSHLd66Mxikv/KmuflCT9XcuKJAcE +dWEisCtZEOcY77i1DRR8e1ySCA+qGeWwrkFUoyfzg1m0gGLRhfrGn4Vk49dKHbbtC1x 5hTfhZYfaLTZ+3M7yH/bEDRiIVA/we8qMSRVlVqs+grJoduTtwG7D8ljCdpcpVMZEK3e 3ccg== X-Gm-Message-State: AOAM53241LJrtMsatYi6AOTdX3D4r/YXWMNT0kOngdbq79tp8WxQpVYc 46CdRZfMabD9XaSsVwoWjMHCCQ== X-Google-Smtp-Source: ABdhPJzButqKQFOvZwcUyr9EDDzPhcmJ8XRTMpdAQyrjNaDbtrxGArgpECjJWYYyEKSsXv4rRmFvKg== X-Received: by 2002:a05:6000:1091:: with SMTP id y17mr19040004wrw.310.1643131109892; Tue, 25 Jan 2022 09:18:29 -0800 (PST) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:f589:cf7d:b2ee:bb5e]) by smtp.gmail.com with ESMTPSA id t18sm17561901wri.34.2022.01.25.09.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 09:18:29 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rjw@rjwysocki.net Cc: robh@kernel.org, lukasz.luba@arm.com, heiko@sntech.de, arnd@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Ulf Hansson , Daniel Lezcano , "Rafael J. Wysocki" Subject: [PATCH v7 3/5] powercap/drivers/dtpm: Add CPU DT initialization support Date: Tue, 25 Jan 2022 18:18:07 +0100 Message-Id: <20220125171809.1273269-4-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220125171809.1273269-1-daniel.lezcano@linaro.org> References: <20220125171809.1273269-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Based on the previous DT changes in the core code, use the 'setup' callback to initialize the CPU DTPM backend. Code is reorganized to stick to the DTPM table description. No functional changes. Signed-off-by: Daniel Lezcano Reviewed-by: Ulf Hansson --- drivers/powercap/dtpm_cpu.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c index 5763e0ce2af5..eed5ad688d46 100644 --- a/drivers/powercap/dtpm_cpu.c +++ b/drivers/powercap/dtpm_cpu.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -176,6 +177,17 @@ static int cpuhp_dtpm_cpu_offline(unsigned int cpu) } static int cpuhp_dtpm_cpu_online(unsigned int cpu) +{ + struct dtpm_cpu *dtpm_cpu; + + dtpm_cpu = per_cpu(dtpm_per_cpu, cpu); + if (dtpm_cpu) + return dtpm_update_power(&dtpm_cpu->dtpm); + + return 0; +} + +static int __dtpm_cpu_setup(int cpu, struct dtpm *parent) { struct dtpm_cpu *dtpm_cpu; struct cpufreq_policy *policy; @@ -183,6 +195,10 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu) char name[CPUFREQ_NAME_LEN]; int ret = -ENOMEM; + dtpm_cpu = per_cpu(dtpm_per_cpu, cpu); + if (dtpm_cpu) + return 0; + policy = cpufreq_cpu_get(cpu); if (!policy) return 0; @@ -191,10 +207,6 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu) if (!pd) return -EINVAL; - dtpm_cpu = per_cpu(dtpm_per_cpu, cpu); - if (dtpm_cpu) - return dtpm_update_power(&dtpm_cpu->dtpm); - dtpm_cpu = kzalloc(sizeof(*dtpm_cpu), GFP_KERNEL); if (!dtpm_cpu) return -ENOMEM; @@ -207,7 +219,7 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu) snprintf(name, sizeof(name), "cpu%d-cpufreq", dtpm_cpu->cpu); - ret = dtpm_register(name, &dtpm_cpu->dtpm, NULL); + ret = dtpm_register(name, &dtpm_cpu->dtpm, parent); if (ret) goto out_kfree_dtpm_cpu; @@ -231,7 +243,18 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu) return ret; } -static int __init dtpm_cpu_init(void) +static int dtpm_cpu_setup(struct dtpm *dtpm, struct device_node *np) +{ + int cpu; + + cpu = of_cpu_node_to_id(np); + if (cpu < 0) + return 0; + + return __dtpm_cpu_setup(cpu, dtpm); +} + +static int dtpm_cpu_init(void) { int ret; @@ -272,4 +295,5 @@ static int __init dtpm_cpu_init(void) struct dtpm_subsys_ops dtpm_cpu_ops = { .name = KBUILD_MODNAME, .init = dtpm_cpu_init, + .setup = dtpm_cpu_setup, };