From mboxrd@z Thu Jan 1 00:00:00 1970 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.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 BC8C1C433DF for ; Wed, 19 Aug 2020 13:06:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90FC8206FA for ; Wed, 19 Aug 2020 13:06:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H9uu9JET" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728674AbgHSNGV (ORCPT ); Wed, 19 Aug 2020 09:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728504AbgHSNAW (ORCPT ); Wed, 19 Aug 2020 09:00:22 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F645C06135C; Wed, 19 Aug 2020 05:59:35 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id v6so24467502iow.11; Wed, 19 Aug 2020 05:59:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6oVAmZyNrEFZ/qRL/Go1FpkwND3iynaGyrQg/YaoVXg=; b=H9uu9JET+dLKWqo7t/dWEJEOctZhL8wpGr2sXlW4Vb0wn6trZDEN53GJhvvjgJhZIP 659ezdEWF8Z4SwbFa/Asb8VX8m00ejalsigAVz8iJKnKyCI+Y14A0l9BpPcAIV61HTCV uSfB7Cuztw8qjG9OfjCWkBcFv/MC/IwjzPQ7rRo//S533Jp0nMNsR7oulST+XzR+YwnC kmSr1NWBD1FlYBqRwOimkgE9IAGSV+V5ZHP0kBvKwX1FPYgqHSh2pN5JijoMlxiTGLex Fb+pWCudQGBLu2FCBxMHqDJ5M8C1HHIJQcVn0ocp9XUmG7NfOTi/5BXj5i9AOFw+Bd4a 43ww== 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:mime-version :content-transfer-encoding; bh=6oVAmZyNrEFZ/qRL/Go1FpkwND3iynaGyrQg/YaoVXg=; b=hC3xTUxk8dbKJbLSAJ5cq5eC2NBYH+7zkjdCZK5ryfZBp3yDIx/8fHl+B8eSIn82BG h2S1NMtHB0NEJu5nE+1lAH5nz2cVqzzQd0WLfD0Mp6m/09usRuEcddKXz82nZgWOM5uh UKcQIFa5zan5oMPH61NcGZtmLxwRYYpaQGr3EaIVRa2oPs2y4ScqhVClo6F+qPbk1Jgc n/qR95vnTtTaCFPjS3d9I8/+Q5C1rtt1AaMO8K4sapJXsm/RoTxq1pcKZ+hum6JS/UAF XcWfJNWsQ0vfaRtE0iEZV2WMXDFwvHNzDISYSjYjW1H4eEZFVK/1WoUSGCyKzzlVbwn2 gq5A== X-Gm-Message-State: AOAM5303v6hSnnkQgrXApLRptbjC4kGCePzazWBgrWjx2Aoyzj3oAXI/ gFpcJXnBqslN7mtqG8cgPWpwZZYd2dmDjmP1 X-Google-Smtp-Source: ABdhPJy7SeHYcvfIBOyXe6sU4+ijHjrvIgF6d7n/mmqAgapcaRBQ/s4uRdGv3Qa2xUjeFQ0kgX8+iA== X-Received: by 2002:a02:3843:: with SMTP id v3mr24082031jae.23.1597841973657; Wed, 19 Aug 2020 05:59:33 -0700 (PDT) Received: from aford-IdeaCentre-A730.lan ([2601:448:8400:9e8:b588:1a5f:55c3:870e]) by smtp.gmail.com with ESMTPSA id i5sm4138388ilc.69.2020.08.19.05.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 05:59:32 -0700 (PDT) From: Adam Ford To: linux-pm@vger.kernel.org Cc: aford@beaconembedded.com, hns@goldelico.com, Adam Ford , kernel test robot , Tony Lindgren , Russell King , Eduardo Valentin , Keerthy , Zhang Rui , Daniel Lezcano , Amit Kucheria , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 1/2] thermal: ti-soc-thermal: Enable addition power management Date: Wed, 19 Aug 2020 07:59:23 -0500 Message-Id: <20200819125925.2119434-1-aford173@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The bandgap sensor can be idled when the processor is too, but it isn't currently being done, so the power consumption of OMAP3 boards can elevated if the bangap sensor is enabled. This patch attempts to use some additional power management to idle the clock to the bandgap when not needed. Signed-off-by: Adam Ford Reported-by: kernel test robot --- V2: Fix issue where variable stating the suspend mode isn't being properly set and cleared. diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c index ab19ceff6e2a..9404631bea4d 100644 --- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c +++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c @@ -25,10 +25,18 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include "ti-bandgap.h" static int ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id); +static int bandgap_omap_cpu_notifier(struct notifier_block *nb, + unsigned long cmd, void *v); /*** Helper functions to access registers and their bitfields ***/ @@ -1008,6 +1016,9 @@ int ti_bandgap_probe(struct platform_device *pdev) } } + bgp->nb.notifier_call = bandgap_omap_cpu_notifier; + cpu_pm_register_notifier(&bgp->nb); + return 0; remove_last_cooling: @@ -1041,7 +1052,9 @@ int ti_bandgap_remove(struct platform_device *pdev) struct ti_bandgap *bgp = platform_get_drvdata(pdev); int i; - /* First thing is to remove sensor interfaces */ + cpu_pm_unregister_notifier(&bgp->nb); + + /* Remove sensor interfaces */ for (i = 0; i < bgp->conf->sensor_count; i++) { if (bgp->conf->sensors[i].unregister_cooling) bgp->conf->sensors[i].unregister_cooling(bgp, i); @@ -1150,9 +1163,43 @@ static int ti_bandgap_suspend(struct device *dev) if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) clk_disable_unprepare(bgp->fclock); + bgp->is_suspended = true; + return err; } +static int bandgap_omap_cpu_notifier(struct notifier_block *nb, + unsigned long cmd, void *v) +{ + struct ti_bandgap *bgp; + + bgp = container_of(nb, struct ti_bandgap, nb); + + spin_lock(&bgp->lock); + switch (cmd) { + case CPU_CLUSTER_PM_ENTER: + if (bgp->is_suspended) + break; + ti_bandgap_save_ctxt(bgp); + ti_bandgap_power(bgp, false); + if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) + clk_disable(bgp->fclock); + break; + case CPU_CLUSTER_PM_ENTER_FAILED: + case CPU_CLUSTER_PM_EXIT: + if (bgp->is_suspended) + break; + if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) + clk_enable(bgp->fclock); + ti_bandgap_power(bgp, true); + ti_bandgap_restore_ctxt(bgp); + break; + } + spin_unlock(&bgp->lock); + + return NOTIFY_OK; +} + static int ti_bandgap_resume(struct device *dev) { struct ti_bandgap *bgp = dev_get_drvdata(dev); @@ -1161,6 +1208,7 @@ static int ti_bandgap_resume(struct device *dev) clk_prepare_enable(bgp->fclock); ti_bandgap_power(bgp, true); + bgp->is_suspended = false; return ti_bandgap_restore_ctxt(bgp); } diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.h b/drivers/thermal/ti-soc-thermal/ti-bandgap.h index fce4657e9486..ed0ea4b17b25 100644 --- a/drivers/thermal/ti-soc-thermal/ti-bandgap.h +++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.h @@ -12,6 +12,10 @@ #include #include #include +#include +#include +#include +#include struct gpio_desc; @@ -203,6 +207,8 @@ struct ti_bandgap { int irq; struct gpio_desc *tshut_gpiod; u32 clk_rate; + struct notifier_block nb; + unsigned int is_suspended:1; }; /** -- 2.25.1 From mboxrd@z Thu Jan 1 00:00:00 1970 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.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,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 C8965C433E1 for ; Wed, 19 Aug 2020 13:01:16 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 85445206FA for ; Wed, 19 Aug 2020 13:01:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="fbEkW921"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H9uu9JET" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85445206FA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=bHXlYiYf/WnAZD3o2oQjmKb0a9jE1Gy5QQ37SzyTQBA=; b=fbEkW921rD24t8XNpQScOB7hni IuS0We6z9aarcqr+mL3uRW5//HIza4c2WD4MHQu5d2o9J9szZTBPSDqBaUjs+8mOZeu7r3aEUqyIy QUDixQXnD2hFNsQOfCzcSqc4P5V6nBnt5SXVAs/QSnXz+ZOsHqDDG+MMV6WOT7JVKPEg51JooJ5Uw 3CIX46iNvfpc0lPObcTsnv8qouUAGynwCIyiwB9Gq/AT8t8NIIYKfO+JvF/5L/QXawplmnpKIvNB1 h27DJGtNQT9A97Efjk2OTTuQobt8E/ES8qXIQeAImNec/KHEGZkQQUh32RnzKmGdZbw9OXDKotDtz VqET87/Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k8Ngo-0001FQ-Of; Wed, 19 Aug 2020 12:59:38 +0000 Received: from mail-io1-xd43.google.com ([2607:f8b0:4864:20::d43]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k8Ngl-0001DL-Rl for linux-arm-kernel@lists.infradead.org; Wed, 19 Aug 2020 12:59:36 +0000 Received: by mail-io1-xd43.google.com with SMTP id s1so11460995iot.10 for ; Wed, 19 Aug 2020 05:59:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6oVAmZyNrEFZ/qRL/Go1FpkwND3iynaGyrQg/YaoVXg=; b=H9uu9JET+dLKWqo7t/dWEJEOctZhL8wpGr2sXlW4Vb0wn6trZDEN53GJhvvjgJhZIP 659ezdEWF8Z4SwbFa/Asb8VX8m00ejalsigAVz8iJKnKyCI+Y14A0l9BpPcAIV61HTCV uSfB7Cuztw8qjG9OfjCWkBcFv/MC/IwjzPQ7rRo//S533Jp0nMNsR7oulST+XzR+YwnC kmSr1NWBD1FlYBqRwOimkgE9IAGSV+V5ZHP0kBvKwX1FPYgqHSh2pN5JijoMlxiTGLex Fb+pWCudQGBLu2FCBxMHqDJ5M8C1HHIJQcVn0ocp9XUmG7NfOTi/5BXj5i9AOFw+Bd4a 43ww== 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:mime-version :content-transfer-encoding; bh=6oVAmZyNrEFZ/qRL/Go1FpkwND3iynaGyrQg/YaoVXg=; b=PuXlA5JS7BITdZ/yN8NC4t4swXda9wJtx9s3YBnpuZUuoKRH3xDyZjJiQrXGtE9A1u dCtXa6vU917SrcZyUY2u9ROeNfLwmwm6FoW/j+Jy9yBnQa/iSyRlMWNCbzAhcyCBZs9q f2akVDYxdwGS0WwzigbhpYLC82KAFhcl1cK4ysAHMdVTtv4ssRldWoD0iTW/bJBCfUxr e5FjwOUv49Loxow93hzuAO/ObkaoIpB3aS1AYpS8DOoi+coFhc81oaO1KBqQvE0QUKml pC5r64L1LZd3OO9+zLRhFIjnnh4/wZDKntnDMvZ5pzO4PUKQxU8ce3eUJywLpjMBY7to +CTQ== X-Gm-Message-State: AOAM533e75xFOtGQdSPfgE2TzeeFgZ8p+xk2R8OJdbD28/kHwJs8+AzX 9l78mEuCuVsrYpd/oy0xayg= X-Google-Smtp-Source: ABdhPJy7SeHYcvfIBOyXe6sU4+ijHjrvIgF6d7n/mmqAgapcaRBQ/s4uRdGv3Qa2xUjeFQ0kgX8+iA== X-Received: by 2002:a02:3843:: with SMTP id v3mr24082031jae.23.1597841973657; Wed, 19 Aug 2020 05:59:33 -0700 (PDT) Received: from aford-IdeaCentre-A730.lan ([2601:448:8400:9e8:b588:1a5f:55c3:870e]) by smtp.gmail.com with ESMTPSA id i5sm4138388ilc.69.2020.08.19.05.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 05:59:32 -0700 (PDT) From: Adam Ford To: linux-pm@vger.kernel.org Subject: [PATCH V2 1/2] thermal: ti-soc-thermal: Enable addition power management Date: Wed, 19 Aug 2020 07:59:23 -0500 Message-Id: <20200819125925.2119434-1-aford173@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200819_085936_091056_F69ED3A1 X-CRM114-Status: GOOD ( 20.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amit Kucheria , linux-kernel@vger.kernel.org, kernel test robot , Tony Lindgren , hns@goldelico.com, Daniel Lezcano , aford@beaconembedded.com, Russell King , Eduardo Valentin , Keerthy , Zhang Rui , linux-omap@vger.kernel.org, Adam Ford , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The bandgap sensor can be idled when the processor is too, but it isn't currently being done, so the power consumption of OMAP3 boards can elevated if the bangap sensor is enabled. This patch attempts to use some additional power management to idle the clock to the bandgap when not needed. Signed-off-by: Adam Ford Reported-by: kernel test robot --- V2: Fix issue where variable stating the suspend mode isn't being properly set and cleared. diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c index ab19ceff6e2a..9404631bea4d 100644 --- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c +++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c @@ -25,10 +25,18 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include "ti-bandgap.h" static int ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id); +static int bandgap_omap_cpu_notifier(struct notifier_block *nb, + unsigned long cmd, void *v); /*** Helper functions to access registers and their bitfields ***/ @@ -1008,6 +1016,9 @@ int ti_bandgap_probe(struct platform_device *pdev) } } + bgp->nb.notifier_call = bandgap_omap_cpu_notifier; + cpu_pm_register_notifier(&bgp->nb); + return 0; remove_last_cooling: @@ -1041,7 +1052,9 @@ int ti_bandgap_remove(struct platform_device *pdev) struct ti_bandgap *bgp = platform_get_drvdata(pdev); int i; - /* First thing is to remove sensor interfaces */ + cpu_pm_unregister_notifier(&bgp->nb); + + /* Remove sensor interfaces */ for (i = 0; i < bgp->conf->sensor_count; i++) { if (bgp->conf->sensors[i].unregister_cooling) bgp->conf->sensors[i].unregister_cooling(bgp, i); @@ -1150,9 +1163,43 @@ static int ti_bandgap_suspend(struct device *dev) if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) clk_disable_unprepare(bgp->fclock); + bgp->is_suspended = true; + return err; } +static int bandgap_omap_cpu_notifier(struct notifier_block *nb, + unsigned long cmd, void *v) +{ + struct ti_bandgap *bgp; + + bgp = container_of(nb, struct ti_bandgap, nb); + + spin_lock(&bgp->lock); + switch (cmd) { + case CPU_CLUSTER_PM_ENTER: + if (bgp->is_suspended) + break; + ti_bandgap_save_ctxt(bgp); + ti_bandgap_power(bgp, false); + if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) + clk_disable(bgp->fclock); + break; + case CPU_CLUSTER_PM_ENTER_FAILED: + case CPU_CLUSTER_PM_EXIT: + if (bgp->is_suspended) + break; + if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) + clk_enable(bgp->fclock); + ti_bandgap_power(bgp, true); + ti_bandgap_restore_ctxt(bgp); + break; + } + spin_unlock(&bgp->lock); + + return NOTIFY_OK; +} + static int ti_bandgap_resume(struct device *dev) { struct ti_bandgap *bgp = dev_get_drvdata(dev); @@ -1161,6 +1208,7 @@ static int ti_bandgap_resume(struct device *dev) clk_prepare_enable(bgp->fclock); ti_bandgap_power(bgp, true); + bgp->is_suspended = false; return ti_bandgap_restore_ctxt(bgp); } diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.h b/drivers/thermal/ti-soc-thermal/ti-bandgap.h index fce4657e9486..ed0ea4b17b25 100644 --- a/drivers/thermal/ti-soc-thermal/ti-bandgap.h +++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.h @@ -12,6 +12,10 @@ #include #include #include +#include +#include +#include +#include struct gpio_desc; @@ -203,6 +207,8 @@ struct ti_bandgap { int irq; struct gpio_desc *tshut_gpiod; u32 clk_rate; + struct notifier_block nb; + unsigned int is_suspended:1; }; /** -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel