Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp515731ybe; Wed, 18 Sep 2019 22:30:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqy7awJZUKngEyiwh4ynqwa80rpZ9bU24pJ1ZtCDg+GPaagZWGP3gbttCglIzecVlAvC/eU5 X-Received: by 2002:a50:cfc7:: with SMTP id i7mr13744990edk.89.1568871057919; Wed, 18 Sep 2019 22:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568871057; cv=none; d=google.com; s=arc-20160816; b=o/fSnvKNsTbeXmsyS1otYfAj7e9IKgXbxNTWXHQ2Q1TG3EyxAYWl25CPT+TgXNlmeX DqPltcmVj7Z2ms5SO5Nx5YRsgNO/RhpJcdpVeeisRKQVazW2O5+9OuvaikOk1HHPb0GS jV0E9v8Z6HE1o9aHqJ1TYfcHB2/0jyqtZfuPA2ZFatQGAAjeT6qjWcidbPYA6r3xfxwZ 5NiuRDmcSB+yaXqBWT9a7X90UepFMrU3ZsJkQ6c32HtiJCSIf9gQN0BZZXnPV/rOslVk qxQVBe6l6NLoPtH8+FaJUJlyAfW8Oufmo8RvmCFHXp59QBGInF04wiu9/tmJE2zLJW+d sn0w== 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:dkim-signature; bh=hnMqV/Yia1YygR1EYdN6c9UtAx32hcNfOwxm8eVaTYM=; b=cKueTREZBoVQvX2HgwkDZqInfhmKPKR2iC6SPkz8lE/3qijsqxf6eTvwI9szgKNQWP vI7Ct6n4oigwibd9lNn5oPMloGsQ9Rf1P/RcWeVJvoibQYNSIhAxdMr155/xC8cg/VOR FoYQmoYkKTH1AaVAbPJK51GE97FXFW+Ecf7DewWdut1SVcdhtueQZdXvz7MFaRfENxrV 45Beeia/LcOwc+W1ZNPldREzXZ5s7gh2YDuD0mXLB/FYwYu0tSvqLT0K2jqgAWQd41Iu jjg48XLJ+ahYm0UtCPI+kb6Ngt2+5gHTwU3f55EVCOV0tWabrQRQzhOakFAYo5ZaXqDM yp3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eoagL2Ho; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f13si4339566edr.445.2019.09.18.22.30.34; Wed, 18 Sep 2019 22:30:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eoagL2Ho; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388334AbfISCSb (ORCPT + 99 others); Wed, 18 Sep 2019 22:18:31 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:37656 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388315AbfISCS3 (ORCPT ); Wed, 18 Sep 2019 22:18:29 -0400 Received: by mail-qt1-f196.google.com with SMTP id d2so2330446qtr.4 for ; Wed, 18 Sep 2019 19:18:27 -0700 (PDT) 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; bh=hnMqV/Yia1YygR1EYdN6c9UtAx32hcNfOwxm8eVaTYM=; b=eoagL2Ho32riRPQK1weZiYpbIytlCjkW+ru7mE2enP6E/1J6MXI8dYLN9ZbL0TSvgL ElEo8/fVUCczO5OnPUJQuhmN6UyL9gSi0RVvLnoKMKzmgH6ezTiYhfLfYhDAtJXMClsd sHwL6T6041fq6ZUVgx4mrecGEtKRzMYCvquYUd+LTZDMjKQx/VcmZiS2eESxodx/m+2F GDtNYjhS70G2aHSmcMNL5FrX3lYahyzmjVfLEq51P4OKo/2AQjJGyUfOwz8WWWEl51mj i0ASOSu1d6zJFC1sJ/a37mSX/HDShmjbTtLSm+6riV6sC6Njepz9E13sxGUmB2ho2nBU 1Pog== 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:in-reply-to :references; bh=hnMqV/Yia1YygR1EYdN6c9UtAx32hcNfOwxm8eVaTYM=; b=PoalqTNFPDqKBNii4972cJR84uI15c2fV9wKOnf++PF/7G+DxsTitpMMkvzWP26zi3 BKZ3Vg/FrHon0uaJRb9WXGAA60LoN0FVAp82gazrr4vdYaxTCiJgEI82dIJmXiUSo+C0 q1qNaMrdBkOJ5dEbgCvH98Kdn7ATnwTr2Yt8X7UZYQRLsyLFZ3lGtqwBKYq127GPyQWG U5IOZ9XhlqCXbGjBZ/WCk3yk5tIZOqdk6gRPC2+4fNtX7tRAJNj3aaeWStkYUBfC1SJS 1Dwq1Ky4/FkuDz5Q0D0Xdiq3p760vK9cL7SRC2/qjfxghMYa2ZMpIIIBG98Dm2v00R2q QU8w== X-Gm-Message-State: APjAAAUin+uiWyAe7ZmXaTm6o7C8p7LYMbQooe4qIGwY9BboN9paGxGC WpkGq4c6jFKHoXbONHTlvNkcIYtKirAUuw== X-Received: by 2002:aed:2726:: with SMTP id n35mr850709qtd.171.1568859507091; Wed, 18 Sep 2019 19:18:27 -0700 (PDT) Received: from Thara-Work-Ubuntu.fios-router.home (pool-71-255-246-27.washdc.fios.verizon.net. [71.255.246.27]) by smtp.googlemail.com with ESMTPSA id o52sm5261275qtf.56.2019.09.18.19.18.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Sep 2019 19:18:26 -0700 (PDT) From: Thara Gopinath To: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, vincent.guittot@linaro.org, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: amit.kucheria@verdurent.com, mark.rutland@arm.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] thermal: Thermal core and sysfs changes needed to support bi-directional monitoring of trip points. Date: Wed, 18 Sep 2019 22:18:21 -0400 Message-Id: <1568859503-19725-3-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1568859503-19725-1-git-send-email-thara.gopinath@linaro.org> References: <1568859503-19725-1-git-send-email-thara.gopinath@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thermal trip points can be defined to indicate whether a temperature rise or a temperature fall is to be monitored. This property can now be defined in the DT bindings for a trip point. To support this following three changes are introduced to thermal core and sysfs code. 1. Define a new variable in thermal_trip to capture the monitor rising/falling information from trip point DT bindings. 2. Define a new ops in thermal_zone_device_ops that can be populated to indicate whether a trip is being monitored for rising or falling temperature. If the ops is not populated or if the binding is missing in the DT, it is assumed that the trip is being monitored for rising temperature. (default behavior today) 3. Introduce sysfs entries for each trip point to read the direction of monitoring. Signed-off-by: Thara Gopinath --- drivers/thermal/thermal_sysfs.c | 60 ++++++++++++++++++++++++++++++++++++++--- include/linux/thermal.h | 10 +++++++ include/uapi/linux/thermal.h | 2 +- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index aa99edb..b4ef6be 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -216,6 +216,31 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr, } static ssize_t +trip_point_monitor_type_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct thermal_zone_device *tz = to_thermal_zone(dev); + enum thermal_trip_monitor_type type; + int trip, result; + + if (sscanf(attr->attr.name, "trip_point_%d_monitor_type", &trip) != 1) + return -EINVAL; + + if (!tz->ops->get_trip_monitor_type) + goto exit; + + result = tz->ops->get_trip_monitor_type(tz, trip, &type); + if (result) + return result; + + if (type == THERMAL_TRIP_MONITOR_FALLING) + return sprintf(buf, "falling\n"); + +exit: + return sprintf(buf, "rising\n"); +} + +static ssize_t passive_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -520,10 +545,20 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) if (!tz->trip_type_attrs) return -ENOMEM; + tz->trip_monitor_type_attrs = kcalloc + (tz->trips, + sizeof(*tz->trip_monitor_type_attrs), + GFP_KERNEL); + if (!tz->trip_monitor_type_attrs) { + kfree(tz->trip_type_attrs); + return -ENOMEM; + } + tz->trip_temp_attrs = kcalloc(tz->trips, sizeof(*tz->trip_temp_attrs), GFP_KERNEL); if (!tz->trip_temp_attrs) { kfree(tz->trip_type_attrs); + kfree(tz->trip_monitor_type_attrs); return -ENOMEM; } @@ -533,14 +568,16 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) GFP_KERNEL); if (!tz->trip_hyst_attrs) { kfree(tz->trip_type_attrs); + kfree(tz->trip_monitor_type_attrs); kfree(tz->trip_temp_attrs); return -ENOMEM; } } - attrs = kcalloc(tz->trips * 3 + 1, sizeof(*attrs), GFP_KERNEL); + attrs = kcalloc(tz->trips * 4 + 1, sizeof(*attrs), GFP_KERNEL); if (!attrs) { kfree(tz->trip_type_attrs); + kfree(tz->trip_monitor_type_attrs); kfree(tz->trip_temp_attrs); if (tz->ops->get_trip_hyst) kfree(tz->trip_hyst_attrs); @@ -559,6 +596,20 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) tz->trip_type_attrs[indx].attr.show = trip_point_type_show; attrs[indx] = &tz->trip_type_attrs[indx].attr.attr; + /* create trip monitor type attribute */ + snprintf(tz->trip_monitor_type_attrs[indx].name, + THERMAL_NAME_LENGTH, "trip_point_%d_monitor_type", + indx); + + sysfs_attr_init(&tz->trip_monitor_type_attrs[indx].attr.attr); + tz->trip_monitor_type_attrs[indx].attr.attr.name = + tz->trip_monitor_type_attrs[indx].name; + tz->trip_monitor_type_attrs[indx].attr.attr.mode = S_IRUGO; + tz->trip_monitor_type_attrs[indx].attr.show = + trip_point_monitor_type_show; + attrs[indx + tz->trips] = + &tz->trip_monitor_type_attrs[indx].attr.attr; + /* create trip temp attribute */ snprintf(tz->trip_temp_attrs[indx].name, THERMAL_NAME_LENGTH, "trip_point_%d_temp", indx); @@ -574,7 +625,8 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) tz->trip_temp_attrs[indx].attr.store = trip_point_temp_store; } - attrs[indx + tz->trips] = &tz->trip_temp_attrs[indx].attr.attr; + attrs[indx + tz->trips * 2] = + &tz->trip_temp_attrs[indx].attr.attr; /* create Optional trip hyst attribute */ if (!tz->ops->get_trip_hyst) @@ -592,10 +644,10 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) tz->trip_hyst_attrs[indx].attr.store = trip_point_hyst_store; } - attrs[indx + tz->trips * 2] = + attrs[indx + tz->trips * 3] = &tz->trip_hyst_attrs[indx].attr.attr; } - attrs[tz->trips * 3] = NULL; + attrs[tz->trips * 4] = NULL; tz->trips_attribute_group.attrs = attrs; diff --git a/include/linux/thermal.h b/include/linux/thermal.h index e45659c..1435176b 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -70,6 +70,11 @@ enum thermal_trip_type { THERMAL_TRIP_CRITICAL, }; +enum thermal_trip_monitor_type { + THERMAL_TRIP_MONITOR_RISING = 0, + THERMAL_TRIP_MONITOR_FALLING +}; + enum thermal_trend { THERMAL_TREND_STABLE, /* temperature is stable */ THERMAL_TREND_RAISING, /* temperature is raising */ @@ -113,6 +118,8 @@ struct thermal_zone_device_ops { enum thermal_trend *); int (*notify) (struct thermal_zone_device *, int, enum thermal_trip_type); + int (*get_trip_monitor_type)(struct thermal_zone_device *, int, + enum thermal_trip_monitor_type *); }; struct thermal_cooling_device_ops { @@ -196,6 +203,7 @@ struct thermal_zone_device { struct thermal_attr *trip_temp_attrs; struct thermal_attr *trip_type_attrs; struct thermal_attr *trip_hyst_attrs; + struct thermal_attr *trip_monitor_type_attrs; void *devdata; int trips; unsigned long trips_disabled; /* bitmap for disabled trips */ @@ -364,6 +372,7 @@ struct thermal_zone_of_device_ops { * @temperature: temperature value in miliCelsius * @hysteresis: relative hysteresis in miliCelsius * @type: trip point type + * @monitor_type: trip point monitor type. */ struct thermal_trip { @@ -371,6 +380,7 @@ struct thermal_trip { int temperature; int hysteresis; enum thermal_trip_type type; + enum thermal_trip_monitor_type monitor_type; }; /* Function declarations */ diff --git a/include/uapi/linux/thermal.h b/include/uapi/linux/thermal.h index 9621837..c01492c 100644 --- a/include/uapi/linux/thermal.h +++ b/include/uapi/linux/thermal.h @@ -2,7 +2,7 @@ #ifndef _UAPI_LINUX_THERMAL_H #define _UAPI_LINUX_THERMAL_H -#define THERMAL_NAME_LENGTH 20 +#define THERMAL_NAME_LENGTH 30 /* Adding event notification support elements */ #define THERMAL_GENL_FAMILY_NAME "thermal_event" -- 2.1.4