Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp701064pxa; Wed, 19 Aug 2020 12:24:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyT+RRujpHXCnriSWxM77git50pgGqmc65REfKGh9HdLrnX6O+k67XSYYiIn5Q1nF31+64W X-Received: by 2002:a17:906:824d:: with SMTP id f13mr27750197ejx.190.1597865071152; Wed, 19 Aug 2020 12:24:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597865071; cv=none; d=google.com; s=arc-20160816; b=QPWaCLF3bdNZSlaC5ZegRr81SRxfOsY0GRsuBydXYTeQkTgq5S34VhilAKj+qbF7Ue HL0qaZr3NVLsQWVvfv04jNgkZamSu8sN5SflG50FvW5TAyrCw8dWTrXtXgGbZEyrFXuf 5F0fEcH2FuqSE9kO5u3AaCHI1luzVyAJkcj6liQu2dN0+XoBXPvDrcxmwMKf5pR5bCiu ihUn/rgmbLHX64I+hjk1kXJ05Xwy0qnudqQB9uxTclnikakOOfAcJZvIeam4qzpcaZKo ZmngWq7Qt0vr8ileUp5diWUuQgyZyPLsypAgDCypvWbjd4oi4QULl+SQbH91p8E5HxAl BlQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=bGT9fwoymd6Ic9AGH3RntlECSDyDiGNWp2hinEX/z1I=; b=wG3K/yhwPkiePei3V57/xZMZWoJ+PTr8Hd4tC6YjV1ZbSU3/CKJisnuYoKQp7UQ8lj Kpx9UBKVJyT/ayFU8W4OZrJWghXEkS7LjMT2jBYu9H+/hxBu7l4EpZ2Zz2TG/TF0bR+o /oljSZ1u1mG7n75iV38YZ04hCISdlfjFZ8tRNSgKjOhNB+3G6us3Jcr2jSGi6PbD+dp/ XR5aSIBehp2cHm0uVP8nfnXS8G16V/bhrBIyqw/16yjUnDobFl6klay1br5luXIOV/3B EDOqXuC4lkZQc+zv59LE+N8XOE8WOuVX/9Z9B/U7hnXjHz0rFP+qcyC1lYbHLq46qNoj Y6nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=Nz4x6SLP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e11si15553276ejd.431.2020.08.19.12.24.06; Wed, 19 Aug 2020 12:24:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=Nz4x6SLP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726918AbgHSTXd (ORCPT + 99 others); Wed, 19 Aug 2020 15:23:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726211AbgHSTX3 (ORCPT ); Wed, 19 Aug 2020 15:23:29 -0400 Received: from mail.andi.de1.cc (mail.andi.de1.cc [IPv6:2a01:238:4321:8900:456f:ecd6:43e:202c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3DD6C061757; Wed, 19 Aug 2020 12:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kemnade.info; s=20180802; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To:From:Date:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=bGT9fwoymd6Ic9AGH3RntlECSDyDiGNWp2hinEX/z1I=; b=Nz4x6SLPB9YvHOHs9R+RjbXmsw jiuyRjtli+sw8kM98fLFS5EIeX+rBOTraKKByIt9LXeg9v/m0CkpMXl8fxql5/7dGIU5s6CaDDlen 5ZDNxwMqLhM14odRkryCHduXiSpRZg47ztbMSWOLM8kuN1nard283L3+x0rwBxkmcUag=; Received: from p200300ccff0e87001a3da2fffebfd33a.dip0.t-ipconnect.de ([2003:cc:ff0e:8700:1a3d:a2ff:febf:d33a] helo=aktux) by mail.andi.de1.cc with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1k8Tfv-0007qx-2w; Wed, 19 Aug 2020 21:23:07 +0200 Date: Wed, 19 Aug 2020 21:23:05 +0200 From: Andreas Kemnade To: Adam Ford Cc: linux-pm@vger.kernel.org, aford@beaconembedded.com, hns@goldelico.com, 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: Re: [PATCH V2 1/2] thermal: ti-soc-thermal: Enable addition power management Message-ID: <20200819212305.6caa4b7d@aktux> In-Reply-To: <20200819125925.2119434-1-aford173@gmail.com> References: <20200819125925.2119434-1-aford173@gmail.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Score: -1.0 (-) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 19 Aug 2020 07:59:23 -0500 Adam Ford wrote: > 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. > I get root@(none):/# cat /sys/class/thermal/thermal_zone0/type cpu_thermal root@(none):/# cat /sys/class/thermal/thermal_zone0/temp 50000 root@(none):/# cat /sys/class/thermal/thermal_zone1/ available_policies mode subsystem/ integral_cutoff offset sustainable_power k_d passive temp k_i policy type k_po power/ uevent k_pu slope root@(none):/# cat /sys/class/thermal/thermal_zone1/type bq27000-battery root@(none):/# cat /sys/kernel/debug/pm_debug/count usbhost_pwrdm (ON),OFF:3459,RET:635,INA:0,ON:4095,RET-LOGIC-OFF:0,RET-MEMBANK1-OFF:0 sgx_pwrdm (OFF),OFF:1,RET:0,INA:1,ON:2,RET-LOGIC-OFF:0,RET-MEMBANK1-OFF:0 core_pwrdm (ON),OFF:86,RET:7,INA:0,ON:94,RET-LOGIC-OFF:0,RET-MEMBANK1-OFF:0,RET-MEMBANK2-OFF:0 per_pwrdm (ON),OFF:1518,RET:64,INA:0,ON:1583,RET-LOGIC-OFF:0,RET-MEMBANK1-OFF:0 dss_pwrdm (ON),OFF:3459,RET:635,INA:0,ON:4095,RET-LOGIC-OFF:0,RET-MEMBANK1-OFF:0 cam_pwrdm (OFF),OFF:1,RET:1,INA:0,ON:2,RET-LOGIC-OFF:0,RET-MEMBANK1-OFF:0 neon_pwrdm (ON),OFF:2845,RET:1131,INA:119,ON:4096,RET-LOGIC-OFF:0 mpu_pwrdm (ON),OFF:2845,RET:1130,INA:119,ON:4095,RET-LOGIC-OFF:0,RET-MEMBANK1-OFF:0 iva2_pwrdm (OFF),OFF:1,RET:1,INA:0,ON:2,RET-LOGIC-OFF:0,RET-MEMBANK1-OFF:0,RET-MEMBANK2-OFF:0,RET-MEMBANK3-OFF:0,RET-MEMBANK4-OFF:0 usbhost_clkdm->usbhost_pwrdm (1) sgx_clkdm->sgx_pwrdm (0) per_clkdm->per_pwrdm (13) cam_clkdm->cam_pwrdm (0) dss_clkdm->dss_pwrdm (1) d2d_clkdm->core_pwrdm (0) iva2_clkdm->iva2_pwrdm (0) mpu_clkdm->mpu_pwrdm (0) core_l4_clkdm->core_pwrdm (20) core_l3_clkdm->core_pwrdm (1) neon_clkdm->neon_pwrdm (0) root@(none):/# So things still turn off. Tested-by: Andreas Kemnade # GTA04 > 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; > }; > > /**