From patchwork Wed Aug 30 08:47:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111281 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp595037qge; Wed, 30 Aug 2017 01:48:54 -0700 (PDT) X-Received: by 10.84.241.130 with SMTP id b2mr1039692pll.252.1504082934453; Wed, 30 Aug 2017 01:48:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504082934; cv=none; d=google.com; s=arc-20160816; b=ywB+u+Rzf7NW54HOqo6VWZRyaWkdcDfL1bvJCJzJlzxkduXj5mLd2N8wuM54lvIzAM on0GHa6v9OinHO0dQTAbiGVxCiOdCo+vF/F5pSDyDdbArEb28UaFdvICgpQW002iaxJT Efece0F+PHvwky9mJoMi8YJy67oxMKIido6IHgqXF8ROH8cIMyabKz3N8fs8duIWx8kX jR4+q9H3Sbh+GX1xJgXqpJhuot/f0y6TqvpAzWJnyI7KAhQ25S6bgZaeaOlSNNubDboH /Ja0/feCpGeMH+ItbcytEg49/cpctgsG4LgGILt2c+7y5tjhH6deLA8Ol7nocSeWGZM1 kAGQ== 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=tsKGe/FsS6FBrZr9kIBcZDFgU37QobKuMSUyAnln3hg=; b=OvZUofj0JTfkvCkFRWTFIXnwZ4kF/E1pyiafLOCbQFx3yg454IpdIPbp7rBTYs4evv 8OvTrSXHNXiVwQkvRV0WBv6HWMYP+vGrWwdVRpxKBUUzuOO4ydQWIvy9zl7OU+M+5IbS 3vuJtWu+fKO6ZtDAEhGwH1OBo10kecMt8XAyo7UIvVmQ8DfZ0Fn0cwVIldiVoPoSOKMm Be3yGS8nnGMrOfkr96Q/MnZq0lO+JDdE76yTt1unrFWvHieoBOGpsEIfOxAOnFsMOOBE qiWlgrDx4vIphAP5DORpVaUnyRKHX9q1mzNnlP2Kh/C8cXFzvRiflu8wOrgfKg/gMB8+ OwEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TIPzjWAT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 t8si3968210pfk.157.2017.08.30.01.48.54; Wed, 30 Aug 2017 01:48:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=TIPzjWAT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1751478AbdH3Ist (ORCPT + 26 others); Wed, 30 Aug 2017 04:48:49 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:34980 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751408AbdH3Isr (ORCPT ); Wed, 30 Aug 2017 04:48:47 -0400 Received: by mail-wm0-f49.google.com with SMTP id a80so5550986wma.0 for ; Wed, 30 Aug 2017 01:48:46 -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=tsKGe/FsS6FBrZr9kIBcZDFgU37QobKuMSUyAnln3hg=; b=TIPzjWAT0k0WtZvZjU2nzjWKtnUm/nzfsTSLVd43rTw+swFOkOCOiInZ/apDAVBHRn sPcZvIlfH3WDmY8SITjZFUPhpLyrqSqLD4IUTjP+kS+LVMiUhNv/DISO0DKThdFYEAgx 8wpOmfm1mM2Go44mTn6Pn4GWyevQPuFjghhBw= 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=tsKGe/FsS6FBrZr9kIBcZDFgU37QobKuMSUyAnln3hg=; b=skphRCKrpPG+xVRXr/5sZ46XG9EGy1DdCGvjGTa9slQa0MpEg3hiJmOrGAY8GBHZB/ x1s2rXAOUPEo6Gf3R7Pbv2BQI5a1D94hGIGG5jLVsN+VbtYSrN/dkmtX/I7Z2FPePZoh T8LgyKXhxOd4dXnnesWFpTDoYPWs722LjPUvNZNn0L5mBMjxmWWfHUcmOe8djLRJCXdL JgOqhubGG4/mPaenhfgZ9wETCPebgMBysHR6c7hhJM64idc8bf/QBMjOaDmg4sJAbwZy TH6EudBGkDbcKiXeb85YFbTqh0jT3iPRNQOhRcLl5kOO043PTdNiILrKoaD+O0qmU/aa 0biQ== X-Gm-Message-State: AHYfb5hWgPBD7jJdWMrBGrJKJ8bKY7HYgof+JrTqIl1XUviLm5AfDkei WMbl120IFv/QduUJu9q3Zg== X-Received: by 10.28.218.148 with SMTP id r142mr751883wmg.20.1504082925806; Wed, 30 Aug 2017 01:48:45 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:b0b0:ba2b:b9fd:8a33]) by smtp.gmail.com with ESMTPSA id q24sm4032811wrc.26.2017.08.30.01.48.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 01:48:44 -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 (open list) Subject: [PATCH 02/13] thermal/drivers/hisi: Remove the multiple sensors support Date: Wed, 30 Aug 2017 10:47:26 +0200 Message-Id: <1504082857-21702-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> References: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 | 77 +++++++++++------------------------------- 1 file changed, 20 insertions(+), 57 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 8381696..92b6889 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,11 +54,10 @@ 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 Wed Aug 30 08:47:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111292 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp597781qge; Wed, 30 Aug 2017 01:51:32 -0700 (PDT) X-Received: by 10.99.186.73 with SMTP id l9mr836411pgu.178.1504083092771; Wed, 30 Aug 2017 01:51:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504083092; cv=none; d=google.com; s=arc-20160816; b=xwEQsAPyCi041LwSKXnKJyKDOiDFMfsgoYcY1M/vbJvKb0fHQJ/k8RPzjrFMzM3yzk cP28id9+0Vqs3NuvgehChvLcEBmIdvNC/AVUumn8N9ERxjv5yyjyRyexj1HlEXE163dh NawhuyLSTV5ZtWk5VRlHcLTOLrdmf085fv2djZSDve0arPWuxLKtbEjvsZ0jhYA0+xVL EMGENnsOyueILUeJyf4g+8oWrJ8iMZ98yXbP2l5engGIoir4TGtBKgOENm/f943ov4cr i7wH2AP7CeHnYRXdeWlq0JiZ6Q46/Vxp2C4Jn9Mhg7vYkbRSAY18X7V0qzG7gFmdlxPY 8xig== 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=uVfbmmx54HOtZ3QnvMk62tFTHAWiTh+5LBOf9rt7w8E=; b=RyXbQfTZ9alkbiZIGI5zFmH8WUa9Srz2FQoe5z+6mdWRUTMLBRrtbAFL/doHjzXUCv /D5Nas1GnELMHodpYMwxf343j+D9ys9oAzfTLa6x95BQp3ojqyrbhG7SN6FvHDXA5huD k5oW+j+9Rxu8S9raUw1nTCU86glK8iYqAZZN5dH6Uc8+7mMcU4hIfBVnC071Ai3mPQDS 3eAUq6pRgF1ipmjt4fU2SnrXFS4bBi0w232LovFe4Qs7oc+348wFAQlL60TPK4BVlwQ4 ttTLA9b+TBcxp52NTwnfaR1Q2yjWsd9zNxWBWYuNFNUoMhZ0j8bmNYccc6LPU3zPzy0V cLsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ATqmiBrY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 b6si3903244pgn.316.2017.08.30.01.51.32; Wed, 30 Aug 2017 01:51:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=ATqmiBrY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1751675AbdH3Iva (ORCPT + 26 others); Wed, 30 Aug 2017 04:51:30 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:38059 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751425AbdH3Iss (ORCPT ); Wed, 30 Aug 2017 04:48:48 -0400 Received: by mail-wm0-f47.google.com with SMTP id t201so6047392wmt.1 for ; Wed, 30 Aug 2017 01:48:48 -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=uVfbmmx54HOtZ3QnvMk62tFTHAWiTh+5LBOf9rt7w8E=; b=ATqmiBrYZZFTG2VZVl9nqQ+zWkHg3rKebEa2hvtPmxdsJaFZl4lvKMq0gMc3zaM3WV w4OmVossNfKleoMOqWPrpYrxHsm9nEKKjB+tvanhI1LiZBv/3VU9nNIQTePTVNeI23oF LJ6wCi90Qj8SheFtu4gr0ZXQD04LT3dQf75TM= 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=uVfbmmx54HOtZ3QnvMk62tFTHAWiTh+5LBOf9rt7w8E=; b=Ev67YzZI57otPpVzEi80Xn4T9irxby2O9Z447pT57w+W0WRkMXExMpYCeNKKCPBt6c WNSuGQ3EL0hKB9ftaRBcralmrUyRf/xo/6qwQF0MC+iXZBpZgCFjBeZRk+4tox27KrWJ sIHui4xK0zkdaR2aCikjcy/Ok+EoJ8sQCAPDGP1p1WEmYFlTOFJbq410VNDAehFquS88 TwKBwYLX7tMj+FcTV9vqYiezXkRuhE+6hZ97P8Hpcv+k91y8NaKtZh/ebWQwKbSXAMat PecLpJcc8kS/qumza4MP+gyn7+n5T70tXNhY4qHwHpFBYTk0tJMtkdWCQTnkfx7ZTL8k BIBw== X-Gm-Message-State: AHYfb5hZ3l5roMilQT5fQVyZ8XETFIas9VTRbBND5VXD7Hz2cb+aejsv 3hODN5rWHM+poe16 X-Received: by 10.28.56.2 with SMTP id f2mr729422wma.157.1504082927275; Wed, 30 Aug 2017 01:48:47 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:b0b0:ba2b:b9fd:8a33]) by smtp.gmail.com with ESMTPSA id q24sm4032811wrc.26.2017.08.30.01.48.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 01:48:46 -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 (open list) Subject: [PATCH 03/13] thermal/drivers/hisi: Fix kernel panic on alarm interrupt Date: Wed, 30 Aug 2017 10:47:27 +0200 Message-Id: <1504082857-21702-3-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> References: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- drivers/thermal/hisi_thermal.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) -- 2.7.4 Reviewed-by: Leo Yan Tested-by: Leo Yan diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 92b6889..67db523 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 Wed Aug 30 08:47:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111283 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp595170qge; Wed, 30 Aug 2017 01:49:01 -0700 (PDT) X-Received: by 10.99.167.77 with SMTP id w13mr813133pgo.448.1504082941309; Wed, 30 Aug 2017 01:49:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504082941; cv=none; d=google.com; s=arc-20160816; b=DVE1NRM0T+1OzZDGEje3GmOBp33/F5UOxPoVB6BDL9O0XYzWV9vOefZts9+iK4v7xc lpyx7kCZxrg1O2XbSViIDucs8CQ2+AglLDwr76Q/0L5tTUNAUb+UI6GgnbZ+Bvy57Ws2 ROetCZRXUaspAOyJTilM0zF/rv0VTbHoKvy8dhwJq9DEDzivN9QWmkwqpxRVAYohBqoX SOIAKOyuEIRQjOy/rPXu6m5FnnKKncLtJe7nj9XMwHjImyC58zuTajksNZfDSZ7+rOW+ OhP4oqdZcDCERlGLfNN+XMU1gqdQ1XtX+8zgu2+mwPsYgk/4ESg2mwIRcpjZ2uNtQDB9 e56w== 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=4HbvK6BUvYUgvRAgNOEcC64tIt4D3NKLKxpXvAOgmPg=; b=Rs1Yw5ihWzuKDzZDBYJKhYJtk9InLwYzus2NcWpdgjm5PmExanuFbP0b5b56pdsQEj 3iQCMPS7/bWUJIIUYNtQQ75qb1Oj8MrKCyj3O7SsDYC52b/Z3R8TwvADCxFtZNPcvpvA kWpd7v2aniUej6Dwuur4nNUacud5YzQlXTVCouRqVA5MfCaHSqtz2kzwylFBOx3VhdFv +ooqj9950kBlGuaEg+lEzcrg1XLp6DBrvG78qLWEMlL0Tp0a2750LxaypIu0j28+flxY qySP9nMbhF6ngxKXsC9c2iF/XkO/qm6xdZmbj7ilHbznI35+7ahCNJTRa7UMX7qXCuXY qNQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xe4KQp+N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 i7si3903435pgt.598.2017.08.30.01.49.01; Wed, 30 Aug 2017 01:49:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=Xe4KQp+N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1751586AbdH3Is5 (ORCPT + 26 others); Wed, 30 Aug 2017 04:48:57 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:38079 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751408AbdH3Isu (ORCPT ); Wed, 30 Aug 2017 04:48:50 -0400 Received: by mail-wm0-f48.google.com with SMTP id t201so6047932wmt.1 for ; Wed, 30 Aug 2017 01:48:49 -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=4HbvK6BUvYUgvRAgNOEcC64tIt4D3NKLKxpXvAOgmPg=; b=Xe4KQp+NJsz+R2ITTLiPY482Z9gi8djDg9d0nlELo18D69DTTJdAU+pcBrr2O9QEH8 y4WtHzoGbQXzSgGI9RenD1NVKkBo6buEeXoLt7HJpscsv14CvcW0/dHgWV1F0gXAlMPt cTPa1ZABohT/EojvMmlT+fuBcaKCictjv3u/A= 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=4HbvK6BUvYUgvRAgNOEcC64tIt4D3NKLKxpXvAOgmPg=; b=lyr1lbwRYfU/zyO52EbT2t7GIcRuD117SEsD7a22Uecf3UlrnrVGNrx6XCKz4gx+9V 56eOS+OKscBInXYJewAXZonKpDh8xkF77+8z8qsB3gFVrIvSD8SvaeWP/kGfuhofLDek Yu5/UC3xllpcEkK9M7PwXu6uQ+JQKSWvy1PBpcDRBcsfdlwAtgAGf3pUikgp/ZHbGM8a tlLBphybg21cDvUunhua/vpZJU5vg9vVG32my1TXu0Z+M9Ikrp9BL3+RhEEdYrfabsz9 LEWaygVxtPWtt1Dqf0oCNZ73Qlu9rG4pJeICkG379by+J2xQFlSArMyFocUFMGvrL/1G LW3Q== X-Gm-Message-State: AHYfb5gKf4qsU/CQsFI9fvMrQkn2+ReKK8DBIDrMUvvuWGO04UrYT8p2 vC7ctwfAn+8OwbkShiaMeg== X-Received: by 10.28.134.133 with SMTP id i127mr800148wmd.162.1504082929113; Wed, 30 Aug 2017 01:48:49 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:b0b0:ba2b:b9fd:8a33]) by smtp.gmail.com with ESMTPSA id q24sm4032811wrc.26.2017.08.30.01.48.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 01:48:48 -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 (open list) Subject: [PATCH 04/13] thermal/drivers/hisi: Simplify the temperature/step computation Date: Wed, 30 Aug 2017 10:47:28 +0200 Message-Id: <1504082857-21702-4-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> References: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- drivers/thermal/hisi_thermal.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) -- 2.7.4 Reviewed-by: Leo Yan Tested-by: Leo Yan diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 67db523..b58ad40 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 Wed Aug 30 08:47:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111282 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp595119qge; Wed, 30 Aug 2017 01:48:58 -0700 (PDT) X-Received: by 10.84.194.195 with SMTP id h61mr1025279pld.435.1504082938718; Wed, 30 Aug 2017 01:48:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504082938; cv=none; d=google.com; s=arc-20160816; b=iF6HeBtpWPDzcqSLkfwsJZono97SPDQNGaonlbYztYP6BJI7ToIq023DOj9Z1nzjUF ko8uOeV7lodIbgOCIO2Pniwr6hli+AUO/Ln6UvxGmiOr3vkWkQ16vpOilfmoTqEDHCcs YeRg6xe3ajUaN/gFP0Q+xEugQQIbeU9Jpxr9+kAgZnRigyvlkIZ+wxenc/aqkGNiIkzu zadLn255G9vTeVgH2hHRp4lTDoiQBDCVgJ6uDKcAltOvkw7LGOVL2CGK6TMN0Jl2wVTG APfcBANLst+8VRJRxDe9mrNuF9QBps/UEMduKCjA2Fjle6DlEGWHi5u1vwAh7dt2Ir4V x/pg== 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=4+rAp94M2r7NZFrIVYg29+O5v7953i37MtsvlqJrtR4=; b=TNqybdrkb4501BRtC61+fBEvoLhuvLOUnyE7PHOLsAhWS6y6PyoE/+CHw5w0eRrIi9 XK/zRdRvG4tn46glVH1BymtJZkZNGj2irox96DTKNjbUxyaQi4SMFaophFFS4tc6Jpu2 ytzTbT5VH1PcBl/zbTO5ebhexi+XfW85hnSmEAqld1xQPJcq94iX7hFE7DAs/KSbbgfY JKyNdNjviGszZDOF7Mr61kbsXDCpZTvsL2cSQxUl87BZh1/QX9gA9gYHMswzmO712bUR yXG19smwB5OCWqR3BnesKRlI9kQ3l42K9dbZbiCC251cvqHIourAeQcCcjjSjw62VJEM hURA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SsnBMlNu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 i7si3903435pgt.598.2017.08.30.01.48.58; Wed, 30 Aug 2017 01:48:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=SsnBMlNu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1751547AbdH3Isz (ORCPT + 26 others); Wed, 30 Aug 2017 04:48:55 -0400 Received: from mail-wm0-f43.google.com ([74.125.82.43]:38096 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751484AbdH3Isw (ORCPT ); Wed, 30 Aug 2017 04:48:52 -0400 Received: by mail-wm0-f43.google.com with SMTP id t201so6048426wmt.1 for ; Wed, 30 Aug 2017 01:48:51 -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=4+rAp94M2r7NZFrIVYg29+O5v7953i37MtsvlqJrtR4=; b=SsnBMlNu2WwG5mCcWJJtk8rkVBoI1V7V48t/zKizAgtit5Wn46GVdr8bUc5Xl4Ko/B /GwZkJ6OzuY6xANOAqz0WgEpcwLdxv1Il+g7GVklO9GryWG/ZeqeYjy/mMFkJYBYyLK2 7nHYixj4gTi62vC5hbMDfz8Hr1YjHJyXvVJ44= 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=4+rAp94M2r7NZFrIVYg29+O5v7953i37MtsvlqJrtR4=; b=OJBaOZeGHfiE67eF+kpquTDtdDdT2PMUsAirqiLkK3b4taVRI8uWKNkwhXUhIaHMBT IF7GenNK5zEYB8e2y61izBGU7vgFm/XZKxeV1ntaKfXZDjRndmbaAweevdwuANLr/ONT 8O5tF9N7mVgnnLUoz2PdiuF0Ov/pHjZdzoGtqKnXRqEz+jOVUrL44JTv58YDT1r2/559 lEpuqznfi2nh+Yi2nPknaA3K2Uh1mxs+RF94ZGiokPWx+nrIi9KZh5OYzCeasToX79Xo 0zBb2drONygUmDZ0FIitSbdIoBMUugYPhLGn3PyrpB0/rWF4C6wFPoJderVEIQO3QiUF bPJw== X-Gm-Message-State: AHYfb5h5ZkB1bblsmU/fdxJuMEPVGi1Xhx66wd1ckE3v1rZDddRPmuwv qV25jNvRDWzQIcNp X-Received: by 10.28.109.81 with SMTP id i78mr803211wmc.24.1504082930946; Wed, 30 Aug 2017 01:48:50 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:b0b0:ba2b:b9fd:8a33]) by smtp.gmail.com with ESMTPSA id q24sm4032811wrc.26.2017.08.30.01.48.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 01:48:50 -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 (open list) Subject: [PATCH 05/13] thermal/drivers/hisi: Fix multiple alarm interrupts firing Date: Wed, 30 Aug 2017 10:47:29 +0200 Message-Id: <1504082857-21702-5-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> References: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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 b58ad40..524310d 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 Wed Aug 30 08:47:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111291 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp597205qge; Wed, 30 Aug 2017 01:51:02 -0700 (PDT) X-Received: by 10.99.96.21 with SMTP id u21mr810232pgb.400.1504083061928; Wed, 30 Aug 2017 01:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504083061; cv=none; d=google.com; s=arc-20160816; b=tpgQZDjJbPWpNYEIEgiq19K4MDk/8arhs+eE45velkDcfb0KVRFgj2VFEgxQXrmgTX ffRAUFmsO0SaW14eEqJiIaAIdBbmPv1hm2D3eWFM89Cr1+zVmG/S8ve6yrQWC70r8ubf jbYx7EyK0lN0Hbl5ofrxXxxqL3CZ24OG67kwZMc5hcNeKyApepzsB6NOVJO9lVyI7iNo ust8lO3vunfLtlAF0NjX1xzt6awTSXZTXCn40Q54CVdp/qJ7d4cvnr30Falkz9KZlhyh XeZwRGdPmt/oGW+k9Yvb5lmQXL9Bc0Bvl/5kInDAfj0NMhl/cYSuDLrHkQSywfF8WBxl /8mg== 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=FiACXre4j1zDHJFAozRZ8XVINlP9M64l5RYa3Gl2lig=; b=Xu9xNdV4jZX9S2DjDVn9vRFqInOzFeU9pdkpuV9w+E0OFAjmo9NZXQxC6y2MwIsvqM WNuApQ00dBkS7vKZXyYXuwBiEwTWXUP78v2CVYze4qMQZiFLmzn21JqovhQs6um9Ukz4 Ymn0WdOk9Xh1/WTe3FNiKfNLN8R+mDKqrrY60UZqkb20688LrzWXzkSb2Z0B7yP2R3BN A2F3XO6pdehSdYayCGEN2j9c714YIGj4SxKKIxr+0psZfGb6k3JLygC5WrBMvgXs796r //xEGXWTyModkuPlquw0Rr5NtKpXdv0FxokZlwX98vw/yjqX9j23HSekrO/aQ2N+hTxs +HQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jEIcLZUD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 a7si4121985pln.393.2017.08.30.01.51.01; Wed, 30 Aug 2017 01:51:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=jEIcLZUD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1751871AbdH3Iu7 (ORCPT + 26 others); Wed, 30 Aug 2017 04:50:59 -0400 Received: from mail-wr0-f176.google.com ([209.85.128.176]:34280 "EHLO mail-wr0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751488AbdH3Isx (ORCPT ); Wed, 30 Aug 2017 04:48:53 -0400 Received: by mail-wr0-f176.google.com with SMTP id z91so16540471wrc.1 for ; Wed, 30 Aug 2017 01:48:53 -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=FiACXre4j1zDHJFAozRZ8XVINlP9M64l5RYa3Gl2lig=; b=jEIcLZUDuoiZ+g3IugB23GGhaPNlb319S54AIaPvtwiICYsWUg+eRkCsZQwhgaW7nI STZb6aNf8EJ8si/0nP61cy+0RBDVnL+NlN56d8uPqM7pb8xmO8eAXmDv8Qlga6F6OslS PrNsyKeM6H7jNJ/wT/meqhE9JpZ7Z0K1pJJFM= 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=FiACXre4j1zDHJFAozRZ8XVINlP9M64l5RYa3Gl2lig=; b=IY/feSCOMR0BwiIykYhZf36HDZ6Tn1joYqv3/5As9TrO1zu4NHSKP+MnP4yV3kpMiT pe+Rrb21sVmM/w6bgmPfMxSkPRQiSaFQ45bbM81jCG+nf2FYurLYug3os1HGmtII7pPS JjLeRfMF8zB4JnR3ZgnWJpdYJuSzDFUNQjpWpCa9+ygWGcKubSiPL5QbyvnavaZu1Suv Gq4f1DOLtbip5yJt/bIhGefjyAny1dNrOftK4j1qH2b2ub3C+kvle0zWZVkw25qTflQX wxMIjF9vMIJtm/qjUUkROa9E+CiDDviuneE+EkoTm3ftN2ibcWgQF9l6osobIzCtENJ9 Js1A== X-Gm-Message-State: AHYfb5jucKxMRjDOQPxc/msP5EKxzbK+n5q3cMpSyS4y3Wr2ody61fg5 9li+RDAs3kItXUJ6 X-Received: by 10.223.154.73 with SMTP id z67mr547184wrb.136.1504082932355; Wed, 30 Aug 2017 01:48:52 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:b0b0:ba2b:b9fd:8a33]) by smtp.gmail.com with ESMTPSA id q24sm4032811wrc.26.2017.08.30.01.48.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 01:48:51 -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 (open list) Subject: [PATCH 06/13] thermal/drivers/hisi: Remove pointless lock Date: Wed, 30 Aug 2017 10:47:30 +0200 Message-Id: <1504082857-21702-6-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> References: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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 524310d..6f0dab1 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 Wed Aug 30 08:47:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111284 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp595217qge; Wed, 30 Aug 2017 01:49:03 -0700 (PDT) X-Received: by 10.84.224.7 with SMTP id r7mr1029423plj.273.1504082943687; Wed, 30 Aug 2017 01:49:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504082943; cv=none; d=google.com; s=arc-20160816; b=ke/LnvWrJ3bhVIgxjQK6UOyHP6qIjPkf5TQ0HGyIin784SqdZkjlh869fZBl1H8ZfO Gng99unyGSecNL1OepXiUWCdv4Qe2m0FVqziiEHOMCkfcMpnl0WC41PD07UOZQJZ/75B wA54VMYen19JaIdePJozNohyx7rAe/iRWskIOI+dg+jSeMomtfmp0y2fsHUBKKStWzxn nfpczcxEODAldXV+2zC2Oz13j34TagzT09sWfgEikY37ngDYIA6QakI39KEoq9vQXQ8m OLfLkWZcgWshTiV6UgO1/8xHaEOs+sSIjodxXS7Y9x7ryA3tLzrqF/OI16NCqXKMg0+o vPgA== 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=H7Rq81WC7FRzqlHCumAXThd9aHoX8pIoG37+155ge1U=; b=Eyr3Q8EWSKXLp18BGWb+5f4vA+YgX7tzLkB29aM3bcDFqoMntVCklfYpvMkL5cUtFQ 29X7H4EQkExko2tmiEdmuf0R7JwuT/YIMbFV41mnkBdEIMAOfUWR/piWt1522AxErOJa UYnyWD0PmiGkv+fm+DkGGI+H4wsiGPDRrNQ841yQSttpvvwG1I6zhZKcfDM4YDQybYT1 RNRgLE8K4X5yauscp9MYx4WYZ9p3bD6l34BUmD6JaISgXUkbtczbC7V1e64nuXwosYba +6jRSiHs84kVp+qhfiW1bWcOq6gm1GPuIDphEMTs18T5YKw3v4+opJjr4oqPATBifFRI jLSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ntxa88zL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 h185si3913779pfb.398.2017.08.30.01.49.03; Wed, 30 Aug 2017 01:49:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=Ntxa88zL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1751655AbdH3ItA (ORCPT + 26 others); Wed, 30 Aug 2017 04:49:00 -0400 Received: from mail-wm0-f53.google.com ([74.125.82.53]:35055 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751523AbdH3Isz (ORCPT ); Wed, 30 Aug 2017 04:48:55 -0400 Received: by mail-wm0-f53.google.com with SMTP id a80so5553042wma.0 for ; Wed, 30 Aug 2017 01:48:54 -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=H7Rq81WC7FRzqlHCumAXThd9aHoX8pIoG37+155ge1U=; b=Ntxa88zLXh5TtMyQiAh3wz/VFXtkSZ3zke9g/K3T0sjg/d07SHMxqOLhh6kp/qlmQD zBIjb/qsJyRzh5i33HBjfUL1LHpE71hBB/XrWuRHOLClF6Z5sYy8OKOJNkG96rShSjjf ormiiUbHp6ShvWQCmw9vmy3jlaJrQZF7ktde4= 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=H7Rq81WC7FRzqlHCumAXThd9aHoX8pIoG37+155ge1U=; b=ohgAWjsFtwsX5KzNT2l41r/agI5qcafu4TwafYODkcWrEzDOg/43ArdDeCQERfJJCG Z+8pWHyUlpiacRjfwuOzztnBtjXtc2OcRD4q00uJrQN+MyqLg2T+T3Oyhq4a1nEDys71 QiCdRfFprcMzFANkaOtBSDgxD6I1M4tM0CJzAnrlf4iAxxiPCyGEFAi8ANjXQ7jJ9LSm RUC/BrlG8meKzXPs+Ns0jSDB3bU9TKMlEp+XvmxVh9Dxh7QM1twJ8uhT0rxCLUkfgasX dnI0vK6EJMZNOei9kcq0t9Zjxfyo4w8SKcltfT9pmaM4UlPWgXziCjvEjWwH92kMu453 GcuQ== X-Gm-Message-State: AHYfb5hKOmG4rVOx+OZIz+/4OYEZoz4yOCpjWqtMniK9p5Ddme8ylpQ9 Q5Lz8ZfDUPQYs+DU X-Received: by 10.28.210.9 with SMTP id j9mr754965wmg.134.1504082933990; Wed, 30 Aug 2017 01:48:53 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:b0b0:ba2b:b9fd:8a33]) by smtp.gmail.com with ESMTPSA id q24sm4032811wrc.26.2017.08.30.01.48.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 01:48:53 -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 (open list) Subject: [PATCH 07/13] thermal/drivers/hisi: Encapsulate register writes into helpers Date: Wed, 30 Aug 2017 10:47:31 +0200 Message-Id: <1504082857-21702-7-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> References: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 | 96 +++++++++++++++++++++++++++++++----------- 1 file changed, 72 insertions(+), 24 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 6f0dab1..d77a938 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,29 +186,27 @@ 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); - - writel(0x0, data->regs + TEMP0_INT_CLR); - writel(0x1, data->regs + TEMP0_INT_EN); + hisi_thermal_reset_enable(data->regs, 1); + hisi_thermal_enable(data->regs, 1); + hisi_thermal_alarm_clear(data->regs, 0); + hisi_thermal_alarm_enable(data->regs, 1); + usleep_range(3000, 5000); mutex_unlock(&data->thermal_lock); @@ -169,10 +217,10 @@ 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 Wed Aug 30 08:47:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111289 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp596313qge; Wed, 30 Aug 2017 01:50:11 -0700 (PDT) X-Received: by 10.99.0.77 with SMTP id 74mr822932pga.294.1504083011024; Wed, 30 Aug 2017 01:50:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504083011; cv=none; d=google.com; s=arc-20160816; b=Qofkus2XlIKNbyyOEI0NOjNAD8Ys8mnH+GvtOpWSIUl9Vma/nOjNqH27cjyzMMPwQo m0UmSF4EbaWtHK1eaACN5bjqyQGFriu2xB1eZQG4OPacnGM1bE2CarDRjgBYZUnuIn5s bLLVMxB9xgluF6KI1NrbPp91o7NPWpQFtqbBnu6G2JqvfoMwajPg/PQGgx2dSoK4Vcis v4lnaSlV1KX2vAMlkYASGpiTEiRQ5QDBlc6Pch6RaUhOXSmyfZPpjblbfl9com53xxfM O1Pcz1OZ2VQymHSBOvb8PfnDxrApbiwrG/q4hQpysiSYxrnBmbxqoN2LnCr3oZwBweOs DetA== 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=Ofvd0lWOI5ALt8B7PA3KHEPduWTFCLCZ2xTNbrVN3DU=; b=CCeeut89zc7iyM1m5NGAgKh+RI4kT92verQIEbmjCguwavLXecCo5zCPwNF6VdqWaL zXu82TDH0dP4GChwaluXM07MHFJfrxbzyf+WzGZhqKnofiowUmtTq6h8+hTc/3bnHDbX VuWu8CATIBCdMg979sKczp+Lq7CD6Wd66RL5rVHFXUKRiuKRT98XoW/EerUSYt8a6wuA SyPa8yJoJEiF94sc9fTU6wGn04+pHpSKGXSWKFrQ4OaceSXKfVdjti6S8e6kctWWgOn6 Ol/imefjapXA6Pf6oN6Z5TKFM+7uY1SACmwHsCPKp4YznN0N7EI7KDqpr7jX5mwqbxkK 1Wlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Pcu2tnkU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 t6si3973304pgt.643.2017.08.30.01.50.10; Wed, 30 Aug 2017 01:50:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=Pcu2tnkU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1751839AbdH3IuI (ORCPT + 26 others); Wed, 30 Aug 2017 04:50:08 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:35084 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751589AbdH3Is7 (ORCPT ); Wed, 30 Aug 2017 04:48:59 -0400 Received: by mail-wm0-f46.google.com with SMTP id a80so5553870wma.0 for ; Wed, 30 Aug 2017 01:48:58 -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=Ofvd0lWOI5ALt8B7PA3KHEPduWTFCLCZ2xTNbrVN3DU=; b=Pcu2tnkU895jA4ocWh7io00dbuyoNKgxIein1Lfl7wvxHskOWeL9vy/XIKE4IDUquq fOes8Q9GKdCXtx/umMwAgTkv2gJt35kn4uRlFS8YuiFYh9Rp//JYt/Kto0RW8L/AWIqf 30XV15/X56TI+IhtZRNiDTrPRaKIKo1b9tquE= 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=Ofvd0lWOI5ALt8B7PA3KHEPduWTFCLCZ2xTNbrVN3DU=; b=gXc+RBWFzeEuHJHxEd76cKYH3BgTswAdyUYNNSPi5N6bui3NUJntVGVz8sk7x9Hja1 aOjHjGxclpMBYafzgEtdEVGegck8N8nXq0qsyLQoADItv+w5cEfaQlyHgrNpUBXB/5oF uDF9+VLuxJkILrX0UF6yew4CRC0erO+HDeez+P/iPHiCJHZHhj101dUuVtlUnOT/GK+x crh67ifN9JPvC6lsIK2YXBS1Np1XGhxWXsCZnUnoJzLED6LfF+gDi8w2QuBLv3Sx+81f QetCG2cLaG08JGfHu6/2ZEWfPmT21b5keT7onz3kGSQYyaAlfZhyLkoUI69HY8Uor3ov lIlQ== X-Gm-Message-State: AHYfb5gqeLh3r8A4vem2TbbEXgj8Pn4Uxon53ua488C+taL0pJqfQ+ga l96NYFEJOpmrq/DK X-Received: by 10.28.218.148 with SMTP id r142mr752198wmg.20.1504082937374; Wed, 30 Aug 2017 01:48:57 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:b0b0:ba2b:b9fd:8a33]) by smtp.gmail.com with ESMTPSA id q24sm4032811wrc.26.2017.08.30.01.48.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 01:48:56 -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 (open list) Subject: [PATCH 09/13] thermal/drivers/hisi: Remove costly sensor inspection Date: Wed, 30 Aug 2017 10:47:33 +0200 Message-Id: <1504082857-21702-9-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> References: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The sensor is all setup, bind, resetted, acked, etc... every single second. That was the way to workaround a problem with the interrupt bouncing again and again. With the following changes, we fix all in one: - Do the setup, one time, at probe time - Add the IRQF_ONESHOT, ack the interrupt in the threaded handler - Remove the interrupt handler - Set the correct value for the LAG register - Remove all the irq_enabled stuff in the code as the interruption handling is fixed - Remove the 3ms delay - Reorder the initialization routine to be in the right order It ends up to a nicer code and more efficient, the 3-5ms delay is removed from the get_temp() path. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 203 +++++++++++++++++++---------------------- 1 file changed, 93 insertions(+), 110 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 3e03908..b038d8a 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -39,6 +39,7 @@ #define HISI_TEMP_BASE (-60000) #define HISI_TEMP_RESET (100000) #define HISI_TEMP_STEP (784) +#define HISI_TEMP_LAG (3500) #define HISI_MAX_SENSORS 4 #define HISI_DEFAULT_SENSOR 2 @@ -58,8 +59,6 @@ struct hisi_thermal_data { struct clk *clk; struct hisi_thermal_sensor sensors; int irq; - bool irq_enabled; - void __iomem *regs; }; @@ -97,9 +96,40 @@ static inline long hisi_thermal_round_temp(int temp) hisi_thermal_temp_to_step(temp)); } +/* + * The lag register contains 5 bits encoding the temperature in steps. + * + * Each time the temperature crosses the threshold boundary, an + * interrupt is raised. It could be when the temperature is going + * above the threshold or below. However, if the temperature is + * fluctuating around this value due to the load, we can receive + * several interrupts which may not desired. + * + * We can setup a temperature representing the delta between the + * threshold and the current temperature when the temperature is + * decreasing. + * + * For instance: the lag register is 5°C, the threshold is 65°C, when + * the temperature reaches 65°C an interrupt is raised and when the + * temperature decrease to 65°C - 5°C another interrupt is raised. + * + * A very short lag can lead to an interrupt storm, a long lag + * increase the latency to react to the temperature changes. In our + * case, that is not really a problem as we are polling the + * temperature. + * + * [0:4] : lag register + * + * The temperature is coded in steps, cf. HISI_TEMP_STEP. + * + * Min : 0x00 : 0.0 °C + * Max : 0x1F : 24.3 °C + * + * The 'value' parameter is in milliCelsius. + */ static inline void hisi_thermal_set_lag(void __iomem *addr, int value) { - writel(value, addr + TEMP0_LAG); + writel((value / HISI_TEMP_STEP) & 0x1F, addr + TEMP0_LAG); } static inline void hisi_thermal_alarm_clear(void __iomem *addr, int value) @@ -167,71 +197,6 @@ static inline void hisi_thermal_hdak_set(void __iomem *addr, int value) writel(readl(addr + TEMP0_CFG) | (value << 4), addr + TEMP0_CFG); } -static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, - struct hisi_thermal_sensor *sensor) -{ - long val; - - mutex_lock(&data->thermal_lock); - - /* disable interrupt */ - hisi_thermal_alarm_enable(data->regs, 0); - hisi_thermal_alarm_clear(data->regs, 1); - - /* disable module firstly */ - hisi_thermal_enable(data->regs, 0); - - /* select sensor id */ - hisi_thermal_sensor_select(data->regs, sensor->id); - - /* enable module */ - hisi_thermal_enable(data->regs, 1); - - usleep_range(3000, 5000); - - val = hisi_thermal_get_temperature(data->regs); - - mutex_unlock(&data->thermal_lock); - - return val; -} - -static void hisi_thermal_enable_bind_irq_sensor - (struct hisi_thermal_data *data) -{ - struct hisi_thermal_sensor *sensor; - - mutex_lock(&data->thermal_lock); - - sensor = &data->sensors; - - /* setting the hdak time */ - hisi_thermal_hdak_set(data->regs, 0); - - /* disable module firstly */ - hisi_thermal_reset_enable(data->regs, 0); - hisi_thermal_enable(data->regs, 0); - - /* select sensor id */ - hisi_thermal_sensor_select(data->regs, sensor->id); - - /* enable for interrupt */ - hisi_thermal_alarm_set(data->regs, sensor->thres_temp); - - hisi_thermal_reset_set(data->regs, HISI_TEMP_RESET); - - /* enable module */ - hisi_thermal_reset_enable(data->regs, 1); - hisi_thermal_enable(data->regs, 1); - - hisi_thermal_alarm_clear(data->regs, 0); - hisi_thermal_alarm_enable(data->regs, 1); - - usleep_range(3000, 5000); - - mutex_unlock(&data->thermal_lock); -} - static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data) { mutex_lock(&data->thermal_lock); @@ -249,25 +214,10 @@ static int hisi_thermal_get_temp(void *_sensor, int *temp) struct hisi_thermal_sensor *sensor = _sensor; struct hisi_thermal_data *data = sensor->thermal; - *temp = hisi_thermal_get_sensor_temp(data, sensor); - - dev_dbg(&data->pdev->dev, "id=%d, irq=%d, temp=%d, thres=%d\n", - sensor->id, data->irq_enabled, *temp, sensor->thres_temp); - /* - * Bind irq to sensor for two cases: - * Reenable alarm IRQ if temperature below threshold; - * if irq has been enabled, always set it; - */ - if (data->irq_enabled) { - hisi_thermal_enable_bind_irq_sensor(data); - return 0; - } + *temp = hisi_thermal_get_temperature(data->regs); - if (*temp < sensor->thres_temp) { - data->irq_enabled = true; - hisi_thermal_enable_bind_irq_sensor(data); - enable_irq(data->irq); - } + dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n", + sensor->id, *temp, sensor->thres_temp); return 0; } @@ -276,26 +226,27 @@ static const struct thermal_zone_of_device_ops hisi_of_thermal_ops = { .get_temp = hisi_thermal_get_temp, }; -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 = &data->sensors; + int temp; - disable_irq_nosync(irq); - data->irq_enabled = false; + hisi_thermal_alarm_clear(data->regs, 1); - return IRQ_WAKE_THREAD; -} + temp = hisi_thermal_get_temperature(data->regs); -static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) -{ - struct hisi_thermal_data *data = dev; - struct hisi_thermal_sensor *sensor = &data->sensors; + if (temp >= sensor->thres_temp) { + dev_crit(&data->pdev->dev, "THERMAL ALARM: %d > %d\n", + temp, sensor->thres_temp); - dev_crit(&data->pdev->dev, "THERMAL ALARM: T > %d\n", - sensor->thres_temp); + thermal_zone_device_update(data->sensors.tzd, + THERMAL_EVENT_UNSPECIFIED); - thermal_zone_device_update(data->sensors.tzd, - THERMAL_EVENT_UNSPECIFIED); + } else if (temp < sensor->thres_temp) { + dev_crit(&data->pdev->dev, "THERMAL ALARM stopped: %d < %d\n", + temp, sensor->thres_temp); + } return IRQ_HANDLED; } @@ -348,6 +299,40 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); } +static int hisi_thermal_setup(struct hisi_thermal_data *data) +{ + struct hisi_thermal_sensor *sensor; + + sensor = &data->sensors; + + /* disable module firstly */ + hisi_thermal_reset_enable(data->regs, 0); + hisi_thermal_enable(data->regs, 0); + + /* select sensor id */ + hisi_thermal_sensor_select(data->regs, sensor->id); + + /* setting the hdak time */ + hisi_thermal_hdak_set(data->regs, 0); + + /* setting lag value between current temp and the threshold */ + hisi_thermal_set_lag(data->regs, HISI_TEMP_LAG); + + /* enable for interrupt */ + hisi_thermal_alarm_set(data->regs, sensor->thres_temp); + + hisi_thermal_reset_set(data->regs, HISI_TEMP_RESET); + + /* enable module */ + hisi_thermal_reset_enable(data->regs, 1); + hisi_thermal_enable(data->regs, 1); + + hisi_thermal_alarm_clear(data->regs, 0); + hisi_thermal_alarm_enable(data->regs, 1); + + return 0; +} + static int hisi_thermal_probe(struct platform_device *pdev) { struct hisi_thermal_data *data; @@ -390,9 +375,6 @@ static int hisi_thermal_probe(struct platform_device *pdev) return ret; } - hisi_thermal_enable_bind_irq_sensor(data); - data->irq_enabled = true; - ret = hisi_thermal_register_sensor(pdev, data, &data->sensors, HISI_DEFAULT_SENSOR); @@ -402,18 +384,21 @@ static int hisi_thermal_probe(struct platform_device *pdev) return ret; } - hisi_thermal_toggle_sensor(&data->sensors, true); + ret = hisi_thermal_setup(data); + if (ret) { + dev_err(&pdev->dev, "Failed to setup the sensor: %d\n", ret); + return ret; + } - ret = devm_request_threaded_irq(&pdev->dev, data->irq, - hisi_thermal_alarm_irq, + ret = devm_request_threaded_irq(&pdev->dev, data->irq, NULL, hisi_thermal_alarm_irq_thread, - 0, "hisi_thermal", data); + IRQF_ONESHOT, "hisi_thermal", data); if (ret < 0) { dev_err(&pdev->dev, "failed to request alarm irq: %d\n", ret); return ret; } - enable_irq(data->irq); + hisi_thermal_toggle_sensor(&data->sensors, true); return 0; } @@ -436,7 +421,6 @@ static int hisi_thermal_suspend(struct device *dev) struct hisi_thermal_data *data = dev_get_drvdata(dev); hisi_thermal_disable_sensor(data); - data->irq_enabled = false; clk_disable_unprepare(data->clk); @@ -452,8 +436,7 @@ static int hisi_thermal_resume(struct device *dev) if (ret) return ret; - data->irq_enabled = true; - hisi_thermal_enable_bind_irq_sensor(data); + hisi_thermal_setup(data); return 0; } From patchwork Wed Aug 30 08:47:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111288 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp595928qge; Wed, 30 Aug 2017 01:49:49 -0700 (PDT) X-Received: by 10.84.129.72 with SMTP id 66mr1070748plb.146.1504082989480; Wed, 30 Aug 2017 01:49:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504082989; cv=none; d=google.com; s=arc-20160816; b=AXsh0431yYEq9Pv6MzTxTKaueoaz0z2+zMk9B6yKPmkQxsFNKRQ+zKr5Eo6F6EC5r7 jjB9yih4vFFhmsL6o6sb0l4K2xPYfe7GO7H6KWC6Ttn5yDKTavu5CAIjqdCyZT7Otn6Z CvPB/gGkO7NBUfUbBWuo7/UDdU2WkzkbyRjqxZ740Au9Nu29OA4W2D9lwiwIfEK4bcVh rKFKMnSciy/Sy+HUWSyDb9m81nrsc8N8ujk/m+/X4swKHjqfvIUoRL0vgTG53SE3WIJJ 3Hg0U1OjR2gq02+N5vr4r/SfZetdwcRPfumBb6VocHPPa0NM3aL/n0/zd6HbS/WUfGOQ PnaA== 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=WeFOG+oviVc1VL7UA3v8s8FiVMumNIWhEvJpbkLKeNQ=; b=Wi+U35fOY/sbEbqZSHFLxWrLKV66zk0RXHixlTnn+u7nv7KrBkDifQ62Sh/9v+jm1A npBNhemzR1AJ5gv0d0krQ+/1+e/3ltOKwfXdwpHdmiLLvvoGDu/leqzf33OLPW3aNE+U lf2AbQZg7579/RYLCvJ+jiDcPAz4ETXYVSKIBIoioOG3f995LGsMMuzsktTlAQ2ctUw+ oNQ9Z5ti2hBhhjE0DOVqWxfbHVcAltf01rNCqfp4aLuC4Gt/m4dSCdcySvc1D6FKZ62P +Ru8KTqDzJmGoVOKKTLDZQ1hRbBjvhEecd+TIaFLvrKanBJLXxRdeuK1h6tQ5/DBJK1N 2pWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Dv4dzHxM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 31si4075898ply.343.2017.08.30.01.49.49; Wed, 30 Aug 2017 01:49:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=Dv4dzHxM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1751813AbdH3Itq (ORCPT + 26 others); Wed, 30 Aug 2017 04:49:46 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:38180 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751523AbdH3ItB (ORCPT ); Wed, 30 Aug 2017 04:49:01 -0400 Received: by mail-wm0-f46.google.com with SMTP id t201so6050985wmt.1 for ; Wed, 30 Aug 2017 01:49:01 -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=WeFOG+oviVc1VL7UA3v8s8FiVMumNIWhEvJpbkLKeNQ=; b=Dv4dzHxMjB3YYBUWo55pc3ASatUiyuAdV3XrxPB/9FHUPFpbWYvnePQh/Icgfep9hU qsLWae11Yq1BlQ79+CBWa4UFSlh4ITShMj+H1kFTw94nYlJpVVjUQGHX4I9dwj9ssL0N Er2O1zJUzvMbPA2rgGyrUcm7TpFYLbYOtcK3U= 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=WeFOG+oviVc1VL7UA3v8s8FiVMumNIWhEvJpbkLKeNQ=; b=Ir+plEiAZnJ0JncDHWsEZ63kL11bMhFmXtxOkYm9l0d5MxdkhWmGBF2D52PZCiLAbd QDQiRu3el8sGkFW3vDeOMCXU/E3z7AOpigoFopU+2/rsx6uP7VB74+AhpHqbuyOc+OsJ IJDlnfInVQWdb4EuMM2olQ+Fz+zDhYN41i3Jp6nso8XRNsDfhlYdgVt5Sgz0CtHC6tLY q1uSnttumoRjbIExxOxLFqFHJ2r2JiHsdtQaN0ER1Ze/pJyyM3De2rufPL28hMRy3pZu EFrjnHj27LLvjHoUetSejw9IoEK4YZKAFkAXOq50keI9ZsekTpFz+u208MXntgCgxafJ bUrw== X-Gm-Message-State: AHYfb5jr4oFCYhYYklp22FrmdkJHdOYIph5vOFFliXv3NpRSUwFXaakG /7B30YqIMsj0ROLZ X-Received: by 10.28.107.193 with SMTP id a62mr809597wmi.101.1504082940367; Wed, 30 Aug 2017 01:49:00 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:b0b0:ba2b:b9fd:8a33]) by smtp.gmail.com with ESMTPSA id q24sm4032811wrc.26.2017.08.30.01.48.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 01:48:59 -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 (open list) Subject: [PATCH 11/13] thermal/drivers/hisi: Convert long to int Date: Wed, 30 Aug 2017 10:47:35 +0200 Message-Id: <1504082857-21702-11-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> References: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is no point to specify the temperature as long variable, the int is enough. Replace all long variables to int, so making the code consistent. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 68b625c..9eee82b 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -83,12 +83,12 @@ static inline int hisi_thermal_step_to_temp(int step) return HISI_TEMP_BASE + (step * HISI_TEMP_STEP); } -static inline long hisi_thermal_temp_to_step(long temp) +static inline int hisi_thermal_temp_to_step(int temp) { return (temp - HISI_TEMP_BASE) / HISI_TEMP_STEP; } -static inline long hisi_thermal_round_temp(int temp) +static inline int hisi_thermal_round_temp(int temp) { return hisi_thermal_step_to_temp( hisi_thermal_temp_to_step(temp)); From patchwork Wed Aug 30 08:47:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111286 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp595332qge; Wed, 30 Aug 2017 01:49:10 -0700 (PDT) X-Received: by 10.84.231.199 with SMTP id g7mr1117878pln.104.1504082950872; Wed, 30 Aug 2017 01:49:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504082950; cv=none; d=google.com; s=arc-20160816; b=KPrOcPjQGDesBqKnl1GVMeQsX49fLhAA2fJtNspeEJQQmoLRQOmdpGXyAjTZY/XVyv sLOQgcwWxK0J7aVP+0Vlb82NnN9Zp9PmKpHp83BgPZ8ouEUuXI+XyudqFFYOU+Sm/MRb Qer+V4xjpgtiTnsq7/PIE8QUoLoZXHgG17YQ0e47OTC9cecq+UkKsUZ6EqVzN8ozTUwh iBNT9Cse4RuK2S15EWVBwZDFBCNg9tYiTsNn30pWcpYwMow8ly+DahgWI3+JMFRH8EYf zVIyyvNJ7DqZZJsJbgmDISWBfdiwsA/Fvxw4kkZmWP5bqD9o1F4jTFUAbreQBCTHq8uA Cn9A== 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=m87CszR4V4jz5bAZloLpCirPsN4I4nvqmJFsduiPhoc=; b=cd+VsLIHVn3KKqmiLl2xJx5J9DesH1E5mfjhnyDSheWPMxapqDVWGZAZiPiV2WsNkC tK/1JKO9bVNJ2vf7kLVMWv2dQfGn9YpIWzinOyf6zog1BM+J/iWj3IIMhiZ+uhY7ydxo N8/TJlNG3C3nu+dKryJwNSzo+pSSJRKFpxjdAfPHut6XvICV4FSsXzKBBBJIg3gRVHU2 dmmhe603ir5aDXp4CqrmCS8n5VKbmWbP78WzebGQmC5tLJ8QDTLd2qevaN2yYD3P1HMk pG77aD6WQl+RcD/OOSohFWDhP8ROe7NsOYEmbN2+hQ9lSjTOYken8PsBmRaZNYc6+WC6 efZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EzoUug7p; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 3si1242588pfg.575.2017.08.30.01.49.10; Wed, 30 Aug 2017 01:49:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=EzoUug7p; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1751724AbdH3ItH (ORCPT + 26 others); Wed, 30 Aug 2017 04:49:07 -0400 Received: from mail-wr0-f182.google.com ([209.85.128.182]:38406 "EHLO mail-wr0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751667AbdH3ItD (ORCPT ); Wed, 30 Aug 2017 04:49:03 -0400 Received: by mail-wr0-f182.google.com with SMTP id 40so15985268wrv.5 for ; Wed, 30 Aug 2017 01:49:02 -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=m87CszR4V4jz5bAZloLpCirPsN4I4nvqmJFsduiPhoc=; b=EzoUug7pH8lQFHDD0ry/zETPytTp+xzKMJc3A2x1K9k+1AbXsyz48KjAoZHNwSi/4+ r+Nfy04brZG4Eem/RSN6Gv6Ebyx5PV4cxmMVqiKimZHocMvIWns2OAVP7Oz1CMfxSbFj MHoYPAthjQJXvvm6vofd8U6zDSShhHm8uC8e8= 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=m87CszR4V4jz5bAZloLpCirPsN4I4nvqmJFsduiPhoc=; b=K71MtxuBr4un+10lLFkA2tsQf/2fbbNSpYlxLZpaQCXB44yOlSB5ErDB9EhIIMrgpt a4o31k/ovG/r+78TRLH/o/ZtWon7clIRD4ToYvZxxs3af4dKNjfCEDjHnVgf/h9w0g5L ewqd8sdugFhCPtbO1usmUhwkgQGjLt0PU7blf0WiTo2edfRyLyMvMluPweNnRkQtRd5O Hbx0DDQAT5X/+iq4geq5LDS7xidqzdxSc/pEHvJxfDdFscycYQf5J52yflqHsnIaFIui NFXkiuWJazfOc1nGr2pV3KyPGvQAxFW1ZO8xtDQjzT5c3Xd3vVDoNUykocif9dI0laGq YSSQ== X-Gm-Message-State: AHYfb5hVwpK4BcAjb4RYrGH4sw1+r6ObC7wUiQ8dFgtvkg39HvD2ZSZ7 1ws11k2rytTsr4Ns X-Received: by 10.223.143.3 with SMTP id p3mr389514wrb.255.1504082941836; Wed, 30 Aug 2017 01:49:01 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:b0b0:ba2b:b9fd:8a33]) by smtp.gmail.com with ESMTPSA id q24sm4032811wrc.26.2017.08.30.01.49.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 01:49:01 -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 (open list) Subject: [PATCH 12/13] thermal/drivers/hisi: Remove thermal data back pointer Date: Wed, 30 Aug 2017 10:47:36 +0200 Message-Id: <1504082857-21702-12-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> References: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The presence of the thermal data pointer in the sensor structure has the unique purpose of accessing the thermal data in the interrupt handler. The sensor pointer is passed when registering the interrupt handler, replace the cookie by the thermal data pointer, so the back pointer is no longer needed. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 9eee82b..b1b086ab 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -45,7 +45,6 @@ #define HISI_DEFAULT_SENSOR 2 struct hisi_thermal_sensor { - struct hisi_thermal_data *thermal; struct thermal_zone_device *tzd; uint32_t id; uint32_t thres_temp; @@ -207,10 +206,10 @@ static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data) mutex_unlock(&data->thermal_lock); } -static int hisi_thermal_get_temp(void *_sensor, int *temp) +static int hisi_thermal_get_temp(void *__data, int *temp) { - struct hisi_thermal_sensor *sensor = _sensor; - struct hisi_thermal_data *data = sensor->thermal; + struct hisi_thermal_data *data = __data; + struct hisi_thermal_sensor *sensor = &data->sensor; *temp = hisi_thermal_get_temperature(data->regs); @@ -258,10 +257,10 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, const struct thermal_trip *trip; sensor->id = index; - sensor->thermal = data; sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, - sensor->id, sensor, &hisi_of_thermal_ops); + sensor->id, data, + &hisi_of_thermal_ops); if (IS_ERR(sensor->tzd)) { ret = PTR_ERR(sensor->tzd); sensor->tzd = NULL; From patchwork Wed Aug 30 08:47:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111287 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp595576qge; Wed, 30 Aug 2017 01:49:25 -0700 (PDT) X-Received: by 10.84.217.143 with SMTP id p15mr1095139pli.160.1504082965391; Wed, 30 Aug 2017 01:49:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504082965; cv=none; d=google.com; s=arc-20160816; b=OqtTNfW30OV/digkoBgyuk4o6IRcirHQ3QHqTZrXN/QmpPR2T2Ba+Q6O32G79yFIYi sR8kW8uDm/bV6kUSu014JEilWheGmi5u5p1Ult+QE1mBs9yEM+W4awUx17JBxAYzOsiN 8v4vgn2kYeInCpTtpMqAxfO9rEtwXF2UtGED8+juIny236J1652Jm2brAvPHldPzHU+N OoSbJ4z2ksI2YXxnt8u9iEsFvGMjkDA2pEdPuOW/0t5tFky/RBekCesCRHOhUfjg7g5p sOHcOYSBdW+JsGiN0EnBhcVHuf+2MnQzOrL0XrhNEugIzhsuYOCEJZcEBrNQUNBibFLh n2aQ== 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=wwiB2f2240ZA8RntlKIwM3sfl30uKc7bI1Zm6/mVJzI=; b=JbqOY0+yej7+5Lge5dBIf58/CkPG8ylgurOQfDEws2yu0eiBHwppSrK/tFAdqgS94W oNgJNckTBpF99wOhz+VDGW2Nid7pia/0bVsvAWZYUXdeN3evagqN6l3FZnKvew/JvhF2 HfvrkytSgIl4cpbVgDuYgflljncn9JoyX75yFjMCUjPEYLSwdObg0apnJWA7A1fz8bED QaIoX5WCDYymaEWtv+IZVcBlZO/8FVGDf5Mf4W519kE/xziDho6qLTgLRnkJ8Hb81P5c 27PpPxPHWso9F0vIzVW2aF6mdqB8G48MB3y9L+z3F2g9VY+bpZ7VyvbISQtarn/BdFCc uXpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b0FkjWao; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 d79si3968449pfj.466.2017.08.30.01.49.25; Wed, 30 Aug 2017 01:49:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=b0FkjWao; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1751771AbdH3ItW (ORCPT + 26 others); Wed, 30 Aug 2017 04:49:22 -0400 Received: from mail-wr0-f179.google.com ([209.85.128.179]:38412 "EHLO mail-wr0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751622AbdH3ItE (ORCPT ); Wed, 30 Aug 2017 04:49:04 -0400 Received: by mail-wr0-f179.google.com with SMTP id 40so15985435wrv.5 for ; Wed, 30 Aug 2017 01:49:04 -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=wwiB2f2240ZA8RntlKIwM3sfl30uKc7bI1Zm6/mVJzI=; b=b0FkjWaoghCRVJeZLAthLSwQNG8M7KwA//r/7HAfiFroT8TS664Rea+0q8Xu5V8ahg cWSZR1JZQXbU1eO8ApQSOVGBkKk+ihgGsWukJW26XBwF/R427CQHD4fqKS1cxuCobuYG 6ub9+EM4s/ZLWCIh6271POC1aJiJNSGF69FC8= 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=wwiB2f2240ZA8RntlKIwM3sfl30uKc7bI1Zm6/mVJzI=; b=eLLYfI+b9LHvkrpF0KdsDcxijULi2epkpgXquQ9MnvjoFodPHPDWN5p1PzI5VVuq0G 7ag+35gSQFrT/WHqMBZH7XX9/WAHh0oybRYiahFGMw4zn4K/TxOQVyQfLmxOlmy+jWRt tZD/hIiWSx9Lz8kDxBN6UpnCF5wAqyu6AJrsFFKHR7NkgUThbfi5up0xIFP3iEZHsOzx 6n3U76Bmx97qfQFVkxHDXCmE3jLT5Lyh76uJars3HJQrWdVSlckLGooCPWKg0tMqoTP1 YDV1wp6tk9cuRgIwaPgsucqStNuXBxDWbZPDEPvt1gYQn9Szk+ZLA7fs5gyJlKeDJZ/s jBkw== X-Gm-Message-State: AHYfb5g+UzJY6ajMM9Csf9AAgnspo97jRnUKe7Hx5uT9hCFKc8mdJkE7 1J4Xmbad1cYhhooB X-Received: by 10.223.136.196 with SMTP id g4mr547467wrg.100.1504082943573; Wed, 30 Aug 2017 01:49:03 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:b0b0:ba2b:b9fd:8a33]) by smtp.gmail.com with ESMTPSA id q24sm4032811wrc.26.2017.08.30.01.49.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 01:49:02 -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 (open list) Subject: [PATCH 13/13] thermal/drivers/hisi: Remove mutex_lock in the code Date: Wed, 30 Aug 2017 10:47:37 +0200 Message-Id: <1504082857-21702-13-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> References: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The mutex is used to protect against writes in the configuration register. That happens at probe time, with no possible race yet. Then when the module is unloaded and at suspend/resume. When the module is unloaded, it is an userspace operation, thus via a process. Suspending the system goes through the freezer to suspend all the tasks synchronously before continuing. So it is not possible to hit the suspend ops in this driver while we are unloading it. The resume is the same situation than the probe. In other words, even if there are several places where we write the configuration register, there is no situation where we can write it at the same time, so far as I can judge Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 6 ------ 1 file changed, 6 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index b1b086ab..b9e8ee2 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -51,7 +51,6 @@ struct hisi_thermal_sensor { }; struct hisi_thermal_data { - struct mutex thermal_lock; /* protects register data */ struct platform_device *pdev; struct clk *clk; struct hisi_thermal_sensor sensor; @@ -196,14 +195,10 @@ static inline void hisi_thermal_hdak_set(void __iomem *addr, int value) static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data) { - mutex_lock(&data->thermal_lock); - /* disable sensor module */ 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); } static int hisi_thermal_get_temp(void *__data, int *temp) @@ -340,7 +335,6 @@ static int hisi_thermal_probe(struct platform_device *pdev) if (!data) return -ENOMEM; - mutex_init(&data->thermal_lock); data->pdev = pdev; res = platform_get_resource(pdev, IORESOURCE_MEM, 0);