From patchwork Mon Sep 4 19:56:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111603 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp1935072qge; Mon, 4 Sep 2017 12:57:37 -0700 (PDT) X-Received: by 10.84.133.111 with SMTP id 102mr1819759plf.346.1504555057388; Mon, 04 Sep 2017 12:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504555057; cv=none; d=google.com; s=arc-20160816; b=jsVR3KMaXAUJ6mp6xfG6BI9SlBl/ATbnbeEQK4grT5J4P7jzDuh6VIYXEuBfqSyl44 THfUlUxODr6qzRXgGq70bFFKxcNbolSAT+YrCl7tvIhr8fQzHlIDLz3lpFx13g8oz/jZ nDStYdTfso3ATF/7JJIeO//Dtek/aOWCSZUo/8JfLW3sO1J+VUaINyhZrrutAx6REX8v K1dfs1akDjVxiQAZnyHREPSIIMIPmn0KIHCLBWhK4uPsOuJnV8gow1VAtAz0WYcyGden veTgc0GkhPyMCcIu/rhxodEtzDn1JW5UWW8NmBBzuEU8ak5Jp89IWsZEAOjFAbfcxuMe TwVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=9mRtfZLSLgWOn6G7+Ddy+JCYVSrWjeU3WoTVo6SXWdw=; b=TWDLMXXVDB9DGI3qUedjKOn5We9eICw1zFPPQizwm40NUzCTjPWij+caYGjyouz4/W 9irrhmxA3yrWnmJ3QaBQJG8TpeSgQHRvnDQIZi8uUwPTDV5awlWNqZNz/EBy0D/HrPOL P7onbHO/K8PMebOTMKciHpAbKnB0un8XedwXIbpNKadskylWR0Wn+6E2dl+rOkrd3ElW tOav4rs2atScv4bdd+qbV8n2KeniyInjzssVAlxWy+u0ki6p+PHCSWc8nY+d9URNmnhi 8VT2CKvx94cu7BKw24tC5duyOupfC8kBkRFmUSaMuIILgQkAwknUmbpEdXaS2D2IrO01 aZ9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EqahFVVL; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b71si4260418pli.163.2017.09.04.12.57.36; Mon, 04 Sep 2017 12:57:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EqahFVVL; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753973AbdIDT5e (ORCPT + 12 others); Mon, 4 Sep 2017 15:57:34 -0400 Received: from mail-wr0-f178.google.com ([209.85.128.178]:35500 "EHLO mail-wr0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753953AbdIDT5e (ORCPT ); Mon, 4 Sep 2017 15:57:34 -0400 Received: by mail-wr0-f178.google.com with SMTP id y15so4042639wrc.2 for ; Mon, 04 Sep 2017 12:57:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=9mRtfZLSLgWOn6G7+Ddy+JCYVSrWjeU3WoTVo6SXWdw=; b=EqahFVVL0sg9sgjoKF2Kv+ULtobcqEyu8J7NEsswUL5pVU6GA45dLNkhqfXKhxu+Dk UXgLcqHSHZvBJX2H/7JBqLK+s9F1vZ0AwihHiHb4EJ2s5mnY+HNO6MJSD5ZMrZt6RTKU os/uweg+dC3MHh3SA00n7dQjGVsZ9uk9lSm4Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=9mRtfZLSLgWOn6G7+Ddy+JCYVSrWjeU3WoTVo6SXWdw=; b=tYDgh7ZceA2SiBCDwb0JgvmZsFVb0N+A0Ku2/GP9HJstmSdAq+6zZQzb4Ic+gXGBzw YK3hCSjbol5V0VNQiVar6Wj8Tr4lC7bYEyHN2XXOzI/0meZdhXIRb7SNbb3qg3jIXZPb LZOQ+mhW3FYODrbflkG150hkDnmIGBeA6qTLaTZ+Zyzkq2GPcSmqONbwKU2H1oqu6p6a 8zBLS2Q5edEZsOZvQ3g+iDf832jeDTrb/16Ij2P1jND6ua5Jl8pwQkQoxRczLBI8SMdI fTaZbN0DgiroO8neZmnz1zrfE/2sq6T5P6D48RUvQQs7bQOKoF5mv+XwqcoV4clBCNIO DijA== X-Gm-Message-State: AHPjjUhSuMqJboeXbHHKjgM334C+ChPjNHbHuy73UmARp0lY4vtbY/7C szbn98+hwRePYaEA X-Google-Smtp-Source: ADKCNb4/UT4uSTMMuMQRFONQ1NeAIUfgGUq8C/xmmNrJ5zv3Tm+8NsXShscUrpaCmj6g4cQOHrSjsw== X-Received: by 10.223.184.246 with SMTP id c51mr1007414wrg.310.1504555052913; Mon, 04 Sep 2017 12:57:32 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:f567:7c41:be9d:9286]) by smtp.gmail.com with ESMTPSA id 23sm10798976wrt.44.2017.09.04.12.57.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 12:57:32 -0700 (PDT) From: Daniel Lezcano To: rui.zhang@intel.com, edubezval@gmail.com Cc: daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, kevin.wangtao@linaro.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 01/13] thermal/drivers/hisi: Fix missing interrupt enablement Date: Mon, 4 Sep 2017 21:56:00 +0200 Message-Id: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The interrupt for the temperature threshold is not enabled at the end of the probe function, enable it after the setup is complete. On the other side, the irq_enabled is not correctly set as we are checking if the interrupt is masked where 'yes' means irq_enabled=false. irq_get_irqchip_state(data->irq, IRQCHIP_STATE_MASKED, &data->irq_enabled); As we are always enabling the interrupt, it is pointless to check if the interrupt is masked or not, just set irq_enabled to 'true'. Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan Tested-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index bd3572c..8381696 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -345,8 +345,7 @@ static int hisi_thermal_probe(struct platform_device *pdev) } hisi_thermal_enable_bind_irq_sensor(data); - irq_get_irqchip_state(data->irq, IRQCHIP_STATE_MASKED, - &data->irq_enabled); + data->irq_enabled = true; for (i = 0; i < HISI_MAX_SENSORS; ++i) { ret = hisi_thermal_register_sensor(pdev, data, @@ -358,6 +357,8 @@ static int hisi_thermal_probe(struct platform_device *pdev) hisi_thermal_toggle_sensor(&data->sensors[i], true); } + enable_irq(data->irq); + return 0; } From patchwork Mon Sep 4 19:56:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111615 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp1937351qge; Mon, 4 Sep 2017 13:00:22 -0700 (PDT) X-Received: by 10.84.235.203 with SMTP id m11mr1749581plt.28.1504555222616; Mon, 04 Sep 2017 13:00:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504555222; cv=none; d=google.com; s=arc-20160816; b=K+lhTOZoIDMeqdwd6hQHyzWDAoRRmbKpYFLgqz3x2XH9+TQnROtC9/eEptcuWWMGTE Dgup4ygsLMq6vhLFbbHzK5/KPT16Sj6VZMFwIieXnlGPRMjFm3hYqntUCQlRZDgvOVnn jhwQ9LqkOoBQSr0f53s/3WHX7DwHk8L8Se12sPdpUUf7IkduseiHhELrqpS6EtxrhMax pSEfVmyZO/sDKv8LAgBbnVHXUk5qD5KlyPE2pH0nI0M/FtmfBhHwlyyHYK1vnCROxtJd i4jmaW5ayGh3hI3zbcV2ROuhMajysYj5CQtixbxlkHxU2kXhH4QyfisO9MRFAAU4oaUv YHYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=5I8mkUE7/qyP/tez8VZpxc30jNELR4h693da5NkRK2Q=; b=Rr5hhuuiwG2/1C3gFse0t7BjQxSR0OxGoyb19hkm6nd/isl8Kk0mSamcYD1NwSIjwz uIA/3aSlLMQzBY7Rp8/F5O+m0vXPXxEbKBRkPOuAfNwXccbJrOvt6llZQ63DXyZ2MzB0 XLL8UYgV7Zsh1Cd1eiB3pIRDYI6c3v4S/PqwXxY5p+y/ygcABXkmHsgmJqXpg9C0lmXH c2gqCxntHegY9ZVNwOgzgPLXzKyfvyz+zElPx9qaz5g4fUNKHZF3sZl1H9yFvkdUOT6k ZGZ1QQK9xfOwX9PHpR4DwEWOzorU8c+008LXmL2poOVudTf/w6e04JbWXNQL/QQE0s5Y 1xnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MZJKN8/N; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k30si5071pgn.341.2017.09.04.13.00.22; Mon, 04 Sep 2017 13:00:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MZJKN8/N; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753977AbdIDUAU (ORCPT + 12 others); Mon, 4 Sep 2017 16:00:20 -0400 Received: from mail-wr0-f179.google.com ([209.85.128.179]:35503 "EHLO mail-wr0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753953AbdIDT5f (ORCPT ); Mon, 4 Sep 2017 15:57:35 -0400 Received: by mail-wr0-f179.google.com with SMTP id y15so4042763wrc.2 for ; Mon, 04 Sep 2017 12:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5I8mkUE7/qyP/tez8VZpxc30jNELR4h693da5NkRK2Q=; b=MZJKN8/NOLhLWJBnDSVRRW0JuXRJQV5scI26+4/EEGjyIg0Ee/YlYa+KqJHp7iHyRG V6beCD8BX4c0fVkU4W/0HKwPHhBsuwTIUOSz5MTmRKCnmzWRE1HfJzMIoY4D5ZA/VZcW SG0QxKzQk7cvzJ44bz9ZBNZL6AJtXib3TjKfE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5I8mkUE7/qyP/tez8VZpxc30jNELR4h693da5NkRK2Q=; b=OFCI+XRRdbkyo93rWiYVASab2ZGAInUudjMUjTchdOqSd/kYTaEypscntUtG1ldmmF iGdU2G+Amt2pZYf0GtiZOEs4HCxCpbEaw1NNPHSLK9hTNBEEtwllhz63XlHkVwuJSxYo DWfykJ+fe+8nr4qRJ5W7a6Yzz8WHMYWesWDR5kmYVW5b/o+nysm9gHQwFqn+ORGSfOOa vfhZEJFoSuAtlu+AVU5d7W+N6FYGAQc/n6JRaGAbxo876nedFdmF/eaTEgNR/wvYgcYs +hGCzwyf7dWYPU7QyJliLPvjamFGSly/qla1crK1oQ8490ZPfqPkEJPk4FTCUGiccp/c AYPw== X-Gm-Message-State: AHPjjUjare9sdgrtBvWTbk83dSses/dFu67vSRU4HQHda7m+5teg+C74 qZYT5CcBI1AItH42 X-Google-Smtp-Source: ADKCNb7w/buJ4nc+DhsCUKHzTCBFdaaNP11Y7gsBIM41Old6hCFs4vcSJzXKBPVrsn1STdfZdlqrIw== X-Received: by 10.223.154.81 with SMTP id z75mr906771wrb.124.1504555054500; Mon, 04 Sep 2017 12:57:34 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:f567:7c41:be9d:9286]) by smtp.gmail.com with ESMTPSA id 23sm10798976wrt.44.2017.09.04.12.57.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 12:57:33 -0700 (PDT) From: Daniel Lezcano To: rui.zhang@intel.com, edubezval@gmail.com Cc: daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, kevin.wangtao@linaro.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 02/13] thermal/drivers/hisi: Remove the multiple sensors support Date: Mon, 4 Sep 2017 21:56:01 +0200 Message-Id: <1504554972-2624-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> References: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org By essence, the tsensor does not really support multiple sensor at the same time. It allows to set a sensor and use it to get the temperature, another sensor could be switched but with a delay of 3-5ms. It is difficult to read simultaneously several sensors without a big delay. Today, just one sensor is used, it is not necessary to deal with multiple sensors in the code. Remove them and if it is needed in the future add them on top of a code which will be clean up in the meantime. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 75 +++++++++++------------------------------- 1 file changed, 19 insertions(+), 56 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 8381696..725d0d4 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -39,6 +39,7 @@ #define HISI_TEMP_RESET (100000) #define HISI_MAX_SENSORS 4 +#define HISI_DEFAULT_SENSOR 2 struct hisi_thermal_sensor { struct hisi_thermal_data *thermal; @@ -53,9 +54,8 @@ struct hisi_thermal_data { struct mutex thermal_lock; /* protects register data */ struct platform_device *pdev; struct clk *clk; - struct hisi_thermal_sensor sensors[HISI_MAX_SENSORS]; - - int irq, irq_bind_sensor; + struct hisi_thermal_sensor sensors; + int irq; bool irq_enabled; void __iomem *regs; @@ -113,7 +113,7 @@ static void hisi_thermal_enable_bind_irq_sensor mutex_lock(&data->thermal_lock); - sensor = &data->sensors[data->irq_bind_sensor]; + sensor = &data->sensors; /* setting the hdak time */ writel(0x0, data->regs + TEMP0_CFG); @@ -160,31 +160,8 @@ static int hisi_thermal_get_temp(void *_sensor, int *temp) struct hisi_thermal_sensor *sensor = _sensor; struct hisi_thermal_data *data = sensor->thermal; - int sensor_id = -1, i; - long max_temp = 0; - *temp = hisi_thermal_get_sensor_temp(data, sensor); - sensor->sensor_temp = *temp; - - for (i = 0; i < HISI_MAX_SENSORS; i++) { - if (!data->sensors[i].tzd) - continue; - - if (data->sensors[i].sensor_temp >= max_temp) { - max_temp = data->sensors[i].sensor_temp; - sensor_id = i; - } - } - - /* If no sensor has been enabled, then skip to enable irq */ - if (sensor_id == -1) - return 0; - - mutex_lock(&data->thermal_lock); - data->irq_bind_sensor = sensor_id; - mutex_unlock(&data->thermal_lock); - dev_dbg(&data->pdev->dev, "id=%d, irq=%d, temp=%d, thres=%d\n", sensor->id, data->irq_enabled, *temp, sensor->thres_temp); /* @@ -197,7 +174,7 @@ static int hisi_thermal_get_temp(void *_sensor, int *temp) return 0; } - if (max_temp < sensor->thres_temp) { + if (*temp < sensor->thres_temp) { data->irq_enabled = true; hisi_thermal_enable_bind_irq_sensor(data); enable_irq(data->irq); @@ -224,22 +201,16 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) { struct hisi_thermal_data *data = dev; struct hisi_thermal_sensor *sensor; - int i; mutex_lock(&data->thermal_lock); - sensor = &data->sensors[data->irq_bind_sensor]; + sensor = &data->sensors; dev_crit(&data->pdev->dev, "THERMAL ALARM: T > %d\n", sensor->thres_temp / 1000); mutex_unlock(&data->thermal_lock); - for (i = 0; i < HISI_MAX_SENSORS; i++) { - if (!data->sensors[i].tzd) - continue; - - thermal_zone_device_update(data->sensors[i].tzd, - THERMAL_EVENT_UNSPECIFIED); - } + thermal_zone_device_update(data->sensors.tzd, + THERMAL_EVENT_UNSPECIFIED); return IRQ_HANDLED; } @@ -296,7 +267,6 @@ static int hisi_thermal_probe(struct platform_device *pdev) { struct hisi_thermal_data *data; struct resource *res; - int i; int ret; data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); @@ -347,16 +317,17 @@ static int hisi_thermal_probe(struct platform_device *pdev) hisi_thermal_enable_bind_irq_sensor(data); data->irq_enabled = true; - for (i = 0; i < HISI_MAX_SENSORS; ++i) { - ret = hisi_thermal_register_sensor(pdev, data, - &data->sensors[i], i); - if (ret) - dev_err(&pdev->dev, - "failed to register thermal sensor: %d\n", ret); - else - hisi_thermal_toggle_sensor(&data->sensors[i], true); + ret = hisi_thermal_register_sensor(pdev, data, + &data->sensors, + HISI_DEFAULT_SENSOR); + if (ret) { + dev_err(&pdev->dev, "failed to register thermal sensor: %d\n", + ret); + return ret; } + hisi_thermal_toggle_sensor(&data->sensors, true); + enable_irq(data->irq); return 0; @@ -365,17 +336,9 @@ static int hisi_thermal_probe(struct platform_device *pdev) static int hisi_thermal_remove(struct platform_device *pdev) { struct hisi_thermal_data *data = platform_get_drvdata(pdev); - int i; - - for (i = 0; i < HISI_MAX_SENSORS; i++) { - struct hisi_thermal_sensor *sensor = &data->sensors[i]; - - if (!sensor->tzd) - continue; - - hisi_thermal_toggle_sensor(sensor, false); - } + struct hisi_thermal_sensor *sensor = &data->sensors; + hisi_thermal_toggle_sensor(sensor, false); hisi_thermal_disable_sensor(data); clk_disable_unprepare(data->clk); From patchwork Mon Sep 4 19:56:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111604 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp1935182qge; Mon, 4 Sep 2017 12:57:45 -0700 (PDT) X-Received: by 10.99.54.7 with SMTP id d7mr1568612pga.115.1504555064915; Mon, 04 Sep 2017 12:57:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504555064; cv=none; d=google.com; s=arc-20160816; b=DP2uqDQyF0ecmjuCuKH/d6qEAeU9qGVZIFqAb5f+aYPk+h6s+K5ST4c+8zQ6/Iccpc FDQcWMh+i5Kqi+SBuFoeJ4+xfFQlx4vDPF+qy4XztRUHKRR+n1pCAfgDujUN+0vJIQpX mp7w29onrkkHWBQ22MNrTkB5aGjxP+uxyXlwY1eQsqB4seBF8Ikm3EcXrLaJEeLtZ5oq MrGnHrQQWoM1gKcrVMw1b1rNn9DE1ePQczrOcEKLw76fW/Nkqul42LZ5PFansI3o6OYA C7Wz/muu74GCUU7Sh5DKgCbwbzejqo6+s3gH+ejuC988bTfE/nz6JFuob/w6DtsSi2B6 Umyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=7xBEhVPaCblnkIL+P8vAWg4HSWgZbmZtlo3bOYLNLEA=; b=0PCPGDTq9aRDmXhsr0yb+QoQ2CDkXEB1hqwgARnTvurumpNj8jcmUyoKd/vl737NYi Dy5xd3IYzYtCexn3+UK2iLrM6BtF4t+ryuSb7mkyeDbuxSLeQFYR2qYorFJBQB2KxBeH l6vkkx8nGoAAsQdrxe4WGsC5gGncyWJHLUYibUkBQflC3ns/8KqF/5Dudah+C3df11n0 7xCT1pa1IIJs9OFCJ/mc3gSQno49LcpTaXT0FuFVGap0g/yNyVC/py35W9sxgbaCb0az gXptbdkuBByoqz50cq4FrOoyCgi7dUKBcokuIxmbyK5ffAoJpYAKovnzow9YblbRrLD9 6qKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E628kOng; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w15si5872932plk.360.2017.09.04.12.57.44; Mon, 04 Sep 2017 12:57:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E628kOng; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754010AbdIDT5k (ORCPT + 12 others); Mon, 4 Sep 2017 15:57:40 -0400 Received: from mail-wr0-f170.google.com ([209.85.128.170]:36292 "EHLO mail-wr0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753988AbdIDT5h (ORCPT ); Mon, 4 Sep 2017 15:57:37 -0400 Received: by mail-wr0-f170.google.com with SMTP id p14so2065229wrg.3 for ; Mon, 04 Sep 2017 12:57:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7xBEhVPaCblnkIL+P8vAWg4HSWgZbmZtlo3bOYLNLEA=; b=E628kOngR8LJeCT0rFlYJpmyUYqd8yMBZx28kPASN0vZk4q55S9GNk4A1HcTuyG4Fz k1DvExarOEZ7EAKPUabibBwueXUoc3wCJAYDbbMlxDqKgI56bJb8NZ4MLKN2JA9Qxggf awGrxr0SWsX20mU2MvC5cSpQ9mgpa0qSFfolg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7xBEhVPaCblnkIL+P8vAWg4HSWgZbmZtlo3bOYLNLEA=; b=CpBQw0+5ARS8JECa9yIs+tsa8soArAt+vEqkSCryMqGKvnHWfOerS6L0ljYfTXaacr BJxA4Ee/zt86Uf9IHKJ7rNAWVWqpeQpWqu054e//ZAlilQtgsbS4URZbdepZvNm4mbX1 6boTgSbbnyrv4OZjldRvBIOsE0H5odzEHabFMcZd1PaxEv3zpIw0hU+Ax98W4OSIvu7N NYr5d06Cf2ihhcnHTc+CVv8VB2rhI2mh68SnSqMg8aBPRM/C1ytmTbFo9IQ5wKlP+dmi etf0RWl48SvoBw9cnq2q/VnJAuGAzjo9EWNG9njYK2IkunKB5A4Mt8stkOwTgTV3LSxY I1TQ== X-Gm-Message-State: AHPjjUgQNdmwFbMOZWxATHBhtRheMIEOYcCZiH1ZIAYDlFdEJludhe1z sXGjMKBrFWZ/IxGh X-Google-Smtp-Source: ADKCNb7BoQdNcM+0+iQifdjITlo9DOh+q7+DIq9cfYMNnXiCy9cuV3ruvmFp013SJgazNyGJco1SDg== X-Received: by 10.223.184.230 with SMTP id c35mr988577wrg.313.1504555056020; Mon, 04 Sep 2017 12:57:36 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:f567:7c41:be9d:9286]) by smtp.gmail.com with ESMTPSA id 23sm10798976wrt.44.2017.09.04.12.57.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 12:57:35 -0700 (PDT) From: Daniel Lezcano To: rui.zhang@intel.com, edubezval@gmail.com Cc: daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, kevin.wangtao@linaro.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 03/13] thermal/drivers/hisi: Fix kernel panic on alarm interrupt Date: Mon, 4 Sep 2017 21:56:02 +0200 Message-Id: <1504554972-2624-3-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> References: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The threaded interrupt for the alarm interrupt is requested before the temperature controller is setup. This one can fire an interrupt immediately leading to a kernel panic as the sensor data is not initialized. In order to prevent that, move the threaded irq after the Tsensor is setup. Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan Tested-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 725d0d4..f69aea0 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -287,15 +287,6 @@ static int hisi_thermal_probe(struct platform_device *pdev) if (data->irq < 0) return data->irq; - ret = devm_request_threaded_irq(&pdev->dev, data->irq, - hisi_thermal_alarm_irq, - hisi_thermal_alarm_irq_thread, - 0, "hisi_thermal", data); - if (ret < 0) { - dev_err(&pdev->dev, "failed to request alarm irq: %d\n", ret); - return ret; - } - platform_set_drvdata(pdev, data); data->clk = devm_clk_get(&pdev->dev, "thermal_clk"); @@ -328,6 +319,15 @@ static int hisi_thermal_probe(struct platform_device *pdev) hisi_thermal_toggle_sensor(&data->sensors, true); + ret = devm_request_threaded_irq(&pdev->dev, data->irq, + hisi_thermal_alarm_irq, + hisi_thermal_alarm_irq_thread, + 0, "hisi_thermal", data); + if (ret < 0) { + dev_err(&pdev->dev, "failed to request alarm irq: %d\n", ret); + return ret; + } + enable_irq(data->irq); return 0; From patchwork Mon Sep 4 19:56:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111605 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp1935220qge; Mon, 4 Sep 2017 12:57:48 -0700 (PDT) X-Received: by 10.99.121.135 with SMTP id u129mr1591718pgc.260.1504555068480; Mon, 04 Sep 2017 12:57:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504555068; cv=none; d=google.com; s=arc-20160816; b=hUsfvG8YJqUrTmOkFwmo+gDHtamjco8A7IDcLBB2xVU5bR8vXwjrU9gOE8wfSOxR9D 07PNdvBZ+PHSExaHad8eaT7TMsSxWTT4z0tVXz2H/cwphhVuI+YrEYL1Xq72L/WcZsqR S19NzIP9WcZyNUk4CoapBVNJhP18hoi40S3Xq678BovulJ704gi8Zw471n141HXkTMyU B9k3Que2kbOrELnjZu+0RVrofw8meUp9vuMccHgO8DhIJpSAiu6g1lWTSnoTlV92EfwW i4SiosyoEdWQEjZpwA3BbIyg1W8jREXcbI9QnTFtoyUS05vHldZag976awg6hODBogeZ b7bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=NuA6gjRftABL/rv9GKnssf5OdZWL4ib7fDKZNQooWY0=; b=kZCmNkQDmJ7AsLrTxhbS+RphGyh3ISvTg5gWXIzg8YypBRMfrdRX/s/lVRSKc0MRgp nK4QP6P2PihW0RNa3kKthPPEzke3ayJ8Z8mNAOeW/HyQtctgtwEW01dPSJwyT2SZcHg9 yiK23kN18JZb6u2YUYbmp3q3t25QZ+fwvat44L6hpEpiwyG3jPC9zgAWTneB4wcA7J+/ emEBQZ0++DfL76NBHC4OGfITIUd61cQD5Im44TocpSpbkdGZQxbVPq8Xj+RnaFG03aXK 1bECAUgnOS/2AmoHnNEbXwU/mKNFcyhTXJAIE0Aha3dLAKvpP3xgivP7vcbDs5T4hLHR egXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VvNeB+rR; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w15si5872932plk.360.2017.09.04.12.57.48; Mon, 04 Sep 2017 12:57:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VvNeB+rR; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754014AbdIDT5o (ORCPT + 12 others); Mon, 4 Sep 2017 15:57:44 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:35191 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753957AbdIDT5i (ORCPT ); Mon, 4 Sep 2017 15:57:38 -0400 Received: by mail-wm0-f54.google.com with SMTP id v2so9982447wmf.0 for ; Mon, 04 Sep 2017 12:57:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NuA6gjRftABL/rv9GKnssf5OdZWL4ib7fDKZNQooWY0=; b=VvNeB+rRUS8aY3K6TO+aeUVNjZhCZCxSHybDiHAH/EyhHCIErnMTrGfqpaKheXpbrJ qeR9FG/OoTtJh7brpvEjur62CQSvIufUuciop1K29TN0t0ZlxA7kUmDbb3mmN5rcn0vc LYRV2JiWKGjMszuuQlZL+5HrP7pX0xFVZwuC8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NuA6gjRftABL/rv9GKnssf5OdZWL4ib7fDKZNQooWY0=; b=OLj3rh6M57Idajymy4vHTouU8abxoKUm205S+DdHItWKOC1AiMQs3+a2JDnYoabGel ETB7eED8c6ZSgY+4pousOLpCvenbFBUs8CNYFLXzGS/rjbbWBHOSlz0EhozxtbXBwOp4 H4d8AXArLY8B89sUNIKE4XTLvqRY+lBW9u9h1civbYvAz1Rg4/aYalXKNyKh27u0kTER oWkuNsBqy0Niq+qSn3TEKlqKLh3dktWYerhEEK24276emkc1x9ViVteTUBT7DIMVlZPy 8CrlS5H4CtLg715yBzjnyLk9S2nnTrmP2m5jK+TQLPC+nVGvSJUn/y4drlIwUcBPUJs9 TOCg== X-Gm-Message-State: AHPjjUiCIphWTzZgacrHhfeaGii0P3A50XDWg48UbhmELiw3JAyQxy2S SRHHLydmlTH5s/2l X-Google-Smtp-Source: ADKCNb7+AJu0cPgzea3lzmy096dlawOHtYWX4g00f27p9dnOqLCO3Hm637oKza71jcrlhNLHOeKqtA== X-Received: by 10.28.137.19 with SMTP id l19mr1124039wmd.98.1504555057563; Mon, 04 Sep 2017 12:57:37 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:f567:7c41:be9d:9286]) by smtp.gmail.com with ESMTPSA id 23sm10798976wrt.44.2017.09.04.12.57.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 12:57:37 -0700 (PDT) From: Daniel Lezcano To: rui.zhang@intel.com, edubezval@gmail.com Cc: daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, kevin.wangtao@linaro.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 04/13] thermal/drivers/hisi: Simplify the temperature/step computation Date: Mon, 4 Sep 2017 21:56:03 +0200 Message-Id: <1504554972-2624-4-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> References: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The step and the base temperature are fixed values, we can simplify the computation by converting the base temperature to milli celsius and use a pre-computed step value. That saves us a lot of mult + div for nothing at runtime. Take also the opportunity to change the function names to be consistent with the rest of the code. Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan Tested-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index f69aea0..583bc19 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -35,8 +35,9 @@ #define TEMP0_RST_MSK (0x1C) #define TEMP0_VALUE (0x28) -#define HISI_TEMP_BASE (-60) +#define HISI_TEMP_BASE (-60000) #define HISI_TEMP_RESET (100000) +#define HISI_TEMP_STEP (784) #define HISI_MAX_SENSORS 4 #define HISI_DEFAULT_SENSOR 2 @@ -61,19 +62,32 @@ struct hisi_thermal_data { void __iomem *regs; }; -/* in millicelsius */ -static inline int _step_to_temp(int step) +/* + * The temperature computation on the tsensor is as follow: + * Unit: millidegree Celsius + * Step: 255/200 (0.7843) + * Temperature base: -60°C + * + * The register is programmed in temperature steps, every step is 784 + * millidegree and begins at -60 000 m°C + * + * The temperature from the steps: + * + * Temp = TempBase + (steps x 784) + * + * and the steps from the temperature: + * + * steps = (Temp - TempBase) / 784 + * + */ +static inline int hisi_thermal_step_to_temp(int step) { - /* - * Every step equals (1 * 200) / 255 celsius, and finally - * need convert to millicelsius. - */ - return (HISI_TEMP_BASE * 1000 + (step * 200000 / 255)); + return HISI_TEMP_BASE + (step * HISI_TEMP_STEP); } -static inline long _temp_to_step(long temp) +static inline long hisi_thermal_temp_to_step(long temp) { - return ((temp - HISI_TEMP_BASE * 1000) * 255) / 200000; + return (temp - HISI_TEMP_BASE) / HISI_TEMP_STEP; } static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, @@ -99,7 +113,7 @@ static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, usleep_range(3000, 5000); val = readl(data->regs + TEMP0_VALUE); - val = _step_to_temp(val); + val = hisi_thermal_step_to_temp(val); mutex_unlock(&data->thermal_lock); @@ -126,10 +140,11 @@ static void hisi_thermal_enable_bind_irq_sensor writel((sensor->id << 12), data->regs + TEMP0_CFG); /* enable for interrupt */ - writel(_temp_to_step(sensor->thres_temp) | 0x0FFFFFF00, + writel(hisi_thermal_temp_to_step(sensor->thres_temp) | 0x0FFFFFF00, data->regs + TEMP0_TH); - writel(_temp_to_step(HISI_TEMP_RESET), data->regs + TEMP0_RST_TH); + writel(hisi_thermal_temp_to_step(HISI_TEMP_RESET), + data->regs + TEMP0_RST_TH); /* enable module */ writel(0x1, data->regs + TEMP0_RST_MSK); From patchwork Mon Sep 4 19:56:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111607 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp1935278qge; Mon, 4 Sep 2017 12:57:53 -0700 (PDT) X-Received: by 10.84.217.221 with SMTP id d29mr1702919plj.309.1504555073113; Mon, 04 Sep 2017 12:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504555073; cv=none; d=google.com; s=arc-20160816; b=K+P5sfcpXPKAFNotfK6Sriu7WE1f+zihlQ8W5wY3lA/JzyWMCwGB6/2UDq81Nm3+qG RJwqKDKBLA4wL0RSW1+0SJujqZyD6QE3bVlHtyrk3kBy7WscGlDFzcRBLNNnFyzUIowH yQ5XfXxBi8s+CnT0aScysFiripgzagD+qOs48KEdtJA5X/UdUa1uKzv1R+g5KpQGt2Cx Ggoa8kJNSM6y+5txOcMU4Py6kRksPr7rLKXq0yVPVN70ywZbickXhwlGXEOiuhEZkauK 8TW2jIQrbktrlJjGQBbGnf9lND6BEW9nhYmTsaEcbI2tt/QT1EUXl1hE3mUVhDgR0I8f wOwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=JhdkkJiHQ5XrqCWufTQWevXb2F70BZ7yIA5hrygNHqI=; b=KfImhFZKu9GAhzjQQjLhzhswFo3HkWEMiijFt+M4hWmErUXYzirZ+1OOeiDntsPiRT jtX7up7nrLxKAnGQSvvzFPrloW6gPdhYJESyEEB5uwnvtWQ7PpWiz1PBd62uWXvVXDTk A1eDBpy5cHruQAQp3VQJHCTvBnJyBGUdaNfWGI/JkWzoTsT68Nq4AAvfQyIqjYQFRJHe kiReRy4bfNMkyVU0aDSzOsZqUcKUDEl3IBv81+cnlvx+DMEKYUghoWOQj/jPPzKuColI 1PBakdvAwSYqi3H9YBxRMtgoU/45jMKoZ3jdostgsFTjeFrr/63B3uW8Sg5S4/jYUa+K sQdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BvUpPO26; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si5992406pln.738.2017.09.04.12.57.52; Mon, 04 Sep 2017 12:57:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BvUpPO26; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754033AbdIDT5q (ORCPT + 12 others); Mon, 4 Sep 2017 15:57:46 -0400 Received: from mail-wr0-f181.google.com ([209.85.128.181]:37243 "EHLO mail-wr0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754009AbdIDT5k (ORCPT ); Mon, 4 Sep 2017 15:57:40 -0400 Received: by mail-wr0-f181.google.com with SMTP id n33so3986164wrn.4 for ; Mon, 04 Sep 2017 12:57:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JhdkkJiHQ5XrqCWufTQWevXb2F70BZ7yIA5hrygNHqI=; b=BvUpPO2699282hpyurPKnI2nEi+qQS3xaNcsdrYjpsqjQWHTvgcyCB9s3jhLK7KecG I3oc4bdMX6CTobx0CfjJBdYK2NwODmInFm2qgSx9i8eoLWFezP4XifhjfOSr03825In1 4XaDVuBc07GLy2yNeMw6XZ+ISEkjBtf7RI6Kw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JhdkkJiHQ5XrqCWufTQWevXb2F70BZ7yIA5hrygNHqI=; b=msMvl18Ex3SZItIoBSYpG/AITtuPXcP1OPoZp62hYM78Bc077bcT5aOugLpxcpdS1R Gxu8gu0kjZ61j/50A4spvEmySqg1odn1oidIYHqx8X54G3JL0LUvFjasc9bSmWniLEqW oZS3R50h9V7R5toNxppfUNOIwlL0uOn/j/CGjD3Czu0drkkaTctgiAp+fv7Uy8F+4eXa Cs9FmLmIuNs0+2sHDuLV07hI47OIOnpiVEz3e+UMt2fzfAAe0wKkKNGVILH5RbA1PfKu +79y+qnK4ydy6lOT9Kd216Dh46m5YjiQE+e3bDnU1gORbUjh0lU5k3rq6m9aalFr1e+4 wTJw== X-Gm-Message-State: AHPjjUhP2F3NTigSExRn9Vrkr/kpDUvMTVabdt2TiuEESyObzAz7a9o3 owfbWwcctoo3Ej/b X-Google-Smtp-Source: ADKCNb7mPEdqt8F+4Gd4bcA9xl5yCC6cwGJOvpBKtqLVMEADEMlng7rWCDz8CPIUwduSRWZHCRULng== X-Received: by 10.223.169.83 with SMTP id u77mr865439wrc.268.1504555059233; Mon, 04 Sep 2017 12:57:39 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:f567:7c41:be9d:9286]) by smtp.gmail.com with ESMTPSA id 23sm10798976wrt.44.2017.09.04.12.57.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 12:57:38 -0700 (PDT) From: Daniel Lezcano To: rui.zhang@intel.com, edubezval@gmail.com Cc: daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, kevin.wangtao@linaro.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 05/13] thermal/drivers/hisi: Fix multiple alarm interrupts firing Date: Mon, 4 Sep 2017 21:56:04 +0200 Message-Id: <1504554972-2624-5-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> References: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The DT specifies a threshold of 65000, we setup the register with a value in the temperature resolution for the controller, 64656. When we reach 64656, the interrupt fires, the interrupt is disabled. Then the irq thread runs and calls thermal_zone_device_update() which will call in turn hisi_thermal_get_temp(). The function will look if the temperature decreased, assuming it was more than 65000, but that is not the case because the current temperature is 64656 (because of the rounding when setting the threshold). This condition being true, we re-enable the interrupt which fires immediately after exiting the irq thread. That happens again and again until the temperature goes to more than 65000. Potentially, there is here an interrupt storm if the temperature stabilizes at this temperature. A very unlikely case but possible. In any case, it does not make sense to handle dozens of alarm interrupt for nothing. Fix this by rounding the threshold value to the controller resolution so the check against the threshold is consistent with the one set in the controller. Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan Tested-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 583bc19..f523197 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -90,6 +90,12 @@ static inline long hisi_thermal_temp_to_step(long temp) return (temp - HISI_TEMP_BASE) / HISI_TEMP_STEP; } +static inline long hisi_thermal_round_temp(int temp) +{ + return hisi_thermal_step_to_temp( + hisi_thermal_temp_to_step(temp)); +} + static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, struct hisi_thermal_sensor *sensor) { @@ -221,7 +227,7 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) sensor = &data->sensors; dev_crit(&data->pdev->dev, "THERMAL ALARM: T > %d\n", - sensor->thres_temp / 1000); + sensor->thres_temp); mutex_unlock(&data->thermal_lock); thermal_zone_device_update(data->sensors.tzd, @@ -255,7 +261,7 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, for (i = 0; i < of_thermal_get_ntrips(sensor->tzd); i++) { if (trip[i].type == THERMAL_TRIP_PASSIVE) { - sensor->thres_temp = trip[i].temperature; + sensor->thres_temp = hisi_thermal_round_temp(trip[i].temperature); break; } } From patchwork Mon Sep 4 19:56:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111606 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp1935259qge; Mon, 4 Sep 2017 12:57:51 -0700 (PDT) X-Received: by 10.84.211.46 with SMTP id b43mr1766395pli.161.1504555071357; Mon, 04 Sep 2017 12:57:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504555071; cv=none; d=google.com; s=arc-20160816; b=nJKpCxSiT8c9uRTK2hCsyltjOuY3j+8+/7NQp9meOAVGXW1ceReqqgTLQ7Er2dc7Bb 8CFlufH2014m0Q/OFx6+XpKlJhKXeDxeb44Q9qGotxZmB7Oq7iYWocD0PhI5dmjRKw9n edI/cYXrLHub3Vn4al4H0ds9VHRk4M5J3rxcccIQuPYLD6rJ/mU6FjsBjrdiXT7U+hFn tij/vJU7rM0Pno7u9oJrRQtPlZ5Hjdg4hMPB0DX52rwTFQf3h7ZGlZar1v10fo1OZ5hl m7HLTjOmOJShG68lNNK8UPevELMGxSTUrUOzg4jCrgxOrGlpFLUe13ueZHaORosqutNd h5Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=hu9AHyaZ046I9ZgSTrpmNxghB1bERyxm+xqdqK7QvI8=; b=rmV/g++YwqFZKTd04WWGtxVflol3QNoQoiyrj2BRb2QFfeUeG2o8yI9juT+NqTBpb4 2iIrw5WPNQDHzOdhjb4mzUAzD5FhRbcZ/RVty3ppQ1wReP0MkUvAiM0hOAF2EJF+rwlv jhs6Ap7PNt1/xu6fvMr5TAJ2bpX6y9FH0AkZwe/1LF87cj5NcUuTLJsO46ODuVtr6Esc Rxn0+wN49EUwo+Lmsv4nGEYRz8VxoB/u3Sdwy+bBseza20dNU3x/iP/Rrq/QLLxXjJCR bhICQZ7p/FzuOAx1fOfR0lVOTN4/vGKenpBOl24VFIRa4aUAqrGTWGogOnp2Hn/mZV5h 2vhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CZiTPKRC; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si5992406pln.738.2017.09.04.12.57.50; Mon, 04 Sep 2017 12:57:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CZiTPKRC; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753984AbdIDT5s (ORCPT + 12 others); Mon, 4 Sep 2017 15:57:48 -0400 Received: from mail-wr0-f170.google.com ([209.85.128.170]:35516 "EHLO mail-wr0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754011AbdIDT5l (ORCPT ); Mon, 4 Sep 2017 15:57:41 -0400 Received: by mail-wr0-f170.google.com with SMTP id y15so4043260wrc.2 for ; Mon, 04 Sep 2017 12:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hu9AHyaZ046I9ZgSTrpmNxghB1bERyxm+xqdqK7QvI8=; b=CZiTPKRCwM6tV7fgb9m4q6ZM/w3LrIe+AT5PAazm1lkjztr3Bqi/8wqyQ3wlLApzl7 j9a/wEvafrJISCk4jWyNaxjEfYxDbcUZtOUbqG2+N/FAhMUhblUGjEb+QuiiAgauzAfd rFD5u39P5jfEaG79I/TN8c5HRCdOGb0TabwB4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hu9AHyaZ046I9ZgSTrpmNxghB1bERyxm+xqdqK7QvI8=; b=g7TLwEGZqNWS1l7PCEP1Ei0Av011k9b9GFMMBLcB713Tg+TUGS+Dv5JI+tDW/hZrfa CpXEm2OQIhsP1h4rLVf3jts5oHOA9NcMsNTVoLtOD5NLyTvXXsV1hocDKBzzfhk2LzIe iyUlu48BB8W6Kk3kj7z1RLXryEA/JV1x0pu9TUgXKhisVE96C4HMsxwoCtKxCgGuDeqr jo4LTOwOv1WMsm+PT687l3/qZY8W89wTnH4Xc8Cum0Wx+qnAvJAP8F4dGq+XOQ/ioENo XyNjs5INNUXeq0/k4igrCHOiNuvAm74Fz+E4HaNgEPmHPus3mIzjWZ86c19BHE+pD00r Dxlg== X-Gm-Message-State: AHPjjUg1s6pkLlfUSqiYUkL1vLI6UzfILv2Bu0nutfxcJYJltnhTq4wD N9bJXT75KU+GvxPL X-Google-Smtp-Source: ADKCNb6CjttE++STvowzu0ruZXU199OguDpahOn6jCScHXgNn3t0b+pEkom6guF/XTpFPyQUMMiVGw== X-Received: by 10.223.129.133 with SMTP id 5mr869205wra.231.1504555060773; Mon, 04 Sep 2017 12:57:40 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:f567:7c41:be9d:9286]) by smtp.gmail.com with ESMTPSA id 23sm10798976wrt.44.2017.09.04.12.57.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 12:57:40 -0700 (PDT) From: Daniel Lezcano To: rui.zhang@intel.com, edubezval@gmail.com Cc: daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, kevin.wangtao@linaro.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 06/13] thermal/drivers/hisi: Remove pointless lock Date: Mon, 4 Sep 2017 21:56:05 +0200 Message-Id: <1504554972-2624-6-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> References: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The threaded interrupt inspect the sensors structure to look in the temp threshold field, but this field is read-only in all the code, except in the probe function before the threaded interrupt is set. In other words there is not race window in the threaded interrupt when reading the field value. Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index f523197..9ec5f29 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -221,14 +221,10 @@ static irqreturn_t hisi_thermal_alarm_irq(int irq, void *dev) static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) { struct hisi_thermal_data *data = dev; - struct hisi_thermal_sensor *sensor; - - mutex_lock(&data->thermal_lock); - sensor = &data->sensors; + struct hisi_thermal_sensor *sensor = &data->sensors; dev_crit(&data->pdev->dev, "THERMAL ALARM: T > %d\n", sensor->thres_temp); - mutex_unlock(&data->thermal_lock); thermal_zone_device_update(data->sensors.tzd, THERMAL_EVENT_UNSPECIFIED); From patchwork Mon Sep 4 19:56:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111613 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp1936585qge; Mon, 4 Sep 2017 12:59:36 -0700 (PDT) X-Received: by 10.84.238.16 with SMTP id u16mr1784768plk.217.1504555176430; Mon, 04 Sep 2017 12:59:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504555176; cv=none; d=google.com; s=arc-20160816; b=QpVzXSgXG70j2RgZafobwKW/5oT/h1NjM7nqWWjc6wLkPQPk5L4X4nPdw6JucbmcNz YToZ6cUBW/+pem8gjlyw+St3onzqB0m8MQsK8K1r73uIk2kB3PzDpGzLRXVzLuk1IE9w CfrXV3GnDyUaggbHTVQ2C/SvxDEbf3/F4Xa8PtO1C2mKST1ZLrADhTO+qjxrabas9HSL COXYhebchWxPvKnUsLvtZnv8lplkTuzAxvr86UdIgY5LEcI/9Y9bBhX+Svj/6FomKNUc Bkz151XSnGqPapFRqGRPkBS3QQoBTZHgYqpe8jBBjhYZQNXbp5KM2SOTVkrUp3OWPB29 tsFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=uzREllr6QWICFAknjY66duz84hhhLpYMQZr2MlXYubA=; b=QWgma3hwIC0n32sYhY0ML9ChqTP6Gj2T2Kasu1gpObI7NWY9OEaFbJy23PNtp6wUa/ HmCWWEoJIapO6oZ8LsFh3Q4VININpAzdQFB5LboTiNhOrZsECfOwxFAi8V+Hkm7V82xC G/y6qmyRgyl0lSoWmTWy1uj3gsHvtlFC9d0esAq7p/0+DcPPB32ub7j8uk2XGU4CglOk so9SkJvrCz3A/u5r6T4rzfe/hZyIkClno16qIUzLiwjYfLINyueByonvp8NMxt/ahDvH HYENawa2Pf6dJj5FD8eT302Zo7kQlw+bbyo8VJfEj31MPyofnsXvN7Po8iww82A2v1DM dBqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rc1OZcqe; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5si5701843plx.823.2017.09.04.12.59.36; Mon, 04 Sep 2017 12:59:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rc1OZcqe; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754039AbdIDT5t (ORCPT + 12 others); Mon, 4 Sep 2017 15:57:49 -0400 Received: from mail-wr0-f170.google.com ([209.85.128.170]:38641 "EHLO mail-wr0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753988AbdIDT5n (ORCPT ); Mon, 4 Sep 2017 15:57:43 -0400 Received: by mail-wr0-f170.google.com with SMTP id 108so3966801wra.5 for ; Mon, 04 Sep 2017 12:57:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uzREllr6QWICFAknjY66duz84hhhLpYMQZr2MlXYubA=; b=Rc1OZcqexgyOegxIyyGTAhIOpuLV5Lr2WE2LnDnFLSpzg2AsCU6yj75c/6qOBv6LOn ipR5Am/tcHllneAfzhj01rEeVwFm2DcfT0b8D0xP7qJe0KoOGuBPX03pn5epYmM8FxZB jQ9F35AIPF6bHGJd6GMKOfpNcND5J0WpfPPqk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uzREllr6QWICFAknjY66duz84hhhLpYMQZr2MlXYubA=; b=GTp69rVMQQrcRG1PYapcliqRuGXieByEQpWzKB1BamTZ+rornJaCIX1mreiTQBE3u4 jRC6+AhNxw6JLOHDZ1sM1cwK8C+jjIXzvZK98PxnT2O0sFf6WBk6ulg8V74EjVEVXlHV 3ildLQpR3F4WjSd3mOOvU1G3mCLrSHCRsS8cBTq7KFU4r6akEu1Y+Eitn/DScYInhxNK 8JT+tWTdwyUrgREsVH07z1ID5V/heL/4SgxPnWPPQfdIoWEvfgrRZl9vTcCQ0uVVFY2v G6mMYOflwDQfnrE13liqq598yxTSYrGSdtiQz267BvZWTbj6BqAAYb3vpL62unEkebRB 17wQ== X-Gm-Message-State: AHPjjUiBlASEtqF0z62qXdvFojSMKajrzY0eK4XAzpB9izOxKJ+s4Tl5 P3mV17ckmOqW22uZ X-Google-Smtp-Source: ADKCNb5LjUxGpAecLxlxrc4wVMexP3IzLp36ZMOfblrlE1E449s2+I0A0Y2625bYP6NT75/91l9+TA== X-Received: by 10.223.142.82 with SMTP id n76mr933565wrb.272.1504555062400; Mon, 04 Sep 2017 12:57:42 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:f567:7c41:be9d:9286]) by smtp.gmail.com with ESMTPSA id 23sm10798976wrt.44.2017.09.04.12.57.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 12:57:41 -0700 (PDT) From: Daniel Lezcano To: rui.zhang@intel.com, edubezval@gmail.com Cc: daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, kevin.wangtao@linaro.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 07/13] thermal/drivers/hisi: Encapsulate register writes into helpers Date: Mon, 4 Sep 2017 21:56:06 +0200 Message-Id: <1504554972-2624-7-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> References: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Hopefully, the function name can help to clarify the semantic of the operations when writing in the register. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 92 ++++++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 22 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 9ec5f29..7747b96 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -26,6 +26,7 @@ #include "thermal_core.h" +#define TEMP0_LAG (0x0) #define TEMP0_TH (0x4) #define TEMP0_RST_TH (0x8) #define TEMP0_CFG (0xC) @@ -96,6 +97,56 @@ static inline long hisi_thermal_round_temp(int temp) hisi_thermal_temp_to_step(temp)); } +static inline void hisi_thermal_set_lag(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_LAG); +} + +static inline void hisi_thermal_alarm_clear(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_INT_CLR); +} + +static inline void hisi_thermal_alarm_enable(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_INT_EN); +} + +static inline void hisi_thermal_alarm_set(void __iomem *addr, int temp) +{ + writel(hisi_thermal_temp_to_step(temp) | 0x0FFFFFF00, addr + TEMP0_TH); +} + +static inline void hisi_thermal_reset_set(void __iomem *addr, int temp) +{ + writel(hisi_thermal_temp_to_step(temp), addr + TEMP0_RST_TH); +} + +static inline void hisi_thermal_reset_enable(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_RST_MSK); +} + +static inline void hisi_thermal_enable(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_EN); +} + +static inline void hisi_thermal_sensor_select(void __iomem *addr, int sensor) +{ + writel((sensor << 12), addr + TEMP0_CFG); +} + +static inline int hisi_thermal_get_temperature(void __iomem *addr) +{ + return hisi_thermal_step_to_temp(readl(addr + TEMP0_VALUE)); +} + +static inline void hisi_thermal_hdak_set(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_CFG); +} + static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, struct hisi_thermal_sensor *sensor) { @@ -104,22 +155,21 @@ static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, mutex_lock(&data->thermal_lock); /* disable interrupt */ - writel(0x0, data->regs + TEMP0_INT_EN); - writel(0x1, data->regs + TEMP0_INT_CLR); + hisi_thermal_alarm_enable(data->regs, 0); + hisi_thermal_alarm_clear(data->regs, 1); /* disable module firstly */ - writel(0x0, data->regs + TEMP0_EN); + hisi_thermal_enable(data->regs, 0); /* select sensor id */ - writel((sensor->id << 12), data->regs + TEMP0_CFG); + hisi_thermal_sensor_select(data->regs, sensor->id); /* enable module */ - writel(0x1, data->regs + TEMP0_EN); + hisi_thermal_enable(data->regs, 1); usleep_range(3000, 5000); - val = readl(data->regs + TEMP0_VALUE); - val = hisi_thermal_step_to_temp(val); + val = hisi_thermal_get_temperature(data->regs); mutex_unlock(&data->thermal_lock); @@ -136,28 +186,26 @@ static void hisi_thermal_enable_bind_irq_sensor sensor = &data->sensors; /* setting the hdak time */ - writel(0x0, data->regs + TEMP0_CFG); + hisi_thermal_hdak_set(data->regs, 0); /* disable module firstly */ - writel(0x0, data->regs + TEMP0_RST_MSK); - writel(0x0, data->regs + TEMP0_EN); + hisi_thermal_reset_enable(data->regs, 0); + hisi_thermal_enable(data->regs, 0); /* select sensor id */ - writel((sensor->id << 12), data->regs + TEMP0_CFG); + hisi_thermal_sensor_select(data->regs, sensor->id); /* enable for interrupt */ - writel(hisi_thermal_temp_to_step(sensor->thres_temp) | 0x0FFFFFF00, - data->regs + TEMP0_TH); + hisi_thermal_alarm_set(data->regs, sensor->thres_temp); - writel(hisi_thermal_temp_to_step(HISI_TEMP_RESET), - data->regs + TEMP0_RST_TH); + hisi_thermal_reset_set(data->regs, HISI_TEMP_RESET); /* enable module */ - writel(0x1, data->regs + TEMP0_RST_MSK); - writel(0x1, data->regs + TEMP0_EN); + hisi_thermal_reset_enable(data->regs, 1); + hisi_thermal_enable(data->regs, 1); - writel(0x0, data->regs + TEMP0_INT_CLR); - writel(0x1, data->regs + TEMP0_INT_EN); + hisi_thermal_alarm_clear(data->regs, 0); + hisi_thermal_alarm_enable(data->regs, 1); usleep_range(3000, 5000); @@ -169,9 +217,9 @@ static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data) mutex_lock(&data->thermal_lock); /* disable sensor module */ - writel(0x0, data->regs + TEMP0_INT_EN); - writel(0x0, data->regs + TEMP0_RST_MSK); - writel(0x0, data->regs + TEMP0_EN); + hisi_thermal_enable(data->regs, 0); + hisi_thermal_alarm_enable(data->regs, 0); + hisi_thermal_reset_enable(data->regs, 0); mutex_unlock(&data->thermal_lock); } From patchwork Mon Sep 4 19:56:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111614 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp1936675qge; Mon, 4 Sep 2017 12:59:43 -0700 (PDT) X-Received: by 10.99.53.3 with SMTP id c3mr1616954pga.220.1504555183296; Mon, 04 Sep 2017 12:59:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504555183; cv=none; d=google.com; s=arc-20160816; b=YUeRDhQ/KQeTZVhYlxRFGBW75Nr14iW5zopEWDFW4ljCnDtZ3Cm/bCHtVZ+nYoOfiA +rilzW3FiZQNKTOGmOP9I1n5BYIpQag08B1IKBIXix3/sgiYL+USSDtEh7kXrLUCacMp e/6flM/U22U//frgdJJdX7NcGwx1c4YHzadY2LLue9szrPR+7GDfmxNnnB61xPY9ySaj v4TtltjwkTClhI5oKLF2jFimODPRaVmKPiG2ox053sbW/3PXst2LApI8Q9GlcnpTvSBl DLhJnmMh/vhXlfvvAIcVWFBuwm1LJJkcqRfPzYCcnVpexapLJN41+4ibHrTr3c1D5M8V jjEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=9wIioYVS5jJaplv6n3a4/5RJKXAaiI/7GFQhyYZW/+M=; b=oC7mHO9IWq69b7iOV0Xz0zc6cG/1X9YWEVVBQ/c0IY3+8+Tg/53ga94Zimzy987aNH tdtRV1AclYCaJsEA2g4Iti3bQ+XWAb3opYaL4HZ1JWg4O6oYJNXQYRHu25ka/BV4pa9g zbCducHPEKYSljcz9kHyuc7xGD2IbxBwSmrGbcBNODsLxWrbZ2QLnCapyKb8l3IkDvRq UruDxAAs5o2o70MAwWW/7wJat3NQhErhxkCIRsVy0Jju1L3ackfUguOBT+XSG3tKMDEo +Ww/XHy2FiCUbXcIkbthUmDs0pn3137mSLCAqlobJL+Par8U1BdLpTJSHEE7NQ9MkQki X1Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BpB5Exnx; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5si5701843plx.823.2017.09.04.12.59.43; Mon, 04 Sep 2017 12:59:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BpB5Exnx; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754017AbdIDT7l (ORCPT + 12 others); Mon, 4 Sep 2017 15:59:41 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:33588 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753957AbdIDT5p (ORCPT ); Mon, 4 Sep 2017 15:57:45 -0400 Received: by mail-wm0-f45.google.com with SMTP id f145so6663904wme.0 for ; Mon, 04 Sep 2017 12:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9wIioYVS5jJaplv6n3a4/5RJKXAaiI/7GFQhyYZW/+M=; b=BpB5ExnxFeC6qVcqm4bQzZVjxUtZtXsB5dE4D23wyEpzRcVB6s3iFwMNWN5H6zax0A TkR7rnTEUo+DIN+sMGWIGYDPm/VKyKO41ybsWubxOohO2h6ccz5GeZeSoLYDBGjs4Ord PeAS6QHkgzsfuVgj9Z1yhDBdeiTozPrm4Uq9k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9wIioYVS5jJaplv6n3a4/5RJKXAaiI/7GFQhyYZW/+M=; b=oGnpG2EEGgmmR2gGigVcFgd5p5EO4do4fqN+sq7j31BBO0e1cenDuuH9bWfdZqFC/Z Nu6Y/8o8DEMTyppFqS0fdr93WHztsRn6c2F8fFV44CCg087B9HT+rwYLclrO5wQPQI44 9H0Gznc5PxJYhMZjpqZLUfyww4P7fipb+hmMEHZN11NIBlaZU+63ceUffd7IBrnaMZGz 1ty9/3yNDDpf5pjFaak0GXSskfAdAojcr+ZLwBXfVhemrG04pOhkcUuAb09PcrRB2PDY Q7R5pIbbPLZNNU44ugTO6GXk5hk/SA8NKlwl7wJQIJKpPFHejcadKJUeb+nmJik6i7M4 mCDA== X-Gm-Message-State: AHPjjUhIQAMLh+Rg7TOm12tBQ87bs3Vxgzg9zqug6UmG6llDq9ERfJNW yW+qYlAHQoIkyVLvwPWEvg== X-Google-Smtp-Source: ADKCNb7/vkrx8bKz4QNqS01WJ0Qjqn4aAEYDAY8YvRMPHQB+0dsZT6jz6H/JyxCTHRMHTXB8C++WhQ== X-Received: by 10.28.217.85 with SMTP id q82mr1002194wmg.89.1504555064006; Mon, 04 Sep 2017 12:57:44 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:f567:7c41:be9d:9286]) by smtp.gmail.com with ESMTPSA id 23sm10798976wrt.44.2017.09.04.12.57.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 12:57:43 -0700 (PDT) From: Daniel Lezcano To: rui.zhang@intel.com, edubezval@gmail.com Cc: daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, kevin.wangtao@linaro.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 08/13] thermal/drivers/hisi: Fix configuration register setting Date: Mon, 4 Sep 2017 21:56:07 +0200 Message-Id: <1504554972-2624-8-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> References: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The TEMP0_CFG configuration register contains different field to set up the temperature controller. However in the code, nothing prevents a setup to overwrite the previous one: eg. writing the hdak value overwrites the sensor selection, the sensor selection overwrites the hdak value. In order to prevent such thing, use a regmap-like mechanism by reading the value before, set the corresponding bits and write the result. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 7747b96..10ef6bc 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -30,6 +30,8 @@ #define TEMP0_TH (0x4) #define TEMP0_RST_TH (0x8) #define TEMP0_CFG (0xC) +#define TEMP0_CFG_SS_MSK (0xF000) +#define TEMP0_CFG_HDAK_MSK (0x30) #define TEMP0_EN (0x10) #define TEMP0_INT_EN (0x14) #define TEMP0_INT_CLR (0x18) @@ -132,19 +134,41 @@ static inline void hisi_thermal_enable(void __iomem *addr, int value) writel(value, addr + TEMP0_EN); } -static inline void hisi_thermal_sensor_select(void __iomem *addr, int sensor) +static inline int hisi_thermal_get_temperature(void __iomem *addr) { - writel((sensor << 12), addr + TEMP0_CFG); + return hisi_thermal_step_to_temp(readl(addr + TEMP0_VALUE)); } -static inline int hisi_thermal_get_temperature(void __iomem *addr) +/* + * Temperature configuration register - Sensor selection + * + * Bits [19:12] + * + * 0x0: local sensor (default) + * 0x1: remote sensor 1 (ACPU cluster 1) + * 0x2: remote sensor 2 (ACPU cluster 0) + * 0x3: remote sensor 3 (G3D) + */ +static inline void hisi_thermal_sensor_select(void __iomem *addr, int sensor) { - return hisi_thermal_step_to_temp(readl(addr + TEMP0_VALUE)); + writel((readl(addr + TEMP0_CFG) & ~TEMP0_CFG_SS_MSK ) | + (sensor << 12), addr + TEMP0_CFG); } +/* + * Temperature configuration register - Hdak conversion polling interval + * + * Bits [5:4] + * + * 0x0 : 0.768 ms + * 0x1 : 6.144 ms + * 0x2 : 49.152 ms + * 0x3 : 393.216 ms + */ static inline void hisi_thermal_hdak_set(void __iomem *addr, int value) { - writel(value, addr + TEMP0_CFG); + writel((readl(addr + TEMP0_CFG) & ~TEMP0_CFG_HDAK_MSK) | + (value << 4), addr + TEMP0_CFG); } static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data,