Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp953518pxp; Wed, 16 Mar 2022 22:29:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaMiH+imi4946CEz2tucQHQcSrqx03ToFRqRKDnnWW9NP4kNVeJqd9mDh9jP0PG8r5PMIy X-Received: by 2002:a17:903:32c8:b0:150:1189:c862 with SMTP id i8-20020a17090332c800b001501189c862mr2935340plr.134.1647494983420; Wed, 16 Mar 2022 22:29:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647494983; cv=none; d=google.com; s=arc-20160816; b=vbWZB9Nr1JCDS4SAjdnDLBVONgzv3n93tSCXxRJ9C8l09nmg7GCrjg7mRPUu5z70yQ S0AtYzve7RF6b2ZFt2NNbhGTH1Y5i3n1mZpHAYg1X2O20YrWn6yU0XvKd8zqOcgnI9r0 dih2N0PwWbDBtd2I60QzM9BcR2fQ7k80YgN1ALcXHr8lsZlriaD0AyqU5eM6g6VcoXT+ szQlTOuKGYHKz+1TXz/r+JIUOh/57oidNh7ie+DmGtgrlMBqWZ7n/RaTnZA8CAyVC+tn yI41RjejSnoqo/DJMD3FMGmbCPHwCiXB+aJq2VWjqA1LSNOJX1RAuhUXLbYxDatdoQjO RZxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=YuBwkb6Bm2dJygmGjKNMzcQ7V38KULA7oyW33icX/Xs=; b=gkEqYDgLlRvDi8BZVm2GzsCV9+T7Ey1HKeyg8+OWi1sCWD14u+ILZcma8gWILIjnEs ZLrE8/QoPmvUkaPEnQQWJtZlNhNvoZh+uVJj8sSPoE0oc1O9x6wfKFua8eOpt2qfyezi Jbr8TrNUitpH60Gkhq996QkzZOdTaYyyB0OnTqRmVqF98UgLUdOWw2JneyuFPaGa0O/u C3ogD+e74EhQCQ4ywOYG04Jkw5og6hYPVM3ZybbC7HTBDvmA3WLr+Q1qao6rAlBK5AIx qNjH/pdOkU27ddggDkPeALGR7xEeOmfE0nbVLQY34meWCRLjNRDUgFcv49jBB3YsoaeE aPaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@squareup.com header.s=google header.b=f2Pkm0+U; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=squareup.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id b19-20020a656693000000b003816043f119si1068571pgw.782.2022.03.16.22.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 22:29:43 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@squareup.com header.s=google header.b=f2Pkm0+U; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=squareup.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 520492359D3; Wed, 16 Mar 2022 21:31:05 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351182AbiCPVLx (ORCPT + 99 others); Wed, 16 Mar 2022 17:11:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358098AbiCPVLo (ORCPT ); Wed, 16 Mar 2022 17:11:44 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 557A843394 for ; Wed, 16 Mar 2022 14:10:28 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id m11-20020a17090a7f8b00b001beef6143a8so3654189pjl.4 for ; Wed, 16 Mar 2022 14:10:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=squareup.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YuBwkb6Bm2dJygmGjKNMzcQ7V38KULA7oyW33icX/Xs=; b=f2Pkm0+UTgAdPrRxaAeSDHe2Wp9gfhaR7VrH65WjuMJTB8JJEn4ensEPYp3kvebZ/1 Iuzewo74EBgaO5auuBP4euHPDcWXtXahB0WhOJ2A6uDo/KeSm6EuFGApxjRLPpwtxYvH k1x1C2KOtBGn46T71xGS0u+hwDMvUxQXmv1XI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YuBwkb6Bm2dJygmGjKNMzcQ7V38KULA7oyW33icX/Xs=; b=w0t6iFZzwp6IHmA/2RUuSu7hrqb1FSX5mub7nHldd/FuVfWT+y+p+yEyUtMWHquurc 6DppeWzI9JkK0OhaN+ZzCZ7geq3OX5fnimOHJGHTTJRRd+w/3tl6T7jiRHjLR2Xev4RM DBnbaIkB3ApEvAVzHkaOicRzqopas6HQ+Q2WWCm/bLZb7+jgvfVg/lJYgaVBbuHsCru5 FQv4AOxOrzUOMrDU19+C2xIdoiAkGImFdhZAksnW3+u7CtdZqB1PNfAXNpnARcnX7wla e8sHhjOVgbjzW9pzYdlOqPWcpjUZXsUZs3mhAWYqMgUeDatcO2EdHGmlABkYeINfejfP slsw== X-Gm-Message-State: AOAM530c8/k8KdgF2LJ6I7YaayizDHxJFb2JstTfb0IRpzlPyoxhlc+H ECvvXhA4bCWLwt8AQVX2dY6D3Q== X-Received: by 2002:a17:902:e848:b0:151:e3a5:b609 with SMTP id t8-20020a170902e84800b00151e3a5b609mr1440981plg.137.1647465027663; Wed, 16 Mar 2022 14:10:27 -0700 (PDT) Received: from localhost ([135.84.132.250]) by smtp.gmail.com with ESMTPSA id q9-20020a056a00088900b004e03b051040sm4476450pfj.112.2022.03.16.14.10.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Mar 2022 14:10:27 -0700 (PDT) From: Benjamin Li To: Daniel Lezcano , Amit Kucheria , Thara Gopinath Cc: Bjorn Andersson , Zac Crosby , Benjamin Li , Andy Gross , "Rafael J. Wysocki" , Zhang Rui , linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] thermal: thermal_of: add pass-through change_mode to ops struct Date: Wed, 16 Mar 2022 14:09:44 -0700 Message-Id: <20220316210946.6935-2-benl@squareup.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220316210946.6935-1-benl@squareup.com> References: <20220316210946.6935-1-benl@squareup.com> X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add an optional change_mode method to the ops struct, allowing thermal_of- based drivers to properly implement disabling of sensors/IRQs. Previously thermal_core would just disable the polling timer when a zone is disabled, as thermal_of drivers could not provide a change_mode implementation. This meant thermal_of drivers supporting interrupt-based updates had to keep sensors/IRQs enabled at all times, and needed to resort to reading tzd->mode in their IRQ handler or get_temp implementation to actually stop updating. This is a waste of resources in IRQ handlers to ignore updates, and for sensors that can power down it's a waste of power. Signed-off-by: Benjamin Li --- drivers/thermal/thermal_of.c | 14 ++++++++++++++ include/linux/thermal.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 9233f7e74454..a69ec39780a7 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -106,6 +106,17 @@ static int of_thermal_set_trips(struct thermal_zone_device *tz, return data->ops->set_trips(data->sensor_data, low, high); } +static int of_thermal_change_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ + struct __thermal_zone *data = tz->devdata; + + if (!data->ops || !data->ops->change_mode) + return -EINVAL; + + return data->ops->change_mode(data->sensor_data, mode); +} + /** * of_thermal_get_ntrips - function to export number of available trip * points. @@ -405,6 +416,9 @@ thermal_zone_of_add_sensor(struct device_node *zone, if (ops->set_trips) tzd->ops->set_trips = of_thermal_set_trips; + if (ops->change_mode) + tzd->ops->change_mode = of_thermal_change_mode; + if (ops->set_emul_temp) tzd->ops->set_emul_temp = of_thermal_set_emul_temp; diff --git a/include/linux/thermal.h b/include/linux/thermal.h index c314893970b3..469a1664f1ed 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -295,6 +295,7 @@ struct thermal_zone_params { * @set_trips: a pointer to a function that sets a temperature window. When * this window is left the driver must inform the thermal core via * thermal_zone_device_update. + * @change_mode: a pointer to a function that enables/disables reporting. * @set_emul_temp: a pointer to a function that sets sensor emulated * temperature. * @set_trip_temp: a pointer to a function that sets the trip temperature on @@ -304,6 +305,7 @@ struct thermal_zone_of_device_ops { int (*get_temp)(void *, int *); int (*get_trend)(void *, int, enum thermal_trend *); int (*set_trips)(void *, int, int); + int (*change_mode)(void *, enum thermal_device_mode); int (*set_emul_temp)(void *, int); int (*set_trip_temp)(void *, int, int); }; -- 2.17.1