Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5612588ybl; Tue, 10 Dec 2019 08:43:42 -0800 (PST) X-Google-Smtp-Source: APXvYqwT4blPX3iL0eb0EQ0uamY7khKtGHnH657kPK0kOqMahaaCDJocxiildrIKmQf3cSTBOMCb X-Received: by 2002:a9d:74c4:: with SMTP id a4mr27312293otl.119.1575996222708; Tue, 10 Dec 2019 08:43:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575996222; cv=none; d=google.com; s=arc-20160816; b=hXt5I32Xv3JK2QhEtrJFBymq22QDn1V+/IGy+79ORMyKiyqu49QPqaH/T3QvZLKKI7 K2hMJE+7vkLI/vBo6fPh06Jhm8IT3FgUeIDRIhqv0u/N1szH1DywWqaT89O0JHLbCL/h P3hBO7Vdx9cC5+/oM6GQGNnnZyMBQH0lQ3LgIM1P9jA8Bo2RrDr0IsV3/9Hxe43bgJ/J +4lcLjvaojdSdwACYSpthdye4aou9eISGKx9NGiIXMON5fdIjidxQp+RyTLJ7mLwFZGG zvlqO7d32CWspwk/sDF7iqNoTZCJ/n+fGi/NJprCYTFZLrFPsD7j/kY7OgF3fzO8HfM9 3mcw== 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=jdPbCHrU2X5cb40jCnETs7i2ifIUn3Ola/UP2b4mOwM=; b=R1FJFkEZU40ajtVMI+51T9RfMqpO1P2slcsLWvJlhHTbPkobGgkGX0GFQitNdU7jLT YbDniSJDyoDt0vjeL6GSpX/1UKw6HlsnmH76YfhrQLrjIFom8X4ao0aGcknZMUgz08m1 wBfz+UaH6N2eOGqDdUg4wdgA3i8Px6rljlzAwrnOF9Vls9RKsnpKiSw+79xaiFB3uEVY 0U+V0ldk97bJuwOQD+59EhaqMnN4E2gf/szzUwh+amesDQZD69jIg/GVB0c9tOf2g0s2 564hfEOUuwc2nnFLKoiDP9edJzhjOhtQYz68hGcaYTALAnDxo3yGSIfuOzefKLHOQsAf PH6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Masq6otl; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j26si2051475otk.291.2019.12.10.08.43.30; Tue, 10 Dec 2019 08:43:42 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=Masq6otl; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727856AbfLJQm1 (ORCPT + 99 others); Tue, 10 Dec 2019 11:42:27 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:40252 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727831AbfLJQmZ (ORCPT ); Tue, 10 Dec 2019 11:42:25 -0500 Received: by mail-pl1-f195.google.com with SMTP id g6so90066plp.7; Tue, 10 Dec 2019 08:42:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jdPbCHrU2X5cb40jCnETs7i2ifIUn3Ola/UP2b4mOwM=; b=Masq6otl9D8o4RjM+csEhLQJelHQhLQftYTI7Vq2zmqnRdCp8gLt3kIYVKEWnyqFI8 lnFLUTaL6kiDNNp2bTBipgRDTIQ+BgbNrDT9sQJ89p/PvFgNxPmvl2z+FIj+rkVWaUtn Vv+WqZpFpa0nPcUHiVVvNxM2OHrMJzqIAT4PMLyy+0BVXqA7DgmVYhfaEkzgBpuWGU6u OBAU5FRp1vuraJ+xXeZeVu4O85V4cWC6b6hJiyUFMagOrwO9XkpXTvkqtyX7Z+x4YaAT fKhKGHZ7F9pgNyofbFKjJu1jpE7P0vUqy/yJWUgA7Wt81uBxp04hwKwO40PUx5hjlZMY +AFA== 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=jdPbCHrU2X5cb40jCnETs7i2ifIUn3Ola/UP2b4mOwM=; b=gTV4zw4RibJeNVB6JDiOAZBtSxskwuo28ePYjTqEBKTGCvJ00tgftUnDnTJgVbLyEm 065W3HyLdVd6unYBgs2Q5EbHXm0bC8bL4Bu96rpQ9+jR32WRPnAXPZ7W4AAlDm5W408R ap2/4SuDUKFmnMu1LPQbOYwRlntCRe44TaMQvt7+y6nETiS68cWYEtNeS49wcl4dHPHf zAAILV4sA2TqRz22ClEAsgykQHltTFQ+0YpERJMc3Ov0Kk7TrlFcSkxalz128UBFwYbJ NfQhZXmZMIru7AFdjH89aC73zkrxKkgSDFlZNfLmC9YWj1PafhWWmnRlFr/Lh091/K9W EfGw== X-Gm-Message-State: APjAAAV4IcLLcVGvq6RUQfCFas6+te68IhnbX7KaB0Jr+vTjXshOJO5i Nfef00+niPeuhnWN0C5F62s= X-Received: by 2002:a17:90a:8989:: with SMTP id v9mr6398145pjn.119.1575996144681; Tue, 10 Dec 2019 08:42:24 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id j38sm4034634pgj.27.2019.12.10.08.42.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:42:23 -0800 (PST) From: Andrey Smirnov To: Daniel Lezcano Cc: Andrey Smirnov , Lucas Stach , Chris Healy , Eduardo Valentin , Angus Ainslie , linux-imx@nxp.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 10/12] thermal: qoriq: Do not report invalid temperature reading Date: Tue, 10 Dec 2019 08:41:51 -0800 Message-Id: <20191210164153.10463-11-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191210164153.10463-1-andrew.smirnov@gmail.com> References: <20191210164153.10463-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before returning measured temperature data to upper layer we need to make sure that the reading was marked as "valid" to avoid reporting bogus data. Signed-off-by: Andrey Smirnov Reviewed-by: Daniel Lezcano Tested-by: Lucas Stach Cc: Chris Healy Cc: Lucas Stach Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: Angus Ainslie (Purism) Cc: linux-imx@nxp.com Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/thermal/qoriq_thermal.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index 6c5e53ea7711..b684d3ceda69 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -48,6 +48,7 @@ #define REGS_TRITSR(n) (0x100 + 16 * (n)) /* Immediate Temperature * Site Register */ +#define TRITSR_V BIT(31) #define REGS_TTRnCR(n) (0xf10 + 4 * (n)) /* Temperature Range n * Control Register */ @@ -80,8 +81,24 @@ static int tmu_get_temp(void *p, int *temp) struct qoriq_sensor *qsensor = p; struct qoriq_tmu_data *qdata = qoriq_sensor_to_data(qsensor); u32 val; + /* + * REGS_TRITSR(id) has the following layout: + * + * 31 ... 7 6 5 4 3 2 1 0 + * V TEMP + * + * Where V bit signifies if the measurement is ready and is + * within sensor range. TEMP is an 8 bit value representing + * temperature in C. + */ + if (regmap_read_poll_timeout(qdata->regmap, + REGS_TRITSR(qsensor->id), + val, + val & TRITSR_V, + USEC_PER_MSEC, + 10 * USEC_PER_MSEC)) + return -ENODATA; - regmap_read(qdata->regmap, REGS_TRITSR(qsensor->id), &val); *temp = (val & 0xff) * 1000; return 0; -- 2.21.0