From patchwork Mon Dec 3 13:31:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael David Tinoco X-Patchwork-Id: 152703 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6814535ljp; Mon, 3 Dec 2018 05:31:24 -0800 (PST) X-Google-Smtp-Source: AFSGD/XYrOvHEuhqF/2HPK8c65XtoknmkT9Pwei4j0McmFY4WmFNgFvbOSGhl2sQ6e+8W4uPT97x X-Received: by 2002:a17:902:f01:: with SMTP id 1mr15457004ply.143.1543843883871; Mon, 03 Dec 2018 05:31:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543843883; cv=none; d=google.com; s=arc-20160816; b=p6OrAcGuQt76wckYttagUQ9Ro3a6uoy6A0CzrArsufAZzzFTqMW7aawbe38b2LUL9x lUXA9WxuzpN66OkK543gOysq0QmhF+1jRfEoX3adnONaCTjaaHbbEkLAGdX2ODpKZaRH yIRZyKn+etp8WTDPVsBiU1vhgW+m7CR6vt7qjOue1VZuy5iqLFVT6w04QCrw6S/7vE6g 7N0XA5zjlVUnqdJF2EYOL0iWQ7/e61GguY1KKg9n/FRrIWq8xmmonuANMjucafgGMjiH 2rRDLZiEn9zJltt/08SbEbsnDtt3ect/s5PyxK/GdmgV8NGwmtc0Y7A4vXzCd/hBnwgr 9LAw== 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; bh=OZD4wbyF9EkTu7UJQPBSAQZkCQxHDTNWUeyHRP/NGb0=; b=zQNRSDhCtEBeNRM/XzbXE6D2Vp0EuuBK2MmPkHAOgv/85AD09zbiMkhPxrxAu8Q2w/ D7H3JXGMIv28BZJLyEDtv2P8WqNYH4Wmr67Q7bUxfcVBLcSBxirBDBaQzfthjVn50oTA c4CPQfUjCvAudznn0oY12QyR5+XL/xd40U5gIFbXqFRx1CHV+3gIkkHdb8qiScL40gmd A9Zn1EFZEFX1xyk0LsqCqDWBuIw/X53iLS3xzm3K3h7cKhqyUKAWTarS/4GMr4y8glUR fyvDyo44QbSVCXTFuWRvtnNOLbRWL5UbjDelUofiCjD7YMuHVYTK8s1MUSk7hnylgif5 EKoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RqdCl40+; 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 e67si3756713pfa.15.2018.12.03.05.31.23; Mon, 03 Dec 2018 05:31:23 -0800 (PST) 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=RqdCl40+; 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 S1725947AbeLCNcX (ORCPT + 11 others); Mon, 3 Dec 2018 08:32:23 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:42145 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726174AbeLCNcW (ORCPT ); Mon, 3 Dec 2018 08:32:22 -0500 Received: by mail-qt1-f194.google.com with SMTP id d19so13632268qtq.9 for ; Mon, 03 Dec 2018 05:31:19 -0800 (PST) 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=OZD4wbyF9EkTu7UJQPBSAQZkCQxHDTNWUeyHRP/NGb0=; b=RqdCl40+FY0B7VOb00rNWAsUW79xJnjUbWFl9432NeXaHrFrMLS22igSW/VN5fO+dZ d5kyIhP1b9LYcCssPBO56MppAcop1HMxmy3zxlmNs8NDcB5V0FDFVJpP4pLv3R1EMUuG TDvef2QUf6mcJcNybq7ZsfEWGwKA+DZUWk2WU= 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=OZD4wbyF9EkTu7UJQPBSAQZkCQxHDTNWUeyHRP/NGb0=; b=NBADKqEh//Tvay3iU/hC7DSnZSMnTyZqPV3Z4c/hCZuVVhlv1EcUrwTp//mBH1hjWf tOjCGkZLONRyZ6XXmDSHeQfqQV1HcbwJvBwoxt8lJNUji4D9UBbz7kq7RAAFHK0P45Pc vjHED8xfWgKLXHeWb37I7qK0yV+wAYponNOAvyXvtZJqykm96TZKA0UTGiaArKdw2uam krKu1D3rjt0/7VT+C8I4829XZtffcQHY4oTYmkZ/oodFkIEuMLfON56suzM4wv+ns8hn gL707P0I4EEmwJtE0OYoMi3Nu5FdZZRqvKJhY6BEs0VPRPcSOzqD0PExugZo8thupsGx Q4bQ== X-Gm-Message-State: AA+aEWa/sko9FZ0CXZpEsDpzLolj/BJzmc2Kq7lkumSVqBKlG3Rx0ezm e27ufEEYRp7pk2IO6RHazKDu1w== X-Received: by 2002:a0c:878d:: with SMTP id 13mr15631294qvj.8.1543843878814; Mon, 03 Dec 2018 05:31:18 -0800 (PST) Received: from workstation.celeiro.br ([138.204.25.29]) by smtp.gmail.com with ESMTPSA id r56sm8619112qtj.30.2018.12.03.05.31.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 05:31:18 -0800 (PST) From: Rafael David Tinoco To: sashal@kernel.org Cc: rafael.tinoco@linaro.org, gregkh@linuxfoundation.org, rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 2/5] thermal/drivers/hisi: Remove pointless lock Date: Mon, 3 Dec 2018 11:31:04 -0200 Message-Id: <20181203133107.4002-3-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.20.0.rc1 In-Reply-To: <20181203133107.4002-1-rafael.tinoco@linaro.org> References: <20181203133107.4002-1-rafael.tinoco@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 From: Daniel Lezcano commit 2d4fa7b4c6f8080ced2e8237c9f46fb1fc110d64 upstream. 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. Link: https://bugs.linaro.org/show_bug.cgi?id=4053 (PATCH 2/5) Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan Signed-off-by: Eduardo Valentin (cherry picked from commit 2d4fa7b4c6f8080ced2e8237c9f46fb1fc110d64) Signed-off-by: Rafael David Tinoco --- drivers/thermal/hisi_thermal.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) -- 2.20.0.rc1 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index aecbfe9fc8f2..0c2966c285b1 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 Dec 3 13:31:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael David Tinoco X-Patchwork-Id: 152705 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6814623ljp; Mon, 3 Dec 2018 05:31:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/VyKw2w4cySTD+azwwcfRC7qupGNR6qvWnAaOmIkZ/53g+c3lFpIt1dPUdFzWHtwQanUk9J X-Received: by 2002:a17:902:6e16:: with SMTP id u22mr15766174plk.175.1543843887712; Mon, 03 Dec 2018 05:31:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543843887; cv=none; d=google.com; s=arc-20160816; b=OrSGRHCzoSxPQe6uK07m8e86wTGDWm3f6lVjvMqjmX1AwXaDcSClsrvNslaO8rUYXD MSsjWbfOF1e5przFG2SafFbixqcmHsNiPWumqlxTbnzDzFvqPthB042F6NxWc9r3RSOl zPd3Yjk18xzTsKm/Z9Ych2B2MHDKcBqj+A5kitj5RJB8KFVTWSiHNON658pcq4/LPzU5 ojKN2j7vRiKqD7gpQ1ZNiZEm4Gq+IL0X48pLzTrFO324Nw2DLiSLXDVOjOYf4XcGFg2M rE3zBvEWoOxlZd2Qvh+ox5uqsFZcUPgU97bTaFSTH7LgX8ePVXgYZzgchyGbVTiyfteG Yy4Q== 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; bh=nFtnXOJk34JsfWJZd01m3ADJA/D8osfUhgPthbLAvEM=; b=j5WtwcOB7PB0ZPfU9QqNnCK1J9QP3Sce1y4sezyj4u5EbZkj/woGDfAnsGdJCZjtAl FtMACrEReKxUkDE36jcWx3Ielda59HX+tZgqCUUT+lnjiLmnsepKXMShlItVy4Zs9gAr lnruye3+1VTSkdC32DE5+ja7RVgMLiNStbN9fZMMuFItcz9zgSnmKNkHxTC/FyQv4QlC wl3SqKqbBx3ML1F4AEUrd47JkOuSeWlCIyqYbt3SB+6/7RrfWp7VgQgkck3Jn6IitXPT VmrDKRpLbz2M8M3vday7m7guq+8D0Eg3pn2qXHaG7AaekeJFQi4dER8pzQ7uLoDfU+y/ T11g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ES13xdpa; 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 t65si14244081pfb.247.2018.12.03.05.31.27; Mon, 03 Dec 2018 05:31:27 -0800 (PST) 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=ES13xdpa; 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 S1726440AbeLCNc1 (ORCPT + 11 others); Mon, 3 Dec 2018 08:32:27 -0500 Received: from mail-qk1-f195.google.com ([209.85.222.195]:45763 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726277AbeLCNc1 (ORCPT ); Mon, 3 Dec 2018 08:32:27 -0500 Received: by mail-qk1-f195.google.com with SMTP id y78so7265385qka.12 for ; Mon, 03 Dec 2018 05:31:25 -0800 (PST) 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=nFtnXOJk34JsfWJZd01m3ADJA/D8osfUhgPthbLAvEM=; b=ES13xdpahgCvbqHWUtmELY1obONm+Y+3+JXt50FkCXB/4HGKn13Z+qkCgs/EjvZ6g7 qmUbvuWVoc9h2x5GdehV3PvYW53kwkGzBRn/2PLyJjLhxxaUZredZoxqDJobBPFPbXwo R+0EI3NNt2z8nkopYhdts/bWzPq2Yeb7deKTI= 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=nFtnXOJk34JsfWJZd01m3ADJA/D8osfUhgPthbLAvEM=; b=kNTyI5Z+a3hZjMOmP35y9pu7jMGaNG+Z9lNPz0YEeGlVkASQx2PYVE77STHYhmQxNu w7+GiOzjrJBNp/LAyS01T8tFzXGwbkxMRGO/R8N+PdGtZmJE5Tj2s40xbMN0mbJbCl9F izJO5m+6oU3vA19rGjXH+Uv+7Uou4ETUWn1JhxDlaExH9J3EuQabY9Dv6WrP+fUAsJzp bMj9WW0elVduC/ZIiWDUzmhHEVYB1ue13pV4mKZW3FE9j+bqjAgYtQpegDZ18j2ZlHlg /X5PprmdEqV8XkKzDc7sADQJJtumlQ4Vo6Hkm18rU33vftfv/e4PYqmQ2zwPn9x4K9Vo RwwA== X-Gm-Message-State: AA+aEWadjOLMYl3ukvJuSCWx3gbRNn6mHV2djMilro5vKSne61mTxkOH dfr17h7L1z+uXpTErKLL6Z/ugQ== X-Received: by 2002:a37:6f45:: with SMTP id k66mr12779246qkc.313.1543843884761; Mon, 03 Dec 2018 05:31:24 -0800 (PST) Received: from workstation.celeiro.br ([138.204.25.29]) by smtp.gmail.com with ESMTPSA id r56sm8619112qtj.30.2018.12.03.05.31.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 05:31:24 -0800 (PST) From: Rafael David Tinoco To: sashal@kernel.org Cc: rafael.tinoco@linaro.org, gregkh@linuxfoundation.org, rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 4/5] thermal/drivers/hisi: Fix configuration register setting Date: Mon, 3 Dec 2018 11:31:06 -0200 Message-Id: <20181203133107.4002-5-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.20.0.rc1 In-Reply-To: <20181203133107.4002-1-rafael.tinoco@linaro.org> References: <20181203133107.4002-1-rafael.tinoco@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 From: Daniel Lezcano patch b424315a287c70eeb5f920f84c92492bd2f5658e upstream. 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. Link: https://bugs.linaro.org/show_bug.cgi?id=4053 (PATCH 4/5) Signed-off-by: Daniel Lezcano Signed-off-by: Eduardo Valentin (cherry picked from commit b424315a287c70eeb5f920f84c92492bd2f5658e) Signed-off-by: Rafael David Tinoco --- drivers/thermal/hisi_thermal.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) -- 2.20.0.rc1 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index a803043f37ae..31b52ebf426f 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,