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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,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 269E5C2BA19 for ; Tue, 14 Apr 2020 18:02:33 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D5CCE20767 for ; Tue, 14 Apr 2020 18:02:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="OlWvuBaC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D5CCE20767 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-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=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To: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:List-Owner; bh=AVfztCBUgUJkMyLgZBFYVxHmVQSe//2JY9WAR9t4lfc=; b=OlWvuBaCcitiG472NhfoBp1lvj sunql2IC2+E+o83ctEDFi11jZD5dcBCdCAJUUFaf12ncwixipcS0LZNxFBskKIAJa0CBxQYK0NuXf +k04cgJ9zQuS4zyfJ09P2LwLwhmmUGJ5CtunEUGBp7cpXuHMTCbg/ul6qYfxi5ObwgBjfevTRcHAf h0RfDA1LmsebY5XJEQil8FI0rz8GvqPFKXHwcC+7DxQT+FfxsFmbUkajBPmOsdZE+5Bq0Uq0lNwWL jfnX/i6I1iBzTZdVpuVjN/ChZ0HvxQ+9WcoahVfbrpNXgcthLgrJYXbOtONqha2BF79Zz5yN+gWVC xUbV7TeA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jOPtG-0003Im-QF; Tue, 14 Apr 2020 18:02:30 +0000 Received: from bhuna.collabora.co.uk ([46.235.227.227]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jOPsE-0002IP-FR for linux-arm-kernel@lists.infradead.org; Tue, 14 Apr 2020 18:01:28 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id F37A42A1BDC From: Andrzej Pietrasiewicz To: linux-pm@vger.kernel.org Subject: [RFC v2 4/9] thermal: core: Let thermal zone device's mode be stored in its struct Date: Tue, 14 Apr 2020 20:01:00 +0200 Message-Id: <20200414180105.20042-5-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414180105.20042-1-andrzej.p@collabora.com> References: <2bc5a902-acde-526a-11a5-2357d899916c@linaro.org> <20200414180105.20042-1-andrzej.p@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200414_110126_802027_4757070B X-CRM114-Status: GOOD ( 11.26 ) 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: "Rafael J . Wysocki" , platform-driver-x86@vger.kernel.org, kernel@collabora.com, Fabio Estevam , Amit Kucheria , Daniel Lezcano , linux-acpi@vger.kernel.org, NXP Linux Team , Darren Hart , Zhang Rui , Gayatri Kammela , Len Brown , Sascha Hauer , Ido Schimmel , Jiri Pirko , Thomas Gleixner , Allison Randal , linux-arm-kernel@lists.infradead.org, Support Opensource , Shawn Guo , Peter Kaestle , Andrzej Pietrasiewicz , Pengutronix Kernel Team , netdev@vger.kernel.org, Enrico Weigelt , "David S . Miller" , Andy Shevchenko MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org All the drivers which provide ->get_mode()/->set_mode() methods store their mode in a thermal_device_mode enum, so keep this information in struct thermal_zone_device rather than scattered all over the place. Signed-off-by: Andrzej Pietrasiewicz --- drivers/thermal/thermal_core.c | 28 +++++++++++++++++++ drivers/thermal/thermal_sysfs.c | 9 +++---- include/linux/thermal.h | 48 +++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 6 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 9a321dc548c8..cb0ff47f0dbe 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -469,6 +469,34 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) thermal_zone_device_init(tz); } +int thermal_zone_device_get_mode(struct thermal_zone_device *tz, + enum thermal_device_mode *mode) +{ + if (tz->ops->get_mode) + return tz->ops->get_mode(tz, mode); + + *mode = tz->mode; + + return 0; +} +EXPORT_SYMBOL_GPL(thermal_zone_device_get_mode); + +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ + if (mode != THERMAL_DEVICE_DISABLED && + mode != THERMAL_DEVICE_ENABLED) + return -EINVAL; + + if (tz->ops->set_mode) + return tz->ops->set_mode(tz, mode); + + tz->mode = mode; + + return 0; +} +EXPORT_SYMBOL_GPL(thermal_zone_device_set_mode); + void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index aa99edb4dff7..66d9691b8bd6 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -52,10 +52,7 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) enum thermal_device_mode mode; int result; - if (!tz->ops->get_mode) - return -EPERM; - - result = tz->ops->get_mode(tz, &mode); + result = thermal_zone_device_get_mode(tz, &mode); if (result) return result; @@ -74,9 +71,9 @@ mode_store(struct device *dev, struct device_attribute *attr, return -EPERM; if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); + result = thermal_zone_device_enable(tz); else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); + result = thermal_zone_device_disable(tz); else result = -EINVAL; diff --git a/include/linux/thermal.h b/include/linux/thermal.h index c91b1e344d56..9ff8542b7e7d 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -143,6 +143,7 @@ struct thermal_attr { * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature * @trip_type_attrs: attributes for trip points for sysfs: trip type * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis + * @mode: current mode of this thermal zone * @devdata: private pointer for device private data * @trips: number of trip points the thermal zone supports * @trips_disabled; bitmap for disabled trips @@ -185,6 +186,7 @@ struct thermal_zone_device { struct thermal_attr *trip_temp_attrs; struct thermal_attr *trip_type_attrs; struct thermal_attr *trip_hyst_attrs; + enum thermal_device_mode mode; void *devdata; int trips; unsigned long trips_disabled; /* bitmap for disabled trips */ @@ -437,6 +439,19 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, unsigned int); int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, struct thermal_cooling_device *); + +int thermal_zone_device_get_mode(struct thermal_zone_device *tz, + enum thermal_device_mode *mode); +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode); + +static inline void +thermal_zone_device_store_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ + tz->mode = mode; +} + void thermal_zone_device_update(struct thermal_zone_device *, enum thermal_notify_event); void thermal_zone_set_trips(struct thermal_zone_device *); @@ -494,6 +509,17 @@ static inline int thermal_zone_unbind_cooling_device( struct thermal_zone_device *tz, int trip, struct thermal_cooling_device *cdev) { return -ENODEV; } +static inline int thermal_zone_device_get_mode(struct thermal_zone_device *tz, + enum thermal_device_mode *mode) +{ return -ENODEV; } +static inline int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ return -ENODEV; } +static inline void +thermal_zone_device_store_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ } + static inline void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { } @@ -543,4 +569,26 @@ static inline void thermal_notify_framework(struct thermal_zone_device *tz, { } #endif /* CONFIG_THERMAL */ +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); +} + +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); +} + +static inline void +thermal_zone_device_store_enabled(struct thermal_zone_device *tz) +{ + thermal_zone_device_store_mode(tz, THERMAL_DEVICE_ENABLED); +} + +static inline void +thermal_zone_device_store_disabled(struct thermal_zone_device *tz) +{ + thermal_zone_device_store_mode(tz, THERMAL_DEVICE_DISABLED); +} + #endif /* __THERMAL_H__ */ -- 2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel