From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756945AbbLAVGc (ORCPT ); Tue, 1 Dec 2015 16:06:32 -0500 Received: from bh-25.webhostbox.net ([208.91.199.152]:46106 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756911AbbLAVG2 (ORCPT ); Tue, 1 Dec 2015 16:06:28 -0500 Date: Tue, 1 Dec 2015 13:06:24 -0800 From: Guenter Roeck To: Nishanth Menon Cc: Jean Delvare , linux-kernel@vger.kernel.org, lm-sensors@lm-sensors.org, linux-omap@vger.kernel.org, beagleboard-x15@googlegroups.com, Eduardo Valentin Subject: Re: [PATCH V2] hwmon: (tmp102) Force wait for conversion time for the first valid data Message-ID: <20151201210624.GA9177@roeck-us.net> References: <1448943955-2385-1-git-send-email-nm@ti.com> <1448986221-6190-1-git-send-email-nm@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1448986221-6190-1-git-send-email-nm@ti.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 01, 2015 at 10:10:21AM -0600, Nishanth Menon wrote: > TMP102 works based on conversions done periodically. However, as per > the TMP102 data sheet[1] the first conversion is triggered immediately > after we program the configuration register. The temperature data > registers do not reflect proper data until the first conversion is > complete (in our case HZ/4). > > The driver currently sets the last_update to be jiffies - HZ, just > after the configuration is complete. When TMP102 driver registers > with the thermal framework, it immediately tries to read the sensor > temperature data. This takes place even before the conversion on the > TMP102 is complete and results in an invalid temperature read. > > Depending on the value read, this may cause thermal framework to > assume that a critical temperature event has occurred and attempts to > shutdown the system. > > Instead of causing an invalid mid-conversion value to be read > erroneously, we mark the last_update to be in-line with the current > jiffies. This allows the tmp102_update_device function to skip update > until the required conversion time is complete. Further, we ensure to > return -EAGAIN result instead of returning spurious temperature (such > as 0C) values to the caller to prevent any wrong decisions made with > such values. NOTE: this allows the read functions not to be blocking > and allows the callers to make the decision if they would like to > block or try again later. At least the current user(thermal) seems to > handle this by retrying later. > > A simpler alternative approach could be to sleep in the probe for the > duration required, but that will result in latency that is undesirable > and delay boot sequence un-necessarily. > > [1] http://www.ti.com/lit/ds/symlink/tmp102.pdf > > Cc: Eduardo Valentin > Reported-by: Aparna Balasubramanian > Reported-by: Elvita Lobo > Reported-by: Yan Liu > Signed-off-by: Nishanth Menon Applied. Thanks, Guenter