From patchwork Tue Nov 8 05:08:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9416547 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9C9CE60512 for ; Tue, 8 Nov 2016 05:15:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C6F528B99 for ; Tue, 8 Nov 2016 05:15:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 809F328B9B; Tue, 8 Nov 2016 05:15:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2810828B99 for ; Tue, 8 Nov 2016 05:15:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752929AbcKHFJx (ORCPT ); Tue, 8 Nov 2016 00:09:53 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:36637 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752906AbcKHFJu (ORCPT ); Tue, 8 Nov 2016 00:09:50 -0500 Received: by mail-pf0-f193.google.com with SMTP id n85so18049225pfi.3; Mon, 07 Nov 2016 21:09:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UGjfhTjSMIIxuXC9emCHksOYUO58P9kbGbwMm3uPS50=; b=gMK2+hJqQGzG1orJb79Er9ZPp04C6okGuF5zIMKT5XDD7tyw9Snv84gyevmSGeyfp0 0sJOfmIBasYkw3J+y6GcnA1NtJahtJu/2MPUiUYS5izaBT5aq6G3QwI/ZtAGa2bfqZpa 7V5D7YAPiTJD7juD5lkhPRQn1zi+7BIRxMrEOu1H6DtS4UWEF6iDktVaBSwWopjkl4cG 2uZK/N18Wfnrxk5LZSZ1IA8fxOJL0/LfzobIKYLiCpKA0XSHjQc+VBQOCr6kIIskWtNf W3TV2M1KGRmWew5xGp1MhzQZ+E0ygSQl38gm/QCoymE9Wd89FreZ5NoVW7G3I3Y19O5h R3aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UGjfhTjSMIIxuXC9emCHksOYUO58P9kbGbwMm3uPS50=; b=G6BhDuKae0mMX5LWuKJLGNKu/kFbkx4EX/f6lp4c0Ch78j2FzTVy6mPq5C2Ej5h8E5 NojsajPii9ryoWq1MQl31UsmSbIMaWc/XtTeNa/Y779OyvvmeH07soueuZPfN9t0DgzH kglXRNwtwZWmkz9X7KqP1WOuD4Ls8r3FYzdCqnrZdS6xrqtIu1zNUibIiDtoeKMOHNcQ zZgCAFkAtrKOSUn5bBhLOgq/hpfMQAsskBhwoFFWgGhIeaO89Lu70uzA74lVzd8slLOA Hr3o+9B+m63Oq9gnPk+wmtghKTW6hTizqTTnCvZoZ0CZ+DfgM2IUad1p14WooWW5M3Gz 2W4Q== X-Gm-Message-State: ABUngveOxAUgxlKQVdd19zJqKZU99tYS1F5EtoqA5ynWyHqWpoKQWdKXTJg+3fgF6tm+bQ== X-Received: by 10.98.153.204 with SMTP id t73mr20014545pfk.144.1478581789316; Mon, 07 Nov 2016 21:09:49 -0800 (PST) Received: from localhost ([2601:647:4401:a2f0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id uh10sm44542791pab.5.2016.11.07.21.09.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Nov 2016 21:09:48 -0800 (PST) From: Eduardo Valentin To: Rui Zhang Cc: LKML , Linux PM , Eduardo Valentin Subject: [PATCHv2 07/49] thermal: core: move passive attr to tz->device.groups Date: Mon, 7 Nov 2016 21:08:45 -0800 Message-Id: <1478581767-7009-8-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1478581767-7009-1-git-send-email-edubezval@gmail.com> References: <1478581767-7009-1-git-send-email-edubezval@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch moves the passive attribute to tz->device.groups. Moving the passive attribute also requires a .is_visible() callback implementation for its attribute group. The logic behind the visibility of passive attribute is kept the same. We only expose the passive attribute if the thermal driver has exposed at least one passive trip point. Cc: Zhang Rui Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_core.c | 45 +++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index ec8551a..f3d9fe9 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1114,9 +1114,45 @@ static struct attribute_group thermal_zone_mode_attribute_group = { .is_visible = thermal_zone_mode_is_visible, }; +/* We expose passive only if passive trips are present */ +static struct attribute *thermal_zone_passive_attrs[] = { + &dev_attr_passive.attr, + NULL, +}; + +static umode_t thermal_zone_passive_is_visible(struct kobject *kobj, + struct attribute *attr, + int attrno) +{ + struct device *dev = container_of(kobj, struct device, kobj); + struct thermal_zone_device *tz; + enum thermal_trip_type trip_type; + int count, passive = 0; + + tz = container_of(dev, struct thermal_zone_device, device); + + for (count = 0; count < tz->trips && !passive; count++) { + tz->ops->get_trip_type(tz, count, &trip_type); + + if (trip_type == THERMAL_TRIP_PASSIVE) + passive = 1; + } + + if (!passive) + return attr->mode; + + return 0; +} + +static struct attribute_group thermal_zone_passive_attribute_group = { + .attrs = thermal_zone_passive_attrs, + .is_visible = thermal_zone_passive_is_visible, +}; + static const struct attribute_group *thermal_zone_attribute_groups[] = { &thermal_zone_attribute_group, &thermal_zone_mode_attribute_group, + &thermal_zone_passive_attribute_group, NULL }; @@ -1906,7 +1942,6 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, int trip_temp; int result; int count; - int passive = 0; struct thermal_governor *governor; if (!type || strlen(type) == 0) @@ -1967,8 +2002,6 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, for (count = 0; count < trips; count++) { if (tz->ops->get_trip_type(tz, count, &trip_type)) set_bit(count, &tz->trips_disabled); - if (trip_type == THERMAL_TRIP_PASSIVE) - passive = 1; if (tz->ops->get_trip_temp(tz, count, &trip_temp)) set_bit(count, &tz->trips_disabled); /* Check for bogus trip points */ @@ -1976,12 +2009,6 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, set_bit(count, &tz->trips_disabled); } - if (!passive) { - result = device_create_file(&tz->device, &dev_attr_passive); - if (result) - goto unregister; - } - /* Update 'this' zone's governor information */ mutex_lock(&thermal_governor_lock);