From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753800AbcDSNeV (ORCPT ); Tue, 19 Apr 2016 09:34:21 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:41040 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752159AbcDSNeT (ORCPT ); Tue, 19 Apr 2016 09:34:19 -0400 Subject: Re: [PATCH] hwmon: (ads7828) Enable internal reference To: Akshay Bhat References: <1461008873-17694-1-git-send-email-akshay.bhat@timesys.com> Cc: jdelvare@suse.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org From: Guenter Roeck Message-ID: <571633DF.7050101@roeck-us.net> Date: Tue, 19 Apr 2016 06:34:23 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <1461008873-17694-1-git-send-email-akshay.bhat@timesys.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Authenticated_sender: linux@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: linux@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: linux@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 04/18/2016 12:47 PM, Akshay Bhat wrote: > On ads7828 the internal reference defaults to off upon power up. When > using internal reference, it needs to be turned on and the voltage needs > to settle before normal conversion cycle can be started. Hence perform a > dummy read in the probe to enable the internal reference allowing the > voltage to settle before performing a normal read. > > Without this fix, the first read from the ADC when using internal > reference always returns incorrect data. > > Signed-off-by: Akshay Bhat Applied (after fixing 'volatage' in the comment below). Thanks, Guenter > --- > drivers/hwmon/ads7828.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c > index 6c99ee7..b15c9bd 100644 > --- a/drivers/hwmon/ads7828.c > +++ b/drivers/hwmon/ads7828.c > @@ -120,6 +120,7 @@ static int ads7828_probe(struct i2c_client *client, > unsigned int vref_mv = ADS7828_INT_VREF_MV; > bool diff_input = false; > bool ext_vref = false; > + unsigned int regval; > > data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL); > if (!data) > @@ -154,6 +155,15 @@ static int ads7828_probe(struct i2c_client *client, > if (!diff_input) > data->cmd_byte |= ADS7828_CMD_SD_SE; > > + /* > + * Datasheet specifies internal reference volatage is disabled by > + * default. The internal reference voltage needs to be enabled and > + * voltage needs to settle before getting valid ADC data. So perform a > + * dummy read to enable the internal reference voltage. > + */ > + if (!ext_vref) > + regmap_read(data->regmap, data->cmd_byte, ®val); > + > hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, > data, > ads7828_groups); >