From patchwork Thu Sep 19 02:18:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 174017 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp422106ill; Wed, 18 Sep 2019 19:18:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqydv52x8OA6bxVrtnnU2VLYhSVuN7ChRstDJk1JYifPK2Z+peNy9rOfj7UeAbby7BCoLpBn X-Received: by 2002:a17:906:f204:: with SMTP id gt4mr9941162ejb.299.1568859512071; Wed, 18 Sep 2019 19:18:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568859512; cv=none; d=google.com; s=arc-20160816; b=VEANwTl7XPCmP/A7CgepVwJ2c6W576bDjQFigHNZIF0H8cdCb64igTDE3Gu3O4u/OF +ivHbZhdx1OjzkUH0rzeIH3rIQhpjv6deroUbUZ0adlZq4gxipH5pKsu+x+oo6E1joKs 9thSVF0v7qldSw5hVyG5jyhs+YQ8xRz/8qzph7g7BK60kk+ZcHZ6JdtJWcIGNVoUq98c fEXjB8NKmFdqWBugpqYRsO3rfB1cnoMba12Jxq8qApqP8YWLcuitKRqkhgTKnjj6FE4c yFbh16NGSAnwkTjifIMQnmoK95ZihXp5Ed70ScFQ17kexoEMLUdphmlLe6z5n5RMR9Uf 8x2g== 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=LiLgBdqbiBwQxOeyWjz1I++Y2tyojGKINNZLZGI2Zeup1/IZhphVtNWntTigm3dro+ QwxNRiuncm5EnOKeU4snbUksB8VOd1vqlkIXbG1nvQGYBPkjC3Rh9JClLNHAiLq5hCpT K4vHVbodLqbQqYxkYfMgSd9hopc6dvSHg4at2qWI1MN+RCUfO7DFSvjVMcVSkLVKgIFl DJoJ6Z0qBT7yKmbNeT1VG5Bh/pZafm0p8ft+MbovsUWlwdGKQ3SaM1K5t9KmkxJ62Mq3 bo5LkNG5leLHa21ciSWk4Se+f4PhllFck0t6yCS9cOoZTez9R10Z6H1i3p1LCYUY+KQA Wh9A== 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 devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 c48si4657415edc.169.2019.09.18.19.18.31; Wed, 18 Sep 2019 19:18:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-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 devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 S2388327AbfISCS3 (ORCPT + 8 others); Wed, 18 Sep 2019 22:18:29 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:46364 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388273AbfISCS2 (ORCPT ); Wed, 18 Sep 2019 22:18:28 -0400 Received: by mail-qt1-f195.google.com with SMTP id u22so2253521qtq.13 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=DKTKryQPbhEc4+9DSXCTvnF6tvvRfH9T0CEeVeS5CIZmDUgps+VdyrcjwAwGB5GkHT N833YEHsltO02bnWf677vt9hZQWwygKTuna+0tZZPvNCIM3IX7gxpckKDSlj/rMB9gAz cPOPlpgV/CPreNUEaHvZP16uUjhfi7nbcLmeruacZvpL7FcL9qDmBYn/9815dcAAZqBB HZpxnzJcxqGjU2DGUGqNTfVFQNYvy7EytQLiZhU+xDcfezCsL5SVAt3TGvL8Fa6MalNh QJXD4h+B1EZbhsfI2L94if0jZHO83413wphkUHyKQA2HxjwdzO96XxtXGYDWkbSfcq2u w1MQ== X-Gm-Message-State: APjAAAWwo3oluz/Au92tsC3CIbGblCI2gZr6qipkwIQJjhoNfpH3kgq1 kwye3n0eHiIPEnXMKwr2zx7hIg== 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: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@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(-) -- 2.1.4 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"