From patchwork Thu Jan 5 08:22:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alice Guo (OSS)" X-Patchwork-Id: 13089535 X-Patchwork-Delegate: daniel.lezcano@linaro.org 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 5B0DFC3DA7A for ; Thu, 5 Jan 2023 08:27:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231201AbjAEI0o (ORCPT ); Thu, 5 Jan 2023 03:26:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231285AbjAEI0G (ORCPT ); Thu, 5 Jan 2023 03:26:06 -0500 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2067.outbound.protection.outlook.com [40.107.6.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A96CA50047; Thu, 5 Jan 2023 00:24:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cEX674ADpaIICADKxAO17lPo0RF4N03f9o0YW1niojCDj08OjaNCf3Z0rJa9sGoK7H25awxuQ9c7ZUX+vmZhHr2txGwZP8f6xjxZtylEt3ecdL0KEF3oegKrdlAvHNYHU0hwq95CZga7BxeBuSccz2VVoHqWUwGw4KgwFEklyRTgCIdEz8nEP0GC8KuPrgU1ONThn3B8YfmoSczsvk8pHLPW+JG15BY6XR1r2BOUa/r3IohsOVfuHRkCsO4jlkeBjfqm3I42Hqrwcy7twmW+eG1azIu7NQmb+rGVm7TJNE31HRt866jIba4J6w16CpdHJks+WPZ8JieI2ckkE6xrBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vpQASw28zsvT4u8rGArOefZkKgG7vvLOEkQF0Gr/TgY=; b=NNVY9lxxh8lYmYMRTvpS2q+7D3MohK7amDpgdGSDk7VD2Quy6VoSsZj306d0REERJXrdJLCj28ZJMbP9lvo0NxCoUwoJbYnZB7ixCY+IcaeU3Nf3VkQ90wMrf8LWNiYkRrTphYSl12pncp4vXM/7ho03qi6Hh5eqT+Wv5SooAh2xnFdO1It9xaTrmUv9YLbXyaOPkEHY+26+VG78jFLhkl5ZvkjbHjxPQL91861Aq6+UtC7c2Bry+LNbWZNkxCv+09xrbBkqAn2eC1IrVD/zJLCriAcu5DZ0WSkcBSnZrvwJ8oJsZRuA7qwm2xf9RVmOh4dbinw+GN5DKSgfqEO2SA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vpQASw28zsvT4u8rGArOefZkKgG7vvLOEkQF0Gr/TgY=; b=RwbJ23WhdJR8H8Bmy8+9uBACShGLXdx/etM6JUqJlzlKRXrVXm2x4LAPqLEXR6RLmKUGtvwGjWZwbJrKLbO8bJfOs4/22Bxika566TSzdl3KJpVEhuZVOmROP8eEoWlJ1nKcErIa/r1tKKq1SIJK1FChP2BofsvC5u5Qjsab7A4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM6PR04MB6053.eurprd04.prod.outlook.com (2603:10a6:20b:b9::10) by AS8PR04MB8771.eurprd04.prod.outlook.com (2603:10a6:20b:42c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Thu, 5 Jan 2023 08:24:45 +0000 Received: from AM6PR04MB6053.eurprd04.prod.outlook.com ([fe80::f75a:918f:6b4c:4a00]) by AM6PR04MB6053.eurprd04.prod.outlook.com ([fe80::f75a:918f:6b4c:4a00%4]) with mapi id 15.20.5944.019; Thu, 5 Jan 2023 08:24:45 +0000 From: "Alice Guo (OSS)" To: rafael@kernel.org, daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com, aisheng.dong@nxp.com, shawnguo@kernel.org, leoyang.li@nxp.com Cc: linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/2] thermal: Add generic device cooling support Date: Thu, 5 Jan 2023 16:22:33 +0800 Message-Id: <20230105082234.16962-2-alice.guo@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230105082234.16962-1-alice.guo@oss.nxp.com> References: <20230105082234.16962-1-alice.guo@oss.nxp.com> X-ClientProxiedBy: SG2P153CA0031.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c7::18) To AM6PR04MB6053.eurprd04.prod.outlook.com (2603:10a6:20b:b9::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB6053:EE_|AS8PR04MB8771:EE_ X-MS-Office365-Filtering-Correlation-Id: 6379a957-5603-49a8-6ffc-08daeef64d67 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: smYXcyiakQUOmfCKr48kmNby9Y4q/lHAjRUw0bcX0cus7EDyPWDW7z9/g3PUdWHj+IgpiMSSpIycwJr5DwCcipFcTgZY02cnOp7HUuEMLiLhdQqXF8K/4WIhbocrrhisXgdoEnSnMvd2fHqlPuONpcLJFcK+QpRdyg473lwF4pV1ichWM8cZQxFRtRVfB0EeYKVnL/eqZrDbxmpsSw2sUiLQtzx6bVetJrd2LU+f1p6K1lUXlctyOQwleZd1jEURYQOOQ7ZY1t1AxMWXMXQufeD6eYtAAfKNRVJoEXVSRwMgKyD8vGSoPVhOxjICYyKqTShtPOMruoFY70cXexYWR7PTJB4QRLDIofW63oDxWbi19ZnqVbNvVRrY/hc/JCpmx9zN1h4WKKPr+Nvmr+7B8/T/Dkm+SnHeLyvhnMOdviVh9MHLTK9PmTN7gW5EXY4CKdQ5mP2+Fm4LQSUJklnmyIwC23Rm6D0ayXUcPH5XxjFA0eSB/b4aT88KYmTZmuKRPM9NOXBAPqVgrobfhFkRWoZZb1pppuKlK0MueVOjgxd7K46MJyga2KPCfe5KrX10zkRcGidpZbinb+BSyptQ/L3R4P7OMGBo3vKltk3z/ubQy4PNsbWi8059WaHJTQ5FVkuKSwIIWdqiOTYJHPpgY2sIlUNUu5S7i+n550SLi7AwUlpDotwzaDCBo6DXfgA/5/wDISS5fbKZLtHcDL9xdyZAtFly9brRamm9yA8MJz4nfNNF5jwReuLrFPj2Qw36 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB6053.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(136003)(366004)(39860400002)(396003)(346002)(376002)(451199015)(5660300002)(4326008)(41300700001)(316002)(8676002)(66946007)(66556008)(66476007)(8936002)(2906002)(6666004)(6506007)(52116002)(478600001)(6486002)(6512007)(186003)(26005)(86362001)(83380400001)(1076003)(2616005)(38350700002)(38100700002)(41533002)(2004002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS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dsin8KpyjnOVVIbJ5ELMhz8a1ymYa0RWfwu1R3ek8T/D3L2mSQ3rd7IlYGrkRfgp+HxlEwLa5uFGrReJ2xGoMJ95DQTLMUw+MxMTCnUMj4mBK9YCfw1Q7RCXRdu3y7VnSEgzLGqAAGyB+tgKtwOr7QUeOU48z5xbb7BpUo7zGhZtQtiYC8nJRBTAUeh2BOI/vdfclKsFWSoBwotSE9w0MysAG1h8ND0vFeO3sA5bbw9mQU01Wx5SI4y1WXpwnhppFWukIMBZhvWODuHPPgHijJ8thR2R3mrcfxF18LGGccxy8uDAvpp8kzyfhOA2LOXpv+HIS1uu4lCZQtl9jY7pytooM0bazpuuTthhFMckhRIEXkM2eplWre57T3qgJfCtYWwby/rAXemKebfbZCLRMuJYUSSthx9i2WlQFkV/IGjMOLdkHkTtHAgRVqiQH3+8TvZe/M7vMy9tHmVY7U/BePf477zafZlyfSMB1Ar6jfQmKFM+wWlMQkXqM86ITS6UMg0cjZ0KEi4fxTI4ji15QKVQxwO1rr++P2JE X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6379a957-5603-49a8-6ffc-08daeef64d67 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6053.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2023 08:24:45.6367 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4U4dYvTCGlAq8Huj8BtmxHmmODSayyWTimNRmHlFPgc1+7K7RZPs4s0pG8VfHuv3xvLKDFukDKsoebQXS0uMbw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8771 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Anson Huang To compatible with previous implementation, add generic device cooling support, each thermal zone will register a cooling device, and when temperature exceed passive trip, the device cooling driver will send out a system wide notification, each device supporting cooling will need to register device cooling and takes action when passive trip is exceeded; Signed-off-by: Anson Huang Signed-off-by: Dong Aisheng Signed-off-by: Alice Guo --- drivers/thermal/Kconfig | 7 ++ drivers/thermal/Makefile | 1 + drivers/thermal/device_cooling.c | 154 +++++++++++++++++++++++++++++++ include/linux/device_cooling.h | 46 +++++++++ 4 files changed, 208 insertions(+) create mode 100644 drivers/thermal/device_cooling.c create mode 100644 include/linux/device_cooling.h diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig index e052dae614eb..2625903b56f5 100644 --- a/drivers/thermal/Kconfig +++ b/drivers/thermal/Kconfig @@ -284,6 +284,13 @@ config K3_THERMAL This includes temperature reading functionality. +config DEVICE_THERMAL + tristate "generic device cooling support" + help + Support for device cooling. + It supports notification of crossing passive trip for devices, + devices need to do their own actions to cool down the SOC. + config MAX77620_THERMAL tristate "Temperature sensor driver for Maxim MAX77620 PMIC" depends on MFD_MAX77620 diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index 2506c6c8ca83..77c4b2e525a4 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -46,6 +46,7 @@ obj-$(CONFIG_ARMADA_THERMAL) += armada_thermal.o obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o obj-$(CONFIG_IMX_SC_THERMAL) += imx_sc_thermal.o obj-$(CONFIG_IMX8MM_THERMAL) += imx8mm_thermal.o +obj-$(CONFIG_DEVICE_THERMAL) += device_cooling.o obj-$(CONFIG_MAX77620_THERMAL) += max77620_thermal.o obj-$(CONFIG_QORIQ_THERMAL) += qoriq_thermal.o obj-$(CONFIG_DA9062_THERMAL) += da9062-thermal.o diff --git a/drivers/thermal/device_cooling.c b/drivers/thermal/device_cooling.c new file mode 100644 index 000000000000..6bd668ee545e --- /dev/null +++ b/drivers/thermal/device_cooling.c @@ -0,0 +1,154 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2013-2015 Freescale Semiconductor, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Copyright 2023 NXP + */ + +#include +#include +#include +#include + +struct devfreq_cooling_device { + int id; + struct thermal_cooling_device *cool_dev; + unsigned int devfreq_state; +}; + +static DEFINE_IDR(devfreq_idr); +static DEFINE_MUTEX(devfreq_cooling_lock); + +#define MAX_STATE 1 + +static BLOCKING_NOTIFIER_HEAD(devfreq_cooling_chain_head); + +int register_devfreq_cooling_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register( + &devfreq_cooling_chain_head, nb); +} +EXPORT_SYMBOL_GPL(register_devfreq_cooling_notifier); + +int unregister_devfreq_cooling_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister( + &devfreq_cooling_chain_head, nb); +} +EXPORT_SYMBOL_GPL(unregister_devfreq_cooling_notifier); + +static int devfreq_cooling_notifier_call_chain(unsigned long val) +{ + return (blocking_notifier_call_chain( + &devfreq_cooling_chain_head, val, NULL) + == NOTIFY_BAD) ? -EINVAL : 0; +} + +static int devfreq_set_cur_state(struct thermal_cooling_device *cdev, + unsigned long state) +{ + struct devfreq_cooling_device *devfreq_device = cdev->devdata; + int ret; + + ret = devfreq_cooling_notifier_call_chain(state); + if (ret) + return -EINVAL; + + devfreq_device->devfreq_state = state; + + return 0; +} + +static int devfreq_get_max_state(struct thermal_cooling_device *cdev, + unsigned long *state) +{ + *state = MAX_STATE; + + return 0; +} + +static int devfreq_get_cur_state(struct thermal_cooling_device *cdev, + unsigned long *state) +{ + struct devfreq_cooling_device *devfreq_device = cdev->devdata; + + *state = devfreq_device->devfreq_state; + + return 0; +} + +static const struct thermal_cooling_device_ops devfreq_cooling_ops = { + .get_max_state = devfreq_get_max_state, + .get_cur_state = devfreq_get_cur_state, + .set_cur_state = devfreq_set_cur_state, +}; + +static int get_idr(struct idr *idr, int *id) +{ + int ret; + + mutex_lock(&devfreq_cooling_lock); + ret = idr_alloc(idr, NULL, 0, 0, GFP_KERNEL); + mutex_unlock(&devfreq_cooling_lock); + if (unlikely(ret < 0)) + return ret; + *id = ret; + + return 0; +} + +static void release_idr(struct idr *idr, int id) +{ + mutex_lock(&devfreq_cooling_lock); + idr_remove(idr, id); + mutex_unlock(&devfreq_cooling_lock); +} + +struct thermal_cooling_device *devfreq_cooling_register(void) +{ + struct thermal_cooling_device *cool_dev; + struct devfreq_cooling_device *devfreq_dev = NULL; + char dev_name[THERMAL_NAME_LENGTH]; + int ret = 0; + + devfreq_dev = kzalloc(sizeof(struct devfreq_cooling_device), + GFP_KERNEL); + if (!devfreq_dev) + return ERR_PTR(-ENOMEM); + + ret = get_idr(&devfreq_idr, &devfreq_dev->id); + if (ret) { + kfree(devfreq_dev); + return ERR_PTR(-EINVAL); + } + + snprintf(dev_name, sizeof(dev_name), "thermal-devfreq-%d", + devfreq_dev->id); + + cool_dev = thermal_cooling_device_register(dev_name, devfreq_dev, + &devfreq_cooling_ops); + if (!cool_dev) { + release_idr(&devfreq_idr, devfreq_dev->id); + kfree(devfreq_dev); + return ERR_PTR(-EINVAL); + } + devfreq_dev->cool_dev = cool_dev; + devfreq_dev->devfreq_state = 0; + + return cool_dev; +} +EXPORT_SYMBOL_GPL(devfreq_cooling_register); + +void devfreq_cooling_unregister(struct thermal_cooling_device *cdev) +{ + struct devfreq_cooling_device *devfreq_dev = cdev->devdata; + + thermal_cooling_device_unregister(devfreq_dev->cool_dev); + release_idr(&devfreq_idr, devfreq_dev->id); + kfree(devfreq_dev); +} +EXPORT_SYMBOL_GPL(devfreq_cooling_unregister); diff --git a/include/linux/device_cooling.h b/include/linux/device_cooling.h new file mode 100644 index 000000000000..83b709e7c893 --- /dev/null +++ b/include/linux/device_cooling.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2013-2015 Freescale Semiconductor, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Copyright 2023 NXP + */ + +#ifndef __DEVICE_THERMAL_H__ +#define __DEVICE_THERMAL_H__ + +#include + +#ifdef CONFIG_DEVICE_THERMAL +int register_devfreq_cooling_notifier(struct notifier_block *nb); +int unregister_devfreq_cooling_notifier(struct notifier_block *nb); +struct thermal_cooling_device *devfreq_cooling_register(void); +void devfreq_cooling_unregister(struct thermal_cooling_device *cdev); +#else +static inline +int register_devfreq_cooling_notifier(struct notifier_block *nb) +{ + return 0; +} + +static inline +int unregister_devfreq_cooling_notifier(struct notifier_block *nb) +{ + return 0; +} + +static inline +struct thermal_cooling_device *devfreq_cooling_register(void) +{ + return ERR_PTR(-EINVAL); +} + +static inline +void devfreq_cooling_unregister(struct thermal_cooling_device *cdev) +{ +} +#endif +#endif /* __DEVICE_THERMAL_H__ */ From patchwork Thu Jan 5 08:22:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alice Guo (OSS)" X-Patchwork-Id: 13089536 X-Patchwork-Delegate: daniel.lezcano@linaro.org 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 CF92FC3DA7D for ; Thu, 5 Jan 2023 08:27:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231344AbjAEI0q (ORCPT ); Thu, 5 Jan 2023 03:26:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231719AbjAEI0P (ORCPT ); Thu, 5 Jan 2023 03:26:15 -0500 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2066.outbound.protection.outlook.com [40.107.6.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A16BC5007D; Thu, 5 Jan 2023 00:24:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E1NiXRNPyGgiDAe7XkLB0hQz1M2PzEr0Ecb46fnVuDhMPhw/4t3FatZLpWiAZgY3zcvpwyx4QyZhTQi0dKdcnZdiuRQA7BisVQADHeKaC4XV+cW1DW9rqQRfr/YZbpCvObZmuD0GD876BejBvMCwFtvHOFk7KIW74mk0ACCpwjdG7IQAr8uQHlP0ZckK/0qw/L7vtgzMrV4o4XcqKV62UpppehecCVMJIj6w3gm1E5fGwftwBJz3+YpcHEr1ey0IWkhFUxorG7GT68Q04FN69krqHrkQZSn7wKxXgzdDhYMkFNrA4ffBuqY6xjXU5+UgL8Ty3A3JMq0FbhTxXoLTxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0cmjDbM9CwyqBncNx8qogTYlUutQNsN6a5GlZMHDs2U=; b=YoeGG9+kQUpi9ect23lirVXJjbhDRJfRyKfgWQOwAlzHpMOJz9M8iBYVggtyEjL7Prssc9+yl0pgUFhFx+638jKCFS7ibsGwnRsOK1diLHgw77/Di6r8ku3GhCFKGeqjNNdR5NjtfeGUOOAkk8AIuRntd9L/OWgrEOZMuWdGMQapYhD2pk1ub6nZYsTvuXX46y6hf8hfjBQJaj4CV49gixZ22FUP8iUhsjJm24tyQJ/o9oVhQ0NtwB6G18QfZ3kWNWint3o10py1WQq8PM0P5+k6AKE7qXwnYDhj3+Wbv11RnJ3Uu3Qjh6jxYXDyW9cxoL911ZVqq3pS8rPmILP/Hw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0cmjDbM9CwyqBncNx8qogTYlUutQNsN6a5GlZMHDs2U=; b=cD68RAZyizo2lwPPGd1puYoi7X8v4ydVKRlWMEsIIlf7le1Fi9rSwYTeLbcUuf5d+dDdFwAIR0GpPRe4x8o/GNerZdnOZsXJ7vEnOJIxhfVQO09SdCYB2S5qlYs3riU7QG+63pgt6cGELw4v5cgt6A2Jo1PDKF2+lMOVnS9J0wE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM6PR04MB6053.eurprd04.prod.outlook.com (2603:10a6:20b:b9::10) by AS8PR04MB8771.eurprd04.prod.outlook.com (2603:10a6:20b:42c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Thu, 5 Jan 2023 08:24:51 +0000 Received: from AM6PR04MB6053.eurprd04.prod.outlook.com ([fe80::f75a:918f:6b4c:4a00]) by AM6PR04MB6053.eurprd04.prod.outlook.com ([fe80::f75a:918f:6b4c:4a00%4]) with mapi id 15.20.5944.019; Thu, 5 Jan 2023 08:24:51 +0000 From: "Alice Guo (OSS)" To: rafael@kernel.org, daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com, aisheng.dong@nxp.com, shawnguo@kernel.org, leoyang.li@nxp.com Cc: linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/2] thermal: qoriq: Add device cooling support Date: Thu, 5 Jan 2023 16:22:34 +0800 Message-Id: <20230105082234.16962-3-alice.guo@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230105082234.16962-1-alice.guo@oss.nxp.com> References: <20230105082234.16962-1-alice.guo@oss.nxp.com> X-ClientProxiedBy: SG2P153CA0031.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c7::18) To AM6PR04MB6053.eurprd04.prod.outlook.com (2603:10a6:20b:b9::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB6053:EE_|AS8PR04MB8771:EE_ X-MS-Office365-Filtering-Correlation-Id: 36f91bc9-655f-4200-fc03-08daeef650cf X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QVkFMDI7kRxDmSOYlpuUKmPXtOX30mcpQs/SpVqA+dUaYRHocqC9VIEy8jbHqhMuCeS6mTZHDymQ1S1nufrmUPWzon6l0eSfCqow/RVSLP7mZMXy79zk0xGq0zRyn1uEBPFgzq6NSEy3Vq9Vjki3PQCiW5BWmFj2rez6RLVIecMq7MF/OpXhWDOvhovOUvEbBVHCp2lCriM3KPmnWpFQgPniKUN/f8hPy7Y/gpMaRR/9BItI7GQr8l9g87pe0l5JbGGlIyRxhSepFmyVT0sbLt00tDNsraFQZHsTz2oEslkcXOaArk62j3Jhe2xH/qUq01X+JlbxxnvB/4WX+19P+d2aTrB/wkr0h7NKHszKLjnSHdNldi3V/PaBquTHqa5aRzsLspKr0oqhL4ukOWAcHf3Bm77Dwff9OCXxSlARupbuq73YX9HW2r8oXCqI0f+KVs83mnVx82lxGop5Qq/N/idR73AcMhTBGizE5TpvAgdlGBYLktVmZZuH82t5Gu1iIrB2hJhc8meI7zms4oXbH4VHWQojCOcsn9x02wHOqOTEhxgRvbB9cfgVWlyvyRIXpr2N6SYPZ/f08uc+MrdovSrPtev0Ay9YeUzxJRf3W7lV46OHunpXXBfFLwWiKlQ/ISyTTQnyvENLGidzXyC2WEFCJlYfRrD4RPfZGmGko+La7CQhkXxBmuk13j2nSGrBbP3nlb73HRyECezz4fGqpA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB6053.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(136003)(366004)(39860400002)(396003)(346002)(376002)(451199015)(5660300002)(4326008)(41300700001)(316002)(8676002)(66946007)(66556008)(66476007)(8936002)(2906002)(6666004)(6506007)(52116002)(478600001)(6486002)(6512007)(186003)(26005)(86362001)(83380400001)(1076003)(2616005)(38350700002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uAab30O5oZCFbyCQN29ycvPFCCQnpz5yesK12WwNMtxgTMaFexAN+ynvIn9jak5w8MAHjG+YURn0f/bib4UqsVx6Tauwodj22BslOIobVJbrFZOOJEOFuHkSVyOx2dCwuTkOUZKm+HzqPsIi3g7732xBN7f9id6a4dzGFBFHf8Hjb05zNwBndwdZbK+coGyBPaY9QWHWF4EZ5e6LL8Y3ZI7OfTcJ4EdwqPr576zsLZgFvo34BGguUtKldrrkbAQzBaAH88z1GXQHHXyC1XlIjwMvh9GCe96BJZ6PWdxYG/d8AxxbtbNJcJXGOmfXOCZ/Z7F+V955hvFcXScw8+IxVjptBtZ2Gevj8zb35w1/VPXd2S2jIdfm+vasTu/Aa2qj93ZwKhAFLzgKtvKQ95ScuDvs0JIYQuZQgKEnb9F+yQDNkMhyRgJiiVUFF5UmbKTI+dd+eOBlOyV9Cg35h4Pdx3Rx5BWB+Bdgh1rt2B8Hd8hlbA3wgDpeqYrrYlQ2902Ar7VwTBxdE2Z7Zwt2rU8BmM+U4PJWCai4rlPlu6tqBw9geDj2gz38GdQoXlwkkzJYiD0twVu8sqJHI2VbURFm0WC8HWJKZzsPMdZnU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Tenant-AuthSource: AM6PR04MB6053.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2023 08:24:51.3238 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wXA2qqWWIb8CODQcNIp34p8kd4rsjX7/be4uqPlPYjY2vHGNTrJUIzyUXplRmP0FFg7Ko8cbQa6j9JLlSvufbg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8771 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Anson Huang Register device cooling for first thermal zone manually, when temperature exceeds passive trip, system wide cooling notification will be triggered. Signed-off-by: Anson Huang Signed-off-by: Alice Guo Reviewed-by: Jacky Bai --- drivers/thermal/qoriq_thermal.c | 83 ++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index d111e218f362..3c21b2d184eb 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -3,6 +3,7 @@ // Copyright 2016 Freescale Semiconductor, Inc. #include +#include #include #include #include @@ -27,6 +28,7 @@ #define TMSARA_V2 0xe #define TMU_VER1 0x1 #define TMU_VER2 0x2 +#define TMU_TEMP_PASSIVE_COOL_DELTA 10000 #define REGS_TMR 0x000 /* Mode Register */ #define TMR_DISABLE 0x0 @@ -68,6 +70,10 @@ */ struct qoriq_sensor { int id; + struct thermal_zone_device *tzd; + int temp_passive; + int temp_critical; + struct thermal_cooling_device *cdev; }; struct qoriq_tmu_data { @@ -77,6 +83,12 @@ struct qoriq_tmu_data { struct qoriq_sensor sensor[SITES_MAX]; }; +enum tmu_trip { + TMU_TRIP_PASSIVE, + TMU_TRIP_CRITICAL, + TMU_TRIP_NUM, +}; + static struct qoriq_tmu_data *qoriq_sensor_to_data(struct qoriq_sensor *s) { return container_of(s, struct qoriq_tmu_data, sensor[s->id]); @@ -122,14 +134,53 @@ static int tmu_get_temp(struct thermal_zone_device *tz, int *temp) return 0; } +static int tmu_get_trend(struct thermal_zone_device *tz, int trip, + enum thermal_trend *trend) + +{ + struct qoriq_sensor *qsensor = tz->devdata; + int trip_temp; + + if (!qsensor->tzd) + return 0; + + trip_temp = (trip == TMU_TRIP_PASSIVE) ? qsensor->temp_passive : + qsensor->temp_critical; + + if (qsensor->tzd->temperature >= + (trip_temp - TMU_TEMP_PASSIVE_COOL_DELTA)) + *trend = THERMAL_TREND_RAISING; + else + *trend = THERMAL_TREND_DROPPING; + + return 0; +} + +static int tmu_set_trip_temp(struct thermal_zone_device *tz, int trip, + int temp) +{ + struct qoriq_sensor *qsensor = tz->devdata; + + if (trip == TMU_TRIP_CRITICAL) + qsensor->temp_critical = temp; + + if (trip == TMU_TRIP_PASSIVE) + qsensor->temp_passive = temp; + + return 0; +} + static const struct thermal_zone_device_ops tmu_tz_ops = { .get_temp = tmu_get_temp, + .get_trend = tmu_get_trend, + .set_trip_temp = tmu_set_trip_temp, }; static int qoriq_tmu_register_tmu_zone(struct device *dev, struct qoriq_tmu_data *qdata) { int id; + const struct thermal_trip *trip; if (qdata->ver == TMU_VER1) { regmap_write(qdata->regmap, REGS_TMR, @@ -158,10 +209,40 @@ static int qoriq_tmu_register_tmu_zone(struct device *dev, return ret; } + sensor->tzd = tzd; + if (devm_thermal_add_hwmon_sysfs(tzd)) dev_warn(dev, "Failed to add hwmon sysfs attributes\n"); - + /* first thermal zone takes care of system-wide device cooling */ + if (id == 0) { + sensor->cdev = devfreq_cooling_register(); + if (IS_ERR(sensor->cdev)) { + ret = PTR_ERR(sensor->cdev); + pr_err("failed to register devfreq cooling device: %d\n", + ret); + return ret; + } + + ret = thermal_zone_bind_cooling_device(sensor->tzd, + TMU_TRIP_PASSIVE, + sensor->cdev, + THERMAL_NO_LIMIT, + THERMAL_NO_LIMIT, + THERMAL_WEIGHT_DEFAULT); + if (ret) { + pr_err("binding zone %s with cdev %s failed:%d\n", + sensor->tzd->type, + sensor->cdev->type, + ret); + devfreq_cooling_unregister(sensor->cdev); + return ret; + } + + trip = of_thermal_get_trip_points(sensor->tzd); + sensor->temp_passive = trip[0].temperature; + sensor->temp_critical = trip[1].temperature; + } } return 0;