From patchwork Wed Jul 18 07:25:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 142249 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp211708ljj; Wed, 18 Jul 2018 00:25:40 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcRrWkk5CFybx9KuvF1a8DXlYl4jYfixd/F2Sd8DKTbMkMO+f0/Ikr+/GjS9lAjBZRuAs1K X-Received: by 2002:a62:ce81:: with SMTP id y123-v6mr4086774pfg.95.1531898740239; Wed, 18 Jul 2018 00:25:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531898740; cv=none; d=google.com; s=arc-20160816; b=chp1WUcOJYdy9fGV05unsORnBC2B3uWiUGtHf3Z1yE5z2eMr4kIJ7Aghskvc5GgC0s sRiYUSj/0kzz1G08exvLN7hyZdPIE1lALkTm6etP1UdfATs/nHJtJeOUV3jNpeF15V35 LDkOqaQDIsuuO6vFyjAxxu/4kYovKkYkFT5rOHcq6T9tIycSpz/yZLxw4DP5BBLG8Z+b jUuC2xms51VaS9eFuIC6ZR+9+fZa3yrMb4a2kcsDghi4DXoSNImIF/OWFfOp9TgdIU8G hQ2q3ktDB0YdGzJjcKVXDiywz4bGXwdKDL4YeopN/Op8xdX1+U2jBFhhNrjh/AxpPGte rlag== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=VD2olbd9oQC1RGmU9iprACti8KCCG3wIJjoyBgZ3IoM=; b=MhCe66wgRK6K4FVG6Xswdew5wjW7XApv4RJR0uQmW8oMp4ouY2fpcV+wlr9dt36/CY UM59h038qVa8uGxZopf7K5vNbIRp29sJ3RMruiMZwU8ToXrLhp00Gq7+yr0orZPUkaPB 9pHgLMH/FiSlICz1OyBwhA7jwkzItfN10j06E56n9SiJCaOyuoMQ9O0K2ynXBVmBukN2 d0HS8Jk/YcBO2d+EyJhnVcjRZIE5JW6yOFwnO7n3KBWRro4yHZWmfqAOxmzcfxs3Bqha u3vWklwL4Cr5ladGTcp8SPmgUnH/3IVv8DdyNHqLhoUW1BRO9xSu2S59vHO/UvpIB9ra /C4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="M/Jo+vXV"; 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 k6-v6si2585736pgb.446.2018.07.18.00.25.39; Wed, 18 Jul 2018 00:25:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="M/Jo+vXV"; 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 S1729594AbeGRICD (ORCPT + 10 others); Wed, 18 Jul 2018 04:02:03 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45596 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729462AbeGRICC (ORCPT ); Wed, 18 Jul 2018 04:02:02 -0400 Received: by mail-wr1-f66.google.com with SMTP id c4-v6so3520936wrs.12 for ; Wed, 18 Jul 2018 00:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=VD2olbd9oQC1RGmU9iprACti8KCCG3wIJjoyBgZ3IoM=; b=M/Jo+vXV92GYMmp5IIJxWZp+PRsISVnNpXChlCaibp28Aj1WOgJc8ctyjRUcPy3qfy cSzhNz2CADP5c2t0MD6Iu1UWRNQIosmYqZnCdQWS4NBzRbV8cnsQjilvW/Vry1CwdHMY EIGhDWO2GSxqxyyj/UYxbngSBIs2Jz4Ccuxo0= 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:in-reply-to:references; bh=VD2olbd9oQC1RGmU9iprACti8KCCG3wIJjoyBgZ3IoM=; b=g4a5D79h5BiBfGZC9Hsoz2ghJrsa8FctjN9hj6HFuzQzDAJU4JRcrCBTlqPb2n0sTW KDwkvZwBPNuKCiGYajCVGJocWL+LyjqPvOlZ5QIIsss1Fxm2/Q112vXA6XQLfZ2csjPT KUfOuWS7uNT+LMPi0YiBVV4Iyrs0npM6QmTXyHmKJX4VMLLnjHqzJz+Q5BUz0l0pIXPC 996qipkv7EdpsnqJ6pmcjGFGCWL6G9IQsdmY5AFhhHI09u9WU1Au3jmRPOKlVxHiVDMn m3a2l/C+gzGTL9OpsdTH4MjbSioMWKd35XAjK/SlCNr59xxidSt4Xer+kZI9X3LITO4U cuYA== X-Gm-Message-State: AOUpUlFxlj1yq9K21lu25QaQd7wPJmGl/VlRHzxLZ3gxK+zjFmm3pTEK xabeV+yg2tgOJzmwGXBG8UObzw== X-Received: by 2002:adf:88e3:: with SMTP id g32-v6mr3270446wrg.62.1531898734754; Wed, 18 Jul 2018 00:25:34 -0700 (PDT) Received: from localhost ([49.248.170.255]) by smtp.gmail.com with ESMTPSA id q11-v6sm7220033wrp.58.2018.07.18.00.25.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 00:25:34 -0700 (PDT) From: Amit Kucheria To: linux-kernel@vger.kernel.org Cc: rnayak@codeaurora.org, linux-arm-msm@vger.kernel.org, bjorn.andersson@linaro.org, edubezval@gmail.com, smohanad@codeaurora.org, andy.gross@linaro.org, dianders@chromium.org, mka@chromium.org, Zhang Rui , linux-pm@vger.kernel.org Subject: [PATCH v1 2/3] thermal: tsens: switch from of_iomap() to devm_ioremap_resource() Date: Wed, 18 Jul 2018 12:55:02 +0530 Message-Id: <4dd9f01c2b5d6988c5329062c25ae61747b42a32.1531898088.git.amit.kucheria@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org devm_ioremap_resources() automatically requests resources (so that the I/O region shows up in /proc/iomem) and devm_ wrappers do better error handling and unmapping of the I/O region when needed. Signed-off-by: Amit Kucheria --- drivers/thermal/qcom/tsens-common.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c index 25e7f24..6207d8d 100644 --- a/drivers/thermal/qcom/tsens-common.c +++ b/drivers/thermal/qcom/tsens-common.c @@ -127,13 +127,11 @@ static const struct regmap_config tsens_config = { int __init init_common(struct tsens_device *tmdev) { void __iomem *base; + struct resource *res; struct platform_device *op = of_find_device_by_node(tmdev->dev->of_node); if (!op) return -EINVAL; - base = of_iomap(tmdev->dev->of_node, 0); - if (!base) - return -EINVAL; /* The driver only uses the TM register address space for now */ if (op->num_resources > 1) { @@ -143,11 +141,14 @@ int __init init_common(struct tsens_device *tmdev) tmdev->tm_offset = 0x1000; } + res = platform_get_resource(op, IORESOURCE_MEM, 0); + base = devm_ioremap_resource(&op->dev, res); + if (IS_ERR(base)) + return PTR_ERR(base); + tmdev->map = devm_regmap_init_mmio(tmdev->dev, base, &tsens_config); - if (IS_ERR(tmdev->map)) { - iounmap(base); + if (IS_ERR(tmdev->map)) return PTR_ERR(tmdev->map); - } return 0; } From patchwork Wed Jul 18 07:25:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 142250 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp211794ljj; Wed, 18 Jul 2018 00:25:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc13IfFf8qjlmqTD3T9mpRIKjVEmGMg4oFpS0gQpq/5iFM4hMeJiLmfVgEmB9CfxR54Z7II X-Received: by 2002:a17:902:4503:: with SMTP id m3-v6mr4294890pld.168.1531898746444; Wed, 18 Jul 2018 00:25:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531898746; cv=none; d=google.com; s=arc-20160816; b=NPHg8TxOv0Qete1PmAgIPu25SE8XdiSWu9RibyUXUC8qyuL9CI7X2t1QAfr1ciloam 7p+ohbZy8XQNy2AwYvmDsw37WcOh1doR3a9qtSIPWF04DTvq2yLEzZL7791ewtklF6yh 0sVU9SnlHPEyXsYdWpgJCoCE/jAH2jsp1dO5iLlcRant1Sq6Hgb2s52gSakohUerzQlK 9bsWdO+ais1Y2syulsHjWpq7pSlHWebK9TJ2/C9r/OA2nwyCp9EMDPmizkhp4NgJo5BH 3FXZLNyKs9vr1mUI+PJ9RNGMjNAq2cohWWU6zZyJBabDs7kTAvqMT3rAsDg4VokfFuxF o2zg== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=PRLjO4NtEBHF3gs51RwAFkmtv8s6MEbP/FrpA8XBlqY=; b=H9oFd2nt0YgQPoqgHCEXvpKj3+imAA1az0wXE3wDvtzOvomqTCNj+SBua6M0LgsjGs JYrjw+wknJSE8UlVjvPaA046tVEWMVDN0eNZCGuuP3emCXqKoBP2Loaeg4E72tGEp/8F oSgkQKW8FM64hSGo8fbryE+CBaZpxhB+YA/oKQHZzt/gWU1g7D/H3eIIKdmAlbq0Xubk GhX6PsRq5eOGplCNhPi8FiYyW9GS7+G8yvzFoTgoe3Fsfz8pYBlvAG1NC2Os7XRALpaX X4b5sCAspx2kCRloZlWreAZQ/XhaCC6UTX/F6l2Xeo0xLxk7fy5B6fGqCDtKyH7ov2EG V1Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e74zkUDu; 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 k6-v6si2585736pgb.446.2018.07.18.00.25.46; Wed, 18 Jul 2018 00:25:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e74zkUDu; 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 S1729861AbeGRICL (ORCPT + 10 others); Wed, 18 Jul 2018 04:02:11 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43548 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729462AbeGRICK (ORCPT ); Wed, 18 Jul 2018 04:02:10 -0400 Received: by mail-wr1-f67.google.com with SMTP id b15-v6so3524537wrv.10 for ; Wed, 18 Jul 2018 00:25:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=PRLjO4NtEBHF3gs51RwAFkmtv8s6MEbP/FrpA8XBlqY=; b=e74zkUDuqT7GYt7618dzrGPvIsDdZdmol4UIQI7axxkYed1TVtfj4ZJwY6PlJ2d29q nC2SGzUeH4zTybBtWaZvWBQkGZd7is9HONCvuWKREXkIlr6XAowV3p50GpVKkziAAOga GCRSvf6zZ1BMS1olVsjRH4AFVtu3vidCE+o4A= 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:in-reply-to:references; bh=PRLjO4NtEBHF3gs51RwAFkmtv8s6MEbP/FrpA8XBlqY=; b=pmV13olOjqW60V2n1PW7n/Lj2MdYVT1mBlStxdcviBsOHh/hL+WcOZYyFsU7MW6kpD aUObD7B1l7zP+Vfs2t7/2Q5dBH78qQppWY60H1TP37Gwjd6kBfEJRsoARH6HIFkVRkjh suGY4SEqIL1vRlfebkO/80Z/yiHOOLXcTQdVOjWUFOtQchtQYHWeeiocL7A+6pRuUdf6 2bOn1iXvow4OXgpEzbxaQMD1auhKsNbH7sPiim5gjAGKIZ/En4K7a11G1+LKan9LGPKq d5E+KC+C4m1GwihPYJp2ERVT7uSxDOuZ6fqiSnXcPMD5UpwsbJLLKni4ks3WOZc3hcMI faOw== X-Gm-Message-State: AOUpUlHUiAAqYZL+zjJkmh9k2SkDnWFgSjSBa0AUuMaf8ji5ofjk0XH3 6AP6uNrJpemFaMARoJnIg5k67A== X-Received: by 2002:adf:96c3:: with SMTP id u61-v6mr3477566wrb.72.1531898742996; Wed, 18 Jul 2018 00:25:42 -0700 (PDT) Received: from localhost ([49.248.170.255]) by smtp.gmail.com with ESMTPSA id l127-v6sm5729520wma.41.2018.07.18.00.25.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 00:25:42 -0700 (PDT) From: Amit Kucheria To: linux-kernel@vger.kernel.org Cc: rnayak@codeaurora.org, linux-arm-msm@vger.kernel.org, bjorn.andersson@linaro.org, edubezval@gmail.com, smohanad@codeaurora.org, andy.gross@linaro.org, dianders@chromium.org, mka@chromium.org, Zhang Rui , linux-pm@vger.kernel.org Subject: [PATCH v1 3/3] thermal: tsens: Fix negative temperature reporting Date: Wed, 18 Jul 2018 12:55:03 +0530 Message-Id: <42d6f2a6f9babd6351bd2fcde4000d5ca9c351ce.1531898088.git.amit.kucheria@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The current code will always return 0xffffffff in case of negative temperatures due to a bug in how the binary sign extension is being done. Use sign_extend32() instead. Signed-off-by: Amit Kucheria --- drivers/thermal/qcom/tsens-v2.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c index 908e3dc..46abc21 100644 --- a/drivers/thermal/qcom/tsens-v2.c +++ b/drivers/thermal/qcom/tsens-v2.c @@ -5,19 +5,20 @@ */ #include +#include #include "tsens.h" #define STATUS_OFFSET 0xa0 #define LAST_TEMP_MASK 0xfff #define STATUS_VALID_BIT BIT(21) -#define CODE_SIGN_BIT BIT(11) static int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp) { struct tsens_sensor *s = &tmdev->sensor[id]; u32 code; unsigned int status_reg; - int last_temp = 0, last_temp2 = 0, last_temp3 = 0, ret; + u32 last_temp = 0, last_temp2 = 0, last_temp3 = 0; + int ret; status_reg = tmdev->tm_offset + STATUS_OFFSET + s->hw_id * 4; ret = regmap_read(tmdev->map, status_reg, &code); @@ -54,12 +55,8 @@ static int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp) else if (last_temp2 == last_temp3) last_temp = last_temp3; done: - /* Code sign bit is the sign extension for a negative value */ - if (last_temp & CODE_SIGN_BIT) - last_temp |= ~CODE_SIGN_BIT; - - /* Temperatures are in deciCelicius */ - *temp = last_temp * 100; + /* Convert temperatures to milliCelicius */ + *temp = sign_extend32(last_temp, fls(LAST_TEMP_MASK) - 1) * 100; return 0; }