From patchwork Fri Oct 7 07:30:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Folkesson X-Patchwork-Id: 13000891 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 15975C433F5 for ; Fri, 7 Oct 2022 07:32:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=1W2OhXsZrQXFEQkXA7eZGTI3fhvbtUf/x4LQm4WtR0Y=; b=gFvmxY6YwAelJf 7SesfDE5OwK6+AsgVIEp74IFGXBo0E2ra5AR67Ym5xl/XreXljxkbpjZspM3p5Ji0ZAHK6WIvvnWd D7gpHVpR9JP1980dQmikmpH6ZO3DA6wQLOpCJ3kM6+bGAgMSqNK/7uv6vfdcKUAW+jx9KAfrkjJpO wJbWKgsFGiHlyOfcqGBZeMaDX2uB+NPAYtW6jZOMY/OWQOsNd+2gIKVDb9YdBOWMLZ/uoy2nQAFcr ny24DUrAg8/84KhOvRocIZxrJI0UgcBF8FjtolEaJvrhH3M47vXkwhHGcfuDra3LkJy6UISb4aM3v HeLrGMMBAO89K4cFR52Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oghpC-007tmm-3q; Fri, 07 Oct 2022 07:31:14 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oghp9-007tm5-6O for linux-arm-kernel@lists.infradead.org; Fri, 07 Oct 2022 07:31:12 +0000 Received: by mail-lf1-x131.google.com with SMTP id bp15so6052057lfb.13 for ; Fri, 07 Oct 2022 00:31:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=EYSGULqa5xfW659MCGZ1cJazL97U/ExMDYm/HUp34jc=; b=aWEK54yQMnoWsg52sifbjsz+ERvWv8idSbv7d/i7YgBWk3Q0eMeZueLfGWlBbGUB51 0Bdfj7vIhEFfak3R/EGLhKguWiPd1BcPW3zQfCncEiv3Xnu071lYO8+AgnlHw6H8ST45 GEWcmyJxni4RxaOmx6TN3QlCOCuh5N3/L4VS3Q78L3UGqdJPeqHsuNwzQOO21x2LAswi 588I9NAaFl85/HWWRGZeRObyEndpifEcNDNN+7plEINLZyU4b1j9mVkDMJa85Znpo0xO Fx6qwV1JTwwH4K9U3Y9J8XDC5GOaxVFhRE1cohOJhP9wzAB+7+fCLysFlbKzErJKBss5 SfsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=EYSGULqa5xfW659MCGZ1cJazL97U/ExMDYm/HUp34jc=; b=6n31xfNiSQ0QbGgaITM2JBqInLKpaTaV22uH2ggviDs06a/ef+q5vbnzjkcQVCqDb8 S+oT1rDxV/o6QvBv++S2wuct5btVIvvZt43/z9TxL1vsRZVOKM6DI41XI9BoNKU0Dg3a 4R8NGXk31MTTG6YLsRsv1m6T/vI/w19YqI7kcXHheXIrHqMqPn9k9qHlsofqptfzn0Tk wPKUbtl1UUHuXf9hMV8MHRvkca4yCqbgXYQfSqZ+22u9WQdgC5t8J92ejg5C7I0yXdLv p8SzywdpCYtUMS5Ln/4SRfQXYuxJNJ1FM69G1U947AuisG+UFNr7/Wg3fcuFZrKCJkGZ Fo1A== X-Gm-Message-State: ACrzQf05vrsKRuwjxC8ZnLyIJWBrN6Wgo0Ff5Gfxphink7RSOhnnFqSn ub2gHprr/trYUXEgoFI2CEk= X-Google-Smtp-Source: AMsMyM7VcZMfaeRok8chUjeQBJg6+kCAAGwiL9obfGOWsOtiYCMpNuM5IaftejwLSI0AqVvsCBEcrA== X-Received: by 2002:a05:6512:6c2:b0:4a2:e7c:6164 with SMTP id u2-20020a05651206c200b004a20e7c6164mr1415568lff.329.1665127868220; Fri, 07 Oct 2022 00:31:08 -0700 (PDT) Received: from localhost.localdomain (82-209-154-112.cust.bredband2.com. [82.209.154.112]) by smtp.gmail.com with ESMTPSA id x18-20020a056512079200b004917a30c82bsm185611lfr.153.2022.10.07.00.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 00:31:07 -0700 (PDT) From: Marcus Folkesson To: "Rafael J . Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Anson Huang Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Marcus Folkesson Subject: [PATCH v2] thermal: imx8mm_thermal: wait for a valid measurement Date: Fri, 7 Oct 2022 09:30:57 +0200 Message-Id: <20221007073057.41803-1-marcus.folkesson@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221007_003111_252278_A2868E65 X-CRM114-Status: GOOD ( 13.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Check if first measurement is still pending or if temperature is out of range. Return and try again later if that is the case. Fixes: 5eed800a6811 ("thermal: imx8mm: Add support for i.MX8MM thermal monitoring unit") Signed-off-by: Marcus Folkesson --- Notes: v2: Also invalidate if temperature > max (125 degrees C) drivers/thermal/imx8mm_thermal.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/imx8mm_thermal.c b/drivers/thermal/imx8mm_thermal.c index af666bd9e8d4..e42bf373cebc 100644 --- a/drivers/thermal/imx8mm_thermal.c +++ b/drivers/thermal/imx8mm_thermal.c @@ -62,11 +62,17 @@ static int imx8mm_tmu_get_temp(void *data, int *temp) { struct tmu_sensor *sensor = data; struct imx8mm_tmu *tmu = sensor->priv; - u32 val; + bool ready; + unsigned long val; + + val = readl_relaxed(tmu->base + TRITSR); + ready = test_bit(probe_status_offset(1), &val); + if (!ready) + return -EAGAIN; - val = readl_relaxed(tmu->base + TRITSR) & TRITSR_TEMP0_VAL_MASK; + val = val & TRITSR_TEMP0_VAL_MASK; *temp = val * 1000; - if (*temp < VER1_TEMP_LOW_LIMIT) + if (*temp < VER1_TEMP_LOW_LIMIT || *temp > VER2_TEMP_HIGH_LIMIT) return -EAGAIN; return 0;