From patchwork Tue Feb 16 05:05:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "J, KEERTHY" X-Patchwork-Id: 8321011 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 63BA3C02AA for ; Tue, 16 Feb 2016 05:07:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 60B492025A for ; Tue, 16 Feb 2016 05:07:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 61AC6202F2 for ; Tue, 16 Feb 2016 05:06:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753359AbcBPFG4 (ORCPT ); Tue, 16 Feb 2016 00:06:56 -0500 Received: from comal.ext.ti.com ([198.47.26.152]:42135 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753356AbcBPFGy (ORCPT ); Tue, 16 Feb 2016 00:06:54 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id u1G56qkO007170; Mon, 15 Feb 2016 23:06:52 -0600 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id u1G56qH1025435; Mon, 15 Feb 2016 23:06:52 -0600 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.224.2; Mon, 15 Feb 2016 23:06:52 -0600 Received: from ula0393675.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id u1G56niq028552; Mon, 15 Feb 2016 23:06:50 -0600 From: Keerthy To: CC: , , , , Subject: [PATCH] thermal: omap-thermal: Add notify function to thermal_zone_device_ops Date: Tue, 16 Feb 2016 10:35:45 +0530 Message-ID: <1455599145-5656-1-git-send-email-j-keerthy@ti.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP notify function is used to notify when some temperature thresholds are crossed. In case we get notified for a critical trip point then schedule an emergency shutdown function to backup orderly_poweroff failures. orderly_poweroff is triggered when a graceful shutdown of system is desired. This may be used in many critical states of the kernel such as when subsystems detects conditions such as critical temperature conditions. However, in certain conditions in system boot up sequences like those in the middle of driver probes being initiated, userspace will be unable to power off the system in a clean manner and leaves the system in a critical state. In cases like these, the /sbin/poweroff will return success (having forked off to attempt powering off the system. However, the system overall will fail to completely poweroff (since other modules will be probed) and the system is still functional with no userspace (since that would have shut itself off). However, there is no clean way of detecting such failure of userspace powering off the system. In such scenarios, it is necessary for a backup workqueue to be able to force a shutdown of the system when orderly shutdown is not successful after a configurable time period. Signed-off-by: Keerthy --- The previous discussion: https://lkml.org/lkml/2016/1/28/989 Making use of the notify ops to schedule a backup thermal shutdown. drivers/thermal/ti-soc-thermal/Kconfig | 13 +++++++ drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 43 ++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/drivers/thermal/ti-soc-thermal/Kconfig b/drivers/thermal/ti-soc-thermal/Kconfig index ea8283f..b4b9668 100644 --- a/drivers/thermal/ti-soc-thermal/Kconfig +++ b/drivers/thermal/ti-soc-thermal/Kconfig @@ -71,3 +71,16 @@ config DRA752_THERMAL This includes alert interrupts generation and also the TSHUT support. + +config TI_THERMAL_EMERGENCY_POWEROFF_DELAY_MS + int "Emergency poweroff delay in milli-seconds" + depends on TI_SOC_THERMAL + default 0 + help + The number of milliseconds to delay before emergency + poweroff kicks in. The delay should be carefully profiled + so as to give adequate time for orderly_poweroff. In case + of failure of an orderly_poweroff the emergency poweroff + kicks in after the delay has elapsed and shuts down the system. + + If set to 0 poweroff will happen immediately. diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c index b213a12..d48eb5b1 100644 --- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c +++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "ti-thermal.h" #include "ti-bandgap.h" @@ -286,6 +287,47 @@ static int ti_thermal_get_crit_temp(struct thermal_zone_device *thermal, return ti_thermal_get_trip_temp(thermal, OMAP_TRIP_NUMBER - 1, temp); } +/** + * emergency_poweroff_func - emergency poweroff work after a known delay + * @work: work_struct associated with the emergency poweroff function + * + * This function is called in very critical situations to force + * a kernel poweroff after a configurable timeout value. + */ +static void emergency_poweroff_func(struct work_struct *work) +{ + pr_warn("Attempting kernel_power_off\n"); + kernel_power_off(); + + pr_warn("kernel_power_off has failed! Attempting emergency_restart\n"); + emergency_restart(); +} + +static DECLARE_DELAYED_WORK(emergency_poweroff_work, emergency_poweroff_func); + +/** + * emergency_poweroff - Trigger an emergency system poweroff + * + * This may be called from any critical situation to trigger a system shutdown + * after a known period of time. By default the delay is 0 millisecond + */ +void ti_thermal_emergency_poweroff(void) +{ + schedule_delayed_work(&emergency_poweroff_work, + msecs_to_jiffies(CONFIG_TI_THERMAL_EMERGENCY_POWEROFF_DELAY_MS)); +} + +static int ti_thermal_notify(struct thermal_zone_device *thermal, int temp, + enum thermal_trip_type type) +{ + if (type == THERMAL_TRIP_CRITICAL) { + pr_warn("critical temperature %d reached", temp); + ti_thermal_emergency_poweroff(); + } + + return 0; +} + static const struct thermal_zone_of_device_ops ti_of_thermal_ops = { .get_temp = __ti_thermal_get_temp, .get_trend = __ti_thermal_get_trend, @@ -301,6 +343,7 @@ static struct thermal_zone_device_ops ti_thermal_ops = { .get_trip_type = ti_thermal_get_trip_type, .get_trip_temp = ti_thermal_get_trip_temp, .get_crit_temp = ti_thermal_get_crit_temp, + .notify = ti_thermal_notify, }; static struct ti_thermal_data