From patchwork Wed Mar 16 21:09:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Li X-Patchwork-Id: 12783197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63EE2C433EF for ; Wed, 16 Mar 2022 21:10:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358131AbiCPVLs (ORCPT ); Wed, 16 Mar 2022 17:11:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358104AbiCPVLq (ORCPT ); Wed, 16 Mar 2022 17:11:46 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 558164D629 for ; Wed, 16 Mar 2022 14:10:28 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id m11-20020a17090a7f8b00b001beef6143a8so3654187pjl.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=yIaGcOZKX8BaXk6ExYqyNLktbVIOlWDgz3Cl3qWMhPct0jqnb6XQmdz4tqJeNGK3pG bQRLqRHI3zogI83vpKE8FbigalRnnh6LNNpiueNBUMEcnPWMrezPSNuC3Ka8Dwc7fSYf 8I8+kr4D1e4enAEM3UDA+Qdk51ozWt/TWsAPe2PDH0RgSk4+dwl1sAO1ioBaeODTKVX7 zX1aI/eTtZD+ffcKDvOQ0+r9mB7xp4jjoC4akWgkGUoYlknkXZj962Pydmu29ge7Mnjo RyoEZN0EaOgW3tDMWlVNbdcC0xI4IdHFUzJg9J9iSLMD/oiOFl4dx/TKq4r/IQhaaWNb QkCw== X-Gm-Message-State: AOAM532yjKtTHMIM4SidjgOLzYx4dgdPYRNSs5sGtAkWlXxy0w2He4LU kn0I8kzApx3TZwKXqmTZRgYe3A== X-Google-Smtp-Source: ABdhPJxh5UhmNk4YCcGt0E/+WtCoAz7hr3beaRxtARhLtP83XT+fe8dwt5IvhPsE65sdrXs7b6QV8g== 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> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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); };