Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp680186ybm; Thu, 28 May 2020 12:25:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSJSkBHT7mEvDgiittWX8hdlW4SxutkINaTfYa2Cj78qgY7RHJcVb84aM9eLqFQ0DY5hjW X-Received: by 2002:a17:906:49da:: with SMTP id w26mr4399595ejv.548.1590693927956; Thu, 28 May 2020 12:25:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590693927; cv=none; d=google.com; s=arc-20160816; b=UC5PNiRpVY1W4biWnWGAdnHvXiq7CiDjCY/urIb9zZX1JyKtcLMDWTyE0Uqr3DD9A5 NaD/guxXPO8hnIsbDAGCszjAVt4H+XDIkrgWAzSWyYofCH/crUehJrJ+8sd2d26IrfKu 24pS/fwBUautWFYyUg6S+CnM/mFAH6tYqu0mmgOCpRZA3nsk74E+fTgthW9jvqArdSir VV3gKNy3z5+GtG/3kesavuZUvJuYhGjyXqCbV/YJZ+HvBlLYarQcxKrUaXZR4E9TwGqJ guCvswWAmbl+yqWfbJwiB/H8WlCsbAHFgRc9AsYemQ4JEgFPeqKifY8Dhw7EtFYOfcmH TwSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=5D+osIqTEhi34r+jM5JmHsiCFCemKUETuYWwPCeqIqo=; b=T0mRfG63QQK+WgHhFOOWWTii9cYAn3J3jR6PeHhMxOduTUrzZ/H4irTZDsPzvWDjCF lG//Z88MNkULn9CBFWjMygkCTwDxP6PV3ubFQjZnyrhledF0X+fpoBVwfm+v1sHYbQVs d6HQantHVK3f5kdxmaHEMOvhoLpeQO76bcT38OquAxzfj8e1s//m+Wi3/pZu81QbuKKJ D0jfzCTq3e38b4DcqyUSPZ6b1xnO5sHU1zE1rQqPdjzRCoShF5CARLrSE82KuxIXT+Vh S3tG4AQL7QZ1XZBk8QnkRkcjSlJ3YyjG9nf60Bt8la1HYnlcsc3KHWWrHkcxPS6MvBo2 4MDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn14si1442250ejc.414.2020.05.28.12.25.03; Thu, 28 May 2020 12:25:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406436AbgE1TWL (ORCPT + 99 others); Thu, 28 May 2020 15:22:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406423AbgE1TWF (ORCPT ); Thu, 28 May 2020 15:22:05 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3A70C08C5C6; Thu, 28 May 2020 12:22:04 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 5D9472A41CC From: Andrzej Pietrasiewicz To: linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-rockchip@lists.infradead.org Cc: "Rafael J . Wysocki" , Len Brown , Vishal Kulkarni , "David S . Miller" , Jiri Pirko , Ido Schimmel , Johannes Berg , Emmanuel Grumbach , Luca Coelho , Intel Linux Wireless , Kalle Valo , Peter Kaestle , Darren Hart , Andy Shevchenko , Sebastian Reichel , Miquel Raynal , Daniel Lezcano , Amit Kucheria , Support Opensource , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Heiko Stuebner , Orson Zhai , Baolin Wang , Chunyan Zhang , Zhang Rui , Allison Randal , Enrico Weigelt , Gayatri Kammela , Thomas Gleixner , Bartlomiej Zolnierkiewicz , Andrzej Pietrasiewicz , kernel@collabora.com Subject: [PATCH v4 06/11] thermal: Add mode helpers Date: Thu, 28 May 2020 21:20:46 +0200 Message-Id: <20200528192051.28034-7-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200528192051.28034-1-andrzej.p@collabora.com> References: <20200528192051.28034-1-andrzej.p@collabora.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Prepare for making the drivers not access tzd's private members. Signed-off-by: Andrzej Pietrasiewicz --- drivers/thermal/thermal_core.c | 53 ++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 13 +++++++++ 2 files changed, 66 insertions(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 14d3b1b94c4f..f2a5c5ee3455 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -459,6 +459,59 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) thermal_zone_device_init(tz); } +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ + int ret = 0; + + mutex_lock(&tz->lock); + + /* do nothing if mode isn't changing */ + if (mode == tz->mode) { + mutex_unlock(&tz->lock); + + return ret; + } + + if (tz->ops->set_mode) + ret = tz->ops->set_mode(tz, mode); + + if (!ret) + tz->mode = mode; + + mutex_unlock(&tz->lock); + + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); + + return ret; +} + +int thermal_zone_device_enable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); +} +EXPORT_SYMBOL(thermal_zone_device_enable); + +int thermal_zone_device_disable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); +} +EXPORT_SYMBOL(thermal_zone_device_disable); + +int thermal_zone_device_is_enabled(struct thermal_zone_device *tz) +{ + enum thermal_device_mode mode; + + mutex_lock(&tz->lock); + + mode = tz->mode; + + mutex_unlock(&tz->lock); + + return mode == THERMAL_DEVICE_ENABLED; +} +EXPORT_SYMBOL(thermal_zone_device_is_enabled); + void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { diff --git a/include/linux/thermal.h b/include/linux/thermal.h index a808f6fa2777..df013c39ba9b 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -416,6 +416,9 @@ int thermal_zone_get_offset(struct thermal_zone_device *tz); void thermal_cdev_update(struct thermal_cooling_device *); void thermal_notify_framework(struct thermal_zone_device *, int); +int thermal_zone_device_enable(struct thermal_zone_device *tz); +int thermal_zone_device_disable(struct thermal_zone_device *tz); +int thermal_zone_device_is_enabled(struct thermal_zone_device *tz); #else static inline struct thermal_zone_device *thermal_zone_device_register( const char *type, int trips, int mask, void *devdata, @@ -463,6 +466,16 @@ static inline void thermal_cdev_update(struct thermal_cooling_device *cdev) static inline void thermal_notify_framework(struct thermal_zone_device *tz, int trip) { } + +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) +{ return -ENODEV; } + +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) +{ return -ENODEV; } + +static inline int +thermal_zone_device_is_enabled(struct thermal_zone_device *tz) +{ return -ENODEV; } #endif /* CONFIG_THERMAL */ #endif /* __THERMAL_H__ */ -- 2.17.1